Status: Accepted
Owner: smichr
Labels: Type-Defect Priority-Medium

New issue 2005 by smichr: (x**(2*y)).subs(exp(3*y*log(x)), z) gives z**(3/2) instead of z**(2/3)
http://code.google.com/p/sympy/issues/detail?id=2005

I have corrected the subs routine for this in 1836 which is under review.

And although I know discussion is taking place elsewhere about subs, I just add here that I think these sorts of contorted substitutions make the subs procedure too complex. If the sort of thing I was talking about in "subs enhancement" discussion were implemented someone could be clear about what is getting replaced by doing this (or something like it):

(x**(2*y)).subs(x, Eq(exp(3*y*log(x)), z))

This way subs can be good at making substitutions; solve can be good at finding the value of x in terms of y and z; it is clear what the desired outcome will be when you look at the code. Otherwise, how do you know what is going to be replaced, the x (as shown) or the y to give x**(2*log(z)/(3*log(x)))?

The same sort of thing applies to replacing 1 + x with y in the expression,

2+3*x+exp(1+x)

What is expected:

An **exact** replacement:
(2+3*x+exp(1+x)).subs(1+x, y, exact=1)
2 + 3*x + exp(y)

A replacement suggestive of being able to **re-write** the expression without adding or subtracting anything:
as x + 2(1 + x) + exp(1+x):
(2+3*x+exp(1+x)).subs(1+x, y)
x + 2*y + exp(y)

Or a **u-substitution** like replacement where all x are being replaced
using that relationship:
(2+3*x+exp(1+x)).subs(x, Eq(1+x, y))
-1 + 3*y + exp(y)

When you make subs deal with more than exact-expression or symbol substitutions, then you have the non-canonical issues to deal with in trying to determine whether a change should take place or not e.g.

(x+y*(1+x))**2
(x + y*(1 + x))**2
_.subs(x+y+x*y,2)
(x + y*(1 + x))**2
_.expand(base=1).subs(x+y+x*y,2)
4

Who should be doing the canonicalization, subs or the user?

A real-sympy example of the different subs needs came up recently in making changes of issue 1961. The risch algorithm identifies functions that need to be replaced with variables. It pulls out things like sqrt(x) for x**(3/2) and x**(-1/2) and expect that if sqrt(x) is X0 then the other expressions will (via current subs behavior) be x0**3 and 1/x0. But it also pulls out things like exp(5*x) and exp(3*x) and the problem here is that whichever one comes first you end up with a fractional term like X0**(5/3) or X0**(3/5) and this causes risch to fail because it tries to create polys in X0. So for the powers, risch wants subs to behave in an algebraic sense; for exp it needs literal replacement. The reason that the problem didn't surface until 1961 was that additive terms were being split up so exp(5*x) and exp(3*x) didn't ever appear together. Aaron has pointed out, however, that this is not generally desired (splitting up Adds that are going to risch) so then something else has to give.

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