How it was found

Before the theorem there was the mirror

Kayles was a puzzle long before it had a theory, and the classic answer is a symmetry: knock down the middle, leave two equal rows, copy every move. That answer is the fact that a game added to itself is a loss, and it was the only fact about sums anybody used between Bouton's paper and Sprague's. Measured on every Kayles position to twenty-four skittles, it sees 271 of 1,194 losses. Reading equal as equal in value raises that to 754, and the exclusive-or of 1901 does the rest. The theorem of 1935 is where the two older tools meet.

Assumes: Two people, four years apart, one theorem · The step nobody took for thirty-four years

Kayles is a row of skittles. A player knocks down one skittle, or two that stand side by side, and a gap left in the middle of a row turns one row into two. Whoever knocks down the last skittle wins. Henry Dudeney and Sam Loyd both set it as a puzzle early in the twentieth century, decades before anybody could say what a Kayles position was worth, and the game has a classic answer that needs no worth at all.

From a single row, the first player knocks down the middle skittle if the row is odd, or the middle two if it is even. That leaves two rows of the same length. From then on the first player copies: whatever the opponent does in one row, the same move is made in the other. The two halves stay identical after every pair of moves, so whenever the opponent has a move there is a copy of it available, and the opponent is the one who runs out.

That answer is older than the theory that explains Kayles by about thirty years. Bouton had solved Nim in 1901, and Sprague and Grundy proved in 1935 and 1939 that every impartial game is a Nim heap in disguise. Between them, the puzzle answer was the one general fact about adding games together that anybody used. This essay asks what that fact could decide, measured on every Kayles position up to twenty-four skittles, and what had to be added to it to reach the rest.

Copying is a theorem about sums

The copying argument looks like a trick for one puzzle, and it is really a theorem.

Kayles opened by a mirror. Rows of one to ten skittles, each with the middle skittle or the middle two knocked down. What is left is two equal rows, which the first player then keeps equal by copying, so every single row is a first-player win.
Fig. 1 Rows of one to ten skittles, each opened by the classic move: the middle one knocked down when the row is odd, the middle two when it is even. Rows of one and two vanish at once. Every longer row is left as two equal halves, and from there copying wins, so every single row of Kayles is a win for the player who moves first.

What copying uses is that the position after the opening move is a sum, G + G, two copies of one game side by side, and that the player who must move in a sum of two copies loses. Nothing about Kayles enters the argument. The opponent moves in one copy, the reply is the same move in the other, and the position is again two equal copies, smaller than before. Since the game is finite, the opponent eventually has no move. That is the statement

G+G=0,G + G = 0 ,

for any impartial game G, and it is the same symmetry that wins Cram on boards with both sides even, there by turning the board a half-turn and here by matching two rows.

What the argument does not do is say anything about G itself. It works without knowing who would win the row of five on its own, or what it is worth. That is its strength as a puzzle answer, and it is the whole of its limit as a theory. A position wins or loses by copying only if it already consists of matched pairs, or can be turned into matched pairs in one move.

How far copying reaches

So the question is how many positions are matched pairs. A Kayles position is a collection of rows, and for the copying argument to apply, every row length must occur an even number of times: two rows of three, or two of five and two of one, and so on. Call such a position a mirror.

What a mirror sees of the losses. Positions of Kayles with two to twenty-four skittles, by how many are losses and which test recognises them. Of 1,194 losses, 271 are pairs of equal rows, 754 are rows paired by equal Grundy value, and the rest need the exclusive-or. No position with an odd number of skittles is a mirror.
Fig. 2 Every Kayles position of two to twenty-four skittles, 7,336 of them, and the 1,194 that are lost for the player to move. Each bar splits the losses with that many skittles into three parts: the mirrors, the further losses that are rows paired by equal value, and the losses that only the exclusive-or of the values finds. No position with an odd number of skittles is a mirror.

Every mirror is a loss, and up to four skittles every loss is a mirror. After that, the share falls steadily. At ten skittles, 7 of the 9 losses are mirrors; at sixteen, 22 of 44; at twenty-four, 77 of 245, less than a third. Across the whole range, 271 of the 1,194 losses are mirrors, 23 per cent.

The counting behind the census is direct. For each total from two to twenty-four, every way of writing it as a sum of row lengths is a position, and its Grundy values are taken from the Kayles sequence. A position is a loss when the values exclusive-or to nought, a mirror when every length appears an even number of times, and a pairing by value when every value does. There is no sampling, and none of the three tests depends on the others.

The rows with an odd total are the striking feature. A mirror always has an even number of skittles, since it is two copies of something. But Kayles has losses with odd totals: one with five skittles, one with seven, and 125 with twenty-one. Copying can never see any of them, however clever the player, because no arrangement of matched pairs adds up to an odd number.

There is a clean reason why the mirror’s share must keep falling. The mirrors with 2m skittles are exactly the ways of splitting m skittles into rows and then doubling each row, so they are counted by the partitions of m: 77 at twenty-four, which is the number of partitions of twelve. The positions themselves are counted by the partitions of 2m, which grow far faster. Unless the losses become a vanishing fraction of all positions, which nothing in the census suggests, the mirrors are a smaller and smaller part of them.

The loss with five skittles

The smallest loss that copying cannot see is a row of four beside a row of one.

Losses no copying can find. The ten smallest Kayles positions that are lost for the player to move and are not pairs of equal rows, with each row's Grundy value. Six are rows paired by equal value; four, beginning with three, two and one, need the exclusive-or.
Fig. 3 The ten smallest losses that are not mirrors, with each row’s Grundy value. The first is a row of four and a row of one, both worth star. Six of the ten are rows that pair off by value, and four, beginning with rows of three, two and one, need the exclusive-or of the values.

It is easy to check by hand, and the check is itself a little copying argument. From four and one, the player to move has five kinds of move. Taking the single skittle leaves a row of four, and the opponent knocks down its middle two and leaves one and one. Taking an end skittle of the four leaves three and one, and the opponent takes two from the three and leaves one and one. Taking an inner skittle of the four leaves one, two and one, and the opponent takes the two. Taking two from the end leaves two and one, and the opponent takes one of the two. Taking the middle two leaves one, one and one, and the opponent takes any one of them. Every reply leaves a mirror, so every move loses. Copying sees this position one move further down, and only by trying every move; looking at the rows, it sees two different lengths and nothing to copy.

What the rows of four and one share is their value. A row of four is worth ∗, exactly as a row of one is. That means that the row of four is, in every sum it might ever appear in, interchangeable with a single skittle. The copying argument works between them as well, not move for move but strategy for strategy: whatever the opponent does to either row, there is a reply that brings the whole position back to a value of nought, because two games of equal value are the same game as far as winning is concerned. Equal games are the ones no company can tell apart, and that is the sense of “the same” that copying needed all along.

Rows that are one game

Read in that sense, the mirror becomes a much larger test. A position is lost if its rows can be paired off so that the two rows of each pair have the same value.

Rows that are one game. Rows of Kayles from one to twenty-four skittles, grouped by Grundy value. Six rows are worth star, five are worth star two, three star three, six star four, and two each star six and star seven.
Fig. 4 The rows of Kayles up to twenty-four skittles, grouped by Grundy value. Rows of 1, 4, 8, 13, 16 and 20 skittles are all worth star; rows of 3, 6 and 18 are all worth star three. Any two rows in one line cancel, though nothing about their lengths says so.

The classes are irregular, as the Kayles sequence is irregular before its period sets in at seventy. Six lengths up to twenty-four are worth star and six are worth star four; only two, eleven and twenty-two, are worth star six. Inside each line every pair cancels: a row of eight beside a row of thirteen is as lost as two rows of eight. Pairing by value catches 754 of the 1,194 losses, 63 per cent, against the mirror’s 23.

This is the step that is easy to describe and impossible to take without the theory. To pair a row of four with a row of one, a player has to know that they have the same value, and the value of a Kayles row is not visible on the skittles. It comes out of a recursion over every way the row can be broken, the mex rule applied to the values of everything a row can become. Nobody in the puzzle books had that recursion, and without it the class of star is a list of numbers with no visible reason behind it: one, four, eight, thirteen, sixteen, twenty.

It is the same step that separates Bouton’s criterion from the 1935 theorem: replace each heap’s size by its value. There the substitution was made inside the exclusive-or; here it is made inside the copying argument, and it does a different job. In the exclusive-or it turns a criterion for one game into a criterion for all of them. In the copying argument it turns a test for one shape of position into a test for a whole class of positions of different shapes.

Copying by value, worked

What replaces move-for-move copying is easiest to see in play. Take a row of eight beside a row of thirteen, both worth star, and suppose the opponent moves first.

If the opponent knocks down the middle skittle of the thirteen, the position is eight, six and six. The two sixes are a mirror on their own, and the eight is worth star, so the player wants to turn the eight into something worth nought: knocking down its middle two leaves three and three, and the whole position is now three, three, six and six, a plain mirror that copying finishes. If instead the opponent takes an end skittle from the eight, leaving seven beside thirteen, the rows are worth ∗2 and ∗, and the reply is a move in the thirteen to something worth ∗2. Knocking down two skittles that leave eight and three does it, since eight is worth star and three is worth ∗3, and star plus ∗3 is ∗2. The position seven, eight and three is worth nought and looks like nothing in particular.

The second kind of reply is the one copying never makes. It does not imitate the opponent’s move. It restores a balance of values, and it can always do so for a reason that is the core of the 1935 theorem: a position worth ∗n has a move to a position worth each smaller value, because the value is the least one that cannot be reached. So whenever the opponent lowers a value, the reply lowers its partner to match, and whenever the opponent raises one, as the move from eight to five and two does by turning star into ∗6, the reply lowers it straight back. The values do not always descend, and the strategy does not need them to.

Played this way, a pair of rows equal in value is exactly as safe for the second player as a pair of identical rows. The player who holds it never has to know what any row is worth beyond the two values being matched, and in that sense the middle layer is still copying. It copies values rather than moves.

What only the exclusive-or adds

Pairing by value still misses 440 losses. The smallest of them is three rows, of three, two and one skittles, worth ∗3, ∗2 and ∗.

No two of those rows have the same value, so no pairing exists. The position is lost because ∗3 + ∗2 + ∗ is nought, and that is a fact about how three different values combine, which is exactly what Bouton’s exclusive-or computes. Three is binary 11, two is 10, one is 01, and each column of binary digits has an even number of ones. In Nim, a heap of three, a heap of two and a heap of one is the standard first example of a losing position that is not a pair, and in Kayles the rows of three, two and one are a losing position for the same reason, once the rows are replaced by their values.

So the 1,194 losses fall into three layers. 271 are matched pairs of rows, and copying settles them. 483 more are pairs of rows equal in value, and they need the values. The other 440 need the values and the exclusive-or together. The theorem of 1935 settles every one of them, and it does so by joining two things that had both existed since the first decade of the century: copying, which knew that a pair cancels, and Bouton’s exclusive-or, which knew how unequal heaps combine.

Nim needed one step, and Kayles needed two

The comparison with Nim shows why nobody found the middle layer by looking at Nim.

Nim needed one step and Kayles two. Positions of Nim and of Kayles with two to twenty-four counters or skittles. Both have 271 mirrors. In Nim they are 42% of 645 losses and pairing by value adds none; in Kayles they are 23% of 1,194, pairing by value raises that to 63%, and 489 losses have an odd number of skittles.
Fig. 5 The three tests on Nim and on Kayles, over every position of two to twenty-four counters or skittles. Both games have the same 271 mirrors, since a mirror is a fact about the shape of the position. In Nim pairing by value adds nothing, because a heap is its own value, and Bouton’s exclusive-or takes the mirrors’ 42 per cent to everything. In Kayles the middle step is a large one.

A Nim heap of n counters is worth ∗n. Two heaps have equal value exactly when they have equal size, so pairing by value is pairing by size, and the middle layer is empty. The whole distance from copying to the truth in Nim is Bouton’s exclusive-or, and he crossed it in 1901. Nim also has no losses with odd totals, for a reason that can be read off the binary digits: the units digits of the heaps must contain an even number of ones, which makes their total even. Kayles has 489 odd losses up to twenty-four skittles, and every one of them is out of reach of copying from the start.

The second line of the figure’s footnote is the other half of the story. Bouton’s rule applied to Kayles as written, to the lengths of the rows rather than their values, calls 645 positions lost. 484 of them are, including all 271 mirrors, since equal lengths always exclusive-or to nothing. The other 161 are wins, and 710 genuine losses are not named at all. The rule of 1901 transplanted to Kayles is wrong in both directions, as it is wrong on every game it was not written for.

So the decade after 1901 held both tools and neither worked on Kayles. Copying was sound everywhere and saw a quarter of the losses. The exclusive-or was complete for Nim and unsound everywhere else. What joins them is the value: copying, with equal read as equal in value, and the exclusive-or, applied to values rather than sizes. Either tool alone would have suggested what the other needed, if anyone had been looking at both.

Where the copying move exists

The puzzle answer was always about winning rather than losing. It tells the first player what to do. So the other measure of its reach is how often a player who can win has a copying move available, a move that leaves a mirror.

Where the copying move exists. Kayles positions won by the player to move, at six totals from four to twenty-four skittles, and how many have a move to two equal sets of rows. Over every total to twenty-four, 2,674 of 6,143 wins have one.
Fig. 6 Kayles positions won by the player to move, at six totals from four to twenty-four skittles, and how many of them have a move to a mirror. Every single row has one. Across all totals to twenty-four, 2,674 of the 6,143 winning positions have such a move, and the share falls from all three of the four-skittle wins to a third at twenty-four.

A move to a mirror is better than a proof that the position is won. It is the winning move itself, and the strategy for every move after it. It exists in every single row of Kayles, which is why the puzzle has a satisfying answer. Once rows have been broken up, it is available in fewer than half the winning positions, and at twenty-four skittles in about a third. A player who knows only how to copy can win the opening of any game of Kayles and then, often within a few moves, finds a position that is still won with no idea of how to win it.

The count is the same exhaustive one as the census of losses: every position of each total, every move from it, and a check of whether the position after the move has each row length an even number of times.

The convention named

Kayles here is the normal-play game: the player who knocks down the last skittle wins, equivalently the player left with no move loses. Under the other convention, where taking the last skittle loses, copying fails, since a mirror can be a win for the player to move, and none of these counts would stand. That other convention has no negatives, so the very statement G + G = 0 is false there.

The positions are counted as collections of rows, without regard to order, so that three skittles beside one are the same position as one beside three. A move takes one skittle, or two that stand side by side, from any one row. The Grundy values are the standard Kayles sequence, computed by the mex rule from the empty row up.

What the census cannot show

Whether anyone pushed copying further in print before 1935. The puzzle answer is the version that survives in the books, and a historian of the period might find a sharper one. Nothing here can rule that out. What the census measures is what the copying argument itself can reach, which is a fact about the argument and not about its users.

How the shares behave past twenty-four skittles. The mirror’s share must keep falling, by the counting argument above, provided the losses do not become rare among the positions. The share of pairing by value fell from 76 per cent at twelve skittles to 62 at twenty-four, and the census says nothing about where it goes after that. It could level off, since the Kayles sequence becomes periodic at seventy and the classes then grow in a regular way.

Anything about other games. The middle layer exists in Kayles because many row lengths share a value. In a game whose values are all different, as in Nim, it vanishes, and in a game where nearly everything is worth one of two values it would swallow almost every loss. Kayles is one game, and its numbers describe Kayles.

Still open: how the middle layer grows

The middle layer is the part of the theory that a player could hold in their head without any arithmetic: a short list of row lengths that cancel one another. For Kayles up to twenty-four skittles that list has six classes and covers 63 per cent of the losses. Past seventy, the Kayles sequence repeats with period twelve, so the classes become infinite and regular, and a player with the twelve residues and the fourteen exceptional rows below seventy would hold a complete table of which rows cancel. The question is what share of the losses that table settles as the skittles grow. If the share tends to a fixed fraction, then a player who knew only how to pair, with no exclusive-or, would win a fixed proportion of lost positions for ever. If it tends to nought, then the exclusive-or carries more and more of the game as positions grow, and Bouton’s arithmetic, not the copying, is what the theorem of 1935 mostly is. The census to a few hundred skittles, which is a partition count of some millions, would say which.

Part 5 of 7

One argument about Sprague–Grundy. The parts either side of it:

What links here

Essays that reach for this one mid-argument — the half of a link its own author cannot write down.

What this makes readable

Essays that declare this one a prerequisite.

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.

Disjunctive sumEquivalenceExhaustive searchGrundy valueKaylesNim-sumPairing strategySprague–GrundySymmetry