Strategy for Integration
Differentiation is an algorithm: apply the rules and you always get an answer. Integration is a search: you must recognise which technique fits, and sometimes none does. This lesson organises the techniques of this chapter into a strategy, shows how to recognise each type, and explains which integrals cannot be done in elementary terms at all, and what to do then.
The toolbox so far
| Technique | Recognise it by | Lesson |
|---|---|---|
| table + linearity | sum of basic functions | Antiderivatives |
| substitution | a composite times (a multiple of) | Substitution |
| integration by parts | product of unlike types: , , , | Parts |
| trig integrals | powers of / or / | Trig Integrals |
| trig substitution | , | Trig Substitution |
| partial fractions | rational function | Partial Fractions |
| rationalising substitution | with linear , rational in , | Partial Fractions |
A four-step strategy
- Simplify the integrand. Expand, cancel, use identities. ; expands to powers; .
- Look for an obvious substitution. Is part of the integrand (up to a constant) the derivative of another part? : .
- Classify by form. Rational → partial fractions. Product of a polynomial and a transcendental function → parts. Trig powers → trig integrals. Radical of a quadratic → trig substitution (after completing the square).
- Try again. Manipulate: try a different substitution (even an unusual one), parts with , multiply by 1 in a clever form (), relate the integral to one you have already done, or combine several methods.
Sometimes one problem needs several steps. : substitute (, ) to get , then parts: .
How a CAS follows the same strategy
SymPy's manualintegrate module imitates the hand strategy: it tries a list of rules (table lookups, substitutions, parts, trig rules, partial fractions) and records which one it used. Asking for the steps shows the classification:
import sympy as sp
from sympy.integrals.manualintegrate import integral_steps
x = sp.symbols('x')
cases = [x * sp.exp(x**2), x * sp.exp(x), sp.sin(x)**3, sp.sqrt(4 - x**2),
1 / (x**2 + 3*x + 2), sp.log(x)]
for f in cases:
rule = type(integral_steps(f, x)).__name__
print(f"{str(f):18} -> {rule:22} -> {sp.integrate(f, x, manual=True)}")x*exp(x**2) -> AlternativeRule -> exp(x**2)/2
x*exp(x) -> PartsRule -> x*exp(x) - exp(x)
sin(x)**3 -> RewriteRule -> cos(x)**3/3 - cos(x)
sqrt(4 - x**2) -> SqrtQuadraticRule -> x*sqrt(4 - x**2)/2 + 2*asin(x/2)
1/(x**2 + 3*x + 2) -> URule -> log(2*x + 2) - log(2*x + 4)
log(x) -> PartsRule -> x*log(x) - x
An AlternativeRule means SymPy found several workable approaches; a RewriteRule means it first rewrote the integrand (step 1 of our strategy, here ); URule is a substitution, here applied after splitting the rational function; SqrtQuadraticRule handles roots of quadratics, the job of trig substitution. Answers such as log(2x + 2) − log(2x + 4) differ from the textbook only by a constant.
Not every integral is elementary
An elementary function is built from polynomials, exponentials, logarithms, trig and inverse trig functions by arithmetic and composition. Every continuous function has an antiderivative (FTC Part 1), but often it is not elementary. Liouville's theorem (1830s) gives a precise criterion, and from it one can prove that these have no elementary antiderivative:
No amount of cleverness will find formulas for them. They define special functions instead, which a CAS reports by name:
import sympy as sp
x = sp.symbols('x', positive=True)
for f in [sp.exp(-x**2), sp.sin(x) / x, 1 / sp.log(x), sp.sin(x**2), sp.exp(x) / x]:
print(f"∫ {str(f):12} dx = {sp.integrate(f, x)}")∫ exp(-x**2) dx = sqrt(pi)*erf(x)/2
∫ sin(x)/x dx = Si(x)
∫ 1/log(x) dx = li(x)
∫ sin(x**2) dx = 3*sqrt(2)*sqrt(pi)*fresnels(sqrt(2)*x/sqrt(pi))*gamma(3/4)/(8*gamma(7/4))
∫ exp(x)/x dx = Ei(x)
erf is the error function (normal-distribution probabilities), Si the sine integral (signal processing, antenna theory), li the logarithmic integral (counting primes: li(x) is the best simple estimate of how many primes lie below ), fresnels a Fresnel integral (optics, clothoid road curves; the gamma(…) factors are just constants), and Ei the exponential integral.
When there is no formula: go numerical
For definite integrals, a non-elementary antiderivative is no obstacle. Numerical quadrature (Approximate Integration) gives the value to near machine precision:
import math
from scipy.integrate import quad
from scipy.special import sici
val, err = quad(lambda x: math.sin(x) / x if x else 1.0, 0, 10)
print(f"∫_0^10 sin x / x dx = {val:.12f} (quad, estimated error {err:.1e})")
print(f"Si(10) from scipy.special = {sici(10)[0]:.12f}")
val, _ = quad(lambda x: math.sqrt(1 + x**3), 0, 2)
print(f"∫_0^2 √(1 + x³) dx = {val:.10f}")∫_0^10 sin x / x dx = 1.658347594219 (quad, estimated error 2.9e-14)
Si(10) from scipy.special = 1.658347594219
∫_0^2 √(1 + x³) dx = 3.2413092632
In software
- Symbolic integration is a search problem. CAS integrators (SymPy, Mathematica, Maple) combine heuristic rule-based search like the strategy above with complete decision procedures (the Risch algorithm) for elementary integrands. Researchers have even trained neural networks to propose antiderivatives, which are then checked by differentiation, the same "verify by differentiating" habit.
- Know when to stop. In engineering code, a numerical integral is usually the right answer: faster to write, robust, and as accurate as you need. Reach for a closed form when you need it many times, need derivatives with respect to parameters, or want insight.
- Special-function libraries (
scipy.special, Boost.Math, Cephes) are the industrial answer to non-elementary integrals.
Exercises
Exercise 1: Classify
Name the technique you would try first for each: (a) , (b) , (c) , (d) .
Answer
(a) substitution ; (b) parts (twice); (c) partial fractions; (d) trig substitution (or ).
Solution
(a) is (up to ) the derivative of the inner . (b) A polynomial times an exponential. (c) . (d) A root of .
Exercise 2: Two techniques
Compute .
Answer
.
Solution
import sympy as sp
x = sp.symbols('x', positive=True)
F = 2 * sp.sin(sp.sqrt(x)) - 2 * sp.sqrt(x) * sp.cos(sp.sqrt(x))
print(sp.simplify(sp.diff(F, x) - sp.sin(sp.sqrt(x))))0
Exercise 3: Simplify first
Compute .
Answer
.
Solution
Split: .
Exercise 4: Elementary or not?
Which of these has an elementary antiderivative: , , ?
Answer
Only (antiderivative ).
Solution
is a substitution with . The other two are not elementary ( is the imaginary error function, erfi, up to a constant; parts on the third leads back to ).
import sympy as sp
x = sp.symbols('x', positive=True)
for f in [sp.exp(x**2), x * sp.exp(x**2), sp.exp(x**2) / x**2]:
print(f, "->", sp.integrate(f, x))exp(x**2) -> sqrt(pi)*erfi(x)/2
x*exp(x**2) -> exp(x**2)/2
exp(x**2)/x**2 -> sqrt(pi)*erfi(x) - exp(x**2)/x
Test yourself
Which integral has no elementary antiderivative?
First step of the strategy for ?
- Partial fractions
- Trig substitution
- Parts
- Expand and simplify:
A CAS returns for an integral. What does that mean?
- The integral diverges
- The antiderivative is a special (non-elementary) function, which can still be evaluated numerically
- The CAS failed
- The answer is 0