6. Substitution
The chain rule, run backwards.
\frac{d}{dx}F(g(x)) = F'(g(x))\,g'(x) \implies \int F'(g(x))\,g'(x)\,dx = F(g(x))+C
Written with u = g(x) and du = g'(x)\,dx:
\boxed{\int f(g(x))\,g'(x)\,dx = \int f(u)\,du}
Spot an inner function and its derivative multiplying it, and the composition collapses.
The mechanics
- Choose u — usually the inside of a composition, or whatever's under a root, in an exponent, or in a denominator.
- Compute du = g'(x)\,dx.
- Rewrite the integral entirely in u. No x may survive.
- Integrate.
- Substitute back (indefinite integrals only).
Step 3 is the test. If an x remains and won't go away, the substitution was wrong — pick differently, or use another technique.
Worked through
\int 2x\left(x^2+1\right)^3dx
The inner function is x^2+1, and its derivative 2x is sitting right there.
u = x^2+1, \qquad du = 2x\,dx
\int(x^2+1)^3\cdot2x\,dx = \int u^3\,du = \frac{u^4}{4}+C = \boxed{\frac{(x^2+1)^4}{4}+C}
Check by differentiating: \frac{4(x^2+1)^3\cdot2x}{4} = 2x(x^2+1)^3 ✓.
Fixing the constant
The derivative is rarely present with exactly the right coefficient, and that's fine — constants can be moved across the integral sign.
\int x\,e^{x^2}dx
u = x^2 gives du = 2x\,dx, so x\,dx = \frac12du:
\int e^{x^2}\cdot x\,dx = \int e^u\cdot\frac12du = \frac12e^u+C = \boxed{\frac12e^{x^2}+C}
Only constants can be moved this way. If you find yourself wanting to move an x outside the integral to make the substitution work, stop — that's illegal, and it's the most common substitution error.
\int e^{x^2}dx \quad\text{— no } x \text{ available, and no elementary answer exists}
The presence or absence of that single factor of x is the entire difference between a one-line problem and an unsolvable one.
Definite integrals: change the limits
Two options, and one is better.
Option A: substitute back to x at the end, then use the original limits.
Option B: convert the limits as you go, and never return to x.
\int_0^2x\,e^{x^2}dx
With u = x^2: when x=0, u=0; when x=2, u=4.
= \int_0^4\frac12e^u\,du = \left[\frac12e^u\right]_0^4 = \frac{e^4-1}{2}
Option B is better — less algebra, and no chance of forgetting to convert back. But the limits are now u-limits, and using the old ones with the new variable is a classic and silent error. Write u=0 to u=4 explicitly.
Choosing u
There's no algorithm, but there's a reliable priority order:
- Something inside a composition — the argument of \sin, e, \ln, or a power.
- Whatever is under a root.
- The denominator, if its derivative appears on top.
- The exponent.
And the check: does du account for everything left over?
Some non-obvious ones worth knowing:
\int\tan x\,dx = \int\frac{\sin x}{\cos x}dx \overset{u=\cos x}{=} -\int\frac{du}{u} = -\ln|\cos x|+C = \ln|\sec x|+C
\int\frac{dx}{x\ln x} \overset{u=\ln x}{=} \int\frac{du}{u} = \ln|\ln x|+C
The pattern in both: \int\frac{u'}{u}du = \ln|u|. Whenever the numerator is the denominator's derivative, the answer is a logarithm. Train yourself to see that shape.
When part of it won't convert
Sometimes an x remains, and you can rescue it by solving the substitution back.
\int x\sqrt{x+1}\,dx
u = x+1, du = dx — but there's a stray x. Since x = u-1:
\int(u-1)\sqrt u\,du = \int\left(u^{3/2}-u^{1/2}\right)du = \frac25u^{5/2}-\frac23u^{3/2}+C
= \boxed{\frac25(x+1)^{5/2}-\frac23(x+1)^{3/2}+C}
Back-substituting for the leftover x is a legitimate and often necessary move. It works whenever u = g(x) can be inverted.
Doing it in Python
Substitution results, verified by differentiating back:
import sympy as sp
x = sp.Symbol('x')
cases = [
(2*x*(x**2+1)**3, "u = x^2+1"),
(x*sp.exp(x**2), "u = x^2"),
(sp.tan(x), "u = cos x"),
(1/(x*sp.log(x)), "u = ln x"),
(x*sp.sqrt(x+1), "u = x+1, then x = u-1"),
]
for f, hint in cases:
F = sp.integrate(f, x)
back = sp.simplify(sp.diff(F, x) - f)
print(f"int {str(f):<20} = {str(F):<34} [{hint}]")
print(f"{'':4}differentiates back correctly: {back == 0}\n")
Changing the limits versus substituting back:
import sympy as sp
from math import exp
x, u = sp.symbols('x u')
# Option B: convert the limits
in_u = sp.integrate(sp.Rational(1,2)*sp.exp(u), (u, 0, 4))
# Option A: stay in x
in_x = sp.integrate(x*sp.exp(x**2), (x, 0, 2))
print(f"converting limits (u from 0 to 4) : {in_u} = {float(in_u):.8f}")
print(f"staying in x (x from 0 to 2) : {in_x} = {float(in_x):.8f}")
print(f"\nthe classic error -- new variable, OLD limits:")
wrong = sp.integrate(sp.Rational(1,2)*sp.exp(u), (u, 0, 2))
print(f" int_0^2 (1/2)e^u du = {wrong} = {float(wrong):.8f} <- wrong")
The factor that decides everything:
import sympy as sp
x = sp.Symbol('x')
for f in (x*sp.exp(x**2), sp.exp(x**2)):
print(f"int {str(f):<14} dx = {sp.integrate(f, x)}")
print("\none has an x to absorb into du. the other does not, and has no")
print("elementary antiderivative at all. that single factor is the whole story.")
The \int u'/u = \ln|u| pattern:
import sympy as sp
x = sp.Symbol('x', positive=True)
for f in (sp.tan(x), 1/(x*sp.log(x)), 2*x/(x**2+1), sp.cos(x)/sp.sin(x)):
print(f"int {str(f):<18} = {sp.integrate(f, x)}")
print("\nevery one is a log: numerator = derivative of denominator")
Worked example
Evaluate \displaystyle\int_0^{\pi/2}\frac{\cos x}{1+\sin^2x}\,dx.
Scan for an inner function whose derivative is present. The denominator has \sin x, and \cos x — its derivative — is the whole numerator.
u = \sin x, \qquad du = \cos x\,dx
Limits: x=0 \Rightarrow u=\sin0=0; x=\frac\pi2 \Rightarrow u=1.
\int_0^{\pi/2}\frac{\cos x\,dx}{1+\sin^2x} = \int_0^1\frac{du}{1+u^2}
That's the arctangent integral from §2.7:
= \Big[\arctan u\Big]_0^1 = \arctan1 - \arctan0 = \frac\pi4 - 0 = \boxed{\frac\pi4}
Two things worth extracting. First, the substitution turned a trigonometric integral into an inverse-trigonometric answer — the two are not the same family, and expecting the answer to "look like" the question is a bad instinct.
Second, \frac{\pi}{4} \approx 0.785, and a sanity check confirms it: the integrand runs from \frac{\cos0}{1+0}=1 down to \frac{0}{2}=0 over an interval of length \frac\pi2\approx1.57. A decreasing function from 1 to 0 over 1.57 should integrate to something under 1.57 and above 0 — and roughly half of it. ✓
Your turn
1. \displaystyle\int(3x+1)^5dx
2. \displaystyle\int\frac{x}{x^2+4}dx
3. \displaystyle\int_0^1x\sqrt{1-x^2}\,dx
4. \displaystyle\int\frac{\ln x}{x}dx
Solutions
1. u = 3x+1, du = 3\,dx, so dx = \frac13du:
\int u^5\cdot\frac13du = \frac{u^6}{18}+C = \boxed{\frac{(3x+1)^6}{18}+C}
2. The denominator's derivative is 2x, and the numerator is x — off by a constant, which is fine.
u = x^2+4, du = 2x\,dx, so x\,dx = \frac12du:
\int\frac{\frac12du}{u} = \frac12\ln|u|+C = \boxed{\frac12\ln(x^2+4)+C}
No absolute value needed, since x^2+4>0 always.
3. u = 1-x^2, du = -2x\,dx, so x\,dx = -\frac12du.
Limits: x=0\Rightarrow u=1; x=1\Rightarrow u=0. Note they reverse.
\int_1^0\sqrt u\left(-\tfrac12\right)du = \frac12\int_0^1\sqrt u\,du = \frac12\left[\frac23u^{3/2}\right]_0^1 = \frac12\cdot\frac23 = \boxed{\frac13}
The minus sign and the reversed limits cancelled each other — using $\int_b^a = -\int_a^b$ from §4.2. If you flip the limits, you must flip the sign; doing one without the other is a sign error that's easy to miss because the answer still looks plausible.
4. u = \ln x, du = \frac{dx}{x} — and \frac{dx}{x} is exactly what's there:
\int u\,du = \frac{u^2}{2}+C = \boxed{\frac{(\ln x)^2}{2}+C}
Contrast \int\frac{dx}{x\ln x}, where u=\ln x gives $\int\frac{du}{u} = \ln|\ln x|$. Same substitution, different placement of \ln x, completely different answer. Read where the pieces sit before committing.
Check yourself in code
Verify five substitution results by differentiating them back.
For 2x(x^2+1)^3, xe^{x^2}, \tan x, \frac{1}{x\ln x}, and x\sqrt{x+1}, print SymPy's antiderivative.
Print exactly this:
int 2x(x^2+1)^3 = x**8/4 + x**6 + 3*x**4/2 + x**2
int x*e^(x^2) = exp(x**2)/2
int tan(x) = -log(cos(x))
int 1/(x*ln(x)) = log(log(x))
int x*sqrt(x+1) = 2*x**2*sqrt(x + 1)/5 + 2*x*sqrt(x + 1)/15 - 4*sqrt(x + 1)/15
import sympy as sp
x = sp.Symbol('x')
cases = [
("2x(x^2+1)^3", 2*x*(x**2+1)**3),
("x*e^(x^2)", x*sp.exp(x**2)),
("tan(x)", sp.tan(x)),
("1/(x*ln(x))", 1/(x*sp.log(x))),
("x*sqrt(x+1)", x*sp.sqrt(x+1)),
]
for name, f in cases:
# integrate and print
print(f"int {name:<14} = ...")
import sympy as sp
x = sp.Symbol('x')
cases = [
("2x(x^2+1)^3", 2*x*(x**2+1)**3),
("x*e^(x^2)", x*sp.exp(x**2)),
("tan(x)", sp.tan(x)),
("1/(x*ln(x))", 1/(x*sp.log(x))),
("x*sqrt(x+1)", x*sp.sqrt(x+1)),
]
for name, f in cases:
print(f"int {name:<14} = {sp.integrate(f, x)}")
Substitution reverses the chain rule: find an inner function whose derivative multiplies the rest, set u to it, and the composition collapses. Constants can be adjusted freely; a stray variable cannot, and that single missing factor of x is the difference between \int xe^{x^2} and the unsolvable \int e^{x^2}. For definite integrals, convert the limits and never look back. And \int\frac{u'}{u} = \ln|u| is the pattern worth recognising on sight.
Next: what to do when the integrand is a product rather than a composition.