12.11.2011 21:42, [email protected] пишет: > This: > > import ast > ast.parse(repr(expression)) > > will do the trick if repr is well coded. > > How much faith should I put in the repr strings in sympy? Or there is > another way? > > On 12 November 2011 18:20, [email protected] < > [email protected]> wrote: > >> Is there any way to get the expression tree from an expression (either >> using the python abstract syntax tree module or just some tuples): >> >> for example >> >> get_tree( x+y*sin(z) ) would return >> >> (Add, x, (Mul, y, (Sin z))) >> >> or >> >> (BinOp, Add, ((Symbol, x), (BinOp, Mul, (blah blah blah)))) >> >
I know only how to obtain the childes: >>> e = x+y*sin(z) + z >>> e.args (y*sin(z), z, x) >>> e.args[0] >>> y*sin(z) >>> e.args[0].args (y, sin(z)) And test the classes: >>> e.is_Add True In other words, the somewhat tree of the expressions exists. How to represent expression-tree in other formats (strings or structures), I do not know. Regards. -- Alexey U. -- You received this message because you are subscribed to the Google Groups "sympy" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/sympy?hl=en.
