Calculus

Some calculus-related methods waiting to find a better place in the Diofant modules tree.

diofant.calculus.singularities.singularities(f, x)[source]

Find singularities of real-valued function \(f\) with respect to \(x\).

Examples

>>> singularities(1/(1 + x), x)
{-1}
>>> singularities(exp(1/x) + log(x + 1), x)
{-1, 0}
>>> singularities(exp(1/log(x + 1)), x)
{0}

Notes

Removable singularities are not supported now.

References

class diofant.calculus.limits.Limit(e, z, z0, dir=None)[source]

Represents an unevaluated 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 (Expr or Reals, optional) – selects the direction (as sign(dir)) to approach the limit point if the dir is an Expr. For infinite z0, the default value is determined from the direction of the infinity (e.g., the limit from the left, dir=1, for oo). Otherwise, the default is the limit from the right, dir=-1. If dir=Reals, the limit is the bidirectional real limit.

Examples

>>> Limit(1/x, x, 0, dir=1)
Limit(1/x, x, 0, dir=1)
>>> _.doit()
-oo

See also

limit

doit(**hints)[source]

Evaluates limit.

Notes

First we handle some trivial cases (i.e. constant), then try Gruntz algorithm (see the gruntz module).

diofant.calculus.limits.limit(expr, z, z0, dir=None)[source]

Compute the directional limit of expr at the point z0.

Examples

>>> limit(1/x, x, 0)
oo
>>> limit(1/x, x, 0, dir=1)
-oo
>>> limit(1/x, x, oo)
0

See also

Limit

diofant.calculus.optimization.maximize(f, *v)[source]

Maximizes \(f\) with respect to given variables \(v\).

See also

minimize

diofant.calculus.optimization.minimize(f, *v)[source]

Minimizes \(f\) with respect to given variables \(v\).

Examples

>>> minimize(x**2, x)
(0, {x: 0})
>>> minimize([x**2, x >= 1], x)
(1, {x: 1})
>>> minimize([-x**2, x >= -2, x <= 1], x)
(-4, {x: -2})

See also

maximize

diofant.calculus.order.O[source]

alias of Order

class diofant.calculus.order.Order(expr, var=None, point=0, **kwargs)[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

  • var (Symbol, optional) – a variable of the expr. If not privided, the expression is assumed to be univariate and it’s variable is used.

  • point (Expr, optional) – a limit point, default is zero.

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:

>>> 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, x)

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(x) in O(1, x)
True
>>> O(x**2) in O(x)
True

Limit points other then zero 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)

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