Opened 6 years ago

Last modified 5 years ago

#15021 new defect

Return unevaluated derivative from BuiltinFunction

Reported by: eviatarbach Owned by:
Priority: major Milestone: sage-6.4
Component: symbolics Keywords:
Cc: burcin Merged in:
Authors: Reviewers:
Report Upstream: N/A Work issues:
Branch: Commit:
Dependencies: Stopgaps:

Description (last modified by eviatarbach)

There should be a way to return an unevaluated derivative from within the _derivative_ or _tderivative_ method of a BuiltinFunction. Perhaps by returning None, like _eval_ does for remaining unevaluated. As of now returning None causes a segmentation fault.

This is important because for multivariate functions often only the derivative with respect to one variable may be known, so we want to return the unevaluated derivative if it's taken with respect to a variable in which we don't know the derivative. Right now it seems the only way to not return an evaluated derivative is to raise an exception.

Change History (6)

comment:1 Changed 6 years ago by eviatarbach

  • Description modified (diff)

comment:2 Changed 6 years ago by vbraun_spam

  • Milestone changed from sage-6.1 to sage-6.2

comment:3 Changed 6 years ago by vbraun_spam

  • Milestone changed from sage-6.2 to sage-6.3

comment:4 Changed 5 years ago by vbraun_spam

  • Milestone changed from sage-6.3 to sage-6.4

comment:5 Changed 5 years ago by rws

  • Summary changed from Return unevaluated derivative to Return unevaluated derivative from BuiltinFunction

comment:6 Changed 5 years ago by nbruin

This issue was discussed before. We have the functionality in FDerivativeOperator, it's just not available on top level or as a method on BuiltinFunction? instances:

http://permalink.gmane.org/gmane.comp.mathematics.sage.devel/58041

I thought this stuff was on trac somewhere already, but I cannot find it presently. For archival purposes:

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 one can input the form that sage prints:

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)

Input will never be in Leibnitz notation, since unevaluated functions do not have names for their parameters, just position numbers for them.

Note: See TracTickets for help on using tickets.