import Mathlib import OAI.Analysis.HardSphere.Paths.Admissible import OAI.Analysis.HardSphere.Allocation.PhysicalGroupComparison import OAI.Analysis.HardSphere.Orbitals.PhysicalOrbitalReference namespace OAI section noncomputable section open MeasureTheory ProbabilityTheory Set open scoped ENNReal BigOperators namespace HardSphere.Groups open Wiener Bridge Sampling Comparison GaussianPacking PathCutoff CellOrbital _root_.OAI.HardSphere.Lattice HardSphere.DyadicSkeleton attribute [local instance] Classical.propDecidable lemma measureAffinity_nsmul {X : Type*} [MeasurableSpace X] (P Q : Measure X) [IsFiniteMeasure P] [IsFiniteMeasure Q] (n : ℕ) : measureAffinity (n • P) (n • Q)=(n:ℝ)*measureAffinity P Q := by have h := measureAffinity_smul P Q (n:ℝ) (Nat.cast_nonneg n) rw [ENNReal.ofReal_natCast] at h simpa only [Nat.cast_smul_eq_nsmul] using h lemma affinity_double_sum_bound {X I J : Type*} [MeasurableSpace X] [Fintype I] [Fintype J] (A : I→J→Bool→Measure X) (Q : Bool→Measure X) (n : ℕ) [∀i j b,IsFiniteMeasure (A i j b)] [∀b,IsFiniteMeasure (Q b)] (h : ∀b,(∑i,∑j,A i j b)≤n • Q b) : (∑i,∑j,measureAffinity (A i j true) (A i j false))≤(n:ℝ)*measureAffinity (Q true) (Q false) := by have hb : (∑i,∑j,measureAffinity (A i j true) (A i j false))≤ measureAffinity (∑i,∑j,A i j true) (∑i,∑j,A i j false) := by refine (Finset.sum_le_sum (fun i _ ↦ measureAffinity_finset_sum Finset.univ (fun j ↦ A i j true) (fun j ↦ A i j false))).trans ?_ exact measureAffinity_finset_sum Finset.univ (fun i ↦ ∑j,A i j true) (fun i ↦ ∑j,A i j false) exact hb.trans ((measureAffinity_mono _ _ _ _ (h true) (h false)).trans_eq (measureAffinity_nsmul _ _ n)) lemma physical_total_posts {N K : ℕ} [NeZero K] {L : Length} (hL : L.val=(K:ℝ)) (hK : 1≤K) (b : Bool) (P : Measure (Torus L×Configuration N L)) [SFinite P] : (∑ij : DiscreteTorus K×DiscreteTorus K, physicalCellVolumePost L (siteIndex (if b then ij.2 else ij.1)) (siteIndex (if b then ij.1 else ij.2)) b ∘ₘ P)= (P.prod volume).map (cellObservation b) := by rw [Fintype.sum_prod_type] cases b <;> simp only [Bool.false_eq_true,ite_false,ite_true] · rw [Finset.sum_comm] have he := physical_cell_posts_sum hL hK false P rw [←he] exact (siteIndexEquiv.sum_comp (fun tag : Fin 3→Fin K ↦ ∑extra : DiscreteTorus K,physicalCellVolumePost L (siteIndex extra) tag false ∘ₘ P)).trans (Finset.sum_congr rfl (fun tag _ ↦ siteIndexEquiv.sum_comp (fun extra : Fin 3→Fin K ↦ physicalCellVolumePost L extra tag false ∘ₘ P))) · rw [←physical_cell_posts_sum hL hK true P] exact (siteIndexEquiv.sum_comp (fun tag : Fin 3→Fin K ↦ ∑extra : DiscreteTorus K,physicalCellVolumePost L (siteIndex extra) tag true ∘ₘ P)).trans (Finset.sum_congr rfl (fun tag _ ↦ siteIndexEquiv.sum_comp (fun extra : Fin 3→Fin K ↦ physicalCellVolumePost L extra tag true ∘ₘ P))) lemma physicalGroupReference_finite {N K M G : ℕ} [NeZero K] {L : Length} {r : ℝ} (hL : L.val=(K:ℝ)) (hK : 1≤K) {ψ : Jet (N+1) L} (hψ : IsGroundVector (N+1) L r ψ) (m : ℕ) (t R C S s₀ : ℝ) (ht : 0≤t) (u : Time) (x y : DiscreteTorus K) (g : Fin G) (b : Bool) : IsFiniteMeasure (physicalGroupReference (M:=M) (x:=x) (y:=y) hL ψ g m t r R C S s₀ u b) := by let (flags : Fin (N+1)→Bool) (a : GridAllocation (N+1) K (G*M)) := physicalBranchLaw_finite hL hK hψ g flags a m R C S s₀ (2*t) (by linarith) u unfold physicalGroupReference infer_instance lemma physical_group_references_le {N K M G : ℕ} [NeZero K] {L : Length} {r : ℝ} (hL : L.val=(K:ℝ)) (hK : 1≤K) (h50 : 50