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