Documentation

CslibFrontier.Languages.Probabilistic.UniformNat.Residue

Binary samples as canonical residues #

sampleBinaryNat w reads w fair bits as a natural number below 2 ^ w. These are exactly the canonical representatives ZMod.val of the residues modulo 2 ^ w, so the sampler draws the canonical representative of a uniform residue. Repeating it lists the representatives of a uniform residue vector, in coordinate order, and repeating those runs lists the rows of a uniform residue matrix. Every count and the width may be zero; at width zero every sample is 0, the only representative modulo 1.

For a positive modulus q, reducing each of count samples modulo q gives a vector within statistical distance count * (q / 2 ^ w) of uniform.

Main results #

An unsigned w-bit sample is the canonical representative of a uniform residue modulo 2 ^ w.

theorem Cslib.ProbComp.eval_replicate_sampleBinaryNat (count w : ℕ) :
eval (OracleComp.replicate count (sampleBinaryNat w)) = PMF.map (fun (x : Fin count → ZMod (2 ^ w)) => List.ofFn fun (j : Fin count) => (x j).val) (Probability.PMF.uniformOfFintype (Fin count → ZMod (2 ^ w)))

count independent unsigned w-bit samples list the canonical representatives of a uniform residue vector modulo 2 ^ w.

theorem Cslib.ProbComp.eval_replicate_replicate_sampleBinaryNat (rows cols w : ℕ) :
eval (OracleComp.replicate rows (OracleComp.replicate cols (sampleBinaryNat w))) = PMF.map (fun (A : Matrix (Fin rows) (Fin cols) (ZMod (2 ^ w))) => List.ofFn fun (i : Fin rows) => List.ofFn fun (j : Fin cols) => (A i j).val) (Probability.PMF.uniformOfFintype (Matrix (Fin rows) (Fin cols) (ZMod (2 ^ w))))

rows independent lists of cols unsigned w-bit samples list, row by row, the canonical representatives of a uniform rows × cols residue matrix modulo 2 ^ w.

A bounded modular sample is already the canonical representative of its residue.

theorem Cslib.ProbComp.dist_replicateFin_sampleModNat_le (count width q : ℕ) [NeZero q] :
dist (eval (OracleComp.replicateFin count (Nat.cast <$> sampleModNat width q))) (Probability.PMF.uniformOfFintype (Fin count → ZMod q)) ≤ ↑count * (↑q / 2 ^ width)

Reducing independent binary samples modulo q approximates a uniform residue vector. The statistical error is at most the sum of the one-coordinate errors.

theorem Cslib.ProbComp.closeTo_replicate_sampleModIndex (count width q : ℕ) [NeZero q] :
Probability.CloseTo (PMF.map (fun (v : Fin count → ZMod q) => List.ofFn fun (j : Fin count) => (v j).val) (Probability.PMF.uniformOfFintype (Fin count → ZMod q))) (eval (OracleComp.replicate count (sampleModIndex width q))) (↑count * ↑q / 2 ^ width)

The list of unary residues produced by independent bounded samplers approximates the canonical representatives of a uniform vector, with error at most count * q / 2 ^ width on every event.

theorem Cslib.ProbComp.exists_vector_of_mem_support_replicate_sampleModIndex {count width q : ℕ} [NeZero q] {xs : List ℕ} (hx : xs ∈ (eval (OracleComp.replicate count (sampleModIndex width q))).support) :
∃ (v : Fin count → ZMod q), xs = List.ofFn fun (j : Fin count) => (v j).val

Every supported list of modular samples consists of the canonical representatives of a residue vector of the requested dimension.

theorem Cslib.ProbComp.closeTo_replicate_sampleModIndex_precision (count q precision : ℕ) [NeZero q] :
Probability.CloseTo (PMF.map (fun (v : Fin count → ZMod q) => List.ofFn fun (j : Fin count) => (v j).val) (Probability.PMF.uniformOfFintype (Fin count → ZMod q))) (eval (OracleComp.replicate count (sampleModIndex (count.size + q.size + precision) q))) (1 / 2 ^ precision)

Using the bit lengths of the count and modulus plus precision bits per sample gives statistical error at most 2 ^ (-precision) for the whole list.