Exact Fisher–Yates Uniform Permutation Batch Sampler #
This module implements a strict probabilistic polynomial-time (Cslib.Probability.IsPPTOn)
4 * n + 4-step Fisher–Yates rejection batch fyBatch n i perm and proves:
- Exact uniformity target (
fisherYatesTarget_zero): running Fisher–Yates from(0, 1)yieldsPMF.uniformOfFintype (Equiv.Perm (Fin n)). - Support preservation (
fyBatch_support): every supported output offyBatch n i (permOfEquiv π)is a valid permutation state(i', permOfEquiv π')withi' ≤ n. - Exact harmonicity (
fyBatch_harmonic):fisherYatesTarget nis harmonic underfyBatch n, so repeatingfyBatchin a Las Vegas loop preserves exact uniformity without bias. - Constant-probability completion (
fyBatch_retry_le_half): from any partial statei ≤ n, a single4 * n + 4-step batch fails to complete (i' < n) with probability at most1 / 2(proved via the potential function $\Phi(i) = 2^{n - i} \cdot \mathbf{1}_{i < n}$). - Strict PPT certificate (
isPPTOn_fyBatch):fyBatchis realized in strict probabilistic polynomial time on native multi-tape fair-coin Turing machines.
Main definitions #
Cslib.Probability.permOfEquiv: list representationList.ofFn (fun u => (π u).val)ofπ : Equiv.Perm (Fin n).Cslib.Probability.listSwap: computable index swap onList ℕ.Cslib.Probability.encPermList: list of unary-encoded natural numbers.Cslib.Probability.fisherYatesTarget: exact Fisher–Yates continuation distribution.Cslib.Probability.fyBatch:4 * n + 4-step strict-PPT Fisher–Yates batch.
Main results #
Cslib.Probability.fisherYatesTarget_zero: exact uniformity onEquiv.Perm (Fin n).Cslib.Probability.fyBatch_support: preservation of valid permutation states(i, permOfEquiv π).Cslib.Probability.fyBatch_harmonic: harmonicity offisherYatesTargetunderfyBatch.Cslib.Probability.fyBatch_retry_le_half: probability ofi' < nis at most2⁻¹.Cslib.Probability.isPPTOn_fyBatch:IsPPTOncertificate forfyBatch.
1. List representation of permutations and computable swaps #
List representation of π : Equiv.Perm (Fin n) as [π(0), π(1), ..., π(n - 1)].
permOfEquiv has length n.
permOfEquiv 1 = List.range n.
permOfEquiv is injective on Equiv.Perm (Fin n).
listSwap on permOfEquiv π corresponds to right multiplication by Equiv.swap i j.
2. Exact Fisher–Yates continuation target and uniformity #
Exact Fisher–Yates continuation distribution from position i and current permutation π.
Evaluation of fisherYatesTarget at i < n.
Evaluation of fisherYatesTarget at n ≤ i.
Exact uniformity of Fisher–Yates: fisherYatesTarget n 0 1 is the uniform distribution on
Equiv.Perm (Fin n).
3. The 4 * n + 4-step strict-PPT Fisher–Yates batch #
4. Support invariant, harmonicity, and retry-probability bound ≤ 1 / 2 #
fyBatch support invariant: applying fyBatch n to a valid state (i, permOfEquiv π)
with i ≤ n only produces valid states (i', permOfEquiv π') with i' ≤ n.
Harmonicity of fisherYatesTarget under fyBatch: applying fyBatch n to a valid state
(i, permOfEquiv π) preserves the exact continuation law fisherYatesTarget n i π.
Retry probability bound: after one 4 * n + 4-step batch fyBatch n i perm, the
probability that step' < n is at most 2⁻¹ for every n, i : ℕ and perm.
Strict PPT certificate for fyBatch: sampling the 4 * n + 4-step Fisher–Yates batch on
inputs (n, i, perm) is IsPPTOn.