10. Partial fractions

📖 Reading · 12 min
💡 Every code box below is live — edit it and hit Run.

\int\frac{3x+11}{x^2-x-6}\,dx

No substitution helps — the numerator isn't the denominator's derivative. Parts makes it worse. Trig substitution doesn't apply.

The answer is algebra, not calculus: break the fraction into simpler ones you already know how to integrate.

The idea

\frac{3x+11}{x^2-x-6} = \frac{3x+11}{(x-3)(x+2)} = \frac{A}{x-3}+\frac{B}{x+2}

Each piece integrates to a logarithm. Adding fractions is routine; partial fractions is that operation reversed, and it's the entire technique.

Finding the constants

Multiply through by the common denominator:

3x+11 = A(x+2)+B(x-3)

The fast way: substitute the roots. Each choice kills one unknown.

x=3: 9+11 = A(5), so A = 4.

x=-2: -6+11 = B(-5), so B = -1.

\frac{3x+11}{x^2-x-6} = \frac{4}{x-3}-\frac{1}{x+2}

\int\frac{3x+11}{x^2-x-6}dx = 4\ln|x-3| - \ln|x+2| + C

Substituting the roots beats expanding and matching coefficients, and it's the method to default to. (Matching coefficients also works and is necessary for irreducible quadratics — see below.)

The four cases

First, two prerequisites. The fraction must be proper (numerator degree < denominator degree). If not, do polynomial long division first; the quotient integrates trivially and the remainder is proper. And the denominator must be factored as far as possible over the reals.

Then:

1. Distinct linear factors. One term each:

\frac{1}{(x-1)(x+2)} = \frac{A}{x-1}+\frac{B}{x+2}

2. Repeated linear factors. One term per power, up to the multiplicity:

\frac{1}{(x-1)^2(x+3)} = \frac{A}{x-1}+\frac{B}{(x-1)^2}+\frac{C}{x+3}

Missing the \frac{A}{x-1} term is the standard error — you need both powers, not just the highest.

3. Irreducible quadratic factors. A linear numerator over each:

\frac{1}{(x^2+1)(x-2)} = \frac{Ax+B}{x^2+1}+\frac{C}{x-2}

"Irreducible" means negative discriminant — no real roots, so it won't factor further over \mathbb R.

4. Repeated quadratics. One term per power, each with a linear numerator.

Integrating the pieces

\int\frac{A}{x-r}dx = A\ln|x-r|+C

\int\frac{A}{(x-r)^n}dx = \frac{A}{(1-n)(x-r)^{n-1}}+C \quad (n>1)

\int\frac{Ax+B}{x^2+a^2}dx = \frac A2\ln(x^2+a^2)+\frac Ba\arctan\frac xa + C

That last one splits into two: the Ax part is a substitution (u = x^2+a^2), and the B part is the arctangent from §2.7. Split it deliberately rather than trying to do both at once.

For a quadratic that isn't already x^2+a^2, complete the square first — the same preparation as §4.8.

Why it always works

This isn't a bag of tricks; it's a theorem.

Every polynomial with real coefficients factors over \mathbb R into linear and irreducible-quadratic factors. (That follows from the Fundamental Theorem of Algebra: complex roots come in conjugate pairs, and multiplying a conjugate pair gives a real quadratic.)

And every proper rational function decomposes into partial fractions over those factors.

Therefore every rational function has an elementary antiderivative, built from logarithms, arctangents, and powers. That's a strong and unusual guarantee — §4.0 noted that most classes of function have no such promise, and \int e^{-x^2} has no elementary answer at all. Rational functions are the well-behaved corner of integration, and this technique is why.

The practical catch: it requires factoring the denominator, which for degree 5 and above has no general formula (Abel–Ruffini). The theory guarantees an answer; the algebra may still defeat you.

Doing it in Python

The decomposition, and the integral:

import sympy as sp

x = sp.Symbol('x')

cases = [
    (3*x + 11) / (x**2 - x - 6),
    1 / ((x - 1)**2 * (x + 3)),
    (x**2 + 1) / (x**3 - x),
    1 / ((x**2 + 1) * (x - 2)),
]

for f in cases:
    print(f"f      = {f}")
    print(f"apart  = {sp.apart(f)}")
    print(f"int    = {sp.integrate(f, x)}\n")

Substituting the roots, step by step:

import sympy as sp

x, A, B = sp.symbols('x A B')

# 3x + 11 = A(x+2) + B(x-3)
lhs = 3*x + 11
rhs = A*(x + 2) + B*(x - 3)

a_val = sp.solve(sp.Eq(lhs.subs(x, 3), rhs.subs(x, 3)), A)[0]
b_val = sp.solve(sp.Eq(lhs.subs(x, -2), rhs.subs(x, -2)), B)[0]

print(f"set x = 3  (kills B): A = {a_val}")
print(f"set x = -2 (kills A): B = {b_val}")
print(f"\ndecomposition: {a_val}/(x-3) + ({b_val})/(x+2)")
print(f"sympy's apart: {sp.apart((3*x + 11)/(x**2 - x - 6))}")

Improper fractions need division first:

import sympy as sp

x = sp.Symbol('x')
f = (x**3 + 2*x) / (x**2 - 1)

quotient, remainder = sp.div(sp.numer(f), sp.denom(f), x)
print(f"f          = {f}")
print(f"long division: {quotient} + ({remainder})/({sp.denom(f)})")
print(f"apart       : {sp.apart(f)}")
print(f"integral    : {sp.integrate(f, x)}")
print("\nthe polynomial part integrates trivially; only the remainder")
print("needs partial fractions")

Every rational function has an elementary antiderivative:

import sympy as sp
import random

x = sp.Symbol('x')
random.seed(5)

print("random rational functions, all integrable in closed form:\n")
for _ in range(4):
    num = sum(random.randint(-3, 3) * x**k for k in range(3))
    den = sp.expand((x - random.randint(-3, 3)) * (x**2 + random.randint(1, 4)))
    F = sp.integrate(num/den, x)
    print(f"  int ({num}) / ({den})")
    print(f"    = {sp.simplify(F)}\n")

print("logs and arctangents every time -- guaranteed by the theory")

Worked example

Evaluate \displaystyle\int\frac{x^2+2x+3}{(x-1)(x^2+4)}\,dx.

Set up the form. One linear factor and one irreducible quadratic (x^2+4 has no real roots), so:

\frac{x^2+2x+3}{(x-1)(x^2+4)} = \frac{A}{x-1}+\frac{Bx+C}{x^2+4}

Clear denominators.

x^2+2x+3 = A(x^2+4)+(Bx+C)(x-1)

Find A by substituting the root. x=1:

1+2+3 = A(1+4) \implies 6 = 5A \implies A = \frac65

Find B and C by matching coefficients — there's no real root of x^2+4 to substitute. Expand the right side:

A x^2+4A+Bx^2-Bx+Cx-C = (A+B)x^2 + (C-B)x + (4A-C)

Match against x^2+2x+3:

  • x^2: A+B = 1 \implies B = 1-\frac65 = -\frac15
  • x^1: C-B = 2 \implies C = 2-\frac15 = \frac95
  • x^0: 4A-C = 3check: \frac{24}{5}-\frac95 = \frac{15}{5} = 3

The redundant equation is free verification. Always use it.

Integrate, splitting the quadratic term into its two natural pieces:

\int\frac{6/5}{x-1}dx = \frac65\ln|x-1|

\int\frac{-\frac15x+\frac95}{x^2+4}dx = -\frac15\int\frac{x\,dx}{x^2+4} + \frac95\int\frac{dx}{x^2+4}

= -\frac1{10}\ln(x^2+4) + \frac95\cdot\frac12\arctan\frac x2

\boxed{\frac65\ln|x-1| - \frac{1}{10}\ln(x^2+4)+\frac{9}{10}\arctan\frac x2+C}

Note the two kinds of absolute value. |x-1| needs the bars because x-1 changes sign; x^2+4 is always positive, so it doesn't.

Your turn

1. \displaystyle\int\frac{dx}{x^2-1}

2. \displaystyle\int\frac{5x-4}{x^2-x-2}dx

3. Set up (don't integrate) the decomposition of \dfrac{x^3+1}{x^2(x-1)(x^2+9)}.

4. \displaystyle\int\frac{x^2}{x^2-1}dx — careful.

Solutions

1. Factor and decompose:

\frac{1}{(x-1)(x+1)} = \frac{A}{x-1}+\frac{B}{x+1} \implies 1 = A(x+1)+B(x-1)

x=1: 1 = 2A, so A=\frac12. x=-1: 1=-2B, so B=-\frac12.

\int\left[\frac{1/2}{x-1}-\frac{1/2}{x+1}\right]dx = \boxed{\frac12\ln\left|\frac{x-1}{x+1}\right|+C}

Combining the two logs into one is optional but tidier, and it's the form you'll meet again as \tanh^{-1} (§2.8) up to a constant.

2. x^2-x-2 = (x-2)(x+1):

5x-4 = A(x+1)+B(x-2)

x=2: 6 = 3A, so A=2. x=-1: -9=-3B, so B=3.

\boxed{2\ln|x-2|+3\ln|x+1|+C}

3. Repeated linear (x^2), distinct linear (x-1), and irreducible quadratic (x^2+9):

\boxed{\frac{A}{x}+\frac{B}{x^2}+\frac{C}{x-1}+\frac{Dx+E}{x^2+9}}

Five unknowns for a degree-5 denominator — the counts always match, which is a useful check that you've written the right form. Note both \frac Ax and \frac{B}{x^2} appear, and the quadratic gets a linear numerator.

4. The fraction is improper — numerator and denominator both have degree 2. Divide first:

\frac{x^2}{x^2-1} = 1 + \frac{1}{x^2-1}

(Check: \frac{(x^2-1)+1}{x^2-1} = 1+\frac{1}{x^2-1} ✓.)

Now the second piece is exercise 1:

\int\left[1+\frac{1}{x^2-1}\right]dx = \boxed{x+\frac12\ln\left|\frac{x-1}{x+1}\right|+C}

Skipping the division is the most common failure on this technique. Setting up \frac{x^2}{(x-1)(x+1)} = \frac{A}{x-1}+\frac{B}{x+1} leads to an inconsistent system, because no such decomposition exists — the left side doesn't go to 0 at infinity and the right side does. Check the degrees first, every time.

Check yourself in code

Decompose and integrate three rational functions.

For \frac{3x+11}{x^2-x-6}, \frac{1}{x^2-1}, and \frac{1}{(x^2+1)(x-2)}, print SymPy's apart decomposition and its integral.

Print exactly this:

(3x+11)/(x^2-x-6)
  apart = -1/(x + 2) + 4/(x - 3)
  int   = 4*log(x - 3) - log(x + 2)
1/(x^2-1)
  apart = -1/(2*(x + 1)) + 1/(2*(x - 1))
  int   = log(x - 1)/2 - log(x + 1)/2
1/((x^2+1)(x-2))
  apart = -(x + 2)/(5*(x**2 + 1)) + 1/(5*(x - 2))
  int   = log(x - 2)/5 - log(x**2 + 1)/10 - 2*atan(x)/5
import sympy as sp

x = sp.Symbol('x')

cases = [
    ("(3x+11)/(x^2-x-6)", (3*x + 11) / (x**2 - x - 6)),
    ("1/(x^2-1)", 1 / (x**2 - 1)),
    ("1/((x^2+1)(x-2))", 1 / ((x**2 + 1) * (x - 2))),
]

for name, f in cases:
    print(name)
    # print the apart decomposition and the integral, indented two spaces
    print("  apart = ...")
import sympy as sp

x = sp.Symbol('x')

cases = [
    ("(3x+11)/(x^2-x-6)", (3*x + 11) / (x**2 - x - 6)),
    ("1/(x^2-1)", 1 / (x**2 - 1)),
    ("1/((x^2+1)(x-2))", 1 / ((x**2 + 1) * (x - 2))),
]

for name, f in cases:
    print(name)
    print(f"  apart = {sp.apart(f)}")
    print(f"  int   = {sp.integrate(f, x)}")

Reverse the addition of fractions: factor the denominator, write one term per factor (one per power for repeated factors, with a linear numerator over each quadratic), and find the constants by substituting the roots — falling back to matching coefficients for irreducible quadratics. Divide first if the fraction is improper. Every piece then integrates to a logarithm, an arctangent, or a power, which is why every rational function has an elementary antiderivative — a guarantee almost nothing else in integration enjoys.

Next: integrals over infinite intervals, and integrands that blow up.