Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

The original question tried to replicate the syntax in which sage prints derivatives. This comes up more often. Isn't it time to include (perhaps not in the global namespace, but at least somewhere from which it is easily important) an object that allows users to do so? It's valid python syntax so it's fairly easy to do. It does require boilerplate that's a bit beyond a one-liner, though:

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

With this definition you can just write:

sage: function('f'); var('x','y','z')
sage: D[0,1,2](f)(x,y,z)
diff(f(x, y, z), x, y, z)

The original question tried to replicate the syntax in which sage prints derivatives. This comes up more often. Isn't it time to include (perhaps not in the global namespace, but at least somewhere from which it is easily important) imported) an object that allows users to do so? It's valid python syntax so it's fairly easy to do. It does require boilerplate that's a bit beyond a one-liner, though:

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

With this definition you can just write:

sage: function('f'); var('x','y','z')
sage: D[0,1,2](f)(x,y,z)
diff(f(x, y, z), x, y, z)

The original question tried to replicate the syntax in which sage prints derivatives. This comes up more often. Isn't it time to include (perhaps not in the global namespace, but at least somewhere from which it is easily imported) an object that allows users to do so? It's valid python syntax so it's fairly easy to do. It does require boilerplate that's a bit beyond a one-liner, though:

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

With this definition you can just write:

sage: function('f'); var('x','y','z')
sage: D[0,1,2](f)(x,y,z)
diff(f(x, y, z), x, y, z)

This is now https://trac.sagemath.org/ticket/25054