Library · Geometric Probability · Chapter 40

Expected squared distance in a unit square

Revised Report an error

Problem 40.1

Let P1,P2P_1, P_2 be two points chosen independently and uniformly in the unit square [0,1]2[0, 1]^2. What is the expected squared distance E[∣P1−P2∣2]\mathbb{E}[|P_1 - P_2|^2]?

Solution. Write Pi=(Xi,Yi)P_i = (X_i, Y_i). The squared distance decomposes as ∣P1−P2∣2=(X1−X2)2+(Y1−Y2)2.|P_1 - P_2|^2 = (X_1 - X_2)^2 + (Y_1 - Y_2)^2. By linearity, E[∣P1−P2∣2]=E[(X1−X2)2]+E[(Y1−Y2)2].\mathbb{E}[|P_1 - P_2|^2] = \mathbb{E}[(X_1 - X_2)^2] + \mathbb{E}[(Y_1 - Y_2)^2]. For X1,X2X_1, X_2 iid uniform on [0,1][0, 1], E[(X1−X2)2]=Var⁡(X1−X2)=2Var⁡(X1)=212=16,\mathbb{E}[(X_1 - X_2)^2] = \operatorname{Var}(X_1 - X_2) = 2 \operatorname{Var}(X_1) = \tfrac{2}{12} = \tfrac{1}{6}, using Var⁡(X1)=1/12\operatorname{Var}(X_1) = 1/12 for uniform on [0,1][0, 1]. Similarly for the YY-terms.

Therefore E[∣P1−P2∣2]=16+16=13.■\boxed{\mathbb{E}[|P_1 - P_2|^2] = \frac{1}{6} + \frac{1}{6} = \frac{1}{3}.} \qedhere

Compare the analogous constant for the unit disc (Chapter 31): E[∣P1−P2∣2]=1\mathbb{E}[|P_1 - P_2|^2] = 1 for radius 11. The two constants reveal a dimensional structure: for a planar region KK with centroid at the origin, E[∣P1−P2∣2]=2⋅E[∣P∣2],\mathbb{E}[|P_1 - P_2|^2] = 2 \cdot \mathbb{E}[|P|^2], so the ratio between disc and square values reflects the moment of inertia per unit area. For the unit disc, E[∣P∣2]=1/2\mathbb{E}[|P|^2] = 1/2; for the unit square centred at the centroid, E[∣P∣2]=1/6\mathbb{E}[|P|^2] = 1/6, giving E[∣P1−P2∣2]=2⋅1/6=1/3\mathbb{E}[|P_1 - P_2|^2] = 2 \cdot 1/6 = 1/3.

import numpy as np
p = np.random.rand(2, 2, 10**7)
d2 = np.sum((p[:,0] - p[:,1])**2, axis=0)
print(f"sim: {d2.mean():.5f}   exact: {1/3:.5f}")
# sim: 0.33311   exact: 0.33333
Report an error on this page

Reports are stored by Netlify. See the privacy note.