import Mathlib namespace OAI noncomputable section open scoped BigOperators open MeasureTheory ProbabilityTheory Filter namespace SKGap abbrev Spin (n : ℕ) := Fin n → Bool abbrev Edge (n : ℕ) := {p : Fin n × Fin n // p.1 < p.2} abbrev Disorder (n : ℕ) := Edge n → ℝ def spinValue (b : Bool) : ℝ := if b then 1 else -1 def coupling {n : ℕ} (g : Disorder n) (i k : Fin n) : ℝ := if h : i < k then g ⟨(i, k), h⟩ else if h : k < i then g ⟨(k, i), h⟩ else 0 def hamiltonian {n : ℕ} (g : Disorder n) (h : Fin n → ℝ) (x : Spin n) : ℝ := (1 / 2 : ℝ) * ∑ i, ∑ k, spinValue (x i) * coupling g i k * spinValue (x k) + ∑ i, h i * spinValue (x i) def weight {n : ℕ} (g : Disorder n) (h : Fin n → ℝ) (x : Spin n) : ℝ := Real.exp (hamiltonian g h x) def partition {n : ℕ} (g : Disorder n) (h : Fin n → ℝ) : ℝ := ∑ x, weight g h x def mass {n : ℕ} (g : Disorder n) (h : Fin n → ℝ) (x : Spin n) : ℝ := weight g h x / partition g h def expectation {n : ℕ} (g : Disorder n) (h : Fin n → ℝ) (f : Spin n → ℝ) : ℝ := ∑ x, mass g h x * f x def variance {n : ℕ} (g : Disorder n) (h : Fin n → ℝ) (f : Spin n → ℝ) : ℝ := expectation g h (fun x => (f x - expectation g h f) ^ 2) def flip {n : ℕ} (i : Fin n) (x : Spin n) : Spin n := Function.update x i (!(x i)) /-- Conditional expectation under the actual Gibbs law given all other spins. -/ def conditionalExpectation {n : ℕ} (g : Disorder n) (h : Fin n → ℝ) (i : Fin n) (f : Spin n → ℝ) (x : Spin n) : ℝ := (weight g h x * f x + weight g h (flip i x) * f (flip i x)) / (weight g h x + weight g h (flip i x)) /-- Unscaled form: each site has a rate-one clock. -/ def dirichlet {n : ℕ} (g : Disorder n) (h : Fin n → ℝ) (f : Spin n → ℝ) : ℝ := ∑ i, expectation g h (fun x => (f x - conditionalExpectation g h i f x) ^ 2) def disorderLaw (β : ℝ) (n : ℕ) : Measure (Disorder n) := Measure.pi (fun _ : Edge n => gaussianReal 0 (Real.toNNReal (β ^ 2 / n))) def poincareEvent (n : ℕ) (C : ℝ) : Set (Disorder n) := {g | ∀ f : Spin n → ℝ, variance g 0 f ≤ C * dirichlet g 0 f} /-- Rayleigh quotient definition of the uniform-site discrete heat-bath gap. -/ def discreteGap {n : ℕ} (g : Disorder n) : ℝ := sInf {r : ℝ | ∃ f : Spin n → ℝ, 0 < variance g 0 f ∧ r = dirichlet g 0 f / ((n : ℝ) * variance g 0 f)} def MainStatement (β : ℝ) : Prop := ∃ C : ℝ, 0 < C ∧ Tendsto (fun n : ℕ => disorderLaw β n (poincareEvent n C)) atTop (nhds 1) ∧ Tendsto (fun n : ℕ => disorderLaw β n {g | 1 / (C * (n : ℝ)) ≤ discreteGap g}) atTop (nhds 1) end SKGap end end OAI