Processing math: 100%

Neal Grantham

neal@nsgrantham.com

The Sum Over 1 Problem

I recently came across this fun probability problem which I’ve dubbed the ‘Sum Over 1’ problem.

It goes like this:

On average, how many random draws from the interval [0, 1] are necessary to ensure that their sum exceeds 1?

To answer this question we’ll use some probability theory (probability rules, distribution functions, expected value) and a dash of calculus (integration).

Let’s Begin!

Let Ui follow a Uniform distribution over the interval [0,1], where i=1,2, denotes the ith draw.

Let N denote the number of draws such that Ni=1Ui>1 and N1i=1Ui1. Thus, N is a discrete random variable taking values n=2,3, (n=1 is impossible because no single draw from [0,1] can exceed 1).

We seek the long-run average, or expected value, of N denoted E(N). A good first step for a numerical problem like this is to utilize computer simulations to point us in the right direction.

Simulations with R

Let’s generate, say, 20 random draws from [0,1], (u1,,u20).

draws <- runif(20)  # vector of u_1, ..., u_20

Consider the partial sums of these draws (u1,u1+u2,3i=1ui,,20i=1ui).

If we index this partial sum vector from 1 up to 20, then n here is simply the index of the first component of this vector whose value exceeds 1.

The find_n function accomplishes this for any vector of random draws u:

find_n <- function(u) {
  which(cumsum(u) > 1)[1]  # which partial sum first exceeds 1?
}

n <- find_n(draws)
draws[1:n]
## [1] 0.2858056 0.1689087 0.6259122

In this instance, it took 3 random draws from [0,1] to sum over 1. We can sample from the probability distribution of N by repeating this process many more times. The sample_from_N function takes m samples from the distribution of N:

sample_from_N <- function(m) {
  # m-by-20 matrix of random [0,1] draws
  draws <- matrix(runif(m * 20), ncol = 20)
  # for each row of 20 draws, find n
  n.many <- apply(draws, 1, find_n)
  # estimate P(N = n), n = 2, 3, ..., 10
  # (truncated b/c probs are miniscule for n > 10)
  estimated.probs <- table(factor(n.many, levels = 2:10)) / m  
  return(estimated.probs)
}

m <- 1000
approx.N <- sample_from_N(m)  # approximate prob. dist'n of N
approx.N
## 
##     2     3     4     5     6     7     8     9    10 
## 0.514 0.330 0.121 0.026 0.005 0.004 0.000 0.000 0.000

So, we estimate P(N=2) by ˆP(N=2)=0.514, P(N=3) by ˆP(N=3)=0.33, and so forth.

These are just point estimates for P(N=n), but we can estimate their standard errors as well by running sample_from_N many more times. The approximate probability distribution of N is depicted below.

Probability that big N equals little n

The dotted line here marks the estimated expected value of N, ˆE(N)=n=2nˆP(N=n)2.71962. This value is tantalizingly close to the mathematical constant e2.7183 known as Euler’s number1.

Could the answer to our probability puzzle truly be e?

Proof

Let’s start small by finding the probability that N=2. The probability that it takes exactly 2 random draws from [0,1] for their sum to exceed 1 is simply the complement of the probability that the sum of our 2 draws fall short of exceeding 1. That is,

P(N=2)=P(U1+U2>1)=1P(U1+U21).

We can interpret the probability that U1+U21 geometrically. Since U1 and U2 are Uniform random variables on [0,1], the point (U1,U2) can arise anywhere in the unit square with equal probability. Thus, P(U1+U21) corresponds exactly to the proportion of the unit square shaded in the following image.

2-dimensional unit simplex

This shaded region is referred to as a 2-dimensional unit simplex2 with area

P(U1+U21)=101u20du1du2=10(1u2)du2=1/2

So P(N=2)=11/2=1/2, which agrees nicely with our simulation estimate ˆP(N=2)=0.514.

Now for the probability that N=3, it is tempting to proceed by finding the exact probability

P(N=3)=P(U1+U2+U3>1,U1+U21),

but dealing with both inequality constraints simultaneously is annoying. It is helpful to recognize that P(N=3)=P(N3)P(N=2) where

P(N3)=P(U1+U2+U3>1)=1P(U1+U2+U31).

Similar to the previous case, the probability that the sum of three random draws from [0,1], U1,U2, and U3, does not exceed 1 is given by the proportion of the unit cube shaded in the following image.

3-dimensional unit simplex

This shaded region is a 3-dimensional unit simplex with volume

P(U1+U2+U31)=101u301u3u20du1du2du3=1012[12u3+u23]du3=1/6.

So P(N=3)=P(N3)P(N=2)=(11/6)1/2=1/3 which again agrees with our simulation estimate of ˆP(N=3)=0.33.

Foregoing a formal proof, we can generalize our results on the unit simplex: the n-dimensional unit simplex has “volume” given by 1/n!. For our purposes, P(Nn)=11/n!. Thus, for any n2,

P(N=n)=P(Nn)P(Nn1)=[11n!][11(n1)!]=n1n!.

We’ve got everything we need to find the expected value of N.

E(N)=n=2nP(N=n)=n=2n(n1n!)=n=21(n2)!=n=01n!

Recall the exponential series is given by ex=n=0xnn!.

Thus, E(N) is equivalently e.

Yes that’s right: we expect, on average, e random draws from the interval [0,1] to ensure their sum exceeds 1!

  1. A convenient way to remember e: Take 0.3 from 3 (2.7) followed by the election year of former U.S. president (and horrible human being) Andrew Jackson twice in a row (1828). That is, e2.718281828. Okay, maybe it’s not that helpful, but you’re slightly more prepared for American presidential history trivia! 

  2. An n-dimensional unit simplex is the region of n-dimensional space for which x1+x2++xn1 and xi>0,i=1,2,,n. A unit simplex in one dimension (1D) is boring; it’s just the unit interval [0,1]. In 2D, the unit simplex takes the form of a triangle bounded by x1+x21,x1>0,x2>0. In 3D, we get a tetrahedron, in 4D a hypertetrahedron, and in n dimensions — well, an n-dimensional simplex. 

October 30, 2014  @nsgrantham