Smart subs

71 views
Skip to first unread message

Paul Royik

unread,
Apr 1, 2015, 1:01:29 PM4/1/15
to sy...@googlegroups.com
Is there a function that will convert sqrt(x+1)+x+3 into y^2+y+2 with y=sqrt(x+1)?
Subs is smart enough to make (x**4+x**2+2).subs(x**2, y) into y**2+y+2.

But it doesn't work with initial example. Even sqrt(x+1)+x+1 is not converted into y^2+y

Francesco Bonazzi

unread,
Apr 2, 2015, 5:15:02 AM4/2/15
to sy...@googlegroups.com
In [1]: ex = sqrt(x+1)+x+3

In [2]: ex.subs(x, solve(y-sqrt(x+1), x)[0])
Out[2]:
        ____    
 
2      2    
y  
+ ╲╱  y   + 2


If y is declared to be positive, you get the right expression.

Paul Royik

unread,
Apr 2, 2015, 9:17:54 AM4/2/15
to sy...@googlegroups.com
Another smart solution. Thanks a ton.

Maybe you can tell me why the following code doesn't work: https://github.com/sympy/sympy/issues/9233

Paul Royik

unread,
Apr 2, 2015, 10:02:41 AM4/2/15
to sy...@googlegroups.com
Your aaproach fails when we want to substitute sqrt(xy+1) for u.
What to solve here?

Paul Royik

unread,
Apr 2, 2015, 4:24:12 PM4/2/15
to sy...@googlegroups.com
Is there any way subs can substitute 3x+3y into 3t without factoring first?

I enter 3*(x+y) but sympy automatically converts it into 3x+3y and subs doesn't work.


On Thursday, April 2, 2015 at 12:15:02 PM UTC+3, Francesco Bonazzi wrote:

Francesco Bonazzi

unread,
Apr 2, 2015, 9:06:29 PM4/2/15
to sy...@googlegroups.com
Maybe you should read the documentation. Have a look at unevaluated expressions.

Paul Royik

unread,
Apr 3, 2015, 12:32:40 PM4/3/15
to sy...@googlegroups.com
OK. Thank you.
Reply all
Reply to author
Forward
0 new messages