# 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 point z0.

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 for dir="-" the limit from the left ($$z\to z_0 - 0$$). If dir="real", the limit is the bidirectional real limit. For infinite z0 (oo or -oo), the dir argument is determined from the direction of the infinity (i.e., dir="-" for oo).

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

diofant.series.limits.limit(expr, z, z0, dir='+')[source]

Compute the directional limit of expr at the point z0.

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 in x around point x0.

diofant.series.order.O
class diofant.series.order.Order[source]

Represents the limiting behavior of function.

The formal definition 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.

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


References

contains(expr)[source]

Membership test.

Returns: Boolean or None – Return True if expr belongs to self. Return False if self belongs to expr. Return None if the inclusion relation cannot be determined.
diofant.series.residues.residue(expr, x, x0)[source]

Finds the residue of expr at the point x=x0.

The residue is defined 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.

Examples

>>> residue(1/x, x, 0)
1
>>> residue(1/x**2, x, 0)
0
>>> residue(2/sin(x), x, 0)
2


References