# subs: why it accepts one form but not the other?

Hello,

Consider the following expression

y=function("y")(x)
z=-3*diff(y,x)/y^4


I would like to replace diff(y,x)/y^4 by, say, 2/5

I tried,

z.subs(diff(y,x)/y^4==2/5).show()


But this didn't work (threw back at me the original expression)

I tried to replace y^4 by 5, and to do that I did

z.subs(y^4==5).show()


It didn't work. However,

z.subs(1/y^4==5).show()


worked!. I am confused!

If I tried to replace just y with 5^(1/4)

z.subs(y==(5)^(1/4)).show()


it worked! so it cannot replace y^4 with 5, but it can replace y with (5)^1/4.

To get what I want I finally did

z.subs(diff(y,x)==2).subs(1/y^4==5).show()


I got this by trial and error. Shouldn't the first one

z.subs(diff(y,x)/y^4==2/5).show()


have worked in the first place? What is the logic behind this that it didn't work?

edit retag close merge delete

Sort by ยป oldest newest most voted

The general strategy to replace a composed expression like diff(y, x)/y^4 is to replace only a simple part of it by an equivalent expression. In your case:

sage: y = function('y')
sage: Y = y(x)
sage: z = -3*diff(Y, x)/Y^4
sage: z.subs(diff(Y, x) == 2/5*Y^4)
-6/5

more