Documentation

CombinatorialGames.Game.Specific.Nim

Nim and the Sprague-Grundy theorem #

In the game of nim o, for o an ordinal number, both players may move to nim a for any a < o.

We also define a Grundy value for an impartial game x and prove the Sprague-Grundy theorem, that x is equivalent to nim (grundy x). Finally, we prove that the grundy value of a sum x + y corresponds to the nimber sum of the individual grundy values.

Nim game #

@[irreducible]
noncomputable def IGame.nim (o : Nimber) :

The definition of single-heap nim, which can be viewed as a pile of stones where each player can take a positive number of stones from it on their turn.

Equations
  • One or more equations did not get rendered due to their size.
Instances For
    theorem IGame.forall_leftMoves_nim {P : IGameProp} {o : Nimber} :
    (∀ x(nim o).leftMoves, P x) a < o, P (nim a)
    theorem IGame.forall_rightMoves_nim {P : IGameProp} {o : Nimber} :
    (∀ x(nim o).rightMoves, P x) a < o, P (nim a)
    theorem IGame.exists_leftMoves_nim {P : IGameProp} {o : Nimber} :
    (∃ x(nim o).leftMoves, P x) a < o, P (nim a)
    theorem IGame.exists_rightMoves_nim {P : IGameProp} {o : Nimber} :
    (∃ x(nim o).rightMoves, P x) a < o, P (nim a)
    theorem IGame.forall_leftMoves_nim_natCast {P : IGameProp} {n : } :
    (∀ x(nim (Ordinal.toNimber n)).leftMoves, P x) m < n, P (nim (Ordinal.toNimber m))
    theorem IGame.forall_rightMoves_nim_natCast {P : IGameProp} {n : } :
    (∀ x(nim (Ordinal.toNimber n)).rightMoves, P x) m < n, P (nim (Ordinal.toNimber m))
    theorem IGame.exists_leftMoves_nim_natCast {P : IGameProp} {n : } :
    (∃ x(nim (Ordinal.toNimber n)).leftMoves, P x) m < n, P (nim (Ordinal.toNimber m))
    theorem IGame.exists_rightMoves_nim_natCast {P : IGameProp} {n : } :
    (∃ x(nim (Ordinal.toNimber n)).rightMoves, P x) m < n, P (nim (Ordinal.toNimber m))
    theorem IGame.forall_leftMoves_nim_ofNat {P : IGameProp} {n : } [n.AtLeastTwo] :
    (∀ x(nim (Ordinal.toNimber (OfNat.ofNat n))).leftMoves, P x) m < n, P (nim (Ordinal.toNimber m))
    theorem IGame.forall_rightMoves_nim_ofNat {P : IGameProp} {n : } [n.AtLeastTwo] :
    (∀ x(nim (Ordinal.toNimber (OfNat.ofNat n))).rightMoves, P x) m < n, P (nim (Ordinal.toNimber m))
    theorem IGame.exists_leftMoves_nim_ofNat {P : IGameProp} {n : } [n.AtLeastTwo] :
    (∃ x(nim (Ordinal.toNimber (OfNat.ofNat n))).leftMoves, P x) m < n, P (nim (Ordinal.toNimber m))
    theorem IGame.exists_rightMoves_nim_ofNat {P : IGameProp} {n : } [n.AtLeastTwo] :
    (∃ x(nim (Ordinal.toNimber (OfNat.ofNat n))).rightMoves, P x) m < n, P (nim (Ordinal.toNimber m))
    @[simp]
    theorem IGame.nim_inj {a b : Nimber} :
    nim a = nim b a = b
    @[simp]
    theorem IGame.nim_zero :
    nim 0 = 0
    @[simp]
    theorem IGame.nim_one :
    @[simp, irreducible]
    theorem IGame.birthday_nim (o : Nimber) :
    (nim o).birthday = o
    @[simp, irreducible]
    theorem IGame.neg_nim (o : Nimber) :
    -nim o = nim o
    @[irreducible]
    @[simp]
    theorem IGame.nim_equiv_iff {a b : Nimber} :
    nim anim b a = b
    @[simp]
    theorem IGame.nim_fuzzy_iff {a b : Nimber} :
    nim anim b a b
    @[irreducible]
    theorem IGame.nim_add_equiv (a b : Nimber) :
    nim a + nim bnim (a + b)

    Grundy value #

    @[irreducible]
    noncomputable def IGame.Impartial.grundy (x : IGame) :

    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 either its left or right options.

    This is the nimber which corresponds to the game of nim that the game is equivalent to.

    Equations
    Instances For

      This version is stated in terms of left moves of x.

      This version is stated in terms of left moves of x.

      This version is stated in terms of left moves of x.

      This version is stated in terms of left moves of x.

      theorem IGame.Impartial.grundy_ne {x y : IGame} (hy : y x.leftMoves) :

      This version is stated in terms of left moves of x.

      @[irreducible]

      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.

      @[simp]
      @[simp]

      This version is stated in terms of right moves of x.

      This version is stated in terms of right moves of x.

      This version is stated in terms of right moves of x.

      This version is stated in terms of right moves of x.

      This version is stated in terms of right moves of x.