Download data/lean/OAI/Probability/Ising/PinnedMarginal.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 12.4 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Probability/Ising/PinnedMarginal.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Probability/Ising/PinnedMarginal.lean
-
curl -L -o PinnedMarginal.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Probability/Ising/PinnedMarginal.lean
12.4 kB
| import OAI.Probability.Ising.SpinCorrelation | |
| import OAI.Probability.Ising.Marginals | |
| namespace OAI | |
| open scoped BigOperators Classical | |
| namespace BufferedIsing | |
| /-- The actual contracted marginal retains arbitrary fields and all effects | |
| of the common pins. It is distinct from the zero-field comparison weight. -/ | |
| noncomputable def contractedPinnedWeight {n m : β} (G : FiniteGraph n m) | |
| (h : Fin n β β) (I J F : Finset (Fin n)) (Ο : Spins n) | |
| (Ο : KeptVertex F β Bool) : β := | |
| if Respects (comparisonSetoid G I J F β ) Ο then weight G h (pinExtension F Ο Ο) else 0 | |
| lemma respects_terminals_iff {n m : β} (G : FiniteGraph n m) | |
| (I J F : Finset (Fin n)) (Ο : KeptVertex F β Bool) : | |
| Respects (comparisonSetoid G I J F β ) Ο β | |
| (β x y, x.val β I β y.val β I β Ο x = Ο y) β§ | |
| (β x y, x.val β J β y.val β J β Ο x = Ο y) := by | |
| constructor | |
| Β· intro H | |
| exact β¨fun x y hx hy => H x y (Relation.EqvGen.rel _ _ (Or.inl β¨hx, hyβ©)), | |
| fun x y hx hy => H x y (Relation.EqvGen.rel _ _ (Or.inr (Or.inl β¨hx, hyβ©)))β© | |
| Β· rintro β¨hI, hJβ© x y hxy | |
| induction hxy with | |
| | rel x y h => | |
| rcases h with h | h | β¨e, he, _β© | |
| Β· exact hI x y h.1 h.2 | |
| Β· exact hJ x y h.1 h.2 | |
| Β· exact (Finset.notMem_empty e he).elim | |
| | refl => rfl | |
| | symm _ _ _ ih => exact ih.symm | |
| | trans _ _ _ _ _ ih ih' => exact ih.trans ih' | |
| lemma contracted_prescription_iff {n m : β} (G : FiniteGraph n m) | |
| (I J F : Finset (Fin n)) (hIF : Disjoint I F) (hJF : Disjoint J F) | |
| (i j : KeptVertex F) (hi : i.val β I) (hj : j.val β J) | |
| (Ο : Spins n) (Ο : KeptVertex F β Bool) (s t : Bool) : | |
| (Ο i = s β§ Ο j = t β§ Respects (comparisonSetoid G I J F β ) Ο) β | |
| AgreesOn I (pinExtension F Ο Ο) (fun _ => s) β§ | |
| AgreesOn J (pinExtension F Ο Ο) (fun _ => t) := by | |
| constructor | |
| Β· rintro β¨his, hjt, hrespβ© | |
| obtain β¨hI, hJβ© := (respects_terminals_iff G I J F Ο).mp hresp | |
| constructor | |
| Β· intro v hv | |
| have hvF : v β F := fun hvF => Finset.disjoint_left.mp hIF hv hvF | |
| exact (pinExtension_apply F Ο Ο β¨v, hvFβ©).trans ((hI _ i hv hi).trans his) | |
| Β· intro v hv | |
| have hvF : v β F := fun hvF => Finset.disjoint_left.mp hJF hv hvF | |
| exact (pinExtension_apply F Ο Ο β¨v, hvFβ©).trans ((hJ _ j hv hj).trans hjt) | |
| Β· rintro β¨hI, hJβ© | |
| have hI' : β v : KeptVertex F, v.val β I β Ο v = s := by | |
| intro v hv | |
| simpa only [pinExtension_apply] using hI v.val hv | |
| have hJ' : β v : KeptVertex F, v.val β J β Ο v = t := by | |
| intro v hv | |
| simpa only [pinExtension_apply] using hJ v.val hv | |
| refine β¨hI' i hi, hJ' j hj, (respects_terminals_iff G I J F Ο).mpr ?_β© | |
| exact β¨fun x y hx hy => (hI' x hx).trans (hI' y hy).symm, | |
| fun x y hx hy => (hJ' x hx).trans (hJ' y hy).symmβ© | |
| /-- Identifying each terminal set separately is *exactly* restriction to its | |
| constant configurations; no new model comparison enters this identity. -/ | |
| lemma pairTable_contractedPinned {n m : β} (G : FiniteGraph n m) | |
| (h : Fin n β β) (I J F : Finset (Fin n)) | |
| (hIF : Disjoint I F) (hJF : Disjoint J F) | |
| (i j : KeptVertex F) (hi : i.val β I) (hj : j.val β J) | |
| (Ο : Spins n) (s t : Bool) : | |
| pairTable (contractedPinnedWeight G h I J F Ο) i j s t = | |
| jointWeight G h I J F Ο (fun _ => s) (fun _ => t) := by | |
| classical | |
| have hdel := constrainedSum_delete_variables G h F Ο | |
| (fun Ο => AgreesOn I Ο (fun _ => s) β§ AgreesOn J Ο (fun _ => t)) | |
| have hswap : jointWeight G h I J F Ο (fun _ => s) (fun _ => t) = | |
| constrainedSum G h (fun Ο => AgreesOn F Ο Ο β§ | |
| (AgreesOn I Ο (fun _ => s) β§ AgreesOn J Ο (fun _ => t))) := by | |
| unfold jointWeight constrainedSum | |
| apply Finset.sum_congr rfl | |
| intro Ο _ | |
| congr 1 | |
| exact propext and_rotate.symm | |
| rw [hswap, hdel] | |
| unfold pairTable | |
| apply Finset.sum_congr rfl | |
| intro Ο _ | |
| unfold contractedPinnedWeight | |
| have H := contracted_prescription_iff G I J F hIF hJF i j hi hj Ο Ο s t | |
| by_cases hc : Ο i = s β§ Ο j = t | |
| Β· rw [ite_eq_left hc] | |
| by_cases hr : Respects (comparisonSetoid G I J F β ) Ο | |
| Β· rw [ite_eq_left hr, ite_eq_left (H.mp β¨hc.1, hc.2, hrβ©)] | |
| Β· rw [ite_eq_right hr, ite_eq_right (fun hp => hr (H.mpr hp).2.2)] | |
| Β· rw [ite_eq_right hc, ite_eq_right (fun hp => hc β¨(H.mpr hp).1, (H.mpr hp).2.1β©)] | |
| lemma extremeLogOdds_eq_effective {n m : β} (G : FiniteGraph n m) | |
| (h : Fin n β β) (I J F : Finset (Fin n)) | |
| (hIF : Disjoint I F) (hJF : Disjoint J F) | |
| (i j : KeptVertex F) (hi : i.val β I) (hj : j.val β J) (Ο : Spins n) : | |
| extremeLogOdds G h I J F Ο = | |
| 4 * tableCoupling (pairTable (contractedPinnedWeight G h I J F Ο) i j) := by | |
| simp only [tableCoupling, pairTable_contractedPinned G h I J F hIF hJF i j hi hj] | |
| unfold extremeLogOdds | |
| change _ = 4 * ((Real.log (jointWeight G h I J F Ο β€ β€) + | |
| Real.log (jointWeight G h I J F Ο β₯ β₯) - Real.log (jointWeight G h I J F Ο β€ β₯) - | |
| Real.log (jointWeight G h I J F Ο β₯ β€)) / 4) | |
| ring | |
| lemma sum_pin_incidence {n m : β} (l r : Fin m β Fin n) (F : Finset (Fin n)) (f : Fin m β β) (Ο : Fin n β β) : | |
| (β v : Fin n, if v β F then (β e, if l e = v β§ r e β F then f e else 0) * Ο v else 0) = | |
| β e, if l e β F β§ r e β F then f e * Ο (l e) else 0 := by | |
| classical | |
| calc | |
| _ = β v : Fin n, β e, if v β F β§ l e = v β§ r e β F then f e * Ο v else 0 := by | |
| apply Finset.sum_congr rfl | |
| intro v _ | |
| by_cases hv : v β F | |
| Β· simp [hv] | |
| Β· simp only [hv, not_false_eq_true, ite_true, true_and, Finset.sum_mul] | |
| apply Finset.sum_congr rfl | |
| intro e _ | |
| split_ifs <;> simp | |
| _ = _ := by | |
| rw [Finset.sum_comm] | |
| apply Finset.sum_congr rfl | |
| intro e _ | |
| have H : β v : Fin n, (v β F β§ l e = v β§ r e β F) β | |
| (l e = v β§ l e β F β§ r e β F) := by | |
| intro v | |
| constructor | |
| Β· rintro β¨hv, he, hrβ© | |
| exact β¨he, he.symm βΈ hv, hrβ© | |
| Β· rintro β¨he, hl, hrβ© | |
| exact β¨he βΈ hl, he, hrβ© | |
| simp_rw [H] | |
| by_cases he : l e β F β§ r e β F | |
| Β· simp [he] | |
| Β· simp [he] | |
| /-- The finite-field contribution induced by the actual prescribed spins. | |
| Neither these induced fields nor the original fields survive in `qZero`. -/ | |
| noncomputable def pinField {n m : β} (G : FiniteGraph n m) | |
| (h : Fin n β β) (F : Finset (Fin n)) (Ο : Spins n) (v : KeptVertex F) : β := | |
| h v + (β e, if G.left e = v.val β§ G.right e β F then | |
| G.coupling e * spin (Ο (G.right e)) else 0) + | |
| β e, if G.right e = v.val β§ G.left e β F then | |
| G.coupling e * spin (Ο (G.left e)) else 0 | |
| /-- Field and bond terms depending only on fixed sites. They cancel from | |
| all normalized laws, but recording them makes the elimination exact. -/ | |
| noncomputable def pinConstant {n m : β} (G : FiniteGraph n m) | |
| (h : Fin n β β) (F : Finset (Fin n)) (Ο : Spins n) : β := | |
| (β e, if G.left e β F β§ G.right e β F then | |
| G.coupling e * spin (Ο (G.left e)) * spin (Ο (G.right e)) else 0) + | |
| β v β F, h v * spin (Ο v) | |
| lemma energy_pin_expansion {n m : β} (G : FiniteGraph n m) | |
| (h : Fin n β β) (F : Finset (Fin n)) (Ο Ο : Spins n) (hΟ : AgreesOn F Ο Ο) : | |
| energy G h Ο = pinConstant G h F Ο + | |
| (β e, if G.left e β F β§ G.right e β F then | |
| G.coupling e * spin (Ο (G.left e)) * spin (Ο (G.right e)) else 0) + | |
| β v : Fin n, if v β F then | |
| (h v + (β e, if G.left e = v β§ G.right e β F then | |
| G.coupling e * spin (Ο (G.right e)) else 0) + | |
| β e, if G.right e = v β§ G.left e β F then | |
| G.coupling e * spin (Ο (G.left e)) else 0) * spin (Ο v) else 0 := by | |
| classical | |
| have hsplit : (β v : Fin n, if v β F then | |
| (h v + (β e, if G.left e = v β§ G.right e β F then | |
| G.coupling e * spin (Ο (G.right e)) else 0) + | |
| β e, if G.right e = v β§ G.left e β F then | |
| G.coupling e * spin (Ο (G.left e)) else 0) * spin (Ο v) else 0) = | |
| (β v : Fin n, if v β F then h v * spin (Ο v) else 0) + | |
| (β e, if G.left e β F β§ G.right e β F then | |
| (G.coupling e * spin (Ο (G.right e))) * spin (Ο (G.left e)) else 0) + | |
| (β e, if G.right e β F β§ G.left e β F then | |
| (G.coupling e * spin (Ο (G.left e))) * spin (Ο (G.right e)) else 0) := by | |
| rw [β sum_pin_incidence G.left G.right F | |
| (fun e => G.coupling e * spin (Ο (G.right e))) (fun v => spin (Ο v)), | |
| β sum_pin_incidence G.right G.left F | |
| (fun e => G.coupling e * spin (Ο (G.left e))) (fun v => spin (Ο v))] | |
| rw [β Finset.sum_add_distrib, β Finset.sum_add_distrib] | |
| apply Finset.sum_congr rfl | |
| intro v _ | |
| by_cases hv : v β F <;> simp [hv, add_mul] | |
| rw [hsplit] | |
| unfold energy pinConstant | |
| have he : (β e, G.coupling e * spin (Ο (G.left e)) * spin (Ο (G.right e))) = | |
| (β e, if G.left e β F β§ G.right e β F then | |
| G.coupling e * spin (Ο (G.left e)) * spin (Ο (G.right e)) else 0) + | |
| (β e, if G.left e β F β§ G.right e β F then | |
| G.coupling e * spin (Ο (G.left e)) * spin (Ο (G.right e)) else 0) + | |
| (β e, if G.left e β F β§ G.right e β F then | |
| (G.coupling e * spin (Ο (G.right e))) * spin (Ο (G.left e)) else 0) + | |
| (β e, if G.right e β F β§ G.left e β F then | |
| (G.coupling e * spin (Ο (G.left e))) * spin (Ο (G.right e)) else 0) := by | |
| rw [β Finset.sum_add_distrib, β Finset.sum_add_distrib, β Finset.sum_add_distrib] | |
| apply Finset.sum_congr rfl | |
| intro e _ | |
| by_cases hl : G.left e β F <;> by_cases hr : G.right e β F | |
| Β· simp [hl, hr, hΟ _ hl, hΟ _ hr] | |
| Β· simp [hl, hr, hΟ _ hl] | |
| Β· simp [hl, hr, hΟ _ hr, mul_comm, mul_left_comm] | |
| Β· simp [hl, hr] | |
| have hv : (β v, h v * spin (Ο v)) = | |
| (β v β F, h v * spin (Ο v)) + | |
| (β v : Fin n, if v β F then h v * spin (Ο v) else 0) := by | |
| rw [β Fintype.sum_extend_by_zero F (fun v => h v * spin (Ο v)), | |
| β Finset.sum_add_distrib] | |
| apply Finset.sum_congr rfl | |
| intro v _ | |
| by_cases hv : v β F <;> simp [hv, hΟ v] | |
| rw [he, hv] | |
| ring | |
| lemma sum_kept {n : β} (F : Finset (Fin n)) (f : Fin n β β) : | |
| (β v : KeptVertex F, f v.val) = β v : Fin n, if v β F then f v else 0 := by | |
| classical | |
| rw [β Finset.sum_filter] | |
| exact (Finset.sum_subtype _ (fun v => by simp only [Finset.mem_filter, | |
| Finset.mem_univ, true_and]) f).symm | |
| /-- Exact deletion of fixed sites: their incident bonds become finite real | |
| fields, while only bonds with two free endpoints remain as interactions. -/ | |
| lemma energy_pinExtension {n m : β} (G : FiniteGraph n m) | |
| (h : Fin n β β) (F : Finset (Fin n)) (Ο : Spins n) (Ο : KeptVertex F β Bool) : | |
| energy G h (pinExtension F Ο Ο) = pinConstant G h F Ο + | |
| deletedEnergy G F Ο + β v : KeptVertex F, pinField G h F Ο v * spin (Ο v) := by | |
| classical | |
| rw [energy_pin_expansion G h F Ο _ (pinExtension_agrees F Ο Ο)] | |
| congr 1 | |
| Β· congr 1 | |
| unfold deletedEnergy keptEdges | |
| rw [Finset.sum_filter] | |
| apply Finset.sum_congr rfl | |
| intro e _ | |
| split_ifs with he | |
| Β· simp only [pinExtension, extendKept, dite_eq_right he.1, dite_eq_right he.2, dite_eq_left he.1, dite_eq_left he.2] | |
| Β· rfl | |
| Β· have hs : (β v : KeptVertex F, pinField G h F Ο v * spin (Ο v)) = | |
| β v : Fin n, if v β F then | |
| (h v + (β e, if G.left e = v β§ G.right e β F then | |
| G.coupling e * spin (Ο (G.right e)) else 0) + | |
| β e, if G.right e = v β§ G.left e β F then | |
| G.coupling e * spin (Ο (G.left e)) else 0) * | |
| spin (pinExtension F Ο Ο v) else 0 := by | |
| rw [β sum_kept] | |
| simp only [pinField, pinExtension_apply] | |
| exact hs.symm | |
| lemma weight_pinExtension {n m : β} (G : FiniteGraph n m) | |
| (h : Fin n β β) (F : Finset (Fin n)) (Ο : Spins n) (Ο : KeptVertex F β Bool) : | |
| weight G h (pinExtension F Ο Ο) = Real.exp (pinConstant G h F Ο) * | |
| Real.exp (deletedEnergy G F Ο + β v : KeptVertex F, pinField G h F Ο v * spin (Ο v)) := by | |
| unfold weight | |
| rw [energy_pinExtension] | |
| rw [β Real.exp_add] | |
| congr 1 | |
| ring | |
| end BufferedIsing | |
| end OAI | |