TExcelTAD
Home › Calculus Essentials › Integration by Parts

Integration by Parts

Integration by parts handles many products that substitution cannot, such as xexx e^x, xsin⁡xx \sin x or ln⁡x\ln x. It is the product rule for derivatives turned into a rule for integrals: you trade the integral you have for one that is (hopefully) easier.

The formula

The product rule says (uv)′=u′v+uv′(uv)' = u'v + uv'. Integrate both sides and rearrange:

∫u dv=u⋅v−∫v du\int u\,dv = u \cdot v - \int v\,du

You split the integrand into two pieces: uu (which you will differentiate) and dvdv (which you will integrate). The method pays off when dudu is simpler than uu and vv is no worse than dvdv.

Example. ∫xex dx\int x e^x\,dx. Choose u=xu = x (it becomes simpler) and dv=ex dxdv = e^x\,dx:

u=xdu=dxdv=ex dxv=ex∫xex dx=xex−∫ex dx=xex−ex+C=(x−1)ex+C\begin{aligned} &u = x \qquad du = dx \\ &dv = e^x\,dx \qquad v = e^x \\[1ex] &\int x e^x\,dx = x e^x - \int e^x\,dx = x e^x - e^x + C = (x - 1)e^x + C \end{aligned}

Choosing the other way round (u=exu = e^x, dv=x dxdv = x\,dx) gives ∫(x2/2)ex dx\int (x^2/2)e^x\,dx, which is worse. If that happens, swap.

Choosing u: LIATE

A handy order for picking uu, first choice first:

Letter Type Examples
L Logarithmic ln⁡x\ln x
I Inverse trig arctan⁡x\arctan x, arcsin⁡x\arcsin x
A Algebraic xx, x2x^2, polynomials
T Trigonometric sin⁡x\sin x, cos⁡x\cos x
E Exponential exe^x, 2x2^x

It is a rule of thumb, not a law, but it works for most textbook products.

Classic cases

∫ln⁡x dx:u=ln⁡x, dv=dx→xln⁡x−∫x⋅(1/x) dx=xln⁡x−x+C∫x2sin⁡x dx:parts twice→−x2cos⁡x+2xsin⁡x+2cos⁡x+C∫exsin⁡x dx:parts twice gives the original integral back; solve for it:→ex(sin⁡x−cos⁡x)/2+C\begin{aligned} \int \ln x\,dx&: \quad u = \ln x,\ dv = dx \to x \ln x - \int x \cdot (1/x)\,dx = x \ln x - x + C \\ \int x^2 \sin x\,dx&: \quad \text{parts twice} \to -x^2 \cos x + 2x \sin x + 2 \cos x + C \\ \int e^x \sin x\,dx&: \quad \text{parts twice gives the original integral back; solve for it} \\ &\phantom{:} \quad \to e^x (\sin x - \cos x) / 2 + C \end{aligned}

The last one is the "boomerang": after two rounds, I=exsin⁡x−excos⁡x−II = e^x \sin x - e^x \cos x - I, so 2I=ex(sin⁡x−cos⁡x)2I = e^x(\sin x - \cos x).

python · try it yourself
import sympy as sp

x = sp.symbols("x")
for f in [x * sp.exp(x), sp.log(x), x**2 * sp.sin(x), sp.exp(x) * sp.sin(x)]:
    F = sp.integrate(f, x)
    ok = sp.simplify(sp.diff(F, x) - f) == 0
    print(f"∫ {str(f):14} dx = {str(F):40} check: {ok}")
∫ x*exp(x)       dx = (x - 1)*exp(x)                           check: True
∫ log(x)         dx = x*log(x) - x                             check: True
∫ x**2*sin(x)    dx = -x**2*cos(x) + 2*x*sin(x) + 2*cos(x)     check: True
∫ exp(x)*sin(x)  dx = exp(x)*sin(x)/2 - exp(x)*cos(x)/2        check: True

For definite integrals the uvuv part is evaluated at the limits: ∫abu dv=[uv]ab−∫abv du\int_a^b u\,dv = \Big[uv\Big]_a^b - \int_a^b v\,du.

In software: expected values and factorials

The mean of an exponential distribution. Waiting times (time to the next request, the next failure) are often modelled with the density p(x)=λe−λxp(x) = \lambda e^{-\lambda x}, x≥0x \ge 0. The mean is E[X]=∫0∞xλe−λx dxE[X] = \int_0^\infty x \lambda e^{-\lambda x}\,dx. With u=xu = x, dv=λe−λx dxdv = \lambda e^{-\lambda x}\,dx, v=−e−λxv = -e^{-\lambda x}:

E[X]=[−xe−λx]0∞+∫0∞e−λx dx=0+1/λE[X] = \Big[-x e^{-\lambda x}\Big]_0^\infty + \int_0^\infty e^{-\lambda x}\,dx = 0 + 1/\lambda

So a server with on average λ=4\lambda = 4 requests per second has a mean gap of 0.25 s.

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

lam = 4.0
mean, _ = quad(lambda x: x * lam * math.exp(-lam * x), 0, math.inf)
print(f"E[X] by integration = {mean:.6f}, 1/λ = {1 / lam}")

# Gamma function: repeated integration by parts gives ∫ x^n e^-x dx = n!
for n in [3, 5, 8]:
    val, _ = quad(lambda x: x**n * math.exp(-x), 0, math.inf)
    print(f"n={n}: integral = {val:.4f}   n! = {math.factorial(n)}")
E[X] by integration = 0.250000, 1/λ = 0.25
n=3: integral = 6.0000   n! = 6
n=5: integral = 120.0000   n! = 120
n=8: integral = 40320.0000   n! = 40320

The second result is the Gamma function: each round of parts lowers the power by one and multiplies by it, ∫xne−x dx=n⋅∫xn−1e−x dx\int x^n e^{-x}\,dx = n \cdot \int x^{n-1} e^{-x}\,dx, which is why Γ(n+1)=n!\Gamma(n + 1) = n!. Python's math.gamma extends factorials to non-integers this way, and many probability distributions used in ML (Gamma, Beta, Student t) have it in their formulas.

Note: For repeated parts with a polynomial times exe^x or sin⁡x\sin x, the tabular method saves writing: list derivatives of the polynomial down to 0 in one column, integrals of the other factor in the next, and combine diagonals with alternating signs +−+…+ - + \ldots.

Exercises

Exercise 1: One round

Find ∫xcos⁡x dx\int x \cos x\,dx.

Answer

xsin⁡x+cos⁡x+Cx \sin x + \cos x + C

Solution
u=x, du=dx;dv=cos⁡x dx, v=sin⁡x∫xcos⁡x dx=xsin⁡x−∫sin⁡x dx=xsin⁡x+cos⁡x+C\begin{aligned} &u = x,\ du = dx; \quad dv = \cos x\,dx,\ v = \sin x \\ &\int x \cos x\,dx = x \sin x - \int \sin x\,dx = x \sin x + \cos x + C \end{aligned}

Exercise 2: Logarithm times x

Find ∫xln⁡x dx\int x \ln x\,dx.

Answer

(x2/2)ln⁡x−x2/4+C(x^2/2) \ln x - x^2/4 + C

Solution
LIATE: u=ln⁡x, du=dx/x;dv=x dx, v=x2/2∫xln⁡x dx=(x2/2)ln⁡x−∫(x2/2)(1/x) dx=(x2/2)ln⁡x−x2/4+C\begin{aligned} &\text{LIATE: } u = \ln x,\ du = dx/x; \quad dv = x\,dx,\ v = x^2/2 \\ &\int x \ln x\,dx = (x^2/2) \ln x - \int (x^2/2)(1/x)\,dx = (x^2/2) \ln x - x^2/4 + C \end{aligned}

Exercise 3: Definite

Evaluate ∫01xe−x dx\int_0^1 x e^{-x}\,dx.

Answer

1−2/e≈0.26421 - 2/e \approx 0.2642

Solution
u=x, dv=e−x dx, v=−e−x∫01xe−x dx=[−xe−x]01+∫01e−x dx=−e−1+(1−e−1)=1−2/e\begin{aligned} &u = x,\ dv = e^{-x}\,dx,\ v = -e^{-x} \\ &\int_0^1 x e^{-x}\,dx = \Big[-x e^{-x}\Big]_0^1 + \int_0^1 e^{-x}\,dx = -e^{-1} + (1 - e^{-1}) = 1 - 2/e \end{aligned}

Exercise 4: Tabular method

Find ∫x3ex dx\int x^3 e^x\,dx with the tabular method and check it with SymPy.

Answer

ex(x3−3x2+6x−6)+Ce^x(x^3 - 3x^2 + 6x - 6) + C

Solution
text
derivatives of x³:  x³   3x²   6x   6   0
integrals of eˣ:    eˣ   eˣ    eˣ   eˣ
signs:              +    −     +    −
result: x³eˣ − 3x²eˣ + 6xeˣ − 6eˣ + C
python · try it yourself
import sympy as sp

x = sp.symbols("x")
mine = sp.exp(x) * (x**3 - 3 * x**2 + 6 * x - 6)
print(sp.simplify(sp.diff(mine, x) - x**3 * sp.exp(x)) == 0)
True

Test yourself

For ∫x2ex dx\int x^2 e^x\,dx, which choice of uu follows LIATE?

  1. u=exu = e^x
  2. u=x2exu = x^2 e^x
  3. u=x2u = x^2
  4. u=1u = 1

Integration by parts comes from which rule?

  1. The product rule
  2. The chain rule
  3. The quotient rule
  4. L'Hôpital's rule

What is ∫0∞x4e−x dx\int_0^\infty x^4 e^{-x}\,dx?

  1. 4
  2. 1
  3. 120
  4. 24