Partial Fractions
Every rational function, a quotient of polynomials , can be integrated in elementary terms. The method is to split it into a polynomial plus a sum of simple fractions whose integrals are logarithms and arctangents. This lesson states the decomposition theorem, works through all four cases, computes coefficients by hand (including Heaviside's cover-up shortcut) and with SymPy's apart, and shows where the same algebra runs in signal processing and control code.
Step 0: make it proper
If , divide first: with . The polynomial integrates directly.
The decomposition theorem
Factor over the reals into linear factors and irreducible quadratics with (always possible, by the Fundamental Theorem of Algebra). Then is a unique sum of terms:
| Factor of | Terms contributed |
|---|---|
The number of unknown constants always equals , and multiplying out gives a linear system with a unique solution.
Case 1: distinct linear factors, and the cover-up method
Multiply by : . Setting kills the term: , so . Setting : , so .
Heaviside's cover-up rule does this in one move: to find the coefficient of , cover the factor in the original fraction and evaluate the rest at .
import sympy as sp
x = sp.symbols('x')
f = (5*x - 4) / (x**2 - x - 2)
print("apart:", sp.apart(f))
def cover_up(num, den, r):
"""Coefficient of 1/(x - r) for a simple root r of den."""
rest = sp.cancel(den / (x - r))
return sp.simplify(num.subs(x, r) / rest.subs(x, r))
print("cover-up:", {r: cover_up(5*x - 4, x**2 - x - 2, r) for r in sp.roots(x**2 - x - 2)})
print("integral:", sp.integrate(f, x))apart: 3/(x + 1) + 2/(x - 2)
cover-up: {2: 2, -1: 3}
integral: 2*log(x - 2) + 3*log(x + 1)
Case 2: repeated linear factors
Cover-up gives (at ) and (cover , evaluate at 1). needs one more equation; compare the coefficients: , so .
Cases 3 and 4: irreducible quadratics
A quadratic factor contributes a term , which splits into a logarithm and an arctangent:
If the quadratic is not of the form , complete the square first. Repeated quadratic factors lead to integrals like , handled with (Trigonometric Substitution).
import sympy as sp
x = sp.symbols('x')
examples = [
(x**3 + 2*x) / (x**2 - 1), # improper: division first
(x**2 + 1) / (x * (x - 1)**2), # repeated linear
(2*x**2 - x + 4) / (x**3 + 4*x), # linear × irreducible quadratic
(x + 3) / ((x - 1) * (x**2 + 2*x + 5)), # quadratic needing completed square
]
for f in examples:
print("f =", f)
print("apart =", sp.apart(f))
print("∫ f =", sp.integrate(f, x))
print()f = (x**3 + 2*x)/(x**2 - 1)
apart = x + 3/(2*(x + 1)) + 3/(2*(x - 1))
∫ f = x**2/2 + 3*log(x**2 - 1)/2
f = (x**2 + 1)/(x*(x - 1)**2)
apart = 2/(x - 1)**2 + 1/x
∫ f = log(x) - 2/(x - 1)
f = (2*x**2 - x + 4)/(x**3 + 4*x)
apart = (x - 1)/(x**2 + 4) + 1/x
∫ f = log(x) + log(x**2 + 4)/2 - atan(x/2)/2
f = (x + 3)/((x - 1)*(x**2 + 2*x + 5))
apart = -(x + 1)/(2*(x**2 + 2*x + 5)) + 1/(2*(x - 1))
∫ f = log(x - 1)/2 - log(x**2 + 2*x + 5)/4
Every result is built from polynomials, log and atan, as the theorem promises. SymPy writes log(x - 1) where we write : it works with complex logarithms, which differ from the real only by a constant on each interval.
Rationalising substitutions
Some non-rational integrands become rational after a substitution. For , set , so and :
The same trick (, the Weierstrass substitution) turns any rational function of and into a rational function of .
Partial fractions in signal processing
Linear filters and control systems are described by transfer functions, rational functions of (Laplace) or (digital). Their partial-fraction expansion separates the response into independent modes, one per pole. For example, has poles at −1 and −2, and its impulse response is the inverse Laplace transform of the expanded terms:
import sympy as sp
from scipy import signal
s, t = sp.symbols('s t')
H = (s + 3) / (s**2 + 3*s + 2)
print("expansion:", sp.apart(H, s))
print("impulse response h(t) =", sp.inverse_laplace_transform(H, s, t).subs(sp.Heaviside(t), 1))
r, p, k = signal.residue([1, 3], [1, 3, 2])
print("scipy.signal.residue: residues", [float(v.real) for v in r], "poles", [float(v.real) for v in p])expansion: -1/(s + 2) + 2/(s + 1)
impulse response h(t) = 2*exp(-t) - exp(-2*t)
scipy.signal.residue: residues [2.0, -1.0] poles [-1.0, -2.0]
The residues are the cover-up coefficients: at and at , giving .
In software
- Control and filter design.
scipy.signal.residue/residuez, MATLAB'sresidueand every circuit simulator expand transfer functions into partial fractions to find modes, stability (all poles in the left half-plane) and time responses. - Logistic growth. Separating leads to , solved by partial fractions; the result is the sigmoid (Models for Population Growth).
- Computer algebra. The Risch–Norman and Hermite reduction algorithms that CAS systems use for rational functions are partial fractions made systematic (Integration with Tables and Computer Algebra).
Exercises
Exercise 1: Distinct linear factors
Compute .
Answer
.
Solution
Cover-up: .
Exercise 2: A repeated factor
Decompose and integrate.
Answer
; integral .
Solution
, so divide by .
import sympy as sp
x = sp.symbols('x')
f = (3*x + 5) / (x + 1)**2
print(sp.apart(f), "|", sp.integrate(f, x))3/(x + 1) + 2/(x + 1)**2 | 3*log(x + 1) - 2/(x + 1)
Exercise 3: An irreducible quadratic
Compute .
Answer
.
Solution
and . On : .
Exercise 4: Count the unknowns
Write the form (without solving) of the decomposition of .
Answer
: seven constants.
Solution
, so the fraction is proper. has discriminant −3, so it is irreducible. One term per power of each factor, as in the table.
Test yourself
What must you check before decomposing ?
- That has no real roots
- That (otherwise divide first)
- That is irreducible
- That
Using the cover-up rule, what is in ?
- 7
- 1
An irreducible quadratic factor contributes which kind of term?