ASKSAGE: Sage Q&A Forum - Individual question feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Thu, 16 Jan 2014 07:36:00 -0600Calculus with formal functions: substitution?https://ask.sagemath.org/question/10928/calculus-with-formal-functions-substitution/If I enter
var('f,x,y')
y = function('y',x)
f = function('f',x,y)
then
f.diff(x)
returns
D[1](f)(x, y(x))*D[0](y)(x) + D[0](f)(x, y(x))
In order to perform more computations later on, I want to rewrite this, using substitutions, so it looks something like
Fy*yx + Fx
But I've got no idea how to do this. In Maxima I'd just use `'diff(f,x)` as the expression to substitute for, but even trying to use `dummy_diff` doesn't seem to work:
from sage.calculus.calculus import dummy_diff
dummy_diff(f,x)
produces the same result as `f.diff(x)` above.
Does anybody know how I can use substitutions to express the results of a formal differentiation with other symbols?Thu, 16 Jan 2014 01:18:05 -0600https://ask.sagemath.org/question/10928/calculus-with-formal-functions-substitution/Answer by ndomes for <p>If I enter</p>
<pre><code>var('f,x,y')
y = function('y',x)
f = function('f',x,y)
</code></pre>
<p>then </p>
<pre><code>f.diff(x)
</code></pre>
<p>returns</p>
<pre><code>D[1](f)(x, y(x))*D[0](y)(x) + D[0](f)(x, y(x))
</code></pre>
<p>In order to perform more computations later on, I want to rewrite this, using substitutions, so it looks something like</p>
<pre><code>Fy*yx + Fx
</code></pre>
<p>But I've got no idea how to do this. In Maxima I'd just use <code>'diff(f,x)</code> as the expression to substitute for, but even trying to use <code>dummy_diff</code> doesn't seem to work:</p>
<pre><code>from sage.calculus.calculus import dummy_diff
dummy_diff(f,x)
</code></pre>
<p>produces the same result as <code>f.diff(x)</code> above.</p>
<p>Does anybody know how I can use substitutions to express the results of a formal differentiation with other symbols?</p>
https://ask.sagemath.org/question/10928/calculus-with-formal-functions-substitution/?answer=15928#post-id-15928A suggestion: convert to a string, use string method replace and reconvert to a sage expression.
F = function('F',x)
print diff(F(2*x))
f = function('f',x)
f(x) = sage_eval(str(diff(F(2*x))).replace('D[0](F)','f'),locals={'x':x,'f':f})
f(x)Thu, 16 Jan 2014 07:36:00 -0600https://ask.sagemath.org/question/10928/calculus-with-formal-functions-substitution/?answer=15928#post-id-15928