7. Integration by parts
Substitution reverses the chain rule. This reverses the product rule.
Start from (uv)' = u'v + uv', integrate both sides, and rearrange:
uv = \int u'v\,dx + \int uv'\,dx \implies \boxed{\int u\,dv = uv - \int v\,du}
It doesn't solve the integral — it trades it for a different one. The whole skill is choosing the split so the new integral is easier than the old.
The choice
You must split the integrand into u (to be differentiated) and dv (to be integrated). Two requirements:
- dv must be something you can antidifferentiate.
- u should get simpler when differentiated.
The standard heuristic is LIATE, a priority order for choosing u:
| Type | Example | |
|---|---|---|
| L | Logarithmic | \ln x |
| I | Inverse trig | \arctan x |
| A | Algebraic | x^2, x |
| T | Trigonometric | \sin x |
| E | Exponential | e^x |
Whichever appears first in LIATE becomes u. It's a heuristic, not a theorem, but it works nearly always — because the list is roughly ordered by how much a function improves under differentiation. \ln x becomes \frac1x (enormous improvement); e^x becomes e^x (none at all).
The basic case
\int xe^x\,dx
Algebraic before Exponential, so u = x, dv = e^xdx.
u = x \implies du = dx, \qquad dv = e^xdx \implies v = e^x
\int xe^xdx = xe^x - \int e^xdx = xe^x - e^x + C = \boxed{e^x(x-1)+C}
The trade worked: \int xe^x became \int e^x, and the x is gone.
Had you chosen the other way — u = e^x, dv = x\,dx — you'd get
\frac{x^2}{2}e^x - \int\frac{x^2}{2}e^xdx
with a higher power of x. Worse, and it gets worse again if you persist. Choosing badly makes the problem harder, visibly and immediately, which at least tells you to back up.
Integrating a function that isn't a product
\int\ln x\,dx
There's nothing to split — unless you notice \ln x = \ln x\cdot 1.
u = \ln x \implies du = \frac{dx}{x}, \qquad dv = dx \implies v = x
\int\ln x\,dx = x\ln x - \int x\cdot\frac{dx}{x} = x\ln x - \int dx = \boxed{x\ln x - x + C}
Taking dv = dx is the standard move for \ln, \arcsin, and \arctan — functions with no obvious antiderivative but very pleasant derivatives. Check by differentiating: \ln x + x\cdot\frac1x - 1 = \ln x ✓.
Repeating
\int x^2e^xdx
u = x^2, dv = e^xdx:
= x^2e^x - \int2xe^xdx
The remaining integral is the one we did above:
= x^2e^x - 2\left(xe^x - e^x\right) + C = \boxed{e^x\left(x^2-2x+2\right)+C}
Each application drops the polynomial's degree by one. For \int x^ne^xdx you need n applications, and the answer is e^x times a degree-n polynomial with alternating signs.
The circular case
I = \int e^x\sin x\,dx
Neither factor simplifies under differentiation, so no choice of u makes progress. Do it anyway, twice, and something else happens.
u = \sin x, dv = e^xdx:
I = e^x\sin x - \int e^x\cos x\,dx
Again on the new integral, u = \cos x, dv = e^xdx:
\int e^x\cos x\,dx = e^x\cos x + \int e^x\sin x\,dx = e^x\cos x + I
Substituting back:
I = e^x\sin x - e^x\cos x - I
The original integral has reappeared. Solve for it algebraically:
2I = e^x(\sin x - \cos x) \implies I = \boxed{\frac{e^x(\sin x-\cos x)}{2}+C}
Two rules for this pattern. You must be consistent — pick dv = e^xdx both times. Switching on the second pass unwinds the first and returns I = I, true and useless. And remember the +C: it vanishes during the algebra and must be restored at the end.
Definite integrals
\int_a^bu\,dv = \Big[uv\Big]_a^b - \int_a^bv\,du
The boundary term gets evaluated; the remaining integral keeps the limits.
Doing it in Python
The standard results:
import sympy as sp
x = sp.Symbol('x', positive=True)
cases = [
(x*sp.exp(x), "u=x, dv=e^x dx"),
(x*sp.sin(x), "u=x, dv=sin x dx"),
(sp.log(x), "u=ln x, dv=dx"),
(x**2*sp.exp(x), "twice"),
(sp.atan(x), "u=arctan x, dv=dx"),
(sp.exp(x)*sp.sin(x), "twice, then solve for I"),
]
for f, hint in cases:
F = sp.integrate(f, x)
ok = sp.simplify(sp.diff(F, x) - f) == 0
print(f"int {str(f):<16} = {str(F):<32} [{hint}] checks: {ok}")
Why the choice matters — running it both ways:
import sympy as sp
x = sp.Symbol('x')
# good choice: u = x, dv = e^x dx
u, v = x, sp.exp(x)
good = u*v - sp.integrate(v * sp.diff(u, x), x)
# bad choice: u = e^x, dv = x dx -> leaves a HIGHER power
u2, v2 = sp.exp(x), x**2/2
leftover = sp.integrate(v2 * sp.diff(u2, x), x)
print(f"good split: x*e^x - int(e^x) = {sp.simplify(good)}")
print(f"bad split : (x^2/2)e^x - int((x^2/2) e^x)")
print(f" the leftover integral is {leftover}")
print("\nthe bad split raised the power of x. it is not wrong, just useless.")
The circular case, done by hand:
import sympy as sp
x, I = sp.symbols('x I')
# after two applications: I = e^x sin x - e^x cos x - I
equation = sp.Eq(I, sp.exp(x)*sp.sin(x) - sp.exp(x)*sp.cos(x) - I)
solved = sp.solve(equation, I)[0]
print(f"after two rounds : I = e^x sin x - e^x cos x - I")
print(f"solving for I : I = {sp.simplify(solved)}")
print(f"sympy agrees : {sp.integrate(sp.exp(x)*sp.sin(x), x)}")
The degree ladder for \int x^ne^x:
import sympy as sp
x = sp.Symbol('x')
for n in range(5):
F = sp.simplify(sp.integrate(x**n * sp.exp(x), x))
print(f"int x^{n} e^x dx = {sp.factor(F)}")
print("\nn applications, and the polynomial factor has alternating signs")
print("and coefficients n!/(k!) -- the pattern is n! * sum (-1)^k x^k / k!")
Worked example
Evaluate \displaystyle\int_1^{e}x^2\ln x\,dx.
LIATE: L beats A, so u = \ln x even though the polynomial looks like the natural thing to differentiate.
u = \ln x \implies du = \frac{dx}{x}, \qquad dv = x^2dx \implies v = \frac{x^3}{3}
\int_1^ex^2\ln x\,dx = \left[\frac{x^3}{3}\ln x\right]_1^e - \int_1^e\frac{x^3}{3}\cdot\frac{dx}{x}
The remaining integrand simplifies — this is the payoff of differentiating the log:
\frac{x^3}{3}\cdot\frac1x = \frac{x^2}{3}
= \left[\frac{x^3}{3}\ln x\right]_1^e - \int_1^e\frac{x^2}{3}dx = \left[\frac{x^3}{3}\ln x - \frac{x^3}{9}\right]_1^e
Evaluate. At x=e, using \ln e = 1:
\frac{e^3}{3} - \frac{e^3}{9} = \frac{3e^3-e^3}{9} = \frac{2e^3}{9}
At x=1, using \ln1=0:
0 - \frac19 = -\frac19
\int_1^ex^2\ln x\,dx = \frac{2e^3}{9} + \frac19 = \boxed{\frac{2e^3+1}{9}} \approx 4.575
Why LIATE was right here. Choosing u = x^2 instead would give dv = \ln x\,dx, requiring you to already know \int\ln x — and it would leave you with \int x\left(x\ln x - x\right)dx, which is worse than what you started with. Differentiating the logarithm is what makes the problem collapse, and that's exactly why L sits at the front of the list.
Your turn
1. \displaystyle\int x\cos x\,dx
2. \displaystyle\int\arctan x\,dx
3. \displaystyle\int_0^1xe^{2x}dx
4. \displaystyle\int(\ln x)^2dx
Solutions
1. u=x, dv=\cos x\,dx, so v = \sin x:
x\sin x - \int\sin x\,dx = \boxed{x\sin x + \cos x + C}
Check: \sin x + x\cos x - \sin x = x\cos x ✓.
(This is the antiderivative §4.0 pulled out of thin air to make the point that every integration answer is checkable by differentiating. Here it is derived rather than asserted.)
2. Nothing to split, so u = \arctan x, dv = dx:
x\arctan x - \int\frac{x}{1+x^2}dx
The remaining integral is a substitution (w = 1+x^2, §4.5 exercise 2):
\int\frac{x\,dx}{1+x^2} = \frac12\ln(1+x^2)
\boxed{x\arctan x - \frac12\ln(1+x^2)+C}
Two techniques in one problem — by parts, then substitution. That's typical for anything non-trivial.
3. u = x, dv = e^{2x}dx, so v = \frac12e^{2x} (watch the \frac12 from the chain rule):
\left[\frac{x}{2}e^{2x}\right]_0^1 - \int_0^1\frac12e^{2x}dx = \frac{e^2}{2} - \left[\frac14e^{2x}\right]_0^1
= \frac{e^2}{2} - \left(\frac{e^2}{4}-\frac14\right) = \boxed{\frac{e^2+1}{4}} \approx 2.097
4. u = (\ln x)^2, dv = dx:
x(\ln x)^2 - \int x\cdot 2\ln x\cdot\frac1x\,dx = x(\ln x)^2 - 2\int\ln x\,dx
And \int\ln x\,dx = x\ln x - x from the lesson:
\boxed{x(\ln x)^2 - 2x\ln x + 2x + C}
Check by differentiating:
(\ln x)^2 + x\cdot\frac{2\ln x}{x} - 2\ln x - 2 + 2 = (\ln x)^2 \quad\checkmark
Two applications, and note the pattern from \int x^ne^x repeating: each round peels one factor off the "hard" part.
Check yourself in code
Verify five integration-by-parts results.
For xe^x, x\sin x, \ln x, x^2e^x, and \arctan x, print SymPy's antiderivative.
Print exactly this:
int x*e^x = (x - 1)*exp(x)
int x*sin(x) = -x*cos(x) + sin(x)
int ln(x) = x*log(x) - x
int x^2*e^x = (x**2 - 2*x + 2)*exp(x)
int arctan(x) = x*atan(x) - log(x**2 + 1)/2
import sympy as sp
x = sp.Symbol('x')
cases = [
("x*e^x", x*sp.exp(x)),
("x*sin(x)", x*sp.sin(x)),
("ln(x)", sp.log(x)),
("x^2*e^x", x**2*sp.exp(x)),
("arctan(x)", sp.atan(x)),
]
for name, f in cases:
print(f"int {name:<12} = ...")
import sympy as sp
x = sp.Symbol('x')
cases = [
("x*e^x", x*sp.exp(x)),
("x*sin(x)", x*sp.sin(x)),
("ln(x)", sp.log(x)),
("x^2*e^x", x**2*sp.exp(x)),
("arctan(x)", sp.atan(x)),
]
for name, f in cases:
print(f"int {name:<12} = {sp.integrate(f, x)}")
\int u\,dv = uv - \int v\,du trades one integral for another, and LIATE tells you which factor to differentiate so the trade is favourable. Use dv = dx for \ln and the inverse trig functions, which have no obvious antiderivative but excellent derivatives. Repeat to grind a polynomial down. And when the original integral reappears after two rounds, stop integrating and solve for it algebraically — being careful to keep dv consistent and to restore the +C.
Next: integrals where trigonometric identities do the work before any technique applies.