Substitution undoes the chain rule. Integration by parts undoes the product rule, so it is the tool for integrals of products like $x e^{x}$, $x\cos x$ or $x^{2}\ln x$, where no factor is the derivative of the other.
Why it works
The product rule says $(uv)' = u'v + uv'$. Integrate both sides:
$$uv = \int u'v\,dx + \int uv'\,dx.$$
Move one integral across, and write $du = u'\,dx$, $dv = v'\,dx$:
$$\int u\,dv = uv - \int v\,du.$$
Nothing is integrated yet. The formula trades one integral for another, and it helps when the new one, $\int v\,du$, is simpler.
Key idea
$$\int u\,dv = uv - \int v\,du,$$ $$\int_a^b u\,dv = \Big[uv\Big]_a^b - \int_a^b v\,du.$$
Choose $u$ to be a factor that gets simpler when you differentiate it, and $dv$ a factor you can integrate.
- A rule of thumb for $u$, first match wins: Logarithms, Inverse trig, Algebraic (powers of $x$), Trig, Exponentials (LIATE).
- Write the four pieces $u$, $du$, $dv$, $v$ before you substitute. You never need a $+C$ in $v$.
- Check the answer by differentiating it.
Worked example: A power times a trig function
Find $\int x\cos x\,dx$.
- $u = x$, $dv = \cos x\,dx$, so $du = dx$ and $v = \sin x$.
- $$\begin{aligned} &\int x\cos x\,dx \\ &= x\sin x - \int \sin x\,dx \\ &= x\sin x + \cos x + C. \end{aligned}$$
- Check: $$\begin{aligned} &\frac{d}{dx}(x\sin x + \cos x) \\ &= \sin x + x\cos x - \sin x \\ &= x\cos x. \end{aligned}$$
Answer: $x\sin x + \cos x + C$
Worked example: A lone logarithm
Find $\int \ln x\,dx$.
- There is only one factor, so let $u = \ln x$ and $dv = dx$. Then $du = \frac{1}{x}dx$ and $v = x$.
- $$\begin{aligned} \int \ln x\,dx &= x\ln x - \int x\cdot\frac{1}{x}\,dx \\ &= x\ln x - x + C. \end{aligned}$$
Answer: $x\ln x - x + C$
Common mistake
Choosing $u$ so that the new integral is harder. For $\int x e^{x}\,dx$, the choice $u = e^{x}$, $dv = x\,dx$ gives $\frac{x^{2}}{2}e^{x} - \int \frac{x^{2}}{2}e^{x}\,dx$: the power of $x$ went up, not down. If the new integral looks worse than the one you started with, swap your choices. With $u = x$ you get $x e^{x} - \int e^{x}dx = e^{x}(x - 1) + C$.
Worked example: Parts twice
Find $\int x^{2}e^{x}\,dx$.
- $u = x^{2}$, $dv = e^{x}dx$: $\int x^{2}e^{x}dx = x^{2}e^{x} - \int 2x e^{x}\,dx$.
- Again with $u = 2x$: $\int 2x e^{x}dx = 2x e^{x} - 2e^{x}$.
- Combine: $$\begin{aligned} &x^{2}e^{x} - 2x e^{x} + 2e^{x} + C \\ &= e^{x}(x^{2} - 2x + 2) + C. \end{aligned}$$
Answer: $e^{x}(x^{2} - 2x + 2) + C$
Worked example: When the integral comes back
Find $I = \int e^{x}\sin x\,dx$.
- $u = \sin x$, $dv = e^{x}dx$: $I = e^{x}\sin x - \int e^{x}\cos x\,dx$.
- Again with $u = \cos x$: $$\begin{aligned} &\int e^{x}\cos x\,dx \\ &= e^{x}\cos x + \int e^{x}\sin x\,dx \\ &= e^{x}\cos x + I. \end{aligned}$$
- So $I = e^{x}\sin x - e^{x}\cos x - I$, and $2I = e^{x}(\sin x - \cos x)$.
- $I = \frac{e^{x}}{2}(\sin x - \cos x) + C$. Treat $I$ like an unknown and solve for it; keep the same kind of choice ($u$ = the trig factor) both times.
Answer: $\frac{e^{x}}{2}(\sin x - \cos x) + C$
For a definite integral, evaluate the $uv$ part at the limits too: $$\begin{aligned} &\int_0^{\pi} x\sin x\,dx \\ &= \Big[-x\cos x\Big]_0^{\pi} + \int_0^{\pi}\cos x\,dx \\ &= \pi + 0 \\ &= \pi. \end{aligned}$$