Concept

XOR — where it appears

Bitwise addition without carrying, under which two equal numbers cancel, and the operation impartial values add by. Two equal heaps cancel under it, which is why a symmetric Nim position is a loss for whoever has to move.

Named by 22 essays across 5 fields — each of them below, with the objects they name alongside it.

Nim with heaps of 3, 5, 7. Heaps of counters; a move takes any number from one heap. The position is a loss for the player to move exactly when the binary digits of the heap sizes cancel in every column — the nim-sum — and that is the whole of the theory of Nim.

Nim, and the nim-sum

Three heaps of counters, take as many as you like from one of them, and the player who takes the last counter wins. The winning condition is not a search, not a table, and not a heuristic — it is the bitwise exclusive-or of the heap sizes, and it was found in 1901.

impartial · Nim
Bouton's invariant, checked over 512 positions. Nim positions in binary, one column per bit. Bouton's 1901 argument is that a position is a loss for the mover exactly when every column holds an even number of marks — and that from such a position every move breaks a column, while from any other position some move repairs them all. Both halves are checked here over every position in the range rather than illustrated once, and the middle row shows the repairing move being made.

The theorem that needed none of the theory

Bouton solved Nim completely in 1901, with an argument that mentions no value, no sum of games and no Grundy number, because none of the three existed. The argument is two closure properties and it is airtight — and run on any other game it fails at the step that does the work.

history · Bouton
Poker Nim from 3, 5, 7, with reserves of 4 and 4. Nim with one extra kind of move: a player may put any number of counters back onto a heap from a private reserve. It looks as though a losing player could stall for ever. They cannot, and the winner is decided by exactly the same nim-sum as ordinary Nim — checked here over every position within a stated range rather than argued.

The move that gives counters back

Poker Nim adds one rule to Nim — a player may put counters back onto a heap from a private reserve. It looks as though a losing player could stall for ever. The winner is decided by exactly the same nim-sum, and the reason is the single most useful idea in the whole reduction apparatus.

impartial · Nim
Turning Turtles: a row of 12 coins. A row of coins, some heads and some tails. A move turns some of them over, and the rightmost coin turned must go from heads to tails — which is what makes the game end. The number under each place is what a lone head there is worth, and the row is worth the exclusive or of the places showing heads.

A row of coins is already a sum

Everywhere else on this site a sum is several positions side by side. In a coin-turning game it is one row — each coin showing heads is a game in its own right, and the row is worth the exclusive or of them. The decomposition is inside a single picture.

impartial · Sprague–Grundy
a triangle on a stalk, worth ∗2. A Hackenbush position in which every edge is green, so either player may cut any of them and the position is impartial. Its value is a single Nim heap. Two principles find which one: fusion, which collapses every cycle to a point and leaves that many loops behind, and the colon principle, which replaces a branch by a stalk as long as the branch's own value.

Squash every loop to a point

Colour every Hackenbush edge green and the game becomes impartial, so the whole picture is worth a single Nim heap. Two principles find which one without playing anything — fuse the cycles, then run one pass up the tree — and a nine-vertex lattice that costs 1,283 positions to solve costs twelve steps to read.

positions · Hackenbush
The same position, and two rulers to measure it with. Nim positions with the length of their input under two encodings — the heap sizes in binary, and the counters themselves — beside the work the nim-sum does. The work never changes. Which of the two lengths it is compared against decides whether the same algorithm reads as linear or as exponentially fast, and hardness claims are always made against one particular encoding.

Nim is easy, in binary

Three heaps of a thousand counters take thirty bits to write down and three thousand counters to lay out. The nim-sum does three exclusive-ors either way. Whether that counts as fast depends entirely on which of the two numbers the work is compared against.

complexity · Complexity
Nim-multiplication below 16, and every field axiom checked. The nim-product, defined by taking the least value the product is not forced to be — the same manoeuvre as the mex rule, applied to a product rather than to a move. The result is that these values are not merely a group under nim-addition but a field: every axiom is checked over the whole table here, including an inverse for every non-zero value, and the sizes at which the axioms fail are reported rather than avoided.

The nimbers multiply

Nim-addition is exclusive-or and everybody meets it first. There is also a multiplication, defined by the same take-the-least-value-not-forced manoeuvre as the mex — and it makes the nimbers below sixteen a field, with every axiom checked here and an inverse for every non-zero value.

impartial · Nim
A grid of coins, and a multiplication table. The Grundy values of a two-dimensional coin-turning game, computed from its own move rules by a mex at every cell. Down the left and across the top are the one-coin values of the two one-dimensional games it is built from. Every cell is the nimber product of its two edge values — the multiplication defined for the nimber field on algebraic grounds — and beside the grid are the three combining rules a reader would try first, each killed on a named cell.

The tartan theorem

The nimbers are a field, with a multiplication defined by a mex-style rule that looks like an algebraist's amusement. Lay two coin-turning games on a grid and the Grundy value of each square is the nimber product of its two coordinates — which is the point at which the multiplication stops being a curiosity and starts computing answers.

impartial · Nim
Mock Turtles on 8 coins: every lost position. The rows a player to move has already lost, drawn in full. A filled disc is a coin showing heads. The set is closed under turning over every coin two of its members disagree about, which is what makes it a linear code, and the count of heads in the sparsest of them is the fewest coin turns that separate two lost positions.

The losing positions are a code

Turn over one, two or three coins, and the rows a player has already lost turn out to be closed under adding two of them together. That makes them a linear code — and on eight coins it is the extended Hamming code exactly, sixteen words with a weight enumerator of 1 + 14x⁴ + x⁸, produced by a move rule that knows nothing about codes.

impartial · Codes
The same position, two conventions, two winners. Three-player Nim with the last counter winning. The two columns differ only in what a player does when they cannot win themselves, which is a question the rules do not answer — and the answer decides who wins.

Three players and no answer

Every theorem here is about two players, and the reason is not convenience. With two players the game is zero-sum, so 'play well' needs no further explanation. Add a third and the winner of a Nim position becomes a fact about the convention: two reasonable ones disagree on 56 of the 71 positions swept. The one question no convention touches — can a player force a win against the other two together — is answered 'nobody' in 65 of the 71.

limits · Multiplayer
Mock Turtles on 8 coins: finding the move is decoding. Every row of the game, sorted by what it takes to win from it. The lost rows are the codewords; a won row is a codeword with errors, and the winning move is the error pattern that turns them off. The distance column is a fact about the code and the coins column is a fact about the rules, and the two do not quite agree.

The code names the move

If the lost rows of a coin-turning game are a linear code, then a won row is a codeword with errors in it and the winning move is whatever turns the errors off. Over all 256 rows of Mock Turtles on eight coins: 16 codewords, 240 won rows, none more than two coins from a lost one — and 64 of them whose cheapest winning move has to turn three coins anyway.

impartial · Codes
Welter positions and what they are worth. Coins on a strip, with the Grundy value the recursion returns and the nim-sum the squares would have if they were independent heaps. The two columns are the essay: they hardly ever agree.

No two heaps alike

Welter's game is Nim with one extra clause — no two heaps may be the same size — and the clause is fatal to the nim-sum, which gives the right answer in none of the 120 three-coin positions. What replaces it is a function of pairs: ⟨a | b⟩ = (a ⊕ b) − 1, exact on all 55 two-coin positions, and nim-added over every pair it is exact on the whole board provided the number of coins is even.

impartial · Welter
Three take-and-break games, three kinds of answer. The Grundy sequences of Nim, Lasker's Nim and Kayles over the first heaps. Adding a move that removes nothing takes Nim's sequence from the identity to a four-line formula; bounding how much may be taken instead takes it somewhere with no formula at all.

Splitting is a move

Add to Nim a move that removes nothing — break a heap in two — and the Grundy sequence gets simpler, not harder. Lasker's Nim has a closed form with one clause per residue modulo four, exact on all 2,001 heaps checked: the identity with every fourth pair transposed. Kayles is the same kind of game with the taking bounded instead of the splitting, and it has no closed form at all, settling into a period of twelve only from heap 71 with fourteen values outside it for ever.

impartial · Lasker
The genus of a sum. Every pair of heaps up to 9 counters, from nine impartial games, filed by the genus symbols of its two parts. The claim under test is that the file determines the answer; it does, and neither half of the symbol determines it alone.

The genus of a sum

A genus symbol is meant to be carried one per heap, so that a solver never has to look at the heap again. That is a claim that the pair of symbols determines the sum's, and across nine games and 405 pairs it holds without exception — while the bases alone determine it in only 38 of 50 cases and the superscripts alone in 70 of 74. Both halves of the symbol are load-bearing, and two wild heaps can add to a tame sum.

limits · Genus
Moore’s rule, reversed. Moore’s Nim under the misère convention at three values of k, with the normal-play rule and the same rule plus a clause about heaps of one. The patch is the one Nim takes, with the modulus the normal-play rule already carries, and it is right on every position swept.

The patch that generalised

Misère Nim takes a one-line patch: play the normal-play strategy until every heap holds a single counter, then invert. Moore's Nim, where a move may take from up to k heaps at once, takes exactly the same patch with exactly the same modulus — and the two rules disagree on six positions out of 923.

impartial · Moores-nim
One number per heap, and one number per state. Sums of Fibonacci Nim components solved in full, against two predictions. Giving each component the number its heap size suggests gets a quarter of the pairs wrong; giving it the Grundy value of its state — the pair of heap size and cap — gets every pair and every triple right.

What restores the theorem

Fibonacci Nim breaks the recipe every impartial game is supposed to obey: one number per heap, exclusive-ored, gets a quarter of two-heap sums wrong. Index the recursion on the pair of heap size and cap instead and the recipe is exact on every pair and every triple — and the number a heap of nine carries turns out to be five rather than one.

limits · Memory
How two genus symbols make a third. The composition rule for genus symbols, stated with its cases and checked on every pair of heaps of nine games. The base exclusive-ors, the sum is fickle only when every component is, and the symbol follows from those two.

The rule the symbols follow

Two genus symbols make a third by three lines and no lookup table: the base exclusive-ors, the sum is fickle only when every component is, and the symbol follows. Checked on 252 pairs across nine games it is right on 238 — and the fourteen failures are exactly the fourteen pairs with a wild heap in them, which is the boundary the genus is defined up to arriving as a measurement.

limits · Genus
Thirty-two words, four of them lost. Every position of five heaps grouped by the parities of its heaps in decreasing order of size. Each word is uniform, and four of the thirty-two are losing.

The parities, in size order

The rung below settled four of six parity classes in bounded Moore's Nim and asked whether the sizes pick out the losing positions in the two it could not. They do — but only through the order they put the parities in. Sort the heaps largest first, read off their parities, and that five-bit word settles the whole game at every width of move, with the losing words forming a subspace.

impartial · Moores-nim
What a certificate costs, in units of the one Guy and Smith wrote. Octal codes with the period of their Grundy sequence, the window a proof of that period needs, and the arithmetic each costs — counted as mex operations and exclusive-ors, which are the two things a person computing by hand actually performs. Everything is priced in units of the certificate for Dawson's chess, so the column reads as multiples of one hand computation rather than as a number of operations. Some codes cost tens of times as much, and some have no certificate at all.

What the arithmetic cost in 1956

The rung below ends by respecting a hand computation without pricing it. Priced in the operations a person actually performs, ·137's certificate is 7,919 of them — and the same sweep says ·47's is sixty-three times that, that a splitting move is what makes the cost quadratic, and that seventeen of sixty-four codes have no certificate at any price.

history · Dawson
One substitution, thirty-four years. Bouton's criterion and the Sprague–Grundy theorem run side by side over a family of games. They differ in one quantity: the heap's size against the heap's Grundy value. The exclusive-or that combines them is the same operation in both, and it is the one Bouton published in 1901.

The step nobody took for thirty-four years

Bouton's criterion is that the heap sizes exclusive-or to nothing. The 1935 theorem is that the heap Grundy values do. The exclusive-or is the same operation in both and it is his, so the whole of the intervening thirty-four years is one substitution — and run over eight games and 672 positions, the substituted criterion is exact on every one while the original is exact on Nim and nowhere else.

history · Bouton
Lasker's Nim in sixteen cells. A four-by-four table. Each row and column is a residue mod 4 of one part of a split heap, with the residue of that part's Grundy value beside it; each cell is the residue mod 4 of the split's value, the nim-sum of the two parts. Every split of every heap to four hundred lands in the cell its residues name.

The proof is sixteen cells

Lasker's Nim has a four-clause formula that was checked on two thousand heaps and never proved. The proof fits in a four-by-four table: the last two bits of a split's value are fixed by the last two bits of its parts, so no split can land in its own heap's class — except at 3 mod 4, where it lands exactly on the one value the takes leave missing and pushes the answer up by one.

impartial · Lasker
Two heaps and a held pass. Every pair of heaps up to 16 with one pass available that may not be the last move. Filled cells are the pairs the player to move loses: the empty board and the pairs one and two, three and four, five and six, and so on. Outlined cells are the equal pairs Nim calls lost, all of which are wins once the pass is there.

Three heaps and a pass

Nim with a single pass that may not end the game is easy on one heap and on two: a heap swaps each odd size with the even one above it, and two heaps lose exactly at (2k − 1, 2k). On three heaps the losses are known only as a list. Fix the smallest heap and each slice of the list settles into a pattern after an irregular start — period 4, 8, 10, then 160 at a smallest heap of ten, and nothing visible from eleven.

limits · Pass

Named alongside it

The objects these essays reach for when they reach for this one.

Grundy valueExhaustive searchImpartialNim-sumNimMexSprague–GrundyNormal playNimberP-positionBinaryClosed form

All concepts