import Mathlib import OAI.Probability.CriticalPercolation.Exploration.QueryBand import OAI.Probability.CriticalPercolation.Exploration.IncidenceIdentity import OAI.Probability.CriticalPercolation.Exploration.QueryNormalized 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 size_pos {ω : Set E} {v : V} (hC : (G.cluster ω v).Finite) : 0 < size G ω v := (Set.ncard_pos hC).mpr ⟨v,SimpleGraph.Reachable.refl v⟩ lemma mass_eq_min (s : ℕ) (hs : 0 simp [he,hω,hp,coefficient] · simp [he] lemma finite_rootAbsolute_expect (p : ℝ) (hp : p ∈ Ioo 0 1) (w : E → Prop → ℝ) (hw : ∀ e, ∑ b, w e b=1) (hn : ∀ e b, 0≤w e b) (hf : LazyDFS.Fresh w p ∅) (D : ℕ) (hDpos : 1≤D) (hD : ∀ v, (G.incidentEdges {v}).ncard ≤ D) (K : ℕ) (v : V) : expect w (fun ω => rootAbsolute G (4^K) p ω v) ≤ (D:ℝ)/p*(6/(2:ℝ)^K) := by let t := IncidenceSearch.tree G v have hwel (ω : Set E) : rootAbsolute G (4^K) p ω v ≤ (D:ℝ)/p * (|t.centeredSum p ω| * min (1/(4:ℝ)^K) (1/(t.queryCount ω : ℝ))) := by rw [rootAbsolute,rootSum_eq_centered G p hp.1.ne' ω v,abs_div,abs_neg,abs_of_pos hp.1] by_cases hT : t.queryCount ω = 0 · rw [t.centeredSum_eq_zero_of_count ω hT p] simp · have hC := G.finite_cluster_of_finite_bonds (Set.toFinite ω) v have hTD : t.queryCount ω ≤ D*size G ω v := by rw [IncidenceSearch.tree_count,← Set.ncard_eq_toFinset_card'] simpa only [size,mul_comm] using G.incident_ncard_le _ hC D (fun w _ => hD w) have hh := mass_le_normalized G (4^K) (t.queryCount ω) D (by positivity) (Nat.pos_of_ne_zero hT) hDpos ω v hC hTD have hh' : mass G (4^K) ω v ≤ (D:ℝ)*min (1/(4:ℝ)^K) (1/(t.queryCount ω : ℝ)) := by simpa only [Nat.cast_pow,Nat.cast_ofNat] using hh calc _ ≤ ((D:ℝ)*min (1/(4:ℝ)^K) (1/(t.queryCount ω : ℝ))) * (|t.centeredSum p ω|/p) := mul_le_mul_of_nonneg_right hh' (div_nonneg (abs_nonneg _) hp.1.le) _ = _ := by ring calc _ ≤ expect w (fun ω => (D:ℝ)/p * (|t.centeredSum p ω| * min (1/(4:ℝ)^K) (1/(t.queryCount ω : ℝ)))) := expect_mono hn hwel _ = (D:ℝ)/p * expect w (fun ω => |t.centeredSum p ω| * min (1/(4:ℝ)^K) (1/(t.queryCount ω : ℝ))) := expect_const_mul _ _ _ _ ≤ _ := mul_le_mul_of_nonneg_left (t.normalized_centered_bound ∅ (IncidenceSearch.tree_valid G v) p ⟨hp.1.le,hp.2.le⟩ w hw hn hf K) (div_nonneg (Nat.cast_nonneg D) hp.1.le) lemma finite_rootAbsolute_integral (p : unitInterval) (hp : (p:ℝ) ∈ Ioo 0 1) (D : ℕ) (hDpos : 1≤D) (hD : ∀ v, (G.incidentEdges {v}).ncard ≤ D) (K : ℕ) (v : V) : (∫ ω, rootAbsolute G (4^K) p ω v ∂G.law p) ≤ (D:ℝ)/p*(6/(2:ℝ)^K) := by rw [BondGraph.law,← BernoulliProduct.law_const,BernoulliProduct.integral_law_eq_expect] exact finite_rootAbsolute_expect G p hp _ (fun _ => BernoulliProduct.bitWeight_sum p) (fun _ => BernoulliProduct.bitWeight_nonneg p) (fun _ _ => ⟨by simp [BernoulliProduct.bitWeight],by simp [BernoulliProduct.bitWeight]⟩) D hDpos hD K v end CriticalPercolation.FiniteClusters end end end OAI