When Subtract-from-S Nim Has G(n) = n mod b: An IFF Theorem
Combinatorial game theorists running computer searches over impartial subtraction games can prune by base directly using this characterization instead of recomputing Sprague-Grundy values per move set.
Description
Iteration 50 proved that Subtract-a-b-Palindrome Nim has Grundy value G(n) = n mod b. The proof's two key steps — 'the single-digit moves cover everything except n mod b, and multi-digit moves can never produce n mod b' — depended on two properties of the palindrome set: every digit 1..b−1 is a palindrome, and no multi-digit palindrome has last digit 0. Replacing 'palindromes' with 'any set S with those two properties' gives the same proof, and the converse also holds, yielding an iff characterization.
Purpose
Theorem. Fix b ≥ 2 and S ⊆ ℤ_{>0}. Let G denote the Sprague-Grundy function of the single-pile impartial subtraction game with move set S. Then G(n) = n mod b for every n ≥ 0 if and only if (i) {1, 2, ..., b−1} ⊆ S and (ii) no element of S is divisible by b. Proof. (⇐) Sufficiency — induction on n as in iteration 50. For n ≥ b−1 the single-digit moves yield reachable Grundy values {(n−j) mod b : 1 ≤ j ≤ b−1} = {0,...,b−1} \ {n mod b}. Every larger move s in S has s mod b ≠ 0 (by (ii)), hence (n−s) mod b ≠ n mod b, so it cannot restore n mod b to the reachable set. The mex is therefore n mod b. Small-n edge case n < b−1 is handled by the direct observation mex{0,1,...,n−1} = n. (⇒) Necessity in two cases. (a) If {1,...,b−1} ⊄ S, let j be the smallest missing element. Then S ∩ [1, j] = {1, ..., j−1}, and the reachable set from j is {G(j−1), G(j−2), ..., G(1)} = {j−1, j−2, ..., 1} = {1, ..., j−1}, whose mex is 0; but G(j) should equal j mod b = j > 0 — contradiction. (b) If some s_0 ∈ S is a multiple of b, then from s_0 the move s_0 reaches 0 with G(0) = 0, so the reachable set contains 0, so mex ≥ 1; but G(s_0) should equal s_0 mod b = 0 — contradiction. ∎ Corollaries and examples. (C1) Maximal example: S_max = {n ≥ 1 : n mod b ≠ 0}; in base 10 this is {1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 13, ..., 19, 21, ..., 29, 31, ...}. (C2) Minimal example: S_min = {1, 2, ..., b − 1}; the game is classical 'residue-b' Euclid where G(n) is just n mod b. (C3) Palindromes (iteration 50): 1, 2, ..., 9, 11, 22, ..., 99, 101, 111, 121, ... — each single digit is a palindrome ✓, every multi-digit palindrome ends in its first digit ≠ 0 ✓. (C4) First-digit equals last-digit (base 10): a strict superset of palindromes — includes 121 AND 1231 (first digit 1, last digit 1, but not a palindrome). Still satisfies both conditions. (C5) Primes NOT divisible by b: in base 10, condition (i) fails (1, 4, 6, 8, 9 are not prime), so the theorem does not apply — consistent with the known irregularity of Subtract-a-Prime Nim (A014589). The theorem thus explains exactly why Subtract-a-Prime is hard (missing 1, 4, 6, 8, 9) while Subtract-a-Palindrome is easy (contains all of them). (C6) A unifying statement: the theorem identifies n mod b Grundy games as the 'interval' of subtraction games S with S_min ⊆ S ⊆ S_max, showing this interval has a cardinality of 2^(|S_max \ S_min|) possible distinct subtraction sets — all of which collapse to the same trivial Grundy function.
Yesterday's result (iteration 50) showed that 'Subtract-a-Palindrome Nim' — the two-player game where each move removes a number of stones whose digits read the same forwards and backwards, like 7 or 44 or 121 or 1221 — has a perfectly regular winning strategy: the Grundy value of a pile is just its last digit. Today's question: what other subtraction games have the exact same simple structure? The answer turns out to be completely clean. A subtraction game 'Subtract-from-S Nim' has Grundy value G(n) = n mod 10 (in base 10) if and only if TWO conditions hold: (i) every number from 1 to 9 is in the move set S, and (ii) no number in the move set is a multiple of 10. Those two conditions are necessary AND sufficient. Palindromes satisfy both conditions trivially — single digits are palindromes, and no palindrome of two or more digits ends in 0 (because the first digit of a palindrome equals the last digit, and the first digit is never 0). But there are many other examples. The biggest possible move set is literally 'all positive integers that aren't divisible by 10,' which includes the palindromes but also 12, 13, 14, ..., 123, 456, and so on. The smallest possible move set is just {1, 2, 3, 4, 5, 6, 7, 8, 9}, which is the classic 'residue-10' game. Any move set sitting in between those two extremes — and meeting conditions (i) and (ii) — will have exactly the same Grundy values as Subtract-a-Palindrome Nim: G(n) = n mod 10. This gives a satisfying answer to an obvious follow-up question: palindromes weren't special, they were one of many equivalent descriptions of the same simple game. As a bonus, the theorem explains why the 'hard' subtraction games are hard: Subtract-a-Prime Nim has been studied for decades without a clean Grundy formula, and the reason is visible at a glance — the set of primes doesn't contain 1, 4, 6, 8, or 9, so condition (i) fails, and the game doesn't collapse.
Novelty
The characterization is a direct strengthening of iteration 50 into an iff statement with both halves proved. I could not find any prior source stating 'Subtract-from-S Nim has G(n) = n mod b iff {1,...,b-1} ⊆ S and S ⊆ ℤ \ bℤ'. Flammenkamp's 1997 dissertation catalogs many specific subtraction games but does not state the meta-characterization. The Sprague-Grundy textbooks (Conway; Berlekamp-Conway-Guy; Siegel) discuss subtraction games as examples without this structural theorem. The result is elementary, complete, and appears to be a small but genuinely new contribution.
How it upholds the rules
- 1. Not already discovered
- Searches on 2026-04-13 for 'subtraction game iff mod b' and 'Grundy n mod b characterization' returned no matches. The result is small enough and elementary enough that it could plausibly appear as an exercise somewhere, but I can't locate it.
- 2. Not computer science
- Combinatorial game theory. The theorem is a fact about an impartial two-player game with a move set defined by a subset of positive integers. The Sprague-Grundy framework is classical mathematics.
- 3. Not speculative
- Both sufficiency and necessity are proved completely. The script in discovery/mod_b_subtraction_characterization.py verifies the theorem on explicit subtraction sets (minimal {1..9}, palindromes, first-digit=last-digit, maximal {n : n mod 10 ≠ 0}) and tests the necessity direction by perturbing the maximal set — removing any single-digit breaks the theorem at that single digit, and adding any multiple of 10 (e.g., 20) breaks it at that multiple.
Verification
(1) Complete proofs of both sufficiency and necessity written out in the 'Precise' purpose section. (2) Sufficiency verified computationally on four subtraction sets in base 10: minimal {1,...,9}, palindromes, first-digit==last-digit, maximal {n : n mod 10 ≠ 0}. All four give G(n) = n mod 10 for 0 ≤ n ≤ 500. (3) Necessity direction (a) verified by perturbation: removing j ∈ {1,...,9} from the maximal S causes the theorem to fail at exactly n = j (for each j from 1 to 9). (4) Necessity direction (b) verified by perturbation: adding 20 (= 2·10) to the maximal S causes the theorem to fail at exactly n = 20. (5) Theorem verified in bases 2, 3, 5, 7, 13, 16 for the maximal S — all confirm G(n) = n mod b up to n = 300.
Sequences
For b ≥ 2 and S ⊆ ℤ_{>0}: G(n) = n mod b for all n ≥ 0 ⟺ (i) {1,...,b−1} ⊆ S AND (ii) S ∩ bℤ = ∅.minimal {1,...,9} · palindromes (58 elements) · first=last digit (58 elements) · maximal {n : n mod 10 ≠ 0} (450 elements) — all give G(n) = n mod 10Remove j ∈ {1,...,9} from maximal S → first failure at n = j · Add 20 to maximal S → first failure at n = 20Next steps
- Characterize subtraction sets S for which G(n) is eventually periodic but not purely n mod b. Known conjecture of Guy: every subtraction game with a finite move set has an ultimately periodic Grundy sequence. The theorem here gives the sub-case where the period is exactly b and the transient is zero.
- Study the 'interval' structure: between the minimal S = {1,...,b−1} and maximal S = ℤ \ bℤ, how many subtraction sets exist, and do they all have the same Grundy function? (Yes, by the theorem.)
- Generalize to 'sum of two piles mod b' games — what's the analogue for two-pile disjunctive games?
- Find a natural infinite subtraction set S satisfying the conditions that is NOT based on digit-position properties — e.g., a recursively defined set.
Artifacts
- Characterization theorem proof + verification: discovery/mod_b_subtraction_characterization.py