Sprague–Grundy values
Lax689614.Grundy · concepts/Lax689614/Grundy.lean · lax-689614
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 Lax689614.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 Lax689614.Grundy |
| 17 | |
| 18 | open ArcKayles |
| 19 | |
| 20 | noncomputable def mex (S : Finset ℕ) : ℕ := sInf {n : ℕ | n ∉ S} |
| 21 | |
| 22 | noncomputable def value {V : Type} [DecidableEq V] |
| 23 | (G : SimpleGraph V) (S : Finset V) : ℕ := |
| 24 | mex ((moves G S).attach.image fun e => value G (remove S e.val.1 e.val.2)) |
| 25 | termination_by S.card |
| 26 | decreasing_by |
| 27 | have h := e.property |
| 28 | simp only [moves, Finset.mem_filter, Finset.mem_product] at h |
| 29 | exact lt_of_le_of_lt Finset.card_erase_le (Finset.card_erase_lt_of_mem h.1.1) |
| 30 | |
| 31 | end Lax689614.Grundy |
| 32 |
Discussion
Ask a question or add context. Endorsements and structured flags are kept in the review panel above.
0 comments