math / data /lean /OAI /Computability /UniqueGames /Analysis /MatrixParityRow.lean
introvoyz045's picture
Migrated from GitHub
4a56cd6 verified
Raw History Blame Contribute Delete
13.6 kB
import Mathlib.Algebra.Order.BigOperators.Expect
import Mathlib.Basic.Complex.BigOperators
import Mathlib.Tactic.Linarith
import OAI.Computability.UniqueGames.Analysis.MatrixCharactersLemmas
import OAI.Computability.UniqueGames.Analysis.MatrixRestrictions
namespace OAI
section
/-! Fourier expansion of actual affine restrictions and parity extraction. -/
noncomputable section
namespace UniqueGamesTheorem.Fourier.MatrixParityRow
open MatrixCharacters MatrixFourier MatrixParity
open scoped BigOperators Classical
variable {E C V : Type*} [AddCommGroup E] [Module F2 E]
[AddCommGroup C] [Module F2 C] [AddCommGroup V] [Module F2 V]
theorem traceCharacter_comp (Q : E β†’β‚—[F2] V) (A : V β†’β‚—[F2] C)
(T : C β†’β‚—[F2] E) :
linearTraceCharacter T (A.comp Q) = linearTraceCharacter (Q.comp T) A := by
simp only [linearTraceCharacter_apply, linearTracePair, LinearMap.comp_assoc]
theorem traceCharacter_re_add (T : C β†’β‚—[F2] E) (X Y : E β†’β‚—[F2] C) :
(linearTraceCharacter T (X + Y)).re =
(linearTraceCharacter T X).re * (linearTraceCharacter T Y).re := by
rw [AddChar.map_add_eq_mul, Complex.mul_re]
simp [linearTraceCharacter_apply, binarySign_im]
variable [FiniteDimensional F2 E] [FiniteDimensional F2 C] [FiniteDimensional F2 V]
[Fintype (E β†’β‚—[F2] C)] [Fintype (C β†’β‚—[F2] E)] [Fintype (V β†’β‚—[F2] C)]
omit [FiniteDimensional F2 E] [Fintype (E β†’β‚—[F2] C)] [Fintype (C β†’β‚—[F2] E)] in
/-- Characters restricted to the row vanish unless the dual map lands in the
kernel of `Q`. For `Q = W.mkQ` this is precisely `range T ≀ W`. -/
theorem row_character_average (Q : E β†’β‚—[F2] V) (T : C β†’β‚—[F2] E) :
(𝔼 A : V β†’β‚—[F2] C, (linearTraceCharacter T (A.comp Q)).re) =
if Q.comp T = 0 then 1 else 0 := by
have hcomplex : (𝔼 A : V β†’β‚—[F2] C,
linearTraceCharacter T (A.comp Q)) = if Q.comp T = 0 then 1 else 0 := by
simp only [traceCharacter_comp, Fintype.expect_eq_sum_div_card,
sum_linearTraceCharacter]
split <;> simp [Fintype.card_ne_zero]
have h := congrArg Complex.re hcomplex
simpa only [Complex.re_expect, apply_ite, Complex.one_re, Complex.zero_re] using h
omit [FiniteDimensional F2 E] [Fintype (E β†’β‚—[F2] C)] in
/-- Averaging a finite trace-character expansion on an actual affine row. -/
theorem row_spectral_average (Q : E β†’β‚—[F2] V) (Xβ‚€ : E β†’β‚—[F2] C)
(a : (C β†’β‚—[F2] E) β†’ ℝ) :
(𝔼 A : V β†’β‚—[F2] C, βˆ‘ T : C β†’β‚—[F2] E,
a T * (linearTraceCharacter T (Xβ‚€ + A.comp Q)).re) =
βˆ‘ T : C β†’β‚—[F2] E, if Q.comp T = 0 then
a T * (linearTraceCharacter T Xβ‚€).re else 0 := by
rw [Finset.expect_sum_comm]
apply Finset.sum_congr rfl
intro T _
simp only [traceCharacter_re_add, ← mul_assoc]
rw [← Finset.mul_expect, row_character_average]
split <;> simp
/-- Equation (5.18), with the primal row parametrized by actual quotient maps. -/
theorem row_fourier_average (Q : E β†’β‚—[F2] V) (Xβ‚€ : E β†’β‚—[F2] C)
(g : (E β†’β‚—[F2] C) β†’ ℝ) :
(𝔼 A : V β†’β‚—[F2] C, g (Xβ‚€ + A.comp Q)) =
βˆ‘ T : C β†’β‚—[F2] E, if Q.comp T = 0 then
linearCoeff g T * (linearTraceCharacter T Xβ‚€).re else 0 := by
rw [← row_spectral_average]
apply Finset.expect_congr rfl
intro A _
exact (linear_fourier_inversion g _).symm
omit [FiniteDimensional F2 E] [Fintype (E β†’β‚—[F2] C)] [Fintype (C β†’β‚—[F2] E)] in
theorem shift_character_average [Fintype C] (Ο„ : E β†’β‚—[F2] F2)
(T : C β†’β‚—[F2] E) :
(𝔼 c : C, (linearTraceCharacter T (Ο„.smulRight c)).re) =
if Ο„.comp T = 0 then 1 else 0 := by
have hc := linearTrace_shift_average Ο„ T
rw [← Fintype.expect_eq_sum_div_card] at hc
have hr := congrArg Complex.re hc
simpa only [Complex.re_expect, apply_ite, Complex.one_re, Complex.zero_re] using hr
/-- The folding average is the Fourier projection onto parity-zero frequencies. -/
theorem shift_fourier_average [Fintype C] (Ο„ : E β†’β‚—[F2] F2)
(X : E β†’β‚—[F2] C) (g : (E β†’β‚—[F2] C) β†’ ℝ) :
(𝔼 c : C, g (X + Ο„.smulRight c)) =
βˆ‘ T : C β†’β‚—[F2] E, (if Ο„.comp T = 0 then linearCoeff g T else 0) *
(linearTraceCharacter T X).re := by
calc
_ = 𝔼 c : C, βˆ‘ T : C β†’β‚—[F2] E,
linearCoeff g T * (linearTraceCharacter T (X + Ο„.smulRight c)).re := by
apply Finset.expect_congr rfl
intro c _
exact (linear_fourier_inversion g _).symm
_ = _ := by
rw [Finset.expect_sum_comm]
apply Finset.sum_congr rfl
intro T _
simp only [traceCharacter_re_add, ← mul_assoc]
rw [← Finset.mul_expect, shift_character_average]
split <;> simp
/-- The parity-zero row subtotal equals the row average of the folded average. -/
theorem row_shift_fourier_average [Fintype C] (Q : E β†’β‚—[F2] V)
(Ο„ : E β†’β‚—[F2] F2) (Xβ‚€ : E β†’β‚—[F2] C) (g : (E β†’β‚—[F2] C) β†’ ℝ) :
(𝔼 A : V β†’β‚—[F2] C, 𝔼 c : C, g (Xβ‚€ + A.comp Q + Ο„.smulRight c)) =
βˆ‘ T : C β†’β‚—[F2] E, if Q.comp T = 0 ∧ Ο„.comp T = 0 then
linearCoeff g T * (linearTraceCharacter T Xβ‚€).re else 0 := by
simp only [shift_fourier_average]
rw [row_spectral_average]
apply Finset.sum_congr rfl
intro T _
split_ifs <;> simp_all
omit [FiniteDimensional F2 E] [FiniteDimensional F2 C]
[Fintype (E β†’β‚—[F2] C)] [Fintype (C β†’β‚—[F2] E)] in
theorem signed_coefficient_le_abs (a : ℝ) (T : C β†’β‚—[F2] E)
(X : E β†’β‚—[F2] C) : a * (linearTraceCharacter T X).re ≀ |a| := by
rcases Integration.BinaryLinear.scalar_cases (linearTracePair X T) with h | h
Β· simpa [linearTraceCharacter_apply, h] using le_abs_self a
Β· simpa [linearTraceCharacter_apply, h] using neg_le_abs a
/-- Actual coefficient extraction from a dense affine row and a uniformly small
folding average. The row frequency count is an explicit finite cardinal bound;
the quotient/subspace specialization supplies it by counting maps into `W`. -/
theorem coefficient_of_dense_row [Fintype C] (Q : E β†’β‚—[F2] V)
(Ο„ : E β†’β‚—[F2] F2) (Xβ‚€ : E β†’β‚—[F2] C) (g : (E β†’β‚—[F2] C) β†’ ℝ)
(ρ : ℝ) (N : Nat) (ρ_pos : 0 < ρ) (N_pos : 0 < N)
(row_count : (Finset.univ.filter fun T : C β†’β‚—[F2] E => Q.comp T = 0).card ≀ N)
(dense : ρ < 𝔼 A : V β†’β‚—[F2] C, g (Xβ‚€ + A.comp Q))
(shift_bound : βˆ€ X, (𝔼 c : C, g (X + Ο„.smulRight c)) ≀ ρ / 2) :
βˆƒ T : C β†’β‚—[F2] E, Q.comp T = 0 ∧ Ο„.comp T β‰  0 ∧
ρ / (2 * (N : ℝ)) < |linearCoeff g T| := by
classical
let row : Finset (C β†’β‚—[F2] E) := Finset.univ.filter fun T => Q.comp T = 0
let term (T : C β†’β‚—[F2] E) := linearCoeff g T * (linearTraceCharacter T Xβ‚€).re
let Ξ² : ℝ := (ρ / 2) / (N : ℝ)
have hN : (0 : ℝ) < (N : ℝ) := Nat.cast_pos.mpr N_pos
have hΞ² : 0 ≀ Ξ² := le_of_lt (div_pos (div_pos ρ_pos zero_lt_two) hN)
have hbudget : (N : ℝ) * Ξ² = ρ / 2 := by
dsimp [Ξ²]
rw [mul_comm, div_mul_cancelβ‚€ _ (ne_of_gt hN)]
have htotal : ρ < βˆ‘ T : C β†’β‚—[F2] E,
if Q.comp T = 0 then term T else 0 := by
rw [row_fourier_average] at dense
apply lt_of_lt_of_eq dense
apply Finset.sum_congr rfl
intro frequency _
exact ite_congr rfl (fun _ => rfl) (fun _ => rfl)
have hzero : (βˆ‘ T : C β†’β‚—[F2] E,
if Q.comp T = 0 ∧ Ο„.comp T = 0 then term T else 0) ≀ ρ / 2 := by
change (βˆ‘ T : C β†’β‚—[F2] E, if Q.comp T = 0 ∧ Ο„.comp T = 0 then
linearCoeff g T * (linearTraceCharacter T Xβ‚€).re else 0) ≀ _
rw [← row_shift_fourier_average]
apply Finset.expect_le Finset.univ_nonempty
intro A _
exact shift_bound (Xβ‚€ + A.comp Q)
have hsplit : (βˆ‘ T : C β†’β‚—[F2] E, if Q.comp T = 0 then term T else 0) =
(βˆ‘ T : C β†’β‚—[F2] E, if Q.comp T = 0 ∧ Ο„.comp T = 0 then term T else 0) +
βˆ‘ T ∈ row, if Ο„.comp T = 0 then 0 else term T := by
simp only [row, Finset.sum_filter]
rw [← Finset.sum_add_distrib]
apply Finset.sum_congr rfl
intro T _
split_ifs <;> simp_all
have hnonzero : ρ / 2 < βˆ‘ T ∈ row, if Ο„.comp T = 0 then 0 else term T := by
linarith
by_contra hnone
have hsmall : βˆ€ T ∈ row, (if Ο„.comp T = 0 then 0 else term T) ≀ Ξ² := by
intro T hT
split_ifs with hΟ„
Β· exact hΞ²
Β· have hQ : Q.comp T = 0 := (Finset.mem_filter.mp hT).2
have hc : |linearCoeff g T| ≀ Ξ² := by
by_contra hc
apply hnone
refine ⟨T, hQ, hΟ„, ?_⟩
have hlarge : Ξ² < |linearCoeff g T| := lt_of_not_ge hc
simpa only [Ξ², div_div] using hlarge
exact (signed_coefficient_le_abs (linearCoeff g T) T Xβ‚€).trans hc
have hsum := Finset.sum_le_sum hsmall
have hcard : (row.card : ℝ) ≀ (N : ℝ) := by exact_mod_cast row_count
have hcount := mul_le_mul_of_nonneg_right hcard hΞ²
have hsum' : (βˆ‘ T ∈ row, if Ο„.comp T = 0 then 0 else term T) ≀
(row.card : ℝ) * Ξ² := by
simpa only [Finset.sum_const, nsmul_eq_mul] using hsum
linarith
/-- Dense-row extraction for a genuinely folded color map. The zero-parity
subtotal bound follows from folding, rather than being supplied as a hypothesis. -/
theorem coefficient_of_folded_dense_row [Fintype C]
{D : Type*} [AddCommGroup D] [Module F2 D]
(Q : E β†’β‚—[F2] V) (Ο„ : E β†’β‚—[F2] F2) (Xβ‚€ : E β†’β‚—[F2] C)
(inclusion : C β†’β‚—[F2] D) (inclusion_injective : Function.Injective inclusion)
(F : (E β†’β‚—[F2] C) β†’ D)
(folded : βˆ€ X c, F (X + Ο„.smulRight c) = F X + inclusion c)
(y : D) (ρ : ℝ) (N : Nat) (ρ_pos : 0 < ρ) (N_pos : 0 < N)
(color_bound : 1 / (Fintype.card C : ℝ) ≀ ρ / 2)
(row_count : (Finset.univ.filter fun T : C β†’β‚—[F2] E => Q.comp T = 0).card ≀ N)
(dense : ρ < 𝔼 A : V β†’β‚—[F2] C, if F (Xβ‚€ + A.comp Q) = y then (1 : ℝ) else 0) :
βˆƒ T : C β†’β‚—[F2] E, Q.comp T = 0 ∧ Ο„.comp T β‰  0 ∧
ρ / (2 * (N : ℝ)) < |linearCoeff (fun X => if F X = y then 1 else 0) T| := by
apply coefficient_of_dense_row Q Ο„ Xβ‚€ (fun X => if F X = y then 1 else 0)
ρ N ρ_pos N_pos row_count dense
intro X
rw [Fintype.expect_eq_sum_div_card]
exact (folded_indicator_average_le Ο„ inclusion inclusion_injective F folded X y).trans
color_bound
lemma color_card_bound [Fintype C] (r s : Nat) (ρ : ℝ)
(hρ : ρ = 2 / (2 : ℝ) ^ (s - r))
(hdim : s - r ≀ Module.finrank F2 C) :
1 / (Fintype.card C : ℝ) ≀ ρ / 2 := by
have hcard : Fintype.card C = 2 ^ Module.finrank F2 C := by
simpa [F2, ZMod.card] using Module.card_fintype (Module.finBasis F2 C)
have hleNat : 2 ^ (s - r) ≀ Fintype.card C := by
rw [hcard]
exact Nat.pow_le_pow_right (by decide : 0 < 2) hdim
have hle : (2 : ℝ) ^ (s - r) ≀ (Fintype.card C : ℝ) := by
exact_mod_cast hleNat
calc
1 / (Fintype.card C : ℝ) ≀ 1 / (2 : ℝ) ^ (s - r) :=
one_div_le_one_div_of_le (pow_pos zero_lt_two _) hle
_ = ρ / 2 := by rw [hρ]; ring
omit [FiniteDimensional F2 E] [FiniteDimensional F2 C]
[Fintype (E β†’β‚—[F2] C)] [Fintype (C β†’β‚—[F2] E)] in
lemma fixed_row_folded {R D : Type*}
[AddCommGroup R] [Module F2 R] [AddCommGroup D] [Module F2 D]
(Ο„ : E β†’β‚—[F2] F2) (questionInclusion : C β†’β‚—[F2] R)
(colorInclusion : C β†’β‚—[F2] D)
(FU : (E β†’β‚—[F2] R) β†’ D) (Z : E β†’β‚—[F2] R)
(folded : βˆ€ Y c, FU (Y + Ο„.smulRight (questionInclusion c)) = FU Y + colorInclusion c) :
βˆ€ X c, FU (Z + questionInclusion.comp (X + Ο„.smulRight c)) =
FU (Z + questionInclusion.comp X) + colorInclusion c := by
intro X c
have hshift : questionInclusion.comp (Ο„.smulRight c) = Ο„.smulRight (questionInclusion c) := by
ext e
simp [LinearMap.smulRight_apply]
rw [LinearMap.comp_add, hshift, ← add_assoc, folded]
/-- Lemma 5.3 on an actual quotient-parametrized dense row. The density parameter
is stated as a ratio of natural powers, avoiding truncated negative exponents. -/
theorem lemma53_quotient [Fintype C]
{D : Type*} [AddCommGroup D] [Module F2 D]
(W : Submodule F2 E)
[Fintype ((E β§Έ W) β†’β‚—[F2] C)] [Fintype (C β†’β‚—[F2] W)]
(Ο„ : E β†’β‚—[F2] F2) (Xβ‚€ : E β†’β‚—[F2] C)
(inclusion : C β†’β‚—[F2] D) (inclusion_injective : Function.Injective inclusion)
(F : (E β†’β‚—[F2] C) β†’ D)
(folded : βˆ€ X c, F (X + Ο„.smulRight c) = F X + inclusion c)
(y : D) (r s : Nat) (ρ : ℝ)
(hρ : ρ = 2 / (2 : ℝ) ^ (s - r))
(hW : Module.finrank F2 W ≀ r)
(hC : Module.finrank F2 C ≀ s)
(hdim : s - r ≀ Module.finrank F2 C)
(dense : ρ < 𝔼 A : (E β§Έ W) β†’β‚—[F2] C,
if F (Xβ‚€ + A.comp W.mkQ) = y then (1 : ℝ) else 0) :
βˆƒ T : C β†’β‚—[F2] E, Ο„.comp T β‰  0 ∧
ρ / (2 * ((2 ^ (r * s) : Nat) : ℝ)) <
|linearCoeff (fun X => if F X = y then 1 else 0) T| := by
have hρpos : 0 < ρ := by
rw [hρ]
exact div_pos zero_lt_two (pow_pos zero_lt_two _)
have hcount : (Finset.univ.filter fun T : C β†’β‚—[F2] E => W.mkQ.comp T = 0).card ≀
2 ^ (r * s) := by
rw [← Finset.filter_congr_decidable Finset.univ
(fun frequency : C β†’β‚—[F2] E => W.mkQ.comp frequency = 0)
(fun frequency => Classical.propDecidable (W.mkQ.comp frequency = 0)),
MatrixRestrictions.quotientKernel_filter_card W]
exact MatrixParity.card_linearMaps_le (E := W) (C := C) r s hW hC
obtain ⟨T, _, hΟ„, hβ⟩ := coefficient_of_folded_dense_row W.mkQ Ο„ Xβ‚€
inclusion inclusion_injective F folded y ρ (2 ^ (r * s)) hρpos
(Nat.two_pow_pos _) (color_card_bound r s ρ hρ hdim) hcount dense
exact ⟨T, hΟ„, hβ⟩
end UniqueGamesTheorem.Fourier.MatrixParityRow
end
end
end OAI