Hi, On Mon, Apr 19, 2010 at 12:09:08AM -0700, smichr wrote: > Do you want the computer to make the decision about which Add to do > next? If they choose the wrong op, do you just want to output the same > expression? e.g. > > >> eq > 2*3+4+5 > >> eq.mul() > 6+4+5 > >> eq.add() > 10+5 > >> eq.add() > 15 > > vs > > >> eq > 2*3+4+5 > >> eq.add() > 2*3+9 > >> eq.add() > 2*3+9 > >> eq.mul() > 6+9 > >> eq.add() > 15 > > Interestingly, this is somewhat related to what I am trying to do with > rebuilding expressions. One way to do this is to selectively update > parts of an unevaluate expression, but in trying to do that I ran the > problem that things like Mul(2,3,evaluate=False) still evaluate to 6. > So one might have to use a little trickery to get this to work by > using symbols for numbers: > > >>> Add(*[Mul(*[Symbol('2'),Symbol('3')]),Symbol('4'),Symbol('5')]) > 4 + 5 + 2*3 > >>> srepr(_) > "Add(Symbol('4'), Symbol('5'), Mul(Symbol('2'), Symbol('3')))" > >>> > > For the simple 4-ops, one can allow any operation as long as it > involves only two numbers/symbols. For more complicated things > (list .distrubute()) you would have other criteria. > > I think it's doable. >
evaluate=False thing is evil (at least in the current form). On hold branch in my github repo: http://github.com/mattpap/sympy-polys/commits/hold I implemented (almost) unevaluated expressions from scratch, e.g: In [1]: hold('1 + 1 + 1*sin(x + x) + 1*2*3') Out[1]: 1 + 1 + 1⋅sin(x + x) + 1⋅2⋅3 In [2]: type(_) Out[2]: <class 'sympy.core.holdclasses.HoldAdd'> In [3]: _1.unhold() Out[3]: 8 + sin(2⋅x) In [4]: _1.unhold(Add) Out[4]: 2 + 1⋅sin(2⋅x) + 1⋅2⋅3 In [5]: _1.unhold(Mul) Out[5]: 1 + 1 + sin(x + x) + 6 In [6]: _1.unhold_first() Out[6]: 2 + 1⋅sin(x + x) + 1⋅2⋅3 (almost means that HoldAdd and HoldMul are flattened automatically). In hold() I use AST API so currently only >= Python 2.6 interpreters are supported. Also there are some issues with negation and printing. To make all this useful for step-by-step rewriting unhold_first() will have to be improved to unhold not the very first object in the expression tree (as it does currently), but unhold all Hold* instances on the first level with Hold* in the expression tree. > -- > You received this message because you are subscribed to the Google Groups > "sympy" group. > To post to this group, send email to sy...@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. > -- Mateusz
signature.asc
Description: This is a digitally signed message part