Finding antiderivatives is harder than finding derivatives. Five techniques cover most integrals: substitution (reverse chain rule), integration by parts (reverse product rule), partial fractions (decompose rational functions), trig substitution (for square roots), and improper integrals (infinite limits).
Substitution (u-substitution)
If the integrand looks like f(g(x)) · g'(x), let u = g(x), du = g'(x)dx. The integral becomes the integral of f(u)du, which is often simpler. This reverses the chain rule.
Scheme
; u-substitution: integral of 2x * cos(x^2) dx; Let u = x^2, du = 2x dx; Becomes: integral of cos(u) du = sin(u) + C = sin(x^2) + C
(define (integrate f a b n)
(let ((dx (/ (- b a) n)))
(let loop ((i 0) (sum 0))
(if (= i n) (* sum dx)
(let ((x (+ a (* i dx) (/ dx 2))))
(loop (+ i 1) (+ sum (f x))))))))
; Original integrand
(define (integrand x) (* 2 x (cos (* x x))))
; Antiderivative via substitution: sin(x^2)
(define (F x) (sin (* x x)))
; Compare on [0, 1]
(define numerical (integrate integrand 0110000))
(define exact (- (F 1) (F 0)))
(display "Numerical: ") (display (/ (round (* numerical 10000)) 10000)) (newline)
(display "Exact: ") (display (/ (round (* exact 10000)) 10000))
Python
importmath# integral of 2x*cos(x^2) dx from 0 to 1# u = x^2, answer = sin(x^2) evaluated at boundsdef integrate(f, a, b, n=10000):
dx = (b - a) / n
returnsum(f(a + (i+0.5)*dx) * dx for i inrange(n))
numerical = integrate(lambda x: 2*x*math.cos(x**2), 0, 1)
exact = math.sin(1) - math.sin(0)
print(f"Numerical: {numerical:.6f}")
print(f"Exact: {exact:.6f}")
Integration by parts
The integral of u dv = uv - the integral of v du. This reverses the product rule. Choose u as the function that simplifies when differentiated, and dv as the rest. LIATE order: Logarithmic, Inverse trig, Algebraic, Trig, Exponential.
Scheme
; Integration by parts: integral of x*e^x dx; u = x, dv = e^x dx; du = dx, v = e^x; = x*e^x - integral of e^x dx = x*e^x - e^x + C = (x-1)*e^x + C
(define (integrate f a b n)
(let ((dx (/ (- b a) n)))
(let loop ((i 0) (sum 0))
(if (= i n) (* sum dx)
(let ((x (+ a (* i dx) (/ dx 2))))
(loop (+ i 1) (+ sum (f x))))))))
(define (integrand x) (* x (exp x)))
(define (F x) (* (- x 1) (exp x))) ; antiderivative; Integral from 0 to 1
(define numerical (integrate integrand 0110000))
(define exact (- (F 1) (F 0)))
(display "Numerical: ") (display (/ (round (* numerical 10000)) 10000)) (newline)
(display "Exact: ") (display (/ (round (* exact 10000)) 10000)) (newline)
; Exact = (1-1)*e^1 - (0-1)*e^0 = 0 + 1 = 1
(display "= e^1 * 0 - e^0 * (-1) = 1")
Python
importmath# Integration by parts: integral of x*e^x dx# u=x, dv=e^x dx => antiderivative = (x-1)*e^xdef integrate(f, a, b, n=10000):
dx = (b - a) / n
returnsum(f(a + (i+0.5)*dx) * dx for i inrange(n))
integrand = lambda x: x * math.exp(x)
F = lambda x: (x - 1) * math.exp(x)
numerical = integrate(integrand, 0, 1)
exact = F(1) - F(0)
print("Numerical: {:.4f}".format(numerical))
print("Exact: {:.4f}".format(exact))
print("= e^1 * 0 - e^0 * (-1) = 1")
Partial fractions
To integrate a rational function p(x)/q(x), factor the denominator and decompose into simpler fractions. Each factor (x-a) in the denominator contributes a term A/(x-a). Each integral becomes A ln|x-a|.
Scheme
; Partial fractions: integral of 1/(x^2 - 1) dx; 1/(x^2-1) = 1/((x-1)(x+1)) = A/(x-1) + B/(x+1); 1 = A(x+1) + B(x-1); x=1: 1 = 2A, A = 1/2; x=-1: 1 = -2B, B = -1/2; integral = (1/2)ln|x-1| - (1/2)ln|x+1| + C
(define (integrate f a b n)
(let ((dx (/ (- b a) n)))
(let loop ((i 0) (sum 0))
(if (= i n) (* sum dx)
(let ((x (+ a (* i dx) (/ dx 2))))
(loop (+ i 1) (+ sum (f x))))))))
(define (integrand x) (/ 1 (- (* x x) 1)))
; Antiderivative: (1/2) ln|(x-1)/(x+1)|
(define (F x) (* 0.5 (log (abs (/ (- x 1) (+ x 1))))))
; Integral from 2 to 5 (avoiding the singularity at x=1)
(define numerical (integrate integrand 2510000))
(define exact (- (F 5) (F 2)))
(display "Numerical: ") (display (/ (round (* numerical 10000)) 10000)) (newline)
(display "Exact: ") (display (/ (round (* exact 10000)) 10000))
Python
importmath# Partial fractions: integral of 1/(x^2 - 1) dx from 2 to 5# = (1/2) ln|(x-1)/(x+1)| + Cdef integrate(f, a, b, n=10000):
dx = (b - a) / n
returnsum(f(a + (i+0.5)*dx) * dx for i inrange(n))
integrand = lambda x: 1 / (x**2 - 1)
F = lambda x: 0.5 * math.log(abs((x-1)/(x+1)))
numerical = integrate(integrand, 2, 5)
exact = F(5) - F(2)
print("Numerical: {:.4f}".format(numerical))
print("Exact: {:.4f}".format(exact))
Trig substitution
For integrands with square roots of quadratics, substitute a trig function. For sqrt(a² - x²): let x = a sinθ. For sqrt(a² + x²): let x = a tanθ. For sqrt(x² - a²): let x = a secθ. The Pythagorean identity eliminates the square root.
Scheme
; Trig substitution: integral of sqrt(1 - x^2) dx from 0 to 1; This is the area of a quarter circle of radius 1 = pi/4; Let x = sin(theta), dx = cos(theta) d(theta); sqrt(1-x^2) = cos(theta); Integral becomes integral of cos^2(theta) d(theta)
(define pi 3.141592653589793)
(define (integrate f a b n)
(let ((dx (/ (- b a) n)))
(let loop ((i 0) (sum 0))
(if (= i n) (* sum dx)
(let ((x (+ a (* i dx) (/ dx 2))))
(loop (+ i 1) (+ sum (f x))))))))
(define (integrand x) (sqrt (- 1 (* x x))))
(define numerical (integrate integrand 0110000))
(define exact (/ pi 4))
(display "Numerical: ") (display (/ (round (* numerical 10000)) 10000)) (newline)
(display "pi/4: ") (display (/ (round (* exact 10000)) 10000))
Python
importmath# Trig substitution: integral of sqrt(1-x^2) from 0 to 1# This is the area of a quarter circle = pi/4def integrate(f, a, b, n=10000):
dx = (b - a) / n
returnsum(f(a + (i+0.5)*dx) * dx for i inrange(n))
integrand = lambda x: math.sqrt(1 - x**2)
numerical = integrate(integrand, 0, 1)
exact = math.pi / 4print("Numerical: {:.4f}".format(numerical))
print("pi/4: {:.4f}".format(exact))
Improper integrals
When the interval is infinite or the integrand blows up, take a limit. The integral from 1 to infinity of 1/x² dx = limb→∞ [-1/x] from 1 to b = 0 - (-1) = 1. The integral converges if the limit is finite.
Scheme
; Improper integral: integral of 1/x^2 from 1 to infinity; = lim(b->inf) [-1/x] from 1 to b = lim(-1/b + 1) = 1
(define (integrate f a b n)
(let ((dx (/ (- b a) n)))
(let loop ((i 0) (sum 0))
(if (= i n) (* sum dx)
(let ((x (+ a (* i dx) (/ dx 2))))
(loop (+ i 1) (+ sum (f x))))))))
(define (integrand x) (/ 1 (* x x)))
; Approximate with increasing upper limits
(display "1 to 10: ") (display (/ (round (* (integrate integrand 1101000) 10000)) 10000)) (newline)
(display "1 to 100: ") (display (/ (round (* (integrate integrand 110010000) 10000)) 10000)) (newline)
(display "1 to 1000: ") (display (/ (round (* (integrate integrand 11000100000) 10000)) 10000)) (newline)
(display "Exact: 1") (newline) (newline)
; Divergent: integral of 1/x from 1 to infinity = ln(b) -> infinity
(display "1/x from 1 to 100: ") (display (/ (round (* (integrate (lambda (x) (/ 1 x)) 110010000) 100)) 100)) (newline)
(display "1/x from 1 to 1000: ") (display (/ (round (* (integrate (lambda (x) (/ 1 x)) 11000100000) 100)) 100)) (newline)
(display "Diverges: ln(b) grows without bound")
Python
importmath# Improper integral: 1/x^2 from 1 to infinity = 1 (converges)def integrate(f, a, b, n):
dx = (b - a) / n
returnsum(f(a + (i+0.5)*dx) * dx for i inrange(n))
for b, n in [(10, 1000), (100, 10000), (1000, 100000)]:
val = integrate(lambda x: 1/x**2, 1, b, n)
print("1/x^2 from 1 to {}: {:.4f}".format(b, val))
print("Exact: 1")
print()
# 1/x from 1 to infinity divergesfor b, n in [(100, 10000), (1000, 100000)]:
val = integrate(lambda x: 1/x, 1, b, n)
print("1/x from 1 to {}: {:.2f}".format(b, val))
print("Diverges: ln(b) grows without bound")