Preliminaries #
testBit #
@[simp]
theorem
Nat.ne_implies_bit_diff
{x : Nat}
{y : Nat}
(p : x ≠ y)
:
∃ (i : Nat), Nat.testBit x i ≠ Nat.testBit y i
theorem
Nat.eq_of_testBit_eq
{x : Nat}
{y : Nat}
(pred : ∀ (i : Nat), Nat.testBit x i = Nat.testBit y i)
:
x = y
eq_of_testBit_eq
allows proving two natural numbers are equal
if their bits are all equal.
testBit #
theorem
Nat.testBit_two_pow_add_eq
(x : Nat)
(i : Nat)
:
Nat.testBit (2 ^ i + x) i = !Nat.testBit x i
theorem
Nat.testBit_mul_two_pow_add_eq
(a : Nat)
(b : Nat)
(i : Nat)
:
Nat.testBit (2 ^ i * a + b) i = Bool.xor (decide (a % 2 = 1)) (Nat.testBit b i)
theorem
Nat.testBit_two_pow_add_gt
{i : Nat}
{j : Nat}
(j_lt_i : j < i)
(x : Nat)
:
Nat.testBit (2 ^ i + x) j = Nat.testBit x j
@[simp]
theorem
Nat.testBit_mod_two_pow
(x : Nat)
(j : Nat)
(i : Nat)
:
Nat.testBit (x % 2 ^ j) i = (decide (i < j) && Nat.testBit x i)
@[simp]
theorem
Nat.testBit_bool_to_nat
(b : Bool)
(i : Nat)
:
Nat.testBit (Bool.toNat b) i = (decide (i = 0) && b)
bitwise #
theorem
Nat.testBit_bitwise
{f : Bool → Bool → Bool}
(false_false_axiom : f false false = false)
(x : Nat)
(y : Nat)
(i : Nat)
:
Nat.testBit (Nat.bitwise f x y) i = f (Nat.testBit x i) (Nat.testBit y i)
bitwise #
and #
@[simp]
theorem
Nat.testBit_and
(x : Nat)
(y : Nat)
(i : Nat)
:
Nat.testBit (x &&& y) i = (Nat.testBit x i && Nat.testBit y i)
lor #
@[simp]
theorem
Nat.testBit_or
(x : Nat)
(y : Nat)
(i : Nat)
:
Nat.testBit (x ||| y) i = (Nat.testBit x i || Nat.testBit y i)
xor #
@[simp]
theorem
Nat.testBit_xor
(x : Nat)
(y : Nat)
(i : Nat)
:
Nat.testBit (x ^^^ y) i = Bool.xor (Nat.testBit x i) (Nat.testBit y i)
Arithmetic #
theorem
Nat.testBit_mul_pow_two_add
(a : Nat)
{b : Nat}
{i : Nat}
(b_lt : b < 2 ^ i)
(j : Nat)
:
Nat.testBit (2 ^ i * a + b) j = if j < i then Nat.testBit b j else Nat.testBit a (j - i)
theorem
Nat.testBit_mul_pow_two
{i : Nat}
{a : Nat}
{j : Nat}
:
Nat.testBit (2 ^ i * a) j = (decide (j ≥ i) && Nat.testBit a (j - i))
shiftLeft and shiftRight #
@[simp]
theorem
Nat.testBit_shiftLeft
{i : Nat}
{j : Nat}
(x : Nat)
:
Nat.testBit (x <<< i) j = (decide (j ≥ i) && Nat.testBit x (j - i))
@[simp]
theorem
Nat.testBit_shiftRight
{i : Nat}
{j : Nat}
(x : Nat)
:
Nat.testBit (x >>> i) j = Nat.testBit x (i + j)