Problem
The Riddler Manufacturing Company makes all sorts of mathematical tools: compasses, protractors, slide rules — you name it!
Recently, there was an issue with the production of foot-long rulers. It seems that each ruler was accidentally sliced at three random points along the ruler, resulting in four pieces. Looking on the bright side, that means there are now four times as many rulers — they just happen to have different lengths.
On average, how long are the pieces that contain the 6-inch mark?
Order Statistics
Let X1​,X2​,⋯,Xn​ be a random sample of size n from a continuous distribution with distribution function F(x). We order the random sample in increasing order and obtain Y1​,Y2​,⋯,Yn​. In other words, we have:
Y1​= the smallest of X1​,X2​,⋯,Xn​
Y2​= the second smallest of X1​,X2​,⋯,Xn​
â‹…â‹…â‹…
Yn​= the largest of X1​,X2​,⋯,Xn​
We set Ymin​=Y1​ and Ymax​=Yn​. The order statistic Yi​ is called the ith order statistic. Since we are working with a continuous distribution, we assume that the probability of two sample items being equal is zero. Thus we can assume that Y1​<Y2​<⋯<Yn​. That is, the probability of a tie is zero among the order statistics.
The Distribution Functions of the Order Statistics
The distribution function of Yi​ is an upper tail of a binomial distribution. If the event Yi​≤y occurs, then there are at least i many Xj​ in the sample that are less than or equal to y. Consider the event that X≤y as a success and F(y)=P[X≤y] as the probability of success. Then the drawing of each sample item becomes a Bernoulli trial (a success or a failure). We are interested in the probability of having at least i many successes. Thus the following is the distribution function of Yi​:
FYi​​(y)=P[Yi​≤y]=k=i∑n​(kn​)F(y)k[1−F(y)]n−k
The Probability Density Functions of the Order Statistics
The probability density function of Yi​ is given by:
fYi​​(y)=(i−1)!(n−i)!n!​F(y)i−1[1−F(y)]n−ifX​(y)
The details of the derivation can be found here - Order Statistics.
When Xi​∼U[0,1], we have F(y)=y and fX​(y)=1, therefore
FYi​​(y)=P[Yi​≤y]=k=i∑n​(kn​)yk(1−y)n−k
fYi​​(y)=(i−1)!(n−i)!n!​yi−1(1−y)n−i
E[Yi​]​=∫01​fYi​​(y)ydy=∫01​i(in​)yi(1−y)n−idy=n+1i​​
Solution
Let LY1​,LY2​ and LYn​ be the n places where the ruler has been sliced where L is the length of the ruler in inches, Xi​∼U[0,1] and Yi​ are the order statistics of the Uniform distribution.
When the mark m lies between LYk​ and LYk+1​, we have
P[Yk​≤a≤Yk+1​]​=1−(P[Yk+1​≤a]+P[Yk​≥a])=1−(FYk+1​​(a)+1−FYk​​(a))=FYk​​(a)−FYk+1​​(a)=(kn​)ak(1−a)n−k​
E[LYk+1​−LYk​∣Yk​≤a≤Yk+1​]=k+1m​+n−k+1L−m​
where a=Lm​.
The average length of the piece which has the m inch mark is given by
(1−FY1​​(a))(m+n+1L−m​)+(FY1​​(a)−FY2​​(a))(2m​+nL−m​)+⋯+FYn​​(a)(n+1m​+L−m)=(1−a)n(m+n+1L−m​)+(1n​)a(1−a)n−1(2m​+nL−m​)+⋯+an(n+1m​+L−m)=m∫01​(ax+1−a)ndx+(L−m)∫01​(a+(1−a)x)ndx=a(n+1)m​−a(n+1)m(1−a)n+1​+a(n+1)m​−(1−a)(n+1)(L−m)an+1​=n+1L​(2−(1−a)n+1−an+1)​
In the given problem, L=12, m=6, n=3 and a=126​=21​ , therefore the average length of the piece we are interested in is given by
3+112​(2−23+11​−23+11​)=6−83​=5.625
Computational solution in Python
from random import uniform
l = 0
u = 12
m = 6
n = 4
runs = 500000
tl = 0
for _ in range(runs):
endpoints = [l] + sorted([uniform(l, u) for _ in range(n-1)]) + [u]
for i, ep in enumerate(endpoints[:-1]):
if ep < m < endpoints[i+1]:
tl += (endpoints[i+1] - ep)
print("Avg length of the piece that contains the mark:", tl/runs)