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.
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โ
Instances For
div2 n = โn/2โ the greatest integer smaller than n/2
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
Instances For
Lean takes the unprimed name for Nat.shiftLeft_eq m n : m <<< n = m * 2 ^ n.
size n : Returns the size of a natural number in
bits i.e. the length of its binary representation
Instances For
bits n returns a list of Bools which correspond to the binary representation of n, where
the head of the list represents the least significant bit
Instances For
ldiff a b performs bitwise set difference. For each corresponding
pair of bits taken as Booleans, say aแตข and bแตข, it applies the
Boolean operation aแตข โง ยฌbแตข to obtain the iแตสฐ bit of the result.
Instances For
bitwise ops