math / data /lean /OAI /Computability /MaxCut /Gadgets /Polynomial.lean
introvoyz045's picture
Migrated from GitHub
4a56cd6 verified
Raw History Blame Contribute Delete
10.7 kB
import Mathlib
import OAI.Computability.MaxCut.Estimates.Degree
namespace OAI
noncomputable section
namespace OptimalMaxCut.BooleanFourthMoment
open scoped BigOperators
open Finset MaxCutGames.Foundations.Hastad
theorem sum_cube_succ {n : β„•} (F : Cube (Fin (n + 1)) β†’ ℝ) :
βˆ‘ x, F x = βˆ‘ b : Bool, βˆ‘ y : Cube (Fin n), F (Fin.cons b y) := by
rw [← (Fin.consEquiv (fun _ : Fin (n + 1) => Bool)).sum_comp]
exact Fintype.sum_prod_type _
theorem expect_cube_succ {n : β„•} (F : Cube (Fin (n + 1)) β†’ ℝ) :
(𝔼 x, F x) = 𝔼 b : Bool, 𝔼 y : Cube (Fin n), F (Fin.cons b y) := by
calc
_ = 𝔼 p : Bool Γ— Cube (Fin n), F (Fin.cons p.1 p.2) :=
(Fintype.expect_equiv (Fin.consEquiv (fun _ : Fin (n + 1) => Bool)) _ F (fun _ => rfl)).symm
_ = _ := by rw [← Finset.univ_product_univ, Finset.expect_product]
theorem expect_bool (F : Bool β†’ ℝ) : (𝔼 b, F b) = (F false + F true) / 2 := by
rw [Fintype.expect_eq_sum_div_card]
simp [add_comm]
noncomputable def polynomial {I : Type*} [Fintype I] [DecidableEq I]
(c : Cube I β†’ ℝ) (x : Cube I) : ℝ := βˆ‘ s, c s * walsh s x
noncomputable def energy {I : Type*} [Fintype I] [DecidableEq I]
(c : Cube I β†’ ℝ) : ℝ :=
βˆ‘ s, (∏ i, if s i then (3 : ℝ) else 1) * c s ^ 2
theorem energy_nonneg {I : Type*} [Fintype I] [DecidableEq I] (c : Cube I β†’ ℝ) :
0 ≀ energy c := by
apply Finset.sum_nonneg
intro s _
apply mul_nonneg _ (sq_nonneg _)
apply Finset.prod_nonneg
intro i _
split_ifs <;> norm_num
theorem walsh_cons {n : β„•} (s x : Cube (Fin n)) (a b : Bool) :
walsh (Fin.cons a s) (Fin.cons b x) = (if a then bitSign b else 1) * walsh s x := by
cases a <;> simp [walsh, Fin.prod_univ_succ, bitSign]
theorem polynomial_cons {n : β„•} (c : Cube (Fin (n + 1)) β†’ ℝ) (x : Cube (Fin n)) (b : Bool) :
polynomial c (Fin.cons b x) = polynomial (fun s => c (Fin.cons false s)) x +
bitSign b * polynomial (fun s => c (Fin.cons true s)) x := by
unfold polynomial
rw [sum_cube_succ, Fintype.sum_bool]
simp only [walsh_cons, Bool.false_eq_true, ↓reduceIte, one_mul]
rw [Finset.mul_sum, add_comm]
congr 1
apply Finset.sum_congr rfl
intro s _
ring
theorem energy_cons {n : β„•} (c : Cube (Fin (n + 1)) β†’ ℝ) :
energy c = energy (fun s => c (Fin.cons false s)) +
3 * energy (fun s => c (Fin.cons true s)) := by
unfold energy
rw [sum_cube_succ, Fintype.sum_bool]
simp only [Fin.prod_univ_succ, Fin.cons_zero, Fin.cons_succ, Bool.false_eq_true, ↓reduceIte,
one_mul, mul_assoc]
rw [← Finset.mul_sum]
ring
theorem fourth_moment_cons {n : β„•} (c : Cube (Fin (n + 1)) β†’ ℝ) :
(𝔼 x, polynomial c x ^ 4) =
(𝔼 x, polynomial (fun s => c (Fin.cons false s)) x ^ 4) +
6 * (𝔼 x, polynomial (fun s => c (Fin.cons false s)) x ^ 2 *
polynomial (fun s => c (Fin.cons true s)) x ^ 2) +
(𝔼 x, polynomial (fun s => c (Fin.cons true s)) x ^ 4) := by
rw [expect_cube_succ, Finset.expect_comm]
simp_rw [expect_bool]
simp only [polynomial_cons, bitSign, Bool.false_eq_true, ↓reduceIte, one_mul, neg_one_mul]
simp_rw [show βˆ€ a b : ℝ, ((a + b) ^ 4 + (a + -b) ^ 4) / 2 = a ^ 4 + 6 * (a ^ 2 * b ^ 2) + b ^ 4 by
intro a b; ring]
rw [Finset.expect_add_distrib, Finset.expect_add_distrib, ← Finset.mul_expect]
theorem fourth_moment_bound (n : β„•) (c : Cube (Fin n) β†’ ℝ) :
(𝔼 x, polynomial c x ^ 4) ≀ energy c ^ 2 := by
induction n with
| zero => simp [polynomial, energy, walsh]; exact le_of_eq (by ring)
| succ n ih =>
let cβ‚€ : Cube (Fin n) β†’ ℝ := fun s => c (Fin.cons false s)
let c₁ : Cube (Fin n) β†’ ℝ := fun s => c (Fin.cons true s)
have hβ‚€ := ih cβ‚€
have h₁ := ih c₁
have heβ‚€ := energy_nonneg cβ‚€
have he₁ := energy_nonneg c₁
have hmβ‚€ : 0 ≀ 𝔼 x, polynomial cβ‚€ x ^ 4 := by positivity
have hm₁ : 0 ≀ 𝔼 x, polynomial c₁ x ^ 4 := by positivity
have hc := Finset.expect_mul_sq_le_sq_mul_sq Finset.univ
(fun x => polynomial cβ‚€ x ^ 2) (fun x => polynomial c₁ x ^ 2)
simp only [← pow_mul, Nat.reduceMul] at hc
have hc' : (𝔼 x, polynomial cβ‚€ x ^ 2 * polynomial c₁ x ^ 2) ^ 2 ≀
(energy cβ‚€ * energy c₁) ^ 2 := by
calc _ ≀ _ := hc
_ ≀ energy cβ‚€ ^ 2 * energy c₁ ^ 2 := mul_le_mul hβ‚€ h₁ hm₁ (sq_nonneg _)
_ = _ := by ring
have hc'' : (𝔼 x, polynomial cβ‚€ x ^ 2 * polynomial c₁ x ^ 2) ≀ energy cβ‚€ * energy c₁ :=
(sq_le_sqβ‚€ (by positivity) (mul_nonneg heβ‚€ he₁)).mp hc'
rw [fourth_moment_cons, energy_cons]
change (𝔼 x, polynomial cβ‚€ x ^ 4) +
6 * (𝔼 x, polynomial cβ‚€ x ^ 2 * polynomial c₁ x ^ 2) +
(𝔼 x, polynomial c₁ x ^ 4) ≀ (energy cβ‚€ + 3 * energy c₁) ^ 2
nlinarith [sq_nonneg (energy c₁)]
theorem weight_eq_degree {I : Type*} [Fintype I] [DecidableEq I] (s : Cube I) :
(∏ i, if s i then (3 : ℝ) else 1) = 3 ^ Analytic.degree s := by
simp [Finset.prod_ite, Analytic.degree]
theorem energy_truncated {I : Type*} [Fintype I] [DecidableEq I]
(K : β„•) (c : Cube I β†’ ℝ) (hc : βˆ€ s, K < Analytic.degree s β†’ c s = 0) :
energy c ≀ 3 ^ K * βˆ‘ s, c s ^ 2 := by
unfold energy
rw [Finset.mul_sum]
apply Finset.sum_le_sum
intro s _
rw [weight_eq_degree]
by_cases hs : Analytic.degree s ≀ K
Β· exact mul_le_mul_of_nonneg_right (pow_le_pow_rightβ‚€ (by norm_num) hs) (sq_nonneg _)
Β· rw [hc s (lt_of_not_ge hs)]; simp
theorem coefficient_polynomial {I : Type*} [Fintype I] [DecidableEq I]
(c : Cube I β†’ ℝ) (a : Cube I) : coefficient (polynomial c) a = c a := by
unfold coefficient polynomial
simp only [Finset.sum_mul]
rw [Finset.expect_sum_comm]
simp_rw [mul_assoc, ← Finset.mul_expect, walsh_orthogonality]
simp
theorem polynomial_second_moment {I : Type*} [Fintype I] [DecidableEq I] (c : Cube I β†’ ℝ) :
(𝔼 x, polynomial c x ^ 2) = βˆ‘ s, c s ^ 2 := by
rw [← walsh_parseval]
simp only [coefficient_polynomial]
theorem degree_fourth_moment_bound {n K : β„•} (c : Cube (Fin n) β†’ ℝ)
(hc : βˆ€ s, K < Analytic.degree s β†’ c s = 0) :
(𝔼 x, polynomial c x ^ 4) ≀ (3 ^ K * (𝔼 x, polynomial c x ^ 2)) ^ 2 := by
rw [polynomial_second_moment]
exact (fourth_moment_bound n c).trans
((sq_le_sqβ‚€ (energy_nonneg c) (by positivity)).mpr (energy_truncated K c hc))
theorem degree_third_moment_bound {n K : β„•} (c : Cube (Fin n) β†’ ℝ)
(hc : βˆ€ s, K < Analytic.degree s β†’ c s = 0) {Ο„ : ℝ} (hΟ„ : 0 ≀ Ο„)
(hsmall : (𝔼 x, polynomial c x ^ 2) ≀ Ο„ ^ 2) :
(𝔼 x, |polynomial c x| ^ 3) ≀ 3 ^ K * Ο„ * (𝔼 x, polynomial c x ^ 2) := by
have hsecond : 0 ≀ 𝔼 x, polynomial c x ^ 2 := by positivity
have hfourth := degree_fourth_moment_bound c hc
have hCS := Finset.expect_mul_sq_le_sq_mul_sq Finset.univ
(fun x => |polynomial c x|) (fun x => polynomial c x ^ 2)
have hp (a : ℝ) : |a| * a ^ 2 = |a| ^ 3 := by rw [← sq_abs]; ring
simp_rw [hp, sq_abs, ← pow_mul, Nat.reduceMul] at hCS
have hbound : (𝔼 x, |polynomial c x| ^ 3) ^ 2 ≀
(3 ^ K * Ο„ * (𝔼 x, polynomial c x ^ 2)) ^ 2 := by
calc
_ ≀ (𝔼 x, polynomial c x ^ 2) * (𝔼 x, polynomial c x ^ 4) := hCS
_ ≀ (𝔼 x, polynomial c x ^ 2) * (3 ^ K * (𝔼 x, polynomial c x ^ 2)) ^ 2 :=
mul_le_mul_of_nonneg_left hfourth hsecond
_ = (3 ^ K * (𝔼 x, polynomial c x ^ 2)) ^ 2 * (𝔼 x, polynomial c x ^ 2) := by ring
_ ≀ (3 ^ K * (𝔼 x, polynomial c x ^ 2)) ^ 2 * Ο„ ^ 2 :=
mul_le_mul_of_nonneg_left hsmall (sq_nonneg _)
_ = _ := by ring
exact (sq_le_sqβ‚€ (by positivity) (by positivity)).mp hbound
theorem walsh_flip {I : Type*} [Fintype I] [DecidableEq I]
(s x : Cube I) (i : I) :
walsh s (Function.update x i (!x i)) = (if s i then -1 else 1) * walsh s x := by
classical
have hp (j : I) : bitSign (s j && Function.update x i (!x i) j) =
(if j = i then (if s i then (-1 : ℝ) else 1) else 1) * bitSign (s j && x j) := by
by_cases h : j = i
Β· subst j; cases s i <;> cases x i <;> simp [bitSign]
Β· simp [h]
simp only [walsh, hp, Finset.prod_mul_distrib]
simp
noncomputable def discreteDiff {I : Type*} [Fintype I] [DecidableEq I]
(f : Cube I β†’ ℝ) (i : I) (x : Cube I) : ℝ := (f x - f (Function.update x i (!x i))) / 2
theorem polynomial_diff {I : Type*} [Fintype I] [DecidableEq I]
(c : Cube I β†’ ℝ) (i : I) :
discreteDiff (polynomial c) i = polynomial (fun s => if s i then c s else 0) := by
funext x
simp only [discreteDiff, polynomial, walsh_flip, ← Finset.sum_sub_distrib, Finset.sum_div]
apply Finset.sum_congr rfl
intro s _
cases s i <;> simp
theorem total_diff_second {I : Type*} [Fintype I] [DecidableEq I]
(c : Cube I β†’ ℝ) :
(βˆ‘ i, 𝔼 x, discreteDiff (polynomial c) i x ^ 2) =
βˆ‘ s, (Analytic.degree s : ℝ) * c s ^ 2 := by
simp only [polynomial_diff, polynomial_second_moment]
rw [Finset.sum_comm]
apply Finset.sum_congr rfl
intro s _
simp only [ite_pow, zero_pow (by omega : 2 β‰  0)]
rw [← Finset.sum_filter]
simp [Analytic.degree]
theorem total_diff_second_truncated {I : Type*} [Fintype I] [DecidableEq I]
(K : β„•) (c : Cube I β†’ ℝ) (hc : βˆ€ s, K < Analytic.degree s β†’ c s = 0) :
(βˆ‘ i, 𝔼 x, discreteDiff (polynomial c) i x ^ 2) ≀
K * (𝔼 x, polynomial c x ^ 2) := by
rw [total_diff_second, polynomial_second_moment, Finset.mul_sum]
apply Finset.sum_le_sum
intro s _
by_cases hs : Analytic.degree s ≀ K
Β· exact mul_le_mul_of_nonneg_right (by exact_mod_cast hs) (sq_nonneg _)
Β· rw [hc s (lt_of_not_ge hs)]; simp
theorem total_diff_third_truncated {n K : β„•} (c : Cube (Fin n) β†’ ℝ)
(hc : βˆ€ s, K < Analytic.degree s β†’ c s = 0) {Ο„ : ℝ} (hΟ„ : 0 ≀ Ο„)
(hsmall : βˆ€ i, (𝔼 x, discreteDiff (polynomial c) i x ^ 2) ≀ Ο„ ^ 2) :
(βˆ‘ i, 𝔼 x, |discreteDiff (polynomial c) i x| ^ 3) ≀
3 ^ K * Ο„ * K * (𝔼 x, polynomial c x ^ 2) := by
calc
_ ≀ βˆ‘ i, 3 ^ K * Ο„ * (𝔼 x, discreteDiff (polynomial c) i x ^ 2) := by
apply Finset.sum_le_sum
intro i _
have hi := hsmall i
rw [polynomial_diff] at hi ⊒
exact degree_third_moment_bound _ (fun s hs => by rw [hc s hs]; split_ifs <;> rfl)
hΟ„ hi
_ = 3 ^ K * Ο„ * (βˆ‘ i, 𝔼 x, discreteDiff (polynomial c) i x ^ 2) := by rw [Finset.mul_sum]
_ ≀ 3 ^ K * Ο„ * (K * (𝔼 x, polynomial c x ^ 2)) :=
mul_le_mul_of_nonneg_left (total_diff_second_truncated K c hc) (by positivity)
_ = _ := by ring
end OptimalMaxCut.BooleanFourthMoment
end
end OAI