Documentation

CombinatorialGames.Game.Classes

Classes of games #

This file collects multiple basic classes of games, so as to make them available on most files. We develop their theory elsewhere.

Dicotic games #

A game is dicotic when every non-zero subposition has both left and right moves. The lawnmower theorem (proven in CombinatorialGames.Game.Small) shows that every dicotic game is small.

Impartial games #

We define an impartial game as one where every subposition is equivalent to its negative. This is a weaker definition than that found in the literature (which requires equality, rather than equivalence), but this is still strong enough to prove the Sprague--Grundy theorem, as well as closure under the basic arithmetic operations of multiplication and division.

Numeric games #

A game is Numeric if all the Left options are strictly smaller than all the Right options, and all those options are themselves numeric. In terms of combinatorial games, the numeric games have "frozen"; you can only make your position worse by playing, and Left is some definite "number" of moves ahead (or behind) Right.

Short games #

A combinatorial game is Short if it has only finitely many subpositions. In particular, this means there is a finite set of moves at every point.

We historically defined Short x as data, which we then used to enable some degree of computation on combinatorial games. This functionality is now implemented through the game_cmp tactic instead.

Dicotic games #

class inductive IGame.Dicotic :

A game x is dicotic if both players can move from every nonempty subposition of x.

Instances
    theorem IGame.dicotic_def' (a✝ : IGame) :
    a✝.Dicotic ↔ (moves left a✝ = ∅ ↔ moves right a✝ = ∅) ∧ ∀ (p : Player), ∀ y ∈ moves p a✝, y.Dicotic
    theorem IGame.dicotic_def {x : IGame} :
    x.Dicotic ↔ (moves left x = ∅ ↔ moves right x = ∅) ∧ ∀ (p : Player), ∀ l ∈ moves p x, l.Dicotic
    theorem IGame.Dicotic.eq_zero_iff {x : IGame} [hx : x.Dicotic] :
    x = 0 ↔ ∃ (p : Player), moves p x = ∅
    theorem IGame.Dicotic.ne_zero_iff {x : IGame} [x.Dicotic] :
    x ≠ 0 ↔ ∀ (p : Player), (moves p x).Nonempty
    theorem IGame.Dicotic.of_mem_moves {x y : IGame} {p : Player} [hx : x.Dicotic] (h : y ∈ moves p x) :

    dicotic eagerly adds all possible Dicotic hypotheses.

    Equations
    Instances For
      @[irreducible]
      instance IGame.Dicotic.neg (x : IGame) [x.Dicotic] :
      @[irreducible]
      instance IGame.Dicotic.add (x y : IGame) [x.Dicotic] [y.Dicotic] :
      (x + y).Dicotic
      instance IGame.Dicotic.sub (x y : IGame) [x.Dicotic] [y.Dicotic] :
      (x + y).Dicotic
      instance IGame.Dicotic.nsmul (n : ℕ) (x : IGame) [x.Dicotic] :
      (n • x).Dicotic
      instance IGame.Dicotic.zsmul (n : ℤ) (x : IGame) [x.Dicotic] :
      (n • x).Dicotic

      Self-negative games #

      An auxiliary typeclass for games which are equivalent to their own negative. This allows us to generalize results about impartial games.

      • neg_equiv : -x ≈ x
      Instances
        @[simp]
        theorem IGame.NegSelfEquiv.sub_equiv (x y : IGame) [y.NegSelfEquiv] :
        x - y ≈ x + y
        theorem IGame.NegSelfEquiv.le_comm {x y : IGame} [hx : x.NegSelfEquiv] [hy : y.NegSelfEquiv] :
        x ≤ y ↔ y ≤ x
        theorem IGame.NegSelfEquiv.equiv_or_fuzzy (x y : IGame) [x.NegSelfEquiv] [y.NegSelfEquiv] :
        x ≈ y ∨ x ‖ y

        By setting y = 0, we find that in a self-negative game, either the first player always wins, or the second player always wins.

        @[simp]
        theorem IGame.NegSelfEquiv.not_equiv_iff {x y : IGame} [hx : x.NegSelfEquiv] [hy : y.NegSelfEquiv] :
        ¬x ≈ y ↔ x ‖ y
        @[simp]
        theorem IGame.NegSelfEquiv.not_fuzzy_iff {x y : IGame} [hx : x.NegSelfEquiv] [hy : y.NegSelfEquiv] :
        ¬x ‖ y ↔ x ≈ y
        @[simp]
        theorem IGame.NegSelfEquiv.le_iff_equiv {x y : IGame} [hx : x.NegSelfEquiv] [hy : y.NegSelfEquiv] :
        x ≤ y ↔ x ≈ y
        theorem IGame.NegSelfEquiv.ge_iff_equiv {x y : IGame} [hx : x.NegSelfEquiv] [hy : y.NegSelfEquiv] :
        y ≤ x ↔ x ≈ y
        theorem IGame.NegSelfEquiv.lf_iff_fuzzy {x y : IGame} [hx : x.NegSelfEquiv] [hy : y.NegSelfEquiv] :
        ¬y ≤ x ↔ x ‖ y
        theorem IGame.NegSelfEquiv.gf_iff_fuzzy {x y : IGame} [hx : x.NegSelfEquiv] [hy : y.NegSelfEquiv] :
        ¬x ≤ y ↔ x ‖ y
        theorem IGame.NegSelfEquiv.equiv_iff_add_equiv_zero {x y : IGame} [hy : y.NegSelfEquiv] :
        x ≈ y ↔ x + y ≈ 0

        This lemma doesn't require x to be self-negative.

        theorem IGame.NegSelfEquiv.equiv_iff_add_equiv_zero' {x y : IGame} [hx : x.NegSelfEquiv] :
        x ≈ y ↔ x + y ≈ 0

        This lemma doesn't require y to be self-negative.

        theorem IGame.NegSelfEquiv.fuzzy_iff_add_fuzzy_zero {x y : IGame} [hy : y.NegSelfEquiv] :
        x ‖ y ↔ x + y ‖ 0

        This lemma doesn't require x to be self-negative.

        theorem IGame.NegSelfEquiv.fuzzy_iff_add_fuzzy_zero' {x y : IGame} [hx : x.NegSelfEquiv] :
        x ‖ y ↔ x + y ‖ 0

        This lemma doesn't require y to be self-negative.

        "Weakly" impartial games #

        class inductive IGame.WeaklyImpartial :

        A weakly impartial game is one that's equivalent to its negative, such that each left and right move is also weakly impartial.

        This is more general than Impartial, since we don't require x = -x. Despite this, the Sprague-Grundy theorem still holds: see IGame.nim_grundy_equiv.

        In such a game, both players have the same payoffs at any subposition.

        Instances
          theorem IGame.weaklyImpartial_def' (a✝ : IGame) :
          a✝.WeaklyImpartial ↔ -a✝ ≈ a✝ ∧ ∀ (p : Player), ∀ y ∈ moves p a✝, y.WeaklyImpartial
          theorem IGame.weaklyImpartial_def {x : IGame} :
          x.WeaklyImpartial ↔ -x ≈ x ∧ ∀ (p : Player), ∀ y ∈ moves p x, y.WeaklyImpartial

          weakly_impartial eagerly adds all possible WeaklyImpartial hypotheses.

          Equations
          Instances For
            theorem IGame.WeaklyImpartial.equiv_iff_forall_fuzzy {x y : IGame} [x.WeaklyImpartial] [y.WeaklyImpartial] (p : Player) :
            x ≈ y ↔ (∀ z ∈ moves p x, z ‖ y) ∧ ∀ z ∈ moves (-p) y, x ‖ z
            theorem IGame.WeaklyImpartial.fuzzy_iff_exists_equiv {x y : IGame} [x.WeaklyImpartial] [y.WeaklyImpartial] (p : Player) :
            x ‖ y ↔ (∃ z ∈ moves p x, z ≈ y) ∨ ∃ z ∈ moves (-p) y, x ≈ z
            theorem IGame.WeaklyImpartial.equiv_zero {x : IGame} [x.WeaklyImpartial] (p : Player) :
            x ≈ 0 ↔ ∀ y ∈ moves p x, y ‖ 0
            theorem IGame.WeaklyImpartial.fuzzy_zero {x : IGame} [x.WeaklyImpartial] (p : Player) :
            x ‖ 0 ↔ ∃ y ∈ moves p x, y ≈ 0
            theorem IGame.WeaklyImpartial.fuzzy_zero_of_forall_exists {x y : IGame} [x.WeaklyImpartial] {p : Player} (hy : y ∈ moves p x) (H : ∀ z ∈ moves p y, ∃ w ∈ moves p x, z ≈ w) :
            x ‖ 0

            A strategy stealing argument. If there's a move in x, such that any immediate move could have also been reached in the first turn, then x is won by the first player.

            Impartial games #

            class inductive IGame.Impartial :

            An impartial game is one that's equal to its negative, such that each left and right move is also impartial.

            Note that many theorems hold under the WeaklyImpartial assumption, or the even weaker NegSelfEquiv assumption.

            Instances
              theorem IGame.impartial_def' (a✝ : IGame) :
              a✝.Impartial ↔ -a✝ = a✝ ∧ ∀ (p : Player), ∀ y ∈ moves p a✝, y.Impartial
              theorem IGame.impartial_def {x : IGame} :
              x.Impartial ↔ -x = x ∧ ∀ (p : Player), ∀ y ∈ moves p x, y.Impartial
              @[simp]
              theorem IGame.Impartial.neg_eq (x : IGame) [hx : x.Impartial] :
              -x = x
              theorem IGame.Impartial.of_mem_moves {p : Player} {x y : IGame} [h : x.Impartial] :
              y ∈ moves p x → y.Impartial

              impartial eagerly adds all possible Impartial hypotheses.

              Equations
              Instances For
                @[irreducible]
                @[irreducible]
                instance IGame.Impartial.add (x y : IGame) [x.Impartial] [y.Impartial] :
                (x + y).Impartial
                @[irreducible]
                instance IGame.Impartial.mul (x y : IGame) [x.Impartial] :
                (x * y).Impartial
                @[simp]
                theorem IGame.Impartial.neg_moves (x : IGame) [x.Impartial] (p : Player) :
                -moves p x = moves p x
                @[irreducible]

                Numeric games #

                class inductive IGame.Numeric :

                A game !{s | t} is numeric if everything in s is less than everything in t, and all the elements of these sets are also numeric.

                The Surreal numbers are built as the quotient of numeric games under equivalence.

                Instances
                  theorem IGame.numeric_def' (a✝ : IGame) :
                  a✝.Numeric ↔ (∀ y ∈ moves left a✝, ∀ z ∈ moves right a✝, y < z) ∧ ∀ (p : Player), ∀ y ∈ moves p a✝, y.Numeric
                  theorem IGame.numeric_def {x : IGame} :
                  x.Numeric ↔ (∀ y ∈ moves left x, ∀ z ∈ moves right x, y < z) ∧ ∀ (p : Player), ∀ y ∈ moves p x, y.Numeric
                  theorem IGame.Numeric.left_lt_right {x y z : IGame} [h : x.Numeric] (hy : y ∈ moves left x) (hz : z ∈ moves right x) :
                  y < z
                  theorem IGame.Numeric.of_mem_moves {x y : IGame} {p : Player} [h : x.Numeric] (hy : y ∈ moves p x) :

                  numeric eagerly adds all possible Numeric hypotheses.

                  Equations
                  Instances For
                    @[simp]
                    instance IGame.Numeric.moves {x : IGame} [x.Numeric] {p : Player} (y : ↑(moves p x)) :
                    (↑y).Numeric
                    theorem IGame.Numeric.le_of_not_le {x y : IGame} [x.Numeric] [y.Numeric] :
                    ¬x ≤ y → y ≤ x
                    theorem IGame.Numeric.le_total (x y : IGame) [x.Numeric] [y.Numeric] :
                    x ≤ y ∨ y ≤ x
                    theorem IGame.Numeric.lt_of_not_ge {x y : IGame} [x.Numeric] [y.Numeric] (h : ¬x ≤ y) :
                    y < x
                    @[simp]
                    theorem IGame.Numeric.not_le {x y : IGame} [x.Numeric] [y.Numeric] :
                    ¬x ≤ y ↔ y < x
                    @[simp]
                    theorem IGame.Numeric.not_lt {x y : IGame} [x.Numeric] [y.Numeric] :
                    ¬x < y ↔ y ≤ x
                    theorem IGame.Numeric.le_or_gt (x y : IGame) [x.Numeric] [y.Numeric] :
                    x ≤ y ∨ y < x
                    theorem IGame.Numeric.lt_or_ge (x y : IGame) [x.Numeric] [y.Numeric] :
                    x < y ∨ y ≤ x
                    theorem IGame.Numeric.not_fuzzy (x y : IGame) [x.Numeric] [y.Numeric] :
                    ¬x ‖ y
                    theorem IGame.Numeric.lt_or_equiv_or_gt (x y : IGame) [x.Numeric] [y.Numeric] :
                    x < y ∨ x ≈ y ∨ y < x
                    theorem IGame.Numeric.mk_of_lf {x : IGame} (h₁ : ∀ y ∈ moves left x, ∀ z ∈ moves right x, ¬z ≤ y) (h₂ : ∀ (p : Player), ∀ y ∈ moves p x, y.Numeric) :

                    To prove a game is numeric, it suffices to show the left options are less or fuzzy to the right options.

                    theorem IGame.Numeric.le_iff_forall_lt {x y : IGame} [x.Numeric] [y.Numeric] :
                    x ≤ y ↔ (∀ z ∈ moves left x, z < y) ∧ ∀ z ∈ moves right y, x < z
                    theorem IGame.Numeric.lt_iff_exists_le {x y : IGame} [x.Numeric] [y.Numeric] :
                    x < y ↔ (∃ z ∈ moves left y, x ≤ z) ∨ ∃ z ∈ moves right x, z ≤ y
                    theorem IGame.Numeric.left_lt {x y : IGame} [x.Numeric] (h : y ∈ moves left x) :
                    y < x
                    theorem IGame.Numeric.lt_right {x y : IGame} [x.Numeric] (h : y ∈ moves right x) :
                    x < y
                    @[irreducible]
                    instance IGame.Numeric.neg (x : IGame) [x.Numeric] :
                    @[irreducible]
                    instance IGame.Numeric.add (x y : IGame) [x.Numeric] [y.Numeric] :
                    (x + y).Numeric
                    instance IGame.Numeric.sub (x y : IGame) [x.Numeric] [y.Numeric] :
                    (x - y).Numeric
                    instance IGame.Numeric.nsmul (n : ℕ) (x : IGame) [x.Numeric] :
                    (n • x).Numeric
                    instance IGame.Numeric.zsmul (n : ℤ) (x : IGame) [x.Numeric] :
                    (n • x).Numeric
                    instance IGame.Numeric.natCast (n : ℕ) :
                    (↑n).Numeric
                    instance IGame.Numeric.intCast (n : ℤ) :
                    (↑n).Numeric

                    Short games #

                    class inductive IGame.Short :

                    A short game is one with finitely many subpositions. That is, the left and right sets are finite, and all of the games in them are short as well.

                    Instances
                      theorem IGame.short_def' (a✝ : IGame) :
                      a✝.Short ↔ (∀ (p : Player), (moves p a✝).Finite) ∧ ∀ (p : Player), ∀ y ∈ moves p a✝, y.Short
                      theorem IGame.short_def {x : IGame} :
                      x.Short ↔ ∀ (p : Player), (moves p x).Finite ∧ ∀ y ∈ moves p x, y.Short
                      theorem IGame.Short.mk {x : IGame} :
                      (∀ (p : Player), (moves p x).Finite ∧ ∀ y ∈ moves p x, y.Short) → x.Short

                      Alias of the reverse direction of IGame.short_def.

                      theorem IGame.Short.finite_moves (p : Player) (x : IGame) [h : x.Short] :
                      theorem IGame.Short.of_mem_moves {x y : IGame} [h : x.Short] {p : Player} (hy : y ∈ moves p x) :
                      theorem IGame.Short.subposition {x y : IGame} [x.Short] (h : y.Subposition x) :

                      short eagerly adds all possible Short hypotheses.

                      Equations
                      Instances For
                        @[simp]
                        @[simp]
                        @[irreducible]
                        instance IGame.Short.neg (x : IGame) [x.Short] :
                        (-x).Short
                        @[simp]
                        @[irreducible]
                        instance IGame.Short.add (x y : IGame) [x.Short] [y.Short] :
                        (x + y).Short
                        instance IGame.Short.sub (x y : IGame) [x.Short] [y.Short] :
                        (x - y).Short
                        instance IGame.Short.natCast (n : ℕ) :
                        (↑n).Short
                        instance IGame.Short.intCast (n : ℤ) :
                        (↑n).Short
                        @[irreducible]
                        instance IGame.Short.mul (x y : IGame) [x.Short] [y.Short] :
                        (x * y).Short
                        instance IGame.Short.mulOption (x y a b : IGame) [x.Short] [y.Short] [a.Short] [b.Short] :
                        (mulOption x y a b).Short