Sage: Ticket #25054: Provide a differential operator that matches the print syntax
https://trac.sagemath.org/ticket/25054
<p>
We currently have
</p>
<pre class="wiki">sage: function('f');
sage: diff(f(x,x),x)
D[0](f)(x, x) + D[1](f)(x, x)
</pre><p>
which is fine. It's even valid Python syntax. However, we do not have a definition for D available that allows this to serve as input. It's easy to define, though.
</p>
en-usSagehttps://trac.sagemath.org/chrome/site/logo_sagemath_trac.png
https://trac.sagemath.org/ticket/25054
Trac 1.2Nils BruinWed, 28 Mar 2018 19:31:20 GMT
https://trac.sagemath.org/ticket/25054#comment:1
https://trac.sagemath.org/ticket/25054#comment:1
<p>
The relevant code is
</p>
<pre class="wiki">from sage.symbolic.operators import FDerivativeOperator
class Dclass(object):
def __init__(self,L=None):
if L is None:
self.L=[]
else:
self.L=L
def __getitem__(self,index):
if isinstance(index,tuple):
index=list(index)
elif not(isinstance(index,list)):
index=[index]
return Dclass(self.L+index)
def __call__(self,arg):
return FDerivativeOperator(arg,self.L)
def __repr__(self):
return "D"+str(self.L)
D=Dclass()
</pre><p>
It's a little more substantial than just a one-liner, so it probably deserves to live somewhere in the library.
</p>
<p>
Whether this binding to <code>D</code> should be in the top-level namespace is another question. Maybe? <code>D</code> isn't defined there presently. If we don't put it there, it should live in an easily importable place. Once this ticket is done, something along the lines of
</p>
<pre class="wiki">sage: from sage.calculus.calculus import D
sage: function('f');
sage: D[0,1](f)(x,x)
D[0, 1](f)(x, x)
sage: D[0,0](f)(x)
diff(f(x), x, x)
sage: D[0](sin)(x)
cos(x)
</pre><p>
should work.
</p>
TicketRalf StephanThu, 29 Mar 2018 07:46:18 GMT
https://trac.sagemath.org/ticket/25054#comment:2
https://trac.sagemath.org/ticket/25054#comment:2
<p>
See also <a class="needs_work ticket" href="https://trac.sagemath.org/ticket/24861" title="#24861: defect: Option to hold for derivative (needs_work)">#24861</a>.
</p>
Ticket