Callable Symbolic Expressions#
EXAMPLES:
When you do arithmetic with:
sage: f(x, y, z) = sin(x+y+z)
sage: g(x, y) = y + 2*x
sage: f + g
(x, y, z) |--> 2*x + y + sin(x + y + z)
sage: f(x, y, z) = sin(x+y+z)
sage: g(w, t) = cos(w - t)
sage: f + g
(t, w, x, y, z) |--> cos(-t + w) + sin(x + y + z)
sage: f(x, y, t) = y*(x^2-t)
sage: g(x, y, w) = x + y - cos(w)
sage: f*g
(x, y, t, w) |--> (x^2 - t)*(x + y - cos(w))*y
sage: f(x,y, t) = x+y
sage: g(x, y, w) = w + t
sage: f + g
(x, y, t, w) |--> t + w + x + y
- class sage.symbolic.callable.CallableSymbolicExpressionFunctor(arguments)#
Bases:
ConstructionFunctor
A functor which produces a CallableSymbolicExpressionRing from the SymbolicRing.
EXAMPLES:
sage: from sage.symbolic.callable import CallableSymbolicExpressionFunctor sage: x,y = var('x,y') sage: f = CallableSymbolicExpressionFunctor((x,y)); f CallableSymbolicExpressionFunctor(x, y) sage: f(SR) Callable function ring with arguments (x, y) sage: loads(dumps(f)) CallableSymbolicExpressionFunctor(x, y)
- arguments()#
EXAMPLES:
sage: from sage.symbolic.callable import CallableSymbolicExpressionFunctor sage: x,y = var('x,y') sage: a = CallableSymbolicExpressionFunctor((x,y)) sage: a.arguments() (x, y)
- merge(other)#
EXAMPLES:
sage: from sage.symbolic.callable import CallableSymbolicExpressionFunctor sage: x,y = var('x,y') sage: a = CallableSymbolicExpressionFunctor((x,)) sage: b = CallableSymbolicExpressionFunctor((y,)) sage: a.merge(b) CallableSymbolicExpressionFunctor(x, y)
- unify_arguments(x)#
Takes the variable list from another
CallableSymbolicExpression
object and compares it with the currentCallableSymbolicExpression
object’s variable list, combining them according to the following rules:Let
a
beself
’s variable list, letb
bey
’s variable list.If
a == b
, then the variable lists are identical, so return that variable list.If
a
\(\neq\)b
, then check if the first \(n\) items ina
are the first \(n\) items inb
, or vice versa. If so, return a list with these \(n\) items, followed by the remaining items ina
andb
sorted together in alphabetical order.
Note
When used for arithmetic between
CallableSymbolicExpression
’s, these rules ensure that the set ofCallableSymbolicExpression
’s will have certain properties. In particular, it ensures that the set is a commutative ring, i.e., the order of the input variables is the same no matter in which order arithmetic is done.INPUT:
x
- A CallableSymbolicExpression
OUTPUT: A tuple of variables.
EXAMPLES:
sage: from sage.symbolic.callable import CallableSymbolicExpressionFunctor sage: x,y = var('x,y') sage: a = CallableSymbolicExpressionFunctor((x,)) sage: b = CallableSymbolicExpressionFunctor((y,)) sage: a.unify_arguments(b) (x, y)
AUTHORS:
Bobby Moretti: thanks to William Stein for the rules
- class sage.symbolic.callable.CallableSymbolicExpressionRingFactory#
Bases:
UniqueFactory
- create_key(args, check=True)#
EXAMPLES:
sage: x,y = var('x,y') sage: CallableSymbolicExpressionRing.create_key((x,y)) (x, y)
- create_object(version, key, **extra_args)#
Returns a CallableSymbolicExpressionRing given a version and a key.
EXAMPLES:
sage: x,y = var('x,y') sage: CallableSymbolicExpressionRing.create_object(0, (x, y)) Callable function ring with arguments (x, y)
- class sage.symbolic.callable.CallableSymbolicExpressionRing_class(arguments)#
Bases:
SymbolicRing
,CallableSymbolicExpressionRing
EXAMPLES:
We verify that coercion works in the case where
x
is not an instance of SymbolicExpression, but its parent is still the SymbolicRing:sage: f(x) = 1 sage: f*e x |--> e
- args()#
Returns the arguments of
self
. The order that the variables appear inself.arguments()
is the order that is used in evaluating the elements ofself
.EXAMPLES:
sage: x,y = var('x,y') sage: f(x,y) = 2*x+y sage: f.parent().arguments() (x, y) sage: f(y,x) = 2*x+y sage: f.parent().arguments() (y, x)
- arguments()#
Returns the arguments of
self
. The order that the variables appear inself.arguments()
is the order that is used in evaluating the elements ofself
.EXAMPLES:
sage: x,y = var('x,y') sage: f(x,y) = 2*x+y sage: f.parent().arguments() (x, y) sage: f(y,x) = 2*x+y sage: f.parent().arguments() (y, x)
- construction()#
EXAMPLES:
sage: f(x,y) = x^2 + y sage: f.parent().construction() (CallableSymbolicExpressionFunctor(x, y), Symbolic Ring)
- sage.symbolic.callable.is_CallableSymbolicExpression(x)#
Returns
True
ifx
is a callable symbolic expression.EXAMPLES:
sage: from sage.symbolic.callable import is_CallableSymbolicExpression sage: var('a x y z') (a, x, y, z) sage: f(x,y) = a + 2*x + 3*y + z sage: is_CallableSymbolicExpression(f) doctest:warning... DeprecationWarning: is_CallableSymbolicExpression is deprecated; use isinstance(..., Expression) and ....is_callable() instead See https://trac.sagemath.org/34215 for details. True sage: is_CallableSymbolicExpression(a+2*x) False sage: def foo(n): return n^2 ... sage: is_CallableSymbolicExpression(foo) False
- sage.symbolic.callable.is_CallableSymbolicExpressionRing(x)#
Return
True
ifx
is a callable symbolic expression ring.INPUT:
x
- object
OUTPUT: bool
EXAMPLES:
sage: from sage.symbolic.callable import is_CallableSymbolicExpressionRing sage: is_CallableSymbolicExpressionRing(QQ) doctest:warning... DeprecationWarning: is_CallableSymbolicExpressionRing is deprecated; use isinstance(..., sage.rings.abc.CallableSymbolicExpressionRing instead See https://trac.sagemath.org/32665 for details. False sage: var('x,y,z') (x, y, z) sage: is_CallableSymbolicExpressionRing(CallableSymbolicExpressionRing((x,y,z))) True