forked from sympy/sympy-paper
/
calculus.tex
65 lines (61 loc) · 2.98 KB
/
calculus.tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
Integrals are calculated with the \verb|integrate| function. SymPy
implements a combination of the Risch
algorithm~\cite{bronstein2005integration}, table lookups, a reimplementation
of Manuel Bronstein's ``Poor Man's Integrator''~\cite{Bronstein2005pmint}, and
an algorithm for computing integrals based on Meijer G-functions~\cite{Roach1996hyper,roach1997meijerg}. These allow
SymPy to compute a wide variety of indefinite and definite integrals. The
Meijer G-function algorithm and the Risch algorithm are respectively
demonstrated below by the computation of \[\int_{0}^{\infty} e^{-s t}\log{\left (t \right )}\, dt = - \frac{ \log{\left (s \right )} + \gamma}{s}\] and \[\int \frac{- 2 x^{2} \left(\log{\left (x \right )} + 1\right) e^{x^{2}} + {\left(e^{x^{2}} + 1\right)}^{2}}{x {\left(e^{x^{2}} + 1\right)}^{2} \left(\log{\left (x \right )} + 1\right)}\, dx = \log{\left (\log{\left (x \right )} + 1 \right )} + \frac{1}{e^{x^{2}} + 1}.\]
\begin{verbatim}
>>> s, t = symbols('s t', positive=True)
>>> integrate(exp(-s*t)*log(t), (t, 0, oo)).simplify()
-(log(s) + EulerGamma)/s
>>> integrate((-2*x**2*(log(x) + 1)*exp(x**2) +
... (exp(x**2) + 1)**2)/(x*(exp(x**2) + 1)**2*(log(x) + 1)), x)
log(log(x) + 1) + 1/(exp(x**2) + 1)
\end{verbatim}
Derivatives are computed with the \verb|diff| function, which recursively uses
the various differentiation rules.
\begin{verbatim}
>>> diff(sin(x)*exp(x), x)
exp(x)*sin(x) + exp(x)*cos(x)
\end{verbatim}
Summations and products are computed with \verb|summation| and \verb|product|,
respectively. Summations are computed using a combination of Gosper's
algorithm~\cite{gosper1978decision}, an algorithm that uses Meijer G-functions~\cite{Roach1996hyper,roach1997meijerg}, and heuristics. Products
are computed via a suite of heuristics.
% TODO: Are there other summation algorithms implemented?
% TODO: A good summation example or two
\begin{verbatim}
>>> i, n = symbols('i n')
>>> summation(2**i, (i, 0, n - 1))
2**n - 1
>>> summation(i*factorial(i), (i, 1, n))
n*factorial(n) + factorial(n) - 1
\end{verbatim}
Limits are computed with the \verb|limit| function. The limit module
implements the Gruntz algorithm~\cite{Gruntz1996limits} for computing symbolic
limits.
For example, the following computes
$\lim\limits_{x\to \infty} x\sin(\frac{1}{x})=1$. Note that SymPy denotes
$\infty$ as \verb|oo|.
\begin{verbatim}
>>> limit(x*sin(1/x), x, oo)
1
\end{verbatim}
As a more complex example, SymPy computes \[\lim\limits_{x\to 0}{\left(2 e^{\frac{1 - \cos{\left (x \right )}}{\sin{\left (x \right )}}} -
1\right)}^{\frac{\sinh{\left (x \right )}}{\operatorname{atan}^{2}{\left (x
\right )}}} = e.\]
\begin{verbatim}
>>> limit((2*E**((1-cos(x))/sin(x))-1)**(sinh(x)/atan(x)**2), x, 0)
E
\end{verbatim}
Integrals, derivatives, summations, products, and limits that cannot be
computed return unevaluated objects. These can also be created directly if the
user chooses.
\begin{verbatim}
>>> integrate(x**x, x)
Integral(x**x, x)
>>> Sum(2**i, (i, 0, n - 1))
Sum(2**i, (i, 0, n - 1))
\end{verbatim}