Integration is facilitated when an antiderivative for $f$ can be found, as then definite integrals can be evaluated through the fundamental theorem of calculus.
However, despite integration being an algorithmic procedure,
integration is not. There are "tricks" to try, such as substitution
and integration by parts. These work in some cases. However, there are
classes of functions for which algorithms exist. For example, the
`SymPy` `integrate` function mostly implements an algorithm that decides if
and Cook we can see how. Recall the division algorithm, for example, says there are ``q_k`` and ``r_k`` with ``A=q\cdot q_k + r_k`` where the degree of ``r_k`` is less than that of ``q``, which is linear or quadratic. This is repeatedly applied below:
So the term ``A(x)/q(x)^k`` can be expressed in terms of a sum where the numerators or each term have degree less than ``q(x)``, as expected by the statement of the theorem.
## Integrating the terms in a partial fraction decomposition
We discuss, by example, how each type of possible term in a partial
fraction decomposition has an antiderivative. Hence, rational
functions will *always* have an antiderivative that can be computed.
### Linear factors
For $j=1$, if $q_i$ is linear, then $a_{ij}/q_i^j$ must look like a constant over a linear term, or something like:
```julia;
p = a/(x-c)
```
This has a logarithmic antiderivative:
```julia;
integrate(p, x)
```
For $j > 1$, we have powers.
```julia;
@syms j::positive
integrate(a/(x-c)^j, x)
```
### Quadratic factors
When $q_i$ is quadratic, it looks like $ax^2 + bx + c$. Then $a_{ij}$
can be a constant or a linear polynomial. The latter can be written as
$Ax + B$.
The integral of the following general form is presented below:
```math
\frac{Ax +B }{(ax^2 + bx + c)^j},
```
With `SymPy`, we consider a few cases of the following form, which results from a shift of `x`
```math
\frac{Ax + B}{((ax)^2 \pm 1)^j}
```
This can be done by finding a $d$ so that $a(x-d)^2 + b(x-d) + c = dx^2 + e = e((\sqrt{d/e}x^2 \pm 1)$.
The integrals of the type $Ax/((ax)^2 \pm 1)$ can completed by $u$-substitution, with $u=(ax)^2 \pm 1$.
For example,
```julia;
integrate(A*x/((a*x)^2 + 1)^4, x)
```
The integrals of the type $B/((ax)^2\pm 1)$ are completed by
trigonometric substitution and various reduction formulas. They can get involved, but are tractable. For
example:
```julia;
integrate(B/((a*x)^2 + 1)^4, x)
```
and
```julia;
integrate(B/((a*x)^2 - 1)^4, x)
```
----
In [Bronstein](http://www-sop.inria.fr/cafe/Manuel.Bronstein/publications/issac98.pdf) this characterization can be found - "This method, which dates back to Newton, Leibniz and Bernoulli, should not be
used in practice, yet it remains the method found in most calculus texts and is
often taught. Its major drawback is the factorization of the denominator of the
integrand over the real or complex numbers." We can also find the following formulas which formalize the above exploratory calculations (``j>1`` and ``b^2 - 4c < 0`` below):
(Bronstein also sketches the modern method which is to use a Hermite reduction to express ``\int (f/g) dx = p/q + \int (g/h) dx``, where ``h`` is square free (the "`j`" are all ``1``). The latter can be written over the complex numbers as logarithmic terms of the form ``\log(x-a)``, the "`a`s"found following a method due to Trager and Lazard, and Rioboo, which is mentioned in the SymPy documentation as the method used.)
#### Examples
Find an antiderivative for $1/(x\cdot(x^2+1)^2)$.
We have a partial fraction decomposition is:
```julia;
q = (x * (x^2 + 1)^2)
apart(1/q)
```
We see three terms. The first and second will be done by $u$-substitution, the third by a logarithm:
```julia;
integrate(1/q, x)
```
----
Find an antiderivative of $1/(x^2 - 2x-3)$.
We again just let `SymPy` do the work. A partial fraction decomposition is given by:
```julia;
𝒒 = (x^2 - 2x - 3)
apart(1/𝒒)
```
We see what should yield two logarithmic terms:
```julia;
integrate(1/𝒒, x)
```
!!! note
`SymPy` will find ``\log(x)`` as an antiderivative for ``1/x``, but more
generally, ``\log(\lvert x\rvert)`` is one.
##### Example
The answers found can become quite involved. [Corless](https://arxiv.org/pdf/1712.01752.pdf), Moir, Maza, and Xie use this example which at first glance seems tame enough:
```julia
ex = (x^2 - 1) / (x^4 + 5x^2 + 7)
```
But the integral is something best suited to a computer algebra system:
```julia
integrate(ex, x)
```
## Questions
###### Question
The partial fraction decomposition of $1/(x(x-1))$ must be of the form $A/x + B/(x-1)$.
What is $A$? (Use `SymPy` or just put the sum over a common denominator and solve for $A$ and $B$.)
```julia; hold=true; echo=false
val = -1
numericq(val)
```
What is $B$?
```julia; hold=true; echo=false
val = 1
numericq(val)
```
###### Question
The following gives the partial fraction decomposition for a rational expression:
Is $-6\log(5) - 5\log(3) - 1/6 + 11\log(4)$ the answer?
```julia; hold=true; echo=false
yesnoq("yes")
```
###### Question
In the assumptions for the partial fraction decomposition is the fact that $p(x)$ and $q(x)$ share no common factors. Suppose, this isn't the case and in fact we have:
The partial fraction decomposition, as presented, factors the denominator polynomial into linear and quadratic factors over the real numbers. Alternatively, factoring over the complex numbers is possible, resulting in terms like:
```math
\frac{a + ib}{x - (\alpha + i \beta)} + \frac{a - ib}{x - (\alpha - i \beta)}
```
How to see that these give rise to real answers on integration is the point of this question.
Breaking the terms up over ``a`` and ``b`` we have:
```math
\begin{align*}
I &= \frac{a}{x - (\alpha + i \beta)} + \frac{a}{x - (\alpha - i \beta)} \\
II &= i\frac{b}{x - (\alpha + i \beta)} - i\frac{b}{x - (\alpha - i \beta)}
\end{align*}
```
Integrating ``I`` leads to two logarithmic terms, which are combined to give:
```math
\int I dx = a\cdot \log((x-(\alpha+i\beta)) \cdot (x - (\alpha-i\beta)))
```
This involves no complex numbers, as:
```julia; hold=true; echo=false
choices = ["The complex numbers are complex conjugates, so the term in the logarithm will simply be ``x - 2\\alpha x + \\alpha^2 + \\beta^2``",
"The ``\\beta`` are ``0``, as the polynomials in question are real"]
radioq(choices, 1)
```
The term ``II`` benefits from this computation (attributed to Rioboo by [Corless et. al](https://arxiv.org/pdf/1712.01752.pdf))
```math
\frac{d}{dx} i \log(\frac{X+iY}{X-iY}) = 2\frac{d}{dx}\arctan(\frac{X}{Y})
```
Applying this with ``X=x - \alpha`` and ``Y=-\beta`` shows that ``\int II dx`` will be