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.bits_eq_nil_iff: a natural has no binary digits exactly when it is zero.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_one_ne_zero,Nat.bits_foldr_bit_one,Nat.foldr_bit_one_lt: reconstruction with base value1, producing a positive number whose binary digits end intrue.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.
Folding Nat.bit with base 1 over any word gives a positive number.
Reading enough low-order digits recovers the natural, including its leading zero digits.