The Mathlib Handbook

The volumes of the handbook are not written yet. This site shows the map of Mathlib that they will follow, at Mathlib 4472534b60.

The areas / V02. Numbers

Mathlib.Data.Nat.BinaryRec

31 declarations. Mathlib docs · Source

def Nat.bit E1 #

Bool → ℕ → ℕ

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

theorem Nat.shiftRight_one E1 #

∀ (n : ℕ), n >>> 1 = n / 2

theorem Nat.bit_decide_mod_two_eq_one_shiftRight_one E0 #

∀ (n : ℕ), Nat.bit (decide (n % 2 = 1)) (n >>> 1) = n

theorem Nat.bit_testBit_zero_shiftRight_one E1 #

∀ (n : ℕ), Nat.bit (n.testBit 0) (n >>> 1) = n

theorem Nat.bit_false E0 #

Nat.bit false = fun x ↦ 2 * x

theorem Nat.bit_true E0 #

Nat.bit true = fun x ↦ 2 * x + 1

theorem Nat.bit_false_apply E0 #

∀ (n : ℕ), Nat.bit false n = 2 * n

theorem Nat.bit_true_apply E0 #

∀ (n : ℕ), Nat.bit true n = 2 * n + 1

theorem Nat.bit_eq_zero_iff E0 #

∀ {n : ℕ} {b : Bool}, Nat.bit b n = 0 ↔ n = 0 ∧ b = false

theorem Nat.bit_ne_zero_iff E0 #

∀ {n : ℕ} {b : Bool}, Nat.bit b n ≠ 0 ↔ n = 0 → b = true

def Nat.bitCasesOn E1 #

{motive : ℕ → Sort u} → (n : ℕ) → ((b : Bool) → (n : ℕ) → motive (Nat.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.

theorem Nat.bit_lt_two_pow_succ_iff E0 #

∀ {b : Bool} {x n : ℕ}, Nat.bit b x < 2 ^ (n + 1) ↔ x < 2 ^ n

theorem Nat.log2_eq_succ_log2_shiftRight E1 #

∀ {n : ℕ}, n >>> 1 ≠ 0 → n.log2 = (n >>> 1).log2.succ

def Nat.binaryRec E1 #

{motive : ℕ → Sort u} → motive 0 → ((b : Bool) → (n : ℕ) → motive n → motive (Nat.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.

def Nat.binaryRec' E1 #

{motive : ℕ → Sort u} →
  motive 0 → ((b : Bool) → (n : ℕ) → (n = 0 → b = true) → motive n → motive (Nat.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

def Nat.binaryRecFromOne E1 #

{motive : ℕ → Sort u} →
  motive 0 → motive 1 → ((b : Bool) → (n : ℕ) → n ≠ 0 → motive n → motive (Nat.bit b n)) → (n : ℕ) → motive n

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

theorem Nat.bit_val E0 #

∀ (b : Bool) (n : ℕ), Nat.bit b n = 2 * n + b.toNat

theorem Nat.bit_div_two E0 #

∀ (b : Bool) (n : ℕ), Nat.bit b n / 2 = n

theorem Nat.bit_mod_two E0 #

∀ (b : Bool) (n : ℕ), Nat.bit b n % 2 = b.toNat

theorem Nat.bit_shiftRight_one E0 #

∀ (b : Bool) (n : ℕ), Nat.bit b n >>> 1 = n

theorem Nat.testBit_bit_zero E1 #

∀ (b : Bool) (n : ℕ), (Nat.bit b n).testBit 0 = b

theorem Nat.bitCasesOn_bit E0 #

∀ {motive : ℕ → Sort u} (h : (b : Bool) → (n : ℕ) → motive (Nat.bit b n)) (b : Bool) (n : ℕ),
  Nat.bitCasesOn (Nat.bit b n) h = h b n

theorem Nat.binaryRec_zero E0 #

∀ {motive : ℕ → Sort u} (zero : motive 0) (bit : (b : Bool) → (n : ℕ) → motive n → motive (Nat.bit b n)),
  Nat.binaryRec zero bit 0 = zero

theorem Nat.binaryRec_one E0 #

∀ {motive : ℕ → Sort u} (zero : motive 0) (bit : (b : Bool) → (n : ℕ) → motive n → motive (Nat.bit b n)),
  Nat.binaryRec zero bit 1 = bit true 0 zero

theorem Nat.binaryRec_eq E0 #

∀ {motive : ℕ → Sort u} {zero : motive 0} {bit : (b : Bool) → (n : ℕ) → motive n → motive (Nat.bit b n)} (b : Bool)
  (n : ℕ),
  bit false 0 zero = zero ∨ (n = 0 → b = true) →
    Nat.binaryRec zero bit (Nat.bit b n) = bit b n (Nat.binaryRec zero bit n)

theorem Nat.binaryRec'_zero E0 #

∀ {motive : ℕ → Sort u} (zero : motive 0)
  (bit : (b : Bool) → (n : ℕ) → (n = 0 → b = true) → motive n → motive (Nat.bit b n)), Nat.binaryRec' zero bit 0 = zero

theorem Nat.binaryRec'_one E0 #

∀ {motive : ℕ → Sort u} (zero : motive 0)
  (bit : (b : Bool) → (n : ℕ) → (n = 0 → b = true) → motive n → motive (Nat.bit b n)),
  Nat.binaryRec' zero bit 1 = bit true 0 Nat.binaryRec'_one._proof_1 zero

theorem Nat.binaryRec'_eq E0 #

∀ {motive : ℕ → Sort u} {zero : motive 0}
  {bit : (b : Bool) → (n : ℕ) → (n = 0 → b = true) → motive n → motive (Nat.bit b n)} (b : Bool) (n : ℕ)
  (h : n = 0 → b = true), Nat.binaryRec' zero bit (Nat.bit b n) = bit b n h (Nat.binaryRec' zero bit n)

theorem Nat.binaryRecFromOne_zero E0 #

∀ {motive : ℕ → Sort u} (zero : motive 0) (one : motive 1)
  (bit : (b : Bool) → (n : ℕ) → n ≠ 0 → motive n → motive (Nat.bit b n)), Nat.binaryRecFromOne zero one bit 0 = zero

theorem Nat.binaryRecFromOne_one E0 #

∀ {motive : ℕ → Sort u} {zero : motive 0} {one : motive 1}
  (bit : (b : Bool) → (n : ℕ) → n ≠ 0 → motive n → motive (Nat.bit b n)), Nat.binaryRecFromOne zero one bit 1 = one

theorem Nat.binaryRecFromOne_eq E0 #

∀ {motive : ℕ → Sort u} {zero : motive 0} {one : motive 1}
  {bit : (b : Bool) → (n : ℕ) → n ≠ 0 → motive n → motive (Nat.bit b n)} (b : Bool) (n : ℕ) (h : n ≠ 0),
  Nat.binaryRecFromOne zero one bit (Nat.bit b n) = bit b n h (Nat.binaryRecFromOne zero one bit n)