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)