Comment #13 on issue 1654 by [email protected]: subs() doesn't substitute lower derivatives into higher order ones
http://code.google.com/p/sympy/issues/detail?id=1654

The solution taken in issue 1435 raises a tricky problem here. There, unevaluated Derivatives were left untouched and evaluated ones had its variables sorted.

Transposing the idea to this issue, it means that

a) Derivative(f(x, y), x, y).subs(Derivative(f(x, y), y, x), 1)

should not substitute anything, but

b) f(x, y).diff(x, y).subs(f(x, y).diff(y, x), 1)

should. The problem is with things like:

c) f(x, y, z).diff(x, y, z).subs(f(x, y, z).diff(y, z), 1)

If the mixed derivatives commute, then it's okay to subs the derivative on y, z by 1, but if not, then you cannot ignore that the derivative is first taken with respect to x. But subs() has no way to know if the expression was originally unevaluated or not, in the case where it was unevaluated but in the same order it would have if its args were sorted.

My suggestion is: if self.args and old.args are both sorted, try to match in any order. If one of them is in a different order, than only subs if the patterns matches the expression variables in the order they appear, starting from the first. So (a) doesn't subs, but (b) and (c) do.

That way, the only ambiguous case is when you didn't want mixed derivatives to commute, but had the order in both the expression and the pattern in the exact order they would have if evaluated.

--
You received this message because you are subscribed to the Google Groups 
"sympy-issues" 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-issues?hl=en.

Reply via email to