On Wed, Jul 20, 2011 at 11:59 AM, Aaron Meurer <[email protected]> wrote:
> First off, if you want an explicit order of substitution, you should
> not use a dictionary.  Subs also allows the [(old, new), ...] syntax,
> which lets you define a specific order.
>
> But even in this case, it will perform the substitution iteratively.
> This is actually a useful feature.  For example, you can take the
> output of cse() and back-substituted it all in one step, even though
> the various substitutions depend on each other.
>
> In your case, I recommend adding additional steps with dummy
> variables.  So, something like
>
> a, b, x, y = symbols('a b x y')
> xx, yy = symbols('xx yy', cls=Dummy)
> expr = x**2 + y**3
> expr.subs([(x, a*xx + b*yy), (y, b*xx - a*yy), (xx, x), (yy, y)])
>
> This gives:
>
> In [4]: a, b, x, y = symbols('a b x y')
>
> In [5]: xx, yy = symbols('xx yy', cls=Dummy)
>
> In [6]: expr = x**2 + y**3
>
> In [7]: expr.subs([(x, a*xx + b*yy), (y, b*xx - a*yy), (xx, x), (yy, y)])
> Out[7]:
>           2               3
> (a⋅x + b⋅y)  + (-a⋅y + b⋅x)
>
> Something about this behavior should be added to the docstring of subs.

Martin, if this does what you want and you have some time, you can
send us a github pull request with a better docstring for the .subs()
method, explaining the above subtlety. That'd be a great help.

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.

Reply via email to