Opened 5 years ago

# Provide a differential operator that matches the print syntax

Reported by: Owned by: Nils Bruin minor sage-8.2 calculus Ralf Stephan N/A

### Description

We currently have

```sage: function('f');
sage: diff(f(x,x),x)
D(f)(x, x) + D(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.

### 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:
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(sin)(x)
cos(x)
```

should work.