Documentation

Mathlib.Data.Nat.BinaryRec

Binary recursion on Nat #

This file defines binary recursion on Nat.

Main results #

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

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 : Nat) :
    n >>> 1 = n / 2
    @[simp]
    @[simp]
    theorem Nat.bit_false :
    bit false = fun (x : Nat) => 2 * x
    @[simp]
    theorem Nat.bit_true :
    bit true = fun (x : Nat) => 2 * x + 1
    @[simp]
    theorem Nat.bit_false_apply (n : Nat) :
    bit false n = 2 * n
    @[simp]
    theorem Nat.bit_true_apply (n : Nat) :
    bit true n = 2 * n + 1
    @[simp]
    theorem Nat.bit_eq_zero_iff {n : Nat} {b : Bool} :
    bit b n = 0 n = 0 b = false
    theorem Nat.bit_ne_zero_iff {n : Nat} {b : Bool} :
    bit b n 0 n = 0b = true
    @[inline]
    def Nat.bitCasesOn {motive : NatSort u} (n : Nat) (bit : (b : Bool) → (n : Nat) → 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 : Nat} :
      bit b x < 2 ^ (n + 1) x < 2 ^ n
      theorem Nat.log2_eq_succ_log2_shiftRight {n : Nat} (hn : n >>> 1 0) :
      n.log2 = (n >>> 1).log2.succ
      @[specialize #[]]
      def Nat.binaryRec {motive : NatSort u} (zero : motive 0) (bit : (b : Bool) → (n : Nat) → motive nmotive (bit b n)) (n : Nat) :
      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 : NatSort u} (zero : motive 0) (bit : (b : Bool) → (n : Nat) → (n = 0b = true)motive nmotive (bit b n)) (n : Nat) :
        motive n

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

        Equations
        • One or more equations did not get rendered due to their size.
        Instances For
          @[specialize #[]]
          def Nat.binaryRecFromOne {motive : NatSort u} (zero : motive 0) (one : motive 1) (bit : (b : Bool) → (n : Nat) → n 0motive nmotive (bit b n)) (n : Nat) :
          motive n

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

          Equations
          • One or more equations did not get rendered due to their size.
          Instances For
            theorem Nat.bit_val (b : Bool) (n : Nat) :
            bit b n = 2 * n + b.toNat
            @[simp]
            theorem Nat.bit_div_two (b : Bool) (n : Nat) :
            bit b n / 2 = n
            @[simp]
            theorem Nat.bit_mod_two (b : Bool) (n : Nat) :
            bit b n % 2 = b.toNat
            @[simp]
            theorem Nat.bit_shiftRight_one (b : Bool) (n : Nat) :
            bit b n >>> 1 = n
            theorem Nat.testBit_bit_zero (b : Bool) (n : Nat) :
            (bit b n).testBit 0 = b
            @[simp]
            theorem Nat.bitCasesOn_bit {motive : NatSort u} (h : (b : Bool) → (n : Nat) → motive (bit b n)) (b : Bool) (n : Nat) :
            bitCasesOn (bit b n) h = h b n
            @[simp]
            theorem Nat.binaryRec_zero {motive : NatSort u} (zero : motive 0) (bit : (b : Bool) → (n : Nat) → motive nmotive (bit b n)) :
            binaryRec zero bit 0 = zero
            @[simp]
            theorem Nat.binaryRec_one {motive : NatSort u} (zero : motive 0) (bit : (b : Bool) → (n : Nat) → motive nmotive (bit b n)) :
            binaryRec zero bit 1 = bit true 0 zero
            theorem Nat.binaryRec_eq {motive : NatSort u} {zero : motive 0} {bit : (b : Bool) → (n : Nat) → motive nmotive (bit b n)} (b : Bool) (n : Nat) (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 : NatSort u} (zero : motive 0) (bit : (b : Bool) → (n : Nat) → (n = 0b = true)motive nmotive (bit b n)) :
            binaryRec' zero bit 0 = zero
            @[simp]
            theorem Nat.binaryRec'_one {motive : NatSort u} (zero : motive 0) (bit : (b : Bool) → (n : Nat) → (n = 0b = true)motive nmotive (bit b n)) :
            theorem Nat.binaryRec'_eq {motive : NatSort u} {zero : motive 0} {bit : (b : Bool) → (n : Nat) → (n = 0b = true)motive nmotive (bit b n)} (b : Bool) (n : Nat) (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 : NatSort u} (zero : motive 0) (one : motive 1) (bit : (b : Bool) → (n : Nat) → n 0motive nmotive (bit b n)) :
            binaryRecFromOne zero one bit 0 = zero
            @[simp]
            theorem Nat.binaryRecFromOne_one {motive : NatSort u} {zero : motive 0} {one : motive 1} (bit : (b : Bool) → (n : Nat) → n 0motive nmotive (bit b n)) :
            binaryRecFromOne zero one bit 1 = one
            theorem Nat.binaryRecFromOne_eq {motive : NatSort u} {zero : motive 0} {one : motive 1} {bit : (b : Bool) → (n : Nat) → n 0motive nmotive (bit b n)} (b : Bool) (n : Nat) (h : n 0) :
            binaryRecFromOne zero one bit (Nat.bit b n) = bit b n h (binaryRecFromOne zero one bit n)