On Tue, Jul 26, 2011 at 9:02 AM, Chris Smith <[email protected]> wrote:
>> Actually, I see now that this is the wrong approach.  subs should be
>> able to do multiple substitutions at once at the core level.  The
>> reason is efficiency. Consider the following
>
> Just to be clear, by "multiple substitutions at once" do you mean
> doing multiple substitutions before rebuilding the expression? So `(x
> + y + z).subs([(x, 1), (y, 2)])` would iterate through all
> replacements with the `[x, y, z]` args before rebuilding the Add? BTW,
> to keep this static one would either have to remove the subexpressions
> after a successful replacement or use dummies as intermediates.

If you do it right, there should be no need for Dummys, because you
should only hit each part of the expression exactly once, and never
recurse through something that was newly put there by subs.  This is
how xreplace works (see the code).  Actually, it's important that you
do hit each part only once, first, because it's more efficient that
way, and second, because if you don't you risk substituting something
twice.

Aaron Meurer

-- 
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.

Reply via email to