import Mathlib import OAI.Probability.ParisiFinite.SelectedBlock namespace OAI /-! Core Scale Sq Le One. -/ noncomputable section open scoped BigOperators ComplexConjugate InnerProductSpace Topology ComplexOrder open Filter open scoped BigOperators open scoped Matrix Matrix.Norms.L2Operator ComplexConjugate open scoped InnerProductSpace ComplexConjugate open Filter Topology open Filter Set Topology open scoped InnerProductSpace ComplexConjugate Topology open scoped InnerProductSpace open scoped BigOperators Topology InnerProductSpace open scoped BigOperators InnerProductSpace open scoped BigOperators Matrix Topology ComplexConjugate open MeasureTheory ProbabilityTheory Filter open scoped BigOperators Topology open scoped BigOperators Matrix Topology open scoped BigOperators Matrix Topology Matrix.Norms.Operator open scoped Topology open Filter Asymptotics open scoped InnerProductSpace Topology open scoped InnerProductSpace BigOperators open scoped InnerProductSpace Topology BigOperators open scoped Topology BigOperators open scoped Matrix Matrix.Norms.L2Operator InnerProductSpace open scoped Matrix Matrix.Norms.L2Operator InnerProductSpace BigOperators open Filter ContinuousLinearMap open ContinuousLinearMap open scoped InnerProductSpace BigOperators Topology open ContinuousLinearMap InnerProductSpace open ContinuousLinearMap Filter open Filter MeasureTheory open scoped Topology ENNReal open MeasureTheory ProbabilityTheory open scoped BigOperators Topology RealInnerProductSpace open scoped BigOperators TensorProduct open scoped Topology InnerProductSpace open MeasureTheory Filter open MeasureTheory ProbabilityTheory Complex open scoped BigOperators Topology InnerProductSpace ComplexConjugate open scoped BigOperators Topology NNReal open scoped BigOperators NNReal Topology open scoped BigOperators NNReal open scoped NNReal Topology open scoped NNReal Topology BigOperators open MeasureTheory ProbabilityTheory Filter TopologicalSpace open scoped BigOperators Topology NNReal ENNReal open MeasureTheory ProbabilityTheory Filter open scoped BigOperators Topology NNReal ENNReal namespace SKCavity open SKQAOA SKGaussian ParisiInterpolation lemma coreScale_sq_le_one (n : ℕ) : coreScale n^2 ≤ 1 := by rw [coreScale_sq] apply (div_le_one (by positivity : (0:ℝ) N+N) atTop atTop := tendsto_atTop_mono (fun N => Nat.le_add_right N N) tendsto_id have h := (((tendsto_pressure_perSpin hβ).comp hN).const_mul 2).sub (tendsto_pressure_perSpin hβ) have he : ∀ᶠ N in atTop, windowSlope β N= 2*(pressure β (N+N)/(N+N:ℕ))-pressure β N/(N:ℝ) := by filter_upwards [eventually_gt_atTop 0] with N hN have hN' : (N:ℝ)≠0 := Nat.cast_ne_zero.mpr hN.ne' dsimp [windowSlope] push_cast field_simp ring apply Tendsto.congr' (he.mono fun _ h => h.symm) simpa only [Function.comp_def, show 2*(β*limitingFreeEnergy β)-β*limitingFreeEnergy β=β*limitingFreeEnergy β by ring] using h lemma cavityWindowBudget_root_bound {N m : ℕ} (hN : 0 windowSlope β N+ (Real.pi*(8*(m+1:ℕ)+4*(∑ k,(d k:ℝ))))/(eighthRootScale N^2)+ (ell*(m+1:ℕ)*(17+4*|β|+12*(m+1:ℕ)))/eighthRootScale N) atTop (𝓝 (β*limitingFreeEnergy β)) := by have hi : Tendsto (fun N => (eighthRootScale N)⁻¹) atTop (𝓝 0) := tendsto_inv_atTop_zero.comp tendsto_eighthRootScale have h1 := (hi.pow 2).const_mul (Real.pi*(8*(m+1:ℕ)+4*(∑ k,(d k:ℝ)))) have h2 := hi.const_mul (ell*(m+1:ℕ)*(17+4*|β|+12*(m+1:ℕ))) have h := ((tendsto_windowSlope hβ).add h1).add h2 simpa only [div_eq_mul_inv,inv_pow,zero_pow (by decide : 2≠0),mul_zero,add_zero] using h end SKCavity open MeasureTheory ProbabilityTheory Filter open scoped BigOperators Topology NNReal ENNReal namespace SKCavity open SKQAOA SKGaussian ParisiInterpolation theorem exists_cavity_compatible {m : ℕ} (d : Fin (m+1) → ℕ) {β : ℝ} (hβ : 0<β) (M : ℕ) {ε : ℝ} (hε : 0<ε) : ∃ (n : ℕ) (x : Fin (m+1) → ℝ), M ≤ n ∧ 0 (eighthRootScale N)⁻¹) atTop (𝓝 0) := tendsto_inv_atTop_zero.comp tendsto_eighthRootScale have hv : Tendsto (fun N => 4*(m+1:ℕ)/(eighthRootScale N^2)) atTop (𝓝 0) := by simpa only [div_eq_mul_inv,inv_pow,zero_pow (by decide : 2≠0),mul_zero] using (hi.pow 2).const_mul ((4:ℝ)*(m+1:ℕ)) have hv' : ∀ᶠ N in atTop, 4*(m+1:ℕ)/(eighthRootScale N^2)<ε := hv.eventually (eventually_lt_nhds hε) obtain ⟨N,hN,hMN,hBN,hVN⟩ := (eventually_gt_atTop 0 |>.and ((eventually_ge_atTop M).and (hB.and hv'))).exists have hr := one_le_eighthRootScale hN have hrp : 0 ?_⟩ · have hs := Finset.sum_le_sum (fun k (_ : k∈Finset.univ) => eighthRoot_amplitude_pressure_bound hN (hx k)) rw [← Finset.sum_div] at hs simp only [Finset.sum_const,Finset.card_univ,Fintype.card_fin,nsmul_eq_mul] at hs have hn' : (0:ℝ) sq_nonneg (x k)) hn' hle apply hd.trans (hs.trans _) have he : (m+1:ℕ)*(4/(eighthRootScale N^2))=4*(m+1:ℕ)/(eighthRootScale N^2) := by ring rw [he] exact hVN.le · exact hc.trans (hbudget.trans (add_le_add_right hτε P)) · apply (hg k r i f hf).trans apply (div_le_iff₀ hell).mpr have habs : P-a ≤ |P-a| := le_abs_self _ have he : τ*ell=|P-a|+2 := by dsimp [ell]; field_simp have hmul := mul_le_mul_of_nonneg_right hτε hell.le change _-a ≤ ε*ell nlinarith only [hbudget,habs,hτ1,he,hmul] end SKCavity open MeasureTheory ProbabilityTheory Filter open scoped BigOperators Topology NNReal ENNReal namespace SKCavity open SKQAOA SKGaussian ParisiInterpolation def compatibleSize {β : ℝ} (hβ : 0<β) (m : ℕ) : ℕ := (exists_cavity_compatible (show Fin (m+1) → ℕ from Fin.val) hβ (m+1) (by positivity : (0:ℝ)<1/(m+1:ℕ))).choose def compatibleAmplitude {β : ℝ} (hβ : 0<β) (m : ℕ) : Fin (m+1) → ℝ := (exists_cavity_compatible (show Fin (m+1) → ℕ from Fin.val) hβ (m+1) (by positivity : (0:ℝ)<1/(m+1:ℕ))).choose_spec.choose lemma compatible_spec {β : ℝ} (hβ : 0<β) (m : ℕ) : m+1 ≤ compatibleSize hβ m ∧ 0 (1:ℝ)/(m+1:ℕ)) atTop (𝓝 0) := by have h : Tendsto (fun m : ℕ => ((m+1:ℕ):ℝ)) atTop atTop := tendsto_natCast_atTop_atTop.comp (tendsto_atTop_mono (fun m => Nat.le_succ m) tendsto_id) simpa only [one_div,Function.comp_def] using tendsto_inv_atTop_zero.comp h lemma tendsto_compatibleGG {β : ℝ} (hβ : 0<β) (p r : ℕ) (i : Fin r) (f : ∀ m, (Fin r → Configuration (compatibleSize hβ m)) → ℝ) (hf : ∀ m σ, |f m σ| ≤ 1) : Tendsto (fun m => overlapGGDefect (compatibleCoeff hβ m) p i (f m)) atTop (𝓝 0) := by apply tendsto_zero_iff_norm_tendsto_zero.mpr simp only [Real.norm_eq_abs] exact squeeze_zero' (Eventually.of_forall fun m => abs_nonneg _) ((eventually_ge_atTop p).mono fun m hm => compatibleGG_le hβ hm i (f m) (hf m)) tendsto_succ_reciprocal lemma compatible_limit_Gram {β : ℝ} (hβ : 0<β) {μ : ProbabilityMeasure OverlapArray} {φ : ℕ → ℕ} (hμ : Tendsto (fun k => compatibleLaw hβ (φ k)) atTop (𝓝 μ)) : (μ : Measure _) GramArrays=1 := by have h := ProbabilityMeasure.limsup_measure_closed_le_of_tendsto hμ isClosed_GramArrays have he : ∀ k, (compatibleLaw hβ (φ k) : Measure _) GramArrays=(1:ℝ≥0∞) := fun k => finiteProbability_set_of_forall _ (fieldReplicaMass_nonneg _) (sum_fieldReplicaMass (φ k+1) _) _ (configurationOverlap_mem_Gram (compatible_spec hβ (φ k)).2.1) simp_rw [he] at h rw [limsup_const] at h exact le_antisymm prob_le_one h lemma compatible_limit_GG {β : ℝ} (hβ : 0<β) {μ : ProbabilityMeasure OverlapArray} {φ : ℕ → ℕ} (hφ : StrictMono φ) (hμ : Tendsto (fun k => compatibleLaw hβ (φ k)) atTop (𝓝 μ)) (r p : ℕ) (i : Fin r) (f : C(OverlapBlock r,ℝ)) (hf : ∀ R, |f R| ≤ 1) : arrayGGDefect μ r p i f=0 := by have hz := (tendsto_compatibleGG hβ p r i (fun _ σ => f (blockOfReplicas σ)) (fun _ σ => hf _)).comp hφ.tendsto_atTop have he : ∀ᶠ k in atTop, overlapGGDefect (compatibleCoeff hβ (φ k)) p i (fun σ => f (blockOfReplicas σ))= arrayGGDefect (compatibleLaw hβ (φ k)) r p i f := by filter_upwards [hφ.tendsto_atTop.eventually (eventually_ge_atTop (max r 1))] with k hk exact (arrayGGDefect_fieldOverlapLaw (by omega) (by omega) _ p i f).symm exact tendsto_nhds_unique ((continuous_arrayGGDefect r p i f).tendsto μ |>.comp hμ) (hz.congr' he) end SKCavity open MeasureTheory ProbabilityTheory Filter TopologicalSpace open scoped BigOperators Topology NNReal ENNReal namespace SKCavity open SKQAOA SKGaussian ParisiInterpolation lemma compatible_limit_GG_unbounded {β : ℝ} (hβ : 0<β) {μ : ProbabilityMeasure OverlapArray} {φ : ℕ → ℕ} (hφ : StrictMono φ) (hμ : Tendsto (fun k => compatibleLaw hβ (φ k)) atTop (𝓝 μ)) (r p : ℕ) (i : Fin r) (f : C(OverlapBlock r,ℝ)) : arrayGGDefect μ r p i f=0 := by let M : ℝ := ‖f‖+1 have hm : 0 M⁻¹*f R)=0 at h rw [arrayGGDefect_const_mul] at h exact (mul_eq_zero.mp h).resolve_left (inv_ne_zero hm.ne') theorem compatible_limit_continuousGG {β : ℝ} (hβ : 0<β) {μ : ProbabilityMeasure OverlapArray} {φ : ℕ → ℕ} (hφ : StrictMono φ) (hμ : Tendsto (fun k => compatibleLaw hβ (φ k)) atTop (𝓝 μ)) (r : ℕ) (i : Fin r) (f : C(OverlapBlock r,ℝ)) (ψ : C(OverlapEntry,ℝ)) : continuousGG μ r i f ψ=0 := by let L := continuousGG μ r i f have hp (p : ℕ) : L (overlapPower p)=0 := by rw [continuousGG_power] exact compatible_limit_GG_unbounded hβ hφ hμ r p i f have hpoly (p : Polynomial ℝ) : L (p.toContinuousMapOn (Set.Icc (-1:ℝ) 1))=0 := by induction p using Polynomial.induction_on' with | add p q hp hq => have he : (p+q).toContinuousMapOn (Set.Icc (-1:ℝ) 1)=p.toContinuousMapOn _+q.toContinuousMapOn _ := by ext x; simp [Polynomial.toContinuousMapOn] rw [he, map_add, hp, hq, add_zero] | monomial p a => have he : (Polynomial.monomial p a).toContinuousMapOn (Set.Icc (-1:ℝ) 1)=a • overlapPower p := by ext x; simp [Polynomial.toContinuousMapOn, overlapPower] rw [he, map_smul, hp, smul_zero] have hs : (polynomialFunctions (Set.Icc (-1:ℝ) 1) : Set C(OverlapEntry,ℝ)) ⊆ {g | L g=0} := by intro g hg rw [polynomialFunctions_coe] at hg rcases hg with ⟨p,rfl⟩ exact hpoly p have hc := closure_minimal hs (isClosed_eq L.continuous continuous_const) exact hc (continuousMap_mem_polynomialFunctions_closure (-1) 1 ψ) lemma compatible_limit_exchangeable_integral {β : ℝ} (hβ : 0<β) {μ : ProbabilityMeasure OverlapArray} {φ : ℕ → ℕ} (hφ : StrictMono φ) (hμ : Tendsto (fun k => compatibleLaw hβ (φ k)) atTop (𝓝 μ)) (r : ℕ) (e : Fin r → ℕ) (he : Function.Injective e) (f : C(OverlapBlock r,ℝ)) : (∫ R, f (selectedBlock e R) ∂(μ : Measure OverlapArray))= ∫ R, f (blockOfArray r R) ∂(μ : Measure OverlapArray) := by let F : C(OverlapArray,ℝ) := f.comp ⟨selectedBlock e,continuous_selectedBlock e⟩ let G : C(OverlapArray,ℝ) := f.comp ⟨blockOfArray r,continuous_blockOfArray r⟩ have hF := (ProbabilityMeasure.continuous_integral_continuousMap F).tendsto μ |>.comp hμ have hG := (ProbabilityMeasure.continuous_integral_continuousMap G).tendsto μ |>.comp hμ have ha : ∀ᶠ k in atTop, (∫ R, F R ∂(compatibleLaw hβ (φ k) : Measure OverlapArray))= ∫ R, G R ∂(compatibleLaw hβ (φ k) : Measure OverlapArray) := by filter_upwards [hφ.tendsto_atTop.eventually (eventually_ge_atTop (max r (∑ i,e i)))] with k hk have hr : r ≤ φ k+1 := by omega have ht (i : Fin r) : e i<φ k+1 := by have h := Finset.single_le_sum (fun j _ => Nat.zero_le (e j)) (Finset.mem_univ i) omega change (∫ R, f (selectedBlock e R) ∂(fieldOverlapLaw (t:=φ k) (compatibleCoeff hβ (φ k)) : Measure _))=_ rw [integral_fieldOverlapLaw_selected hr e he ht] exact (integral_fieldOverlapLaw_block hr _ f).symm exact tendsto_nhds_unique (hF.congr' ha) hG theorem compatible_limit_exchangeable {β : ℝ} (hβ : 0<β) {μ : ProbabilityMeasure OverlapArray} {φ : ℕ → ℕ} (hφ : StrictMono φ) (hμ : Tendsto (fun k => compatibleLaw hβ (φ k)) atTop (𝓝 μ)) (r : ℕ) (e : Fin r → ℕ) (he : Function.Injective e) : (μ : Measure OverlapArray).map (selectedBlock e)=blockLaw μ r := by apply ext_of_forall_integral_eq_of_IsFiniteMeasure intro f rw [integral_map (continuous_selectedBlock e).measurable.aemeasurable f.continuous.aestronglyMeasurable, blockLaw, integral_map (continuous_blockOfArray r).measurable.aemeasurable f.continuous.aestronglyMeasurable] exact compatible_limit_exchangeable_integral hβ hφ hμ r e he f.toContinuousMap theorem exists_compatible_ultrametric_limit {β : ℝ} (hβ : 0<β) : ∃ (μ : ProbabilityMeasure OverlapArray) (φ : ℕ → ℕ), StrictMono φ ∧ Tendsto (fun k => compatibleLaw hβ (φ k)) atTop (𝓝 μ) ∧ (μ : Measure OverlapArray) GramArrays=1 ∧ GGIdentities μ ∧ FiniteExchangeable μ ∧ (μ : Measure OverlapArray) UltrametricArrays=1 ∧ ∀ k, compatibleValue hβ (φ k) ≤ β*limitingFreeEnergy β+1/(φ k+1:ℕ) := by obtain ⟨μ,φ,hφ,hμ⟩ := CompactSpace.tendsto_subseq (compatibleLaw hβ) have hG := compatible_limit_Gram hβ hμ have hgg : GGIdentities μ := fun r i => GG_measure_identity μ r i (compatible_limit_continuousGG hβ hφ hμ r i) have hex : FiniteExchangeable μ := compatible_limit_exchangeable hβ hφ hμ exact ⟨μ,φ,hφ,hμ,hG,hgg,hex,GG_ultrametric hG hgg hex,fun k => compatibleValue_le hβ (φ k)⟩ end SKCavity open MeasureTheory ProbabilityTheory Filter TopologicalSpace open scoped BigOperators Topology NNReal ENNReal namespace SKCavity open SKQAOA SKGaussian ParisiInterpolation def partitionBlock {r : ℕ} (c : Fin r → ℕ) (q : ℝ) : Set (OverlapBlock r) := {T | ∀ i j, q<(T i j:ℝ) ↔ c i=c j} def partitionEvent {r : ℕ} (c : Fin r → ℕ) (q : ℝ) : Set OverlapArray := (blockOfArray r) ⁻¹' partitionBlock c q lemma measurableSet_partitionBlock {r : ℕ} (c : Fin r → ℕ) (q : ℝ) : MeasurableSet (partitionBlock c q) := by unfold partitionBlock simp only [Set.ofPred_forall] apply MeasurableSet.iInter intro i apply MeasurableSet.iInter intro j by_cases h : c i=c j · simp only [h,iff_true] exact measurableSet_lt measurable_const (by fun_prop) · simp only [h,iff_false,not_lt] exact measurableSet_le (by fun_prop) measurable_const lemma measurableSet_partitionEvent {r : ℕ} (c : Fin r → ℕ) (q : ℝ) : MeasurableSet (partitionEvent c q) := (measurableSet_partitionBlock c q).preimage (continuous_blockOfArray r).measurable def clusterCount {r : ℕ} (c : Fin r → ℕ) (i : Fin r) : ℕ := (Finset.univ.filter (fun j => c j=c i)).card lemma clusterCount_pos {r : ℕ} (c : Fin r → ℕ) (i : Fin r) : 0 hR.1,fun hR => ⟨hR,(hR i j).mpr h⟩⟩ · ext R simp only [Set.mem_ofPred_eq,Set.mem_empty_iff_false,iff_false] exact fun hR => h ((hR.1 i j).mp hR.2) theorem GG_partition_join {μ : ProbabilityMeasure OverlapArray} (hgg : GGIdentities μ) {r : ℕ} (c : Fin r → ℕ) (q : ℝ) (i : Fin r) : (r:ℝ)*(μ:Measure OverlapArray).real {R | R∈partitionEvent c q ∧ q<(R i r:ℝ)}= (μ:Measure OverlapArray).real (partitionEvent c q)* ((clusterCount c i:ℝ)-1+(entryLaw μ 0 1).real {x | q<(x:ℝ)}) := by have h := GG_event_identity hgg r i (partitionBlock c q) {x | q<(x:ℝ)} (measurableSet_partitionBlock c q) (measurableSet_lt measurable_const (by fun_prop)) change (r:ℝ)*(μ:Measure OverlapArray).real {R | R∈partitionEvent c q ∧ q<(R i r:ℝ)}= (μ:Measure OverlapArray).real (partitionEvent c q)*(entryLaw μ 0 1).real {x | q<(x:ℝ)}+ ∑ l∈Finset.univ.erase i,(μ:Measure OverlapArray).real {R | R∈partitionEvent c q ∧ q<(R i l:ℝ)} at h simp_rw [partition_pair_event] at h simp only [apply_ite,measureReal_empty] at h have hs : (∑ l∈Finset.univ.erase i,if c i=c l then (μ:Measure OverlapArray).real (partitionEvent c q) else 0)= ((clusterCount c i:ℝ)-1)*(μ:Measure OverlapArray).real (partitionEvent c q) := by have hj : (∑ l : Fin r,if c i=c l then (μ:Measure OverlapArray).real (partitionEvent c q) else 0)= (clusterCount c i:ℝ)*(μ:Measure OverlapArray).real (partitionEvent c q) := by simp only [← Finset.sum_filter] simp only [Finset.sum_const,nsmul_eq_mul] congr 2 apply congrArg Finset.card ext l simp only [Finset.mem_filter,Finset.mem_univ,true_and,eq_comm] have hh := Finset.sum_erase_add (s:=Finset.univ) (f:=fun l => if c i=c l then (μ:Measure OverlapArray).real (partitionEvent c q) else 0) (Finset.mem_univ i) simp only [ite_true] at hh rw [hj] at hh linarith rw [hs] at h nlinarith only [h] lemma ultrametric_partition_join_disjoint {r : ℕ} (c : Fin r → ℕ) (q : ℝ) (i j : Fin r) (hij : c i≠c j) : Disjoint {R | R∈UltrametricArrays ∧ R∈partitionEvent c q ∧ q<(R i r:ℝ)} {R | R∈UltrametricArrays ∧ R∈partitionEvent c q ∧ q<(R j r:ℝ)} := by apply Set.disjoint_left.mpr intro R hi hj have hu := hi.1 i j r exact hij ((hi.2.1 i j).mp ((lt_min hi.2.2 hj.2.2).trans_le hu)) end SKCavity open MeasureTheory ProbabilityTheory Filter TopologicalSpace open scoped BigOperators Topology NNReal ENNReal namespace SKCavity open SKQAOA SKGaussian ParisiInterpolation def overlapDiscount (μ : ProbabilityMeasure OverlapArray) (q : ℝ) : ℝ := (entryLaw μ 0 1).real {x | (x:ℝ) ≤ q} lemma entry_upper_mass (μ : ProbabilityMeasure OverlapArray) (q : ℝ) : (entryLaw μ 0 1).real {x | q<(x:ℝ)}=1-overlapDiscount μ q := by let := entryLaw_probability μ 0 1 have h : {x : OverlapEntry | q<(x:ℝ)}={x : OverlapEntry | (x:ℝ) ≤ q}ᶜ := by ext x; simp rw [h,probReal_compl_eq_one_sub (measurableSet_le (by fun_prop) measurable_const)] rfl lemma GG_cluster_join {μ : ProbabilityMeasure OverlapArray} (hgg : GGIdentities μ) {r : ℕ} (c : Fin r → ℕ) (q : ℝ) (i : Fin r) : (r:ℝ)*(μ:Measure OverlapArray).real {R | R∈partitionEvent c q ∧ q<(R i r:ℝ)}= ((clusterCount c i:ℝ)-overlapDiscount μ q)*(μ:Measure OverlapArray).real (partitionEvent c q) := by rw [GG_partition_join hgg,entry_upper_mass] ring def ClusterReps {r : ℕ} (c : Fin r → ℕ) (S : Finset (Fin r)) : Prop := Set.InjOn c S ∧ ∀ i, ∃ j∈S, c j=c i lemma exists_clusterReps {r : ℕ} (c : Fin r → ℕ) : ∃ S, ClusterReps c S := by have h : Set.SurjOn c Set.univ (Finset.univ.image c) := by intro i hi obtain ⟨j,_,rfl⟩ := Finset.mem_image.mp hi exact ⟨j,Set.mem_univ _,rfl⟩ obtain ⟨S,_,hinj,hS⟩ := Finset.exists_subset_injOn_image_eq_of_surjOn Set.univ (Finset.univ.image c) h refine ⟨S,hinj,fun i => ?_⟩ have hi : c i∈S.image c := by rw [hS]; exact Finset.mem_image_of_mem _ (Finset.mem_univ i) exact Finset.mem_image.mp hi lemma sum_clusterCount {r : ℕ} {c : Fin r → ℕ} {S : Finset (Fin r)} (hS : ClusterReps c S) : (∑ i∈S, clusterCount c i)=r := by have hc (i) : clusterCount c i=∑ j : Fin r,if c j=c i then 1 else 0 := by simp [clusterCount] simp_rw [hc] rw [Finset.sum_comm] have h1 (j : Fin r) : (∑ i∈S,if c j=c i then 1 else 0)=1 := by obtain ⟨i,hi,hij⟩ := hS.2 j rw [Finset.sum_eq_single i] · simp [hij] · intro k hk hki have hne : c j≠c k := fun hh => hki (hS.1 hk hi (hh.symm.trans hij.symm)) simp [hne] · exact fun h => (h hi).elim simp_rw [h1] simp lemma ae_full_probability {X : Type*} [MeasurableSpace X] (μ : ProbabilityMeasure X) {S : Set X} (hS : MeasurableSet S) (h : (μ:Measure X) S=1) : ∀ᵐ x ∂(μ:Measure X), x∈S := by apply ae_iff.mpr change (μ:Measure X) Sᶜ=0 rw [measure_compl hS (measure_ne_top _ _),h] simp theorem GG_cluster_innovation {μ : ProbabilityMeasure OverlapArray} (hG : (μ:Measure OverlapArray) GramArrays=1) (hgg : GGIdentities μ) (hu : (μ:Measure OverlapArray) UltrametricArrays=1) {r : ℕ} {c : Fin r → ℕ} {S : Finset (Fin r)} (hS : ClusterReps c S) (q : ℝ) : (r:ℝ)*(μ:Measure OverlapArray).real {R | R∈partitionEvent c q ∧ ∀ i : Fin r, (R i r:ℝ) ≤ q}= (S.card:ℝ)*overlapDiscount μ q*(μ:Measure OverlapArray).real (partitionEvent c q) := by let U := GramArrays∩UltrametricArrays have hUa : ∀ᵐ R ∂(μ:Measure OverlapArray), R∈U := (ae_full_probability μ isClosed_GramArrays.measurableSet hG).and (ae_full_probability μ isClosed_UltrametricArrays.measurableSet hu) have hUr (T : Set OverlapArray) : (μ:Measure OverlapArray).real (U∩T)=(μ:Measure OverlapArray).real T := congrArg ENNReal.toReal (Measure.measure_inter_eq_of_ae hUa) let E := partitionEvent c q let J (i : Fin r) : Set OverlapArray := {R | R∈E ∧ q<(R i r:ℝ)} let A : Set OverlapArray := ⋃ i∈S, J i have hJ (i : Fin r) : MeasurableSet (J i) := by change MeasurableSet (partitionEvent c q ∩ {R : OverlapArray | q<(R i r:ℝ)}) exact (measurableSet_partitionEvent c q).inter (measurableSet_lt measurable_const (by fun_prop)) have hA : MeasurableSet A := MeasurableSet.iUnion fun i => MeasurableSet.iUnion fun _ => hJ i have hdis : Set.PairwiseDisjoint (S:Set (Fin r)) (fun i => U∩J i) := by intro i hi j hj hij apply Set.disjoint_left.mpr intro R hRi hRj have hne : c i≠c j := fun hh => hij (hS.1 hi hj hh) have h := hRi.1.2 i j r exact hne ((hRi.2.1 i j).mp ((lt_min hRi.2.2 hRj.2.2).trans_le h)) have hsum : (μ:Measure OverlapArray).real A=∑ i∈S,(μ:Measure OverlapArray).real (J i) := by rw [← hUr A] have he : U∩A=⋃ i∈S,U∩J i := by ext R; simp only [A,Set.mem_inter_iff,Set.mem_iUnion]; aesop rw [he,measureReal_biUnion_finset hdis (fun i _ => (isClosed_GramArrays.measurableSet.inter isClosed_UltrametricArrays.measurableSet).inter (hJ i))] exact Finset.sum_congr rfl fun i _ => hUr (J i) have hcompl : (μ:Measure OverlapArray).real {R | R∈E ∧ ∀ i : Fin r, (R i r:ℝ) ≤ q}= (μ:Measure OverlapArray).real (E\A) := by apply congrArg ENNReal.toReal apply measure_congr filter_upwards [hUa] with R hR apply propext constructor · rintro ⟨hE,hnew⟩ refine ⟨hE,?_⟩ simp only [A,Set.mem_iUnion] rintro ⟨i,hi,hj⟩ exact (not_lt_of_ge (hnew i)) hj.2 · rintro ⟨hE,hnot⟩ refine ⟨hE,fun i => ?_⟩ by_contra hi have hi' : q<(R i r:ℝ) := lt_of_not_ge hi obtain ⟨j,hj,hij⟩ := hS.2 i have ho : q<(R j i:ℝ) := (hE j i).mpr hij have hu' := hR.2 j r i rw [hR.1.1 r i] at hu' have hj' : q<(R j r:ℝ) := (lt_min ho hi').trans_le hu' exact hnot (Set.mem_iUnion.mpr ⟨j,Set.mem_iUnion.mpr ⟨hj,⟨hE,hj'⟩⟩⟩) rw [hcompl,measureReal_sdiff (by intro R hR obtain ⟨i,hR⟩ := Set.mem_iUnion.mp hR obtain ⟨_,hR⟩ := Set.mem_iUnion.mp hR exact hR.1) hA,hsum] have hi := Finset.sum_congr (s₁:=S) (s₂:=S) rfl (fun i _ => GG_cluster_join hgg c q i) rw [← Finset.mul_sum] at hi have hc := sum_clusterCount hS have hc' : (∑ i∈S,(clusterCount c i:ℝ))=(r:ℝ) := by exact_mod_cast hc simp_rw [sub_mul] at hi rw [Finset.sum_sub_distrib,← Finset.sum_mul,hc',Finset.sum_const,nsmul_eq_mul] at hi change (r:ℝ)*(∑ i∈S,(μ:Measure OverlapArray).real (J i))=_ at hi nlinarith only [hi] end SKCavity end end OAI