import Mathlib namespace OAI open MeasureTheory ProbabilityTheory namespace CriticalZ3 abbrev Vertex := Fin 3 → ℤ abbrev Bond := Vertex × Fin 3 abbrev BondConfig := Bond → Bool abbrev SiteConfig := Vertex → Bool def step (x : Vertex) (i : Fin 3) : Vertex := fun j => x j + if i = j then 1 else 0 def NearestNeighbor (x y : Vertex) : Prop := ∃ i : Fin 3, y = step x i ∨ x = step y i def BondOpen (ω : BondConfig) (x y : Vertex) : Prop := (∃ i : Fin 3, y = step x i ∧ ω (x, i) = true) ∨ (∃ i : Fin 3, x = step y i ∧ ω (y, i) = true) def SiteOpen (ω : SiteConfig) (x y : Vertex) : Prop := NearestNeighbor x y ∧ ω x = true ∧ ω y = true def BondConnected (ω : BondConfig) (x y : Vertex) : Prop := Relation.ReflTransGen (BondOpen ω) x y def SiteConnected (ω : SiteConfig) (x y : Vertex) : Prop := ω x = true ∧ Relation.ReflTransGen (SiteOpen ω) x y def bondCluster (ω : BondConfig) (x : Vertex) : Set Vertex := {y | BondConnected ω x y} def siteCluster (ω : SiteConfig) (x : Vertex) : Set Vertex := {y | SiteConnected ω x y} def bondInfiniteAt (x : Vertex) : Set BondConfig := {ω | (bondCluster ω x).Infinite} def siteInfiniteAt (x : Vertex) : Set SiteConfig := {ω | (siteCluster ω x).Infinite} noncomputable def parameter (p : ℝ) : Set.Icc (0 : ℝ) 1 := ⟨max 0 (min 1 p), le_max_left _ _, max_le (by norm_num) (min_le_left _ _)⟩ noncomputable def bondLaw (p : ℝ) : Measure BondConfig := Measure.infinitePi (fun _ : Bond => bernoulliMeasure true false (parameter p)) noncomputable def siteLaw (p : ℝ) : Measure SiteConfig := Measure.infinitePi (fun _ : Vertex => bernoulliMeasure true false (parameter p)) noncomputable def bondCritical : ℝ := sInf {p : ℝ | p ∈ Set.Icc (0 : ℝ) 1 ∧ 0 < bondLaw p (bondInfiniteAt 0)} noncomputable def siteCritical : ℝ := sInf {p : ℝ | p ∈ Set.Icc (0 : ℝ) 1 ∧ 0 < siteLaw p (siteInfiniteAt 0)} end CriticalZ3 end OAI