Binary recursion on Nat #
This file defines binary recursion on Nat.
Main results #
Nat.binaryRec: A recursion principle forbitrepresentations of natural numbers.Nat.binaryRec': The same asbinaryRec, but the induction step can assume that ifn=0, the bit being appended istrue.Nat.binaryRecFromOne: The same asbinaryRec, but special casing both 0 and 1 as base cases.
bit b appends the digit b to the little end of the binary representation of
its natural number input.
Instances For
@[simp]
theorem
Nat.bit_decide_mod_two_eq_one_shiftRight_one
(n : ℕ)
:
bit (decide (n % 2 = 1)) (n >>> 1) = n
@[simp]
@[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.
Instances For
@[simp]
@[specialize #[]]
def
Nat.binaryRec
{motive : ℕ → Sort u}
(zero : motive 0)
(bit : (b : Bool) → (n : ℕ) → motive n → motive (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.
Instances For
@[specialize #[]]
def
Nat.binaryRec'
{motive : ℕ → Sort u}
(zero : motive 0)
(bit : (b : Bool) → (n : ℕ) → (n = 0 → b = true) → motive n → motive (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
Instances For
@[specialize #[]]
def
Nat.binaryRecFromOne
{motive : ℕ → Sort u}
(zero : motive 0)
(one : motive 1)
(bit : (b : Bool) → (n : ℕ) → n ≠ 0 → motive n → motive (bit b n))
(n : ℕ)
:
motive n
The same as binaryRec, but special casing both 0 and 1 as base cases
Instances For
@[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 n → motive (bit b n))
:
binaryRec zero bit 0 = zero
@[simp]
theorem
Nat.binaryRec_one
{motive : ℕ → Sort u}
(zero : motive 0)
(bit : (b : Bool) → (n : ℕ) → motive n → motive (bit b n))
:
binaryRec zero bit 1 = bit true 0 zero
@[simp]
theorem
Nat.binaryRec'_zero
{motive : ℕ → Sort u}
(zero : motive 0)
(bit : (b : Bool) → (n : ℕ) → (n = 0 → b = true) → motive n → motive (bit b n))
:
binaryRec' zero bit 0 = zero
@[simp]
theorem
Nat.binaryRec'_one
{motive : ℕ → Sort u}
(zero : motive 0)
(bit : (b : Bool) → (n : ℕ) → (n = 0 → b = true) → motive n → motive (bit b n))
:
binaryRec' zero bit 1 = bit true 0 binaryRec'_one._proof_1 zero
theorem
Nat.binaryRec'_eq
{motive : ℕ → Sort u}
{zero : motive 0}
{bit : (b : Bool) → (n : ℕ) → (n = 0 → b = true) → motive n → motive (bit b n)}
(b : Bool)
(n : ℕ)
(h : n = 0 → b = 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 ≠ 0 → motive n → motive (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 ≠ 0 → motive n → motive (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 ≠ 0 → motive n → motive (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)