How it was found

A machine that knew one theorem

In 1940 a machine of relays played Nim against the public at the New York World's Fair, on four rows of up to seven lamps, and is reported to have won about nine games in ten. Everything it knew was Bouton's theorem, which is three column parities and one test per row. The record is the interesting number, and it is a measurement of the visitors rather than of the machine: against a visitor choosing at random the machine wins 98.5 per cent, and nine in ten is what a visitor earns by playing perfectly once seven lamps or fewer are lit. On the board the game is usually set up on, a visitor handed the first move cannot win at all.

Assumes: Nim, and the nim-sum · Start at the end and work backwards

One of the first machines built to play a game against the public played Nim. It was built at Westinghouse by Edward Condon with two engineers, Gerald Tawney and Willard Derr, patented in 1940, and shown that year at the New York World’s Fair, where visitors sat down in front of four rows of lamps and took turns with it putting lamps out. Its builders reported that it played around a hundred thousand games there and won about nine in ten. It is remembered as a curiosity, a large cabinet of relays doing arithmetic in public eight years before anybody ran a program on a stored-program computer.

It is also a complete object, which almost nothing else in the history of this subject is. Four rows of up to seven lamps is 4,096 positions, and every one of them can be looked at. So the machine’s knowledge, its record and the decisions its builders had to make without any theorem to help them can all be measured rather than described, and the measurements say something the anecdote does not: the famous number is a fact about the people who sat down to play.

Four rows of lamps and three winning cuts. A Nim board of four rows of up to seven lamps, lit 7, 5, 3 and 2, with each row's binary beside it. The columns add without carrying to 011, a nim-sum of 3; the three rows carrying the middle bit each have a winning cut, to 4, to 0 and to 1, and the lamps each cut would put out are shaded.
Fig. 1 Four rows lit 7, 5, 3 and 2, with each row’s size in binary. The columns added without carrying give 011, a nim-sum of 3. The three rows that carry its top bit each have a cut that leaves nought — row 1 down to 4, row 3 to nothing, row 4 to 1 — and the lamps each cut would put out are drawn in the second shade.

Everything it knew was Bouton

The game is ordinary Nim. On a turn a player chooses one row and puts out any number of its lamps, from one to all of them, and the player who puts out the last lamp wins — which is the normal-play convention, the one under which the player unable to move loses. Four rows of up to seven lamps is the board every account of the machine describes.

Bouton’s theorem of 1901 settles every position of that game, and the picture his proof leaves behind is the one drawn above: columns of bits, each of which has to cancel. Write each row’s size in binary and add the columns without carrying — the nim-sum. A position is lost for the player about to move exactly when the nim-sum is nought. From any other position there is a move to one where it is nought: find the highest bit set in the sum, pick a row with that bit set, and cut it to its own size exclusive-or the sum, which is smaller because the top bit goes.

That is the whole of what the machine had to know, and the figure above is the whole of what it had to do. For rows of 7, 5, 3 and 2 the columns read 111, 101, 011 and 010; the fours column holds two ones and cancels, the twos column holds three and the units column three, so the sum is 011. The top bit of that sum is the twos, three rows carry it, and each of the three can be cut to a size that makes every column even. Any of the three wins. The machine needed only one — and since every impartial game is a Nim heap, the same one-line decision would have played any impartial game whose rows could be valued. The choice among them turns out not to matter to anything measured here — the visitor’s behaviour depends on the position in front of the visitor, not on how it was reached.

The machine's decision, switch by switch. The decision for rows of 7, 5, 3 and 2 lamps: the parity of each binary column, reading 4s, 2s and 1s (even, odd, odd, giving 011), then for each row whether it carries the top bit of the sum and, if so, the cut that leaves nought — row 1 to 4, row 3 to 0, row 4 to 1.
Fig. 2 The same decision written as a switching circuit has to make it. First the three column parities, each a matter of whether an odd number of four switches is closed; together they are the nim-sum. Then one test per row, whether the row carries the sum’s top bit, and for each that does, the cut that leaves nought. Nothing else is read — not the history of the game, not the number of lamps lit.

The shape of that computation is what made the machine possible in 1940. It is not a search. There is no look-ahead, no table of positions and no memory of how the board came to be as it is — which is the sense of what a strategy has to remember at its smallest: nothing at all, where some games need one bit of memory and most need far more. Every decision is a fixed function of the twelve bits on the board, computed in the same way whatever they are, and a fixed function of a dozen bits is exactly what a cabinet of relays can compute. A game that needed search would have needed a machine that did not yet exist.

That is the first connection worth drawing, because it runs against the usual story. The machine is often described as a precursor of game-playing programs, and in one sense it is. In the sense that matters it is their opposite. Every program that has played a game well since has done it by searching a tree, pruning it and evaluating what is left, and the cost of that search is the whole engineering problem. The first machine to play well did it by knowing a theorem that made the tree irrelevant, which very few games have ever allowed: Nim is almost alone among games people actually play in having a winning rule that is a fixed function of the board.

One position in eight is lost

The first thing a complete object allows is a count of what the machine is up against.

One position in eight is lost. Of the 4,096 ordered positions of four rows of up to seven lamps, 512 are lost for the player to move, and the share lost is drawn for each total number of lamps lit from 0 to 28. Every loss has an even total; at odd totals the share is nought.
Fig. 3 All 4,096 ordered positions of four rows of up to seven lamps, and for each total number of lamps lit, the share lost for the player to move. Exactly 512 are lost, one in eight. Every one has an even total, because the units column has to cancel, and at every odd total nothing is lost at all. Read as unordered positions, 50 of 330 are lost.

The count of 512 needs no search. Choose the first three rows freely — eight sizes each, 512 ways — and the nim-sum of the four rows is nought for exactly one size of the fourth, the exclusive-or of the other three. That size is always a legal row, because the exclusive-or of numbers below eight is below eight. So every choice of three rows extends to exactly one loss, and there are 8 × 8 × 8 of them: one position in eight, on the nose. The census confirms the count and adds the pattern the argument predicts, that no loss has an odd number of lamps lit. A board with an odd total always has a winning move, and whoever sits down to one with the move is ahead.

The unordered count is the figure a visitor would recognise, because a visitor describes a board as “a one, a three, a five and a seven” rather than as an ordered list. There the share is a little higher, 50 of 330 or about fifteen per cent, because a lost position often repeats a row — two equal rows cancel, and a position with a repeated row has fewer orderings to be counted among the 4,096. Either way the arithmetic says the same thing: a board chosen at random is almost always a win for whoever moves first, and the machine’s record cannot be explained by its being handed lost boards to play from.

What a random move is worth

It can be explained by the opposite: winning positions are extremely easy to throw away.

A random move wins one time in seven. For each of the 3584 winning positions of four rows of up to seven lamps, the share of legal moves that keep the win, in tenths. Most positions sit below one in five; the mean is 14.6%.
Fig. 4 The 3,584 winning positions, by the share of their legal moves that keep the win. Every one has either one winning move or three — 1,792 of each — while the legal moves number from one to twenty-seven. The mean share is 14.6 per cent and the median exactly one in seven. The worst is 6 · 6 · 6 · 7, with one winning move among twenty-five.

Two facts combine here. The number of winning moves is tiny and fixed: it is the number of rows carrying the nim-sum’s top bit, which is odd, and with four rows it is one or three — in this board, exactly half the winning positions each. The number of legal moves is large and grows with the board: it is simply the number of lamps lit, since a move is a choice of row and a number of lamps to leave, and every lamp position is one choice. On a board with twenty lamps lit, a visitor facing a winning position has one or three good moves among twenty.

So a visitor who moves at random — which is roughly what a visitor who does not know the theorem does in the middle of a game, when the board is too big to think through — keeps a winning position won about one time in seven. After one such slip the machine is winning, and it never slips back, because from a lost position every move leads to a winning one and the machine always has the winning reply. Nim is a game in which one mistake by the visitor is decisive and no number of mistakes by the machine is possible. The record is built from that asymmetry, and it only needs the visitor to make the mistake once in a long game. Working backwards from the empty board makes the same point in the language of the recursion: every position on the losing side has only winning positions below it, so the machine’s side of the table is a set the visitor can fall into and never climb out of.

The record is a measurement of the visitors

That turns the reported nine in ten into a question with an answer. What would a visitor have to know for the machine to win only nine games in ten?

The model here is the simplest one that describes how people actually play small games: a visitor who plays perfectly once the board is small enough to think through, and does not before. Precisely, the visitor sees k lamps ahead — plays a winning move whenever one exists and at most k lamps are lit, and otherwise chooses among the legal moves with equal chance. With k at nought the visitor is guessing throughout; with k at twenty-eight the visitor is Bouton. The machine plays the winning move whenever there is one, and from a lost position takes one lamp from its longest row, for reasons the next section measures. Every probability is exact: for each start, the chance the machine wins is computed backwards from the empty board through all 4,096 positions, with no sampling.

Nine in ten is about seven lamps. The machine's winning share over every start, the visitor moving first, against a visitor who plays perfectly once at most k lamps are lit and at random before, for k from 0 to 28. It falls from 98.5% to one in eight and crosses nine in ten between k = 7 and k = 8.
Fig. 5 The machine’s winning share over all 4,095 non-empty starts, the visitor moving first, against a visitor who plays perfectly once at most k lamps are lit and at random before. Guessing throughout, the visitor loses 98.5 per cent of games. The line of nine in ten is crossed between k = 7, at 90.4 per cent, and k = 8, at 87.4. Seeing the whole board, the visitor loses only the starts already lost, one in eight.

The curve is flat for the first few lamps, because an endgame of four or five lamps is short and a guessing visitor has usually lost well before it is reached. It then falls steeply through the middle — each extra lamp of foresight adds a whole class of positions where the visitor stops throwing wins away — and levels out at one in eight, which is the share of starts that are lost for the visitor however well the visitor plays.

Nine in ten is the curve at seven lamps. A crowd whose members could, on average, play out a board of seven lamps or so without error and guessed before that would have produced exactly the record the machine’s builders reported. That is a plausible description of people meeting a game for the first time: the last few moves of Nim are easy to see — two equal rows cancel, a lone row should be taken whole — and the middle game is not.

A second visitor makes the same point from a different direction. Suppose a visitor knows one rule and only one, the rule most people discover within a few games: with two rows left, make them equal. That visitor plays perfectly whenever at most two rows are lit and guesses otherwise. Against that visitor the machine wins 91.1 per cent — nine in ten again. Two quite different models of what visitors knew give the reported record, and the models agree about what it means: the visitors could play the end of the game and not the middle, and the machine’s nine in ten measures the width of that middle.

A rule for losing, which the theorem does not give

The model above made the machine take one lamp from its longest row whenever it faced a lost position. That rule is not in Bouton’s paper, and the paper cannot supply it. The theorem says a lost position has no winning move — every move leaves a nim-sum that is not nought — and against a perfect opponent that is the end of the matter. Against a visitor it is not, because the visitor may slip, and different losing moves give the visitor different chances to.

The rule for a lost position. Four rules for the machine's move from a lost position, and the best rule found by search, scored by the machine's winning share against four visitors. Taking one lamp from the longest row is within a tenth of a point of the best; clearing the longest row costs about three points.
Fig. 6 Five rules for the machine’s move from a lost position, scored by its winning share against four visitors: at random throughout, perfect from six lamps, perfect from ten, and knowing only the two-row rule. The last row is the best rule possible against each visitor separately, found by search. Taking one lamp from the longest row comes within a tenth of a point of it everywhere; clearing the longest row is the worst of the four wired rules, by up to six points.

The spread is small at the extremes and real in the middle. Against a visitor who guesses throughout, the machine wins whatever it does, since the visitor will slip long before the losing position matters. Against a visitor who sees ten lamps ahead the rules differ by six points, from 77.1 per cent down to 71.2.

The best rule is the one that keeps the game long. Taking a single lamp from the longest row leaves the visitor a board almost as large as before, with as many legal moves to choose among and as few winning ones, and so as many chances to go wrong before the board shrinks to the size the visitor can see through. Clearing the longest row does the reverse: it brings the board down to a visitor’s horizon in a single move and hands over a position the visitor can play perfectly. Taking one lamp from the shortest row is nearly as good against the horizon visitors and noticeably worse against the two-row visitor, 88.4 per cent against 91.1, because shortening a short row is the fastest way to reach a board with two rows left.

The comparison that matters is with the last row. The best possible rule against each visitor was found by searching every legal move from every lost position and keeping the one with the highest chance of the visitor slipping later. It beats “take one from the longest” by less than a tenth of a percentage point against every visitor. The one decision the builders had to make without a theorem is very nearly the optimal one, and the simple reason — keep the board big, because the board’s size is the visitor’s enemy — is all the optimisation there is to do.

That is the site’s second connection, and it links the machine to a question this subject almost never asks. The theory of games is about positions with a known value, and it has nothing to say about how to lose. A program playing people spends a real share of its time in lost positions and has to choose among moves that the theory values identically — the same problem a potential that names every move runs into from the other side, where a rule is needed exactly where the theory declines to rank the options. The machine’s builders met it in 1940 and solved it by the obvious heuristic, and the heuristic is right.

The board the game is set up on

One board is special because it is the one Nim is usually set up on: rows of one, three, five and seven. Its nim-sum is 1 ⊕ 3 ⊕ 5 ⊕ 7, which is nought.

The usual start is lost for the mover. Six starting positions with their lamp count, nim-sum, verdict for the player to move and winning moves among legal ones, and, for each order of play, the fewest lamps from which a visitor must play perfectly to take one game in ten from the machine. A visitor moving first on a lost board never wins; with the machine moving first on 1-3-5-7 the visitor needs thirteen lamps.
Fig. 7 Six starting boards with the fewest lamps from which a visitor must play perfectly to take one game in ten from the machine, for each order of play. A visitor moving first on a lost board cannot win at all. Handed the move on 1 · 3 · 5 · 7, the machine is losing — and still the visitor must play perfectly from thirteen of the sixteen lamps to win one game in ten. On 1 · 2 · 3 · 4 a visitor with the move needs to see only five.

So the usual board is lost for whoever moves first. A visitor who was offered 1 · 3 · 5 · 7 and the first move could not have beaten the machine at all, because the machine always has the reply that keeps the nim-sum at nought, and nobody at the fair could have noticed the trick unless they already knew the theorem.

Turn the order round and the machine is the one in a lost position — and it hardly matters. From 1 · 3 · 5 · 7 with the machine to move, a visitor seeing six lamps ahead loses 99.98 per cent of games, and must see thirteen of the sixteen lamps before taking even one game in ten. The full board of four sevens is lost for the mover too, and there the visitor needs twenty-five lamps of twenty-eight. The asymmetry of the previous section is at its sharpest on these boards: they are lost for the mover, but lost only to perfect play, and the machine needs the visitor to be imperfect once.

This bears on the record in a way the historical accounts leave open. They do not say, anywhere this essay can check, which boards visitors were given or who moved first. If every game had started from 1 · 3 · 5 · 7 with the visitor moving, the machine would have won every game, not nine in ten. If every game had started there with the machine moving, a nine-in-ten record would imply visitors who could play perfectly from thirteen lamps, which is not a plausible description of a crowd at a fair. The reported record is consistent with neither, and is consistent with boards varied enough that many of them were winnable for the visitor and visitors who could see the last half-dozen lamps. The arithmetic cannot say what the setup was, but it can say which setups the record rules out.

The conventions the numbers depend on

Every figure above assumes the normal-play ending — the player who puts out the last lamp wins — which is the game Bouton solved and the one the machine is described as playing. Under the opposite ending, misère play, the losses differ on every board whose rows are all nought or one, and every percentage here would move. The board is four rows of up to seven lamps and positions are counted as ordered lists, one per assignment of lamps to rows, except where the unordered count is stated.

The visitor models are models. A visitor who plays perfectly below a threshold and uniformly at random above it is the simplest description of learning a game, and the two-row visitor is the simplest description of a rule people are known to find; neither is a claim about the visitors of 1940, of whom nothing is recorded here. The winning shares average over every non-empty start with equal weight, because the starts actually used are unknown. The machine’s winning move is always the one in the lowest-numbered row carrying the top bit; since the visitor’s behaviour depends only on the position the visitor faces, any other choice among winning moves gives the same shares.

What the arithmetic cannot recover

The figures settle what the machine could do, what a random visitor faced and what kinds of visitor are consistent with the record. They do not settle what happened at the fair. The reported count of games and the reported share won are the builders’ own figures, and nothing here tests them; the setup — which boards, who moved first, whether visitors could choose — is not in any source this essay relies on. The internal circuit is drawn as the logic a relay machine has to implement, not as a reconstruction of the machine’s wiring, which the essay does not attempt.

What the arithmetic does recover is the direction of explanation. The number usually quoted as evidence of the machine’s skill cannot be evidence of that, because the machine’s skill is total and fixed — it plays Bouton’s theorem, and Bouton’s theorem cannot be played better. Whatever the record measures, it measures on the other side of the table.

Still open: the machine that did not know the theorem

Nim was the right game for 1940 precisely because it needed no search, and that is also why the machine taught its builders nothing about playing games in general. The next machines to play in public did play games without a theorem. The most instructive of them played Hex, a game in which the first player is known to win and nobody can say how, and it chose its moves by measuring an electrical network wired in the shape of the board. A theorem that names no move is what such a machine was up against, and the question it poses is the same one this essay asked of the Nim machine turned inside out: when a machine plays by a rule that is not a theorem, how often is the rule right, and where does it go wrong?

Part 1 of 2

One argument about Machines. The parts either side of it:

The objects named here

The third axis, after the field and the series: the games, values and theorems themselves, and every essay that touches each one.

BinaryBoutonExhaustive searchMove selectionNimNim-sumP-positionParityStrategyXOR