math / data /lean /OAI /Probability /Ising /Basic.lean
introvoyz045's picture
Migrated from GitHub
4a56cd6 verified
Raw History Blame Contribute Delete
9.23 kB
import Mathlib
namespace OAI
open scoped BigOperators Classical
namespace BufferedIsing
/-- A finite graph given by its edge list. Zero couplings can encode missing edges.
Edges are indexed separately so parallel edges are counted separately. -/
structure FiniteGraph (n m : β„•) where
left : Fin m β†’ Fin n
right : Fin m β†’ Fin n
coupling : Fin m β†’ ℝ
coupling_nonneg : βˆ€ e, 0 ≀ coupling e
no_loops : βˆ€ e, left e β‰  right e
abbrev Spins (n : β„•) := Fin n β†’ Bool
def spin (b : Bool) : ℝ := if b then 1 else -1
noncomputable def energy {n m : β„•} (G : FiniteGraph n m)
(h : Fin n β†’ ℝ) (Οƒ : Spins n) : ℝ :=
(βˆ‘ e, G.coupling e * spin (Οƒ (G.left e)) * spin (Οƒ (G.right e))) +
βˆ‘ v, h v * spin (Οƒ v)
noncomputable def weight {n m : β„•} (G : FiniteGraph n m)
(h : Fin n β†’ ℝ) (Οƒ : Spins n) : ℝ := Real.exp (energy G h Οƒ)
def AgreesOn {n : β„•} (S : Finset (Fin n)) (Οƒ Ο„ : Spins n) : Prop :=
βˆ€ v ∈ S, Οƒ v = Ο„ v
noncomputable def constrainedSum {n m : β„•} (G : FiniteGraph n m)
(h : Fin n β†’ ℝ) (P : Spins n β†’ Prop) : ℝ := by
classical
exact βˆ‘ Οƒ, if P Οƒ then weight G h Οƒ else 0
/-- Conditional probability of Οƒ_I=a, with Οƒ_J=b and Οƒ_F=Ο„ prescribed.
All sums are finite and all fields are finite real numbers. -/
noncomputable def conditionalProb {n m : β„•} (G : FiniteGraph n m)
(h : Fin n β†’ ℝ) (I J F : Finset (Fin n)) (a b Ο„ : Spins n) : ℝ :=
constrainedSum G h (fun Οƒ => AgreesOn I Οƒ a ∧ AgreesOn J Οƒ b ∧ AgreesOn F Οƒ Ο„) /
constrainedSum G h (fun Οƒ => AgreesOn J Οƒ b ∧ AgreesOn F Οƒ Ο„)
/-- Edges remaining after DELETION, not pinning, of F. -/
def keptEdges {n m : β„•} (G : FiniteGraph n m) (F : Finset (Fin n)) : Finset (Fin m) :=
Finset.univ.filter (fun e => G.left e βˆ‰ F ∧ G.right e βˆ‰ F)
abbrev KeptVertex {n : β„•} (F : Finset (Fin n)) := {v : Fin n // v βˆ‰ F}
/-- Open-edge adjacency together with the two separate terminal identifications.
No virtual identification of common pins is present: those vertices are absent. -/
def comparisonRel {n m : β„•} (G : FiniteGraph n m)
(I J F : Finset (Fin n)) (Ο‰ : Finset (Fin m)) (u v : KeptVertex F) : Prop :=
(u.val ∈ I ∧ v.val ∈ I) ∨ (u.val ∈ J ∧ v.val ∈ J) ∨
βˆƒ e ∈ Ο‰, (G.left e = u.val ∧ G.right e = v.val) ∨
(G.left e = v.val ∧ G.right e = u.val)
/-- The equivalence closure implements components of the contracted open graph. -/
def comparisonSetoid {n m : β„•} (G : FiniteGraph n m)
(I J F : Finset (Fin n)) (Ο‰ : Finset (Fin m)) : Setoid (KeptVertex F) :=
Relation.EqvGen.setoid (comparisonRel G I J F Ο‰)
noncomputable def clusterCount {n m : β„•} (G : FiniteGraph n m)
(I J F : Finset (Fin n)) (Ο‰ : Finset (Fin m)) : β„• :=
Nat.card (Quotient (comparisonSetoid G I J F Ο‰))
/-- Zero-field FK weight with q=2 and p_e=1-exp(-2 K_e).
Parallel edges may be retained: the measure after summing them is the measure
for the summed parallel coupling. Loops created by contraction do not change
components and cancel from connection probabilities. -/
noncomputable def fkWeight {n m : β„•} (G : FiniteGraph n m)
(I J F : Finset (Fin n)) (Ο‰ : Finset (Fin m)) : ℝ := by
classical
exact (2 : ℝ) ^ clusterCount G I J F Ο‰ *
∏ e ∈ keptEdges G F,
if e ∈ Ο‰ then 1 - Real.exp (-2 * G.coupling e) else Real.exp (-2 * G.coupling e)
/-- Choose any i in I and j in J. The terminal connection is independent of
these choices because I and J are each identified. -/
noncomputable def qZero {n m : β„•} (G : FiniteGraph n m)
(I J F : Finset (Fin n)) (i j : KeptVertex F) : ℝ := by
classical
exact (βˆ‘ Ο‰ ∈ (keptEdges G F).powerset,
if (comparisonSetoid G I J F Ο‰).r i j then fkWeight G I J F Ο‰ else 0) /
βˆ‘ Ο‰ ∈ (keptEdges G F).powerset, fkWeight G I J F Ο‰
/-- Any probability mixture of source prescriptions. Full configurations
index the mixture, but only their restrictions to J are used. Thus this is
exactly the class of all mixtures on {-1,+1}^J. -/
noncomputable def mixtureProb {n m : β„•} (G : FiniteGraph n m)
(h : Fin n β†’ ℝ) (I J F : Finset (Fin n)) (a Ο„ : Spins n)
(mix : Spins n β†’ ℝ) : ℝ :=
βˆ‘ b, mix b * conditionalProb G h I J F a b Ο„
@[simp] lemma spin_true : spin true = 1 := rfl
@[simp] lemma spin_false : spin false = -1 := rfl
/-- The unnormalized I,J marginal with the common pins F fixed. -/
noncomputable def jointWeight {n m : β„•} (G : FiniteGraph n m)
(h : Fin n β†’ ℝ) (I J F : Finset (Fin n)) (Ο„ a b : Spins n) : ℝ :=
constrainedSum G h (fun Οƒ => AgreesOn I Οƒ a ∧ AgreesOn J Οƒ b ∧ AgreesOn F Οƒ Ο„)
/-- Expectation in the unpinned finite Ising law. -/
noncomputable def expectation {n m : β„•} (G : FiniteGraph n m)
(h : Fin n β†’ ℝ) (f : Spins n β†’ ℝ) : ℝ :=
(βˆ‘ Οƒ, weight G h Οƒ * f Οƒ) / βˆ‘ Οƒ, weight G h Οƒ
/-- Arbitrary real background fields do not increase the spin covariance above the zero-field correlation. -/
def ArbitraryFieldCovarianceBound : Prop :=
βˆ€ (n m : β„•) (G : FiniteGraph n m) (h : Fin n β†’ ℝ) (u v : Fin n),
expectation G h (fun Οƒ => spin (Οƒ u) * spin (Οƒ v)) -
expectation G h (fun Οƒ => spin (Οƒ u)) * expectation G h (fun Οƒ => spin (Οƒ v)) ≀
expectation G (fun _ => 0) (fun Οƒ => spin (Οƒ u) * spin (Οƒ v))
lemma weight_pos {n m : β„•} (G : FiniteGraph n m)
(h : Fin n β†’ ℝ) (Οƒ : Spins n) : 0 < weight G h Οƒ := Real.exp_pos _
lemma constrainedSum_nonneg {n m : β„•} (G : FiniteGraph n m)
(h : Fin n β†’ ℝ) (P : Spins n β†’ Prop) : 0 ≀ constrainedSum G h P := by
classical
apply Finset.sum_nonneg
intro Οƒ _
split_ifs
Β· exact (weight_pos G h Οƒ).le
Β· exact le_rfl
lemma constrainedSum_pos {n m : β„•} (G : FiniteGraph n m)
(h : Fin n β†’ ℝ) (P : Spins n β†’ Prop) (Οƒ : Spins n) (hΟƒ : P Οƒ) :
0 < constrainedSum G h P := by
classical
apply lt_of_lt_of_le (weight_pos G h Οƒ)
unfold constrainedSum
exact Finset.single_le_sum (fun Ο„ _ => by
split_ifs
Β· exact (weight_pos G h Ο„).le
· exact le_rfl) (Finset.mem_univ σ) |>.trans' (by simp [hσ])
lemma jointWeight_pos {n m : β„•} (G : FiniteGraph n m)
(h : Fin n β†’ ℝ) (I J F : Finset (Fin n))
(hIJ : Disjoint I J) (hIF : Disjoint I F) (hJF : Disjoint J F)
(Ο„ a b : Spins n) : 0 < jointWeight G h I J F Ο„ a b := by
classical
apply constrainedSum_pos G h _ (fun v => if v ∈ I then a v else if v ∈ J then b v else Ο„ v)
refine ⟨?_, ?_, ?_⟩
Β· intro v hv
simp [hv]
Β· intro v hv
have hi : v βˆ‰ I := fun hvi => (Finset.disjoint_left.mp hIJ) hvi hv
simp [hi, hv]
Β· intro v hv
have hi : v βˆ‰ I := fun hvi => (Finset.disjoint_left.mp hIF) hvi hv
have hj : v βˆ‰ J := fun hvj => (Finset.disjoint_left.mp hJF) hvj hv
simp [hi, hj]
lemma spin_modular (a b : Bool) :
spin a + spin b = spin (a βŠ“ b) + spin (a βŠ” b) := by
cases a <;> cases b <;> norm_num [spin]
lemma spin_product_supermodular (a b c d : Bool) :
spin a * spin b + spin c * spin d ≀
spin (a βŠ“ c) * spin (b βŠ“ d) + spin (a βŠ” c) * spin (b βŠ” d) := by
cases a <;> cases b <;> cases c <;> cases d <;> norm_num [spin]
lemma energy_supermodular {n m : β„•} (G : FiniteGraph n m)
(h : Fin n β†’ ℝ) (Οƒ ρ : Spins n) :
energy G h Οƒ + energy G h ρ ≀ energy G h (Οƒ βŠ“ ρ) + energy G h (Οƒ βŠ” ρ) := by
have he : (βˆ‘ e, (G.coupling e * spin (Οƒ (G.left e)) * spin (Οƒ (G.right e)) +
G.coupling e * spin (ρ (G.left e)) * spin (ρ (G.right e)))) ≀
βˆ‘ e, (G.coupling e * spin ((Οƒ βŠ“ ρ) (G.left e)) * spin ((Οƒ βŠ“ ρ) (G.right e)) +
G.coupling e * spin ((Οƒ βŠ” ρ) (G.left e)) * spin ((Οƒ βŠ” ρ) (G.right e))) := by
apply Finset.sum_le_sum
intro e _
have H := mul_le_mul_of_nonneg_left
(spin_product_supermodular (Οƒ (G.left e)) (Οƒ (G.right e))
(ρ (G.left e)) (ρ (G.right e))) (G.coupling_nonneg e)
simpa only [Pi.inf_apply, Pi.sup_apply, mul_add, mul_assoc] using H
have hv : (βˆ‘ v, (h v * spin (Οƒ v) + h v * spin (ρ v))) =
βˆ‘ v, (h v * spin ((Οƒ βŠ“ ρ) v) + h v * spin ((Οƒ βŠ” ρ) v)) := by
apply Finset.sum_congr rfl
intro v _
simpa only [Pi.inf_apply, Pi.sup_apply, mul_add] using
congrArg (fun x => h v * x) (spin_modular (Οƒ v) (ρ v))
dsimp [energy]
simp only [Finset.sum_add_distrib] at he hv
dsimp at he hv
linarith
lemma weight_logSupermodular {n m : β„•} (G : FiniteGraph n m)
(h : Fin n β†’ ℝ) (Οƒ ρ : Spins n) :
weight G h Οƒ * weight G h ρ ≀ weight G h (Οƒ βŠ“ ρ) * weight G h (Οƒ βŠ” ρ) := by
unfold weight
rw [← Real.exp_add, ← Real.exp_add]
exact Real.exp_le_exp.mpr (energy_supermodular G h Οƒ ρ)
lemma agreesOn_inf {n : β„•} {S : Finset (Fin n)} {Οƒ ρ a b : Spins n}
(ha : AgreesOn S Οƒ a) (hb : AgreesOn S ρ b) : AgreesOn S (Οƒ βŠ“ ρ) (a βŠ“ b) := by
intro v hv
simp only [Pi.inf_apply, ha v hv, hb v hv]
lemma agreesOn_sup {n : β„•} {S : Finset (Fin n)} {Οƒ ρ a b : Spins n}
(ha : AgreesOn S Οƒ a) (hb : AgreesOn S ρ b) : AgreesOn S (Οƒ βŠ” ρ) (a βŠ” b) := by
intro v hv
simp only [Pi.sup_apply, ha v hv, hb v hv]
end BufferedIsing
end OAI