TExcelTAD
Home › Calculus in Depth › Integration by Parts

Integration by Parts

Substitution reverses the chain rule; integration by parts reverses the product rule. It trades the integral of a product for another integral that is, with a good choice, simpler. This lesson derives the formula, gives a strategy for choosing the parts, and covers the three advanced patterns: repeated parts, integrals that reappear and must be solved for, and reduction formulas. For a first look see Integration by Parts.

The formula

The product rule says (f⋅g)′=f′g+fg′(f \cdot g)' = f'g + fg'. Integrate both sides and rearrange:

∫f(x)g′(x) dx=f(x)g(x)−∫g(x)f′(x) dx\int f(x)g'(x)\,dx = f(x)g(x) - \int g(x)f'(x)\,dx

With u=f(x)u = f(x) and v=g(x)v = g(x), so du=f′(x) dxdu = f'(x)\,dx and dv=g′(x) dxdv = g'(x)\,dx:

∫u dv=uv−∫v du\int u\,dv = uv - \int v\,du

For definite integrals, by FTC Part 2:

∫abf(x)g′(x) dx=[f(x)g(x)]ab−∫abg(x)f′(x) dx\int_a^b f(x)g'(x)\,dx = \Big[f(x)g(x)\Big]_a^b - \int_a^b g(x)f'(x)\,dx

Choosing u and dv

You must be able to integrate dvdv, and dudu should be simpler than uu. A common heuristic (often called LIATE) picks uu as the first type present in this list:

Priority for uu Type Examples
1 Logarithmic ln⁡x\ln x
2 Inverse trig tan⁡−1x\tan^{-1} x, sin⁡−1x\sin^{-1} x
3 Algebraic x2x^2, 3x+13x + 1
4 Trigonometric cos⁡x\cos x
5 Exponential e2xe^{2x}

The functions at the top get simpler when differentiated (ln⁡x→1/x\ln x \to 1/x); those at the bottom stay the same size when integrated. It is a guide, not a law.

Examples.

∫xe3x dx:u=x, dv=e3x dx⇒ =xe3x3−∫e3x3 dx=e3x(3x−1)9+C∫ln⁡x dx:u=ln⁡x, dv=dx⇒ =xln⁡x−∫x⋅1x dx=xln⁡x−x+C∫tan⁡−1x dx:u=tan⁡−1x, dv=dx⇒ =xtan⁡−1x−∫x1+x2 dx=xtan⁡−1x−12ln⁡(1+x2)+C\begin{aligned} &\int x e^{3x}\,dx: && u = x,\ dv = e^{3x}\,dx && \Rightarrow\ = \frac{x e^{3x}}{3} - \int \frac{e^{3x}}{3}\,dx = \frac{e^{3x}(3x - 1)}{9} + C \\[1ex] &\int \ln x\,dx: && u = \ln x,\ dv = dx && \Rightarrow\ = x \ln x - \int x \cdot \frac{1}{x}\,dx = x \ln x - x + C \\[1ex] &\int \tan^{-1} x\,dx: && u = \tan^{-1} x,\ dv = dx && \Rightarrow\ = x \tan^{-1} x - \int \frac{x}{1 + x^2}\,dx = x \tan^{-1} x - \frac{1}{2}\ln(1 + x^2) + C \end{aligned}

The last one also needs a substitution, w=1+x2w = 1 + x^2, for the remaining integral. Combining techniques is normal.

Repeated parts and the tabular shortcut

∫x3ex dx\int x^3 e^x\,dx needs parts three times, each time lowering the power. Organised as a table, differentiate uu down to 0 and integrate dvdv the same number of times, then multiply along diagonals with alternating signs:

text
 sign    u (differentiate)    dv (integrate)
  +        x³                   eˣ
  −        3x²                  eˣ
  +        6x                   eˣ
  −        6                    eˣ
           0                    eˣ
∫x3ex dx=ex(x3−3x2+6x−6)+C\int x^3 e^x\,dx = e^x(x^3 - 3x^2 + 6x - 6) + C
python · try it yourself
import sympy as sp

x = sp.symbols('x')
def tabular(u, dv):
    """Integration by parts repeated until u differentiates to 0."""
    total, sign, v = 0, 1, dv
    while u != 0:
        v = sp.integrate(v, x)
        total += sign * u * v
        u, sign = sp.diff(u, x), -sign
    return total

for u, dv in [(x**3, sp.exp(x)), (x**2, sp.cos(2 * x))]:
    F = sp.factor(tabular(u, dv))
    print(f"∫ {u}·{dv} dx = {F}")
    print("   check:", sp.simplify(sp.diff(F, x) - u * dv) == 0)
∫ x**3·exp(x) dx = (x**3 - 3*x**2 + 6*x - 6)*exp(x)
   check: True
∫ x**2·cos(2*x) dx = (2*x**2*sin(2*x) + 2*x*cos(2*x) - sin(2*x))/4
   check: True

When the integral comes back

For I=∫exsin⁡x dxI = \int e^x \sin x\,dx, parts twice returns the original integral:

u=sin⁡x, dv=ex dx:I=exsin⁡x−∫excos⁡x dxu=cos⁡x, dv=ex dx:∫excos⁡x dx=excos⁡x+∫exsin⁡x dx=excos⁡x+ISo I=exsin⁡x−excos⁡x−I ⇒ 2I=ex(sin⁡x−cos⁡x) ⇒ I=ex(sin⁡x−cos⁡x)2+C\begin{aligned} &u = \sin x,\ dv = e^x\,dx: && I = e^x \sin x - \int e^x \cos x\,dx \\ &u = \cos x,\ dv = e^x\,dx: && \int e^x \cos x\,dx = e^x \cos x + \int e^x \sin x\,dx = e^x \cos x + I \\ &\text{So } && I = e^x \sin x - e^x \cos x - I \ \Rightarrow\ 2I = e^x(\sin x - \cos x) \ \Rightarrow\ I = \frac{e^x(\sin x - \cos x)}{2} + C \end{aligned}

Treat II as an unknown and solve the equation; do not keep integrating in circles. (The two choices of uu must be the same type, both trig here; switching to u=exu = e^x the second time undoes the first step.)

Reduction formulas

Parts can lower an exponent in general. For In=∫0π/2sin⁡nx dxI_n = \int_0^{\pi/2} \sin^n x\,dx with u=sin⁡n−1xu = \sin^{n-1} x, dv=sin⁡x dxdv = \sin x\,dx, the boundary term vanishes and using cos⁡2=1−sin⁡2\cos^2 = 1 - \sin^2 gives

In=n−1n⋅In−2,I0=π2,I1=1I_n = \frac{n - 1}{n} \cdot I_{n-2}, \qquad I_0 = \frac{\pi}{2},\quad I_1 = 1

so I6=56⋅34⋅12⋅π2=5π32I_6 = \frac{5}{6} \cdot \frac{3}{4} \cdot \frac{1}{2} \cdot \frac{\pi}{2} = \frac{5\pi}{32}. Products of such ratios lead to Wallis's product for π\pi:

python · try it yourself
import math
from fractions import Fraction
from scipy.integrate import quad

def I(n):                                    # the reduction formula, applied recursively
    if n == 0: return math.pi / 2
    if n == 1: return 1.0
    return (n - 1) / n * I(n - 2)

for n in (2, 5, 6, 11):
    numeric = quad(lambda t: math.sin(t)**n, 0, math.pi / 2)[0]
    print(f"I_{n:<2} reduction = {I(n):.10f}   quad = {numeric:.10f}")

# Wallis: π/2 = Π (2k/(2k−1))·(2k/(2k+1))
p = Fraction(1)
for k in range(1, 2001):
    p *= Fraction(4 * k * k, 4 * k * k - 1)
print("Wallis product, 2000 factors: 2·P =", round(2 * float(p), 6), " π =", round(math.pi, 6))
I_2  reduction = 0.7853981634   quad = 0.7853981634
I_5  reduction = 0.5333333333   quad = 0.5333333333
I_6  reduction = 0.4908738521   quad = 0.4908738521
I_11 reduction = 0.3694083694   quad = 0.3694083694
Wallis product, 2000 factors: 2·P = 3.1412  π = 3.141593

The reduction formula matches numerical quadrature exactly. Wallis's product is beautiful but slow: 2000 factors give only four correct digits, because its error falls like 1/n1/n.

In software

  • Weak forms and the finite element method. FEM solvers (structural analysis, heat flow, cloth simulation) multiply a PDE by a test function and integrate by parts to move a derivative off the unknown; that is what makes piecewise-linear elements usable.
  • Score matching and Stein's identity. In generative ML, integration by parts turns an objective involving an unknown density into one involving only the model's score ∇log⁡p\nabla \log p, which is how diffusion models are trained without computing normalising constants.
  • Summation by parts. The discrete version ∑akΔbk=[ab]−∑bk+1Δak\sum a_k \Delta b_k = [ab] - \sum b_{k+1} \Delta a_k (Abel summation) appears in the analysis of algorithms and in convergence proofs for series.

Exercises

Exercise 1: Basic

Compute ∫xcos⁡3x dx\int x \cos 3x\,dx.

Answer

xsin⁡3x3+cos⁡3x9+C\frac{x \sin 3x}{3} + \frac{\cos 3x}{9} + C.

Solution

u=xu = x, dv=cos⁡3x dxdv = \cos 3x\,dx, v=sin⁡3x3v = \frac{\sin 3x}{3}: =xsin⁡3x3−∫sin⁡3x3 dx=xsin⁡3x3+cos⁡3x9+C= \frac{x \sin 3x}{3} - \int \frac{\sin 3x}{3}\,dx = \frac{x \sin 3x}{3} + \frac{\cos 3x}{9} + C.

Exercise 2: A definite integral with a log

Compute ∫1ex2ln⁡x dx\int_1^e x^2 \ln x\,dx.

Answer

2e3+19≈4.5746\frac{2e^3 + 1}{9} \approx 4.5746.

Solution
u=ln⁡x, dv=x2 dx, v=x33=[x3ln⁡x3]1e−∫1ex23 dx=e33−e3−19=2e3+19\begin{aligned} &u = \ln x,\ dv = x^2\,dx,\ v = \frac{x^3}{3} \\ &= \Big[\frac{x^3 \ln x}{3}\Big]_1^e - \int_1^e \frac{x^2}{3}\,dx = \frac{e^3}{3} - \frac{e^3 - 1}{9} = \frac{2e^3 + 1}{9} \end{aligned}
python · try it yourself
import sympy as sp
x = sp.symbols('x', positive=True)
r = sp.integrate(x**2 * sp.log(x), (x, 1, sp.E))
print(sp.simplify(r), round(float(r), 4))
1/9 + 2*exp(3)/9 4.5746

Exercise 3: Solve for the integral

Compute ∫e2xcos⁡x dx\int e^{2x} \cos x\,dx.

Answer

e2x(2cos⁡x+sin⁡x)5+C\frac{e^{2x}(2\cos x + \sin x)}{5} + C.

Solution
I=∫e2xcos⁡x dx;u=cos⁡x, dv=e2x dx:I=e2xcos⁡x2+12∫e2xsin⁡x dx∫e2xsin⁡x dx;u=sin⁡x, dv=e2x dx:=e2xsin⁡x2−12II=e2xcos⁡x2+e2xsin⁡x4−I4⇒ 54I=e2x(2cos⁡x+sin⁡x)4\begin{aligned} &I = \int e^{2x} \cos x\,dx; && u = \cos x,\ dv = e^{2x}\,dx: && I = \frac{e^{2x} \cos x}{2} + \frac{1}{2}\int e^{2x} \sin x\,dx \\ &\int e^{2x} \sin x\,dx; && u = \sin x,\ dv = e^{2x}\,dx: && = \frac{e^{2x} \sin x}{2} - \frac{1}{2}I \\ &I = \frac{e^{2x} \cos x}{2} + \frac{e^{2x} \sin x}{4} - \frac{I}{4} && \Rightarrow\ \frac{5}{4}I = \frac{e^{2x}(2\cos x + \sin x)}{4} \end{aligned}

Exercise 4: A reduction formula

Show that ∫(ln⁡x)n dx=x(ln⁡x)n−n∫(ln⁡x)n−1 dx\int (\ln x)^n\,dx = x(\ln x)^n - n\int (\ln x)^{n-1}\,dx, and use it for n=2n = 2.

Answer

∫(ln⁡x)2 dx=x(ln⁡x)2−2xln⁡x+2x+C\int (\ln x)^2\,dx = x(\ln x)^2 - 2x \ln x + 2x + C.

Solution

u=(ln⁡x)nu = (\ln x)^n, dv=dxdv = dx: du=n(ln⁡x)n−1x dxdu = \frac{n(\ln x)^{n-1}}{x}\,dx, v=xv = x, and v du=n(ln⁡x)n−1 dxv\,du = n(\ln x)^{n-1}\,dx. For n=2n = 2: x(ln⁡x)2−2(xln⁡x−x)x(\ln x)^2 - 2(x \ln x - x).

Test yourself

Integration by parts comes from which differentiation rule?

  1. The chain rule
  2. The quotient rule
  3. The product rule
  4. The power rule

For ∫x2ln⁡x dx\int x^2 \ln x\,dx, the better choice is…

  1. u=x2u = x^2, dv=ln⁡x dxdv = \ln x\,dx
  2. u=ln⁡xu = \ln x, dv=x2 dxdv = x^2\,dx
  3. u=x2ln⁡xu = x^2 \ln x, dv=dxdv = dx
  4. Parts does not apply

Using In=n−1nIn−2I_n = \frac{n - 1}{n} I_{n-2} with I1=1I_1 = 1, what is ∫0π/2sin⁡3x dx\int_0^{\pi/2} \sin^3 x\,dx?

  1. 34\frac{3}{4}
  2. π4\frac{\pi}{4}
  3. 13\frac{1}{3}
  4. 23\frac{2}{3}