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 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 (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
    @[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
          @[simp]
          theorem Nimber.toOrdinal_toNimber (a : Nimber) :
          Ordinal.toNimber (Nimber.toOrdinal a) = a
          theorem Nimber.lt_wf :
          WellFounded fun (x1 x2 : Nimber) => x1 < x2
          @[simp]
          @[simp]
          theorem Nimber.toOrdinal_zero :
          Nimber.toOrdinal 0 = 0
          @[simp]
          theorem Nimber.toOrdinal_one :
          Nimber.toOrdinal 1 = 1
          @[simp]
          theorem Nimber.toOrdinal_eq_zero {a : Nimber} :
          Nimber.toOrdinal a = 0 a = 0
          @[simp]
          theorem Nimber.toOrdinal_eq_one {a : Nimber} :
          Nimber.toOrdinal a = 1 a = 1
          @[simp]
          theorem Nimber.toOrdinal_max (a b : Nimber) :
          Nimber.toOrdinal (a b) = Nimber.toOrdinal a Nimber.toOrdinal b
          @[simp]
          theorem Nimber.toOrdinal_min (a b : Nimber) :
          Nimber.toOrdinal (a b) = Nimber.toOrdinal a Nimber.toOrdinal b
          theorem Nimber.succ_def (a : Nimber) :
          Order.succ a = Ordinal.toNimber (Nimber.toOrdinal a + 1)
          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
            Equations
            • =
            Equations
            • =
            instance Nimber.small_Ico (a b : Nimber) :
            Equations
            • =
            instance Nimber.small_Icc (a b : Nimber) :
            Equations
            • =
            instance Nimber.small_Ioo (a b : Nimber) :
            Equations
            • =
            instance Nimber.small_Ioc (a b : Nimber) :
            Equations
            • =
            @[simp]
            theorem Ordinal.toNimber_toOrdinal (a : Ordinal.{u_1}) :
            Nimber.toOrdinal (Ordinal.toNimber a) = a
            @[simp]
            theorem Ordinal.toNimber_zero :
            Ordinal.toNimber 0 = 0
            @[simp]
            theorem Ordinal.toNimber_one :
            Ordinal.toNimber 1 = 1
            @[simp]
            theorem Ordinal.toNimber_eq_zero {a : Ordinal.{u_1}} :
            Ordinal.toNimber a = 0 a = 0
            @[simp]
            theorem Ordinal.toNimber_eq_one {a : Ordinal.{u_1}} :
            Ordinal.toNimber a = 1 a = 1
            @[simp]
            theorem Ordinal.toNimber_max (a b : Ordinal.{u_1}) :
            Ordinal.toNimber (a b) = Ordinal.toNimber a Ordinal.toNimber b
            @[simp]
            theorem Ordinal.toNimber_min (a b : Ordinal.{u_1}) :
            Ordinal.toNimber (a b) = Ordinal.toNimber a Ordinal.toNimber b

            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
              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
              Equations
              • One or more equations did not get rendered due to their size.
              @[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]
              theorem Nimber.add_nat (a b : ) :
              Ordinal.toNimber a + Ordinal.toNimber b = Ordinal.toNimber (a ^^^ b)

              Nimber addition of naturals corresponds to the bitwise XOR operation.