Opened 5 years ago

Last modified 5 years ago

#25054 new enhancement

Provide a differential operator that matches the print syntax

Reported by: Nils Bruin Owned by:
Priority: minor Milestone: sage-8.2
Component: calculus Keywords:
Cc: Ralf Stephan Merged in:
Authors: Reviewers:
Report Upstream: N/A Work issues:
Branch: Commit:
Dependencies: Stopgaps:

Status badges


We currently have

sage: function('f');
sage: diff(f(x,x),x)
D[0](f)(x, x) + D[1](f)(x, x)

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.

Change History (2)

comment:1 Changed 5 years ago by Nils Bruin

The relevant code is

from sage.symbolic.operators import FDerivativeOperator
class Dclass(object):
    def __init__(self,L=None):
        if L is None:
    def __getitem__(self,index):
        if isinstance(index,tuple):
        elif not(isinstance(index,list)):
        return Dclass(self.L+index)
    def __call__(self,arg):
        return FDerivativeOperator(arg,self.L)
    def __repr__(self):
        return "D"+str(self.L)

It's a little more substantial than just a one-liner, so it probably deserves to live somewhere in the library.

Whether this binding to D should be in the top-level namespace is another question. Maybe? D 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

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)

should work.

comment:2 Changed 5 years ago by Ralf Stephan

See also #24861.

Note: See TracTickets for help on using tickets.