Bitwise operations on natural numbers #
In the first half of this file, we provide theorems for reasoning about natural numbers from their
bitwise properties. In the second half of this file, we show properties of the bitwise operations
lor, land and xor, which are defined in core.
Main results #
- eq_of_testBit_eq: two natural numbers are equal if they have equal bits at every position.
- exists_most_significant_bit: if- n ≠ 0, then there is some position- ithat contains the most significant- 1-bit of- n.
- lt_of_testBit: if- nand- mare numbers and- iis a position such that the- i-th bit of of- nis zero, the- i-th bit of- mis one, and all more significant bits are equal, then- n < m.
Future work #
There is another way to express bitwise properties of natural number: digits 2. The two ways
should be connected.
Keywords #
bitwise, and, or, xor
An alternative for bitwise_bit which replaces the f false false = false assumption
with assumptions that neither bit a m nor bit b n are 0
(albeit, phrased as the implications m = 0 → a = true and n = 0 → b = true)
The ith bit is the ith element of n.bits.
Bitwise extensionality: Two numbers agree if they agree at every bit position.
If f is a commutative operation on bools such that f false false = false, then bitwise f
is also commutative.
Proving associativity of bitwise operations in general essentially boils down to a huge case distinction, so it is shorter to use this tactic instead of proving it in the general case.
Equations
- Nat.tacticBitwise_assoc_tac = Lean.ParserDescr.node `Nat.tacticBitwise_assoc_tac 1024 (Lean.ParserDescr.nonReservedSymbol "bitwise_assoc_tac" false)