Download data/lean/OAI/Probability/Ising/SpinCorrelation.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 8.97 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Probability/Ising/SpinCorrelation.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Probability/Ising/SpinCorrelation.lean
-
curl -L -o SpinCorrelation.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Probability/Ising/SpinCorrelation.lean
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 | |