Magic coin

From the Riddler, the growing certainty of magic.

Problem

I have a coin with a sun on the front and a moon on the back. I claim that on most days, it’s a fair coin, with a 50 percent chance of landing on either the sun or the moon.

But once a year, on the summer solstice, the coin absorbs the sun’s rays and exhibits a strange power: It always comes up the opposite side as the previous flip.

Of course, you are skeptical of my claim. You figure there’s a 1 percent chance that the coin is magical and a 99 percent chance that it’s just an ordinary fair coin. You then ask me to “prove” the coin is magical by flipping it some number of times.

How many successfully alternating coin flips will it take for you to think there’s a 99 percent chance the coin is magical (or, more likely, that I’ve rigged it in some way so it always alternates)?

Bayes Rule, Priors and posteriors

We can update our probability of the coin being magic – beginning with our prior of only a 1% probability – by leveraging Bayes’ Rule. This gives us an easy way to see the probabilities increasing with each flip.

$$ \[\begin{aligned} P(M \mid X = n) & = \frac{P(X = n \mid M) \cdot P(M)}{P(X = n)} \\ \\ & = \frac{1 \cdot p_0}{1 \cdot p_0 + (\frac{1}{2})^n \cdot (1 - p_0)} \\ \end{aligned}\]

$$

Odds, Bayes factor

We can also articulate the relationship using odds. Here, the relationship is clearer — with each successful flip, the odds double for the coin being magic.

The formulation to update odds incorporating the Bayes Factor is pretty easy to re-derive when needed, so here it is.

\[ \begin{aligned} O(M | X) & = \frac{P(M \mid X)}{P(M^c \mid X)} \\ & = \frac{P(X \mid M)\cdot P(M)}{P(X \mid M^c) \cdot P(M^c)} \\ & = \frac{P(X \mid M)}{P(X \mid M^c)} \cdot \frac{P(M)}{P(M^c)} \\ & = \frac{P(X \mid M)}{P(X \mid M^c)} \cdot O(M) \\ \end{aligned} \] The Bayes Factor (\(BF\)) captures the ratio of the likelihood of the observations given the competing hypothesis – that the coin is magic or not magic. If the coin is magic, the observations are guaranteed. But the likelihood of the fair coin decreases with each consecutive flip.

\[ \begin{aligned} BF & = \frac{P(X \mid M)}{P(X \mid M^c)} \\ o_{t+1} & = BF \cdot o_t \\ \\ BF & = \frac{1}{(\frac{1}{2})} = 2 \\ o_n & = 2^n \cdot o_0 \end{aligned} \]

Analytic solution

And if we choose, we can solve directly for the \(n\) value which gives us a probability that exceeds our threshold, \(p_t = 0.99\).

\[ \begin{aligned} n \log{2} & \le \log{o_t} - \log{o_0} \\ n & \ge \log_2{o_t} - \log_2{o_0} \\ n & \ge \log_2{\left(\frac{.99}{.01}\right)} - \log_2{\left(\frac{.01}{.99}\right)} \\ n & \ge 13.26 \\ \end{aligned} \] Here, we see that the number of consecutive flips needs to be at least 14. Why does it take us so long to reach that conclusion if the odds are doubling with each alternating flip? We’ve chosen a very conservative Muggle prior – that it is beyond a shadow of doubt that there is no magic. And we’re demanding a similar standard of proof to convince us otherwise.