TExcelTAD
Home › Probability Theory › Sums of Continuous Variables

Sums of Continuous Variables

For continuous variables the convolution sum becomes an integral. If XX and YY are independent with densities ff and gg, then Z=X+YZ = X + Y has density

h(z)=(f∗g)(z)=∫−∞∞f(x) g(z−x) dxh(z) = (f * g)(z) = \int_{-\infty}^{\infty} f(x)\, g(z - x)\,dx

Two uniforms make a triangle

For X,YX, Y uniform on [0,1][0, 1], the integrand is 1 when both 0≤x≤10 \le x \le 1 and 0≤z−x≤10 \le z - x \le 1. The overlap has length zz for 0≤z≤10 \le z \le 1 and 2−z2 - z for 1≤z≤21 \le z \le 2:

h(z)={z0≤z≤12−z1≤z≤2h(z) = \begin{cases} z & 0 \le z \le 1 \\ 2 - z & 1 \le z \le 2 \end{cases}

a triangle. Adding a third uniform gives a piecewise quadratic, already quite bell-shaped (the Irwin–Hall densities).

python · try it yourself
import random

rng = random.Random(1)
n = 200_000
for k in [1, 2, 3, 12]:
    sums = [sum(rng.random() for _ in range(k)) for _ in range(n)]
    hist = [0] * 10
    for s in sums:
        hist[min(int(s / k * 10), 9)] += 1
    print(f"k={k:2d}: " + " ".join(f"{h / n:.3f}" for h in hist))
k= 1: 0.099 0.101 0.100 0.099 0.101 0.101 0.099 0.100 0.100 0.101
k= 2: 0.020 0.060 0.100 0.141 0.178 0.179 0.140 0.100 0.060 0.020
k= 3: 0.004 0.031 0.086 0.162 0.217 0.215 0.163 0.086 0.031 0.005
k=12: 0.000 0.000 0.007 0.109 0.384 0.383 0.109 0.008 0.000 0.000

The rows show the distribution of the sum rescaled to [0,1][0, 1], in 10 bins. One uniform is flat; two make a triangle; twelve are already very close to a normal curve. The sum of 12 uniforms minus 6 has mean 0 and variance 12⋅112=112 \cdot \frac{1}{12} = 1, an old trick for generating approximately standard normal numbers.

Exponentials sum to gamma

The sum of nn independent exponentials with rate λ\lambda has the gamma density λntn−1(n−1)!e−λt\frac{\lambda^n t^{n-1}}{(n-1)!} e^{-\lambda t} (Gamma, Beta and Chi-Squared). For two exponentials the convolution integral is short:

h(z)=∫0zλe−λxλe−λ(z−x) dx=λ2e−λz∫0zdx=λ2ze−λzh(z) = \int_0^z \lambda e^{-\lambda x} \lambda e^{-\lambda(z - x)}\,dx = \lambda^2 e^{-\lambda z} \int_0^z dx = \lambda^2 z e^{-\lambda z}
python · try it yourself
from sympy import symbols, integrate, exp, simplify

x, z = symbols("x z", positive=True)
lam = symbols("lambda", positive=True)
f = lam * exp(-lam * x)
h2 = simplify(integrate(f * lam * exp(-lam * (z - x)), (x, 0, z)))
print("two exponentials:", h2)
h3 = simplify(integrate(h2.subs(z, x) * lam * exp(-lam * (z - x)), (x, 0, z)))
print("three exponentials:", h3)
two exponentials: lambda**2*z*exp(-lambda*z)
three exponentials: lambda**3*z**2*exp(-lambda*z)/2

Normals sum to normals

If X∼N(μ1,σ12)X \sim N(\mu_1, \sigma_1^2) and Y∼N(μ2,σ22)Y \sim N(\mu_2, \sigma_2^2) are independent, then X+Y∼N(μ1+μ2,σ12+σ22)X + Y \sim N(\mu_1 + \mu_2, \sigma_1^2 + \sigma_2^2). Completing the square in the convolution integral proves it; moment generating functions prove it in one line. This stability is special: the normal is the fixed point that sums of many independent variables converge to.

The Cauchy surprise

The average of nn independent Cauchy variables has the same Cauchy distribution as one of them. Averaging does not help at all, because the Cauchy has no mean (Expectation for Densities). Convolution confirms what the running averages showed: heavy tails do not average out.

python · try it yourself
import math
import random

rng = random.Random(2)
cauchy = lambda: math.tan(math.pi * (rng.random() - 0.5))
for n in [1, 10, 100]:
    avgs = [sum(cauchy() for _ in range(n)) / n for _ in range(20_000)]
    inside = sum(abs(a) < 1 for a in avgs) / len(avgs)
    print(f"average of {n:3d} Cauchy samples: P(|avg| < 1) = {inside:.3f}")
print("for a single Cauchy: P(|X| < 1) = 0.5")
average of   1 Cauchy samples: P(|avg| < 1) = 0.499
average of  10 Cauchy samples: P(|avg| < 1) = 0.505
average of 100 Cauchy samples: P(|avg| < 1) = 0.500
for a single Cauchy: P(|X| < 1) = 0.5

In software

Sums of continuous variables model total delays in a pipeline, total measurement error, and aggregated risk. Noise added in differential privacy is often Laplace or Gaussian, and the privacy analysis of many noisy queries is a statement about sums of these. Kernel density estimates are themselves convolutions of the data with a smoothing kernel.

Exercises

Exercise 1: Triangle probability

For the sum of two uniforms on [0,1][0, 1], find Pr⁡[Z≤0.5]\Pr[Z \le 0.5] and Pr⁡[Z≤1.5]\Pr[Z \le 1.5].

Answer

1/81/8 and 7/87/8.

Solution

∫00.5z dz=1/8\int_0^{0.5} z\,dz = 1/8. By symmetry about 1, Pr⁡[Z≤1.5]=1−1/8\Pr[Z \le 1.5] = 1 - 1/8.

Exercise 2: Variance of the sum

What are the mean and variance of the sum of 12 independent uniforms on [0,1][0, 1]?

Answer

Mean 6, variance 1.

Solution

Each has mean 1/21/2 and variance 1/121/12; both add over independent terms.

Exercise 3: Sum of uniforms on different ranges (code)

Simulate X+YX + Y with XX uniform on [0,1][0, 1] and YY uniform on [0,2][0, 2], and compare Pr⁡[X+Y≤1]\Pr[X + Y \le 1] and Pr⁡[X+Y≤2]\Pr[X + Y \le 2] with the exact values 1/41/4 and 3/43/4.

Answer

Simulated values near 0.25 and 0.75; the density is a trapezoid.

Solution

The joint density is 1/21/2 on the rectangle [0,1]×[0,2][0, 1] \times [0, 2]. Pr⁡[X+Y≤1]\Pr[X + Y \le 1] is a triangle of area 1/21/2 times 1/21/2; Pr⁡[X+Y≤2]\Pr[X + Y \le 2] is area 3/23/2 times 1/21/2.

python · try it yourself
import random

rng = random.Random(3)
n = 200_000
s = [rng.random() + rng.uniform(0, 2) for _ in range(n)]
print(round(sum(v <= 1 for v in s) / n, 4), round(sum(v <= 2 for v in s) / n, 4))
0.2487 0.7498

Test yourself

The sum of two independent uniforms on [0,1][0, 1] has which density?

  1. Uniform on [0,2][0, 2]
  2. Triangular on [0,2][0, 2]
  3. Exponential
  4. Normal

The average of 100 independent Cauchy variables has…

  1. a normal distribution
  2. the same Cauchy distribution as one variable
  3. variance 1/100
  4. a point mass at 0