Documentation

Mathlib.Data.Nat.Bits

Additional properties of binary recursion on Nat #

This file documents additional properties of binary recursion, which allows us to more easily work with operations which do depend on the number of leading zeros in the binary representation of n. For example, we can more easily work with Nat.bits and Nat.size.

See also: Nat.bitwise, Nat.pow (for various lemmas about size and shiftLeft/shiftRight), and Nat.digits.

boddDiv2_eq and bodd #

@[simp]
@[simp]
theorem Nat.bodd_bit0 (n : ) :
@[simp]
theorem Nat.bodd_bit1 (n : ) :
@[simp]
theorem Nat.div2_bit0 (n : ) :
@[simp]
theorem Nat.div2_bit1 (n : ) :

bit0 and bit1 #

@[simp]
theorem Nat.bit0_eq_bit0 {m : } {n : } :
bit0 m = bit0 n m = n
@[simp]
theorem Nat.bit1_eq_bit1 {m : } {n : } :
bit1 m = bit1 n m = n
@[simp]
theorem Nat.bit1_eq_one {n : } :
bit1 n = 1 n = 0
@[simp]
theorem Nat.one_eq_bit1 {n : } :
1 = bit1 n n = 0
theorem Nat.bit_add (b : Bool) (n : ) (m : ) :
Nat.bit b (n + m) = Nat.bit false n + Nat.bit b m
theorem Nat.bit_add' (b : Bool) (n : ) (m : ) :
Nat.bit b (n + m) = Nat.bit b n + Nat.bit false m
theorem Nat.bit_ne_zero (b : Bool) {n : } (h : n 0) :
Nat.bit b n 0
theorem Nat.bit0_mod_two {n : } :
bit0 n % 2 = 0
theorem Nat.bit1_mod_two {n : } :
bit1 n % 2 = 1
theorem Nat.pos_of_bit0_pos {n : } (h : 0 < bit0 n) :
0 < n
@[simp]
theorem Nat.bitCasesOn_bit {C : Sort u} (H : (b : Bool) → (n : ) → C (Nat.bit b n)) (b : Bool) (n : ) :
Nat.bitCasesOn (Nat.bit b n) H = H b n
@[simp]
theorem Nat.bitCasesOn_bit0 {C : Sort u} (H : (b : Bool) → (n : ) → C (Nat.bit b n)) (n : ) :
@[simp]
theorem Nat.bitCasesOn_bit1 {C : Sort u} (H : (b : Bool) → (n : ) → C (Nat.bit b n)) (n : ) :
theorem Nat.bit_cases_on_injective {C : Sort u} :
Function.Injective fun (H : (b : Bool) → (n : ) → C (Nat.bit b n)) (n : ) => Nat.bitCasesOn n H
@[simp]
theorem Nat.bit_cases_on_inj {C : Sort u} (H₁ : (b : Bool) → (n : ) → C (Nat.bit b n)) (H₂ : (b : Bool) → (n : ) → C (Nat.bit b n)) :
((fun (n : ) => Nat.bitCasesOn n H₁) = fun (n : ) => Nat.bitCasesOn n H₂) H₁ = H₂
theorem Nat.bit0_eq_zero {n : } :
bit0 n = 0 n = 0
theorem Nat.bit_eq_zero_iff {n : } {b : Bool} :
Nat.bit b n = 0 n = 0 b = false
theorem Nat.binaryRec_eq' {C : Sort u_1} {z : C 0} {f : (b : Bool) → (n : ) → C nC (Nat.bit b n)} (b : Bool) (n : ) (h : f false 0 z = z (n = 0b = true)) :
Nat.binaryRec z f (Nat.bit b n) = f b n (Nat.binaryRec z f n)

The same as binaryRec_eq, but that one unfortunately requires f to be the identity when appending false to 0. Here, we allow you to explicitly say that that case is not happening, i.e. supplying n = 0 → b = true.

def Nat.binaryRec' {C : Sort u_1} (z : C 0) (f : (b : Bool) → (n : ) → (n = 0b = true)C nC (Nat.bit b n)) (n : ) :
C n

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

Equations
Instances For
    def Nat.binaryRecFromOne {C : Sort u_1} (z₀ : C 0) (z₁ : C 1) (f : (b : Bool) → (n : ) → n 0C nC (Nat.bit b n)) (n : ) :
    C n

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

    Equations
    Instances For
      @[simp]
      theorem Nat.zero_bits :
      Nat.bits 0 = []
      @[simp]
      theorem Nat.bits_append_bit (n : ) (b : Bool) (hn : n = 0b = true) :
      @[simp]
      theorem Nat.bit0_bits (n : ) (hn : n 0) :
      @[simp]
      @[simp]