Opened 2 years ago

Last modified 2 years ago

#25054 new enhancement

Provide a differential operator that matches the print syntax

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

Description

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 2 years ago by nbruin

The relevant code is

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()

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)
cos(x)

should work.

comment:2 Changed 2 years ago by rws

See also #24861.

Note: See TracTickets for help on using tickets.