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.Thu, 18 Mar 2021 12:47:09 +0100Function composition not workinghttps://ask.sagemath.org/question/56217/function-composition-not-working/I'm experiencing some strange behavior when composing two basic functions. My OS is Windows 10. Here is an example:
sage: r=var('r')
sage: s=var('s')
sage: f(r)=r**2
sage: g(r)=r**(1/2)
sage: f(g(r))
sqrt(r)
sage: f(g(s))
s
Whenever I evaluate the functions at the variable they were defined with (or even if just the outer function was defined with it), Sage returns the inner function as the result. This seems to happen only when the two functions are inverses of each other, since it behaves as expected with $f(r)=r^2$ and $g(r)=r^{1/3}$, returning $r^{2/3}$.
Is this a known issue? Is this somehow expected behavior? Thanks for any help.Thu, 18 Mar 2021 03:32:41 +0100https://ask.sagemath.org/question/56217/function-composition-not-working/Answer by slelievre for <p>I'm experiencing some strange behavior when composing two basic functions. My OS is Windows 10. Here is an example:</p>
<pre><code>sage: r=var('r')
sage: s=var('s')
sage: f(r)=r**2
sage: g(r)=r**(1/2)
sage: f(g(r))
sqrt(r)
sage: f(g(s))
s
</code></pre>
<p>Whenever I evaluate the functions at the variable they were defined with (or even if just the outer function was defined with it), Sage returns the inner function as the result. This seems to happen only when the two functions are inverses of each other, since it behaves as expected with $f(r)=r^2$ and $g(r)=r^{1/3}$, returning $r^{2/3}$.</p>
<p>Is this a known issue? Is this somehow expected behavior? Thanks for any help.</p>
https://ask.sagemath.org/question/56217/function-composition-not-working/?answer=56219#post-id-56219This bug was recently fixed.
In Sage 9.3.beta9:
sage: r, s = SR.var('r, s')
sage: f(r) = r**2
sage: g(r) = r**(1/2)
sage: f(g(r))
r
sage: f(g(s))
s
Thu, 18 Mar 2021 12:47:09 +0100https://ask.sagemath.org/question/56217/function-composition-not-working/?answer=56219#post-id-56219