Dimas, The pattern matching code I've been working on might be useful to compactly represent this sort of transformation.
The code is here: https://github.com/markdewing/sympy/blob/derivation_modeling/sympy/prototype/codegen/pattern_match.py Example of it in use is here (converting to a python tree - not the python AST, but a different one) https://github.com/markdewing/sympy/blob/derivation_modeling/sympy/prototype/codegen/sympy_to_py.py Everyone, I think the pattern-matching code could be ready to go into the main sympy branch, but where should it live - perhaps in sympy.util? (The rest of the code generation and derivation modeling work is probably not ready yet, but the pattern-matching piece could be useful on its own). Mark On Sep 8, 12:27 pm, Dimas Abreu Dutra <dimasadu...@gmail.com> wrote: > On Thu, Sep 8, 2011 at 1:27 PM, Aaron Meurer <asmeu...@gmail.com> wrote: > > You need to fix some doctests. For example, the fix_missing_locations > > used in the convert() method docstring isn't imported. > > Weird, all my doctests are passing. > > > I think perhaps your convert methods should be class methods. > > Do you mean class methods as opposed to instance methods? The thing is that > the conversion needs to know the constants that should remain named and is > currently saving the recalled symbols and functions. These could be useful > to know what functions and symbols are being loaded so that the namespaces > can be appropriately populated. Those things are obviously instance related, > so that's why the conversions are not class methods. > > > I guess that could be a useful addition to sympy, and other people > > > might need it as well. I was thinking it could be included as a module > > > in the sympy.parsing package. I'm not sure about the name, though, > > > perhaps sympy_ast or ast_builder. I'm still working on it, though, so > > > maybe I could send a pull request when I'm done. > > > Yes, please do. > > Ok, will soon post a pull request with my code as a module name *ast_builder > *. It will be easier to comment and test then. Something that I also forgot > to mention is that this could be used for code generation, with very little > effort, using the unparse module. > > http://svn.python.org/view/python/trunk/Demo/parser/unparse.py > > ~Dimas -- You received this message because you are subscribed to the Google Groups "sympy" group. To post to this group, send email to sympy@googlegroups.com. To unsubscribe from this group, send email to sympy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sympy?hl=en.