The current method for transforming sympy trees (used in the printers, for example) can require some nested if-tests, even for some simple cases like subtraction (addition of -1 multiplied by the first arg), or division (mutiply by arg to the power of -1). It would be nice to be able to represent and match on more complex patterns in each 'if' branch (like many functional languages). I've been working on a syntax for doing this...
Small sample (this particular example converts to a python expression tree) def expr_to_py(e): ... # subtraction if m(Add, (Mul, S.NegativeOne, v.e1), v.e2): # use v.e1 and v.e2 in constructing the target expression here return py_expr(py_expr.PY_OP_MINUS, expr_to_py(v.e2), expr_to_py(v.e1)) # addition if m(Add, v.e1, v.e2): return py_expr(py_expr.PY_OP_PLUS, expr_to_py(v.e1), expr_to_py(v.e2)) Larger example and prototype implementation here: https://gist.github.com/896417 -- 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.