Fair-bit samplers for integer intervals and boxes #
Sampling the integer box [-B, B]^m, of odd cardinality (2 * B + 1)^m, from a fixed number of
fair bits is approximate. sampleIntBox B width reduces width fair bits modulo 2 * B + 1
(ProbComp.sampleModNat) and shifts the residue by -B (boxShift). Every sample lies in
[-B, B], and the law factors through the residue sampler, so its distance from the exact uniform
law uniformBox1D B is the residue sampler's. sampleIntBoxList and sampleIntBoxVec draw m
independent coordinates; their exact counterpart is the uniform law on
Cslib.Probability.intBox (Fin m) B. The dyadic centered range
[-2 ^ (width - 1), 2 ^ width - 1 - 2 ^ (width - 1)] has power-of-two size and is sampled
exactly by sampleDyadicIntBox width.
Each sampler comes with a deterministic coin map, such as sampleIntBoxCoins, whose pushforward
of uniform fair bits is the sampler's law. The statistical-distance bounds are in
CslibFrontier.Crypto.Game.CloseTo.IntBox and the strict-PPT certificates in
CslibFrontier.Computability.Probabilistic.IntBox.
Main definitions #
Cslib.Probability.boxShift,Cslib.Probability.sampleIntBoxCoins,Cslib.Probability.sampleIntBox: the 1D shift, coin map and sampler for[-B, B].Cslib.Probability.sampleIntBoxListCoins,Cslib.Probability.sampleIntBoxVecCoins,Cslib.Probability.sampleIntBoxList,Cslib.Probability.sampleIntBoxVec:m-coordinate coin maps and samplers for[-B, B]^m.Cslib.Probability.sampleDyadicIntBoxCoins,Cslib.Probability.sampleDyadicIntBox: the exact dyadic centered sampler.Cslib.Probability.uniformBox1D,Cslib.Probability.uniformDyadicIntBox: the exact uniform laws on[-B, B]and on the dyadic centered range.Cslib.Probability.vecOfList: read a list of integers as a vector, padding with0.
Main results #
Cslib.Probability.eval_sampleIntBox_eq_coins,Cslib.Probability.eval_sampleIntBoxList_eq_coins,Cslib.Probability.eval_sampleIntBoxVec_eq_coins: each law is the pushforward of uniform fair bits by its coin map.Cslib.Probability.abs_le_of_mem_support_sampleIntBox,Cslib.Probability.mem_intBox_of_mem_support_sampleIntBoxVec: every sample lies in the box.Cslib.Probability.eval_sampleIntBoxVec_eq_iid,Cslib.Probability.eval_sampleIntBoxList_eq_map_ofFn: the vector sampler has the independent product law, and the list sampler is its list form.Cslib.Probability.eval_sampleIntBox_eq_map_zmod,Cslib.Probability.iid_uniformBox1D: the factorization throughZMod (2 * B + 1)and the product form of the uniform box law.Cslib.Probability.eval_sampleDyadicIntBox: the dyadic sampler is exact.
References #
One-dimensional integer-box sampler #
Shift a nonnegative residue u < 2 * B + 1 into the symmetric interval [-B, B].
Every coin string maps into [-B, B] under sampleIntBoxCoins B.
Every coin string maps to an integer of natAbs at most B under sampleIntBoxCoins B.
Sample an integer in [-B, B] using width fair bits reduced modulo 2 * B + 1.
The evaluation law of sampleIntBox B width is the pushforward of width uniform fair bits by
sampleIntBoxCoins B.
Every integer in the support of sampleIntBox B width has absolute value at most B.
Every integer in the support of sampleIntBox B width has natAbs at most B.
The support of sampleIntBox B width is contained in Finset.Icc (-B) B.
The exact uniform distribution on the 1D integer interval [-B, B].
Shifting the uniform distribution on ZMod (2 * B + 1) by -B gives uniformBox1D B.
sampleIntBox B width factors through ZMod (2 * B + 1) via boxShift B ∘ ZMod.val.
Multi-coordinate integer-box samplers #
m independent draws from uniformBox1D B form the uniform distribution on the integer box
intBox (Fin m) B = [-B, B]^m.
Deterministic coin-to-list sampler for [-B, B]^m, slicing m * width bits into m rows of
width bits and mapping each row by sampleIntBoxCoins B.
Every coin string maps into intBox (Fin m) B under sampleIntBoxVecCoins B m width.
Sample a vector in Fin m → ℤ with m independent coordinates from sampleIntBox B width.
sampleIntBoxList B m width has the same distribution as applying sampleIntBoxListCoins to
m * width uniform fair bits.
sampleIntBoxVec B m width has the same distribution as applying sampleIntBoxVecCoins to
m * width uniform fair bits.
sampleIntBoxVec B m width has the m-fold independent product law iid.
The list sampler is the vector sampler read as a list: sampleIntBoxList B m width has the
law of List.ofFn applied to sampleIntBoxVec B m width.
Every vector in the support of sampleIntBoxVec B m width lies in intBox (Fin m) B.
Exact dyadic centered integer-box sampler #
Sample an integer uniformly from the dyadic range [0, 2 ^ width - 1] - 2 ^ (width - 1).
The exact uniform distribution on the dyadic centered range
[0, 2 ^ width - 1] - 2 ^ (width - 1).
sampleDyadicIntBox width has the exact law uniformDyadicIntBox width.