AFTD Auto-Formalizing Theoretical Domains

subtraction_grundy

def

The ordinary Sprague-Grundy sequence g_S : ℕ → ℕ of a subtraction game with move set S ⊆ ℕ is defined recursively by g_S(n) = mex {g_S(n - s) : s ∈ S, 0 < s ≤ n}.

Statement

noncomputable def subtraction_grundy (S : Set ℕ) : ℕ → ℕ
Defined in
arXiv:2611.30147, line 199 (equation 1)
Verified
24 Nov 2026
Axioms
none listed
Built on 1
  • nat_mex_setThe minimum excluded natural number of a set s of natural numbers is the infimum of the set of natural numbers not in s.
Used by 2
  • op2347_gThe Sprague-Grundy sequence for the normal-play subtraction game with move set {10, 12, 24, 72 * k - 1}.
  • subtraction_pass_grundyThe pass-available Sprague-Grundy sequence h_S : ℕ → ℕ of a subtraction game with move set S ⊆ ℕ is defined recursively by h_S(n) = mex…

Read back from the Lean

The function subtraction_grundy takes a set of natural numbers $S \subseteq \mathbb{N}$ and returns a function from $\mathbb{N}$ to $\mathbb{N}$ defined by well-founded recursion on $n \in \mathbb{N}$ (using the standard ordering on $\mathbb{N}$). For each $n \in \mathbb{N}$, its value is the minimum excluded natural number (nat_mex_set) of the set of recursive values at $n - s$ over all $s \in S$ such that $0 < s \le n$.

Written by a model that saw only the Lean, never the English above. If the two disagree, that is worth a challenge.

Lean source view module on GitHub

/-- Ordinary Sprague-Grundy sequence of a subtraction game with move set S. -/
noncomputable def subtraction_grundy (S : Set ℕ) : ℕ → ℕ :=
  WellFounded.fix (measure id).wf fun n ih =>
    nat_mex_set {k | ∃ s ∈ S, ∃ (hs : 0 < s) (hle : s ≤ n), k = ih (n - s) (Nat.sub_lt_self hs hle)}
See it in the graphDiscuss this resultChallenge it