## The Two Envelopes Problem

Recently I came across a Youtube video by „vsauce“ explaining the two envelope paradox. The problem is at least half a century old, and most likely a lot older. It can be found in a 1953 book by Maurice Kraitchik which is the oldest citation in Wikipedia.

*Someone places money into one of two identical envelopes and double the money into the second. We select one of the two envelopes without knowing if we have the first or the second one. We open it. Should we keep that money or return it and opt for the other envelope?*

(Let us assume that the value in the first envelope is a rational number. So we cannot conclude with certainty which envelope we have opened. If we selected from integer numbers we would know the envelope in the case of an even value.)

The naive analysis goes like this:

Let X be the amount we have. Since we have chosen the envelopes at random, the other envelope contains X/2 and 2X with the same probability. So our expectation after switching is

\(\dfrac{X/2+2X}{2} = \dfrac{5}{4} X\)

So switching sounds like a winning strategy. It gets more striking if we consider switching before even opening the envelope. Switching back and forth drives the expected value to infinity. This is clearly nonsense.

This paradox is a confirmation of my principle:

*To analyze a probabilistic problem we need an experiment that we could, at least hypothetically, implement in a computer. Equivalently, we need a probability space to work with. *

The two envelopes problem does not satisfy this principle. The reason is that it is impossible to select a rational number at random from the set of all rational numbers. You cannot even select an integer evenly from all the integers. We need a probability distribution for that. Think of how you would test the switching strategy on a computer. You will have to tell the machine how to select a number. It can select a number with equal probability from all the numbers it can represent. But it cannot do so from all, infinitely many numbers.

Now that we know that the original problem makes no sense, we can start to analyze the problem by assuming an a priori distribution for the value M in the first envelope. By doing so, we get a bunch of very interesting questions. (By the way, it is always easy to create questions in mathematics. Only a few questions have nice answers, however.)

Let us start by selecting M evenly from 1 to n. Clearly, we switch if the opened envelope, containing X, is odd. We will keep the money only if X>n. For n which is a multiple of 4, we have the following cases:

- M<=n/2: We will switch no matter if X=M or X=2M. Thus the average outcome is 3/2 M.
- M>n/2: We get 2M in every case.

It is an exercise to compute that our average result is

\(E = \dfrac{15n+14}{16}\)

This is a blog about Euler Math Toolbox too. So let us simulate the strategy in EMT. In this case, a loop would be a good idea, maybe written in C or Python. However, it is also possible to do this elegantly with the matrix language

>n=10; N=1000000; >M=intrandom(N,n); // select a number between 1 and n >sel=intrandom(N,2); // select 1 or 2 envelope >X1=M*sel; X2=M*(3-sel); // X1 is in the selected, X2 in the other >sum((X1>n)*X1+(X1<=n)*X2)/N // X1 for X1>n, X2 else 10.253055 >(15*n+14)/16 // expected outcome 10.25

We could also try a distribution on the positive real numbers for M. A typical candidate is the exponential distribution. We decide ourselves to keep a value greater than some a>0.

In this case, we switch for all M<a/2 and M>a, getting 3/2 M on average. In half of the cases between a/2 and a, we get 2 M. In the other half we still get 3/2 M. Thus

\(E = \dfrac{3}{2}+\dfrac{1}{2} \int\limits_{a/2}^a x e^{-x} \, dx\)

The best choice is a = 4 ln(2) with

\(E \sim 1.68\)

We can simulate that too.

>n=10; N=1000000; >M=randexponential(N); // select a number between 1 and n >sel=intrandom(N,2); // select 1 or 2 envelope >X1=M*sel; X2=M*(3-sel); // X1 is in the selected, X2 in the other >a=4*ln(2); sum((X1>a)*X1+(X1<=a)*X2)/N // X1 for X1>n, X2 else 1.68097393969

Note that switching all the time or never both expect E=3/2.

You might ask if there is a distribution for M which ensures that it does not matter to look inside the first envelope. But that is not the case. Such a distribution does not exist.m Knowing the distribution and looking at the first envelope will always yield an expected overhead for us.