Documentation

Mathlib.SetTheory.Nimber.Basic

Nimbers #

The goal of this file is to define the nimbers, constructed as ordinals endowed with new arithmetical operations. The nim sum a + b is recursively defined as the least ordinal not equal to any a' + b or a + b' for a' < a and b' < b. There is also a nim product, defined in the Mathlib/SetTheory/Nimber/Field.lean file.

Nim addition arises within the context of impartial games. By the Sprague-Grundy theorem, each impartial game is equivalent to some game of nim. If x ≈ nim o₁ and y ≈ nim o₂, then x + y ≈ nim (o₁ + o₂), where the ordinals are summed together as nimbers. Unfortunately, the nim product admits no such characterization.

Notation #

Following [On Numbers And Games][conway2001] (p. 121), we define notation ∗o for the cast from Ordinal to Nimber. Note that for general n : ℕ, ∗n is not the same as ↑n. For instance, ∗2 ≠ 0, whereas ↑2 = ↑1 + ↑1 = 0.

Implementation notes #

The nimbers inherit the order from the ordinals - this makes working with minimum excluded values much more convenient. However, the fact that nimbers are of characteristic 2 prevents the order from interacting with the arithmetic in any nice way.

To reduce API duplication, we opt not to implement operations on Nimber on Ordinal. The order isomorphisms Ordinal.toNimber and Nimber.toOrdinal allow us to cast between them whenever needed.

Basic casts between Ordinal and Nimber #

def Nimber :
Type (u_1 + 1)

A type synonym for ordinals with nimber addition and multiplication.

Equations
    Instances For
      Equations
        Equations
          @[match_pattern]

          The identity function between Ordinal and Nimber.

          Equations
            Instances For
              @[match_pattern]

              The identity function between Nimber and Ordinal.

              Equations
                Instances For

                  The identity function between Ordinal and Nimber.

                  Equations
                    Instances For
                      theorem Nimber.lt_wf :
                      WellFounded fun (x1 x2 : Nimber) => x1 < x2
                      @[simp]
                      @[simp]
                      @[simp]
                      @[simp]
                      @[simp]
                      def Nimber.rec {β : NimberSort u_1} (h : (a : Ordinal.{u_2}) → β (Ordinal.toNimber a)) (a : Nimber) :
                      β a

                      A recursor for Nimber. Use as induction x.

                      Equations
                        Instances For
                          theorem Nimber.induction {p : NimberProp} (i : Nimber) :
                          (∀ (j : Nimber), (∀ k < j, p k)p j)p i

                          Ordinal.induction but for Nimber.

                          theorem Nimber.le_zero {a : Nimber} :
                          a 0 a = 0
                          theorem Nimber.lt_one_iff_zero {a : Nimber} :
                          a < 1 a = 0
                          theorem Nimber.eq_nat_of_le_nat {a : Nimber} {b : } (h : a Ordinal.toNimber b) :
                          ∃ (c : ), a = Ordinal.toNimber c

                          Nimber addition #

                          @[irreducible]
                          def Nimber.add (a b : Nimber) :

                          Nimber addition is recursively defined so that a + b is the smallest nimber not equal to a' + b or a + b' for a' < a and b' < b.

                          Equations
                            Instances For
                              Equations
                                theorem Nimber.add_def (a b : Nimber) :
                                a + b = sInf {x : Nimber | (∃ a' < a, a' + b = x) b' < b, a + b' = x}
                                theorem Nimber.exists_of_lt_add {a b c : Nimber} (h : c < a + b) :
                                (∃ a' < a, a' + b = c) b' < b, a + b' = c
                                theorem Nimber.add_le_of_forall_ne {a b c : Nimber} (h₁ : a' < a, a' + b c) (h₂ : b' < b, a + b' c) :
                                a + b c
                                @[irreducible]
                                theorem Nimber.add_comm (a b : Nimber) :
                                a + b = b + a
                                @[irreducible]
                                theorem Nimber.add_eq_zero {a b : Nimber} :
                                a + b = 0 a = b
                                theorem Nimber.add_ne_zero_iff {a b : Nimber} :
                                a + b 0 a b
                                @[simp]
                                theorem Nimber.add_self (a : Nimber) :
                                a + a = 0
                                @[irreducible]
                                theorem Nimber.add_assoc (a b c : Nimber) :
                                a + b + c = a + (b + c)
                                @[irreducible]
                                theorem Nimber.add_zero (a : Nimber) :
                                a + 0 = a
                                theorem Nimber.zero_add (a : Nimber) :
                                0 + a = a
                                Equations
                                  @[simp]
                                  theorem Nimber.neg_eq (a : Nimber) :
                                  -a = a
                                  @[simp]
                                  theorem Nimber.add_cancel_right (a b : Nimber) :
                                  a + b + b = a
                                  @[simp]
                                  theorem Nimber.add_cancel_left (a b : Nimber) :
                                  a + (a + b) = b
                                  theorem Nimber.add_trichotomy {a b c : Nimber} (h : a + b + c 0) :
                                  b + c < a c + a < b a + b < c
                                  theorem Nimber.lt_add_cases {a b c : Nimber} (h : a < b + c) :
                                  a + c < b a + b < c
                                  @[irreducible]

                                  Nimber addition of naturals corresponds to the bitwise XOR operation.