Documentation

Mathlib.Data.Nat.BinaryRec

Binary recursion on Nat #

This file defines binary recursion on Nat.

Main results #

def Nat.bit (b : Bool) (n : ) :

bit b appends the digit b to the little end of the binary representation of its natural number input.

Equations
    Instances For
      theorem Nat.shiftRight_one (n : ) :
      n >>> 1 = n / 2
      @[simp]
      theorem Nat.bit_false :
      bit false = fun (x : ) => 2 * x
      @[simp]
      theorem Nat.bit_true :
      bit true = fun (x : ) => 2 * x + 1
      @[simp]
      theorem Nat.bit_false_apply (n : ) :
      bit false n = 2 * n
      @[simp]
      theorem Nat.bit_true_apply (n : ) :
      bit true n = 2 * n + 1
      @[simp]
      theorem Nat.bit_eq_zero_iff {n : } {b : Bool} :
      bit b n = 0 n = 0 b = false
      theorem Nat.bit_ne_zero_iff {n : } {b : Bool} :
      bit b n 0 n = 0b = true
      @[inline]
      def Nat.bitCasesOn {motive : Sort u} (n : ) (bit : (b : Bool) → (n : ) → motive (bit b n)) :
      motive n

      For a predicate motive : Nat → Sort u, if instances can be constructed for natural numbers of the form bit b n, they can be constructed for any given natural number.

      Equations
        Instances For
          @[simp]
          theorem Nat.bit_lt_two_pow_succ_iff {b : Bool} {x n : } :
          bit b x < 2 ^ (n + 1) x < 2 ^ n
          theorem Nat.log2_eq_succ_log2_shiftRight {n : } (hn : n >>> 1 0) :
          n.log2 = (n >>> 1).log2.succ
          @[specialize #[]]
          def Nat.binaryRec {motive : Sort u} (zero : motive 0) (bit : (b : Bool) → (n : ) → motive nmotive (bit b n)) (n : ) :
          motive n

          A recursion principle for bit representations of natural numbers. For a predicate motive : Nat → Sort u, if instances can be constructed for natural numbers of the form bit b n, they can be constructed for all natural numbers.

          Equations
            Instances For
              @[specialize #[]]
              def Nat.binaryRec' {motive : Sort u} (zero : motive 0) (bit : (b : Bool) → (n : ) → (n = 0b = true)motive nmotive (bit b n)) (n : ) :
              motive n

              The same as binaryRec, but the induction step can assume that if n=0, the bit being appended is true

              Equations
                Instances For
                  @[specialize #[]]
                  def Nat.binaryRecFromOne {motive : Sort u} (zero : motive 0) (one : motive 1) (bit : (b : Bool) → (n : ) → n 0motive nmotive (bit b n)) (n : ) :
                  motive n

                  The same as binaryRec, but special casing both 0 and 1 as base cases

                  Equations
                    Instances For
                      theorem Nat.bit_val (b : Bool) (n : ) :
                      bit b n = 2 * n + b.toNat
                      @[simp]
                      theorem Nat.bit_div_two (b : Bool) (n : ) :
                      bit b n / 2 = n
                      @[simp]
                      theorem Nat.bit_mod_two (b : Bool) (n : ) :
                      bit b n % 2 = b.toNat
                      @[simp]
                      theorem Nat.bit_shiftRight_one (b : Bool) (n : ) :
                      bit b n >>> 1 = n
                      theorem Nat.testBit_bit_zero (b : Bool) (n : ) :
                      (bit b n).testBit 0 = b
                      @[simp]
                      theorem Nat.bitCasesOn_bit {motive : Sort u} (h : (b : Bool) → (n : ) → motive (bit b n)) (b : Bool) (n : ) :
                      bitCasesOn (bit b n) h = h b n
                      @[simp]
                      theorem Nat.binaryRec_zero {motive : Sort u} (zero : motive 0) (bit : (b : Bool) → (n : ) → motive nmotive (bit b n)) :
                      binaryRec zero bit 0 = zero
                      @[simp]
                      theorem Nat.binaryRec_one {motive : Sort u} (zero : motive 0) (bit : (b : Bool) → (n : ) → motive nmotive (bit b n)) :
                      binaryRec zero bit 1 = bit true 0 zero
                      theorem Nat.binaryRec_eq {motive : Sort u} {zero : motive 0} {bit : (b : Bool) → (n : ) → motive nmotive (bit b n)} (b : Bool) (n : ) (h : bit false 0 zero = zero (n = 0b = true)) :
                      binaryRec zero bit (Nat.bit b n) = bit b n (binaryRec zero bit n)
                      @[simp]
                      theorem Nat.binaryRec'_zero {motive : Sort u} (zero : motive 0) (bit : (b : Bool) → (n : ) → (n = 0b = true)motive nmotive (bit b n)) :
                      binaryRec' zero bit 0 = zero
                      @[simp]
                      theorem Nat.binaryRec'_one {motive : Sort u} (zero : motive 0) (bit : (b : Bool) → (n : ) → (n = 0b = true)motive nmotive (bit b n)) :
                      theorem Nat.binaryRec'_eq {motive : Sort u} {zero : motive 0} {bit : (b : Bool) → (n : ) → (n = 0b = true)motive nmotive (bit b n)} (b : Bool) (n : ) (h : n = 0b = true) :
                      binaryRec' zero bit (Nat.bit b n) = bit b n h (binaryRec' zero bit n)
                      @[simp]
                      theorem Nat.binaryRecFromOne_zero {motive : Sort u} (zero : motive 0) (one : motive 1) (bit : (b : Bool) → (n : ) → n 0motive nmotive (bit b n)) :
                      binaryRecFromOne zero one bit 0 = zero
                      @[simp]
                      theorem Nat.binaryRecFromOne_one {motive : Sort u} {zero : motive 0} {one : motive 1} (bit : (b : Bool) → (n : ) → n 0motive nmotive (bit b n)) :
                      binaryRecFromOne zero one bit 1 = one
                      theorem Nat.binaryRecFromOne_eq {motive : Sort u} {zero : motive 0} {one : motive 1} {bit : (b : Bool) → (n : ) → n 0motive nmotive (bit b n)} (b : Bool) (n : ) (h : n 0) :
                      binaryRecFromOne zero one bit (Nat.bit b n) = bit b n h (binaryRecFromOne zero one bit n)