Package sage :: Package calculus :: Module calculus :: Class CallableSymbolicExpression
[hide private]
[frames] | no frames]

Class CallableSymbolicExpression

source code

                      object --+                    
                               |                    
structure.sage_object.SageObject --+                
                                   |                
           structure.element.Element --+            
                                       |            
         structure.element.ModuleElement --+        
                                           |        
               structure.element.RingElement --+    
                                               |    
                              SymbolicExpression --+
                                                   |
                                                  CallableSymbolicExpression


A callable symbolic expression that knows the ordered list of
variables on which it depends.

EXAMPLES:
    sage: var('a, x, y, z')
    (a, x,   y, z)
    sage: f(x,y) = a + 2*x + 3*y + z
    sage: f
    (x, y) |--> z + 3*y + 2*x + a
    sage: f(1,2)
    z + a + 8



Instance Methods [hide private]
 
__init__(self, parent, expr)
Create a symbolic expression.
source code
 
variables(self)
EXAMPLES:...
source code
 
integral(self, x=['4ti2-20061025', 'R-2.6.0', 'atlas-3.7.37', 'atlas-3.8.1', 'a..., a=['4ti2-20061025', 'R-2.6.0', 'atlas-3.7.37', 'atlas-3.8.1', 'a..., b=['4ti2-20061025', 'R-2.6.0', 'atlas-3.7.37', 'atlas-3.8.1', 'a...)
Returns an integral of \code{self}.
source code
 
integrate(self, x=['4ti2-20061025', 'R-2.6.0', 'atlas-3.7.37', 'atlas-3.8.1', 'a..., a=['4ti2-20061025', 'R-2.6.0', 'atlas-3.7.37', 'atlas-3.8.1', 'a..., b=['4ti2-20061025', 'R-2.6.0', 'atlas-3.7.37', 'atlas-3.8.1', 'a...)
Returns an integral of \code{self}.
source code
 
expression(self)
Return the underlying symbolic expression (i.e., forget the extra map structure).
source code
 
args(self) source code
 
arguments(self)
Returns the arguments of \code{self}.
source code
 
number_of_arguments(self)
Returns the number of arguments of \code{self}.
source code
 
_maxima_init_(self) source code
 
_fast_float_(self, *vars)
EXAMPLES: sage: x,y,z = var('x,y,z') sage: f = 1 + sin(x)/x + sqrt(z^2+y^2)/cosh(x) sage: ff = f._fast_float_('x', 'y', 'z') sage: f(1.0,2.0,3.0) 4.1780638977866...
source code
 
__float__(self) source code
 
__complex__(self) source code
 
_mpfr_(self, field)
Coerce to a multiprecision real number.
source code
 
_complex_mpfr_field_(self, field) source code
 
_complex_double_(self, C) source code
 
_real_double_(self, R) source code
 
_real_rqdf_(self, R) source code
 
__call__(self, *args)
EXAMPLES: sage: x,y=var('x,y') sage: f = x+y sage: f.arguments() (x, y) sage: f() y + x sage: f(3) y + 3 sage: f(3,4) 7 sage: f(2,3,4) Traceback (most recent call last): ...
source code
 
_repr_(self, simplify=True)
File: sage/structure/element.pyx (starting at line 291)
source code
 
_latex_(self)
Finds the LaTeX representation of this expression.
source code
 
_neg_(self)
Return the formal negative of \code{self}.
source code
 
__add__(self, right)
EXAMPLES:...
source code
 
_add_(self, right)
EXAMPLES:...
source code
 
__sub__(self, right)
EXAMPLES:...
source code
 
_sub_(self, right)
EXAMPLES:...
source code
 
__mul__(self, right)
EXAMPLES:...
source code
 
_mul_(self, right)
EXAMPLES:...
source code
 
__div__(self, right)
EXAMPLES:...
source code
 
_div_(self, right)
EXAMPLES:...
source code
 
__pow__(self, right)
EXAMPLES:...
source code
 
_unify_args(self, x)
Takes the variable list from another \class{CallableSymbolicExpression} object and compares it with the current \class{CallableSymbolicExpression} object's variable list, combining them according to the following rules: Let \code{a} be \code{self}'s variable list, let \code{b} be \code{y}'s variable list.
source code

Inherited from SymbolicExpression: __abs__, __cmp__, __eq__, __ge__, __gt__, __hash__, __int__, __le__, __long__, __lt__, __ne__, __nonzero__, __str__, _axiom_init_, _gap_init_, _gp_init_, _integer_, _kash_init_, _macaulay2_init_, _magma_init_, _maple_init_, _mathematica_init_, _maxima_, _octave_init_, _pari_init_, _polynomial_, _rational_, _richcmp_, _singular_init_, _sys_init_, coeff, coefficient, coefficients, coeffs, combine, conjugate, default_variable, denominator, derivative, diff, differentiate, display2d, exp_simplify, expand, expand_rational, expand_trig, factor, factor_list, find_maximum_on_interval, find_minimum_on_interval, find_root, full_simplify, function, gradient, hessian, imag, inverse_laplace, laplace, limit, log_simplify, minpoly, n, nintegral, nintegrate, norm, numerator, numerical_approx, partial_fraction, plot, poly, polynomial, power_series, radical_simplify, rational_expand, rational_simplify, real, roots, show, simplify, simplify_exp, simplify_full, simplify_log, simplify_radical, simplify_rational, simplify_trig, solve, subs, subs_expr, substitute, substitute_over_ring, taylor, trig_expand, trig_simplify

Inherited from structure.element.RingElement: __idiv__, __imul__, __invert__, __new__, __pos__, __rdiv__, __rmul__, __rpow__, __rtruediv__, __truediv__, _idiv_, _imul_, abs, additive_order, is_nilpotent, is_one, is_unit, multiplicative_order, order

Inherited from structure.element.ModuleElement: __iadd__, __isub__, __neg__, __radd__, __rsub__, _iadd_, _ilmul_, _isub_, _lmul_, _rmul_

Inherited from structure.element.Element: __reduce__, __rxor__, __xor__, _cmp_, _im_gens_, base_base_extend, base_base_extend_canonical_sym, base_extend, base_extend_canonical, base_extend_canonical_sym, base_extend_recursive, base_ring, category, is_zero, parent

Inherited from structure.sage_object.SageObject: __repr__, _axiom_, _gap_, _gp_, _interface_, _interface_init_, _interface_is_cached_, _kash_, _macaulay2_, _magma_, _maple_, _mathematica_, _octave_, _pari_, _r_init_, _sage_, _singular_, db, dump, dumps, rename, reset_name, save, version

Inherited from object: __delattr__, __getattribute__, __reduce_ex__, __setattr__

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, parent, expr)
(Constructor)

source code 

Create a symbolic expression.

EXAMPLES:
This example is mainly for testing purposes.

We explicitly import the SymbolicExpression class.
    sage: from sage.calculus.calculus import SymbolicExpression

Then we make an instance of it.  Note that it prints as a
``generic element'', since it doesn't even have a specific
value!
    sage: a = SymbolicExpression(); a
    Generic element of a structure

It's of the right type.
    sage: type(a)
    <class 'sage.calculus.calculus.SymbolicExpression'>

And it has the right parent. 
    sage: a.parent()
    Symbolic Ring        

Overrides: SymbolicExpression.__init__
(inherited documentation)

variables(self)

source code 

EXAMPLES:
    sage: a = var('a')
    sage: g(x) = sin(x) + a
    sage: g.variables()
    (a, x)
    sage: g.args()
    (x,)
    sage: g(y,x,z) = sin(x) + a - a
    sage: g
    (y, x, z) |--> sin(x)
    sage: g.args()
    (y, x, z)

Overrides: SymbolicExpression.variables

integral(self, x=['4ti2-20061025', 'R-2.6.0', 'atlas-3.7.37', 'atlas-3.8.1', 'a..., a=['4ti2-20061025', 'R-2.6.0', 'atlas-3.7.37', 'atlas-3.8.1', 'a..., b=['4ti2-20061025', 'R-2.6.0', 'atlas-3.7.37', 'atlas-3.8.1', 'a...)

source code 

Returns an integral of \code{self}. 

Overrides: SymbolicExpression.integral

integrate(self, x=['4ti2-20061025', 'R-2.6.0', 'atlas-3.7.37', 'atlas-3.8.1', 'a..., a=['4ti2-20061025', 'R-2.6.0', 'atlas-3.7.37', 'atlas-3.8.1', 'a..., b=['4ti2-20061025', 'R-2.6.0', 'atlas-3.7.37', 'atlas-3.8.1', 'a...)

source code 

Returns an integral of \code{self}. 

Overrides: SymbolicExpression.integral

arguments(self)

source code 

Returns the arguments of \code{self}.  The order that the
variables appear in \code{self.arguments()} is the order that
is used in \code{self.__call__}.

EXAMPLES:
    sage: x,y = var('x,y')
    sage: f(x,y) = 2*x+y
    sage: f.arguments()
    (x, y)
    sage: f(2)
    y + 4
    sage: f(2, 1)
    5
    
    sage: f(y,x) = 2*x+y
    sage: f.arguments()
    (y, x)
    sage: f(2)
    2*x + 2
    sage: f(2, 1)
    4         

Overrides: SymbolicExpression.arguments

number_of_arguments(self)

source code 

Returns the number of arguments of \code{self}.

EXAMPLES:
    sage: a = var('a')
    sage: g(x) = sin(x) + a
    sage: g.number_of_arguments()
    1
    sage: g(x,y,z) = sin(x) - a + a
    sage: g.number_of_arguments()
    3

Overrides: SymbolicExpression.number_of_arguments

_maxima_init_(self)

source code 
Overrides: SymbolicExpression._maxima_init_

_fast_float_(self, *vars)

source code 

EXAMPLES: 
    sage: x,y,z = var('x,y,z')
    sage: f = 1 + sin(x)/x + sqrt(z^2+y^2)/cosh(x)
    sage: ff = f._fast_float_('x', 'y', 'z')
    sage: f(1.0,2.0,3.0)
    4.1780638977866...
    sage: ff(1.0,2.0,3.0)
    4.17806389778660...

Overrides: SymbolicExpression._fast_float_
(inherited documentation)

_mpfr_(self, field)

source code 

Coerce to a multiprecision real number.

EXAMPLES:
    sage: RealField(100)(SR(10))
    10.000000000000000000000000000

Overrides: SymbolicExpression._mpfr_

_complex_mpfr_field_(self, field)

source code 
Overrides: SymbolicExpression._complex_mpfr_field_

_complex_double_(self, C)

source code 
Overrides: SymbolicExpression._complex_double_

_real_double_(self, R)

source code 
Overrides: SymbolicExpression._real_double_

_real_rqdf_(self, R)

source code 
Overrides: SymbolicExpression._real_rqdf_

__call__(self, *args)
(Call operator)

source code 

EXAMPLES:
    sage: x,y=var('x,y')
    sage: f = x+y
    sage: f.arguments()
    (x, y)
    sage: f()
    y + x
    sage: f(3)
    y + 3
    sage: f(3,4)
    7
    sage: f(2,3,4)
    Traceback (most recent call last):
    ...
    ValueError: the number of arguments must be less than or equal to 2

    sage: f({x:3})
    y + 3
    sage: f({x:3,y:4})
    7
    sage: f(x=3)
    y + 3
    sage: f(x=3,y=4)
    7

    sage: a = (2^(8/9))
    sage: a(4)
    Traceback (most recent call last):
    ...
    ValueError: the number of arguments must be less than or equal to 0


    sage: f = function('Gamma', var('z'), var('w')); f
    Gamma(z, w)
    sage: f(2)
    Gamma(2, w)
    sage: f(2,5)
    Gamma(2, 5)

Overrides: SymbolicExpression.__call__
(inherited documentation)

_repr_(self, simplify=True)

source code 
File: sage/structure/element.pyx (starting at line 291)

Overrides: structure.element.Element._repr_
(inherited documentation)

_latex_(self)

source code 

Finds the LaTeX representation of this expression.

EXAMPLES:
    sage: f(A, t, omega, psi) = A*cos(omega*t - psi)
    sage: f._latex_()
    '\left(A, t, \omega, \psi \right)\ {\mapsto}\ {\cos \left( {\omega t} - \psi \right) A}'

    sage: f(mu) =  mu^3
    sage: f._latex_()
    '\mu \ {\mapsto}\ {\mu}^{3} '

_neg_(self)

source code 

Return the formal negative of \code{self}.

EXAMPLES:
    sage: var('a,x,y')
    (a, x, y)
    sage: -a
    -a
    sage: -(x+y)
    -y - x

Overrides: SymbolicExpression._neg_
(inherited documentation)

__add__(self, right)
(Addition operator)

source code 

EXAMPLES:
    sage: var('x y z n m')
    (x, y, z, n, m)
    sage: f(x,n,y) = x^n + y^m;  g(x,n,m,z) = x^n +z^m
    sage: f + g
    (x, n, m, y, z) |--> z^m + y^m + 2*x^n
    sage: g + f
    (x, n, m, y, z) |--> z^m + y^m + 2*x^n

    sage: f(x) = x^2
    sage: f+sin
    x |--> sin(x) + x^2
    sage: g(y) = y^2
    sage: g+sin
    y |--> sin(y) + y^2
    sage: h = g+sin
    sage: h(2)
    sin(2) + 4

Overrides: structure.element.ModuleElement.__add__

_add_(self, right)

source code 

EXAMPLES:
    sage: var('x,y')
    (x, y)
    sage: x + y
    y + x
    sage: x._add_(y)
    y + x

Overrides: SymbolicExpression._add_
(inherited documentation)

__sub__(self, right)
(Subtraction operator)

source code 

EXAMPLES:
    sage: var('x y z n m')
    (x, y, z, n, m)
    sage: f(x,n,y) = x^n + y^m;  g(x,n,m,z) = x^n +z^m            
    sage: f - g
    (x, n, m, y, z) |--> y^m - z^m
    sage: g - f
    (x, n, m, y, z) |--> z^m - y^m

Overrides: structure.element.ModuleElement.__sub__

_sub_(self, right)

source code 

EXAMPLES:
    sage: var('x,y')
    (x, y)
    sage: x - y
    x - y

Overrides: SymbolicExpression._sub_
(inherited documentation)

__mul__(self, right)

source code 

EXAMPLES:
    sage: var('x y z a b c n m')
    (x, y, z, a, b, c, n, m)
    
    sage: f(x) = x+2*y; g(y) = y+3*x
    sage: f*(2/3)
    x |--> 2*(2*y + x)/3
    sage: f*g
    (x, y) |--> (y + 3*x)*(2*y + x)
    sage: (2/3)*f
    x |--> 2*(2*y + x)/3
    
    sage: f(x,y,z,a,b) = x+y+z-a-b; f
    (x, y, z, a, b) |--> z + y + x - b - a
    sage: f * (b*c)
    (x, y, z, a, b) |--> b*c*(z + y + x - b - a)
    sage: g(x,y,w,t) = x*y*w*t
    sage: f*g
    (x, y, a, b, t, w, z) |--> t*w*x*y*(z + y + x - b - a)
    sage: (f*g)(2,3)
    6*t*w*(z - b - a + 5)

    sage: f(x,n,y) = x^n + y^m;  g(x,n,m,z) = x^n +z^m
    sage: f * g
    (x, n, m, y, z) |--> (y^m + x^n)*(z^m + x^n)
    sage: g * f
    (x, n, m, y, z) |--> (y^m + x^n)*(z^m + x^n)

Overrides: structure.element.RingElement.__mul__

_mul_(self, right)

source code 

EXAMPLES:
    sage: var('x,y')
    (x, y)
    sage: x * y
    x*y

Overrides: SymbolicExpression._mul_
(inherited documentation)

__div__(self, right)

source code 

EXAMPLES:
    sage: var('x,y,z,m,n')
    (x, y, z, m, n)
    sage: f(x,n,y) = x^n + y^m;  g(x,n,m,z) = x^n +z^m            
    sage: f / g
    (x, n, m, y, z) |--> (y^m + x^n)/(z^m + x^n)
    sage: g / f
    (x, n, m, y, z) |--> (z^m + x^n)/(y^m + x^n)

Overrides: structure.element.RingElement.__div__

_div_(self, right)

source code 

EXAMPLES:
    sage: var('x,y')
    (x, y)
    sage: x / y
    x/y

Overrides: SymbolicExpression._div_
(inherited documentation)

__pow__(self, right)

source code 

EXAMPLES:
    sage: var('x,n')
    (x, n)
    sage: x^(n+1)
    x^(n + 1)

Overrides: SymbolicExpression.__pow__
(inherited documentation)

_unify_args(self, x)

source code 

Takes the variable list from another \class{CallableSymbolicExpression} object and
compares it with the current \class{CallableSymbolicExpression} object's variable list,
combining them according to the following rules:

Let \code{a} be \code{self}'s variable list, let \code{b} be
\code{y}'s variable list. 

\begin{enumerate}

\item If \code{a == b}, then the variable lists are identical,
      so return that variable list.

\item If \code{a} $\neq$ \code{b}, then check if the first $n$
      items in \code{a} are the first $n$ items in \code{b},
      or vice-versa. If so, return a list with these $n$
      items, followed by the remaining items in \code{a} and
      \code{b} sorted together in alphabetical order.

\end{enumerate}

Note: When used for arithmetic between \class{CallableSymbolicExpression}s,
these rules ensure that the set of \class{CallableSymbolicExpression}s will have
certain properties.  In particular, it ensures that the set is
a \emph{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: f(x, y, z) = sin(x+y+z)
    sage: f
    (x, y, z) |--> sin(z + y + x)
    sage: g(x, y) = y + 2*x
    sage: g
    (x, y) |--> y + 2*x
    sage: f._unify_args(g)
    (x, y, z)
    sage: g._unify_args(f)
    (x, y, z)

    sage: f(x, y, z) = sin(x+y+z)
    sage: g(w, t) = cos(w - t)
    sage: g
    (w, t) |--> cos(w - t)
    sage: f._unify_args(g)
    (t, w, x, y, z)

    sage: f(x, y, t) = y*(x^2-t)
    sage: f
    (x, y, t) |--> (x^2 - t)*y
    sage: g(x, y, w) = x + y - cos(w)
    sage: f._unify_args(g)
    (x, y, t, w)
    sage: g._unify_args(f)
    (x, y, t, w)
    sage: f*g
    (x, y, t, w) |--> (x^2 - t)*y*(y + x - cos(w))
    
    sage: f(x,y, t) = x+y
    sage: g(x, y, w) = w + t
    sage: f._unify_args(g)
    (x, y, t, w)
    sage: g._unify_args(f)
    (x, y, t, w)
    sage: f + g
    (x, y, t, w) |--> y + x + w + t

AUTHORS:
    -- Bobby Moretti, thanks to William Stein for the rules