import Mathlib import OAI.Probability.CriticalPercolation.ProductMeasure.FiniteInterpolationMeasure import OAI.Probability.CriticalPercolation.Criticality.SharpnessPhi import OAI.Probability.CriticalPercolation.Modular.ClusterMassInfinite namespace OAI section noncomputable section open Set MeasureTheory open scoped Classical BigOperators namespace CriticalPercolation.FiniteClusters open FiniteProduct variable {V E : Type*} (G : BondGraph V E) lemma clusterTail_iff_size {ω : Set E} {v : V} (hC : (G.cluster ω v).Finite) (s : ℕ) : ω ∈ G.clusterTail v s ↔ s ≤ size G ω v := by constructor · rintro ⟨A,hA,hAC,hs⟩ exact hs.trans (Set.ncard_le_ncard hAC hC) · intro hs exact ⟨G.cluster ω v,hC,Subset.rfl,hs⟩ lemma size_insert_disconnected (ω : Set E) (e : E) (x y : V) (he : G.ends e = s(x,y)) (hxy : ¬(G.openGraph ω).Reachable x y) (hx : (G.cluster ω x).Finite) (hy : (G.cluster ω y).Finite) : size G (insert e ω) x = size G ω x + size G ω y := by unfold size rw [G.cluster_insert_endpoint ω e x y he, Set.ncard_union_eq (G.cluster_disjoint_of_not_reachable hxy) hx hy] lemma size_insert_connected (ω : Set E) (e : E) (x y : V) (he : G.ends e = s(x,y)) (hxy : (G.openGraph ω).Reachable x y) : size G (insert e ω) x = size G ω x := by unfold size rw [G.cluster_insert_endpoint ω e x y he,G.cluster_eq_of_reachable hxy,Set.union_self] lemma edgeMass_gap (s : ℕ) (hs : 0 edgeDiscrepancy G s p ω e) = expect w (fun ω => if ¬ω e then edgeMass G s ω e - edgeMass G s (insert e ω) e else 0) := by let : DecidableEq E := Classical.decEq E have hflip := expect_closed_flip_decidable w hw e hp h0 h1 (fun ω => edgeMass G s ω e / p) have hu (ω : Set E) : (Function.update ω e True : Set E) = insert e ω := by ext a change Function.update (fun a => ω a) e True a ↔ a=e ∨ a∈ω by_cases ha : a=e · subst a; simp [Function.update] · simp only [Function.update_of_ne ha,ha,false_or]; rfl have hleft : (fun ω : Set E => if ¬ω e then p*(edgeMass G s (Function.update ω e True) e / p) else 0) = (fun ω => if ¬ω e then edgeMass G s (insert e ω) e else 0) := by funext ω rw [hu] split_ifs <;> field_simp [hp.1.ne'] erw [hleft] at hflip have heq (ω : Set E) : edgeDiscrepancy G s p ω e = (if ¬ω e then edgeMass G s ω e else 0) - (if ω e then (1-p)*(edgeMass G s ω e / p) else 0) := by unfold edgeDiscrepancy coefficient change (if ω e then -(1-p)/p else 1) * edgeMass G s ω e = _ by_cases hb : ω e <;> simp only [hb,ite_true,ite_false,not_true_eq_false,not_false_eq_true,sub_zero,zero_sub,one_mul] ring have hfunc := funext heq erw [hfunc,expect_sub,← hflip,← expect_sub] congr 1 funext ω by_cases hb : ω e <;> simp [hb] lemma finite_endpoint_le_expect (s : ℕ) (hs : 0 ω ∈ G.twoClusterEvent (G.ends e).out.1 (G.ends e).out.2 s) ≤ expect w (fun ω => edgeDiscrepancy G s p ω e) := by rw [finite_expect_edgeDiscrepancy G s p hp w hw e h0 h1] apply expect_mono hn intro ω by_cases hb : ω e · have hconn := LazyDFS.prop_openEdge_reachable G ω hb (G.ends e).out_eq.symm have hno : ¬ (ω : Set E) ∈ G.twoClusterEvent (G.ends e).out.1 (G.ends e).out.2 s := by intro hh exact hh.1.1 hconn change (if (ω : Set E) ∈ G.twoClusterEvent _ _ s then (1:ℝ) else 0) ≤ _ simp only [hno,ite_false,hb,not_true_eq_false,le_refl] · simp only [hb,not_false_eq_true,ite_true] exact edgeMass_gap G s hs ω e (G.finite_cluster_of_finite_bonds (Set.toFinite ω) _) (G.finite_cluster_of_finite_bonds (Set.toFinite ω) _) lemma finite_endpoint_le_integral (s : ℕ) (hs : 0 BernoulliProduct.bitWeight p) (fun _ => BernoulliProduct.bitWeight_sum p) (fun _ => BernoulliProduct.bitWeight_nonneg p) e (by simp [BernoulliProduct.bitWeight]) (by simp [BernoulliProduct.bitWeight]) rw [BondGraph.law,← BernoulliProduct.law_const,BernoulliProduct.integral_law_eq_expect] convert hh using 1 · exact (Sharpness.probability_eq_real p (fun ω => ω ∈ G.twoClusterEvent (G.ends e).out.1 (G.ends e).out.2 s)).symm · rfl end CriticalPercolation.FiniteClusters end end end OAI