introvoyz045's picture
Migrated from GitHub
4a56cd6 verified
Raw History Blame Contribute Delete
37.3 kB
import Mathlib
import OAI.Computability.MaxCut.Games.KMSMomentTheorem
namespace OAI
namespace OptimalMaxCut.Unweighted
open Finset
open scoped BigOperators ComplexConjugate
abbrev Vec (p : β„•) := Fin 6 β†’ ZMod p
def dot {p : β„•} (x y : Vec p) : ZMod p := βˆ‘ i, x i * y i
variable {p : β„•} [Fact p.Prime]
@[simp] theorem card_vec : Fintype.card (Vec p) = p ^ 6 := by
simp [Vec]
omit [Fact (Nat.Prime p)] in
theorem dot_comm (x y : Vec p) : dot x y = dot y x := by
simp [dot, mul_comm]
@[simp] theorem dot_add_right (x y z : Vec p) :
dot x (y + z) = dot x y + dot x z := by
simp [dot, mul_add, sum_add_distrib]
@[simp] theorem dot_sub_left (x y z : Vec p) :
dot (x - y) z = dot x z - dot y z := by
simp [dot, sub_mul, sum_sub_distrib]
@[simp] theorem dot_zero_right (x : Vec p) : dot x 0 = 0 := by simp [dot]
noncomputable def dotChar (h : ZMod p) (x : Vec p) : AddChar (Vec p) β„‚ where
toFun y := ZMod.stdAddChar (h * dot x y)
map_zero_eq_one' := by simp
map_add_eq_mul' y z := by simp [mul_add, AddChar.map_add_eq_mul]
@[simp] theorem norm_stdChar (a : ZMod p) : β€–ZMod.stdAddChar aβ€– = 1 := by
rw [ZMod.stdAddChar_apply]
exact Circle.norm_coe _
theorem dotChar_ne_one (h : ZMod p) (hh : h β‰  0) (x : Vec p) (hx : x β‰  0) :
dotChar h x β‰  1 := by
obtain ⟨i, hi⟩ : βˆƒ i, x i β‰  0 := by
by_contra! hn
exact hx (funext hn)
apply AddChar.ne_one_iff.mpr
refine ⟨Pi.single i 1, ?_⟩
change ZMod.stdAddChar (h * dot x (Pi.single i 1)) β‰  1
have hd : dot x (Pi.single i 1) = x i := by simp [dot, Pi.single_apply]
rw [hd, ← (ZMod.stdAddChar (N := p)).map_zero_eq_one]
exact fun he => (mul_ne_zero hh hi) (ZMod.injective_stdAddChar he)
theorem sum_dotChar (h : ZMod p) (hh : h β‰  0) (x : Vec p) :
βˆ‘ y : Vec p, ZMod.stdAddChar (h * dot x y) =
if x = 0 then (p : β„‚) ^ 6 else 0 := by
split_ifs with hx
Β· subst x
simp [dot]
Β· exact AddChar.sum_eq_zero_of_ne_one (dotChar_ne_one h hh x hx)
@[simp] theorem conj_stdChar (a : ZMod p) :
conj (ZMod.stdAddChar a) = ZMod.stdAddChar (-a) := by
rw [← Complex.inv_eq_conj (norm_stdChar a), AddChar.map_neg_eq_inv]
theorem orthogonality (h : ZMod p) (hh : h β‰  0) (x z : Vec p) :
βˆ‘ y : Vec p, ZMod.stdAddChar (h * dot x y) *
conj (ZMod.stdAddChar (h * dot z y)) =
if x = z then (p : β„‚) ^ 6 else 0 := by
simp_rw [conj_stdChar, ← AddChar.map_add_eq_mul, ← sub_eq_add_neg,
← mul_sub, ← dot_sub_left]
rw [sum_dotChar h hh]
simp only [sub_eq_zero]
theorem rectangle_energy (h : ZMod p) (hh : h β‰  0) (T : Finset (Vec p)) :
βˆ‘ x : Vec p, β€–βˆ‘ y ∈ T, ZMod.stdAddChar (h * dot x y)β€– ^ 2 =
(p : ℝ) ^ 6 * T.card := by
have he : (βˆ‘ x : Vec p, (β€–βˆ‘ y ∈ T, ZMod.stdAddChar (h * dot x y)β€– ^ 2 : ℝ) : β„‚) =
(p : β„‚) ^ 6 * T.card := by
push_cast
simp_rw [← Complex.mul_conj', map_sum, sum_mul, mul_sum]
rw [sum_comm]
apply Eq.trans (sum_congr rfl (fun y hy => sum_comm ..))
simp_rw [dot_comm (_ : Vec p), orthogonality h hh]
simp [mul_comm]
exact_mod_cast he
theorem rectangle_character_bound (h : ZMod p) (hh : h β‰  0)
(S T : Finset (Vec p)) :
β€–βˆ‘ x ∈ S, βˆ‘ y ∈ T, ZMod.stdAddChar (h * dot x y)β€– ≀ (p : ℝ) ^ 9 := by
let f (x : Vec p) := β€–βˆ‘ y ∈ T, ZMod.stdAddChar (h * dot x y)β€–
have htriangle : β€–βˆ‘ x ∈ S, βˆ‘ y ∈ T, ZMod.stdAddChar (h * dot x y)β€– ≀ βˆ‘ x ∈ S, f x :=
norm_sum_le _ _
have hcs := sq_sum_le_card_mul_sum_sq (s := S) (f := f)
have henergy : βˆ‘ x ∈ S, f x ^ 2 ≀ (p : ℝ) ^ 6 * T.card := by
rw [← rectangle_energy h hh T]
exact sum_le_univ_sum_of_nonneg (fun _ => sq_nonneg _)
have hS : (S.card : ℝ) ≀ (p : ℝ) ^ 6 := by
exact_mod_cast (S.card_le_univ.trans_eq card_vec)
have hT : (T.card : ℝ) ≀ (p : ℝ) ^ 6 := by
exact_mod_cast (T.card_le_univ.trans_eq card_vec)
have hbound : (βˆ‘ x ∈ S, f x) ^ 2 ≀ (p : ℝ) ^ 18 := by
calc
_ ≀ S.card * βˆ‘ x ∈ S, f x ^ 2 := hcs
_ ≀ S.card * ((p : ℝ) ^ 6 * T.card) :=
mul_le_mul_of_nonneg_left henergy (by positivity)
_ ≀ (p : ℝ) ^ 6 * ((p : ℝ) ^ 6 * (p : ℝ) ^ 6) :=
mul_le_mul hS (mul_le_mul_of_nonneg_left hT (by positivity))
(by positivity) (by positivity)
_ = _ := by ring
have hnonneg : 0 ≀ βˆ‘ x ∈ S, f x := sum_nonneg (fun _ _ => norm_nonneg _)
have hpower : (p : ℝ) ^ 18 = ((p : ℝ) ^ 9) ^ 2 := by ring
rw [hpower] at hbound
have happ : βˆ‘ x ∈ S, f x ≀ (p : ℝ) ^ 9 :=
(sq_le_sqβ‚€ hnonneg (by positivity)).mp hbound
exact htriangle.trans happ
/-- Fourier coefficient of the residue indicator, probability normalization. -/
noncomputable def beta (I : Finset (ZMod p)) (h : ZMod p) : β„‚ :=
(p : β„‚)⁻¹ * βˆ‘ a ∈ I, ZMod.stdAddChar (-(h * a))
@[simp] theorem beta_zero (I : Finset (ZMod p)) :
beta I 0 = (I.card : β„‚) / p := by simp [beta, div_eq_mul_inv, mul_comm]
theorem beta_norm_le_one (I : Finset (ZMod p)) (h : ZMod p) : β€–beta I hβ€– ≀ 1 := by
have hp : 0 < (p : ℝ) := by exact_mod_cast (Fact.out : p.Prime).pos
have hc : (I.card : ℝ) ≀ p := by
exact_mod_cast (show I.card ≀ p by simpa using I.card_le_univ)
calc
_ = (p : ℝ)⁻¹ * β€–βˆ‘ a ∈ I, ZMod.stdAddChar (-(h * a))β€– := by
simp [beta]
_ ≀ (p : ℝ)⁻¹ * βˆ‘ a ∈ I, β€–ZMod.stdAddChar (-(h * a))β€– :=
mul_le_mul_of_nonneg_left (norm_sum_le _ _) (by positivity)
_ = (p : ℝ)⁻¹ * I.card := by simp
_ ≀ (p : ℝ)⁻¹ * p := mul_le_mul_of_nonneg_left hc (by positivity)
_ = 1 := inv_mul_cancelβ‚€ hp.ne'
theorem residue_fourier (I : Finset (ZMod p)) (a : ZMod p) :
(if a ∈ I then (1 : β„‚) else 0) =
βˆ‘ h : ZMod p, beta I h * ZMod.stdAddChar (h * a) := by
have hp : (p : β„‚) β‰  0 := by exact_mod_cast (Fact.out : p.Prime).ne_zero
symm
simp_rw [beta, mul_assoc, sum_mul, ← AddChar.map_add_eq_mul]
rw [← mul_sum, sum_comm]
have hin (b : ZMod p) :
βˆ‘ h : ZMod p, ZMod.stdAddChar (-(h * b) + h * a) =
if a = b then (p : β„‚) else 0 := by
simp_rw [show βˆ€ h : ZMod p, -(h * b) + h * a = h * (a - b) by intro; ring]
rw [AddChar.sum_mulShift _ (ZMod.isPrimitive_stdAddChar p)]
simp [sub_eq_zero]
simp_rw [hin]
by_cases ha : a ∈ I
Β· simp [ha, inv_mul_cancelβ‚€ hp]
Β· simp [ha]
def rectangleCount (I : Finset (ZMod p)) (S T : Finset (Vec p)) : β„• :=
βˆ‘ x ∈ S, βˆ‘ y ∈ T, if dot x y ∈ I then 1 else 0
/-- Isolate the zero frequency in the rectangle count. -/
theorem rectangle_fourier (I : Finset (ZMod p)) (S T : Finset (Vec p)) :
(rectangleCount I S T : β„‚) - (I.card : β„‚) / p * S.card * T.card =
βˆ‘ h ∈ (univ : Finset (ZMod p)).erase 0,
beta I h * βˆ‘ x ∈ S, βˆ‘ y ∈ T, ZMod.stdAddChar (h * dot x y) := by
have hfull : (rectangleCount I S T : β„‚) =
βˆ‘ h : ZMod p, beta I h * βˆ‘ x ∈ S, βˆ‘ y ∈ T, ZMod.stdAddChar (h * dot x y) := by
simp only [rectangleCount, Nat.cast_sum, Nat.cast_ite, Nat.cast_one, Nat.cast_zero]
simp_rw [residue_fourier]
calc
_ = βˆ‘ x ∈ S, βˆ‘ h : ZMod p, βˆ‘ y ∈ T,
beta I h * ZMod.stdAddChar (h * dot x y) := by
apply sum_congr rfl
intro x hx
rw [sum_comm]
_ = βˆ‘ h : ZMod p, βˆ‘ x ∈ S, βˆ‘ y ∈ T,
beta I h * ZMod.stdAddChar (h * dot x y) := by rw [sum_comm]
_ = _ := by simp_rw [mul_sum]
rw [hfull, ← sum_erase_add _ _ (mem_univ (0 : ZMod p))]
simp [mul_assoc]
/-- Absolute discrepancy in edge counts before dividing by Q=p^12. -/
theorem rectangle_discrepancy_count (I : Finset (ZMod p)) (S T : Finset (Vec p)) :
|(rectangleCount I S T : ℝ) - (I.card : ℝ) / p * S.card * T.card| ≀ (p : ℝ) ^ 10 := by
have hr : (rectangleCount I S T : β„‚) - (I.card : β„‚) / p * S.card * T.card =
((rectangleCount I S T : ℝ) - (I.card : ℝ) / p * S.card * T.card : ℝ) := by
push_cast
rfl
have hbound : β€–(rectangleCount I S T : β„‚) - (I.card : β„‚) / p * S.card * T.cardβ€– ≀
(p : ℝ) ^ 10 := by
rw [rectangle_fourier]
calc
_ ≀ βˆ‘ h ∈ (univ : Finset (ZMod p)).erase 0,
β€–beta I h * βˆ‘ x ∈ S, βˆ‘ y ∈ T, ZMod.stdAddChar (h * dot x y)β€– := norm_sum_le _ _
_ ≀ βˆ‘ h ∈ (univ : Finset (ZMod p)).erase 0, (p : ℝ) ^ 9 := by
apply sum_le_sum
intro h hh
rw [norm_mul]
exact (mul_le_mul (beta_norm_le_one I h)
(rectangle_character_bound h (mem_erase.mp hh).1 S T)
(norm_nonneg _) zero_le_one).trans_eq (one_mul _)
_ ≀ βˆ‘ _ : ZMod p, (p : ℝ) ^ 9 :=
sum_le_sum_of_subset_of_nonneg (erase_subset _ _) (fun _ _ _ => by positivity)
_ = (p : ℝ) ^ 10 := by simp [pow_succ, mul_comm]
rw [hr, Complex.norm_real, Real.norm_eq_abs] at hbound
exact hbound
def residueSet (w : β„š) : Finset (ZMod p) :=
(range ⌊(p : β„š) * wβŒ‹β‚Š).image (fun j : β„• => (j : ZMod p))
theorem card_residueSet (w : β„š) (_hw : 0 ≀ w) (hw1 : w ≀ 1) :
(residueSet (p := p) w).card = ⌊(p : β„š) * wβŒ‹β‚Š := by
have hn : ⌊(p : β„š) * wβŒ‹β‚Š ≀ p :=
Nat.floor_le_of_le (by nlinarith [show (0 : β„š) ≀ p by positivity])
rw [residueSet, card_image_of_injOn]
Β· exact card_range _
Β· intro a ha b hb hab
have ha' : a < p := (mem_range.mp ha).trans_le hn
have hb' : b < p := (mem_range.mp hb).trans_le hn
have h := congrArg ZMod.val hab
simpa [ZMod.val_natCast_of_lt ha', ZMod.val_natCast_of_lt hb'] using h
/-- The exact rounding loss uses the original rational weight, not a renormalized one. -/
theorem residue_density_error (w : β„š) (hw : 0 ≀ w) (hw1 : w ≀ 1) :
|((residueSet (p := p) w).card : ℝ) / p - w| ≀ 1 / (p : ℝ) := by
rw [card_residueSet w hw hw1]
have hp : 0 < (p : ℝ) := by exact_mod_cast (Fact.out : p.Prime).pos
have hfloor : ((⌊(p : β„š) * wβŒ‹β‚Š : β„•) : ℝ) ≀ (p : ℝ) * (w : ℝ) := by
exact_mod_cast (Nat.floor_le (show 0 ≀ (p : β„š) * w by positivity))
have hfloor' : (p : ℝ) * (w : ℝ) < (⌊(p : β„š) * wβŒ‹β‚Š : β„•) + (1 : ℝ) := by
exact_mod_cast (Nat.lt_floor_add_one ((p : β„š) * w))
have hlo : (⌊(p : β„š) * wβŒ‹β‚Š : ℝ) / p ≀ (w : ℝ) :=
(div_le_iffβ‚€ hp).mpr (by nlinarith)
have hhi : (w : ℝ) < ((⌊(p : β„š) * wβŒ‹β‚Š : ℝ) + 1) / p :=
(lt_div_iffβ‚€ hp).mpr (by nlinarith)
rw [add_div] at hhi
exact abs_le.mpr ⟨by linarith, by linarith [show (0 : ℝ) ≀ 1 / p by positivity]⟩
theorem rectangle_discrepancy (w : β„š) (hw : 0 ≀ w) (hw1 : w ≀ 1)
(S T : Finset (Vec p)) :
|(rectangleCount (residueSet w) S T : ℝ) / (p : ℝ) ^ 12 -
w * ((S.card : ℝ) / (p : ℝ) ^ 6) * ((T.card : ℝ) / (p : ℝ) ^ 6)| ≀
1 / (p : ℝ) + 1 / (p : ℝ) ^ 2 := by
have hp : 0 < (p : ℝ) := by exact_mod_cast (Fact.out : p.Prime).pos
let q : ℝ := (p : ℝ) ^ 6
have hq : 0 < q := by dsimp [q]; positivity
have hS : (S.card : ℝ) / q ≀ 1 := by
apply (div_le_one hq).mpr
dsimp [q]
exact_mod_cast (S.card_le_univ.trans_eq card_vec)
have hT : (T.card : ℝ) / q ≀ 1 := by
apply (div_le_one hq).mpr
dsimp [q]
exact_mod_cast (T.card_le_univ.trans_eq card_vec)
have hfrac : 0 ≀ (S.card : ℝ) / q * ((T.card : ℝ) / q) := by positivity
have hfrac1 : (S.card : ℝ) / q * ((T.card : ℝ) / q) ≀ 1 := by
nlinarith [show (0 : ℝ) ≀ S.card / q by positivity,
show (0 : ℝ) ≀ T.card / q by positivity]
have hfirst : |(rectangleCount (residueSet w) S T : ℝ) / (p : ℝ) ^ 12 -
((residueSet (p := p) w).card : ℝ) / p * (S.card / q) * (T.card / q)| ≀
1 / (p : ℝ) ^ 2 := by
have heq : (rectangleCount (residueSet w) S T : ℝ) / (p : ℝ) ^ 12 -
((residueSet (p := p) w).card : ℝ) / p * (S.card / q) * (T.card / q) =
((rectangleCount (residueSet w) S T : ℝ) -
((residueSet (p := p) w).card : ℝ) / p * S.card * T.card) / (p : ℝ) ^ 12 := by
dsimp [q]
field_simp
rw [heq, abs_div, abs_of_pos (pow_pos hp _)]
apply (div_le_iffβ‚€ (pow_pos hp _)).mpr
calc
_ ≀ (p : ℝ) ^ 10 := rectangle_discrepancy_count _ S T
_ = 1 / (p : ℝ) ^ 2 * (p : ℝ) ^ 12 := by field_simp
have hsecond : |(((residueSet (p := p) w).card : ℝ) / p - w) *
(S.card / q * (T.card / q))| ≀ 1 / (p : ℝ) := by
rw [abs_mul, abs_of_nonneg hfrac]
exact (mul_le_mul (residue_density_error w hw hw1) hfrac1 hfrac (by positivity)).trans_eq
(mul_one _)
have heq : (rectangleCount (residueSet w) S T : ℝ) / (p : ℝ) ^ 12 -
w * ((S.card : ℝ) / (p : ℝ) ^ 6) * ((T.card : ℝ) / (p : ℝ) ^ 6) =
((rectangleCount (residueSet w) S T : ℝ) / (p : ℝ) ^ 12 -
((residueSet (p := p) w).card : ℝ) / p * (S.card / q) * (T.card / q)) +
(((residueSet (p := p) w).card : ℝ) / p - w) * (S.card / q * (T.card / q)) := by
dsimp [q]
ring
rw [heq]
exact (abs_add_le _ _).trans ((add_le_add hfirst hsecond).trans_eq (add_comm _ _))
section Rounding
variable {V : Type*} [Fintype V] [DecidableEq V]
def cutMass (a : V β†’ ℝ) (Οƒ : V β†’ Bool) : ℝ :=
∏ i, if Οƒ i then a i else 1 - a i
@[simp] theorem sum_cutMass (a : V β†’ ℝ) : βˆ‘ Οƒ : V β†’ Bool, cutMass a Οƒ = 1 := by
simp_rw [cutMass]
rw [← Fintype.prod_sum (fun (i : V) (b : Bool) => if b then a i else 1 - a i)]
simp []
omit [DecidableEq V] in
theorem cutMass_nonneg (a : V β†’ ℝ) (ha : βˆ€ i, 0 ≀ a i ∧ a i ≀ 1) (Οƒ : V β†’ Bool) :
0 ≀ cutMass a Οƒ := by
apply prod_nonneg
intro i hi
exact ite_nonneg (ha i).1 (sub_nonneg.mpr (ha i).2)
/-- Two distinct coordinates of a product law, proved by finite product expansion. -/
theorem independent_pair (f : V β†’ Bool β†’ ℝ) (hf : βˆ€ i, βˆ‘ b : Bool, f i b = 1)
(u v : V) (huv : u β‰  v) (g k : Bool β†’ ℝ) :
βˆ‘ Οƒ : V β†’ Bool, (∏ i, f i (Οƒ i)) * g (Οƒ u) * k (Οƒ v) =
(βˆ‘ b : Bool, f u b * g b) * (βˆ‘ b : Bool, f v b * k b) := by
let F (i : V) (b : Bool) := f i b * (if i = u then g b else 1) *
(if i = v then k b else 1)
have hmul (Οƒ : V β†’ Bool) : (∏ i, f i (Οƒ i)) * g (Οƒ u) * k (Οƒ v) = ∏ i, F i (Οƒ i) := by
dsimp only [F]
simp only [prod_mul_distrib]
simp
simp_rw [hmul]
rw [← Fintype.prod_sum]
have hF (i : V) : (βˆ‘ b : Bool, F i b) =
(if i = u then (βˆ‘ b : Bool, f u b * g b) else 1) *
(if i = v then (βˆ‘ b : Bool, f v b * k b) else 1) := by
by_cases hiu : i = u
Β· subst i
simp [F, huv]
Β· by_cases hiv : i = v
Β· subst i
simp [F, Ne.symm huv]
Β· simpa [F, hiu, hiv] using hf i
simp_rw [hF]
rw [prod_mul_distrib]
simp
/-- Probability that two distinct vertices receive different cut signs. -/
theorem cutMass_crossing (a : V β†’ ℝ) (u v : V) (huv : u β‰  v) :
βˆ‘ Οƒ : V β†’ Bool, cutMass a Οƒ * (if Οƒ u β‰  Οƒ v then 1 else 0) =
a u * (1 - a v) + (1 - a u) * a v := by
let f (i : V) (b : Bool) : ℝ := if b then a i else 1 - a i
let g (b : Bool) : ℝ := if b then 1 else 0
let k (b : Bool) : ℝ := if b then 0 else 1
have hf (i : V) : βˆ‘ b : Bool, f i b = 1 := by simp [f]
have hcross (Οƒ : V β†’ Bool) : (if Οƒ u β‰  Οƒ v then (1 : ℝ) else 0) =
g (Οƒ u) * k (Οƒ v) + k (Οƒ u) * g (Οƒ v) := by
cases hu : Οƒ u <;> cases hv : Οƒ v <;> simp [g, k]
simp_rw [hcross, mul_add, ← mul_assoc]
rw [sum_add_distrib]
change (βˆ‘ Οƒ : V β†’ Bool, (∏ i, f i (Οƒ i)) * g (Οƒ u) * k (Οƒ v)) +
(βˆ‘ Οƒ : V β†’ Bool, (∏ i, f i (Οƒ i)) * k (Οƒ u) * g (Οƒ v)) = _
rw [independent_pair f hf u v huv, independent_pair f hf u v huv]
simp [f, g, k]
end Rounding
/-- Weighted cut on unordered distinct vertex pairs, on the original weight scale. -/
def weightedCut {N : β„•} (w : Fin N β†’ Fin N β†’ ℝ) (Οƒ : Fin N β†’ Bool) : ℝ :=
βˆ‘ u, βˆ‘ v, if u < v ∧ Οƒ u β‰  Οƒ v then w u v else 0
noncomputable def weightedMax {N : β„•} (w : Fin N β†’ Fin N β†’ ℝ) : ℝ :=
(univ.image (weightedCut w)).max' (univ_nonempty.image _)
theorem weightedCut_le_max {N : β„•} (w : Fin N β†’ Fin N β†’ ℝ) (Οƒ : Fin N β†’ Bool) :
weightedCut w Οƒ ≀ weightedMax w := by
exact (univ.image (weightedCut w)).le_max' _ (mem_image.mpr βŸ¨Οƒ, mem_univ _, rfl⟩)
theorem weightedMax_attained {N : β„•} (w : Fin N β†’ Fin N β†’ ℝ) :
βˆƒ Οƒ : Fin N β†’ Bool, weightedCut w Οƒ = weightedMax w := by
have hm := (univ.image (weightedCut w)).max'_mem (univ_nonempty.image _)
obtain βŸ¨Οƒ, hΟƒ, he⟩ := mem_image.mp hm
exact βŸ¨Οƒ, he⟩
/-- Expected cut weight under independent randomized rounding. -/
def fractionalCut {N : β„•} (w : Fin N β†’ Fin N β†’ ℝ) (a : Fin N β†’ ℝ) : ℝ :=
βˆ‘ u, βˆ‘ v, if u < v then w u v * (a u * (1 - a v) + (1 - a u) * a v) else 0
theorem fractionalCut_expectation {N : β„•} (w : Fin N β†’ Fin N β†’ ℝ) (a : Fin N β†’ ℝ) :
fractionalCut w a = βˆ‘ Οƒ : Fin N β†’ Bool, cutMass a Οƒ * weightedCut w Οƒ := by
unfold fractionalCut weightedCut
symm
simp_rw [mul_sum]
rw [sum_comm]
apply sum_congr rfl
intro u hu
rw [sum_comm]
apply sum_congr rfl
intro v hv
by_cases huv : u < v
Β· simp only [huv, true_and, ite_true]
have h (Οƒ : Fin N β†’ Bool) : cutMass a Οƒ * (if Οƒ u β‰  Οƒ v then w u v else 0) =
w u v * (cutMass a Οƒ * (if Οƒ u β‰  Οƒ v then 1 else 0)) := by
split_ifs <;> ring
simp_rw [h]
rw [← mul_sum, cutMass_crossing a u v (ne_of_lt huv)]
Β· simp [huv]
/-- Rounding cannot exceed an actual integral maximum cut. -/
theorem fractionalCut_le_max {N : β„•} (w : Fin N β†’ Fin N β†’ ℝ) (a : Fin N β†’ ℝ)
(ha : βˆ€ u, 0 ≀ a u ∧ a u ≀ 1) : fractionalCut w a ≀ weightedMax w := by
rw [fractionalCut_expectation]
calc
_ ≀ βˆ‘ Οƒ : Fin N β†’ Bool, cutMass a Οƒ * weightedMax w :=
sum_le_sum (fun Οƒ _ => mul_le_mul_of_nonneg_left (weightedCut_le_max w Οƒ)
(cutMass_nonneg a ha Οƒ))
_ = weightedMax w := by rw [← sum_mul, sum_cutMass, one_mul]
def vecEquiv : Vec p ≃ Fin (p ^ 6) :=
(Equiv.arrowCongr (Equiv.refl (Fin 6)) (ZMod.finEquiv p).symm.toEquiv).trans
finFunctionFinEquiv
/-- Explicit lexicographic indexing of all Np^6 output vertices. -/
def vertexEquiv (N : β„•) : (Fin N Γ— Vec p) ≃ Fin (N * p ^ 6) :=
(Equiv.prodCongr (Equiv.refl (Fin N)) vecEquiv).trans finProdFinEquiv
@[simp] theorem vertexEquiv_val {N : β„•} (u : Fin N) (x : Vec p) :
(vertexEquiv N (u, x) : β„•) = (vecEquiv x : β„•) + p ^ 6 * (u : β„•) := rfl
theorem vertexEquiv_lt_of_lt {N : β„•} (u v : Fin N) (x y : Vec p) (huv : u < v) :
vertexEquiv N (u, x) < vertexEquiv N (v, y) := by
change (vecEquiv x : β„•) + p ^ 6 * (u : β„•) < (vecEquiv y : β„•) + p ^ 6 * (v : β„•)
have h := Nat.mul_le_mul_left (p ^ 6) (show (u : β„•) + 1 ≀ (v : β„•) from huv)
have hx := (vecEquiv x).isLt
nlinarith
theorem vertexEquiv_lt_iff_of_ne {N : β„•} (u v : Fin N) (x y : Vec p) (huv : u β‰  v) :
vertexEquiv N (u, x) < vertexEquiv N (v, y) ↔ u < v := by
constructor
Β· intro h
rcases lt_or_gt_of_ne huv with huv' | hvu'
Β· exact huv'
Β· exact False.elim (lt_asymm h (vertexEquiv_lt_of_lt v u y x hvu'))
Β· exact vertexEquiv_lt_of_lt u v x y
/-- The actual simple unweighted finite output graph, not an abstract promise. -/
def blowupGraph {N : β„•} (w : Fin N β†’ Fin N β†’ β„š) (hw : βˆ€ u v, w u v = w v u) : Graph where
vertices := N * p ^ 6
adj i j :=
let a := (vertexEquiv N).symm i
let b := (vertexEquiv N).symm j
decide (a.1 β‰  b.1 ∧ dot a.2 b.2 ∈ residueSet (w a.1 b.1))
symmetric i j := by
dsimp only
rw [dot_comm, hw]
simp only [ne_comm]
loopless i := by simp
/-- The scale is p^12, not the output number of edges. -/
def blowupOutput {N : β„•} (w : Fin N β†’ Fin N β†’ β„š) (hw : βˆ€ u v, w u v = w v u) : ScaledGraph where
graph := blowupGraph (p := p) w hw
scale := p ^ 12
scale_pos := pow_pos (Fact.out : p.Prime).pos _
@[simp] theorem blowup_adj {N : β„•} (w : Fin N β†’ Fin N β†’ β„š)
(hw : βˆ€ u v, w u v = w v u) (u v : Fin N) (x y : Vec p) :
(blowupGraph w hw).adj (vertexEquiv N (u, x)) (vertexEquiv N (v, y)) =
decide (u β‰  v ∧ dot x y ∈ residueSet (w u v)) := by
simp [blowupGraph]
/-- A cut expressed in cluster coordinates. -/
def clusterCutCount {N : β„•} (w : Fin N β†’ Fin N β†’ β„š) (Οƒ : Fin N β†’ Vec p β†’ Bool) : β„• :=
βˆ‘ u, βˆ‘ v, if u < v then
βˆ‘ x, βˆ‘ y, if dot x y ∈ residueSet (w u v) ∧ Οƒ u x β‰  Οƒ v y then 1 else 0
else 0
theorem blowup_cutSize {N : β„•} (w : Fin N β†’ Fin N β†’ β„š)
(hw : βˆ€ u v, w u v = w v u) (cut : Fin (N * p ^ 6) β†’ Bool) :
(blowupGraph w hw).cutSize cut =
clusterCutCount w (fun u x => cut (vertexEquiv N (u, x))) := by
change (βˆ‘ u : Fin (N * p ^ 6), βˆ‘ v : Fin (N * p ^ 6),
if u < v ∧ (blowupGraph (p := p) w hw).adj u v = true ∧ cut u β‰  cut v
then (1 : β„•) else 0) = _
rw [← Equiv.sum_comp (vertexEquiv N)]
simp_rw [← Equiv.sum_comp (vertexEquiv N)]
simp only [Fintype.sum_prod_type]
unfold clusterCutCount
apply sum_congr rfl
intro u hu
rw [sum_comm]
apply sum_congr rfl
intro v hv
by_cases huv : u < v
Β· simp only [huv, ite_true]
apply sum_congr rfl
intro x hx
apply sum_congr rfl
intro y hy
simp [blowup_adj, vertexEquiv_lt_of_lt u v x y huv, ne_of_lt huv]
Β· simp only [huv, ite_false]
apply sum_eq_zero
intro x hx
apply sum_eq_zero
intro y hy
by_cases heq : u = v
Β· subst v
simp
Β· have hn : Β¬ vertexEquiv N (u, x) < vertexEquiv N (v, y) :=
fun h => huv ((vertexEquiv_lt_iff_of_ne u v x y heq).mp h)
simp [hn]
/-- Either side of a cut inside one cluster. -/
def cutSet (Οƒ : Vec p β†’ Bool) (b : Bool) : Finset (Vec p) :=
univ.filter (fun x => Οƒ x = b)
@[simp] theorem mem_cutSet (Οƒ : Vec p β†’ Bool) (b : Bool) (x : Vec p) :
x ∈ cutSet Οƒ b ↔ Οƒ x = b := by simp [cutSet]
theorem cutSet_card_partition (Οƒ : Vec p β†’ Bool) :
(cutSet Οƒ true).card + (cutSet Οƒ false).card = p ^ 6 := by
have h := card_filter_add_card_filter_not (s := (univ : Finset (Vec p)))
(fun x => Οƒ x = true)
simpa [cutSet] using h
/-- Fraction of a cluster on the positive side, on the exact p^6 scale. -/
noncomputable def cutFraction (Οƒ : Vec p β†’ Bool) : ℝ := (cutSet Οƒ true).card / (p : ℝ) ^ 6
theorem cutFraction_mem (Οƒ : Vec p β†’ Bool) :
0 ≀ cutFraction Οƒ ∧ cutFraction Οƒ ≀ 1 := by
have hp : 0 < (p : ℝ) := by exact_mod_cast (Fact.out : p.Prime).pos
constructor
Β· unfold cutFraction; positivity
Β· unfold cutFraction
apply (div_le_one (pow_pos hp _)).mpr
exact_mod_cast ((cutSet Οƒ true).card_le_univ.trans_eq card_vec)
theorem cutFraction_false (Οƒ : Vec p β†’ Bool) :
((cutSet Οƒ false).card : ℝ) / (p : ℝ) ^ 6 = 1 - cutFraction Οƒ := by
have hp : (p : ℝ) ^ 6 β‰  0 := pow_ne_zero _ (by exact_mod_cast (Fact.out : p.Prime).ne_zero)
have hc : ((cutSet Οƒ true).card : ℝ) + (cutSet Οƒ false).card = (p : ℝ) ^ 6 := by
exact_mod_cast cutSet_card_partition Οƒ
have h : cutFraction Οƒ + ((cutSet Οƒ false).card : ℝ) / (p : ℝ) ^ 6 = 1 := by
rw [cutFraction, ← add_div, hc, div_self hp]
linarith
/-- The exact edge count crossing between two distinct clusters. -/
def pairCutCount (w : β„š) (Οƒ Ο„ : Vec p β†’ Bool) : β„• :=
βˆ‘ x, βˆ‘ y, if dot x y ∈ residueSet w ∧ Οƒ x β‰  Ο„ y then 1 else 0
theorem rectangle_cutSet (I : Finset (ZMod p)) (Οƒ Ο„ : Vec p β†’ Bool) (b c : Bool) :
rectangleCount I (cutSet Οƒ b) (cutSet Ο„ c) =
βˆ‘ x, βˆ‘ y, if Οƒ x = b ∧ Ο„ y = c ∧ dot x y ∈ I then 1 else 0 := by
simp only [rectangleCount, cutSet, sum_filter]
apply sum_congr rfl
intro x hx
by_cases hb : Οƒ x = b
Β· simp only [hb, ite_true, true_and]
apply sum_congr rfl
intro y hy
by_cases hc : Ο„ y = c <;> simp [hc]
Β· simp [hb]
theorem pairCutCount_rectangles (w : β„š) (Οƒ Ο„ : Vec p β†’ Bool) :
pairCutCount w Οƒ Ο„ =
rectangleCount (residueSet w) (cutSet Οƒ true) (cutSet Ο„ false) +
rectangleCount (residueSet w) (cutSet Οƒ false) (cutSet Ο„ true) := by
rw [rectangle_cutSet, rectangle_cutSet, ← sum_add_distrib]
unfold pairCutCount
apply sum_congr rfl
intro x hx
rw [← sum_add_distrib]
apply sum_congr rfl
intro y hy
cases hσ : σ x <;> cases hτ : τ y <;> simp []
theorem pairCutCount_discrepancy (w : β„š) (hw : 0 ≀ w) (hw1 : w ≀ 1)
(Οƒ Ο„ : Vec p β†’ Bool) :
|(pairCutCount w Οƒ Ο„ : ℝ) / (p : ℝ) ^ 12 -
w * (cutFraction Οƒ * (1 - cutFraction Ο„) + (1 - cutFraction Οƒ) * cutFraction Ο„)| ≀
2 * (1 / (p : ℝ) + 1 / (p : ℝ) ^ 2) := by
have h₁ := rectangle_discrepancy w hw hw1 (cutSet Οƒ true) (cutSet Ο„ false)
have hβ‚‚ := rectangle_discrepancy w hw hw1 (cutSet Οƒ false) (cutSet Ο„ true)
rw [cutFraction_false] at h₁ hβ‚‚
change |(rectangleCount _ _ _ : ℝ) / (p : ℝ) ^ 12 -
w * cutFraction Οƒ * (1 - cutFraction Ο„)| ≀ _ at h₁
change |(rectangleCount _ _ _ : ℝ) / (p : ℝ) ^ 12 -
w * (1 - cutFraction Οƒ) * cutFraction Ο„| ≀ _ at hβ‚‚
rw [pairCutCount_rectangles, Nat.cast_add, add_div]
calc
_ = |((rectangleCount (residueSet w) (cutSet Οƒ true) (cutSet Ο„ false) : ℝ) /
(p : ℝ) ^ 12 - w * cutFraction Οƒ * (1 - cutFraction Ο„)) +
((rectangleCount (residueSet w) (cutSet Οƒ false) (cutSet Ο„ true) : ℝ) /
(p : ℝ) ^ 12 - w * (1 - cutFraction Οƒ) * cutFraction Ο„)| := by congr 1; ring
_ ≀ _ := (abs_add_le _ _).trans (by linarith)
/-- Twice the number of unordered distinct pairs, including N=0 and N=1. -/
theorem twice_pair_count (N : β„•) :
(βˆ‘ u : Fin N, βˆ‘ v : Fin N, if u < v then (2 : ℝ) else 0) =
(N : ℝ) * ((N : ℝ) - 1) := by
induction N with
| zero => simp
| succ N ih =>
simp only [Fin.sum_univ_succ, Fin.not_lt_zero, ite_false, Fin.succ_pos,
ite_true, sum_const, card_fin, nsmul_eq_mul, zero_add, Fin.succ_lt_succ_iff,
ih, Nat.cast_add, Nat.cast_one]
ring
/-- Summing the exact pair loss on the common unnormalized scale. -/
theorem clusterCutCount_discrepancy {N : β„•} (w : Fin N β†’ Fin N β†’ β„š)
(hbound : βˆ€ u v, u < v β†’ 0 ≀ w u v ∧ w u v ≀ 1)
(Οƒ : Fin N β†’ Vec p β†’ Bool) :
|(clusterCutCount w Οƒ : ℝ) / (p : ℝ) ^ 12 -
fractionalCut (fun u v => (w u v : ℝ)) (fun u => cutFraction (Οƒ u))| ≀
(N : ℝ) * ((N : ℝ) - 1) * (1 / (p : ℝ) + 1 / (p : ℝ) ^ 2) := by
change |((βˆ‘ u, βˆ‘ v, if u < v then pairCutCount (w u v) (Οƒ u) (Οƒ v) else 0 : β„•) : ℝ) /
(p : ℝ) ^ 12 - βˆ‘ u, βˆ‘ v, if u < v then
(w u v : ℝ) * (cutFraction (Οƒ u) * (1 - cutFraction (Οƒ v)) +
(1 - cutFraction (Οƒ u)) * cutFraction (Οƒ v)) else 0| ≀ _
simp only [Nat.cast_sum, Nat.cast_ite, Nat.cast_zero, sum_div]
rw [← sum_sub_distrib]
simp_rw [← sum_sub_distrib]
calc
_ ≀ βˆ‘ u, βˆ‘ v,
|(if u < v then (pairCutCount (w u v) (Οƒ u) (Οƒ v) : ℝ) else 0) /
(p : ℝ) ^ 12 - (if u < v then
(w u v : ℝ) * (cutFraction (Οƒ u) * (1 - cutFraction (Οƒ v)) +
(1 - cutFraction (Οƒ u)) * cutFraction (Οƒ v)) else 0)| :=
(abs_sum_le_sum_abs _ _).trans (sum_le_sum (fun u _ => abs_sum_le_sum_abs _ _))
_ ≀ βˆ‘ u, βˆ‘ v, if u < v then 2 * (1 / (p : ℝ) + 1 / (p : ℝ) ^ 2) else 0 := by
apply sum_le_sum
intro u hu
apply sum_le_sum
intro v hv
by_cases huv : u < v
Β· simpa only [huv, ite_true] using
pairCutCount_discrepancy (w u v) (hbound u v huv).1 (hbound u v huv).2 (Οƒ u) (Οƒ v)
Β· simp [huv]
_ = _ := by
have he (u v : Fin N) :
(if u < v then 2 * (1 / (p : ℝ) + 1 / (p : ℝ) ^ 2) else 0) =
(if u < v then (2 : ℝ) else 0) * (1 / (p : ℝ) + 1 / (p : ℝ) ^ 2) := by
split_ifs <;> ring
simp_rw [he, ← sum_mul]
rw [twice_pair_count]
/-- Every cut lies below the finite unweighted optimum. -/
theorem graph_cut_le_max (G : Graph) (Οƒ : Fin G.vertices β†’ Bool) :
G.cutSize Οƒ ≀ G.maxCut := by
unfold Graph.maxCut
exact le_sup (s := univ.image G.cutSize) (f := id) (mem_image.mpr βŸ¨Οƒ, mem_univ _, rfl⟩)
/-- The finite unweighted optimum is attained by an actual cut. -/
theorem graph_max_attained (G : Graph) : βˆƒ Οƒ, G.cutSize Οƒ = G.maxCut := by
have h := sup_mem_of_nonempty (s := (univ : Finset (Fin G.vertices β†’ Bool)))
(f := G.cutSize) univ_nonempty
obtain βŸ¨Οƒ, hΟƒ, he⟩ := h
refine βŸ¨Οƒ, ?_⟩
simpa [Graph.maxCut, sup_image, Function.comp_def] using he
@[simp] theorem cutFraction_const (b : Bool) :
cutFraction (p := p) (fun _ => b) = if b then 1 else 0 := by
have hp : (p : ℝ) β‰  0 := by exact_mod_cast (Fact.out : p.Prime).ne_zero
cases b <;> simp [cutFraction, cutSet, hp]
theorem fractionalCut_integral {N : β„•} (w : Fin N β†’ Fin N β†’ ℝ) (Οƒ : Fin N β†’ Bool) :
fractionalCut w (fun u => if Οƒ u then 1 else 0) = weightedCut w Οƒ := by
unfold fractionalCut weightedCut
apply sum_congr rfl
intro u hu
apply sum_congr rfl
intro v hv
cases hσ : σ u <;> cases hτ : σ v <;> simp [hσ, hτ]
/-- Full optimum comparison for the actual simple finite graph.
No complexity certificate is asserted in this analytic/combinatorial theorem. -/
theorem blowup_maxCut_error {N : β„•} (w : Fin N β†’ Fin N β†’ β„š)
(hw : βˆ€ u v, w u v = w v u)
(hbound : βˆ€ u v, u < v β†’ 0 ≀ w u v ∧ w u v ≀ 1) :
|((blowupGraph (p := p) w hw).maxCut : ℝ) / (p : ℝ) ^ 12 -
weightedMax (fun u v => (w u v : ℝ))| ≀
(N : ℝ) * ((N : ℝ) - 1) * (1 / (p : ℝ) + 1 / (p : ℝ) ^ 2) := by
have hp : 0 < (p : ℝ) := by exact_mod_cast (Fact.out : p.Prime).pos
apply abs_le.mpr
constructor
Β· obtain βŸ¨Οƒ, hΟƒβŸ© := weightedMax_attained (fun u v => (w u v : ℝ))
let cut : Fin (N * p ^ 6) β†’ Bool := fun i => Οƒ ((vertexEquiv N).symm i).1
have he : (blowupGraph (p := p) w hw).cutSize cut =
clusterCutCount w (fun u (_ : Vec p) => Οƒ u) := by
rw [blowup_cutSize]
simp only [cut, Equiv.symm_apply_apply]
have hc := clusterCutCount_discrepancy w hbound (fun u (_ : Vec p) => Οƒ u)
simp only [cutFraction_const, fractionalCut_integral, hσ] at hc
have hmax := div_le_div_of_nonneg_right
(show ((blowupGraph (p := p) w hw).cutSize cut : ℝ) ≀
(blowupGraph (p := p) w hw).maxCut from by exact_mod_cast graph_cut_le_max (blowupGraph (p := p) w hw) cut)
(le_of_lt (pow_pos hp 12))
rw [he] at hmax
linarith [(abs_le.mp hc).1]
· obtain ⟨cut, hcut⟩ := graph_max_attained (blowupGraph (p := p) w hw)
have hc := clusterCutCount_discrepancy w hbound
(fun u x => cut (vertexEquiv N (u, x)))
rw [← blowup_cutSize w hw cut, hcut] at hc
have hf := fractionalCut_le_max (fun u v => (w u v : ℝ))
(fun u => cutFraction (fun x => cut (vertexEquiv N (u, x))))
(fun u => cutFraction_mem _)
linarith [(abs_le.mp hc).2]
def totalWeight {N : β„•} (w : Fin N β†’ Fin N β†’ β„š) : β„š :=
βˆ‘ u, βˆ‘ v, if u < v then w u v else 0
theorem normalized_pair_bound {N : β„•} (w : Fin N β†’ Fin N β†’ β„š)
(hnonneg : βˆ€ u v, u < v β†’ 0 ≀ w u v) (hscale : totalWeight w ≀ 1) :
βˆ€ u v, u < v β†’ 0 ≀ w u v ∧ w u v ≀ 1 := by
intro u v huv
refine ⟨hnonneg u v huv, ?_⟩
have hx (u v : Fin N) : 0 ≀ (if u < v then w u v else 0) := by
split_ifs with h
Β· exact hnonneg u v h
Β· exact le_rfl
have h₁ := single_le_sum (fun v (_ : v ∈ (univ : Finset (Fin N))) => hx u v) (mem_univ v)
have hβ‚‚ : (βˆ‘ v, if u < v then w u v else 0) ≀ totalWeight w := by
unfold totalWeight
apply single_le_sum (s := univ) (a := u)
Β· intro u hu
exact sum_nonneg (fun v _ => hx u v)
Β· exact mem_univ _
have h₁' : w u v ≀ βˆ‘ v, if u < v then w u v else 0 := by
simpa only [huv, ite_true] using h₁
exact h₁'.trans (hβ‚‚.trans hscale)
/-- Bounded deterministic prime search. Its bound follows from Bertrand,
not a prime oracle or an unbounded assumed operation. -/
def searchPrime (m : β„•) : β„• :=
((List.range (2 * (m + 1) + 1)).find? (fun q => decide (m + 1 < q ∧ q.Prime))).getD 2
theorem searchPrime_spec (m : β„•) :
(searchPrime m).Prime ∧ m < searchPrime m ∧ searchPrime m ≀ 2 * (m + 1) := by
obtain ⟨q, hq, hmq, hqbound⟩ := Nat.exists_prime_lt_and_le_two_mul (m + 1) (by omega)
have hs : ((List.range (2 * (m + 1) + 1)).find?
(fun q => decide (m + 1 < q ∧ q.Prime))).isSome := by
apply List.find?_isSome.mpr
exact ⟨q, List.mem_range.mpr (by omega), by simp [hmq, hq]⟩
cases hf : ((List.range (2 * (m + 1) + 1)).find?
(fun q => decide (m + 1 < q ∧ q.Prime))) with
| none =>
rw [hf] at hs
contradiction
| some q =>
have hq' : m + 1 < q ∧ q.Prime := by simpa using List.find?_some hf
have hq'' := List.mem_range.mp (List.mem_of_find?_eq_some hf)
simpa only [searchPrime, hf, Option.getD_some] using
(show q.Prime ∧ m < q ∧ q ≀ 2 * (m + 1) from ⟨hq'.2, by omega, by omega⟩)
def deterministicOutput {N : β„•} (K : β„•) (w : Fin N β†’ Fin N β†’ β„š)
(hw : βˆ€ u v, w u v = w v u) : ScaledGraph :=
let p := searchPrime (K * (N + 1) ^ 2)
haveI : Fact p.Prime := ⟨(searchPrime_spec _).1⟩
blowupOutput (p := p) w hw
theorem selected_prime_error (N K : β„•) (hK : 0 < K) :
let p := searchPrime (K * (N + 1) ^ 2)
(N : ℝ) * ((N : ℝ) - 1) * (1 / (p : ℝ) + 1 / (p : ℝ) ^ 2) ≀ 2 / (K : ℝ) := by
dsimp only
let p := searchPrime (K * (N + 1) ^ 2)
have hp : 0 < (p : ℝ) := by exact_mod_cast (searchPrime_spec _).1.pos
have hp1 : 1 ≀ (p : ℝ) := by exact_mod_cast (searchPrime_spec _).1.one_lt.le
have hK' : 0 < (K : ℝ) := by exact_mod_cast hK
have hN : 0 ≀ (N : ℝ) := by positivity
have hlarge : (K : ℝ) * ((N : ℝ) + 1) ^ 2 ≀ (p : ℝ) := by
exact_mod_cast (searchPrime_spec (K * (N + 1) ^ 2)).2.1.le
have hpair : 0 ≀ (N : ℝ) * ((N : ℝ) - 1) := by
rw [← twice_pair_count]
apply sum_nonneg
intro u hu
apply sum_nonneg
intro v hv
split_ifs <;> norm_num
have hr : 1 / (p : ℝ) + 1 / (p : ℝ) ^ 2 ≀ 2 / (p : ℝ) := by
have hh := one_div_le_one_div_of_le hp (show (p : ℝ) ≀ (p : ℝ) ^ 2 by nlinarith)
calc
_ ≀ 1 / (p : ℝ) + 1 / (p : ℝ) := add_le_add (le_refl _) hh
_ = 2 / (p : ℝ) := by ring
calc
_ ≀ (N : ℝ) * ((N : ℝ) - 1) * (2 / (p : ℝ)) := mul_le_mul_of_nonneg_left hr hpair
_ ≀ ((N : ℝ) + 1) ^ 2 * (2 / (p : ℝ)) :=
mul_le_mul_of_nonneg_right (by nlinarith) (by positivity)
_ ≀ 2 / (K : ℝ) := by
rw [← mul_div_assoc]
apply (div_le_div_iffβ‚€ hp hK').mpr
nlinarith
theorem deterministicOutput_error {N : β„•} (K : β„•) (hK : 0 < K)
(w : Fin N β†’ Fin N β†’ β„š) (hw : βˆ€ u v, w u v = w v u)
(hnonneg : βˆ€ u v, u < v β†’ 0 ≀ w u v) (hscale : totalWeight w ≀ 1) :
|((deterministicOutput K w hw).graph.maxCut : ℝ) / (deterministicOutput K w hw).scale -
weightedMax (fun u v => (w u v : ℝ))| ≀ 2 / (K : ℝ) := by
let p := searchPrime (K * (N + 1) ^ 2)
have : Fact p.Prime := ⟨(searchPrime_spec _).1⟩
have h := blowup_maxCut_error (p := p) w hw (normalized_pair_bound w hnonneg hscale)
have he := h.trans (selected_prime_error N K hK)
simpa only [deterministicOutput, blowupOutput, Nat.cast_pow] using he
/-- Explicit polynomial vertex bound for fixed K. It is a size bound, not
by itself a certificate of polynomial running time. -/
theorem deterministicOutput_vertex_bound {N : β„•} (K : β„•)
(w : Fin N β†’ Fin N β†’ β„š) (hw : βˆ€ u v, w u v = w v u) :
(deterministicOutput K w hw).graph.vertices ≀ N * (2 * (K * (N + 1) ^ 2 + 1)) ^ 6 := by
exact Nat.mul_le_mul_left N (Nat.pow_le_pow_left (searchPrime_spec _).2.2 6)
theorem deterministicOutput_scale_bound {N : β„•} (K : β„•)
(w : Fin N β†’ Fin N β†’ β„š) (hw : βˆ€ u v, w u v = w v u) :
(deterministicOutput K w hw).scale ≀ (2 * (K * (N + 1) ^ 2 + 1)) ^ 12 := by
exact Nat.pow_le_pow_left (searchPrime_spec _).2.2 12
theorem unweighted_finite_error (Ξ΅ : ℝ) (hΞ΅ : 0 < Ξ΅) :
βˆƒ K : β„•, 0 < K ∧ βˆ€ (N : β„•) (w : Fin N β†’ Fin N β†’ β„š)
(hw : βˆ€ u v, w u v = w v u)
(_hnonneg : βˆ€ u v, u < v β†’ 0 ≀ w u v) (_hscale : totalWeight w ≀ 1),
|((deterministicOutput K w hw).graph.maxCut : ℝ) / (deterministicOutput K w hw).scale -
weightedMax (fun u v => (w u v : ℝ))| ≀ Ξ΅ := by
obtain ⟨K, hK⟩ := exists_nat_gt (2 / Ρ)
have hK' : 0 < (K : ℝ) := (div_pos (by norm_num) hΞ΅).trans hK
have hKpos : 0 < K := by exact_mod_cast hK'
have he : 2 / (K : ℝ) ≀ Ξ΅ := by
apply le_of_lt
apply (div_lt_iffβ‚€ hK').mpr
have h := (div_lt_iffβ‚€ hΞ΅).mp hK
nlinarith
refine ⟨K, hKpos, ?_⟩
intro N w hw hnonneg hscale
exact (deterministicOutput_error K hKpos w hw hnonneg hscale).trans he
end OptimalMaxCut.Unweighted
/-! Exact tree gate and slice symmetry. Sign values are encoded in ZMod 2:
b encodes (-1)^b. -/
end OAI