Definition · A subtraction game, and its two kinds of positionTwo players alternate. From a position p a player may move to p − m for any m in a fixed subtraction set with m ≤ p. A player with no legal move loses. A position is losing if the player about to move from it loses under perfect play, and winning otherwise.
Theorem · The labelling recurrenceA position p is losing if and only if every move from p leads to a winning position; equivalently, p is winning if and only if some move from p leads to a losing position. A position with no legal moves is losing.
By strong induction on p. Suppose every position below p is correctly labelled. If some move from p reaches a losing position, the player to move takes it and hands the opponent a position from which, by hypothesis, the opponent loses; so p is winning.
If every move from p reaches a winning position, then whatever the player does, the opponent is handed a position from which the opponent, by hypothesis, wins; so p is losing. The two cases are exhaustive, and the vacuous case — no moves at all — falls under the second, which is why a terminal position loses.
□
Notice that this table has no objective to optimise. Every other page on this course computes a best value; this one computes a truth value, and the recurrence is a pair of quantifiers rather than a minimum or a sum. That is worth seeing once, because it separates the technique — a table, an order, a recurrence — from the arithmetic that usually accompanies it.
Example · Take one, three or four, from zero to eighteenThe labels come out L W L W W W W L W L W W W W L W L W W. The losing positions are 0, 2, 7, 9, 14 and 16. Position 2 loses because its only legal move is to 1, which wins; position 7 loses because its moves reach 6, 4 and 3, all winning. The panel reports the smallest period over the positions shown as 7, and a memo-free minimax recursion agrees with the table at every position.
That period is not the multiples of anything. Losing positions are those congruent to 0 or 2 modulo 7, which is two residues rather than one. Change the subtraction set to 1, 2 and 3 and the losing positions are exactly the multiples of 4, and that pattern has an argument a reader can give in one line. Change it to 1 and 2 and the answer is the multiples of 3. Change it to 2 and 5 and positions 0 and 1 both lose, so the pattern does not even begin with a single loss.
What is measured, and what can be proved
The panel's period is computed by testing, for each k in turn, whether the labels agree at every pair of positions k apart among the positions labelled. With nineteen positions on screen and a reported period of 7, that is two full repetitions and a bit. It is a measurement, and if the pattern broke at position 40 the panel would say nothing about it.
Theorem · Subtraction games are eventually periodicLet M be the largest element of the subtraction set. The label of a position is determined by the labels of the M positions below it. There are at most 2^M distinct windows of M consecutive labels, so some window repeats, and from that point the sequence of labels repeats with a period at most 2^M.
Consider the sequence of windows w(p) consisting of the labels of positions p−M through p−1. The recurrence determines the label of p from w(p) alone, and therefore determines w(p+1) from w(p). So the sequence of windows is generated by a function from a finite set to itself.
A sequence of elements of a set of size at most 2^M generated by iterating a function must repeat a value within the first 2^M + 1 steps, and once a window repeats, everything after it repeats too. Hence the labels are eventually periodic with period at most 2^M. For the subtraction set 1, 3, 4 that bound is 16, and the measured period is 7 — the bound is true, loose, and says nothing about which value below it occurs.
□
Those two results are exactly the pairing this Subject insists on. The table measures a period of 7 over nineteen positions. The pigeonhole argument proves eventual periodicity with period at most 16, for every subtraction set. Neither implies the other: the measurement does not establish that 7 continues, and the proof does not say the period is 7 or that it starts at position zero rather than later. Raising the range on the lab extends the measurement and never turns it into the theorem.
The cost is the least interesting thing on the page and is worth one sentence: nineteen positions are labelled with nineteen calls, each looking at up to three predecessors, so labelling n positions is Θ(n) for a fixed subtraction set. The memo-free recursion that checks it is exponential and is capped at position 24 for that reason.