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 three definitions for the Grundy value. leftGrundy
and rightGrundy
are computed using
the left/right options of the game respectively, and are 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 leftGrundy
or rightGrundy
.
The Sprague-Grundy theorem 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 Grundy value of a game is recursively defined as the minimum excluded value (the infimum of the complement) of the left Grundy values of its left options.
This is an auxiliary definition for reasoning about games not yet known to be impartial. Use
Impartial.grundy
for an impartial game.
Equations
- x.leftGrundy = sInf (Set.range fun (y : ↑x.leftMoves) => (↑y).leftGrundy)ᶜ
Instances For
The right Grundy value of a game is recursively defined as the minimum excluded value (the infimum of the complement) of the right Grundy values of its 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
- x.rightGrundy = sInf (Set.range fun (y : ↑x.rightMoves) => (↑y).rightGrundy)ᶜ
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 leftGrundy
or rightGrundy
.
The lemmas leftGrundy_eq_grundy
and rightGrundy_eq_grundy
show that both definitions match in
the case of an impartial game.
Equations
Instances For
Alias of the reverse direction of IGame.Impartial.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.