On Mar 31, 5:14 pm, "john.hoebing" <jlhs...@gmail.com> wrote:
> sage: a=diff(f,x,x)+diff(f,x)/x
> sage: str(a)
> 'D[0](f)(x, y)/x + D[0, 0](f)(x, y)'

If I understand correctly, you would like to be able to put the above
string into sage and get the expression back? That is of course a very
reasonable goal. The class FDerivativeOperator can be used to create
the appropriate expressions, but suffers from the fact it uses a
different syntax. We need to build a wrapper that does allow the
indexing syntax above. Something along these lines would do the trick:

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
from sage.symbolic.operators import FDerivativeOperator
class Doperator:
    def __init__(self,vars=None):
        self.vars= [] if vars is None else vars

    def __call__(self,f):
        return FDerivativeOperator(f,self.vars)

    def __getitem__(self,i):
        if isinstance(i,tuple):
            newvars=self.vars+list(i)
        else:
            newvars=self.vars+[i]
        return Doperator(newvars)

D=Doperator()
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

With that code in place we can indeed do:

sage: var('x,y')
sage: D[0](f)(x, y)/x + D[0, 1](f)(x, y)
D[0](f)(x, y)/x + D[0, 1](f)(x, y)

Perhaps this should go into the library somewhere. I'm not sure we can
afford to predefine D like this, given it's such a commonly used
symbol. Maple does it, though.

-- 
To post to this group, send an email to sage-devel@googlegroups.com
To unsubscribe from this group, send an email to 
sage-devel+unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-devel
URL: http://www.sagemath.org

Reply via email to