New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

undesired (wrong) substition behavior in sympy? #11746

Open
andres-ordonez opened this Issue Oct 20, 2016 · 2 comments

Comments

Projects
None yet
2 participants
@andres-ordonez
Copy link

andres-ordonez commented Oct 20, 2016

I'm getting this undesired behavior in sympy

In [1]: x = sy.var('x', real=True)

In [2]: (1/x).subs(x**2,1)
Out[2]: 1

Clearly, this should not be the case. Out[2] should be 1/x. Am I missing something or is this a bug?

@khan08

This comment has been minimized.

Copy link

khan08 commented Oct 20, 2016

I think it should be 1 instead of 1/x. The first argument is the variable and the second is the substitution. So your substituting x when x2=1. If you try (1/x).subs(x2,4), you will get 1/2.

@andres-ordonez

This comment has been minimized.

Copy link

andres-ordonez commented Oct 20, 2016

The problem is that when x**2=1 x can be either 1 or -1. The subs method is assuming x is positive.

skirpichev added a commit to skirpichev/diofant that referenced this issue Oct 22, 2016

More strict checking of the Pow._eval_power output
For now, we make sure that old.base wasn't changed.

Closes sympy/sympy#11746

skirpichev added a commit to skirpichev/diofant that referenced this issue Nov 2, 2016

More strict checking of the Pow._eval_power output
For now, we make sure that old.base wasn't changed.

Closes sympy/sympy#11746
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment