import Mathlib namespace OAI open Set MeasureTheory ProbabilityTheory namespace CriticalPercolation /-- An undirected graph with labelled bonds, including loops and parallel bonds. -/ structure BondGraph (V E : Type*) where ends : E → Sym2 V namespace BondGraph variable {V E : Type*} (G : BondGraph V E) /-- The graph of retained bonds. `fromEdgeSet` discards loops. -/ def openGraph (ω : Set E) : SimpleGraph V := SimpleGraph.fromEdgeSet (G.ends '' ω) /-- The underlying connectivity graph with every bond retained. -/ def fullGraph : SimpleGraph V := G.openGraph Set.univ /-- Local finiteness counts bonds, not just distinct neighbors. -/ def LocallyFinite : Prop := ∀ v : V, {e : E | v ∈ G.ends e}.Finite /-- Automorphisms preserve the vertex and bond structure, including multiplicities. -/ structure Aut where vertex : V ≃ V edge : E ≃ E preserves : ∀ e, G.ends (edge e) = Sym2.map vertex (G.ends e) /-- Finitely many vertex orbits under the full automorphism group. -/ def QuasiTransitive : Prop := ∃ S : Set V, S.Finite ∧ ∀ v : V, ∃ s ∈ S, ∃ φ : G.Aut, φ.vertex s = v /-- Finite open paths, including the path of length zero, define the open cluster. -/ def cluster (ω : Set E) (v : V) : Set V := {w | (G.openGraph ω).Reachable v w} /-- The event that at least one open cluster is infinite. -/ def percolates : Set (Set E) := {ω | ∃ v : V, (G.cluster ω v).Infinite} /-- Independent retention with parameter `p ∈ [0,1]` of each labelled bond. -/ noncomputable def law (_G : BondGraph V E) (p : unitInterval) : Measure (Set E) := ProbabilityTheory.setBernoulli Set.univ p /-- The infimum of parameters with positive probability of an infinite cluster. -/ noncomputable def criticalProbability : unitInterval := sInf {p : unitInterval | 0 < G.law p G.percolates} end BondGraph end CriticalPercolation end OAI