Arc Kayles
Lax689614.ArcKayles · concepts/Lax689614/ArcKayles.lean · lax-689614
No public endorsements yet.
Loading review…
Sign in with ORCIDNatural Language Statement
Definition
A position consists of a finite set of surviving vertices of a simple graph. A move removes the two endpoints of a surviving edge. Under normal play, the player with no legal move loses. A position is winning for the player to move if some legal move leaves a position losing for the opponent. Isolated vertices may be retained: they permit no moves.
Concept map
Lean source view on GitHub
| 1 | import Mathlib.Combinatorics.SimpleGraph.Basic |
| 2 | import Mathlib.Data.Finset.Card |
| 3 | import Mathlib.Data.Finset.Prod |
| 4 | |
| 5 | /-! |
| 6 | --- |
| 7 | title: Arc Kayles |
| 8 | type: definition |
| 9 | --- |
| 10 | A position consists of a finite set of surviving vertices of a simple graph. |
| 11 | A move removes the two endpoints of a surviving edge. Under normal play, |
| 12 | the player with no legal move loses. A position is winning for the player |
| 13 | to move if some legal move leaves a position losing for the opponent. |
| 14 | Isolated vertices may be retained: they permit no moves. |
| 15 | -/ |
| 16 | |
| 17 | namespace Lax689614.ArcKayles |
| 18 | |
| 19 | variable {V : Type} [DecidableEq V] |
| 20 | |
| 21 | /-- The position after playing an edge with endpoints `u` and `v`. -/ |
| 22 | def remove (S : Finset V) (u v : V) : Finset V := (S.erase u).erase v |
| 23 | |
| 24 | /-- Legal moves, represented by ordered pairs of endpoints. -/ |
| 25 | noncomputable def moves (G : SimpleGraph V) (S : Finset V) : Finset (V × V) := by |
| 26 | classical |
| 27 | exact (S ×ˢ S).filter fun e => G.Adj e.1 e.2 |
| 28 | |
| 29 | /-- Winning for the next player, by backward induction on surviving vertices. -/ |
| 30 | def Winning (G : SimpleGraph V) (S : Finset V) : Prop := |
| 31 | ∃ e : {e // e ∈ moves G S}, ¬ Winning G (remove S e.val.1 e.val.2) |
| 32 | termination_by S.card |
| 33 | decreasing_by |
| 34 | have h := e.property |
| 35 | simp only [moves, Finset.mem_filter, Finset.mem_product] at h |
| 36 | exact lt_of_le_of_lt Finset.card_erase_le (Finset.card_erase_lt_of_mem h.1.1) |
| 37 | |
| 38 | end Lax689614.ArcKayles |
| 39 |
Builds on
none
Discussion
Ask a question or add context. Endorsements and structured flags are kept in the review panel above.
0 comments