Documentation

CslibFrontier.Foundations.BooleanAnalysis.Affinity

Affinity testing #

A Boolean function on the cube is affine when it is a parity plus a constant, f x = b ^^ parityOn S x. Bit strings add coordinatewise modulo two (x + y, through Mathlib's Boolean ring structure on Bool) and single bits by exclusive or (^^). The affine functions are exactly those with f (x + y + z) = (f x ^^ f y ^^ f z) for all x, y, z (BitString.exists_eq_xor_parityOn_iff), or equivalently with f (x + y) = (f x ^^ f y ^^ f 0) for all x, y (BitString.exists_eq_xor_parityOn_iff_add) O'Donnell, Exercise 1.29.

The affinity test queries f at independent uniformly random x, y and z and at x + y + z, which is uniformly distributed as well (BitString.expect_expect_expect_add_add), and accepts when (f x ^^ f y ^^ f z) = f (x + y + z); BitString.affinityAcceptance f is the probability that it accepts. Reading f as the function F x = (-1) ^ f x, the four-point correlation 𝔼 F(x) F(y) F(z) F(x + y + z) is ∑_S F̂(S)⁴ (BitString.expect_mul_mul_mul_eq_sum_fourierCoeff_pow_four), by the convolution theorem applied twice, so the test accepts with probability 1/2 + 1/2 ∑_S F̂(S)⁴ (BitString.affinityAcceptance_eq_sum_fourierCoeff_pow_four). Affine functions pass with probability one (BitString.affinityAcceptance_xor_parityOn). Conversely, a function passing with probability at least 1 - ε differs from some affine function on at most an ε fraction of the inputs (BitString.exists_hammingDist_xor_parityOn_le_of_le_affinityAcceptance): by Parseval's identity, ∑_S F̂(S)⁴ ≤ max_S F̂(S)² ≤ max_S |F̂(S)|, and |F̂(S)| is one minus twice the relative Hamming distance from f to the parity on S or to its negation (BitString.fourierCoeff_signVal_eq_signVal_mul). This is the argument of the BLR test (BitString.exists_hammingDist_parityOn_le_of_le_blrAcceptance) with fourth powers in place of cubes, which is why it also finds negated parities.

The anchored affinity test reads f at uniformly random x and y, at x + y, and at the fixed point 0, and accepts when (f x ^^ f y ^^ f 0) = f (x + y). It is the BLR test on x ↦ f x ^^ f 0 (BitString.anchoredAffinityAcceptance_eq_blrAcceptance), so it has the same completeness and soundness (BitString.anchoredAffinityAcceptance_xor_parityOn, BitString.exists_hammingDist_xor_parityOn_le_of_le_anchoredAffinityAcceptance).

Main definitions #

Main results #

References #

Affine functions #

theorem Cslib.BitString.exists_eq_xor_parityOn_iff_add {ι : Type u_1} [Finite ι] {f : (ι → Bool) → Bool} :
(∃ (b : Bool) (S : Finset ι), f = fun (x : ι → Bool) => b ^^ parityOn S x) ↔ ∀ (x y : ι → Bool), f (x + y) = (f x ^^ f y ^^ f 0)

The affine Boolean functions, through a fixed point: a Boolean function satisfies f (x + y) = (f x ^^ f y ^^ f 0) exactly when it is a parity plus a constant O'Donnell, Exercise 1.29(d).

theorem Cslib.BitString.exists_eq_xor_parityOn_iff {ι : Type u_1} [Finite ι] {f : (ι → Bool) → Bool} :
(∃ (b : Bool) (S : Finset ι), f = fun (x : ι → Bool) => b ^^ parityOn S x) ↔ ∀ (x y z : ι → Bool), f (x + y + z) = (f x ^^ f y ^^ f z)

The affine Boolean functions: a Boolean function satisfies f (x + y + z) = (f x ^^ f y ^^ f z) exactly when it is a parity plus a constant O'Donnell, Exercise 1.29(a).

The four-point correlation #

theorem Cslib.BitString.expect_mul_mul_mul_eq_sum_fourierCoeff_pow_four {ι : Type u_1} [Fintype ι] [DecidableEq ι] (F : (ι → Bool) → ℝ) :
(Finset.univ.expect fun (x : ι → Bool) => Finset.univ.expect fun (y : ι → Bool) => Finset.univ.expect fun (z : ι → Bool) => F x * F y * F z * F (x + y + z)) = ∑ S : Finset ι, fourierCoeff F S ^ 4

The four-point correlation: for independent uniformly random x, y and z, 𝔼 F(x) F(y) F(z) F(x + y + z) = ∑_S F̂(S)⁴ O'Donnell, Exercise 1.29(b).

theorem Cslib.BitString.expect_expect_expect_add_add {ι : Type u_1} [Fintype ι] [DecidableEq ι] {M : Type u_2} [AddCommMonoid M] [Module ℚ≥0 M] (g : (ι → Bool) → M) :
(Finset.univ.expect fun (x : ι → Bool) => Finset.univ.expect fun (y : ι → Bool) => Finset.univ.expect fun (z : ι → Bool) => g (x + y + z)) = Finset.univ.expect fun (w : ι → Bool) => g w

The fourth query x + y + z of the affinity test is uniformly distributed.

The affinity test #

noncomputable def Cslib.BitString.affinityAcceptance {ι : Type u_1} [Fintype ι] [DecidableEq ι] (f : (ι → Bool) → Bool) :

The acceptance probability of the affinity test on f: the probability, over independent uniformly random bit strings x, y and z, that (f x ^^ f y ^^ f z) = f (x + y + z). Each of the four queries is uniformly distributed (expect_expect_expect_add_add).

theorem Cslib.BitString.affinityAcceptance_eq_sum_fourierCoeff_pow_four {ι : Type u_1} [Fintype ι] [DecidableEq ι] (f : (ι → Bool) → Bool) :
affinityAcceptance f = 1 / 2 + 1 / 2 * ∑ S : Finset ι, fourierCoeff (fun (x : ι → Bool) => signVal (f x)) S ^ 4

The acceptance probability of the affinity test: reading f as signs, the test accepts with probability 1/2 + 1/2 ∑_S F̂(S)⁴.

theorem Cslib.BitString.affinityAcceptance_xor_parityOn {ι : Type u_1} [Fintype ι] [DecidableEq ι] (b : Bool) (S : Finset ι) :
(affinityAcceptance fun (x : ι → Bool) => b ^^ parityOn S x) = 1

Completeness of the affinity test: affine functions pass with probability one O'Donnell, Exercise 1.29(c).

theorem Cslib.BitString.fourierCoeff_signVal_eq_signVal_mul {ι : Type u_1} [Fintype ι] [DecidableEq ι] (f : (ι → Bool) → Bool) (b : Bool) (S : Finset ι) :
fourierCoeff (fun (x : ι → Bool) => signVal (f x)) S = signVal b * (1 - 2 * ↑(hammingDist f fun (x : ι → Bool) => b ^^ parityOn S x) / 2 ^ Fintype.card ι)

The Fourier coefficient on S of a Boolean function read as signs is ±1 times one minus twice the relative Hamming distance from the function to the affine function b ^^ parityOn S, with sign (-1) ^ b.

theorem Cslib.BitString.exists_sum_fourierCoeff_signVal_pow_four_le {ι : Type u_1} [Fintype ι] [DecidableEq ι] (f : (ι → Bool) → Bool) :
∃ (S : Finset ι), ∑ T : Finset ι, fourierCoeff (fun (x : ι → Bool) => signVal (f x)) T ^ 4 ≤ fourierCoeff (fun (x : ι → Bool) => signVal (f x)) S ^ 2

The fourth spectral moment of a Boolean function is at most its largest squared coefficient: reading f as signs, some S has ∑_T F̂(T)⁴ ≤ F̂(S)², since ∑_T F̂(T)⁴ ≤ max_S F̂(S)² ∑_T F̂(T)² and the squares sum to one by Parseval's identity.

theorem Cslib.BitString.exists_hammingDist_xor_parityOn_le_of_le_abs_fourierCoeff {ι : Type u_1} [Fintype ι] [DecidableEq ι] {f : (ι → Bool) → Bool} {S : Finset ι} {t : ℝ} (h : t ≤ |fourierCoeff (fun (x : ι → Bool) => signVal (f x)) S|) :
∃ (b : Bool), ↑(hammingDist f fun (x : ι → Bool) => b ^^ parityOn S x) / 2 ^ Fintype.card ι ≤ 1 / 2 - t / 2

A large Fourier coefficient gives a nearby affine function: if t ≤ |F̂(S)| for the Boolean function f read as signs, then f differs from b ^^ parityOn S on at most a 1/2 - t/2 fraction of the inputs for some bit b, namely b = true exactly when F̂(S) < 0.

theorem Cslib.BitString.exists_hammingDist_xor_parityOn_le_of_le_affinityAcceptance {ι : Type u_1} [Fintype ι] [DecidableEq ι] {f : (ι → Bool) → Bool} {ε : ℝ} (h : 1 - ε ≤ affinityAcceptance f) :
∃ (b : Bool) (S : Finset ι), ↑(hammingDist f fun (x : ι → Bool) => b ^^ parityOn S x) / 2 ^ Fintype.card ι ≤ ε

Soundness of the affinity test: if the test accepts f with probability at least 1 - ε, then f differs from some affine function on at most an ε fraction of the inputs O'Donnell, Exercise 1.29(c).

The anchored affinity test #

noncomputable def Cslib.BitString.anchoredAffinityAcceptance {ι : Type u_1} [Fintype ι] [DecidableEq ι] (f : (ι → Bool) → Bool) :

The acceptance probability of the anchored affinity test on f: the probability, over independent uniformly random bit strings x and y, that (f x ^^ f y ^^ f 0) = f (x + y). Three of the four queries are uniformly distributed and the fourth is the point 0.

The anchored affinity test on f is the BLR test on x ↦ f x ^^ f 0.

Completeness of the anchored affinity test: affine functions pass with probability one O'Donnell, Exercise 1.29(d).

theorem Cslib.BitString.exists_hammingDist_xor_parityOn_le_of_le_anchoredAffinityAcceptance {ι : Type u_1} [Fintype ι] [DecidableEq ι] {f : (ι → Bool) → Bool} {ε : ℝ} (h : 1 - ε ≤ anchoredAffinityAcceptance f) :
∃ (b : Bool) (S : Finset ι), ↑(hammingDist f fun (x : ι → Bool) => b ^^ parityOn S x) / 2 ^ Fintype.card ι ≤ ε

Soundness of the anchored affinity test: if the test accepts f with probability at least 1 - ε, then f differs from some affine function on at most an ε fraction of the inputs O'Donnell, Exercise 1.29(d).