Recovering a natural number from its binary digits #
The digits returned by Nat.bits are least significant first. Folding Nat.bit from the right
with initial value zero reconstructs the original number.
Main results #
Nat.foldr_bit_bits: foldingNat.bitover the binary representation ofngivesn.Nat.foldr_bit_lt,Nat.foldr_bit_testBit: fixed-width little-endian reconstruction.Nat.foldr_bit_ofFn: reconstruction is the sum of the digits' binary place values.Nat.size_div_two_add_one: halving a positive number removes one binary digit.
@[simp]
Folding Nat.bit over the binary representation of n gives back n.
A little-endian word represents a natural below the power of two given by its length.
Reading enough low-order digits recovers the natural, including its leading zero digits.