Documentation

Complexity.Probability.UniformNat

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 #

Main results #

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.

    theorem Cslib.Probability.lt_dyadicSize (bound : ℕ) :
    bound < dyadicSize bound

    Every index at most the original bound lies in the dyadic range.

    theorem Cslib.Probability.dyadicSize_le (bound : ℕ) :
    dyadicSize bound ≤ 2 * (bound + 1)

    Rounding up to a power of two increases the range by at most a factor of two.

    @[simp]

    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.

    theorem Cslib.Probability.uniformFin_decide_lt (size threshold : ℕ) [NeZero size] :
    (PMF.map (fun (i : Fin size) => decide (↑i < threshold)) (PMF.uniformOfFintype (Fin size))) true = ↑(min size threshold) / ↑size

    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.