Series¶
The series module implements series expansions as a function and many related functions.

class
diofant.series.limits.
Limit
[source]¶ Represents a directional limit of
expr
at the pointz0
.Parameters:  expr : Expr
algebraic expression
 z : Symbol
variable of the
expr
 z0 : Expr
limit point, \(z_0\)
 dir : {“+”, ““, “real”}, optional
For
dir="+"
(default) it calculates the limit from the right (\(z\to z_0 + 0\)) and fordir=""
the limit from the left (\(z\to z_0  0\)). Ifdir="real"
, the limit is the bidirectional real limit. For infinitez0
(oo
oroo
), thedir
argument is determined from the direction of the infinity (i.e.,dir=""
foroo
).
Examples
>>> Limit(sin(x)/x, x, 0) Limit(sin(x)/x, x, 0) >>> Limit(1/x, x, 0, dir="") Limit(1/x, x, 0, dir='')

doit
(**hints)[source]¶ Evaluates limit.
Notes
First we handle some trivial cases (i.e. constant), then try Gruntz algorithm (see the
gruntz
module).

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.

diofant.series.limits.
limit
(expr, z, z0, dir='+')[source]¶ Compute the directional limit of
expr
at the pointz0
.See also
Examples
>>> limit(sin(x)/x, x, 0) 1 >>> limit(1/x, x, 0, dir="+") oo >>> limit(1/x, x, 0, dir="") oo >>> limit(1/x, x, oo) 0

diofant.series.series.
series
(expr, x=None, x0=0, n=6, dir='+')[source]¶ Series expansion of
expr
inx
around pointx0
.See also

diofant.series.order.
O
¶ alias of
diofant.series.order.Order

class
diofant.series.order.
Order
[source]¶ Represents the limiting behavior of function.
The formal definition [1] for order symbol \(O(f(x))\) (Big O) is that \(g(x) \in O(f(x))\) as \(x\to a\) iff
\[\lim\limits_{x \rightarrow a} \sup \left\frac{g(x)}{f(x)}\right < \infty\]Parameters:  expr : Expr
an expression
 args : sequence of Symbol’s or pairs (Symbol, Expr), optional
If only symbols are provided, i.e. no limit point are passed, then the limit point is assumed to be zero. If no symbols are passed then all symbols in the expression are used.
References
[1] (1, 2) https//en.wikipedia.org/wiki/Big_O_notation Examples
The order of a function can be intuitively thought of representing all terms of powers greater than the one specified. For example, \(O(x^3)\) corresponds to any terms proportional to \(x^3, x^4,\ldots\) and any higher power. For a polynomial, this leaves terms proportional to \(x^2\), \(x\) and constants.
>>> 1 + x + x**2 + x**3 + x**4 + O(x**3) 1 + x + x**2 + O(x**3)
O(f(x))
is automatically transformed toO(f(x).as_leading_term(x))
:>>> O(x + x**2) O(x) >>> O(cos(x)) O(1)
Some arithmetic operations:
>>> O(x)*x O(x**2) >>> O(x)  O(x) O(x)
The Big O symbol is a set, so we support membership test:
>>> x in O(x) True >>> O(1) in O(1, x) True >>> O(1, x) in O(1) False >>> O(x) in O(1, x) True >>> O(x**2) in O(x) True
Limit points other then zero and multivariate Big O are also supported:
>>> O(x) == O(x, (x, 0)) True >>> O(x + x**2, (x, oo)) O(x**2, (x, oo)) >>> O(cos(x), (x, pi/2)) O(x  pi/2, (x, pi/2))
>>> O(1 + x*y) O(1, x, y) >>> O(1 + x*y, (x, 0), (y, 0)) O(1, x, y) >>> O(1 + x*y, (x, oo), (y, oo)) O(x*y, (x, oo), (y, oo))

contains
(expr)[source]¶ Membership test.
Returns:  Boolean or None
Return True if
expr
belongs toself
. Return False ifself
belongs toexpr
. Return None if the inclusion relation cannot be determined.

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.

diofant.series.residues.
residue
(expr, x, x0)[source]¶ Finds the residue of
expr
at the pointx=x0
.The residue is defined [1] as the coefficient of \(1/(x  x_0)\) in the power series expansion around \(x=x_0\).
This notion is essential for the Residue Theorem [2]
References
[1] (1, 2) https//en.wikipedia.org/wiki/Residue_%28complex_analysis%29 [2] (1, 2) https//en.wikipedia.org/wiki/Residue_theorem Examples
>>> residue(1/x, x, 0) 1 >>> residue(1/x**2, x, 0) 0 >>> residue(2/sin(x), x, 0) 2