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
#
theorem
Nat.bit_cases_on_injective
{C : ℕ → Sort u}
:
Function.Injective fun H 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.binaryRec_eq'
{C : ℕ → Sort u_1}
{z : C 0}
{f : (b : Bool) → (n : ℕ) → C n → C (Nat.bit b n)}
(b : Bool)
(n : ℕ)
(h : f false 0 z = z ∨ (n = 0 → b = 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 = 0 → b = true) → C n → C (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
- Nat.binaryRec' z f = Nat.binaryRec z fun b n ih => if h : n = 0 → b = true then f b n h ih else Eq.mpr (_ : C (Nat.bit b n) = C 0) (id z)