Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
"Operators"
import operator from sage.symbolic.ring import is_SymbolicVariable, SR
def add_vararg(first,*rest): r""" Addition of a variable number of arguments.
INPUT:
- ``first``, ``rest`` - arguments to add
OUTPUT: sum of arguments
EXAMPLES::
sage: from sage.symbolic.operators import add_vararg sage: add_vararg(1,2,3,4,5,6,7) 28 sage: F=(1+x+x^2) sage: bool(F.operator()(*F.operands()) == F) True """
def mul_vararg(first,*rest): r""" Multiplication of a variable number of arguments.
INPUT:
- ``args`` - arguments to multiply
OUTPUT: product of arguments
EXAMPLES::
sage: from sage.symbolic.operators import mul_vararg sage: mul_vararg(9,8,7,6,5,4) 60480 sage: G=x*cos(x)*sin(x) sage: bool(G.operator()(*G.operands())==G) True """
arithmetic_operators = {add_vararg: '+', mul_vararg: '*', operator.add: '+', operator.sub: '-', operator.mul: '*', operator.truediv: '/', operator.floordiv: '//', operator.pow: '^'}
relation_operators = {operator.eq:'==', operator.lt:'<', operator.gt:'>', operator.ne:'!=', operator.le:'<=', operator.ge:'>='}
class FDerivativeOperator(object): def __init__(self, function, parameter_set): """ EXAMPLES::
sage: from sage.symbolic.operators import FDerivativeOperator sage: f = function('foo') sage: op = FDerivativeOperator(f, [0,1]) sage: loads(dumps(op)) D[0, 1](foo) """
def __call__(self, *args): """ EXAMPLES::
sage: from sage.symbolic.operators import FDerivativeOperator sage: x,y = var('x,y') sage: f = function('foo') sage: op = FDerivativeOperator(f, [0,1]) sage: op(x,y) diff(foo(x, y), x, y) sage: op(x,x^2) D[0, 1](foo)(x, x^2)
TESTS:
We should be able to operate on functions evaluated at a point, not just a symbolic variable, :trac:`12796`::
sage: from sage.symbolic.operators import FDerivativeOperator sage: f = function('f') sage: op = FDerivativeOperator(f, [0]) sage: op(1) D[0](f)(1)
""" len(args) != len(set(args))): # An evaluated derivative of the form f'(1) is not a # symbolic variable, yet we would like to treat it # like one. So, we replace the argument `1` with a # temporary variable e.g. `t0` and then evaluate the # derivative f'(t0) symbolically at t0=1. See trac # #12796.
def __repr__(self): """ EXAMPLES::
sage: from sage.symbolic.operators import FDerivativeOperator sage: f = function('foo') sage: op = FDerivativeOperator(f, [0,1]); op D[0, 1](foo) """
def function(self): """ EXAMPLES::
sage: from sage.symbolic.operators import FDerivativeOperator sage: f = function('foo') sage: op = FDerivativeOperator(f, [0,1]) sage: op.function() foo """
def change_function(self, new): """ Returns a new FDerivativeOperator with the same parameter set for a new function.
sage: from sage.symbolic.operators import FDerivativeOperator sage: f = function('foo') sage: b = function('bar') sage: op = FDerivativeOperator(f, [0,1]) sage: op.change_function(bar) D[0, 1](bar) """
def parameter_set(self): """ EXAMPLES::
sage: from sage.symbolic.operators import FDerivativeOperator sage: f = function('foo') sage: op = FDerivativeOperator(f, [0,1]) sage: op.parameter_set() [0, 1] """ |