ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Wed, 10 Jun 2020 17:41:02 +0200subs: why it accepts one form but not the other?https://ask.sagemath.org/question/51880/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?Wed, 10 Jun 2020 03:51:05 +0200https://ask.sagemath.org/question/51880/subs-why-it-accepts-one-form-but-not-the-other/Answer by eric_g for <p>Hello,</p>
<p>Consider the following expression</p>
<pre><code>y=function("y")(x)
z=-3*diff(y,x)/y^4
</code></pre>
<p>I would like to replace diff(y,x)/y^4 by, say, 2/5 </p>
<p>I tried, </p>
<pre><code>z.subs(diff(y,x)/y^4==2/5).show()
</code></pre>
<p>But this didn't work (threw back at me the original expression)</p>
<p>I tried to replace y^4 by 5, and to do that I did</p>
<pre><code>z.subs(y^4==5).show()
</code></pre>
<p>It didn't work. However, </p>
<pre><code>z.subs(1/y^4==5).show()
</code></pre>
<p>worked!. I am confused! </p>
<p>If I tried to replace just y with 5^(1/4) </p>
<pre><code>z.subs(y==(5)^(1/4)).show()
</code></pre>
<p>it worked! so it cannot replace y^4 with 5, but it can replace y with (5)^1/4.</p>
<p>To get what I want I finally did </p>
<pre><code>z.subs(diff(y,x)==2).subs(1/y^4==5).show()
</code></pre>
<p>I got this by trial and error. Shouldn't the first one </p>
<pre><code>z.subs(diff(y,x)/y^4==2/5).show()
</code></pre>
<p>have worked in the first place? What is the logic behind this that it didn't work?</p>
https://ask.sagemath.org/question/51880/subs-why-it-accepts-one-form-but-not-the-other/?answer=51898#post-id-51898The 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/5Wed, 10 Jun 2020 17:41:02 +0200https://ask.sagemath.org/question/51880/subs-why-it-accepts-one-form-but-not-the-other/?answer=51898#post-id-51898