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, 03 Feb 2022 10:56:19 +0100Can I expand a composite function symbolically in sagehttps://ask.sagemath.org/question/60916/can-i-expand-a-composite-function-symbolically-in-sage/ The title says it all really. I think I can use ‘expand’ but can’t work out the syntax. Eg, given f(x) = a polynomial and g(x) = some other bit of algebra can I expand fg(x)Thu, 03 Feb 2022 08:36:50 +0100https://ask.sagemath.org/question/60916/can-i-expand-a-composite-function-symbolically-in-sage/Answer by rburing for <p>The title says it all really. I think I can use ‘expand’ but can’t work out the syntax. Eg, given f(x) = a polynomial and g(x) = some other bit of algebra can I expand fg(x)</p>
https://ask.sagemath.org/question/60916/can-i-expand-a-composite-function-symbolically-in-sage/?answer=60917#post-id-60917Yes, for example using callable symbolic expressions:
sage: f(x) = x^3
sage: g(x) = sin(x)+1
sage: f(g(x)).expand()
sin(x)^3 + 3*sin(x)^2 + 3*sin(x) + 1
Or using expression substitution:
sage: f = x^3
sage: g = sin(x)+1
sage: f.subs({x : g}).expand()
sin(x)^3 + 3*sin(x)^2 + 3*sin(x) + 1Thu, 03 Feb 2022 10:45:57 +0100https://ask.sagemath.org/question/60916/can-i-expand-a-composite-function-symbolically-in-sage/?answer=60917#post-id-60917Comment by nerak99 for <p>Yes, for example using callable symbolic expressions:</p>
<pre><code>sage: f(x) = x^3
sage: g(x) = sin(x)+1
sage: f(g(x)).expand()
sin(x)^3 + 3*sin(x)^2 + 3*sin(x) + 1
</code></pre>
<p>Or using expression substitution:</p>
<pre><code>sage: f = x^3
sage: g = sin(x)+1
sage: f.subs({x : g}).expand()
sin(x)^3 + 3*sin(x)^2 + 3*sin(x) + 1
</code></pre>
https://ask.sagemath.org/question/60916/can-i-expand-a-composite-function-symbolically-in-sage/?comment=60918#post-id-60918Thank you for your prompt response. I will have a go later on today.Thu, 03 Feb 2022 10:56:19 +0100https://ask.sagemath.org/question/60916/can-i-expand-a-composite-function-symbolically-in-sage/?comment=60918#post-id-60918