On Sat, Sep 11, 2010 at 9:27 AM, Aaron S. Meurer <[email protected]> wrote: > > On Sep 10, 2010, at 11:19 PM, Bill Hart wrote: > >> What isn't clear is how expressions like >> >> 2*x + 3*y + 4*z >> >> get handled without creating intermediate classes. Do the Add and >> Mult classes combine subexpressions together within the __new__ >> method? > > I think it is impossible to create that all in one fell-swoop in Python just > by typing 2*x + 3*y + 4*z because everything is handled by Python's operator > evaluation precedence. So in this case, Python will evaluate 2*x, 3*x, 2*x + > 3*x, 4*z, (2*x + 3*x) + 4*z, in that order, and there is really no way to > make it do otherwise. > > Now, I suppose we could attempt to make sympify() smarter when passed a > string form of an expression (sympify('2*x + 3*y + 4*z')), but right now, it > isn't (more or less, it just calls ast parse, which does the same thing as > regular Python except it converts x, y, and z into Symbols first) . I don't > know how worth it it would be to make it smarter, since the string version is > rarely used compared to the standard version.
I don't think it's worthy. What is worthy of course is to make Add(a, b, c, d, e) working very fast, and that is already the case, and we do use it, for example when expanding things like (x+1)**100. Next step is to make the whole core (e.g. internal implementation of Add) way faster, but that is a different issue. As far as creation of classes is concerned, I think it's as fast as it could be. Ondrej -- 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.
