Bounded binary indices #
A uniform binary word decodes to a uniform finite index. Capping it puts all excess mass at one sentinel. A power-of-two range above any bound is at most twice the bound plus two, including the zero case.
Main definitions #
Cslib.Probability.dyadicSize: a power-of-two sampling range strictly above a bound.
Main results #
Cslib.BitString.uniformList_binaryValue: exact uniformity of binary decoding.Cslib.BitString.uniformList_boundedBinaryValue: the capped distribution.Cslib.Probability.uniformFin_decide_lt: the exact probability of an index threshold.
References #
Adapted from Probability/UniformNat.lean on the cslib crypto branch at
5ff69ca93402e7c947208dc56396d6d86203ccd8.
A power-of-two sampling range strictly larger than the supplied bound.
Instances For
The sampling range is positive, including at zero.
Even at zero, the sampler draws at least one fair bit.
The sampling range dyadicSize bound is nonzero.
Every index at most the original bound lies in the dyadic range.
Rounding up to a power of two increases the range by at most a factor of two.
Applying the rounding operation to a power-of-two range doubles it.
The sampling range grows only linearly with its bound.
The dyadic range has a bounded unary implementation via the binary decoder.
Comparing a uniform finite index with a threshold samples the corresponding capped fraction.
Binary decoding identifies fair bit strings with uniform finite indices.
A capped uniform index can be sampled using exactly k fair bits.