Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/sage/symbolic/all.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,5 @@
from .units import units

π = pi

from .operators import D
62 changes: 62 additions & 0 deletions src/sage/symbolic/operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,3 +194,65 @@ def parameter_set(self):
[0, 1]
"""
return self._parameter_set

class DerivativeOperator():
"""
Derivative operator.

Acting with this operator onto a function gives a new operator (of
type :class:`FDerivativeOperator`) representing the function
differentiated with respect to one or multiple of its arguments.

This operator takes a list of indices specifying the position of
the arguments to differentiate. For example, D[0, 0, 1] is an
operator that differentiates a function twice with respect to its
first argument and once with respect to its second argument.

EXAMPLES::

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

"""
class DerivativeOperatorWithParameters():
def __init__(self, parameter_set):
self._parameter_set = parameter_set
def __call__(self, function):
return FDerivativeOperator(function, self._parameter_set)
def __repr__(self):
"""
Return the string representation of this derivative operator.

EXAMPLES::

sage: D[0]
D[0]
sage: D[0, 1]
D[0, 1]
"""
return "D[%s]" % (", ".join(map(repr, self._parameter_set)))

def __getitem__(self, args):
"""
TESTS:

The order in which the indices are given should not matter::

sage: x, y = var('x,y'); f = function('f')
sage: bool(D[0, 1, 0](f)(x, y) == D[0, 0, 1](f)(x, y))
True
sage: bool(D[1, 0, 0](f)(x, y) == D[0, 0, 1](f)(x, y))
True
"""
if not isinstance(args, tuple):
args = (args,)
return self.DerivativeOperatorWithParameters(args)

D = DerivativeOperator()