import Mathlib import OAI.Analysis.HardSphere.Conditioning.UnitPairCount namespace OAI noncomputable section open MeasureTheory Filter Set open scoped ENNReal Topology BigOperators open scoped BigOperators ComplexConjugate open MeasureTheory ProbabilityTheory Filter Set open scoped ENNReal NNReal Topology BigOperators open MeasureTheory ProbabilityTheory Real Complex open scoped ENNReal ComplexConjugate open ProbabilityTheory open MeasureTheory Filter Set open scoped ENNReal Topology open MeasureTheory Set open scoped ENNReal namespace HardSphere open MeasureTheory Set Filter SphericalCoordinates open scoped ENNReal lemma unitOccupation_le {n K : ℕ} {L : Length} (hL : L.val=(K:ℝ)) (p : Fin n → Prop) [DecidablePred p] (v : CubeCell K) (X : Configuration n L) : unitOccupation hL p v X≤n := by exact (Fintype.card_subtype_le _).trans ((Fintype.card_subtype_le _).trans (by simp)) lemma unitPairCount_le {n K : ℕ} {L : Length} (hL : L.val=(K:ℝ)) (p : Fin n → Prop) [DecidablePred p] (v : CubeCell K) (X : Configuration n L) : unitPairCount hL p v X≤(n:ℝ)^2 := by have hn : 0≤(unitOccupation hL p v X:ℝ) := Nat.cast_nonneg _ have hb : (unitOccupation hL p v X:ℝ)≤n := by exact_mod_cast unitOccupation_le hL p v X unfold unitPairCount nlinarith only [hn, mul_self_le_mul_self hn hb] lemma unitPairCount_integrable {n K : ℕ} {L : Length} (hL : L.val=(K:ℝ)) (p : Fin n → Prop) [DecidablePred p] (v : CubeCell K) (u : ScalarL2 n L) : Integrable (fun X ↦ unitPairCount hL p v X*‖u X‖^2) volume := L2_bounded_weight_integrable u (unitPairCount_measurable hL p v) (fun X ↦ by rw [abs_of_nonneg (unitPairCount_nonneg hL p v X)]; exact unitPairCount_le hL p v X) lemma localizedNearLabels_integrable {n : ℕ} (L : Length) (A : Finset (Torus L)) (s : ℝ) (u : ScalarL2 n L) : Integrable (fun X ↦ ((localizedNearLabels L A s X).card:ℝ)*‖u X‖^2) volume := L2_bounded_weight_integrable u ((measurable_of_countable (fun k : ℕ ↦ (k:ℝ))).comp (localizedNearLabels_card_measurable L A s)) (B:=(n:ℝ)) (fun X ↦ by rw [abs_of_nonneg (Nat.cast_nonneg _)]; exact_mod_cast (show (localizedNearLabels L A s X).card≤n by simpa using (localizedNearLabels L A s X).card_le_univ)) def weightedUnitPairCount {n K : ℕ} {L : Length} (hL : L.val=(K:ℝ)) (A : Finset (Torus L)) (X : Configuration n L) : ℝ := ∑ v : CubeCell K, Real.exp (-spatialSiteDistance L A (unitCenter L v))*unitPairCount hL (fun _ ↦ True) v X lemma weightedUnitPairCount_nonneg {n K : ℕ} {L : Length} (hL : L.val=(K:ℝ)) (A : Finset (Torus L)) (X : Configuration n L) : 0≤weightedUnitPairCount hL A X := Finset.sum_nonneg (fun v _ ↦ mul_nonneg (Real.exp_pos _).le (unitPairCount_nonneg hL _ v X)) lemma weightedUnitPairCount_integral {n K : ℕ} {L : Length} (hL : L.val=(K:ℝ)) (A : Finset (Torus L)) (u : ScalarL2 n L) : (∫ X, weightedUnitPairCount hL A X*‖u X‖^2)= ∑ v : CubeCell K, Real.exp (-spatialSiteDistance L A (unitCenter L v))*(∫ X, unitPairCount hL (fun _ ↦ True) v X*‖u X‖^2) := by simp only [weightedUnitPairCount,Finset.sum_mul,mul_assoc] rw [integral_finsetSum] · simp only [integral_const_mul] · intro v _ exact (unitPairCount_integrable hL _ v u).const_mul _ lemma weightedUnitPairCount_integrable {n K : ℕ} {L : Length} (hL : L.val=(K:ℝ)) (A : Finset (Torus L)) (u : ScalarL2 n L) : Integrable (fun X ↦ weightedUnitPairCount hL A X*‖u X‖^2) volume := by simp only [weightedUnitPairCount,Finset.sum_mul,mul_assoc] exact integrable_finsetSum _ (fun v _ ↦ (unitPairCount_integrable hL _ v u).const_mul _) lemma spatial_cell_average_real {n K : ℕ} {L : Length} (hL : L.val=(K:ℝ)) (A : Finset (Torus L)) {r : ℝ} (hr : 0