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)
>>> from sage.all import *
>>> __tmp__=var("x,y,z"); f = symbolic_expression(sin(x+y+z)).function(x,y,z)
>>> __tmp__=var("x,y"); g = symbolic_expression(y + Integer(2)*x).function(x,y)
>>> 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)
>>> from sage.all import *
>>> __tmp__=var("x,y,z"); f = symbolic_expression(sin(x+y+z)).function(x,y,z)
>>> __tmp__=var("w,t"); g = symbolic_expression(cos(w - t)).function(w,t)
>>> 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
>>> from sage.all import *
>>> __tmp__=var("x,y,t"); f = symbolic_expression(y*(x**Integer(2)-t)).function(x,y,t)
>>> __tmp__=var("x,y,w"); g = symbolic_expression(x + y - cos(w)).function(x,y,w)
>>> 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
>>> from sage.all import *
>>> __tmp__=var("x,y,t"); f = symbolic_expression(x+y).function(x,y,t)
>>> __tmp__=var("x,y,w"); g = symbolic_expression(w + t).function(x,y,w)
>>> f + g
(x, y, t, w) |--> t + w + x + y
- class sage.symbolic.callable.CallableSymbolicExpressionFunctor(arguments)[source]¶
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)
>>> from sage.all import * >>> from sage.symbolic.callable import CallableSymbolicExpressionFunctor >>> x,y = var('x,y') >>> f = CallableSymbolicExpressionFunctor((x,y)); f CallableSymbolicExpressionFunctor(x, y) >>> f(SR) Callable function ring with arguments (x, y) >>> loads(dumps(f)) CallableSymbolicExpressionFunctor(x, y)
- arguments()[source]¶
EXAMPLES:
sage: from sage.symbolic.callable import CallableSymbolicExpressionFunctor sage: x,y = var('x,y') sage: a = CallableSymbolicExpressionFunctor((x,y)) sage: a.arguments() (x, y)
>>> from sage.all import * >>> from sage.symbolic.callable import CallableSymbolicExpressionFunctor >>> x,y = var('x,y') >>> a = CallableSymbolicExpressionFunctor((x,y)) >>> a.arguments() (x, y)
- merge(other)[source]¶
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)
>>> from sage.all import * >>> from sage.symbolic.callable import CallableSymbolicExpressionFunctor >>> x,y = var('x,y') >>> a = CallableSymbolicExpressionFunctor((x,)) >>> b = CallableSymbolicExpressionFunctor((y,)) >>> a.merge(b) CallableSymbolicExpressionFunctor(x, y)
- unify_arguments(x)[source]¶
Take the variable list from another
CallableSymbolicExpression
object and compare 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
– aCallableSymbolicExpression
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)
>>> from sage.all import * >>> from sage.symbolic.callable import CallableSymbolicExpressionFunctor >>> x,y = var('x,y') >>> a = CallableSymbolicExpressionFunctor((x,)) >>> b = CallableSymbolicExpressionFunctor((y,)) >>> a.unify_arguments(b) (x, y)
AUTHORS:
Bobby Moretti: thanks to William Stein for the rules
- class sage.symbolic.callable.CallableSymbolicExpressionRingFactory[source]¶
Bases:
UniqueFactory
- create_key(args, check=True)[source]¶
EXAMPLES:
sage: x,y = var('x,y') sage: CallableSymbolicExpressionRing.create_key((x,y)) (x, y)
>>> from sage.all import * >>> x,y = var('x,y') >>> CallableSymbolicExpressionRing.create_key((x,y)) (x, y)
- create_object(version, key, **extra_args)[source]¶
Return 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)
>>> from sage.all import * >>> x,y = var('x,y') >>> CallableSymbolicExpressionRing.create_object(Integer(0), (x, y)) Callable function ring with arguments (x, y)
- class sage.symbolic.callable.CallableSymbolicExpressionRing_class(arguments)[source]¶
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
>>> from sage.all import * >>> __tmp__=var("x"); f = symbolic_expression(Integer(1)).function(x) >>> f*e x |--> e
- args()[source]¶
Return the arguments of
self
.The order that the variables appear in
self.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)
>>> from sage.all import * >>> x,y = var('x,y') >>> __tmp__=var("x,y"); f = symbolic_expression(Integer(2)*x+y).function(x,y) >>> f.parent().arguments() (x, y) >>> __tmp__=var("y,x"); f = symbolic_expression(Integer(2)*x+y).function(y,x) >>> f.parent().arguments() (y, x)
- arguments()[source]¶
Return the arguments of
self
.The order that the variables appear in
self.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)
>>> from sage.all import * >>> x,y = var('x,y') >>> __tmp__=var("x,y"); f = symbolic_expression(Integer(2)*x+y).function(x,y) >>> f.parent().arguments() (x, y) >>> __tmp__=var("y,x"); f = symbolic_expression(Integer(2)*x+y).function(y,x) >>> f.parent().arguments() (y, x)
- construction()[source]¶
EXAMPLES:
sage: f(x,y) = x^2 + y sage: f.parent().construction() (CallableSymbolicExpressionFunctor(x, y), Symbolic Ring)
>>> from sage.all import * >>> __tmp__=var("x,y"); f = symbolic_expression(x**Integer(2) + y).function(x,y) >>> f.parent().construction() (CallableSymbolicExpressionFunctor(x, y), Symbolic Ring)