Bitwise operations on natural numbers #
THIS FILE IS SYNCHRONIZED WITH MATHLIB4. Any changes to this file require a corresponding PR to mathlib4.
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 lxor, which are defined in core.
Main results #
- eq_of_test_bit_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_test_bit: 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
    
theorem
nat.bitwise_comm
    {f : bool → bool → bool}
    (hf : ∀ (b b' : bool), f b b' = f b' b)
    (hf' : f bool.ff bool.ff = bool.ff)
    (n m : ℕ) :
nat.bitwise f n m = nat.bitwise f m n
If f is a commutative operation on bools such that f ff ff = ff, then bitwise f is also
commutative.