4.1 Symbolic Computation

Module: sage.calculus.calculus

Symbolic Computation.

Author: Bobby Moretti and William Stein: 2006-2007

The Sage calculus module is loosely based on the Sage Enhancement Proposal found at: http://www.sagemath.org:9001/CalculusSEP.

The basic units of the calculus package are symbolic expressions which are elements of the symbolic expression ring (SR). There are many subclasses of SymbolicExpression. The most basic of these is the formal indeterminate class, SymbolicVariable. To create a SymbolicVariable object in Sage, use the var() method, whose argument is the text of that variable. Note that Sage is intelligent about LaTeXing variable names.

sage: x1 = var('x1'); x1
x1
sage: latex(x1)
x_{1}
sage: theta = var('theta'); theta
theta
sage: latex(theta)
\theta

Sage predefines x to be a global indeterminate. Thus the following works:

sage: x^2
x^2
sage: type(x)
<class 'sage.calculus.calculus.SymbolicVariable'>

More complicated expressions in Sage can be built up using ordinary arithmetic. The following are valid, and follow the rules of Python arithmetic: (The '=' operator represents assignment, and not equality)

sage: var('x,y,z')
(x, y, z)
sage: f = x + y + z/(2*sin(y*z/55))
sage: g = f^f; g
(z/(2*sin(y*z/55)) + y + x)^(z/(2*sin(y*z/55)) + y + x)

Differentiation and integration are available, but behind the scenes through maxima:

sage: f = sin(x)/cos(2*y)
sage: f.derivative(y)
2*sin(x)*sin(2*y)/cos(2*y)^2
sage: g = f.integral(x); g
-cos(x)/cos(2*y)

Note that these methods require an explicit variable name. If none is given, Sage will try to find one for you.

sage: f = sin(x); f.derivative()
cos(x)

However when this is ambiguous, Sage will raise an exception:

sage: f = sin(x+y); f.derivative()
Traceback (most recent call last):
...
ValueError: must supply an explicit variable for an expression containing
more than one variable

Substitution works similarly. We can substitute with a python dict:

sage: f = sin(x*y - z)
sage: f({x: var('t'), y: z})
sin(t*z - z)

Also we can substitute with keywords:

sage: f = sin(x*y - z)
sage: f(x = t, y = z)
sin(t*z - z)

If there is no ambiguity of variable names, we don't have to specify them:

sage: f = sin(x)
sage: f(y)
sin(y)
sage: f(pi)
0

However if there is ambiguity, we must explicitly state what variables we're substituting for:

sage: f = sin(2*pi*x/y)
sage: f(4)
sin(8*pi/y)

We can also make a CallableSymbolicExpression, which is a SymbolicExpression that is a function of specified variables in a fixed order. Each SymbolicExpression has a function(...) method that is used to create a CallableSymbolicExpression, as illustrated below:

sage: u = log((2-x)/(y+5))
sage: f = u.function(x, y); f
(x, y) |--> log((2 - x)/(y + 5))

There is an easier way of creating a CallableSymbolicExpression, which relies on the Sage preparser.

sage: f(x,y) = log(x)*cos(y); f
(x, y) |--> log(x)*cos(y)

Then we have fixed an order of variables and there is no ambiguity substituting or evaluating:

sage: f(x,y) = log((2-x)/(y+5))
sage: f(7,t)
log(-5/(t + 5))

Some further examples:

sage: f = 5*sin(x)
sage: f
5*sin(x)
sage: f(2)
5*sin(2)
sage: f(pi)
0
sage: float(f(pi))             # random low order bits
6.1232339957367663e-16

Another example:

sage: f = integrate(1/sqrt(9+x^2), x); f
arcsinh(x/3)
sage: f(3)
arcsinh(1)
sage: f.derivative(x)
1/(3*sqrt(x^2/9 + 1))

We compute the length of the parabola from 0 to 2:

sage: x = var('x')
sage: y = x^2
sage: dy = derivative(y,x)
sage: z = integral(sqrt(1 + dy^2), x, 0, 2)
sage: print z
                     arcsinh(4) + 4 sqrt(17)
                     ---------------------
                               4
sage: n(z,200)
4.6467837624329358733826155674904591885104869874232887508703
sage: float(z)
4.6467837624329356

We test pickling:

sage: x, y = var('x,y')
sage: f = -sqrt(pi)*(x^3 + sin(x/cos(y)))
sage: bool(loads(dumps(f)) == f)
True

Coercion examples:

We coerce various symbolic expressions into the complex numbers:

sage: CC(I)
1.00000000000000*I
sage: CC(2*I)
2.00000000000000*I
sage: ComplexField(200)(2*I)
2.0000000000000000000000000000000000000000000000000000000000*I
sage: ComplexField(200)(sin(I))
1.1752011936438014568823818505956008151557179813340958702296*I
sage: f = sin(I) + cos(I/2); f
I*sinh(1) + cosh(1/2)
sage: CC(f)
1.12762596520638 + 1.17520119364380*I
sage: ComplexField(200)(f)
1.1276259652063807852262251614026720125478471180986674836290 +
1.1752011936438014568823818505956008151557179813340958702296*I
sage: ComplexField(100)(f)
1.1276259652063807852262251614 + 1.1752011936438014568823818506*I

We illustrate construction of an inverse sum where each denominator has a new variable name:

sage: f = sum(1/var('n%s'%i)^i for i in range(10))
sage: print f
             1     1     1     1     1     1     1     1    1
            --- + --- + --- + --- + --- + --- + --- + --- + -- + 1
              9     8     7     6     5     4     3     2   n1
            n9    n8    n7    n6    n5    n4    n3    n2

Note that after calling var, the variables are immediately available for use:

sage: (n1 + n2)^5
(n2 + n1)^5

We can, of course, substitute:

sage: print f(n9=9,n7=n6)
        1     1     1     1     1     1     1    1    387420490
       --- + --- + --- + --- + --- + --- + --- + -- + ---------
         8     6     7     5     4     3     2   n1   387420489
       n8    n6    n6    n5    n4    n3    n2

TESTS:

Substitution:

sage: f = x
sage: f(x=5)
5

Simplifying expressions involving scientific notation:

sage: k = var('k')
sage: a0 = 2e-6; a1 = 12
sage: c = a1 + a0*k; c
2.000000000000000e-6*k + 12
sage: sqrt(c)
sqrt(2.000000000000000e-6*k + 12)
sage: sqrt(c^3)
sqrt((2.000000000000000e-6*k + 12)^3)

The symbolic Calculus package uses its own copy of maxima for simplification, etc., which is separate from the default system-wide version:

sage: maxima.eval('[x,y]: [1,2]')
'[1,2]'
sage: maxima.eval('expand((x+y)^3)')
'27'

If the copy of maxima used by the symbolic calculus package were the same as the default one, then the following would return 27, which would be very confusing indeed!

sage: x, y = var('x,y')
sage: expand((x+y)^3)
y^3 + 3*x*y^2 + 3*x^2*y + x^3

Set x to be 5 in maxima:

sage: maxima('x: 5')
5
sage: maxima('x + x + %pi')
%pi+10

This simplification is done using maxima (behind the scenes):

sage: x + x + pi
2*x + pi

Note that x is still x, since the maxima used by the calculus package is different than the one in the interactive interpreter.

Check to see that the problem with the variables method mentioned in Trac ticket #3779 is actually fixed:

sage: f = function('F',x)
sage: diff(f*SR(1),x)
diff(F(x), x, 1)

Module-level Functions

CallableSymbolicExpressionRing( args, [check=True])

SymbolicExpressionRing( )

Return the symbolic expression ring. There is one globally defines symbolic expression ring in the calculus module.

sage: SymbolicExpressionRing()
Symbolic Ring
sage: SymbolicExpressionRing() is SR
True

arctan2( y, x)

Modified version of arctan function, since it is used by Maxima.

arctan2(y,x) = arctan(y/x)

This is mainly for internal use.

TODO: entering 'atan2(1,2)' into Sage returns a NameError that 'atan2' is not defined despite the two lines following this function definition. However, one can enter 'atan(1/2)' with no errors.

sage: arctan2 = sage.calculus.calculus.arctan2
sage: arctan2(1,2)
arctan(1/2)
sage: float(arctan2(1,2))
0.46364760900080609
sage: arctan2(2,3)
arctan(2/3)

atan2( y, x)

Modified version of arctan function, since it is used by Maxima.

arctan2(y,x) = arctan(y/x)

This is mainly for internal use.

TODO: entering 'atan2(1,2)' into Sage returns a NameError that 'atan2' is not defined despite the two lines following this function definition. However, one can enter 'atan(1/2)' with no errors.

sage: arctan2 = sage.calculus.calculus.arctan2
sage: arctan2(1,2)
arctan(1/2)
sage: float(arctan2(1,2))
0.46364760900080609
sage: arctan2(2,3)
arctan(2/3)

dilog( z)

The dilogarithm function Li$ _2(z) = \sum_{k=1}^{\infty} z^k / k^2$ .

This is simply an alias for polylog(2, z).

       sage: dilog(1)
       pi^2/6
sage: dilog(1/2)
pi^2/12 - log(2)^2/2
sage: dilog(x^2+1)
       polylog(2, x^2 + 1)
       sage: float(dilog(1))
1.6449340668482264
sage: var('z')
       z
sage: dilog(z).diff(z, 2)
1/((1 - z)*z) + log(1 - z)/z^2
sage: dilog(z).taylor(z, 1/2, 3)
       -(6*log(2)^2 - pi^2)/12 + 2*log(2)*(z - 1/2) + (-2*log(2) + 2)*(z -
1/2)^2 + (8*log(2) - 4)*(z - 1/2)^3/3

dummy_limit( )

This function is called to create formal wrappers of limits that Maxima can't compute:

sage: a = lim(exp(x^2)*(1-erf(x)), x=infinity); a
limit(e^x^2 - e^x^2*erf(x), x, +Infinity)
sage: a = sage.calculus.calculus.dummy_limit(sin(x)/x, x, 0);a 
limit(sin(x)/x, x, 0)

evaled_symbolic_expression_from_maxima_string( x)

Given a string expression that makes sense in Maxima, return the corresponding Sage symbolic expression. This is used mainly internally by the Calculus module.

sage: sage.calculus.calculus.evaled_symbolic_expression_from_maxima_string('2*x + x^3 + y*z*sin(sqrt(x)*erf(theta))')
sin(erf(theta)*sqrt(x))*y*z + x^3 + 2*x
sage: sage.calculus.calculus.evaled_symbolic_expression_from_maxima_string('x^%e + %e^%pi + %i')
x^e + I + e^pi

first_var( expr)

Return the first variable in expr or `x' if there are no variables in expression.

sage: var('a,x,y')
(a, x, y)
sage: sage.calculus.calculus.first_var(a + y^x)
a
sage: sage.calculus.calculus.first_var(y^x - x^3)
x

function( s)

Create a formal symbolic function with the name s.

sage: var('a, b')
(a, b)
sage: f = function('cr', a)
sage: g = f.diff(a).integral(b)
sage: g
diff(cr(a), a, 1)*b
sage: g(cr=cos)
-sin(a)*b
sage: g(cr=sin(x) + cos(x))
(cos(a) - sin(a))*b

Basic arithmetic:

sage: x = var('x')
sage: h = function('f',x)
sage: 2*f
2*f
sage: 2*h
2*f(x)

is_CallableSymbolicExpression( x)

Returns true if x is a callable symbolic expression.

sage: var('a x y z')
(a, x, y, z)
sage: f(x,y) = a + 2*x + 3*y + z
sage: is_CallableSymbolicExpression(f)
True
sage: is_CallableSymbolicExpression(a+2*x)
False
sage: def foo(n): return n^2
...
sage: is_CallableSymbolicExpression(foo)
False

is_CallableSymbolicExpressionRing( x)

Return True if x is a callable symbolic expression.

Input:

x
- object

Output: bool

sage: is_CallableSymbolicExpressionRing(QQ)
False
sage: var('x,y,z')
(x, y, z)
sage: is_CallableSymbolicExpressionRing(CallableSymbolicExpressionRing((x,y,z)))
True

is_SymbolicExpression( x)

sage: is_SymbolicExpression(sin(x))
True
sage: is_SymbolicExpression(2/3)
False
sage: is_SymbolicExpression(sqrt(2))
True

is_SymbolicExpressionRing( x)

sage: is_SymbolicExpressionRing(QQ)
False
sage: is_SymbolicExpressionRing(SR)
True

is_SymbolicVariable( x)

Return True if $ x$ is a symbolic variable.

Input:

x
- object
Output:
bool
- True precisely if x is a symbolic variable.

sage: is_SymbolicVariable('x')
False
sage: is_SymbolicVariable(x)
True

ln( x)

The natural logarithm of x.

Input:

x
- positive real number

Output:
ln(x)
- real number

sage: ln(e^2)
2 
sage: ln(2)
log(2)
sage: ln(2.0)
0.693147180559945

log( x, [base=None])

Return the logarithm of x to the given base.

Calls the log method of the object x when computing the logarithm, thus allowing use of logarithm on any object containing a log method. In other words, log works on more than just real numbers.

TODO: Add p-adic log example.

sage: log(e^2)
2 
sage: log(1024, 2); RDF(log(1024, 2))
log(1024)/log(2)
10.0
sage: log(10, 4); RDF(log(10, 4))
log(10)/log(4)
1.66096404744

sage: log(10, 2)
log(10)/log(2)
sage: n(log(10, 2))
3.32192809488736
sage: log(10, e)
log(10)
sage: n(log(10, e))
2.30258509299405

The log function also works in finite fields as long as the base is generator of the multiplicative group:

sage: F = GF(13); g = F.multiplicative_generator(); g
2
sage: a = F(8)
sage: log(a,g); g^log(a,g)
3
8
sage: log(a,3)
Traceback (most recent call last):
...
ValueError: base (=3) for discrete log must generate multiplicative group

mapped_opts( v)

Used internally when creating a string of options to pass to Maxima.

Input:

v
- an object
Output: a string.

The main use of this is to turn Python bools into lower case strings.

sage: sage.calculus.calculus.mapped_opts(True)
'true'
sage: sage.calculus.calculus.mapped_opts(False)
'false'
sage: sage.calculus.calculus.mapped_opts('bar')
'bar'

maxima_init( x)

maxima_options( )

Used internally to create a string of options to pass to Maxima.

sage: sage.calculus.calculus.maxima_options(an_option=True, another=False, foo='bar')
'an_option=true,foo=bar,another=false'

polylog( n, z)

The polylogarithm function Li$ _n(z) = \sum_{k=1}^{\infty} z^k / k^n$ .

sage: polylog(2,1)
pi^2/6
sage: polylog(2,x^2+1)
polylog(2, x^2 + 1)
sage: polylog(4,0.5)
polylog(4, 0.500000000000000)
sage: float(polylog(4,0.5))
0.51747906167389934

sage: var('z')
z
sage: polylog(2,z).taylor(z, 1/2, 3)
-(6*log(2)^2 - pi^2)/12 + 2*log(2)*(z - 1/2) + (-2*log(2) + 2)*(z - 1/2)^2
+ (8*log(2) - 4)*(z - 1/2)^3/3

symbolic_expression_from_maxima_element( x)

Given an element of the calculus copy of the Maxima interface, create the corresponding Sage symbolic expression.

sage: a = sage.calculus.calculus.maxima('x^(sqrt(y)+%pi) + sin(%e + %pi)')
sage: sage.calculus.calculus.symbolic_expression_from_maxima_element(a)
x^(sqrt(y) + pi) - sin(e)

symbolic_expression_from_maxima_string( x, [equals_sub=False], [maxima=Maxima])

Given a string representation of a Maxima expression, parse it and return the corresponding Sage symbolic expression.

Input:

x
- a string
equals_sub
- (default: False) if True, replace '=' by '==' in self
maxima
- (default: the calculus package's Maxima) the Maxima interpreter to use.

sage: sage.calculus.calculus.symbolic_expression_from_maxima_string('x^%e + %e^%pi + %i + sin(0)')
x^e + I + e^pi

symbolic_expression_from_string( s, [syms=None], [accept_sequence=False])

sys_init( x, system)

var( s, [create=True])

Create a symbolic variable with the name s.

INPUTS: s - a string, either a single variable name or a space or comma separated list of variable names

NOTE: sage.calculus.calculus.var is better suited for using var in library code since it won't touch the global namespace. To create a new variable in the global namespace, use sage.calculus.var.var. That is, use sage.calculus.calculus.var when defining a symbolic variable for use in sage.calculus.calculus functions or library code.

Note that sage.calculus.calculus.var defines a variable which is locally defined in the calculus namespace but is not globally defined:

sage: alpha = 42; alpha
42
sage: sage.calculus.calculus.var('alpha')
alpha
sage: alpha
42

The variable is still of type SymbolicVariable and belongs to the symbolic expression ring:

sage: type(alpha)
<type 'sage.rings.integer.Integer'>
sage: type(sage.calculus.calculus.var('alpha'))
<class 'sage.calculus.calculus.SymbolicVariable'>
sage: var('beta')
beta
sage: type(beta)
<class 'sage.calculus.calculus.SymbolicVariable'>

TESTS:

sage: var('xx')
xx
sage: var('.foo')
Traceback (most recent call last):
...
ValueError: variable name is not a valid Python identifier
sage: var('.foo/x')
Traceback (most recent call last):
...
ValueError: variable name is not a valid Python identifier

var_cmp( x, y)

Class: CallableSymbolicExpression

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

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
sage: f(y=2, a=-1)
z + 2*x + 5
CallableSymbolicExpression( self, parent, expr)

Functions: args,$ \,$ arguments,$ \,$ expression,$ \,$ integral,$ \,$ integrate,$ \,$ number_of_arguments,$ \,$ variables

arguments( self)

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

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

expression( self)

Return the underlying symbolic expression (i.e., forget the extra map structure).

integral( self, [x=None], [a=None], [b=None])

Returns an integral of self.

integrate( self, [x=None], [a=None], [b=None])

Returns an integral of self.

number_of_arguments( self)

Returns the number of arguments of self.

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

variables( self)

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)

Special Functions: __add__,$ \,$ __call__,$ \,$ __complex__,$ \,$ __div__,$ \,$ __float__,$ \,$ __init__,$ \,$ __mul__,$ \,$ __pow__,$ \,$ __sub__,$ \,$ _add_,$ \,$ _complex_double_,$ \,$ _complex_mpfr_field_,$ \,$ _div_,$ \,$ _fast_float_,$ \,$ _latex_,$ \,$ _maxima_init_,$ \,$ _mpfr_,$ \,$ _mul_,$ \,$ _neg_,$ \,$ _real_double_,$ \,$ _real_rqdf_,$ \,$ _repr_,$ \,$ _sub_,$ \,$ _unify_args

__add__( self, right)

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

__call__( self)

Calling a callable symbolic expression returns a symbolic expression with the approriate arguments substituted.

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
sage: f(y=2, a=-1)
z + 2*x + 5

Note that keyword arguments will override the regular arguments.

sage: f.args()
(x, y)
sage: f(1,2)
z + a + 8
sage: f(10,2)
z + a + 26
sage: f(10,2,x=1)
z + a + 8
sage: f(z=100)
3*y + 2*x + a + 100

__div__( self, right)

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)

__mul__( self, right)

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)

__sub__( self, right)

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

_fast_float_( self)

sage: a = var('a')
sage: g(x) = sin(x) + 2
sage: f = g._fast_float_()
sage: f(0)
2.0

_latex_( self)

Finds the LaTeX representation of this expression.

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} '

_mpfr_( self, field)

Coerce to a multiprecision real number.

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

_unify_args( self, x)

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

Let a be self's variable list, let b be y's variable list.

  1. If a == b, then the variable lists are identical, so return that variable list.

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

Note: When used for arithmetic between CallableSymbolicExpressions, these rules ensure that the set of CallableSymbolicExpressions 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.

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

Author: Bobby Moretti, thanks to William Stein for the rules

Class: CallableSymbolicExpressionRing_class

class CallableSymbolicExpressionRing_class
CallableSymbolicExpressionRing_class( self, args)

Functions: args,$ \,$ arguments,$ \,$ is_field,$ \,$ zero_element

args( self)

Returns the arguments of self. The order that the variables appear in self.args() is the order that is used in evaluating the elements of self.

sage: x,y = var('x,y')
sage: f(x,y) = 2*x+y
sage: f.parent().args()
(x, y)
sage: f(y,x) = 2*x+y
sage: f.parent().args()
(y, x)

arguments( self)

Returns the arguments of self. The order that the variables appear in self.args() is the order that is used in evaluating the elements of self.

sage: x,y = var('x,y')
sage: f(x,y) = 2*x+y
sage: f.parent().args()
(x, y)
sage: f(y,x) = 2*x+y
sage: f.parent().args()
(y, x)

is_field( self)

Returns True, since the callable symbolic expression ring is (for the most part) a field.

sage: g(x,y) = x^2 + y^2
sage: g.parent().is_field()
True

zero_element( self)

Return the zero element of the ring of callable symbolic expressions.

sage: R = CallableSymbolicExpressionRing(var('x,y,theta'))
sage: f = R.zero_element(); f
(x, y, theta) |--> 0
sage: f(2,3,4)
0

Special Functions: __call__,$ \,$ __init__,$ \,$ _an_element_impl,$ \,$ _coerce_impl,$ \,$ _repr_

__call__( self, x)

TESTS:

sage: f(x) = x+1; g(y) = y+1
sage: f.parent()(g)
x |--> y + 1
sage: g.parent()(f)
y |--> x + 1
sage: f(x) = x+2*y; g(y) = y+3*x
sage: f.parent()(g)
x |--> y + 3*x
sage: g.parent()(f)
y |--> 2*y + x

_an_element_impl( self)

Return an element of the ring of callabel symbolic expressions. This is used by the coercion model.

sage: R = CallableSymbolicExpressionRing(var('x,y,theta'))
sage: R._an_element_impl()
(x, y, theta) |--> 0

_repr_( self)

String representation of ring of callable symbolic expressions.

sage: R = CallableSymbolicExpressionRing(var('x,y,theta'))
sage: R._repr_()
'Callable function ring with arguments (x, y, theta)'

Class: Function_abs

class Function_abs
The absolute value function.

sage: var('x y')
(x, y)
sage: abs(x)
abs(x)
sage: abs(x^2 + y^2)
y^2 + x^2
sage: abs(-2)
2
sage: sqrt(x^2)
sqrt(x^2)
sage: abs(sqrt(x))
sqrt(x)

Special Functions: __call__,$ \,$ _approx_,$ \,$ _complex_approx_,$ \,$ _latex_,$ \,$ _latex_composition,$ \,$ _repr_

_complex_approx_( self, x)

sage: complex(abs(3*I))
(3+0j)
sage: abs_symbolic._complex_approx_(complex(3*I))
(3+0j)

_latex_composition( self, x)

sage: f = sage.calculus.calculus.Function_abs()
sage: latex(f)
\mathrm{abs}
sage: latex(abs(x))
\left| x 
ight|

Class: Function_arccos

class Function_arccos
The arccosine function

sage: arccos(0.5)
1.04719755119660
sage: arccos(1/2)
pi/3
sage: arccos(1 + I*1.0)
0.904556894302381 - 1.061275061905036*I

Special Functions: _approx_,$ \,$ _latex_,$ \,$ _maxima_init_,$ \,$ _repr_

_maxima_init_( self)

sage: arccos._maxima_init_()
'acos'

Class: Function_arccosh

class Function_arccosh
The inverse of the hyperbolic cosine function.

sage: arccosh(1/2)
arccosh(1/2)
sage: arccosh(1 + I*1.0)
0.904556894302381*I + 1.061275061905036

Warning: If the input is real the output will be real or NaN:

sage: arccosh(0.5)
NaN

But evaluation where the input is in the complex field yields a complex output:

sage: arccosh(CC(0.5))
1.04719755119660*I

Special Functions: _approx_,$ \,$ _latex_,$ \,$ _maxima_init_,$ \,$ _repr_

_approx_( self, x)

Return floating point approximation to arccosh.

sage: float(arccosh(2))
1.3169578969248168
sage: cosh(float(arccosh(2)))
2.0

_latex_( self)

Return latex representation of inverse cosine.

sage: arccosh._latex_()
'\cosh^{-1}'

_maxima_init_( self)

Return Maxima representation of this function.

sage: arccosh._maxima_init_()
'acosh'

_repr_( self, [simplify=True])

Return string representation of arccosh.

sage: arccosh._repr_()
'arccosh'

Class: Function_arccot

class Function_arccot
The arccotangent function.

sage: arccot(1/2)
arccot(1/2)
sage: RDF(arccot(1/2))
1.10714871779
sage: arccot(1 + I)
arccot(I + 1)

Special Functions: _approx_,$ \,$ _latex_,$ \,$ _maxima_init_,$ \,$ _repr_

_maxima_init_( self)

sage: arccot._maxima_init_()
'acot'

Class: Function_arccoth

class Function_arccoth
The inverse of the hyperbolic cotangent function.

sage: arccoth(2.)
0.549306144334055
sage: arccoth(2)
arccoth(2)
sage: arccoth(1 + I*1.0)
0.402359478108525 - 0.553574358897045*I

Special Functions: _approx_,$ \,$ _latex_,$ \,$ _maxima_init_,$ \,$ _repr_

_maxima_init_( self)

sage: arccoth._maxima_init_()
'acoth'

Class: Function_arccsc

class Function_arccsc
The arccosecant function.

sage: arccsc(2)
arccsc(2)
sage: RDF(arccsc(2))
0.523598775598
sage: arccsc(1 + I)
arccsc(I + 1)

Special Functions: _approx_,$ \,$ _latex_,$ \,$ _maxima_init_,$ \,$ _repr_

_maxima_init_( self)

sage: arccsc._maxima_init_()
'acsc'

Class: Function_arccsch

class Function_arccsch
The inverse of the hyperbolic cosecant function.

sage: arccsch(2.)
0.481211825059603
sage: arccsch(2)
arccsch(2)
sage: arccsch(1 + I*1.0)
0.530637530952518 - 0.452278447151191*I

Special Functions: _approx_,$ \,$ _latex_,$ \,$ _maxima_init_,$ \,$ _repr_

_maxima_init_( self)

sage: arccsch._maxima_init_()
'acsch'

Class: Function_arcsec

class Function_arcsec
The arcsecant function.

sage: arcsec(2)
arcsec(2)
sage: RDF(arcsec(2))
1.0471975512
sage: arcsec(1 + I)
arcsec(I + 1)

Special Functions: _approx_,$ \,$ _latex_,$ \,$ _maxima_init_,$ \,$ _repr_

_maxima_init_( self)

asec: arcsec._maxima_init_() 'acsc'

Class: Function_arcsech

class Function_arcsech
The inverse of the hyperbolic secant function.

sage: arcsech(.5)
1.316957896924817
sage: arcsech(1/2)
arcsech(1/2)
sage: arcsech(1 + I*1.0)
0.530637530952518 - 1.118517879643706*I

Special Functions: _approx_,$ \,$ _latex_,$ \,$ _maxima_init_,$ \,$ _repr_

_maxima_init_( self)

sage: arcsech._maxima_init_()
'asech'

Class: Function_arcsin

class Function_arcsin
The arcsine function

sage: arcsin(0.5)
0.523598775598299
sage: arcsin(1/2)
pi/6
sage: arcsin(1 + I*1.0)
1.061275061905036*I + 0.666239432492515

Special Functions: _approx_,$ \,$ _latex_,$ \,$ _maxima_init_,$ \,$ _repr_

_approx_( self, x)

Return floating point approximation to the inverse of sine.

sage: arcsin._approx_(0.5)
0.52359877559829893

_latex_( self)

Return latex representation of self.

sage: arcsin._latex_()
'\sin^{-1}'

_maxima_init_( self)

sage: arcsin._maxima_init_()
'asin'

_repr_( self, [simplify=True])

Return string representation of arcsin.

sage: arcsin._repr_()
'arcsin'

Class: Function_arcsinh

class Function_arcsinh
The inverse of the hyperbolic sine function.

sage: arcsinh(0.5)
0.481211825059603
sage: arcsinh(1/2)
arcsinh(1/2)
sage: arcsinh(1 + I*1.0)
0.666239432492515*I + 1.061275061905036

Special Functions: _approx_,$ \,$ _latex_,$ \,$ _maxima_init_,$ \,$ _repr_

_approx_( self, x)

Return floating point numerical approximation to inverse hyperbolic sin at $ x$ .

sage: arcsinh._approx_(0.5)
0.48121182505960347
sage: sinh(arcsinh._approx_(0.5))
0.5

_latex_( self)

Return latex representation of self.

sage: arcsinh._latex_()
'\sinh^{-1}'

_maxima_init_( self)

Return Maxima representation of this function.

sage: arcsinh._maxima_init_()
'asinh'

_repr_( self, [simplify=True])

Return string representation of arcsinh.

sage: arcsinh._repr_()
'arcsinh'

Class: Function_arctan

class Function_arctan
The arctangent function.

sage: arctan(1/2)
arctan(1/2)
sage: RDF(arctan(1/2))
0.463647609001
sage: arctan(1 + I)
arctan(I + 1)

Special Functions: _approx_,$ \,$ _latex_,$ \,$ _maxima_init_,$ \,$ _repr_

_maxima_init_( self)

sage: arctan._maxima_init_()
'atan'

Class: Function_arctanh

class Function_arctanh
The inverse of the hyperbolic tangent function.

sage: arctanh(0.5)
0.549306144334055
sage: arctanh(1/2)
arctanh(1/2)
sage: arctanh(1 + I*1.0)
1.017221967897851*I + 0.402359478108525

Special Functions: _approx_,$ \,$ _latex_,$ \,$ _maxima_init_,$ \,$ _repr_

_maxima_init_( self)

sage: arctanh._maxima_init_()
'atanh'

Class: Function_ceil

class Function_ceil
The ceiling function.

The ceiling of $ x$ is computed in the following manner.

  1. The x.ceil() method is called and returned if it is there. If it is not, then Sage checks if $ x$ is one of Python's native numeric data types. If so, then it calls and returns Integer(int(math.ceil(x))).

  2. Sage tries to convert $ x$ into a RealIntervalField with 53 bits of precision. Next, the ceilings of the endpoints are computed. If they are the same, then that value is returned. Otherwise, the precision of the RealIntervalField is increased until they do match up or it reaches maximum_bits of precision.

  3. If none of the above work, Sage returns a SymbolicComposition object.

sage: a = ceil(2/5 + x)
sage: a
ceil(x + 2/5)
sage: a(4)
5
sage: a(4.0)
5
sage: ZZ(a(3))
4
sage: a = ceil(x^3 + x + 5/2)
sage: a
ceil(x^3 + x + 1/2) + 2
sage: a(x=2)
13

sage: ceil(log(8)/log(2))
3

sage: ceil(5.4)
6
sage: type(ceil(5.4))
<type 'sage.rings.integer.Integer'>

sage: ceil(factorial(50)/exp(1))
11188719610782480504630258070757734324011354208865721592720336801
sage: ceil(SR(10^50 + 10^(-50)))
100000000000000000000000000000000000000000000000001
sage: ceil(SR(10^50 - 10^(-50)))
100000000000000000000000000000000000000000000000000

Special Functions: __call__,$ \,$ _approx_,$ \,$ _latex_,$ \,$ _maxima_init_,$ \,$ _repr_

_approx_( )
ceil(x)

Return the ceiling of x as a float. This is the smallest integral value >= x.

Class: Function_cos

class Function_cos
The cosine function

Special Functions: __call__,$ \,$ _approx_,$ \,$ _fast_float_,$ \,$ _latex_,$ \,$ _repr_

_approx_( )
cos(x)

Return the cosine of x (measured in radians).

_fast_float_( self)

Returns an object which provides fast floating point evaluation of self.

See sage.ext.fast_eval? for more information.

sage: from sage.ext.fast_eval import fast_float
sage: fast_float(cos)
<sage.ext.fast_eval.FastDoubleFunc object at 0x...>
sage: cos._fast_float_()
<sage.ext.fast_eval.FastDoubleFunc object at 0x...>

Class: Function_cosh

class Function_cosh
The hyperbolic cosine function.

sage: cosh(pi)
cosh(pi)
sage: cosh(3.1415)
11.5908832931176
sage: float(cosh(pi))       # random low order bits
11.591953275521519        
sage: RR(cosh(1/2))
1.12762596520638

Special Functions: _approx_,$ \,$ _latex_,$ \,$ _repr_

Class: Function_cot

class Function_cot
The cotangent function.

sage: cot(pi/4)
1
sage: RR(cot(pi/4))
1.00000000000000
sage: n(cot(pi/4),100)
1.0000000000000000000000000000
sage: cot(1/2)
cot(1/2)
sage: cot(0.5)
1.83048772171245

Special Functions: _approx_,$ \,$ _latex_,$ \,$ _repr_

Class: Function_coth

class Function_coth
The hyperbolic cotangent function.

sage: coth(pi)
coth(pi)
sage: coth(3.1415)
1.00374256795520
sage: float(coth(pi))
1.0037418731973213
sage: RR(coth(pi))
1.00374187319732

Special Functions: _approx_,$ \,$ _latex_,$ \,$ _repr_

Class: Function_csc

class Function_csc
The cosecant function.

sage: csc(pi/4)
sqrt(2)
sage: RR(csc(pi/4))
1.41421356237310
sage: n(csc(pi/4),100)
1.4142135623730950488016887242       
sage: csc(1/2)
csc(1/2)
sage: csc(0.5)
2.08582964293349

Special Functions: _approx_,$ \,$ _latex_,$ \,$ _repr_

Class: Function_csch

class Function_csch
The hyperbolic cosecant function.

sage: csch(pi)
csch(pi)
sage: csch(3.1415)
0.0865975907592133
sage: float(csch(pi))           # random low-order bits
0.086589537530046945
sage: RR(csch(pi))
0.0865895375300470

Special Functions: _approx_,$ \,$ _latex_,$ \,$ _repr_

Class: Function_erf

class Function_erf
The error function, defined as erf$ (x) =
\frac{2}{\sqrt{\pi}} \int_0^x e^{-t^2} dt$ .

Sage currently only implements the error function (via a call to PARI) when the input is real.

Special Functions: _approx_,$ \,$ _latex_,$ \,$ _repr_

Class: Function_exp

class Function_exp
The exponential function, $ \exp(x) = e^x$ .

sage: exp(-1)
e^-1
sage: exp(2)
e^2
sage: exp(x^2 + log(x))
x*e^x^2
sage: exp(2.5)
12.1824939607035
sage: exp(float(2.5))         # random low order bits
12.182493960703473
sage: exp(RDF('2.5'))
12.1824939607
Function_exp( self)

Special Functions: __call__,$ \,$ __init__,$ \,$ _approx_,$ \,$ _latex_,$ \,$ _repr_

Class: Function_floor

class Function_floor
The floor function.

The floor of $ x$ is computed in the following manner.

  1. The x.floor() method is called and returned if it is there. If it is not, then Sage checks if $ x$ is one of Python's native numeric data types. If so, then it calls and returns Integer(int(math.floor(x))).

  2. Sage tries to convert $ x$ into a RealIntervalField with 53 bits of precision. Next, the floors of the endpoints are computed. If they are the same, then that value is returned. Otherwise, the precision of the RealIntervalField is increased until they do match up or it reaches maximum_bits of precision.

  3. If none of the above work, Sage returns a SymbolicComposition object.

sage: floor(5.4)
5
sage: type(floor(5.4))
<type 'sage.rings.integer.Integer'>
sage: var('x')
x
sage: a = floor(5.4 + x); a
floor(x + 0.400000000000000) + 5
sage: a(2)
7

sage: floor(log(8)/log(2))
3

sage: floor(factorial(50)/exp(1))
11188719610782480504630258070757734324011354208865721592720336800
sage: floor(SR(10^50 + 10^(-50)))
100000000000000000000000000000000000000000000000000
sage: floor(SR(10^50 - 10^(-50)))
99999999999999999999999999999999999999999999999999

Special Functions: __call__,$ \,$ _approx_,$ \,$ _latex_,$ \,$ _maxima_init_,$ \,$ _repr_

_approx_( )
floor(x)

Return the floor of x as a float. This is the largest integral value <= x.

Class: Function_log

class Function_log
The log function.

sage: log(e^2)
2 
sage: log(1024, 2) # the following is ugly (for now)
log(1024)/log(2)
sage: log(10, 4)
log(10)/log(4)

sage: RDF(log(10,2))
3.32192809489
sage: RDF(log(8, 2))
3.0
sage: log(RDF(10))
2.30258509299
sage: log(2.718)
0.999896315728952
Function_log( self)

Special Functions: __init__,$ \,$ _approx_,$ \,$ _latex_,$ \,$ _repr_

_approx_( )
log(x[, base]) -> the logarithm of x to the given base. If the base not specified, returns the natural logarithm (base e) of x.

Class: Function_polylog

class Function_polylog
The polylog function Li$ _n(z) = \sum_{k=1}^{\infty} z^k / k^n$ .

Input:

n
- object
z
- object

sage: f = polylog(1,x)._operands[0]; f
polylog(1)
sage: type(f)
<class 'sage.calculus.calculus.Function_polylog'>
Function_polylog( self, n)

Functions: index

index( self)

Return the index of this polylogarithm, i.e., if this is Li$ _n(z)$ , then this function returns $ n$ .

sage: a = polylog(5,x); a
polylog(5, x)
sage: a._operands
[polylog(5), x]
sage: a._operands[0].index()
5

Special Functions: __init__,$ \,$ _approx_,$ \,$ _complex_approx_,$ \,$ _latex_,$ \,$ _maxima_init_,$ \,$ _maxima_init_evaled_,$ \,$ _repr_,$ \,$ _repr_evaled_

_approx_( self, x)

Return real numerical approximation for this polylogarithm evaluated at $ x$ .

sage: f = polylog(4,x)._operands[0]; f
polylog(4)
sage: f._approx_(1)
1.0823232337111381
sage: type(f._approx_(1))
<type 'float'>

_complex_approx_( self, x)

Return real numerical approximation for this polylogarithm evaluated at $ x$ .

sage: a = pari('1+I')
sage: CDF(a)
1.0 + 1.0*I
sage: complex(polylog(4,2))
(2.4278628067547032-0.17437130002545306j)
sage: polylog(4,x)._operands[0]._complex_approx_(2)
(2.4278628067547032-0.17437130002545306j)

_latex_( self)

Return Latex representation of this polylogarithm.

sage: polylog(5,x)._operands[0]._latex_()
'\text{Li}_{5}'

_maxima_init_( self)

Return string representation of this polylog function in Maxima.

sage: polylog(1,x)._operands[0]._maxima_init_()
'li[1]'
sage: polylog(2,x)._operands[0]._maxima_init_()
'li[2]'
sage: polylog(3,x)._operands[0]._maxima_init_()
'li[3]'
sage: polylog(4,x)._operands[0]._maxima_init_()   
'polylog(4)'

Class: Function_sec

class Function_sec
The secant function

sage: sec(pi/4)
sqrt(2)
sage: RR(sec(pi/4))
1.41421356237309
sage: n(sec(pi/4),100)
1.4142135623730950488016887242       
sage: sec(1/2)
sec(1/2)
sage: sec(0.5)
1.13949392732455

Special Functions: _approx_,$ \,$ _latex_,$ \,$ _repr_

Class: Function_sech

class Function_sech
The hyperbolic secant function.

sage: sech(pi)        
sech(pi)
sage: sech(3.1415)
0.0862747018248192
sage: float(sech(pi))    # random low order bits
0.086266738334054432
sage: RR(sech(pi))
0.0862667383340544

Special Functions: _approx_,$ \,$ _latex_,$ \,$ _repr_

Class: Function_sin

class Function_sin
The sine function

Special Functions: __call__,$ \,$ _approx_,$ \,$ _fast_float_,$ \,$ _latex_,$ \,$ _repr_

_approx_( )
sin(x)

Return the sine of x (measured in radians).

_fast_float_( self)

Returns an object which provides fast floating point evaluation of self.

See sage.ext.fast_eval? for more information.

sage: from sage.ext.fast_eval import fast_float
sage: fast_float(sin)
<sage.ext.fast_eval.FastDoubleFunc object at 0x...>
sage: sin._fast_float_()
<sage.ext.fast_eval.FastDoubleFunc object at 0x...>

Class: Function_sinh

class Function_sinh
The hyperbolic sine function.

sage: sinh(pi)
sinh(pi)
sage: sinh(3.1415)
11.5476653707437
sage: float(sinh(pi))              # random low-order bits
11.548739357257748
sage: RR(sinh(pi))
11.5487393572577

Special Functions: _approx_,$ \,$ _latex_,$ \,$ _repr_

Class: Function_sqrt

class Function_sqrt
The square root function. This is a symbolic square root.

sage: sqrt(-1)
I
sage: sqrt(2)
sqrt(2)
sage: sqrt(x^2)
sqrt(x^2)
Function_sqrt( self)

Special Functions: __call__,$ \,$ __init__,$ \,$ _approx_,$ \,$ _do_sqrt,$ \,$ _latex_,$ \,$ _repr_

__call__( self, x)

Input:

x
- a number
prec
- integer (default: None): if None, returns an exact square root; otherwise returns a numerical square root if necessary, to the given bits of precision.
extend
- bool (default: True); if True, return a square root in an extension ring, if necessary. Otherwise, raise a ValueError if the square is not in the base ring.
all
- bool (default: False); if True, return all square roots of self, instead of just one.

Class: Function_tan

class Function_tan
The tangent function

sage: tan(pi)
0
sage: tan(3.1415)
-0.0000926535900581913
sage: tan(3.1415/4)
0.999953674278156
sage: tan(pi/4)
1
sage: tan(1/2)
tan(1/2)
sage: RR(tan(1/2))
0.546302489843790

Special Functions: _approx_,$ \,$ _latex_,$ \,$ _repr_

Class: Function_tanh

class Function_tanh
The hyperbolic tangent function.

sage: tanh(pi)
tanh(pi)
sage: tanh(3.1415)
0.996271386633702
sage: float(tanh(pi))       # random low-order bits
0.99627207622074987
sage: tan(3.1415/4)
0.999953674278156
sage: tanh(pi/4)
tanh(pi/4)
sage: RR(tanh(1/2))
0.462117157260010

sage: CC(tanh(pi + I*e))
0.997524731976164 - 0.00279068768100315*I
sage: ComplexField(100)(tanh(pi + I*e))
0.99752473197616361034204366446 - 0.0027906876810031453884245163923*I
sage: CDF(tanh(pi + I*e))
0.997524731976 - 0.002790687681*I

Special Functions: _approx_,$ \,$ _latex_,$ \,$ _repr_

Class: PrimitiveFunction

class PrimitiveFunction
PrimitiveFunction( self, [needs_braces=False])

Functions: number_of_arguments,$ \,$ plot,$ \,$ tex_needs_braces

number_of_arguments( self)

Returns the number of arguments of self.

sage: sin.variables()
()
sage: sin.number_of_arguments()
1

Special Functions: __call__,$ \,$ __init__,$ \,$ _approx_,$ \,$ _complex_approx_,$ \,$ _is_atomic,$ \,$ _recursive_sub,$ \,$ _recursive_sub_over_ring

_complex_approx_( self, x)

Given a Python complex $ x$ , evaluate self and return a complex value.

sage: complex(cos(3*I))
(10.067661995777771+0j)

The following fails because we and Maxima haven't implemented erf yet for complex values:

sage: complex(erf(3*I))
Traceback (most recent call last):
...
TypeError: unable to simplify to complex approximation

Class: Symbolic_object

class Symbolic_object
A class representing a symbolic expression in terms of a SageObject (not necessarily a `constant').
Symbolic_object( self, obj)

Functions: number_of_arguments,$ \,$ obj,$ \,$ str

number_of_arguments( self)

Returns the number of arguments this object can take.

sage: SR = SymbolicExpressionRing()
sage: a = SR(e)
sage: a.number_of_arguments()
0

obj( self)

Special Functions: __complex__,$ \,$ __float__,$ \,$ __init__,$ \,$ _complex_double_,$ \,$ _complex_mpfr_field_,$ \,$ _fast_float_,$ \,$ _latex_,$ \,$ _maxima_init_,$ \,$ _mpfr_,$ \,$ _real_double_,$ \,$ _real_rqdf_,$ \,$ _repr_,$ \,$ _sys_init_

__complex__( self)

__float__( self)

_complex_double_( self, C)

_complex_mpfr_field_( self, C)

_latex_( self)

_mpfr_( self, field)

_real_double_( self, R)

_real_rqdf_( self, R)

_repr_( self, [simplify=True])

Class: SymbolicArithmetic

class SymbolicArithmetic
Represents the result of an arithmetic operation on $ f$ and $ g$ .
SymbolicArithmetic( self, operands, op)

Special Functions: __call__,$ \,$ __complex__,$ \,$ __float__,$ \,$ __init__,$ \,$ _algebraic_,$ \,$ _complex_double_,$ \,$ _complex_mpfr_field_,$ \,$ _convert,$ \,$ _fast_float_,$ \,$ _is_atomic,$ \,$ _latex_,$ \,$ _maxima_init_,$ \,$ _mpfr_,$ \,$ _real_double_,$ \,$ _real_rqdf_,$ \,$ _recursive_sub,$ \,$ _recursive_sub_over_ring,$ \,$ _repr_,$ \,$ _sympy_,$ \,$ _sys_init_

__call__( self)

Method for handling a function call.

sage: x,y,z=var('x,y,z')

sage: h = sin + cos
sage: h(1)
sin(1) + cos(1)
sage: h(x)
sin(x) + cos(x)
sage: h = 3*sin
sage: h(1)
3*sin(1)
sage: h(x)
3*sin(x)

sage: (sin+cos)(1)
sin(1) + cos(1)
sage: (sin+1)(1)
sin(1) + 1
sage: (x+sin)(5)
sin(5) + 5
sage: (y+sin)(5)
sin(5) + 5
sage: (x+y+sin)(5)
y + sin(5) + 5

sage: f = x + 2*y + 3*z
sage: f(1)
3*z + 2*y + 1
sage: f(0,1)
3*z + 2
sage: f(0,0,1)
3

sage: (sqrt(2) + 17)(x+2)
Traceback (most recent call last):
...
ValueError: the number of arguments must be less than or equal to 0
sage: (I*17+3*5)(x+2)
Traceback (most recent call last):
...
ValueError: the number of arguments must be less than or equal to 0

__complex__( self)

sage: complex((-2)^(1/4))
(0.840896415253714...+0.840896415253714...j)

TESTS:

sage: complex(I - I)
0j
sage: w = I-I; complex(w)
0j
sage: complex(w * x)
0j

__float__( self)

TESTS:

sage: f=x*sin(0)
sage: float(f(x=1))
0.0
sage: w = I - I
sage: float(w)
0.0

_algebraic_( self, field)

Convert a symbolic expression to an algebraic number.

sage: QQbar(sqrt(2) + sqrt(8))
4.242640687119285?
sage: AA(sqrt(2) ^ 4) == 4
True
sage: AA(-golden_ratio)
-1.618033988749895?
sage: QQbar((2*I)^(1/2))
1 + 1*I

TESTS:

sage: AA(x*sin(0))
0
sage: QQbar(x*sin(0))
0

_complex_double_( self, field)

sage: CDF((-1)^(1/3))
0.5 + 0.866025403784*I

Watch out - right now Maxima algebraically simplifies the above to -1:

sage: (-1)^(1/3)
(-1)^(1/3)

So when doing this conversion it is the non-simplified form that is converted, for efficiency purposes, which can result in a different answer in some cases. You can always force using the simplified form:

sage: a = (-1)^(1/3)
sage: CDF(a.simplify())
0.5 + 0.866025403784*I

TESTS:

sage: CDF(x*sin(0))
0

_complex_mpfr_field_( self, field)

sage: CC(sqrt(2))
1.41421356237310
sage: a = sqrt(-2); a
sqrt(2)*I
sage: CC(a)
1.41421356237310*I
sage: ComplexField(200)(a)
1.4142135623730950488016887242096980785696718753769480731767*I
sage: ComplexField(100)((-1)^(1/10))
0.95105651629515357211643933338 + 0.30901699437494742410229341718*I

TESTS:

sage: CC(x*sin(0))
0

_convert( self, typ)

Convert self to the given type by converting each of the operands to that type and doing the arithmetic.

sage: f = sqrt(2) * cos(3); f
sqrt(2)*cos(3)
sage: f._convert(RDF)
-1.40006081534
sage: f._convert(float)
-1.4000608153399503

Converting to an int can have surprising consequences, since Python int is ``floor'' and one individual factor can floor to 0 but the product doesn't:

sage: int(f)
-1
sage: f._convert(int)
0
sage: int(sqrt(2))
1
sage: int(cos(3))
0

TESTS: This illustrates how the conversion works even when a type exception is raised, since here one operand is still x (in the unsimplified form):

sage: f = sin(0)*x
sage: f._convert(CDF)
0

_fast_float_( self)

Returns an object which provides fast floating point evaluation of self.

See sage.ext.fast_eval? for more information.

sage: x,y = var('x,y')
sage: f = x*x-y
sage: ff = f._fast_float_('x','y')
sage: ff(2,3)
1.0

sage: a = x + 2*y
sage: f = a._fast_float_()
sage: f(1,0)
1.0
sage: f(0,1)
2.0

_latex_( self, [simplify=True])

sage: var('x,y')
(x, y)
sage: f=(x+y)*(x-y)*(x^2-2)*(y^2-3)
sage: latex(f)
{{{\left( {x}^{2}  - 2 
ight) \left( x - y 
ight)} \left( y + x 
ight)}
\left( {y}^{2}  - 3 
ight)}
sage: latex(cos*(x+1))
{\left( x + 1 
ight) \cos}

_mpfr_( self, field)

sage: RealField(200)(sqrt(2))
1.4142135623730950488016887242096980785696718753769480731767

TESTS:

sage: w = I-I; RR(w)
0.000000000000000
sage: w = I-I; RealField(200)(w)
0.00000000000000000000000000000000000000000000000000000000000
sage: RealField(200)(x*sin(0))
0.00000000000000000000000000000000000000000000000000000000000

_real_double_( self, field)

sage: RDF(sqrt(2))
1.41421356237

TESTS:

sage: RDF(x*sin(0))
0.0

_real_rqdf_( self, field)

sage: RQDF(sqrt(2))
1.414213562373095048801688724209698078569671875376948073176679738

TESTS:

sage: RQDF(x*sin(0))
0.000000000000000000000000000000000000000000000000000000000000000

_recursive_sub( self, kwds)

sage: var('x, y, z, w')
(x, y, z, w)
sage: f = (x - x) + y^2 - z/z + (w^2-1)/(w+1); f
y^2 + (w^2 - 1)/(w + 1) - 1
sage: f(y=10)
(w^2 - 1)/(w + 1) + 99
sage: f(w=1,y=10)
99
sage: f(y=w,w=y)
(y^2 - 1)/(y + 1) + w^2 - 1

sage: f = y^5 - sqrt(2)
sage: f(10)
100000 - sqrt(2)

sage: a = x^2; b = a(2); b
4
sage: type(b)
<class 'sage.calculus.calculus.SymbolicConstant'>

_repr_( self, [simplify=True])

TESTS:

sage: var('r')
r
sage: a = (1-1/r)^(-1); a
1/(1 - 1/r)
sage: a.derivative(r)
-1/((1 - 1/r)^2*r^2)

sage: var('a,b')
(a, b)
sage: s = 0*(1/a) + -b*(1/a)*(1 + -1*0*(1/a))*(1/(a*b + -1*b*(1/a)))
sage: s
-b/(a*(a*b - b/a))
sage: s(a=2,b=3)
-1/3
sage: -3/(2*(2*3-(3/2)))
-1/3
sage: (-1)^(1/4)
(-1)^(1/4)

sage: (-(x-1)/2)._latex_(simplify=False)
'\frac{-\left( x - 1 \right)}{2}'

_sympy_( self)

Converts any expression to SymPy.

sage: x,y = var('x,y')
sage: import sympy
sage: sympy.sympify(x) # indirect doctest
x

Class: SymbolicComposition

class SymbolicComposition
Represents the symbolic composition of $ f \circ g$ .
SymbolicComposition( self, f, g)

Input:

f, g
- both must be in the symbolic expression ring.

Functions: number_of_arguments

number_of_arguments( self)

Returns the number of arguments that self can take.

sage: sqrt(x).number_of_arguments()
1
sage: sqrt(2).number_of_arguments()
0

Special Functions: __complex__,$ \,$ __float__,$ \,$ __init__,$ \,$ _algebraic_,$ \,$ _complex_double_,$ \,$ _complex_mpfr_field_,$ \,$ _fast_float_,$ \,$ _is_atomic,$ \,$ _latex_,$ \,$ _mathematica_init_,$ \,$ _maxima_init_,$ \,$ _mpfr_,$ \,$ _polynomial_,$ \,$ _real_double_,$ \,$ _real_rqdf_,$ \,$ _recursive_sub,$ \,$ _recursive_sub_over_ring,$ \,$ _repr_,$ \,$ _sympy_,$ \,$ _sys_init_

__complex__( self)

Convert this symbolic composition to a Python complex number.

sage: complex(cos(3))
(-0.98999249660044542+0j)
sage: complex(cos(3*I))
(10.067661995777771+0j)

_algebraic_( self, field)

Coerce to an algebraic number.

sage: QQbar(sqrt(2))
1.414213562373095?
sage: AA(abs(1+I))
1.414213562373095?

_complex_double_( self, field)

Coerce to a complex double.

sage: CDF(sin(2)+cos(2)+I)
0.493150590279 + 1.0*I
sage: CDF(coth(pi))
1.0037418732

_complex_mpfr_field_( self, field)

Coerce to a multiprecision complex number.

sage: ComplexField(100)(sin(2)+cos(2)+I)
0.49315059027853930839845163641 + 1.0000000000000000000000000000*I

_fast_float_( self)

Returns an object which provides fast floating point evaluation of self.

See sage.ext.fast_eval? for more information.

sage: f = sqrt(x)._fast_float_('x')
sage: f(2)
1.41421356237309...
sage: y = var('y')
sage: f = sqrt(x+y)._fast_float_('x', 'y')
sage: f(1,1)
1.41421356237309...

sage: f = sqrt(x+2*y)._fast_float_()
sage: f(2,0)
1.41421356237309...
sage: f(0,1)
1.41421356237309...

_mpfr_( self, field)

Coerce to a multiprecision real number.

sage: RealField(100)(sin(2)+cos(2))
0.49315059027853930839845163641

sage: RR(sin(pi))
1.22464679914735e-16

sage: type(RR(sqrt(163)*pi))
<type 'sage.rings.real_mpfr.RealNumber'>