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.

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

__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

_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,$ \,$ 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)

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).

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).

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.2426406871192847 .. 4.2426406871192857]
sage: AA(sqrt(2) ^ 4) == 4
True
sage: AA(-golden_ratio)
[-1.6180339887498950 .. -1.6180339887498946]
sage: QQbar((2*I)^(1/2))
[1.0000000000000000 .. 1.0000000000000000] + [1.0000000000000000 ..
1.0000000000000000]*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)

sage: x,y = var('x,y')
sage: f = x*x-y
sage: ff = f._fast_float_('x','y')
sage: ff(2,3)
1.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.

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_,$ \,$ _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.4142135623730949 .. 1.4142135623730952]
sage: AA(abs(1+I))
[1.4142135623730949 .. 1.4142135623730952]

_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

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

sage: RR(coth(pi))
1.00374187319732
sage: RealField(100)(coth(pi))
1.0037418731973212882015526912
sage: RealField(200)(arccos(1/10))
1.4706289056333368228857985121870581235299087274579233690964

_polynomial_( self, R)

Symbolic compositions cannot be converted to polynomials unless they are constants.

sage: sqrt(2).polynomial(RR)
1.41421356237310

sage: sqrt(2).polynomial(CC)
1.41421356237310

sage: cos(x).polynomial(QQ)
Traceback (most recent call last):
....
TypeError: cannot convert self (= cos(x)) to a polynomial

sage: sqrt(x).polynomial(QQ)
Traceback (most recent call last):
....
TypeError: cannot convert self (= sqrt(x)) to a polynomial

sage: K3.<a> = NumberField(sqrt(x))
Traceback (most recent call last):
....
TypeError: polynomial (=sqrt(x)) must be a polynomial.

_real_double_( self, field)

Coerce to a real double.

sage: RDF(sin(2)+cos(2))
0.493150590279

_real_rqdf_( self, field)

Coerce to a real qdrf.

Class: SymbolicConstant

class SymbolicConstant
SymbolicConstant( self, x)

Special Functions: __init__,$ \,$ __neg__,$ \,$ __pow__,$ \,$ _add_,$ \,$ _algebraic_,$ \,$ _div_,$ \,$ _fast_float_,$ \,$ _is_atomic,$ \,$ _mul_,$ \,$ _recursive_sub,$ \,$ _recursive_sub_over_ring,$ \,$ _sub_

__pow__( self, right)

sage: SR = SymbolicExpressionRing()
sage: a = SR(2)
sage: b = a^2; b
4
sage: type(b)
<class 'sage.calculus.calculus.SymbolicArithmetic'>

_add_( self, right)

sage: SR = SymbolicExpressionRing()
sage: a = SR(2)
sage: b = a+2; b
4
sage: type(b)
<class 'sage.calculus.calculus.SymbolicConstant'>
sage: b = sum([a for i in range(1000)]); b
2000
sage: type(_)
<class 'sage.calculus.calculus.SymbolicConstant'>

_algebraic_( self, field)

sage: a = SR(5/6)
sage: AA(a)
5/6
sage: type(AA(a))
<class 'sage.rings.qqbar.AlgebraicReal'>
sage: QQbar(a)
5/6
sage: type(QQbar(a))
<class 'sage.rings.qqbar.AlgebraicNumber'>
sage: from sage.calculus.calculus import SymbolicConstant
sage: i = SymbolicConstant(I)
sage: AA(i)
Traceback (most recent call last):
...    
TypeError: Cannot coerce algebraic number with non-zero imaginary part to
algebraic real
sage: QQbar(i)
1*I
sage: phi = SymbolicConstant(golden_ratio)
sage: AA(phi)
[1.6180339887498946 .. 1.6180339887498950]
sage: QQbar(phi)
[1.6180339887498946 .. 1.6180339887498950]

_div_( self, right)

sage: SR = SymbolicExpressionRing()
sage: a = SR(2)
sage: b = a/2; b
1
sage: type(b)
<class 'sage.calculus.calculus.SymbolicConstant'>
sage: b = SR(2^1000)
sage: for i in range(1000): b /= a;
sage: b
1
sage: type(b)
<class 'sage.calculus.calculus.SymbolicConstant'>

_mul_( self, right)

sage: SR = SymbolicExpressionRing()
sage: a = SR(2)
sage: b = a*2; b
4
sage: type(b)
<class 'sage.calculus.calculus.SymbolicConstant'>
sage: prod([a for i in range(1000)])
107150860718626732094842504906000181056140481170553360744375038837035105112
493612249319837881569585812759467291755314682518714528569231404359845775746
985748039345677748242309854210746050623711418779541821530464749835819412673
987675591655439460770629145711964776865421676604298316526243868372056680693
76
sage: type(_)
<class 'sage.calculus.calculus.SymbolicConstant'>

_recursive_sub( self, kwds)

sage: a = SR(5/6)
sage: type(a)
<class 'sage.calculus.calculus.SymbolicConstant'>
sage: a(x=3)
5/6

_sub_( self, right)

sage: SR = SymbolicExpressionRing()
sage: a = SR(2)
sage: b = a-2; b
0
sage: type(b)
<class 'sage.calculus.calculus.SymbolicConstant'>
sage: b = SR(2000)
sage: for i in range(1000): b -= a;
sage: b
0
sage: type(b)
<class 'sage.calculus.calculus.SymbolicConstant'>

Class: SymbolicExpression

class SymbolicExpression
A Symbolic Expression.

Some types of SymbolicExpressions:

sage: a = SR(2+2); a
4
sage: type(a)
<class 'sage.calculus.calculus.SymbolicConstant'>

SymbolicExpression( self)

Create a symbolic expression.

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

Functions: arguments,$ \,$ 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,$ \,$ integral,$ \,$ integrate,$ \,$ inverse_laplace,$ \,$ laplace,$ \,$ limit,$ \,$ log_simplify,$ \,$ minpoly,$ \,$ n,$ \,$ nintegral,$ \,$ nintegrate,$ \,$ norm,$ \,$ number_of_arguments,$ \,$ 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,$ \,$ variables

arguments( self)

Return the arguments of self, if we view self as a callable function.

This is the same as self.variables().

sage: x, theta, a = var('x, theta, a')
sage: f = x^2 + theta^3 - a^x; f
x^2 + theta^3 - a^x
sage: f.arguments()
(a, theta, x)

coeff( self, x, [n=1])

Returns the coefficient of $ x^n$ in self.

Input:

x
- variable, function, expression, etc.
n
- integer, default 1.

Sometimes it may be necessary to expand or factor first, since this is not done automatically.

sage: var('a, x, y, z')
(a, x, y, z)
sage: f = (a*sqrt(2))*x^2 + sin(y)*x^(1/2) + z^z   
sage: f.coefficient(sin(y))
sqrt(x)        
sage: f.coefficient(x^2)
sqrt(2)*a
sage: f.coefficient(x^(1/2))
sin(y)
sage: f.coefficient(1)
0
sage: f.coefficient(x, 0)
z^z

coefficient( self, x, [n=1])

Returns the coefficient of $ x^n$ in self.

Input:

x
- variable, function, expression, etc.
n
- integer, default 1.

Sometimes it may be necessary to expand or factor first, since this is not done automatically.

sage: var('a, x, y, z')
(a, x, y, z)
sage: f = (a*sqrt(2))*x^2 + sin(y)*x^(1/2) + z^z   
sage: f.coefficient(sin(y))
sqrt(x)        
sage: f.coefficient(x^2)
sqrt(2)*a
sage: f.coefficient(x^(1/2))
sin(y)
sage: f.coefficient(1)
0
sage: f.coefficient(x, 0)
z^z

coefficients( self, [x=None])

Coefficients of self as a polynomial in x.

Input:

x
- optional variable
Output: list of pairs [expr, n], where expr is a symbolic expression and n is a power.

sage: var('x, y, a')
(x, y, a)
sage: p = x^3 - (x-3)*(x^2+x) + 1
sage: p.coefficients()
[[1, 0], [3, 1], [2, 2]]
sage: p = expand((x-a*sqrt(2))^2 + x + 1); p
x^2 - 2*sqrt(2)*a*x + x + 2*a^2 + 1
sage: p.coefficients(a)
[[x^2 + x + 1, 0], [-2*sqrt(2)*x, 1], [2, 2]]
sage: p.coefficients(x)
[[2*a^2 + 1, 0], [1 - 2*sqrt(2)*a, 1], [1, 2]]

A polynomial with wacky exponents:

sage: p = (17/3*a)*x^(3/2) + x*y + 1/x + x^x
sage: p.coefficients(x)
[[1, -1], [x^x, 0], [y, 1], [17*a/3, 3/2]]

coeffs( self, [x=None])

Coefficients of self as a polynomial in x.

Input:

x
- optional variable
Output: list of pairs [expr, n], where expr is a symbolic expression and n is a power.

sage: var('x, y, a')
(x, y, a)
sage: p = x^3 - (x-3)*(x^2+x) + 1
sage: p.coefficients()
[[1, 0], [3, 1], [2, 2]]
sage: p = expand((x-a*sqrt(2))^2 + x + 1); p
x^2 - 2*sqrt(2)*a*x + x + 2*a^2 + 1
sage: p.coefficients(a)
[[x^2 + x + 1, 0], [-2*sqrt(2)*x, 1], [2, 2]]
sage: p.coefficients(x)
[[2*a^2 + 1, 0], [1 - 2*sqrt(2)*a, 1], [1, 2]]

A polynomial with wacky exponents:

sage: p = (17/3*a)*x^(3/2) + x*y + 1/x + x^x
sage: p.coefficients(x)
[[1, -1], [x^x, 0], [y, 1], [17*a/3, 3/2]]

combine( self)

Simplifies self by combining all terms with the same denominator into a single term.

sage: var('x, y, a, b, c')
(x, y, a, b, c)
sage: f = x*(x-1)/(x^2 - 7) + y^2/(x^2-7) + 1/(x+1) + b/a + c/a
sage: print f
                         2
                        y      (x - 1) x     1     c   b
                      ------ + --------- + ----- + - + -
                       2         2         x + 1   a   a
                      x  - 7    x  - 7
sage: print f.combine()
                         2
                        y  + (x - 1) x     1     c + b
                        -------------- + ----- + -----
                             2           x + 1     a
                            x  - 7

conjugate( self)

The complex conjugate of self.

sage: a = 1 + 2*I 
sage: a.conjugate()
1 - 2*I
sage: a = sqrt(2) + 3^(1/3)*I; a
3^(1/3)*I + sqrt(2)
sage: a.conjugate()
sqrt(2) - 3^(1/3)*I

default_variable( self)

Return the default variable, which is by definition the first variable in self, or $ x$ is there are no variables in self. The result is cached.

sage: sqrt(2).default_variable()
x        
sage: x, theta, a = var('x, theta, a')
sage: f = x^2 + theta^3 - a^x
sage: f.default_variable()
a

Note that this is the first variable, not the first argument:

sage: f(theta, a, x) = a + theta^3
sage: f.default_variable()
a
sage: f.variables()
(a, theta)
sage: f.arguments()
(theta, a, x)

denominator( self)

Return the denominator of self.

sage: var('x, y, z, theta')
(x, y, z, theta)
sage: f = (sqrt(x) + sqrt(y) + sqrt(z))/(x^10 - y^10 - sqrt(theta))
sage: print f
                          sqrt(z) + sqrt(y) + sqrt(x)
                          ---------------------------
                              10    10
                           - y   + x   - sqrt(theta)
sage: f.denominator()
-y^10 + x^10 - sqrt(theta)

derivative( self)

Derivative with respect to variables supplied in args.

Multiple variables and iteration counts may be supplied; see documentation for the global derivative() function for more details.

SEE ALSO: self._derivative()

sage: h = sin(x)/cos(x)
sage: derivative(h,x,x,x)
6*sin(x)^4/cos(x)^4 + 8*sin(x)^2/cos(x)^2 + 2
sage: derivative(h,x,3)
6*sin(x)^4/cos(x)^4 + 8*sin(x)^2/cos(x)^2 + 2

sage: var('x, y')
(x, y)
sage: u = (sin(x) + cos(y))*(cos(x) - sin(y))
sage: derivative(u,x,y)
sin(x)*sin(y) - cos(x)*cos(y)            
sage: f = ((x^2+1)/(x^2-1))^(1/4)
sage: g = derivative(f, x); g # this is a complex expression
x/(2*(x^2 - 1)^(1/4)*(x^2 + 1)^(3/4)) - x*(x^2 + 1)^(1/4)/(2*(x^2 -
1)^(5/4))
sage: g.simplify_rational()
-x/((x^2 - 1)^(5/4)*(x^2 + 1)^(3/4))

sage: f = y^(sin(x))
sage: derivative(f, x)
cos(x)*y^sin(x)*log(y)

sage: g(x) = sqrt(5-2*x)
sage: g_3 = derivative(g, x, 3); g_3(2)
-3

sage: f = x*e^(-x)
sage: derivative(f, 100)
x*e^(-x) - 100*e^(-x)

sage: g = 1/(sqrt((x^2-1)*(x+5)^6))
sage: derivative(g, x)
-3*(x + 5)^5/(((x + 5)^6)^(3/2)*sqrt(x^2 - 1)) - x/(sqrt((x + 5)^6)*(x^2 -
1)^(3/2))

diff( self)

Derivative with respect to variables supplied in args.

Multiple variables and iteration counts may be supplied; see documentation for the global derivative() function for more details.

SEE ALSO: self._derivative()

sage: h = sin(x)/cos(x)
sage: derivative(h,x,x,x)
6*sin(x)^4/cos(x)^4 + 8*sin(x)^2/cos(x)^2 + 2
sage: derivative(h,x,3)
6*sin(x)^4/cos(x)^4 + 8*sin(x)^2/cos(x)^2 + 2

sage: var('x, y')
(x, y)
sage: u = (sin(x) + cos(y))*(cos(x) - sin(y))
sage: derivative(u,x,y)
sin(x)*sin(y) - cos(x)*cos(y)            
sage: f = ((x^2+1)/(x^2-1))^(1/4)
sage: g = derivative(f, x); g # this is a complex expression
x/(2*(x^2 - 1)^(1/4)*(x^2 + 1)^(3/4)) - x*(x^2 + 1)^(1/4)/(2*(x^2 -
1)^(5/4))
sage: g.simplify_rational()
-x/((x^2 - 1)^(5/4)*(x^2 + 1)^(3/4))

sage: f = y^(sin(x))
sage: derivative(f, x)
cos(x)*y^sin(x)*log(y)

sage: g(x) = sqrt(5-2*x)
sage: g_3 = derivative(g, x, 3); g_3(2)
-3

sage: f = x*e^(-x)
sage: derivative(f, 100)
x*e^(-x) - 100*e^(-x)

sage: g = 1/(sqrt((x^2-1)*(x+5)^6))
sage: derivative(g, x)
-3*(x + 5)^5/(((x + 5)^6)^(3/2)*sqrt(x^2 - 1)) - x/(sqrt((x + 5)^6)*(x^2 -
1)^(3/2))

differentiate( self)

Derivative with respect to variables supplied in args.

Multiple variables and iteration counts may be supplied; see documentation for the global derivative() function for more details.

SEE ALSO: self._derivative()

sage: h = sin(x)/cos(x)
sage: derivative(h,x,x,x)
6*sin(x)^4/cos(x)^4 + 8*sin(x)^2/cos(x)^2 + 2
sage: derivative(h,x,3)
6*sin(x)^4/cos(x)^4 + 8*sin(x)^2/cos(x)^2 + 2

sage: var('x, y')
(x, y)
sage: u = (sin(x) + cos(y))*(cos(x) - sin(y))
sage: derivative(u,x,y)
sin(x)*sin(y) - cos(x)*cos(y)            
sage: f = ((x^2+1)/(x^2-1))^(1/4)
sage: g = derivative(f, x); g # this is a complex expression
x/(2*(x^2 - 1)^(1/4)*(x^2 + 1)^(3/4)) - x*(x^2 + 1)^(1/4)/(2*(x^2 -
1)^(5/4))
sage: g.simplify_rational()
-x/((x^2 - 1)^(5/4)*(x^2 + 1)^(3/4))

sage: f = y^(sin(x))
sage: derivative(f, x)
cos(x)*y^sin(x)*log(y)

sage: g(x) = sqrt(5-2*x)
sage: g_3 = derivative(g, x, 3); g_3(2)
-3

sage: f = x*e^(-x)
sage: derivative(f, 100)
x*e^(-x) - 100*e^(-x)

sage: g = 1/(sqrt((x^2-1)*(x+5)^6))
sage: derivative(g, x)
-3*(x + 5)^5/(((x + 5)^6)^(3/2)*sqrt(x^2 - 1)) - x/(sqrt((x + 5)^6)*(x^2 -
1)^(3/2))

display2d( self, [onscreen=True])

Display self using ASCII art.

Input:

onscreen
- string (optional, default True) If True, displays; if False, returns string.

We display a fraction:

sage: var('x,y')
(x, y)
sage: f = (x^3+y)/(x+3*y^2+1); f
(y + x^3)/(3*y^2 + x + 1)
sage: print f
                                         3
                                    y + x
                                 ------------
                                    2
                                 3 y  + x + 1

Use onscreen=False to get the 2d string:

sage: f.display2d(onscreen=False)
'                                         3\r\n                            
y + x\r\n                                 ------------\r\n                 
2\r\n                                 3 y  + x + 1'

ASCII art really helps for the following integral:

sage: f = integral(sin(x^2)); f
sqrt(pi)*((sqrt(2)*I + sqrt(2))*erf((sqrt(2)*I + sqrt(2))*x/2) + (sqrt(2)*I
- sqrt(2))*erf((sqrt(2)*I - sqrt(2))*x/2))/8
sage: print f
                                             (sqrt(2)  I + sqrt(2)) x
       sqrt( pi) ((sqrt(2)  I + sqrt(2)) erf(------------------------)
                                                        2
                                                   (sqrt(2)  I - sqrt(2)) x
                      + (sqrt(2)  I - sqrt(2))
erf(------------------------))/8
                                                              2

exp_simplify( self)

Simplifies this symbolic expression, which can contain logs, exponentials, and radicals, by converting it into a form which is canonical over a large class of expressions and a given ordering of variables

DETAILS: This uses the Maxima radcan() command. From the Maxima documentation: "All functionally equivalent forms are mapped into a unique form. For a somewhat larger class of expressions, produces a regular form. Two equivalent expressions in this class do not necessarily have the same appearance, but their difference can be simplified by radcan to zero. For some expressions radcan is quite time consuming. This is the cost of exploring certain relationships among the components of the expression for simplifications based on factoring and partial fraction expansions of exponents."

ALIAS: radical_simplify, simplify_radical, simplify_log, log_simplify, exp_simplify, simplify_exp are all the same

sage: var('x,y,a')
(x, y, a)

sage: f = log(x*y)
sage: f.simplify_radical()
log(y) + log(x)

sage: f = (log(x+x^2)-log(x))^a/log(1+x)^(a/2)
sage: f.simplify_radical()
log(x + 1)^(a/2)

sage: f = (e^x-1)/(1+e^(x/2))
sage: f.simplify_exp()
e^(x/2) - 1

expand( self)

Expand this symbolic expression. Products of sums and exponentiated sums are multiplied out, numerators of rational expressions which are sums are split into their respective terms, and multiplications are distributed over addition at all levels.

For polynomials one should usually use expand_rational which uses a more efficient algorithm.

We expand the expression $ (x-y)^5$ using both method and functional notation.

sage: x,y = var('x,y')
sage: a = (x-y)^5
sage: a.expand()
-y^5 + 5*x*y^4 - 10*x^2*y^3 + 10*x^3*y^2 - 5*x^4*y + x^5
sage: expand(a)
-y^5 + 5*x*y^4 - 10*x^2*y^3 + 10*x^3*y^2 - 5*x^4*y + x^5

Note that expand_rational may be faster.

sage: a.expand_rational()
-y^5 + 5*x*y^4 - 10*x^2*y^3 + 10*x^3*y^2 - 5*x^4*y + x^5

We expand some other expressions:

sage: expand((x-1)^3/(y-1))
x^3/(y - 1) - 3*x^2/(y - 1) + 3*x/(y - 1) - 1/(y - 1)
sage: expand((x+sin((x+y)^2))^2)
sin(y^2 + 2*x*y + x^2)^2 + 2*x*sin(y^2 + 2*x*y + x^2) + x^2

expand_rational( self)

Expands self by multiplying out products of sums and exponentiated sums, combining fractions over a common denominator, cancelling the greatest common divisor of the numerator and denominator, then splitting the numerator (if a sum) into its respective terms divided by the denominator.

sage: x,y = var('x,y')
sage: a = (x-y)^5
sage: a.expand_rational()
-y^5 + 5*x*y^4 - 10*x^2*y^3 + 10*x^3*y^2 - 5*x^4*y + x^5
sage: a.rational_expand()
-y^5 + 5*x*y^4 - 10*x^2*y^3 + 10*x^3*y^2 - 5*x^4*y + x^5

ALIAS: rational_expand and expand_rational are the same

expand_trig( self, [full=False], [half_angles=False], [plus=True], [times=True])

Expands trigonometric and hyperbolic functions of sums of angles and of multiple angles occurring in self. For best results, self should already be expanded.

Input:

full
- (default: False) To enhance user control of simplification, this function expands only one level at a time by default, expanding sums of angles or multiple angles. To obtain full expansion into sines and cosines immediately, set the optional parameter full to True.
half_angles
- (default: False) If True, causes half-angles to be simplified away.
plus
- (default: True) Controls the sum rule; expansion of sums (e.g. `sin(x + y)') will take place only if plus is True.
times
- (default: True) Controls the product rule, expansion of products (e.g. sin(2*x)) will take place only if times is True.

Output:
- a symbolic expression

sage: sin(5*x).expand_trig()
sin(x)^5 - 10*cos(x)^2*sin(x)^3 + 5*cos(x)^4*sin(x)

sage: cos(2*x + var('y')).trig_expand()
cos(2*x)*cos(y) - sin(2*x)*sin(y)

We illustrate various options to this function:

sage: f = sin(sin(3*cos(2*x))*x)
sage: f.expand_trig()
sin(x*(3*cos(cos(2*x))^2*sin(cos(2*x)) - sin(cos(2*x))^3))
sage: f.expand_trig(full=True)
sin(x*(3*(sin(cos(x)^2)*cos(sin(x)^2) -
cos(cos(x)^2)*sin(sin(x)^2))*(sin(cos(x)^2)*sin(sin(x)^2) +
cos(cos(x)^2)*cos(sin(x)^2))^2 - (sin(cos(x)^2)*cos(sin(x)^2) -
cos(cos(x)^2)*sin(sin(x)^2))^3))
sage: sin(2*x).expand_trig(times=False)
sin(2*x)
sage: sin(2*x).expand_trig(times=True)
2*cos(x)*sin(x)
sage: sin(2 + x).expand_trig(plus=False)
sin(x + 2)
sage: sin(2 + x).expand_trig(plus=True)
cos(2)*sin(x) + sin(2)*cos(x)
sage: sin(x/2).expand_trig(half_angles=False)
sin(x/2)
sage: sin(x/2).expand_trig(half_angles=True)
sqrt(1 - cos(x))/sqrt(2)

ALIAS: trig_expand and expand_trig are the same

factor( self, [dontfactor=[]])

Factors self, containing any number of variables or functions, into factors irreducible over the integers.

Input:

self
- a symbolic expression
dontfactor
- list (default: []), a list of variables with respect to which factoring is not to occur. Factoring also will not take place with respect to any variables which are less important (using the variable ordering assumed for CRE form) than those on the `dontfactor' list.

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

sage: (x^3-y^3).factor()
(x - y)*(y^2 + x*y + x^2)
sage: factor(-8*y - 4*x + z^2*(2*y + x))
(2*y + x)*(z - 2)*(z + 2)
sage: f = -1 - 2*x - x^2 + y^2 + 2*x*y^2 + x^2*y^2
sage: F = factor(f/(36*(1 + 2*y + y^2)), dontfactor=[x])
sage: print F
                              2
                            (x  + 2 x + 1) (y - 1)
                            ----------------------
                                  36 (y + 1)

If you are factoring a polynomial with rational coefficients (and dontfactor is empty) the factorization is done using Singular instead of Maxima, so the following is very fast instead of dreadfully slow:

sage: var('x,y')
(x, y)
sage: (x^99 + y^99).factor()
(y + x)*(y^2 - x*y + x^2)*(y^6 - x^3*y^3 + x^6)*...

factor_list( self, [dontfactor=[]])

Returns a list of the factors of self, as computed by the factor command.

Input:

self
- a symbolic expression
dontfactor
- see docs for self.factor.

REMARK: If you already have a factored expression and just want to get at the individual factors, use self._factor_list() instead.

sage: var('x, y, z')
(x, y, z)
sage: f = x^3-y^3
sage: f.factor()
(x - y)*(y^2 + x*y + x^2)

Notice that the -1 factor is separated out:

sage: f.factor_list()
[(x - y, 1), (y^2 + x*y + x^2, 1)]

We factor a fairly straightforward expression:

sage: factor(-8*y - 4*x + z^2*(2*y + x)).factor_list()
[(z - 2, 1), (z + 2, 1), (2*y + x, 1)]

This function also works for quotients:

sage: f = -1 - 2*x - x^2 + y^2 + 2*x*y^2 + x^2*y^2
sage: g = f/(36*(1 + 2*y + y^2)); g
(x^2*y^2 + 2*x*y^2 + y^2 - x^2 - 2*x - 1)/(36*(y^2 + 2*y + 1))
sage: g.factor(dontfactor=[x])
(x^2 + 2*x + 1)*(y - 1)/(36*(y + 1))
sage: g.factor_list(dontfactor=[x])
[(x^2 + 2*x + 1, 1), (y - 1, 1), (36, -1), (y + 1, -1)]

An example, where one of the exponents is not an integer.

sage: var('x, u, v')
(x, u, v)
sage: f = expand((2*u*v^2-v^2-4*u^3)^2 * (-u)^3 * (x-sin(x))^3) 
sage: f.factor()                                 
u^3*(2*u*v^2 - v^2 - 4*u^3)^2*(sin(x) - x)^3     
sage: g = f.factor_list(); g                     
[(u, 3), (2*u*v^2 - v^2 - 4*u^3, 2), (sin(x) - x, 3)]

This example also illustrates that the exponents do not have to be integers.

sage: f = x^(2*sin(x)) * (x-1)^(sqrt(2)*x); f
(x - 1)^(sqrt(2)*x)*x^(2*sin(x))
sage: f.factor_list()
[(x - 1, sqrt(2)*x), (x, 2*sin(x))]

find_maximum_on_interval( self, a, b, [var=None], [tol=1.48e-08], [maxfun=500])

Numerically find the maximum of the expression self on the interval [a,b] (or [b,a]) along with the point at which the maximum is attained.

See the documentation for self.find_minimum_on_interval for more details.

sage: f = x*cos(x)
sage: f.find_maximum_on_interval(0,5)
(0.5610963381910451, 0.8603335890...)
sage: f.find_maximum_on_interval(0,5, tol=0.1, maxfun=10)
(0.561090323458081..., 0.857926501456)

find_minimum_on_interval( self, a, b, [var=None], [tol=1.48e-08], [maxfun=500])

Numerically find the minimum of the expression self on the interval [a,b] (or [b,a]) and the point at which it attains that minimum. Note that self must be a function of (at most) one variable.

Input:

var
- variable (default: first variable in self)
a,b
- endpoints of interval on which to minimize self.
tol
- the convergence tolerance
maxfun
- maximum function evaluations

Output:

minval - (float) the minimum value that self takes on in the interval [a,b]

x - (float) the point at which self takes on the minimum value

sage: f = x*cos(x)
sage: f.find_minimum_on_interval(1, 5)
(-3.2883713955908962, 3.42561846957)
sage: f.find_minimum_on_interval(1, 5, tol=1e-3)
(-3.288371361890984, 3.42575079030572)
sage: f.find_minimum_on_interval(1, 5, tol=1e-2, maxfun=10)
(-3.2883708459837844, 3.42508402203)
sage: show(f.plot(0, 20))
sage: f.find_minimum_on_interval(1, 15)
(-9.4772942594797929, 9.52933441095)

ALGORITHM: Uses scipy.optimize.fminbound which uses Brent's method.

Author: William Stein (2007-12-07)

find_root( self, a, b, [var=None], [xtol=1e-12], [rtol=4.5e-16], [maxiter=100], [full_output=False])

Numerically find a root of self on the closed interval [a,b] (or [b,a]) if possible, where self is a function in the one variable.

Input:

a, b
- endpoints of the interval
var
- optional variable
xtol, rtol
- the routine converges when a root is known to lie within xtol of the value return. Should be >= 0. The routine modifies this to take into account the relative precision of doubles.
maxiter
- integer; if convergence is not achieved in maxiter iterations, an error is raised. Must be >= 0.
full_output
- bool (default: False), if True, also return object that contains information about convergence.

Note that in this example both f(-2) and f(3) are positive, yet we still find a root in that interval.

sage: f = x^2 - 1
sage: f.find_root(-2, 3)
1.0
sage: z, result = f.find_root(-2, 3, full_output=True)
sage: result.converged
True
sage: result.flag
'converged'
sage: result.function_calls
11
sage: result.iterations
10
sage: result.root
1.0

More examples:

sage: (sin(x) + exp(x)).find_root(-10, 10)
-0.588532743981862...

An example with a square root:

sage: f = 1 + x + sqrt(x+2); f.find_root(-2,10)
-1.6180339887498949

Some examples that Ted Kosan came up with:

sage: t = var('t')
sage: v = 0.004*(9600*e^(-(1200*t)) - 2400*e^(-(300*t)))
sage: v.find_root(0, 0.002)
0.001540327067911417...

sage: a = .004*(8*e^(-(300*t)) - 8*e^(-(1200*t)))*(720000*e^(-(300*t)) - 11520000*e^(-(1200*t))) +.004*(9600*e^(-(1200*t)) - 2400*e^(-(300*t)))^2

There is a 0 very close to the origin:

sage: show(plot(a, 0, .002),xmin=0, xmax=.002)

Using solve does not work to find it:

sage: a.solve(t)
[]

However find_root works beautifully:

sage: a.find_root(0,0.002)
0.0004110514049349341...

We illustrate that root finding is only implemented in one dimension:

sage: x, y = var('x,y')
sage: (x-y).find_root(-2,2)
Traceback (most recent call last):
...
NotImplementedError: root finding currently only implemented in 1
dimension.

full_simplify( self)

Applies simplify_trig, simplify_rational, and simplify_radical to self (in that order).

ALIAS: simplfy_full and full_simplify are the same.

sage: a = log(8)/log(2)
sage: a.simplify_full()
3

sage: f = sin(x)^2 + cos(x)^2
sage: f.simplify_full()
1

sage: f = sin(x/(x^2 + x))
sage: f.simplify_full()
sin(1/(x + 1))

function( self)

Return a CallableSymbolicExpression, fixing a variable order to be the order of args.

We will use several symbolic variables in the examples below:

sage: var('x, y, z, t, a, w, n')
(x, y, z, t, a, w, n)

sage: u = sin(x) + x*cos(y)
sage: g = u.function(x,y)
sage: g(x,y)
x*cos(y) + sin(x)
sage: g(t,z)
t*cos(z) + sin(t)
sage: g(x^2, x^y)
x^2*cos(x^y) + sin(x^2)

sage: f = (x^2 + sin(a*w)).function(a,x,w); f
(a, x, w) |--> x^2 + sin(a*w)
sage: f(1,2,3)
sin(3) + 4

Using the function method we can obtain the above function $ f$ , but viewed as a function of different variables:

sage: h = f.function(w,a); h
(w, a) |--> x^2 + sin(a*w)

This notation also works:

sage: h(w,a) = f
sage: h
(w, a) |--> x^2 + sin(a*w)

You can even make a symbolic expression $ f$ into a function by writing f(x,y) = f:

sage: f = x^n + y^n; f
y^n + x^n
sage: f(x,y) = f
sage: f
(x, y) |--> y^n + x^n
sage: f(2,3)
3^n + 2^n

gradient( self)

Compute the gradient of a symbolic function. This function returns a vector whose components are the derivatives of the original function.

sage: x,y = var('x y')
sage: f = x^2+y^2
sage: f.gradient()
(2*x, 2*y)

hessian( self)

Compute the hessian of a function. This returns a matrix components are the 2nd partial derivatives of the original function.

sage: x,y = var('x y')
sage: f = x^2+y^2
sage: f.hessian()
[2 0]
[0 2]

imag( self)

Return the imaginary part of self.

sage: sqrt(-2).imag()
sqrt(2)

We simplify $ \ln(\exp(z))$ to $ z$ for $ -\pi<{\rm Im}(z)<=\pi$ :

sage: z = var('z')
sage: f = log(exp(z))
sage: assume(-pi < imag(z))
sage: assume(imag(z) <= pi)
sage: print f
      z
sage: forget()

A more symbolic example:

sage: var('a, b')
(a, b)
sage: f = log(a + b*I)
sage: f.imag()
arctan(b/a)

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

Returns the indefinite integral with respect to the variable $ v$ , ignoring the constant of integration. Or, if endpoints $ a$ and $ b$ are specified, returns the definite integral over the interval $ [a, b]$ .

If self has only one variable, then it returns the integral with respect to that variable.

Input:

v
- (optional) a variable or variable name
a
- (optional) lower endpoint of definite integral
b
- (optional) upper endpoint of definite integral

sage: h = sin(x)/(cos(x))^2
sage: h.integral(x)
1/cos(x)

sage: f = x^2/(x+1)^3
sage: f.integral()
log(x + 1) + (4*x + 3)/(2*x^2 + 4*x + 2)

sage: f = x*cos(x^2)
sage: f.integral(x, 0, sqrt(pi))
0
sage: f.integral(a=-pi, b=pi)
0

sage: f(x) = sin(x)
sage: f.integral(x, 0, pi/2)
1

Constraints are sometimes needed:

sage: var('x, n')
(x, n)
sage: integral(x^n,x)
Traceback (most recent call last):
...
TypeError: Computation failed since Maxima requested additional constraints
(use assume):
Is  n+1  zero or nonzero?
sage: assume(n > 0)
sage: integral(x^n,x)
x^(n + 1)/(n + 1)
sage: forget()

Note that an exception is raised when a definite integral is divergent.

sage: integrate(1/x^3,x,0,1)
Traceback (most recent call last):
...
ValueError: Integral is divergent.
sage: integrate(1/x^3,x,-1,3) 
Traceback (most recent call last):
...
ValueError: Integral is divergent.

NOTE: Above, putting assume(n == -1) does not yield the right behavior. Directly in maxima, doing

The examples in the Maxima documentation:

sage: var('x, y, z, b')
(x, y, z, b)
sage: integral(sin(x)^3)
cos(x)^3/3 - cos(x)
sage: integral(x/sqrt(b^2-x^2))
x*log(2*sqrt(b^2 - x^2) + 2*b)
sage: integral(x/sqrt(b^2-x^2), x)
-sqrt(b^2 - x^2)
sage: integral(cos(x)^2 * exp(x), x, 0, pi)
3*e^pi/5 - 3/5
sage: integral(x^2 * exp(-x^2), x, -oo, oo)
sqrt(pi)/2

We integrate the same function in both Mathematica and Sage (via Maxima):

sage: f = sin(x^2) + y^z
sage: g = mathematica(f)                           # optional  -- requires mathematica
sage: print g                                      # optional
          z        2
         y  + Sin[x ]
sage: print g.Integrate(x)                         # optional
            z        Pi                2
         x y  + Sqrt[--] FresnelS[Sqrt[--] x]
                     2                 Pi
sage: print f.integral(x)
      z                                         (sqrt(2)  I + sqrt(2)) x
   x y  + sqrt( pi) ((sqrt(2)  I + sqrt(2)) erf(------------------------)
                                                           2
                                               (sqrt(2)  I - sqrt(2)) x
                  + (sqrt(2)  I - sqrt(2)) erf(------------------------))/8
                                                          2

We integrate the above function in maple now:

sage: g = maple(f); g                             # optional -- requires maple
sin(x^2)+y^z
sage: g.integrate(x)                              # optional -- requires maple
1/2*2^(1/2)*Pi^(1/2)*FresnelS(2^(1/2)/Pi^(1/2)*x)+y^z*x

We next integrate a function with no closed form integral. Notice that the answer comes back as an expression that contains an integral itself.

sage: A = integral(1/ ((x-4) * (x^3+2*x+1)), x); A
log(x - 4)/73 - integrate((x^2 + 4*x + 18)/(x^3 + 2*x + 1), x)/73
sage: print A
                         /  2
                         [ x  + 4 x + 18
                         I ------------- dx
                         ]  3
            log(x - 4)   / x  + 2 x + 1
            ---------- - ------------------
                73               73

We now show that floats are not converted to rationals automatically since we by default have keepfloat: true in maxima.

sage: integral(e^(-x^2),x, 0, 0.1)       
0.0562314580091424*sqrt(pi)

ALIASES: integral() and integrate() are the same.

Here is example where we have to use assume:

sage: a,b = var('a,b')
sage: integrate(1/(x^3 *(a+b*x)^(1/3)), x)
Traceback (most recent call last):
...
TypeError: Computation failed since Maxima requested additional constraints
(use assume):
Is  a  positive or negative?

So we just assume that $ a>0$ and the integral works:

sage: assume(a>0)
sage: integrate(1/(x^3 *(a+b*x)^(1/3)), x)
2*b^2*arctan((2*(b*x + a)^(1/3) +
a^(1/3))/(sqrt(3)*a^(1/3)))/(3*sqrt(3)*a^(7/3)) - b^2*log((b*x + a)^(2/3) +
a^(1/3)*(b*x + a)^(1/3) + a^(2/3))/(9*a^(7/3)) + 2*b^2*log((b*x + a)^(1/3)
- a^(1/3))/(9*a^(7/3)) + (4*b^2*(b*x + a)^(5/3) - 7*a*b^2*(b*x +
a)^(2/3))/(6*a^2*(b*x + a)^2 - 12*a^3*(b*x + a) + 6*a^4)

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

Returns the indefinite integral with respect to the variable $ v$ , ignoring the constant of integration. Or, if endpoints $ a$ and $ b$ are specified, returns the definite integral over the interval $ [a, b]$ .

If self has only one variable, then it returns the integral with respect to that variable.

Input:

v
- (optional) a variable or variable name
a
- (optional) lower endpoint of definite integral
b
- (optional) upper endpoint of definite integral

sage: h = sin(x)/(cos(x))^2
sage: h.integral(x)
1/cos(x)

sage: f = x^2/(x+1)^3
sage: f.integral()
log(x + 1) + (4*x + 3)/(2*x^2 + 4*x + 2)

sage: f = x*cos(x^2)
sage: f.integral(x, 0, sqrt(pi))
0
sage: f.integral(a=-pi, b=pi)
0

sage: f(x) = sin(x)
sage: f.integral(x, 0, pi/2)
1

Constraints are sometimes needed:

sage: var('x, n')
(x, n)
sage: integral(x^n,x)
Traceback (most recent call last):
...
TypeError: Computation failed since Maxima requested additional constraints
(use assume):
Is  n+1  zero or nonzero?
sage: assume(n > 0)
sage: integral(x^n,x)
x^(n + 1)/(n + 1)
sage: forget()

Note that an exception is raised when a definite integral is divergent.

sage: integrate(1/x^3,x,0,1)
Traceback (most recent call last):
...
ValueError: Integral is divergent.
sage: integrate(1/x^3,x,-1,3) 
Traceback (most recent call last):
...
ValueError: Integral is divergent.

NOTE: Above, putting assume(n == -1) does not yield the right behavior. Directly in maxima, doing

The examples in the Maxima documentation:

sage: var('x, y, z, b')
(x, y, z, b)
sage: integral(sin(x)^3)
cos(x)^3/3 - cos(x)
sage: integral(x/sqrt(b^2-x^2))
x*log(2*sqrt(b^2 - x^2) + 2*b)
sage: integral(x/sqrt(b^2-x^2), x)
-sqrt(b^2 - x^2)
sage: integral(cos(x)^2 * exp(x), x, 0, pi)
3*e^pi/5 - 3/5
sage: integral(x^2 * exp(-x^2), x, -oo, oo)
sqrt(pi)/2

We integrate the same function in both Mathematica and Sage (via Maxima):

sage: f = sin(x^2) + y^z
sage: g = mathematica(f)                           # optional  -- requires mathematica
sage: print g                                      # optional
          z        2
         y  + Sin[x ]
sage: print g.Integrate(x)                         # optional
            z        Pi                2
         x y  + Sqrt[--] FresnelS[Sqrt[--] x]
                     2                 Pi
sage: print f.integral(x)
      z                                         (sqrt(2)  I + sqrt(2)) x
   x y  + sqrt( pi) ((sqrt(2)  I + sqrt(2)) erf(------------------------)
                                                           2
                                               (sqrt(2)  I - sqrt(2)) x
                  + (sqrt(2)  I - sqrt(2)) erf(------------------------))/8
                                                          2

We integrate the above function in maple now:

sage: g = maple(f); g                             # optional -- requires maple
sin(x^2)+y^z
sage: g.integrate(x)                              # optional -- requires maple
1/2*2^(1/2)*Pi^(1/2)*FresnelS(2^(1/2)/Pi^(1/2)*x)+y^z*x

We next integrate a function with no closed form integral. Notice that the answer comes back as an expression that contains an integral itself.

sage: A = integral(1/ ((x-4) * (x^3+2*x+1)), x); A
log(x - 4)/73 - integrate((x^2 + 4*x + 18)/(x^3 + 2*x + 1), x)/73
sage: print A
                         /  2
                         [ x  + 4 x + 18
                         I ------------- dx
                         ]  3
            log(x - 4)   / x  + 2 x + 1
            ---------- - ------------------
                73               73

We now show that floats are not converted to rationals automatically since we by default have keepfloat: true in maxima.

sage: integral(e^(-x^2),x, 0, 0.1)       
0.0562314580091424*sqrt(pi)

ALIASES: integral() and integrate() are the same.

Here is example where we have to use assume:

sage: a,b = var('a,b')
sage: integrate(1/(x^3 *(a+b*x)^(1/3)), x)
Traceback (most recent call last):
...
TypeError: Computation failed since Maxima requested additional constraints
(use assume):
Is  a  positive or negative?

So we just assume that $ a>0$ and the integral works:

sage: assume(a>0)
sage: integrate(1/(x^3 *(a+b*x)^(1/3)), x)
2*b^2*arctan((2*(b*x + a)^(1/3) +
a^(1/3))/(sqrt(3)*a^(1/3)))/(3*sqrt(3)*a^(7/3)) - b^2*log((b*x + a)^(2/3) +
a^(1/3)*(b*x + a)^(1/3) + a^(2/3))/(9*a^(7/3)) + 2*b^2*log((b*x + a)^(1/3)
- a^(1/3))/(9*a^(7/3)) + (4*b^2*(b*x + a)^(5/3) - 7*a*b^2*(b*x +
a)^(2/3))/(6*a^2*(b*x + a)^2 - 12*a^3*(b*x + a) + 6*a^4)

inverse_laplace( self, t, s)

Attempts to compute the inverse Laplace transform of self with respect to the variable $ t$ and transform parameter $ s$ . If this function cannot find a solution, a formal function is returned.

The function that is returned may be be viewed as a function of $ s$ .

DEFINITION: The inverse Laplace transform of a function $ F(s)$ , is the function $ f(t)$ defined by

$\displaystyle F(s) = \frac{1}{2\pi i} \int_{\gamma-i\infty}^{\gamma + i\infty} e^{st} F(s) dt,
$

where $ \gamma$ is chosen so that the contour path of integration is in the region of convergence of $ F(s)$ .

sage: var('w, m')
(w, m)
sage: f = (1/(w^2+10)).inverse_laplace(w, m); f
sin(sqrt(10)*m)/sqrt(10)
sage: laplace(f, m, w)
1/(w^2 + 10)

laplace( self, t, s)

Attempts to compute and return the Laplace transform of self with respect to the variable $ t$ and transform parameter $ s$ . If this function cannot find a solution, a formal function is returned.

The function that is returned may be be viewed as a function of $ s$ .

DEFINITION: The Laplace transform of a function $ f(t)$ , defined for all real numbers $ t \geq 0$ , is the function $ F(s)$ defined by

$\displaystyle F(s) = \int_{0}^{\infty} e^{-st} f(t) dt.
$

We compute a few Laplace transforms:

sage: var('x, s, z, t, t0')
(x, s, z, t, t0)
sage: sin(x).laplace(x, s)
1/(s^2 + 1)
sage: (z + exp(x)).laplace(x, s)
z/s + 1/(s - 1)
sage: log(t/t0).laplace(t, s)
(-log(t0) - log(s) - euler_gamma)/s

We do a formal calculation:

sage: f = function('f', x)
sage: g = f.diff(x); g
diff(f(x), x, 1)
sage: g.laplace(x, s)
s*laplace(f(x), x, s) - f(0)

A BATTLE BETWEEN the X-women and the Y-men (by David Joyner): Solve

$\displaystyle x' = -16y, x(0)=270, y' = -x + 1, y(0) = 90.
$

This models a fight between two sides, the "X-women" and the "Y-men", where the X-women have 270 initially and the Y-men have 90, but the Y-men are better at fighting, because of the higher factor of "-16" vs "-1", and also get an occasional reinforcement, because of the "+1" term.

sage: var('t')
t
sage: t = var('t')
sage: x = function('x', t)
sage: y = function('y', t)
sage: de1 = x.diff(t) + 16*y
sage: de2 = y.diff(t) + x - 1
sage: de1.laplace(t, s)
16*laplace(y(t), t, s) + s*laplace(x(t), t, s) - x(0)
sage: de2.laplace(t, s)
s*laplace(y(t), t, s) + laplace(x(t), t, s) - 1/s - y(0)

Next we form the augmented matrix of the above system:

        sage: A = matrix([[s, 16, 270],[1, s, 90+1/s]])   
        sage: E = A.echelon_form()
        sage: xt = E[0,2].inverse_laplace(s,t)
        sage: yt = E[1,2].inverse_laplace(s,t)
        sage: print xt
4 t	    - 4 t
  91  e      629  e
    		 - -------- + ----------- + 1
     2		   2
        sage: print yt
 4 t	     - 4 t
   91  e      629  e
    		    -------- + -----------
      8	    8
        sage: p1 = plot(xt,0,1/2,rgbcolor=(1,0,0))
        sage: p2 = plot(yt,0,1/2,rgbcolor=(0,1,0))
        sage: (p1+p2).save()

limit( self, [dir=None], [taylor=False])

Return the limit as the variable $ v$ approaches $ a$ from the given direction.

        expr.limit(x = a)
        expr.limit(x = a, dir='above')

Input:

dir
- (default: None); dir may have the value `plus' (or 'above') for a limit from above, `minus' (or 'below') for a limit from below, or may be omitted (implying a two-sided limit is to be computed).
taylor
- (default: False); if True, use Taylor series, which allows more integrals to be computed (but may also crash in some obscure cases due to bugs in Maxima).
**argv
- 1 named parameter

NOTE: The output may also use `und' (undefined), `ind' (indefinite but bounded), and `infinity' (complex infinity).

sage: f = (1+1/x)^x
sage: f.limit(x = oo)
e
sage: f.limit(x = 5)
7776/3125
sage: f.limit(x = 1.2)
2.0696157546720...
sage: f.limit(x = I, taylor=True)
(1 - I)^I
sage: f(1.2)
2.0696157546720...
sage: f(I)
(1 - I)^I
sage: CDF(f(I))
2.06287223508 + 0.74500706218*I
sage: CDF(f.limit(x = I))
2.06287223508 + 0.74500706218*I

More examples:

sage: limit(x*log(x), x = 0, dir='above')
0
sage: lim((x+1)^(1/x),x = 0)
e
sage: lim(e^x/x, x = oo)
+Infinity
sage: lim(e^x/x, x = -oo)
0
sage: lim(-e^x/x, x = oo)
-Infinity
sage: lim((cos(x))/(x^2), x = 0)
+Infinity
sage: lim(sqrt(x^2+1) - x, x = oo)
0
sage: lim(x^2/(sec(x)-1), x=0)
2
sage: lim(cos(x)/(cos(x)-1), x=0)
-Infinity
sage: lim(x*sin(1/x), x=0)
0

sage: f = log(log(x))/log(x)
sage: forget(); assume(x<-2); lim(f, x=0, taylor=True)
und

Here ind means "indefinite but bounded":

sage: lim(sin(1/x), x = 0)
ind

log_simplify( self)

Simplifies this symbolic expression, which can contain logs, exponentials, and radicals, by converting it into a form which is canonical over a large class of expressions and a given ordering of variables

DETAILS: This uses the Maxima radcan() command. From the Maxima documentation: "All functionally equivalent forms are mapped into a unique form. For a somewhat larger class of expressions, produces a regular form. Two equivalent expressions in this class do not necessarily have the same appearance, but their difference can be simplified by radcan to zero. For some expressions radcan is quite time consuming. This is the cost of exploring certain relationships among the components of the expression for simplifications based on factoring and partial fraction expansions of exponents."

ALIAS: radical_simplify, simplify_radical, simplify_log, log_simplify, exp_simplify, simplify_exp are all the same

sage: var('x,y,a')
(x, y, a)

sage: f = log(x*y)
sage: f.simplify_radical()
log(y) + log(x)

sage: f = (log(x+x^2)-log(x))^a/log(1+x)^(a/2)
sage: f.simplify_radical()
log(x + 1)^(a/2)

sage: f = (e^x-1)/(1+e^(x/2))
sage: f.simplify_exp()
e^(x/2) - 1

minpoly( self, [bits=None], [degree=None], [epsilon=0])

Return the minimal polynomial of self, if possible.

Input:

bits
- the number of bits to use in numerical approx
degree
- the expected algebraic degree
epsilon
- return without error as long as f(self) < epsilon, in the case that the result cannot be proven.

All of the above parameters are optional, with epsilon=0, bits and degree tested up to 1000 and 24 by default respectively. If these are known, it will be faster to give them explicitly.

Output: The minimal polynomial of self. This is proved symbolically if epsilon=0 (default).

If the minimal polynomial could not be found, two distinct kinds of errors are raised. If no reasonable candidate was found with the given bit/degree parameters, a ValueError will be raised. If a reasonable candidate was found but (perhaps due to limits in the underlying symbolic package) was unable to be proved correct, a NotImplementedError will be raised.

ALGORITHM: Use the PARI algdep command on a numerical approximation of self to get a candidate minpoly $ f$ . Approximate $ f(\code{self})$ to higher precision and if the result is still close enough to 0 then evaluate $ f(\code{self})$ symbolically, attempting to prove vanishing. If this fails, and epsilon is non-zero, return $ f$ as long as $ f(\code{self}) < \var{epsilon}$ . Otherwise raise an error.

NOTE: Failure of this function does not prove self is not algebraic.

First some simple examples:

sage: sqrt(2).minpoly()
x^2 - 2
sage: a = 2^(1/3)
sage: a.minpoly()
x^3 - 2
sage: (sqrt(2)-3^(1/3)).minpoly()
x^6 - 6*x^4 + 6*x^3 + 12*x^2 + 36*x + 1

Sometimes it fails.

sage: sin(1).minpoly()
Traceback (most recent call last):
...
ValueError: Could not find minimal polynomial (1000 bits, degree 24).

Note that simplification may be necessary.

sage: a = sqrt(2)+sqrt(3)+sqrt(5)
sage: f = a.minpoly(); f
x^8 - 40*x^6 + 352*x^4 - 960*x^2 + 576
sage: f(a)
(sqrt(5) + sqrt(3) + sqrt(2))^2*((sqrt(5) + sqrt(3) + sqrt(2))^2*((sqrt(5)
+ sqrt(3) + sqrt(2))^2*((sqrt(5) + sqrt(3) + sqrt(2))^2 - 40) + 352) - 960)
+ 576
sage: f(a).simplify_radical()
0

Here we verify it gives the same result as the abstract number field.

sage: (sqrt(2) + sqrt(3) + sqrt(6)).minpoly()
x^4 - 22*x^2 - 48*x - 23
sage: K.<a,b> = NumberField([x^2-2, x^2-3])
sage: (a+b+a*b).absolute_minpoly()
x^4 - 22*x^2 - 48*x - 23

Works with trig functions too.

sage: sin(pi/3).minpoly()
x^2 - 3/4

Here we show use of the epsilon parameter. That this result is actually exact can be shown using the addition formula for sin, but maxima is unable to see that.

sage: a = sin(pi/5)
sage: a.minpoly()
Traceback (most recent call last):
...
NotImplementedError: Could not prove minimal polynomial x^4 - 5/4*x^2 +
5/16 (epsilon 0.00000000000000e-1)
sage: f = a.minpoly(epsilon=1e-100); f
x^4 - 5/4*x^2 + 5/16
sage: f(a).numerical_approx(100)
0.00000000000000000000000000000

The degree must be high enough (default tops out at 24).

sage: a = sqrt(3) + sqrt(2)
sage: a.minpoly(bits=100, degree=3)
Traceback (most recent call last):
...
ValueError: Could not find minimal polynomial (100 bits, degree 3).
sage: a.minpoly(bits=100, degree=10)
x^4 - 10*x^2 + 1

Here we solve a cubic and then recover it from its complicated radical expansion.

sage: f = x^3 - x + 1
sage: a = f.solve(x)[0].rhs(); a
(sqrt(3)*I/2 - 1/2)/(3*(sqrt(23)/(6*sqrt(3)) - 1/2)^(1/3)) +
(sqrt(23)/(6*sqrt(3)) - 1/2)^(1/3)*(-sqrt(3)*I/2 - 1/2)
sage: a.minpoly()
x^3 - x + 1

n( self, [prec=None], [digits=None])

Return a numerical approximation of self as either a real or complex number with at least the requested number of bits or digits of precision.

NOTE: You can use foo.n() as a shortcut for foo.numerical_approx().

Input:

prec
- an integer: the number of bits of precision
digits
- an integer: digits of precision

Output: A RealNumber or ComplexNumber approximation of self with prec bits of precision.

sage: cos(3).numerical_approx()
-0.989992496600445

Use the n() shortcut:

sage: cos(3).n()
-0.989992496600445

Higher precision:

sage: cos(3).numerical_approx(200)
-0.98999249660044545727157279473126130239367909661558832881409
sage: numerical_approx(cos(3), digits=10)
-0.9899924966
sage: (i + 1).numerical_approx(32)
1.00000000 + 1.00000000*I
sage: (pi + e + sqrt(2)).numerical_approx(100)
7.2740880444219335226246195788

nintegral( self, x, a, b, [desired_relative_error=1e-8], [maximum_num_subintervals=200])

Return a floating point machine precision numerical approximation to the integral of self from $ a$ to $ b$ , computed using floating point arithmetic via maxima.

Input:

x
- variable to integrate with respect to
a
- lower endpoint of integration
b
- upper endpoint of integration
desired_relative_error
- (default: '1e-8') the desired relative error
maximum_num_subintervals
- (default: 200) maxima number of subintervals

Output:
- float: approximation to the integral
- float: estimated absolute error of the approximation
- the number of integrand evaluations
- an error code:
0
- no problems were encountered
1
- too many subintervals were done
2
- excessive roundoff error
3
- extremely bad integrand behavior
4
- failed to converge
5
- integral is probably divergent or slowly convergent
6
- the input is invalid

ALIAS: nintegrate is the same as nintegral

REMARK: There is also a function numerical_integral that implements numerical integration using the GSL C library. It is potentially much faster and applies to arbitrary user defined functions.

Also, there are limits to the precision to which Maxima can compute the integral to due to limitations in quadpack.

sage: f = x
sage: f = f.nintegral(x,0,1,1e-14)
Traceback (most recent call last):
...
ValueError: Maxima (via quadpack) cannot compute the integral to that
precision

sage: f(x) = exp(-sqrt(x))
sage: f.nintegral(x, 0, 1)
(0.52848223531423055, 4.163...e-11, 231, 0)

We can also use the numerical_integral function, which calls the GSL C library.

sage: numerical_integral(f, 0, 1)       # random low-order bits
(0.52848223225314706, 6.8392846084921134e-07)

Note that in exotic cases where floating point evaluation of the expression leads to the wrong value, then the output can be completely wrong:

sage: f = exp(pi*sqrt(163)) - 262537412640768744

Despite appearance, $ f$ is really very close to 0, but one gets a nonzero value since the definition of float(f) is that it makes all constants inside the expression floats, then evaluates each function and each arithmetic operation using float arithmetic:

sage: float(f)
-480.0

Computing to higher precision we see the truth:

sage: f.n(200)
-7.4992740280181431112064614366622348652078895136533593355718e-13
sage: f.n(300)
-7.499274028018143111206461436626630091372924625896217893520950661817090955
75681963967103004e-13

Now numerically integrating, we see why the answer is wrong:

sage: f.nintegrate(x,0,1)
(-480.00000000000011, 5.3290705182007538e-12, 21, 0)

It is just because every floating point evaluation of return -480.0 in floating point.

Important note: using GP/PARI one can compute numerical integrals to high precision:

sage: gp.eval('intnum(x=17,42,exp(-x^2)*log(x))')
'2.565728500561051482917356396 E-127'        # 32-bit
'2.5657285005610514829173563961304785900 E-127'    # 64-bit
sage: old_prec = gp.set_real_precision(50)
sage: gp.eval('intnum(x=17,42,exp(-x^2)*log(x))')
'2.5657285005610514829173563961304785900147709554020 E-127'
sage: gp.set_real_precision(old_prec)
57

Note that the input function above is a string in PARI syntax.

nintegrate( self, x, a, b, [desired_relative_error=1e-8], [maximum_num_subintervals=200])

Return a floating point machine precision numerical approximation to the integral of self from $ a$ to $ b$ , computed using floating point arithmetic via maxima.

Input:

x
- variable to integrate with respect to
a
- lower endpoint of integration
b
- upper endpoint of integration
desired_relative_error
- (default: '1e-8') the desired relative error
maximum_num_subintervals
- (default: 200) maxima number of subintervals

Output:
- float: approximation to the integral
- float: estimated absolute error of the approximation
- the number of integrand evaluations
- an error code:
0
- no problems were encountered
1
- too many subintervals were done
2
- excessive roundoff error
3
- extremely bad integrand behavior
4
- failed to converge
5
- integral is probably divergent or slowly convergent
6
- the input is invalid

ALIAS: nintegrate is the same as nintegral

REMARK: There is also a function numerical_integral that implements numerical integration using the GSL C library. It is potentially much faster and applies to arbitrary user defined functions.

Also, there are limits to the precision to which Maxima can compute the integral to due to limitations in quadpack.

sage: f = x
sage: f = f.nintegral(x,0,1,1e-14)
Traceback (most recent call last):
...
ValueError: Maxima (via quadpack) cannot compute the integral to that
precision

sage: f(x) = exp(-sqrt(x))
sage: f.nintegral(x, 0, 1)
(0.52848223531423055, 4.163...e-11, 231, 0)

We can also use the numerical_integral function, which calls the GSL C library.

sage: numerical_integral(f, 0, 1)       # random low-order bits
(0.52848223225314706, 6.8392846084921134e-07)

Note that in exotic cases where floating point evaluation of the expression leads to the wrong value, then the output can be completely wrong:

sage: f = exp(pi*sqrt(163)) - 262537412640768744

Despite appearance, $ f$ is really very close to 0, but one gets a nonzero value since the definition of float(f) is that it makes all constants inside the expression floats, then evaluates each function and each arithmetic operation using float arithmetic:

sage: float(f)
-480.0

Computing to higher precision we see the truth:

sage: f.n(200)
-7.4992740280181431112064614366622348652078895136533593355718e-13
sage: f.n(300)
-7.499274028018143111206461436626630091372924625896217893520950661817090955
75681963967103004e-13

Now numerically integrating, we see why the answer is wrong:

sage: f.nintegrate(x,0,1)
(-480.00000000000011, 5.3290705182007538e-12, 21, 0)

It is just because every floating point evaluation of return -480.0 in floating point.

Important note: using GP/PARI one can compute numerical integrals to high precision:

sage: gp.eval('intnum(x=17,42,exp(-x^2)*log(x))')
'2.565728500561051482917356396 E-127'        # 32-bit
'2.5657285005610514829173563961304785900 E-127'    # 64-bit
sage: old_prec = gp.set_real_precision(50)
sage: gp.eval('intnum(x=17,42,exp(-x^2)*log(x))')
'2.5657285005610514829173563961304785900147709554020 E-127'
sage: gp.set_real_precision(old_prec)
57

Note that the input function above is a string in PARI syntax.

norm( self)

The complex norm of self, i.e., self times its complex conjugate.

sage: a = 1 + 2*I 
sage: a.norm()
5
sage: a = sqrt(2) + 3^(1/3)*I; a
3^(1/3)*I + sqrt(2)
sage: a.norm()
3^(2/3) + 2
sage: CDF(a).norm()
4.08008382305
sage: CDF(a.norm())
4.08008382305

number_of_arguments( self)

Returns the number of arguments the object can take.

sage: a,b,c = var('a,b,c')
sage: foo = function('foo', a,b,c)
sage: foo.number_of_arguments()
3

numerator( self)

sage: var('a,x,y')
(a, x, y)
sage: f = x*(x-a)/((x^2 - y)*(x-a))
sage: print f
                                      x
                                    ------
                                     2
                                    x  - y
sage: f.numerator()
x
sage: f.denominator()
x^2 - y

numerical_approx( self, [prec=None], [digits=None])

Return a numerical approximation of self as either a real or complex number with at least the requested number of bits or digits of precision.

NOTE: You can use foo.n() as a shortcut for foo.numerical_approx().

Input:

prec
- an integer: the number of bits of precision
digits
- an integer: digits of precision

Output: A RealNumber or ComplexNumber approximation of self with prec bits of precision.

sage: cos(3).numerical_approx()
-0.989992496600445

Use the n() shortcut:

sage: cos(3).n()
-0.989992496600445

Higher precision:

sage: cos(3).numerical_approx(200)
-0.98999249660044545727157279473126130239367909661558832881409
sage: numerical_approx(cos(3), digits=10)
-0.9899924966
sage: (i + 1).numerical_approx(32)
1.00000000 + 1.00000000*I
sage: (pi + e + sqrt(2)).numerical_approx(100)
7.2740880444219335226246195788

partial_fraction( self, [var=None])

Return the partial fraction expansion of self with respect to the given variable.

Input:

var
- variable name or string (default: first variable)

Output: Symbolic expression

sage: var('x')
x
sage: f = x^2/(x+1)^3
sage: f.partial_fraction()
1/(x + 1) - 2/(x + 1)^2 + 1/(x + 1)^3
sage: print f.partial_fraction()
                            1        2          1
                          ----- - -------- + --------
                          x + 1          2          3
                                  (x + 1)    (x + 1)

Notice that the first variable in the expression is used by default:

sage: var('y')
y
sage: f = y^2/(y+1)^3
sage: f.partial_fraction()
1/(y + 1) - 2/(y + 1)^2 + 1/(y + 1)^3

sage: f = y^2/(y+1)^3 + x/(x-1)^3
sage: f.partial_fraction()
y^2/(y^3 + 3*y^2 + 3*y + 1) + 1/(x - 1)^2 + 1/(x - 1)^3

You can explicitly specify which variable is used.

sage: f.partial_fraction(y)
1/(y + 1) - 2/(y + 1)^2 + 1/(y + 1)^3 + x/(x^3 - 3*x^2 + 3*x - 1)

plot( self)

Plot a symbolic expression.

All arguments are passed onto the standard plot command.

This displays a straight line:

sage: sin(2).plot((x,0,3))

This draws a red oscillatory curve:

sage: sin(x^2).plot((x,0,2*pi), rgbcolor=(1,0,0))

Another plot using the variable theta:

sage: var('theta')
theta
sage: (cos(theta) - erf(theta)).plot((theta,-2*pi,2*pi))

A very thick green plot with a frame:

sage: sin(x).plot((x,-4*pi, 4*pi), thickness=20, rgbcolor=(0,0.7,0)).show(frame=True)

You can embed 2d plots in 3d space as follows:

sage: plot(sin(x^2), (x,-pi, pi), thickness=2).plot3d(z = 1)

A more complicated family:

sage: G = sum([plot(sin(n*x), (x,-2*pi, 2*pi)).plot3d(z=n) for n in [0,0.1,..1]])
sage: G.show(frame_aspect_ratio=[1,1,1/2])

A plot involving the floor function:

sage: plot(1.0 - x * floor(1/x), (x,0.00001,1.0))

poly( self, [x=None])

Express self as a polynomial in $ x$ . If self is not a polynomial in $ x$ , then some coefficients may be functions of $ x$ .

WARNING: This is different from self.polynomial() which returns a Sage polynomial over a given base ring.

sage: var('a, x')
(a, x)
sage: p = expand((x-a*sqrt(2))^2 + x + 1); p
x^2 - 2*sqrt(2)*a*x + x + 2*a^2 + 1
sage: p.poly(a)
(x^2 + x + 1)*1 + -2*sqrt(2)*x*a + 2*a^2
sage: bool(expand(p.poly(a)) == p)
True            
sage: p.poly(x)
(2*a^2 + 1)*1 + (1 - 2*sqrt(2)*a)*x + 1*x^2

polynomial( self, base_ring)

Return self as an algebraic polynomial over the given base ring, if possible.

The point of this function is that it converts purely symbolic polynomials into optimized algebraic polynomials over a given base ring.

WARNING: This is different from self.poly(x) which is used to rewrite self as a polynomial in x.

Input:

base_ring
- a ring

sage: f = x^2 -2/3*x + 1
sage: f.polynomial(QQ)
x^2 - 2/3*x + 1
sage: f.polynomial(GF(19))
x^2 + 12*x + 1

Polynomials can be useful for getting the coefficients of an expression:

sage: g = 6*x^2 - 5
sage: g.coefficients()
[[-5, 0], [6, 2]]
sage: g.polynomial(QQ).list()
[-5, 0, 6]
sage: g.polynomial(QQ).dict()
{0: -5, 2: 6}

sage: f = x^2*e + x + pi/e
sage: f.polynomial(RDF)
2.71828182846*x^2 + 1.0*x + 1.15572734979
sage: g = f.polynomial(RR); g
2.71828182845905*x^2 + 1.00000000000000*x + 1.15572734979092
sage: g.parent()
Univariate Polynomial Ring in x over Real Field with 53 bits of precision  

sage: f.polynomial(RealField(100))
2.7182818284590452353602874714*x^2 + 1.0000000000000000000000000000*x +
1.1557273497909217179100931833
sage: f.polynomial(CDF)
2.71828182846*x^2 + 1.0*x + 1.15572734979
sage: f.polynomial(CC)
2.71828182845905*x^2 + 1.00000000000000*x + 1.15572734979092

We coerce a multivariate polynomial with complex symbolic coefficients:

sage: x, y, n = var('x, y, n')
sage: f = pi^3*x - y^2*e - I; f
-1*e*y^2 + pi^3*x - I
sage: f.polynomial(CDF)
(-2.71828182846)*y^2 + 31.0062766803*x - 1.0*I
sage: f.polynomial(CC)
(-2.71828182845905)*y^2 + 31.0062766802998*x - 1.00000000000000*I
sage: f.polynomial(ComplexField(70))
(-2.7182818284590452354)*y^2 + 31.006276680299820175*x -
1.0000000000000000000*I

Another polynomial:

sage: f = sum((e*I)^n*x^n for n in range(5)); f
e^4*x^4 - e^3*I*x^3 - e^2*x^2 + e*I*x + 1
sage: f.polynomial(CDF)
54.5981500331*x^4 + (-20.0855369232*I)*x^3 + (-7.38905609893)*x^2 +
2.71828182846*I*x + 1.0
sage: f.polynomial(CC)
54.5981500331442*x^4 + (-20.0855369231877*I)*x^3 + (-7.38905609893065)*x^2
+ 2.71828182845905*I*x + 1.00000000000000

A multivariate polynomial over a finite field:

sage: f = (3*x^5 - 5*y^5)^7; f
(3*x^5 - 5*y^5)^7
sage: g = f.polynomial(GF(7)); g
3*x^35 + 2*y^35
sage: parent(g)
Multivariate Polynomial Ring in x, y over Finite Field of size 7

power_series( self, base_ring)

Return algebraic power series associated to this symbolic expression, which must be a polynomial in one variable, with coefficients coercible to the base ring.

The power series is truncated one more than the degree.

sage: theta = var('theta')
sage: f = theta^3 + (1/3)*theta - 17/3
sage: g = f.power_series(QQ); g
-17/3 + 1/3*theta + theta^3 + O(theta^4)
sage: g^3
-4913/27 + 289/9*theta - 17/9*theta^2 + 2602/27*theta^3 + O(theta^4)
sage: g.parent()
Power Series Ring in theta over Rational Field

radical_simplify( self)

Simplifies this symbolic expression, which can contain logs, exponentials, and radicals, by converting it into a form which is canonical over a large class of expressions and a given ordering of variables

DETAILS: This uses the Maxima radcan() command. From the Maxima documentation: "All functionally equivalent forms are mapped into a unique form. For a somewhat larger class of expressions, produces a regular form. Two equivalent expressions in this class do not necessarily have the same appearance, but their difference can be simplified by radcan to zero. For some expressions radcan is quite time consuming. This is the cost of exploring certain relationships among the components of the expression for simplifications based on factoring and partial fraction expansions of exponents."

ALIAS: radical_simplify, simplify_radical, simplify_log, log_simplify, exp_simplify, simplify_exp are all the same

sage: var('x,y,a')
(x, y, a)

sage: f = log(x*y)
sage: f.simplify_radical()
log(y) + log(x)

sage: f = (log(x+x^2)-log(x))^a/log(1+x)^(a/2)
sage: f.simplify_radical()
log(x + 1)^(a/2)

sage: f = (e^x-1)/(1+e^(x/2))
sage: f.simplify_exp()
e^(x/2) - 1

rational_expand( self)

Expands self by multiplying out products of sums and exponentiated sums, combining fractions over a common denominator, cancelling the greatest common divisor of the numerator and denominator, then splitting the numerator (if a sum) into its respective terms divided by the denominator.

sage: x,y = var('x,y')
sage: a = (x-y)^5
sage: a.expand_rational()
-y^5 + 5*x*y^4 - 10*x^2*y^3 + 10*x^3*y^2 - 5*x^4*y + x^5
sage: a.rational_expand()
-y^5 + 5*x*y^4 - 10*x^2*y^3 + 10*x^3*y^2 - 5*x^4*y + x^5

ALIAS: rational_expand and expand_rational are the same

rational_simplify( self)

Simplify by expanding repeatedly rational expressions.

ALIAS: rational_simplify and simplify_rational are the same

sage: f = sin(x/(x^2 + x))
sage: f
sin(x/(x^2 + x))
sage: f.simplify_rational()
sin(1/(x + 1))

sage: f = ((x - 1)^(3/2) - (x + 1)*sqrt(x - 1))/sqrt((x - 1)*(x + 1))
sage: print f
                              3/2
                       (x - 1)    - sqrt(x - 1) (x + 1)
                       --------------------------------
                            sqrt((x - 1) (x + 1))
sage: print f.simplify_rational()
                                  2 sqrt(x - 1)
                                - -------------
                                        2
                                  sqrt(x  - 1)

real( self)

Return the real part of self.

sage: a = log(3+4*I)
sage: print a
                                 log(4  I + 3)
sage: print a.real()
                                    log(5)
sage: print a.imag()
                                         4
                                  arctan(-)
                                         3

Now make a and b symbolic and compute the general real part:

sage: var('a,b')
(a, b)
sage: f = log(a + b*I)
sage: f.real()
log(b^2 + a^2)/2

roots( self, [x=None], [explicit_solutions=True])

Returns roots of self that can be found exactly, with multiplicities. Not all root are guaranteed to be found.

WARNING: This is not a numerical solver - use find_root to solve for self == 0 numerically on an interval.

Input:

x
- variable to view the function in terms of (use default variable if not given)
explicit_solutions
- bool (default True); require that roots be explicit rather than implicit
Output: list of pairs (root, multiplicity)

If there are infinitely many roots, e.g., a function like $ \sin(x)$ , only one is returned.

sage: var('x, a')
(x, a)

A simple example:

sage: ((x^2-1)^2).roots()
[(-1, 2), (1, 2)]

A complicated example.

sage: f = expand((x^2 - 1)^3*(x^2 + 1)*(x-a)); f
x^9 - a*x^8 - 2*x^7 + 2*a*x^6 + 2*x^3 - 2*a*x^2 - x + a

The default variable is $ a$ , since it is the first in alphabetical order:

sage: f.roots()
[(x, 1)]

As a polynomial in $ a$ , $ x$ is indeed a root:

sage: f.poly(a)
(x^9 - 2*x^7 + 2*x^3 - x)*1 + (-x^8 + 2*x^6 - 2*x^2 + 1)*a
sage: f(a=x)
0

The roots in terms of $ x$ are what we expect:

sage: f.roots(x)
[(a, 1), (-1*I, 1), (I, 1), (1, 3), (-1, 3)]

Only one root of $ \sin(x) = 0$ is given:

sage: f = sin(x)    
sage: f.roots(x)
[(0, 1)]

We derive the roots of a general quadratic polynomial:

sage: var('a,b,c,x')
(a, b, c, x)
sage: (a*x^2 + b*x + c).roots(x)
[((-sqrt(b^2 - 4*a*c) - b)/(2*a), 1), ((sqrt(b^2 - 4*a*c) - b)/(2*a), 1)]

By default, all the roots are required to be explicit rather than implicit. To get implicit roots, pass explicit_solutions=False to .roots()

sage: var('x')
x
sage: f = x^(1/9) + (2^(8/9) - 2^(1/9))*(x - 1) - x^(8/9)
sage: f.roots()
Traceback (most recent call last):
...
RuntimeError: no explicit roots found
sage: f.roots(explicit_solutions=False)
[((x^(8/9) - x^(1/9) + 2^(8/9) - 2^(1/9))/(2^(8/9) - 2^(1/9)), 1)]

Another example, but involving a degree 5 poly whose roots don't get computed explicitly:

sage: f = x^5 + x^3 + 17*x + 1
sage: f.roots()
Traceback (most recent call last):
...
RuntimeError: no explicit roots found
sage: f.roots(explicit_solutions=False)
[(x^5 + x^3 + 17*x + 1, 1)]

show( self)

Show this symbolic expression, i.e., typeset it nicely.

sage: (x^2 + 1).show()
{x}^{2}  + 1

simplify( self)

Return the simplified form of this symbolic expression.

NOTE: Expressions always print simplified; a simplified expression is distinguished because the way it prints agrees with its underlyilng representation.

Output:

symbolic expression
- a simplified symbolic expression

We create the symbolic expression $ x - x + 1$ , which is of course equal to $ 1$ .

sage: Z = x - x + 1

It prints as $ 1$ but is really a symbolic arithmetic object, that has the information of the full expression:

sage: Z
1
sage: type(Z)
<class 'sage.calculus.calculus.SymbolicArithmetic'>

Calling simplify returns a new object $ W$ (it does not change $ Z$ ), which actually simplified:

sage: W = Z.simplify(); W
1

Thus $ W$ is a single constant:

sage: type(W)
<class 'sage.calculus.calculus.SymbolicConstant'>

The _has_been_simplified method tells whether an object was constructed by simplifying - or at least is known to be already simplified:

sage: Z._has_been_simplified()
False
sage: W._has_been_simplified()
True

Note that __init__ automatically calls _simp when a symbolic expression is created:

sage: f = x*x*x - (1+1+1)*x*x + 2 + 3 + 5 + 7 + 11; f
x^3 - 3*x^2 + 28
sage: x*x*x
x^3

simplify, however, can be called manually:

sage: f
x^3 - 3*x^2 + 28
sage: f.simplify()
x^3 - 3*x^2 + 28

simplify_exp( self)

Simplifies this symbolic expression, which can contain logs, exponentials, and radicals, by converting it into a form which is canonical over a large class of expressions and a given ordering of variables

DETAILS: This uses the Maxima radcan() command. From the Maxima documentation: "All functionally equivalent forms are mapped into a unique form. For a somewhat larger class of expressions, produces a regular form. Two equivalent expressions in this class do not necessarily have the same appearance, but their difference can be simplified by radcan to zero. For some expressions radcan is quite time consuming. This is the cost of exploring certain relationships among the components of the expression for simplifications based on factoring and partial fraction expansions of exponents."

ALIAS: radical_simplify, simplify_radical, simplify_log, log_simplify, exp_simplify, simplify_exp are all the same

sage: var('x,y,a')
(x, y, a)

sage: f = log(x*y)
sage: f.simplify_radical()
log(y) + log(x)

sage: f = (log(x+x^2)-log(x))^a/log(1+x)^(a/2)
sage: f.simplify_radical()
log(x + 1)^(a/2)

sage: f = (e^x-1)/(1+e^(x/2))
sage: f.simplify_exp()
e^(x/2) - 1

simplify_full( self)

Applies simplify_trig, simplify_rational, and simplify_radical to self (in that order).

ALIAS: simplfy_full and full_simplify are the same.

sage: a = log(8)/log(2)
sage: a.simplify_full()
3

sage: f = sin(x)^2 + cos(x)^2
sage: f.simplify_full()
1

sage: f = sin(x/(x^2 + x))
sage: f.simplify_full()
sin(1/(x + 1))

simplify_log( self)

Simplifies this symbolic expression, which can contain logs, exponentials, and radicals, by converting it into a form which is canonical over a large class of expressions and a given ordering of variables

DETAILS: This uses the Maxima radcan() command. From the Maxima documentation: "All functionally equivalent forms are mapped into a unique form. For a somewhat larger class of expressions, produces a regular form. Two equivalent expressions in this class do not necessarily have the same appearance, but their difference can be simplified by radcan to zero. For some expressions radcan is quite time consuming. This is the cost of exploring certain relationships among the components of the expression for simplifications based on factoring and partial fraction expansions of exponents."

ALIAS: radical_simplify, simplify_radical, simplify_log, log_simplify, exp_simplify, simplify_exp are all the same

sage: var('x,y,a')
(x, y, a)

sage: f = log(x*y)
sage: f.simplify_radical()
log(y) + log(x)

sage: f = (log(x+x^2)-log(x))^a/log(1+x)^(a/2)
sage: f.simplify_radical()
log(x + 1)^(a/2)

sage: f = (e^x-1)/(1+e^(x/2))
sage: f.simplify_exp()
e^(x/2) - 1

simplify_radical( self)

Simplifies this symbolic expression, which can contain logs, exponentials, and radicals, by converting it into a form which is canonical over a large class of expressions and a given ordering of variables

DETAILS: This uses the Maxima radcan() command. From the Maxima documentation: "All functionally equivalent forms are mapped into a unique form. For a somewhat larger class of expressions, produces a regular form. Two equivalent expressions in this class do not necessarily have the same appearance, but their difference can be simplified by radcan to zero. For some expressions radcan is quite time consuming. This is the cost of exploring certain relationships among the components of the expression for simplifications based on factoring and partial fraction expansions of exponents."

ALIAS: radical_simplify, simplify_radical, simplify_log, log_simplify, exp_simplify, simplify_exp are all the same

sage: var('x,y,a')
(x, y, a)

sage: f = log(x*y)
sage: f.simplify_radical()
log(y) + log(x)

sage: f = (log(x+x^2)-log(x))^a/log(1+x)^(a/2)
sage: f.simplify_radical()
log(x + 1)^(a/2)

sage: f = (e^x-1)/(1+e^(x/2))
sage: f.simplify_exp()
e^(x/2) - 1

simplify_rational( self)

Simplify by expanding repeatedly rational expressions.

ALIAS: rational_simplify and simplify_rational are the same

sage: f = sin(x/(x^2 + x))
sage: f
sin(x/(x^2 + x))
sage: f.simplify_rational()
sin(1/(x + 1))

sage: f = ((x - 1)^(3/2) - (x + 1)*sqrt(x - 1))/sqrt((x - 1)*(x + 1))
sage: print f
                              3/2
                       (x - 1)    - sqrt(x - 1) (x + 1)
                       --------------------------------
                            sqrt((x - 1) (x + 1))
sage: print f.simplify_rational()
                                  2 sqrt(x - 1)
                                - -------------
                                        2
                                  sqrt(x  - 1)

simplify_trig( self)

First expands using trig_expand, then employs the identities $ \sin(x)^2 + \cos(x)^2 = 1$ and $ \cosh(x)^2 - \sin(x)^2 = 1$ to simplify expressions containing tan, sec, etc., to sin, cos, sinh, cosh.

ALIAS: trig_simplify and simplify_trig are the same

sage: f = sin(x)^2 + cos(x)^2; f
sin(x)^2 + cos(x)^2
sage: f.simplify()
sin(x)^2 + cos(x)^2
sage: f.simplify_trig()
1

solve( self, x, [multiplicities=False], [explicit_solutions=False])

Analytically solve the equation self == 0 for the variable $ x$ .

WARNING: This is not a numerical solver - use find_root to solve for self == 0 numerically on an interval.

Input:

x
- variable to solve for
multiplicities
- bool (default: False); if True, return corresponding multiplicities.
explicit_solutions
- bool (default:False); if True, require that all solutions returned be explicit (rather than implicit)

sage: z = var('z')
sage: (z^5 - 1).solve(z)
[z == e^(2*I*pi/5), z == e^(4*I*pi/5), z == e^(-(4*I*pi/5)), z ==
e^(-(2*I*pi/5)), z == 1]

subs_expr( self)

Given a dictionary of key:value pairs, substitute all occurences of key for value in self.

WARNING: This is a formal pattern substitution, which may or may not have any mathematical meaning. The exact rules used at present in Sage are determined by Maxima's subst command. Sometimes patterns are not replaced even though one would think they should be - see examples below.

sage: f = x^2 + 1
sage: f.subs_expr(x^2 == x)
x + 1

sage: var('x,y,z'); f = x^3 + y^2 + z
(x, y, z)
sage: f.subs_expr(x^3 == y^2, z == 1)
2*y^2 + 1

sage: f = x^2 + x^4
sage: f.subs_expr(x^2 == x)
x^4 + x
sage: f = cos(x^2) + sin(x^2)
sage: f.subs_expr(x^2 == x)
sin(x) + cos(x)

sage: f(x,y,t) = cos(x) + sin(y) + x^2 + y^2 + t
sage: f.subs_expr(y^2 == t)
(x, y, t) |--> sin(y) + cos(x) + x^2 + 2*t

The following seems really weird, but it *is* what maple does:

sage: f.subs_expr(x^2 + y^2 == t)
(x, y, t) |--> sin(y) + y^2 + cos(x) + x^2 + t        
sage: maple.eval('subs(x^2 + y^2 = t, cos(x) + sin(y) + x^2 + y^2 + t)')          # optional requires maple
'cos(x)+sin(y)+x^2+y^2+t'
sage: maxima.quit()
sage: maxima.eval('cos(x) + sin(y) + x^2 + y^2 + t, x^2 + y^2 = t')
'sin(y)+y^2+cos(x)+x^2+t'

Actually Mathematica does something that makes more sense:

sage: mathematica.eval('Cos[x] + Sin[y] + x^2 + y^2 + t /. x^2 + y^2 -> t')       # optional -- requires mathematica
2 t + Cos[x] + Sin[y]

substitute( self, [in_dict=None])

Takes the symbolic variables given as dict keys or as keywords and replaces them with the symbolic expressions given as dict values or as keyword values. Also run when you call a SymbolicExpression.

Input:

in_dict
- (optional) dictionary of inputs
**kwds
- named parameters

sage: x,y,t = var('x,y,t')
sage: u = 3*y
sage: u.substitute(y=t)
3*t

sage: u = x^3 - 3*y + 4*t
sage: u.substitute(x=y, y=t)
y^3 + t

sage: f = sin(x)^2 + 32*x^(y/2)
sage: f(x=2, y = 10)
sin(2)^2 + 1024

sage: f(x=pi, y=t)
32*pi^(t/2)

sage: f = x
sage: f.variables()
(x,)

sage: f = 2*x
sage: f.variables()
(x,)

sage: f = 2*x^2 - sin(x)
sage: f.variables()
(x,)
sage: f(pi)
2*pi^2
sage: f(x=pi)
2*pi^2

sage: function('f',x)
f(x)
sage: (f(x)).substitute(f=log)
log(x)
sage: (f(x)).substitute({f:log})
log(x)
sage: (x^3 + 1).substitute(x=5)
126
sage: (x^3 + 1).substitute({x:5})
126

Author: Bobby Moretti: Initial version

taylor( self, v, a, n)

Expands self in a truncated Taylor or Laurent series in the variable $ v$ around the point $ a$ , containing terms through $ (x - a)^n$ .

Input:

v
- variable
a
- number
n
- integer

sage: var('a, x, z')
(a, x, z)
sage: taylor(a*log(z), z, 2, 3)
log(2)*a + a*(z - 2)/2 - a*(z - 2)^2/8 + a*(z - 2)^3/24
sage: taylor(sqrt (sin(x) + a*x + 1), x, 0, 3)
1 + (a + 1)*x/2 - (a^2 + 2*a + 1)*x^2/8 + (3*a^3 + 9*a^2 + 9*a - 1)*x^3/48
sage: taylor (sqrt (x + 1), x, 0, 5)
1 + x/2 - x^2/8 + x^3/16 - 5*x^4/128 + 7*x^5/256
sage: taylor (1/log (x + 1), x, 0, 3)
1/x + 1/2 - x/12 + x^2/24 - 19*x^3/720
sage: taylor (cos(x) - sec(x), x, 0, 5)
-x^2 - x^4/6
sage: taylor ((cos(x) - sec(x))^3, x, 0, 9)
-x^6 - x^8/2
sage: taylor (1/(cos(x) - sec(x))^3, x, 0, 5)
-1/x^6 + 1/(2*x^4) + 11/(120*x^2) - 347/15120 - 6767*x^2/604800 -
15377*x^4/7983360

trig_expand( self, [full=False], [half_angles=False], [plus=True], [times=True])

Expands trigonometric and hyperbolic functions of sums of angles and of multiple angles occurring in self. For best results, self should already be expanded.

Input:

full
- (default: False) To enhance user control of simplification, this function expands only one level at a time by default, expanding sums of angles or multiple angles. To obtain full expansion into sines and cosines immediately, set the optional parameter full to True.
half_angles
- (default: False) If True, causes half-angles to be simplified away.
plus
- (default: True) Controls the sum rule; expansion of sums (e.g. `sin(x + y)') will take place only if plus is True.
times
- (default: True) Controls the product rule, expansion of products (e.g. sin(2*x)) will take place only if times is True.

Output:
- a symbolic expression

sage: sin(5*x).expand_trig()
sin(x)^5 - 10*cos(x)^2*sin(x)^3 + 5*cos(x)^4*sin(x)

sage: cos(2*x + var('y')).trig_expand()
cos(2*x)*cos(y) - sin(2*x)*sin(y)

We illustrate various options to this function:

sage: f = sin(sin(3*cos(2*x))*x)
sage: f.expand_trig()
sin(x*(3*cos(cos(2*x))^2*sin(cos(2*x)) - sin(cos(2*x))^3))
sage: f.expand_trig(full=True)
sin(x*(3*(sin(cos(x)^2)*cos(sin(x)^2) -
cos(cos(x)^2)*sin(sin(x)^2))*(sin(cos(x)^2)*sin(sin(x)^2) +
cos(cos(x)^2)*cos(sin(x)^2))^2 - (sin(cos(x)^2)*cos(sin(x)^2) -
cos(cos(x)^2)*sin(sin(x)^2))^3))
sage: sin(2*x).expand_trig(times=False)
sin(2*x)
sage: sin(2*x).expand_trig(times=True)
2*cos(x)*sin(x)
sage: sin(2 + x).expand_trig(plus=False)
sin(x + 2)
sage: sin(2 + x).expand_trig(plus=True)
cos(2)*sin(x) + sin(2)*cos(x)
sage: sin(x/2).expand_trig(half_angles=False)
sin(x/2)
sage: sin(x/2).expand_trig(half_angles=True)
sqrt(1 - cos(x))/sqrt(2)

ALIAS: trig_expand and expand_trig are the same

trig_simplify( self)

First expands using trig_expand, then employs the identities $ \sin(x)^2 + \cos(x)^2 = 1$ and $ \cosh(x)^2 - \sin(x)^2 = 1$ to simplify expressions containing tan, sec, etc., to sin, cos, sinh, cosh.

ALIAS: trig_simplify and simplify_trig are the same

sage: f = sin(x)^2 + cos(x)^2; f
sin(x)^2 + cos(x)^2
sage: f.simplify()
sin(x)^2 + cos(x)^2
sage: f.simplify_trig()
1

variables( self, [vars=()])

Return sorted list of variables that occur in the simplified form of self.

Output: a Python set

sage: var('x,n')
(x, n)
sage: f = x^(n+1) + sin(pi/19); f
x^(n + 1) + sin(pi/19)
sage: f.variables()
(n, x)

sage: a = e^x
sage: a.variables()
(x,)

Special Functions: __abs__,$ \,$ __call__,$ \,$ __cmp__,$ \,$ __eq__,$ \,$ __ge__,$ \,$ __gt__,$ \,$ __init__,$ \,$ __int__,$ \,$ __le__,$ \,$ __long__,$ \,$ __lt__,$ \,$ __ne__,$ \,$ __pow__,$ \,$ __str__,$ \,$ _add_,$ \,$ _axiom_init_,$ \,$ _complex_double_,$ \,$ _complex_mpfr_field_,$ \,$ _declare_simplified,$ \,$ _derivative,$ \,$ _div_,$ \,$ _factor_list,$ \,$ _fast_float_,$ \,$ _gap_init_,$ \,$ _gp_init_,$ \,$ _has_been_simplified,$ \,$ _has_op,$ \,$ _integer_,$ \,$ _kash_init_,$ \,$ _macaulay2_init_,$ \,$ _magma_init_,$ \,$ _maple_init_,$ \,$ _mathematica_init_,$ \,$ _maxima_,$ \,$ _maxima_init_,$ \,$ _mpfr_,$ \,$ _mul_,$ \,$ _neg_,$ \,$ _octave_init_,$ \,$ _pari_init_,$ \,$ _polynomial_,$ \,$ _rational_,$ \,$ _real_double_,$ \,$ _real_rqdf_,$ \,$ _recursive_sub,$ \,$ _recursive_sub_over_ring,$ \,$ _richcmp_,$ \,$ _singular_init_,$ \,$ _sub_,$ \,$ _SymbolicExpression__parse_in_dict,$ \,$ _SymbolicExpression__varify_kwds,$ \,$ _sys_init_

__call__( self)

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)

__cmp__( self, right)

Compares self and right.

This is by definition the comparison of the underlying Maxima objects, if right coerces to a symbolic (otherwise types are compared). It is not used unless you explicitly call cmp, since all the other special comparison methods are overloaded.

These two are equal:

sage: cmp(e+e, e*2)
0
sage: cmp(SR(3), SR(5))
-1
sage: cmp(SR(5), SR(2))
1

Note that specifiec comparison operators do not call cmp.

sage: SR(3) < SR(5)
3 < 5
sage: bool(SR(3) < SR(5))
True

We compare symbolic elements with non symbolic ones.

sage: cmp(SR(3), 5)
-1
sage: cmp(3, SR(5))
-1

Here the underlying types are compared, since Mod(2,5) doesn't coerce to the symbolic ring.

sage: cmp(SR(3), Mod(2,5)) #random due to architecture dependence
1
sage: cmp(type(SR(3)), type(Mod(2,5))) #random due to architecture dependence
1
sage: cmp(Mod(2,5), SR(3) ) #random due to architecture dependence
-1

Some comparisons are fairly arbitrary but consistent:

sage: cmp(SR(3), x) #random due to architecture dependence
-1
sage: cmp(x, SR(3)) #random due to architecture dependence
1

__eq__( self, right)

Construct the symbolic inequality self == right.

NOTE: This only returns a Python bool if right does not coerce to the symbolic ring. Otherwise it returns a symbolic equation.

__ge__( self, right)

Construct the symbolic inequality self >= right.

NOTE: This only returns a Python bool if right does not coerce to the symbolic ring. Otherwise it returns a symbolic equation.

__gt__( self, right)

Construct the symbolic inequality self > right.

NOTE: This only returns a Python bool if right does not coerce to the symbolic ring. Otherwise it returns a symbolic equation.

__int__( self)

sage: int(sin(2)*100)
90

__le__( self, right)

Construct the symbolic inequality self <= right.

NOTE: This only returns a Python bool if right does not coerce to the symbolic ring. Otherwise it returns a symbolic equation.

sage: x <= x
x <= x
sage: x <= Mod(2,5) #random due to architecture dependence
False
sage: Mod(2,5) >= x #random due to architecture dependence
False
sage: Mod(2,5) <= x #random due to architecture dependence
True

__long__( self)

sage: long(sin(2)*100)
90L

__lt__( self, right)

Construct the symbolic inequality self < right.

NOTE: This only returns a Python bool if right does not coerce to the symbolic ring. Otherwise it returns a symbolic equation.

sage: x < x
x < x
sage: x < Mod(2,5) #random due to architecture dependence
False

__ne__( self, right)

Construct the symbolic inequality self != right.

NOTE: This only returns a Python bool if right does not coerce to the symbolic ring. Otherwise it returns a symbolic equation.

__pow__( self, right)

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

__str__( self)

Printing an object explicitly gives ASCII art:

sage: var('x y')
(x, y)
sage: f = y^2/(y+1)^3 + x/(x-1)^3
sage: f
y^2/(y + 1)^3 + x/(x - 1)^3
sage: print f
                                  2
                                 y          x
                              -------- + --------
                                     3          3
                              (y + 1)    (x - 1)

sage: f = (exp(x)-1)/(exp(x/2)+1)
sage: g = exp(x/2)-1
sage: print f(10), g(10)
                         10
                        e   - 1
                       --------
                         5
                        e  + 1 
                          5
                         e  - 1

_add_( self, right)

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

_declare_simplified( self)

Call this function to 'convince' this symbolic expression that it is in fact simplified. Basically this means it won't be simplified further before printing if you do this.

This is mainly for internal use.

We make an $ x + 1 - x$ that prints as that expression with no simplification before printing:

sage: f = x + 1 - x
sage: f._declare_simplified()
sage: f
x + 1 - x
sage: f._has_been_simplified()
True

Note that staying unsimplified as above does not persist when we do arithmetic with $ f$ .

sage: f + 2
3

_derivative( self, [var=None])

Derivative of self with respect to var (a symbolic variable).

If var is None, self must contain only one variable, and the result is the derivative with respect to that variable.

If var does not appear in self, the result is zero.

SEE ALSO: self.derivative()

sage: x = var("x"); y = var("y"); z = var("z")
sage: f = sin(x) * cos(y)
sage: f._derivative(x)
cos(x)*cos(y)
sage: f._derivative(y)
-sin(x)*sin(y)
sage: f._derivative(z)
0
sage: f._derivative()
Traceback (most recent call last):
...
ValueError: must supply an explicit variable for an expression containing
more than one variable

sage: f = sin(x)
sage: f._derivative()
cos(x)

sage: f._derivative(2)
Traceback (most recent call last):
...
TypeError: arguments must be SymbolicVariable objects

_div_( self, right)

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

_factor_list( self)

Turn an expression already in factored form into a list of (prime, power) pairs.

This is used, e.g., internally by the factor_list command.

sage: g = factor(x^3 - 1); g
(x - 1)*(x^2 + x + 1)
sage: v = g._factor_list(); v
[(x - 1, 1), (x^2 + x + 1, 1)]
sage: type(v)
<type 'list'>

_fast_float_( self)

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...

_gap_init_( self)

Conversion of symbolic object to GAP always results in a GAP string.

sage: gap(e+pi^2 + x^3)
x^3 + pi^2 + e

_has_been_simplified( self)

Return True if this symbolic expression was constructed in such a way that it is known to already be simplified.

WARNING: An expression that happens to be in a simplified form need not return True.

This expression starts in simple form:

sage: f = x^2 + 1; f
x^2 + 1

But it has not been simplified, i.e., it was constructed as a simplified expression.

sage: f._has_been_simplified()
False
sage: g = f.simplify(); g
x^2 + 1
sage: g._has_been_simplified()
True

This function still does not return True, since f itself isn't constructed as a simplified expression.

sage: f._has_been_simplified()
False

Here, though f looks simplified when printed, internally it is much more complicated and hence not simplified.

sage: f = x + 1 - x; f
1
sage: f._has_been_simplified()
False
sage: type(f)
<class 'sage.calculus.calculus.SymbolicArithmetic'>
sage: f._operands
[x + 1, x]

_has_op( self, operator)

Recursively searches for the given operator in a SymbolicExpression object.

Input: operator: the operator to search for

Output: True or False

sage: f = 4*(x^2 - 3)
sage: f._has_op(operator.sub)
True
sage: f._has_op(operator.div)
False

_integer_( self)

_maxima_( self, [session=None])

Method for coercing self as a Maxima RingElement.

_mul_( self, right)

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

_neg_( self)

Return the formal negative of self.

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

_polynomial_( self, R)

Coerce this symbolic expression to a polynomial in $ R$ .

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

sage: R = QQ[x,y,z]
sage: R(x^2 + y)
x^2 + y
sage: R = QQ[w]
sage: R(w^3 + w + 1)
w^3 + w + 1
sage: R = GF(7)[z]
sage: R(z^3 + 10*z)
z^3 + 3*z

NOTE: If the base ring of the polynomial ring is the symbolic ring, then a constant polynomial is always returned.

sage: R = SR[x]
sage: a = R(sqrt(2) + x^3 + y)
sage: a
y + x^3 + sqrt(2)
sage: type(a)
<type 'sage.rings.polynomial.polynomial_element.Polynomial_generic_dense'>
sage: a.degree()
0

We coerce to a double precision complex polynomial ring:

sage: f = e*x^3 + pi*y^3 + sqrt(2) + I; f
pi*y^3 + e*x^3 + I + sqrt(2)
sage: R = CDF[x,y]
sage: R(f)
2.71828182846*x^3 + 3.14159265359*y^3 + 1.41421356237 + 1.0*I

We coerce to a higher-precision polynomial ring

sage: R = ComplexField(100)[x,y]
sage: R(f)
2.7182818284590452353602874714*x^3 + 3.1415926535897932384626433833*y^3 +
1.4142135623730950488016887242 + 1.0000000000000000000000000000*I

_richcmp_( left, right, op)

TESTS:

sage: 3 < x
3 < x
sage: 3 <= x
3 <= x
sage: 3 == x
3 == x
sage: 3 >= x
3 >= x
sage: 3 > x
3 > x

_singular_init_( self)

Conversion of a symbolic object to Singular always results in a Singular string.

sage: singular(e+pi^2 + x^3)
x^3 + pi^2 + e

_sub_( self, right)

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

_SymbolicExpression__parse_in_dict( self, in_dict, kwds)

sage: function('f',x)
f(x)
sage: f._SymbolicExpression__parse_in_dict({f:log},{})
{f: <function log at 0x...>}
sage: f._SymbolicExpression__parse_in_dict({},{'f':log})
{'f': <function log at 0x...>}

_SymbolicExpression__varify_kwds( self, kwds)

sage: function('f',x)
f(x)
sage: a = f._SymbolicExpression__parse_in_dict({f:log},{})
sage: f._SymbolicExpression__varify_kwds(a)
{f: <function log at 0x...>}
sage: b = f._SymbolicExpression__parse_in_dict({},{'f':log})
sage: f._SymbolicExpression__varify_kwds(b)
{f: <function log at 0x...>}

Class: SymbolicExpressionRing_class

class SymbolicExpressionRing_class
The ring of all formal symbolic expressions.

sage: SR
Symbolic Ring
sage: type(SR)
<class 'sage.calculus.calculus.SymbolicExpressionRing_class'>

TESTS: Test serializing:

sage: loads(dumps(SR)) == SR
True
SymbolicExpressionRing_class( self, [default_precision=53])

Create a symbolic expression ring.

sage: from sage.calculus.calculus import SymbolicExpressionRing_class
sage: SymbolicExpressionRing_class()
Symbolic Ring

Functions: characteristic,$ \,$ is_exact,$ \,$ is_field,$ \,$ var

characteristic( self)

Return the characteristic of the symbolic ring, which is 0.

Output: a Sage integer

sage: c = SR.characteristic(); c
0
sage: type(c)
<type 'sage.rings.integer.Integer'>

is_exact( self)

Return False, because there are approximate elements in the symbolic ring.

sage: SR.is_exact()
False

Here is an inexact element.

sage: SR(1.9393)
1.93930000000000

is_field( self)

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

sage: SR.is_field()
True

var( self, x)

Return the symbolic variable defined by x as an element of the symbolic ring.

sage: zz = SR.var('zz'); zz
zz
sage: type(zz)
<class 'sage.calculus.calculus.SymbolicVariable'>
sage: t = SR.var('theta2'); t
theta2

Special Functions: __call__,$ \,$ __cmp__,$ \,$ __contains__,$ \,$ __init__,$ \,$ _an_element_impl,$ \,$ _coerce_impl,$ \,$ _latex_,$ \,$ _repr_

__call__( self, x)

Coerce $ x$ into the symbolic expression ring SR.

sage: a = SR(-3/4); a
-3/4
sage: type(a)
<class 'sage.calculus.calculus.SymbolicConstant'>
sage: a.parent()
Symbolic Ring
sage: type(SR(I))
<class 'sage.calculus.calculus.SymbolicConstant'>
sage: is_SymbolicExpression(SR(I))
True

If $ a$ is already in the symblic expression ring, coercing returns $ a$ itself (not a copy):

sage: SR(a) is a
True

A Python complex number:

sage: SR(complex(2,-3))
2.00000000000000 - 3.00000000000000*I

__cmp__( self, other)

Compare two symbolic expression rings. They are equal if and only if they have the same type. Otherwise their types are compared.

sage: cmp(SR, RR) #random
1
sage: cmp(RR, SymbolicExpressionRing()) #random
-1
sage: cmp(SR, SymbolicExpressionRing()) #random
0

__contains__( self, x)

True if there is an element of the symbolic ring that is equal to x under ==.

The symbolic variable x is in the symbolic ring.

sage: x.parent()
Symbolic Ring
sage: x in SR
True

2 is also in the symbolic ring since it is equal to something in SR, even though 2's parent is not SR.

sage: 2 in SR
True
sage: parent(2)
Integer Ring
sage: 1/3 in SR
True

The finite field element 1 (in GF(3)) is not equal to anything in SR.

sage: GF(3)(1) in SR
False

_an_element_impl( self)

Return an element of the symbolic ring, which is used by the coercion model.

Currently this function always returns 0. That may change.

sage: SR._an_element_impl()
0

_coerce_impl( self, x)

Used for implicit coercion.

sage: x=var('x'); y0,y1=PolynomialRing(ZZ,2,'y').gens()
sage: x+y0/y1
y0/y1 + x
sage: x.subs(x=y0/y1)
y0/y1

_latex_( self)

Return latex representation of the symbolic ring.

sage: latex(SR)
	ext{SR}
sage: M = MatrixSpace(SR, 2); latex(M)
\mbox{
m Mat}_{2	imes 2}(	ext{SR})

_repr_( self)

Return string representation of this symbolic ring.

sage: SR._repr_()
'Symbolic Ring'

Class: SymbolicFunction

class SymbolicFunction
A formal symbolic function.

sage: f = function('foo')
sage: var('x,y,z')
(x, y, z)
sage: g = f(x,y,z)
sage: g
foo(x, y, z)
sage: g(x=var('theta'))
foo(theta, y, z)
SymbolicFunction( self, name)

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

Class: SymbolicFunction_delayed

class SymbolicFunction_delayed

Functions: simplify

simplify( self)

Return the simplified form of this delayed function. This always just returns this delayed function itself.

Output: self

sage: f = sage.calculus.calculus.symbolic_expression_from_maxima_string("?%jacobi_cd")
sage: type(f)
<class 'sage.calculus.calculus.SymbolicFunction_delayed'>
sage: f.simplify()
jacobi_cd
sage: f.simplify() is f
True

Special Functions: __call__,$ \,$ _has_been_simplified,$ \,$ _maxima_init_

__call__( self)

Call this delayed function evaluation at the given inputs.

Output: a delayed function evaluation

sage: f = sage.calculus.calculus.symbolic_expression_from_maxima_string("?%jacobi_cd")
sage: f(2)
jacobi_cd(2)
sage: f(2,3)
jacobi_cd(2, 3)
sage: f(2,3,x)
jacobi_cd(2, 3, x)
sage: type(f(2,3,x))
<class 'sage.calculus.calculus.SymbolicFunctionEvaluation_delayed'>

_has_been_simplified( self)

Return True, since delayed symbolic functions are simplified by construction.

Output:

bool
- True

sage: f = sage.calculus.calculus.symbolic_expression_from_maxima_string("?%jacobi_cd")
sage: type(f)
<class 'sage.calculus.calculus.SymbolicFunction_delayed'>
sage: f._has_been_simplified()
True

_maxima_init_( self)

Return Maxima version of self.

sage: f = sage.calculus.calculus.symbolic_expression_from_maxima_string("?%jacobi_cd")
sage: f._maxima_init_()
'?%jacobi_cd'
sage: maxima(f)
?%jacobi_cd

Class: SymbolicFunctionEvaluation

class SymbolicFunctionEvaluation
The result of evaluating a formal symbolic function.

sage: h = function('gfun', x); h
gfun(x)
sage: k = h.integral(x); k
integrate(gfun(x), x)
sage: k(gfun=sin)
-cos(x)
sage: k(gfun=cos)
sin(x)
sage: k.diff(x)
gfun(x)
SymbolicFunctionEvaluation( self, f, [args=None])

Input:

f
- symbolic function
args
- a tuple or list of symbolic expressions, at which f is formally evaluated.

Functions: arguments,$ \,$ variables

arguments( self)

Return arguments of self.

sage: f = function('Gamma', var('z'), var('w'))
sage: f.arguments()
(z, w)

variables( self)

Return the variables appearing in the simplified form of self.

sage: foo = function('foo')
sage: var('x,y,a,b,z,t')
(x, y, a, b, z, t)
sage: w = foo(x,y,a,b,z) + t
sage: w
foo(x, y, a, b, z) + t
sage: w.variables()
(a, b, t, x, y, z)

Special Functions: __float__,$ \,$ __init__,$ \,$ _is_atomic,$ \,$ _latex_,$ \,$ _mathematica_init_,$ \,$ _maxima_init_,$ \,$ _recursive_sub,$ \,$ _recursive_sub_over_ring,$ \,$ _repr_

_mathematica_init_( self)

Return string that in Mathematica evaluates to something equivalent to self.

sage: f = function('Gamma', var('z'))
sage: mathematica(f) # optional
Gamma[z]
sage: f = function('Gamma', var('w'), var('z')); f
Gamma(w, z)
sage: f._mathematica_init_()
'Gamma[w, z]'
sage: mathematica(f(sqrt(2), z+1)) # optional
Gamma[Sqrt[2], 1 + z]

_maxima_init_( self)

Return string that in Maxima evaluates to something equivalent to self.

sage: f = function('Gamma', var('w'), var('theta')); f
Gamma(w, theta)
sage: f._maxima_init_()
"'Gamma(w, theta)"
sage: maxima(f(sqrt(2), theta+3))
'Gamma(sqrt(2),theta+3)

_recursive_sub( self, kwds)

sage: y = var('y')
sage: f = function('foo',x); f
foo(x)
sage: f(foo=sin)
sin(x)
sage: f(x+y)
foo(y + x)
sage: a = f(pi)
sage: a.substitute(foo = sin)
0
sage: a = f(pi/2)
sage: a.substitute(foo = sin)
1

sage: b = f(pi/3) + x + y
sage: b
y + x + foo(pi/3)
sage: b(foo = sin)
y + x + sqrt(3)/2
sage: b(foo = cos)
y + x + 1/2
sage: b(foo = cos, x=y)
2*y + 1/2

Class: SymbolicFunctionEvaluation_delayed

class SymbolicFunctionEvaluation_delayed
We create an example of such a thing.

sage: f = sage.calculus.calculus.symbolic_expression_from_maxima_string("?%jacobi_cd")
sage: type(f)
<class 'sage.calculus.calculus.SymbolicFunction_delayed'>
sage: g = f(10)
sage: type(g)
<class 'sage.calculus.calculus.SymbolicFunctionEvaluation_delayed'>
sage: g
jacobi_cd(10)

Functions: simplify

Special Functions: __complex__,$ \,$ __float__,$ \,$ _complex_double_,$ \,$ _complex_mpfr_field_,$ \,$ _has_been_simplified,$ \,$ _maxima_init_,$ \,$ _mpfr_,$ \,$ _real_double_,$ \,$ _real_rqdf_

Class: SymbolicOperation

class SymbolicOperation
A parent class representing any operation on SymbolicExpression objects.
SymbolicOperation( self, operands)

Functions: number_of_arguments,$ \,$ variables

number_of_arguments( self)

Returns the number of arguments this object can take.

sage: x,y,z = var('x,y,z')
sage: (x+y).number_of_arguments()
2
sage: (x+1).number_of_arguments()
1
sage: (sin+1).number_of_arguments()
1
sage: (sin+x).number_of_arguments()
1
sage: (sin+x+y).number_of_arguments()
2
sage: (sin(z)+x+y).number_of_arguments()
3
sage: (sin+cos).number_of_arguments()
1
sage: (sin(x+y)).number_of_arguments()
2

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

Note that self is simplified first:

sage: f = x + pi - x; f
pi
sage: f.number_of_arguments()
0

variables( self, [vars=()])

Return sorted list of variables that occur in the simplified form of self. The ordering is alphabetic.

sage: var('x,y,z,w,a,b,c')
(x, y, z, w, a, b, c)
sage: f = (x - x) + y^2 - z/z + (w^2-1)/(w+1); f
y^2 + (w^2 - 1)/(w + 1) - 1
sage: f.variables()
(w, y)

sage: (x + y + z + a + b + c).variables()
(a, b, c, x, y, z)

sage: (x^2 + x).variables()
(x,)

Special Functions: __init__

Class: SymbolicPolynomial

class SymbolicPolynomial
An element of a polynomial ring as a formal symbolic expression.

A single variate polynomial:

sage: R.<x> = QQ[]
sage: f = SR(x^3 + x)
sage: f(y=7)
x^3 + x
sage: f(x=5)
130
sage: f.integral(x)
x^4/4 + x^2/2
sage: f(x=var('y'))
y^3 + y

A multivariate polynomial:

sage: R.<x,y,theta> = ZZ[]
sage: f = SR(x^3 + x + y + theta^2); f
x^3 + theta^2 + x + y
sage: f(x=y, theta=y)
y^3 + y^2 + 2*y
sage: f(x=5)
y + theta^2 + 130

The polynomial must be over a field of characteristic 0.

sage: R.<w> = GF(7)[]
sage: f = SR(w^3 + 1)
Traceback (most recent call last):
...
TypeError: polynomial must be over a field of characteristic 0.
SymbolicPolynomial( self, p)

Functions: number_of_arguments,$ \,$ polynomial,$ \,$ variables

number_of_arguments( self)

Returns the number of arguments this object can take. For SymbolicPolynomials, this is just the number of variables of the polynomial.

sage: R.<x> = QQ[]; S.<y> = R[]
sage: f = x+y*x+y^2
sage: g = SR(f)
sage: g.number_of_arguments()
2

polynomial( self, base_ring)

Return self as a polynomial over the given base ring, if possible.

Input:

base_ring
- a ring

sage: R.<x> = QQ[]
sage: f = SR(x^2 -2/3*x + 1)
sage: f.polynomial(QQ)
x^2 - 2/3*x + 1
sage: f.polynomial(GF(19))
x^2 + 12*x + 1

variables( self)

Return sorted list of variables that occur in self. The ordering is alphabetic.

sage: R.<x> = QQ[]; S.<y> = R[]
sage: f = x+y*x+y^2
sage: g = SR(f)
sage: g.variables()
(x, y)

Special Functions: __init__,$ \,$ _fast_float_,$ \,$ _recursive_sub,$ \,$ _recursive_sub_over_ring

Class: SymbolicVariable

class SymbolicVariable
A symbolic variable, which is a calculus object.

sage: z = var('z')
sage: type(z)
<class 'sage.calculus.calculus.SymbolicVariable'>
SymbolicVariable( self, name)

Functions: number_of_arguments,$ \,$ variables

number_of_arguments( self)

Returns the number of arguments of self.

sage: x = var('x')
sage: x.number_of_arguments()
1

variables( self, [vars=()])

Return sorted list of variables that occur in the simplified form of self.

Special Functions: __cmp__,$ \,$ __init__,$ \,$ __str__,$ \,$ _fast_float_,$ \,$ _latex_,$ \,$ _maxima_init_,$ \,$ _recursive_sub,$ \,$ _recursive_sub_over_ring,$ \,$ _repr_,$ \,$ _sys_init_

_fast_float_( self)

Returns a quickly-evaluating function with named parameters vars. Specifically, if self is the $ n$ -th parameter it returns a function extracting the $ n$ -th item out of a tuple.

sage: f = x._fast_float_('x', 'y')
sage: f(1,2)
1.0
sage: f = x._fast_float_('y', 'x')
sage: f(1,2)
2.0
sage: sqrt(2)._fast_float_()(2)
1.4142135623730951

Class: uniq

class uniq
See About this document... for information on suggesting changes.