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

Class SymbolicExpression

source code

                      object --+                
                               |                
structure.sage_object.SageObject --+            
                                   |            
           structure.element.Element --+        
                                       |        
         structure.element.ModuleElement --+    
                                           |    
               structure.element.RingElement --+
                                               |
                                              SymbolicExpression
Known Subclasses:
CallableSymbolicExpression, PrimitiveFunction, SymbolicOperation, Symbolic_object, SymbolicFunctionEvaluation, SymbolicVariable


A Symbolic Expression. 

EXAMPLES:
    Some types of \class{SymbolicExpression}s:

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



Instance Methods [hide private]
 
__init__(self)
Create a symbolic expression.
source code
 
__hash__(self)
Returns the hash of this symbolic expression.
source code
 
__nonzero__(self)
Return True if this element is definitely not zero.
source code
 
__str__(self)
Printing an object explicitly gives ASCII art:...
source code
 
show(self)
Show this symbolic expression, i.e., typeset it nicely.
source code
 
display2d(self, onscreen=True)
Display \code{self} using ASCII art.
source code
 
_has_been_simplified(self)
Return True if this symbolic expression was constructed in such a way that it is known to already be simplified.
source code
 
_declare_simplified(self)
Call this function to 'convince' this symbolic expression that it is in fact simplified.
source code
 
plot(self, *args, **kwds)
Plot a symbolic expression.
source code
 
__lt__(self, right)
Construct the symbolic inequality \code{self < right}.
source code
 
__le__(self, right)
Construct the symbolic inequality \code{self <= right}.
source code
 
__eq__(self, right)
Construct the symbolic inequality \code{self == right}.
source code
 
__ne__(self, right)
Construct the symbolic inequality \code{self != right}.
source code
 
__ge__(self, right)
Construct the symbolic inequality \code{self >= right}.
source code
 
__gt__(self, right)
Construct the symbolic inequality \code{self > right}.
source code
 
__cmp__(self, right)
Compares self and right.
source code
 
_richcmp_(left, right, op)
TESTS:...
source code
 
_neg_(self)
Return the formal negative of \code{self}.
source code
 
_maxima_(self, session=['4ti2-20061025', 'R-2.6.0', 'atlas-3.7.37', 'atlas-3.8.1', 'a...)
Method for coercing self as a Maxima \code{RingElement}.
source code
 
_maxima_init_(self)
File: sage/structure/sage_object.pyx (starting at line 318)
source code
 
_axiom_init_(self)
File: sage/structure/sage_object.pyx (starting at line 309)
source code
 
_gp_init_(self)
File: sage/structure/sage_object.pyx (starting at line 291)
source code
 
_maple_init_(self)
File: sage/structure/sage_object.pyx (starting at line 345)
source code
 
_magma_init_(self)
File: sage/structure/sage_object.pyx (starting at line 327)
source code
 
_kash_init_(self)
File: sage/structure/sage_object.pyx (starting at line 300)
source code
 
_macaulay2_init_(self)
File: sage/structure/sage_object.pyx (starting at line 336)
source code
 
_mathematica_init_(self)
File: sage/structure/sage_object.pyx (starting at line 354)
source code
 
_octave_init_(self)
File: sage/structure/sage_object.pyx (starting at line 363)
source code
 
_pari_init_(self)
File: sage/structure/sage_object.pyx (starting at line 407)
source code
 
_sys_init_(self, system) source code
 
_gap_init_(self)
Conversion of symbolic object to GAP always results in a GAP string.
source code
 
_singular_init_(self)
Conversion of a symbolic object to Singular always results in a Singular string.
source code
 
__int__(self)
EXAMPLES:...
source code
 
__long__(self)
EXAMPLES:...
source code
 
numerical_approx(self, prec=['4ti2-20061025', 'R-2.6.0', 'atlas-3.7.37', 'atlas-3.8.1', 'a..., digits=['4ti2-20061025', 'R-2.6.0', 'atlas-3.7.37', 'atlas-3.8.1', 'a...)
Return a numerical approximation of \code{self} as either a real or complex number with at least the requested number of bits or digits of precision.
source code
 
n(self, prec=['4ti2-20061025', 'R-2.6.0', 'atlas-3.7.37', 'atlas-3.8.1', 'a..., digits=['4ti2-20061025', 'R-2.6.0', 'atlas-3.7.37', 'atlas-3.8.1', 'a...)
Return a numerical approximation of \code{self} as either a real or complex number with at least the requested number of bits or digits of precision.
source code
 
minpoly(self, bits=['4ti2-20061025', 'R-2.6.0', 'atlas-3.7.37', 'atlas-3.8.1', 'a..., degree=['4ti2-20061025', 'R-2.6.0', 'atlas-3.7.37', 'atlas-3.8.1', 'a..., epsilon=0)
Return the minimal polynomial of self, if possible.
source code
 
_mpfr_(self, field) source code
 
_complex_mpfr_field_(self, field) source code
 
_complex_double_(self, C) source code
 
_real_double_(self, R) source code
 
_real_rqdf_(self, R) source code
 
_rational_(self) source code
 
__abs__(self) source code
 
_integer_(self)
EXAMPLES:
source code
 
_add_(self, right)
EXAMPLES:...
source code
 
_sub_(self, right)
EXAMPLES:...
source code
 
_mul_(self, right)
EXAMPLES:...
source code
 
_div_(self, right)
EXAMPLES:...
source code
 
__pow__(self, right)
EXAMPLES:...
source code
 
variables(self, vars=())
Return sorted list of variables that occur in the simplified form of \code{self}.
source code
 
arguments(self)
Return the arguments of self, if we view self as a callable function.
source code
 
number_of_arguments(self)
Returns the number of arguments the object can take.
source code
 
_has_op(self, operator)
Recursively searches for the given operator in a \class{SymbolicExpression} object.
source code
 
__call__(self, *args, **kwds)
EXAMPLES: sage: x,y=var('x,y') sage: f = x+y sage: f.arguments() (x, y) sage: f() y + x sage: f(3) y + 3 sage: f(3,4) 7 sage: f(2,3,4) Traceback (most recent call last): ...
source code
 
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.
source code
 
polynomial(self, base_ring)
Return \code{self} as an algebraic polynomial over the given base ring, if possible.
source code
 
_polynomial_(self, R)
Coerce this symbolic expression to a polynomial in $R$.
source code
 
function(self, *args)
Return a \class{CallableSymbolicExpression}, fixing a variable order to be the order of args.
source code
 
_derivative(self, var=['4ti2-20061025', 'R-2.6.0', 'atlas-3.7.37', 'atlas-3.8.1', 'a...)
Derivative of self with respect to var (a symbolic variable).
source code
 
derivative(self, *args)
Derivative with respect to variables supplied in args.
source code
 
differentiate(self, *args)
Derivative with respect to variables supplied in args.
source code
 
diff(self, *args)
Derivative with respect to variables supplied in args.
source code
 
gradient(self)
Compute the gradient of a symbolic function.
source code
 
hessian(self)
Compute the hessian of a function.
source code
 
taylor(self, v, a, n)
Expands \code{self} in a truncated Taylor or Laurent series in the variable $v$ around the point $a$, containing terms through $(x - a)^n$.
source code
 
limit(self, dir=['4ti2-20061025', 'R-2.6.0', 'atlas-3.7.37', 'atlas-3.8.1', 'a..., taylor=False, **argv)
Return the limit as the variable $v$ approaches $a$ from the given direction.
source code
 
laplace(self, t, s)
Attempts to compute and return the Laplace transform of \code{self} with respect to the variable $t$ and transform parameter $s$.
source code
 
inverse_laplace(self, t, s)
Attempts to compute the inverse Laplace transform of \code{self} with respect to the variable $t$ and transform parameter $s$.
source code
 
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.
source code
 
integral(self, v=['4ti2-20061025', 'R-2.6.0', 'atlas-3.7.37', 'atlas-3.8.1', 'a..., a=['4ti2-20061025', 'R-2.6.0', 'atlas-3.7.37', 'atlas-3.8.1', 'a..., b=['4ti2-20061025', 'R-2.6.0', 'atlas-3.7.37', 'atlas-3.8.1', 'a...)
Returns the indefinite integral with respect to the variable $v$, ignoring the constant of integration.
source code
 
integrate(self, v=['4ti2-20061025', 'R-2.6.0', 'atlas-3.7.37', 'atlas-3.8.1', 'a..., a=['4ti2-20061025', 'R-2.6.0', 'atlas-3.7.37', 'atlas-3.8.1', 'a..., b=['4ti2-20061025', 'R-2.6.0', 'atlas-3.7.37', 'atlas-3.8.1', 'a...)
Returns the indefinite integral with respect to the variable $v$, ignoring the constant of integration.
source code
 
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 \code{self} from $a$ to $b$, computed using floating point arithmetic via maxima.
source code
 
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 \code{self} from $a$ to $b$, computed using floating point arithmetic via maxima.
source code
 
coefficient(self, x, n=1)
Returns the coefficient of $x^n$ in self.
source code
 
coeff(self, x, n=1)
Returns the coefficient of $x^n$ in self.
source code
 
coefficients(self, x=['4ti2-20061025', 'R-2.6.0', 'atlas-3.7.37', 'atlas-3.8.1', 'a...)
Coefficients of \code{self} as a polynomial in x.
source code
 
coeffs(self, x=['4ti2-20061025', 'R-2.6.0', 'atlas-3.7.37', 'atlas-3.8.1', 'a...)
Coefficients of \code{self} as a polynomial in x.
source code
 
poly(self, x=['4ti2-20061025', 'R-2.6.0', 'atlas-3.7.37', 'atlas-3.8.1', 'a...)
Express \code{self} as a polynomial in $x$.
source code
 
combine(self)
Simplifies \code{self} by combining all terms with the same denominator into a single term.
source code
 
numerator(self)
EXAMPLES:...
source code
 
denominator(self)
Return the denominator of self.
source code
 
factor_list(self, dontfactor=[])
Returns a list of the factors of self, as computed by the factor command.
source code
 
_factor_list(self)
Turn an expression already in factored form into a list of (prime, power) pairs.
source code
 
roots(self, x=['4ti2-20061025', 'R-2.6.0', 'atlas-3.7.37', 'atlas-3.8.1', 'a..., explicit_solutions=True)
Returns roots of \code{self} that can be found exactly, with multiplicities.
source code
 
solve(self, x, multiplicities=False, explicit_solutions=False)
Analytically solve the equation \code{self == 0} for the variable $x$.
source code
 
find_root(self, a, b, var=['4ti2-20061025', 'R-2.6.0', 'atlas-3.7.37', 'atlas-3.8.1', 'a..., 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.
source code
 
find_maximum_on_interval(self, a, b, var=['4ti2-20061025', 'R-2.6.0', 'atlas-3.7.37', 'atlas-3.8.1', 'a..., tol=1.48e-08, maxfun=500)
Numerically find the maximum of the expression \code{self} on the interval [a,b] (or [b,a]) along with the point at which the maximum is attained.
source code
 
find_minimum_on_interval(self, a, b, var=['4ti2-20061025', 'R-2.6.0', 'atlas-3.7.37', 'atlas-3.8.1', 'a..., tol=1.48e-08, maxfun=500)
Numerically find the minimum of the expression \code{self} on the interval [a,b] (or [b,a]) and the point at which it attains that minimum.
source code
 
simplify(self)
Return the simplified form of this symbolic expression.
source code
 
simplify_full(self)
Applies simplify_trig, simplify_rational, and simplify_radical to self (in that order).
source code
 
full_simplify(self)
Applies simplify_trig, simplify_rational, and simplify_radical to self (in that order).
source code
 
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.
source code
 
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.
source code
 
simplify_rational(self)
Simplify by expanding repeatedly rational expressions.
source code
 
rational_simplify(self)
Simplify by expanding repeatedly rational expressions.
source code
 
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.
source code
 
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.
source code
 
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.
source code
 
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.
source code
 
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.
source code
 
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.
source code
 
factor(self, dontfactor=[])
Factors self, containing any number of variables or functions, into factors irreducible over the integers.
source code
 
expand(self)
Expand this symbolic expression.
source code
 
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.
source code
 
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.
source code
 
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.
source code
 
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.
source code
 
substitute(self, in_dict=['4ti2-20061025', 'R-2.6.0', 'atlas-3.7.37', 'atlas-3.8.1', 'a..., **kwds)
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.
source code
 
subs(self, *args, **kwds)
File: sage/structure/element.pyx (starting at line 381) Substitutes given generators with given values while not touching other generators.
source code
 
_recursive_sub(self, kwds) source code
 
_recursive_sub_over_ring(self, kwds, ring) source code
 
__parse_in_dict(self, in_dict, kwds)
EXAMPLES:...
source code
 
__varify_kwds(self, kwds)
EXAMPLES:...
source code
 
substitute_over_ring(self, in_dict=['4ti2-20061025', 'R-2.6.0', 'atlas-3.7.37', 'atlas-3.8.1', 'a..., ring=['4ti2-20061025', 'R-2.6.0', 'atlas-3.7.37', 'atlas-3.8.1', 'a..., **kwds) source code
 
subs_expr(self, *equations)
Given a dictionary of key:value pairs, substitute all occurences of key for value in self.
source code
 
real(self)
Return the real part of \code{self}.
source code
 
imag(self)
Return the imaginary part of \code{self}.
source code
 
conjugate(self)
The complex conjugate of \code{self}.
source code
 
norm(self)
The complex norm of \code{self}, i.e., \code{self} times its complex conjugate.
source code
 
partial_fraction(self, var=['4ti2-20061025', 'R-2.6.0', 'atlas-3.7.37', 'atlas-3.8.1', 'a...)
Return the partial fraction expansion of \code{self} with respect to the given variable.
source code
 
_fast_float_(self, *vars)
EXAMPLES: sage: x,y,z = var('x,y,z') sage: f = 1 + sin(x)/x + sqrt(z^2+y^2)/cosh(x) sage: ff = f._fast_float_('x', 'y', 'z') sage: f(1.0,2.0,3.0) 4.1780638977866...
source code

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

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

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

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

Inherited from object: __delattr__, __getattribute__, __reduce_ex__, __setattr__

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self)
(Constructor)

source code 

Create a symbolic expression.

EXAMPLES:
This example is mainly for testing purposes.

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

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

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

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

Overrides: structure.element.Element.__init__

__hash__(self)
(Hashing function)

source code 

Returns the hash of this symbolic expression.

EXAMPLES:
We hash a symbolic polynomial:
    sage: hash(x^2 + 1) #random due to architecture dependence
    -832266011

The default hashing strategy is to simply hash
the string representation of an object.
    sage: hash(repr(x^2+1)) #random due to architecture dependence
    -832266011

In some cases a better hashing strategy is used.
    sage: hash(SR(3/1)) 
    3
    sage: hash(repr(SR(3/1))) #random due to architecture dependence
    -2061914958        

Overrides: structure.element.Element.__hash__

__nonzero__(self)
(Boolean test operator)

source code 

Return True if this element is definitely not zero.

EXAMPLES:
    sage: k = var('k')
    sage: pol = 1/(k-1) - 1/k -1/k/(k-1);
    sage: pol.is_zero()
    True

    sage: f = sin(x)^2 + cos(x)^2 - 1
    sage: f.is_zero()
    True

Overrides: structure.element.Element.__nonzero__

__str__(self)
(Informal representation operator)

source code 

Printing an object explicitly gives ASCII art:

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

Overrides: object.__str__

show(self)

source code 

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

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

display2d(self, onscreen=True)

source code 

Display \code{self} using ASCII art.

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

EXAMPLES:
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 \code{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

_has_been_simplified(self)

source code 

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.

EXAMPLES:
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]            

_declare_simplified(self)

source code 

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. 

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

plot(self, *args, **kwds)

source code 

Plot a symbolic expression.

All arguments are passed onto the standard plot command. 

EXAMPLES:
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))

Overrides: structure.sage_object.SageObject.plot

__lt__(self, right)
(Less-than operator)

source code 

Construct the symbolic inequality \code{self < right}.

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

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

Overrides: structure.element.Element.__lt__

__le__(self, right)
(Less-than-or-equals operator)

source code 

Construct the symbolic inequality \code{self <= right}.

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

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

Overrides: structure.element.Element.__le__

__eq__(self, right)
(Equality operator)

source code 

Construct the symbolic inequality \code{self == right}.

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

EXAMPLES:

Overrides: structure.element.Element.__eq__

__ne__(self, right)

source code 

Construct the symbolic inequality \code{self != right}.

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

EXAMPLES:

Overrides: structure.element.Element.__ne__

__ge__(self, right)
(Greater-than-or-equals operator)

source code 

Construct the symbolic inequality \code{self >= right}.

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

EXAMPLES:

Overrides: structure.element.Element.__ge__

__gt__(self, right)
(Greater-than operator)

source code 

Construct the symbolic inequality \code{self > right}.

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

EXAMPLES:

Overrides: structure.element.Element.__gt__

__cmp__(self, right)
(Comparison operator)

source code 

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.

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

Overrides: structure.element.Element.__cmp__

_richcmp_(left, right, op)

source code 

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

Overrides: structure.element.Element._richcmp_

_neg_(self)

source code 

Return the formal negative of \code{self}.

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

Overrides: structure.element.ModuleElement._neg_

_maxima_(self, session=['4ti2-20061025', 'R-2.6.0', 'atlas-3.7.37', 'atlas-3.8.1', 'a...)

source code 

Method for coercing self as a Maxima \code{RingElement}.

Overrides: structure.sage_object.SageObject._maxima_

_maxima_init_(self)

source code 
File: sage/structure/sage_object.pyx (starting at line 318)

Overrides: structure.sage_object.SageObject._maxima_init_
(inherited documentation)

_axiom_init_(self)

source code 
File: sage/structure/sage_object.pyx (starting at line 309)

Overrides: structure.sage_object.SageObject._axiom_init_
(inherited documentation)

_gp_init_(self)

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

Overrides: structure.sage_object.SageObject._gp_init_
(inherited documentation)

_maple_init_(self)

source code 
File: sage/structure/sage_object.pyx (starting at line 345)

Overrides: structure.sage_object.SageObject._maple_init_
(inherited documentation)

_magma_init_(self)

source code 
File: sage/structure/sage_object.pyx (starting at line 327)

Overrides: structure.sage_object.SageObject._magma_init_
(inherited documentation)

_kash_init_(self)

source code 
File: sage/structure/sage_object.pyx (starting at line 300)

Overrides: structure.sage_object.SageObject._kash_init_
(inherited documentation)

_macaulay2_init_(self)

source code 
File: sage/structure/sage_object.pyx (starting at line 336)

Overrides: structure.sage_object.SageObject._macaulay2_init_
(inherited documentation)

_mathematica_init_(self)

source code 
File: sage/structure/sage_object.pyx (starting at line 354)

Overrides: structure.sage_object.SageObject._mathematica_init_
(inherited documentation)

_octave_init_(self)

source code 
File: sage/structure/sage_object.pyx (starting at line 363)

Overrides: structure.sage_object.SageObject._octave_init_
(inherited documentation)

_pari_init_(self)

source code 
File: sage/structure/sage_object.pyx (starting at line 407)

Overrides: structure.sage_object.SageObject._pari_init_
(inherited documentation)

_gap_init_(self)

source code 

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

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

Overrides: structure.sage_object.SageObject._gap_init_

_singular_init_(self)

source code 

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

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

Overrides: structure.sage_object.SageObject._singular_init_

__int__(self)

source code 

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

__long__(self)

source code 

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

numerical_approx(self, prec=['4ti2-20061025', 'R-2.6.0', 'atlas-3.7.37', 'atlas-3.8.1', 'a..., digits=['4ti2-20061025', 'R-2.6.0', 'atlas-3.7.37', 'atlas-3.8.1', 'a...)

source code 

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

NOTE: You can use \code{foo.n()} as a shortcut for
\code{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.

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

Use the \code{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

n(self, prec=['4ti2-20061025', 'R-2.6.0', 'atlas-3.7.37', 'atlas-3.8.1', 'a..., digits=['4ti2-20061025', 'R-2.6.0', 'atlas-3.7.37', 'atlas-3.8.1', 'a...)

source code 

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

NOTE: You can use \code{foo.n()} as a shortcut for
\code{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.

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

Use the \code{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

Overrides: structure.element.Element.n

minpoly(self, bits=['4ti2-20061025', 'R-2.6.0', 'atlas-3.7.37', 'atlas-3.8.1', 'a..., degree=['4ti2-20061025', 'R-2.6.0', 'atlas-3.7.37', 'atlas-3.8.1', 'a..., epsilon=0)

source code 

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 \exception{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 \exception{NotImplementedError} will be raised. 

ALGORITHM: 
    Use the PARI algdep command on a numerical approximation of \code{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 \var{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. 


EXAMPLES: 

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 \var{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

_add_(self, right)

source code 

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

Overrides: structure.element.ModuleElement._add_

_sub_(self, right)

source code 

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

Overrides: structure.element.ModuleElement._sub_

_mul_(self, right)

source code 

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

Overrides: structure.element.RingElement._mul_

_div_(self, right)

source code 

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

Overrides: structure.element.RingElement._div_

__pow__(self, right)

source code 

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

Overrides: structure.element.RingElement.__pow__

variables(self, vars=())

source code 

Return sorted list of variables that occur in the simplified
form of \code{self}.

OUTPUT:
    a Python set
    
EXAMPLES:
    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,)            

arguments(self)

source code 

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

This is the same as \code{self.variables()}.

EXAMPLES:
    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)        

number_of_arguments(self)

source code 

Returns the number of arguments the object can take.

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

_has_op(self, operator)

source code 

Recursively searches for the given operator in a
\class{SymbolicExpression} object.

INPUT:
    operator: the operator to search for

OUTPUT:
    True or False

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

__call__(self, *args, **kwds)
(Call operator)

source code 

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

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

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


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

power_series(self, base_ring)

source code 

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.

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

polynomial(self, base_ring)

source code 

Return \code{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 \code{self.poly(x)} which is used
to rewrite self as a polynomial in x.

INPUT:
   base_ring -- a ring

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

_polynomial_(self, R)

source code 

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

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

function(self, *args)

source code 

Return a \class{CallableSymbolicExpression}, fixing a variable order
to be the order of args.

EXAMPLES:
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 \method{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 \code{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

_derivative(self, var=['4ti2-20061025', 'R-2.6.0', 'atlas-3.7.37', 'atlas-3.8.1', 'a...)

source code 

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

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

derivative(self, *args)

source code 

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

EXAMPLES:
    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, *args)

source code 

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

EXAMPLES:
    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, *args)

source code 

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

EXAMPLES:
    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))

gradient(self)

source code 

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

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

hessian(self)

source code 

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

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

taylor(self, v, a, n)

source code 

Expands \code{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

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

limit(self, dir=['4ti2-20061025', 'R-2.6.0', 'atlas-3.7.37', 'atlas-3.8.1', 'a..., taylor=False, **argv)

source code 

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

\begin{verbatim}
expr.limit(x = a)
expr.limit(x = a, dir='above')
\end{verbatim}

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

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

laplace(self, t, s)

source code 

Attempts to compute and return the Laplace transform of
\code{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
$$
     F(s) = \int_{0}^{\infty} e^{-st} f(t) dt.
$$

EXAMPLES:
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)

EXAMPLE: A BATTLE BETWEEN the X-women and the Y-men (by David Joyner):
Solve
$$
  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()

inverse_laplace(self, t, s)

source code 

Attempts to compute the inverse Laplace transform of
\code{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
$$
     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)$.

EXAMPLES:
    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)        

default_variable(self)

source code 

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.

EXAMPLES:
    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 \emph{variable}, not
the first \emph{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)        

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

source code 

Returns 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 \code{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
    

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


EXAMPLES:
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=['4ti2-20061025', 'R-2.6.0', 'atlas-3.7.37', 'atlas-3.8.1', 'a..., a=['4ti2-20061025', 'R-2.6.0', 'atlas-3.7.37', 'atlas-3.8.1', 'a..., b=['4ti2-20061025', 'R-2.6.0', 'atlas-3.7.37', 'atlas-3.8.1', 'a...)

source code 

Returns 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 \code{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
    

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


EXAMPLES:
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)

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

source code 

Return a floating point machine precision numerical
approximation to the integral of \code{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 \code{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

EXAMPLES:
    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 \code{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 \code{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.49927402801814311120646143662663009137292462589621789352095066181709095575681963967103004e-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)

source code 

Return a floating point machine precision numerical
approximation to the integral of \code{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 \code{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

EXAMPLES:
    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 \code{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 \code{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.49927402801814311120646143662663009137292462589621789352095066181709095575681963967103004e-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. 

coefficient(self, x, n=1)

source code 

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.

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

coeff(self, x, n=1)

source code 

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.

EXAMPLES:
    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=['4ti2-20061025', 'R-2.6.0', 'atlas-3.7.37', 'atlas-3.8.1', 'a...)

source code 

Coefficients of \code{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.

EXAMPLES:
    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=['4ti2-20061025', 'R-2.6.0', 'atlas-3.7.37', 'atlas-3.8.1', 'a...)

source code 

Coefficients of \code{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.

EXAMPLES:
    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]]        

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

source code 

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

WARNING: This is different from \code{self.polynomial()} which
returns a \sage polynomial over a given base ring.

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

combine(self)

source code 

Simplifies \code{self} by combining all terms with the same
denominator into a single term.

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

numerator(self)

source code 

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

denominator(self)

source code 

Return the denominator of self.

EXAMPLES:
    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)

factor_list(self, dontfactor=[])

source code 

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.

EXAMPLES:
    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))]

_factor_list(self)

source code 

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

This is used, e.g., internally by the \code{factor_list}
command.

EXAMPLES:
    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'>        

roots(self, x=['4ti2-20061025', 'R-2.6.0', 'atlas-3.7.37', 'atlas-3.8.1', 'a..., explicit_solutions=True)

source code 

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

WARNING: This is \emph{not} a numerical solver -- use
\code{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. 

EXAMPLES:
    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 \code{explicit_solutions=False}
to \code{.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)]

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

source code 

Analytically solve the equation \code{self == 0} for the variable $x$.

WARNING: This is not a numerical solver -- use
\code{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)
    
EXAMPLES:
    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]        

find_root(self, a, b, var=['4ti2-20061025', 'R-2.6.0', 'atlas-3.7.37', 'atlas-3.8.1', 'a..., xtol=1e-12, rtol=4.5e-16, maxiter=100, full_output=False)

source code 

 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.

 EXAMPLES:
 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 \code{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.
 

find_maximum_on_interval(self, a, b, var=['4ti2-20061025', 'R-2.6.0', 'atlas-3.7.37', 'atlas-3.8.1', 'a..., tol=1.48e-08, maxfun=500)

source code 

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

See the documentation for \code{self.find_minimum_on_interval}
for more details.

EXAMPLES:
    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=['4ti2-20061025', 'R-2.6.0', 'atlas-3.7.37', 'atlas-3.8.1', 'a..., tol=1.48e-08, maxfun=500)

source code 

Numerically find the minimum of the expression \code{self} on
the interval [a,b] (or [b,a]) and the point at which it
attains that minimum.  Note that \code{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

EXAMPLES:
    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 \module{scipy.optimize.fminbound} which uses Brent's method.

AUTHOR:
     -- William Stein (2007-12-07)

simplify(self)

source code 

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

EXAMPLES:
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 \code{_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 \code{__init__} automatically calls \code{_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

\code{simplify}, however, can be called manually:
    sage: f
    x^3 - 3*x^2 + 28
    sage: f.simplify()
    x^3 - 3*x^2 + 28

simplify_full(self)

source code 

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

ALIAS: simplfy_full and full_simplify are the same.

EXAMPLES:
    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))

full_simplify(self)

source code 

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

ALIAS: simplfy_full and full_simplify are the same.

EXAMPLES:
    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_trig(self)

source code 

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

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

trig_simplify(self)

source code 

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

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

simplify_rational(self)

source code 

Simplify by expanding repeatedly rational expressions.

ALIAS: rational_simplify and simplify_rational are the same

EXAMPLES:
    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)            

rational_simplify(self)

source code 

Simplify by expanding repeatedly rational expressions.

ALIAS: rational_simplify and simplify_rational are the same

EXAMPLES:
    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_radical(self)

source code 

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

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

log_simplify(self)

source code 

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

EXAMPLES:
    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_log(self)

source code 

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

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

radical_simplify(self)

source code 

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

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

exp_simplify(self)

source code 

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

EXAMPLES:
    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_exp(self)

source code 

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

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

factor(self, dontfactor=[])

source code 

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.

EXAMPLES:
    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)*...

expand(self)

source code 

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 \code{expand_rational}
which uses a more efficient algorithm.

EXAMPLES:
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 \code{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)

source code 

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.

EXAMPLES:
    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_expand(self)

source code 

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.

EXAMPLES:
    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)

source code 

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

EXAMPLES:
    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_expand(self, full=False, half_angles=False, plus=True, times=True)

source code 

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

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

substitute(self, in_dict=['4ti2-20061025', 'R-2.6.0', 'atlas-3.7.37', 'atlas-3.8.1', 'a..., **kwds)

source code 

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 \class{SymbolicExpression}.

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

EXAMPLES:
    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
    
    
AUTHORS:
    -- Bobby Moretti: Initial version

Overrides: structure.element.Element.substitute

subs(self, *args, **kwds)

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

Substitutes given generators with given values while not touching 
other generators. This is a generic wrapper around __call__.
The syntax is meant to be compatible with the corresponding method
for symbolic expressions.

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

OUTPUT:
    new object if substitution is possible, otherwise self.

EXAMPLES:
    sage: x, y = PolynomialRing(ZZ,2,'xy').gens()  
    sage: f = x^2 + y + x^2*y^2 + 5
    sage: f((5,y))
    25*y^2 + y + 30
    sage: f.subs({x:5})
    25*y^2 + y + 30
    sage: f.subs(x=5)
    25*y^2 + y + 30
    sage: (1/f).subs(x=5)
    1/(25*y^2 + y + 30)
    sage: Integer(5).subs(x=4)
    5

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

__parse_in_dict(self, in_dict, kwds)

source code 

EXAMPLES:
     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...>}
     

__varify_kwds(self, kwds)

source code 

EXAMPLES:
    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...>}
    

subs_expr(self, *equations)

source code 

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.

EXAMPLES:
    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]

real(self)

source code 

Return the real part of \code{self}.

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

imag(self)

source code 

Return the imaginary part of \code{self}.

EXAMPLES:
    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)

conjugate(self)

source code 

The complex conjugate of \code{self}.

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

norm(self)

source code 

The complex norm of \code{self}, i.e., \code{self} times its complex conjugate.

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

partial_fraction(self, var=['4ti2-20061025', 'R-2.6.0', 'atlas-3.7.37', 'atlas-3.8.1', 'a...)

source code 

Return the partial fraction expansion of \code{self} with respect to
the given variable.

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

OUTPUT:
    Symbolic expression

EXAMPLES:
    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)

_fast_float_(self, *vars)

source code 

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