Documentation

CslibFrontier.Computability.PropertyTesting.Distribution.IdentityReduction

Identity testing by reduction to uniformity #

Testing identity to a fixed distribution q on a finite type of size n reduces to testing uniformity on 4 n points, with the same number of samples and a third of the proximity. This is Goldreich's theorem that the uniform distribution is complete for testing identity Goldreich.

The reduction passes each sample through a randomized map, Goldreich's kernel (identityKernel q). The kernel first replaces the sample by a uniform draw with probability 1 / 2. This lifts every mass of the target to at least 1 / (2 n). It then spreads the result over a domain of 4 n cells (IdentityDomain q):

The kernel sends q exactly to the uniform distribution on these cells (bind_identityKernel_self). It shrinks statistical distance by at most a factor 3 (dist_le_three_mul_dist_bind_identityKernel), because each block size is at least two thirds of 4 n times the mixed mass, that is, of 2 n q(a) + 2. Hence a uniformity tester with proximity ε / 3 on the cells, run on the mapped samples, tests identity to q with proximity ε (isTester_identity_of_uniform).

With the collision tester this gives an explicit identity tester (identityTester) whenever 720 √n ≤ (k - 1) ε² (isTester_identityTester), so k = O(√n / ε²) samples suffice for every fixed q. The block structure follows Goldreich's construction. The grain 1 / (4 n) and the constants 3 and 720 are the ones this proof gives; they are not taken from the source.

Main definitions #

Main results #

References #

noncomputable def Cslib.DistributionTesting.identityGrain {α : Type u_1} [Fintype α] (q : PMF α) (a : α) :

The grain of a: ⌊2 n q(a)⌋, where n is the size of the domain. Element a owns identityGrain q a + 2 cells.

noncomputable def Cslib.DistributionTesting.identityBlock {α : Type u_1} [Fintype α] (q : PMF α) :
Option α → ℕ

The block sizes of Goldreich's kernel: ⌊2 n q(a)⌋ + 2 cells for each element a and 2 n - ∑ a, ⌊2 n q(a)⌋ leftover cells.

theorem Cslib.DistributionTesting.sum_identityGrain_le {α : Type u_1} [Fintype α] (q : PMF α) :
∑ a : α, identityGrain q a ≤ 2 * Fintype.card α

The grains sum to at most 2 n.

@[reducible, inline]
abbrev Cslib.DistributionTesting.IdentityDomain {α : Type u_1} [Fintype α] (q : PMF α) :
Type u_1

The cells of Goldreich's kernel: a block of identityBlock q (some a) cells for each element a and a leftover block of identityBlock q none cells.

Instances For

    There are 4 n cells.

    noncomputable def Cslib.DistributionTesting.identityKernel {α : Type u_1} [Fintype α] (q : PMF α) [DecidableEq α] (y : α) :

    Goldreich's kernel for identity testing to q. It keeps the sample with probability 1 / 2 and replaces it by a uniform draw otherwise. An element a then goes to a uniformly random cell of its own block with probability (⌊2 n q(a)⌋ + 2) / (2 n q(a) + 2), and to a uniformly random leftover cell otherwise.

    theorem Cslib.DistributionTesting.bind_identityKernel_some {α : Type u_1} [Fintype α] (q : PMF α) [DecidableEq α] (p : PMF α) (b : α) (j : Fin (identityBlock q (some b))) :
    ((p.bind (identityKernel q)) ⟨some b, j⟩).toReal = ((p b).toReal / 2 + 1 / (2 * ↑(Fintype.card α))) / (2 * ↑(Fintype.card α) * (q b).toReal + 2)

    Through Goldreich's kernel, p gives each cell of the block of b the probability (p(b) / 2 + 1 / (2 n)) / (2 n q(b) + 2).

    Completeness of the reduction: Goldreich's kernel maps q to the uniform distribution on the cells.

    Soundness of the reduction: Goldreich's kernel shrinks the statistical distance from q by at most a factor 3.

    theorem Cslib.DistributionTesting.isTester_identity_of_uniform {α : Type u_1} [Fintype α] (q : PMF α) [DecidableEq α] {k : ℕ} {T : (Fin k → IdentityDomain q) → PMF Bool} {ε : ℝ} (hT : IsTester T {Probability.PMF.uniformOfFintype (IdentityDomain q)} (ε / 3)) :
    IsTester (fun (x : Fin k → α) => (Probability.PMF.pi fun (i : Fin k) => identityKernel q (x i)).bind T) {q} ε

    The uniform distribution is complete for identity testing Goldreich: a k-sample uniformity tester on the 4 n cells with proximity ε / 3, run on samples passed through Goldreich's kernel, is a k-sample tester for identity to q with proximity ε.

    theorem Cslib.DistributionTesting.exists_isTester_identity_of_uniform {α : Type u_1} [Fintype α] (q : PMF α) {β : Type u_2} [Fintype β] [Nonempty β] (hβ : Fintype.card β = 4 * Fintype.card α) {k : ℕ} {T : (Fin k → β) → PMF Bool} {ε : ℝ} (hT : IsTester T {Probability.PMF.uniformOfFintype β} (ε / 3)) :
    ∃ (T' : (Fin k → α) → PMF Bool), IsTester T' {q} ε

    The reduction for uniformity testers on any domain of size 4 n: a k-sample uniformity tester with proximity ε / 3 there yields a k-sample tester for identity to q with proximity ε.

    noncomputable def Cslib.DistributionTesting.identityTester {α : Type u_1} [Fintype α] (q : PMF α) [DecidableEq α] (k : ℕ) (ε : ℝ) :
    (Fin k → α) → PMF Bool

    The identity tester for q: the collision tester with proximity ε / 3, run on k samples passed through Goldreich's kernel.

    theorem Cslib.DistributionTesting.isTester_identityTester {α : Type u_1} [Fintype α] (q : PMF α) [DecidableEq α] {k : ℕ} {ε : ℝ} (hε : 0 < ε) (hk : 720 * √↑(Fintype.card α) ≤ (↑k - 1) * ε ^ 2) :

    Identity testing with O(√n / ε²) samples: for every fixed distribution q on a domain of size n, identityTester q k ε tests identity to q with proximity ε whenever 720 √n ≤ (k - 1) ε².