Download data/lean/OAI/Computability/MaxCut/Estimates/Vec.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 37.3 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Computability/MaxCut/Estimates/Vec.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Computability/MaxCut/Estimates/Vec.lean
-
curl -L -o Vec.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Computability/MaxCut/Estimates/Vec.lean
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 | |