Sprague–Grundy values
Lax783278.Grundy · concepts/Lax783278/Grundy.lean · lax-783278
No public endorsements yet.
Loading review…
Sign in with ORCIDNatural Language Statement
Definition
The minimum excluded value of a finite set of natural numbers is the least natural number outside the set. The Sprague–Grundy value of a position is the minimum excluded value of the values reachable in one move. In particular, a terminal position has value zero.
Concept map
Lean source view on GitHub
| 1 | import Lax783278.ArcKayles |
| 2 | import Mathlib.Order.ConditionallyCompleteLattice.Basic |
| 3 | import Mathlib.Order.Lattice.Nat |
| 4 | |
| 5 | /-! |
| 6 | --- |
| 7 | title: Sprague–Grundy values |
| 8 | type: definition |
| 9 | --- |
| 10 | The minimum excluded value of a finite set of natural numbers is the least |
| 11 | natural number outside the set. The Sprague–Grundy value of a position is |
| 12 | the minimum excluded value of the values reachable in one move. |
| 13 | In particular, a terminal position has value zero. |
| 14 | -/ |
| 15 | |
| 16 | namespace Lax783278.Grundy |
| 17 | |
| 18 | open ArcKayles |
| 19 | |
| 20 | /-- The least natural number not in the finite set `S`. -/ |
| 21 | noncomputable def mex (S : Finset ℕ) : ℕ := sInf {n : ℕ | n ∉ S} |
| 22 | |
| 23 | /-- The game value obtained from `rounds` rounds of backward induction. |
| 24 | A position at depth zero has value zero; each further round takes the |
| 25 | minimum excluded value of its immediate successors. -/ |
| 26 | noncomputable def valueAfter {V : Type} [DecidableEq V] |
| 27 | (G : SimpleGraph V) : ℕ → Finset V → ℕ |
| 28 | | 0, _ => 0 |
| 29 | | rounds + 1, S => |
| 30 | mex ((moves G S).image fun e => valueAfter G rounds (remove S e.1 e.2)) |
| 31 | |
| 32 | /-- The Sprague–Grundy value of the complete game tree. Its depth is at most |
| 33 | the number of surviving vertices, because every move removes two vertices. -/ |
| 34 | noncomputable def value {V : Type} [DecidableEq V] |
| 35 | (G : SimpleGraph V) (S : Finset V) : ℕ := |
| 36 | valueAfter G S.card S |
| 37 | |
| 38 | end Lax783278.Grundy |
| 39 |
Discussion
Ask a question or add context. Endorsements and structured flags are kept in the review panel above.
0 comments