Documentation

CslibFrontier.Languages.Probabilistic.IntBox

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 #

Main results #

References #

One-dimensional integer-box sampler #

Shift a nonnegative residue u < 2 * B + 1 into the symmetric interval [-B, B].

Deterministic coin-to-residue map underlying ProbComp.sampleModNat.

Deterministic coin-to-box map for the symmetric integer interval [-B, B].

theorem Cslib.Probability.abs_boxShift_mod_le (B u : ℕ) :
|boxShift B (u % (2 * B + 1))| ≤ ↑B

Shifting a residue modulo 2 * B + 1 by -B stays within [-B, B].

theorem Cslib.Probability.natAbs_boxShift_mod_le (B u : ℕ) :
(boxShift B (u % (2 * B + 1))).natAbs ≤ B

Shifting a residue modulo 2 * B + 1 by -B has natAbs at most 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.

noncomputable def Cslib.Probability.sampleIntBox (B width : ℕ) :

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.

theorem Cslib.Probability.abs_le_of_mem_support_sampleIntBox {B width : ℕ} {z : ℤ} (hz : z ∈ (sampleIntBox B width).eval.support) :
|z| ≤ ↑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.

theorem Cslib.Probability.mem_Icc_of_mem_support_sampleIntBox {B width : ℕ} {z : ℤ} (hz : z ∈ (sampleIntBox B width).eval.support) :
z ∈ Finset.Icc (-↑B) ↑B

The support of sampleIntBox B width is contained in Finset.Icc (-B) B.

noncomputable def Cslib.Probability.uniformBox1D (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.

theorem Cslib.Probability.eval_sampleIntBox_eq_map_zmod (B width : ℕ) :
(sampleIntBox B width).eval = PMF.map (fun (r : ZMod (2 * B + 1)) => boxShift B r.val) (PMF.map Nat.cast (ProbComp.sampleModNat width (2 * B + 1)).eval)

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.

View a list of integers as a vector in Fin m → ℤ, padding missing entries with 0.

@[simp]
theorem Cslib.Probability.vecOfList_ofFn {m : ℕ} (v : Fin 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.

@[simp]
theorem Cslib.Probability.length_sampleIntBoxListCoins (B m width : ℕ) (coins : List Bool) :
(sampleIntBoxListCoins B m width coins).length = m
def Cslib.Probability.sampleIntBoxVecCoins (B m width : ℕ) (coins : List Bool) :
Fin m → ℤ

Deterministic coin-to-vector sampler for intBox (Fin m) B = [-B, B]^m.

theorem Cslib.Probability.sampleIntBoxVecCoins_mem_intBox (B m width : ℕ) (coins : List Bool) :
sampleIntBoxVecCoins B m width coins ∈ intBox (Fin m) B

Every coin string maps into intBox (Fin m) B under sampleIntBoxVecCoins B m width.

noncomputable def Cslib.Probability.sampleIntBoxList (B m width : ℕ) :

Sample a list of m independent integers in [-B, B], each using width fair bits.

noncomputable def Cslib.Probability.sampleIntBoxVec (B m width : ℕ) :
ProbComp (Fin m → ℤ)

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.

theorem Cslib.Probability.mem_intBox_of_mem_support_sampleIntBoxVec {B m width : ℕ} {z : Fin m → ℤ} (hz : z ∈ (sampleIntBoxVec B m width).eval.support) :
z ∈ intBox (Fin m) B

Every vector in the support of sampleIntBoxVec B m width lies in intBox (Fin m) B.

Exact dyadic centered integer-box sampler #

Deterministic coin-to-integer map for the dyadic half-range [-2 ^ (width - 1), 2 ^ width - 1 - 2 ^ (width - 1)].

Sample an integer uniformly from the dyadic range [0, 2 ^ width - 1] - 2 ^ (width - 1).

noncomputable def Cslib.Probability.uniformDyadicIntBox (width : ℕ) :

The exact uniform distribution on the dyadic centered range [0, 2 ^ width - 1] - 2 ^ (width - 1).