TExcelTAD
Home › Calculus in Depth › Improper Integrals

Improper Integrals

The definite integral was defined on a closed, bounded interval for a bounded function. Probability, physics and signal processing constantly need more: integrals over [0,∞)[0, \infty), or of functions that blow up at an endpoint. Improper integrals extend the definition with a limit. This lesson defines both types, proves the pp-integral test, gives the comparison test, evaluates the Gaussian integral, and shows why every probability density is an improper integral that must equal 1.

Type 1: infinite intervals

Definition. If ∫atf(x) dx\int_a^t f(x)\,dx exists for every t≥at \ge a, then

∫a∞f(x) dx=lim⁡t→∞∫atf(x) dx\int_a^{\infty} f(x)\,dx = \lim_{t \to \infty} \int_a^t f(x)\,dx

provided the limit exists (as a finite number). Then the integral converges; otherwise it diverges. Similarly for ∫−∞b\int_{-\infty}^{b}. For ∫−∞∞\int_{-\infty}^{\infty} split at any point cc: it converges only if both halves converge.

The last rule matters: ∫−ttx dx=0\int_{-t}^{t} x\,dx = 0 for every tt, but ∫0∞x dx\int_0^{\infty} x\,dx diverges, so ∫−∞∞x dx\int_{-\infty}^{\infty} x\,dx diverges. The symmetric limit is called the Cauchy principal value, and it is a different (weaker) notion.

Type 2: discontinuous integrands

Definition. If ff is continuous on [a,b)[a, b) and unbounded near bb, then ∫abf(x) dx=lim⁡t→b−∫atf(x) dx\int_a^b f(x)\,dx = \lim_{t \to b^-} \int_a^t f(x)\,dx, if the limit exists. Similarly at the left end, and an interior discontinuity at cc splits the integral into two, both of which must converge.

This is the fix for the false computation ∫−11dxx2=−2\int_{-1}^{1} \frac{dx}{x^2} = -2 from the Fundamental Theorem lesson: ∫01dxx2=lim⁡t→0+(1t−1)=∞\int_0^1 \frac{dx}{x^2} = \lim_{t \to 0^+} \big(\frac{1}{t} - 1\big) = \infty, so the integral diverges.

The p-integrals

Theorem. ∫1∞dxxp\int_1^{\infty} \frac{dx}{x^p} converges if p>1p > 1 (to 1p−1\frac{1}{p - 1}) and diverges if p≤1p \le 1. ∫01dxxp\int_0^1 \frac{dx}{x^p} converges if p<1p < 1 (to 11−p\frac{1}{1 - p}) and diverges if p≥1p \ge 1.

Proof (first part). For p≠1p \ne 1, ∫1tx−p dx=t1−p−11−p\int_1^t x^{-p}\,dx = \frac{t^{1-p} - 1}{1 - p}. If p>1p > 1, t1−p→0t^{1-p} \to 0 and the limit is 1p−1\frac{1}{p - 1}. If p<1p < 1, t1−p→∞t^{1-p} \to \infty. For p=1p = 1, ∫1tdxx=ln⁡t→∞\int_1^t \frac{dx}{x} = \ln t \to \infty. The second part is the same computation with t→0+t \to 0^+. ∎

1/x1/x is the borderline in both directions: just a little faster decay (1/x1.011/x^{1.01}) at infinity converges, and a little slower blow-up (1/x0.991/x^{0.99}) at zero converges.

python · try it yourself
import sympy as sp

x, t = sp.symbols('x t', positive=True)
for p in [sp.Rational(1, 2), 1, sp.Rational(3, 2), 2]:
    tail = sp.limit(sp.integrate(x**-p, (x, 1, t)), t, sp.oo)
    head = sp.limit(sp.integrate(x**-p, (x, t, 1)), t, 0, '+')
    print(f"p = {str(p):4}: ∫_1^∞ = {str(tail):4}   ∫_0^1 = {head}")
p = 1/2 : ∫_1^∞ = oo     ∫_0^1 = 2
p = 1   : ∫_1^∞ = oo     ∫_0^1 = oo
p = 3/2 : ∫_1^∞ = 2      ∫_0^1 = oo
p = 2   : ∫_1^∞ = 1      ∫_0^1 = oo

The comparison test

Comparison Theorem. Let f,gf, g be continuous with 0≤g(x)≤f(x)0 \le g(x) \le f(x) for x≥ax \ge a. If ∫a∞f\int_a^{\infty} f converges, so does ∫a∞g\int_a^{\infty} g. If ∫a∞g\int_a^{\infty} g diverges, so does ∫a∞f\int_a^{\infty} f.

(The proof uses that t↦∫atgt \mapsto \int_a^t g is increasing and bounded above, hence has a limit: the completeness of the reals again.) It decides convergence without computing the value:

∫1∞e−x2 dx:e−x2≤e−x for x≥1, and ∫1∞e−x dx=1e converges⇒ converges∫1∞1+sin⁡2xx dx:≥1x, and p=12≤1 diverges⇒ diverges\begin{aligned} &\int_1^{\infty} e^{-x^2}\,dx: && e^{-x^2} \le e^{-x} \text{ for } x \ge 1, \text{ and } \int_1^{\infty} e^{-x}\,dx = \frac{1}{e} \text{ converges} && \Rightarrow\ \text{converges} \\ &\int_1^{\infty} \frac{1 + \sin^2 x}{\sqrt{x}}\,dx: && \ge \frac{1}{\sqrt{x}}, \text{ and } p = \frac{1}{2} \le 1 \text{ diverges} && \Rightarrow\ \text{diverges} \end{aligned}

The Gaussian integral

The bell curve e−x2e^{-x^2} has no elementary antiderivative, yet its improper integral has an exact value:

∫−∞∞e−x2 dx=π\int_{-\infty}^{\infty} e^{-x^2}\,dx = \sqrt{\pi}

Proof sketch. Call the integral II. Then I2=∬e−(x2+y2) dx dyI^2 = \iint e^{-(x^2 + y^2)}\,dx\,dy over the whole plane. In polar coordinates, x2+y2=r2x^2 + y^2 = r^2 and the area element is r dr dθr\,dr\,d\theta, so I2=∫02π∫0∞e−r2r dr dθ=2π⋅12=πI^2 = \int_0^{2\pi} \int_0^{\infty} e^{-r^2} r\,dr\,d\theta = 2\pi \cdot \frac{1}{2} = \pi. The extra factor rr is what makes the inner integral elementary (Double Integrals in Polar Coordinates makes this rigorous).

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

x = sp.symbols('x', real=True)
print("SymPy:", sp.integrate(sp.exp(-x**2), (x, -sp.oo, sp.oo)))
val, err = quad(lambda s: math.exp(-s * s), -math.inf, math.inf)
print(f"quad:  {val:.15f}  (estimated error {err:.1e})")
print(f"√π:    {math.sqrt(math.pi):.15f}")
# a finite window already captures almost everything: the tails are tiny
print(f"∫_-6^6 e^(-x^2) dx = {quad(lambda s: math.exp(-s * s), -6, 6)[0]:.15f}")
SymPy: sqrt(pi)
quad:  1.772453850905516  (estimated error 1.4e-08)
√π:    1.772453850905516
∫_-6^6 e^(-x^2) dx = 1.772453850905516

Probability densities

A probability density function (pdf) ff satisfies f≥0f \ge 0 and ∫−∞∞f(x) dx=1\int_{-\infty}^{\infty} f(x)\,dx = 1; probabilities are areas, P(a≤X≤b)=∫abf(x) dxP(a \le X \le b) = \int_a^b f(x)\,dx, and the mean is the improper integral μ=∫−∞∞xf(x) dx\mu = \int_{-\infty}^{\infty} x f(x)\,dx, when it converges. Rescaling the Gaussian integral gives the normal density

f(x)=1σ2π⋅e−(x−μ)2/(2σ2)f(x) = \frac{1}{\sigma\sqrt{2\pi}} \cdot e^{-(x - \mu)^2/(2\sigma^2)}

whose constant is exactly what makes the total area 1. The exponential density λe−λx\lambda e^{-\lambda x} (x≥0x \ge 0) models waiting times; the Cauchy density 1π(1+x2)\frac{1}{\pi(1 + x^2)} is a warning: it integrates to 1, but ∫0∞xπ(1+x2) dx=∞\int_0^{\infty} \frac{x}{\pi(1 + x^2)}\,dx = \infty, so it has no mean, and averages of Cauchy samples never settle down.

python · try it yourself
import numpy as np
from scipy.integrate import quad

normal = lambda x, mu=1.0, s=2.0: np.exp(-(x - mu)**2 / (2 * s * s)) / (s * np.sqrt(2 * np.pi))
expo = lambda x, lam=0.5: lam * np.exp(-lam * x)
cauchy = lambda x: 1 / (np.pi * (1 + x * x))
print("normal: total =", round(quad(normal, -np.inf, np.inf)[0], 10), " mean =", round(quad(lambda x: x * normal(x), -np.inf, np.inf)[0], 10))
print("expo:   total =", round(quad(expo, 0, np.inf)[0], 10), " mean =", round(quad(lambda x: x * expo(x), 0, np.inf)[0], 10))
print("cauchy: total =", round(quad(cauchy, -np.inf, np.inf)[0], 10), " but ∫_0^t x f(x) dx grows like ln t:")
for t in (1e2, 1e4, 1e6):
    print(f"   t = {t:.0e}: {np.log1p(t * t) / (2 * np.pi):.4f}")

rng = np.random.default_rng(11)
for n in (10**3, 10**5, 10**6):
    print(f"mean of {n:>7} samples: normal {float(rng.normal(1, 2, n).mean()):+.4f}   cauchy {float(rng.standard_cauchy(n).mean()):+.4f}")
normal: total = 1.0  mean = 1.0
expo:   total = 1.0  mean = 2.0
cauchy: total = 1.0  but ∫_0^t x f(x) dx grows like ln t:
   t = 1e+02: 1.4659
   t = 1e+04: 2.9317
   t = 1e+06: 4.3976
mean of    1000 samples: normal +1.0327   cauchy +1.5179
mean of  100000 samples: normal +0.9974   cauchy +3.2799
mean of 1000000 samples: normal +1.0040   cauchy -1.7165

The normal sample means settle at the true mean 1; the Cauchy ones keep jumping, however many samples you take.

In software

  • Machine learning. Likelihoods, the normalising constants of densities, KL divergences and expected losses are improper integrals. Diffusion models and VAEs are built on Gaussians precisely because their integrals have closed forms.
  • Heavy tails in systems. Latencies, file sizes and request rates often have power-law tails like 1/xp1/x^p. The pp-integral test predicts when the mean (p>2p > 2 for a density tail ∼1/xp\sim 1/x^p) or variance (p>3p > 3) exists; when they do not, averages are unstable and percentiles are the right metric.
  • Numerical tails. quad handles infinite limits by substituting x=t1−tx = \frac{t}{1 - t} to map [0,∞)[0, \infty) to [0,1)[0, 1). Rapidly decaying tails can also be cut at a finite point, as the [−6,6][-6, 6] example shows.

Exercises

Exercise 1: Type 1

Evaluate ∫0∞xe−x dx\int_0^{\infty} x e^{-x}\,dx.

Answer
Solution

By parts, ∫0txe−x dx=[−xe−x−e−x]0t=1−(t+1)e−t→1\int_0^t x e^{-x}\,dx = \Big[-x e^{-x} - e^{-x}\Big]_0^t = 1 - (t + 1)e^{-t} \to 1 (exponentials beat powers). This is the mean of the exponential distribution with λ=1\lambda = 1.

Exercise 2: Type 2

Evaluate ∫04dx4−x\int_0^4 \frac{dx}{\sqrt{4 - x}}.

Answer
Solution

∫0t(4−x)−1/2 dx=[−24−x]0t=4−24−t→4\int_0^t (4 - x)^{-1/2}\,dx = \Big[-2\sqrt{4 - x}\Big]_0^t = 4 - 2\sqrt{4 - t} \to 4 as t→4−t \to 4^-.

python · try it yourself
import sympy as sp
x = sp.symbols('x')
print(sp.integrate(1 / sp.sqrt(4 - x), (x, 0, 4)))
4

Exercise 3: Comparison

Does ∫1∞dxx3+x\int_1^{\infty} \frac{dx}{x^3 + \sqrt{x}} converge?

Answer

Yes.

Solution

For x≥1x \ge 1, 0<1x3+x≤1x30 < \frac{1}{x^3 + \sqrt{x}} \le \frac{1}{x^3}, and ∫1∞dxx3\int_1^{\infty} \frac{dx}{x^3} converges (p=3>1p = 3 > 1).

Exercise 4: Normalise a density

Find cc so that f(x)=c1+x2f(x) = \frac{c}{1 + x^2} is a probability density on R\mathbb{R}.

Answer

c=1πc = \frac{1}{\pi}.

Solution

∫−∞∞dx1+x2=lim⁡[tan⁡−1x]=π2−(−π2)=π\int_{-\infty}^{\infty} \frac{dx}{1 + x^2} = \lim \big[\tan^{-1} x\big] = \frac{\pi}{2} - \big(-\frac{\pi}{2}\big) = \pi, so c=1πc = \frac{1}{\pi} (the Cauchy density).

Exercise 5: A Gaussian moment

Using ∫−∞∞e−x2 dx=π\int_{-\infty}^{\infty} e^{-x^2}\,dx = \sqrt{\pi}, compute ∫−∞∞x2e−x2 dx\int_{-\infty}^{\infty} x^2 e^{-x^2}\,dx.

Answer

π2\frac{\sqrt{\pi}}{2}.

Solution

By parts with u=xu = x, dv=xe−x2 dxdv = x e^{-x^2}\,dx, v=−12e−x2v = -\frac{1}{2}e^{-x^2}: the boundary term [−12xe−x2]\big[-\frac{1}{2}x e^{-x^2}\big] vanishes at ±∞\pm\infty, leaving 12∫e−x2 dx=π2\frac{1}{2}\int e^{-x^2}\,dx = \frac{\sqrt{\pi}}{2}.

python · try it yourself
import sympy as sp
x = sp.symbols('x', real=True)
print(sp.integrate(x**2 * sp.exp(-x**2), (x, -sp.oo, sp.oo)))
sqrt(pi)/2

Test yourself

For which pp does ∫1∞dxxp\int_1^{\infty} \frac{dx}{x^p} converge?

  1. p≥1p \ge 1
  2. p<1p < 1
  3. All p>0p > 0
  4. p>1p > 1

Why does ∫−∞∞x dx\int_{-\infty}^{\infty} x\,dx diverge even though ∫−ttx dx=0\int_{-t}^{t} x\,dx = 0 for every tt?

  1. It does not diverge
  2. Both halves must converge separately, and ∫0∞x dx=∞\int_0^{\infty} x\,dx = \infty
  3. xx is odd
  4. Because of the Cauchy principal value

Why does the Cauchy distribution have no mean?

  1. ∫xπ(1+x2) dx\int \frac{x}{\pi(1 + x^2)}\,dx over [0,∞)[0, \infty) diverges
  2. Its total area is not 1
  3. It is not symmetric
  4. It has no density