## A reply to “Of Monkeys and Typewriters”

This again is a guest post by Dan who has been very productive the last week.

We’ve all heard that if you had an infinite number of monkeys plugging away on an infinite number of typewriters for an infinite amount of time then eventually those monkeys would produce all the works of Shakespeare. In his “paper” Mathis sets his sights on disproving this statement, and fails miserably. This is fundamentally a problem of statistics, yet nowhere does Mathis ever use a single statistical argument.

Mathis asserts that since it is possible for a monkey to type an infinite string of “S”’s, that there is a non-zero probability that this monkey will not produce a work of Shakespeare. It is true that there is the possibility that no work of Shakespeare will be produced, but there is a greater probability one will be produced. Mathis seems to quibble over the statement of the monkey theorem given in layman’s terms, had he taken the time to see the precise formal statement of the theory he would realize his argument is flawed. There are a few ways this theorem can be stated, I will use a formulation that does not appeal to the notion of infinite monkeys. To make this formulation precise a few simplifying assumptions are made that in no way change the problem and the process is clearly defined.

The Experiment

Instead of all Shakespeare’s works, let us consider only Macbeth. Let us assume that to reproduce Macbeth it would require n keystrokes. On the given typewriter being used let us assume there are m keys. I stress not knowing the exact numbers in no way changes the results being presented.

The experiment will be conducted as follows. One monkey will randomly press one key at a time on the typewriter. Once the monkey has made n keystrokes we will examine the document produced. If the document matches the Macbeth, then we will call it a success. If it is not a success then the monkey will be given another try. The experiment is complete once the monkey produces a success.

Statistical Analysis & Predictions

We are interested in predicting how many tries the monkey will need until he reproduces Macbeth. Let P(S) be the probability the monkey succeeds on a given try. In order to produce Macbeth the monkey must press n characters in the perfect order. Since there are m possible keys and only one of them is right for the jth character, the probability the monkey presses the right key for the jth character is (1/m). Since he has to press n keys in total and by assumption the keystrokes are statistically independent, the probability of success is given by:

$P(S) = \left(\frac{1}{m} \right)^{n}$

Let X be the random variable that represents the number of trials before the monkey succeeds. Let P(X = k) be the probability that the monkey fails the first (k -1) tries and succeeds on the kth try. The probability of failure on a given try is 1 minus probability of success. Since each try is statistically independent we multiply the probabilities of the individual events to find the probability of the compound event. Thus we have the following:

$P(X=k) = [1-P(S)]^{k-1} \cdot P(S)$

$P(X=k) = \left[1- \left(\frac{1}{m}\right)^n \right]^{k-1} \cdot \left(\frac{1}{m} \right)^n$

This is an example of what is known as a geometric random variable. What we are interested in is the expected value of X. If you are unfamiliar with the language of statistics, the expected value of X means if we were to repeat the experiment over and over, how many trials it takes for the monkey to succeed on average.

Expected Value of a Discrete Random Variable:

If X is a discrete random variable with probability function P(X), then the expected value of X is given by:

$E[X]=\sum\limits_{\Omega} X(\omega)\cdot P(\omega)$

Fortunately since X is a geometric random variable there is a simple formula that gives the expected value of X.

Expected Value of a Geometric Random Variable:

If X is a geometric random variable with probability P(S) of success on any given trial then the expected value of X is given by:

$\sum\limits_{k} k \cdot P(X=k) = \lim\limits_{N\rightarrow \infty} \sum\limits_{k=1}^{N} k\cdot P(X=k) = \frac{1}{P(S)}$

Now in our case we know P(S) and upon substituting the known value we have:

$E[X]=\frac{1}{P(S)}=m^n$

Now mn is an admittedly vary large number in this situation, but it is a finite number. This means that if we were to repeat this experiment over and over then on average the monkey would need mn tries before he successfully typed Macbeth. Note that if we assume that Macbeth has 100 000 characters and a typewriter has 50 keys, this gives us 50100 000 tries on average. Now this is staggeringly large number and shows that this is not a practical undertaking, but practical or not the result is valid.

A Second Analysis

Above we calculated the probability of a success on a given try to be P(S). Now instead of calculating the expected number of tries before success, we can look at it a different way and ask what is the probability the monkey eventually succeeds?

What exactly does it mean for the monkey to eventually succeed? I know this sounds like a pedantic question, but it is useful to properly formulating the problem. This means that on some attempt, say the jth one he finally reproduces Macbeth, but fail on all previous attempts. So to find the probability that he eventually succeeds we need to add the probabilities of success on each try. We need to add the probability he succeeds on the first try, the second try, the third try, and so on. To succeed on the jth try means on the first (j-1) tries he fails then finally gets it right on the jth try. Since each attempt is assumed statistically independent, we simply multiply the probability of failing (j-1) times by the probability of succeeding once on the jth try.

$P(\text{Success on}\, j^{\text{th}} \, \text{trial})= [1-P(S)]^{j-1} \cdot P(S)$

So now we add these probabilities up.

P(eventual success) = P(success on 1st) + P(success on 2nd) + P(success on 3rd)…

$P(\text{eventual success}) = \lim\limits_{N\rightarrow \infty} \sum\limits_{j=1}^{N}P(\text{Success on}\, j^{\text{th}} \, \text{trial}) = \lim\limits_{N\rightarrow \infty} \sum\limits_{j=1}^{N} [1-P(S)]^{j-1}\cdot P(S)$

This is a geometric series with first term P(S) and ratio [1 – P(S)]. Since the common ratio [1 – P(S)] is less than one, we can apply a simple formula to calculate this sum.

Sum of Geometric Series:

$\lim\limits_{N\rightarrow \infty} \sum\limits_{j=1}^{N} a\cdot r^{j-1} = \frac{a}{1-r}$

We now apply this formula to our series:

$\lim\limits_{N\rightarrow \infty} \sum\limits_{j=1}^{N} [1-P(S)]^{j-1}\cdot P(S) = \frac{P(S)}{1-(1-P(S))}=1$

This tells us that that as we give the monkey more and more tries, as the number of tries grows without bound; the probability of a success goes to 1. In the language of statistics this means the success occurs with probability 1, or the event occurs almost surely. Simply put, given enough tries the monkey will almost surely reproduce Macbeth.

Mathis has accomplished a few things with this “paper”. First he has provided a great example illustrating the need for theorems to be stated in precise mathematical language. Everyday language is far too cumbersome to properly attack a problem, the advantages of equations are clear. When a mathematical problem is formulated in everyday language there is the possibility of it being interpreted incorrectly, as Mathis did when he confused the word must with the notion with probability 1. Subtle as the difference is, it completely changes the analysis and final conclusion. Equations give us concrete representation with very precise meaning, a clear way to model the problem and move forward solving it. Second he has showed that no amount of folksy wisdom or “common sense” can ever be a suitable replacement for true mathematical or statistical analysis of a problem. There is a very good reason why mathematical statements are made precise; among other things it helps minimize possibility of what you think should be true interfering with what really is true.

Mathis has clearly demonstrated his lack of understanding of the most basic concepts of probability. I once again suggest he spend the money and buy a decent introductory statistics text, An Introduction to Mathematical Statistics and Its Applications (3rd Edition) by Larson and Marx might do. It is obvious that Mathis has a deep interest in mathematics and physics, so what I don’t understand is why he refuses to learn any of it properly.

This entry was posted in mathematics. Bookmark the permalink.

### 8 Responses to A reply to “Of Monkeys and Typewriters”

1. BenYitzhak says:

This works fine if we allow a monkey to truly random output, but is that really the case? Once you start involving life, things get weird. If you put a human down at the keyboard, the chances of any random output seem decidedly low. I think the layout of the keyboard and the shape of the monkey’s hand would both have an impact on the distribution of the letters in the typing.

Change the nature of the type-writer. The monkey is given one button, whenever it hits the button, it is rewarded somehow. When the button is hit, a random letter generator is activated, and a letter is selected. This is output on a continuous feed and the monkey does not get to see it (probably not necessary, but given an infinite amount of time, the monkey might be able to figure out how to game the random letter generator.)

2. Dan says:

I made the assumption of truly random behavior of the monkey because I believe that was the spirit of the original statement. You are probably right that a monkeys behavior is random, but that would change the analysis so so little. The expected trials until sucess would change, but the part of the analysis summation of the geometric series would be unchanged. Unless there is some reason the monkey could never suceed in any given trial, then he has non zero probability of success, and it will happen in finite time with probability 1.

The real point wasn’t to undertake any deep analysis of monkey-typewriter dynamics. The point was to demonstrate that Mathis and his bastardized statistical handwaving crumble under even little scrutiny.

You don’t sound crazy enough to buy the crap he writes, but have you ever read any of it? Have you read the “paper” this is in response to? If you thought my subtle simplifying assumption was innacurate, then you should read his line of reasoning, if it can even be called reasoning.

Just think how much fun would it be to study monkey-typewriter dynamics! Monkeys are awesome!

All typos can be blamed on the small iPhone keypad.

3. D says:

That should read: … you are probably right that a monkeys behaviour IS NOT random…

4. BenYitzhak says:

Oh, no, he’s really bad at math. I read his comments on the Hilbert Hotel and… no. He is utterly unconvincing.

5. Hoz Turner says:

Any person who thinks that a monkey could produce Macbeth (if given enough time) is profoundly stupid. Seriously. This is mathematical hypothetical claptrap at its worst.

• Dan says:

Actually the arguments and ideas come from statistics, not mathematics. Perhaps if you understood the material you would know that while very unlikely, it is entirely possible for a monkey to produce Macbeth.

Perhaps you could enlighten us all and explain why it could not happen. Or better yet find a flaw in the above proof.

It seems to that the only people who are profoundly stupid are those that make uninformed incorrect pronouncements while at the same time trying to insult others.

• David says:

I agree completely with the mathematics of your analysis. However, if the monkey were as confused and misinformed as Mathis, then it is highly unlikely that it would ever produce anything intelligible. Mathis, who is also a primate, has typed keystroke after keystroke, thousands of pages, and has yet to dispatch a coherent thought; only unintelligible nonsense and gibberish. But in all fairness to the monkey, merely typing keystrokes at random would give the hairy beast a distinct advantage over Mathis.

6. Bart says:

“Any person who thinks that a monkey could produce Macbeth (if given enough time) is profoundly stupid”

Definitely. A real monkey would type write anything he pleases over and over, and that won´t be anything meaningful. No matter how many monkeys or how many repetitions or how many languages.

To the problem, I rather the example of “infinite” perfect dice thrown “infinite” times. Would we achieve some “a trillion consecutive times 6” serie, or a trillion times the “123456543212345654321…” serie?