math / data /lean /OAI /Probability /Ising /SpinCorrelation.lean
introvoyz045's picture
Migrated from GitHub
4a56cd6 verified
Raw History Blame Contribute Delete
8.97 kB
import OAI.Probability.Ising.EdwardsSokal
import OAI.Probability.Ising.TwoSpin
namespace OAI
open scoped BigOperators Classical
namespace BufferedIsing
/-- Extension by the actual common pins, in contrast to the deleted zero-field
comparison graph. -/
def pinExtension {n : β„•} (F : Finset (Fin n)) (Ο„ : Spins n)
(Οƒ : KeptVertex F β†’ Bool) : Spins n :=
fun v => if hv : v ∈ F then Ο„ v else Οƒ ⟨v, hv⟩
lemma pinExtension_agrees {n : β„•} (F : Finset (Fin n)) (Ο„ : Spins n)
(Οƒ : KeptVertex F β†’ Bool) : AgreesOn F (pinExtension F Ο„ Οƒ) Ο„ := by
intro v hv
simp only [pinExtension, dite_eq_left hv]
lemma pinExtension_apply {n : β„•} (F : Finset (Fin n)) (Ο„ : Spins n)
(Οƒ : KeptVertex F β†’ Bool) (v : KeptVertex F) :
pinExtension F Ο„ Οƒ v = Οƒ v := by
simp only [pinExtension, dite_eq_right v.property]
/-- Fixing sites is exactly elimination of their spin variables. This finite
bijection does not replace their interactions by deletion. -/
def pinExtensionEquiv {n : β„•} (F : Finset (Fin n)) (Ο„ : Spins n) :
(KeptVertex F β†’ Bool) ≃ {Οƒ : Spins n // AgreesOn F Οƒ Ο„} where
toFun Οƒ := ⟨pinExtension F Ο„ Οƒ, pinExtension_agrees F Ο„ ΟƒβŸ©
invFun Οƒ v := Οƒ.val v
left_inv Οƒ := by ext v; exact pinExtension_apply F Ο„ Οƒ v
right_inv Οƒ := by
apply Subtype.ext
funext v
by_cases hv : v ∈ F
Β· simpa only [pinExtension, dite_eq_left hv] using (Οƒ.property v hv).symm
Β· simp only [pinExtension, dite_eq_right hv]
lemma constrainedSum_delete_variables {n m : β„•} (G : FiniteGraph n m)
(h : Fin n β†’ ℝ) (F : Finset (Fin n)) (Ο„ : Spins n) (P : Spins n β†’ Prop) :
constrainedSum G h (fun Οƒ => AgreesOn F Οƒ Ο„ ∧ P Οƒ) =
βˆ‘ Οƒ : KeptVertex F β†’ Bool,
if P (pinExtension F Ο„ Οƒ) then weight G h (pinExtension F Ο„ Οƒ) else 0 := by
classical
calc
_ = βˆ‘ Οƒ : Spins n, if AgreesOn F Οƒ Ο„ then
(if P Οƒ then weight G h Οƒ else 0) else 0 := by
unfold constrainedSum
apply Finset.sum_congr rfl
intro Οƒ _
by_cases hF : AgreesOn F Οƒ Ο„ <;> by_cases hP : P Οƒ <;> simp [hF, hP]
_ = βˆ‘ Οƒ ∈ Finset.univ.filter (fun Οƒ : Spins n => AgreesOn F Οƒ Ο„),
if P Οƒ then weight G h Οƒ else 0 := (Finset.sum_filter _ _).symm
_ = βˆ‘ Οƒ : {Οƒ : Spins n // AgreesOn F Οƒ Ο„},
if P Οƒ.val then weight G h Οƒ.val else 0 :=
Finset.sum_subtype _ (by intro Οƒ; simp only [Finset.mem_filter,
Finset.mem_univ, true_and]) _
_ = _ := (Equiv.sum_comp (pinExtensionEquiv F Ο„)
(fun Οƒ => if P Οƒ.val then weight G h Οƒ.val else 0)).symm
/-- A finite two-spin table extracted from a not necessarily normalized spin weight. -/
noncomputable def pairTable {V : Type*} [Fintype V] [DecidableEq V] (W : (V β†’ Bool) β†’ ℝ)
(i j : V) (s t : Bool) : ℝ :=
βˆ‘ Οƒ, if Οƒ i = s ∧ Οƒ j = t then W Οƒ else 0
lemma pairTable_sum {V : Type*} [Fintype V] [DecidableEq V] (W : (V β†’ Bool) β†’ ℝ)
(i j : V) (f : Bool β†’ Bool β†’ ℝ) :
(βˆ‘ s, βˆ‘ t, pairTable W i j s t * f s t) =
βˆ‘ Οƒ, W Οƒ * f (Οƒ i) (Οƒ j) := by
classical
simp only [pairTable, Finset.sum_mul]
calc
_ = βˆ‘ s, βˆ‘ Οƒ, βˆ‘ t, (if Οƒ i = s ∧ Οƒ j = t then W Οƒ else 0) * f s t := by
apply Finset.sum_congr rfl
intro s _
exact Finset.sum_comm
_ = βˆ‘ Οƒ, βˆ‘ s, βˆ‘ t, (if Οƒ i = s ∧ Οƒ j = t then W Οƒ else 0) * f s t :=
Finset.sum_comm
_ = _ := by
apply Finset.sum_congr rfl
intro Οƒ _
cases Οƒ i <;> cases Οƒ j <;> simp
lemma pairTable_expectation {V : Type*} [Fintype V] [DecidableEq V] (W : (V β†’ Bool) β†’ ℝ)
(i j : V) (f : Bool β†’ Bool β†’ ℝ) :
tableExpectation (pairTable W i j) f =
(βˆ‘ Οƒ, W Οƒ * f (Οƒ i) (Οƒ j)) / βˆ‘ Οƒ, W Οƒ := by
unfold tableExpectation
rw [pairTable_sum]
have H := pairTable_sum W i j (fun _ _ => 1)
simp only [mul_one] at H
rw [H]
/-- Global spin reversal is a permutation of configurations. -/
def spinFlipEquiv (V : Type*) : (V β†’ Bool) ≃ (V β†’ Bool) where
toFun Οƒ v := !Οƒ v
invFun Οƒ v := !Οƒ v
left_inv Οƒ := by ext v; simp only [Bool.not_not]
right_inv Οƒ := by ext v; simp only [Bool.not_not]
lemma pairTable_flip {V : Type*} [Fintype V] [DecidableEq V] (W : (V β†’ Bool) β†’ ℝ)
(hW : βˆ€ Οƒ, W (fun v => !Οƒ v) = W Οƒ) (i j : V) (s t : Bool) :
pairTable W i j (!s) (!t) = pairTable W i j s t := by
classical
unfold pairTable
rw [← Equiv.sum_comp (spinFlipEquiv V)
(fun Οƒ => if Οƒ i = !s ∧ Οƒ j = !t then W Οƒ else 0)]
apply Finset.sum_congr rfl
intro Οƒ _
simp only [spinFlipEquiv, Equiv.coe_fn_mk, Bool.not_inj_iff, hW]
lemma symmetricTable_balanced (w : Bool β†’ Bool β†’ ℝ)
(hw : βˆ€ s t, w (!s) (!t) = w s t) : balancedTable w = w := by
have h₁ := hw true true
have hβ‚‚ := hw true false
simp only [Bool.not_true, Bool.not_false] at h₁ hβ‚‚
have hf : tableFieldLeft w = 0 ∧ tableFieldRight w = 0 := by
constructor <;> dsimp only [tableFieldLeft, tableFieldRight] <;> rw [h₁, hβ‚‚] <;> ring
funext s t
simp only [balancedTable, hf.1, hf.2, neg_zero, zero_mul, sub_zero,
Real.exp_zero, mul_one]
lemma symmetricTable_correlation (w : Bool β†’ Bool β†’ ℝ) (hw : βˆ€ s t, 0 < w s t)
(hsym : βˆ€ s t, w (!s) (!t) = w s t) :
tableExpectation w (fun s t => spin s * spin t) = Real.tanh (tableCoupling w) := by
have H := balancedTable_correlation w hw
rw [symmetricTable_balanced w hsym] at H
exact H
lemma respects_spinFlip {V : Type*} (S : Setoid V) (Οƒ : V β†’ Bool) :
Respects S (fun v => !Οƒ v) ↔ Respects S Οƒ := by
unfold Respects
simp only [Bool.not_inj_iff]
lemma deletedEnergy_spinFlip {n m : β„•} (G : FiniteGraph n m)
(F : Finset (Fin n)) (Οƒ : KeptVertex F β†’ Bool) :
deletedEnergy G F (fun v => !Οƒ v) = deletedEnergy G F Οƒ := by
unfold deletedEnergy
apply Finset.sum_congr rfl
intro e he
obtain ⟨hl, hr⟩ := (Finset.mem_filter.mp he).2
have hleft (Οƒ : KeptVertex F β†’ Bool) :
extendKept F Οƒ (G.left e) = Οƒ ⟨G.left e, hl⟩ := by
exact extendKept_apply F Οƒ ⟨G.left e, hl⟩
have hright (Οƒ : KeptVertex F β†’ Bool) :
extendKept F Οƒ (G.right e) = Οƒ ⟨G.right e, hr⟩ := by
exact extendKept_apply F Οƒ ⟨G.right e, hr⟩
rw [hleft, hright, hleft, hright, spin_not, spin_not]
ring
lemma contractedZeroWeight_spinFlip {n m : β„•} (G : FiniteGraph n m)
(I J F : Finset (Fin n)) (Οƒ : KeptVertex F β†’ Bool) :
contractedZeroWeight G I J F (fun v => !Οƒ v) = contractedZeroWeight G I J F Οƒ := by
unfold contractedZeroWeight
rw [respects_spinFlip, deletedEnergy_spinFlip]
lemma contractedZeroWeight_nonneg {n m : β„•} (G : FiniteGraph n m)
(I J F : Finset (Fin n)) (Οƒ : KeptVertex F β†’ Bool) :
0 ≀ contractedZeroWeight G I J F Οƒ := by
unfold contractedZeroWeight
split_ifs
Β· exact (Real.exp_pos _).le
Β· exact le_rfl
lemma contractedZero_pairTable_pos {n m : β„•} (G : FiniteGraph n m)
(I J F : Finset (Fin n)) (hIJ : Disjoint I J)
(i j : KeptVertex F) (hi : i.val ∈ I) (hj : j.val ∈ J) (s t : Bool) :
0 < pairTable (contractedZeroWeight G I J F) i j s t := by
classical
let Οƒ : KeptVertex F β†’ Bool := fun v => if v.val ∈ I then s else t
have hjI : j.val βˆ‰ I := fun hjI => Finset.disjoint_left.mp hIJ hjI hj
have hσi : σ i = s := by simp only [σ, ite_eq_left hi]
have hσj : σ j = t := by simp only [σ, ite_eq_right hjI]
have hresp : Respects (comparisonSetoid G I J F βˆ…) Οƒ := by
intro x y hxy
have hI := comparison_empty_preserves_I G I J F hIJ x y hxy
simp only [Οƒ, hI]
unfold pairTable
apply Finset.sum_pos'
Β· intro Ο„ _
split_ifs
Β· exact contractedZeroWeight_nonneg G I J F Ο„
Β· exact le_rfl
Β· refine βŸ¨Οƒ, Finset.mem_univ _, ?_⟩
rw [ite_eq_left ⟨hΟƒi, hΟƒj⟩, contractedZeroWeight, ite_eq_left hresp]
exact Real.exp_pos _
/-- The FK terminal connection probability is the hyperbolic tangent of the zero-field effective coupling. -/
lemma qZero_eq_tanh_effective {n m : β„•} (G : FiniteGraph n m)
(I J F : Finset (Fin n)) (hIJ : Disjoint I J)
(i j : KeptVertex F) (hi : i.val ∈ I) (hj : j.val ∈ J) :
qZero G I J F i j =
Real.tanh (tableCoupling (pairTable (contractedZeroWeight G I J F) i j)) := by
rw [← symmetricTable_correlation _ (contractedZero_pairTable_pos G I J F hIJ i j hi hj)
(pairTable_flip _ (contractedZeroWeight_spinFlip G I J F) i j)]
rw [pairTable_expectation, qZero_eq_zero_field_correlation]
simp only [mul_assoc]
lemma artanh_qZero_eq_effective {n m : β„•} (G : FiniteGraph n m)
(I J F : Finset (Fin n)) (hIJ : Disjoint I J)
(i j : KeptVertex F) (hi : i.val ∈ I) (hj : j.val ∈ J) :
Real.artanh (qZero G I J F i j) =
tableCoupling (pairTable (contractedZeroWeight G I J F) i j) := by
rw [qZero_eq_tanh_effective G I J F hIJ i j hi hj, Real.artanh_tanh]
end BufferedIsing
end OAI