On Thursday, 3 December 2015 19:45:10 UTC+1, Aaron Meurer wrote: > > > I mean how would it work internally? Right now replace just iterates > all subexpressions (via .args) and replaces the ones that match. You > could make it so that Add(x, y, z) iterates subexpressions like (x, y, > z, x + y, x + 3, y + 3, x + y + 3), but that gets combinatorially > inefficient fast. >
For associative and commutative expression, using python sets. They are implemented in C and therefore fast. If the expression is associative but *not* commutative (e.g. matrix expressions), a for loop over the args. Mixed case (some elements commute while others don't) can be more complicated. In Mathics there are lazy generators for subsets and subranges: https://github.com/mathics/Mathics/blob/3d86a12db65c90b305e9bf4bdb6b3e19073956c2/mathics/core/util.py#L73 https://github.com/mathics/Mathics/blob/3d86a12db65c90b305e9bf4bdb6b3e19073956c2/mathics/core/util.py#L152 They cannot use the *set* trick because their matches have to be exactly the same as Wolfram Mathematica's ones. Another thing to add is the support of *evaluate=False* in all of them (subs, replace, xreplace). -- You received this message because you are subscribed to the Google Groups "sympy" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/sympy. To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/c8fe6aac-0906-4b54-afda-0f81f79ca368%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
