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
.
shiftLeft' b m n
performs a left shift of m
n
times
and adds the bit b
as the least significant bit each time.
Returns the corresponding natural number
Equations
- Nat.shiftLeft' b m 0 = m
- Nat.shiftLeft' b m n.succ = Nat.bit b (Nat.shiftLeft' b m n)
Instances For
@[simp]
Lean takes the unprimed name for Nat.shiftLeft_eq m n : m <<< n = m * 2 ^ n
.
bitwise ops
theorem
Nat.shiftLeft'_add
(b : Bool)
(m : ℕ)
(n : ℕ)
(k : ℕ)
:
Nat.shiftLeft' b m (n + k) = Nat.shiftLeft' b (Nat.shiftLeft' b m n) k
theorem
Nat.shiftLeft'_sub
(b : Bool)
(m : ℕ)
{n : ℕ}
{k : ℕ}
:
k ≤ n → Nat.shiftLeft' b m (n - k) = Nat.shiftLeft' b m n >>> k
boddDiv2_eq
and bodd
#
bit0
and bit1
#
theorem
Nat.bit_cases_on_injective
{motive : ℕ → Sort u}
:
Function.Injective fun (H : (b : Bool) → (n : ℕ) → motive (Nat.bit b n)) (n : ℕ) => Nat.bitCasesOn n H