import sympy as smp
from sympy import *
x = smp.symbols('x')
x ** 2
x, y = smp.symbols('x y')
x ** 4 + smp.sqrt(y)
f = x ** 3 / y + smp.sqrt(y) / x ** 2
f
f.subs(x , 2)
f.subs(y , 4)
f.subs(x, y)
f.subs(y, x)
f.subs(x, y + 2)
g = f.subs(x, y + 2)
g
g.subs(y, 2)
g.subs(y, 4)
g.subs(y, 1)
smp.sin(x)
smp.asin(x)
smp.sec(x)
smp.exp(x)
smp.log(x)
smp.log(x, 10)
x ** (5/2)
x ** (smp.Rational(5/2))
smp.sin(x/2) + smp.sin(x)
smp.limit(smp.sin(x/2 + smp.sin(x)), x, smp.pi)
2 * smp.exp(1/x)/(smp.exp(1/x) + 1)
smp.limit(2*smp.exp(1/x) / (smp.exp(1/x)+1), x, 0, dir='+')
smp.limit(2*smp.exp(1/x) / (smp.exp(1/x)+1), x, 0, dir='-')
(smp.cos(x) - 1)/x
smp.limit((smp.cos(x) - 1)/x, x, smp.oo)
x
smp.diff(x)
x ** 2
smp.diff(x ** 2)
smp.sin(x)
smp.diff(smp.sin(x))
smp.tan(x)
smp.diff(smp.tan(x))
smp.acos(x)
smp.diff(smp.acos(x))
((1 + smp.sin(x)) / (1 - smp.cos(x)))**2
smp.diff(((1 + smp.sin(x)) / (1 - smp.cos(x)))**2, x)
((y + smp.sin(x)) / (1 - smp.cos(x)))**2
smp.diff(((y + smp.sin(x)) / (1 - smp.cos(x)))**2, x)
smp.diff(((y + smp.sin(x)) / (1 - smp.cos(x)))**2, y)
smp.log(x, 5)**(x/2)
smp.diff(smp.log(x, 5)**(x/2), x)
f, g = smp.symbols('f g', cls=smp.Function)
g = g(x)
f = f(x+g)
g
f
smp.diff(f,x)
smp.integrate(x, x)
smp.integrate(smp.sqrt(x), x)
smp.integrate(smp.sqrt(x))
smp.integrate(smp.tan(x), x)
smp.integrate(smp.sec(x), x)
smp.csc(x)*smp.cot(x)
smp.integrate(smp.csc(x)*smp.cot(x), x)
4*smp.sec(3*x)*smp.tan(3*x)
smp.integrate(4*smp.sec(3*x)*smp.tan(3*x), x)
2/smp.sqrt(1-x**2) - 1/x**smp.Rational(1/4)
2/smp.sqrt(1-x**2) - 1/x**smp.Rational(1,4)
smp.integrate(2/smp.sqrt(1-x**2) - 1/x**smp.Rational(1,4), x)
x * smp.tan(x)
smp.integrate(x * smp.tan(x))
smp.integrate(x * smp.tan(x), x)
8*x + smp.csc(x)**2
y_withouth_C = smp.integrate(8*x + smp.csc(x)**2, x)
y_withouth_C
y_withouth_C.subs(x, smp.pi/2)
C = - y_withouth_C.subs(x, smp.pi/2) - 7
C
y_with_C = y_withouth_C + C
y = y_with_C
y
y.subs(x, smp.pi/2)
y
$$\int \frac{(1+\sqrt{x})^{1/3}}{\sqrt{x}} dx$$
(1+smp.sqrt(x))**smp.Rational(1,3) / smp.sqrt(x)
smp.integrate((1+smp.sqrt(x))**smp.Rational(1,3) / smp.sqrt(x), x)
x*(1-x**2)**smp.Rational(1/4)
smp.integrate(x*(1-x**2)**smp.Rational(1/4), x)
(2*x -1)*smp.cos(smp.sqrt(3*(2*x-1)**2 + 6)) / smp.sqrt(3*(2*x-1)**2 + 6)
smp.integrate((2*x -1)*smp.cos(smp.sqrt(3*(2*x-1)**2 + 6)) / smp.sqrt(3*(2*x-1)**2 + 6), x)
smp.exp(x) / smp.sqrt(smp.exp(2*x) + 9)
smp.integrate(smp.exp(x) / smp.sqrt(smp.exp(2*x) + 9), (x, 0, smp.log(4)))
x**10*smp.exp(x)
t= smp.symbols('t')
smp.integrate(x**10*smp.exp(x), (x, 1, t))
16*smp.atan(x) / (1+x**2)
smp.integrate(16*smp.atan(x) / (1+x**2), (x, 0, smp.oo))
n = smp.symbols('n')
n
6/4**n
smp.Sum(6/4**n, (n,0,smp.oo))
smp.Sum(6/4**n, (n,0,smp.oo)).doit()
2**(n+1) / 5**n
smp.Sum(2**(n+1) / 5**n, (n,0,smp.oo))
smp.Sum(2**(n+1) / 5**n, (n,0,smp.oo)).doit()
smp.atan(n)/n**smp.Rational(11,10)
smp.Sum(smp.atan(n)/n**smp.Rational(11,10), (n,1,smp.oo))
smp.Sum(smp.atan(n)/n**smp.Rational(11,10), (n,1,smp.oo)).doit()
smp.Sum(smp.atan(n)/n**smp.Rational(11,10), (n,1,smp.oo)).n()
(1+smp.cos(n))/n
smp.Sum((1+smp.cos(n))/n, (n,1,smp.oo)).doit()
smp.Sum((1+smp.cos(n))/n, (n,1,smp.oo)).n()
(1+smp.cos(n))/n**2
smp.Sum((1+smp.cos(n))/n**2, (n,1,smp.oo)).doit()
smp.Sum((1+smp.cos(n))/n**2, (n,1,smp.oo)).n()
$$ \sum_{n=1}^\infty \frac{1}{n^2}$$
smp.Sum((1)/n**2, (n,1,smp.oo)).doit()
smp.Sum((1)/n**3, (n,1,smp.oo)).doit()
smp.Sum((1)/n**4, (n,1,smp.oo)).doit()
smp.Sum(n, (n,1,n)).doit()
help(smp.hermite)
Help on class hermite in module sympy.functions.special.polynomials:
class hermite(OrthogonalPolynomial)
| hermite(n, x)
|
| ``hermite(n, x)`` gives the nth Hermite polynomial in x, $H_n(x)$
|
| Explanation
| ===========
|
| The Hermite polynomials are orthogonal on $(-\infty, \infty)$
| with respect to the weight $\exp\left(-x^2\right)$.
|
| Examples
| ========
|
| >>> from sympy import hermite, diff
| >>> from sympy.abc import x, n
| >>> hermite(0, x)
| 1
| >>> hermite(1, x)
| 2*x
| >>> hermite(2, x)
| 4*x**2 - 2
| >>> hermite(n, x)
| hermite(n, x)
| >>> diff(hermite(n,x), x)
| 2*n*hermite(n - 1, x)
| >>> hermite(n, -x)
| (-1)**n*hermite(n, x)
|
| See Also
| ========
|
| jacobi, gegenbauer,
| chebyshevt, chebyshevt_root, chebyshevu, chebyshevu_root,
| legendre, assoc_legendre,
| laguerre, assoc_laguerre,
| sympy.polys.orthopolys.jacobi_poly
| sympy.polys.orthopolys.gegenbauer_poly
| sympy.polys.orthopolys.chebyshevt_poly
| sympy.polys.orthopolys.chebyshevu_poly
| sympy.polys.orthopolys.hermite_poly
| sympy.polys.orthopolys.legendre_poly
| sympy.polys.orthopolys.laguerre_poly
|
| References
| ==========
|
| .. [1] https://en.wikipedia.org/wiki/Hermite_polynomial
| .. [2] http://mathworld.wolfram.com/HermitePolynomial.html
| .. [3] http://functions.wolfram.com/Polynomials/HermiteH/
|
| Method resolution order:
| hermite
| OrthogonalPolynomial
| sympy.core.function.Function
| sympy.core.function.Application
| sympy.core.expr.Expr
| sympy.core.basic.Basic
| sympy.printing.defaults.Printable
| sympy.core.evalf.EvalfMixin
| builtins.object
|
| Methods defined here:
|
| fdiff(self, argindex=2)
| Returns the first derivative of the function.
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| eval(n, x) from sympy.core.function.FunctionClass
| Returns a canonical form of cls applied to arguments args.
|
| Explanation
| ===========
|
| The eval() method is called when the class cls is about to be
| instantiated and it should return either some simplified instance
| (possible of some other class), or if the class cls should be
| unmodified, return None.
|
| Examples of eval() for the function "sign"
| ---------------------------------------------
|
| .. code-block:: python
|
| @classmethod
| def eval(cls, arg):
| if arg is S.NaN:
| return S.NaN
| if arg.is_zero: return S.Zero
| if arg.is_positive: return S.One
| if arg.is_negative: return S.NegativeOne
| if isinstance(arg, Mul):
| coeff, terms = arg.as_coeff_Mul(rational=True)
| if coeff is not S.One:
| return cls(coeff) * cls(terms)
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| __sympy__
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| default_assumptions = {}
|
| ----------------------------------------------------------------------
| Methods inherited from sympy.core.function.Function:
|
| as_base_exp(self)
| Returns the method as the 2-tuple (base, exponent).
|
| ----------------------------------------------------------------------
| Class methods inherited from sympy.core.function.Function:
|
| class_key() from sympy.core.function.FunctionClass
| Nice order of classes.
|
| is_singular(a) from sympy.core.function.FunctionClass
| Tests whether the argument is an essential singularity
| or a branch point, or the functions is non-holomorphic.
|
| ----------------------------------------------------------------------
| Static methods inherited from sympy.core.function.Function:
|
| __new__(cls, *args, **options)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from sympy.core.function.Application:
|
| func
| The top-level function in an expression.
|
| The following should hold for all objects::
|
| >> x == x.func(*x.args)
|
| Examples
| ========
|
| >>> from sympy.abc import x
| >>> a = 2*x
| >>> a.func
| <class 'sympy.core.mul.Mul'>
| >>> a.args
| (2, x)
| >>> a.func(*a.args)
| 2*x
| >>> a == a.func(*a.args)
| True
|
| ----------------------------------------------------------------------
| Data descriptors inherited from sympy.core.function.Application:
|
| __dict__
| dictionary for instance variables (if defined)
|
| __weakref__
| list of weak references to the object (if defined)
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from sympy.core.function.Application:
|
| is_Function = True
|
| ----------------------------------------------------------------------
| Methods inherited from sympy.core.expr.Expr:
|
| __abs__(self)
|
| __add__(self, other)
|
| __complex__(self)
|
| __divmod__(self, other)
|
| __eq__(self, other)
| Return a boolean indicating whether a == b on the basis of
| their symbolic trees.
|
| This is the same as a.compare(b) == 0 but faster.
|
| Notes
| =====
|
| If a class that overrides __eq__() needs to retain the
| implementation of __hash__() from a parent class, the
| interpreter must be told this explicitly by setting __hash__ =
| <ParentClass>.__hash__. Otherwise the inheritance of __hash__()
| will be blocked, just as if __hash__ had been explicitly set to
| None.
|
| References
| ==========
|
| from http://docs.python.org/dev/reference/datamodel.html#object.__hash__
|
| __float__(self)
|
| __floordiv__(self, other)
|
| __ge__(self, other)
| Return self>=value.
|
| __gt__(self, other)
| Return self>value.
|
| __hash__(self) -> int
| Return hash(self).
|
| __int__(self)
|
| __le__(self, other)
| Return self<=value.
|
| __lt__(self, other)
| Return self<value.
|
| __mod__(self, other)
|
| __mul__(self, other)
|
| __neg__(self)
|
| __pos__(self)
|
| __pow__(self, other, mod=None)
|
| __radd__(self, other)
|
| __rdivmod__(self, other)
|
| __rfloordiv__(self, other)
|
| __rmod__(self, other)
|
| __rmul__(self, other)
|
| __round__ = round(self, n=None)
|
| __rpow__(self, other)
|
| __rsub__(self, other)
|
| __rtruediv__(self, other)
|
| __sub__(self, other)
|
| __truediv__(self, other)
|
| __trunc__(self)
|
| adjoint(self)
|
| apart(self, x=None, **args)
| See the apart function in sympy.polys
|
| args_cnc(self, cset=False, warn=True, split_1=True)
| Return [commutative factors, non-commutative factors] of self.
|
| Explanation
| ===========
|
| self is treated as a Mul and the ordering of the factors is maintained.
| If ``cset`` is True the commutative factors will be returned in a set.
| If there were repeated factors (as may happen with an unevaluated Mul)
| then an error will be raised unless it is explicitly suppressed by
| setting ``warn`` to False.
|
| Note: -1 is always separated from a Number unless split_1 is False.
|
| Examples
| ========
|
| >>> from sympy import symbols, oo
| >>> A, B = symbols('A B', commutative=0)
| >>> x, y = symbols('x y')
| >>> (-2*x*y).args_cnc()
| [[-1, 2, x, y], []]
| >>> (-2.5*x).args_cnc()
| [[-1, 2.5, x], []]
| >>> (-2*x*A*B*y).args_cnc()
| [[-1, 2, x, y], [A, B]]
| >>> (-2*x*A*B*y).args_cnc(split_1=False)
| [[-2, x, y], [A, B]]
| >>> (-2*x*y).args_cnc(cset=True)
| [{-1, 2, x, y}, []]
|
| The arg is always treated as a Mul:
|
| >>> (-2 + x + A).args_cnc()
| [[], [x - 2 + A]]
| >>> (-oo).args_cnc() # -oo is a singleton
| [[-1, oo], []]
|
| as_coeff_Add(self, rational=False)
| Efficiently extract the coefficient of a summation.
|
| as_coeff_Mul(self, rational=False)
| Efficiently extract the coefficient of a product.
|
| as_coeff_add(self, *deps)
| Return the tuple (c, args) where self is written as an Add, ``a``.
|
| c should be a Rational added to any terms of the Add that are
| independent of deps.
|
| args should be a tuple of all other terms of ``a``; args is empty
| if self is a Number or if self is independent of deps (when given).
|
| This should be used when you don't know if self is an Add or not but
| you want to treat self as an Add or if you want to process the
| individual arguments of the tail of self as an Add.
|
| - if you know self is an Add and want only the head, use self.args[0];
| - if you don't want to process the arguments of the tail but need the
| tail then use self.as_two_terms() which gives the head and tail.
| - if you want to split self into an independent and dependent parts
| use ``self.as_independent(*deps)``
|
| >>> from sympy import S
| >>> from sympy.abc import x, y
| >>> (S(3)).as_coeff_add()
| (3, ())
| >>> (3 + x).as_coeff_add()
| (3, (x,))
| >>> (3 + x + y).as_coeff_add(x)
| (y + 3, (x,))
| >>> (3 + y).as_coeff_add(x)
| (y + 3, ())
|
| as_coeff_exponent(self, x)
| ``c*x**e -> c,e`` where x can be any symbolic expression.
|
| as_coeff_mul(self, *deps, **kwargs)
| Return the tuple (c, args) where self is written as a Mul, ``m``.
|
| c should be a Rational multiplied by any factors of the Mul that are
| independent of deps.
|
| args should be a tuple of all other factors of m; args is empty
| if self is a Number or if self is independent of deps (when given).
|
| This should be used when you don't know if self is a Mul or not but
| you want to treat self as a Mul or if you want to process the
| individual arguments of the tail of self as a Mul.
|
| - if you know self is a Mul and want only the head, use self.args[0];
| - if you don't want to process the arguments of the tail but need the
| tail then use self.as_two_terms() which gives the head and tail;
| - if you want to split self into an independent and dependent parts
| use ``self.as_independent(*deps)``
|
| >>> from sympy import S
| >>> from sympy.abc import x, y
| >>> (S(3)).as_coeff_mul()
| (3, ())
| >>> (3*x*y).as_coeff_mul()
| (3, (x, y))
| >>> (3*x*y).as_coeff_mul(x)
| (3*y, (x,))
| >>> (3*y).as_coeff_mul(x)
| (3*y, ())
|
| as_coefficient(self, expr)
| Extracts symbolic coefficient at the given expression. In
| other words, this functions separates 'self' into the product
| of 'expr' and 'expr'-free coefficient. If such separation
| is not possible it will return None.
|
| Examples
| ========
|
| >>> from sympy import E, pi, sin, I, Poly
| >>> from sympy.abc import x
|
| >>> E.as_coefficient(E)
| 1
| >>> (2*E).as_coefficient(E)
| 2
| >>> (2*sin(E)*E).as_coefficient(E)
|
| Two terms have E in them so a sum is returned. (If one were
| desiring the coefficient of the term exactly matching E then
| the constant from the returned expression could be selected.
| Or, for greater precision, a method of Poly can be used to
| indicate the desired term from which the coefficient is
| desired.)
|
| >>> (2*E + x*E).as_coefficient(E)
| x + 2
| >>> _.args[0] # just want the exact match
| 2
| >>> p = Poly(2*E + x*E); p
| Poly(x*E + 2*E, x, E, domain='ZZ')
| >>> p.coeff_monomial(E)
| 2
| >>> p.nth(0, 1)
| 2
|
| Since the following cannot be written as a product containing
| E as a factor, None is returned. (If the coefficient ``2*x`` is
| desired then the ``coeff`` method should be used.)
|
| >>> (2*E*x + x).as_coefficient(E)
| >>> (2*E*x + x).coeff(E)
| 2*x
|
| >>> (E*(x + 1) + x).as_coefficient(E)
|
| >>> (2*pi*I).as_coefficient(pi*I)
| 2
| >>> (2*I).as_coefficient(pi*I)
|
| See Also
| ========
|
| coeff: return sum of terms have a given factor
| as_coeff_Add: separate the additive constant from an expression
| as_coeff_Mul: separate the multiplicative constant from an expression
| as_independent: separate x-dependent terms/factors from others
| sympy.polys.polytools.Poly.coeff_monomial: efficiently find the single coefficient of a monomial in Poly
| sympy.polys.polytools.Poly.nth: like coeff_monomial but powers of monomial terms are used
|
| as_coefficients_dict(self)
| Return a dictionary mapping terms to their Rational coefficient.
| Since the dictionary is a defaultdict, inquiries about terms which
| were not present will return a coefficient of 0. If an expression is
| not an Add it is considered to have a single term.
|
| Examples
| ========
|
| >>> from sympy.abc import a, x
| >>> (3*x + a*x + 4).as_coefficients_dict()
| {1: 4, x: 3, a*x: 1}
| >>> _[a]
| 0
| >>> (3*a*x).as_coefficients_dict()
| {a*x: 3}
|
| as_content_primitive(self, radical=False, clear=True)
| This method should recursively remove a Rational from all arguments
| and return that (content) and the new self (primitive). The content
| should always be positive and ``Mul(*foo.as_content_primitive()) == foo``.
| The primitive need not be in canonical form and should try to preserve
| the underlying structure if possible (i.e. expand_mul should not be
| applied to self).
|
| Examples
| ========
|
| >>> from sympy import sqrt
| >>> from sympy.abc import x, y, z
|
| >>> eq = 2 + 2*x + 2*y*(3 + 3*y)
|
| The as_content_primitive function is recursive and retains structure:
|
| >>> eq.as_content_primitive()
| (2, x + 3*y*(y + 1) + 1)
|
| Integer powers will have Rationals extracted from the base:
|
| >>> ((2 + 6*x)**2).as_content_primitive()
| (4, (3*x + 1)**2)
| >>> ((2 + 6*x)**(2*y)).as_content_primitive()
| (1, (2*(3*x + 1))**(2*y))
|
| Terms may end up joining once their as_content_primitives are added:
|
| >>> ((5*(x*(1 + y)) + 2*x*(3 + 3*y))).as_content_primitive()
| (11, x*(y + 1))
| >>> ((3*(x*(1 + y)) + 2*x*(3 + 3*y))).as_content_primitive()
| (9, x*(y + 1))
| >>> ((3*(z*(1 + y)) + 2.0*x*(3 + 3*y))).as_content_primitive()
| (1, 6.0*x*(y + 1) + 3*z*(y + 1))
| >>> ((5*(x*(1 + y)) + 2*x*(3 + 3*y))**2).as_content_primitive()
| (121, x**2*(y + 1)**2)
| >>> ((x*(1 + y) + 0.4*x*(3 + 3*y))**2).as_content_primitive()
| (1, 4.84*x**2*(y + 1)**2)
|
| Radical content can also be factored out of the primitive:
|
| >>> (2*sqrt(2) + 4*sqrt(10)).as_content_primitive(radical=True)
| (2, sqrt(2)*(1 + 2*sqrt(5)))
|
| If clear=False (default is True) then content will not be removed
| from an Add if it can be distributed to leave one or more
| terms with integer coefficients.
|
| >>> (x/2 + y).as_content_primitive()
| (1/2, x + 2*y)
| >>> (x/2 + y).as_content_primitive(clear=False)
| (1, x/2 + y)
|
| as_expr(self, *gens)
| Convert a polynomial to a SymPy expression.
|
| Examples
| ========
|
| >>> from sympy import sin
| >>> from sympy.abc import x, y
|
| >>> f = (x**2 + x*y).as_poly(x, y)
| >>> f.as_expr()
| x**2 + x*y
|
| >>> sin(x).as_expr()
| sin(x)
|
| as_independent(self, *deps, **hint)
| A mostly naive separation of a Mul or Add into arguments that are not
| are dependent on deps. To obtain as complete a separation of variables
| as possible, use a separation method first, e.g.:
|
| * separatevars() to change Mul, Add and Pow (including exp) into Mul
| * .expand(mul=True) to change Add or Mul into Add
| * .expand(log=True) to change log expr into an Add
|
| The only non-naive thing that is done here is to respect noncommutative
| ordering of variables and to always return (0, 0) for `self` of zero
| regardless of hints.
|
| For nonzero `self`, the returned tuple (i, d) has the
| following interpretation:
|
| * i will has no variable that appears in deps
| * d will either have terms that contain variables that are in deps, or
| be equal to 0 (when self is an Add) or 1 (when self is a Mul)
| * if self is an Add then self = i + d
| * if self is a Mul then self = i*d
| * otherwise (self, S.One) or (S.One, self) is returned.
|
| To force the expression to be treated as an Add, use the hint as_Add=True
|
| Examples
| ========
|
| -- self is an Add
|
| >>> from sympy import sin, cos, exp
| >>> from sympy.abc import x, y, z
|
| >>> (x + x*y).as_independent(x)
| (0, x*y + x)
| >>> (x + x*y).as_independent(y)
| (x, x*y)
| >>> (2*x*sin(x) + y + x + z).as_independent(x)
| (y + z, 2*x*sin(x) + x)
| >>> (2*x*sin(x) + y + x + z).as_independent(x, y)
| (z, 2*x*sin(x) + x + y)
|
| -- self is a Mul
|
| >>> (x*sin(x)*cos(y)).as_independent(x)
| (cos(y), x*sin(x))
|
| non-commutative terms cannot always be separated out when self is a Mul
|
| >>> from sympy import symbols
| >>> n1, n2, n3 = symbols('n1 n2 n3', commutative=False)
| >>> (n1 + n1*n2).as_independent(n2)
| (n1, n1*n2)
| >>> (n2*n1 + n1*n2).as_independent(n2)
| (0, n1*n2 + n2*n1)
| >>> (n1*n2*n3).as_independent(n1)
| (1, n1*n2*n3)
| >>> (n1*n2*n3).as_independent(n2)
| (n1, n2*n3)
| >>> ((x-n1)*(x-y)).as_independent(x)
| (1, (x - y)*(x - n1))
|
| -- self is anything else:
|
| >>> (sin(x)).as_independent(x)
| (1, sin(x))
| >>> (sin(x)).as_independent(y)
| (sin(x), 1)
| >>> exp(x+y).as_independent(x)
| (1, exp(x + y))
|
| -- force self to be treated as an Add:
|
| >>> (3*x).as_independent(x, as_Add=True)
| (0, 3*x)
|
| -- force self to be treated as a Mul:
|
| >>> (3+x).as_independent(x, as_Add=False)
| (1, x + 3)
| >>> (-3+x).as_independent(x, as_Add=False)
| (1, x - 3)
|
| Note how the below differs from the above in making the
| constant on the dep term positive.
|
| >>> (y*(-3+x)).as_independent(x)
| (y, x - 3)
|
| -- use .as_independent() for true independence testing instead
| of .has(). The former considers only symbols in the free
| symbols while the latter considers all symbols
|
| >>> from sympy import Integral
| >>> I = Integral(x, (x, 1, 2))
| >>> I.has(x)
| True
| >>> x in I.free_symbols
| False
| >>> I.as_independent(x) == (I, 1)
| True
| >>> (I + x).as_independent(x) == (I, x)
| True
|
| Note: when trying to get independent terms, a separation method
| might need to be used first. In this case, it is important to keep
| track of what you send to this routine so you know how to interpret
| the returned values
|
| >>> from sympy import separatevars, log
| >>> separatevars(exp(x+y)).as_independent(x)
| (exp(y), exp(x))
| >>> (x + x*y).as_independent(y)
| (x, x*y)
| >>> separatevars(x + x*y).as_independent(y)
| (x, y + 1)
| >>> (x*(1 + y)).as_independent(y)
| (x, y + 1)
| >>> (x*(1 + y)).expand(mul=True).as_independent(y)
| (x, x*y)
| >>> a, b=symbols('a b', positive=True)
| >>> (log(a*b).expand(log=True)).as_independent(b)
| (log(a), log(b))
|
| See Also
| ========
| .separatevars(), .expand(log=True), sympy.core.add.Add.as_two_terms(),
| sympy.core.mul.Mul.as_two_terms(), .as_coeff_add(), .as_coeff_mul()
|
| as_leading_term(self, *symbols, cdir=0)
| Returns the leading (nonzero) term of the series expansion of self.
|
| The _eval_as_leading_term routines are used to do this, and they must
| always return a non-zero value.
|
| Examples
| ========
|
| >>> from sympy.abc import x
| >>> (1 + x + x**2).as_leading_term(x)
| 1
| >>> (1/x**2 + x + x**2).as_leading_term(x)
| x**(-2)
|
| as_numer_denom(self)
| expression -> a/b -> a, b
|
| This is just a stub that should be defined by
| an object's class methods to get anything else.
|
| See Also
| ========
|
| normal: return ``a/b`` instead of ``(a, b)``
|
| as_ordered_factors(self, order=None)
| Return list of ordered factors (if Mul) else [self].
|
| as_ordered_terms(self, order=None, data=False)
| Transform an expression to an ordered list of terms.
|
| Examples
| ========
|
| >>> from sympy import sin, cos
| >>> from sympy.abc import x
|
| >>> (sin(x)**2*cos(x) + sin(x)**2 + 1).as_ordered_terms()
| [sin(x)**2*cos(x), sin(x)**2, 1]
|
| as_poly(self, *gens, **args)
| Converts ``self`` to a polynomial or returns ``None``.
|
| Explanation
| ===========
|
| >>> from sympy import sin
| >>> from sympy.abc import x, y
|
| >>> print((x**2 + x*y).as_poly())
| Poly(x**2 + x*y, x, y, domain='ZZ')
|
| >>> print((x**2 + x*y).as_poly(x, y))
| Poly(x**2 + x*y, x, y, domain='ZZ')
|
| >>> print((x**2 + sin(y)).as_poly(x, y))
| None
|
| as_powers_dict(self)
| Return self as a dictionary of factors with each factor being
| treated as a power. The keys are the bases of the factors and the
| values, the corresponding exponents. The resulting dictionary should
| be used with caution if the expression is a Mul and contains non-
| commutative factors since the order that they appeared will be lost in
| the dictionary.
|
| See Also
| ========
| as_ordered_factors: An alternative for noncommutative applications,
| returning an ordered list of factors.
| args_cnc: Similar to as_ordered_factors, but guarantees separation
| of commutative and noncommutative factors.
|
| as_real_imag(self, deep=True, **hints)
| Performs complex expansion on 'self' and returns a tuple
| containing collected both real and imaginary parts. This
| method can't be confused with re() and im() functions,
| which does not perform complex expansion at evaluation.
|
| However it is possible to expand both re() and im()
| functions and get exactly the same results as with
| a single call to this function.
|
| >>> from sympy import symbols, I
|
| >>> x, y = symbols('x,y', real=True)
|
| >>> (x + y*I).as_real_imag()
| (x, y)
|
| >>> from sympy.abc import z, w
|
| >>> (z + w*I).as_real_imag()
| (re(z) - im(w), re(w) + im(z))
|
| as_terms(self)
| Transform an expression to a list of terms.
|
| aseries(self, x=None, n=6, bound=0, hir=False)
| Asymptotic Series expansion of self.
| This is equivalent to ``self.series(x, oo, n)``.
|
| Parameters
| ==========
|
| self : Expression
| The expression whose series is to be expanded.
|
| x : Symbol
| It is the variable of the expression to be calculated.
|
| n : Value
| The number of terms upto which the series is to be expanded.
|
| hir : Boolean
| Set this parameter to be True to produce hierarchical series.
| It stops the recursion at an early level and may provide nicer
| and more useful results.
|
| bound : Value, Integer
| Use the ``bound`` parameter to give limit on rewriting
| coefficients in its normalised form.
|
| Examples
| ========
|
| >>> from sympy import sin, exp
| >>> from sympy.abc import x
|
| >>> e = sin(1/x + exp(-x)) - sin(1/x)
|
| >>> e.aseries(x)
| (1/(24*x**4) - 1/(2*x**2) + 1 + O(x**(-6), (x, oo)))*exp(-x)
|
| >>> e.aseries(x, n=3, hir=True)
| -exp(-2*x)*sin(1/x)/2 + exp(-x)*cos(1/x) + O(exp(-3*x), (x, oo))
|
| >>> e = exp(exp(x)/(1 - 1/x))
|
| >>> e.aseries(x)
| exp(exp(x)/(1 - 1/x))
|
| >>> e.aseries(x, bound=3)
| exp(exp(x)/x**2)*exp(exp(x)/x)*exp(-exp(x) + exp(x)/(1 - 1/x) - exp(x)/x - exp(x)/x**2)*exp(exp(x))
|
| Returns
| =======
|
| Expr
| Asymptotic series expansion of the expression.
|
| Notes
| =====
|
| This algorithm is directly induced from the limit computational algorithm provided by Gruntz.
| It majorly uses the mrv and rewrite sub-routines. The overall idea of this algorithm is first
| to look for the most rapidly varying subexpression w of a given expression f and then expands f
| in a series in w. Then same thing is recursively done on the leading coefficient
| till we get constant coefficients.
|
| If the most rapidly varying subexpression of a given expression f is f itself,
| the algorithm tries to find a normalised representation of the mrv set and rewrites f
| using this normalised representation.
|
| If the expansion contains an order term, it will be either ``O(x ** (-n))`` or ``O(w ** (-n))``
| where ``w`` belongs to the most rapidly varying expression of ``self``.
|
| References
| ==========
|
| .. [1] A New Algorithm for Computing Asymptotic Series - Dominik Gruntz
| .. [2] Gruntz thesis - p90
| .. [3] http://en.wikipedia.org/wiki/Asymptotic_expansion
|
| See Also
| ========
|
| Expr.aseries: See the docstring of this function for complete details of this wrapper.
|
| cancel(self, *gens, **args)
| See the cancel function in sympy.polys
|
| coeff(self, x, n=1, right=False)
| Returns the coefficient from the term(s) containing ``x**n``. If ``n``
| is zero then all terms independent of ``x`` will be returned.
|
| Explanation
| ===========
|
| When ``x`` is noncommutative, the coefficient to the left (default) or
| right of ``x`` can be returned. The keyword 'right' is ignored when
| ``x`` is commutative.
|
| Examples
| ========
|
| >>> from sympy import symbols
| >>> from sympy.abc import x, y, z
|
| You can select terms that have an explicit negative in front of them:
|
| >>> (-x + 2*y).coeff(-1)
| x
| >>> (x - 2*y).coeff(-1)
| 2*y
|
| You can select terms with no Rational coefficient:
|
| >>> (x + 2*y).coeff(1)
| x
| >>> (3 + 2*x + 4*x**2).coeff(1)
| 0
|
| You can select terms independent of x by making n=0; in this case
| expr.as_independent(x)[0] is returned (and 0 will be returned instead
| of None):
|
| >>> (3 + 2*x + 4*x**2).coeff(x, 0)
| 3
| >>> eq = ((x + 1)**3).expand() + 1
| >>> eq
| x**3 + 3*x**2 + 3*x + 2
| >>> [eq.coeff(x, i) for i in reversed(range(4))]
| [1, 3, 3, 2]
| >>> eq -= 2
| >>> [eq.coeff(x, i) for i in reversed(range(4))]
| [1, 3, 3, 0]
|
| You can select terms that have a numerical term in front of them:
|
| >>> (-x - 2*y).coeff(2)
| -y
| >>> from sympy import sqrt
| >>> (x + sqrt(2)*x).coeff(sqrt(2))
| x
|
| The matching is exact:
|
| >>> (3 + 2*x + 4*x**2).coeff(x)
| 2
| >>> (3 + 2*x + 4*x**2).coeff(x**2)
| 4
| >>> (3 + 2*x + 4*x**2).coeff(x**3)
| 0
| >>> (z*(x + y)**2).coeff((x + y)**2)
| z
| >>> (z*(x + y)**2).coeff(x + y)
| 0
|
| In addition, no factoring is done, so 1 + z*(1 + y) is not obtained
| from the following:
|
| >>> (x + z*(x + x*y)).coeff(x)
| 1
|
| If such factoring is desired, factor_terms can be used first:
|
| >>> from sympy import factor_terms
| >>> factor_terms(x + z*(x + x*y)).coeff(x)
| z*(y + 1) + 1
|
| >>> n, m, o = symbols('n m o', commutative=False)
| >>> n.coeff(n)
| 1
| >>> (3*n).coeff(n)
| 3
| >>> (n*m + m*n*m).coeff(n) # = (1 + m)*n*m
| 1 + m
| >>> (n*m + m*n*m).coeff(n, right=True) # = (1 + m)*n*m
| m
|
| If there is more than one possible coefficient 0 is returned:
|
| >>> (n*m + m*n).coeff(n)
| 0
|
| If there is only one possible coefficient, it is returned:
|
| >>> (n*m + x*m*n).coeff(m*n)
| x
| >>> (n*m + x*m*n).coeff(m*n, right=1)
| 1
|
| See Also
| ========
|
| as_coefficient: separate the expression into a coefficient and factor
| as_coeff_Add: separate the additive constant from an expression
| as_coeff_Mul: separate the multiplicative constant from an expression
| as_independent: separate x-dependent terms/factors from others
| sympy.polys.polytools.Poly.coeff_monomial: efficiently find the single coefficient of a monomial in Poly
| sympy.polys.polytools.Poly.nth: like coeff_monomial but powers of monomial terms are used
|
| collect(self, syms, func=None, evaluate=True, exact=False, distribute_order_term=True)
| See the collect function in sympy.simplify
|
| combsimp(self)
| See the combsimp function in sympy.simplify
|
| compute_leading_term(self, x, logx=None)
| as_leading_term is only allowed for results of .series()
| This is a wrapper to compute a series first.
|
| conjugate(self)
| Returns the complex conjugate of 'self'.
|
| could_extract_minus_sign(self)
| Return True if self is not in a canonical form with respect
| to its sign.
|
| For most expressions, e, there will be a difference in e and -e.
| When there is, True will be returned for one and False for the
| other; False will be returned if there is no difference.
|
| Examples
| ========
|
| >>> from sympy.abc import x, y
| >>> e = x - y
| >>> {i.could_extract_minus_sign() for i in (e, -e)}
| {False, True}
|
| count_ops(self, visual=None)
| wrapper for count_ops that returns the operation count.
|
| diff(self, *symbols, **assumptions)
|
| dir(self, x, cdir)
|
| equals(self, other, failing_expression=False)
| Return True if self == other, False if it doesn't, or None. If
| failing_expression is True then the expression which did not simplify
| to a 0 will be returned instead of None.
|
| Explanation
| ===========
|
| If ``self`` is a Number (or complex number) that is not zero, then
| the result is False.
|
| If ``self`` is a number and has not evaluated to zero, evalf will be
| used to test whether the expression evaluates to zero. If it does so
| and the result has significance (i.e. the precision is either -1, for
| a Rational result, or is greater than 1) then the evalf value will be
| used to return True or False.
|
| expand(self, deep=True, modulus=None, power_base=True, power_exp=True, mul=True, log=True, multinomial=True, basic=True, **hints)
| Expand an expression using hints.
|
| See the docstring of the expand() function in sympy.core.function for
| more information.
|
| extract_additively(self, c)
| Return self - c if it's possible to subtract c from self and
| make all matching coefficients move towards zero, else return None.
|
| Examples
| ========
|
| >>> from sympy.abc import x, y
| >>> e = 2*x + 3
| >>> e.extract_additively(x + 1)
| x + 2
| >>> e.extract_additively(3*x)
| >>> e.extract_additively(4)
| >>> (y*(x + 1)).extract_additively(x + 1)
| >>> ((x + 1)*(x + 2*y + 1) + 3).extract_additively(x + 1)
| (x + 1)*(x + 2*y) + 3
|
| Sometimes auto-expansion will return a less simplified result
| than desired; gcd_terms might be used in such cases:
|
| >>> from sympy import gcd_terms
| >>> (4*x*(y + 1) + y).extract_additively(x)
| 4*x*(y + 1) + x*(4*y + 3) - x*(4*y + 4) + y
| >>> gcd_terms(_)
| x*(4*y + 3) + y
|
| See Also
| ========
| extract_multiplicatively
| coeff
| as_coefficient
|
| extract_branch_factor(self, allow_half=False)
| Try to write self as ``exp_polar(2*pi*I*n)*z`` in a nice way.
| Return (z, n).
|
| >>> from sympy import exp_polar, I, pi
| >>> from sympy.abc import x, y
| >>> exp_polar(I*pi).extract_branch_factor()
| (exp_polar(I*pi), 0)
| >>> exp_polar(2*I*pi).extract_branch_factor()
| (1, 1)
| >>> exp_polar(-pi*I).extract_branch_factor()
| (exp_polar(I*pi), -1)
| >>> exp_polar(3*pi*I + x).extract_branch_factor()
| (exp_polar(x + I*pi), 1)
| >>> (y*exp_polar(-5*pi*I)*exp_polar(3*pi*I + 2*pi*x)).extract_branch_factor()
| (y*exp_polar(2*pi*x), -1)
| >>> exp_polar(-I*pi/2).extract_branch_factor()
| (exp_polar(-I*pi/2), 0)
|
| If allow_half is True, also extract exp_polar(I*pi):
|
| >>> exp_polar(I*pi).extract_branch_factor(allow_half=True)
| (1, 1/2)
| >>> exp_polar(2*I*pi).extract_branch_factor(allow_half=True)
| (1, 1)
| >>> exp_polar(3*I*pi).extract_branch_factor(allow_half=True)
| (1, 3/2)
| >>> exp_polar(-I*pi).extract_branch_factor(allow_half=True)
| (1, -1/2)
|
| extract_multiplicatively(self, c)
| Return None if it's not possible to make self in the form
| c * something in a nice way, i.e. preserving the properties
| of arguments of self.
|
| Examples
| ========
|
| >>> from sympy import symbols, Rational
|
| >>> x, y = symbols('x,y', real=True)
|
| >>> ((x*y)**3).extract_multiplicatively(x**2 * y)
| x*y**2
|
| >>> ((x*y)**3).extract_multiplicatively(x**4 * y)
|
| >>> (2*x).extract_multiplicatively(2)
| x
|
| >>> (2*x).extract_multiplicatively(3)
|
| >>> (Rational(1, 2)*x).extract_multiplicatively(3)
| x/6
|
| factor(self, *gens, **args)
| See the factor() function in sympy.polys.polytools
|
| fourier_series(self, limits=None)
| Compute fourier sine/cosine series of self.
|
| See the docstring of the :func:`fourier_series` in sympy.series.fourier
| for more information.
|
| fps(self, x=None, x0=0, dir=1, hyper=True, order=4, rational=True, full=False)
| Compute formal power power series of self.
|
| See the docstring of the :func:`fps` function in sympy.series.formal for
| more information.
|
| gammasimp(self)
| See the gammasimp function in sympy.simplify
|
| getO(self)
| Returns the additive O(..) symbol if there is one, else None.
|
| getn(self)
| Returns the order of the expression.
|
| Explanation
| ===========
|
| The order is determined either from the O(...) term. If there
| is no O(...) term, it returns None.
|
| Examples
| ========
|
| >>> from sympy import O
| >>> from sympy.abc import x
| >>> (1 + x + O(x**2)).getn()
| 2
| >>> (1 + x).getn()
|
| integrate(self, *args, **kwargs)
| See the integrate function in sympy.integrals
|
| invert(self, g, *gens, **args)
| Return the multiplicative inverse of ``self`` mod ``g``
| where ``self`` (and ``g``) may be symbolic expressions).
|
| See Also
| ========
| sympy.core.numbers.mod_inverse, sympy.polys.polytools.invert
|
| is_algebraic_expr(self, *syms)
| This tests whether a given expression is algebraic or not, in the
| given symbols, syms. When syms is not given, all free symbols
| will be used. The rational function does not have to be in expanded
| or in any kind of canonical form.
|
| This function returns False for expressions that are "algebraic
| expressions" with symbolic exponents. This is a simple extension to the
| is_rational_function, including rational exponentiation.
|
| Examples
| ========
|
| >>> from sympy import Symbol, sqrt
| >>> x = Symbol('x', real=True)
| >>> sqrt(1 + x).is_rational_function()
| False
| >>> sqrt(1 + x).is_algebraic_expr()
| True
|
| This function does not attempt any nontrivial simplifications that may
| result in an expression that does not appear to be an algebraic
| expression to become one.
|
| >>> from sympy import exp, factor
| >>> a = sqrt(exp(x)**2 + 2*exp(x) + 1)/(exp(x) + 1)
| >>> a.is_algebraic_expr(x)
| False
| >>> factor(a).is_algebraic_expr()
| True
|
| See Also
| ========
| is_rational_function()
|
| References
| ==========
|
| - https://en.wikipedia.org/wiki/Algebraic_expression
|
| is_constant(self, *wrt, **flags)
| Return True if self is constant, False if not, or None if
| the constancy could not be determined conclusively.
|
| Explanation
| ===========
|
| If an expression has no free symbols then it is a constant. If
| there are free symbols it is possible that the expression is a
| constant, perhaps (but not necessarily) zero. To test such
| expressions, a few strategies are tried:
|
| 1) numerical evaluation at two random points. If two such evaluations
| give two different values and the values have a precision greater than
| 1 then self is not constant. If the evaluations agree or could not be
| obtained with any precision, no decision is made. The numerical testing
| is done only if ``wrt`` is different than the free symbols.
|
| 2) differentiation with respect to variables in 'wrt' (or all free
| symbols if omitted) to see if the expression is constant or not. This
| will not always lead to an expression that is zero even though an
| expression is constant (see added test in test_expr.py). If
| all derivatives are zero then self is constant with respect to the
| given symbols.
|
| 3) finding out zeros of denominator expression with free_symbols.
| It won't be constant if there are zeros. It gives more negative
| answers for expression that are not constant.
|
| If neither evaluation nor differentiation can prove the expression is
| constant, None is returned unless two numerical values happened to be
| the same and the flag ``failing_number`` is True -- in that case the
| numerical value will be returned.
|
| If flag simplify=False is passed, self will not be simplified;
| the default is True since self should be simplified before testing.
|
| Examples
| ========
|
| >>> from sympy import cos, sin, Sum, S, pi
| >>> from sympy.abc import a, n, x, y
| >>> x.is_constant()
| False
| >>> S(2).is_constant()
| True
| >>> Sum(x, (x, 1, 10)).is_constant()
| True
| >>> Sum(x, (x, 1, n)).is_constant()
| False
| >>> Sum(x, (x, 1, n)).is_constant(y)
| True
| >>> Sum(x, (x, 1, n)).is_constant(n)
| False
| >>> Sum(x, (x, 1, n)).is_constant(x)
| True
| >>> eq = a*cos(x)**2 + a*sin(x)**2 - a
| >>> eq.is_constant()
| True
| >>> eq.subs({x: pi, a: 2}) == eq.subs({x: pi, a: 3}) == 0
| True
|
| >>> (0**x).is_constant()
| False
| >>> x.is_constant()
| False
| >>> (x**x).is_constant()
| False
| >>> one = cos(x)**2 + sin(x)**2
| >>> one.is_constant()
| True
| >>> ((one - 1)**(x + 1)).is_constant() in (True, False) # could be 0 or 1
| True
|
| is_meromorphic(self, x, a)
| This tests whether an expression is meromorphic as
| a function of the given symbol ``x`` at the point ``a``.
|
| This method is intended as a quick test that will return
| None if no decision can be made without simplification or
| more detailed analysis.
|
| Examples
| ========
|
| >>> from sympy import zoo, log, sin, sqrt
| >>> from sympy.abc import x
|
| >>> f = 1/x**2 + 1 - 2*x**3
| >>> f.is_meromorphic(x, 0)
| True
| >>> f.is_meromorphic(x, 1)
| True
| >>> f.is_meromorphic(x, zoo)
| True
|
| >>> g = x**log(3)
| >>> g.is_meromorphic(x, 0)
| False
| >>> g.is_meromorphic(x, 1)
| True
| >>> g.is_meromorphic(x, zoo)
| False
|
| >>> h = sin(1/x)*x**2
| >>> h.is_meromorphic(x, 0)
| False
| >>> h.is_meromorphic(x, 1)
| True
| >>> h.is_meromorphic(x, zoo)
| True
|
| Multivalued functions are considered meromorphic when their
| branches are meromorphic. Thus most functions are meromorphic
| everywhere except at essential singularities and branch points.
| In particular, they will be meromorphic also on branch cuts
| except at their endpoints.
|
| >>> log(x).is_meromorphic(x, -1)
| True
| >>> log(x).is_meromorphic(x, 0)
| False
| >>> sqrt(x).is_meromorphic(x, -1)
| True
| >>> sqrt(x).is_meromorphic(x, 0)
| False
|
| is_polynomial(self, *syms)
| Return True if self is a polynomial in syms and False otherwise.
|
| This checks if self is an exact polynomial in syms. This function
| returns False for expressions that are "polynomials" with symbolic
| exponents. Thus, you should be able to apply polynomial algorithms to
| expressions for which this returns True, and Poly(expr, \*syms) should
| work if and only if expr.is_polynomial(\*syms) returns True. The
| polynomial does not have to be in expanded form. If no symbols are
| given, all free symbols in the expression will be used.
|
| This is not part of the assumptions system. You cannot do
| Symbol('z', polynomial=True).
|
| Examples
| ========
|
| >>> from sympy import Symbol
| >>> x = Symbol('x')
| >>> ((x**2 + 1)**4).is_polynomial(x)
| True
| >>> ((x**2 + 1)**4).is_polynomial()
| True
| >>> (2**x + 1).is_polynomial(x)
| False
|
|
| >>> n = Symbol('n', nonnegative=True, integer=True)
| >>> (x**n + 1).is_polynomial(x)
| False
|
| This function does not attempt any nontrivial simplifications that may
| result in an expression that does not appear to be a polynomial to
| become one.
|
| >>> from sympy import sqrt, factor, cancel
| >>> y = Symbol('y', positive=True)
| >>> a = sqrt(y**2 + 2*y + 1)
| >>> a.is_polynomial(y)
| False
| >>> factor(a)
| y + 1
| >>> factor(a).is_polynomial(y)
| True
|
| >>> b = (y**2 + 2*y + 1)/(y + 1)
| >>> b.is_polynomial(y)
| False
| >>> cancel(b)
| y + 1
| >>> cancel(b).is_polynomial(y)
| True
|
| See also .is_rational_function()
|
| is_rational_function(self, *syms)
| Test whether function is a ratio of two polynomials in the given
| symbols, syms. When syms is not given, all free symbols will be used.
| The rational function does not have to be in expanded or in any kind of
| canonical form.
|
| This function returns False for expressions that are "rational
| functions" with symbolic exponents. Thus, you should be able to call
| .as_numer_denom() and apply polynomial algorithms to the result for
| expressions for which this returns True.
|
| This is not part of the assumptions system. You cannot do
| Symbol('z', rational_function=True).
|
| Examples
| ========
|
| >>> from sympy import Symbol, sin
| >>> from sympy.abc import x, y
|
| >>> (x/y).is_rational_function()
| True
|
| >>> (x**2).is_rational_function()
| True
|
| >>> (x/sin(y)).is_rational_function(y)
| False
|
| >>> n = Symbol('n', integer=True)
| >>> (x**n + 1).is_rational_function(x)
| False
|
| This function does not attempt any nontrivial simplifications that may
| result in an expression that does not appear to be a rational function
| to become one.
|
| >>> from sympy import sqrt, factor
| >>> y = Symbol('y', positive=True)
| >>> a = sqrt(y**2 + 2*y + 1)/y
| >>> a.is_rational_function(y)
| False
| >>> factor(a)
| (y + 1)/y
| >>> factor(a).is_rational_function(y)
| True
|
| See also is_algebraic_expr().
|
| leadterm(self, x, cdir=0)
| Returns the leading term a*x**b as a tuple (a, b).
|
| Examples
| ========
|
| >>> from sympy.abc import x
| >>> (1+x+x**2).leadterm(x)
| (1, 0)
| >>> (1/x**2+x+x**2).leadterm(x)
| (1, -2)
|
| limit(self, x, xlim, dir='+')
| Compute limit x->xlim.
|
| lseries(self, x=None, x0=0, dir='+', logx=None, cdir=0)
| Wrapper for series yielding an iterator of the terms of the series.
|
| Note: an infinite series will yield an infinite iterator. The following,
| for exaxmple, will never terminate. It will just keep printing terms
| of the sin(x) series::
|
| for term in sin(x).lseries(x):
| print term
|
| The advantage of lseries() over nseries() is that many times you are
| just interested in the next term in the series (i.e. the first term for
| example), but you don't know how many you should ask for in nseries()
| using the "n" parameter.
|
| See also nseries().
|
| normal(self)
| expression -> a/b
|
| See Also
| ========
|
| as_numer_denom: return ``(a, b)`` instead of ``a/b``
|
| nseries(self, x=None, x0=0, n=6, dir='+', logx=None, cdir=0)
| Wrapper to _eval_nseries if assumptions allow, else to series.
|
| If x is given, x0 is 0, dir='+', and self has x, then _eval_nseries is
| called. This calculates "n" terms in the innermost expressions and
| then builds up the final series just by "cross-multiplying" everything
| out.
|
| The optional ``logx`` parameter can be used to replace any log(x) in the
| returned series with a symbolic value to avoid evaluating log(x) at 0. A
| symbol to use in place of log(x) should be provided.
|
| Advantage -- it's fast, because we don't have to determine how many
| terms we need to calculate in advance.
|
| Disadvantage -- you may end up with less terms than you may have
| expected, but the O(x**n) term appended will always be correct and
| so the result, though perhaps shorter, will also be correct.
|
| If any of those assumptions is not met, this is treated like a
| wrapper to series which will try harder to return the correct
| number of terms.
|
| See also lseries().
|
| Examples
| ========
|
| >>> from sympy import sin, log, Symbol
| >>> from sympy.abc import x, y
| >>> sin(x).nseries(x, 0, 6)
| x - x**3/6 + x**5/120 + O(x**6)
| >>> log(x+1).nseries(x, 0, 5)
| x - x**2/2 + x**3/3 - x**4/4 + O(x**5)
|
| Handling of the ``logx`` parameter --- in the following example the
| expansion fails since ``sin`` does not have an asymptotic expansion
| at -oo (the limit of log(x) as x approaches 0):
|
| >>> e = sin(log(x))
| >>> e.nseries(x, 0, 6)
| Traceback (most recent call last):
| ...
| PoleError: ...
| ...
| >>> logx = Symbol('logx')
| >>> e.nseries(x, 0, 6, logx=logx)
| sin(logx)
|
| In the following example, the expansion works but gives only an Order term
| unless the ``logx`` parameter is used:
|
| >>> e = x**y
| >>> e.nseries(x, 0, 2)
| O(log(x)**2)
| >>> e.nseries(x, 0, 2, logx=logx)
| exp(logx*y)
|
| nsimplify(self, constants=[], tolerance=None, full=False)
| See the nsimplify function in sympy.simplify
|
| powsimp(self, *args, **kwargs)
| See the powsimp function in sympy.simplify
|
| primitive(self)
| Return the positive Rational that can be extracted non-recursively
| from every term of self (i.e., self is treated like an Add). This is
| like the as_coeff_Mul() method but primitive always extracts a positive
| Rational (never a negative or a Float).
|
| Examples
| ========
|
| >>> from sympy.abc import x
| >>> (3*(x + 1)**2).primitive()
| (3, (x + 1)**2)
| >>> a = (6*x + 2); a.primitive()
| (2, 3*x + 1)
| >>> b = (x/2 + 3); b.primitive()
| (1/2, x + 6)
| >>> (a*b).primitive() == (1, a*b)
| True
|
| radsimp(self, **kwargs)
| See the radsimp function in sympy.simplify
|
| ratsimp(self)
| See the ratsimp function in sympy.simplify
|
| removeO(self)
| Removes the additive O(..) symbol if there is one
|
| round(self, n=None)
| Return x rounded to the given decimal place.
|
| If a complex number would results, apply round to the real
| and imaginary components of the number.
|
| Examples
| ========
|
| >>> from sympy import pi, E, I, S, Number
| >>> pi.round()
| 3
| >>> pi.round(2)
| 3.14
| >>> (2*pi + E*I).round()
| 6 + 3*I
|
| The round method has a chopping effect:
|
| >>> (2*pi + I/10).round()
| 6
| >>> (pi/10 + 2*I).round()
| 2*I
| >>> (pi/10 + E*I).round(2)
| 0.31 + 2.72*I
|
| Notes
| =====
|
| The Python ``round`` function uses the SymPy ``round`` method so it
| will always return a SymPy number (not a Python float or int):
|
| >>> isinstance(round(S(123), -2), Number)
| True
|
| separate(self, deep=False, force=False)
| See the separate function in sympy.simplify
|
| series(self, x=None, x0=0, n=6, dir='+', logx=None, cdir=0)
| Series expansion of "self" around ``x = x0`` yielding either terms of
| the series one by one (the lazy series given when n=None), else
| all the terms at once when n != None.
|
| Returns the series expansion of "self" around the point ``x = x0``
| with respect to ``x`` up to ``O((x - x0)**n, x, x0)`` (default n is 6).
|
| If ``x=None`` and ``self`` is univariate, the univariate symbol will
| be supplied, otherwise an error will be raised.
|
| Parameters
| ==========
|
| expr : Expression
| The expression whose series is to be expanded.
|
| x : Symbol
| It is the variable of the expression to be calculated.
|
| x0 : Value
| The value around which ``x`` is calculated. Can be any value
| from ``-oo`` to ``oo``.
|
| n : Value
| The number of terms upto which the series is to be expanded.
|
| dir : String, optional
| The series-expansion can be bi-directional. If ``dir="+"``,
| then (x->x0+). If ``dir="-", then (x->x0-). For infinite
| ``x0`` (``oo`` or ``-oo``), the ``dir`` argument is determined
| from the direction of the infinity (i.e., ``dir="-"`` for
| ``oo``).
|
| logx : optional
| It is used to replace any log(x) in the returned series with a
| symbolic value rather than evaluating the actual value.
|
| cdir : optional
| It stands for complex direction, and indicates the direction
| from which the expansion needs to be evaluated.
|
| Examples
| ========
|
| >>> from sympy import cos, exp, tan
| >>> from sympy.abc import x, y
| >>> cos(x).series()
| 1 - x**2/2 + x**4/24 + O(x**6)
| >>> cos(x).series(n=4)
| 1 - x**2/2 + O(x**4)
| >>> cos(x).series(x, x0=1, n=2)
| cos(1) - (x - 1)*sin(1) + O((x - 1)**2, (x, 1))
| >>> e = cos(x + exp(y))
| >>> e.series(y, n=2)
| cos(x + 1) - y*sin(x + 1) + O(y**2)
| >>> e.series(x, n=2)
| cos(exp(y)) - x*sin(exp(y)) + O(x**2)
|
| If ``n=None`` then a generator of the series terms will be returned.
|
| >>> term=cos(x).series(n=None)
| >>> [next(term) for i in range(2)]
| [1, -x**2/2]
|
| For ``dir=+`` (default) the series is calculated from the right and
| for ``dir=-`` the series from the left. For smooth functions this
| flag will not alter the results.
|
| >>> abs(x).series(dir="+")
| x
| >>> abs(x).series(dir="-")
| -x
| >>> f = tan(x)
| >>> f.series(x, 2, 6, "+")
| tan(2) + (1 + tan(2)**2)*(x - 2) + (x - 2)**2*(tan(2)**3 + tan(2)) +
| (x - 2)**3*(1/3 + 4*tan(2)**2/3 + tan(2)**4) + (x - 2)**4*(tan(2)**5 +
| 5*tan(2)**3/3 + 2*tan(2)/3) + (x - 2)**5*(2/15 + 17*tan(2)**2/15 +
| 2*tan(2)**4 + tan(2)**6) + O((x - 2)**6, (x, 2))
|
| >>> f.series(x, 2, 3, "-")
| tan(2) + (2 - x)*(-tan(2)**2 - 1) + (2 - x)**2*(tan(2)**3 + tan(2))
| + O((x - 2)**3, (x, 2))
|
| Returns
| =======
|
| Expr : Expression
| Series expansion of the expression about x0
|
| Raises
| ======
|
| TypeError
| If "n" and "x0" are infinity objects
|
| PoleError
| If "x0" is an infinity object
|
| sort_key(self, order=None)
| Return a sort key.
|
| Examples
| ========
|
| >>> from sympy.core import S, I
|
| >>> sorted([S(1)/2, I, -I], key=lambda x: x.sort_key())
| [1/2, -I, I]
|
| >>> S("[x, 1/x, 1/x**2, x**2, x**(1/2), x**(1/4), x**(3/2)]")
| [x, 1/x, x**(-2), x**2, sqrt(x), x**(1/4), x**(3/2)]
| >>> sorted(_, key=lambda x: x.sort_key())
| [x**(-2), 1/x, x**(1/4), sqrt(x), x, x**(3/2), x**2]
|
| taylor_term(self, n, x, *previous_terms)
| General method for the taylor term.
|
| This method is slow, because it differentiates n-times. Subclasses can
| redefine it to make it faster by using the "previous_terms".
|
| together(self, *args, **kwargs)
| See the together function in sympy.polys
|
| transpose(self)
|
| trigsimp(self, **args)
| See the trigsimp function in sympy.simplify
|
| ----------------------------------------------------------------------
| Readonly properties inherited from sympy.core.expr.Expr:
|
| expr_free_symbols
| Like ``free_symbols``, but returns the free symbols only if they are contained in an expression node.
|
| Examples
| ========
|
| >>> from sympy.abc import x, y
| >>> (x + y).expr_free_symbols
| {x, y}
|
| If the expression is contained in a non-expression object, don't return
| the free symbols. Compare:
|
| >>> from sympy import Tuple
| >>> t = Tuple(x + y)
| >>> t.expr_free_symbols
| set()
| >>> t.free_symbols
| {x, y}
|
| is_number
| Returns True if ``self`` has no free symbols and no
| undefined functions (AppliedUndef, to be precise). It will be
| faster than ``if not self.free_symbols``, however, since
| ``is_number`` will fail as soon as it hits a free symbol
| or undefined function.
|
| Examples
| ========
|
| >>> from sympy import Integral, cos, sin, pi
| >>> from sympy.core.function import Function
| >>> from sympy.abc import x
| >>> f = Function('f')
|
| >>> x.is_number
| False
| >>> f(1).is_number
| False
| >>> (2*x).is_number
| False
| >>> (2 + Integral(2, x)).is_number
| False
| >>> (2 + Integral(2, (x, 1, 2))).is_number
| True
|
| Not all numbers are Numbers in the SymPy sense:
|
| >>> pi.is_number, pi.is_Number
| (True, False)
|
| If something is a number it should evaluate to a number with
| real and imaginary parts that are Numbers; the result may not
| be comparable, however, since the real and/or imaginary part
| of the result may not have precision.
|
| >>> cos(1).is_number and cos(1).is_comparable
| True
|
| >>> z = cos(1)**2 + sin(1)**2 - 1
| >>> z.is_number
| True
| >>> z.is_comparable
| False
|
| See Also
| ========
|
| sympy.core.basic.Basic.is_comparable
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from sympy.core.expr.Expr:
|
| is_scalar = True
|
| ----------------------------------------------------------------------
| Methods inherited from sympy.core.basic.Basic:
|
| __getnewargs__(self)
|
| __getstate__(self)
|
| __ne__(self, other)
| ``a != b`` -> Compare two symbolic trees and see whether they are different
|
| this is the same as:
|
| ``a.compare(b) != 0``
|
| but faster
|
| __reduce_ex__(self, proto)
| Pickling support.
|
| __setstate__(self, state)
|
| as_dummy(self)
| Return the expression with any objects having structurally
| bound symbols replaced with unique, canonical symbols within
| the object in which they appear and having only the default
| assumption for commutativity being True. When applied to a
| symbol a new symbol having only the same commutativity will be
| returned.
|
| Examples
| ========
|
| >>> from sympy import Integral, Symbol
| >>> from sympy.abc import x
| >>> r = Symbol('r', real=True)
| >>> Integral(r, (r, x)).as_dummy()
| Integral(_0, (_0, x))
| >>> _.variables[0].is_real is None
| True
| >>> r.as_dummy()
| _r
|
| Notes
| =====
|
| Any object that has structurally bound variables should have
| a property, `bound_symbols` that returns those symbols
| appearing in the object.
|
| atoms(self, *types)
| Returns the atoms that form the current object.
|
| By default, only objects that are truly atomic and can't
| be divided into smaller pieces are returned: symbols, numbers,
| and number symbols like I and pi. It is possible to request
| atoms of any type, however, as demonstrated below.
|
| Examples
| ========
|
| >>> from sympy import I, pi, sin
| >>> from sympy.abc import x, y
| >>> (1 + x + 2*sin(y + I*pi)).atoms()
| {1, 2, I, pi, x, y}
|
| If one or more types are given, the results will contain only
| those types of atoms.
|
| >>> from sympy import Number, NumberSymbol, Symbol
| >>> (1 + x + 2*sin(y + I*pi)).atoms(Symbol)
| {x, y}
|
| >>> (1 + x + 2*sin(y + I*pi)).atoms(Number)
| {1, 2}
|
| >>> (1 + x + 2*sin(y + I*pi)).atoms(Number, NumberSymbol)
| {1, 2, pi}
|
| >>> (1 + x + 2*sin(y + I*pi)).atoms(Number, NumberSymbol, I)
| {1, 2, I, pi}
|
| Note that I (imaginary unit) and zoo (complex infinity) are special
| types of number symbols and are not part of the NumberSymbol class.
|
| The type can be given implicitly, too:
|
| >>> (1 + x + 2*sin(y + I*pi)).atoms(x) # x is a Symbol
| {x, y}
|
| Be careful to check your assumptions when using the implicit option
| since ``S(1).is_Integer = True`` but ``type(S(1))`` is ``One``, a special type
| of sympy atom, while ``type(S(2))`` is type ``Integer`` and will find all
| integers in an expression:
|
| >>> from sympy import S
| >>> (1 + x + 2*sin(y + I*pi)).atoms(S(1))
| {1}
|
| >>> (1 + x + 2*sin(y + I*pi)).atoms(S(2))
| {1, 2}
|
| Finally, arguments to atoms() can select more than atomic atoms: any
| sympy type (loaded in core/__init__.py) can be listed as an argument
| and those types of "atoms" as found in scanning the arguments of the
| expression recursively:
|
| >>> from sympy import Function, Mul
| >>> from sympy.core.function import AppliedUndef
| >>> f = Function('f')
| >>> (1 + f(x) + 2*sin(y + I*pi)).atoms(Function)
| {f(x), sin(y + I*pi)}
| >>> (1 + f(x) + 2*sin(y + I*pi)).atoms(AppliedUndef)
| {f(x)}
|
| >>> (1 + x + 2*sin(y + I*pi)).atoms(Mul)
| {I*pi, 2*sin(y + I*pi)}
|
| compare(self, other)
| Return -1, 0, 1 if the object is smaller, equal, or greater than other.
|
| Not in the mathematical sense. If the object is of a different type
| from the "other" then their classes are ordered according to
| the sorted_classes list.
|
| Examples
| ========
|
| >>> from sympy.abc import x, y
| >>> x.compare(y)
| -1
| >>> x.compare(x)
| 0
| >>> y.compare(x)
| 1
|
| copy(self)
|
| count(self, query)
| Count the number of matching subexpressions.
|
| doit(self, **hints)
| Evaluate objects that are not evaluated by default like limits,
| integrals, sums and products. All objects of this kind will be
| evaluated recursively, unless some species were excluded via 'hints'
| or unless the 'deep' hint was set to 'False'.
|
| >>> from sympy import Integral
| >>> from sympy.abc import x
|
| >>> 2*Integral(x, x)
| 2*Integral(x, x)
|
| >>> (2*Integral(x, x)).doit()
| x**2
|
| >>> (2*Integral(x, x)).doit(deep=False)
| 2*Integral(x, x)
|
| dummy_eq(self, other, symbol=None)
| Compare two expressions and handle dummy symbols.
|
| Examples
| ========
|
| >>> from sympy import Dummy
| >>> from sympy.abc import x, y
|
| >>> u = Dummy('u')
|
| >>> (u**2 + 1).dummy_eq(x**2 + 1)
| True
| >>> (u**2 + 1) == (x**2 + 1)
| False
|
| >>> (u**2 + y).dummy_eq(x**2 + y, x)
| True
| >>> (u**2 + y).dummy_eq(x**2 + y, y)
| False
|
| find(self, query, group=False)
| Find all subexpressions matching a query.
|
| has(self, *patterns)
| Test whether any subexpression matches any of the patterns.
|
| Examples
| ========
|
| >>> from sympy import sin
| >>> from sympy.abc import x, y, z
| >>> (x**2 + sin(x*y)).has(z)
| False
| >>> (x**2 + sin(x*y)).has(x, y, z)
| True
| >>> x.has(x)
| True
|
| Note ``has`` is a structural algorithm with no knowledge of
| mathematics. Consider the following half-open interval:
|
| >>> from sympy.sets import Interval
| >>> i = Interval.Lopen(0, 5); i
| Interval.Lopen(0, 5)
| >>> i.args
| (0, 5, True, False)
| >>> i.has(4) # there is no "4" in the arguments
| False
| >>> i.has(0) # there *is* a "0" in the arguments
| True
|
| Instead, use ``contains`` to determine whether a number is in the
| interval or not:
|
| >>> i.contains(4)
| True
| >>> i.contains(0)
| False
|
|
| Note that ``expr.has(*patterns)`` is exactly equivalent to
| ``any(expr.has(p) for p in patterns)``. In particular, ``False`` is
| returned when the list of patterns is empty.
|
| >>> x.has()
| False
|
| is_hypergeometric(self, k)
|
| match(self, pattern, old=False)
| Pattern matching.
|
| Wild symbols match all.
|
| Return ``None`` when expression (self) does not match
| with pattern. Otherwise return a dictionary such that::
|
| pattern.xreplace(self.match(pattern)) == self
|
| Examples
| ========
|
| >>> from sympy import Wild, Sum
| >>> from sympy.abc import x, y
| >>> p = Wild("p")
| >>> q = Wild("q")
| >>> r = Wild("r")
| >>> e = (x+y)**(x+y)
| >>> e.match(p**p)
| {p_: x + y}
| >>> e.match(p**q)
| {p_: x + y, q_: x + y}
| >>> e = (2*x)**2
| >>> e.match(p*q**r)
| {p_: 4, q_: x, r_: 2}
| >>> (p*q**r).xreplace(e.match(p*q**r))
| 4*x**2
|
| Structurally bound symbols are ignored during matching:
|
| >>> Sum(x, (x, 1, 2)).match(Sum(y, (y, 1, p)))
| {p_: 2}
|
| But they can be identified if desired:
|
| >>> Sum(x, (x, 1, 2)).match(Sum(q, (q, 1, p)))
| {p_: 2, q_: x}
|
| The ``old`` flag will give the old-style pattern matching where
| expressions and patterns are essentially solved to give the
| match. Both of the following give None unless ``old=True``:
|
| >>> (x - 2).match(p - x, old=True)
| {p_: 2*x - 2}
| >>> (2/x).match(p*x, old=True)
| {p_: 2/x**2}
|
| matches(self, expr, repl_dict={}, old=False)
| Helper method for match() that looks for a match between Wild symbols
| in self and expressions in expr.
|
| Examples
| ========
|
| >>> from sympy import symbols, Wild, Basic
| >>> a, b, c = symbols('a b c')
| >>> x = Wild('x')
| >>> Basic(a + x, x).matches(Basic(a + b, c)) is None
| True
| >>> Basic(a + x, x).matches(Basic(a + b + c, b + c))
| {x_: b + c}
|
| rcall(self, *args)
| Apply on the argument recursively through the expression tree.
|
| This method is used to simulate a common abuse of notation for
| operators. For instance in SymPy the the following will not work:
|
| ``(x+Lambda(y, 2*y))(z) == x+2*z``,
|
| however you can use
|
| >>> from sympy import Lambda
| >>> from sympy.abc import x, y, z
| >>> (x + Lambda(y, 2*y)).rcall(z)
| x + 2*z
|
| refine(self, assumption=True)
| See the refine function in sympy.assumptions
|
| replace(self, query, value, map=False, simultaneous=True, exact=None)
| Replace matching subexpressions of ``self`` with ``value``.
|
| If ``map = True`` then also return the mapping {old: new} where ``old``
| was a sub-expression found with query and ``new`` is the replacement
| value for it. If the expression itself doesn't match the query, then
| the returned value will be ``self.xreplace(map)`` otherwise it should
| be ``self.subs(ordered(map.items()))``.
|
| Traverses an expression tree and performs replacement of matching
| subexpressions from the bottom to the top of the tree. The default
| approach is to do the replacement in a simultaneous fashion so
| changes made are targeted only once. If this is not desired or causes
| problems, ``simultaneous`` can be set to False.
|
| In addition, if an expression containing more than one Wild symbol
| is being used to match subexpressions and the ``exact`` flag is None
| it will be set to True so the match will only succeed if all non-zero
| values are received for each Wild that appears in the match pattern.
| Setting this to False accepts a match of 0; while setting it True
| accepts all matches that have a 0 in them. See example below for
| cautions.
|
| The list of possible combinations of queries and replacement values
| is listed below:
|
| Examples
| ========
|
| Initial setup
|
| >>> from sympy import log, sin, cos, tan, Wild, Mul, Add
| >>> from sympy.abc import x, y
| >>> f = log(sin(x)) + tan(sin(x**2))
|
| 1.1. type -> type
| obj.replace(type, newtype)
|
| When object of type ``type`` is found, replace it with the
| result of passing its argument(s) to ``newtype``.
|
| >>> f.replace(sin, cos)
| log(cos(x)) + tan(cos(x**2))
| >>> sin(x).replace(sin, cos, map=True)
| (cos(x), {sin(x): cos(x)})
| >>> (x*y).replace(Mul, Add)
| x + y
|
| 1.2. type -> func
| obj.replace(type, func)
|
| When object of type ``type`` is found, apply ``func`` to its
| argument(s). ``func`` must be written to handle the number
| of arguments of ``type``.
|
| >>> f.replace(sin, lambda arg: sin(2*arg))
| log(sin(2*x)) + tan(sin(2*x**2))
| >>> (x*y).replace(Mul, lambda *args: sin(2*Mul(*args)))
| sin(2*x*y)
|
| 2.1. pattern -> expr
| obj.replace(pattern(wild), expr(wild))
|
| Replace subexpressions matching ``pattern`` with the expression
| written in terms of the Wild symbols in ``pattern``.
|
| >>> a, b = map(Wild, 'ab')
| >>> f.replace(sin(a), tan(a))
| log(tan(x)) + tan(tan(x**2))
| >>> f.replace(sin(a), tan(a/2))
| log(tan(x/2)) + tan(tan(x**2/2))
| >>> f.replace(sin(a), a)
| log(x) + tan(x**2)
| >>> (x*y).replace(a*x, a)
| y
|
| Matching is exact by default when more than one Wild symbol
| is used: matching fails unless the match gives non-zero
| values for all Wild symbols:
|
| >>> (2*x + y).replace(a*x + b, b - a)
| y - 2
| >>> (2*x).replace(a*x + b, b - a)
| 2*x
|
| When set to False, the results may be non-intuitive:
|
| >>> (2*x).replace(a*x + b, b - a, exact=False)
| 2/x
|
| 2.2. pattern -> func
| obj.replace(pattern(wild), lambda wild: expr(wild))
|
| All behavior is the same as in 2.1 but now a function in terms of
| pattern variables is used rather than an expression:
|
| >>> f.replace(sin(a), lambda a: sin(2*a))
| log(sin(2*x)) + tan(sin(2*x**2))
|
| 3.1. func -> func
| obj.replace(filter, func)
|
| Replace subexpression ``e`` with ``func(e)`` if ``filter(e)``
| is True.
|
| >>> g = 2*sin(x**3)
| >>> g.replace(lambda expr: expr.is_Number, lambda expr: expr**2)
| 4*sin(x**9)
|
| The expression itself is also targeted by the query but is done in
| such a fashion that changes are not made twice.
|
| >>> e = x*(x*y + 1)
| >>> e.replace(lambda x: x.is_Mul, lambda x: 2*x)
| 2*x*(2*x*y + 1)
|
| When matching a single symbol, `exact` will default to True, but
| this may or may not be the behavior that is desired:
|
| Here, we want `exact=False`:
|
| >>> from sympy import Function
| >>> f = Function('f')
| >>> e = f(1) + f(0)
| >>> q = f(a), lambda a: f(a + 1)
| >>> e.replace(*q, exact=False)
| f(1) + f(2)
| >>> e.replace(*q, exact=True)
| f(0) + f(2)
|
| But here, the nature of matching makes selecting
| the right setting tricky:
|
| >>> e = x**(1 + y)
| >>> (x**(1 + y)).replace(x**(1 + a), lambda a: x**-a, exact=False)
| x
| >>> (x**(1 + y)).replace(x**(1 + a), lambda a: x**-a, exact=True)
| x**(-x - y + 1)
| >>> (x**y).replace(x**(1 + a), lambda a: x**-a, exact=False)
| x
| >>> (x**y).replace(x**(1 + a), lambda a: x**-a, exact=True)
| x**(1 - y)
|
| It is probably better to use a different form of the query
| that describes the target expression more precisely:
|
| >>> (1 + x**(1 + y)).replace(
| ... lambda x: x.is_Pow and x.exp.is_Add and x.exp.args[0] == 1,
| ... lambda x: x.base**(1 - (x.exp - 1)))
| ...
| x**(1 - y) + 1
|
| See Also
| ========
|
| subs: substitution of subexpressions as defined by the objects
| themselves.
| xreplace: exact node replacement in expr tree; also capable of
| using matching rules
|
| rewrite(self, *args, **hints)
| Rewrite functions in terms of other functions.
|
| Rewrites expression containing applications of functions
| of one kind in terms of functions of different kind. For
| example you can rewrite trigonometric functions as complex
| exponentials or combinatorial functions as gamma function.
|
| As a pattern this function accepts a list of functions to
| to rewrite (instances of DefinedFunction class). As rule
| you can use string or a destination function instance (in
| this case rewrite() will use the str() function).
|
| There is also the possibility to pass hints on how to rewrite
| the given expressions. For now there is only one such hint
| defined called 'deep'. When 'deep' is set to False it will
| forbid functions to rewrite their contents.
|
| Examples
| ========
|
| >>> from sympy import sin, exp
| >>> from sympy.abc import x
|
| Unspecified pattern:
|
| >>> sin(x).rewrite(exp)
| -I*(exp(I*x) - exp(-I*x))/2
|
| Pattern as a single function:
|
| >>> sin(x).rewrite(sin, exp)
| -I*(exp(I*x) - exp(-I*x))/2
|
| Pattern as a list of functions:
|
| >>> sin(x).rewrite([sin, ], exp)
| -I*(exp(I*x) - exp(-I*x))/2
|
| simplify(self, **kwargs)
| See the simplify function in sympy.simplify
|
| subs(self, *args, **kwargs)
| Substitutes old for new in an expression after sympifying args.
|
| `args` is either:
| - two arguments, e.g. foo.subs(old, new)
| - one iterable argument, e.g. foo.subs(iterable). The iterable may be
| o an iterable container with (old, new) pairs. In this case the
| replacements are processed in the order given with successive
| patterns possibly affecting replacements already made.
| o a dict or set whose key/value items correspond to old/new pairs.
| In this case the old/new pairs will be sorted by op count and in
| case of a tie, by number of args and the default_sort_key. The
| resulting sorted list is then processed as an iterable container
| (see previous).
|
| If the keyword ``simultaneous`` is True, the subexpressions will not be
| evaluated until all the substitutions have been made.
|
| Examples
| ========
|
| >>> from sympy import pi, exp, limit, oo
| >>> from sympy.abc import x, y
| >>> (1 + x*y).subs(x, pi)
| pi*y + 1
| >>> (1 + x*y).subs({x:pi, y:2})
| 1 + 2*pi
| >>> (1 + x*y).subs([(x, pi), (y, 2)])
| 1 + 2*pi
| >>> reps = [(y, x**2), (x, 2)]
| >>> (x + y).subs(reps)
| 6
| >>> (x + y).subs(reversed(reps))
| x**2 + 2
|
| >>> (x**2 + x**4).subs(x**2, y)
| y**2 + y
|
| To replace only the x**2 but not the x**4, use xreplace:
|
| >>> (x**2 + x**4).xreplace({x**2: y})
| x**4 + y
|
| To delay evaluation until all substitutions have been made,
| set the keyword ``simultaneous`` to True:
|
| >>> (x/y).subs([(x, 0), (y, 0)])
| 0
| >>> (x/y).subs([(x, 0), (y, 0)], simultaneous=True)
| nan
|
| This has the added feature of not allowing subsequent substitutions
| to affect those already made:
|
| >>> ((x + y)/y).subs({x + y: y, y: x + y})
| 1
| >>> ((x + y)/y).subs({x + y: y, y: x + y}, simultaneous=True)
| y/(x + y)
|
| In order to obtain a canonical result, unordered iterables are
| sorted by count_op length, number of arguments and by the
| default_sort_key to break any ties. All other iterables are left
| unsorted.
|
| >>> from sympy import sqrt, sin, cos
| >>> from sympy.abc import a, b, c, d, e
|
| >>> A = (sqrt(sin(2*x)), a)
| >>> B = (sin(2*x), b)
| >>> C = (cos(2*x), c)
| >>> D = (x, d)
| >>> E = (exp(x), e)
|
| >>> expr = sqrt(sin(2*x))*sin(exp(x)*x)*cos(2*x) + sin(2*x)
|
| >>> expr.subs(dict([A, B, C, D, E]))
| a*c*sin(d*e) + b
|
| The resulting expression represents a literal replacement of the
| old arguments with the new arguments. This may not reflect the
| limiting behavior of the expression:
|
| >>> (x**3 - 3*x).subs({x: oo})
| nan
|
| >>> limit(x**3 - 3*x, x, oo)
| oo
|
| If the substitution will be followed by numerical
| evaluation, it is better to pass the substitution to
| evalf as
|
| >>> (1/x).evalf(subs={x: 3.0}, n=21)
| 0.333333333333333333333
|
| rather than
|
| >>> (1/x).subs({x: 3.0}).evalf(21)
| 0.333333333333333314830
|
| as the former will ensure that the desired level of precision is
| obtained.
|
| See Also
| ========
| replace: replacement capable of doing wildcard-like matching,
| parsing of match, and conditional replacements
| xreplace: exact node replacement in expr tree; also capable of
| using matching rules
| sympy.core.evalf.EvalfMixin.evalf: calculates the given formula to a desired level of precision
|
| xreplace lambda rule, **_
| # Function needs args so we define a property that returns
| # a function that takes args...and then use that function
| # to return the right value
|
| ----------------------------------------------------------------------
| Class methods inherited from sympy.core.basic.Basic:
|
| fromiter(args, **assumptions) from sympy.core.function.FunctionClass
| Create a new object from an iterable.
|
| This is a convenience function that allows one to create objects from
| any iterable, without having to convert to a list or tuple first.
|
| Examples
| ========
|
| >>> from sympy import Tuple
| >>> Tuple.fromiter(i for i in range(5))
| (0, 1, 2, 3, 4)
|
| ----------------------------------------------------------------------
| Readonly properties inherited from sympy.core.basic.Basic:
|
| args
| Returns a tuple of arguments of 'self'.
|
| Examples
| ========
|
| >>> from sympy import cot
| >>> from sympy.abc import x, y
|
| >>> cot(x).args
| (x,)
|
| >>> cot(x).args[0]
| x
|
| >>> (x*y).args
| (x, y)
|
| >>> (x*y).args[1]
| y
|
| Notes
| =====
|
| Never use self._args, always use self.args.
| Only use _args in __new__ when creating a new function.
| Don't override .args() from Basic (so that it's easy to
| change the interface in the future if needed).
|
| assumptions0
| Return object `type` assumptions.
|
| For example:
|
| Symbol('x', real=True)
| Symbol('x', integer=True)
|
| are different objects. In other words, besides Python type (Symbol in
| this case), the initial assumptions are also forming their typeinfo.
|
| Examples
| ========
|
| >>> from sympy import Symbol
| >>> from sympy.abc import x
| >>> x.assumptions0
| {'commutative': True}
| >>> x = Symbol("x", positive=True)
| >>> x.assumptions0
| {'commutative': True, 'complex': True, 'extended_negative': False,
| 'extended_nonnegative': True, 'extended_nonpositive': False,
| 'extended_nonzero': True, 'extended_positive': True, 'extended_real':
| True, 'finite': True, 'hermitian': True, 'imaginary': False,
| 'infinite': False, 'negative': False, 'nonnegative': True,
| 'nonpositive': False, 'nonzero': True, 'positive': True, 'real':
| True, 'zero': False}
|
| canonical_variables
| Return a dictionary mapping any variable defined in
| ``self.bound_symbols`` to Symbols that do not clash
| with any free symbols in the expression.
|
| Examples
| ========
|
| >>> from sympy import Lambda
| >>> from sympy.abc import x
| >>> Lambda(x, 2*x).canonical_variables
| {x: _0}
|
| free_symbols
| Return from the atoms of self those which are free symbols.
|
| For most expressions, all symbols are free symbols. For some classes
| this is not true. e.g. Integrals use Symbols for the dummy variables
| which are bound variables, so Integral has a method to return all
| symbols except those. Derivative keeps track of symbols with respect
| to which it will perform a derivative; those are
| bound variables, too, so it has its own free_symbols method.
|
| Any other method that uses bound variables should implement a
| free_symbols method.
|
| is_algebraic
|
| is_antihermitian
|
| is_commutative
|
| is_comparable
| Return True if self can be computed to a real number
| (or already is a real number) with precision, else False.
|
| Examples
| ========
|
| >>> from sympy import exp_polar, pi, I
| >>> (I*exp_polar(I*pi/2)).is_comparable
| True
| >>> (I*exp_polar(I*pi*2)).is_comparable
| False
|
| A False result does not mean that `self` cannot be rewritten
| into a form that would be comparable. For example, the
| difference computed below is zero but without simplification
| it does not evaluate to a zero with precision:
|
| >>> e = 2**pi*(1 + 2**pi)
| >>> dif = e - e.expand()
| >>> dif.is_comparable
| False
| >>> dif.n(2)._prec
| 1
|
| is_complex
|
| is_composite
|
| is_even
|
| is_extended_negative
|
| is_extended_nonnegative
|
| is_extended_nonpositive
|
| is_extended_nonzero
|
| is_extended_positive
|
| is_extended_real
|
| is_finite
|
| is_hermitian
|
| is_imaginary
|
| is_infinite
|
| is_integer
|
| is_irrational
|
| is_negative
|
| is_noninteger
|
| is_nonnegative
|
| is_nonpositive
|
| is_nonzero
|
| is_odd
|
| is_polar
|
| is_positive
|
| is_prime
|
| is_rational
|
| is_real
|
| is_transcendental
|
| is_zero
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from sympy.core.basic.Basic:
|
| is_Add = False
|
| is_AlgebraicNumber = False
|
| is_Atom = False
|
| is_Boolean = False
|
| is_Derivative = False
|
| is_Dummy = False
|
| is_Equality = False
|
| is_Float = False
|
| is_Indexed = False
|
| is_Integer = False
|
| is_MatAdd = False
|
| is_MatMul = False
|
| is_Matrix = False
|
| is_Mul = False
|
| is_Not = False
|
| is_Number = False
|
| is_NumberSymbol = False
|
| is_Order = False
|
| is_Piecewise = False
|
| is_Point = False
|
| is_Poly = False
|
| is_Pow = False
|
| is_Rational = False
|
| is_Relational = False
|
| is_Symbol = False
|
| is_Vector = False
|
| is_Wild = False
|
| is_symbol = False
|
| kind = UndefinedKind
|
| ----------------------------------------------------------------------
| Methods inherited from sympy.printing.defaults.Printable:
|
| __repr__ = __str__(self)
|
| __str__(self)
| Return str(self).
|
| ----------------------------------------------------------------------
| Methods inherited from sympy.core.evalf.EvalfMixin:
|
| evalf(self, n=15, subs=None, maxn=100, chop=False, strict=False, quad=None, verbose=False)
| Evaluate the given formula to an accuracy of *n* digits.
|
| Parameters
| ==========
|
| subs : dict, optional
| Substitute numerical values for symbols, e.g.
| ``subs={x:3, y:1+pi}``. The substitutions must be given as a
| dictionary.
|
| maxn : int, optional
| Allow a maximum temporary working precision of maxn digits.
|
| chop : bool or number, optional
| Specifies how to replace tiny real or imaginary parts in
| subresults by exact zeros.
|
| When ``True`` the chop value defaults to standard precision.
|
| Otherwise the chop value is used to determine the
| magnitude of "small" for purposes of chopping.
|
| >>> from sympy import N
| >>> x = 1e-4
| >>> N(x, chop=True)
| 0.000100000000000000
| >>> N(x, chop=1e-5)
| 0.000100000000000000
| >>> N(x, chop=1e-4)
| 0
|
| strict : bool, optional
| Raise ``PrecisionExhausted`` if any subresult fails to
| evaluate to full accuracy, given the available maxprec.
|
| quad : str, optional
| Choose algorithm for numerical quadrature. By default,
| tanh-sinh quadrature is used. For oscillatory
| integrals on an infinite interval, try ``quad='osc'``.
|
| verbose : bool, optional
| Print debug information.
|
| Notes
| =====
|
| When Floats are naively substituted into an expression,
| precision errors may adversely affect the result. For example,
| adding 1e16 (a Float) to 1 will truncate to 1e16; if 1e16 is
| then subtracted, the result will be 0.
| That is exactly what happens in the following:
|
| >>> from sympy.abc import x, y, z
| >>> values = {x: 1e16, y: 1, z: 1e16}
| >>> (x + y - z).subs(values)
| 0
|
| Using the subs argument for evalf is the accurate way to
| evaluate such an expression:
|
| >>> (x + y - z).evalf(subs=values)
| 1.00000000000000
|
| n = evalf(self, n=15, subs=None, maxn=100, chop=False, strict=False, quad=None, verbose=False)
import sympy as smp
x = smp.symbols('x')
smp.hermite(0, x)
smp.hermite(1, x)
smp.hermite(2, x)
smp.hermite(3, x)
n = smp.symbols('n')
smp.hermite(n, x)
H_n = smp.hermite(n, x)
H_n
H_n.subs(n, 1)
smp.diff(smp.hermite(n, x), x)
smp.hermite(n - 1, x)
H_n_1 = smp.hermite(n - 1, x)
2*n*H_n_1
Hp = 2*n*H_n_1
Hp
Hp.subs(n, 2)
H_n_diff = smp.diff(smp.hermite(n, x), x)
H_n_diff
H_n_diff.subs(n, 2)
beta, hbar, omega, xi, eta = smp.symbols('beta hbar omega xi eta')
smp.Sum(smp.exp(-(n+smp.Rational(1,2))*beta*hbar*omega), (n, 0, 10))
smp.Sum(smp.exp(-(n+smp.Rational(1,2))*beta*hbar*omega), (n, 0, 10)).doit()
smp.Sum(smp.exp(-(n+smp.Rational(1,2))*beta*hbar*omega), (n, 0, 100)).doit()
smp.exp(-(n+smp.Rational(1,2))*beta*hbar*omega)*hermite(n, xi)*hermite(n, eta)/(2 ** n * smp.factorial(n))
smp.Sum(smp.exp(-(n+smp.Rational(1,2))*beta*hbar*omega)*hermite(n, xi)*hermite(n, eta)/(2 ** n * smp.factorial(n)), (n, 0, 10))
smp.Sum(smp.exp(-(n+smp.Rational(1,2))*beta*hbar*omega)*hermite(n, xi)*hermite(n, eta)/(2 ** n * smp.factorial(n)), (n, 0, 10)).doit()
help(smp.laguerre)
Help on class laguerre in module sympy.functions.special.polynomials:
class laguerre(OrthogonalPolynomial)
| laguerre(n, x)
|
| Returns the nth Laguerre polynomial in x, $L_n(x)$.
|
| Examples
| ========
|
| >>> from sympy import laguerre, diff
| >>> from sympy.abc import x, n
| >>> laguerre(0, x)
| 1
| >>> laguerre(1, x)
| 1 - x
| >>> laguerre(2, x)
| x**2/2 - 2*x + 1
| >>> laguerre(3, x)
| -x**3/6 + 3*x**2/2 - 3*x + 1
|
| >>> laguerre(n, x)
| laguerre(n, x)
|
| >>> diff(laguerre(n, x), x)
| -assoc_laguerre(n - 1, 1, x)
|
| Parameters
| ==========
|
| n : int
| Degree of Laguerre polynomial. Must be ``n >= 0``.
|
| See Also
| ========
|
| jacobi, gegenbauer,
| chebyshevt, chebyshevt_root, chebyshevu, chebyshevu_root,
| legendre, assoc_legendre,
| hermite,
| assoc_laguerre,
| sympy.polys.orthopolys.jacobi_poly
| sympy.polys.orthopolys.gegenbauer_poly
| sympy.polys.orthopolys.chebyshevt_poly
| sympy.polys.orthopolys.chebyshevu_poly
| sympy.polys.orthopolys.hermite_poly
| sympy.polys.orthopolys.legendre_poly
| sympy.polys.orthopolys.laguerre_poly
|
| References
| ==========
|
| .. [1] https://en.wikipedia.org/wiki/Laguerre_polynomial
| .. [2] http://mathworld.wolfram.com/LaguerrePolynomial.html
| .. [3] http://functions.wolfram.com/Polynomials/LaguerreL/
| .. [4] http://functions.wolfram.com/Polynomials/LaguerreL3/
|
| Method resolution order:
| laguerre
| OrthogonalPolynomial
| sympy.core.function.Function
| sympy.core.function.Application
| sympy.core.expr.Expr
| sympy.core.basic.Basic
| sympy.printing.defaults.Printable
| sympy.core.evalf.EvalfMixin
| builtins.object
|
| Methods defined here:
|
| fdiff(self, argindex=2)
| Returns the first derivative of the function.
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| eval(n, x) from sympy.core.function.FunctionClass
| Returns a canonical form of cls applied to arguments args.
|
| Explanation
| ===========
|
| The eval() method is called when the class cls is about to be
| instantiated and it should return either some simplified instance
| (possible of some other class), or if the class cls should be
| unmodified, return None.
|
| Examples of eval() for the function "sign"
| ---------------------------------------------
|
| .. code-block:: python
|
| @classmethod
| def eval(cls, arg):
| if arg is S.NaN:
| return S.NaN
| if arg.is_zero: return S.Zero
| if arg.is_positive: return S.One
| if arg.is_negative: return S.NegativeOne
| if isinstance(arg, Mul):
| coeff, terms = arg.as_coeff_Mul(rational=True)
| if coeff is not S.One:
| return cls(coeff) * cls(terms)
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| __sympy__
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| default_assumptions = {}
|
| ----------------------------------------------------------------------
| Methods inherited from sympy.core.function.Function:
|
| as_base_exp(self)
| Returns the method as the 2-tuple (base, exponent).
|
| ----------------------------------------------------------------------
| Class methods inherited from sympy.core.function.Function:
|
| class_key() from sympy.core.function.FunctionClass
| Nice order of classes.
|
| is_singular(a) from sympy.core.function.FunctionClass
| Tests whether the argument is an essential singularity
| or a branch point, or the functions is non-holomorphic.
|
| ----------------------------------------------------------------------
| Static methods inherited from sympy.core.function.Function:
|
| __new__(cls, *args, **options)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from sympy.core.function.Application:
|
| func
| The top-level function in an expression.
|
| The following should hold for all objects::
|
| >> x == x.func(*x.args)
|
| Examples
| ========
|
| >>> from sympy.abc import x
| >>> a = 2*x
| >>> a.func
| <class 'sympy.core.mul.Mul'>
| >>> a.args
| (2, x)
| >>> a.func(*a.args)
| 2*x
| >>> a == a.func(*a.args)
| True
|
| ----------------------------------------------------------------------
| Data descriptors inherited from sympy.core.function.Application:
|
| __dict__
| dictionary for instance variables (if defined)
|
| __weakref__
| list of weak references to the object (if defined)
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from sympy.core.function.Application:
|
| is_Function = True
|
| ----------------------------------------------------------------------
| Methods inherited from sympy.core.expr.Expr:
|
| __abs__(self)
|
| __add__(self, other)
|
| __complex__(self)
|
| __divmod__(self, other)
|
| __eq__(self, other)
| Return a boolean indicating whether a == b on the basis of
| their symbolic trees.
|
| This is the same as a.compare(b) == 0 but faster.
|
| Notes
| =====
|
| If a class that overrides __eq__() needs to retain the
| implementation of __hash__() from a parent class, the
| interpreter must be told this explicitly by setting __hash__ =
| <ParentClass>.__hash__. Otherwise the inheritance of __hash__()
| will be blocked, just as if __hash__ had been explicitly set to
| None.
|
| References
| ==========
|
| from http://docs.python.org/dev/reference/datamodel.html#object.__hash__
|
| __float__(self)
|
| __floordiv__(self, other)
|
| __ge__(self, other)
| Return self>=value.
|
| __gt__(self, other)
| Return self>value.
|
| __hash__(self) -> int
| Return hash(self).
|
| __int__(self)
|
| __le__(self, other)
| Return self<=value.
|
| __lt__(self, other)
| Return self<value.
|
| __mod__(self, other)
|
| __mul__(self, other)
|
| __neg__(self)
|
| __pos__(self)
|
| __pow__(self, other, mod=None)
|
| __radd__(self, other)
|
| __rdivmod__(self, other)
|
| __rfloordiv__(self, other)
|
| __rmod__(self, other)
|
| __rmul__(self, other)
|
| __round__ = round(self, n=None)
|
| __rpow__(self, other)
|
| __rsub__(self, other)
|
| __rtruediv__(self, other)
|
| __sub__(self, other)
|
| __truediv__(self, other)
|
| __trunc__(self)
|
| adjoint(self)
|
| apart(self, x=None, **args)
| See the apart function in sympy.polys
|
| args_cnc(self, cset=False, warn=True, split_1=True)
| Return [commutative factors, non-commutative factors] of self.
|
| Explanation
| ===========
|
| self is treated as a Mul and the ordering of the factors is maintained.
| If ``cset`` is True the commutative factors will be returned in a set.
| If there were repeated factors (as may happen with an unevaluated Mul)
| then an error will be raised unless it is explicitly suppressed by
| setting ``warn`` to False.
|
| Note: -1 is always separated from a Number unless split_1 is False.
|
| Examples
| ========
|
| >>> from sympy import symbols, oo
| >>> A, B = symbols('A B', commutative=0)
| >>> x, y = symbols('x y')
| >>> (-2*x*y).args_cnc()
| [[-1, 2, x, y], []]
| >>> (-2.5*x).args_cnc()
| [[-1, 2.5, x], []]
| >>> (-2*x*A*B*y).args_cnc()
| [[-1, 2, x, y], [A, B]]
| >>> (-2*x*A*B*y).args_cnc(split_1=False)
| [[-2, x, y], [A, B]]
| >>> (-2*x*y).args_cnc(cset=True)
| [{-1, 2, x, y}, []]
|
| The arg is always treated as a Mul:
|
| >>> (-2 + x + A).args_cnc()
| [[], [x - 2 + A]]
| >>> (-oo).args_cnc() # -oo is a singleton
| [[-1, oo], []]
|
| as_coeff_Add(self, rational=False)
| Efficiently extract the coefficient of a summation.
|
| as_coeff_Mul(self, rational=False)
| Efficiently extract the coefficient of a product.
|
| as_coeff_add(self, *deps)
| Return the tuple (c, args) where self is written as an Add, ``a``.
|
| c should be a Rational added to any terms of the Add that are
| independent of deps.
|
| args should be a tuple of all other terms of ``a``; args is empty
| if self is a Number or if self is independent of deps (when given).
|
| This should be used when you don't know if self is an Add or not but
| you want to treat self as an Add or if you want to process the
| individual arguments of the tail of self as an Add.
|
| - if you know self is an Add and want only the head, use self.args[0];
| - if you don't want to process the arguments of the tail but need the
| tail then use self.as_two_terms() which gives the head and tail.
| - if you want to split self into an independent and dependent parts
| use ``self.as_independent(*deps)``
|
| >>> from sympy import S
| >>> from sympy.abc import x, y
| >>> (S(3)).as_coeff_add()
| (3, ())
| >>> (3 + x).as_coeff_add()
| (3, (x,))
| >>> (3 + x + y).as_coeff_add(x)
| (y + 3, (x,))
| >>> (3 + y).as_coeff_add(x)
| (y + 3, ())
|
| as_coeff_exponent(self, x)
| ``c*x**e -> c,e`` where x can be any symbolic expression.
|
| as_coeff_mul(self, *deps, **kwargs)
| Return the tuple (c, args) where self is written as a Mul, ``m``.
|
| c should be a Rational multiplied by any factors of the Mul that are
| independent of deps.
|
| args should be a tuple of all other factors of m; args is empty
| if self is a Number or if self is independent of deps (when given).
|
| This should be used when you don't know if self is a Mul or not but
| you want to treat self as a Mul or if you want to process the
| individual arguments of the tail of self as a Mul.
|
| - if you know self is a Mul and want only the head, use self.args[0];
| - if you don't want to process the arguments of the tail but need the
| tail then use self.as_two_terms() which gives the head and tail;
| - if you want to split self into an independent and dependent parts
| use ``self.as_independent(*deps)``
|
| >>> from sympy import S
| >>> from sympy.abc import x, y
| >>> (S(3)).as_coeff_mul()
| (3, ())
| >>> (3*x*y).as_coeff_mul()
| (3, (x, y))
| >>> (3*x*y).as_coeff_mul(x)
| (3*y, (x,))
| >>> (3*y).as_coeff_mul(x)
| (3*y, ())
|
| as_coefficient(self, expr)
| Extracts symbolic coefficient at the given expression. In
| other words, this functions separates 'self' into the product
| of 'expr' and 'expr'-free coefficient. If such separation
| is not possible it will return None.
|
| Examples
| ========
|
| >>> from sympy import E, pi, sin, I, Poly
| >>> from sympy.abc import x
|
| >>> E.as_coefficient(E)
| 1
| >>> (2*E).as_coefficient(E)
| 2
| >>> (2*sin(E)*E).as_coefficient(E)
|
| Two terms have E in them so a sum is returned. (If one were
| desiring the coefficient of the term exactly matching E then
| the constant from the returned expression could be selected.
| Or, for greater precision, a method of Poly can be used to
| indicate the desired term from which the coefficient is
| desired.)
|
| >>> (2*E + x*E).as_coefficient(E)
| x + 2
| >>> _.args[0] # just want the exact match
| 2
| >>> p = Poly(2*E + x*E); p
| Poly(x*E + 2*E, x, E, domain='ZZ')
| >>> p.coeff_monomial(E)
| 2
| >>> p.nth(0, 1)
| 2
|
| Since the following cannot be written as a product containing
| E as a factor, None is returned. (If the coefficient ``2*x`` is
| desired then the ``coeff`` method should be used.)
|
| >>> (2*E*x + x).as_coefficient(E)
| >>> (2*E*x + x).coeff(E)
| 2*x
|
| >>> (E*(x + 1) + x).as_coefficient(E)
|
| >>> (2*pi*I).as_coefficient(pi*I)
| 2
| >>> (2*I).as_coefficient(pi*I)
|
| See Also
| ========
|
| coeff: return sum of terms have a given factor
| as_coeff_Add: separate the additive constant from an expression
| as_coeff_Mul: separate the multiplicative constant from an expression
| as_independent: separate x-dependent terms/factors from others
| sympy.polys.polytools.Poly.coeff_monomial: efficiently find the single coefficient of a monomial in Poly
| sympy.polys.polytools.Poly.nth: like coeff_monomial but powers of monomial terms are used
|
| as_coefficients_dict(self)
| Return a dictionary mapping terms to their Rational coefficient.
| Since the dictionary is a defaultdict, inquiries about terms which
| were not present will return a coefficient of 0. If an expression is
| not an Add it is considered to have a single term.
|
| Examples
| ========
|
| >>> from sympy.abc import a, x
| >>> (3*x + a*x + 4).as_coefficients_dict()
| {1: 4, x: 3, a*x: 1}
| >>> _[a]
| 0
| >>> (3*a*x).as_coefficients_dict()
| {a*x: 3}
|
| as_content_primitive(self, radical=False, clear=True)
| This method should recursively remove a Rational from all arguments
| and return that (content) and the new self (primitive). The content
| should always be positive and ``Mul(*foo.as_content_primitive()) == foo``.
| The primitive need not be in canonical form and should try to preserve
| the underlying structure if possible (i.e. expand_mul should not be
| applied to self).
|
| Examples
| ========
|
| >>> from sympy import sqrt
| >>> from sympy.abc import x, y, z
|
| >>> eq = 2 + 2*x + 2*y*(3 + 3*y)
|
| The as_content_primitive function is recursive and retains structure:
|
| >>> eq.as_content_primitive()
| (2, x + 3*y*(y + 1) + 1)
|
| Integer powers will have Rationals extracted from the base:
|
| >>> ((2 + 6*x)**2).as_content_primitive()
| (4, (3*x + 1)**2)
| >>> ((2 + 6*x)**(2*y)).as_content_primitive()
| (1, (2*(3*x + 1))**(2*y))
|
| Terms may end up joining once their as_content_primitives are added:
|
| >>> ((5*(x*(1 + y)) + 2*x*(3 + 3*y))).as_content_primitive()
| (11, x*(y + 1))
| >>> ((3*(x*(1 + y)) + 2*x*(3 + 3*y))).as_content_primitive()
| (9, x*(y + 1))
| >>> ((3*(z*(1 + y)) + 2.0*x*(3 + 3*y))).as_content_primitive()
| (1, 6.0*x*(y + 1) + 3*z*(y + 1))
| >>> ((5*(x*(1 + y)) + 2*x*(3 + 3*y))**2).as_content_primitive()
| (121, x**2*(y + 1)**2)
| >>> ((x*(1 + y) + 0.4*x*(3 + 3*y))**2).as_content_primitive()
| (1, 4.84*x**2*(y + 1)**2)
|
| Radical content can also be factored out of the primitive:
|
| >>> (2*sqrt(2) + 4*sqrt(10)).as_content_primitive(radical=True)
| (2, sqrt(2)*(1 + 2*sqrt(5)))
|
| If clear=False (default is True) then content will not be removed
| from an Add if it can be distributed to leave one or more
| terms with integer coefficients.
|
| >>> (x/2 + y).as_content_primitive()
| (1/2, x + 2*y)
| >>> (x/2 + y).as_content_primitive(clear=False)
| (1, x/2 + y)
|
| as_expr(self, *gens)
| Convert a polynomial to a SymPy expression.
|
| Examples
| ========
|
| >>> from sympy import sin
| >>> from sympy.abc import x, y
|
| >>> f = (x**2 + x*y).as_poly(x, y)
| >>> f.as_expr()
| x**2 + x*y
|
| >>> sin(x).as_expr()
| sin(x)
|
| as_independent(self, *deps, **hint)
| A mostly naive separation of a Mul or Add into arguments that are not
| are dependent on deps. To obtain as complete a separation of variables
| as possible, use a separation method first, e.g.:
|
| * separatevars() to change Mul, Add and Pow (including exp) into Mul
| * .expand(mul=True) to change Add or Mul into Add
| * .expand(log=True) to change log expr into an Add
|
| The only non-naive thing that is done here is to respect noncommutative
| ordering of variables and to always return (0, 0) for `self` of zero
| regardless of hints.
|
| For nonzero `self`, the returned tuple (i, d) has the
| following interpretation:
|
| * i will has no variable that appears in deps
| * d will either have terms that contain variables that are in deps, or
| be equal to 0 (when self is an Add) or 1 (when self is a Mul)
| * if self is an Add then self = i + d
| * if self is a Mul then self = i*d
| * otherwise (self, S.One) or (S.One, self) is returned.
|
| To force the expression to be treated as an Add, use the hint as_Add=True
|
| Examples
| ========
|
| -- self is an Add
|
| >>> from sympy import sin, cos, exp
| >>> from sympy.abc import x, y, z
|
| >>> (x + x*y).as_independent(x)
| (0, x*y + x)
| >>> (x + x*y).as_independent(y)
| (x, x*y)
| >>> (2*x*sin(x) + y + x + z).as_independent(x)
| (y + z, 2*x*sin(x) + x)
| >>> (2*x*sin(x) + y + x + z).as_independent(x, y)
| (z, 2*x*sin(x) + x + y)
|
| -- self is a Mul
|
| >>> (x*sin(x)*cos(y)).as_independent(x)
| (cos(y), x*sin(x))
|
| non-commutative terms cannot always be separated out when self is a Mul
|
| >>> from sympy import symbols
| >>> n1, n2, n3 = symbols('n1 n2 n3', commutative=False)
| >>> (n1 + n1*n2).as_independent(n2)
| (n1, n1*n2)
| >>> (n2*n1 + n1*n2).as_independent(n2)
| (0, n1*n2 + n2*n1)
| >>> (n1*n2*n3).as_independent(n1)
| (1, n1*n2*n3)
| >>> (n1*n2*n3).as_independent(n2)
| (n1, n2*n3)
| >>> ((x-n1)*(x-y)).as_independent(x)
| (1, (x - y)*(x - n1))
|
| -- self is anything else:
|
| >>> (sin(x)).as_independent(x)
| (1, sin(x))
| >>> (sin(x)).as_independent(y)
| (sin(x), 1)
| >>> exp(x+y).as_independent(x)
| (1, exp(x + y))
|
| -- force self to be treated as an Add:
|
| >>> (3*x).as_independent(x, as_Add=True)
| (0, 3*x)
|
| -- force self to be treated as a Mul:
|
| >>> (3+x).as_independent(x, as_Add=False)
| (1, x + 3)
| >>> (-3+x).as_independent(x, as_Add=False)
| (1, x - 3)
|
| Note how the below differs from the above in making the
| constant on the dep term positive.
|
| >>> (y*(-3+x)).as_independent(x)
| (y, x - 3)
|
| -- use .as_independent() for true independence testing instead
| of .has(). The former considers only symbols in the free
| symbols while the latter considers all symbols
|
| >>> from sympy import Integral
| >>> I = Integral(x, (x, 1, 2))
| >>> I.has(x)
| True
| >>> x in I.free_symbols
| False
| >>> I.as_independent(x) == (I, 1)
| True
| >>> (I + x).as_independent(x) == (I, x)
| True
|
| Note: when trying to get independent terms, a separation method
| might need to be used first. In this case, it is important to keep
| track of what you send to this routine so you know how to interpret
| the returned values
|
| >>> from sympy import separatevars, log
| >>> separatevars(exp(x+y)).as_independent(x)
| (exp(y), exp(x))
| >>> (x + x*y).as_independent(y)
| (x, x*y)
| >>> separatevars(x + x*y).as_independent(y)
| (x, y + 1)
| >>> (x*(1 + y)).as_independent(y)
| (x, y + 1)
| >>> (x*(1 + y)).expand(mul=True).as_independent(y)
| (x, x*y)
| >>> a, b=symbols('a b', positive=True)
| >>> (log(a*b).expand(log=True)).as_independent(b)
| (log(a), log(b))
|
| See Also
| ========
| .separatevars(), .expand(log=True), sympy.core.add.Add.as_two_terms(),
| sympy.core.mul.Mul.as_two_terms(), .as_coeff_add(), .as_coeff_mul()
|
| as_leading_term(self, *symbols, cdir=0)
| Returns the leading (nonzero) term of the series expansion of self.
|
| The _eval_as_leading_term routines are used to do this, and they must
| always return a non-zero value.
|
| Examples
| ========
|
| >>> from sympy.abc import x
| >>> (1 + x + x**2).as_leading_term(x)
| 1
| >>> (1/x**2 + x + x**2).as_leading_term(x)
| x**(-2)
|
| as_numer_denom(self)
| expression -> a/b -> a, b
|
| This is just a stub that should be defined by
| an object's class methods to get anything else.
|
| See Also
| ========
|
| normal: return ``a/b`` instead of ``(a, b)``
|
| as_ordered_factors(self, order=None)
| Return list of ordered factors (if Mul) else [self].
|
| as_ordered_terms(self, order=None, data=False)
| Transform an expression to an ordered list of terms.
|
| Examples
| ========
|
| >>> from sympy import sin, cos
| >>> from sympy.abc import x
|
| >>> (sin(x)**2*cos(x) + sin(x)**2 + 1).as_ordered_terms()
| [sin(x)**2*cos(x), sin(x)**2, 1]
|
| as_poly(self, *gens, **args)
| Converts ``self`` to a polynomial or returns ``None``.
|
| Explanation
| ===========
|
| >>> from sympy import sin
| >>> from sympy.abc import x, y
|
| >>> print((x**2 + x*y).as_poly())
| Poly(x**2 + x*y, x, y, domain='ZZ')
|
| >>> print((x**2 + x*y).as_poly(x, y))
| Poly(x**2 + x*y, x, y, domain='ZZ')
|
| >>> print((x**2 + sin(y)).as_poly(x, y))
| None
|
| as_powers_dict(self)
| Return self as a dictionary of factors with each factor being
| treated as a power. The keys are the bases of the factors and the
| values, the corresponding exponents. The resulting dictionary should
| be used with caution if the expression is a Mul and contains non-
| commutative factors since the order that they appeared will be lost in
| the dictionary.
|
| See Also
| ========
| as_ordered_factors: An alternative for noncommutative applications,
| returning an ordered list of factors.
| args_cnc: Similar to as_ordered_factors, but guarantees separation
| of commutative and noncommutative factors.
|
| as_real_imag(self, deep=True, **hints)
| Performs complex expansion on 'self' and returns a tuple
| containing collected both real and imaginary parts. This
| method can't be confused with re() and im() functions,
| which does not perform complex expansion at evaluation.
|
| However it is possible to expand both re() and im()
| functions and get exactly the same results as with
| a single call to this function.
|
| >>> from sympy import symbols, I
|
| >>> x, y = symbols('x,y', real=True)
|
| >>> (x + y*I).as_real_imag()
| (x, y)
|
| >>> from sympy.abc import z, w
|
| >>> (z + w*I).as_real_imag()
| (re(z) - im(w), re(w) + im(z))
|
| as_terms(self)
| Transform an expression to a list of terms.
|
| aseries(self, x=None, n=6, bound=0, hir=False)
| Asymptotic Series expansion of self.
| This is equivalent to ``self.series(x, oo, n)``.
|
| Parameters
| ==========
|
| self : Expression
| The expression whose series is to be expanded.
|
| x : Symbol
| It is the variable of the expression to be calculated.
|
| n : Value
| The number of terms upto which the series is to be expanded.
|
| hir : Boolean
| Set this parameter to be True to produce hierarchical series.
| It stops the recursion at an early level and may provide nicer
| and more useful results.
|
| bound : Value, Integer
| Use the ``bound`` parameter to give limit on rewriting
| coefficients in its normalised form.
|
| Examples
| ========
|
| >>> from sympy import sin, exp
| >>> from sympy.abc import x
|
| >>> e = sin(1/x + exp(-x)) - sin(1/x)
|
| >>> e.aseries(x)
| (1/(24*x**4) - 1/(2*x**2) + 1 + O(x**(-6), (x, oo)))*exp(-x)
|
| >>> e.aseries(x, n=3, hir=True)
| -exp(-2*x)*sin(1/x)/2 + exp(-x)*cos(1/x) + O(exp(-3*x), (x, oo))
|
| >>> e = exp(exp(x)/(1 - 1/x))
|
| >>> e.aseries(x)
| exp(exp(x)/(1 - 1/x))
|
| >>> e.aseries(x, bound=3)
| exp(exp(x)/x**2)*exp(exp(x)/x)*exp(-exp(x) + exp(x)/(1 - 1/x) - exp(x)/x - exp(x)/x**2)*exp(exp(x))
|
| Returns
| =======
|
| Expr
| Asymptotic series expansion of the expression.
|
| Notes
| =====
|
| This algorithm is directly induced from the limit computational algorithm provided by Gruntz.
| It majorly uses the mrv and rewrite sub-routines. The overall idea of this algorithm is first
| to look for the most rapidly varying subexpression w of a given expression f and then expands f
| in a series in w. Then same thing is recursively done on the leading coefficient
| till we get constant coefficients.
|
| If the most rapidly varying subexpression of a given expression f is f itself,
| the algorithm tries to find a normalised representation of the mrv set and rewrites f
| using this normalised representation.
|
| If the expansion contains an order term, it will be either ``O(x ** (-n))`` or ``O(w ** (-n))``
| where ``w`` belongs to the most rapidly varying expression of ``self``.
|
| References
| ==========
|
| .. [1] A New Algorithm for Computing Asymptotic Series - Dominik Gruntz
| .. [2] Gruntz thesis - p90
| .. [3] http://en.wikipedia.org/wiki/Asymptotic_expansion
|
| See Also
| ========
|
| Expr.aseries: See the docstring of this function for complete details of this wrapper.
|
| cancel(self, *gens, **args)
| See the cancel function in sympy.polys
|
| coeff(self, x, n=1, right=False)
| Returns the coefficient from the term(s) containing ``x**n``. If ``n``
| is zero then all terms independent of ``x`` will be returned.
|
| Explanation
| ===========
|
| When ``x`` is noncommutative, the coefficient to the left (default) or
| right of ``x`` can be returned. The keyword 'right' is ignored when
| ``x`` is commutative.
|
| Examples
| ========
|
| >>> from sympy import symbols
| >>> from sympy.abc import x, y, z
|
| You can select terms that have an explicit negative in front of them:
|
| >>> (-x + 2*y).coeff(-1)
| x
| >>> (x - 2*y).coeff(-1)
| 2*y
|
| You can select terms with no Rational coefficient:
|
| >>> (x + 2*y).coeff(1)
| x
| >>> (3 + 2*x + 4*x**2).coeff(1)
| 0
|
| You can select terms independent of x by making n=0; in this case
| expr.as_independent(x)[0] is returned (and 0 will be returned instead
| of None):
|
| >>> (3 + 2*x + 4*x**2).coeff(x, 0)
| 3
| >>> eq = ((x + 1)**3).expand() + 1
| >>> eq
| x**3 + 3*x**2 + 3*x + 2
| >>> [eq.coeff(x, i) for i in reversed(range(4))]
| [1, 3, 3, 2]
| >>> eq -= 2
| >>> [eq.coeff(x, i) for i in reversed(range(4))]
| [1, 3, 3, 0]
|
| You can select terms that have a numerical term in front of them:
|
| >>> (-x - 2*y).coeff(2)
| -y
| >>> from sympy import sqrt
| >>> (x + sqrt(2)*x).coeff(sqrt(2))
| x
|
| The matching is exact:
|
| >>> (3 + 2*x + 4*x**2).coeff(x)
| 2
| >>> (3 + 2*x + 4*x**2).coeff(x**2)
| 4
| >>> (3 + 2*x + 4*x**2).coeff(x**3)
| 0
| >>> (z*(x + y)**2).coeff((x + y)**2)
| z
| >>> (z*(x + y)**2).coeff(x + y)
| 0
|
| In addition, no factoring is done, so 1 + z*(1 + y) is not obtained
| from the following:
|
| >>> (x + z*(x + x*y)).coeff(x)
| 1
|
| If such factoring is desired, factor_terms can be used first:
|
| >>> from sympy import factor_terms
| >>> factor_terms(x + z*(x + x*y)).coeff(x)
| z*(y + 1) + 1
|
| >>> n, m, o = symbols('n m o', commutative=False)
| >>> n.coeff(n)
| 1
| >>> (3*n).coeff(n)
| 3
| >>> (n*m + m*n*m).coeff(n) # = (1 + m)*n*m
| 1 + m
| >>> (n*m + m*n*m).coeff(n, right=True) # = (1 + m)*n*m
| m
|
| If there is more than one possible coefficient 0 is returned:
|
| >>> (n*m + m*n).coeff(n)
| 0
|
| If there is only one possible coefficient, it is returned:
|
| >>> (n*m + x*m*n).coeff(m*n)
| x
| >>> (n*m + x*m*n).coeff(m*n, right=1)
| 1
|
| See Also
| ========
|
| as_coefficient: separate the expression into a coefficient and factor
| as_coeff_Add: separate the additive constant from an expression
| as_coeff_Mul: separate the multiplicative constant from an expression
| as_independent: separate x-dependent terms/factors from others
| sympy.polys.polytools.Poly.coeff_monomial: efficiently find the single coefficient of a monomial in Poly
| sympy.polys.polytools.Poly.nth: like coeff_monomial but powers of monomial terms are used
|
| collect(self, syms, func=None, evaluate=True, exact=False, distribute_order_term=True)
| See the collect function in sympy.simplify
|
| combsimp(self)
| See the combsimp function in sympy.simplify
|
| compute_leading_term(self, x, logx=None)
| as_leading_term is only allowed for results of .series()
| This is a wrapper to compute a series first.
|
| conjugate(self)
| Returns the complex conjugate of 'self'.
|
| could_extract_minus_sign(self)
| Return True if self is not in a canonical form with respect
| to its sign.
|
| For most expressions, e, there will be a difference in e and -e.
| When there is, True will be returned for one and False for the
| other; False will be returned if there is no difference.
|
| Examples
| ========
|
| >>> from sympy.abc import x, y
| >>> e = x - y
| >>> {i.could_extract_minus_sign() for i in (e, -e)}
| {False, True}
|
| count_ops(self, visual=None)
| wrapper for count_ops that returns the operation count.
|
| diff(self, *symbols, **assumptions)
|
| dir(self, x, cdir)
|
| equals(self, other, failing_expression=False)
| Return True if self == other, False if it doesn't, or None. If
| failing_expression is True then the expression which did not simplify
| to a 0 will be returned instead of None.
|
| Explanation
| ===========
|
| If ``self`` is a Number (or complex number) that is not zero, then
| the result is False.
|
| If ``self`` is a number and has not evaluated to zero, evalf will be
| used to test whether the expression evaluates to zero. If it does so
| and the result has significance (i.e. the precision is either -1, for
| a Rational result, or is greater than 1) then the evalf value will be
| used to return True or False.
|
| expand(self, deep=True, modulus=None, power_base=True, power_exp=True, mul=True, log=True, multinomial=True, basic=True, **hints)
| Expand an expression using hints.
|
| See the docstring of the expand() function in sympy.core.function for
| more information.
|
| extract_additively(self, c)
| Return self - c if it's possible to subtract c from self and
| make all matching coefficients move towards zero, else return None.
|
| Examples
| ========
|
| >>> from sympy.abc import x, y
| >>> e = 2*x + 3
| >>> e.extract_additively(x + 1)
| x + 2
| >>> e.extract_additively(3*x)
| >>> e.extract_additively(4)
| >>> (y*(x + 1)).extract_additively(x + 1)
| >>> ((x + 1)*(x + 2*y + 1) + 3).extract_additively(x + 1)
| (x + 1)*(x + 2*y) + 3
|
| Sometimes auto-expansion will return a less simplified result
| than desired; gcd_terms might be used in such cases:
|
| >>> from sympy import gcd_terms
| >>> (4*x*(y + 1) + y).extract_additively(x)
| 4*x*(y + 1) + x*(4*y + 3) - x*(4*y + 4) + y
| >>> gcd_terms(_)
| x*(4*y + 3) + y
|
| See Also
| ========
| extract_multiplicatively
| coeff
| as_coefficient
|
| extract_branch_factor(self, allow_half=False)
| Try to write self as ``exp_polar(2*pi*I*n)*z`` in a nice way.
| Return (z, n).
|
| >>> from sympy import exp_polar, I, pi
| >>> from sympy.abc import x, y
| >>> exp_polar(I*pi).extract_branch_factor()
| (exp_polar(I*pi), 0)
| >>> exp_polar(2*I*pi).extract_branch_factor()
| (1, 1)
| >>> exp_polar(-pi*I).extract_branch_factor()
| (exp_polar(I*pi), -1)
| >>> exp_polar(3*pi*I + x).extract_branch_factor()
| (exp_polar(x + I*pi), 1)
| >>> (y*exp_polar(-5*pi*I)*exp_polar(3*pi*I + 2*pi*x)).extract_branch_factor()
| (y*exp_polar(2*pi*x), -1)
| >>> exp_polar(-I*pi/2).extract_branch_factor()
| (exp_polar(-I*pi/2), 0)
|
| If allow_half is True, also extract exp_polar(I*pi):
|
| >>> exp_polar(I*pi).extract_branch_factor(allow_half=True)
| (1, 1/2)
| >>> exp_polar(2*I*pi).extract_branch_factor(allow_half=True)
| (1, 1)
| >>> exp_polar(3*I*pi).extract_branch_factor(allow_half=True)
| (1, 3/2)
| >>> exp_polar(-I*pi).extract_branch_factor(allow_half=True)
| (1, -1/2)
|
| extract_multiplicatively(self, c)
| Return None if it's not possible to make self in the form
| c * something in a nice way, i.e. preserving the properties
| of arguments of self.
|
| Examples
| ========
|
| >>> from sympy import symbols, Rational
|
| >>> x, y = symbols('x,y', real=True)
|
| >>> ((x*y)**3).extract_multiplicatively(x**2 * y)
| x*y**2
|
| >>> ((x*y)**3).extract_multiplicatively(x**4 * y)
|
| >>> (2*x).extract_multiplicatively(2)
| x
|
| >>> (2*x).extract_multiplicatively(3)
|
| >>> (Rational(1, 2)*x).extract_multiplicatively(3)
| x/6
|
| factor(self, *gens, **args)
| See the factor() function in sympy.polys.polytools
|
| fourier_series(self, limits=None)
| Compute fourier sine/cosine series of self.
|
| See the docstring of the :func:`fourier_series` in sympy.series.fourier
| for more information.
|
| fps(self, x=None, x0=0, dir=1, hyper=True, order=4, rational=True, full=False)
| Compute formal power power series of self.
|
| See the docstring of the :func:`fps` function in sympy.series.formal for
| more information.
|
| gammasimp(self)
| See the gammasimp function in sympy.simplify
|
| getO(self)
| Returns the additive O(..) symbol if there is one, else None.
|
| getn(self)
| Returns the order of the expression.
|
| Explanation
| ===========
|
| The order is determined either from the O(...) term. If there
| is no O(...) term, it returns None.
|
| Examples
| ========
|
| >>> from sympy import O
| >>> from sympy.abc import x
| >>> (1 + x + O(x**2)).getn()
| 2
| >>> (1 + x).getn()
|
| integrate(self, *args, **kwargs)
| See the integrate function in sympy.integrals
|
| invert(self, g, *gens, **args)
| Return the multiplicative inverse of ``self`` mod ``g``
| where ``self`` (and ``g``) may be symbolic expressions).
|
| See Also
| ========
| sympy.core.numbers.mod_inverse, sympy.polys.polytools.invert
|
| is_algebraic_expr(self, *syms)
| This tests whether a given expression is algebraic or not, in the
| given symbols, syms. When syms is not given, all free symbols
| will be used. The rational function does not have to be in expanded
| or in any kind of canonical form.
|
| This function returns False for expressions that are "algebraic
| expressions" with symbolic exponents. This is a simple extension to the
| is_rational_function, including rational exponentiation.
|
| Examples
| ========
|
| >>> from sympy import Symbol, sqrt
| >>> x = Symbol('x', real=True)
| >>> sqrt(1 + x).is_rational_function()
| False
| >>> sqrt(1 + x).is_algebraic_expr()
| True
|
| This function does not attempt any nontrivial simplifications that may
| result in an expression that does not appear to be an algebraic
| expression to become one.
|
| >>> from sympy import exp, factor
| >>> a = sqrt(exp(x)**2 + 2*exp(x) + 1)/(exp(x) + 1)
| >>> a.is_algebraic_expr(x)
| False
| >>> factor(a).is_algebraic_expr()
| True
|
| See Also
| ========
| is_rational_function()
|
| References
| ==========
|
| - https://en.wikipedia.org/wiki/Algebraic_expression
|
| is_constant(self, *wrt, **flags)
| Return True if self is constant, False if not, or None if
| the constancy could not be determined conclusively.
|
| Explanation
| ===========
|
| If an expression has no free symbols then it is a constant. If
| there are free symbols it is possible that the expression is a
| constant, perhaps (but not necessarily) zero. To test such
| expressions, a few strategies are tried:
|
| 1) numerical evaluation at two random points. If two such evaluations
| give two different values and the values have a precision greater than
| 1 then self is not constant. If the evaluations agree or could not be
| obtained with any precision, no decision is made. The numerical testing
| is done only if ``wrt`` is different than the free symbols.
|
| 2) differentiation with respect to variables in 'wrt' (or all free
| symbols if omitted) to see if the expression is constant or not. This
| will not always lead to an expression that is zero even though an
| expression is constant (see added test in test_expr.py). If
| all derivatives are zero then self is constant with respect to the
| given symbols.
|
| 3) finding out zeros of denominator expression with free_symbols.
| It won't be constant if there are zeros. It gives more negative
| answers for expression that are not constant.
|
| If neither evaluation nor differentiation can prove the expression is
| constant, None is returned unless two numerical values happened to be
| the same and the flag ``failing_number`` is True -- in that case the
| numerical value will be returned.
|
| If flag simplify=False is passed, self will not be simplified;
| the default is True since self should be simplified before testing.
|
| Examples
| ========
|
| >>> from sympy import cos, sin, Sum, S, pi
| >>> from sympy.abc import a, n, x, y
| >>> x.is_constant()
| False
| >>> S(2).is_constant()
| True
| >>> Sum(x, (x, 1, 10)).is_constant()
| True
| >>> Sum(x, (x, 1, n)).is_constant()
| False
| >>> Sum(x, (x, 1, n)).is_constant(y)
| True
| >>> Sum(x, (x, 1, n)).is_constant(n)
| False
| >>> Sum(x, (x, 1, n)).is_constant(x)
| True
| >>> eq = a*cos(x)**2 + a*sin(x)**2 - a
| >>> eq.is_constant()
| True
| >>> eq.subs({x: pi, a: 2}) == eq.subs({x: pi, a: 3}) == 0
| True
|
| >>> (0**x).is_constant()
| False
| >>> x.is_constant()
| False
| >>> (x**x).is_constant()
| False
| >>> one = cos(x)**2 + sin(x)**2
| >>> one.is_constant()
| True
| >>> ((one - 1)**(x + 1)).is_constant() in (True, False) # could be 0 or 1
| True
|
| is_meromorphic(self, x, a)
| This tests whether an expression is meromorphic as
| a function of the given symbol ``x`` at the point ``a``.
|
| This method is intended as a quick test that will return
| None if no decision can be made without simplification or
| more detailed analysis.
|
| Examples
| ========
|
| >>> from sympy import zoo, log, sin, sqrt
| >>> from sympy.abc import x
|
| >>> f = 1/x**2 + 1 - 2*x**3
| >>> f.is_meromorphic(x, 0)
| True
| >>> f.is_meromorphic(x, 1)
| True
| >>> f.is_meromorphic(x, zoo)
| True
|
| >>> g = x**log(3)
| >>> g.is_meromorphic(x, 0)
| False
| >>> g.is_meromorphic(x, 1)
| True
| >>> g.is_meromorphic(x, zoo)
| False
|
| >>> h = sin(1/x)*x**2
| >>> h.is_meromorphic(x, 0)
| False
| >>> h.is_meromorphic(x, 1)
| True
| >>> h.is_meromorphic(x, zoo)
| True
|
| Multivalued functions are considered meromorphic when their
| branches are meromorphic. Thus most functions are meromorphic
| everywhere except at essential singularities and branch points.
| In particular, they will be meromorphic also on branch cuts
| except at their endpoints.
|
| >>> log(x).is_meromorphic(x, -1)
| True
| >>> log(x).is_meromorphic(x, 0)
| False
| >>> sqrt(x).is_meromorphic(x, -1)
| True
| >>> sqrt(x).is_meromorphic(x, 0)
| False
|
| is_polynomial(self, *syms)
| Return True if self is a polynomial in syms and False otherwise.
|
| This checks if self is an exact polynomial in syms. This function
| returns False for expressions that are "polynomials" with symbolic
| exponents. Thus, you should be able to apply polynomial algorithms to
| expressions for which this returns True, and Poly(expr, \*syms) should
| work if and only if expr.is_polynomial(\*syms) returns True. The
| polynomial does not have to be in expanded form. If no symbols are
| given, all free symbols in the expression will be used.
|
| This is not part of the assumptions system. You cannot do
| Symbol('z', polynomial=True).
|
| Examples
| ========
|
| >>> from sympy import Symbol
| >>> x = Symbol('x')
| >>> ((x**2 + 1)**4).is_polynomial(x)
| True
| >>> ((x**2 + 1)**4).is_polynomial()
| True
| >>> (2**x + 1).is_polynomial(x)
| False
|
|
| >>> n = Symbol('n', nonnegative=True, integer=True)
| >>> (x**n + 1).is_polynomial(x)
| False
|
| This function does not attempt any nontrivial simplifications that may
| result in an expression that does not appear to be a polynomial to
| become one.
|
| >>> from sympy import sqrt, factor, cancel
| >>> y = Symbol('y', positive=True)
| >>> a = sqrt(y**2 + 2*y + 1)
| >>> a.is_polynomial(y)
| False
| >>> factor(a)
| y + 1
| >>> factor(a).is_polynomial(y)
| True
|
| >>> b = (y**2 + 2*y + 1)/(y + 1)
| >>> b.is_polynomial(y)
| False
| >>> cancel(b)
| y + 1
| >>> cancel(b).is_polynomial(y)
| True
|
| See also .is_rational_function()
|
| is_rational_function(self, *syms)
| Test whether function is a ratio of two polynomials in the given
| symbols, syms. When syms is not given, all free symbols will be used.
| The rational function does not have to be in expanded or in any kind of
| canonical form.
|
| This function returns False for expressions that are "rational
| functions" with symbolic exponents. Thus, you should be able to call
| .as_numer_denom() and apply polynomial algorithms to the result for
| expressions for which this returns True.
|
| This is not part of the assumptions system. You cannot do
| Symbol('z', rational_function=True).
|
| Examples
| ========
|
| >>> from sympy import Symbol, sin
| >>> from sympy.abc import x, y
|
| >>> (x/y).is_rational_function()
| True
|
| >>> (x**2).is_rational_function()
| True
|
| >>> (x/sin(y)).is_rational_function(y)
| False
|
| >>> n = Symbol('n', integer=True)
| >>> (x**n + 1).is_rational_function(x)
| False
|
| This function does not attempt any nontrivial simplifications that may
| result in an expression that does not appear to be a rational function
| to become one.
|
| >>> from sympy import sqrt, factor
| >>> y = Symbol('y', positive=True)
| >>> a = sqrt(y**2 + 2*y + 1)/y
| >>> a.is_rational_function(y)
| False
| >>> factor(a)
| (y + 1)/y
| >>> factor(a).is_rational_function(y)
| True
|
| See also is_algebraic_expr().
|
| leadterm(self, x, cdir=0)
| Returns the leading term a*x**b as a tuple (a, b).
|
| Examples
| ========
|
| >>> from sympy.abc import x
| >>> (1+x+x**2).leadterm(x)
| (1, 0)
| >>> (1/x**2+x+x**2).leadterm(x)
| (1, -2)
|
| limit(self, x, xlim, dir='+')
| Compute limit x->xlim.
|
| lseries(self, x=None, x0=0, dir='+', logx=None, cdir=0)
| Wrapper for series yielding an iterator of the terms of the series.
|
| Note: an infinite series will yield an infinite iterator. The following,
| for exaxmple, will never terminate. It will just keep printing terms
| of the sin(x) series::
|
| for term in sin(x).lseries(x):
| print term
|
| The advantage of lseries() over nseries() is that many times you are
| just interested in the next term in the series (i.e. the first term for
| example), but you don't know how many you should ask for in nseries()
| using the "n" parameter.
|
| See also nseries().
|
| normal(self)
| expression -> a/b
|
| See Also
| ========
|
| as_numer_denom: return ``(a, b)`` instead of ``a/b``
|
| nseries(self, x=None, x0=0, n=6, dir='+', logx=None, cdir=0)
| Wrapper to _eval_nseries if assumptions allow, else to series.
|
| If x is given, x0 is 0, dir='+', and self has x, then _eval_nseries is
| called. This calculates "n" terms in the innermost expressions and
| then builds up the final series just by "cross-multiplying" everything
| out.
|
| The optional ``logx`` parameter can be used to replace any log(x) in the
| returned series with a symbolic value to avoid evaluating log(x) at 0. A
| symbol to use in place of log(x) should be provided.
|
| Advantage -- it's fast, because we don't have to determine how many
| terms we need to calculate in advance.
|
| Disadvantage -- you may end up with less terms than you may have
| expected, but the O(x**n) term appended will always be correct and
| so the result, though perhaps shorter, will also be correct.
|
| If any of those assumptions is not met, this is treated like a
| wrapper to series which will try harder to return the correct
| number of terms.
|
| See also lseries().
|
| Examples
| ========
|
| >>> from sympy import sin, log, Symbol
| >>> from sympy.abc import x, y
| >>> sin(x).nseries(x, 0, 6)
| x - x**3/6 + x**5/120 + O(x**6)
| >>> log(x+1).nseries(x, 0, 5)
| x - x**2/2 + x**3/3 - x**4/4 + O(x**5)
|
| Handling of the ``logx`` parameter --- in the following example the
| expansion fails since ``sin`` does not have an asymptotic expansion
| at -oo (the limit of log(x) as x approaches 0):
|
| >>> e = sin(log(x))
| >>> e.nseries(x, 0, 6)
| Traceback (most recent call last):
| ...
| PoleError: ...
| ...
| >>> logx = Symbol('logx')
| >>> e.nseries(x, 0, 6, logx=logx)
| sin(logx)
|
| In the following example, the expansion works but gives only an Order term
| unless the ``logx`` parameter is used:
|
| >>> e = x**y
| >>> e.nseries(x, 0, 2)
| O(log(x)**2)
| >>> e.nseries(x, 0, 2, logx=logx)
| exp(logx*y)
|
| nsimplify(self, constants=[], tolerance=None, full=False)
| See the nsimplify function in sympy.simplify
|
| powsimp(self, *args, **kwargs)
| See the powsimp function in sympy.simplify
|
| primitive(self)
| Return the positive Rational that can be extracted non-recursively
| from every term of self (i.e., self is treated like an Add). This is
| like the as_coeff_Mul() method but primitive always extracts a positive
| Rational (never a negative or a Float).
|
| Examples
| ========
|
| >>> from sympy.abc import x
| >>> (3*(x + 1)**2).primitive()
| (3, (x + 1)**2)
| >>> a = (6*x + 2); a.primitive()
| (2, 3*x + 1)
| >>> b = (x/2 + 3); b.primitive()
| (1/2, x + 6)
| >>> (a*b).primitive() == (1, a*b)
| True
|
| radsimp(self, **kwargs)
| See the radsimp function in sympy.simplify
|
| ratsimp(self)
| See the ratsimp function in sympy.simplify
|
| removeO(self)
| Removes the additive O(..) symbol if there is one
|
| round(self, n=None)
| Return x rounded to the given decimal place.
|
| If a complex number would results, apply round to the real
| and imaginary components of the number.
|
| Examples
| ========
|
| >>> from sympy import pi, E, I, S, Number
| >>> pi.round()
| 3
| >>> pi.round(2)
| 3.14
| >>> (2*pi + E*I).round()
| 6 + 3*I
|
| The round method has a chopping effect:
|
| >>> (2*pi + I/10).round()
| 6
| >>> (pi/10 + 2*I).round()
| 2*I
| >>> (pi/10 + E*I).round(2)
| 0.31 + 2.72*I
|
| Notes
| =====
|
| The Python ``round`` function uses the SymPy ``round`` method so it
| will always return a SymPy number (not a Python float or int):
|
| >>> isinstance(round(S(123), -2), Number)
| True
|
| separate(self, deep=False, force=False)
| See the separate function in sympy.simplify
|
| series(self, x=None, x0=0, n=6, dir='+', logx=None, cdir=0)
| Series expansion of "self" around ``x = x0`` yielding either terms of
| the series one by one (the lazy series given when n=None), else
| all the terms at once when n != None.
|
| Returns the series expansion of "self" around the point ``x = x0``
| with respect to ``x`` up to ``O((x - x0)**n, x, x0)`` (default n is 6).
|
| If ``x=None`` and ``self`` is univariate, the univariate symbol will
| be supplied, otherwise an error will be raised.
|
| Parameters
| ==========
|
| expr : Expression
| The expression whose series is to be expanded.
|
| x : Symbol
| It is the variable of the expression to be calculated.
|
| x0 : Value
| The value around which ``x`` is calculated. Can be any value
| from ``-oo`` to ``oo``.
|
| n : Value
| The number of terms upto which the series is to be expanded.
|
| dir : String, optional
| The series-expansion can be bi-directional. If ``dir="+"``,
| then (x->x0+). If ``dir="-", then (x->x0-). For infinite
| ``x0`` (``oo`` or ``-oo``), the ``dir`` argument is determined
| from the direction of the infinity (i.e., ``dir="-"`` for
| ``oo``).
|
| logx : optional
| It is used to replace any log(x) in the returned series with a
| symbolic value rather than evaluating the actual value.
|
| cdir : optional
| It stands for complex direction, and indicates the direction
| from which the expansion needs to be evaluated.
|
| Examples
| ========
|
| >>> from sympy import cos, exp, tan
| >>> from sympy.abc import x, y
| >>> cos(x).series()
| 1 - x**2/2 + x**4/24 + O(x**6)
| >>> cos(x).series(n=4)
| 1 - x**2/2 + O(x**4)
| >>> cos(x).series(x, x0=1, n=2)
| cos(1) - (x - 1)*sin(1) + O((x - 1)**2, (x, 1))
| >>> e = cos(x + exp(y))
| >>> e.series(y, n=2)
| cos(x + 1) - y*sin(x + 1) + O(y**2)
| >>> e.series(x, n=2)
| cos(exp(y)) - x*sin(exp(y)) + O(x**2)
|
| If ``n=None`` then a generator of the series terms will be returned.
|
| >>> term=cos(x).series(n=None)
| >>> [next(term) for i in range(2)]
| [1, -x**2/2]
|
| For ``dir=+`` (default) the series is calculated from the right and
| for ``dir=-`` the series from the left. For smooth functions this
| flag will not alter the results.
|
| >>> abs(x).series(dir="+")
| x
| >>> abs(x).series(dir="-")
| -x
| >>> f = tan(x)
| >>> f.series(x, 2, 6, "+")
| tan(2) + (1 + tan(2)**2)*(x - 2) + (x - 2)**2*(tan(2)**3 + tan(2)) +
| (x - 2)**3*(1/3 + 4*tan(2)**2/3 + tan(2)**4) + (x - 2)**4*(tan(2)**5 +
| 5*tan(2)**3/3 + 2*tan(2)/3) + (x - 2)**5*(2/15 + 17*tan(2)**2/15 +
| 2*tan(2)**4 + tan(2)**6) + O((x - 2)**6, (x, 2))
|
| >>> f.series(x, 2, 3, "-")
| tan(2) + (2 - x)*(-tan(2)**2 - 1) + (2 - x)**2*(tan(2)**3 + tan(2))
| + O((x - 2)**3, (x, 2))
|
| Returns
| =======
|
| Expr : Expression
| Series expansion of the expression about x0
|
| Raises
| ======
|
| TypeError
| If "n" and "x0" are infinity objects
|
| PoleError
| If "x0" is an infinity object
|
| sort_key(self, order=None)
| Return a sort key.
|
| Examples
| ========
|
| >>> from sympy.core import S, I
|
| >>> sorted([S(1)/2, I, -I], key=lambda x: x.sort_key())
| [1/2, -I, I]
|
| >>> S("[x, 1/x, 1/x**2, x**2, x**(1/2), x**(1/4), x**(3/2)]")
| [x, 1/x, x**(-2), x**2, sqrt(x), x**(1/4), x**(3/2)]
| >>> sorted(_, key=lambda x: x.sort_key())
| [x**(-2), 1/x, x**(1/4), sqrt(x), x, x**(3/2), x**2]
|
| taylor_term(self, n, x, *previous_terms)
| General method for the taylor term.
|
| This method is slow, because it differentiates n-times. Subclasses can
| redefine it to make it faster by using the "previous_terms".
|
| together(self, *args, **kwargs)
| See the together function in sympy.polys
|
| transpose(self)
|
| trigsimp(self, **args)
| See the trigsimp function in sympy.simplify
|
| ----------------------------------------------------------------------
| Readonly properties inherited from sympy.core.expr.Expr:
|
| expr_free_symbols
| Like ``free_symbols``, but returns the free symbols only if they are contained in an expression node.
|
| Examples
| ========
|
| >>> from sympy.abc import x, y
| >>> (x + y).expr_free_symbols
| {x, y}
|
| If the expression is contained in a non-expression object, don't return
| the free symbols. Compare:
|
| >>> from sympy import Tuple
| >>> t = Tuple(x + y)
| >>> t.expr_free_symbols
| set()
| >>> t.free_symbols
| {x, y}
|
| is_number
| Returns True if ``self`` has no free symbols and no
| undefined functions (AppliedUndef, to be precise). It will be
| faster than ``if not self.free_symbols``, however, since
| ``is_number`` will fail as soon as it hits a free symbol
| or undefined function.
|
| Examples
| ========
|
| >>> from sympy import Integral, cos, sin, pi
| >>> from sympy.core.function import Function
| >>> from sympy.abc import x
| >>> f = Function('f')
|
| >>> x.is_number
| False
| >>> f(1).is_number
| False
| >>> (2*x).is_number
| False
| >>> (2 + Integral(2, x)).is_number
| False
| >>> (2 + Integral(2, (x, 1, 2))).is_number
| True
|
| Not all numbers are Numbers in the SymPy sense:
|
| >>> pi.is_number, pi.is_Number
| (True, False)
|
| If something is a number it should evaluate to a number with
| real and imaginary parts that are Numbers; the result may not
| be comparable, however, since the real and/or imaginary part
| of the result may not have precision.
|
| >>> cos(1).is_number and cos(1).is_comparable
| True
|
| >>> z = cos(1)**2 + sin(1)**2 - 1
| >>> z.is_number
| True
| >>> z.is_comparable
| False
|
| See Also
| ========
|
| sympy.core.basic.Basic.is_comparable
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from sympy.core.expr.Expr:
|
| is_scalar = True
|
| ----------------------------------------------------------------------
| Methods inherited from sympy.core.basic.Basic:
|
| __getnewargs__(self)
|
| __getstate__(self)
|
| __ne__(self, other)
| ``a != b`` -> Compare two symbolic trees and see whether they are different
|
| this is the same as:
|
| ``a.compare(b) != 0``
|
| but faster
|
| __reduce_ex__(self, proto)
| Pickling support.
|
| __setstate__(self, state)
|
| as_dummy(self)
| Return the expression with any objects having structurally
| bound symbols replaced with unique, canonical symbols within
| the object in which they appear and having only the default
| assumption for commutativity being True. When applied to a
| symbol a new symbol having only the same commutativity will be
| returned.
|
| Examples
| ========
|
| >>> from sympy import Integral, Symbol
| >>> from sympy.abc import x
| >>> r = Symbol('r', real=True)
| >>> Integral(r, (r, x)).as_dummy()
| Integral(_0, (_0, x))
| >>> _.variables[0].is_real is None
| True
| >>> r.as_dummy()
| _r
|
| Notes
| =====
|
| Any object that has structurally bound variables should have
| a property, `bound_symbols` that returns those symbols
| appearing in the object.
|
| atoms(self, *types)
| Returns the atoms that form the current object.
|
| By default, only objects that are truly atomic and can't
| be divided into smaller pieces are returned: symbols, numbers,
| and number symbols like I and pi. It is possible to request
| atoms of any type, however, as demonstrated below.
|
| Examples
| ========
|
| >>> from sympy import I, pi, sin
| >>> from sympy.abc import x, y
| >>> (1 + x + 2*sin(y + I*pi)).atoms()
| {1, 2, I, pi, x, y}
|
| If one or more types are given, the results will contain only
| those types of atoms.
|
| >>> from sympy import Number, NumberSymbol, Symbol
| >>> (1 + x + 2*sin(y + I*pi)).atoms(Symbol)
| {x, y}
|
| >>> (1 + x + 2*sin(y + I*pi)).atoms(Number)
| {1, 2}
|
| >>> (1 + x + 2*sin(y + I*pi)).atoms(Number, NumberSymbol)
| {1, 2, pi}
|
| >>> (1 + x + 2*sin(y + I*pi)).atoms(Number, NumberSymbol, I)
| {1, 2, I, pi}
|
| Note that I (imaginary unit) and zoo (complex infinity) are special
| types of number symbols and are not part of the NumberSymbol class.
|
| The type can be given implicitly, too:
|
| >>> (1 + x + 2*sin(y + I*pi)).atoms(x) # x is a Symbol
| {x, y}
|
| Be careful to check your assumptions when using the implicit option
| since ``S(1).is_Integer = True`` but ``type(S(1))`` is ``One``, a special type
| of sympy atom, while ``type(S(2))`` is type ``Integer`` and will find all
| integers in an expression:
|
| >>> from sympy import S
| >>> (1 + x + 2*sin(y + I*pi)).atoms(S(1))
| {1}
|
| >>> (1 + x + 2*sin(y + I*pi)).atoms(S(2))
| {1, 2}
|
| Finally, arguments to atoms() can select more than atomic atoms: any
| sympy type (loaded in core/__init__.py) can be listed as an argument
| and those types of "atoms" as found in scanning the arguments of the
| expression recursively:
|
| >>> from sympy import Function, Mul
| >>> from sympy.core.function import AppliedUndef
| >>> f = Function('f')
| >>> (1 + f(x) + 2*sin(y + I*pi)).atoms(Function)
| {f(x), sin(y + I*pi)}
| >>> (1 + f(x) + 2*sin(y + I*pi)).atoms(AppliedUndef)
| {f(x)}
|
| >>> (1 + x + 2*sin(y + I*pi)).atoms(Mul)
| {I*pi, 2*sin(y + I*pi)}
|
| compare(self, other)
| Return -1, 0, 1 if the object is smaller, equal, or greater than other.
|
| Not in the mathematical sense. If the object is of a different type
| from the "other" then their classes are ordered according to
| the sorted_classes list.
|
| Examples
| ========
|
| >>> from sympy.abc import x, y
| >>> x.compare(y)
| -1
| >>> x.compare(x)
| 0
| >>> y.compare(x)
| 1
|
| copy(self)
|
| count(self, query)
| Count the number of matching subexpressions.
|
| doit(self, **hints)
| Evaluate objects that are not evaluated by default like limits,
| integrals, sums and products. All objects of this kind will be
| evaluated recursively, unless some species were excluded via 'hints'
| or unless the 'deep' hint was set to 'False'.
|
| >>> from sympy import Integral
| >>> from sympy.abc import x
|
| >>> 2*Integral(x, x)
| 2*Integral(x, x)
|
| >>> (2*Integral(x, x)).doit()
| x**2
|
| >>> (2*Integral(x, x)).doit(deep=False)
| 2*Integral(x, x)
|
| dummy_eq(self, other, symbol=None)
| Compare two expressions and handle dummy symbols.
|
| Examples
| ========
|
| >>> from sympy import Dummy
| >>> from sympy.abc import x, y
|
| >>> u = Dummy('u')
|
| >>> (u**2 + 1).dummy_eq(x**2 + 1)
| True
| >>> (u**2 + 1) == (x**2 + 1)
| False
|
| >>> (u**2 + y).dummy_eq(x**2 + y, x)
| True
| >>> (u**2 + y).dummy_eq(x**2 + y, y)
| False
|
| find(self, query, group=False)
| Find all subexpressions matching a query.
|
| has(self, *patterns)
| Test whether any subexpression matches any of the patterns.
|
| Examples
| ========
|
| >>> from sympy import sin
| >>> from sympy.abc import x, y, z
| >>> (x**2 + sin(x*y)).has(z)
| False
| >>> (x**2 + sin(x*y)).has(x, y, z)
| True
| >>> x.has(x)
| True
|
| Note ``has`` is a structural algorithm with no knowledge of
| mathematics. Consider the following half-open interval:
|
| >>> from sympy.sets import Interval
| >>> i = Interval.Lopen(0, 5); i
| Interval.Lopen(0, 5)
| >>> i.args
| (0, 5, True, False)
| >>> i.has(4) # there is no "4" in the arguments
| False
| >>> i.has(0) # there *is* a "0" in the arguments
| True
|
| Instead, use ``contains`` to determine whether a number is in the
| interval or not:
|
| >>> i.contains(4)
| True
| >>> i.contains(0)
| False
|
|
| Note that ``expr.has(*patterns)`` is exactly equivalent to
| ``any(expr.has(p) for p in patterns)``. In particular, ``False`` is
| returned when the list of patterns is empty.
|
| >>> x.has()
| False
|
| is_hypergeometric(self, k)
|
| match(self, pattern, old=False)
| Pattern matching.
|
| Wild symbols match all.
|
| Return ``None`` when expression (self) does not match
| with pattern. Otherwise return a dictionary such that::
|
| pattern.xreplace(self.match(pattern)) == self
|
| Examples
| ========
|
| >>> from sympy import Wild, Sum
| >>> from sympy.abc import x, y
| >>> p = Wild("p")
| >>> q = Wild("q")
| >>> r = Wild("r")
| >>> e = (x+y)**(x+y)
| >>> e.match(p**p)
| {p_: x + y}
| >>> e.match(p**q)
| {p_: x + y, q_: x + y}
| >>> e = (2*x)**2
| >>> e.match(p*q**r)
| {p_: 4, q_: x, r_: 2}
| >>> (p*q**r).xreplace(e.match(p*q**r))
| 4*x**2
|
| Structurally bound symbols are ignored during matching:
|
| >>> Sum(x, (x, 1, 2)).match(Sum(y, (y, 1, p)))
| {p_: 2}
|
| But they can be identified if desired:
|
| >>> Sum(x, (x, 1, 2)).match(Sum(q, (q, 1, p)))
| {p_: 2, q_: x}
|
| The ``old`` flag will give the old-style pattern matching where
| expressions and patterns are essentially solved to give the
| match. Both of the following give None unless ``old=True``:
|
| >>> (x - 2).match(p - x, old=True)
| {p_: 2*x - 2}
| >>> (2/x).match(p*x, old=True)
| {p_: 2/x**2}
|
| matches(self, expr, repl_dict={}, old=False)
| Helper method for match() that looks for a match between Wild symbols
| in self and expressions in expr.
|
| Examples
| ========
|
| >>> from sympy import symbols, Wild, Basic
| >>> a, b, c = symbols('a b c')
| >>> x = Wild('x')
| >>> Basic(a + x, x).matches(Basic(a + b, c)) is None
| True
| >>> Basic(a + x, x).matches(Basic(a + b + c, b + c))
| {x_: b + c}
|
| rcall(self, *args)
| Apply on the argument recursively through the expression tree.
|
| This method is used to simulate a common abuse of notation for
| operators. For instance in SymPy the the following will not work:
|
| ``(x+Lambda(y, 2*y))(z) == x+2*z``,
|
| however you can use
|
| >>> from sympy import Lambda
| >>> from sympy.abc import x, y, z
| >>> (x + Lambda(y, 2*y)).rcall(z)
| x + 2*z
|
| refine(self, assumption=True)
| See the refine function in sympy.assumptions
|
| replace(self, query, value, map=False, simultaneous=True, exact=None)
| Replace matching subexpressions of ``self`` with ``value``.
|
| If ``map = True`` then also return the mapping {old: new} where ``old``
| was a sub-expression found with query and ``new`` is the replacement
| value for it. If the expression itself doesn't match the query, then
| the returned value will be ``self.xreplace(map)`` otherwise it should
| be ``self.subs(ordered(map.items()))``.
|
| Traverses an expression tree and performs replacement of matching
| subexpressions from the bottom to the top of the tree. The default
| approach is to do the replacement in a simultaneous fashion so
| changes made are targeted only once. If this is not desired or causes
| problems, ``simultaneous`` can be set to False.
|
| In addition, if an expression containing more than one Wild symbol
| is being used to match subexpressions and the ``exact`` flag is None
| it will be set to True so the match will only succeed if all non-zero
| values are received for each Wild that appears in the match pattern.
| Setting this to False accepts a match of 0; while setting it True
| accepts all matches that have a 0 in them. See example below for
| cautions.
|
| The list of possible combinations of queries and replacement values
| is listed below:
|
| Examples
| ========
|
| Initial setup
|
| >>> from sympy import log, sin, cos, tan, Wild, Mul, Add
| >>> from sympy.abc import x, y
| >>> f = log(sin(x)) + tan(sin(x**2))
|
| 1.1. type -> type
| obj.replace(type, newtype)
|
| When object of type ``type`` is found, replace it with the
| result of passing its argument(s) to ``newtype``.
|
| >>> f.replace(sin, cos)
| log(cos(x)) + tan(cos(x**2))
| >>> sin(x).replace(sin, cos, map=True)
| (cos(x), {sin(x): cos(x)})
| >>> (x*y).replace(Mul, Add)
| x + y
|
| 1.2. type -> func
| obj.replace(type, func)
|
| When object of type ``type`` is found, apply ``func`` to its
| argument(s). ``func`` must be written to handle the number
| of arguments of ``type``.
|
| >>> f.replace(sin, lambda arg: sin(2*arg))
| log(sin(2*x)) + tan(sin(2*x**2))
| >>> (x*y).replace(Mul, lambda *args: sin(2*Mul(*args)))
| sin(2*x*y)
|
| 2.1. pattern -> expr
| obj.replace(pattern(wild), expr(wild))
|
| Replace subexpressions matching ``pattern`` with the expression
| written in terms of the Wild symbols in ``pattern``.
|
| >>> a, b = map(Wild, 'ab')
| >>> f.replace(sin(a), tan(a))
| log(tan(x)) + tan(tan(x**2))
| >>> f.replace(sin(a), tan(a/2))
| log(tan(x/2)) + tan(tan(x**2/2))
| >>> f.replace(sin(a), a)
| log(x) + tan(x**2)
| >>> (x*y).replace(a*x, a)
| y
|
| Matching is exact by default when more than one Wild symbol
| is used: matching fails unless the match gives non-zero
| values for all Wild symbols:
|
| >>> (2*x + y).replace(a*x + b, b - a)
| y - 2
| >>> (2*x).replace(a*x + b, b - a)
| 2*x
|
| When set to False, the results may be non-intuitive:
|
| >>> (2*x).replace(a*x + b, b - a, exact=False)
| 2/x
|
| 2.2. pattern -> func
| obj.replace(pattern(wild), lambda wild: expr(wild))
|
| All behavior is the same as in 2.1 but now a function in terms of
| pattern variables is used rather than an expression:
|
| >>> f.replace(sin(a), lambda a: sin(2*a))
| log(sin(2*x)) + tan(sin(2*x**2))
|
| 3.1. func -> func
| obj.replace(filter, func)
|
| Replace subexpression ``e`` with ``func(e)`` if ``filter(e)``
| is True.
|
| >>> g = 2*sin(x**3)
| >>> g.replace(lambda expr: expr.is_Number, lambda expr: expr**2)
| 4*sin(x**9)
|
| The expression itself is also targeted by the query but is done in
| such a fashion that changes are not made twice.
|
| >>> e = x*(x*y + 1)
| >>> e.replace(lambda x: x.is_Mul, lambda x: 2*x)
| 2*x*(2*x*y + 1)
|
| When matching a single symbol, `exact` will default to True, but
| this may or may not be the behavior that is desired:
|
| Here, we want `exact=False`:
|
| >>> from sympy import Function
| >>> f = Function('f')
| >>> e = f(1) + f(0)
| >>> q = f(a), lambda a: f(a + 1)
| >>> e.replace(*q, exact=False)
| f(1) + f(2)
| >>> e.replace(*q, exact=True)
| f(0) + f(2)
|
| But here, the nature of matching makes selecting
| the right setting tricky:
|
| >>> e = x**(1 + y)
| >>> (x**(1 + y)).replace(x**(1 + a), lambda a: x**-a, exact=False)
| x
| >>> (x**(1 + y)).replace(x**(1 + a), lambda a: x**-a, exact=True)
| x**(-x - y + 1)
| >>> (x**y).replace(x**(1 + a), lambda a: x**-a, exact=False)
| x
| >>> (x**y).replace(x**(1 + a), lambda a: x**-a, exact=True)
| x**(1 - y)
|
| It is probably better to use a different form of the query
| that describes the target expression more precisely:
|
| >>> (1 + x**(1 + y)).replace(
| ... lambda x: x.is_Pow and x.exp.is_Add and x.exp.args[0] == 1,
| ... lambda x: x.base**(1 - (x.exp - 1)))
| ...
| x**(1 - y) + 1
|
| See Also
| ========
|
| subs: substitution of subexpressions as defined by the objects
| themselves.
| xreplace: exact node replacement in expr tree; also capable of
| using matching rules
|
| rewrite(self, *args, **hints)
| Rewrite functions in terms of other functions.
|
| Rewrites expression containing applications of functions
| of one kind in terms of functions of different kind. For
| example you can rewrite trigonometric functions as complex
| exponentials or combinatorial functions as gamma function.
|
| As a pattern this function accepts a list of functions to
| to rewrite (instances of DefinedFunction class). As rule
| you can use string or a destination function instance (in
| this case rewrite() will use the str() function).
|
| There is also the possibility to pass hints on how to rewrite
| the given expressions. For now there is only one such hint
| defined called 'deep'. When 'deep' is set to False it will
| forbid functions to rewrite their contents.
|
| Examples
| ========
|
| >>> from sympy import sin, exp
| >>> from sympy.abc import x
|
| Unspecified pattern:
|
| >>> sin(x).rewrite(exp)
| -I*(exp(I*x) - exp(-I*x))/2
|
| Pattern as a single function:
|
| >>> sin(x).rewrite(sin, exp)
| -I*(exp(I*x) - exp(-I*x))/2
|
| Pattern as a list of functions:
|
| >>> sin(x).rewrite([sin, ], exp)
| -I*(exp(I*x) - exp(-I*x))/2
|
| simplify(self, **kwargs)
| See the simplify function in sympy.simplify
|
| subs(self, *args, **kwargs)
| Substitutes old for new in an expression after sympifying args.
|
| `args` is either:
| - two arguments, e.g. foo.subs(old, new)
| - one iterable argument, e.g. foo.subs(iterable). The iterable may be
| o an iterable container with (old, new) pairs. In this case the
| replacements are processed in the order given with successive
| patterns possibly affecting replacements already made.
| o a dict or set whose key/value items correspond to old/new pairs.
| In this case the old/new pairs will be sorted by op count and in
| case of a tie, by number of args and the default_sort_key. The
| resulting sorted list is then processed as an iterable container
| (see previous).
|
| If the keyword ``simultaneous`` is True, the subexpressions will not be
| evaluated until all the substitutions have been made.
|
| Examples
| ========
|
| >>> from sympy import pi, exp, limit, oo
| >>> from sympy.abc import x, y
| >>> (1 + x*y).subs(x, pi)
| pi*y + 1
| >>> (1 + x*y).subs({x:pi, y:2})
| 1 + 2*pi
| >>> (1 + x*y).subs([(x, pi), (y, 2)])
| 1 + 2*pi
| >>> reps = [(y, x**2), (x, 2)]
| >>> (x + y).subs(reps)
| 6
| >>> (x + y).subs(reversed(reps))
| x**2 + 2
|
| >>> (x**2 + x**4).subs(x**2, y)
| y**2 + y
|
| To replace only the x**2 but not the x**4, use xreplace:
|
| >>> (x**2 + x**4).xreplace({x**2: y})
| x**4 + y
|
| To delay evaluation until all substitutions have been made,
| set the keyword ``simultaneous`` to True:
|
| >>> (x/y).subs([(x, 0), (y, 0)])
| 0
| >>> (x/y).subs([(x, 0), (y, 0)], simultaneous=True)
| nan
|
| This has the added feature of not allowing subsequent substitutions
| to affect those already made:
|
| >>> ((x + y)/y).subs({x + y: y, y: x + y})
| 1
| >>> ((x + y)/y).subs({x + y: y, y: x + y}, simultaneous=True)
| y/(x + y)
|
| In order to obtain a canonical result, unordered iterables are
| sorted by count_op length, number of arguments and by the
| default_sort_key to break any ties. All other iterables are left
| unsorted.
|
| >>> from sympy import sqrt, sin, cos
| >>> from sympy.abc import a, b, c, d, e
|
| >>> A = (sqrt(sin(2*x)), a)
| >>> B = (sin(2*x), b)
| >>> C = (cos(2*x), c)
| >>> D = (x, d)
| >>> E = (exp(x), e)
|
| >>> expr = sqrt(sin(2*x))*sin(exp(x)*x)*cos(2*x) + sin(2*x)
|
| >>> expr.subs(dict([A, B, C, D, E]))
| a*c*sin(d*e) + b
|
| The resulting expression represents a literal replacement of the
| old arguments with the new arguments. This may not reflect the
| limiting behavior of the expression:
|
| >>> (x**3 - 3*x).subs({x: oo})
| nan
|
| >>> limit(x**3 - 3*x, x, oo)
| oo
|
| If the substitution will be followed by numerical
| evaluation, it is better to pass the substitution to
| evalf as
|
| >>> (1/x).evalf(subs={x: 3.0}, n=21)
| 0.333333333333333333333
|
| rather than
|
| >>> (1/x).subs({x: 3.0}).evalf(21)
| 0.333333333333333314830
|
| as the former will ensure that the desired level of precision is
| obtained.
|
| See Also
| ========
| replace: replacement capable of doing wildcard-like matching,
| parsing of match, and conditional replacements
| xreplace: exact node replacement in expr tree; also capable of
| using matching rules
| sympy.core.evalf.EvalfMixin.evalf: calculates the given formula to a desired level of precision
|
| xreplace lambda rule, **_
| # Function needs args so we define a property that returns
| # a function that takes args...and then use that function
| # to return the right value
|
| ----------------------------------------------------------------------
| Class methods inherited from sympy.core.basic.Basic:
|
| fromiter(args, **assumptions) from sympy.core.function.FunctionClass
| Create a new object from an iterable.
|
| This is a convenience function that allows one to create objects from
| any iterable, without having to convert to a list or tuple first.
|
| Examples
| ========
|
| >>> from sympy import Tuple
| >>> Tuple.fromiter(i for i in range(5))
| (0, 1, 2, 3, 4)
|
| ----------------------------------------------------------------------
| Readonly properties inherited from sympy.core.basic.Basic:
|
| args
| Returns a tuple of arguments of 'self'.
|
| Examples
| ========
|
| >>> from sympy import cot
| >>> from sympy.abc import x, y
|
| >>> cot(x).args
| (x,)
|
| >>> cot(x).args[0]
| x
|
| >>> (x*y).args
| (x, y)
|
| >>> (x*y).args[1]
| y
|
| Notes
| =====
|
| Never use self._args, always use self.args.
| Only use _args in __new__ when creating a new function.
| Don't override .args() from Basic (so that it's easy to
| change the interface in the future if needed).
|
| assumptions0
| Return object `type` assumptions.
|
| For example:
|
| Symbol('x', real=True)
| Symbol('x', integer=True)
|
| are different objects. In other words, besides Python type (Symbol in
| this case), the initial assumptions are also forming their typeinfo.
|
| Examples
| ========
|
| >>> from sympy import Symbol
| >>> from sympy.abc import x
| >>> x.assumptions0
| {'commutative': True}
| >>> x = Symbol("x", positive=True)
| >>> x.assumptions0
| {'commutative': True, 'complex': True, 'extended_negative': False,
| 'extended_nonnegative': True, 'extended_nonpositive': False,
| 'extended_nonzero': True, 'extended_positive': True, 'extended_real':
| True, 'finite': True, 'hermitian': True, 'imaginary': False,
| 'infinite': False, 'negative': False, 'nonnegative': True,
| 'nonpositive': False, 'nonzero': True, 'positive': True, 'real':
| True, 'zero': False}
|
| canonical_variables
| Return a dictionary mapping any variable defined in
| ``self.bound_symbols`` to Symbols that do not clash
| with any free symbols in the expression.
|
| Examples
| ========
|
| >>> from sympy import Lambda
| >>> from sympy.abc import x
| >>> Lambda(x, 2*x).canonical_variables
| {x: _0}
|
| free_symbols
| Return from the atoms of self those which are free symbols.
|
| For most expressions, all symbols are free symbols. For some classes
| this is not true. e.g. Integrals use Symbols for the dummy variables
| which are bound variables, so Integral has a method to return all
| symbols except those. Derivative keeps track of symbols with respect
| to which it will perform a derivative; those are
| bound variables, too, so it has its own free_symbols method.
|
| Any other method that uses bound variables should implement a
| free_symbols method.
|
| is_algebraic
|
| is_antihermitian
|
| is_commutative
|
| is_comparable
| Return True if self can be computed to a real number
| (or already is a real number) with precision, else False.
|
| Examples
| ========
|
| >>> from sympy import exp_polar, pi, I
| >>> (I*exp_polar(I*pi/2)).is_comparable
| True
| >>> (I*exp_polar(I*pi*2)).is_comparable
| False
|
| A False result does not mean that `self` cannot be rewritten
| into a form that would be comparable. For example, the
| difference computed below is zero but without simplification
| it does not evaluate to a zero with precision:
|
| >>> e = 2**pi*(1 + 2**pi)
| >>> dif = e - e.expand()
| >>> dif.is_comparable
| False
| >>> dif.n(2)._prec
| 1
|
| is_complex
|
| is_composite
|
| is_even
|
| is_extended_negative
|
| is_extended_nonnegative
|
| is_extended_nonpositive
|
| is_extended_nonzero
|
| is_extended_positive
|
| is_extended_real
|
| is_finite
|
| is_hermitian
|
| is_imaginary
|
| is_infinite
|
| is_integer
|
| is_irrational
|
| is_negative
|
| is_noninteger
|
| is_nonnegative
|
| is_nonpositive
|
| is_nonzero
|
| is_odd
|
| is_polar
|
| is_positive
|
| is_prime
|
| is_rational
|
| is_real
|
| is_transcendental
|
| is_zero
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from sympy.core.basic.Basic:
|
| is_Add = False
|
| is_AlgebraicNumber = False
|
| is_Atom = False
|
| is_Boolean = False
|
| is_Derivative = False
|
| is_Dummy = False
|
| is_Equality = False
|
| is_Float = False
|
| is_Indexed = False
|
| is_Integer = False
|
| is_MatAdd = False
|
| is_MatMul = False
|
| is_Matrix = False
|
| is_Mul = False
|
| is_Not = False
|
| is_Number = False
|
| is_NumberSymbol = False
|
| is_Order = False
|
| is_Piecewise = False
|
| is_Point = False
|
| is_Poly = False
|
| is_Pow = False
|
| is_Rational = False
|
| is_Relational = False
|
| is_Symbol = False
|
| is_Vector = False
|
| is_Wild = False
|
| is_symbol = False
|
| kind = UndefinedKind
|
| ----------------------------------------------------------------------
| Methods inherited from sympy.printing.defaults.Printable:
|
| __repr__ = __str__(self)
|
| __str__(self)
| Return str(self).
|
| ----------------------------------------------------------------------
| Methods inherited from sympy.core.evalf.EvalfMixin:
|
| evalf(self, n=15, subs=None, maxn=100, chop=False, strict=False, quad=None, verbose=False)
| Evaluate the given formula to an accuracy of *n* digits.
|
| Parameters
| ==========
|
| subs : dict, optional
| Substitute numerical values for symbols, e.g.
| ``subs={x:3, y:1+pi}``. The substitutions must be given as a
| dictionary.
|
| maxn : int, optional
| Allow a maximum temporary working precision of maxn digits.
|
| chop : bool or number, optional
| Specifies how to replace tiny real or imaginary parts in
| subresults by exact zeros.
|
| When ``True`` the chop value defaults to standard precision.
|
| Otherwise the chop value is used to determine the
| magnitude of "small" for purposes of chopping.
|
| >>> from sympy import N
| >>> x = 1e-4
| >>> N(x, chop=True)
| 0.000100000000000000
| >>> N(x, chop=1e-5)
| 0.000100000000000000
| >>> N(x, chop=1e-4)
| 0
|
| strict : bool, optional
| Raise ``PrecisionExhausted`` if any subresult fails to
| evaluate to full accuracy, given the available maxprec.
|
| quad : str, optional
| Choose algorithm for numerical quadrature. By default,
| tanh-sinh quadrature is used. For oscillatory
| integrals on an infinite interval, try ``quad='osc'``.
|
| verbose : bool, optional
| Print debug information.
|
| Notes
| =====
|
| When Floats are naively substituted into an expression,
| precision errors may adversely affect the result. For example,
| adding 1e16 (a Float) to 1 will truncate to 1e16; if 1e16 is
| then subtracted, the result will be 0.
| That is exactly what happens in the following:
|
| >>> from sympy.abc import x, y, z
| >>> values = {x: 1e16, y: 1, z: 1e16}
| >>> (x + y - z).subs(values)
| 0
|
| Using the subs argument for evalf is the accurate way to
| evaluate such an expression:
|
| >>> (x + y - z).evalf(subs=values)
| 1.00000000000000
|
| n = evalf(self, n=15, subs=None, maxn=100, chop=False, strict=False, quad=None, verbose=False)
smp.laguerre(0, x)
smp.laguerre(1, x)
smp.laguerre(2, x)
smp.laguerre(3, x)
smp.laguerre(n, x)
\exp(i m \varphi)
\mathrm{P}_n^m\left(\cos(\theta)\right)$
help(smp.Ynm)
Help on class Ynm in module sympy.functions.special.spherical_harmonics:
class Ynm(sympy.core.function.Function)
| Ynm(n, m, theta, phi)
|
| Spherical harmonics defined as
|
| .. math::
| Y_n^m(\theta, \varphi) := \sqrt{\frac{(2n+1)(n-m)!}{4\pi(n+m)!}}
| \exp(i m \varphi)
| \mathrm{P}_n^m\left(\cos(\theta)\right)
|
| Explanation
| ===========
|
| ``Ynm()`` gives the spherical harmonic function of order $n$ and $m$
| in $\theta$ and $\varphi$, $Y_n^m(\theta, \varphi)$. The four
| parameters are as follows: $n \geq 0$ an integer and $m$ an integer
| such that $-n \leq m \leq n$ holds. The two angles are real-valued
| with $\theta \in [0, \pi]$ and $\varphi \in [0, 2\pi]$.
|
| Examples
| ========
|
| >>> from sympy import Ynm, Symbol, simplify
| >>> from sympy.abc import n,m
| >>> theta = Symbol("theta")
| >>> phi = Symbol("phi")
|
| >>> Ynm(n, m, theta, phi)
| Ynm(n, m, theta, phi)
|
| Several symmetries are known, for the order:
|
| >>> Ynm(n, -m, theta, phi)
| (-1)**m*exp(-2*I*m*phi)*Ynm(n, m, theta, phi)
|
| As well as for the angles:
|
| >>> Ynm(n, m, -theta, phi)
| Ynm(n, m, theta, phi)
|
| >>> Ynm(n, m, theta, -phi)
| exp(-2*I*m*phi)*Ynm(n, m, theta, phi)
|
| For specific integers $n$ and $m$ we can evaluate the harmonics
| to more useful expressions:
|
| >>> simplify(Ynm(0, 0, theta, phi).expand(func=True))
| 1/(2*sqrt(pi))
|
| >>> simplify(Ynm(1, -1, theta, phi).expand(func=True))
| sqrt(6)*exp(-I*phi)*sin(theta)/(4*sqrt(pi))
|
| >>> simplify(Ynm(1, 0, theta, phi).expand(func=True))
| sqrt(3)*cos(theta)/(2*sqrt(pi))
|
| >>> simplify(Ynm(1, 1, theta, phi).expand(func=True))
| -sqrt(6)*exp(I*phi)*sin(theta)/(4*sqrt(pi))
|
| >>> simplify(Ynm(2, -2, theta, phi).expand(func=True))
| sqrt(30)*exp(-2*I*phi)*sin(theta)**2/(8*sqrt(pi))
|
| >>> simplify(Ynm(2, -1, theta, phi).expand(func=True))
| sqrt(30)*exp(-I*phi)*sin(2*theta)/(8*sqrt(pi))
|
| >>> simplify(Ynm(2, 0, theta, phi).expand(func=True))
| sqrt(5)*(3*cos(theta)**2 - 1)/(4*sqrt(pi))
|
| >>> simplify(Ynm(2, 1, theta, phi).expand(func=True))
| -sqrt(30)*exp(I*phi)*sin(2*theta)/(8*sqrt(pi))
|
| >>> simplify(Ynm(2, 2, theta, phi).expand(func=True))
| sqrt(30)*exp(2*I*phi)*sin(theta)**2/(8*sqrt(pi))
|
| We can differentiate the functions with respect
| to both angles:
|
| >>> from sympy import Ynm, Symbol, diff
| >>> from sympy.abc import n,m
| >>> theta = Symbol("theta")
| >>> phi = Symbol("phi")
|
| >>> diff(Ynm(n, m, theta, phi), theta)
| m*cot(theta)*Ynm(n, m, theta, phi) + sqrt((-m + n)*(m + n + 1))*exp(-I*phi)*Ynm(n, m + 1, theta, phi)
|
| >>> diff(Ynm(n, m, theta, phi), phi)
| I*m*Ynm(n, m, theta, phi)
|
| Further we can compute the complex conjugation:
|
| >>> from sympy import Ynm, Symbol, conjugate
| >>> from sympy.abc import n,m
| >>> theta = Symbol("theta")
| >>> phi = Symbol("phi")
|
| >>> conjugate(Ynm(n, m, theta, phi))
| (-1)**(2*m)*exp(-2*I*m*phi)*Ynm(n, m, theta, phi)
|
| To get back the well known expressions in spherical
| coordinates, we use full expansion:
|
| >>> from sympy import Ynm, Symbol, expand_func
| >>> from sympy.abc import n,m
| >>> theta = Symbol("theta")
| >>> phi = Symbol("phi")
|
| >>> expand_func(Ynm(n, m, theta, phi))
| sqrt((2*n + 1)*factorial(-m + n)/factorial(m + n))*exp(I*m*phi)*assoc_legendre(n, m, cos(theta))/(2*sqrt(pi))
|
| See Also
| ========
|
| Ynm_c, Znm
|
| References
| ==========
|
| .. [1] https://en.wikipedia.org/wiki/Spherical_harmonics
| .. [2] http://mathworld.wolfram.com/SphericalHarmonic.html
| .. [3] http://functions.wolfram.com/Polynomials/SphericalHarmonicY/
| .. [4] http://dlmf.nist.gov/14.30
|
| Method resolution order:
| Ynm
| sympy.core.function.Function
| sympy.core.function.Application
| sympy.core.expr.Expr
| sympy.core.basic.Basic
| sympy.printing.defaults.Printable
| sympy.core.evalf.EvalfMixin
| builtins.object
|
| Methods defined here:
|
| as_real_imag(self, deep=True, **hints)
| Performs complex expansion on 'self' and returns a tuple
| containing collected both real and imaginary parts. This
| method can't be confused with re() and im() functions,
| which does not perform complex expansion at evaluation.
|
| However it is possible to expand both re() and im()
| functions and get exactly the same results as with
| a single call to this function.
|
| >>> from sympy import symbols, I
|
| >>> x, y = symbols('x,y', real=True)
|
| >>> (x + y*I).as_real_imag()
| (x, y)
|
| >>> from sympy.abc import z, w
|
| >>> (z + w*I).as_real_imag()
| (re(z) - im(w), re(w) + im(z))
|
| fdiff(self, argindex=4)
| Returns the first derivative of the function.
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| eval(n, m, theta, phi) from sympy.core.function.FunctionClass
| Returns a canonical form of cls applied to arguments args.
|
| Explanation
| ===========
|
| The eval() method is called when the class cls is about to be
| instantiated and it should return either some simplified instance
| (possible of some other class), or if the class cls should be
| unmodified, return None.
|
| Examples of eval() for the function "sign"
| ---------------------------------------------
|
| .. code-block:: python
|
| @classmethod
| def eval(cls, arg):
| if arg is S.NaN:
| return S.NaN
| if arg.is_zero: return S.Zero
| if arg.is_positive: return S.One
| if arg.is_negative: return S.NegativeOne
| if isinstance(arg, Mul):
| coeff, terms = arg.as_coeff_Mul(rational=True)
| if coeff is not S.One:
| return cls(coeff) * cls(terms)
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| __sympy__
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| default_assumptions = {}
|
| ----------------------------------------------------------------------
| Methods inherited from sympy.core.function.Function:
|
| as_base_exp(self)
| Returns the method as the 2-tuple (base, exponent).
|
| ----------------------------------------------------------------------
| Class methods inherited from sympy.core.function.Function:
|
| class_key() from sympy.core.function.FunctionClass
| Nice order of classes.
|
| is_singular(a) from sympy.core.function.FunctionClass
| Tests whether the argument is an essential singularity
| or a branch point, or the functions is non-holomorphic.
|
| ----------------------------------------------------------------------
| Static methods inherited from sympy.core.function.Function:
|
| __new__(cls, *args, **options)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from sympy.core.function.Application:
|
| func
| The top-level function in an expression.
|
| The following should hold for all objects::
|
| >> x == x.func(*x.args)
|
| Examples
| ========
|
| >>> from sympy.abc import x
| >>> a = 2*x
| >>> a.func
| <class 'sympy.core.mul.Mul'>
| >>> a.args
| (2, x)
| >>> a.func(*a.args)
| 2*x
| >>> a == a.func(*a.args)
| True
|
| ----------------------------------------------------------------------
| Data descriptors inherited from sympy.core.function.Application:
|
| __dict__
| dictionary for instance variables (if defined)
|
| __weakref__
| list of weak references to the object (if defined)
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from sympy.core.function.Application:
|
| is_Function = True
|
| ----------------------------------------------------------------------
| Methods inherited from sympy.core.expr.Expr:
|
| __abs__(self)
|
| __add__(self, other)
|
| __complex__(self)
|
| __divmod__(self, other)
|
| __eq__(self, other)
| Return a boolean indicating whether a == b on the basis of
| their symbolic trees.
|
| This is the same as a.compare(b) == 0 but faster.
|
| Notes
| =====
|
| If a class that overrides __eq__() needs to retain the
| implementation of __hash__() from a parent class, the
| interpreter must be told this explicitly by setting __hash__ =
| <ParentClass>.__hash__. Otherwise the inheritance of __hash__()
| will be blocked, just as if __hash__ had been explicitly set to
| None.
|
| References
| ==========
|
| from http://docs.python.org/dev/reference/datamodel.html#object.__hash__
|
| __float__(self)
|
| __floordiv__(self, other)
|
| __ge__(self, other)
| Return self>=value.
|
| __gt__(self, other)
| Return self>value.
|
| __hash__(self) -> int
| Return hash(self).
|
| __int__(self)
|
| __le__(self, other)
| Return self<=value.
|
| __lt__(self, other)
| Return self<value.
|
| __mod__(self, other)
|
| __mul__(self, other)
|
| __neg__(self)
|
| __pos__(self)
|
| __pow__(self, other, mod=None)
|
| __radd__(self, other)
|
| __rdivmod__(self, other)
|
| __rfloordiv__(self, other)
|
| __rmod__(self, other)
|
| __rmul__(self, other)
|
| __round__ = round(self, n=None)
|
| __rpow__(self, other)
|
| __rsub__(self, other)
|
| __rtruediv__(self, other)
|
| __sub__(self, other)
|
| __truediv__(self, other)
|
| __trunc__(self)
|
| adjoint(self)
|
| apart(self, x=None, **args)
| See the apart function in sympy.polys
|
| args_cnc(self, cset=False, warn=True, split_1=True)
| Return [commutative factors, non-commutative factors] of self.
|
| Explanation
| ===========
|
| self is treated as a Mul and the ordering of the factors is maintained.
| If ``cset`` is True the commutative factors will be returned in a set.
| If there were repeated factors (as may happen with an unevaluated Mul)
| then an error will be raised unless it is explicitly suppressed by
| setting ``warn`` to False.
|
| Note: -1 is always separated from a Number unless split_1 is False.
|
| Examples
| ========
|
| >>> from sympy import symbols, oo
| >>> A, B = symbols('A B', commutative=0)
| >>> x, y = symbols('x y')
| >>> (-2*x*y).args_cnc()
| [[-1, 2, x, y], []]
| >>> (-2.5*x).args_cnc()
| [[-1, 2.5, x], []]
| >>> (-2*x*A*B*y).args_cnc()
| [[-1, 2, x, y], [A, B]]
| >>> (-2*x*A*B*y).args_cnc(split_1=False)
| [[-2, x, y], [A, B]]
| >>> (-2*x*y).args_cnc(cset=True)
| [{-1, 2, x, y}, []]
|
| The arg is always treated as a Mul:
|
| >>> (-2 + x + A).args_cnc()
| [[], [x - 2 + A]]
| >>> (-oo).args_cnc() # -oo is a singleton
| [[-1, oo], []]
|
| as_coeff_Add(self, rational=False)
| Efficiently extract the coefficient of a summation.
|
| as_coeff_Mul(self, rational=False)
| Efficiently extract the coefficient of a product.
|
| as_coeff_add(self, *deps)
| Return the tuple (c, args) where self is written as an Add, ``a``.
|
| c should be a Rational added to any terms of the Add that are
| independent of deps.
|
| args should be a tuple of all other terms of ``a``; args is empty
| if self is a Number or if self is independent of deps (when given).
|
| This should be used when you don't know if self is an Add or not but
| you want to treat self as an Add or if you want to process the
| individual arguments of the tail of self as an Add.
|
| - if you know self is an Add and want only the head, use self.args[0];
| - if you don't want to process the arguments of the tail but need the
| tail then use self.as_two_terms() which gives the head and tail.
| - if you want to split self into an independent and dependent parts
| use ``self.as_independent(*deps)``
|
| >>> from sympy import S
| >>> from sympy.abc import x, y
| >>> (S(3)).as_coeff_add()
| (3, ())
| >>> (3 + x).as_coeff_add()
| (3, (x,))
| >>> (3 + x + y).as_coeff_add(x)
| (y + 3, (x,))
| >>> (3 + y).as_coeff_add(x)
| (y + 3, ())
|
| as_coeff_exponent(self, x)
| ``c*x**e -> c,e`` where x can be any symbolic expression.
|
| as_coeff_mul(self, *deps, **kwargs)
| Return the tuple (c, args) where self is written as a Mul, ``m``.
|
| c should be a Rational multiplied by any factors of the Mul that are
| independent of deps.
|
| args should be a tuple of all other factors of m; args is empty
| if self is a Number or if self is independent of deps (when given).
|
| This should be used when you don't know if self is a Mul or not but
| you want to treat self as a Mul or if you want to process the
| individual arguments of the tail of self as a Mul.
|
| - if you know self is a Mul and want only the head, use self.args[0];
| - if you don't want to process the arguments of the tail but need the
| tail then use self.as_two_terms() which gives the head and tail;
| - if you want to split self into an independent and dependent parts
| use ``self.as_independent(*deps)``
|
| >>> from sympy import S
| >>> from sympy.abc import x, y
| >>> (S(3)).as_coeff_mul()
| (3, ())
| >>> (3*x*y).as_coeff_mul()
| (3, (x, y))
| >>> (3*x*y).as_coeff_mul(x)
| (3*y, (x,))
| >>> (3*y).as_coeff_mul(x)
| (3*y, ())
|
| as_coefficient(self, expr)
| Extracts symbolic coefficient at the given expression. In
| other words, this functions separates 'self' into the product
| of 'expr' and 'expr'-free coefficient. If such separation
| is not possible it will return None.
|
| Examples
| ========
|
| >>> from sympy import E, pi, sin, I, Poly
| >>> from sympy.abc import x
|
| >>> E.as_coefficient(E)
| 1
| >>> (2*E).as_coefficient(E)
| 2
| >>> (2*sin(E)*E).as_coefficient(E)
|
| Two terms have E in them so a sum is returned. (If one were
| desiring the coefficient of the term exactly matching E then
| the constant from the returned expression could be selected.
| Or, for greater precision, a method of Poly can be used to
| indicate the desired term from which the coefficient is
| desired.)
|
| >>> (2*E + x*E).as_coefficient(E)
| x + 2
| >>> _.args[0] # just want the exact match
| 2
| >>> p = Poly(2*E + x*E); p
| Poly(x*E + 2*E, x, E, domain='ZZ')
| >>> p.coeff_monomial(E)
| 2
| >>> p.nth(0, 1)
| 2
|
| Since the following cannot be written as a product containing
| E as a factor, None is returned. (If the coefficient ``2*x`` is
| desired then the ``coeff`` method should be used.)
|
| >>> (2*E*x + x).as_coefficient(E)
| >>> (2*E*x + x).coeff(E)
| 2*x
|
| >>> (E*(x + 1) + x).as_coefficient(E)
|
| >>> (2*pi*I).as_coefficient(pi*I)
| 2
| >>> (2*I).as_coefficient(pi*I)
|
| See Also
| ========
|
| coeff: return sum of terms have a given factor
| as_coeff_Add: separate the additive constant from an expression
| as_coeff_Mul: separate the multiplicative constant from an expression
| as_independent: separate x-dependent terms/factors from others
| sympy.polys.polytools.Poly.coeff_monomial: efficiently find the single coefficient of a monomial in Poly
| sympy.polys.polytools.Poly.nth: like coeff_monomial but powers of monomial terms are used
|
| as_coefficients_dict(self)
| Return a dictionary mapping terms to their Rational coefficient.
| Since the dictionary is a defaultdict, inquiries about terms which
| were not present will return a coefficient of 0. If an expression is
| not an Add it is considered to have a single term.
|
| Examples
| ========
|
| >>> from sympy.abc import a, x
| >>> (3*x + a*x + 4).as_coefficients_dict()
| {1: 4, x: 3, a*x: 1}
| >>> _[a]
| 0
| >>> (3*a*x).as_coefficients_dict()
| {a*x: 3}
|
| as_content_primitive(self, radical=False, clear=True)
| This method should recursively remove a Rational from all arguments
| and return that (content) and the new self (primitive). The content
| should always be positive and ``Mul(*foo.as_content_primitive()) == foo``.
| The primitive need not be in canonical form and should try to preserve
| the underlying structure if possible (i.e. expand_mul should not be
| applied to self).
|
| Examples
| ========
|
| >>> from sympy import sqrt
| >>> from sympy.abc import x, y, z
|
| >>> eq = 2 + 2*x + 2*y*(3 + 3*y)
|
| The as_content_primitive function is recursive and retains structure:
|
| >>> eq.as_content_primitive()
| (2, x + 3*y*(y + 1) + 1)
|
| Integer powers will have Rationals extracted from the base:
|
| >>> ((2 + 6*x)**2).as_content_primitive()
| (4, (3*x + 1)**2)
| >>> ((2 + 6*x)**(2*y)).as_content_primitive()
| (1, (2*(3*x + 1))**(2*y))
|
| Terms may end up joining once their as_content_primitives are added:
|
| >>> ((5*(x*(1 + y)) + 2*x*(3 + 3*y))).as_content_primitive()
| (11, x*(y + 1))
| >>> ((3*(x*(1 + y)) + 2*x*(3 + 3*y))).as_content_primitive()
| (9, x*(y + 1))
| >>> ((3*(z*(1 + y)) + 2.0*x*(3 + 3*y))).as_content_primitive()
| (1, 6.0*x*(y + 1) + 3*z*(y + 1))
| >>> ((5*(x*(1 + y)) + 2*x*(3 + 3*y))**2).as_content_primitive()
| (121, x**2*(y + 1)**2)
| >>> ((x*(1 + y) + 0.4*x*(3 + 3*y))**2).as_content_primitive()
| (1, 4.84*x**2*(y + 1)**2)
|
| Radical content can also be factored out of the primitive:
|
| >>> (2*sqrt(2) + 4*sqrt(10)).as_content_primitive(radical=True)
| (2, sqrt(2)*(1 + 2*sqrt(5)))
|
| If clear=False (default is True) then content will not be removed
| from an Add if it can be distributed to leave one or more
| terms with integer coefficients.
|
| >>> (x/2 + y).as_content_primitive()
| (1/2, x + 2*y)
| >>> (x/2 + y).as_content_primitive(clear=False)
| (1, x/2 + y)
|
| as_expr(self, *gens)
| Convert a polynomial to a SymPy expression.
|
| Examples
| ========
|
| >>> from sympy import sin
| >>> from sympy.abc import x, y
|
| >>> f = (x**2 + x*y).as_poly(x, y)
| >>> f.as_expr()
| x**2 + x*y
|
| >>> sin(x).as_expr()
| sin(x)
|
| as_independent(self, *deps, **hint)
| A mostly naive separation of a Mul or Add into arguments that are not
| are dependent on deps. To obtain as complete a separation of variables
| as possible, use a separation method first, e.g.:
|
| * separatevars() to change Mul, Add and Pow (including exp) into Mul
| * .expand(mul=True) to change Add or Mul into Add
| * .expand(log=True) to change log expr into an Add
|
| The only non-naive thing that is done here is to respect noncommutative
| ordering of variables and to always return (0, 0) for `self` of zero
| regardless of hints.
|
| For nonzero `self`, the returned tuple (i, d) has the
| following interpretation:
|
| * i will has no variable that appears in deps
| * d will either have terms that contain variables that are in deps, or
| be equal to 0 (when self is an Add) or 1 (when self is a Mul)
| * if self is an Add then self = i + d
| * if self is a Mul then self = i*d
| * otherwise (self, S.One) or (S.One, self) is returned.
|
| To force the expression to be treated as an Add, use the hint as_Add=True
|
| Examples
| ========
|
| -- self is an Add
|
| >>> from sympy import sin, cos, exp
| >>> from sympy.abc import x, y, z
|
| >>> (x + x*y).as_independent(x)
| (0, x*y + x)
| >>> (x + x*y).as_independent(y)
| (x, x*y)
| >>> (2*x*sin(x) + y + x + z).as_independent(x)
| (y + z, 2*x*sin(x) + x)
| >>> (2*x*sin(x) + y + x + z).as_independent(x, y)
| (z, 2*x*sin(x) + x + y)
|
| -- self is a Mul
|
| >>> (x*sin(x)*cos(y)).as_independent(x)
| (cos(y), x*sin(x))
|
| non-commutative terms cannot always be separated out when self is a Mul
|
| >>> from sympy import symbols
| >>> n1, n2, n3 = symbols('n1 n2 n3', commutative=False)
| >>> (n1 + n1*n2).as_independent(n2)
| (n1, n1*n2)
| >>> (n2*n1 + n1*n2).as_independent(n2)
| (0, n1*n2 + n2*n1)
| >>> (n1*n2*n3).as_independent(n1)
| (1, n1*n2*n3)
| >>> (n1*n2*n3).as_independent(n2)
| (n1, n2*n3)
| >>> ((x-n1)*(x-y)).as_independent(x)
| (1, (x - y)*(x - n1))
|
| -- self is anything else:
|
| >>> (sin(x)).as_independent(x)
| (1, sin(x))
| >>> (sin(x)).as_independent(y)
| (sin(x), 1)
| >>> exp(x+y).as_independent(x)
| (1, exp(x + y))
|
| -- force self to be treated as an Add:
|
| >>> (3*x).as_independent(x, as_Add=True)
| (0, 3*x)
|
| -- force self to be treated as a Mul:
|
| >>> (3+x).as_independent(x, as_Add=False)
| (1, x + 3)
| >>> (-3+x).as_independent(x, as_Add=False)
| (1, x - 3)
|
| Note how the below differs from the above in making the
| constant on the dep term positive.
|
| >>> (y*(-3+x)).as_independent(x)
| (y, x - 3)
|
| -- use .as_independent() for true independence testing instead
| of .has(). The former considers only symbols in the free
| symbols while the latter considers all symbols
|
| >>> from sympy import Integral
| >>> I = Integral(x, (x, 1, 2))
| >>> I.has(x)
| True
| >>> x in I.free_symbols
| False
| >>> I.as_independent(x) == (I, 1)
| True
| >>> (I + x).as_independent(x) == (I, x)
| True
|
| Note: when trying to get independent terms, a separation method
| might need to be used first. In this case, it is important to keep
| track of what you send to this routine so you know how to interpret
| the returned values
|
| >>> from sympy import separatevars, log
| >>> separatevars(exp(x+y)).as_independent(x)
| (exp(y), exp(x))
| >>> (x + x*y).as_independent(y)
| (x, x*y)
| >>> separatevars(x + x*y).as_independent(y)
| (x, y + 1)
| >>> (x*(1 + y)).as_independent(y)
| (x, y + 1)
| >>> (x*(1 + y)).expand(mul=True).as_independent(y)
| (x, x*y)
| >>> a, b=symbols('a b', positive=True)
| >>> (log(a*b).expand(log=True)).as_independent(b)
| (log(a), log(b))
|
| See Also
| ========
| .separatevars(), .expand(log=True), sympy.core.add.Add.as_two_terms(),
| sympy.core.mul.Mul.as_two_terms(), .as_coeff_add(), .as_coeff_mul()
|
| as_leading_term(self, *symbols, cdir=0)
| Returns the leading (nonzero) term of the series expansion of self.
|
| The _eval_as_leading_term routines are used to do this, and they must
| always return a non-zero value.
|
| Examples
| ========
|
| >>> from sympy.abc import x
| >>> (1 + x + x**2).as_leading_term(x)
| 1
| >>> (1/x**2 + x + x**2).as_leading_term(x)
| x**(-2)
|
| as_numer_denom(self)
| expression -> a/b -> a, b
|
| This is just a stub that should be defined by
| an object's class methods to get anything else.
|
| See Also
| ========
|
| normal: return ``a/b`` instead of ``(a, b)``
|
| as_ordered_factors(self, order=None)
| Return list of ordered factors (if Mul) else [self].
|
| as_ordered_terms(self, order=None, data=False)
| Transform an expression to an ordered list of terms.
|
| Examples
| ========
|
| >>> from sympy import sin, cos
| >>> from sympy.abc import x
|
| >>> (sin(x)**2*cos(x) + sin(x)**2 + 1).as_ordered_terms()
| [sin(x)**2*cos(x), sin(x)**2, 1]
|
| as_poly(self, *gens, **args)
| Converts ``self`` to a polynomial or returns ``None``.
|
| Explanation
| ===========
|
| >>> from sympy import sin
| >>> from sympy.abc import x, y
|
| >>> print((x**2 + x*y).as_poly())
| Poly(x**2 + x*y, x, y, domain='ZZ')
|
| >>> print((x**2 + x*y).as_poly(x, y))
| Poly(x**2 + x*y, x, y, domain='ZZ')
|
| >>> print((x**2 + sin(y)).as_poly(x, y))
| None
|
| as_powers_dict(self)
| Return self as a dictionary of factors with each factor being
| treated as a power. The keys are the bases of the factors and the
| values, the corresponding exponents. The resulting dictionary should
| be used with caution if the expression is a Mul and contains non-
| commutative factors since the order that they appeared will be lost in
| the dictionary.
|
| See Also
| ========
| as_ordered_factors: An alternative for noncommutative applications,
| returning an ordered list of factors.
| args_cnc: Similar to as_ordered_factors, but guarantees separation
| of commutative and noncommutative factors.
|
| as_terms(self)
| Transform an expression to a list of terms.
|
| aseries(self, x=None, n=6, bound=0, hir=False)
| Asymptotic Series expansion of self.
| This is equivalent to ``self.series(x, oo, n)``.
|
| Parameters
| ==========
|
| self : Expression
| The expression whose series is to be expanded.
|
| x : Symbol
| It is the variable of the expression to be calculated.
|
| n : Value
| The number of terms upto which the series is to be expanded.
|
| hir : Boolean
| Set this parameter to be True to produce hierarchical series.
| It stops the recursion at an early level and may provide nicer
| and more useful results.
|
| bound : Value, Integer
| Use the ``bound`` parameter to give limit on rewriting
| coefficients in its normalised form.
|
| Examples
| ========
|
| >>> from sympy import sin, exp
| >>> from sympy.abc import x
|
| >>> e = sin(1/x + exp(-x)) - sin(1/x)
|
| >>> e.aseries(x)
| (1/(24*x**4) - 1/(2*x**2) + 1 + O(x**(-6), (x, oo)))*exp(-x)
|
| >>> e.aseries(x, n=3, hir=True)
| -exp(-2*x)*sin(1/x)/2 + exp(-x)*cos(1/x) + O(exp(-3*x), (x, oo))
|
| >>> e = exp(exp(x)/(1 - 1/x))
|
| >>> e.aseries(x)
| exp(exp(x)/(1 - 1/x))
|
| >>> e.aseries(x, bound=3)
| exp(exp(x)/x**2)*exp(exp(x)/x)*exp(-exp(x) + exp(x)/(1 - 1/x) - exp(x)/x - exp(x)/x**2)*exp(exp(x))
|
| Returns
| =======
|
| Expr
| Asymptotic series expansion of the expression.
|
| Notes
| =====
|
| This algorithm is directly induced from the limit computational algorithm provided by Gruntz.
| It majorly uses the mrv and rewrite sub-routines. The overall idea of this algorithm is first
| to look for the most rapidly varying subexpression w of a given expression f and then expands f
| in a series in w. Then same thing is recursively done on the leading coefficient
| till we get constant coefficients.
|
| If the most rapidly varying subexpression of a given expression f is f itself,
| the algorithm tries to find a normalised representation of the mrv set and rewrites f
| using this normalised representation.
|
| If the expansion contains an order term, it will be either ``O(x ** (-n))`` or ``O(w ** (-n))``
| where ``w`` belongs to the most rapidly varying expression of ``self``.
|
| References
| ==========
|
| .. [1] A New Algorithm for Computing Asymptotic Series - Dominik Gruntz
| .. [2] Gruntz thesis - p90
| .. [3] http://en.wikipedia.org/wiki/Asymptotic_expansion
|
| See Also
| ========
|
| Expr.aseries: See the docstring of this function for complete details of this wrapper.
|
| cancel(self, *gens, **args)
| See the cancel function in sympy.polys
|
| coeff(self, x, n=1, right=False)
| Returns the coefficient from the term(s) containing ``x**n``. If ``n``
| is zero then all terms independent of ``x`` will be returned.
|
| Explanation
| ===========
|
| When ``x`` is noncommutative, the coefficient to the left (default) or
| right of ``x`` can be returned. The keyword 'right' is ignored when
| ``x`` is commutative.
|
| Examples
| ========
|
| >>> from sympy import symbols
| >>> from sympy.abc import x, y, z
|
| You can select terms that have an explicit negative in front of them:
|
| >>> (-x + 2*y).coeff(-1)
| x
| >>> (x - 2*y).coeff(-1)
| 2*y
|
| You can select terms with no Rational coefficient:
|
| >>> (x + 2*y).coeff(1)
| x
| >>> (3 + 2*x + 4*x**2).coeff(1)
| 0
|
| You can select terms independent of x by making n=0; in this case
| expr.as_independent(x)[0] is returned (and 0 will be returned instead
| of None):
|
| >>> (3 + 2*x + 4*x**2).coeff(x, 0)
| 3
| >>> eq = ((x + 1)**3).expand() + 1
| >>> eq
| x**3 + 3*x**2 + 3*x + 2
| >>> [eq.coeff(x, i) for i in reversed(range(4))]
| [1, 3, 3, 2]
| >>> eq -= 2
| >>> [eq.coeff(x, i) for i in reversed(range(4))]
| [1, 3, 3, 0]
|
| You can select terms that have a numerical term in front of them:
|
| >>> (-x - 2*y).coeff(2)
| -y
| >>> from sympy import sqrt
| >>> (x + sqrt(2)*x).coeff(sqrt(2))
| x
|
| The matching is exact:
|
| >>> (3 + 2*x + 4*x**2).coeff(x)
| 2
| >>> (3 + 2*x + 4*x**2).coeff(x**2)
| 4
| >>> (3 + 2*x + 4*x**2).coeff(x**3)
| 0
| >>> (z*(x + y)**2).coeff((x + y)**2)
| z
| >>> (z*(x + y)**2).coeff(x + y)
| 0
|
| In addition, no factoring is done, so 1 + z*(1 + y) is not obtained
| from the following:
|
| >>> (x + z*(x + x*y)).coeff(x)
| 1
|
| If such factoring is desired, factor_terms can be used first:
|
| >>> from sympy import factor_terms
| >>> factor_terms(x + z*(x + x*y)).coeff(x)
| z*(y + 1) + 1
|
| >>> n, m, o = symbols('n m o', commutative=False)
| >>> n.coeff(n)
| 1
| >>> (3*n).coeff(n)
| 3
| >>> (n*m + m*n*m).coeff(n) # = (1 + m)*n*m
| 1 + m
| >>> (n*m + m*n*m).coeff(n, right=True) # = (1 + m)*n*m
| m
|
| If there is more than one possible coefficient 0 is returned:
|
| >>> (n*m + m*n).coeff(n)
| 0
|
| If there is only one possible coefficient, it is returned:
|
| >>> (n*m + x*m*n).coeff(m*n)
| x
| >>> (n*m + x*m*n).coeff(m*n, right=1)
| 1
|
| See Also
| ========
|
| as_coefficient: separate the expression into a coefficient and factor
| as_coeff_Add: separate the additive constant from an expression
| as_coeff_Mul: separate the multiplicative constant from an expression
| as_independent: separate x-dependent terms/factors from others
| sympy.polys.polytools.Poly.coeff_monomial: efficiently find the single coefficient of a monomial in Poly
| sympy.polys.polytools.Poly.nth: like coeff_monomial but powers of monomial terms are used
|
| collect(self, syms, func=None, evaluate=True, exact=False, distribute_order_term=True)
| See the collect function in sympy.simplify
|
| combsimp(self)
| See the combsimp function in sympy.simplify
|
| compute_leading_term(self, x, logx=None)
| as_leading_term is only allowed for results of .series()
| This is a wrapper to compute a series first.
|
| conjugate(self)
| Returns the complex conjugate of 'self'.
|
| could_extract_minus_sign(self)
| Return True if self is not in a canonical form with respect
| to its sign.
|
| For most expressions, e, there will be a difference in e and -e.
| When there is, True will be returned for one and False for the
| other; False will be returned if there is no difference.
|
| Examples
| ========
|
| >>> from sympy.abc import x, y
| >>> e = x - y
| >>> {i.could_extract_minus_sign() for i in (e, -e)}
| {False, True}
|
| count_ops(self, visual=None)
| wrapper for count_ops that returns the operation count.
|
| diff(self, *symbols, **assumptions)
|
| dir(self, x, cdir)
|
| equals(self, other, failing_expression=False)
| Return True if self == other, False if it doesn't, or None. If
| failing_expression is True then the expression which did not simplify
| to a 0 will be returned instead of None.
|
| Explanation
| ===========
|
| If ``self`` is a Number (or complex number) that is not zero, then
| the result is False.
|
| If ``self`` is a number and has not evaluated to zero, evalf will be
| used to test whether the expression evaluates to zero. If it does so
| and the result has significance (i.e. the precision is either -1, for
| a Rational result, or is greater than 1) then the evalf value will be
| used to return True or False.
|
| expand(self, deep=True, modulus=None, power_base=True, power_exp=True, mul=True, log=True, multinomial=True, basic=True, **hints)
| Expand an expression using hints.
|
| See the docstring of the expand() function in sympy.core.function for
| more information.
|
| extract_additively(self, c)
| Return self - c if it's possible to subtract c from self and
| make all matching coefficients move towards zero, else return None.
|
| Examples
| ========
|
| >>> from sympy.abc import x, y
| >>> e = 2*x + 3
| >>> e.extract_additively(x + 1)
| x + 2
| >>> e.extract_additively(3*x)
| >>> e.extract_additively(4)
| >>> (y*(x + 1)).extract_additively(x + 1)
| >>> ((x + 1)*(x + 2*y + 1) + 3).extract_additively(x + 1)
| (x + 1)*(x + 2*y) + 3
|
| Sometimes auto-expansion will return a less simplified result
| than desired; gcd_terms might be used in such cases:
|
| >>> from sympy import gcd_terms
| >>> (4*x*(y + 1) + y).extract_additively(x)
| 4*x*(y + 1) + x*(4*y + 3) - x*(4*y + 4) + y
| >>> gcd_terms(_)
| x*(4*y + 3) + y
|
| See Also
| ========
| extract_multiplicatively
| coeff
| as_coefficient
|
| extract_branch_factor(self, allow_half=False)
| Try to write self as ``exp_polar(2*pi*I*n)*z`` in a nice way.
| Return (z, n).
|
| >>> from sympy import exp_polar, I, pi
| >>> from sympy.abc import x, y
| >>> exp_polar(I*pi).extract_branch_factor()
| (exp_polar(I*pi), 0)
| >>> exp_polar(2*I*pi).extract_branch_factor()
| (1, 1)
| >>> exp_polar(-pi*I).extract_branch_factor()
| (exp_polar(I*pi), -1)
| >>> exp_polar(3*pi*I + x).extract_branch_factor()
| (exp_polar(x + I*pi), 1)
| >>> (y*exp_polar(-5*pi*I)*exp_polar(3*pi*I + 2*pi*x)).extract_branch_factor()
| (y*exp_polar(2*pi*x), -1)
| >>> exp_polar(-I*pi/2).extract_branch_factor()
| (exp_polar(-I*pi/2), 0)
|
| If allow_half is True, also extract exp_polar(I*pi):
|
| >>> exp_polar(I*pi).extract_branch_factor(allow_half=True)
| (1, 1/2)
| >>> exp_polar(2*I*pi).extract_branch_factor(allow_half=True)
| (1, 1)
| >>> exp_polar(3*I*pi).extract_branch_factor(allow_half=True)
| (1, 3/2)
| >>> exp_polar(-I*pi).extract_branch_factor(allow_half=True)
| (1, -1/2)
|
| extract_multiplicatively(self, c)
| Return None if it's not possible to make self in the form
| c * something in a nice way, i.e. preserving the properties
| of arguments of self.
|
| Examples
| ========
|
| >>> from sympy import symbols, Rational
|
| >>> x, y = symbols('x,y', real=True)
|
| >>> ((x*y)**3).extract_multiplicatively(x**2 * y)
| x*y**2
|
| >>> ((x*y)**3).extract_multiplicatively(x**4 * y)
|
| >>> (2*x).extract_multiplicatively(2)
| x
|
| >>> (2*x).extract_multiplicatively(3)
|
| >>> (Rational(1, 2)*x).extract_multiplicatively(3)
| x/6
|
| factor(self, *gens, **args)
| See the factor() function in sympy.polys.polytools
|
| fourier_series(self, limits=None)
| Compute fourier sine/cosine series of self.
|
| See the docstring of the :func:`fourier_series` in sympy.series.fourier
| for more information.
|
| fps(self, x=None, x0=0, dir=1, hyper=True, order=4, rational=True, full=False)
| Compute formal power power series of self.
|
| See the docstring of the :func:`fps` function in sympy.series.formal for
| more information.
|
| gammasimp(self)
| See the gammasimp function in sympy.simplify
|
| getO(self)
| Returns the additive O(..) symbol if there is one, else None.
|
| getn(self)
| Returns the order of the expression.
|
| Explanation
| ===========
|
| The order is determined either from the O(...) term. If there
| is no O(...) term, it returns None.
|
| Examples
| ========
|
| >>> from sympy import O
| >>> from sympy.abc import x
| >>> (1 + x + O(x**2)).getn()
| 2
| >>> (1 + x).getn()
|
| integrate(self, *args, **kwargs)
| See the integrate function in sympy.integrals
|
| invert(self, g, *gens, **args)
| Return the multiplicative inverse of ``self`` mod ``g``
| where ``self`` (and ``g``) may be symbolic expressions).
|
| See Also
| ========
| sympy.core.numbers.mod_inverse, sympy.polys.polytools.invert
|
| is_algebraic_expr(self, *syms)
| This tests whether a given expression is algebraic or not, in the
| given symbols, syms. When syms is not given, all free symbols
| will be used. The rational function does not have to be in expanded
| or in any kind of canonical form.
|
| This function returns False for expressions that are "algebraic
| expressions" with symbolic exponents. This is a simple extension to the
| is_rational_function, including rational exponentiation.
|
| Examples
| ========
|
| >>> from sympy import Symbol, sqrt
| >>> x = Symbol('x', real=True)
| >>> sqrt(1 + x).is_rational_function()
| False
| >>> sqrt(1 + x).is_algebraic_expr()
| True
|
| This function does not attempt any nontrivial simplifications that may
| result in an expression that does not appear to be an algebraic
| expression to become one.
|
| >>> from sympy import exp, factor
| >>> a = sqrt(exp(x)**2 + 2*exp(x) + 1)/(exp(x) + 1)
| >>> a.is_algebraic_expr(x)
| False
| >>> factor(a).is_algebraic_expr()
| True
|
| See Also
| ========
| is_rational_function()
|
| References
| ==========
|
| - https://en.wikipedia.org/wiki/Algebraic_expression
|
| is_constant(self, *wrt, **flags)
| Return True if self is constant, False if not, or None if
| the constancy could not be determined conclusively.
|
| Explanation
| ===========
|
| If an expression has no free symbols then it is a constant. If
| there are free symbols it is possible that the expression is a
| constant, perhaps (but not necessarily) zero. To test such
| expressions, a few strategies are tried:
|
| 1) numerical evaluation at two random points. If two such evaluations
| give two different values and the values have a precision greater than
| 1 then self is not constant. If the evaluations agree or could not be
| obtained with any precision, no decision is made. The numerical testing
| is done only if ``wrt`` is different than the free symbols.
|
| 2) differentiation with respect to variables in 'wrt' (or all free
| symbols if omitted) to see if the expression is constant or not. This
| will not always lead to an expression that is zero even though an
| expression is constant (see added test in test_expr.py). If
| all derivatives are zero then self is constant with respect to the
| given symbols.
|
| 3) finding out zeros of denominator expression with free_symbols.
| It won't be constant if there are zeros. It gives more negative
| answers for expression that are not constant.
|
| If neither evaluation nor differentiation can prove the expression is
| constant, None is returned unless two numerical values happened to be
| the same and the flag ``failing_number`` is True -- in that case the
| numerical value will be returned.
|
| If flag simplify=False is passed, self will not be simplified;
| the default is True since self should be simplified before testing.
|
| Examples
| ========
|
| >>> from sympy import cos, sin, Sum, S, pi
| >>> from sympy.abc import a, n, x, y
| >>> x.is_constant()
| False
| >>> S(2).is_constant()
| True
| >>> Sum(x, (x, 1, 10)).is_constant()
| True
| >>> Sum(x, (x, 1, n)).is_constant()
| False
| >>> Sum(x, (x, 1, n)).is_constant(y)
| True
| >>> Sum(x, (x, 1, n)).is_constant(n)
| False
| >>> Sum(x, (x, 1, n)).is_constant(x)
| True
| >>> eq = a*cos(x)**2 + a*sin(x)**2 - a
| >>> eq.is_constant()
| True
| >>> eq.subs({x: pi, a: 2}) == eq.subs({x: pi, a: 3}) == 0
| True
|
| >>> (0**x).is_constant()
| False
| >>> x.is_constant()
| False
| >>> (x**x).is_constant()
| False
| >>> one = cos(x)**2 + sin(x)**2
| >>> one.is_constant()
| True
| >>> ((one - 1)**(x + 1)).is_constant() in (True, False) # could be 0 or 1
| True
|
| is_meromorphic(self, x, a)
| This tests whether an expression is meromorphic as
| a function of the given symbol ``x`` at the point ``a``.
|
| This method is intended as a quick test that will return
| None if no decision can be made without simplification or
| more detailed analysis.
|
| Examples
| ========
|
| >>> from sympy import zoo, log, sin, sqrt
| >>> from sympy.abc import x
|
| >>> f = 1/x**2 + 1 - 2*x**3
| >>> f.is_meromorphic(x, 0)
| True
| >>> f.is_meromorphic(x, 1)
| True
| >>> f.is_meromorphic(x, zoo)
| True
|
| >>> g = x**log(3)
| >>> g.is_meromorphic(x, 0)
| False
| >>> g.is_meromorphic(x, 1)
| True
| >>> g.is_meromorphic(x, zoo)
| False
|
| >>> h = sin(1/x)*x**2
| >>> h.is_meromorphic(x, 0)
| False
| >>> h.is_meromorphic(x, 1)
| True
| >>> h.is_meromorphic(x, zoo)
| True
|
| Multivalued functions are considered meromorphic when their
| branches are meromorphic. Thus most functions are meromorphic
| everywhere except at essential singularities and branch points.
| In particular, they will be meromorphic also on branch cuts
| except at their endpoints.
|
| >>> log(x).is_meromorphic(x, -1)
| True
| >>> log(x).is_meromorphic(x, 0)
| False
| >>> sqrt(x).is_meromorphic(x, -1)
| True
| >>> sqrt(x).is_meromorphic(x, 0)
| False
|
| is_polynomial(self, *syms)
| Return True if self is a polynomial in syms and False otherwise.
|
| This checks if self is an exact polynomial in syms. This function
| returns False for expressions that are "polynomials" with symbolic
| exponents. Thus, you should be able to apply polynomial algorithms to
| expressions for which this returns True, and Poly(expr, \*syms) should
| work if and only if expr.is_polynomial(\*syms) returns True. The
| polynomial does not have to be in expanded form. If no symbols are
| given, all free symbols in the expression will be used.
|
| This is not part of the assumptions system. You cannot do
| Symbol('z', polynomial=True).
|
| Examples
| ========
|
| >>> from sympy import Symbol
| >>> x = Symbol('x')
| >>> ((x**2 + 1)**4).is_polynomial(x)
| True
| >>> ((x**2 + 1)**4).is_polynomial()
| True
| >>> (2**x + 1).is_polynomial(x)
| False
|
|
| >>> n = Symbol('n', nonnegative=True, integer=True)
| >>> (x**n + 1).is_polynomial(x)
| False
|
| This function does not attempt any nontrivial simplifications that may
| result in an expression that does not appear to be a polynomial to
| become one.
|
| >>> from sympy import sqrt, factor, cancel
| >>> y = Symbol('y', positive=True)
| >>> a = sqrt(y**2 + 2*y + 1)
| >>> a.is_polynomial(y)
| False
| >>> factor(a)
| y + 1
| >>> factor(a).is_polynomial(y)
| True
|
| >>> b = (y**2 + 2*y + 1)/(y + 1)
| >>> b.is_polynomial(y)
| False
| >>> cancel(b)
| y + 1
| >>> cancel(b).is_polynomial(y)
| True
|
| See also .is_rational_function()
|
| is_rational_function(self, *syms)
| Test whether function is a ratio of two polynomials in the given
| symbols, syms. When syms is not given, all free symbols will be used.
| The rational function does not have to be in expanded or in any kind of
| canonical form.
|
| This function returns False for expressions that are "rational
| functions" with symbolic exponents. Thus, you should be able to call
| .as_numer_denom() and apply polynomial algorithms to the result for
| expressions for which this returns True.
|
| This is not part of the assumptions system. You cannot do
| Symbol('z', rational_function=True).
|
| Examples
| ========
|
| >>> from sympy import Symbol, sin
| >>> from sympy.abc import x, y
|
| >>> (x/y).is_rational_function()
| True
|
| >>> (x**2).is_rational_function()
| True
|
| >>> (x/sin(y)).is_rational_function(y)
| False
|
| >>> n = Symbol('n', integer=True)
| >>> (x**n + 1).is_rational_function(x)
| False
|
| This function does not attempt any nontrivial simplifications that may
| result in an expression that does not appear to be a rational function
| to become one.
|
| >>> from sympy import sqrt, factor
| >>> y = Symbol('y', positive=True)
| >>> a = sqrt(y**2 + 2*y + 1)/y
| >>> a.is_rational_function(y)
| False
| >>> factor(a)
| (y + 1)/y
| >>> factor(a).is_rational_function(y)
| True
|
| See also is_algebraic_expr().
|
| leadterm(self, x, cdir=0)
| Returns the leading term a*x**b as a tuple (a, b).
|
| Examples
| ========
|
| >>> from sympy.abc import x
| >>> (1+x+x**2).leadterm(x)
| (1, 0)
| >>> (1/x**2+x+x**2).leadterm(x)
| (1, -2)
|
| limit(self, x, xlim, dir='+')
| Compute limit x->xlim.
|
| lseries(self, x=None, x0=0, dir='+', logx=None, cdir=0)
| Wrapper for series yielding an iterator of the terms of the series.
|
| Note: an infinite series will yield an infinite iterator. The following,
| for exaxmple, will never terminate. It will just keep printing terms
| of the sin(x) series::
|
| for term in sin(x).lseries(x):
| print term
|
| The advantage of lseries() over nseries() is that many times you are
| just interested in the next term in the series (i.e. the first term for
| example), but you don't know how many you should ask for in nseries()
| using the "n" parameter.
|
| See also nseries().
|
| normal(self)
| expression -> a/b
|
| See Also
| ========
|
| as_numer_denom: return ``(a, b)`` instead of ``a/b``
|
| nseries(self, x=None, x0=0, n=6, dir='+', logx=None, cdir=0)
| Wrapper to _eval_nseries if assumptions allow, else to series.
|
| If x is given, x0 is 0, dir='+', and self has x, then _eval_nseries is
| called. This calculates "n" terms in the innermost expressions and
| then builds up the final series just by "cross-multiplying" everything
| out.
|
| The optional ``logx`` parameter can be used to replace any log(x) in the
| returned series with a symbolic value to avoid evaluating log(x) at 0. A
| symbol to use in place of log(x) should be provided.
|
| Advantage -- it's fast, because we don't have to determine how many
| terms we need to calculate in advance.
|
| Disadvantage -- you may end up with less terms than you may have
| expected, but the O(x**n) term appended will always be correct and
| so the result, though perhaps shorter, will also be correct.
|
| If any of those assumptions is not met, this is treated like a
| wrapper to series which will try harder to return the correct
| number of terms.
|
| See also lseries().
|
| Examples
| ========
|
| >>> from sympy import sin, log, Symbol
| >>> from sympy.abc import x, y
| >>> sin(x).nseries(x, 0, 6)
| x - x**3/6 + x**5/120 + O(x**6)
| >>> log(x+1).nseries(x, 0, 5)
| x - x**2/2 + x**3/3 - x**4/4 + O(x**5)
|
| Handling of the ``logx`` parameter --- in the following example the
| expansion fails since ``sin`` does not have an asymptotic expansion
| at -oo (the limit of log(x) as x approaches 0):
|
| >>> e = sin(log(x))
| >>> e.nseries(x, 0, 6)
| Traceback (most recent call last):
| ...
| PoleError: ...
| ...
| >>> logx = Symbol('logx')
| >>> e.nseries(x, 0, 6, logx=logx)
| sin(logx)
|
| In the following example, the expansion works but gives only an Order term
| unless the ``logx`` parameter is used:
|
| >>> e = x**y
| >>> e.nseries(x, 0, 2)
| O(log(x)**2)
| >>> e.nseries(x, 0, 2, logx=logx)
| exp(logx*y)
|
| nsimplify(self, constants=[], tolerance=None, full=False)
| See the nsimplify function in sympy.simplify
|
| powsimp(self, *args, **kwargs)
| See the powsimp function in sympy.simplify
|
| primitive(self)
| Return the positive Rational that can be extracted non-recursively
| from every term of self (i.e., self is treated like an Add). This is
| like the as_coeff_Mul() method but primitive always extracts a positive
| Rational (never a negative or a Float).
|
| Examples
| ========
|
| >>> from sympy.abc import x
| >>> (3*(x + 1)**2).primitive()
| (3, (x + 1)**2)
| >>> a = (6*x + 2); a.primitive()
| (2, 3*x + 1)
| >>> b = (x/2 + 3); b.primitive()
| (1/2, x + 6)
| >>> (a*b).primitive() == (1, a*b)
| True
|
| radsimp(self, **kwargs)
| See the radsimp function in sympy.simplify
|
| ratsimp(self)
| See the ratsimp function in sympy.simplify
|
| removeO(self)
| Removes the additive O(..) symbol if there is one
|
| round(self, n=None)
| Return x rounded to the given decimal place.
|
| If a complex number would results, apply round to the real
| and imaginary components of the number.
|
| Examples
| ========
|
| >>> from sympy import pi, E, I, S, Number
| >>> pi.round()
| 3
| >>> pi.round(2)
| 3.14
| >>> (2*pi + E*I).round()
| 6 + 3*I
|
| The round method has a chopping effect:
|
| >>> (2*pi + I/10).round()
| 6
| >>> (pi/10 + 2*I).round()
| 2*I
| >>> (pi/10 + E*I).round(2)
| 0.31 + 2.72*I
|
| Notes
| =====
|
| The Python ``round`` function uses the SymPy ``round`` method so it
| will always return a SymPy number (not a Python float or int):
|
| >>> isinstance(round(S(123), -2), Number)
| True
|
| separate(self, deep=False, force=False)
| See the separate function in sympy.simplify
|
| series(self, x=None, x0=0, n=6, dir='+', logx=None, cdir=0)
| Series expansion of "self" around ``x = x0`` yielding either terms of
| the series one by one (the lazy series given when n=None), else
| all the terms at once when n != None.
|
| Returns the series expansion of "self" around the point ``x = x0``
| with respect to ``x`` up to ``O((x - x0)**n, x, x0)`` (default n is 6).
|
| If ``x=None`` and ``self`` is univariate, the univariate symbol will
| be supplied, otherwise an error will be raised.
|
| Parameters
| ==========
|
| expr : Expression
| The expression whose series is to be expanded.
|
| x : Symbol
| It is the variable of the expression to be calculated.
|
| x0 : Value
| The value around which ``x`` is calculated. Can be any value
| from ``-oo`` to ``oo``.
|
| n : Value
| The number of terms upto which the series is to be expanded.
|
| dir : String, optional
| The series-expansion can be bi-directional. If ``dir="+"``,
| then (x->x0+). If ``dir="-", then (x->x0-). For infinite
| ``x0`` (``oo`` or ``-oo``), the ``dir`` argument is determined
| from the direction of the infinity (i.e., ``dir="-"`` for
| ``oo``).
|
| logx : optional
| It is used to replace any log(x) in the returned series with a
| symbolic value rather than evaluating the actual value.
|
| cdir : optional
| It stands for complex direction, and indicates the direction
| from which the expansion needs to be evaluated.
|
| Examples
| ========
|
| >>> from sympy import cos, exp, tan
| >>> from sympy.abc import x, y
| >>> cos(x).series()
| 1 - x**2/2 + x**4/24 + O(x**6)
| >>> cos(x).series(n=4)
| 1 - x**2/2 + O(x**4)
| >>> cos(x).series(x, x0=1, n=2)
| cos(1) - (x - 1)*sin(1) + O((x - 1)**2, (x, 1))
| >>> e = cos(x + exp(y))
| >>> e.series(y, n=2)
| cos(x + 1) - y*sin(x + 1) + O(y**2)
| >>> e.series(x, n=2)
| cos(exp(y)) - x*sin(exp(y)) + O(x**2)
|
| If ``n=None`` then a generator of the series terms will be returned.
|
| >>> term=cos(x).series(n=None)
| >>> [next(term) for i in range(2)]
| [1, -x**2/2]
|
| For ``dir=+`` (default) the series is calculated from the right and
| for ``dir=-`` the series from the left. For smooth functions this
| flag will not alter the results.
|
| >>> abs(x).series(dir="+")
| x
| >>> abs(x).series(dir="-")
| -x
| >>> f = tan(x)
| >>> f.series(x, 2, 6, "+")
| tan(2) + (1 + tan(2)**2)*(x - 2) + (x - 2)**2*(tan(2)**3 + tan(2)) +
| (x - 2)**3*(1/3 + 4*tan(2)**2/3 + tan(2)**4) + (x - 2)**4*(tan(2)**5 +
| 5*tan(2)**3/3 + 2*tan(2)/3) + (x - 2)**5*(2/15 + 17*tan(2)**2/15 +
| 2*tan(2)**4 + tan(2)**6) + O((x - 2)**6, (x, 2))
|
| >>> f.series(x, 2, 3, "-")
| tan(2) + (2 - x)*(-tan(2)**2 - 1) + (2 - x)**2*(tan(2)**3 + tan(2))
| + O((x - 2)**3, (x, 2))
|
| Returns
| =======
|
| Expr : Expression
| Series expansion of the expression about x0
|
| Raises
| ======
|
| TypeError
| If "n" and "x0" are infinity objects
|
| PoleError
| If "x0" is an infinity object
|
| sort_key(self, order=None)
| Return a sort key.
|
| Examples
| ========
|
| >>> from sympy.core import S, I
|
| >>> sorted([S(1)/2, I, -I], key=lambda x: x.sort_key())
| [1/2, -I, I]
|
| >>> S("[x, 1/x, 1/x**2, x**2, x**(1/2), x**(1/4), x**(3/2)]")
| [x, 1/x, x**(-2), x**2, sqrt(x), x**(1/4), x**(3/2)]
| >>> sorted(_, key=lambda x: x.sort_key())
| [x**(-2), 1/x, x**(1/4), sqrt(x), x, x**(3/2), x**2]
|
| taylor_term(self, n, x, *previous_terms)
| General method for the taylor term.
|
| This method is slow, because it differentiates n-times. Subclasses can
| redefine it to make it faster by using the "previous_terms".
|
| together(self, *args, **kwargs)
| See the together function in sympy.polys
|
| transpose(self)
|
| trigsimp(self, **args)
| See the trigsimp function in sympy.simplify
|
| ----------------------------------------------------------------------
| Readonly properties inherited from sympy.core.expr.Expr:
|
| expr_free_symbols
| Like ``free_symbols``, but returns the free symbols only if they are contained in an expression node.
|
| Examples
| ========
|
| >>> from sympy.abc import x, y
| >>> (x + y).expr_free_symbols
| {x, y}
|
| If the expression is contained in a non-expression object, don't return
| the free symbols. Compare:
|
| >>> from sympy import Tuple
| >>> t = Tuple(x + y)
| >>> t.expr_free_symbols
| set()
| >>> t.free_symbols
| {x, y}
|
| is_number
| Returns True if ``self`` has no free symbols and no
| undefined functions (AppliedUndef, to be precise). It will be
| faster than ``if not self.free_symbols``, however, since
| ``is_number`` will fail as soon as it hits a free symbol
| or undefined function.
|
| Examples
| ========
|
| >>> from sympy import Integral, cos, sin, pi
| >>> from sympy.core.function import Function
| >>> from sympy.abc import x
| >>> f = Function('f')
|
| >>> x.is_number
| False
| >>> f(1).is_number
| False
| >>> (2*x).is_number
| False
| >>> (2 + Integral(2, x)).is_number
| False
| >>> (2 + Integral(2, (x, 1, 2))).is_number
| True
|
| Not all numbers are Numbers in the SymPy sense:
|
| >>> pi.is_number, pi.is_Number
| (True, False)
|
| If something is a number it should evaluate to a number with
| real and imaginary parts that are Numbers; the result may not
| be comparable, however, since the real and/or imaginary part
| of the result may not have precision.
|
| >>> cos(1).is_number and cos(1).is_comparable
| True
|
| >>> z = cos(1)**2 + sin(1)**2 - 1
| >>> z.is_number
| True
| >>> z.is_comparable
| False
|
| See Also
| ========
|
| sympy.core.basic.Basic.is_comparable
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from sympy.core.expr.Expr:
|
| is_scalar = True
|
| ----------------------------------------------------------------------
| Methods inherited from sympy.core.basic.Basic:
|
| __getnewargs__(self)
|
| __getstate__(self)
|
| __ne__(self, other)
| ``a != b`` -> Compare two symbolic trees and see whether they are different
|
| this is the same as:
|
| ``a.compare(b) != 0``
|
| but faster
|
| __reduce_ex__(self, proto)
| Pickling support.
|
| __setstate__(self, state)
|
| as_dummy(self)
| Return the expression with any objects having structurally
| bound symbols replaced with unique, canonical symbols within
| the object in which they appear and having only the default
| assumption for commutativity being True. When applied to a
| symbol a new symbol having only the same commutativity will be
| returned.
|
| Examples
| ========
|
| >>> from sympy import Integral, Symbol
| >>> from sympy.abc import x
| >>> r = Symbol('r', real=True)
| >>> Integral(r, (r, x)).as_dummy()
| Integral(_0, (_0, x))
| >>> _.variables[0].is_real is None
| True
| >>> r.as_dummy()
| _r
|
| Notes
| =====
|
| Any object that has structurally bound variables should have
| a property, `bound_symbols` that returns those symbols
| appearing in the object.
|
| atoms(self, *types)
| Returns the atoms that form the current object.
|
| By default, only objects that are truly atomic and can't
| be divided into smaller pieces are returned: symbols, numbers,
| and number symbols like I and pi. It is possible to request
| atoms of any type, however, as demonstrated below.
|
| Examples
| ========
|
| >>> from sympy import I, pi, sin
| >>> from sympy.abc import x, y
| >>> (1 + x + 2*sin(y + I*pi)).atoms()
| {1, 2, I, pi, x, y}
|
| If one or more types are given, the results will contain only
| those types of atoms.
|
| >>> from sympy import Number, NumberSymbol, Symbol
| >>> (1 + x + 2*sin(y + I*pi)).atoms(Symbol)
| {x, y}
|
| >>> (1 + x + 2*sin(y + I*pi)).atoms(Number)
| {1, 2}
|
| >>> (1 + x + 2*sin(y + I*pi)).atoms(Number, NumberSymbol)
| {1, 2, pi}
|
| >>> (1 + x + 2*sin(y + I*pi)).atoms(Number, NumberSymbol, I)
| {1, 2, I, pi}
|
| Note that I (imaginary unit) and zoo (complex infinity) are special
| types of number symbols and are not part of the NumberSymbol class.
|
| The type can be given implicitly, too:
|
| >>> (1 + x + 2*sin(y + I*pi)).atoms(x) # x is a Symbol
| {x, y}
|
| Be careful to check your assumptions when using the implicit option
| since ``S(1).is_Integer = True`` but ``type(S(1))`` is ``One``, a special type
| of sympy atom, while ``type(S(2))`` is type ``Integer`` and will find all
| integers in an expression:
|
| >>> from sympy import S
| >>> (1 + x + 2*sin(y + I*pi)).atoms(S(1))
| {1}
|
| >>> (1 + x + 2*sin(y + I*pi)).atoms(S(2))
| {1, 2}
|
| Finally, arguments to atoms() can select more than atomic atoms: any
| sympy type (loaded in core/__init__.py) can be listed as an argument
| and those types of "atoms" as found in scanning the arguments of the
| expression recursively:
|
| >>> from sympy import Function, Mul
| >>> from sympy.core.function import AppliedUndef
| >>> f = Function('f')
| >>> (1 + f(x) + 2*sin(y + I*pi)).atoms(Function)
| {f(x), sin(y + I*pi)}
| >>> (1 + f(x) + 2*sin(y + I*pi)).atoms(AppliedUndef)
| {f(x)}
|
| >>> (1 + x + 2*sin(y + I*pi)).atoms(Mul)
| {I*pi, 2*sin(y + I*pi)}
|
| compare(self, other)
| Return -1, 0, 1 if the object is smaller, equal, or greater than other.
|
| Not in the mathematical sense. If the object is of a different type
| from the "other" then their classes are ordered according to
| the sorted_classes list.
|
| Examples
| ========
|
| >>> from sympy.abc import x, y
| >>> x.compare(y)
| -1
| >>> x.compare(x)
| 0
| >>> y.compare(x)
| 1
|
| copy(self)
|
| count(self, query)
| Count the number of matching subexpressions.
|
| doit(self, **hints)
| Evaluate objects that are not evaluated by default like limits,
| integrals, sums and products. All objects of this kind will be
| evaluated recursively, unless some species were excluded via 'hints'
| or unless the 'deep' hint was set to 'False'.
|
| >>> from sympy import Integral
| >>> from sympy.abc import x
|
| >>> 2*Integral(x, x)
| 2*Integral(x, x)
|
| >>> (2*Integral(x, x)).doit()
| x**2
|
| >>> (2*Integral(x, x)).doit(deep=False)
| 2*Integral(x, x)
|
| dummy_eq(self, other, symbol=None)
| Compare two expressions and handle dummy symbols.
|
| Examples
| ========
|
| >>> from sympy import Dummy
| >>> from sympy.abc import x, y
|
| >>> u = Dummy('u')
|
| >>> (u**2 + 1).dummy_eq(x**2 + 1)
| True
| >>> (u**2 + 1) == (x**2 + 1)
| False
|
| >>> (u**2 + y).dummy_eq(x**2 + y, x)
| True
| >>> (u**2 + y).dummy_eq(x**2 + y, y)
| False
|
| find(self, query, group=False)
| Find all subexpressions matching a query.
|
| has(self, *patterns)
| Test whether any subexpression matches any of the patterns.
|
| Examples
| ========
|
| >>> from sympy import sin
| >>> from sympy.abc import x, y, z
| >>> (x**2 + sin(x*y)).has(z)
| False
| >>> (x**2 + sin(x*y)).has(x, y, z)
| True
| >>> x.has(x)
| True
|
| Note ``has`` is a structural algorithm with no knowledge of
| mathematics. Consider the following half-open interval:
|
| >>> from sympy.sets import Interval
| >>> i = Interval.Lopen(0, 5); i
| Interval.Lopen(0, 5)
| >>> i.args
| (0, 5, True, False)
| >>> i.has(4) # there is no "4" in the arguments
| False
| >>> i.has(0) # there *is* a "0" in the arguments
| True
|
| Instead, use ``contains`` to determine whether a number is in the
| interval or not:
|
| >>> i.contains(4)
| True
| >>> i.contains(0)
| False
|
|
| Note that ``expr.has(*patterns)`` is exactly equivalent to
| ``any(expr.has(p) for p in patterns)``. In particular, ``False`` is
| returned when the list of patterns is empty.
|
| >>> x.has()
| False
|
| is_hypergeometric(self, k)
|
| match(self, pattern, old=False)
| Pattern matching.
|
| Wild symbols match all.
|
| Return ``None`` when expression (self) does not match
| with pattern. Otherwise return a dictionary such that::
|
| pattern.xreplace(self.match(pattern)) == self
|
| Examples
| ========
|
| >>> from sympy import Wild, Sum
| >>> from sympy.abc import x, y
| >>> p = Wild("p")
| >>> q = Wild("q")
| >>> r = Wild("r")
| >>> e = (x+y)**(x+y)
| >>> e.match(p**p)
| {p_: x + y}
| >>> e.match(p**q)
| {p_: x + y, q_: x + y}
| >>> e = (2*x)**2
| >>> e.match(p*q**r)
| {p_: 4, q_: x, r_: 2}
| >>> (p*q**r).xreplace(e.match(p*q**r))
| 4*x**2
|
| Structurally bound symbols are ignored during matching:
|
| >>> Sum(x, (x, 1, 2)).match(Sum(y, (y, 1, p)))
| {p_: 2}
|
| But they can be identified if desired:
|
| >>> Sum(x, (x, 1, 2)).match(Sum(q, (q, 1, p)))
| {p_: 2, q_: x}
|
| The ``old`` flag will give the old-style pattern matching where
| expressions and patterns are essentially solved to give the
| match. Both of the following give None unless ``old=True``:
|
| >>> (x - 2).match(p - x, old=True)
| {p_: 2*x - 2}
| >>> (2/x).match(p*x, old=True)
| {p_: 2/x**2}
|
| matches(self, expr, repl_dict={}, old=False)
| Helper method for match() that looks for a match between Wild symbols
| in self and expressions in expr.
|
| Examples
| ========
|
| >>> from sympy import symbols, Wild, Basic
| >>> a, b, c = symbols('a b c')
| >>> x = Wild('x')
| >>> Basic(a + x, x).matches(Basic(a + b, c)) is None
| True
| >>> Basic(a + x, x).matches(Basic(a + b + c, b + c))
| {x_: b + c}
|
| rcall(self, *args)
| Apply on the argument recursively through the expression tree.
|
| This method is used to simulate a common abuse of notation for
| operators. For instance in SymPy the the following will not work:
|
| ``(x+Lambda(y, 2*y))(z) == x+2*z``,
|
| however you can use
|
| >>> from sympy import Lambda
| >>> from sympy.abc import x, y, z
| >>> (x + Lambda(y, 2*y)).rcall(z)
| x + 2*z
|
| refine(self, assumption=True)
| See the refine function in sympy.assumptions
|
| replace(self, query, value, map=False, simultaneous=True, exact=None)
| Replace matching subexpressions of ``self`` with ``value``.
|
| If ``map = True`` then also return the mapping {old: new} where ``old``
| was a sub-expression found with query and ``new`` is the replacement
| value for it. If the expression itself doesn't match the query, then
| the returned value will be ``self.xreplace(map)`` otherwise it should
| be ``self.subs(ordered(map.items()))``.
|
| Traverses an expression tree and performs replacement of matching
| subexpressions from the bottom to the top of the tree. The default
| approach is to do the replacement in a simultaneous fashion so
| changes made are targeted only once. If this is not desired or causes
| problems, ``simultaneous`` can be set to False.
|
| In addition, if an expression containing more than one Wild symbol
| is being used to match subexpressions and the ``exact`` flag is None
| it will be set to True so the match will only succeed if all non-zero
| values are received for each Wild that appears in the match pattern.
| Setting this to False accepts a match of 0; while setting it True
| accepts all matches that have a 0 in them. See example below for
| cautions.
|
| The list of possible combinations of queries and replacement values
| is listed below:
|
| Examples
| ========
|
| Initial setup
|
| >>> from sympy import log, sin, cos, tan, Wild, Mul, Add
| >>> from sympy.abc import x, y
| >>> f = log(sin(x)) + tan(sin(x**2))
|
| 1.1. type -> type
| obj.replace(type, newtype)
|
| When object of type ``type`` is found, replace it with the
| result of passing its argument(s) to ``newtype``.
|
| >>> f.replace(sin, cos)
| log(cos(x)) + tan(cos(x**2))
| >>> sin(x).replace(sin, cos, map=True)
| (cos(x), {sin(x): cos(x)})
| >>> (x*y).replace(Mul, Add)
| x + y
|
| 1.2. type -> func
| obj.replace(type, func)
|
| When object of type ``type`` is found, apply ``func`` to its
| argument(s). ``func`` must be written to handle the number
| of arguments of ``type``.
|
| >>> f.replace(sin, lambda arg: sin(2*arg))
| log(sin(2*x)) + tan(sin(2*x**2))
| >>> (x*y).replace(Mul, lambda *args: sin(2*Mul(*args)))
| sin(2*x*y)
|
| 2.1. pattern -> expr
| obj.replace(pattern(wild), expr(wild))
|
| Replace subexpressions matching ``pattern`` with the expression
| written in terms of the Wild symbols in ``pattern``.
|
| >>> a, b = map(Wild, 'ab')
| >>> f.replace(sin(a), tan(a))
| log(tan(x)) + tan(tan(x**2))
| >>> f.replace(sin(a), tan(a/2))
| log(tan(x/2)) + tan(tan(x**2/2))
| >>> f.replace(sin(a), a)
| log(x) + tan(x**2)
| >>> (x*y).replace(a*x, a)
| y
|
| Matching is exact by default when more than one Wild symbol
| is used: matching fails unless the match gives non-zero
| values for all Wild symbols:
|
| >>> (2*x + y).replace(a*x + b, b - a)
| y - 2
| >>> (2*x).replace(a*x + b, b - a)
| 2*x
|
| When set to False, the results may be non-intuitive:
|
| >>> (2*x).replace(a*x + b, b - a, exact=False)
| 2/x
|
| 2.2. pattern -> func
| obj.replace(pattern(wild), lambda wild: expr(wild))
|
| All behavior is the same as in 2.1 but now a function in terms of
| pattern variables is used rather than an expression:
|
| >>> f.replace(sin(a), lambda a: sin(2*a))
| log(sin(2*x)) + tan(sin(2*x**2))
|
| 3.1. func -> func
| obj.replace(filter, func)
|
| Replace subexpression ``e`` with ``func(e)`` if ``filter(e)``
| is True.
|
| >>> g = 2*sin(x**3)
| >>> g.replace(lambda expr: expr.is_Number, lambda expr: expr**2)
| 4*sin(x**9)
|
| The expression itself is also targeted by the query but is done in
| such a fashion that changes are not made twice.
|
| >>> e = x*(x*y + 1)
| >>> e.replace(lambda x: x.is_Mul, lambda x: 2*x)
| 2*x*(2*x*y + 1)
|
| When matching a single symbol, `exact` will default to True, but
| this may or may not be the behavior that is desired:
|
| Here, we want `exact=False`:
|
| >>> from sympy import Function
| >>> f = Function('f')
| >>> e = f(1) + f(0)
| >>> q = f(a), lambda a: f(a + 1)
| >>> e.replace(*q, exact=False)
| f(1) + f(2)
| >>> e.replace(*q, exact=True)
| f(0) + f(2)
|
| But here, the nature of matching makes selecting
| the right setting tricky:
|
| >>> e = x**(1 + y)
| >>> (x**(1 + y)).replace(x**(1 + a), lambda a: x**-a, exact=False)
| x
| >>> (x**(1 + y)).replace(x**(1 + a), lambda a: x**-a, exact=True)
| x**(-x - y + 1)
| >>> (x**y).replace(x**(1 + a), lambda a: x**-a, exact=False)
| x
| >>> (x**y).replace(x**(1 + a), lambda a: x**-a, exact=True)
| x**(1 - y)
|
| It is probably better to use a different form of the query
| that describes the target expression more precisely:
|
| >>> (1 + x**(1 + y)).replace(
| ... lambda x: x.is_Pow and x.exp.is_Add and x.exp.args[0] == 1,
| ... lambda x: x.base**(1 - (x.exp - 1)))
| ...
| x**(1 - y) + 1
|
| See Also
| ========
|
| subs: substitution of subexpressions as defined by the objects
| themselves.
| xreplace: exact node replacement in expr tree; also capable of
| using matching rules
|
| rewrite(self, *args, **hints)
| Rewrite functions in terms of other functions.
|
| Rewrites expression containing applications of functions
| of one kind in terms of functions of different kind. For
| example you can rewrite trigonometric functions as complex
| exponentials or combinatorial functions as gamma function.
|
| As a pattern this function accepts a list of functions to
| to rewrite (instances of DefinedFunction class). As rule
| you can use string or a destination function instance (in
| this case rewrite() will use the str() function).
|
| There is also the possibility to pass hints on how to rewrite
| the given expressions. For now there is only one such hint
| defined called 'deep'. When 'deep' is set to False it will
| forbid functions to rewrite their contents.
|
| Examples
| ========
|
| >>> from sympy import sin, exp
| >>> from sympy.abc import x
|
| Unspecified pattern:
|
| >>> sin(x).rewrite(exp)
| -I*(exp(I*x) - exp(-I*x))/2
|
| Pattern as a single function:
|
| >>> sin(x).rewrite(sin, exp)
| -I*(exp(I*x) - exp(-I*x))/2
|
| Pattern as a list of functions:
|
| >>> sin(x).rewrite([sin, ], exp)
| -I*(exp(I*x) - exp(-I*x))/2
|
| simplify(self, **kwargs)
| See the simplify function in sympy.simplify
|
| subs(self, *args, **kwargs)
| Substitutes old for new in an expression after sympifying args.
|
| `args` is either:
| - two arguments, e.g. foo.subs(old, new)
| - one iterable argument, e.g. foo.subs(iterable). The iterable may be
| o an iterable container with (old, new) pairs. In this case the
| replacements are processed in the order given with successive
| patterns possibly affecting replacements already made.
| o a dict or set whose key/value items correspond to old/new pairs.
| In this case the old/new pairs will be sorted by op count and in
| case of a tie, by number of args and the default_sort_key. The
| resulting sorted list is then processed as an iterable container
| (see previous).
|
| If the keyword ``simultaneous`` is True, the subexpressions will not be
| evaluated until all the substitutions have been made.
|
| Examples
| ========
|
| >>> from sympy import pi, exp, limit, oo
| >>> from sympy.abc import x, y
| >>> (1 + x*y).subs(x, pi)
| pi*y + 1
| >>> (1 + x*y).subs({x:pi, y:2})
| 1 + 2*pi
| >>> (1 + x*y).subs([(x, pi), (y, 2)])
| 1 + 2*pi
| >>> reps = [(y, x**2), (x, 2)]
| >>> (x + y).subs(reps)
| 6
| >>> (x + y).subs(reversed(reps))
| x**2 + 2
|
| >>> (x**2 + x**4).subs(x**2, y)
| y**2 + y
|
| To replace only the x**2 but not the x**4, use xreplace:
|
| >>> (x**2 + x**4).xreplace({x**2: y})
| x**4 + y
|
| To delay evaluation until all substitutions have been made,
| set the keyword ``simultaneous`` to True:
|
| >>> (x/y).subs([(x, 0), (y, 0)])
| 0
| >>> (x/y).subs([(x, 0), (y, 0)], simultaneous=True)
| nan
|
| This has the added feature of not allowing subsequent substitutions
| to affect those already made:
|
| >>> ((x + y)/y).subs({x + y: y, y: x + y})
| 1
| >>> ((x + y)/y).subs({x + y: y, y: x + y}, simultaneous=True)
| y/(x + y)
|
| In order to obtain a canonical result, unordered iterables are
| sorted by count_op length, number of arguments and by the
| default_sort_key to break any ties. All other iterables are left
| unsorted.
|
| >>> from sympy import sqrt, sin, cos
| >>> from sympy.abc import a, b, c, d, e
|
| >>> A = (sqrt(sin(2*x)), a)
| >>> B = (sin(2*x), b)
| >>> C = (cos(2*x), c)
| >>> D = (x, d)
| >>> E = (exp(x), e)
|
| >>> expr = sqrt(sin(2*x))*sin(exp(x)*x)*cos(2*x) + sin(2*x)
|
| >>> expr.subs(dict([A, B, C, D, E]))
| a*c*sin(d*e) + b
|
| The resulting expression represents a literal replacement of the
| old arguments with the new arguments. This may not reflect the
| limiting behavior of the expression:
|
| >>> (x**3 - 3*x).subs({x: oo})
| nan
|
| >>> limit(x**3 - 3*x, x, oo)
| oo
|
| If the substitution will be followed by numerical
| evaluation, it is better to pass the substitution to
| evalf as
|
| >>> (1/x).evalf(subs={x: 3.0}, n=21)
| 0.333333333333333333333
|
| rather than
|
| >>> (1/x).subs({x: 3.0}).evalf(21)
| 0.333333333333333314830
|
| as the former will ensure that the desired level of precision is
| obtained.
|
| See Also
| ========
| replace: replacement capable of doing wildcard-like matching,
| parsing of match, and conditional replacements
| xreplace: exact node replacement in expr tree; also capable of
| using matching rules
| sympy.core.evalf.EvalfMixin.evalf: calculates the given formula to a desired level of precision
|
| xreplace lambda rule, **_
| # Function needs args so we define a property that returns
| # a function that takes args...and then use that function
| # to return the right value
|
| ----------------------------------------------------------------------
| Class methods inherited from sympy.core.basic.Basic:
|
| fromiter(args, **assumptions) from sympy.core.function.FunctionClass
| Create a new object from an iterable.
|
| This is a convenience function that allows one to create objects from
| any iterable, without having to convert to a list or tuple first.
|
| Examples
| ========
|
| >>> from sympy import Tuple
| >>> Tuple.fromiter(i for i in range(5))
| (0, 1, 2, 3, 4)
|
| ----------------------------------------------------------------------
| Readonly properties inherited from sympy.core.basic.Basic:
|
| args
| Returns a tuple of arguments of 'self'.
|
| Examples
| ========
|
| >>> from sympy import cot
| >>> from sympy.abc import x, y
|
| >>> cot(x).args
| (x,)
|
| >>> cot(x).args[0]
| x
|
| >>> (x*y).args
| (x, y)
|
| >>> (x*y).args[1]
| y
|
| Notes
| =====
|
| Never use self._args, always use self.args.
| Only use _args in __new__ when creating a new function.
| Don't override .args() from Basic (so that it's easy to
| change the interface in the future if needed).
|
| assumptions0
| Return object `type` assumptions.
|
| For example:
|
| Symbol('x', real=True)
| Symbol('x', integer=True)
|
| are different objects. In other words, besides Python type (Symbol in
| this case), the initial assumptions are also forming their typeinfo.
|
| Examples
| ========
|
| >>> from sympy import Symbol
| >>> from sympy.abc import x
| >>> x.assumptions0
| {'commutative': True}
| >>> x = Symbol("x", positive=True)
| >>> x.assumptions0
| {'commutative': True, 'complex': True, 'extended_negative': False,
| 'extended_nonnegative': True, 'extended_nonpositive': False,
| 'extended_nonzero': True, 'extended_positive': True, 'extended_real':
| True, 'finite': True, 'hermitian': True, 'imaginary': False,
| 'infinite': False, 'negative': False, 'nonnegative': True,
| 'nonpositive': False, 'nonzero': True, 'positive': True, 'real':
| True, 'zero': False}
|
| canonical_variables
| Return a dictionary mapping any variable defined in
| ``self.bound_symbols`` to Symbols that do not clash
| with any free symbols in the expression.
|
| Examples
| ========
|
| >>> from sympy import Lambda
| >>> from sympy.abc import x
| >>> Lambda(x, 2*x).canonical_variables
| {x: _0}
|
| free_symbols
| Return from the atoms of self those which are free symbols.
|
| For most expressions, all symbols are free symbols. For some classes
| this is not true. e.g. Integrals use Symbols for the dummy variables
| which are bound variables, so Integral has a method to return all
| symbols except those. Derivative keeps track of symbols with respect
| to which it will perform a derivative; those are
| bound variables, too, so it has its own free_symbols method.
|
| Any other method that uses bound variables should implement a
| free_symbols method.
|
| is_algebraic
|
| is_antihermitian
|
| is_commutative
|
| is_comparable
| Return True if self can be computed to a real number
| (or already is a real number) with precision, else False.
|
| Examples
| ========
|
| >>> from sympy import exp_polar, pi, I
| >>> (I*exp_polar(I*pi/2)).is_comparable
| True
| >>> (I*exp_polar(I*pi*2)).is_comparable
| False
|
| A False result does not mean that `self` cannot be rewritten
| into a form that would be comparable. For example, the
| difference computed below is zero but without simplification
| it does not evaluate to a zero with precision:
|
| >>> e = 2**pi*(1 + 2**pi)
| >>> dif = e - e.expand()
| >>> dif.is_comparable
| False
| >>> dif.n(2)._prec
| 1
|
| is_complex
|
| is_composite
|
| is_even
|
| is_extended_negative
|
| is_extended_nonnegative
|
| is_extended_nonpositive
|
| is_extended_nonzero
|
| is_extended_positive
|
| is_extended_real
|
| is_finite
|
| is_hermitian
|
| is_imaginary
|
| is_infinite
|
| is_integer
|
| is_irrational
|
| is_negative
|
| is_noninteger
|
| is_nonnegative
|
| is_nonpositive
|
| is_nonzero
|
| is_odd
|
| is_polar
|
| is_positive
|
| is_prime
|
| is_rational
|
| is_real
|
| is_transcendental
|
| is_zero
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from sympy.core.basic.Basic:
|
| is_Add = False
|
| is_AlgebraicNumber = False
|
| is_Atom = False
|
| is_Boolean = False
|
| is_Derivative = False
|
| is_Dummy = False
|
| is_Equality = False
|
| is_Float = False
|
| is_Indexed = False
|
| is_Integer = False
|
| is_MatAdd = False
|
| is_MatMul = False
|
| is_Matrix = False
|
| is_Mul = False
|
| is_Not = False
|
| is_Number = False
|
| is_NumberSymbol = False
|
| is_Order = False
|
| is_Piecewise = False
|
| is_Point = False
|
| is_Poly = False
|
| is_Pow = False
|
| is_Rational = False
|
| is_Relational = False
|
| is_Symbol = False
|
| is_Vector = False
|
| is_Wild = False
|
| is_symbol = False
|
| kind = UndefinedKind
|
| ----------------------------------------------------------------------
| Methods inherited from sympy.printing.defaults.Printable:
|
| __repr__ = __str__(self)
|
| __str__(self)
| Return str(self).
|
| ----------------------------------------------------------------------
| Methods inherited from sympy.core.evalf.EvalfMixin:
|
| evalf(self, n=15, subs=None, maxn=100, chop=False, strict=False, quad=None, verbose=False)
| Evaluate the given formula to an accuracy of *n* digits.
|
| Parameters
| ==========
|
| subs : dict, optional
| Substitute numerical values for symbols, e.g.
| ``subs={x:3, y:1+pi}``. The substitutions must be given as a
| dictionary.
|
| maxn : int, optional
| Allow a maximum temporary working precision of maxn digits.
|
| chop : bool or number, optional
| Specifies how to replace tiny real or imaginary parts in
| subresults by exact zeros.
|
| When ``True`` the chop value defaults to standard precision.
|
| Otherwise the chop value is used to determine the
| magnitude of "small" for purposes of chopping.
|
| >>> from sympy import N
| >>> x = 1e-4
| >>> N(x, chop=True)
| 0.000100000000000000
| >>> N(x, chop=1e-5)
| 0.000100000000000000
| >>> N(x, chop=1e-4)
| 0
|
| strict : bool, optional
| Raise ``PrecisionExhausted`` if any subresult fails to
| evaluate to full accuracy, given the available maxprec.
|
| quad : str, optional
| Choose algorithm for numerical quadrature. By default,
| tanh-sinh quadrature is used. For oscillatory
| integrals on an infinite interval, try ``quad='osc'``.
|
| verbose : bool, optional
| Print debug information.
|
| Notes
| =====
|
| When Floats are naively substituted into an expression,
| precision errors may adversely affect the result. For example,
| adding 1e16 (a Float) to 1 will truncate to 1e16; if 1e16 is
| then subtracted, the result will be 0.
| That is exactly what happens in the following:
|
| >>> from sympy.abc import x, y, z
| >>> values = {x: 1e16, y: 1, z: 1e16}
| >>> (x + y - z).subs(values)
| 0
|
| Using the subs argument for evalf is the accurate way to
| evaluate such an expression:
|
| >>> (x + y - z).evalf(subs=values)
| 1.00000000000000
|
| n = evalf(self, n=15, subs=None, maxn=100, chop=False, strict=False, quad=None, verbose=False)
`theta, phi, n, m = smp.symbols('theta phi n m')
smp.Ynm(n, m, theta, phi)
smp.Ynm(0, 0, theta, phi)
smp.Ynm(n, m, theta, phi).expand(func=True)
smp.Ynm(0, 0, theta, phi).expand(func=True)
smp.Ynm(1, 0, theta, phi).expand(func=True)
smp.Ynm(1, 1, theta, phi).expand(func=True)
smp.Ynm(1, -1, theta, phi).expand(func=True)
smp.Ynm(1, -1, theta, -phi).expand(func=True)
smp.Ynm(2, 0, theta, phi).expand(func=True)
smp.Ynm(2, -2, theta, phi).expand(func=True)
smp.Ynm(2, -1, theta, phi).expand(func=True)
smp.Ynm(2, 1, theta, phi).expand(func=True)
smp.Ynm(2, 2, theta, phi).expand(func=True)
smp.simplify(smp.Ynm(2, 2, theta, phi).expand(func=True))
smp.simplify(smp.Ynm(2, 1, theta, phi).expand(func=True))
smp.diff(smp.Ynm(2, 1, theta, phi).expand(func=True), theta)
smp.diff(smp.Ynm(2, 1, theta, phi).expand(func=True), phi)
smp.conjugate(smp.Ynm(2, 1, theta, phi).expand(func=True))
smp.Ynm(2, 1, theta, phi).expand(func=True)
smp.simplify(smp.Ynm(10, 9, theta, phi).expand(func=True))
smp.simplify(smp.Ynm(10, 9, smp.pi/4, smp.pi).expand(func=True))
help(smp.assoc_legendre)
Help on class assoc_legendre in module sympy.functions.special.polynomials:
class assoc_legendre(sympy.core.function.Function)
| assoc_legendre(n, m, x)
|
| ``assoc_legendre(n, m, x)`` gives $P_n^m(x)$, where n and m are
| the degree and order or an expression which is related to the nth
| order Legendre polynomial, $P_n(x)$ in the following manner:
|
| .. math::
| P_n^m(x) = (-1)^m (1 - x^2)^{\frac{m}{2}}
| \frac{\mathrm{d}^m P_n(x)}{\mathrm{d} x^m}
|
| Explanation
| ===========
|
| Associated Legendre polynomials are orthogonal on [-1, 1] with:
|
| - weight = 1 for the same m, and different n.
| - weight = 1/(1-x**2) for the same n, and different m.
|
| Examples
| ========
|
| >>> from sympy import assoc_legendre
| >>> from sympy.abc import x, m, n
| >>> assoc_legendre(0,0, x)
| 1
| >>> assoc_legendre(1,0, x)
| x
| >>> assoc_legendre(1,1, x)
| -sqrt(1 - x**2)
| >>> assoc_legendre(n,m,x)
| assoc_legendre(n, m, x)
|
| See Also
| ========
|
| jacobi, gegenbauer,
| chebyshevt, chebyshevt_root, chebyshevu, chebyshevu_root,
| legendre,
| hermite,
| laguerre, assoc_laguerre,
| sympy.polys.orthopolys.jacobi_poly
| sympy.polys.orthopolys.gegenbauer_poly
| sympy.polys.orthopolys.chebyshevt_poly
| sympy.polys.orthopolys.chebyshevu_poly
| sympy.polys.orthopolys.hermite_poly
| sympy.polys.orthopolys.legendre_poly
| sympy.polys.orthopolys.laguerre_poly
|
| References
| ==========
|
| .. [1] https://en.wikipedia.org/wiki/Associated_Legendre_polynomials
| .. [2] http://mathworld.wolfram.com/LegendrePolynomial.html
| .. [3] http://functions.wolfram.com/Polynomials/LegendreP/
| .. [4] http://functions.wolfram.com/Polynomials/LegendreP2/
|
| Method resolution order:
| assoc_legendre
| sympy.core.function.Function
| sympy.core.function.Application
| sympy.core.expr.Expr
| sympy.core.basic.Basic
| sympy.printing.defaults.Printable
| sympy.core.evalf.EvalfMixin
| builtins.object
|
| Methods defined here:
|
| fdiff(self, argindex=3)
| Returns the first derivative of the function.
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| eval(n, m, x) from sympy.core.function.FunctionClass
| Returns a canonical form of cls applied to arguments args.
|
| Explanation
| ===========
|
| The eval() method is called when the class cls is about to be
| instantiated and it should return either some simplified instance
| (possible of some other class), or if the class cls should be
| unmodified, return None.
|
| Examples of eval() for the function "sign"
| ---------------------------------------------
|
| .. code-block:: python
|
| @classmethod
| def eval(cls, arg):
| if arg is S.NaN:
| return S.NaN
| if arg.is_zero: return S.Zero
| if arg.is_positive: return S.One
| if arg.is_negative: return S.NegativeOne
| if isinstance(arg, Mul):
| coeff, terms = arg.as_coeff_Mul(rational=True)
| if coeff is not S.One:
| return cls(coeff) * cls(terms)
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| __sympy__
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| default_assumptions = {}
|
| ----------------------------------------------------------------------
| Methods inherited from sympy.core.function.Function:
|
| as_base_exp(self)
| Returns the method as the 2-tuple (base, exponent).
|
| ----------------------------------------------------------------------
| Class methods inherited from sympy.core.function.Function:
|
| class_key() from sympy.core.function.FunctionClass
| Nice order of classes.
|
| is_singular(a) from sympy.core.function.FunctionClass
| Tests whether the argument is an essential singularity
| or a branch point, or the functions is non-holomorphic.
|
| ----------------------------------------------------------------------
| Static methods inherited from sympy.core.function.Function:
|
| __new__(cls, *args, **options)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from sympy.core.function.Application:
|
| func
| The top-level function in an expression.
|
| The following should hold for all objects::
|
| >> x == x.func(*x.args)
|
| Examples
| ========
|
| >>> from sympy.abc import x
| >>> a = 2*x
| >>> a.func
| <class 'sympy.core.mul.Mul'>
| >>> a.args
| (2, x)
| >>> a.func(*a.args)
| 2*x
| >>> a == a.func(*a.args)
| True
|
| ----------------------------------------------------------------------
| Data descriptors inherited from sympy.core.function.Application:
|
| __dict__
| dictionary for instance variables (if defined)
|
| __weakref__
| list of weak references to the object (if defined)
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from sympy.core.function.Application:
|
| is_Function = True
|
| ----------------------------------------------------------------------
| Methods inherited from sympy.core.expr.Expr:
|
| __abs__(self)
|
| __add__(self, other)
|
| __complex__(self)
|
| __divmod__(self, other)
|
| __eq__(self, other)
| Return a boolean indicating whether a == b on the basis of
| their symbolic trees.
|
| This is the same as a.compare(b) == 0 but faster.
|
| Notes
| =====
|
| If a class that overrides __eq__() needs to retain the
| implementation of __hash__() from a parent class, the
| interpreter must be told this explicitly by setting __hash__ =
| <ParentClass>.__hash__. Otherwise the inheritance of __hash__()
| will be blocked, just as if __hash__ had been explicitly set to
| None.
|
| References
| ==========
|
| from http://docs.python.org/dev/reference/datamodel.html#object.__hash__
|
| __float__(self)
|
| __floordiv__(self, other)
|
| __ge__(self, other)
| Return self>=value.
|
| __gt__(self, other)
| Return self>value.
|
| __hash__(self) -> int
| Return hash(self).
|
| __int__(self)
|
| __le__(self, other)
| Return self<=value.
|
| __lt__(self, other)
| Return self<value.
|
| __mod__(self, other)
|
| __mul__(self, other)
|
| __neg__(self)
|
| __pos__(self)
|
| __pow__(self, other, mod=None)
|
| __radd__(self, other)
|
| __rdivmod__(self, other)
|
| __rfloordiv__(self, other)
|
| __rmod__(self, other)
|
| __rmul__(self, other)
|
| __round__ = round(self, n=None)
|
| __rpow__(self, other)
|
| __rsub__(self, other)
|
| __rtruediv__(self, other)
|
| __sub__(self, other)
|
| __truediv__(self, other)
|
| __trunc__(self)
|
| adjoint(self)
|
| apart(self, x=None, **args)
| See the apart function in sympy.polys
|
| args_cnc(self, cset=False, warn=True, split_1=True)
| Return [commutative factors, non-commutative factors] of self.
|
| Explanation
| ===========
|
| self is treated as a Mul and the ordering of the factors is maintained.
| If ``cset`` is True the commutative factors will be returned in a set.
| If there were repeated factors (as may happen with an unevaluated Mul)
| then an error will be raised unless it is explicitly suppressed by
| setting ``warn`` to False.
|
| Note: -1 is always separated from a Number unless split_1 is False.
|
| Examples
| ========
|
| >>> from sympy import symbols, oo
| >>> A, B = symbols('A B', commutative=0)
| >>> x, y = symbols('x y')
| >>> (-2*x*y).args_cnc()
| [[-1, 2, x, y], []]
| >>> (-2.5*x).args_cnc()
| [[-1, 2.5, x], []]
| >>> (-2*x*A*B*y).args_cnc()
| [[-1, 2, x, y], [A, B]]
| >>> (-2*x*A*B*y).args_cnc(split_1=False)
| [[-2, x, y], [A, B]]
| >>> (-2*x*y).args_cnc(cset=True)
| [{-1, 2, x, y}, []]
|
| The arg is always treated as a Mul:
|
| >>> (-2 + x + A).args_cnc()
| [[], [x - 2 + A]]
| >>> (-oo).args_cnc() # -oo is a singleton
| [[-1, oo], []]
|
| as_coeff_Add(self, rational=False)
| Efficiently extract the coefficient of a summation.
|
| as_coeff_Mul(self, rational=False)
| Efficiently extract the coefficient of a product.
|
| as_coeff_add(self, *deps)
| Return the tuple (c, args) where self is written as an Add, ``a``.
|
| c should be a Rational added to any terms of the Add that are
| independent of deps.
|
| args should be a tuple of all other terms of ``a``; args is empty
| if self is a Number or if self is independent of deps (when given).
|
| This should be used when you don't know if self is an Add or not but
| you want to treat self as an Add or if you want to process the
| individual arguments of the tail of self as an Add.
|
| - if you know self is an Add and want only the head, use self.args[0];
| - if you don't want to process the arguments of the tail but need the
| tail then use self.as_two_terms() which gives the head and tail.
| - if you want to split self into an independent and dependent parts
| use ``self.as_independent(*deps)``
|
| >>> from sympy import S
| >>> from sympy.abc import x, y
| >>> (S(3)).as_coeff_add()
| (3, ())
| >>> (3 + x).as_coeff_add()
| (3, (x,))
| >>> (3 + x + y).as_coeff_add(x)
| (y + 3, (x,))
| >>> (3 + y).as_coeff_add(x)
| (y + 3, ())
|
| as_coeff_exponent(self, x)
| ``c*x**e -> c,e`` where x can be any symbolic expression.
|
| as_coeff_mul(self, *deps, **kwargs)
| Return the tuple (c, args) where self is written as a Mul, ``m``.
|
| c should be a Rational multiplied by any factors of the Mul that are
| independent of deps.
|
| args should be a tuple of all other factors of m; args is empty
| if self is a Number or if self is independent of deps (when given).
|
| This should be used when you don't know if self is a Mul or not but
| you want to treat self as a Mul or if you want to process the
| individual arguments of the tail of self as a Mul.
|
| - if you know self is a Mul and want only the head, use self.args[0];
| - if you don't want to process the arguments of the tail but need the
| tail then use self.as_two_terms() which gives the head and tail;
| - if you want to split self into an independent and dependent parts
| use ``self.as_independent(*deps)``
|
| >>> from sympy import S
| >>> from sympy.abc import x, y
| >>> (S(3)).as_coeff_mul()
| (3, ())
| >>> (3*x*y).as_coeff_mul()
| (3, (x, y))
| >>> (3*x*y).as_coeff_mul(x)
| (3*y, (x,))
| >>> (3*y).as_coeff_mul(x)
| (3*y, ())
|
| as_coefficient(self, expr)
| Extracts symbolic coefficient at the given expression. In
| other words, this functions separates 'self' into the product
| of 'expr' and 'expr'-free coefficient. If such separation
| is not possible it will return None.
|
| Examples
| ========
|
| >>> from sympy import E, pi, sin, I, Poly
| >>> from sympy.abc import x
|
| >>> E.as_coefficient(E)
| 1
| >>> (2*E).as_coefficient(E)
| 2
| >>> (2*sin(E)*E).as_coefficient(E)
|
| Two terms have E in them so a sum is returned. (If one were
| desiring the coefficient of the term exactly matching E then
| the constant from the returned expression could be selected.
| Or, for greater precision, a method of Poly can be used to
| indicate the desired term from which the coefficient is
| desired.)
|
| >>> (2*E + x*E).as_coefficient(E)
| x + 2
| >>> _.args[0] # just want the exact match
| 2
| >>> p = Poly(2*E + x*E); p
| Poly(x*E + 2*E, x, E, domain='ZZ')
| >>> p.coeff_monomial(E)
| 2
| >>> p.nth(0, 1)
| 2
|
| Since the following cannot be written as a product containing
| E as a factor, None is returned. (If the coefficient ``2*x`` is
| desired then the ``coeff`` method should be used.)
|
| >>> (2*E*x + x).as_coefficient(E)
| >>> (2*E*x + x).coeff(E)
| 2*x
|
| >>> (E*(x + 1) + x).as_coefficient(E)
|
| >>> (2*pi*I).as_coefficient(pi*I)
| 2
| >>> (2*I).as_coefficient(pi*I)
|
| See Also
| ========
|
| coeff: return sum of terms have a given factor
| as_coeff_Add: separate the additive constant from an expression
| as_coeff_Mul: separate the multiplicative constant from an expression
| as_independent: separate x-dependent terms/factors from others
| sympy.polys.polytools.Poly.coeff_monomial: efficiently find the single coefficient of a monomial in Poly
| sympy.polys.polytools.Poly.nth: like coeff_monomial but powers of monomial terms are used
|
| as_coefficients_dict(self)
| Return a dictionary mapping terms to their Rational coefficient.
| Since the dictionary is a defaultdict, inquiries about terms which
| were not present will return a coefficient of 0. If an expression is
| not an Add it is considered to have a single term.
|
| Examples
| ========
|
| >>> from sympy.abc import a, x
| >>> (3*x + a*x + 4).as_coefficients_dict()
| {1: 4, x: 3, a*x: 1}
| >>> _[a]
| 0
| >>> (3*a*x).as_coefficients_dict()
| {a*x: 3}
|
| as_content_primitive(self, radical=False, clear=True)
| This method should recursively remove a Rational from all arguments
| and return that (content) and the new self (primitive). The content
| should always be positive and ``Mul(*foo.as_content_primitive()) == foo``.
| The primitive need not be in canonical form and should try to preserve
| the underlying structure if possible (i.e. expand_mul should not be
| applied to self).
|
| Examples
| ========
|
| >>> from sympy import sqrt
| >>> from sympy.abc import x, y, z
|
| >>> eq = 2 + 2*x + 2*y*(3 + 3*y)
|
| The as_content_primitive function is recursive and retains structure:
|
| >>> eq.as_content_primitive()
| (2, x + 3*y*(y + 1) + 1)
|
| Integer powers will have Rationals extracted from the base:
|
| >>> ((2 + 6*x)**2).as_content_primitive()
| (4, (3*x + 1)**2)
| >>> ((2 + 6*x)**(2*y)).as_content_primitive()
| (1, (2*(3*x + 1))**(2*y))
|
| Terms may end up joining once their as_content_primitives are added:
|
| >>> ((5*(x*(1 + y)) + 2*x*(3 + 3*y))).as_content_primitive()
| (11, x*(y + 1))
| >>> ((3*(x*(1 + y)) + 2*x*(3 + 3*y))).as_content_primitive()
| (9, x*(y + 1))
| >>> ((3*(z*(1 + y)) + 2.0*x*(3 + 3*y))).as_content_primitive()
| (1, 6.0*x*(y + 1) + 3*z*(y + 1))
| >>> ((5*(x*(1 + y)) + 2*x*(3 + 3*y))**2).as_content_primitive()
| (121, x**2*(y + 1)**2)
| >>> ((x*(1 + y) + 0.4*x*(3 + 3*y))**2).as_content_primitive()
| (1, 4.84*x**2*(y + 1)**2)
|
| Radical content can also be factored out of the primitive:
|
| >>> (2*sqrt(2) + 4*sqrt(10)).as_content_primitive(radical=True)
| (2, sqrt(2)*(1 + 2*sqrt(5)))
|
| If clear=False (default is True) then content will not be removed
| from an Add if it can be distributed to leave one or more
| terms with integer coefficients.
|
| >>> (x/2 + y).as_content_primitive()
| (1/2, x + 2*y)
| >>> (x/2 + y).as_content_primitive(clear=False)
| (1, x/2 + y)
|
| as_expr(self, *gens)
| Convert a polynomial to a SymPy expression.
|
| Examples
| ========
|
| >>> from sympy import sin
| >>> from sympy.abc import x, y
|
| >>> f = (x**2 + x*y).as_poly(x, y)
| >>> f.as_expr()
| x**2 + x*y
|
| >>> sin(x).as_expr()
| sin(x)
|
| as_independent(self, *deps, **hint)
| A mostly naive separation of a Mul or Add into arguments that are not
| are dependent on deps. To obtain as complete a separation of variables
| as possible, use a separation method first, e.g.:
|
| * separatevars() to change Mul, Add and Pow (including exp) into Mul
| * .expand(mul=True) to change Add or Mul into Add
| * .expand(log=True) to change log expr into an Add
|
| The only non-naive thing that is done here is to respect noncommutative
| ordering of variables and to always return (0, 0) for `self` of zero
| regardless of hints.
|
| For nonzero `self`, the returned tuple (i, d) has the
| following interpretation:
|
| * i will has no variable that appears in deps
| * d will either have terms that contain variables that are in deps, or
| be equal to 0 (when self is an Add) or 1 (when self is a Mul)
| * if self is an Add then self = i + d
| * if self is a Mul then self = i*d
| * otherwise (self, S.One) or (S.One, self) is returned.
|
| To force the expression to be treated as an Add, use the hint as_Add=True
|
| Examples
| ========
|
| -- self is an Add
|
| >>> from sympy import sin, cos, exp
| >>> from sympy.abc import x, y, z
|
| >>> (x + x*y).as_independent(x)
| (0, x*y + x)
| >>> (x + x*y).as_independent(y)
| (x, x*y)
| >>> (2*x*sin(x) + y + x + z).as_independent(x)
| (y + z, 2*x*sin(x) + x)
| >>> (2*x*sin(x) + y + x + z).as_independent(x, y)
| (z, 2*x*sin(x) + x + y)
|
| -- self is a Mul
|
| >>> (x*sin(x)*cos(y)).as_independent(x)
| (cos(y), x*sin(x))
|
| non-commutative terms cannot always be separated out when self is a Mul
|
| >>> from sympy import symbols
| >>> n1, n2, n3 = symbols('n1 n2 n3', commutative=False)
| >>> (n1 + n1*n2).as_independent(n2)
| (n1, n1*n2)
| >>> (n2*n1 + n1*n2).as_independent(n2)
| (0, n1*n2 + n2*n1)
| >>> (n1*n2*n3).as_independent(n1)
| (1, n1*n2*n3)
| >>> (n1*n2*n3).as_independent(n2)
| (n1, n2*n3)
| >>> ((x-n1)*(x-y)).as_independent(x)
| (1, (x - y)*(x - n1))
|
| -- self is anything else:
|
| >>> (sin(x)).as_independent(x)
| (1, sin(x))
| >>> (sin(x)).as_independent(y)
| (sin(x), 1)
| >>> exp(x+y).as_independent(x)
| (1, exp(x + y))
|
| -- force self to be treated as an Add:
|
| >>> (3*x).as_independent(x, as_Add=True)
| (0, 3*x)
|
| -- force self to be treated as a Mul:
|
| >>> (3+x).as_independent(x, as_Add=False)
| (1, x + 3)
| >>> (-3+x).as_independent(x, as_Add=False)
| (1, x - 3)
|
| Note how the below differs from the above in making the
| constant on the dep term positive.
|
| >>> (y*(-3+x)).as_independent(x)
| (y, x - 3)
|
| -- use .as_independent() for true independence testing instead
| of .has(). The former considers only symbols in the free
| symbols while the latter considers all symbols
|
| >>> from sympy import Integral
| >>> I = Integral(x, (x, 1, 2))
| >>> I.has(x)
| True
| >>> x in I.free_symbols
| False
| >>> I.as_independent(x) == (I, 1)
| True
| >>> (I + x).as_independent(x) == (I, x)
| True
|
| Note: when trying to get independent terms, a separation method
| might need to be used first. In this case, it is important to keep
| track of what you send to this routine so you know how to interpret
| the returned values
|
| >>> from sympy import separatevars, log
| >>> separatevars(exp(x+y)).as_independent(x)
| (exp(y), exp(x))
| >>> (x + x*y).as_independent(y)
| (x, x*y)
| >>> separatevars(x + x*y).as_independent(y)
| (x, y + 1)
| >>> (x*(1 + y)).as_independent(y)
| (x, y + 1)
| >>> (x*(1 + y)).expand(mul=True).as_independent(y)
| (x, x*y)
| >>> a, b=symbols('a b', positive=True)
| >>> (log(a*b).expand(log=True)).as_independent(b)
| (log(a), log(b))
|
| See Also
| ========
| .separatevars(), .expand(log=True), sympy.core.add.Add.as_two_terms(),
| sympy.core.mul.Mul.as_two_terms(), .as_coeff_add(), .as_coeff_mul()
|
| as_leading_term(self, *symbols, cdir=0)
| Returns the leading (nonzero) term of the series expansion of self.
|
| The _eval_as_leading_term routines are used to do this, and they must
| always return a non-zero value.
|
| Examples
| ========
|
| >>> from sympy.abc import x
| >>> (1 + x + x**2).as_leading_term(x)
| 1
| >>> (1/x**2 + x + x**2).as_leading_term(x)
| x**(-2)
|
| as_numer_denom(self)
| expression -> a/b -> a, b
|
| This is just a stub that should be defined by
| an object's class methods to get anything else.
|
| See Also
| ========
|
| normal: return ``a/b`` instead of ``(a, b)``
|
| as_ordered_factors(self, order=None)
| Return list of ordered factors (if Mul) else [self].
|
| as_ordered_terms(self, order=None, data=False)
| Transform an expression to an ordered list of terms.
|
| Examples
| ========
|
| >>> from sympy import sin, cos
| >>> from sympy.abc import x
|
| >>> (sin(x)**2*cos(x) + sin(x)**2 + 1).as_ordered_terms()
| [sin(x)**2*cos(x), sin(x)**2, 1]
|
| as_poly(self, *gens, **args)
| Converts ``self`` to a polynomial or returns ``None``.
|
| Explanation
| ===========
|
| >>> from sympy import sin
| >>> from sympy.abc import x, y
|
| >>> print((x**2 + x*y).as_poly())
| Poly(x**2 + x*y, x, y, domain='ZZ')
|
| >>> print((x**2 + x*y).as_poly(x, y))
| Poly(x**2 + x*y, x, y, domain='ZZ')
|
| >>> print((x**2 + sin(y)).as_poly(x, y))
| None
|
| as_powers_dict(self)
| Return self as a dictionary of factors with each factor being
| treated as a power. The keys are the bases of the factors and the
| values, the corresponding exponents. The resulting dictionary should
| be used with caution if the expression is a Mul and contains non-
| commutative factors since the order that they appeared will be lost in
| the dictionary.
|
| See Also
| ========
| as_ordered_factors: An alternative for noncommutative applications,
| returning an ordered list of factors.
| args_cnc: Similar to as_ordered_factors, but guarantees separation
| of commutative and noncommutative factors.
|
| as_real_imag(self, deep=True, **hints)
| Performs complex expansion on 'self' and returns a tuple
| containing collected both real and imaginary parts. This
| method can't be confused with re() and im() functions,
| which does not perform complex expansion at evaluation.
|
| However it is possible to expand both re() and im()
| functions and get exactly the same results as with
| a single call to this function.
|
| >>> from sympy import symbols, I
|
| >>> x, y = symbols('x,y', real=True)
|
| >>> (x + y*I).as_real_imag()
| (x, y)
|
| >>> from sympy.abc import z, w
|
| >>> (z + w*I).as_real_imag()
| (re(z) - im(w), re(w) + im(z))
|
| as_terms(self)
| Transform an expression to a list of terms.
|
| aseries(self, x=None, n=6, bound=0, hir=False)
| Asymptotic Series expansion of self.
| This is equivalent to ``self.series(x, oo, n)``.
|
| Parameters
| ==========
|
| self : Expression
| The expression whose series is to be expanded.
|
| x : Symbol
| It is the variable of the expression to be calculated.
|
| n : Value
| The number of terms upto which the series is to be expanded.
|
| hir : Boolean
| Set this parameter to be True to produce hierarchical series.
| It stops the recursion at an early level and may provide nicer
| and more useful results.
|
| bound : Value, Integer
| Use the ``bound`` parameter to give limit on rewriting
| coefficients in its normalised form.
|
| Examples
| ========
|
| >>> from sympy import sin, exp
| >>> from sympy.abc import x
|
| >>> e = sin(1/x + exp(-x)) - sin(1/x)
|
| >>> e.aseries(x)
| (1/(24*x**4) - 1/(2*x**2) + 1 + O(x**(-6), (x, oo)))*exp(-x)
|
| >>> e.aseries(x, n=3, hir=True)
| -exp(-2*x)*sin(1/x)/2 + exp(-x)*cos(1/x) + O(exp(-3*x), (x, oo))
|
| >>> e = exp(exp(x)/(1 - 1/x))
|
| >>> e.aseries(x)
| exp(exp(x)/(1 - 1/x))
|
| >>> e.aseries(x, bound=3)
| exp(exp(x)/x**2)*exp(exp(x)/x)*exp(-exp(x) + exp(x)/(1 - 1/x) - exp(x)/x - exp(x)/x**2)*exp(exp(x))
|
| Returns
| =======
|
| Expr
| Asymptotic series expansion of the expression.
|
| Notes
| =====
|
| This algorithm is directly induced from the limit computational algorithm provided by Gruntz.
| It majorly uses the mrv and rewrite sub-routines. The overall idea of this algorithm is first
| to look for the most rapidly varying subexpression w of a given expression f and then expands f
| in a series in w. Then same thing is recursively done on the leading coefficient
| till we get constant coefficients.
|
| If the most rapidly varying subexpression of a given expression f is f itself,
| the algorithm tries to find a normalised representation of the mrv set and rewrites f
| using this normalised representation.
|
| If the expansion contains an order term, it will be either ``O(x ** (-n))`` or ``O(w ** (-n))``
| where ``w`` belongs to the most rapidly varying expression of ``self``.
|
| References
| ==========
|
| .. [1] A New Algorithm for Computing Asymptotic Series - Dominik Gruntz
| .. [2] Gruntz thesis - p90
| .. [3] http://en.wikipedia.org/wiki/Asymptotic_expansion
|
| See Also
| ========
|
| Expr.aseries: See the docstring of this function for complete details of this wrapper.
|
| cancel(self, *gens, **args)
| See the cancel function in sympy.polys
|
| coeff(self, x, n=1, right=False)
| Returns the coefficient from the term(s) containing ``x**n``. If ``n``
| is zero then all terms independent of ``x`` will be returned.
|
| Explanation
| ===========
|
| When ``x`` is noncommutative, the coefficient to the left (default) or
| right of ``x`` can be returned. The keyword 'right' is ignored when
| ``x`` is commutative.
|
| Examples
| ========
|
| >>> from sympy import symbols
| >>> from sympy.abc import x, y, z
|
| You can select terms that have an explicit negative in front of them:
|
| >>> (-x + 2*y).coeff(-1)
| x
| >>> (x - 2*y).coeff(-1)
| 2*y
|
| You can select terms with no Rational coefficient:
|
| >>> (x + 2*y).coeff(1)
| x
| >>> (3 + 2*x + 4*x**2).coeff(1)
| 0
|
| You can select terms independent of x by making n=0; in this case
| expr.as_independent(x)[0] is returned (and 0 will be returned instead
| of None):
|
| >>> (3 + 2*x + 4*x**2).coeff(x, 0)
| 3
| >>> eq = ((x + 1)**3).expand() + 1
| >>> eq
| x**3 + 3*x**2 + 3*x + 2
| >>> [eq.coeff(x, i) for i in reversed(range(4))]
| [1, 3, 3, 2]
| >>> eq -= 2
| >>> [eq.coeff(x, i) for i in reversed(range(4))]
| [1, 3, 3, 0]
|
| You can select terms that have a numerical term in front of them:
|
| >>> (-x - 2*y).coeff(2)
| -y
| >>> from sympy import sqrt
| >>> (x + sqrt(2)*x).coeff(sqrt(2))
| x
|
| The matching is exact:
|
| >>> (3 + 2*x + 4*x**2).coeff(x)
| 2
| >>> (3 + 2*x + 4*x**2).coeff(x**2)
| 4
| >>> (3 + 2*x + 4*x**2).coeff(x**3)
| 0
| >>> (z*(x + y)**2).coeff((x + y)**2)
| z
| >>> (z*(x + y)**2).coeff(x + y)
| 0
|
| In addition, no factoring is done, so 1 + z*(1 + y) is not obtained
| from the following:
|
| >>> (x + z*(x + x*y)).coeff(x)
| 1
|
| If such factoring is desired, factor_terms can be used first:
|
| >>> from sympy import factor_terms
| >>> factor_terms(x + z*(x + x*y)).coeff(x)
| z*(y + 1) + 1
|
| >>> n, m, o = symbols('n m o', commutative=False)
| >>> n.coeff(n)
| 1
| >>> (3*n).coeff(n)
| 3
| >>> (n*m + m*n*m).coeff(n) # = (1 + m)*n*m
| 1 + m
| >>> (n*m + m*n*m).coeff(n, right=True) # = (1 + m)*n*m
| m
|
| If there is more than one possible coefficient 0 is returned:
|
| >>> (n*m + m*n).coeff(n)
| 0
|
| If there is only one possible coefficient, it is returned:
|
| >>> (n*m + x*m*n).coeff(m*n)
| x
| >>> (n*m + x*m*n).coeff(m*n, right=1)
| 1
|
| See Also
| ========
|
| as_coefficient: separate the expression into a coefficient and factor
| as_coeff_Add: separate the additive constant from an expression
| as_coeff_Mul: separate the multiplicative constant from an expression
| as_independent: separate x-dependent terms/factors from others
| sympy.polys.polytools.Poly.coeff_monomial: efficiently find the single coefficient of a monomial in Poly
| sympy.polys.polytools.Poly.nth: like coeff_monomial but powers of monomial terms are used
|
| collect(self, syms, func=None, evaluate=True, exact=False, distribute_order_term=True)
| See the collect function in sympy.simplify
|
| combsimp(self)
| See the combsimp function in sympy.simplify
|
| compute_leading_term(self, x, logx=None)
| as_leading_term is only allowed for results of .series()
| This is a wrapper to compute a series first.
|
| conjugate(self)
| Returns the complex conjugate of 'self'.
|
| could_extract_minus_sign(self)
| Return True if self is not in a canonical form with respect
| to its sign.
|
| For most expressions, e, there will be a difference in e and -e.
| When there is, True will be returned for one and False for the
| other; False will be returned if there is no difference.
|
| Examples
| ========
|
| >>> from sympy.abc import x, y
| >>> e = x - y
| >>> {i.could_extract_minus_sign() for i in (e, -e)}
| {False, True}
|
| count_ops(self, visual=None)
| wrapper for count_ops that returns the operation count.
|
| diff(self, *symbols, **assumptions)
|
| dir(self, x, cdir)
|
| equals(self, other, failing_expression=False)
| Return True if self == other, False if it doesn't, or None. If
| failing_expression is True then the expression which did not simplify
| to a 0 will be returned instead of None.
|
| Explanation
| ===========
|
| If ``self`` is a Number (or complex number) that is not zero, then
| the result is False.
|
| If ``self`` is a number and has not evaluated to zero, evalf will be
| used to test whether the expression evaluates to zero. If it does so
| and the result has significance (i.e. the precision is either -1, for
| a Rational result, or is greater than 1) then the evalf value will be
| used to return True or False.
|
| expand(self, deep=True, modulus=None, power_base=True, power_exp=True, mul=True, log=True, multinomial=True, basic=True, **hints)
| Expand an expression using hints.
|
| See the docstring of the expand() function in sympy.core.function for
| more information.
|
| extract_additively(self, c)
| Return self - c if it's possible to subtract c from self and
| make all matching coefficients move towards zero, else return None.
|
| Examples
| ========
|
| >>> from sympy.abc import x, y
| >>> e = 2*x + 3
| >>> e.extract_additively(x + 1)
| x + 2
| >>> e.extract_additively(3*x)
| >>> e.extract_additively(4)
| >>> (y*(x + 1)).extract_additively(x + 1)
| >>> ((x + 1)*(x + 2*y + 1) + 3).extract_additively(x + 1)
| (x + 1)*(x + 2*y) + 3
|
| Sometimes auto-expansion will return a less simplified result
| than desired; gcd_terms might be used in such cases:
|
| >>> from sympy import gcd_terms
| >>> (4*x*(y + 1) + y).extract_additively(x)
| 4*x*(y + 1) + x*(4*y + 3) - x*(4*y + 4) + y
| >>> gcd_terms(_)
| x*(4*y + 3) + y
|
| See Also
| ========
| extract_multiplicatively
| coeff
| as_coefficient
|
| extract_branch_factor(self, allow_half=False)
| Try to write self as ``exp_polar(2*pi*I*n)*z`` in a nice way.
| Return (z, n).
|
| >>> from sympy import exp_polar, I, pi
| >>> from sympy.abc import x, y
| >>> exp_polar(I*pi).extract_branch_factor()
| (exp_polar(I*pi), 0)
| >>> exp_polar(2*I*pi).extract_branch_factor()
| (1, 1)
| >>> exp_polar(-pi*I).extract_branch_factor()
| (exp_polar(I*pi), -1)
| >>> exp_polar(3*pi*I + x).extract_branch_factor()
| (exp_polar(x + I*pi), 1)
| >>> (y*exp_polar(-5*pi*I)*exp_polar(3*pi*I + 2*pi*x)).extract_branch_factor()
| (y*exp_polar(2*pi*x), -1)
| >>> exp_polar(-I*pi/2).extract_branch_factor()
| (exp_polar(-I*pi/2), 0)
|
| If allow_half is True, also extract exp_polar(I*pi):
|
| >>> exp_polar(I*pi).extract_branch_factor(allow_half=True)
| (1, 1/2)
| >>> exp_polar(2*I*pi).extract_branch_factor(allow_half=True)
| (1, 1)
| >>> exp_polar(3*I*pi).extract_branch_factor(allow_half=True)
| (1, 3/2)
| >>> exp_polar(-I*pi).extract_branch_factor(allow_half=True)
| (1, -1/2)
|
| extract_multiplicatively(self, c)
| Return None if it's not possible to make self in the form
| c * something in a nice way, i.e. preserving the properties
| of arguments of self.
|
| Examples
| ========
|
| >>> from sympy import symbols, Rational
|
| >>> x, y = symbols('x,y', real=True)
|
| >>> ((x*y)**3).extract_multiplicatively(x**2 * y)
| x*y**2
|
| >>> ((x*y)**3).extract_multiplicatively(x**4 * y)
|
| >>> (2*x).extract_multiplicatively(2)
| x
|
| >>> (2*x).extract_multiplicatively(3)
|
| >>> (Rational(1, 2)*x).extract_multiplicatively(3)
| x/6
|
| factor(self, *gens, **args)
| See the factor() function in sympy.polys.polytools
|
| fourier_series(self, limits=None)
| Compute fourier sine/cosine series of self.
|
| See the docstring of the :func:`fourier_series` in sympy.series.fourier
| for more information.
|
| fps(self, x=None, x0=0, dir=1, hyper=True, order=4, rational=True, full=False)
| Compute formal power power series of self.
|
| See the docstring of the :func:`fps` function in sympy.series.formal for
| more information.
|
| gammasimp(self)
| See the gammasimp function in sympy.simplify
|
| getO(self)
| Returns the additive O(..) symbol if there is one, else None.
|
| getn(self)
| Returns the order of the expression.
|
| Explanation
| ===========
|
| The order is determined either from the O(...) term. If there
| is no O(...) term, it returns None.
|
| Examples
| ========
|
| >>> from sympy import O
| >>> from sympy.abc import x
| >>> (1 + x + O(x**2)).getn()
| 2
| >>> (1 + x).getn()
|
| integrate(self, *args, **kwargs)
| See the integrate function in sympy.integrals
|
| invert(self, g, *gens, **args)
| Return the multiplicative inverse of ``self`` mod ``g``
| where ``self`` (and ``g``) may be symbolic expressions).
|
| See Also
| ========
| sympy.core.numbers.mod_inverse, sympy.polys.polytools.invert
|
| is_algebraic_expr(self, *syms)
| This tests whether a given expression is algebraic or not, in the
| given symbols, syms. When syms is not given, all free symbols
| will be used. The rational function does not have to be in expanded
| or in any kind of canonical form.
|
| This function returns False for expressions that are "algebraic
| expressions" with symbolic exponents. This is a simple extension to the
| is_rational_function, including rational exponentiation.
|
| Examples
| ========
|
| >>> from sympy import Symbol, sqrt
| >>> x = Symbol('x', real=True)
| >>> sqrt(1 + x).is_rational_function()
| False
| >>> sqrt(1 + x).is_algebraic_expr()
| True
|
| This function does not attempt any nontrivial simplifications that may
| result in an expression that does not appear to be an algebraic
| expression to become one.
|
| >>> from sympy import exp, factor
| >>> a = sqrt(exp(x)**2 + 2*exp(x) + 1)/(exp(x) + 1)
| >>> a.is_algebraic_expr(x)
| False
| >>> factor(a).is_algebraic_expr()
| True
|
| See Also
| ========
| is_rational_function()
|
| References
| ==========
|
| - https://en.wikipedia.org/wiki/Algebraic_expression
|
| is_constant(self, *wrt, **flags)
| Return True if self is constant, False if not, or None if
| the constancy could not be determined conclusively.
|
| Explanation
| ===========
|
| If an expression has no free symbols then it is a constant. If
| there are free symbols it is possible that the expression is a
| constant, perhaps (but not necessarily) zero. To test such
| expressions, a few strategies are tried:
|
| 1) numerical evaluation at two random points. If two such evaluations
| give two different values and the values have a precision greater than
| 1 then self is not constant. If the evaluations agree or could not be
| obtained with any precision, no decision is made. The numerical testing
| is done only if ``wrt`` is different than the free symbols.
|
| 2) differentiation with respect to variables in 'wrt' (or all free
| symbols if omitted) to see if the expression is constant or not. This
| will not always lead to an expression that is zero even though an
| expression is constant (see added test in test_expr.py). If
| all derivatives are zero then self is constant with respect to the
| given symbols.
|
| 3) finding out zeros of denominator expression with free_symbols.
| It won't be constant if there are zeros. It gives more negative
| answers for expression that are not constant.
|
| If neither evaluation nor differentiation can prove the expression is
| constant, None is returned unless two numerical values happened to be
| the same and the flag ``failing_number`` is True -- in that case the
| numerical value will be returned.
|
| If flag simplify=False is passed, self will not be simplified;
| the default is True since self should be simplified before testing.
|
| Examples
| ========
|
| >>> from sympy import cos, sin, Sum, S, pi
| >>> from sympy.abc import a, n, x, y
| >>> x.is_constant()
| False
| >>> S(2).is_constant()
| True
| >>> Sum(x, (x, 1, 10)).is_constant()
| True
| >>> Sum(x, (x, 1, n)).is_constant()
| False
| >>> Sum(x, (x, 1, n)).is_constant(y)
| True
| >>> Sum(x, (x, 1, n)).is_constant(n)
| False
| >>> Sum(x, (x, 1, n)).is_constant(x)
| True
| >>> eq = a*cos(x)**2 + a*sin(x)**2 - a
| >>> eq.is_constant()
| True
| >>> eq.subs({x: pi, a: 2}) == eq.subs({x: pi, a: 3}) == 0
| True
|
| >>> (0**x).is_constant()
| False
| >>> x.is_constant()
| False
| >>> (x**x).is_constant()
| False
| >>> one = cos(x)**2 + sin(x)**2
| >>> one.is_constant()
| True
| >>> ((one - 1)**(x + 1)).is_constant() in (True, False) # could be 0 or 1
| True
|
| is_meromorphic(self, x, a)
| This tests whether an expression is meromorphic as
| a function of the given symbol ``x`` at the point ``a``.
|
| This method is intended as a quick test that will return
| None if no decision can be made without simplification or
| more detailed analysis.
|
| Examples
| ========
|
| >>> from sympy import zoo, log, sin, sqrt
| >>> from sympy.abc import x
|
| >>> f = 1/x**2 + 1 - 2*x**3
| >>> f.is_meromorphic(x, 0)
| True
| >>> f.is_meromorphic(x, 1)
| True
| >>> f.is_meromorphic(x, zoo)
| True
|
| >>> g = x**log(3)
| >>> g.is_meromorphic(x, 0)
| False
| >>> g.is_meromorphic(x, 1)
| True
| >>> g.is_meromorphic(x, zoo)
| False
|
| >>> h = sin(1/x)*x**2
| >>> h.is_meromorphic(x, 0)
| False
| >>> h.is_meromorphic(x, 1)
| True
| >>> h.is_meromorphic(x, zoo)
| True
|
| Multivalued functions are considered meromorphic when their
| branches are meromorphic. Thus most functions are meromorphic
| everywhere except at essential singularities and branch points.
| In particular, they will be meromorphic also on branch cuts
| except at their endpoints.
|
| >>> log(x).is_meromorphic(x, -1)
| True
| >>> log(x).is_meromorphic(x, 0)
| False
| >>> sqrt(x).is_meromorphic(x, -1)
| True
| >>> sqrt(x).is_meromorphic(x, 0)
| False
|
| is_polynomial(self, *syms)
| Return True if self is a polynomial in syms and False otherwise.
|
| This checks if self is an exact polynomial in syms. This function
| returns False for expressions that are "polynomials" with symbolic
| exponents. Thus, you should be able to apply polynomial algorithms to
| expressions for which this returns True, and Poly(expr, \*syms) should
| work if and only if expr.is_polynomial(\*syms) returns True. The
| polynomial does not have to be in expanded form. If no symbols are
| given, all free symbols in the expression will be used.
|
| This is not part of the assumptions system. You cannot do
| Symbol('z', polynomial=True).
|
| Examples
| ========
|
| >>> from sympy import Symbol
| >>> x = Symbol('x')
| >>> ((x**2 + 1)**4).is_polynomial(x)
| True
| >>> ((x**2 + 1)**4).is_polynomial()
| True
| >>> (2**x + 1).is_polynomial(x)
| False
|
|
| >>> n = Symbol('n', nonnegative=True, integer=True)
| >>> (x**n + 1).is_polynomial(x)
| False
|
| This function does not attempt any nontrivial simplifications that may
| result in an expression that does not appear to be a polynomial to
| become one.
|
| >>> from sympy import sqrt, factor, cancel
| >>> y = Symbol('y', positive=True)
| >>> a = sqrt(y**2 + 2*y + 1)
| >>> a.is_polynomial(y)
| False
| >>> factor(a)
| y + 1
| >>> factor(a).is_polynomial(y)
| True
|
| >>> b = (y**2 + 2*y + 1)/(y + 1)
| >>> b.is_polynomial(y)
| False
| >>> cancel(b)
| y + 1
| >>> cancel(b).is_polynomial(y)
| True
|
| See also .is_rational_function()
|
| is_rational_function(self, *syms)
| Test whether function is a ratio of two polynomials in the given
| symbols, syms. When syms is not given, all free symbols will be used.
| The rational function does not have to be in expanded or in any kind of
| canonical form.
|
| This function returns False for expressions that are "rational
| functions" with symbolic exponents. Thus, you should be able to call
| .as_numer_denom() and apply polynomial algorithms to the result for
| expressions for which this returns True.
|
| This is not part of the assumptions system. You cannot do
| Symbol('z', rational_function=True).
|
| Examples
| ========
|
| >>> from sympy import Symbol, sin
| >>> from sympy.abc import x, y
|
| >>> (x/y).is_rational_function()
| True
|
| >>> (x**2).is_rational_function()
| True
|
| >>> (x/sin(y)).is_rational_function(y)
| False
|
| >>> n = Symbol('n', integer=True)
| >>> (x**n + 1).is_rational_function(x)
| False
|
| This function does not attempt any nontrivial simplifications that may
| result in an expression that does not appear to be a rational function
| to become one.
|
| >>> from sympy import sqrt, factor
| >>> y = Symbol('y', positive=True)
| >>> a = sqrt(y**2 + 2*y + 1)/y
| >>> a.is_rational_function(y)
| False
| >>> factor(a)
| (y + 1)/y
| >>> factor(a).is_rational_function(y)
| True
|
| See also is_algebraic_expr().
|
| leadterm(self, x, cdir=0)
| Returns the leading term a*x**b as a tuple (a, b).
|
| Examples
| ========
|
| >>> from sympy.abc import x
| >>> (1+x+x**2).leadterm(x)
| (1, 0)
| >>> (1/x**2+x+x**2).leadterm(x)
| (1, -2)
|
| limit(self, x, xlim, dir='+')
| Compute limit x->xlim.
|
| lseries(self, x=None, x0=0, dir='+', logx=None, cdir=0)
| Wrapper for series yielding an iterator of the terms of the series.
|
| Note: an infinite series will yield an infinite iterator. The following,
| for exaxmple, will never terminate. It will just keep printing terms
| of the sin(x) series::
|
| for term in sin(x).lseries(x):
| print term
|
| The advantage of lseries() over nseries() is that many times you are
| just interested in the next term in the series (i.e. the first term for
| example), but you don't know how many you should ask for in nseries()
| using the "n" parameter.
|
| See also nseries().
|
| normal(self)
| expression -> a/b
|
| See Also
| ========
|
| as_numer_denom: return ``(a, b)`` instead of ``a/b``
|
| nseries(self, x=None, x0=0, n=6, dir='+', logx=None, cdir=0)
| Wrapper to _eval_nseries if assumptions allow, else to series.
|
| If x is given, x0 is 0, dir='+', and self has x, then _eval_nseries is
| called. This calculates "n" terms in the innermost expressions and
| then builds up the final series just by "cross-multiplying" everything
| out.
|
| The optional ``logx`` parameter can be used to replace any log(x) in the
| returned series with a symbolic value to avoid evaluating log(x) at 0. A
| symbol to use in place of log(x) should be provided.
|
| Advantage -- it's fast, because we don't have to determine how many
| terms we need to calculate in advance.
|
| Disadvantage -- you may end up with less terms than you may have
| expected, but the O(x**n) term appended will always be correct and
| so the result, though perhaps shorter, will also be correct.
|
| If any of those assumptions is not met, this is treated like a
| wrapper to series which will try harder to return the correct
| number of terms.
|
| See also lseries().
|
| Examples
| ========
|
| >>> from sympy import sin, log, Symbol
| >>> from sympy.abc import x, y
| >>> sin(x).nseries(x, 0, 6)
| x - x**3/6 + x**5/120 + O(x**6)
| >>> log(x+1).nseries(x, 0, 5)
| x - x**2/2 + x**3/3 - x**4/4 + O(x**5)
|
| Handling of the ``logx`` parameter --- in the following example the
| expansion fails since ``sin`` does not have an asymptotic expansion
| at -oo (the limit of log(x) as x approaches 0):
|
| >>> e = sin(log(x))
| >>> e.nseries(x, 0, 6)
| Traceback (most recent call last):
| ...
| PoleError: ...
| ...
| >>> logx = Symbol('logx')
| >>> e.nseries(x, 0, 6, logx=logx)
| sin(logx)
|
| In the following example, the expansion works but gives only an Order term
| unless the ``logx`` parameter is used:
|
| >>> e = x**y
| >>> e.nseries(x, 0, 2)
| O(log(x)**2)
| >>> e.nseries(x, 0, 2, logx=logx)
| exp(logx*y)
|
| nsimplify(self, constants=[], tolerance=None, full=False)
| See the nsimplify function in sympy.simplify
|
| powsimp(self, *args, **kwargs)
| See the powsimp function in sympy.simplify
|
| primitive(self)
| Return the positive Rational that can be extracted non-recursively
| from every term of self (i.e., self is treated like an Add). This is
| like the as_coeff_Mul() method but primitive always extracts a positive
| Rational (never a negative or a Float).
|
| Examples
| ========
|
| >>> from sympy.abc import x
| >>> (3*(x + 1)**2).primitive()
| (3, (x + 1)**2)
| >>> a = (6*x + 2); a.primitive()
| (2, 3*x + 1)
| >>> b = (x/2 + 3); b.primitive()
| (1/2, x + 6)
| >>> (a*b).primitive() == (1, a*b)
| True
|
| radsimp(self, **kwargs)
| See the radsimp function in sympy.simplify
|
| ratsimp(self)
| See the ratsimp function in sympy.simplify
|
| removeO(self)
| Removes the additive O(..) symbol if there is one
|
| round(self, n=None)
| Return x rounded to the given decimal place.
|
| If a complex number would results, apply round to the real
| and imaginary components of the number.
|
| Examples
| ========
|
| >>> from sympy import pi, E, I, S, Number
| >>> pi.round()
| 3
| >>> pi.round(2)
| 3.14
| >>> (2*pi + E*I).round()
| 6 + 3*I
|
| The round method has a chopping effect:
|
| >>> (2*pi + I/10).round()
| 6
| >>> (pi/10 + 2*I).round()
| 2*I
| >>> (pi/10 + E*I).round(2)
| 0.31 + 2.72*I
|
| Notes
| =====
|
| The Python ``round`` function uses the SymPy ``round`` method so it
| will always return a SymPy number (not a Python float or int):
|
| >>> isinstance(round(S(123), -2), Number)
| True
|
| separate(self, deep=False, force=False)
| See the separate function in sympy.simplify
|
| series(self, x=None, x0=0, n=6, dir='+', logx=None, cdir=0)
| Series expansion of "self" around ``x = x0`` yielding either terms of
| the series one by one (the lazy series given when n=None), else
| all the terms at once when n != None.
|
| Returns the series expansion of "self" around the point ``x = x0``
| with respect to ``x`` up to ``O((x - x0)**n, x, x0)`` (default n is 6).
|
| If ``x=None`` and ``self`` is univariate, the univariate symbol will
| be supplied, otherwise an error will be raised.
|
| Parameters
| ==========
|
| expr : Expression
| The expression whose series is to be expanded.
|
| x : Symbol
| It is the variable of the expression to be calculated.
|
| x0 : Value
| The value around which ``x`` is calculated. Can be any value
| from ``-oo`` to ``oo``.
|
| n : Value
| The number of terms upto which the series is to be expanded.
|
| dir : String, optional
| The series-expansion can be bi-directional. If ``dir="+"``,
| then (x->x0+). If ``dir="-", then (x->x0-). For infinite
| ``x0`` (``oo`` or ``-oo``), the ``dir`` argument is determined
| from the direction of the infinity (i.e., ``dir="-"`` for
| ``oo``).
|
| logx : optional
| It is used to replace any log(x) in the returned series with a
| symbolic value rather than evaluating the actual value.
|
| cdir : optional
| It stands for complex direction, and indicates the direction
| from which the expansion needs to be evaluated.
|
| Examples
| ========
|
| >>> from sympy import cos, exp, tan
| >>> from sympy.abc import x, y
| >>> cos(x).series()
| 1 - x**2/2 + x**4/24 + O(x**6)
| >>> cos(x).series(n=4)
| 1 - x**2/2 + O(x**4)
| >>> cos(x).series(x, x0=1, n=2)
| cos(1) - (x - 1)*sin(1) + O((x - 1)**2, (x, 1))
| >>> e = cos(x + exp(y))
| >>> e.series(y, n=2)
| cos(x + 1) - y*sin(x + 1) + O(y**2)
| >>> e.series(x, n=2)
| cos(exp(y)) - x*sin(exp(y)) + O(x**2)
|
| If ``n=None`` then a generator of the series terms will be returned.
|
| >>> term=cos(x).series(n=None)
| >>> [next(term) for i in range(2)]
| [1, -x**2/2]
|
| For ``dir=+`` (default) the series is calculated from the right and
| for ``dir=-`` the series from the left. For smooth functions this
| flag will not alter the results.
|
| >>> abs(x).series(dir="+")
| x
| >>> abs(x).series(dir="-")
| -x
| >>> f = tan(x)
| >>> f.series(x, 2, 6, "+")
| tan(2) + (1 + tan(2)**2)*(x - 2) + (x - 2)**2*(tan(2)**3 + tan(2)) +
| (x - 2)**3*(1/3 + 4*tan(2)**2/3 + tan(2)**4) + (x - 2)**4*(tan(2)**5 +
| 5*tan(2)**3/3 + 2*tan(2)/3) + (x - 2)**5*(2/15 + 17*tan(2)**2/15 +
| 2*tan(2)**4 + tan(2)**6) + O((x - 2)**6, (x, 2))
|
| >>> f.series(x, 2, 3, "-")
| tan(2) + (2 - x)*(-tan(2)**2 - 1) + (2 - x)**2*(tan(2)**3 + tan(2))
| + O((x - 2)**3, (x, 2))
|
| Returns
| =======
|
| Expr : Expression
| Series expansion of the expression about x0
|
| Raises
| ======
|
| TypeError
| If "n" and "x0" are infinity objects
|
| PoleError
| If "x0" is an infinity object
|
| sort_key(self, order=None)
| Return a sort key.
|
| Examples
| ========
|
| >>> from sympy.core import S, I
|
| >>> sorted([S(1)/2, I, -I], key=lambda x: x.sort_key())
| [1/2, -I, I]
|
| >>> S("[x, 1/x, 1/x**2, x**2, x**(1/2), x**(1/4), x**(3/2)]")
| [x, 1/x, x**(-2), x**2, sqrt(x), x**(1/4), x**(3/2)]
| >>> sorted(_, key=lambda x: x.sort_key())
| [x**(-2), 1/x, x**(1/4), sqrt(x), x, x**(3/2), x**2]
|
| taylor_term(self, n, x, *previous_terms)
| General method for the taylor term.
|
| This method is slow, because it differentiates n-times. Subclasses can
| redefine it to make it faster by using the "previous_terms".
|
| together(self, *args, **kwargs)
| See the together function in sympy.polys
|
| transpose(self)
|
| trigsimp(self, **args)
| See the trigsimp function in sympy.simplify
|
| ----------------------------------------------------------------------
| Readonly properties inherited from sympy.core.expr.Expr:
|
| expr_free_symbols
| Like ``free_symbols``, but returns the free symbols only if they are contained in an expression node.
|
| Examples
| ========
|
| >>> from sympy.abc import x, y
| >>> (x + y).expr_free_symbols
| {x, y}
|
| If the expression is contained in a non-expression object, don't return
| the free symbols. Compare:
|
| >>> from sympy import Tuple
| >>> t = Tuple(x + y)
| >>> t.expr_free_symbols
| set()
| >>> t.free_symbols
| {x, y}
|
| is_number
| Returns True if ``self`` has no free symbols and no
| undefined functions (AppliedUndef, to be precise). It will be
| faster than ``if not self.free_symbols``, however, since
| ``is_number`` will fail as soon as it hits a free symbol
| or undefined function.
|
| Examples
| ========
|
| >>> from sympy import Integral, cos, sin, pi
| >>> from sympy.core.function import Function
| >>> from sympy.abc import x
| >>> f = Function('f')
|
| >>> x.is_number
| False
| >>> f(1).is_number
| False
| >>> (2*x).is_number
| False
| >>> (2 + Integral(2, x)).is_number
| False
| >>> (2 + Integral(2, (x, 1, 2))).is_number
| True
|
| Not all numbers are Numbers in the SymPy sense:
|
| >>> pi.is_number, pi.is_Number
| (True, False)
|
| If something is a number it should evaluate to a number with
| real and imaginary parts that are Numbers; the result may not
| be comparable, however, since the real and/or imaginary part
| of the result may not have precision.
|
| >>> cos(1).is_number and cos(1).is_comparable
| True
|
| >>> z = cos(1)**2 + sin(1)**2 - 1
| >>> z.is_number
| True
| >>> z.is_comparable
| False
|
| See Also
| ========
|
| sympy.core.basic.Basic.is_comparable
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from sympy.core.expr.Expr:
|
| is_scalar = True
|
| ----------------------------------------------------------------------
| Methods inherited from sympy.core.basic.Basic:
|
| __getnewargs__(self)
|
| __getstate__(self)
|
| __ne__(self, other)
| ``a != b`` -> Compare two symbolic trees and see whether they are different
|
| this is the same as:
|
| ``a.compare(b) != 0``
|
| but faster
|
| __reduce_ex__(self, proto)
| Pickling support.
|
| __setstate__(self, state)
|
| as_dummy(self)
| Return the expression with any objects having structurally
| bound symbols replaced with unique, canonical symbols within
| the object in which they appear and having only the default
| assumption for commutativity being True. When applied to a
| symbol a new symbol having only the same commutativity will be
| returned.
|
| Examples
| ========
|
| >>> from sympy import Integral, Symbol
| >>> from sympy.abc import x
| >>> r = Symbol('r', real=True)
| >>> Integral(r, (r, x)).as_dummy()
| Integral(_0, (_0, x))
| >>> _.variables[0].is_real is None
| True
| >>> r.as_dummy()
| _r
|
| Notes
| =====
|
| Any object that has structurally bound variables should have
| a property, `bound_symbols` that returns those symbols
| appearing in the object.
|
| atoms(self, *types)
| Returns the atoms that form the current object.
|
| By default, only objects that are truly atomic and can't
| be divided into smaller pieces are returned: symbols, numbers,
| and number symbols like I and pi. It is possible to request
| atoms of any type, however, as demonstrated below.
|
| Examples
| ========
|
| >>> from sympy import I, pi, sin
| >>> from sympy.abc import x, y
| >>> (1 + x + 2*sin(y + I*pi)).atoms()
| {1, 2, I, pi, x, y}
|
| If one or more types are given, the results will contain only
| those types of atoms.
|
| >>> from sympy import Number, NumberSymbol, Symbol
| >>> (1 + x + 2*sin(y + I*pi)).atoms(Symbol)
| {x, y}
|
| >>> (1 + x + 2*sin(y + I*pi)).atoms(Number)
| {1, 2}
|
| >>> (1 + x + 2*sin(y + I*pi)).atoms(Number, NumberSymbol)
| {1, 2, pi}
|
| >>> (1 + x + 2*sin(y + I*pi)).atoms(Number, NumberSymbol, I)
| {1, 2, I, pi}
|
| Note that I (imaginary unit) and zoo (complex infinity) are special
| types of number symbols and are not part of the NumberSymbol class.
|
| The type can be given implicitly, too:
|
| >>> (1 + x + 2*sin(y + I*pi)).atoms(x) # x is a Symbol
| {x, y}
|
| Be careful to check your assumptions when using the implicit option
| since ``S(1).is_Integer = True`` but ``type(S(1))`` is ``One``, a special type
| of sympy atom, while ``type(S(2))`` is type ``Integer`` and will find all
| integers in an expression:
|
| >>> from sympy import S
| >>> (1 + x + 2*sin(y + I*pi)).atoms(S(1))
| {1}
|
| >>> (1 + x + 2*sin(y + I*pi)).atoms(S(2))
| {1, 2}
|
| Finally, arguments to atoms() can select more than atomic atoms: any
| sympy type (loaded in core/__init__.py) can be listed as an argument
| and those types of "atoms" as found in scanning the arguments of the
| expression recursively:
|
| >>> from sympy import Function, Mul
| >>> from sympy.core.function import AppliedUndef
| >>> f = Function('f')
| >>> (1 + f(x) + 2*sin(y + I*pi)).atoms(Function)
| {f(x), sin(y + I*pi)}
| >>> (1 + f(x) + 2*sin(y + I*pi)).atoms(AppliedUndef)
| {f(x)}
|
| >>> (1 + x + 2*sin(y + I*pi)).atoms(Mul)
| {I*pi, 2*sin(y + I*pi)}
|
| compare(self, other)
| Return -1, 0, 1 if the object is smaller, equal, or greater than other.
|
| Not in the mathematical sense. If the object is of a different type
| from the "other" then their classes are ordered according to
| the sorted_classes list.
|
| Examples
| ========
|
| >>> from sympy.abc import x, y
| >>> x.compare(y)
| -1
| >>> x.compare(x)
| 0
| >>> y.compare(x)
| 1
|
| copy(self)
|
| count(self, query)
| Count the number of matching subexpressions.
|
| doit(self, **hints)
| Evaluate objects that are not evaluated by default like limits,
| integrals, sums and products. All objects of this kind will be
| evaluated recursively, unless some species were excluded via 'hints'
| or unless the 'deep' hint was set to 'False'.
|
| >>> from sympy import Integral
| >>> from sympy.abc import x
|
| >>> 2*Integral(x, x)
| 2*Integral(x, x)
|
| >>> (2*Integral(x, x)).doit()
| x**2
|
| >>> (2*Integral(x, x)).doit(deep=False)
| 2*Integral(x, x)
|
| dummy_eq(self, other, symbol=None)
| Compare two expressions and handle dummy symbols.
|
| Examples
| ========
|
| >>> from sympy import Dummy
| >>> from sympy.abc import x, y
|
| >>> u = Dummy('u')
|
| >>> (u**2 + 1).dummy_eq(x**2 + 1)
| True
| >>> (u**2 + 1) == (x**2 + 1)
| False
|
| >>> (u**2 + y).dummy_eq(x**2 + y, x)
| True
| >>> (u**2 + y).dummy_eq(x**2 + y, y)
| False
|
| find(self, query, group=False)
| Find all subexpressions matching a query.
|
| has(self, *patterns)
| Test whether any subexpression matches any of the patterns.
|
| Examples
| ========
|
| >>> from sympy import sin
| >>> from sympy.abc import x, y, z
| >>> (x**2 + sin(x*y)).has(z)
| False
| >>> (x**2 + sin(x*y)).has(x, y, z)
| True
| >>> x.has(x)
| True
|
| Note ``has`` is a structural algorithm with no knowledge of
| mathematics. Consider the following half-open interval:
|
| >>> from sympy.sets import Interval
| >>> i = Interval.Lopen(0, 5); i
| Interval.Lopen(0, 5)
| >>> i.args
| (0, 5, True, False)
| >>> i.has(4) # there is no "4" in the arguments
| False
| >>> i.has(0) # there *is* a "0" in the arguments
| True
|
| Instead, use ``contains`` to determine whether a number is in the
| interval or not:
|
| >>> i.contains(4)
| True
| >>> i.contains(0)
| False
|
|
| Note that ``expr.has(*patterns)`` is exactly equivalent to
| ``any(expr.has(p) for p in patterns)``. In particular, ``False`` is
| returned when the list of patterns is empty.
|
| >>> x.has()
| False
|
| is_hypergeometric(self, k)
|
| match(self, pattern, old=False)
| Pattern matching.
|
| Wild symbols match all.
|
| Return ``None`` when expression (self) does not match
| with pattern. Otherwise return a dictionary such that::
|
| pattern.xreplace(self.match(pattern)) == self
|
| Examples
| ========
|
| >>> from sympy import Wild, Sum
| >>> from sympy.abc import x, y
| >>> p = Wild("p")
| >>> q = Wild("q")
| >>> r = Wild("r")
| >>> e = (x+y)**(x+y)
| >>> e.match(p**p)
| {p_: x + y}
| >>> e.match(p**q)
| {p_: x + y, q_: x + y}
| >>> e = (2*x)**2
| >>> e.match(p*q**r)
| {p_: 4, q_: x, r_: 2}
| >>> (p*q**r).xreplace(e.match(p*q**r))
| 4*x**2
|
| Structurally bound symbols are ignored during matching:
|
| >>> Sum(x, (x, 1, 2)).match(Sum(y, (y, 1, p)))
| {p_: 2}
|
| But they can be identified if desired:
|
| >>> Sum(x, (x, 1, 2)).match(Sum(q, (q, 1, p)))
| {p_: 2, q_: x}
|
| The ``old`` flag will give the old-style pattern matching where
| expressions and patterns are essentially solved to give the
| match. Both of the following give None unless ``old=True``:
|
| >>> (x - 2).match(p - x, old=True)
| {p_: 2*x - 2}
| >>> (2/x).match(p*x, old=True)
| {p_: 2/x**2}
|
| matches(self, expr, repl_dict={}, old=False)
| Helper method for match() that looks for a match between Wild symbols
| in self and expressions in expr.
|
| Examples
| ========
|
| >>> from sympy import symbols, Wild, Basic
| >>> a, b, c = symbols('a b c')
| >>> x = Wild('x')
| >>> Basic(a + x, x).matches(Basic(a + b, c)) is None
| True
| >>> Basic(a + x, x).matches(Basic(a + b + c, b + c))
| {x_: b + c}
|
| rcall(self, *args)
| Apply on the argument recursively through the expression tree.
|
| This method is used to simulate a common abuse of notation for
| operators. For instance in SymPy the the following will not work:
|
| ``(x+Lambda(y, 2*y))(z) == x+2*z``,
|
| however you can use
|
| >>> from sympy import Lambda
| >>> from sympy.abc import x, y, z
| >>> (x + Lambda(y, 2*y)).rcall(z)
| x + 2*z
|
| refine(self, assumption=True)
| See the refine function in sympy.assumptions
|
| replace(self, query, value, map=False, simultaneous=True, exact=None)
| Replace matching subexpressions of ``self`` with ``value``.
|
| If ``map = True`` then also return the mapping {old: new} where ``old``
| was a sub-expression found with query and ``new`` is the replacement
| value for it. If the expression itself doesn't match the query, then
| the returned value will be ``self.xreplace(map)`` otherwise it should
| be ``self.subs(ordered(map.items()))``.
|
| Traverses an expression tree and performs replacement of matching
| subexpressions from the bottom to the top of the tree. The default
| approach is to do the replacement in a simultaneous fashion so
| changes made are targeted only once. If this is not desired or causes
| problems, ``simultaneous`` can be set to False.
|
| In addition, if an expression containing more than one Wild symbol
| is being used to match subexpressions and the ``exact`` flag is None
| it will be set to True so the match will only succeed if all non-zero
| values are received for each Wild that appears in the match pattern.
| Setting this to False accepts a match of 0; while setting it True
| accepts all matches that have a 0 in them. See example below for
| cautions.
|
| The list of possible combinations of queries and replacement values
| is listed below:
|
| Examples
| ========
|
| Initial setup
|
| >>> from sympy import log, sin, cos, tan, Wild, Mul, Add
| >>> from sympy.abc import x, y
| >>> f = log(sin(x)) + tan(sin(x**2))
|
| 1.1. type -> type
| obj.replace(type, newtype)
|
| When object of type ``type`` is found, replace it with the
| result of passing its argument(s) to ``newtype``.
|
| >>> f.replace(sin, cos)
| log(cos(x)) + tan(cos(x**2))
| >>> sin(x).replace(sin, cos, map=True)
| (cos(x), {sin(x): cos(x)})
| >>> (x*y).replace(Mul, Add)
| x + y
|
| 1.2. type -> func
| obj.replace(type, func)
|
| When object of type ``type`` is found, apply ``func`` to its
| argument(s). ``func`` must be written to handle the number
| of arguments of ``type``.
|
| >>> f.replace(sin, lambda arg: sin(2*arg))
| log(sin(2*x)) + tan(sin(2*x**2))
| >>> (x*y).replace(Mul, lambda *args: sin(2*Mul(*args)))
| sin(2*x*y)
|
| 2.1. pattern -> expr
| obj.replace(pattern(wild), expr(wild))
|
| Replace subexpressions matching ``pattern`` with the expression
| written in terms of the Wild symbols in ``pattern``.
|
| >>> a, b = map(Wild, 'ab')
| >>> f.replace(sin(a), tan(a))
| log(tan(x)) + tan(tan(x**2))
| >>> f.replace(sin(a), tan(a/2))
| log(tan(x/2)) + tan(tan(x**2/2))
| >>> f.replace(sin(a), a)
| log(x) + tan(x**2)
| >>> (x*y).replace(a*x, a)
| y
|
| Matching is exact by default when more than one Wild symbol
| is used: matching fails unless the match gives non-zero
| values for all Wild symbols:
|
| >>> (2*x + y).replace(a*x + b, b - a)
| y - 2
| >>> (2*x).replace(a*x + b, b - a)
| 2*x
|
| When set to False, the results may be non-intuitive:
|
| >>> (2*x).replace(a*x + b, b - a, exact=False)
| 2/x
|
| 2.2. pattern -> func
| obj.replace(pattern(wild), lambda wild: expr(wild))
|
| All behavior is the same as in 2.1 but now a function in terms of
| pattern variables is used rather than an expression:
|
| >>> f.replace(sin(a), lambda a: sin(2*a))
| log(sin(2*x)) + tan(sin(2*x**2))
|
| 3.1. func -> func
| obj.replace(filter, func)
|
| Replace subexpression ``e`` with ``func(e)`` if ``filter(e)``
| is True.
|
| >>> g = 2*sin(x**3)
| >>> g.replace(lambda expr: expr.is_Number, lambda expr: expr**2)
| 4*sin(x**9)
|
| The expression itself is also targeted by the query but is done in
| such a fashion that changes are not made twice.
|
| >>> e = x*(x*y + 1)
| >>> e.replace(lambda x: x.is_Mul, lambda x: 2*x)
| 2*x*(2*x*y + 1)
|
| When matching a single symbol, `exact` will default to True, but
| this may or may not be the behavior that is desired:
|
| Here, we want `exact=False`:
|
| >>> from sympy import Function
| >>> f = Function('f')
| >>> e = f(1) + f(0)
| >>> q = f(a), lambda a: f(a + 1)
| >>> e.replace(*q, exact=False)
| f(1) + f(2)
| >>> e.replace(*q, exact=True)
| f(0) + f(2)
|
| But here, the nature of matching makes selecting
| the right setting tricky:
|
| >>> e = x**(1 + y)
| >>> (x**(1 + y)).replace(x**(1 + a), lambda a: x**-a, exact=False)
| x
| >>> (x**(1 + y)).replace(x**(1 + a), lambda a: x**-a, exact=True)
| x**(-x - y + 1)
| >>> (x**y).replace(x**(1 + a), lambda a: x**-a, exact=False)
| x
| >>> (x**y).replace(x**(1 + a), lambda a: x**-a, exact=True)
| x**(1 - y)
|
| It is probably better to use a different form of the query
| that describes the target expression more precisely:
|
| >>> (1 + x**(1 + y)).replace(
| ... lambda x: x.is_Pow and x.exp.is_Add and x.exp.args[0] == 1,
| ... lambda x: x.base**(1 - (x.exp - 1)))
| ...
| x**(1 - y) + 1
|
| See Also
| ========
|
| subs: substitution of subexpressions as defined by the objects
| themselves.
| xreplace: exact node replacement in expr tree; also capable of
| using matching rules
|
| rewrite(self, *args, **hints)
| Rewrite functions in terms of other functions.
|
| Rewrites expression containing applications of functions
| of one kind in terms of functions of different kind. For
| example you can rewrite trigonometric functions as complex
| exponentials or combinatorial functions as gamma function.
|
| As a pattern this function accepts a list of functions to
| to rewrite (instances of DefinedFunction class). As rule
| you can use string or a destination function instance (in
| this case rewrite() will use the str() function).
|
| There is also the possibility to pass hints on how to rewrite
| the given expressions. For now there is only one such hint
| defined called 'deep'. When 'deep' is set to False it will
| forbid functions to rewrite their contents.
|
| Examples
| ========
|
| >>> from sympy import sin, exp
| >>> from sympy.abc import x
|
| Unspecified pattern:
|
| >>> sin(x).rewrite(exp)
| -I*(exp(I*x) - exp(-I*x))/2
|
| Pattern as a single function:
|
| >>> sin(x).rewrite(sin, exp)
| -I*(exp(I*x) - exp(-I*x))/2
|
| Pattern as a list of functions:
|
| >>> sin(x).rewrite([sin, ], exp)
| -I*(exp(I*x) - exp(-I*x))/2
|
| simplify(self, **kwargs)
| See the simplify function in sympy.simplify
|
| subs(self, *args, **kwargs)
| Substitutes old for new in an expression after sympifying args.
|
| `args` is either:
| - two arguments, e.g. foo.subs(old, new)
| - one iterable argument, e.g. foo.subs(iterable). The iterable may be
| o an iterable container with (old, new) pairs. In this case the
| replacements are processed in the order given with successive
| patterns possibly affecting replacements already made.
| o a dict or set whose key/value items correspond to old/new pairs.
| In this case the old/new pairs will be sorted by op count and in
| case of a tie, by number of args and the default_sort_key. The
| resulting sorted list is then processed as an iterable container
| (see previous).
|
| If the keyword ``simultaneous`` is True, the subexpressions will not be
| evaluated until all the substitutions have been made.
|
| Examples
| ========
|
| >>> from sympy import pi, exp, limit, oo
| >>> from sympy.abc import x, y
| >>> (1 + x*y).subs(x, pi)
| pi*y + 1
| >>> (1 + x*y).subs({x:pi, y:2})
| 1 + 2*pi
| >>> (1 + x*y).subs([(x, pi), (y, 2)])
| 1 + 2*pi
| >>> reps = [(y, x**2), (x, 2)]
| >>> (x + y).subs(reps)
| 6
| >>> (x + y).subs(reversed(reps))
| x**2 + 2
|
| >>> (x**2 + x**4).subs(x**2, y)
| y**2 + y
|
| To replace only the x**2 but not the x**4, use xreplace:
|
| >>> (x**2 + x**4).xreplace({x**2: y})
| x**4 + y
|
| To delay evaluation until all substitutions have been made,
| set the keyword ``simultaneous`` to True:
|
| >>> (x/y).subs([(x, 0), (y, 0)])
| 0
| >>> (x/y).subs([(x, 0), (y, 0)], simultaneous=True)
| nan
|
| This has the added feature of not allowing subsequent substitutions
| to affect those already made:
|
| >>> ((x + y)/y).subs({x + y: y, y: x + y})
| 1
| >>> ((x + y)/y).subs({x + y: y, y: x + y}, simultaneous=True)
| y/(x + y)
|
| In order to obtain a canonical result, unordered iterables are
| sorted by count_op length, number of arguments and by the
| default_sort_key to break any ties. All other iterables are left
| unsorted.
|
| >>> from sympy import sqrt, sin, cos
| >>> from sympy.abc import a, b, c, d, e
|
| >>> A = (sqrt(sin(2*x)), a)
| >>> B = (sin(2*x), b)
| >>> C = (cos(2*x), c)
| >>> D = (x, d)
| >>> E = (exp(x), e)
|
| >>> expr = sqrt(sin(2*x))*sin(exp(x)*x)*cos(2*x) + sin(2*x)
|
| >>> expr.subs(dict([A, B, C, D, E]))
| a*c*sin(d*e) + b
|
| The resulting expression represents a literal replacement of the
| old arguments with the new arguments. This may not reflect the
| limiting behavior of the expression:
|
| >>> (x**3 - 3*x).subs({x: oo})
| nan
|
| >>> limit(x**3 - 3*x, x, oo)
| oo
|
| If the substitution will be followed by numerical
| evaluation, it is better to pass the substitution to
| evalf as
|
| >>> (1/x).evalf(subs={x: 3.0}, n=21)
| 0.333333333333333333333
|
| rather than
|
| >>> (1/x).subs({x: 3.0}).evalf(21)
| 0.333333333333333314830
|
| as the former will ensure that the desired level of precision is
| obtained.
|
| See Also
| ========
| replace: replacement capable of doing wildcard-like matching,
| parsing of match, and conditional replacements
| xreplace: exact node replacement in expr tree; also capable of
| using matching rules
| sympy.core.evalf.EvalfMixin.evalf: calculates the given formula to a desired level of precision
|
| xreplace lambda rule, **_
| # Function needs args so we define a property that returns
| # a function that takes args...and then use that function
| # to return the right value
|
| ----------------------------------------------------------------------
| Class methods inherited from sympy.core.basic.Basic:
|
| fromiter(args, **assumptions) from sympy.core.function.FunctionClass
| Create a new object from an iterable.
|
| This is a convenience function that allows one to create objects from
| any iterable, without having to convert to a list or tuple first.
|
| Examples
| ========
|
| >>> from sympy import Tuple
| >>> Tuple.fromiter(i for i in range(5))
| (0, 1, 2, 3, 4)
|
| ----------------------------------------------------------------------
| Readonly properties inherited from sympy.core.basic.Basic:
|
| args
| Returns a tuple of arguments of 'self'.
|
| Examples
| ========
|
| >>> from sympy import cot
| >>> from sympy.abc import x, y
|
| >>> cot(x).args
| (x,)
|
| >>> cot(x).args[0]
| x
|
| >>> (x*y).args
| (x, y)
|
| >>> (x*y).args[1]
| y
|
| Notes
| =====
|
| Never use self._args, always use self.args.
| Only use _args in __new__ when creating a new function.
| Don't override .args() from Basic (so that it's easy to
| change the interface in the future if needed).
|
| assumptions0
| Return object `type` assumptions.
|
| For example:
|
| Symbol('x', real=True)
| Symbol('x', integer=True)
|
| are different objects. In other words, besides Python type (Symbol in
| this case), the initial assumptions are also forming their typeinfo.
|
| Examples
| ========
|
| >>> from sympy import Symbol
| >>> from sympy.abc import x
| >>> x.assumptions0
| {'commutative': True}
| >>> x = Symbol("x", positive=True)
| >>> x.assumptions0
| {'commutative': True, 'complex': True, 'extended_negative': False,
| 'extended_nonnegative': True, 'extended_nonpositive': False,
| 'extended_nonzero': True, 'extended_positive': True, 'extended_real':
| True, 'finite': True, 'hermitian': True, 'imaginary': False,
| 'infinite': False, 'negative': False, 'nonnegative': True,
| 'nonpositive': False, 'nonzero': True, 'positive': True, 'real':
| True, 'zero': False}
|
| canonical_variables
| Return a dictionary mapping any variable defined in
| ``self.bound_symbols`` to Symbols that do not clash
| with any free symbols in the expression.
|
| Examples
| ========
|
| >>> from sympy import Lambda
| >>> from sympy.abc import x
| >>> Lambda(x, 2*x).canonical_variables
| {x: _0}
|
| free_symbols
| Return from the atoms of self those which are free symbols.
|
| For most expressions, all symbols are free symbols. For some classes
| this is not true. e.g. Integrals use Symbols for the dummy variables
| which are bound variables, so Integral has a method to return all
| symbols except those. Derivative keeps track of symbols with respect
| to which it will perform a derivative; those are
| bound variables, too, so it has its own free_symbols method.
|
| Any other method that uses bound variables should implement a
| free_symbols method.
|
| is_algebraic
|
| is_antihermitian
|
| is_commutative
|
| is_comparable
| Return True if self can be computed to a real number
| (or already is a real number) with precision, else False.
|
| Examples
| ========
|
| >>> from sympy import exp_polar, pi, I
| >>> (I*exp_polar(I*pi/2)).is_comparable
| True
| >>> (I*exp_polar(I*pi*2)).is_comparable
| False
|
| A False result does not mean that `self` cannot be rewritten
| into a form that would be comparable. For example, the
| difference computed below is zero but without simplification
| it does not evaluate to a zero with precision:
|
| >>> e = 2**pi*(1 + 2**pi)
| >>> dif = e - e.expand()
| >>> dif.is_comparable
| False
| >>> dif.n(2)._prec
| 1
|
| is_complex
|
| is_composite
|
| is_even
|
| is_extended_negative
|
| is_extended_nonnegative
|
| is_extended_nonpositive
|
| is_extended_nonzero
|
| is_extended_positive
|
| is_extended_real
|
| is_finite
|
| is_hermitian
|
| is_imaginary
|
| is_infinite
|
| is_integer
|
| is_irrational
|
| is_negative
|
| is_noninteger
|
| is_nonnegative
|
| is_nonpositive
|
| is_nonzero
|
| is_odd
|
| is_polar
|
| is_positive
|
| is_prime
|
| is_rational
|
| is_real
|
| is_transcendental
|
| is_zero
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from sympy.core.basic.Basic:
|
| is_Add = False
|
| is_AlgebraicNumber = False
|
| is_Atom = False
|
| is_Boolean = False
|
| is_Derivative = False
|
| is_Dummy = False
|
| is_Equality = False
|
| is_Float = False
|
| is_Indexed = False
|
| is_Integer = False
|
| is_MatAdd = False
|
| is_MatMul = False
|
| is_Matrix = False
|
| is_Mul = False
|
| is_Not = False
|
| is_Number = False
|
| is_NumberSymbol = False
|
| is_Order = False
|
| is_Piecewise = False
|
| is_Point = False
|
| is_Poly = False
|
| is_Pow = False
|
| is_Rational = False
|
| is_Relational = False
|
| is_Symbol = False
|
| is_Vector = False
|
| is_Wild = False
|
| is_symbol = False
|
| kind = UndefinedKind
|
| ----------------------------------------------------------------------
| Methods inherited from sympy.printing.defaults.Printable:
|
| __repr__ = __str__(self)
|
| __str__(self)
| Return str(self).
|
| ----------------------------------------------------------------------
| Methods inherited from sympy.core.evalf.EvalfMixin:
|
| evalf(self, n=15, subs=None, maxn=100, chop=False, strict=False, quad=None, verbose=False)
| Evaluate the given formula to an accuracy of *n* digits.
|
| Parameters
| ==========
|
| subs : dict, optional
| Substitute numerical values for symbols, e.g.
| ``subs={x:3, y:1+pi}``. The substitutions must be given as a
| dictionary.
|
| maxn : int, optional
| Allow a maximum temporary working precision of maxn digits.
|
| chop : bool or number, optional
| Specifies how to replace tiny real or imaginary parts in
| subresults by exact zeros.
|
| When ``True`` the chop value defaults to standard precision.
|
| Otherwise the chop value is used to determine the
| magnitude of "small" for purposes of chopping.
|
| >>> from sympy import N
| >>> x = 1e-4
| >>> N(x, chop=True)
| 0.000100000000000000
| >>> N(x, chop=1e-5)
| 0.000100000000000000
| >>> N(x, chop=1e-4)
| 0
|
| strict : bool, optional
| Raise ``PrecisionExhausted`` if any subresult fails to
| evaluate to full accuracy, given the available maxprec.
|
| quad : str, optional
| Choose algorithm for numerical quadrature. By default,
| tanh-sinh quadrature is used. For oscillatory
| integrals on an infinite interval, try ``quad='osc'``.
|
| verbose : bool, optional
| Print debug information.
|
| Notes
| =====
|
| When Floats are naively substituted into an expression,
| precision errors may adversely affect the result. For example,
| adding 1e16 (a Float) to 1 will truncate to 1e16; if 1e16 is
| then subtracted, the result will be 0.
| That is exactly what happens in the following:
|
| >>> from sympy.abc import x, y, z
| >>> values = {x: 1e16, y: 1, z: 1e16}
| >>> (x + y - z).subs(values)
| 0
|
| Using the subs argument for evalf is the accurate way to
| evaluate such an expression:
|
| >>> (x + y - z).evalf(subs=values)
| 1.00000000000000
|
| n = evalf(self, n=15, subs=None, maxn=100, chop=False, strict=False, quad=None, verbose=False)
smp.simplify(smp.assoc_legendre(n, m, x))
smp.assoc_legendre(3, 2, x)
smp.plot(x**2)
<sympy.plotting.plot.Plot at 0x7fbbdad61d30>
smp.plot(x**2, show = False)
<sympy.plotting.plot.Plot at 0x7fbbdfe760a0>
p1 = smp.plot(x**2, show = False)
p2 = smp.plot(x, show = False)
p1.append(p2[0])
p1
<sympy.plotting.plot.Plot at 0x7fbbdfe8cf40>
p1.show()
p3 = smp.plot(-x, show = False)
p1.append(p3[0])
p1.show()
smp.plot(smp.sin(x), show=True)
<sympy.plotting.plot.Plot at 0x7fbbe0debbe0>
smp.plot(x**3, (x, -5, 5), show=True)
<sympy.plotting.plot.Plot at 0x7fbbe0deb8e0>
smp.plot(x**3, x **2, x, (x, -5, 5), show=True)
<sympy.plotting.plot.Plot at 0x7fbbe10b73d0>
smp.plot((x**3, (x, -2, 2)), (x**2, (x, -4, 4)), show=True)
<sympy.plotting.plot.Plot at 0x7fbbe11ee310>
smp.plot_parametric((smp.cos(x), smp.sin(x), (x, -10, 10)))
<sympy.plotting.plot.Plot at 0x7fbbde57fa60>
u = smp.symbols('u')
expr1 = (u, smp.cos(2*smp.pi*u)/2 + 1/2)
expr2 = (u, smp.sin(2*smp.pi*u)/2 + 1/2)
p = smp.plot_parametric(expr1, expr2, (u, 0, 1), line_color='red')
p[0].line_color = 'm'
p.show()
p[1].line_color = 'green'
p.show()
smp.plotting.plot3d(x * u, (x, -3, 3), (u, -4, 4))
<sympy.plotting.plot.Plot at 0x7fbbe2ad3310>
y = smp.symbols('y')
smp.plotting.plot3d(x**2 * y**2, -x**2 * y**2, (x, -3, 3), (y, -4, 4))
<sympy.plotting.plot.Plot at 0x7fbbdcc89eb0>
smp.plotting.plot3d(smp.cos(x), smp.sin(x), (x, -3, 3))
<sympy.plotting.plot.Plot at 0x7fbbe37e9bb0>
smp.plotting.plot3d_parametric_line(smp.cos(x), smp.sin(x), x, (x, -10, 10))
<sympy.plotting.plot.Plot at 0x7fbbe390ab20>
smp.plotting.plot3d_parametric_surface(smp.cos(x+y), smp.sin(x-y), x-y, (x, -4, 4), (y, -5, 5))
<sympy.plotting.plot.Plot at 0x7fbbe48410d0>
smp.plot_implicit(smp.Eq(x ** 2 + y ** 2, 4))
<sympy.plotting.plot.Plot at 0x7fbbe4e051c0>
smp.plot_implicit(smp.Eq(x ** 2 + y ** 2, 4), (x, -2, 2), (y, -2, 2))
<sympy.plotting.plot.Plot at 0x7fbbe49275e0>
smp.plot_implicit(smp.Eq(x ** 2 + y ** 2, 4), (x, -2, 2), (y, -2, 2), depth = 2)
<sympy.plotting.plot.Plot at 0x7fbbde18d550>
smp.plot_implicit(y>x**2)
<sympy.plotting.plot.Plot at 0x7fbbf6050af0>
smp.plot_implicit(y<x**2)
<sympy.plotting.plot.Plot at 0x7fbbdcdb08b0>
smp.plot_implicit(y>x)
<sympy.plotting.plot.Plot at 0x7fbbc9ccd100>
smp.plot_implicit(smp.And(y>x, y>-x))
<sympy.plotting.plot.Plot at 0x7fbbdca2ceb0>
smp.plot_implicit(smp.Or(y>x, y>-x))
<sympy.plotting.plot.Plot at 0x7fbbe52923a0>
p1 = smp.plot(x, x**2, x**3, (x, -5, 5))
p2 = smp.plot((x**2, (x, -6, 6)), (x, (x, -5, 5)))
p3 = smp.plot(x**3, (x, -5, 5))
p4 = smp.plotting.plot3d(x*y, (x, -5, 5), (y, -5, 5))
smp.plotting.PlotGrid(2, 2, p1, p2 ,p3, p4)
<sympy.plotting.plot.PlotGrid at 0x7fbbe5d354f0>
smp.plotting.PlotGrid(1, 4, p1, p2 ,p3, p4)
<sympy.plotting.plot.PlotGrid at 0x7fbbc9f5a430>