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 : (b : Bool) → (n : ℕ) → C (Nat.bit b n)) (n : ℕ) => Nat.bitCasesOn n 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
.