Integration by Parts

Integration by parts is the reverse of the product rule. It turns an integral of a product into an easier one, and it is the standard way to compute the mean of the exponential and gamma distributions. In survival analysis it yields a clean fact: the mean waiting time is the area under the survival curve, E[T]=0S(t)dt\mathbb{E}[T] = \int_0^\infty S(t)\,dt — for example the mean time to infection or to pathogen clearance.

The formula

Starting from the product rule ddx(uv)=uv+uv\frac{d}{dx}(uv) = u\,v' + u'\,v and integrating both sides, then rearranging, gives

udv=uvvdu.\int u\,dv = uv - \int v\,du .

Here you split the integrand into a part uu (to differentiate) and a part dvdv (to integrate): compute du=udxdu = u'\,dx and v=dvv = \int dv, then apply the formula and hope the new integral vdu\int v\,du is simpler.

Choosing uu and dvdv: LIATE

A useful priority for picking uu (differentiate first what comes earliest):

Whatever is left becomes dvdv. The goal is for vdu\int v\,du to be easier than the original.

Worked example

Compute xexdx\displaystyle\int x\,e^{-x}\,dx. By LIATE, the algebraic factor xx is uu and exdxe^{-x}dx is dvdv:

u=x,du=dx,dv=exdx,v=ex.u = x,\quad du = dx, \qquad dv = e^{-x}\,dx,\quad v = -e^{-x}.

Apply the formula:

xexdx=xex(ex)dx=xexex+C=(x+1)ex+C.\int x\,e^{-x}\,dx = -x e^{-x} - \int (-e^{-x})\,dx = -x e^{-x} - e^{-x} + C = -(x+1)e^{-x} + C .

Definite version over [0,)[0,\infty):

0xexdx=[(x+1)ex]0=0((0+1)1)=1.\int_0^\infty x\,e^{-x}\,dx = \Big[-(x+1)e^{-x}\Big]_0^\infty = 0 - (-(0+1)\cdot 1) = 1 .

Computing it

R

# Numeric check: integral of x*exp(-x) from 0 to Inf equals 1
integrate(function(x) x * exp(-x), 0, Inf)$value   # 1
$```

### Python

```python
import sympy as sp
from scipy.integrate import quad
import numpy as np

x = sp.symbols("x")
print(sp.integrate(x*sp.exp(-x), x))            # -x*exp(-x) - exp(-x)
print(sp.integrate(x*sp.exp(-x), (x, 0, sp.oo)))  # 1

val, _ = quad(lambda t: t*np.exp(-t), 0, np.inf)
print(val)                                      # 1.0000000000000002
(-x - 1)*exp(-x)
1
0.9999999999999998

Julia

using Symbolics, QuadGK

@variables x
# Numeric verification
println(quadgk(t -> t*exp(-t), 0, Inf)[1])      # 1.0

# Symbolic check: d/dx[-(x+1)e^{-x}] = x e^{-x}
D = Differential(x)
expand_derivatives(D(-(x+1)*exp(-x)))           # x*exp(-x)

Why it matters for statistics

The exponential distribution with rate λ\lambda has density λeλx\lambda e^{-\lambda x}, and its mean is

E[X]=0xλeλxdx=1λ,E[X] = \int_0^\infty x\,\lambda e^{-\lambda x}\,dx = \frac{1}{\lambda},

which is exactly the integration-by-parts computation above (with a rescaling). The same technique produces the moments of the gamma distribution and appears whenever you integrate a polynomial against an exponential kernel.