A machine outputs random real numbers between and , until their sum exceeds . How many numbers will it need to generate, on average?
Here's a little trick that's often useful: when a random variable takes on positive integer values, its expectation is
- The probability that it is at least 1, plus
- The probability that it is at least 2, plus
- The probability that it is at least 3, plus
- …and so on.
The reason is simple: the probability that it is exactly 7 shows up 7 times in this infinite sum. So overall, this is just the sum of k times the probability of k, which is the expectation.
Why is that useful? You see, when you’re working with a random variable such as “number of times until the sum exceeds 1”, or more generally a “stopping time” or “first success” kind of thing, the probability that it is exactly 7 is a little annoying to calculate: it’s the probability that you didn’t succeed in steps 1 through 6, but then did succeed in step 7. Instead, the probability that it is at least 7 is nothing more nor less than the probability that the first 6 steps failed. This is almost always a simpler expression.
In our case, the chances that you need at least k+1 numbers for the sum to exceed 1 is just the probability that the first k numbers chosen add up to less than 1. This is a simple volume calculation:
- The length of the segment 0\leq x\leq 1 is 1.
- The area of the triangle x+y\leq 1, with x,y\geq 0, is 1/2.
- The volume of the pyramid x+y+z\leq 1, with x,y,z\geq 0, is 1/6.
- …and so on. The volume of the polyhedron x_1+\ldots x_k\leq 1 when x_1,\ldots x_k\geq 0 is 1/k!.
Therefore, the expectation we are looking for is simply the sum of 1/k! over all k (including k=0), which is simply e.