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
exprat the pointz0.- Parameters:
expr (Expr) – algebraic expression
z (Symbol) – variable of the
exprz0 (Expr) – limit point, \(z_0\)
dir (Expr or Reals, optional) – selects the direction (as
sign(dir)) to approach the limit point if thediris an Expr. For infinitez0, the default value is determined from the direction of the infinity (e.g., the limit from the left,dir=1, foroo). Otherwise, the default is the limit from the right,dir=-1. Ifdir=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
- diofant.calculus.limits.limit(expr, z, z0, dir=None, **kwargs)[source]
Compute the directional limit of
exprat the pointz0.Examples
>>> limit(1/x, x, 0) oo >>> limit(1/x, x, 0, dir=1) -oo >>> limit(1/x, x, oo) 0
See also
- diofant.calculus.optimization.maximize(f, *v)[source]
Maximizes \(f\) with respect to given variables \(v\).
See also
- 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
- 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 toO(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
- diofant.calculus.residues.residue(expr, x, x0)[source]
Finds the residue of
exprat the pointx=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