Download data/lean/OAI/Computability/MaxCut/PCP/CayleySampling.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 33 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Computability/MaxCut/PCP/CayleySampling.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Computability/MaxCut/PCP/CayleySampling.lean
-
curl -L -o CayleySampling.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Computability/MaxCut/PCP/CayleySampling.lean
33 kB
| import Mathlib | |
| import OAI.Computability.MaxCut.PCP.PortTables | |
| namespace OAI | |
| noncomputable section | |
| namespace MaxCutGames.Foundations.PCP.CayleySampling | |
| open scoped BigOperators | |
| open Finset | |
| open MaxCutGames.Foundations.Hastad | |
| variable {V D : Type*} | |
| /-- The common fiber left after separating a Boolean character's sign. -/ | |
| abbrev FalseFiber (Ο : V β Bool) := {x : V // Ο x = false} | |
| def falseRepresentative (Ο : V β Bool) (flip : V β V) | |
| (hΟ : β x, Ο (flip x) = !(Ο x)) (x : V) : FalseFiber Ο := | |
| if h : Ο x = false then β¨x, hβ© | |
| else β¨flip x, by cases hx : Ο x <;> simp_allβ© | |
| def booleanSplitEquiv (Ο : V β Bool) (flip : V β V) | |
| (hflip : Function.Involutive flip) (hΟ : β x, Ο (flip x) = !(Ο x)) : | |
| V β Bool Γ FalseFiber Ο where | |
| toFun x := (Ο x, falseRepresentative Ο flip hΟ x) | |
| invFun p := if p.1 then flip p.2.val else p.2.val | |
| left_inv x := by | |
| cases hx : Ο x <;> simp [falseRepresentative, hx] | |
| exact hflip x | |
| right_inv p := by | |
| rcases p with β¨b, xβ© | |
| apply Prod.ext | |
| Β· cases b <;> simp [hΟ, x.property] | |
| Β· cases b <;> apply Subtype.ext <;> | |
| simp [falseRepresentative, hΟ, x.property] | |
| exact hflip x.val | |
| @[simp] theorem booleanSplitEquiv_fst (Ο : V β Bool) (flip : V β V) | |
| (hflip : Function.Involutive flip) (hΟ : β x, Ο (flip x) = !(Ο x)) (x : V) : | |
| (booleanSplitEquiv Ο flip hflip hΟ x).1 = Ο x := rfl | |
| def sampleSplitEquiv (Ο : V β Bool) (flip : V β V) | |
| (hflip : Function.Involutive flip) (hΟ : β x, Ο (flip x) = !(Ο x)) : | |
| (D β V) β (D β Bool) Γ (D β FalseFiber Ο) := | |
| (Equiv.piCongrRight fun _ : D => booleanSplitEquiv Ο flip hflip hΟ).trans | |
| (Equiv.arrowProdEquivProdArrow D (fun _ => Bool) (fun _ => FalseFiber Ο)) | |
| @[simp] theorem sampleSplitEquiv_fst (Ο : V β Bool) (flip : V β V) | |
| (hflip : Function.Involutive flip) (hΟ : β x, Ο (flip x) = !(Ο x)) (g : D β V) : | |
| (sampleSplitEquiv Ο flip hflip hΟ g).1 = fun d => Ο (g d) := rfl | |
| theorem card_boolean_split [Fintype V] (Ο : V β Bool) (flip : V β V) | |
| (hflip : Function.Involutive flip) (hΟ : β x, Ο (flip x) = !(Ο x)) : | |
| Fintype.card V = 2 * Fintype.card (FalseFiber Ο) := by | |
| simpa using Fintype.card_congr (booleanSplitEquiv Ο flip hflip hΟ) | |
| theorem expect_boolean_samples [Fintype V] [Nonempty V] [Fintype D] [DecidableEq D] | |
| (Ο : V β Bool) (flip : V β V) (hflip : Function.Involutive flip) | |
| (hΟ : β x, Ο (flip x) = !(Ο x)) (F : (D β Bool) β β) : | |
| (πΌ g : D β V, F (fun d => Ο (g d))) = πΌ b : D β Bool, F b := by | |
| classical | |
| have : Nonempty (FalseFiber Ο) := | |
| β¨falseRepresentative Ο flip hΟ (Classical.choice βΉNonempty VβΊ)β© | |
| calc | |
| (πΌ g : D β V, F (fun d => Ο (g d))) = | |
| πΌ p : (D β Bool) Γ (D β FalseFiber Ο), F p.1 := by | |
| apply Fintype.expect_equiv (sampleSplitEquiv Ο flip hflip hΟ) | |
| intro g | |
| rfl | |
| _ = πΌ b : D β Bool, F b := by | |
| rw [β Finset.univ_product_univ, Finset.expect_product] | |
| simp only [Fintype.expect_const] | |
| variable {I : Type*} [Fintype I] [DecidableEq I] [Fintype D] [DecidableEq D] | |
| omit [DecidableEq I] in | |
| theorem exists_true_of_ne_zero (s : Cube I) (hs : s β fun _ => false) : | |
| β i, s i = true := by | |
| by_contra h | |
| apply hs | |
| funext i | |
| cases hi : s i | |
| Β· rfl | |
| Β· exact False.elim (h β¨i, hiβ©) | |
| /-- Actual parity words from independently indexed uniform cube vectors have | |
| exactly the uniform Boolean-word distribution. -/ | |
| theorem expect_parity_samples (s : Cube I) (hs : s β fun _ => false) | |
| (F : (D β Bool) β β) : | |
| (πΌ g : D β Cube I, F (fun d => AssignmentTester.parity s (g d))) = | |
| πΌ b : D β Bool, F b := by | |
| obtain β¨i, hiβ© := exists_true_of_ne_zero s hs | |
| exact expect_boolean_samples (AssignmentTester.parity s) (AssignmentTester.flipAt i) | |
| (AssignmentTester.flipAt_twice i) | |
| (fun x => AssignmentTester.parity_flipAt s i x hi) F | |
| /-- The same joint law expressed with the actual real Walsh character values. -/ | |
| theorem expect_walsh_samples (s : Cube I) (hs : s β fun _ => false) | |
| (F : (D β β) β β) : | |
| (πΌ g : D β Cube I, F (fun d => walsh s (g d))) = | |
| πΌ b : D β Bool, F (fun d => bitSign (b d)) := by | |
| simpa only [AssignmentTester.bitSign_parity] using | |
| expect_parity_samples s hs (fun b => F (fun d => bitSign (b d))) | |
| /-- In particular, any test of the empirical Walsh bias has the corresponding | |
| uniform Boolean-word average. This is the eigenvalue sampling law. -/ | |
| theorem expect_walsh_mean (s : Cube I) (hs : s β fun _ => false) (F : β β β) : | |
| (πΌ g : D β Cube I, F (πΌ d, walsh s (g d))) = | |
| πΌ b : D β Bool, F (πΌ d, bitSign (b d)) := | |
| expect_walsh_samples s hs (fun z => F (πΌ d, z d)) | |
| end MaxCutGames.Foundations.PCP.CayleySampling | |
| end | |
| /-! Actual finite binary-word tail counts for the proposed Cayley base graph. | |
| No expander, independence, spectral, or random-generator existence result is | |
| assumed here. | |
| -/ | |
| namespace MaxCutGames.Foundations.PCP.CayleyTailCount | |
| open scoped BigOperators | |
| open MaxCutGames.Foundations.Hastad (bitSign) | |
| variable {Ξ± : Type*} [DecidableEq Ξ±] | |
| def upperMasks (s : Finset Ξ±) (m : β) : Finset (Finset Ξ±) := | |
| s.powerset.filter fun t => 3 * m β€ t.card | |
| def lowerMasks (s : Finset Ξ±) (m : β) : Finset (Finset Ξ±) := | |
| s.powerset.filter fun t => t.card β€ m | |
| def badMasks (s : Finset Ξ±) (m : β) : Finset (Finset Ξ±) := | |
| lowerMasks s m βͺ upperMasks s m | |
| omit [DecidableEq Ξ±] in | |
| /-- Weight every actual upper-tail mask by at least `3 ^ (3 * m)`. -/ | |
| theorem upperMasks_weight (s : Finset Ξ±) (m : β) (hcard : s.card = 4 * m) : | |
| (upperMasks s m).card * 3 ^ (3 * m) β€ 4 ^ (4 * m) := by | |
| calc | |
| _ = β _t β upperMasks s m, 3 ^ (3 * m) := by simp | |
| _ β€ β t β upperMasks s m, 3 ^ t.card := by | |
| apply Finset.sum_le_sum | |
| intro t ht | |
| exact Nat.pow_le_pow_right (by decide) (Finset.mem_filter.mp ht).2 | |
| _ β€ β t β s.powerset, 3 ^ t.card := by | |
| apply Finset.sum_le_sum_of_subset_of_nonneg | |
| Β· exact Finset.filter_subset _ _ | |
| Β· intro t _ _ | |
| exact Nat.zero_le _ | |
| _ = 4 ^ s.card := by | |
| simpa using Finset.sum_pow_mul_eq_add_pow (3 : β) 1 s | |
| _ = 4 ^ (4 * m) := by rw [hcard] | |
| /-- Complementation preserves multiplicity and exchanges the two closed tails. -/ | |
| theorem lowerMasks_complement_image (s : Finset Ξ±) (m : β) | |
| (hcard : s.card = 4 * m) : | |
| (lowerMasks s m).image (fun t => s \ t) = upperMasks s m := by | |
| ext u | |
| constructor | |
| Β· intro hu | |
| obtain β¨t, ht, rflβ© := Finset.mem_image.mp hu | |
| obtain β¨hts, htloβ© := Finset.mem_filter.mp ht | |
| have hsub := Finset.mem_powerset.mp hts | |
| apply Finset.mem_filter.mpr | |
| refine β¨Finset.mem_powerset.mpr Finset.sdiff_subset, ?_β© | |
| rw [Finset.card_sdiff_of_subset hsub, hcard] | |
| omega | |
| Β· intro hu | |
| obtain β¨hus, huhiβ© := Finset.mem_filter.mp hu | |
| have hsub := Finset.mem_powerset.mp hus | |
| apply Finset.mem_image.mpr | |
| refine β¨s \ u, ?_, Finset.sdiff_sdiff_eq_self hsubβ© | |
| apply Finset.mem_filter.mpr | |
| refine β¨Finset.mem_powerset.mpr Finset.sdiff_subset, ?_β© | |
| rw [Finset.card_sdiff_of_subset hsub, hcard] | |
| omega | |
| theorem lowerMasks_card_eq_upperMasks (s : Finset Ξ±) (m : β) | |
| (hcard : s.card = 4 * m) : | |
| (lowerMasks s m).card = (upperMasks s m).card := by | |
| have hinj : Set.InjOn (fun t : Finset Ξ± => s \ t) (lowerMasks s m) := by | |
| intro a ha b hb hab | |
| have has := Finset.mem_powerset.mp (Finset.mem_filter.mp ha).1 | |
| have hbs := Finset.mem_powerset.mp (Finset.mem_filter.mp hb).1 | |
| have h := congrArg (fun t : Finset Ξ± => s \ t) hab | |
| simpa only [Finset.sdiff_sdiff_eq_self has, Finset.sdiff_sdiff_eq_self hbs] using h | |
| calc | |
| _ = ((lowerMasks s m).image (fun t => s \ t)).card := | |
| (Finset.card_image_of_injOn hinj).symm | |
| _ = _ := congrArg Finset.card (lowerMasks_complement_image s m hcard) | |
| private theorem ratio_le_of_weight_inline_CayleyTailCount (c m : β) | |
| (h : c * 3 ^ (3 * m) β€ 4 ^ (4 * m)) : | |
| (c : β) / 2 ^ (4 * m) β€ (16 / 27 : β) ^ m := by | |
| have hc : (c : β) * 3 ^ (3 * m) β€ 4 ^ (4 * m) := by exact_mod_cast h | |
| have h3 : 0 < (3 : β) ^ (3 * m) := by positivity | |
| have h2 : 0 < (2 : β) ^ (4 * m) := by positivity | |
| calc | |
| _ β€ ((4 : β) ^ (4 * m) / 3 ^ (3 * m)) / 2 ^ (4 * m) := | |
| div_le_div_of_nonneg_right ((le_div_iffβ h3).mpr hc) h2.le | |
| _ = _ := by | |
| rw [pow_mul, pow_mul, pow_mul, β div_pow, β div_pow] | |
| norm_num | |
| omit [DecidableEq Ξ±] in | |
| theorem upperMasks_ratio_le (s : Finset Ξ±) (m : β) (hcard : s.card = 4 * m) : | |
| ((upperMasks s m).card : β) / 2 ^ s.card β€ (16 / 27 : β) ^ m := by | |
| rw [hcard] | |
| exact ratio_le_of_weight_inline_CayleyTailCount _ m (upperMasks_weight s m hcard) | |
| theorem lowerMasks_ratio_le (s : Finset Ξ±) (m : β) (hcard : s.card = 4 * m) : | |
| ((lowerMasks s m).card : β) / 2 ^ s.card β€ (16 / 27 : β) ^ m := by | |
| rw [lowerMasks_card_eq_upperMasks s m hcard] | |
| exact upperMasks_ratio_le s m hcard | |
| theorem badMasks_ratio_le_sharp (s : Finset Ξ±) (m : β) (hcard : s.card = 4 * m) : | |
| ((badMasks s m).card : β) / 2 ^ s.card β€ 2 * (16 / 27 : β) ^ m := by | |
| have hc : ((badMasks s m).card : β) β€ | |
| (lowerMasks s m).card + (upperMasks s m).card := by | |
| exact_mod_cast (Finset.card_union_le (lowerMasks s m) (upperMasks s m)) | |
| have hpos : 0 < (2 : β) ^ s.card := by positivity | |
| calc | |
| _ β€ ((lowerMasks s m).card + (upperMasks s m).card : β) / 2 ^ s.card := | |
| div_le_div_of_nonneg_right hc hpos.le | |
| _ = ((lowerMasks s m).card : β) / 2 ^ s.card + | |
| ((upperMasks s m).card : β) / 2 ^ s.card := add_div _ _ _ | |
| _ β€ (16 / 27 : β) ^ m + (16 / 27 : β) ^ m := | |
| add_le_add (lowerMasks_ratio_le s m hcard) (upperMasks_ratio_le s m hcard) | |
| _ = _ := by ring | |
| theorem badMasks_ratio_le (s : Finset Ξ±) (m : β) (hcard : s.card = 4 * m) : | |
| ((badMasks s m).card : β) / 2 ^ s.card β€ 2 * (2 / 3 : β) ^ m := by | |
| apply (badMasks_ratio_le_sharp s m hcard).trans | |
| exact mul_le_mul_of_nonneg_left | |
| (pow_le_pow_leftβ (by norm_num) (by norm_num) m) (by norm_num) | |
| section Words | |
| variable {D : Type*} [Fintype D] | |
| def trueMask (word : D β Bool) : Finset D := | |
| Finset.univ.filter fun i => word i = true | |
| def countTrue (word : D β Bool) : β := (trueMask word).card | |
| def badWord (m : β) (word : D β Bool) : Prop := | |
| countTrue word β€ m β¨ 3 * m β€ countTrue word | |
| instance (m : β) (word : D β Bool) : Decidable (badWord m word) := | |
| inferInstanceAs (Decidable (countTrue word β€ m β¨ 3 * m β€ countTrue word)) | |
| /-- The sign convention is the existing Walsh convention: false is +1, true is -1. -/ | |
| theorem bitSign_mean_eq [Nonempty D] (word : D β Bool) : | |
| (πΌ i, bitSign (word i)) = | |
| 1 - 2 * ((countTrue word : β) / Fintype.card D) := by | |
| have hsign (b : Bool) : bitSign b = 1 - 2 * (if b = true then (1 : β) else 0) := by | |
| cases b <;> norm_num [bitSign] | |
| calc | |
| _ = (πΌ i : D, (1 - 2 * (if word i = true then (1 : β) else 0))) := by | |
| apply Finset.expect_congr rfl | |
| intro i _ | |
| exact hsign (word i) | |
| _ = 1 - 2 * (πΌ i, if word i = true then (1 : β) else 0) := by | |
| rw [Finset.expect_sub_distrib, β Finset.mul_expect, Fintype.expect_const] | |
| _ = _ := by | |
| rw [Fintype.expect_eq_sum_div_card, Finset.sum_boole] | |
| rfl | |
| /-- Excluding both closed integer tails bounds the actual mean Walsh sign. -/ | |
| theorem not_badWord_bias (m : β) (hcard : Fintype.card D = 4 * m) (hm : 0 < m) | |
| (word : D β Bool) (hword : Β¬ badWord m word) : | |
| |πΌ i, bitSign (word i)| β€ (1 / 2 : β) := by | |
| have hD : 0 < Fintype.card D := by rw [hcard]; omega | |
| let : Nonempty D := Fintype.card_pos_iff.mp hD | |
| have hlo : m < countTrue word := lt_of_not_ge (not_or.mp hword).1 | |
| have hhi : countTrue word < 3 * m := lt_of_not_ge (not_or.mp hword).2 | |
| have hmr : 0 < (m : β) := by exact_mod_cast hm | |
| have hlor : (m : β) β€ countTrue word := by exact_mod_cast hlo.le | |
| have hhir : (countTrue word : β) β€ 3 * m := by exact_mod_cast hhi.le | |
| have hden : 0 < 4 * (m : β) := by positivity | |
| have hratioLo : (1 / 4 : β) β€ (countTrue word : β) / (4 * m) := | |
| (le_div_iffβ hden).mpr (by nlinarith) | |
| have hratioHi : (countTrue word : β) / (4 * m) β€ (3 / 4 : β) := | |
| (div_le_iffβ hden).mpr (by nlinarith) | |
| rw [bitSign_mean_eq word, hcard] | |
| simp only [Nat.cast_mul, Nat.cast_ofNat] | |
| apply abs_le.mpr | |
| constructor <;> linarith | |
| /-- All words occur once, so subset counting keeps the actual uniform law. -/ | |
| def wordMaskEquiv [DecidableEq D] : (D β Bool) β Finset D where | |
| toFun := trueMask | |
| invFun s i := decide (i β s) | |
| left_inv word := by | |
| funext i | |
| cases h : word i <;> simp [trueMask, h] | |
| right_inv s := by | |
| ext i | |
| simp [trueMask] | |
| /-- Actual real uniform expectation on binary words, including both closed tails. -/ | |
| theorem twoTail_probability [DecidableEq D] (m : β) (hcard : Fintype.card D = 4 * m) : | |
| (πΌ word : D β Bool, if badWord m word then (1 : β) else 0) β€ | |
| 2 * (2 / 3 : β) ^ m := by | |
| classical | |
| have he : (πΌ word : D β Bool, if badWord m word then (1 : β) else 0) = | |
| (πΌ s : Finset D, if s.card β€ m β¨ 3 * m β€ s.card then (1 : β) else 0) := by | |
| apply Finset.expect_equiv (wordMaskEquiv (D := D)) | |
| Β· intro word | |
| simp | |
| Β· intro word _ | |
| rfl | |
| have hs : (Finset.univ.filter fun s : Finset D => s.card β€ m β¨ 3 * m β€ s.card) = | |
| badMasks (Finset.univ : Finset D) m := by | |
| ext s | |
| simp [badMasks, lowerMasks, upperMasks] | |
| rw [he, Fintype.expect_eq_sum_div_card, Finset.sum_boole, hs, Fintype.card_finset] | |
| simpa only [Nat.cast_pow, Nat.cast_ofNat, Finset.card_univ] using | |
| badMasks_ratio_le (Finset.univ : Finset D) m (by simpa using hcard) | |
| end Words | |
| /-- Numerical budget for a union bound over at most `2 ^ n` frequencies. -/ | |
| theorem union_bound_le_half (n m : β) (hm : 3 * (n + 2) β€ m) : | |
| (2 : β) ^ n * (2 * (2 / 3 : β) ^ m) β€ 1 / 2 := by | |
| have hpow : (2 / 3 : β) ^ m β€ (2 / 3 : β) ^ (3 * (n + 2)) := | |
| pow_le_pow_of_le_one (by norm_num) (by norm_num) hm | |
| have hbase : (2 / 3 : β) ^ (3 * (n + 2)) β€ (1 / 2 : β) ^ (n + 2) := by | |
| rw [pow_mul] | |
| exact pow_le_pow_leftβ (by positivity) (by norm_num) (n + 2) | |
| calc | |
| _ β€ (2 : β) ^ n * (2 * (1 / 2 : β) ^ (n + 2)) := by | |
| exact mul_le_mul_of_nonneg_left | |
| (mul_le_mul_of_nonneg_left (hpow.trans hbase) (by norm_num)) (by positivity) | |
| _ = 1 / 2 := by | |
| rw [pow_add, div_pow] | |
| norm_num | |
| field_simp | |
| norm_num | |
| /-- The proposed fixed parameters meet the elementary counting margin. -/ | |
| theorem fixed_parameters : 3 * (448 + 2) β€ 16384 β§ 4 * 16384 = 2 ^ 16 := by | |
| norm_num | |
| theorem fixed_union_bound : | |
| (2 : β) ^ 448 * (2 * (2 / 3 : β) ^ 16384) β€ 1 / 2 := | |
| union_bound_le_half 448 16384 fixed_parameters.1 | |
| /-- Pure parameter identity; this does not assert existence of a graph. -/ | |
| theorem seventh_power_size : (2 : β) ^ 448 = (((2 : β) ^ 16) ^ 7) ^ 4 := by | |
| rw [β pow_mul, β pow_mul] | |
| /-- Pure scalar estimate, ready for a separately proved spectral powering theorem. -/ | |
| theorem seventh_power_abs_le {a : β} (ha : |a| β€ 1 / 2) : |a ^ 7| β€ 1 / 128 := by | |
| rw [abs_pow] | |
| calc | |
| |a| ^ 7 β€ (1 / 2 : β) ^ 7 := pow_le_pow_leftβ (abs_nonneg a) ha 7 | |
| _ = 1 / 128 := by norm_num | |
| end MaxCutGames.Foundations.PCP.CayleyTailCount | |
| namespace MaxCutGames.Foundations.PCP.SpectralReturn | |
| open PoweringWalks | |
| open scoped BigOperators | |
| noncomputable section | |
| def mean {A : Type*} [Fintype A] (f : A β β) : β := Finset.univ.expect f | |
| def energy {A : Type*} [Fintype A] (f : A β β) : β := mean (fun x => (f x) ^ 2) | |
| def correlation {A : Type*} [Fintype A] (f g : A β β) : β := | |
| mean (fun x => f x * g x) | |
| def averagingOperator {V D : Type*} [Fintype D] (G : PortGraph V D) | |
| (f : V β β) (v : V) : β := Finset.univ.expect (fun d => f (G.rot (v, d)).1) | |
| def iterateOperator {V D : Type*} [Fintype D] (G : PortGraph V D) : | |
| Nat β (V β β) β (V β β) | |
| | 0, f => f | |
| | n + 1, f => averagingOperator G (iterateOperator G n f) | |
| def edgeProfile {V D : Type*} [Fintype D] (bad : V Γ D β Bool) (v : V) : β := | |
| Finset.univ.expect (fun d => if bad (v, d) then 1 else 0) | |
| def edgeDensity {V D : Type*} [Fintype V] [Fintype D] (bad : V Γ D β Bool) : β := | |
| mean (edgeProfile bad) | |
| def markedStep {V D : Type*} [Fintype D] (G : PortGraph V D) | |
| (bad : V Γ D β Bool) (f : V β β) (v : V) : β := | |
| Finset.univ.expect (fun d => if bad (v, d) then f (G.rot (v, d)).1 else 0) | |
| def returnMass {V D : Type*} [Fintype V] [Fintype D] | |
| (G : PortGraph V D) (bad : V Γ D β Bool) (gap : Nat) : β := | |
| mean (markedStep G bad (iterateOperator G gap (edgeProfile bad))) | |
| structure SpectralCertificate {V D : Type*} [Fintype V] [Fintype D] | |
| (G : PortGraph V D) (lambda : β) : Prop where | |
| nonnegative : 0 β€ lambda | |
| lt_one : lambda < 1 | |
| contraction : β f : V β β, mean f = 0 β | |
| energy (averagingOperator G f) β€ lambda ^ 2 * energy f | |
| /-! ## Finite normalized averages -/ | |
| section Averages | |
| variable {A B : Type*} [Fintype A] [Fintype B] | |
| theorem mean_eq_sum_div_card (f : A β β) : | |
| mean f = (β x, f x) / (Fintype.card A : β) := | |
| Fintype.expect_eq_sum_div_card f | |
| theorem mean_equiv (e : A β B) (f : B β β) : | |
| mean (fun x => f (e x)) = mean f := | |
| Fintype.expect_equiv e _ _ (fun _ => rfl) | |
| theorem mean_prod (f : A Γ B β β) : | |
| mean f = mean (fun a => mean (fun b => f (a, b))) := by | |
| simpa only [mean, Finset.univ_product_univ] using | |
| Finset.expect_product (Finset.univ : Finset A) (Finset.univ : Finset B) f | |
| @[simp] theorem mean_const [Nonempty A] (c : β) : mean (fun _ : A => c) = c := | |
| Fintype.expect_const c | |
| theorem mean_add (f g : A β β) : | |
| mean (fun x => f x + g x) = mean f + mean g := | |
| Finset.expect_add_distrib _ f g | |
| theorem mean_sub (f g : A β β) : | |
| mean (fun x => f x - g x) = mean f - mean g := | |
| Finset.expect_sub_distrib _ f g | |
| theorem mean_mul_left (c : β) (f : A β β) : | |
| mean (fun x => c * f x) = c * mean f := | |
| (Finset.mul_expect _ f c).symm | |
| theorem mean_mul_right (f : A β β) (c : β) : | |
| mean (fun x => f x * c) = mean f * c := | |
| (Finset.expect_mul _ f c).symm | |
| theorem mean_nonnegative (f : A β β) (hf : β x, 0 β€ f x) : 0 β€ mean f := | |
| Finset.expect_nonneg (fun x _ => hf x) | |
| theorem mean_mono {f g : A β β} (h : β x, f x β€ g x) : mean f β€ mean g := | |
| Finset.expect_le_expect (fun x _ => h x) | |
| theorem energy_nonnegative (f : A β β) : 0 β€ energy f := | |
| mean_nonnegative _ (fun x => sq_nonneg (f x)) | |
| /-- The finite Cauchy--Schwarz inequality, in the chosen normalized convention. -/ | |
| theorem correlation_sq_le (f g : A β β) : | |
| correlation f g ^ 2 β€ energy f * energy g := | |
| Finset.expect_mul_sq_le_sq_mul_sq Finset.univ f g | |
| theorem energy_sub_const [Nonempty A] (f : A β β) (c : β) : | |
| energy (fun x => f x - c) = energy f - 2 * c * mean f + c ^ 2 := by | |
| have h : (fun x => (f x - c) ^ 2) = | |
| (fun x => (f x) ^ 2 - (2 * c) * f x + c ^ 2) := by | |
| funext x | |
| ring | |
| unfold energy | |
| rw [h, mean_add, mean_sub, mean_mul_left, mean_const] | |
| theorem correlation_sub_const [Nonempty A] (f g : A β β) (c d : β) : | |
| correlation (fun x => f x - c) (fun x => g x - d) = | |
| correlation f g - d * mean f - c * mean g + c * d := by | |
| have h : (fun x => (f x - c) * (g x - d)) = | |
| (fun x => f x * g x - d * f x - c * g x + c * d) := by | |
| funext x | |
| ring | |
| unfold correlation | |
| rw [h, mean_add, mean_sub, mean_sub, mean_mul_left, mean_mul_left, mean_const] | |
| end Averages | |
| /-! ## The exact graph operator and the reversal identity -/ | |
| section Graph | |
| variable {V D : Type*} [Fintype V] [Fintype D] [Nonempty V] [Nonempty D] | |
| (G : PortGraph V D) | |
| omit [Nonempty V] in | |
| theorem mean_operator (f : V β β) : mean (averagingOperator G f) = mean f := by | |
| calc | |
| mean (averagingOperator G f) = mean (fun e : V Γ D => f (G.rot e).1) := | |
| (mean_prod (fun e : V Γ D => f (G.rot e).1)).symm | |
| _ = mean (fun e : V Γ D => f e.1) := mean_equiv G.rot (fun e => f e.1) | |
| _ = mean (fun v : V => mean (fun _ : D => f v)) := | |
| mean_prod (fun e : V Γ D => f e.1) | |
| _ = mean f := by simp only [mean_const] | |
| omit [Fintype V] [Nonempty V] in | |
| theorem operator_sub_const (f : V β β) (c : β) : | |
| averagingOperator G (fun v => f v - c) = fun v => averagingOperator G f v - c := by | |
| funext v | |
| change mean (fun d => f (G.rot (v, d)).1 - c) = _ | |
| rw [mean_sub, mean_const] | |
| rfl | |
| omit [Nonempty V] in | |
| theorem mean_iterate (n : Nat) (f : V β β) : mean (iterateOperator G n f) = mean f := by | |
| induction n with | |
| | zero => rfl | |
| | succ n ih => rw [iterateOperator, mean_operator, ih] | |
| omit [Fintype V] [Nonempty V] in | |
| theorem iterate_sub_const (n : Nat) (f : V β β) (c : β) : | |
| iterateOperator G n (fun v => f v - c) = fun v => iterateOperator G n f v - c := by | |
| induction n with | |
| | zero => rfl | |
| | succ n ih => rw [iterateOperator, ih, operator_sub_const]; rfl | |
| omit [Nonempty V] [Nonempty D] in | |
| /-- Reversal moves the first marked edge to its endpoint. The profile therefore | |
| appears at the endpoint, before the `gap` remaining vertex transitions. -/ | |
| theorem mean_markedStep (bad : V Γ D β Bool) | |
| (reversal : β e, bad (G.rot e) = bad e) (f : V β β) : | |
| mean (markedStep G bad f) = correlation (edgeProfile bad) f := by | |
| calc | |
| mean (markedStep G bad f) = | |
| mean (fun e : V Γ D => if bad e then f (G.rot e).1 else 0) := by | |
| exact (mean_prod (fun e : V Γ D => if bad e then f (G.rot e).1 else 0)).symm | |
| _ = mean (fun e : V Γ D => if bad (G.rot e) | |
| then f (G.rot (G.rot e)).1 else 0) := | |
| (mean_equiv G.rot (fun e : V Γ D => if bad e then f (G.rot e).1 else 0)).symm | |
| _ = mean (fun e : V Γ D => if bad e then f e.1 else 0) := by | |
| congr 1 | |
| funext e | |
| rw [reversal e, G.rot_involutive e] | |
| _ = mean (fun v => mean (fun d => if bad (v, d) then f v else 0)) := | |
| mean_prod (fun e : V Γ D => if bad e then f e.1 else 0) | |
| _ = correlation (edgeProfile bad) f := by | |
| unfold correlation | |
| congr 1 | |
| funext v | |
| have h : (fun d => if bad (v, d) then f v else 0) = | |
| (fun d => (if bad (v, d) then (1 : β) else 0) * f v) := by | |
| funext d | |
| cases bad (v, d) <;> simp | |
| rw [h, mean_mul_right] | |
| rfl | |
| omit [Nonempty V] [Nonempty D] in | |
| theorem returnMass_eq_correlation (bad : V Γ D β Bool) | |
| (reversal : β e, bad (G.rot e) = bad e) (gap : Nat) : | |
| returnMass G bad gap = correlation (edgeProfile bad) | |
| (iterateOperator G gap (edgeProfile bad)) := | |
| mean_markedStep G bad reversal _ | |
| /-! ## Iterated contraction and centering -/ | |
| omit [Nonempty V] in | |
| theorem iterate_energy_bound (lambda : β) (certificate : SpectralCertificate G lambda) | |
| (f : V β β) (hf : mean f = 0) (n : Nat) : | |
| energy (iterateOperator G n f) β€ (lambda ^ n) ^ 2 * energy f := by | |
| induction n with | |
| | zero => simp [iterateOperator] | |
| | succ n ih => | |
| calc | |
| energy (iterateOperator G (n + 1) f) β€ | |
| lambda ^ 2 * energy (iterateOperator G n f) := | |
| certificate.contraction _ ((mean_iterate G n f).trans hf) | |
| _ β€ lambda ^ 2 * ((lambda ^ n) ^ 2 * energy f) := | |
| mul_le_mul_of_nonneg_left ih (sq_nonneg lambda) | |
| _ = (lambda ^ (n + 1)) ^ 2 * energy f := by rw [pow_succ]; ring | |
| omit [Nonempty V] in | |
| theorem zero_mean_correlation_bound (lambda : β) | |
| (certificate : SpectralCertificate G lambda) (f : V β β) | |
| (hf : mean f = 0) (n : Nat) : | |
| correlation f (iterateOperator G n f) β€ lambda ^ n * energy f := by | |
| have hsq : correlation f (iterateOperator G n f) ^ 2 β€ | |
| (lambda ^ n * energy f) ^ 2 := by | |
| calc | |
| _ β€ energy f * energy (iterateOperator G n f) := correlation_sq_le _ _ | |
| _ β€ energy f * ((lambda ^ n) ^ 2 * energy f) := | |
| mul_le_mul_of_nonneg_left (iterate_energy_bound G lambda certificate f hf n) | |
| (energy_nonnegative f) | |
| _ = _ := by ring | |
| exact le_of_sq_le_sq hsq | |
| (mul_nonneg (pow_nonneg certificate.nonnegative n) (energy_nonnegative f)) | |
| theorem correlation_centered (f : V β β) (n : Nat) : | |
| correlation f (iterateOperator G n f) = mean f ^ 2 + | |
| correlation (fun v => f v - mean f) | |
| (iterateOperator G n (fun v => f v - mean f)) := by | |
| rw [iterate_sub_const, correlation_sub_const, mean_iterate] | |
| ring | |
| end Graph | |
| /-! ## The edge profile has Bernoulli-size variance -/ | |
| section Profiles | |
| variable {V D : Type*} [Fintype V] [Fintype D] [Nonempty V] [Nonempty D] | |
| omit [Nonempty V] [Nonempty D] in | |
| /-- Density is exactly the uniform probability of a marked directed port-edge. -/ | |
| theorem edgeDensity_eq_edge_mean (bad : V Γ D β Bool) : | |
| edgeDensity bad = mean (fun e => if bad e then (1 : β) else 0) := | |
| (mean_prod (fun e : V Γ D => if bad e then (1 : β) else 0)).symm | |
| omit [Nonempty V] [Nonempty D] in | |
| /-- The edge convention counts each directed port once, including parallel | |
| edges and loops. Thus the density is literally the marked-edge cardinal ratio. -/ | |
| theorem edgeDensity_eq_card (bad : V Γ D β Bool) : | |
| edgeDensity bad = | |
| ((Finset.univ.filter (fun e => bad e = true)).card : β) / | |
| (Fintype.card (V Γ D) : β) := by | |
| rw [edgeDensity_eq_edge_mean, mean_eq_sum_div_card] | |
| simp only [Finset.sum_boole] | |
| omit [Fintype V] [Nonempty V] [Nonempty D] in | |
| theorem edgeProfile_nonnegative (bad : V Γ D β Bool) (v : V) : 0 β€ edgeProfile bad v := | |
| mean_nonnegative _ (fun d => by cases bad (v, d) <;> norm_num) | |
| omit [Fintype V] [Nonempty V] in | |
| theorem edgeProfile_le_one (bad : V Γ D β Bool) (v : V) : edgeProfile bad v β€ 1 := by | |
| change mean (fun d => if bad (v, d) then (1 : β) else 0) β€ 1 | |
| calc | |
| _ β€ mean (fun _ : D => (1 : β)) := mean_mono (fun d => by | |
| cases bad (v, d) <;> norm_num) | |
| _ = 1 := mean_const _ | |
| omit [Nonempty V] [Nonempty D] in | |
| theorem edgeDensity_nonnegative (bad : V Γ D β Bool) : 0 β€ edgeDensity bad := | |
| mean_nonnegative _ (edgeProfile_nonnegative bad) | |
| theorem edgeDensity_le_one (bad : V Γ D β Bool) : edgeDensity bad β€ 1 := by | |
| calc | |
| _ β€ mean (fun _ : V => (1 : β)) := mean_mono (edgeProfile_le_one bad) | |
| _ = 1 := mean_const _ | |
| omit [Nonempty V] in | |
| theorem edgeProfile_energy_le_density (bad : V Γ D β Bool) : | |
| energy (edgeProfile bad) β€ edgeDensity bad := | |
| mean_mono (fun v => by | |
| have h0 := edgeProfile_nonnegative bad v | |
| have h1 := edgeProfile_le_one bad v | |
| nlinarith) | |
| theorem edgeProfile_centered_energy (bad : V Γ D β Bool) : | |
| energy (fun v => edgeProfile bad v - edgeDensity bad) β€ | |
| edgeDensity bad * (1 - edgeDensity bad) := by | |
| rw [energy_sub_const] | |
| have h := edgeProfile_energy_le_density bad | |
| change energy (edgeProfile bad) - 2 * edgeDensity bad * edgeDensity bad + | |
| edgeDensity bad ^ 2 β€ _ | |
| nlinarith | |
| /-- Sharp return bound. No division by the bad-edge density occurs, so the empty | |
| bad set is covered. `gap = 0` gives the adjacent-edge upper bound `epsilon`. -/ | |
| theorem returnMass_le_sharp (G : PortGraph V D) (lambda : β) | |
| (certificate : SpectralCertificate G lambda) (bad : V Γ D β Bool) | |
| (reversal : β e, bad (G.rot e) = bad e) (gap : Nat) : | |
| returnMass G bad gap β€ edgeDensity bad ^ 2 + | |
| lambda ^ gap * (edgeDensity bad * (1 - edgeDensity bad)) := by | |
| rw [returnMass_eq_correlation G bad reversal, correlation_centered] | |
| have hzero : mean (fun v => edgeProfile bad v - edgeDensity bad) = 0 := by | |
| rw [mean_sub, mean_const] | |
| simp only [edgeDensity, sub_self] | |
| have hc := zero_mean_correlation_bound G lambda certificate | |
| (fun v => edgeProfile bad v - edgeDensity bad) hzero gap | |
| have hv := mul_le_mul_of_nonneg_left (edgeProfile_centered_energy bad) | |
| (pow_nonneg certificate.nonnegative gap) | |
| change edgeDensity bad ^ 2 + _ β€ _ | |
| exact add_le_add (le_refl _) (hc.trans hv) | |
| /-- The simple bound used in the second-moment estimate. -/ | |
| theorem returnMass_le (G : PortGraph V D) (lambda : β) | |
| (certificate : SpectralCertificate G lambda) (bad : V Γ D β Bool) | |
| (reversal : β e, bad (G.rot e) = bad e) (gap : Nat) : | |
| returnMass G bad gap β€ edgeDensity bad ^ 2 + edgeDensity bad * lambda ^ gap := by | |
| have h := returnMass_le_sharp G lambda certificate bad reversal gap | |
| have hvar : edgeDensity bad * (1 - edgeDensity bad) β€ edgeDensity bad := by | |
| nlinarith [sq_nonneg (edgeDensity bad)] | |
| have hm := mul_le_mul_of_nonneg_left hvar (pow_nonneg certificate.nonnegative gap) | |
| nlinarith | |
| theorem adjacent_returnMass_le (G : PortGraph V D) (lambda : β) | |
| (certificate : SpectralCertificate G lambda) (bad : V Γ D β Bool) | |
| (reversal : β e, bad (G.rot e) = bad e) : | |
| returnMass G bad 0 β€ edgeDensity bad := by | |
| have h := returnMass_le_sharp G lambda certificate bad reversal 0 | |
| norm_num at h | |
| nlinarith | |
| end Profiles | |
| /-- The finite geometric-series bound that absorbs forward and reverse returns. | |
| It applies to every finite window, with no limiting probability argument. -/ | |
| theorem geometric_sum_le (lambda : β) (h0 : 0 β€ lambda) (h1 : lambda < 1) (n : Nat) : | |
| (β k β Finset.range n, lambda ^ k) β€ 1 / (1 - lambda) := by | |
| have hsum : (β k β Finset.range n, lambda ^ k) * (1 - lambda) = 1 - lambda ^ n := by | |
| induction n with | |
| | zero => simp | |
| | succ n ih => rw [Finset.sum_range_succ, pow_succ]; nlinarith | |
| have hden : 0 < 1 - lambda := by linarith | |
| apply (le_div_iffβ hden).2 | |
| rw [hsum] | |
| linarith [pow_nonneg h0 n] | |
| variable {V D : Type*} [Fintype V] [Fintype D] [Nonempty V] [Nonempty D] | |
| /-- The return contribution from one marked edge, over a finite forward window. -/ | |
| theorem sum_returnMass_le (G : PortGraph V D) (lambda : β) | |
| (certificate : SpectralCertificate G lambda) (bad : V Γ D β Bool) | |
| (reversal : β e, bad (G.rot e) = bad e) (n : Nat) : | |
| (β gap β Finset.range n, returnMass G bad gap) β€ | |
| (n : β) * edgeDensity bad ^ 2 + edgeDensity bad / (1 - lambda) := by | |
| calc | |
| _ β€ β gap β Finset.range n, | |
| (edgeDensity bad ^ 2 + edgeDensity bad * lambda ^ gap) := | |
| Finset.sum_le_sum (fun gap _ => returnMass_le G lambda certificate bad reversal gap) | |
| _ = (n : β) * edgeDensity bad ^ 2 + | |
| edgeDensity bad * (β gap β Finset.range n, lambda ^ gap) := by | |
| rw [Finset.sum_add_distrib, β Finset.mul_sum] | |
| simp only [Finset.sum_const, Finset.card_range, nsmul_eq_mul] | |
| _ β€ (n : β) * edgeDensity bad ^ 2 + edgeDensity bad * (1 / (1 - lambda)) := | |
| add_le_add (le_refl _) | |
| (mul_le_mul_of_nonneg_left | |
| (geometric_sum_le lambda certificate.nonnegative certificate.lt_one n) | |
| (edgeDensity_nonnegative bad)) | |
| _ = _ := by ring | |
| /-- Sum over all distinct ordered-time pairs, counting each pair once. | |
| The row for the later edge `j` has gaps `0,...,j-1`. -/ | |
| theorem triangular_returnMass_sum_le (G : PortGraph V D) (lambda : β) | |
| (certificate : SpectralCertificate G lambda) (bad : V Γ D β Bool) | |
| (reversal : β e, bad (G.rot e) = bad e) (n : Nat) : | |
| (β j β Finset.range n, β gap β Finset.range j, returnMass G bad gap) β€ | |
| ((n : β) * ((n : β) - 1) / 2) * edgeDensity bad ^ 2 + | |
| (n : β) * (edgeDensity bad / (1 - lambda)) := by | |
| induction n with | |
| | zero => simp | |
| | succ n ih => | |
| rw [Finset.sum_range_succ] | |
| have hrow := sum_returnMass_le G lambda certificate bad reversal n | |
| have h := add_le_add ih hrow | |
| calc | |
| _ β€ ((n : β) * ((n : β) - 1) / 2) * edgeDensity bad ^ 2 + | |
| (n : β) * (edgeDensity bad / (1 - lambda)) + | |
| ((n : β) * edgeDensity bad ^ 2 + edgeDensity bad / (1 - lambda)) := h | |
| _ = _ := by simp only [Nat.cast_add, Nat.cast_one]; ring | |
| /-- The exact finite envelope needed after expanding the square of the hit | |
| count. The diagonal contributes `n * epsilon`; both off-diagonal triangles | |
| contribute twice the return sum. The actual walk-event identity is supplied by | |
| `PoweringMoment` and `PoweringReturn`. -/ | |
| theorem secondMoment_return_envelope (G : PortGraph V D) (lambda : β) | |
| (certificate : SpectralCertificate G lambda) (bad : V Γ D β Bool) | |
| (reversal : β e, bad (G.rot e) = bad e) (n : Nat) : | |
| (n : β) * edgeDensity bad + | |
| 2 * (β j β Finset.range n, β gap β Finset.range j, returnMass G bad gap) β€ | |
| (n : β) * edgeDensity bad * | |
| (1 + 2 / (1 - lambda) + ((n : β) - 1) * edgeDensity bad) := by | |
| calc | |
| _ β€ (n : β) * edgeDensity bad + | |
| 2 * (((n : β) * ((n : β) - 1) / 2) * edgeDensity bad ^ 2 + | |
| (n : β) * (edgeDensity bad / (1 - lambda))) := | |
| add_le_add (le_refl _) | |
| (mul_le_mul_of_nonneg_left | |
| (triangular_returnMass_sum_le G lambda certificate bad reversal n) (by norm_num)) | |
| _ = _ := by ring | |
| end | |
| end MaxCutGames.Foundations.PCP.SpectralReturn | |
| end OAI | |