Problem 40.1
Let P1,P2 be two points chosen independently and uniformly in the unit square [0,1]2. What is the expected squared distance E[∣P1−P2∣2]?
Solution. Write Pi=(Xi,Yi). The squared distance decomposes as ∣P1−P2∣2=(X1−X2)2+(Y1−Y2)2. By linearity, E[∣P1−P2∣2]=E[(X1−X2)2]+E[(Y1−Y2)2]. For X1,X2 iid uniform on [0,1], E[(X1−X2)2]=Var(X1−X2)=2Var(X1)=122=61, using Var(X1)=1/12 for uniform on [0,1]. Similarly for the Y-terms.
Therefore E[∣P1−P2∣2]=61+61=31.■
Compare the analogous constant for the unit disc (Chapter 31): E[∣P1−P2∣2]=1 for radius 1. The two constants reveal a dimensional structure: for a planar region K with centroid at the origin, E[∣P1−P2∣2]=2⋅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; for the unit square centred at the centroid, E[∣P∣2]=1/6, giving E[∣P1−P2∣2]=2⋅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