Grundy value #
The Grundy value of an impartial game is recursively defined as the least nimber not among the Grundy values of either its left or right options. This map respects addition and multiplication.
We provide two definitions for the Grundy value. grundyFor is computed using either the left or
right options of the game, and is defined for all games. To make the API symmetric, we also provide
Impartial.grundy, which enforces that the game is impartial, and is thus equal to either of
grundyFor left or grundyFor right.
The Sprague-Grundy theorem Impartial.nim_grundy_equiv shows that any impartial game is
equivalent to a game of Nim, namely that corresponding to its Grundy value.
Grundy value #
The left or right Grundy value of a game is recursively defined as the minimum excluded value (the infimum of the complement) of the left or right Grundy values of its left or right options.
This is an auxiliary definition for reasoning about games not yet known to be impartial. Use
Impartial.grundy for an impartial game.
Equations
- IGame.grundyFor p x = sInf (Set.range fun (y : ↑(IGame.moves p x)) => IGame.grundyFor p ↑y)ᶜ
Instances For
The Grundy value of an impartial game is recursively defined as the minimum excluded value (the infimum of the complement) of the Grundy values of its options.
This definition enforces that x is impartial. If you want to talk about the left or right Grundy
values of a game (e.g. if you don't yet know it to be impartial), use grundyFor.
The lemma grundyFor_eq_grundy shows that both definitions match in
the case of an impartial game.
Equations
Instances For
The Sprague-Grundy theorem states that every impartial game is equivalent to a game of nim, namely the game of nim for the game's Grundy value.
Alias of the reverse direction of IGame.grundy_eq_iff_equiv_nim.
If a game x has only impartial options, and its left Grundy value equals its right Grundy
value, then it's impartial.