Lemmas about bitwise operations on natural numbers. #
Possibly only of archaeological significance.
boddDiv2 n
returns a 2-tuple of type (Bool,Nat)
where the Bool
value indicates whether n
is odd or not
and the Nat
value returns ⌊n/2⌋
Equations
- Nat.boddDiv2 0 = (false, 0)
- Nat.boddDiv2 (Nat.succ n) = match Nat.boddDiv2 n with | (false, m) => (true, m) | (true, m) => (false, Nat.succ m)
Instances For
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 (Nat.succ n) = Nat.bit b (Nat.shiftLeft' b m n)
Instances For
@[simp]
Std4 takes the unprimed name for Nat.shiftLeft_eq m n : m <<< n = m * 2 ^ n
.
def
Nat.binaryRec
{C : ℕ → Sort u}
(z : C 0)
(f : (b : Bool) → (n : ℕ) → C n → C (Nat.bit b n))
(n : ℕ)
:
C n
A recursion principle for bit
representations of natural numbers.
For a predicate C : Nat → Sort*
, if instances can be
constructed for natural numbers of the form bit b n
,
they can be constructed for all natural numbers.
Equations
- Nat.binaryRec z f n = if n0 : n = 0 then Eq.mpr ⋯ z else let n' := Nat.div2 n; let_fun _x := ⋯; Eq.mpr ⋯ (f (Nat.bodd n) n' (Nat.binaryRec z f n'))
Instances For
@[simp]
theorem
Nat.binaryRec_zero
{C : ℕ → Sort u}
(z : C 0)
(f : (b : Bool) → (n : ℕ) → C n → C (Nat.bit b n))
:
Nat.binaryRec z f 0 = z
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
theorem
Nat.testBit_bit_succ
(m : ℕ)
(b : Bool)
(n : ℕ)
:
Nat.testBit (Nat.bit b n) (Nat.succ m) = Nat.testBit n m
theorem
Nat.binaryRec_eq
{C : ℕ → Sort u}
{z : C 0}
{f : (b : Bool) → (n : ℕ) → C n → C (Nat.bit b n)}
(h : f false 0 z = z)
(b : Bool)
(n : ℕ)
:
Nat.binaryRec z f (Nat.bit b n) = f b n (Nat.binaryRec z f n)