Saturating binary decoding #
Words are read most significant bit first. Saturating at every step keeps a unary accumulator bounded on arbitrary input words; it agrees with capping the full mathematical binary value.
Main definitions #
binaryValue: the natural represented by a binary word, without a size bound.boundedBinaryValue: the same fold with a cap at every step.binaryWord: the word of a given width representing a number.lowBits: a fixed-width word in the opposite, least-significant-first order.
Main results #
binaryValue_injective_of_length_eq: fixed-width words have distinct binary values.boundedBinaryValue_eq: incremental saturation equals a single final cap.boundedBinaryValue_le: every output is at most the cap.binaryValue_lt_two_pow,exists_binaryValue_eq: the words oftbits represent exactly the numbers below2 ^ t.length_binaryWord,binaryValue_binaryWord: the word of widthtof a number below2 ^ t.
References #
Adapted from Probability/UniformNat.lean on the cslib crypto branch at
5ff69ca93402e7c947208dc56396d6d86203ccd8.
The first width digits of a natural, least significant first. Unlike binaryWord, this
always has the declared width: high digits are truncated and absent digits are false.
Instances For
The natural number represented by a word, most significant bit first.
Instances For
Saturating at each step agrees with capping the final mathematical value.
The unary result never exceeds the declared bound.
Append a low-order bit to a most-significant-first binary word.
Reversing the little-endian digits gives the corresponding most-significant-first value.
An all-one binary word represents one less than the corresponding power of two.
A word of n bits represents a number below 2 ^ n.
Leading zeros do not change the represented number.
The word of width w representing a in binary, most significant bit first, padded with
leading zeros; it has width w when a < 2 ^ w (length_binaryWord).
Instances For
The word of width w representing a has w bits when a < 2 ^ w.
The word binaryWord w a represents a, whatever the width w.
Every number below 2 ^ t is represented by a word of t bits.
Fixed-width binary words represent their values injectively.