import OAI.Combinatorics.ListHadwiger.StagePacking namespace OAI namespace LinearListHadwiger.Sampling open Finset ConnectivityTests variable {V Ω : Type} [Fintype V] [DecidableEq V] [Fintype Ω] theorem complement_failure_thousand (G : SimpleGraph V) [DecidableRel G.Adj] {n r ε : ℝ} {k : ℕ} (hk : 64 ≤ k) (hr : 0 < r) (hrk : r ≤ k) (hord : (Fintype.card V : ℝ) ≤ n) (hconn : KConnectedOn G univ k) {μ : Ω → ℝ} (hμ : ∀ ω, 0 ≤ μ ω) (U : Ω → Finset V) (hsurv : ∀ v, probability μ (fun ω => v ∈ U ω) ≤ 1/1000) (hε : 0 ≤ ε) (htail : ∀ A : Finset V, probability μ (fun ω => r/100 ≤ |((U ω ∩ A).card : ℝ)-expectation μ (fun z => ((U z ∩ A).card : ℝ))|) ≤ ε) : probability μ (fun ω => ¬((∀ v, k ≤ 2*((univ \ U ω).filter (G.Adj v)).card) ∧ KConnectedOn G (univ \ U ω) (k/32))) ≤ (n+(n+1)^(⌈10*(n/k)*Real.log (2*n)⌉₊+1))*ε := by classical obtain ⟨F,hFcard,hF,hFtest⟩ := cut_test G hk hord hconn have hD (v : V) : ∃ D ⊆ Density.neighbors G univ v, D.card=k := exists_subset_card_eq (Knitting.min_degree G hconn (mem_univ v)) choose D hD hDc using hD let Idx := V ⊕ ↥F let A : Idx → Finset V := fun i => match i with | .inl v => D v | .inr E => endpoints E.val let bad : Idx → Ω → Prop := fun i ω => r/100 ≤ |((U ω ∩ A i).card : ℝ)-expectation μ (fun z => ((U z ∩ A i).card : ℝ))| have hbad (i : Idx) : probability μ (bad i) ≤ ε := htail (A i) have hgood (ω : Ω) (havoid : ∀ i, ¬bad i ω) : (∀ v, k ≤ 2*((univ \ U ω).filter (G.Adj v)).card) ∧ KConnectedOn G (univ \ U ω) (k/32) := by have hsmall (i : Idx) (hAk : (A i).card ≤ k) : 32*(U ω ∩ A i).card < k := by have he := expectation_inter_card_le U hsurv (A i) have hAc : ((A i).card : ℝ) ≤ k := by exact_mod_cast hAk have hm : expectation μ (fun z => ((U z ∩ A i).card : ℝ)) ≤ (k:ℝ)/1000 := by nlinarith have hdev := (abs_lt.mp (lt_of_not_ge (havoid i))).2 have hkpos : (0:ℝ) < k := by exact_mod_cast (by omega : 0 < k) have hh : (32:ℝ)*((U ω ∩ A i).card : ℝ) < k := by nlinarith exact_mod_cast hh have hneigh (v : V) : k ≤ 2*((univ \ U ω).filter (G.Adj v)).card := by have hc := hsmall (.inl v) (by dsimp [A]; exact (hDc v).le) have hd : (D v \ U ω).card+(D v ∩ U ω).card=k := by rw [card_sdiff_add_card_inter,hDc] have hsub : D v \ U ω ⊆ (univ \ U ω).filter (G.Adj v) := by intro w hw obtain ⟨hwD,hwU⟩ := mem_sdiff.mp hw have hadj := hD v hwD simp only [Density.neighbors,mem_filter,mem_univ,true_and] at hadj exact mem_filter.mpr ⟨mem_sdiff.mpr ⟨mem_univ _,hwU⟩,hadj⟩ have hcard := card_le_card hsub dsimp [A] at hc rw [inter_comm] at hc omega refine ⟨hneigh,hFtest (U ω) hneigh ?_⟩ intro E hE have he := (hF E hE).1 have hcard : (endpoints E).card ≤ k := by have hb := endpoints_card_le E have hd := Nat.div_mul_le_self k 8 omega have hc := hsmall (.inr ⟨E,hE⟩) hcard simpa [A,inter_comm] using hc have hprob : probability μ (fun ω => ¬((∀ v, k ≤ 2*((univ \ U ω).filter (G.Adj v)).card) ∧ KConnectedOn G (univ \ U ω) (k/32))) ≤ probability μ (fun ω => ∃ i, bad i ω) := by apply probability_mono hμ intro ω h by_contra hn push Not at hn exact h (hgood ω hn) calc _ ≤ probability μ (fun ω => ∃ i, bad i ω) := hprob _ ≤ ∑ i, probability μ (bad i) := probability_union_le hμ bad _ ≤ ∑ _ : Idx, ε := sum_le_sum (fun i _ => hbad i) _ = ((Fintype.card V : ℝ)+F.card)*ε := by simp [Idx] _ ≤ _ := by gcongr noncomputable def coin (p : ℝ) (b : Bool) : ℝ := if b then p else 1-p lemma coin_nonneg {p : ℝ} (hp : 0 ≤ p) (hp1 : p ≤ 1) (b : Bool) : 0 ≤ coin p b := by cases b <;> simp [coin] <;> linarith lemma coin_sum (p : ℝ) : ∑ b : Bool, coin p b = 1 := by simp [coin] noncomputable def chosen (x : V → Bool) : Finset V := univ.filter (fun v => x v = true) lemma chosen_marginal (p : ℝ) (v : V) : probability (productMass (fun _ : V => coin p)) (fun x => v ∈ chosen x) = p := by classical have he : (fun x : V → Bool => v ∈ chosen x) = (fun x => x v = true) := by funext x simp [chosen] rw [he,probability_coordinate (fun _ => coin_sum p) v (fun b => b = true)] simp [probability,coin] lemma chosen_mean (p : ℝ) (D : Finset V) : expectation (productMass (fun _ : V => coin p)) (fun x => ((chosen x ∩ D).card : ℝ)) = (D.card : ℝ)*p := by rw [expectation_inter_card] simp only [chosen_marginal,sum_const,nsmul_eq_mul] lemma chosen_bounded_change (D : Finset V) (i : V) (x y : V → Bool) (hxy : ∀ j, j ≠ i → x j = y j) : |((chosen x ∩ D).card : ℝ)-(chosen y ∩ D).card| ≤ 1 := by classical have he : (chosen x ∩ D).erase i = (chosen y ∩ D).erase i := by ext j by_cases hj : j = i · subst j; simp · simp [chosen,hj,hxy j hj] have hx := card_erase_le (s := chosen x ∩ D) (a := i) have hy := card_erase_le (s := chosen y ∩ D) (a := i) have hx' := pred_card_le_card_erase (s := chosen x ∩ D) (a := i) have hy' := pred_card_le_card_erase (s := chosen y ∩ D) (a := i) have hec := congrArg Finset.card he have h₁ : (chosen x ∩ D).card ≤ (chosen y ∩ D).card+1 := by omega have h₂ : (chosen y ∩ D).card ≤ (chosen x ∩ D).card+1 := by omega have h₁r : ((chosen x ∩ D).card : ℝ) ≤ (chosen y ∩ D).card+1 := by exact_mod_cast h₁ have h₂r : ((chosen y ∩ D).card : ℝ) ≤ (chosen x ∩ D).card+1 := by exact_mod_cast h₂ exact abs_le.mpr ⟨by linarith,by linarith⟩ lemma chosen_concentration {p u : ℝ} (hp : 0 ≤ p) (hp1 : p ≤ 1) (hn : 1 ≤ Fintype.card V) (hu : 0 < u) (D : Finset V) : probability (productMass (fun _ : V => coin p)) (fun x => u ≤ |((chosen x ∩ D).card : ℝ)-(D.card : ℝ)*p|) ≤ 2*Real.exp (-u^2/(2*Fintype.card V)) := by have hh := bounded_differences_general hn (fun _ : V => coin p) (fun _ => coin_nonneg hp hp1) (fun _ => coin_sum p) (fun x => ((chosen x ∩ D).card : ℝ)) (by norm_num : (0:ℝ)<1) hu (chosen_bounded_change D) simpa only [chosen_mean,one_pow,mul_one] using hh theorem exists_sparse_split {I : Type} [Fintype I] (G : SimpleGraph V) [DecidableRel G.Adj] {k : ℕ} {n : ℝ} (hk : 64 ≤ k) (hord : (Fintype.card V : ℝ) ≤ n) (hc : KConnectedOn G univ k) (D : I → Finset V) (hD : ∀ i, (D i).card = k) (hsmall : ((Fintype.card I : ℝ)+n+(n+1)^(⌈10*(n/k)*Real.log (2*n)⌉₊+1)) * (2*Real.exp (-((k:ℝ)/2000)^2/(2*Fintype.card V))) < 1) : ∃ A : Finset V, (∀ i, k ≤ 2000*(A ∩ D i).card ∧ k ≤ 2*((univ \ A) ∩ D i).card) ∧ KConnectedOn G (univ \ A) (k/32) := by classical let μ := productMass (fun _ : V => coin (1/1000)) let ε := 2*Real.exp (-((k:ℝ)/2000)^2/(2*Fintype.card V)) have hkpos : (0:ℝ) coin_nonneg (by norm_num) (by norm_num)) have hμs : ∑ x, μ x = 1 := productMass_sum (fun _ => coin_sum _) let bad (i : I) (x : V → Bool) : Prop := ¬(k ≤ 2000*(chosen x ∩ D i).card ∧ k ≤ 2*((univ \ chosen x) ∩ D i).card) have hbad (i : I) : probability μ (bad i) ≤ ε := by have hh := chosen_concentration (V := V) (p := 1/1000) (by norm_num) (by norm_num) hn (show (0:ℝ) (∃ i, bad i x) ∨ cbad x) < 1 := by have hu := probability_union_le hμ bad have hs : (∑ i, probability μ (bad i)) ≤ (Fintype.card I : ℝ)*ε := by calc _ ≤ ∑ _i : I, ε := sum_le_sum (fun i _ => hbad i) _ = _ := by simp have ho := probability_or_le hμ (fun x => ∃ i, bad i x) cbad have he : ((Fintype.card I:ℝ)+n+(n+1)^(⌈10*(n/k)*Real.log (2*n)⌉₊+1))*ε = (Fintype.card I : ℝ)*ε+(n+(n+1)^(⌈10*(n/k)*Real.log (2*n)⌉₊+1))*ε := by ring rw [he] at hsmall linarith obtain ⟨x,_,hx⟩ := exists_positive_avoiding hμ hμs hfail refine ⟨chosen x,?_,?_⟩ · intro i by_contra hh exact hx (Or.inl ⟨i,hh⟩) · have hh : ¬cbad x := fun hh => hx (Or.inr hh) exact (not_not.mp hh).2 open Filter lemma sparse_split_numeric_cutoff : ∀ᶠ t : ℝ in atTop, ∀ n k N m : ℝ, 1 ≤ N → N ≤ n → n ≤ t^(11/10:ℝ) → t ≤ k → 0 ≤ m → m ≤ n → (m+n+(n+1)^(⌈10*(n/k)*Real.log (2*n)⌉₊+1)) * (2*Real.exp (-(k/2000)^2/(2*N))) < 1 := by have hp := (tendsto_rpow_atTop (show (0:ℝ)<1/5 by norm_num)).eventually (eventually_ge_atTop (8000000:ℝ)) filter_upwards [eventually_gt_atTop (1:ℝ),hp,complement_numeric_cutoff] with t ht hp hc intro n k N m hN hNn hn htk hm hmn have htpos : 0 G.Adj v w.val) have hNc (v : V) : (N v).card=(S.filter (G.Adj v)).card := by rw [←card_image_of_injective (N v) Subtype.val_injective] congr 1 ext w simp only [N,mem_image,mem_filter,mem_univ,true_and] constructor · rintro ⟨u,hu,rfl⟩ exact ⟨u.property,hu⟩ · rintro ⟨hw,hvw⟩ exact ⟨⟨w,hw⟩,hvw,rfl⟩ have hD : ∀ v, ∃ D ⊆ N v, D.card=k := fun v => exists_subset_card_eq (by rw [hNc]; exact hdeg v) choose D hDN hDc using hD have hSord : (Fintype.card (↑S : Set V) : ℝ) ≤ n := by have hs : Fintype.card (↑S : Set V) ≤ Fintype.card V := Fintype.card_subtype_le _ exact (show (Fintype.card (↑S : Set V) : ℝ) ≤ Fintype.card V by exact_mod_cast hs).trans hord obtain ⟨A',hA',hB'⟩ := hT t n ht hn hnt (↑S : Set V) V (G.induce (↑S : Set V)) k htk hSord hord (Knitting.induce_connected G S hc) D hDc let A := A'.image Subtype.val let B := (univ\A').image Subtype.val have himage_subset (E : Finset (↑S : Set V)) : E.image Subtype.val ⊆ S := by intro v hv obtain ⟨w,_,rfl⟩ := mem_image.mp hv exact w.property have hdis : Disjoint A B := by apply Finset.disjoint_left.mpr intro v hva hvb obtain ⟨u,hu,huv⟩ := mem_image.mp hva obtain ⟨w,hw,hwv⟩ := mem_image.mp hvb have he : u=w := Subtype.val_injective (huv.trans hwv.symm) exact (mem_sdiff.mp hw).2 (he ▸ hu) have hcount (E : Finset (↑S : Set V)) (v : V) : (E ∩ D v).card ≤ ((E.image Subtype.val).filter (G.Adj v)).card := by rw [←card_image_of_injective (E ∩ D v) Subtype.val_injective] apply card_le_card intro w hw obtain ⟨u,hu,rfl⟩ := mem_image.mp hw exact mem_filter.mpr ⟨mem_image.mpr ⟨u,(mem_inter.mp hu).1,rfl⟩, (mem_filter.mp (hDN v (mem_inter.mp hu).2)).2⟩ refine ⟨A,B,himage_subset _,himage_subset _,hdis,?_,?_⟩ · intro v exact ⟨(hA' v).1.trans (Nat.mul_le_mul_left _ (hcount A' v)), (hA' v).2.trans (Nat.mul_le_mul_left _ (hcount (univ\A') v))⟩ · exact Knitting.kConnected_image G Subtype.val Subtype.val_injective hB' end LinearListHadwiger.Sampling end OAI