diff --git a/lean/OAI/Probability/SKGap/Entropy/WeightedMomentComparison.lean b/lean/OAI/Probability/SKGap/Entropy/WeightedMomentComparison.lean new file mode 100644 index 0000000000000000000000000000000000000000..14f0d75aedf1c769c136664a0cb206febc7b5ccb --- /dev/null +++ b/lean/OAI/Probability/SKGap/Entropy/WeightedMomentComparison.lean @@ -0,0 +1,78 @@ +import Mathlib +import OAI.Probability.SKGap.Model + +namespace OAI + +section +noncomputable section +namespace SKGap +open Real +open scoped BigOperators + +variable {ι : Type*} [Fintype ι] + +lemma sum_abs_le_sqrt_card_l2 (d : ι → ℝ) : + (∑ i, |d i|) ≤ √(Fintype.card ι:ℝ)*√(∑ i,d i^2) := by + simpa only [one_mul,one_pow,Finset.sum_const,Finset.card_univ,nsmul_eq_mul,mul_one, + sq_abs] using Real.sum_mul_le_sqrt_mul_sqrt Finset.univ (fun _ : ι => (1:ℝ)) (fun i => |d i|) + +theorem weighted_moment_comparison (a v y f : ι → ℝ) {H C D R : ℝ} + (hH : 0 ≤ H) (hC : 0 ≤ C) (hD : 0 ≤ D) (hR : 1 ≤ R) + (ha : ∀ i, |a i-v i| ≤ D) + (hsmall : ∀ i, |y i| ≤ R → |f i| ≤ H) + (hlarge : ∀ i, |f i| ≤ C*(1+y i^2)) : + |∑ i,(a i-v i)*f i| ≤ H*√(Fintype.card ι:ℝ)*√(∑ i,(a i-v i)^2)+ + 2*C*D*∑ i,if R < |y i| then y i^2 else 0 := by + have hpoint (i : ι) : |(a i-v i)*f i| ≤ H*|a i-v i|+ + 2*C*D*(if R < |y i| then y i^2 else 0) := by + rw [abs_mul] + by_cases hi : R < |y i| + · rw [ite_eq_left hi] + have hy : 1 ≤ y i^2 := by nlinarith [sq_abs (y i)] + have hf : |f i| ≤ 2*C*y i^2 := (hlarge i).trans (by nlinarith) + have hh := mul_le_mul (ha i) hf (abs_nonneg _) hD + nlinarith [mul_nonneg hH (abs_nonneg (a i-v i))] + · rw [ite_eq_right hi,mul_zero,add_zero] + simpa only [mul_comm H] using mul_le_mul_of_nonneg_left (hsmall i (le_of_not_gt hi)) (abs_nonneg (a i-v i)) + calc + _ ≤ ∑ i, |(a i-v i)*f i| := Finset.abs_sum_le_sum_abs _ _ + _ ≤ ∑ i,(H*|a i-v i|+2*C*D*(if R < |y i| then y i^2 else 0)) := + Finset.sum_le_sum (fun i _ => hpoint i) + _ = H*(∑ i,|a i-v i|)+2*C*D*∑ i,if R < |y i| then y i^2 else 0 := by + rw [Finset.sum_add_distrib,← Finset.mul_sum,← Finset.mul_sum] + _ ≤ _ := by + rw [mul_assoc H] + exact add_le_add (mul_le_mul_of_nonneg_left (sum_abs_le_sqrt_card_l2 _) hH) le_rfl + +theorem normalized_weighted_moment_comparison {n : ℕ} (hn : 0 < n) + (a v y f : Fin n → ℝ) {H C D R ε ν : ℝ} + (hH : 0 ≤ H) (hC : 0 ≤ C) (hD : 0 ≤ D) (hR : 1 ≤ R) + (hε : 0 ≤ ε) (ha : ∀ i, |a i-v i| ≤ D) + (hsmall : ∀ i, |y i| ≤ R → |f i| ≤ H) + (hlarge : ∀ i, |f i| ≤ C*(1+y i^2)) + (hclose : ∑ i,(a i-v i)^2 ≤ ε^2*(n:ℝ)) + (htail : (∑ i,if R < |y i| then y i^2 else 0) ≤ ν*(n:ℝ)) : + |(∑ i,(a i-v i)*f i)/(n:ℝ)| ≤ H*ε+2*C*D*ν := by + have hnR : 0 < (n:ℝ) := by exact_mod_cast hn + have hnorm : √(∑ i,(a i-v i)^2) ≤ ε*√(n:ℝ) := by + apply Real.sqrt_le_iff.mpr + constructor + · positivity + · nlinarith [Real.sq_sqrt hnR.le] + have h := weighted_moment_comparison a v y f hH hC hD hR ha hsmall hlarge + simp only [Fintype.card_fin] at h + have h' : |∑ i,(a i-v i)*f i| ≤ (H*ε+2*C*D*ν)*(n:ℝ) := by + calc + _ ≤ _ := h + _ ≤ H*√(n:ℝ)*(ε*√(n:ℝ))+2*C*D*(ν*(n:ℝ)) := by + exact add_le_add (mul_le_mul_of_nonneg_left hnorm (by positivity)) + (mul_le_mul_of_nonneg_left htail (by positivity)) + _ = H*ε*(√(n:ℝ))^2+2*C*D*ν*(n:ℝ) := by ring + _ = _ := by rw [Real.sq_sqrt hnR.le]; ring + rw [abs_div,abs_of_pos hnR] + exact (div_le_iff₀ hnR).mpr h' +end SKGap +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Entropy/WeightedRateAssembly.lean b/lean/OAI/Probability/SKGap/Entropy/WeightedRateAssembly.lean new file mode 100644 index 0000000000000000000000000000000000000000..2e561a0c0aeea89c54a783e813920c066b067d07 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Entropy/WeightedRateAssembly.lean @@ -0,0 +1,39 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.ScalarEmpirical + +namespace OAI + +section +noncomputable section +namespace SKGap +open MeasureTheory ProbabilityTheory Real Set +open scoped ENNReal + +lemma weighted_four_region_bound {α : Type*} [MeasurableSpace α] (μ : Measure α) + (f g : α → ℝ≥0∞) (hg : Measurable g) (B F D : Set α) + (hB : MeasurableSet B) (hF : MeasurableSet F) (hD : MeasurableSet D) + (hfg : ∀ x, f x ≤ g x) (k : ℝ≥0∞) + (hgood : ∀ x ∈ B ∩ Fᶜ ∩ Dᶜ, f x ≤ g x*k) : + (∫⁻ x, f x ∂μ) ≤ (∫⁻ x in Bᶜ,g x ∂μ)+(∫⁻ x in B ∩ F,g x ∂μ)+ + (∫⁻ x in D,g x ∂μ)+(∫⁻ x,g x ∂μ)*k := by + have bound (E : Set α) : (∫⁻ x in E,f x ∂μ) ≤ (∫⁻ x in E,g x ∂μ) := lintegral_mono hfg + have sub (E E' : Set α) (h : E ⊆ E') : (∫⁻ x in E,g x ∂μ) ≤ (∫⁻ x in E',g x ∂μ) := + lintegral_mono_set h + have hgood' : (∫⁻ x in B ∩ Fᶜ ∩ Dᶜ,f x ∂μ) ≤ (∫⁻ x,g x ∂μ)*k := by + calc + _ ≤ ∫⁻ x in B ∩ Fᶜ ∩ Dᶜ,g x*k ∂μ := + lintegral_mono_ae (ae_restrict_of_forall_mem ((hB.inter hF.compl).inter hD.compl) hgood) + _ = (∫⁻ x in B ∩ Fᶜ ∩ Dᶜ,g x ∂μ)*k := lintegral_mul_const _ hg + _ ≤ (∫⁻ x,g x ∂μ)*k := mul_le_mul' (lintegral_mono' Measure.restrict_le_self le_rfl) le_rfl + have h3 := (lintegral_split_le μ f (B ∩ Fᶜ) D).trans + (add_le_add ((bound _).trans (sub _ _ (fun _ h=>h.2))) hgood') + have h2 := (lintegral_split_le μ f B F).trans (add_le_add (bound _) h3) + have h1 := (lintegral_split_le μ f univ B).trans (add_le_add + (by simpa only [univ_inter] using h2) (by simpa only [univ_inter] using bound Bᶜ)) + simpa only [Measure.restrict_univ,add_comm,add_left_comm,add_assoc] using h1 + +end SKGap +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Entropy/WeightedScalarMoments.lean b/lean/OAI/Probability/SKGap/Entropy/WeightedScalarMoments.lean new file mode 100644 index 0000000000000000000000000000000000000000..cb13b39e10e9c0abcd58f005421df35610428eb5 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Entropy/WeightedScalarMoments.lean @@ -0,0 +1,69 @@ +import Mathlib +import OAI.Probability.SKGap.Model + +namespace OAI + +section +noncomputable section +namespace SKGap +open Real MeasureTheory +open scoped BigOperators BoundedContinuousFunction + +lemma scalarVariance_cosh (y : ℝ) : (1-tanh y^2)*cosh y^2=1 := by + rw [tanh_eq_sinh_div_cosh] + field_simp + exact cosh_sq_sub_sinh_sq y + +lemma square_le_sinh_square (y : ℝ) : y^2 ≤ sinh y^2 := by + by_cases hy : 0 ≤ y + · have h := (self_le_sinh_iff).2 hy + have hs := (sinh_nonneg_iff).2 hy + nlinarith + · have h := (sinh_le_self_iff).2 (le_of_not_ge hy) + have hs := (sinh_nonpos_iff).2 (le_of_not_ge hy) + nlinarith + +lemma scalarVariance_weight_bound (y : ℝ) : (1+y^2)*(1-tanh y^2) ≤ 1 := by + have hv : 0 ≤ 1-tanh y^2 := sub_nonneg.mpr (tanh_sq_lt_one y).le + have hb : 1+y^2 ≤ cosh y^2 := by linarith [square_le_sinh_square y,cosh_sq_sub_sinh_sq y] + have h := mul_le_mul_of_nonneg_right hb hv + rw [mul_comm (cosh y^2),scalarVariance_cosh] at h + exact h + +lemma weightedScalarMoment_bound (k l : Fin 3) (y : ℝ) : + |y^(k:ℕ)*tanh y^(l:ℕ)*(1-tanh y^2)| ≤ 1 := by + have hv : 0 ≤ 1-tanh y^2 := sub_nonneg.mpr (tanh_sq_lt_one y).le + have ht : |tanh y|^(l:ℕ) ≤ 1 := pow_le_one₀ (abs_nonneg _) (abs_tanh_lt_one y).le + have hy : |y|^(k:ℕ) ≤ 1+y^2 := by + fin_cases k + · simp only [pow_zero]; nlinarith [sq_nonneg y] + · simp only [pow_one] + nlinarith [sq_nonneg (|y|-1),sq_abs y] + · simp only [pow_two,← sq_abs y]; nlinarith [sq_abs y] + calc + _ = (|y|^(k:ℕ)*|tanh y|^(l:ℕ))*(1-tanh y^2) := by + rw [abs_mul,abs_mul,abs_pow,abs_pow,abs_of_nonneg hv] + _ ≤ (1+y^2)*(1-tanh y^2) := by + apply mul_le_mul_of_nonneg_right _ hv + exact (mul_le_mul_of_nonneg_left ht (by positivity)).trans (by simpa using hy) + _ ≤ 1 := scalarVariance_weight_bound y + +def weightedScalarMoment (k l : Fin 3) : ℝ →ᵇ ℝ := + BoundedContinuousFunction.ofNormedAddCommGroup + (fun y => y^(k:ℕ)*tanh y^(l:ℕ)*(1-tanh y^2)) (by + have ht : Continuous tanh := by + change Continuous (fun y => tanh y) + simp_rw [tanh_eq_sinh_div_cosh] + exact continuous_sinh.div continuous_cosh (fun y => (cosh_pos y).ne') + fun_prop) (1:ℝ) (fun y => by + simpa only [Real.norm_eq_abs] using weightedScalarMoment_bound k l y) + +lemma continuous_weightedScalarMoment_integral (k l : Fin 3) : + Continuous (fun P : ProbabilityMeasure ℝ => ∫ y, weightedScalarMoment k l y ∂P) := + ProbabilityMeasure.continuous_integral_boundedContinuousFunction _ + +end SKGap +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Entropy/WordUniformCost.lean b/lean/OAI/Probability/SKGap/Entropy/WordUniformCost.lean new file mode 100644 index 0000000000000000000000000000000000000000..00404d42f6822db1157ea7fdae2558701c374972 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Entropy/WordUniformCost.lean @@ -0,0 +1,106 @@ +import Mathlib +import OAI.Probability.SKGap.Matrix.WordExpectedRecursion + +namespace OAI + +section +noncomputable section +namespace SKGap +open Matrix Real Set +open scoped BigOperators SchwartzMap + +lemma finite_cost_bound (g : ℕ→ℕ→ℕ→ℝ) (L : ℕ) : + ∃ C : ℝ,0≤C ∧ ∀ u≤L,∀ v≤L,∀ q≤L,g u v q≤C := by + let C := ∑ u∈Finset.range (L+1),∑ v∈Finset.range (L+1),∑ q∈Finset.range (L+1),|g u v q| + refine ⟨C,by dsimp [C];positivity,?_⟩ + intro u hu v hv q hq + calc + g u v q ≤ |g u v q| := le_abs_self _ + _ ≤ ∑ r∈Finset.range (L+1),|g u v r| := Finset.single_le_sum (f := fun r => |g u v r|) (fun _ _=>abs_nonneg _) (Finset.mem_range.mpr (Nat.lt_succ_of_le hq)) + _ ≤ ∑ w∈Finset.range (L+1),∑ r∈Finset.range (L+1),|g u w r| := Finset.single_le_sum (f := fun w => ∑ r∈Finset.range (L+1),|g u w r|) (fun w _=>Finset.sum_nonneg (fun r _=>abs_nonneg (g u w r))) (Finset.mem_range.mpr (Nat.lt_succ_of_le hv)) + _ ≤ C := by + dsimp only [C] + exact Finset.single_le_sum (f := fun w => ∑ v∈Finset.range (L+1),∑ r∈Finset.range (L+1),|g w v r|) (fun w _=>Finset.sum_nonneg (fun v _=>Finset.sum_nonneg (fun r _=>abs_nonneg (g w v r)))) (Finset.mem_range.mpr (Nat.lt_succ_of_le hu)) + +lemma continuous_wordMarkedCost (B : NNReal) (j R A c : ℝ) (p q : ℕ) : + Continuous (fun z=>wordMarkedCost B j R A c z p q) := by + unfold wordMarkedCost markedRateConstant wordDifferentialBound + fun_prop + +lemma wordMarkedCost_uniform (B : NNReal) (j R A c : ℝ) (L : ℕ) : + ∃ C : ℝ,0≤C ∧ ∀ z∈Icc (0:ℝ) 1,∀ p≤L,∀ q≤L, + wordMarkedCost B j R A c z p q≤C := by + let H : ℝ→ℝ := fun z=>∑ p∈Finset.range (L+1),∑ q∈Finset.range (L+1),|wordMarkedCost B j R A c z p q| + have hH : Continuous H := by + unfold H + exact continuous_finsetSum _ (fun p _=>continuous_finsetSum _ (fun q _=>(continuous_wordMarkedCost B j R A c p q).abs)) + obtain ⟨C,hC⟩ := isCompact_Icc.exists_bound_of_continuousOn hH.continuousOn + refine ⟨max 0 C,le_max_left _ _,?_⟩ + intro z hz p hp q hq + have hb : wordMarkedCost B j R A c z p q≤H z := by + calc + _ ≤ |wordMarkedCost B j R A c z p q| := le_abs_self _ + _ ≤ ∑ r∈Finset.range (L+1),|wordMarkedCost B j R A c z p r| := + Finset.single_le_sum (f := fun r=>|wordMarkedCost B j R A c z p r|) (fun _ _=>abs_nonneg _) (Finset.mem_range.mpr (Nat.lt_succ_of_le hq)) + _ ≤ H z := by + dsimp only [H] + exact Finset.single_le_sum (f := fun w=>∑ r∈Finset.range (L+1),|wordMarkedCost B j R A c z w r|) (fun w _=>Finset.sum_nonneg (fun r _=>abs_nonneg (wordMarkedCost B j R A c z w r))) + (Finset.mem_range.mpr (Nat.lt_succ_of_le hp)) + have hbH : |H z|≤C := hC z hz + exact hb.trans ((le_abs_self _).trans (hbH.trans (le_max_right _ _))) + +variable {ι : Type*} +lemma wordPartners_length_sides (a : ι→ℝ) (F : List (WordLetter ι)) (c : WordCut ι) + (hc : c∈wordPartners a F) : c.left.length≤F.length+1 ∧ c.right.length≤F.length+1 := by + have hh := wordPartners_lengths a F c hc + cases hi : c.inversePartner + · simp only [hi,Bool.false_eq_true,ite_false] at hh + omega + · have hs := wordPartners_inverse_sides a F c hc hi + have hL : inverseCount c.left≤c.left.length := List.countP_le_length + have hR : inverseCount c.right≤c.right.length := List.countP_le_length + simp only [hi,ite_true] at hh + omega + +lemma wordRecursionAtCost_uniform {j B z C : ℝ} (hz : z∈Icc (0:ℝ) 1) + (hC : 0≤C) (L : ℕ) (hc : ∀ u≤L,∀ v≤L,∀ q≤L,wordLeadingCost j B u v q≤C) + (a : ι→ℝ) (P Q : List (WordLetter ι)) (hP : P.length+1+Q.length≤L) : + wordRecursionAtCost j B z a P Q≤(L:ℝ)*C := by + have hp : P.length≤L := by omega + have hq : Q.length≤L := by omega + have hz' (b : Bool) : |if b then z else 1|≤1 := by + split + · rw [abs_of_nonneg hz.1];exact hz.2 + · simp + have hl (c : WordCut ι) (h : c∈wordPartners a P) : + |if c.inversePartner then z else 1| *wordLeadingCost j B c.left.length c.right.length Q.length≤C := by + have hb := wordPartners_length_sides a P c h + have hcost := hc c.left.length (by omega) c.right.length (by omega) Q.length hq + have hh := mul_le_mul_of_nonneg_left hcost (abs_nonneg (if c.inversePartner then z else 1)) + exact hh.trans ((mul_le_mul_of_nonneg_right (hz' _) hC).trans_eq (one_mul C)) + have hr (c : WordCut ι) (h : c∈wordPartners a Q) : + |if c.inversePartner then z else 1| *wordLeadingCost j B P.length c.left.length c.right.length≤C := by + have hb := wordPartners_length_sides a Q c h + have hcost := hc P.length hp c.left.length (by omega) c.right.length (by omega) + exact (mul_le_mul_of_nonneg_left hcost (abs_nonneg (if c.inversePartner then z else 1))).trans + ((mul_le_mul_of_nonneg_right (hz' _) hC).trans_eq (one_mul C)) + have hb (X : List (WordCut ι)) (f : WordCut ι→ℝ) (hf : ∀ x∈X,f x≤C) : + (X.map f).sum≤(X.length:ℝ)*C := by + induction X with + | nil => simp + | cons x X ih => + simp only [List.map_cons,List.sum_cons,List.length_cons,Nat.cast_add,Nat.cast_one] + exact (add_le_add (hf x List.mem_cons_self) (ih (fun x hx=>hf x (List.mem_cons_of_mem _ hx)))).trans_eq (by ring) + have hsum := add_le_add (hb _ _ hl) (hb _ _ hr) + have hlen : ((wordPartners a P).length:ℝ)+(wordPartners a Q).length≤L := by + exact_mod_cast (show (wordPartners a P).length+(wordPartners a Q).length≤L by + have hh1 := wordPartners_card_bound a P + have hh2 := wordPartners_card_bound a Q + omega) + apply hsum.trans + nlinarith [mul_nonneg hC (sub_nonneg.mpr hlen)] +end SKGap +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Gaussian/AdaptiveInnovationSquareTails.lean b/lean/OAI/Probability/SKGap/Gaussian/AdaptiveInnovationSquareTails.lean new file mode 100644 index 0000000000000000000000000000000000000000..22c10313e6339cde4341a825aa218b915de7ecc1 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Gaussian/AdaptiveInnovationSquareTails.lean @@ -0,0 +1,96 @@ +import Mathlib +import OAI.Probability.SKGap.Gaussian.SquareTail2 + +namespace OAI + +section +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open scoped BigOperators +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open scoped BigOperators +open scoped BigOperators NNReal ENNReal +open MeasureTheory Metric Set +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators NNReal ENNReal Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Set +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators ENNReal NNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Matrix +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators ENNReal NNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal +open scoped BigOperators +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise NNReal ENNReal +open scoped BigOperators +open Filter Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Topology +namespace SKGapCutoff.Regression + +theorem adaptive_innovation_squareTails + {H : ℕ → Type*} [∀ n, MeasurableSpace (H n)] + (ρ : ∀ n, Measure (H n)) [∀ n, IsProbabilityMeasure (ρ n)] (r : ℕ) + (U : ∀ n, H n → Fin n → Fin r → ℝ) (q : ∀ n, H n → Fin n → ℝ) + (hUm : ∀ n, Measurable (U n)) (hqm : ∀ n, Measurable (q n)) + (hU : ∀ n h a, ∑ i, U n h i a^2 ≤ 1) (hq : ∀ n h, ∑ i, q n h i^2 ≤ 1) : + ExponentialSquareTails (fun n => (ρ n).prod (standardArrayLaw (Fin n ⊕ Unit))) + (fun n z i => Real.sqrt n * + queryInnovation (residualProjection (U n z.1)) (q n z.1) z.2 i) := by + have hs (n : ℕ) : HasLaw Prod.snd (standardArrayLaw (Fin n ⊕ Unit)) + ((ρ n).prod (standardArrayLaw (Fin n ⊕ Unit))) := + ⟨measurable_snd.aemeasurable, measurePreserving_snd.map_eq⟩ + have ht : ExponentialSquareTails (fun n => (ρ n).prod (standardArrayLaw (Fin n ⊕ Unit))) + (fun _ z i => z.2 (Sum.inl i)) := by + refine iid_exponential_squareTails + (fun n => (ρ n).prod (standardArrayLaw (Fin n ⊕ Unit))) + (fun _ z i => z.2 (Sum.inl i)) + (fun _ _ => (measurable_pi_apply _).comp measurable_snd) ?_ (gaussianReal 0 1) ?_ ?_ + · intro n + apply iIndepFun_comp_hasLaw (hs n) (fun i g => g (Sum.inl i)) + (fun _ => (measurable_pi_apply _).aemeasurable) + exact coordinates_independent.precomp Sum.inl_injective + · intro n i + exact (coordinate_hasLaw (Sum.inl i)).fun_comp (hs n) + · exact gaussian_integrable_exp_quarter_sq + exact ht.l2_stability (adaptive_innovation_error_exponential ρ r U q hUm hqm hU hq) + +end SKGapCutoff.Regression + +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology + +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Gaussian/ConditionalGramTail.lean b/lean/OAI/Probability/SKGap/Gaussian/ConditionalGramTail.lean new file mode 100644 index 0000000000000000000000000000000000000000..7afd7e0da0ed4adfb2977ac22ef70d07ed4fae66 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Gaussian/ConditionalGramTail.lean @@ -0,0 +1,94 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.GramColumnBounds + +namespace OAI + +section +noncomputable section +namespace SKGap +open Matrix MeasureTheory ProbabilityTheory Real Set +open scoped BigOperators Matrix.Norms.Frobenius +variable {ι : Type*} [Fintype ι] [DecidableEq ι] + +omit [DecidableEq ι] in +lemma matrixBilinear_eq_pair (M : Matrix ι ι ℝ) (x y : EuclideanSpace ℝ ι) : + matrixBilinear M x y=matrixPair M x.ofLp y.ofLp := by + simp only [matrixBilinear,matrixPair,dotProduct,Matrix.mulVec,Finset.mul_sum] + congr 1; ext i; congr 1; ext k; ring + +lemma exactG_transpose (j : ℝ) (a : ι → ℝ) {W : Matrix ι ι ℝ} (hW : Wᵀ=W) : + (exactG j a W)ᵀ=exactG j a W := by + simp only [exactG,Matrix.transpose_mul,Matrix.transpose_nonsing_inv, + Matrix.transpose_sub,Matrix.transpose_one,Matrix.transpose_smul,hW, + pathDiagonal,Matrix.diagonal_transpose,Matrix.mul_assoc] + +def augmentedGramTolerance (B ε : ℝ) : ℝ := + 4*(ε+(sqrt B)⁻¹*(1+B)*ε+B⁻¹*(1+2*B+B^2)*ε) + +def actualAugmentedGram {n : ℕ} (j : ℝ) (a : Fin n → ℝ) + (p : Fin 3 → EuclideanSpace ℝ (Fin n)) (u : EuclideanSpace ℝ (Fin n)) + (g : MatrixCoordinates (Fin n) → ℝ) : Matrix ((Fin 3) ⊕ Unit) ((Fin 3) ⊕ Unit) ℝ := + let B := j/(n:ℝ)*∑ i,a i + let W := goeMatrix (j/(n:ℝ)) g + let V := extendColumns (fun r => (p r).ofLp) (residualGramVector B W u.ofLp) + Vᵀ*exactG j a W*V + +def diagonalAugmentedGram {n : ℕ} (a : Fin n → ℝ) + (p : Fin 3 → EuclideanSpace ℝ (Fin n)) : + Matrix ((Fin 3) ⊕ Unit) ((Fin 3) ⊕ Unit) ℝ := + fromBlocks (fun r s => matrixPair (diagonal a) (p r).ofLp (p s).ofLp) 0 0 1 + +theorem conditional_augmented_gram_tail {j A U ε : ℝ} + (hj : 0 < j) (hA : 0 < A) (hs : sqrt j*A < 1) (hU : 0 ≤ U) (hε : 0 < ε) : + ∃ (c : ℝ) (N : ℕ), 0 < c ∧ 0 < N ∧ + ∀ n, N ≤ n → ∀ a : Fin n → ℝ, (∀ i,0 ≤ a i) → (∀ i,a i ≤ A) → + 0 < j/(n:ℝ)*∑ i,a i → + ∀ (p : Fin 3 → EuclideanSpace ℝ (Fin n)) (u : EuclideanSpace ℝ (Fin n)), + (∀ r,‖p r‖ ≤ U) → ‖u‖ ≤ U → u.ofLp⬝ᵥu.ofLp=1 → + (Measure.pi (fun _ : MatrixCoordinates (Fin n) => gaussianReal 0 1)).real + {g | ¬bilinearPathGood j A a g ∨ + augmentedGramTolerance (j/(n:ℝ)*∑ i,a i) ε < + ‖actualAugmentedGram j a p u g-diagonalAugmentedGram a p‖} ≤ + 99*Real.exp (-c*(n:ℝ)) := by + obtain ⟨c,N,hc,hN,ht⟩ := bilinear_deterministic_equivalents hj hA hs hU hε 4 + refine ⟨c,N,hc,hN,?_⟩ + intro n hn a ha haA hB p u hp hu hunit + let v : Fin 4 → EuclideanSpace ℝ (Fin n) := Fin.cons u p + have hv : ∀ r,‖v r‖ ≤ U := by + intro r + refine Fin.cases hu (fun r => hp r) r + have hh := ht n hn a ha haA v hv + apply (measureReal_mono (s₂ := {g | ¬bilinearPathGood j A a g ∨ ∃ r s k, + ε < |matrixBilinear (bilinearError k j a (goeMatrix (j/(n:ℝ)) g)) (v r) (v s)|}) + ?_ (measure_ne_top _ _)).trans (by norm_num only [Nat.cast_ofNat,show (3:ℝ)+6*4^2=99 by norm_num] at hh; exact hh) + intro g hg + by_contra hbad + change ¬(¬bilinearPathGood j A a g ∨ ∃ r s k, + ε < |matrixBilinear (bilinearError k j a (goeMatrix (j/(n:ℝ)) g)) (v r) (v s)|) at hbad + push Not at hbad + rcases hbad with ⟨hpath,hpair⟩ + have he (r s : Fin 4) (k : Fin 3) : + |matrixPair (bilinearError k j a (goeMatrix (j/(n:ℝ)) g)) (v r).ofLp (v s).ofLp| ≤ ε := by + rw [← matrixBilinear_eq_pair] + exact hpair r s k + have h00 (r s : Fin 3) := he r.succ s.succ 0 + have h0u (r : Fin 3) := he r.succ 0 0 + have h1u (r : Fin 3) := he r.succ 0 1 + have h0 := he 0 0 0 + have h1 := he 0 0 1 + have h2 := he 0 0 2 + simp only [v,Fin.cons_succ,Fin.cons_zero,bilinearError,ite_true,ite_false, + Fin.reduceEq,Fintype.card_fin] at h00 h0u h1u h0 h1 h2 + have hb := augmented_gram_error (exactG_transpose j a (goeMatrix_transpose _ g)) + (goeMatrix_transpose _ g) (diagonal a) hB hε.le (fun r => (p r).ofLp) u.ofLp hunit + h00 h0u h1u h0 h1 h2 + have hb' : ‖actualAugmentedGram j a p u g-diagonalAugmentedGram a p‖ ≤ + augmentedGramTolerance (j/(n:ℝ)*∑ i,a i) ε := by + simpa only [actualAugmentedGram,diagonalAugmentedGram,augmentedGramTolerance, + Fintype.card_fin,Nat.cast_ofNat,show (3:ℝ)+1=4 by norm_num] using hb + exact hg.elim (fun hn => hn hpath) (fun he => not_lt_of_ge hb' he) +end SKGap +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Gaussian/ConditionalUniformTail.lean b/lean/OAI/Probability/SKGap/Gaussian/ConditionalUniformTail.lean new file mode 100644 index 0000000000000000000000000000000000000000..ef3eec70c084f0003b51181e7cc738810f93c16a --- /dev/null +++ b/lean/OAI/Probability/SKGap/Gaussian/ConditionalUniformTail.lean @@ -0,0 +1,122 @@ +import Mathlib +import OAI.Probability.SKGap.Gaussian.GOEScalarTail + +namespace OAI + +section +noncomputable section +namespace SKGap +open Matrix MeasureTheory ProbabilityTheory Real Set +open scoped BigOperators MatrixOrder Matrix.Norms.Frobenius + +theorem compact_conditional_uniform_tail {α : Type*} [TopologicalSpace α] [CompactSpace α] + {j A : ℝ} (hj : 0 < j) (hj1 : j < 1) (hA : 0 < A) + (hsub : sqrt j*A < 1) + (b e s q κ : α → ℝ) (hb : Continuous b) (he : Continuous e) + (hs : Continuous s) (hq : Continuous q) (hk : Continuous κ) + (hb0 : ∀ x,0 < b x) (hb1 : ∀ x,b x ≤ 1) (he0 : ∀ x,0 ≤ e x) + (hs0 : ∀ x,0 < s x) (hq0 : ∀ x,0 < q x) + (hkq : ∀ x,κ x^2=1-j*q x/s x) : + ∃ δ ρ : ℝ, 0 < δ ∧ δ < 1 ∧ 0 < ρ ∧ + ∀ U : ℝ, 0 ≤ U → ∀ ε τ : ℝ, 0 < ε → 0 < τ → ∃ c : ℝ, ∃ N : ℕ, 0 < c ∧ 0 < N ∧ + ∀ n, N ≤ n → ∀ a : Fin n → ℝ, (∀ i,0 ≤ a i) → (∀ i,a i ≤ A) → + 0 < j/(n:ℝ)*∑ i,a i → + augmentedGramTolerance (j/(n:ℝ)*∑ i,a i) ε < ρ/2 → + ∀ p : Fin 3 → EuclideanSpace ℝ (Fin n), ∀ u : EuclideanSpace ℝ (Fin n), + (∀ r,‖p r‖ ≤ U) → ‖u‖ ≤ U → u.ofLp⬝ᵥu.ofLp=1 → + ∀ x (C E : Matrix ((Fin 3) ⊕ Unit) ((Fin 3) ⊕ Unit) ℝ), + C.IsHermitian → E.IsHermitian → τ*‖E‖ < ρ/2 → + ‖diagonalAugmentedGram a p-augmentedGram (ν := Unit) (limitingGram (b x) (e x) (s x))‖ < ρ/2 → + ‖C-conditionalCoefficient j ((2*j*q x+2*(j*b x)*(κ x-1))/q x) + j ((κ x-1)*√(j*b x)/√(q x))‖ < ρ/2 → + (Measure.pi (fun _ : MatrixCoordinates (Fin n) => gaussianReal 0 1)).real + {g | ¬(conditionalBase j a g- + pathDiagonal a 1*conditionalUpdateColumns j a p u g* + (C+matrixBilinear (goeMatrix (j/(n:ℝ)) g) u u • E)* + (conditionalUpdateColumns j a p u g)ᵀ*pathDiagonal a 1- + (δ*((1-sqrt j*A)^2/4)) • (1 : Matrix (Fin n) (Fin n) ℝ)).PosDef} ≤ + 101*exp (-c*(n:ℝ)) := by + obtain ⟨δ,ρ,hδ,hδ1,hρ,hcrit⟩ := compact_conditional_rank_criterion hj hj1 b e s q κ + hb he hs hq hk hb0 hb1 he0 hs0 hq0 hkq + refine ⟨δ,ρ,hδ,hδ1,hρ,?_⟩ + intro U hU ε τ hε hτ + obtain ⟨c₀,N,hc₀,hN,hgram⟩ := conditional_augmented_gram_tail hj hA hsub hU hε + let c₁ := τ^2/(π^2*(2*(U+1)^2)^2*j) + have hc₁ : 0 < c₁ := by dsimp [c₁]; positivity + refine ⟨min c₀ c₁,N,lt_min hc₀ hc₁,hN,?_⟩ + intro n hn a ha haA hB heps p u hp hu hunit x C E hC hE hEbound hdiag hcoef + let μ := Measure.pi (fun _ : MatrixCoordinates (Fin n) => gaussianReal 0 1) + let badG := {g | ¬bilinearPathGood j A a g ∨ + augmentedGramTolerance (j/(n:ℝ)*∑ i,a i) ε < + ‖actualAugmentedGram j a p u g-diagonalAugmentedGram a p‖} + let badS := {g | τ ≤ |matrixBilinear (goeMatrix (j/(n:ℝ)) g) u u|} + have hnpos := hN.trans_le hn + have hgprob : μ.real badG ≤ 99*exp (-c₀*(n:ℝ)) := hgram n hn a ha haA hB p u hp hu hunit + have hsprob : μ.real badS ≤ 2*exp (-c₁*(n:ℝ)) := by + have hh := goe_scalar_tail hnpos hj hU hτ.le u hu + convert hh using 1 + congr 2 + dsimp [c₁] + ring + have hsubsets : {g | ¬(conditionalBase j a g- + pathDiagonal a 1*conditionalUpdateColumns j a p u g* + (C+matrixBilinear (goeMatrix (j/(n:ℝ)) g) u u • E)* + (conditionalUpdateColumns j a p u g)ᵀ*pathDiagonal a 1- + (δ*((1-sqrt j*A)^2/4)) • (1 : Matrix (Fin n) (Fin n) ℝ)).PosDef} ⊆ badG ∪ badS := by + intro g hg + by_contra hbad + have hgG : g ∉ badG := fun hh => hbad (Or.inl hh) + have hgS : g ∉ badS := fun hh => hbad (Or.inr hh) + simp only [badG,mem_ofPred_eq,not_or,not_lt] at hgG + have hgS' : |matrixBilinear (goeMatrix (j/(n:ℝ)) g) u u| < τ := lt_of_not_ge hgS + let D := pathDiagonal a 1 + let S := conditionalBase j a g + let V := conditionalUpdateColumns j a p u g + let Cg := C+matrixBilinear (goeMatrix (j/(n:ℝ)) g) u u • E + let lo := (1-sqrt j*A)^2/4 + have hmargin : (S-lo • (1 : Matrix (Fin n) (Fin n) ℝ)).PosDef := + bilinearPathGood_margin a g (not_not.mp hgG.1) + have hlo : 0 ≤ lo := by dsimp [lo]; positivity + have hSpos : S.PosDef := by + have hh := hmargin.add_posSemidef ((Matrix.PosSemidef.one : (1 : Matrix (Fin n) (Fin n) ℝ).PosSemidef).smul hlo) + convert hh using 1; abel + have hD : D.IsHermitian := isHermitian_diagonal_iff.mpr + (fun i => isSelfAdjoint_iff.mpr (star_trivial _)) + have hCg : Cg.IsHermitian := hC.add (hE.smul (R := ℝ) + (isSelfAdjoint_iff.mpr (star_trivial _))) + have hG : ‖Vᵀ*D*S⁻¹*D*V-augmentedGram (ν := Unit) (limitingGram (b x) (e x) (s x))‖ < ρ := by + have hh := norm_sub_le_norm_sub_add_norm_sub (actualAugmentedGram j a p u g) (diagonalAugmentedGram a p) + (augmentedGram (ν := Unit) (limitingGram (b x) (e x) (s x))) + have heq : Vᵀ*D*S⁻¹*D*V=actualAugmentedGram j a p u g := by + simp only [V,D,S,conditionalUpdateColumns,conditionalBase,actualAugmentedGram, + exactG,Fintype.card_fin,Matrix.mul_assoc] + rw [heq] + exact hh.trans_lt (by linarith [hgG.2]) + have hCgclose : ‖Cg-conditionalCoefficient j ((2*j*q x+2*(j*b x)*(κ x-1))/q x) + j ((κ x-1)*√(j*b x)/√(q x))‖ < ρ := by + have hn : ‖matrixBilinear (goeMatrix (j/(n:ℝ)) g) u u • E‖ ≤ τ*‖E‖ := by + rw [norm_smul,Real.norm_eq_abs] + exact mul_le_mul_of_nonneg_right hgS'.le (norm_nonneg _) + have hh := norm_add_le (C-conditionalCoefficient j ((2*j*q x+2*(j*b x)*(κ x-1))/q x) + j ((κ x-1)*√(j*b x)/√(q x))) (matrixBilinear (goeMatrix (j/(n:ℝ)) g) u u • E) + have heq : Cg-conditionalCoefficient j ((2*j*q x+2*(j*b x)*(κ x-1))/q x) + j ((κ x-1)*√(j*b x)/√(q x))= + (C-conditionalCoefficient j ((2*j*q x+2*(j*b x)*(κ x-1))/q x) + j ((κ x-1)*√(j*b x)/√(q x)))+matrixBilinear (goeMatrix (j/(n:ℝ)) g) u u • E := by + dsimp [Cg]; abel + rw [heq] + exact hh.trans_lt (by linarith) + exact hg (hcrit x (Fin n) S D V Cg lo hSpos hD hCg hmargin.posSemidef hG hCgclose) + apply (measureReal_mono hsubsets (measure_ne_top _ _)).trans + apply (measureReal_union_le badG badS).trans + apply (add_le_add hgprob hsprob).trans + have he₀ : exp (-c₀*(n:ℝ)) ≤ exp (-min c₀ c₁*(n:ℝ)) := by + apply exp_le_exp.mpr; simpa only [neg_mul] using neg_le_neg (mul_le_mul_of_nonneg_right (min_le_left c₀ c₁) (Nat.cast_nonneg n : (0:ℝ) ≤ n)) + have he₁ : exp (-c₁*(n:ℝ)) ≤ exp (-min c₀ c₁*(n:ℝ)) := by + apply exp_le_exp.mpr; simpa only [neg_mul] using neg_le_neg (mul_le_mul_of_nonneg_right (min_le_right c₀ c₁) (Nat.cast_nonneg n : (0:ℝ) ≤ n)) + nlinarith +end SKGap +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Gaussian/DiagonalNormTail.lean b/lean/OAI/Probability/SKGap/Gaussian/DiagonalNormTail.lean new file mode 100644 index 0000000000000000000000000000000000000000..c6f29d69d7e8d87f3f376c31d07f6e55b234edb2 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Gaussian/DiagonalNormTail.lean @@ -0,0 +1,47 @@ +import Mathlib +import OAI.Probability.SKGap.Matrix.GOEDiagonalSquare +import OAI.Probability.SKGap.Matrix.GOESubmatrix + +namespace OAI + +section +noncomputable section +namespace SKGap +open Matrix Real Set MeasureTheory ProbabilityTheory +open RealComplex +open scoped BigOperators Matrix.Norms.Frobenius + +theorem zeroDiagGOE_norm_tail {j : ℝ} (hj : 0gaussianReal 0 1)) + {g | 2*sqrt j+1+1goeMatrix (j/n) g i i))≤1 := + opNorm_diagonal_le zero_le_one (fun i=>le_of_not_gt (fun hi=>hh'.2 ⟨i,hi⟩)) + have hsub := opNorm_sub (goeMatrix (j/n) g) (Matrix.diagonal (fun i=>goeMatrix (j/n) g i i)) + exact (not_lt_of_ge (hsub.trans (add_le_add (le_of_not_gt hh'.1) hd))) hg + have he : μ E≤ENNReal.ofReal (2*exp (-(n:ℝ)/(π^2*j))) := by + rw [←ofReal_measureReal] + apply ENNReal.ofReal_le_ofReal + have ht := goe_norm_tail (ι:=Fin n) hj (show (0:ℝ)≤1 by norm_num) + simpa only [one_pow,neg_mul,one_mul,Fintype.card_fin,matrixOperator,μ,E,opNorm] using ht + have hv : μ V≤ENNReal.ofReal (2*(n:ℝ)*exp (-1/(8*(j/n)))) := by + rw [←ofReal_measureReal] + apply ENNReal.ofReal_le_ofReal + simpa only [one_pow,Fintype.card_fin] using goe_diagonal_tail (ι:=Fin n) hr (show (0:ℝ)≤1 by norm_num) + exact ((measure_mono hs).trans (measure_union_le E V)).trans (add_le_add he hv) +end SKGap +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Gaussian/FourierMoment.lean b/lean/OAI/Probability/SKGap/Gaussian/FourierMoment.lean new file mode 100644 index 0000000000000000000000000000000000000000..745d373a58f03428458b6f51d5cfe0c894ad4f7b --- /dev/null +++ b/lean/OAI/Probability/SKGap/Gaussian/FourierMoment.lean @@ -0,0 +1,74 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.EntryLM + +namespace OAI + +noncomputable section + +open MeasureTheory ProbabilityTheory InformationTheory Real Set +open scoped NNReal ENNReal +open Filter +open scoped Topology +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius ENNReal NNReal +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius NNReal +open MeasureTheory ProbabilityTheory Real Set Filter +open MeasureTheory.Measure +open scoped ENNReal NNReal MeasureTheory Topology +open MeasureTheory +open MeasureTheory Set NormedSpace +open scoped Topology +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius +namespace SKGap.ComplexMatrix +open MeasureTheory NormedSpace +open scoped FourierTransform SchwartzMap +variable {ι : Type*} [Fintype ι] [DecidableEq ι] + +noncomputable def fourierMoment (f : 𝓢(ℝ,ℂ)) (k : ℕ) : ℝ := + ∫ t : ℝ, ‖(𝓕 f) t‖*|t|^k + +lemma fourierMoment_nonneg (f : 𝓢(ℝ,ℂ)) (k : ℕ) : 0 ≤ fourierMoment f k := by + apply integral_nonneg + intro t + positivity + +lemma fourierMoment_integrable (f : 𝓢(ℝ,ℂ)) (k : ℕ) : + Integrable (fun t : ℝ => ‖(𝓕 f) t‖*|t|^k) := by + simpa only [Real.norm_eq_abs,mul_comm] using (𝓕 f).integrable_pow_mul volume k + +lemma opNorm_rsmul (r : ℝ) (M : Matrix ι ι ℂ) : opNorm (r • M) = |r| * opNorm M := by + change opNorm ((r:ℂ) • M) = _ + rw [opNorm_csmul,Complex.norm_real,Real.norm_eq_abs] + +lemma schwartzMatrix_lipschitz (f : 𝓢(ℝ,ℂ)) (M N : Matrix ι ι ℂ) + (hM : Mᴴ = M) (hN : Nᴴ = N) : + ‖schwartzMatrix f M-schwartzMatrix f N‖ ≤ + (2*Real.pi*fourierMoment f 1)*‖M-N‖ := by + have hf₁ : Integrable (fun t : ℝ => ‖(𝓕 f) t‖*|t|) := by + simpa only [pow_one] using fourierMoment_integrable f 1 + have hh := kernelMatrix_lipschitz (𝓕 f).integrable hf₁ + ((2*Real.pi:ℝ) • M) ((2*Real.pi:ℝ) • N) (by simp [hM]) (by simp [hN]) + rw [← smul_sub,norm_smul,Real.norm_eq_abs,abs_of_pos (by positivity : 0 < (2*Real.pi:ℝ))] at hh + exact hh.trans_eq (by simp only [fourierMoment,pow_one]; ring) + +lemma schwartzMatrix_four_point (f : 𝓢(ℝ,ℂ)) (a b c d : Matrix ι ι ℂ) + (ha : aᴴ = a) (hb : bᴴ = b) (hc : cᴴ = c) (hd : dᴴ = d) : + ‖(schwartzMatrix f a-schwartzMatrix f b)-(schwartzMatrix f c-schwartzMatrix f d)‖ ≤ + (2*Real.pi*fourierMoment f 1)*‖(a-b)-(c-d)‖ + + ((2*Real.pi)^2*fourierMoment f 2)*(opNorm (a-c)+opNorm (b-d))*‖c-d‖ := by + have hf₁ : Integrable (fun t : ℝ => ‖(𝓕 f) t‖*|t|) := by + simpa only [pow_one] using fourierMoment_integrable f 1 + have hh := kernelMatrix_four_point (𝓕 f).integrable hf₁ (fourierMoment_integrable f 2) + ((2*Real.pi:ℝ) • a) ((2*Real.pi:ℝ) • b) ((2*Real.pi:ℝ) • c) ((2*Real.pi:ℝ) • d) + (by simp [ha]) (by simp [hb]) (by simp [hc]) (by simp [hd]) + simp only [← smul_sub,norm_smul,opNorm_rsmul,Real.norm_eq_abs, + abs_of_pos (by positivity : 0 < (2*Real.pi:ℝ))] at hh + exact hh.trans_eq (by simp only [fourierMoment,pow_one]; ring) + +end SKGap.ComplexMatrix + +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Gaussian/GOEGaussian.lean b/lean/OAI/Probability/SKGap/Gaussian/GOEGaussian.lean new file mode 100644 index 0000000000000000000000000000000000000000..16a22f4d3d9aba738a88aed4f6e39f4c3da19bc7 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Gaussian/GOEGaussian.lean @@ -0,0 +1,64 @@ +import Mathlib +import OAI.Probability.SKGap.Matrix.MatrixCoordinates +import OAI.Probability.SKGap.Gaussian.GaussianRegression + +namespace OAI + +section +noncomputable section +namespace SKGap +open MeasureTheory ProbabilityTheory Matrix Real +open scoped BigOperators ENNReal + +variable {ι : Type*} [Fintype ι] [DecidableEq ι] + +def goeEntryCoeff (r : ℝ) : Matrix (ι × ι) (MatrixCoordinates ι) ℝ := + fun p a => sqrt (2*r)/2 * ((if a=Sum.inl p then 1 else 0)+ + (if a=Sum.inl (p.2,p.1) then 1 else 0)) + +lemma goeEntryCoeff_sample (r : ℝ) (g : MatrixCoordinates ι → ℝ) (i k : ι) : + (goeEntryCoeff r*ᵥg) (i,k) = goeMatrix r g i k := by + simp only [mulVec,dotProduct,goeEntryCoeff,mul_assoc,add_mul] + rw [← Finset.mul_sum,Finset.sum_add_distrib] + simp [goeMatrix] + +lemma goe_matrix_gaussian (r : ℝ) : + HasGaussianLaw (fun (g : MatrixCoordinates ι → ℝ) (p : ι × ι) => goeMatrix r g p.1 p.2) (gaussianCoordinates (MatrixCoordinates ι)) := by + have hh := matrix_sample_gaussian (goeEntryCoeff (ι := ι) r) + simpa only [show (fun g => goeEntryCoeff (ι := ι) r*ᵥg) = + (fun g p => goeMatrix r g p.1 p.2) from funext (fun g => funext (fun p => goeEntryCoeff_sample r g p.1 p.2))] using hh + +lemma goe_mean_zero (r : ℝ) (i k : ι) : + (∫ g, goeMatrix r g i k ∂gaussianCoordinates (MatrixCoordinates ι))=0 := by + simpa only [← goeEntryCoeff_sample,mulVec,dotProduct] using linear_gaussian_mean (goeEntryCoeff (ι := ι) r (i,k)) + +lemma goe_entry_cov {r : ℝ} (hr : 0 ≤ r) (i k l m : ι) : + cov[fun g => goeMatrix r g i k,fun g => goeMatrix r g l m; + gaussianCoordinates (MatrixCoordinates ι)] = + r*((if i=l then 1 else 0)*(if k=m then 1 else 0)+ + (if i=m then 1 else 0)*(if k=l then 1 else 0)) := by + let μ := gaussianCoordinates (MatrixCoordinates ι) + have hm (a : MatrixCoordinates ι) := (coordinate_hasLaw a).hasGaussianLaw.memLp_two + change cov[fun g : MatrixCoordinates ι → ℝ => sqrt (2*r)/2*(g (.inl (i,k))+g (.inl (k,i))), + fun g => sqrt (2*r)/2*(g (.inl (l,m))+g (.inl (m,l))); μ]=_ + rw [covariance_const_mul_left,covariance_const_mul_right] + change sqrt (2*r)/2*(sqrt (2*r)/2*cov[(fun g => g (.inl (i,k))) + (fun g => g (.inl (k,i))), + (fun g => g (.inl (l,m))) + (fun g => g (.inl (m,l)));gaussianCoordinates (MatrixCoordinates ι)]) = _ + rw [covariance_add_left (hm _) (hm _) ((hm _).add (hm _)), + covariance_add_right (hm _) (hm _) (hm _), + covariance_add_right (hm _) (hm _) (hm _)] + simp only [coordinate_covariance,Sum.inl.injEq,Prod.mk.injEq] + have hs : (sqrt (2*r)/2)^2=r/2 := by rw [div_pow,sq_sqrt (by positivity)]; ring + have hs' : sqrt (2*r)/2*(sqrt (2*r)/2)=r/2 := by nlinarith only [hs] + rw [← mul_assoc,hs'] + have hind (p q : Prop) [Decidable p] [Decidable q] : + (if p ∧ q then (1:ℝ) else 0)=(if p then 1 else 0)*(if q then 1 else 0) := by + split_ifs <;> simp_all + simp_rw [hind] + ring + +end SKGap +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Gaussian/GOERowTail.lean b/lean/OAI/Probability/SKGap/Gaussian/GOERowTail.lean new file mode 100644 index 0000000000000000000000000000000000000000..65ad74cf6e9dd51e87f2ec12b18d8b8a2f2fe66c --- /dev/null +++ b/lean/OAI/Probability/SKGap/Gaussian/GOERowTail.lean @@ -0,0 +1,98 @@ +import Mathlib +import OAI.Probability.SKGap.Entropy.SparseSubsetEntropy +import OAI.Probability.SKGap.Matrix.TanhMatrixBounds +import OAI.Probability.SKGap.Matrix.GOERowLaw + +namespace OAI + +section +noncomputable section +namespace SKGap +open MeasureTheory ProbabilityTheory Matrix Real Set +open scoped BigOperators +variable {n : ℕ} + +lemma coupling_goe_offdiag (r : ℝ) (g : MatrixCoordinates (Fin n)→ℝ) (i k : Fin n) + (hik : i≠k) : coupling (goeDisorder r g) i k=goeMatrix r g i k := by + have h := congrFun (congrFun (coupling_goeDisorder r g) i) k + simpa only [of_apply,Matrix.sub_apply,diagonal_apply_ne _ hik,sub_zero] using h + +lemma coupling_goe_row_square_sum (r : ℝ) (g : MatrixCoordinates (Fin n)→ℝ) + (i : Fin n) (S : Finset (Fin n)) : + (∑ k∈S,coupling (goeDisorder r g) i k^2)=∑ k : S.erase i,goeMatrix r g i k^2 := by + rw [Finset.sum_coe_sort (S.erase i) (fun k : Fin n=>goeMatrix r g i k^2)] + calc + _ = ∑ k∈S.erase i,coupling (goeDisorder r g) i k^2 := + by + by_cases hi : i∈S + · rw [Finset.sum_erase_eq_sub hi] + simp [coupling] + · rw [Finset.erase_eq_self.mpr hi] + _ = _ := Finset.sum_congr rfl (fun k hk=>by rw [coupling_goe_offdiag r g i k (Ne.symm (Finset.ne_of_mem_erase hk))]) + +lemma coupling_goe_row_tail {r : ℝ} (hr : 0 < r) (i : Fin n) (S : Finset (Fin n)) (t : ℝ) : + (gaussianCoordinates (MatrixCoordinates (Fin n))).real + {g | t < ∑ k∈S,coupling (goeDisorder r g) i k^2} ≤ + exp (-t/(4*r)+(S.card:ℝ)*log 2) := by + let e : S.erase i ↪ Fin n := ⟨Subtype.val,Subtype.val_injective⟩ + have havoid (k : S.erase i) : e k≠i := Finset.ne_of_mem_erase k.2 + have hm : MeasurableSet {v : S.erase i→ℝ | t < ∑ k,v k^2} := by measurability + simp_rw [coupling_goe_row_square_sum] + have heq := (goe_row_hasLaw hr.le i e havoid).measureReal_eq hm + change (gaussianCoordinates (MatrixCoordinates (Fin n))).real + {g | t < ∑ k : S.erase i,goeMatrix r g i k^2} = (Measure.pi (fun _ : S.erase i=>gaussianReal 0 (Real.toNNReal r))).real {v | t < ∑ k,v k^2} at heq + rw [heq] + apply (scaled_gaussian_square_tail hr t).trans + apply exp_le_exp.mpr + have hcard : (Fintype.card (S.erase i):ℝ) ≤ S.card := by + rw [Fintype.card_coe] + exact_mod_cast Finset.card_erase_le + exact add_le_add (le_refl _) (mul_le_mul_of_nonneg_right hcard (log_nonneg (show (1:ℝ) ≤ 2 by norm_num))) + +lemma coupling_goe_sparse_rows_tail [NeZero n] {j α l t : ℝ} + (hj : 0 < j) (_hα : 0 ≤ α) (hl : 0 ≤ l) : + (gaussianCoordinates (MatrixCoordinates (Fin n))).real + {g | ∃ i : Fin n,∃ S : Finset (Fin n),(S.card:ℝ) ≤ α*(n:ℝ) ∧ + t < ∑ k∈S,coupling (goeDisorder (j/(n:ℝ)) g) i k^2} ≤ + (n:ℝ)*exp (-(n:ℝ)*(t/(4*j)-(l*α+log (1+exp (-l))+α*log 2))) := by + have hn : (0:ℝ) < n := by exact_mod_cast NeZero.pos n + have hsingle (i : Fin n) : + (gaussianCoordinates (MatrixCoordinates (Fin n))).real + {g | ∃ S : Finset (Fin n),(S.card:ℝ) ≤ α*(n:ℝ) ∧ + t < ∑ k∈S,coupling (goeDisorder (j/(n:ℝ)) g) i k^2} ≤ + exp (-(n:ℝ)*(t/(4*j)-(l*α+log (1+exp (-l))+α*log 2))) := by + have he : {g : MatrixCoordinates (Fin n)→ℝ | ∃ S : Finset (Fin n),(S.card:ℝ) ≤ α*(n:ℝ) ∧ + t < ∑ k∈S,coupling (goeDisorder (j/(n:ℝ)) g) i k^2}= + ⋃ S∈smallSupports (ι:=Fin n) α,{g | t < ∑ k∈S,coupling (goeDisorder (j/(n:ℝ)) g) i k^2} := by + ext g;simp [smallSupports] + rw [he] + have hb := sparse_union_bound (gaussianCoordinates (MatrixCoordinates (Fin n))) + (ι:=Fin n) (C:=1) (q:=t/(4*j)-α*log 2) (α:=α) + (fun S=>{g | t < ∑ k∈S,coupling (goeDisorder (j/(n:ℝ)) g) i k^2}) hl (by norm_num : (0:ℝ) ≤ 1) ?_ + · convert hb using 1 + simp only [one_mul,Fintype.card_fin] + congr 1 + ring + intro S hS + have hc : (S.card:ℝ) ≤ α*(n:ℝ) := by simpa only [Fintype.card_fin] using (Finset.mem_filter.mp hS).2 + apply (coupling_goe_row_tail (div_pos hj hn) i S t).trans + simp only [one_mul,Fintype.card_fin] + apply exp_le_exp.mpr + have hh := mul_le_mul_of_nonneg_right hc (log_nonneg (show (1:ℝ) ≤ 2 by norm_num)) + have he' : -t/(4*(j/(n:ℝ))) = -(n:ℝ)*(t/(4*j)) := by field_simp + rw [he'] + nlinarith only [hh] + have he : {g : MatrixCoordinates (Fin n)→ℝ | ∃ i : Fin n,∃ S : Finset (Fin n),(S.card:ℝ) ≤ α*(n:ℝ) ∧ + t < ∑ k∈S,coupling (goeDisorder (j/(n:ℝ)) g) i k^2}= + ⋃ i : Fin n,{g | ∃ S : Finset (Fin n),(S.card:ℝ) ≤ α*(n:ℝ) ∧ + t < ∑ k∈S,coupling (goeDisorder (j/(n:ℝ)) g) i k^2} := by ext g;simp + rw [he] + apply (measureReal_iUnion_fintype_le _).trans + apply (Finset.sum_le_sum (fun i _=>hsingle i)).trans_eq + simp +end SKGap + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Gaussian/GOEScalarTail.lean b/lean/OAI/Probability/SKGap/Gaussian/GOEScalarTail.lean new file mode 100644 index 0000000000000000000000000000000000000000..3cb4dc5adf7457043e1ea37e388021234610402d --- /dev/null +++ b/lean/OAI/Probability/SKGap/Gaussian/GOEScalarTail.lean @@ -0,0 +1,158 @@ +import Mathlib +import OAI.Probability.SKGap.Gaussian.ConditionalGramTail +import OAI.Probability.SKGap.Localization.ConditionalRankAlgebra + +namespace OAI + +section +noncomputable section +namespace SKGap +open Matrix MeasureTheory ProbabilityTheory Real +open scoped BigOperators Matrix.Norms.Frobenius + +theorem goe_scalar_tail {n : ℕ} (hn : 0 < n) {j U ε : ℝ} + (hj : 0 < j) (hU : 0 ≤ U) (hε : 0 ≤ ε) + (u : EuclideanSpace ℝ (Fin n)) (hu : ‖u‖ ≤ U) : + (Measure.pi (fun _ : MatrixCoordinates (Fin n) => gaussianReal 0 1)).real + {g | ε ≤ |matrixBilinear (goeMatrix (j/(n:ℝ)) g) u u|} ≤ + 2*exp (-(n:ℝ)*ε^2/(π^2*(2*(U+1)^2)^2*j)) := by + let : Nonempty (Fin n) := Fin.pos_iff_nonempty.mp hn + have h := goe_bilinear_concentration hj (by norm_num : (0:ℝ)≤1) hU + (by norm_num : (0:ℝ)≤0) hε (fun M => M) (fun _ _ _ => rfl) + (fun M N => by simp) 0 (by intro i; simp [goeEntry_integral]) u u hu hu + have hz : (diagonal (0 : Fin n → ℝ) : Matrix (Fin n) (Fin n) ℝ)=0 := by + ext i k; simp [Matrix.diagonal] + rw [hz] at h + simpa only [Fintype.card_fin,zero_mul,zero_add,sub_zero, + show (1:ℝ)+1=2 by norm_num] using h +end SKGap +end +end + +section +noncomputable section +namespace SKGap +open Matrix MeasureTheory ProbabilityTheory Real Set +open scoped BigOperators MatrixOrder Matrix.Norms.Frobenius + +def conditionalBase {n : ℕ} (j : ℝ) (a : Fin n → ℝ) + (g : MatrixCoordinates (Fin n) → ℝ) : Matrix (Fin n) (Fin n) ℝ := + 1-pathDiagonal a 1*(goeMatrix (j/(n:ℝ)) g-((j/(n:ℝ))*∑ i,a i) • 1)*pathDiagonal a 1 + +def conditionalUpdateColumns {n : ℕ} (j : ℝ) (a : Fin n → ℝ) + (p : Fin 3 → EuclideanSpace ℝ (Fin n)) (u : EuclideanSpace ℝ (Fin n)) + (g : MatrixCoordinates (Fin n) → ℝ) : Matrix (Fin n) ((Fin 3) ⊕ Unit) ℝ := + extendColumns (fun r => (p r).ofLp) + (residualGramVector (j/(n:ℝ)*∑ i,a i) (goeMatrix (j/(n:ℝ)) g) u.ofLp) + +theorem compact_conditional_fixed_tail {α : Type*} [TopologicalSpace α] [CompactSpace α] + {j A U : ℝ} (hj : 0 < j) (hj1 : j < 1) (hA : 0 < A) + (hsub : sqrt j*A < 1) (hU : 0 ≤ U) + (b e s q κ : α → ℝ) (hb : Continuous b) (he : Continuous e) + (hs : Continuous s) (hq : Continuous q) (hk : Continuous κ) + (hb0 : ∀ x,0 < b x) (hb1 : ∀ x,b x ≤ 1) (he0 : ∀ x,0 ≤ e x) + (hs0 : ∀ x,0 < s x) (hq0 : ∀ x,0 < q x) + (hkq : ∀ x,κ x^2=1-j*q x/s x) : + ∃ δ ρ : ℝ, 0 < δ ∧ δ < 1 ∧ 0 < ρ ∧ + ∀ ε τ : ℝ, 0 < ε → 0 < τ → ∃ c : ℝ, ∃ N : ℕ, 0 < c ∧ 0 < N ∧ + ∀ n, N ≤ n → ∀ a : Fin n → ℝ, (∀ i,0 ≤ a i) → (∀ i,a i ≤ A) → + 0 < j/(n:ℝ)*∑ i,a i → + augmentedGramTolerance (j/(n:ℝ)*∑ i,a i) ε < ρ/2 → + ∀ p : Fin 3 → EuclideanSpace ℝ (Fin n), ∀ u : EuclideanSpace ℝ (Fin n), + (∀ r,‖p r‖ ≤ U) → ‖u‖ ≤ U → u.ofLp⬝ᵥu.ofLp=1 → + ∀ x (C E : Matrix ((Fin 3) ⊕ Unit) ((Fin 3) ⊕ Unit) ℝ), + C.IsHermitian → E.IsHermitian → τ*‖E‖ < ρ/2 → + ‖diagonalAugmentedGram a p-augmentedGram (ν := Unit) (limitingGram (b x) (e x) (s x))‖ < ρ/2 → + ‖C-conditionalCoefficient j ((2*j*q x+2*(j*b x)*(κ x-1))/q x) + j ((κ x-1)*√(j*b x)/√(q x))‖ < ρ/2 → + (Measure.pi (fun _ : MatrixCoordinates (Fin n) => gaussianReal 0 1)).real + {g | ¬(conditionalBase j a g- + pathDiagonal a 1*conditionalUpdateColumns j a p u g* + (C+matrixBilinear (goeMatrix (j/(n:ℝ)) g) u u • E)* + (conditionalUpdateColumns j a p u g)ᵀ*pathDiagonal a 1- + (δ*((1-sqrt j*A)^2/4)) • (1 : Matrix (Fin n) (Fin n) ℝ)).PosDef} ≤ + 101*exp (-c*(n:ℝ)) := by + obtain ⟨δ,ρ,hδ,hδ1,hρ,hcrit⟩ := compact_conditional_rank_criterion hj hj1 b e s q κ + hb he hs hq hk hb0 hb1 he0 hs0 hq0 hkq + refine ⟨δ,ρ,hδ,hδ1,hρ,?_⟩ + intro ε τ hε hτ + obtain ⟨c₀,N,hc₀,hN,hgram⟩ := conditional_augmented_gram_tail hj hA hsub hU hε + let c₁ := τ^2/(π^2*(2*(U+1)^2)^2*j) + have hc₁ : 0 < c₁ := by dsimp [c₁]; positivity + refine ⟨min c₀ c₁,N,lt_min hc₀ hc₁,hN,?_⟩ + intro n hn a ha haA hB heps p u hp hu hunit x C E hC hE hEbound hdiag hcoef + let μ := Measure.pi (fun _ : MatrixCoordinates (Fin n) => gaussianReal 0 1) + let badG := {g | ¬bilinearPathGood j A a g ∨ + augmentedGramTolerance (j/(n:ℝ)*∑ i,a i) ε < + ‖actualAugmentedGram j a p u g-diagonalAugmentedGram a p‖} + let badS := {g | τ ≤ |matrixBilinear (goeMatrix (j/(n:ℝ)) g) u u|} + have hnpos := hN.trans_le hn + have hgprob : μ.real badG ≤ 99*exp (-c₀*(n:ℝ)) := hgram n hn a ha haA hB p u hp hu hunit + have hsprob : μ.real badS ≤ 2*exp (-c₁*(n:ℝ)) := by + have hh := goe_scalar_tail hnpos hj hU hτ.le u hu + convert hh using 1 + congr 2 + dsimp [c₁] + ring + have hsubsets : {g | ¬(conditionalBase j a g- + pathDiagonal a 1*conditionalUpdateColumns j a p u g* + (C+matrixBilinear (goeMatrix (j/(n:ℝ)) g) u u • E)* + (conditionalUpdateColumns j a p u g)ᵀ*pathDiagonal a 1- + (δ*((1-sqrt j*A)^2/4)) • (1 : Matrix (Fin n) (Fin n) ℝ)).PosDef} ⊆ badG ∪ badS := by + intro g hg + by_contra hbad + have hgG : g ∉ badG := fun hh => hbad (Or.inl hh) + have hgS : g ∉ badS := fun hh => hbad (Or.inr hh) + simp only [badG,mem_ofPred_eq,not_or,not_lt] at hgG + have hgS' : |matrixBilinear (goeMatrix (j/(n:ℝ)) g) u u| < τ := lt_of_not_ge hgS + let D := pathDiagonal a 1 + let S := conditionalBase j a g + let V := conditionalUpdateColumns j a p u g + let Cg := C+matrixBilinear (goeMatrix (j/(n:ℝ)) g) u u • E + let lo := (1-sqrt j*A)^2/4 + have hmargin : (S-lo • (1 : Matrix (Fin n) (Fin n) ℝ)).PosDef := + bilinearPathGood_margin a g (not_not.mp hgG.1) + have hlo : 0 ≤ lo := by dsimp [lo]; positivity + have hSpos : S.PosDef := by + have hh := hmargin.add_posSemidef ((Matrix.PosSemidef.one : (1 : Matrix (Fin n) (Fin n) ℝ).PosSemidef).smul hlo) + convert hh using 1; abel + have hD : D.IsHermitian := isHermitian_diagonal_iff.mpr + (fun i => isSelfAdjoint_iff.mpr (star_trivial _)) + have hCg : Cg.IsHermitian := hC.add (hE.smul (R := ℝ) + (isSelfAdjoint_iff.mpr (star_trivial _))) + have hG : ‖Vᵀ*D*S⁻¹*D*V-augmentedGram (ν := Unit) (limitingGram (b x) (e x) (s x))‖ < ρ := by + have hh := norm_sub_le_norm_sub_add_norm_sub (actualAugmentedGram j a p u g) (diagonalAugmentedGram a p) + (augmentedGram (ν := Unit) (limitingGram (b x) (e x) (s x))) + have heq : Vᵀ*D*S⁻¹*D*V=actualAugmentedGram j a p u g := by + simp only [V,D,S,conditionalUpdateColumns,conditionalBase,actualAugmentedGram, + exactG,Fintype.card_fin,Matrix.mul_assoc] + rw [heq] + exact hh.trans_lt (by linarith [hgG.2]) + have hCgclose : ‖Cg-conditionalCoefficient j ((2*j*q x+2*(j*b x)*(κ x-1))/q x) + j ((κ x-1)*√(j*b x)/√(q x))‖ < ρ := by + have hn : ‖matrixBilinear (goeMatrix (j/(n:ℝ)) g) u u • E‖ ≤ τ*‖E‖ := by + rw [norm_smul,Real.norm_eq_abs] + exact mul_le_mul_of_nonneg_right hgS'.le (norm_nonneg _) + have hh := norm_add_le (C-conditionalCoefficient j ((2*j*q x+2*(j*b x)*(κ x-1))/q x) + j ((κ x-1)*√(j*b x)/√(q x))) (matrixBilinear (goeMatrix (j/(n:ℝ)) g) u u • E) + have heq : Cg-conditionalCoefficient j ((2*j*q x+2*(j*b x)*(κ x-1))/q x) + j ((κ x-1)*√(j*b x)/√(q x))= + (C-conditionalCoefficient j ((2*j*q x+2*(j*b x)*(κ x-1))/q x) + j ((κ x-1)*√(j*b x)/√(q x)))+matrixBilinear (goeMatrix (j/(n:ℝ)) g) u u • E := by + dsimp [Cg]; abel + rw [heq] + exact hh.trans_lt (by linarith) + exact hg (hcrit x (Fin n) S D V Cg lo hSpos hD hCg hmargin.posSemidef hG hCgclose) + apply (measureReal_mono hsubsets (measure_ne_top _ _)).trans + apply (measureReal_union_le badG badS).trans + apply (add_le_add hgprob hsprob).trans + have he₀ : exp (-c₀*(n:ℝ)) ≤ exp (-min c₀ c₁*(n:ℝ)) := by + apply exp_le_exp.mpr; simpa only [neg_mul] using neg_le_neg (mul_le_mul_of_nonneg_right (min_le_left c₀ c₁) (Nat.cast_nonneg n : (0:ℝ) ≤ n)) + have he₁ : exp (-c₁*(n:ℝ)) ≤ exp (-min c₀ c₁*(n:ℝ)) := by + apply exp_le_exp.mpr; simpa only [neg_mul] using neg_le_neg (mul_le_mul_of_nonneg_right (min_le_right c₀ c₁) (Nat.cast_nonneg n : (0:ℝ) ≤ n)) + nlinarith +end SKGap +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Gaussian/GaussMoment.lean b/lean/OAI/Probability/SKGap/Gaussian/GaussMoment.lean new file mode 100644 index 0000000000000000000000000000000000000000..11023d78a608af1283cc7d45db73f99e01b6f874 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Gaussian/GaussMoment.lean @@ -0,0 +1,511 @@ +import Mathlib +import OAI.Probability.SKGap.Model + +namespace OAI + +section +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open scoped BigOperators +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open scoped BigOperators +open scoped BigOperators NNReal ENNReal +open MeasureTheory Metric Set +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators NNReal ENNReal Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Set +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators ENNReal NNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Matrix +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators ENNReal NNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal +open scoped BigOperators +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise NNReal ENNReal +open scoped BigOperators +open Filter Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal Topology +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Set Matrix +open scoped BigOperators NNReal ENNReal Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open Filter MeasureTheory ProbabilityTheory +open scoped Topology NNReal ENNReal +open Filter MeasureTheory ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter +open scoped Topology NNReal ENNReal +namespace SKGapCutoff.Clock + +noncomputable def gaussMoment (a : ℝ) (k : ℕ) (x : ℝ) : ℝ := + x^k*Real.exp (-a*x^2) + +lemma integrable_gaussMoment {a : ℝ} (ha : 0 < a) (k : ℕ) : + Integrable (gaussMoment a k) := by + have hk : (-1:ℝ) < (k:ℝ) := by have := (Nat.cast_nonneg k : (0:ℝ)≤k); linarith + have hh := integrable_rpow_mul_exp_neg_mul_sq ha hk + convert! hh using 1 + ext x + exact (Real.rpow_natCast x k).symm |> congrArg (fun t => t*Real.exp (-a*x^2)) + +lemma hasDerivAt_gaussMoment (a : ℝ) (k : ℕ) (x : ℝ) : + HasDerivAt (gaussMoment a k) + ((k:ℝ)*gaussMoment a (k-1) x-2*a*gaussMoment a (k+1) x) x := by + have he := ((((hasDerivAt_id x).pow 2).const_mul (-a)).exp) + convert! ((hasDerivAt_id x).pow k).mul he using 1 + simp only [gaussMoment,pow_succ,Pi.pow_apply,id_eq,Nat.cast_ofNat,mul_one,pow_zero] + ring + +lemma integrable_abs_add_one_pow_gauss {a : ℝ} (ha : 0 < a) (k : ℕ) : + Integrable (fun x : ℝ => (|x|+1)^k*Real.exp (-a*x^2)) := by + have hi (j : ℕ) : Integrable (fun x : ℝ => |x|^j*Real.exp (-a*x^2)) := by + simpa only [gaussMoment,Real.norm_eq_abs,abs_mul,abs_pow, + abs_of_nonneg (Real.exp_nonneg _)] using (integrable_gaussMoment ha j).norm + have hh := integrable_finsetSum (Finset.range (k+1)) + (fun j _ => (hi j).mul_const (k.choose j:ℝ)) + convert! hh using 1 + ext x + rw [add_pow,Finset.sum_mul] + apply Finset.sum_congr rfl + intro j hj + simp only [one_pow,mul_one] + ring + +noncomputable def momentEnvelope (a : ℝ) (k : ℕ) (x : ℝ) : ℝ := + ((k:ℝ)*(|x|+1)^(k-1)+2*a*(|x|+1)^(k+1))*Real.exp a*Real.exp (-(a/2)*x^2) + +lemma integrable_momentEnvelope {a : ℝ} (ha : 0 < a) (k : ℕ) : + Integrable (momentEnvelope a k) := by + have hhalf : 0 < a/2 := by positivity + have hh := (((integrable_abs_add_one_pow_gauss hhalf (k-1)).const_mul (k:ℝ)).add + ((integrable_abs_add_one_pow_gauss hhalf (k+1)).const_mul (2*a))).const_mul (Real.exp a) + convert! hh using 1 + ext x + simp only [momentEnvelope,Pi.add_apply] + ring + +lemma gaussMoment_deriv_bound {a : ℝ} (ha : 0 < a) (k : ℕ) (x z : ℝ) + (hz : z ∈ Set.Icc (x-1) (x+1)) : + |(k:ℝ)*gaussMoment a (k-1) z-2*a*gaussMoment a (k+1) z| ≤ + momentEnvelope a k x := by + have hdist : |z-x| ≤ 1 := abs_le.mpr ⟨by linarith [hz.1],by linarith [hz.2]⟩ + have hzabs : |z| ≤ |x|+1 := by + calc + |z| = |(z-x)+x| := by rw [sub_add_cancel] + _ ≤ |z-x|+|x| := abs_add_le _ _ + _ ≤ |x|+1 := by linarith + have hsq : (z-x)^2 ≤ 1 := by + have hh := mul_self_le_mul_self (abs_nonneg (z-x)) hdist + nlinarith [sq_abs (z-x)] + have hquad : x^2/2-1 ≤ z^2 := by nlinarith [sq_nonneg (x-2*z)] + have he : Real.exp (-a*z^2) ≤ Real.exp a*Real.exp (-(a/2)*x^2) := by + rw [← Real.exp_add] + apply Real.exp_le_exp.mpr + nlinarith [mul_nonneg ha.le (sub_nonneg.mpr hquad)] + have h1 := pow_le_pow_left₀ (abs_nonneg z) hzabs (k-1) + have h2 := pow_le_pow_left₀ (abs_nonneg z) hzabs (k+1) + calc + _ ≤ |(k:ℝ)*gaussMoment a (k-1) z|+|2*a*gaussMoment a (k+1) z| := by + simpa only [Real.norm_eq_abs] using norm_sub_le + ((k:ℝ)*gaussMoment a (k-1) z) (2*a*gaussMoment a (k+1) z) + _ = ((k:ℝ)*|z|^(k-1)+2*a*|z|^(k+1))*Real.exp (-a*z^2) := by + norm_num only [gaussMoment,abs_mul,abs_pow,abs_of_nonneg (Nat.cast_nonneg k : (0:ℝ)≤k), + abs_of_nonneg ha.le,abs_of_nonneg (Real.exp_nonneg _)] + ring + _ ≤ ((k:ℝ)*(|x|+1)^(k-1)+2*a*(|x|+1)^(k+1))* + (Real.exp a*Real.exp (-(a/2)*x^2)) := by + apply mul_le_mul _ he (Real.exp_nonneg _) (by positivity) + exact add_le_add (mul_le_mul_of_nonneg_left h1 (Nat.cast_nonneg _)) + (mul_le_mul_of_nonneg_left h2 (by positivity)) + _ = _ := by dsimp [momentEnvelope]; ring + +noncomputable def diffMoment (a : ℝ) (k : ℕ) (h x : ℝ) : ℝ := + (gaussMoment a k (x+h)-gaussMoment a k x)/h + +lemma diffMoment_bound {a : ℝ} (ha : 0 < a) (k : ℕ) {h : ℝ} + (hh : 0 < h) (hh1 : h ≤ 1) (x : ℝ) : + |diffMoment a k h x| ≤ momentEnvelope a k x := by + have hmv := Convex.norm_image_sub_le_of_norm_hasDerivWithin_le + (s := Set.Icc (x-1) (x+1)) + (f := gaussMoment a k) + (f' := fun z => (k:ℝ)*gaussMoment a (k-1) z-2*a*gaussMoment a (k+1) z) + (fun z _ => (hasDerivAt_gaussMoment a k z).hasDerivWithinAt) + (fun z hz => by simpa only [Real.norm_eq_abs] using gaussMoment_deriv_bound ha k x z hz) + (convex_Icc _ _) (show x ∈ Set.Icc (x-1) (x+1) from ⟨by linarith,by linarith⟩) + (show x+h ∈ Set.Icc (x-1) (x+1) from ⟨by linarith,by linarith⟩) + rw [Real.norm_eq_abs,Real.norm_eq_abs,add_sub_cancel_left,abs_of_pos hh] at hmv + unfold diffMoment + rw [abs_div,abs_of_pos hh] + exact (div_le_iff₀ hh).mpr hmv + +lemma integrable_diffMoment {a : ℝ} (ha : 0 < a) (k : ℕ) (h : ℝ) : + Integrable (diffMoment a k h) := + (((integrable_gaussMoment ha k).comp_add_right h).sub + (integrable_gaussMoment ha k)).div_const h + +lemma gaussMoment_derivative_L1 {a : ℝ} (ha : 0 < a) (k : ℕ) : + Tendsto (fun n : ℕ => ∫ x : ℝ, + |diffMoment a k (1/((n:ℝ)+1)) x- + ((k:ℝ)*gaussMoment a (k-1) x-2*a*gaussMoment a (k+1) x)|) + atTop (𝓝 0) := by + let dg : ℝ → ℝ := fun x => (k:ℝ)*gaussMoment a (k-1) x-2*a*gaussMoment a (k+1) x + have hdg : Integrable dg := ((integrable_gaussMoment ha (k-1)).const_mul (k:ℝ)).sub + ((integrable_gaussMoment ha (k+1)).const_mul (2*a)) + have hstep : Tendsto (fun n : ℕ => 1/((n:ℝ)+1)) atTop (𝓝[≠] (0:ℝ)) := by + refine tendsto_nhdsWithin_iff.mpr ⟨tendsto_one_div_add_atTop_nhds_zero_nat, ?_⟩ + exact Filter.Eventually.of_forall (fun n => by + simp only [Set.mem_compl_iff,Set.mem_singleton_iff] + exact ne_of_gt (by positivity)) + have hp (x : ℝ) : Tendsto (fun n : ℕ => diffMoment a k (1/((n:ℝ)+1)) x) + atTop (𝓝 (dg x)) := by + have hh := (hasDerivAt_gaussMoment a k x).tendsto_slope_zero.comp hstep + simpa only [Function.comp_def,smul_eq_mul,div_eq_mul_inv,mul_comm,diffMoment,dg] using hh + have ht := tendsto_integral_of_dominated_convergence + (fun x => momentEnvelope a k x+|dg x|) + (F := fun n : ℕ => fun x => |diffMoment a k (1/((n:ℝ)+1)) x-dg x|) + (f := fun _ => (0:ℝ)) + (fun n => ((integrable_diffMoment ha k _).sub hdg).abs.aestronglyMeasurable) + ((integrable_momentEnvelope ha k).add hdg.abs) + (fun n => Filter.Eventually.of_forall (fun x => by + rw [Real.norm_eq_abs,abs_abs] + have htri : |diffMoment a k (1/((n:ℝ)+1)) x-dg x| ≤ + |diffMoment a k (1/((n:ℝ)+1)) x|+|dg x| := by + simpa only [Real.norm_eq_abs] using + norm_sub_le (diffMoment a k (1/((n:ℝ)+1)) x) (dg x) + exact htri.trans (add_le_add (diffMoment_bound ha k (h := 1/((n:ℝ)+1)) (by positivity) + (by have := (Nat.cast_nonneg n : (0:ℝ)≤n); apply (div_le_one (by positivity)).mpr; linarith) x) le_rfl))) + (Filter.Eventually.of_forall (fun x => by simpa using ((hp x).sub_const (dg x)).abs)) + simpa only [integral_zero] using ht + +noncomputable def momentL1 (a : ℝ) (ha : 0 < a) (k : ℕ) (y : ℝ) : Lp ℝ 1 (volume : Measure ℝ) := + Integrable.toL1 (fun x : ℝ => gaussMoment a k (x+y)) + ((integrable_gaussMoment ha k).comp_add_right y) + +lemma norm_toL1_real {f : ℝ → ℝ} (hf : Integrable f) : + ‖hf.toL1 f‖ = ∫ x : ℝ, |f x| := by + rw [Integrable.norm_toL1_eq_lintegral_enorm, + ← integral_norm_eq_lintegral_enorm hf.aestronglyMeasurable] + simp only [Real.norm_eq_abs] + +lemma momentL1_derivative {a : ℝ} (ha : 0 < a) (k : ℕ) (y : ℝ) : + Tendsto (fun n : ℕ => ((1/((n:ℝ)+1))⁻¹) • + (momentL1 a ha k (y+1/((n:ℝ)+1))-momentL1 a ha k y)) atTop + (𝓝 ((k:ℝ) • momentL1 a ha (k-1) y-(2*a) • momentL1 a ha (k+1) y)) := by + apply tendsto_iff_norm_sub_tendsto_zero.mpr + have he (n : ℕ) : + ‖((1/((n:ℝ)+1))⁻¹) • (momentL1 a ha k (y+1/((n:ℝ)+1))- + momentL1 a ha k y)-((k:ℝ) • momentL1 a ha (k-1) y- + (2*a) • momentL1 a ha (k+1) y)‖ = + ∫ x : ℝ, |diffMoment a k (1/((n:ℝ)+1)) x- + ((k:ℝ)*gaussMoment a (k-1) x-2*a*gaussMoment a (k+1) x)| := by + let h : ℝ := 1/((n:ℝ)+1) + let f : ℝ → ℝ := fun x => h⁻¹ * (gaussMoment a k (x+(y+h))- + gaussMoment a k (x+y))- + ((k:ℝ)*gaussMoment a (k-1) (x+y)-(2*a)*gaussMoment a (k+1) (x+y)) + have hf : Integrable f := + ((((integrable_gaussMoment ha k).comp_add_right (y+h)).sub + ((integrable_gaussMoment ha k).comp_add_right y)).const_mul h⁻¹).sub + ((((integrable_gaussMoment ha (k-1)).comp_add_right y).const_mul (k:ℝ)).sub + (((integrable_gaussMoment ha (k+1)).comp_add_right y).const_mul (2*a))) + change ‖hf.toL1 f‖ = _ + rw [norm_toL1_real] + have hfun : (fun x => |f x|) = fun x => |diffMoment a k h (x+y)- + ((k:ℝ)*gaussMoment a (k-1) (x+y)-2*a*gaussMoment a (k+1) (x+y))| := by + funext x + simp only [f,diffMoment,add_assoc,div_eq_mul_inv,mul_comm] + rw [hfun] + exact integral_add_right_eq_self (fun x => |diffMoment a k h x- + ((k:ℝ)*gaussMoment a (k-1) x-2*a*gaussMoment a (k+1) x)|) y + simp_rw [he] + exact gaussMoment_derivative_L1 ha k + +lemma momentL1_mem_of_gaussian {a : ℝ} (ha : 0 < a) + (S : Submodule ℝ (Lp ℝ 1 (volume : Measure ℝ))) (hS : IsClosed (S : Set (Lp ℝ 1 (volume : Measure ℝ)))) + (hbase : ∀ y, momentL1 a ha 0 y ∈ S) : + ∀ k y, momentL1 a ha k y ∈ S := by + intro k + induction k using Nat.strong_induction_on with + | h k ih => + intro y + cases k with + | zero => exact hbase y + | succ k => + have hder : (k:ℝ) • momentL1 a ha (k-1) y- + (2*a) • momentL1 a ha (k+1) y ∈ S := + hS.mem_of_tendsto (momentL1_derivative ha k y) + (Filter.Eventually.of_forall (fun n => S.smul_mem _ + (S.sub_mem (ih k (by omega) _) (ih k (by omega) _)))) + have hlow : (k:ℝ) • momentL1 a ha (k-1) y ∈ S := + S.smul_mem _ (ih (k-1) (by omega) y) + have hhigh := S.sub_mem hlow hder + rw [sub_sub_cancel] at hhigh + have hn : (2*a) ≠ 0 := ne_of_gt (by positivity) + have hh := S.smul_mem (2*a)⁻¹ hhigh + simpa only [smul_smul,inv_mul_cancel₀ hn,one_smul] using hh + +noncomputable def gaussianTaylor (a c : ℝ) (N : ℕ) (x : ℝ) : ℝ := + ∑ k ∈ Finset.range N, ((-c)^k/(Nat.factorial k : ℝ))*gaussMoment a (2*k) x + +lemma gaussianTaylor_eq (a c : ℝ) (N : ℕ) (x : ℝ) : + gaussianTaylor a c N x = + (∑ k ∈ Finset.range N, (-c*x^2)^k/(Nat.factorial k : ℝ))*Real.exp (-a*x^2) := by + unfold gaussianTaylor gaussMoment + rw [Finset.sum_mul] + apply Finset.sum_congr rfl + intro k _ + rw [mul_pow,← pow_mul] + ring + +lemma gaussianTaylor_bound (a : ℝ) {c : ℝ} (hc : 0 ≤ c) (N : ℕ) (x : ℝ) : + |gaussianTaylor a c N x| ≤ Real.exp (-(a-c)*x^2) := by + rw [gaussianTaylor_eq,abs_mul,abs_of_pos (Real.exp_pos _)] + have habs : |∑ k ∈ Finset.range N, (-c*x^2)^k/(Nat.factorial k : ℝ)| ≤ + ∑ k ∈ Finset.range N, (c*x^2)^k/(Nat.factorial k : ℝ) := by + calc + _ ≤ ∑ k ∈ Finset.range N, |(-c*x^2)^k/(Nat.factorial k : ℝ)| := + Finset.abs_sum_le_sum_abs _ _ + _ = _ := by + apply Finset.sum_congr rfl + intro k _ + rw [abs_div,abs_pow,abs_mul,abs_neg,abs_of_nonneg hc, + abs_of_nonneg (sq_nonneg x),abs_of_nonneg (Nat.cast_nonneg _)] + calc + _ ≤ Real.exp (c*x^2)*Real.exp (-a*x^2) := + mul_le_mul_of_nonneg_right (habs.trans (Real.sum_le_exp_of_nonneg (by positivity) N)) + (Real.exp_nonneg _) + _ = _ := by rw [← Real.exp_add]; congr 1; ring + +lemma integrable_gaussianTaylor {a : ℝ} (ha : 0 < a) (c : ℝ) (N : ℕ) : + Integrable (gaussianTaylor a c N) := + integrable_finsetSum _ (fun k _ => (integrable_gaussMoment ha (2*k)).const_mul _) + +lemma gaussianTaylor_tendsto (a c x : ℝ) : + Tendsto (fun N : ℕ => gaussianTaylor a c N x) atTop (𝓝 (gaussMoment (a+c) 0 x)) := by + have ht := (NormedSpace.expSeries_div_hasSum_exp (-c*x^2)).tendsto_sum_nat.mul_const + (Real.exp (-a*x^2)) + simpa only [gaussianTaylor_eq,← Real.exp_eq_exp_ℝ,← Real.exp_add,gaussMoment,pow_zero,one_mul, + show -c*x^2+-a*x^2=-(a+c)*x^2 by ring] using ht + +lemma gaussianTaylor_L1 {a c : ℝ} (ha : 0 < a) (hc : 0 ≤ c) (hca : c < a) : + Tendsto (fun N : ℕ => ∫ x : ℝ, + |gaussianTaylor a c N x-gaussMoment (a+c) 0 x|) atTop (𝓝 0) := by + have hp : 0 < a+c := by linarith + have hm : 0 < a-c := by linarith + have hh := tendsto_integral_of_dominated_convergence + (fun x => Real.exp (-(a-c)*x^2)+Real.exp (-(a+c)*x^2)) + (F := fun N : ℕ => fun x => |gaussianTaylor a c N x-gaussMoment (a+c) 0 x|) + (f := fun _ => (0:ℝ)) + (fun N => ((integrable_gaussianTaylor ha c N).sub (integrable_gaussMoment hp 0)).abs.aestronglyMeasurable) + (by simpa only [Pi.add_def,gaussMoment,pow_zero,one_mul] using + (integrable_gaussMoment hm 0).add (integrable_gaussMoment hp 0)) + (fun N => Filter.Eventually.of_forall (fun x => by + rw [Real.norm_eq_abs,abs_abs] + have htri := norm_sub_le (gaussianTaylor a c N x) (gaussMoment (a+c) 0 x) + simp only [Real.norm_eq_abs,gaussMoment,pow_zero,one_mul,abs_of_pos (Real.exp_pos _)] at htri + simpa only [gaussMoment,pow_zero,one_mul] using + htri.trans (add_le_add (gaussianTaylor_bound a hc N x) le_rfl))) + (Filter.Eventually.of_forall (fun x => by + simpa using ((gaussianTaylor_tendsto a c x).sub_const (gaussMoment (a+c) 0 x)).abs)) + simpa only [integral_zero] using hh + +lemma toL1_finsetSum {ι : Type*} (s : Finset ι) (f : ι → ℝ → ℝ) + (hf : ∀ i, Integrable (f i)) : + (integrable_finsetSum s (fun i _ => hf i)).toL1 (fun x => ∑ i ∈ s, f i x) = + ∑ i ∈ s, (hf i).toL1 (f i) := by + classical + induction s using Finset.induction_on with + | empty => + simp only [Finset.sum_empty] + exact Integrable.toL1_zero _ + | @insert i s hi ih => + simp only [Finset.sum_insert hi] + change (((hf i).add (integrable_finsetSum s (fun j _ => hf j))).toL1 + (f i+(fun x => ∑ j ∈ s, f j x))) = _ + rw [Integrable.toL1_add _ _ (hf i) + (integrable_finsetSum s (fun j _ => hf j)),ih] + +lemma toL1_tendsto_of_integral_abs_sub {f : ℕ → ℝ → ℝ} {g : ℝ → ℝ} + (hf : ∀ n, Integrable (f n)) (hg : Integrable g) + (ht : Tendsto (fun n => ∫ x : ℝ, |f n x-g x|) atTop (𝓝 0)) : + Tendsto (fun n => (hf n).toL1 (f n)) atTop (𝓝 (hg.toL1 g)) := by + apply tendsto_iff_norm_sub_tendsto_zero.mpr + have he (n : ℕ) : ‖(hf n).toL1 (f n)-hg.toL1 g‖ = ∫ x : ℝ, |f n x-g x| := by + change ‖((hf n).sub hg).toL1 (f n-g)‖ = _ + exact norm_toL1_real _ + simpa only [he] using ht + +lemma gaussian_increment_mem {a c : ℝ} (ha : 0 < a) (hc : 0 ≤ c) (hca : c < a) + (S : Submodule ℝ (Lp ℝ 1 (volume : Measure ℝ))) + (hS : IsClosed (S : Set (Lp ℝ 1 (volume : Measure ℝ)))) + (hbase : ∀ y, momentL1 a ha 0 y ∈ S) : + ∀ y, momentL1 (a+c) (by linarith) 0 y ∈ S := by + intro y + have hm := momentL1_mem_of_gaussian ha S hS hbase + let fp : ℕ → ℝ → ℝ := fun N x => gaussianTaylor a c N (x+y) + have hfp (N : ℕ) : Integrable (fp N) := (integrable_gaussianTaylor ha c N).comp_add_right y + have hin (N : ℕ) : (hfp N).toL1 (fp N) ∈ S := by + have he : (hfp N).toL1 (fp N) = + ∑ k ∈ Finset.range N, ((-c)^k/(Nat.factorial k:ℝ)) • momentL1 a ha (2*k) y := by + exact toL1_finsetSum (Finset.range N) + (fun k x => ((-c)^k/(Nat.factorial k:ℝ))*gaussMoment a (2*k) (x+y)) + (fun k => ((integrable_gaussMoment ha (2*k)).comp_add_right y).const_mul _) + rw [he] + exact S.sum_mem (fun k _ => S.smul_mem _ (hm _ y)) + have ht : Tendsto (fun N => ∫ x : ℝ, + |fp N x-gaussMoment (a+c) 0 (x+y)|) atTop (𝓝 0) := by + have he (N : ℕ) : (∫ x : ℝ, |fp N x-gaussMoment (a+c) 0 (x+y)|) = + ∫ x : ℝ, |gaussianTaylor a c N x-gaussMoment (a+c) 0 x| := + integral_add_right_eq_self (fun x => |gaussianTaylor a c N x-gaussMoment (a+c) 0 x|) y + simpa only [he] using gaussianTaylor_L1 ha hc hca + exact hS.mem_of_tendsto (toL1_tendsto_of_integral_abs_sub hfp + ((integrable_gaussMoment (by linarith : 0 < a+c) 0).comp_add_right y) ht) + (Filter.Eventually.of_forall hin) + +lemma gaussian_wider_precision_mem {a b : ℝ} (ha : 0 < a) (hab : a ≤ b) + (S : Submodule ℝ (Lp ℝ 1 (volume : Measure ℝ))) + (hS : IsClosed (S : Set (Lp ℝ 1 (volume : Measure ℝ)))) + (hbase : ∀ y, momentL1 a ha 0 y ∈ S) : + ∀ y, momentL1 b (ha.trans_le hab) 0 y ∈ S := by + obtain ⟨N,hN⟩ := exists_nat_gt ((b-a)/a+1) + have hN0 : (0:ℝ) < N := by + have : 0 ≤ (b-a)/a := div_nonneg (sub_nonneg.mpr hab) ha.le + linarith + let c : ℝ := (b-a)/N + have hc : 0 ≤ c := div_nonneg (sub_nonneg.mpr hab) hN0.le + have hca : c < a := by + apply (div_lt_iff₀ hN0).mpr + have : (b-a)/a < (N:ℝ) := by linarith + have := (div_lt_iff₀ ha).mp this + linarith + have hall (n : ℕ) : ∀ y, momentL1 (a+(n:ℝ)*c) (by positivity) 0 y ∈ S := by + induction n with + | zero => simpa only [Nat.cast_zero,zero_mul,add_zero] using hbase + | succ n ih => + have hh := gaussian_increment_mem (show 0 < a+(n:ℝ)*c by positivity) hc + (show c < a+(n:ℝ)*c by have := mul_nonneg (Nat.cast_nonneg n) hc; linarith) S hS ih + have he : a+(↑(n+1):ℝ)*c=(a+(n:ℝ)*c)+c := by push_cast; ring + simpa only [he] using hh + have he : a+(N:ℝ)*c = b := by dsimp [c]; field_simp [ne_of_gt hN0]; ring + simpa only [he] using hall N + +lemma gaussian_mem_closed_span {a b : ℝ} (ha : 0 < a) (hab : a ≤ b) (y : ℝ) : + momentL1 b (ha.trans_le hab) 0 y ∈ + (Submodule.span ℝ (Set.range (momentL1 a ha 0))).topologicalClosure := by + apply gaussian_wider_precision_mem ha hab _ + (Submodule.isClosed_topologicalClosure _) (fun z => ?_) y + exact Submodule.le_topologicalClosure _ (Submodule.subset_span ⟨z,rfl⟩) + +theorem finite_gaussian_approximation {a b ε : ℝ} (ha : 0 < a) (hab : a ≤ b) + (hε : 0 < ε) : + ∃ (s : Finset ℝ) (c : ℝ → ℝ), + (∫ x : ℝ, |gaussMoment b 0 x- + ∑ y ∈ s, c y*gaussMoment a 0 (x+y)|) < ε := by + classical + have hm := gaussian_mem_closed_span ha hab 0 + change momentL1 b (ha.trans_le hab) 0 0 ∈ + closure (↑(Submodule.span ℝ (Set.range (momentL1 a ha 0))) : Set _) at hm + obtain ⟨w,hw,hclose⟩ := Metric.mem_closure_iff.mp hm ε hε + obtain ⟨c,rfl⟩ := Finsupp.mem_span_range_iff_exists_finsupp.mp hw + refine ⟨c.support,c,?_⟩ + let f : ℝ → ℝ := fun x => ∑ y ∈ c.support, c y*gaussMoment a 0 (x+y) + have hf : Integrable f := integrable_finsetSum _ (fun y _ => + ((integrable_gaussMoment ha 0).comp_add_right y).const_mul (c y)) + have hfL : hf.toL1 f = c.sum (fun y z => z • momentL1 a ha 0 y) := + toL1_finsetSum c.support (fun y x => c y*gaussMoment a 0 (x+y)) + (fun y => ((integrable_gaussMoment ha 0).comp_add_right y).const_mul (c y)) + rw [dist_eq_norm,← hfL] at hclose + change ‖((((integrable_gaussMoment (ha.trans_le hab) 0).comp_add_right 0).sub hf).toL1 + (fun x => gaussMoment b 0 (x+0)-f x))‖ < ε at hclose + rw [norm_toL1_real] at hclose + simpa only [add_zero] using hclose + +end SKGapCutoff.Clock + +open MeasureTheory Filter ProbabilityTheory +open scoped Topology NNReal ENNReal + +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Gaussian/GaussianCompactTailRate.lean b/lean/OAI/Probability/SKGap/Gaussian/GaussianCompactTailRate.lean new file mode 100644 index 0000000000000000000000000000000000000000..b1e9424caa918033989f29f4333c5ae7c54d6426 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Gaussian/GaussianCompactTailRate.lean @@ -0,0 +1,186 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.ScalarEmpirical +import OAI.Probability.SKGap.Gaussian.SquareTail + +namespace OAI + +section +noncomputable section +open MeasureTheory ProbabilityTheory InformationTheory Real Set Filter +open scoped NNReal ENNReal Topology +noncomputable section +open Real Set +noncomputable section +open MeasureTheory ProbabilityTheory Real Set Filter +open scoped Topology NNReal ENNReal BoundedContinuousFunction +open MeasureTheory ProbabilityTheory Filter Set Topology Real +open scoped NNReal ENNReal BoundedContinuousFunction +noncomputable section +open Set Filter Topology +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set Topology Real +open scoped NNReal ENNReal BoundedContinuousFunction +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set Topology Real +open scoped NNReal ENNReal BoundedContinuousFunction +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set Topology Real +open scoped NNReal ENNReal +noncomputable section +open MeasureTheory ProbabilityTheory Real Filter Set +open scoped Topology NNReal ENNReal BoundedContinuousFunction +namespace SKGap + +theorem gaussian_compact_tail_rate {X : Type*} [TopologicalSpace X] {K : Set X} + (hK : IsCompact K) {P : X → ProbabilityMeasure ℝ} {d s ψ : X → ℝ} + (hP : ContinuousOn P K) (hd : ContinuousOn d K) (hs : ContinuousOn s K) + (hψ : ContinuousOn ψ K) (hpos : ∀ x ∈ K, 0 < s x) (R : ℝ) + {α ν : ℝ} (hα : 0 < α) (hν : 0 < ν) + (hαs : ∀ x ∈ K, α < 1/(4*s x)) + (hW : ∀ ε > 0, ∀ x ∈ K, ∃ f : ℝ →ᵇ ℝ, ψ x-(∫ y, f y ∂P x)+ + log (∫ y, exp (f y) ∂gaussianReal (d x) (s x).toNNReal) < ε) : + ∃ R₁ : ℝ, ∃ N : ℕ, ∀ n ≥ N, ∀ hn : 0 < n, ∀ z : (Fin n → ℝ) → X, + ∀ E : Set (Fin n → ℝ), MeasurableSet E → + (∀ y ∈ E, z y ∈ K) → + (∀ y ∈ E, P (z y) = @empiricalLaw (Fin n) _ ⟨⟨0,hn⟩⟩ y) → + (∀ y ∈ E, ∑ i, (y i)^2 ≤ (n:ℝ)*R) → + (∀ y ∈ E, (n:ℝ)*ν ≤ ∑ i, squareTail R₁ (y i)) → + (∫⁻ y in E, ENNReal.ofReal (exp ((n:ℝ)*ψ (z y))*productNormal (d (z y)) (s (z y)) y)) ≤ + ENNReal.ofReal (exp (-(α*ν/2)*(n:ℝ))) := by + classical + have hav : 0 < α*ν := mul_pos hα hν + obtain ⟨C,f,hC⟩ := finite_gaussian_test_cover hK hP hd hs hψ hpos R (α*ν/8) + (hW _ (by positivity)) + have hinc (x : K) : ∀ᶠ r : ℝ in atTop, + log (∫ y, exp (f x y+α*squareTail r y) ∂gaussianReal (d x) (s x).toNNReal) ≤ + log (∫ y, exp (f x y) ∂gaussianReal (d x) (s x).toNNReal)+α*ν/8 := by + have hp : (0:ℝ≥0) < (s x).toNNReal := Real.toNNReal_pos.mpr (hpos x x.2) + have ha : α < 1/(4*((s x).toNNReal:ℝ)) := by + simpa only [Real.coe_toNNReal _ (hpos x x.2).le] using hαs x x.2 + have h := (tendsto_gaussian_tail_tilt (f x) (d := d x) hp hα.le ha).log + (tiltedNormal_mass_pos (f x) (d x) (s x).toNNReal).ne' + exact (h.eventually_lt_const (by linarith : + log (∫ y, exp (f x y) ∂gaussianReal (d x) (s x).toNNReal) < + log (∫ y, exp (f x y) ∂gaussianReal (d x) (s x).toNNReal)+α*ν/8)).mono + (fun _ hr => hr.le) + have hall : ∀ᶠ r : ℝ in atTop, ∀ x ∈ C, + log (∫ y, exp (f x y+α*squareTail r y) ∂gaussianReal (d x) (s x).toNNReal) ≤ + log (∫ y, exp (f x y) ∂gaussianReal (d x) (s x).toNNReal)+α*ν/8 := + (eventually_all_finset C).mpr (fun x _ => hinc x) + obtain ⟨R₁,hR₁⟩ := hall.exists + obtain ⟨N,hN⟩ := absorb_finite_exponential_factor C.card (show 0 < α*ν/4 by positivity) + refine ⟨R₁,N,?_⟩ + intro n hn hn' z E hE hz hemp hmom htail + let : Nonempty (Fin n) := ⟨⟨0,hn'⟩⟩ + have hh := gaussian_covered_tail_laplace C f (fun x : K => d x) (fun x : K => s x) + (fun x _ => hpos x x.2) (fun y => d (z y)) (fun y => s (z y)) (fun y => ψ (z y)) + R (α*ν/8) (α*ν/8) α ν R₁ hα.le hE (fun y hy => hpos (z y) (hz y hy)) + (by simpa only [Fintype.card_fin] using hmom) (by simpa only [Fintype.card_fin] using htail) + (fun x _ => integrable_gaussian_tail_test (f x) (Real.toNNReal_pos.mpr (hpos x x.2)) hα.le + (by simpa only [Real.coe_toNNReal _ (hpos x x.2).le] using hαs x x.2) R₁) + hR₁ (fun y hy => by + obtain ⟨x,hx,hcx⟩ := hC (z y) (hz y hy) + rw [hemp y hy] at hcx + exact ⟨x,hx,hcx⟩) + simp only [Fintype.card_fin] at hh + refine hh.trans (ENNReal.ofReal_le_ofReal ?_) + convert hN n hn (α*ν/8+α*ν/8-α*ν) using 1 + congr 1 + ring + +end SKGap + +namespace SKGap +lemma squareTail_antitone {R₁ R₂ : ℝ} (hR : R₁ ≤ R₂) (y : ℝ) : + squareTail R₂ y ≤ squareTail R₁ y := by + unfold squareTail + split_ifs <;> try positivity + · exact le_rfl + · exact (not_lt_of_ge hR (lt_of_lt_of_le (by assumption) (le_of_not_gt (by assumption)))).elim + +theorem scalar_rate_iv {j t₀ T ν : ℝ} (hj : 0 < j) (hj1 : j < 1) + (ht₀ : 0 < t₀) (hT : t₀ ≤ T) (hν : 0 < ν) : + ∃ R₁ : ℝ, ∃ a > 0, ∃ N : ℕ, ∀ R₂ ≥ R₁, ∀ n ≥ N, ∀ hn : 0 < n, + ∀ t ∈ Icc t₀ T, ∀ σ ∈ Icc 0 1, + ∀ E : Set (Fin n → ℝ), MeasurableSet E → + (∀ y ∈ E, (n:ℝ)*ν ≤ ∑ i, squareTail R₂ (y i)) → + (∫⁻ y in E, ENNReal.ofReal (@scalarIntegrand (Fin n) _ ⟨⟨0,hn⟩⟩ j t σ y)) ≤ + ENNReal.ofReal (exp (-a*(n:ℝ))) := by + have hT0 : 0 ≤ T := ht₀.le.trans hT + obtain ⟨R,hR,hTail⟩ := scalar_uniform_tail hj.le hT0 ht₀ 1 + let K := scalarBox j R T t₀ + let α := 1/(8*(T+1+j)) + have hα : 0 < α := by dsimp [α]; positivity + have hs (p : ScalarPoint) (hp : p ∈ K) : 0 < scalarS j p := ht₀.trans_le hp.2 + have hmom : K ⊆ scalarMomentDomain R := fun _ hp => ⟨hp.1.1,mem_univ _⟩ + have hαs (p : ScalarPoint) (hp : p ∈ K) : α < 1/(4*scalarS j p) := by + have hq := (scalarQMoment_bounds p.1).2 + have hz := hp.1.2.2 + have ht := hp.1.2.1 + have hsup : scalarS j p ≤ T+1+j := by + unfold scalarS + have hmul := mul_le_mul_of_nonneg_left hq hj.le + nlinarith [sq_nonneg p.2.2,hz.1,hz.2,ht.2] + have hsp := hs p hp + dsimp [α] + apply one_div_lt_one_div_of_lt (by positivity : 0 < 4*scalarS j p) + nlinarith [hs p hp] + obtain ⟨R₁,N,hN⟩ := gaussian_compact_tail_rate (isCompact_scalarBox j R T t₀) + (P := fun p : ScalarPoint => p.1) continuous_fst.continuousOn + (continuous_scalarD j).continuousOn (continuous_scalarS j).continuousOn + (continuousOn_scalarPsi_of_pos hj.le hR.le hmom hs) hs R hα hν hαs + (fun ε hε p hp => scalar_weak_test (hmom hp) hj hj1 hp.1.2.1.1 (hs p hp) hε) + let b := min (α*ν/2) 1 + have hb : 0 < b := lt_min (by positivity) zero_lt_one + obtain ⟨M,hM⟩ := absorb_finite_exponential_factor 2 (half_pos hb) + refine ⟨R₁,b/2,half_pos hb,max N M,?_⟩ + intro R₂ hR₂ n hn hn' t ht σ hσ E hE htail + let : Nonempty (Fin n) := ⟨⟨0,hn'⟩⟩ + have hsE (y : Fin n → ℝ) : t₀ ≤ scalarS j (scalarEmpirical y t σ) := by + unfold scalarS scalarEmpirical + dsimp only + have hq := mul_nonneg hj.le (scalarQMoment_bounds (empiricalLaw y)).1 + nlinarith [sq_nonneg σ,ht.1] + let B : Set (Fin n → ℝ) := {y | ∑ i, (y i)^2 ≤ (n:ℝ)*R} + have hB : MeasurableSet B := isClosed_le (by fun_prop) continuous_const |>.measurableSet + have hc := hN n (le_trans (le_max_left _ _) hn) hn' (fun y => scalarEmpirical y t σ) + (E ∩ B) (hE.inter hB) (fun y hy => ⟨⟨empirical_momentBall y hR.le + (by simpa only [Fintype.card_fin] using (show ∑ i, (y i)^2 ≤ (n:ℝ)*R from hy.2)), + ⟨ht₀.le.trans ht.1,ht.2⟩,hσ⟩,hsE y⟩) (fun _ _ => rfl) (fun _ hy => hy.2) + (fun y hy => (htail y hy.1).trans (Finset.sum_le_sum (fun i _ => squareTail_antitone hR₂ (y i)))) + have hc' : (∫⁻ y in E ∩ B, ENNReal.ofReal (scalarIntegrand j t σ y)) ≤ + ENNReal.ofReal (exp (-b*(n:ℝ))) := by + have hab : exp (-(α*ν/2)*(n:ℝ)) ≤ exp (-b*(n:ℝ)) := exp_le_exp.mpr (by + have hh := mul_le_mul_of_nonneg_right (min_le_left (α*ν/2) 1) (Nat.cast_nonneg (α := ℝ) n) + dsimp [b]; linarith only [hh]) + simpa only [scalarIntegrand,Fintype.card_fin] using hc.trans (ENNReal.ofReal_le_ofReal hab) + have htail' := hTail n hn' t ⟨ht₀.le.trans ht.1,ht.2⟩ σ hσ (E ∩ Bᶜ) (hE.inter hB.compl) + (fun y _ => hsE y) (fun _ hy => le_of_lt (not_le.mp hy.2)) + have he : exp (-(1:ℝ)*(n:ℝ)) ≤ exp (-b*(n:ℝ)) := exp_le_exp.mpr (by + have hh := mul_le_mul_of_nonneg_right (min_le_right (α*ν/2) 1) (Nat.cast_nonneg (α := ℝ) n) + dsimp [b]; linarith only [hh]) + have htotal := (lintegral_split_le volume (fun y => ENNReal.ofReal (scalarIntegrand j t σ y)) E B).trans + (add_le_add hc' (htail'.trans (ENNReal.ofReal_le_ofReal he))) + have hadd : ENNReal.ofReal (exp (-b*(n:ℝ)))+ENNReal.ofReal (exp (-b*(n:ℝ))) = + ENNReal.ofReal (2*exp ((n:ℝ)*(-b))) := by + rw [← ENNReal.ofReal_add (exp_pos _).le (exp_pos _).le] + congr 1 + ring_nf + rw [hadd] at htotal + refine htotal.trans (ENNReal.ofReal_le_ofReal ?_) + convert hM n (le_trans (le_max_right _ _) hn) (-b) using 1 + congr 1 + ring + +end SKGap +end +end +end +end +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Gaussian/GaussianCoordinateMemLp.lean b/lean/OAI/Probability/SKGap/Gaussian/GaussianCoordinateMemLp.lean new file mode 100644 index 0000000000000000000000000000000000000000..b755ce6913aacf19ecc19bf6df25d512ff072d90 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Gaussian/GaussianCoordinateMemLp.lean @@ -0,0 +1,109 @@ +import Mathlib +import OAI.Probability.SKGap.Matrix.MatrixCoordinates + +namespace OAI + +section +noncomputable section +open MeasureTheory ProbabilityTheory InformationTheory Real Set +open scoped NNReal ENNReal +open Filter +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius ENNReal NNReal +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius NNReal +noncomputable section +open MeasureTheory ProbabilityTheory Real Set Filter +open MeasureTheory.Measure +open scoped ENNReal NNReal MeasureTheory Topology +open MeasureTheory +noncomputable section +noncomputable section +open MeasureTheory Set NormedSpace +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius +noncomputable section +open Set Real +open scoped Topology +noncomputable section +open Matrix Set Filter +open scoped Topology Matrix.Norms.Frobenius +noncomputable section +open Matrix NormedSpace ContinuousLinearMap +open scoped Matrix.Norms.Frobenius +noncomputable section +open Matrix +namespace SKGap +open MeasureTheory ProbabilityTheory Real +open scoped ENNReal NNReal +variable {ι : Type*} [Fintype ι] + +lemma gaussianCoordinate_memLp (a : MatrixCoordinates ι) : + MemLp (fun g : MatrixCoordinates ι → ℝ => g a) 2 + (Measure.pi (fun _ => gaussianReal 0 1)) := by + exact (IsGaussian.memLp_id (gaussianReal 0 1) 2 (by norm_num)).comp_measurePreserving + (measurePreserving_eval (fun _ : MatrixCoordinates ι => gaussianReal 0 1) a) + +lemma gaussianCoordinate_integral_sq (a : MatrixCoordinates ι) : + (∫ g : MatrixCoordinates ι → ℝ, (g a)^2 ∂Measure.pi (fun _ => gaussianReal 0 1)) = 1 := by + rw [integral_comp_eval (μ := fun _ : MatrixCoordinates ι => gaussianReal 0 1) (i := a) (by fun_prop : AEStronglyMeasurable (fun x : ℝ => x^2) (gaussianReal 0 1))] + have hh := variance_fun_id_gaussianReal (μ := 0) (v := 1) + rw [variance_eq_integral (by fun_prop),integral_id_gaussianReal] at hh + simpa only [sub_zero,NNReal.coe_one] using hh + +lemma goeEntry_memLp (r : ℝ) (i b : ι) : + MemLp (fun g => goeMatrix r g i b) 2 + (Measure.pi (fun _ : MatrixCoordinates ι => gaussianReal 0 1)) := by + exact ((gaussianCoordinate_memLp (.inl (i,b))).add + (gaussianCoordinate_memLp (.inl (b,i)))).const_mul _ + +lemma goeEntry_integral_sq_le {r : ℝ} (hr : 0 ≤ r) (i b : ι) : + (∫ g, (goeMatrix r g i b)^2 + ∂Measure.pi (fun _ : MatrixCoordinates ι => gaussianReal 0 1)) ≤ 2*r := by + let μ := Measure.pi (fun _ : MatrixCoordinates ι => gaussianReal 0 1) + have h1 := (gaussianCoordinate_memLp (.inl (i,b))).integrable_sq + have h2 := (gaussianCoordinate_memLp (.inl (b,i))).integrable_sq + have hb (g : MatrixCoordinates ι → ℝ) : (goeMatrix r g i b)^2 ≤ + r*((g (.inl (i,b)))^2+(g (.inl (b,i)))^2) := by + have hx : (g (.inl (i,b))+g (.inl (b,i)))^2 ≤ + 2*((g (.inl (i,b)))^2+(g (.inl (b,i)))^2) := by + nlinarith only [sq_nonneg (g (.inl (i,b))-g (.inl (b,i)))] + simp only [goeMatrix,mul_pow] + calc + _ ≤ (sqrt (2*r)/2)^2*(2*((g (.inl (i,b)))^2+(g (.inl (b,i)))^2)) := + mul_le_mul_of_nonneg_left hx (sq_nonneg _) + _ = _ := by rw [div_pow,sq_sqrt (by positivity)]; ring + calc + _ ≤ ∫ g, r*((g (.inl (i,b)))^2+(g (.inl (b,i)))^2) ∂μ := + integral_mono (goeEntry_memLp r i b).integrable_sq ((h1.add h2).const_mul r) hb + _ = 2*r := by + rw [integral_const_mul,integral_add h1 h2,gaussianCoordinate_integral_sq, + gaussianCoordinate_integral_sq] + ring + +end SKGap + +noncomputable section +open MeasureTheory ProbabilityTheory Real Set +open scoped ENNReal NNReal + +end +end +end +end +end +end +end +end +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Gaussian/GaussianCoordinates.lean b/lean/OAI/Probability/SKGap/Gaussian/GaussianCoordinates.lean new file mode 100644 index 0000000000000000000000000000000000000000..9da8e7547cc72dd0febf01c5fd5a9c35bf6f4511 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Gaussian/GaussianCoordinates.lean @@ -0,0 +1,187 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.FiniteMax + +namespace OAI + +section +noncomputable section +open MeasureTheory ProbabilityTheory InformationTheory Real Set +open scoped NNReal ENNReal +open Filter +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius ENNReal NNReal +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius NNReal +noncomputable section +open MeasureTheory ProbabilityTheory Real Set Filter +open MeasureTheory.Measure +open scoped ENNReal NNReal MeasureTheory Topology +open MeasureTheory +noncomputable section +noncomputable section +open MeasureTheory Set NormedSpace +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius +noncomputable section +open Set Real +open scoped Topology +noncomputable section +open Matrix Set Filter +open scoped Topology Matrix.Norms.Frobenius +noncomputable section +open Matrix NormedSpace ContinuousLinearMap +open scoped Matrix.Norms.Frobenius +noncomputable section +open Matrix +noncomputable section +open MeasureTheory ProbabilityTheory Real Set +open scoped ENNReal NNReal +noncomputable section +open MeasureTheory ProbabilityTheory InformationTheory Real Set +open scoped NNReal ENNReal +namespace SKGap +section ArbitraryCoordinates +variable {I κ : Type*} [TopologicalSpace I] [CompactSpace I] [Nonempty I] + [Fintype κ] + +def gaussianCoordinates (κ : Type*) [Fintype κ] : Measure (κ → ℝ) := + Measure.pi (fun _ => gaussianReal 0 1) + +instance : IsProbabilityMeasure (gaussianCoordinates κ) := by + unfold gaussianCoordinates + infer_instance + +def gaussianAffine (m : I → ℝ) (a : I → κ → ℝ) (z : κ → ℝ) (i : I) : ℝ := + m i + ∑ k, a i k * z k + +def gaussianSup (m : I → ℝ) (a : I → κ → ℝ) (z : κ → ℝ) : ℝ := + sSup (Set.range (gaussianAffine m a z)) + +omit [CompactSpace I] [Nonempty I] in + theorem continuous_gaussianAffine {m : I → ℝ} {a : I → κ → ℝ} + (hm : Continuous m) (ha : Continuous a) (z : κ → ℝ) : + Continuous (gaussianAffine m a z) := + hm.add (continuous_finsetSum _ (fun k _ => + ((continuous_apply k).comp ha).mul continuous_const)) + +theorem gaussianSup_attained {m : I → ℝ} {a : I → κ → ℝ} + (hm : Continuous m) (ha : Continuous a) (z : κ → ℝ) : + ∃ i, gaussianSup m a z = gaussianAffine m a z i ∧ + ∀ j, gaussianAffine m a z j ≤ gaussianAffine m a z i := by + obtain ⟨i, _, he, hi⟩ := isCompact_univ.exists_sSup_image_eq_and_ge + Set.univ_nonempty (continuous_gaussianAffine hm ha z).continuousOn + exact ⟨i, by simpa [gaussianSup] using he, fun j => hi j (Set.mem_univ _)⟩ + +theorem gaussianSup_le {m : I → ℝ} {a : I → κ → ℝ} + (hm : Continuous m) (ha : Continuous a) (z : κ → ℝ) {c : ℝ} + (hc : ∀ i, gaussianAffine m a z i ≤ c) : gaussianSup m a z ≤ c := by + obtain ⟨i, he, _⟩ := gaussianSup_attained hm ha z + rw [he] + exact hc i + +omit [Nonempty I] in + theorem continuous_gaussianSup {m : I → ℝ} {a : I → κ → ℝ} + (hm : Continuous m) (ha : Continuous a) : Continuous (gaussianSup m a) := by + have hc : Continuous (fun p : (κ → ℝ) × I => gaussianAffine m a p.1 p.2) := by + exact (hm.comp continuous_snd).add (continuous_finsetSum _ (fun k _ => + (((continuous_apply k).comp ha).comp continuous_snd).mul + ((continuous_apply k).comp continuous_fst))) + change Continuous (fun z => sSup (Set.range (gaussianAffine m a z))) + simpa only [Set.image_univ] using isCompact_univ.continuous_sSup hc + +theorem integrable_gaussianSup {m : I → ℝ} {a : I → κ → ℝ} + (hm : Continuous m) (ha : Continuous a) : + Integrable (gaussianSup m a) (gaussianCoordinates κ) := by + obtain ⟨M, hM⟩ := isCompact_univ.exists_bound_of_continuousOn hm.continuousOn + obtain ⟨A, hA⟩ := isCompact_univ.exists_bound_of_continuousOn ha.continuousOn + have hMb : ∀ i, |m i| ≤ M := fun i => by + simpa only [Real.norm_eq_abs] using hM i (Set.mem_univ _) + have hAb : ∀ i k, |a i k| ≤ A := by + intro i k + have hk : |a i k| ≤ ‖a i‖ := by + simpa only [Real.norm_eq_abs] using norm_le_pi_norm (a i) k + exact hk.trans (hA i (Set.mem_univ _)) + apply ((integrable_const M).add ((integrable_finsetSum (Finset.univ : Finset κ) (fun k _ => + ((integrable_eval (i := k) IsGaussian.integrable_id).norm))).const_mul A)).mono' + (continuous_gaussianSup hm ha).aestronglyMeasurable + apply Filter.Eventually.of_forall + intro z + obtain ⟨i, he, _⟩ := gaussianSup_attained hm ha z + rw [he, Real.norm_eq_abs] + change |gaussianAffine m a z i| ≤ M + A * ∑ k, |z k| + calc + _ ≤ |m i| + |∑ k, a i k * z k| := abs_add_le _ _ + _ ≤ M + ∑ k, |a i k * z k| := + add_le_add (hMb i) (Finset.abs_sum_le_sum_abs _ _) + _ ≤ M + ∑ k, A * |z k| := by + gcongr with k + rw [abs_mul] + exact mul_le_mul_of_nonneg_right (hAb i k) (abs_nonneg _) + _ = _ := by rw [Finset.mul_sum] + +theorem gaussianSup_comparison [Nonempty κ] {m : I → ℝ} {a b : I → κ → ℝ} + (hm : Continuous m) (ha : Continuous a) (hb : Continuous b) + (horth : ∀ i j, ∑ k, (a i k - a j k) * (b i k - b j k) = 0) + (hinc : ∀ i j, (∑ k, (b i k - b j k)^2) ≤ ∑ k, (a i k - a j k)^2) : + (∫ z, gaussianSup m b z ∂gaussianCoordinates κ) ≤ + ∫ z, gaussianSup m a z ∂gaussianCoordinates κ := by + obtain ⟨n, hn⟩ := Nat.exists_eq_succ_of_ne_zero (Fintype.card_ne_zero (α := κ)) + let e : Fin (n + 1) ≃ κ := (finCongr hn.symm).trans (Fintype.equivFin κ).symm + let E := MeasurableEquiv.piCongrLeft (fun _ : κ => ℝ) e + let a' : I → Fin (n + 1) → ℝ := fun i k => a i (e k) + let b' : I → Fin (n + 1) → ℝ := fun i k => b i (e k) + have ha' : Continuous a' := continuous_pi (fun k => (continuous_apply (e k)).comp ha) + have hb' : Continuous b' := continuous_pi (fun k => (continuous_apply (e k)).comp hb) + have he (f : κ → ℝ) : ∑ k : Fin (n + 1), f (e k) = ∑ k : κ, f k := e.sum_comp f + have horth' (i j : I) : ∑ k, (a' i k - a' j k) * (b' i k - b' j k) = 0 := by + dsimp [a', b'] + rw [he (fun k => (a i k - a j k) * (b i k - b j k))] + exact horth i j + have hinc' (i j : I) : (∑ k, (b' i k - b' j k)^2) ≤ ∑ k, (a' i k - a' j k)^2 := by + dsimp [a', b'] + rw [he (fun k => (b i k - b j k)^2), he (fun k => (a i k - a j k)^2)] + exact hinc i j + have hpres : MeasurePreserving E (standardGaussianProduct (n + 1)) (gaussianCoordinates κ) := + measurePreserving_piCongrLeft (fun _ => gaussianReal 0 1) e + have hpoint (c : I → κ → ℝ) (z : Fin (n + 1) → ℝ) : + gaussianSup m c (E z) = supProcess m (fun i k => c i (e k)) z := by + unfold gaussianSup supProcess + congr 1 + congr 1 + funext i + dsimp [gaussianAffine, affineProcess] + rw [← he (fun k => c i k * E z k)] + simp [E, MeasurableEquiv.piCongrLeft, Equiv.piCongrLeft] + rw [← hpres.integral_comp' (gaussianSup m b), ← hpres.integral_comp' (gaussianSup m a)] + simp_rw [hpoint] + exact gaussian_supProcess_comparison hm ha' hb' horth' hinc' + +end ArbitraryCoordinates +end SKGap + +noncomputable section +open scoped BigOperators +open MeasureTheory ProbabilityTheory + +end +end +end +end +end +end +end +end +end +end +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Gaussian/GaussianDisintegration.lean b/lean/OAI/Probability/SKGap/Gaussian/GaussianDisintegration.lean new file mode 100644 index 0000000000000000000000000000000000000000..f55aaa499daf3a5e23f09dba2ecc49ae775aeec7 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Gaussian/GaussianDisintegration.lean @@ -0,0 +1,56 @@ +import Mathlib +import OAI.Probability.SKGap.Gaussian.GaussianRegression + +namespace OAI + +section + +noncomputable section +open MeasureTheory ProbabilityTheory Matrix +open scoped BigOperators ENNReal +namespace SKGap.GaussianRegression + +lemma residual_joint_gaussian {Ω ι κ : Type*} [MeasurableSpace Ω] + [Fintype ι] [Fintype κ] {P : Measure Ω} {X : Ω → ι → ℝ} {Y : Ω → κ → ℝ} + (hXY : HasGaussianLaw (fun w => (X w,Y w)) P) (K : Matrix ι κ ℝ) : + HasGaussianLaw (fun w => (X w-K*ᵥ Y w,Y w)) P := + hXY.map_fun (((ContinuousLinearMap.fst ℝ (ι → ℝ) (κ → ℝ))- + (matrixCLM K).comp (ContinuousLinearMap.snd ℝ (ι → ℝ) (κ → ℝ))).prod + (ContinuousLinearMap.snd ℝ (ι → ℝ) (κ → ℝ))) + +theorem regression_joint_law {Ω ι κ : Type*} [MeasurableSpace Ω] + [Fintype ι] [Fintype κ] {P : Measure Ω} {X : Ω → ι → ℝ} {Y : Ω → κ → ℝ} + (hXY : HasGaussianLaw (fun w => (X w,Y w)) P) (K : Matrix ι κ ℝ) + (hcov : ∀ i k, cov[fun w => X w i, fun w => Y w k; P] = + ∑ l, K i l * cov[fun w => Y w l,fun w => Y w k; P]) : + P.map (fun w => (X w,Y w)) = + ((P.map (fun w => X w-K*ᵥ Y w)).prod (P.map Y)).map + (fun z : (ι → ℝ) × (κ → ℝ) => (z.1+K*ᵥ z.2,z.2)) := by + have := hXY.isProbabilityMeasure + have hR := residual_joint_gaussian hXY K + have hi := residual_independent hXY K hcov + rw [← hi.map_prod_eq_prod_map_map hR.fst.aemeasurable hR.snd.aemeasurable, + AEMeasurable.map_map_of_aemeasurable (by fun_prop) hR.aemeasurable] + congr 1 + funext w + simp only [Function.comp_apply,sub_add_cancel] + +theorem regression_lintegral {Ω ι κ : Type*} [MeasurableSpace Ω] + [Fintype ι] [Fintype κ] {P : Measure Ω} {X : Ω → ι → ℝ} {Y : Ω → κ → ℝ} + (hXY : HasGaussianLaw (fun w => (X w,Y w)) P) (K : Matrix ι κ ℝ) + (hcov : ∀ i k, cov[fun w => X w i, fun w => Y w k; P] = + ∑ l, K i l * cov[fun w => Y w l,fun w => Y w k; P]) + (F : (ι → ℝ) × (κ → ℝ) → ℝ≥0∞) (hF : Measurable F) : + (∫⁻ w, F (X w,Y w) ∂P) = + ∫⁻ y, ∫⁻ r, F (r+K*ᵥ y,y) ∂P.map (fun w => X w-K*ᵥ Y w) ∂P.map Y := by + have := hXY.isProbabilityMeasure + rw [← lintegral_map' hF.aemeasurable hXY.aemeasurable, + regression_joint_law hXY K hcov,lintegral_map (by fun_prop) (by fun_prop), + lintegral_prod_symm] + fun_prop + +end SKGap.GaussianRegression +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Gaussian/GaussianFiniteIBPError.lean b/lean/OAI/Probability/SKGap/Gaussian/GaussianFiniteIBPError.lean new file mode 100644 index 0000000000000000000000000000000000000000..4403930b6dc8b10e67e40496826d73bd8098e351 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Gaussian/GaussianFiniteIBPError.lean @@ -0,0 +1,43 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.CoordinateDeriv + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory InformationTheory Real Set +open scoped NNReal ENNReal +open Filter +open scoped Topology +namespace SKGap +variable {κ : Type*} [Fintype κ] [DecidableEq κ] + +theorem gaussianFinite_IBP_error (i : κ) + {f d : (κ → ℝ) → ℝ} {L : ℝ≥0} {C D : ℝ} {s : Set (κ → ℝ)} + (hf : LipschitzWith L f) (hC : ∀ x, ‖f x‖ ≤ C) + (hd : Measurable d) (hD : ∀ x, ‖d x‖ ≤ D) (hs : MeasurableSet s) + (hder : ∀ x ∈ s, HasDerivAt (fun z => f (Function.update x i z)) (d x) (x i)) : + |(∫ x, x i*f x ∂Measure.pi (fun _ : κ => gaussianReal 0 1))- + ∫ x, d x ∂Measure.pi (fun _ : κ => gaussianReal 0 1)| ≤ + ((L:ℝ)+D)*(Measure.pi (fun _ : κ => gaussianReal 0 1)).real sᶜ := by + let μ := Measure.pi (fun _ : κ => gaussianReal 0 1) + have hi : Integrable (finiteCoordinateDeriv i f) μ := + Integrable.of_bound (measurable_finiteCoordinateDeriv i hf.continuous).aestronglyMeasurable + (L:ℝ) (ae_of_all _ (norm_finiteCoordinateDeriv_le i hf)) + have hid : Integrable d μ := Integrable.of_bound hd.aestronglyMeasurable D (ae_of_all _ hD) + rw [gaussianFinite_lipschitz_IBP i hf hC,← integral_sub hi hid] + have he : (fun x => finiteCoordinateDeriv i f x-d x) = + sᶜ.indicator (fun x => finiteCoordinateDeriv i f x-d x) := by + funext x + by_cases hx : x ∈ s + · simp only [Set.indicator_of_notMem (show x ∉ sᶜ by simpa using hx),finiteCoordinateDeriv] + rw [(hder x hx).deriv,sub_self] + · rw [Set.indicator_of_mem hx] + rw [he,integral_indicator hs.compl] + exact norm_setIntegral_le_of_norm_le_const (measure_lt_top μ sᶜ) (fun x _ => + (norm_sub_le _ _).trans (add_le_add (norm_finiteCoordinateDeriv_le i hf x) (hD x))) + +end SKGap + +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Gaussian/GaussianGramMomentsJoined.lean b/lean/OAI/Probability/SKGap/Gaussian/GaussianGramMomentsJoined.lean new file mode 100644 index 0000000000000000000000000000000000000000..ce16895453d0a3f8c21d810e5134cad3c3ac541b --- /dev/null +++ b/lean/OAI/Probability/SKGap/Gaussian/GaussianGramMomentsJoined.lean @@ -0,0 +1,197 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.FiniteRankPositive +import OAI.Probability.SKGap.Localization.ScalarFixedPointJoined + +namespace OAI + +section + +noncomputable section +open MeasureTheory ProbabilityTheory InformationTheory Real Set +open scoped NNReal ENNReal +namespace SKGap + +end SKGap + +namespace SKGap + +def scalarGramVariance (y : ℝ) := 1-tanh y^2 + +def spinMixed (y : ℝ) := tanh y^2*scalarGramVariance y + +lemma spinVariance_nonneg (y : ℝ) : 0 ≤ scalarGramVariance y := + sub_nonneg.mpr (tanh_sq_lt_one y).le + +lemma abs_spinVariance_le_one (y : ℝ) : |scalarGramVariance y| ≤ 1 := by + rw [abs_of_nonneg (spinVariance_nonneg y)] + unfold scalarGramVariance + nlinarith [sq_nonneg (tanh y)] + +lemma abs_spinMixed_le_one (y : ℝ) : |spinMixed y| ≤ 1 := by + unfold spinMixed + rw [abs_mul,abs_of_nonneg (sq_nonneg _)] + calc + _ ≤ 1*1 := mul_le_mul (tanh_sq_lt_one y).le (abs_spinVariance_le_one y) (abs_nonneg _) zero_le_one + _ = 1 := one_mul 1 + +lemma integrable_spinVariance {μ : Measure ℝ} [IsFiniteMeasure μ] : Integrable scalarGramVariance μ := + Integrable.of_bound (by unfold scalarGramVariance; fun_prop) 1 + (ae_of_all _ (fun y => by simpa only [Real.norm_eq_abs] using abs_spinVariance_le_one y)) + +lemma integrable_spinMixed {μ : Measure ℝ} [IsFiniteMeasure μ] : Integrable spinMixed μ := + Integrable.of_bound (by unfold spinMixed scalarGramVariance; fun_prop) 1 + (ae_of_all _ (fun y => by simpa only [Real.norm_eq_abs] using abs_spinMixed_le_one y)) + +lemma gaussian_nishimori_variance (s : ℝ≥0) : + (∫ y, oddVariance y ∂gaussianReal s s) = ∫ y, spinMixed y ∂gaussianReal s s := by + by_cases hs : s = 0 + · subst s; simp [oddVariance,spinMixed,scalarGramVariance] + have hi := (integrable_gaussian_iff hs).mp + (integrable_oddVariance.sub (integrable_spinMixed (μ := gaussianReal s s))) + let f : ℝ → ℝ := fun y => gaussianPDFReal s s y*(oddVariance y-spinMixed y) + have hf : Integrable f := hi + have hid (y : ℝ) : f y+f (-y) = 0 := by + have hh := gaussianPDFReal_diagonal_symmetry hs y + dsimp [f,oddVariance,spinMixed,scalarGramVariance] + rw [tanh_neg,neg_sq] + nlinarith [congrArg (fun x => tanh y*(1-tanh y^2)*x) hh] + have hz : (∫ y, f y)+(∫ y, f (-y)) = 0 := by + rw [← integral_add hf hf.comp_neg] + simp only [hid,integral_zero] + rw [integral_neg_eq_self] at hz + have hsub : ∫ y, oddVariance y-spinMixed y ∂gaussianReal s s = 0 := by + rw [integral_gaussianReal_eq_integral_smul hs] + change (∫ y, f y) = 0 + linarith + rw [integral_sub integrable_oddVariance integrable_spinMixed] at hsub + exact sub_eq_zero.mp hsub + +lemma hasDerivAt_spinVariance (y : ℝ) : HasDerivAt scalarGramVariance (-2*oddVariance y) y := by + convert! (hasDerivAt_const y (1:ℝ)).sub ((hasDerivAt_tanh y).pow 2) using 1 + simp only [oddVariance]; norm_num; ring + +lemma hasDerivAt_oddVariance (y : ℝ) : + HasDerivAt oddVariance (scalarGramVariance y-3*spinMixed y) y := by + convert! (hasDerivAt_tanh y).mul (hasDerivAt_spinVariance y) using 1 + simp only [spinMixed,scalarGramVariance,oddVariance]; ring + +lemma integrable_center_spinVariance (d : ℝ) (s : ℝ≥0) : + Integrable (fun y => (y-d)*scalarGramVariance y) (gaussianReal d s) := by + have h := ((IsGaussian.integrable_id (μ := gaussianReal d s)).sub (integrable_const d)).bdd_mul (f := scalarGramVariance) + (by unfold scalarGramVariance; fun_prop) (c := 1) + (ae_of_all _ (fun y => by simpa only [Real.norm_eq_abs] using abs_spinVariance_le_one y)) + simpa only [mul_comm,Pi.sub_apply,id_eq] using h + +lemma integrable_center_oddVariance (d : ℝ) (s : ℝ≥0) : + Integrable (fun y => (y-d)*oddVariance y) (gaussianReal d s) := by + have h := ((IsGaussian.integrable_id (μ := gaussianReal d s)).sub (integrable_const d)).bdd_mul (f := oddVariance) + (by unfold oddVariance; fun_prop) (c := 1) + (ae_of_all _ (fun y => by simpa only [Real.norm_eq_abs] using abs_oddVariance_le_one y)) + simpa only [mul_comm,Pi.sub_apply,id_eq] using h + +lemma integrable_center_sq_spinVariance (d : ℝ) (s : ℝ≥0) : + Integrable (fun y => (y-d)^2*scalarGramVariance y) (gaussianReal d s) := by + have hmem : MemLp (fun y : ℝ => y-d) 2 (gaussianReal d s) := + (IsGaussian.memLp_id (gaussianReal d s) 2 (by norm_num)).sub (memLp_const d) + have h := hmem.integrable_sq.bdd_mul (f := scalarGramVariance) + (by unfold scalarGramVariance; fun_prop) (c := 1) + (ae_of_all _ (fun y => by simpa only [Real.norm_eq_abs] using abs_spinVariance_le_one y)) + simpa only [mul_comm,Pi.sub_apply,id_eq] using h + +theorem gaussian_weighted_gram_moments {s : ℝ≥0} (hs : 0 < s) : + (∫ y, (y-(s:ℝ))*scalarGramVariance y ∂gaussianReal s s) = + -2*(s:ℝ)*(∫ y, spinMixed y ∂gaussianReal s s) ∧ + (∫ y, (y-(s:ℝ))*oddVariance y ∂gaussianReal s s) = + (s:ℝ)*((∫ y, scalarGramVariance y ∂gaussianReal s s)-3*(∫ y, spinMixed y ∂gaussianReal s s)) ∧ + (∫ y, (y-(s:ℝ))^2*scalarGramVariance y ∂gaussianReal s s) = + (s:ℝ)*(∫ y, scalarGramVariance y ∂gaussianReal s s)+ + (s:ℝ)^2*(-2*(∫ y, scalarGramVariance y ∂gaussianReal s s)+6*(∫ y, spinMixed y ∂gaussianReal s s)) := by + have h1 := gaussian_integration_by_parts hs.ne' hasDerivAt_spinVariance + integrable_spinVariance (integrable_oddVariance.const_mul (-2)) + (integrable_center_spinVariance s s) + rw [integral_const_mul,gaussian_nishimori_variance] at h1 + have h2 := gaussian_integration_by_parts hs.ne' hasDerivAt_oddVariance + integrable_oddVariance (integrable_spinVariance.sub (integrable_spinMixed.const_mul 3)) + (integrable_center_oddVariance s s) + rw [integral_sub integrable_spinVariance (integrable_spinMixed.const_mul 3),integral_const_mul] at h2 + have hder (y : ℝ) : HasDerivAt (fun y => (y-(s:ℝ))*scalarGramVariance y) + (scalarGramVariance y-2*((y-(s:ℝ))*oddVariance y)) y := by + convert! ((hasDerivAt_id y).sub_const (s:ℝ)).mul (hasDerivAt_spinVariance y) using 1 + simp only [id_eq,one_mul]; ring + have h3 := gaussian_integration_by_parts hs.ne' hder (integrable_center_spinVariance s s) + (integrable_spinVariance.sub ((integrable_center_oddVariance s s).const_mul 2)) + ((integrable_center_sq_spinVariance s s).congr (ae_of_all _ (fun y => by ring))) + have h3' : (∫ y, (y-(s:ℝ))^2*scalarGramVariance y ∂gaussianReal s s) = + (s:ℝ)*((∫ y, scalarGramVariance y ∂gaussianReal s s)-2*(∫ y, (y-(s:ℝ))*oddVariance y ∂gaussianReal s s)) := by + convert h3 using 1 + · congr 1; funext y; ring + · rw [integral_sub integrable_spinVariance ((integrable_center_oddVariance s s).const_mul 2),integral_const_mul] + refine ⟨?_,h2,?_⟩ + · linarith [h1] + · rw [h3',h2]; ring + +end SKGap +end +end + +section +noncomputable section +namespace SKGap +open Real Matrix MeasureTheory ProbabilityTheory +open scoped NNReal BigOperators + +def scalarGramVector (s y : ℝ) : Fin 3 → ℝ := ![1,tanh y,(y-s)/s] + +theorem gaussian_weighted_gram_matrix {s : ℝ≥0} (hs : 0 < s) : + (fun i k : Fin 3 => ∫ y, scalarGramVariance y*scalarGramVector s y i*scalarGramVector s y k + ∂gaussianReal s s)= + limitingGram (∫ y,scalarGramVariance y ∂gaussianReal s s) + (∫ y,spinMixed y ∂gaussianReal s s) s := by + have hsR : (s:ℝ) ≠ 0 := by exact_mod_cast hs.ne' + obtain ⟨h1,h2,h3⟩ := gaussian_weighted_gram_moments hs + have h01 : (∫ y,scalarGramVariance y*tanh y ∂gaussianReal s s)=∫ y,spinMixed y ∂gaussianReal s s := by + convert gaussian_nishimori_variance s using 1 + congr 1; funext y; unfold oddVariance scalarGramVariance; ring + have h02 : (∫ y,scalarGramVariance y*((y-(s:ℝ))/(s:ℝ)) ∂gaussianReal s s)= + -2*(∫ y,spinMixed y ∂gaussianReal s s) := by + calc + _ = (∫ y,(y-(s:ℝ))*scalarGramVariance y ∂gaussianReal s s)/(s:ℝ) := by + rw [← integral_div]; congr 1; funext y; ring + _ = _ := by rw [h1]; field_simp + have h11 : (∫ y,scalarGramVariance y*tanh y*tanh y ∂gaussianReal s s)= + ∫ y,spinMixed y ∂gaussianReal s s := by + congr 1; funext y; unfold spinMixed; ring + have h12 : (∫ y,scalarGramVariance y*tanh y*((y-(s:ℝ))/(s:ℝ)) ∂gaussianReal s s)= + (∫ y,scalarGramVariance y ∂gaussianReal s s)-3*(∫ y,spinMixed y ∂gaussianReal s s) := by + calc + _ = (∫ y,(y-(s:ℝ))*oddVariance y ∂gaussianReal s s)/(s:ℝ) := by + rw [← integral_div]; congr 1; funext y; unfold oddVariance scalarGramVariance; ring + _ = _ := by rw [h2]; field_simp + have h22 : (∫ y,scalarGramVariance y*((y-(s:ℝ))/(s:ℝ))*((y-(s:ℝ))/(s:ℝ)) ∂gaussianReal s s)= + (∫ y,scalarGramVariance y ∂gaussianReal s s)/(s:ℝ)- + 2*(∫ y,scalarGramVariance y ∂gaussianReal s s)+6*(∫ y,spinMixed y ∂gaussianReal s s) := by + calc + _ = (∫ y,(y-(s:ℝ))^2*scalarGramVariance y ∂gaussianReal s s)/(s:ℝ)^2 := by + rw [← integral_div]; congr 1; funext y; ring + _ = _ := by rw [h3]; field_simp; ring + have hsym (i k : Fin 3) : + (∫ y,scalarGramVariance y*scalarGramVector s y i*scalarGramVector s y k ∂gaussianReal s s)= + ∫ y,scalarGramVariance y*scalarGramVector s y k*scalarGramVector s y i ∂gaussianReal s s := by + congr 1; funext y; ring + ext i k + fin_cases i <;> fin_cases k + · simp [scalarGramVector,limitingGram] + · simpa [scalarGramVector,limitingGram] using h01 + · simpa [scalarGramVector,limitingGram] using h02 + · simpa [scalarGramVector,limitingGram] using (hsym 1 0).trans (by simpa [scalarGramVector] using h01) + · simpa [scalarGramVector,limitingGram] using h11 + · simpa [scalarGramVector,limitingGram] using h12 + · simpa [scalarGramVector,limitingGram] using (hsym 2 0).trans (by simpa [scalarGramVector] using h02) + · simpa [scalarGramVector,limitingGram] using (hsym 2 1).trans (by simpa [scalarGramVector] using h12) + · simpa [scalarGramVector,limitingGram] using h22 + +end SKGap +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Gaussian/GaussianLinearDensity.lean b/lean/OAI/Probability/SKGap/Gaussian/GaussianLinearDensity.lean new file mode 100644 index 0000000000000000000000000000000000000000..2c04059fb7aae4e6f03fc5c3338be64331467305 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Gaussian/GaussianLinearDensity.lean @@ -0,0 +1,170 @@ +import Mathlib +import OAI.Probability.SKGap.Gaussian.GaussianRegression +import OAI.Probability.SKGap.Localization.EqualityCurve +import OAI.Probability.SKGap.Localization.RankCovariance + +namespace OAI + +section +noncomputable section +namespace SKGap.GaussianDensity +open MeasureTheory ProbabilityTheory Matrix Real +open scoped BigOperators ENNReal NNReal +variable {ι Ω : Type*} [Fintype ι] [DecidableEq ι] [MeasurableSpace Ω] + {P : Measure Ω} {X : Ω → ι → ℝ} + +theorem gaussian_density_of_matrix (hX : HasGaussianLaw X P) (A : Matrix ι ι ℝ) (hA : A.det ≠ 0) + (hm : ∀ i,(∫ w,X w i ∂P)=0) + (hc : ∀ i k,cov[fun w => X w i,fun w => X w k;P]=(A*Aᵀ) i k) : + P.map X=(volume : Measure (ι → ℝ)).withDensity (fun x => ENNReal.ofReal + (|A.det⁻¹| *∏ i,gaussianPDFReal 0 1 ((A⁻¹*ᵥx) i))) := by + have hl : P.map X=(gaussianCoordinates ι).map (fun x => A*ᵥx) := by + apply GaussianRegression.law_eq_of_mean_covariance hX (matrix_sample_gaussian A) + · intro i + rw [hm] + exact (linear_gaussian_mean (A i)).symm + · intro i k + rw [hc,matrix_sample_covariance] + rw [hl] + exact matrix_map_gaussian_density A hA + +lemma gaussian_rankOne_density (hX : HasGaussianLaw X P) {a b : ℝ} (ha : 0 < a) (hb : 0 < b) + {u : ι → ℝ} (hu : u⬝ᵥu=1) (hm : ∀ i,(∫ w,X w i ∂P)=0) + (hc : ∀ i k,cov[fun w => X w i,fun w => X w k;P]= + rankOneTransform (a^2) (b^2) u i k) : + P.map X=(volume : Measure (ι → ℝ)).withDensity (fun x => ENNReal.ofReal + ((a^(Fintype.card ι)*(b/a))⁻¹*∏ i,gaussianPDFReal 0 1 + ((rankOneTransform a⁻¹ b⁻¹ u*ᵥx) i))) := by + have hd : 0 < (rankOneTransform a b u).det := by + rw [rankOneTransform_det ha.ne' b hu] + positivity + have hc' : ∀ i k,cov[fun w => X w i,fun w => X w k;P]= + (rankOneTransform a b u*(rankOneTransform a b u)ᵀ) i k := by + intro i k + rw [hc,rankOneTransform_transpose,rankOneTransform_mul hu] + simp only [← pow_two] + rw [gaussian_density_of_matrix hX _ hd.ne' hm hc', + rankOneTransform_inv ha.ne' hb.ne' hu,abs_of_pos (inv_pos.mpr hd),rankOneTransform_det ha.ne' b hu] + +end SKGap.GaussianDensity +end +end + +section +noncomputable section +namespace SKGap.GaussianDensity +open MeasureTheory ProbabilityTheory Matrix Real +open scoped BigOperators ENNReal NNReal +variable {ι : Type*} [Fintype ι] [DecidableEq ι] + +def radialDensity (a : ℝ) (x : ι → ℝ) : ℝ := + ((sqrt (2*Real.pi)*a)⁻¹)^(Fintype.card ι)*exp (-(x⬝ᵥx)/(2*a^2)) + +omit [DecidableEq ι] in +lemma product_gaussianPDF_formula (v : ℝ≥0) (x : ι → ℝ) : + (∏ i,gaussianPDFReal 0 v (x i))=(sqrt (2*Real.pi*v))⁻¹^(Fintype.card ι)* + exp (-(x⬝ᵥx)/(2*v)) := by + simp only [gaussianPDFReal,sub_zero,Finset.prod_mul_distrib,Finset.prod_const, + Finset.card_univ,← exp_sum,← Finset.sum_div,← Finset.sum_neg_distrib,dotProduct,← pow_two] + +omit [DecidableEq ι] in +lemma product_gaussianPDF_radial {a : ℝ} (ha : 0 ≤ a) (x : ι → ℝ) : + (∏ i,gaussianPDFReal 0 (NNReal.mk (a^2) (sq_nonneg a)) (x i))=radialDensity a x := by + rw [product_gaussianPDF_formula] + simp only [NNReal.coe_mk,radialDensity,sqrt_mul (by positivity : 0 ≤ 2*Real.pi),sqrt_sq ha] + +lemma rankOne_density_radial {a b : ℝ} (ha : a ≠ 0) (hb : b ≠ 0) + {u : ι → ℝ} (hu : u⬝ᵥu=1) (x : ι → ℝ) : + (a^(Fintype.card ι)*(b/a))⁻¹*(∏ i,gaussianPDFReal 0 1 + ((rankOneTransform a⁻¹ b⁻¹ u*ᵥx) i)) = + (a/b)*radialDensity a x*exp ((b^2-a^2)/(2*a^2*b^2)*(u⬝ᵥx)^2) := by + rw [product_gaussianPDF_formula,rankOneTransform_norm_sq hu] + simp only [NNReal.coe_one,mul_one] + have he : -(a⁻¹^2*(x⬝ᵥx)+(b⁻¹^2-a⁻¹^2)*(u⬝ᵥx)^2)/2 = + -(x⬝ᵥx)/(2*a^2)+(b^2-a^2)/(2*a^2*b^2)*(u⬝ᵥx)^2 := by + field_simp + ring + rw [he,exp_add] + unfold radialDensity + have hc : (a^(Fintype.card ι)*(b/a))⁻¹*(sqrt (2*Real.pi))⁻¹^(Fintype.card ι)= + (a/b)*((sqrt (2*Real.pi)*a)⁻¹)^(Fintype.card ι) := by + simp only [_root_.mul_inv_rev,mul_pow,inv_pow,inv_inv,div_eq_mul_inv] + ring + rw [← mul_assoc,← mul_assoc,hc] + ring + +end SKGap.GaussianDensity +end +end + +section +noncomputable section +namespace SKGap.GaussianDensity +open MeasureTheory ProbabilityTheory Matrix Real +open scoped BigOperators ENNReal NNReal +variable {ι Ω : Type*} [Fintype ι] [DecidableEq ι] [MeasurableSpace Ω] + {P : Measure Ω} {X : Ω → ι → ℝ} + +def rankOneDensity (s r : ℝ) (m x : ι → ℝ) : ℝ := + sqrt (s/(s+r*(m⬝ᵥm)))*radialDensity (sqrt s) x* + exp (r/(2*s*(s+r*(m⬝ᵥm)))*(m⬝ᵥx)^2) + +omit [Fintype ι] in +lemma rankOne_scaled_covariance (s r c : ℝ) (u : ι → ℝ) : + rankOneCovariance s r (c • u)=rankOneTransform s (s+r*c^2) u := by + ext i k + simp only [rankOneCovariance,rankOneTransform,Matrix.add_apply,Matrix.smul_apply, + smul_eq_mul,Matrix.vecMulVec_apply,Pi.smul_apply] + ring + +lemma scaled_unit_exists [Nonempty ι] (m : ι → ℝ) : + ∃ (c : ℝ) (u : ι → ℝ), 0 ≤ c ∧ u⬝ᵥu=1 ∧ m=c • u := by + by_cases hm : m=0 + · let i : ι := Classical.choice inferInstance + refine ⟨0,Pi.single i 1,le_rfl,?_,by simp [hm]⟩ + simp [dotProduct,Pi.single_apply] + · have hq : 0 < m⬝ᵥm := lt_of_le_of_ne + (Finset.sum_nonneg (fun i _ => mul_self_nonneg (m i))) + (Ne.symm (mt dotProduct_self_eq_zero.mp hm)) + have hc : 0 < sqrt (m⬝ᵥm) := sqrt_pos.mpr hq + refine ⟨sqrt (m⬝ᵥm),(sqrt (m⬝ᵥm))⁻¹ • m,hc.le,?_,?_⟩ + · simp only [smul_dotProduct,dotProduct_smul,smul_eq_mul] + have hh := sq_sqrt hq.le + field_simp + nlinarith + · simp [smul_smul,hc.ne'] + +theorem gaussian_rankOne_covariance_density [Nonempty ι] + (hX : HasGaussianLaw X P) {s r : ℝ} (hs : 0 < s) (hr : 0 ≤ r) + (m : ι → ℝ) (hm : ∀ i,(∫ w,X w i ∂P)=0) + (hc : ∀ i k,cov[fun w => X w i,fun w => X w k;P]=rankOneCovariance s r m i k) : + P.map X=(volume : Measure (ι → ℝ)).withDensity + (fun x => ENNReal.ofReal (rankOneDensity s r m x)) := by + obtain ⟨c,u,hcpos,hu,rfl⟩ := scaled_unit_exists m + have hS : 0 < s+r*c^2 := add_pos_of_pos_of_nonneg hs (mul_nonneg hr (sq_nonneg c)) + have ha : 0 < sqrt s := sqrt_pos.mpr hs + have hb : 0 < sqrt (s+r*c^2) := sqrt_pos.mpr hS + have hc' : ∀ i k,cov[fun w => X w i,fun w => X w k;P]= + rankOneTransform ((sqrt s)^2) ((sqrt (s+r*c^2))^2) u i k := by + intro i k + rw [sq_sqrt hs.le,sq_sqrt hS.le,hc,rankOne_scaled_covariance] + rw [gaussian_rankOne_density hX ha hb hu hm hc'] + congr 1 + ext x + rw [rankOne_density_radial ha.ne' hb.ne' hu x] + simp only [rankOneDensity,smul_dotProduct,dotProduct_smul,smul_eq_mul,hu,mul_one, + sq_sqrt hs.le,sq_sqrt hS.le] + have hq : c*c=c^2 := by ring + rw [hq] + have hpref : sqrt s/sqrt (s+r*c^2)=sqrt (s/(s+r*c^2)) := (sqrt_div hs.le _).symm + rw [hpref] + congr 2 + congr 1 + field_simp + ring + +end SKGap.GaussianDensity +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Gaussian/GaussianMarginal.lean b/lean/OAI/Probability/SKGap/Gaussian/GaussianMarginal.lean new file mode 100644 index 0000000000000000000000000000000000000000..8ac26e05d20349125b4a5d65d95be49e4f1d4714 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Gaussian/GaussianMarginal.lean @@ -0,0 +1,175 @@ +import Mathlib +import OAI.Probability.SKGap.Posterior.History + +namespace OAI + +namespace SKGap.GaussianHistory +open MeasureTheory ProbabilityTheory Real Set Filter +open scoped BigOperators ENNReal NNReal +open GaussianStep +noncomputable section +variable {n : ℕ} + +lemma pi_gaussian_add (m₁ m₂ : Fin n → ℝ) (v₁ v₂ : ℝ≥0) : + ((Measure.pi fun i => gaussianReal (m₁ i) v₁).prod + (Measure.pi fun i => gaussianReal (m₂ i) v₂)).map + (fun z : (Fin n → ℝ) × (Fin n → ℝ) => fun i => z.1 i+z.2 i) = + Measure.pi (fun i => gaussianReal (m₁ i+m₂ i) (v₁+v₂)) := by + rw [← (measurePreserving_arrowProdEquivProdArrow ℝ ℝ (Fin n) + (fun i => gaussianReal (m₁ i) v₁) (fun i => gaussianReal (m₂ i) v₂)).map_eq] + rw [Measure.map_map (by fun_prop) (MeasurableEquiv.measurable _)] + change (Measure.pi (fun i => (gaussianReal (m₁ i) v₁).prod (gaussianReal (m₂ i) v₂))).map + (fun z i => (z i).1+(z i).2) = _ + rw [Measure.pi_map_pi (f := fun _ (z : ℝ × ℝ) => z.1+z.2) (fun _ => by fun_prop)] + congr 1 + funext i + exact gaussianReal_conv_gaussianReal + +def field (t : ℝ) : {k : ℕ} → History n k → (Fin n → ℝ) + | 0, _ => 0 + | _+1, h => fun i => field t h.1 i+sqrt t*h.2 i + +lemma continuous_field (t : ℝ) : ∀k,Continuous (field (n := n) t (k := k)) + | 0 => continuous_const + | k+1 => (continuous_field t k).comp continuous_fst |>.add + (by fun_prop) + +lemma map_scaled_reference {t : ℝ} (ht : 0≤t) : + (GaussianStep.reference n).map (fun z : Fin n→ℝ => fun i => sqrt t*z i) = + Measure.pi (fun _ : Fin n => gaussianReal 0 (toNNReal t)) := by + unfold GaussianStep.reference + rw [Measure.pi_map_pi (fun _ => by fun_prop)] + congr 1 + funext i + rw [gaussianReal_map_const_mul] + congr 1 + · simp + · apply NNReal.coe_injective + simp [sq_sqrt ht,ht] + +lemma map_field_reference {t : ℝ} (ht : 0≤t) : ∀k, + (reference n k).map (field t (k := k)) = + Measure.pi (fun _ : Fin n => gaussianReal 0 (toNNReal ((k:ℝ)*t))) + | 0 => by + simp only [reference,field,Nat.cast_zero,zero_mul,toNNReal_zero,gaussianReal_zero_var] + rw [Measure.map_dirac' (by fun_prop) ()] + apply (Measure.pi_eq (μ := fun _ : Fin n => Measure.dirac (0:ℝ)) (μ' := Measure.dirac (0:Fin n→ℝ)) ?_).symm + intro s hs + by_cases hx : ∀i:Fin n,(0:ℝ)∈s i + · rw [Measure.dirac_apply_of_mem (by simpa only [mem_univ_pi,Pi.zero_apply] using hx)] + symm + exact Finset.prod_eq_one (fun i _ => Measure.dirac_apply_of_mem (hx i)) + · push Not at hx + obtain ⟨i,hi⟩ := hx + rw [Measure.dirac_apply' _ (MeasurableSet.univ_pi hs), + Set.indicator_of_notMem (by simp only [mem_univ_pi,Pi.zero_apply]; exact not_forall.mpr ⟨i,hi⟩)] + symm + exact Finset.prod_eq_zero (Finset.mem_univ i) + (by rw [Measure.dirac_apply' _ (hs i),Set.indicator_of_notMem hi]) + | k+1 => by + change ((reference n k).prod (GaussianStep.reference n)).map + ((fun z : (Fin n→ℝ) × (Fin n→ℝ) => fun i => z.1 i+z.2 i) ∘ + Prod.map (field t) (fun z : Fin n→ℝ => fun i => sqrt t*z i)) = _ + rw [← Measure.map_map (by fun_prop) ((continuous_field t k).measurable.prodMap (by fun_prop)), ← Measure.map_prod_map + (reference n k) (GaussianStep.reference n) + (continuous_field t k).measurable (by fun_prop), + map_field_reference ht k,map_scaled_reference ht,pi_gaussian_add] + congr 1 + funext i + simp only [zero_add] + congr 1 + rw [←toNNReal_add (mul_nonneg (by positivity) ht) ht] + congr 1 + push_cast + ring + +lemma likelihood_field (t : ℝ) (x : Spin n) : ∀{k : ℕ} (h : History n k), + likelihood t x h = exp ((∑i,spinValue (x i)*field t h i)-(k:ℝ)*t*(n:ℝ)/2) + | 0, _ => by simp [likelihood,field] + | k+1, h => by + rw [likelihood,likelihood_field t x h.1,GaussianStep.likelihood,←exp_add] + congr 1 + simp only [field,Finset.sum_add_distrib,mul_add,Nat.cast_add,Nat.cast_one] + have he : (∑i,spinValue (x i)*(sqrt t*h.2 i)) = sqrt t*∑i,spinValue (x i)*h.2 i := by + rw [Finset.mul_sum] + apply Finset.sum_congr rfl + intro i _ + ring + rw [he] + ring + +lemma map_withDensity_comp {α β : Type*} [MeasurableSpace α] [MeasurableSpace β] + (μ : Measure α) (f : α→β) (g : β→ℝ≥0∞) (hf : Measurable f) (hg : Measurable g) : + (μ.withDensity (g ∘ f)).map f = (μ.map f).withDensity g := by + ext s hs + rw [Measure.map_apply hf hs,withDensity_apply _ (hf hs),withDensity_apply _ hs] + rw [←lintegral_indicator (hf hs),←lintegral_indicator hs, + lintegral_map (hg.indicator hs) hf] + apply lintegral_congr + intro x + by_cases hx : f x∈s <;> simp [hx] + +theorem field_law (p : Prior n) {t : ℝ} (ht : 0≤t) (k : ℕ) : + (law p t k).map (field t) = + ((GaussianStep.reference n).withDensity + (fun z => ENNReal.ofReal (GaussianStep.density p ((k:ℝ)*t) z))).map + (fun z : Fin n→ℝ => fun i => sqrt ((k:ℝ)*t)*z i) := by + let D : (Fin n→ℝ)→ℝ≥0∞ := fun y => ENNReal.ofReal + (∑ x, p x*exp ((∑i,spinValue (x i)*y i)-(k:ℝ)*t*(n:ℝ)/2)) + have hD : Measurable D := by unfold D; fun_prop + have hd : (fun h : History n k => ENNReal.ofReal (density p t h))=D ∘ field t := by + funext h + simp only [density,likelihood_field,Function.comp_def,D] + have hs : (fun z => ENNReal.ofReal (GaussianStep.density p ((k:ℝ)*t) z)) = + D ∘ (fun z : Fin n→ℝ => fun i => sqrt ((k:ℝ)*t)*z i) := by + funext z + unfold D GaussianStep.density GaussianStep.likelihood + dsimp + congr 1 + apply Finset.sum_congr rfl + intro x _ + congr 2 + rw [Finset.mul_sum] + congr 1 + apply Finset.sum_congr rfl + intro i _ + ring + rw [law,hd,hs,map_withDensity_comp _ _ _ (continuous_field t k).measurable hD, + map_withDensity_comp _ _ _ (by fun_prop) hD,map_field_reference ht, + map_scaled_reference (mul_nonneg (by positivity) ht)] + +lemma weight_field (g : Disorder n) (h₀ y : Fin n→ℝ) (x : Spin n) : + weight g (h₀+y) x=weight g h₀ x*exp (∑i,spinValue (x i)*y i) := by + unfold weight hamiltonian + rw [←exp_add] + congr 1 + simp only [Pi.add_apply,add_mul,Finset.sum_add_distrib] + have he : (∑i,y i*spinValue (x i))=∑i,spinValue (x i)*y i := + Finset.sum_congr rfl (fun i _ => mul_comm _ _) + rw [he] + ring + +lemma posterior_gibbs_field (g : Disorder n) (h₀ : Fin n→ℝ) (t : ℝ) + {k : ℕ} (h : History n k) : posterior (gibbsPrior g h₀) t h = gibbsPrior g (h₀+field t h) := by + have he (x : Spin n) : gibbsPrior g h₀ x*likelihood t x h = + (exp (-(k:ℝ)*t*(n:ℝ)/2)/partition g h₀)*weight g (h₀+field t h) x := by + rw [likelihood_field,weight_field] + change (weight g h₀ x/partition g h₀)*exp (_-_) = _ + rw [exp_sub] + have hn : -(k:ℝ)*t*(n:ℝ)/2 = -((k:ℝ)*t*(n:ℝ)/2) := by ring + rw [hn,exp_neg] + ring + have hd : density (gibbsPrior g h₀) t h = + (exp (-(k:ℝ)*t*(n:ℝ)/2)/partition g h₀)*partition g (h₀+field t h) := by + simp only [density,he,←Finset.mul_sum,partition] + apply Prior.ext + funext x + change gibbsPrior g h₀ x*likelihood t x h/density (gibbsPrior g h₀) t h = + weight g (h₀+field t h) x/partition g (h₀+field t h) + rw [he,hd] + exact mul_div_mul_left _ _ (div_ne_zero (exp_ne_zero _) (partition_pos _ _).ne') + +end +end SKGap.GaussianHistory + +end OAI diff --git a/lean/OAI/Probability/SKGap/Gaussian/GaussianMatrixChaining.lean b/lean/OAI/Probability/SKGap/Gaussian/GaussianMatrixChaining.lean new file mode 100644 index 0000000000000000000000000000000000000000..3a249040f13a2818d18d4e5291aae1ed14e3b4a9 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Gaussian/GaussianMatrixChaining.lean @@ -0,0 +1,82 @@ +import Mathlib +import OAI.Probability.SKGap.Gaussian.MatrixNormTail +import OAI.Probability.SKGap.Localization.BoxChaining + +namespace OAI + +section +noncomputable section +namespace SKGap +open Matrix Real MeasureTheory ProbabilityTheory Set Filter +open scoped BigOperators Matrix.Norms.Frobenius Topology +variable {κ α : Type*} [Fintype κ] [Fintype α] [DecidableEq α] + +def gaussianMatrixChainConstant (H B : ℝ) : ℝ := + 5*(matrixNormConstant*H+π*H*sqrt (B+1)) + +lemma gaussianMatrixChain_exponent {H B s : ℝ} (hH : 0F θ x-F η x)) + (hc : ∀ g : κ→ℝ,Continuous (fun θ=>matrixCentered (F θ) (WithLp.toLp 2 g))) + (p : Bool) : + (Measure.pi (fun _ : κ=>gaussianReal 0 1)) + {g | ∃ θ,gaussianMatrixChainConstant H B< matrixWordSeminorm p (matrixCentered (F θ) (WithLp.toLp 2 g))} ≤ + ENNReal.ofReal (3*exp (-(n:ℝ))) := by + let T := π*H*sqrt (B+1) + let b := matrixNormConstant*H+T + have hT : 0 ≤ T := by dsimp [T];positivity + have hC : 0 ≤ matrixNormConstant := zero_le_one.trans matrixNormConstant_bounds.1 + have hb0 : 0 ≤ b := add_nonneg (mul_nonneg hC hH.le) hT + let r : ℕ→ℝ := fun k=>b*((k:ℝ)+1)*(1/2:ℝ)^k + have hsum : HasSum r (b*4) := by + have he : r=(fun k : ℕ=>b*(((k:ℝ)+1)*(1/2:ℝ)^k)) := by + funext k + dsimp [r] + ring + rw [he] + exact arithmetic_half_geometric_hasSum.mul_left b + have hbase (θ : α→Icc (0:ℝ) 1) : (Measure.pi (fun _ : κ=>gaussianReal 0 1)) + {g | b< matrixWordSeminorm p (matrixCentered (F θ) (WithLp.toLp 2 g))} ≤ + ENNReal.ofReal (exp (-(2*(B+1))*(n:ℝ))) := by + have hh := gaussianMatrix_scaled_semnorm_tail hn hH (by norm_num : (0:ℝ)<1) hT + (by norm_num : (0:ℝ) ≤ 1) (F:=F θ) (by simpa only [mul_one] using hF θ) p + rw [gaussianMatrixChain_exponent hH hB] at hh + simpa only [T,b,mul_one,one_pow] using hh + have hincr (k : ℕ) (θ η : α→Icc (0:ℝ) 1) (hθ : dist θ η ≤ 2*(1/4:ℝ)^k) : + (Measure.pi (fun _ : κ=>gaussianReal 0 1)) + {g | r k< matrixWordSeminorm p (matrixCentered (F θ) (WithLp.toLp 2 g)-matrixCentered (F η) (WithLp.toLp 2 g))} ≤ + ENNReal.ofReal (exp (-(2*(B+1))*((k:ℝ)+1)^2*(n:ℝ))) := by + have hh := gaussianMatrix_scaled_semnorm_tail hn hH (by positivity : (0:ℝ)<(1/2:ℝ)^k) hT + (by positivity : 0 ≤ (k:ℝ)+1) (hi k θ η hθ) p + rw [gaussianMatrixChain_exponent hH hB] at hh + simp_rw [matrixCentered_sub (hF θ) (hF η)] at hh + apply (measure_mono (show {g | r k< matrixWordSeminorm p (matrixCentered (F θ) (WithLp.toLp 2 g)-matrixCentered (F η) (WithLp.toLp 2 g))}⊆ + {g | (matrixNormConstant*H+T*((k:ℝ)+1))*(1/2:ℝ)^k< matrixWordSeminorm p (matrixCentered (F θ) (WithLp.toLp 2 g)-matrixCentered (F η) (WithLp.toLp 2 g))} from ?_)).trans hh + intro g hg + change r k<_ at hg + change (matrixNormConstant*H+T*((k:ℝ)+1))*(1/2:ℝ)^k<_ + apply lt_of_le_of_lt _ hg + dsimp [r,b] + apply mul_le_mul_of_nonneg_right _ (by positivity) + nlinarith only [mul_nonneg (mul_nonneg hC hH.le) (Nat.cast_nonneg k)] + have hh := box_chaining_probability (Measure.pi (fun _ : κ=>gaussianReal 0 1)) + (matrixWordSeminorm p) (matrixWordSeminorm_lipschitz p).continuous (matrixWordSeminorm_add p) + (fun θ g=>matrixCentered (F θ) (WithLp.toLp 2 g)) hc hn hB (by linarith : B+1 ≤ 2*(B+1)) + hdim b r (fun k=>by dsimp [r];positivity) hsum.summable hbase hincr + rw [hsum.tsum_eq] at hh + have he : b+b*4=gaussianMatrixChainConstant H B := by dsimp [b,T,gaussianMatrixChainConstant];ring + rwa [he] at hh +end SKGap +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Gaussian/GaussianPDFMoment.lean b/lean/OAI/Probability/SKGap/Gaussian/GaussianPDFMoment.lean new file mode 100644 index 0000000000000000000000000000000000000000..a288c53785eee503cb07804c852131450b549c0c --- /dev/null +++ b/lean/OAI/Probability/SKGap/Gaussian/GaussianPDFMoment.lean @@ -0,0 +1,172 @@ +import Mathlib +import OAI.Probability.SKGap.Gaussian.GaussMoment + +namespace OAI + +section +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open scoped BigOperators +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open scoped BigOperators +open scoped BigOperators NNReal ENNReal +open MeasureTheory Metric Set +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators NNReal ENNReal Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Set +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators ENNReal NNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Matrix +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators ENNReal NNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal +open scoped BigOperators +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise NNReal ENNReal +open scoped BigOperators +open Filter Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal Topology +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Set Matrix +open scoped BigOperators NNReal ENNReal Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open Filter MeasureTheory ProbabilityTheory +open scoped Topology NNReal ENNReal +open Filter MeasureTheory ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter +open scoped Topology NNReal ENNReal +open MeasureTheory Filter ProbabilityTheory +open scoped Topology NNReal ENNReal +namespace SKGapCutoff.Clock + +lemma gaussianPDF_moment (v : ℝ≥0) (y x : ℝ) : + gaussianPDFReal y v x = (Real.sqrt (2*Real.pi*v))⁻¹ * + gaussMoment (1/(2*(v:ℝ))) 0 (x-y) := by + unfold gaussianPDFReal gaussMoment + simp only [pow_zero,one_mul] + congr 2 + ring + +theorem finite_gaussianPDF_approximation {v w : ℝ≥0} (hv : 0 < v) (hw : 0 < w) + (hwv : w ≤ v) {ε : ℝ} (hε : 0 < ε) : + ∃ (s : Finset ℝ) (c : ℝ → ℝ), + (∫ x : ℝ, |gaussianPDFReal 0 w x- + ∑ y ∈ s, c y*gaussianPDFReal (-y) v x|) < ε := by + have hvR : (0:ℝ) < v := hv + have hwR : (0:ℝ) < w := hw + let kv : ℝ := (Real.sqrt (2*Real.pi*v))⁻¹ + let kw : ℝ := (Real.sqrt (2*Real.pi*w))⁻¹ + have hkv : 0 < kv := by dsimp [kv]; positivity + have hkw : 0 < kw := by dsimp [kw]; positivity + have hra : 0 < 1/(2*(v:ℝ)) := by positivity + have hrab : 1/(2*(v:ℝ)) ≤ 1/(2*(w:ℝ)) := by + apply one_div_le_one_div_of_le (by positivity) + exact mul_le_mul_of_nonneg_left (show (w:ℝ) ≤ v from hwv) (by norm_num) + obtain ⟨s,c,hc⟩ := finite_gaussian_approximation hra hrab (show 0 < ε/kw by positivity) + refine ⟨s,fun y => kw*c y/kv,?_⟩ + have he (x : ℝ) : |gaussianPDFReal 0 w x- + ∑ y ∈ s, (kw*c y/kv)*gaussianPDFReal (-y) v x| = + kw*|gaussMoment (1/(2*(w:ℝ))) 0 x- + ∑ y ∈ s, c y*gaussMoment (1/(2*(v:ℝ))) 0 (x+y)| := by + simp only [gaussianPDF_moment,sub_zero,sub_neg_eq_add] + change |kw*gaussMoment (1/(2*(w:ℝ))) 0 x- + ∑ y ∈ s, (kw*c y/kv)*(kv*gaussMoment (1/(2*(v:ℝ))) 0 (x+y))| = _ + have hterm (y : ℝ) : (kw*c y/kv)*(kv*gaussMoment (1/(2*(v:ℝ))) 0 (x+y)) = + kw*(c y*gaussMoment (1/(2*(v:ℝ))) 0 (x+y)) := by field_simp + simp_rw [hterm] + rw [← Finset.mul_sum,← mul_sub,abs_mul,abs_of_pos hkw] + simp_rw [he] + rw [integral_const_mul] + have hh := mul_lt_mul_of_pos_left hc hkw + rwa [mul_div_cancel₀ _ hkw.ne'] at hh + +end SKGapCutoff.Clock + +open MeasureTheory Filter +open scoped Topology + +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Gaussian/GaussianPartition.lean b/lean/OAI/Probability/SKGap/Gaussian/GaussianPartition.lean new file mode 100644 index 0000000000000000000000000000000000000000..d0622f5e3af5b5ff330560e33d0be2870e303c98 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Gaussian/GaussianPartition.lean @@ -0,0 +1,163 @@ +import Mathlib +import OAI.Probability.SKGap.Terminal.SpinEnergy +import OAI.Probability.SKGap.Entropy.GaussianExponentialLinear + +namespace OAI + +section +noncomputable section +namespace SKGap +open MeasureTheory ProbabilityTheory Real +open scoped BigOperators + +def edgeCoefficient {n : ℕ} (r : ℝ) (x : Spin n) : Edge n→ℝ := + fun e=>sqrt r*spinValue (x e.1.1)*spinValue (x e.1.2) + +def gaussianSpinPartition (n : ℕ) (r : ℝ) (g : Disorder n) : ℝ := + ∑ x : Spin n,exp (∑ e,edgeCoefficient r x e*g e) + +lemma gaussianSpinPartition_eq_partition {n : ℕ} (r : ℝ) (g : Disorder n) : + gaussianSpinPartition n r g=partition (fun e=>sqrt r*g e) 0 := by + unfold gaussianSpinPartition partition weight + apply Finset.sum_congr rfl;intro x _ + rw [edge_energy_formula] + congr 1 + apply Finset.sum_congr rfl;intro e _ + unfold edgeCoefficient;ring + +lemma edgeCoefficient_sq_sum {n : ℕ} {r : ℝ} (hr : 0 ≤ r) (x : Spin n) : + (∑ e,edgeCoefficient r x e^2)= r*(Fintype.card (Edge n):ℝ) := by + simp only [edgeCoefficient,mul_pow,spinValue_sq,sq_sqrt hr,mul_one, + Finset.sum_const,Finset.card_univ,nsmul_eq_mul,mul_comm] + +lemma edgeCoefficient_add_sq {n : ℕ} {r : ℝ} (hr : 0 ≤ r) (x y : Spin n) (e : Edge n) : + (edgeCoefficient r x e+edgeCoefficient r y e)^2= + 2*r+2*r*spinValue (spinMul x y e.1.1)*spinValue (spinMul x y e.1.2) := by + have hc : edgeCoefficient r x e*edgeCoefficient r y e= + r*spinValue (spinMul x y e.1.1)*spinValue (spinMul x y e.1.2) := by + rw [spinValue_mul,spinValue_mul] + unfold edgeCoefficient + calc + _ = (sqrt r)^2*spinValue (x e.1.1)*spinValue (y e.1.1)*spinValue (x e.1.2)*spinValue (y e.1.2) := by ring + _ = _ := by rw [sq_sqrt hr];ring + have hs (z : Spin n) : edgeCoefficient r z e^2=r := by + simp only [edgeCoefficient,mul_pow,spinValue_sq,sq_sqrt hr,mul_one] + nlinarith only [hc,hs x,hs y] + +lemma edgeCoefficient_add_sq_sum {n : ℕ} {r : ℝ} (hr : 0 ≤ r) (x y : Spin n) : + (∑ e,(edgeCoefficient r x e+edgeCoefficient r y e)^2)= + 2*r*(Fintype.card (Edge n):ℝ)+r*((∑ i,spinValue (spinMul x y i))^2-(n:ℝ)) := by + simp_rw [edgeCoefficient_add_sq hr x y] + rw [Finset.sum_add_distrib] + have he := edge_symmetric_sum (fun i=>spinValue (spinMul x y i)) + simp only [spinValue_sq,Finset.sum_const,Finset.card_univ,Fintype.card_fin,nsmul_eq_mul,mul_one] at he + simp only [Finset.sum_const,Finset.card_univ,nsmul_eq_mul] + have hsum : (∑ e : Edge n,2*r*spinValue (spinMul x y e.1.1)*spinValue (spinMul x y e.1.2))= + r*(2*∑ e : Edge n,spinValue (spinMul x y e.1.1)*spinValue (spinMul x y e.1.2)) := by + simp only [Finset.mul_sum];apply Finset.sum_congr rfl;intro e _;ring + rw [hsum,he];ring + +lemma gaussianSpinPartition_integrable (n : ℕ) (r : ℝ) : + Integrable (gaussianSpinPartition n r) (gaussianCoordinates (Edge n)) := + integrable_finsetSum _ (fun x _=>linear_gaussian_exp_integrable (edgeCoefficient r x)) + +lemma gaussianSpinPartition_integral {n : ℕ} {r : ℝ} (hr : 0 ≤ r) : + (∫ g,gaussianSpinPartition n r g ∂gaussianCoordinates (Edge n))= + (Fintype.card (Spin n):ℝ)*exp (r*(Fintype.card (Edge n):ℝ)/2) := by + unfold gaussianSpinPartition + rw [integral_finsetSum _ (fun x _=>linear_gaussian_exp_integrable (edgeCoefficient r x))] + simp only [linear_gaussian_exp_integral,edgeCoefficient_sq_sum hr, + Finset.sum_const,Finset.card_univ,nsmul_eq_mul] + +lemma gaussianSpinPartition_square (n : ℕ) (r : ℝ) (g : Disorder n) : + (gaussianSpinPartition n r g)^2= + ∑ x : Spin n,∑ y : Spin n,exp (∑ e,(edgeCoefficient r x e+edgeCoefficient r y e)*g e) := by + unfold gaussianSpinPartition + rw [sq,Finset.sum_mul_sum] + apply Finset.sum_congr rfl;intro x _ + apply Finset.sum_congr rfl;intro y _ + rw [← exp_add] + congr 1 + simp only [add_mul,Finset.sum_add_distrib] + +lemma gaussianSpinPartition_square_integrable (n : ℕ) (r : ℝ) : + Integrable (fun g=>(gaussianSpinPartition n r g)^2) (gaussianCoordinates (Edge n)) := by + simp_rw [gaussianSpinPartition_square] + exact integrable_finsetSum _ (fun x _=>integrable_finsetSum _ + (fun y _=>linear_gaussian_exp_integrable (fun e=>edgeCoefficient r x e+edgeCoefficient r y e))) + +lemma gaussianSpinPartition_square_integral {n : ℕ} {r : ℝ} (hr : 0 ≤ r) : + (∫ g,(gaussianSpinPartition n r g)^2 ∂gaussianCoordinates (Edge n))= + (Fintype.card (Spin n):ℝ)*exp (r*(Fintype.card (Edge n):ℝ)-r*(n:ℝ)/2)* + ∑ x : Spin n,exp (r/2*(∑ i,spinValue (x i))^2) := by + simp_rw [gaussianSpinPartition_square] + rw [integral_finsetSum _ (fun x _=>integrable_finsetSum _ + (fun y _=>linear_gaussian_exp_integrable (fun e=>edgeCoefficient r x e+edgeCoefficient r y e)))] + simp_rw [integral_finsetSum _ (fun y _=>linear_gaussian_exp_integrable _), + linear_gaussian_exp_integral,edgeCoefficient_add_sq_sum hr] + have he (x y : Spin n) : exp ((2*r*(Fintype.card (Edge n):ℝ)+ + r*((∑ i,spinValue (spinMul x y i))^2-(n:ℝ)))/2)= + exp (r*(Fintype.card (Edge n):ℝ)-r*(n:ℝ)/2)*exp (r/2*(∑ i,spinValue (spinMul x y i))^2) := by + rw [← exp_add];congr 1;ring + simp_rw [he,← Finset.mul_sum] + have hs (x : Spin n) : + (∑ y : Spin n,exp (r/2*(∑ i,spinValue (spinMul x y i))^2))= + ∑ y : Spin n,exp (r/2*(∑ i,spinValue (y i))^2) := + sum_spinMul x (fun y=>exp (r/2*(∑ i,spinValue (y i))^2)) + simp_rw [hs] + simp only [Finset.sum_const,Finset.card_univ,nsmul_eq_mul,mul_assoc] + ring + +end SKGap +end +end + +section +noncomputable section +namespace SKGap +open MeasureTheory ProbabilityTheory Real Set + +lemma second_moment_positive_probability {Ω : Type*} [MeasurableSpace Ω] + (μ : Measure Ω) [IsProbabilityMeasure μ] (Z : Ω→ℝ) + (hZ : Measurable Z) (hi : Integrable Z μ) (hi2 : Integrable (fun x=>Z x^2) μ) + {M B : ℝ} (hM : 0 < M) (hB : 0 < B) (hmean : (∫ x,Z x ∂μ)=M) + (hmoment : (∫ x,Z x^2 ∂μ) ≤ B*M^2) : + 1/(4*B) ≤ μ.real {x | M/2 ≤ Z x} := by + let S : Set Ω := {x | M/2 ≤ Z x} + have hS : MeasurableSet S := measurableSet_le measurable_const hZ + have hden : 0 < 4*B*M := by positivity + have hpoint : ∀ x,Z x ≤ M/2+B*M*S.indicator (fun _=>1) x+Z x^2/(4*B*M) := by + intro x + by_cases hx : x∈S + · rw [indicator_of_mem hx] + apply (mul_le_mul_iff_right₀ hden).mp + nlinarith [sq_nonneg (Z x-2*B*M),div_mul_cancel₀ (Z x^2) hden.ne', + mul_nonneg hB.le (sq_nonneg M)] + · rw [indicator_of_notMem hx] + change ¬ M/2 ≤ Z x at hx + have hn : 0 ≤ Z x^2/(4*B*M) := div_nonneg (sq_nonneg _) hden.le + nlinarith [not_le.mp hx] + have hiS : Integrable (S.indicator (fun _=> (1:ℝ))) μ := (integrable_const _).indicator hS + have hiA : Integrable (fun x=>M/2+B*M*S.indicator (fun _=>(1:ℝ)) x) μ := + (integrable_const (M/2)).add (hiS.const_mul (B*M)) + have hiB : Integrable (fun x=>B*M*S.indicator (fun _=>(1:ℝ)) x) μ := hiS.const_mul _ + have hiC : Integrable (fun x=>Z x^2/(4*B*M)) μ := hi2.div_const _ + have hh := integral_mono hi (hiA.add hiC) hpoint + change (∫ x,Z x ∂μ) ≤ ∫ x,M/2+B*M*S.indicator (fun _=>(1:ℝ)) x+Z x^2/(4*B*M) ∂μ at hh + rw [hmean,integral_add hiA hiC,integral_add (integrable_const (M/2)) hiB, + integral_const,integral_const_mul,integral_div,integral_indicator hS, + setIntegral_const] at hh + simp only [probReal_univ,smul_eq_mul,mul_one,one_mul] at hh + have hterm : (∫ x,Z x^2 ∂μ)/(4*B*M) ≤ M/4 := by + apply (div_le_iff₀ hden).mpr + nlinarith only [hmoment] + have hh' : 1 ≤ 4*B*μ.real S := by + have h : M/4 ≤ B*M*μ.real S := by linarith only [hh,hterm] + apply (mul_le_mul_iff_right₀ hM).mp + nlinarith only [h] + exact (div_le_iff₀ (show 0 < 4*B by positivity)).mpr (by nlinarith only [hh']) +end SKGap +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Gaussian/GaussianProductIntegral.lean b/lean/OAI/Probability/SKGap/Gaussian/GaussianProductIntegral.lean new file mode 100644 index 0000000000000000000000000000000000000000..a4f7270d6d8aa91a790586a9ed7de32d1720e884 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Gaussian/GaussianProductIntegral.lean @@ -0,0 +1,73 @@ +import Mathlib +import OAI.Probability.SKGap.Terminal.PowExponentialPair + +namespace OAI + +section +noncomputable section +open MeasureTheory ProbabilityTheory InformationTheory Real Set +open scoped NNReal ENNReal +open Filter +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius ENNReal NNReal +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius NNReal +noncomputable section +open MeasureTheory ProbabilityTheory Real Set Filter +open MeasureTheory.Measure +open scoped ENNReal NNReal MeasureTheory Topology +namespace SKGap +open MeasureTheory ProbabilityTheory Real +open scoped Topology +section ProductMoments +variable {κ : Type*} [Fintype κ] + +lemma gaussianProduct_integral (F : EuclideanSpace ℝ κ → ℝ) (hF : Continuous F) : + (∫ g : κ → ℝ, F (WithLp.toLp 2 g) ∂Measure.pi (fun _ => gaussianReal 0 1)) = + ∫ x, F x ∂stdGaussian (EuclideanSpace ℝ κ) := by + rw [← map_pi_eq_stdGaussian] + exact (integral_map (by fun_prop) hF.aestronglyMeasurable).symm + +lemma gaussianProduct_integrable_lipschitz {F : EuclideanSpace ℝ κ → ℝ} + {L : ℝ≥0} (hF : LipschitzWith L F) : + Integrable (fun g : κ → ℝ => F (WithLp.toLp 2 g)) + (Measure.pi (fun _ => gaussianReal 0 1)) := by + have hi := gaussian_integrable_lipschitz (μ := stdGaussian (EuclideanSpace ℝ κ)) hF + rw [← map_pi_eq_stdGaussian] at hi + exact hi.comp_measurable (by fun_prop) + +lemma gaussianProduct_abs_centered_moment {F : EuclideanSpace ℝ κ → ℝ} + {L : ℝ≥0} (hF : LipschitzWith L F) (hL : 0 < L) (k : ℕ) : + (∫ g : κ → ℝ, |F (WithLp.toLp 2 g)- + ∫ h : κ → ℝ, F (WithLp.toLp 2 h) ∂Measure.pi (fun _ => gaussianReal 0 1)|^k + ∂Measure.pi (fun _ => gaussianReal 0 1)) ≤ + (2*(k.factorial : ℝ)*exp (π^2/8))*(L:ℝ)^k := by + rw [gaussianProduct_integral F hF.continuous] + rw [gaussianProduct_integral (fun x => |F x-∫ y, F y ∂stdGaussian _|^k) ((hF.continuous.sub continuous_const).abs.pow k)] + exact stdGaussian_abs_centered_moment hF hL k + +lemma gaussianProduct_centered_L1 {F : EuclideanSpace ℝ κ → ℝ} + {L : ℝ≥0} (hF : LipschitzWith L F) (hL : 0 < L) : + (∫ g : κ → ℝ, |F (WithLp.toLp 2 g)- + ∫ h : κ → ℝ, F (WithLp.toLp 2 h) ∂Measure.pi (fun _ => gaussianReal 0 1)| + ∂Measure.pi (fun _ => gaussianReal 0 1)) ≤ + (2*exp (π^2/8))*(L:ℝ) := by + simpa using gaussianProduct_abs_centered_moment hF hL 1 + +end ProductMoments +end SKGap + +open MeasureTheory +noncomputable section + +end +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Gaussian/GaussianProductPower.lean b/lean/OAI/Probability/SKGap/Gaussian/GaussianProductPower.lean new file mode 100644 index 0000000000000000000000000000000000000000..b45964367b83ddea5bc20be4573218c8370cb7ed --- /dev/null +++ b/lean/OAI/Probability/SKGap/Gaussian/GaussianProductPower.lean @@ -0,0 +1,163 @@ +import Mathlib +import OAI.Probability.SKGap.Gaussian.GaussianProductIntegral +import OAI.Probability.SKGap.Matrix.MatrixSeminorm + +namespace OAI + +section +noncomputable section +namespace SKGap +open Real MeasureTheory ProbabilityTheory +open scoped BigOperators +variable {κ : Type*} [Fintype κ] + +lemma gaussianProduct_integrable_exp_lipschitz {F : EuclideanSpace ℝ κ→ℝ} + {L : NNReal} (hF : LipschitzWith L F) (r : ℝ) : + Integrable (fun g : κ→ℝ=>exp (r*F (WithLp.toLp 2 g))) (Measure.pi (fun _=>gaussianReal 0 1)) := by + have hi := gaussian_integrable_exp_lipschitz (μ:=stdGaussian (EuclideanSpace ℝ κ)) hF r + rw [←map_pi_eq_stdGaussian] at hi + exact hi.comp_measurable (by fun_prop) + +lemma gaussianProduct_integrable_abs_pow_lipschitz {F : EuclideanSpace ℝ κ→ℝ} + {L : NNReal} (hF : LipschitzWith L F) (k : ℕ) : + Integrable (fun g : κ→ℝ=>|F (WithLp.toLp 2 g)|^k) (Measure.pi (fun _=>gaussianReal 0 1)) := by + let μ := Measure.pi (fun _ : κ=>gaussianReal 0 1) + have h1 := gaussianProduct_integrable_exp_lipschitz hF 1 + have h2 := gaussianProduct_integrable_exp_lipschitz hF (-1) + have hh := (h1.add h2).const_mul (k.factorial:ℝ) + apply hh.mono' + · exact ((hF.continuous.comp (by fun_prop : Continuous (WithLp.toLp 2 : (κ→ℝ)→EuclideanSpace ℝ κ))).abs.pow k).aestronglyMeasurable + · filter_upwards [] with g + simpa only [Real.norm_eq_abs,abs_pow,abs_abs,one_pow,div_one,Pi.add_apply] using + pow_le_exponential_pair (F (WithLp.toLp 2 g)) (by norm_num : (0:ℝ)<1) k + +lemma gaussianProduct_integrable_pow_lipschitz {F : EuclideanSpace ℝ κ→ℝ} + {L : NNReal} (hF : LipschitzWith L F) (k : ℕ) : + Integrable (fun g : κ→ℝ=>F (WithLp.toLp 2 g)^k) (Measure.pi (fun _=>gaussianReal 0 1)) := by + apply (gaussianProduct_integrable_abs_pow_lipschitz hF k).mono' + · exact ((hF.continuous.comp (by fun_prop : Continuous (WithLp.toLp 2 : (κ→ℝ)→EuclideanSpace ℝ κ))).pow k).aestronglyMeasurable + · filter_upwards [] with g + simp only [Real.norm_eq_abs,abs_pow,le_refl] +end SKGap +end +end + +section +noncomputable section +namespace SKGap +open Real Matrix MeasureTheory ProbabilityTheory Set +open scoped BigOperators Matrix.Norms.Frobenius +variable {ι κ : Type*} [Fintype ι] [DecidableEq ι] [Fintype κ] + +def matrixEntryMean (F : EuclideanSpace ℝ κ→Matrix ι ι ℝ) : Matrix ι ι ℝ := + fun i k=>∫ g : κ→ℝ,F (WithLp.toLp 2 g) i k ∂Measure.pi (fun _=>gaussianReal 0 1) +def matrixCentered (F : EuclideanSpace ℝ κ→Matrix ι ι ℝ) (x : EuclideanSpace ℝ κ) := + F x-matrixEntryMean F + +lemma matrixCentered_lipschitz {F : EuclideanSpace ℝ κ→Matrix ι ι ℝ} + {L : NNReal} (hF : LipschitzWith L F) : LipschitzWith L (matrixCentered F) := by + apply LipschitzWith.of_dist_le_mul + intro x y + simpa only [matrixCentered,dist_sub_right] using hF.dist_le_mul x y + +lemma matrixEntry_lip {F : EuclideanSpace ℝ κ→Matrix ι ι ℝ} + {L : NNReal} (hF : LipschitzWith L F) (i k : ι) : LipschitzWith L (fun x=>F x i k) := by + simpa only [one_mul,Function.comp_def] using (matrixEntry_lipschitz i k).comp hF + +lemma diagonalCentered_lip {F : EuclideanSpace ℝ κ→Matrix ι ι ℝ} + {L : NNReal} (hF : LipschitzWith L F) : LipschitzWith L (fun x=>diagonalSeminorm (matrixCentered F x)) := by + simpa only [one_mul,Function.comp_def] using diagonalSeminorm_lipschitz.comp (matrixCentered_lipschitz hF) +lemma offDiagonalCentered_lip {F : EuclideanSpace ℝ κ→Matrix ι ι ℝ} + {L : NNReal} (hF : LipschitzWith L F) : LipschitzWith L (fun x=>offDiagonalSeminorm (matrixCentered F x)) := by + simpa only [one_mul,Function.comp_def] using offDiagonalSeminorm_lipschitz.comp (matrixCentered_lipschitz hF) + +lemma matrixCentered_even_moment {F : EuclideanSpace ℝ κ→Matrix ι ι ℝ} + {L : NNReal} (hF : LipschitzWith L F) (hL : 0gaussianReal 0 1))≤ + (2*((2*k).factorial:ℝ)*exp (π^2/8))*(L:ℝ)^(2*k) := by + have hh := gaussianProduct_abs_centered_moment (matrixEntry_lip hF i b) hL (2*k) + simpa only [matrixCentered,matrixEntryMean,Matrix.sub_apply,pow_mul,sq_abs] using hh + +lemma diagonalCentered_second_moment {F : EuclideanSpace ℝ κ→Matrix ι ι ℝ} + {L : NNReal} (hF : LipschitzWith L F) (hL : 0gaussianReal 0 1))≤ + (Fintype.card ι:ℝ)*(4*exp (π^2/8))*(L:ℝ)^2 := by + simp_rw [diagonalSeminorm_sq] + rw [integral_finsetSum _ (fun i _=>gaussianProduct_integrable_pow_lipschitz (matrixEntry_lip (matrixCentered_lipschitz hF) i i) 2)] + apply (Finset.sum_le_sum (fun i _=>matrixCentered_even_moment hF hL i i 1)).trans_eq + norm_num [Finset.sum_const,mul_assoc] + +lemma offDiagonalCentered_fourth_moment {F : EuclideanSpace ℝ κ→Matrix ι ι ℝ} + {L : NNReal} (hF : LipschitzWith L F) (hL : 0gaussianReal 0 1))≤ + (Fintype.card ι:ℝ)^2*(48*exp (π^2/8))*(L:ℝ)^4 := by + simp_rw [offDiagonalSeminorm_fourth] + have hi (p : ι×ι) : Integrable (fun g : κ→ℝ=>if p.1=p.2 then 0 else matrixCentered F (WithLp.toLp 2 g) p.1 p.2^4) + (Measure.pi (fun _=>gaussianReal 0 1)) := by + split_ifs + · exact integrable_const _ + · exact gaussianProduct_integrable_pow_lipschitz (matrixEntry_lip (matrixCentered_lipschitz hF) p.1 p.2) 4 + rw [integral_finsetSum _ (fun p _=>hi p)] + have hb (p : ι×ι) : (∫ g : κ→ℝ,(if p.1=p.2 then 0 else matrixCentered F (WithLp.toLp 2 g) p.1 p.2^4) + ∂Measure.pi (fun _=>gaussianReal 0 1)) ≤ (48*exp (π^2/8))*(L:ℝ)^4 := by + split_ifs + · simp only [integral_zero];positivity + · have hh := matrixCentered_even_moment hF hL p.1 p.2 2 + norm_num at hh + exact hh + apply (Finset.sum_le_sum (fun p _=>hb p)).trans_eq + simp only [Finset.sum_const,Finset.card_univ,Fintype.card_prod,nsmul_eq_mul,Nat.cast_mul] + ring + +lemma gaussianProduct_jensen_pow {F : EuclideanSpace ℝ κ→ℝ} {L : NNReal} + (hF : LipschitzWith L F) (hpos : ∀ x,0≤F x) (k : ℕ) : + (∫ g : κ→ℝ,F (WithLp.toLp 2 g) ∂Measure.pi (fun _=>gaussianReal 0 1))^k≤ + ∫ g : κ→ℝ,F (WithLp.toLp 2 g)^k ∂Measure.pi (fun _=>gaussianReal 0 1) := by + exact (convexOn_pow (𝕜:=ℝ) k).map_integral_le (by fun_prop) isClosed_Ici + (ae_of_all _ (fun g=>hpos (WithLp.toLp 2 g))) (gaussianProduct_integrable_lipschitz hF) + (gaussianProduct_integrable_pow_lipschitz hF k) + +def matrixNormConstant : ℝ := 1+48*exp (π^2/8) + +omit [Fintype ι] [DecidableEq ι] [Fintype κ] in +lemma matrixNormConstant_bounds : 1≤ matrixNormConstant ∧ + 4*exp (π^2/8)≤ matrixNormConstant^2 ∧ 48*exp (π^2/8)≤ matrixNormConstant^4 := by + have hE := (exp_pos (π^2/8)).le + have hC : 1≤ matrixNormConstant := by unfold matrixNormConstant;linarith + have hC2 : matrixNormConstant≤ matrixNormConstant^2 := by + simpa only [pow_one] using pow_le_pow_right₀ hC (by decide : 1≤2) + have hC4 : matrixNormConstant≤ matrixNormConstant^4 := by + simpa only [pow_one] using pow_le_pow_right₀ hC (by decide : 1≤4) + refine ⟨hC,?_,?_⟩ <;> unfold matrixNormConstant at * <;> linarith + +lemma gaussianProduct_centered_matrix_norms {F : EuclideanSpace ℝ κ→Matrix ι ι ℝ} + {L : NNReal} (hF : LipschitzWith L F) (hL : 0gaussianReal 0 1))≤ + matrixNormConstant*sqrt (Fintype.card ι)*(L:ℝ) ∧ + (∫ g : κ→ℝ,offDiagonalSeminorm (matrixCentered F (WithLp.toLp 2 g)) ∂Measure.pi (fun _=>gaussianReal 0 1))≤ + matrixNormConstant*sqrt (Fintype.card ι)*(L:ℝ) := by + let : Fact (1≤(4:ENNReal)) := ⟨by norm_num⟩ + have hC0 : 0≤ matrixNormConstant := zero_le_one.trans matrixNormConstant_bounds.1 + have hcn : (0:ℝ)≤Fintype.card ι := Nat.cast_nonneg _ + constructor + · apply le_of_pow_le_pow_left₀ (by decide : 2≠0) (by positivity) + have hJ := gaussianProduct_jensen_pow (diagonalCentered_lip hF) (fun x=>norm_nonneg (diagonalVector (matrixCentered F x))) 2 + apply (hJ.trans (diagonalCentered_second_moment hF hL)).trans + rw [mul_pow,mul_pow,sq_sqrt hcn] + have hh := mul_le_mul_of_nonneg_right (mul_le_mul_of_nonneg_left matrixNormConstant_bounds.2.1 hcn) (sq_nonneg (L:ℝ)) + nlinarith only [hh] + · apply le_of_pow_le_pow_left₀ (by decide : 4≠0) (by positivity) + have hJ := gaussianProduct_jensen_pow (offDiagonalCentered_lip hF) (fun x=>norm_nonneg (offDiagonalVector (matrixCentered F x))) 4 + apply (hJ.trans (offDiagonalCentered_fourth_moment hF hL)).trans + have hs : sqrt (Fintype.card ι)^4=(Fintype.card ι:ℝ)^2 := by + calc + _ = (sqrt (Fintype.card ι)^2)^2 := by ring + _ = _ := by rw [sq_sqrt hcn] + rw [mul_pow,mul_pow,hs] + have hh := mul_le_mul_of_nonneg_right (mul_le_mul_of_nonneg_left matrixNormConstant_bounds.2.2 (sq_nonneg (Fintype.card ι:ℝ))) (by positivity : (0:ℝ)≤(L:ℝ)^4) + nlinarith only [hh] +end SKGap +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Gaussian/GaussianProductUpperTailLipschitz.lean b/lean/OAI/Probability/SKGap/Gaussian/GaussianProductUpperTailLipschitz.lean new file mode 100644 index 0000000000000000000000000000000000000000..9f6cf03ea8bbc4aac0d0b79d6b3f0ddbfd4f67f4 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Gaussian/GaussianProductUpperTailLipschitz.lean @@ -0,0 +1,103 @@ +import Mathlib +import OAI.Probability.SKGap.Gaussian.StdGaussianMgfLipschitz + +namespace OAI + +section +noncomputable section +open MeasureTheory ProbabilityTheory InformationTheory Real Set +open scoped NNReal ENNReal +open Filter +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius ENNReal NNReal +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius NNReal +noncomputable section +open MeasureTheory ProbabilityTheory Real Set Filter +open MeasureTheory.Measure +open scoped ENNReal NNReal MeasureTheory Topology +open MeasureTheory +noncomputable section +noncomputable section +open MeasureTheory Set NormedSpace +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius +noncomputable section +open Set Real +open scoped Topology +noncomputable section +open Matrix Set Filter +open scoped Topology Matrix.Norms.Frobenius +noncomputable section +open Matrix NormedSpace ContinuousLinearMap +open scoped Matrix.Norms.Frobenius +noncomputable section +open Matrix +noncomputable section +open MeasureTheory ProbabilityTheory Real Set +open scoped ENNReal NNReal +noncomputable section +open MeasureTheory ProbabilityTheory InformationTheory Real Set +open scoped NNReal ENNReal +noncomputable section +open scoped BigOperators +open MeasureTheory ProbabilityTheory +open Real +namespace SKGap +section ProductGaussianConcentration +variable {κ : Type*} [Fintype κ] + +theorem gaussianProduct_upper_tail_lipschitz {f : (κ → ℝ) → ℝ} {L : ℝ≥0} + (hf : LipschitzWith L (fun x : EuclideanSpace ℝ κ => f x.ofLp)) + (hL : 0 < L) {u : ℝ} (hu : 0 ≤ u) : + (Measure.pi (fun _ : κ => gaussianReal 0 1)).real + {x | u ≤ f x - ∫ y, f y ∂Measure.pi (fun _ : κ => gaussianReal 0 1)} ≤ + Real.exp (-2*u^2/(π^2*(L:ℝ)^2)) := by + let e : (κ → ℝ) ≃ᵐ EuclideanSpace ℝ κ := MeasurableEquiv.toLp 2 _ + have hp : MeasurePreserving e (Measure.pi (fun _ : κ => gaussianReal 0 1)) + (stdGaussian (EuclideanSpace ℝ κ)) := + ⟨e.measurable, map_pi_eq_stdGaussian⟩ + have hi := hp.integral_comp' (fun x : EuclideanSpace ℝ κ => f x.ofLp) + change (∫ x, f x ∂Measure.pi (fun _ : κ => gaussianReal 0 1)) = _ at hi + have h := stdGaussian_upper_tail_lipschitz hf hL hu + rw [← hi] at h + have hs : MeasurableSet {x : EuclideanSpace ℝ κ | + u ≤ f x.ofLp - ∫ y, f y ∂Measure.pi (fun _ : κ => gaussianReal 0 1)} := + measurableSet_le measurable_const (hf.continuous.measurable.sub_const _) + have he := hp.measure_preimage hs.nullMeasurableSet + have her := congrArg ENNReal.toReal he + change (Measure.pi (fun _ : κ => gaussianReal 0 1)).real + {x | u ≤ f x - ∫ y, f y ∂Measure.pi (fun _ : κ => gaussianReal 0 1)} = _ at her + rw [her] + exact h + +end ProductGaussianConcentration +end SKGap + +noncomputable section +open scoped BigOperators Topology +open Filter Real + +end +end +end +end +end +end +end +end +end +end +end +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Gaussian/GaussianQuadratic.lean b/lean/OAI/Probability/SKGap/Gaussian/GaussianQuadratic.lean new file mode 100644 index 0000000000000000000000000000000000000000..5b07916fc508de0b31832f5bc4f8ab0658ad80f8 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Gaussian/GaussianQuadratic.lean @@ -0,0 +1,202 @@ +import Mathlib +import OAI.Probability.SKGap.Terminal.FiniteSpinCalculus +import OAI.Probability.SKGap.Gaussian.StandardGaussianProduct + +namespace OAI + +section +noncomputable section +open MeasureTheory ProbabilityTheory InformationTheory Real Set +open scoped NNReal ENNReal +open Filter +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius ENNReal NNReal +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius NNReal +noncomputable section +open MeasureTheory ProbabilityTheory Real Set Filter +open MeasureTheory.Measure +open scoped ENNReal NNReal MeasureTheory Topology +open MeasureTheory +noncomputable section +noncomputable section +open MeasureTheory Set NormedSpace +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius +noncomputable section +open Set Real +open scoped Topology +noncomputable section +open Matrix Set Filter +open scoped Topology Matrix.Norms.Frobenius +noncomputable section +open Matrix NormedSpace ContinuousLinearMap +open scoped Matrix.Norms.Frobenius +noncomputable section +open Matrix +noncomputable section +open MeasureTheory ProbabilityTheory Real Set +open scoped ENNReal NNReal +noncomputable section +open MeasureTheory ProbabilityTheory InformationTheory Real Set +open scoped NNReal ENNReal +noncomputable section +open scoped BigOperators +open MeasureTheory ProbabilityTheory +open Real +namespace SKGap +open scoped BigOperators + +lemma gaussian_integrable_pow (k : ℕ) : + Integrable (fun x : ℝ => x^k) (gaussianReal 0 1) := by + apply (integrable_norm_iff (by fun_prop)).mp + simpa only [id_eq, norm_pow] using + (IsGaussian.memLp_id (gaussianReal 0 1) (k : ℝ≥0∞) (by simp)).integrable_norm_pow' + +lemma gaussian_memLp_sq : MemLp (fun x : ℝ => x^2) 2 (gaussianReal 0 1) := by + apply (memLp_two_iff_integrable_sq (by fun_prop)).mpr + simpa only [← pow_mul] using gaussian_integrable_pow 4 + +lemma gaussian_integral_sq : (∫ x : ℝ, x^2 ∂gaussianReal 0 1) = 1 := by + have h := variance_fun_id_gaussianReal (μ := 0) (v := 1) + rw [variance_eq_integral (by fun_prop), integral_id_gaussianReal] at h + simpa only [sub_zero, NNReal.coe_one] using h + +lemma gaussian_integral_fourth : (∫ x : ℝ, x^4 ∂gaussianReal 0 1) = 3 := by + have hd (x : ℝ) : HasDerivAt (fun x : ℝ => x^3) (3*x^2) x := by + convert! (hasDerivAt_id x).pow 3 using 1; norm_num [Pi.pow_apply, id_eq] + have hi : Integrable (fun x : ℝ => (x - 0)*x^3) (gaussianReal 0 1) := by + simpa only [sub_zero, ← pow_succ'] using gaussian_integrable_pow 4 + have h := gaussian_integration_by_parts (by norm_num : (1 : ℝ≥0) ≠ 0) + hd (gaussian_integrable_pow 3) ((gaussian_integrable_pow 2).const_mul 3) hi + simpa only [sub_zero, ← pow_succ', integral_const_mul, gaussian_integral_sq, + NNReal.coe_one, one_mul, mul_one] using h + +lemma gaussian_variance_sq : Var[fun x : ℝ => x^2; gaussianReal 0 1] = 2 := by + rw [variance_eq_sub gaussian_memLp_sq] + simp only [Pi.pow_apply, ← pow_mul, gaussian_integral_fourth, gaussian_integral_sq] + norm_num + +section Quadratic +variable {ι : Type*} [Fintype ι] + +def gaussianQuadratic (a : ι → ℝ) (x : ι → ℝ) : ℝ := ∑ i, a i * (x i)^2 + +lemma gaussianQuadratic_memLp (a : ι → ℝ) : + MemLp (gaussianQuadratic a) 2 (Measure.pi (fun _ : ι => gaussianReal 0 1)) := by + apply memLp_finsetSum + intro i _ + exact ((gaussian_memLp_sq.const_mul (a i)).comp_measurePreserving + (measurePreserving_eval (fun _ : ι => gaussianReal 0 1) i)) + +lemma gaussianQuadratic_mean (a : ι → ℝ) : + (∫ x, gaussianQuadratic a x ∂Measure.pi (fun _ : ι => gaussianReal 0 1)) = ∑ i, a i := by + unfold gaussianQuadratic + have hi (i : ι) : Integrable (fun x : ι → ℝ => a i * (x i)^2) + (Measure.pi (fun _ : ι => gaussianReal 0 1)) := + ((gaussian_memLp_sq.const_mul (a i)).comp_measurePreserving + (measurePreserving_eval (fun _ : ι => gaussianReal 0 1) i)).integrable (by norm_num) + rw [integral_finsetSum _ (fun i _ => hi i)] + apply Finset.sum_congr rfl + intro i _ + rw [integral_const_mul] + have he : (∫ x : ι → ℝ, (x i)^2 ∂Measure.pi (fun _ : ι => gaussianReal 0 1)) = + ∫ y : ℝ, y^2 ∂gaussianReal 0 1 := + integral_comp_eval (μ := fun _ : ι => gaussianReal 0 1) (i := i) + (f := fun y : ℝ => y^2) (by fun_prop) + rw [he, gaussian_integral_sq, mul_one] + +lemma gaussianQuadratic_variance (a : ι → ℝ) : + Var[gaussianQuadratic a; Measure.pi (fun _ : ι => gaussianReal 0 1)] = + 2 * ∑ i, (a i)^2 := by + have h : Var[gaussianQuadratic a; Measure.pi (fun _ : ι => gaussianReal 0 1)] = + ∑ i, Var[fun x : ℝ => a i * x^2; gaussianReal 0 1] := by + convert variance_sum_pi (fun i : ι => gaussian_memLp_sq.const_mul (a i)) using 1 + congr 1 + funext x + simp only [gaussianQuadratic, Finset.sum_apply] + rw [h] + simp only [variance_const_mul, gaussian_variance_sq, ← Finset.sum_mul] + ring + +end Quadratic + +lemma sqrt_sub_sq_le_abs_sub {x y : ℝ} (hx : 0 ≤ x) (hy : 0 ≤ y) : + (sqrt x - sqrt y)^2 ≤ |x-y| := by + have hx2 := sq_sqrt hx + have hy2 := sq_sqrt hy + rcases le_total x y with h | h + · rw [abs_of_nonpos (sub_nonpos.mpr h)] + have hh := sqrt_le_sqrt h + nlinarith [mul_nonneg (sqrt_nonneg x) (sub_nonneg.mpr hh)] + · rw [abs_of_nonneg (sub_nonneg.mpr h)] + have hh := sqrt_le_sqrt h + nlinarith [mul_nonneg (sqrt_nonneg y) (sub_nonneg.mpr hh)] + +section Fluctuation +variable {Ω : Type*} [MeasurableSpace Ω] {μ : Measure Ω} [IsProbabilityMeasure μ] + +omit [IsProbabilityMeasure μ] in +lemma memLp_sqrt_of_nonneg {f : Ω → ℝ} (hf : Integrable f μ) + (hpos : ∀ x, 0 ≤ f x) : MemLp (fun x => sqrt (f x)) 2 μ := by + apply (memLp_two_iff_integrable_sq + (Real.continuous_sqrt.comp_aestronglyMeasurable hf.aestronglyMeasurable)).mpr + exact hf.congr (Filter.Eventually.of_forall (fun x => (sq_sqrt (hpos x)).symm)) + +lemma integral_abs_le_sqrt_sq {f : Ω → ℝ} (hf : MemLp f 2 μ) : + (∫ x, |f x| ∂μ) ≤ sqrt (∫ x, (f x)^2 ∂μ) := by + have h0 := ProbabilityTheory.variance_nonneg (fun x => ‖f x‖) μ + rw [variance_eq_sub hf.norm] at h0 + have hsq : (∫ x, |f x| ∂μ)^2 ≤ ∫ x, (f x)^2 ∂μ := by + simpa only [Real.norm_eq_abs, Pi.pow_apply, sq_abs, sub_nonneg] using h0 + have hi : 0 ≤ ∫ x, (f x)^2 ∂μ := integral_nonneg (fun x => sq_nonneg _) + have hh := sq_sqrt hi + have hp := sqrt_nonneg (∫ x, (f x)^2 ∂μ) + nlinarith [sq_nonneg ((∫ x, |f x| ∂μ) - sqrt (∫ x, (f x)^2 ∂μ))] + +theorem integral_sqrt_fluctuation {f : Ω → ℝ} (hf : MemLp f 2 μ) + (hpos : ∀ x, 0 ≤ f x) : + (∫ x, |sqrt (f x) - sqrt (∫ y, f y ∂μ)| ∂μ) ≤ sqrt (sqrt (Var[f; μ])) := by + let m := ∫ y, f y ∂μ + have hm : 0 ≤ m := integral_nonneg hpos + have hg : MemLp (fun x => f x - m) 2 μ := hf.sub (memLp_const m) + have hroot : MemLp (fun x => sqrt (f x) - sqrt m) 2 μ := by + apply (memLp_two_iff_integrable_sq ((Real.continuous_sqrt.comp_aestronglyMeasurable hf.aestronglyMeasurable).sub aestronglyMeasurable_const)).mpr + apply hg.integrable (by norm_num) |>.norm |>.mono' + (((Real.continuous_sqrt.comp_aestronglyMeasurable hf.aestronglyMeasurable).sub aestronglyMeasurable_const).pow 2) + filter_upwards [] with x + change |(sqrt (f x) - sqrt m)^2| ≤ |f x - m| + rw [abs_of_nonneg (sq_nonneg (sqrt (f x) - sqrt m))] + exact sqrt_sub_sq_le_abs_sub (hpos x) hm + have hdiff : (∫ x, (sqrt (f x) - sqrt m)^2 ∂μ) ≤ ∫ x, |f x-m| ∂μ := by + apply integral_mono hroot.integrable_sq (hg.integrable (by norm_num)).norm + exact fun x => sqrt_sub_sq_le_abs_sub (hpos x) hm + have hc := integral_abs_le_sqrt_sq hg + rw [← variance_eq_integral hf.aemeasurable] at hc + exact (integral_abs_le_sqrt_sq hroot).trans (sqrt_le_sqrt (hdiff.trans hc)) + +end Fluctuation +end SKGap + +end +end +end +end +end +end +end +end +end +end +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Gaussian/GaussianQuadraticSupComparison.lean b/lean/OAI/Probability/SKGap/Gaussian/GaussianQuadraticSupComparison.lean new file mode 100644 index 0000000000000000000000000000000000000000..15542c0ef5454082c96bf22e5b6354058e7991c5 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Gaussian/GaussianQuadraticSupComparison.lean @@ -0,0 +1,147 @@ +import Mathlib +import OAI.Probability.SKGap.Gaussian.GaussianCoordinates +import OAI.Probability.SKGap.Localization.QuadraticCoeff + +namespace OAI + +section +noncomputable section +open MeasureTheory ProbabilityTheory InformationTheory Real Set +open scoped NNReal ENNReal +open Filter +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius ENNReal NNReal +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius NNReal +noncomputable section +open MeasureTheory ProbabilityTheory Real Set Filter +open MeasureTheory.Measure +open scoped ENNReal NNReal MeasureTheory Topology +open MeasureTheory +noncomputable section +noncomputable section +open MeasureTheory Set NormedSpace +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius +noncomputable section +open Set Real +open scoped Topology +noncomputable section +open Matrix Set Filter +open scoped Topology Matrix.Norms.Frobenius +noncomputable section +open Matrix NormedSpace ContinuousLinearMap +open scoped Matrix.Norms.Frobenius +noncomputable section +open Matrix +noncomputable section +open MeasureTheory ProbabilityTheory Real Set +open scoped ENNReal NNReal +noncomputable section +open MeasureTheory ProbabilityTheory InformationTheory Real Set +open scoped NNReal ENNReal +noncomputable section +open scoped BigOperators +open MeasureTheory ProbabilityTheory +namespace SKGap +section QuadraticComparison +variable {I ι : Type*} [TopologicalSpace I] [CompactSpace I] [Nonempty I] + [Fintype ι] [Nonempty ι] + +theorem gaussian_quadraticSup_comparison {m : I → ℝ} + {w : I → EuclideanSpace ℝ ι} (hm : Continuous m) (hw : Continuous w) + {r : ℝ} (hr : 0 ≤ r) (z : ℝ) : + (∫ g, gaussianSup m (fun i k => z * quadraticCoeff r (w i) k) g + ∂gaussianCoordinates (MatrixCoordinates ι)) ≤ + ∫ g, gaussianSup m (fun i k => z * linearCoeff r (w i) k) g + ∂gaussianCoordinates (MatrixCoordinates ι) := by + have hc {q : EuclideanSpace ℝ ι → MatrixCoordinates ι → ℝ} (hq : Continuous q) : + Continuous (fun i k => z * q (w i) k) := by + apply continuous_pi + intro k + exact continuous_const.mul ((continuous_apply k).comp (hq.comp hw)) + apply gaussianSup_comparison hm (hc (continuous_linearCoeff r)) + (hc (continuous_quadraticCoeff r)) + · intro i j + simp_rw [← mul_sub] + simp_rw [show ∀ k, (z * (linearCoeff r (w i) k - linearCoeff r (w j) k)) * + (z * (quadraticCoeff r (w i) k - quadraticCoeff r (w j) k)) = + z^2 * ((linearCoeff r (w i) k - linearCoeff r (w j) k) * + (quadraticCoeff r (w i) k - quadraticCoeff r (w j) k)) by intros; ring] + rw [← Finset.mul_sum, quadratic_linear_orthogonal, mul_zero] + · intro i j + simp_rw [← mul_sub, mul_pow, ← Finset.mul_sum] + exact mul_le_mul_of_nonneg_left (quadratic_linear_increment_le r hr (w i) (w j)) + (sq_nonneg z) +end QuadraticComparison +end SKGap + +namespace SKGap +section SupLipschitz +variable {I κ : Type*} [TopologicalSpace I] [CompactSpace I] [Nonempty I] [Fintype κ] + +lemma gaussianAffine_le_gaussianSup {m : I → ℝ} {a : I → κ → ℝ} + (hm : Continuous m) (ha : Continuous a) (x : κ → ℝ) (i : I) : + gaussianAffine m a x i ≤ gaussianSup m a x := by + obtain ⟨j, hj, hmax⟩ := gaussianSup_attained hm ha x + rw [hj] + exact hmax i + +lemma gaussianSup_sub_le {m : I → ℝ} {a : I → κ → ℝ} + (hm : Continuous m) (ha : Continuous a) {L : ℝ} + (hL : ∀ i, ‖WithLp.toLp 2 (a i)‖ ≤ L) (x y : EuclideanSpace ℝ κ) : + gaussianSup m a x.ofLp - gaussianSup m a y.ofLp ≤ L * ‖x-y‖ := by + obtain ⟨i, hi, _⟩ := gaussianSup_attained hm ha x.ofLp + calc + _ ≤ gaussianAffine m a x.ofLp i - gaussianAffine m a y.ofLp i := by + rw [hi] + exact sub_le_sub_left (gaussianAffine_le_gaussianSup hm ha y.ofLp i) _ + _ = inner ℝ (WithLp.toLp 2 (a i)) (x-y) := by + simp only [gaussianAffine, PiLp.inner_apply, WithLp.ofLp_sub, + Pi.sub_apply, RCLike.inner_apply, conj_trivial] + rw [add_sub_add_left_eq_sub, ← Finset.sum_sub_distrib] + apply Finset.sum_congr rfl + intro k _ + ring + _ ≤ ‖WithLp.toLp 2 (a i)‖ * ‖x-y‖ := real_inner_le_norm _ _ + _ ≤ L * ‖x-y‖ := mul_le_mul_of_nonneg_right (hL i) (norm_nonneg _) + +theorem gaussianSup_lipschitz {m : I → ℝ} {a : I → κ → ℝ} + (hm : Continuous m) (ha : Continuous a) {L : ℝ≥0} + (hL : ∀ i, ‖WithLp.toLp 2 (a i)‖ ≤ (L : ℝ)) : + LipschitzWith L (fun x : EuclideanSpace ℝ κ => gaussianSup m a x.ofLp) := by + apply LipschitzWith.of_dist_le_mul + intro x y + rw [Real.dist_eq, dist_eq_norm] + apply abs_le.mpr + constructor + · have h := gaussianSup_sub_le hm ha hL y x + rw [norm_sub_rev] at h + linarith + · exact gaussianSup_sub_le hm ha hL x y + +end SupLipschitz +end SKGap + +end +end +end +end +end +end +end +end +end +end +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Gaussian/GaussianRankCorrection.lean b/lean/OAI/Probability/SKGap/Gaussian/GaussianRankCorrection.lean new file mode 100644 index 0000000000000000000000000000000000000000..73db12dc21d62d326d78c325ace6a9ca0094ebe6 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Gaussian/GaussianRankCorrection.lean @@ -0,0 +1,429 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.BilinearCoefficient +import OAI.Probability.SKGap.Localization.QueryResidual +import OAI.Probability.SKGap.Gaussian.SubgaussianAbsTail + +namespace OAI + +section +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open scoped BigOperators +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open scoped BigOperators +open scoped BigOperators NNReal ENNReal +open MeasureTheory Metric Set +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators NNReal ENNReal Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Set +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators ENNReal NNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Matrix +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators ENNReal NNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal +open scoped BigOperators +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise NNReal ENNReal +namespace SKGapCutoff.Regression + +noncomputable def gaussianRankCorrection {ι κ η : Type*} [Fintype κ] [Fintype η] + (V : ι → κ → ℝ) (W : κ → η → ℝ) (g : η → ℝ) (i : ι) : ℝ := + ∑ a, V i a * ∑ j, W a j * g j + +lemma rankCorrection_sq_bound {ι κ : Type*} [Fintype ι] [Fintype κ] + (V : ι → κ → ℝ) (c : κ → ℝ) (M : ℝ) + (hV : ∀ a, ∑ i, V i a ^ 2 ≤ M) : + ∑ i, (∑ a, V i a * c a)^2 ≤ M * Fintype.card κ * ∑ a, c a^2 := by + calc + _ ≤ ∑ i, (∑ a, V i a^2) * ∑ a, c a^2 := + Finset.sum_le_sum (fun i _ => Finset.sum_mul_sq_le_sq_mul_sq _ _ _) + _ = (∑ a, ∑ i, V i a^2) * ∑ a, c a^2 := by + rw [← Finset.sum_mul, Finset.sum_comm] + _ ≤ (∑ _a : κ, M) * ∑ a, c a^2 := by + exact mul_le_mul_of_nonneg_right (Finset.sum_le_sum (fun a _ => hV a)) + (Finset.sum_nonneg (fun a _ => sq_nonneg _)) + _ = _ := by simp [mul_comm] + +lemma gaussian_linear_unit_tail {η : Type*} [Fintype η] (W : η → ℝ) + (hW : ∑ j, W j^2 ≤ 1) (b : ℝ) (hb : 0 < b) : + standardArrayLaw η {g | b ≤ |∑ j, W j * g j|} ≤ + 2 * ENNReal.ofReal (Real.exp (-b^2/2)) := by + have h := RandomMatrix.gaussian_linear_abs_tail 1 W b b hb + refine h.trans (mul_le_mul' (le_refl 2) (ENNReal.ofReal_le_ofReal + (Real.exp_le_exp.mpr ?_))) + simp only [NNReal.coe_one, one_mul] + nlinarith [mul_le_mul_of_nonneg_right hW (sq_nonneg b)] + +theorem gaussian_rank_correction_tail {ι κ η : Type*} + [Fintype ι] [Fintype κ] [Fintype η] [Nonempty κ] + (V : ι → κ → ℝ) (W : κ → η → ℝ) + (hV : ∀ a, ∑ i, V i a^2 ≤ 2) (hW : ∀ a, ∑ j, W a j^2 ≤ 1) + (N ε : ℝ) (hN : 0 < N) (hε : 0 < ε) : + standardArrayLaw η {g | N*ε < ∑ i, gaussianRankCorrection V W g i^2} ≤ + (2 * Fintype.card κ : ℝ≥0∞) * + ENNReal.ofReal (Real.exp (-(N*ε)/(4*(Fintype.card κ : ℝ)^2))) := by + classical + let m : ℝ := Fintype.card κ + have hm : 0 < m := by + dsimp [m] + exact_mod_cast (Fintype.card_pos : 0 < Fintype.card κ) + let b : ℝ := Real.sqrt (N*ε/(2*m^2)) + have hb : 0 < b := Real.sqrt_pos.mpr (by positivity) + have hb2 : b^2 = N*ε/(2*m^2) := Real.sq_sqrt (by positivity) + have hsub : {g | N*ε < ∑ i, gaussianRankCorrection V W g i^2} ⊆ + ⋃ a : κ, {g | b ≤ |∑ j, W a j*g j|} := by + intro g hg + by_contra hnot + have hcoeff (a : κ) : (∑ j, W a j*g j)^2 ≤ b^2 := by + have ha : |∑ j, W a j*g j| < b := lt_of_not_ge + (fun ha => hnot (Set.mem_iUnion.mpr ⟨a, ha⟩)) + nlinarith [sq_abs (∑ j, W a j*g j), abs_nonneg (∑ j, W a j*g j)] + have he := rankCorrection_sq_bound V (fun a => ∑ j, W a j*g j) 2 hV + have hs : (∑ a, (∑ j, W a j*g j)^2) ≤ m*b^2 := by + calc + _ ≤ ∑ _a : κ, b^2 := Finset.sum_le_sum (fun a _ => hcoeff a) + _ = _ := by simp [m] + have he' : ∑ i, gaussianRankCorrection V W g i^2 ≤ N*ε := by + calc + _ ≤ 2*m * ∑ a, (∑ j, W a j*g j)^2 := he + _ ≤ 2*m*(m*b^2) := mul_le_mul_of_nonneg_left hs (by positivity) + _ = _ := by rw [hb2]; field_simp + exact not_lt_of_ge he' hg + calc + _ ≤ standardArrayLaw η (⋃ a : κ, {g | b ≤ |∑ j, W a j*g j|}) := measure_mono hsub + _ ≤ ∑ a : κ, standardArrayLaw η {g | b ≤ |∑ j, W a j*g j|} := measure_iUnion_fintype_le _ _ + _ ≤ ∑ _a : κ, 2 * ENNReal.ofReal (Real.exp (-b^2/2)) := + Finset.sum_le_sum (fun a _ => gaussian_linear_unit_tail (W a) (hW a) b hb) + _ = _ := by + have hbexp : -b^2/2 = -(N*ε)/(4*(Fintype.card κ : ℝ)^2) := by + rw [hb2]; dsimp [m]; ring + rw [hbexp] + simp only [Finset.sum_const, Finset.card_univ, nsmul_eq_mul] + ring + +noncomputable def innovationErrorVectors {n r : ℕ} + (U : Matrix (Fin n) (Fin r) ℝ) (q : Fin n → ℝ) (i : Fin n) : Fin r ⊕ Bool → ℝ := + Sum.elim (fun a => -U i a) (fun b => if b then Real.sqrt 2*q i else -q i) + +def innovationErrorCoefficients {n r : ℕ} + (U : Matrix (Fin n) (Fin r) ℝ) (q : Fin n → ℝ) : + (Fin r ⊕ Bool) → (Fin n ⊕ Unit) → ℝ := + Sum.elim (fun a => Sum.elim (fun j => U j a) (fun _ => 0)) + (fun b => if b then Sum.elim (fun _ => 0) (fun _ => 1) + else Sum.elim q (fun _ => 0)) + +lemma innovationErrorVectors_sq_le {n r : ℕ} + (U : Matrix (Fin n) (Fin r) ℝ) (q : Fin n → ℝ) + (hU : ∀ a, ∑ i, U i a^2 ≤ 1) (hq : ∑ i, q i^2 ≤ 1) + (a : Fin r ⊕ Bool) : ∑ i, innovationErrorVectors U q i a^2 ≤ 2 := by + rcases a with a | (_ | _) + · simpa [innovationErrorVectors] using (hU a).trans (by norm_num : (1:ℝ) ≤ 2) + · simpa [innovationErrorVectors] using hq.trans (by norm_num : (1:ℝ) ≤ 2) + · simp only [innovationErrorVectors, Sum.elim_inr, ↓reduceIte, + mul_pow, Real.sq_sqrt (by norm_num : (0:ℝ) ≤ 2), ← Finset.mul_sum] + linarith + +lemma innovationErrorCoefficients_sq_le {n r : ℕ} + (U : Matrix (Fin n) (Fin r) ℝ) (q : Fin n → ℝ) + (hU : ∀ a, ∑ i, U i a^2 ≤ 1) (hq : ∑ i, q i^2 ≤ 1) + (a : Fin r ⊕ Bool) : ∑ j, innovationErrorCoefficients U q a j^2 ≤ 1 := by + rcases a with a | (_ | _) + · simpa [innovationErrorCoefficients, Fintype.sum_sum_type] using hU a + · simpa [innovationErrorCoefficients, Fintype.sum_sum_type] using hq + · simp [innovationErrorCoefficients, Fintype.sum_sum_type] + +lemma queryInnovation_error_eq {n r : ℕ} (hn : 0 < n) + (U : Matrix (Fin n) (Fin r) ℝ) (q : Fin n → ℝ) + (g : (Fin n ⊕ Unit) → ℝ) (i : Fin n) : + Real.sqrt n * queryInnovation (residualProjection U) q g i - g (Sum.inl i) = + gaussianRankCorrection (innovationErrorVectors U q) (innovationErrorCoefficients U q) g i := by + have hsn : Real.sqrt (n:ℝ) ≠ 0 := (Real.sqrt_pos.mpr (Nat.cast_pos.mpr hn)).ne' + have hh : ∑ k, (residualProjection U i k-q i*q k)*g (Sum.inl k) = + g (Sum.inl i) - ∑ a, U i a * (∑ k, U k a*g (Sum.inl k)) - + q i*(∑ k, q k*g (Sum.inl k)) := by + simp only [residualProjection, Matrix.sub_apply, Matrix.mul_apply, Matrix.transpose_apply, + sub_mul, Finset.sum_sub_distrib, Finset.sum_mul, mul_assoc] + rw [Finset.sum_comm] + simp [Matrix.one_apply, Finset.mul_sum] + simp only [queryInnovation, queryComplement_apply] + rw [mul_div_cancel₀ _ hsn, hh] + simp only [gaussianRankCorrection, innovationErrorVectors, innovationErrorCoefficients, + Fintype.sum_sum_type, Sum.elim_inl, Sum.elim_inr, Fintype.sum_bool, Bool.false_eq_true, + ↓reduceIte, zero_mul, one_mul, Finset.sum_const_zero, add_zero, + Fintype.sum_unique, neg_mul, Finset.sum_neg_distrib] + ring + +theorem queryInnovation_iid_error_tail {n r : ℕ} (hn : 0 < n) + (U : Matrix (Fin n) (Fin r) ℝ) (q : Fin n → ℝ) + (hU : ∀ a, ∑ i, U i a^2 ≤ 1) (hq : ∑ i, q i^2 ≤ 1) + (ε : ℝ) (hε : 0 < ε) : + standardArrayLaw (Fin n ⊕ Unit) {g | (n:ℝ)*ε < ∑ i, + (Real.sqrt n * queryInnovation (residualProjection U) q g i - g (Sum.inl i))^2} ≤ + (2*(r+2) : ℝ≥0∞) * ENNReal.ofReal (Real.exp (-((n:ℝ)*ε)/(4*((r:ℝ)+2)^2))) := by + simp_rw [queryInnovation_error_eq hn U q] + have h := gaussian_rank_correction_tail (innovationErrorVectors U q) + (innovationErrorCoefficients U q) (innovationErrorVectors_sq_le U q hU hq) + (innovationErrorCoefficients_sq_le U q hU hq) n ε (Nat.cast_pos.mpr hn) hε + simpa only [Fintype.card_sum, Fintype.card_fin, Fintype.card_bool, Nat.cast_add, + Nat.cast_ofNat] using h + +lemma probability_prod_section_bound {H A : Type*} [MeasurableSpace H] [MeasurableSpace A] + (ρ : Measure H) [IsProbabilityMeasure ρ] (μ : Measure A) [SFinite μ] + (s : Set (H × A)) (hs : MeasurableSet s) (b : ℝ≥0∞) + (hb : ∀ h, μ (Prod.mk h ⁻¹' s) ≤ b) : (ρ.prod μ) s ≤ b := by + rw [Measure.prod_apply hs] + calc + _ ≤ ∫⁻ _h, b ∂ρ := lintegral_mono hb + _ = _ := by simp + +theorem adaptive_queryInnovation_iid_error_tail {n r : ℕ} (hn : 0 < n) + {H : Type*} [MeasurableSpace H] (ρ : Measure H) [IsProbabilityMeasure ρ] + (U : H → Fin n → Fin r → ℝ) (q : H → Fin n → ℝ) + (hUm : Measurable U) (hqm : Measurable q) + (hU : ∀ h a, ∑ i, U h i a^2 ≤ 1) (hq : ∀ h, ∑ i, q h i^2 ≤ 1) + (ε : ℝ) (hε : 0 < ε) : + (ρ.prod (standardArrayLaw (Fin n ⊕ Unit))) {z | (n:ℝ)*ε < ∑ i, + (Real.sqrt n * queryInnovation (residualProjection (U z.1)) (q z.1) z.2 i - z.2 (Sum.inl i))^2} ≤ + (2*(r+2) : ℝ≥0∞) * ENNReal.ofReal (Real.exp (-((n:ℝ)*ε)/(4*((r:ℝ)+2)^2))) := by + have hP : Measurable (fun h => fun i j => residualProjection (U h) i j) := by + apply Measurable.of_eval + intro i + apply Measurable.of_eval + intro j + change Measurable (fun h => (if i=j then (1:ℝ) else 0) - ∑ a, U h i a*U h j a) + apply measurable_const.sub + apply Finset.measurable_sum + intro a _ + exact ((measurable_pi_apply a).comp ((measurable_pi_apply i).comp hUm)).mul + ((measurable_pi_apply a).comp ((measurable_pi_apply j).comp hUm)) + have hI := measurable_queryInnovation_comp + (fun z : H × ((Fin n ⊕ Unit) → ℝ) => residualProjection (U z.1)) + (fun z => q z.1) (fun z => z.2) (hP.comp measurable_fst) + (hqm.comp measurable_fst) measurable_snd + apply probability_prod_section_bound + · apply measurableSet_lt measurable_const + apply Finset.measurable_sum + intro i _ + exact (((measurable_pi_apply i).comp hI).const_mul _ |>.sub + ((measurable_pi_apply (Sum.inl i)).comp measurable_snd)).pow_const 2 + · intro h + exact queryInnovation_iid_error_tail hn (U h) (q h) (hU h) (hq h) ε hε + +lemma independent_bounded_average_tail {Ω : Type*} [MeasurableSpace Ω] + {μ : Measure Ω} [IsProbabilityMeasure μ] {n : ℕ} (hn : 0 < n) + (X : Fin n → Ω → ℝ) (hXi : iIndepFun X μ) + (hX : ∀ i, HasLaw (X i) (gaussianReal 0 1) μ) (f : Fin n → ℝ → ℝ) + (hf : ∀ i, Measurable (f i)) (B : ℝ) (hB : 0 ≤ B) + (hbound : ∀ i z, |f i z| ≤ B) (ε : ℝ) (hε : 0 ≤ ε) : + μ {g | ε ≤ |((∑ i, f i (X i g)) - ∑ i, ∫ z, f i z ∂gaussianReal 0 1)/(n:ℝ)|} ≤ + 2 * ENNReal.ofReal (Real.exp (-(ε^2*(n:ℝ))/(2*B^2))) := by + let m (i : Fin n) := ∫ z, f i z ∂gaussianReal 0 1 + have hi : iIndepFun (fun i (g : Ω) => f i (X i g)-m i) μ := + hXi.comp (fun i z => f i z-m i) (fun i => (hf i).sub_const (m i)) + have hm (i : Fin n) : (∫ g : Ω, f i (X i g) ∂μ) = m i := + (hX i).integral_comp (hf i).aestronglyMeasurable + have hsub (i : Fin n) : HasSubgaussianMGF (fun g : Ω => f i (X i g)-m i) + ((‖B-(-B)‖₊/2)^2) μ := by + have hb : ∀ᵐ g : Ω ∂μ, f i (X i g) ∈ Set.Icc (-B) B := + Filter.Eventually.of_forall (fun g => abs_le.mp (hbound i (X i g))) + simpa only [hm] using hasSubgaussianMGF_of_mem_Icc + (show AEMeasurable (fun g : Ω => f i (X i g)) μ from + (hf i).comp_aemeasurable (hX i).aemeasurable) hb + have hh := subgaussian_abs_tail + (HasSubgaussianMGF.sum_of_iIndepFun hi (s := Finset.univ) (fun i _ => hsub i)) + (ε*n) (by positivity) + have he (g : Ω) : + (ε*(n:ℝ) ≤ |∑ i, (f i (X i g)-m i)|) ↔ + ε ≤ |((∑ i, f i (X i g)) - ∑ i, m i)/(n:ℝ)| := by + rw [Finset.sum_sub_distrib, abs_div, abs_of_pos (show (0:ℝ) < n from Nat.cast_pos.mpr hn)] + exact (le_div_iff₀ (Nat.cast_pos.mpr hn)).symm + simp only [he] at hh + convert hh using 1 + congr 3 + simp only [Finset.sum_const, Finset.card_univ, Fintype.card_fin, nsmul_eq_mul, + NNReal.coe_mul, NNReal.coe_natCast, NNReal.coe_pow, NNReal.coe_div, NNReal.coe_ofNat, + coe_nnnorm, Real.norm_eq_abs] + rw [abs_of_nonneg (by linarith : 0 ≤ B-(-B))] + have hn0 : (n:ℝ) ≠ 0 := Nat.cast_ne_zero.mpr (Nat.ne_of_gt hn) + by_cases hB0 : B=0 + · simp [hB0] + · field_simp + ring + +lemma average_Lipschitz_error_sq {n : ℕ} (hn : 0 < n) + (f : Fin n → ℝ → ℝ) {K : ℝ≥0} (hf : ∀ i, LipschitzWith K (f i)) + (v w : Fin n → ℝ) : + |((∑ i, f i (v i))-(∑ i, f i (w i)))/(n:ℝ)|^2 ≤ + (K:ℝ)^2 * (∑ i, (v i-w i)^2)/(n:ℝ) := by + have hnR : (0:ℝ) < n := Nat.cast_pos.mpr hn + rw [sq_abs, div_pow, ← Finset.sum_sub_distrib] + have hcs := Finset.sum_mul_sq_le_sq_mul_sq Finset.univ + (fun i : Fin n => (1:ℝ)) (fun i => f i (v i)-f i (w i)) + simp only [one_mul, one_pow, Finset.sum_const, Finset.card_univ, + Fintype.card_fin, nsmul_eq_mul, mul_one] at hcs + have hsite (i : Fin n) : (f i (v i)-f i (w i))^2 ≤ (K:ℝ)^2*(v i-w i)^2 := by + have h := (hf i).dist_le_mul (v i) (w i) + rw [Real.dist_eq, Real.dist_eq] at h + have hs := mul_self_le_mul_self (abs_nonneg _) h + simpa [← pow_two, mul_pow] using hs + apply (div_le_iff₀ (sq_pos_of_pos hnR)).mpr + calc + _ ≤ (n:ℝ) * ∑ i, (f i (v i)-f i (w i))^2 := hcs + _ ≤ (n:ℝ) * ∑ i, (K:ℝ)^2*(v i-w i)^2 := + mul_le_mul_of_nonneg_left (Finset.sum_le_sum (fun i _ => hsite i)) hnR.le + _ = _ := by rw [← Finset.mul_sum]; field_simp + +theorem queryInnovation_empirical_tail {n r : ℕ} (hn : 0 < n) + (U : Matrix (Fin n) (Fin r) ℝ) (q : Fin n → ℝ) + (hU : ∀ a, ∑ i, U i a^2 ≤ 1) (hq : ∑ i, q i^2 ≤ 1) + (f : Fin n → ℝ → ℝ) {K : ℝ≥0} (hf : ∀ i, LipschitzWith K (f i)) + (B : ℝ) (hB : 0 ≤ B) (hbound : ∀ i z, |f i z| ≤ B) + (ε : ℝ) (hε : 0 < ε) : + standardArrayLaw (Fin n ⊕ Unit) {g | ε ≤ + |((∑ i, f i (Real.sqrt n * queryInnovation (residualProjection U) q g i)) - + ∑ i, ∫ z, f i z ∂gaussianReal 0 1)/(n:ℝ)|} ≤ + 2 * ENNReal.ofReal (Real.exp (-(ε^2*(n:ℝ))/(8*B^2))) + + (2*(r+2) : ℝ≥0∞) * ENNReal.ofReal + (Real.exp (-((n:ℝ)*ε^2)/(64*((K:ℝ)+1)^2*((r:ℝ)+2)^2))) := by + let δ := ε^2/(16*((K:ℝ)+1)^2) + have hδ : 0 < δ := by dsimp [δ]; positivity + have hnR : (0:ℝ) < n := Nat.cast_pos.mpr hn + let M := ∑ i, ∫ z, f i z ∂gaussianReal 0 1 + let A (g : (Fin n ⊕ Unit) → ℝ) := ∑ i, f i (g (Sum.inl i)) + let C (g : (Fin n ⊕ Unit) → ℝ) := + ∑ i, f i (Real.sqrt n * queryInnovation (residualProjection U) q g i) + let E (g : (Fin n ⊕ Unit) → ℝ) := + ∑ i, (Real.sqrt n * queryInnovation (residualProjection U) q g i-g (Sum.inl i))^2 + have hi : iIndepFun (fun i : Fin n => fun g : (Fin n ⊕ Unit) → ℝ => g (Sum.inl i)) + (standardArrayLaw (Fin n ⊕ Unit)) := coordinates_independent.precomp Sum.inl_injective + have h1 := independent_bounded_average_tail (μ := standardArrayLaw (Fin n ⊕ Unit)) hn + (fun i g => g (Sum.inl i)) hi (fun i => coordinate_hasLaw (Sum.inl i)) f + (fun i => (hf i).continuous.measurable) B hB hbound (ε/2) (by positivity) + have h2 := queryInnovation_iid_error_tail hn U q hU hq δ hδ + have hsub : {g | ε ≤ |(C g-M)/(n:ℝ)|} ⊆ + {g | ε/2 ≤ |(A g-M)/(n:ℝ)|} ∪ {g | (n:ℝ)*δ < E g} := by + intro g hg + by_cases ha : ε/2 ≤ |(A g-M)/(n:ℝ)| + · exact Or.inl ha + apply Or.inr + by_contra he + have he' : E g ≤ (n:ℝ)*δ := le_of_not_gt he + have hcs := average_Lipschitz_error_sq hn f hf + (fun i => Real.sqrt n * queryInnovation (residualProjection U) q g i) + (fun i => g (Sum.inl i)) + change |(C g-A g)/(n:ℝ)|^2 ≤ (K:ℝ)^2*E g/(n:ℝ) at hcs + have hk : (K:ℝ)^2*δ ≤ ε^2/16 := by + dsimp [δ] + have hkp : 0 < ((K:ℝ)+1)^2 := by positivity + apply (le_div_iff₀ (by norm_num : (0:ℝ)<16)).mpr + field_simp + have hkk : (K:ℝ)^2 ≤ ((K:ℝ)+1)^2 := by nlinarith [K.coe_nonneg] + exact hkk + have hsq : |(C g-A g)/(n:ℝ)|^2 ≤ ε^2/16 := hcs.trans + ((calc + (K:ℝ)^2*E g/(n:ℝ) ≤ (K:ℝ)^2*((n:ℝ)*δ)/(n:ℝ) := by gcongr + _ = (K:ℝ)^2*δ := by field_simp).trans hk) + have hd : |(C g-A g)/(n:ℝ)| ≤ ε/2 := by + nlinarith [abs_nonneg ((C g-A g)/(n:ℝ))] + have ht := abs_add_le ((C g-A g)/(n:ℝ)) ((A g-M)/(n:ℝ)) + rw [← add_div, sub_add_sub_cancel] at ht + have ha' : |(A g-M)/(n:ℝ)| < ε/2 := lt_of_not_ge ha + change ε ≤ |(C g-M)/(n:ℝ)| at hg + linarith + apply (measure_mono hsub).trans ((measure_union_le _ _).trans _) + have h1' : standardArrayLaw (Fin n ⊕ Unit) {g | ε/2 ≤ |(A g-M)/(n:ℝ)|} ≤ + 2 * ENNReal.ofReal (Real.exp (-(ε^2*(n:ℝ))/(8*B^2))) := by + convert h1 using 1 + congr 3 + ring + have h2' : standardArrayLaw (Fin n ⊕ Unit) {g | (n:ℝ)*δ < E g} ≤ + (2*(r+2) : ℝ≥0∞) * ENNReal.ofReal + (Real.exp (-((n:ℝ)*ε^2)/(64*((K:ℝ)+1)^2*((r:ℝ)+2)^2))) := by + convert h2 using 1 + congr 3 + dsimp [δ] + field_simp + ring + exact add_le_add h1' h2' + +lemma measurable_residualProjection_comp {n r : ℕ} {H : Type*} [MeasurableSpace H] + (U : H → Fin n → Fin r → ℝ) (hU : Measurable U) : + Measurable (fun h => fun i j => residualProjection (U h) i j) := by + apply Measurable.of_eval + intro i + apply Measurable.of_eval + intro j + change Measurable (fun h => (if i=j then (1:ℝ) else 0) - ∑ a, U h i a*U h j a) + apply measurable_const.sub + apply Finset.measurable_sum + intro a _ + exact ((measurable_pi_apply a).comp ((measurable_pi_apply i).comp hU)).mul + ((measurable_pi_apply a).comp ((measurable_pi_apply j).comp hU)) + +theorem adaptive_queryInnovation_empirical_tail {n r : ℕ} (hn : 0 < n) + {H : Type*} [MeasurableSpace H] (ρ : Measure H) [IsProbabilityMeasure ρ] + (U : H → Fin n → Fin r → ℝ) (q : H → Fin n → ℝ) + (hUm : Measurable U) (hqm : Measurable q) + (hU : ∀ h a, ∑ i, U h i a^2 ≤ 1) (hq : ∀ h, ∑ i, q h i^2 ≤ 1) + (f : H → Fin n → ℝ → ℝ) (hfm : ∀ i, Measurable (fun z : H × ℝ => f z.1 i z.2)) + {K : ℝ≥0} (hf : ∀ h i, LipschitzWith K (f h i)) + (B : ℝ) (hB : 0 ≤ B) (hbound : ∀ h i z, |f h i z| ≤ B) (ε : ℝ) (hε : 0 < ε) : + (ρ.prod (standardArrayLaw (Fin n ⊕ Unit))) {z | ε ≤ + |((∑ i, f z.1 i (Real.sqrt n * + queryInnovation (residualProjection (U z.1)) (q z.1) z.2 i)) - + ∑ i, ∫ x, f z.1 i x ∂gaussianReal 0 1)/(n:ℝ)|} ≤ + 2 * ENNReal.ofReal (Real.exp (-(ε^2*(n:ℝ))/(8*B^2))) + + (2*(r+2) : ℝ≥0∞) * ENNReal.ofReal + (Real.exp (-((n:ℝ)*ε^2)/(64*((K:ℝ)+1)^2*((r:ℝ)+2)^2))) := by + have hI := measurable_queryInnovation_comp + (fun z : H × ((Fin n ⊕ Unit) → ℝ) => residualProjection (U z.1)) + (fun z => q z.1) (fun z => z.2) + ((measurable_residualProjection_comp U hUm).comp measurable_fst) + (hqm.comp measurable_fst) measurable_snd + have hM (i : Fin n) : Measurable (fun h => ∫ x, f h i x ∂gaussianReal 0 1) := + (hfm i).stronglyMeasurable.integral_prod_right.measurable + apply probability_prod_section_bound + · apply measurableSet_le measurable_const + apply Measurable.abs + apply Measurable.div_const + apply Measurable.sub + · apply Finset.measurable_sum + intro i _ + exact (hfm i).comp (measurable_fst.prodMk (((measurable_pi_apply i).comp hI).const_mul _)) + · apply Finset.measurable_sum + intro i _ + exact (hM i).comp measurable_fst + · intro h + exact queryInnovation_empirical_tail hn (U h) (q h) (hU h) (hq h) + (f h) (hf h) B hB (hbound h) ε hε + +end SKGapCutoff.Regression + +open scoped BigOperators +open Filter Topology + +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Gaussian/GaussianRecipeEvent.lean b/lean/OAI/Probability/SKGap/Gaussian/GaussianRecipeEvent.lean new file mode 100644 index 0000000000000000000000000000000000000000..61c53d59b6b891017836300e3a293d9342336030 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Gaussian/GaussianRecipeEvent.lean @@ -0,0 +1,121 @@ +import Mathlib +import OAI.Probability.SKGap.Matrix.PrimaryWordEventBinding + +namespace OAI + +section + +noncomputable section +open scoped BigOperators +namespace SKGapCutoff.Recipe +open SKGap SKGap.Noncrossing SKGap.Noncrossing.Primary MeasureTheory ProbabilityTheory Real Set + +def ordinaryWordTail (j : ℝ) (L n : ℕ) : ENNReal := + 2*((wordPatternSet L L).card*ENNReal.ofReal (3*exp (-(n:ℝ)))+ + ENNReal.ofReal (exp (-2*(n:ℝ)/(π^2*(sqrt (2*j))^2)))+ + (ENNReal.ofReal (2*exp (-(n:ℝ)/(π^2*j)))+ + ENNReal.ofReal (2*(n:ℝ)*exp (-1/(8*(j/n)))))) +def recipeNormTail (j : ℝ) (n : ℕ) : ENNReal := + ENNReal.ofReal (2*exp (-(n:ℝ)/(π^2*j)))+ + ENNReal.ofReal (2*(n:ℝ)*exp (-1/(8*(j/n)))) + +theorem gaussian_recipe_event {j A : ℝ} (hj : 0gaussianReal 0 1)) + {g | ¬RecipeMatrixEvent j R A B W C M Nmax + (removeDiagonal (goeMatrix (j/n) g))}≤ + recipeNormTail j n+ordinaryWordTail j (2*M+2*Nmax+3) n := by + let R:=max A (2*sqrt j+1+1) + have hAR : A≤R:=le_max_left _ _ + have hR : 1≤R:=hA.trans hAR + obtain ⟨C,N,hC,hN,hword⟩:=ordinary_word_event hj hj1 hA (2*M+2*Nmax+3) + refine ⟨R,primaryEventBudget j R C M,R^(2*Nmax+3)+C,C,N,hR, + primaryEventBudget_nonneg (by linarith) hC.le M, + add_nonneg (pow_nonneg (by linarith) _) hC.le,hC,hN,?_⟩ + intro n hn + have hn0 : 0gaussianReal 0 1) + let E : Set (MatrixCoordinates (Fin n)→ℝ):= + {g | 2*sqrt j+1+1hh (.inl hbad))) (le_max_right _ _) + have hw : WordSeminormBound (removeDiagonal (goeMatrix (j/n) g)) j A C (2*M+2*Nmax+3):=by + by_contra hbad; exact hh (.inr hbad) + exact hg (wordEvent_recipeEvent _ hn0 hR hA hAR hC.le hJ M Nmax hw) + +end SKGapCutoff.Recipe + +end +end + +section + +noncomputable section +open scoped BigOperators Topology +open Filter MeasureTheory ProbabilityTheory Real +namespace SKGapCutoff.Recipe +open SKGap SKGap.Noncrossing SKGap.Noncrossing.Primary + +lemma exp_rate_limit {c : ℝ} (hc : 0exp (-c*(n:ℝ))) atTop (𝓝 0) := by + simpa using (summable_pow_mul_exp_neg_nat_mul 0 hc).tendsto_atTop_zero +lemma n_exp_rate_limit {c : ℝ} (hc : 0(n:ℝ)*exp (-c*(n:ℝ))) atTop (𝓝 0) := by + simpa using (summable_pow_mul_exp_neg_nat_mul 1 hc).tendsto_atTop_zero + +lemma recipeNormTail_limit {j : ℝ} (hj : 0ENNReal.ofReal (2*exp (-(n:ℝ)/(π^2*j)))) atTop (𝓝 0) := by + have H:=ENNReal.tendsto_ofReal ((exp_rate_limit (c:=1/(π^2*j)) (by positivity)).const_mul 2) + simpa only [mul_zero,ENNReal.ofReal_zero,show ∀(n : ℕ),-(1/(π^2*j))*(n:ℝ)=-(n:ℝ)/(π^2*j) by intro n;ring] using H + have h₂ : Tendsto (fun n : ℕ=>ENNReal.ofReal (2*(n:ℝ)*exp (-1/(8*(j/n))))) atTop (𝓝 0) := by + have H:=ENNReal.tendsto_ofReal ((n_exp_rate_limit (c:=1/(8*j)) (by positivity)).const_mul 2) + have HH : Tendsto (fun n : ℕ=>ENNReal.ofReal (2*((n:ℝ)*exp (-(1/(8*j))*(n:ℝ))))) atTop (𝓝 0):=by simpa using H + apply HH.congr' + filter_upwards [eventually_ge_atTop 1] with n hn + have hn0 : (n:ℝ)≠0:=by exact_mod_cast (by omega : n≠0) + congr 1 + rw [mul_assoc] + congr 2 + field_simp + convert h₁.add h₂ using 1 <;> first | rfl | simp + +lemma ordinaryWordTail_limit {j : ℝ} (hj : 0ENNReal.ofReal (3*exp (-(n:ℝ)))) atTop (𝓝 0) := by + simpa using ENNReal.tendsto_ofReal ((exp_rate_limit (c:=1) (by norm_num)).const_mul 3) + have h₂ : Tendsto (fun n : ℕ=>ENNReal.ofReal (exp (-2*(n:ℝ)/(π^2*(sqrt (2*j))^2)))) atTop (𝓝 0) := by + have hsq : 0<(sqrt (2*j))^2:=by rw [sq_sqrt (by positivity)]; positivity + have H:=ENNReal.tendsto_ofReal (exp_rate_limit (c:=2/(π^2*(sqrt (2*j))^2)) (by positivity)) + simpa only [ENNReal.ofReal_zero,show ∀(n : ℕ),-(2/(π^2*(sqrt (2*j))^2))*(n:ℝ)= -2*(n:ℝ)/(π^2*(sqrt (2*j))^2) by intro n;ring] using H + have h₃:=(ENNReal.Tendsto.const_mul h₁ (a:=((wordPatternSet L L).card:ENNReal)) (Or.inr (by simp))).add h₂ |>.add (recipeNormTail_limit hj) + convert ENNReal.Tendsto.const_mul h₃ (a:=2) (Or.inr (by simp)) using 1 <;> first | rfl | simp + +theorem gaussian_recipe_event_probability {j A : ℝ} (hj : 0(Measure.pi (fun _ : MatrixCoordinates (Fin n)=>gaussianReal 0 1)) + {g | ¬RecipeMatrixEvent j R A B W C M Nmax + (removeDiagonal (goeMatrix (j/n) g))}) atTop (𝓝 0) := by + obtain ⟨R,B,W,C,N,hR,hB,hW,hC,hN,hb⟩:=gaussian_recipe_event hj hj1 hA M Nmax + refine ⟨R,B,W,C,hR,hB,hW,hC,?_⟩ + apply tendsto_of_tendsto_of_tendsto_of_le_of_le' tendsto_const_nhds + (show Tendsto (fun n=>recipeNormTail j n+ordinaryWordTail j (2*M+2*Nmax+3) n) atTop (𝓝 0) from + by simpa using (recipeNormTail_limit hj).add (ordinaryWordTail_limit hj _)) + (Filter.Eventually.of_forall (fun _=>bot_le)) + filter_upwards [eventually_ge_atTop N] with n hn + exact hb n hn + +end SKGapCutoff.Recipe + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Gaussian/GaussianReductionPointwise.lean b/lean/OAI/Probability/SKGap/Gaussian/GaussianReductionPointwise.lean new file mode 100644 index 0000000000000000000000000000000000000000..3509156a9a65235228d72caee54930e78991d72f --- /dev/null +++ b/lean/OAI/Probability/SKGap/Gaussian/GaussianReductionPointwise.lean @@ -0,0 +1,73 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.ConditionalHessianLaw +import OAI.Probability.SKGap.Localization.ScalarEmpirical +import OAI.Probability.SKGap.Gaussian.ScalarGaussianReductionAlgebra + +namespace OAI + +section +noncomputable section +namespace SKGap +open Matrix Real Set MeasureTheory ProbabilityTheory GaussianDensity +open scoped BigOperators Matrix.Norms.Frobenius ENNReal + +lemma tapField_planted_observation {n : ℕ} [NeZero n] (j t σ : ℝ) + (y x : Fin n → ℝ) (W : Matrix (Fin n) (Fin n) ℝ) : + tapField j (plantedInteraction j W) (fun i=>t+x i) y= + empiricalObservation j t σ y-W*ᵥmagnetization y-x := by + ext i + simp only [tapField,plantedInteraction,Matrix.add_apply,Matrix.smul_apply, + smul_eq_mul,vecMulVec_apply,mul_one,add_mul,Finset.sum_add_distrib, + ← Finset.mul_sum,empiricalObservation,scalarD,scalarM,integral_empiricalLaw, + Fintype.card_fin,scalarBMoment,scalarQMoment_empirical_overlap,onsager, + magnetization,Pi.sub_apply,Matrix.mulVec,dotProduct] + ring + +lemma scalar_density_cancellation {n : ℕ} [NeZero n] {j t σ : ℝ} + (hj : 0 ≤ j) (ht : 0 ≤ t) (hσ : 0 < σ) (y : Fin n → ℝ) : + rankOneDensity ((j/(n:ℝ))*(magnetization y⬝ᵥmagnetization y)+(t+σ^2)) + (j/(n:ℝ)) (magnetization y) (empiricalObservation j t σ y)* + exp ((n:ℝ)*j*(1-overlap y)^2/2)= + sqrt (scalarS j (scalarEmpirical y t σ)/ + (scalarS j (scalarEmpirical y t σ)+j*scalarQMoment (empiricalLaw y)))*scalarIntegrand j t σ y := by + let p := scalarEmpirical y t σ + let q := scalarQMoment (empiricalLaw y) + let s := scalarS j p + let S := s+j*q + have hn : (n:ℝ) ≠ 0 := by exact_mod_cast NeZero.ne n + have hq : 0 ≤ q := (scalarQMoment_bounds _).1 + have hs : 0 < s := add_pos_of_pos_of_nonneg (add_pos_of_nonneg_of_pos ht (sq_pos_of_pos hσ)) (mul_nonneg hj hq) + have hS : 0 < S := add_pos_of_pos_of_nonneg hs (mul_nonneg hj hq) + have hm : magnetization y⬝ᵥmagnetization y=(n:ℝ)*q := by + dsimp [q] + rw [scalarQMoment_empirical_overlap] + simp only [overlap,magnetization,dotProduct,← pow_two] + field_simp + have hx : (fun i=>y i-scalarD j p)⬝ᵥmagnetization y=(n:ℝ)*scalarA j p := by + rw [dotProduct_comm] + exact scalarA_empirical_sum j t σ y + have hs' : (j/(n:ℝ))*(magnetization y⬝ᵥmagnetization y)+(t+σ^2)=s := by + rw [hm]; dsimp [s,scalarS,p,scalarEmpirical,q]; field_simp; ring + rw [hs'] + have hobs : empiricalObservation j t σ y=(fun i=>y i-scalarD j p)+(j*(1-q)) • magnetization y := rfl + rw [hobs] + have hc := rankOneDensity_cancellation hn hs hS.ne' (rfl : S=s+j*q) + (fun i=>y i-scalarD j p) (magnetization y) hm hx (b := 1-q) + have hb : 1-overlap y=1-q := by rw [← scalarQMoment_empirical_overlap] + rw [hb,hc] + have hd : productNormal (scalarD j p) s y=radialDensity (sqrt s) (fun i=>y i-scalarD j p) := by + unfold productNormal + rw [show s.toNNReal=NNReal.mk s hs.le from by ext; exact Real.coe_toNNReal _ hs.le] + exact gaussian_density_shift _ hs.le y + rw [scalarIntegrand,show scalarEmpirical y t σ=p from rfl,hd] + simp only [Fintype.card_fin] + have he : (n:ℝ)*j*(scalarA j p-s*(1-q))^2/(2*s*S)=(n:ℝ)*scalarPsi j p := by + dsimp [S,s,q,p,scalarPsi,scalarEmpirical] + ring + rw [he] + ring +end SKGap +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Gaussian/GaussianRegression.lean b/lean/OAI/Probability/SKGap/Gaussian/GaussianRegression.lean new file mode 100644 index 0000000000000000000000000000000000000000..a18cc5b9ef8fbe8f27a03ab93e1c63e0d53a3850 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Gaussian/GaussianRegression.lean @@ -0,0 +1,134 @@ +import Mathlib +import OAI.Probability.SKGap.Gaussian.GaussianCoordinates + +namespace OAI + +section + +noncomputable section +open MeasureTheory ProbabilityTheory Matrix +open scoped BigOperators ENNReal +namespace SKGap.GaussianRegression + +theorem law_eq_of_mean_covariance {Ω Ω' ι : Type*} + [MeasurableSpace Ω] [MeasurableSpace Ω'] [Fintype ι] [DecidableEq ι] + {P : Measure Ω} {P' : Measure Ω'} {X : Ω → ι → ℝ} {Y : Ω' → ι → ℝ} + (hX : HasGaussianLaw X P) (hY : HasGaussianLaw Y P') + (hm : ∀ i, (∫ w, X w i ∂P) = ∫ w, Y w i ∂P') + (hc : ∀ i k, cov[fun w => X w i, fun w => X w k; P] = + cov[fun w => Y w i, fun w => Y w k; P']) : + P.map X = P'.map Y := by + classical + have := hX.isProbabilityMeasure + have := hY.isProbabilityMeasure + apply Measure.ext_of_charFunDual + ext L + rw [hX.charFunDual_map_eq,hY.charFunDual_map_eq] + let c : ι → ℝ := fun i => L (fun k => if i=k then 1 else 0) + have hL (x : ι → ℝ) : L x = ∑ i, x i * c i := by + simpa only [c, smul_eq_mul, ContinuousLinearMap.coe_coe] using L.toLinearMap.pi_apply_eq_sum_univ x + have hLX : L ∘ X = fun w => ∑ i, X w i*c i := funext (fun w => hL (X w)) + have hLY : L ∘ Y = fun w => ∑ i, Y w i*c i := funext (fun w => hL (Y w)) + have hiX (i : ι) := (hX.eval i).memLp_two + have hiY (i : ι) := (hY.eval i).memLp_two + have hem : (∫ w, (L ∘ X) w ∂P) = ∫ w, (L ∘ Y) w ∂P' := by + rw [hLX,hLY] + rw [integral_finsetSum _ (fun i _ => ((hX.eval i).integrable.mul_const _)), + integral_finsetSum _ (fun i _ => ((hY.eval i).integrable.mul_const _))] + simp only [integral_mul_const,hm] + have hev : Var[L ∘ X; P] = Var[L ∘ Y; P'] := by + rw [← covariance_self (hX.map L).aemeasurable, + ← covariance_self (hY.map L).aemeasurable] + rw [hLX,hLY] + rw [covariance_fun_sum_fun_sum (fun i => (hiX i).mul_const _) (fun i => (hiX i).mul_const _), + covariance_fun_sum_fun_sum (fun i => (hiY i).mul_const _) (fun i => (hiY i).mul_const _)] + simp only [covariance_mul_const_left,covariance_mul_const_right,hc] + rw [hev,hem] + +def matrixCLM {ι κ : Type*} [Fintype κ] (A : Matrix ι κ ℝ) : + (κ → ℝ) →L[ℝ] (ι → ℝ) := A.mulVecLin.toContinuousLinearMap + +@[simp] lemma matrixCLM_apply {ι κ : Type*} [Fintype κ] (A : Matrix ι κ ℝ) (x : κ → ℝ) : + matrixCLM A x = A *ᵥ x := rfl + +theorem residual_independent {Ω ι κ : Type*} [MeasurableSpace Ω] + [Fintype ι] [Fintype κ] {P : Measure Ω} {X : Ω → ι → ℝ} {Y : Ω → κ → ℝ} + (hXY : HasGaussianLaw (fun w => (X w,Y w)) P) (K : Matrix ι κ ℝ) + (hcov : ∀ i k, cov[fun w => X w i, fun w => Y w k; P] = + ∑ l, K i l * cov[fun w => Y w l,fun w => Y w k; P]) : + IndepFun (fun w => X w-K*ᵥ Y w) Y P := by + have := hXY.isProbabilityMeasure + have hR : HasGaussianLaw (fun w => (X w-K*ᵥ Y w,Y w)) P := by + exact hXY.map_fun (((ContinuousLinearMap.fst ℝ (ι → ℝ) (κ → ℝ))- + (matrixCLM K).comp (ContinuousLinearMap.snd ℝ (ι → ℝ) (κ → ℝ))).prod + (ContinuousLinearMap.snd ℝ (ι → ℝ) (κ → ℝ))) + apply hR.indepFun_of_covariance_eval + intro i k + change cov[fun w => X w i-∑ l, K i l*Y w l,fun w => Y w k; P]=0 + have hK : MemLp (fun w => ∑ l, K i l*Y w l) 2 P := + ((hXY.snd.map (matrixCLM K)).eval i).memLp_two + rw [covariance_fun_sub_left (hXY.fst.eval i).memLp_two hK (hXY.snd.eval k).memLp_two] + rw [covariance_fun_sum_left (fun l => (hXY.snd.eval l).memLp_two.const_mul _) + (hXY.snd.eval k).memLp_two] + simp only [covariance_const_mul_left,hcov,sub_self] + +end SKGap.GaussianRegression +end +end + +section +noncomputable section +namespace SKGap +open MeasureTheory ProbabilityTheory Matrix +open scoped BigOperators ENNReal + +lemma coordinate_hasLaw {κ : Type*} [Fintype κ] (i : κ) : + HasLaw (fun g : κ → ℝ => g i) (gaussianReal 0 1) (gaussianCoordinates κ) := + ⟨(measurable_pi_apply i).aemeasurable, + (measurePreserving_eval (fun _ : κ => gaussianReal 0 1) i).map_eq⟩ + +lemma coordinates_gaussian {κ : Type*} [Fintype κ] : + HasGaussianLaw (fun g : κ → ℝ => g) (gaussianCoordinates κ) := + (iIndepFun_pi (fun _ : κ => aemeasurable_id)).hasGaussianLaw + (fun i => (coordinate_hasLaw i).hasGaussianLaw) + +lemma coordinate_covariance {κ : Type*} [Fintype κ] [DecidableEq κ] (i k : κ) : + cov[fun g : κ → ℝ => g i,fun g : κ → ℝ => g k;gaussianCoordinates κ] = + if i=k then 1 else 0 := by + by_cases h : i=k + · subst k + rw [ite_eq_left rfl,covariance_self (measurable_pi_apply i).aemeasurable, + (coordinate_hasLaw i).variance_eq] + simp + · rw [ite_eq_right h] + exact ((iIndepFun_pi (fun _ : κ => aemeasurable_id)).indepFun h).covariance_eq_zero + (coordinate_hasLaw i).hasGaussianLaw.memLp_two (coordinate_hasLaw k).hasGaussianLaw.memLp_two + +lemma linear_gaussian_mean {κ : Type*} [Fintype κ] (a : κ → ℝ) : + (∫ g, ∑ i, a i*g i ∂gaussianCoordinates κ) = 0 := by + rw [integral_finsetSum _ (fun i _ => (coordinate_hasLaw i).hasGaussianLaw.integrable.const_mul _)] + simp [integral_const_mul,(coordinate_hasLaw _).integral_eq] + +lemma linear_gaussian_covariance {κ : Type*} [Fintype κ] [DecidableEq κ] (a b : κ → ℝ) : + cov[fun g => ∑ i, a i*g i,fun g => ∑ i, b i*g i;gaussianCoordinates κ] = + ∑ i, a i*b i := by + rw [covariance_fun_sum_fun_sum + (fun i => (coordinate_hasLaw i).hasGaussianLaw.memLp_two.const_mul _) + (fun i => (coordinate_hasLaw i).hasGaussianLaw.memLp_two.const_mul _)] + simp only [covariance_const_mul_left,covariance_const_mul_right,coordinate_covariance] + simp [mul_comm] + +lemma matrix_sample_gaussian {ι κ : Type*} [Fintype ι] [Fintype κ] (A : Matrix ι κ ℝ) : + HasGaussianLaw (fun g => A*ᵥg) (gaussianCoordinates κ) := + coordinates_gaussian.map_fun (GaussianRegression.matrixCLM A) + +lemma matrix_sample_covariance {ι κ : Type*} [Fintype κ] [DecidableEq κ] + (A : Matrix ι κ ℝ) (i k : ι) : + cov[fun g => (A*ᵥg) i,fun g => (A*ᵥg) k;gaussianCoordinates κ] = (A*Aᵀ) i k := + linear_gaussian_covariance (A i) (A k) + +end SKGap +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Gaussian/GaussianSign.lean b/lean/OAI/Probability/SKGap/Gaussian/GaussianSign.lean new file mode 100644 index 0000000000000000000000000000000000000000..9ea7879cb13034be23048222b295c7d738b125bd --- /dev/null +++ b/lean/OAI/Probability/SKGap/Gaussian/GaussianSign.lean @@ -0,0 +1,79 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.Conjugation + +namespace OAI + +section +noncomputable section +namespace SKGap +open Matrix MeasureTheory ProbabilityTheory +open scoped BigOperators + +noncomputable def gaussianSignEquiv {κ : Type*} (q : κ → ℝ) (hq : ∀ b, q b^2=1) : + (κ → ℝ) ≃ᵐ (κ → ℝ) where + toFun g b := q b*g b + invFun g b := q b*g b + left_inv g := by ext b; dsimp; rw [← mul_assoc,← sq,hq b,one_mul] + right_inv g := by ext b; dsimp; rw [← mul_assoc,← sq,hq b,one_mul] + measurable_toFun := by change Measurable (fun g : κ → ℝ => fun b => q b*g b); fun_prop + measurable_invFun := by change Measurable (fun g : κ → ℝ => fun b => q b*g b); fun_prop + +lemma gaussianSign_map {κ : Type*} [Fintype κ] (q : κ → ℝ) (hq : ∀ b, q b^2=1) : + (Measure.pi (fun _ : κ => gaussianReal 0 1)).map (gaussianSignEquiv q hq) = + Measure.pi (fun _ : κ => gaussianReal 0 1) := by + have he (b : κ) : (gaussianReal 0 1).map (fun x => q b*x) = gaussianReal 0 1 := by + rcases sq_eq_one_iff.mp (hq b) with h|h + · simp [h] + · simpa only [h,neg_one_mul,neg_zero] using (gaussianReal_map_neg (μ := (0:ℝ)) (v := 1)) + change (Measure.pi (fun _ : κ => gaussianReal 0 1)).map (fun g b => q b*g b) = _ + rw [Measure.pi_map_pi (fun _ => by fun_prop)] + simp only [he] + +lemma gaussianSign_integral {κ : Type*} [Fintype κ] (q : κ → ℝ) (hq : ∀ b, q b^2=1) + (F : (κ → ℝ) → ℝ) : + (∫ g, F (gaussianSignEquiv q hq g) ∂Measure.pi (fun _ : κ => gaussianReal 0 1)) = + ∫ g, F g ∂Measure.pi (fun _ : κ => gaussianReal 0 1) := by + rw [← integral_map_equiv,gaussianSign_map] + +variable {ι : Type*} [Fintype ι] [DecidableEq ι] +def goeSign (s : ι → ℝ) : MatrixCoordinates ι → ℝ := + Sum.elim (fun p => s p.1*s p.2) (fun _ => 1) + +omit [Fintype ι] [DecidableEq ι] in +lemma goeSign_sq (s : ι → ℝ) (hs : ∀ i, s i^2=1) (b : MatrixCoordinates ι) : + goeSign s b^2=1 := by + rcases b with ⟨i,k⟩|i + · simp only [goeSign,Sum.elim_inl,mul_pow,hs,one_mul] + · norm_num [goeSign] + +omit [Fintype ι] [DecidableEq ι] in +lemma goeMatrix_sign (r : ℝ) (s : ι → ℝ) (hs : ∀ i, s i^2=1) + (g : MatrixCoordinates ι → ℝ) : + goeMatrix r (gaussianSignEquiv (goeSign s) (goeSign_sq s hs) g) = + signConjugate s (goeMatrix r g) := by + ext i k + dsimp [goeMatrix,gaussianSignEquiv,goeSign,signConjugate] + ring + +lemma goe_equivariant_offdiag (r : ℝ) (F : Matrix ι ι ℝ → Matrix ι ι ℝ) + (hF : ∀ (s : ι → ℝ), (∀ i, s i^2=1) → ∀ M, + F (signConjugate s M)=signConjugate s (F M)) (i k : ι) (hik : i ≠ k) : + (∫ g, F (goeMatrix r g) i k ∂Measure.pi (fun _ : MatrixCoordinates ι => gaussianReal 0 1))=0 := by + let s : ι → ℝ := fun b => if b=i then -1 else 1 + have hs : ∀ b, s b^2=1 := by intro b; dsimp [s]; split <;> norm_num + have hi := gaussianSign_integral (goeSign s) (goeSign_sq s hs) (fun g => F (goeMatrix r g) i k) + have hsi : s i = -1 := by simp [s] + have hsk : s k = 1 := by simp [s,Ne.symm hik] + have heq : (fun g => F (goeMatrix r (gaussianSignEquiv (goeSign s) (goeSign_sq s hs) g)) i k) = + (fun g => -F (goeMatrix r g) i k) := by + funext g + rw [goeMatrix_sign r s hs g,hF s hs] + change s i*s k*F (goeMatrix r g) i k = _ + rw [hsi,hsk,neg_one_mul,neg_mul,one_mul] + rw [heq,integral_neg] at hi + linarith +end SKGap +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Gaussian/GaussianSquareTail.lean b/lean/OAI/Probability/SKGap/Gaussian/GaussianSquareTail.lean new file mode 100644 index 0000000000000000000000000000000000000000..256a61e719b6bd20108fee45cca91f439229d9e9 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Gaussian/GaussianSquareTail.lean @@ -0,0 +1,153 @@ +import Mathlib +import OAI.Probability.SKGap.Gaussian.GaussianRegression + +namespace OAI + +section +noncomputable section +namespace SKGap +open MeasureTheory ProbabilityTheory Real +open scoped BigOperators + +lemma gaussian_square_exp_integral : + (∫ x : ℝ,exp (x^2/4) ∂gaussianReal 0 1) ≤ 2 := by + rw [gaussianReal_of_var_ne_zero 0 (one_ne_zero), + integral_withDensity_eq_integral_toReal_smul (measurable_gaussianPDF 0 1) + (ae_of_all _ (fun y=>by simp [gaussianPDF]))] + simp only [gaussianPDF,ENNReal.toReal_ofReal (gaussianPDFReal_nonneg _ _ _),smul_eq_mul] + have he : (fun x : ℝ=>gaussianPDFReal 0 1 x*exp (x^2/4))= + (fun x : ℝ=>(1/sqrt (2*Real.pi))*exp (-(1/4:ℝ)*x^2)) := by + funext x + simp only [gaussianPDFReal,NNReal.coe_one,sub_zero,mul_one] + rw [mul_assoc,← exp_add] + congr 2 <;> ring + rw [he,integral_const_mul,integral_gaussian] + have hp := Real.pi_pos + have h1 := sq_sqrt (show 0 ≤ 2*Real.pi by positivity) + have h2 := sq_sqrt (show 0 ≤ Real.pi/(1/4:ℝ) by positivity) + have h3 := sqrt_nonneg (2*Real.pi) + have h4 := sqrt_nonneg (Real.pi/(1/4:ℝ)) + rw [one_div,mul_comm,← div_eq_mul_inv] + apply (div_le_iff₀ (sqrt_pos.mpr (by positivity))).mpr + nlinarith + +lemma gaussian_square_exp_integrable : + Integrable (fun x : ℝ=>exp (x^2/4)) (gaussianReal 0 1) := by + rw [gaussianReal_of_var_ne_zero 0 (one_ne_zero),integrable_withDensity_iff + (measurable_gaussianPDF 0 1) (ae_of_all _ (fun y=>by simp [gaussianPDF]))] + simp only [gaussianPDF,ENNReal.toReal_ofReal (gaussianPDFReal_nonneg _ _ _)] + have hi := (integrable_exp_neg_mul_sq (show (0:ℝ) < 1/4 by norm_num)).const_mul (1/sqrt (2*Real.pi)) + have he : (fun g : ℝ=>exp (g^2/4)*gaussianPDFReal 0 1 g)= + (fun g : ℝ=>(1/sqrt (2*Real.pi))*exp (-(1/4:ℝ)*g^2)) := by + funext g + simp only [gaussianPDFReal,NNReal.coe_one,sub_zero,mul_one] + rw [mul_left_comm,← exp_add] + congr 2 <;> ring + rw [he] + exact hi + +lemma product_gaussian_square_exp_integral {ι : Type*} [Fintype ι] : + (∫ g : ι→ℝ,exp ((∑ i,g i^2)/4) ∂Measure.pi (fun _ : ι=>gaussianReal 0 1)) ≤ + exp ((Fintype.card ι:ℝ)*log 2) := by + have he (g : ι→ℝ) : exp ((∑ i,g i^2)/4)=∏ i,exp (g i^2/4) := by + rw [← exp_sum,Finset.sum_div] + simp_rw [he] + rw [integral_fintype_prod_eq_prod (f:=fun _ : ι=>fun x : ℝ=>exp (x^2/4))] + calc + _ ≤ ∏ _i : ι,(2:ℝ) := Finset.prod_le_prod₀ + (fun i _=>integral_nonneg (fun x=>(exp_pos _).le)) + (fun i _=>gaussian_square_exp_integral) + _ = _ := by rw [Finset.prod_const,Finset.card_univ,exp_nat_mul,exp_log (by norm_num : (0:ℝ)<2)] + +lemma product_gaussian_square_exp_integrable {ι : Type*} [Fintype ι] : + Integrable (fun g : ι→ℝ=>exp ((∑ i,g i^2)/4)) + (Measure.pi (fun _ : ι=>gaussianReal 0 1)) := by + have hi := Integrable.fintype_prod (fun _ : ι=>gaussian_square_exp_integrable) + convert hi using 1 + ext g + rw [← exp_sum,Finset.sum_div] + +lemma product_gaussian_square_tail {ι : Type*} [Fintype ι] (t : ℝ) : + (Measure.pi (fun _ : ι=>gaussianReal 0 1)).real {g | t < ∑ i,g i^2} ≤ + exp (-t/4+(Fintype.card ι:ℝ)*log 2) := by + have hm := mul_meas_ge_le_integral_of_nonneg + (ae_of_all (Measure.pi (fun _ : ι=>gaussianReal 0 1)) + (fun g=>(exp_pos ((∑ i,g i^2)/4)).le)) product_gaussian_square_exp_integrable (exp (t/4)) + have hs : {g : ι→ℝ| t < ∑ i,g i^2} ⊆ {g | exp (t/4) ≤ exp ((∑ i,g i^2)/4)} := by + intro g hg + exact exp_le_exp.mpr (by linarith only [show t < ∑ i,g i^2 from hg]) + have hb := (mul_le_mul_of_nonneg_left (measureReal_mono hs) + (exp_pos (t/4)).le).trans (hm.trans product_gaussian_square_exp_integral) + rw [show -t/4+(Fintype.card ι:ℝ)*log 2=(Fintype.card ι:ℝ)*log 2-t/4 by ring,exp_sub] + apply (le_div_iff₀ (exp_pos _)).mpr + simpa only [mul_comm] using hb +end SKGap +end +end + +section +noncomputable section +namespace SKGap +open MeasureTheory ProbabilityTheory Real +open scoped BigOperators NNReal +variable {κ : Type*} [Fintype κ] + +lemma gaussian_scaled_coordinates_hasLaw {r : ℝ} (hr : 0 ≤ r) : + HasLaw (fun g : κ→ℝ=>fun k=>sqrt r*g k) + (Measure.pi (fun _ : κ=>gaussianReal 0 (Real.toNNReal r))) (gaussianCoordinates κ) := by + have hl (k : κ) : HasLaw (fun g : κ→ℝ=>sqrt r*g k) + (gaussianReal 0 (Real.toNNReal r)) (gaussianCoordinates κ) := by + have h := gaussianReal_const_mul (coordinate_hasLaw (κ:=κ) k) (sqrt r) + have hv : (⟨(sqrt r)^2,sq_nonneg _⟩:ℝ≥0)*1=Real.toNNReal r := by + apply NNReal.eq + change (sqrt r)^2*1=↑(Real.toNNReal r) + rw [mul_one,sq_sqrt hr,Real.coe_toNNReal _ hr] + rw [mul_zero] at h + convert h using 1 + exact congrArg (gaussianReal 0) hv.symm + exact iIndepFun.hasLaw_pi hl ((iIndepFun_pi (fun _ : κ=>aemeasurable_id)).comp + (fun _=>fun x : ℝ=>sqrt r*x) (fun _=>by fun_prop)) + +lemma scaled_gaussian_square_tail {r : ℝ} (hr : 0 < r) (t : ℝ) : + (Measure.pi (fun _ : κ=>gaussianReal 0 (Real.toNNReal r))).real {g | t < ∑ i,g i^2} ≤ + exp (-t/(4*r)+(Fintype.card κ:ℝ)*log 2) := by + have hm : MeasurableSet {g : κ→ℝ | t < ∑ i,g i^2} := by measurability + rw [← (gaussian_scaled_coordinates_hasLaw (κ:=κ) hr.le).measureReal_eq hm] + have he : {g : κ→ℝ | t < ∑ i,(sqrt r*g i)^2}={g | t/r < ∑ i,g i^2} := by + ext g + simp only [Set.mem_ofPred_eq,mul_pow,sq_sqrt hr.le,← Finset.mul_sum] + rw [div_lt_iff₀ hr,mul_comm] + rw [he] + simpa only [gaussianCoordinates,neg_div,div_div,mul_comm r (4:ℝ)] using + product_gaussian_square_tail (ι:=κ) (t/r) +end SKGap +end +end + +section +noncomputable section +namespace SKGap +open MeasureTheory ProbabilityTheory Real +open scoped BigOperators + +lemma gaussian_real_square_tail {r : ℝ} (hr : 0 < r) (t : ℝ) : + (gaussianReal 0 (Real.toNNReal r)).real {x : ℝ | t < x^2} ≤ exp (-t/(4*r)+log 2) := by + have h : HasLaw (fun v : Unit→ℝ=>v ()) (gaussianReal 0 (Real.toNNReal r)) + (Measure.pi (fun _ : Unit=>gaussianReal 0 (Real.toNNReal r))) := + ⟨(measurable_pi_apply ()).aemeasurable,(measurePreserving_eval (fun _ : Unit=>gaussianReal 0 (Real.toNNReal r)) ()).map_eq⟩ + rw [← h.measureReal_eq (by measurability : MeasurableSet {x : ℝ | t < x^2})] + simpa using scaled_gaussian_square_tail (κ:=Unit) hr t + +lemma gaussian_real_abs_tail {r : ℝ} (hr : 0 < r) {d : ℝ} (hd : 0 ≤ d) : + (gaussianReal 0 (Real.toNNReal r)).real {x : ℝ | d < |x|} ≤ 2*exp (-d^2/(4*r)) := by + have he : {x : ℝ | d < |x|}={x | d^2 < x^2} := by + ext x + simpa only [Set.mem_ofPred_eq,sq_abs] using (sq_lt_sq₀ hd (abs_nonneg x)).symm + rw [he] + apply (gaussian_real_square_tail hr (d^2)).trans_eq + rw [exp_add,exp_log (by norm_num : (0:ℝ) < 2),mul_comm] +end SKGap +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Gaussian/GaussianTailScale.lean b/lean/OAI/Probability/SKGap/Gaussian/GaussianTailScale.lean new file mode 100644 index 0000000000000000000000000000000000000000..023582b6a8f7ecfa1bc9b5363b418f0c175a369c --- /dev/null +++ b/lean/OAI/Probability/SKGap/Gaussian/GaussianTailScale.lean @@ -0,0 +1,179 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.PartitionLogLipschitz + +namespace OAI + +section +noncomputable section +namespace SKGap +open MeasureTheory ProbabilityTheory Real Filter Set +open scoped BigOperators NNReal Topology + +lemma exists_gaussian_tail_quantile {p : ℝ} (hp : 0 < p) : + ∃ c : ℝ, 0 < c ∧ exp (-2*c^2/π^2) < p := by + let c : ℝ := sqrt (π^2/2*(|log p|+1)) + have hc : 0 < c := sqrt_pos.mpr (mul_pos (div_pos (sq_pos_of_pos pi_pos) (by norm_num)) (by positivity)) + have hc2 : c^2=π^2/2*(|log p|+1) := sq_sqrt (by positivity) + refine ⟨c,hc,?_⟩ + have he : -2*c^2/π^2= -(|log p|+1) := by rw [hc2];field_simp + rw [he] + apply lt_of_lt_of_eq ?_ (exp_log hp) + apply exp_lt_exp.mpr + linarith only [neg_abs_le (log p)] + +lemma eventually_sqrt_cost_le_linear {δ c : ℝ} (hδ : 0 < δ) (hc : 0 ≤ c) : + ∀ᶠ n : ℕ in atTop, log 2+c*sqrt (n:ℝ) ≤ δ*(n:ℝ)/2 := by + have hl : 0 ≤ log (2:ℝ) := log_nonneg (by norm_num) + have hlarge : ∀ᶠ n : ℕ in atTop, (4*c/δ)^2+4*log 2/δ ≤ (n:ℝ) := + tendsto_natCast_atTop_atTop.eventually (eventually_ge_atTop _) + filter_upwards [hlarge] with n hn + have hn0 : (0:ℝ) ≤ n := by positivity + have hs : 4*c/δ ≤ sqrt (n:ℝ) := by + apply (sq_le_sq₀ (by positivity) (sqrt_nonneg _)).mp + rw [sq_sqrt hn0] + linarith only [hn,div_nonneg (mul_nonneg (by norm_num : (0:ℝ) ≤ 4) hl) hδ.le] + have hs' := (div_le_iff₀ hδ).mp hs + have he := sq_sqrt hn0 + have hm := mul_le_mul_of_nonneg_right hs' (sqrt_nonneg (n:ℝ)) + have hn' : 4*log 2/δ ≤ (n:ℝ) := by linarith only [hn,sq_nonneg (4*c/δ)] + have hl' := (div_le_iff₀ hδ).mp hn' + have hm' : 4*c*sqrt (n:ℝ) ≤ δ*(n:ℝ) := hm.trans_eq (by + calc sqrt (n:ℝ)*δ*sqrt (n:ℝ) = δ*(sqrt (n:ℝ))^2 := by ring + _ = δ*(n:ℝ) := by rw [he]) + linarith only [hm',hl'] + +end SKGap +end +end + +section +noncomputable section +namespace SKGap +open MeasureTheory ProbabilityTheory Real Filter Set +open scoped BigOperators NNReal Topology + +lemma gaussianSpinPartition_log_mean_lower {j c : ℝ} (hj0 : 0 ≤ j) (hj : j < 1) + (hc : 0 < c) (hpc : exp (-2*c^2/π^2) < 1/(4*quadraticGaussianBound j)) + {n : ℕ} (hn : 0 < n) {r : ℝ} (hr : 0 ≤ r) (hnr : (n:ℝ)*r ≤ j) : + log (∫ g,gaussianSpinPartition n r g ∂gaussianCoordinates (Edge n))-log 2-c*sqrt (n:ℝ) ≤ + ∫ g,log (gaussianSpinPartition n r g) ∂gaussianCoordinates (Edge n) := by + have hM := gaussianSpinPartition_mean_pos (n:=n) hr + have hsub : {g | (∫ g,gaussianSpinPartition n r g ∂gaussianCoordinates (Edge n))/2 ≤ gaussianSpinPartition n r g} ⊆ + {g | log (∫ g,gaussianSpinPartition n r g ∂gaussianCoordinates (Edge n))-log 2 ≤ log (gaussianSpinPartition n r g)} := by + intro g hg + simp only [mem_ofPred_eq] at hg ⊢ + have h := log_le_log (div_pos hM (by norm_num)) hg + rwa [log_div hM.ne' (by norm_num : (2:ℝ) ≠ 0)] at h + exact gaussian_log_anchor (f:=fun g=>log (gaussianSpinPartition n r g)) (gaussianSpinPartition_log_lipschitz hr (hnr.trans hj.le)) + (by exact_mod_cast sqrt_pos.mpr (show (0:ℝ) < n by exact_mod_cast hn)) hc hpc + ((gaussianSpinPartition_positive_probability hj0 hj hr hnr).trans + (measureReal_mono hsub (measure_ne_top _ _))) + +lemma gaussianSpinPartition_lower_tail_bound {j c δ : ℝ} (hj0 : 0 ≤ j) (hj : j < 1) + (hc : 0 < c) (hpc : exp (-2*c^2/π^2) < 1/(4*quadraticGaussianBound j)) (hδ : 0 < δ) + {n : ℕ} (hn : 0 < n) {r : ℝ} (hr : 0 ≤ r) (hnr : (n:ℝ)*r ≤ j) + (hbudget : log 2+c*sqrt (n:ℝ) ≤ δ*(n:ℝ)/2) : + (gaussianCoordinates (Edge n)).real + {g | gaussianSpinPartition n r g/(∫ g,gaussianSpinPartition n r g ∂gaussianCoordinates (Edge n)) < exp (-δ*(n:ℝ))} ≤ + exp (-δ^2*(n:ℝ)/(2*π^2)) := by + have hnp : (0:ℝ) < n := by exact_mod_cast hn + have hM := gaussianSpinPartition_mean_pos (n:=n) hr + have ha := gaussianSpinPartition_log_mean_lower hj0 hj hc hpc hn hr hnr + have hsub : {g | gaussianSpinPartition n r g/(∫ g,gaussianSpinPartition n r g ∂gaussianCoordinates (Edge n)) < exp (-δ*(n:ℝ))} ⊆ + {g | log (gaussianSpinPartition n r g)-(∫ g,log (gaussianSpinPartition n r g) ∂gaussianCoordinates (Edge n)) ≤ -(δ*(n:ℝ)/2)} := by + intro g hg + simp only [mem_ofPred_eq] at hg + have hg' := (div_lt_iff₀ hM).mp hg + have hlog := log_lt_log (gaussianSpinPartition_pos n r g) hg' + rw [log_mul (exp_pos _).ne' hM.ne',log_exp] at hlog + simp only [mem_ofPred_eq] + linarith only [hlog,ha,hbudget] + have htail := gaussianProduct_lower_tail_lipschitz (f:=fun g=>log (gaussianSpinPartition n r g)) + (gaussianSpinPartition_log_lipschitz hr (hnr.trans hj.le)) + (show (0:ℝ≥0) < ⟨sqrt (n:ℝ),sqrt_nonneg _⟩ from sqrt_pos.mpr hnp) + (show 0 ≤ δ*(n:ℝ)/2 by positivity) + have he : -2*(δ*(n:ℝ)/2)^2/(π^2*(sqrt (n:ℝ))^2)= -δ^2*(n:ℝ)/(2*π^2) := by + rw [sq_sqrt hnp.le] + field_simp + change _ ≤ exp (-2*(δ*(n:ℝ)/2)^2/(π^2*(sqrt (n:ℝ))^2)) at htail + rw [he] at htail + exact (measureReal_mono hsub (measure_ne_top _ _)).trans htail + +lemma gaussianSpinPartition_lower_tail_tendsto {j : ℝ} (hj0 : 0 ≤ j) (hj : j < 1) + {δ : ℝ} (hδ : 0 < δ) : + Tendsto (fun n : ℕ=>(gaussianCoordinates (Edge n)).real + {g | gaussianSpinPartition n (j/(n:ℝ)) g/ + (∫ g,gaussianSpinPartition n (j/(n:ℝ)) g ∂gaussianCoordinates (Edge n)) < exp (-δ*(n:ℝ))}) atTop (𝓝 0) := by + obtain ⟨c,hc,hpc⟩ := exists_gaussian_tail_quantile + (show 0 < 1/(4*quadraticGaussianBound j) by + have hB := quadraticGaussianBound_ge_one hj0 hj; positivity) + have hb : ∀ᶠ n : ℕ in atTop, + (gaussianCoordinates (Edge n)).real {g | gaussianSpinPartition n (j/(n:ℝ)) g/ + (∫ g,gaussianSpinPartition n (j/(n:ℝ)) g ∂gaussianCoordinates (Edge n)) < exp (-δ*(n:ℝ))} ≤ + exp (-δ^2*(n:ℝ)/(2*π^2)) := by + filter_upwards [eventually_gt_atTop 0,eventually_sqrt_cost_le_linear hδ hc.le] with n hn hbudget + have hnp : (0:ℝ) < n := by exact_mod_cast hn + apply gaussianSpinPartition_lower_tail_bound hj0 hj hc hpc hδ hn (div_nonneg hj0 hnp.le) _ hbudget + rw [mul_div_cancel₀ _ hnp.ne'] + have ht : Tendsto (fun n : ℕ=>exp (-δ^2*(n:ℝ)/(2*π^2))) atTop (𝓝 0) := by + have hpos : 0 < δ^2/(2*π^2) := by positivity + have hh : Tendsto (fun n : ℕ=>(δ^2/(2*π^2))*(n:ℝ)) atTop atTop := + tendsto_natCast_atTop_atTop.const_mul_atTop hpos + convert tendsto_exp_neg_atTop_nhds_zero.comp hh using 1; ext n; congr 1; ring + exact squeeze_zero' (Eventually.of_forall (fun _=>measureReal_nonneg)) hb ht +end SKGap +end +end + +section +noncomputable section +namespace SKGap +open MeasureTheory ProbabilityTheory Real Filter Set +open scoped BigOperators NNReal Topology + +lemma gaussian_disorder_hasLaw (β : ℝ) (n : ℕ) : + HasLaw (fun g : Disorder n=>fun e=>sqrt (β^2/(n:ℝ))*g e) (disorderLaw β n) + (gaussianCoordinates (Edge n)) := by + have hr : 0 ≤ β^2/(n:ℝ) := by positivity + have hl (e : Edge n) : HasLaw (fun g : Disorder n=>sqrt (β^2/(n:ℝ))*g e) + (gaussianReal 0 (Real.toNNReal (β^2/(n:ℝ)))) (gaussianCoordinates (Edge n)) := by + have h := gaussianReal_const_mul (coordinate_hasLaw (κ:=Edge n) e) (sqrt (β^2/(n:ℝ))) + have hv : (⟨(sqrt (β^2/(n:ℝ)))^2,sq_nonneg _⟩:ℝ≥0)*1=Real.toNNReal (β^2/(n:ℝ)) := by + apply NNReal.eq + change (sqrt (β^2/(n:ℝ)))^2*1=↑(Real.toNNReal (β^2/(n:ℝ))) + rw [mul_one,sq_sqrt hr,Real.coe_toNNReal _ hr] + rw [mul_zero] at h + convert h using 1 + exact congrArg (gaussianReal 0) hv.symm + exact iIndepFun.hasLaw_pi hl ((iIndepFun_pi (fun _ : Edge n=>aemeasurable_id)).comp + (fun _=>fun x : ℝ=>sqrt (β^2/(n:ℝ))*x) (fun _=>by fun_prop)) + +lemma partition_zero_measurable (n : ℕ) : Measurable (fun g : Disorder n=>partition g 0) := by + have he : (fun g : Disorder n=>partition g 0)=gaussianSpinPartition n 1 := by + ext g + rw [gaussianSpinPartition_eq_partition] + simp only [sqrt_one,one_mul] + rw [he] + exact gaussianSpinPartition_measurable n 1 + +lemma disorder_partition_mean (β : ℝ) (n : ℕ) : + (∫ g,partition g 0 ∂disorderLaw β n)= + ∫ g,gaussianSpinPartition n (β^2/(n:ℝ)) g ∂gaussianCoordinates (Edge n) := by + have h := (gaussian_disorder_hasLaw β n).integral_comp (partition_zero_measurable n).aestronglyMeasurable + simpa only [Function.comp_def,gaussianSpinPartition_eq_partition] using h.symm + +theorem disorder_partition_lower_tail {β : ℝ} (hβ : 0 < β) (hβ1 : β < 1) + {δ : ℝ} (hδ : 0 < δ) : + Tendsto (fun n : ℕ=>(disorderLaw β n).real + {g | partition g 0/(∫ g,partition g 0 ∂disorderLaw β n) < exp (-δ*(n:ℝ))}) atTop (𝓝 0) := by + have ht := gaussianSpinPartition_lower_tail_tendsto (sq_nonneg β) (show β^2 < 1 by nlinarith) hδ + apply ht.congr + intro n + rw [← (gaussian_disorder_hasLaw β n).measureReal_eq + (measurableSet_lt ((partition_zero_measurable n).div_const _) measurable_const)] + simp only [disorder_partition_mean,gaussianSpinPartition_eq_partition] +end SKGap +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Gaussian/GaussianTiltIdentity.lean b/lean/OAI/Probability/SKGap/Gaussian/GaussianTiltIdentity.lean new file mode 100644 index 0000000000000000000000000000000000000000..09cacb97348d0844c3a854b68d533c82d2eac559 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Gaussian/GaussianTiltIdentity.lean @@ -0,0 +1,64 @@ +import Mathlib +import OAI.Probability.SKGap.Gaussian.GaussianRegression +import OAI.Probability.SKGap.Gaussian.ProductGaussianDensity + +namespace OAI + +section +noncomputable section +namespace SKGap +open MeasureTheory ProbabilityTheory Real +open scoped BigOperators ENNReal + +lemma gaussianPDFReal_standard_tilt (a x : ℝ) : + gaussianPDFReal a 1 x=gaussianPDFReal 0 1 x*exp (a*x-a^2/2) := by + simp only [gaussianPDFReal,NNReal.coe_one,mul_one,sub_zero] + have he : -(x-a)^2/2= -x^2/2+(a*x-a^2/2) := by ring + rw [he,exp_add] + ring + +lemma gaussianCoordinates_tilt {κ : Type*} [Fintype κ] (a : κ→ℝ) : + (gaussianCoordinates κ).withDensity + (fun g=>ENNReal.ofReal (exp ((∑ i,a i*g i)-(∑ i,a i^2)/2))) = + Measure.pi (fun i=>gaussianReal (a i) 1) := by + have hp (g : κ→ℝ) : (∏ i,gaussianPDFReal (a i) 1 (g i))= + (∏ i,gaussianPDFReal 0 1 (g i))*exp ((∑ i,a i*g i)-(∑ i,a i^2)/2) := by + calc + _ = ∏ i, (gaussianPDFReal 0 1 (g i)*exp (a i*g i-a i^2/2)) := + Finset.prod_congr rfl (fun i _=>gaussianPDFReal_standard_tilt _ _) + _ = _ := by + rw [Finset.prod_mul_distrib,← exp_sum] + congr 2 + rw [Finset.sum_sub_distrib,Finset.sum_div] + change (Measure.pi (fun _ : κ=>gaussianReal 0 1)).withDensity _=_ + rw [GaussianDensity.pi_gaussian_density (fun _ : κ=>0) (fun _=>1) (fun _=>one_ne_zero), + GaussianDensity.pi_gaussian_density a (fun _=>1) (fun _=>one_ne_zero)] + rw [← withDensity_mul _ (GaussianDensity.measurable_productPDF _ _) (by fun_prop)] + congr 1 + ext g + simp only [Pi.mul_apply,hp] + exact (ENNReal.ofReal_mul (Finset.prod_nonneg (fun i _=>gaussianPDFReal_nonneg 0 1 (g i)))).symm + +lemma gaussianCoordinates_shift_hasLaw {κ : Type*} [Fintype κ] (a : κ→ℝ) : + HasLaw (fun g : κ→ℝ => fun i=>g i+a i) + (Measure.pi (fun i=>gaussianReal (a i) 1)) (gaussianCoordinates κ) := by + have hl (i : κ) : HasLaw (fun g : κ→ℝ=>g i+a i) + (gaussianReal (a i) 1) (gaussianCoordinates κ) := by + simpa only [zero_add] using gaussianReal_add_const (coordinate_hasLaw i) (a i) + exact iIndepFun.hasLaw_pi hl ((iIndepFun_pi (fun _ : κ=>aemeasurable_id)).comp + (fun i=>fun x : ℝ=>x+a i) (fun _=>by fun_prop)) + +lemma gaussian_tilt_lintegral {κ : Type*} [Fintype κ] (a : κ→ℝ) + (f : (κ→ℝ)→ℝ≥0∞) (hf : Measurable f) : + (∫⁻ g,ENNReal.ofReal (exp ((∑ i,a i*g i)-(∑ i,a i^2)/2))*f g ∂gaussianCoordinates κ)= + ∫⁻ g,f (fun i=>g i+a i) ∂gaussianCoordinates κ := by + have he := lintegral_withDensity_eq_lintegral_mul (gaussianCoordinates κ) + (f:=fun g=>ENNReal.ofReal (exp ((∑ i,a i*g i)-(∑ i,a i^2)/2))) (by fun_prop) hf + simp only [Pi.mul_apply] at he + rw [← he,gaussianCoordinates_tilt] + exact (gaussianCoordinates_shift_hasLaw a).lintegral_comp hf.aemeasurable |>.symm +end SKGap +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Gaussian/GaussianTiltMass.lean b/lean/OAI/Probability/SKGap/Gaussian/GaussianTiltMass.lean new file mode 100644 index 0000000000000000000000000000000000000000..eee222e6f158d103857a72270baad0382f8f1be5 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Gaussian/GaussianTiltMass.lean @@ -0,0 +1,171 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.EmpiricalLaw +import OAI.Probability.SKGap.Matrix.NormalLogConst + +namespace OAI + +section +noncomputable section +open MeasureTheory ProbabilityTheory InformationTheory Real Set Filter +open scoped NNReal ENNReal Topology +noncomputable section +open Real Set +noncomputable section +open MeasureTheory ProbabilityTheory Real Set Filter +open scoped Topology NNReal ENNReal BoundedContinuousFunction +open MeasureTheory ProbabilityTheory Filter Set Topology Real +open scoped NNReal ENNReal BoundedContinuousFunction +noncomputable section +open Set Filter Topology +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set Topology Real +open scoped NNReal ENNReal BoundedContinuousFunction +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set Topology Real +open scoped NNReal ENNReal BoundedContinuousFunction +namespace SKGap + +variable {ι : Type*} [Fintype ι] [Nonempty ι] + +end SKGap + +namespace SKGap +variable {ι : Type*} [Fintype ι] [Nonempty ι] + +omit [Nonempty ι] in +lemma gaussian_tilt_mass (f : ℝ →ᵇ ℝ) (d : ℝ) {s : ℝ} (hs : 0 < s) (r : ℝ) : + (∫ y : ι → ℝ, exp ((Fintype.card ι : ℝ)*r - + (Fintype.card ι : ℝ)*log (∫ x, exp (f x) ∂gaussianReal d s.toNNReal)) * + (exp (∑ i, f (y i))*productNormal d s y)) = exp ((Fintype.card ι : ℝ)*r) := by + rw [integral_const_mul, product_tiltedNormal_integral f d hs, ← exp_add] + congr 1 + ring + +theorem gaussian_covered_laplace {X : Type*} (C : Finset X) (f : X → ℝ →ᵇ ℝ) + (d₀ s₀ : X → ℝ) (hs₀ : ∀ x ∈ C, 0 < s₀ x) + (d s ψ : (ι → ℝ) → ℝ) (R r : ℝ) {E : Set (ι → ℝ)} (hE : MeasurableSet E) + (hpos : ∀ y ∈ E, 0 < s y) + (hmom : ∀ y ∈ E, ∑ i, (y i)^2 ≤ (Fintype.card ι : ℝ)*R) + (hcover : ∀ y ∈ E, ∃ x ∈ C, + ψ y-(∫ u, f x u ∂empiricalLaw y)+normalDensityError R (d y) (s y) (d₀ x) (s₀ x)+ + log (∫ u, exp (f x u) ∂gaussianReal (d₀ x) (s₀ x).toNNReal) < r) : + (∫⁻ y in E, ENNReal.ofReal (exp ((Fintype.card ι : ℝ)*ψ y)*productNormal (d y) (s y) y)) ≤ + ENNReal.ofReal ((C.card : ℝ)*exp ((Fintype.card ι : ℝ)*r)) := by + classical + let F (x : X) (y : ι → ℝ) : ℝ := + exp ((Fintype.card ι : ℝ)*r-(Fintype.card ι : ℝ)* + log (∫ u, exp (f x u) ∂gaussianReal (d₀ x) (s₀ x).toNNReal)) * + (exp (∑ i, f x (y i))*productNormal (d₀ x) (s₀ x) y) + have hFi (x : X) : Integrable (F x) := + (product_tiltedNormal_integrable (f x) (d₀ x) (s₀ x)).const_mul _ + have hFnn (x : X) (y : ι → ℝ) : 0 ≤ F x y := + mul_nonneg (exp_pos _).le (mul_nonneg (exp_pos _).le (productNormal_nonneg _ _ _)) + have hnorm (x : X) (hx : x ∈ C) : ∫ y, F x y = exp ((Fintype.card ι : ℝ)*r) := + gaussian_tilt_mass (f x) (d₀ x) (hs₀ x hx) r + have hdom (y : ι → ℝ) (hy : y ∈ E) : + exp ((Fintype.card ι : ℝ)*ψ y)*productNormal (d y) (s y) y ≤ ∑ x ∈ C, F x y := by + obtain ⟨x,hx,hc⟩ := hcover y hy + have hdens := normalLogDensity_sum_sub_le (hmom y hy) (d y) (s y) (d₀ x) (s₀ x) + change _ ≤ (Fintype.card ι : ℝ)*normalDensityError R (d y) (s y) (d₀ x) (s₀ x) at hdens + have hn : (0 : ℝ) < Fintype.card ι := by exact_mod_cast (Fintype.card_pos (α := ι)) + have hc' := mul_lt_mul_of_pos_left hc hn + have hemp := card_mul_integral_empiricalLaw y (f x) + have hsmall : exp ((Fintype.card ι : ℝ)*ψ y)*productNormal (d y) (s y) y ≤ F x y := by + dsimp only [F] + rw [productNormal_eq_exp _ (hpos y hy), productNormal_eq_exp _ (hs₀ x hx), + ← exp_add, ← exp_add, ← exp_add] + apply exp_le_exp.mpr + nlinarith + exact hsmall.trans (Finset.single_le_sum (fun a _ => hFnn a y) hx) + have hsumI : Integrable (fun y => ∑ x ∈ C, F x y) := integrable_finsetSum C (fun x _ => hFi x) + calc + _ ≤ ∫⁻ y in E, ENNReal.ofReal (∑ x ∈ C, F x y) := lintegral_mono_ae + ((ae_restrict_mem hE).mono (fun y hy => ENNReal.ofReal_le_ofReal (hdom y hy))) + _ ≤ ∫⁻ y, ENNReal.ofReal (∑ x ∈ C, F x y) := lintegral_mono' Measure.restrict_le_self (fun _ => le_rfl) + _ = ENNReal.ofReal (∫ y, ∑ x ∈ C, F x y) := + (ofReal_integral_eq_lintegral_ofReal hsumI (ae_of_all _ (fun y => Finset.sum_nonneg (fun x _ => hFnn x y)))).symm + _ = _ := by + rw [integral_finsetSum C (fun x _ => hFi x)] + simp_rw [Finset.sum_congr rfl hnorm] + simp + +end SKGap + +namespace SKGap + +theorem gaussian_compact_laplace {X : Type*} [TopologicalSpace X] {K : Set X} + (hK : IsCompact K) {P : X → ProbabilityMeasure ℝ} {d s ψ : X → ℝ} + (hP : ContinuousOn P K) (hd : ContinuousOn d K) (hs : ContinuousOn s K) + (hψ : ContinuousOn ψ K) (hpos : ∀ x ∈ K, 0 < s x) (R r : ℝ) + (hW : ∀ x ∈ K, ∃ f : ℝ →ᵇ ℝ, ψ x-(∫ y, f y ∂P x)+ + log (∫ y, exp (f y) ∂gaussianReal (d x) (s x).toNNReal) < r) : + ∃ M : ℕ, ∀ n : ℕ, ∀ hn : 0 < n, ∀ z : (Fin n → ℝ) → X, + ∀ E : Set (Fin n → ℝ), MeasurableSet E → + (∀ y ∈ E, z y ∈ K) → + (∀ y ∈ E, P (z y) = @empiricalLaw (Fin n) _ ⟨⟨0,hn⟩⟩ y) → + (∀ y ∈ E, ∑ i, (y i)^2 ≤ (n:ℝ)*R) → + (∫⁻ y in E, ENNReal.ofReal (exp ((n:ℝ)*ψ (z y))*productNormal (d (z y)) (s (z y)) y)) ≤ + ENNReal.ofReal ((M:ℝ)*exp ((n:ℝ)*r)) := by + classical + obtain ⟨C,f,hC⟩ := finite_gaussian_test_cover hK hP hd hs hψ hpos R r hW + refine ⟨C.card, ?_⟩ + intro n hn z E hE hz hemp hmom + let : Nonempty (Fin n) := ⟨⟨0,hn⟩⟩ + have hh := gaussian_covered_laplace C f (fun x : K => d x) (fun x : K => s x) + (fun x _ => hpos x x.2) (fun y => d (z y)) (fun y => s (z y)) + (fun y => ψ (z y)) R r hE (fun y hy => hpos (z y) (hz y hy)) + (by simpa only [Fintype.card_fin] using hmom) (fun y hy => by + obtain ⟨x,hx,hcx⟩ := hC (z y) (hz y hy) + rw [hemp y hy] at hcx + exact ⟨x,hx,hcx⟩) + simpa only [Fintype.card_fin] using hh + +lemma absorb_finite_exponential_factor (M : ℕ) {ε : ℝ} (hε : 0 < ε) : + ∃ N : ℕ, ∀ n ≥ N, ∀ r : ℝ, + (M:ℝ)*exp ((n:ℝ)*r) ≤ exp ((n:ℝ)*(r+ε)) := by + obtain ⟨N,hN⟩ := exists_nat_gt (log ((M:ℝ)+1)/ε) + refine ⟨N,?_⟩ + intro n hn r + have hcast : (N:ℝ) ≤ n := by exact_mod_cast hn + have hnlog : log ((M:ℝ)+1) ≤ (n:ℝ)*ε := by + have h := (div_lt_iff₀ hε).mp hN + nlinarith + have he : (M:ℝ) ≤ exp ((n:ℝ)*ε) := by + have h := exp_le_exp.mpr hnlog + rw [exp_log (by positivity)] at h + linarith + calc + _ ≤ exp ((n:ℝ)*ε)*exp ((n:ℝ)*r) := mul_le_mul_of_nonneg_right he (exp_pos _).le + _ = _ := by rw [← exp_add]; congr 1; ring + +theorem gaussian_compact_rate {X : Type*} [TopologicalSpace X] {K : Set X} + (hK : IsCompact K) {P : X → ProbabilityMeasure ℝ} {d s ψ : X → ℝ} + (hP : ContinuousOn P K) (hd : ContinuousOn d K) (hs : ContinuousOn s K) + (hψ : ContinuousOn ψ K) (hpos : ∀ x ∈ K, 0 < s x) (R r : ℝ) + (hW : ∀ x ∈ K, ∃ f : ℝ →ᵇ ℝ, ψ x-(∫ y, f y ∂P x)+ + log (∫ y, exp (f y) ∂gaussianReal (d x) (s x).toNNReal) < r) + {ε : ℝ} (hε : 0 < ε) : + ∃ N : ℕ, ∀ n ≥ N, ∀ hn : 0 < n, ∀ z : (Fin n → ℝ) → X, + ∀ E : Set (Fin n → ℝ), MeasurableSet E → + (∀ y ∈ E, z y ∈ K) → + (∀ y ∈ E, P (z y) = @empiricalLaw (Fin n) _ ⟨⟨0,hn⟩⟩ y) → + (∀ y ∈ E, ∑ i, (y i)^2 ≤ (n:ℝ)*R) → + (∫⁻ y in E, ENNReal.ofReal (exp ((n:ℝ)*ψ (z y))*productNormal (d (z y)) (s (z y)) y)) ≤ + ENNReal.ofReal (exp ((n:ℝ)*(r+ε))) := by + obtain ⟨M,hM⟩ := gaussian_compact_laplace hK hP hd hs hψ hpos R r hW + obtain ⟨N,hN⟩ := absorb_finite_exponential_factor M hε + refine ⟨N,?_⟩ + intro n hn hn' z E hE hz hemp hmom + exact (hM n hn' z E hE hz hemp hmom).trans (ENNReal.ofReal_le_ofReal (hN n hn r)) + +end SKGap + +end +end +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Gaussian/GaussianVectorMoments.lean b/lean/OAI/Probability/SKGap/Gaussian/GaussianVectorMoments.lean new file mode 100644 index 0000000000000000000000000000000000000000..c55342dd8ccba8257e03910a67c45dc7f5ebcd68 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Gaussian/GaussianVectorMoments.lean @@ -0,0 +1,63 @@ +import Mathlib +import OAI.Probability.SKGap.Gaussian.GaussianQuadratic +import OAI.Probability.SKGap.Gaussian.GaussianRegression + +namespace OAI + +section +noncomputable section +namespace SKGap +open MeasureTheory ProbabilityTheory Matrix Real +open scoped BigOperators ENNReal NNReal + +lemma gaussian_integral_fourth_variance (v : ℝ≥0) : + (∫ x : ℝ,x^4 ∂gaussianReal 0 v)=3*(v:ℝ)^2 := by + have hm : (gaussianReal 0 1).map (fun x : ℝ => sqrt (v:ℝ)*x)=gaussianReal 0 v := by + rw [gaussianReal_map_const_mul] + congr 1 + · simp + · ext; simp [Real.sq_sqrt v.coe_nonneg] + rw [← hm,integral_map (by fun_prop) (by fun_prop)] + simp only [mul_pow,integral_const_mul,gaussian_integral_fourth] + rw [show sqrt (v:ℝ)^4=(v:ℝ)^2 by rw [show 4=2*2 by norm_num,pow_mul,Real.sq_sqrt v.coe_nonneg]] + ring + +lemma gaussian_fourth_integrable (v : ℝ≥0) : + Integrable (fun x : ℝ => x^4) (gaussianReal 0 v) := by + apply (integrable_norm_iff (by fun_prop)).mp + simpa only [id_eq,norm_pow] using + (IsGaussian.memLp_id (gaussianReal 0 v) (4:ℝ≥0∞) (by norm_num)).integrable_norm_pow' + +lemma linear_gaussian_fourth {κ : Type*} [Fintype κ] [DecidableEq κ] (a : κ → ℝ) : + (∫ g,(∑ i,a i*g i)^4 ∂gaussianCoordinates κ)=3*(∑ i,a i^2)^2 := by + let A : Matrix Unit κ ℝ := fun _ => a + have hg := (matrix_sample_gaussian A).eval () + change HasGaussianLaw (fun g : κ → ℝ => ∑ i,a i*g i) (gaussianCoordinates κ) at hg + have hl : HasLaw _ _ _ := ⟨hg.aemeasurable,hg.map_eq_gaussianReal⟩ + have hm := linear_gaussian_mean a + have hv : Var[fun g => ∑ i,a i*g i;gaussianCoordinates κ]=∑ i,a i^2 := by + rw [← covariance_self hg.aemeasurable] + simpa only [sq] using linear_gaussian_covariance a a + change HasLaw (fun g : κ → ℝ => ∑ i,a i*g i) _ _ at hl + rw [hm,hv] at hl + have he := hl.integral_comp (f := fun x : ℝ => x^4) (by fun_prop) + simp only [Function.comp_def] at he + rw [he,gaussian_integral_fourth_variance] + rw [Real.coe_toNNReal _ (Finset.sum_nonneg (fun i _ => sq_nonneg (a i)))] + +lemma linear_gaussian_fourth_integrable {κ : Type*} [Fintype κ] (a : κ → ℝ) : + Integrable (fun g => (∑ i,a i*g i)^4) (gaussianCoordinates κ) := by + let A : Matrix Unit κ ℝ := fun _ => a + have hg := (matrix_sample_gaussian A).eval () + change HasGaussianLaw (fun g : κ → ℝ => ∑ i,a i*g i) (gaussianCoordinates κ) at hg + have hl : HasLaw _ _ _ := ⟨hg.aemeasurable,hg.map_eq_gaussianReal⟩ + rw [linear_gaussian_mean a] at hl + have hi := gaussian_fourth_integrable (Var[fun g : κ → ℝ => ∑ i,a i*g i;gaussianCoordinates κ].toNNReal) + rw [← hl.map_eq] at hi + exact (integrable_map_measure (by fun_prop) hl.aemeasurable).mp hi + +end SKGap +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Gaussian/IndependentBoundedAverageTailLaw.lean b/lean/OAI/Probability/SKGap/Gaussian/IndependentBoundedAverageTailLaw.lean new file mode 100644 index 0000000000000000000000000000000000000000..969d37287bff670803013f7d2847f1395b2da4ca --- /dev/null +++ b/lean/OAI/Probability/SKGap/Gaussian/IndependentBoundedAverageTailLaw.lean @@ -0,0 +1,234 @@ +import Mathlib +import OAI.Probability.SKGap.Entropy.ProdFst + +namespace OAI + +section +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open scoped BigOperators +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open scoped BigOperators +open scoped BigOperators NNReal ENNReal +open MeasureTheory Metric Set +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators NNReal ENNReal Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Set +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators ENNReal NNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Matrix +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators ENNReal NNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal +open scoped BigOperators +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise NNReal ENNReal +open scoped BigOperators +open Filter Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +namespace SKGapCutoff.Regression +lemma independent_bounded_average_tail_law {Ω : Type*} [MeasurableSpace Ω] + {μ : Measure Ω} [IsProbabilityMeasure μ] + {F : Type*} [MeasurableSpace F] (τ : Measure F) {n : ℕ} (hn : 0 < n) + (X : Fin n → Ω → F) (hXi : iIndepFun X μ) + (hX : ∀ i, HasLaw (X i) τ μ) (f : Fin n → F → ℝ) + (hf : ∀ i, Measurable (f i)) (B : ℝ) (hB : 0 ≤ B) + (hbound : ∀ i z, |f i z| ≤ B) (ε : ℝ) (hε : 0 ≤ ε) : + μ {g | ε ≤ |((∑ i, f i (X i g)) - ∑ i, ∫ z, f i z ∂τ)/(n:ℝ)|} ≤ + 2 * ENNReal.ofReal (Real.exp (-(ε^2*(n:ℝ))/(2*B^2))) := by + let m (i : Fin n) := ∫ z, f i z ∂τ + have hi : iIndepFun (fun i (g : Ω) => f i (X i g)-m i) μ := + hXi.comp (fun i z => f i z-m i) (fun i => (hf i).sub_const (m i)) + have hm (i : Fin n) : (∫ g : Ω, f i (X i g) ∂μ) = m i := + (hX i).integral_comp (hf i).aestronglyMeasurable + have hsub (i : Fin n) : HasSubgaussianMGF (fun g : Ω => f i (X i g)-m i) + ((‖B-(-B)‖₊/2)^2) μ := by + have hb : ∀ᵐ g : Ω ∂μ, f i (X i g) ∈ Set.Icc (-B) B := + Filter.Eventually.of_forall (fun g => abs_le.mp (hbound i (X i g))) + simpa only [hm] using hasSubgaussianMGF_of_mem_Icc + (show AEMeasurable (fun g : Ω => f i (X i g)) μ from + (hf i).comp_aemeasurable (hX i).aemeasurable) hb + have hh := subgaussian_abs_tail + (HasSubgaussianMGF.sum_of_iIndepFun hi (s := Finset.univ) (fun i _ => hsub i)) + (ε*n) (by positivity) + have he (g : Ω) : + (ε*(n:ℝ) ≤ |∑ i, (f i (X i g)-m i)|) ↔ + ε ≤ |((∑ i, f i (X i g)) - ∑ i, m i)/(n:ℝ)| := by + rw [Finset.sum_sub_distrib, abs_div, abs_of_pos (show (0:ℝ) < n from Nat.cast_pos.mpr hn)] + exact (le_div_iff₀ (Nat.cast_pos.mpr hn)).symm + simp only [he] at hh + convert hh using 1 + congr 3 + simp only [Finset.sum_const, Finset.card_univ, Fintype.card_fin, nsmul_eq_mul, + NNReal.coe_mul, NNReal.coe_natCast, NNReal.coe_pow, NNReal.coe_div, NNReal.coe_ofNat, + coe_nnnorm, Real.norm_eq_abs] + rw [abs_of_nonneg (by linarith : 0 ≤ B-(-B))] + have hn0 : (n:ℝ) ≠ 0 := Nat.cast_ne_zero.mpr (Nat.ne_of_gt hn) + by_cases hB0 : B=0 + · simp [hB0] + · field_simp + ring + +lemma probability_average_lipschitz + {E F : Type*} [PseudoMetricSpace E] [PseudoMetricSpace F] + [MeasurableSpace F] [BorelSpace F] + (τ : Measure F) [IsProbabilityMeasure τ] + {f : E × F → ℝ} {K : ℝ≥0} (hf : LipschitzWith K f) + (B : ℝ) (hB : ∀ z, |f z| ≤ B) : + LipschitzWith K (fun x => ∫ y, f (x,y) ∂τ) := by + have hi (x : E) : Integrable (fun y => f (x,y)) τ := by + apply integrable_bounded_lipschitz τ (K := K) _ B (fun y => hB (x,y)) + apply LipschitzWith.of_dist_le_mul + intro y z + simpa only [Prod.dist_eq, dist_self, max_eq_right (dist_nonneg)] using + hf.dist_le_mul (x,y) (x,z) + apply LipschitzWith.of_dist_le_mul + intro x y + rw [Real.dist_eq, ← integral_sub (hi x) (hi y)] + have hh := norm_integral_le_of_norm_le_const (μ := τ) + (C := (K:ℝ)*dist x y) (f := fun z => f (x,z)-f (y,z)) + (Filter.Eventually.of_forall (fun z => by + simpa only [Real.norm_eq_abs, ← Real.dist_eq, Prod.dist_eq, dist_self, + max_eq_left (dist_nonneg)] using hf.dist_le_mul (x,z) (y,z))) + simpa using hh + +lemma probability_average_bound {E F : Type*} [MeasurableSpace F] + (τ : Measure F) [IsProbabilityMeasure τ] {f : E × F → ℝ} + (B : ℝ) (hB : ∀ z, |f z| ≤ B) (x : E) : + |∫ z, f (x,z) ∂τ| ≤ B := by + have h := norm_integral_le_of_norm_le_const (μ := τ) + (C := B) (f := fun z => f (x,z)) + (Filter.Eventually.of_forall (fun z => by simpa only [Real.norm_eq_abs] using hB (x,z))) + simpa using h + +lemma iid_seed_empirical_tail + {E F H : Type*} [MeasurableSpace E] [MeasurableSpace F] [MeasurableSpace H] + (τ : Measure F) [IsProbabilityMeasure τ] (ρ : Measure H) [IsProbabilityMeasure ρ] + {n : ℕ} (hn : 0 < n) (X : H → Fin n → E) (hX : Measurable X) + (f : E × F → ℝ) (hf : Measurable f) + (B : ℝ) (hB : 0 ≤ B) (hbound : ∀ z, |f z| ≤ B) (ε : ℝ) (hε : 0 ≤ ε) : + (ρ.prod (Measure.pi (fun _ : Fin n => τ))) {z | ε ≤ + |((∑ i, f (X z.1 i,z.2 i)) - ∑ i, ∫ w, f (X z.1 i,w) ∂τ)/(n:ℝ)|} ≤ + 2 * ENNReal.ofReal (Real.exp (-(ε^2*(n:ℝ))/(2*B^2))) := by + have hM : Measurable (fun x => ∫ y, f (x,y) ∂τ) := + (show StronglyMeasurable (Function.uncurry (fun x y => f (x,y))) from + hf.stronglyMeasurable).integral_prod_right.measurable + apply probability_prod_section_bound + · apply measurableSet_le measurable_const + apply Measurable.abs + apply Measurable.div_const + apply Measurable.sub + · apply Finset.measurable_sum + intro i _ + exact hf.comp ((((measurable_pi_apply i).comp hX).comp measurable_fst).prodMk + ((measurable_pi_apply i).comp measurable_snd)) + · apply Finset.measurable_sum + intro i _ + exact hM.comp (((measurable_pi_apply i).comp hX).comp measurable_fst) + · intro h + exact independent_bounded_average_tail_law τ hn + (fun i (z : Fin n → F) => z i) + (iIndepFun_pi (fun _ => measurable_id.aemeasurable)) + (fun i => (measurePreserving_eval (fun _ : Fin n => τ) i).hasLaw) + (fun i w => f (X h i,w)) (fun i => hf.comp measurable_prodMk_left) + B hB (fun i w => hbound _) ε hε + +theorem ExponentialEmpiricalConcentration.iid_seed + {E F : Type*} [PseudoMetricSpace E] [MeasurableSpace E] [BorelSpace E] + [SecondCountableTopology E] [PseudoMetricSpace F] [MeasurableSpace F] [BorelSpace F] + [SecondCountableTopology F] + {H : ℕ → Type*} [∀ n, MeasurableSpace (H n)] + (ρ : ∀ n, Measure (H n)) [∀ n, IsProbabilityMeasure (ρ n)] + (ν : Measure E) [IsProbabilityMeasure ν] (τ : Measure F) [IsProbabilityMeasure τ] + (X : ∀ n, H n → Fin n → E) (hXm : ∀ n, Measurable (X n)) + (hX : ExponentialEmpiricalConcentration ρ X ν) : + ExponentialEmpiricalConcentration + (fun n => (ρ n).prod (Measure.pi (fun _ : Fin n => τ))) + (fun n z i => (X n z.1 i,z.2 i)) (ν.prod τ) := by + intro f K hf B hbound ε hε + let D := |B|+1 + have hD : 0 < D := by dsimp [D]; positivity + have hb : ∀ z, |f z| ≤ D := fun z => (hbound z).trans (by dsimp [D]; linarith [le_abs_self B]) + let ψ : E → ℝ := fun x => ∫ y, f (x,y) ∂τ + have hp := probability_average_lipschitz τ hf D hb + have hpb := probability_average_bound τ D hb + have hm : ∫ z, f z ∂ν.prod τ = ∫ x, ψ x ∂ν := + integral_prod f (integrable_bounded_lipschitz _ hf D hb) + have hold := ((hX.average ψ hp D hpb) (ε/2) (by positivity)).prod_fst + (fun n => Measure.pi (fun _ : Fin n => τ)) + have hnew : ExponentiallyRare + (fun n => (ρ n).prod (Measure.pi (fun _ : Fin n => τ))) + (fun n => {z | ε/2 ≤ |((∑ i, f (X n z.1 i,z.2 i)) - ∑ i, ψ (X n z.1 i))/(n:ℝ)|}) := by + refine ⟨2,ε^2/(8*D^2),by norm_num,by positivity,?_⟩ + filter_upwards [eventually_ge_atTop 1] with n hn + have hh := iid_seed_empirical_tail τ (ρ n) hn (X n) (hXm n) f hf.continuous.measurable + D hD.le hb (ε/2) (by positivity) + have he : -((ε/2)^2*(n:ℝ))/(2*D^2) = -(ε^2/(8*D^2))*(n:ℝ) := by + field_simp + ring + simpa only [ψ, he, ENNReal.ofReal_mul (by norm_num : (0:ℝ) ≤ 2), ENNReal.ofReal_ofNat] + using hh + apply (hold.union hnew).mono + refine Filter.Eventually.of_forall ?_ + intro n z hz + change ε ≤ |(∑ i, f (X n z.1 i,z.2 i))/(n:ℝ)-∫ w, f w ∂ν.prod τ| at hz + rw [hm] at hz + by_cases ho : ε/2 ≤ dist ((∑ i, ψ (X n z.1 i))/(n:ℝ)) (∫ x, ψ x ∂ν) + · exact Or.inl ho + apply Or.inr + by_contra hn + have ho' : |(∑ i, ψ (X n z.1 i))/(n:ℝ) - ∫ x, ψ x ∂ν| < ε/2 := lt_of_not_ge ho + have hn' : |((∑ i, f (X n z.1 i,z.2 i)) - ∑ i, ψ (X n z.1 i))/(n:ℝ)| < ε/2 := + lt_of_not_ge hn + rw [sub_div] at hn' + have ht := abs_add_le + ((∑ i, f (X n z.1 i,z.2 i))/(n:ℝ) - (∑ i, ψ (X n z.1 i))/(n:ℝ)) + ((∑ i, ψ (X n z.1 i))/(n:ℝ) - ∫ x, ψ x ∂ν) + rw [sub_add_sub_cancel] at ht + linarith + +end SKGapCutoff.Regression + +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology + +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Gaussian/LiteralWeakTail.lean b/lean/OAI/Probability/SKGap/Gaussian/LiteralWeakTail.lean new file mode 100644 index 0000000000000000000000000000000000000000..6f482e906076a82d7eea4129c207b049d9db071a --- /dev/null +++ b/lean/OAI/Probability/SKGap/Gaussian/LiteralWeakTail.lean @@ -0,0 +1,108 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.LiteralLocalWeak + +namespace OAI + +section + +noncomputable section +open scoped BigOperators Matrix.Norms.Frobenius +namespace SKGapCutoff.Recipe +open Primary Static SKGap.Stein SKGap.Noncrossing.Primary SKGap.Noncrossing.Primary.Tensor.Series SKGap.Noncrossing.ClosedMarked +universe u +variable {Ω : Type u} {n : Ω→ℕ} {M : ℕ} +theorem literal_local_weak_terminal_targets (j : ℝ) (J : ∀b,Interaction (n b)) + (h : ∀b,Fin (n b)→ℝ) (l : Fin M) (f : KernelExpr) + (a c : ∀b,Spin (n b)→ℝ) (r e : ∀b,Fin (n b)→ℝ) + (w y : ∀b,VectorFields (n b)) (E : ∀b,Set (Spin (n b))) + (hn : ∀b,0Real.sqrt (n b:ℝ)*c b v) x‖≤Vc) + (heq : ∀b x,x∈E b→LiteralEquations (J b) j f (fld j (J b) (h b) l.val) + (mag j (J b) (h b) l.val) (w b) (y b) (a b) (c b) (r b) (e b) x) + (hdiag : ∀b x,x∈flipNeighborhood (E b)→LiteralInitialDiagnostics + (literalInitial (J b) j (Real.sqrt (n b:ℝ)) f (fld j (J b) (h b) l.val) + (mag j (J b) (h b) l.val) (a b) (c b) (r b) (e b)) + (w b) (y b) (primaryTree j (J b) (h b) x l.val) x V S F (literalResidualBudget j f R Bc l.val)) + (P : ∀b,Observables (n b)) (hP : ∀b x,0≤P b x) (hp : ∀b,∑x,P b x=1) + (hm : ∀b x i,conditionalMean (P b) x i=mag j (J b) (h b) 1 x i) + (hJ : ∀b,(J b).IsSymm) + (hw : ∀b x,x∈flipNeighborhood (E b)→ClosedWordTestBound j + (fun i=>phi (fld j (J b) (h b) l.val x i) (r b i) (a b x)) (J b) (literalResidualBudget j f R Bc l.val) W (2*(2+2*l.val)+5)) + (hd : ∀b x,x∈flipNeighborhood (E b)→ClosedWordDiagramBound j + (fun i=>phi (fld j (J b) (h b) l.val x i) (r b i) (a b x)) (J b) (literalResidualBudget j f R Bc l.val) C (2*M+2*(2+2*l.val)+4)) : + (∀p≤l.val,LocalUniformWeak E P (fun b x=>∑i,residual j (J b) (h b) p x i*w b x i)) ∧ + LocalUniformWeak E P (fun b x=>∑i,residual j (J b) (h b) l.val x i*y b x i) ∧ + LocalUniformWeak E P (fun b x=>∑i,residual j (J b) (h b) l.val x i* + (Real.tanh (fld j (J b) (h b) l.val x i)/Real.sqrt (n b:ℝ))) ∧ + LocalUniformMultiplier E (fun b=>siteMean (fun x i=>phi (fld j (J b) (h b) l.val x i) (r b i) (a b x))) ∧ + LocalUniformMultiplier E (fun b x=>j*onsager j (J b) (h b) l.val x) ∧ + LocalUniformMultiplier E (fun b x=>Real.sqrt (n b:ℝ)*c b x) := by + let Kt:=2+|literalCoefficientBudget f j R Bc| + have hKt : 2≤Kt := by dsimp [Kt];linarith [abs_nonneg (literalCoefficientBudget f j R Bc)] + have hKt0 : 0≤Kt:=by linarith + have hA : 1≤literalResidualBudget j f R Bc l.val := + (by linarith : 1≤Kt).trans (residualCoefficientBudget_ge j hKt0 l.val 0) + have C:=literal_finite_control j J h l f a c r e w y E hn he + hK hB hBc hVa hVc hA hV hS hF hW hC hop hformal ha hc hDa hDc heq hdiag + (2+2*l.val) hw hd + have H:=literal_full_local_family j J h l f a c r e w y E hn he hBc ha hc heq + have hclass : literalCoefficientBudget f j R Bc≤Kt := by + dsimp [Kt];linarith [le_abs_self (literalCoefficientBudget f j R Bc)] + have HH:=H.mono le_rfl le_rfl le_rfl hclass + have hb:=residualCoefficientBudget_antitone j hKt0 l.val + have rule:=local_uniform_residual_rule C hP hp hm hn hJ Sum.inl (fun _ _=>rfl) + (residualCoefficientBudget j Kt l.val) hb l.val l.isLt + (fun p _=>hb (Nat.zero_le p)) + (fun p _=>hKt.trans (residualCoefficientBudget_ge j hKt0 l.val p)) + (fun p hp=>le_of_eq (residualCoefficientBudget_step j Kt hp)) + let D:=fun b=>literalFullData j (J b) (h b) l f (a b) (c b) (r b) (e b) + have allw : ∀p≤l.val,LocalUniformWeak E P (fun b x=>∑i,residual j (J b) (h b) p x i*w b x i) := by + intro p hp + have H':=HH.mono hp le_rfl le_rfl (residualCoefficientBudget_ge j hKt0 l.val p) + have hh:=rule p hp D 1 H' (by omega) + apply hh.congr_on + intro b x hx + rw [(H.initial b x hx).1] + refine ⟨allw,?_,?_,?_,?_,?_⟩ + · have H' := HH.appendAuxiliary + have hh:=rule l.val le_rfl (fun b=>(D b).appendAuxiliary 1) 2 + (H'.mono le_rfl le_rfl (by norm_num) (residualCoefficientBudget_ge j hKt0 l.val l.val)) (by omega) + apply hh.congr_on + intro b x hx + rw [show 2=1+1 from rfl,OrdinaryData.appendAuxiliary_started_source,(H.initial b x hx).2] + · have H' := HH.appendPrimary hn hKt l le_rfl + have hh:=rule l.val le_rfl (fun b=>(D b).appendPrimary 1 l) 2 + (H'.mono le_rfl le_rfl (by norm_num) (residualCoefficientBudget_ge j hKt0 l.val l.val)) (by omega) + apply hh.congr + intro b x + rw [show 2=1+1 from rfl,OrdinaryData.appendPrimary_started_source] + rfl + + · have hh:=C.means D 1 l.val Kt HH (by omega) (residualCoefficientBudget_ge j hKt0 l.val 0) 0 + apply hh.congr + intro b x + congr 1 + ext v i + dsimp only [D,literalFullData] + rw [OrdinaryData.unitPullback_auxCoefficient _ l Sum.inr _ _ _ rfl rfl] + exact literalInitial_coefficient _ _ _ _ _ _ _ _ _ _ _ _ + · exact C.local_onsager_multiplier l.val l.isLt.le + · refine ⟨Bc,Vc,hBc,hVc,fun b x hx=>hc b x (Or.inl hx),?_⟩ + intro b x hx + simpa only [norm_derivativeVector_sq] using + pow_le_pow_left₀ (norm_nonneg _) (hDc b x (Or.inl hx)) 2 + +end SKGapCutoff.Recipe + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Gaussian/LocalGaussianMoments.lean b/lean/OAI/Probability/SKGap/Gaussian/LocalGaussianMoments.lean new file mode 100644 index 0000000000000000000000000000000000000000..700313e468f04be4b9e95b0034351eef08384194 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Gaussian/LocalGaussianMoments.lean @@ -0,0 +1,165 @@ +import Mathlib +import OAI.Probability.SKGap.Gaussian.GaussianVectorMoments +import OAI.Probability.SKGap.Localization.LocalWhitening + +namespace OAI + +section +noncomputable section +namespace SKGap +open MeasureTheory ProbabilityTheory Matrix Real +open scoped BigOperators ENNReal NNReal + +lemma matrix_fourth_sum_integrable {ι κ : Type*} [Fintype ι] [Fintype κ] + (A : Matrix ι κ ℝ) : + Integrable (fun g => ∑ i,((A*ᵥg) i)^4) (gaussianCoordinates κ) := by + apply integrable_finsetSum + intro i _ + exact linear_gaussian_fourth_integrable (A i) + +lemma matrix_fourth_sum_mean {ι κ : Type*} [Fintype ι] [Fintype κ] [DecidableEq κ] + (A : Matrix ι κ ℝ) : + (∫ g,∑ i,((A*ᵥg) i)^4 ∂gaussianCoordinates κ)=3*∑ i,(∑ k,A i k^2)^2 := by + simp only [Matrix.mulVec,dotProduct] + rw [integral_finsetSum _ (fun i _ => linear_gaussian_fourth_integrable (A i)),Finset.mul_sum] + apply Finset.sum_congr rfl + intro i _ + exact linear_gaussian_fourth (A i) + +lemma matrix_fourth_sum_bound {n m : ℕ} (A : Matrix (Fin n) (Fin m) ℝ) + {c : ℝ} (hc : 0 ≤ c) (hb : ∀ i,∑ k,A i k^2 ≤ c) : + (∫ g,∑ i,((A*ᵥg) i)^4 ∂gaussianCoordinates (Fin m)) ≤ 3*(n:ℝ)*c^2 := by + rw [matrix_fourth_sum_mean] + have hs : (∑ i : Fin n,(∑ k,A i k^2)^2) ≤ ∑ _i : Fin n,c^2 := by + apply Finset.sum_le_sum + intro i _ + exact (sq_le_sq₀ (Finset.sum_nonneg (fun k _ => sq_nonneg _)) hc).mpr (hb i) + simp only [Finset.sum_const,Finset.card_univ,Fintype.card_fin,nsmul_eq_mul] at hs + nlinarith + +lemma matrix_norm_fourth_integrable {n m : ℕ} (A : Matrix (Fin n) (Fin m) ℝ) : + Integrable (fun g => vectorNorm (A*ᵥg)^4) (gaussianCoordinates (Fin m)) := by + apply ((matrix_fourth_sum_integrable A).const_mul (n:ℝ)).mono' ?_ ?_ + · have he : (fun g => vectorNorm (A*ᵥg)^4)=fun g => (∑ i,((A*ᵥg) i)^2)^2 := by + funext g + rw [show vectorNorm (A*ᵥg)^4=(vectorNorm (A*ᵥg)^2)^2 by ring,vectorNorm_sq] + rfl + rw [he] + fun_prop + · filter_upwards [] with g + rw [Real.norm_eq_abs,abs_of_nonneg (by positivity)] + exact vectorNorm_fourth_le (A*ᵥg) + +lemma matrix_norm_fourth_bound {n m : ℕ} (A : Matrix (Fin n) (Fin m) ℝ) + {c : ℝ} (hc : 0 ≤ c) (hb : ∀ i,∑ k,A i k^2 ≤ c) : + (∫ g,vectorNorm (A*ᵥg)^4 ∂gaussianCoordinates (Fin m)) ≤ 3*(n:ℝ)^2*c^2 := by + calc + _ ≤ ∫ g,(n:ℝ)*(∑ i,((A*ᵥg) i)^4) ∂gaussianCoordinates (Fin m) := + integral_mono (matrix_norm_fourth_integrable A) + ((matrix_fourth_sum_integrable A).const_mul _) (fun g => vectorNorm_fourth_le _) + _ = (n:ℝ)*(∫ g,∑ i,((A*ᵥg) i)^4 ∂gaussianCoordinates (Fin m)) := integral_const_mul _ _ + _ ≤ (n:ℝ)*(3*(n:ℝ)*c^2) := mul_le_mul_of_nonneg_left (matrix_fourth_sum_bound A hc hb) (Nat.cast_nonneg _) + _ = _ := by ring + +theorem localGaussian_fourth_moments {n : ℕ} {U : Matrix (Fin n) (Fin n) ℝ} + (hU : U.IsHermitian) {γ σ : ℝ} (hγ : 0 < γ) + (hbound : ∀ g : Field n, vectorNorm (U*ᵥg) ≤ vectorNorm g/sqrt γ) : + (∫ g,∑ i,((σ • U)*ᵥg) i^4 ∂gaussianCoordinates (Fin n)) ≤ 3*(n:ℝ)*σ^4/γ^2 ∧ + (∫ g,vectorNorm ((σ • U)*ᵥg)^4 ∂gaussianCoordinates (Fin n)) ≤ 3*(n:ℝ)^2*σ^4/γ^2 := by + have hb (i : Fin n) : ∑ k,(σ • U) i k^2 ≤ σ^2/γ := by + have hh := symmetric_row_sq_bound hU (inv_nonneg.mpr (sqrt_nonneg γ)) + (fun g => by simpa only [div_eq_mul_inv,mul_comm] using hbound g) i + rw [inv_pow,Real.sq_sqrt hγ.le] at hh + simp only [Matrix.smul_apply,smul_eq_mul,mul_pow,← Finset.mul_sum] + exact (mul_le_mul_of_nonneg_left hh (sq_nonneg σ)).trans_eq (by ring) + have h1 := matrix_fourth_sum_bound (σ • U) (div_nonneg (sq_nonneg σ) hγ.le) hb + have h2 := matrix_norm_fourth_bound (σ • U) (div_nonneg (sq_nonneg σ) hγ.le) hb + constructor + · convert h1 using 1; ring + · convert h2 using 1; ring + +end SKGap +end +end + +section +noncomputable section +namespace SKGap +open MeasureTheory ProbabilityTheory Matrix Real Set +open scoped BigOperators ENNReal NNReal + +lemma gaussian_vectorSqNorm_integrable (n : ℕ) : + Integrable (vectorSqNorm (n := n)) (gaussianCoordinates (Fin n)) := by + have hh := (gaussianQuadratic_memLp (fun _ : Fin n => (1:ℝ))).integrable (by norm_num) + change Integrable (fun g : Field n => ∑ i,1*g i^2) (gaussianCoordinates (Fin n)) at hh + change Integrable (fun g : Field n => ∑ i,g i^2) (gaussianCoordinates (Fin n)) + simpa only [one_mul] using hh + +lemma gaussian_vectorSqNorm_mean (n : ℕ) : + (∫ g,vectorSqNorm g ∂gaussianCoordinates (Fin n))=(n:ℝ) := by + simpa only [vectorSqNorm,gaussianQuadratic,one_mul,gaussianCoordinates,Finset.sum_const, + Finset.card_univ,Fintype.card_fin,nsmul_eq_mul,mul_one] using + gaussianQuadratic_mean (fun _ : Fin n => (1:ℝ)) + +def localGaussianBall (n : ℕ) : Set (Field n) := {g | vectorSqNorm g ≤ 4*(n:ℝ)} + +lemma localGaussianBall_measurable (n : ℕ) : MeasurableSet (localGaussianBall n) := by + unfold localGaussianBall vectorSqNorm + exact measurableSet_le (by fun_prop) measurable_const + +lemma localGaussianBall_norm {n : ℕ} {g : Field n} (hg : g ∈ localGaussianBall n) : + vectorNorm g ≤ 2*sqrt (n:ℝ) := by + apply (sq_le_sq₀ (vectorNorm_nonneg _) (by positivity)).mp + rw [vectorNorm_sq,mul_pow,Real.sq_sqrt (Nat.cast_nonneg _)] + simpa only [localGaussianBall,Set.mem_ofPred_eq,show (2:ℝ)^2=4 by norm_num] using hg + +theorem localGaussianBall_probability {n : ℕ} (hn : 0 < n) : + 3/4 ≤ (gaussianCoordinates (Fin n)).real (localGaussianBall n) := by + let μ := gaussianCoordinates (Fin n) + have hn0 : (0:ℝ) < n := by exact_mod_cast hn + have hh := mul_meas_ge_le_integral_of_nonneg + (μ := μ) (ae_of_all _ (fun g => vectorSqNorm_nonneg g)) + (gaussian_vectorSqNorm_integrable n) (4*(n:ℝ)) + rw [gaussian_vectorSqNorm_mean] at hh + have hsub : (localGaussianBall n)ᶜ ⊆ {g | 4*(n:ℝ) ≤ vectorSqNorm g} := by + intro g hg + change ¬ vectorSqNorm g ≤ 4*(n:ℝ) at hg + exact (lt_of_not_ge hg).le + have hmono := measureReal_mono hsub (measure_ne_top μ _) + have hc := probReal_compl_eq_one_sub (μ := μ) (localGaussianBall_measurable n) + rw [hc] at hmono + nlinarith + +lemma localGaussianBall_ne_zero {n : ℕ} (hn : 0 < n) : + gaussianCoordinates (Fin n) (localGaussianBall n) ≠ 0 := by + intro he + have hh := localGaussianBall_probability hn + simp only [measureReal_def,he,ENNReal.toReal_zero] at hh + norm_num at hh + +lemma integrable_cond_of_integrable {Ω E : Type*} [MeasurableSpace Ω] + [NormedAddCommGroup E] {μ : Measure Ω} {s : Set Ω} {f : Ω → E} + (hs : μ s ≠ 0) (hf : Integrable f μ) : Integrable f (cond μ s) := by + exact hf.restrict.smul_measure (ENNReal.inv_ne_top.mpr hs) + +lemma integral_cond_nonneg_le_two {Ω : Type*} [MeasurableSpace Ω] + {μ : Measure Ω} [IsProbabilityMeasure μ] {s : Set Ω} {f : Ω → ℝ} + (hp : 1/2 ≤ μ.real s) + (hf : Integrable f μ) (hn : 0 ≤ᵐ[μ] f) : + (∫ x,f x ∂cond μ s) ≤ 2*∫ x,f x ∂μ := by + have hps : 0 < μ.real s := by linarith + have his : 0 ≤ ∫ x in s,f x ∂μ := integral_nonneg_of_ae (ae_restrict_of_ae hn) + have hsle : (∫ x in s,f x ∂μ) ≤ ∫ x,f x ∂μ := + integral_mono_measure μ.restrict_le_self hn hf + have hinv : (μ.real s)⁻¹ ≤ 2 := by + rw [inv_eq_one_div] + exact (div_le_iff₀ hps).mpr (by linarith) + rw [ProbabilityTheory.cond,integral_smul_measure,ENNReal.toReal_inv] + change (μ.real s)⁻¹*(∫ x in s,f x ∂μ) ≤ _ + exact (mul_le_mul_of_nonneg_right hinv his).trans (mul_le_mul_of_nonneg_left hsle (by norm_num)) + +end SKGap +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Gaussian/MatrixNormTail.lean b/lean/OAI/Probability/SKGap/Gaussian/MatrixNormTail.lean new file mode 100644 index 0000000000000000000000000000000000000000..8271b15b086c4aefd6838acdc709fd5c42e6df49 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Gaussian/MatrixNormTail.lean @@ -0,0 +1,104 @@ +import Mathlib +import OAI.Probability.SKGap.Gaussian.GaussianProductUpperTailLipschitz +import OAI.Probability.SKGap.Gaussian.GaussianProductPower + +namespace OAI + +section +noncomputable section +namespace SKGap +open Matrix Real MeasureTheory ProbabilityTheory Set +open scoped BigOperators Matrix.Norms.Frobenius +variable {ι κ : Type*} [Fintype ι] [DecidableEq ι] [Fintype κ] + +def matrixWordSeminorm (p : Bool) (M : Matrix ι ι ℝ) : ℝ := + if p then offDiagonalSeminorm M else diagonalSeminorm M +lemma matrixWordSeminorm_lipschitz (p : Bool) : LipschitzWith 1 (matrixWordSeminorm (ι:=ι) p) := by + cases p + · exact diagonalSeminorm_lipschitz + · exact offDiagonalSeminorm_lipschitz +lemma matrixWordSeminorm_add (p : Bool) (M N : Matrix ι ι ℝ) : + matrixWordSeminorm p (M+N)≤ matrixWordSeminorm p M+matrixWordSeminorm p N := by + cases p + · exact diagonalSeminorm_add M N + · exact offDiagonalSeminorm_add M N +lemma matrixWordSeminorm_nonneg (p : Bool) (M : Matrix ι ι ℝ) : 0≤ matrixWordSeminorm p M := by + let : Fact (1≤(4:ENNReal)) := ⟨by norm_num⟩ + cases p + · exact norm_nonneg (diagonalVector M) + · exact norm_nonneg (offDiagonalVector M) + +lemma matrixCentered_sub {F G : EuclideanSpace ℝ κ→Matrix ι ι ℝ} + {L K : NNReal} (hF : LipschitzWith L F) (hG : LipschitzWith K G) (x : EuclideanSpace ℝ κ) : + matrixCentered (fun y=>F y-G y) x=matrixCentered F x-matrixCentered G x := by + have hm : matrixEntryMean (fun y=>F y-G y)=matrixEntryMean F-matrixEntryMean G := by + ext i k + exact integral_sub (gaussianProduct_integrable_lipschitz (matrixEntry_lip hF i k)) + (gaussianProduct_integrable_lipschitz (matrixEntry_lip hG i k)) + simp only [matrixCentered,hm] + abel + +lemma gaussianProduct_centered_matrix_tail {F : EuclideanSpace ℝ κ→Matrix ι ι ℝ} + {L : NNReal} (hF : LipschitzWith L F) (hL : 0gaussianReal 0 1)) + {g | matrixNormConstant*sqrt (Fintype.card ι)*(L:ℝ)+u< + matrixWordSeminorm p (matrixCentered F (WithLp.toLp 2 g))}≤ + ENNReal.ofReal (exp (-2*u^2/(π^2*(L:ℝ)^2))) := by + let μ := Measure.pi (fun _ : κ=>gaussianReal 0 1) + let X : (κ→ℝ)→ℝ := fun g=>matrixWordSeminorm p (matrixCentered F (WithLp.toLp 2 g)) + have hXL : LipschitzWith L (fun x : EuclideanSpace ℝ κ=>X x.ofLp) := by + simpa only [X,WithLp.toLp_ofLp,one_mul,Function.comp_def] using + (matrixWordSeminorm_lipschitz p).comp (matrixCentered_lipschitz hF) + have hE : (∫ g,X g ∂μ)≤ matrixNormConstant*sqrt (Fintype.card ι)*(L:ℝ) := by + cases p + · exact (gaussianProduct_centered_matrix_norms hF hL).1 + · exact (gaussianProduct_centered_matrix_norms hF hL).2 + have htail := gaussianProduct_upper_tail_lipschitz hXL hL hu + have hmono : μ {g | matrixNormConstant*sqrt (Fintype.card ι)*(L:ℝ)+ugaussianReal 0 1)) + {g | (matrixNormConstant*H+T*s)*r< matrixWordSeminorm p (matrixCentered F (WithLp.toLp 2 g))} ≤ + ENNReal.ofReal (exp (-2*T^2*s^2*(n:ℝ)/(π^2*H^2))) := by + have hn0 : (0:ℝ)gaussianReal 0 1)|^(2*k) + ∂Measure.pi (fun _=>gaussianReal 0 1)) ≤ + (2*((2*k).factorial:ℝ)*exp (π^2/8)) * + (((F.length:ℝ)*(R:ℝ)^F.length)^2*(2*j))^k/(n:ℝ)^k := by + have hnr : (0:ℝ) + trace (matrixFactorProduct F (goeMatrix (j/n) z))/(n:ℝ)) := by + have hnr : (0:ℝ)gaussianReal 0 1)| + ∂Measure.pi (fun _=>gaussianReal 0 1)) ≤ + (2*exp (π^2/8))*((F.length:ℝ)*(R:ℝ)^F.length)*sqrt (2*j)/(n:ℝ) := by + have hnr : (0:ℝ)gaussianReal 0 1)| + ∂Measure.pi (fun _=>gaussianReal 0 1)) ≤ + (2*exp (π^2/8))*((F.length:ℝ)*(R:ℝ)^F.length)*sqrt (2*j)/(n:ℝ) := by + by_cases he : F=[] + · subst F + simp only [matrixFactorProduct_nil,List.length_nil,Nat.cast_zero,zero_mul,mul_zero,zero_div] + simp + · exact goe_word_trace_centered_L1 hn hj F (List.length_pos_iff.mpr he) hR hF hL +end SKGap +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Gaussian/PartitionSecondMoment.lean b/lean/OAI/Probability/SKGap/Gaussian/PartitionSecondMoment.lean new file mode 100644 index 0000000000000000000000000000000000000000..6d7f494ebfc9f9c776b8c2e58e355d4339d75e7f --- /dev/null +++ b/lean/OAI/Probability/SKGap/Gaussian/PartitionSecondMoment.lean @@ -0,0 +1,144 @@ +import Mathlib +import OAI.Probability.SKGap.Gaussian.GaussianProductUpperTailLipschitz +import OAI.Probability.SKGap.Terminal.SpinGaussianBound +import OAI.Probability.SKGap.Gaussian.GaussianPartition + +namespace OAI + +section +noncomputable section +namespace SKGap +open MeasureTheory ProbabilityTheory Real +open scoped BigOperators + +def quadraticGaussianBound (j : ℝ) : ℝ := ∫ g : ℝ, exp (j*g^2/2) ∂gaussianReal 0 1 + +lemma quadraticGaussianBound_ge_one {j : ℝ} (hj : 0 ≤ j) (hj1 : j < 1) : + 1 ≤ quadraticGaussianBound j := by + have h := integral_mono (integrable_const (1:ℝ)) (gaussian_quadratic_integrable_sharp hj1) + (fun g : ℝ=>one_le_exp (by positivity : 0 ≤ j*g^2/2)) + simpa [quadraticGaussianBound] using h + +lemma gaussianSpinPartition_pos (n : ℕ) (r : ℝ) (g : Disorder n) : + 0 < gaussianSpinPartition n r g := + Finset.sum_pos (fun _ _=>exp_pos _) Finset.univ_nonempty + +lemma gaussianSpinPartition_measurable (n : ℕ) (r : ℝ) : Measurable (gaussianSpinPartition n r) := by + unfold gaussianSpinPartition + exact Finset.measurable_sum _ (fun x _=>Real.measurable_exp.comp + (Finset.measurable_sum _ (fun e _=>(measurable_pi_apply e).const_mul _))) + +lemma gaussianSpinPartition_mean_pos {n : ℕ} {r : ℝ} (hr : 0 ≤ r) : + 0 < ∫ g, gaussianSpinPartition n r g ∂gaussianCoordinates (Edge n) := by + rw [gaussianSpinPartition_integral hr] + exact mul_pos (by exact_mod_cast Fintype.card_pos) (exp_pos _) + +lemma gaussianSpinPartition_second_moment {n : ℕ} {j r : ℝ} (hj : j < 1) + (hr : 0 ≤ r) (hnr : (n:ℝ)*r ≤ j) : + (∫ g,(gaussianSpinPartition n r g)^2 ∂gaussianCoordinates (Edge n)) ≤ + quadraticGaussianBound j*(∫ g,gaussianSpinPartition n r g ∂gaussianCoordinates (Edge n))^2 := by + rw [gaussianSpinPartition_square_integral hr,gaussianSpinPartition_integral hr] + have hc : (Fintype.card (Spin n):ℝ)=(2:ℝ)^n := by simp [Spin] + have he : exp (r*(Fintype.card (Edge n):ℝ)-r*(n:ℝ)/2) ≤ exp (r*(Fintype.card (Edge n):ℝ)) := + exp_le_exp.mpr (by nlinarith [mul_nonneg hr (show (0:ℝ) ≤ n by positivity)]) + have hb := spin_quadratic_sum_bound hj hr hnr + rw [← hc] at hb + have hB : 0 ≤ quadraticGaussianBound j := integral_nonneg (fun _=>(exp_pos _).le) + have hc0 : (0:ℝ) ≤ Fintype.card (Spin n) := by positivity + calc + _ ≤ (Fintype.card (Spin n):ℝ)*exp (r*(Fintype.card (Edge n):ℝ)-r*(n:ℝ)/2)* + ((Fintype.card (Spin n):ℝ)*quadraticGaussianBound j) := + mul_le_mul_of_nonneg_left hb (by positivity) + _ ≤ (Fintype.card (Spin n):ℝ)*exp (r*(Fintype.card (Edge n):ℝ))* + ((Fintype.card (Spin n):ℝ)*quadraticGaussianBound j) := + mul_le_mul_of_nonneg_right (mul_le_mul_of_nonneg_left he hc0) (mul_nonneg hc0 hB) + _ = _ := by + have h : exp (r*(Fintype.card (Edge n):ℝ))=exp (r*(Fintype.card (Edge n):ℝ)/2)^2 := by + rw [← exp_nat_mul];congr 1;ring + rw [h];ring + +lemma gaussianSpinPartition_positive_probability {n : ℕ} {j r : ℝ} (hj0 : 0 ≤ j) + (hj : j < 1) (hr : 0 ≤ r) (hnr : (n:ℝ)*r ≤ j) : + 1/(4*quadraticGaussianBound j) ≤ (gaussianCoordinates (Edge n)).real + {g | (∫ g,gaussianSpinPartition n r g ∂gaussianCoordinates (Edge n))/2 ≤ gaussianSpinPartition n r g} := by + exact second_moment_positive_probability _ _ (gaussianSpinPartition_measurable n r) + (gaussianSpinPartition_integrable n r) (gaussianSpinPartition_square_integrable n r) + (gaussianSpinPartition_mean_pos hr) (lt_of_lt_of_le zero_lt_one (quadraticGaussianBound_ge_one hj0 hj)) + rfl (gaussianSpinPartition_second_moment hj hr hnr) +end SKGap +end +end + +section +noncomputable section +namespace SKGap +open MeasureTheory ProbabilityTheory Real Set +open scoped BigOperators NNReal + +lemma log_sum_exp_order {ι : Type*} [Fintype ι] [Nonempty ι] + (f g : ι→ℝ) (d : ℝ) (h : ∀ i,f i ≤ g i+d) : + log (∑ i,exp (f i)) ≤ log (∑ i,exp (g i))+d := by + have hp : 0 < ∑ i,exp (f i) := Finset.sum_pos (fun i _=>exp_pos _) Finset.univ_nonempty + have hq : 0 < ∑ i,exp (g i) := Finset.sum_pos (fun i _=>exp_pos _) Finset.univ_nonempty + have hh : (∑ i,exp (f i)) ≤ (∑ i,exp (g i))*exp d := by + rw [Finset.sum_mul] + exact Finset.sum_le_sum (fun i _=> (exp_le_exp.mpr (h i)).trans_eq (exp_add _ _)) + have he := log_le_log hp hh + rw [log_mul hq.ne' (exp_pos _).ne',log_exp] at he + exact he + +lemma log_sum_exp_lipschitz {ι : Type*} [Fintype ι] [Nonempty ι] + {E : Type*} [PseudoMetricSpace E] (f : ι→E→ℝ) {L : ℝ≥0} + (hf : ∀ i,LipschitzWith L (f i)) : + LipschitzWith L (fun x=>log (∑ i,exp (f i x))) := by + apply LipschitzWith.of_dist_le_mul + intro x y + rw [Real.dist_eq,abs_le] + constructor + · have hh := log_sum_exp_order (fun i=>f i y) (fun i=>f i x) ((L:ℝ)*dist x y) + (fun i=>by have hh := (hf i).dist_le_mul y x;rw [Real.dist_eq,dist_comm y x] at hh + linarith only [le_abs_self (f i y-f i x),hh]) + linarith only [hh] + · have hh := log_sum_exp_order (fun i=>f i x) (fun i=>f i y) ((L:ℝ)*dist x y) + (fun i=>by have hh := (hf i).dist_le_mul x y;rw [Real.dist_eq] at hh + linarith only [le_abs_self (f i x-f i y),hh]) + linarith only [hh] + +lemma gaussianProduct_lower_tail_lipschitz {κ : Type*} [Fintype κ] + {f : (κ→ℝ)→ℝ} {L : ℝ≥0} + (hf : LipschitzWith L (fun x : EuclideanSpace ℝ κ=>f x.ofLp)) + (hL : 0 < L) {u : ℝ} (hu : 0 ≤ u) : + (Measure.pi (fun _ : κ=>gaussianReal 0 1)).real + {x | f x-∫ y,f y ∂Measure.pi (fun _ : κ=>gaussianReal 0 1) ≤ -u} ≤ + exp (-2*u^2/(π^2*(L:ℝ)^2)) := by + have hn : LipschitzWith L (fun x : EuclideanSpace ℝ κ=>-f x.ofLp) := by + apply LipschitzWith.of_dist_le_mul + intro x y + simpa only [Real.dist_eq,neg_sub_neg,abs_sub_comm] using hf.dist_le_mul x y + have h := gaussianProduct_upper_tail_lipschitz (f:=fun x=>-f x) hn hL hu + simp only [integral_neg] at h + convert h using 2 + ext x;simp only [mem_ofPred_eq];constructor <;> intro hx <;> linarith only [hx] + +lemma gaussian_log_anchor {κ : Type*} [Fintype κ] + {f : (κ→ℝ)→ℝ} {L : ℝ≥0} + (hf : LipschitzWith L (fun x : EuclideanSpace ℝ κ=>f x.ofLp)) + (hL : 0 < L) {p b c : ℝ} (hc : 0 < c) + (hpc : exp (-2*c^2/π^2) < p) + (hp : p ≤ (Measure.pi (fun _ : κ=>gaussianReal 0 1)).real {x | b ≤ f x}) : + b-c*(L:ℝ) ≤ ∫ y,f y ∂Measure.pi (fun _ : κ=>gaussianReal 0 1) := by + by_contra hh + have hs : {x | b ≤ f x} ⊆ {x | c*(L:ℝ) ≤ f x-∫ y,f y ∂Measure.pi (fun _ : κ=>gaussianReal 0 1)} := by + intro x hx;dsimp only [mem_ofPred_eq] at *;linarith only [not_le.mp hh,hx] + have ht := gaussianProduct_upper_tail_lipschitz hf hL (mul_nonneg hc.le (NNReal.coe_nonneg L)) + have he : -2*(c*(L:ℝ))^2/(π^2*(L:ℝ)^2)= -2*c^2/π^2 := by + have hLr : (L:ℝ) ≠ 0 := ne_of_gt hL + field_simp + rw [he] at ht + have hm := measureReal_mono hs (measure_ne_top (Measure.pi (fun _ : κ=>gaussianReal 0 1)) _) + linarith only [hp,ht,hm,hpc] +end SKGap +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Gaussian/PhiMoments.lean b/lean/OAI/Probability/SKGap/Gaussian/PhiMoments.lean new file mode 100644 index 0000000000000000000000000000000000000000..24b4fb9a05391feaec022a91a8c5cbb590941ac2 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Gaussian/PhiMoments.lean @@ -0,0 +1,138 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.PhiBounds + +namespace OAI + +section + +noncomputable section +open MeasureTheory +namespace SKGap.Stein + +def hyper (b : Bool) (x : ℝ) : ℝ := if b then Real.sinh x else Real.cosh x +lemma continuous_hyper (b : Bool) : Continuous (hyper b) := by unfold hyper; split_ifs <;> fun_prop +lemma hyper_hasDerivAt (b : Bool) (x : ℝ) : HasDerivAt (hyper b) (hyper (!b) x) x := by + cases b <;> simpa only [hyper,Bool.not_false,Bool.not_true,Bool.false_eq_true,ite_false,ite_true] using + (show HasDerivAt _ _ x from (by first | exact Real.hasDerivAt_cosh x | exact Real.hasDerivAt_sinh x)) + +lemma hyper_abs_le (b : Bool) (x : ℝ) : |hyper b x|≤Real.cosh x := by + cases b + · simp only [hyper,Bool.false_eq_true,ite_false,abs_of_pos (Real.cosh_pos _),le_refl] + · exact abs_sinh_le_cosh x + +def momentNum (p q : ℕ) (b : Bool) (d a : ℝ) : ℝ := + ∫u in (0:ℝ)..1,weight a u*u^p*((1-u^2)/2)^q*hyper b (u*d) + +def moment (p q : ℕ) (b : Bool) (z r a : ℝ) : ℝ := + momentNum p q b (z-r) a/(Real.cosh z*Real.cosh r) + +lemma moment_base (z r a : ℝ) : moment 0 0 false z r a=phi z r a := by + rw [phi_eq] + simp only [moment,momentNum,numerator,pow_zero,mul_one,hyper,Bool.false_eq_true,ite_false] + +lemma momentNum_hasDerivAt_d (p q : ℕ) (b : Bool) (d a : ℝ) : + HasDerivAt (fun d=>momentNum p q b d a) (momentNum (p+1) q (!b) d a) d := by + unfold momentNum + apply hasDerivAt_integral01 + (F:=fun d u=>weight a u*u^p*((1-u^2)/2)^q*hyper b (u*d)) + (F':=fun d u=>weight a u*u^(p+1)*((1-u^2)/2)^q*hyper (!b) (u*d)) + · exact (((continuous_weight a).comp continuous_snd).mul (continuous_snd.pow p)|>.mul + (((continuous_const.sub (continuous_snd.pow 2)).div_const 2).pow q)).mul + ((continuous_hyper b).comp (continuous_snd.mul continuous_fst)) + · exact (((continuous_weight a).comp continuous_snd).mul (continuous_snd.pow (p+1))|>.mul + (((continuous_const.sub (continuous_snd.pow 2)).div_const 2).pow q)).mul + ((continuous_hyper (!b)).comp (continuous_snd.mul continuous_fst)) + · intro d u + have H:=((hyper_hasDerivAt b (u*d)).comp d ((hasDerivAt_id d).const_mul u)).const_mul + (weight a u*u^p*((1-u^2)/2)^q) + convert! H using 1 + simp only [pow_succ] + ring + +lemma momentNum_hasDerivAt_a (p q : ℕ) (b : Bool) (d a : ℝ) : + HasDerivAt (fun a=>momentNum p q b d a) (momentNum p (q+1) b d a) a := by + unfold momentNum + apply hasDerivAt_integral01 + (F:=fun a u=>weight a u*u^p*((1-u^2)/2)^q*hyper b (u*d)) + (F':=fun a u=>weight a u*u^p*((1-u^2)/2)^(q+1)*hyper b (u*d)) + · apply Continuous.mul + · unfold weight; fun_prop + · exact (continuous_hyper b).comp (continuous_snd.mul_const d) + · apply Continuous.mul + · unfold weight; fun_prop + · exact (continuous_hyper b).comp (continuous_snd.mul_const d) + · intro a u + have H:=((((hasDerivAt_id a).mul_const (1-u^2)).div_const 2).exp).mul_const + (u^p*((1-u^2)/2)^q*hyper b (u*d)) + convert! H using 1 <;> (try funext x) <;> dsimp [weight] <;> simp only [pow_succ] <;> ring + +lemma momentNum_abs_le (p q : ℕ) (b : Bool) (d a : ℝ) : + |momentNum p q b d a|≤ momentNum 0 0 false d a := by + unfold momentNum + apply (intervalIntegral.abs_integral_le_integral_abs (by norm_num : (0:ℝ)≤1)).trans + apply intervalIntegral.integral_mono_on (by norm_num : (0:ℝ)≤1) + · apply Continuous.intervalIntegrable + apply Continuous.abs + exact (((continuous_weight a).mul (continuous_id.pow p)).mul + (((continuous_const.sub (continuous_id.pow 2)).div_const 2).pow q)).mul + ((continuous_hyper b).comp (continuous_id.mul_const d)) + · apply Continuous.intervalIntegrable + exact (((continuous_weight a).mul (continuous_id.pow 0)).mul + (((continuous_const.sub (continuous_id.pow 2)).div_const 2).pow 0)).mul + ((continuous_hyper false).comp (continuous_id.mul_const d)) + · intro u hu + have hu2 : u^2≤1 := by nlinarith [hu.1,hu.2] + have hv0 : 0≤(1-u^2)/2 := by linarith + have hv1 : (1-u^2)/2≤1 := by nlinarith [sq_nonneg u] + have hp : u^p ≤ 1 := pow_le_one₀ hu.1 hu.2 + have hq : ((1-u^2)/2)^q ≤ 1 := pow_le_one₀ hv0 hv1 + simp only [abs_mul,abs_of_pos (show 0moment p q b z r a) + (moment (p+1) q (!b) z r a-Real.tanh z*moment p q b z r a) z := by + have H:=((momentNum_hasDerivAt_d p q b (z-r) a).comp z ((hasDerivAt_id z).sub_const r)).div + ((Real.hasDerivAt_cosh z).mul_const (Real.cosh r)) + (ne_of_gt (mul_pos (Real.cosh_pos _) (Real.cosh_pos _))) + convert! H using 1 + dsimp [moment] + rw [Real.tanh_eq_sinh_div_cosh] + field_simp [ne_of_gt (Real.cosh_pos z),ne_of_gt (Real.cosh_pos r)] + +lemma moment_hasDerivAt_r (p q : ℕ) (b : Bool) (z r a : ℝ) : + HasDerivAt (fun r=>moment p q b z r a) + (-moment (p+1) q (!b) z r a-Real.tanh r*moment p q b z r a) r := by + have H:=((momentNum_hasDerivAt_d p q b (z-r) a).comp r ((hasDerivAt_id r).const_sub z)).div + ((Real.hasDerivAt_cosh r).const_mul (Real.cosh z)) + (ne_of_gt (mul_pos (Real.cosh_pos _) (Real.cosh_pos _))) + convert! H using 1 + dsimp [moment] + rw [Real.tanh_eq_sinh_div_cosh] + field_simp [ne_of_gt (Real.cosh_pos z),ne_of_gt (Real.cosh_pos r)] + +lemma moment_hasDerivAt_a (p q : ℕ) (b : Bool) (z r a : ℝ) : + HasDerivAt (fun a=>moment p q b z r a) (moment p (q+1) b z r a) a := by + exact (momentNum_hasDerivAt_a p q b (z-r) a).div_const _ + +end SKGap.Stein + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Gaussian/PhiStein.lean b/lean/OAI/Probability/SKGap/Gaussian/PhiStein.lean new file mode 100644 index 0000000000000000000000000000000000000000..7ac44b8abfd0d18731785d5e3d74dbef82c2c8c8 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Gaussian/PhiStein.lean @@ -0,0 +1,135 @@ +import Mathlib +import OAI.Probability.SKGap.Model + +namespace OAI + +section + +noncomputable section +open MeasureTheory Filter +open scoped Topology +namespace SKGap.Stein + +lemma hasDerivAt_integral01 {F F' : ℝ→ℝ→ℝ} + (hF : Continuous (fun p : ℝ×ℝ=>F p.1 p.2)) + (hF' : Continuous (fun p : ℝ×ℝ=>F' p.1 p.2)) + (hd : ∀ z u,HasDerivAt (fun z=>F z u) (F' z u) z) (z : ℝ) : + HasDerivAt (fun z=>∫u in (0:ℝ)..1,F z u) (∫u in (0:ℝ)..1,F' z u) z := by + obtain ⟨C,hC⟩ := (isCompact_Icc.prod isCompact_Icc).exists_bound_of_continuousOn + (hF'.continuousOn : ContinuousOn (fun p : ℝ×ℝ=>F' p.1 p.2) + ((Set.Icc (z-1) (z+1))×ˢ(Set.Icc (0:ℝ) 1))) + have hc (x : ℝ) : Continuous (F x) := hF.comp (continuous_const.prodMk continuous_id) + have hc' (x : ℝ) : Continuous (F' x) := hF'.comp (continuous_const.prodMk continuous_id) + exact (intervalIntegral.hasDerivAt_integral_of_dominated_loc_of_deriv_le + (F:=F) (F':=F') (bound:=fun _=>C) + (s:=Set.Icc (z-1) (z+1)) (Icc_mem_nhds (by linarith) (by linarith)) + (Eventually.of_forall (fun x=>(hc x).aestronglyMeasurable)) + (hc z|>.intervalIntegrable _ _) (hc' z).aestronglyMeasurable + (Eventually.of_forall (by + intro u hu x hx + rw [Set.uIoc_of_le (by norm_num : (0:ℝ)≤1)] at hu + exact hC (x,u) ⟨hx,hu.1.le,hu.2⟩)) + intervalIntegrable_const + (Eventually.of_forall (fun u _ x _=>hd x u))).2 + +def weight (a u : ℝ) : ℝ := Real.exp (a*(1-u^2)/2) +def numerator (z r a : ℝ) : ℝ := ∫u in (0:ℝ)..1,weight a u*Real.cosh (u*(z-r)) +def numeratorZ (z r a : ℝ) : ℝ := ∫u in (0:ℝ)..1,weight a u*u*Real.sinh (u*(z-r)) +def phi (z r a : ℝ) : ℝ := ∫u in (0:ℝ)..1, + weight a u*Real.cosh (u*(z-r))/(Real.cosh z*Real.cosh r) +def phiZ (z r a : ℝ) : ℝ := numeratorZ z r a/(Real.cosh z*Real.cosh r)-Real.tanh z*phi z r a + +lemma continuous_weight (a : ℝ) : Continuous (weight a) := by unfold weight; fun_prop + +lemma phi_eq (z r a : ℝ) : phi z r a=numerator z r a/(Real.cosh z*Real.cosh r) := by + exact intervalIntegral.integral_div _ _ + +lemma numerator_hasDerivAt (z r a : ℝ) : + HasDerivAt (fun z=>numerator z r a) (numeratorZ z r a) z := by + unfold numerator numeratorZ + apply hasDerivAt_integral01 (F:=fun z u=>weight a u*Real.cosh (u*(z-r))) + (F':=fun z u=>weight a u*u*Real.sinh (u*(z-r))) + · unfold weight; fun_prop + · unfold weight; fun_prop + · intro z u + convert! ((Real.hasDerivAt_cosh (u*(z-r))).comp z + (((hasDerivAt_id z).sub_const r).const_mul u)).const_mul (weight a u) using 1 + ring + +lemma phi_hasDerivAt (z r a : ℝ) : HasDerivAt (fun z=>phi z r a) (phiZ z r a) z := by + have h := (numerator_hasDerivAt z r a).div + ((Real.hasDerivAt_cosh z).mul_const (Real.cosh r)) + (ne_of_gt (mul_pos (Real.cosh_pos z) (Real.cosh_pos r))) + convert! h using 1 + · funext x; exact phi_eq x r a + · rw [phiZ,phi_eq,Real.tanh_eq_sinh_div_cosh] + field_simp [ne_of_gt (Real.cosh_pos z),ne_of_gt (Real.cosh_pos r)] + +lemma weight_hasDerivAt (a u : ℝ) : HasDerivAt (weight a) (-a*u*weight a u) u := by + unfold weight + convert! (Real.hasDerivAt_exp _).comp u + ((((hasDerivAt_id u).pow 2).const_sub 1).const_mul a |>.div_const 2) using 1 + dsimp + ring + +lemma boundary_hasDerivAt (z r a u : ℝ) : + HasDerivAt (fun u=>weight a u*Real.sinh (u*(z-r))) + (weight a u*((z-r)*Real.cosh (u*(z-r))-a*u*Real.sinh (u*(z-r)))) u := by + convert! (weight_hasDerivAt a u).mul + ((Real.hasDerivAt_sinh (u*(z-r))).comp u ((hasDerivAt_id u).mul_const (z-r))) using 1 + dsimp + ring + +lemma numerator_boundary (z r a : ℝ) : + (z-r)*numerator z r a-a*numeratorZ z r a=Real.sinh (z-r) := by + have hc1 : Continuous (fun u=>weight a u*Real.cosh (u*(z-r))) := by + exact (continuous_weight a).mul (by fun_prop) + have hc2 : Continuous (fun u=>weight a u*u*Real.sinh (u*(z-r))) := by + exact ((continuous_weight a).mul continuous_id).mul (by fun_prop) + have he : (fun u=>weight a u*((z-r)*Real.cosh (u*(z-r))-a*u*Real.sinh (u*(z-r))))= + (fun u=>(z-r)*(weight a u*Real.cosh (u*(z-r)))-a*(weight a u*u*Real.sinh (u*(z-r)))) := by + funext u; ring + have H:=intervalIntegral.integral_eq_sub_of_hasDerivAt + (a:=(0:ℝ)) (b:=1) (fun u _=>boundary_hasDerivAt z r a u) + (show IntervalIntegrable (fun u=>weight a u*((z-r)*Real.cosh (u*(z-r))-a*u*Real.sinh (u*(z-r)))) volume 0 1 from by + rw [he]; exact ((hc1.const_mul (z-r)).sub (hc2.const_mul a)).intervalIntegrable _ _) + rw [he,intervalIntegral.integral_sub ((hc1.const_mul (z-r)).intervalIntegrable _ _) + ((hc2.const_mul a).intervalIntegrable _ _),intervalIntegral.integral_const_mul, + intervalIntegral.integral_const_mul] at H + simpa only [numerator,numeratorZ,weight,one_pow,sub_self,mul_zero,zero_div, + Real.exp_zero,one_mul,zero_mul,Real.sinh_zero,sub_zero] using H + +theorem phi_stein (z r a : ℝ) : + (z-r-a*Real.tanh z)*phi z r a-a*phiZ z r a=Real.tanh z-Real.tanh r := by + rw [phiZ,phi_eq] + have H:=numerator_boundary z r a + have hId : Real.sinh (z-r)/(Real.cosh z*Real.cosh r)=Real.tanh z-Real.tanh r := by + rw [Real.sinh_sub,Real.tanh_eq_sinh_div_cosh,Real.tanh_eq_sinh_div_cosh] + field_simp [ne_of_gt (Real.cosh_pos z),ne_of_gt (Real.cosh_pos r)] + rw [←hId] + field_simp [ne_of_gt (Real.cosh_pos z),ne_of_gt (Real.cosh_pos r)] + nlinarith [H] + +lemma phi_pos (z r a : ℝ) : 0phi z r a) z=Real.tanh z-Real.tanh r := by + rw [(phi_hasDerivAt z r a).deriv] + exact phi_stein z r a + +end SKGap.Stein + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Gaussian/ProductGaussianDensity.lean b/lean/OAI/Probability/SKGap/Gaussian/ProductGaussianDensity.lean new file mode 100644 index 0000000000000000000000000000000000000000..54170ab5704814e36e43aad1e6937239e57d128e --- /dev/null +++ b/lean/OAI/Probability/SKGap/Gaussian/ProductGaussianDensity.lean @@ -0,0 +1,42 @@ +import Mathlib +import OAI.Probability.SKGap.Model + +namespace OAI + +section +noncomputable section +open MeasureTheory ProbabilityTheory Matrix +open scoped BigOperators ENNReal NNReal +namespace SKGap.GaussianDensity +variable {ι : Type*} [Fintype ι] + +theorem pi_gaussian_density (m : ι → ℝ) (v : ι → ℝ≥0) (hv : ∀ i,v i ≠ 0) : + Measure.pi (fun i => gaussianReal (m i) (v i)) = + (volume : Measure (ι → ℝ)).withDensity (fun x => ENNReal.ofReal (∏ i,gaussianPDFReal (m i) (v i) (x i))) := by + apply Measure.pi_eq + intro s hs + rw [withDensity_apply _ (MeasurableSet.univ_pi hs)] + have hi : Integrable (fun x : ι → ℝ => ∏ i,gaussianPDFReal (m i) (v i) (x i)) + (volume.restrict (Set.univ.pi s)) := by + exact (Integrable.fintype_prod (fun i => integrable_gaussianPDFReal (m i) (v i))).restrict + rw [← ofReal_integral_eq_lintegral_ofReal hi (Filter.Eventually.of_forall + (fun x => Finset.prod_nonneg (fun i _ => gaussianPDFReal_nonneg _ _ _)))] + change ENNReal.ofReal (∫ x, (∏ i,gaussianPDFReal (m i) (v i) (x i)) + ∂(Measure.pi (fun _ : ι => (volume : Measure ℝ))).restrict (Set.univ.pi s))=_ + rw [Measure.restrict_pi_pi,integral_fintype_prod_eq_prod, + ENNReal.ofReal_prod_of_nonneg (fun i _ => integral_nonneg (fun x => gaussianPDFReal_nonneg _ _ _))] + apply Finset.prod_congr rfl + intro i _ + rw [gaussianReal_of_var_ne_zero _ (hv i),withDensity_apply _ (hs i)] + exact ofReal_integral_eq_lintegral_ofReal (integrable_gaussianPDFReal (m i) (v i)).restrict + (Filter.Eventually.of_forall (gaussianPDFReal_nonneg _ _)) + +lemma measurable_productPDF (m : ι → ℝ) (v : ι → ℝ≥0) : + Measurable (fun x : ι → ℝ => ENNReal.ofReal (∏ i,gaussianPDFReal (m i) (v i) (x i))) := by + fun_prop + +end SKGap.GaussianDensity +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Gaussian/RegressionMoments.lean b/lean/OAI/Probability/SKGap/Gaussian/RegressionMoments.lean new file mode 100644 index 0000000000000000000000000000000000000000..1c5b3ea13bc369eeab5aace75e9a829ef760fac7 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Gaussian/RegressionMoments.lean @@ -0,0 +1,63 @@ +import Mathlib +import OAI.Probability.SKGap.Gaussian.GaussianDisintegration + +namespace OAI + +section +noncomputable section +namespace SKGap.GaussianRegression +open MeasureTheory ProbabilityTheory Matrix +open scoped BigOperators +variable {Ω ι κ : Type*} [MeasurableSpace Ω] [Fintype ι] [Fintype κ] + {P : Measure Ω} {X : Ω → ι → ℝ} {Y : Ω → κ → ℝ} + +lemma residual_mean_zero (hXY : HasGaussianLaw (fun w => (X w,Y w)) P) + (K : Matrix ι κ ℝ) (hx : ∀ i, (∫ w, X w i ∂P)=0) + (hy : ∀ k, (∫ w, Y w k ∂P)=0) (i : ι) : + (∫ w, (X w-K*ᵥY w) i ∂P)=0 := by + have hK : Integrable (fun w => ∑ k,K i k*Y w k) P := + ((hXY.snd.map (matrixCLM K)).eval i).integrable + change (∫ w, X w i-∑ k, K i k*Y w k ∂P)=0 + rw [integral_sub (hXY.fst.eval i).integrable hK, + integral_finsetSum _ (fun k _ => (hXY.snd.eval k).integrable.const_mul _)] + simp only [integral_const_mul,hx,hy,mul_zero,Finset.sum_const_zero,sub_zero] + +lemma residual_cross_covariance (hXY : HasGaussianLaw (fun w => (X w,Y w)) P) + (K : Matrix ι κ ℝ) + (hc : ∀ i k, cov[fun w => X w i,fun w => Y w k;P]= + ∑ l, K i l*cov[fun w => Y w l,fun w => Y w k;P]) (i : ι) (k : κ) : + cov[fun w => (X w-K*ᵥY w) i,fun w => Y w k;P]=0 := by + have := hXY.isProbabilityMeasure + have hK : MemLp (fun w => ∑ l,K i l*Y w l) 2 P := + ((hXY.snd.map (matrixCLM K)).eval i).memLp_two + change cov[fun w => X w i-∑ l,K i l*Y w l,fun w => Y w k;P]=0 + rw [covariance_fun_sub_left (hXY.fst.eval i).memLp_two hK (hXY.snd.eval k).memLp_two, + covariance_fun_sum_left (fun l => (hXY.snd.eval l).memLp_two.const_mul _) (hXY.snd.eval k).memLp_two] + simp only [covariance_const_mul_left,hc,sub_self] + +lemma residual_covariance (hXY : HasGaussianLaw (fun w => (X w,Y w)) P) + (K : Matrix ι κ ℝ) + (hc : ∀ i k, cov[fun w => X w i,fun w => Y w k;P]= + ∑ l, K i l*cov[fun w => Y w l,fun w => Y w k;P]) (i k : ι) : + cov[fun w => (X w-K*ᵥY w) i,fun w => (X w-K*ᵥY w) k;P]= + cov[fun w => X w i,fun w => X w k;P]- + ∑ l, K i l*cov[fun w => Y w l,fun w => X w k;P] := by + have := hXY.isProbabilityMeasure + have hR := (residual_joint_gaussian hXY K).fst + have hK (q : ι) : MemLp (fun w => ∑ l,K q l*Y w l) 2 P := + ((hXY.snd.map (matrixCLM K)).eval q).memLp_two + change cov[fun w => (X w-K*ᵥY w) i,fun w => X w k-∑ l,K k l*Y w l;P]=_ + rw [covariance_fun_sub_right (hR.eval i).memLp_two (hXY.fst.eval k).memLp_two (hK k), + covariance_fun_sum_right (fun l => (hXY.snd.eval l).memLp_two.const_mul _) (hR.eval i).memLp_two] + simp only [covariance_const_mul_right,residual_cross_covariance hXY K hc,mul_zero, + Finset.sum_const_zero,sub_zero] + change cov[fun w => X w i-∑ l,K i l*Y w l,fun w => X w k;P]=_ + rw [covariance_fun_sub_left (hXY.fst.eval i).memLp_two (hK i) (hXY.fst.eval k).memLp_two, + covariance_fun_sum_left (fun l => (hXY.snd.eval l).memLp_two.const_mul _) (hXY.fst.eval k).memLp_two] + simp only [covariance_const_mul_left] + +end SKGap.GaussianRegression +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Gaussian/ReplicaTailWeight.lean b/lean/OAI/Probability/SKGap/Gaussian/ReplicaTailWeight.lean new file mode 100644 index 0000000000000000000000000000000000000000..5ee2f60ae225d7b589f1707159e4529beb1ea787 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Gaussian/ReplicaTailWeight.lean @@ -0,0 +1,318 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.LogPartitionDeviationProbability + +namespace OAI + +section +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal +namespace SKGapCutoff + +noncomputable def replicaTailWeight {n : ℕ} (J : Interaction n) (ε : ℝ) : ℝ := + ∑ x : Spin n, ∑ y : Spin n, if ε * n < |replicaOverlap x y| then + Real.exp (energy J x + energy J y) else 0 + +noncomputable def replicaTail {n : ℕ} (J : Interaction n) (ε : ℝ) : ℝ := + ∑ x : Spin n, ∑ y : Spin n, if ε * n < |replicaOverlap x y| then + gibbs J x * gibbs J y else 0 + +lemma replicaTailWeight_nonneg {n : ℕ} (J : Interaction n) (ε : ℝ) : + 0 ≤ replicaTailWeight J ε := by + apply Finset.sum_nonneg + intro x _ + apply Finset.sum_nonneg + intro y _ + split_ifs <;> positivity + +lemma replicaTail_eq_ratio {n : ℕ} (J : Interaction n) (ε : ℝ) : + replicaTail J ε = replicaTailWeight J ε / partition J ^ 2 := by + unfold replicaTail replicaTailWeight gibbs + simp_rw [Finset.sum_div] + apply Finset.sum_congr rfl + intro x _ + apply Finset.sum_congr rfl + intro y _ + split_ifs + · rw [Real.exp_add] + ring + · simp + +lemma replicaTail_nonneg {n : ℕ} (J : Interaction n) (ε : ℝ) : + 0 ≤ replicaTail J ε := by + rw [replicaTail_eq_ratio] + exact div_nonneg (replicaTailWeight_nonneg J ε) (sq_nonneg _) + +lemma replicaTailWeight_le_partition_sq {n : ℕ} (J : Interaction n) (ε : ℝ) : + replicaTailWeight J ε ≤ partition J ^ 2 := by + rw [partition_sq_eq_sum] + apply Finset.sum_le_sum + intro x _ + apply Finset.sum_le_sum + intro y _ + split_ifs + · exact le_rfl + · positivity + +lemma replicaTail_le_one {n : ℕ} (J : Interaction n) (ε : ℝ) : + replicaTail J ε ≤ 1 := by + rw [replicaTail_eq_ratio, div_le_one (sq_pos_of_pos (partition_pos J))] + exact replicaTailWeight_le_partition_sq J ε + +lemma integrable_replicaTailWeight (β ε : ℝ) (n : ℕ) : + Integrable (fun g => replicaTailWeight (sampledInteraction g) ε) (disorderLaw β n) := by + apply integrable_finsetSum + intro x _ + apply integrable_finsetSum + intro y _ + by_cases h : ε * n < |replicaOverlap x y| + · simp only [h, ite_true] + exact integrable_exp_combined_energy β x y + · simp only [h, ite_false] + exact integrable_zero _ ℝ _ + +lemma integral_replicaTailWeight (β ε : ℝ) {n : ℕ} (hn : 0 < n) : + (∫ g, replicaTailWeight (sampledInteraction g) ε ∂disorderLaw β n) = + Real.exp (β^2*((n : ℝ)-2)/2) * + ∑ x : Spin n, ∑ y : Spin n, if ε*n < |replicaOverlap x y| then + Real.exp (β^2 * replicaOverlap x y ^ 2 / (2*n)) else 0 := by + have hi (x y : Spin n) : Integrable (fun g => + if ε*n < |replicaOverlap x y| then + Real.exp (energy (sampledInteraction g) x + energy (sampledInteraction g) y) + else 0) (disorderLaw β n) := by + split_ifs + · exact integrable_exp_combined_energy β x y + · exact integrable_zero _ ℝ _ + unfold replicaTailWeight + rw [integral_finsetSum _ (fun x _ => integrable_finsetSum _ (fun y _ => hi x y))] + simp_rw [integral_finsetSum _ (fun y _ => hi _ y), Finset.mul_sum] + apply Finset.sum_congr rfl + intro x _ + apply Finset.sum_congr rfl + intro y _ + split_ifs + · rw [integral_exp_combined_energy β hn, Real.exp_add] + · simp + +lemma replicaTailWeight_annealed_identity (β ε : ℝ) {n : ℕ} (hn : 0 < n) : + (∫ g, replicaTailWeight (sampledInteraction g) ε ∂disorderLaw β n) / + (∫ g, partition (sampledInteraction g) ∂disorderLaw β n)^2 = + Real.exp (-β^2/2) * + (∑ x : Spin n, if ε*n < |magnetization x| then + Real.exp (β^2 * magnetization x ^ 2 / (2*n)) else 0) / (2 : ℝ)^n := by + rw [integral_replicaTailWeight β ε hn, integral_partition_sampled β hn] + simp_rw [sum_replicaOverlap _ (fun z => if ε*n < |z| then Real.exp (β^2*z^2/(2*n)) else 0)] + simp only [Finset.sum_const, Finset.card_univ, card_spin, nsmul_eq_mul, + Nat.cast_pow, Nat.cast_ofNat, mul_pow] + have he : Real.exp (β^2*((n : ℝ)-2)/2) = + Real.exp (-β^2/2) * Real.exp (β^2*((n : ℝ)-1)/4)^2 := by + rw [← Real.exp_nat_mul, ← Real.exp_add] + congr 1 + ring + rw [he] + field_simp + +lemma sign_square_tail_le (β q ε : ℝ) (hβq : β^2 < q) (hq : q < 1) + (hε : 0 < ε) {n : ℕ} (hn : 0 < n) : + (∑ x : Spin n, if ε*n < |magnetization x| then + Real.exp (β^2 * magnetization x ^ 2 / (2*n)) else 0) / (2 : ℝ)^n ≤ + Real.exp (-((q-β^2)*ε^2*n/2)) * (Real.sqrt (1-q))⁻¹ := by + have hq0 : 0 ≤ q := (sq_nonneg β).trans hβq.le + have hqβ : 0 ≤ q-β^2 := sub_nonneg.mpr hβq.le + have hnR : 0 < (n : ℝ) := by exact_mod_cast hn + have hs := sign_square_moment_le (Real.sqrt q) (by rwa [Real.sq_sqrt hq0]) hn + rw [Real.sq_sqrt hq0] at hs + have hpoint (x : Spin n) : + (if ε*n < |magnetization x| then Real.exp (β^2 * magnetization x ^ 2 / (2*n)) else 0) ≤ + Real.exp (-((q-β^2)*ε^2*n/2)) * Real.exp (q * magnetization x ^ 2 / (2*n)) := by + split_ifs with hx + · rw [← Real.exp_add] + apply Real.exp_le_exp.mpr + have hsq : ε^2 * (n : ℝ)^2 ≤ magnetization x ^ 2 := by + have h := (sq_le_sq₀ (by positivity : 0 ≤ ε*(n : ℝ)) (abs_nonneg _)).mpr hx.le + simpa only [mul_pow, sq_abs] using h + have hm := mul_le_mul_of_nonneg_left hsq hqβ + have hd : (q-β^2)*ε^2*n/2 ≤ (q-β^2) * magnetization x ^ 2 / (2*n) := by + apply (le_div_iff₀ (by positivity : 0 < (2 : ℝ)*n)).mpr + nlinarith + rw [sub_mul q (β^2) (magnetization x^2), sub_div] at hd + linarith + · positivity + calc + _ ≤ (∑ x : Spin n, Real.exp (-((q-β^2)*ε^2*n/2)) * + Real.exp (q * magnetization x ^ 2 / (2*n))) / (2 : ℝ)^n := + div_le_div_of_nonneg_right (Finset.sum_le_sum fun x _ => hpoint x) (by positivity) + _ = Real.exp (-((q-β^2)*ε^2*n/2)) * + ((∑ x : Spin n, Real.exp (q * magnetization x^2/(2*n))) / (2 : ℝ)^n) := by + rw [← Finset.mul_sum] + ring + _ ≤ _ := mul_le_mul_of_nonneg_left hs (Real.exp_pos _).le + +lemma replicaTailWeight_annealed_bound (β q ε : ℝ) (hβq : β^2 < q) (hq : q < 1) + (hε : 0 < ε) {n : ℕ} (hn : 0 < n) : + (∫ g, replicaTailWeight (sampledInteraction g) ε ∂disorderLaw β n) / + (∫ g, partition (sampledInteraction g) ∂disorderLaw β n)^2 ≤ + Real.exp (-((q-β^2)*ε^2*n/2)) * (Real.sqrt (1-q))⁻¹ := by + rw [replicaTailWeight_annealed_identity β ε hn, mul_div_assoc] + have he : Real.exp (-β^2/2) ≤ 1 := Real.exp_le_one_iff.mpr (by nlinarith [sq_nonneg β]) + calc + _ ≤ Real.exp (-β^2/2) * (Real.exp (-((q-β^2)*ε^2*n/2)) * (Real.sqrt (1-q))⁻¹) := + mul_le_mul_of_nonneg_left (sign_square_tail_le β q ε hβq hq hε hn) (Real.exp_pos _).le + _ ≤ _ := by simpa only [one_mul] using mul_le_mul_of_nonneg_right he (by positivity) + +lemma probability_markov_real {E : Type*} [MeasurableSpace E] (μ : Measure E) + [IsFiniteMeasure μ] (Y : E → ℝ) (hY : Integrable Y μ) (hY0 : ∀ x, 0 ≤ Y x) + (t : ℝ) (ht : 0 < t) : + μ {x | t ≤ Y x} ≤ ENNReal.ofReal ((∫ x, Y x ∂μ) / t) := by + have h := mul_meas_ge_le_integral_of_nonneg (μ := μ) + (Filter.Eventually.of_forall hY0) hY t + rw [mul_comm t, ← le_div_iff₀ ht] at h + rw [← ENNReal.ofReal_toReal (measure_ne_top μ _)] + exact ENNReal.ofReal_le_ofReal h + +lemma scalar_log_ratio_tail (Z m W δ a : ℝ) (hZ0 : 0 < Z) (hm : 0 < m) + (hδ : 0 < δ) (hlog : Real.log m-a ≤ Real.log Z) (hW : δ < W/Z^2) : + δ * Real.exp (-2*a) ≤ W/m^2 := by + have hZ : m * Real.exp (-a) ≤ Z := by + have he := Real.exp_le_exp.mpr hlog + rw [show Real.log m-a = Real.log m + (-a) by ring, Real.exp_add, + Real.exp_log hm, Real.exp_log hZ0] at he + exact he + have hZ2 := pow_le_pow_left₀ (mul_nonneg hm.le (Real.exp_pos _).le) hZ 2 + have he : (m * Real.exp (-a))^2 = m^2 * Real.exp (-2*a) := by + rw [mul_pow, ← Real.exp_nat_mul] + congr 2 + ring + rw [he] at hZ2 + rw [lt_div_iff₀ (sq_pos_of_pos hZ0)] at hW + apply (le_div_iff₀ (sq_pos_of_pos hm)).mpr + nlinarith [mul_le_mul_of_nonneg_left hZ2 hδ.le] + +lemma divide_exponential_scalar (W m δ a : ℝ) : + (W/m^2) / (δ*Real.exp (-2*a)) = (Real.exp (2*a)/δ) * (W/m^2) := by + rw [show -2*a = -(2*a) by ring, Real.exp_neg] + simp only [div_eq_mul_inv, mul_inv_rev, inv_inv] + ring + +lemma replicaTail_probability_transfer (β ε δ a : ℝ) {n : ℕ} (hn : 0 < n) + (hδ : 0 < δ) : + (disorderLaw β n) {g | δ < replicaTail (sampledInteraction g) ε} ≤ + (disorderLaw β n) {g | Real.log (partition (sampledInteraction g)) < + Real.log (∫ h, partition (sampledInteraction h) ∂disorderLaw β n) - a} + + ENNReal.ofReal ((Real.exp (2*a)/δ) * + ((∫ g, replicaTailWeight (sampledInteraction g) ε ∂disorderLaw β n) / + (∫ g, partition (sampledInteraction g) ∂disorderLaw β n)^2)) := by + let μ := disorderLaw β n + let : IsProbabilityMeasure μ := by dsimp [μ, disorderLaw]; infer_instance + let m := ∫ g, partition (sampledInteraction g) ∂μ + have hm : 0 < m := by dsimp [m, μ]; rw [integral_partition_sampled β hn]; positivity + let Y := fun g : GaussianCoordinates n => replicaTailWeight (sampledInteraction g) ε / m^2 + let t := δ * Real.exp (-2*a) + have ht : 0 < t := by dsimp [t]; positivity + have hY : Integrable Y μ := (integrable_replicaTailWeight β ε n).div_const _ + have hY0 (g) : 0 ≤ Y g := div_nonneg (replicaTailWeight_nonneg _ ε) (sq_nonneg _) + have hsub : {g | δ < replicaTail (sampledInteraction g) ε} ⊆ + {g | Real.log (partition (sampledInteraction g)) < Real.log m - a} ∪ {g | t ≤ Y g} := by + intro g hg + by_cases hl : Real.log (partition (sampledInteraction g)) < Real.log m - a + · exact Or.inl hl + right + change δ * Real.exp (-2*a) ≤ replicaTailWeight (sampledInteraction g) ε / m^2 + apply scalar_log_ratio_tail _ _ _ _ _ (partition_pos _) hm hδ (le_of_not_gt hl) + rwa [← replicaTail_eq_ratio] + have hmarkov := probability_markov_real μ Y hY hY0 t ht + have hid : (∫ g, Y g ∂μ) / t = (Real.exp (2*a)/δ) * + ((∫ g, replicaTailWeight (sampledInteraction g) ε ∂μ) / m^2) := by + dsimp [Y, t] + rw [integral_div, divide_exponential_scalar] + rw [hid] at hmarkov + exact (measure_mono hsub).trans ((measure_union_le _ _).trans + (add_le_add le_rfl hmarkov)) + +lemma replicaTail_disorder_probability_bound (β q ε δ : ℝ) (hβq : β^2 < q) + (hq : q < 1) (hε : 0 < ε) (hδ : 0 < δ) {n : ℕ} (hn : 0 < n) : + (disorderLaw β n) {g | δ < replicaTail (sampledInteraction g) ε} ≤ + (disorderLaw β n) {g | (q-β^2)*ε^2/8 < + |(Real.log (partition (sampledInteraction g)) - + Real.log (∫ h, partition (sampledInteraction h) ∂disorderLaw β n)) / n|} + + ENNReal.ofReal (((Real.sqrt (1-q))⁻¹ / δ) * Real.exp (-((q-β^2)*ε^2*n/4))) := by + have hnR : 0 < (n : ℝ) := by exact_mod_cast hn + have h := replicaTail_probability_transfer β ε δ ((q-β^2)*ε^2*n/8) hn hδ + apply h.trans + apply add_le_add + · apply measure_mono + intro g hg + have hd : (Real.log (partition (sampledInteraction g)) - + Real.log (∫ h, partition (sampledInteraction h) ∂disorderLaw β n)) / n < + -((q-β^2)*ε^2/8) := by + apply (div_lt_iff₀ hnR).mpr + change Real.log (partition (sampledInteraction g)) < _ at hg + linarith + change (q-β^2)*ε^2/8 < _ + linarith [neg_le_abs ((Real.log (partition (sampledInteraction g)) - + Real.log (∫ h, partition (sampledInteraction h) ∂disorderLaw β n)) / n)] + · apply ENNReal.ofReal_le_ofReal + calc + _ ≤ (Real.exp (2*((q-β^2)*ε^2*n/8))/δ) * + (Real.exp (-((q-β^2)*ε^2*n/2)) * (Real.sqrt (1-q))⁻¹) := + mul_le_mul_of_nonneg_left (replicaTailWeight_annealed_bound β q ε hβq hq hε hn) + (by positivity) + _ = _ := by + have he : Real.exp (2*((q-β^2)*ε^2*(n : ℝ)/8)) * + Real.exp (-((q-β^2)*ε^2*n/2)) = Real.exp (-((q-β^2)*ε^2*n/4)) := by + rw [← Real.exp_add] + congr 1 + ring + calc + _ = (Real.exp (2*((q-β^2)*ε^2*(n : ℝ)/8)) * + Real.exp (-((q-β^2)*ε^2*n/2))) * (Real.sqrt (1-q))⁻¹ / δ := by ring + _ = _ := by rw [he]; ring + +lemma replica_overlap_vanishes (β : ℝ) (hβ : β^2 < 1) (ε : ℝ) (hε : 0 < ε) : + DisorderLimit β (fun _ J => replicaTail J ε) 0 := by + intro δ hδ + let q := (β^2+1)/2 + have hβq : β^2 < q := by dsimp [q]; linarith + have hq : q < 1 := by dsimp [q]; linarith + have ha : 0 < (q-β^2)*ε^2/8 := by positivity + have hb : 0 < (q-β^2)*ε^2/4 := by positivity + have hlog := log_partition_annealed_difference_limit β hβ ((q-β^2)*ε^2/8) ha + simp only [sub_zero] at hlog + have hexp : Tendsto (fun n : ℕ => Real.exp (-((q-β^2)*ε^2*n/4))) atTop (nhds 0) := by + have hlin := (tendsto_natCast_atTop_atTop : Tendsto (fun n : ℕ => (n : ℝ)) atTop atTop) + |>.const_mul_atTop hb + have he := Real.tendsto_exp_neg_atTop_nhds_zero.comp hlin + convert he using 1 + ext n + congr 1 + ring + have hbound : Tendsto (fun n : ℕ => ENNReal.ofReal (((Real.sqrt (1-q))⁻¹/δ) * + Real.exp (-((q-β^2)*ε^2*n/4)))) atTop (nhds 0) := by + simpa only [Function.comp_def, mul_zero, ENNReal.ofReal_zero] using + ENNReal.continuous_ofReal.continuousAt.tendsto.comp (hexp.const_mul ((Real.sqrt (1-q))⁻¹/δ)) + have hsum := hlog.add hbound + simp only [zero_add] at hsum + apply tendsto_of_tendsto_of_tendsto_of_le_of_le' tendsto_const_nhds hsum + (Eventually.of_forall (fun _ => bot_le)) + filter_upwards [eventually_ge_atTop 1] with n hn + simpa only [sub_zero, abs_of_nonneg (replicaTail_nonneg _ _)] using + replicaTail_disorder_probability_bound β q ε δ hβq hq hε hδ (by omega : 0 < n) + +end SKGapCutoff + +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise + +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Gaussian/SampledInnerTailScaled.lean b/lean/OAI/Probability/SKGap/Gaussian/SampledInnerTailScaled.lean new file mode 100644 index 0000000000000000000000000000000000000000..12dc0f7bbae5a7203f1250c6dffc8d772e59be89 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Gaussian/SampledInnerTailScaled.lean @@ -0,0 +1,205 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.BilinearCoefficient + +namespace OAI + +section +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open scoped BigOperators +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open scoped BigOperators +open scoped BigOperators NNReal ENNReal +open MeasureTheory Metric Set +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators NNReal ENNReal Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Set +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators ENNReal NNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Matrix +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators ENNReal NNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal +open scoped BigOperators +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise NNReal ENNReal +open scoped BigOperators +open Filter Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal Topology +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Set Matrix +open scoped BigOperators NNReal ENNReal Matrix.Norms.L2Operator +namespace SKGapCutoff.RandomMatrix + +lemma sampled_inner_tail_scaled (β : ℝ) (hβ : 0 < β) {n : ℕ} (hn : 0 < n) + (x y : EuclideanSpace ℝ (Fin n)) (hx : ‖x‖ ≤ 1) (hy : ‖y‖ ≤ 1) : + disorderLaw β n {g | 11*β ≤ |inner (𝕜 := ℝ) + (Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) (sampledInteraction g) x) y|} ≤ + 2 * ENNReal.ofReal (Real.exp (-(10:ℝ)*n)) := by + have hnR : (0:ℝ) < n := Nat.cast_pos.mpr hn + have hcoef : ∑ p, bilinearCoefficient y x p ^ 2 ≤ 2 := by + have hh := bilinearCoefficient_sq_le y x + rw [← EuclideanSpace.real_norm_sq_eq, ← EuclideanSpace.real_norm_sq_eq] at hh + have hx2 : ‖x‖^2 ≤ 1 := by nlinarith [norm_nonneg x] + have hy2 : ‖y‖^2 ≤ 1 := by nlinarith [norm_nonneg y] + nlinarith [mul_le_mul hy2 hx2 (sq_nonneg ‖x‖) (by norm_num : (0:ℝ) ≤ 1)] + simp_rw [sampled_inner] + have hh := gaussian_linear_abs_tail (Real.toNNReal (β^2/n)) + (bilinearCoefficient y x) (11*β) (n/β) (div_pos hnR hβ) + refine hh.trans (mul_le_mul' (le_refl 2) (ENNReal.ofReal_le_ofReal (Real.exp_le_exp.mpr ?_))) + rw [Real.coe_toNNReal _ (div_nonneg (sq_nonneg β) hnR.le)] + have hv : β^2/(n:ℝ) * (∑ p, bilinearCoefficient y x p^2) * (n/β)^2 / 2 ≤ n := by + calc + _ ≤ β^2/(n:ℝ) * 2 * (n/β)^2 / 2 := by gcongr + _ = _ := by field_simp + have he : (n:ℝ)/β*(11*β)=11*n := by field_simp + rw [he] + linarith + +lemma sampled_opNorm_tail_scaled (β : ℝ) (hβ : 0 < β) {n : ℕ} (hn : 0 < n) : + disorderLaw β n {g | 2*(11*β) < ‖Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) (sampledInteraction g)‖} ≤ + ENNReal.ofReal (2 * (81:ℝ)^n * Real.exp (-(10:ℝ)*n)) := by + classical + obtain ⟨s, hb, hc, hs⟩ := unit_ball_net n + let E (x y : EuclideanSpace ℝ (Fin n)) : Set (GaussianCoordinates n) := + {g | 11*β ≤ |inner (𝕜 := ℝ) (Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) (sampledInteraction g) x) y|} + have hsub : {g | 2*(11*β) < ‖Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) (sampledInteraction g)‖} ⊆ + ⋃ x ∈ s, ⋃ y ∈ s, E x y := by + intro g hg + by_contra hnot + have hb' : ∀ x ∈ s, ∀ y ∈ s, |inner (𝕜 := ℝ) + (Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) (sampledInteraction g) x) y| ≤ 11*β := by + intro x hx y hy + have hh : g ∉ E x y := fun hgE => hnot (Set.mem_iUnion₂.mpr + ⟨x, hx, Set.mem_iUnion₂.mpr ⟨y, hy, hgE⟩⟩) + exact (not_le.mp hh).le + have hh := opNorm_le_of_net (Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) (sampledInteraction g)) s hb hc + (11*β) (by positivity) hb' + exact not_lt_of_ge hh hg + have hu : disorderLaw β n (⋃ x ∈ s, ⋃ y ∈ s, E x y) ≤ + ∑ x ∈ s, ∑ y ∈ s, disorderLaw β n (E x y) := by + refine (measure_biUnion_finset_le s _).trans ?_ + exact Finset.sum_le_sum (fun x _ => measure_biUnion_finset_le s (E x)) + refine (measure_mono hsub).trans (hu.trans ?_) + calc + _ ≤ ∑ _x ∈ s, ∑ _y ∈ s, 2 * ENNReal.ofReal (Real.exp (-(10:ℝ)*n)) := by + exact Finset.sum_le_sum (fun x hx => Finset.sum_le_sum (fun y hy => + sampled_inner_tail_scaled β hβ hn x y (hb x hx) (hb y hy))) + _ = ENNReal.ofReal (2 * (s.card:ℝ)^2 * Real.exp (-(10:ℝ)*n)) := by + simp only [Finset.sum_const, nsmul_eq_mul] + rw [ENNReal.ofReal_mul (by positivity), ENNReal.ofReal_mul (by norm_num : (0:ℝ) ≤ 2)] + simp only [ENNReal.ofReal_ofNat, ENNReal.ofReal_pow (show (0:ℝ) ≤ s.card by positivity), ENNReal.ofReal_natCast] + ring + _ ≤ _ := ENNReal.ofReal_le_ofReal (by + have hh : (s.card : ℝ)^2 ≤ (81:ℝ)^n := by + calc + _ ≤ ((9:ℝ)^n)^2 := pow_le_pow_left₀ (by positivity) hs 2 + _ = _ := by rw [← pow_mul, mul_comm n 2, pow_mul]; norm_num + gcongr) + +lemma sampled_opNorm_tendsto_scaled (β : ℝ) (hβ : 0 < β) : + Tendsto (fun n => disorderLaw β n {g | + 2*(11*β) < ‖Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) (sampledInteraction g)‖}) + atTop (nhds 0) := by + have hq : 81 * Real.exp (-10) < 1 := by + rw [Real.exp_neg, ← div_eq_mul_inv, div_lt_one (Real.exp_pos _)] + have h2 : (2:ℝ) ≤ Real.exp 1 := by linarith [Real.add_one_le_exp 1] + have hp : (81:ℝ) < (Real.exp 1)^10 := (by norm_num : (81:ℝ) < 2^10).trans_le + (pow_le_pow_left₀ (by norm_num) h2 10) + simpa only [← Real.exp_nat_mul, Nat.cast_ofNat, mul_one] using hp + have hlim : Tendsto (fun n : ℕ => 2 * (81:ℝ)^n * Real.exp (-(10:ℝ)*n)) + atTop (nhds 0) := by + have hh := (tendsto_pow_atTop_nhds_zero_of_lt_one + (by positivity : (0:ℝ) ≤ 81*Real.exp (-10)) hq).const_mul 2 + simp only [mul_zero] at hh + convert! hh using 1 + ext n + rw [mul_pow, ← Real.exp_nat_mul] + rw [show (n:ℝ)*(-10) = -(10:ℝ)*n by ring] + ring + have hlimE : Tendsto (fun n : ℕ => ENNReal.ofReal + (2 * (81:ℝ)^n * Real.exp (-(10:ℝ)*n))) atTop (nhds 0) := by + convert! ENNReal.continuous_ofReal.continuousAt.tendsto.comp hlim using 1 + simp only [ENNReal.ofReal_zero] + apply tendsto_of_tendsto_of_tendsto_of_le_of_le' tendsto_const_nhds hlimE + (Eventually.of_forall (fun _ => bot_le)) + filter_upwards [eventually_ge_atTop 1] with n hn + exact sampled_opNorm_tail_scaled β hβ hn + +end SKGapCutoff.RandomMatrix + +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Gaussian/ScalarGaussianReductionAlgebra.lean b/lean/OAI/Probability/SKGap/Gaussian/ScalarGaussianReductionAlgebra.lean new file mode 100644 index 0000000000000000000000000000000000000000..13d9b2b2b102e9924eafe74431c75b7c74abd336 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Gaussian/ScalarGaussianReductionAlgebra.lean @@ -0,0 +1,172 @@ +import Mathlib +import OAI.Probability.SKGap.Matrix.GOERegression +import OAI.Probability.SKGap.Brownian.ContinuousKernel + +namespace OAI + +section +noncomputable section +namespace SKGap.GaussianDensity +open MeasureTheory ProbabilityTheory Matrix Real +open scoped BigOperators ENNReal NNReal +variable {ι : Type*} [Fintype ι] + +lemma radialDensity_translate (a c : ℝ) (x m : ι → ℝ) : + radialDensity a (x+c • m)=radialDensity a x* + exp (-(2*c*(x⬝ᵥm)+c^2*(m⬝ᵥm))/(2*a^2)) := by + unfold radialDensity + simp only [add_dotProduct,dotProduct_add,smul_dotProduct,dotProduct_smul,smul_eq_mul] + rw [dotProduct_comm m x] + have he : -(x⬝ᵥx+c*(x⬝ᵥm)+c*(x⬝ᵥm+c*(m⬝ᵥm)))/(2*a^2)= + -(x⬝ᵥx)/(2*a^2)+(-(2*c*(x⬝ᵥm)+c^2*(m⬝ᵥm))/(2*a^2)) := by ring + rw [he,exp_add] + ring + +lemma gaussian_density_shift (d : ℝ) {s : ℝ} (hs : 0 ≤ s) (y : ι → ℝ) : + (∏ i,gaussianPDFReal d (NNReal.mk s hs) (y i))= + radialDensity (sqrt s) (fun i => y i-d) := by + have he (i : ι) : gaussianPDFReal d (NNReal.mk s hs) (y i)= + gaussianPDFReal 0 (NNReal.mk s hs) (y i-d) := by simp [gaussianPDFReal] + simp only [he] + have hv : NNReal.mk s hs=NNReal.mk ((sqrt s)^2) (sq_nonneg (sqrt s)) := by + ext + exact (sq_sqrt hs).symm + rw [hv,product_gaussianPDF_radial (sqrt_nonneg _)] + +lemma scalar_gaussian_exponent {n s S j q b a : ℝ} (hn : n ≠ 0) (hs : s ≠ 0) + (hS : S ≠ 0) (hSq : S=s+j*q) : + -(2*(j*b)*(n*a)+(j*b)^2*(n*q))/(2*s)+ + (j/n)/(2*s*S)*(n*a+j*b*(n*q))^2+n*j*b^2/2 = + n*j*(a-s*b)^2/(2*s*S) := by + subst S + field_simp + ring + +end SKGap.GaussianDensity +end +end + +section +noncomputable section +namespace SKGap.GaussianDensity +open MeasureTheory ProbabilityTheory Matrix Real +open scoped BigOperators ENNReal NNReal +variable {ι : Type*} [Fintype ι] + +theorem rankOneDensity_cancellation {n s S j q b a : ℝ} (hn : n ≠ 0) + (hs : 0 < s) (hS : S ≠ 0) (hSq : S=s+j*q) + (x m : ι → ℝ) (hm : m⬝ᵥm=n*q) (hx : x⬝ᵥm=n*a) : + rankOneDensity s (j/n) m (x+(j*b) • m)*exp (n*j*b^2/2) = + sqrt (s/S)*radialDensity (sqrt s) x*exp (n*j*(a-s*b)^2/(2*s*S)) := by + have he : s+(j/n)*(m⬝ᵥm)=S := by rw [hm,hSq]; field_simp + rw [rankOneDensity,he,radialDensity_translate,sq_sqrt hs.le,hm,hx] + simp only [dotProduct_add,dotProduct_smul,smul_eq_mul] + rw [dotProduct_comm m x,hm,hx] + have hE := scalar_gaussian_exponent hn hs.ne' hS hSq (j := j) (q := q) (b := b) (a := a) + calc + _ = sqrt (s/S)*radialDensity (sqrt s) x* + exp (-(2*(j*b)*(n*a)+(j*b)^2*(n*q))/(2*s)+ + (j/n)/(2*s*S)*(n*a+j*b*(n*q))^2+n*j*b^2/2) := by rw [exp_add,exp_add]; ring + _ = _ := by rw [hE] + +end SKGap.GaussianDensity +end +end + +section +noncomputable section +namespace SKGap.GaussianDensity +open MeasureTheory ProbabilityTheory Matrix Real Set +open scoped BigOperators ENNReal NNReal +variable {ι : Type*} [Fintype ι] + +lemma pi_gaussian_convolution (m₁ m₂ : ι → ℝ) (v₁ v₂ : ι → ℝ≥0) : + ((Measure.pi (fun i=>gaussianReal (m₁ i) (v₁ i))).prod + (Measure.pi (fun i=>gaussianReal (m₂ i) (v₂ i)))).map (fun p=>p.1+p.2)= + Measure.pi (fun i=>gaussianReal (m₁ i+m₂ i) (v₁ i+v₂ i)) := by + have h := (measurePreserving_arrowProdEquivProdArrow ℝ ℝ ι + (fun i=>gaussianReal (m₁ i) (v₁ i)) (fun i=>gaussianReal (m₂ i) (v₂ i))).map_eq + rw [← h,Measure.map_map (by fun_prop) (MeasurableEquiv.arrowProdEquivProdArrow ℝ ℝ ι).measurable] + change (Measure.pi (fun i=>(gaussianReal (m₁ i) (v₁ i)).prod (gaussianReal (m₂ i) (v₂ i)))).map + (fun x i=> (x i).1+(x i).2)=_ + have (i : ι) : IsProbabilityMeasure (((gaussianReal (m₁ i) (v₁ i)).prod + (gaussianReal (m₂ i) (v₂ i))).map (fun p : ℝ×ℝ=>p.1+p.2)) := + inferInstance + rw [Measure.pi_map_pi (f := fun (_ : ι) (p : ℝ×ℝ)=>p.1+p.2) (fun _=>by fun_prop)] + congr 1 + funext i + exact gaussianReal_conv_gaussianReal + +theorem continuous_convolution_density (μ : Measure (ι → ℝ)) [IsProbabilityMeasure μ] + {φ p : (ι → ℝ) → ℝ} (hφ : Continuous φ) (hp : Continuous p) + (hφpos : ∀ x,0 ≤ φ x) + {C : ℝ} (hφC : ∀ x,φ x ≤ C) + (hconv : (μ.prod ((volume : Measure (ι → ℝ)).withDensity (fun x=>ENNReal.ofReal (φ x)))).map + (fun q=>q.1+q.2)=(volume : Measure (ι → ℝ)).withDensity (fun x=>ENNReal.ofReal (p x))) + (z : ι → ℝ) : + (∫⁻ x, ENNReal.ofReal (φ (z-x)) ∂μ)=ENNReal.ofReal (p z) := by + let K : (ι → ℝ) → ℝ≥0∞ := fun y=>∫⁻ x,ENNReal.ofReal (φ (y-x)) ∂μ + have hK : Measurable K := by dsimp [K]; fun_prop + have hae : K=ᵐ[volume] (fun y=>ENNReal.ofReal (p y)) := by + apply (withDensity_eq_iff_of_sigmaFinite hK.aemeasurable hp.measurable.ennreal_ofReal.aemeasurable).mp + ext s hs + rw [withDensity_apply _ hs,withDensity_apply _ hs] + let F : (ι → ℝ) × (ι → ℝ) → ℝ≥0∞ := fun q=>s.indicator (fun _=>1) q.2 + have hF : Measurable F := measurable_const.indicator (hs.preimage measurable_snd) + have hh := additive_noise_lintegral μ (fun x=>ENNReal.ofReal (φ x)) + hφ.measurable.ennreal_ofReal id measurable_id F hF + have hm : Measurable (s.indicator (fun _=> (1 : ℝ≥0∞))) := measurable_const.indicator hs + have he := congrArg (fun ν=>∫⁻ y,s.indicator (fun _=> (1 : ℝ≥0∞)) y ∂ν) hconv + rw [lintegral_map hm (by fun_prop),lintegral_withDensity_eq_lintegral_mul _ + hp.measurable.ennreal_ofReal hm] at he + change (∫⁻ q,F (q.1,id q.1+q.2) ∂μ.prod (volume.withDensity (fun x=>ENNReal.ofReal (φ x))))=_ at he + rw [hh] at he + have hleft (y : ι → ℝ) : (∫⁻ x, ENNReal.ofReal (φ (y-id x))*F (x,y) ∂μ)=s.indicator K y := by + by_cases hy : y∈s <;> simp [F,K,hy] + have hright (y : ι → ℝ) : ENNReal.ofReal (p y)*s.indicator (fun _=>(1 : ℝ≥0∞)) y= + s.indicator (fun y=>ENNReal.ofReal (p y)) y := by by_cases hy : y∈s <;> simp [hy] + simp only [Pi.mul_apply,hleft,hright,lintegral_indicator hs] at he + exact he + have hi (y : ι → ℝ) : Integrable (fun x=>φ (y-x)) μ := + integrable_bounded μ (by fun_prop) (fun x=>by rw [norm_eq_abs,abs_of_nonneg (hφpos _)]; exact hφC _) + have hc : Continuous (fun y : ι → ℝ=>∫ x,φ (y-x) ∂μ) := by + apply continuous_of_dominated (bound := fun _=>C) + · intro y; exact (hi y).aestronglyMeasurable + · intro y; exact Filter.Eventually.of_forall (fun x=>by rw [norm_eq_abs,abs_of_nonneg (hφpos _)]; exact hφC _) + · exact integrable_const C + · exact Filter.Eventually.of_forall (fun x=>by fun_prop) + have he (y : ι → ℝ) : K y=ENNReal.ofReal (∫ x,φ (y-x) ∂μ) := + (ofReal_integral_eq_lintegral_ofReal (hi y) (Filter.Eventually.of_forall (fun x=>hφpos _))).symm + have hcont : Continuous K := by rw [show K=(fun y=>ENNReal.ofReal (∫ x,φ (y-x) ∂μ)) from funext he]; exact ENNReal.continuous_ofReal.comp hc + exact congrFun ((Continuous.ae_eq_iff_eq (volume : Measure (ι → ℝ)) hcont + (ENNReal.continuous_ofReal.comp hp)).mp hae) z + +theorem gaussian_radial_convolution {t σ : ℝ} (ht : 0 ≤ t) (hσ : 0 < σ) (z : ι → ℝ) : + (∫⁻ x, ENNReal.ofReal (radialDensity σ (z-x)) + ∂Measure.pi (fun _ : ι=>gaussianReal 0 t.toNNReal))= + ENNReal.ofReal (radialDensity (sqrt (t+σ^2)) z) := by + classical + have hv : 0 < t+σ^2 := add_pos_of_nonneg_of_pos ht (sq_pos_of_pos hσ) + have hnoise : Measure.pi (fun _ : ι=>gaussianReal 0 (NNReal.mk (σ^2) (sq_nonneg σ)))= + (volume : Measure (ι → ℝ)).withDensity (fun x=>ENNReal.ofReal (radialDensity σ x)) := by + rw [pi_gaussian_density _ _ (fun _=>by intro hh; have hh' := congrArg (fun r : ℝ≥0=>(r:ℝ)) hh; exact (sq_pos_of_pos hσ).ne' hh')] + congr 1; funext x; rw [product_gaussianPDF_radial hσ.le] + have hout : Measure.pi (fun _ : ι=>gaussianReal 0 (t.toNNReal+NNReal.mk (σ^2) (sq_nonneg σ)))= + (volume : Measure (ι → ℝ)).withDensity (fun x=>ENNReal.ofReal (radialDensity (sqrt (t+σ^2)) x)) := by + rw [pi_gaussian_density _ _ (fun _=>by + have he : (↑(t.toNNReal+NNReal.mk (σ^2) (sq_nonneg σ)):ℝ)=t+σ^2 := by simp [Real.coe_toNNReal _ ht] + exact_mod_cast (show (↑(t.toNNReal+NNReal.mk (σ^2) (sq_nonneg σ)):ℝ)≠0 by rw [he]; exact hv.ne'))] + congr 1; funext x + have he : t.toNNReal+NNReal.mk (σ^2) (sq_nonneg σ)=NNReal.mk ((sqrt (t+σ^2))^2) (sq_nonneg _) := by + ext; simp [Real.coe_toNNReal _ ht,sq_sqrt hv.le] + rw [he,product_gaussianPDF_radial (sqrt_nonneg _)] + apply continuous_convolution_density _ (continuous_radialDensity σ) + (continuous_radialDensity _) (fun x=>(radialDensity_pos hσ x).le) + (radialDensity_le hσ) + rw [← hnoise,pi_gaussian_convolution] + simpa only [zero_add] using hout +end SKGap.GaussianDensity +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Gaussian/ScalarMomentGram.lean b/lean/OAI/Probability/SKGap/Gaussian/ScalarMomentGram.lean new file mode 100644 index 0000000000000000000000000000000000000000..400c9b6a6a02c3448d8aa4a042f9413a6479fa94 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Gaussian/ScalarMomentGram.lean @@ -0,0 +1,93 @@ +import Mathlib +import OAI.Probability.SKGap.Entropy.WeightedScalarMoments +import OAI.Probability.SKGap.Localization.EmpiricalLaw + +namespace OAI + +section +noncomputable section +namespace SKGap +open Real Matrix MeasureTheory ProbabilityTheory Set +open scoped BigOperators Matrix.Norms.Frobenius + +def gramCoordinates (d s y : ℝ) : Fin 3 → ℝ := ![1,tanh y,(y-d)/s] + +def scalarMomentGram (P : ProbabilityMeasure ℝ) (d s : ℝ) : Matrix (Fin 3) (Fin 3) ℝ := + let M := fun k l => ∫ y,weightedScalarMoment k l y ∂P + !![M 0 0,M 0 1,(M 1 0-d*M 0 0)/s; + M 0 1,M 0 2,(M 1 1-d*M 0 1)/s; + (M 1 0-d*M 0 0)/s,(M 1 1-d*M 0 1)/s, + (M 2 0-2*d*M 1 0+d^2*M 0 0)/s^2] + +lemma scalarMomentGram_integral (P : ProbabilityMeasure ℝ) (d s : ℝ) : + scalarMomentGram P d s = fun i k => ∫ y, + (1-tanh y^2)*gramCoordinates d s y i*gramCoordinates d s y k ∂P := by + have hi (k l : Fin 3) := (weightedScalarMoment k l).integrable (μ := (P : Measure ℝ)) + have h00 : (∫ y,(1-tanh y^2) ∂P)=∫ y,weightedScalarMoment 0 0 y ∂P := by + congr 1; funext y; simp [weightedScalarMoment] + have h01 : (∫ y,(1-tanh y^2)*tanh y ∂P)=∫ y,weightedScalarMoment 0 1 y ∂P := by + congr 1; funext y; simp [weightedScalarMoment]; ring + have h02 : (∫ y,(1-tanh y^2)*((y-d)/s) ∂P)= + ((∫ y,weightedScalarMoment 1 0 y ∂P)-d*(∫ y,weightedScalarMoment 0 0 y ∂P))/s := by + calc + _ = ∫ y,(weightedScalarMoment 1 0 y-d*weightedScalarMoment 0 0 y)/s ∂P := by + congr 1; funext y; simp [weightedScalarMoment]; ring + _ = _ := by rw [integral_div,integral_sub (hi 1 0) ((hi 0 0).const_mul d),integral_const_mul] + have h11 : (∫ y,(1-tanh y^2)*tanh y*tanh y ∂P)=∫ y,weightedScalarMoment 0 2 y ∂P := by + congr 1; funext y; simp [weightedScalarMoment]; ring + have h12 : (∫ y,(1-tanh y^2)*tanh y*((y-d)/s) ∂P)= + ((∫ y,weightedScalarMoment 1 1 y ∂P)-d*(∫ y,weightedScalarMoment 0 1 y ∂P))/s := by + calc + _ = ∫ y,(weightedScalarMoment 1 1 y-d*weightedScalarMoment 0 1 y)/s ∂P := by + congr 1; funext y; simp [weightedScalarMoment]; ring + _ = _ := by rw [integral_div,integral_sub (hi 1 1) ((hi 0 1).const_mul d),integral_const_mul] + have h22 : (∫ y,(1-tanh y^2)*((y-d)/s)*((y-d)/s) ∂P)= + ((∫ y,weightedScalarMoment 2 0 y ∂P)-2*d*(∫ y,weightedScalarMoment 1 0 y ∂P)+ + d^2*(∫ y,weightedScalarMoment 0 0 y ∂P))/s^2 := by + calc + _ = ∫ y,(weightedScalarMoment 2 0 y-2*d*weightedScalarMoment 1 0 y+ + d^2*weightedScalarMoment 0 0 y)/s^2 ∂P := by + congr 1; funext y; simp [weightedScalarMoment]; ring + _ = _ := by + rw [integral_div,integral_add (show Integrable (fun y => weightedScalarMoment 2 0 y-2*d*weightedScalarMoment 1 0 y) (P : Measure ℝ) from + (hi 2 0).sub ((hi 1 0).const_mul (2*d))) ((hi 0 0).const_mul (d^2)), + integral_sub (hi 2 0) ((hi 1 0).const_mul (2*d))] + simp only [integral_const_mul] + ext i k + fin_cases i <;> fin_cases k <;> + simp [scalarMomentGram,gramCoordinates] + all_goals first | exact h00.symm | exact h01.symm | exact h02.symm | + exact h11.symm | exact h12.symm | exact h22.symm | + (convert h12.symm using 1; congr 1; funext y; ring) + +lemma continuousAt_scalarMomentGram {p : ProbabilityMeasure ℝ × (ℝ × ℝ)} (hs : p.2.2 ≠ 0) : + ContinuousAt (fun p : ProbabilityMeasure ℝ × (ℝ × ℝ) => scalarMomentGram p.1 p.2.1 p.2.2) p := by + apply continuousAt_pi.mpr + intro i + apply continuousAt_pi.mpr + intro k + have hm (i k : Fin 3) : Continuous (fun p : ProbabilityMeasure ℝ × (ℝ × ℝ) => + ∫ y,weightedScalarMoment i k y ∂p.1) := + (continuous_weightedScalarMoment_integral i k).comp continuous_fst + have hd : Continuous (fun p : ProbabilityMeasure ℝ × (ℝ × ℝ) => p.2.1) := continuous_fst.comp continuous_snd + have hss : Continuous (fun p : ProbabilityMeasure ℝ × (ℝ × ℝ) => p.2.2) := continuous_snd.comp continuous_snd + fin_cases i <;> fin_cases k <;> + simp only [scalarMomentGram, Matrix.of_apply, Matrix.cons_val,Fin.isValue,Fin.reduceFinMk] + all_goals first | exact (hm _ _).continuousAt | + exact ((hm _ _).continuousAt.sub (hd.continuousAt.mul (hm _ _).continuousAt)).div hss.continuousAt hs | + exact (((hm _ _).continuousAt.sub + ((continuousAt_const.mul hd.continuousAt).mul (hm _ _).continuousAt)).add + ((hd.continuousAt.pow 2).mul (hm _ _).continuousAt)).div + (hss.continuousAt.pow 2) (pow_ne_zero _ hs) + +lemma scalarMomentGram_empirical {n : ℕ} [NeZero n] (y : Fin n → ℝ) (d s : ℝ) : + scalarMomentGram (empiricalLaw y) d s = fun i k => + (n:ℝ)⁻¹*∑ l,(1-tanh (y l)^2)*gramCoordinates d s (y l) i*gramCoordinates d s (y l) k := by + rw [scalarMomentGram_integral] + ext i k + simp only [integral_empiricalLaw,Fintype.card_fin] +end SKGap +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Gaussian/SquareTail.lean b/lean/OAI/Probability/SKGap/Gaussian/SquareTail.lean new file mode 100644 index 0000000000000000000000000000000000000000..4da4896a5c051bedbe1fb56db031a3afcc2be068 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Gaussian/SquareTail.lean @@ -0,0 +1,217 @@ +import Mathlib +import OAI.Probability.SKGap.Gaussian.StandardGaussianProduct +import OAI.Probability.SKGap.Localization.EmpiricalLaw +import OAI.Probability.SKGap.Matrix.NormalLogConst + +namespace OAI + +section +noncomputable section +open MeasureTheory ProbabilityTheory InformationTheory Real Set Filter +open scoped NNReal ENNReal Topology +noncomputable section +open Real Set +noncomputable section +open MeasureTheory ProbabilityTheory Real Set Filter +open scoped Topology NNReal ENNReal BoundedContinuousFunction +open MeasureTheory ProbabilityTheory Filter Set Topology Real +open scoped NNReal ENNReal BoundedContinuousFunction +noncomputable section +open Set Filter Topology +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set Topology Real +open scoped NNReal ENNReal BoundedContinuousFunction +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set Topology Real +open scoped NNReal ENNReal BoundedContinuousFunction +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set Topology Real +open scoped NNReal ENNReal +noncomputable section +open MeasureTheory ProbabilityTheory Real Filter Set +open scoped Topology NNReal ENNReal BoundedContinuousFunction +namespace SKGap + +lemma gaussian_exp_quadratic_integrable {d α : ℝ} {s : ℝ≥0} (hs : 0 < s) + (hα : α < 1/(4*(s:ℝ))) : + Integrable (fun y => exp (α*y^2)) (gaussianReal d s) := by + rw [gaussianReal_of_var_ne_zero d (ne_of_gt hs), integrable_withDensity_iff + (measurable_gaussianPDF d s) (ae_of_all _ (fun y => by simp [gaussianPDF]))] + simp only [gaussianPDF, ENNReal.toReal_ofReal (gaussianPDFReal_nonneg _ _ _)] + let c : ℝ := 1/(4*(s:ℝ))-α + have hsp : 0 < (s:ℝ) := hs + have hc : 0 < c := sub_pos.mpr hα + have hi := (integrable_exp_neg_mul_sq hc).const_mul + ((1/sqrt (2*Real.pi*(s:ℝ)))*exp (d^2/(2*(s:ℝ)))) + apply hi.mono' (by fun_prop) + filter_upwards [] with y + rw [Real.norm_eq_abs, abs_of_nonneg (mul_nonneg (exp_pos _).le (gaussianPDFReal_nonneg _ _ _))] + unfold gaussianPDFReal + have hbound : α*y^2 + -(y-d)^2/(2*(s:ℝ)) ≤ d^2/(2*(s:ℝ))-c*y^2 := by + dsimp [c] + field_simp + nlinarith [sq_nonneg (y-2*d)] + calc + _ = (1/sqrt (2*Real.pi*(s:ℝ)))*exp (α*y^2 + -(y-d)^2/(2*(s:ℝ))) := by rw [exp_add]; ring + _ ≤ (1/sqrt (2*Real.pi*(s:ℝ)))*exp (d^2/(2*(s:ℝ))-c*y^2) := + mul_le_mul_of_nonneg_left (exp_le_exp.mpr hbound) (by positivity) + _ = _ := by simp only [sub_eq_add_neg,exp_add,neg_mul,mul_assoc] + +def squareTail (R y : ℝ) : ℝ := if R < |y| then y^2 else 0 + +lemma measurable_squareTail (R : ℝ) : Measurable (squareTail R) := by + unfold squareTail + exact Measurable.ite (measurableSet_lt measurable_const measurable_id.abs) + (measurable_id.pow_const 2) measurable_const + +lemma squareTail_nonneg (R y : ℝ) : 0 ≤ squareTail R y := by + unfold squareTail + split_ifs <;> positivity + +lemma squareTail_le (R y : ℝ) : squareTail R y ≤ y^2 := by + unfold squareTail + split_ifs <;> nlinarith [sq_nonneg y] + +lemma tendsto_squareTail (y : ℝ) : Tendsto (fun R => squareTail R y) atTop (𝓝 0) := by + apply tendsto_const_nhds.congr' + filter_upwards [eventually_ge_atTop |y|] with R hR + exact (ite_eq_right (not_lt.mpr hR)).symm + +lemma tendsto_gaussian_tail_tilt (f : ℝ →ᵇ ℝ) {d α : ℝ} {s : ℝ≥0} + (hs : 0 < s) (hα0 : 0 ≤ α) (hα : α < 1/(4*(s:ℝ))) : + Tendsto (fun R => ∫ y, exp (f y+α*squareTail R y) ∂gaussianReal d s) + atTop (𝓝 (∫ y, exp (f y) ∂gaussianReal d s)) := by + let bound : ℝ → ℝ := fun y => exp ‖f‖*exp (α*y^2) + apply tendsto_integral_filter_of_dominated_convergence bound + · exact Eventually.of_forall (fun R => + ((f.continuous.measurable.add ((measurable_squareTail R).const_mul α)).exp).aestronglyMeasurable) + · exact Eventually.of_forall (fun R => ae_of_all _ (fun y => by + rw [Real.norm_eq_abs,abs_of_pos (exp_pos _)] + dsimp [bound] + rw [← exp_add] + apply exp_le_exp.mpr + exact add_le_add ((le_abs_self _).trans (f.norm_coe_le_norm y)) + (mul_le_mul_of_nonneg_left (squareTail_le R y) hα0))) + · exact (gaussian_exp_quadratic_integrable hs hα).const_mul _ + · exact ae_of_all _ (fun y => by + have h := (tendsto_const_nhds (x := f y)).add ((tendsto_squareTail y).const_mul α) + simpa only [mul_zero, add_zero,Function.comp_def] using (continuous_exp.tendsto _).comp h) + +end SKGap + +namespace SKGap +lemma integrable_gaussian_tail_test (f : ℝ →ᵇ ℝ) {d α : ℝ} {s : ℝ≥0} + (hs : 0 < s) (hα0 : 0 ≤ α) (hα : α < 1/(4*(s:ℝ))) (R : ℝ) : + Integrable (fun y => exp (f y+α*squareTail R y)) (gaussianReal d s) := by + apply ((gaussian_exp_quadratic_integrable hs hα).const_mul (exp ‖f‖)).mono' + (((f.continuous.measurable.add ((measurable_squareTail R).const_mul α)).exp).aestronglyMeasurable) + exact ae_of_all _ (fun y => by + rw [Real.norm_eq_abs,abs_of_pos (exp_pos _),← exp_add] + apply exp_le_exp.mpr + exact add_le_add ((le_abs_self _).trans (f.norm_coe_le_norm y)) + (mul_le_mul_of_nonneg_left (squareTail_le R y) hα0)) + +lemma product_general_test_integrable {ι : Type*} [Fintype ι] {g : ℝ → ℝ} {d s : ℝ} + (hs : 0 < s) (hg : Integrable (fun y => exp (g y)) (gaussianReal d s.toNNReal)) : + Integrable (fun y : ι → ℝ => exp (∑ i, g (y i))*productNormal d s y) := by + have h := Integrable.fintype_prod (fun _ : ι => + (integrable_gaussian_iff (ne_of_gt (Real.toNNReal_pos.mpr hs))).mp hg) + simpa only [exp_sum,productNormal,Finset.prod_mul_distrib,volume_pi,mul_comm] using h + +lemma product_general_test_integral {ι : Type*} [Fintype ι] {g : ℝ → ℝ} {d s : ℝ} + (hs : 0 < s) (hg : Integrable (fun y => exp (g y)) (gaussianReal d s.toNNReal)) : + (∫ y : ι → ℝ, exp (∑ i, g (y i))*productNormal d s y) = + exp ((Fintype.card ι:ℝ)*log (∫ x, exp (g x) ∂gaussianReal d s.toNNReal)) := by + have hz : 0 < ∫ x, exp (g x) ∂gaussianReal d s.toNNReal := + (integral_pos_iff_support_of_nonneg (fun _ => (exp_pos _).le) hg).mpr + (by simp [Function.support,(exp_pos _).ne']) + have he (y : ι → ℝ) : exp (∑ i, g (y i))*productNormal d s y = + ∏ i, exp (g (y i))*gaussianPDFReal d s.toNNReal (y i) := by + rw [exp_sum,productNormal,Finset.prod_mul_distrib] + simp_rw [he] + rw [integral_fintype_prod_volume_eq_pow (fun x : ℝ => exp (g x)*gaussianPDFReal d s.toNNReal x)] + have hnorm : (∫ x, exp (g x)*gaussianPDFReal d s.toNNReal x) = + ∫ x, exp (g x) ∂gaussianReal d s.toNNReal := by + rw [integral_gaussianReal_eq_integral_smul (ne_of_gt (Real.toNNReal_pos.mpr hs))] + simp only [smul_eq_mul,mul_comm] + rw [hnorm,exp_nat_mul,exp_log hz] + +theorem gaussian_covered_tail_laplace {ι : Type*} [Fintype ι] [Nonempty ι] + {X : Type*} (C : Finset X) (f : X → ℝ →ᵇ ℝ) (d₀ s₀ : X → ℝ) + (hs₀ : ∀ x ∈ C, 0 < s₀ x) (d s ψ : (ι → ℝ) → ℝ) + (R r ε α ν R₁ : ℝ) (hα : 0 ≤ α) {E : Set (ι → ℝ)} (hE : MeasurableSet E) + (hpos : ∀ y ∈ E, 0 < s y) + (hmom : ∀ y ∈ E, ∑ i, (y i)^2 ≤ (Fintype.card ι:ℝ)*R) + (htail : ∀ y ∈ E, (Fintype.card ι:ℝ)*ν ≤ ∑ i, squareTail R₁ (y i)) + (hi : ∀ x ∈ C, Integrable (fun y => exp (f x y+α*squareTail R₁ y)) + (gaussianReal (d₀ x) (s₀ x).toNNReal)) + (hinc : ∀ x ∈ C, log (∫ y, exp (f x y+α*squareTail R₁ y) + ∂gaussianReal (d₀ x) (s₀ x).toNNReal) ≤ + log (∫ y, exp (f x y) ∂gaussianReal (d₀ x) (s₀ x).toNNReal)+ε) + (hcover : ∀ y ∈ E, ∃ x ∈ C, + ψ y-(∫ u, f x u ∂empiricalLaw y)+normalDensityError R (d y) (s y) (d₀ x) (s₀ x)+ + log (∫ u, exp (f x u) ∂gaussianReal (d₀ x) (s₀ x).toNNReal) < r) : + (∫⁻ y in E, ENNReal.ofReal (exp ((Fintype.card ι:ℝ)*ψ y)*productNormal (d y) (s y) y)) ≤ + ENNReal.ofReal ((C.card:ℝ)*exp ((Fintype.card ι:ℝ)*(r+ε-α*ν))) := by + classical + let F (x : X) (y : ι → ℝ) : ℝ := + exp ((Fintype.card ι:ℝ)*(r-α*ν)-(Fintype.card ι:ℝ)* + log (∫ u, exp (f x u) ∂gaussianReal (d₀ x) (s₀ x).toNNReal)) * + (exp (∑ i, (f x (y i)+α*squareTail R₁ (y i)))*productNormal (d₀ x) (s₀ x) y) + have hFi (x : X) (hx : x ∈ C) : Integrable (F x) := + (product_general_test_integrable (hs₀ x hx) (hi x hx)).const_mul _ + have hFnn (x : X) (y : ι → ℝ) : 0 ≤ F x y := + mul_nonneg (exp_pos _).le (mul_nonneg (exp_pos _).le (productNormal_nonneg _ _ _)) + have hnorm (x : X) (hx : x ∈ C) : + ∫ y, F x y ≤ exp ((Fintype.card ι:ℝ)*(r+ε-α*ν)) := by + dsimp [F] + rw [integral_const_mul,product_general_test_integral (hs₀ x hx) (hi x hx),← exp_add] + apply exp_le_exp.mpr + have h := mul_le_mul_of_nonneg_left (hinc x hx) (Nat.cast_nonneg (Fintype.card ι) : (0:ℝ) ≤ _) + nlinarith + have hdom (y : ι → ℝ) (hy : y ∈ E) : + exp ((Fintype.card ι:ℝ)*ψ y)*productNormal (d y) (s y) y ≤ ∑ x ∈ C, F x y := by + obtain ⟨x,hx,hc⟩ := hcover y hy + have hdens := normalLogDensity_sum_sub_le (hmom y hy) (d y) (s y) (d₀ x) (s₀ x) + change _ ≤ (Fintype.card ι:ℝ)*normalDensityError R (d y) (s y) (d₀ x) (s₀ x) at hdens + have hn : (0:ℝ) < Fintype.card ι := by exact_mod_cast (Fintype.card_pos (α := ι)) + have hc' := mul_lt_mul_of_pos_left hc hn + have hemp := card_mul_integral_empiricalLaw y (f x) + have ht := mul_le_mul_of_nonneg_left (htail y hy) hα + have hsum : (∑ i, (f x (y i)+α*squareTail R₁ (y i))) = + (∑ i, f x (y i))+α*∑ i, squareTail R₁ (y i) := by + rw [Finset.sum_add_distrib,Finset.mul_sum] + have hsmall : exp ((Fintype.card ι:ℝ)*ψ y)*productNormal (d y) (s y) y ≤ F x y := by + dsimp only [F] + rw [productNormal_eq_exp _ (hpos y hy),productNormal_eq_exp _ (hs₀ x hx), + hsum,← exp_add,← exp_add,← exp_add] + apply exp_le_exp.mpr + nlinarith + exact hsmall.trans (Finset.single_le_sum (fun a _ => hFnn a y) hx) + have hsumI : Integrable (fun y => ∑ x ∈ C, F x y) := integrable_finsetSum C hFi + calc + _ ≤ ∫⁻ y in E, ENNReal.ofReal (∑ x ∈ C, F x y) := lintegral_mono_ae + ((ae_restrict_mem hE).mono (fun y hy => ENNReal.ofReal_le_ofReal (hdom y hy))) + _ ≤ ∫⁻ y, ENNReal.ofReal (∑ x ∈ C, F x y) := lintegral_mono' Measure.restrict_le_self (fun _ => le_rfl) + _ = ENNReal.ofReal (∫ y, ∑ x ∈ C, F x y) := + (ofReal_integral_eq_lintegral_ofReal hsumI (ae_of_all _ (fun y => Finset.sum_nonneg (fun x _ => hFnn x y)))).symm + _ ≤ _ := by + apply ENNReal.ofReal_le_ofReal + rw [integral_finsetSum C hFi] + calc + _ ≤ ∑ _x ∈ C, exp ((Fintype.card ι:ℝ)*(r+ε-α*ν)) := Finset.sum_le_sum hnorm + _ = _ := by simp + +end SKGap + +end +end +end +end +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Gaussian/SquareTail2.lean b/lean/OAI/Probability/SKGap/Gaussian/SquareTail2.lean new file mode 100644 index 0000000000000000000000000000000000000000..bf6221f94e2353f06f44bf52143ac5fe257627af --- /dev/null +++ b/lean/OAI/Probability/SKGap/Gaussian/SquareTail2.lean @@ -0,0 +1,501 @@ +import Mathlib +import OAI.Probability.SKGap.Entropy.ExponentiallyRare + +namespace OAI + +section +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open scoped BigOperators +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open scoped BigOperators +open scoped BigOperators NNReal ENNReal +open MeasureTheory Metric Set +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators NNReal ENNReal Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Set +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators ENNReal NNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Matrix +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators ENNReal NNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal +open scoped BigOperators +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise NNReal ENNReal +open scoped BigOperators +open Filter Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Topology +namespace SKGapCutoff.Regression + +lemma gaussian_integrable_exp_quarter_sq : + Integrable (fun x : ℝ => Real.exp (x^2/4)) (gaussianReal 0 1) := by + rw [gaussianReal_of_var_ne_zero _ (by norm_num : (1:ℝ≥0) ≠ 0)] + rw [integrable_withDensity_iff_integrable_smul' + (measurable_gaussianPDF _ _) (ae_of_all _ (fun _ => gaussianPDF_lt_top))] + have h := (integrable_exp_neg_mul_sq (by norm_num : (0:ℝ)<1/4)).const_mul + ((Real.sqrt (2*Real.pi))⁻¹) + apply h.congr + filter_upwards [] with x + symm + simp only [toReal_gaussianPDF, + smul_eq_mul, gaussianPDFReal, NNReal.coe_one, sub_zero, mul_one, one_div] + rw [mul_assoc, ← Real.exp_add] + congr 2 + ring + +lemma iid_upper_deviation_of_log_mgf {Ω : Type*} [MeasurableSpace Ω] + {μ : Measure Ω} [IsProbabilityMeasure μ] {n : ℕ} (hn : 0 < n) + (X : Fin n → Ω → ℝ) (hXi : iIndepFun X μ) + (hXm : ∀ i, Measurable (X i)) (ν : Measure ℝ) + (hLaw : ∀ i, HasLaw (X i) ν μ) {t : ℝ} (ht : 0 < t) + (hi : Integrable (fun x : ℝ => Real.exp (t*x)) ν) (a : ℝ) : + μ {ω | a ≤ (∑ i, X i ω)/(n:ℝ)} ≤ + ENNReal.ofReal (Real.exp (-((t*a-cgf id ν t)*(n:ℝ)))) := by + have he (i : Fin n) : Integrable (fun ω => Real.exp (t*X i ω)) μ := + by + rw [← (hLaw i).map_eq] at hi + exact (integrable_map_measure (by fun_prop) (hLaw i).aemeasurable).mp hi + have hsum := hXi.integrable_exp_mul_sum hXm (s := Finset.univ) (fun i _ => he i) + have hc := measure_ge_le_exp_cgf (μ := μ) (X := ∑ i, X i) (a*n) ht.le hsum + have hcgf (i : Fin n) : cgf (X i) μ t = cgf id ν t := by + unfold cgf mgf + congr 1 + exact (hLaw i).integral_comp (f := fun x : ℝ => Real.exp (t*x)) (by fun_prop) + rw [hXi.cgf_sum hXm (fun i _ => he i)] at hc + simp only [hcgf, Finset.sum_const, Finset.card_univ, Fintype.card_fin, + nsmul_eq_mul] at hc + have hset : {ω | a*(n:ℝ) ≤ (∑ i, X i) ω} = + {ω | a ≤ (∑ i, X i ω)/(n:ℝ)} := by + ext ω + simp only [Finset.sum_apply, Set.mem_ofPred_eq, + le_div_iff₀ ((show (0:ℝ) positivity + +lemma squareTail_le (R x : ℝ) : squareTail R x ≤ x^2 := by + unfold squareTail + split_ifs <;> simp [sq_nonneg] + +lemma measurable_squareTail (R : ℝ) : Measurable (squareTail R) := by + unfold squareTail + exact Measurable.ite (measurableSet_lt measurable_const measurable_abs) + (by fun_prop) measurable_const + +lemma integrable_exp_squareTail {ν : Measure ℝ} + (hi : Integrable (fun x : ℝ => Real.exp (x^2/4)) ν) (R : ℝ) : + Integrable (fun x => Real.exp (squareTail R x/4)) ν := by + apply hi.mono' (((measurable_squareTail R).div_const 4).exp.aestronglyMeasurable) + filter_upwards [] with x + rw [Real.norm_eq_abs, abs_of_pos (Real.exp_pos _)] + exact Real.exp_le_exp.mpr (div_le_div_of_nonneg_right (squareTail_le R x) (by norm_num)) + +lemma tendsto_squareTail_mgf {ν : Measure ℝ} [IsProbabilityMeasure ν] + (hi : Integrable (fun x : ℝ => Real.exp (x^2/4)) ν) : + Tendsto (fun R : ℕ => ∫ x, Real.exp (squareTail R x/4) ∂ν) atTop (𝓝 1) := by + have ht : Tendsto (fun R : ℕ => ∫ x, Real.exp (squareTail R x/4) ∂ν) + atTop (𝓝 (∫ _x : ℝ, (1:ℝ) ∂ν)) := by + apply tendsto_integral_of_dominated_convergence (fun x : ℝ => Real.exp (x^2/4)) + · intro R + exact (((measurable_squareTail R).div_const 4).exp.aestronglyMeasurable) + · exact hi + · intro R + filter_upwards [] with x + rw [Real.norm_eq_abs, abs_of_pos (Real.exp_pos _)] + exact Real.exp_le_exp.mpr (div_le_div_of_nonneg_right (squareTail_le R x) (by norm_num)) + · filter_upwards [] with x + apply tendsto_const_nhds.congr' + filter_upwards [eventually_ge_atTop (⌈|x|⌉₊)] with R hR + have hx : |x| ≤ (R:ℝ) := (Nat.le_ceil _).trans (by exact_mod_cast hR) + simp [squareTail, not_lt.mpr hx] + simpa using ht + +def ExponentialSquareTails {H : ℕ → Type*} [∀ n, MeasurableSpace (H n)] + (ρ : ∀ n, Measure (H n)) (X : ∀ n, H n → Fin n → ℝ) : Prop := + ∀ ε : ℝ, 0 < ε → ∃ R : ℝ, 0 < R ∧ + ExponentiallyRare ρ (fun n => {h | ε ≤ (∑ i, squareTail R (X n h i))/(n:ℝ)}) + +theorem iid_exponential_squareTails {H : ℕ → Type*} [∀ n, MeasurableSpace (H n)] + (ρ : ∀ n, Measure (H n)) [∀ n, IsProbabilityMeasure (ρ n)] + (X : ∀ n, H n → Fin n → ℝ) + (hXm : ∀ n i, Measurable (fun h => X n h i)) + (hXi : ∀ n, iIndepFun (fun i h => X n h i) (ρ n)) + (ν : Measure ℝ) [IsProbabilityMeasure ν] + (hLaw : ∀ n i, HasLaw (fun h => X n h i) ν (ρ n)) + (hi : Integrable (fun x : ℝ => Real.exp (x^2/4)) ν) : + ExponentialSquareTails ρ X := by + intro ε hε + have ht : Tendsto (fun R : ℕ => Real.log (∫ x, Real.exp (squareTail R x/4) ∂ν)) + atTop (𝓝 0) := by + simpa only [Function.comp_def, Real.log_one] using (Real.continuousAt_log (by norm_num : (1:ℝ)≠0)).tendsto.comp + (tendsto_squareTail_mgf hi) + have he : ∀ᶠ R : ℕ in atTop, + Real.log (∫ x, Real.exp (squareTail R x/4) ∂ν) < ε/4 := + ht.eventually (gt_mem_nhds (by positivity)) + obtain ⟨R,hR,hm⟩ := (eventually_ge_atTop 1 |>.and he).exists + let m := Real.log (∫ x, Real.exp (squareTail R x/4) ∂ν) + have htm : Measurable (squareTail R) := measurable_squareTail R + have hl : HasLaw (squareTail R) (ν.map (squareTail R)) ν := ⟨htm.aemeasurable,rfl⟩ + have hcg : cgf id (ν.map (squareTail R)) (1/4) = m := by + unfold cgf mgf m + rw [integral_map htm.aemeasurable (by fun_prop)] + congr 2 + ext x + simp only [id_eq] + congr 1 + ring + have hint : Integrable (fun x : ℝ => Real.exp (1/4*x)) (ν.map (squareTail R)) := by + rw [integrable_map_measure (by fun_prop) htm.aemeasurable] + simpa only [Function.comp_def, one_div_mul_eq_div] using integrable_exp_squareTail hi R + refine ⟨R,by exact_mod_cast hR,1,ε/4-m,by norm_num,sub_pos.mpr hm,?_⟩ + filter_upwards [eventually_ge_atTop 1] with n hn + have hb := iid_upper_deviation_of_log_mgf hn (fun i h => squareTail R (X n h i)) + ((hXi n).comp (fun _ => squareTail R) (fun _ => htm)) + (fun i => htm.comp (hXm n i)) (ν.map (squareTail R)) + (fun i => hl.fun_comp (hLaw n i)) (by norm_num : (0:ℝ)<1/4) hint ε + rw [hcg] at hb + simpa only [one_mul, one_div_mul_eq_div, neg_mul] using hb + +theorem gaussian_exponential_squareTails : + ExponentialSquareTails (fun n => standardArrayLaw (Fin n)) (fun _ g => g) := by + exact iid_exponential_squareTails _ _ (fun _ _ => measurable_pi_apply _) + (fun _ => coordinates_independent) (gaussianReal 0 1) (fun _ _ => coordinate_hasLaw _) + gaussian_integrable_exp_quarter_sq + +lemma squareTail_perturbation (R x y : ℝ) (_hR : 0 ≤ R) : + squareTail (2*R) y ≤ 4*squareTail R x+4*(x-y)^2 := by + unfold squareTail + split_ifs with hy hx + · nlinarith [sq_nonneg (x+y)] + · have hx' := le_of_not_gt hx + have habs := abs_sub_abs_le_abs_sub y x + have hxy : R < |y-x| := by linarith + have hyb : |y| ≤ 2*|y-x| := by linarith + have hs := mul_self_le_mul_self (abs_nonneg y) hyb + nlinarith [sq_abs y, sq_abs (y-x)] + · positivity + · positivity + +theorem ExponentialSquareTails.l2_stability + {H : ℕ → Type*} [∀ n, MeasurableSpace (H n)] + {ρ : ∀ n, Measure (H n)} {X Y : ∀ n, H n → Fin n → ℝ} + (hX : ExponentialSquareTails ρ X) + (hXY : ExponentialConvergence ρ + (fun n h => (∑ i, (X n h i-Y n h i)^2)/(n:ℝ)) 0) : + ExponentialSquareTails ρ Y := by + intro ε hε + obtain ⟨R,hR,ht⟩ := hX (ε/8) (by positivity) + refine ⟨2*R,by positivity,?_⟩ + apply (ht.union (hXY (ε/8) (by positivity))).mono + filter_upwards [eventually_ge_atTop 1] with n hn + intro h hh + simp only [Set.mem_ofPred_eq] at hh + by_cases hx : ε/8 ≤ (∑ i, squareTail R (X n h i))/(n:ℝ) + · exact Or.inl hx + apply Or.inr + have hb : (∑ i, squareTail (2*R) (Y n h i))/(n:ℝ) ≤ + 4*((∑ i, squareTail R (X n h i))/(n:ℝ))+ + 4*((∑ i, (X n h i-Y n h i)^2)/(n:ℝ)) := by + calc + _ ≤ (∑ i, (4*squareTail R (X n h i)+4*(X n h i-Y n h i)^2))/(n:ℝ) := by + apply div_le_div_of_nonneg_right _ (Nat.cast_nonneg _) + exact Finset.sum_le_sum (fun i _ => squareTail_perturbation R _ _ hR.le) + _ = _ := by rw [Finset.sum_add_distrib, ← Finset.mul_sum, ← Finset.mul_sum]; ring + change ε/8 ≤ dist ((∑ i, (X n h i-Y n h i)^2)/(n:ℝ)) 0 + rw [Real.dist_eq, sub_zero, abs_of_nonneg (by positivity)] + have hx' := lt_of_not_ge hx + linarith + +lemma squareTail_add (R x y : ℝ) (_hR : 0 ≤ R) : + squareTail (2*R) (x+y) ≤ 4*(squareTail R x+squareTail R y) := by + unfold squareTail + split_ifs with hxy hx hy hy + · nlinarith [sq_nonneg (x-y)] + · have hy' := le_of_not_gt hy + have hxy' : |y| ≤ |x| := hy'.trans (le_of_lt hx) + have hs := mul_self_le_mul_self (abs_nonneg y) hxy' + nlinarith [sq_abs x, sq_abs y, sq_nonneg (x-y)] + · have hx' := le_of_not_gt hx + have hxy' : |x| ≤ |y| := hx'.trans (le_of_lt hy) + have hs := mul_self_le_mul_self (abs_nonneg x) hxy' + nlinarith [sq_abs x, sq_abs y, sq_nonneg (x-y)] + · have hx' := le_of_not_gt hx + have hy' := le_of_not_gt hy + have := abs_add_le x y + linarith + all_goals positivity + +lemma squareTail_antitone (x : ℝ) : Antitone (fun R => squareTail R x) := by + intro R S hRS + dsimp only [squareTail] + split_ifs <;> first | exact le_rfl | positivity | (exfalso; linarith) + +theorem ExponentialSquareTails.add + {H : ℕ → Type*} [∀ n, MeasurableSpace (H n)] + {ρ : ∀ n, Measure (H n)} {X Y : ∀ n, H n → Fin n → ℝ} + (hX : ExponentialSquareTails ρ X) (hY : ExponentialSquareTails ρ Y) : + ExponentialSquareTails ρ (fun n h i => X n h i+Y n h i) := by + intro ε hε + obtain ⟨R,hR,ht⟩ := hX (ε/8) (by positivity) + obtain ⟨S,hS,hs⟩ := hY (ε/8) (by positivity) + refine ⟨2*max R S,by positivity,?_⟩ + apply (ht.union hs).mono + filter_upwards [eventually_ge_atTop 1] with n hn + intro h hh + simp only [Set.mem_ofPred_eq] at hh + by_cases hx : ε/8 ≤ (∑ i, squareTail R (X n h i))/(n:ℝ) + · exact Or.inl hx + apply Or.inr + have hb : (∑ i, squareTail (2*max R S) (X n h i+Y n h i))/(n:ℝ) ≤ + 4*((∑ i, squareTail R (X n h i))/(n:ℝ))+ + 4*((∑ i, squareTail S (Y n h i))/(n:ℝ)) := by + calc + _ ≤ (∑ i, 4*(squareTail R (X n h i)+squareTail S (Y n h i)))/(n:ℝ) := by + apply div_le_div_of_nonneg_right _ (Nat.cast_nonneg _) + apply Finset.sum_le_sum + intro i _ + exact (squareTail_add _ _ _ (le_max_of_le_left hR.le)).trans + (mul_le_mul_of_nonneg_left (add_le_add + (squareTail_antitone _ (le_max_left _ _)) + (squareTail_antitone _ (le_max_right _ _))) (by norm_num)) + _ = _ := by simp_rw [mul_add]; rw [Finset.sum_add_distrib, ← Finset.mul_sum, + ← Finset.mul_sum]; ring + have hx' := lt_of_not_ge hx + change ε/8 ≤ (∑ i, squareTail S (Y n h i))/(n:ℝ) + linarith + +lemma squareTail_mul (R x a B : ℝ) (_hR : 0 ≤ R) (ha : |a| ≤ B) : + squareTail (B*R) (a*x) ≤ B^2*squareTail R x := by + have hB := (abs_nonneg a).trans ha + unfold squareTail + split_ifs with hax hx + · have hs := mul_self_le_mul_self (abs_nonneg a) ha + have hsq : a^2 ≤ B^2 := by nlinarith [sq_abs a] + nlinarith [mul_le_mul_of_nonneg_right hsq (sq_nonneg x)] + · have hx' := le_of_not_gt hx + have hab : |a*x| ≤ B*R := by rw [abs_mul]; exact mul_le_mul ha hx' (abs_nonneg x) hB + exact False.elim ((not_lt_of_ge hab) hax) + all_goals positivity + +lemma ExponentialSquareTails.bounded_mul + {H : ℕ → Type*} [∀ n, MeasurableSpace (H n)] + {ρ : ∀ n, Measure (H n)} {X : ∀ n, H n → Fin n → ℝ} + (hX : ExponentialSquareTails ρ X) + (a : ∀ n, H n → Fin n → ℝ) (B : ℝ) (hB : 0 ≤ B) + (ha : ∀ n h i, |a n h i| ≤ B) : + ExponentialSquareTails ρ (fun n h i => a n h i*X n h i) := by + intro ε hε + obtain ⟨R,hR,ht⟩ := hX (ε/(B+1)^2) (by positivity) + refine ⟨(B+1)*R,by positivity,ht.mono ?_⟩ + filter_upwards [] with n + intro h hh + change ε/(B+1)^2 ≤ (∑ i, squareTail R (X n h i))/(n:ℝ) + apply (div_le_iff₀ (by positivity : 0 < (B+1)^2)).mpr + have hb : (∑ i, squareTail ((B+1)*R) (a n h i*X n h i))/(n:ℝ) ≤ + (B+1)^2*((∑ i, squareTail R (X n h i))/(n:ℝ)) := by + calc + _ ≤ (∑ i, (B+1)^2*squareTail R (X n h i))/(n:ℝ) := by + apply div_le_div_of_nonneg_right _ (Nat.cast_nonneg _) + exact Finset.sum_le_sum (fun i _ => squareTail_mul R _ _ _ hR.le ((ha n h i).trans (by linarith))) + _ = _ := by rw [← Finset.mul_sum]; ring + exact (show ε ≤ _ from hh).trans (by simpa [mul_comm] using hb) + +noncomputable def clippedSquare (R x : ℝ) : ℝ := (min |x| R)^2 + +lemma clippedSquare_bounds (R x : ℝ) (hR : 0 ≤ R) : + 0 ≤ clippedSquare R x ∧ clippedSquare R x ≤ x^2 ∧ clippedSquare R x ≤ R^2 := by + have hm := le_min (abs_nonneg x) hR + have hx := mul_self_le_mul_self hm (min_le_left |x| R) + have hr := mul_self_le_mul_self hm (min_le_right |x| R) + dsimp [clippedSquare] + exact ⟨sq_nonneg _, by nlinarith [sq_abs x], by nlinarith⟩ + +lemma clippedSquare_error (R x : ℝ) (hR : 0 ≤ R) : + |x^2-clippedSquare R x| ≤ squareTail R x := by + rw [abs_of_nonneg (sub_nonneg.mpr (clippedSquare_bounds R x hR).2.1)] + by_cases hx : R < |x| + · simp only [squareTail, ite_eq_left hx] + linarith [(clippedSquare_bounds R x hR).1] + · simp [clippedSquare, squareTail, hx, min_eq_left (le_of_not_gt hx)] + +lemma clippedSquare_lipschitz (R : ℝ≥0) : + LipschitzWith (2*R) (clippedSquare R) := by + have ha : LipschitzWith 1 (fun x : ℝ => |x|) := by + apply LipschitzWith.of_dist_le_mul + intro x y + simpa only [Real.dist_eq, NNReal.coe_one, one_mul] using abs_abs_sub_abs_le_abs_sub x y + have h : LipschitzWith 1 (fun x : ℝ => min |x| (R:ℝ)) := ha.min_const _ + have hb (x : ℝ) : |min |x| (R:ℝ)| ≤ R := by + rw [abs_of_nonneg (le_min (abs_nonneg _) R.coe_nonneg)] + exact min_le_right _ _ + change LipschitzWith (2*R) (fun x : ℝ => (min |x| (R:ℝ))^2) + simpa only [one_mul, ← two_mul, pow_two] using bounded_product_lipschitz h h hb hb + +lemma integrable_clippedSquare (ν : Measure ℝ) [IsProbabilityMeasure ν] + (R : ℝ≥0) : Integrable (clippedSquare R) ν := by + apply integrable_bounded_lipschitz ν (clippedSquare_lipschitz R) ((R:ℝ)^2) + intro x + rw [abs_of_nonneg (clippedSquare_bounds R x R.coe_nonneg).1] + exact (clippedSquare_bounds R x R.coe_nonneg).2.2 + +lemma tendsto_integral_clippedSquare (ν : Measure ℝ) + (hi : Integrable (fun x : ℝ => x^2) ν) : + Tendsto (fun R : ℕ => ∫ x, clippedSquare R x ∂ν) atTop (𝓝 (∫ x, x^2 ∂ν)) := by + apply tendsto_integral_of_dominated_convergence (fun x : ℝ => x^2) + · intro R + exact (clippedSquare_lipschitz R).continuous.measurable.aestronglyMeasurable + · exact hi + · intro R + filter_upwards [] with x + rw [Real.norm_eq_abs, abs_of_nonneg (clippedSquare_bounds R x (Nat.cast_nonneg _)).1] + exact (clippedSquare_bounds R x (Nat.cast_nonneg _)).2.1 + · filter_upwards [] with x + apply tendsto_const_nhds.congr' + filter_upwards [eventually_ge_atTop (⌈|x|⌉₊)] with R hR + have hx : |x| ≤ (R:ℝ) := (Nat.le_ceil _).trans (by exact_mod_cast hR) + simp [clippedSquare, min_eq_left hx] + +theorem ExponentialEmpiricalConcentration.secondMoment + {H : ℕ → Type*} [∀ n, MeasurableSpace (H n)] + {ρ : ∀ n, Measure (H n)} {X : ∀ n, H n → Fin n → ℝ} + {ν : Measure ℝ} [IsProbabilityMeasure ν] + (hX : ExponentialEmpiricalConcentration ρ X ν) + (hT : ExponentialSquareTails ρ X) + (hi : Integrable (fun x : ℝ => x^2) ν) : + ExponentialConvergence ρ (fun n h => (∑ i, X n h i^2)/(n:ℝ)) + (∫ x, x^2 ∂ν) := by + intro ε hε + obtain ⟨R,hR,ht⟩ := hT (ε/3) (by positivity) + have hbias : ∀ᶠ k : ℕ in atTop, + |(∫ x, clippedSquare k x ∂ν) - ∫ x, x^2 ∂ν| < ε/3 := by + simpa only [Real.dist_eq] using (Metric.tendsto_nhds.mp + (tendsto_integral_clippedSquare ν hi)) (ε/3) (by positivity) + obtain ⟨k,hk,hbias⟩ := ((eventually_ge_atTop ⌈R⌉₊).and hbias).exists + have hRk : R ≤ (k:ℝ) := (Nat.le_ceil _).trans (by exact_mod_cast hk) + have hc : ExponentiallyRare ρ (fun n => {h | ε/3 ≤ + |(∑ i, clippedSquare k (X n h i))/(n:ℝ) - ∫ x, clippedSquare k x ∂ν|}) := by + apply hX (clippedSquare k) (2*(k:ℝ≥0)) (clippedSquare_lipschitz k) + ((k:ℝ)^2) + · intro x + rw [abs_of_nonneg (clippedSquare_bounds k x (Nat.cast_nonneg _)).1] + exact (clippedSquare_bounds k x (Nat.cast_nonneg _)).2.2 + · positivity + apply (ht.union hc).mono + filter_upwards [eventually_ge_atTop 1] with n hn + intro h hh + change ε ≤ |(∑ i, X n h i^2)/(n:ℝ) - ∫ x, x^2 ∂ν| at hh + by_cases htail : ε/3 ≤ (∑ i, squareTail R (X n h i))/(n:ℝ) + · exact Or.inl htail + apply Or.inr + by_contra hclip + have herror : |(∑ i, X n h i^2)/(n:ℝ) - + (∑ i, clippedSquare k (X n h i))/(n:ℝ)| ≤ + (∑ i, squareTail R (X n h i))/(n:ℝ) := by + rw [← sub_div, abs_div, abs_of_nonneg (Nat.cast_nonneg n : (0:ℝ) ≤ n), ← Finset.sum_sub_distrib] + apply div_le_div_of_nonneg_right _ (Nat.cast_nonneg _) + calc + _ ≤ ∑ i, |X n h i^2-clippedSquare k (X n h i)| := Finset.abs_sum_le_sum_abs _ _ + _ ≤ ∑ i, squareTail R (X n h i) := by + apply Finset.sum_le_sum + intro i _ + exact (clippedSquare_error k _ (Nat.cast_nonneg _)).trans + (squareTail_antitone _ hRk) + have htriangle := abs_add_three + ((∑ i, X n h i^2)/(n:ℝ)-(∑ i, clippedSquare k (X n h i))/(n:ℝ)) + ((∑ i, clippedSquare k (X n h i))/(n:ℝ)-∫ x, clippedSquare k x ∂ν) + ((∫ x, clippedSquare k x ∂ν)-∫ x, x^2 ∂ν) + rw [sub_add_sub_cancel, sub_add_sub_cancel] at htriangle + have ht' := lt_of_not_ge htail + simp only [Set.mem_ofPred_eq] at hclip + have hc' := lt_of_not_ge hclip + linarith + +lemma iIndepFun_comp_hasLaw {Ω A : Type*} [MeasurableSpace Ω] [MeasurableSpace A] + {ρ : Measure Ω} [IsProbabilityMeasure ρ] {μ : Measure A} + {g : Ω → A} (hg : HasLaw g μ ρ) + {ι : Type*} [Fintype ι] (X : ι → A → ℝ) (hX : ∀ i, AEMeasurable (X i) μ) + (hXi : iIndepFun X μ) : iIndepFun (fun i ω => X i (g ω)) ρ := by + have hl (i : ι) : HasLaw (X i) (μ.map (X i)) μ := ⟨hX i,rfl⟩ + exact (iIndepFun_iff_hasLaw_pi_pi (fun i => (hl i).fun_comp hg)).mpr + ((hXi.hasLaw_pi hl).fun_comp hg) + +lemma adaptive_innovation_error_exponential + {H : ℕ → Type*} [∀ n, MeasurableSpace (H n)] + (ρ : ∀ n, Measure (H n)) [∀ n, IsProbabilityMeasure (ρ n)] (r : ℕ) + (U : ∀ n, H n → Fin n → Fin r → ℝ) (q : ∀ n, H n → Fin n → ℝ) + (hUm : ∀ n, Measurable (U n)) (hqm : ∀ n, Measurable (q n)) + (hU : ∀ n h a, ∑ i, U n h i a^2 ≤ 1) (hq : ∀ n h, ∑ i, q n h i^2 ≤ 1) : + ExponentialConvergence (fun n => (ρ n).prod (standardArrayLaw (Fin n ⊕ Unit))) + (fun n z => (∑ i, (z.2 (Sum.inl i) - Real.sqrt n * + queryInnovation (residualProjection (U n z.1)) (q n z.1) z.2 i)^2)/(n:ℝ)) 0 := by + intro ε hε + refine ⟨2*((r:ℝ)+2),ε/(8*((r:ℝ)+2)^2),by positivity,by positivity,?_⟩ + filter_upwards [eventually_ge_atTop 1] with n hn + have he := adaptive_queryInnovation_iid_error_tail hn (ρ n) (U n) (q n) + (hUm n) (hqm n) (hU n) (hq n) (ε/2) (by positivity) + apply (measure_mono (show {z | ε ≤ dist + ((∑ i, (z.2 (Sum.inl i)-Real.sqrt n*queryInnovation + (residualProjection (U n z.1)) (q n z.1) z.2 i)^2)/(n:ℝ)) 0} ⊆ _ from ?_)).trans + (he.trans_eq ?_) + · intro z hz + simp only [Set.mem_ofPred_eq, Real.dist_eq, sub_zero, + abs_of_nonneg (by positivity : 0 ≤ (∑ i, (z.2 (Sum.inl i)-Real.sqrt n*queryInnovation + (residualProjection (U n z.1)) (q n z.1) z.2 i)^2)/(n:ℝ))] at hz + rw [le_div_iff₀ (by exact_mod_cast hn : (0:ℝ) Finset.sum_mul_sq_le_sq_mul_sq Finset.univ (A i) x) + _ = _ := by rw [← Finset.sum_mul] + exact (pow_le_pow_left₀ (norm_nonneg _) hN 2).trans_eq (Real.sq_sqrt hS) + +lemma matrix_fourth_trace_bound {n : ℕ} (A : Interaction n) (hA : ∀ i j, A i j = A j i) : + ‖Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) A‖^4 ≤ + ∑ i, ∑ j, ∑ k, ∑ l, A i j*A j k*A k l*A l i := by + have hstar : A.conjTranspose = A := by ext i j; simpa using hA j i + have he : ‖Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) (A*A)‖ = + ‖Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) A‖^2 := by + simpa only [Matrix.cstar_norm_def, hstar, pow_two] using Matrix.l2_opNorm_conjTranspose_mul_self A + have hh := matrix_opNorm_sq_le_frobenius (A*A) + rw [he, ← pow_mul] at hh + convert! hh using 1 + simp only [Matrix.mul_apply, pow_two, Finset.sum_mul_sum] + apply Finset.sum_congr rfl + intro i _ + rw [Finset.sum_comm (f := fun j k => ∑ l, A i j*A j k*A k l*A l i)] + apply Finset.sum_congr rfl + intro k _ + apply Finset.sum_congr rfl + intro j _ + apply Finset.sum_congr rfl + intro l _ + rw [hA k l, hA l i] + ring + +lemma gaussian_sq_integral (v : ℝ≥0) : ∫ x : ℝ, x^2 ∂gaussianReal 0 v = v := by + have h := variance_fun_id_gaussianReal (μ := 0) (v := v) + rw [variance_eq_integral measurable_id'.aemeasurable] at h + simpa only [integral_id_gaussianReal, sub_zero] using h + +lemma gaussian_squared_centered_integral (v : ℝ≥0) : + ∫ x : ℝ, (x^2-(v:ℝ)) ∂gaussianReal 0 v = 0 := by + have h2 : Integrable (fun x : ℝ => x^2) (gaussianReal 0 v) := by + have h : MemLp (fun x : ℝ => x*x) 1 (gaussianReal 0 v) := + (memLp_id_gaussianReal' (μ := 0) (v := v) 2 (by norm_num)).mul (memLp_id_gaussianReal' 2 (by norm_num)) + simpa only [pow_two] using h.integrable (le_refl 1) + rw [integral_sub h2 (integrable_const _), gaussian_sq_integral] + simp + +lemma gaussian_squared_centered_memLp_four (v : ℝ≥0) : + MemLp (fun x : ℝ => x^2-(v:ℝ)) 4 (gaussianReal 0 v) := by + have h : MemLp (fun x : ℝ => x*x) 4 (gaussianReal 0 v) := + (memLp_id_gaussianReal' (μ := 0) (v := v) 8 (by norm_num)).mul + (memLp_id_gaussianReal' 8 (by norm_num)) + convert! h.sub (memLp_const (v:ℝ)) using 1; (ext x; simp only [pow_two, Pi.sub_apply]) + +noncomputable def squaredGaussianFourth : ℝ := ∫ x : ℝ, (x^2-1)^4 ∂gaussianReal 0 1 + +lemma squaredGaussianFourth_nonneg : 0 ≤ squaredGaussianFourth := by + apply integral_nonneg + intro x + positivity + +lemma gaussian_squared_fourth_integral (v : ℝ≥0) : + ∫ x : ℝ, (x^2-(v:ℝ))^4 ∂gaussianReal 0 v = (v:ℝ)^4*squaredGaussianFourth := by + have hm : (gaussianReal 0 1).map (fun x : ℝ => Real.sqrt v*x) = gaussianReal 0 v := by + rw [gaussianReal_map_const_mul] + congr 1 + · simp + · ext; simp only [NNReal.coe_mk, mul_one, + Real.sq_sqrt v.coe_nonneg] + rw [← hm, integral_map (by fun_prop) (by fun_prop)] + have he (x : ℝ) : ((Real.sqrt v*x)^2-(v:ℝ))^4 = (v:ℝ)^4*(x^2-1)^4 := by + rw [mul_pow, Real.sq_sqrt v.coe_nonneg] + ring + simp_rw [he] + rw [integral_const_mul] + rfl + +def centeredSquareCoordinate {ι : Type*} (v : ℝ≥0) (i : ι) (g : ι → ℝ) : ℝ := g i^2-(v:ℝ) + +def centeredSquared {n : ℕ} (v : ℝ≥0) (g : GaussianCoordinates n) : Interaction n := + fun i j => if i = j then 0 else centeredSquareCoordinate v (min i j, max i j) g + +lemma centeredSquared_diag {n : ℕ} (v : ℝ≥0) (g : GaussianCoordinates n) (i : Fin n) : + centeredSquared v g i i = 0 := by simp [centeredSquared] + +lemma centeredSquared_symm {n : ℕ} (v : ℝ≥0) (g : GaussianCoordinates n) (i j : Fin n) : + centeredSquared v g i j = centeredSquared v g j i := by + simp only [centeredSquared, eq_comm, min_comm i j, max_comm i j] + +lemma centeredSquareCoordinate_memLp {ι : Type*} [Fintype ι] (v : ℝ≥0) (i : ι) : + MemLp (centeredSquareCoordinate v i) 4 (Measure.pi (fun _ : ι => gaussianReal 0 v)) := + (gaussian_squared_centered_memLp_four v).comp_measurePreserving + (measurePreserving_eval (fun _ : ι => gaussianReal 0 v) i) + +lemma centeredSquareCoordinate_mean {ι : Type*} [Fintype ι] (v : ℝ≥0) (i : ι) : + ∫ g, centeredSquareCoordinate v i g ∂Measure.pi (fun _ : ι => gaussianReal 0 v) = 0 := by + change ∫ g, (g i^2-(v:ℝ)) ∂Measure.pi (fun _ : ι => gaussianReal 0 v) = 0 + convert! ((measurePreserving_eval (fun _ : ι => gaussianReal 0 v) i).hasLaw.integral_comp + (show AEStronglyMeasurable (fun x : ℝ => x^2-(v:ℝ)) (gaussianReal 0 v) from by fun_prop)).trans + (gaussian_squared_centered_integral v) using 1 + +lemma centeredSquareCoordinate_fourth {ι : Type*} [Fintype ι] (v : ℝ≥0) (i : ι) : + ∫ g, (centeredSquareCoordinate v i g)^4 ∂Measure.pi (fun _ : ι => gaussianReal 0 v) = + (v:ℝ)^4*squaredGaussianFourth := by + change ∫ g, (g i^2-(v:ℝ))^4 ∂Measure.pi (fun _ : ι => gaussianReal 0 v) = _ + convert! ((measurePreserving_eval (fun _ : ι => gaussianReal 0 v) i).hasLaw.integral_comp + (show AEStronglyMeasurable (fun x : ℝ => (x^2-(v:ℝ))^4) (gaussianReal 0 v) from by fun_prop)).trans + (gaussian_squared_fourth_integral v) using 1 + +lemma centeredSquareCoordinate_independent {ι : Type*} [Fintype ι] (v : ℝ≥0) : + iIndepFun (centeredSquareCoordinate (ι := ι) v) (Measure.pi (fun _ : ι => gaussianReal 0 v)) := by + exact (iIndepFun_pi (fun _ : ι => measurable_id.aemeasurable)).comp + (fun _ (x : ℝ) => x^2-(v:ℝ)) (fun _ => by fun_prop) + +lemma centeredSquared_memLp {n : ℕ} (v : ℝ≥0) (i j : Fin n) : + MemLp (fun g : GaussianCoordinates n => centeredSquared v g i j) 4 + (Measure.pi (fun _ : Fin n × Fin n => gaussianReal 0 v)) := by + by_cases h : i = j + · subst j; simpa only [centeredSquared_diag] using (memLp_const (0:ℝ)) + · simpa only [centeredSquared, h, ite_false] using + centeredSquareCoordinate_memLp v (min i j, max i j) + +lemma centeredSquared_fourth_integrable {n : ℕ} (v : ℝ≥0) (i j : Fin n) : + Integrable (fun g : GaussianCoordinates n => centeredSquared v g i j^4) + (Measure.pi (fun _ : Fin n × Fin n => gaussianReal 0 v)) := by + simpa only [Real.norm_eq_abs, (show Even (4:ℕ) by decide).pow_abs] using + (centeredSquared_memLp v i j).integrable_norm_pow (by decide : (4:ℕ) ≠ 0) + +lemma centeredSquared_fourth_le {n : ℕ} (v : ℝ≥0) (i j : Fin n) : + ∫ g : GaussianCoordinates n, centeredSquared v g i j^4 + ∂(Measure.pi (fun _ : Fin n × Fin n => gaussianReal 0 v)) ≤ + (v:ℝ)^4*squaredGaussianFourth := by + by_cases h : i = j + · subst j; simp only [centeredSquared_diag, zero_pow (by decide : (4:ℕ) ≠ 0), integral_zero] + exact mul_nonneg (by positivity) squaredGaussianFourth_nonneg + · simp only [centeredSquared, h, ite_false, centeredSquareCoordinate_fourth, le_refl] + +lemma centeredSquared_cyclic_integrable {n : ℕ} (v : ℝ≥0) (i j k l : Fin n) : + Integrable (fun g : GaussianCoordinates n => centeredSquared v g i j*centeredSquared v g j k* + centeredSquared v g k l*centeredSquared v g l i) + (Measure.pi (fun _ : Fin n × Fin n => gaussianReal 0 v)) := by + have hab : MemLp (fun g : GaussianCoordinates n => centeredSquared v g i j*centeredSquared v g j k) 2 + (Measure.pi (fun _ : Fin n × Fin n => gaussianReal 0 v)) := + (centeredSquared_memLp v i j).mul (centeredSquared_memLp v j k) + have hcd : MemLp (fun g : GaussianCoordinates n => centeredSquared v g k l*centeredSquared v g l i) 2 + (Measure.pi (fun _ : Fin n × Fin n => gaussianReal 0 v)) := + (centeredSquared_memLp v k l).mul (centeredSquared_memLp v l i) + convert! hab.integrable_mul hcd using 1; (ext g; simp only [Pi.mul_apply]; ring) + +lemma minmax_eq_iff {α : Type*} [LinearOrder α] (a b c d : α) : + (min a b, max a b) = (min c d, max c d) ↔ + (a=c ∧ b=d) ∨ (a=d ∧ b=c) := by + constructor + · intro h + rcases le_total a b with hab | hab + · rcases le_total c d with hcd | hcd + · left; simpa only [min_eq_left hab, max_eq_right hab, min_eq_left hcd, max_eq_right hcd, + Prod.mk.injEq] using h + · right; simpa only [min_eq_left hab, max_eq_right hab, min_eq_right hcd, max_eq_left hcd, + Prod.mk.injEq] using h + · rcases le_total c d with hcd | hcd + · right + have hh : b=c ∧ a=d := by + simpa only [min_eq_right hab, max_eq_left hab, + min_eq_left hcd, max_eq_right hcd, Prod.mk.injEq] using h + exact ⟨hh.2, hh.1⟩ + · left + have hh : b=d ∧ a=c := by + simpa only [min_eq_right hab, max_eq_left hab, + min_eq_right hcd, max_eq_left hcd, Prod.mk.injEq] using h + exact ⟨hh.2, hh.1⟩ + · rintro (⟨rfl,rfl⟩ | ⟨rfl,rfl⟩) + · rfl + · simp only [min_comm, max_comm] + +lemma integral_sq_mul_sq_le_fourth {Ω : Type*} [MeasurableSpace Ω] {μ : Measure Ω} + (f g : Ω → ℝ) (hint : Integrable (fun x => f x^2*g x^2) μ) + (hf : Integrable (fun x => f x^4) μ) (hg : Integrable (fun x => g x^4) μ) : + (∫ x, f x^2*g x^2 ∂μ) ≤ ((∫ x, f x^4 ∂μ)+(∫ x, g x^4 ∂μ))/2 := by + calc + _ ≤ ∫ x, (f x^4+g x^4)/2 ∂μ := by + apply integral_mono hint ((hf.add hg).div_const _) + intro x + change f x^2*g x^2 ≤ (f x^4+g x^4)/2 + nlinarith [sq_nonneg (f x^2-g x^2)] + _ = _ := by rw [integral_div, integral_add hf hg] + +lemma centeredSquared_cyclic_zero {n : ℕ} (v : ℝ≥0) (i j k l : Fin n) + (hik : i ≠ k) (hjl : j ≠ l) : + ∫ g : GaussianCoordinates n, centeredSquared v g i j*centeredSquared v g j k* + centeredSquared v g k l*centeredSquared v g l i + ∂(Measure.pi (fun _ : Fin n × Fin n => gaussianReal 0 v)) = 0 := by + by_cases hij : i = j + · subst j; simp [centeredSquared_diag] + by_cases hjk : j = k + · subst k; simp [centeredSquared_diag] + by_cases hkl : k = l + · subst l; simp [centeredSquared_diag] + by_cases hli : l = i + · subst l; simp [centeredSquared_diag] + simp only [centeredSquared, hij, hjk, hkl, hli, ite_false] + let e₁ := (min i j, max i j) + let e₂ := (min j k, max j k) + let e₃ := (min k l, max k l) + let e₄ := (min l i, max l i) + have h12 : e₁ ≠ e₂ := by simpa only [e₁, e₂, ne_eq, minmax_eq_iff] using + (show ¬ ((i=j ∧ j=k) ∨ (i=k ∧ j=j)) by tauto) + have h13 : e₁ ≠ e₃ := by simpa only [e₁, e₃, ne_eq, minmax_eq_iff] using + (show ¬ ((i=k ∧ j=l) ∨ (i=l ∧ j=k)) by tauto) + have h14 : e₁ ≠ e₄ := by simpa only [e₁, e₄, ne_eq, minmax_eq_iff] using + (show ¬ ((i=l ∧ j=i) ∨ (i=i ∧ j=l)) by tauto) + have h23 : e₂ ≠ e₃ := by simpa only [e₂, e₃, ne_eq, minmax_eq_iff] using + (show ¬ ((j=k ∧ k=l) ∨ (j=l ∧ k=k)) by tauto) + have h24 : e₂ ≠ e₄ := by simpa only [e₂, e₄, ne_eq, minmax_eq_iff] using + (show ¬ ((j=l ∧ k=i) ∨ (j=i ∧ k=l)) by tauto) + have hm (e : Fin n × Fin n) : Measurable (centeredSquareCoordinate v e) := by + unfold centeredSquareCoordinate; fun_prop + have hab := (centeredSquareCoordinate_independent v).indepFun h12 + have hprod := (centeredSquareCoordinate_independent v).indepFun_mul_mul hm e₁ e₂ e₃ e₄ h13 h14 h23 h24 + have he := hprod.integral_fun_mul_eq_mul_integral + ((hm e₁).mul (hm e₂)).aestronglyMeasurable ((hm e₃).mul (hm e₄)).aestronglyMeasurable + simp only [Pi.mul_apply] at he + rw [hab.integral_fun_mul_eq_mul_integral (hm e₁).aestronglyMeasurable (hm e₂).aestronglyMeasurable, + centeredSquareCoordinate_mean, zero_mul, zero_mul] at he + simpa only [e₁, e₂, e₃, e₄, mul_assoc] using he + +lemma centeredSquared_cyclic_le {n : ℕ} (v : ℝ≥0) (i j k l : Fin n) : + ∫ g : GaussianCoordinates n, centeredSquared v g i j*centeredSquared v g j k* + centeredSquared v g k l*centeredSquared v g l i + ∂(Measure.pi (fun _ : Fin n × Fin n => gaussianReal 0 v)) ≤ + (if i=k then (v:ℝ)^4*squaredGaussianFourth else 0) + + (if j=l then (v:ℝ)^4*squaredGaussianFourth else 0) := by + have hM : 0 ≤ (v:ℝ)^4*squaredGaussianFourth := mul_nonneg (by positivity) squaredGaussianFourth_nonneg + have hp := centeredSquared_cyclic_integrable v i j k l + by_cases hik : i = k + · subst k + have he (g : GaussianCoordinates n) : centeredSquared v g i j*centeredSquared v g j i* + centeredSquared v g i l*centeredSquared v g l i = + centeredSquared v g i j^2*centeredSquared v g i l^2 := by + rw [centeredSquared_symm v g j i, centeredSquared_symm v g l i]; ring + simp_rw [he] at hp ⊢ + have hh := integral_sq_mul_sq_le_fourth (fun g => centeredSquared v g i j) + (fun g => centeredSquared v g i l) hp (centeredSquared_fourth_integrable v i j) + (centeredSquared_fourth_integrable v i l) + have hb := centeredSquared_fourth_le v i j + have hc := centeredSquared_fourth_le v i l + simp only [ite_true] + have hright : 0 ≤ (if j=l then (v:ℝ)^4*squaredGaussianFourth else 0) := by + split_ifs <;> linarith + linarith + · by_cases hjl : j = l + · subst l + have he (g : GaussianCoordinates n) : centeredSquared v g i j*centeredSquared v g j k* + centeredSquared v g k j*centeredSquared v g j i = + centeredSquared v g i j^2*centeredSquared v g k j^2 := by + rw [centeredSquared_symm v g j i, centeredSquared_symm v g j k]; ring + simp_rw [he] at hp ⊢ + have hh := integral_sq_mul_sq_le_fourth (fun g => centeredSquared v g i j) + (fun g => centeredSquared v g k j) hp (centeredSquared_fourth_integrable v i j) + (centeredSquared_fourth_integrable v k j) + have hb := centeredSquared_fourth_le v i j + have hc := centeredSquared_fourth_le v k j + simp only [hik, ite_false, ite_true, zero_add] + linarith + · rw [centeredSquared_cyclic_zero v i j k l hik hjl] + simp only [hik, hjl, ite_false, add_zero, le_refl] + +noncomputable def squaredFourthTrace {n : ℕ} (v : ℝ≥0) (g : GaussianCoordinates n) : ℝ := + ∑ i, ∑ j, ∑ k, ∑ l, centeredSquared v g i j*centeredSquared v g j k* + centeredSquared v g k l*centeredSquared v g l i + +lemma squaredFourthTrace_integrable {n : ℕ} (v : ℝ≥0) : + Integrable (squaredFourthTrace (n := n) v) + (Measure.pi (fun _ : Fin n × Fin n => gaussianReal 0 v)) := by + exact integrable_finsetSum _ (fun i _ => integrable_finsetSum _ (fun j _ => + integrable_finsetSum _ (fun k _ => integrable_finsetSum _ (fun l _ => + centeredSquared_cyclic_integrable v i j k l)))) + +lemma squaredFourthTrace_nonneg {n : ℕ} (v : ℝ≥0) (g : GaussianCoordinates n) : + 0 ≤ squaredFourthTrace v g := + (pow_nonneg (norm_nonneg _) 4).trans (matrix_fourth_trace_bound _ (centeredSquared_symm v g)) + +lemma squaredFourthTrace_integral_le {n : ℕ} (v : ℝ≥0) : + ∫ g : GaussianCoordinates n, squaredFourthTrace v g + ∂(Measure.pi (fun _ : Fin n × Fin n => gaussianReal 0 v)) ≤ + 2*(n:ℝ)^3*(v:ℝ)^4*squaredGaussianFourth := by + have hl (i j k : Fin n) := integrable_finsetSum Finset.univ (fun l _ => + centeredSquared_cyclic_integrable v i j k l) + have hk (i j : Fin n) := integrable_finsetSum Finset.univ (fun k _ => hl i j k) + have hj (i : Fin n) := integrable_finsetSum Finset.univ (fun j _ => hk i j) + unfold squaredFourthTrace + rw [integral_finsetSum _ (fun i _ => hj i)] + simp_rw [integral_finsetSum _ (fun j _ => hk _ j), integral_finsetSum _ (fun k _ => hl _ _ k), + integral_finsetSum _ (fun l _ => centeredSquared_cyclic_integrable v _ _ _ l)] + calc + _ ≤ ∑ i : Fin n, ∑ j : Fin n, ∑ k : Fin n, ∑ l : Fin n, + ((if i=k then (v:ℝ)^4*squaredGaussianFourth else 0) + + (if j=l then (v:ℝ)^4*squaredGaussianFourth else 0)) := by + exact Finset.sum_le_sum (fun i _ => Finset.sum_le_sum (fun j _ => + Finset.sum_le_sum (fun k _ => Finset.sum_le_sum (fun l _ => centeredSquared_cyclic_le v i j k l)))) + _ = _ := by + simp only [Finset.sum_add_distrib, Finset.sum_const, Finset.card_univ, Fintype.card_fin, + nsmul_eq_mul, ← Finset.mul_sum, Finset.mem_univ, ite_true, + Finset.sum_ite_eq] + ring + +lemma centeredSquared_opNorm_tail {n : ℕ} (v : ℝ≥0) (δ : ℝ) (hδ : 0 < δ) : + (Measure.pi (fun _ : Fin n × Fin n => gaussianReal 0 v)) + {g | δ < ‖Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) (centeredSquared v g)‖} ≤ + ENNReal.ofReal (2*(n:ℝ)^3*(v:ℝ)^4*squaredGaussianFourth/δ^4) := by + refine (measure_mono (show {g | δ < ‖Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) (centeredSquared v g)‖} ⊆ + {g | δ^4 ≤ squaredFourthTrace v g} from ?_)).trans ?_ + · intro g hg + exact (pow_le_pow_left₀ hδ.le hg.le 4).trans + (matrix_fourth_trace_bound _ (centeredSquared_symm v g)) + · exact (probability_markov_real _ _ (squaredFourthTrace_integrable v) + (squaredFourthTrace_nonneg v) (δ^4) (by positivity)).trans + (ENNReal.ofReal_le_ofReal (div_le_div_of_nonneg_right (squaredFourthTrace_integral_le v) (by positivity))) + +lemma centeredSquared_disorder_tail (β : ℝ) {n : ℕ} (hn : 0 < n) (δ : ℝ) (hδ : 0 < δ) : + disorderLaw β n {g | δ < ‖Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) + (centeredSquared (Real.toNNReal (β^2/(n:ℝ))) g)‖} ≤ + ENNReal.ofReal ((2*β^8*squaredGaussianFourth/δ^4)/(n:ℝ)) := by + convert! centeredSquared_opNorm_tail (n := n) (Real.toNNReal (β^2/(n:ℝ))) δ hδ using 2 + rw [Real.coe_toNNReal _ (by positivity)] + have hn0 : (n:ℝ) ≠ 0 := by exact_mod_cast hn.ne' + field_simp + +lemma centeredSquared_disorder_tendsto (β : ℝ) (δ : ℝ) (hδ : 0 < δ) : + Tendsto (fun n => disorderLaw β n {g | δ < ‖Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) + (centeredSquared (Real.toNNReal (β^2/(n:ℝ))) g)‖}) atTop (nhds 0) := by + have ht : Tendsto (fun n : ℕ => (2*β^8*squaredGaussianFourth/δ^4)/(n:ℝ)) atTop (nhds 0) := + tendsto_const_nhds.div_atTop tendsto_natCast_atTop_atTop + have hh := ENNReal.continuous_ofReal.continuousAt.tendsto.comp ht + simp only [ENNReal.ofReal_zero] at hh + exact tendsto_of_tendsto_of_tendsto_of_le_of_le' tendsto_const_nhds hh + (Eventually.of_forall (fun _ => bot_le)) + ((eventually_gt_atTop 0).mono (fun n hn => centeredSquared_disorder_tail β hn δ hδ)) + +noncomputable def sampledSquaredDeviation {n : ℕ} (β : ℝ) (g : GaussianCoordinates n) : Interaction n := + fun i j => (sampledInteraction g i j)^2-β^2/(n:ℝ) + +lemma sampledSquaredDeviation_eq {n : ℕ} (β : ℝ) (g : GaussianCoordinates n) : + sampledSquaredDeviation β g = centeredSquared (Real.toNNReal (β^2/(n:ℝ))) g - + (β^2/(n:ℝ)) • (1 : Interaction n) := by + have hv : 0 ≤ β^2/(n:ℝ) := by positivity + ext i j + by_cases h : i=j + · subst j + simp only [sampledSquaredDeviation, sampledInteraction, centeredSquared, ite_true, zero_pow (by decide : (2:ℕ) ≠ 0), + Matrix.sub_apply, Matrix.smul_apply, Matrix.one_apply_eq, smul_eq_mul, mul_one] + · simp only [sampledSquaredDeviation, sampledInteraction, centeredSquared, h, ite_false, + Matrix.sub_apply, Matrix.smul_apply, Matrix.one_apply_ne h, smul_eq_mul, mul_zero, + sub_zero, centeredSquareCoordinate, Real.coe_toNNReal _ hv] + +lemma sampledSquaredDeviation_norm_le {n : ℕ} (β : ℝ) (g : GaussianCoordinates n) : + ‖Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) (sampledSquaredDeviation β g)‖ ≤ + ‖Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) (centeredSquared (Real.toNNReal (β^2/(n:ℝ))) g)‖ + β^2/(n:ℝ) := by + have hv : 0 ≤ β^2/(n:ℝ) := by positivity + rw [sampledSquaredDeviation_eq, map_sub, map_smul] + have hone : ‖Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) (1 : Interaction n)‖ ≤ 1 := by + rw [map_one] + change ‖ContinuousLinearMap.id ℝ (EuclideanSpace ℝ (Fin n))‖ ≤ 1 + exact ContinuousLinearMap.norm_id_le + calc + _ ≤ _ + ‖(β^2/(n:ℝ)) • Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) (1 : Interaction n)‖ := norm_sub_le _ _ + _ ≤ _ := by + rw [norm_smul, Real.norm_eq_abs, abs_of_nonneg hv] + exact add_le_add le_rfl (by simpa only [mul_one] using mul_le_mul_of_nonneg_left hone hv) + +lemma sampledSquaredDeviation_tendsto (β : ℝ) (δ : ℝ) (hδ : 0 < δ) : + Tendsto (fun n => disorderLaw β n {g | δ < ‖Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) + (sampledSquaredDeviation β g)‖}) atTop (nhds 0) := by + have hv : Tendsto (fun n : ℕ => β^2/(n:ℝ)) atTop (nhds 0) := + tendsto_const_nhds.div_atTop tendsto_natCast_atTop_atTop + have he : ∀ᶠ n : ℕ in atTop, β^2/(n:ℝ) < δ/2 := hv.eventually (gt_mem_nhds (by positivity)) + apply tendsto_of_tendsto_of_tendsto_of_le_of_le' tendsto_const_nhds + (centeredSquared_disorder_tendsto β (δ/2) (by positivity)) + (Eventually.of_forall (fun _ => bot_le)) + filter_upwards [he] with n hn + apply measure_mono + intro g hg + have hh := sampledSquaredDeviation_norm_le β g + change δ/2 < _ + change δ < ‖Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) (sampledSquaredDeviation β g)‖ at hg + linarith + +end SKGapCutoff.RandomMatrix + +open scoped BigOperators Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Set + +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Gaussian/StandardGaussianProduct.lean b/lean/OAI/Probability/SKGap/Gaussian/StandardGaussianProduct.lean new file mode 100644 index 0000000000000000000000000000000000000000..024798f0b80306da9a7863278ead789bc5428f9f --- /dev/null +++ b/lean/OAI/Probability/SKGap/Gaussian/StandardGaussianProduct.lean @@ -0,0 +1,208 @@ +import Mathlib +import OAI.Probability.SKGap.Model + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory InformationTheory Real Set +open scoped NNReal ENNReal +namespace SKGap + +theorem hasDerivAt_gaussianPDFReal (d : ℝ) {s : ℝ≥0} (hs : s ≠ 0) (y : ℝ) : + HasDerivAt (gaussianPDFReal d s) + (-(y - d) / (s : ℝ) * gaussianPDFReal d s y) y := by + have hsp : 0 < (s : ℝ) := NNReal.coe_pos.mpr (pos_iff_ne_zero.mpr hs) + unfold gaussianPDFReal + convert! (((((hasDerivAt_id y).sub_const d).pow 2).neg.div_const + (2 * (s : ℝ))).exp).const_mul (1 / sqrt (2 * π * (s : ℝ))) using 1 + · ext x + simp only [one_div, Pi.neg_apply, Pi.pow_apply, id_eq] + · simp only [Pi.neg_apply, Pi.pow_apply, id_eq] + norm_num + ring + +theorem integrable_gaussian_iff {d : ℝ} {s : ℝ≥0} (hs : s ≠ 0) {f : ℝ → ℝ} : + Integrable f (gaussianReal d s) ↔ Integrable (fun y => gaussianPDFReal d s y * f y) := by + rw [gaussianReal_of_var_ne_zero d hs, + integrable_withDensity_iff_integrable_smul' (measurable_gaussianPDF d s) + (ae_of_all _ (fun _ => gaussianPDF_lt_top))] + simp only [toReal_gaussianPDF, smul_eq_mul] + +theorem gaussian_integration_by_parts {d : ℝ} {s : ℝ≥0} (hs : s ≠ 0) + {f f' : ℝ → ℝ} (hd : ∀ y, HasDerivAt f (f' y) y) + (hf : Integrable f (gaussianReal d s)) (hf' : Integrable f' (gaussianReal d s)) + (hyf : Integrable (fun y => (y - d) * f y) (gaussianReal d s)) : + (∫ y, (y - d) * f y ∂gaussianReal d s) = + (s : ℝ) * (∫ y, f' y ∂gaussianReal d s) := by + have hsp : 0 < (s : ℝ) := NNReal.coe_pos.mpr (pos_iff_ne_zero.mpr hs) + have hfg := (integrable_gaussian_iff hs).mp hf + have hf'g := (integrable_gaussian_iff hs).mp hf' + have hyfg := (integrable_gaussian_iff hs).mp hyf + have hder (y : ℝ) : HasDerivAt (fun y => gaussianPDFReal d s y * f y) + (gaussianPDFReal d s y * f' y - + (gaussianPDFReal d s y * ((y - d) * f y)) / (s : ℝ)) y := by + convert! (hasDerivAt_gaussianPDFReal d hs y).mul (hd y) using 1 + ring + have hii : Integrable (fun y => gaussianPDFReal d s y * f' y - + (gaussianPDFReal d s y * ((y - d) * f y)) / (s : ℝ)) := + hf'g.sub (hyfg.div_const _) + have hz := integral_eq_zero_of_hasDerivAt_of_integrable hder hii hfg + rw [integral_sub hf'g (hyfg.div_const (s : ℝ)), integral_div] at hz + rw [integral_gaussianReal_eq_integral_smul hs, + integral_gaussianReal_eq_integral_smul hs] + simp only [smul_eq_mul] + have he : (∫ y, gaussianPDFReal d s y * ((y - d) * f y)) / (s : ℝ) = + ∫ y, gaussianPDFReal d s y * f' y := by linarith + have hm := (div_eq_iff hsp.ne').mp he + nlinarith only [hm] + +def standardGaussianProduct (n : ℕ) : Measure (Fin n → ℝ) := + Measure.pi (fun _ => gaussianReal 0 1) + +instance (n : ℕ) : IsProbabilityMeasure (standardGaussianProduct n) := by + unfold standardGaussianProduct + infer_instance + +theorem continuous_insertNth {n : ℕ} (i : Fin (n + 1)) (u : Fin n → ℝ) : + Continuous (fun z : ℝ => i.insertNth (α := fun _ => ℝ) z u) := by + apply continuous_pi + refine i.forall_iff_succAbove.mpr ⟨?_, ?_⟩ + · simp only [Fin.insertNth_apply_same] + convert! (continuous_id : Continuous (fun x : ℝ => x)) using 1 + · intro k + simpa only [Fin.insertNth_apply_succAbove] using + (continuous_const : Continuous (fun _ : ℝ => u k)) + +theorem gaussianProduct_coordinate_IBP {n : ℕ} (i : Fin (n + 1)) + {f df : (Fin (n + 1) → ℝ) → ℝ} {C D : ℝ} + (hf : Continuous f) (hdf : Continuous df) + (hfbound : ∀ x, ‖f x‖ ≤ C) (hdfbound : ∀ x, ‖df x‖ ≤ D) + (hder : ∀ (u : Fin n → ℝ) (z : ℝ), + HasDerivAt (fun z => f (i.insertNth z u)) (df (i.insertNth z u)) z) : + (∫ x, x i * f x ∂standardGaussianProduct (n + 1)) = + ∫ x, df x ∂standardGaussianProduct (n + 1) := by + let e := MeasurableEquiv.piFinSuccAbove (fun _ : Fin (n + 1) => ℝ) i + have hp : MeasurePreserving e.symm + ((gaussianReal 0 1).prod (standardGaussianProduct n)) + (standardGaussianProduct (n + 1)) := + (measurePreserving_piFinSuccAbove (fun _ => gaussianReal 0 1) i).symm + have hi : Integrable (fun x : Fin (n + 1) → ℝ => x i * f x) + (standardGaussianProduct (n + 1)) := by + simpa only [mul_comm, standardGaussianProduct] using + (integrable_eval (i := i) IsGaussian.integrable_id).bdd_mul + hf.aestronglyMeasurable (ae_of_all _ hfbound) + have hi' : Integrable df (standardGaussianProduct (n + 1)) := + Integrable.of_bound hdf.aestronglyMeasurable D (ae_of_all _ hdfbound) + have hsplit (g : (Fin (n + 1) → ℝ) → ℝ) + (hg : Integrable g (standardGaussianProduct (n + 1))) : + (∫ x, g x ∂standardGaussianProduct (n + 1)) = + ∫ u, ∫ z, g (i.insertNth z u) ∂gaussianReal 0 1 ∂standardGaussianProduct n := by + have hi2 : Integrable (fun x => g (e.symm x)) + ((gaussianReal 0 1).prod (standardGaussianProduct n)) := + hp.integrable_comp_of_integrable hg + rw [← hp.integral_comp' g, integral_prod _ hi2] + rw [integral_integral_swap hi2] + rfl + rw [hsplit _ hi, hsplit _ hi'] + apply integral_congr_ae + filter_upwards [] with u + simp only [Fin.insertNth_apply_same] + have hfu : Integrable (fun z => f (i.insertNth z u)) (gaussianReal 0 1) := + Integrable.of_bound (hf.comp (continuous_insertNth i u)).aestronglyMeasurable C + (ae_of_all _ (fun z => hfbound _)) + have hdfu : Integrable (fun z => df (i.insertNth z u)) (gaussianReal 0 1) := + Integrable.of_bound (hdf.comp (continuous_insertNth i u)).aestronglyMeasurable D + (ae_of_all _ (fun z => hdfbound _)) + have hzfu : Integrable (fun z => z * f (i.insertNth z u)) (gaussianReal 0 1) := by + simpa only [mul_comm, id_eq, Function.comp_def] using (IsGaussian.integrable_id (μ := gaussianReal 0 1)).bdd_mul + (hf.comp (continuous_insertNth i u)).aestronglyMeasurable + (ae_of_all _ (fun z => hfbound _)) + simpa only [NNReal.coe_one, sub_zero, one_mul] using + gaussian_integration_by_parts (d := 0) (s := 1) one_ne_zero (hder u) hfu hdfu + (by simpa only [sub_zero] using hzfu) + +end SKGap + +open Filter +open scoped Topology +namespace SKGap +lemma tendsto_gaussianPDFReal_atTop (d : ℝ) {s : ℝ≥0} (hs : 0 < s) : + Filter.Tendsto (gaussianPDFReal d s) Filter.atTop (𝓝 0) := by + have hsp : (0:ℝ) < s := hs + have hshift : Tendsto (fun x : ℝ => x-d) atTop atTop := by + apply tendsto_atTop.2 + intro b + filter_upwards [eventually_ge_atTop (b+d)] with x hx + linarith + have hpow : Filter.Tendsto (fun x : ℝ => (x-d)^2) Filter.atTop Filter.atTop := + (tendsto_pow_atTop (by norm_num : (2:ℕ) ≠ 0)).comp hshift + have hexp := Real.tendsto_exp_neg_atTop_nhds_zero.comp (hpow.atTop_div_const (by positivity : 0 < 2*(s:ℝ))) + rw [gaussianPDFReal_def] + simpa only [neg_div, mul_zero,one_div,Function.comp_apply] using hexp.const_mul (1/sqrt (2*Real.pi*(s:ℝ))) + +lemma tendsto_gaussianPDFReal_neg_atTop (d : ℝ) {s : ℝ≥0} (hs : 0 < s) : + Filter.Tendsto (fun x => gaussianPDFReal d s (-x)) Filter.atTop (𝓝 0) := by + have he : (fun x => gaussianPDFReal d s (-x)) = gaussianPDFReal (-d) s := by + funext x + unfold gaussianPDFReal + congr 2 + ring + rw [he] + exact tendsto_gaussianPDFReal_atTop (-d) hs + +theorem gaussian_lipschitz_IBP {f : ℝ → ℝ} {L : ℝ≥0} {C d : ℝ} {s : ℝ≥0} + (hs : 0 < s) (hL : LipschitzWith L f) (hC : ∀ x, ‖f x‖ ≤ C) : + (∫ y, (y-d)*f y ∂gaussianReal d s) = (s:ℝ)*(∫ y, deriv f y ∂gaussianReal d s) := by + have hC0 : 0 ≤ C := (norm_nonneg (f 0)).trans (hC 0) + have hdf : Integrable (deriv f) (gaussianReal d s) := + Integrable.of_bound (measurable_deriv f).aestronglyMeasurable (L:ℝ) + (ae_of_all _ (fun _ => norm_deriv_le_of_lipschitz hL)) + have hyf : Integrable (fun y => (y-d)*f y) (gaussianReal d s) := by + have hh := ((IsGaussian.integrable_id (μ := gaussianReal d s)).sub (integrable_const d)).bdd_mul + (f := f) hL.continuous.aestronglyMeasurable (ae_of_all _ hC) + simpa only [mul_comm,Pi.sub_apply,id_eq] using hh + let p := gaussianPDFReal d s + have hpi : Integrable (fun y => p y*deriv f y) := (integrable_gaussian_iff hs.ne').mp hdf + have hxi : Integrable (fun y => p y*((y-d)*f y)) := (integrable_gaussian_iff hs.ne').mp hyf + let g : ℝ → ℝ := fun y => p y*deriv f y-(p y*((y-d)*f y))/(s:ℝ) + have hgi : Integrable g := hpi.sub (hxi.div_const _) + have hpd (y : ℝ) : deriv p y = -(y-d)/(s:ℝ)*p y := (hasDerivAt_gaussianPDFReal d hs.ne' y).deriv + have hpac (a b : ℝ) : AbsolutelyContinuousOnInterval p a b := by + apply ContDiffOn.absolutelyContinuousOnInterval + have hh : ContDiff ℝ 1 p := by + change ContDiff ℝ 1 (fun x : ℝ => (sqrt (2 * π * (s : ℝ)))⁻¹ * exp (-(x-d)^2/(2*(s:ℝ)))) + fun_prop + exact hh.contDiffOn + have hfac (a b : ℝ) : AbsolutelyContinuousOnInterval f a b := hL.lipschitzOnWith.absolutelyContinuousOnInterval + have hftc (a b : ℝ) : (∫ y in a..b, g y) = p b*f b-p a*f a := by + rw [← (hpac a b).integral_deriv_mul_eq_sub (hfac a b)] + apply intervalIntegral.integral_congr + intro y _ + dsimp [g] + rw [hpd] + ring + have hbd (u : ℝ → ℝ) (hp : Filter.Tendsto (fun x => p (u x)) Filter.atTop (𝓝 0)) : + Filter.Tendsto (fun x => p (u x)*f (u x)) Filter.atTop (𝓝 0) := by + apply squeeze_zero_norm (fun x => ?_) (by simpa only [zero_mul] using hp.mul_const C) + rw [norm_mul, Real.norm_eq_abs (p (u x)),abs_of_nonneg (gaussianPDFReal_nonneg _ _ _)] + exact mul_le_mul_of_nonneg_left (hC _) (gaussianPDFReal_nonneg _ _ _) + have htop := hbd id (tendsto_gaussianPDFReal_atTop d hs) + have hbot := hbd Neg.neg (tendsto_gaussianPDFReal_neg_atTop d hs) + have hlim := intervalIntegral_tendsto_integral hgi Filter.tendsto_neg_atTop_atBot Filter.tendsto_id + simp only [hftc] at hlim + have hz : (∫ y, g y) = 0 := by + simpa only [id_eq,sub_zero] using tendsto_nhds_unique hlim (htop.sub hbot) + dsimp [g] at hz + rw [integral_sub hpi (hxi.div_const _),integral_div] at hz + rw [integral_gaussianReal_eq_integral_smul hs.ne',integral_gaussianReal_eq_integral_smul hs.ne'] + simp only [smul_eq_mul] + have hh : (∫ y, p y*((y-d)*f y))/(s:ℝ) = ∫ y, p y*deriv f y := by linarith + have hm := (div_eq_iff (ne_of_gt (show (0:ℝ) < s from hs))).mp hh + dsimp [p] at hm + nlinarith only [hm] + +end SKGap + +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Gaussian/StdGaussianMgfLipschitz.lean b/lean/OAI/Probability/SKGap/Gaussian/StdGaussianMgfLipschitz.lean new file mode 100644 index 0000000000000000000000000000000000000000..75b9e4fbcc468b52cd747c3d7e4df21fc935f0b4 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Gaussian/StdGaussianMgfLipschitz.lean @@ -0,0 +1,123 @@ +import Mathlib +import OAI.Probability.SKGap.Matrix.LipschitzNormedConvolution + +namespace OAI + +section +noncomputable section +open MeasureTheory ProbabilityTheory InformationTheory Real Set +open scoped NNReal ENNReal +open Filter +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius ENNReal NNReal +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius NNReal +noncomputable section +open MeasureTheory ProbabilityTheory Real Set Filter +open MeasureTheory.Measure +open scoped ENNReal NNReal MeasureTheory Topology +namespace SKGap +section StandardGaussianRotation +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] + [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] + +theorem stdGaussian_mgf_lipschitz_le {f : E → ℝ} {L : ℝ≥0} + (hf : LipschitzWith L f) (r : ℝ) : + (∫ x, exp (r * (f x - ∫ y, f y ∂stdGaussian E)) ∂stdGaussian E) ≤ + exp (π ^ 2 * r ^ 2 * (L : ℝ) ^ 2 / 8) := by + have hε (ε : ℝ) (hε : 0 < ε) : + (∫ x, exp (r * (f x - ∫ y, f y ∂stdGaussian E)) ∂stdGaussian E) ≤ + exp (2 * |r| * ((L : ℝ) * ε)) * exp (π ^ 2 * r ^ 2 * (L : ℝ) ^ 2 / 8) := by + obtain ⟨g, hgs, hgl, hgf⟩ := exists_smooth_lipschitz_approx hf hε + have hmg := stdGaussian_mgf_centered_le + (fun x => (hgs.differentiable (by simp) x).hasFDerivAt) + (hgs.continuous_fderiv (by simp)) (fun _ => norm_fderiv_le_of_lipschitz ℝ hgl) r + exact (centered_mgf_le_of_uniform_dist hf hgl + (fun x => by simpa only [dist_comm] using hgf x) r).trans + (mul_le_mul_of_nonneg_left hmg (exp_pos _).le) + have ht : Tendsto (fun ε : ℝ => exp (2 * |r| * ((L : ℝ) * ε)) * + exp (π ^ 2 * r ^ 2 * (L : ℝ) ^ 2 / 8)) (𝓝[>] 0) + (𝓝 (exp (π ^ 2 * r ^ 2 * (L : ℝ) ^ 2 / 8))) := by + have hc : Continuous (fun ε : ℝ => exp (2 * |r| * ((L : ℝ) * ε)) * + exp (π ^ 2 * r ^ 2 * (L : ℝ) ^ 2 / 8)) := by fun_prop + simpa using ((hc.tendsto 0).mono_left (nhdsWithin_le_nhds (s := Ioi (0 : ℝ)))) + apply ge_of_tendsto ht + filter_upwards [self_mem_nhdsWithin] with ε heps + exact hε ε heps + +theorem stdGaussian_upper_tail_lipschitz {f : E → ℝ} {L : ℝ≥0} + (hf : LipschitzWith L f) (hL : 0 < L) {u : ℝ} (hu : 0 ≤ u) : + (stdGaussian E).real {x | u ≤ f x - ∫ y, f y ∂stdGaussian E} ≤ + exp (-2 * u ^ 2 / (π ^ 2 * (L : ℝ) ^ 2)) := by + let t : ℝ := 4 * u / (π ^ 2 * (L : ℝ) ^ 2) + have hLr : 0 < (L : ℝ) := hL + have hden : 0 < π ^ 2 * (L : ℝ) ^ 2 := mul_pos (sq_pos_of_pos pi_pos) (sq_pos_of_pos hLr) + have ht : 0 ≤ t := div_nonneg (mul_nonneg (by norm_num) hu) hden.le + have hi : Integrable (fun x => exp (t * (f x - ∫ y, f y ∂stdGaussian E))) + (stdGaussian E) := by + simp_rw [exp_mul_sub] + exact (gaussian_integrable_exp_lipschitz hf t).const_mul _ + calc + _ ≤ exp (-t * u) * ∫ x, exp (t * (f x - ∫ y, f y ∂stdGaussian E)) + ∂stdGaussian E := measure_ge_le_exp_mul_mgf u ht hi + _ ≤ exp (-t * u) * exp (π ^ 2 * t ^ 2 * (L : ℝ) ^ 2 / 8) := + mul_le_mul_of_nonneg_left (stdGaussian_mgf_lipschitz_le hf t) (exp_pos _).le + _ = exp (-2 * u ^ 2 / (π ^ 2 * (L : ℝ) ^ 2)) := by + rw [← exp_add] + congr 1 + dsimp [t] + field_simp + ring + +theorem stdGaussian_lower_tail_lipschitz {f : E → ℝ} {L : ℝ≥0} + (hf : LipschitzWith L f) (hL : 0 < L) {u : ℝ} (hu : 0 ≤ u) : + (stdGaussian E).real {x | f x - ∫ y, f y ∂stdGaussian E ≤ -u} ≤ + exp (-2 * u ^ 2 / (π ^ 2 * (L : ℝ) ^ 2)) := by + have h := stdGaussian_upper_tail_lipschitz hf.neg hL hu + have he : {x | (fun x => -f x) x - ∫ y, -f y ∂stdGaussian E ≥ u} = + {x | f x - ∫ y, f y ∂stdGaussian E ≤ -u} := by + ext x + simp only [mem_ofPred_eq, integral_neg] + constructor <;> intro hx <;> linarith + simp only [Pi.neg_apply] at h + rw [he] at h + exact h + +theorem stdGaussian_tail_lipschitz {f : E → ℝ} {L : ℝ≥0} + (hf : LipschitzWith L f) (hL : 0 < L) {u : ℝ} (hu : 0 ≤ u) : + (stdGaussian E).real {x | u ≤ |f x - ∫ y, f y ∂stdGaussian E|} ≤ + 2 * exp (-2 * u ^ 2 / (π ^ 2 * (L : ℝ) ^ 2)) := by + have he : {x | u ≤ |f x - ∫ y, f y ∂stdGaussian E|} = + {x | u ≤ f x - ∫ y, f y ∂stdGaussian E} ∪ + {x | f x - ∫ y, f y ∂stdGaussian E ≤ -u} := by + ext x + simp only [mem_union, mem_ofPred_eq, le_abs] + constructor <;> rintro (hx | hx) + · exact Or.inl hx + · right; linarith + · exact Or.inl hx + · right; linarith + rw [he] + calc + _ ≤ (stdGaussian E).real {x | u ≤ f x - ∫ y, f y ∂stdGaussian E} + + (stdGaussian E).real {x | f x - ∫ y, f y ∂stdGaussian E ≤ -u} := + measureReal_union_le _ _ + _ ≤ exp (-2 * u ^ 2 / (π ^ 2 * (L : ℝ) ^ 2)) + + exp (-2 * u ^ 2 / (π ^ 2 * (L : ℝ) ^ 2)) := + add_le_add (stdGaussian_upper_tail_lipschitz hf hL hu) + (stdGaussian_lower_tail_lipschitz hf hL hu) + _ = _ := by ring + +end StandardGaussianRotation +end SKGap + +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Gaussian/SteinRecipeRegularity.lean b/lean/OAI/Probability/SKGap/Gaussian/SteinRecipeRegularity.lean new file mode 100644 index 0000000000000000000000000000000000000000..79cbe606f4fa8423e29016795026973efb7260ff --- /dev/null +++ b/lean/OAI/Probability/SKGap/Gaussian/SteinRecipeRegularity.lean @@ -0,0 +1,56 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.RecipeCoefficientClosure + +namespace OAI + +section + +noncomputable section +open scoped BigOperators +namespace SKGapCutoff.Recipe +open SKGap.Stein +variable {n : ℕ} {ι κ σ : Type*} [Fintype ι] [DecidableEq ι] [Fintype κ] [DecidableEq κ] [Fintype σ] + +omit [Fintype ι] [DecidableEq ι] [Fintype κ] [DecidableEq κ] in +lemma two_field_kernel_value (f : KernelExpr) (H : ι→VectorFields n) + (θ : κ→Spin n→ℝ) (x : Spin n) (l m : ι) (α : κ) (R : ℝ) + (hx : |θ α x|≤R) (hf : ∀k,|θ α (flip x k)|≤R) : + SegmentValue H θ (fun _ u=>eval3 f.eval (phiPairSelect l m α u)) x (f.mass*Real.exp (R/2)) := by + intro i k t ht + apply f.absolute_bound + have hb : phiPairSelect l m α (localArgs H θ x i)∈strip R := by + simpa [strip,phiPairSelect,localArgs] using hx + have he : phiPairSelect l m α (localArgs H θ (flip x k) i)∈strip R := by + simpa [strip,phiPairSelect,localArgs] using hf k + have := (convex_strip R).add_smul_sub_mem hb he ht + simpa only [map_add,map_smul,map_sub] using this + +def steinCoefficientBudget (R : ℝ) : ℝ := + let f:=KernelExpr.atom 0 0 false + f.mass*Real.exp (R/2)+f.dBudget R+f.ddBudget R +lemma steinCoefficientBudget_nonneg (R : ℝ) : 0 ≤ steinCoefficientBudget R := by + have h0:= (KernelExpr.atom 0 0 false).mass_nonneg + have h1:= (KernelExpr.atom 0 0 false).dBudget_nonneg R + have h2:= (KernelExpr.atom 0 0 false).ddBudget_nonneg R + unfold steinCoefficientBudget + positivity + +namespace OrdinaryData +omit [Fintype σ] in +lemma CoefficientClass.appendStein {D : OrdinaryData n ι κ σ} {N : ℕ} {x : Spin n} {K : ℝ} + (h : D.CoefficientClass N x K) (l m : ι) (α : κ) (R : ℝ) + (hx : |D.θ α x|≤R) (hf : ∀k,|D.θ α (flip x k)|≤R) : + (D.appendStein N l m α).CoefficientClass (N+1) x (K+4*steinCoefficientBudget R*K) := by + apply h.appendProduct (steinCoefficientBudget_nonneg R) + · apply (two_field_kernel_regular (KernelExpr.atom 0 0 false) D.H D.θ x l m α R hx hf).mono + exact le_add_of_nonneg_left (mul_nonneg (KernelExpr.atom 0 0 false).mass_nonneg (Real.exp_pos _).le) |>.trans_eq (by unfold steinCoefficientBudget; ring) + · intro i k t ht + exact (two_field_kernel_value (KernelExpr.atom 0 0 false) D.H D.θ x l m α R hx hf i k t ht).trans + (by unfold steinCoefficientBudget; linarith [(KernelExpr.atom 0 0 false).dBudget_nonneg R,(KernelExpr.atom 0 0 false).ddBudget_nonneg R]) +end OrdinaryData +end SKGapCutoff.Recipe + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Gaussian/SubgaussianAbsTail.lean b/lean/OAI/Probability/SKGap/Gaussian/SubgaussianAbsTail.lean new file mode 100644 index 0000000000000000000000000000000000000000..c39ff2bedfc1614e29f50288adaf61b814bd7932 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Gaussian/SubgaussianAbsTail.lean @@ -0,0 +1,202 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.StandardArrayLaw + +namespace OAI + +section +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open scoped BigOperators +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open scoped BigOperators +open scoped BigOperators NNReal ENNReal +open MeasureTheory Metric Set +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators NNReal ENNReal Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Set +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators ENNReal NNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Matrix +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators ENNReal NNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal +namespace SKGapCutoff.Regression + +lemma subgaussian_abs_tail {Ω : Type*} [MeasurableSpace Ω] {μ : Measure Ω} + [IsFiniteMeasure μ] {X : Ω → ℝ} {c : ℝ≥0} (hX : HasSubgaussianMGF X c μ) + (ε : ℝ) (hε : 0 ≤ ε) : + μ {ω | ε ≤ |X ω|} ≤ 2 * ENNReal.ofReal (Real.exp (-ε^2/(2*(c:ℝ)))) := by + have hu := ENNReal.ofReal_le_ofReal (hX.measure_ge_le hε) + have hl := ENNReal.ofReal_le_ofReal (hX.neg.measure_ge_le hε) + simp only [Measure.real, ENNReal.ofReal_toReal (measure_ne_top _ _)] at hu hl + have hs : {ω | ε ≤ |X ω|} ⊆ {ω | ε ≤ X ω} ∪ {ω | ε ≤ -X ω} := by + intro ω h + simpa only [Set.mem_union, Set.mem_ofPred_eq, le_abs] using h + calc + _ ≤ _ := measure_mono hs + _ ≤ _ := measure_union_le _ _ + _ ≤ _ := add_le_add hu hl + _ = _ := (two_mul _).symm + +lemma iid_bounded_average_tail_of_hasLaw {Ω : Type*} [MeasurableSpace Ω] + {μ : Measure Ω} [IsProbabilityMeasure μ] {n : ℕ} (hn : 0 < n) + (X : Fin n → Ω → ℝ) (hXi : iIndepFun X μ) + (hX : ∀ i, HasLaw (X i) (gaussianReal 0 1) μ) (f : ℝ → ℝ) + (hf : Measurable f) (B : ℝ) (hB : 0 ≤ B) (hbound : ∀ z, |f z| ≤ B) + (ε : ℝ) (hε : 0 ≤ ε) : + μ {g | + ε ≤ |(∑ i : Fin n, f (X i g))/(n:ℝ) - ∫ z, f z ∂gaussianReal 0 1|} ≤ + 2 * ENNReal.ofReal (Real.exp (-(ε^2*(n:ℝ))/(2*B^2))) := by + let m := ∫ z, f z ∂gaussianReal 0 1 + have hi : iIndepFun (fun i (g : Ω) => f (X i g) - m) μ := + hXi.comp (fun _ z => f z-m) (fun _ => hf.sub_const m) + have hm (i : Fin n) : + (∫ g : Ω, f (X i g) ∂μ) = m := by + exact (hX i).integral_comp hf.aestronglyMeasurable + have hsub (i : Fin n) : HasSubgaussianMGF (fun g : Ω => f (X i g)-m) + ((‖B-(-B)‖₊/2)^2) μ := by + have hb : ∀ᵐ g : Ω ∂μ, f (X i g) ∈ Set.Icc (-B) B := + Eventually.of_forall (fun g => abs_le.mp (hbound (X i g))) + simpa only [hm] using hasSubgaussianMGF_of_mem_Icc + (show AEMeasurable (fun g : Ω => f (X i g)) μ from + hf.comp_aemeasurable (hX i).aemeasurable) hb + have hh := subgaussian_abs_tail + (HasSubgaussianMGF.sum_of_iIndepFun hi (s := Finset.univ) (fun i _ => hsub i)) + (ε*n) (by positivity) + have he (g : Ω) : + (ε*(n:ℝ) ≤ |∑ i : Fin n, (f (X i g)-m)|) ↔ + ε ≤ |(∑ i : Fin n, f (X i g))/(n:ℝ)-m| := by + have hnR : (0:ℝ) < n := Nat.cast_pos.mpr hn + rw [Finset.sum_sub_distrib, Finset.sum_const, Finset.card_univ, Fintype.card_fin, + nsmul_eq_mul] + have heq : (∑ i : Fin n, f (X i g))-(n:ℝ)*m = + (n:ℝ)*((∑ i : Fin n, f (X i g))/(n:ℝ)-m) := by field_simp + rw [heq, abs_mul, abs_of_pos hnR] + rw [mul_comm ε (n:ℝ), mul_le_mul_iff_right₀ hnR] + simp only [he] at hh + convert hh using 1 + congr 3 + simp only [Finset.sum_const, Finset.card_univ, Fintype.card_fin, nsmul_eq_mul, + NNReal.coe_mul, NNReal.coe_natCast, NNReal.coe_pow, NNReal.coe_div, NNReal.coe_ofNat, + coe_nnnorm, Real.norm_eq_abs] + rw [abs_of_nonneg (by linarith : 0 ≤ B-(-B))] + have hn0 : (n:ℝ) ≠ 0 := Nat.cast_ne_zero.mpr (Nat.ne_of_gt hn) + by_cases hB0 : B=0 + · simp [hB0] + · field_simp + ring + +lemma iid_bounded_average_tail {n : ℕ} (hn : 0 < n) (f : ℝ → ℝ) + (hf : Measurable f) (B : ℝ) (hB : 0 ≤ B) (hbound : ∀ z, |f z| ≤ B) + (ε : ℝ) (hε : 0 ≤ ε) : + standardArrayLaw (Fin n) {g | + ε ≤ |(∑ i : Fin n, f (g i))/(n:ℝ) - ∫ z, f z ∂gaussianReal 0 1|} ≤ + 2 * ENNReal.ofReal (Real.exp (-(ε^2*(n:ℝ))/(2*B^2))) := by + exact iid_bounded_average_tail_of_hasLaw (μ := standardArrayLaw (Fin n)) hn + (fun (i : Fin n) (g : Fin n → ℝ) => g i) + coordinates_independent coordinate_hasLaw f hf B hB hbound ε hε + +lemma gaussian_hasSubgaussianMGF {Ω : Type*} [MeasurableSpace Ω] + {μ : Measure Ω} [IsProbabilityMeasure μ] {X : Ω → ℝ} {v : ℝ≥0} + (hX : HasLaw X (gaussianReal 0 v) μ) : HasSubgaussianMGF X v μ where + integrable_exp_mul t := by + rw [← mgf_pos_iff, mgf_gaussianReal hX] + exact Real.exp_pos _ + mgf_le t := by + rw [mgf_gaussianReal hX] + simp + +lemma average_common_shift_bound {n : ℕ} (hn : 0 < n) {f : ℝ → ℝ} {K : ℝ≥0} + (hf : LipschitzWith K f) (v : Fin n → ℝ) (r : ℝ) : + |(∑ i, f (v i+r))/(n:ℝ) - (∑ i, f (v i))/(n:ℝ)| ≤ (K:ℝ)*|r| := by + have hnR : (0:ℝ) < n := Nat.cast_pos.mpr hn + rw [← sub_div, ← Finset.sum_sub_distrib, abs_div, abs_of_pos hnR] + apply (div_le_iff₀ hnR).mpr + apply (Finset.abs_sum_le_sum_abs _ _).trans + calc + _ ≤ ∑ _i : Fin n, (K:ℝ)*|r| := by + apply Finset.sum_le_sum + intro i _ + simpa only [Real.dist_eq, add_sub_cancel_left] using hf.dist_le_mul (v i+r) (v i) + _ = _ := by simp [mul_comm] + +lemma iid_common_shift_average_tail {n : ℕ} (hn : 0 < n) (m a b : ℝ) + (f : ℝ → ℝ) {K : ℝ≥0} (hf : LipschitzWith K f) + (B : ℝ) (hB : 0 ≤ B) (hbound : ∀ z, |f z| ≤ B) + (ε : ℝ) (hε : 0 ≤ ε) : + standardArrayLaw (Option (Fin n)) {g | + ε ≤ |(∑ i : Fin n, f (m+a*g (some i)+b*g none))/(n:ℝ) - + ∫ z, f (m+a*z) ∂gaussianReal 0 1|} ≤ + 2 * ENNReal.ofReal (Real.exp (-(ε^2*(n:ℝ))/(8*B^2))) + + 2 * ENNReal.ofReal (Real.exp (-ε^2/(8*(K:ℝ)^2*b^2))) := by + let M := ∫ z, f (m+a*z) ∂gaussianReal 0 1 + let A (g : Option (Fin n) → ℝ) := (∑ i : Fin n, f (m+a*g (some i)))/(n:ℝ) + have hi : iIndepFun (fun i : Fin n => fun g : Option (Fin n) → ℝ => g (some i)) + (standardArrayLaw (Option (Fin n))) := coordinates_independent.precomp (Option.some_injective (Fin n)) + have ht := iid_bounded_average_tail_of_hasLaw (μ := standardArrayLaw (Option (Fin n))) hn + (fun (i : Fin n) (g : Option (Fin n) → ℝ) => g (some i)) hi + (fun i => coordinate_hasLaw (some i)) (fun z => f (m+a*z)) + (hf.continuous.measurable.comp (measurable_const.add (measurable_const.mul measurable_id))) + B hB (fun z => hbound _) (ε/2) (by positivity) + have hz := subgaussian_abs_tail + ((gaussian_hasSubgaussianMGF (coordinate_hasLaw (none : Option (Fin n)))).const_mul ((K:ℝ)*b)) + (ε/2) (by positivity) + have hsub : {g | ε ≤ |(∑ i : Fin n, f (m+a*g (some i)+b*g none))/(n:ℝ)-M|} ⊆ + {g | ε/2 ≤ |A g-M|} ∪ {g | ε/2 ≤ |(K:ℝ)*b*g none|} := by + intro g hg + by_cases ha : ε/2 ≤ |A g-M| + · exact Or.inl ha + apply Or.inr + have hd := average_common_shift_bound hn hf (fun i => m+a*g (some i)) (b*g none) + have htri := abs_add_le + ((∑ i : Fin n, f (m+a*g (some i)+b*g none))/(n:ℝ) - A g) (A g-M) + have hrad : (K:ℝ)*|b*g none| = |(K:ℝ)*b*g none| := by + simp [abs_mul, abs_of_nonneg K.coe_nonneg, mul_assoc] + rw [hrad] at hd + simp only [sub_add_sub_cancel] at htri + change ε ≤ _ at hg + change |(∑ i : Fin n, f (m+a*g (some i)+b*g none))/(n:ℝ) - A g| ≤ _ at hd + have : |A g-M| < ε/2 := lt_of_not_ge ha + change ε/2 ≤ |(K:ℝ)*b*g none| + linarith + apply (measure_mono hsub).trans + apply (measure_union_le _ _).trans + have h1 : standardArrayLaw (Option (Fin n)) {g | ε/2 ≤ |A g-M|} ≤ + 2 * ENNReal.ofReal (Real.exp (-(ε^2*(n:ℝ))/(8*B^2))) := by + convert ht using 1 + congr 3 + ring + have h2 : standardArrayLaw (Option (Fin n)) {g | ε/2 ≤ |(K:ℝ)*b*g none|} ≤ + 2 * ENNReal.ofReal (Real.exp (-ε^2/(8*(K:ℝ)^2*b^2))) := by + convert hz using 1 + congr 3 + change -ε^2 / (8 * (K:ℝ)^2 * b^2) = -(ε / 2)^2 / (2 * ((((K:ℝ)*b)^2) * 1)) + ring + exact add_le_add h1 h2 + +end SKGapCutoff.Regression + +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/AffineBilinear.lean b/lean/OAI/Probability/SKGap/Localization/AffineBilinear.lean new file mode 100644 index 0000000000000000000000000000000000000000..1dcf695c0f8b4e60d43f2252fa6f87c4b9abf811 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/AffineBilinear.lean @@ -0,0 +1,128 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.ProjectedReal +import OAI.Probability.SKGap.Localization.Bilinear + +namespace OAI + +section +noncomputable section +namespace SKGap +open Matrix MeasureTheory ProbabilityTheory Real Set +open scoped BigOperators Matrix.Norms.Frobenius NNReal ENNReal +variable {ι : Type*} [Fintype ι] [DecidableEq ι] + +omit [DecidableEq ι] in +lemma gaussianCoordinate_mean (a : MatrixCoordinates ι) : + (∫ g : MatrixCoordinates ι → ℝ, g a ∂Measure.pi (fun _ => gaussianReal 0 1)) = 0 := by + rw [integral_comp_eval (μ := fun _ : MatrixCoordinates ι => gaussianReal 0 1) (i := a) + (by fun_prop : AEStronglyMeasurable (fun x : ℝ => x) (gaussianReal 0 1))] + exact integral_id_gaussianReal + +omit [DecidableEq ι] in +lemma goeEntry_integral (r : ℝ) (i k : ι) : + (∫ g, goeMatrix r g i k ∂Measure.pi (fun _ : MatrixCoordinates ι => gaussianReal 0 1)) = 0 := by + simp only [goeMatrix,integral_const_mul] + rw [integral_add ((gaussianCoordinate_memLp (.inl (i,k))).integrable (by norm_num)) + ((gaussianCoordinate_memLp (.inl (k,i))).integrable (by norm_num))] + simp only [gaussianCoordinate_mean,add_zero,mul_zero] + +omit [Fintype ι] in +lemma signConjugate_diagonal (s : ι → ℝ) (hs : ∀ i, s i^2=1) (d : ι → ℝ) : + signConjugate s (diagonal d)=diagonal d := by + ext i k + by_cases h : i=k + · subst k + simp only [signConjugate,diagonal_apply_eq] + rw [← pow_two,hs,one_mul] + · simp [signConjugate,diagonal_apply_ne _ h] + +omit [Fintype ι] [DecidableEq ι] in +lemma signConjugate_sub (s : ι → ℝ) (M N : Matrix ι ι ℝ) : + signConjugate s (M-N) = signConjugate s M-signConjugate s N := by + ext i k; simp [signConjugate,mul_sub] + +omit [Fintype ι] [DecidableEq ι] in +lemma signConjugate_smul (s : ι → ℝ) (w : ℝ) (M : Matrix ι ι ℝ) : + signConjugate s (w • M) = w • signConjugate s M := by + ext i k; simp only [signConjugate,Matrix.smul_apply,smul_eq_mul]; ring + +def affineRight (F : Matrix ι ι ℝ → Matrix ι ι ℝ) (d e : ι → ℝ) + (w : ℝ) (M : Matrix ι ι ℝ) : Matrix ι ι ℝ := F M*diagonal d-diagonal e-w • M + +lemma affineRight_sign (F : Matrix ι ι ℝ → Matrix ι ι ℝ) (d e : ι → ℝ) (w : ℝ) + (hF : ∀ (s : ι → ℝ), (∀ i, s i^2=1) → ∀ M, + F (signConjugate s M)=signConjugate s (F M)) + (s : ι → ℝ) (hs : ∀ i, s i^2=1) (M : Matrix ι ι ℝ) : + affineRight F d e w (signConjugate s M)=signConjugate s (affineRight F d e w M) := by + simp only [affineRight,signConjugate_sub,signConjugate_smul,signConjugate_mul s hs, + signConjugate_diagonal s hs,hF s hs] + +lemma affineRight_lip (F : Matrix ι ι ℝ → Matrix ι ι ℝ) (d e : ι → ℝ) (w : ℝ) + {L D : ℝ} (hD : 0 ≤ D) (hd : ∀ i, |d i| ≤ D) + (hF : ∀ M N, ‖F M-F N‖ ≤ L*‖M-N‖) (M N : Matrix ι ι ℝ) : + ‖affineRight F d e w M-affineRight F d e w N‖ ≤ (L*D+|w|)*‖M-N‖ := by + have he : affineRight F d e w M-affineRight F d e w N = + (F M-F N)*diagonal d-w • (M-N) := by + simp only [affineRight,sub_mul,smul_sub]; abel + rw [he] + calc + _ ≤ ‖(F M-F N)*diagonal d‖+‖w • (M-N)‖ := norm_sub_le _ _ + _ ≤ ‖F M-F N‖*opNorm (diagonal d)+|w| *‖M-N‖ := by + rw [norm_smul,Real.norm_eq_abs] + exact add_le_add (frobenius_mul_le_opNorm_right (F M-F N) (diagonal d)) le_rfl + _ ≤ (L*‖M-N‖)*D+|w| *‖M-N‖ := add_le_add + (mul_le_mul (hF M N) (opNorm_diagonal_le hD hd) (norm_nonneg _) (le_trans (norm_nonneg _) (hF M N))) le_rfl + _ = _ := by ring + +lemma affineRight_diag (F : Matrix ι ι ℝ → Matrix ι ι ℝ) (d e : ι → ℝ) + (w : ℝ) (M : Matrix ι ι ℝ) (i : ι) : + affineRight F d e w M i i=F M i i*d i-e i-w*M i i := by + simp only [affineRight,Matrix.sub_apply,Matrix.mul_diagonal,diagonal_apply_eq, + Matrix.smul_apply,smul_eq_mul] + +lemma affineRight_bias (r : ℝ) (F : Matrix ι ι ℝ → Matrix ι ι ℝ) (d e k : ι → ℝ) (w : ℝ) + {ε D : ℝ} (_hD : 0 ≤ D) (hd : ∀ i, |d i| ≤ D) + (hI : ∀ i k, Integrable (fun g => F (goeMatrix r g) i k) + (Measure.pi (fun _ : MatrixCoordinates ι => gaussianReal 0 1))) + (hF : ∀ i, |(∫ g, F (goeMatrix r g) i i + ∂Measure.pi (fun _ : MatrixCoordinates ι => gaussianReal 0 1))-k i| ≤ ε) (i : ι) : + |(∫ g, affineRight F d e w (goeMatrix r g) i i + ∂Measure.pi (fun _ : MatrixCoordinates ι => gaussianReal 0 1))-(k i*d i-e i)| ≤ ε*D := by + simp_rw [affineRight_diag] + rw [integral_sub (f := fun g => F (goeMatrix r g) i i*d i-e i) + (g := fun g => w*goeMatrix r g i i) + ((hI i i).mul_const (d i) |>.sub (integrable_const (e i))) + ((goeEntry_memLp r i i).integrable (by norm_num) |>.const_mul w), + integral_sub (f := fun g => F (goeMatrix r g) i i*d i) (g := fun _ => e i) + ((hI i i).mul_const (d i)) (integrable_const (e i)), + integral_mul_const,integral_const,integral_const_mul,goeEntry_integral] + simp only [probReal_univ,one_smul,mul_zero,sub_zero] + rw [show (∫ g, F (goeMatrix r g) i i ∂Measure.pi (fun _ : MatrixCoordinates ι => gaussianReal 0 1))*d i-e i- + (k i*d i-e i) = ((∫ g, F (goeMatrix r g) i i ∂Measure.pi (fun _ : MatrixCoordinates ι => gaussianReal 0 1))-k i)*d i by ring, + abs_mul] + exact mul_le_mul (hF i) (hd i) (abs_nonneg _) (le_trans (abs_nonneg _) (hF i)) + +lemma affineRight_concentration [Nonempty ι] {j L U ε D t : ℝ} + (hj : 0 < j) (hL : 0 ≤ L) (hU : 0 ≤ U) (hε : 0 ≤ ε) (hD : 0 ≤ D) (ht : 0 ≤ t) + (F : Matrix ι ι ℝ → Matrix ι ι ℝ) (d e k : ι → ℝ) (w : ℝ) + (hd : ∀ i, |d i| ≤ D) + (hF : ∀ (s : ι → ℝ), (∀ i, s i^2=1) → ∀ M, + F (signConjugate s M)=signConjugate s (F M)) + (hLip : ∀ M N, ‖F M-F N‖ ≤ L*‖M-N‖) + (hk : ∀ i, |(∫ g, F (goeMatrix (j/(Fintype.card ι:ℝ)) g) i i + ∂Measure.pi (fun _ : MatrixCoordinates ι => gaussianReal 0 1))-k i| ≤ ε) + (u v : EuclideanSpace ℝ ι) (hu : ‖u‖ ≤ U) (hv : ‖v‖ ≤ U) : + (Measure.pi (fun _ : MatrixCoordinates ι => gaussianReal 0 1)).real + {g | (ε*D)*U^2+t ≤ |matrixBilinear (affineRight F d e w (goeMatrix (j/(Fintype.card ι:ℝ)) g)- + diagonal (fun i => k i*d i-e i)) u v|} ≤ + 2*exp (-(Fintype.card ι:ℝ)*t^2/(π^2*((L*D+|w|+1)*(U+1)^2)^2*j)) := by + exact goe_bilinear_concentration hj (by positivity) hU (mul_nonneg hε hD) ht + (affineRight F d e w) (affineRight_sign F d e w hF) + (affineRight_lip F d e w hD hd hLip) _ + (affineRight_bias _ F d e k w hD hd (goe_entries_integrable _ F hL hLip) hk) + u v hu hv +end SKGap +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/AffineUpper.lean b/lean/OAI/Probability/SKGap/Localization/AffineUpper.lean new file mode 100644 index 0000000000000000000000000000000000000000..3e61e950fa5cf71f32fc7f48b4433076d129a8b5 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/AffineUpper.lean @@ -0,0 +1,60 @@ +import Mathlib +import OAI.Probability.SKGap.Model + +namespace OAI + +namespace SKGap.DiscreteRecurrence +open Real + +lemma affine_upper (u : ℕ→ℝ) {b r : ℝ} (hb : 0≤b) (hr : 0≤r) + (hzero : u 0≤0) (K : ℕ) + (hstep : ∀k simpa using hzero + | succ k ih => + have hi:=mul_le_mul_of_nonneg_left (ih (Nat.le_of_succ_le hk)) (by linarith : 0≤1+b) + have hp : 1≤(1+b)^(k+1) := one_le_pow₀ (by linarith) + have hrp:=mul_le_mul_of_nonneg_left hp hr + have hs:=hstep k (Nat.lt_of_succ_le hk) + simp only [Nat.cast_add,Nat.cast_one,pow_succ] at hrp ⊢ + nlinarith + have hp:=pow_le_pow_left₀ (by linarith : 0≤1+b) (by simpa only [add_comm] using Real.add_one_le_exp b) K + have hm:=mul_le_mul_of_nonneg_left hp (show 0≤(K:ℝ)*r by positivity) + rw [←Real.exp_nat_mul] at hm + simpa only [mul_comm b] using (hh K le_rfl).trans hm + +lemma affine_lower (u : ℕ→ℝ) {r b : ℝ} (hr : 0≤r) (hr1 : r≤1) (hb : 0≤b) + (K : ℕ) (hstep : ∀k simp + | succ K ih => + have hi:=mul_le_mul_of_nonneg_left (ih (fun k hk => hstep k (hk.trans (Nat.lt_succ_self K)))) hr + have hs:=hstep K (Nat.lt_succ_self K) + have hb':=mul_le_mul_of_nonneg_right hr1 (show 0≤(K:ℝ)*b by positivity) + rw [Nat.cast_add,Nat.cast_one,pow_succ] + nlinarith + +lemma exp_neg_two_le {x : ℝ} (hx : 0≤x) (hx1 : x≤1/2) : + exp (-2*x)≤1-x := by + have hpos : 0<1-x := by linarith + have hi : (1-x)⁻¹≤1+2*x := by + rw [inv_eq_one_div,div_le_iff₀ hpos] + nlinarith + have hl:=Real.one_sub_inv_le_log_of_pos hpos + have hh : -2*x≤log (1-x) := by linarith + simpa only [Real.exp_log hpos] using Real.exp_le_exp.mpr hh + +lemma pow_one_sub_lower {x : ℝ} (hx : 0≤x) (hx1 : x≤1/2) (K : ℕ) : + exp (-2*(K:ℝ)*x)≤(1-x)^K := by + have hh:=pow_le_pow_left₀ (exp_pos (-2*x)).le (exp_neg_two_le hx hx1) K + rw [←Real.exp_nat_mul] at hh + have he : (K:ℝ)*(-2*x)= -2*(K:ℝ)*x := by ring + rwa [he] at hh + +end SKGap.DiscreteRecurrence + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/Append.lean b/lean/OAI/Probability/SKGap/Localization/Append.lean new file mode 100644 index 0000000000000000000000000000000000000000..66e12d0cf9df3b1a7cf8bb41b87094761c29b97d --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/Append.lean @@ -0,0 +1,311 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.SeparateCut +import OAI.Probability.SKGap.Matrix.InverseDiagram + +namespace OAI + +section +noncomputable section +noncomputable section +open scoped BigOperators +noncomputable section +namespace SKGap.Noncrossing +namespace Diagram +variable {D E : Type*} + +def append : Diagram D → Diagram D → Diagram D + | .nil, e => e + | .diag a d, e => .diag a (d.append e) + | .arch a b, e => .arch a (b.append e) + +@[simp] lemma append_word (d e : Diagram D) : (d.append e).word = d.word ++ e.word := by + induction d with + | nil => rfl + | diag a d ih => simp [append,word,ih] + | arch a b ia ib => simp [append,word,ib,List.append_assoc] + +@[simp] lemma append_nil (d : Diagram D) : d.append .nil = d := by + induction d with + | nil => rfl + | diag a d ih => simp [append,ih] + | arch a b ia ib => simp [append,ib] + +lemma append_assoc (d e f : Diagram D) : (d.append e).append f = d.append (e.append f) := by + induction d with + | nil => rfl + | diag a d ih => simp [append,ih] + | arch a b ia ib => simp [append,ib] + +def map (f : D → E) : Diagram D → Diagram E + | .nil => .nil + | .diag a d => .diag (f a) (d.map f) + | .arch a b => .arch (a.map f) (b.map f) + +def Letter.map (f : D → E) : Letter D → Letter E + | .diag a => .diag (f a) + | .noise => .noise + +@[simp] lemma map_word (f : D → E) (d : Diagram D) : + (d.map f).word = d.word.map (Letter.map f) := by + induction d with + | nil => rfl + | diag a d ih => simp [map,word,ih,Letter.map] + | arch a b ia ib => simp [map,word,ia,ib,Letter.map] + +@[simp] lemma map_append (f : D → E) (d e : Diagram D) : + (d.append e).map f = (d.map f).append (e.map f) := by + induction d with + | nil => rfl + | diag a d ih => simp [map,append,ih] + | arch a b ia ib => simp [map,append,ib] + +lemma remove_last_diag (d : Diagram D) (F : List (Letter D)) (a : D) + (h : d.word = F ++ [.diag a]) : + ∃ e : Diagram D, e.word=F ∧ d=e.append (.diag a .nil) := by + induction d generalizing F with + | nil => simp [word] at h + | diag b d ih => + cases F with + | nil => + simp only [List.nil_append,word,List.cons.injEq] at h + obtain ⟨hb,hd⟩ := h + have hab : b=a := Letter.diag.inj hb + subst b + have he : d=.nil := by cases d <;> simp [word] at hd ⊢ + subst d + exact ⟨.nil,rfl,rfl⟩ + | cons c F => + simp only [List.cons_append,word,List.cons.injEq] at h + obtain ⟨rfl,hd⟩ := h + obtain ⟨e,he,hd⟩ := ih F hd + refine ⟨.diag b e,?_,?_⟩ + · simp [word,he] + · simp [append,hd] + | arch b d ib ih => + cases F with + | nil => simp [word] at h + | cons c F => + simp only [List.cons_append,word,List.cons.injEq] at h + obtain ⟨rfl,hd⟩ := h + have hdlen : b.word.length+1≤F.length := by + have hh := congrArg List.length hd + simp only [List.length_append,List.length_cons,List.length_nil] at hh + by_contra hc + have hef : d.word=[] := by + apply List.length_eq_zero_iff.mp + omega + rw [hef] at hd + have hlast := congrArg List.getLast? hd + simp at hlast + have he : F = b.word ++ (.noise :: F.drop (b.word.length+1)) := by + have hh := congrArg (List.take (b.word.length+1)) hd + rw [List.take_append_of_le_length (l₁ := F) (l₂ := [.diag a]) hdlen] at hh + simp only [List.take_append, + List.take_of_length_le (show b.word.length ≤ b.word.length+1 by omega), + Nat.add_sub_cancel_left, List.take_succ_cons,List.take_zero] at hh + have hb : F.take (b.word.length+1)=b.word++[.noise] := hh.symm + calc + F = F.take (b.word.length+1) ++ F.drop (b.word.length+1) := + (List.take_append_drop _ _).symm + _ = _ := by rw [hb]; simp + rw [he,List.append_assoc,List.cons_append,List.append_cancel_left_eq, + List.cons.injEq] at hd + obtain ⟨_,ht⟩ := hd + obtain ⟨e,he',hde⟩ := ih _ ht + refine ⟨.arch b e,?_,?_⟩ + · simpa [word,he'] using he.symm + · simp [append,hde] + +end Diagram +end SKGap.Noncrossing + +noncomputable section +namespace SKGap.Noncrossing +namespace Diagram +variable {D : Type*} + +@[simp] lemma append_size (d e : Diagram D) : (d.append e).size = d.size+e.size := by + induction d with + | nil => simp [append,size] + | diag a d ih => simp [append,size,ih]; omega + | arch a b ia ib => simp [append,size,ib]; omega + +lemma append_last_diag_injective (a : D) : + Function.Injective (fun d : Diagram D => d.append (.diag a .nil)) := by + intro d + induction d with + | nil => + intro e he + cases e with + | nil => rfl + | diag b e => + have ht : Diagram.nil = e.append (.diag a .nil) := (Diagram.diag.inj he).2 + have hs := congrArg size ht + simp [size] at hs + | arch b e => cases he + | diag b d ih => + intro e he + cases e with + | nil => + have ht : d.append (.diag a .nil) = Diagram.nil := (Diagram.diag.inj he).2 + have hs := congrArg size ht + simp [size] at hs + | diag c e => + obtain ⟨rfl,ht⟩ := Diagram.diag.inj he + rw [ih ht] + | arch c e => cases he + | arch b d ib ih => + intro e he + cases e with + | nil => cases he + | diag c e => cases he + | arch c e => + obtain ⟨rfl,ht⟩ := Diagram.arch.inj he + rw [ih ht] + +lemma value_append {ι : Type*} [Fintype ι] (j : ℝ) (d e : Diagram (ι→ℝ)) (i : ι) : + (d.append e).value j i = d.value j i * e.value j i := by + induction d with + | nil => simp [append,value] + | diag a d ih => simp [append,value,ih,mul_assoc] + | arch a b ia ib => simp [append,value,ib,mul_assoc] + +end Diagram +namespace InverseDiagram + +def expandBlocks (bs : List Bool) : List (Letter Bool) := + bs.flatMap (fun b => if b then [.diag true,.noise] else [.diag false]) + +@[simp] lemma expandBlocks_nil : expandBlocks [] = [] := rfl +@[simp] lemma expandBlocks_false (bs : List Bool) : + expandBlocks (false::bs) = .diag false :: expandBlocks bs := rfl +@[simp] lemma expandBlocks_true (bs : List Bool) : + expandBlocks (true::bs) = .diag true :: .noise :: expandBlocks bs := rfl +@[simp] lemma expandBlocks_append (bs cs : List Bool) : + expandBlocks (bs++cs) = expandBlocks bs ++ expandBlocks cs := by + simp [expandBlocks] + +lemma split_noise (bs : List Bool) (U V : List (Letter Bool)) + (h : expandBlocks bs = U ++ (.noise::V)) : + ∃ p q : List Bool, bs=p++(true::q) ∧ + U=expandBlocks p++[.diag true] ∧ V=expandBlocks q := by + induction bs generalizing U with + | nil => simp at h + | cons b bs ih => + cases b with + | false => + cases U with + | nil => simp at h + | cons c U => + simp only [expandBlocks_false,List.cons_append,List.cons.injEq] at h + obtain ⟨rfl,ht⟩ := h + obtain ⟨p,q,hpq,hU,hV⟩ := ih U ht + exact ⟨false::p,q,by simp [hpq],by simp [hU],hV⟩ + | true => + cases U with + | nil => simp at h + | cons c U => + simp only [expandBlocks_true,List.cons_append,List.cons.injEq] at h + obtain ⟨rfl,ht⟩ := h + cases U with + | nil => + simp only [List.nil_append,List.cons.injEq,true_and] at ht + exact ⟨[],bs,rfl,rfl,ht.symm⟩ + | cons c U => + simp only [List.cons_append,List.cons.injEq] at ht + obtain ⟨rfl,ht⟩ := ht + obtain ⟨p,q,hpq,hU,hV⟩ := ih U ht + exact ⟨true::p,q,by simp [hpq],by simp [hU],hV⟩ + +def toDiagram : InverseDiagram → Diagram Bool + | .empty => .nil + | .counterterm d => .diag false (toDiagram d) + | .arch u v => .diag true + (.arch ((toDiagram u).append (.diag true .nil)) (toDiagram v)) + +@[simp] lemma toDiagram_word (d : InverseDiagram) : + d.toDiagram.word = expandBlocks d.blocks := by + induction d with + | empty => rfl + | counterterm d ih => simp [toDiagram,Diagram.word,blocks,ih] + | arch u v iu iv => simp [toDiagram,Diagram.word,blocks,iu,iv,List.append_assoc] + +lemma toDiagram_injective : Function.Injective toDiagram := by + intro d + induction d with + | empty => intro e he; cases e <;> cases he; rfl + | counterterm d ih => + intro e he + cases e with + | empty => cases he + | counterterm e => exact congrArg counterterm (ih (Diagram.diag.inj he).2) + | arch u v => cases he + | arch u v iu iv => + intro e he + cases e with + | empty => cases he + | counterterm e => cases he + | arch x y => + have ht := Diagram.arch.inj (Diagram.diag.inj he).2 + rw [iu (Diagram.append_last_diag_injective true ht.1),iv ht.2] + +lemma toDiagram_surjective (d : Diagram Bool) (bs : List Bool) + (h : d.word=expandBlocks bs) : + ∃ e : InverseDiagram, e.blocks=bs ∧ e.toDiagram=d := by + induction hs : d.size using Nat.strong_induction_on generalizing d bs with + | h n ih => + cases bs with + | nil => + have hd : d=.nil := by cases d <;> simp [Diagram.word] at h ⊢ + subst d + exact ⟨.empty,rfl,rfl⟩ + | cons b bs => + cases b with + | false => + cases d with + | nil => simp [Diagram.word] at h + | arch u v => simp [Diagram.word] at h + | diag a d => + simp only [Diagram.word,expandBlocks_false,List.cons.injEq,Letter.diag.injEq] at h + obtain ⟨rfl,hd⟩ := h + obtain ⟨e,he,hed⟩ := ih d.size (by simp [Diagram.size] at hs; omega) d bs hd rfl + exact ⟨.counterterm e,by simp [blocks,he],by simp [toDiagram,hed]⟩ + | true => + cases d with + | nil => simp [Diagram.word] at h + | arch u v => simp [Diagram.word] at h + | diag a d => + simp only [Diagram.word,expandBlocks_true,List.cons.injEq,Letter.diag.injEq] at h + obtain ⟨rfl,hd⟩ := h + cases d with + | nil => simp [Diagram.word] at hd + | diag a d => simp [Diagram.word] at hd + | arch u v => + simp only [Diagram.word,List.cons.injEq,true_and] at hd + obtain ⟨p,q,hbs,hu,hv⟩ := split_noise bs u.word v.word hd.symm + obtain ⟨u',hu',huu⟩ := u.remove_last_diag (expandBlocks p) true hu + have hnu : u'.size hU.preimage (hT.iterate k)) + +lemma disjoint_attractionBasins [T2Space X] {p q : X} (hpq : p ≠ q) : + Disjoint (attractionBasin T p) (attractionBasin T q) := by + rw [disjoint_left] + intro x hx hy + exact hpq (tendsto_nhds_unique hx hy) + +end Basins + +theorem lyapunov_unique_fixed_point {X : Type*} [TopologicalSpace X] [CompactSpace X] + [ConnectedSpace X] [T2Space X] + (T : X → X) (hT : Continuous T) (φ : X → ℝ) (hφ : Continuous φ) + (hstrict : ∀ x, T x ≠ x → φ (T x) < φ x) + (hattract : ∀ p, T p = p → ∃ U : Set X, IsOpen U ∧ p ∈ U ∧ + U ⊆ attractionBasin T p) : ∃! p, T p = p := by + have hopen (p) (hp : T p = p) : IsOpen (attractionBasin T p) := by + obtain ⟨U, hU, hpU, hatt⟩ := hattract p hp + exact isOpen_attractionBasin T hT hU hpU hatt + have hcover (x : X) : ∃ p, T p = p ∧ x ∈ attractionBasin T p := by + let U := ⋃ p : {p // T p = p}, attractionBasin T p.val + have hU : IsOpen U := isOpen_iUnion (fun p => hopen p.val p.property) + have hfixed (p) (hp : T p = p) : p ∈ U := + mem_iUnion.mpr ⟨⟨p, hp⟩, fixed_mem_attractionBasin T hp⟩ + obtain ⟨k, hk⟩ := lyapunov_eventually_hits T hT φ hφ hstrict hU hfixed x + obtain ⟨p, hp⟩ := mem_iUnion.mp hk + exact ⟨p.val, p.property, (mem_attractionBasin_iterate_iff T p.val x k).mp hp⟩ + obtain ⟨p, hp⟩ := lyapunov_fixed_point T φ hφ hstrict + refine ⟨p, hp, fun q hq => ?_⟩ + by_contra hqp + let V := ⋃ q : {q // T q = q ∧ q ≠ p}, attractionBasin T q.val + have hV : IsOpen V := isOpen_iUnion (fun q => hopen q.val q.property.1) + have hdisj : Disjoint (attractionBasin T p) V := by + rw [disjoint_iUnion_right] + intro q + exact disjoint_attractionBasins T q.property.2.symm + have hcov : (univ : Set X) ⊆ attractionBasin T p ∪ V := by + intro x _ + obtain ⟨r, hr, hx⟩ := hcover x + by_cases he : r = p + · subst r + exact Or.inl hx + · exact Or.inr (mem_iUnion.mpr ⟨⟨r, hr, he⟩, hx⟩) + have hconn := IsPreconnected.subset_or_subset (hopen p hp) hV hdisj hcov + isPreconnected_univ + rcases hconn with hconn | hconn + · have hqp' := tendsto_nhds_unique (hconn (mem_univ q)) + (fixed_mem_attractionBasin T hq) + exact hqp hqp'.symm + · exact disjoint_left.mp hdisj (fixed_mem_attractionBasin T hp) (hconn (mem_univ p)) + +theorem local_contraction_attracts {X : Type*} [MetricSpace X] + {T : X → X} {p : X} (hp : T p = p) {K : NNReal} (hK : K < 1) + {U : Set X} (hU : U ∈ 𝓝 p) (hlip : LipschitzOnWith K T U) : + ∃ V : Set X, IsOpen V ∧ p ∈ V ∧ V ⊆ attractionBasin T p := by + obtain ⟨ε, hε, hball⟩ := Metric.mem_nhds_iff.mp hU + have hpU : p ∈ U := hball (Metric.mem_ball_self hε) + have hmaps : MapsTo T (Metric.ball p ε) (Metric.ball p ε) := by + intro x hx + have h := hlip.dist_le_mul x (hball hx) p hpU + rw [hp] at h + exact h.trans_lt ((mul_le_of_le_one_left (dist_nonneg : 0 ≤ dist x p) + (show (K:ℝ) ≤ 1 by exact_mod_cast hK.le)).trans_lt hx) + refine ⟨Metric.ball p ε, Metric.isOpen_ball, Metric.mem_ball_self hε, ?_⟩ + intro x hx + have hbd (n : ℕ) : dist (T^[n] x) p ≤ (K:ℝ)^n * dist x p := by + induction n with + | zero => simp + | succ n ih => + rw [iterate_succ_apply'] + have h := hlip.dist_le_mul (T^[n] x) (hball (hmaps.iterate n hx)) p hpU + rw [hp] at h + exact h.trans (by simpa only [pow_succ', mul_assoc] using + mul_le_mul_of_nonneg_left ih K.coe_nonneg) + have ht := (tendsto_pow_atTop_nhds_zero_of_lt_one K.coe_nonneg + (show (K:ℝ) < 1 by exact_mod_cast hK)).mul_const (dist x p) + rw [zero_mul] at ht + exact Metric.tendsto_atTop.mpr (fun δ hδ => by + obtain ⟨N, hN⟩ := eventually_atTop.mp (ht.eventually (gt_mem_nhds hδ)) + exact ⟨N, fun n hn => (hbd n).trans_lt (hN n hn)⟩) + +theorem strict_derivative_attracts {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] + {T : E → E} {p : E} {D : E →L[ℝ] E} + (hp : T p = p) (hD : HasStrictFDerivAt T D p) (hnorm : ‖D‖ < 1) : + ∃ U : Set E, IsOpen U ∧ p ∈ U ∧ U ⊆ attractionBasin T p := by + have hn : ‖D‖₊ < 1 := by exact_mod_cast hnorm + obtain ⟨K, hDK, hK⟩ := exists_between hn + obtain ⟨U, hU, hlip⟩ := hD.exists_lipschitzOnWith_of_nnnorm_lt K hDK + exact local_contraction_attracts hp hK hU hlip + +end SKGap + +noncomputable section +open Set Function Real +open scoped Topology NNReal +namespace SKGap +section GradientDescent +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] + +theorem lipschitz_gradient_remainder {φ : E → ℝ} {G : E → E} {s : Set E} + (hs : Convex ℝ s) (hgrad : ∀ x ∈ s, HasFDerivAt φ (innerSL ℝ (G x)) x) + {L : ℝ≥0} (hG : LipschitzOnWith L G s) {x y : E} (hx : x ∈ s) (hy : y ∈ s) : + |φ y - φ x - inner ℝ (G x) (y-x)| ≤ (L:ℝ)*‖y-x‖^2 := by + let d := y-x + let ℓ : ℝ →ᵃ[ℝ] E := AffineMap.lineMap x y + let f := fun t : ℝ => φ (ℓ t) - t * inner ℝ (G x) d + let f' := fun t : ℝ => inner ℝ (G (ℓ t) - G x) d + have hℓ (t : ℝ) : ℓ t = x + t • d := by + simp only [ℓ, d, AffineMap.lineMap_apply_module] + module + have hmem (t : ℝ) (ht : t ∈ Icc (0:ℝ) 1) : ℓ t ∈ s := + hs.mapsTo_lineMap hx hy ht + have hf (t : ℝ) (ht : t ∈ Icc (0:ℝ) 1) : + HasDerivWithinAt f (f' t) (Icc (0:ℝ) 1) t := by + have hd := ((hgrad (ℓ t) (hmem t ht)).comp_hasDerivAt t + AffineMap.hasDerivAt_lineMap).sub + ((hasDerivAt_id t).mul_const (inner ℝ (G x) d)) + convert! (hd.hasDerivWithinAt (s := Icc (0:ℝ) 1)) using 1 + simp only [f', innerSL_apply_apply, inner_sub_left, d, one_mul] + have hb (t : ℝ) (ht : t ∈ Ico (0:ℝ) 1) : + ‖f' t‖ ≤ (L:ℝ)*‖d‖^2 := by + have hdiff : ‖ℓ t-x‖ ≤ ‖d‖ := by + rw [hℓ, add_sub_cancel_left, norm_smul, Real.norm_eq_abs, abs_of_nonneg ht.1] + exact mul_le_of_le_one_left (norm_nonneg _) ht.2.le + have h := (hG.norm_sub_le (hmem t ⟨ht.1, ht.2.le⟩) hx).trans + (mul_le_mul_of_nonneg_left hdiff L.coe_nonneg) + calc + ‖f' t‖ ≤ ‖G (ℓ t)-G x‖*‖d‖ := norm_inner_le_norm _ _ + _ ≤ ((L:ℝ)*‖d‖)*‖d‖ := mul_le_mul_of_nonneg_right h (norm_nonneg d) + _ = _ := by ring + have h := norm_image_sub_le_of_norm_deriv_le_segment_01' hf hb + simpa only [f, ℓ, AffineMap.lineMap_apply_zero, AffineMap.lineMap_apply_one, + zero_mul, sub_zero, one_mul, Real.norm_eq_abs, d, sub_right_comm] using h + +theorem gradient_step_strict_descent {φ : E → ℝ} {G : E → E} {s : Set E} + (hs : Convex ℝ s) (hgrad : ∀ x ∈ s, HasFDerivAt φ (innerSL ℝ (G x)) x) + {L : ℝ≥0} (hG : LipschitzOnWith L G s) {ε : ℝ} (hε : 0 < ε) + (hsmall : (L:ℝ)*ε < 1) {x : E} (hx : x ∈ s) (hstep : x-ε • G x ∈ s) + (hGx : G x ≠ 0) : φ (x-ε • G x) < φ x := by + have h := (le_abs_self _).trans (lipschitz_gradient_remainder hs hgrad hG hx hstep) + have he : x-ε • G x-x = -ε • G x := by module + rw [he, inner_smul_right, real_inner_self_eq_norm_sq, + norm_smul, Real.norm_eq_abs, abs_of_neg (neg_neg_of_pos hε)] at h + have hn : 0 < ‖G x‖^2 := sq_pos_of_pos (norm_pos_iff.mpr hGx) + have hc : 0 < ε*(1-(L:ℝ)*ε)*‖G x‖^2 := by positivity + nlinarith only [h, hc] + +theorem gradient_step_derivative_sq_bound {D : E →L[ℝ] E} {c M ε : ℝ} + (_hc : 0 ≤ c) (_hM : 0 ≤ M) (hε : 0 ≤ ε) + (hcoercive : ∀ v, c*‖v‖^2 ≤ inner ℝ v (D v)) (hbound : ‖D‖ ≤ M) + (v : E) : + ‖v-ε • D v‖^2 ≤ (1-2*ε*c+ε^2*M^2)*‖v‖^2 := by + have hD : ‖D v‖ ≤ M*‖v‖ := D.le_of_opNorm_le hbound v + have hD2 : ‖D v‖^2 ≤ M^2*‖v‖^2 := by + nlinarith [norm_nonneg (D v), mul_nonneg _hM (norm_nonneg v)] + have h := mul_le_mul_of_nonneg_left (hcoercive v) (show 0 ≤ 2*ε by positivity) + have h' := mul_le_mul_of_nonneg_left hD2 (sq_nonneg ε) + rw [norm_sub_sq_real, inner_smul_right, norm_smul, Real.norm_eq_abs, + abs_of_nonneg hε] + nlinarith only [h, h'] + +end GradientDescent +end SKGap + +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/Bilinear.lean b/lean/OAI/Probability/SKGap/Localization/Bilinear.lean new file mode 100644 index 0000000000000000000000000000000000000000..e86a93d5a2601ba80b3eeb076507bc285c3d55c9 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/Bilinear.lean @@ -0,0 +1,239 @@ +import Mathlib +import OAI.Probability.SKGap.Matrix.MatrixEntryCLM +import OAI.Probability.SKGap.Gaussian.GaussianProductIntegral +import OAI.Probability.SKGap.Matrix.OpNormDiagonal +import OAI.Probability.SKGap.Gaussian.GaussianSign + +namespace OAI + +section +noncomputable section +namespace SKGap +open Matrix MeasureTheory ProbabilityTheory Real +open scoped BigOperators Matrix.Norms.Frobenius NNReal ENNReal +variable {ι : Type*} [Fintype ι] [DecidableEq ι] + +lemma operator_le_frobenius (M : Matrix ι ι ℝ) : opNorm M ≤ ‖M‖ := by + apply ContinuousLinearMap.opNorm_le_bound _ (norm_nonneg _) + intro x + have hh := Matrix.frobenius_norm_mul M (Matrix.replicateCol Unit (fun i => x i)) + rw [← Matrix.replicateCol_mulVec,Matrix.frobenius_norm_replicateCol, + Matrix.frobenius_norm_replicateCol] at hh + exact hh + +def matrixBilinear (M : Matrix ι ι ℝ) (u v : EuclideanSpace ℝ ι) : ℝ := + ∑ i, ∑ k, u i*M i k*v k + +lemma matrixBilinear_inner (M : Matrix ι ι ℝ) (u v : EuclideanSpace ℝ ι) : + matrixBilinear M u v = inner ℝ u (M.toEuclideanLin.toContinuousLinearMap v) := by + change (∑ i, ∑ k, u i*M i k*v k) = ∑ i, (∑ k, M i k*v k)*u i + simp only [Finset.sum_mul] + apply Finset.sum_congr rfl + intro i _ + apply Finset.sum_congr rfl + intro k _ + ring + +lemma matrixBilinear_abs_le (M : Matrix ι ι ℝ) (u v : EuclideanSpace ℝ ι) : + |matrixBilinear M u v| ≤ opNorm M*‖u‖*‖v‖ := by + rw [matrixBilinear_inner] + calc + _ ≤ ‖u‖*‖M.toEuclideanLin.toContinuousLinearMap v‖ := abs_real_inner_le_norm _ _ + _ ≤ ‖u‖*(opNorm M*‖v‖) := mul_le_mul_of_nonneg_left + (M.toEuclideanLin.toContinuousLinearMap.le_opNorm v) (norm_nonneg _) + _ = _ := by ring + +lemma matrixBilinear_frobenius (M : Matrix ι ι ℝ) (u v : EuclideanSpace ℝ ι) : + |matrixBilinear M u v| ≤ ‖M‖*‖u‖*‖v‖ := + (matrixBilinear_abs_le M u v).trans (mul_le_mul_of_nonneg_right + (mul_le_mul_of_nonneg_right (operator_le_frobenius M) (norm_nonneg _)) (norm_nonneg _)) + +omit [DecidableEq ι] in +lemma matrixBilinear_sub (M N : Matrix ι ι ℝ) (u v : EuclideanSpace ℝ ι) : + matrixBilinear (M-N) u v = matrixBilinear M u v-matrixBilinear N u v := by + simp only [matrixBilinear,Matrix.sub_apply,mul_sub,sub_mul,Finset.sum_sub_distrib] + +omit [DecidableEq ι] in +lemma matrixBilinear_integral {Ω : Type*} [MeasurableSpace Ω] (μ : Measure Ω) + (F : Ω → Matrix ι ι ℝ) (hF : ∀ i k, Integrable (fun x => F x i k) μ) + (u v : EuclideanSpace ℝ ι) : + (∫ x, matrixBilinear (F x) u v ∂μ) = + matrixBilinear (fun i k => ∫ x, F x i k ∂μ) u v := by + unfold matrixBilinear + rw [integral_finsetSum _ (fun i _ => integrable_finsetSum _ + (fun k _ => ((hF i k).const_mul (u i)).mul_const (v k)))] + apply Finset.sum_congr rfl + intro i _ + rw [integral_finsetSum _ (fun k _ => ((hF i k).const_mul (u i)).mul_const (v k))] + simp only [integral_mul_const,integral_const_mul] + +lemma matrixBilinear_diagonal_error {e : ι → ℝ} {ε : ℝ} (hε : 0 ≤ ε) + (he : ∀ i, |e i| ≤ ε) (u v : EuclideanSpace ℝ ι) : + |matrixBilinear (diagonal e) u v| ≤ ε*‖u‖*‖v‖ := + (matrixBilinear_abs_le _ _ _).trans (mul_le_mul_of_nonneg_right + (mul_le_mul_of_nonneg_right (opNorm_diagonal_le hε he) (norm_nonneg _)) (norm_nonneg _)) + +lemma goe_bilinear_lipschitz (r : ℝ) (F : Matrix ι ι ℝ → Matrix ι ι ℝ) + {L : ℝ} (hL : 0 ≤ L) (hF : ∀ M N, ‖F M-F N‖ ≤ L*‖M-N‖) + (u v : EuclideanSpace ℝ ι) : + LipschitzWith ⟨L*‖u‖*‖v‖*sqrt (2*r),by positivity⟩ + (fun g : EuclideanSpace ℝ (MatrixCoordinates ι) => matrixBilinear (F (goeMatrix r g)) u v) := by + apply LipschitzWith.of_dist_le_mul + intro x y + simp only [dist_eq_norm,Real.norm_eq_abs] + rw [← matrixBilinear_sub] + calc + _ ≤ ‖F (goeMatrix r x)-F (goeMatrix r y)‖*‖u‖*‖v‖ := matrixBilinear_frobenius _ _ _ + _ ≤ (L*‖goeMatrix r x-goeMatrix r y‖)*‖u‖*‖v‖ := + mul_le_mul_of_nonneg_right (mul_le_mul_of_nonneg_right (hF _ _) (norm_nonneg _)) (norm_nonneg _) + _ ≤ (L*(sqrt (2*r)*‖x-y‖))*‖u‖*‖v‖ := by + apply mul_le_mul_of_nonneg_right _ (norm_nonneg _) + apply mul_le_mul_of_nonneg_right _ (norm_nonneg _) + apply mul_le_mul_of_nonneg_left _ hL + exact (goeMatrix_L2_lipschitz r).norm_sub_le x y + _ = _ := by change _ = (L*‖u‖*‖v‖*sqrt (2*r))*‖x-y‖; ring + +end SKGap + +namespace SKGap +open MeasureTheory ProbabilityTheory Real +open scoped NNReal ENNReal +lemma gaussianProduct_tail_lipschitz {κ : Type*} [Fintype κ] + {f : (κ → ℝ) → ℝ} {L : ℝ≥0} + (hf : LipschitzWith L (fun x : EuclideanSpace ℝ κ => f x.ofLp)) + (hL : 0 < L) {u : ℝ} (hu : 0 ≤ u) : + (Measure.pi (fun _ : κ => gaussianReal 0 1)).real + {x | u ≤ |f x - ∫ y, f y ∂Measure.pi (fun _ : κ => gaussianReal 0 1)|} ≤ + 2*exp (-2*u^2/(π^2*(L:ℝ)^2)) := by + let e : (κ → ℝ) ≃ᵐ EuclideanSpace ℝ κ := MeasurableEquiv.toLp 2 _ + have hp : MeasurePreserving e (Measure.pi (fun _ : κ => gaussianReal 0 1)) + (stdGaussian (EuclideanSpace ℝ κ)) := ⟨e.measurable,map_pi_eq_stdGaussian⟩ + have hi := hp.integral_comp' (fun x : EuclideanSpace ℝ κ => f x.ofLp) + change (∫ x, f x ∂Measure.pi (fun _ : κ => gaussianReal 0 1)) = _ at hi + have h := stdGaussian_tail_lipschitz hf hL hu + rw [← hi] at h + have hs : MeasurableSet {x : EuclideanSpace ℝ κ | + u ≤ |f x.ofLp-∫ y, f y ∂Measure.pi (fun _ : κ => gaussianReal 0 1)|} := + measurableSet_le measurable_const ((hf.continuous.measurable.sub_const _).abs) + have he := congrArg ENNReal.toReal (hp.measure_preimage hs.nullMeasurableSet) + change (Measure.pi (fun _ : κ => gaussianReal 0 1)).real + {x | u ≤ |f x-∫ y, f y ∂Measure.pi (fun _ : κ => gaussianReal 0 1)|} = _ at he + rw [he] + exact h +end SKGap +end +end + +section +noncomputable section +namespace SKGap +open Matrix MeasureTheory ProbabilityTheory Real Set +open scoped BigOperators Matrix.Norms.Frobenius NNReal ENNReal +variable {ι : Type*} [Fintype ι] [DecidableEq ι] + +lemma goe_entries_integrable (r : ℝ) (F : Matrix ι ι ℝ → Matrix ι ι ℝ) + {L : ℝ} (hL : 0 ≤ L) (hF : ∀ M N, ‖F M-F N‖ ≤ L*‖M-N‖) (i k : ι) : + Integrable (fun g => F (goeMatrix r g) i k) + (Measure.pi (fun _ : MatrixCoordinates ι => gaussianReal 0 1)) := by + have hf : LipschitzWith ⟨L,hL⟩ F := by + apply LipschitzWith.of_dist_le_mul + intro M N + change ‖F M-F N‖ ≤ L*‖M-N‖ + exact hF M N + exact gaussianProduct_integrable_lipschitz ((matrixEntry_lipschitz i k).comp + (hf.comp (goeMatrix_L2_lipschitz r))) + +lemma goe_bilinear_bias (r : ℝ) (F : Matrix ι ι ℝ → Matrix ι ι ℝ) + (hF : ∀ (s : ι → ℝ), (∀ i, s i^2=1) → ∀ M, + F (signConjugate s M)=signConjugate s (F M)) + (hI : ∀ i k, Integrable (fun g => F (goeMatrix r g) i k) + (Measure.pi (fun _ : MatrixCoordinates ι => gaussianReal 0 1))) + (d : ι → ℝ) {ε : ℝ} (hε : 0 ≤ ε) + (hd : ∀ i, |(∫ g, F (goeMatrix r g) i i + ∂Measure.pi (fun _ : MatrixCoordinates ι => gaussianReal 0 1))-d i| ≤ ε) + (u v : EuclideanSpace ℝ ι) : + |(∫ g, matrixBilinear (F (goeMatrix r g)) u v + ∂Measure.pi (fun _ : MatrixCoordinates ι => gaussianReal 0 1))- + matrixBilinear (diagonal d) u v| ≤ ε*‖u‖*‖v‖ := by + let e : ι → ℝ := fun i => ∫ g, F (goeMatrix r g) i i + ∂Measure.pi (fun _ : MatrixCoordinates ι => gaussianReal 0 1) + have he : (fun i k => ∫ g, F (goeMatrix r g) i k + ∂Measure.pi (fun _ : MatrixCoordinates ι => gaussianReal 0 1)) = diagonal e := by + ext i k + by_cases hik : i=k + · subst k; simp only [diagonal_apply_eq]; rfl + · rw [diagonal_apply_ne _ hik] + exact goe_equivariant_offdiag r F hF i k hik + rw [matrixBilinear_integral _ _ hI,he,← matrixBilinear_sub,diagonal_sub] + exact matrixBilinear_diagonal_error hε hd u v + +lemma gaussianProduct_tail_from_bias {κ : Type*} [Fintype κ] + {f : (κ → ℝ) → ℝ} {L : ℝ≥0} + (hf : LipschitzWith L (fun x : EuclideanSpace ℝ κ => f x.ofLp)) + (hL : 0 < L) {a b t : ℝ} (hb : |(∫ x, f x + ∂Measure.pi (fun _ : κ => gaussianReal 0 1))-a| ≤ b) (ht : 0 ≤ t) : + (Measure.pi (fun _ : κ => gaussianReal 0 1)).real {x | b+t ≤ |f x-a|} ≤ + 2*exp (-2*t^2/(π^2*(L:ℝ)^2)) := by + let μ := Measure.pi (fun _ : κ => gaussianReal 0 1) + apply (measureReal_mono (show {x | b+t ≤ |f x-a|} ⊆ + {x | t ≤ |f x-∫ y, f y ∂μ|} from ?_)).trans (gaussianProduct_tail_lipschitz hf hL ht) + intro x hx + have hh : |f x-a| ≤ |f x-∫ y, f y ∂μ|+|(∫ y, f y ∂μ)-a| := abs_sub_le _ _ _ + change b+t ≤ |f x-a| at hx + change t ≤ |f x-∫ y, f y ∂μ| + linarith + +lemma goe_bilinear_uniform_lipschitz (r : ℝ) (F : Matrix ι ι ℝ → Matrix ι ι ℝ) + {L U : ℝ} (hL : 0 ≤ L) (hU : 0 ≤ U) (hF : ∀ M N, ‖F M-F N‖ ≤ L*‖M-N‖) + (u v : EuclideanSpace ℝ ι) (hu : ‖u‖ ≤ U) (hv : ‖v‖ ≤ U) : + LipschitzWith ⟨(L+1)*(U+1)^2*sqrt (2*r),by positivity⟩ + (fun g : EuclideanSpace ℝ (MatrixCoordinates ι) => matrixBilinear (F (goeMatrix r g)) u v) := by + apply (goe_bilinear_lipschitz r F hL hF u v).weaken + change L*‖u‖*‖v‖*sqrt (2*r) ≤ (L+1)*(U+1)^2*sqrt (2*r) + apply mul_le_mul_of_nonneg_right _ (sqrt_nonneg _) + calc + _ ≤ (L+1)*(U+1)*(U+1) := by gcongr <;> linarith + _ = _ := by ring + +lemma goe_bilinear_concentration {j L U ε t : ℝ} (hj : 0 < j) (hL : 0 ≤ L) + (hU : 0 ≤ U) (hε : 0 ≤ ε) (ht : 0 ≤ t) [Nonempty ι] + (F : Matrix ι ι ℝ → Matrix ι ι ℝ) + (hF : ∀ (s : ι → ℝ), (∀ i, s i^2=1) → ∀ M, + F (signConjugate s M)=signConjugate s (F M)) + (hLip : ∀ M N, ‖F M-F N‖ ≤ L*‖M-N‖) + (d : ι → ℝ) + (hd : ∀ i, |(∫ g, F (goeMatrix (j/(Fintype.card ι:ℝ)) g) i i + ∂Measure.pi (fun _ : MatrixCoordinates ι => gaussianReal 0 1))-d i| ≤ ε) + (u v : EuclideanSpace ℝ ι) (hu : ‖u‖ ≤ U) (hv : ‖v‖ ≤ U) : + (Measure.pi (fun _ : MatrixCoordinates ι => gaussianReal 0 1)).real + {g | ε*U^2+t ≤ |matrixBilinear (F (goeMatrix (j/(Fintype.card ι:ℝ)) g)-diagonal d) u v|} ≤ + 2*exp (-(Fintype.card ι:ℝ)*t^2/(π^2*((L+1)*(U+1)^2)^2*j)) := by + let n : ℝ := Fintype.card ι + let r := j/n + let C := (L+1)*(U+1)^2 + have hn : 0 < n := Nat.cast_pos.mpr Fintype.card_pos + have hr : 0 < r := div_pos hj hn + have hC : 0 < C := by dsimp [C]; positivity + have hCF : LipschitzWith ⟨C*sqrt (2*r),by positivity⟩ + (fun g : EuclideanSpace ℝ (MatrixCoordinates ι) => matrixBilinear (F (goeMatrix r g)) u v) := + goe_bilinear_uniform_lipschitz r F hL hU hLip u v hu hv + have hmean := goe_bilinear_bias r F hF (goe_entries_integrable r F hL hLip) d hε hd u v + have hmean' : |(∫ g, matrixBilinear (F (goeMatrix r g)) u v + ∂Measure.pi (fun _ : MatrixCoordinates ι => gaussianReal 0 1))- + matrixBilinear (diagonal d) u v| ≤ ε*U^2 := hmean.trans (by nlinarith [mul_le_mul hu hv (norm_nonneg _) hU]) + have hpos : (0:ℝ≥0) < ⟨C*sqrt (2*r),by positivity⟩ := by + change (0:ℝ) < C*sqrt (2*r) + positivity + have hp := gaussianProduct_tail_from_bias hCF hpos hmean' ht + simp only [matrixBilinear_sub] + apply hp.trans_eq + congr 2 + change -2*t^2/(π^2*(C*sqrt (2*r))^2) = -n*t^2/(π^2*C^2*j) + rw [mul_pow,sq_sqrt (by positivity : 0 ≤ 2*r)] + dsimp only [r] + field_simp +end SKGap +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/Bilinear2.lean b/lean/OAI/Probability/SKGap/Localization/Bilinear2.lean new file mode 100644 index 0000000000000000000000000000000000000000..3ac519e143d0ed2d9e892e94df9e9432db1c7ceb --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/Bilinear2.lean @@ -0,0 +1,133 @@ +import Mathlib +import OAI.Probability.SKGap.Brownian.PathAgreement + +namespace OAI + +section +noncomputable section +namespace SKGap +open Matrix MeasureTheory ProbabilityTheory Real Set Filter +open RealComplex +open scoped BigOperators Matrix.Norms.Frobenius NNReal ENNReal SchwartzMap Topology +variable {ι : Type*} [Fintype ι] [DecidableEq ι] + +def exactG (j : ℝ) (a : ι → ℝ) (M : Matrix ι ι ℝ) : Matrix ι ι ℝ := + pathDiagonal a 1*(1-pathDiagonal a 1*(M-((j/(Fintype.card ι:ℝ))*∑ b,a b) • 1)*pathDiagonal a 1)⁻¹*pathDiagonal a 1 + +def bilinearDataD (k : Fin 3) (q : ℝ) (a : ι → ℝ) : ι → ℝ := + if k=0 then a else fun i => 1+q*a i + +def bilinearDataE (k : Fin 3) : ι → ℝ := if k=1 then 1 else 0 + +def bilinearDataW (k : Fin 3) : ℝ := if k=2 then 1 else 0 + +def bilinearError (k : Fin 3) (j : ℝ) (a : ι → ℝ) (M : Matrix ι ι ℝ) : Matrix ι ι ℝ := + let q := (j/(Fintype.card ι:ℝ))*∑ b,a b + if k=0 then exactG j a M-diagonal a + else if k=1 then exactG j a M*M-q • diagonal a + else M*exactG j a M*M-q • (1:Matrix ι ι ℝ)-q^2 • diagonal a + +omit [DecidableEq ι] in +lemma bilinearData_bound [Nonempty ι] {j A : ℝ} (hj : 0 ≤ j) (hA : 0 ≤ A) {a : ι → ℝ} + (ha : ∀ i, 0 ≤ a i) (haA : ∀ i, a i ≤ A) (k : Fin 3) (i : ι) : + |bilinearDataD k ((j/(Fintype.card ι:ℝ))*∑ b,a b) a i| ≤ A+1+j*A^2 := by + have hq := diagonal_mean_bounds hj ha haA + have hq0 := hq.1 + have hai := ha i + have haAi := haA i + unfold bilinearDataD + split_ifs + · rw [abs_of_nonneg hai] + nlinarith [mul_nonneg hj (sq_nonneg A)] + · rw [abs_of_nonneg (by positivity)] + have hh := mul_le_mul hq.2 haAi hai (mul_nonneg hj hA) + nlinarith + +lemma bilinearDataW_bound (k : Fin 3) : |bilinearDataW k| ≤ 1 := by + unfold bilinearDataW + split_ifs <;> norm_num + +lemma bilinearError_agrees [Nonempty ι] (f : 𝓢(ℝ,ℂ)) {lo hi : ℝ} (hlo : 0 < lo) + (hf : ∀ x ∈ Icc lo hi, f x=(x:ℂ)⁻¹) {R : ℝ} (hR : 0 ≤ R) + (j : ℝ) {a : ι → ℝ} (ha : ∀ i, 0 ≤ a i) (M : Matrix ι ι ℝ) + (hM : Mᵀ=M) (hMR : opNorm M ≤ R) + (hl : lo ≤ ComplexSpectral.lowerRayleigh (liftMatrix + (1-pathDiagonal a 1*(M-pathShift 1 ((j/(Fintype.card ι:ℝ))*∑ b,a b))*pathDiagonal a 1))) + (hu : -hi ≤ ComplexSpectral.lowerRayleigh (-liftMatrix + (1-pathDiagonal a 1*(M-pathShift 1 ((j/(Fintype.card ι:ℝ))*∑ b,a b))*pathDiagonal a 1))) + (k : Fin 3) : + let q := (j/(Fintype.card ι:ℝ))*∑ b,a b + bilinearError k j a M=affineRight (pathFeature (decide (k=2)) f R hR j a) + (bilinearDataD k q a) (bilinearDataE k) (bilinearDataW k) M- + diagonal (fun i => (if k=2 then q else 1)*bilinearDataD k q a i-bilinearDataE k i) := by + dsimp only + have he := path_bilinear_agreement f hlo hf hR j ha M hM hMR hl hu + dsimp only at he + have hd (q : ℝ) : diagonal (fun i => q*a i)=q • diagonal a := by + ext i k; by_cases h : i=k <;> simp [h] + have hd₂ (q : ℝ) : diagonal (fun i => q*(1+q*a i))=q • (1:Matrix ι ι ℝ)+q^2 • diagonal a := by + ext i k; by_cases h : i=k + · subst k; simp only [diagonal_apply_eq,Matrix.add_apply,Matrix.smul_apply,Matrix.one_apply_eq,smul_eq_mul]; ring + · simp [h] + fin_cases k + · change exactG j a M-diagonal a=affineRight (pathK f R hR j a 1) a 0 0 M-diagonal (fun i => 1*a i-0) + simpa only [one_mul,sub_zero,exactG] using congrArg (fun Q => Q-diagonal a) he.1.symm + · change exactG j a M*M-((j/(Fintype.card ι:ℝ))*∑ b,a b) • diagonal a= + affineRight (pathK f R hR j a 1) (fun i => 1+((j/(Fintype.card ι:ℝ))*∑ b,a b)*a i) 1 0 M- + diagonal (fun i => 1*(1+((j/(Fintype.card ι:ℝ))*∑ b,a b)*a i)-1) + rw [he.2.1] + simp only [one_mul,add_sub_cancel_left,hd,exactG] + · change M*exactG j a M*M-((j/(Fintype.card ι:ℝ))*∑ b,a b) • 1- + ((j/(Fintype.card ι:ℝ))*∑ b,a b)^2 • diagonal a= + affineRight (fun Q => realProject R hR Q*pathK f R hR j a 1 Q) + (fun i => 1+((j/(Fintype.card ι:ℝ))*∑ b,a b)*a i) 0 1 M- + diagonal (fun i => ((j/(Fintype.card ι:ℝ))*∑ b,a b)*(1+((j/(Fintype.card ι:ℝ))*∑ b,a b)*a i)-0) + rw [he.2.2] + simp only [sub_zero,hd₂,exactG] + abel + +lemma path_all_good_exponential [Nonempty ι] {j A : ℝ} {a : ι → ℝ} + (hj : 0 < j) (hA0 : 0 < A) (ha : ∀ i, 0 ≤ a i) (haA : ∀ i, a i ≤ A) + (hs : sqrt j*A < 1) + (herr : 2*sqrt A*sqrt (sqrt (2*j^2*A^2/(Fintype.card ι:ℝ))) ≤ (1-sqrt j*A)^2/4) : + (Measure.pi (fun _ : MatrixCoordinates ι => gaussianReal 0 1)).real + {g | ∃ z ∈ Icc (0:ℝ) 1, g ∉ truncationGoodSet (j/(Fintype.card ι:ℝ)) + (2*sqrt j+1+1) ((1-sqrt j*A)^2/4) (2+A*(2*sqrt j+1+j*A)) + (pathDiagonal a z) (pathShift z ((j/(Fintype.card ι:ℝ))*∑ b,a b))} ≤ + 3*exp (-pathRate j A*(Fintype.card ι:ℝ)) := by + have hp := goe_path_spectral_tail hj hA0 (by norm_num : (0:ℝ)≤1) ha haA hs herr + dsimp only at hp + have he : {g | ∃ z ∈ Icc (0:ℝ) 1, g ∉ truncationGoodSet (j/(Fintype.card ι:ℝ)) + (2*sqrt j+1+1) ((1-sqrt j*A)^2/4) (2+A*(2*sqrt j+1+j*A)) + (pathDiagonal a z) (pathShift z ((j/(Fintype.card ι:ℝ))*∑ b,a b))} ⊆ + {g | ∃ z ∈ Icc (0:ℝ) 1, ¬(opNorm (goeMatrix (j/(Fintype.card ι:ℝ)) g)<2*sqrt j+1+1 ∧ + ((1-sqrt j*A)^2/2)/2 < ComplexSpectral.lowerRayleigh (liftMatrix + (stabilityMatrix a z ((j/(Fintype.card ι:ℝ))*∑ b,a b) (goeMatrix (j/(Fintype.card ι:ℝ)) g))) ∧ + -(2+A*(2*sqrt j+1+j*A)) < ComplexSpectral.lowerRayleigh (-liftMatrix + (stabilityMatrix a z ((j/(Fintype.card ι:ℝ))*∑ b,a b) (goeMatrix (j/(Fintype.card ι:ℝ)) g))))} := by + rintro g ⟨z,hz,hg⟩ + refine ⟨z,hz,?_⟩ + intro hh + apply hg + rw [stabilityMatrix_path_rep a ha hz.1] at hh + simpa only [truncationGoodSet,Set.mem_ofPred_eq,div_div,show (2:ℝ)*2=4 by norm_num] using hh + apply ((measureReal_mono he).trans hp).trans + have hn : (0:ℝ) ≤ Fintype.card ι := Nat.cast_nonneg _ + have h₁ := mul_le_mul_of_nonneg_right (min_le_left (1/(π^2*j)) + (((1-sqrt j*A)^2)^2/(16*π^2*j*A^2))) hn + have h₂ := mul_le_mul_of_nonneg_right (min_le_right (1/(π^2*j)) + (((1-sqrt j*A)^2)^2/(16*π^2*j*A^2))) hn + have he₁ : exp (-(1:ℝ)^2*(Fintype.card ι:ℝ)/(π^2*j)) ≤ exp (-pathRate j A*(Fintype.card ι:ℝ)) := by + apply exp_le_exp.mpr + change _ ≤ -min _ _ * _ + convert neg_le_neg h₁ using 1 <;> first | rfl | ring + have he₂ : exp (-((1-sqrt j*A)^2)^2*(Fintype.card ι:ℝ)/(16*π^2*j*A^2)) ≤ exp (-pathRate j A*(Fintype.card ι:ℝ)) := by + apply exp_le_exp.mpr + change _ ≤ -min _ _ * _ + convert neg_le_neg h₂ using 1 <;> first | rfl | ring + linarith +end SKGap +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/BilinearCoefficient.lean b/lean/OAI/Probability/SKGap/Localization/BilinearCoefficient.lean new file mode 100644 index 0000000000000000000000000000000000000000..eed5a6c19fa6152477963fa625047edbea5eab62 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/BilinearCoefficient.lean @@ -0,0 +1,390 @@ +import Mathlib +import OAI.Probability.SKGap.Gaussian.ReplicaTailWeight +import OAI.Probability.SKGap.Localization.ScalarVariance +import OAI.Probability.SKGap.Localization.SeparatedCard + +namespace OAI + +section +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open scoped BigOperators +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open scoped BigOperators +open scoped BigOperators NNReal ENNReal +open MeasureTheory Metric Set +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter Set +namespace SKGapCutoff.RandomMatrix + +lemma gaussian_linear_upper_tail {ι : Type*} [Fintype ι] (v : ℝ≥0) (a : ι → ℝ) + (r t : ℝ) (ht : 0 < t) : + (Measure.pi (fun _ : ι => gaussianReal 0 v)) {g | r ≤ ∑ i, a i * g i} ≤ + ENNReal.ofReal (Real.exp (v * (∑ i, a i ^ 2) * t^2 / 2 - t*r)) := by + let μ := Measure.pi (fun _ : ι => gaussianReal 0 v) + have he (g : ι → ℝ) : ∑ i, (t*a i)*g i = t * ∑ i, a i*g i := by + simp only [Finset.mul_sum]; apply Finset.sum_congr rfl; intro i _; ring + have hs : {g : ι → ℝ | r ≤ ∑ i, a i*g i} ⊆ + {g | Real.exp (t*r) ≤ Real.exp (∑ i, (t*a i)*g i)} := by + intro g hg + rw [Set.mem_ofPred_eq, he] + exact Real.exp_le_exp.mpr (mul_le_mul_of_nonneg_left hg ht.le) + refine (measure_mono hs).trans ?_ + have hh := probability_markov_real μ (fun g => Real.exp (∑ i, (t*a i)*g i)) + (integrable_exp_gaussian_linear v (fun i => t*a i)) (fun _ => (Real.exp_pos _).le) + (Real.exp (t*r)) (Real.exp_pos _) + rw [integral_exp_gaussian_linear] at hh + convert! hh using 2 + rw [← Real.exp_sub] + congr 1 + have heq : ∑ i, (t*a i)^2 = t^2 * ∑ i, a i^2 := by + simp only [mul_pow, Finset.mul_sum] + rw [heq] + ring + +lemma gaussian_linear_abs_tail {ι : Type*} [Fintype ι] (v : ℝ≥0) (a : ι → ℝ) + (r t : ℝ) (ht : 0 < t) : + (Measure.pi (fun _ : ι => gaussianReal 0 v)) {g | r ≤ |∑ i, a i * g i|} ≤ + 2 * ENNReal.ofReal (Real.exp (v * (∑ i, a i ^ 2) * t^2 / 2 - t*r)) := by + have hs : {g : ι → ℝ | r ≤ |∑ i, a i*g i|} = + {g | r ≤ ∑ i, a i*g i} ∪ {g | r ≤ ∑ i, (-a i)*g i} := by + ext g + simp only [Set.mem_ofPred_eq, Set.mem_union, neg_mul, Finset.sum_neg_distrib] + rw [le_abs] + rw [hs] + have hh := gaussian_linear_upper_tail v (fun i => -a i) r t ht + simp only [neg_sq] at hh + calc + _ ≤ _ + _ := measure_union_le _ _ + _ ≤ _ + _ := add_le_add (gaussian_linear_upper_tail v a r t ht) hh + _ = _ := by rw [two_mul] + +def bilinearCoefficient {n : ℕ} (x y : Fin n → ℝ) (p : Fin n × Fin n) : ℝ := + if p.1 < p.2 then x p.1 * y p.2 + x p.2 * y p.1 else 0 + +lemma bilinear_sampled {n : ℕ} (x y : Fin n → ℝ) (g : GaussianCoordinates n) : + ∑ i, ∑ j, x i * sampledInteraction g i j * y j = + ∑ p, bilinearCoefficient x y p * g p := by + have hp (i j : Fin n) : x i * sampledInteraction g i j * y j = + (if i < j then x i*y j*g (i,j) else 0) + + (if j < i then x i*y j*g (j,i) else 0) := by + rcases lt_trichotomy i j with h | h | h + · simp [sampledInteraction, ne_of_lt h, min_eq_left h.le, max_eq_right h.le, + h, not_lt_of_ge h.le]; ring + · subst j; simp [sampledInteraction] + · simp [sampledInteraction, ne_of_gt h, min_eq_right h.le, max_eq_left h.le, + h, not_lt_of_ge h.le]; ring + simp_rw [hp] + simp only [Finset.sum_add_distrib] + rw [Finset.sum_comm (f := fun i j => if j < i then x i*y j*g (j,i) else 0)] + rw [Fintype.sum_prod_type, ← Finset.sum_add_distrib] + apply Finset.sum_congr rfl + intro i _ + rw [← Finset.sum_add_distrib] + apply Finset.sum_congr rfl + intro j _ + by_cases h : i < j <;> simp [bilinearCoefficient, h, add_mul] + +lemma bilinearCoefficient_sq_le {n : ℕ} (x y : Fin n → ℝ) : + ∑ p, bilinearCoefficient x y p ^ 2 ≤ + 2 * (∑ i, x i^2) * (∑ i, y i^2) := by + have hp (i j : Fin n) : bilinearCoefficient x y (i,j)^2 + + bilinearCoefficient x y (j,i)^2 ≤ 2 * (x i^2*y j^2 + x j^2*y i^2) := by + rcases lt_trichotomy i j with h | h | h + · simp only [bilinearCoefficient, h, not_lt_of_ge h.le, ite_true, ite_false, zero_pow (by decide : (2:ℕ) ≠ 0), add_zero] + nlinarith [sq_nonneg (x i*y j-x j*y i)] + · subst j; simp only [bilinearCoefficient, lt_self_iff_false, ite_false, zero_pow (by decide : (2:ℕ) ≠ 0), add_zero] + positivity + · simp only [bilinearCoefficient, h, not_lt_of_ge h.le, ite_true, ite_false, zero_pow (by decide : (2:ℕ) ≠ 0), zero_add] + nlinarith [sq_nonneg (x i*y j-x j*y i)] + have hs := Finset.sum_le_sum (s := Finset.univ) (fun i _ => + Finset.sum_le_sum (s := Finset.univ) (fun j _ => hp i j)) + simp only [mul_add, Finset.sum_add_distrib] at hs + rw [Finset.sum_comm (f := fun i j => bilinearCoefficient x y (j,i)^2)] at hs + rw [Fintype.sum_prod_type] + have he : ∑ i, ∑ j, 2*(x i^2*y j^2) = 2 * (∑ i, x i^2) * (∑ j, y j^2) := by + calc + _ = 2 * (∑ i, ∑ j, x i^2*y j^2) := by simp only [Finset.mul_sum] + _ = 2 * ((∑ i, x i^2) * (∑ j, y j^2)) := by rw [Finset.sum_mul_sum] + _ = _ := by ring + have he' : ∑ i, ∑ j, 2*(x j^2*y i^2) = 2 * (∑ i, x i^2) * (∑ j, y j^2) := by + rw [Finset.sum_comm]; exact he + rw [he, he'] at hs + linarith + +lemma sampled_inner {n : ℕ} (x y : EuclideanSpace ℝ (Fin n)) (g : GaussianCoordinates n) : + inner (𝕜 := ℝ) (Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) (sampledInteraction g) x) y = + ∑ p, bilinearCoefficient y x p * g p := by + rw [real_inner_comm, Matrix.inner_toEuclideanCLM] + change (∑ i, y i * ∑ j, sampledInteraction g i j * x j) = _ + simp only [Finset.mul_sum, ← mul_assoc] + exact bilinear_sampled y x g + +lemma sampled_inner_tail (β : ℝ) {n : ℕ} (hn : 0 < n) + (x y : EuclideanSpace ℝ (Fin n)) (hx : ‖x‖ ≤ 1) (hy : ‖y‖ ≤ 1) : + disorderLaw β n {g | β^2+10 ≤ |inner (𝕜 := ℝ) + (Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) (sampledInteraction g) x) y|} ≤ + 2 * ENNReal.ofReal (Real.exp (-(10:ℝ)*n)) := by + have hnR : (0:ℝ) < n := Nat.cast_pos.mpr hn + have hcoef : ∑ p, bilinearCoefficient y x p ^ 2 ≤ 2 := by + have hh := bilinearCoefficient_sq_le y x + rw [← EuclideanSpace.real_norm_sq_eq, ← EuclideanSpace.real_norm_sq_eq] at hh + have hx2 : ‖x‖^2 ≤ 1 := by nlinarith [norm_nonneg x] + have hy2 : ‖y‖^2 ≤ 1 := by nlinarith [norm_nonneg y] + nlinarith [mul_le_mul hy2 hx2 (sq_nonneg ‖x‖) (by norm_num : (0:ℝ) ≤ 1)] + simp_rw [sampled_inner] + have hh := gaussian_linear_abs_tail (Real.toNNReal (β^2/n)) + (bilinearCoefficient y x) (β^2+10) n hnR + refine hh.trans (mul_le_mul' (le_refl 2) (ENNReal.ofReal_le_ofReal (Real.exp_le_exp.mpr ?_))) + rw [Real.coe_toNNReal _ (div_nonneg (sq_nonneg β) hnR.le)] + have hv : β^2/(n:ℝ) * (∑ p, bilinearCoefficient y x p^2) * (n:ℝ)^2 / 2 ≤ β^2*n := by + calc + _ ≤ β^2/(n:ℝ) * 2 * (n:ℝ)^2 / 2 := by gcongr + _ = _ := by field_simp + nlinarith + +lemma sampled_opNorm_tail (β : ℝ) {n : ℕ} (hn : 0 < n) : + disorderLaw β n {g | 2*(β^2+10) < ‖Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) (sampledInteraction g)‖} ≤ + ENNReal.ofReal (2 * (81:ℝ)^n * Real.exp (-(10:ℝ)*n)) := by + classical + obtain ⟨s, hb, hc, hs⟩ := unit_ball_net n + let E (x y : EuclideanSpace ℝ (Fin n)) : Set (GaussianCoordinates n) := + {g | β^2+10 ≤ |inner (𝕜 := ℝ) (Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) (sampledInteraction g) x) y|} + have hsub : {g | 2*(β^2+10) < ‖Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) (sampledInteraction g)‖} ⊆ + ⋃ x ∈ s, ⋃ y ∈ s, E x y := by + intro g hg + by_contra hnot + have hb' : ∀ x ∈ s, ∀ y ∈ s, |inner (𝕜 := ℝ) + (Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) (sampledInteraction g) x) y| ≤ β^2+10 := by + intro x hx y hy + have hh : g ∉ E x y := fun hgE => hnot (Set.mem_iUnion₂.mpr + ⟨x, hx, Set.mem_iUnion₂.mpr ⟨y, hy, hgE⟩⟩) + exact (not_le.mp hh).le + have hh := opNorm_le_of_net (Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) (sampledInteraction g)) s hb hc + (β^2+10) (by positivity) hb' + exact not_lt_of_ge hh hg + have hu : disorderLaw β n (⋃ x ∈ s, ⋃ y ∈ s, E x y) ≤ + ∑ x ∈ s, ∑ y ∈ s, disorderLaw β n (E x y) := by + refine (measure_biUnion_finset_le s _).trans ?_ + exact Finset.sum_le_sum (fun x _ => measure_biUnion_finset_le s (E x)) + refine (measure_mono hsub).trans (hu.trans ?_) + calc + _ ≤ ∑ _x ∈ s, ∑ _y ∈ s, 2 * ENNReal.ofReal (Real.exp (-(10:ℝ)*n)) := by + exact Finset.sum_le_sum (fun x hx => Finset.sum_le_sum (fun y hy => + sampled_inner_tail β hn x y (hb x hx) (hb y hy))) + _ = ENNReal.ofReal (2 * (s.card:ℝ)^2 * Real.exp (-(10:ℝ)*n)) := by + simp only [Finset.sum_const, nsmul_eq_mul] + rw [ENNReal.ofReal_mul (by positivity), ENNReal.ofReal_mul (by norm_num : (0:ℝ) ≤ 2)] + simp only [ENNReal.ofReal_ofNat, ENNReal.ofReal_pow (show (0:ℝ) ≤ s.card by positivity), ENNReal.ofReal_natCast] + ring + _ ≤ _ := ENNReal.ofReal_le_ofReal (by + have hh : (s.card : ℝ)^2 ≤ (81:ℝ)^n := by + calc + _ ≤ ((9:ℝ)^n)^2 := pow_le_pow_left₀ (by positivity) hs 2 + _ = _ := by rw [← pow_mul, mul_comm n 2, pow_mul]; norm_num + gcongr) + +lemma sampled_opNorm_tendsto (β : ℝ) : + Tendsto (fun n => disorderLaw β n {g | + 2*(β^2+10) < ‖Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) (sampledInteraction g)‖}) + atTop (nhds 0) := by + have hq : 81 * Real.exp (-10) < 1 := by + rw [Real.exp_neg, ← div_eq_mul_inv, div_lt_one (Real.exp_pos _)] + have h2 : (2:ℝ) ≤ Real.exp 1 := by linarith [Real.add_one_le_exp 1] + have hp : (81:ℝ) < (Real.exp 1)^10 := (by norm_num : (81:ℝ) < 2^10).trans_le + (pow_le_pow_left₀ (by norm_num) h2 10) + simpa only [← Real.exp_nat_mul, Nat.cast_ofNat, mul_one] using hp + have hlim : Tendsto (fun n : ℕ => 2 * (81:ℝ)^n * Real.exp (-(10:ℝ)*n)) + atTop (nhds 0) := by + have hh := (tendsto_pow_atTop_nhds_zero_of_lt_one + (by positivity : (0:ℝ) ≤ 81*Real.exp (-10)) hq).const_mul 2 + simp only [mul_zero] at hh + convert! hh using 1 + ext n + rw [mul_pow, ← Real.exp_nat_mul] + rw [show (n:ℝ)*(-10) = -(10:ℝ)*n by ring] + ring + have hlimE : Tendsto (fun n : ℕ => ENNReal.ofReal + (2 * (81:ℝ)^n * Real.exp (-(10:ℝ)*n))) atTop (nhds 0) := by + convert! ENNReal.continuous_ofReal.continuousAt.tendsto.comp hlim using 1 + simp only [ENNReal.ofReal_zero] + apply tendsto_of_tendsto_of_tendsto_of_le_of_le' tendsto_const_nhds hlimE + (Eventually.of_forall (fun _ => bot_le)) + filter_upwards [eventually_ge_atTop 1] with n hn + exact sampled_opNorm_tail β hn + +lemma gaussian_entry_tail (β : ℝ) {n : ℕ} (hn : 0 < n) (δ : ℝ) (hδ : 0 < δ) + (p : Fin n × Fin n) : + disorderLaw β n {g | δ ≤ |g p|} ≤ + 2 * ENNReal.ofReal (Real.exp (-(δ^2/(2*(β^2+1)))*(n:ℝ))) := by + have hnR : (0:ℝ) < n := Nat.cast_pos.mpr hn + have hB : 0 < β^2+1 := by positivity + have ht : 0 < δ*n/(β^2+1) := by positivity + have hh := gaussian_linear_abs_tail (Real.toNNReal (β^2/n)) (Pi.single p 1) + δ (δ*n/(β^2+1)) ht + have he (g : GaussianCoordinates n) : ∑ i, (Pi.single p (1:ℝ) : (Fin n × Fin n) → ℝ) i * g i = g p := by + simp [Pi.single_apply] + simp only [he] at hh + have hsq : ∑ i : Fin n × Fin n, ((Pi.single p (1:ℝ) : (Fin n × Fin n) → ℝ) i)^2 = 1 := by simp [Pi.single_apply] + rw [hsq, mul_one, Real.coe_toNNReal _ (div_nonneg (sq_nonneg β) hnR.le)] at hh + suffices hc : β^2/(n:ℝ) * (δ*n/(β^2+1))^2/2 - δ*n/(β^2+1)*δ ≤ + -(δ^2/(2*(β^2+1)))*(n:ℝ) from + hh.trans (mul_le_mul' (le_refl 2) (ENNReal.ofReal_le_ofReal (Real.exp_le_exp.mpr hc))) + have heq : β^2/(n:ℝ) * (δ*n/(β^2+1))^2/2 - δ*n/(β^2+1)*δ = + -(δ^2/(2*(β^2+1)))*(n:ℝ) - δ^2*n/(2*(β^2+1)^2) := by + field_simp + ring + rw [heq] + exact sub_le_self _ (by positivity) + +lemma sampled_maxEntry_tail (β : ℝ) {n : ℕ} (hn : 0 < n) (δ : ℝ) (hδ : 0 < δ) : + disorderLaw β n {g | ∃ i j, δ ≤ |sampledInteraction g i j|} ≤ + ENNReal.ofReal (2*(n:ℝ)^2 * Real.exp (-(δ^2/(2*(β^2+1)))*(n:ℝ))) := by + have hsub : {g : GaussianCoordinates n | ∃ i j, δ ≤ |sampledInteraction g i j|} ⊆ + ⋃ p : Fin n × Fin n, {g | δ ≤ |g p|} := by + intro g hg + obtain ⟨i, j, hij⟩ := hg + have hne : i ≠ j := by + intro heq; subst j + simp only [sampledInteraction_diag, abs_zero] at hij + exact (not_le_of_gt hδ) hij + exact Set.mem_iUnion.mpr ⟨(min i j, max i j), by simpa [sampledInteraction, hne] using hij⟩ + calc + _ ≤ _ := measure_mono hsub + _ ≤ ∑ p : Fin n × Fin n, disorderLaw β n {g | δ ≤ |g p|} := measure_iUnion_fintype_le _ _ + _ ≤ ∑ _p : Fin n × Fin n, 2 * ENNReal.ofReal (Real.exp (-(δ^2/(2*(β^2+1)))*(n:ℝ))) := + Finset.sum_le_sum (fun p _ => gaussian_entry_tail β hn δ hδ p) + _ = _ := by + simp only [Finset.sum_const, Finset.card_univ, Fintype.card_prod, Fintype.card_fin, nsmul_eq_mul] + rw [ENNReal.ofReal_mul (by positivity), ENNReal.ofReal_mul (by norm_num : (0:ℝ) ≤ 2)] + simp only [ENNReal.ofReal_ofNat, ENNReal.ofReal_pow (show (0:ℝ) ≤ n by positivity), + ENNReal.ofReal_natCast, Nat.cast_mul] + ring + +lemma sampled_maxEntry_tendsto (β : ℝ) (δ : ℝ) (hδ : 0 < δ) : + Tendsto (fun n => disorderLaw β n {g | ∃ i j, δ ≤ |sampledInteraction g i j|}) + atTop (nhds 0) := by + have hc : 0 < δ^2/(2*(β^2+1)) := by positivity + have hlim : Tendsto (fun n : ℕ => 2*(n:ℝ)^2 * Real.exp (-(δ^2/(2*(β^2+1)))*(n:ℝ))) + atTop (nhds 0) := by + have hh := (tendsto_rpow_mul_exp_neg_mul_atTop_nhds_zero 2 (δ^2/(2*(β^2+1))) hc).comp (tendsto_natCast_atTop_atTop : Tendsto (fun n : ℕ => (n:ℝ)) atTop atTop) + have hh' := hh.const_mul 2 + convert! hh' using 1 + · ext n; dsimp only [Function.comp_def]; rw [Real.rpow_two]; ring + · simp only [mul_zero] + have hlimE : Tendsto (fun n : ℕ => ENNReal.ofReal + (2*(n:ℝ)^2 * Real.exp (-(δ^2/(2*(β^2+1)))*(n:ℝ)))) atTop (nhds 0) := by + convert! ENNReal.continuous_ofReal.continuousAt.tendsto.comp hlim using 1 + simp only [ENNReal.ofReal_zero] + apply tendsto_of_tendsto_of_tendsto_of_le_of_le' tendsto_const_nhds hlimE + (Eventually.of_forall (fun _ => bot_le)) + filter_upwards [eventually_ge_atTop 1] with n hn + exact sampled_maxEntry_tail β hn δ hδ + +lemma matrix_column_sq_le {n : ℕ} (J : Interaction n) (j : Fin n) : + ∑ i, J i j^2 ≤ ‖Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) J‖^2 := by + let A := Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) J + let e : EuclideanSpace ℝ (Fin n) := EuclideanSpace.single j 1 + have he : ‖e‖ = 1 := by simp [e] + have hh : ‖A e‖ ≤ ‖A‖ := by simpa only [he, mul_one] using A.le_opNorm e + have hv : ‖A e‖^2 = ∑ i, J i j^2 := by + rw [EuclideanSpace.real_norm_sq_eq] + apply Finset.sum_congr rfl + intro i _ + have hi : A e i = J i j := by + change (∑ k, J i k * ((Pi.single j (1:ℝ) : Fin n → ℝ) k)) = J i j + simp [Pi.single_apply] + rw [hi] + rw [← hv] + exact pow_le_pow_left₀ (norm_nonneg _) hh 2 + +lemma matrix_bilinear_le {n : ℕ} (J : Interaction n) (a b : Fin n → ℝ) : + |∑ i, ∑ j, a i * J j i * b j| ≤ + ‖Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) J‖ / 2 * + ((∑ i, a i^2) + ∑ j, b j^2) := by + let A := Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) J + let aE : EuclideanSpace ℝ (Fin n) := WithLp.toLp 2 a + let bE : EuclideanSpace ℝ (Fin n) := WithLp.toLp 2 b + have he : (∑ i, ∑ j, a i * J j i * b j) = inner (𝕜 := ℝ) bE (A aE) := by + rw [Matrix.inner_toEuclideanCLM] + change (∑ i, ∑ j, a i * J j i * b j) = ∑ j, b j * (∑ i, J j i * a i) + rw [Finset.sum_comm] + simp only [Finset.mul_sum] + apply Finset.sum_congr rfl + intro i _ + apply Finset.sum_congr rfl + intro j _ + ring + rw [he] + have hh : |inner (𝕜 := ℝ) bE (A aE)| ≤ ‖A‖ * (‖aE‖ * ‖bE‖) := by + calc + _ ≤ ‖bE‖ * ‖A aE‖ := abs_real_inner_le_norm _ _ + _ ≤ ‖bE‖ * (‖A‖ * ‖aE‖) := mul_le_mul_of_nonneg_left (A.le_opNorm _) (norm_nonneg _) + _ = _ := by ring + have hsq : ‖aE‖ * ‖bE‖ ≤ (‖aE‖^2+‖bE‖^2)/2 := by nlinarith [sq_nonneg (‖aE‖-‖bE‖)] + have hh' := mul_le_mul_of_nonneg_left hsq (norm_nonneg A) + rw [EuclideanSpace.real_norm_sq_eq, EuclideanSpace.real_norm_sq_eq] at hh' + exact hh.trans (by simpa only [aE, bE, mul_div_assoc, div_mul_eq_mul_div] using hh') + +lemma matrix_entry_le_opNorm {n : ℕ} (J : Interaction n) (i j : Fin n) : + |J i j| ≤ ‖Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) J‖ := by + have hh : J i j^2 ≤ ‖Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) J‖^2 := by + exact (Finset.single_le_sum (f := fun i => J i j^2) (fun _ _ => sq_nonneg _) + (Finset.mem_univ i)).trans (matrix_column_sq_le J j) + exact (sq_le_sq₀ (abs_nonneg _) (norm_nonneg _)).mp (by simpa only [sq_abs] using hh) + +lemma rough_square_of_opNorm {n : ℕ} (J : Interaction n) (hJ : ∀ i j, J i j = J j i) + (C : ℝ) (hC : 0 ≤ C) (hJC : ‖Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) J‖ ≤ C) + (p : VectorFields n) (x : Spin n) : + (∑ i, 2*p x i*gradientGenerator J p x i) - generator J (vectorSquare p) x ≤ + (2*(C+4*C^2)+4*(2*Real.exp (8*C)*C^2)-2) * vectorSquare p x - vectorDissipation J p x := by + have hM (i : Fin n) : ∑ j, J j i^2 ≤ C^2 := (matrix_column_sq_le J i).trans + (pow_le_pow_left₀ (norm_nonneg _) hJC 2) + have hJB (a b : Fin n → ℝ) : |∑ i, ∑ j, a i*J j i*b j| ≤ + C/2*((∑ i, a i^2)+∑ j, b j^2) := by + exact (matrix_bilinear_le J a b).trans (by gcongr) + exact gradient_square_le J p x (C+4*C^2) (2*Real.exp (8*C)*C^2) + (influence_quadratic_le J hJ x (p x) C (C^2) hC hJB hM) + (influence_weighted_row_le J x C (C^2) (fun i j => (matrix_entry_le_opNorm J i j).trans hJC) hM) + +lemma sampled_rough_square_good (β : ℝ) : + let C := 2*(β^2+10) + Tendsto (fun n => disorderLaw β n {g | ¬ ∀ (p : VectorFields n) (x : Spin n), + (∑ i, 2*p x i*gradientGenerator (sampledInteraction g) p x i) - + generator (sampledInteraction g) (vectorSquare p) x ≤ + (2*(C+4*C^2)+4*(2*Real.exp (8*C)*C^2)-2) * vectorSquare p x - + vectorDissipation (sampledInteraction g) p x}) atTop (nhds 0) := by + dsimp only + apply tendsto_of_tendsto_of_tendsto_of_le_of_le' tendsto_const_nhds (sampled_opNorm_tendsto β) + (Eventually.of_forall (fun _ => bot_le)) + apply Eventually.of_forall + intro n + apply measure_mono + intro g hg + by_contra hnot + apply hg + exact rough_square_of_opNorm (sampledInteraction g) (sampledInteraction_symm g) + (2*(β^2+10)) (by positivity) (le_of_not_gt hnot) + +end SKGapCutoff.RandomMatrix + +open scoped BigOperators NNReal ENNReal Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Set + +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/BilinearUnion.lean b/lean/OAI/Probability/SKGap/Localization/BilinearUnion.lean new file mode 100644 index 0000000000000000000000000000000000000000..e0af37a3efe2baadf08531d54da012c938059ca0 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/BilinearUnion.lean @@ -0,0 +1,205 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.Bilinear2 + +namespace OAI + +section +noncomputable section +namespace SKGap +open Matrix MeasureTheory ProbabilityTheory Real Set Filter +open RealComplex +open scoped BigOperators Matrix.Norms.Frobenius NNReal ENNReal SchwartzMap Topology + +def bilinearPathGood {n : ℕ} (j A : ℝ) (a : Fin n → ℝ) + (g : MatrixCoordinates (Fin n) → ℝ) : Prop := + ∀ z ∈ Icc (0:ℝ) 1, g ∈ truncationGoodSet (j/(n:ℝ)) + (2*sqrt j+1+1) ((1-sqrt j*A)^2/4) (2+A*(2*sqrt j+1+j*A)) + (pathDiagonal a z) (pathShift z ((j/(n:ℝ))*∑ b,a b)) + +theorem bilinear_deterministic_equivalents {j A U ε : ℝ} + (hj : 0 < j) (hA : 0 < A) (hs : sqrt j*A < 1) + (hU : 0 ≤ U) (hε : 0 < ε) (m : ℕ) : + ∃ (c : ℝ) (N : ℕ), 0 < c ∧ 0 < N ∧ + ∀ n, N ≤ n → ∀ a : Fin n → ℝ, (∀ i, 0 ≤ a i) → (∀ i, a i ≤ A) → + ∀ v : Fin m → EuclideanSpace ℝ (Fin n), (∀ r, ‖v r‖ ≤ U) → + (Measure.pi (fun _ : MatrixCoordinates (Fin n) => gaussianReal 0 1)).real + {g | ¬bilinearPathGood j A a g ∨ ∃ r s k, + ε < |matrixBilinear (bilinearError k j a (goeMatrix (j/(n:ℝ)) g)) (v r) (v s)|} ≤ + (3+6*(m:ℝ)^2)*exp (-c*(n:ℝ)) := by + have hD : 0 ≤ A+1+j*A^2 := by positivity + obtain ⟨f,R,hR,lo,hi,c₀,N₀,hReq,hloeq,hhieq,hlo,hf,hc₀,hN₀,htail⟩ := + actual_path_affine_tail hj hA hs hD hU (by norm_num : (0:ℝ)≤1) hε + obtain ⟨N₁,hN₁⟩ := eventually_atTop.mp (path_size_eventually hs) + refine ⟨min c₀ (pathRate j A),max N₀ N₁,lt_min hc₀ (pathRate_pos hj hA hs), + hN₀.trans_le (le_max_left _ _),?_⟩ + intro n hn a ha haA v hv + have hn₀ := (le_max_left N₀ N₁).trans hn + have hn₁ := (le_max_right N₀ N₁).trans hn + have hnpos := hN₀.trans_le hn₀ + let : Nonempty (Fin n) := Fin.pos_iff_nonempty.mp hnpos + let μ := Measure.pi (fun _ : MatrixCoordinates (Fin n) => gaussianReal 0 1) + let B : Set (MatrixCoordinates (Fin n) → ℝ) := {g | ¬bilinearPathGood j A a g} + let T (p : Fin m × Fin m × Fin 3) : Set (MatrixCoordinates (Fin n) → ℝ) := + {g | ε ≤ |matrixBilinear (affineRight (pathFeature (decide (p.2.2=2)) f R hR j a) + (bilinearDataD p.2.2 ((j/(n:ℝ))*∑ b,a b) a) (bilinearDataE p.2.2) (bilinearDataW p.2.2) + (goeMatrix (j/(n:ℝ)) g)-diagonal (fun i => + (if p.2.2=2 then (j/(n:ℝ))*∑ b,a b else 1)* + bilinearDataD p.2.2 ((j/(n:ℝ))*∑ b,a b) a i-bilinearDataE p.2.2 i)) (v p.1) (v p.2.1)|} + have hb : μ.real B ≤ 3*exp (-pathRate j A*(n:ℝ)) := by + have hh := path_all_good_exponential hj hA ha haA hs (by simpa only [Fintype.card_fin] using hN₁ n hn₁) + simpa only [B,μ,bilinearPathGood,not_forall,exists_prop,Fintype.card_fin] using hh + have ht (p : Fin m × Fin m × Fin 3) : μ.real (T p) ≤ 2*exp (-c₀*(n:ℝ)) := by + have hh := htail n hn₀ a ha haA (decide (p.2.2=2)) + (bilinearDataD p.2.2 ((j/(n:ℝ))*∑ b,a b) a) (bilinearDataE p.2.2) (bilinearDataW p.2.2) + (fun i => by simpa only [Fintype.card_fin] using bilinearData_bound hj.le hA.le ha haA p.2.2 i) + (bilinearDataW_bound p.2.2) (v p.1) (v p.2.1) (hv p.1) (hv p.2.1) + simpa only [T,μ,decide_eq_true_eq] using hh + have hsub : {g | ¬bilinearPathGood j A a g ∨ ∃ r s k, + ε < |matrixBilinear (bilinearError k j a (goeMatrix (j/(n:ℝ)) g)) (v r) (v s)|} ⊆ B ∪ ⋃ p,T p := by + intro g hg + by_cases hgood : bilinearPathGood j A a g + · rcases hg with hb | ⟨r,s,k,hk⟩ + · exact (hb hgood).elim + · apply Or.inr + refine mem_iUnion.mpr ⟨(r,s,k),?_⟩ + have hg₁ := hgood 1 (by constructor <;> norm_num) + change opNorm _ < _ ∧ _ < _ ∧ _ < _ at hg₁ + have he := bilinearError_agrees f hlo hf hR j ha + (goeMatrix (j/(n:ℝ)) g) (goeMatrix_transpose _ g) + (by simpa only [hReq] using hg₁.1.le) + (by simpa only [hloeq,Fintype.card_fin] using hg₁.2.1.le) + (by simpa only [hhieq,Fintype.card_fin] using hg₁.2.2.le) k + dsimp only at he + simp only [Fintype.card_fin] at he + change ε ≤ |matrixBilinear _ (v r) (v s)| + rw [← he] + exact hk.le + · exact Or.inl hgood + have hbound := (measureReal_mono hsub (measure_ne_top _ _)).trans + ((measureReal_union_le B (⋃ p,T p)).trans (add_le_add hb + ((measureReal_iUnion_fintype_le T).trans (Finset.sum_le_sum (fun p _ => ht p))))) + simp only [Finset.sum_const,Finset.card_univ,Fintype.card_prod,Fintype.card_fin, + nsmul_eq_mul,Nat.cast_mul,Nat.cast_ofNat] at hbound + have hnr : (0:ℝ) ≤ n := Nat.cast_nonneg _ + have he₀ : exp (-c₀*(n:ℝ)) ≤ exp (-min c₀ (pathRate j A)*(n:ℝ)) := + exp_le_exp.mpr (mul_le_mul_of_nonneg_right (neg_le_neg (min_le_left _ _)) hnr) + have he₁ : exp (-pathRate j A*(n:ℝ)) ≤ exp (-min c₀ (pathRate j A)*(n:ℝ)) := + exp_le_exp.mpr (mul_le_mul_of_nonneg_right (neg_le_neg (min_le_right _ _)) hnr) + apply hbound.trans + have hh₀ := mul_le_mul_of_nonneg_left he₀ (show 0 ≤ (m:ℝ)*((m:ℝ)*3)*2 by positivity) + linarith +end SKGap +end +end + +section +noncomputable section +namespace SKGap +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius +variable {ι κ : Type*} [Fintype ι] + +def matrixPair (G : Matrix ι ι ℝ) (x y : ι → ℝ) := x ⬝ᵥ (G*ᵥy) + +lemma matrixPair_sub (G H : Matrix ι ι ℝ) (x y : ι → ℝ) : + matrixPair (G-H) x y=matrixPair G x y-matrixPair H x y := by + simp [matrixPair,Matrix.sub_mulVec,dotProduct_sub] +lemma matrixPair_smul (a : ℝ) (G : Matrix ι ι ℝ) (x y : ι → ℝ) : + matrixPair (a • G) x y=a*matrixPair G x y := by + simp [matrixPair,Matrix.smul_mulVec,smul_eq_mul] +lemma matrixPair_sub_right (G : Matrix ι ι ℝ) (x y z : ι → ℝ) : + matrixPair G x (y-z)=matrixPair G x y-matrixPair G x z := by + simp [matrixPair,Matrix.mulVec_sub,dotProduct_sub] +lemma matrixPair_sub_left (G : Matrix ι ι ℝ) (x y z : ι → ℝ) : + matrixPair G (x-y) z=matrixPair G x z-matrixPair G y z := by + simp [matrixPair,sub_dotProduct] +lemma matrixPair_smul_right (G : Matrix ι ι ℝ) (a : ℝ) (x y : ι → ℝ) : + matrixPair G x (a • y)=a*matrixPair G x y := by + simp [matrixPair,Matrix.mulVec_smul,smul_eq_mul] +lemma matrixPair_smul_left (G : Matrix ι ι ℝ) (a : ℝ) (x y : ι → ℝ) : + matrixPair G (a • x) y=a*matrixPair G x y := by + simp [matrixPair,smul_eq_mul] +lemma matrixPair_mul_right (G W : Matrix ι ι ℝ) (x y : ι → ℝ) : + matrixPair G x (W*ᵥy)=matrixPair (G*W) x y := by + simp [matrixPair,Matrix.mulVec_mulVec] +lemma matrixPair_symm {G : Matrix ι ι ℝ} (hG : Gᵀ=G) (x y : ι → ℝ) : + matrixPair G x y=matrixPair G y x := by + simpa only [hG,matrixPair] using Matrix.dotProduct_transpose_mulVec G x y +lemma matrixPair_mul_left {W : Matrix ι ι ℝ} (hW : Wᵀ=W) + (G : Matrix ι ι ℝ) (x y : ι → ℝ) : + matrixPair G (W*ᵥx) y=matrixPair (W*G) x y := by + calc + _ = (G*ᵥy) ⬝ᵥ (W*ᵥx) := dotProduct_comm _ _ + _ = x ⬝ᵥ (W*ᵥ(G*ᵥy)) := by + simpa only [hW] using Matrix.dotProduct_transpose_mulVec W (G*ᵥy) x + _ = _ := by rw [matrixPair,Matrix.mulVec_mulVec] + +def residualGramVector (B : ℝ) (W : Matrix ι ι ℝ) (u : ι → ℝ) := + (Real.sqrt B)⁻¹ • (W*ᵥu-B • u) + +lemma centered_gram_mixed (G W A : Matrix ι ι ℝ) (B : ℝ) (x u : ι → ℝ) : + matrixPair G x (residualGramVector B W u)= + (Real.sqrt B)⁻¹*(matrixPair (G*W-B • A) x u-B*matrixPair (G-A) x u) := by + simp only [residualGramVector,matrixPair_smul_right,matrixPair_sub_right, + matrixPair_mul_right,matrixPair_sub,matrixPair_smul] + ring + +lemma centered_gram_diagonal [DecidableEq ι] {G W : Matrix ι ι ℝ} (hG : Gᵀ=G) (hW : Wᵀ=W) + (A : Matrix ι ι ℝ) {B : ℝ} (hB : 0 < B) (u : ι → ℝ) (hu : u⬝ᵥu=1) : + matrixPair G (residualGramVector B W u) (residualGramVector B W u)-1= + B⁻¹*(matrixPair (W*G*W-B • 1-B^2 • A) u u- + 2*B*matrixPair (G*W-B • A) u u+B^2*matrixPair (G-A) u u) := by + have hs : (Real.sqrt B)⁻¹*(Real.sqrt B)⁻¹=B⁻¹ := by + rw [← mul_inv,← pow_two,Real.sq_sqrt hB.le] + have hx : matrixPair G (W*ᵥu) u=matrixPair (G*W) u u := by + rw [matrixPair_symm hG,matrixPair_mul_right] + simp only [residualGramVector,matrixPair_smul_left,matrixPair_smul_right, + matrixPair_sub_left,matrixPair_sub_right,matrixPair_mul_right, + matrixPair_sub,matrixPair_smul] + rw [matrixPair_mul_left hW,hx,← Matrix.mul_assoc] + have hi : matrixPair (1 : Matrix ι ι ℝ) u u=1 := by simp [matrixPair,hu] + rw [hi] + calc + _ = ((Real.sqrt B)⁻¹*(Real.sqrt B)⁻¹)* + (matrixPair (W*G*W) u u-2*B*matrixPair (G*W) u u+B^2*matrixPair G u u)-1 := by ring + _ = _ := by rw [hs]; field_simp; ring + +lemma centered_gram_mixed_bound (G W A : Matrix ι ι ℝ) {B ε : ℝ} + (hB : 0 < B) (x u : ι → ℝ) + (h0 : |matrixPair (G-A) x u| ≤ ε) + (h1 : |matrixPair (G*W-B • A) x u| ≤ ε) : + |matrixPair G x (residualGramVector B W u)| ≤ (Real.sqrt B)⁻¹*(1+B)*ε := by + rw [centered_gram_mixed G W A B x u,abs_mul,abs_of_pos (inv_pos.mpr (Real.sqrt_pos.mpr hB))] + conv_rhs => rw [mul_assoc] + apply mul_le_mul_of_nonneg_left _ (inv_nonneg.mpr (Real.sqrt_nonneg _)) + calc + _ ≤ |matrixPair (G*W-B • A) x u|+|B*matrixPair (G-A) x u| := abs_sub _ _ + _ ≤ ε+B*ε := by rw [abs_mul,abs_of_pos hB]; exact add_le_add h1 (mul_le_mul_of_nonneg_left h0 hB.le) + _ = _ := by ring + +lemma centered_gram_diagonal_bound [DecidableEq ι] {G W : Matrix ι ι ℝ} (hG : Gᵀ=G) (hW : Wᵀ=W) + (A : Matrix ι ι ℝ) {B ε : ℝ} (hB : 0 < B) (u : ι → ℝ) (hu : u⬝ᵥu=1) + (h0 : |matrixPair (G-A) u u| ≤ ε) + (h1 : |matrixPair (G*W-B • A) u u| ≤ ε) + (h2 : |matrixPair (W*G*W-B • 1-B^2 • A) u u| ≤ ε) : + |matrixPair G (residualGramVector B W u) (residualGramVector B W u)-1| ≤ + B⁻¹*(1+2*B+B^2)*ε := by + rw [centered_gram_diagonal hG hW A hB u hu,abs_mul,abs_of_pos (inv_pos.mpr hB)] + conv_rhs => rw [mul_assoc] + apply mul_le_mul_of_nonneg_left _ (inv_nonneg.mpr hB.le) + calc + _ ≤ |matrixPair (W*G*W-B • 1-B^2 • A) u u-2*B*matrixPair (G*W-B • A) u u|+ + |B^2*matrixPair (G-A) u u| := abs_add_le _ _ + _ ≤ (ε+2*B*ε)+B^2*ε := by + apply add_le_add + · apply (abs_sub _ _).trans + rw [abs_mul,abs_of_nonneg (by positivity : 0 ≤ 2*B)] + exact add_le_add h2 (mul_le_mul_of_nonneg_left h1 (by positivity)) + · rw [abs_mul,abs_of_nonneg (sq_nonneg B)] + exact mul_le_mul_of_nonneg_left h0 (sq_nonneg B) + _ = _ := by ring +end SKGap +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/BlockDegree.lean b/lean/OAI/Probability/SKGap/Localization/BlockDegree.lean new file mode 100644 index 0000000000000000000000000000000000000000..1d0139198e126a8df3fec9a216c37f0c772e7b27 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/BlockDegree.lean @@ -0,0 +1,218 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.Append + +namespace OAI + +section +noncomputable section +noncomputable section +open scoped BigOperators +noncomputable section +noncomputable section +noncomputable section +open scoped BigOperators +namespace SKGap.Noncrossing +namespace InverseDiagram + +def blockDegree (bs : List Bool) : ℕ := (bs.map (fun b => if b then 1 else 2)).sum + +def blockEnumerate : ℕ → List (List Bool) + | 0 => [[]] + | n+1 => (blockEnumerate n).map (true::·) ++ + (if n=0 then [] else (blockEnumerate (n-1)).map (false::·)) +termination_by m => m + +def Blocks (n : ℕ) := {bs : List Bool // blockDegree bs=n} + +@[simp] lemma blockDegree_nil : blockDegree []=0 := rfl +@[simp] lemma blockDegree_true (bs : List Bool) : + blockDegree (true::bs)=blockDegree bs+1 := by simp [blockDegree,add_comm] +@[simp] lemma blockDegree_false (bs : List Bool) : + blockDegree (false::bs)=blockDegree bs+2 := by simp [blockDegree,add_comm] + +lemma mem_blockEnumerate (bs : List Bool) (n : ℕ) : + bs∈blockEnumerate n ↔ blockDegree bs=n := by + induction n using Nat.strong_induction_on generalizing bs with + | h n ih => + cases n with + | zero => + cases bs with + | nil => simp [blockEnumerate] + | cons b bs => cases b <;> simp [blockEnumerate] + | succ n => + rw [blockEnumerate] + cases bs with + | nil => split_ifs <;> simp + | cons b bs => + cases b with + | true => + have ht : ((true::bs)∈(blockEnumerate n).map (true::·) ++ + (if n=0 then [] else (blockEnumerate (n-1)).map (false::·))) ↔ + bs∈blockEnumerate n := by split_ifs <;> simp + rw [ht,ih n (by omega) bs,blockDegree_true] + omega + | false => + by_cases hn : n=0 + · subst n; simp + · have hf : ((false::bs)∈(blockEnumerate n).map (true::·) ++ + (if n=0 then [] else (blockEnumerate (n-1)).map (false::·))) ↔ + bs∈blockEnumerate (n-1) := by simp [hn] + rw [hf,ih (n-1) (by omega) bs,blockDegree_false] + omega + +lemma blockEnumerate_nodup (n : ℕ) : (blockEnumerate n).Nodup := by + induction n using Nat.strong_induction_on with + | h n ih => + cases n with + | zero => simp [blockEnumerate] + | succ n => + rw [blockEnumerate,List.nodup_append] + refine ⟨(List.nodup_map_iff (by intro a b h; exact List.cons.inj h |>.2)).mpr + (ih n (by omega)),?_,?_⟩ + · split_ifs + · simp + · exact (List.nodup_map_iff (by intro a b h; exact List.cons.inj h |>.2)).mpr + (ih (n-1) (by omega)) + · split_ifs + · simp + · intro bs h1 cs h2 he + obtain ⟨p,_,rfl⟩ := List.mem_map.mp h1 + obtain ⟨q,_,rfl⟩ := List.mem_map.mp h2 + cases he + +instance blocksFintype (n : ℕ) : Fintype (Blocks n) := + Fintype.ofFinset (blockEnumerate n).toFinset (by + intro bs + simp only [List.mem_toFinset,mem_blockEnumerate]; rfl) + +def LiteralPaired (n : ℕ) := Σ bs : Blocks n, Diagram.Paired (expandBlocks bs.val) +instance literalPairedFintype (n : ℕ) : Fintype (LiteralPaired n) := + inferInstanceAs (Fintype (Σ bs : Blocks n, Diagram.Paired (expandBlocks bs.val))) + +def AtDegree (n : ℕ) := {d : InverseDiagram // d.degree=n} +instance atDegreeFintype (n : ℕ) : Fintype (AtDegree n) := + Fintype.ofFinset (enumerate n).toFinset (by + intro d + simp only [List.mem_toFinset,mem_enumerate]; rfl) + +def toLiteral {n : ℕ} (d : AtDegree n) : LiteralPaired (2*n) := + ⟨⟨d.val.blocks,by + simpa only [blockDegree,d.property] using d.val.blocks_degree⟩, + ⟨d.val.toDiagram,d.val.toDiagram_word⟩⟩ + +lemma toLiteral_bijective (n : ℕ) : Function.Bijective (@toLiteral n) := by + constructor + · intro d e he + apply Subtype.ext + apply toDiagram_injective + exact congrArg (fun z : LiteralPaired (2*n) => z.2.val) he + · intro z + obtain ⟨e,he,hed⟩ := toDiagram_surjective z.2.val z.1.val z.2.property + have hn : e.degree=n := by + have hh := e.blocks_degree + rw [he] at hh + change blockDegree z.1.val=2*e.degree at hh + rw [z.1.property] at hh + omega + use ⟨e,hn⟩ + apply Sigma.ext + · exact Subtype.ext he + · apply (Subtype.heq_iff_coe_eq (fun d => ?_)).mpr hed + change d.word=expandBlocks e.blocks ↔ d.word=expandBlocks z.1.val + rw [he] + +def literalEquiv (n : ℕ) : AtDegree n ≃ LiteralPaired (2*n) := + Equiv.ofBijective toLiteral (toLiteral_bijective n) + +lemma literal_odd_empty (n : ℕ) : IsEmpty (LiteralPaired (2*n+1)) := by + constructor + intro z + obtain ⟨e,he,hed⟩ := toDiagram_surjective z.2.val z.1.val z.2.property + have hh := e.blocks_degree + rw [he] at hh + change blockDegree z.1.val=2*e.degree at hh + rw [z.1.property] at hh + omega + +variable {ι : Type*} [Fintype ι] + +def blockLabel (j : ℝ) (a : ι→ℝ) : Bool → ι→ℝ + | true => a + | false => fun i => -(j*average a)*a i + +lemma toDiagram_value (j : ℝ) (a : ι→ℝ) (d : InverseDiagram) (i : ι) : + (d.toDiagram.map (blockLabel j a)).value j i = d.value j a i := by + induction d generalizing i with + | empty => rfl + | counterterm d ih => simp [toDiagram,Diagram.map,Diagram.value,blockLabel,value,ih] + | arch u v iu iv => + simp only [toDiagram,Diagram.map,Diagram.map_append,Diagram.value,blockLabel, + value,iv] + have hm : Diagram.mean (fun k => (u.toDiagram.map (blockLabel j a)).value j k*a k) = + average (fun k => a k*value j a u k) := by + simp only [Diagram.mean,average] + congr 1 + apply Finset.sum_congr rfl + intro k _ + rw [iu] + ring + have hv : Diagram.value j ((u.toDiagram.map (blockLabel j a)).append (.diag a .nil)) = + (fun k => (u.toDiagram.map (blockLabel j a)).value j k * a k) := by + funext k + simp only [Diagram.value_append,Diagram.value,mul_one] + rw [hv,hm] + ring + +def literalCoefficient (j : ℝ) (a : ι→ℝ) (n : ℕ) (i : ι) : ℝ := + ∑ z : LiteralPaired n, (z.2.val.map (blockLabel j a)).value j i + +lemma literalCoefficient_even (j : ℝ) (a : ι→ℝ) (n : ℕ) (i : ι) : + literalCoefficient j a (2*n) i=coefficient j a n i := by + have hh := Fintype.sum_equiv (literalEquiv n) + (fun d => value j a d.val i) + (fun z => (z.2.val.map (blockLabel j a)).value j i) + (fun d => (toDiagram_value j a d.val i).symm) + change _=literalCoefficient j a (2*n) i at hh + rw [← hh] + let : Fintype {d : InverseDiagram // d.degree=n} := atDegreeFintype n + change (∑ d : {d : InverseDiagram // d.degree=n}, value j a d.val i) = _ + have hx := Finset.sum_subtype (p := fun d : InverseDiagram => d.degree=n) + (F := atDegreeFintype n) + (enumerate n).toFinset (by + intro d; simpa only [List.mem_toFinset] using mem_enumerate d n) + (fun d => value j a d i) + exact hx.symm.trans (List.sum_toFinset _ (enumerate_nodup n)) + +lemma literalCoefficient_odd (j : ℝ) (a : ι→ℝ) (n : ℕ) (i : ι) : + literalCoefficient j a (2*n+1) i=0 := by + let := literal_odd_empty n + exact Finset.sum_eq_zero (by intro z; exact isEmptyElim z) + +theorem literalCoefficient_eq (j : ℝ) (a : ι→ℝ) (n : ℕ) (i : ι) : + literalCoefficient j a n i = if n=0 then 1 else 0 := by + obtain ⟨m,hm⟩|⟨m,hm⟩ := Nat.even_or_odd n + · have he : n=2*m := by omega + rw [he,literalCoefficient_even] + by_cases h : m=0 + · subst m; simp + · rw [coefficient_positive j a m (by omega)] + simp [h] + · have he : n=2*m+1 := by omega + rw [he,literalCoefficient_odd] + simp + +end InverseDiagram +end SKGap.Noncrossing + +noncomputable section +open scoped BigOperators + +end +end +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/BoundedIntervalFubini.lean b/lean/OAI/Probability/SKGap/Localization/BoundedIntervalFubini.lean new file mode 100644 index 0000000000000000000000000000000000000000..c0ebeaf58fb60fa0e504ec0e3fe1677b8ed7bb0f --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/BoundedIntervalFubini.lean @@ -0,0 +1,52 @@ +import Mathlib +import OAI.Probability.SKGap.Model + +namespace OAI + +section +noncomputable section +namespace SKGap +open MeasureTheory Real Set +lemma interval_product_integrable {Ω : Type*} [TopologicalSpace Ω] [MeasurableSpace Ω] + [BorelSpace Ω] [SecondCountableTopology Ω] {μ : Measure Ω} [IsFiniteMeasure μ] + {B : ℝ × Ω → ℝ} (hB : Continuous B) {D : ℝ} + (hb : ∀ t ∈ Icc (0:ℝ) 1, ∀ g, |B (t,g)| ≤ D) : + Integrable B ((volume.restrict (Ioc (0:ℝ) 1)).prod μ) := by + apply Integrable.of_bound hB.aestronglyMeasurable D + apply (Measure.ae_prod_iff_ae_ae (measurableSet_le hB.norm.measurable measurable_const)).mpr + filter_upwards [ae_restrict_mem measurableSet_Ioc] with t ht + exact ae_of_all _ (fun g => by simpa only [Real.norm_eq_abs] using hb t ⟨ht.1.le,ht.2⟩ g) + +lemma bounded_interval_mean {Ω : Type*} [TopologicalSpace Ω] [MeasurableSpace Ω] + [BorelSpace Ω] [SecondCountableTopology Ω] {μ : Measure Ω} [IsFiniteMeasure μ] + {B : ℝ × Ω → ℝ} (hB : Continuous B) {D c ε : ℝ} + (hb : ∀ t ∈ Icc (0:ℝ) 1, ∀ g, |B (t,g)| ≤ D) + (hm : ∀ t ∈ Icc (0:ℝ) 1, |(∫ g, B (t,g) ∂μ)-t*c| ≤ ε) : + Integrable (fun g => ∫ t in (0:ℝ)..1, B (t,g)) μ ∧ + |(∫ g, (∫ t in (0:ℝ)..1, B (t,g)) ∂μ)-c/2| ≤ ε := by + have hi := interval_product_integrable (μ := μ) hB hb + have hi' : Integrable (Function.uncurry (fun t g => B (t,g))) + ((volume.restrict (uIoc (0:ℝ) 1)).prod μ) := by + have he : Function.uncurry (fun t g => B (t,g)) = B := by + funext x; rcases x with ⟨t,g⟩; rfl + rw [he,uIoc_of_le (by norm_num : (0:ℝ)≤1)] + exact hi + constructor + · simpa only [intervalIntegral.integral_of_le (by norm_num : (0:ℝ)≤1)] using hi.integral_prod_right + · rw [← intervalIntegral_integral_swap hi'] + have hit : IntervalIntegrable (fun t => ∫ g, B (t,g) ∂μ) volume 0 1 := by + rw [intervalIntegrable_iff_integrableOn_Ioc_of_le (by norm_num : (0:ℝ)≤1)] + exact hi.integral_prod_left + have hid : IntervalIntegrable (fun t : ℝ => t*c) volume 0 1 := (continuous_id.mul_const c).intervalIntegrable 0 1 + have hc : (∫ t in (0:ℝ)..1, t*c)=c/2 := by rw [intervalIntegral.integral_mul_const,integral_id]; ring + rw [← hc,← intervalIntegral.integral_sub hit hid] + have hh := intervalIntegral.norm_integral_le_of_norm_le_const (a := (0:ℝ)) (b := 1) + (f := fun t => (∫ g, B (t,g) ∂μ)-t*c) (C := ε) (fun t ht => by + have ht' : t ∈ Ioc (0:ℝ) 1 := by simpa only [uIoc_of_le (by norm_num : (0:ℝ)≤1)] using ht + simpa only [Real.norm_eq_abs] using hm t ⟨ht'.1.le,ht'.2⟩) + simpa using hh +end SKGap +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/BoxChaining.lean b/lean/OAI/Probability/SKGap/Localization/BoxChaining.lean new file mode 100644 index 0000000000000000000000000000000000000000..f39fcb6e3396bca770a932345bc3853f1308f616 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/BoxChaining.lean @@ -0,0 +1,79 @@ +import Mathlib +import OAI.Probability.SKGap.Brownian.IntervalMesh +import OAI.Probability.SKGap.Localization.ChainingCore + +namespace OAI + +section +noncomputable section +namespace SKGap +open MeasureTheory ProbabilityTheory Real Set Filter +open scoped BigOperators ENNReal Topology +variable {α : Type*} [Fintype α] [DecidableEq α] + +def boxMeshEdges (k : ℕ) : Finset ((α→Fin (4^k+1))×(α→Fin (4^(k+1)+1))) := + Finset.univ.filter (fun e=>dist (boxMeshPoint (k+1) e.2) (boxMeshPoint k e.1)≤2*(1/4:ℝ)^k) + +lemma boxMesh_base_exp : (Fintype.card (α→Fin (4^0+1)):ℝ)≤exp (log 16*(Fintype.card α:ℝ)) := by + have hh : (Fintype.card (α→Fin (4^0+1)):ℝ)≤(16:ℝ)^(Fintype.card α) := by + simp only [Fintype.card_fun,Fintype.card_fin,pow_zero];norm_num + exact pow_le_pow_left₀ (by norm_num) (by norm_num) _ + apply hh.trans_eq + rw [←exp_log (by norm_num : (0:ℝ)<16),←exp_nat_mul] + simp only [log_exp] + congr 1;ring + +theorem box_chaining_probability {Ω E : Type*} [MeasurableSpace Ω] + [AddCommGroup E] [TopologicalSpace E] (μ : Measure Ω) + (p : E→ℝ) (hc : Continuous p) (hp : ∀ x y,p (x+y)≤p x+p y) + (F : (α→Icc (0:ℝ) 1)→Ω→E) (hF : ∀ ω,Continuous (fun t=>F t ω)) + {n : ℕ} (hn : 1≤n) {A B : ℝ} (hB : 0≤B) (hA : B+1≤A) + (hdim : log 16*(Fintype.card α:ℝ)≤B*(n:ℝ)) + (b : ℝ) (r : ℕ→ℝ) (hr : ∀ k,0≤r k) (hrs : Summable r) + (hb : ∀ θ,μ {ω | b

α→Fin (4^k+1)) boxMeshPoint boxMeshEdges (by + intro θ _ + refine ⟨boxMeshIndex θ,?_,boxMeshIndex_tendsto θ⟩ + intro k + simpa only [boxMeshEdges,Finset.mem_filter,Finset.mem_univ,true_and] using boxMeshIndex_increment θ k) + r hr hrs b (ENNReal.ofReal (exp (-A*(n:ℝ)))) + (fun k=>ENNReal.ofReal (exp (-A*((k:ℝ)+1)^2*(n:ℝ)))) + (fun i=>hb (boxMeshPoint 0 i)) (by + intro k e he + exact hi k _ _ (Finset.mem_filter.mp he).2) + simp only [mem_univ,true_and] at hq + apply hq.trans + have hc1 : log 2≤(1:ℝ) := by + have hh := log_le_sub_one_of_pos (by norm_num : (0:ℝ)<2) + norm_num at hh ⊢;exact hh + have hbcard : (Fintype.card (α→Fin (4^0+1)):ℝ≥0∞)≤ENNReal.ofReal (exp (B*(n:ℝ))) := by + rw [←ENNReal.ofReal_natCast] + exact ENNReal.ofReal_le_ofReal (boxMesh_base_exp.trans (exp_le_exp.mpr hdim)) + have hbcost := chaining_entropy_tail_product hn hB (by norm_num : (0:ℝ)<1) hA 0 + (m := (Fintype.card (α→Fin (4^0+1)):ℝ≥0∞)) + (q := ENNReal.ofReal (exp (-A*(n:ℝ)))) + (by simpa only [Nat.cast_zero,zero_add,mul_one] using hbcard) (by simp) + have hecard (k : ℕ) : ((boxMeshEdges (α:=α) k).card:ℝ≥0∞)≤ENNReal.ofReal (exp (B*((k:ℝ)+1)*(n:ℝ))) := by + rw [←ENNReal.ofReal_natCast] + apply ENNReal.ofReal_le_ofReal + apply (boxMesh_edges_exp k _).trans + apply exp_le_exp.mpr + have hh := mul_le_mul_of_nonneg_right hdim (by positivity : 0≤(k:ℝ)+1) + nlinarith only [hh] + have hicost := chaining_entropy_series hn hB hc1 hA + (fun k=>((boxMeshEdges (α:=α) k).card:ℝ≥0∞)) + (fun k=>ENNReal.ofReal (exp (-A*((k:ℝ)+1)^2*(n:ℝ)))) hecard (fun _=>le_rfl) + apply (add_le_add hbcost hicost).trans_eq + simp only [Nat.cast_zero,zero_add,mul_one,one_mul,neg_mul] + rw [←ENNReal.ofReal_add (exp_pos _).le (by positivity)] + congr 1;ring +end SKGap +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/BufferedComparisonBound.lean b/lean/OAI/Probability/SKGap/Localization/BufferedComparisonBound.lean new file mode 100644 index 0000000000000000000000000000000000000000..55e968cec2d744758fb0e818b15a5f5a3cbab5de --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/BufferedComparisonBound.lean @@ -0,0 +1,155 @@ +import Mathlib +import OAI.Probability.SKGap.Stability.ImplicitComparison +import OAI.Probability.SKGap.Stability.StableLiteralComparison + +namespace OAI + +section + +noncomputable section +open scoped BigOperators Matrix.Norms.Frobenius +namespace SKGapCutoff.Recipe +open SKGap.Stein Primary Static +universe u + +theorem buffered_root_comparison_weak {j K B Aroot ε c r₀ R ρ : ℝ} + (hj : 0≤j) (hK : 0≤K) (hB : 0≤B) (hA : 1≤Aroot) (hc : 0j*(1-onsager j (J b) (h b) (k+1) v-SKGap.overlap (r b))) + (c₀ b) (r b) (e b) x) ∧ + LocalUniformWeak (fun b=>{x | residualCutoff ρ j (J b) (h b) k x≠0}) P + (fun b=>literalTerminal j (J b) (h b) k (w b) (c₀ b)) ∧ + LocalUniformWeak (fun b=>{x | residualCutoff ρ j (J b) (h b) k x≠0}) P + (fun b x=>j*c₀ b x*(∑i,residual j (J b) (h b) (k+1) x i* + (Real.tanh (fld j (J b) (h b) (k+1) x i)-Real.tanh (r b i)))) := by + let η:=(1+2*j)*(1+(1+(K+3*j)/c)*(K+4*j))*(2*ρ) + have hη : 0≤η:=by dsimp [η];positivity + obtain ⟨A,hA',hh⟩:=stable_literal_comparison_weak hj hK hB hc hη himplicit k f + refine ⟨A,hA',?_⟩ + intro W C hW hC Ω n J h e P hn hJ he hevent hbad hdim hP hp hm + have hact (b) (v : Fin (n b)→ℝ) : vectorNorm ((J b).mulVec v)≤K*vectorNorm v := + (vectorNorm_matrix_mul _ v).trans (mul_le_mul_of_nonneg_right (hevent b).1 (vectorNorm_nonneg v)) + choose r hr hu hs using fun b=>stable_primary_buffer (hn b) hj hK hA hc hr₀ + (mul_nonneg (by norm_num) hρ.le) hε hAR hbuffer hR hsmall (J b) (hJ b) (h b) (hact b) (hbad b) + let E:=fun b=>{x | residualCutoff ρ j (J b) (h b) k x≠0} + have hstable : ∀b x,x∈flipNeighborhood (flipNeighborhood (E b))→ + LiteralStableAt (J b) j (fld j (J b) (h b) (k+1)) (mag j (J b) (h b) (k+1)) + (fun v=>j*(1-onsager j (J b) (h b) (k+1) v-SKGap.overlap (r b))) (r b) R η c x := by + intro b x hx + let BB:=residualDerivativeBudget j K B k+residualDerivativeBudget j K B (k+1) + have hBB : 0≤BB:=add_nonneg (residualDerivativeBudget_nonneg hK hB _) + (residualDerivativeBudget_nonneg hK hB _) + have hD₀ (v : Spin (n b)) : SKGap.opNorm (derivativeMatrix (residual j (J b) (h b) k) v)≤BB := + (residual_derivative_bound (hn b) hK hB (J b) (h b) (hevent b).1 k + (fun v l hl=>(hevent b).2.1 (h b) v l (by omega)) v).trans + (le_add_of_nonneg_right (residualDerivativeBudget_nonneg hK hB _)) + have hD₁ (v : Spin (n b)) : SKGap.opNorm (derivativeMatrix (residual j (J b) (h b) (k+1)) v)≤BB := + (residual_derivative_bound (hn b) hK hB (J b) (h b) (hevent b).1 (k+1) + (fun v l hl=>(hevent b).2.1 (h b) v l (by omega)) v).trans + (le_add_of_nonneg_left (residualDerivativeBudget_nonneg hK hB _)) + have H0:=vector_neighborhood_twice_buffer (residual j (J b) (h b) k) (E b) hBB hD₀ (hdim b) + (fun v hv=>(residualCutoff_support (hn b) hρ (J b) (h b) k v hv).1) + have H1:=vector_neighborhood_twice_buffer (residual j (J b) (h b) (k+1)) (E b) hBB hD₁ (hdim b) + (fun v hv=>(residualCutoff_support (hn b) hρ (J b) (h b) k v hv).2) + rcases hx with hx|⟨i,hx⟩ + · exact hs b k x (H0 x hx).1 (H1 x hx).1 + · have h0:=(H0 (flip x i) hx).2 i + have h1:=(H1 (flip x i) hx).2 i + simp only [flip_flip] at h0 h1 + exact hs b k x h0 h1 + obtain ⟨w,y,c₀,heq,hw⟩:=hh W C hW hC Ω n J h r e E P hn hJ he hevent hstable hP hp hm + exact ⟨r,fun b=>⟨hr b,hu b⟩,w,y,c₀,heq,hw⟩ + +end SKGapCutoff.Recipe + +end +end + +section + +noncomputable section +open scoped BigOperators +namespace SKGapCutoff.Recipe +open Primary Static SKGap.Stein Matrix +variable {n : ℕ} + + theorem literal_comparison_identity (hn : 0j*(1-onsager j J h (k+1) v-SKGap.overlap r)) c r e x) : + literalTerminal j J h k w c x= + (∑i,((fld j J h (k+1) x i-r i- + j*(1-onsager j J h (k+1) x-SKGap.overlap r)*Real.tanh (fld j J h (k+1) x i))* + f.eval (fld j J h (k+1) x i) (r i) (j*(1-onsager j J h (k+1) x-SKGap.overlap r))*e i- + j*(1-onsager j J h (k+1) x-SKGap.overlap r)* + f.dz.eval (fld j J h (k+1) x i) (r i) (j*(1-onsager j J h (k+1) x-SKGap.overlap r))*e i))+ + j*(1-SKGap.overlap r-siteMean (fun v i=>phi (fld j J h (k+1) v i) (r i) + (j*(1-onsager j J h (k+1) v-SKGap.overlap r))) x)* + (∑i,(Real.tanh (fld j J h (k+1) x i)-Real.tanh (r i))*w x i)- + j*c x*(∑i,residual j J h (k+1) x i*(Real.tanh (fld j J h (k+1) x i)-Real.tanh (r i))) := by + let z:=fld j J h (k+1) + let m:=mag j J h (k+1) + let a:=fun v=>j*(1-onsager j J h (k+1) v-SKGap.overlap r) + have hn0 : (n:ℝ)≠0:=ne_of_gt (Nat.cast_pos.mpr hn) + have ht := (literalEquations_recipe J j 1 f z m w y a c r e one_ne_zero x).mp heq + have hw := fun i=>congrFun ht.1 i + simp only [literalInitial_source J j 1 f z m y a c r e one_ne_zero x] at hw + have hy := ht.2.1.trans (literalInitial_field J j 1 f z m w y a c r e x ht.1 ht.2.2) + have hc : (n:ℝ)*c x=∑i,(f.dz.eval (z x i) (r i) (a x)*e i+ + phiZ (z x i) (r i) (a x)*(y x i-j*c x*Real.tanh (r i))) := by + calc + _ = (n:ℝ)*siteMean ((literalInitial J j 1 f z m a c r e).implicitPartial y) x := by rw [←ht.2.2] + _ = _ := ?_ + rw [siteMean,mul_div_cancel₀ _ hn0] + apply Finset.sum_congr rfl + intro i _ + exact literalInitial_partial J j 1 f z m y a c r e one_ne_zero x i + have hroot (i) : r i-h i-J.mulVec (fun q=>Real.tanh (r q)) i+ + j*(1-SKGap.overlap r)*Real.tanh (r i)=0 := by + have hh:=congrFun hr i + simp only [SKGap.tapField,SKGap.onsager,SKGap.magnetization,Pi.zero_apply] at hh + simpa only [mulVec,dotProduct] using (by linear_combination hh : + r i-h i-(∑q,J i q*Real.tanh (r q))+j*(1-SKGap.overlap r)*Real.tanh (r i)=0) + have hb : (∑i,(Real.tanh (z x i))^2)=(n:ℝ)*(1-onsager j J h (k+2) x) := by + simp only [onsager,siteMean,mag_succ,z,Finset.sum_sub_distrib,Finset.sum_const, + Finset.card_univ,Fintype.card_fin,nsmul_eq_mul,mul_one] + field_simp + ring + have hq : (∑i,(Real.tanh (r i))^2)=(n:ℝ)*SKGap.overlap r := by + simp only [SKGap.overlap,SKGap.magnetization,mul_div_cancel₀ _ hn0] + have hh:=implicit_comparison J hJ (z x) r h (m x) (w x) (y x) + (fun i=>f.eval (z x i) (r i) (a x)*e i) + (fun i=>f.dz.eval (z x i) (r i) (a x)*e i) + j (onsager j J h (k+2) x) (onsager j J h (k+1) x) (SKGap.overlap r) + (siteMean (fun v i=>phi (z v i) (r i) (a v)) x) (c x) + hroot hb hq hw (fun i=>congrFun hy i) hc + have hmag : mag j J h (k+2) x=(fun i=>Real.tanh (z x i)):=funext fun i=>mag_succ .. + simpa only [literalTerminal,Primary.residual,hmag,mag_succ,z,m,a,mul_assoc] using hh + +end SKGapCutoff.Recipe + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/BufferedFlip.lean b/lean/OAI/Probability/SKGap/Localization/BufferedFlip.lean new file mode 100644 index 0000000000000000000000000000000000000000..8cba83da3a208a4b75addab7ce5811db0e4d4939 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/BufferedFlip.lean @@ -0,0 +1,184 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.LiteralMargin +import OAI.Probability.SKGap.Stability.LiteralStableEvent + +namespace OAI + +section + +noncomputable section +open scoped BigOperators Matrix +namespace SKGapCutoff.Recipe +open SKGap Primary Static SKGap.ObservationBridge SKGap.Stein +variable {n : ℕ} + +lemma vector_column_opNorm (M : Interaction n) (k : Fin n) : + vectorNorm (fun i=>M i k)≤SKGap.opNorm M := by + apply nonneg_le_nonneg_of_sq_le_sq (norm_nonneg _) + simp only [←pow_two] + rw [vectorNorm_sq] + exact SKGap.SourceError.matrix_column_square_le M k + +lemma vector_flip_opNorm (F : VectorFields n) (x : Spin n) (k : Fin n) : + vectorNorm (F (flip x k)-F x)≤2*SKGap.opNorm (derivativeMatrix F x) := by + have H:=congrArg norm (halfDiff_column F x k) + rw [norm_smul,Real.norm_eq_abs,abs_div,abs_spin_eq_one,abs_of_pos (by norm_num : (0:ℝ)<2),norm_sub_rev] at H + have hcol:=vector_column_opNorm (derivativeMatrix F x) k + change (1/2:ℝ)*vectorNorm (F (flip x k)-F x)=vectorNorm (fun i=>derivativeMatrix F x i k) at H + linarith + +lemma vector_flip_buffer (F : VectorFields n) (x : Spin n) {B ρ : ℝ} + (hD : SKGap.opNorm (derivativeMatrix F x)≤B) + (hsmall : 2*B≤ρ*Real.sqrt (n:ℝ)) + (hF : vectorNorm (F x)≤ρ*Real.sqrt (n:ℝ)) (k : Fin n) : + vectorNorm (F (flip x k))≤(2*ρ)*Real.sqrt (n:ℝ) := by + have H : vectorNorm (F (flip x k))≤vectorNorm (F x)+vectorNorm (F (flip x k)-F x) := by + calc + _ = vectorNorm (F x+(F (flip x k)-F x)) := by congr 1;ext i;simp + _ ≤ _ := SKGap.vectorNorm_add_le _ _ + exact H.trans ((add_le_add hF ((vector_flip_opNorm F x k).trans + ((mul_le_mul_of_nonneg_left hD (by norm_num)).trans hsmall))).trans_eq (by ring)) + +lemma residualCutoff_flip_buffer (hn : 0j*(1-b y-q)) x= -j • derivativeVector b x := by + ext i + simp only [derivativeVector,WithLp.ofLp_toLp,PiLp.smul_apply,halfDiff] + ring + +lemma primary_literal_derivative_diagnostics (hn : 0j*(1-Primary.onsager j J h (k+1) v-SKGap.overlap r) + SKGap.opNorm (derivativeMatrix (fld j J h (k+1)) x)+‖derivativeVector a x‖≤T ∧ + SKGap.opNorm (derivativeMatrix (mag j J h (k+1)) x)≤T ∧ + ‖derivativeMatrix (fld j J h (k+1)) x-(primaryTree j J h x (k+1)).fieldMatrix j J‖≤C ∧ + ‖derivativeMatrix (mag j J h (k+1)) x-(primaryTree j J h x (k+1)).sourceMatrix j J‖≤C ∧ + (∑i,∑v,(derivativeMatrix (fld j J h (k+1)) x i v)^4)≤(2*C)^4 ∧ + (∑i,(derivativeMatrix (fld j J h (k+1)) x i i)^2)≤T^2 := by + dsimp only + let C:=localPrimaryBudget j K B (k+3) + have hC : 0≤C:=localPrimaryBudget_nonneg hK hB _ + have hT : C≤(1+|j|)*C := by nlinarith [abs_nonneg j] + have hh:=primary_differentiation J h x hn hK hB hop (k+1) + (fun l hl=>hformal x l (by omega)) + have hb:=(localPrimaryBudget_bounds (j:=j) hK hB (k+3) ⟨k+1,by omega⟩).1 + have hz : ShapeBound (derivativeMatrix (fld j J h (k+1)) x) C := hh.2.2.2.mono hb + have ha := onsager_derivative_bound (j:=j) J h x hn hK hB hop (k+3) + (hformal x) (show k+1≤k+3 by omega) + refine ⟨?_,(hh.2.2.1.trans hb).trans hT,?_,?_,?_,?_⟩ + · rw [auxiliary_derivative,norm_smul,Real.norm_eq_abs,abs_neg] + exact (add_le_add hz.1 (mul_le_mul_of_nonneg_left ha (abs_nonneg j))).trans_eq (by dsimp [C];ring) + · rw [(primaryTree_matrices j J h x (k+1)).2] + exact hh.1.trans hb + · rw [(primaryTree_matrices j J h x (k+1)).1] + exact hh.2.1.trans hb + · exact (fourth_sum_le hC hz).trans (by nlinarith [pow_nonneg hC 4]) + · have H:=pow_le_pow_left₀ (norm_nonneg _) (hz.2.1.trans hT) 2 + change (SKGap.diagonalSeminorm (derivativeMatrix (fld j J h (k+1)) x))^2≤((1+|j|)*C)^2 at H + simpa only [SKGap.diagonalSeminorm_sq] using H + +end SKGapCutoff.Recipe + +noncomputable section +open scoped BigOperators Matrix.Norms.Frobenius +namespace SKGapCutoff.Recipe +open Primary SKGap.Stein + +theorem stable_selected_initial_diagnostics {j K B A ε c r₀ R ρ : ℝ} + (hj : 0≤j) (hK : 0≤K) (hB : 0≤B) (hA : 1≤A) (hc : 0j*(1-Primary.onsager j J h (k+1) v-SKGap.overlap r) + LiteralEquations J j f (fld j J h (k+1)) (mag j J h (k+1)) w y a c₀ r e x ∧ + LiteralInitialDiagnostics + (literalInitial J j (Real.sqrt (n:ℝ)) f (fld j J h (k+1)) (mag j J h (k+1)) a c₀ r e) + w y (primaryTree j J h x (k+1)) x V S F (Real.exp (R/2)) := by + let η:=(1+2*j)*(1+(1+(K+3*j)/c)*(K+4*j))*(2*ρ) + let C:=localPrimaryBudget j K B (k+3) + let T:=(1+|j|)*C + have hη : 0≤η:=by dsimp [η];positivity + have hC : 0≤C:=localPrimaryBudget_nonneg hK hB _ + have hT : 0≤T:=by dsimp [T];positivity + obtain ⟨V,hV,S,hS,F,hF,hdiag⟩:=literal_initial_diagnostics j R η c T K (2*C) C f hj hc hη hT + (mul_nonneg (by norm_num) hC) himplicit + refine ⟨V,hV,S,hS,F,hF,?_⟩ + intro n hn J h hJ hop hbad hformal hdim + have hact : ∀v,vectorNorm (J.mulVec v)≤K*vectorNorm v := fun v=> + (vectorNorm_matrix_mul J v).trans (mul_le_mul_of_nonneg_right hop (vectorNorm_nonneg v)) + obtain ⟨r,hr,hu,hstable⟩:=stable_primary_buffer hn hj hK hA hc hr₀ + (mul_nonneg (by norm_num) hρ.le) hε hAR hbuffer hR hsmall J hJ h hact hbad + refine ⟨r,hr,hu,?_⟩ + intro e he + let a:Spin n→ℝ:=fun v=>j*(1-Primary.onsager j J h (k+1) v-SKGap.overlap r) + obtain ⟨w,y,c₀,heq,hd⟩:=hdiag n hn J (fld j J h (k+1)) (mag j J h (k+1)) a r e hJ hop he + refine ⟨w,y,c₀,?_⟩ + intro x hcut + have hD₀ : SKGap.opNorm (derivativeMatrix (Primary.residual j J h k) x)≤ + residualDerivativeBudget j K B k+residualDerivativeBudget j K B (k+1) := + (residual_derivative_bound hn hK hB J h hop k + (fun v l hl=>hformal v l (by omega)) x).trans + (le_add_of_nonneg_right (residualDerivativeBudget_nonneg hK hB _)) + have hD₁ : SKGap.opNorm (derivativeMatrix (Primary.residual j J h (k+1)) x)≤ + residualDerivativeBudget j K B k+residualDerivativeBudget j K B (k+1) := + (residual_derivative_bound hn hK hB J h hop (k+1) + (fun v l hl=>hformal v l (by omega)) x).trans + (le_add_of_nonneg_left (residualDerivativeBudget_nonneg hK hB _)) + have hf:=residualCutoff_flip_buffer hn hρ J h k x hcut hD₀ hD₁ hdim + obtain ⟨h0,h1⟩:=residualCutoff_support hn hρ J h k x hcut + have hρ2 : ρ*Real.sqrt (n:ℝ)≤(2*ρ)*Real.sqrt (n:ℝ) := + mul_le_mul_of_nonneg_right (by linarith) (Real.sqrt_nonneg _) + have H:=hstable k x (h0.trans hρ2) (h1.trans hρ2) + have Hf (v:Fin n):=hstable k (flip x v) (hf v).1 (hf v).2 + have hb:=primary_literal_derivative_diagnostics hn hK hB J h hop k hformal r x + change LiteralEquations J j f (fld j J h (k+1)) (mag j J h (k+1)) w y a c₀ r e x ∧ _ + exact ⟨heq x H,hd x (primaryTree j J h x (k+1)) H Hf hb.1 hb.2.1 + (primaryState_mag_bounded j J h (k+1) x) hb.2.2.1 hb.2.2.2.1 hb.2.2.2.2.1 hb.2.2.2.2.2⟩ + +end SKGapCutoff.Recipe + +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/BufferedSelectionDiagnostics.lean b/lean/OAI/Probability/SKGap/Localization/BufferedSelectionDiagnostics.lean new file mode 100644 index 0000000000000000000000000000000000000000..524fd474f1935c77c49e7e1339fa3505264368cf --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/BufferedSelectionDiagnostics.lean @@ -0,0 +1,195 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.LocalWeakBase +import OAI.Probability.SKGap.Localization.BufferedFlip + +namespace OAI + +section + +noncomputable section +open scoped BigOperators Matrix.Norms.Frobenius +namespace SKGapCutoff.Recipe +open SKGap.Stein Primary Static +variable {n : ℕ} + +lemma vector_flip_additive (F : VectorFields n) (x : Spin n) (k : Fin n) {B : ℝ} + (hD : SKGap.opNorm (derivativeMatrix F x)≤B) : + vectorNorm (F (flip x k))≤vectorNorm (F x)+2*B := by + have H : vectorNorm (F (flip x k))≤vectorNorm (F x)+vectorNorm (F (flip x k)-F x) := by + calc + _ = vectorNorm (F x+(F (flip x k)-F x)) := by congr 1;ext i;simp + _ ≤ _ := SKGap.vectorNorm_add_le _ _ + have H' := (vector_flip_opNorm F x k).trans + (mul_le_mul_of_nonneg_left hD (by norm_num : (0:ℝ)≤2)) + linarith + +lemma vector_neighborhood_twice_buffer (F : VectorFields n) (E : Set (Spin n)) + {B ρ : ℝ} (hB : 0≤B) (hD : ∀x,SKGap.opNorm (derivativeMatrix F x)≤B) + (hsmall : 4*B≤ρ*Real.sqrt (n:ℝ)) + (hF : ∀x∈E,vectorNorm (F x)≤ρ*Real.sqrt (n:ℝ)) (x : Spin n) + (hx : x∈flipNeighborhood E) : + vectorNorm (F x)≤(2*ρ)*Real.sqrt (n:ℝ) ∧ + ∀k,vectorNorm (F (flip x k))≤(2*ρ)*Real.sqrt (n:ℝ) := by + have hbase : vectorNorm (F x)≤ρ*Real.sqrt (n:ℝ)+2*B := by + rcases hx with hx|⟨k,hk⟩ + · exact (hF x hx).trans (le_add_of_nonneg_right (by positivity)) + · have H:=vector_flip_additive F (flip x k) k (hD (flip x k)) + simp only [flip_flip] at H + have H' := hF _ hk + linarith + refine ⟨by linarith,?_⟩ + intro k + have H:=vector_flip_additive F x k (hD x) + linarith + +theorem buffered_selected_initial_diagnostics {j K B A ε c r₀ R ρ : ℝ} + (hj : 0≤j) (hK : 0≤K) (hB : 0≤B) (hA : 1≤A) (hc : 0j*(1-Primary.onsager j J h (k+1) v-SKGap.overlap r) + LiteralEquations J j f (fld j J h (k+1)) (mag j J h (k+1)) w y a c₀ r e x ∧ + LiteralInitialDiagnostics + (literalInitial J j (Real.sqrt (n:ℝ)) f (fld j J h (k+1)) (mag j J h (k+1)) a c₀ r e) + w y (primaryTree j J h x (k+1)) x V S F (Real.exp (R/2)) := by + let η:=(1+2*j)*(1+(1+(K+3*j)/c)*(K+4*j))*(2*ρ) + let C:=localPrimaryBudget j K B (k+3) + let T:=(1+|j|)*C + have hη : 0≤η:=by dsimp [η];positivity + have hC : 0≤C:=localPrimaryBudget_nonneg hK hB _ + have hT : 0≤T:=by dsimp [T];positivity + obtain ⟨V,hV,S,hS,F,hF,hdiag⟩:=literal_initial_diagnostics j R η c T K (2*C) C f hj hc hη hT + (mul_nonneg (by norm_num) hC) himplicit + refine ⟨V,hV,S,hS,F,hF,?_⟩ + intro n hn J h hJ hop hbad hformal hdim + have hact : ∀v,vectorNorm (J.mulVec v)≤K*vectorNorm v := fun v=> + (vectorNorm_matrix_mul J v).trans (mul_le_mul_of_nonneg_right hop (vectorNorm_nonneg v)) + obtain ⟨r,hr,hu,hstable⟩:=stable_primary_buffer hn hj hK hA hc hr₀ + (mul_nonneg (by norm_num) hρ.le) hε hAR hbuffer hR hsmall J hJ h hact hbad + refine ⟨r,hr,hu,?_⟩ + intro e he + let a:Spin n→ℝ:=fun v=>j*(1-Primary.onsager j J h (k+1) v-SKGap.overlap r) + obtain ⟨w,y,c₀,heq,hd⟩:=hdiag n hn J (fld j J h (k+1)) (mag j J h (k+1)) a r e hJ hop he + refine ⟨w,y,c₀,?_⟩ + intro x hx + let BB:=residualDerivativeBudget j K B k+residualDerivativeBudget j K B (k+1) + have hBB : 0≤BB:=add_nonneg (residualDerivativeBudget_nonneg hK hB _) + (residualDerivativeBudget_nonneg hK hB _) + have hD₀ (v : Spin n) : SKGap.opNorm (derivativeMatrix (Primary.residual j J h k) v)≤BB := + (residual_derivative_bound hn hK hB J h hop k + (fun v l hl=>hformal v l (by omega)) v).trans + (le_add_of_nonneg_right (residualDerivativeBudget_nonneg hK hB _)) + have hD₁ (v : Spin n) : SKGap.opNorm (derivativeMatrix (Primary.residual j J h (k+1)) v)≤BB := + (residual_derivative_bound hn hK hB J h hop (k+1) + (fun v l hl=>hformal v l (by omega)) v).trans + (le_add_of_nonneg_left (residualDerivativeBudget_nonneg hK hB _)) + have H0:=vector_neighborhood_twice_buffer (Primary.residual j J h k) + {v | residualCutoff ρ j J h k v≠0} hBB hD₀ hdim + (fun v hv=>(residualCutoff_support hn hρ J h k v hv).1) x hx + have H1:=vector_neighborhood_twice_buffer (Primary.residual j J h (k+1)) + {v | residualCutoff ρ j J h k v≠0} hBB hD₁ hdim + (fun v hv=>(residualCutoff_support hn hρ J h k v hv).2) x hx + have H:=hstable k x H0.1 H1.1 + have Hf (v:Fin n):=hstable k (flip x v) (H0.2 v) (H1.2 v) + have hb:=primary_literal_derivative_diagnostics hn hK hB J h hop k hformal r x + change LiteralEquations J j f (fld j J h (k+1)) (mag j J h (k+1)) w y a c₀ r e x ∧ _ + exact ⟨heq x H,hd x (primaryTree j J h x (k+1)) H Hf hb.1 hb.2.1 + (primaryState_mag_bounded j J h (k+1) x) hb.2.2.1 hb.2.2.2.1 hb.2.2.2.2.1 hb.2.2.2.2.2⟩ + +end SKGapCutoff.Recipe + +end +end + +section + +noncomputable section +open scoped BigOperators +namespace SKGapCutoff.Recipe +open SKGap.Stein Primary +variable {n : ℕ} + +def literalCoefficientBudget (f : KernelExpr) (j R B : ℝ) : ℝ := + 1+|initialRegularBudget f j R B|+f.mass*Real.exp (R/2)+ + (1+|j| *|B|)*phiExpr.mass*Real.exp (R/2) + +lemma literalInitial_coefficientClass (J : Interaction n) (j d : ℝ) (f : KernelExpr) + (z m : VectorFields n) (a c : Spin n→ℝ) (r e : Fin n→ℝ) (x : Spin n) + {R B : ℝ} (hB : 0≤B) (ha : |a x|≤R) (haf : ∀k,|a (flip x k)|≤R) + (hc : |d*c x|≤B) (hcf : ∀k,|d*c (flip x k)|≤B) (N : ℕ) : + (literalInitial J j d f z m a c r e).CoefficientClass N x + (literalCoefficientBudget f j R B) := by + let D:=literalInitial J j d f z m a c r e + let K:=literalCoefficientBudget f j R B + have hreg:=literalInitial_regular J j d f z m a c r e x hB ha haf hc hcf + have h1 : 1≤K := by + have h2 : 0≤f.mass*Real.exp (R/2):=mul_nonneg f.mass_nonneg (Real.exp_pos _).le + have h3 : 0≤(1+|j| *|B|)*phiExpr.mass*Real.exp (R/2):=by positivity [phiExpr.mass_nonneg] + dsimp [K,literalCoefficientBudget];linarith [abs_nonneg (initialRegularBudget f j R B)] + have hR : initialRegularBudget f j R B≤K := by + have h0:=le_abs_self (initialRegularBudget f j R B) + have h2 : 0≤f.mass*Real.exp (R/2):=mul_nonneg f.mass_nonneg (Real.exp_pos _).le + have h3 : 0≤(1+|j| *|B|)*phiExpr.mass*Real.exp (R/2):=by positivity [phiExpr.mass_nonneg] + dsimp [K,literalCoefficientBudget];linarith + have hF : f.mass*Real.exp (R/2)≤K := by + have h3 : 0≤(1+|j| *|B|)*phiExpr.mass*Real.exp (R/2):=by positivity [phiExpr.mass_nonneg] + dsimp [K,literalCoefficientBudget];linarith [abs_nonneg (initialRegularBudget f j R B)] + have hP : phiExpr.mass*Real.exp (R/2)≤K := by + have h2 : 0≤f.mass*Real.exp (R/2):=mul_nonneg f.mass_nonneg (Real.exp_pos _).le + have h3 : 0≤|j| *|B| *(phiExpr.mass*Real.exp (R/2)):=by positivity [phiExpr.mass_nonneg] + dsimp [K,literalCoefficientBudget];nlinarith [abs_nonneg (initialRegularBudget f j R B)] + have hJP : |j| *B*(phiExpr.mass*Real.exp (R/2))≤K := by + have h2 : 0≤f.mass*Real.exp (R/2):=mul_nonneg f.mass_nonneg (Real.exp_pos _).le + have h3 : 0≤phiExpr.mass*Real.exp (R/2):=by positivity [phiExpr.mass_nonneg] + dsimp [K,literalCoefficientBudget];rw [abs_of_nonneg hB] + nlinarith [abs_nonneg (initialRegularBudget f j R B)] + refine ⟨h1,?_,?_,?_,?_⟩ + · intro q hq b + simpa only [D,literalInitial] using (hreg.1 b).mono hR + · intro q hq b + simpa only [D,literalInitial] using hreg.2.mono hR + · intro q hq b i k t ht + cases b + · exact (initialKernel_segment_value f D.H D.θ x r R ha haf i k t ht).trans hF + · change |(-j)*(_)*initialKernel phiExpr (r i) _|≤K + rw [abs_mul,abs_mul,abs_neg] + exact (mul_le_mul (mul_le_mul_of_nonneg_left + (parameter_segment_value D.H D.θ x true hc hcf i k t ht) (abs_nonneg _)) + (initialKernel_segment_value phiExpr D.H D.θ x r R ha haf i k t ht) + (abs_nonneg _) (mul_nonneg (abs_nonneg _) hB)).trans hJP + · intro q hq b i k t ht + exact (initialKernel_segment_value phiExpr D.H D.θ x r R ha haf i k t ht).trans hP + +lemma literalInitial_seed_bound (J : Interaction n) (j : ℝ) (f : KernelExpr) + (z m : VectorFields n) (a c : Spin n→ℝ) (r e : Fin n→ℝ) + (hn : 0Real.tanh (r i)/Real.sqrt (n:ℝ))≤1 := by + have hv:=vectorNorm_tanh r + have hscale : (fun i=>Real.tanh (r i)/Real.sqrt (n:ℝ))= + (Real.sqrt (n:ℝ))⁻¹ • (fun i=>Real.tanh (r i)):=by ext i;simp [div_eq_mul_inv,mul_comm] + rw [hscale,vectorNorm_smul,abs_of_nonneg (inv_nonneg.mpr hd.le)] + calc + _ ≤ (Real.sqrt (n:ℝ))⁻¹*Real.sqrt (n:ℝ) := mul_le_mul_of_nonneg_left hv (inv_nonneg.mpr hd.le) + _ = 1 := inv_mul_cancel₀ hd.ne' + simp only [Fintype.sum_bool,literalInitial,Bool.false_eq_true,↓reduceIte] + change vectorNorm (fun i=>Real.tanh (r i)/Real.sqrt (n:ℝ))+vectorNorm e≤2 + linarith +end SKGapCutoff.Recipe + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/Centered.lean b/lean/OAI/Probability/SKGap/Localization/Centered.lean new file mode 100644 index 0000000000000000000000000000000000000000..118764564f175027eae0d1d505b9b14a97ff3eaa --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/Centered.lean @@ -0,0 +1,151 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.ScalarEigenfunction + +namespace OAI + +section +open scoped BigOperators +namespace SKGapCutoff + +noncomputable def centered {n : ℕ} (J : Interaction n) (f : Observables n) : Observables n := + fun x => f x - gibbsExpectation J f + +@[simp] lemma gibbsExpectation_centered {n : ℕ} (J : Interaction n) (f : Observables n) : + gibbsExpectation J (centered J f) = 0 := by + unfold centered + rw [gibbsExpectation_sub, gibbsExpectation_const, sub_self] + +@[simp] lemma halfDiff_centered {n : ℕ} (J : Interaction n) (f : Observables n) + (i : Fin n) (x : Spin n) : halfDiff i (centered J f) x = halfDiff i f x := by + simp only [halfDiff, centered] + ring + +lemma dirichlet_centered {n : ℕ} (J : Interaction n) (f g : Observables n) : + dirichlet J (centered J f) (centered J g) = dirichlet J f g := by + simp only [dirichlet, halfDiff_centered] + +lemma centered_variance {n : ℕ} (J : Interaction n) (f : Observables n) : + stationaryInner J (centered J f) (centered J f) = gibbsVariance J f := by + simp only [stationaryInner, centered, gibbsVariance, pow_two] + +lemma spectral_dirichlet {n : ℕ} (J : Interaction n) + (hJ : ∀ i j, J i j = J j i) (hdiag : ∀ i, J i i = 0) (f : Observables n) : + dirichlet J f f = ∑ a, spinEigenvalues J hJ hdiag a * + ((spinEigenbasis J hJ hdiag).repr (gibbsEuclideanEquiv J f) a) ^ 2 := by + rw [← gibbs_dirichlet J hJ hdiag] + change stationaryInner J f (-generator J f) = _ + rw [← spectral_parseval J hJ hdiag] + simp_rw [spectral_generator_coordinates] + apply Finset.sum_congr rfl + intro a _ + ring + +lemma centered_spectral_coordinate_zero {n : ℕ} (J : Interaction n) + (hJ : ∀ i j, J i j = J j i) (hdiag : ∀ i, J i i = 0) (f : Observables n) + (a : Fin (Fintype.card (Spin n))) (ha : spinEigenvalues J hJ hdiag a = 0) : + (spinEigenbasis J hJ hdiag).repr (gibbsEuclideanEquiv J (centered J f)) a = 0 := by + have hg : generator J (scalarEigenfunction J hJ hdiag a) = 0 := by + rw [generator_scalarEigenfunction, ha, neg_zero, zero_smul] + have hc (x : Spin n) : scalarEigenfunction J hJ hdiag a x = + scalarEigenfunction J hJ hdiag a (fun _ => false) := + constant_of_generator_zero J hJ hdiag _ hg x _ + rw [spectral_coordinates_inner] + simp only [stationaryInner, hc, gibbsExpectation_mul_const, gibbsExpectation_centered, + mul_zero] + +lemma hasGap_of_positive_eigenvalues {n : ℕ} (J : Interaction n) + (hJ : ∀ i j, J i j = J j i) (hdiag : ∀ i, J i i = 0) (γ : ℝ) + (hγ : ∀ a, 0 < spinEigenvalues J hJ hdiag a → γ ≤ spinEigenvalues J hJ hdiag a) : + HasGap J γ := by + intro f + rw [← centered_variance, ← dirichlet_centered J f f, spectral_dirichlet J hJ hdiag, + ← spectral_parseval J hJ hdiag, Finset.mul_sum] + apply Finset.sum_le_sum + intro a _ + by_cases ha : spinEigenvalues J hJ hdiag a = 0 + · simp only [centered_spectral_coordinate_zero J hJ hdiag f a ha, mul_zero, zero_pow, ne_eq, + OfNat.ofNat_ne_zero, not_false_eq_true, le_refl] + · have hp := lt_of_le_of_ne (spinEigenvalues_nonneg J hJ hdiag a) (Ne.symm ha) + simpa only [pow_two, mul_assoc] using + mul_le_mul_of_nonneg_right (hγ a hp) + (sq_nonneg ((spinEigenbasis J hJ hdiag).repr (gibbsEuclideanEquiv J (centered J f)) a)) + +theorem finite_gap_pos {n : ℕ} (J : Interaction n) + (hJ : ∀ i j, J i j = J j i) (hdiag : ∀ i, J i i = 0) : + ∃ γ : ℝ, 0 < γ ∧ HasGap J γ := by + let values : Finset ℝ := insert 1 ((Finset.univ.image (spinEigenvalues J hJ hdiag)).filter (0 < ·)) + have hne : values.Nonempty := ⟨1, Finset.mem_insert_self _ _⟩ + refine ⟨values.min' hne, ?_, hasGap_of_positive_eigenvalues J hJ hdiag _ ?_⟩ + · have hm := Finset.min'_mem values hne + rcases Finset.mem_insert.mp hm with h | h + · rw [h]; norm_num + · exact (Finset.mem_filter.mp h).2 + · intro a ha + apply Finset.min'_le + exact Finset.mem_insert_of_mem (Finset.mem_filter.mpr + ⟨Finset.mem_image.mpr ⟨a, Finset.mem_univ _, rfl⟩, ha⟩) + +end SKGapCutoff + +namespace SKGapCutoff + +lemma scalarEigenfunction_centered {n : ℕ} (J : Interaction n) + (hJ : ∀ i j, J i j = J j i) (hdiag : ∀ i, J i i = 0) + (a : Fin (Fintype.card (Spin n))) (ha : spinEigenvalues J hJ hdiag a ≠ 0) : + gibbsExpectation J (scalarEigenfunction J hJ hdiag a) = 0 := by + have hz := gibbs_generator_zero J hJ hdiag (scalarEigenfunction J hJ hdiag a) + rw [generator_scalarEigenfunction] at hz + change gibbsExpectation J (fun x => -spinEigenvalues J hJ hdiag a * + scalarEigenfunction J hJ hdiag a x) = 0 at hz + rw [gibbsExpectation_mul_const] at hz + exact (mul_eq_zero.mp hz).resolve_left (neg_ne_zero.mpr ha) + +lemma scalarEigenfunction_inner_self {n : ℕ} (J : Interaction n) + (hJ : ∀ i j, J i j = J j i) (hdiag : ∀ i, J i i = 0) + (a : Fin (Fintype.card (Spin n))) : + stationaryInner J (scalarEigenfunction J hJ hdiag a) + (scalarEigenfunction J hJ hdiag a) = 1 := by + rw [← gibbsEuclideanEquiv_inner, lift_scalarEigenfunction, + real_inner_self_eq_norm_sq, (spinEigenbasis J hJ hdiag).orthonormal.norm_eq_one, one_pow] + +lemma gap_le_positive_eigenvalue {n : ℕ} (J : Interaction n) + (hJ : ∀ i j, J i j = J j i) (hdiag : ∀ i, J i i = 0) + {γ : ℝ} (hγ : HasGap J γ) (a : Fin (Fintype.card (Spin n))) + (ha : 0 < spinEigenvalues J hJ hdiag a) : γ ≤ spinEigenvalues J hJ hdiag a := by + have hv : gibbsVariance J (scalarEigenfunction J hJ hdiag a) = 1 := by + rw [gibbsVariance, scalarEigenfunction_centered J hJ hdiag a (ne_of_gt ha)] + simp only [sub_zero, pow_two] + exact scalarEigenfunction_inner_self J hJ hdiag a + have hd : dirichlet J (scalarEigenfunction J hJ hdiag a) + (scalarEigenfunction J hJ hdiag a) = spinEigenvalues J hJ hdiag a := by + rw [← gibbs_dirichlet J hJ hdiag, generator_scalarEigenfunction] + simp only [Pi.smul_apply, smul_eq_mul, neg_mul, neg_neg] + simp_rw [mul_left_comm (scalarEigenfunction J hJ hdiag a _) (spinEigenvalues J hJ hdiag a)] + rw [gibbsExpectation_mul_const] + change spinEigenvalues J hJ hdiag a * stationaryInner J + (scalarEigenfunction J hJ hdiag a) (scalarEigenfunction J hJ hdiag a) = _ + rw [scalarEigenfunction_inner_self, mul_one] + simpa only [hv, hd, mul_one] using hγ (scalarEigenfunction J hJ hdiag a) + +theorem hasGap_iff_positive_eigenvalues {n : ℕ} (J : Interaction n) + (hJ : ∀ i j, J i j = J j i) (hdiag : ∀ i, J i i = 0) (γ : ℝ) : + HasGap J γ ↔ ∀ a, 0 < spinEigenvalues J hJ hdiag a → + γ ≤ spinEigenvalues J hJ hdiag a := + ⟨fun h a ha => gap_le_positive_eigenvalue J hJ hdiag h a ha, + hasGap_of_positive_eigenvalues J hJ hdiag γ⟩ + +theorem quenchedGap_iff_spectral (β : ℝ) : QuenchedGap β ↔ + ∃ γ : ℝ, 0 < γ ∧ Filter.Tendsto (fun n => (disorderLaw β n) + {g | ∀ a, 0 < spinEigenvalues (sampledInteraction g) + (sampledInteraction_symm g) (sampledInteraction_diag g) a → + γ ≤ spinEigenvalues (sampledInteraction g) + (sampledInteraction_symm g) (sampledInteraction_diag g) a}) + Filter.atTop (nhds 1) := by + simp only [QuenchedGap, hasGap_iff_positive_eigenvalues (sampledInteraction _) + (sampledInteraction_symm _) (sampledInteraction_diag _)] + +end SKGapCutoff + +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/ChainingCore.lean b/lean/OAI/Probability/SKGap/Localization/ChainingCore.lean new file mode 100644 index 0000000000000000000000000000000000000000..f0657dcb9aaeb1cdae0b4069d057a89b435bc7f3 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/ChainingCore.lean @@ -0,0 +1,155 @@ +import Mathlib +import OAI.Probability.SKGap.Model + +namespace OAI + +section +noncomputable section +namespace SKGap +open MeasureTheory ProbabilityTheory Real Set Filter +open scoped BigOperators ENNReal Topology + +lemma subadditive_chain_finite {E : Type*} [AddCommGroup E] (p : E→ℝ) + (hp : ∀ x y,p (x+y) ≤ p x+p y) (u : ℕ→E) (r : ℕ→ℝ) + (hr : ∀ k,p (u (k+1)-u k) ≤ r k) (n : ℕ) : + p (u n) ≤ p (u 0)+∑ k∈Finset.range n,r k := by + induction n with + | zero => simp + | succ n hn => + have hh := hp (u n) (u (n+1)-u n) + rw [add_sub_cancel] at hh + rw [Finset.sum_range_succ] + linarith only [hh,hn,hr n] + +lemma subadditive_chain_limit {E : Type*} [AddCommGroup E] [TopologicalSpace E] + (p : E→ℝ) (hc : Continuous p) (hp : ∀ x y,p (x+y) ≤ p x+p y) + (u : ℕ→E) {x : E} (hu : Tendsto u atTop (𝓝 x)) (r : ℕ→ℝ) + (hr0 : ∀ k,0 ≤ r k) (hrs : Summable r) (hr : ∀ k,p (u (k+1)-u k) ≤ r k) : + p x ≤ p (u 0)+∑' k,r k := by + apply le_of_tendsto (hc.tendsto x |>.comp hu) + exact Eventually.of_forall (fun n=>(subadditive_chain_finite p hp u r hr n).trans + (add_le_add_right (hrs.sum_le_tsum (Finset.range n) (fun i _=>hr0 i)) _)) + +lemma arithmetic_half_geometric_hasSum : + HasSum (fun k : ℕ=>((k:ℝ)+1)*(1/2:ℝ)^k) 4 := by + have h₁ := hasSum_coe_mul_geometric_of_norm_lt_one (by norm_num : ‖(1/2:ℝ)‖ < 1) + have h₂ := hasSum_geometric_of_lt_one (by norm_num : (0:ℝ) ≤ 1/2) (by norm_num : (1/2:ℝ)<1) + have h : HasSum (fun k : ℕ => ((k:ℝ)+1)*(1/2:ℝ)^k) + (1/2/(1-1/2)^2+(1-1/2)⁻¹) := by + convert h₁.add h₂ using 1 + ext k + ring + norm_num at h + exact h + +theorem continuous_chaining_probability + {Ω T E : Type*} [MeasurableSpace Ω] (μ : Measure Ω) + [TopologicalSpace T] [AddCommGroup E] [TopologicalSpace E] + (p : E→ℝ) (hc : Continuous p) (hp : ∀ x y,p (x+y) ≤ p x+p y) + (F : T→Ω→E) (hF : ∀ ω,Continuous (fun t=>F t ω)) + (S : Set T) (ι : ℕ→Type*) [∀ k,Fintype (ι k)] + (v : ∀ k,ι k→T) (edges : ∀ k,Finset (ι k×ι (k+1))) + (hcover : ∀ t∈S,∃ a : ∀ k,ι k, + (∀ k,(a k,a (k+1))∈edges k) ∧ Tendsto (fun k=>v k (a k)) atTop (𝓝 t)) + (r : ℕ→ℝ) (hr0 : ∀ k,0 ≤ r k) (hrs : Summable r) + (b : ℝ) (q₀ : ℝ≥0∞) (q : ℕ→ℝ≥0∞) + (hb : ∀ i,μ {ω | b < p (F (v 0 i) ω)} ≤ q₀) + (hi : ∀ k, ∀ e∈edges k,μ {ω | r k < p (F (v (k+1) e.2) ω-F (v k e.1) ω)} ≤ q k) : + μ {ω | ∃ t∈S,b+(∑' k,r k) < p (F t ω)} ≤ + (Fintype.card (ι 0):ℝ≥0∞)*q₀+∑' k,((edges k).card:ℝ≥0∞)*q k := by + classical + let B : Set Ω := ⋃ i : ι 0,{ω | b < p (F (v 0 i) ω)} + let I : ℕ→Set Ω := fun k=>⋃ e∈edges k,{ω | r k < p (F (v (k+1) e.2) ω-F (v k e.1) ω)} + have hs : {ω | ∃ t∈S,b+(∑' k,r k) < p (F t ω)} ⊆ B ∪ ⋃ k,I k := by + intro ω hω + by_contra hh + have hh' := not_or.mp hh + obtain ⟨t,ht,htp⟩ := hω + obtain ⟨a,ha,hat⟩ := hcover t ht + have hbase : p (F (v 0 (a 0)) ω) ≤ b := by + by_contra hn + exact hh'.1 (mem_iUnion.mpr ⟨a 0,not_le.mp hn⟩) + have hinc : ∀ k,p (F (v (k+1) (a (k+1))) ω-F (v k (a k)) ω) ≤ r k := by + intro k + by_contra hn + apply hh'.2 + exact mem_iUnion.mpr ⟨k,mem_iUnion₂.mpr ⟨(a k,a (k+1)),ha k,not_le.mp hn⟩⟩ + have hl := subadditive_chain_limit p hc hp (fun k=>F (v k (a k)) ω) + ((hF ω).tendsto t |>.comp hat) r hr0 hrs hinc + linarith only [hl,hbase,htp] + apply (measure_mono hs).trans + apply (measure_union_le _ _).trans + apply add_le_add + · exact (measure_iUnion_fintype_le μ _).trans ((Finset.sum_le_sum (fun i _=>hb i)).trans_eq (by simp)) + · apply (measure_iUnion_le I).trans + apply ENNReal.tsum_le_tsum + intro k + apply (measure_biUnion_finset_le (edges k) _).trans + exact (Finset.sum_le_sum (fun e he=>hi k e he)).trans_eq (by simp) +end SKGap +end +end + +section +noncomputable section +namespace SKGap +open MeasureTheory ProbabilityTheory Real Set Filter +open scoped BigOperators ENNReal Topology + +lemma exponential_series_bound {c : ℝ} (hc : log 2 ≤ c) : + (∑' k : ℕ,ENNReal.ofReal (exp (-c*((k:ℝ)+1)))) ≤ ENNReal.ofReal (2*exp (-c)) := by + have hc0 : 0 < c := lt_of_lt_of_le (log_pos (by norm_num : (1:ℝ)<2)) hc + have hr : exp (-c) < 1 := by rw [exp_lt_one_iff];linarith + have hr2 : exp (-c) ≤ 1/2 := by + rw [← exp_log (by norm_num : (0:ℝ)<(1/2))] + apply exp_le_exp.mpr + rw [log_div (by norm_num) (by norm_num),log_one] + linarith only [hc] + have he (k : ℕ) : exp (-c*((k:ℝ)+1))=exp (-c)*exp (-c)^k := by + rw [← exp_nat_mul,← exp_add] + congr 1;ring + have hs : HasSum (fun k : ℕ=>exp (-c*((k:ℝ)+1))) (exp (-c)*(1-exp (-c))⁻¹) := by + simpa only [he] using (hasSum_geometric_of_lt_one (exp_pos (-c)).le hr).mul_left (exp (-c)) + rw [← ENNReal.ofReal_tsum_of_nonneg (fun _=>(exp_pos _).le) hs.summable,hs.tsum_eq] + apply ENNReal.ofReal_le_ofReal + rw [← div_eq_mul_inv] + apply (div_le_iff₀ (by linarith only [hr] : 0 < 1-exp (-c))).mpr + nlinarith only [mul_le_mul_of_nonneg_left hr2 (exp_pos (-c)).le] + +lemma chaining_entropy_tail_product {n : ℕ} (_hn : 1 ≤ n) + {A B c : ℝ} (hB : 0 ≤ B) (hc : 0 < c) (hA : B+c ≤ A) + (k : ℕ) {m q : ℝ≥0∞} + (hm : m ≤ ENNReal.ofReal (exp (B*((k:ℝ)+1)*(n:ℝ)))) + (hq : q ≤ ENNReal.ofReal (exp (-A*((k:ℝ)+1)^2*(n:ℝ)))) : + m*q ≤ ENNReal.ofReal (exp (-c*(n:ℝ)*((k:ℝ)+1))) := by + apply (mul_le_mul' hm hq).trans + rw [← ENNReal.ofReal_mul (exp_pos _).le,← exp_add] + apply ENNReal.ofReal_le_ofReal + apply exp_le_exp.mpr + have hkn : 1 ≤ (k:ℝ)+1 := by + have hk : (0:ℝ) ≤ k := by positivity + linarith only [hk] + have hnn : 0 ≤ (n:ℝ) := by positivity + have hA0 : 0 ≤ A := by linarith + have hs : (k:ℝ)+1 ≤ ((k:ℝ)+1)^2 := by nlinarith + have hh := mul_le_mul_of_nonneg_left hs hA0 + have hh' := mul_le_mul_of_nonneg_right hA (show 0 ≤ (k:ℝ)+1 by positivity) + have hh'' := mul_le_mul_of_nonneg_right (show c*((k:ℝ)+1) ≤ A*((k:ℝ)+1)^2-B*((k:ℝ)+1) by linarith only [hh,hh']) hnn + linarith only [hh''] + +lemma chaining_entropy_series {n : ℕ} (hn : 1 ≤ n) + {A B c : ℝ} (hB : 0 ≤ B) (hc : log 2 ≤ c) (hA : B+c ≤ A) + (m q : ℕ→ℝ≥0∞) + (hm : ∀ k,m k ≤ ENNReal.ofReal (exp (B*((k:ℝ)+1)*(n:ℝ)))) + (hq : ∀ k,q k ≤ ENNReal.ofReal (exp (-A*((k:ℝ)+1)^2*(n:ℝ)))) : + (∑' k,m k*q k) ≤ ENNReal.ofReal (2*exp (-c*(n:ℝ))) := by + have hc0 : 0 < c := lt_of_lt_of_le (log_pos (by norm_num : (1:ℝ)<2)) hc + have hn' : (1:ℝ) ≤ n := by exact_mod_cast hn + apply (ENNReal.tsum_le_tsum (fun k=>chaining_entropy_tail_product hn hB hc0 hA k (hm k) (hq k))).trans + have hcn : log 2 ≤ c*(n:ℝ) := hc.trans (by nlinarith only [hn',hc0]) + simpa only [neg_mul] using exponential_series_bound hcn +end SKGap +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/Character.lean b/lean/OAI/Probability/SKGap/Localization/Character.lean new file mode 100644 index 0000000000000000000000000000000000000000..d7f64a56d1609c81b9ebe627f95f8dc11b942311 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/Character.lean @@ -0,0 +1,433 @@ +import Mathlib +import OAI.Probability.SKGap.Terminal.Spin + +namespace OAI + +section +open scoped BigOperators +namespace SKGapCutoff + +theorem exp_apply_hasSum {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] + [CompleteSpace E] (A : E →L[ℝ] E) (f : E) : + HasSum (fun k : ℕ => (k.factorial : ℝ)⁻¹ • ((A ^ k) f)) + (NormedSpace.exp A f) := by + simpa only [NormedSpace.expSeries_apply_eq, ContinuousLinearMap.apply_apply, + smul_apply] using + (ContinuousLinearMap.apply ℝ E f).hasSum + (NormedSpace.expSeries_hasSum_exp (𝕂 := ℝ) A) + +theorem exp_apply_of_apply_eq_zero {E : Type*} [NormedAddCommGroup E] + [NormedSpace ℝ E] [CompleteSpace E] (A : E →L[ℝ] E) (f : E) + (h : A f = 0) : NormedSpace.exp A f = f := by + have hp (k : ℕ) : (A ^ (k + 1)) f = 0 := by + induction k with + | zero => simpa using h + | succ k ih => rw [pow_succ', mul_apply_eq_comp, ih, map_zero] + have hs : HasSum (fun k : ℕ => (k.factorial : ℝ)⁻¹ • ((A ^ k) f)) f := by + convert hasSum_ite_eq 0 f using 1 + funext k + cases k with + | zero => simp + | succ k => simp [hp] + exact (exp_apply_hasSum A f).unique hs + +@[simp] theorem semigroup_const {n : ℕ} (J : Interaction n) (t a : ℝ) : + semigroup J t (fun _ => a) = fun _ => a := by + apply exp_apply_of_apply_eq_zero + funext x + change t * generator J (fun _ => a) x = 0 + simp + +theorem exp_smul_identity {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] + [CompleteSpace E] (a : ℝ) : + NormedSpace.exp (a • (1 : E →L[ℝ] E)) = Real.exp a • (1 : E →L[ℝ] E) := by + simpa only [Algebra.algebraMap_eq_smul_one, ← Real.exp_eq_exp_ℝ] using + (NormedSpace.algebraMap_exp_comm (𝔸 := E →L[ℝ] E) a).symm + +theorem semigroup_uniformization {n : ℕ} (hn : 0 < n) (J : Interaction n) (t : ℝ) : + semigroup J t = Real.exp (-(n : ℝ) * t) • + NormedSpace.exp (((n : ℝ) * t) • attemptLM J) := by + have hn' : (n : ℝ) ≠ 0 := by exact_mod_cast ne_of_gt hn + have heq : t • generatorCLM J = + (-(n : ℝ) * t) • (1 : Observables n →L[ℝ] Observables n) + + ((n : ℝ) * t) • attemptLM J := by + unfold attemptLM + simp only [smul_add, smul_smul] + have hc : ((n : ℝ) * t) * (n : ℝ)⁻¹ = t := by field_simp + rw [hc] + module + let : NormedAlgebra ℚ (Observables n →L[ℝ] Observables n) := + NormedAlgebra.restrictScalars ℚ ℝ _ + unfold semigroup + rw [heq, NormedSpace.exp_add_of_commute + (((Commute.one_left (attemptLM J)).smul_left _).smul_right _), + exp_smul_identity, smul_mul_assoc, one_mul] + +theorem semigroup_nonneg {n : ℕ} (J : Interaction n) (t : ℝ) (ht : 0 ≤ t) + (f : Observables n) (hf : ∀ x, 0 ≤ f x) (x : Spin n) : + 0 ≤ semigroup J t f x := by + by_cases hn : n = 0 + · subst n + have hL : generatorCLM J = 0 := by + ext f x + simp [generatorCLM, generatorLM, generator] + simp only [semigroup, hL, smul_zero, NormedSpace.exp_zero, + one_apply_eq_self] + exact hf x + · rw [semigroup_uniformization (Nat.pos_of_ne_zero hn)] + simp only [smul_apply, Pi.smul_apply, smul_eq_mul] + apply mul_nonneg (le_of_lt (Real.exp_pos _)) + have hs := Pi.hasSum.mp (exp_apply_hasSum (((n : ℝ) * t) • attemptLM J) f) x + apply HasSum.nonneg _ hs + intro k + simp only [smul_pow, smul_apply, Pi.smul_apply, smul_eq_mul] + exact mul_nonneg (inv_nonneg.mpr (Nat.cast_nonneg _)) + (mul_nonneg (pow_nonneg (mul_nonneg (Nat.cast_nonneg _) ht) _) + (attempt_pow_nonneg J k f hf x)) + +theorem continuousKernel_nonneg {n : ℕ} (J : Interaction n) (t : ℝ) (ht : 0 ≤ t) + (x y : Spin n) : 0 ≤ continuousKernel J t x y := by + exact semigroup_nonneg J t ht _ (fun _ => by split_ifs <;> norm_num) x + +theorem continuousKernel_sum {n : ℕ} (J : Interaction n) (t : ℝ) (x : Spin n) : + ∑ y, continuousKernel J t x y = 1 := by + have eq_one : (∑ y : Spin n, fun z => if z = y then (1 : ℝ) else 0) = + fun _ : Spin n => (1 : ℝ) := by + funext z + simp + unfold continuousKernel + rw [← Finset.sum_apply, ← map_sum, eq_one, semigroup_const] + +@[simp] theorem spin_sq {n : ℕ} (x : Spin n) (i : Fin n) : spin x i ^ 2 = 1 := by + unfold spin + cases x i <;> norm_num + +@[simp] theorem spin_mul_self {n : ℕ} (x : Spin n) (i : Fin n) : + spin x i * spin x i = 1 := by simpa only [pow_two] using spin_sq x i + +@[simp] theorem field_zero {n : ℕ} (x : Spin n) (i : Fin n) : + field (0 : Interaction n) x i = 0 := by simp [field] + +@[simp] theorem mean_zero {n : ℕ} (x : Spin n) (i : Fin n) : + mean (0 : Interaction n) x i = 0 := by simp [mean] + +@[simp] theorem energy_zero {n : ℕ} (x : Spin n) : + energy (0 : Interaction n) x = 0 := by simp [energy] + +@[simp] theorem card_spin (n : ℕ) : Fintype.card (Spin n) = 2 ^ n := by + simp [Spin] + +@[simp] theorem partition_zero (n : ℕ) : partition (0 : Interaction n) = (2 : ℝ) ^ n := by + simp [partition] + +@[simp] theorem gibbs_zero {n : ℕ} (x : Spin n) : + gibbs (0 : Interaction n) x = ((2 : ℝ) ^ n)⁻¹ := by simp [gibbs] + +noncomputable def character {n : ℕ} (s : Finset (Fin n)) (x : Spin n) : ℝ := + ∏ i ∈ s, spin x i + +@[simp] theorem character_empty {n : ℕ} (x : Spin n) : character ∅ x = 1 := by + simp [character] + +@[simp] theorem character_sq {n : ℕ} (s : Finset (Fin n)) (x : Spin n) : + character s x ^ 2 = 1 := by simp [character, ← Finset.prod_pow] + +lemma character_erase {n : ℕ} (s : Finset (Fin n)) (x : Spin n) (i : Fin n) + (hi : i ∈ s) : spin x i * character (s.erase i) x = character s x := by + exact Finset.mul_prod_erase s (fun j => spin x j) hi + +lemma spin_replace_of_ne {n : ℕ} (x : Spin n) {i j : Fin n} (h : j ≠ i) (b : Bool) : + spin (replace x i b) j = spin x j := by + simp [spin, replace, Function.update_of_ne h] + +lemma character_replace_of_not_mem {n : ℕ} (s : Finset (Fin n)) (x : Spin n) + (i : Fin n) (hi : i ∉ s) (b : Bool) : character s (replace x i b) = character s x := by + apply Finset.prod_congr rfl + intro j hj + exact spin_replace_of_ne x (ne_of_mem_of_not_mem hj hi) b + +lemma character_replace_of_mem {n : ℕ} (s : Finset (Fin n)) (x : Spin n) + (i : Fin n) (hi : i ∈ s) (b : Bool) : + character s (replace x i b) = (if b then 1 else -1) * character (s.erase i) x := by + rw [← character_erase s (replace x i b) i hi, + character_replace_of_not_mem _ x i (Finset.notMem_erase i s)] + simp [spin] + +lemma halfDiff_character {n : ℕ} (s : Finset (Fin n)) (x : Spin n) (i : Fin n) : + halfDiff i (character s) x = if i ∈ s then character (s.erase i) x else 0 := by + by_cases hi : i ∈ s + · simp only [halfDiff, character_replace_of_mem s x i hi, Bool.false_eq_true, ↓reduceIte, hi] + ring + · simp [halfDiff, character_replace_of_not_mem s x i hi, hi] + +lemma spin_mul_halfDiff_character {n : ℕ} (s : Finset (Fin n)) (x : Spin n) (i : Fin n) : + spin x i * halfDiff i (character s) x = if i ∈ s then character s x else 0 := by + rw [halfDiff_character] + split_ifs with hi + · exact character_erase s x i hi + · ring + +lemma generator_zero_character {n : ℕ} (s : Finset (Fin n)) : + generatorCLM (0 : Interaction n) (character s) = -(s.card : ℝ) • character s := by + funext x + change generator (0 : Interaction n) (character s) x = -(s.card : ℝ) * character s x + simp only [generator, mean_zero, zero_sub, neg_mul, spin_mul_halfDiff_character, + Finset.sum_neg_distrib] + simp + +theorem exp_apply_of_eigenvector {E : Type*} [NormedAddCommGroup E] + [NormedSpace ℝ E] [CompleteSpace E] (A : E →L[ℝ] E) (f : E) (a : ℝ) + (h : A f = a • f) : NormedSpace.exp A f = Real.exp a • f := by + have hp (k : ℕ) : (A ^ k) f = a ^ k • f := by + induction k with + | zero => simp + | succ k ih => + rw [pow_succ', mul_apply_eq_comp, ih, map_smul, h, smul_smul, pow_succ] + have hs : HasSum (fun k : ℕ => (k.factorial : ℝ)⁻¹ * a ^ k) (Real.exp a) := by + simpa only [smul_eq_mul, Real.exp_eq_exp_ℝ] using + (NormedSpace.exp_series_hasSum_exp' (𝕂 := ℝ) a) + apply (exp_apply_hasSum A f).unique + simpa only [hp, smul_smul] using hs.smul_const f + +lemma semigroup_zero_character {n : ℕ} (s : Finset (Fin n)) (t : ℝ) : + semigroup (0 : Interaction n) t (character s) = + Real.exp (-t * (s.card : ℝ)) • character s := by + apply exp_apply_of_eigenvector + rw [smul_apply, generator_zero_character, smul_smul] + congr 1 + ring + +lemma attempt_zero_character {n : ℕ} (s : Finset (Fin n)) : + attemptLM (0 : Interaction n) (character s) = + (1 - (s.card : ℝ) / n) • character s := by + change character s + (n : ℝ)⁻¹ • generatorCLM (0 : Interaction n) (character s) = _ + rw [generator_zero_character, smul_smul] + module + +lemma attempt_pow_zero_character {n : ℕ} (s : Finset (Fin n)) (k : ℕ) : + (attemptLM (0 : Interaction n) ^ k) (character s) = + (1 - (s.card : ℝ) / n) ^ k • character s := by + induction k with + | zero => simp + | succ k ih => + rw [pow_succ', mul_apply_eq_comp, ih, map_smul, attempt_zero_character, + smul_smul, pow_succ] + +lemma character_eq_prod_univ {n : ℕ} (s : Finset (Fin n)) (x : Spin n) : + character s x = ∏ i : Fin n, if i ∈ s then spin x i else 1 := by + simp [character, Finset.prod_ite_mem] + +lemma character_inner {n : ℕ} (s r : Finset (Fin n)) : + ∑ x : Spin n, character s x * character r x = + if s = r then (2 : ℝ) ^ n else 0 := by + by_cases h : s = r + · subst r + simp only [← pow_two, character_sq, ↓reduceIte, Finset.sum_const, + Finset.card_univ, card_spin, nsmul_eq_mul, mul_one, Nat.cast_pow, Nat.cast_ofNat] + · rw [ite_eq_right h] + have hp : (∑ x : Spin n, character s x * character r x) = + ∏ i : Fin n, ∑ b : Bool, + (if i ∈ s then (if b then (1 : ℝ) else -1) else 1) * + (if i ∈ r then (if b then (1 : ℝ) else -1) else 1) := by + rw [Fintype.prod_sum] + apply Finset.sum_congr rfl + intro x _ + rw [character_eq_prod_univ, character_eq_prod_univ, ← Finset.prod_mul_distrib] + rfl + rw [hp] + obtain ⟨i, hi⟩ : ∃ i, ¬ (i ∈ s ↔ i ∈ r) := by + by_contra! hc + exact h (Finset.ext hc) + apply Finset.prod_eq_zero (Finset.mem_univ i) + by_cases hs : i ∈ s <;> by_cases hr : i ∈ r + · exact (hi (by simp [hs, hr])).elim + · simp [hs, hr] + · simp [hs, hr] + · exact (hi (by simp [hs, hr])).elim + +lemma character_sum {n : ℕ} (s : Finset (Fin n)) : + ∑ x : Spin n, character s x = if s = ∅ then (2 : ℝ) ^ n else 0 := by + simpa only [character_empty, mul_one] using character_inner s ∅ + +lemma character_delta_sum {n : ℕ} (x y : Spin n) : + ∑ s : Finset (Fin n), character s x * character s y = + if x = y then (2 : ℝ) ^ n else 0 := by + have hsum : (∑ s : Finset (Fin n), character s x * character s y) = + ∏ i : Fin n, (spin x i * spin y i + 1) := by + rw [Finset.prod_add_one] + simp only [Finset.powerset_univ] + apply Finset.sum_congr rfl + intro s _ + exact (Finset.prod_mul_distrib (f := spin x) (g := spin y)).symm + rw [hsum] + by_cases h : x = y + · subst y + simp only [spin_mul_self, ↓reduceIte, Finset.prod_const, Finset.card_univ, + Fintype.card_fin] + norm_num + · rw [ite_eq_right h] + obtain ⟨i, hi⟩ : ∃ i, x i ≠ y i := Function.ne_iff.mp h + apply Finset.prod_eq_zero (Finset.mem_univ i) + unfold spin + cases hx : x i <;> cases hy : y i <;> simp_all + +lemma delta_character_expansion {n : ℕ} (y : Spin n) : + (fun x : Spin n => if x = y then (1 : ℝ) else 0) = + ((2 : ℝ) ^ n)⁻¹ • ∑ s : Finset (Fin n), character s y • character s := by + funext x + simp only [Pi.smul_apply, Finset.sum_apply, smul_eq_mul] + simp_rw [mul_comm (character _ y)] + rw [character_delta_sum] + split_ifs <;> simp + +lemma character_parseval {n : ℕ} (a : Finset (Fin n) → ℝ) : + (∑ x : Spin n, (∑ s : Finset (Fin n), a s * character s x) ^ 2) = + (2 : ℝ) ^ n * ∑ s : Finset (Fin n), a s ^ 2 := by + simp only [pow_two, Finset.sum_mul_sum] + rw [Finset.sum_comm] + apply Eq.trans _ (Finset.mul_sum ..).symm + apply Finset.sum_congr rfl + intro s _ + rw [Finset.sum_comm] + simp_rw [show ∀ r x, a s * character s x * (a r * character r x) = + (a s * a r) * (character s x * character r x) by intros; ring, + ← Finset.mul_sum, character_inner] + simp only [mul_ite, mul_zero, Fintype.sum_ite_eq] + ring + +noncomputable def fourierKernel {n : ℕ} (a : Finset (Fin n) → ℝ) + (x y : Spin n) : ℝ := + ((2 : ℝ) ^ n)⁻¹ * ∑ s : Finset (Fin n), a s * character s x * character s y + +lemma continuousKernel_zero_fourier {n : ℕ} (t : ℝ) (x y : Spin n) : + continuousKernel (0 : Interaction n) t x y = + fourierKernel (fun s => Real.exp (-t * (s.card : ℝ))) x y := by + unfold continuousKernel + rw [delta_character_expansion y, map_smul, map_sum] + simp_rw [map_smul, semigroup_zero_character] + simp only [Pi.smul_apply, Finset.sum_apply, smul_eq_mul, fourierKernel] + congr 1 + apply Finset.sum_congr rfl + intro s _ + ring + +lemma discreteKernel_zero_fourier {n : ℕ} (k : ℕ) (x y : Spin n) : + discreteKernel (0 : Interaction n) k x y = + fourierKernel (fun s => (1 - (s.card : ℝ) / n) ^ k) x y := by + unfold discreteKernel + rw [delta_character_expansion y, map_smul, map_sum] + simp_rw [map_smul, attempt_pow_zero_character] + simp only [Pi.smul_apply, Finset.sum_apply, smul_eq_mul, fourierKernel] + congr 1 + apply Finset.sum_congr rfl + intro s _ + ring + +noncomputable def centeredFourier {n : ℕ} (a : Finset (Fin n) → ℝ) + (s : Finset (Fin n)) : ℝ := a s - if s = ∅ then 1 else 0 + +lemma centeredFourier_sum_sq {n : ℕ} (a : Finset (Fin n) → ℝ) (ha : a ∅ = 1) : + ∑ s, centeredFourier a s ^ 2 = (∑ s, a s ^ 2) - 1 := by + have h (s : Finset (Fin n)) : centeredFourier a s ^ 2 = + a s ^ 2 - if s = ∅ then 1 else 0 := by + by_cases hs : s = ∅ <;> simp [centeredFourier, hs, ha] + simp_rw [h, Finset.sum_sub_distrib] + simp + +lemma centeredFourier_expansion {n : ℕ} (a : Finset (Fin n) → ℝ) (x y : Spin n) : + ∑ s, centeredFourier a s * character s x * character s y = + (∑ s, a s * character s x * character s y) - 1 := by + simp only [centeredFourier, sub_mul, Finset.sum_sub_distrib] + simp + +lemma fourierKernel_sub_uniform {n : ℕ} (a : Finset (Fin n) → ℝ) (x y : Spin n) : + fourierKernel a x y - ((2 : ℝ) ^ n)⁻¹ = + ((2 : ℝ) ^ n)⁻¹ * ∑ s, centeredFourier a s * character s x * character s y := by + rw [centeredFourier_expansion] + unfold fourierKernel + ring + +lemma fourierKernel_chiSquare {n : ℕ} (a : Finset (Fin n) → ℝ) (ha : a ∅ = 1) + (x : Spin n) : + (2 : ℝ) ^ n * ∑ y, (fourierKernel a x y - ((2 : ℝ) ^ n)⁻¹) ^ 2 = + (∑ s, a s ^ 2) - 1 := by + simp_rw [fourierKernel_sub_uniform, mul_pow] + rw [← Finset.mul_sum, character_parseval] + simp only [mul_pow, character_sq, mul_one] + rw [centeredFourier_sum_sq a ha] + field_simp + +lemma totalVariation_fourier_sq_le {n : ℕ} (a : Finset (Fin n) → ℝ) + (ha : a ∅ = 1) (x : Spin n) : + 4 * totalVariation (fourierKernel a x) (gibbs (0 : Interaction n)) ^ 2 ≤ + (∑ s, a s ^ 2) - 1 := by + have hc := Finset.sum_mul_sq_le_sq_mul_sq (R := ℝ) Finset.univ + (fun y : Spin n => |fourierKernel a x y - ((2 : ℝ) ^ n)⁻¹|) (fun _ => 1) + simp only [mul_one, one_pow, Finset.sum_const, Finset.card_univ, card_spin, + nsmul_eq_mul, Nat.cast_pow, Nat.cast_ofNat, mul_one, sq_abs] at hc + rw [mul_comm, fourierKernel_chiSquare a ha x] at hc + simp only [totalVariation, gibbs_zero] + nlinarith + +lemma sum_pow_card {n : ℕ} (q : ℝ) : + ∑ s : Finset (Fin n), q ^ s.card = (1 + q) ^ n := by + simpa only [Finset.powerset_univ, one_pow, mul_one, Finset.card_univ, + Fintype.card_fin, add_comm] using + (Finset.sum_pow_mul_eq_add_pow q 1 (Finset.univ : Finset (Fin n))) + +lemma exp_card_sq (t : ℝ) (k : ℕ) : + Real.exp (-t * (k : ℝ)) ^ 2 = Real.exp (-2 * t) ^ k := by + rw [← Real.exp_nat_mul, ← Real.exp_nat_mul] + congr 1 + push_cast + ring + +lemma continuous_zero_tv_sq_le {n : ℕ} (t : ℝ) (x : Spin n) : + 4 * totalVariation (continuousKernel (0 : Interaction n) t x) + (gibbs (0 : Interaction n)) ^ 2 ≤ (1 + Real.exp (-2 * t)) ^ n - 1 := by + have hkernel : continuousKernel (0 : Interaction n) t x = + fourierKernel (fun s => Real.exp (-t * (s.card : ℝ))) x := by + funext y; exact continuousKernel_zero_fourier t x y + rw [hkernel] + have h := totalVariation_fourier_sq_le (fun s => Real.exp (-t * (s.card : ℝ))) + (by simp) x + simpa only [exp_card_sq, sum_pow_card] using h + +lemma discrete_character_sq_le {n : ℕ} (hn : 0 < n) (k : ℕ) + (s : Finset (Fin n)) : + ((1 - (s.card : ℝ) / n) ^ k) ^ 2 ≤ Real.exp (-2 * (k : ℝ) / n) ^ s.card := by + have hn' : (0 : ℝ) < n := by exact_mod_cast hn + have hc : (s.card : ℝ) ≤ n := by + exact_mod_cast (show s.card ≤ n by simpa using Finset.card_le_univ s) + have hnonneg : 0 ≤ 1 - (s.card : ℝ) / n := sub_nonneg.mpr ((div_le_one hn').mpr hc) + have hle : 1 - (s.card : ℝ) / n ≤ Real.exp (-(s.card : ℝ) / n) := by + simpa only [neg_div, sub_eq_add_neg, add_comm] using + Real.add_one_le_exp (-(s.card : ℝ) / n) + calc + ((1 - (s.card : ℝ) / n) ^ k) ^ 2 = + (1 - (s.card : ℝ) / n) ^ (2 * k) := by rw [← pow_mul, Nat.mul_comm] + _ ≤ Real.exp (-(s.card : ℝ) / n) ^ (2 * k) := pow_le_pow_left₀ hnonneg hle _ + _ = Real.exp (-2 * (k : ℝ) / n) ^ s.card := by + rw [← Real.exp_nat_mul, ← Real.exp_nat_mul] + congr 1 + push_cast + ring + +lemma discrete_zero_tv_sq_le {n : ℕ} (hn : 0 < n) (k : ℕ) (x : Spin n) : + 4 * totalVariation (discreteKernel (0 : Interaction n) k x) + (gibbs (0 : Interaction n)) ^ 2 ≤ + (1 + Real.exp (-2 * (k : ℝ) / n)) ^ n - 1 := by + have hkernel : discreteKernel (0 : Interaction n) k x = + fourierKernel (fun s => (1 - (s.card : ℝ) / n) ^ k) x := by + funext y; exact discreteKernel_zero_fourier k x y + rw [hkernel] + apply (totalVariation_fourier_sq_le (fun s => (1 - (s.card : ℝ) / n) ^ k) + (by simp) x).trans + apply sub_le_sub_right _ 1 + rw [← sum_pow_card] + exact Finset.sum_le_sum (fun s _ => discrete_character_sq_le hn k s) + +end SKGapCutoff +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/ClosedMarked.lean b/lean/OAI/Probability/SKGap/Localization/ClosedMarked.lean new file mode 100644 index 0000000000000000000000000000000000000000..4fc244a479810eb5d00dcf4dd4dfc64cf04c6dce --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/ClosedMarked.lean @@ -0,0 +1,314 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.ClosedPrediction +import OAI.Probability.SKGap.Matrix.RecipeTraceBudget + +namespace OAI + +section + +noncomputable section +open scoped BigOperators Matrix.Norms.Frobenius +namespace SKGap.Noncrossing.ClosedMarked +open Matrix +variable {n : ℕ} + +abbrev Word (n : ℕ) := List (WordLetter (Fin n)) +abbrev Polynomial (n : ℕ) := List (ℝ×Word n) +def matrixValue (j : ℝ) (a : Fin n→ℝ) (J : Matrix (Fin n) (Fin n) ℝ) + (P : Polynomial n) : Matrix (Fin n) (Fin n) ℝ := + (P.map (fun t=>t.1 • exactWord j a t.2 J)).sum +def prediction (j : ℝ) (a : Fin n→ℝ) (P : Polynomial n) (i : Fin n) : ℝ := + (P.map (fun t=>t.1*wordPrediction j a 1 t.2 i)).sum + +def ungrade (P : Primary.Tensor.Series.GradedWords (Fin n)) : Polynomial n := + P.map (fun t=>(t.1,t.2.2)) +lemma ungrade_matrix (j : ℝ) (a : Fin n→ℝ) (J : Matrix (Fin n) (Fin n) ℝ) + (P : Primary.Tensor.Series.GradedWords (Fin n)) : + matrixValue j a J (ungrade P)=Primary.Tensor.Series.GradedWords.matrixValue j a J P := by + simp [matrixValue,ungrade,Primary.Tensor.Series.GradedWords.matrixValue,List.map_map,Function.comp_def] +lemma ungrade_prediction (j : ℝ) (a : Fin n→ℝ) (P : Primary.Tensor.Series.GradedWords (Fin n)) : + prediction j a (ungrade P)=Primary.Tensor.Series.GradedWords.prediction j a 1 P := by + funext i + simp [prediction,ungrade,Primary.Tensor.Series.GradedWords.prediction,List.map_map,Function.comp_def] + +inductive Mark (n : ℕ) where + | diagonal : Word n→(Fin n→ℝ)→Word n→Mark n + | average : (Fin n→ℝ)→Word n→Mark n +namespace Mark + +def vector : Mark n→Fin n→ℝ + | .diagonal _ s _ => s + | .average s _ => s +def word : Mark n→Word n + | .diagonal P s Q => P++(.diag s::Q) + | .average _ P => P +def scalar : Mark n→ℝ + | .diagonal _ _ _ => 1 + | .average s _ => Diagram.mean s +def prepend (P : Word n) : Mark n→Mark n + | .diagonal Q s R => .diagonal (P++Q) s R + | .average s Q => .average s (P++Q) +lemma prefix_vector (P : Word n) (t : Mark n) : (t.prepend P).vector=t.vector := by cases t <;> rfl +lemma prefix_scalar (P : Word n) (t : Mark n) : (t.prepend P).scalar=t.scalar := by cases t <;> rfl +lemma prefix_word (P : Word n) (t : Mark n) : (t.prepend P).word=P++t.word := by + cases t <;> simp [prepend,word,List.append_assoc] +def diagnostic (d : Fin n→ℝ) : Mark n→Word n + | .diagonal P _ Q => Q++(.diag d::P) + | .average _ P => P + +lemma diagnostic_inverse (d : Fin n→ℝ) (t : Mark n) : + inverseCount (t.diagnostic d)=inverseCount t.word := by + cases t <;> simp [diagnostic,word,inverseCount,List.countP_append,Nat.add_comm] + +lemma trace_error (j : ℝ) (a : Fin n→ℝ) (J : Matrix (Fin n) (Fin n) ℝ) + (hn : 0 + simpa only [scalar,one_mul,word,diagnostic,vector,SKGapCutoff.Recipe.vectorNorm] using + (rotated_small_word_trace_error j a d s J P Q ht).trans + (mul_le_mul_of_nonneg_left hb (norm_nonneg _)) + | average s P => + have H:=trace_small_diagonal_error d (wordPrediction j a 1 P) (exactWord j a P J) + rw [abs_mul] + exact (mul_le_mul_of_nonneg_left H (abs_nonneg _)).trans (by + change |Diagram.mean s| *(SKGapCutoff.Recipe.vectorNorm d*_)≤SKGapCutoff.Recipe.vectorNorm s*B + calc + _ ≤ |Diagram.mean s| *(SKGapCutoff.Recipe.vectorNorm d*B) := + mul_le_mul_of_nonneg_left (mul_le_mul_of_nonneg_left hb (norm_nonneg _)) (abs_nonneg _) + _ = (|Diagram.mean s| *SKGapCutoff.Recipe.vectorNorm d)*B := by ring + _ ≤ _ := mul_le_mul_of_nonneg_right (Primary.SmallMark.average_norm_product hn s d hd) hB) +end Mark + +abbrev Marked (n : ℕ) := List (ℝ×Mark n) +namespace Marked + +def plain (P : Marked n) : Polynomial n := P.map (fun t=>(t.1*t.2.scalar,t.2.word)) +def budget (P : Marked n) : ℝ := (P.map (fun t=>|t.1| *SKGapCutoff.Recipe.vectorNorm t.2.vector)).sum +def prepend (F : Word n) (P : Marked n) : Marked n := P.map (fun t=>(t.1,t.2.prepend F)) +def scale (c : ℝ) (P : Marked n) : Marked n := P.map (fun t=>(c*t.1,t.2)) +lemma plain_prefix (F : Word n) (P : Marked n) : + (P.prepend F).plain=P.plain.map (fun t=>(t.1,F++t.2)) := by + simp [prepend,plain,List.map_map,Function.comp_def,Mark.prefix_scalar,Mark.prefix_word] +lemma plain_scale (c : ℝ) (P : Marked n) : (P.scale c).plain=P.plain.map (fun t=>(c*t.1,t.2)) := by + simp [scale,plain,List.map_map,Function.comp_def,mul_assoc] +lemma plain_append (P Q : Marked n) : (P++Q).plain=P.plain++Q.plain := by simp [plain] +lemma budget_prefix (F : Word n) (P : Marked n) : (P.prepend F).budget=P.budget := by + simp [prepend,budget,List.map_map,Function.comp_def,Mark.prefix_vector] +lemma budget_scale (c : ℝ) (P : Marked n) : (P.scale c).budget=|c| *P.budget := by + induction P with + | nil => simp [scale,budget] + | cons t P ih => simp [scale,budget,abs_mul,mul_assoc,mul_add] at *;exact ih +lemma budget_append (P Q : Marked n) : (P++Q).budget=P.budget+Q.budget := by simp [budget] +lemma budget_nonneg (P : Marked n) : 0≤P.budget := by + apply List.sum_nonneg; intro r hr; obtain ⟨t,_,rfl⟩:=List.mem_map.mp hr + exact mul_nonneg (abs_nonneg _) (norm_nonneg _) + +theorem trace_error (j : ℝ) (a : Fin n→ℝ) (J : Matrix (Fin n) (Fin n) ℝ) (hn : 0 simp [plain,budget,matrixValue,prediction] + | cons t P ih => + have ht:=Mark.trace_error j a J hn d hd t.2 (hI t (by simp)) hB (hb t (by simp)) + have hh:=ih (fun s hs=>hI s (List.mem_cons_of_mem _ hs)) (fun s hs=>hb s (List.mem_cons_of_mem _ hs)) + simp only [plain,List.map_cons,matrixValue,List.sum_cons,prediction,budget] at * + simp only [mul_add,mul_smul_comm,trace_add,trace_smul,smul_eq_mul,Finset.sum_add_distrib,add_mul] + have he : (∑i,d i*(t.1*t.2.scalar*wordPrediction j a 1 t.2.word i))= + t.1*t.2.scalar*(∑i,d i*wordPrediction j a 1 t.2.word i) := by + rw [Finset.mul_sum];apply Finset.sum_congr rfl;intro i _;ring + rw [he] + have hc:=mul_le_mul_of_nonneg_left ht (abs_nonneg t.1) + rw [←abs_mul] at hc + calc + _ = |t.1*(t.2.scalar*(trace (Matrix.diagonal d*exactWord j a t.2.word J)- + ∑i,d i*wordPrediction j a 1 t.2.word i))+ + (trace (Matrix.diagonal d*(List.map (fun p=>p.1 • exactWord j a p.2 J) + (List.map (fun t=>(t.1*t.2.scalar,t.2.word)) P)).sum)- + ∑i,d i*(List.map (fun p=>p.1*wordPrediction j a 1 p.2 i) + (List.map (fun t=>(t.1*t.2.scalar,t.2.word)) P)).sum)| := by congr 1;ring + _ ≤ _ := (abs_add_le _ _).trans (add_le_add (by convert! hc using 1; ring) hh) +end Marked +end SKGap.Noncrossing.ClosedMarked + +end +end + +section + +noncomputable section +open scoped BigOperators Matrix.Norms.Frobenius +namespace SKGap.Noncrossing.ClosedMarked +open Matrix Primary Primary.Tensor.Series +variable {n : ℕ} + +lemma ungrade_append (P Q : GradedWords (Fin n)) : ungrade (P++Q)=ungrade P++ungrade Q := by simp [ungrade] +lemma ungrade_bump (P : GradedWords (Fin n)) : ungrade (GradedWords.bump P)=ungrade P := by + simp [ungrade,GradedWords.bump,List.map_map,Function.comp_def] +lemma ungrade_prepend (l : WordLetter (Fin n)) (P : GradedWords (Fin n)) : + ungrade (GradedWords.prepend l P)=(ungrade P).map (fun t=>(t.1,l::t.2)) := by + simp [ungrade,GradedWords.prepend,List.map_map,Function.comp_def] +lemma ungrade_scale (c : ℝ) (P : GradedWords (Fin n)) : + ungrade (GradedWords.scale c P)=(ungrade P).map (fun t=>(c*t.1,t.2)) := by + simp [ungrade,GradedWords.scale,List.map_map,Function.comp_def] + +namespace Marked + +def diagonalWords (s : Fin n→ℝ) (P : GradedWords (Fin n)) : Marked n := + P.map (fun t=>(t.1,Mark.diagonal [] s t.2.2)) +def averageWords (c : ℝ) (s : Fin n→ℝ) (P : GradedWords (Fin n)) : Marked n := + P.map (fun t=>(c*t.1,Mark.average s t.2.2)) +def mass (P : GradedWords (Fin n)) : ℝ := (P.map (fun t=>|t.1|)).sum +lemma plain_diagonalWords (s : Fin n→ℝ) (P : GradedWords (Fin n)) : + (diagonalWords s P).plain=ungrade (GradedWords.prepend (.diag s) P) := by + simp [diagonalWords,plain,ungrade,GradedWords.prepend,List.map_map,Function.comp_def,Mark.scalar,Mark.word] +lemma plain_averageWords (c : ℝ) (s : Fin n→ℝ) (P : GradedWords (Fin n)) : + (averageWords c s P).plain=ungrade (GradedWords.scale (c*Diagram.mean s) P) := by + simp only [averageWords,plain,ungrade,GradedWords.scale,List.map_map,Function.comp_def,Mark.scalar,Mark.word] + congr 1;funext t;congr 1;ring +lemma budget_diagonalWords (s : Fin n→ℝ) (P : GradedWords (Fin n)) : + (diagonalWords s P).budget=SKGapCutoff.Recipe.vectorNorm s*mass P := by + induction P with + | nil => simp [diagonalWords,budget,mass] + | cons t P ih => + simp only [diagonalWords,List.map_cons,budget,List.sum_cons,Mark.vector,mass] at * + rw [ih];ring +lemma budget_averageWords (c : ℝ) (s : Fin n→ℝ) (P : GradedWords (Fin n)) : + (averageWords c s P).budget=|c| *SKGapCutoff.Recipe.vectorNorm s*mass P := by + induction P with + | nil => simp [averageWords,budget,mass] + | cons t P ih => + simp only [averageWords,List.map_cons,budget,List.sum_cons,Mark.vector,mass,abs_mul] at * + rw [ih];ring + +lemma bounded_of_plain (P : Marked n) (Q : GradedWords (Fin n)) (h : P.plain=ungrade Q) + (hQ : GradedWords.bounded 1 Q) : ∀t∈P,inverseCount t.2.word≤1 := by + intro t ht + have hp : (t.1*t.2.scalar,t.2.word)∈ungrade Q := h ▸ List.mem_map.mpr ⟨t,ht,rfl⟩ + obtain ⟨q,hq,he⟩:=List.mem_map.mp hp + have hword : q.2.2=t.2.word := congrArg Prod.snd he + rw [←hword] + exact hQ q hq +end Marked + +abbrev Pair (n : ℕ) := Marked n×Marked n +def pairPlain (P : Pair n) : Polynomial n×Polynomial n := (P.1.plain,P.2.plain) +def pairUngrade (P : GradedWords (Fin n)×GradedWords (Fin n)) := (ungrade P.1,ungrade P.2) +def zeroPair : Pair n := ([(0,.average 0 [])],[(0,.average 0 [.noise])]) +lemma zeroPair_plain (j : ℝ) : pairPlain (zeroPair (n:=n))=pairUngrade (GradedWords.ordinaryWords j (.leaf 0)) := by + simp [pairPlain,pairUngrade,zeroPair,Marked.plain,Mark.scalar,Mark.word,GradedWords.ordinaryWords, + GradedWords.scalar,GradedWords.bump,GradedWords.prepend,ungrade] + +def implicitPair (j : ℝ) (a p : Fin n→ℝ) (t : SourceTree (Fin n→ℝ)) : Pair n := + let T:=GradedWords.ordinaryWords j t + let S:=(Marked.diagonalWords p T.2).prepend [.inverse]++ + (Marked.averageWords (-j) p T.1).prepend [.inverse,.diag a] + (S,(S.prepend [.noise]++S.scale (-(j*Diagram.mean a)))++Marked.averageWords (-j) p T.1) + +lemma implicitPair_plain (j : ℝ) (a p : Fin n→ℝ) (t : SourceTree (Fin n→ℝ)) : + pairPlain (implicitPair j a p t)=pairUngrade (GradedWords.implicitSource j a p t,GradedWords.implicitField j a p t) := by + have hs : (implicitPair j a p t).1.plain=ungrade (GradedWords.implicitSource j a p t) := by + simp only [implicitPair,Marked.plain_append,Marked.plain_prefix,Marked.plain_diagonalWords, + Marked.plain_averageWords,GradedWords.implicitSource,ungrade_prepend,ungrade_append, + ungrade_scale,ungrade_bump,List.map_append,List.map_map,Function.comp_def, + List.cons_append,List.nil_append,neg_mul] + apply Prod.ext hs + dsimp only [pairPlain,pairUngrade] + change ((implicitPair j a p t).1.prepend [.noise]++ + (implicitPair j a p t).1.scale (-(j*Diagram.mean a))++Marked.averageWords (-j) p (GradedWords.ordinaryWords j t).1).plain=_ + rw [Marked.plain_append,Marked.plain_append,Marked.plain_prefix,Marked.plain_scale,hs,Marked.plain_averageWords] + simp [GradedWords.implicitField,ungrade_append,ungrade_bump,ungrade_scale,ungrade_prepend,neg_mul] + +def smallBranch (j : ℝ) (p : Fin n→ℝ) (T : GradedWords (Fin n)×GradedWords (Fin n)) (V : Pair n) : Pair n := + (Marked.diagonalWords p T.2++V.1, + ((Marked.diagonalWords p T.2).prepend [.noise]++Marked.averageWords (-j) p T.1)++V.2) +def boundedBranch (j : ℝ) (p : Fin n→ℝ) (U V : Pair n) : Pair n := + (U.2.prepend [.diag p]++V.1, + (U.2.prepend [.noise,.diag p]++U.1.scale (-(j*Diagram.mean p)))++V.2) +lemma smallBranch_plain (j : ℝ) (p : Fin n→ℝ) (T V : GradedWords (Fin n)×GradedWords (Fin n)) + (Q : Pair n) (hQ : pairPlain Q=pairUngrade V) : + pairPlain (smallBranch j p T Q)=pairUngrade (GradedWords.branch j p T V) := by + have h₁ : Q.1.plain=ungrade V.1 := congrArg Prod.fst hQ + have h₂ : Q.2.plain=ungrade V.2 := congrArg Prod.snd hQ + simp [pairPlain,smallBranch,Marked.plain_append,Marked.plain_prefix,Marked.plain_diagonalWords, + Marked.plain_averageWords,h₁,h₂,pairUngrade,GradedWords.branch,ungrade_append,ungrade_bump, + ungrade_prepend,ungrade_scale,List.map_map,Function.comp_def,neg_mul] +lemma boundedBranch_plain (j : ℝ) (p : Fin n→ℝ) (T V : GradedWords (Fin n)×GradedWords (Fin n)) + (P Q : Pair n) (hP : pairPlain P=pairUngrade T) (hQ : pairPlain Q=pairUngrade V) : + pairPlain (boundedBranch j p P Q)=pairUngrade (GradedWords.branch j p T V) := by + have h₁ : P.1.plain=ungrade T.1 := congrArg Prod.fst hP + have h₂ : P.2.plain=ungrade T.2 := congrArg Prod.snd hP + have h₃ : Q.1.plain=ungrade V.1 := congrArg Prod.fst hQ + have h₄ : Q.2.plain=ungrade V.2 := congrArg Prod.snd hQ + simp [pairPlain,boundedBranch,Marked.plain_append,Marked.plain_prefix,Marked.plain_scale, + h₁,h₂,h₃,h₄,pairUngrade,GradedWords.branch,ungrade_append,ungrade_bump,ungrade_prepend, + ungrade_scale,List.map_map,Function.comp_def] + +inductive SmallTree (n : ℕ) where + | zero + | implicit : (Fin n→ℝ)→SourceTree (Fin n→ℝ)→SmallTree n + | small : (Fin n→ℝ)→ClosedTree (Fin n→ℝ)→SmallTree n→SmallTree n + | bounded : (Fin n→ℝ)→SmallTree n→SmallTree n→SmallTree n +namespace SmallTree + +def tree : SmallTree n→ClosedTree (Fin n→ℝ) + | .zero=>.leaf 0 + | .implicit p T=>.implicit p T + | .small p T V=>.branch p T V.tree + | .bounded p T V=>.branch p T.tree V.tree +def marked (j : ℝ) (a : Fin n→ℝ) : SmallTree n→Pair n + | .zero=>zeroPair + | .implicit p T=>implicitPair j a p T + | .small p T V=>smallBranch j p (T.words j a) (V.marked j a) + | .bounded p T V=>boundedBranch j p (T.marked j a) (V.marked j a) +lemma leafMass (T : SmallTree n) : T.tree.leafMass=0 := by + induction T with + | zero=>rfl + | implicit=>rfl + | small p U V ih=>exact ih + | bounded p U V ih1 ih2=>exact ih2 +lemma plain (j : ℝ) (a : Fin n→ℝ) (T : SmallTree n) : + pairPlain (T.marked j a)=pairUngrade (T.tree.words j a) := by + induction T with + | zero=>exact zeroPair_plain j + | implicit p U=>exact implicitPair_plain j a p U + | small p U V ih=>exact smallBranch_plain j p (U.words j a) (V.tree.words j a) (V.marked j a) ih + | bounded p U V ih1 ih2 => + exact boundedBranch_plain j p (U.tree.words j a) (V.tree.words j a) + (U.marked j a) (V.marked j a) ih1 ih2 + +theorem diagonal (j : ℝ) (a : Fin n→ℝ) (J : Matrix (Fin n) (Fin n) ℝ) (hn : 0⟨(h d hd).1,(h d hd).2.trans hLK⟩ + +lemma MarkControl.prepend {A : ℝ} {L : ℕ} {t : Mark n} (h : MarkControl A L t) + (P : Word n) (hp : closedWordBounded A P) : MarkControl A (L+P.length) (t.prepend P) := by + intro d hd + rcases h d hd with ⟨hb,hl⟩ + cases t with + | diagonal Q s R=> + simp only [Mark.prepend,Mark.diagnostic,List.length_append,List.length_cons] at * + constructor + · intro l hh + simp only [List.mem_append,List.mem_cons] at hh + rcases hh with hh|hh|hh|hh + · exact hb l (List.mem_append_left _ hh) + · subst l; exact hb (.diag d) (by simp) + · exact hp l hh + · exact hb l (by simp [hh]) + · omega + | average s Q=> + simp only [Mark.prepend,Mark.diagnostic] at * + exact ⟨closedWordBounded_append hp hb,by simp only [List.length_append]; omega⟩ + +lemma MarkedControl.append {A : ℝ} {L : ℕ} {P Q : Marked n} + (hp : MarkedControl A L P) (hq : MarkedControl A L Q) : MarkedControl A L (P++Q) := by + intro t ht; rcases List.mem_append.mp ht with ht|ht + · exact hp t ht + · exact hq t ht + +lemma MarkedControl.mono {A : ℝ} {L K : ℕ} {P : Marked n} + (h : MarkedControl A L P) (hLK : L≤K) : MarkedControl A K P := fun t ht=>(h t ht).mono hLK + +lemma MarkedControl.prepend {A : ℝ} {L : ℕ} {P : Marked n} + (h : MarkedControl A L P) (w : Word n) (hw : closedWordBounded A w) : + MarkedControl A (L+w.length) (P.prepend w) := by + intro t ht + obtain ⟨s,hs,rfl⟩:=List.mem_map.mp ht + exact (h s hs).prepend w hw + +lemma MarkedControl.scale {A : ℝ} {L : ℕ} {P : Marked n} + (h : MarkedControl A L P) (c : ℝ) : MarkedControl A L (P.scale c) := by + intro t ht + obtain ⟨s,hs,rfl⟩:=List.mem_map.mp ht + exact h s hs + +lemma diagonalWords_control {A : ℝ} {L : ℕ} (hA : 1≤A) (s : Fin n→ℝ) + (P : GradedWords (Fin n)) (hP : ∀t∈P,closedWordBounded A t.2.2 ∧ t.2.2.length≤L) : + MarkedControl A (L+1) (diagonalWords s P) := by + intro t ht d hd + obtain ⟨r,hr,he⟩:=List.mem_map.mp ht + subst t + simp only [Mark.diagnostic,List.length_append,List.length_cons,List.length_nil] + exact ⟨closedWordBounded_diag (hP r hr).1 d (fun i=>(hd i).trans hA),by have hh:=(hP r hr).2; omega⟩ + +lemma averageWords_control {A : ℝ} {L : ℕ} (c : ℝ) (s : Fin n→ℝ) + (P : GradedWords (Fin n)) (hP : ∀t∈P,closedWordBounded A t.2.2 ∧ t.2.2.length≤L) : + MarkedControl A L (averageWords c s P) := by + intro t ht d hd + obtain ⟨r,hr,he⟩:=List.mem_map.mp ht + subst t + exact hP r hr + +lemma zeroPair_control {A : ℝ} {L : ℕ} (hL : 1≤L) : PairControl (n:=n) A L zeroPair := by + constructor + · intro t ht; have he:=List.mem_singleton.mp ht; subst t + intro d hd; exact ⟨by intro l hl; simp [Mark.diagnostic] at hl,by simp [Mark.diagnostic]⟩ + · intro t ht; have he:=List.mem_singleton.mp ht; subst t + intro d hd + constructor + · intro l hl + have he : l=WordLetter.noise := by simpa [Mark.diagnostic] using hl + subst l + trivial + · simpa [Mark.diagnostic] using hL + +lemma smallBranch_control {A : ℝ} {L K : ℕ} (hA : 1≤A) (hLK : L+2≤K) + (j : ℝ) (p : Fin n→ℝ) (T : GradedWords (Fin n)×GradedWords (Fin n)) (V : Pair n) + (hT : (∀t∈T.1,closedWordBounded A t.2.2 ∧ t.2.2.length≤L) ∧ + (∀t∈T.2,closedWordBounded A t.2.2 ∧ t.2.2.length≤L)) + (hV : PairControl A K V) : PairControl A K (smallBranch j p T V) := by + have hd:=diagonalWords_control hA p _ hT.2 + have ha:=averageWords_control (-j) p _ hT.1 + have hn : closedWordBounded (n:=n) A [.noise] := by intro l hl; have he:=List.mem_singleton.mp hl; subst l; trivial + refine ⟨(hd.mono (by omega)).append hV.1,?_⟩ + exact (((hd.prepend [.noise] hn).mono (by simp only [List.length_cons,List.length_nil]; omega)).append (ha.mono (by omega))).append hV.2 + +lemma boundedBranch_control {A : ℝ} {L K : ℕ} (hLK : L+2≤K) + (j : ℝ) (p : Fin n→ℝ) (hp : ∀i,|p i|≤A) (U V : Pair n) + (hU : PairControl A L U) (hV : PairControl A K V) : PairControl A K (boundedBranch j p U V) := by + have hd : closedWordBounded (n:=n) A [.diag p] := by intro l hl; have he:=List.mem_singleton.mp hl; subst l; exact hp + have hd' : closedWordBounded (n:=n) A [.noise,.diag p] := by + intro l hl; simp only [List.mem_cons,List.not_mem_nil,or_false] at hl + rcases hl with rfl|rfl + · trivial + · exact hp + refine ⟨((hU.2.prepend [.diag p] hd).mono (by simp only [List.length_singleton]; omega)).append hV.1,?_⟩ + exact (((hU.2.prepend [.noise,.diag p] hd').mono (by simp only [List.length_cons,List.length_nil]; omega)).append + ((hU.1.scale _).mono (by omega))).append hV.2 + +end SKGap.Noncrossing.ClosedMarked + +end +end + +section + +noncomputable section +open scoped BigOperators +namespace SKGap.Noncrossing.ClosedMarked +open SKGapCutoff.Recipe Primary Primary.Tensor.Series Marked +variable {n : ℕ} + +def GradedControl (A : ℝ) (L : ℕ) (P : GradedWords (Fin n)) : Prop := + ∀v∈P,closedWordBounded A v.2.2 ∧ v.2.2.length≤L + +lemma PairControl.mono {A : ℝ} {L K : ℕ} {P : Pair n} (h : PairControl A L P) (hLK : L≤K) : + PairControl A K P := ⟨h.1.mono hLK,h.2.mono hLK⟩ +lemma implicitPair_control (j : ℝ) (a p : Fin n→ℝ) (T : SourceTree (Fin n→ℝ)) + {A : ℝ} {L : ℕ} (hA : 1≤A) (ha : ∀i,|a i|≤A) + (hT : GradedControl A L (GradedWords.ordinaryWords j T).1 ∧ + GradedControl A L (GradedWords.ordinaryWords j T).2) : + PairControl A (L+3) (implicitPair j a p T) := by + have hd:=diagonalWords_control hA p _ hT.2 + have hm:=averageWords_control (-j) p _ hT.1 + have hb : closedWordBounded (n:=n) A [.inverse] := by + intro l hl;have he:=List.mem_singleton.mp hl;subst l;trivial + have hba : closedWordBounded A [.inverse,.diag a] := by + intro l hl;simp only [List.mem_cons,List.not_mem_nil,or_false] at hl + rcases hl with rfl|rfl + · trivial + · exact ha + have hS : MarkedControl A (L+2) (implicitPair j a p T).1 := by + exact ((hd.prepend [.inverse] hb).mono (by simp)).append + ((hm.prepend [.inverse,.diag a] hba).mono (by simp)) + have hn : closedWordBounded (n:=n) A [.noise] := by + intro l hl;have he:=List.mem_singleton.mp hl;subst l;trivial + refine ⟨hS.mono (by omega),?_⟩ + exact (((hS.prepend [.noise] hn).mono (by simp)).append + ((hS.scale _).mono (by omega))).append (hm.mono (by omega)) + +namespace SmallTree +lemma smallBranches_control (j : ℝ) (a₀ : Fin n→ℝ) {A : ℝ} {L K : ℕ} + (hA : 1≤A) (hLK : L+2≤K) + (xs : List ((Fin n→ℝ)×ClosedTree (Fin n→ℝ))) (U : SmallTree n) + (hT : ∀t∈xs,GradedControl A L (t.2.words j a₀).1 ∧ GradedControl A L (t.2.words j a₀).2) + (hU : PairControl A K (U.marked j a₀)) : + PairControl A K ((smallBranches xs U).marked j a₀) := by + induction xs with + | nil=>exact hU + | cons t xs ih=> + exact smallBranch_control hA hLK j _ _ _ (hT t (by simp)) (ih (fun v hv=>hT v (by simp [hv]))) +lemma boundedBranches_control (j : ℝ) (a₀ : Fin n→ℝ) {A : ℝ} {L K : ℕ} + (hLK : L+2≤K) + (xs : List ((Fin n→ℝ)×SmallTree n)) (U : SmallTree n) + (ha : ∀t∈xs,∀i,|t.1 i|≤A) (hT : ∀t∈xs,PairControl A L (t.2.marked j a₀)) + (hU : PairControl A K (U.marked j a₀)) : + PairControl A K ((boundedBranches xs U).marked j a₀) := by + induction xs with + | nil=>exact hU + | cons t xs ih=> + exact boundedBranch_control hLK j _ (ha t (by simp)) _ _ (hT t (by simp)) + (ih (fun v hv=>ha v (by simp [hv])) (fun v hv=>hT v (by simp [hv]))) +end SmallTree +end SKGap.Noncrossing.ClosedMarked +namespace SKGapCutoff.Recipe.OrdinaryData +open Primary SKGap SKGap.Noncrossing SKGap.Noncrossing.Primary SKGap.Noncrossing.Primary.Tensor.Series +open SKGap.Noncrossing.ClosedMarked +variable {n : ℕ} {ι κ σ : Type*} [Fintype ι] [DecidableEq ι] [Fintype κ] [DecidableEq κ] [Fintype σ] +variable (D : OrdinaryData n ι κ σ) + +theorem startedMarked_control (w y : VectorFields n) (T : ι→SourceTree (Fin n→ℝ)) + (t₀ : SmallTree n) (a₀ : Fin n→ℝ) (x : Spin n) (N L : ℕ) {A : ℝ} (hA : 1≤A) + (hinit : SKGap.Noncrossing.ClosedMarked.PairControl A (L+3) (t₀.marked D.j a₀)) + (hT : ∀l,GradedControl A L (GradedWords.ordinaryWords D.j (T l)).1 ∧ + GradedControl A L (GradedWords.ordinaryWords D.j (T l)).2) + (ha : ∀a≤N,∀b i,|D.auxCoefficient a b x i|≤A) : + ∀a≤N,SKGap.Noncrossing.ClosedMarked.PairControl A (L+2*a+3) ((D.startedSmallTree w y T t₀ x a).marked D.j a₀) := by + intro a + induction a using Nat.strong_induction_on with + | h a ih=> + intro haN + rcases a with _|r + · simpa only [startedSmallTree,Nat.mul_zero,Nat.add_zero] using hinit + · rw [startedSmallTree] + apply SmallTree.smallBranches_control D.j a₀ (L:=L) hA (by omega) + · intro t ht + obtain ⟨l,hl,rfl⟩:=List.mem_map.mp ht + simpa only [ClosedTree.words_ofOrdinary] using hT l + · apply SmallTree.boundedBranches_control D.j a₀ (L:=L+2*r+3) (by omega) + · intro t ht;obtain ⟨b,hb,rfl⟩:=List.mem_map.mp ht + exact ha (r+1) haN b + · intro t ht;obtain ⟨b,hb,rfl⟩:=List.mem_map.mp ht + exact (ih b b.isLt (b.isLt.le.trans haN)).mono (by omega) + · exact SKGap.Noncrossing.ClosedMarked.zeroPair_control (by omega) +end SKGapCutoff.Recipe.OrdinaryData + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/ClosedPrediction.lean b/lean/OAI/Probability/SKGap/Localization/ClosedPrediction.lean new file mode 100644 index 0000000000000000000000000000000000000000..226ff7ffb5c6a9c8f7cd79c7ac0df6525bfae0a3 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/ClosedPrediction.lean @@ -0,0 +1,171 @@ +import Mathlib +import OAI.Probability.SKGap.Matrix.WordFockSeries + +namespace OAI + +section + +noncomputable section +open scoped BigOperators +namespace SKGap.Noncrossing.Primary.Tensor.Series +open Diagram InverseDiagram WordSeries Loop +variable {ι : Type*} [Fintype ι] +namespace GradedWords + +def branch (j : ℝ) (p : ι→ℝ) (U V : GradedWords ι×GradedWords ι) : GradedWords ι×GradedWords ι := + (prepend (.diag p) U.2++V.1, + (bump (prepend .noise (prepend (.diag p) U.2))++ + scale (-(j*Diagram.mean p)) (bump (bump U.1)))++V.2) +def ordinaryWords (j : ℝ) : SourceTree (ι→ℝ)→GradedWords ι×GradedWords ι + | .leaf c => (scalar c,bump (prepend .noise (scalar c))) + | .branch p t u => branch j p (ordinaryWords j t) (ordinaryWords j u) +def implicitSource (j : ℝ) (a p : ι→ℝ) (t : SourceTree (ι→ℝ)) : GradedWords ι := + prepend .inverse (prepend (.diag p) (ordinaryWords j t).2++ + scale (-(j*Diagram.mean p)) (bump (bump (prepend (.diag a) (ordinaryWords j t).1)))) +def implicitField (j : ℝ) (a p : ι→ℝ) (t : SourceTree (ι→ℝ)) : GradedWords ι := + (bump (prepend .noise (implicitSource j a p t))++ + scale (-(j*Diagram.mean a)) (bump (bump (implicitSource j a p t))))++ + scale (-(j*Diagram.mean p)) (bump (bump (ordinaryWords j t).1)) + +def pairSeq (j : ℝ) (a : ι→ℝ) (P : GradedWords ι×GradedWords ι) := + (seq j a P.1,seq j a P.2) +lemma pairSeq_branch (j : ℝ) (a p : ι→ℝ) (U V : GradedWords ι×GradedWords ι) : + pairSeq j a (branch j p U V)= + (branchSource p (pairSeq j a U) (pairSeq j a V), + branchField j p (pairSeq j a U) (pairSeq j a V)) := by + simp [pairSeq,branch,branchSource,branchField,seq_append,seq_bump,seq_prepend, + seq_scale,letterOperator,sub_eq_add_neg,add_assoc] +lemma pairSeq_ordinary (j : ℝ) (a : ι→ℝ) (t : SourceTree (ι→ℝ)) : + pairSeq j a (ordinaryWords j t)=ordinary j t := by + induction t with + | leaf c => + simp [ordinaryWords,pairSeq,seq_scalar,seq_bump,seq_prepend,letterOperator, + ordinary,act_ofVector] + | branch p t u ih1 ih2 => simp only [ordinaryWords,pairSeq_branch,ih1,ih2,ordinary] +lemma seq_implicitSource (j : ℝ) (a p : ι→ℝ) (t : SourceTree (ι→ℝ)) : + seq j a (implicitSource j a p t)=loopSource j a p t := by + have h1:=congrArg Prod.fst (pairSeq_ordinary j a t) + have h2:=congrArg Prod.snd (pairSeq_ordinary j a t) + simp only [pairSeq] at h1 h2 + simp [implicitSource,seq_prepend,seq_append,seq_scale,seq_bump,letterOperator, + h1,h2,loopSource,sub_eq_add_neg] +lemma seq_implicitField (j : ℝ) (a p : ι→ℝ) (t : SourceTree (ι→ℝ)) : + seq j a (implicitField j a p t)=loopField j a p t := by + have h1:=congrArg Prod.fst (pairSeq_ordinary j a t) + simp only [pairSeq] at h1 + simp [implicitField,seq_prepend,seq_append,seq_scale,seq_bump,letterOperator, + h1,seq_implicitSource,loopField,sub_eq_add_neg,add_assoc] + +section +omit [Fintype ι] + +def bounded (k : ℕ) (P : GradedWords ι) : Prop := ∀ t∈P,inverseCount t.2.2≤k +lemma bounded_mono {k l : ℕ} (hkl : k≤l) {P : GradedWords ι} (h : bounded k P) : bounded l P := + fun t ht=>(h t ht).trans hkl +lemma bounded_scalar (k : ℕ) (c : ℝ) : bounded k (scalar (ι:=ι) c) := by + rintro t ht + simp only [scalar,List.mem_singleton] at ht + subst t + simp [inverseCount] +lemma bounded_append {k : ℕ} {P Q : GradedWords ι} (hP : bounded k P) (hQ : bounded k Q) : + bounded k (P++Q) := by + intro t ht + rcases List.mem_append.mp ht with h|h + · exact hP t h + · exact hQ t h +lemma bounded_scale {k : ℕ} {P : GradedWords ι} (c : ℝ) (hP : bounded k P) : bounded k (scale c P) := by + intro t ht + obtain ⟨s,hs,rfl⟩:=List.mem_map.mp ht + exact hP s hs +lemma bounded_bump {k : ℕ} {P : GradedWords ι} (hP : bounded k P) : bounded k (bump P) := by + intro t ht + obtain ⟨s,hs,rfl⟩:=List.mem_map.mp ht + exact hP s hs +lemma bounded_diag {k : ℕ} {P : GradedWords ι} (d : ι→ℝ) (hP : bounded k P) : + bounded k (prepend (.diag d) P) := by + intro t ht + obtain ⟨s,hs,rfl⟩:=List.mem_map.mp ht + exact hP s hs +lemma bounded_noise {k : ℕ} {P : GradedWords ι} (hP : bounded k P) : + bounded k (prepend .noise P) := by + intro t ht + obtain ⟨s,hs,rfl⟩:=List.mem_map.mp ht + exact hP s hs +lemma bounded_inverse {k : ℕ} {P : GradedWords ι} (hP : bounded k P) : + bounded (k+1) (prepend .inverse P) := by + intro t ht + obtain ⟨s,hs,rfl⟩:=List.mem_map.mp ht + simpa only [inverseCount_inverse] using Nat.add_le_add_right (hP s hs) 1 + +end + +lemma bounded_branch {k : ℕ} (j : ℝ) (p : ι→ℝ) {U V : GradedWords ι×GradedWords ι} + (hU : bounded k U.1 ∧ bounded k U.2) (hV : bounded k V.1 ∧ bounded k V.2) : + bounded k (branch j p U V).1 ∧ bounded k (branch j p U V).2 := by + exact ⟨bounded_append (bounded_diag _ hU.2) hV.1, + bounded_append (bounded_append (bounded_bump (bounded_noise (bounded_diag _ hU.2))) + (bounded_scale _ (bounded_bump (bounded_bump hU.1)))) hV.2⟩ +lemma bounded_ordinary (j : ℝ) (t : SourceTree (ι→ℝ)) : + bounded 0 (ordinaryWords j t).1 ∧ bounded 0 (ordinaryWords j t).2 := by + induction t with + | leaf c => exact ⟨bounded_scalar 0 c,bounded_bump (bounded_noise (bounded_scalar 0 c))⟩ + | branch p t u ih1 ih2 => exact bounded_branch j p ih1 ih2 +lemma bounded_implicitSource (j : ℝ) (a p : ι→ℝ) (t : SourceTree (ι→ℝ)) : + bounded 1 (implicitSource j a p t) := by + have h:=bounded_ordinary j t + exact bounded_inverse (bounded_append (bounded_diag _ h.2) + (bounded_scale _ (bounded_bump (bounded_bump (bounded_diag _ h.1))))) +lemma bounded_implicitField (j : ℝ) (a p : ι→ℝ) (t : SourceTree (ι→ℝ)) : + bounded 1 (implicitField j a p t) := by + have h:=bounded_implicitSource j a p t + exact bounded_append (bounded_append (bounded_bump (bounded_noise h)) + (bounded_scale _ (bounded_bump (bounded_bump h)))) + (bounded_scale _ (bounded_bump (bounded_bump (bounded_mono (by omega) (bounded_ordinary j t).1)))) +end GradedWords + +namespace ClosedTree +open GradedWords + +def words (j : ℝ) (a : ι→ℝ) : ClosedTree (ι→ℝ)→GradedWords ι×GradedWords ι + | .leaf c => ordinaryWords j (.leaf c) + | .implicit p t => (implicitSource j a p t,implicitField j a p t) + | .branch p t u => GradedWords.branch j p (t.words j a) (u.words j a) +lemma words_series (j : ℝ) (a : ι→ℝ) (t : ClosedTree (ι→ℝ)) : + pairSeq j a (t.words j a)=t.series j a := by + induction t with + | leaf c => exact pairSeq_ordinary j a (.leaf c) + | implicit p t => exact Prod.ext (seq_implicitSource j a p t) (seq_implicitField j a p t) + | branch p t u ih1 ih2 => simp only [words,pairSeq_branch,ih1,ih2,series] +lemma words_bounded (j : ℝ) (a : ι→ℝ) (t : ClosedTree (ι→ℝ)) : + bounded 1 (t.words j a).1 ∧ bounded 1 (t.words j a).2 := by + induction t with + | leaf c => + exact ⟨bounded_mono (by omega) (bounded_ordinary j (.leaf c)).1, + bounded_mono (by omega) (bounded_ordinary j (.leaf c)).2⟩ + | implicit p t => exact ⟨bounded_implicitSource j a p t,bounded_implicitField j a p t⟩ + | branch p t u ih1 ih2 => exact bounded_branch j p ih1 ih2 + +theorem field_prediction_zero (j : ℝ) (a : ι→ℝ) (t : ClosedTree (ι→ℝ)) (z : ℝ) (i : ι) : + prediction j a z (t.words j a).2 i=0 := by + apply prediction_zero_of_project j a _ (t.words_bounded j a).2 + intro n + have h:=congrArg Prod.snd (t.words_series j a) + change seq j a (t.words j a).2=(t.series j a).2 at h + rw [h] + exact t.project_field j a n ▸ rfl + +theorem source_prediction_zero (j : ℝ) (a : ι→ℝ) (t : ClosedTree (ι→ℝ)) + (ht : t.leafMass=0) (z : ℝ) (i : ι) : prediction j a z (t.words j a).1 i=0 := by + apply prediction_zero_of_project j a _ (t.words_bounded j a).1 + intro n + have h:=congrArg Prod.fst (t.words_series j a) + change seq j a (t.words j a).1=(t.series j a).1 at h + rw [h,t.project_source,ht] + split_ifs <;> rfl +end ClosedTree +end SKGap.Noncrossing.Primary.Tensor.Series + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/CoefficientFlip.lean b/lean/OAI/Probability/SKGap/Localization/CoefficientFlip.lean new file mode 100644 index 0000000000000000000000000000000000000000..f069735e022282b8d4dcf2b15764515d8a160d53 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/CoefficientFlip.lean @@ -0,0 +1,68 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.Taylor +import OAI.Probability.SKGap.Localization.ScalarVariance + +namespace OAI + +section + +noncomputable section +open Set +namespace SKGapCutoff.Recipe +variable {n : ℕ} {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] + +def flipHalfDiff (i : Fin n) (P : Spin n→E) (x : Spin n) : E := + (spin x i/2) • (P x-P (flip x i)) + +lemma flipHalfDiff_norm (i : Fin n) (P : Spin n→E) (x : Spin n) : + ‖flipHalfDiff i P x‖=‖P (flip x i)-P x‖/2 := by + simp only [flipHalfDiff,norm_smul,Real.norm_eq_abs,abs_div,abs_spin_eq_one,abs_of_pos (by norm_num : (0:ℝ)<2)] + rw [norm_sub_rev] + ring + +lemma flipHalfDiff_real (i : Fin n) (P : Spin n→ℝ) (x : Spin n) : + flipHalfDiff i P x=halfDiff i P x := by + rw [halfDiff_as_flip] + dsimp only [flipHalfDiff,smul_eq_mul] + ring + +lemma coefficient_linearization (i : Fin n) (P : Spin n→E) (x : Spin n) + (F : E→ℝ) (T : E→L[ℝ]ℝ) : + halfDiff i (fun y=>F (P y)) x-T (flipHalfDiff i P x)= + (-spin x i/2)*(F (P (flip x i))-F (P x)-T (P (flip x i)-P x)) := by + rw [halfDiff_as_flip] + simp only [flipHalfDiff,map_smul,map_sub,smul_eq_mul] + ring + +lemma coefficient_taylor (i : Fin n) (P : Spin n→E) (x : Spin n) + (F : E→ℝ) (F' : E→E→L[ℝ]ℝ) {L : ℝ} (hL : 0≤L) + (hF : ∀t∈Icc (0:ℝ) 1,HasFDerivAt F + (F' (P x+t • (P (flip x i)-P x))) (P x+t • (P (flip x i)-P x))) + (hLip : ∀t∈Icc (0:ℝ) 1, + ‖F' (P x+t • (P (flip x i)-P x))-F' (P x)‖≤L*‖t • (P (flip x i)-P x)‖) : + |halfDiff i (fun y=>F (P y)) x-F' (P x) (flipHalfDiff i P x)|≤ + 2*L*‖flipHalfDiff i P x‖^2 := by + have H:=SKGap.SourceTaylor.segment_taylor F F' (P x) (P (flip x i)) hL hF hLip + rw [coefficient_linearization,abs_mul,abs_div,abs_neg,abs_spin_eq_one, + abs_of_pos (by norm_num : (0:ℝ)<2),flipHalfDiff_norm] + calc + _ ≤ (1/2:ℝ)*(L*‖P (flip x i)-P x‖^2) := mul_le_mul_of_nonneg_left H (by norm_num) + _ = _ := by ring + +lemma coefficient_lipschitz (i : Fin n) (P : Spin n→E) (x : Spin n) + (F : E→ℝ) (F' : E→E→L[ℝ]ℝ) {C : ℝ} (hC : 0≤C) + (hF : ∀t∈Icc (0:ℝ) 1,HasFDerivAt F + (F' (P x+t • (P (flip x i)-P x))) (P x+t • (P (flip x i)-P x))) + (hBound : ∀t∈Icc (0:ℝ) 1,‖F' (P x+t • (P (flip x i)-P x))‖≤C) : + |halfDiff i (fun y=>F (P y)) x|≤C*‖flipHalfDiff i P x‖ := by + have H:=SKGap.SourceTaylor.segment_lipschitz F F' (P x) (P (flip x i)) hC hF hBound + rw [halfDiff_as_flip,abs_div,abs_mul,abs_spin_eq_one,one_mul, + abs_of_pos (by norm_num : (0:ℝ)<2),flipHalfDiff_norm,abs_sub_comm] + simpa only [mul_div_assoc] using div_le_div_of_nonneg_right H (show (0:ℝ)≤2 by norm_num) + +end SKGapCutoff.Recipe + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/CoefficientInputBridge.lean b/lean/OAI/Probability/SKGap/Localization/CoefficientInputBridge.lean new file mode 100644 index 0000000000000000000000000000000000000000..0144ed9d40739b17daf88afdde2d52787feac111 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/CoefficientInputBridge.lean @@ -0,0 +1,43 @@ +import Mathlib +import OAI.Probability.SKGap.Stability.OrdinaryClosure +import OAI.Probability.SKGap.Localization.RecipeCoefficientClosure + +namespace OAI + +section + +noncomputable section +open scoped BigOperators +namespace SKGapCutoff.Recipe +open SKGap.Noncrossing.Primary +variable {n : ℕ} {ι κ σ τ : Type*} [Fintype ι] [DecidableEq ι] [Fintype κ] [DecidableEq κ] [Fintype σ] [Fintype τ] + +namespace LocalConstants +def withCoefficient (c : LocalConstants) (K S : ℝ) (hK : 1≤K) (hS : 0≤S) : LocalConstants := + {c with A:=K,C:=K,S:=S,one_le_A:=hK,C_nonneg:=le_trans (by norm_num) hK,C_le_A:=le_rfl,S_nonneg:=hS} +end LocalConstants + +theorem LocalOrdinaryInput.with_coefficients {D : OrdinaryData n ι κ σ} {N : ℕ} + {T : ι→SourceTree (Fin n→ℝ)} {x : Spin n} {c : LocalConstants} + (h : LocalOrdinaryInput D T x N c) (E : OrdinaryData n ι κ τ) + (hJ : E.J=D.J) (hj : E.j=D.j) (hH : E.H=D.H) (hp : E.predecessor=D.predecessor) (hθ : E.θ=D.θ) + (A : ℕ) (K S : ℝ) (hK : 1≤K) (hS : 0≤S) + (hs : (∑s,vectorNorm (E.seed s))≤S) (hc : E.CoefficientClass A x K) : + LocalOrdinaryInput E T x A (c.withCoefficient K S hK hS) := by + refine ⟨h.dimension,?_,?_,?_,?_,?_,?_,hs,?_,hc.seedRegular,hc.auxRegular,?_,?_⟩ + · simpa only [hJ,LocalConstants.withCoefficient] using h.interaction + · simpa only [hH,LocalConstants.withCoefficient] using h.primaryShape + · simpa only [hH,hj,hJ,LocalConstants.withCoefficient] using h.primaryFieldError + · simpa only [hp,hj,hJ,LocalConstants.withCoefficient] using h.primarySourceError + · simpa only [hp] using h.primaryValue + · simpa only [hp,LocalConstants.withCoefficient] using h.primaryDerivative + · simpa only [hθ,LocalConstants.withCoefficient] using h.parameter + · intro a ha s i; exact (hc.seedValue a ha s).at i + · intro a ha b i; exact (hc.auxValue a ha b).at i + +end SKGapCutoff.Recipe + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/CoefficientRow.lean b/lean/OAI/Probability/SKGap/Localization/CoefficientRow.lean new file mode 100644 index 0000000000000000000000000000000000000000..a23e51ea2c0975b7643ed930f200f4a3e0aced83 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/CoefficientRow.lean @@ -0,0 +1,185 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.LocalCoefficient +import OAI.Probability.SKGap.Localization.Operation + +namespace OAI + +section + +noncomputable section +open scoped BigOperators Matrix.Norms.Frobenius +namespace SKGapCutoff.Recipe +open Primary Matrix +variable {n : ℕ} {ι κ : Type*} [Fintype ι] [Fintype κ] + +lemma row_vectorNorm_le_opNorm (D : Interaction n) (i : Fin n) : + vectorNorm (D i) ≤ SKGap.opNorm D := by + have h0 : 0≤SKGap.opNorm D := norm_nonneg _ + apply nonneg_le_nonneg_of_sq_le_sq h0 + simp only [←sq,vectorNorm_sq] + exact SKGap.SourceError.matrix_row_square_le D i + +lemma local_argument_row_bound (H : ι→VectorFields n) (θ : κ→Spin n→ℝ) + (x : Spin n) (i : Fin n) : + vectorNorm (fun k=>‖flipHalfDiff k (fun y=>localArgs H θ y i) x‖) ≤ + (∑l,SKGap.opNorm (derivativeMatrix (H l) x))+(∑α,‖derivativeVector (θ α) x‖) := by + have hQ (l : ι) : vectorNorm (fun k=>|derivativeMatrix (H l) x i k|)≤SKGap.opNorm (derivativeMatrix (H l) x) := by + rw [vectorNorm_abs]; exact row_vectorNorm_le_opNorm _ _ + have hT (α : κ) : vectorNorm (fun k=>|halfDiff k (θ α) x|)=‖derivativeVector (θ α) x‖ := by + rw [vectorNorm_abs]; rfl + calc + _ ≤ vectorNorm (fun k=>(∑l,|derivativeMatrix (H l) x i k|)+(∑α,|halfDiff k (θ α) x|)) := + vectorNorm_mono fun k=>by + have hp : 0≤(∑l,|derivativeMatrix (H l) x i k|)+(∑α,|halfDiff k (θ α) x|) := + add_nonneg (Finset.sum_nonneg fun _ _=>abs_nonneg _) (Finset.sum_nonneg fun _ _=>abs_nonneg _) + simpa only [abs_of_nonneg (norm_nonneg _),abs_of_nonneg hp] using local_argument_bound H θ x i k + _ ≤ vectorNorm (fun k=>∑l,|derivativeMatrix (H l) x i k|)+ + vectorNorm (fun k=>∑α,|halfDiff k (θ α) x|) := vectorNorm_add _ _ + _ ≤ (∑l,vectorNorm (fun k=>|derivativeMatrix (H l) x i k|))+ + ∑α,vectorNorm (fun k=>|halfDiff k (θ α) x|) := by + apply add_le_add + · convert! vectorNorm_sum (fun l k=>|derivativeMatrix (H l) x i k|) using 1 + congr 1; ext k; simp + · convert! vectorNorm_sum (fun α k=>|halfDiff k (θ α) x|) using 1 + congr 1; ext k; simp + _ ≤ _ := add_le_add (Finset.sum_le_sum fun l _=>hQ l) (by simp only [hT]; rfl) + +lemma coefficient_row_bound (H : ι→VectorFields n) (θ : κ→Spin n→ℝ) + (F : Fin n→Args (ι:=ι) (κ:=κ)→ℝ) + (F' : Fin n→Args (ι:=ι) (κ:=κ)→Args (ι:=ι) (κ:=κ)→L[ℝ]ℝ) + (x : Spin n) (i : Fin n) {L : ℝ} (hL : 0≤L) + (hF : ∀k t, t∈Set.Icc (0:ℝ) 1→HasFDerivAt (F i) + (F' i (localArgs H θ x i+t • (localArgs H θ (flip x k) i-localArgs H θ x i))) + (localArgs H θ x i+t • (localArgs H θ (flip x k) i-localArgs H θ x i))) + (hBound : ∀k t, t∈Set.Icc (0:ℝ) 1→ + ‖F' i (localArgs H θ x i+t • (localArgs H θ (flip x k) i-localArgs H θ x i))‖≤L) : + vectorNorm (derivativeMatrix (coefficient H θ F) x i) ≤ + L*((∑l,SKGap.opNorm (derivativeMatrix (H l) x))+(∑α,‖derivativeVector (θ α) x‖)) := by + calc + _ ≤ vectorNorm (fun k=>L*‖flipHalfDiff k (fun y=>localArgs H θ y i) x‖) := + vectorNorm_mono fun k=>by + rw [abs_of_nonneg (mul_nonneg hL (norm_nonneg _))] + exact coefficient_lipschitz k (fun y=>localArgs H θ y i) x (F i) (F' i) hL (hF k) (hBound k) + _ = L*vectorNorm (fun k=>‖flipHalfDiff k (fun y=>localArgs H θ y i) x‖) := by + convert! vectorNorm_smul L (fun k=>‖flipHalfDiff k (fun y=>localArgs H θ y i) x‖) using 1 + rw [abs_of_nonneg hL] + _ ≤ _ := mul_le_mul_of_nonneg_left (local_argument_row_bound H θ x i) hL + +end SKGapCutoff.Recipe + +end +end + +section + +noncomputable section +open scoped BigOperators Matrix.Norms.Frobenius +namespace SKGapCutoff.Recipe +open Primary Matrix +variable {n : ℕ} + +structure SmallBound (U : VectorFields n) (x : Spin n) (C : ℝ) : Prop where + nonneg : 0≤C + size : vectorNorm (U x)≤C + derivative : ‖derivativeMatrix U x‖≤C + +lemma derivativeMatrix_add (U V : VectorFields n) (x : Spin n) : + derivativeMatrix (fun x i=>U x i+V x i) x=derivativeMatrix U x+derivativeMatrix V x := by + ext i k; simp only [derivativeMatrix,halfDiff,Matrix.add_apply]; ring + +lemma derivativeMatrix_sum {ι : Type*} [Fintype ι] (U : ι→VectorFields n) (x : Spin n) : + derivativeMatrix (fun x i=>∑l,U l x i) x=∑l,derivativeMatrix (U l) x := by + ext i k; simp only [Matrix.sum_apply,derivativeMatrix,halfDiff_sum] + +lemma SmallBound.mono {U : VectorFields n} {x : Spin n} {C D : ℝ} + (h : SmallBound U x C) (hCD : C≤D) : SmallBound U x D := + ⟨h.nonneg.trans hCD,h.size.trans hCD,h.derivative.trans hCD⟩ + +lemma SmallBound.seed (s : Fin n→ℝ) (x : Spin n) : + SmallBound (fun _=>s) x (vectorNorm s) := by + refine ⟨vectorNorm_nonneg _,le_rfl,?_⟩ + have he : derivativeMatrix (fun _=>s) x=0 := by ext i k; simp [derivativeMatrix,halfDiff] + rw [he,norm_zero]; exact vectorNorm_nonneg _ + +lemma SmallBound.add {U V : VectorFields n} {x : Spin n} {C D : ℝ} + (hU : SmallBound U x C) (hV : SmallBound V x D) : + SmallBound (fun x i=>U x i+V x i) x (C+D) := by + refine ⟨add_nonneg hU.nonneg hV.nonneg,(vectorNorm_add _ _).trans (add_le_add hU.size hV.size),?_⟩ + rw [derivativeMatrix_add] + exact (norm_add_le _ _).trans (add_le_add hU.derivative hV.derivative) + +lemma SmallBound.smul {U : VectorFields n} {x : Spin n} {C : ℝ} + (hU : SmallBound U x C) (c : ℝ) : SmallBound (fun x i=>c*U x i) x (|c| *C) := by + refine ⟨mul_nonneg (abs_nonneg _) hU.nonneg,?_,?_⟩ + · calc + _ = |c| *vectorNorm (U x) := vectorNorm_smul _ _ + _ ≤ _ := mul_le_mul_of_nonneg_left hU.size (abs_nonneg _) + · rw [derivativeMatrix_smul,norm_smul,Real.norm_eq_abs] + exact mul_le_mul_of_nonneg_left hU.derivative (abs_nonneg _) + +lemma SmallBound.sub {U V : VectorFields n} {x : Spin n} {C D : ℝ} + (hU : SmallBound U x C) (hV : SmallBound V x D) : + SmallBound (fun x i=>U x i-V x i) x (C+D) := by + simpa only [abs_neg,abs_one,one_mul,neg_one_mul,sub_eq_add_neg] using hU.add (hV.smul (-1)) + +lemma SmallBound.sum {ι : Type*} [Fintype ι] {U : ι→VectorFields n} {x : Spin n} {C : ι→ℝ} + (hU : ∀l,SmallBound (U l) x (C l)) : + SmallBound (fun x i=>∑l,U l x i) x (∑l,C l) := by + refine ⟨Finset.sum_nonneg fun l _=>(hU l).nonneg,?_,?_⟩ + · have h:= (vectorNorm_sum (fun l=>U l x)).trans (Finset.sum_le_sum fun l _=>(hU l).size) + convert! h using 1 + congr 1; ext i; simp + · rw [derivativeMatrix_sum] + exact (norm_sum_le _ _).trans (Finset.sum_le_sum fun l _=>(hU l).derivative) + +lemma SmallBound.coefficient {U : VectorFields n} {x : Spin n} {C : ℝ} + (hU : SmallBound U x C) (a : VectorFields n) {A R : ℝ} + (hA : 0≤A) (hR : 0≤R) (ha : ∀i,|a x i|≤A) + (hda : ∀i,∑k,(derivativeMatrix a x i k)^2≤R^2) : + SmallBound (fun x i=>a x i*U x i) x (C*(A+3*R)) := by + refine ⟨mul_nonneg hU.nonneg (by positivity),?_,?_⟩ + · exact ((vectorNorm_mul _ _ hA ha).trans (mul_le_mul_of_nonneg_left hU.size hA)).trans + (by nlinarith [mul_nonneg hU.nonneg hR]) + · calc + _ ≤ A*‖derivativeMatrix U x‖+R*vectorNorm (U x)+2*R*‖derivativeMatrix U x‖ := + source_frobenius a U x hA hR ha hda + _ ≤ A*C+R*C+2*R*C := add_le_add (add_le_add + (mul_le_mul_of_nonneg_left hU.derivative hA) (mul_le_mul_of_nonneg_left hU.size hR)) + (mul_le_mul_of_nonneg_left hU.derivative (by positivity)) + _ = _ := by ring + +lemma SmallBound.linear {U : VectorFields n} {x : Spin n} {C : ℝ} + (hU : SmallBound U x C) (J : Interaction n) : + SmallBound (fun x=>J.mulVec (U x)) x (SKGap.opNorm J*C) := by + refine ⟨mul_nonneg (norm_nonneg _) hU.nonneg, + (vectorNorm_matrix_mul _ _).trans (mul_le_mul_of_nonneg_left hU.size (norm_nonneg _)),?_⟩ + have he : derivativeMatrix (fun x=>J.mulVec (U x)) x=J*derivativeMatrix U x := by + convert! derivativeMatrix_linear J U (fun _=>0) x using 1 + simp only [zero_add]; rfl + rw [he] + exact (SKGap.frobenius_mul_le_opNorm _ _).trans (mul_le_mul_of_nonneg_left hU.derivative (norm_nonneg _)) + +lemma SmallBound.primaryCorrection {U : VectorFields n} {x : Spin n} {C P : ℝ} + (hU : SmallBound U x C) (m : VectorFields n) (hn : 0siteMean U y*m y i) x (C*(1+3*P)) := by + refine ⟨mul_nonneg hU.nonneg (by positivity),?_, + primary_mean_frobenius U m x hn hU.nonneg hP hU.size hU.derivative hm hdm⟩ + exact ((primary_mean_size U m x hn hm).trans hU.size).trans (by nlinarith [mul_nonneg hU.nonneg hP]) + +lemma SmallBound.auxiliaryCorrection {U : VectorFields n} {x : Spin n} {C : ℝ} + (hU : SmallBound U x C) (a : VectorFields n) {A R : ℝ} + (hA : 0≤A) (hR : 0≤R) (ha : ∀i,|a x i|≤A) + (hda : ∀i,∑k,(derivativeMatrix a x i k)^2≤R^2) : + SmallBound (fun y i=>siteMean a y*U y i) x (C*(A+3*R)) := by + apply hU.coefficient (fun x _=>siteMean a x) hA hR (fun _=>coefficient_mean_value a x hA ha) + intro i + have H:=pow_le_pow_left₀ (norm_nonneg _) (coefficient_mean_difference a x hR hda) 2 + simpa only [derivativeMatrix,derivativeVector,EuclideanSpace.real_norm_sq_eq,WithLp.ofLp_toLp] using H + +end SKGapCutoff.Recipe + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/CompactTube.lean b/lean/OAI/Probability/SKGap/Localization/CompactTube.lean new file mode 100644 index 0000000000000000000000000000000000000000..41097ee3fcba38304682d54fffdc608c612c9b5d --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/CompactTube.lean @@ -0,0 +1,217 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.ConditionalModelAlgebra + +namespace OAI + +section +noncomputable section +namespace SKGap +open Set Filter Topology + +theorem compact_perturbation_tube {X : Type*} [TopologicalSpace X] + {K : Set X} (hK : IsCompact K) (E : Set (X × ℝ)) + (hE : ∀ x ∈ K, E ∈ 𝓝 (x,0)) : + ∃ U : Set X, IsOpen U ∧ K ⊆ U ∧ ∃ δ > 0, + ∀ x ∈ U, ∀ r : ℝ, |r| ≤ δ → (x,r) ∈ E := by + have hc : K ×ˢ ({0} : Set ℝ) ⊆ interior E := by + rintro ⟨x,r⟩ ⟨hx,hr⟩ + have hr0 : r=0 := mem_singleton_iff.mp hr + subst r + exact mem_interior_iff_mem_nhds.mpr (hE x hx) + obtain ⟨U,V,hU,hV,hKU,h0V,hUV⟩ := generalized_tube_lemma hK isCompact_singleton isOpen_interior hc + have hV0 : V ∈ 𝓝 (0:ℝ) := hV.mem_nhds (h0V (mem_singleton 0)) + obtain ⟨r,hr,hrV⟩ := Metric.mem_nhds_iff.mp hV0 + refine ⟨U,hU,hKU,r/2,half_pos hr,?_⟩ + intro x hx a ha + apply interior_subset (hUV ⟨hx,?_⟩) + apply hrV + rw [Metric.mem_ball,Real.dist_eq,sub_zero] + linarith +end SKGap +namespace SKGap +open Set Filter Topology +lemma compact_perturbation_tube_norm {X Y : Type*} [TopologicalSpace X] + [NormedAddCommGroup Y] {K : Set X} (hK : IsCompact K) (E : Set (X × Y)) + (hE : ∀ x ∈ K, E ∈ 𝓝 (x,0)) : + ∃ U : Set X, IsOpen U ∧ K ⊆ U ∧ ∃ δ > 0, + ∀ x ∈ U, ∀ r : Y, ‖r‖ ≤ δ → (x,r) ∈ E := by + have hc : K ×ˢ ({0} : Set Y) ⊆ interior E := by + rintro ⟨x,r⟩ ⟨hx,hr⟩ + have hr0 : r=0 := mem_singleton_iff.mp hr + subst r + exact mem_interior_iff_mem_nhds.mpr (hE x hx) + obtain ⟨U,V,hU,hV,hKU,h0V,hUV⟩ := generalized_tube_lemma hK isCompact_singleton isOpen_interior hc + obtain ⟨r,hr,hrV⟩ := Metric.mem_nhds_iff.mp (hV.mem_nhds (h0V (mem_singleton 0))) + refine ⟨U,hU,hKU,r/2,half_pos hr,?_⟩ + intro x hx a ha + apply interior_subset (hUV ⟨hx,hrV ?_⟩) + rw [Metric.mem_ball,dist_zero_right] + linarith +end SKGap +end +end + +section +noncomputable section +namespace SKGap +open Real Matrix MeasureTheory ProbabilityTheory Set Filter Topology +open scoped BigOperators Matrix.Norms.Frobenius + +def conditionalScalarSize (j : ℝ) (p : ScalarPoint) (r : ℝ) : ℝ := + (1+|scalarD j p|)/scalarS j p+1/scalarQMoment p.1+1/scalarS j p+ + 1/(j*scalarBMoment p.1+r)+(j*scalarBMoment p.1+r)+‖conditionalScalarData j p‖ + +lemma continuousAt_conditionalSize {X : Type*} [TopologicalSpace X] + {R j : ℝ} (hR : 0 ≤ R) (f : X → ScalarPoint) (hf : Continuous f) + (hdom : ∀ x,f x ∈ scalarMomentDomain R) (r : X → ℝ) (hr : Continuous r) + {x : X} (hq : 0 < scalarQMoment (f x).1) (hs : 0 < scalarS j (f x)) + (hS : 0 < scalarS j (f x)+j*scalarQMoment (f x).1) + (hB : 0 < j*scalarBMoment (f x).1+r x) : + ContinuousAt (fun x=>conditionalScalarSize j (f x) (r x)) x := by + have hq' := (continuous_scalarQMoment.comp (continuous_fst.comp hf)).continuousAt (x := x) + have hs' := ((continuous_scalarS j).comp hf).continuousAt (x := x) + have hd' := ((continuous_scalarD j).comp hf).continuousAt (x := x) + have hb' := (((continuous_const : Continuous (fun _ : X=>j)).mul (continuous_scalarBMoment.comp (continuous_fst.comp hf))).add hr).continuousAt (x := x) + have he' := (continuousAt_conditionalData hR f hf hdom r hr hq hs hS).2.norm + exact (((((continuousAt_const.add hd'.abs).div hs' hs.ne').add + (continuousAt_const.div hq' hq.ne')).add (continuousAt_const.div hs' hs.ne')).add + (continuousAt_const.div hb' hB.ne')).add hb' |>.add he' + +lemma continuousAt_augmentedGram {X : Type*} [TopologicalSpace X] + {H : X → Matrix (Fin 3) (Fin 3) ℝ} {x : X} (hH : ContinuousAt H x) : + ContinuousAt (fun x=>augmentedGram (ν := Unit) (H x)) x := by + apply continuousAt_pi.mpr + intro i + apply continuousAt_pi.mpr + intro k + cases i with + | inl i => cases k with + | inl k => exact (continuousAt_pi.mp (continuousAt_pi.mp hH i) k) + | inr k => exact continuousAt_const + | inr i => cases k <;> exact continuousAt_const + +abbrev ScalarTimeDomain (R t0 T : ℝ) := (momentBall R) × (Icc t0 T) + +def scalarEqualitySet (j R t0 T : ℝ) : Set (ScalarTimeDomain R t0 T) := + {x | (x.1 : ProbabilityMeasure ℝ)=scalarCurve j x.2} + +def scalarPerturbedPoint {R t0 T : ℝ} (z : ScalarTimeDomain R t0 T × (ℝ × ℝ)) : ScalarPoint := + ((z.1.1 : ProbabilityMeasure ℝ),(z.1.2 : ℝ),z.2.1) + +lemma continuous_scalarPerturbedPoint {R t0 T : ℝ} : + Continuous (@scalarPerturbedPoint R t0 T) := by + unfold scalarPerturbedPoint + fun_prop + +lemma scalarPerturbedPoint_domain {R t0 T : ℝ} (z : ScalarTimeDomain R t0 T × (ℝ × ℝ)) : + scalarPerturbedPoint z ∈ scalarMomentDomain R := ⟨z.1.1.2,mem_univ _⟩ + +lemma isCompact_scalarEqualitySet {j R t0 T : ℝ} (hj : 0 < j) (hj1 : j < 1) (ht0 : 0 < t0) : + IsCompact (scalarEqualitySet j R t0 T) := by + let : CompactSpace (momentBall R) := isCompact_iff_compactSpace.mp (isCompact_momentBall R) + have hcurve : Continuous (fun t : Icc t0 T=>scalarCurve j t) := + (continuous_scalarCurve_nonneg hj hj1).comp (continuous_subtype_val.subtype_mk (fun t=>ht0.le.trans t.2.1)) + exact (isClosed_eq (continuous_subtype_val.comp continuous_fst) (hcurve.comp continuous_snd)).isCompact + +theorem scalar_conditional_neighborhood {j R t0 T ρ : ℝ} + (hj : 0 < j) (hj1 : j < 1) (hR : 0 ≤ R) (ht0 : 0 < t0) (hρ : 0 < ρ) : + ∃ L : ℝ, 1 ≤ L ∧ ∃ U : Set (ScalarTimeDomain R t0 T), IsOpen U ∧ + scalarEqualitySet j R t0 T ⊆ U ∧ ∃ δ > 0, + ∀ x ∈ U,∀ σ r : ℝ, |σ| ≤ δ → |r| ≤ δ → + let p : ScalarPoint := ((x.1 : ProbabilityMeasure ℝ),(x.2 : ℝ),σ) + 0 < scalarQMoment p.1 ∧ 0 < scalarS j p ∧ 0 < j*scalarBMoment p.1+r ∧ + conditionalScalarSize j p r < L ∧ + ‖augmentedGram (ν := Unit) (scalarMomentGram p.1 (scalarD j p) (scalarS j p))- + augmentedGram (ν := Unit) (limitingGram (scalarBMoment (scalarCurve j x.2)) + (scalarEMoment (scalarCurve j x.2)) (scalarFixedPoint j x.2))‖ < ρ ∧ + ‖conditionalMeanData j p r-curveCoefficient j x.2‖ < ρ := by + let X := ScalarTimeDomain R t0 T + let K := scalarEqualitySet j R t0 T + let f : X × (ℝ × ℝ) → ScalarPoint := scalarPerturbedPoint + let r : X × (ℝ × ℝ) → ℝ := fun z=>z.2.2 + have hf : Continuous f := continuous_scalarPerturbedPoint + have hr : Continuous r := continuous_snd.comp continuous_snd + have hd : ∀ z,f z ∈ scalarMomentDomain R := scalarPerturbedPoint_domain + have hK : IsCompact K := isCompact_scalarEqualitySet hj hj1 ht0 + have heq (x : X) (hx : x ∈ K) : f (x,0)=(scalarCurve j x.2,(x.2:ℝ),0) := by + change ((x.1:ProbabilityMeasure ℝ),(x.2:ℝ),0)=_ + rw [show (x.1:ProbabilityMeasure ℝ)=scalarCurve j x.2 from hx] + have hpoint (x : X) (hx : x ∈ K) : + 0 < scalarQMoment (f (x,0)).1 ∧ 0 < scalarS j (f (x,0)) ∧ + 0 < scalarS j (f (x,0))+j*scalarQMoment (f (x,0)).1 ∧ + 0 < j*scalarBMoment (f (x,0)).1+r (x,0) := by + rw [heq x hx,scalarQMoment_curve hj hj1 (ht0.le.trans x.2.2.1),scalarS_curve hj hj1 (ht0.le.trans x.2.2.1)] + have hp := scalar_fixed_pos hj hj1 (ht0.trans_le x.2.2.1) + exact ⟨hp.2,hp.1,add_pos hp.1 (mul_pos hj hp.2),by simpa [r] using mul_pos hj (scalarBMoment_pos (scalarCurve j x.2))⟩ + have hsize (x : X) (hx : x ∈ K) : + ContinuousAt (fun z=>conditionalScalarSize j (f z) (r z)) (x,0) := + continuousAt_conditionalSize hR f hf hd r hr (hpoint x hx).1 (hpoint x hx).2.1 + (hpoint x hx).2.2.1 (hpoint x hx).2.2.2 + have hsizeK : ContinuousOn (fun x : X=>conditionalScalarSize j (f (x,0)) (r (x,0))) K := by + intro x hx + exact ((hsize x hx).comp (x := x) (continuousAt_id.prodMk continuousAt_const)).continuousWithinAt + obtain ⟨M,hM⟩ := hK.bddAbove_image hsizeK + let L := max 1 (M+1) + have hL : 1 ≤ L := le_max_left _ _ + have hsmall (x : X) (hx : x ∈ K) : conditionalScalarSize j (f (x,0)) (r (x,0)) < L := + (lt_of_le_of_lt (hM (mem_image_of_mem _ hx)) (by linarith : M < M+1)).trans_le (le_max_right _ _) + obtain ⟨hs,hq,hb,he,hkap,hc⟩ := continuous_curve_statistics (T := T) hj hj1 ht0 + let G : X × (ℝ × ℝ) → Matrix ((Fin 3) ⊕ Unit) ((Fin 3) ⊕ Unit) ℝ := fun z=> + augmentedGram (ν := Unit) (scalarMomentGram (f z).1 (scalarD j (f z)) (scalarS j (f z))) + let G0 : X × (ℝ × ℝ) → Matrix ((Fin 3) ⊕ Unit) ((Fin 3) ⊕ Unit) ℝ := fun z=> + augmentedGram (ν := Unit) (limitingGram (scalarBMoment (scalarCurve j z.1.2)) + (scalarEMoment (scalarCurve j z.1.2)) (scalarFixedPoint j z.1.2)) + have hG0 : Continuous G0 := by + apply continuous_iff_continuousAt.mpr + intro z + apply continuousAt_augmentedGram + unfold limitingGram + apply continuousAt_pi.mpr + intro i + apply continuousAt_pi.mpr + intro k + have hb' := (hb.comp (continuous_snd.comp continuous_fst)).continuousAt (x := z) + have he' := (he.comp (continuous_snd.comp continuous_fst)).continuousAt (x := z) + have hs' := (hs.comp (continuous_snd.comp continuous_fst)).continuousAt (x := z) + fin_cases i <;> fin_cases k <;> simp only [Matrix.of_apply,Matrix.cons_val,Fin.reduceFinMk] <;> + fun_prop (disch := exact (scalar_fixed_pos hj hj1 (ht0.trans_le z.1.2.2.1)).1.ne') + let E : Set (X × (ℝ × ℝ)) := {z | + 0 < scalarQMoment (f z).1 ∧ 0 < scalarS j (f z) ∧ 0 < j*scalarBMoment (f z).1+r z ∧ + conditionalScalarSize j (f z) (r z) < L ∧ ‖G z-G0 z‖ < ρ ∧ + ‖conditionalMeanData j (f z) (r z)-curveCoefficient j z.1.2‖ < ρ} + have hE (x : X) (hx : x ∈ K) : E ∈ 𝓝 (x,0) := by + have hpt := hpoint x hx + have hqc := (continuous_scalarQMoment.comp (continuous_fst.comp hf)).continuousAt (x := (x,0)) + have hsc := ((continuous_scalarS j).comp hf).continuousAt (x := (x,0)) + have hbc := (((continuous_const : Continuous (fun _ : X × (ℝ × ℝ)=>j)).mul (continuous_scalarBMoment.comp (continuous_fst.comp hf))).add hr).continuousAt (x := (x,0)) + have cg : ContinuousAt G (x,0) := by + apply continuousAt_augmentedGram + exact (continuousAt_scalarMomentGram (p := ((f (x,0)).1,scalarD j (f (x,0)),scalarS j (f (x,0)))) hpt.2.1.ne').comp + (x := (x,0)) ((continuous_fst.comp hf).continuousAt.prodMk + (((continuous_scalarD j).comp hf).continuousAt.prodMk hsc)) + have cm := (continuousAt_conditionalData hR f hf hd r hr hpt.1 hpt.2.1 hpt.2.2.1).1 + have hgzero : G (x,0)-G0 (x,0)=0 := by + dsimp only [G,G0] + rw [heq x hx,scalarD_curve hj hj1 (ht0.le.trans x.2.2.1),scalarS_curve hj hj1 (ht0.le.trans x.2.2.1), + scalarMomentGram_curve hj hj1 (ht0.trans_le x.2.2.1)] + exact sub_self _ + have hczero : conditionalMeanData j (f (x,0)) (r (x,0))-curveCoefficient j x.2=0 := by + rw [heq x hx] + change conditionalMeanData j (scalarCurve j x.2,(x.2:ℝ),0) 0-curveCoefficient j x.2=0 + rw [conditionalMeanData_curve hj hj1 (ht0.trans_le x.2.2.1),sub_self] + have e1 := hqc.eventually_const_lt hpt.1 + have e2 := hsc.eventually_const_lt hpt.2.1 + have e3 := hbc.eventually_const_lt hpt.2.2.2 + have e4 := (hsize x hx).eventually_lt_const (hsmall x hx) + have e5 := (cg.sub hG0.continuousAt).norm.eventually_lt_const (by change ‖G (x,0)-G0 (x,0)‖ < ρ; simpa only [hgzero,norm_zero] using hρ) + have e6 := (cm.sub (hc.comp (continuous_snd.comp continuous_fst)).continuousAt).norm.eventually_lt_const (by change ‖conditionalMeanData j (f (x,0)) (r (x,0))-curveCoefficient j x.2‖ < ρ; simpa only [hczero,norm_zero] using hρ) + exact e1.and (e2.and (e3.and (e4.and (e5.and e6)))) + obtain ⟨U,hU,hKU,δ,hδ,hδE⟩ := compact_perturbation_tube_norm hK E hE + refine ⟨L,hL,U,hU,hKU,δ,hδ,?_⟩ + intro x hx σ r hσ hr + exact hδE x hx (σ,r) (by simpa only [Prod.norm_def,Real.norm_eq_abs,max_le_iff] using And.intro hσ hr) +end SKGap +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/ComponentRefresh.lean b/lean/OAI/Probability/SKGap/Localization/ComponentRefresh.lean new file mode 100644 index 0000000000000000000000000000000000000000..eeb8c89e2328bcfa89480854be2f6b752af85a33 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/ComponentRefresh.lean @@ -0,0 +1,438 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.PreparationGrowth + +namespace OAI + +section +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open scoped BigOperators +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open scoped BigOperators +open scoped BigOperators NNReal ENNReal +open MeasureTheory Metric Set +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators NNReal ENNReal Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Set +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators ENNReal NNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Matrix +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators ENNReal NNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal +open scoped BigOperators +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise NNReal ENNReal +open scoped BigOperators +open Filter Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal Topology +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Set Matrix +open scoped BigOperators NNReal ENNReal Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open Filter MeasureTheory ProbabilityTheory +open scoped Topology NNReal ENNReal +open Filter MeasureTheory ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter +open scoped Topology NNReal ENNReal +open MeasureTheory Filter ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter +open scoped Topology +open MeasureTheory Filter ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter ProbabilityTheory ContinuousLinearMap +open scoped Topology NNReal ENNReal +open Filter MeasureTheory ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter +open scoped BigOperators Topology +open MeasureTheory Filter +open scoped BigOperators Topology +open MeasureTheory Filter +open scoped BigOperators Topology +open MeasureTheory Filter +open scoped BigOperators Topology +open MeasureTheory Filter +open scoped BigOperators Topology +open Filter Set Metric +open scoped Topology RealInnerProductSpace +open scoped BigOperators +open ContinuousLinearMap +open scoped BigOperators +open ContinuousLinearMap +open scoped Topology Interval +open MeasureTheory +open MeasureTheory +open scoped BigOperators Topology Interval +open MeasureTheory +open scoped BigOperators Topology Interval +open scoped Topology +open MeasureTheory +open scoped BigOperators Topology Interval +namespace SKGapCutoff + +noncomputable def componentRefresh {n : ℕ} (m : VectorFields n) (t : ℝ) + (p : VectorFields n) : VectorFields n := + fun x i => refreshSemigroup m t (fun y => p y i) x + +noncomputable def componentGenerator {n : ℕ} (m p : VectorFields n) : VectorFields n := + fun x i => refreshGenerator m (fun y => p y i) x + +noncomputable def vectorDerivativeSquare {n : ℕ} (p : VectorFields n) (x : Spin n) : ℝ := + ∑ i, ∑ j, (halfDiff j (fun y => p y i) x)^2 + +lemma refresh_jensen_square {n : ℕ} (m : VectorFields n) (hm : ∀ x i, |m x i|≤1) + (t : ℝ) (ht : 0≤t) (f : Observables n) (x : Spin n) : + (refreshSemigroup m t f x)^2 ≤ refreshSemigroup m t (fun y => f y^2) x := by + let a := refreshSemigroup m t f x + have hh := refreshSemigroup_nonneg m hm t ht (fun y => (f y-a)^2) (fun y => sq_nonneg (f y-a)) x + have he : (fun y => (f y-a)^2) = (fun y => f y^2) - (2*a) • f + (fun _ => a^2) := by + funext y; simp only [Pi.sub_apply, Pi.add_apply, Pi.smul_apply, smul_eq_mul]; ring + rw [he, map_add, map_sub, map_smul] at hh + simp only [Pi.add_apply, Pi.sub_apply, Pi.smul_apply, smul_eq_mul, + refreshSemigroup_const] at hh + dsimp only [a] at hh + nlinarith only [hh] + +lemma componentRefresh_vectorSquare {n : ℕ} (m : VectorFields n) + (hm : ∀ x i, |m x i|≤1) (t : ℝ) (ht : 0≤t) (p : VectorFields n) (x : Spin n) : + vectorSquare (componentRefresh m t p) x ≤ refreshSemigroup m t (vectorSquare p) x := by + calc + _ ≤ ∑ i, refreshSemigroup m t (fun y => p y i^2) x := by + exact Finset.sum_le_sum (fun i _ => refresh_jensen_square m hm t ht _ x) + _ = _ := by + have he : vectorSquare p = ∑ i, fun y => p y i^2 := by + funext y; simp [vectorSquare] + rw [he, map_sum, Finset.sum_apply] + +lemma componentRefresh_derivativeSquare {n : ℕ} (m : VectorFields n) (C : ℝ) + (hrough : ∀ q : VectorFields n, ∀ t : ℝ, 0≤t → ∀ x, + vectorSquare (refreshGradientSemigroup m t q) x ≤ + Real.exp (C*t)*refreshSemigroup m t (vectorSquare q) x) + (t : ℝ) (ht : 0≤t) (p : VectorFields n) (x : Spin n) : + vectorDerivativeSquare (componentRefresh m t p) x ≤ + Real.exp (C*t)*refreshSemigroup m t (vectorDerivativeSquare p) x := by + unfold vectorDerivativeSquare + calc + _ ≤ ∑ i, Real.exp (C*t)*refreshSemigroup m t + (fun y => ∑ j, (halfDiff j (fun z => p z i) y)^2) x := by + apply Finset.sum_le_sum + intro i _ + have hh := hrough (fun y j => halfDiff j (fun z => p z i) y) t ht x + change (∑ j, (refreshGradientSemigroup m t (fun y j => halfDiff j (fun z => p z i) y) x j)^2) ≤ _ at hh + have he : vectorSquare (fun y j => halfDiff j (fun z => p z i) y) = + fun y => ∑ j, (halfDiff j (fun z => p z i) y)^2 := rfl + rw [he] at hh + simpa only [componentRefresh, refreshHalfDiff_semigroup] using hh + _ = _ := by + rw [← Finset.mul_sum] + congr 1 + have he : (fun y => ∑ i, ∑ j, (halfDiff j (fun z => p z i) y)^2) = + ∑ i, (fun y => ∑ j, (halfDiff j (fun z => p z i) y)^2) := by funext y; simp + rw [he, map_sum, Finset.sum_apply] + +noncomputable def refreshCorrection {n : ℕ} (m p : VectorFields n) : VectorFields n := + componentGenerator m p-refreshGradientGenerator m p + +lemma refreshCorrection_square {n : ℕ} (m p : VectorFields n) + (x : Spin n) (M D : ℝ) + (hrow : ∀ i, ∑ j, refreshInfluence m x i j^2 ≤ D) + (hop : ∀ q : Fin n → ℝ, ∑ i, (∑ j, refreshInfluence m x i j*q j)^2 ≤ + M^2*∑ i, q i^2) : + vectorSquare (refreshCorrection m p) x ≤ + 3*(1+M^2)*vectorSquare p x+12*D*vectorDerivativeSquare p x := by + have hc (i : Fin n) : (∑ j, refreshInfluence m x i j*halfDiff j (fun y => p y i) x)^2 ≤ + D*∑ j, (halfDiff j (fun y => p y i) x)^2 := + (Finset.sum_mul_sq_le_sq_mul_sq _ _ _).trans + (mul_le_mul_of_nonneg_right (hrow i) (Finset.sum_nonneg (fun j _ => sq_nonneg _))) + have he (i : Fin n) : (refreshCorrection m p x i)^2 ≤ + 3*(p x i)^2 + 12*D*(∑ j, (halfDiff j (fun y => p y i) x)^2) + + 3*(∑ j, refreshInfluence m x i j*p x j)^2 := by + have hrepr : refreshCorrection m p x i = p x i + + 2*spin x i*(∑ j, refreshInfluence m x i j*halfDiff j (fun y => p y i) x) - + ∑ j, refreshInfluence m x i j*p x j := by + simp only [refreshCorrection, Pi.sub_apply, componentGenerator, refreshGradientGenerator, + refreshInfluence] + ring + rw [hrepr] + have hs : (2*spin x i*(∑ j, refreshInfluence m x i j*halfDiff j (fun y => p y i) x))^2 = + 4*(∑ j, refreshInfluence m x i j*halfDiff j (fun y => p y i) x)^2 := by + rw [mul_pow, mul_pow, spin_sq]; ring + have hsum (a b c : ℝ) : (a+b-c)^2 ≤ 3*a^2+3*b^2+3*c^2 := by + nlinarith only [sq_nonneg (a-b),sq_nonneg (a+c),sq_nonneg (b+c)] + have hh := hsum (p x i) (2*spin x i*(∑ j, refreshInfluence m x i j*halfDiff j (fun y => p y i) x)) + (∑ j, refreshInfluence m x i j*p x j) + rw [hs] at hh + nlinarith only [hh,hc i] + have hh := Finset.sum_le_sum (fun i (_ : i ∈ Finset.univ) => he i) + simp only [Finset.sum_add_distrib, ← Finset.mul_sum] at hh + have ho := hop (p x) + dsimp only [vectorSquare, vectorDerivativeSquare] + nlinarith only [hh,ho] + +lemma componentRefresh_hasDerivAt {n : ℕ} (m p : VectorFields n) (t : ℝ) : + HasDerivAt (fun s => componentRefresh m s p) + (componentGenerator m (componentRefresh m t p)) t := by + apply hasDerivAt_pi.mpr + intro x + apply hasDerivAt_pi.mpr + intro i + exact hasDerivAt_pi.mp (refreshSemigroup_apply_hasDerivAt' m (fun y => p y i) t) x + +lemma gradientComponent_interpolate_hasDerivAt {n : ℕ} (m p : VectorFields n) (t s : ℝ) : + HasDerivAt (fun r : ℝ => refreshGradientSemigroup m (t-r) (componentRefresh m r p)) + (refreshGradientSemigroup m (t-s) (refreshCorrection m (componentRefresh m s p))) s := by + have hk := (hasDerivAt_exp_smul_const (refreshGradientGeneratorCLM m) (t-s)).scomp s + ((hasDerivAt_id s).const_sub t) + have hh := hk.clm_apply (componentRefresh_hasDerivAt m p s) + apply hh.congr_deriv + simp only [one_smul, neg_smul, Function.comp_def] + change -refreshGradientSemigroup m (t-s) (refreshGradientGenerator m (componentRefresh m s p)) + + refreshGradientSemigroup m (t-s) (componentGenerator m (componentRefresh m s p)) = _ + rw [refreshCorrection, map_sub] + abel + +noncomputable def vectorEvalEuclideanLM {n : ℕ} (x : Spin n) : + VectorFields n →ₗ[ℝ] EuclideanSpace ℝ (Fin n) where + toFun p := WithLp.toLp 2 (p x) + map_add' _ _ := rfl + map_smul' _ _ := rfl + +noncomputable def vectorEvalEuclidean {n : ℕ} (x : Spin n) : + VectorFields n →L[ℝ] EuclideanSpace ℝ (Fin n) := + (vectorEvalEuclideanLM x).toContinuousLinearMap + +lemma vectorEvalEuclidean_norm_sq {n : ℕ} (x : Spin n) (p : VectorFields n) : + ‖vectorEvalEuclidean x p‖^2 = vectorSquare p x := by + rw [EuclideanSpace.real_norm_sq_eq] + rfl + +lemma gradient_component_difference {n : ℕ} (m p : VectorFields n) + (hm : ∀ x i, |m x i|≤1) (C B t : ℝ) (hC : 0≤C) (hB : 0≤B) (ht : 0≤t) + (hrough : ∀ q : VectorFields n, ∀ s : ℝ, 0 ≤ s → ∀ x, + vectorSquare (refreshGradientSemigroup m s q) x ≤ + Real.exp (C*s)*refreshSemigroup m s (vectorSquare q) x) + (hcorr : ∀ s ∈ Set.Icc 0 t, ∀ x, + vectorSquare (refreshCorrection m (componentRefresh m s p)) x ≤ B) + (x : Spin n) : + vectorSquare (refreshGradientSemigroup m t p-componentRefresh m t p) x ≤ + t^2*Real.exp (C*t)*B := by + let f (s : ℝ) := vectorEvalEuclidean x + (refreshGradientSemigroup m (t-s) (componentRefresh m s p)) + let f' (s : ℝ) := vectorEvalEuclidean x + (refreshGradientSemigroup m (t-s) (refreshCorrection m (componentRefresh m s p))) + have hd (s : ℝ) : HasDerivAt f (f' s) s := + (vectorEvalEuclidean x).hasFDerivAt.comp_hasDerivAt s + (gradientComponent_interpolate_hasDerivAt m p t s) + have hb (s : ℝ) (hs : s ∈ Set.Icc 0 t) : ‖f' s‖ ≤ Real.sqrt (Real.exp (C*t)*B) := by + apply Real.le_sqrt_of_sq_le + rw [show ‖f' s‖^2 = vectorSquare + (refreshGradientSemigroup m (t-s) (refreshCorrection m (componentRefresh m s p))) x + from vectorEvalEuclidean_norm_sq _ _] + calc + _ ≤ Real.exp (C*(t-s))*refreshSemigroup m (t-s) + (vectorSquare (refreshCorrection m (componentRefresh m s p))) x := + hrough _ _ (sub_nonneg.mpr hs.2) _ + _ ≤ Real.exp (C*(t-s))*B := mul_le_mul_of_nonneg_left + ((refreshSemigroup_mono m hm (t-s) (sub_nonneg.mpr hs.2) (hcorr s hs) x).trans_eq + (by simp)) (Real.exp_pos _).le + _ ≤ _ := mul_le_mul_of_nonneg_right (Real.exp_le_exp.mpr (by nlinarith [hs.1])) hB + have hh := norm_image_sub_le_of_norm_deriv_le_segment' + (fun s (_ : s ∈ Set.Icc 0 t) => (hd s).hasDerivWithinAt) + (fun s hs => hb s ⟨hs.1,hs.2.le⟩) t ⟨ht,le_rfl⟩ + have hzero : componentRefresh m 0 p = p := by ext y i; simp [componentRefresh] + have hend : f t-f 0 = vectorEvalEuclidean x + (componentRefresh m t p-refreshGradientSemigroup m t p) := by + simp only [f, sub_self, sub_zero, refreshGradientSemigroup, zero_smul, + NormedSpace.exp_zero, one_apply_eq_self, hzero, map_sub] + rw [hend, sub_zero] at hh + have hh' := pow_le_pow_left₀ (norm_nonneg _) hh 2 + rw [mul_pow, Real.sq_sqrt (mul_nonneg (Real.exp_pos _).le hB), + vectorEvalEuclidean_norm_sq] at hh' + have he : vectorSquare (componentRefresh m t p-refreshGradientSemigroup m t p) x = + vectorSquare (refreshGradientSemigroup m t p-componentRefresh m t p) x := by + unfold vectorSquare + apply Finset.sum_congr rfl + intro i _ + simp only [Pi.sub_apply] + ring + rw [he] at hh' + nlinarith only [hh'] + +lemma component_correction_bound {n : ℕ} (m p : VectorFields n) + (hm : ∀ x i, |m x i|≤1) (C U H M D t s : ℝ) + (hC : 0≤C) (hU0 : 0≤U) (hH0 : 0≤H) (hD : 0≤D) + (hs : s ∈ Set.Icc 0 t) + (hrough : ∀ q : VectorFields n, ∀ u : ℝ, 0≤u → ∀ x, + vectorSquare (refreshGradientSemigroup m u q) x ≤ + Real.exp (C*u)*refreshSemigroup m u (vectorSquare q) x) + (hU : ∀ x, vectorSquare p x ≤ U) (hH : ∀ x, vectorDerivativeSquare p x ≤ H) + (hrow : ∀ x i, ∑ j, refreshInfluence m x i j^2 ≤ D) + (hop : ∀ x (q : Fin n → ℝ), ∑ i, (∑ j, refreshInfluence m x i j*q j)^2 ≤ + M^2*∑ i, q i^2) (x : Spin n) : + vectorSquare (refreshCorrection m (componentRefresh m s p)) x ≤ + Real.exp (C*t)*(3*(1+M^2)*U+12*D*H) := by + have hu : vectorSquare (componentRefresh m s p) x ≤ U := + (componentRefresh_vectorSquare m hm s hs.1 p x).trans + ((refreshSemigroup_mono m hm s hs.1 hU x).trans_eq (by simp)) + have hh : vectorDerivativeSquare (componentRefresh m s p) x ≤ Real.exp (C*t)*H := by + calc + _ ≤ Real.exp (C*s)*refreshSemigroup m s (vectorDerivativeSquare p) x := + componentRefresh_derivativeSquare m C hrough s hs.1 p x + _ ≤ Real.exp (C*s)*H := mul_le_mul_of_nonneg_left + ((refreshSemigroup_mono m hm s hs.1 hH x).trans_eq (by simp)) (Real.exp_pos _).le + _ ≤ _ := mul_le_mul_of_nonneg_right + (Real.exp_le_exp.mpr (mul_le_mul_of_nonneg_left hs.2 hC)) hH0 + have he : 1 ≤ Real.exp (C*t) := Real.one_le_exp_iff.mpr (mul_nonneg hC (hs.1.trans hs.2)) + have hu' : vectorSquare (componentRefresh m s p) x ≤ Real.exp (C*t)*U := + hu.trans (by nlinarith only [mul_le_mul_of_nonneg_right he hU0]) + calc + _ ≤ 3*(1+M^2)*vectorSquare (componentRefresh m s p) x+ + 12*D*vectorDerivativeSquare (componentRefresh m s p) x := + refreshCorrection_square m _ x M D (hrow x) (hop x) + _ ≤ 3*(1+M^2)*(Real.exp (C*t)*U)+12*D*(Real.exp (C*t)*H) := + add_le_add (mul_le_mul_of_nonneg_left hu' (by positivity)) + (mul_le_mul_of_nonneg_left hh (by positivity)) + _ = _ := by ring + +lemma vectorSquare_sub_triangle {n : ℕ} (p q r : VectorFields n) (x : Spin n) : + vectorSquare (p-r) x ≤ 2*vectorSquare (p-q) x+2*vectorSquare (q-r) x := by + simp only [vectorSquare, Pi.sub_apply, Finset.mul_sum, ← Finset.sum_add_distrib] + exact Finset.sum_le_sum (fun i _ => by + nlinarith only [sq_nonneg (p x i-2*q x i+r x i)]) + +lemma componentRefresh_difference {n : ℕ} (m p : VectorFields n) + (hm : ∀ x i, |m x i|≤1) (t : ℝ) (ht : 0≤t) (x : Spin n) : + vectorSquare (componentRefresh m t p-p) x ≤ + refreshSemigroup m t (fun y => ∑ i, (p y i-p x i)^2) x := by + have hi (i : Fin n) : (componentRefresh m t p x i-p x i)^2 ≤ + refreshSemigroup m t (fun y => (p y i-p x i)^2) x := by + have hh := refresh_jensen_square m hm t ht (fun y => p y i-p x i) x + have he : (fun y => p y i-p x i) = (fun y => p y i)-(fun _ => p x i) := rfl + rw [he, map_sub] at hh + simpa only [Pi.sub_apply, refreshSemigroup_const, componentRefresh] using hh + have he : (fun y => ∑ i, (p y i-p x i)^2) = ∑ i, fun y => (p y i-p x i)^2 := by + funext y; simp + rw [he, map_sum, Finset.sum_apply] + exact Finset.sum_le_sum (fun i _ => hi i) + +theorem refreshGradient_short_time {n : ℕ} (m p : VectorFields n) + (hm : ∀ x i, |m x i|≤1) (C U H M D t : ℝ) + (hC : 0≤C) (hU0 : 0≤U) (hH0 : 0≤H) (hD : 0≤D) (ht : 0≤t) + (hrough : ∀ q : VectorFields n, ∀ u : ℝ, 0≤u → ∀ x, + vectorSquare (refreshGradientSemigroup m u q) x ≤ + Real.exp (C*u)*refreshSemigroup m u (vectorSquare q) x) + (hU : ∀ x, vectorSquare p x ≤ U) (hH : ∀ x, vectorDerivativeSquare p x ≤ H) + (hrow : ∀ x i, ∑ j, refreshInfluence m x i j^2 ≤ D) + (hop : ∀ x (q : Fin n → ℝ), ∑ i, (∑ j, refreshInfluence m x i j*q j)^2 ≤ + M^2*∑ i, q i^2) (x : Spin n) : + vectorSquare (refreshGradientSemigroup m t p-p) x ≤ + 2*t^2*Real.exp (2*C*t)*(3*(1+M^2)*U+12*D*H)+ + 2*refreshSemigroup m t (fun y => ∑ i, (p y i-p x i)^2) x := by + have hB : 0 ≤ Real.exp (C*t)*(3*(1+M^2)*U+12*D*H) := by positivity + have hh := gradient_component_difference m p hm C _ t hC hB ht hrough + (fun s hs x => component_correction_bound m p hm C U H M D t s hC hU0 hH0 hD hs + hrough hU hH hrow hop x) x + have hr := vectorSquare_sub_triangle (refreshGradientSemigroup m t p) (componentRefresh m t p) p x + have ho := componentRefresh_difference m p hm t ht x + have he : Real.exp (2*C*t) = Real.exp (C*t)*Real.exp (C*t) := by + rw [← Real.exp_add]; congr 1; ring + rw [he] + nlinarith only [hh,hr,ho] + +end SKGapCutoff + +open scoped BigOperators Topology + +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/CondSubConst.lean b/lean/OAI/Probability/SKGap/Localization/CondSubConst.lean new file mode 100644 index 0000000000000000000000000000000000000000..bb94b03c1742a8c47409cc5c6a9351f9fedf2793 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/CondSubConst.lean @@ -0,0 +1,214 @@ +import Mathlib +import OAI.Probability.SKGap.Entropy.EntropyBound + +namespace OAI + +namespace SKGap.GaussianStep +open scoped BigOperators +noncomputable section +variable {n : ℕ} + +lemma cond_sub_const (p : Prior n) (hp : ∀x,0

f x-c) x=cond p i f x-c := by + unfold cond + field_simp [(add_pos (hp x) (hp (flip i x))).ne'] + ring + +lemma energy_sub_const (p : Prior n) (hp : ∀x,0

f x-c)=energy p f := by + unfold energy + simp_rw [cond_sub_const p hp f c,sub_sub_sub_cancel_right] + +lemma var_center (p : Prior n) (f : Spin n→ℝ) : + var p (fun x => f x-avg p f)=var p f := by + unfold var + rw [avg_center] + simp only [sub_zero] + +end +end SKGap.GaussianStep + +namespace SKGap.GaussianHistory +open MeasureTheory ProbabilityTheory Real Set Filter +open scoped BigOperators ENNReal NNReal +open GaussianStep +noncomputable section +variable {n : ℕ} + +lemma localization_scalar {den N E r c e s v w : ℝ} (hd : 0 (f x)^2)) (hc : avg p f=0) + {t : ℝ} (ht : 0≤t) (htn : 4*(n:ℝ)*t≤1) + (K : ℕ) (B G : ∀k,Set (History n k)) + (hB : ∀k,MeasurableSet (B k)) (hG : ∀k,MeasurableSet (G k)) + (E : Set (History n K)) (hE : MeasurableSet E) + (hprefix : ∀k (f x)^2))) + (hcov : ∀k (f x)^2) := by rw [var_eq,hc]; ring + rw [hv] at hh ⊢ + let v:=T*(W*(n:ℝ)+2*A*sqrt (n:ℝ)+4/a)+64*(n:ℝ)^2*T*t + let w:=T*A*sqrt (n:ℝ) + have hbody : T*(W*(n:ℝ)+A*sqrt (n:ℝ)*(2+energy p f/avg p (fun x => (f x)^2))+4/a)+ + 64*(n:ℝ)^2*T*t = v+w*energy p f/avg p (fun x => (f x)^2) := by dsimp [v,w]; ring + rw [hbody] at hh + simpa only [localizationLoss,localizationCost,v,w,mul_assoc] using + localization_scalar (mul_pos hb (by exact_mod_cast hn)) hf hh + +theorem poincare_of_history_estimates (p : Prior n) (hp : ∀x,0

(f x)^2)),∀k (f x)^2))) + (hcov : ∀(f : Spin n→ℝ),∀k f x-avg p f + have hF : 0 (F x)^2) := hv + have hh:=centered_localization_bound p hp hn F hF (avg_center p f) ht htn K B G hB hG E hE hprefix hGE + D W A a b L T hD hW hA ha hb hL hDt hT hsmall hEsmall (hmean F hF) (hcov F) (hterminal F) + dsimp [F] at hh + rw [var_center,energy_sub_const p hp] at hh + have hl:=mul_le_mul_of_nonneg_right hLoss hv.le + have hc:=mul_le_mul_of_nonneg_right hCost (energy_nonneg p f) + rw [div_mul_eq_mul_div] + apply (le_div_iff₀ (exp_pos (-2*D*T))).mpr + nlinarith + · have hz : var p f=0 := le_antisymm (le_of_not_gt hv) (var_nonneg p f) + rw [hz] + exact mul_nonneg (div_nonneg (by positivity) (exp_pos _).le) (energy_nonneg p f) + +end +end SKGap.GaussianHistory + +namespace SKGap.GaussianHistory +open MeasureTheory ProbabilityTheory Real Set Filter +open scoped BigOperators ENNReal NNReal +open GaussianStep +noncomputable section +variable {n : ℕ} + +lemma eventProbability_lift (p : Prior n) {t : ℝ} (ht : 0≤t) {k : ℕ} + (E : Set (History n k)) (hE : MeasurableSet E) : + eventProbability p t (Prod.fst ⁻¹' E : Set (History n (k+1)))=eventProbability p t E := by + rw [eventProbability, ← integral_indicator (hE.preimage measurable_fst), + eventProbability, ← integral_indicator hE] + have hm : Measurable (E.indicator (fun _=> (1:ℝ))) := measurable_const.indicator hE + have he (h : History n k) : density p t h*E.indicator (fun _=>(1:ℝ)) h=E.indicator (density p t) h := by + by_cases hmem : h∈E <;> simp [hmem] + have hi : Integrable (fun h=>density p t h*E.indicator (fun _=> (1:ℝ)) h) (reference n k) := by + simpa only [he] using (integrable_density p t k).indicator hE + have H:=integral_lift p ht _ hm hi + have he' (h : History n (k+1)) : density p t h*E.indicator (fun _=>(1:ℝ)) h.1= + (Prod.fst ⁻¹' E).indicator (density p t (k:=k+1)) h := by + by_cases hmem : h.1∈E <;> simp [hmem] + simpa only [he,he'] using H + +lemma eventProbability_union_le (p : Prior n) {t : ℝ} (_ht : 0≤t) {k : ℕ} + (E F : Set (History n k)) (hE : MeasurableSet E) (hF : MeasurableSet F) : + eventProbability p t (E∪F)≤eventProbability p t E+eventProbability p t F := by + have H := measureReal_union_le (μ := law p t k) E F + have he (A : Set (History n k)) (hA : MeasurableSet A) : + (law p t k).real A=eventProbability p t A := by + rw [Measure.real, ← eventProbability_eq p t A hA, ENNReal.toReal_ofReal (eventProbability_nonneg p t A)] + simpa only [he _ (hE.union hF),he E hE,he F hF] using H + +def goodPrefix (B : ∀k, Set (History n k)) : ∀k,Set (History n k) + | 0 => (B 0)ᶜ + | k+1 => (Prod.fst ⁻¹' goodPrefix B k) ∩ (B (k+1))ᶜ + +lemma measurable_goodPrefix (B : ∀k, Set (History n k)) (hB : ∀k,MeasurableSet (B k)) : + ∀k,MeasurableSet (goodPrefix B k) + | 0 => (hB 0).compl + | k+1 => ((measurable_goodPrefix B hB k).preimage measurable_fst).inter (hB (k+1)).compl + +lemma goodPrefix_not_bad (B : ∀k, Set (History n k)) : + ∀k,∀h:History n k,h∈goodPrefix B k→h∉B k + | 0, _, h => h + | _+1, _, h => h.2 + +lemma goodPrefix_previous (B : ∀k, Set (History n k)) (k : ℕ) + (h : History n (k+1)) (hh : h∈goodPrefix B (k+1)) : h.1∈goodPrefix B k := hh.1 + +lemma goodPrefix_failure_bound (p : Prior n) {t : ℝ} (ht : 0≤t) + (B : ∀k,Set (History n k)) (hB : ∀k,MeasurableSet (B k)) : + ∀k,eventProbability p t (goodPrefix B k)ᶜ ≤ ∑i∈Finset.range (k+1),eventProbability p t (B i) + | 0 => by simp [goodPrefix] + | k+1 => by + have hE : (goodPrefix B (k+1))ᶜ = + (Prod.fst ⁻¹' (goodPrefix B k)ᶜ) ∪ B (k+1) := by + ext h + simp only [goodPrefix,mem_compl_iff,mem_preimage,mem_inter_iff,mem_union] + tauto + rw [hE,Finset.sum_range_succ] + have H : eventProbability p t (Prod.fst ⁻¹' (goodPrefix B k)ᶜ : Set (History n (k+1))) ≤ + ∑i∈Finset.range (k+1),eventProbability p t (B i) := by + rw [eventProbability_lift p ht _ (measurable_goodPrefix B hB k).compl] + exact goodPrefix_failure_bound p ht B hB k + exact (eventProbability_union_le p ht _ _ + ((measurable_goodPrefix B hB k).compl.preimage measurable_fst) (hB (k+1))).trans + (by linarith) + +lemma eventProbability_mono (p : Prior n) {t : ℝ} (_ht : 0≤t) {k : ℕ} + {E F : Set (History n k)} (h : E⊆F) : eventProbability p t E≤eventProbability p t F := by + exact setIntegral_mono_set (integrable_density p t k).integrableOn + (ae_of_all _ (fun h=> (density_pos p t h).le)) (Filter.Eventually.of_forall h) + +lemma bad_term_le_sum (p : Prior n) (t : ℝ) (B : ∀k,Set (History n k)) {k K : ℕ} + (hk : k≤K) : eventProbability p t (B k)≤∑i∈Finset.range (K+1),eventProbability p t (B i) := by + exact Finset.single_le_sum (fun i _=>eventProbability_nonneg p t (B i)) (by simpa using hk) + +end +end SKGap.GaussianHistory + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/ConditionalEmpiricalLaw.lean b/lean/OAI/Probability/SKGap/Localization/ConditionalEmpiricalLaw.lean new file mode 100644 index 0000000000000000000000000000000000000000..89503d0c592d4b7d5ce97369dd39afd78335c348 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/ConditionalEmpiricalLaw.lean @@ -0,0 +1,119 @@ +import Mathlib +import OAI.Probability.SKGap.Posterior.GOEPointwisePosterior +import OAI.Probability.SKGap.Posterior.ConditionalObservationData +import OAI.Probability.SKGap.Stability.ConditionalMeanScalar + +namespace OAI + +section +noncomputable section +namespace SKGap +open Matrix Real Set MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix.Norms.Frobenius + +def empiricalObservation {n : ℕ} [NeZero n] (j t σ : ℝ) (y : Fin n → ℝ) : Fin n → ℝ := + fun i=>y i-scalarD j (empiricalLaw y,t,σ)+j*scalarBMoment (empiricalLaw y)*tanh (y i) + +def empiricalConditionalGoe {n : ℕ} [NeZero n] (j t σ : ℝ) (y : Fin n → ℝ) + (g : MatrixCoordinates (Fin n) → ℝ) : Matrix (Fin n) (Fin n) ℝ := + let p : ScalarPoint := (empiricalLaw y,t,σ) + let q := scalarQMoment p.1 + let s := scalarS j p + conditionalBlockMatrix (j/(n:ℝ)) j q s (s+j*q) (scalarA j p) + (j*scalarBMoment p.1) (conditionalKappa j p) (conditionalEll j p) + (empiricalUnit y q).ofLp (sqrt s • (empiricalGramColumns y (scalarD j p) s 2).ofLp) g + +lemma empirical_observation_covariance {n : ℕ} [NeZero n] (j t σ : ℝ) (y : Fin n → ℝ) + (hq : 0 ≤ scalarQMoment (empiricalLaw y)) : + (j/(n:ℝ))*sqrt ((n:ℝ)*scalarQMoment (empiricalLaw y))^2+(t+σ^2)= + scalarS j (empiricalLaw y,t,σ) ∧ + (t+σ^2)+2*(j/(n:ℝ))*sqrt ((n:ℝ)*scalarQMoment (empiricalLaw y))^2= + scalarS j (empiricalLaw y,t,σ)+j*scalarQMoment (empiricalLaw y) := by + have hn : (n:ℝ) ≠ 0 := by exact_mod_cast NeZero.ne n + rw [sq_sqrt (mul_nonneg (Nat.cast_nonneg n) hq)] + dsimp [scalarS] + constructor <;> field_simp <;> ring + +lemma empirical_conditional_mean {n : ℕ} [NeZero n] {j t σ : ℝ} + (hj : 0 ≤ j) (ht : 0 < t) (y : Fin n → ℝ) + (hq : 0 < scalarQMoment (empiricalLaw y)) : + let p : ScalarPoint := (empiricalLaw y,t,σ) + let q := scalarQMoment p.1 + let s := scalarS j p + let u := (empiricalUnit y q).ofLp + let Z := sqrt s • (empiricalGramColumns y (scalarD j p) s 2).ofLp + (fun i k=>(goeRegressionCoefficient (j/(n:ℝ)) (t+σ^2) (fun l=>tanh (y l))*ᵥ + empiricalObservation j t σ y) (i,k))= + vecMulVec u ((j*sqrt (q/s)) • Z-(j*scalarA j p/s) • u)+ + vecMulVec ((j*sqrt (q/s)) • Z-(j*scalarA j p/s) • u) u+ + (2*j*(scalarA j p+j*scalarBMoment p.1*q)/(s+j*q)) • vecMulVec u u := by + dsimp only + let p : ScalarPoint := (empiricalLaw y,t,σ) + let q := scalarQMoment p.1 + let s := scalarS j p + let B := j*scalarBMoment p.1 + let c := sqrt ((n:ℝ)*q) + let u := (empiricalUnit y q).ofLp + let Z := sqrt s • (empiricalGramColumns y (scalarD j p) s 2).ofLp + have hn : 0 < (n:ℝ) := by exact_mod_cast NeZero.pos n + have hv : 0 < t+σ^2 := add_pos_of_pos_of_nonneg ht (sq_nonneg _) + have hs : 0 < s := add_pos_of_pos_of_nonneg hv (mul_nonneg hj hq.le) + have hu : u⬝ᵥu=1 := empiricalUnit_unit y hq + have hscale : c • u=(fun i=>tanh (y i)) := empirical_unit_scale y hq + have hc := empirical_observation_covariance j t σ y hq.le + have hdot : u⬝ᵥempiricalObservation j t σ y=(n:ℝ)*(scalarA j p+B*q)/c := + empirical_unit_observation_dot j t σ B y hq + have hmean := goeRegressionCoefficient_block_mean (c := c) (div_nonneg hj hn.le) hv hu + (empiricalObservation j t σ y) + rw [hscale] at hmean + rw [hc.1,hc.2,hdot] at hmean + have hperp : ((j/(n:ℝ))*c/s) • (empiricalObservation j t σ y- + ((n:ℝ)*(scalarA j p+B*q)/c) • u)= + (j*sqrt (q/s)) • Z-(j*scalarA j p/s) • u := by + ext i + have hzi := congrFun (empirical_Z_formula y (scalarD j p) hs) i + change Z i=(y i-scalarD j p)/(sqrt (n:ℝ)*sqrt s) at hzi + have hmi := congrFun hscale i + change c*u i=tanh (y i) at hmi + change (j/(n:ℝ)*c/s)*(y i-scalarD j p+B*tanh (y i)- + ((n:ℝ)*(scalarA j p+B*q)/c)*u i)= + j*sqrt (q/s)*Z i-j*scalarA j p/s*u i + rw [← hmi,hzi] + convert conditional_perp_mean_scalar hn hq hs j (scalarA j p) B + (y i-scalarD j p) (u i) using 1 + ring + rw [hperp] at hmean + have hparallel := conditional_parallel_mean_scalar (S := s+j*q) hn hq j (scalarA j p) B + rw [hparallel] at hmean + exact hmean + +theorem empirical_conditional_law {n : ℕ} [NeZero n] {j t σ : ℝ} + (hj : 0 ≤ j) (ht : 0 < t) (y : Fin n → ℝ) + (hq : 0 < scalarQMoment (empiricalLaw y)) : + conditionalGoeLaw (j/(n:ℝ)) (t+σ^2) (fun i=>tanh (y i)) (empiricalObservation j t σ y)= + (gaussianCoordinates (MatrixCoordinates (Fin n))).map + (fun g p=>empiricalConditionalGoe j t σ y g p.1 p.2) := by + let q := scalarQMoment (empiricalLaw y) + have hn : 0 < (n:ℝ) := by exact_mod_cast NeZero.pos n + have hv : 0 < t+σ^2 := add_pos_of_pos_of_nonneg ht (sq_nonneg _) + have hh := conditionalGoeLaw_block (c := sqrt ((n:ℝ)*q)) (div_nonneg hj hn.le) hv + (empiricalUnit_unit y hq) (empiricalObservation j t σ y) + rw [empirical_unit_scale y hq] at hh + rw [(empirical_observation_covariance j t σ y hq.le).1, + (empirical_observation_covariance j t σ y hq.le).2] at hh + rw [hh] + congr 1 + funext g p + have hmean := congrArg (fun M : Matrix (Fin n) (Fin n) ℝ=>M p.1 p.2) + (empirical_conditional_mean (σ := σ) hj ht y hq) + change _+_=empiricalConditionalGoe j t σ y g p.1 p.2 + dsimp only [empiricalConditionalGoe,conditionalBlockMatrix] + dsimp only at hmean + rw [hmean] + simp only [Matrix.add_apply,conditionalKappa,conditionalEll] + ring +end SKGap +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/ConditionalHessianLaw.lean b/lean/OAI/Probability/SKGap/Localization/ConditionalHessianLaw.lean new file mode 100644 index 0000000000000000000000000000000000000000..939f95c89721d0f7d60428374b093e3348dd2887 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/ConditionalHessianLaw.lean @@ -0,0 +1,134 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.DiagonalHessianJoined +import OAI.Probability.SKGap.Localization.ConditionalEmpiricalLaw +import OAI.Probability.SKGap.Entropy.ConditionalBadSet + +namespace OAI + +section +noncomputable section +namespace SKGap +open Matrix Real Set MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix.Norms.Frobenius + +lemma scalarQMoment_empirical_overlap {n : ℕ} [NeZero n] (y : Fin n → ℝ) : + scalarQMoment (empiricalLaw y)=overlap y := by + simp only [scalarQMoment,integral_empiricalLaw,Fintype.card_fin,overlap,magnetization, + div_eq_mul_inv,mul_comm] + +lemma empirical_columns_zero_outer {n : ℕ} [NeZero n] (y : Fin n → ℝ) (d s j : ℝ) : + j • vecMulVec (empiricalGramColumns y d s 0).ofLp (empiricalGramColumns y d s 0).ofLp= + (j/(n:ℝ)) • vecMulVec (fun _=>1) (fun _=>1) := by + have hnR : (n:ℝ) ≠ 0 := by exact_mod_cast NeZero.ne n + have hn : sqrt (n:ℝ) ≠ 0 := (sqrt_pos.mpr (by exact_mod_cast NeZero.pos n)).ne' + ext i k + simp only [empiricalGramColumns,gramCoordinates,Matrix.cons_val,WithLp.ofLp_toLp, + Matrix.smul_apply,smul_eq_mul,vecMulVec_apply,mul_one] + field_simp + rw [Real.sq_sqrt (Nat.cast_nonneg n)] + +lemma empirical_unit_outer {n : ℕ} [NeZero n] (y : Fin n → ℝ) {q : ℝ} (hq : 0 < q) (j : ℝ) : + (2*j*q) • vecMulVec (empiricalUnit y q).ofLp (empiricalUnit y q).ofLp= + (2*j/(n:ℝ)) • vecMulVec (magnetization y) (magnetization y) := by + have hn : (n:ℝ) ≠ 0 := by exact_mod_cast NeZero.ne n + have hc : sqrt ((n:ℝ)*q) ≠ 0 := (sqrt_pos.mpr (mul_pos (by exact_mod_cast NeZero.pos n) hq)).ne' + ext i k + simp only [empiricalUnit,WithLp.ofLp_toLp,Matrix.smul_apply,smul_eq_mul,vecMulVec_apply,magnetization] + field_simp + rw [Real.sq_sqrt (mul_nonneg hq.le (Nat.cast_nonneg n))] + ring + +lemma empiricalConditionalMiddle_literal {n : ℕ} [NeZero n] (j t σ : ℝ) (y : Fin n → ℝ) + (hq : 0 < scalarQMoment (empiricalLaw y)) (g : MatrixCoordinates (Fin n) → ℝ) : + empiricalConditionalMiddle j t σ y g= + plantedInteraction j (empiricalConditionalGoe j t σ y g)+ + (2*j/(n:ℝ)) • vecMulVec (magnetization y) (magnetization y)- + onsager j y • (1 : Matrix (Fin n) (Fin n) ℝ) := by + dsimp only [empiricalConditionalMiddle,empiricalConditionalGoe,plantedInteraction] + rw [empirical_columns_zero_outer,empirical_unit_outer y hq, + scalarBMoment,scalarQMoment_empirical_overlap] + rfl + +lemma fieldHessian_diagonalHessian {n : ℕ} (j : ℝ) (W : Matrix (Fin n) (Fin n) ℝ) + (y a : Fin n → ℝ) : + fieldHessian j (plantedInteraction j W) y a = diagonalHessian a + (plantedInteraction j W+(2*j/(n:ℝ)) • vecMulVec (magnetization y) (magnetization y)- + onsager j y • (1 : Matrix (Fin n) (Fin n) ℝ)) := by + ext i k + simp only [fieldHessian,hessianCore,diagonalHessian,diagonalRoot,Matrix.sub_apply, + Matrix.one_apply,Matrix.diagonal_mul,Matrix.mul_diagonal,Matrix.add_apply, + Matrix.smul_apply,smul_eq_mul,vecMulVec_apply] + ring + +lemma empiricalConditionalGoe_hessian {n : ℕ} [NeZero n] (j t σ : ℝ) (y a : Fin n → ℝ) + (hq : 0 < scalarQMoment (empiricalLaw y)) (g : MatrixCoordinates (Fin n) → ℝ) : + fieldHessian j (plantedInteraction j (empiricalConditionalGoe j t σ y g)) y a= + diagonalHessian a (empiricalConditionalMiddle j t σ y g) := by + rw [empiricalConditionalMiddle_literal j t σ y hq g,fieldHessian_diagonalHessian] + +lemma quadraticForm_dotProduct {n : ℕ} (M : Matrix (Fin n) (Fin n) ℝ) (x : Fin n → ℝ) : + quadraticForm M x=x⬝ᵥ(M*ᵥx) := by + simp only [quadraticForm,dotProduct,Matrix.mulVec,Finset.mul_sum] + apply Finset.sum_congr rfl; intro i _ + apply Finset.sum_congr rfl; intro k _; ring + +lemma quadraticForm_margin {n : ℕ} {M : Matrix (Fin n) (Fin n) ℝ} {m : ℝ} + (hM : (M-m • (1 : Matrix (Fin n) (Fin n) ℝ)).PosSemidef) + (x : EuclideanSpace ℝ (Fin n)) (hx : ‖x‖=1) : m ≤ quadraticForm M x.ofLp := by + have hh := hM.dotProduct_mulVec_nonneg x.ofLp + have hxx : x.ofLp⬝ᵥx.ofLp=1 := by + have he := EuclideanSpace.real_norm_sq_eq x + rw [hx,one_pow] at he + simpa only [dotProduct,pow_two] using he.symm + simp only [star_trivial,Matrix.sub_mulVec,Matrix.smul_mulVec,Matrix.one_mulVec, + dotProduct_sub,dotProduct_smul,smul_eq_mul,hxx,mul_one] at hh + rw [quadraticForm_dotProduct] + linarith + +end SKGap +end +end + +section +noncomputable section +namespace SKGap +open Matrix Real Set MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix.Norms.Frobenius ENNReal + +lemma measurable_conditionalGoe_map {n : ℕ} [NeZero n] (j t σ : ℝ) (y : Fin n → ℝ) : + Measurable (fun g (p : Fin n × Fin n) => empiricalConditionalGoe j t σ y g p.1 p.2) := by + dsimp [empiricalConditionalGoe,conditionalBlockMatrix,goeBlockResidual,goeBilinear, + Matrix.mulVec,dotProduct,goeMatrix] + fun_prop + +lemma measurable_badField_fiber {n : ℕ} (j A ε c : ℝ) (y : Fin n → ℝ) : + MeasurableSet {W : (Fin n × Fin n) → ℝ | ((fun i k=>W (i,k)),y) ∈ badFieldSet n j A ε c} := + ((isClosed_badFieldSet n j A ε c).preimage (by fun_prop)).measurableSet + +lemma conditional_bad_le_freshbad {n : ℕ} [NeZero n] {j t σ A ε c m : ℝ} + (hj : 0 ≤ j) (ht : 0 < t) (hcm : c < m) (y : Fin n → ℝ) + (hq : 0 < scalarQMoment (empiricalLaw y)) : + (conditionalGoeLaw (j/(n:ℝ)) (t+σ^2) (magnetization y) (empiricalObservation j t σ y)).real + {W | ((fun i k=>W (i,k)),y) ∈ badFieldSet n j A ε c} ≤ + (gaussianCoordinates (MatrixCoordinates (Fin n))).real + {g | ∃ a, (∀ i,a i ∈ Icc 0 A) ∧ + (∑ i,(a i-(1-tanh (y i)^2))^2) ≤ ε^2*(n:ℝ) ∧ + ¬(diagonalHessian a (empiricalConditionalMiddle j t σ y g)- + m • (1 : Matrix (Fin n) (Fin n) ℝ)).PosSemidef} := by + rw [show magnetization y=(fun i=>tanh (y i)) from rfl,empirical_conditional_law hj ht y hq] + unfold Measure.real + rw [Measure.map_apply (measurable_conditionalGoe_map j t σ y) (measurable_badField_fiber j A ε c y)] + apply ENNReal.toReal_mono (by finiteness) + apply measure_mono + intro g hg + obtain ⟨a,ha,hclose,x,hx,hquad⟩ := hg + refine ⟨a,ha,hclose,?_⟩ + intro hpsd + rw [empiricalConditionalGoe_hessian j t σ y a hq g] at hquad + exact (not_le_of_gt hcm) ((quadraticForm_margin hpsd x hx).trans hquad) + +end SKGap +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/ConditionalIntegralRate.lean b/lean/OAI/Probability/SKGap/Localization/ConditionalIntegralRate.lean new file mode 100644 index 0000000000000000000000000000000000000000..a671bdaacbf07703780291a5e613ab4e51d39da8 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/ConditionalIntegralRate.lean @@ -0,0 +1,169 @@ +import Mathlib +import OAI.Probability.SKGap.Gaussian.GaussianCompactTailRate +import OAI.Probability.SKGap.Localization.ScalarRelativeIsolation +import OAI.Probability.SKGap.Stability.ConditionalStability +import OAI.Probability.SKGap.Localization.ConditionalWeight +import OAI.Probability.SKGap.Entropy.WeightedRateAssembly + +namespace OAI + +section +noncomputable section +namespace SKGap +open Matrix Real Set MeasureTheory ProbabilityTheory GaussianDensity +open scoped BigOperators Matrix.Norms.Frobenius ENNReal + +def badFieldFlat (n : ℕ) (j A ε m : ℝ) : Set (((Fin n×Fin n) → ℝ) × (Fin n → ℝ)) := + {p | ((fun i k=>p.1 (i,k)),p.2)∈badFieldSet n j A ε m} + +lemma measurableSet_badFieldFlat (n : ℕ) (j A ε m : ℝ) : + MeasurableSet (badFieldFlat n j A ε m) := + ((isClosed_badFieldSet n j A ε m).preimage (by fun_prop)).measurableSet + +def reducedBadDensity {n : ℕ} [NeZero n] (j t σ A ε m : ℝ) (y : Fin n → ℝ) : ℝ≥0∞ := + ENNReal.ofReal (sqrt (scalarS j (scalarEmpirical y t σ)/ + (scalarS j (scalarEmpirical y t σ)+j*scalarQMoment (empiricalLaw y)))*scalarIntegrand j t σ y)* + conditionalFieldWeight j t σ (badFieldFlat n j A ε m) y + +lemma reducedBadDensity_le {n : ℕ} [NeZero n] {j t σ : ℝ} + (hj : 0 ≤ j) (ht : 0 ≤ t) (hσ : 0 < σ) (A ε m : ℝ) (y : Fin n → ℝ) : + reducedBadDensity j t σ A ε m y ≤ ENNReal.ofReal (scalarIntegrand j t σ y) := by + simpa only [reducedBadDensity,mul_one] using scalar_weighted_density_bound hj ht hσ y + (conditionalFieldWeight_le_one j t σ (badFieldFlat n j A ε m) y) + +lemma empirical_of_not_forbidden {n : ℕ} [NeZero n] {R t0 T t σ : ℝ} {U : Set (ScalarTimeDomain R t0 T)} + {y : Fin n → ℝ} (hP : empiricalLaw y ∈ momentBall R) (ht : t∈Icc t0 T) + (hF : scalarEmpirical y t σ ∉ scalarRelativeForbidden U) : + (⟨empiricalLaw y,hP⟩,⟨t,ht⟩) ∈ U := by + by_contra h + exact hF ⟨(⟨empiricalLaw y,hP⟩,⟨t,ht⟩),h,rfl⟩ + +lemma reduced_bad_integral_bound {n : ℕ} [NeZero n] {j t σ R t0 T R1 ν A ε m c : ℝ} + (hj : 0 ≤ j) (ht0 : 0 < t0) (ht : t∈Icc t0 T) (hσ : 0 < σ) (hR : 0 ≤ R) + (U : Set (ScalarTimeDomain R t0 T)) (hU : IsOpen U) + (hcond : ∀ x ∈ U, ∀ y : Fin n → ℝ, empiricalLaw y=(x.1:ProbabilityMeasure ℝ) → + (∑ i,if R1 < |y i| then y i^2 else 0) ≤ ν*(n:ℝ) → + (conditionalGoeLaw (j/(n:ℝ)) ((x.2:ℝ)+σ^2) (magnetization y) + (empiricalObservation j x.2 σ y)).real + {W | ((fun i k=>W (i,k)),y)∈badFieldSet n j A ε m} ≤ exp (-c*(n:ℝ))) : + (∫⁻ y,reducedBadDensity (n := n) j t σ A ε m y) ≤ + (∫⁻ y in {y : Fin n → ℝ | (n:ℝ)*R < ∑ i,y i^2},ENNReal.ofReal (scalarIntegrand j t σ y))+ + (∫⁻ y in {y : Fin n → ℝ | ∑ i,y i^2 ≤ (n:ℝ)*R} ∩ + {y | scalarEmpirical y t σ ∈ scalarRelativeForbidden U},ENNReal.ofReal (scalarIntegrand j t σ y))+ + (∫⁻ y in {y : Fin n → ℝ | (n:ℝ)*ν ≤ ∑ i,squareTail R1 (y i)},ENNReal.ofReal (scalarIntegrand j t σ y))+ + (∫⁻ y,ENNReal.ofReal (scalarIntegrand (ι := Fin n) j t σ y))*ENNReal.ofReal (exp (-c*(n:ℝ))) := by + let B : Set (Fin n → ℝ) := {y | ∑ i,y i^2 ≤ (n:ℝ)*R} + let F : Set (Fin n → ℝ) := {y | scalarEmpirical y t σ ∈ scalarRelativeForbidden U} + let D : Set (Fin n → ℝ) := {y | (n:ℝ)*ν ≤ ∑ i,squareTail R1 (y i)} + have hB : MeasurableSet B := (isClosed_le (by fun_prop) continuous_const).measurableSet + have hF : MeasurableSet F := ((isClosed_scalarRelativeForbidden hU).preimage + (continuous_empiricalLaw.prodMk continuous_const)).measurableSet + have hD : MeasurableSet D := measurableSet_le measurable_const (Finset.measurable_sum _ + (fun i _=>(measurable_squareTail R1).comp (measurable_pi_apply i))) + have hb := weighted_four_region_bound volume (reducedBadDensity (n := n) j t σ A ε m) + (fun y=>ENNReal.ofReal (scalarIntegrand j t σ y)) (measurable_scalarIntegrand j t σ).ennreal_ofReal + B F D hB hF hD (reducedBadDensity_le hj (ht0.le.trans ht.1) hσ A ε m) + (ENNReal.ofReal (exp (-c*(n:ℝ)))) (by + intro y hy + have hP := empirical_momentBall y hR (by simpa only [B,mem_ofPred_eq,Fintype.card_fin] using hy.1.1) + have hx := empirical_of_not_forbidden hP ht hy.1.2 + have htail : (∑ i,if R1 < |y i| then y i^2 else 0) ≤ ν*(n:ℝ) := by + have hh := le_of_lt (not_le.mp (show ¬ (n:ℝ)*ν ≤ ∑ i,squareTail R1 (y i) from hy.2)) + simpa only [squareTail,mul_comm] using hh + have hc' := hcond (⟨empiricalLaw y,hP⟩,⟨t,ht⟩) hx y rfl htail + exact scalar_weighted_density_bound hj (ht0.le.trans ht.1) hσ y + (conditionalFieldWeight_of_real_bound (badFieldFlat n j A ε m) y hc')) + have hBc : Bᶜ={y : Fin n → ℝ | (n:ℝ)*R < ∑ i,y i^2} := by ext y; change (¬ ∑ i,y i^2 ≤ (n:ℝ)*R) ↔ _; exact not_le + simpa only [hBc] using hb + +theorem conditional_bad_integral_rate {j A t0 T : ℝ} (hj : 0 < j) (hj1 : j < 1) + (hA : 1 ≤ A) (hsub : sqrt j*A < 1) (ht0 : 0 < t0) (hT : t0 ≤ T) : + ∃ m ε σ0 a : ℝ, 0 < m ∧ 0 < ε ∧ 0 < σ0 ∧ 0 < a ∧ ∃ N : ℕ, + ∀ (n : ℕ) [NeZero n], N ≤ n → ∀ t ∈ Icc t0 T, ∀ σ ∈ Ioc 0 σ0, + (∫⁻ y,reducedBadDensity (n := n) j t σ A ε m y) ≤ ENNReal.ofReal (exp (-a*(n:ℝ))) := by + have hT0 : 0 ≤ T := ht0.le.trans hT + obtain ⟨R,hR,hTail⟩ := scalar_uniform_tail hj.le hT0 ht0 1 + obtain ⟨m,ν,σc,hm,hν,hσc,U,hU,hKU,hcond⟩ := conditional_field_stability hj hj1 hA hsub hR.le ht0 (T := T) + obtain ⟨R1,aD,haD,ND,hD⟩ := scalar_rate_iv hj hj1 ht0 hT hν + obtain ⟨ε,c,NC,hε,hc,_,hC⟩ := hcond (max R1 1) (le_max_right _ _) + obtain ⟨aF,haF,δ,hδ,NF,hF⟩ := scalar_relative_neighborhood_rate hj hj1 ht0 hT hU hKU + obtain ⟨NG,hG⟩ := scalar_unrestricted_rate hj hj1 hT0 ht0 (half_pos hc) + let b := min 1 (min aF (min aD (c/2))) + have hb : 0 < b := lt_min zero_lt_one (lt_min haF (lt_min haD (half_pos hc))) + obtain ⟨M,hM⟩ := absorb_finite_exponential_factor 4 (half_pos hb) + refine ⟨m,ε,min σc (min δ 1),b/2,hm,hε,lt_min hσc (lt_min hδ zero_lt_one),half_pos hb, + max NC (max ND (max NF (max NG M))),?_⟩ + intro n _ hn t ht σ hσ + have hn' : 0 < n := NeZero.pos n + have hNC : NC ≤ n := (le_max_left _ _).trans hn + have hND : ND ≤ n := (le_max_left ND _).trans ((le_max_right NC _).trans hn) + have hNF : NF ≤ n := (le_max_left NF _).trans ((le_max_right ND _).trans ((le_max_right NC _).trans hn)) + have hNG : NG ≤ n := (le_max_left NG M).trans ((le_max_right NF _).trans ((le_max_right ND _).trans ((le_max_right NC _).trans hn))) + have hMN : M ≤ n := (le_max_right NG M).trans ((le_max_right NF _).trans ((le_max_right ND _).trans ((le_max_right NC _).trans hn))) + have hσ1 : σ∈Icc 0 1 := ⟨hσ.1.le,(min_le_right _ _).trans' ((min_le_right _ _).trans' hσ.2)⟩ + have hσδ : σ∈Icc 0 (min δ 1) := ⟨hσ.1.le,(min_le_right _ _).trans' hσ.2⟩ + have hσc' : |σ| ≤ σc := by rw [abs_of_pos hσ.1]; exact (min_le_left _ _).trans' hσ.2 + let B : Set (Fin n → ℝ) := {y | ∑ i,y i^2 ≤ (n:ℝ)*R} + let F : Set (Fin n → ℝ) := {y | scalarEmpirical y t σ ∈ scalarRelativeForbidden U} + let D : Set (Fin n → ℝ) := {y | (n:ℝ)*ν ≤ ∑ i,squareTail (max R1 1) (y i)} + have hBm : MeasurableSet B := (isClosed_le (by fun_prop) continuous_const).measurableSet + have hFm : MeasurableSet F := ((isClosed_scalarRelativeForbidden hU).preimage + (continuous_empiricalLaw.prodMk continuous_const)).measurableSet + have hDm : MeasurableSet D := measurableSet_le measurable_const (Finset.measurable_sum _ + (fun i _=>(measurable_squareTail (max R1 1)).comp (measurable_pi_apply i))) + have hs (y : Fin n → ℝ) : t0 ≤ scalarS j (scalarEmpirical y t σ) := by + have hq := mul_nonneg hj.le (scalarQMoment_bounds (empiricalLaw y)).1 + change t0 ≤ t+σ^2+j*scalarQMoment (empiricalLaw y) + linarith [ht.1,sq_nonneg σ] + have htail := hTail n hn' t ⟨ht0.le.trans ht.1,ht.2⟩ σ hσ1 Bᶜ hBm.compl + (fun y _=>hs y) (fun y hy=>le_of_lt (not_le.mp hy)) + have hforb := hF n hNF hn' t ht σ hσδ (B∩F) (hBm.inter hFm) + (fun y hy=>empirical_momentBall y hR.le (by simpa only [B,mem_ofPred_eq,Fintype.card_fin] using hy.1)) (by + intro y hy x hx + obtain ⟨z,hz,hze⟩ := hy.2 + by_contra hh + push Not at hh + apply hz + have he : z=x := by + apply Prod.ext <;> apply Subtype.ext + · exact (congrArg Prod.fst hze).trans hh.1 + · exact (congrArg Prod.snd hze).trans hh.2 + simpa only [he] using hx) + have hdiag := hD (max R1 1) (le_max_left _ _) n hND hn' t ht σ hσ1 D hDm (fun _ hy=>hy) + have hglobal := hG n hNG hn' t ⟨ht0.le.trans ht.1,ht.2⟩ σ hσ1 univ MeasurableSet.univ (fun y _=>hs y) + simp only [Measure.restrict_univ] at hglobal + have hgood := mul_le_mul' hglobal (le_rfl (a := ENNReal.ofReal (exp (-c*(n:ℝ))))) + rw [← ENNReal.ofReal_mul (exp_pos _).le,← exp_add] at hgood + have he : c/2*(n:ℝ)+ -c*(n:ℝ)= -(c/2)*(n:ℝ) := by ring + rw [he] at hgood + have hcoeff {r : ℝ} (hr : b ≤ r) : ENNReal.ofReal (exp (-r*(n:ℝ))) ≤ ENNReal.ofReal (exp (-b*(n:ℝ))) := + ENNReal.ofReal_le_ofReal (exp_le_exp.mpr (by nlinarith [Nat.cast_nonneg (α := ℝ) n])) + have hb1 : b ≤ 1 := min_le_left _ _ + have hbF : b ≤ aF := (min_le_right _ _).trans (min_le_left _ _) + have hbD : b ≤ aD := (min_le_right _ _).trans ((min_le_right _ _).trans (min_le_left _ _)) + have hbC : b ≤ c/2 := (min_le_right _ _).trans ((min_le_right _ _).trans (min_le_right _ _)) + have hbound := reduced_bad_integral_bound hj.le ht0 ht hσ.1 hR.le U hU + (fun x hx y hP hy=>hC n hNC x hx y hP hy σ hσc') + have hBc : Bᶜ={y : Fin n → ℝ | (n:ℝ)*R < ∑ i,y i^2} := by ext y; change (¬ ∑ i,y i^2 ≤ (n:ℝ)*R) ↔ _; exact not_le + rw [← hBc] at hbound + have htotal := hbound.trans (add_le_add (add_le_add (add_le_add + (htail.trans (hcoeff hb1)) (hforb.trans (hcoeff hbF))) (hdiag.trans (hcoeff hbD))) + (hgood.trans (hcoeff hbC))) + have hadd : ENNReal.ofReal (exp (-b*(n:ℝ)))+ENNReal.ofReal (exp (-b*(n:ℝ)))+ + ENNReal.ofReal (exp (-b*(n:ℝ)))+ENNReal.ofReal (exp (-b*(n:ℝ)))= + ENNReal.ofReal (4*exp ((n:ℝ)*(-b))) := by + rw [← ENNReal.ofReal_add (exp_pos _).le (exp_pos _).le, + ← ENNReal.ofReal_add (by positivity) (exp_pos _).le, + ← ENNReal.ofReal_add (by positivity) (exp_pos _).le] + congr 1 + ring_nf + rw [hadd] at htotal + apply htotal.trans (ENNReal.ofReal_le_ofReal _) + convert hM n hMN (-b) using 1 + congr 1 + ring +end SKGap +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/ConditionalMiddleSize.lean b/lean/OAI/Probability/SKGap/Localization/ConditionalMiddleSize.lean new file mode 100644 index 0000000000000000000000000000000000000000..f6196eca728592154aa4d617740a466480f0e094 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/ConditionalMiddleSize.lean @@ -0,0 +1,82 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.ConditionalModelAlgebra + +namespace OAI + +section +noncomputable section +namespace SKGap +open Matrix Real Set MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix.Norms.Frobenius + +def conditionalMiddleSize (j V W : ℝ) (p : ScalarPoint) : ℝ := + (1+2*|conditionalKappa j p-1|+|conditionalEll j p-2*conditionalKappa j p+1|)*W+ + 2*(|j*sqrt (scalarQMoment p.1/scalarS j p)| * (sqrt (scalarS j p)*V)+ + |j*scalarA j p/scalarS j p|)+ + |2*j*(scalarA j p+j*scalarBMoment p.1*scalarQMoment p.1)/(scalarS j p+j*scalarQMoment p.1)|+ + |j| * V^2+|2*j*scalarQMoment p.1|+|j*scalarBMoment p.1| + +lemma continuousAt_conditionalMiddleSize {X : Type*} [TopologicalSpace X] + {R : ℝ} (hR : 0 ≤ R) (j V W : ℝ) (f : X → ScalarPoint) (hf : Continuous f) + (hdom : ∀ x,f x ∈ scalarMomentDomain R) {x : X} + (hs : scalarS j (f x) ≠ 0) (hS : scalarS j (f x)+j*scalarQMoment (f x).1 ≠ 0) : + ContinuousAt (fun x=>conditionalMiddleSize j V W (f x)) x := by + have hq := (continuous_scalarQMoment.comp (continuous_fst.comp hf)).continuousAt (x := x) + have hb := (continuous_scalarBMoment.comp (continuous_fst.comp hf)).continuousAt (x := x) + have hss := ((continuous_scalarS j).comp hf).continuousAt (x := x) + have hSS : ContinuousAt (fun x=>scalarS j (f x)+j*scalarQMoment (f x).1) x := hss.add (continuousAt_const.mul hq) + have ha := ((continuousOn_scalarA hR j).comp_continuous hf hdom).continuousAt (x := x) + have hn : ContinuousAt (fun x=>(f x).2.1+(f x).2.2^2) x := by fun_prop + have hk : ContinuousAt (fun x=>conditionalKappa j (f x)) x := (hn.div hss hs).sqrt + have hl : ContinuousAt (fun x=>conditionalEll j (f x)) x := (hn.div hSS hS).sqrt + unfold conditionalMiddleSize + fun_prop (disch := assumption) + +theorem conditionalMiddleSize_uniform {j R t0 T : ℝ} (hj : 0 ≤ j) (hR : 0 ≤ R) + (ht0 : 0 < t0) (V W : ℝ) : + ∃ L : ℝ, 1 ≤ L ∧ ∀ (P : ProbabilityMeasure ℝ), P ∈ momentBall R → + ∀ t ∈ Icc t0 T,∀ σ : ℝ, |σ| ≤ 1 → conditionalMiddleSize j V W (P,t,σ) ≤ L := by + let X : Type := ↥(momentBall R) × ↥(Icc t0 T) × ↥(Icc (-1:ℝ) 1) + let : CompactSpace (momentBall R) := isCompact_iff_compactSpace.mp (isCompact_momentBall R) + let f : X → ScalarPoint := fun x=>((x.1:ProbabilityMeasure ℝ),(x.2.1:ℝ),(x.2.2:ℝ)) + have hf : Continuous f := by dsimp [f,X]; fun_prop + have hdom : ∀ x,f x ∈ scalarMomentDomain R := fun (x : X)=>⟨x.1.2,mem_univ _⟩ + have hc : Continuous (fun x : X=>conditionalMiddleSize j V W (f x)) := by + apply continuous_iff_continuousAt.mpr + intro x + have ht : 0 < (x.2.1:ℝ) := ht0.trans_le x.2.1.2.1 + have hs : 0 < scalarS j (f x) := by + dsimp [scalarS,f] + exact add_pos_of_pos_of_nonneg (add_pos_of_pos_of_nonneg ht (sq_nonneg _)) + (mul_nonneg hj (scalarQMoment_bounds _).1) + have hS : 0 < scalarS j (f x)+j*scalarQMoment (f x).1 := + add_pos_of_pos_of_nonneg hs (mul_nonneg hj (scalarQMoment_bounds _).1) + exact continuousAt_conditionalMiddleSize hR j V W f hf hdom hs.ne' hS.ne' + obtain ⟨M,hM⟩ := isCompact_univ.bddAbove_image hc.continuousOn + refine ⟨max 1 M,le_max_left _ _,?_⟩ + intro P hP t ht σ hσ + let x : X := (⟨P,hP⟩,⟨t,ht⟩,⟨σ,abs_le.mp hσ⟩) + exact (hM (mem_image_of_mem _ (mem_univ x))).trans (le_max_right _ _) + +lemma empirical_column_coefficient {n : ℕ} [NeZero n] {j t0 t T σ : ℝ} + (hj : 0 ≤ j) (ht0 : 0 < t0) (ht : t ∈ Icc t0 T) (y : Fin n → ℝ) : + (1+|scalarD j (empiricalLaw y,t,σ)|)/scalarS j (empiricalLaw y,t,σ) ≤ + max 1 ((1+|T|+j)/t0) := by + have ht' : 0 < t := ht0.trans_le ht.1 + have hd : |scalarD j (empiricalLaw y,t,σ)| ≤ |T|+j := by + apply (abs_add_le _ _).trans + rw [abs_of_pos ht',abs_mul,abs_of_nonneg hj] + have hh := mul_le_mul_of_nonneg_left (scalarM_bounds (empiricalLaw y)) hj + have hT := ht.2.trans (le_abs_self T) + nlinarith only [hh,hT] + have hs : t0 ≤ scalarS j (empiricalLaw y,t,σ) := by + dsimp [scalarS] + exact ht.1.trans (le_add_of_nonneg_right (sq_nonneg σ) |>.trans + (le_add_of_nonneg_right (mul_nonneg hj (scalarQMoment_bounds _).1))) + apply le_trans _ (le_max_right _ _) + exact div_le_div₀ (by positivity) (by linarith) ht0 hs +end SKGap +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/ConditionalModelAlgebra.lean b/lean/OAI/Probability/SKGap/Localization/ConditionalModelAlgebra.lean new file mode 100644 index 0000000000000000000000000000000000000000..0ad6579eddb315a70de71b414bc54f46401da418 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/ConditionalModelAlgebra.lean @@ -0,0 +1,291 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.ConditionalRankAlgebra +import OAI.Probability.SKGap.Matrix.GOEBlockExpansion + +namespace OAI + +section +noncomputable section +namespace SKGap +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius +variable {ι : Type*} [Fintype ι] [DecidableEq ι] + +def conditionalBlockMatrix (r j q s S a B κ ell : ℝ) (u Z : ι → ℝ) + (g : MatrixCoordinates ι → ℝ) : Matrix ι ι ℝ := + goeBlockResidual r κ ell u g+ + vecMulVec u ((j*sqrt (q/s)) • Z-(j*a/s) • u)+ + vecMulVec ((j*sqrt (q/s)) • Z-(j*a/s) • u) u+ + (2*j*(a+B*q)/S) • vecMulVec u u + +def conditionalMeanCoefficient (j q s S a B BA κ : ℝ) := + conditionalCoefficient j + ((2*j*q-2*j*a/s+2*j*(a+B*q)/S+2*BA*(κ-1))/q) + j ((κ-1)*sqrt BA/sqrt q) + +def conditionalScalarCoefficient (q κ ell : ℝ) := + conditionalCoefficient 0 ((ell-2*κ+1)/q) 0 0 + +lemma conditionalCoefficient_add_scalar (j cM cG cN z w : ℝ) : + conditionalCoefficient j cM cG cN+ + z • conditionalCoefficient 0 w 0 0= + conditionalCoefficient j (cM+z*w) cG cN := by + ext i k + cases i with + | inl i => cases k with + | inl k => fin_cases i <;> fin_cases k <;> + simp [conditionalCoefficient] + | inr k => fin_cases i <;> simp [conditionalCoefficient,conditionalCoupling] + | inr i => cases k with + | inl k => fin_cases k <;> simp [conditionalCoefficient,conditionalCoupling] + | inr k => simp [conditionalCoefficient] + +lemma conditionalMeanCoefficient_equality {j q s b κ : ℝ} + (hs : 0 < s) (hq : 0 < q) (hj : 0 ≤ j) : + conditionalMeanCoefficient j q s (s+j*q) (s*b) (j*b) (j*b) κ= + conditionalCoefficient j ((2*j*q+2*(j*b)*(κ-1))/q) j ((κ-1)*sqrt (j*b)/sqrt q) := by + have hS : s+j*q ≠ 0 := ne_of_gt (add_pos_of_pos_of_nonneg hs (mul_nonneg hj hq.le)) + unfold conditionalMeanCoefficient + congr 1 + field_simp + ring + +theorem conditional_hessian_rank_form (r j a B κ ell : ℝ) + {q s S BA : ℝ} (hq : 0 < q) (hs : 0 < s) (hBA : 0 < BA) + (X u Z : ι → ℝ) (D : Matrix ι ι ℝ) (g : MatrixCoordinates ι → ℝ) : + let W := goeMatrix r g + let Q := conditionalColumns X (sqrt q • u) ((sqrt s)⁻¹ • Z) + (residualGramVector BA W u) + 1+D*(B • (1 : Matrix ι ι ℝ)-conditionalBlockMatrix r j q s S a B κ ell u Z g- + j • vecMulVec X X-(2*j*q) • vecMulVec u u)*D= + (1-D*(W-BA • (1 : Matrix ι ι ℝ))*D)- + D*Q*(conditionalMeanCoefficient j q s S a B BA κ+ + goeBilinear r u u g • conditionalScalarCoefficient q κ ell)*Qᵀ*D+ + (B-BA) • (D*D) := by + dsimp only + have hroot : sqrt (q/s)*sqrt s/sqrt q=1 := by + rw [Real.sqrt_div hq.le] + field_simp + have hz : j*sqrt (q/s)*sqrt s/sqrt q=j := by + calc + _ = j*(sqrt (q/s)*sqrt s/sqrt q) := by ring + _ = _ := by rw [hroot,mul_one] + have hrank := conditional_rank_change_basis X u Z (goeMatrix r g*ᵥu) j + (2*j*q-2*j*a/s+2*j*(a+B*q)/S+(ell-2*κ+1)*goeBilinear r u u g) + (j*sqrt (q/s)) (κ-1) hq hs hBA + dsimp only at hrank + rw [hz] at hrank + have hc : conditionalMeanCoefficient j q s S a B BA κ+ + goeBilinear r u u g • conditionalScalarCoefficient q κ ell= + conditionalCoefficient j + ((2*j*q-2*j*a/s+2*j*(a+B*q)/S+(ell-2*κ+1)*goeBilinear r u u g+2*BA*(κ-1))/q) + j ((κ-1)*sqrt BA/sqrt q) := by + unfold conditionalMeanCoefficient conditionalScalarCoefficient + rw [conditionalCoefficient_add_scalar] + congr 1 + ring + rw [hc] + change _ = (1-D*(goeMatrix r g-BA • (1 : Matrix ι ι ℝ))*D)-D*_*_*_*D+_ + have hrank' := congrArg (fun M => D*M*D) hrank + simp only [Matrix.mul_assoc] at hrank' + simp only [residualGramVector] at * + rw [show D*conditionalColumns X (sqrt q • u) ((sqrt s)⁻¹ • Z) + ((sqrt BA)⁻¹ • (goeMatrix r g*ᵥu-BA • u))* + conditionalCoefficient j + ((2*j*q-2*j*a/s+2*j*(a+B*q)/S+(ell-2*κ+1)*goeBilinear r u u g+2*BA*(κ-1))/q) + j ((κ-1)*sqrt BA/sqrt q)* + (conditionalColumns X (sqrt q • u) ((sqrt s)⁻¹ • Z) + ((sqrt BA)⁻¹ • (goeMatrix r g*ᵥu-BA • u)))ᵀ*D= + D*(j • vecMulVec X X+ + (2*j*q-2*j*a/s+2*j*(a+B*q)/S+(ell-2*κ+1)*goeBilinear r u u g) • vecMulVec u u+ + (j*sqrt (q/s)) • (vecMulVec u Z+vecMulVec Z u)+ + (κ-1) • (vecMulVec u (goeMatrix r g*ᵥu)+vecMulVec (goeMatrix r g*ᵥu) u))*D by + simpa only [Matrix.mul_assoc] using hrank'] + unfold conditionalBlockMatrix + rw [goeBlockResidual_expand] + have he : vecMulVec u ((j*sqrt (q/s)) • Z-(j*a/s) • u)+ + vecMulVec ((j*sqrt (q/s)) • Z-(j*a/s) • u) u= + (j*sqrt (q/s)) • (vecMulVec u Z+vecMulVec Z u)-(2*j*a/s) • vecMulVec u u := by + ext i k + simp only [Matrix.add_apply,Matrix.sub_apply,Matrix.smul_apply,vecMulVec_apply, + Pi.sub_apply,Pi.smul_apply,smul_eq_mul] + ring + have hcombine : goeMatrix r g+ + (κ-1) • (vecMulVec u (goeMatrix r g*ᵥu)+vecMulVec (goeMatrix r g*ᵥu) u)+ + ((ell-2*κ+1)*goeBilinear r u u g) • vecMulVec u u+ + vecMulVec u ((j*sqrt (q/s)) • Z-(j*a/s) • u)+ + vecMulVec ((j*sqrt (q/s)) • Z-(j*a/s) • u) u= + goeMatrix r g+(κ-1) • (vecMulVec u (goeMatrix r g*ᵥu)+vecMulVec (goeMatrix r g*ᵥu) u)+ + ((ell-2*κ+1)*goeBilinear r u u g) • vecMulVec u u+ + ((j*sqrt (q/s)) • (vecMulVec u Z+vecMulVec Z u)-(2*j*a/s) • vecMulVec u u) := by + rw [← he] + abel + rw [hcombine] + simp only [Matrix.mul_add,Matrix.mul_sub,Matrix.add_mul,Matrix.sub_mul,Matrix.mul_smul, + Matrix.smul_mul,Matrix.mul_one,sub_smul,add_smul] + abel +end SKGap +end +end + +section +noncomputable section +namespace SKGap +open Real Matrix MeasureTheory ProbabilityTheory Set Filter Topology +open scoped BigOperators Matrix.Norms.Frobenius + +def conditionalKappa (j : ℝ) (p : ScalarPoint) : ℝ := sqrt ((p.2.1+p.2.2^2)/scalarS j p) +def conditionalEll (j : ℝ) (p : ScalarPoint) : ℝ := + sqrt ((p.2.1+p.2.2^2)/(scalarS j p+j*scalarQMoment p.1)) +def conditionalMeanData (j : ℝ) (p : ScalarPoint) (r : ℝ) : + Matrix ((Fin 3) ⊕ Unit) ((Fin 3) ⊕ Unit) ℝ := + conditionalMeanCoefficient j (scalarQMoment p.1) (scalarS j p) + (scalarS j p+j*scalarQMoment p.1) (scalarA j p) + (j*scalarBMoment p.1) (j*scalarBMoment p.1+r) (conditionalKappa j p) +def conditionalScalarData (j : ℝ) (p : ScalarPoint) : + Matrix ((Fin 3) ⊕ Unit) ((Fin 3) ⊕ Unit) ℝ := + conditionalScalarCoefficient (scalarQMoment p.1) (conditionalKappa j p) (conditionalEll j p) +def curveKappa (j t : ℝ) : ℝ := sqrt (t/scalarFixedPoint j t) +def curveCoefficient (j t : ℝ) : Matrix ((Fin 3) ⊕ Unit) ((Fin 3) ⊕ Unit) ℝ := + conditionalCoefficient j + ((2*j*scalarQ j t+2*(j*scalarBMoment (scalarCurve j t))*(curveKappa j t-1))/scalarQ j t) + j ((curveKappa j t-1)*sqrt (j*scalarBMoment (scalarCurve j t))/sqrt (scalarQ j t)) + +lemma conditionalKappa_curve {j t : ℝ} (hj : 0 < j) (hj1 : j < 1) (ht : 0 ≤ t) : + conditionalKappa j (scalarCurve j t,t,0)=curveKappa j t := by + simp only [conditionalKappa,curveKappa,scalarS_curve hj hj1 ht,zero_pow (by decide : 2 ≠ 0),add_zero] + +lemma curveKappa_sq {j t : ℝ} (hj : 0 < j) (hj1 : j < 1) (ht : 0 < t) : + curveKappa j t^2=1-j*scalarQ j t/scalarFixedPoint j t := by + have hs := (scalar_fixed_pos hj hj1 ht).1 + unfold curveKappa + rw [Real.sq_sqrt (div_nonneg ht.le hs.le)] + have he := (scalarFixedPoint_spec hj hj1 ht.le).2 + change scalarFixedPoint j t=t+j*scalarQ j t at he + field_simp + linarith + +lemma conditionalMeanData_curve {j t : ℝ} (hj : 0 < j) (hj1 : j < 1) (ht : 0 < t) : + conditionalMeanData j (scalarCurve j t,t,0) 0=curveCoefficient j t := by + unfold conditionalMeanData curveCoefficient + rw [scalarQMoment_curve hj hj1 ht.le,scalarS_curve hj hj1 ht.le, + scalarA_curve hj hj1 ht,conditionalKappa_curve hj hj1 ht.le,add_zero] + exact conditionalMeanCoefficient_equality (scalar_fixed_pos hj hj1 ht).1 + (scalar_fixed_pos hj hj1 ht).2 hj.le + +lemma continuousAt_conditionalCoefficient {X : Type*} [TopologicalSpace X] + {j a b c : X → ℝ} {x : X} (hj : ContinuousAt j x) (ha : ContinuousAt a x) + (hb : ContinuousAt b x) (hc : ContinuousAt c x) : + ContinuousAt (fun x=>conditionalCoefficient (j x) (a x) (b x) (c x)) x := by + apply continuousAt_pi.mpr + intro i + apply continuousAt_pi.mpr + intro k + cases i with + | inl i => cases k with + | inl k => fin_cases i <;> fin_cases k <;> + simp only [conditionalCoefficient,fromBlocks_apply₁₁,Matrix.of_apply,Matrix.cons_val,Fin.reduceFinMk] <;> first | exact hj | exact ha | exact hb | exact continuousAt_const + | inr k => fin_cases i <;> simp [conditionalCoefficient,conditionalCoupling] <;> first | exact hc | exact continuousAt_const + | inr i => cases k with + | inl k => fin_cases k <;> simp [conditionalCoefficient,conditionalCoupling] <;> first | exact hc | exact continuousAt_const + | inr k => simp [conditionalCoefficient]; exact continuousAt_const + +lemma continuousAt_conditionalMeanCoefficient {p : ℝ × (ℝ × (ℝ × (ℝ × (ℝ × (ℝ × ℝ)))))} + (hq : 0 < p.1) (hs : p.2.1 ≠ 0) (hS : p.2.2.1 ≠ 0) (j : ℝ) : + ContinuousAt (fun p : ℝ × (ℝ × (ℝ × (ℝ × (ℝ × (ℝ × ℝ))))) => + conditionalMeanCoefficient j p.1 p.2.1 p.2.2.1 p.2.2.2.1 p.2.2.2.2.1 + p.2.2.2.2.2.1 p.2.2.2.2.2.2) p := by + have hq0 := hq.ne' + have hsq := (sqrt_pos.mpr hq).ne' + apply continuousAt_pi.mpr + intro i + apply continuousAt_pi.mpr + intro k + cases i with + | inl i => cases k with + | inl k => fin_cases i <;> fin_cases k <;> + simp only [conditionalMeanCoefficient,conditionalCoefficient,fromBlocks_apply₁₁,Matrix.of_apply,Matrix.cons_val,Fin.reduceFinMk] <;> fun_prop (disch := assumption) + | inr k => fin_cases i <;> simp [conditionalMeanCoefficient,conditionalCoefficient,conditionalCoupling] <;> fun_prop (disch := assumption) + | inr i => cases k with + | inl k => fin_cases k <;> simp [conditionalMeanCoefficient,conditionalCoefficient,conditionalCoupling] <;> fun_prop (disch := assumption) + | inr k => simp [conditionalMeanCoefficient,conditionalCoefficient]; fun_prop + +lemma continuousAt_conditionalScalarCoefficient {p : ℝ × (ℝ × ℝ)} (hq : p.1 ≠ 0) : + ContinuousAt (fun p : ℝ × (ℝ × ℝ) => conditionalScalarCoefficient p.1 p.2.1 p.2.2) p := by + unfold conditionalScalarCoefficient conditionalCoefficient conditionalCoupling + fun_prop (disch := assumption) + +lemma continuousAt_conditionalData {X : Type*} [TopologicalSpace X] + {R j : ℝ} (hR : 0 ≤ R) (f : X → ScalarPoint) (hf : Continuous f) + (hdom : ∀ x,f x ∈ scalarMomentDomain R) (r : X → ℝ) (hr : Continuous r) + {x : X} (hq : 0 < scalarQMoment (f x).1) (hs : 0 < scalarS j (f x)) + (hS : 0 < scalarS j (f x)+j*scalarQMoment (f x).1) : + ContinuousAt (fun x=>conditionalMeanData j (f x) (r x)) x ∧ + ContinuousAt (fun x=>conditionalScalarData j (f x)) x := by + have hcq : Continuous (fun x=>scalarQMoment (f x).1) := continuous_scalarQMoment.comp (continuous_fst.comp hf) + have hcs : Continuous (fun x=>scalarS j (f x)) := (continuous_scalarS j).comp hf + have hcS : Continuous (fun x=>scalarS j (f x)+j*scalarQMoment (f x).1) := hcs.add (continuous_const.mul hcq) + have hca : Continuous (fun x=>scalarA j (f x)) := (continuousOn_scalarA hR j).comp_continuous hf hdom + have hcb : Continuous (fun x=>j*scalarBMoment (f x).1) := continuous_const.mul (continuous_scalarBMoment.comp (continuous_fst.comp hf)) + have hcn : Continuous (fun x=>(f x).2.1+(f x).2.2^2) := by fun_prop + have hk : ContinuousAt (fun x=>conditionalKappa j (f x)) x := (hcn.continuousAt.div hcs.continuousAt hs.ne').sqrt + have hl : ContinuousAt (fun x=>conditionalEll j (f x)) x := (hcn.continuousAt.div hcS.continuousAt hS.ne').sqrt + have hq' := hcq.continuousAt (x := x) + have hs' := hcs.continuousAt (x := x) + have hS' := hcS.continuousAt (x := x) + have ha' := hca.continuousAt (x := x) + have hb' := hcb.continuousAt (x := x) + have hba := hb'.add hr.continuousAt + have hM : ContinuousAt (fun x => + (2*j*scalarQMoment (f x).1-2*j*scalarA j (f x)/scalarS j (f x)+ + 2*j*(scalarA j (f x)+j*scalarBMoment (f x).1*scalarQMoment (f x).1)/(scalarS j (f x)+j*scalarQMoment (f x).1)+ + 2*(j*scalarBMoment (f x).1+r x)*(conditionalKappa j (f x)-1))/scalarQMoment (f x).1) x := + ((((continuousAt_const.mul hq').sub ((continuousAt_const.mul ha').div hs' hs.ne')).add + ((continuousAt_const.mul (ha'.add (hb'.mul hq'))).div hS' hS.ne')).add + ((continuousAt_const.mul hba).mul (hk.sub continuousAt_const))).div hq' hq.ne' + have hN : ContinuousAt (fun x => (conditionalKappa j (f x)-1)*sqrt (j*scalarBMoment (f x).1+r x)/sqrt (scalarQMoment (f x).1)) x := + ((hk.sub continuousAt_const).mul hba.sqrt).div hq'.sqrt (sqrt_pos.mpr hq).ne' + constructor + · exact continuousAt_conditionalCoefficient continuousAt_const hM continuousAt_const hN + · have hM' : ContinuousAt (fun x => (conditionalEll j (f x)-2*conditionalKappa j (f x)+1)/scalarQMoment (f x).1) x := + ((hl.sub (continuousAt_const.mul hk)).add continuousAt_const).div hq' hq.ne' + exact continuousAt_conditionalCoefficient continuousAt_const hM' continuousAt_const continuousAt_const + +lemma continuous_curve_statistics {j t0 T : ℝ} (hj : 0 < j) (hj1 : j < 1) (ht0 : 0 < t0) : + Continuous (fun t : Icc t0 T=>scalarFixedPoint j t) ∧ + Continuous (fun t : Icc t0 T=>scalarQ j t) ∧ + Continuous (fun t : Icc t0 T=>scalarBMoment (scalarCurve j t)) ∧ + Continuous (fun t : Icc t0 T=>scalarEMoment (scalarCurve j t)) ∧ + Continuous (fun t : Icc t0 T=>curveKappa j t) ∧ + Continuous (fun t : Icc t0 T=>curveCoefficient j t) := by + let inc : Icc t0 T → Ici (0:ℝ) := fun t=>⟨t,ht0.le.trans t.2.1⟩ + have hi : Continuous inc := continuous_subtype_val.subtype_mk _ + have hs := (continuous_scalarFixedPoint_nonneg hj hj1).comp hi + have hcurve := (continuous_scalarCurve_nonneg hj hj1).comp hi + have hq : Continuous (fun t : Icc t0 T=>scalarQ j t) := by + convert continuous_scalarQMoment.comp hcurve using 1 + funext t + exact (scalarQMoment_curve hj hj1 (ht0.le.trans t.2.1)).symm + have hb := continuous_scalarBMoment.comp hcurve + have he := continuous_scalarEMoment.comp hcurve + have hk : Continuous (fun t : Icc t0 T=>curveKappa j t) := + (continuous_subtype_val.div hs (fun t=>(scalar_fixed_pos hj hj1 (ht0.trans_le t.2.1)).1.ne')).sqrt + refine ⟨hs,hq,hb,he,hk,?_⟩ + apply continuous_iff_continuousAt.mpr + intro t + have hqt : 0 < scalarQ j (t:ℝ) := (scalar_fixed_pos hj hj1 (ht0.trans_le t.2.1)).2 + have hq' := hq.continuousAt (x := t) + have hb' := hb.continuousAt (x := t) + have hk' := hk.continuousAt (x := t) + have hM : ContinuousAt (fun t : Icc t0 T => + (2*j*scalarQ j t+2*(j*scalarBMoment (scalarCurve j t))*(curveKappa j t-1))/scalarQ j t) t := + ((continuousAt_const.mul hq').add + ((continuousAt_const.mul (continuousAt_const.mul hb')).mul (hk'.sub continuousAt_const))).div hq' hqt.ne' + have hN : ContinuousAt (fun t : Icc t0 T => (curveKappa j t-1)*sqrt (j*scalarBMoment (scalarCurve j t))/sqrt (scalarQ j t)) t := + ((hk'.sub continuousAt_const).mul (continuousAt_const.mul hb').sqrt).div hq'.sqrt (sqrt_pos.mpr hqt).ne' + exact continuousAt_conditionalCoefficient continuousAt_const hM continuousAt_const hN +end SKGap +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/ConditionalRankAlgebra.lean b/lean/OAI/Probability/SKGap/Localization/ConditionalRankAlgebra.lean new file mode 100644 index 0000000000000000000000000000000000000000..1fa8f7a82d833deb0fe64dfd2a652245b2b2145e --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/ConditionalRankAlgebra.lean @@ -0,0 +1,199 @@ +import Mathlib +import OAI.Probability.SKGap.Matrix.MatrixWhitening +import OAI.Probability.SKGap.Localization.BilinearUnion +import OAI.Probability.SKGap.Localization.GramUniformRobust + +namespace OAI + +section +noncomputable section +namespace SKGap +open Matrix Real +open scoped BigOperators +variable {ι : Type*} + +def conditionalColumns (X M G N : ι → ℝ) : Matrix ι ((Fin 3) ⊕ Unit) ℝ := + fun i k => Sum.elim (fun l => ![X i,M i,G i] l) (fun _ => N i) k + +def conditionalCoupling (c : ℝ) : Matrix (Fin 3) Unit ℝ := fun k _ => ![0,c,0] k + +def conditionalCoefficient (j cM cG cN : ℝ) : + Matrix ((Fin 3) ⊕ Unit) ((Fin 3) ⊕ Unit) ℝ := + fromBlocks !![j,0,0;0,cM,cG;0,cG,0] (conditionalCoupling cN) + (conditionalCoupling cN)ᵀ 0 + +lemma conditionalCoefficient_hermitian (j cM cG cN : ℝ) : + (conditionalCoefficient j cM cG cN).IsHermitian := by + ext i k + cases i with + | inl i => cases k with + | inl k => fin_cases i <;> fin_cases k <;> simp [conditionalCoefficient,Matrix.conjTranspose_apply] + | inr k => simp [conditionalCoefficient,Matrix.conjTranspose_apply] + | inr i => cases k <;> simp [conditionalCoefficient,Matrix.conjTranspose_apply] + +lemma conditional_rank_expansion (X M G N : ι → ℝ) (j cM cG cN : ℝ) : + conditionalColumns X M G N*conditionalCoefficient j cM cG cN* + (conditionalColumns X M G N)ᵀ = + j • vecMulVec X X+cM • vecMulVec M M+ + cG • (vecMulVec M G+vecMulVec G M)+cN • (vecMulVec M N+vecMulVec N M) := by + ext i k + simp [Matrix.mul_apply,Fintype.sum_sum_type,Fin.sum_univ_succ, + conditionalColumns,conditionalCoefficient,conditionalCoupling,vecMulVec_apply] + ring + +lemma conditional_schur_coefficient {j b s q κ : ℝ} (hb : 0 < b) (hj : 0 < j) + (hs : 0 < s) (hq : 0 < q) (hk : κ^2=1-j*q/s) : + (2*j*q+2*(j*b)*(κ-1))/q = j*(2-j*b/s)-((κ-1)*√(j*b)/√q)^2 := by + have hB : 0 < j*b := mul_pos hj hb + have hq0 : √q ≠ 0 := ne_of_gt (Real.sqrt_pos.2 hq) + rw [div_pow,mul_pow,Real.sq_sqrt hB.le,Real.sq_sqrt hq.le] + field_simp + have hk' : κ^2*s=s-j*q := by + calc + _ = (1-j*q/s)*s := by rw [hk] + _ = _ := by field_simp + nlinarith [hk'] + +lemma conditionalCoefficient_at_equality {j b s q κ : ℝ} (hb : 0 < b) (hj : 0 < j) + (hs : 0 < s) (hq : 0 < q) (hk : κ^2=1-j*q/s) : + conditionalCoefficient j ((2*j*q+2*(j*b)*(κ-1))/q) j ((κ-1)*√(j*b)/√q)= + augmentedCoefficient (rankCoefficient j b s) (conditionalCoupling ((κ-1)*√(j*b)/√q)) := by + have h := conditional_schur_coefficient hb hj hs hq hk + ext i k + cases i with + | inl i => cases k with + | inl k => fin_cases i <;> fin_cases k <;> + simp [conditionalCoefficient,augmentedCoefficient,rankCoefficient,conditionalCoupling, + Matrix.mul_apply,h,pow_two] + | inr k => simp [conditionalCoefficient,augmentedCoefficient] + | inr i => cases k <;> simp [conditionalCoefficient,augmentedCoefficient] + +theorem conditional_rank_change_basis (X U Z V : ι → ℝ) (j cU cZ cV : ℝ) + {q s B : ℝ} (hq : 0 < q) (hs : 0 < s) (hB : 0 < B) : + let Q := conditionalColumns X (√q • U) ((√s)⁻¹ • Z) ((√B)⁻¹ • (V-B • U)) + Q*conditionalCoefficient j ((cU+2*B*cV)/q) (cZ*√s/√q) (cV*√B/√q)*Qᵀ = + j • vecMulVec X X+cU • vecMulVec U U+ + cZ • (vecMulVec U Z+vecMulVec Z U)+cV • (vecMulVec U V+vecMulVec V U) := by + dsimp only + rw [conditional_rank_expansion] + have hq0 : √q ≠ 0 := ne_of_gt (Real.sqrt_pos.2 hq) + have hs0 : √s ≠ 0 := ne_of_gt (Real.sqrt_pos.2 hs) + have hB0 : √B ≠ 0 := ne_of_gt (Real.sqrt_pos.2 hB) + ext i k + simp only [Matrix.add_apply,Matrix.smul_apply,vecMulVec_apply,Pi.smul_apply,Pi.sub_apply, + smul_eq_mul] + field_simp + rw [Real.sq_sqrt hq.le]; ring +end SKGap +end +end + +section +noncomputable section +namespace SKGap +open Matrix Set Real +open scoped MatrixOrder Matrix.Norms.Frobenius + +theorem compact_conditional_rank_criterion {α : Type*} [TopologicalSpace α] [CompactSpace α] + {j : ℝ} (hj : 0 < j) (hj1 : j < 1) (b e s q κ : α → ℝ) + (hb : Continuous b) (he : Continuous e) (hs : Continuous s) + (hq : Continuous q) (hκ : Continuous κ) + (hb0 : ∀ x, 0 < b x) (hb1 : ∀ x, b x ≤ 1) (he0 : ∀ x, 0 ≤ e x) + (hs0 : ∀ x, 0 < s x) (hq0 : ∀ x, 0 < q x) + (hκsq : ∀ x, κ x^2=1-j*q x/s x) : + ∃ δ ρ : ℝ, 0 < δ ∧ δ < 1 ∧ 0 < ρ ∧ + ∀ x (ι : Type) [Fintype ι] [DecidableEq ι] + (S D : Matrix ι ι ℝ) (V : Matrix ι ((Fin 3) ⊕ Unit) ℝ) + (C : Matrix ((Fin 3) ⊕ Unit) ((Fin 3) ⊕ Unit) ℝ) (c : ℝ), + S.PosDef → D.IsHermitian → C.IsHermitian → + (S-c • (1 : Matrix ι ι ℝ)).PosSemidef → + ‖Vᵀ*D*S⁻¹*D*V-augmentedGram (ν := Unit) (limitingGram (b x) (e x) (s x))‖ < ρ → + ‖C-conditionalCoefficient j ((2*j*q x+2*(j*b x)*(κ x-1))/q x) + j ((κ x-1)*√(j*b x)/√(q x))‖ < ρ → + (S-D*V*C*Vᵀ*D-(δ*c) • (1 : Matrix ι ι ℝ)).PosDef := by + let coupling := fun x => conditionalCoupling ((κ x-1)*√(j*b x)/√(q x)) + have hcoupling : Continuous coupling := by + unfold coupling conditionalCoupling + fun_prop (disch := intro x; exact ne_of_gt (Real.sqrt_pos.2 (hq0 x))) + obtain ⟨δ,ρ,hδ,hδ1,hρ,hcrit⟩ := compact_limiting_augmented_gram_robust hj hj1 + b e s coupling hb he hs hcoupling hb1 he0 (fun x => (hs0 x).ne') + refine ⟨δ,ρ,hδ,hδ1,hρ,?_⟩ + intro x ι _ _ S D V C c hS hD hC hc hg hcc + obtain ⟨R,hR,hRR,hu,hgram⟩ := positive_whitening_gram hS D hD V + have hcc' : ‖C-augmentedCoefficient (rankCoefficient j (b x) (s x)) (coupling x)‖ < ρ := by + rw [conditionalCoefficient_at_equality (hb0 x) hj (hs0 x) (hq0 x) (hκsq x)] at hcc + exact hcc + have hh := hcrit x ι (R⁻¹*D*V) C hC (by rw [hgram]; exact hg) hcc' + have hp := positive_unwhitening hR hD hRR hu V C δ hh + have hp' := hp.add_posSemidef (hc.smul hδ.le) + convert hp' using 1 + rw [smul_sub,smul_smul,sub_smul,one_smul] + abel +end SKGap +end +end + +section +noncomputable section +namespace SKGap +open Matrix Real Set +open scoped BigOperators MatrixOrder Matrix.Norms.Frobenius +variable {ι : Type*} [Fintype ι] [DecidableEq ι] + +omit [DecidableEq ι] in +lemma quadratic_lift_real (M : Matrix ι ι ℝ) (v : EuclideanSpace ℝ ι) : + ComplexSpectral.quadratic (RealComplex.liftMatrix M) (RealComplex.liftVec v)=rayleigh M v := by + simp [ComplexSpectral.quadratic,RealComplex.liftMatrix,RealComplex.liftVec, + rayleigh,dotProduct,mulVec] + +lemma complex_lowerRayleigh_margin {M : Matrix ι ι ℝ} (hM : M.IsHermitian) + {c : ℝ} (hc : c < ComplexSpectral.lowerRayleigh (RealComplex.liftMatrix M)) : + (M-c • (1 : Matrix ι ι ℝ)).PosDef := by + apply Matrix.PosDef.of_dotProduct_mulVec_pos (hM.sub + (Matrix.isHermitian_one.smul (R := ℝ) (isSelfAdjoint_iff.mpr (star_trivial c)))) + intro x hx + apply rayleigh_pos_of_unit (M := M-c • (1 : Matrix ι ι ℝ)) (fun v hv => ?_) + (v := WithLp.toLp 2 x) (fun hz => hx (congrArg WithLp.ofLp hz)) + have hv' : ‖v‖=1 := hv + have hh := ComplexSpectral.lowerRayleigh_le (RealComplex.liftMatrix M) + (x := RealComplex.liftVec v) (by + simp only [ComplexSpectral.unitSphere,Metric.mem_sphere,dist_zero_right, + RealComplex.norm_liftVec,hv']) + rw [quadratic_lift_real] at hh + have hsq : v.ofLp⬝ᵥv.ofLp=1 := by + have hn := EuclideanSpace.real_norm_sq_eq v + rw [hv'] at hn + simpa only [dotProduct,pow_two,one_mul] using hn.symm + change 0 < v.ofLp⬝ᵥ((M-c • (1 : Matrix ι ι ℝ))*ᵥv.ofLp) + rw [Matrix.sub_mulVec,Matrix.smul_mulVec,Matrix.one_mulVec,dotProduct_sub, + dotProduct_smul,smul_eq_mul,hsq,mul_one] + exact sub_pos.mpr (lt_of_lt_of_le hc hh) + +theorem bilinearPathGood_margin {n : ℕ} {j A : ℝ} (a : Fin n → ℝ) + (g : MatrixCoordinates (Fin n) → ℝ) (hg : bilinearPathGood j A a g) : + ((1-pathDiagonal a 1*(goeMatrix (j/(n:ℝ)) g- + ((j/(n:ℝ))*∑ i,a i) • 1)*pathDiagonal a 1)- + ((1-sqrt j*A)^2/4) • (1 : Matrix (Fin n) (Fin n) ℝ)).PosDef := by + have hh := hg 1 ⟨by norm_num,le_rfl⟩ + change _ ∧ _ ∧ _ at hh + have he : pathShift 1 ((j/(n:ℝ))*∑ i,a i)=((j/(n:ℝ))*∑ i,a i) • + (1 : Matrix (Fin n) (Fin n) ℝ) := by + ext i k + simp [pathShift,Matrix.diagonal,Matrix.one_apply] + rw [he] at hh + apply complex_lowerRayleigh_margin ?_ hh.2.1 + apply Matrix.isHermitian_one.sub + have hD : (pathDiagonal a 1).IsHermitian := by + exact isHermitian_diagonal_iff.mpr (fun i => isSelfAdjoint_iff.mpr (star_trivial _)) + have hW : (goeMatrix (j/(n:ℝ)) g).IsHermitian := by + change (goeMatrix (j/(n:ℝ)) g)ᴴ=goeMatrix (j/(n:ℝ)) g + simpa only [Matrix.conjTranspose_eq_transpose_of_trivial] using goeMatrix_transpose (j/(n:ℝ)) g + change (pathDiagonal a 1*(goeMatrix (j/(n:ℝ)) g-((j/(n:ℝ))*∑ i,a i) • 1)*pathDiagonal a 1).IsHermitian + unfold Matrix.IsHermitian + simp only [Matrix.conjTranspose_mul,Matrix.conjTranspose_sub,Matrix.conjTranspose_smul, + Matrix.conjTranspose_one,hD.eq,hW.eq,star_trivial,Matrix.mul_assoc] +end SKGap +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/ConditionalTolerance.lean b/lean/OAI/Probability/SKGap/Localization/ConditionalTolerance.lean new file mode 100644 index 0000000000000000000000000000000000000000..b3fcda5e0d5eb61f960daf9df9be45125c89275b --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/ConditionalTolerance.lean @@ -0,0 +1,251 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.EmpiricalConditionalData +import OAI.Probability.SKGap.Gaussian.ConditionalUniformTail + +namespace OAI + +section +noncomputable section +namespace SKGap +open Real Matrix +open scoped BigOperators Matrix.Norms.Frobenius + +def augmentedToleranceConstant (L : ℝ) := + 4*(1+(L+1)*(1+L)+L*(1+2*L+L^2)) + +lemma augmentedToleranceConstant_pos {L : ℝ} (hL : 0 ≤ L) : + 0 < augmentedToleranceConstant L := by unfold augmentedToleranceConstant; positivity + +lemma augmentedGramTolerance_bound {B L ε : ℝ} (hB : 0 < B) (hL : 1 ≤ L) + (hε : 0 ≤ ε) (hb : B ≤ L) (hi : 1/B ≤ L) : + augmentedGramTolerance B ε ≤ augmentedToleranceConstant L*ε := by + have hL0 : 0 ≤ L := by linarith + have hir : (sqrt B)⁻¹ ≤ L+1 := by + have hs : (sqrt B)⁻¹=sqrt B⁻¹ := (sqrt_inv B).symm + rw [hs] + have hh := sq_sqrt (inv_pos.mpr hB).le + have hh' : B⁻¹ ≤ L := by simpa only [one_div] using hi + nlinarith [sq_nonneg (sqrt B⁻¹-1)] + have hB2 : B^2 ≤ L^2 := pow_le_pow_left₀ hB.le hb 2 + have ht1 : (sqrt B)⁻¹*(1+B) ≤ (L+1)*(1+L) := + mul_le_mul hir (by linarith) (by positivity) (by linarith) + have ht2 : B⁻¹*(1+2*B+B^2) ≤ L*(1+2*L+L^2) := + mul_le_mul (by simpa only [one_div] using hi) (by linarith) (by positivity) hL0 + unfold augmentedGramTolerance augmentedToleranceConstant + have h1 := mul_le_mul_of_nonneg_right ht1 hε + have h2 := mul_le_mul_of_nonneg_right ht2 hε + nlinarith + +lemma conditionalMeanData_hermitian (j : ℝ) (p : ScalarPoint) (r : ℝ) : + (conditionalMeanData j p r).IsHermitian := by + exact conditionalCoefficient_hermitian _ _ _ _ +lemma conditionalScalarData_hermitian (j : ℝ) (p : ScalarPoint) : + (conditionalScalarData j p).IsHermitian := by + exact conditionalCoefficient_hermitian _ _ _ _ +end SKGap +end +end + +section +noncomputable section +namespace SKGap +open Real Matrix MeasureTheory ProbabilityTheory Set +open scoped BigOperators Matrix.Norms.Frobenius + +lemma diagonal_mass_margin {n : ℕ} (H : Matrix (Fin n) (Fin n) ℝ) + (a : Fin n → ℝ) {m r A : ℝ} (ha : ∀ i,0 ≤ a i) (hA : ∀ i,a i ≤ A) + (hr : |r| * A ≤ m) (hH : (H-(2*m) • (1 : Matrix (Fin n) (Fin n) ℝ)).PosDef) : + (H-r • diagonal a-m • (1 : Matrix (Fin n) (Fin n) ℝ)).PosDef := by + have hd : (diagonal (fun i=>m-r*a i)).PosSemidef := Matrix.PosSemidef.diagonal (fun i=>by + change 0 ≤ m-r*a i + have hh : r*a i ≤ |r| * A := (mul_le_mul_of_nonneg_right (le_abs_self r) (ha i)).trans + (mul_le_mul_of_nonneg_left (hA i) (abs_nonneg r)) + linarith) + convert hH.add_posSemidef hd using 1 + ext i k + by_cases hik : i=k + · subst k; simp; ring + · simp [hik] + +lemma empirical_moment_vector_bound {n : ℕ} [NeZero n] {R : ℝ} + (hR : 0 ≤ R) (y : Fin n → ℝ) (hy : empiricalLaw y ∈ momentBall R) : + ∑ i,y i^2 ≤ (R+1)^2*(n:ℝ) := by + have hh := momentBall_integral_le hR hy + rw [integral_empiricalLaw] at hh + simp only [Fintype.card_fin] at hh + have hn : 0 < (n:ℝ) := by exact_mod_cast NeZero.pos n + have hp := mul_le_mul_of_nonneg_left hh hn.le + have hp' : ∑ i,y i^2 ≤ R*(n:ℝ) := by + simpa only [← mul_assoc,mul_inv_cancel₀ hn.ne',one_mul,mul_comm (n:ℝ) R] using hp + have hR' : R ≤ (R+1)^2 := by nlinarith [sq_nonneg R] + exact hp'.trans (mul_le_mul_of_nonneg_right hR' hn.le) + +lemma empirical_cutoff_gram_small {n : ℕ} [NeZero n] (a y : Fin n → ℝ) + {A L ε ν R1 ρ d s : ℝ} + (ha : ∀ i,0 ≤ a i) (haA : ∀ i,a i ≤ A) (hA : 0 ≤ A) + (hs : 0 < s) (hL : 1 ≤ L) (hd : (1+|d|)/s ≤ L) + (hR1 : 1 ≤ R1) (hε : 0 ≤ ε) (hν : 0 ≤ ν) + (haclose : ∑ i,(a i-(1-tanh (y i)^2))^2 ≤ ε^2*(n:ℝ)) + (hy : (∑ i,if R1 < |y i| then y i^2 else 0) ≤ ν*(n:ℝ)) + (hεgram : 8*L^2*(1+R1^2)*ε ≤ ρ/8) + (hνgram : 16*L^2*(A+1)*ν ≤ ρ/8) : + ‖diagonalAugmentedGram a (empiricalGramColumns y d s)- + augmentedGram (ν := Unit) (scalarMomentGram (empiricalLaw y) d s)‖ ≤ ρ/4 := by + have hdiff (i : Fin n) : |a i-(1-tanh (y i)^2)| ≤ A+1 := by + have hv0 := tanh_sq_lt_one (y i) + have hv1 := sq_nonneg (tanh (y i)) + exact abs_le.mpr ⟨by linarith [ha i],by linarith [haA i]⟩ + have hg := empirical_augmented_gram_comparison a y hs hL hd + (by positivity : 0 ≤ A+1) hR1 hε hν hdiff haclose hy + apply hg.trans + nlinarith + +lemma gram_close_by_quarters {α : Type*} [SeminormedAddCommGroup α] (a b c : α) + {ρ : ℝ} (hab : ‖a-b‖ ≤ ρ/4) (hbc : ‖b-c‖ < ρ/4) : ‖a-c‖ < ρ/2 := by + exact (norm_sub_le_norm_sub_add_norm_sub a b c).trans_lt (by linarith) + +def conditionalEmpiricalCore {n : ℕ} [NeZero n] (j t σ : ℝ) (a y : Fin n → ℝ) + (g : MatrixCoordinates (Fin n) → ℝ) : Matrix (Fin n) (Fin n) ℝ := + let p : ScalarPoint := (empiricalLaw y,t,σ) + let B := j*scalarBMoment p.1 + let BA := j/(n:ℝ)*∑ i,a i + let u := empiricalUnit y (scalarQMoment p.1) + let V := conditionalUpdateColumns j a (empiricalGramColumns y (scalarD j p) (scalarS j p)) u g + conditionalBase j a g-pathDiagonal a 1*V* + (conditionalMeanData j p (BA-B)+matrixBilinear (goeMatrix (j/(n:ℝ)) g) u u • conditionalScalarData j p)* + Vᵀ*pathDiagonal a 1+(B-BA) • diagonal a + +theorem conditional_empirical_fixed_tail {j A R t0 T : ℝ} + (hj : 0 < j) (hj1 : j < 1) (hA : 1 ≤ A) (hsub : sqrt j*A < 1) + (hR : 0 ≤ R) (ht0 : 0 < t0) : + ∃ m ν σ0 : ℝ, 0 < m ∧ 0 < ν ∧ 0 < σ0 ∧ + ∃ U : Set (ScalarTimeDomain R t0 T), IsOpen U ∧ scalarEqualitySet j R t0 T ⊆ U ∧ + ∀ R1 : ℝ, 1 ≤ R1 → ∃ ε c : ℝ, ∃ N : ℕ, 0 < ε ∧ 0 < c ∧ 0 < N ∧ + ∀ (n : ℕ) [NeZero n], N ≤ n → ∀ x ∈ U, ∀ y : Fin n → ℝ, + empiricalLaw y=(x.1 : ProbabilityMeasure ℝ) → + (∑ i,if R1 < |y i| then y i^2 else 0) ≤ ν*(n:ℝ) → + ∀ σ : ℝ, |σ| ≤ σ0 → ∀ a : Fin n → ℝ, (∀ i,0 ≤ a i) → (∀ i,a i ≤ A) → + (∑ i,(a i-(1-tanh (y i)^2))^2) ≤ ε^2*(n:ℝ) → + (Measure.pi (fun _ : MatrixCoordinates (Fin n)=>gaussianReal 0 1)).real + {g | ¬(conditionalEmpiricalCore j x.2 σ a y g-m • (1 : Matrix (Fin n) (Fin n) ℝ)).PosDef} ≤ + 101*exp (-c*(n:ℝ)) := by + have hA0 : 0 < A := by linarith + obtain ⟨hs,hq,hb,he,hκ,_⟩ := continuous_curve_statistics (T := T) hj hj1 ht0 + obtain ⟨δ,ρ,hδ,_,hρ,htail⟩ := compact_conditional_uniform_tail hj hj1 hA0 hsub + (fun t : Icc t0 T=>scalarBMoment (scalarCurve j t)) + (fun t : Icc t0 T=>scalarEMoment (scalarCurve j t)) + (fun t : Icc t0 T=>scalarFixedPoint j t) (fun t : Icc t0 T=>scalarQ j t) + (fun t : Icc t0 T=>curveKappa j t) hb he hs hq hκ + (fun t=>scalarBMoment_pos _) (fun t=>scalarBMoment_le_one _) (fun t=>scalarEMoment_nonneg _) + (fun t=>(scalar_fixed_pos hj hj1 (ht0.trans_le t.2.1)).1) + (fun t=>(scalar_fixed_pos hj hj1 (ht0.trans_le t.2.1)).2) + (fun t=>curveKappa_sq hj hj1 (ht0.trans_le t.2.1)) + obtain ⟨L,hL,U,hU,hKU,σ0,hσ0,hnb⟩ := scalar_conditional_neighborhood (R := R) (T := T) hj hj1 hR ht0 (by positivity : 0 < ρ/4) + let m := δ*((1-sqrt j*A)^2/4)/2 + have hm : 0 < m := by dsimp [m]; positivity + let terr := 16*L^2*(A+1) + have hterr : 0 < terr := by dsimp [terr]; positivity + let ν := ρ/(8*terr) + have hν : 0 < ν := by dsimp [ν]; positivity + let Vbound := 2*L*(R+2)+1 + have hV : 0 ≤ Vbound := by dsimp [Vbound]; positivity + let K := augmentedToleranceConstant L + have hK : 0 < K := augmentedToleranceConstant_pos (by linarith) + let εg := ρ/(4*K) + let τ := ρ/(4*(L+1)) + have hεg : 0 < εg := by dsimp [εg]; positivity + have hτ : 0 < τ := by dsimp [τ]; positivity + obtain ⟨c,N,hc,hN,hfixed⟩ := htail Vbound hV εg τ hεg hτ + refine ⟨m,ν,σ0,hm,hν,hσ0,U,hU,hKU,?_⟩ + intro R1 hR1 + let berr := 8*L^2*(1+R1^2) + have hberr : 0 < berr := by dsimp [berr]; positivity + let ε := min (σ0/(j+1)) (min (ρ/(8*berr)) (m/(j*A+1))) + have hε : 0 < ε := by dsimp [ε]; positivity + have hεσ : ε*(j+1) ≤ σ0 := (le_div_iff₀ (by positivity)).mp (min_le_left _ _) + have hεgram : berr*ε ≤ ρ/8 := by + have hh : ε ≤ ρ/(8*berr) := (min_le_right _ _).trans (min_le_left _ _) + have hh' := (le_div_iff₀ (by positivity : 0 < 8*berr)).mp hh + nlinarith only [hh'] + have hεmass : ε*(j*A+1) ≤ m := (le_div_iff₀ (by positivity)).mp ((min_le_right _ _).trans (min_le_right _ _)) + refine ⟨ε,c,N,hε,hc,hN,?_⟩ + intro n _ hn x hx y hP hy σ hσ a ha haA haclose + let p : ScalarPoint := (empiricalLaw y,(x.2:ℝ),σ) + let BA := j/(n:ℝ)*∑ i,a i + let B := j*scalarBMoment (empiricalLaw y) + let r := BA-B + have hr : |r| ≤ j*ε := empirical_mass_close a y hj.le hε.le haclose + have hrσ : |r| ≤ σ0 := hr.trans (by nlinarith only [hεσ,hε.le]) + have hnbe := hnb x hx σ r hσ hrσ + rw [← hP] at hnbe + change 0 < scalarQMoment p.1 ∧ 0 < scalarS j p ∧ 0 < B+r ∧ + conditionalScalarSize j p r < L ∧ _ ∧ _ at hnbe + have hBr : B+r=BA := by dsimp [r]; ring + have hBA : 0 < BA := by simpa only [hBr] using hnbe.2.2.1 + have hd := conditionalSize_bounds hnbe.1 hnbe.2.1 hnbe.2.2.1 hnbe.2.2.2.1 + have hBAle : BA < L := by + have hh := hd.2.2.2.2.1 + change B+r(empiricalGramColumns_norm (NeZero.pos n) y hnbe.2.1 hL (by linarith : 0 ≤ R+1) hd.1.le hvecmom k).trans (by dsimp [Vbound]; linarith) + have hubound : ‖u‖ ≤ Vbound := by + rw [empiricalUnit_norm y hnbe.1] + dsimp [Vbound] + have hp : 0 ≤ 2*L*(R+2) := by positivity + linarith + have hunit : u.ofLp⬝ᵥu.ofLp=1 := empiricalUnit_unit y hnbe.1 + have hνgram : 16*L^2*(A+1)*ν ≤ ρ/8 := by + have ht : terr*ν=ρ/8 := by dsimp [ν]; field_simp + exact ht.le + have hgsmall := empirical_cutoff_gram_small a y ha haA hA0.le hnbe.2.1 hL hd.1.le + hR1 hε.le hν.le haclose hy hεgram hνgram + have hGram : ‖diagonalAugmentedGram a cols-augmentedGram (ν := Unit) + (limitingGram (scalarBMoment (scalarCurve j x.2)) (scalarEMoment (scalarCurve j x.2)) + (scalarFixedPoint j x.2))‖ < ρ/2 := by + exact gram_close_by_quarters _ _ _ hgsmall hnbe.2.2.2.2.1 + have hCoef : ‖conditionalMeanData j p r-curveCoefficient j x.2‖ < ρ/2 := + hnbe.2.2.2.2.2.trans (by linarith) + have hprob := hfixed n hn a ha haA hBA htol cols u hpbound hubound hunit x.2 + (conditionalMeanData j p r) (conditionalScalarData j p) + (conditionalMeanData_hermitian j p r) (conditionalScalarData_hermitian j p) hEbound hGram hCoef + apply le_trans (measureReal_mono (s₂ := {g | ¬(conditionalBase j a g- + pathDiagonal a 1*conditionalUpdateColumns j a cols u g* + (conditionalMeanData j p r+matrixBilinear (goeMatrix (j/(n:ℝ)) g) u u • conditionalScalarData j p)* + (conditionalUpdateColumns j a cols u g)ᵀ*pathDiagonal a 1- + (δ*((1-sqrt j*A)^2/4)) • (1 : Matrix (Fin n) (Fin n) ℝ)).PosDef}) ?_ (measure_ne_top _ _)) hprob + intro g hg + contrapose! hg + simp only [Set.mem_ofPred_eq,not_not] at hg ⊢ + have hrm : |r| * A ≤ m := by + apply (mul_le_mul_of_nonneg_right hr hA0.le).trans + nlinarith only [hεmass,hε.le] + have hm2 : 2*m=δ*((1-sqrt j*A)^2/4) := by dsimp [m]; ring + have hh := diagonal_mass_margin _ a ha haA hrm (by rw [hm2]; exact hg) + convert hh using 1 + dsimp [conditionalEmpiricalCore,p,B,BA,r,cols,u] + congr 1 + module +end SKGap +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/ConditionalWeight.lean b/lean/OAI/Probability/SKGap/Localization/ConditionalWeight.lean new file mode 100644 index 0000000000000000000000000000000000000000..6894c44b4c4c339d1f51a87fdeeab13e4f8f4e6c --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/ConditionalWeight.lean @@ -0,0 +1,62 @@ +import Mathlib +import OAI.Probability.SKGap.Stability.FieldIntegralReduction + +namespace OAI + +section +noncomputable section +namespace SKGap +open Matrix Real Set MeasureTheory ProbabilityTheory GaussianDensity +open scoped BigOperators Matrix.Norms.Frobenius ENNReal + +instance conditionalGoeLaw_probability {ι : Type*} [Fintype ι] [DecidableEq ι] [Nonempty ι] + (r v : ℝ) (m z : ι → ℝ) : IsProbabilityMeasure (conditionalGoeLaw r v m z) := by + unfold conditionalGoeLaw + infer_instance + +lemma conditionalFieldWeight_le_one {n : ℕ} [NeZero n] (j t σ : ℝ) + (E : Set (((Fin n×Fin n) → ℝ) × (Fin n → ℝ))) (y : Fin n → ℝ) : + conditionalFieldWeight j t σ E y ≤ 1 := prob_le_one + +lemma conditionalFieldWeight_of_real_bound {n : ℕ} [NeZero n] {j t σ c : ℝ} + (E : Set (((Fin n×Fin n) → ℝ) × (Fin n → ℝ))) (y : Fin n → ℝ) + (hb : (conditionalGoeLaw (j/(n:ℝ)) (t+σ^2) (magnetization y) (empiricalObservation j t σ y)).real + {W | (W,y)∈E} ≤ c) : conditionalFieldWeight j t σ E y ≤ ENNReal.ofReal c := by + rw [← ENNReal.ofReal_toReal (show conditionalFieldWeight j t σ E y ≠ ⊤ from measure_ne_top _ _)] + exact ENNReal.ofReal_le_ofReal hb + +lemma measurable_scalarIntegrand {n : ℕ} [NeZero n] (j t σ : ℝ) : + Measurable (scalarIntegrand (ι := Fin n) j t σ) := by + unfold scalarIntegrand productNormal scalarEmpirical scalarPsi scalarA scalarD scalarS scalarM scalarQMoment + simp only [integral_empiricalLaw] + unfold gaussianPDFReal + fun_prop + +lemma scalar_density_prefactor_le_one {n : ℕ} [NeZero n] {j t σ : ℝ} + (hj : 0 ≤ j) (ht : 0 ≤ t) (hσ : 0 < σ) (y : Fin n → ℝ) : + sqrt (scalarS j (scalarEmpirical y t σ)/ + (scalarS j (scalarEmpirical y t σ)+j*scalarQMoment (empiricalLaw y))) ≤ 1 := by + have hq : 0 ≤ j*scalarQMoment (empiricalLaw y) := mul_nonneg hj (scalarQMoment_bounds _).1 + have hs : 0 < scalarS j (scalarEmpirical y t σ) := add_pos_of_pos_of_nonneg + (add_pos_of_nonneg_of_pos ht (sq_pos_of_pos hσ)) hq + exact sqrt_le_one.mpr ((div_le_one (add_pos_of_pos_of_nonneg hs hq)).mpr (le_add_of_nonneg_right hq)) + +lemma scalarIntegrand_nonneg {n : ℕ} [NeZero n] (j t σ : ℝ) (y : Fin n → ℝ) : + 0 ≤ scalarIntegrand j t σ y := mul_nonneg (exp_pos _).le + (Finset.prod_nonneg (fun i _=>gaussianPDFReal_nonneg _ _ (y i))) + +lemma scalar_weighted_density_bound {n : ℕ} [NeZero n] {j t σ : ℝ} + (hj : 0 ≤ j) (ht : 0 ≤ t) (hσ : 0 < σ) (y : Fin n → ℝ) {w b : ℝ≥0∞} + (hw : w ≤ b) : + ENNReal.ofReal (sqrt (scalarS j (scalarEmpirical y t σ)/ + (scalarS j (scalarEmpirical y t σ)+j*scalarQMoment (empiricalLaw y)))*scalarIntegrand j t σ y)*w ≤ + ENNReal.ofReal (scalarIntegrand j t σ y)*b := by + apply mul_le_mul' _ hw + apply ENNReal.ofReal_le_ofReal + exact mul_le_of_le_one_left (scalarIntegrand_nonneg j t σ y) (scalar_density_prefactor_le_one hj ht hσ y) + +end SKGap +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/ConditionalWellDefined.lean b/lean/OAI/Probability/SKGap/Localization/ConditionalWellDefined.lean new file mode 100644 index 0000000000000000000000000000000000000000..4f62d05dd08dbc51a6422021010e34f3c4088124 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/ConditionalWellDefined.lean @@ -0,0 +1,120 @@ +import Mathlib +import OAI.Probability.SKGap.Matrix.ConditionalEmpiricalNorm +import OAI.Probability.SKGap.Localization.SparseShrink + +namespace OAI + +section +noncomputable section +namespace SKGap +open Real Matrix MeasureTheory ProbabilityTheory Set +open scoped BigOperators Matrix.Norms.Frobenius + +theorem empirical_conditional_wellDefined {j R t0 T : ℝ} + (hj : 0 < j) (hj1 : j < 1) (hR : 0 ≤ R) (ht0 : 0 < t0) : + ∃ U : Set (ScalarTimeDomain R t0 T), IsOpen U ∧ scalarEqualitySet j R t0 T ⊆ U ∧ + ∃ σ0 ε0 : ℝ, 0 < σ0 ∧ 0 < ε0 ∧ ∀ x ∈ U,∀ σ : ℝ, |σ| ≤ σ0 → + ∀ (n : ℕ) [NeZero n] (y a : Fin n → ℝ), empiricalLaw y=(x.1:ProbabilityMeasure ℝ) → + (∑ i,(a i-(1-tanh (y i)^2))^2) ≤ ε0^2*(n:ℝ) → + 0 < scalarQMoment (empiricalLaw y) ∧ 0 < scalarS j (empiricalLaw y,(x.2:ℝ),σ) ∧ + 0 < j/(n:ℝ)*∑ i,a i := by + obtain ⟨L,hL,U,hU,hKU,δ,hδ,hnb⟩ := scalar_conditional_neighborhood (R := R) (T := T) + hj hj1 hR ht0 (by norm_num : (0:ℝ)<1) + let ε := δ/(j+1) + have hε : 0 < ε := by dsimp [ε]; positivity + have hεδ : j*ε ≤ δ := by + have hh : (j+1)*ε=δ := by dsimp [ε]; field_simp + nlinarith only [hh,hε.le] + refine ⟨U,hU,hKU,δ,ε,hδ,hε,?_⟩ + intro x hx σ hσ n _ y a hP hclose + let r := j/(n:ℝ)*∑ i,a i-j*scalarBMoment (empiricalLaw y) + have hr : |r| ≤ δ := (empirical_mass_close a y hj.le hε.le hclose).trans hεδ + have hh := hnb x hx σ r hσ hr + rw [← hP] at hh + refine ⟨hh.1,hh.2.1,?_⟩ + have hB : j*scalarBMoment (empiricalLaw y)+r=j/(n:ℝ)*∑ i,a i := by dsimp [r]; ring + simpa only [hB] using hh.2.2.1 +end SKGap +end +end + +section +noncomputable section +namespace SKGap +open Matrix Real Set MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix.Norms.Frobenius + +lemma four_radius_sq_le {ε δ : ℝ} (hε : 0 ≤ ε) (hεδ : ε ≤ δ/2) : + 4*ε^2 ≤ δ^2 := by + have hh := mul_self_le_mul_self (by linarith : 0 ≤ 2*ε) (by linarith : 2*ε ≤ δ) + nlinarith only [hh] + +theorem conditional_empirical_simultaneous {j A R t0 T : ℝ} + (hj : 0 < j) (hj1 : j < 1) (hA : 1 ≤ A) (hsub : sqrt j*A < 1) + (hR : 0 ≤ R) (ht0 : 0 < t0) : + ∃ m ν σ0 : ℝ, 0 < m ∧ 0 < ν ∧ 0 < σ0 ∧ + ∃ U : Set (ScalarTimeDomain R t0 T), IsOpen U ∧ scalarEqualitySet j R t0 T ⊆ U ∧ + ∀ R1 : ℝ, 1 ≤ R1 → ∃ ε c : ℝ, ∃ N : ℕ, 0 < ε ∧ 0 < c ∧ 0 < N ∧ + ∀ (n : ℕ) [NeZero n], N ≤ n → ∀ x ∈ U, ∀ y : Fin n → ℝ, + empiricalLaw y=(x.1 : ProbabilityMeasure ℝ) → + (∑ i,if R1 < |y i| then y i^2 else 0) ≤ ν*(n:ℝ) → + ∀ σ : ℝ, |σ| ≤ σ0 → + (Measure.pi (fun _ : MatrixCoordinates (Fin n)=>gaussianReal 0 1)).real + {g | ∃ a, (∀ i,a i ∈ Icc 0 A) ∧ + (∑ i,(a i-(1-tanh (y i)^2))^2) ≤ ε^2*(n:ℝ) ∧ + ¬(diagonalHessian a (empiricalConditionalMiddle j x.2 σ y g)- + m • (1 : Matrix (Fin n) (Fin n) ℝ)).PosSemidef} ≤ + 103*exp (-c*(n:ℝ)) := by + obtain ⟨m,ν,σf,hm,hν,hσf,Uf,hUf,hKUf,hfixed⟩ := + conditional_empirical_fixed_tail (T := T) hj hj1 hA hsub hR ht0 + obtain ⟨Uw,hUw,hKUw,σw,εw,hσw,hεw,hwell⟩ := + empirical_conditional_wellDefined (T := T) hj hj1 hR ht0 + obtain ⟨L,hL,hnorm⟩ := empiricalConditionalMiddle_uniform_norm (T := T) hj.le hR ht0 (2*sqrt j+1) + let σ0 := min 1 (min σf σw) + have hσ0 : 0 < σ0 := by dsimp [σ0]; positivity + refine ⟨m/2,ν,σ0,half_pos hm,hν,hσ0,Uf ∩ Uw,hUf.inter hUw,?_,?_⟩ + · exact fun x hx=>⟨hKUf hx,hKUw hx⟩ + intro R1 hR1 + obtain ⟨εf,c,N,hεf,hc,hN,hfix⟩ := hfixed R1 hR1 + obtain ⟨εs,hεs,hsparse⟩ := conditional_sparse_uniform hj (by linarith : 0 < A) + (by linarith : 0 < L) hm hc + let ε := min εs (min (εf/2) (εw/2)) + have hε : 0 < ε := by dsimp [ε]; positivity + have hεs' : ε ≤ εs := min_le_left _ _ + have hεf' : ε ≤ εf/2 := (min_le_right _ _).trans (min_le_left _ _) + have hεw' : ε ≤ εw/2 := (min_le_right _ _).trans (min_le_right _ _) + let c0 := min (1/(π^2*j)) (c/2) + have hc0 : 0 < c0 := by dsimp [c0]; positivity + refine ⟨ε,c0,N,hε,hc0,hN,?_⟩ + intro n _ hn x hx y hP hy σ hσ + have hσ1 : |σ| ≤ 1 := hσ.trans (min_le_left _ _) + have hσf' : |σ| ≤ σf := hσ.trans ((min_le_right _ _).trans (min_le_left _ _)) + have hσw' : |σ| ≤ σw := hσ.trans ((min_le_right _ _).trans (min_le_right _ _)) + let v : Fin n → ℝ := fun i=>1-tanh (y i)^2 + have hv (i : Fin n) : v i ∈ Icc 0 A := ⟨by dsimp [v]; linarith [tanh_sq_lt_one (y i)], + by dsimp [v]; linarith [sq_nonneg (tanh (y i))]⟩ + have hzero : (∑ i,(v i-(1-tanh (y i)^2))^2) ≤ εw^2*(n:ℝ) := by + simp only [v,sub_self,zero_pow (by norm_num : 2 ≠ 0),Finset.sum_const_zero] + positivity + have hpos := hwell x hx.2 σ hσw' n y v hP hzero + have hnorm' : ∀ g,opNorm (goeMatrix (j/(n:ℝ)) g) ≤ 2*sqrt j+1 → + opNorm (empiricalConditionalMiddle j x.2 σ y g) ≤ L := + hnorm n y (by rw [hP]; exact x.1.2) hpos.1 x.2 x.2.2 σ hσ1 + apply hsparse ε hε hεs' n v hv (empiricalConditionalMiddle j x.2 σ y) + (empiricalConditionalMiddle_hermitian j x.2 σ y) hnorm' + intro b hb hbclose + have hclosef : (∑ i,(b i-(1-tanh (y i)^2))^2) ≤ εf^2*(n:ℝ) := + hbclose.trans (mul_le_mul_of_nonneg_right (four_radius_sq_le hε.le hεf') (Nat.cast_nonneg n)) + have hclosew : (∑ i,(b i-(1-tanh (y i)^2))^2) ≤ εw^2*(n:ℝ) := + hbclose.trans (mul_le_mul_of_nonneg_right (four_radius_sq_le hε.le hεw') (Nat.cast_nonneg n)) + have hposb := hwell x hx.2 σ hσw' n y b hP hclosew + have heq (g : MatrixCoordinates (Fin n) → ℝ) := conditionalEmpiricalCore_eq_hessian j x.2 σ b y g + (fun i=>(hb i).1) hposb.1 hposb.2.1 hposb.2.2 + have hh := hfix n hn x hx.1 y hP hy σ hσf' b (fun i=>(hb i).1) (fun i=>(hb i).2) hclosef + simp only [heq] at hh + exact hh +end SKGap +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/Conjugation.lean b/lean/OAI/Probability/SKGap/Localization/Conjugation.lean new file mode 100644 index 0000000000000000000000000000000000000000..e5550e95f666462ff3306ca0d1ac83cac23aab1a --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/Conjugation.lean @@ -0,0 +1,136 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.RealPart + +namespace OAI + +section +noncomputable section +namespace SKGap.ComplexMatrix +open Matrix +open scoped Matrix.Norms.Frobenius SchwartzMap +variable {ι : Type*} [Fintype ι] [DecidableEq ι] + +lemma conjugate_frobenius (U : unitary (Matrix ι ι ℂ)) (M : Matrix ι ι ℂ) : + ‖conjugate U M‖ = ‖M‖ := by + change ‖(U : Matrix ι ι ℂ)*M*(U : Matrix ι ι ℂ)ᴴ‖ = _ + rw [frobenius_mul_unitary ((U : Matrix ι ι ℂ)*M) ((U : Matrix ι ι ℂ)ᴴ) (Unitary.star_mem U.property), + frobenius_unitary_mul _ _ U.property] + +noncomputable def conjugateIsometry (U : unitary (Matrix ι ι ℂ)) : + Matrix ι ι ℂ ≃ₗᵢ[ℝ] Matrix ι ι ℂ where + toLinearEquiv := (conjugate U).toAlgEquiv.toLinearEquiv.restrictScalars ℝ + norm_map' := conjugate_frobenius U + +lemma conjugate_opNorm (U : unitary (Matrix ι ι ℂ)) (M : Matrix ι ι ℂ) : + opNorm (conjugate U M) = opNorm M := by + change ‖lin ((U : Matrix ι ι ℂ)*M*(U : Matrix ι ι ℂ)ᴴ)‖ = _ + rw [lin_mul,lin_mul] + have hstar : lin ((U : Matrix ι ι ℂ)ᴴ) ∈ unitary _ := lin_unitary _ (Unitary.star_mem U.property) + rw [CStarRing.norm_mul_mem_unitary _ hstar, + CStarRing.norm_mem_unitary_mul _ (lin_unitary _ U.property)] + rfl + +lemma matrixProject_conjugate (U : unitary (Matrix ι ι ℂ)) {R : ℝ} (hR : 0 ≤ R) + (M : Matrix ι ι ℂ) : + matrixProject R hR (conjugate U M) = conjugate U (matrixProject R hR M) := by + apply convexProject_equivariant (hermitianBall_good hR) (conjugateIsometry U) + intro N + change ((conjugate U N)ᴴ = conjugate U N ∧ opNorm (conjugate U N) ≤ R) ↔ + (Nᴴ = N ∧ opNorm N ≤ R) + have hh : (conjugate U N)ᴴ = conjugate U Nᴴ := (map_star (conjugate U) N).symm + have he : conjugate U Nᴴ = conjugate U N ↔ Nᴴ=N := + ⟨fun h => (conjugate U).injective h,fun h => congrArg (conjugate U) h⟩ + rw [hh,he,conjugate_opNorm] + +lemma truncatedG_conjugate (f : 𝓢(ℝ,ℂ)) (U : unitary (Matrix ι ι ℂ)) {R : ℝ} (hR : 0 ≤ R) + (B D M : Matrix ι ι ℂ) (hB : Bᴴ=B) (hD : Dᴴ=D) : + truncatedG f R hR (conjugate U B) (conjugate U D) (conjugate U M) = + conjugate U (truncatedG f R hR B D M) := by + have hs : sandShift (conjugate U B) (conjugate U D) (matrixProject R hR (conjugate U M)) = + conjugate U (sandShift B D (matrixProject R hR M)) := by + simp only [sandShift,matrixProject_conjugate,map_sub,map_mul] + unfold truncatedG + rw [hs,schwartzMatrix_conjugate f U _ + (sandShift_hermitian _ _ _ hB hD (matrixProject_bound R hR M).1)] + simp only [map_mul] + +lemma truncatedK_conjugate (f : 𝓢(ℝ,ℂ)) (U : unitary (Matrix ι ι ℂ)) {R : ℝ} (hR : 0 ≤ R) + (B D C M : Matrix ι ι ℂ) (hB : Bᴴ=B) (hD : Dᴴ=D) : + truncatedK f R hR (conjugate U B) (conjugate U D) (conjugate U C) (conjugate U M) = + conjugate U (truncatedK f R hR B D C M) := by + simp only [truncatedK,truncatedG_conjugate f U hR B D M hB hD,matrixProject_conjugate, + map_add,map_one,map_mul,map_sub] +end SKGap.ComplexMatrix +end +end + +section +noncomputable section +namespace SKGap +open Matrix MeasureTheory ProbabilityTheory +open RealComplex ComplexMatrix +open scoped Matrix.Norms.Frobenius SchwartzMap +variable {ι : Type*} [Fintype ι] [DecidableEq ι] + +def signConjugate (s : ι → ℝ) (M : Matrix ι ι ℝ) : Matrix ι ι ℝ := + fun i k => s i*s k*M i k + +noncomputable def signUnitary (s : ι → ℝ) (hs : ∀ i, s i^2=1) : + unitary (Matrix ι ι ℂ) := + ⟨diagonal (fun i => (s i : ℂ)), by + have hh : ∀ i, (s i : ℂ)*(s i : ℂ)=1 := by + intro i + exact_mod_cast (show s i*s i=1 by nlinarith [hs i]) + change (diagonal (fun i => (s i : ℂ)))ᴴ*diagonal (fun i => (s i : ℂ))=1 ∧ + diagonal (fun i => (s i : ℂ))*(diagonal (fun i => (s i : ℂ)))ᴴ=1 + simp only [diagonal_conjTranspose,Pi.star_apply,Complex.star_def,Complex.conj_ofReal, + diagonal_mul_diagonal,hh,diagonal_one,and_self]⟩ + +lemma sign_conjugate_entry (s : ι → ℝ) (hs : ∀ i, s i^2=1) (M : Matrix ι ι ℂ) (i k : ι) : + conjugate (signUnitary s hs) M i k = (s i:ℂ)*(s k:ℂ)*M i k := by + change (diagonal (fun b => (s b:ℂ))*M*(diagonal (fun b => (s b:ℂ)))ᴴ) i k = _ + simp only [diagonal_conjTranspose,Pi.star_apply,Complex.star_def,Complex.conj_ofReal,mul_diagonal,diagonal_mul] + ring + +lemma sign_conjugate_diagonal (s : ι → ℝ) (hs : ∀ i, s i^2=1) (d : ι → ℝ) : + conjugate (signUnitary s hs) (liftMatrix (diagonal d)) = liftMatrix (diagonal d) := by + ext i k + rw [sign_conjugate_entry] + by_cases hik : i=k + · subst k + simp only [liftMatrix,Matrix.map_apply,diagonal_apply_eq] + have h : (s i:ℂ)*(s i:ℂ)=1 := by exact_mod_cast (show s i*s i=1 by nlinarith [hs i]) + rw [h,one_mul] + · simp [liftMatrix,Matrix.diagonal,hik] + +lemma sign_conjugate_lift (s : ι → ℝ) (hs : ∀ i, s i^2=1) (M : Matrix ι ι ℝ) : + conjugate (signUnitary s hs) (liftMatrix M) = liftMatrix (signConjugate s M) := by + ext i k + simp [sign_conjugate_entry,liftMatrix,signConjugate] + +lemma realPart_sign_conjugate (s : ι → ℝ) (hs : ∀ i, s i^2=1) (M : Matrix ι ι ℂ) : + RealComplex.realPart (conjugate (signUnitary s hs) M) = signConjugate s (RealComplex.realPart M) := by + ext i k + simp [RealComplex.realPart,sign_conjugate_entry,signConjugate,Complex.mul_re] + +lemma realTruncatedK_sign (f : 𝓢(ℝ,ℂ)) {R : ℝ} (hR : 0 ≤ R) + (s : ι → ℝ) (hs : ∀ i, s i^2=1) (d c : ι → ℝ) (M : Matrix ι ι ℝ) : + realTruncatedK f R hR (diagonal d) (diagonal c) (signConjugate s M) = + signConjugate s (realTruncatedK f R hR (diagonal d) (diagonal c) M) := by + unfold realTruncatedK + rw [← sign_conjugate_lift s hs M] + have hd := liftMatrix_hermitian (diagonal d) (diagonal_transpose _) + have hc := liftMatrix_hermitian (diagonal c) (diagonal_transpose _) + have hB : (1+liftMatrix (diagonal d)*liftMatrix (diagonal c)*liftMatrix (diagonal d))ᴴ = + 1+liftMatrix (diagonal d)*liftMatrix (diagonal c)*liftMatrix (diagonal d) := by + simp only [conjTranspose_add,conjTranspose_one,conjTranspose_mul,hd,hc,mul_assoc] + have he := truncatedK_conjugate f (signUnitary s hs) hR + (1+liftMatrix (diagonal d)*liftMatrix (diagonal c)*liftMatrix (diagonal d)) + (liftMatrix (diagonal d)) (liftMatrix (diagonal c)) (liftMatrix M) hB hd + simp only [map_add,map_one,map_mul,sign_conjugate_diagonal] at he + rw [he,realPart_sign_conjugate] +end SKGap +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/ConstantRecipe.lean b/lean/OAI/Probability/SKGap/Localization/ConstantRecipe.lean new file mode 100644 index 0000000000000000000000000000000000000000..622b34bfd37833551273e4a4b2cc64d07b3e18c9 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/ConstantRecipe.lean @@ -0,0 +1,215 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.SelectionPartition + +namespace OAI + +section + +noncomputable section +open scoped BigOperators +namespace SKGapCutoff.Static +universe u +variable {Ω : Type u} {n : Ω→ℕ} +lemma UniformWeak.finset_sum {τ : Type*} {P : ∀a,Observables (n a)} + {F : τ→∀a,Observables (n a)} (s : Finset τ) (h : ∀t∈s,UniformWeak P (F t)) : + UniformWeak P (fun a x=>∑t∈s,F t a x) := by + classical + induction s using Finset.induction_on with + | empty=>simpa using UniformWeak.zero P + | @insert t s ht ih=> + simpa only [Finset.sum_insert ht] using (h t (Finset.mem_insert_self ..)).add + (ih (fun r hr=>h r (Finset.mem_insert_of_mem hr))) +lemma UniformSquare.finset_sum {τ : Type*} {P : ∀a,Observables (n a)} + {F : τ→∀a,Observables (n a)} (s : Finset τ) (h : ∀t∈s,UniformSquare P (F t)) : + UniformSquare P (fun a x=>∑t∈s,F t a x) := by + classical + induction s using Finset.induction_on with + | empty=>simpa using UniformSquare.zero P + | @insert t s ht ih=> + simpa only [Finset.sum_insert ht] using (h t (Finset.mem_insert_self ..)).add + (ih (fun r hr=>h r (Finset.mem_insert_of_mem hr))) +end SKGapCutoff.Static +namespace SKGapCutoff.Recipe +open Primary Static +variable {n M : ℕ} + +def constantRecipe (j : ℝ) (J : Interaction n) (h e : Fin n→ℝ) (M : ℕ) : + OrdinaryData n (Fin M) (Fin M) Unit where + J:=J + j:=j + H:=fun q=>fld j J h q.val + predecessor:=fun q=>mag j J h q.val + θ:=fun q x=>j*(onsager j J h (q.val+1) x-onsager j J h q.val x) + seed:=fun _=>e + seedFunction:=fun _ _ _ _=>1 + seedDerivative:=fun _ _ _ _=>0 + auxFunction:=fun _ _ _ _=>0 + auxDerivative:=fun _ _ _ _=>0 + +lemma constantRecipe_source (j : ℝ) (J : Interaction n) (h e : Fin n→ℝ) (M : ℕ) : + (constantRecipe j J h e M).source 0=fun _=>e := by + rw [OrdinaryData.source_eq] + ext x i + simp [OrdinaryData.sourceOf,constantRecipe,OrdinaryData.seedCoefficient,OrdinaryData.auxCoefficient,coefficient] + +lemma constantRecipe_coefficients (j : ℝ) (J : Interaction n) (h e : Fin n→ℝ) (M N : ℕ) (x : Spin n) : + (constantRecipe j J h e M).CoefficientClass N x 1 := by + refine ⟨le_rfl,?_,?_,?_,?_⟩ + · intro a ha s; exact (segmentRegular_const _ _ x 1).mono zero_le_one + · intro a ha b; exact (segmentRegular_const _ _ x 0).mono zero_le_one + · intros; norm_num [SegmentValue,constantRecipe] + · intros; norm_num [SegmentValue,constantRecipe] + +lemma constantRecipe_admissible (j : ℝ) (J : Interaction n) (h e : Fin n→ℝ) (M N p : ℕ) : + (constantRecipe j J h e M).Admissible N p := by + intro a ha q hq + constructor <;> intro s <;> ext x i <;> + simp [OrdinaryData.seedPartial,OrdinaryData.auxPartial,localPartial,constantRecipe,partialAt] + +universe u +variable {Ω : Type u} {N : Ω→ℕ} {j R B W C : ℝ} +variable {J : ∀a,Interaction (N a)} {h e : ∀a,Fin (N a)→ℝ} + +lemma constantRecipe_family (he : ∀a,vectorNorm (e a)≤1) (M p : ℕ) : + FamilyRecipe j J h (fun a=>constantRecipe j (J a) (h a) (e a) M) 0 p 2 := by + refine ⟨fun _=>rfl,fun _=>rfl,fun _ _=>rfl,fun _ _=>rfl,fun _ _=>rfl, + ⟨1,zero_le_one,?_⟩,fun a x=>(constantRecipe_coefficients j (J a) (h a) (e a) M 0 x).mono (by norm_num), + fun a=>constantRecipe_admissible j (J a) (h a) (e a) M 0 p⟩ + intro a; simpa [constantRecipe] using he a + +lemma primary_residual_telescope (j : ℝ) (J : Interaction n) (h : Fin n→ℝ) (d : ℕ) (x : Spin n) (i : Fin n) : + (∑k∈Finset.range d,residual j J h k x i)=spin x i-mag j J h d x i := by + induction d with + | zero=>simp [mag_zero] + | succ d ih=>rw [Finset.sum_range_succ,ih];dsimp [Primary.residual];ring + +theorem gibbs_constant_residuals (d : ℕ) (hR : 0≤R) (hB : 0≤B) (hW : 0≤W) (hC : 0≤C) + (hn : ∀a,0fieldGibbs (J a) (h a)) + (fun a x=>∑i,(spin x i-mag j (J a) (h a) k x i)*e a i) ∧ + UniformSquare (fun a=>fieldGibbs (J a) (h a)) + (fun a x=>∑i,(spin x i-mag j (J a) (h a) k x i)*e a i) := by + have H (l : ℕ) (hl : l(hevent a).mono (residualCoefficientBudget_depth_mono j (by omega)) (by omega)) + (fun a=>constantRecipe j (J a) (h a) (e a) (d+1)) (constantRecipe_family he (d+1) l) + have H' (l : ℕ) (hl : lfieldGibbs (J a) (h a)) (fun a x=>∑i,residual j (J a) (h a) l x i*e a i) ∧ + UniformSquare (fun a=>fieldGibbs (J a) (h a)) (fun a x=>∑i,residual j (J a) (h a) l x i*e a i) := by + simpa only [constantRecipe_source] using H l hl + have hh (a : Ω) (x : Spin (N a)) : + (∑l∈Finset.range k,∑i,residual j (J a) (h a) l x i*e a i)= + ∑i,(spin x i-mag j (J a) (h a) k x i)*e a i := by + rw [Finset.sum_comm] + simp only [←Finset.sum_mul,primary_residual_telescope] + exact ⟨((UniformWeak.finset_sum (Finset.range k) (fun l hl=>(H' l (Finset.mem_range.mp hl)).1))).congr hh, + ((UniformSquare.finset_sum (Finset.range k) (fun l hl=>(H' l (Finset.mem_range.mp hl)).2))).congr hh⟩ + +end SKGapCutoff.Recipe + +end +end + +section + +noncomputable section +open scoped BigOperators +namespace SKGapCutoff.Static +universe u +variable {Ω : Type u} {n : Ω→ℕ} +lemma UniformMultiplier.neg {F : ∀a,Observables (n a)} (hF : UniformMultiplier F) : + UniformMultiplier (fun a x=>-F a x) := by + obtain ⟨B,L,hB,hL,hF,hd⟩:=hF + refine ⟨B,L,hB,hL,fun a x=>by simpa using hF a x,fun a x=>?_⟩ + have he (i : Fin (n a)) : halfDiff i (fun y=>-F a y) x= -halfDiff i (F a) x := by unfold halfDiff;ring + simpa only [he,neg_sq] using hd a x +lemma UniformMultiplier.mul {F G : ∀a,Observables (n a)} (hF : UniformMultiplier F) + (hG : UniformMultiplier G) : UniformMultiplier (fun a x=>F a x*G a x) := by + obtain ⟨B,L,hB,hL,hF,hdF⟩:=hF + obtain ⟨D,K,hD,hK,hG,hdG⟩:=hG + exact ⟨B*D,Real.sqrt (2*B^2*K^2+2*D^2*L^2),mul_nonneg hB hD,Real.sqrt_nonneg _, + fun a=>(scalar_product_bounds (F a) (G a) hB hL hD hK (hF a) (hdF a) (hG a) (hdG a)).1, + fun a=>(scalar_product_bounds (F a) (G a) hB hL hD hK (hF a) (hdF a) (hG a) (hdG a)).2⟩ +lemma UniformMultiplier.finset_prod {τ : Type*} {F : τ→∀a,Observables (n a)} (s : Finset τ) + (h : ∀t∈s,UniformMultiplier (F t)) : UniformMultiplier (fun a x=>∏t∈s,F t a x) := by + classical + induction s using Finset.induction_on with + | empty=>simpa using UniformMultiplier.const (n:=n) 1 + | @insert t s ht ih=> + simpa only [Finset.prod_insert ht] using (h t (Finset.mem_insert_self ..)).mul + (ih (fun r hr=>h r (Finset.mem_insert_of_mem hr))) +end SKGapCutoff.Static +namespace SKGapCutoff.Recipe +open Primary Static +variable {n : ℕ} + +def residualDerivativeBudget (j R B : ℝ) (k : ℕ) : ℝ := + differentiationBound j R B k+differentiationBound j R B (k+1) + +lemma residualDerivativeBudget_nonneg {j R B : ℝ} (hR : 0≤R) (hB : 0≤B) (k : ℕ) : + 0≤residualDerivativeBudget j R B k := + add_nonneg (differentiationBound_nonneg hR hB k) (differentiationBound_nonneg hR hB (k+1)) + +lemma residual_derivative_bound (hn : 0hformal x t (ht.trans hl))).2.2.1 + rw [show derivativeMatrix (residual j J h k) x= + derivativeMatrix (mag j J h k) x-derivativeMatrix (mag j J h (k+1)) x from derivativeMatrix_sub _ _ x] + simp only [opNorm_eq,map_sub] + exact (norm_sub_le _ _).trans (add_le_add (hm _ (by omega)) (hm _ le_rfl)) + +universe u +variable {Ω : Type u} {N : Ω→ℕ} {j R B ρ : ℝ} {M : ℕ} +variable {J : ∀a,Interaction (N a)} {h : ∀a,Fin (N a)→ℝ} + +lemma residualCutoff_uniform (hρ : 0<ρ) (hR : 0≤R) (hB : 0≤B) + (hn : ∀a,0residualCutoff ρ j (J a) (h a) k) := by + obtain ⟨K,hK⟩:=residualScalarCutoff_lipschitz + let A:=residualDerivativeBudget j R B k + let D:=residualDerivativeBudget j R B (k+1) + have hA : 0≤A:=residualDerivativeBudget_nonneg hR hB k + have hD : 0≤D:=residualDerivativeBudget_nonneg hR hB (k+1) + let L:=2*(K:ℝ)/ρ^2*((4*A+2*A^2)+(4*D+2*D^2)) + have hL : 0≤L:=by dsimp [L];positivity + refine ⟨1,L,zero_le_one,hL,fun a x=>?_,fun a x=>?_⟩ + · rw [abs_of_nonneg (residualCutoff_bounds ρ j (J a) (h a) k x).1] + exact (residualCutoff_bounds ρ j (J a) (h a) k x).2 + · have H:=residualCutoff_gradient (hn a) hρ hK (J a) (h a) k x hA hD + (residual_derivative_bound (hn a) hR hB (J a) (h a) (hop a) k (fun x l hl=>hformal a x l (by omega)) x) + (residual_derivative_bound (hn a) hR hB (J a) (h a) (hop a) (k+1) (fun x l hl=>hformal a x l (by omega)) x) + have hone : 1≤Real.sqrt (N a:ℝ) := Real.one_le_sqrt.mpr (by exact_mod_cast hn a) + have hd : ‖derivativeVector (residualCutoff ρ j (J a) (h a) k) x‖≤L := + H.trans (div_le_self hL hone) + simpa only [norm_derivativeVector_sq] using pow_le_pow_left₀ (norm_nonneg _) hd 2 + +lemma cutoffWeight_uniform {C : ℕ→∀a,Observables (N a)} (k : ℕ) + (hC : ∀l≤k,UniformMultiplier (C l)) : + UniformMultiplier (fun a x=>cutoffWeight (fun l=>C l a x) k) := by + exact (hC k le_rfl).mul (UniformMultiplier.finset_prod (Finset.range k) + (fun l hl=>(UniformMultiplier.const 1).add (hC l (Finset.mem_range.mp hl).le).neg)) + +lemma residualWeight_uniform (hρ : 0<ρ) (hR : 0≤R) (hB : 0≤B) + (hn : ∀a,0cutoffWeight (fun l=>residualCutoff ρ j (J a) (h a) l x) k) := by + apply cutoffWeight_uniform + intro l hl + exact residualCutoff_uniform hρ hR hB hn hop hformal l (by omega) + +end SKGapCutoff.Recipe + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/CoordinateDeriv.lean b/lean/OAI/Probability/SKGap/Localization/CoordinateDeriv.lean new file mode 100644 index 0000000000000000000000000000000000000000..225e809581acb0c051b18dcc0db7575975bbc056 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/CoordinateDeriv.lean @@ -0,0 +1,168 @@ +import Mathlib +import OAI.Probability.SKGap.Gaussian.StandardGaussianProduct + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory InformationTheory Real Set +open scoped NNReal ENNReal +open Filter +open scoped Topology +namespace SKGap + +def coordinateDeriv {n : ℕ} (i : Fin (n+1)) (f : (Fin (n+1) → ℝ) → ℝ) + (x : Fin (n+1) → ℝ) : ℝ := + deriv (fun z => f (i.insertNth z (i.removeNth x))) (x i) + +lemma lipschitz_insertNth {n : ℕ} (i : Fin (n+1)) (u : Fin n → ℝ) : + LipschitzWith 1 (fun z : ℝ => i.insertNth (α := fun _ => ℝ) z u) := by + apply LipschitzWith.of_dist_le_mul + intro x y + simp only [NNReal.coe_one,one_mul] + apply (dist_pi_le_iff dist_nonneg).2 + refine i.forall_iff_succAbove.mpr ⟨?_,?_⟩ + · simp only [Fin.insertNth_apply_same,le_refl] + · intro k + simp only [Fin.insertNth_apply_succAbove,dist_self] + exact dist_nonneg + +lemma continuous_insertNth_uncurry {n : ℕ} (i : Fin (n+1)) : + Continuous (fun p : (Fin n → ℝ) × ℝ => i.insertNth (α := fun _ => ℝ) p.2 p.1) := by + apply continuous_pi + refine i.forall_iff_succAbove.mpr ⟨?_,?_⟩ + · simpa only [Fin.insertNth_apply_same] using (continuous_snd : Continuous (fun p : (Fin n → ℝ) × ℝ => p.2)) + · intro k + simpa only [Fin.insertNth_apply_succAbove,Function.comp_def] using (continuous_apply k).comp continuous_fst + +lemma measurable_coordinateDeriv {n : ℕ} (i : Fin (n+1)) {f : (Fin (n+1) → ℝ) → ℝ} + (hf : Continuous f) : Measurable (coordinateDeriv i f) := by + have h := measurable_deriv_with_param (f := fun u z => f (i.insertNth z u)) + (hf.comp (continuous_insertNth_uncurry i)) + have hc : Continuous (fun x : Fin (n+1) → ℝ => (i.removeNth x,x i)) := by + apply Continuous.prodMk + · apply continuous_pi + intro k + exact continuous_apply (i.succAbove k) + · exact continuous_apply i + exact h.comp hc.measurable + +lemma norm_coordinateDeriv_le {n : ℕ} (i : Fin (n+1)) {f : (Fin (n+1) → ℝ) → ℝ} + {L : ℝ≥0} (hf : LipschitzWith L f) (x : Fin (n+1) → ℝ) : + ‖coordinateDeriv i f x‖ ≤ L := by + have hl := hf.comp (lipschitz_insertNth i (i.removeNth x)) + simpa only [mul_one,coordinateDeriv,Function.comp_def] using norm_deriv_le_of_lipschitz hl (x₀ := x i) + +theorem gaussianProduct_lipschitz_IBP {n : ℕ} (i : Fin (n+1)) + {f : (Fin (n+1) → ℝ) → ℝ} {L : ℝ≥0} {C : ℝ} + (hf : LipschitzWith L f) (hC : ∀ x, ‖f x‖ ≤ C) : + (∫ x, x i * f x ∂standardGaussianProduct (n+1)) = + ∫ x, coordinateDeriv i f x ∂standardGaussianProduct (n+1) := by + let e := MeasurableEquiv.piFinSuccAbove (fun _ : Fin (n+1) => ℝ) i + have hp : MeasurePreserving e.symm + ((gaussianReal 0 1).prod (standardGaussianProduct n)) + (standardGaussianProduct (n+1)) := + (measurePreserving_piFinSuccAbove (fun _ => gaussianReal 0 1) i).symm + have hi : Integrable (fun x : Fin (n+1) → ℝ => x i * f x) + (standardGaussianProduct (n+1)) := by + simpa only [mul_comm,standardGaussianProduct] using + (integrable_eval (i := i) IsGaussian.integrable_id).bdd_mul + hf.continuous.aestronglyMeasurable (ae_of_all _ hC) + have hi' : Integrable (coordinateDeriv i f) (standardGaussianProduct (n+1)) := + Integrable.of_bound (measurable_coordinateDeriv i hf.continuous).aestronglyMeasurable (L:ℝ) + (ae_of_all _ (norm_coordinateDeriv_le i hf)) + have hsplit (g : (Fin (n+1) → ℝ) → ℝ) (hg : Integrable g (standardGaussianProduct (n+1))) : + (∫ x, g x ∂standardGaussianProduct (n+1)) = + ∫ u, ∫ z, g (i.insertNth (α := fun _ => ℝ) z u) ∂gaussianReal 0 1 ∂standardGaussianProduct n := by + have hi2 : Integrable (fun x => g (e.symm x)) + ((gaussianReal 0 1).prod (standardGaussianProduct n)) := hp.integrable_comp_of_integrable hg + rw [← hp.integral_comp' g,integral_prod _ hi2,integral_integral_swap hi2] + rfl + rw [hsplit _ hi,hsplit _ hi'] + apply integral_congr_ae + filter_upwards [] with u + simp only [coordinateDeriv,Fin.insertNth_apply_same,Fin.removeNth_insertNth] + simpa only [sub_zero,NNReal.coe_one,one_mul,Function.comp_def] using + gaussian_lipschitz_IBP (d := 0) (s := 1) (by norm_num) + (hf.comp (lipschitz_insertNth i u)) (fun z => hC (i.insertNth (α := fun _ => ℝ) z u)) + +variable {κ : Type*} [Fintype κ] [DecidableEq κ] + +def finiteCoordinateDeriv (i : κ) (f : (κ → ℝ) → ℝ) (x : κ → ℝ) : ℝ := + deriv (fun z => f (Function.update x i z)) (x i) + +lemma lipschitz_coordinate_update (i : κ) (x : κ → ℝ) : + LipschitzWith 1 (fun z : ℝ => Function.update x i z) := by + apply LipschitzWith.of_dist_le_mul + intro z w + simp only [NNReal.coe_one,one_mul] + apply (dist_pi_le_iff dist_nonneg).2 + intro k + by_cases h : k = i + · subst k; simp + · simp only [Function.update_of_ne h,dist_self]; exact dist_nonneg + +lemma measurable_finiteCoordinateDeriv (i : κ) {f : (κ → ℝ) → ℝ} + (hf : Continuous f) : Measurable (finiteCoordinateDeriv i f) := by + have h := measurable_deriv_with_param (f := fun x z => f (Function.update x i z)) + (hf.comp (continuous_update i)) + exact h.comp ((continuous_id.prodMk (continuous_apply i)).measurable) + +lemma norm_finiteCoordinateDeriv_le (i : κ) {f : (κ → ℝ) → ℝ} + {L : ℝ≥0} (hf : LipschitzWith L f) (x : κ → ℝ) : + ‖finiteCoordinateDeriv i f x‖ ≤ L := by + simpa only [finiteCoordinateDeriv,Function.comp_def,mul_one] using + norm_deriv_le_of_lipschitz (hf.comp (lipschitz_coordinate_update i x)) (x₀ := x i) + +lemma gaussianFinite_lipschitz_IBP_equiv {n : ℕ} (e : Fin (n+1) ≃ κ) (i : κ) + {f : (κ → ℝ) → ℝ} {L : ℝ≥0} {C : ℝ} + (hf : LipschitzWith L f) (hC : ∀ x, ‖f x‖ ≤ C) : + (∫ x, x i*f x ∂Measure.pi (fun _ : κ => gaussianReal 0 1)) = + ∫ x, finiteCoordinateDeriv i f x ∂Measure.pi (fun _ : κ => gaussianReal 0 1) := by + let E := MeasurableEquiv.piCongrLeft (fun _ : κ => ℝ) e + have he (x : Fin (n+1) → ℝ) (k : κ) : E x k = x (e.symm k) := by + simp [E,MeasurableEquiv.coe_piCongrLeft,Equiv.piCongrLeft_apply] + have hl : LipschitzWith 1 E := by + apply LipschitzWith.of_dist_le_mul + intro x y + simp only [NNReal.coe_one,one_mul] + apply (dist_pi_le_iff dist_nonneg).2 + intro k + simpa only [he] using dist_le_pi_dist x y (e.symm k) + have hp := measurePreserving_piCongrLeft (fun _ : κ => gaussianReal 0 1) e + have hh := gaussianProduct_lipschitz_IBP (e.symm i) + (by simpa only [mul_one,Function.comp_def] using hf.comp hl) (fun x => hC (E x)) + have hu (x : Fin (n+1) → ℝ) (z : ℝ) : + E ((e.symm i).insertNth z ((e.symm i).removeNth x)) = + Function.update (E x) i z := by + rw [Fin.insertNth_removeNth] + ext k + simp only [he] + by_cases h : k = i + · subst k; simp + · simp [he,Function.update_of_ne h,show e.symm k ≠ e.symm i from fun h' => h (e.symm.injective h')] + have hd (x : Fin (n+1) → ℝ) : + coordinateDeriv (e.symm i) (f ∘ E) x = finiteCoordinateDeriv i f (E x) := by + simp only [coordinateDeriv,finiteCoordinateDeriv,Function.comp_def,hu,he] + rw [← hp.integral_comp' (fun x => x i*f x), + ← hp.integral_comp' (finiteCoordinateDeriv i f)] + change (∫ x, E x i*f (E x) ∂standardGaussianProduct (n+1)) = + ∫ x, finiteCoordinateDeriv i f (E x) ∂standardGaussianProduct (n+1) + simpa only [← hd,he,Function.comp_def] using hh + +theorem gaussianFinite_lipschitz_IBP (i : κ) + {f : (κ → ℝ) → ℝ} {L : ℝ≥0} {C : ℝ} + (hf : LipschitzWith L f) (hC : ∀ x, ‖f x‖ ≤ C) : + (∫ x, x i*f x ∂Measure.pi (fun _ : κ => gaussianReal 0 1)) = + ∫ x, finiteCoordinateDeriv i f x ∂Measure.pi (fun _ : κ => gaussianReal 0 1) := by + have hn : Fintype.card κ ≠ 0 := by + let : Nonempty κ := ⟨i⟩ + exact Fintype.card_ne_zero + obtain ⟨n,hn⟩ := Nat.exists_eq_succ_of_ne_zero hn + let e : κ ≃ Fin (n+1) := (Fintype.equivFin κ).trans (Equiv.cast (congrArg Fin hn)) + exact gaussianFinite_lipschitz_IBP_equiv e.symm i hf hC + +end SKGap + +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/CoordinateLipschitz.lean b/lean/OAI/Probability/SKGap/Localization/CoordinateLipschitz.lean new file mode 100644 index 0000000000000000000000000000000000000000..cf5abbbc4497d35d69a5b44d45f6ad964765f6ec --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/CoordinateLipschitz.lean @@ -0,0 +1,466 @@ +import Mathlib +import OAI.Probability.SKGap.Terminal.FiniteSpinCalculus +import OAI.Probability.SKGap.Brownian.ContinuousEnergy +import OAI.Probability.SKGap.Localization.UpperCoefficient + +namespace OAI + +section +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal +namespace SKGapCutoff + +def CoordinateLipschitz {ι : Type*} [Fintype ι] (f : (ι → ℝ) → ℝ) : Prop := + ∀ x y, |f x - f y| ≤ ∑ i, |x i - y i| + +lemma CoordinateLipschitz.lipschitz {ι : Type*} [Fintype ι] + {f : (ι → ℝ) → ℝ} (hf : CoordinateLipschitz f) : + LipschitzWith (Fintype.card ι) f := by + apply LipschitzWith.of_dist_le_mul + intro x y + calc + dist (f x) (f y) = |f x - f y| := Real.dist_eq _ _ + _ ≤ ∑ i, |x i - y i| := hf x y + _ ≤ ∑ _ : ι, dist x y := Finset.sum_le_sum fun i _ => by + simpa only [Real.dist_eq] using dist_le_pi_dist x y i + _ = _ := by simp + +lemma memLp_gaussian_pi_id {ι : Type*} [Fintype ι] (v : ℝ≥0) : + MemLp (id : (ι → ℝ) → (ι → ℝ)) 2 (Measure.pi (fun _ => gaussianReal 0 v)) := by + apply memLp_pi_iff.2 + intro i + exact (memLp_id_gaussianReal (μ := 0) (v := v) 2).comp_measurePreserving + (measurePreserving_eval _ i) + +lemma memLp_gaussian_pi_of_lipschitz {ι : Type*} [Fintype ι] + {f : (ι → ℝ) → ℝ} {K : ℝ≥0} (hf : LipschitzWith K f) (v : ℝ≥0) : + MemLp f 2 (Measure.pi (fun _ => gaussianReal 0 v)) := by + have hsub : LipschitzWith K (fun x => f x - f 0) := by + apply LipschitzWith.of_dist_le_mul + intro x y + simpa only [dist_sub_right] using hf.dist_le_mul x y + have h := hsub.comp_memLp (by simp) (memLp_gaussian_pi_id (ι := ι) v) + convert h.add (memLp_const (f 0)) using 1 + · ext x; simp + +lemma memLp_gaussian_real_of_lipschitz {f : ℝ → ℝ} {K : ℝ≥0} + (hf : LipschitzWith K f) (v : ℝ≥0) : MemLp f 2 (gaussianReal 0 v) := by + have hsub : LipschitzWith K (fun x => f x - f 0) := by + apply LipschitzWith.of_dist_le_mul + intro x y + simpa only [dist_sub_right] using hf.dist_le_mul x y + have h := hsub.comp_memLp (by simp) + (memLp_id_gaussianReal (μ := 0) (v := v) 2) + convert h.add (memLp_const (f 0)) using 1 <;> try norm_num + ext x + simp + +lemma gaussian_lipschitz_variance {f : ℝ → ℝ} (hf : LipschitzWith 1 f) (v : ℝ≥0) : + variance f (gaussianReal 0 v) ≤ v := by + have hm := memLp_gaussian_real_of_lipschitz hf v + have hs : MemLp (fun z => f z - f 0) 2 (gaussianReal 0 v) := hm.sub (memLp_const (f 0)) + have hv : variance f (gaussianReal 0 v) = + (∫ z, (f z - f 0)^2 ∂gaussianReal 0 v) - + (∫ z, f z - f 0 ∂gaussianReal 0 v)^2 := by + rw [← variance_sub_const hm.aestronglyMeasurable (f 0)] + simpa only [Pi.pow_apply] using variance_eq_sub hs + rw [hv] + have hi : (∫ z, (f z - f 0)^2 ∂gaussianReal 0 v) ≤ + ∫ z, z^2 ∂gaussianReal 0 v := by + apply integral_mono hs.integrable_sq + (memLp_id_gaussianReal (μ := 0) (v := v) 2).integrable_sq + intro z + have h := hf.dist_le_mul z 0 + simp only [Real.dist_eq, NNReal.coe_one, one_mul, sub_zero] at h + exact sq_le_sq.mpr h + have hid : (∫ z : ℝ, z^2 ∂gaussianReal 0 v) = v := by + have hh := variance_eq_sub (memLp_id_gaussianReal (μ := 0) (v := v) 2) + simpa only [variance_id_gaussianReal, integral_id_gaussianReal, zero_pow (by decide : (2 : ℕ) ≠ 0), sub_zero, + id_eq, Pi.pow_apply] using hh.symm + rw [hid] at hi + linarith [sq_nonneg (∫ z, f z - f 0 ∂gaussianReal 0 v)] + +lemma coordinateLipschitz_cons_real {n : ℕ} {f : (Fin (n+1) → ℝ) → ℝ} + (hf : CoordinateLipschitz f) (x : Fin n → ℝ) : + LipschitzWith 1 (fun z => f (Fin.cons z x)) := by + apply LipschitzWith.of_dist_le_mul + intro z w + simpa [Real.dist_eq, Fin.sum_univ_succ] using hf (Fin.cons z x) (Fin.cons w x) + +lemma coordinateLipschitz_integral_cons {n : ℕ} {f : (Fin (n+1) → ℝ) → ℝ} + (hf : CoordinateLipschitz f) (v : ℝ≥0) : + CoordinateLipschitz (fun x : Fin n → ℝ => + ∫ z, f (Fin.cons z x) ∂gaussianReal 0 v) := by + intro x y + rw [← integral_sub + ((memLp_gaussian_real_of_lipschitz (coordinateLipschitz_cons_real hf x) v).integrable one_le_two) + ((memLp_gaussian_real_of_lipschitz (coordinateLipschitz_cons_real hf y) v).integrable one_le_two)] + calc + _ ≤ ∫ z, |f (Fin.cons z x) - f (Fin.cons z y)| ∂gaussianReal 0 v := + abs_integral_le_integral_abs + _ ≤ ∫ _ : ℝ, (∑ i, |x i - y i|) ∂gaussianReal 0 v := by + apply integral_mono + (((memLp_gaussian_real_of_lipschitz (coordinateLipschitz_cons_real hf x) v).integrable one_le_two).sub + ((memLp_gaussian_real_of_lipschitz (coordinateLipschitz_cons_real hf y) v).integrable one_le_two)).abs + (integrable_const _) + intro z + simpa [Fin.sum_univ_succ] using hf (Fin.cons z x) (Fin.cons z y) + _ = _ := by simp + +lemma integral_gaussian_fin_succ {n : ℕ} (v : ℝ≥0) + (f : (Fin (n+1) → ℝ) → ℝ) + (hf : Integrable f (Measure.pi (fun _ => gaussianReal 0 v))) : + (∫ x, f x ∂Measure.pi (fun _ => gaussianReal 0 v)) = + ∫ x : Fin n → ℝ, ∫ z : ℝ, f (Fin.cons z x) ∂gaussianReal 0 v + ∂Measure.pi (fun _ => gaussianReal 0 v) := by + let e := (MeasurableEquiv.piFinSuccAbove (fun _ : Fin (n+1) => ℝ) 0).symm + have hm := (measurePreserving_piFinSuccAbove (fun _ : Fin (n+1) => gaussianReal 0 v) 0).symm + have he (p : ℝ × (Fin n → ℝ)) : e p = Fin.cons p.1 p.2 := by + simp [e, MeasurableEquiv.piFinSuccAbove_symm_apply, Fin.insertNthEquiv] + rw [← hm.integral_comp'] + change (∫ p : ℝ × (Fin n → ℝ), f (e p) ∂(gaussianReal 0 v).prod + (Measure.pi (fun _ => gaussianReal 0 v))) = _ + simp_rw [he] + apply integral_prod_symm + have hi := (hm.integrable_comp hf.aestronglyMeasurable).mpr hf + change Integrable (fun p : ℝ × (Fin n → ℝ) => f (e p)) _ at hi + simpa only [he] using hi + +lemma gaussian_coordinate_variance_fin (v : ℝ≥0) (n : ℕ) + {f : (Fin n → ℝ) → ℝ} (hf : CoordinateLipschitz f) : + variance f (Measure.pi (fun _ => gaussianReal 0 v)) ≤ (n : ℝ) * v := by + induction n with + | zero => + have he : f = fun _ => f 0 := funext fun x => congrArg f (Subsingleton.elim x 0) + rw [he, variance_eq_sub (memLp_const _)] + simp + | succ n ih => + let g : (Fin n → ℝ) → ℝ := fun x => ∫ z, f (Fin.cons z x) ∂gaussianReal 0 v + have hg := coordinateLipschitz_integral_cons hf v + have hfm := memLp_gaussian_pi_of_lipschitz hf.lipschitz v + have hgm := memLp_gaussian_pi_of_lipschitz hg.lipschitz v + change MemLp g 2 _ at hgm + have hpoint (x : Fin n → ℝ) : + (∫ z, f (Fin.cons z x)^2 ∂gaussianReal 0 v) ≤ v + g x ^ 2 := by + have hv := gaussian_lipschitz_variance (coordinateLipschitz_cons_real hf x) v + rw [variance_eq_sub (memLp_gaussian_real_of_lipschitz + (coordinateLipschitz_cons_real hf x) v)] at hv + change (∫ z, f (Fin.cons z x)^2 ∂gaussianReal 0 v) - g x ^ 2 ≤ v at hv + linarith + have hsq := integral_mono_of_nonneg + (Filter.Eventually.of_forall (fun x => integral_nonneg (fun z => sq_nonneg _))) + ((integrable_const (v : ℝ)).add hgm.integrable_sq) (Filter.Eventually.of_forall hpoint) + simp only [Pi.add_apply] at hsq + rw [integral_add (f := fun _ => (v : ℝ)) (g := fun x => g x ^ 2) + (integrable_const _) hgm.integrable_sq, integral_const] at hsq + simp only [measureReal_def, measure_univ, ENNReal.toReal_one, one_smul] at hsq + rw [← integral_gaussian_fin_succ v (fun x => f x^2) hfm.integrable_sq] at hsq + have hih := ih hg + rw [variance_eq_sub hgm] at hih + rw [variance_eq_sub hfm, integral_gaussian_fin_succ v f (hfm.integrable one_le_two)] + change (∫ x, f x^2 ∂Measure.pi (fun _ => gaussianReal 0 v)) - + (∫ x, g x ∂Measure.pi (fun _ => gaussianReal 0 v))^2 ≤ ((n+1 : ℕ) : ℝ) * v + push_cast + change (∫ x, g x^2 ∂Measure.pi (fun _ => gaussianReal 0 v)) - + (∫ x, g x ∂Measure.pi (fun _ => gaussianReal 0 v))^2 ≤ (n : ℝ)*v at hih + linarith + +lemma gaussian_coordinate_variance {ι : Type*} [Fintype ι] (v : ℝ≥0) + {f : (ι → ℝ) → ℝ} (hf : CoordinateLipschitz f) : + variance f (Measure.pi (fun _ => gaussianReal 0 v)) ≤ (Fintype.card ι : ℝ) * v := by + let e : Fin (Fintype.card ι) ≃ ι := (Fintype.equivFin ι).symm + let T := MeasurableEquiv.piCongrLeft (fun _ : ι => ℝ) e + have hm := measurePreserving_piCongrLeft (fun _ : ι => gaussianReal 0 v) e + have hg : CoordinateLipschitz (fun x => f (T x)) := by + intro x y + calc + _ ≤ ∑ i : ι, |T x i - T y i| := hf _ _ + _ = ∑ i : Fin (Fintype.card ι), |x i - y i| := by + rw [← e.sum_comp] + simp [T, MeasurableEquiv.piCongrLeft_apply_apply] + rw [← hm.variance_fun_comp hf.lipschitz.continuous.measurable.aemeasurable] + exact gaussian_coordinate_variance_fin v _ hg + +lemma abs_upperCoefficient_le_one {n : ℕ} (x : Spin n) (p : Fin n × Fin n) : + |upperCoefficient x p| ≤ 1 := by + unfold upperCoefficient + split_ifs + · rw [abs_mul]; cases h₁ : x p.1 <;> cases h₂ : x p.2 <;> simp [spin, h₁, h₂] + · simp + +lemma energy_sampled_diff_le {n : ℕ} (x : Spin n) (g h : GaussianCoordinates n) : + |energy (sampledInteraction g) x - energy (sampledInteraction h) x| ≤ + ∑ p, |g p - h p| := by + simp only [energy_sampled, ← Finset.sum_sub_distrib, ← mul_sub] + calc + _ ≤ ∑ p, |upperCoefficient x p * (g p - h p)| := Finset.abs_sum_le_sum_abs _ _ + _ ≤ _ := Finset.sum_le_sum fun p _ => by + rw [abs_mul] + exact mul_le_of_le_one_left (abs_nonneg _) (abs_upperCoefficient_le_one x p) + +lemma log_partition_sampled_le {n : ℕ} (g h : GaussianCoordinates n) : + Real.log (partition (sampledInteraction g)) ≤ + (∑ p, |g p - h p|) + Real.log (partition (sampledInteraction h)) := by + have hp : partition (sampledInteraction g) ≤ + Real.exp (∑ p, |g p - h p|) * partition (sampledInteraction h) := by + unfold partition + rw [Finset.mul_sum] + apply Finset.sum_le_sum + intro x _ + rw [← Real.exp_add] + apply Real.exp_le_exp.mpr + have hh := (le_abs_self _).trans (energy_sampled_diff_le x g h) + linarith + have hh := Real.log_le_log (partition_pos _) hp + rw [Real.log_mul (ne_of_gt (Real.exp_pos _)) (ne_of_gt (partition_pos _)), + Real.log_exp] at hh + exact hh + +lemma coordinateLipschitz_log_partition (n : ℕ) : + CoordinateLipschitz (fun g : GaussianCoordinates n => + Real.log (partition (sampledInteraction g))) := by + intro g h + apply abs_le.mpr + have hg := log_partition_sampled_le g h + have hh := log_partition_sampled_le h g + simp_rw [abs_sub_comm (h _) (g _)] at hh + constructor <;> linarith + +lemma memLp_log_partition (β : ℝ) (n : ℕ) : + MemLp (fun g => Real.log (partition (sampledInteraction g))) 2 (disorderLaw β n) := + memLp_gaussian_pi_of_lipschitz (coordinateLipschitz_log_partition n).lipschitz _ + +lemma variance_log_partition_le (β : ℝ) {n : ℕ} (hn : 0 < n) : + variance (fun g => Real.log (partition (sampledInteraction g))) (disorderLaw β n) ≤ + β ^ 2 * n := by + have h := gaussian_coordinate_variance (Real.toNNReal (β ^ 2 / n)) + (coordinateLipschitz_log_partition n) + simp only [Fintype.card_prod, Fintype.card_fin, Nat.cast_mul, + Real.coe_toNNReal _ (div_nonneg (sq_nonneg _) (Nat.cast_nonneg _))] at h + have hn0 : (n : ℝ) ≠ 0 := by exact_mod_cast ne_of_gt hn + have he : (n : ℝ) * n * (β ^ 2 / n) = β ^ 2 * n := by field_simp + rw [he] at h + exact h + +lemma integral_sq_cauchy {Ω : Type*} [MeasurableSpace Ω] (μ : Measure Ω) + [IsFiniteMeasure μ] {f : Ω → ℝ} (hf : Integrable f μ) + (hf2 : Integrable (fun x => f x ^ 2) μ) : + (∫ x, f x ∂μ) ^ 2 ≤ μ.real Set.univ * ∫ x, f x ^ 2 ∂μ := by + by_cases hμ : μ = 0 + · simp [hμ] + have hM : 0 < μ.real Set.univ := by + rw [measureReal_def, ENNReal.toReal_pos_iff] + exact ⟨pos_iff_ne_zero.mpr (Measure.measure_univ_ne_zero.mpr hμ), measure_lt_top _ _⟩ + let M := μ.real Set.univ + let I := ∫ x, f x ∂μ + have hp (x : Ω) : (M * f x - I) ^ 2 = + M ^ 2 * f x ^ 2 - (2 * M * I) * f x + I ^ 2 := by ring + have h := integral_nonneg (μ := μ) (f := fun x => (M * f x - I) ^ 2) + (fun x => sq_nonneg _) + simp_rw [hp] at h + rw [integral_add (f := fun x => M ^ 2 * f x ^ 2 - (2 * M * I) * f x) + (g := fun _ => I ^ 2) ((hf2.const_mul _).sub (hf.const_mul _)) (integrable_const _), + integral_sub (f := fun x => M ^ 2 * f x ^ 2) (g := fun x => (2 * M * I) * f x) + (hf2.const_mul _) (hf.const_mul _), integral_const_mul, + integral_const_mul, integral_const] at h + simp only [smul_eq_mul] at h + change 0 ≤ M ^ 2 * (∫ x, f x ^ 2 ∂μ) - 2 * M * I * I + M * I ^ 2 at h + change I ^ 2 ≤ M * ∫ x, f x ^ 2 ∂μ + have h' : 0 ≤ M * (M * (∫ x, f x ^ 2 ∂μ) - I ^ 2) := by nlinarith + exact sub_nonneg.mp ((mul_nonneg_iff_of_pos_left hM).mp h') + +lemma second_moment_lower_probability {Ω : Type*} [MeasurableSpace Ω] + (μ : Measure Ω) [IsProbabilityMeasure μ] {f : Ω → ℝ} + (hf : Integrable f μ) (hf2 : Integrable (fun x => f x ^ 2) μ) + (hm : Measurable f) (hfp : ∀ x, 0 ≤ f x) {a : ℝ} + (ha : 0 ≤ a) (ham : a ≤ ∫ x, f x ∂μ) : + ((∫ x, f x ∂μ) - a) ^ 2 ≤ μ.real {x | a ≤ f x} * ∫ x, f x ^ 2 ∂μ := by + let A := {x | a ≤ f x} + have hA : MeasurableSet A := measurableSet_le measurable_const hm + have hIc : (∫ x in Aᶜ, f x ∂μ) ≤ a := by + calc + _ ≤ ∫ _ in Aᶜ, a ∂μ := by + apply setIntegral_mono_on hf.integrableOn (integrable_const _).integrableOn hA.compl + intro x hx + exact le_of_lt (lt_of_not_ge hx) + _ = μ.real Aᶜ * a := by rw [setIntegral_const]; rfl + _ ≤ a := by + simpa only [one_mul] using mul_le_mul_of_nonneg_right + (measureReal_le_one (μ := μ) (s := Aᶜ)) ha + have hdecomp := integral_add_compl hA hf + have hI : (∫ x, f x ∂μ) - a ≤ ∫ x in A, f x ∂μ := by linarith + have hI0 : 0 ≤ ∫ x in A, f x ∂μ := integral_nonneg hfp + have hsq := integral_sq_cauchy (μ.restrict A) hf.integrableOn hf2.integrableOn + simp only [measureReal_restrict_apply_univ] at hsq + have hQ : (∫ x in A, f x ^ 2 ∂μ) ≤ ∫ x, f x ^ 2 ∂μ := + setIntegral_le_integral hf2 (Filter.Eventually.of_forall (fun x => sq_nonneg (f x))) + have hQ' := mul_le_mul_of_nonneg_left hQ (measureReal_nonneg (μ := μ) (s := A)) + have hab : 0 ≤ (∫ x, f x ∂μ) - a := sub_nonneg.mpr ham + nlinarith + +open ProbabilityTheory +lemma partition_half_mean_probability (β : ℝ) (hβ : β ^ 2 < 1) + {n : ℕ} (hn : 0 < n) : + Real.sqrt (1 - β ^ 2) / 4 ≤ (disorderLaw β n).real + {g | (∫ h, partition (sampledInteraction h) ∂disorderLaw β n) / 2 ≤ + partition (sampledInteraction g)} := by + let : IsProbabilityMeasure (disorderLaw β n) := by unfold disorderLaw; infer_instance + let m := ∫ g, partition (sampledInteraction g) ∂disorderLaw β n + let q := ∫ g, partition (sampledInteraction g) ^ 2 ∂disorderLaw β n + let p := (disorderLaw β n).real {g | m / 2 ≤ partition (sampledInteraction g)} + have hm : 0 < m := by + dsimp [m] + rw [integral_partition_sampled β hn] + positivity + have hs : 0 < Real.sqrt (1 - β ^ 2) := Real.sqrt_pos.2 (by linarith) + have hz := second_moment_lower_probability (disorderLaw β n) + (integrable_partition_sampled β n) (integrable_partition_sq_sampled β n) + (((continuous_partition n).comp (continuous_sampledInteraction n)).measurable) + (fun g => le_of_lt (partition_pos _)) (a := m / 2) (by positivity) (by dsimp [m]; linarith) + change (m - m / 2) ^ 2 ≤ p * q at hz + have hu := partition_second_moment_bound β hβ hn + change q / m ^ 2 ≤ (Real.sqrt (1 - β ^ 2))⁻¹ at hu + have hu' : q * Real.sqrt (1 - β ^ 2) ≤ m ^ 2 := by + rw [div_le_iff₀ (sq_pos_of_pos hm)] at hu + have := mul_le_mul_of_nonneg_left hu (le_of_lt hs) + field_simp at this + nlinarith + have hp : 0 ≤ p := measureReal_nonneg + have hh := mul_le_mul_of_nonneg_right hz (le_of_lt hs) + have hh' := mul_le_mul_of_nonneg_left hu' hp + change Real.sqrt (1 - β ^ 2) / 4 ≤ p + nlinarith [sq_pos_of_pos hm] + +lemma mean_ge_of_upper_event {Ω : Type*} [MeasurableSpace Ω] (μ : Measure Ω) + [IsProbabilityMeasure μ] {f : Ω → ℝ} (hf : MemLp f 2 μ) + {a p : ℝ} (hp : 0 < p) (hprob : p ≤ μ.real {x | a ≤ f x}) : + a - Real.sqrt (variance f μ / p) ≤ ∫ x, f x ∂μ := by + by_cases ha : a ≤ ∫ x, f x ∂μ + · linarith [Real.sqrt_nonneg (variance f μ / p)] + have hc : 0 < a - ∫ x, f x ∂μ := sub_pos.mpr (lt_of_not_ge ha) + have hsub : {x | a ≤ f x} ⊆ + {x | a - (∫ x, f x ∂μ) ≤ |f x - (∫ x, f x ∂μ)|} := by + intro x hx + change a ≤ f x at hx + exact (sub_le_sub_right hx _).trans (le_abs_self _) + have hm := meas_ge_le_variance_div_sq hf hc + have hr := ENNReal.toReal_mono ENNReal.ofReal_ne_top hm + rw [ENNReal.toReal_ofReal (div_nonneg (variance_nonneg _ _) (sq_nonneg _))] at hr + have hreal : p ≤ variance f μ / (a - (∫ x, f x ∂μ)) ^ 2 := + hprob.trans ((measureReal_mono hsub).trans hr) + rw [le_div_iff₀ (sq_pos_of_pos hc)] at hreal + have hs := Real.sq_sqrt (div_nonneg (variance_nonneg f μ) (le_of_lt hp)) + have he : p * Real.sqrt (variance f μ / p)^2 = variance f μ := by + rw [hs]; field_simp + have hle : a - (∫ x, f x ∂μ) ≤ Real.sqrt (variance f μ / p) := by + have hz := Real.sqrt_nonneg (variance f μ / p) + have hc2 := (mul_le_mul_iff_of_pos_left hp).mp (hreal.trans_eq he.symm) + nlinarith + linarith + +lemma integral_log_partition_le_log_mean (β : ℝ) {n : ℕ} (hn : 0 < n) : + (∫ g, Real.log (partition (sampledInteraction g)) ∂disorderLaw β n) ≤ + Real.log (∫ g, partition (sampledInteraction g) ∂disorderLaw β n) := by + let μ := disorderLaw β n + let : IsProbabilityMeasure μ := by dsimp [μ, disorderLaw]; infer_instance + let m := ∫ g, partition (sampledInteraction g) ∂μ + have hm : 0 < m := by dsimp [m, μ]; rw [integral_partition_sampled β hn]; positivity + have hi := integral_mono (memLp_log_partition β n |>.integrable one_le_two) + ((integrable_const (Real.log m)).add + ((integrable_partition_sampled β n).div_const m) |>.sub (integrable_const 1)) + (fun g => show Real.log (partition (sampledInteraction g)) ≤ + Real.log m + partition (sampledInteraction g) / m - 1 from by + have hl := Real.log_le_sub_one_of_pos (div_pos (partition_pos (sampledInteraction g)) hm) + rw [Real.log_div (ne_of_gt (partition_pos _)) (ne_of_gt hm)] at hl + linarith) + simp only [Pi.sub_apply, Pi.add_apply] at hi + rw [integral_sub (f := fun g => Real.log m + partition (sampledInteraction g) / m) + (g := fun _ => 1) ((integrable_const _).add ((integrable_partition_sampled β n).div_const _)) + (integrable_const _), integral_add (integrable_const _) + ((integrable_partition_sampled β n).div_const _), integral_const, integral_const, + integral_div] at hi + change (∫ g, Real.log (partition (sampledInteraction g)) ∂μ) ≤ + μ.real Set.univ • Real.log m + m / m - μ.real Set.univ • 1 at hi + simpa [ne_of_gt hm] using hi + +lemma integral_log_partition_ge_log_mean (β : ℝ) (hβ : β ^ 2 < 1) + {n : ℕ} (hn : 0 < n) : + Real.log (∫ g, partition (sampledInteraction g) ∂disorderLaw β n) - Real.log 2 - + Real.sqrt (β ^ 2 * n / (Real.sqrt (1 - β ^ 2) / 4)) ≤ + ∫ g, Real.log (partition (sampledInteraction g)) ∂disorderLaw β n := by + let μ := disorderLaw β n + let : IsProbabilityMeasure μ := by dsimp [μ, disorderLaw]; infer_instance + let m := ∫ g, partition (sampledInteraction g) ∂μ + have hm : 0 < m := by dsimp [m, μ]; rw [integral_partition_sampled β hn]; positivity + have hp : 0 < Real.sqrt (1 - β ^ 2) / 4 := by + exact div_pos (Real.sqrt_pos.2 (by linarith)) (by norm_num) + have hprob := partition_half_mean_probability β hβ hn + have he : {g : GaussianCoordinates n | m / 2 ≤ partition (sampledInteraction g)} = + {g : GaussianCoordinates n | Real.log m - Real.log 2 ≤ Real.log (partition (sampledInteraction g))} := by + ext g + rw [← Real.log_div (ne_of_gt hm) (by norm_num)] + exact (Real.log_le_log_iff (by positivity) (partition_pos _)).symm + change Real.sqrt (1 - β ^ 2) / 4 ≤ μ.real {g | m / 2 ≤ partition (sampledInteraction g)} at hprob + rw [he] at hprob + have hv := variance_log_partition_le β hn + have hs := Real.sqrt_le_sqrt (div_le_div_of_nonneg_right hv (le_of_lt hp)) + have hl := mean_ge_of_upper_event μ (memLp_log_partition β n) hp hprob + dsimp [m, μ] at hl hs ⊢ + linarith + +lemma square_integral_shift {Ω : Type*} [MeasurableSpace Ω] (μ : Measure Ω) + [IsProbabilityMeasure μ] {f : Ω → ℝ} (hf : MemLp f 2 μ) (a : ℝ) : + (∫ x, (f x - a)^2 ∂μ) = variance f μ + ((∫ x, f x ∂μ) - a)^2 := by + have hs : MemLp (fun x => f x - a) 2 μ := hf.sub (memLp_const a) + have hv := variance_eq_sub hs + rw [variance_sub_const hf.aestronglyMeasurable] at hv + simp only [Pi.pow_apply] at hv + rw [integral_sub (hf.integrable one_le_two) (integrable_const _), integral_const] at hv + simp only [measureReal_def, measure_univ, ENNReal.toReal_one, one_smul] at hv + linarith + +lemma second_moment_log_partition_centered_le (β : ℝ) (hβ : β ^ 2 < 1) + {n : ℕ} (hn : 0 < n) : + (∫ g, (Real.log (partition (sampledInteraction g)) - + Real.log (∫ h, partition (sampledInteraction h) ∂disorderLaw β n)) ^ 2 + ∂disorderLaw β n) ≤ + (β ^ 2 + 2 * β ^ 2 / (Real.sqrt (1 - β ^ 2) / 4)) * n + 2 * (Real.log 2)^2 := by + let μ := disorderLaw β n + let : IsProbabilityMeasure μ := by dsimp [μ, disorderLaw]; infer_instance + let c := Real.log (∫ g, partition (sampledInteraction g) ∂μ) + let m := ∫ g, Real.log (partition (sampledInteraction g)) ∂μ + let p := Real.sqrt (1 - β ^ 2) / 4 + have hp : 0 < p := by dsimp [p]; positivity + have hs : Real.sqrt (β ^ 2 * n / p)^2 = β ^ 2 * n / p := + Real.sq_sqrt (by positivity) + have hmUpper := integral_log_partition_le_log_mean β hn + have hmLower := integral_log_partition_ge_log_mean β hβ hn + change m ≤ c at hmUpper + change c - Real.log 2 - Real.sqrt (β ^ 2 * n / p) ≤ m at hmLower + have hlog : 0 ≤ Real.log 2 := Real.log_nonneg (by norm_num) + have hsq : (m-c)^2 ≤ 2 * (Real.log 2)^2 + 2 * β ^ 2 * n / p := by + have hm0 : 0 ≤ c-m := sub_nonneg.mpr hmUpper + have hms : c-m ≤ Real.log 2 + Real.sqrt (β ^ 2 * n / p) := by linarith + have hmsq := sq_le_sq₀ hm0 (by positivity : 0 ≤ Real.log 2 + Real.sqrt (β^2*n/p)) |>.mpr hms + have hh : 2 * β ^ 2 * (n : ℝ) / p = 2 * (β ^ 2 * n / p) := by ring + rw [hh] + nlinarith [sq_nonneg (Real.log 2 - Real.sqrt (β^2*n/p))] + rw [square_integral_shift μ (memLp_log_partition β n) c] + have hv := variance_log_partition_le β hn + change variance (fun g => Real.log (partition (sampledInteraction g))) μ ≤ β^2*n at hv + change variance (fun g => Real.log (partition (sampledInteraction g))) μ + (m-c)^2 ≤ _ + calc + _ ≤ β^2*n + (2 * (Real.log 2)^2 + 2 * β^2*n/p) := add_le_add hv hsq + _ = _ := by dsimp [p]; ring + +end SKGapCutoff +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/CubeApprox.lean b/lean/OAI/Probability/SKGap/Localization/CubeApprox.lean new file mode 100644 index 0000000000000000000000000000000000000000..800f332a5166599cad690f2edf5825e69fe36d79 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/CubeApprox.lean @@ -0,0 +1,99 @@ +import Mathlib +import OAI.Probability.SKGap.Matrix.RegularizedLogDet +import OAI.Probability.SKGap.Brownian.LogDetPath + +namespace OAI + +section +noncomputable section +namespace SKGap +open Matrix MeasureTheory ProbabilityTheory Real Set Filter +open scoped BigOperators Matrix.Norms.Frobenius Topology +variable {ι : Type*} [Fintype ι] [DecidableEq ι] [Nonempty ι] + +def coordAverage (a : ι → ℝ) : ℝ := (∑ i,a i)/(Fintype.card ι:ℝ) + +omit [DecidableEq ι] in +lemma coordAverage_bounds {a : ι → ℝ} (ha : ∀ i, 0 ≤ a i) (ha1 : ∀ i, a i ≤ 1) : + 0 ≤ coordAverage a ∧ coordAverage a ≤ 1 := by + have hn : (0:ℝ) < Fintype.card ι := Nat.cast_pos.mpr Fintype.card_pos + constructor + · exact div_nonneg (Finset.sum_nonneg (fun i _ => ha i)) hn.le + · apply (div_le_iff₀ hn).mpr + simpa using Finset.sum_le_sum (s := Finset.univ) (fun i _ => ha1 i) + +omit [DecidableEq ι] in +lemma coordAverage_sub_le {a b : ι → ℝ} {δ : ℝ} (hab : ∀ i, |a i-b i| ≤ δ) : + |coordAverage a-coordAverage b| ≤ δ := by + have hn : (0:ℝ) < Fintype.card ι := Nat.cast_pos.mpr Fintype.card_pos + unfold coordAverage + rw [← sub_div,← Finset.sum_sub_distrib,abs_div,abs_of_pos hn] + apply (div_le_iff₀ hn).mpr + exact ((Finset.abs_sum_le_sum_abs _ _).trans + (Finset.sum_le_sum (fun i _ => hab i))).trans_eq (by simp [mul_comm]) + +omit [DecidableEq ι] in +lemma coordAverage_sq_sub_le {j δ : ℝ} (hj : 0 ≤ j) {a b : ι → ℝ} + (ha : ∀ i, 0 ≤ a i) (ha1 : ∀ i,a i ≤ 1) (hb : ∀ i,0 ≤ b i) (hb1 : ∀ i,b i ≤ 1) + (hab : ∀ i, |a i-b i| ≤ δ) : + |j*(coordAverage a)^2-j*(coordAverage b)^2| ≤ 2*j*δ := by + have haa := coordAverage_bounds ha ha1 + have hbb := coordAverage_bounds hb hb1 + have hd := coordAverage_sub_le hab + have hh := mul_le_mul_of_nonneg_left hd hj + have he : j*(coordAverage a)^2-j*(coordAverage b)^2= + (j*(coordAverage a-coordAverage b))*(coordAverage a+coordAverage b) := by ring + rw [he,abs_mul,abs_mul,abs_of_nonneg hj,abs_of_nonneg (by linarith : 0 ≤ coordAverage a+coordAverage b)] + calc + _ ≤ (j*δ)*2 := mul_le_mul hh (by linarith) (by linarith : 0 ≤ coordAverage a+coordAverage b) (by nlinarith [abs_nonneg (coordAverage a-coordAverage b)]) + _ = _ := by ring + +lemma logPath_cube_difference {j δ R : ℝ} (hj : 0 ≤ j) (hδ : 0 ≤ δ) (_hR : 0 ≤ R) + {a b : ι → ℝ} (ha : ∀ i,0 ≤ a i) (ha1 : ∀ i,a i ≤ 1) + (hb : ∀ i,0 ≤ b i) (hb1 : ∀ i,b i ≤ 1) (hab : ∀ i,|a i-b i| ≤ δ) + {M : Matrix ι ι ℝ} (hM : opNorm M ≤ R) : + ‖logPath (j*coordAverage a) a M 1-logPath (j*coordAverage b) b M 1‖ ≤ + sqrt (Fintype.card ι:ℝ)*(2*j+R)*δ := by + have haa := coordAverage_bounds ha ha1 + have hd := coordAverage_sub_le hab + have hDa : opNorm (diagonal a-diagonal b) ≤ δ := by + rw [diagonal_sub] + exact opNorm_diagonal_le hδ hab + have hDb : opNorm (diagonal b) ≤ 1 := opNorm_diagonal_le (by norm_num) + (fun i => by rw [abs_of_nonneg (hb i)]; exact hb1 i) + have hF₁ := (LogDet.frobenius_le_sqrt_card_opNorm (diagonal a-diagonal b)).trans + (mul_le_mul_of_nonneg_left hDa (sqrt_nonneg _)) + have hF₂ := (LogDet.frobenius_le_sqrt_card_opNorm (diagonal b)).trans + (mul_le_mul_of_nonneg_left hDb (sqrt_nonneg _)) + simp only [mul_one] at hF₂ + have hq : |j*coordAverage a| ≤ j := by rw [abs_of_nonneg (mul_nonneg hj haa.1)]; nlinarith + have hq' : |j*coordAverage a-j*coordAverage b| ≤ j*δ := by + rw [← mul_sub,abs_mul,abs_of_nonneg hj]; exact mul_le_mul_of_nonneg_left hd hj + have he : logPath (j*coordAverage a) a M 1-logPath (j*coordAverage b) b M 1= + (j*coordAverage a) • (diagonal a-diagonal b)+ + (j*coordAverage a-j*coordAverage b) • diagonal b-(diagonal a-diagonal b)*M := by + simp only [logPath,one_pow,one_mul,one_smul,smul_sub,sub_smul,Matrix.sub_mul] + abel + rw [he] + apply (norm_sub_le _ _).trans + apply (add_le_add (norm_add_le _ _) (frobenius_mul_le_opNorm_right _ _)).trans + rw [norm_smul,norm_smul,Real.norm_eq_abs,Real.norm_eq_abs] + have hf₁ := mul_le_mul hq hF₁ (norm_nonneg _) hj + have hf₂ := mul_le_mul hq' hF₂ (norm_nonneg _) (mul_nonneg hj hδ) + have hf₃ := mul_le_mul hF₁ hM (norm_nonneg _) (mul_nonneg (sqrt_nonneg _) hδ) + nlinarith + +lemma scalar_cube_net {δ : ℝ} (hδ : 0 < δ) : + ∃ s : Finset ℝ, (∀ x ∈ s, x ∈ Icc (0:ℝ) 1) ∧ + ∀ x ∈ Icc (0:ℝ) 1, ∃ y ∈ s, |x-y| ≤ δ := by + classical + obtain ⟨s,hs,hsfin,hcover⟩ := (isCompact_Icc : IsCompact (Icc (0:ℝ) 1)).finite_cover_balls hδ + refine ⟨hsfin.toFinset,fun x hx => hs (hsfin.mem_toFinset.mp hx),?_⟩ + intro x hx + obtain ⟨y,hy,hxy⟩ := mem_iUnion₂.mp (hcover hx) + exact ⟨y,hsfin.mem_toFinset.mpr hy,(show |x-y| < δ from Metric.mem_ball.mp hxy).le⟩ +end SKGap +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/CubeWeight.lean b/lean/OAI/Probability/SKGap/Localization/CubeWeight.lean new file mode 100644 index 0000000000000000000000000000000000000000..b8b03275a3ab500e6214c2c34527b15d67cdc02e --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/CubeWeight.lean @@ -0,0 +1,235 @@ +import Mathlib +import OAI.Probability.SKGap.Terminal.GibbsExpectation + +namespace OAI + +section +open scoped BigOperators +open scoped BigOperators +namespace SKGapCutoff + +noncomputable def cubeWeight {n : ℕ} (z : Fin n → ℝ) (x : Spin n) : ℝ := + ∏ i, (1 + spin x i * z i) / 2 + +noncomputable def deletedWeight {n : ℕ} (z : Fin n → ℝ) (x : Spin n) + (i : Fin n) : ℝ := ∏ j ∈ Finset.univ.erase i, (1 + spin x j * z j) / 2 + +noncomputable def cubeExtension {n : ℕ} (f : Observables n) (z : Fin n → ℝ) : ℝ := + ∑ x, cubeWeight z x * f x + +lemma cubeWeight_sum {n : ℕ} (z : Fin n → ℝ) : ∑ x, cubeWeight z x = 1 := by + change (∑ x : Fin n → Bool, ∏ i, (1 + (if x i then 1 else -1 : ℝ) * z i) / 2) = 1 + rw [← Fintype.prod_sum (fun (i : Fin n) (b : Bool) => + (1 + (if b then 1 else -1 : ℝ) * z i) / 2)] + have h (i : Fin n) : (∑ b : Bool, (1 + (if b then 1 else -1 : ℝ) * z i) / 2) = 1 := by + rw [Fintype.sum_bool] + simp only [Bool.false_eq_true, ↓reduceIte] + ring + simp_rw [h] + simp + +lemma cubeWeight_nonneg {n : ℕ} (z : Fin n → ℝ) + (hz : ∀ i, -1 ≤ z i ∧ z i ≤ 1) (x : Spin n) : 0 ≤ cubeWeight z x := by + apply Finset.prod_nonneg + intro i _ + apply div_nonneg _ (by norm_num) + rcases hz i with ⟨hl, hu⟩ + cases h : x i <;> simp only [spin, h, ↓reduceIte, Bool.false_eq_true] + · linarith + · linarith + +lemma cubeWeight_vertex {n : ℕ} (x y : Spin n) : + cubeWeight (spin x) y = if y = x then 1 else 0 := by + classical + by_cases h : y = x + · subst y + simp [cubeWeight, ← sq, spin_sq] + · rw [ite_eq_right h] + obtain ⟨i, hi⟩ := Function.ne_iff.mp h + apply Finset.prod_eq_zero (Finset.mem_univ i) + have hs : spin y i * spin x i = -1 := by + cases hx : x i <;> cases hy : y i <;> simp_all [spin] + simp [hs] + +lemma cubeExtension_vertex {n : ℕ} (f : Observables n) (x : Spin n) : + cubeExtension f (spin x) = f x := by + classical + simp [cubeExtension, cubeWeight_vertex] + +lemma deletedWeight_flip {n : ℕ} (z : Fin n → ℝ) (x : Spin n) (i : Fin n) : + deletedWeight z (flip x i) i = deletedWeight z x i := by + apply Finset.prod_congr rfl + intro j hj + simp only [Finset.mem_erase] at hj + rw [spin_flip] + simp [hj.1] + +lemma cubeWeight_factor {n : ℕ} (z : Fin n → ℝ) (x : Spin n) (i : Fin n) : + cubeWeight z x = (1 + spin x i * z i) / 2 * deletedWeight z x i := by + exact (Finset.mul_prod_erase _ _ (Finset.mem_univ i)).symm + +lemma cubeWeight_flip_add {n : ℕ} (z : Fin n → ℝ) (x : Spin n) (i : Fin n) : + cubeWeight z x + cubeWeight z (flip x i) = deletedWeight z x i := by + rw [cubeWeight_factor z x i, cubeWeight_factor z (flip x i) i, + deletedWeight_flip, spin_flip_self] + ring + +lemma cubeWeight_halfDiff {n : ℕ} (z : Fin n → ℝ) (f : Observables n) (i : Fin n) : + (∑ x, cubeWeight z x * halfDiff i f x) = + ∑ x, f x * (spin x i / 2) * deletedWeight z x i := by + have hA (x : Spin n) : + f x * (spin x i / 2) * deletedWeight z x i + + f (flip x i) * (spin (flip x i) i / 2) * deletedWeight z (flip x i) i = + deletedWeight z x i * halfDiff i f x := by + rw [spin_flip_self, deletedWeight_flip] + have he : f (flip x i) = f x - 2 * spin x i * halfDiff i f x := by + linarith only [flip_sub i f x] + rw [he] + calc + _ = (spin x i * spin x i) * (deletedWeight z x i * halfDiff i f x) := by ring + _ = _ := by rw [spin_mul_self, one_mul] + have hB (x : Spin n) : + cubeWeight z x * halfDiff i f x + + cubeWeight z (flip x i) * halfDiff i f (flip x i) = + deletedWeight z x i * halfDiff i f x := by + rw [halfDiff_flip, ← add_mul, cubeWeight_flip_add] + have ha := sum_flip i (fun x => f x * (spin x i / 2) * deletedWeight z x i) + have hb := sum_flip i (fun x => cubeWeight z x * halfDiff i f x) + have h : (∑ x, cubeWeight z x * halfDiff i f x) + + (∑ x, cubeWeight z (flip x i) * halfDiff i f (flip x i)) = + (∑ x, f x * (spin x i / 2) * deletedWeight z x i) + + (∑ x, f (flip x i) * (spin (flip x i) i / 2) * deletedWeight z (flip x i) i) := by + rw [← Finset.sum_add_distrib, ← Finset.sum_add_distrib] + exact Finset.sum_congr rfl (fun x _ => (hB x).trans (hA x).symm) + rw [ha, hb] at h + linarith only [h] + +lemma cubeExtension_line_deriv {n : ℕ} (f : Observables n) (a b : Fin n → ℝ) (t : ℝ) : + HasDerivAt (fun s : ℝ => cubeExtension f (fun i => a i + s * b i)) + (∑ i, b i * ∑ x, cubeWeight (fun j => a j + t * b j) x * halfDiff i f x) t := by + have hf (x : Spin n) (i : Fin n) : + HasDerivAt (fun s : ℝ => (1 + spin x i * (a i + s * b i)) / 2) + (spin x i * b i / 2) t := by + simpa only [one_mul, id_eq] using (((((hasDerivAt_id t).mul_const (b i)).const_add (a i)).const_mul + (spin x i)).const_add 1).div_const 2 + have hp (x : Spin n) := + (HasDerivAt.finsetProd (u := Finset.univ) (fun i _ => hf x i)).mul_const (f x) + have h := HasDerivAt.sum (u := Finset.univ) (fun x _ => hp x) + have hd : (∑ x, (∑ i, (∏ j ∈ Finset.univ.erase i, + (1 + spin x j * (a j + t * b j)) / 2) • (spin x i * b i / 2)) * f x) = + ∑ i, b i * ∑ x, cubeWeight (fun j => a j + t * b j) x * halfDiff i f x := by + simp only [smul_eq_mul, Finset.sum_mul] + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro i _ + rw [cubeWeight_halfDiff, Finset.mul_sum] + apply Finset.sum_congr rfl + intro x _ + dsimp only [deletedWeight] + ring + rw [hd] at h + have he : (∑ x, fun y : ℝ => (∏ i, (1 + spin x i * (a i + y * b i)) / 2) * f x) = + (fun s : ℝ => cubeExtension f (fun i => a i + s * b i)) := by + funext s + simp only [Finset.sum_apply, cubeExtension, cubeWeight] + simp only [Finset.prod_apply] at h + rw [he] at h + exact h + +lemma weighted_mean_sq_le {α : Type*} [Fintype α] (p f : α → ℝ) + (hp : ∀ x, 0 ≤ p x) (hs : ∑ x, p x = 1) : + (∑ x, p x * f x) ^ 2 ≤ ∑ x, p x * f x ^ 2 := by + have h : 0 ≤ ∑ x, p x * (f x - ∑ y, p y * f y) ^ 2 := by + exact Finset.sum_nonneg (fun x _ => mul_nonneg (hp x) (sq_nonneg _)) + simp_rw [sub_sq, mul_add, mul_sub] at h + simp only [Finset.sum_add_distrib, Finset.sum_sub_distrib] at h + have h1 : (∑ x, p x * (2 * f x * ∑ y, p y * f y)) = + 2 * (∑ x, p x * f x) ^ 2 := by + simp_rw [show ∀ x, p x * (2 * f x * ∑ y, p y * f y) = + 2 * (p x * f x) * (∑ y, p y * f y) by intro x; ring] + rw [← Finset.sum_mul, ← Finset.mul_sum] + ring + have h2 : (∑ x, p x * (∑ y, p y * f y) ^ 2) = (∑ y, p y * f y) ^ 2 := by + rw [← Finset.sum_mul, hs, one_mul] + rw [h1, h2] at h + linarith only [h] + +lemma cubeExtension_gradient_sq_le {n : ℕ} (f : Observables n) (z : Fin n → ℝ) + (hz : ∀ i, -1 ≤ z i ∧ z i ≤ 1) (C : ℝ) + (hf : ∀ x, ∑ i, (halfDiff i f x) ^ 2 ≤ C ^ 2) : + (∑ i, (∑ x, cubeWeight z x * halfDiff i f x) ^ 2) ≤ C ^ 2 := by + calc + _ ≤ ∑ i, ∑ x, cubeWeight z x * (halfDiff i f x) ^ 2 := by + apply Finset.sum_le_sum + intro i _ + exact weighted_mean_sq_le _ _ (cubeWeight_nonneg z hz) (cubeWeight_sum z) + _ = ∑ x, cubeWeight z x * ∑ i, (halfDiff i f x) ^ 2 := by + rw [Finset.sum_comm] + simp_rw [Finset.mul_sum] + _ ≤ ∑ x, cubeWeight z x * C ^ 2 := by + apply Finset.sum_le_sum + intro x _ + exact mul_le_mul_of_nonneg_left (hf x) (cubeWeight_nonneg z hz x) + _ = C ^ 2 := by rw [← Finset.sum_mul, cubeWeight_sum, one_mul] + +lemma spin_segment_mem {n : ℕ} (x y : Spin n) (t : ℝ) (ht : t ∈ Set.Icc (0 : ℝ) 1) + (i : Fin n) : -1 ≤ spin x i + t * (spin y i - spin x i) ∧ + spin x i + t * (spin y i - spin x i) ≤ 1 := by + rcases ht with ⟨hl, hu⟩ + cases hx : x i <;> cases hy : y i <;> + simp only [spin, hx, hy, Bool.false_eq_true, ↓reduceIte] <;> constructor <;> nlinarith + +lemma spin_vertex_distance_sq {n : ℕ} (x y : Spin n) : + (∑ i, (spin y i - spin x i) ^ 2) ≤ 4 * n := by + calc + _ ≤ ∑ _i : Fin n, (4 : ℝ) := by + apply Finset.sum_le_sum + intro i _ + cases hx : x i <;> cases hy : y i <;> + norm_num [spin, hx, hy] + _ = _ := by simp; ring + +lemma cubeExtension_direction_bound {n : ℕ} (f : Observables n) (z b : Fin n → ℝ) + (hz : ∀ i, -1 ≤ z i ∧ z i ≤ 1) (C : ℝ) (hC : 0 ≤ C) + (hf : ∀ x, ∑ i, (halfDiff i f x) ^ 2 ≤ C ^ 2) + (hb : ∑ i, (b i) ^ 2 ≤ 4 * n) : + |∑ i, b i * ∑ x, cubeWeight z x * halfDiff i f x| ≤ 2 * Real.sqrt n * C := by + have hn : (0 : ℝ) ≤ n := Nat.cast_nonneg n + have hg := cubeExtension_gradient_sq_le f z hz C hf + have hs : (∑ i, b i * ∑ x, cubeWeight z x * halfDiff i f x) ^ 2 ≤ + (2 * Real.sqrt n * C) ^ 2 := by + calc + _ ≤ (∑ i, (b i) ^ 2) * (∑ i, (∑ x, cubeWeight z x * halfDiff i f x) ^ 2) := + Finset.sum_mul_sq_le_sq_mul_sq Finset.univ _ _ + _ ≤ (4 * n) * C ^ 2 := mul_le_mul hb hg + (Finset.sum_nonneg (fun i _ => sq_nonneg _)) (by positivity) + _ = _ := by rw [mul_pow, mul_pow, Real.sq_sqrt hn]; ring + exact le_of_sq_le_sq (by simpa only [sq_abs] using hs) (by positivity) + +theorem euclidean_oscillation {n : ℕ} (f : Observables n) (C : ℝ) (hC : 0 ≤ C) + (hf : ∀ x, ∑ i, (halfDiff i f x) ^ 2 ≤ C ^ 2) (x y : Spin n) : + |f x - f y| ≤ 2 * Real.sqrt n * C := by + let F : ℝ → ℝ := fun t => cubeExtension f (fun i => spin x i + t * (spin y i - spin x i)) + have hd (t : ℝ) := cubeExtension_line_deriv f (spin x) (fun i => spin y i - spin x i) t + have hdiff : ∀ t ∈ Set.Icc (0 : ℝ) 1, DifferentiableAt ℝ F t := + fun t _ => (hd t).differentiableAt + have hbound : ∀ t ∈ Set.Icc (0 : ℝ) 1, ‖deriv F t‖ ≤ 2 * Real.sqrt n * C := by + intro t ht + rw [(hd t).deriv, Real.norm_eq_abs] + exact cubeExtension_direction_bound f _ _ (spin_segment_mem x y t ht) C hC hf + (spin_vertex_distance_sq x y) + have hv := (convex_Icc (0 : ℝ) 1).norm_image_sub_le_of_norm_deriv_le + hdiff hbound (by simp : (0 : ℝ) ∈ Set.Icc (0 : ℝ) 1) + (by simp : (1 : ℝ) ∈ Set.Icc (0 : ℝ) 1) + have hf0 : F 0 = f x := by simp [F, cubeExtension_vertex] + have hf1 : F 1 = f y := by simp [F, cubeExtension_vertex] + rw [hf0, hf1, sub_zero, norm_one, mul_one, Real.norm_eq_abs, abs_sub_comm] at hv + exact hv + +end SKGapCutoff + +open scoped BigOperators + +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/CurieWeiss.lean b/lean/OAI/Probability/SKGap/Localization/CurieWeiss.lean new file mode 100644 index 0000000000000000000000000000000000000000..600593fae6e77f2201d1f96b335ecc7ac2db8c2d --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/CurieWeiss.lean @@ -0,0 +1,323 @@ +import Mathlib +import OAI.Probability.SKGap.Terminal.GibbsExpectationMono +import OAI.Probability.SKGap.Matrix.NormalizedInfluence + +namespace OAI + +section +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open scoped BigOperators +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open scoped BigOperators +open scoped BigOperators NNReal ENNReal +open MeasureTheory Metric Set +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators NNReal ENNReal Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Set +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators ENNReal NNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Matrix +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators ENNReal NNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal +open scoped BigOperators +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise NNReal ENNReal +open scoped BigOperators +open Filter Topology +namespace SKGapCutoff + +noncomputable def curieWeiss (a : ℝ) (n : ℕ) : Interaction n := + fun i j => if i=j then 0 else a/(n:ℝ) + +lemma curieWeiss_symm (a : ℝ) (n : ℕ) : + ∀ i j, curieWeiss a n i j = curieWeiss a n j i := by + intro i j + simp only [curieWeiss, eq_comm] + +lemma curieWeiss_diag (a : ℝ) (n : ℕ) : ∀ i, curieWeiss a n i i = 0 := by + intro i + simp [curieWeiss] + +lemma curieWeiss_energy (a : ℝ) {n : ℕ} (x : Spin n) : + energy (curieWeiss a n) x = a/(2*(n:ℝ))*(magnetization x^2-(n:ℝ)) := by + have hentry (i j : Fin n) : spin x i * curieWeiss a n i j * spin x j = + a/(n:ℝ)*(spin x i*spin x j) - if i=j then a/(n:ℝ) else 0 := by + by_cases h : i=j + · subst j + simp [curieWeiss] + · simp [curieWeiss, h] + ring + have hs : (∑ i, ∑ j, a/(n:ℝ)*(spin x i*spin x j)) = + a/(n:ℝ)*magnetization x^2 := by + simp only [magnetization, pow_two, Finset.mul_sum, Finset.sum_mul] + exact Finset.sum_comm + simp only [energy, hentry, Finset.sum_sub_distrib, + Fintype.sum_ite_eq, Finset.sum_const, Finset.card_univ, Fintype.card_fin, nsmul_eq_mul] + rw [hs] + ring + +noncomputable def majority {n : ℕ} (x : Spin n) : ℝ := + if 0 < magnetization x then 1 else if magnetization x < 0 then -1 else 0 + +@[simp] lemma magnetization_invert {n : ℕ} (x : Spin n) : + magnetization (invert x) = -magnetization x := by + simp [magnetization] + +@[simp] lemma majority_invert {n : ℕ} (x : Spin n) : majority (invert x) = -majority x := by + simp only [majority, magnetization_invert] + split_ifs <;> linarith + +lemma majority_abs_le_one {n : ℕ} (x : Spin n) : |majority x| ≤ 1 := by + unfold majority + split_ifs <;> norm_num + +lemma majority_centered {n : ℕ} (J : Interaction n) : gibbsExpectation J majority = 0 := by + have h := sum_invert (fun x => gibbs J x*majority x) + simp only [gibbs_invert, majority_invert, mul_neg, Finset.sum_neg_distrib] at h + unfold gibbsExpectation + linarith + +lemma majority_sq {n : ℕ} (x : Spin n) : + majority x^2 = if magnetization x=0 then 0 else 1 := by + rcases lt_trichotomy (magnetization x) 0 with hm | hm | hm + · simp [majority, hm, not_lt_of_ge (le_of_lt hm), ne_of_lt hm] + · simp [majority, hm] + · simp [majority, hm, ne_of_gt hm] + +lemma magnetization_replace {n : ℕ} (x : Spin n) (i : Fin n) (b : Bool) : + magnetization (replace x i b) = magnetization x - spin x i + if b then 1 else -1 := by + have h : spin (replace x i b) = Function.update (spin x) i (if b then 1 else -1) := by + funext j + by_cases hj : j=i + · subst j + simp [spin, replace] + · simp [spin, replace, hj] + simp only [magnetization, h] + rw [Finset.sum_update_of_mem (Finset.mem_univ i)] + have hs := Finset.sum_sdiff (f := spin x) (by simp : + ({i} : Finset (Fin n)) ⊆ Finset.univ) + simp only [Finset.sum_singleton] at hs + linarith + +lemma halfDiff_majority_zero {n : ℕ} (x : Spin n) (i : Fin n) + (hx : 2 < |magnetization x|) : halfDiff i majority x = 0 := by + have hi := spin_sq x i + have hi1 : -1 ≤ spin x i ∧ spin x i ≤ 1 := by + constructor <;> nlinarith + rcases lt_or_ge (magnetization x) 0 with hm | hm + · rw [abs_of_neg hm] at hx + have ht : magnetization (replace x i true) < 0 := by + simp only [magnetization_replace, ↓reduceIte] + linarith [hi1.1] + have hf : magnetization (replace x i false) < 0 := by + simp only [magnetization_replace, Bool.false_eq_true, ↓reduceIte] + linarith [hi1.1] + simp [halfDiff, majority, ht, hf, not_lt_of_ge (le_of_lt ht), not_lt_of_ge (le_of_lt hf)] + · rw [abs_of_nonneg hm] at hx + have ht : 0 < magnetization (replace x i true) := by + simp only [magnetization_replace, ↓reduceIte] + linarith [hi1.2] + have hf : 0 < magnetization (replace x i false) := by + simp only [magnetization_replace, Bool.false_eq_true, ↓reduceIte] + linarith [hi1.2] + simp [halfDiff, majority, ht, hf] + +lemma halfDiff_majority_abs_le_one {n : ℕ} (x : Spin n) (i : Fin n) : + |halfDiff i majority x| ≤ 1 := by + have h := (abs_sub (majority (replace x i true)) (majority (replace x i false))).trans + (add_le_add (majority_abs_le_one _) (majority_abs_le_one _)) + simp only [halfDiff, abs_div, abs_of_pos (by norm_num : (0:ℝ)<2)] + exact (div_le_iff₀ (by norm_num : (0:ℝ)<2)).mpr (by linarith) + +noncomputable def centralMass {n : ℕ} (J : Interaction n) : ℝ := + gibbsExpectation J (fun x => if |magnetization x| ≤ 2 then 1 else 0) + +lemma majority_variance_lower {n : ℕ} (J : Interaction n) : + 1 - centralMass J ≤ gibbsVariance J majority := by + rw [gibbsVariance, majority_centered] + simp only [sub_zero] + calc + _ = gibbsExpectation J (fun x => 1-(if |magnetization x| ≤ 2 then 1 else 0)) := by + rw [gibbsExpectation_sub, gibbsExpectation_const] + rfl + _ ≤ _ := gibbsExpectation_mono J _ _ (fun x => by + rw [majority_sq] + split_ifs <;> simp_all) + +lemma majority_dirichlet_upper {n : ℕ} (J : Interaction n) : + dirichlet J majority majority ≤ (n:ℝ)*centralMass J := by + change gibbsExpectation J _ ≤ (n:ℝ)*gibbsExpectation J _ + rw [← gibbsExpectation_mul_const] + apply gibbsExpectation_mono + intro x + by_cases hx : |magnetization x| ≤ 2 + · simp only [hx, ↓reduceIte, mul_one] + calc + _ ≤ ∑ _i : Fin n, (1:ℝ) := by + apply Finset.sum_le_sum + intro i _ + have ha := halfDiff_majority_abs_le_one x i + have hh : (halfDiff i majority x)^2 ≤ 1 := + (sq_le_one_iff_abs_le_one _).mpr ha + nlinarith [(le_of_lt (siteVariance_pos J x i)), siteVariance_le_one J x i, + mul_le_mul_of_nonneg_left hh ((le_of_lt (siteVariance_pos J x i)))] + _ = _ := by simp + · simp [hx, halfDiff_majority_zero x _ (lt_of_not_ge hx)] + +lemma gibbs_le_exp_energy_diff {n : ℕ} (J : Interaction n) (x y : Spin n) : + gibbs J x ≤ Real.exp (energy J x-energy J y) := by + rw [gibbs, Real.exp_sub] + apply div_le_div_of_nonneg_left (le_of_lt (Real.exp_pos _)) (Real.exp_pos _) + exact Finset.single_le_sum (fun z _ => le_of_lt (Real.exp_pos (energy J z))) (Finset.mem_univ y) + +lemma curieWeiss_central_point_bound (a : ℝ) (ha : 0 ≤ a) {n : ℕ} + (hn : 0 < n) (x : Spin n) (hx : |magnetization x| ≤ 2) : + gibbs (curieWeiss a n) x ≤ Real.exp (-a*(n:ℝ)/2+2*a/(n:ℝ)) := by + apply (gibbs_le_exp_energy_diff _ x (plusSpin n)).trans + apply Real.exp_le_exp.mpr + rw [curieWeiss_energy, curieWeiss_energy, magnetization_plus] + have hnR : (0:ℝ) < n := Nat.cast_pos.mpr hn + have hsq : magnetization x^2 ≤ 4 := by + have h := (sq_le_sq₀ (abs_nonneg (magnetization x)) (by norm_num : (0:ℝ)≤2)).mpr hx + norm_num at h ⊢ + exact h + calc + _ = a/(2*(n:ℝ))*magnetization x^2-a*(n:ℝ)/2 := by field_simp; ring + _ ≤ a/(2*(n:ℝ))*4-a*(n:ℝ)/2 := by gcongr + _ = _ := by ring + +lemma curieWeiss_central_bound (a : ℝ) (ha : 0 ≤ a) {n : ℕ} (hn : 0 < n) : + centralMass (curieWeiss a n) ≤ (2:ℝ)^n*Real.exp (-a*(n:ℝ)/2+2*a/(n:ℝ)) := by + unfold centralMass gibbsExpectation + calc + _ ≤ ∑ _x : Spin n, Real.exp (-a*(n:ℝ)/2+2*a/(n:ℝ)) := by + apply Finset.sum_le_sum + intro x _ + dsimp only + split_ifs with hx + · simpa using curieWeiss_central_point_bound a ha hn x hx + · simp [le_of_lt (Real.exp_pos _)] + _ = _ := by simp [Spin] + +theorem curieWeiss_gap_bottleneck (a : ℝ) (ha : 0 ≤ a) {n : ℕ} (hn : 0 < n) + {γ : ℝ} (hγ : 0 ≤ γ) (hg : HasGap (curieWeiss a n) γ) : + γ*(1-(2:ℝ)^n*Real.exp (-a*(n:ℝ)/2+2*a/(n:ℝ))) ≤ + (n:ℝ)*((2:ℝ)^n*Real.exp (-a*(n:ℝ)/2+2*a/(n:ℝ))) := by + have hb := curieWeiss_central_bound a ha hn + calc + _ ≤ γ*(1-centralMass (curieWeiss a n)) := by gcongr + _ ≤ γ*gibbsVariance (curieWeiss a n) majority := + mul_le_mul_of_nonneg_left (majority_variance_lower _) hγ + _ ≤ dirichlet (curieWeiss a n) majority majority := hg majority + _ ≤ (n:ℝ)*centralMass (curieWeiss a n) := majority_dirichlet_upper _ + _ ≤ _ := by gcongr + +lemma curieWeiss_entry_bound (a : ℝ) (ha : 0 ≤ a) {n : ℕ} (i j : Fin n) : + |curieWeiss a n i j| ≤ a/(n:ℝ) := by + unfold curieWeiss + split_ifs + · simp only [abs_zero] + positivity + · exact (abs_of_nonneg (by positivity)).le + +lemma curieWeiss_norm_bound (a : ℝ) (ha : 0 ≤ a) {n : ℕ} (hn : 0 < n) : + ‖Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) (curieWeiss a n)‖ ≤ a := by + apply matrix_opNorm_le_schur _ a ha + · intro i + calc + _ ≤ ∑ _j : Fin n, a/(n:ℝ) := Finset.sum_le_sum (fun j _ => curieWeiss_entry_bound a ha i j) + _ = a := by simp; field_simp + · intro j + calc + _ ≤ ∑ _i : Fin n, a/(n:ℝ) := Finset.sum_le_sum (fun i _ => curieWeiss_entry_bound a ha i j) + _ = a := by simp; field_simp + +lemma curieWeiss_bound_exp (a : ℝ) (n : ℕ) : + (2:ℝ)^n*Real.exp (-a*(n:ℝ)/2+2*a/(n:ℝ)) = + Real.exp (-(a/2-Real.log 2)*(n:ℝ))*Real.exp (2*a/(n:ℝ)) := by + have hp : (2:ℝ)^n = Real.exp ((n:ℝ)*Real.log 2) := by + rw [Real.exp_nat_mul, Real.exp_log (by norm_num : (0:ℝ)<2)] + rw [hp, ← Real.exp_add, ← Real.exp_add] + congr 1 + ring + +lemma curieWeiss_bound_tendsto_zero (a : ℝ) (ha : 2*Real.log 2 < a) : + Tendsto (fun n : ℕ => (2:ℝ)^n*Real.exp (-a*(n:ℝ)/2+2*a/(n:ℝ))) atTop (nhds 0) := by + have hk : 0 < a/2-Real.log 2 := by linarith + have h1 : Tendsto (fun n : ℕ => Real.exp (-(a/2-Real.log 2)*(n:ℝ))) atTop (nhds 0) := by + simpa using (Real.summable_pow_mul_exp_neg_nat_mul 0 hk).tendsto_atTop_zero + have h2 : Tendsto (fun n : ℕ => Real.exp (2*a/(n:ℝ))) atTop (nhds 1) := by + simpa only [Function.comp_def, Real.exp_zero] using Real.continuous_exp.continuousAt.tendsto.comp + (show Tendsto (fun n : ℕ => 2*a/(n:ℝ)) atTop (nhds 0) from + tendsto_const_nhds.div_atTop tendsto_natCast_atTop_atTop) + simp_rw [curieWeiss_bound_exp] + simpa using h1.mul h2 + +lemma curieWeiss_n_bound_tendsto_zero (a : ℝ) (ha : 2*Real.log 2 < a) : + Tendsto (fun n : ℕ => (n:ℝ)*((2:ℝ)^n*Real.exp (-a*(n:ℝ)/2+2*a/(n:ℝ)))) + atTop (nhds 0) := by + have hk : 0 < a/2-Real.log 2 := by linarith + have h1 : Tendsto (fun n : ℕ => (n:ℝ)*Real.exp (-(a/2-Real.log 2)*(n:ℝ))) + atTop (nhds 0) := by + simpa using (Real.summable_pow_mul_exp_neg_nat_mul 1 hk).tendsto_atTop_zero + have h2 : Tendsto (fun n : ℕ => Real.exp (2*a/(n:ℝ))) atTop (nhds 1) := by + simpa only [Function.comp_def, Real.exp_zero] using Real.continuous_exp.continuousAt.tendsto.comp + (show Tendsto (fun n : ℕ => 2*a/(n:ℝ)) atTop (nhds 0) from + tendsto_const_nhds.div_atTop tendsto_natCast_atTop_atTop) + simp_rw [curieWeiss_bound_exp, ← mul_assoc] + simpa using h1.mul h2 + +theorem curieWeiss_no_uniform_gap (a : ℝ) (ha : 2*Real.log 2 < a) : + ¬ ∃ γ : ℝ, 0 < γ ∧ ∀ᶠ n : ℕ in atTop, HasGap (curieWeiss a n) γ := by + rintro ⟨γ, hγ, hg⟩ + have ha0 : 0 ≤ a := by linarith [Real.log_pos (by norm_num : (1:ℝ)<2)] + have hbound : ∀ᶠ n : ℕ in atTop, + γ*(1-(2:ℝ)^n*Real.exp (-a*(n:ℝ)/2+2*a/(n:ℝ))) ≤ + (n:ℝ)*((2:ℝ)^n*Real.exp (-a*(n:ℝ)/2+2*a/(n:ℝ))) := by + filter_upwards [hg, eventually_gt_atTop 0] with n hn hn0 + exact curieWeiss_gap_bottleneck a ha0 hn0 hγ.le hn + have hleft : Tendsto (fun n : ℕ => γ*(1-(2:ℝ)^n*Real.exp (-a*(n:ℝ)/2+2*a/(n:ℝ)))) + atTop (nhds γ) := by + simpa using ((tendsto_const_nhds : Tendsto (fun _ : ℕ => (1:ℝ)) atTop (nhds 1)).sub + (curieWeiss_bound_tendsto_zero a ha)).const_mul γ + have hle := le_of_tendsto_of_tendsto hleft (curieWeiss_n_bound_tendsto_zero a ha) hbound + linarith + +lemma curieWeiss_entries_vanish (a : ℝ) (ha : 0 ≤ a) (ε : ℝ) (hε : 0 < ε) : + ∀ᶠ n : ℕ in atTop, ∀ i j : Fin n, |curieWeiss a n i j| < ε := by + have h : Tendsto (fun n : ℕ => a/(n:ℝ)) atTop (nhds 0) := + tendsto_const_nhds.div_atTop tendsto_natCast_atTop_atTop + filter_upwards [h.eventually (gt_mem_nhds hε)] with n hn i j + exact (curieWeiss_entry_bound a ha i j).trans_lt hn + +end SKGapCutoff + +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology + +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/CyclicPrediction.lean b/lean/OAI/Probability/SKGap/Localization/CyclicPrediction.lean new file mode 100644 index 0000000000000000000000000000000000000000..6b44efb55e789dae2384685263768581ef0833be --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/CyclicPrediction.lean @@ -0,0 +1,92 @@ +import Mathlib +import OAI.Probability.SKGap.Matrix.PolynomialCoeListSum + +namespace OAI + +section + +noncomputable section +open scoped BigOperators +namespace SKGap.Noncrossing +open Diagram InverseDiagram WordSeries +variable {ι : Type*} [Fintype ι] + +lemma mean_finset_sum {α : Type*} (s : Finset α) (f : α→ι→ℝ) : + Diagram.mean (fun i =>∑ a∈s,f a i)=∑ a∈s,Diagram.mean (f a) := by + simp only [Diagram.mean] + rw [Finset.sum_comm,Finset.sum_div] + +lemma ordinary_mean_noise_rotate (j : ℝ) (F : List (Letter (ι→ℝ))) : + Diagram.mean (ordinary j (.noise::F))=Diagram.mean (ordinary j (F++[.noise])) := by + have h1 := funext (expect_at j (id : (ι→ℝ)→ι→ℝ) [] F) + have h2 := funext (expect_at j (id : (ι→ℝ)→ι→ℝ) F []) + simp only [ordinary] + simp only [List.nil_append,List.append_nil,Fintype.sum_empty,zero_add,add_zero] at h1 h2 + rw [h1,h2,mean_finset_sum,mean_finset_sum] + apply Finset.sum_congr rfl + intro s _ + rw [mean_const_mul,mean_const_mul] + ring + +lemma ordinary_mean_cons_rotate (j : ℝ) (a : Letter (ι→ℝ)) (F : List (Letter (ι→ℝ))) : + Diagram.mean (ordinary j (a::F))=Diagram.mean (ordinary j (F++[a])) := by + cases a with + | noise => exact ordinary_mean_noise_rotate j F + | diag d => congr 1; funext i; simp [mul_comm] + +theorem ordinary_mean_cyclic (j : ℝ) (P Q : List (Letter (ι→ℝ))) : + Diagram.mean (ordinary j (P++Q))=Diagram.mean (ordinary j (Q++P)) := by + induction P generalizing Q with + | nil => simp + | cons a P ih => + rw [List.cons_append,ordinary_mean_cons_rotate,List.append_assoc,ih] + simp [List.append_assoc] + +lemma meanSeries_cyclic (j : ℝ) (a : ι→ℝ) (P Q : List (WordLetter ι)) : + meanSeries (literalSeries j a (P++Q))=meanSeries (literalSeries j a (Q++P)) := by + have hi : inverseCount (P++Q)=inverseCount (Q++P) := by simp [inverseCount_append,add_comm] + ext m + simp only [coeff_meanSeries] + by_cases h : inverseCount (P++Q)=0 + · have h' : inverseCount (Q++P)=0 := hi ▸ h + simp only [literalSeries,h,h',ite_true,PowerSeries.coeff_C] + by_cases hm : m=0 + · simp only [hm,ite_true] + simpa only [expandWord,List.flatMap_append] using + ordinary_mean_cyclic j (expandWord j a [] P) (expandWord j a [] Q) + · simp [hm,Diagram.mean] + · have h' : inverseCount (Q++P)≠0 := hi ▸ h + simp only [literalSeries,h,h',ite_false,PowerSeries.coeff_mk] + rw [mean_finset_sum,mean_finset_sum] + apply Finset.sum_congr rfl + intro bs _ + simpa only [expandWord,List.flatMap_append] using + ordinary_mean_cyclic j (expandWord j a bs.val P) (expandWord j a bs.val Q) + +theorem wordPrediction_mean_cyclic (j : ℝ) (a : ι→ℝ) (z : ℝ) + (P Q : List (WordLetter ι)) (hI : inverseCount (P++Q)≤1) : + (∑ i,wordPrediction j a z (P++Q) i)=(∑ i,wordPrediction j a z (Q++P) i) := by + classical + by_cases hn : Fintype.card ι=0 + · have : IsEmpty ι := Fintype.card_eq_zero_iff.mp hn + simp + have hc := meanSeries_cyclic j a P Q + have hI' : inverseCount (Q++P)≤1 := by simpa only [inverseCount_append,add_comm] using hI + unfold meanSeries at hc + simp_rw [literalSeries_eq_wordPredictionPolynomial j a (P++Q) hI, + literalSeries_eq_wordPredictionPolynomial j a (Q++P) hI'] at hc + have hmult : (PowerSeries.C ((Fintype.card ι:ℝ)⁻¹))≠0 := by + exact (map_ne_zero PowerSeries.C).mpr (inv_ne_zero (Nat.cast_ne_zero.mpr hn)) + have hs := mul_left_cancel₀ hmult hc + have hp : (∑ i,wordPredictionPolynomial j a (P++Q) i)= + ∑ i,wordPredictionPolynomial j a (Q++P) i := by + apply Polynomial.coe_injective ℝ + simpa only [polynomial_coe_finset_sum] using hs + have he := congrArg (Polynomial.eval z) hp + simpa only [Polynomial.eval_finsetSum,fun F i => (wordPredictionPolynomial_spec j a F i).2 z] using he +end SKGap.Noncrossing + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/DerivNonnegRightMin.lean b/lean/OAI/Probability/SKGap/Localization/DerivNonnegRightMin.lean new file mode 100644 index 0000000000000000000000000000000000000000..936ee20935a52cec7b69f413447c0b819ee41754 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/DerivNonnegRightMin.lean @@ -0,0 +1,306 @@ +import Mathlib +import OAI.Probability.SKGap.Model + +namespace OAI + +section +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open scoped BigOperators +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open scoped BigOperators +open scoped BigOperators NNReal ENNReal +open MeasureTheory Metric Set +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators NNReal ENNReal Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Set +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators ENNReal NNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Matrix +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators ENNReal NNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal +open scoped BigOperators +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise NNReal ENNReal +open scoped BigOperators +open Filter Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal Topology +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Set Matrix +open scoped BigOperators NNReal ENNReal Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open Filter MeasureTheory ProbabilityTheory +open scoped Topology NNReal ENNReal +open Filter MeasureTheory ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter +open scoped Topology NNReal ENNReal +open MeasureTheory Filter ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter +open scoped Topology +open MeasureTheory Filter ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter ProbabilityTheory ContinuousLinearMap +open scoped Topology NNReal ENNReal +open Filter MeasureTheory ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter +open scoped BigOperators Topology +open MeasureTheory Filter +open scoped BigOperators Topology +open MeasureTheory Filter +open scoped BigOperators Topology +open MeasureTheory Filter +open scoped BigOperators Topology +open MeasureTheory Filter +open scoped BigOperators Topology +open Filter Set Metric +open scoped Topology RealInnerProductSpace +namespace SKGapCutoff + +lemma deriv_nonneg_of_right_min {f : ℝ → ℝ} {d : ℝ} + (hd : HasDerivAt f d 0) (hmin : ∀ᶠ t in 𝓝[>] (0:ℝ), f 0 ≤ f t) : 0 ≤ d := by + apply ge_of_tendsto (hasDerivAt_iff_tendsto_slope_left_right.mp hd).2 + filter_upwards [hmin, self_mem_nhdsWithin] with t ht htpos + rw [slope_def_field] + exact div_nonneg (sub_nonneg.mpr ht) (sub_nonneg.mpr (le_of_lt htpos)) + +lemma hasDerivAt_norm_inverse_direction {E F : Type*} + [NormedAddCommGroup E] [NormedSpace ℝ E] + [NormedAddCommGroup F] [InnerProductSpace ℝ F] + {f : E → F} {A : E →L[ℝ] F} {z v : E} {y : F} + (hf : HasFDerivAt f A z) (hv : A v = y-f z) (hne : f z ≠ y) : + HasDerivAt (fun t : ℝ => ‖f (z+t • v)-y‖) (-‖f z-y‖) 0 := by + have hp : HasDerivAt (fun t : ℝ => z+t • v) v 0 := by + simpa using ((hasDerivAt_id (0:ℝ)).smul_const v).const_add z + have hcomp : HasDerivAt (fun t : ℝ => f (z+t • v)-y) (-(f z-y)) 0 := by + have hf' : HasFDerivAt f A (z+(0:ℝ) • v) := by simpa using hf + convert (hf'.comp_hasDerivAt 0 hp).sub_const y using 1 <;> simp [hv] + have hs := hcomp.norm_sq + have hb : 0 < ‖f z-y‖ := norm_pos_iff.mpr (sub_ne_zero.mpr hne) + have hs' : HasDerivAt (fun t : ℝ => ‖f (z+t • v)-y‖^2) + (-2*‖f z-y‖^2) 0 := by + simpa only [zero_smul, add_zero, inner_neg_right, real_inner_self_eq_norm_sq, mul_neg, neg_mul] using hs + have hh := hs'.sqrt (by simpa using (sq_pos_of_pos hb).ne') + convert hh using 1 + · funext t + exact (Real.sqrt_sq (norm_nonneg _)).symm + · simp only [zero_smul, add_zero, Real.sqrt_sq (norm_nonneg (f z-y))] + field_simp + +theorem ball_subset_image_of_uniform_right_inverse {E F : Type*} + [NormedAddCommGroup E] [NormedSpace ℝ E] [ProperSpace E] + [NormedAddCommGroup F] [InnerProductSpace ℝ F] + (f : E → F) (hf : Continuous f) (z₀ : E) {R a : ℝ} + (hR : 0 < R) (_ha : 0 < a) + (hder : ∀ z ∈ ball z₀ R, ∃ A : E →L[ℝ] F, + HasFDerivAt f A z ∧ ∀ w : F, ∃ v : E, A v = w ∧ a*‖v‖ ≤ ‖w‖) : + ball (f z₀) (a*R) ⊆ f '' ball z₀ R := by + intro y hy + have hd₀ : ‖f z₀-y‖ < a*R := by simpa [mem_ball, dist_eq_norm, norm_sub_rev] using hy + have hc₀ : ‖f z₀-y‖/R < a := (div_lt_iff₀ hR).mpr hd₀ + obtain ⟨c, hc₁, hc₂⟩ := exists_between hc₀ + have hc : 0 < c := (div_nonneg (norm_nonneg _) hR.le).trans_lt hc₁ + have hcR : ‖f z₀-y‖ < c*R := (div_lt_iff₀ hR).mp hc₁ + let ψ := fun z : E => ‖f z-y‖+c*‖z-z₀‖ + have hψ : Continuous ψ := by dsimp [ψ]; fun_prop + obtain ⟨z, hz, hmin⟩ := (isCompact_closedBall z₀ R).exists_isMinOn + (nonempty_closedBall.mpr hR.le) hψ.continuousOn + have hbound : ψ z ≤ ‖f z₀-y‖ := by + simpa [ψ] using hmin (mem_closedBall_self hR.le) + have hzR : z ∈ ball z₀ R := by + rw [mem_ball, dist_eq_norm] + apply (mul_lt_mul_iff_right₀ hc).mp + have hn := norm_nonneg (f z-y) + dsimp [ψ] at hbound + linarith + by_cases he : f z = y + · exact ⟨z, hzR, he⟩ + obtain ⟨A, hA, hsurj⟩ := hder z hzR + obtain ⟨v, hv, hvnorm⟩ := hsurj (y-f z) + rw [norm_sub_rev] at hvnorm + let η : ℝ → ℝ := fun t => ‖f (z+t • v)-y‖+c*(‖z-z₀‖+t*‖v‖) + have hη : HasDerivAt η (-‖f z-y‖+c*‖v‖) 0 := by + apply (hasDerivAt_norm_inverse_direction hA hv he).add + simpa using (((hasDerivAt_id (0:ℝ)).mul_const ‖v‖).const_add ‖z-z₀‖).const_mul c + have hloc : ∀ᶠ t in 𝓝 (0:ℝ), z+t • v ∈ closedBall z₀ R := by + have hc' : ContinuousAt (fun t : ℝ => z+t • v) 0 := by fun_prop + have hh := hc'.preimage_mem_nhds (isOpen_ball.mem_nhds (by simpa using hzR)) + filter_upwards [hh] with t ht + exact ball_subset_closedBall ht + have hminη : ∀ᶠ t in 𝓝[>] (0:ℝ), η 0 ≤ η t := by + filter_upwards [hloc.filter_mono nhdsWithin_le_nhds, self_mem_nhdsWithin] with t ht htpos + have hh := hmin ht + have htri : ‖z+t • v-z₀‖ ≤ ‖z-z₀‖+t*‖v‖ := by + calc + _ = ‖(z-z₀)+t • v‖ := by congr 1; abel + _ ≤ ‖z-z₀‖+‖t • v‖ := norm_add_le _ _ + _ = _ := by rw [norm_smul, Real.norm_eq_abs, abs_of_pos htpos] + dsimp [η] + simp only [zero_smul, add_zero, zero_mul] + exact hh.trans (add_le_add le_rfl (mul_le_mul_of_nonneg_left htri hc.le)) + have hnonneg := deriv_nonneg_of_right_min hη hminη + have hnormpos : 0 < ‖f z-y‖ := norm_pos_iff.mpr (sub_ne_zero.mpr he) + have hvpos : 0 < ‖v‖ := by + by_contra! h + have hv0 : v=0 := norm_eq_zero.mp (le_antisymm h (norm_nonneg _)) + simp [hv0] at hv + exact he (sub_eq_zero.mp hv.symm).symm + have hstrict : c*‖v‖ < a*‖v‖ := mul_lt_mul_of_pos_right hc₂ hvpos + linarith + +lemma injective_of_norm_lower {E F : Type*} + [NormedAddCommGroup E] [NormedSpace ℝ E] + [NormedAddCommGroup F] [NormedSpace ℝ F] + (A : E →L[ℝ] F) {a : ℝ} (ha : 0 < a) (hA : ∀ x, a*‖x‖ ≤ ‖A x‖) : + Function.Injective A := by + intro x y hxy + apply sub_eq_zero.mp + apply norm_eq_zero.mp + have hh := hA (x-y) + rw [map_sub, hxy, sub_self, norm_zero] at hh + nlinarith [norm_nonneg (x-y)] + +lemma exists_right_inverse_of_adjoint_lower {E : Type*} + [NormedAddCommGroup E] [InnerProductSpace ℝ E] [FiniteDimensional ℝ E] + (A : E →L[ℝ] E) {a : ℝ} (ha : 0 < a) + (hA : ∀ x, a*‖x‖ ≤ ‖A.adjoint x‖) : + ∀ w : E, ∃ v : E, A v = w ∧ a*‖v‖ ≤ ‖w‖ := by + have hBsurj : Function.Surjective A.adjoint := + (LinearMap.injective_iff_surjective (f := A.adjoint.toLinearMap)).mp + (injective_of_norm_lower A.adjoint ha hA) + have hAlower : ∀ x : E, a*‖x‖ ≤ ‖A x‖ := by + intro x + by_cases hx : x=0 + · simp [hx] + have hxpos : 0 < ‖x‖ := norm_pos_iff.mpr hx + obtain ⟨u, hu⟩ := hBsurj x + have hnorm : a*‖u‖ ≤ ‖x‖ := by simpa [hu] using hA u + have hi : ‖x‖^2 ≤ ‖A x‖*‖u‖ := by + calc + _ = ⟪x, A.adjoint u⟫ := by rw [hu, real_inner_self_eq_norm_sq] + _ = ⟪A x, u⟫ := A.adjoint_inner_right x u + _ ≤ _ := real_inner_le_norm _ _ + have hc : (a*‖x‖)*‖x‖ ≤ ‖A x‖*‖x‖ := by + calc + _ = a*(‖x‖^2) := by ring + _ ≤ a*(‖A x‖*‖u‖) := mul_le_mul_of_nonneg_left hi ha.le + _ = ‖A x‖*(a*‖u‖) := by ring + _ ≤ _ := mul_le_mul_of_nonneg_left hnorm (norm_nonneg _) + exact (mul_le_mul_iff_left₀ hxpos).mp hc + have hsurj : Function.Surjective A := + (LinearMap.injective_iff_surjective (f := A.toLinearMap)).mp + (injective_of_norm_lower A ha hAlower) + intro w + obtain ⟨v, hv⟩ := hsurj w + exact ⟨v, hv, hv ▸ hAlower v⟩ + +theorem ball_subset_image_of_adjoint_lower {E : Type*} + [NormedAddCommGroup E] [InnerProductSpace ℝ E] [FiniteDimensional ℝ E] + (f : E → E) (hf : Continuous f) (z₀ : E) {R a : ℝ} + (hR : 0 < R) (ha : 0 < a) + (hder : ∀ z ∈ ball z₀ R, ∃ A : E →L[ℝ] E, + HasFDerivAt f A z ∧ ∀ u : E, a*‖u‖ ≤ ‖A.adjoint u‖) : + ball (f z₀) (a*R) ⊆ f '' ball z₀ R := by + apply ball_subset_image_of_uniform_right_inverse f hf z₀ hR ha + intro z hz + obtain ⟨A, hA, hnorm⟩ := hder z hz + exact ⟨A, hA, exists_right_inverse_of_adjoint_lower A ha hnorm⟩ + +end SKGapCutoff + +open scoped BigOperators +open ContinuousLinearMap + +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/DiagonalHessianJoined.lean b/lean/OAI/Probability/SKGap/Localization/DiagonalHessianJoined.lean new file mode 100644 index 0000000000000000000000000000000000000000..e5c720da42618cfe28c79e05a68dca61a0219b0b --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/DiagonalHessianJoined.lean @@ -0,0 +1,201 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.ConditionalTolerance + +namespace OAI + +section +noncomputable section +namespace SKGap +open Matrix Real +open scoped MatrixOrder Matrix.Norms.L2Operator +variable {ι : Type*} [Fintype ι] [DecidableEq ι] + +lemma sqrt_half_holder {a b : ℝ} (ha : 0 ≤ a) (hb : 0 ≤ b) : + |sqrt a-sqrt b| ≤ sqrt |a-b| := by + have hsq : (sqrt a-sqrt b)^2 ≤ |a-b| := by + rcases le_total a b with hab | hab + · rw [abs_of_nonpos (sub_nonpos.mpr hab)] + have hp := mul_nonneg (sqrt_nonneg a) (sub_nonneg.mpr (sqrt_le_sqrt hab)) + nlinarith [sq_sqrt ha,sq_sqrt hb] + · rw [abs_of_nonneg (sub_nonneg.mpr hab)] + have hp := mul_nonneg (sqrt_nonneg b) (sub_nonneg.mpr (sqrt_le_sqrt hab)) + nlinarith [sq_sqrt ha,sq_sqrt hb] + simpa only [sqrt_sq_eq_abs] using sqrt_le_sqrt hsq + +def diagonalRoot (a : ι → ℝ) : Matrix ι ι ℝ := diagonal (fun i => sqrt (a i)) +def diagonalHessian (a : ι → ℝ) (K : Matrix ι ι ℝ) : Matrix ι ι ℝ := + 1-diagonalRoot a*K*diagonalRoot a + +lemma diagonalRoot_norm {a : ι → ℝ} {M : ℝ} (_hM : 0 ≤ M) (ha : ∀ i,a i ≤ M) : + ‖diagonalRoot a‖ ≤ sqrt M := by + rw [diagonalRoot,Matrix.l2_opNorm_diagonal] + exact (pi_norm_le_iff_of_nonneg (sqrt_nonneg M)).mpr + (fun i => by rw [Real.norm_eq_abs,abs_of_nonneg (sqrt_nonneg _)]; exact sqrt_le_sqrt (ha i)) + +lemma diagonalRoot_half_holder {a b : ι → ℝ} {ζ : ℝ} (_hζ : 0 ≤ ζ) + (ha : ∀ i,0 ≤ a i) (hb : ∀ i,0 ≤ b i) (hab : ∀ i,|a i-b i| ≤ ζ) : + ‖diagonalRoot a-diagonalRoot b‖ ≤ sqrt ζ := by + rw [diagonalRoot,diagonalRoot,Matrix.diagonal_sub,Matrix.l2_opNorm_diagonal] + exact (pi_norm_le_iff_of_nonneg (sqrt_nonneg ζ)).mpr (fun i => + (sqrt_half_holder (ha i) (hb i)).trans (sqrt_le_sqrt (hab i))) + +theorem diagonalHessian_half_holder {a b : ι → ℝ} {M ζ L : ℝ} + (hM : 0 ≤ M) (hζ : 0 ≤ ζ) (hL : 0 ≤ L) + (ha : ∀ i,a i ∈ Set.Icc 0 M) (hb : ∀ i,b i ∈ Set.Icc 0 M) + (hab : ∀ i,|a i-b i| ≤ ζ) (K : Matrix ι ι ℝ) (hK : ‖K‖ ≤ L) : + ‖diagonalHessian a K-diagonalHessian b K‖ ≤ 2*sqrt M*L*sqrt ζ := by + have hD := diagonalRoot_norm hM (fun i => (ha i).2) + have hE := diagonalRoot_norm hM (fun i => (hb i).2) + have hDE := diagonalRoot_half_holder hζ (fun i => (ha i).1) (fun i => (hb i).1) hab + have heq : diagonalHessian a K-diagonalHessian b K= + -((diagonalRoot a-diagonalRoot b)*K*diagonalRoot a+ + diagonalRoot b*K*(diagonalRoot a-diagonalRoot b)) := by + simp only [diagonalHessian,Matrix.sub_mul,Matrix.mul_sub] + abel + rw [heq,norm_neg] + apply (norm_add_le _ _).trans + apply (add_le_add (norm_mul_le _ _) (norm_mul_le _ _)).trans + have hb₁ : ‖(diagonalRoot a-diagonalRoot b)*K‖ ≤ sqrt ζ*L := + (norm_mul_le _ _).trans (mul_le_mul hDE hK (norm_nonneg _) (sqrt_nonneg _)) + have hb₂ : ‖diagonalRoot b*K‖ ≤ sqrt M*L := + (norm_mul_le _ _).trans (mul_le_mul hE hK (norm_nonneg _) (sqrt_nonneg _)) + apply (add_le_add (mul_le_mul hb₁ hD (norm_nonneg _) (by positivity)) + (mul_le_mul hb₂ hDE (norm_nonneg _) (by positivity))).trans_eq + ring + +lemma diagonalHessian_hermitian (a : ι → ℝ) {K : Matrix ι ι ℝ} (hK : K.IsHermitian) : + (diagonalHessian a K).IsHermitian := by + unfold diagonalHessian Matrix.IsHermitian + simp only [Matrix.conjTranspose_sub,Matrix.conjTranspose_one,Matrix.conjTranspose_mul, + diagonalRoot,Matrix.diagonal_conjTranspose,star_trivial,hK.eq] + simp only [Matrix.mul_assoc] + +lemma matrix_quadratic_op_bound (M : Matrix ι ι ℝ) (x : ι → ℝ) : + |x ⬝ᵥ (M*ᵥx)| ≤ ‖M‖*(x⬝ᵥx) := by + let y : EuclideanSpace ℝ ι := WithLp.toLp 2 x + have hh := abs_real_inner_le_norm y (M.toEuclideanLin.toContinuousLinearMap y) + have hn := M.toEuclideanLin.toContinuousLinearMap.le_opNorm y + have hin : inner ℝ y (M.toEuclideanLin.toContinuousLinearMap y)=x⬝ᵥ(M*ᵥx) := by + change (∑ i,(M*ᵥx) i*x i)=∑ i,x i*(M*ᵥx) i + apply Finset.sum_congr rfl; intro i _; ring + have hy : ‖y‖^2=x⬝ᵥx := by + rw [EuclideanSpace.real_norm_sq_eq] + simp only [y,dotProduct,pow_two] + rw [hin] at hh + calc + _ ≤ ‖y‖*‖M.toEuclideanLin.toContinuousLinearMap y‖ := hh + _ ≤ ‖y‖*(‖M‖*‖y‖) := mul_le_mul_of_nonneg_left hn (norm_nonneg _) + _ = _ := by rw [← hy]; ring + +theorem hermitian_margin_transfer {S T : Matrix ι ι ℝ} (hS : S.IsHermitian) + (_hT : T.IsHermitian) {c d : ℝ} (hd : ‖S-T‖ ≤ d) + (hc : (T-c • (1 : Matrix ι ι ℝ)).PosSemidef) : + (S-(c-d) • (1 : Matrix ι ι ℝ)).PosSemidef := by + refine Matrix.posSemidef_iff_dotProduct_mulVec.mpr ⟨?_,?_⟩ + · exact hS.sub (Matrix.isHermitian_one.smul (R := ℝ) (isSelfAdjoint_iff.mpr (star_trivial _))) + · intro x + have hq := matrix_quadratic_op_bound (S-T) x + have hp := hc.dotProduct_mulVec_nonneg x + have hxx : 0 ≤ x⬝ᵥx := Finset.sum_nonneg (fun i _ => mul_self_nonneg (x i)) + have hbd := mul_le_mul_of_nonneg_right hd hxx + simp only [star_trivial,Matrix.sub_mulVec,Matrix.smul_mulVec,Matrix.one_mulVec, + dotProduct_sub,dotProduct_smul,smul_eq_mul] at hp hq ⊢ + rcases abs_le.mp (hq.trans hbd) with ⟨hl,_⟩ + nlinarith only [hp,hl] +end SKGap +end +end + +section +noncomputable section +namespace SKGap +open Real Matrix MeasureTheory ProbabilityTheory Set +open scoped BigOperators Matrix.Norms.Frobenius + +def empiricalConditionalMiddle {n : ℕ} [NeZero n] (j t σ : ℝ) (y : Fin n → ℝ) + (g : MatrixCoordinates (Fin n) → ℝ) : Matrix (Fin n) (Fin n) ℝ := + let p : ScalarPoint := (empiricalLaw y,t,σ) + let q := scalarQMoment p.1 + let s := scalarS j p + let u := (empiricalUnit y q).ofLp + let X := (empiricalGramColumns y (scalarD j p) s 0).ofLp + let Z := sqrt s • (empiricalGramColumns y (scalarD j p) s 2).ofLp + conditionalBlockMatrix (j/(n:ℝ)) j q s (s+j*q) (scalarA j p) + (j*scalarBMoment p.1) (conditionalKappa j p) (conditionalEll j p) u Z g+ + j • vecMulVec X X+(2*j*q) • vecMulVec u u- + (j*scalarBMoment p.1) • (1 : Matrix (Fin n) (Fin n) ℝ) + +lemma empirical_columns_one {n : ℕ} (y : Fin n → ℝ) (d s : ℝ) {q : ℝ} + (hq : 0 < q) : sqrt q • (empiricalUnit y q).ofLp=(empiricalGramColumns y d s 1).ofLp := by + have hsq : sqrt q ≠ 0 := (sqrt_pos.mpr hq).ne' + ext i + simp only [empiricalUnit,empiricalGramColumns,gramCoordinates,WithLp.ofLp_toLp, + Pi.smul_apply,smul_eq_mul,Matrix.cons_val,sqrt_mul (Nat.cast_nonneg n)] + field_simp + +lemma empirical_columns_two {n : ℕ} (y : Fin n → ℝ) (d : ℝ) {s : ℝ} + (hs : 0 < s) : (sqrt s)⁻¹ • (sqrt s • (empiricalGramColumns y d s 2).ofLp)= + (empiricalGramColumns y d s 2).ofLp := by + rw [inv_smul_smul₀ (sqrt_pos.mpr hs).ne'] + +lemma empirical_columns_matrix {n : ℕ} (y : Fin n → ℝ) (d : ℝ) {q s : ℝ} + (hq : 0 < q) (hs : 0 < s) (N : Fin n → ℝ) : + conditionalColumns (empiricalGramColumns y d s 0).ofLp + (sqrt q • (empiricalUnit y q).ofLp) + ((sqrt s)⁻¹ • (sqrt s • (empiricalGramColumns y d s 2).ofLp)) N= + extendColumns (fun r=>(empiricalGramColumns y d s r).ofLp) N := by + rw [empirical_columns_one y d s hq,empirical_columns_two y d hs] + ext i k + cases k with + | inl k => fin_cases k <;> rfl + | inr k => rfl + +lemma pathDiagonal_one_eq_sqrt {n : ℕ} (a : Fin n → ℝ) : pathDiagonal a 1=diagonalRoot a := by + simp only [pathDiagonal,diagonalRoot,Real.sqrt_one,one_mul] + +lemma pathDiagonal_sq {n : ℕ} (a : Fin n → ℝ) (ha : ∀ i,0 ≤ a i) : + pathDiagonal a 1*pathDiagonal a 1=diagonal a := by + rw [pathDiagonal_one_eq_sqrt,diagonalRoot,Matrix.diagonal_mul_diagonal] + congr 1 + ext i + simp only [← pow_two,Real.sq_sqrt (ha i)] + +theorem conditionalEmpiricalCore_eq_hessian {n : ℕ} [NeZero n] (j t σ : ℝ) + (a y : Fin n → ℝ) (g : MatrixCoordinates (Fin n) → ℝ) + (ha : ∀ i,0 ≤ a i) (hq : 0 < scalarQMoment (empiricalLaw y)) + (hs : 0 < scalarS j (empiricalLaw y,t,σ)) (hBA : 0 < j/(n:ℝ)*∑ i,a i) : + conditionalEmpiricalCore j t σ a y g=diagonalHessian a (empiricalConditionalMiddle j t σ y g) := by + let p : ScalarPoint := (empiricalLaw y,t,σ) + let q := scalarQMoment p.1 + let s := scalarS j p + let B := j*scalarBMoment p.1 + let BA := j/(n:ℝ)*∑ i,a i + have hh := conditional_hessian_rank_form (j/(n:ℝ)) j (scalarA j p) B + (conditionalKappa j p) (conditionalEll j p) (q := q) (s := s) + (S := s+j*q) hq hs hBA + (empiricalGramColumns y (scalarD j p) s 0).ofLp + (empiricalUnit y q).ofLp + (sqrt s • (empiricalGramColumns y (scalarD j p) s 2).ofLp) + (pathDiagonal a 1) g + dsimp only at hh + rw [empirical_columns_matrix y (scalarD j p) hq hs,pathDiagonal_sq a ha] at hh + have hB : B+(BA-B)=BA := by ring + have hbil : goeBilinear (j/(n:ℝ)) (empiricalUnit y q).ofLp (empiricalUnit y q).ofLp g= + matrixBilinear (goeMatrix (j/(n:ℝ)) g) (empiricalUnit y q) (empiricalUnit y q) := by + rw [matrixBilinear_eq_pair] + rfl + rw [hbil] at hh + symm + convert hh using 1 + · simp only [diagonalHessian,empiricalConditionalMiddle,p,q,s,B,pathDiagonal_one_eq_sqrt, + Matrix.mul_add,Matrix.mul_sub,Matrix.add_mul,Matrix.sub_mul,Matrix.mul_smul, + Matrix.smul_mul,Matrix.mul_one] + abel + · simp only [conditionalEmpiricalCore,conditionalBase,conditionalUpdateColumns, + conditionalMeanData,conditionalScalarData,p,q,s,B,BA] at * + rw [hB] +end SKGap +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/DiagonalSqrt.lean b/lean/OAI/Probability/SKGap/Localization/DiagonalSqrt.lean new file mode 100644 index 0000000000000000000000000000000000000000..c32a2b7f63d9c5fa36b14fcf558d6ee767f6810d --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/DiagonalSqrt.lean @@ -0,0 +1,141 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.QuadraticCoeff + +namespace OAI + +section +noncomputable section +open MeasureTheory ProbabilityTheory InformationTheory Real Set +open scoped NNReal ENNReal +open Filter +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius ENNReal NNReal +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius NNReal +noncomputable section +open MeasureTheory ProbabilityTheory Real Set Filter +open MeasureTheory.Measure +open scoped ENNReal NNReal MeasureTheory Topology +open MeasureTheory +noncomputable section +noncomputable section +open MeasureTheory Set NormedSpace +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius +noncomputable section +open Set Real +open scoped Topology +noncomputable section +open Matrix Set Filter +open scoped Topology Matrix.Norms.Frobenius +noncomputable section +open Matrix NormedSpace ContinuousLinearMap +open scoped Matrix.Norms.Frobenius +noncomputable section +open Matrix +noncomputable section +open MeasureTheory ProbabilityTheory Real Set +open scoped ENNReal NNReal +noncomputable section +open MeasureTheory ProbabilityTheory InformationTheory Real Set +open scoped NNReal ENNReal +noncomputable section +open scoped BigOperators +open MeasureTheory ProbabilityTheory +namespace SKGap +section DiagonalGeometry +variable {ι : Type*} [Fintype ι] + +def diagonalSqrt (a : ι → ℝ) (p : EuclideanSpace ℝ ι) : EuclideanSpace ℝ ι := + WithLp.toLp 2 (fun i => Real.sqrt (a i) * p i) + +lemma diagonalSqrt_norm_sq (a : ι → ℝ) (ha : ∀ i, 0 ≤ a i) (p : EuclideanSpace ℝ ι) : + ‖diagonalSqrt a p‖^2 = ∑ i, a i * (p i)^2 := by + rw [EuclideanSpace.norm_sq_eq] + apply Finset.sum_congr rfl + intro i _ + simp only [diagonalSqrt, WithLp.ofLp_toLp, Real.norm_eq_abs, sq_abs, mul_pow, + Real.sq_sqrt (ha i)] + +lemma diagonalSqrt_norm_sq_le {a : ι → ℝ} {A : ℝ} + (ha : ∀ i, 0 ≤ a i) (hA : ∀ i, a i ≤ A) (p : EuclideanSpace ℝ ι) : + ‖diagonalSqrt a p‖^2 ≤ A * ‖p‖^2 := by + rw [diagonalSqrt_norm_sq a ha, ← sum_coord_sq, Finset.mul_sum] + exact Finset.sum_le_sum (fun i _ => mul_le_mul_of_nonneg_right (hA i) (sq_nonneg _)) + +lemma diagonalSqrt_norm_le_sqrt {a : ι → ℝ} {A : ℝ} + (ha : ∀ i, 0 ≤ a i) (hA0 : 0 ≤ A) (hA : ∀ i, a i ≤ A) + {p : EuclideanSpace ℝ ι} (hp : ‖p‖ ≤ 1) : + ‖diagonalSqrt a p‖ ≤ Real.sqrt A := by + have h := diagonalSqrt_norm_sq_le ha hA p + have hp2 : ‖p‖^2 ≤ 1 := by nlinarith [norm_nonneg p] + have hh := mul_le_mul_of_nonneg_left hp2 hA0 + have hs := Real.sq_sqrt hA0 + have hs0 := Real.sqrt_nonneg A + nlinarith [norm_nonneg (diagonalSqrt a p)] + +omit [Fintype ι] in +lemma continuous_diagonalSqrt (a : ι → ℝ) : Continuous (diagonalSqrt a) := by + apply (PiLp.continuous_toLp 2 (fun _ : ι => ℝ)).comp + exact continuous_pi (fun i => continuous_const.mul (PiLp.continuous_apply 2 (fun _ => ℝ) i)) + +lemma diagonal_sum_mul_le_norm (a : ι → ℝ) (p g : EuclideanSpace ℝ ι) : + (∑ i, diagonalSqrt a p i * g i) ≤ ‖p‖ * ‖diagonalSqrt a g‖ := by + have he : (∑ i, diagonalSqrt a p i * g i) = inner ℝ p (diagonalSqrt a g) := by + rw [PiLp.inner_apply] + apply Finset.sum_congr rfl + intro i _ + simp only [diagonalSqrt, WithLp.ofLp_toLp, RCLike.inner_apply, conj_trivial] + ring + rw [he] + exact real_inner_le_norm _ _ + +lemma quadraticCoeff_norm {r : ℝ} (hr : 0 ≤ r) (w : EuclideanSpace ℝ ι) : + ‖WithLp.toLp 2 (quadraticCoeff r w)‖ = Real.sqrt (2*r) * ‖w‖^2 := by + have hsum : (∑ k, (quadraticCoeff r w k)^2) = 2*r*‖w‖^4 := by + have h := quadraticCoeff_increment r hr w 0 + have h0 : quadraticCoeff r (0 : EuclideanSpace ℝ ι) = 0 := by + funext k + cases k <;> simp [quadraticCoeff] + simpa only [h0, Pi.zero_apply, sub_zero, norm_zero, zero_pow (by norm_num : (4 : ℕ) ≠ 0), + WithLp.ofLp_zero, zero_mul, mul_zero, Finset.sum_const_zero, zero_pow (by norm_num : (2 : ℕ) ≠ 0), + add_zero] using h + have he : ‖WithLp.toLp 2 (quadraticCoeff r w)‖^2 = + (Real.sqrt (2*r) * ‖w‖^2)^2 := by + rw [← sum_coord_sq, hsum, mul_pow, Real.sq_sqrt (by positivity)] + ring + have hnon : 0 ≤ Real.sqrt (2*r) * ‖w‖^2 := by positivity + nlinarith [norm_nonneg (WithLp.toLp 2 (quadraticCoeff r w))] + +end DiagonalGeometry + +lemma quadratic_margin {d b : ℝ} (_hd : 0 ≤ d) (hdb : d ≤ b) (hb : b ≤ 1) : + 2*d-d^2 ≤ 1-(1-b)^2 := by + nlinarith [mul_nonneg (sub_nonneg.mpr hdb) (show 0 ≤ 2-b-d by linarith)] + +end SKGap + +open Real + +end +end +end +end +end +end +end +end +end +end +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/DiagonalSum.lean b/lean/OAI/Probability/SKGap/Localization/DiagonalSum.lean new file mode 100644 index 0000000000000000000000000000000000000000..1041af10eb73539e4d3c09e8e512f3da70b80115 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/DiagonalSum.lean @@ -0,0 +1,232 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.UnitBall +import OAI.Probability.SKGap.Gaussian.GaussianProductUpperTailLipschitz + +namespace OAI + +section +noncomputable section +open MeasureTheory ProbabilityTheory InformationTheory Real Set +open scoped NNReal ENNReal +open Filter +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius ENNReal NNReal +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius NNReal +noncomputable section +open MeasureTheory ProbabilityTheory Real Set Filter +open MeasureTheory.Measure +open scoped ENNReal NNReal MeasureTheory Topology +open MeasureTheory +noncomputable section +noncomputable section +open MeasureTheory Set NormedSpace +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius +noncomputable section +open Set Real +open scoped Topology +noncomputable section +open Matrix Set Filter +open scoped Topology Matrix.Norms.Frobenius +noncomputable section +open Matrix NormedSpace ContinuousLinearMap +open scoped Matrix.Norms.Frobenius +noncomputable section +open Matrix +noncomputable section +open MeasureTheory ProbabilityTheory Real Set +open scoped ENNReal NNReal +noncomputable section +open MeasureTheory ProbabilityTheory InformationTheory Real Set +open scoped NNReal ENNReal +noncomputable section +open scoped BigOperators +open MeasureTheory ProbabilityTheory +open Real +noncomputable section +open scoped BigOperators Topology +open Filter Real +namespace SKGap +section MatrixScale +variable {ι : Type*} [Fintype ι] + +lemma diagonal_sum_le {a : ι → ℝ} {A : ℝ} (hA : ∀ i, a i ≤ A) : + (∑ i, a i) ≤ (Fintype.card ι : ℝ) * A := by + simpa only [Finset.sum_const, Finset.card_univ, nsmul_eq_mul] using + Finset.sum_le_sum (fun i (_ : i ∈ Finset.univ) => hA i) + +lemma diagonal_sq_sum_le {a : ι → ℝ} {A : ℝ} + (ha : ∀ i, 0 ≤ a i) (hA : ∀ i, a i ≤ A) : + (∑ i, (a i)^2) ≤ (Fintype.card ι : ℝ) * A^2 := + diagonal_sum_le (fun i => by nlinarith [ha i, hA i]) + +lemma scaled_mean_bound [Nonempty ι] {j A : ℝ} {a : ι → ℝ} + (hj : 0 ≤ j) (hA : ∀ i, a i ≤ A) : + (j / (Fintype.card ι : ℝ)) * (∑ i, a i) ≤ j*A := by + have hn : 0 < (Fintype.card ι : ℝ) := by exact_mod_cast Fintype.card_pos + have h := mul_le_mul_of_nonneg_left (diagonal_sum_le hA) (div_nonneg hj hn.le) + calc + _ ≤ _ := h + _ = _ := by field_simp + +lemma scaled_variance_bound [Nonempty ι] {j A : ℝ} {a : ι → ℝ} + (ha : ∀ i, 0 ≤ a i) (hA : ∀ i, a i ≤ A) : + 2*(j / (Fintype.card ι : ℝ))^2 * (∑ i, (a i)^2) ≤ + 2*j^2*A^2 / (Fintype.card ι : ℝ) := by + have hn : 0 < (Fintype.card ι : ℝ) := by exact_mod_cast Fintype.card_pos + have h := mul_le_mul_of_nonneg_left (diagonal_sq_sum_le ha hA) + (show 0 ≤ 2*(j / (Fintype.card ι : ℝ))^2 by positivity) + calc + _ ≤ _ := h + _ = _ := by field_simp + +lemma scaled_sqrt_mean_bound [Nonempty ι] {j A : ℝ} {a : ι → ℝ} + (hj : 0 ≤ j) (ha : ∀ i, 0 ≤ a i) (hA : ∀ i, a i ≤ A) (hA0 : 0 ≤ A) : + sqrt ((j / (Fintype.card ι : ℝ)) * (∑ i, a i)) * sqrt A ≤ sqrt j * A := by + have hn : 0 ≤ (Fintype.card ι : ℝ) := by positivity + have hq : 0 ≤ (j / (Fintype.card ι : ℝ)) * ∑ i, a i := + mul_nonneg (div_nonneg hj hn) (Finset.sum_nonneg (fun i _ => ha i)) + rw [← sqrt_mul hq] + calc + _ ≤ sqrt (j * A^2) := sqrt_le_sqrt (by + have h := mul_le_mul_of_nonneg_right (scaled_mean_bound hj hA) hA0 + nlinarith only [h]) + _ = sqrt j * A := by rw [sqrt_mul hj, sqrt_sq hA0] + +lemma subcritical_endpoint_margin {b : ℝ} (hb0 : 0 ≤ b) (hb1 : b ≤ 1) : + b^2 ≤ 1 - (1-b)^2/2 := by + nlinarith [mul_nonneg (sub_nonneg.mpr hb1) (show 0 ≤ 3*b+1 by positivity)] + +lemma scaled_qA_bound [Nonempty ι] {j A : ℝ} {a : ι → ℝ} + (hj : 0 ≤ j) (hA : ∀ i, a i ≤ A) (hA0 : 0 ≤ A) + (hsub : sqrt j * A ≤ 1) : + ((j / (Fintype.card ι : ℝ)) * (∑ i, a i))*A ≤ + 1-(1-sqrt j*A)^2/2 := by + have h := mul_le_mul_of_nonneg_right (scaled_mean_bound hj hA) hA0 + have hm := subcritical_endpoint_margin (show 0 ≤ sqrt j*A by positivity) hsub + have he : (sqrt j*A)^2 = j*A^2 := by rw [mul_pow, sq_sqrt hj] + rw [he] at hm + nlinarith only [h, hm] + +end MatrixScale + +lemma diagonal_error_tendsto (j A : ℝ) : + Tendsto (fun n : ℕ => 2*sqrt A * sqrt (sqrt (2*j^2*A^2/(n:ℝ)))) atTop (𝓝 0) := by + have hd : Tendsto (fun n : ℕ => 2*j^2*A^2/(n:ℝ)) atTop (𝓝 0) := + tendsto_const_div_atTop_nhds_zero_nat (2*j^2*A^2) + simpa only [sqrt_zero, mul_zero, Function.comp_def] using + (tendsto_const_nhds.mul (Real.continuous_sqrt.continuousAt.tendsto.comp + (Real.continuous_sqrt.continuousAt.tendsto.comp hd))) + +end SKGap + +namespace SKGap +section DiagonalProbability +open MeasureTheory ProbabilityTheory Real Set Filter +variable {ι : Type*} [Fintype ι] [Nonempty ι] + +lemma scaled_diagonal_expected_margin {j A : ℝ} {a : ι → ℝ} + (hj : 0 ≤ j) (ha : ∀ i, 0 ≤ a i) (hA : ∀ i, a i ≤ A) (hA0 : 0 ≤ A) + (hsub : sqrt j*A ≤ 1) : + (∫ g, diagonalProcess (j/(Fintype.card ι:ℝ)) a 1 + ((j/(Fintype.card ι:ℝ))*∑ i, a i) g + ∂gaussianCoordinates (MatrixCoordinates ι)) ≤ + 1-(1-sqrt j*A)^2 + + 2*sqrt A*sqrt (sqrt (2*j^2*A^2/(Fintype.card ι:ℝ))) := by + have h := diagonalProcess_expected_margin (div_nonneg hj (by positivity)) ha hA hA0 + (by norm_num : (0:ℝ) ≤ 1) le_rfl (scaled_sqrt_mean_bound hj ha hA hA0) hsub + exact h.trans (add_le_add_right + (mul_le_mul_of_nonneg_left (sqrt_le_sqrt (sqrt_le_sqrt + (scaled_variance_bound (j := j) ha hA))) (show 0 ≤ 2*sqrt A by positivity)) _) + +theorem scaled_diagonal_path_tail {j A : ℝ} {a : ι → ℝ} + (hj : 0 < j) (hA0 : 0 < A) (ha : ∀ i, 0 ≤ a i) (hA : ∀ i, a i ≤ A) + (hsub : sqrt j*A < 1) + (herr : 2*sqrt A*sqrt (sqrt (2*j^2*A^2/(Fintype.card ι:ℝ))) ≤ + (1-sqrt j*A)^2/4) : + (gaussianCoordinates (MatrixCoordinates ι)).real + {g | ∃ z ∈ Icc (0:ℝ) 1, + 1-(1-sqrt j*A)^2/2 < diagonalProcess (j/(Fintype.card ι:ℝ)) a z + ((j/(Fintype.card ι:ℝ))*∑ i, a i) g} ≤ + Real.exp (-((1-sqrt j*A)^2)^2 * (Fintype.card ι:ℝ) / (16*π^2*j*A^2)) := by + let r := j/(Fintype.card ι:ℝ) + let q := r*∑ i, a i + let δ := (1-sqrt j*A)^2 + let c := 1-δ/2 + let P := diagonalProcess r a 1 q + have hn : 0 < (Fintype.card ι:ℝ) := by exact_mod_cast Fintype.card_pos + have hr : 0 < r := div_pos hj hn + have hq : 0 ≤ q := mul_nonneg hr.le (Finset.sum_nonneg (fun i _ => ha i)) + have hd : 0 < δ := sq_pos_of_pos (sub_pos.mpr hsub) + have hd1 : δ ≤ 1 := by + dsimp [δ] + have hb : 0 ≤ sqrt j*A := by positivity + nlinarith + have hc : 0 ≤ c := by dsimp [c]; linarith + have hqc : q*A ≤ c := scaled_qA_bound hj.le hA hA0.le hsub.le + have hmean : (∫ g, P g ∂gaussianCoordinates (MatrixCoordinates ι)) ≤ 1-3*δ/4 := by + have h := scaled_diagonal_expected_margin hj.le ha hA hA0.le hsub.le + change (∫ g, P g ∂gaussianCoordinates (MatrixCoordinates ι)) ≤ 1-δ+_ at h + change _ ≤ δ/4 at herr + linarith + have hlip := diagonalProcess_lipschitz hr.le ha hA hA0.le (by norm_num : (0:ℝ) ≤ 1) q + have hL : 0 < Real.toNNReal (1*sqrt (2*r)*A) := by + rw [Real.toNNReal_pos] + positivity + have htail := gaussianProduct_upper_tail_lipschitz hlip hL (show 0 ≤ δ/4 by positivity) + have hset : {g | ∃ z ∈ Icc (0:ℝ) 1, c < diagonalProcess r a z q g} ⊆ + {g | δ/4 ≤ P g - ∫ y, P y ∂gaussianCoordinates (MatrixCoordinates ι)} := by + rintro g ⟨z, hz, hg⟩ + have hgc : c < P g := by + by_contra h + have hpath := diagonalProcess_path_le ha hA hA0.le hq hc hqc + (le_of_not_gt h) hz.1 hz.2 + exact (not_lt_of_ge hpath) hg + change δ/4 ≤ _ + dsimp [c] at hgc + linarith + refine (measureReal_mono hset).trans (htail.trans_eq ?_) + congr 1 + rw [Real.coe_toNNReal _ (by positivity)] + have hs : (sqrt (2*r))^2 = 2*r := sq_sqrt (by positivity) + simp only [one_mul] + rw [mul_pow, hs] + dsimp [δ, r] + field_simp + ring + +theorem exists_uniform_diagonal_cutoff {j A : ℝ} (hsub : sqrt j*A < 1) : + ∃ n₀ : ℕ, ∀ n ≥ n₀, + 2*sqrt A*sqrt (sqrt (2*j^2*A^2/(n:ℝ))) ≤ (1-sqrt j*A)^2/4 := by + have hpos : 0 < (1-sqrt j*A)^2/4 := by positivity + have h := (diagonal_error_tendsto j A).eventually (gt_mem_nhds hpos) + obtain ⟨n₀, hn⟩ := eventually_atTop.mp h + exact ⟨n₀, fun n hn' => (hn n hn').le⟩ + +end DiagonalProbability +end SKGap + +end +end +end +end +end +end +end +end +end +end +end +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/DiagonalTMemLp.lean b/lean/OAI/Probability/SKGap/Localization/DiagonalTMemLp.lean new file mode 100644 index 0000000000000000000000000000000000000000..a8a5e98f2c36bb11fdac1da6708c97d0112dd4ef --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/DiagonalTMemLp.lean @@ -0,0 +1,179 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.UnitBall +import OAI.Probability.SKGap.Gaussian.GaussianProductUpperTailLipschitz + +namespace OAI + +section +noncomputable section +open MeasureTheory ProbabilityTheory InformationTheory Real Set +open scoped NNReal ENNReal +open Filter +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius ENNReal NNReal +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius NNReal +noncomputable section +open MeasureTheory ProbabilityTheory Real Set Filter +open MeasureTheory.Measure +open scoped ENNReal NNReal MeasureTheory Topology +open MeasureTheory +noncomputable section +noncomputable section +open MeasureTheory Set NormedSpace +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius +noncomputable section +open Set Real +open scoped Topology +noncomputable section +open Matrix Set Filter +open scoped Topology Matrix.Norms.Frobenius +noncomputable section +open Matrix NormedSpace ContinuousLinearMap +open scoped Matrix.Norms.Frobenius +noncomputable section +open Matrix +noncomputable section +open MeasureTheory ProbabilityTheory Real Set +open scoped ENNReal NNReal +noncomputable section +open MeasureTheory ProbabilityTheory InformationTheory Real Set +open scoped NNReal ENNReal +noncomputable section +open scoped BigOperators +open MeasureTheory ProbabilityTheory +open Real +noncomputable section +open scoped BigOperators Topology +open Filter Real +namespace SKGap +section GOEProbability +variable {ι : Type*} [Fintype ι] [Nonempty ι] + +omit [Nonempty ι] in +lemma diagonalT_memLp {r : ℝ} (hr : 0 ≤ r) {a : ι → ℝ} (ha : ∀ i, 0 ≤ a i) : + MemLp (diagonalT r a) 2 (gaussianCoordinates (MatrixCoordinates ι)) := by + apply memLp_sqrt_of_nonneg ((gaussianQuadratic_memLp (diagonalWeights r a)).integrable + (by norm_num)) + intro g + apply Finset.sum_nonneg + intro k _ + apply mul_nonneg _ (sq_nonneg _) + cases k <;> simp only [diagonalWeights] + · exact le_rfl + · exact mul_nonneg hr (ha _) + +omit [Nonempty ι] in +lemma diagonalT_mean_le {r : ℝ} (hr : 0 ≤ r) {a : ι → ℝ} (ha : ∀ i, 0 ≤ a i) : + (∫ g, diagonalT r a g ∂gaussianCoordinates (MatrixCoordinates ι)) ≤ + sqrt (r * ∑ i, a i) := by + have he (g : MatrixCoordinates ι → ℝ) : (diagonalT r a g)^2 = + gaussianQuadratic (diagonalWeights r a) g := by + apply sq_sqrt + apply Finset.sum_nonneg + intro k _ + apply mul_nonneg _ (sq_nonneg _) + cases k <;> simp only [diagonalWeights] + · exact le_rfl + · exact mul_nonneg hr (ha _) + have h := integral_abs_le_sqrt_sq (diagonalT_memLp hr ha) + simp_rw [he, abs_of_nonneg (show 0 ≤ diagonalT r a _ from sqrt_nonneg _)] at h + have hm : (∫ g, gaussianQuadratic (diagonalWeights r a) g + ∂gaussianCoordinates (MatrixCoordinates ι)) = r * ∑ i, a i := by + simpa only [gaussianCoordinates, diagonalWeights_sum] using gaussianQuadratic_mean (diagonalWeights r a) + rwa [hm] at h + +theorem goe_expected_top {j : ℝ} (hj : 0 ≤ j) : + (∫ g, diagonalProcess (j/(Fintype.card ι:ℝ)) (fun _ : ι => 1) 1 0 g + ∂gaussianCoordinates (MatrixCoordinates ι)) ≤ 2*sqrt j := by + let r := j/(Fintype.card ι:ℝ) + let a : ι → ℝ := fun _ => 1 + have hr : 0 ≤ r := div_nonneg hj (by positivity) + have ha : ∀ i, 0 ≤ a i := by intro; norm_num [a] + have hc := gaussian_quadraticSup_comparison (continuous_diagonalOffset a 1 0) + ((continuous_diagonalSqrt a).comp continuous_subtype_val) hr 1 + change (∫ g, diagonalProcess r a 1 0 g ∂gaussianCoordinates (MatrixCoordinates ι)) ≤ + (∫ g, diagonalLinearProcess r a 1 0 g ∂gaussianCoordinates (MatrixCoordinates ι)) at hc + have hb (g) : diagonalLinearProcess r a 1 0 g ≤ 2*diagonalT r a g := by + have h := diagonalLinearProcess_le (A := 1) (b := 0) hr ha + (by intro; exact le_rfl) zero_le_one (by norm_num : (0:ℝ) ≤ 1) le_rfl + le_rfl (by norm_num) zero_le_one g + simpa only [sub_zero, one_pow, sub_self, sqrt_zero, sqrt_one, mul_one, + abs_of_nonneg (show 0 ≤ diagonalT r a g from sqrt_nonneg _), zero_add] using h + have hi := diagonalT_integrable hr ha + calc + _ ≤ ∫ g, diagonalLinearProcess r a 1 0 g + ∂gaussianCoordinates (MatrixCoordinates ι) := hc + _ ≤ ∫ g, 2*diagonalT r a g ∂gaussianCoordinates (MatrixCoordinates ι) := + integral_mono (integrable_diagonalLinearProcess r a 1 0) (hi.const_mul 2) hb + _ = 2 * ∫ g, diagonalT r a g ∂gaussianCoordinates (MatrixCoordinates ι) := + integral_const_mul _ _ + _ ≤ 2*sqrt (r * ∑ i, a i) := mul_le_mul_of_nonneg_left (diagonalT_mean_le hr ha) (by norm_num) + _ = 2*sqrt j := by + have hn : (Fintype.card ι:ℝ) ≠ 0 := by exact_mod_cast Fintype.card_ne_zero + simp [a, r, hn] + +lemma gaussianCoordinates_preserving_neg {κ : Type*} [Fintype κ] : + MeasurePreserving (fun g : κ → ℝ => -g) (gaussianCoordinates κ) + (gaussianCoordinates κ) := by + apply measurePreserving_pi (f := fun _ => fun x : ℝ => -x) + (fun _ => gaussianReal 0 1) (fun _ => gaussianReal 0 1) + intro i + exact ⟨by fun_prop, by simpa using (gaussianReal_map_neg (μ := 0) (v := 1))⟩ + +theorem goe_top_tail {j ε : ℝ} (hj : 0 < j) (hε : 0 ≤ ε) : + (gaussianCoordinates (MatrixCoordinates ι)).real + {g | 2*sqrt j+ε < diagonalProcess (j/(Fintype.card ι:ℝ)) (fun _ : ι => 1) 1 0 g} ≤ + Real.exp (-ε^2*(Fintype.card ι:ℝ)/(π^2*j)) := by + let r := j/(Fintype.card ι:ℝ) + let P := diagonalProcess r (fun _ : ι => 1) 1 0 + have hn : 0 < (Fintype.card ι:ℝ) := by exact_mod_cast Fintype.card_pos + have hr : 0 < r := div_pos hj hn + have hL := diagonalProcess_lipschitz (a := fun _ : ι => 1) hr.le (fun _ => zero_le_one) + (fun _ => le_rfl) zero_le_one (by norm_num : (0:ℝ) ≤ 1) 0 + have hLp : 0 < Real.toNNReal (1*sqrt (2*r)*1) := by + rw [Real.toNNReal_pos]; positivity + have ht := gaussianProduct_upper_tail_lipschitz hL hLp hε + have hm := goe_expected_top (ι := ι) hj.le + have hs : {g | 2*sqrt j+ε < P g} ⊆ + {g | ε ≤ P g - ∫ g, P g ∂gaussianCoordinates (MatrixCoordinates ι)} := by + intro g hg + change ε ≤ P g - ∫ g, P g ∂gaussianCoordinates (MatrixCoordinates ι) + change _ < P g at hg + change (∫ g, P g ∂gaussianCoordinates (MatrixCoordinates ι)) ≤ 2*sqrt j at hm + linarith + exact (measureReal_mono hs).trans (ht.trans_eq (by + congr 1 + rw [Real.coe_toNNReal _ (by positivity)] + simp only [one_mul, mul_one] + rw [sq_sqrt (by positivity)] + dsimp [r] + field_simp)) + +end GOEProbability +end SKGap + +end +end +end +end +end +end +end +end +end +end +end +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/DimensionDecay.lean b/lean/OAI/Probability/SKGap/Localization/DimensionDecay.lean new file mode 100644 index 0000000000000000000000000000000000000000..0f03b3841237ce3bd10f61e01ad9903730cd33fd --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/DimensionDecay.lean @@ -0,0 +1,196 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.Magnetization + +namespace OAI + +section +open scoped BigOperators +namespace SKGapCutoff +open Filter Topology + +noncomputable def dimensionDecay (a : ℝ) (n : ℕ) : ℝ := + Real.exp (-a * Real.log (n : ℝ)) + +lemma dimensionDecay_tendsto (a : ℝ) (ha : 0 < a) : + Tendsto (dimensionDecay a) atTop (nhds 0) := by + have hlog : Tendsto (fun n : ℕ => Real.log (n : ℝ)) atTop atTop := + Real.tendsto_log_atTop.comp tendsto_natCast_atTop_atTop + have hneg := tendsto_neg_atTop_atBot.comp (hlog.const_mul_atTop ha) + change Tendsto (fun n : ℕ => Real.exp (-a * Real.log (n : ℝ))) atTop (nhds 0) + simpa only [Function.comp_def, neg_mul] using Real.tendsto_exp_atBot.comp hneg + +lemma dimensionDecay_upper_tendsto (a : ℝ) (ha : 0 < a) : + Tendsto (fun n => Real.sqrt (Real.exp (dimensionDecay a n) - 1) / 2) + atTop (nhds 0) := by + have hexp := (Real.continuous_exp.tendsto 0).comp (dimensionDecay_tendsto a ha) + have h := ((hexp.sub (tendsto_const_nhds (x := (1 : ℝ)))).sqrt).div_const (2 : ℝ) + simpa using h + +lemma mul_exp_log_identity {n : ℕ} (hn : 0 < n) (a : ℝ) : + (n : ℝ) * Real.exp (-(1 + a) * Real.log (n : ℝ)) = dimensionDecay a n := by + have hn' : (0 : ℝ) < n := by exact_mod_cast hn + calc + _ = Real.exp (Real.log (n : ℝ)) * Real.exp (-(1 + a) * Real.log (n : ℝ)) := by + rw [Real.exp_log hn'] + _ = _ := by rw [← Real.exp_add]; unfold dimensionDecay; congr 1; ring + +lemma exp_log_div_identity {n : ℕ} (hn : 0 < n) (a : ℝ) : + Real.exp ((1 - a) * Real.log (n : ℝ)) / (n : ℝ) = dimensionDecay a n := by + have hn' : (0 : ℝ) < n := by exact_mod_cast hn + calc + _ = Real.exp ((1 - a) * Real.log (n : ℝ)) / Real.exp (Real.log (n : ℝ)) := by + rw [Real.exp_log hn'] + _ = _ := by rw [← Real.exp_sub]; unfold dimensionDecay; congr 1; ring + +lemma cutoffTime_one (n : ℕ) : cutoffTime 1 n = Real.log (n : ℝ) / 2 := by + simp [cutoffTime] + +lemma cutoffTime_one_nonneg {n : ℕ} (hn : 0 < n) : 0 ≤ cutoffTime 1 n := by + rw [cutoffTime_one] + exact div_nonneg (Real.log_nonneg (by exact_mod_cast hn)) (by norm_num) + +lemma tendsto_one_of_error (f e : ℕ → ℝ) (he : Tendsto e atTop (nhds 0)) + (hup : ∀ᶠ n in atTop, f n ≤ 1) (hlo : ∀ᶠ n in atTop, 1 - e n ≤ f n) : + Tendsto f atTop (nhds 1) := by + have hz : Tendsto (fun n => 1 - f n) atTop (nhds 0) := + squeeze_zero' (hup.mono (fun _ h => by linarith)) + (hlo.mono (fun _ h => by linarith)) he + have h := (tendsto_const_nhds (x := (1 : ℝ))).sub hz + simpa using h + +lemma continuous_zero_cutoff_upper (ε : ℝ) (hε : 0 < ε) : + Tendsto (fun n => worstContinuous (0 : Interaction n) ((1 + ε) * cutoffTime 1 n)) + atTop (nhds 0) := by + apply squeeze_zero (fun n => worstContinuous_nonneg _ _) + (fun n => ?_) (dimensionDecay_upper_tendsto ε hε) + by_cases hn : 0 < n + · have h := worstContinuous_zero_upper (n := n) ((1 + ε) * cutoffTime 1 n) + have he : (n : ℝ) * Real.exp (-2 * ((1 + ε) * cutoffTime 1 n)) = + dimensionDecay ε n := by + rw [cutoffTime_one] + convert mul_exp_log_identity hn ε using 2; congr 1; ring + simpa only [he] using h + · have hn0 : n = 0 := by omega + subst n + have hup := worstContinuous_zero_upper (n := 0) ((1 + ε) * cutoffTime 1 0) + simp only [Nat.cast_zero, zero_mul, Real.exp_zero, sub_self, Real.sqrt_zero, + zero_div] at hup + exact hup.trans (by positivity) + +lemma continuous_zero_cutoff_lower (ε : ℝ) (hε : 0 < ε) (hε1 : ε < 1) : + Tendsto (fun n => worstContinuous (0 : Interaction n) ((1 - ε) * cutoffTime 1 n)) + atTop (nhds 1) := by + apply tendsto_one_of_error _ (fun n => 8 * dimensionDecay ε n) + (by simpa using (dimensionDecay_tendsto ε hε).const_mul 8) + · filter_upwards [eventually_gt_atTop 0] with n hn + exact worstContinuous_le_one _ _ + (mul_nonneg (by linarith) (cutoffTime_one_nonneg hn)) + · filter_upwards [eventually_gt_atTop 0] with n hn + have h := worstContinuous_zero_lower hn ((1 - ε) * cutoffTime 1 n) + (mul_nonneg (by linarith) (cutoffTime_one_nonneg hn)) + have he : 8 * Real.exp (2 * ((1 - ε) * cutoffTime 1 n)) / (n : ℝ) = + 8 * dimensionDecay ε n := by + rw [mul_div_assoc, ← exp_log_div_identity hn ε, cutoffTime_one] + congr 2 + ring_nf + simpa only [he] using h + +@[simp] lemma sampledInteraction_zero (n : ℕ) : + sampledInteraction (0 : GaussianCoordinates n) = (0 : Interaction n) := by + funext i j + simp [sampledInteraction] + +lemma disorderLaw_zero (n : ℕ) : disorderLaw 0 n = + MeasureTheory.Measure.dirac (0 : GaussianCoordinates n) := by + unfold disorderLaw + simp only [zero_pow (by norm_num : 2 ≠ 0), zero_div, Real.toNNReal_zero, + ProbabilityTheory.gaussianReal_zero_var] + apply MeasureTheory.Measure.pi_eq + intro s _ + simp only [MeasureTheory.Measure.dirac_apply, Set.indicator, Pi.one_apply, + Pi.zero_apply, Set.mem_univ_pi] + have hm : (0 : GaussianCoordinates n) ∈ Set.univ.pi s ↔ + ∀ i : Fin n × Fin n, (0 : ℝ) ∈ s i := Set.mem_univ_pi + by_cases h : (0 : GaussianCoordinates n) ∈ Set.univ.pi s + · simp only [ite_eq_left h] + symm + exact Finset.prod_eq_one (fun i _ => ite_eq_left ((hm.mp h) i)) + · simp only [ite_eq_right h] + symm + obtain ⟨i, hi⟩ := not_forall.mp (fun hforall => h (hm.mpr hforall)) + exact Finset.prod_eq_zero (Finset.mem_univ i) (by simp [hi]) + +lemma disorderLimit_zero_of_tendsto (F : (n : ℕ) → Interaction n → ℝ) (a : ℝ) + (h : Tendsto (fun n => F n 0) atTop (nhds a)) : DisorderLimit 0 F a := by + intro δ hδ + have habs : Tendsto (fun n => |F n 0 - a|) atTop (nhds 0) := by + simpa using (h.sub (tendsto_const_nhds (x := a))).abs + have hlt := habs.eventually_lt_const hδ + have he : (fun n => (disorderLaw 0 n) + {g | δ < |F n (sampledInteraction g) - a|}) =ᶠ[atTop] (fun _ => 0) := by + filter_upwards [hlt] with n hn + rw [disorderLaw_zero, MeasureTheory.Measure.dirac_apply] + simp [Set.indicator, not_lt.mpr hn.le] + exact (tendsto_congr' he).mpr tendsto_const_nhds + +lemma discrete_zero_cutoff_upper (ε : ℝ) (hε : 0 < ε) : + Tendsto (fun n => worstDiscrete (0 : Interaction n) + ⌈(1 + ε) * (n : ℝ) * cutoffTime 1 n⌉₊) atTop (nhds 0) := by + apply squeeze_zero' (Eventually.of_forall (fun n => worstDiscrete_nonneg _ _)) + _ (dimensionDecay_upper_tendsto ε hε) + filter_upwards [eventually_gt_atTop 0] with n hn + have hn' : (0 : ℝ) < n := by exact_mod_cast hn + let k := ⌈(1 + ε) * (n : ℝ) * cutoffTime 1 n⌉₊ + have hceil : (1 + ε) * (n : ℝ) * (Real.log (n : ℝ) / 2) ≤ (k : ℝ) := by + simpa only [k, cutoffTime_one] using Nat.le_ceil ((1 + ε) * (n : ℝ) * cutoffTime 1 n) + have hr : -2 * (k : ℝ) / (n : ℝ) ≤ -(1 + ε) * Real.log (n : ℝ) := by + apply (div_le_iff₀ hn').mpr + nlinarith only [hceil] + have hq : (n : ℝ) * Real.exp (-2 * (k : ℝ) / n) ≤ dimensionDecay ε n := by + rw [← mul_exp_log_identity hn ε] + exact mul_le_mul_of_nonneg_left (Real.exp_le_exp.mpr hr) hn'.le + apply (worstDiscrete_zero_upper hn k).trans + gcongr + +lemma discrete_zero_cutoff_lower (ε : ℝ) (hε : 0 < ε) (hε1 : ε < 1) : + Tendsto (fun n => worstDiscrete (0 : Interaction n) + ⌊(1 - ε) * (n : ℝ) * cutoffTime 1 n⌋₊) atTop (nhds 1) := by + apply tendsto_one_of_error _ (fun n => 8 * dimensionDecay (ε / 2) n) + (by simpa using (dimensionDecay_tendsto (ε / 2) (by positivity)).const_mul 8) + (Eventually.of_forall (fun n => worstDiscrete_le_one _ _)) + have hlarge : ∀ᶠ n : ℕ in atTop, 1 ≤ (ε / 2) * (n : ℝ) := + ((tendsto_natCast_atTop_atTop : Tendsto (fun n : ℕ => (n : ℝ)) atTop atTop).const_mul_atTop + (by positivity : 0 < ε / 2)).eventually (eventually_ge_atTop 1) + filter_upwards [eventually_ge_atTop 2, hlarge] with n hn hlargeN + have hn0 : 0 < n := by omega + have hn' : (1 : ℝ) < n := by exact_mod_cast (show 1 < n by omega) + have hs : 0 < (n : ℝ) - 1 := by linarith + have hlog : 0 ≤ Real.log (n : ℝ) := Real.log_nonneg (by linarith) + let k := ⌊(1 - ε) * (n : ℝ) * cutoffTime 1 n⌋₊ + have hfloor : (k : ℝ) ≤ (1 - ε) * (n : ℝ) * (Real.log (n : ℝ) / 2) := by + rw [← cutoffTime_one] + exact Nat.floor_le (mul_nonneg (mul_nonneg (by linarith) (Nat.cast_nonneg n)) + (cutoffTime_one_nonneg hn0)) + have hc : (1 - ε) * (n : ℝ) ≤ (1 - ε / 2) * ((n : ℝ) - 1) := by + nlinarith only [hlargeN, hε] + have hr : 2 * (k : ℝ) / ((n : ℝ) - 1) ≤ (1 - ε / 2) * Real.log (n : ℝ) := by + apply (div_le_iff₀ hs).mpr + nlinarith only [hfloor, mul_le_mul_of_nonneg_right hc hlog] + have he : 8 * Real.exp (2 * (k : ℝ) / ((n : ℝ) - 1)) / (n : ℝ) ≤ + 8 * dimensionDecay (ε / 2) n := by + rw [← exp_log_div_identity hn0 (ε / 2), ← mul_div_assoc] + gcongr + exact (sub_le_sub_left he 1).trans (worstDiscrete_zero_lower hn k) + +theorem beta_zero_cutoff : CutoffAtRate 0 1 := by + intro ε hε hε1 + exact ⟨disorderLimit_zero_of_tendsto _ _ (continuous_zero_cutoff_lower ε hε hε1), + disorderLimit_zero_of_tendsto _ _ (continuous_zero_cutoff_upper ε hε), + disorderLimit_zero_of_tendsto _ _ (discrete_zero_cutoff_lower ε hε hε1), + disorderLimit_zero_of_tendsto _ _ (discrete_zero_cutoff_upper ε hε)⟩ + +end SKGapCutoff + +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/DimensionDecayPos.lean b/lean/OAI/Probability/SKGap/Localization/DimensionDecayPos.lean new file mode 100644 index 0000000000000000000000000000000000000000..2a4dc796f9f5a37e9d8e1315a2bc250a92e023bd --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/DimensionDecayPos.lean @@ -0,0 +1,215 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.DimensionDecay + +namespace OAI + +section +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open scoped BigOperators +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open scoped BigOperators +open scoped BigOperators NNReal ENNReal +open MeasureTheory Metric Set +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators NNReal ENNReal Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Set +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators ENNReal NNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Matrix +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators ENNReal NNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal +open scoped BigOperators +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise NNReal ENNReal +open scoped BigOperators +open Filter Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal Topology +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Set Matrix +open scoped BigOperators NNReal ENNReal Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open Filter MeasureTheory ProbabilityTheory +open scoped Topology NNReal ENNReal +open Filter MeasureTheory ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter +open scoped Topology NNReal ENNReal +open MeasureTheory Filter ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter +open scoped Topology +open MeasureTheory Filter ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter ProbabilityTheory ContinuousLinearMap +open scoped Topology NNReal ENNReal +open Filter MeasureTheory ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter +open scoped BigOperators Topology +open MeasureTheory Filter +open scoped BigOperators Topology +open MeasureTheory Filter +open scoped BigOperators Topology +open MeasureTheory Filter +open scoped BigOperators Topology +namespace SKGapCutoff + +lemma dimensionDecay_pos (a : ℝ) (n : ℕ) : 0 < dimensionDecay a n := Real.exp_pos _ + +lemma dimensionDecay_le_one {a : ℝ} (ha : 0 ≤ a) {n : ℕ} (hn : 0 < n) : + dimensionDecay a n ≤ 1 := by + apply Real.exp_le_one_iff.mpr + have hlog := Real.log_nonneg (show (1:ℝ) ≤ n by exact_mod_cast hn) + nlinarith + +lemma dimensionDecay_mul (a b : ℝ) (n : ℕ) : + dimensionDecay a n * dimensionDecay b n = dimensionDecay (a+b) n := by + unfold dimensionDecay + rw [← Real.exp_add] + congr 1 + ring + +lemma nat_mul_dimensionDecay {n : ℕ} (hn : 0 < n) (a : ℝ) : + (n:ℝ)*dimensionDecay a n = dimensionDecay (a-1) n := by + simpa only [show 1+(a-1) = a by ring, dimensionDecay] using mul_exp_log_identity hn (a-1) + +lemma nat_sq_mul_dimensionDecay {n : ℕ} (hn : 0 < n) (a : ℝ) : + (n:ℝ)^2*dimensionDecay a n = dimensionDecay (a-2) n := by + rw [pow_two, mul_assoc, nat_mul_dimensionDecay hn, nat_mul_dimensionDecay hn] + congr 1 + ring + +lemma exp_cutoffTime_eq_dimensionDecay {rate : ℝ} (hrate : rate ≠ 0) (ρ c : ℝ) (n : ℕ) : + Real.exp (-2*ρ*(c*cutoffTime rate n)) = dimensionDecay (c*ρ/rate) n := by + unfold cutoffTime dimensionDecay + congr 1 + field_simp [hrate] + +lemma dimensionDecay_mul_cutoffTime_tendsto {q rate : ℝ} (hq : 0 < q) : + Tendsto (fun n => dimensionDecay q n*cutoffTime rate n) atTop (𝓝 0) := by + have hh := (tendsto_rpow_mul_exp_neg_mul_atTop_nhds_zero 1 q hq).comp + (Real.tendsto_log_atTop.comp tendsto_natCast_atTop_atTop) + simp only [Function.comp_def, Real.rpow_one] at hh + have hh' := hh.div_const (2*rate) + convert hh' using 1 + · funext n + unfold dimensionDecay cutoffTime + ring + · simp + +lemma linear_mean_error_tendsto {C α q : ℝ} (hα : 1 < α) (hq : 1 < q) : + Tendsto (fun n => 2*Real.sqrt (C*dimensionDecay (α-1) n+C*dimensionDecay (q-1) n)) + atTop (𝓝 0) := by + have hh := ((dimensionDecay_tendsto (α-1) (by linarith)).const_mul C).add + ((dimensionDecay_tendsto (q-1) (by linarith)).const_mul C) + simpa using hh.sqrt.const_mul 2 + +lemma upper_polynomial_error_tendsto {C M θ m α δ q : ℝ} + (hexp : 1+2*δ < α) (hα : 1 < α) (htail : 2 < θ*δ) (hq : 1 < q) : + Tendsto (fun n => Real.sqrt (C/4*dimensionDecay (α-1) n + + C/4*dimensionDecay (α-1-2*δ) n + + 2*C*M*Real.exp (θ*m)*dimensionDecay (θ*δ-2) n + + C*dimensionDecay (q-1) n)) atTop (𝓝 0) := by + have h1 := (dimensionDecay_tendsto (α-1) (by linarith)).const_mul (C/4) + have h2 := (dimensionDecay_tendsto (α-1-2*δ) (by linarith)).const_mul (C/4) + have h3 := (dimensionDecay_tendsto (θ*δ-2) (by linarith)).const_mul (2*C*M*Real.exp (θ*m)) + have h4 := (dimensionDecay_tendsto (q-1) (by linarith)).const_mul C + simpa using ((h1.add h2).add h3 |>.add h4).sqrt + +end SKGapCutoff + +open MeasureTheory Filter +open scoped BigOperators Topology + +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/DisorderRecipeEvent.lean b/lean/OAI/Probability/SKGap/Localization/DisorderRecipeEvent.lean new file mode 100644 index 0000000000000000000000000000000000000000..16dbb95eaa1cee8a3b1f3935bb3bd796cbb78383 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/DisorderRecipeEvent.lean @@ -0,0 +1,120 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.OperatorQuenched +import OAI.Probability.SKGap.Matrix.FixedNormRecipeEvent + +namespace OAI + +section + +noncomputable section +open scoped BigOperators Matrix.Norms.Frobenius +namespace SKGapCutoff.Recipe +open SKGap SKGap.Noncrossing SKGap.Noncrossing.Primary MeasureTheory ProbabilityTheory Real Set +variable {n : ℕ} + +lemma continuous_matrixLetter (a : Letter (Fin n→ℝ)) : + Continuous (fun J : Interaction n=>matrixLetter J a) := by + cases a <;> first | exact continuous_const | exact continuous_id + +lemma continuous_matrixWord (w : OrdinaryWord n) : + Continuous (fun J : Interaction n=>matrixWord J w) := by + induction w with + | nil=>simpa only [matrixWord,List.map_nil,List.prod_nil] using + (continuous_const : Continuous (fun _ : Interaction n=>(1 : Interaction n))) + | cons a w ih=> + simpa only [matrixWord,List.map_cons,List.prod_cons] using + (continuous_matrixLetter a).matrix_mul ih + +lemma isClosed_wordSeminormBound (j A C : ℝ) (L : ℕ) : + IsClosed {J : Interaction n | WordSeminormBound J j A C L} := by + simp only [WordSeminormBound,ofPred_forall] + apply isClosed_iInter;intro p + apply isClosed_iInter;intro w + apply isClosed_iInter;intro hw + apply isClosed_iInter;intro hb + exact isClosed_le ((matrixWordSeminorm_lipschitz p).continuous.comp + ((continuous_matrixWord w).sub continuous_const)) continuous_const + +end SKGapCutoff.Recipe + +noncomputable section +open scoped BigOperators Topology +namespace SKGapCutoff.Recipe +open SKGap SKGap.ObservationBridge SKGap.Noncrossing SKGap.Noncrossing.Primary +open MeasureTheory ProbabilityTheory Real Set Filter +local instance (n : ℕ) : MeasurableSpace (Interaction n) := borel _ +local instance (n : ℕ) : BorelSpace (Interaction n) := ⟨rfl⟩ + +lemma disorder_closed_matrix_event (β : ℝ) {n : ℕ} (P : Interaction n→Prop) + (hP : IsClosed {J | P J}) : + SKGap.disorderLaw β n {g | ¬P (coupling g)}= + (Measure.pi (fun _ : MatrixCoordinates (Fin n)=>gaussianReal 0 1)) + {g | ¬P (removeDiagonal (goeMatrix (β^2/n) g))} := by + have hE : MeasurableSet {g : Disorder n | ¬P (coupling g)} := + (hP.preimage SKGap.ObservationBridge.continuous_coupling).measurableSet.compl + have H:=(measurePreserving_goeEdges (n:=n) (r:=β^2/(n:ℝ)) (by positivity)).measure_preimage hE.nullMeasurableSet + simpa only [SKGap.gaussianCoordinates,SKGap.disorderLaw,Set.preimage_ofPred_eq,coupling_goeEdges, + eraseDiagonal,removeDiagonal] using H.symm + +lemma disorder_word_event {β A : ℝ} (hβ : 0<β) (hβ1 : β<1) (hA : 1≤A) (L : ℕ) : + ∃C:ℝ,∃N:ℕ,0SKGap.opNorm J≤physicalNormBound (β^2)) hP + simp only [not_le] at H + rw [H] + exact zeroDiagGOE_norm_tail (sq_pos_of_pos hβ) hn + +theorem disorder_fixed_norm_recipe_probability {β A : ℝ} (hβ : 0<β) (hβ1 : β<1) + (hA : 1≤A) (M Nmax : ℕ) : ∃B W C : ℝ,0≤B ∧ 0≤W ∧ 0SKGap.disorderLaw β n + {g | ¬RecipeMatrixEvent (β^2) (physicalNormBound (β^2)) A B W C M Nmax + (coupling g)}) atTop (𝓝 0) := by + let j:=β^2 + have hj : 0recipeNormTail j n+ordinaryWordTail j (2*M+2*Nmax+3) n) atTop (𝓝 0) from + by simpa using (recipeNormTail_limit hj).add (ordinaryWordTail_limit hj _)) + (Filter.Eventually.of_forall (fun _=>bot_le)) + filter_upwards [eventually_ge_atTop N] with n hn + have hn0 : 0hh (.inl hbad)) + have hw : WordSeminormBound (coupling g) j A C (2*M+2*Nmax+3):=by + by_contra hbad;exact hh (.inr hbad) + have hev:=wordEvent_recipeEvent (coupling g) hn0 hR hA hAR hC.le + (hp.trans (le_max_right _ _)) M Nmax hw + exact hg ⟨hp,hev.2⟩ + +end SKGapCutoff.Recipe + +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/DivergenceIntegrand.lean b/lean/OAI/Probability/SKGap/Localization/DivergenceIntegrand.lean new file mode 100644 index 0000000000000000000000000000000000000000..a05cec44b51c26cb90ebb6e540de8d7acf359f4e --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/DivergenceIntegrand.lean @@ -0,0 +1,378 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.Reference + +namespace OAI + +namespace SKGap.GaussianStep +open MeasureTheory ProbabilityTheory Real Set Filter +open scoped BigOperators ENNReal NNReal +noncomputable section +variable {n : ℕ} + +lemma var_eq (p : Prior n) (f : Spin n → ℝ) : + var p f = avg p (fun x => (f x)^2) - (avg p f)^2 := by + rw [var, avg_shift_square] + ring + +lemma var_le_square (p : Prior n) (f : Spin n → ℝ) : + var p f ≤ avg p (fun x => (f x)^2) := by rw [var_eq]; linarith [sq_nonneg (avg p f)] + +lemma l1_square_le_avg_square (p : Prior n) (f : Spin n → ℝ) : + (∑ x, |p x*f x|)^2 ≤ avg p (fun x => (f x)^2) := by + have hc := Finset.sum_mul_sq_le_sq_mul_sq Finset.univ + (fun x => sqrt (p x)) (fun x => sqrt (p x)*|f x|) + have hs : (∑ x, (sqrt (p x))^2) = 1 := by + simp_rw [sq_sqrt (p.nonneg _)]; exact p.sum_one + have he : (∑ x, sqrt (p x)*(sqrt (p x)*|f x|)) = ∑ x, |p x*f x| := by + apply Finset.sum_congr rfl + intro x _ + rw [← mul_assoc, mul_self_sqrt (p.nonneg x), abs_mul, abs_of_nonneg (p.nonneg x)] + have hf : (∑ x, (sqrt (p x)*|f x|)^2) = avg p (fun x => (f x)^2) := by + simp only [avg, mul_pow, sq_sqrt (p.nonneg _), sq_abs] + rw [he, hs, hf, one_mul] at hc + exact hc + +lemma centered_l1_bound (p : Prior n) (f : Spin n → ℝ) : + (∑ x, |p x*(f x-avg p f)|)^2 ≤ var p f := + l1_square_le_avg_square p (fun x => f x-avg p f) + +lemma posterior_avg_weight (p : Prior n) (t : ℝ) (z : Fin n → ℝ) (f : Spin n → ℝ) : + density p t z * avg (posterior p t z) f = ∑ x, (p x*f x)*likelihood t x z := by + unfold avg posterior + rw [Finset.mul_sum] + apply Finset.sum_congr rfl + intro x _ + dsimp + field_simp [(density_pos p t z).ne'] + +lemma integrable_posterior_avg_weight (p : Prior n) (t : ℝ) (f : Spin n → ℝ) : + Integrable (fun z => density p t z * avg (posterior p t z) f) (reference n) := by + simp_rw [posterior_avg_weight] + exact integrable_finsetSum _ (fun x _ => (integrable_likelihood t x).const_mul _) + +lemma integral_posterior_avg_weight (p : Prior n) {t : ℝ} (ht : 0 ≤ t) (f : Spin n → ℝ) : + (∫ z, density p t z * avg (posterior p t z) f ∂reference n) = avg p f := by + simp_rw [posterior_avg_weight] + rw [integral_finsetSum _ (fun x _ => (integrable_likelihood t x).const_mul _)] + simp_rw [integral_const_mul, integral_likelihood ht, mul_one] + rfl + +lemma posterior_variance_identity (p : Prior n) (t : ℝ) (z : Fin n → ℝ) (f : Spin n → ℝ) : + density p t z * var (posterior p t z) f = + density p t z * avg (posterior p t z) (fun x => (f x-avg p f)^2) - + quadraticIntegrand p (fun x => p x*(f x-avg p f)) t z := by + have ha := posterior_avg_weight p t z (fun x => f x-avg p f) + have hshift := avg_shift_square (posterior p t z) f (avg p f) + rw [avg_sub, avg_const] at ha + rw [var_eq, hshift, quadraticIntegrand, ← ha] + field_simp [(density_pos p t z).ne'] + ring + +lemma integrable_posterior_variance_weight (p : Prior n) (t : ℝ) (f : Spin n → ℝ) : + Integrable (fun z => density p t z * var (posterior p t z) f) (reference n) := by + simp_rw [posterior_variance_identity] + exact (integrable_posterior_avg_weight p t _).sub (integrable_quadraticIntegrand p _ t) + +lemma integral_posterior_variance (p : Prior n) {t : ℝ} (ht : 0 ≤ t) (f : Spin n → ℝ) : + (∫ z, density p t z * var (posterior p t z) f ∂reference n) = + var p f - ∫ z, quadraticIntegrand p (fun x => p x*(f x-avg p f)) t z ∂reference n := by + simp_rw [posterior_variance_identity] + rw [integral_sub (integrable_posterior_avg_weight p t _) + (integrable_quadraticIntegrand p _ t), integral_posterior_avg_weight p ht] + rfl + +theorem variance_step_bound (p : Prior n) {t : ℝ} (ht : 0 ≤ t) + (htn : 4*(n:ℝ)*t ≤ 1) (f : Spin n → ℝ) : + var p f - t*(∑ i, (∑ x, p x*(f x-avg p f)*spinValue (x i))^2) - + 16*(n:ℝ)^2*t^2*var p f ≤ + ∫ z, density p t z*var (posterior p t z) f ∂reference n := by + rw [integral_posterior_variance p ht] + have hq := quadratic_bound p (fun x => p x*(f x-avg p f)) (avg_center p f) ht htn + have he := mul_le_mul_of_nonneg_left (centered_l1_bound p f) + (show 0 ≤ 16*(n:ℝ)^2*t^2 by positivity) + linarith + +lemma scalar_entropy_nonneg {r : ℝ} (hr : 0 < r) : 0 ≤ r*log r-r+1 := by + have h := mul_le_mul_of_nonneg_left (one_sub_inv_le_log_of_pos hr) hr.le + have hi : r*r⁻¹ = 1 := mul_inv_cancel₀ hr.ne' + nlinarith + +lemma scalar_entropy_le_square {r : ℝ} (hr : 0 < r) : r*log r-r+1 ≤ (r-1)^2 := by + have h := mul_le_mul_of_nonneg_left (log_le_sub_one_of_pos hr) hr.le + nlinarith + +def divergenceIntegrand (p q : Prior n) (t : ℝ) (z : Fin n → ℝ) : ℝ := + density q t z * log (density q t z/density p t z) - density q t z + density p t z + +lemma divergenceIntegrand_eq (p q : Prior n) (t : ℝ) (z : Fin n → ℝ) : + divergenceIntegrand p q t z = density p t z * + ((density q t z/density p t z)*log (density q t z/density p t z)- + density q t z/density p t z+1) := by + unfold divergenceIntegrand + field_simp [(density_pos p t z).ne'] + +lemma divergenceIntegrand_nonneg (p q : Prior n) (t : ℝ) (z : Fin n → ℝ) : + 0 ≤ divergenceIntegrand p q t z := by + rw [divergenceIntegrand_eq] + exact mul_nonneg (density_pos p t z).le + (scalar_entropy_nonneg (div_pos (density_pos q t z) (density_pos p t z))) + +lemma density_sub (p q : Prior n) (t : ℝ) (z : Fin n → ℝ) : + (∑ x, (q x-p x)*likelihood t x z) = density q t z-density p t z := by + simp only [sub_mul, Finset.sum_sub_distrib, density] + +lemma divergenceIntegrand_le_quadratic (p q : Prior n) (t : ℝ) (z : Fin n → ℝ) : + divergenceIntegrand p q t z ≤ quadraticIntegrand p (fun x => q x-p x) t z := by + rw [divergenceIntegrand_eq, quadraticIntegrand, density_sub] + calc + _ ≤ density p t z*(density q t z/density p t z-1)^2 := + mul_le_mul_of_nonneg_left + (scalar_entropy_le_square (div_pos (density_pos q t z) (density_pos p t z))) + (density_pos p t z).le + _ = _ := by field_simp [(density_pos p t z).ne'] + +lemma continuous_divergenceIntegrand (p q : Prior n) (t : ℝ) : + Continuous (divergenceIntegrand p q t) := by + have hd := (continuous_density q t).div (continuous_density p t) + (fun z => (density_pos p t z).ne') + exact (((continuous_density q t).mul (hd.log (fun z => + (div_pos (density_pos q t z) (density_pos p t z)).ne'))).sub + (continuous_density q t)).add (continuous_density p t) + +lemma integrable_divergenceIntegrand (p q : Prior n) (t : ℝ) : + Integrable (divergenceIntegrand p q t) (reference n) := by + apply (integrable_quadraticIntegrand p (fun x => q x-p x) t).mono' + (continuous_divergenceIntegrand p q t).aestronglyMeasurable + filter_upwards [] with z + rw [Real.norm_eq_abs, abs_of_nonneg (divergenceIntegrand_nonneg p q t z)] + exact divergenceIntegrand_le_quadratic p q t z + +lemma prior_sub_l1 (p q : Prior n) : (∑ x, |q x-p x|) ≤ 2 := by + calc + _ ≤ ∑ x, (q x+p x) := Finset.sum_le_sum (fun x _ => by + simpa only [abs_of_nonneg (q.nonneg x), abs_of_nonneg (p.nonneg x)] using abs_sub (q x) (p x)) + _ = 2 := by rw [Finset.sum_add_distrib, q.sum_one, p.sum_one]; norm_num + +lemma prior_sub_sum (p q : Prior n) : (∑ x, (q x-p x)) = 0 := by + rw [Finset.sum_sub_distrib, q.sum_one, p.sum_one, sub_self] + +theorem entropy_step_bound (p q : Prior n) {t : ℝ} (ht : 0 ≤ t) + (htn : 4*(n:ℝ)*t ≤ 1) : + (∫ z, divergenceIntegrand p q t z ∂reference n) ≤ + t*(∑ i, (mean q i-mean p i)^2)+64*(n:ℝ)^2*t^2 := by + have hmean : (∑ i, (∑ x, (q x-p x)*spinValue (x i))^2) = + ∑ i, (mean q i-mean p i)^2 := by + simp only [sub_mul, Finset.sum_sub_distrib, mean] + have he : (∑ x, |q x-p x|)^2 ≤ 4 := by + have hl : 0 ≤ ∑ x, |q x-p x| := Finset.sum_nonneg (fun _ _ => abs_nonneg _) + nlinarith [prior_sub_l1 p q] + calc + _ ≤ ∫ z, quadraticIntegrand p (fun x => q x-p x) t z ∂reference n := + integral_mono (integrable_divergenceIntegrand p q t) (integrable_quadraticIntegrand p _ t) + (divergenceIntegrand_le_quadratic p q t) + _ ≤ t*(∑ i, (mean q i-mean p i)^2)+16*(n:ℝ)^2*t^2*(∑ x, |q x-p x|)^2 := by + simpa only [hmean] using quadratic_bound p (fun x => q x-p x) (prior_sub_sum p q) ht htn + _ ≤ _ := by nlinarith [mul_le_mul_of_nonneg_left he (show 0 ≤ 16*(n:ℝ)^2*t^2 by positivity)] + +lemma integrable_relativeEntropy (p q : Prior n) (t : ℝ) : + Integrable (fun z => density q t z*log (density q t z/density p t z)) (reference n) := by + have he : (fun z => density q t z*log (density q t z/density p t z)) = + fun z => divergenceIntegrand p q t z+density q t z-density p t z := by + funext z + unfold divergenceIntegrand + ring + rw [he] + exact ((integrable_divergenceIntegrand p q t).add (integrable_density q t)).sub + (integrable_density p t) + +lemma integral_relativeEntropy (p q : Prior n) {t : ℝ} (ht : 0 ≤ t) : + (∫ z, density q t z*log (density q t z/density p t z) ∂reference n) = + ∫ z, divergenceIntegrand p q t z ∂reference n := by + have hi := integral_add + ((integrable_relativeEntropy p q t).sub (integrable_density q t)) (integrable_density p t) + have hj := integral_sub (integrable_relativeEntropy p q t) (integrable_density q t) + simp only [Pi.sub_apply] at hi hj + rw [hj, integral_density q ht, integral_density p ht] at hi + change (∫ z, divergenceIntegrand p q t z ∂reference n) = _ at hi + linarith + +def squarePrior (p : Prior n) (f : Spin n → ℝ) (hf : 0 < avg p (fun x => (f x)^2)) : Prior n where + mass x := p x*(f x)^2/avg p (fun x => (f x)^2) + nonneg x := div_nonneg (mul_nonneg (p.nonneg x) (sq_nonneg _)) hf.le + sum_one := by rw [← Finset.sum_div]; exact div_self hf.ne' + +lemma squarePrior_density (p : Prior n) (f : Spin n → ℝ) + (hf : 0 < avg p (fun x => (f x)^2)) (t : ℝ) (z : Fin n → ℝ) : + density (squarePrior p f hf) t z = + density p t z*avg (posterior p t z) (fun x => (f x)^2)/avg p (fun x => (f x)^2) := by + rw [posterior_avg_weight] + unfold density squarePrior + dsimp + rw [Finset.sum_div] + apply Finset.sum_congr rfl + intro x _ + ring + +lemma posterior_square_pos (p : Prior n) (f : Spin n → ℝ) + (hf : 0 < avg p (fun x => (f x)^2)) (t : ℝ) (z : Fin n → ℝ) : + 0 < avg (posterior p t z) (fun x => (f x)^2) := by + have h := density_pos (squarePrior p f hf) t z + rw [squarePrior_density] at h + exact (mul_pos_iff_of_pos_left (density_pos p t z)).mp ((div_pos_iff_of_pos_right hf).mp h) + +lemma squarePrior_posterior (p : Prior n) (f : Spin n → ℝ) + (hf : 0 < avg p (fun x => (f x)^2)) (t : ℝ) (z : Fin n → ℝ) : + posterior (squarePrior p f hf) t z = + squarePrior (posterior p t z) f (posterior_square_pos p f hf t z) := by + apply Prior.ext + funext x + change (p x*(f x)^2/avg p (fun x => (f x)^2))*likelihood t x z / + density (squarePrior p f hf) t z = + (p x*likelihood t x z/density p t z)*(f x)^2/avg (posterior p t z) (fun x => (f x)^2) + rw [squarePrior_density] + field_simp [hf.ne', (density_pos p t z).ne', (posterior_square_pos p f hf t z).ne'] + +lemma avg_add (p : Prior n) (f g : Spin n → ℝ) : + avg p (fun x => f x+g x) = avg p f+avg p g := by + simp only [avg, mul_add, Finset.sum_add_distrib] + +lemma avg_const_mul (p : Prior n) (c : ℝ) (f : Spin n → ℝ) : + avg p (fun x => c*f x) = c*avg p f := by + simpa only [mul_comm c] using avg_mul_const p f c + +lemma avg_nonneg (p : Prior n) (f : Spin n → ℝ) (hf : ∀ x, 0 ≤ f x) : 0 ≤ avg p f := + Finset.sum_nonneg (fun x _ => mul_nonneg (p.nonneg x) (hf x)) + +def cond (p : Prior n) (i : Fin n) (f : Spin n → ℝ) (x : Spin n) : ℝ := + (p x*f x+p (flip i x)*f (flip i x))/(p x+p (flip i x)) + +lemma cond_flip (p : Prior n) (i : Fin n) (f : Spin n → ℝ) (x : Spin n) : + cond p i f (flip i x) = cond p i f x := by + simp only [cond, flip_flip, add_comm] + +lemma avg_flip (p : Prior n) (i : Fin n) (f : Spin n → ℝ) : + avg p f = (1/2:ℝ)*∑ x, (p x*f x+p (flip i x)*f (flip i x)) := by + rw [Finset.sum_add_distrib, sum_flip i (fun x => p x*f x)] + unfold avg + ring + +lemma conditional_orthogonal (p : Prior n) (hp : ∀ x, 0 < p x) (i : Fin n) + (f c : Spin n → ℝ) (hc : ∀ x, c (flip i x)=c x) : + avg p (fun x => (f x-cond p i f x)*c x) = 0 := by + rw [avg_flip p i] + have hs : (∑ x, (p x*((f x-cond p i f x)*c x)+ + p (flip i x)*((f (flip i x)-cond p i f (flip i x))*c (flip i x)))) = 0 := by + apply Finset.sum_eq_zero + intro x _ + rw [cond_flip, hc] + unfold cond + field_simp [(add_pos (hp x) (hp (flip i x))).ne'] + ring + rw [hs, mul_zero] + +lemma conditional_minimal (p : Prior n) (hp : ∀ x, 0 < p x) (i : Fin n) + (f c : Spin n → ℝ) (hc : ∀ x, c (flip i x)=c x) : + avg p (fun x => (f x-cond p i f x)^2) ≤ avg p (fun x => (f x-c x)^2) := by + have ho := conditional_orthogonal p hp i f (fun x => cond p i f x-c x) + (fun x => by rw [cond_flip, hc]) + have he (x : Spin n) : (f x-c x)^2 = + (f x-cond p i f x)^2+(cond p i f x-c x)^2+ + 2*((f x-cond p i f x)*(cond p i f x-c x)) := by ring + simp_rw [he] + rw [avg_add, avg_add, avg_const_mul, ho, mul_zero, add_zero] + exact le_add_of_nonneg_right (avg_nonneg p _ (fun _ => sq_nonneg _)) + +def energy (p : Prior n) (f : Spin n → ℝ) : ℝ := + ∑ i, avg p (fun x => (f x-cond p i f x)^2) + +lemma energy_nonneg (p : Prior n) (f : Spin n → ℝ) : 0 ≤ energy p f := + Finset.sum_nonneg (fun _ _ => avg_nonneg p _ (fun _ => sq_nonneg _)) + +lemma avg_sum (p : Prior n) {ι : Type*} [Fintype ι] (f : ι → Spin n → ℝ) : + avg p (fun x => ∑ i, f i x) = ∑ i, avg p (f i) := by + simp only [avg, Finset.mul_sum] + rw [Finset.sum_comm] + +lemma posterior_mass_pos (p : Prior n) (hp : ∀ x, 0 < p x) (t : ℝ) (z : Fin n → ℝ) + (x : Spin n) : 0 < posterior p t z x := + div_pos (mul_pos (hp x) (likelihood_pos t x z)) (density_pos p t z) + +lemma posterior_energy_bound (p : Prior n) (hp : ∀ x, 0 < p x) (t : ℝ) (z : Fin n → ℝ) + (f : Spin n → ℝ) : + energy (posterior p t z) f ≤ avg (posterior p t z) + (fun x => ∑ i, (f x-cond p i f x)^2) := by + rw [avg_sum] + exact Finset.sum_le_sum (fun i _ => conditional_minimal (posterior p t z) + (posterior_mass_pos p hp t z) i f (cond p i f) (cond_flip p i f)) + +lemma continuous_posterior_mass (p : Prior n) (t : ℝ) (x : Spin n) : + Continuous (fun z => posterior p t z x) := by + exact ((continuous_likelihood t x).const_mul (p x)).div (continuous_density p t) + (fun z => (density_pos p t z).ne') + +lemma continuous_posterior_cond (p : Prior n) (hp : ∀ x, 0 < p x) (t : ℝ) + (i : Fin n) (f : Spin n → ℝ) (x : Spin n) : + Continuous (fun z => cond (posterior p t z) i f x) := by + apply Continuous.div + (((continuous_posterior_mass p t x).mul_const (f x)).add + ((continuous_posterior_mass p t (flip i x)).mul_const (f (flip i x)))) + ((continuous_posterior_mass p t x).add (continuous_posterior_mass p t (flip i x))) + intro z + exact (add_pos (posterior_mass_pos p hp t z x) (posterior_mass_pos p hp t z (flip i x))).ne' + +lemma continuous_posterior_energy (p : Prior n) (hp : ∀ x, 0 < p x) (t : ℝ) + (f : Spin n → ℝ) : Continuous (fun z => energy (posterior p t z) f) := by + apply continuous_finsetSum + intro i _ + apply continuous_finsetSum + intro x _ + exact (continuous_posterior_mass p t x).mul + ((continuous_const.sub (continuous_posterior_cond p hp t i f x)).pow 2) + +lemma integrable_posterior_energy_weight (p : Prior n) (hp : ∀ x, 0 < p x) (t : ℝ) + (f : Spin n → ℝ) : + Integrable (fun z => density p t z*energy (posterior p t z) f) (reference n) := by + apply (integrable_posterior_avg_weight p t (fun x => ∑ i, (f x-cond p i f x)^2)).mono' + ((continuous_density p t).mul (continuous_posterior_energy p hp t f)).aestronglyMeasurable + filter_upwards [] with z + change |density p t z*energy (posterior p t z) f| ≤ _ + rw [abs_of_nonneg (mul_nonneg (density_pos p t z).le (energy_nonneg _ _))] + exact mul_le_mul_of_nonneg_left (posterior_energy_bound p hp t z f) (density_pos p t z).le + +theorem energy_step_bound (p : Prior n) (hp : ∀ x, 0 < p x) {t : ℝ} (ht : 0 ≤ t) + (f : Spin n → ℝ) : + (∫ z, density p t z*energy (posterior p t z) f ∂reference n) ≤ energy p f := by + let F : Spin n → ℝ := fun x => ∑ i, (f x-cond p i f x)^2 + have hle : (∫ z, density p t z*energy (posterior p t z) f ∂reference n) ≤ + ∫ z, density p t z*avg (posterior p t z) F ∂reference n := by + apply integral_mono (integrable_posterior_energy_weight p hp t f) + (integrable_posterior_avg_weight p t F) + intro z + exact mul_le_mul_of_nonneg_left (posterior_energy_bound p hp t z f) (density_pos p t z).le + rw [integral_posterior_avg_weight p ht] at hle + change _ ≤ avg p (fun x => ∑ i, (f x-cond p i f x)^2) at hle + rw [avg_sum] at hle + exact hle + +lemma gibbsPrior_avg (g : Disorder n) (h : Fin n → ℝ) (f : Spin n → ℝ) : + avg (gibbsPrior g h) f = expectation g h f := rfl + +lemma gibbsPrior_var (g : Disorder n) (h : Fin n → ℝ) (f : Spin n → ℝ) : + var (gibbsPrior g h) f = variance g h f := rfl + +lemma gibbsPrior_cond (g : Disorder n) (h : Fin n → ℝ) (i : Fin n) + (f : Spin n → ℝ) (x : Spin n) : + cond (gibbsPrior g h) i f x = conditionalExpectation g h i f x := by + unfold cond gibbsPrior conditionalExpectation + dsimp + unfold mass + field_simp [(partition_pos g h).ne', (add_pos (weight_pos g h x) (weight_pos g h (flip i x))).ne'] + +lemma gibbsPrior_energy (g : Disorder n) (h : Fin n → ℝ) (f : Spin n → ℝ) : + energy (gibbsPrior g h) f = dirichlet g h f := by + simp only [energy, gibbsPrior_cond, gibbsPrior_avg, dirichlet] + +end +end SKGap.GaussianStep + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/DoublePlantedLawTransfer.lean b/lean/OAI/Probability/SKGap/Localization/DoublePlantedLawTransfer.lean new file mode 100644 index 0000000000000000000000000000000000000000..428d7b3d615387e35173976b3666bb30d14b6ad5 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/DoublePlantedLawTransfer.lean @@ -0,0 +1,205 @@ +import Mathlib +import OAI.Probability.SKGap.Matrix.DoublePlantLogNorm + +namespace OAI + +section +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open scoped BigOperators +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open scoped BigOperators +open scoped BigOperators NNReal ENNReal +open MeasureTheory Metric Set +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators NNReal ENNReal Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Set +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators ENNReal NNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Matrix +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators ENNReal NNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal +open scoped BigOperators +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise NNReal ENNReal +open scoped BigOperators +open Filter Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal Topology +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +namespace SKGapCutoff + +lemma double_planted_law_transfer (β : ℝ) (hβ : β^2 < 1) {n : ℕ} (hn : 0 < n) + (a s : ℝ) (f : GaussianCoordinates n → ℝ≥0∞) (hf : Measurable f) : + (disorderLaw β n) {g | Real.log (∫ h, partition (sampledInteraction h) ∂disorderLaw β n) - a ≤ + Real.log (partition (sampledInteraction g)) ∧ ENNReal.ofReal (Real.exp (-s)) ≤ f g} ≤ + ENNReal.ofReal ((Real.sqrt (1-β^2))⁻¹ * Real.exp (2*a+s)) * + ∫⁻ g, f g ∂doublePlantedDisorderLaw β n := by + let m := ∫ h, partition (sampledInteraction h) ∂disorderLaw β n + let C := (Real.sqrt (1-β^2))⁻¹ + have hC : 0 < C := inv_pos.mpr (Real.sqrt_pos.mpr (sub_pos.mpr hβ)) + let r := fun g : GaussianCoordinates n => ENNReal.ofReal + (partition (sampledInteraction g)^2/doublePlantNorm β n) + let A := {g : GaussianCoordinates n | Real.log m - a ≤ + Real.log (partition (sampledInteraction g)) ∧ ENNReal.ofReal (Real.exp (-s)) ≤ f g} + have hm : 0 < m := by dsimp [m]; rw [integral_partition_sampled β hn]; positivity + have hZ := (continuous_partition n).comp (continuous_sampledInteraction n) + have hr : Measurable r := ((hZ.measurable.pow_const 2).div_const _).ennreal_ofReal + have hA : MeasurableSet A := + (measurableSet_le measurable_const hZ.measurable.log).inter + (measurableSet_le measurable_const hf) + have hNorm : doublePlantNorm β n ≤ C*m^2 := + (div_le_iff₀ (sq_pos_of_pos hm)).mp (partition_second_moment_bound β hβ hn) + have hd : ∀ g ∈ A, ENNReal.ofReal (Real.exp (-2*a)/C) ≤ r g := by + intro g hg + apply ENNReal.ofReal_le_ofReal + have hl : m*Real.exp (-a) ≤ partition (sampledInteraction g) := by + have he := Real.exp_le_exp.mpr hg.1 + rwa [Real.exp_sub, Real.exp_log hm, Real.exp_log (partition_pos _), + div_eq_mul_inv, ← Real.exp_neg] at he + have hs : m^2*Real.exp (-2*a) ≤ partition (sampledInteraction g)^2 := by + have hh := pow_le_pow_left₀ (mul_nonneg hm.le (Real.exp_pos _).le) hl 2 + rw [mul_pow, ← Real.exp_nat_mul] at hh + convert! hh using 1 + congr 2 + ring + apply (div_le_div_iff₀ hC (doublePlantNorm_pos β hn)).mpr + calc + _ ≤ Real.exp (-2*a)*(C*m^2) := mul_le_mul_of_nonneg_left hNorm (Real.exp_pos _).le + _ ≤ partition (sampledInteraction g)^2*C := by + nlinarith [mul_le_mul_of_nonneg_right hs hC.le] + have h := lower_density_markov_div (disorderLaw β n) r f hr hf A hA + (ENNReal.ofReal (Real.exp (-2*a)/C)) (ENNReal.ofReal (Real.exp (-s))) + (by positivity) ENNReal.ofReal_ne_top (by positivity) ENNReal.ofReal_ne_top hd + (fun g hg => hg.2) + have he : (ENNReal.ofReal (Real.exp (-2*a)/C) * ENNReal.ofReal (Real.exp (-s)))⁻¹ = + ENNReal.ofReal (C*Real.exp (2*a+s)) := by + rw [← ENNReal.ofReal_mul (by positivity), ← ENNReal.ofReal_inv_of_pos (by positivity)] + congr 1 + rw [_root_.mul_inv_rev, inv_div, ← Real.exp_neg, neg_neg] + rw [div_eq_mul_inv, ← Real.exp_neg] + rw [show -(-2*a) = 2*a by ring] + rw [Real.exp_add] + ring + rw [div_eq_mul_inv, he, mul_comm] at h + exact h + +lemma double_planted_failure_probability_bound (β : ℝ) (hβ : β^2 < 1) + {n : ℕ} (hn : 0 < n) (a s : ℝ) + (f : GaussianCoordinates n → ℝ≥0∞) (hf : Measurable f) : + disorderLaw β n {g | ENNReal.ofReal (Real.exp (-s)) ≤ f g} ≤ + disorderLaw β n {g | a/(n:ℝ) < |(Real.log (partition (sampledInteraction g)) - + Real.log (∫ h, partition (sampledInteraction h) ∂disorderLaw β n))/(n:ℝ)|} + + ENNReal.ofReal ((Real.sqrt (1-β^2))⁻¹ * Real.exp (2*a+s)) * + ∫⁻ g, f g ∂doublePlantedDisorderLaw β n := by + let m := ∫ h, partition (sampledInteraction h) ∂disorderLaw β n + let E := {g : GaussianCoordinates n | Real.log m-a ≤ Real.log (partition (sampledInteraction g))} + have hsub : {g | ENNReal.ofReal (Real.exp (-s)) ≤ f g} ⊆ Eᶜ ∪ + {g | Real.log m-a ≤ Real.log (partition (sampledInteraction g)) ∧ + ENNReal.ofReal (Real.exp (-s)) ≤ f g} := by + intro g hg + by_cases h : g ∈ E + · exact Or.inr ⟨h,hg⟩ + · exact Or.inl h + apply (measure_mono hsub).trans + apply (measure_union_le _ _).trans + apply add_le_add _ (double_planted_law_transfer β hβ hn a s f hf) + apply measure_mono + intro g hg + have hnR : (0:ℝ) < n := Nat.cast_pos.mpr hn + have hh : Real.log (partition (sampledInteraction g)) < Real.log m-a := lt_of_not_ge hg + change a/(n:ℝ) < |(Real.log (partition (sampledInteraction g))-Real.log m)/(n:ℝ)| + rw [abs_div, abs_of_pos hnR] + apply (div_lt_div_iff_of_pos_right hnR).mpr + linarith [neg_le_abs (Real.log (partition (sampledInteraction g))-Real.log m)] + +lemma quenched_double_exponential_transfer (β : ℝ) (hβ : β^2 < 1) + (c : ℝ) (hc : 0 < c) (f : (n : ℕ) → GaussianCoordinates n → ℝ≥0∞) + (hf : ∀ n, Measurable (f n)) + (hsmall : ∀ᶠ n : ℕ in atTop, (∫⁻ g, f n g ∂doublePlantedDisorderLaw β n) ≤ + ENNReal.ofReal (Real.exp (-c*n))) : + Tendsto (fun n => disorderLaw β n {g | ENNReal.ofReal (Real.exp (-(c/2)*n)) ≤ f n g}) + atTop (nhds 0) := by + have hlog := log_partition_annealed_difference_limit β hβ (c/8) (by positivity) + simp only [sub_zero] at hlog + have he : Tendsto (fun n : ℕ => (Real.sqrt (1-β^2))⁻¹ * Real.exp (-(c/4)*n)) + atTop (nhds 0) := by + have hh := Real.tendsto_exp_neg_atTop_nhds_zero.comp + ((tendsto_natCast_atTop_atTop : Tendsto (fun n : ℕ => (n:ℝ)) atTop atTop).const_mul_atTop + (show 0 < c/4 by positivity)) + simpa only [Function.comp_def, neg_mul, mul_zero] using hh.const_mul ((Real.sqrt (1-β^2))⁻¹) + have he' := ENNReal.continuous_ofReal.continuousAt.tendsto.comp he + simp only [ENNReal.ofReal_zero] at he' + have hb := hlog.add he' + simp only [zero_add] at hb + apply tendsto_of_tendsto_of_tendsto_of_le_of_le' tendsto_const_nhds hb + (Eventually.of_forall (fun _ => bot_le)) + filter_upwards [eventually_gt_atTop 0, hsmall] with n hn hs + have hh := double_planted_failure_probability_bound β hβ hn (c*n/8) (c*n/2) (f n) (hf n) + have hn0 : (n:ℝ) ≠ 0 := Nat.cast_ne_zero.mpr (Nat.ne_of_gt hn) + have hfrac : (c*(n:ℝ)/8)/(n:ℝ) = c/8 := by field_simp + rw [hfrac] at hh + have hleft : -(c*(n:ℝ)/2) = -(c/2)*n := by ring + rw [hleft] at hh + apply hh.trans + apply add_le_add le_rfl + calc + _ ≤ ENNReal.ofReal ((Real.sqrt (1-β^2))⁻¹ * Real.exp (2*(c*n/8)+c*n/2)) * + ENNReal.ofReal (Real.exp (-c*n)) := mul_le_mul' le_rfl hs + _ = _ := by + rw [← ENNReal.ofReal_mul (by positivity), mul_assoc, ← Real.exp_add] + congr 3 + ring + +end SKGapCutoff + +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators + +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/DriftSquare.lean b/lean/OAI/Probability/SKGap/Localization/DriftSquare.lean new file mode 100644 index 0000000000000000000000000000000000000000..9e01a034a09d03d649e19925597882b6ab1eac13 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/DriftSquare.lean @@ -0,0 +1,156 @@ +import Mathlib +import OAI.Probability.SKGap.Brownian.ContinuousPosteriorMass + +namespace OAI + +namespace SKGap.GaussianHistory +open MeasureTheory ProbabilityTheory Real Set Filter +open scoped BigOperators ENNReal NNReal +open GaussianStep +noncomputable section +variable {n : ℕ} + +def driftSquare (p q : Prior n) (t : ℝ) {k : ℕ} (h : History n k) : ℝ := + ∑i,(mean (posterior q t h) i-mean (posterior p t h) i)^2 + +lemma driftSquare_nonneg (p q : Prior n) (t : ℝ) {k : ℕ} (h : History n k) : + 0≤driftSquare p q t h := Finset.sum_nonneg (fun _ _ => sq_nonneg _) + +lemma driftSquare_le (p q : Prior n) (t : ℝ) {k : ℕ} (h : History n k) : + driftSquare p q t h≤4*(n:ℝ) := mean_difference_square_le _ _ + +lemma continuous_driftSquare (p q : Prior n) (t : ℝ) (k : ℕ) : + Continuous (driftSquare p q t (k := k)) := by + unfold driftSquare mean + exact continuous_finsetSum _ (fun i _ => + ((continuous_finsetSum _ (fun x _ => (continuous_posterior_mass q t k x).mul_const _)).sub + (continuous_finsetSum _ (fun x _ => (continuous_posterior_mass p t k x).mul_const _))).pow 2) + +lemma integrable_driftSquare_weight (p q : Prior n) (t : ℝ) (k : ℕ) : + Integrable (fun h : History n k => density q t h*driftSquare p q t h) (reference n k) := by + apply ((integrable_density q t k).mul_const (4*(n:ℝ))).mono' + ((continuous_density q t k).mul (continuous_driftSquare p q t k)).aestronglyMeasurable + filter_upwards [] with h + change |density q t h*driftSquare p q t h|≤_ + rw [abs_of_nonneg (mul_nonneg (density_pos q t h).le (driftSquare_nonneg _ _ _ _))] + exact mul_le_mul_of_nonneg_left (driftSquare_le p q t h) (density_pos q t h).le + +lemma integrable_entropy_increment (p q : Prior n) (hp : ∀x,0

density q t h* + (∫z,GaussianStep.divergenceIntegrand (posterior p t h) (posterior q t h) t z + ∂GaussianStep.reference n)) (reference n k) := by + let L : History n k → ℝ := fun h => log (density q t h/density p t h) + have hL : Measurable L := (continuous_log_ratio p q t k).measurable + have hiL : Integrable (fun h => density q t h*L h) (reference n k) := + integrable_relativeEntropyIntegrand p q hp t k + have hLift := integrable_lift q ht L hL hiL + have hi := (integrable_relativeEntropyIntegrand p q hp t (k+1)).sub hLift + have he : (fun hz : History n (k+1) => relativeEntropyIntegrand p q t hz-density q t hz*L hz.1) = + fun hz => density q t hz.1*(GaussianStep.density (posterior q t hz.1) t hz.2* + log (GaussianStep.density (posterior q t hz.1) t hz.2/GaussianStep.density (posterior p t hz.1) t hz.2)) := by + funext ⟨h,z⟩ + rw [relativeEntropy_succ] + dsimp [L] + ring + change Integrable (fun hz : History n (k+1) => relativeEntropyIntegrand p q t hz- + density q t hz*L hz.1) ((reference n k).prod (GaussianStep.reference n)) at hi + rw [he] at hi + have hh := hi.integral_prod_left + simp_rw [integral_const_mul,GaussianStep.integral_relativeEntropy _ _ ht] at hh + exact hh + +lemma entropy_step_history_bound (p q : Prior n) (hp : ∀x,0

(mul_le_mul_of_nonneg_left + (GaussianStep.entropy_step_bound (posterior p t h) (posterior q t h) ht htn) + (density_pos q t h).le).trans_eq (by dsimp [driftSquare]; ring)) + simp only [Pi.add_apply] at hh + rw [integral_add ((integrable_driftSquare_weight p q t k).const_mul t) + ((integrable_density q t k).mul_const (64*(n:ℝ)^2*t^2)),integral_const_mul, + integral_mul_const,integral_density q ht,one_mul] at hh + linarith + +lemma drift_integral_bound (p : Prior n) (hp : ∀x,0

(f x)^2)) {t : ℝ} (ht : 0≤t) (k : ℕ) + (B : Set (History n k)) (hB : MeasurableSet B) (W A : ℝ) (hW : 0≤W) (hA : 0≤A) + (hgood : ∀h:History n k,h∉B → driftSquare p (squarePrior p f hf) t h ≤ + W*(n:ℝ)+A*sqrt (n:ℝ)*(2+energy (posterior p t h) f/avg (posterior p t h) (fun x => (f x)^2))) : + (∫h:History n k,density (squarePrior p f hf) t h*driftSquare p (squarePrior p f hf) t h ∂reference n k) ≤ + W*(n:ℝ)+A*sqrt (n:ℝ)*(2+energy p f/avg p (fun x => (f x)^2))+ + 4*(n:ℝ)*eventProbability (squarePrior p f hf) t B := by + let q:=squarePrior p f hf + let N:=avg p (fun x => (f x)^2) + let d : History n k→ℝ := fun h => density p t h*energy (posterior p t h) f + have hiD : Integrable d (reference n k) := integrable_posterior_energy_weight p hp t k f + have hiQ := integrable_density q t k + have hiB := hiQ.indicator hB + have hpoint (h : History n k) : density q t h*driftSquare p q t h ≤ + (W*(n:ℝ)+2*A*sqrt (n:ℝ))*density q t h+ + (A*sqrt (n:ℝ)/N)*d h+4*(n:ℝ)*B.indicator (density q t) h := by + have he := weighted_energy_identity p f hf t h + change density q t h*(energy (posterior p t h) f/avg (posterior p t h) (fun x => (f x)^2)) = d h/N at he + have hd0 : 0≤d h := mul_nonneg (density_pos p t h).le (energy_nonneg _ _) + have hconst : 0≤(W*(n:ℝ)+2*A*sqrt (n:ℝ))*density q t h := + mul_nonneg (by positivity) (density_pos q t h).le + have hdpos : 0≤(A*sqrt (n:ℝ)/N)*d h := mul_nonneg (div_nonneg (mul_nonneg hA (sqrt_nonneg _)) hf.le) hd0 + by_cases hb : h∈B + · rw [Set.indicator_of_mem hb] + have hh:=mul_le_mul_of_nonneg_left (driftSquare_le p q t h) (density_pos q t h).le + nlinarith + · rw [Set.indicator_of_notMem hb,mul_zero,add_zero] + have hh:=mul_le_mul_of_nonneg_left (hgood h hb) (density_pos q t h).le + calc + _≤density q t h*(W*(n:ℝ)+A*sqrt (n:ℝ)*(2+energy (posterior p t h) f/avg (posterior p t h) (fun x => (f x)^2))) := hh + _=(W*(n:ℝ)+2*A*sqrt (n:ℝ))*density q t h+A*sqrt (n:ℝ)* + (density q t h*(energy (posterior p t h) f/avg (posterior p t h) (fun x => (f x)^2))) := by ring + _=_ := by rw [he]; ring + have hi1 := hiQ.const_mul (W*(n:ℝ)+2*A*sqrt (n:ℝ)) + have hi2 := hiD.const_mul (A*sqrt (n:ℝ)/N) + have hi3 := hiB.const_mul (4*(n:ℝ)) + have hi12 : Integrable (fun h => (W*(n:ℝ)+2*A*sqrt (n:ℝ))*density q t h+ + (A*sqrt (n:ℝ)/N)*d h) (reference n k) := hi1.add hi2 + have hh := integral_mono (integrable_driftSquare_weight p q t k) (hi12.add hi3) hpoint + simp only [Pi.add_apply] at hh + rw [integral_add hi12 hi3,integral_add hi1 hi2,integral_const_mul, + integral_const_mul,integral_const_mul,integral_density q ht,integral_indicator hB,mul_one] at hh + have hd:=mul_le_mul_of_nonneg_left (energy_history_bound p hp ht k f) + (show 0≤A*sqrt (n:ℝ)/N from div_nonneg (mul_nonneg hA (sqrt_nonneg _)) hf.le) + change _≤(W*(n:ℝ)+2*A*sqrt (n:ℝ))+(A*sqrt (n:ℝ)/N)*(∫h,d h ∂reference n k)+ + 4*(n:ℝ)*eventProbability q t B at hh + change (A*sqrt (n:ℝ)/N)*(∫h,d h ∂reference n k)≤(A*sqrt (n:ℝ)/N)*energy p f at hd + dsimp [N,q] at hh hd + simp only [div_eq_mul_inv] at hh hd ⊢ + nlinarith + +theorem entropy_good_step (p : Prior n) (hp : ∀x,0

(f x)^2)) {t : ℝ} (ht : 0≤t) (htn : 4*(n:ℝ)*t≤1) (k : ℕ) + (B : Set (History n k)) (hB : MeasurableSet B) (W A a : ℝ) + (hW : 0≤W) (hA : 0≤A) (ha : 0 (f x)^2))) : + entropy p (squarePrior p f hf) t (k+1)≤ + (1+4*t/a)*entropy p (squarePrior p f hf) t k+ + t*(W*(n:ℝ)+A*sqrt (n:ℝ)*(2+energy p f/avg p (fun x => (f x)^2))+4/a)+ + 64*(n:ℝ)^2*t^2 := by + have hs:=entropy_step_history_bound p (squarePrior p f hf) hp ht htn k + have hd:=mul_le_mul_of_nonneg_left (drift_integral_bound p hp f hf ht k B hB W A hW hA hgood) ht + have he:=entropy_event_bound p (squarePrior p f hf) hp ht k B hB (a*(n:ℝ)) + (by simpa only [neg_mul] using hsmall) + have he':=mul_le_mul_of_nonneg_left he (show 0≤4*t/a by positivity) + have heq : (4*t/a)*(a*(n:ℝ)*eventProbability (squarePrior p f hf) t B)= + t*(4*(n:ℝ)*eventProbability (squarePrior p f hf) t B) := by field_simp + rw [heq] at he' + simp only [div_eq_mul_inv] at hs hd he' ⊢ + nlinarith + +end +end SKGap.GaussianHistory + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/EmpiricalConditionalData.lean b/lean/OAI/Probability/SKGap/Localization/EmpiricalConditionalData.lean new file mode 100644 index 0000000000000000000000000000000000000000..00b82087fe9c0b357a9f733fcd139a9ecf879cf9 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/EmpiricalConditionalData.lean @@ -0,0 +1,109 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.EmpiricalGramBound +import OAI.Probability.SKGap.Localization.CompactTube + +namespace OAI + +section +noncomputable section +namespace SKGap +open Real Matrix MeasureTheory ProbabilityTheory Set +open scoped BigOperators Matrix.Norms.Frobenius + +lemma conditionalSize_bounds {j : ℝ} {p : ScalarPoint} {r L : ℝ} + (hq : 0 < scalarQMoment p.1) (hs : 0 < scalarS j p) + (hB : 0 < j*scalarBMoment p.1+r) (hsize : conditionalScalarSize j p r < L) : + (1+|scalarD j p|)/scalarS j p < L ∧ 1/scalarQMoment p.1 < L ∧ + 1/scalarS j p < L ∧ 1/(j*scalarBMoment p.1+r) < L ∧ + j*scalarBMoment p.1+r < L ∧ ‖conditionalScalarData j p‖ < L := by + have h1 : 0 ≤ (1+|scalarD j p|)/scalarS j p := by positivity + have h2 : 0 ≤ 1/scalarQMoment p.1 := by positivity + have h3 : 0 ≤ 1/scalarS j p := by positivity + have h4 : 0 ≤ 1/(j*scalarBMoment p.1+r) := by positivity + have h5 := norm_nonneg (conditionalScalarData j p) + unfold conditionalScalarSize at hsize + constructor; linarith + constructor; linarith + constructor; linarith + constructor; linarith + constructor <;> linarith + +lemma empiricalGramColumns_norm {n : ℕ} (hn : 0 < n) (y : Fin n → ℝ) + {d s L R : ℝ} (hs : 0 < s) (hL : 1 ≤ L) (hR : 0 ≤ R) + (hd : (1+|d|)/s ≤ L) (hy : ∑ i,y i^2 ≤ R^2*(n:ℝ)) (r : Fin 3) : + ‖empiricalGramColumns y d s r‖ ≤ 2*L*(R+1) := by + have hnR : 0 < (n:ℝ) := by exact_mod_cast hn + have hb (i : Fin n) : (gramCoordinates d s (y i) r)^2 ≤ 2*L^2*(1+y i^2) := by + simpa only [← sq,abs_pow, sq_abs] using gramCoordinates_product_bound hs hL hd (y i) r r + have hsq : ‖empiricalGramColumns y d s r‖^2 ≤ 2*L^2*(1+R^2) := by + rw [EuclideanSpace.real_norm_sq_eq] + simp only [empiricalGramColumns,PiLp.toLp_apply,div_pow,Real.sq_sqrt hnR.le] + rw [← Finset.sum_div] + apply (div_le_iff₀ hnR).mpr + calc + _ ≤ ∑ i,2*L^2*(1+y i^2) := Finset.sum_le_sum (fun i _=>hb i) + _ = 2*L^2*((n:ℝ)+∑ i,y i^2) := by rw [← Finset.mul_sum,Finset.sum_add_distrib]; simp + _ ≤ 2*L^2*((n:ℝ)+R^2*(n:ℝ)) := mul_le_mul_of_nonneg_left (add_le_add_right hy _) (by positivity) + _ = _ := by ring + have hcmp : 2*L^2*(1+R^2) ≤ (2*L*(R+1))^2 := by + nlinarith [mul_nonneg (sq_nonneg L) hR, sq_nonneg (L*R)] + exact (sq_le_sq₀ (norm_nonneg _) (by positivity)).mp (hsq.trans hcmp) + +def empiricalUnit {n : ℕ} (y : Fin n → ℝ) (q : ℝ) : EuclideanSpace ℝ (Fin n) := + WithLp.toLp 2 (fun i=>tanh (y i)/sqrt ((n:ℝ)*q)) + +lemma empiricalUnit_unit {n : ℕ} [NeZero n] (y : Fin n → ℝ) + (hq : 0 < scalarQMoment (empiricalLaw y)) : + (empiricalUnit y (scalarQMoment (empiricalLaw y))).ofLp⬝ᵥ + (empiricalUnit y (scalarQMoment (empiricalLaw y))).ofLp=1 := by + have hn : 0 < (n:ℝ) := by exact_mod_cast NeZero.pos n + have hsum : ∑ i,tanh (y i)^2=(n:ℝ)*scalarQMoment (empiricalLaw y) := by + simpa only [scalarQMoment,Fintype.card_fin] using (card_mul_integral_empiricalLaw y (fun x=>tanh x^2)).symm + simp only [empiricalUnit,WithLp.ofLp_toLp,dotProduct,← sq,div_pow,Real.sq_sqrt (mul_nonneg hn.le hq.le)] + rw [← Finset.sum_div,hsum,div_self (mul_pos hn hq).ne'] + +lemma empiricalUnit_norm {n : ℕ} [NeZero n] (y : Fin n → ℝ) + (hq : 0 < scalarQMoment (empiricalLaw y)) : + ‖empiricalUnit y (scalarQMoment (empiricalLaw y))‖=1 := by + have hh := empiricalUnit_unit y hq + have he : ‖empiricalUnit y (scalarQMoment (empiricalLaw y))‖^2=1 := by + simpa only [EuclideanSpace.real_norm_sq_eq,dotProduct,← sq] using hh + nlinarith [norm_nonneg (empiricalUnit y (scalarQMoment (empiricalLaw y)))] + +lemma normalized_average_l2 {n : ℕ} (hn : 0 < n) (d : Fin n → ℝ) {ε : ℝ} + (hε : 0 ≤ ε) (hd : ∑ i,d i^2 ≤ ε^2*(n:ℝ)) : + |(n:ℝ)⁻¹*∑ i,d i| ≤ ε := by + have hnR : 0 < (n:ℝ) := by exact_mod_cast hn + have hs : sqrt (∑ i,d i^2) ≤ ε*sqrt (n:ℝ) := by + apply Real.sqrt_le_iff.mpr + refine ⟨by positivity,?_⟩ + simpa only [mul_pow,Real.sq_sqrt hnR.le] using hd + have hh := (Finset.abs_sum_le_sum_abs d Finset.univ).trans (sum_abs_le_sqrt_card_l2 d) + simp only [Fintype.card_fin] at hh + have hh' : |∑ i,d i| ≤ ε*(n:ℝ) := by + apply hh.trans + apply (mul_le_mul_of_nonneg_left hs (sqrt_nonneg _)).trans_eq + calc + _ = ε*(sqrt (n:ℝ))^2 := by ring + _ = _ := by rw [sq_sqrt hnR.le] + rw [abs_mul,abs_of_pos (inv_pos.mpr hnR)] + have hp := mul_le_mul_of_nonneg_left hh' (inv_nonneg.mpr hnR.le) + convert hp using 1; first | rfl | field_simp + +lemma empirical_mass_close {n : ℕ} [NeZero n] (a y : Fin n → ℝ) {j ε : ℝ} + (hj : 0 ≤ j) (hε : 0 ≤ ε) + (hd : ∑ i,(a i-(1-tanh (y i)^2))^2 ≤ ε^2*(n:ℝ)) : + |j/(n:ℝ)*∑ i,a i-j*scalarBMoment (empiricalLaw y)| ≤ j*ε := by + have hb : scalarBMoment (empiricalLaw y)=(n:ℝ)⁻¹*∑ i,(1-tanh (y i)^2) := by + rw [scalarBMoment_integral] + simpa only [scalarGramVariance,Fintype.card_fin] using integral_empiricalLaw y (fun x=>1-tanh x^2) + rw [hb] + have he : j/(n:ℝ)*∑ i,a i-j*((n:ℝ)⁻¹*∑ i,(1-tanh (y i)^2))= + j*((n:ℝ)⁻¹*∑ i,(a i-(1-tanh (y i)^2))) := by simp only [Finset.sum_sub_distrib]; ring + rw [he,abs_mul,abs_of_nonneg hj] + exact mul_le_mul_of_nonneg_left (normalized_average_l2 (NeZero.pos n) _ hε hd) hj +end SKGap +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/EmpiricalGramBound.lean b/lean/OAI/Probability/SKGap/Localization/EmpiricalGramBound.lean new file mode 100644 index 0000000000000000000000000000000000000000..10b2de4276ed14591b2740d54bb8cb85a379625b --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/EmpiricalGramBound.lean @@ -0,0 +1,107 @@ +import Mathlib +import OAI.Probability.SKGap.Entropy.WeightedMomentComparison +import OAI.Probability.SKGap.Gaussian.ScalarMomentGram +import OAI.Probability.SKGap.Gaussian.ConditionalGramTail +import OAI.Probability.SKGap.Localization.GramUniformRobust + +namespace OAI + +section +noncomputable section +namespace SKGap +open Real Matrix MeasureTheory ProbabilityTheory Set +open scoped BigOperators Matrix.Norms.Frobenius + +lemma gramCoordinates_bound {d s L : ℝ} (hs : 0 < s) (hL : 1 ≤ L) + (hd : (1+|d|)/s ≤ L) (y : ℝ) (r : Fin 3) : + |gramCoordinates d s y r| ≤ L*(1+|y|) := by + have hLy : L ≤ L*(1+|y|) := by nlinarith [mul_nonneg (by linarith : 0 ≤ L) (abs_nonneg y)] + fin_cases r + · simpa [gramCoordinates] using hL.trans hLy + · simpa [gramCoordinates] using (abs_tanh_lt_one y).le.trans (hL.trans hLy) + · simp only [gramCoordinates,Matrix.cons_val,Fin.reduceFinMk,abs_div,abs_of_pos hs] + apply (div_le_div_of_nonneg_right (abs_sub y d) hs.le).trans + calc + _ ≤ ((1+|d|)/s)*(1+|y|) := by + rw [div_mul_eq_mul_div,div_le_div_iff_of_pos_right hs] + nlinarith [mul_nonneg (abs_nonneg d) (abs_nonneg y)] + _ ≤ _ := mul_le_mul_of_nonneg_right hd (by positivity) + +lemma gramCoordinates_product_bound {d s L : ℝ} (hs : 0 < s) (hL : 1 ≤ L) + (hd : (1+|d|)/s ≤ L) (y : ℝ) (r k : Fin 3) : + |gramCoordinates d s y r*gramCoordinates d s y k| ≤ 2*L^2*(1+y^2) := by + rw [abs_mul] + have hp := mul_le_mul (gramCoordinates_bound hs hL hd y r) + (gramCoordinates_bound hs hL hd y k) (abs_nonneg _) (by positivity : 0 ≤ L*(1+|y|)) + have hx : (1+|y|)^2 ≤ 2*(1+y^2) := by nlinarith [sq_nonneg (|y|-1),sq_abs y] + nlinarith [mul_le_mul_of_nonneg_left hx (sq_nonneg L)] + +def empiricalGramColumns {n : ℕ} (y : Fin n → ℝ) (d s : ℝ) : + Fin 3 → EuclideanSpace ℝ (Fin n) := fun r => WithLp.toLp 2 (fun i => gramCoordinates d s (y i) r/√(n:ℝ)) + +lemma diagonal_empirical_gram_entry {n : ℕ} (hn : 0 < n) (a y : Fin n → ℝ) (d s : ℝ) (r k : Fin 3) : + matrixPair (diagonal a) (empiricalGramColumns y d s r).ofLp + (empiricalGramColumns y d s k).ofLp= + (n:ℝ)⁻¹*∑ i,a i*gramCoordinates d s (y i) r*gramCoordinates d s (y i) k := by + have hnR : 0 < (n:ℝ) := by exact_mod_cast hn + simp only [matrixPair,Matrix.mulVec_diagonal,empiricalGramColumns,WithLp.ofLp_toLp,dotProduct] + rw [Finset.mul_sum] + apply Finset.sum_congr rfl + intro i _ + have hn0 : √(n:ℝ) ≠ 0 := (Real.sqrt_pos.2 hnR).ne' + field_simp + rw [Real.sq_sqrt hnR.le] + ring + +theorem empirical_augmented_gram_comparison {n : ℕ} [NeZero n] + (a y : Fin n → ℝ) {d s L D R ε ν : ℝ} (hs : 0 < s) (hL : 1 ≤ L) + (hd : (1+|d|)/s ≤ L) (hD : 0 ≤ D) (hR : 1 ≤ R) (hε : 0 ≤ ε) (hν : 0 ≤ ν) + (ha : ∀ i,|a i-(1-tanh (y i)^2)| ≤ D) + (hclose : ∑ i,(a i-(1-tanh (y i)^2))^2 ≤ ε^2*(n:ℝ)) + (htail : (∑ i,if R < |y i| then y i^2 else 0) ≤ ν*(n:ℝ)) : + ‖diagonalAugmentedGram a (empiricalGramColumns y d s)- + augmentedGram (ν := Unit) (scalarMomentGram (empiricalLaw y) d s)‖ ≤ + 4*(2*L^2*(1+R^2)*ε+4*L^2*D*ν) := by + have hn : 0 < n := NeZero.pos n + have he (r k : Fin 3) : |matrixPair (diagonal a) (empiricalGramColumns y d s r).ofLp + (empiricalGramColumns y d s k).ofLp-scalarMomentGram (empiricalLaw y) d s r k| ≤ + 2*L^2*(1+R^2)*ε+4*L^2*D*ν := by + rw [diagonal_empirical_gram_entry hn,scalarMomentGram_empirical] + have hsmall (i : Fin n) (hi : |y i| ≤ R) : + |gramCoordinates d s (y i) r*gramCoordinates d s (y i) k| ≤ 2*L^2*(1+R^2) := by + apply (gramCoordinates_product_bound hs hL hd (y i) r k).trans + have hy : y i^2 ≤ R^2 := by + simpa only [sq_abs] using (sq_le_sq₀ (abs_nonneg (y i)) (by linarith : 0 ≤ R)).mpr hi + exact mul_le_mul_of_nonneg_left (by linarith) (by positivity) + have hb := normalized_weighted_moment_comparison hn a (fun i=>1-tanh (y i)^2) y + (fun i=>gramCoordinates d s (y i) r*gramCoordinates d s (y i) k) + (H := 2*L^2*(1+R^2)) (C := 2*L^2) (D := D) (R := R) (by positivity) + (by positivity) hD hR hε ha hsmall (fun i=>gramCoordinates_product_bound hs hL hd (y i) r k) + hclose htail + have hid : (n:ℝ)⁻¹*(∑ i,a i*gramCoordinates d s (y i) r*gramCoordinates d s (y i) k)- + (n:ℝ)⁻¹*(∑ i,(1-tanh (y i)^2)*gramCoordinates d s (y i) r*gramCoordinates d s (y i) k)= + (∑ i,(a i-(1-tanh (y i)^2))*(gramCoordinates d s (y i) r*gramCoordinates d s (y i) k))/(n:ℝ) := by + rw [← mul_sub,← Finset.sum_sub_distrib,div_eq_mul_inv,mul_comm _ (n:ℝ)⁻¹] + congr 1 + apply Finset.sum_congr rfl + intro i _;ring + rw [hid] + convert hb using 1; ring + have hb0 : 0 ≤ 2*L^2*(1+R^2)*ε+4*L^2*D*ν := by positivity + have hb := frobenius_le_card_bound (M := diagonalAugmentedGram a (empiricalGramColumns y d s)- + augmentedGram (ν := Unit) (scalarMomentGram (empiricalLaw y) d s)) + (ε := 2*L^2*(1+R^2)*ε+4*L^2*D*ν) (by positivity) (by + intro r k + cases r with + | inl r => cases k with + | inl k => exact he r k + | inr k => change |(0:ℝ)-0| ≤ _; simpa only [sub_zero,abs_zero] using hb0 + | inr r => cases k with + | inl k => change |(0:ℝ)-0| ≤ _; simpa only [sub_zero,abs_zero] using hb0 + | inr k => change |(1:ℝ)-1| ≤ _; simpa only [sub_self,abs_zero] using hb0) + simpa using hb +end SKGap +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/EmpiricalLaw.lean b/lean/OAI/Probability/SKGap/Localization/EmpiricalLaw.lean new file mode 100644 index 0000000000000000000000000000000000000000..8c2f982fbb9c916a267760385b8990f582c2802e --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/EmpiricalLaw.lean @@ -0,0 +1,49 @@ +import Mathlib +import OAI.Probability.SKGap.Model + +namespace OAI + +section +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set Topology Real +open scoped NNReal ENNReal BoundedContinuousFunction +namespace SKGap + +variable {ι : Type*} [Fintype ι] [Nonempty ι] + +def empiricalLaw (y : ι → ℝ) : ProbabilityMeasure ℝ := + ⟨(Fintype.card ι : ℝ≥0∞)⁻¹ • ∑ i, Measure.dirac (y i), ⟨by + rw [Measure.smul_apply, Measure.finsetSum_apply] + simp only [Measure.dirac_apply_of_mem (mem_univ _), Finset.sum_const, Finset.card_univ, nsmul_eq_mul, mul_one, smul_eq_mul] + exact ENNReal.inv_mul_cancel (by exact_mod_cast ((Fintype.card_pos (α := ι)).ne')) (by simp)⟩⟩ + +lemma empiricalLaw_coe (y : ι → ℝ) : (empiricalLaw y : Measure ℝ) = + (Fintype.card ι : ℝ≥0∞)⁻¹ • ∑ i, Measure.dirac (y i) := rfl + +lemma integrable_empiricalLaw (y : ι → ℝ) (f : ℝ → ℝ) : Integrable f (empiricalLaw y : Measure ℝ) := by + rw [empiricalLaw_coe] + apply Integrable.smul_measure + · exact integrable_finsetSum_measure.mpr (fun i _ => integrable_dirac (by simp)) + · exact ENNReal.inv_ne_top.mpr (by exact_mod_cast ((Fintype.card_pos (α := ι)).ne')) + +lemma integral_empiricalLaw (y : ι → ℝ) (f : ℝ → ℝ) : + (∫ x, f x ∂empiricalLaw y) = (Fintype.card ι : ℝ)⁻¹ * ∑ i, f (y i) := by + rw [empiricalLaw_coe, integral_smul_measure, + integral_finsetSum_measure (fun i _ => integrable_dirac (by simp))] + simp only [integral_dirac, ENNReal.toReal_inv, ENNReal.toReal_natCast, smul_eq_mul] + +lemma card_mul_integral_empiricalLaw (y : ι → ℝ) (f : ℝ → ℝ) : + (Fintype.card ι : ℝ)*(∫ x, f x ∂empiricalLaw y) = ∑ i, f (y i) := by + rw [integral_empiricalLaw, ← mul_assoc, mul_inv_cancel₀ (by exact_mod_cast (Fintype.card_pos (α := ι)).ne'), one_mul] + +lemma continuous_empiricalLaw : Continuous (empiricalLaw (ι := ι)) := by + rw [ProbabilityMeasure.continuous_iff_forall_continuous_integral] + intro f + simp_rw [integral_empiricalLaw] + fun_prop + +end SKGap +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/EntryLM.lean b/lean/OAI/Probability/SKGap/Localization/EntryLM.lean new file mode 100644 index 0000000000000000000000000000000000000000..ca5cca1574187378d12137d6457a5773376439a9 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/EntryLM.lean @@ -0,0 +1,202 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.LinSub + +namespace OAI + +noncomputable section + +open MeasureTheory ProbabilityTheory InformationTheory Real Set +open scoped NNReal ENNReal +open Filter +open scoped Topology +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius ENNReal NNReal +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius NNReal +open MeasureTheory ProbabilityTheory Real Set Filter +open MeasureTheory.Measure +open scoped ENNReal NNReal MeasureTheory Topology +open MeasureTheory +open MeasureTheory Set NormedSpace +open scoped Topology +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius +namespace SKGap.ComplexMatrix + +section +open MeasureTheory Set NormedSpace +open scoped Topology FourierTransform SchwartzMap +variable {ι : Type*} [Fintype ι] [DecidableEq ι] + +local instance : ContinuousENorm (Matrix ι ι ℂ) := + @SeminormedAddGroup.toContinuousENorm _ Matrix.frobeniusSeminormedAddCommGroup.toSeminormedAddGroup +local instance : TopologicalSpace.PseudoMetrizableSpace (Matrix ι ι ℂ) := + inferInstanceAs (TopologicalSpace.PseudoMetrizableSpace (ι → ι → ℂ)) + +def entryLM (i j : ι) : Matrix ι ι ℂ →ₗ[ℂ] ℂ where + toFun := fun M => M i j + map_add' := by intros; rfl + map_smul' := by intros; rfl + +def entryCLM (i j : ι) : Matrix ι ι ℂ →L[ℂ] ℂ := (entryLM i j).toContinuousLinearMap + +lemma integral_entry {F : ℝ → Matrix ι ι ℂ} (hF : Integrable F) (i j : ι) : + (∫ t : ℝ, F t) i j = ∫ t : ℝ, F t i j := by + exact ((entryCLM i j).integral_comp_comm hF).symm + +def conjugate (U : unitary (Matrix ι ι ℂ)) : Matrix ι ι ℂ ≃⋆ₐ[ℂ] Matrix ι ι ℂ := + Unitary.conjStarAlgAut ℂ _ U + +def conjugateCLM (U : unitary (Matrix ι ι ℂ)) : Matrix ι ι ℂ →L[ℂ] Matrix ι ι ℂ := + (conjugate U).toAlgEquiv.toLinearMap.toContinuousLinearMap + +lemma conjugate_exp (U : unitary (Matrix ι ι ℂ)) (M : Matrix ι ι ℂ) : + conjugate U (exp M) = exp (conjugate U M) := by + exact NormedSpace.map_exp (conjugate U).toRingHom (conjugateCLM U).continuous M + +lemma conjugate_imaginary (U : unitary (Matrix ι ι ℂ)) (t : ℝ) (M : Matrix ι ι ℂ) : + conjugate U (imaginary t M) = imaginary t (conjugate U M) := by + exact (conjugate U).map_smul' _ _ + +lemma kernelMatrix_conjugate {g : ℝ → ℂ} (hg : Integrable g) (U : unitary (Matrix ι ι ℂ)) + (M : Matrix ι ι ℂ) (hM : Mᴴ = M) : + kernelMatrix g (conjugate U M) = conjugate U (kernelMatrix g M) := by + have hi := (conjugateCLM U).integral_comp_comm (kernel_integrable hg M hM) + change _ = (conjugateCLM U) (∫ t : ℝ, g t • exp (imaginary t M)) + calc + _ = ∫ t : ℝ, (conjugateCLM U) (g t • exp (imaginary t M)) := by + apply integral_congr_ae + filter_upwards [] with t + change g t • exp (imaginary t (conjugate U M)) = conjugate U (g t • exp (imaginary t M)) + rw [map_smul,conjugate_exp,conjugate_imaginary] + _ = _ := hi + +lemma kernelMatrix_diagonal {g : ℝ → ℂ} (hg : Integrable g) (x : ι → ℝ) : + kernelMatrix g (diagonal (fun i => (x i : ℂ))) = + diagonal (fun i => ∫ t : ℝ, g t * Complex.exp ((t : ℂ)*Complex.I*(x i : ℂ))) := by + have hD : (diagonal (fun i => (x i : ℂ)))ᴴ = diagonal (fun i => (x i : ℂ)) := by + simp [Matrix.diagonal_conjTranspose] + ext i j + rw [kernelMatrix,integral_entry (kernel_integrable hg _ hD)] + have hexp (t : ℝ) : exp (imaginary t (diagonal (fun i => (x i : ℂ)))) = + diagonal (fun i => Complex.exp ((t : ℂ)*Complex.I*(x i : ℂ))) := by + rw [imaginary,← diagonal_smul,Matrix.exp_diagonal] + congr 1 + ext i + rw [Pi.coe_exp,← Complex.exp_eq_exp_ℂ] + rfl + simp_rw [hexp,Matrix.smul_apply,smul_eq_mul] + by_cases hij : i = j + · subst j; simp + · simp [hij] + +noncomputable def schwartzMatrix (f : 𝓢(ℝ, ℂ)) (M : Matrix ι ι ℂ) : Matrix ι ι ℂ := + kernelMatrix ((𝓕 f : 𝓢(ℝ,ℂ)) : ℝ → ℂ) ((2*Real.pi : ℝ) • M) + +lemma fourier_scalar_inverse (f : 𝓢(ℝ, ℂ)) (x : ℝ) : + (∫ t : ℝ, (𝓕 f) t * Complex.exp ((t : ℂ)*Complex.I*((2*Real.pi*x : ℝ) : ℂ))) = f x := by + have hh := congrArg (fun g : 𝓢(ℝ,ℂ) => g x) (show (𝓕⁻ (𝓕 f : 𝓢(ℝ,ℂ)) : 𝓢(ℝ,ℂ)) = f from FourierTransform.fourierInv_fourier_eq f) + rw [SchwartzMap.fourierInv_coe,Real.fourierInv_eq'] at hh + rw [← hh] + apply integral_congr_ae + filter_upwards [] with t + simp only [smul_eq_mul,Real.inner_apply] + conv_lhs => rw [mul_comm] + congr 1 + congr 1 + push_cast + ring + +lemma schwartzMatrix_diagonal (f : 𝓢(ℝ,ℂ)) (x : ι → ℝ) : + schwartzMatrix f (diagonal (fun i => (x i : ℂ))) = diagonal (fun i => f (x i)) := by + rw [schwartzMatrix,← diagonal_smul] + have heq : (2*Real.pi : ℝ) • (fun i => (x i : ℂ)) = fun i => ((2*Real.pi*x i : ℝ) : ℂ) := by + ext i; simp + rw [heq,kernelMatrix_diagonal (𝓕 f).integrable] + congr 1 + ext i + exact fourier_scalar_inverse f (x i) + +lemma schwartzMatrix_conjugate (f : 𝓢(ℝ,ℂ)) (U : unitary (Matrix ι ι ℂ)) + (M : Matrix ι ι ℂ) (hM : Mᴴ = M) : + schwartzMatrix f (conjugate U M) = conjugate U (schwartzMatrix f M) := by + have heq : (2*Real.pi : ℝ) • conjugate U M = conjugate U ((2*Real.pi : ℝ) • M) := by + simp [conjugate,Unitary.conjStarAlgAut_apply] + rw [schwartzMatrix,heq] + exact kernelMatrix_conjugate (𝓕 f).integrable U _ (by simp [hM]) + +lemma schwartzMatrix_spectral (f : 𝓢(ℝ,ℂ)) (M : Matrix ι ι ℂ) (hM : M.IsHermitian) : + schwartzMatrix f M = conjugate hM.eigenvectorUnitary (diagonal (fun i => f (hM.eigenvalues i))) := by + conv_lhs => rw [hM.spectral_theorem] + change schwartzMatrix f (conjugate hM.eigenvectorUnitary (diagonal (fun i => (hM.eigenvalues i : ℂ)))) = _ + rw [schwartzMatrix_conjugate f _ _ (by simp [Matrix.diagonal_conjTranspose]),schwartzMatrix_diagonal] + +end + +open MeasureTheory Set NormedSpace +open scoped Topology FourierTransform SchwartzMap +variable {ι : Type*} [Fintype ι] [DecidableEq ι] +local instance : ContinuousENorm (Matrix ι ι ℂ) := + @SeminormedAddGroup.toContinuousENorm _ Matrix.frobeniusSeminormedAddCommGroup.toSeminormedAddGroup +local instance : TopologicalSpace.PseudoMetrizableSpace (Matrix ι ι ℂ) := + inferInstanceAs (TopologicalSpace.PseudoMetrizableSpace (ι → ι → ℂ)) + +def linCLM : Matrix ι ι ℂ →L[ℂ] (EuclideanSpace ℂ ι →L[ℂ] EuclideanSpace ℂ ι) := + (linEquiv (ι := ι)).toLinearMap.toContinuousLinearMap + +lemma opNorm_kernelMatrix {g : ℝ → ℂ} (hg : Integrable g) + (M : Matrix ι ι ℂ) (hM : Mᴴ = M) : + opNorm (kernelMatrix g M) ≤ ∫ t : ℝ, ‖g t‖ := by + let : CompleteSpace (EuclideanSpace ℂ ι →L[ℂ] EuclideanSpace ℂ ι) := + ContinuousLinearMap.instCompleteSpace + have hi := linCLM.integral_comp_comm (kernel_integrable hg M hM) + change ‖linCLM (∫ t : ℝ, g t • exp (imaginary t M))‖ ≤ _ + calc + _ = ‖∫ t : ℝ, linCLM (g t • exp (imaginary t M))‖ := congrArg norm hi.symm + _ ≤ ∫ t : ℝ, ‖linCLM (g t • exp (imaginary t M))‖ := norm_integral_le_integral_norm _ + _ ≤ ∫ t : ℝ, ‖g t‖ := by + apply integral_mono (linCLM.integrable_comp (kernel_integrable hg M hM)).norm hg.norm + intro t + change ‖lin (g t • exp (imaginary t M))‖ ≤ _ + rw [lin_csmul,norm_smul] + exact (mul_le_mul_of_nonneg_left (imaginary_exp_opNorm_le t M hM) (norm_nonneg _)).trans_eq (mul_one _) + +lemma schwartzMatrix_opNorm (f : 𝓢(ℝ,ℂ)) (M : Matrix ι ι ℂ) (hM : Mᴴ = M) : + opNorm (schwartzMatrix f M) ≤ ∫ t : ℝ, ‖(𝓕 f) t‖ := + opNorm_kernelMatrix (𝓕 f).integrable _ (by simp [hM]) + +lemma schwartzMatrix_eq_inverse (f : 𝓢(ℝ,ℂ)) {lo hi : ℝ} (hlo : 0 < lo) + (hf : ∀ x ∈ Icc lo hi, f x = (x : ℂ)⁻¹) + (M : Matrix ι ι ℂ) (hM : M.IsHermitian) + (hspec : ∀ i, hM.eigenvalues i ∈ Icc lo hi) : + schwartzMatrix f M = M⁻¹ := by + rw [schwartzMatrix_spectral f M hM] + symm + apply Matrix.inv_eq_left_inv + conv_lhs => rhs; rw [hM.spectral_theorem] + change conjugate hM.eigenvectorUnitary (diagonal (fun i => f (hM.eigenvalues i))) * + conjugate hM.eigenvectorUnitary (diagonal (fun i => (hM.eigenvalues i : ℂ))) = 1 + rw [← map_mul,diagonal_mul_diagonal] + have hd : diagonal (fun i => f (hM.eigenvalues i) * (hM.eigenvalues i : ℂ)) = (1 : Matrix ι ι ℂ) := by + have hz (i : ι) : (hM.eigenvalues i : ℂ) ≠ 0 := by exact_mod_cast ne_of_gt (lt_of_lt_of_le hlo (hspec i).1) + simp_rw [hf _ (hspec _),inv_mul_cancel₀ (hz _)] + exact diagonal_one + rw [hd,map_one] + +lemma schwartzMatrix_hermitian (f : 𝓢(ℝ,ℂ)) (hf : ∀ x, star (f x) = f x) + (M : Matrix ι ι ℂ) (hM : M.IsHermitian) : (schwartzMatrix f M).IsHermitian := by + rw [schwartzMatrix_spectral f M hM] + change star (conjugate hM.eigenvectorUnitary (diagonal _)) = _ + rw [← map_star] + congr 1 + change (diagonal (fun i => f (hM.eigenvalues i)))ᴴ = _ + rw [Matrix.diagonal_conjTranspose] + congr 1 + funext i + exact hf (hM.eigenvalues i) + +end SKGap.ComplexMatrix + +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/Envelope.lean b/lean/OAI/Probability/SKGap/Localization/Envelope.lean new file mode 100644 index 0000000000000000000000000000000000000000..4ec514ffdda96e4e28645ce3991512d9c2bc256a --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/Envelope.lean @@ -0,0 +1,194 @@ +import Mathlib +import OAI.Probability.SKGap.Brownian.ContinuousPosteriorMass + +namespace OAI + +namespace SKGap.GaussianHistory +open MeasureTheory ProbabilityTheory Real Set Filter +open scoped BigOperators ENNReal NNReal +open GaussianStep +noncomputable section +variable {n : ℕ} + +def envelope (p : Prior n) (t : ℝ) {k : ℕ} (A : Set (History n k)) (f : Spin n→ℝ) + (h : History n k) : ℝ := + by classical exact if h∈A then var (posterior p t h) f else avg (posterior p t h) (fun x => (f x)^2) + +lemma envelope_nonneg (p : Prior n) (t : ℝ) {k : ℕ} (A : Set (History n k)) + (f : Spin n→ℝ) (h : History n k) : 0≤envelope p t A f h := by + unfold envelope + split_ifs + · exact var_nonneg _ _ + · exact avg_nonneg _ _ (fun _ => sq_nonneg _) + +lemma var_le_envelope (p : Prior n) (t : ℝ) {k : ℕ} (A : Set (History n k)) + (f : Spin n→ℝ) (h : History n k) : var (posterior p t h) f≤envelope p t A f h := by + unfold envelope + split_ifs + · rfl + · exact var_le_square _ _ + +lemma envelope_le_square (p : Prior n) (t : ℝ) {k : ℕ} (A : Set (History n k)) + (f : Spin n→ℝ) (h : History n k) : + envelope p t A f h≤avg (posterior p t h) (fun x => (f x)^2) := by + unfold envelope + split_ifs + · exact var_le_square _ _ + · rfl + +lemma measurable_envelope (p : Prior n) (t : ℝ) {k : ℕ} (A : Set (History n k)) + (hA : MeasurableSet A) (f : Spin n→ℝ) : Measurable (envelope p t A f) := + Measurable.ite hA (continuous_posterior_var p t k f).measurable + (continuous_posterior_avg p t k _).measurable + +lemma integrable_envelope_weight (p : Prior n) (t : ℝ) {k : ℕ} (A : Set (History n k)) + (hA : MeasurableSet A) (f : Spin n→ℝ) : + Integrable (fun h => density p t h*envelope p t A f h) (reference n k) := by + apply (integrable_posterior_avg_weight p t (fun x => (f x)^2) k).mono' + (((continuous_density p t k).measurable.mul (measurable_envelope p t A hA f)).aestronglyMeasurable) + filter_upwards [] with h + change |density p t h*envelope p t A f h|≤_ + rw [abs_of_nonneg (mul_nonneg (density_pos p t h).le (envelope_nonneg p t A f h))] + exact mul_le_mul_of_nonneg_left (envelope_le_square p t A f h) (density_pos p t h).le + +def envelopeIntegral (p : Prior n) (t : ℝ) {k : ℕ} (A : Set (History n k)) (f : Spin n→ℝ) : ℝ := + ∫h,density p t h*envelope p t A f h ∂reference n k + +lemma variance_le_envelope_zero (p : Prior n) (t : ℝ) (A : Set (History n 0)) (f : Spin n→ℝ) : + var p f≤envelopeIntegral p t A f := by + unfold envelopeIntegral reference + rw [integral_dirac,density_zero,one_mul] + have hh:=var_le_envelope p t A f () + rw [posterior_zero] at hh + exact hh + +lemma integrable_envelope_section (p : Prior n) (t : ℝ) {k : ℕ} (G : Set (History n (k+1))) + (hG : MeasurableSet G) (f : Spin n→ℝ) (h : History n k) : + Integrable (fun z => GaussianStep.density (posterior p t h) t z * + envelope p t G f (h,z)) (GaussianStep.reference n) := by + have hm : Measurable (fun z => envelope p t G f (h,z)) := + (measurable_envelope p t G hG f).comp (measurable_const.prodMk measurable_id) + have hn : Integrable (fun z => GaussianStep.density (posterior p t h) t z* + avg (posterior p t (k := k+1) (h,z)) (fun x => (f x)^2)) (GaussianStep.reference n) := by + simp_rw [posterior_succ] + exact GaussianStep.integrable_posterior_avg_weight _ t _ + apply hn.mono' (((GaussianStep.continuous_density (posterior p t h) t).measurable.mul hm).aestronglyMeasurable) + filter_upwards [] with z + change |GaussianStep.density (posterior p t h) t z*envelope p t G f (h,z)|≤_ + rw [abs_of_nonneg (mul_nonneg (GaussianStep.density_pos _ _ _).le (envelope_nonneg _ _ _ _ _))] + exact mul_le_mul_of_nonneg_left (envelope_le_square p t G f (h,z)) (GaussianStep.density_pos _ _ _).le + +lemma envelope_step_point (p : Prior n) (t : ℝ) {k : ℕ} + (A : Set (History n k)) (G : Set (History n (k+1))) (hG : MeasurableSet G) + (hprefix : ∀h:History n (k+1),h∈G→h.1∈A) (f : Spin n→ℝ) + (ht : 0≤t) (htn : 4*(n:ℝ)*t≤1) (D : ℝ) (hD : 0≤D) + (hgood : ∀h:History n k,h∈A→ + (∑i,(∑x,posterior p t h x*(f x-avg (posterior p t h) f)*spinValue (x i))^2)≤ + D*(var (posterior p t h) f+energy (posterior p t h) f)) + (h : History n k) : + (1-D*t)*envelope p t A f h-D*t*energy (posterior p t h) f- + 16*(n:ℝ)^2*t^2*avg (posterior p t h) (fun x => (f x)^2) ≤ + ∫z,GaussianStep.density (posterior p t h) t z*envelope p t G f (h,z) + ∂GaussianStep.reference n := by + by_cases hh : h∈A + · have hv : (∫z,GaussianStep.density (posterior p t h) t z* + var (GaussianStep.posterior (posterior p t h) t z) f ∂GaussianStep.reference n) ≤ + ∫z,GaussianStep.density (posterior p t h) t z*envelope p t G f (h,z) + ∂GaussianStep.reference n := by + apply integral_mono (GaussianStep.integrable_posterior_variance_weight _ t f) + (integrable_envelope_section p t G hG f h) + intro z + have he:=var_le_envelope p t G f (h,z) + rw [posterior_succ] at he + exact mul_le_mul_of_nonneg_left he (GaussianStep.density_pos _ _ _).le + have hs:=GaussianStep.variance_step_bound (posterior p t h) ht htn f + have hc:=mul_le_mul_of_nonneg_left (hgood h hh) ht + have hn:=mul_le_mul_of_nonneg_left (var_le_square (posterior p t h) f) + (show 0≤16*(n:ℝ)^2*t^2 by positivity) + rw [envelope,ite_eq_left hh] + nlinarith + · have he (z : Fin n→ℝ) : envelope p t G f (h,z)= + avg (GaussianStep.posterior (posterior p t h) t z) (fun x => (f x)^2) := by + rw [envelope,ite_eq_right (fun hmem => hh (hprefix (h,z) hmem)),posterior_succ] + simp_rw [he] + rw [GaussianStep.integral_posterior_avg_weight _ ht,envelope,ite_eq_right hh] + have hN : 0≤avg (posterior p t h) (fun x => (f x)^2) := avg_nonneg _ _ (fun _ => sq_nonneg _) + have hE:=energy_nonneg (posterior p t h) f + have hdt : 0≤D*t := mul_nonneg hD ht + have herr : 0≤16*(n:ℝ)^2*t^2 := by positivity + nlinarith [mul_nonneg hdt hN,mul_nonneg hdt hE,mul_nonneg herr hN] + +theorem envelope_step_bound (p : Prior n) (hp : ∀x,0

(f x)^2) ≤ envelopeIntegral p t G f := by + have hi:=integrable_envelope_weight p t G hG f + change Integrable (fun hz : History n k × (Fin n→ℝ) => density p t (k := k+1) hz*envelope p t G f hz) + ((reference n k).prod (GaussianStep.reference n)) at hi + have hiR:=hi.integral_prod_left + have he : (∫h:History n k,∫z,density p t (k := k+1) (h,z)*envelope p t G f (h,z) + ∂GaussianStep.reference n ∂reference n k)=envelopeIntegral p t G f := + (integral_prod _ hi).symm + have hi1:=(integrable_envelope_weight p t A hA f).const_mul (1-D*t) + have hi2:=(integrable_posterior_energy_weight p hp t k f).const_mul (D*t) + have hi3:=(integrable_posterior_avg_weight p t (fun x => (f x)^2) k).const_mul (16*(n:ℝ)^2*t^2) + have hi12 : Integrable (fun h => (1-D*t)*(density p t h*envelope p t A f h)- + D*t*(density p t h*energy (posterior p t h) f)) (reference n k) := hi1.sub hi2 + have hh:=integral_mono (hi12.sub hi3) hiR (fun h => ?_) + swap + · simp only [Pi.sub_apply] + simp_rw [density_succ,mul_assoc] + rw [integral_const_mul] + convert mul_le_mul_of_nonneg_left (envelope_step_point p t A G hG hprefix f ht htn D hD hgood h) + (density_pos p t h).le using 1; ring + simp only [Pi.sub_apply] at hh + rw [integral_sub hi12 hi3,integral_sub hi1 hi2,integral_const_mul, + integral_const_mul,integral_const_mul,integral_posterior_avg_weight p ht,he] at hh + have hd:=mul_le_mul_of_nonneg_left (energy_history_bound p hp ht k f) (mul_nonneg hD ht) + change (1-D*t)*envelopeIntegral p t A f-D*t*(∫h,density p t h*energy (posterior p t h) f ∂reference n k)- + 16*(n:ℝ)^2*t^2*avg p (fun x => (f x)^2)≤envelopeIntegral p t G f at hh + linarith + +theorem envelope_terminal_bound (p : Prior n) (hp : ∀x,0

(f x)^2)) {t : ℝ} (ht : 0≤t) {k : ℕ} + (A E : Set (History n k)) (hA : MeasurableSet A) (hE : MeasurableSet E) + (hprefix : Aᶜ⊆E) (L : ℝ) (hL : 0≤L) + (hterminal : ∀h:History n k,h∉E→var (posterior p t h) f≤L*energy (posterior p t h) f) : + envelopeIntegral p t A f≤ L*energy p f+ + avg p (fun x => (f x)^2)*eventProbability (squarePrior p f hf) t E := by + let N:=avg p (fun x => (f x)^2) + have hi1:=(integrable_posterior_energy_weight p hp t k f).const_mul L + have hi2:=((integrable_density (squarePrior p f hf) t k).indicator hE).const_mul N + have hh:=integral_mono (integrable_envelope_weight p t A hA f) (hi1.add hi2) (fun h => ?_) + swap + · simp only [Pi.add_apply] + by_cases he : h∈E + · rw [Set.indicator_of_mem he,squarePrior_density] + have henv:=mul_le_mul_of_nonneg_left (envelope_le_square p t A f h) (density_pos p t h).le + have hden : N*(density p t h*avg (posterior p t h) (fun x => (f x)^2)/N)= + density p t h*avg (posterior p t h) (fun x => (f x)^2) := mul_div_cancel₀ _ hf.ne' + change _≤L*(density p t h*energy (posterior p t h) f)+N*(_/N) + rw [hden] + exact henv.trans (le_add_of_nonneg_left (mul_nonneg hL + (mul_nonneg (density_pos p t h).le (energy_nonneg _ _)))) + · have ha : h∈A := by by_contra hn; exact he (hprefix hn) + simp only [Set.indicator_of_notMem he,mul_zero,add_zero,envelope,ite_eq_left ha] + simpa only [mul_left_comm] using mul_le_mul_of_nonneg_left (hterminal h he) (density_pos p t h).le + simp only [Pi.add_apply] at hh + rw [integral_add hi1 hi2,integral_const_mul,integral_const_mul,integral_indicator hE] at hh + have hd:=mul_le_mul_of_nonneg_left (energy_history_bound p hp ht k f) hL + change envelopeIntegral p t A f≤L*(∫h,density p t h*energy (posterior p t h) f ∂reference n k)+ + N*eventProbability (squarePrior p f hf) t E at hh + dsimp [N] at hh + linarith + +end +end SKGap.GaussianHistory + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/EqualityCurve.lean b/lean/OAI/Probability/SKGap/Localization/EqualityCurve.lean new file mode 100644 index 0000000000000000000000000000000000000000..885bebc8fce5d71376c609bb5726e8bc6e7dfa7f --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/EqualityCurve.lean @@ -0,0 +1,176 @@ +import Mathlib +import OAI.Probability.SKGap.Gaussian.ProductGaussianDensity +import OAI.Probability.SKGap.Gaussian.ScalarMomentGram +import OAI.Probability.SKGap.Gaussian.GaussianGramMomentsJoined + +namespace OAI + +section +noncomputable section +namespace SKGap +open Real Matrix MeasureTheory ProbabilityTheory Set Filter +open scoped BigOperators NNReal + +def scalarCurve (j t : ℝ) : ProbabilityMeasure ℝ := + ⟨gaussianReal (scalarFixedPoint j t) (scalarFixedPoint j t).toNNReal,inferInstance⟩ + +def scalarBMoment (P : ProbabilityMeasure ℝ) : ℝ := 1-scalarQMoment P + +def scalarEMoment (P : ProbabilityMeasure ℝ) : ℝ := ∫ y,weightedScalarMoment 0 2 y ∂P + +lemma scalarBMoment_integral (P : ProbabilityMeasure ℝ) : + scalarBMoment P=∫ y,scalarGramVariance y ∂P := by + unfold scalarBMoment scalarQMoment scalarGramVariance + rw [integral_sub (integrable_const 1) integrable_tanh_sq] + simp + +lemma scalarEMoment_integral (P : ProbabilityMeasure ℝ) : + scalarEMoment P=∫ y,spinMixed y ∂P := by + unfold scalarEMoment + congr 1 + funext y + simp [weightedScalarMoment,spinMixed,scalarGramVariance] + +lemma scalarBMoment_pos (P : ProbabilityMeasure ℝ) : 0 < scalarBMoment P := by + rw [scalarBMoment_integral,integral_pos_iff_support_of_nonneg spinVariance_nonneg integrable_spinVariance] + have he : Function.support scalarGramVariance=univ := by + ext y + simp only [Function.mem_support,mem_univ,iff_true] + exact ne_of_gt (sub_pos.mpr (tanh_sq_lt_one y)) + rw [he,measure_univ] + exact zero_lt_one + +lemma scalarBMoment_le_one (P : ProbabilityMeasure ℝ) : scalarBMoment P ≤ 1 := by + have h := (scalarQMoment_bounds P).1 + unfold scalarBMoment + linarith + +lemma scalarEMoment_nonneg (P : ProbabilityMeasure ℝ) : 0 ≤ scalarEMoment P := by + rw [scalarEMoment_integral] + exact integral_nonneg (fun y=>mul_nonneg (sq_nonneg _) (spinVariance_nonneg _)) + +lemma continuous_scalarBMoment : Continuous scalarBMoment := continuous_const.sub continuous_scalarQMoment +lemma continuous_scalarEMoment : Continuous scalarEMoment := continuous_weightedScalarMoment_integral 0 2 + +lemma continuous_scalarFixedPoint_nonneg {j : ℝ} (hj : 0 < j) (hj1 : j < 1) : + Continuous (fun t : Ici (0:ℝ) => scalarFixedPoint j t) := by + have hjgap : 0 < 1-j := sub_pos.mpr hj1 + have hL : LipschitzWith (⟨1/(1-j),by positivity⟩ : ℝ≥0) + (fun t : Ici (0:ℝ) => scalarFixedPoint j t) := by + apply LipschitzWith.of_dist_le_mul + intro t u + change |scalarFixedPoint j t-scalarFixedPoint j u| ≤ (1/(1-j))*|((t:ℝ)-(u:ℝ))| + exact scalarFixedPoint_lipschitz hj hj1 t.2 u.2 + exact hL.continuous + +lemma continuous_scalarCurve_nonneg {j : ℝ} (hj : 0 < j) (hj1 : j < 1) : + Continuous (fun t : Ici (0:ℝ) => scalarCurve j t) := by + rw [ProbabilityMeasure.continuous_iff_forall_continuous_integral] + intro f + have hc := (continuous_gaussianAverage f.continuous (C := ‖f‖) (fun y=>f.norm_coe_le_norm y)).comp + ((continuous_scalarFixedPoint_nonneg hj hj1).prodMk (continuous_scalarFixedPoint_nonneg hj hj1)) + convert hc using 1 + funext t + exact (gaussianAverage_eq_integral f.continuous _ (scalarFixedPoint_spec hj hj1 t.2).1).symm + +lemma scalarQMoment_curve {j t : ℝ} (hj : 0 < j) (hj1 : j < 1) (ht : 0 ≤ t) : + scalarQMoment (scalarCurve j t)=scalarQ j t := (scalarQ_spec hj hj1 ht).1.symm + +lemma scalarM_curve {j t : ℝ} (hj : 0 < j) (hj1 : j < 1) (ht : 0 ≤ t) : + scalarM (scalarCurve j t)=scalarQ j t := by + have hs := (scalarFixedPoint_spec hj hj1 ht).1 + have h := gaussian_nishimori (scalarFixedPoint j t).toNNReal + simp only [Real.coe_toNNReal _ hs] at h + exact h.trans (scalarQMoment_curve hj hj1 ht) + +lemma scalarD_curve {j t : ℝ} (hj : 0 < j) (hj1 : j < 1) (ht : 0 ≤ t) : + scalarD j (scalarCurve j t,t,0)=scalarFixedPoint j t := by + rw [scalarD,scalarM_curve hj hj1 ht] + exact (scalarFixedPoint_spec hj hj1 ht).2.symm + +lemma scalarS_curve {j t : ℝ} (hj : 0 < j) (hj1 : j < 1) (ht : 0 ≤ t) : + scalarS j (scalarCurve j t,t,0)=scalarFixedPoint j t := by + rw [scalarS,scalarQMoment_curve hj hj1 ht] + simpa only [zero_pow (by decide : 2 ≠ 0),add_zero,scalarQ] using (scalarFixedPoint_spec hj hj1 ht).2.symm + +lemma scalarA_curve {j t : ℝ} (hj : 0 < j) (hj1 : j < 1) (ht : 0 < t) : + scalarA j (scalarCurve j t,t,0)=scalarFixedPoint j t*scalarBMoment (scalarCurve j t) := by + let s := scalarFixedPoint j t + have hs : 0 < s := (scalar_fixed_pos hj hj1 ht).1 + have hn : s.toNNReal ≠ 0 := ne_of_gt (Real.toNNReal_pos.mpr hs) + have hi : Integrable (fun y : ℝ => (y-s)*tanh y) (gaussianReal s s.toNNReal) := + ((IsGaussian.integrable_id (μ := gaussianReal s s.toNNReal)).sub (integrable_const s)).mul_bdd + (c := 1) continuous_tanh.aestronglyMeasurable (ae_of_all _ (fun y=>by simpa using (abs_tanh_lt_one y).le)) + have hyt : Integrable (fun y : ℝ => y*tanh y) (gaussianReal s s.toNNReal) := + (IsGaussian.integrable_id (μ := gaussianReal s s.toNNReal)).mul_bdd + (c := 1) continuous_tanh.aestronglyMeasurable (ae_of_all _ (fun y=>by simpa using (abs_tanh_lt_one y).le)) + have hibp := gaussian_integration_by_parts hn hasDerivAt_tanh integrable_tanh + integrable_spinVariance hi + rw [Real.coe_toNNReal _ hs.le] at hibp + unfold scalarA + rw [scalarD_curve hj hj1 ht.le,scalarBMoment_integral] + change (∫ y,y*tanh y ∂gaussianReal s s.toNNReal)-s*(∫ y,tanh y ∂gaussianReal s s.toNNReal)=s*(∫ y,1-tanh y^2 ∂gaussianReal s s.toNNReal) + rw [← integral_const_mul,← integral_sub hyt (integrable_tanh.const_mul s)] + convert hibp using 1 + congr 1 + funext y + ring + +lemma scalarMomentGram_curve {j t : ℝ} (hj : 0 < j) (hj1 : j < 1) (ht : 0 < t) : + scalarMomentGram (scalarCurve j t) (scalarFixedPoint j t) (scalarFixedPoint j t)= + limitingGram (scalarBMoment (scalarCurve j t)) (scalarEMoment (scalarCurve j t)) + (scalarFixedPoint j t) := by + have hs := (scalar_fixed_pos hj hj1 ht).1 + have h := gaussian_weighted_gram_matrix (s := (scalarFixedPoint j t).toNNReal) + (by exact_mod_cast (Real.toNNReal_pos.mpr hs)) + rw [scalarMomentGram_integral,scalarBMoment_integral,scalarEMoment_integral] + ext i k + simpa only [Real.coe_toNNReal _ hs.le,scalarCurve,scalarGramVector,gramCoordinates, + scalarGramVariance,ProbabilityMeasure.coe_mk] using congrFun (congrFun h i) k +end SKGap +end +end + +section +noncomputable section +open MeasureTheory ProbabilityTheory Matrix +open scoped BigOperators ENNReal +namespace SKGap.GaussianDensity + +lemma map_withDensity_leftInverse {α β : Type*} [MeasurableSpace α] [MeasurableSpace β] + (μ : Measure α) {f : α → β} {g : β → α} (hf : Measurable f) (hg : Measurable g) + (hgf : Function.LeftInverse g f) (d : α → ℝ≥0∞) (hd : Measurable d) : + (μ.withDensity d).map f=(μ.map f).withDensity (d ∘ g) := by + ext s hs + rw [Measure.map_apply hf hs,withDensity_apply _ (hf hs),withDensity_apply _ hs, + setLIntegral_map hs (hd.comp hg) hf] + apply lintegral_congr + intro x + simp only [Function.comp_apply] + rw [hgf x] + +variable {ι : Type*} [Fintype ι] [DecidableEq ι] + +theorem matrix_map_gaussian_density (A : Matrix ι ι ℝ) (hA : A.det ≠ 0) : + (Measure.pi (fun _ : ι => gaussianReal 0 1)).map (fun x => A*ᵥx) = + (volume : Measure (ι → ℝ)).withDensity (fun x => ENNReal.ofReal + (|A.det⁻¹| *∏ i,gaussianPDFReal 0 1 ((A⁻¹*ᵥx) i))) := by + have hm (B : Matrix ι ι ℝ) : Measurable (fun x => B*ᵥx) := by fun_prop + have hleft : Function.LeftInverse (fun x => A⁻¹*ᵥx) (fun x => A*ᵥx) := by + intro x + change A⁻¹*ᵥ(A*ᵥx)=x + rw [Matrix.mulVec_mulVec,Matrix.nonsing_inv_mul _ (isUnit_iff_ne_zero.mpr hA),Matrix.one_mulVec] + rw [pi_gaussian_density (fun _ : ι => 0) (fun _ => 1) (fun _ => one_ne_zero), + map_withDensity_leftInverse _ (hm A) (hm A⁻¹) hleft _ (measurable_productPDF _ _)] + have hvol : (volume : Measure (ι → ℝ)).map (fun x => A*ᵥx)= + ENNReal.ofReal |A.det⁻¹| • volume := Real.map_matrix_volume_pi_eq_smul_volume_pi hA + rw [hvol,withDensity_smul_measure,← withDensity_smul _ ((measurable_productPDF _ _).comp (hm A⁻¹))] + congr 1 + ext x + simp only [Pi.smul_apply,Function.comp_apply,smul_eq_mul,ENNReal.ofReal_mul (abs_nonneg _)] + +end SKGap.GaussianDensity +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/Error.lean b/lean/OAI/Probability/SKGap/Localization/Error.lean new file mode 100644 index 0000000000000000000000000000000000000000..963fd23b1fdd3085a0de2caf6effeeb9bd44afef --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/Error.lean @@ -0,0 +1,311 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.Bilinear +import OAI.Probability.SKGap.Matrix.MatrixSeminorm + +namespace OAI + +section + +noncomputable section +open scoped BigOperators Matrix.Norms.Frobenius +namespace SKGap.SourceError +open Matrix +variable {ι : Type*} [Fintype ι] [DecidableEq ι] +local instance : Fact (1≤(4:ENNReal)) := ⟨by norm_num⟩ + +lemma real_op_norm_nonneg (P : Matrix ι ι ℝ) : 0≤opNorm P := norm_nonneg _ + +lemma cauchy_bound {α : Type*} [Fintype α] (f g : α→ℝ) {A B : ℝ} + (hA : 0≤A) (hB : 0≤B) (hf : (∑i,(f i)^2)≤A^2) (hg : (∑i,(g i)^2)≤B^2) : + |∑i,f i*g i|≤A*B := by + have H:=Finset.sum_mul_sq_le_sq_mul_sq Finset.univ f g + have hh:=mul_le_mul hf hg (Finset.sum_nonneg (fun i _=>sq_nonneg _)) (sq_nonneg _) + nlinarith [sq_abs (∑i,f i*g i),mul_nonneg hA hB,abs_nonneg (∑i,f i*g i)] + +omit [DecidableEq ι] in +lemma double_cauchy (f g : ι→ι→ℝ) {A B : ℝ} (hA : 0≤A) (hB : 0≤B) + (hf : (∑i,∑k,(f i k)^2)≤A^2) (hg : (∑i,∑k,(g i k)^2)≤B^2) : + |∑i,∑k,f i k*g i k|≤A*B := by + have H:=cauchy_bound (fun a : ι×ι=>f a.1 a.2) (fun a=>g a.1 a.2) hA hB + (by simpa only [Fintype.sum_prod_type] using hf) (by simpa only [Fintype.sum_prod_type] using hg) + simpa only [Fintype.sum_prod_type] using H + +def traceAbsolute (P E : Matrix ι ι ℝ) : ℝ := ∑i,∑k,|P k i| * |E i k| + +omit [DecidableEq ι] in +lemma trace_le_traceAbsolute (P E : Matrix ι ι ℝ) : |trace (P*E)|≤traceAbsolute P E := by + rw [trace_mul_comm] + simp only [trace,diag,Matrix.mul_apply] + apply (Finset.abs_sum_le_sum_abs ..).trans + apply Finset.sum_le_sum; intro i _ + exact (Finset.abs_sum_le_sum_abs ..).trans_eq (by simp only [abs_mul,mul_comm]) + +lemma matrix_column_square_le (P : Matrix ι ι ℝ) (i : ι) : + (∑k,(P k i)^2)≤(opNorm P)^2 := by + have H:=pow_le_pow_left₀ (norm_nonneg (colVec P i)) (colVec_norm_le P i) 2 + simpa only [colVec,EuclideanSpace.real_norm_sq_eq] using H + +lemma matrix_row_square_le (P : Matrix ι ι ℝ) (i : ι) : + (∑k,(P i k)^2)≤(opNorm P)^2 := by + simpa only [Matrix.transpose_apply,opNorm_transpose] using matrix_column_square_le Pᵀ i + +lemma small_column_square (P : Matrix ι ι ℝ) (s : ι→ℝ) : + (∑i,∑k,(|P k i| * |s i|)^2)≤(opNorm P)^2*(∑i,(s i)^2) := by + simp only [mul_pow,sq_abs] + calc + _ ≤ ∑i,(opNorm P)^2*(s i)^2 := by + apply Finset.sum_le_sum; intro i _ + rw [←Finset.sum_mul] + exact mul_le_mul_of_nonneg_right (matrix_column_square_le P i) (sq_nonneg _) + _ = _ := by rw [←Finset.mul_sum] + +lemma small_row_square (P : Matrix ι ι ℝ) (t : ι→ℝ) : + (∑i,∑k,(|P k i| * |t k|)^2)≤(opNorm P)^2*(∑k,(t k)^2) := by + rw [Finset.sum_comm] + simpa only [Matrix.transpose_apply,opNorm_transpose] using small_column_square Pᵀ t + +lemma quadratic_trace_bound (P Q : Matrix ι ι ℝ) (s : ι→ℝ) {S B : ℝ} + (hS : 0≤S) (hB : 0≤B) (hs : (∑i,(s i)^2)≤S^2) + (hQ : (∑i,∑k,(Q i k)^4)≤B^4) : + (∑i,∑k,|P k i| * |s i| *(Q i k)^2)≤opNorm P*S*B^2 := by + have H:=double_cauchy (fun i k=>|P k i| * |s i|) (fun i k=>(Q i k)^2) + (mul_nonneg (real_op_norm_nonneg P) hS) (pow_nonneg hB 2) + ((small_column_square P s).trans (by + simpa only [mul_pow] using mul_le_mul_of_nonneg_left hs (sq_nonneg (opNorm P)))) + (by simpa only [←pow_mul] using hQ) + exact (le_abs_self _).trans H + +lemma mixed_trace_bound (P Q : Matrix ι ι ℝ) (s t : ι→ℝ) {S T B : ℝ} + (hS : 0≤S) (hT : 0≤T) (hB : 0≤B) + (hs : (∑i,(s i)^2)≤S^2) (ht : (∑k,(t k)^2)≤T^2) + (hQ : ∀i,(∑k,(Q i k)^2)≤B^2) : + (∑i,∑k,|P k i| * |s i| * |Q i k| * |t k|)≤opNorm P*T*(S*B) := by + have hf : (∑i,∑k,(|P k i| * |t k|)^2)≤(opNorm P*T)^2 := + (small_row_square P t).trans (by simpa only [mul_pow] using (mul_le_mul_of_nonneg_left ht (sq_nonneg (opNorm P)))) + have hg : (∑i,∑k,(|s i| * |Q i k|)^2)≤(S*B)^2 := by + simp only [mul_pow,sq_abs,←Finset.mul_sum] + calc + _ ≤ ∑i,(s i)^2*B^2 := Finset.sum_le_sum (fun i _=>mul_le_mul_of_nonneg_left (hQ i) (sq_nonneg _)) + _ = (∑i,(s i)^2)*B^2 := (Finset.sum_mul ..).symm + _ ≤ S^2*B^2 := mul_le_mul_of_nonneg_right hs (sq_nonneg _) + have H:=double_cauchy (fun i k=>|P k i| * |t k|) (fun i k=>|s i| * |Q i k|) + (mul_nonneg (real_op_norm_nonneg P) hT) (mul_nonneg hS hB) hf hg + apply (le_abs_self _).trans + have he : (∑i,∑k,|P k i| * |s i| * |Q i k| * |t k|) = + ∑i,∑k,|P k i| * |t k| * (|s i| * |Q i k|) := by + apply Finset.sum_congr rfl; intro i _ + apply Finset.sum_congr rfl; intro k _; ring + rw [he] + exact H + +lemma parameter_square_trace_bound (P : Matrix ι ι ℝ) (s t : ι→ℝ) {S T : ℝ} + (hS : 0≤S) (hT : 0≤T) (hs : (∑i,(s i)^2)≤S^2) (ht : (∑k,(t k)^2)≤T^2) : + (∑i,∑k,|P k i| * |s i| *(t k)^2)≤opNorm P*T*(S*T) := by + have hf : (∑i,∑k,(|P k i| * |t k|)^2)≤(opNorm P*T)^2 := + (small_row_square P t).trans (by simpa only [mul_pow] using (mul_le_mul_of_nonneg_left ht (sq_nonneg (opNorm P)))) + have hg : (∑i,∑k,(|s i| * |t k|)^2)≤(S*T)^2 := by + simp only [mul_pow,sq_abs,←Finset.mul_sum,←Finset.sum_mul] + exact mul_le_mul hs ht (Finset.sum_nonneg (fun k _=>sq_nonneg _)) (sq_nonneg _) + have H:=double_cauchy (fun i k=>|P k i| * |t k|) (fun i k=>|s i| * |t k|) + (mul_nonneg (real_op_norm_nonneg P) hT) (mul_nonneg hS hT) hf hg + apply (le_abs_self _).trans + have he : (∑i,∑k,|P k i| * |s i| * (t k)^2) = + ∑i,∑k,|P k i| * |t k| * (|s i| * |t k|) := by + apply Finset.sum_congr rfl; intro i _ + apply Finset.sum_congr rfl; intro k _ + rw [← sq_abs (t k)]; ring + rw [he] + exact H + +theorem source_taylor_trace_bound (P E Q : Matrix ι ι ℝ) (s t : ι→ℝ) {C S T B R : ℝ} + (hC : 0≤C) (hS : 0≤S) (hT : 0≤T) (hB : 0≤B) (hR : 0≤R) + (hs : (∑i,(s i)^2)≤S^2) (ht : (∑k,(t k)^2)≤T^2) + (hQ4 : (∑i,∑k,(Q i k)^4)≤B^4) (hQr : ∀i,(∑k,(Q i k)^2)≤R^2) + (hE : ∀i k,|E i k|≤C*|s i| *((Q i k)^2+|Q i k| * |t k|+(t k)^2)) : + |trace (P*E)|≤C*opNorm P*S*(B^2+R*T+T^2) := by + apply (trace_le_traceAbsolute P E).trans + calc + _ ≤ ∑i,∑k,|P k i| *(C*|s i| *((Q i k)^2+|Q i k| * |t k|+(t k)^2)) := by + apply Finset.sum_le_sum; intro i _ + apply Finset.sum_le_sum; intro k _ + exact mul_le_mul_of_nonneg_left (hE i k) (abs_nonneg _) + _ = C*((∑i,∑k,|P k i| * |s i| *(Q i k)^2)+ + (∑i,∑k,|P k i| * |s i| * |Q i k| * |t k|)+ + (∑i,∑k,|P k i| * |s i| *(t k)^2)) := by + simp only [Finset.mul_sum,←Finset.sum_add_distrib] + apply Finset.sum_congr rfl; intro i _ + apply Finset.sum_congr rfl; intro k _; ring + _ ≤ C*(opNorm P*S*B^2+opNorm P*T*(S*R)+opNorm P*T*(S*T)) := by + exact mul_le_mul_of_nonneg_left (add_le_add (add_le_add + (quadratic_trace_bound P Q s hS hB hs hQ4) + (mixed_trace_bound P Q s t hS hT hR hs ht hQr)) + (parameter_square_trace_bound P s t hS hT hs ht)) hC + _ = _ := by ring + +omit [DecidableEq ι] in +lemma fourth_holder (P D Q : Matrix ι ι ℝ) {B S R : ℝ} + (hB : 0≤B) (hS : 0≤S) (hR : 0≤R) + (hP : (∑i,∑k,(P i k)^4)≤B^4) (hD : (∑i,∑k,(D i k)^2)≤S^2) + (hQ : (∑i,∑k,(Q i k)^4)≤R^4) : + (∑i,∑k,|P i k| * |D i k| * |Q i k|)≤S*(B*R) := by + have H₁:=double_cauchy (fun i k=>(P i k)^2) (fun i k=>(Q i k)^2) + (sq_nonneg B) (sq_nonneg R) (by simpa only [←pow_mul] using hP) + (by simpa only [←pow_mul] using hQ) + have H₂ : (∑i,∑k,(|P i k| * |Q i k|)^2)≤(B*R)^2 := by + simp only [mul_pow,sq_abs] + exact (le_abs_self _).trans H₁ + have H₃:=double_cauchy (fun i k=>|D i k|) (fun i k=>|P i k| * |Q i k|) + hS (mul_nonneg hB hR) (by simpa only [sq_abs] using hD) H₂ + apply (le_abs_self _).trans + have he : (∑i,∑k,|P i k| * |D i k| * |Q i k|) = + ∑i,∑k,|D i k| * (|P i k| * |Q i k|) := by + apply Finset.sum_congr rfl; intro i _ + apply Finset.sum_congr rfl; intro k _; ring + rw [he]; exact H₃ + +lemma sum_split_diagonal (f : ι→ι→ℝ) : + (∑i,∑k,f i k)=(∑i,f i i)+(∑i,∑k,if i=k then 0 else f i k) := by + rw [←Finset.sum_add_distrib] + apply Finset.sum_congr rfl; intro i _ + have he : f i i=∑k,if i=k then f i k else 0 := by simp + rw [he,←Finset.sum_add_distrib] + apply Finset.sum_congr rfl; intro k _ + split_ifs <;> simp + +lemma diagonal_product_trace_bound (P D Q : Matrix ι ι ℝ) {S R : ℝ} + (hS : 0≤S) (hR : 0≤R) (hD : (∑i,(D i i)^2)≤S^2) + (hQ : (∑i,(Q i i)^2)≤R^2) : + (∑i,|P i i| * |D i i| * |Q i i|)≤opNorm P*(S*R) := by + calc + _ ≤ ∑i,opNorm P*(|D i i| * |Q i i|) := by + apply Finset.sum_le_sum; intro i _ + nlinarith [mul_le_mul_of_nonneg_right (matrix_entry_le_opNorm P i i) + (mul_nonneg (abs_nonneg (D i i)) (abs_nonneg (Q i i)))] + _ = opNorm P*(∑i,|D i i| * |Q i i|) := by rw [Finset.mul_sum] + _ ≤ opNorm P*(S*R) := by + apply mul_le_mul_of_nonneg_left _ (real_op_norm_nonneg P) + exact (le_abs_self _).trans (cauchy_bound (fun i=>|D i i|) (fun i=>|Q i i|) + hS hR (by simpa only [sq_abs] using hD) (by simpa only [sq_abs] using hQ)) + +lemma parameter_product_trace_bound (P D : Matrix ι ι ℝ) (t : ι→ℝ) {S T : ℝ} + (hS : 0≤S) (hT : 0≤T) (hD : (∑i,∑k,(D i k)^2)≤S^2) + (ht : (∑k,(t k)^2)≤T^2) : + (∑i,∑k,|P k i| * |D i k| * |t k|)≤S*(opNorm P*T) := by + have hf : (∑i,∑k,(|P k i| * |t k|)^2)≤(opNorm P*T)^2 := + (small_row_square P t).trans (by simpa only [mul_pow] using + (mul_le_mul_of_nonneg_left ht (sq_nonneg (opNorm P)))) + have H:=double_cauchy (fun i k=>|D i k|) (fun i k=>|P k i| * |t k|) + hS (mul_nonneg (real_op_norm_nonneg P) hT) (by simpa only [sq_abs] using hD) hf + apply (le_abs_self _).trans + have he : (∑i,∑k,|P k i| * |D i k| * |t k|) = + ∑i,∑k,|D i k| * (|P k i| * |t k|) := by + apply Finset.sum_congr rfl; intro i _ + apply Finset.sum_congr rfl; intro k _; ring + rw [he]; exact H + +theorem source_product_trace_bound (P E D Q : Matrix ι ι ℝ) (t : ι→ℝ) {C S T B R L : ℝ} + (hC : 0≤C) (hS : 0≤S) (hT : 0≤T) (hB : 0≤B) (hR : 0≤R) (hL : 0≤L) + (hD : (∑i,∑k,(D i k)^2)≤S^2) (ht : (∑k,(t k)^2)≤T^2) + (hP : (∑i,∑k,if i=k then 0 else (P k i)^4)≤B^4) + (hQ : (∑i,∑k,(Q i k)^4)≤R^4) (hQd : (∑i,(Q i i)^2)≤L^2) + (hE : ∀i k,|E i k|≤C*|D i k| *(|Q i k|+|t k|)) : + |trace (P*E)|≤C*S*(B*R+opNorm P*(L+T)) := by + have hDd : (∑i,(D i i)^2)≤S^2 := by + apply le_trans _ hD + exact Finset.sum_le_sum (fun i _=>Finset.single_le_sum (fun k _=>sq_nonneg (D i k)) + (Finset.mem_univ i)) + let O : Matrix ι ι ℝ := fun i k=>if i=k then 0 else P k i + have hO : (∑i,∑k,(O i k)^4)≤B^4 := by + simpa only [O,ite_pow,zero_pow (by decide : 4≠0)] using hP + have hOff := fourth_holder O D Q hB hS hR hO hD hQ + have heOff : (∑i,∑k,if i=k then 0 else |P k i| * |D i k| * |Q i k|) = + ∑i,∑k,|O i k| * |D i k| * |Q i k| := by + apply Finset.sum_congr rfl; intro i _ + apply Finset.sum_congr rfl; intro k _ + dsimp only [O]; split_ifs <;> simp + have hProd : (∑i,∑k,|P k i| * |D i k| * |Q i k|)≤opNorm P*(S*L)+S*(B*R) := by + rw [sum_split_diagonal,heOff] + exact add_le_add (diagonal_product_trace_bound P D Q hS hL hDd hQd) hOff + apply (trace_le_traceAbsolute P E).trans + calc + _ ≤ ∑i,∑k,|P k i| *(C*|D i k| *(|Q i k|+|t k|)) := by + apply Finset.sum_le_sum; intro i _ + apply Finset.sum_le_sum; intro k _ + exact mul_le_mul_of_nonneg_left (hE i k) (abs_nonneg _) + _ = C*((∑i,∑k,|P k i| * |D i k| * |Q i k|)+ + (∑i,∑k,|P k i| * |D i k| * |t k|)) := by + simp only [Finset.mul_sum,←Finset.sum_add_distrib] + apply Finset.sum_congr rfl; intro i _ + apply Finset.sum_congr rfl; intro k _; ring + _ ≤ C*(opNorm P*(S*L)+S*(B*R)+S*(opNorm P*T)) := + mul_le_mul_of_nonneg_left (add_le_add hProd + (parameter_product_trace_bound P D t hS hT hD ht)) hC + _ = _ := by ring + +lemma trace_square_eq (E : Matrix ι ι ℝ) : trace (Eᵀ*E)=‖E‖^2 := by + rw [frobenius_sq] + simp only [trace,diag,Matrix.mul_apply,Matrix.transpose_apply,←sq] + rw [Finset.sum_comm] + +lemma frobenius_from_traces (E : Matrix ι ι ℝ) {C : ℝ} (hC : 0≤C) + (h : ∀P : Matrix ι ι ℝ,|trace (P*E)|≤C*‖P‖) : ‖E‖≤C := by + have H:=h Eᵀ + rw [trace_square_eq,abs_of_nonneg (sq_nonneg _),Matrix.frobenius_norm_transpose] at H + nlinarith [norm_nonneg E] + +theorem source_taylor_frobenius_bound (E Q : Matrix ι ι ℝ) (s t : ι→ℝ) {C S T B R : ℝ} + (hC : 0≤C) (hS : 0≤S) (hT : 0≤T) (hB : 0≤B) (hR : 0≤R) + (hs : (∑i,(s i)^2)≤S^2) (ht : (∑k,(t k)^2)≤T^2) + (hQ4 : (∑i,∑k,(Q i k)^4)≤B^4) (hQr : ∀i,(∑k,(Q i k)^2)≤R^2) + (hE : ∀i k,|E i k|≤C*|s i| *((Q i k)^2+|Q i k| * |t k|+(t k)^2)) : + ‖E‖≤C*S*(B^2+R*T+T^2) := by + apply frobenius_from_traces E (by positivity) + intro P + have H:=source_taylor_trace_bound P E Q s t hC hS hT hB hR hs ht hQ4 hQr hE + apply H.trans + nlinarith [mul_le_mul_of_nonneg_right (operator_le_frobenius P) + (show 0≤C*S*(B^2+R*T+T^2) by positivity)] + +theorem source_product_frobenius_bound (E D Q : Matrix ι ι ℝ) (t : ι→ℝ) {C S T R L : ℝ} + (hC : 0≤C) (hS : 0≤S) (hT : 0≤T) (hR : 0≤R) (hL : 0≤L) + (hD : (∑i,∑k,(D i k)^2)≤S^2) (ht : (∑k,(t k)^2)≤T^2) + (hQ : (∑i,∑k,(Q i k)^4)≤R^4) (hQd : (∑i,(Q i i)^2)≤L^2) + (hE : ∀i k,|E i k|≤C*|D i k| *(|Q i k|+|t k|)) : + ‖E‖≤C*S*(R+L+T) := by + apply frobenius_from_traces E (by positivity) + intro P + have hP : (∑i,∑k,if i=k then 0 else (P k i)^4)≤‖P‖^4 := by + have H:=pow_le_pow_left₀ (norm_nonneg (offDiagonalVector P)) (offDiagonalSeminorm_le P) 4 + change offDiagonalSeminorm P ^ 4 ≤ ‖P‖ ^ 4 at H + rw [offDiagonalSeminorm_fourth,Fintype.sum_prod_type] at H + rw [Finset.sum_comm] + simpa only [eq_comm] using H + have H:=source_product_trace_bound P E D Q t hC hS hT (norm_nonneg P) hR hL + hD ht hP hQ hQd hE + apply H.trans + nlinarith [mul_le_mul_of_nonneg_left (mul_le_mul_of_nonneg_right + (operator_le_frobenius P) (show 0≤L+T by positivity)) (mul_nonneg hC hS)] + +lemma rank_one_trace_bound (P : Matrix ι ι ℝ) (u v : EuclideanSpace ℝ ι) : + |trace (P*Matrix.of (fun i k=>u i*v k))|≤opNorm P*‖u‖*‖v‖ := by + have H:=abs_real_inner_le_norm v (P.toEuclideanLin.toContinuousLinearMap u) + have he : trace (P*Matrix.of (fun i k=>u i*v k))= + inner ℝ v (P.toEuclideanLin.toContinuousLinearMap u) := by + change (∑i,∑k,P i k*(u k*v i))=∑i,(∑k,P i k*u k)*v i + simp only [Finset.sum_mul] + apply Finset.sum_congr rfl; intro i _ + apply Finset.sum_congr rfl; intro k _; ring + rw [he] + apply H.trans + have h:=mul_le_mul_of_nonneg_left + (P.toEuclideanLin.toContinuousLinearMap.le_opNorm u) (norm_nonneg v) + change ‖v‖*‖P.toEuclideanLin.toContinuousLinearMap u‖≤opNorm P*‖u‖*‖v‖ + change ‖v‖*‖P.toEuclideanLin.toContinuousLinearMap u‖≤‖v‖*(opNorm P*‖u‖) at h + nlinarith only [h] + +end SKGap.SourceError + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/ExpAbsSum.lean b/lean/OAI/Probability/SKGap/Localization/ExpAbsSum.lean new file mode 100644 index 0000000000000000000000000000000000000000..0d3496d0a965ca812f70197564b257163a9cea56 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/ExpAbsSum.lean @@ -0,0 +1,239 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.JumpEnergy +import OAI.Probability.SKGap.Stability.FieldSquareSum + +namespace OAI + +section +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open scoped BigOperators +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open scoped BigOperators +open scoped BigOperators NNReal ENNReal +open MeasureTheory Metric Set +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators NNReal ENNReal Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Set +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators ENNReal NNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Matrix +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators ENNReal NNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal +open scoped BigOperators +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise NNReal ENNReal +open scoped BigOperators +open Filter Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal Topology +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Set Matrix +open scoped BigOperators NNReal ENNReal Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open Filter MeasureTheory ProbabilityTheory +open scoped Topology NNReal ENNReal +open Filter MeasureTheory ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter +open scoped Topology NNReal ENNReal +open MeasureTheory Filter ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter +open scoped Topology +open MeasureTheory Filter ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter ProbabilityTheory ContinuousLinearMap +open scoped Topology NNReal ENNReal +open Filter MeasureTheory ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter +open scoped BigOperators Topology +open MeasureTheory Filter +open scoped BigOperators Topology +namespace SKGapCutoff + +lemma exp_abs_le_sum (z : ℝ) : Real.exp |z| ≤ Real.exp z + Real.exp (-z) := by + rcases le_total 0 z with hz | hz + · rw [abs_of_nonneg hz] + linarith [Real.exp_pos (-z)] + · rw [abs_of_nonpos hz] + linarith [Real.exp_pos z] + +lemma indicator_max_le_exp {n : ℕ} (u c : Fin n → ℝ) {θ H m : ℝ} + (hθ : 0 ≤ θ) (hc : ∀ i, |c i| ≤ m) : + (if ∃ i, H < |u i| then (1:ℝ) else 0) ≤ + Real.exp (-θ*(H-m)) * ∑ i, (Real.exp (θ*(u i-c i)) + Real.exp (-θ*(u i-c i))) := by + classical + by_cases hu : ∃ i, H < |u i| + · simp only [hu, ↓reduceIte] + obtain ⟨i, hi⟩ := hu + have htri : H-m ≤ |u i-c i| := by + have hh : |u i| ≤ |u i-c i|+|c i| := by + simpa only [sub_add_cancel] using abs_add_le (u i-c i) (c i) + linarith [hc i] + have hs : Real.exp (θ*|u i-c i|) ≤ + ∑ j, (Real.exp (θ*(u j-c j)) + Real.exp (-θ*(u j-c j))) := by + have hh := exp_abs_le_sum (θ*(u i-c i)) + rw [abs_mul, abs_of_nonneg hθ] at hh + have hh' : Real.exp (θ*|u i-c i|) ≤ + Real.exp (θ*(u i-c i))+Real.exp (-θ*(u i-c i)) := by + simpa only [neg_mul] using hh + exact hh'.trans (Finset.single_le_sum (f := fun j => + Real.exp (θ*(u j-c j))+Real.exp (-θ*(u j-c j))) + (fun j _ => by positivity) (Finset.mem_univ i)) + calc + 1 ≤ Real.exp (-θ*(H-m))*Real.exp (θ*|u i-c i|) := by + rw [← Real.exp_add, Real.one_le_exp_iff] + have hh := mul_le_mul_of_nonneg_left htri hθ + linarith + _ ≤ _ := mul_le_mul_of_nonneg_left hs (Real.exp_pos _).le + · simp only [hu, ↓reduceIte] + positivity + +lemma semigroup_max_tail {n : ℕ} (J : Interaction n) (f : Fin n → Observables n) + {t θ H m C : ℝ} (ht : 0 ≤ t) (hθ : 0 ≤ θ) (x : Spin n) + (hmean : ∀ i, |semigroup J t (f i) x| ≤ m) + (hmgf : ∀ i, ∀ σ ∈ ({-1,1}:Set ℝ), + semigroup J t (fun y => Real.exp (σ*θ*(f i y-semigroup J t (f i) x))) x ≤ C) : + semigroup J t (fun y => if ∃ i, H < |f i y| then (1:ℝ) else 0) x ≤ + 2*(n:ℝ)*C*Real.exp (-θ*(H-m)) := by + classical + have hh := semigroup_mono J t ht (fun y => + indicator_max_le_exp (fun i => f i y) (fun i => semigroup J t (f i) x) (H := H) hθ hmean) x + have he : (fun y => Real.exp (-θ*(H-m))*∑ i, + (Real.exp (θ*(f i y-semigroup J t (f i) x)) + + Real.exp (-θ*(f i y-semigroup J t (f i) x)))) = + Real.exp (-θ*(H-m)) • ∑ i : Fin n, + ((fun y => Real.exp (θ*(f i y-semigroup J t (f i) x))) + + (fun y => Real.exp (-θ*(f i y-semigroup J t (f i) x)))) := by + funext y + simp only [Pi.smul_apply, smul_eq_mul, Finset.sum_apply, Pi.add_apply] + rw [he, map_smul, map_sum] at hh + simp only [Pi.smul_apply, smul_eq_mul, Finset.sum_apply, map_add, Pi.add_apply] at hh + have hib : ∀ i : Fin n, + semigroup J t (fun y => Real.exp (θ*(f i y-semigroup J t (f i) x))) x + + semigroup J t (fun y => Real.exp (-θ*(f i y-semigroup J t (f i) x))) x ≤ 2*C := by + intro i + have hpos := hmgf i 1 (by simp) + have hneg := hmgf i (-1) (by simp) + simp only [one_mul, neg_one_mul] at hpos hneg + linarith + calc + _ ≤ _ := hh + _ ≤ Real.exp (-θ*(H-m))*∑ _i : Fin n, 2*C := + mul_le_mul_of_nonneg_left (Finset.sum_le_sum (fun i _ => hib i)) (Real.exp_pos _).le + _ = _ := by simp; ring + +lemma jumpWeight_lower_from_field {n : ℕ} (J : Interaction n) (x : Spin n) (i : Fin n) + {H : ℝ} (hH : |field J x i| ≤ H) : + 2/(1+Real.exp (2*H)) ≤ 1-mean J x i*spin x i := by + have hpos : 1/(1+Real.exp (2*H)) ≤ 1/(1+Real.exp (2*field J x i)) := by + apply one_div_le_one_div_of_le (by positivity) + apply add_le_add le_rfl + exact Real.exp_le_exp.mpr (by linarith [le_abs_self (field J x i)]) + have hneg : 1/(1+Real.exp (2*H)) ≤ 1/(1+Real.exp (-2*field J x i)) := by + apply one_div_le_one_div_of_le (by positivity) + apply add_le_add le_rfl + exact Real.exp_le_exp.mpr (by linarith [neg_le_abs (field J x i)]) + rw [← one_sub_tanh_half (field J x i)] at hpos + rw [← one_add_tanh_half (field J x i)] at hneg + simp only [div_eq_mul_inv, one_mul] at hpos hneg ⊢ + cases hs : x i <;> simp only [spin, hs, Bool.false_eq_true, ↓reduceIte, + mean, mul_neg_one, mul_one] <;> linarith + +end SKGapCutoff + +open MeasureTheory Filter +open scoped BigOperators Topology + +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/ExpDrift.lean b/lean/OAI/Probability/SKGap/Localization/ExpDrift.lean new file mode 100644 index 0000000000000000000000000000000000000000..999a9ccdadaf25aa7b4096d2bb0a9f8ea4f8c84b --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/ExpDrift.lean @@ -0,0 +1,227 @@ +import Mathlib +import OAI.Probability.SKGap.Terminal.GibbsExpectation +import OAI.Probability.SKGap.Localization.JumpEnergy + +namespace OAI + +section +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +namespace SKGapCutoff + +noncomputable def expDrift {n : ℕ} (J : Interaction n) (θ : ℝ) + (f : Observables n) (x : Spin n) : ℝ := + generator J (fun y => Real.exp (θ * f y)) x - + θ * Real.exp (θ * f x) * generator J f x + +lemma expDrift_eq_sum {n : ℕ} (J : Interaction n) (θ : ℝ) (f : Observables n) (x : Spin n) : + expDrift J θ f x = Real.exp (θ * f x) * ∑ i, flipRate J x i * + (Real.exp (θ * (f (flip x i) - f x)) - 1 - θ * (f (flip x i) - f x)) := by + have he (i : Fin n) : Real.exp (θ * f (flip x i)) = + Real.exp (θ * f x) * Real.exp (θ * (f (flip x i) - f x)) := by + rw [← Real.exp_add] + congr 1 + ring + simp only [expDrift, generator_flip, he, Finset.mul_sum, ← Finset.sum_sub_distrib] + apply Finset.sum_congr rfl + intro i _ + ring + +lemma flipRate_nonneg {n : ℕ} (J : Interaction n) (x : Spin n) (i : Fin n) : + 0 ≤ flipRate J x i := by + unfold flipRate + exact div_nonneg (by simpa only [mul_comm] using (jumpWeight_bounds J x i).1) (by norm_num) + +lemma jumpEnergy_eq_jump_square {n : ℕ} (J : Interaction n) (f : Observables n) (x : Spin n) : + jumpEnergy J f x = ∑ i, flipRate J x i * (f (flip x i) - f x) ^ 2 := by + simp only [jumpEnergy, Finset.mul_sum] + apply Finset.sum_congr rfl + intro i _ + rw [flip_sub] + simp only [mul_pow, spin_sq, mul_one, flipRate] + ring + +lemma abs_flip_sub_le {n : ℕ} (f : Observables n) (x : Spin n) (B : ℝ) + (hB : ∑ j, (halfDiff j f x) ^ 2 ≤ B) (i : Fin n) : + |f (flip x i) - f x| ≤ 2 * Real.sqrt B := by + have hi : (halfDiff i f x) ^ 2 ≤ B := + (Finset.single_le_sum (fun j _ => sq_nonneg (halfDiff j f x)) (Finset.mem_univ i)).trans hB + have hs : |spin x i| = 1 := by cases hx : x i <;> simp [spin, hx] + rw [flip_sub, abs_mul, abs_mul, hs] + norm_num + exact Real.abs_le_sqrt hi + +lemma expDrift_le {n : ℕ} (J : Interaction n) (θ : ℝ) (f : Observables n) (x : Spin n) + (B b : ℝ) (hB : ∑ i, (halfDiff i f x) ^ 2 ≤ B) + (hb : ∑ i, (halfDiff i f x) ^ 2 ≤ b) : + expDrift J θ f x ≤ (2 * θ ^ 2 * Real.exp (2 * |θ| * Real.sqrt B) * b) * + Real.exp (θ * f x) := by + let R := Real.exp (2 * |θ| * Real.sqrt B) + have hR : 0 ≤ θ ^ 2 * R / 2 := by positivity + have hrem (i : Fin n) : + Real.exp (θ * (f (flip x i) - f x)) - 1 - θ * (f (flip x i) - f x) ≤ + θ ^ 2 * R / 2 * (f (flip x i) - f x) ^ 2 := by + have ha : |θ * (f (flip x i) - f x)| ≤ 2 * |θ| * Real.sqrt B := by + rw [abs_mul] + calc + _ ≤ |θ| * (2 * Real.sqrt B) := + mul_le_mul_of_nonneg_left (abs_flip_sub_le f x B hB i) (abs_nonneg θ) + _ = _ := by ring + calc + _ ≤ (θ * (f (flip x i) - f x)) ^ 2 * + Real.exp |θ * (f (flip x i) - f x)| / 2 := real_exp_remainder_le _ + _ ≤ (θ * (f (flip x i) - f x)) ^ 2 * R / 2 := by + apply div_le_div_of_nonneg_right _ (by norm_num) + exact mul_le_mul_of_nonneg_left (Real.exp_le_exp.mpr ha) (sq_nonneg _) + _ = _ := by ring + rw [expDrift_eq_sum] + calc + _ ≤ Real.exp (θ * f x) * ∑ i, flipRate J x i * + (θ ^ 2 * R / 2 * (f (flip x i) - f x) ^ 2) := by + apply mul_le_mul_of_nonneg_left (Finset.sum_le_sum _) (Real.exp_pos _).le + intro i _ + exact mul_le_mul_of_nonneg_left (hrem i) (flipRate_nonneg J x i) + _ = Real.exp (θ * f x) * (θ ^ 2 * R / 2) * jumpEnergy J f x := by + rw [jumpEnergy_eq_jump_square] + simp only [Finset.mul_sum] + apply Finset.sum_congr rfl + intro i _ + ring + _ ≤ Real.exp (θ * f x) * (θ ^ 2 * R / 2) * (4 * b) := by + apply mul_le_mul_of_nonneg_left _ (mul_nonneg (Real.exp_pos _).le hR) + exact (jumpEnergy_le_gradient J f x).trans (mul_le_mul_of_nonneg_left hb (by norm_num)) + _ = _ := by dsimp [R]; ring + +lemma backward_exp_hasDerivAt {n : ℕ} (J : Interaction n) (f : Observables n) + (θ d s : ℝ) : + HasDerivAt (fun r : ℝ => fun x : Spin n => Real.exp (θ * semigroup J (d - r) f x)) + (fun x => -θ * Real.exp (θ * semigroup J (d - s) f x) * + generator J (semigroup J (d - s) f) x) s := by + apply hasDerivAt_pi.mpr + intro x + have h := ((hasDerivAt_pi.mp (backward_flow_hasDerivAt J f d s) x).const_mul θ).exp + convert h using 1 + ring + +lemma interpolated_exp_hasDerivAt {n : ℕ} (J : Interaction n) (f : Observables n) + (θ d s : ℝ) : + HasDerivAt (fun r : ℝ => semigroup J r + (fun x => Real.exp (θ * semigroup J (d - r) f x))) + (semigroup J s (expDrift J θ (semigroup J (d - s) f))) s := by + have h := (semigroup_hasDerivAt J s).clm_apply (backward_exp_hasDerivAt J f θ d s) + apply h.congr_deriv + simp only [mul_apply_eq_comp] + change semigroup J s (generator J (fun x => Real.exp (θ * semigroup J (d - s) f x))) + + semigroup J s (fun x => -θ * Real.exp (θ * semigroup J (d - s) f x) * + generator J (semigroup J (d - s) f) x) = _ + rw [← map_add] + congr 1 + funext x + simp only [Pi.add_apply, expDrift] + ring + +lemma semigroup_pos {n : ℕ} (J : Interaction n) (t : ℝ) (ht : 0 ≤ t) + {f : Observables n} (hf : ∀ x, 0 < f x) (x : Spin n) : 0 < semigroup J t f x := by + obtain ⟨y, _, hy⟩ := Finset.exists_min_image (Finset.univ : Finset (Spin n)) f + Finset.univ_nonempty + have h := semigroup_mono J t ht (fun z => hy z (Finset.mem_univ z)) x + exact (hf y).trans_le (by simpa only [semigroup_const] using h) + +lemma expDrift_continuous {n : ℕ} (J : Interaction n) (θ : ℝ) : + Continuous (expDrift J θ) := by + unfold expDrift generator halfDiff + fun_prop + +lemma interpolated_exp_continuous {n : ℕ} (J : Interaction n) (f : Observables n) + (θ d : ℝ) (x : Spin n) : + Continuous (fun s : ℝ => semigroup J s + (fun y => Real.exp (θ * semigroup J (d - s) f y)) x) := by + exact continuous_apply x |>.comp + ((show Differentiable ℝ (fun s : ℝ => semigroup J s + (fun y => Real.exp (θ * semigroup J (d - s) f y))) from + fun s => (interpolated_exp_hasDerivAt J f θ d s).differentiableAt).continuous) + +lemma interpolated_expDrift_continuous {n : ℕ} (J : Interaction n) (f : Observables n) + (θ d : ℝ) (x : Spin n) : + Continuous (fun s : ℝ => semigroup J s (expDrift J θ (semigroup J (d - s) f)) x) := by + have hc : Continuous (fun s : ℝ => semigroup J (d - s) f) := + ((semigroup_continuous J).comp (continuous_const.sub continuous_id)).clm_apply continuous_const + exact continuous_apply x |>.comp ((semigroup_continuous J).clm_apply + ((expDrift_continuous J θ).comp hc)) + +theorem semigroup_jump_mgf {n : ℕ} (J : Interaction n) (f : Observables n) + (d : ℝ) (hd : 0 ≤ d) (b : ℝ → ℝ) (B θ : ℝ) + (hb : IntervalIntegrable b MeasureTheory.volume 0 d) + (hB : ∀ r ∈ Set.Icc (0 : ℝ) d, b r ≤ B) + (hbound : ∀ r ∈ Set.Icc (0 : ℝ) d, ∀ x, ∑ i, (halfDiff i (semigroup J r f) x) ^ 2 ≤ b r) + (x : Spin n) : + semigroup J d (fun y => Real.exp (θ * (f y - semigroup J d f x))) x ≤ + Real.exp (2 * θ ^ 2 * Real.exp (2 * |θ| * Real.sqrt B) * ∫ r in (0 : ℝ)..d, b r) := by + let F (s : ℝ) := semigroup J s (fun y => Real.exp (θ * semigroup J (d - s) f y)) x + let F' (s : ℝ) := semigroup J s (expDrift J θ (semigroup J (d - s) f)) x + let K := 2 * θ ^ 2 * Real.exp (2 * |θ| * Real.sqrt B) + have hFpos (s : ℝ) (hs : 0 ≤ s) : 0 < F s := + semigroup_pos J s hs (fun y => Real.exp_pos _) x + have hFderiv (s : ℝ) : HasDerivAt F (F' s) s := + hasDerivAt_pi.mp (interpolated_exp_hasDerivAt J f θ d s) x + have hlog (s : ℝ) (hs : s ∈ Set.Icc (0 : ℝ) d) : + HasDerivAt (fun r => Real.log (F r)) (F' s / F s) s := + (hFderiv s).log (hFpos s hs.1).ne' + have hcont : ContinuousOn (fun s => F' s / F s) (Set.uIcc (0 : ℝ) d) := by + apply (interpolated_expDrift_continuous J f θ d x).continuousOn.div + (interpolated_exp_continuous J f θ d x).continuousOn + intro s hs + have hs' : s ∈ Set.Icc (0 : ℝ) d := by simpa only [Set.uIcc_of_le hd] using hs + exact (hFpos s hs'.1).ne' + have hI : Real.log (F d) - Real.log (F 0) = + ∫ s in (0 : ℝ)..d, F' s / F s := by + symm + apply intervalIntegral.integral_eq_sub_of_hasDerivAt _ hcont.intervalIntegrable + intro s hs + exact hlog s (by simpa only [Set.uIcc_of_le hd] using hs) + have hbr : IntervalIntegrable (fun s => b (d - s)) MeasureTheory.volume 0 d := by + simpa only [sub_self, sub_zero] using (hb.comp_sub_left d).symm + have hle : Real.log (F d) - Real.log (F 0) ≤ K * ∫ r in (0 : ℝ)..d, b r := by + rw [hI] + calc + _ ≤ ∫ s in (0 : ℝ)..d, K * b (d - s) := by + apply intervalIntegral.integral_mono_on hd hcont.intervalIntegrable (hbr.const_mul K) + intro s hs + apply (div_le_iff₀ (hFpos s hs.1)).mpr + have hr : d - s ∈ Set.Icc (0 : ℝ) d := ⟨sub_nonneg.mpr hs.2, by linarith [hs.1]⟩ + have hp := semigroup_mono J s hs.1 + (fun y => expDrift_le J θ (semigroup J (d - s) f) y B (b (d - s)) + ((hbound (d - s) hr y).trans (hB (d - s) hr)) (hbound (d - s) hr y)) x + change F' s ≤ semigroup J s ((K * b (d - s)) • + (fun y => Real.exp (θ * semigroup J (d - s) f y))) x at hp + simpa only [map_smul, Pi.smul_apply, smul_eq_mul] using hp + _ = _ := by + rw [intervalIntegral.integral_const_mul, intervalIntegral.integral_comp_sub_left] + simp only [sub_self, sub_zero] + have hF0 : F 0 = Real.exp (θ * semigroup J d f x) := by + dsimp [F] + rw [sub_zero, semigroup_zero, one_apply_eq_self] + have hFd : F d = semigroup J d (fun y => Real.exp (θ * f y)) x := by + simp only [F, sub_self, semigroup_zero, one_apply_eq_self] + rw [hF0, Real.log_exp] at hle + have hle' := (Real.log_le_iff_le_exp (hFpos d hd)).mp (sub_le_iff_le_add.mp hle) + have hfactor : (fun y => Real.exp (θ * (f y - semigroup J d f x))) = + Real.exp (-(θ * semigroup J d f x)) • (fun y => Real.exp (θ * f y)) := by + funext y + simp only [Pi.smul_apply, smul_eq_mul, mul_sub, Real.exp_sub, Real.exp_neg] + ring + rw [hfactor, map_smul, Pi.smul_apply, smul_eq_mul] + calc + _ ≤ Real.exp (-(θ * semigroup J d f x)) * + Real.exp (K * (∫ r in (0 : ℝ)..d, b r) + θ * semigroup J d f x) := + mul_le_mul_of_nonneg_left (by rwa [hFd] at hle') (Real.exp_pos _).le + _ = _ := by rw [← Real.exp_add]; congr 1; dsimp [K]; ring + +end SKGapCutoff + +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/ExpDuhamel.lean b/lean/OAI/Probability/SKGap/Localization/ExpDuhamel.lean new file mode 100644 index 0000000000000000000000000000000000000000..397549f89f1e15f09223d2dcd0765dc4d402a21b --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/ExpDuhamel.lean @@ -0,0 +1,174 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.FrobeniusSq + +namespace OAI + +noncomputable section + +open MeasureTheory ProbabilityTheory InformationTheory Real Set +open scoped NNReal ENNReal +open Filter +open scoped Topology +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius ENNReal NNReal +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius NNReal +open MeasureTheory ProbabilityTheory Real Set Filter +open MeasureTheory.Measure +open scoped ENNReal NNReal MeasureTheory Topology +open MeasureTheory +open MeasureTheory Set NormedSpace +open scoped Topology +namespace SKGap +section Algebra +variable {A : Type*} [NormedRing A] [NormedAlgebra ℝ A] [NormedAlgebra ℚ A] [CompleteSpace A] + +lemma exp_duhamel (a b : A) : + exp a - exp b = ∫ u : ℝ in (0 : ℝ)..1, exp ((1-u) • a) * (a-b) * exp (u • b) := by + have hd (u : ℝ) : HasDerivAt (fun u : ℝ => exp ((1-u) • a) * exp (u • b)) + (-(exp ((1-u) • a) * (a-b) * exp (u • b))) u := by + have h₁ := (hasDerivAt_exp_smul_const a (1-u)).scomp u ((hasDerivAt_const u (1:ℝ)).sub (hasDerivAt_id u)) + have h₂ := hasDerivAt_exp_smul_const' b u + convert h₁.mul h₂ using 1 <;> (try simp only [zero_sub, neg_smul, one_smul]) <;> noncomm_ring + have hc : Continuous (fun u : ℝ => -(exp ((1-u) • a) * (a-b) * exp (u • b))) := by fun_prop + have hh := intervalIntegral.integral_eq_sub_of_hasDerivAt (fun u _ => hd u) + (hc.intervalIntegrable 0 1) + simpa only [intervalIntegral.integral_neg, sub_self, zero_smul, NormedSpace.exp_zero, one_mul, + sub_zero, one_smul, mul_one, neg_neg, neg_sub] using congrArg Neg.neg hh.symm + +end Algebra + +variable {A : Type*} [NormedRing A] [NormedAlgebra ℝ A] [NormedAlgebra ℚ A] [CompleteSpace A] + [StarRing A] [ContinuousStar A] [CStarRing A] + +omit [CStarRing A] in +lemma exp_skew_unitary (a : A) (ha : star a = -a) (t : ℝ) + [StarModule ℝ A] : exp (t • a) ∈ unitary A := by + apply exp_mem_unitary_of_mem_skewAdjoint + change star (t • a) = -(t • a) + simp [ha] + +lemma exp_skew_difference [StarModule ℝ A] (a b : A) + (ha : star a = -a) (hb : star b = -b) : ‖exp a - exp b‖ ≤ ‖a-b‖ := by + rw [exp_duhamel] + have hc : Continuous (fun u : ℝ => exp ((1-u) • a) * (a-b) * exp (u • b)) := by fun_prop + have hh : ∀ u : ℝ, ‖exp ((1-u) • a) * (a-b) * exp (u • b)‖ = ‖a-b‖ := by + intro u + rw [CStarRing.norm_mul_coe_unitary _ ⟨_,exp_skew_unitary b hb u⟩, + CStarRing.norm_coe_unitary_mul ⟨_,exp_skew_unitary a ha (1-u)⟩] + calc + ‖∫ u : ℝ in (0 : ℝ)..1, exp ((1-u) • a) * (a-b) * exp (u • b)‖ ≤ + ∫ u : ℝ in (0 : ℝ)..1, ‖exp ((1-u) • a) * (a-b) * exp (u • b)‖ := + intervalIntegral.norm_integral_le_integral_norm (by norm_num) + _ = ‖a-b‖ := by simp only [hh]; simp + +end SKGap + +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius +namespace SKGap +namespace ComplexMatrix +variable {ι : Type*} [Fintype ι] [DecidableEq ι] + +abbrev lin (M : Matrix ι ι ℂ) := M.toEuclideanLin.toContinuousLinearMap +noncomputable def opNorm (M : Matrix ι ι ℂ) : ℝ := ‖lin M‖ +noncomputable def colVec (M : Matrix ι ι ℂ) (k : ι) : EuclideanSpace ℂ ι := WithLp.toLp 2 (fun i => M i k) + +lemma frobenius_sq (M : Matrix ι ι ℂ) : ‖M‖^2 = ∑ i,∑ k, ‖M i k‖^2 := by + rw [Matrix.frobenius_norm_def] + simp only [Real.rpow_two] + rw [← Real.sqrt_eq_rpow,Real.sq_sqrt] + positivity + +lemma frobenius_col_sq (M : Matrix ι ι ℂ) : ‖M‖^2 = ∑ k, ‖colVec M k‖^2 := by + rw [frobenius_sq,Finset.sum_comm] + apply Finset.sum_congr rfl + intro k _ + simp [EuclideanSpace.norm_sq_eq,colVec] + +lemma colVec_mul (M N : Matrix ι ι ℂ) (k : ι) : + colVec (M*N) k = lin M (colVec N k) := by ext i; rfl + +lemma lin_mul (M N : Matrix ι ι ℂ) : lin (M*N) = lin M * lin N := by + apply ContinuousLinearMap.ext + intro x + exact congrArg (fun T : EuclideanSpace ℂ ι →ₗ[ℂ] EuclideanSpace ℂ ι => T x) + (Matrix.toLpLin_mul 2 2 2 M N) + +lemma lin_one : lin (1 : Matrix ι ι ℂ) = 1 := by + ext x i + change (Matrix.mulVec 1 (WithLp.ofLp x)) i = x i + simp + +lemma frobenius_mul_le_opNorm (M N : Matrix ι ι ℂ) : ‖M*N‖ ≤ opNorm M * ‖N‖ := by + have hp : 0 ≤ opNorm M := norm_nonneg _ + apply nonneg_le_nonneg_of_sq_le_sq (mul_nonneg hp (norm_nonneg N)) + simp only [← sq] + rw [frobenius_col_sq,mul_pow,frobenius_col_sq,Finset.mul_sum] + apply Finset.sum_le_sum + intro k _ + rw [colVec_mul] + have hh := (lin M).le_opNorm (colVec N k) + change ‖lin M (colVec N k)‖ ≤ opNorm M * ‖colVec N k‖ at hh + nlinarith only [hh,norm_nonneg (lin M (colVec N k)),mul_nonneg hp (norm_nonneg (colVec N k))] + +lemma lin_adjoint (M : Matrix ι ι ℂ) : lin Mᴴ = (lin M).adjoint := by + rw [lin,Matrix.toEuclideanLin_conjTranspose_eq_adjoint,LinearMap.adjoint_toContinuousLinearMap] + +lemma opNorm_adjoint (M : Matrix ι ι ℂ) : opNorm Mᴴ = opNorm M := by + rw [opNorm,lin_adjoint,ContinuousLinearMap.adjoint.norm_map] + rfl + +lemma frobenius_mul_le_opNorm_right (M N : Matrix ι ι ℂ) : ‖M*N‖ ≤ ‖M‖ * opNorm N := by + rw [← Matrix.frobenius_norm_conjTranspose (M*N),Matrix.conjTranspose_mul] + exact (frobenius_mul_le_opNorm Nᴴ Mᴴ).trans_eq (by rw [opNorm_adjoint,Matrix.frobenius_norm_conjTranspose,mul_comm]) + +lemma lin_unitary (U : Matrix ι ι ℂ) (hU : U ∈ unitary (Matrix ι ι ℂ)) : + lin U ∈ unitary (EuclideanSpace ℂ ι →L[ℂ] EuclideanSpace ℂ ι) := by + change (lin U).adjoint * lin U = 1 ∧ lin U * (lin U).adjoint = 1 + rw [← lin_adjoint,← lin_mul,← lin_mul] + constructor + · rw [show Uᴴ * U = 1 from Unitary.star_mul_self_of_mem hU,lin_one] + · rw [show U * Uᴴ = 1 from Unitary.mul_star_self_of_mem hU,lin_one] + +lemma frobenius_unitary_mul (U M : Matrix ι ι ℂ) (hU : U ∈ unitary (Matrix ι ι ℂ)) : + ‖U*M‖ = ‖M‖ := by + have hh : ‖U*M‖^2 = ‖M‖^2 := by + rw [frobenius_col_sq,frobenius_col_sq] + apply Finset.sum_congr rfl + intro k _ + rw [colVec_mul,ContinuousLinearMap.norm_map_of_mem_unitary (lin_unitary U hU)] + nlinarith [norm_nonneg (U*M),norm_nonneg M] + +lemma frobenius_mul_unitary (M U : Matrix ι ι ℂ) (hU : U ∈ unitary (Matrix ι ι ℂ)) : + ‖M*U‖ = ‖M‖ := by + rw [← Matrix.frobenius_norm_conjTranspose (M*U),Matrix.conjTranspose_mul] + rw [frobenius_unitary_mul Uᴴ Mᴴ (Unitary.star_mem hU),Matrix.frobenius_norm_conjTranspose] + +end ComplexMatrix +end SKGap + +namespace SKGap.ComplexMatrix +variable {ι : Type*} [Fintype ι] [DecidableEq ι] + +def linEquiv : Matrix ι ι ℂ ≃ₗ[ℂ] (EuclideanSpace ℂ ι →L[ℂ] EuclideanSpace ℂ ι) := + Matrix.toEuclideanLin.trans LinearMap.toContinuousLinearMap + +def linHom : Matrix ι ι ℂ →+* (EuclideanSpace ℂ ι →L[ℂ] EuclideanSpace ℂ ι) where + toFun := lin + map_one' := lin_one + map_mul' := lin_mul + map_zero' := linEquiv.map_zero + map_add' := linEquiv.map_add + +lemma continuous_lin : Continuous (lin : Matrix ι ι ℂ → _) := + (linEquiv (ι := ι)).toLinearMap.continuous_of_finiteDimensional + +lemma lin_exp (M : Matrix ι ι ℂ) : lin (NormedSpace.exp M) = NormedSpace.exp (lin M) := + NormedSpace.map_exp linHom continuous_lin M + +end SKGap.ComplexMatrix + +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/ExpSum.lean b/lean/OAI/Probability/SKGap/Localization/ExpSum.lean new file mode 100644 index 0000000000000000000000000000000000000000..b234ef25519f86ba4653315724764111afb0d114 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/ExpSum.lean @@ -0,0 +1,500 @@ +import Mathlib +import OAI.Probability.SKGap.Gaussian.StandardGaussianProduct + +namespace OAI + +section +noncomputable section +open MeasureTheory ProbabilityTheory InformationTheory Real Set +open scoped NNReal ENNReal +open Filter +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius ENNReal NNReal +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius NNReal +noncomputable section +open MeasureTheory ProbabilityTheory Real Set Filter +open MeasureTheory.Measure +open scoped ENNReal NNReal MeasureTheory Topology +open MeasureTheory +noncomputable section +noncomputable section +open MeasureTheory Set NormedSpace +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius +noncomputable section +open Set Real +open scoped Topology +noncomputable section +open Matrix Set Filter +open scoped Topology Matrix.Norms.Frobenius +noncomputable section +open Matrix NormedSpace ContinuousLinearMap +open scoped Matrix.Norms.Frobenius +noncomputable section +open Matrix +noncomputable section +open MeasureTheory ProbabilityTheory Real Set +open scoped ENNReal NNReal +noncomputable section +open MeasureTheory ProbabilityTheory InformationTheory Real Set +open scoped NNReal ENNReal +namespace SKGap + +instance (n : ℕ) : IsProbabilityMeasure (standardGaussianProduct n) := by + unfold standardGaussianProduct + infer_instance + +variable {ι : Type*} [Fintype ι] [Nonempty ι] + +def expSum (κ : ℝ) (x : ι → ℝ) : ℝ := ∑ i, Real.exp (κ * x i) +def softWeight (κ : ℝ) (x : ι → ℝ) (i : ι) : ℝ := Real.exp (κ * x i) / expSum κ x +def smoothMax (κ : ℝ) (x : ι → ℝ) : ℝ := log (expSum κ x) / κ + +theorem expSum_pos (κ : ℝ) (x : ι → ℝ) : 0 < expSum κ x := by + exact Finset.sum_pos (fun i _ => exp_pos _) Finset.univ_nonempty + +theorem softWeight_pos (κ : ℝ) (x : ι → ℝ) (i : ι) : 0 < softWeight κ x i := + div_pos (exp_pos _) (expSum_pos κ x) + +theorem sum_softWeight (κ : ℝ) (x : ι → ℝ) : ∑ i, softWeight κ x i = 1 := by + simp only [softWeight, ← Finset.sum_div] + exact div_self (expSum_pos κ x).ne' + +theorem softWeight_le_one (κ : ℝ) (x : ι → ℝ) (i : ι) : softWeight κ x i ≤ 1 := by + rw [← sum_softWeight κ x] + exact Finset.single_le_sum (fun j _ => (softWeight_pos κ x j).le) (Finset.mem_univ i) + +theorem continuous_softWeight (κ : ℝ) (i : ι) : Continuous (fun x : ι → ℝ => softWeight κ x i) := by + apply Continuous.div + · exact continuous_exp.comp (continuous_const.mul (continuous_apply i)) + · exact continuous_finsetSum _ (fun j _ => continuous_exp.comp (continuous_const.mul (continuous_apply j))) + · exact fun x => (expSum_pos κ x).ne' + +theorem continuous_smoothMax (κ : ℝ) : Continuous (smoothMax κ : (ι → ℝ) → ℝ) := by + apply Continuous.div_const + exact (continuous_finsetSum _ (fun j _ => continuous_exp.comp (continuous_const.mul (continuous_apply j)))).log + (fun x => (expSum_pos κ x).ne') + +omit [Nonempty ι] in +theorem hasDerivAt_expSum {κ t : ℝ} {f : ι → ℝ → ℝ} {df : ι → ℝ} + (hf : ∀ i, HasDerivAt (f i) (df i) t) : + HasDerivAt (fun s => expSum κ (fun i => f i s)) + (∑ i, Real.exp (κ * f i t) * (κ * df i)) t := by + convert! HasDerivAt.fun_sum (fun i _ => ((hf i).const_mul κ).exp) using 1 + +theorem hasDerivAt_smoothMax {κ t : ℝ} (hκ : κ ≠ 0) {f : ι → ℝ → ℝ} {df : ι → ℝ} + (hf : ∀ i, HasDerivAt (f i) (df i) t) : + HasDerivAt (fun s => smoothMax κ (fun i => f i s)) + (∑ i, softWeight κ (fun j => f j t) i * df i) t := by + convert! ((hasDerivAt_expSum hf).log (expSum_pos κ (fun j => f j t)).ne').div_const κ using 1 + simp only [softWeight] + have hs : (∑ i, Real.exp (κ * f i t) * (κ * df i)) = + κ * ∑ i, Real.exp (κ * f i t) * df i := by + rw [Finset.mul_sum] + apply Finset.sum_congr rfl + intro i _ + ring + rw [hs] + simp_rw [div_mul_eq_mul_div, ← Finset.sum_div] + field_simp [hκ, (expSum_pos κ (fun j => f j t)).ne'] + +theorem hasDerivAt_softWeight {κ t : ℝ} {f : ι → ℝ → ℝ} {df : ι → ℝ} + (hf : ∀ i, HasDerivAt (f i) (df i) t) (i : ι) : + HasDerivAt (fun s => softWeight κ (fun j => f j s) i) + (κ * softWeight κ (fun j => f j t) i * + (df i - ∑ j, softWeight κ (fun k => f k t) j * df j)) t := by + convert! (((hf i).const_mul κ).exp).div (hasDerivAt_expSum hf) + (expSum_pos κ (fun j => f j t)).ne' using 1 + simp only [softWeight] + have hs : (∑ j, Real.exp (κ * f j t) * (κ * df j)) = + κ * ∑ j, Real.exp (κ * f j t) * df j := by + rw [Finset.mul_sum] + apply Finset.sum_congr rfl + intro j _ + ring + rw [hs] + simp_rw [div_mul_eq_mul_div, ← Finset.sum_div] + field_simp [(expSum_pos κ (fun j => f j t)).ne'] + +theorem weighted_abs_le (κ : ℝ) (x v : ι → ℝ) : + |∑ i, softWeight κ x i * v i| ≤ ∑ i, |v i| := by + calc + _ ≤ ∑ i, |softWeight κ x i * v i| := Finset.abs_sum_le_sum_abs _ _ + _ ≤ ∑ i, |v i| := by + apply Finset.sum_le_sum + intro i _ + rw [abs_mul, abs_of_pos (softWeight_pos κ x i)] + exact mul_le_of_le_one_left (abs_nonneg _) (softWeight_le_one κ x i) + +omit [Nonempty ι] in +theorem smoothMax_ge {κ : ℝ} (hκ : 0 < κ) (x : ι → ℝ) (i : ι) : + x i ≤ smoothMax κ x := by + rw [smoothMax, le_div_iff₀ hκ] + calc + x i * κ = log (Real.exp (κ * x i)) := by rw [log_exp]; ring + _ ≤ log (expSum κ x) := log_le_log (exp_pos _) <| + Finset.single_le_sum (fun j _ => (exp_pos (κ * x j)).le) (Finset.mem_univ i) + +theorem smoothMax_le {κ : ℝ} (hκ : 0 < κ) (x : ι → ℝ) {b : ℝ} + (hb : ∀ i, x i ≤ b) : smoothMax κ x ≤ b + log (Fintype.card ι) / κ := by + have hn : (0 : ℝ) < Fintype.card ι := Nat.cast_pos.mpr Fintype.card_pos + rw [smoothMax, div_le_iff₀ hκ] + calc + log (expSum κ x) ≤ log ((Fintype.card ι : ℝ) * Real.exp (κ * b)) := by + apply log_le_log (expSum_pos _ _) + calc + _ ≤ ∑ _ : ι, Real.exp (κ * b) := Finset.sum_le_sum (fun i _ => exp_le_exp.mpr (mul_le_mul_of_nonneg_left (hb i) hκ.le)) + _ = _ := by simp + _ = _ := by rw [log_mul hn.ne' (exp_pos _).ne', log_exp]; field_simp; ring + +variable {ι : Type*} [Fintype ι] [Nonempty ι] + +def affineProcess {n : ℕ} (m : ι → ℝ) (a : ι → Fin n → ℝ) (z : Fin n → ℝ) (i : ι) : ℝ := + m i + ∑ k, a i k * z k + +omit [Fintype ι] [Nonempty ι] in +theorem continuous_affineProcess {n : ℕ} (m : ι → ℝ) (a : ι → Fin n → ℝ) : + Continuous (affineProcess m a) := by + apply continuous_pi + intro i + exact continuous_const.add (continuous_finsetSum _ (fun k _ => continuous_const.mul (continuous_apply k))) + +omit [Fintype ι] [Nonempty ι] in +theorem affineProcess_coordinate_hasDerivAt {n : ℕ} (m : ι → ℝ) + (a : ι → Fin (n + 1) → ℝ) (i : ι) (k : Fin (n + 1)) (u : Fin n → ℝ) (z : ℝ) : + HasDerivAt (fun z => affineProcess m a (k.insertNth z u) i) (a i k) z := by + have he (z : ℝ) : affineProcess m a (k.insertNth z u) i = + a i k * z + (m i + ∑ l, a i (k.succAbove l) * u l) := by + rw [affineProcess, Fin.sum_univ_succAbove _ k] + simp only [Fin.insertNth_apply_same, Fin.insertNth_apply_succAbove] + ring + simp_rw [he] + convert! ((hasDerivAt_id z).const_mul (a i k)).add_const (m i + ∑ l, a i (k.succAbove l) * u l) using 1 + simp + +theorem affine_softWeight_coordinate_IBP {n : ℕ} (κ : ℝ) (m : ι → ℝ) + (a : ι → Fin (n + 1) → ℝ) (i : ι) (k : Fin (n + 1)) : + (∫ z, z k * softWeight κ (affineProcess m a z) i ∂standardGaussianProduct (n + 1)) = + ∫ z, κ * softWeight κ (affineProcess m a z) i * + (a i k - ∑ j, softWeight κ (affineProcess m a z) j * a j k) + ∂standardGaussianProduct (n + 1) := by + apply gaussianProduct_coordinate_IBP (C := 1) (D := |κ| * (|a i k| + ∑ j, |a j k|)) k + · exact (continuous_softWeight κ i).comp (continuous_affineProcess m a) + · exact (continuous_const.mul ((continuous_softWeight κ i).comp (continuous_affineProcess m a))).mul + (continuous_const.sub (continuous_finsetSum _ (fun j _ => + ((continuous_softWeight κ j).comp (continuous_affineProcess m a)).mul continuous_const))) + · intro z + rw [Real.norm_eq_abs, abs_of_pos (softWeight_pos _ _ _)] + exact softWeight_le_one _ _ _ + · intro z + rw [norm_mul, norm_mul, Real.norm_eq_abs κ, + Real.norm_eq_abs (softWeight _ _ _), abs_of_pos (softWeight_pos _ _ _), Real.norm_eq_abs] + apply mul_le_mul + · exact mul_le_of_le_one_right (abs_nonneg κ) (softWeight_le_one _ _ _) + · exact (abs_sub _ _).trans (add_le_add_right (weighted_abs_le κ _ (fun j => a j k)) _) + · positivity + · positivity + · intro u z + exact hasDerivAt_softWeight (fun j => affineProcess_coordinate_hasDerivAt m a j k u z) i + +omit [Nonempty ι] in +theorem weighted_covariance_identity (p u v : ι → ℝ) (hp : ∑ i, p i = 1) : + (∑ i, p i * u i * v i) - (∑ i, p i * u i) * (∑ i, p i * v i) = + (1 / 2 : ℝ) * ∑ i, ∑ j, p i * p j * (u i - u j) * (v i - v j) := by + have he (i j : ι) : p i * p j * (u i - u j) * (v i - v j) = + (p i * u i * v i) * p j + p i * (p j * u j * v j) - + (p i * u i) * (p j * v j) - (p i * v i) * (p j * u j) := by ring + simp_rw [he, Finset.sum_sub_distrib, Finset.sum_add_distrib, + ← Finset.mul_sum, ← Finset.sum_mul] + rw [hp] + ring + +theorem smoothMax_norm_le {κ : ℝ} (hκ : 0 < κ) (x : ι → ℝ) : + ‖smoothMax κ x‖ ≤ ∑ i, |x i| + log (Fintype.card ι) / κ := by + have hn : (1 : ℝ) ≤ Fintype.card ι := by exact_mod_cast Fintype.card_pos + have hlog : 0 ≤ log (Fintype.card ι) / κ := div_nonneg (log_nonneg hn) hκ.le + have hb (i : ι) : |x i| ≤ ∑ j, |x j| := + Finset.single_le_sum (fun j _ => abs_nonneg (x j)) (Finset.mem_univ i) + rw [Real.norm_eq_abs] + apply abs_le.mpr + constructor + · let i : ι := Classical.choice inferInstance + have hlo := smoothMax_ge hκ x i + have ha := (abs_le.mp (hb i)).1 + linarith + · exact smoothMax_le hκ x (fun i => (le_abs_self _).trans (hb i)) + +def interpolatedCoeff {n : ℕ} (a b : ι → Fin n → ℝ) (t : ℝ) (i : ι) (k : Fin n) : ℝ := + sin t * a i k + cos t * b i k + +def interpolatedCoeffDeriv {n : ℕ} (a b : ι → Fin n → ℝ) (t : ℝ) (i : ι) (k : Fin n) : ℝ := + cos t * a i k - sin t * b i k + +def processBound {n : ℕ} (a b : ι → Fin n → ℝ) (z : Fin n → ℝ) : ℝ := + ∑ i, ∑ k, (|a i k| + |b i k|) * |z k| + +omit [Fintype ι] [Nonempty ι] in +theorem interpolatedCoeff_abs_le {n : ℕ} (a b : ι → Fin n → ℝ) (t : ℝ) (i : ι) (k : Fin n) : + |interpolatedCoeff a b t i k| ≤ |a i k| + |b i k| := by + calc + _ ≤ |sin t * a i k| + |cos t * b i k| := abs_add_le _ _ + _ ≤ 1 * |a i k| + 1 * |b i k| := by + simp only [abs_mul] + gcongr + · exact abs_sin_le_one t + · exact abs_cos_le_one t + _ = _ := by ring + +omit [Fintype ι] [Nonempty ι] in +theorem interpolatedCoeffDeriv_abs_le {n : ℕ} (a b : ι → Fin n → ℝ) (t : ℝ) (i : ι) (k : Fin n) : + |interpolatedCoeffDeriv a b t i k| ≤ |a i k| + |b i k| := by + calc + _ ≤ |cos t * a i k| + |sin t * b i k| := abs_sub _ _ + _ ≤ 1 * |a i k| + 1 * |b i k| := by + simp only [abs_mul] + gcongr + · exact abs_cos_le_one t + · exact abs_sin_le_one t + _ = _ := by ring + +omit [Nonempty ι] in +theorem integrable_processBound {n : ℕ} (a b : ι → Fin n → ℝ) : + Integrable (processBound a b) (standardGaussianProduct n) := by + apply integrable_finsetSum + intro i _ + apply integrable_finsetSum + intro k _ + exact ((integrable_eval (i := k) IsGaussian.integrable_id).norm).const_mul _ + +omit [Fintype ι] [Nonempty ι] in +theorem interpolated_affine_hasDerivAt {n : ℕ} (m : ι → ℝ) (a b : ι → Fin n → ℝ) + (z : Fin n → ℝ) (t : ℝ) (i : ι) : + HasDerivAt (fun t => affineProcess m (interpolatedCoeff a b t) z i) + (∑ k, interpolatedCoeffDeriv a b t i k * z k) t := by + convert! (HasDerivAt.fun_sum (fun k _ => + (((Real.hasDerivAt_sin t).mul_const (a i k)).add + ((Real.hasDerivAt_cos t).mul_const (b i k))).mul_const (z k))).const_add (m i) using 1 + apply Finset.sum_congr rfl + intro k _ + dsimp [interpolatedCoeffDeriv] + ring + +def interpolationDerivative {n : ℕ} (κ : ℝ) (m : ι → ℝ) (a b : ι → Fin n → ℝ) + (t : ℝ) (z : Fin n → ℝ) : ℝ := + ∑ i, softWeight κ (affineProcess m (interpolatedCoeff a b t) z) i * + ∑ k, interpolatedCoeffDeriv a b t i k * z k + +theorem interpolationDerivative_norm_le {n : ℕ} (κ : ℝ) (m : ι → ℝ) + (a b : ι → Fin n → ℝ) (t : ℝ) (z : Fin n → ℝ) : + ‖interpolationDerivative κ m a b t z‖ ≤ processBound a b z := by + rw [Real.norm_eq_abs] + calc + _ ≤ ∑ i, |∑ k, interpolatedCoeffDeriv a b t i k * z k| := weighted_abs_le _ _ _ + _ ≤ ∑ i, ∑ k, (|a i k| + |b i k|) * |z k| := by + apply Finset.sum_le_sum + intro i _ + apply (Finset.abs_sum_le_sum_abs _ _).trans + apply Finset.sum_le_sum + intro k _ + rw [abs_mul] + exact mul_le_mul_of_nonneg_right (interpolatedCoeffDeriv_abs_le a b t i k) (abs_nonneg _) + +theorem interpolated_smoothMax_norm_le {n : ℕ} {κ : ℝ} (hκ : 0 < κ) (m : ι → ℝ) + (a b : ι → Fin n → ℝ) (t : ℝ) (z : Fin n → ℝ) : + ‖smoothMax κ (affineProcess m (interpolatedCoeff a b t) z)‖ ≤ + (∑ i, |m i|) + processBound a b z + log (Fintype.card ι) / κ := by + apply (smoothMax_norm_le hκ _).trans + gcongr + rw [processBound, ← Finset.sum_add_distrib] + apply Finset.sum_le_sum + intro i _ + apply (abs_add_le _ _).trans + gcongr + apply (Finset.abs_sum_le_sum_abs _ _).trans + apply Finset.sum_le_sum + intro k _ + rw [abs_mul] + exact mul_le_mul_of_nonneg_right (interpolatedCoeff_abs_le a b t i k) (abs_nonneg _) + +theorem interpolation_hasDerivAt {n : ℕ} {κ : ℝ} (hκ : 0 < κ) + (m : ι → ℝ) (a b : ι → Fin n → ℝ) (t : ℝ) : + HasDerivAt (fun t => ∫ z, smoothMax κ (affineProcess m (interpolatedCoeff a b t) z) + ∂standardGaussianProduct n) + (∫ z, interpolationDerivative κ m a b t z ∂standardGaussianProduct n) t := by + have hp (t : ℝ) (i : ι) : + Continuous (fun z => softWeight κ (affineProcess m (interpolatedCoeff a b t) z) i) := + (continuous_softWeight κ i).comp (continuous_affineProcess m _) + have hf (t : ℝ) : Continuous (fun z => smoothMax κ (affineProcess m (interpolatedCoeff a b t) z)) := + (continuous_smoothMax κ).comp (continuous_affineProcess m _) + have hdf (t : ℝ) : Continuous (interpolationDerivative κ m a b t) := by + apply continuous_finsetSum + intro i _ + exact (hp t i).mul (continuous_finsetSum _ (fun k _ => continuous_const.mul (continuous_apply k))) + have hb : Integrable (fun z => (∑ i, |m i|) + processBound a b z + log (Fintype.card ι) / κ) + (standardGaussianProduct n) := + ((integrable_const _).add (integrable_processBound a b)).add (integrable_const _) + exact (hasDerivAt_integral_of_dominated_loc_of_deriv_le + (μ := standardGaussianProduct n) (s := univ) (x₀ := t) + (F := fun t z => smoothMax κ (affineProcess m (interpolatedCoeff a b t) z)) + (F' := fun t z => interpolationDerivative κ m a b t z) + (bound := processBound a b) + Filter.univ_mem (Filter.Eventually.of_forall (fun t => (hf t).aestronglyMeasurable)) + (hb.mono' (hf t).aestronglyMeasurable (ae_of_all _ (interpolated_smoothMax_norm_le hκ m a b t))) + (hdf t).aestronglyMeasurable + (ae_of_all _ (fun z t _ => interpolationDerivative_norm_le κ m a b t z)) + (integrable_processBound a b) + (ae_of_all _ (fun z t _ => hasDerivAt_smoothMax hκ.ne' + (fun i => interpolated_affine_hasDerivAt m a b z t i)))).2 + +theorem integrable_affine_weight {n : ℕ} (κ : ℝ) (m : ι → ℝ) (a : ι → Fin n → ℝ) (i : ι) : + Integrable (fun z => softWeight κ (affineProcess m a z) i) (standardGaussianProduct n) := by + apply Integrable.of_bound ((continuous_softWeight κ i).comp (continuous_affineProcess m a)).aestronglyMeasurable 1 + exact ae_of_all _ (fun z => by + simp only [Function.comp_def] + rw [Real.norm_eq_abs, abs_of_pos (softWeight_pos _ _ _)] + exact softWeight_le_one _ _ _) + +theorem integrable_coordinate_weight {n : ℕ} (κ : ℝ) (m : ι → ℝ) + (a : ι → Fin n → ℝ) (i : ι) (k : Fin n) : + Integrable (fun z => z k * softWeight κ (affineProcess m a z) i) (standardGaussianProduct n) := by + apply Integrable.mul_bdd (integrable_eval (i := k) IsGaussian.integrable_id) + ((continuous_softWeight κ i).comp (continuous_affineProcess m a)).aestronglyMeasurable + exact ae_of_all _ (fun z => by + simp only [Function.comp_def] + rw [Real.norm_eq_abs, abs_of_pos (softWeight_pos _ _ _)] + exact softWeight_le_one _ _ _) + +theorem integrable_weight_covariance {n : ℕ} (κ : ℝ) (m : ι → ℝ) + (a : ι → Fin n → ℝ) (i : ι) (k : Fin n) : + Integrable (fun z => κ * softWeight κ (affineProcess m a z) i * + (a i k - ∑ j, softWeight κ (affineProcess m a z) j * a j k)) + (standardGaussianProduct n) := by + have hi : Integrable (fun z => a i k - ∑ j, softWeight κ (affineProcess m a z) j * a j k) + (standardGaussianProduct n) := by + apply (integrable_const _).sub + exact integrable_finsetSum _ (fun j _ => (integrable_affine_weight κ m a j).mul_const _) + have hm := hi.bdd_mul ((continuous_softWeight κ i).comp (continuous_affineProcess m a)).aestronglyMeasurable + (ae_of_all _ (fun z => by + simp only [Function.comp_def] + rw [Real.norm_eq_abs, abs_of_pos (softWeight_pos κ (affineProcess m a z) i)] + exact softWeight_le_one _ _ _)) + convert! hm.const_mul κ using 1 + ext z + simp only [Function.comp_def] + ring + +omit [Nonempty ι] in +theorem weighted_matrix_covariance_identity {n : ℕ} (p : ι → ℝ) (a d : ι → Fin n → ℝ) + (hp : ∑ i, p i = 1) : + (∑ i, ∑ k, d i k * p i * (a i k - ∑ j, p j * a j k)) = + (1 / 2 : ℝ) * ∑ i, ∑ j, p i * p j * ∑ k, (d i k - d j k) * (a i k - a j k) := by + have hk (k : Fin n) : + (∑ i, d i k * p i * (a i k - ∑ j, p j * a j k)) = + (1/2:ℝ) * ∑ i, ∑ j, p i * p j * (d i k - d j k) * (a i k - a j k) := by + rw [← weighted_covariance_identity p (fun i => d i k) (fun i => a i k) hp] + simp_rw [mul_sub, Finset.sum_sub_distrib, ← Finset.sum_mul] + congr 1 + · apply Finset.sum_congr rfl + intro i _ + ring + · congr 1 + apply Finset.sum_congr rfl + intro i _ + ring + rw [Finset.sum_comm] + simp_rw [hk, ← Finset.mul_sum] + congr 1 + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro i _ + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro j _ + rw [Finset.mul_sum] + apply Finset.sum_congr rfl + intro k _ + ring + +theorem gaussian_linear_weight_IBP {n : ℕ} (κ : ℝ) (m : ι → ℝ) + (a d : ι → Fin (n + 1) → ℝ) : + (∫ z, ∑ i, softWeight κ (affineProcess m a z) i * ∑ k, d i k * z k + ∂standardGaussianProduct (n + 1)) = + (κ / 2) * ∫ z, ∑ i, ∑ j, + softWeight κ (affineProcess m a z) i * softWeight κ (affineProcess m a z) j * + ∑ k, (d i k - d j k) * (a i k - a j k) + ∂standardGaussianProduct (n + 1) := by + let p := fun z i => softWeight κ (affineProcess m a z) i + have hi (i : ι) (k : Fin (n + 1)) : Integrable (fun z => d i k * (z k * p z i)) + (standardGaussianProduct (n + 1)) := (integrable_coordinate_weight κ m a i k).const_mul _ + have hr (i : ι) (k : Fin (n + 1)) : Integrable (fun z => d i k * + (κ * p z i * (a i k - ∑ j, p z j * a j k))) (standardGaussianProduct (n + 1)) := + (integrable_weight_covariance κ m a i k).const_mul _ + calc + _ = ∫ z, ∑ i, ∑ k, d i k * (z k * p z i) ∂standardGaussianProduct (n + 1) := by + apply integral_congr_ae + filter_upwards [] with z + apply Finset.sum_congr rfl + intro i _ + rw [Finset.mul_sum] + apply Finset.sum_congr rfl + intro k _ + dsimp [p] + ring + _ = ∑ i, ∑ k, d i k * ∫ z, z k * p z i ∂standardGaussianProduct (n + 1) := by + rw [integral_finsetSum _ (fun i _ => integrable_finsetSum _ (fun k _ => hi i k))] + apply Finset.sum_congr rfl + intro i _ + rw [integral_finsetSum _ (fun k _ => hi i k)] + simp only [integral_const_mul] + _ = ∑ i, ∑ k, d i k * ∫ z, κ * p z i * (a i k - ∑ j, p z j * a j k) + ∂standardGaussianProduct (n + 1) := by + apply Finset.sum_congr rfl + intro i _ + apply Finset.sum_congr rfl + intro k _ + rw [affine_softWeight_coordinate_IBP] + _ = ∫ z, ∑ i, ∑ k, d i k * (κ * p z i * (a i k - ∑ j, p z j * a j k)) + ∂standardGaussianProduct (n + 1) := by + rw [integral_finsetSum _ (fun i _ => integrable_finsetSum _ (fun k _ => hr i k))] + apply Finset.sum_congr rfl + intro i _ + rw [integral_finsetSum _ (fun k _ => hr i k)] + simp only [integral_const_mul] + _ = _ := by + rw [← integral_const_mul] + apply integral_congr_ae + filter_upwards [] with z + have he := weighted_matrix_covariance_identity (p z) a d (sum_softWeight κ _) + calc + _ = κ * ∑ i, ∑ k, d i k * p z i * (a i k - ∑ j, p z j * a j k) := by + simp only [Finset.mul_sum] + apply Finset.sum_congr rfl + intro i _ + apply Finset.sum_congr rfl + intro k _ + ring + _ = _ := by rw [he]; dsimp [p]; ring + +end SKGap +end +end +end +end +end +end +end +end +end +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/ExpectedCutoff.lean b/lean/OAI/Probability/SKGap/Localization/ExpectedCutoff.lean new file mode 100644 index 0000000000000000000000000000000000000000..a40ceb1b32bebae5b784d4795f34d1a9e2f1f454 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/ExpectedCutoff.lean @@ -0,0 +1,251 @@ +import Mathlib +import OAI.Probability.SKGap.Matrix.RealSymmetricResolventUnit +import OAI.Probability.SKGap.Brownian.PathDiagonal + +namespace OAI + +section +noncomputable section +open MeasureTheory ProbabilityTheory InformationTheory Real Set +open scoped NNReal ENNReal +open Filter +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius ENNReal NNReal +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius NNReal +noncomputable section +open MeasureTheory ProbabilityTheory Real Set Filter +open MeasureTheory.Measure +open scoped ENNReal NNReal MeasureTheory Topology +open MeasureTheory +noncomputable section +noncomputable section +open MeasureTheory Set NormedSpace +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius +noncomputable section +open Set Real +open scoped Topology +noncomputable section +open Matrix Set Filter +open scoped Topology Matrix.Norms.Frobenius +noncomputable section +open Matrix NormedSpace ContinuousLinearMap +open scoped Matrix.Norms.Frobenius +noncomputable section +open Matrix +noncomputable section +open MeasureTheory ProbabilityTheory Real Set +open scoped ENNReal NNReal +noncomputable section +open MeasureTheory ProbabilityTheory InformationTheory Real Set +open scoped NNReal ENNReal +noncomputable section +open scoped BigOperators +open MeasureTheory ProbabilityTheory +open Real +noncomputable section +open scoped BigOperators Topology +open Filter Real +namespace SKGap +open Matrix MeasureTheory ProbabilityTheory Real Set +open RealComplex +open scoped BigOperators Matrix.Norms.Frobenius NNReal ENNReal SchwartzMap +variable {ι : Type*} [Fintype ι] [DecidableEq ι] + +noncomputable def expectedCutoff (f : 𝓢(ℝ,ℂ)) (R : ℝ) (hR : 0 ≤ R) + (D C : Matrix ι ι ℝ) (r : ℝ) (i : ι) : ℝ := + ∫ g, realTruncatedK f R hR D C (goeMatrix r g) i i + ∂(Measure.pi (fun _ : MatrixCoordinates ι => gaussianReal 0 1)) + +noncomputable def cutoffErrorOne (f : 𝓢(ℝ,ℂ)) (r R lo hi : ℝ) + (D C : Matrix ι ι ℝ) : ℝ := + let b := ComplexMatrix.kBound f R (liftMatrix D) (liftMatrix C) + let L := Real.toNNReal (ComplexMatrix.kLip f R (liftMatrix D) (liftMatrix C)) + let Lπ : ℝ≥0 := L*(⟨sqrt (2*r),sqrt_nonneg _⟩ * + (Fintype.card (MatrixCoordinates ι) : ℝ≥0) ^ (1/(2:ℝ≥0∞)).toReal) + let T : ℝ≥0 := (⟨sqrt (Fintype.card ι)*opNorm (D*D), + mul_nonneg (sqrt_nonneg _) (norm_nonneg _)⟩*L)*⟨sqrt (2*r),sqrt_nonneg _⟩+1 + (Fintype.card ι:ℝ)*(sqrt (2*r)*(Lπ:ℝ)+r*(2*b*opNorm (D*D)*b))* + (Measure.pi (fun _ : MatrixCoordinates ι => gaussianReal 0 1)).real + (truncationGoodSet r R lo hi D C)ᶜ+ + r*(b*((2*Real.exp (π^2/8))*(T:ℝ))+b*opNorm (D*D)*b) + +noncomputable def cutoffErrorTwo (f : 𝓢(ℝ,ℂ)) (r R lo hi : ℝ) + (d c : ι → ℝ) (i : ι) : ℝ := + let b := ComplexMatrix.kBound f R (liftMatrix (diagonal d)) (liftMatrix (diagonal c)) + let p := (Measure.pi (fun _ : MatrixCoordinates ι => gaussianReal 0 1)).real + (truncationGoodSet r R lo hi (diagonal d) (diagonal c))ᶜ + (b+1+|(d i)^2*c i| *b)*p+ + (|(d i)^2| *b)*(Fintype.card ι:ℝ)*sqrt (2*r)*sqrt p + +lemma integrated_diagonal_trace (f : 𝓢(ℝ,ℂ)) {R : ℝ} (hR : 0 ≤ R) + (d c : ι → ℝ) (r : ℝ) : + (∫ g, trace (realTruncatedK f R hR (diagonal d) (diagonal c) (goeMatrix r g)* + (diagonal d*diagonal d)) + ∂(Measure.pi (fun _ : MatrixCoordinates ι => gaussianReal 0 1))) = + ∑ b, (d b)^2*expectedCutoff f R hR (diagonal d) (diagonal c) r b := by + let μ := Measure.pi (fun _ : MatrixCoordinates ι => gaussianReal 0 1) + let K := fun g => realTruncatedK f R hR (diagonal d) (diagonal c) (goeMatrix r g) + let B := ComplexMatrix.kBound f R (liftMatrix (diagonal d)) (liftMatrix (diagonal c)) + have hc : Continuous K := (realTruncatedK_lipschitz f hR _ _ (diagonal_transpose _) (diagonal_transpose _)).continuous.comp + (goeMatrix_pi_lipschitz r).continuous + have hi (b : ι) : Integrable (fun g => K g b b) μ := + Integrable.mono' (integrable_const B) (hc.matrix_elem b b).aestronglyMeasurable + (ae_of_all _ (fun g => by + rw [Real.norm_eq_abs] + exact (matrix_entry_le_opNorm _ b b).trans + (realTruncatedK_opNorm f hR _ _ _ (diagonal_transpose _) (diagonal_transpose _)))) + have he (g : MatrixCoordinates ι → ℝ) : trace (K g*(diagonal d*diagonal d)) = + ∑ b, (d b)^2*K g b b := by + rw [diagonal_mul_diagonal] + simp only [Matrix.trace,Matrix.diag,Matrix.mul_diagonal] + apply Finset.sum_congr rfl + intro b _ + ring + simp_rw [show (fun g => trace (realTruncatedK f R hR (diagonal d) (diagonal c) (goeMatrix r g)* + (diagonal d*diagonal d))) = (fun g => ∑ b, (d b)^2*K g b b) from funext he] + rw [integral_finsetSum _ (fun b _ => (hi b).const_mul _)] + simp only [integral_const_mul,expectedCutoff,K,μ] + +omit [Fintype ι] [DecidableEq ι] in +lemma combine_resolvent_loops {k w r a c t e₁ e₂ : ℝ} + (h₁ : |w-r*t*k| ≤ e₁) (h₂ : |k-(1+a*(w-c*k))| ≤ e₂) : + |k-1-a*(r*t-c)*k| ≤ e₂+|a| *e₁ := by + have he : k-1-a*(r*t-c)*k = (k-(1+a*(w-c*k)))+a*(w-r*t*k) := by ring + rw [he] + exact (abs_add_le _ _).trans (add_le_add h₂ (by rw [abs_mul]; exact mul_le_mul_of_nonneg_left h₁ (abs_nonneg _))) + +theorem actual_cutoff_self_consistency (f : 𝓢(ℝ,ℂ)) {lo hi : ℝ} (hlo : 0 < lo) + (hf : ∀ x ∈ Icc lo hi, f x = (x : ℂ)⁻¹) + {R r : ℝ} (hR : 0 ≤ R) (hr : 0 ≤ r) (d c : ι → ℝ) (i : ι) : + let k := expectedCutoff f R hR (diagonal d) (diagonal c) r + |k i-1-(d i)^2*(r*(∑ b, (d b)^2*k b)-c i)*k i| ≤ + cutoffErrorTwo f r R lo hi d c i+ + |(d i)^2| *cutoffErrorOne f r R lo hi (diagonal d) (diagonal c) := by + intro k + have h₁ := realTruncatedK_first_loop f hlo hf hR hr (diagonal d) (diagonal c) + (diagonal_transpose _) (diagonal_transpose _) i + have h₂ := realTruncatedK_second_loop f hlo hf hR hr d c i + dsimp only at h₁ h₂ + rw [integrated_diagonal_trace f hR d c r] at h₁ + exact combine_resolvent_loops h₁ h₂ + +end SKGap + +namespace SKGap +open Matrix MeasureTheory ProbabilityTheory Real Set +open RealComplex +open scoped BigOperators Matrix.Norms.Frobenius NNReal ENNReal SchwartzMap +variable {ι : Type*} [Fintype ι] [DecidableEq ι] [Nonempty ι] + +lemma cutoffErrorOne_bound (f : 𝓢(ℝ,ℂ)) {j R lo hi A B L p : ℝ} + (D C : Matrix ι ι ℝ) (hj : 0 ≤ j) (hA : 0 ≤ A) (hB : 0 ≤ B) + (hL : 0 ≤ L) (hR : 0 ≤ R) + (hb : ComplexMatrix.kBound f R (liftMatrix D) (liftMatrix C) ≤ B) + (hl : ComplexMatrix.kLip f R (liftMatrix D) (liftMatrix C) ≤ L) + (hd : opNorm (D*D) ≤ A) + (hp : (Measure.pi (fun _ : MatrixCoordinates ι => gaussianReal 0 1)).real + (truncationGoodSet (j/(Fintype.card ι:ℝ)) R lo hi D C)ᶜ ≤ p) : + cutoffErrorOne f (j/(Fintype.card ι:ℝ)) R lo hi D C ≤ + (2*j*L*((Fintype.card ι:ℝ)^2+Fintype.card ι)+2*j*B*A*B)*p+ + (j/(Fintype.card ι:ℝ))*(B*(2*Real.exp (π^2/8))*(A*L*sqrt (2*j)+1)+B*A*B) := by + let n : ℝ := Fintype.card ι + let r := j/n + let b := ComplexMatrix.kBound f R (liftMatrix D) (liftMatrix C) + let ℓ : ℝ := (Real.toNNReal (ComplexMatrix.kLip f R (liftMatrix D) (liftMatrix C)) : ℝ) + have hn : 0 < n := Nat.cast_pos.mpr Fintype.card_pos + have hr : 0 ≤ r := div_nonneg hj hn.le + have hd0 : 0 ≤ opNorm (D*D) := norm_nonneg _ + have hb0 : 0 ≤ b := by + have hh := (ComplexMatrix.g_constants_nonneg f hR 1 1 (liftMatrix D) (liftMatrix D)).1 + dsimp [b,ComplexMatrix.kBound] + exact add_nonneg zero_le_one (mul_nonneg hh (add_nonneg hR (norm_nonneg _))) + have hl0 : 0 ≤ ℓ := NNReal.coe_nonneg _ + have hl' : ℓ ≤ L := by + have hh : Real.toNNReal (ComplexMatrix.kLip f R (liftMatrix D) (liftMatrix C)) ≤ (⟨L,hL⟩ : ℝ≥0) := Real.toNNReal_le_iff_le_coe.mpr hl + exact_mod_cast hh + have hp0 : 0 ≤ p := (measureReal_nonneg).trans hp + have hnr : n*r = j := by dsimp [r]; field_simp + have hs : sqrt n*sqrt (2*r)=sqrt (2*j) := by + rw [← sqrt_mul hn.le] + congr 1 + nlinarith [hnr] + have hT : sqrt n*opNorm (D*D)*ℓ*sqrt (2*r)+1 ≤ A*L*sqrt (2*j)+1 := by + calc + _ = opNorm (D*D)*ℓ*(sqrt n*sqrt (2*r))+1 := by ring + _ ≤ _ := by rw [hs]; gcongr + have hdim : (((Fintype.card (MatrixCoordinates ι) : ℝ≥0) ^ + (1/(2:ℝ≥0∞)).toReal : ℝ≥0) : ℝ) ≤ n^2+n := by + have hh := NNReal.coe_le_coe.mpr (matrixCoordinates_dimension_bound (ι := ι)) + simpa only [NNReal.coe_add,NNReal.coe_pow,NNReal.coe_natCast,n] using hh + have hfirst : n*(sqrt (2*r)*(ℓ*(sqrt (2*r)* + (((Fintype.card (MatrixCoordinates ι) : ℝ≥0) ^ (1/(2:ℝ≥0∞)).toReal : ℝ≥0) : ℝ)))+ + r*(2*b*opNorm (D*D)*b)) ≤ 2*j*L*(n^2+n)+2*j*B*A*B := by + calc + _ ≤ n*(sqrt (2*r)*(L*(sqrt (2*r)*(n^2+n)))+r*(2*B*A*B)) := by gcongr + _ = _ := by + have hh := sq_sqrt (mul_nonneg (by norm_num : (0:ℝ) ≤ 2) hr) + calc + _ = n*(L*(n^2+n)*(sqrt (2*r)^2)+r*(2*B*A*B)) := by ring + _ = 2*(n*r)*L*(n^2+n)+2*(n*r)*B*A*B := by rw [hh]; ring + _ = _ := by rw [hnr] + unfold cutoffErrorOne + dsimp only + simp only [NNReal.coe_mul,NNReal.coe_add,NNReal.coe_one] + change n*(sqrt (2*r)*(ℓ*(sqrt (2*r)*_))+r*(2*b*opNorm (D*D)*b))*_+ + r*(b*((2*Real.exp (π^2/8))*(sqrt n*opNorm (D*D)*ℓ*sqrt (2*r)+1))+b*opNorm (D*D)*b) ≤ _ + apply add_le_add + · exact mul_le_mul hfirst hp measureReal_nonneg (by positivity) + · apply mul_le_mul_of_nonneg_left _ hr + apply add_le_add + · rw [← mul_assoc] + gcongr + · gcongr + +lemma cutoffErrorTwo_bound (f : 𝓢(ℝ,ℂ)) {j R lo hi A B p : ℝ} + (d c : ι → ℝ) (i : ι) (hj : 0 ≤ j) (hA : 0 ≤ A) (hB : 0 ≤ B) (hR : 0 ≤ R) + (hb : ComplexMatrix.kBound f R (liftMatrix (diagonal d)) (liftMatrix (diagonal c)) ≤ B) + (hd : (d i)^2 ≤ A) (hc : |c i| ≤ j*A) + (hp : (Measure.pi (fun _ : MatrixCoordinates ι => gaussianReal 0 1)).real + (truncationGoodSet (j/(Fintype.card ι:ℝ)) R lo hi (diagonal d) (diagonal c))ᶜ ≤ p) : + cutoffErrorTwo f (j/(Fintype.card ι:ℝ)) R lo hi d c i ≤ + (B+1+A*(j*A)*B)*p+A*B*(Fintype.card ι:ℝ)*sqrt (2*j)*sqrt p := by + have hn : (1:ℝ) ≤ Fintype.card ι := by exact_mod_cast Fintype.card_pos (α := ι) + have hr : j/(Fintype.card ι:ℝ) ≤ j := by + exact div_le_self hj hn + have hb0 : 0 ≤ ComplexMatrix.kBound f R (liftMatrix (diagonal d)) (liftMatrix (diagonal c)) := by + have hh := (ComplexMatrix.g_constants_nonneg f hR 1 1 (liftMatrix (diagonal d)) (liftMatrix (diagonal d))).1 + exact add_nonneg zero_le_one (mul_nonneg hh (add_nonneg hR (norm_nonneg _))) + have hdc : |(d i)^2*c i| ≤ A*(j*A) := by + rw [abs_mul,abs_of_nonneg (sq_nonneg _)] + exact mul_le_mul hd hc (abs_nonneg _) hA + have hp0 : 0 ≤ p := measureReal_nonneg.trans hp + unfold cutoffErrorTwo + dsimp only + rw [abs_of_nonneg (sq_nonneg (d i))] + gcongr +end SKGap +end +end +end +end +end +end +end +end +end +end +end +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/FiniteMax.lean b/lean/OAI/Probability/SKGap/Localization/FiniteMax.lean new file mode 100644 index 0000000000000000000000000000000000000000..40c357dc456ffa050873413bd50540b17e9273ce --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/FiniteMax.lean @@ -0,0 +1,385 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.ExpSum + +namespace OAI + +section +noncomputable section +open MeasureTheory ProbabilityTheory InformationTheory Real Set +open scoped NNReal ENNReal +open Filter +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius ENNReal NNReal +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius NNReal +noncomputable section +open MeasureTheory ProbabilityTheory Real Set Filter +open MeasureTheory.Measure +open scoped ENNReal NNReal MeasureTheory Topology +open MeasureTheory +noncomputable section +noncomputable section +open MeasureTheory Set NormedSpace +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius +noncomputable section +open Set Real +open scoped Topology +noncomputable section +open Matrix Set Filter +open scoped Topology Matrix.Norms.Frobenius +noncomputable section +open Matrix NormedSpace ContinuousLinearMap +open scoped Matrix.Norms.Frobenius +noncomputable section +open Matrix +noncomputable section +open MeasureTheory ProbabilityTheory Real Set +open scoped ENNReal NNReal +noncomputable section +open MeasureTheory ProbabilityTheory InformationTheory Real Set +open scoped NNReal ENNReal +namespace SKGap +variable {ι : Type*} [Fintype ι] [Nonempty ι] +variable {ι : Type*} [Fintype ι] [Nonempty ι] +omit [Fintype ι] [Nonempty ι] in +theorem interpolation_increment_identity {n : ℕ} (a b : ι → Fin n → ℝ) (i j : ι) (t : ℝ) + (horth : ∑ k, (a i k - a j k) * (b i k - b j k) = 0) : + (∑ k, (interpolatedCoeffDeriv a b t i k - interpolatedCoeffDeriv a b t j k) * + (interpolatedCoeff a b t i k - interpolatedCoeff a b t j k)) = + sin t * cos t * ((∑ k, (a i k - a j k) ^ 2) - ∑ k, (b i k - b j k) ^ 2) := by + have he (k : Fin n) : + (interpolatedCoeffDeriv a b t i k - interpolatedCoeffDeriv a b t j k) * + (interpolatedCoeff a b t i k - interpolatedCoeff a b t j k) = + sin t * cos t * (a i k - a j k)^2 - sin t * cos t * (b i k - b j k)^2 + + (cos t ^ 2 - sin t ^ 2) * ((a i k - a j k) * (b i k - b j k)) := by + dsimp [interpolatedCoeff, interpolatedCoeffDeriv] + ring + simp_rw [he, Finset.sum_add_distrib, Finset.sum_sub_distrib, ← Finset.mul_sum] + rw [horth] + ring + +theorem interpolation_derivative_nonneg {n : ℕ} {κ : ℝ} (hκ : 0 ≤ κ) + (m : ι → ℝ) (a b : ι → Fin (n + 1) → ℝ) + (horth : ∀ i j, ∑ k, (a i k - a j k) * (b i k - b j k) = 0) + (hinc : ∀ i j, (∑ k, (b i k - b j k)^2) ≤ ∑ k, (a i k - a j k)^2) + {t : ℝ} (ht : t ∈ Icc 0 (π / 2)) : + 0 ≤ ∫ z, interpolationDerivative κ m a b t z ∂standardGaussianProduct (n + 1) := by + have hs : 0 ≤ sin t := sin_nonneg_of_nonneg_of_le_pi ht.1 (by linarith [pi_pos, ht.2]) + have hc : 0 ≤ cos t := cos_nonneg_of_mem_Icc ⟨by linarith [pi_pos, ht.1], ht.2⟩ + rw [show (fun z => interpolationDerivative κ m a b t z) = + (fun z => ∑ i, softWeight κ (affineProcess m (interpolatedCoeff a b t) z) i * + ∑ k, interpolatedCoeffDeriv a b t i k * z k) from rfl, + gaussian_linear_weight_IBP] + apply mul_nonneg (div_nonneg hκ (by norm_num)) + apply integral_nonneg + intro z + apply Finset.sum_nonneg + intro i _ + apply Finset.sum_nonneg + intro j _ + apply mul_nonneg (mul_nonneg (softWeight_pos _ _ _).le (softWeight_pos _ _ _).le) + rw [interpolation_increment_identity a b i j t (horth i j)] + exact mul_nonneg (mul_nonneg hs hc) (sub_nonneg.mpr (hinc i j)) + +theorem gaussian_smoothMax_comparison {n : ℕ} {κ : ℝ} (hκ : 0 < κ) + (m : ι → ℝ) (a b : ι → Fin (n + 1) → ℝ) + (horth : ∀ i j, ∑ k, (a i k - a j k) * (b i k - b j k) = 0) + (hinc : ∀ i j, (∑ k, (b i k - b j k)^2) ≤ ∑ k, (a i k - a j k)^2) : + (∫ z, smoothMax κ (affineProcess m b z) ∂standardGaussianProduct (n + 1)) ≤ + ∫ z, smoothMax κ (affineProcess m a z) ∂standardGaussianProduct (n + 1) := by + let f := fun t => ∫ z, smoothMax κ (affineProcess m (interpolatedCoeff a b t) z) + ∂standardGaussianProduct (n + 1) + have hmono : MonotoneOn f (Icc 0 (π / 2)) := by + apply monotoneOn_of_hasDerivWithinAt_nonneg (convex_Icc _ _) + (continuous_iff_continuousAt.mpr (fun t => (interpolation_hasDerivAt hκ m a b t).continuousAt)).continuousOn + (fun t _ => (interpolation_hasDerivAt hκ m a b t).hasDerivWithinAt) + intro t ht + exact interpolation_derivative_nonneg hκ.le m a b horth hinc (interior_subset ht) + have hle := hmono (show (0:ℝ) ∈ Icc 0 (π/2) from ⟨le_refl _, by positivity⟩) + (show π/2 ∈ Icc (0:ℝ) (π/2) from ⟨by positivity, le_refl _⟩) (by positivity) + have h0 : interpolatedCoeff a b 0 = b := by + funext i k + simp [interpolatedCoeff] + have h1 : interpolatedCoeff a b (π/2) = a := by + funext i k + simp [interpolatedCoeff] + simpa only [f, h0, h1] using hle + +def finiteMax (x : ι → ℝ) : ℝ := Finset.univ.sup' Finset.univ_nonempty x + +theorem le_finiteMax (x : ι → ℝ) (i : ι) : x i ≤ finiteMax x := + Finset.le_sup' x (Finset.mem_univ i) + +theorem finiteMax_le {x : ι → ℝ} {b : ℝ} (hb : ∀ i, x i ≤ b) : finiteMax x ≤ b := + Finset.sup'_le _ _ (fun i _ => hb i) + +theorem continuous_finiteMax : Continuous (finiteMax : (ι → ℝ) → ℝ) := + Continuous.finset_sup'_apply Finset.univ_nonempty (fun i _ => continuous_apply i) + +theorem finiteMax_norm_le (x : ι → ℝ) : ‖finiteMax x‖ ≤ ∑ i, |x i| := by + obtain ⟨i, _, hi⟩ := Finset.exists_mem_eq_sup' Finset.univ_nonempty x + change ‖Finset.univ.sup' Finset.univ_nonempty x‖ ≤ _ + rw [hi, Real.norm_eq_abs] + exact Finset.single_le_sum (fun j _ => abs_nonneg (x j)) (Finset.mem_univ i) + +omit [Fintype ι] [Nonempty ι] in +theorem integrable_affineProcess {n : ℕ} (m : ι → ℝ) (a : ι → Fin n → ℝ) (i : ι) : + Integrable (fun z => affineProcess m a z i) (standardGaussianProduct n) := by + apply (integrable_const _).add + exact integrable_finsetSum _ (fun k _ => (integrable_eval (i := k) IsGaussian.integrable_id).const_mul _) + +theorem integrable_finiteMax_affine {n : ℕ} (m : ι → ℝ) (a : ι → Fin n → ℝ) : + Integrable (fun z => finiteMax (affineProcess m a z)) (standardGaussianProduct n) := by + apply (integrable_finsetSum _ (fun i _ => (integrable_affineProcess m a i).norm)).mono' + (continuous_finiteMax.comp (continuous_affineProcess m a)).aestronglyMeasurable + exact ae_of_all _ (fun z => finiteMax_norm_le _) + +theorem integrable_smoothMax_affine {n : ℕ} {κ : ℝ} (hκ : 0 < κ) (m : ι → ℝ) (a : ι → Fin n → ℝ) : + Integrable (fun z => smoothMax κ (affineProcess m a z)) (standardGaussianProduct n) := by + apply ((integrable_finsetSum _ (fun i _ => (integrable_affineProcess m a i).norm)).add + (integrable_const (log (Fintype.card ι) / κ))).mono' + ((continuous_smoothMax κ).comp (continuous_affineProcess m a)).aestronglyMeasurable + exact ae_of_all _ (fun z => smoothMax_norm_le hκ _) + +theorem gaussian_finiteMax_comparison {n : ℕ} + (m : ι → ℝ) (a b : ι → Fin (n + 1) → ℝ) + (horth : ∀ i j, ∑ k, (a i k - a j k) * (b i k - b j k) = 0) + (hinc : ∀ i j, (∑ k, (b i k - b j k)^2) ≤ ∑ k, (a i k - a j k)^2) : + (∫ z, finiteMax (affineProcess m b z) ∂standardGaussianProduct (n + 1)) ≤ + ∫ z, finiteMax (affineProcess m a z) ∂standardGaussianProduct (n + 1) := by + apply le_of_forall_pos_le_add + intro ε hε + have hlog : 0 ≤ log (Fintype.card ι) := log_nonneg (by exact_mod_cast Fintype.card_pos) + let κ := (log (Fintype.card ι) + 1) / ε + have hκ : 0 < κ := div_pos (by linarith) hε + have herr : log (Fintype.card ι) / κ ≤ ε := by + apply (div_le_iff₀ hκ).mpr + dsimp [κ] + rw [mul_div_cancel₀ _ hε.ne'] + linarith + calc + _ ≤ ∫ z, smoothMax κ (affineProcess m b z) ∂standardGaussianProduct (n + 1) := by + apply integral_mono (integrable_finiteMax_affine m b) (integrable_smoothMax_affine hκ m b) + intro z + exact finiteMax_le (fun i => smoothMax_ge hκ _ i) + _ ≤ ∫ z, smoothMax κ (affineProcess m a z) ∂standardGaussianProduct (n + 1) := + gaussian_smoothMax_comparison hκ m a b horth hinc + _ ≤ (∫ z, finiteMax (affineProcess m a z) ∂standardGaussianProduct (n + 1)) + ε := by + calc + _ ≤ ∫ z, finiteMax (affineProcess m a z) + log (Fintype.card ι) / κ + ∂standardGaussianProduct (n + 1) := by + apply integral_mono (integrable_smoothMax_affine hκ m a) + ((integrable_finiteMax_affine m a).add (integrable_const _)) + intro z + exact smoothMax_le hκ _ (fun i => le_finiteMax _ i) + _ = (∫ z, finiteMax (affineProcess m a z) ∂standardGaussianProduct (n + 1)) + + log (Fintype.card ι) / κ := by + rw [integral_add (integrable_finiteMax_affine m a) (integrable_const _)] + simp + _ ≤ _ := add_le_add (le_refl _) herr + +section CompactIndex +variable {I : Type*} [TopologicalSpace I] [CompactSpace I] [Nonempty I] + +def supProcess {n : ℕ} (m : I → ℝ) (a : I → Fin n → ℝ) (z : Fin n → ℝ) : ℝ := + sSup (Set.range (affineProcess m a z)) + +omit [CompactSpace I] [Nonempty I] in +theorem continuous_affine_index {n : ℕ} {m : I → ℝ} {a : I → Fin n → ℝ} + (hm : Continuous m) (ha : Continuous a) (z : Fin n → ℝ) : + Continuous (affineProcess m a z) := by + exact hm.add (continuous_finsetSum _ (fun k _ => ((continuous_apply k).comp ha).mul continuous_const)) + +theorem supProcess_attained {n : ℕ} {m : I → ℝ} {a : I → Fin n → ℝ} + (hm : Continuous m) (ha : Continuous a) (z : Fin n → ℝ) : + ∃ i, supProcess m a z = affineProcess m a z i ∧ + ∀ j, affineProcess m a z j ≤ affineProcess m a z i := by + obtain ⟨i, _, he, hi⟩ := isCompact_univ.exists_sSup_image_eq_and_ge + Set.univ_nonempty (continuous_affine_index hm ha z).continuousOn + exact ⟨i, by simpa [supProcess] using he, fun j => hi j (Set.mem_univ _)⟩ + +theorem affine_le_supProcess {n : ℕ} {m : I → ℝ} {a : I → Fin n → ℝ} + (hm : Continuous m) (ha : Continuous a) (z : Fin n → ℝ) (i : I) : + affineProcess m a z i ≤ supProcess m a z := by + obtain ⟨j, he, hj⟩ := supProcess_attained hm ha z + rw [he] + exact hj i + +theorem supProcess_le {n : ℕ} {m : I → ℝ} {a : I → Fin n → ℝ} + (hm : Continuous m) (ha : Continuous a) (z : Fin n → ℝ) {c : ℝ} + (hc : ∀ i, affineProcess m a z i ≤ c) : supProcess m a z ≤ c := by + obtain ⟨i, he, _⟩ := supProcess_attained hm ha z + rw [he] + exact hc i + +omit [Nonempty I] in +theorem continuous_supProcess {n : ℕ} {m : I → ℝ} {a : I → Fin n → ℝ} + (hm : Continuous m) (ha : Continuous a) : Continuous (supProcess m a) := by + have hc : Continuous (fun p : (Fin n → ℝ) × I => affineProcess m a p.1 p.2) := by + exact (hm.comp continuous_snd).add (continuous_finsetSum _ (fun k _ => + (((continuous_apply k).comp ha).comp continuous_snd).mul + ((continuous_apply k).comp continuous_fst))) + change Continuous (fun z => sSup (Set.range (affineProcess m a z))) + simpa only [Set.image_univ] using isCompact_univ.continuous_sSup hc + +omit [TopologicalSpace I] [CompactSpace I] [Nonempty I] in + theorem affineProcess_abs_le {n : ℕ} {m : I → ℝ} {a : I → Fin n → ℝ} + {M A : ℝ} (hm : ∀ i, |m i| ≤ M) (ha : ∀ i k, |a i k| ≤ A) + (z : Fin n → ℝ) (i : I) : + |affineProcess m a z i| ≤ M + A * ∑ k, |z k| := by + calc + _ ≤ |m i| + |∑ k, a i k * z k| := abs_add_le _ _ + _ ≤ M + ∑ k, |a i k * z k| := add_le_add (hm i) (Finset.abs_sum_le_sum_abs _ _) + _ ≤ M + ∑ k, A * |z k| := by + gcongr with k + rw [abs_mul] + exact mul_le_mul_of_nonneg_right (ha i k) (abs_nonneg _) + _ = _ := by rw [Finset.mul_sum] + +theorem integrable_supProcess {n : ℕ} {m : I → ℝ} {a : I → Fin n → ℝ} + (hm : Continuous m) (ha : Continuous a) : + Integrable (supProcess m a) (standardGaussianProduct n) := by + obtain ⟨M, hM⟩ := isCompact_univ.exists_bound_of_continuousOn hm.continuousOn + obtain ⟨A, hA⟩ := isCompact_univ.exists_bound_of_continuousOn ha.continuousOn + have hMb : ∀ i, |m i| ≤ M := fun i => by simpa only [Real.norm_eq_abs] using hM i (Set.mem_univ _) + have hAb : ∀ i k, |a i k| ≤ A := by + intro i k + have hk : |a i k| ≤ ‖a i‖ := by simpa only [Real.norm_eq_abs] using norm_le_pi_norm (a i) k + exact hk.trans (hA i (Set.mem_univ _)) + apply ((integrable_const M).add ((integrable_finsetSum _ (fun k _ => + ((integrable_eval (i := k) IsGaussian.integrable_id).norm))).const_mul A)).mono' + (continuous_supProcess hm ha).aestronglyMeasurable + apply Filter.Eventually.of_forall + intro z + obtain ⟨i, he, _⟩ := supProcess_attained hm ha z + rw [he, Real.norm_eq_abs] + exact affineProcess_abs_le hMb hAb z i + +theorem exists_finite_affine_net {n : ℕ} {m : I → ℝ} {a : I → Fin n → ℝ} + (hm : Continuous m) (ha : Continuous a) {ε : ℝ} (hε : 0 < ε) : + ∃ t : Finset I, t.Nonempty ∧ ∀ j, ∃ i ∈ t, + |m j - m i| ≤ ε ∧ ∀ k, |a j k - a i k| ≤ ε := by + let U : I → Set I := fun i => m ⁻¹' Metric.ball (m i) ε ∩ a ⁻¹' Metric.ball (a i) ε + have ho (i : I) : IsOpen (U i) := + (Metric.isOpen_ball.preimage hm).inter (Metric.isOpen_ball.preimage ha) + have hu : Set.univ ⊆ ⋃ i, U i := by + intro j _ + apply Set.mem_iUnion.mpr + exact ⟨j, by simp [U, hε]⟩ + obtain ⟨t, ht⟩ := isCompact_univ.elim_finite_subcover U ho hu + have hcover (j : I) : ∃ i ∈ t, j ∈ U i := by + obtain ⟨i, hi⟩ := Set.mem_iUnion.mp (ht (Set.mem_univ j)) + obtain ⟨hit, hji⟩ := Set.mem_iUnion.mp hi + exact ⟨i, hit, hji⟩ + have hne : t.Nonempty := by + obtain ⟨i, hi, _⟩ := hcover (Classical.choice inferInstance) + exact ⟨i, hi⟩ + refine ⟨t, hne, fun j => ?_⟩ + obtain ⟨i, hi, hj⟩ := hcover j + refine ⟨i, hi, ?_, fun k => ?_⟩ + · have hd : dist (m j) (m i) < ε := hj.1 + simpa only [Real.dist_eq] using hd.le + · have hb : dist (a j) (a i) < ε := hj.2 + have hk := (dist_le_pi_dist (a j) (a i) k).trans_lt hb + simpa only [Real.dist_eq] using hk.le + +omit [TopologicalSpace I] [CompactSpace I] [Nonempty I] in + theorem affineProcess_difference_abs_le {n : ℕ} (m : I → ℝ) (a : I → Fin n → ℝ) + {ε : ℝ} {i j : I} (hm : |m i - m j| ≤ ε) + (ha : ∀ k, |a i k - a j k| ≤ ε) (z : Fin n → ℝ) : + |affineProcess m a z i - affineProcess m a z j| ≤ ε * (1 + ∑ k, |z k|) := by + have he : affineProcess m a z i - affineProcess m a z j = + (m i - m j) + ∑ k, (a i k - a j k) * z k := by + simp only [affineProcess, sub_mul, Finset.sum_sub_distrib] + ring + rw [he] + calc + _ ≤ |m i - m j| + |∑ k, (a i k - a j k) * z k| := abs_add_le _ _ + _ ≤ ε + ∑ k, |(a i k - a j k) * z k| := + add_le_add hm (Finset.abs_sum_le_sum_abs _ _) + _ ≤ ε + ∑ k, ε * |z k| := by + gcongr with k + rw [abs_mul] + exact mul_le_mul_of_nonneg_right (ha k) (abs_nonneg _) + _ = _ := by rw [← Finset.mul_sum]; ring + +theorem gaussian_supProcess_comparison {n : ℕ} + {m : I → ℝ} {a b : I → Fin (n + 1) → ℝ} + (hm : Continuous m) (ha : Continuous a) (hb : Continuous b) + (horth : ∀ i j, ∑ k, (a i k - a j k) * (b i k - b j k) = 0) + (hinc : ∀ i j, (∑ k, (b i k - b j k)^2) ≤ ∑ k, (a i k - a j k)^2) : + (∫ z, supProcess m b z ∂standardGaussianProduct (n + 1)) ≤ + ∫ z, supProcess m a z ∂standardGaussianProduct (n + 1) := by + let μ := standardGaussianProduct (n + 1) + let Z : (Fin (n + 1) → ℝ) → ℝ := fun z => 1 + ∑ k, |z k| + have hZI : Integrable Z μ := (integrable_const 1).add + (integrable_finsetSum _ (fun k _ => by + have hi : Integrable (fun z : Fin (n + 1) → ℝ => z k) μ := + integrable_eval (i := k) IsGaussian.integrable_id + simpa only [Real.norm_eq_abs] using hi.norm)) + have hZ : 0 ≤ ∫ z, Z z ∂μ := integral_nonneg (fun z => by dsimp [Z]; positivity) + apply le_of_forall_pos_le_add + intro ε hε + let δ : ℝ := ε / ((∫ z, Z z ∂μ) + 1) + have hδ : 0 < δ := div_pos hε (by linarith) + have hδε : δ * (∫ z, Z z ∂μ) ≤ ε := by + dsimp [δ] + rw [div_mul_eq_mul_div] + apply (div_le_iff₀ (by linarith : 0 < (∫ z, Z z ∂μ) + 1)).mpr + nlinarith + obtain ⟨t, ht, hnet⟩ := exists_finite_affine_net hm hb hδ + have : Nonempty t := ht.to_subtype + let mf : t → ℝ := fun i => m i + let af : t → Fin (n + 1) → ℝ := fun i => a i + let bf : t → Fin (n + 1) → ℝ := fun i => b i + have hfinite := gaussian_finiteMax_comparison mf af bf + (fun i j => horth i j) (fun i j => hinc i j) + calc + _ ≤ ∫ z, finiteMax (affineProcess mf bf z) + δ * Z z ∂μ := by + apply integral_mono (integrable_supProcess hm hb) + ((integrable_finiteMax_affine mf bf).add (hZI.const_mul δ)) + intro z + apply supProcess_le hm hb + intro j + obtain ⟨i, hi, hmj, hbj⟩ := hnet j + have hd := (le_abs_self _).trans (affineProcess_difference_abs_le m b hmj hbj z) + have hmax := le_finiteMax (affineProcess mf bf z) (⟨i, hi⟩ : t) + change affineProcess m b z i ≤ _ at hmax + change affineProcess m b z j ≤ finiteMax (affineProcess mf bf z) + δ * (1 + ∑ k, |z k|) + linarith + _ = (∫ z, finiteMax (affineProcess mf bf z) ∂μ) + δ * ∫ z, Z z ∂μ := by + rw [integral_add (integrable_finiteMax_affine mf bf) (hZI.const_mul δ), integral_const_mul] + _ ≤ (∫ z, finiteMax (affineProcess mf af z) ∂μ) + ε := add_le_add hfinite hδε + _ ≤ (∫ z, supProcess m a z ∂μ) + ε := by + refine add_le_add ?_ le_rfl + apply integral_mono (integrable_finiteMax_affine mf af) (integrable_supProcess hm ha) + intro z + apply finiteMax_le + intro i + exact affine_le_supProcess hm ha z i + +end CompactIndex +end SKGap + +end +end +end +end +end +end +end +end +end +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/FiniteRankPositive.lean b/lean/OAI/Probability/SKGap/Localization/FiniteRankPositive.lean new file mode 100644 index 0000000000000000000000000000000000000000..f993418456e35f84a887865a2debeaa3277bf194 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/FiniteRankPositive.lean @@ -0,0 +1,216 @@ +import Mathlib +import OAI.Probability.SKGap.Model + +namespace OAI + +section + +noncomputable section +open Real Matrix Set +open scoped BigOperators +namespace SKGap +variable {ι : Type*} [Fintype ι] + +def rayleigh (M : Matrix ι ι ℝ) (v : EuclideanSpace ℝ ι) : ℝ := + (WithLp.ofLp v) ⬝ᵥ (M *ᵥ WithLp.ofLp v) + +lemma continuous_rayleigh : Continuous (fun p : Matrix ι ι ℝ × EuclideanSpace ℝ ι => rayleigh p.1 p.2) := by + unfold rayleigh dotProduct mulVec + fun_prop + +lemma rayleigh_smul (M : Matrix ι ι ℝ) (v : EuclideanSpace ℝ ι) (c : ℝ) : + rayleigh M (c • v) = c^2*rayleigh M v := by + simp only [rayleigh, WithLp.ofLp_smul, mulVec_smul, dotProduct_smul, smul_dotProduct, + smul_eq_mul] + ring + +lemma rayleigh_zero (M : Matrix ι ι ℝ) : rayleigh M 0 = 0 := by + simp [rayleigh] + +def unitEuclidean (ι : Type*) [Fintype ι] := {v : EuclideanSpace ℝ ι | ‖v‖ = 1} + +lemma isCompact_unitEuclidean : IsCompact (unitEuclidean ι) := by + simpa only [unitEuclidean, Metric.sphere, dist_zero_right] using + (isCompact_sphere (0 : EuclideanSpace ℝ ι) 1) + +lemma unitEuclidean_nonempty [Nonempty ι] : (unitEuclidean ι).Nonempty := by + classical + obtain ⟨i⟩ := ‹Nonempty ι› + refine ⟨EuclideanSpace.single i (1:ℝ),?_⟩ + simp [unitEuclidean] + +def lowerRayleigh (M : Matrix ι ι ℝ) : ℝ := sInf (rayleigh M '' unitEuclidean ι) + +lemma continuous_lowerRayleigh : Continuous (lowerRayleigh (ι := ι)) := by + exact isCompact_unitEuclidean.continuous_sInf continuous_rayleigh + +lemma lowerRayleigh_attained [Nonempty ι] (M : Matrix ι ι ℝ) : + ∃ v ∈ unitEuclidean ι, lowerRayleigh M = rayleigh M v ∧ + ∀ w ∈ unitEuclidean ι, rayleigh M v ≤ rayleigh M w := by + exact isCompact_unitEuclidean.exists_sInf_image_eq_and_le unitEuclidean_nonempty + (continuous_rayleigh.comp (continuous_const.prodMk continuous_id)).continuousOn + +lemma lowerRayleigh_le [Nonempty ι] (M : Matrix ι ι ℝ) {v : EuclideanSpace ℝ ι} + (hv : v ∈ unitEuclidean ι) : lowerRayleigh M ≤ rayleigh M v := by + obtain ⟨w,_,he,hw⟩ := lowerRayleigh_attained M + rw [he] + exact hw v hv + +lemma unitEuclidean_normalize {v : EuclideanSpace ℝ ι} (hv : v ≠ 0) : + ‖v‖⁻¹ • v ∈ unitEuclidean ι := by + change ‖‖v‖⁻¹ • v‖ = 1 + rw [norm_smul, Real.norm_eq_abs, abs_of_nonneg (inv_nonneg.mpr (norm_nonneg _)), + inv_mul_cancel₀ (norm_ne_zero_iff.mpr hv)] + +lemma nonneg_rayleigh_of_unit {M : Matrix ι ι ℝ} + (h : ∀ v ∈ unitEuclidean ι, 0 ≤ rayleigh M v) (v : EuclideanSpace ℝ ι) : + 0 ≤ rayleigh M v := by + by_cases hv : v = 0 + · simp [hv,rayleigh_zero] + have hh := h _ (unitEuclidean_normalize hv) + rw [rayleigh_smul] at hh + exact nonneg_of_mul_nonneg_right hh (sq_pos_of_pos (inv_pos.mpr (norm_pos_iff.mpr hv))) + +lemma rayleigh_pos_of_unit {M : Matrix ι ι ℝ} + (h : ∀ v ∈ unitEuclidean ι, 0 < rayleigh M v) {v : EuclideanSpace ℝ ι} (hv : v ≠ 0) : + 0 < rayleigh M v := by + have hh := h _ (unitEuclidean_normalize hv) + rw [rayleigh_smul] at hh + exact pos_of_mul_pos_right hh (sq_nonneg _) + +lemma lowerRayleigh_nonneg_iff [Nonempty ι] {M : Matrix ι ι ℝ} (hM : M.IsHermitian) : + 0 ≤ lowerRayleigh M ↔ M.PosSemidef := by + constructor + · intro h + apply Matrix.PosSemidef.of_dotProduct_mulVec_nonneg hM + intro x + exact nonneg_rayleigh_of_unit (fun v hv => h.trans (lowerRayleigh_le M hv)) (WithLp.toLp 2 x) + · intro h + obtain ⟨v,_,he,_⟩ := lowerRayleigh_attained M + rw [he] + exact h.dotProduct_mulVec_nonneg _ + +lemma lowerRayleigh_pos_iff [Nonempty ι] {M : Matrix ι ι ℝ} (hM : M.IsHermitian) : + 0 < lowerRayleigh M ↔ M.PosDef := by + constructor + · intro h + apply Matrix.PosDef.of_dotProduct_mulVec_pos hM + intro x hx + apply rayleigh_pos_of_unit (fun v hv => h.trans_le (lowerRayleigh_le M hv)) + (v := WithLp.toLp 2 x) + exact fun hz => hx (congrArg WithLp.ofLp hz) + · intro h + obtain ⟨v,hv,he,_⟩ := lowerRayleigh_attained M + rw [he] + exact h.dotProduct_mulVec_pos (fun hz => by + have hz' : v = 0 := WithLp.ofLp_injective 2 hz + have hv' : ‖v‖ = 1 := hv + simp [hz'] at hv') + +theorem matrix_path_posDef [DecidableEq ι] {a : ℝ} (ha : 0 ≤ a) (M : ℝ → Matrix ι ι ℝ) + (hcont : Continuous M) (hherm : ∀ t ∈ Icc 0 a, (M t).IsHermitian) + (hdet : ∀ t ∈ Icc 0 a, (M t).det ≠ 0) (hzero : (M 0).PosDef) : (M a).PosDef := by + cases isEmpty_or_nonempty ι with + | inl h => + let := h + apply Matrix.PosDef.of_dotProduct_mulVec_pos (hherm a ⟨ha,le_rfl⟩) + intro x hx + exact (hx (Subsingleton.elim _ _)).elim + | inr h => + let := h + let f := fun t => lowerRayleigh (M t) + have hf : Continuous f := continuous_lowerRayleigh.comp hcont + have hnz : ∀ t ∈ Icc 0 a, f t ≠ 0 := by + intro t ht hz + have hpsd := (lowerRayleigh_nonneg_iff (hherm t ht)).mp (le_of_eq hz.symm) + have hpd := hpsd.posDef_iff_det_ne_zero.mpr (hdet t ht) + have hh := (lowerRayleigh_pos_iff (hherm t ht)).mpr hpd + exact (ne_of_gt hh) hz + have h0 : 0 < f 0 := (lowerRayleigh_pos_iff hzero.1).mpr hzero + apply (lowerRayleigh_pos_iff (hherm a ⟨ha,le_rfl⟩)).mp + by_contra hh + have han : f a < 0 := lt_of_le_of_ne (not_lt.mp hh) (hnz a ⟨ha,le_rfl⟩) + obtain ⟨t,ht,he⟩ := intermediate_value_Icc' ha hf.continuousOn ⟨han.le,h0.le⟩ + exact hnz t ht he + +end SKGap + +noncomputable section +open Real Matrix Set +open scoped BigOperators +namespace SKGap + +def limitingGram (b e s : ℝ) : Matrix (Fin 3) (Fin 3) ℝ := + !![b,e,-2*e; e,e,b-3*e; -2*e,b-3*e,b/s-2*b+6*e] + +def rankCoefficient (j b s : ℝ) : Matrix (Fin 3) (Fin 3) ℝ := + j • !![1,0,0; 0,2-j*b/s,1; 0,1,0] + +lemma limiting_rank_determinant (j b e s : ℝ) : + (1-limitingGram b e s * rankCoefficient j b s).det = + (1-j*b+2*j*e)*(1-j*b+j*e)^2 := by + simp [Matrix.det_fin_three, limitingGram, rankCoefficient, + Matrix.sub_apply, cons_val_two, vecHead, vecTail] + ring + +lemma rankCoefficient_hermitian (j b s : ℝ) : (rankCoefficient j b s).IsHermitian := by + ext i k + fin_cases i <;> fin_cases k <;> simp [rankCoefficient, Matrix.conjTranspose_apply] + +variable {ι : Type*} [Fintype ι] [DecidableEq ι] + +def limitingPositiveMatrix (Q : Matrix ι (Fin 3) ℝ) (j b s : ℝ) : Matrix ι ι ℝ := + 1-Q*rankCoefficient j b s*Qᵀ + +lemma limitingPositiveMatrix_det (Q : Matrix ι (Fin 3) ℝ) {b e s : ℝ} + (hQ : Qᵀ*Q = limitingGram b e s) (j : ℝ) : + (limitingPositiveMatrix Q j b s).det = (1-j*b+2*j*e)*(1-j*b+j*e)^2 := by + unfold limitingPositiveMatrix + calc + _ = (1-(rankCoefficient j b s*Qᵀ)*Q).det := by + rw [Matrix.mul_assoc, Matrix.det_one_sub_mul_comm] + _ = (1-rankCoefficient j b s*limitingGram b e s).det := by rw [Matrix.mul_assoc,hQ] + _ = (1-limitingGram b e s*rankCoefficient j b s).det := Matrix.det_one_sub_mul_comm _ _ + _ = _ := limiting_rank_determinant _ _ _ _ + +end SKGap + +namespace SKGap +variable {ι : Type*} [Fintype ι] [DecidableEq ι] + +omit [Fintype ι] in +lemma limitingPositiveMatrix_hermitian (Q : Matrix ι (Fin 3) ℝ) (j b s : ℝ) : + (limitingPositiveMatrix Q j b s).IsHermitian := by + unfold limitingPositiveMatrix + apply Matrix.isHermitian_one.sub + simpa only [Matrix.conjTranspose_eq_transpose_of_trivial] using + Matrix.isHermitian_mul_mul_conjTranspose Q (rankCoefficient_hermitian j b s) + +omit [Fintype ι] in +lemma continuous_limitingPositiveMatrix (Q : Matrix ι (Fin 3) ℝ) (b s : ℝ) : + Continuous (fun j => limitingPositiveMatrix Q j b s) := by + unfold limitingPositiveMatrix rankCoefficient + apply continuous_const.sub + apply Continuous.matrix_mul ?_ continuous_const + apply continuous_const.matrix_mul + fun_prop + +theorem limitingPositiveMatrix_posDef (Q : Matrix ι (Fin 3) ℝ) {j b e s : ℝ} + (hj : 0 ≤ j) (hj1 : j < 1) (hb1 : b ≤ 1) (he : 0 ≤ e) + (hQ : Qᵀ*Q = limitingGram b e s) : (limitingPositiveMatrix Q j b s).PosDef := by + apply matrix_path_posDef hj _ (continuous_limitingPositiveMatrix Q b s) + (fun r _ => limitingPositiveMatrix_hermitian Q r b s) + · intro r hr + rw [limitingPositiveMatrix_det Q hQ] + have hrb : r*b < 1 := lt_of_le_of_lt (mul_le_of_le_one_right hr.1 hb1) (hr.2.trans_lt hj1) + have hre : 0 ≤ r*e := mul_nonneg hr.1 he + exact ne_of_gt (mul_pos (by nlinarith) (sq_pos_of_pos (by linarith))) + · simpa [limitingPositiveMatrix,rankCoefficient] using + (Matrix.PosDef.one : (1 : Matrix ι ι ℝ).PosDef) + +end SKGap +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/FiniteRecipeControl.lean b/lean/OAI/Probability/SKGap/Localization/FiniteRecipeControl.lean new file mode 100644 index 0000000000000000000000000000000000000000..1100806265a3cef2a9b0e483de94147ec7979f9b --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/FiniteRecipeControl.lean @@ -0,0 +1,199 @@ +import Mathlib +import OAI.Probability.SKGap.Matrix.WordDiag +import OAI.Probability.SKGap.Stability.UniformOrdinary +import OAI.Probability.SKGap.Localization.UniformRecipeClass +import OAI.Probability.SKGap.Localization.CoefficientInputBridge + +namespace OAI + +section + +noncomputable section +open scoped BigOperators Matrix.Norms.Frobenius +namespace SKGapCutoff.Recipe +open Primary Static SKGap.Noncrossing.Primary SKGap.Noncrossing.Primary.MarkedPolynomial +universe u +variable {Ω : Type u} {n : Ω→ℕ} + +structure FiniteRecipeControl (j : ℝ) (J : ∀a,Interaction (n a)) (h : ∀a,Fin (n a)→ℝ) + (M Nmax : ℕ) (A : ℝ) : Prop where + small : ∀ {σ : Type} [Fintype σ] (D : ∀a,OrdinaryData (n a) (Fin M) (Fin M) σ) + (N p : ℕ) (K : ℝ), FamilyRecipe j J h D N p K → N≤Nmax → K≤A → + ∃C : ℝ,0≤C ∧ ∀a x,SmallBound ((D a).source N) x C ∧ + (∀q,SmallBound ((D a).sourcePartial N q) x C) ∧ + (∑i,|derivativeMatrix ((D a).source N) x i i|)≤C + means : ∀ {σ : Type} [Fintype σ] (D : ∀a,OrdinaryData (n a) (Fin M) (Fin M) σ) + (N p : ℕ) (K : ℝ), FamilyRecipe j J h D N p K → N≤Nmax → K≤A → + ∀b:Fin N,UniformMultiplier (fun a=>siteMean ((D a).auxCoefficient N b)) + parameter : ∀q:Fin M,UniformMultiplier + (fun a x=>j*(onsager j (J a) (h a) (q.val+1) x-onsager j (J a) (h a) q.val x)) + +variable {M : ℕ} {j : ℝ} {J : ∀a,Interaction (n a)} {h : ∀a,Fin (n a)→ℝ} + +theorem finite_recipe_control (D₀ : ∀a,OrdinaryData (n a) (Fin M) (Fin M) Unit) + (H₀ : FamilyRecipe j J h D₀ 0 0 1) + (T : ∀a,Spin (n a)→Fin M→SourceTree (Fin (n a)→ℝ)) (c : LocalConstants) + (hc : ∀a x,LocalOrdinaryInput (D₀ a) (T a x) x 0 c) + (Nmax L : ℕ) (A W B Q : ℝ) (hA : 1≤A) (hW : 0≤W) (hB : 0≤B) (hQ : 0≤Q) + (hm : ∀a x q,mass ((T a x q).words j).1≤Q ∧ mass ((T a x q).words j).2≤Q) + (hT : ∀a x q,PolynomialControl A L ((T a x q).words j).1 ∧ + PolynomialControl A L ((T a x q).words j).2) + (hw : ∀a,WordTestBound (J a) A W (2*Nmax+3)) + (hd : ∀a,WordDiagramBound (J a) j A B (L+2*Nmax+2)) : + FiniteRecipeControl j J h M Nmax A := by + have transfer {σ : Type} [Fintype σ] (D : ∀a,OrdinaryData (n a) (Fin M) (Fin M) σ) + (N p : ℕ) (K : ℝ) (H : FamilyRecipe j J h D N p K) (hKA : K≤A) : + ∃c' : LocalConstants,c'.A=A ∧ ∀a x,LocalOrdinaryInput (D a) (T a x) x N c' := by + obtain ⟨S,hS,hs⟩:=H.seed + refine ⟨c.withCoefficient A S hA hS,rfl,fun a x=>?_⟩ + obtain ⟨hJ,hj,hH,hp,hθ⟩:=H.sameEnvironment H₀ a + exact (hc a x).with_coefficients (D a) hJ hj hH hp hθ N A S hA hS (hs a) + ((H.coefficients a x).mono hKA) + constructor + · intro σ inst D N p K H hN hKA + obtain ⟨c',hAc,hi⟩:=transfer D N p K H hKA + apply uniform_ordinary_control D T N L c' j H.coupling hi hW hB hQ hm + · simpa only [hAc] using hT + · intro a w hlen hb + rw [H.interaction a,hAc] at * + exact hw a w (hlen.trans (by omega)) hb + · intro a w hlen hb + rw [H.interaction a,hAc] at * + exact hd a w (hlen.trans (by omega)) hb + · intro σ inst D N p K H hN hKA b + obtain ⟨c',hAc,hi⟩:=transfer D N p K H hKA + exact uniform_auxiliary_mean D T N c' hi b + · intro q + refine ⟨|j|,c.V,abs_nonneg _,c.V_nonneg, + fun a x=>onsager_parameter_bound j (J a) (h a) q.val x,fun a x=>?_⟩ + have hh : ‖derivativeVector ((D₀ a).θ q) x‖≤c.V := + (Finset.single_le_sum (fun r _=>norm_nonneg (derivativeVector ((D₀ a).θ r) x)) + (Finset.mem_univ q)).trans (hc a x).parameter + have hs:=pow_le_pow_left₀ (norm_nonneg _) hh 2 + rw [H₀.parameter a q,EuclideanSpace.real_norm_sq_eq] at hs + exact hs + +end SKGapCutoff.Recipe + +end +end + +section + +noncomputable section +open scoped BigOperators Matrix.Norms.Frobenius +namespace SKGapCutoff.Recipe +open Primary Static +variable {n M : ℕ} + +def emptyRecipe (j : ℝ) (J : Interaction n) (h : Fin n→ℝ) (M : ℕ) : + OrdinaryData n (Fin M) (Fin M) Unit where + J:=J + j:=j + H:=fun q=>fld j J h q.val + predecessor:=fun q=>mag j J h q.val + θ:=fun q x=>j*(onsager j J h (q.val+1) x-onsager j J h q.val x) + seed:=0 + seedFunction:=fun _ _ _ _=>0 + seedDerivative:=fun _ _ _ _=>0 + auxFunction:=fun _ _ _ _=>0 + auxDerivative:=fun _ _ _ _=>0 + +lemma emptyRecipe_coefficients (j : ℝ) (J : Interaction n) (h : Fin n→ℝ) (M N : ℕ) (x : Spin n) : + (emptyRecipe j J h M).CoefficientClass N x 1 := by + refine ⟨le_rfl,?_,?_,?_,?_⟩ + · intro a ha s; exact (segmentRegular_const _ _ x 0).mono zero_le_one + · intro a ha b; exact (segmentRegular_const _ _ x 0).mono zero_le_one + · intros; norm_num [SegmentValue,emptyRecipe] + · intros; norm_num [SegmentValue,emptyRecipe] + +lemma emptyRecipe_family {Ω : Type*} {n : Ω→ℕ} (j : ℝ) + (J : ∀a,Interaction (n a)) (h : ∀a,Fin (n a)→ℝ) (M : ℕ) : + FamilyRecipe j J h (fun a=>emptyRecipe j (J a) (h a) M) 0 0 1 := by + refine ⟨fun _=>rfl,fun _=>rfl,fun _ _=>rfl,fun _ _=>rfl,fun _ _=>rfl, + ⟨0,le_rfl,?_⟩,fun a x=>emptyRecipe_coefficients j (J a) (h a) M 0 x,?_⟩ + · intro a; simp [emptyRecipe,vectorNorm] + · intro a r hr q hq; omega + +lemma emptyRecipe_local (j : ℝ) (J : Interaction n) (h : Fin n→ℝ) (M : ℕ) + (T : Fin M→SKGap.Noncrossing.Primary.SourceTree (Fin n→ℝ)) (x : Spin n) + {P L E V : ℝ} (hP : 0≤P) (hL : 0≤L) (hE : 0≤E) (hV : 0≤V) (hn : 0j*(onsager j J h (q.val+1) y-onsager j J h q.val y)) x‖)≤V) : + LocalOrdinaryInput (emptyRecipe j J h M) T x 0 + ⟨1,1,P,L,E,V,0,le_rfl,zero_le_one,le_rfl,hP,hL,hE,hV,le_rfl⟩ := by + refine ⟨hn,hJ,hshape,hfield,hsource,?_,hderiv,?_,hparam,?_,?_,?_,?_⟩ + · intro q i; exact primaryState_mag_bounded j J h q.val x i + · simp [emptyRecipe,vectorNorm] + · intro a ha s; exact (segmentRegular_const _ _ x 0).mono zero_le_one + · intro a ha b; exact (segmentRegular_const _ _ x 0).mono zero_le_one + · intros; norm_num [OrdinaryData.seedCoefficient,coefficient,emptyRecipe] + · intros; norm_num [OrdinaryData.auxCoefficient,coefficient,emptyRecipe] + +end SKGapCutoff.Recipe + +end +end + +section + +noncomputable section +open scoped BigOperators +namespace SKGap.Noncrossing.Primary +open WordSeries MeasureTheory ProbabilityTheory Real Set + +theorem primary_uniform_two_seminorms {j : ℝ} (hj : 0gaussianReal 0 1)) + {g | ∃ (p : Bool) (a : ℕ→Fin n→ℝ), (∀ l i,|a l i|≤1) ∧ + C< matrixWordSeminorm p (primaryMatrix j (removeDiagonal (goeMatrix (j/n) g)) a k)} ≤ + 2*((wordPatternSet (2*k) (2*k)).card*ENNReal.ofReal (3*exp (-(n:ℝ)))+ + ENNReal.ofReal (exp (-2*(n:ℝ)/(π^2*(sqrt (2*j))^2))) + + (ENNReal.ofReal (2*exp (-(n:ℝ)/(π^2*j)))+ + ENNReal.ofReal (2*(n:ℝ)*exp (-1/(8*(j/n)))))) := by + have hs : sqrt j*(1:ℝ)<1 := by + nlinarith [sq_sqrt hj.le,sqrt_nonneg j] + obtain ⟨C,N,hC,hN,hgood⟩ := zeroDiag_exact_words_two_seminorms + hj (by norm_num : (0:ℝ)<1) hs (by norm_num : (1:ℝ)≤1) + (by norm_num : (1:ℝ)≤1) (by norm_num : (0:ℝ)<1) (2*k) + refine ⟨massBound j k*C,N,mul_pos (massBound_pos j k) hC,hN,?_⟩ + intro n hn + have hn0 : 00),liftWord t.2,?_,?_,htB.2,?_,?_,?_⟩ + · intro i; norm_num + · simpa [liftWord] using htB.1 + · simp + · exact Or.inl (inverseCount_lift t.2) + · have he : wordPrediction j (fun _ : Fin n=>0) 1 (liftWord t.2)=Diagram.prediction j t.2 := + funext (wordPrediction_lift j _ _ _) + simpa only [exactWord_lift,he] using hlt + have hb := primaryMatrix_seminorm p j (removeDiagonal (goeMatrix (j/n) g)) a k hk hterm + have hm := mul_le_mul_of_nonneg_right (primaryMass_bound j a ha k) hC.le + exact (not_lt_of_ge (hb.trans hm)) hlarge + +end SKGap.Noncrossing.Primary + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/FiniteStartedControlGeneral.lean b/lean/OAI/Probability/SKGap/Localization/FiniteStartedControlGeneral.lean new file mode 100644 index 0000000000000000000000000000000000000000..d9e88ac854415587331964af480a8d753320b7aa --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/FiniteStartedControlGeneral.lean @@ -0,0 +1,188 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.BufferedSelectionDiagnostics +import OAI.Probability.SKGap.Localization.RecipeArgumentPullback +import OAI.Probability.SKGap.Localization.UniformStarted + +namespace OAI + +section + +noncomputable section +open scoped BigOperators Matrix.Norms.Frobenius +namespace SKGapCutoff.Recipe +open Primary Static Matrix SKGap SKGap.Noncrossing SKGap.Noncrossing.Primary SKGap.Noncrossing.Primary.Tensor.Series SKGap.Noncrossing.ClosedMarked +universe u +variable {σ₁ : Type} [Fintype σ₁] +variable {Ω : Type u} {n : Ω→ℕ} {κ κ₀ σ₀ : Type} [Fintype κ] [DecidableEq κ] [Fintype κ₀] [DecidableEq κ₀] [Fintype σ₀] +variable {M : ℕ} {j : ℝ} {J : ∀a,Interaction (n a)} {h : ∀a,Fin (n a)→ℝ} +variable {E : ∀a,Set (Spin (n a))} {Θ : ∀a,κ→Observables (n a)} {w y : ∀a,VectorFields (n a)} + +theorem finite_started_control_seeds (D₀ : ∀a,OrdinaryData (n a) (Fin M) κ σ₁) + (K₀ : ℝ) (H₀ : LocalFamilyRecipe E j J h Θ w y D₀ 1 0 K₀) + (I : ∀a,OrdinaryData (n a) Unit κ₀ σ₀) + (hij : ∀a,(I a).j=j) (hIJ : ∀a,(I a).J=J a) + (T : ∀a,Spin (n a)→Fin M→SourceTree (Fin (n a)→ℝ)) + (t : ∀a,Spin (n a)→SourceTree (Fin (n a)→ℝ)) + (c : LocalConstants) (A : ℝ) + (hc : ∀a x,x∈flipNeighborhood (E a)→LocalOrdinaryInput (D₀ a) (T a x) x 1 c) + (index : Fin M→κ) + (hθ : ∀a q,(D₀ a).θ (index q)=fun x=>j*(onsager j (J a) (h a) (q.val+1) x-onsager j (J a) (h a) q.val x)) + (Nmax L : ℕ) (C F B₀ W B Q : ℝ) (hA : 1≤A) + (hC : 0≤C) (hF : 0≤F) (hB₀ : 0≤B₀) (hW : 0≤W) (hB : 0≤B) (hQ : 0≤Q) + (hW₀ : ∀a x,x∈flipNeighborhood (E a)→w a x=(I a).sourceOf 1 (fun _=>y a) x) + (hWf : ∀a x,x∈flipNeighborhood (E a)→∀i,w a (flip x i)=(I a).sourceOf 1 (fun _=>y a) (flip x i)) + (hY₀ : ∀a x,x∈flipNeighborhood (E a)→y a x=(I a).fieldOf 1 (fun _=>w a) (fun _=>y a) x) + (hYf : ∀a x,x∈flipNeighborhood (E a)→∀i,y a (flip x i)=(I a).fieldOf 1 (fun _=>w a) (fun _=>y a) (flip x i)) + (ha0 : ∀a x,x∈flipNeighborhood (E a)→∀i,0≤(I a).implicitCoefficient x i) + (hS : ∀a x,x∈flipNeighborhood (E a)→(1-SKGap.pathDiagonal ((I a).implicitCoefficient x) 1* + ((I a).J-((I a).j*siteMean (I a).implicitCoefficient x) • 1)*SKGap.pathDiagonal ((I a).implicitCoefficient x) 1).PosDef) + (hw₀ : ∀a x,x∈flipNeighborhood (E a)→SmallBound (w a) x B₀) + (hy₀ : ∀a x,x∈flipNeighborhood (E a)→SmallBound (y a) x B₀) + (hp₀ : ∀a x,x∈flipNeighborhood (E a)→vectorNorm ((I a).implicitPartial (y a) x)≤B₀) + (hP : ∀a x,x∈flipNeighborhood (E a)→TraceControl ((I a).implicitSourcePrimitive (t a x) (y a) x) C) + (hF' : ∀a x,x∈flipNeighborhood (E a)→TraceControl ((I a).implicitFieldPrimitive (t a x) (w a) (y a) x) F) + (ha : ∀a x,x∈flipNeighborhood (E a)→∀i,|(I a).implicitCoefficient x i|≤A) + (hm : ∀a x,x∈flipNeighborhood (E a)→∀l,Marked.mass (GradedWords.ordinaryWords j (T a x l)).1≤Q ∧ Marked.mass (GradedWords.ordinaryWords j (T a x l)).2≤Q) + (hm₀ : ∀a x,x∈flipNeighborhood (E a)→Marked.mass (GradedWords.ordinaryWords j (t a x)).1≤Q ∧ Marked.mass (GradedWords.ordinaryWords j (t a x)).2≤Q) + (hT : ∀a x,x∈flipNeighborhood (E a)→∀l,GradedControl A L (GradedWords.ordinaryWords j (T a x l)).1 ∧ GradedControl A L (GradedWords.ordinaryWords j (T a x l)).2) + (ht : ∀a x,x∈flipNeighborhood (E a)→GradedControl A L (GradedWords.ordinaryWords j (t a x)).1 ∧ GradedControl A L (GradedWords.ordinaryWords j (t a x)).2) + (hw : ∀a x,x∈flipNeighborhood (E a)→ClosedWordTestBound j ((I a).implicitCoefficient x) (J a) A W (2*Nmax+5)) + (hd : ∀a x,x∈flipNeighborhood (E a)→ClosedWordDiagramBound j ((I a).implicitCoefficient x) (J a) A B (L+2*Nmax+3)) : + FiniteLocalRecipeControl E j J h Θ w y M Nmax A := by + have transfer {σ : Type} [Fintype σ] (D : ∀a,OrdinaryData (n a) (Fin M) κ σ) + (N p : ℕ) (K : ℝ) (H : LocalFamilyRecipe E j J h Θ w y D N p K) (hKA : K≤A) : + ∃c' : LocalConstants,c'.A=A ∧ ∀a x,x∈flipNeighborhood (E a)→LocalOrdinaryInput (D a) (T a x) x N c' := by + obtain ⟨S,hS,hs⟩:=H.seed + refine ⟨c.withCoefficient A S hA hS,rfl,fun a x hx=>?_⟩ + obtain ⟨hJ,hj,hH,hp,hθ'⟩:=H.sameEnvironment H₀ a + exact (hc a x hx).with_coefficients (D a) hJ hj hH hp hθ' N A S hA hS (hs a) + ((H.coefficients a x hx).mono hKA) + constructor + · intro σ inst D N p K H hN hKA + obtain ⟨c',hAc',hi⟩:=transfer D N p K H hKA + apply uniform_started_control (fun a=>flipNeighborhood (E a)) D I w y T t N L c' j H.coupling hij + (fun a=>(H.interaction a).trans (hIJ a).symm) hi hW₀ hWf hY₀ hYf ha0 hS hB₀ hW hB hQ hC hF hw₀ hy₀ hp₀ hP hF' + · simpa only [hAc'] using ha + · exact hm + · exact hm₀ + · simpa only [hAc'] using hT + · simpa only [hAc'] using ht + · intro a x hx v hl hi hb + rw [H.interaction a,hAc'] at * + exact hw a x hx v (hl.trans (by omega)) hi hb + · intro a x hx v hl hi hb + rw [H.interaction a,hAc'] at * + exact hd a x hx v (hl.trans (by omega)) hi hb + · intro σ inst D N p K H hN hKA b + obtain ⟨c',hAc',hi⟩:=transfer D N p K H hKA + exact local_uniform_auxiliary_mean E D T N c' hi b + · intro q + refine ⟨|j|,c.V,abs_nonneg _,c.V_nonneg, + fun a x hx=>onsager_parameter_bound j (J a) (h a) q.val x,fun a x hx=>?_⟩ + have hh' : ‖derivativeVector ((D₀ a).θ (index q)) x‖≤c.V := + (Finset.single_le_sum (fun r _=>norm_nonneg (derivativeVector ((D₀ a).θ r) x)) + (Finset.mem_univ (index q))).trans (hc a x (Or.inl hx)).parameter + have hs:=pow_le_pow_left₀ (norm_nonneg _) hh' 2 + rw [hθ a q,EuclideanSpace.real_norm_sq_eq] at hs + exact hs + +end SKGapCutoff.Recipe + +end +end + +section + +noncomputable section +open scoped BigOperators +namespace SKGapCutoff.Recipe +open Primary SKGap.Stein Static + +variable {n M : ℕ} + +def literalFullParameters (j : ℝ) (J : Interaction n) (h : Fin n→ℝ) + (a c : Spin n→ℝ) : Fin M⊕Bool→Spin n→ℝ := + Sum.elim (fun q x=>j*(onsager j J h (q.val+1) x-onsager j J h q.val x)) + (fun b x=>if b then Real.sqrt (n:ℝ)*c x else a x) + +def literalFullData (j : ℝ) (J : Interaction n) (h : Fin n→ℝ) + (l : Fin M) (f : KernelExpr) (a c : Spin n→ℝ) (r e : Fin n→ℝ) : + OrdinaryData n (Fin M) (Fin M⊕Bool) Bool := + (literalInitial J j (Real.sqrt (n:ℝ)) f (fld j J h l.val) (mag j J h l.val) a c r e).argumentPullback (fun _:Unit=>l) Sum.inr (fun q=>fld j J h q.val) + (fun q=>mag j J h q.val) (literalFullParameters j J h a c) + +lemma literalFullData_admissible (j : ℝ) (J : Interaction n) (h : Fin n→ℝ) + (l : Fin M) (f : KernelExpr) (a c : Spin n→ℝ) (r e : Fin n→ℝ) + (N p : ℕ) (hp : p≤l.val) : (literalFullData j J h l f a c r e).Admissible N p := by + intro b hb q hq + have hne : q≠l := by intro he;subst q;omega + dsimp only [literalFullData] + constructor + · intro s + rw [OrdinaryData.unitPullback_seedPartial + (literalInitial J j (Real.sqrt (n:ℝ)) f (fld j J h l.val) (mag j J h l.val) a c r e) + l Sum.inr (fun q : Fin M=>fld j J h q.val) (fun q : Fin M=>mag j J h q.val) + (literalFullParameters j J h a c) rfl rfl] + simp only [ite_eq_right hne] + · intro s + rw [OrdinaryData.unitPullback_auxPartial + (literalInitial J j (Real.sqrt (n:ℝ)) f (fld j J h l.val) (mag j J h l.val) a c r e) + l Sum.inr (fun q : Fin M=>fld j J h q.val) (fun q : Fin M=>mag j J h q.val) + (literalFullParameters j J h a c) rfl rfl] + simp only [ite_eq_right hne] + +lemma literalFullData_coefficientClass (j : ℝ) (J : Interaction n) (h : Fin n→ℝ) + (l : Fin M) (f : KernelExpr) (a c : Spin n→ℝ) (r e : Fin n→ℝ) (x : Spin n) + {R B : ℝ} (hB : 0≤B) (ha : |a x|≤R) (haf : ∀k,|a (flip x k)|≤R) + (hc : |Real.sqrt (n:ℝ)*c x|≤B) (hcf : ∀k,|Real.sqrt (n:ℝ)*c (flip x k)|≤B) (N : ℕ) : + (literalFullData j J h l f a c r e).CoefficientClass N x (literalCoefficientBudget f j R B) := by + exact (literalInitial_coefficientClass J j (Real.sqrt (n:ℝ)) f + (fld j J h l.val) (mag j J h l.val) a c r e x hB ha haf hc hcf N).argumentPullback (fun _:Unit=>l) Sum.inr _ _ _ rfl rfl + +lemma literalFullData_initial (j : ℝ) (J : Interaction n) (h : Fin n→ℝ) + (l : Fin M) (f : KernelExpr) (a c : Spin n→ℝ) (r e : Fin n→ℝ) + (w y : VectorFields n) (hn : 0literalFullParameters j (J b) (h b) (a b) (c b)) w y + (fun b=>literalFullData j (J b) (h b) l f (a b) (c b) (r b) (e b)) 1 l.val + (literalCoefficientBudget f j R B) := by + refine ⟨le_rfl,fun _=>rfl,fun _=>rfl,fun _ _=>rfl,fun _ _=>rfl,fun _=>rfl,?_,?_,?_,?_⟩ + · refine ⟨2,by norm_num,fun b=>?_⟩ + exact literalInitial_seed_bound (J b) j f (fld j (J b) (h b) l.val) + (mag j (J b) (h b) l.val) (a b) (c b) (r b) (e b) (hn b) (he b) + · intro b x hx + apply literalFullData_coefficientClass j (J b) (h b) l f (a b) (c b) (r b) (e b) x hB + · exact ha b x (Or.inl hx) + · intro k;exact ha b (flip x k) (Or.inr ⟨k,by simpa only [flip_flip] using hx⟩) + · exact hc b x (Or.inl hx) + · intro k;exact hc b (flip x k) (Or.inr ⟨k,by simpa only [flip_flip] using hx⟩) + · intro b;exact literalFullData_admissible j (J b) (h b) l f (a b) (c b) (r b) (e b) 1 l.val le_rfl + · intro b x hx;exact literalFullData_initial j (J b) (h b) l f (a b) (c b) (r b) (e b) + (w b) (y b) (hn b) x (heq b x hx) + +end SKGapCutoff.Recipe + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/FixedTimeQuenched.lean b/lean/OAI/Probability/SKGap/Localization/FixedTimeQuenched.lean new file mode 100644 index 0000000000000000000000000000000000000000..6573c48482ee08562c24cf2c74d292c55d8a11d6 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/FixedTimeQuenched.lean @@ -0,0 +1,102 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.PartitionChangeMeasure +import OAI.Probability.SKGap.Stability.FixedTimeAnnealed + +namespace OAI + +section + +noncomputable section +namespace SKGap.ObservationBridge +open Matrix Real Set MeasureTheory ProbabilityTheory Filter +open scoped BigOperators ENNReal NNReal Topology + +def fixedTimeFailure (n : ℕ) (j A K ε c ρ t : ℝ) (J : Disorder n) : ℝ := + (fixedTimeFailureENN j A K ε c ρ t J).toReal + +lemma measurable_fixedTimeFailure (n : ℕ) (j A K ε c ρ t : ℝ) : + Measurable (fixedTimeFailure n j A K ε c ρ t) := + (measurable_fixedTimeFailureENN j A K ε c ρ t).ennreal_toReal + +lemma fixedTimeFailure_nonneg (n : ℕ) (j A K ε c ρ t : ℝ) (J : Disorder n) : + 0 ≤ fixedTimeFailure n j A K ε c ρ t J := ENNReal.toReal_nonneg + +lemma fixedTimeFailure_le_one (n : ℕ) (j A K ε c ρ t : ℝ) (J : Disorder n) : + fixedTimeFailure n j A K ε c ρ t J ≤ 1 := by + exact (ENNReal.toReal_mono ENNReal.one_ne_top + (fixedTimeFailureENN_le_one j A K ε c ρ t J)).trans_eq ENNReal.toReal_one + +lemma ofReal_fixedTimeFailure (n : ℕ) (j A K ε c ρ t : ℝ) (J : Disorder n) : + ENNReal.ofReal (fixedTimeFailure n j A K ε c ρ t J) = fixedTimeFailureENN j A K ε c ρ t J := + ENNReal.ofReal_toReal (ne_top_of_le_ne_top ENNReal.one_ne_top + (fixedTimeFailureENN_le_one j A K ε c ρ t J)) + +lemma disorder_partition_integrable (β : ℝ) (n : ℕ) : + Integrable (fun J : Disorder n=>partition J 0) (disorderLaw β n) := by + rw [← (gaussian_disorder_hasLaw β n).map_eq] + apply (integrable_map_measure (partition_zero_measurable n).aestronglyMeasurable + (gaussian_disorder_hasLaw β n).aemeasurable).2 + simpa only [Function.comp_def,← gaussianSpinPartition_eq_partition] using + gaussianSpinPartition_integrable n (β^2/(n:ℝ)) + +def partitionSizeBias (β : ℝ) (n : ℕ) (J : Disorder n) : ℝ := + partition J 0/(∫ J,partition J 0 ∂disorderLaw β n) + +lemma partitionSizeBias_pos (β : ℝ) (n : ℕ) (J : Disorder n) : + 0 < partitionSizeBias β n J := by + unfold partitionSizeBias + rw [disorder_partition_mean] + exact div_pos (partition_pos J 0) (gaussianSpinPartition_mean_pos (by positivity)) + +lemma partitionSizeBias_integrable (β : ℝ) (n : ℕ) : + Integrable (partitionSizeBias β n) (disorderLaw β n) := + (disorder_partition_integrable β n).div_const _ + +lemma weighted_fixedTimeFailure_integrable (β : ℝ) (n : ℕ) (j A K ε c ρ t : ℝ) : + Integrable (fun J=> partitionSizeBias β n J*fixedTimeFailure n j A K ε c ρ t J) + (disorderLaw β n) := by + apply (partitionSizeBias_integrable β n).mul_bdd + (measurable_fixedTimeFailure n j A K ε c ρ t).aestronglyMeasurable + filter_upwards [] with J + rw [Real.norm_eq_abs,abs_of_nonneg (fixedTimeFailure_nonneg _ _ _ _ _ _ _ _ _)] + exact fixedTimeFailure_le_one n j A K ε c ρ t J + +lemma weighted_fixedTimeFailure_integral_bound (β : ℝ) (n : ℕ) (A K ε c ρ t b : ℝ) + (hb : 0 ≤ b) + (hh : (∫⁻ J : Disorder n, ENNReal.ofReal (partitionSizeBias β n J)* + fixedTimeFailureENN (β^2) A K ε c ρ t J ∂disorderLaw β n) ≤ ENNReal.ofReal b) : + (∫ J : Disorder n,partitionSizeBias β n J*fixedTimeFailure n (β^2) A K ε c ρ t J + ∂disorderLaw β n) ≤ b := by + apply (ENNReal.ofReal_le_ofReal_iff hb).mp + rw [ofReal_integral_eq_lintegral_ofReal + (weighted_fixedTimeFailure_integrable β n (β^2) A K ε c ρ t) + (ae_of_all _ (fun J=>mul_nonneg (partitionSizeBias_pos β n J).le + (fixedTimeFailure_nonneg _ _ _ _ _ _ _ _ _)))] + simp_rw [ENNReal.ofReal_mul (partitionSizeBias_pos β n _).le,ofReal_fixedTimeFailure] + exact hh + +theorem quenched_fixed_time_root_stability {β T : ℝ} (hβ : 0<β) (hβ1 : β<1) (hT : 0(disorderLaw β n).real + {J | exp (-a*(n:ℝ)) < fixedTimeFailure n (β^2) A K ε c ρ (τ n) J}) atTop (𝓝 0) := by + obtain ⟨A,K,ε,c,ρ,a,hA,hK,hsub,hε,hc,hρ,ha,N,hN,hann⟩ := + annealed_fixed_time_root_stability hβ hβ1 hT + refine ⟨A,K,ε,c,ρ,a/4,hA,hK,hsub,hε,hc,hρ,by positivity,?_⟩ + intro τ hτ + apply exponential_size_bias_transfer (C:=1) (disorderLaw β) (partitionSizeBias β) + (fun n=>fixedTimeFailure n (β^2) A K ε c ρ (τ n)) + (fun n J=>(partitionSizeBias_pos β n J).le) + (fun n J=>fixedTimeFailure_nonneg _ _ _ _ _ _ _ _ _) + (fun n=>weighted_fixedTimeFailure_integrable _ _ _ _ _ _ _ _ _) ha zero_le_one + · exact disorder_partition_lower_tail hβ hβ1 (by positivity) + · filter_upwards [eventually_ge_atTop N] with n hn + simp only [one_mul] + exact weighted_fixedTimeFailure_integral_bound β n A K ε c ρ (τ n) _ (exp_pos _).le + (hann n hn (τ n) (hτ n)) +end SKGap.ObservationBridge + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/FockSeries.lean b/lean/OAI/Probability/SKGap/Localization/FockSeries.lean new file mode 100644 index 0000000000000000000000000000000000000000..0d8674a25c2935d71ed28d0ed91e373162a0d420 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/FockSeries.lean @@ -0,0 +1,305 @@ +import Mathlib +import OAI.Probability.SKGap.Stability.OrdinaryGraph +import OAI.Probability.SKGap.Matrix.LoopPrediction + +namespace OAI + +section + +noncomputable section +open scoped BigOperators +namespace SKGap.Noncrossing.Primary.Tensor.Series +open Diagram InverseDiagram WordSeries Loop +variable {ι : Type*} +abbrev Seq := ℕ→Space (ι:=ι) + +def ofVector (v : Space (ι:=ι)) : Seq (ι:=ι) := fun n => if n=0 then v else 0 + +def shift : Seq (ι:=ι)→ₗ[ℝ] Seq (ι:=ι) where + toFun v n := match n with | 0 => 0 | n+1 => v n + map_add' _ _ := by ext n i I; cases n <;> simp + map_smul' _ _ := by ext n i I; cases n <;> simp + +def act (A : Space (ι:=ι)→ₗ[ℝ] Space (ι:=ι)) : Seq (ι:=ι)→ₗ[ℝ] Seq (ι:=ι) where + toFun v n := A (v n) + map_add' _ _ := by funext n; exact A.map_add _ _ + map_smul' _ _ := by funext n; exact A.map_smul _ _ + +@[simp] lemma shift_zero (v : Seq (ι:=ι)) : shift v 0=0 := rfl +@[simp] lemma shift_succ (v : Seq (ι:=ι)) (n : ℕ) : shift v (n+1)=v n := rfl +@[simp] lemma act_apply (A : Space (ι:=ι)→ₗ[ℝ] Space (ι:=ι)) (v : Seq (ι:=ι)) (n : ℕ) : + act A v n=A (v n) := rfl +lemma act_shift (A : Space (ι:=ι)→ₗ[ℝ] Space (ι:=ι)) (v : Seq (ι:=ι)) : + act A (shift v)=shift (act A v) := by ext n; cases n <;> simp + +variable [Fintype ι] + +def inverseSeq (j : ℝ) (a : ι→ℝ) (v : Seq (ι:=ι)) : Seq (ι:=ι) + | 0 => v 0 + | 1 => v 1+diagonal a (noise j (v 0)) + | n+2 => v (n+2)+diagonal a (noise j (inverseSeq j a v (n+1)))- + (j*Diagram.mean a) • diagonal a (inverseSeq j a v n) + +lemma inverseSeq_add (j : ℝ) (a : ι→ℝ) (v w : Seq (ι:=ι)) : + inverseSeq j a (v+w)=inverseSeq j a v+inverseSeq j a w := by + funext n + induction n using Nat.twoStepInduction with + | zero => rfl + | one => simp only [inverseSeq,Pi.add_apply,map_add]; abel + | more n ih0 ih1 => + simp only [inverseSeq,Pi.add_apply] at ih0 ih1 ⊢ + rw [ih0,ih1] + simp only [map_add,smul_add] + abel +lemma inverseSeq_smul (j c : ℝ) (a : ι→ℝ) (v : Seq (ι:=ι)) : + inverseSeq j a (c • v)=c • inverseSeq j a v := by + funext n + induction n using Nat.twoStepInduction with + | zero => rfl + | one => simp [inverseSeq,map_smul,smul_add] + | more n ih0 ih1 => + simp only [inverseSeq,Pi.smul_apply] at ih0 ih1 ⊢ + rw [ih0,ih1] + simp only [map_smul,smul_add,smul_sub,smul_smul] + rw [mul_comm (j*Diagram.mean a) c] + +def inverse (j : ℝ) (a : ι→ℝ) : Seq (ι:=ι)→ₗ[ℝ] Seq (ι:=ι) where + toFun := inverseSeq j a + map_add' := inverseSeq_add j a + map_smul' c v := inverseSeq_smul j c a v + +lemma inverse_equation (j : ℝ) (a : ι→ℝ) (v : Seq (ι:=ι)) : + inverse j a v=v+shift (act ((diagonal a).comp (noise j)) (inverse j a v))- + (j*Diagram.mean a) • shift (shift (act (diagonal a) (inverse j a v))) := by + funext n + rcases n with _|n + · simp [inverse,inverseSeq] + rcases n with _|n + · simp [inverse,inverseSeq] + · rfl + +lemma inverse_unique (j : ℝ) (a : ι→ℝ) (v u : Seq (ι:=ι)) + (hu : u=v+shift (act ((diagonal a).comp (noise j)) u)- + (j*Diagram.mean a) • shift (shift (act (diagonal a) u))) : + u=inverse j a v := by + funext n + induction n using Nat.twoStepInduction with + | zero => have h:=congrFun hu 0; simpa [inverse,inverseSeq] using h + | one => + have h0:=congrFun hu 0 + have h1:=congrFun hu 1 + simp only [Pi.add_apply,Pi.sub_apply,shift_zero,Pi.smul_apply,smul_zero,add_zero,sub_zero] at h0 + simpa [inverse,inverseSeq,h0] using h1 + | more n ih0 ih1 => + have h:=congrFun hu (n+2) + simp only [Pi.add_apply,Pi.sub_apply,shift_succ,act_apply,LinearMap.comp_apply,Pi.smul_apply] at h + rw [ih0,ih1] at h + exact h + +lemma inverse_shift (j : ℝ) (a : ι→ℝ) (v : Seq (ι:=ι)) : + inverse j a (shift v)=shift (inverse j a v) := by + symm + apply inverse_unique + have h:=congrArg shift (inverse_equation j a v) + simpa only [map_add,map_sub,map_smul,act_shift] using h + +lemma kernel_add_two_left (j : ℝ) (a : ι→ℝ) (n : ℕ) : + kernel j a (n+2)=((diagonal a).comp (noise j)).comp (kernel j a (n+1))- + (j*Diagram.mean a) • (diagonal a).comp (kernel j a n) := by + have h := Fintype.sum_equiv (Equiv.ofBijective (blockPrepend n) (blockPrepend_bijective n)) + (fun s => match s with + | .inl bs => word j (chain j a (true::bs.val)) + | .inr bs => word j (chain j a (false::bs.val))) + (fun bs => word j (chain j a bs.val)) (by intro s; cases s <;> rfl) + change _=kernel j a (n+2) at h + rw [Fintype.sum_sum_type] at h + rw [←h] + simp only [chain_true,chain_false,word,letter,diagonal_scale,LinearMap.smul_comp] + ext v i I + simp [kernel,LinearMap.sum_apply,LinearMap.comp_apply,Finset.sum_neg_distrib, + ←Finset.mul_sum,sub_eq_add_neg] + +lemma inverse_ofVector (j : ℝ) (a : ι→ℝ) (v : Space (ι:=ι)) (n : ℕ) : + inverse j a (ofVector v) n=kernel j a n v := by + induction n using Nat.twoStepInduction with + | zero => simp [inverse,inverseSeq,ofVector,kernel_zero] + | one => simp [inverse,inverseSeq,ofVector,kernel_one] + | more n ih0 ih1 => + change inverseSeq j a (ofVector v) (n+2)=_ + rw [inverseSeq] + change ofVector v (n+2)+diagonal a (noise j (inverse j a (ofVector v) (n+1)))- + (j*Diagram.mean a) • diagonal a (inverse j a (ofVector v) n)=_ + rw [ih0,ih1,kernel_add_two_left] + simp [ofVector] + +end SKGap.Noncrossing.Primary.Tensor.Series + +end +end + +section + +noncomputable section +open scoped BigOperators +namespace SKGap.Noncrossing.Primary.Tensor.Series +open Diagram Loop +variable {ι : Type*} [Fintype ι] + +def branchSource (p : ι→ℝ) (U V : Seq (ι:=ι)×Seq (ι:=ι)) : Seq (ι:=ι) := + act (diagonal p) U.2+V.1 +def branchField (j : ℝ) (p : ι→ℝ) (U V : Seq (ι:=ι)×Seq (ι:=ι)) : Seq (ι:=ι) := + shift (act (noise j) (act (diagonal p) U.2))- + (j*Diagram.mean p) • shift (shift U.1)+V.2 + +def ordinary (j : ℝ) : SourceTree (ι→ℝ)→Seq (ι:=ι)×Seq (ι:=ι) + | .leaf c => (ofVector (c • vacuum),shift (ofVector (c • noise j vacuum))) + | .branch p t u => (branchSource p (ordinary j t) (ordinary j u), + branchField j p (ordinary j t) (ordinary j u)) + +lemma noise_vacuum (j : ℝ) : noise j (vacuum (ι:=ι))=creation vacuum := by + rw [vacuum,←realize_noise] + have h : Primary.noise j (Primary.vacuum (ι:=ι))=Primary.creation Primary.vacuum := by + simp [Primary.noise,Primary.vacuum] + rw [h,realize_creation] + +lemma branch_field_creation (j : ℝ) (p : ι→ℝ) (U V : Seq (ι:=ι)×Seq (ι:=ι)) + (hU : U.2=shift (act creation U.1)) (hV : V.2=shift (act creation V.1)) : + branchField j p U V=shift (act creation (branchSource p U V)) := by + funext n + cases n with + | zero => simp [branchField,branchSource,hV] + | succ n => + cases n with + | zero => simp [branchField,branchSource,hU,hV] + | succ n => + simp only [branchField,branchSource,Pi.add_apply,Pi.sub_apply,Pi.smul_apply, + hU,hV,shift_succ,act_apply,noise,LinearMap.add_apply,LinearMap.smul_apply, + annihilation_diagonal_creation,map_add,smul_smul] + abel + +lemma ordinary_field_creation (j : ℝ) (t : SourceTree (ι→ℝ)) : + (ordinary j t).2=shift (act creation (ordinary j t).1) := by + induction t with + | leaf c => + funext n + cases n with + | zero => rfl + | succ n => + simp only [ordinary,shift_succ,act_apply,ofVector] + split_ifs <;> simp [noise_vacuum] + | branch p t u ih1 ih2 => exact branch_field_creation j p _ _ ih1 ih2 + +def loopSource (j : ℝ) (a p : ι→ℝ) (t : SourceTree (ι→ℝ)) : Seq (ι:=ι) := + inverse j a (act (diagonal p) (ordinary j t).2- + (j*Diagram.mean p) • shift (shift (act (diagonal a) (ordinary j t).1))) +def loopField (j : ℝ) (a p : ι→ℝ) (t : SourceTree (ι→ℝ)) : Seq (ι:=ι) := + shift (act (noise j) (loopSource j a p t))- + (j*Diagram.mean a) • shift (shift (loopSource j a p t))- + (j*Diagram.mean p) • shift (shift (ordinary j t).1) + +lemma loop_source_equation (j : ℝ) (a p : ι→ℝ) (t : SourceTree (ι→ℝ)) : + loopSource j a p t=act (diagonal a) (loopField j a p t)+ + act (diagonal p) (ordinary j t).2 := by + have h := inverse_equation j a + (act (diagonal p) (ordinary j t).2- + (j*Diagram.mean p) • shift (shift (act (diagonal a) (ordinary j t).1))) + change loopSource j a p t = + act (diagonal p) (ordinary j t).2- + (j*Diagram.mean p) • shift (shift (act (diagonal a) (ordinary j t).1))+ + shift (act ((diagonal a).comp (noise j)) (loopSource j a p t))- + (j*Diagram.mean a) • shift (shift (act (diagonal a) (loopSource j a p t))) at h + refine h.trans ?_ + change _=act (diagonal a) (shift (act (noise j) (loopSource j a p t))- + (j*Diagram.mean a) • shift (shift (loopSource j a p t))- + (j*Diagram.mean p) • shift (shift (ordinary j t).1))+ + act (diagonal p) (ordinary j t).2 + simp only [map_sub,map_smul,act_shift] + have hc : act ((diagonal a).comp (noise j)) (loopSource j a p t)= + act (diagonal a) (act (noise j) (loopSource j a p t)) := rfl + rw [hc] + abel + +lemma loop_source_zero (j : ℝ) (a p : ι→ℝ) (t : SourceTree (ι→ℝ)) : + loopSource j a p t 0=0 := by + have h:=congrFun (loop_source_equation j a p t) 0 + simpa [loopField,ordinary_field_creation j t] using h + +theorem loop_field_creation (j : ℝ) (a p : ι→ℝ) (t : SourceTree (ι→ℝ)) : + loopField j a p t=shift (act creation (loopSource j a p t)) := by + have ht := ordinary_field_creation j t + have hs := loop_source_equation j a p t + have h (n : ℕ) : loopField j a p t (n+1)=creation (loopSource j a p t n) := by + induction n with + | zero => simp [loopField,loop_source_zero] + | succ n ih => + have he := congrFun hs (n+1) + simp only [Pi.add_apply,act_apply,ih,ht,shift_succ] at he + change _ = creation (loopSource j a p t (n+1)) + simp only [loopField,Pi.sub_apply,Pi.smul_apply,shift_succ,act_apply] + rw [noise,LinearMap.add_apply,LinearMap.smul_apply,he] + simp only [map_add,annihilation_diagonal_creation,smul_add,smul_smul] + abel + funext n + cases n with + | zero => simp [loopField] + | succ n => exact h n + +inductive ClosedTree (D : Type*) where + | leaf : ℝ→ClosedTree D + | implicit : D→SourceTree D→ClosedTree D + | branch : D→ClosedTree D→ClosedTree D→ClosedTree D + +def ClosedTree.series (j : ℝ) (a : ι→ℝ) : ClosedTree (ι→ℝ)→Seq (ι:=ι)×Seq (ι:=ι) + | .leaf c => ordinary j (.leaf c) + | .implicit p t => (loopSource j a p t,loopField j a p t) + | .branch p t u => (branchSource p (t.series j a) (u.series j a), + branchField j p (t.series j a) (u.series j a)) + +def ClosedTree.leafMass {D : Type*} : ClosedTree D→ℝ + | .leaf c => c + | .implicit _ _ => 0 + | .branch _ _ u => u.leafMass + +theorem ClosedTree.field_creation (j : ℝ) (a : ι→ℝ) (t : ClosedTree (ι→ℝ)) : + (t.series j a).2=shift (act creation (t.series j a).1) := by + induction t with + | leaf c => exact ordinary_field_creation j (.leaf c) + | implicit p t => exact loop_field_creation j a p t + | branch p t u ih1 ih2 => exact branch_field_creation j p _ _ ih1 ih2 + +theorem ClosedTree.project_field (j : ℝ) (a : ι→ℝ) (t : ClosedTree (ι→ℝ)) (n : ℕ) : + project ((t.series j a).2 n)=0 := by + rw [t.field_creation] + cases n with + | zero => simp + | succ n => simp [project_creation] + +theorem ClosedTree.project_source (j : ℝ) (a : ι→ℝ) (t : ClosedTree (ι→ℝ)) (n : ℕ) : + project ((t.series j a).1 n)=if n=0 then (fun _ : ι => t.leafMass) else 0 := by + induction t with + | leaf c => + simp only [series,ordinary,ofVector,leafMass] + split_ifs <;> simp [vacuum,project_realize,Primary.vacuum] + ext index + simp + | implicit p t => + simp only [series,leafMass] + simp only [Pi.zero_def,ite_self] + rw [loop_source_equation,Pi.add_apply,act_apply,act_apply, + loop_field_creation,ordinary_field_creation] + cases n with + | zero => simp; rfl + | succ n => simp [project_diagonal_creation]; rfl + | branch p t u ih1 ih2 => + simp only [series,branchSource,Pi.add_apply,act_apply,leafMass] + rw [t.field_creation] + cases n with + | zero => simpa using ih2 + | succ n => simpa [project_diagonal_creation] using ih2 + +end SKGap.Noncrossing.Primary.Tensor.Series + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/FrobeniusSq.lean b/lean/OAI/Probability/SKGap/Localization/FrobeniusSq.lean new file mode 100644 index 0000000000000000000000000000000000000000..5221d6ae03ffb50b63f028a18d1d123a0adf61fa --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/FrobeniusSq.lean @@ -0,0 +1,77 @@ +import Mathlib +import OAI.Probability.SKGap.Matrix.OpNorm + +namespace OAI + +noncomputable section + +open MeasureTheory ProbabilityTheory InformationTheory Real Set +open scoped NNReal ENNReal +open Filter +open scoped Topology +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius ENNReal NNReal +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius NNReal +namespace SKGap +variable {ι : Type*} [Fintype ι] [DecidableEq ι] + +lemma frobenius_sq (M : Matrix ι ι ℝ) : ‖M‖^2 = ∑ i,∑ k, (M i k)^2 := by + rw [Matrix.frobenius_norm_def] + simp only [Real.rpow_two, Real.norm_eq_abs,sq_abs] + rw [← Real.sqrt_eq_rpow,Real.sq_sqrt] + positivity + +lemma frobenius_col_sq (M : Matrix ι ι ℝ) : ‖M‖^2 = ∑ k, ‖colVec M k‖^2 := by + rw [frobenius_sq,Finset.sum_comm] + apply Finset.sum_congr rfl + intro k _ + rw [EuclideanSpace.norm_sq_eq] + simp [colVec,Real.norm_eq_abs,sq_abs] + +lemma colVec_mul (M N : Matrix ι ι ℝ) (k : ι) : + colVec (M*N) k = M.toEuclideanLin.toContinuousLinearMap (colVec N k) := by + ext i + rfl + +lemma frobenius_mul_le_opNorm (M N : Matrix ι ι ℝ) : ‖M*N‖ ≤ opNorm M * ‖N‖ := by + have hp : 0 ≤ opNorm M := norm_nonneg _ + apply nonneg_le_nonneg_of_sq_le_sq (mul_nonneg hp (norm_nonneg N)) + simp only [← sq] + rw [frobenius_col_sq,mul_pow,frobenius_col_sq,Finset.mul_sum] + apply Finset.sum_le_sum + intro k _ + rw [colVec_mul] + have hh := M.toEuclideanLin.toContinuousLinearMap.le_opNorm (colVec N k) + change ‖M.toEuclideanLin.toContinuousLinearMap (colVec N k)‖ ≤ opNorm M * ‖colVec N k‖ at hh + nlinarith only [hh, norm_nonneg (M.toEuclideanLin.toContinuousLinearMap (colVec N k)), + mul_nonneg hp (norm_nonneg (colVec N k))] + +lemma opNorm_transpose (M : Matrix ι ι ℝ) : opNorm Mᵀ = opNorm M := by + change ‖Mᵀ.toEuclideanLin.toContinuousLinearMap‖ = ‖M.toEuclideanLin.toContinuousLinearMap‖ + have he : Mᵀ.toEuclideanLin.toContinuousLinearMap = + ContinuousLinearMap.adjoint M.toEuclideanLin.toContinuousLinearMap := by + apply ContinuousLinearMap.ext + intro x + apply ext_inner_left ℝ + intro y + rw [ContinuousLinearMap.adjoint_inner_right] + change (∑ i, (∑ k, M k i*x k)*y i) = ∑ i, x i * (∑ k, M i k*y k) + simp only [Finset.sum_mul,Finset.mul_sum] + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro i _ + apply Finset.sum_congr rfl + intro k _ + ring + rw [he,ContinuousLinearMap.adjoint.norm_map] + +lemma frobenius_mul_le_opNorm_right (M N : Matrix ι ι ℝ) : ‖M*N‖ ≤ ‖M‖ * opNorm N := by + rw [← Matrix.frobenius_norm_transpose (M*N),Matrix.transpose_mul] + exact (frobenius_mul_le_opNorm Nᵀ Mᵀ).trans_eq (by rw [opNorm_transpose,Matrix.frobenius_norm_transpose,mul_comm]) + +end SKGap + +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/GeneralTemplateRegularity.lean b/lean/OAI/Probability/SKGap/Localization/GeneralTemplateRegularity.lean new file mode 100644 index 0000000000000000000000000000000000000000..5ec15e366b5552e005424c52610a87e33b485c89 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/GeneralTemplateRegularity.lean @@ -0,0 +1,146 @@ +import Mathlib +import OAI.Probability.SKGap.Matrix.GlobalWordIncrement + +namespace OAI + +section +noncomputable section +namespace SKGap +open Matrix Real Set +open scoped BigOperators Matrix.Norms.Frobenius SchwartzMap +variable {ι : Type*} [Fintype ι] [DecidableEq ι] {m : ℕ} + +def generalTemplateMatrix (f : 𝓢(ℝ,ℂ)) (R : ℝ) (hR : 0 ≤ R) (j A D : ℝ) + (F : List (WordTemplateLetter m)) (θ : WordParameter m ι) : Matrix ι ι ℝ→Matrix ι ι ℝ := + actualWord f R hR j (templateInverse A θ) 1 (templateWord D θ F) + +def generalTemplateHolder (f : 𝓢(ℝ,ℂ)) (R j A D : ℝ) : ℝ := + globalWordHolder f R j A D*sqrt (templateScale A D) + +lemma generalTemplateHolder_nonneg (f : 𝓢(ℝ,ℂ)) {R j A D : ℝ} + (hR : 0 ≤ R) (hj : 0 ≤ j) (hA : 0 ≤ A) (hD : 0 ≤ D) : + 0 ≤ generalTemplateHolder f R j A D := + mul_nonneg (globalWordHolder_nonneg f hR hj hA hD) (sqrt_nonneg _) + +theorem generalTemplateMatrix_increments [Nonempty ι] (f : 𝓢(ℝ,ℂ)) {R j A D : ℝ} + (hR : 0 ≤ R) (hj : 0 ≤ j) (hA : 0 ≤ A) (hD : 0 ≤ D) + (F : List (WordTemplateLetter m)) (θ η : WordParameter m ι) : + let B : NNReal := ⟨actualWordBound f R j A D,(actualWordBound_pos f hR hj hA hD).le⟩ + let Δ : NNReal := ⟨generalTemplateHolder f R j A D*sqrt (dist θ η),mul_nonneg (generalTemplateHolder_nonneg f hR hj hA hD) (sqrt_nonneg _)⟩ + (∀ M,opNorm (generalTemplateMatrix f R hR j A D F θ M-generalTemplateMatrix f R hR j A D F η M) ≤ + (wordParameterCoeff B F.length:ℝ)*Δ) ∧ + LipschitzWith (wordMixedCoeff B F.length*Δ) + (fun M=>generalTemplateMatrix f R hR j A D F θ M-generalTemplateMatrix f R hR j A D F η M) := by + intro B Δ + have hK : 0 ≤ templateScale A D := by dsimp [templateScale];positivity + have hh := actualWord_pair_global f hR hj hA hD (mul_nonneg hK dist_nonneg) + (fun i=>(templateInverse_bounds hA θ i).1) (fun i=>(templateInverse_bounds hA η i).1) + (fun i=>(templateInverse_bounds hA θ i).2) (fun i=>(templateInverse_bounds hA η i).2) + (templateInverse_dist hA hD θ η) + (F.map (fun l=>(l.realize D θ,l.realize D η))) (templateWord_paired hA hD θ η F) + simpa only [generalTemplateMatrix,generalTemplateHolder,B,Δ,List.length_map,List.map_map, + Function.comp_def,templateWord,Real.sqrt_mul hK,mul_assoc] using! hh +end SKGap +end +end + +section +noncomputable section +namespace SKGap +open Matrix Real Set +open scoped BigOperators Matrix.Norms.Frobenius SchwartzMap +variable {ι : Type*} [Fintype ι] [DecidableEq ι] {m : ℕ} + +omit [DecidableEq ι] in +lemma wordParameter_dist_le_one (θ η : WordParameter m ι) : dist θ η ≤ 1 := by + apply (dist_pi_le_iff zero_le_one).mpr + intro s + rw [Subtype.dist_eq,Real.dist_eq] + exact abs_le.mpr ⟨by linarith [(θ s).property.1,(η s).property.2],by linarith [(θ s).property.2,(η s).property.1]⟩ + +def templateMatrix (f : 𝓢(ℝ,ℂ)) (R : ℝ) (hR : 0 ≤ R) (j D : ℝ) + (F : List (WordTemplateLetter m)) (θ : WordParameter m ι) : Matrix ι ι ℝ→Matrix ι ι ℝ := + actualWord f R hR j (templateInverse 1 θ) 1 (templateWord D θ F) + +def templateHolder (f : 𝓢(ℝ,ℂ)) (R j D : ℝ) : ℝ := wordHolderScale f R j 1+2*D+1 + +lemma templateHolder_nonneg (f : 𝓢(ℝ,ℂ)) {R j D : ℝ} (hj : 0 ≤ j) (hD : 0 ≤ D) : + 0 ≤ templateHolder f R j D := by + have hh := wordHolderScale_ge_one f R 1 hj + dsimp [templateHolder] + linarith + +lemma templateFactor_pair [Nonempty ι] (f : 𝓢(ℝ,ℂ)) {R j D : ℝ} + (hR : 0 ≤ R) (hj : 0 ≤ j) (hD : 0 ≤ D) (θ η : WordParameter m ι) (l : WordTemplateLetter m) : + let B : NNReal := ⟨actualWordBound f R j 1 D,(actualWordBound_pos f hR hj zero_le_one hD).le⟩ + let Δ : NNReal := ⟨templateHolder f R j D*sqrt (dist θ η),mul_nonneg (templateHolder_nonneg f hj hD) (sqrt_nonneg _)⟩ + MatrixFactorPairBounds B Δ + ((l.realize D θ).eval f R hR j (templateInverse 1 θ) 1) + ((l.realize D η).eval f R hR j (templateInverse 1 η) 1) := by + intro B Δ + have ha (θ : WordParameter m ι) (i : ι) := templateInverse_bounds zero_le_one θ i + have hl (θ : WordParameter m ι) : (l.realize D θ).bounded D := + templateWord_bounded hD θ [l] _ (by simp [templateWord]) + obtain ⟨h1,h2⟩ := WordLetter.eval_bounds f hR hj zero_le_one hD (fun i=>(ha θ i).1) (fun i=>(ha θ i).2) ⟨zero_le_one,le_rfl⟩ _ (hl θ) + obtain ⟨h3,h4⟩ := WordLetter.eval_bounds f hR hj zero_le_one hD (fun i=>(ha η i).1) (fun i=>(ha η i).2) ⟨zero_le_one,le_rfl⟩ _ (hl η) + have hδ1 := wordParameter_dist_le_one θ η + have hlarge : wordHolderScale f R j 1 ≤ templateHolder f R j D := by dsimp [templateHolder];linarith + have haη (i : ι) : |templateInverse 1 θ i-templateInverse 1 η i| ≤ dist θ η := by + simpa only [templateInverse,one_mul] using template_coord_dist θ η (none,i) + refine ⟨h1,h3,h2,h4,?_,?_⟩ + · intro M + cases l with + | diag k => + change opNorm (diagonal (templateDiagonal D θ k)-diagonal (templateDiagonal D η k)) ≤ _ + rw [Matrix.diagonal_sub] + apply (opNorm_diagonal_le (show 0 ≤ 2*D*dist θ η by positivity) (fun i=>?_)).trans + · change 2*D*dist θ η ≤ templateHolder f R j D*sqrt (dist θ η) + have hp := parameter_sqrt_small dist_nonneg hδ1 + have hH := wordHolderScale_ge_one f R 1 hj + have hh : 2*D ≤ templateHolder f R j D := by dsimp [templateHolder];linarith + exact mul_le_mul hh hp dist_nonneg (templateHolder_nonneg f hj hD) + · have he : templateDiagonal D θ k i-templateDiagonal D η k i= + (2*D)*((θ (some k,i):ℝ)-(η (some k,i):ℝ)) := by dsimp [templateDiagonal];ring + rw [he,abs_mul,abs_of_nonneg (by positivity : 0 ≤ 2*D)] + exact mul_le_mul_of_nonneg_left (template_coord_dist θ η (some k,i)) (by positivity) + | noise => + simp only [WordTemplateLetter.realize,WordLetter.eval,sub_self,opNorm,map_zero,norm_zero] + exact Δ.coe_nonneg + | inverse => + have hh := WordLetter.eval_pair f hR hj zero_le_one hD dist_nonneg hδ1 + (fun i=>(ha θ i).1) (fun i=>(ha η i).1) (fun i=>(ha θ i).2) (fun i=>(ha η i).2) + haη WordLetter.inverse WordLetter.inverse trivial trivial trivial + exact (hh.parameter M).trans (mul_le_mul_of_nonneg_right hlarge (sqrt_nonneg _)) + · cases l with + | diag k => + exact (LipschitzWith.const (diagonal (templateDiagonal D θ k)-diagonal (templateDiagonal D η k))).weaken (show (0:NNReal) ≤ Δ from zero_le) + | noise => + simpa only [WordTemplateLetter.realize,WordLetter.eval,sub_self] using + (LipschitzWith.const (0:Matrix ι ι ℝ)).weaken (show (0:NNReal) ≤ Δ from zero_le) + | inverse => + have hh := WordLetter.eval_pair f hR hj zero_le_one hD dist_nonneg hδ1 + (fun i=>(ha θ i).1) (fun i=>(ha η i).1) (fun i=>(ha θ i).2) (fun i=>(ha η i).2) + haη WordLetter.inverse WordLetter.inverse trivial trivial trivial + exact hh.increment.weaken (show (⟨wordHolderScale f R j 1*sqrt (dist θ η),mul_nonneg (zero_le_one.trans (wordHolderScale_ge_one f R 1 hj)) (sqrt_nonneg _)⟩:NNReal) ≤ Δ from + mul_le_mul_of_nonneg_right hlarge (sqrt_nonneg _)) + +theorem templateMatrix_increments [Nonempty ι] (f : 𝓢(ℝ,ℂ)) {R j D : ℝ} + (hR : 0 ≤ R) (hj : 0 ≤ j) (hD : 0 ≤ D) (F : List (WordTemplateLetter m)) (θ η : WordParameter m ι) : + let B : NNReal := ⟨actualWordBound f R j 1 D,(actualWordBound_pos f hR hj zero_le_one hD).le⟩ + let Δ : NNReal := ⟨templateHolder f R j D*sqrt (dist θ η),mul_nonneg (templateHolder_nonneg f hj hD) (sqrt_nonneg _)⟩ + (∀ M,opNorm (templateMatrix f R hR j D F θ M-templateMatrix f R hR j D F η M) ≤ + (wordParameterCoeff B F.length:ℝ)*Δ) ∧ + LipschitzWith (wordMixedCoeff B F.length*Δ) (fun M=>templateMatrix f R hR j D F θ M-templateMatrix f R hR j D F η M) := by + intro B Δ + let G := F.map (fun l=>((l.realize D θ).eval f R hR j (templateInverse 1 θ) 1, + (l.realize D η).eval f R hR j (templateInverse 1 η) 1)) + have hG : ∀ p∈G,MatrixFactorPairBounds B Δ p.1 p.2 := by + intro p hp + obtain ⟨l,hl,rfl⟩ := List.mem_map.mp hp + exact templateFactor_pair f hR hj hD θ η l + simpa only [G,List.length_map,List.map_map,Function.comp_def,templateMatrix,actualWord,templateWord] using! matrixWord_pair_increments G hG +end SKGap +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/GeneratorNonposMax.lean b/lean/OAI/Probability/SKGap/Localization/GeneratorNonposMax.lean new file mode 100644 index 0000000000000000000000000000000000000000..7574f0a63c6345e9d0687a13efd4b4fca2bada81 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/GeneratorNonposMax.lean @@ -0,0 +1,186 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.Centered +import OAI.Probability.SKGap.Localization.ExpDrift +import OAI.Probability.SKGap.Localization.BilinearCoefficient + +namespace OAI + +section +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open scoped BigOperators +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open scoped BigOperators +open scoped BigOperators NNReal ENNReal +open MeasureTheory Metric Set +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators NNReal ENNReal Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Set +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators ENNReal NNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Matrix +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators ENNReal NNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal +open scoped BigOperators +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise NNReal ENNReal +open scoped BigOperators +open Filter Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal Topology +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Set Matrix +open scoped BigOperators NNReal ENNReal Matrix.Norms.L2Operator +namespace SKGapCutoff + +lemma generator_nonpos_of_max {n : ℕ} (J : Interaction n) (f : Observables n) + (x : Spin n) (hx : ∀ y, f y ≤ f x) : generator J f x ≤ 0 := by + rw [generator_flip] + apply Finset.sum_nonpos + intro i _ + apply mul_nonpos_of_nonneg_of_nonpos + · exact flipRate_nonneg J x i + · exact sub_nonpos.mpr (hx _) + +lemma eigen_gradient_nonzero {n : ℕ} (J : Interaction n) + (hJ : ∀ i j, J i j=J j i) (hdiag : ∀ i, J i i=0) + (a : Fin (Fintype.card (Spin n))) (ha : 0 < spinEigenvalues J hJ hdiag a) : + ∃ x, 0 < vectorSquare (fun y i => halfDiff i (scalarEigenfunction J hJ hdiag a) y) x := by + let f := scalarEigenfunction J hJ hdiag a + by_contra! h + have hz (i : Fin n) (x : Spin n) : halfDiff i f x=0 := by + have hs := (Finset.single_le_sum (fun j _ => sq_nonneg (halfDiff j f x)) + (Finset.mem_univ i)).trans (h x) + nlinarith [sq_nonneg (halfDiff i f x)] + have hf (x : Spin n) : f x=0 := by + have he := congrFun (generator_scalarEigenfunction J hJ hdiag a) x + have he0 : generator J f x=0 := by simp only [generator,hz,mul_zero,Finset.sum_const_zero] + change generator J f x = -spinEigenvalues J hJ hdiag a*f x at he + rw [he0] at he + exact (mul_eq_zero.mp he.symm).resolve_left (neg_ne_zero.mpr ha.ne') + have hnorm := scalarEigenfunction_inner_self J hJ hdiag a + change stationaryInner J f f=1 at hnorm + simp only [stationaryInner,gibbsExpectation,hf,mul_zero,Finset.sum_const_zero] at hnorm + norm_num at hnorm + +theorem hasGap_of_gradient_square {n : ℕ} (J : Interaction n) + (hJ : ∀ i j, J i j=J j i) (hdiag : ∀ i, J i i=0) (C : ℝ) + (hC : ∀ (p : VectorFields n) x, + (∑ i, 2*p x i*gradientGenerator J p x i) - generator J (vectorSquare p) x ≤ + -2*C*vectorSquare p x) : HasGap J C := by + apply hasGap_of_positive_eigenvalues J hJ hdiag C + intro a ha + let f := scalarEigenfunction J hJ hdiag a + let p : VectorFields n := fun x i => halfDiff i f x + obtain ⟨x,hxpos⟩ := eigen_gradient_nonzero J hJ hdiag a ha + obtain ⟨y,_,hy⟩ := Finset.exists_max_image Finset.univ (vectorSquare p) + (Finset.univ_nonempty : (Finset.univ : Finset (Spin n)).Nonempty) + have hymax : ∀ z, vectorSquare p z ≤ vectorSquare p y := fun z => hy z (Finset.mem_univ z) + have hyp : 0 < vectorSquare p y := hxpos.trans_le (hymax x) + have he (z : Spin n) (i : Fin n) : gradientGenerator J p z i = + -spinEigenvalues J hJ hdiag a*p z i := by + rw [← halfDiff_generator] + rw [generator_scalarEigenfunction] + change halfDiff i (fun x => -spinEigenvalues J hJ hdiag a*f x) z = _ + simp only [halfDiff,p] + ring + have hs := hC p y + simp_rw [he] at hs + have he' : (∑ i, 2*p y i*(-spinEigenvalues J hJ hdiag a*p y i)) = + -2*spinEigenvalues J hJ hdiag a*vectorSquare p y := by + simp only [vectorSquare,Finset.mul_sum] + apply Finset.sum_congr rfl + intro i _ + ring + rw [he'] at hs + have hg := generator_nonpos_of_max J (vectorSquare p) y hymax + nlinarith + +theorem hasGap_of_opNorm {n : ℕ} (J : Interaction n) + (hJ : ∀ i j, J i j=J j i) (hdiag : ∀ i, J i i=0) + (C : ℝ) (hC : 0 ≤ C) + (hJC : ‖Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) J‖ ≤ C) : + HasGap J (1-C-4*C^2-4*Real.exp (8*C)*C^2) := by + apply hasGap_of_gradient_square J hJ hdiag + intro p x + have hs := RandomMatrix.rough_square_of_opNorm J hJ C hC hJC p x + have hd := vectorDissipation_nonneg J p x + nlinarith + +end SKGapCutoff + +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/GramColumnBounds.lean b/lean/OAI/Probability/SKGap/Localization/GramColumnBounds.lean new file mode 100644 index 0000000000000000000000000000000000000000..6a84e87891ef14b943175ebc4903b27914ffd10a --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/GramColumnBounds.lean @@ -0,0 +1,94 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.BilinearUnion + +namespace OAI + +section +noncomputable section +namespace SKGap +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius +variable {ι κ : Type*} [Fintype ι] [Fintype κ] + +lemma frobenius_le_card_bound {M : Matrix κ κ ℝ} {ε : ℝ} (hε : 0 ≤ ε) + (hM : ∀ i k,|M i k| ≤ ε) : ‖M‖ ≤ (Fintype.card κ:ℝ)*ε := by + rw [Matrix.frobenius_norm_def] + simp only [Real.rpow_two] + rw [← Real.sqrt_eq_rpow] + apply Real.sqrt_le_iff.mpr + refine ⟨by positivity,?_⟩ + calc + _ ≤ ∑ _i : κ,∑ _k : κ, ε^2 := by + apply Finset.sum_le_sum; intro i _ + apply Finset.sum_le_sum; intro k _ + rw [Real.norm_eq_abs] + exact (sq_le_sq₀ (abs_nonneg _) hε).mpr (hM i k) + _ = _ := by simp; ring + +def extendColumns (p : κ → ι → ℝ) (N : ι → ℝ) : Matrix ι (κ ⊕ Unit) ℝ := + fun i k => Sum.elim (fun r => p r i) (fun _ => N i) k + +omit [Fintype κ] in +lemma gram_entry (G : Matrix ι ι ℝ) (V : Matrix ι κ ℝ) (r s : κ) : + (Vᵀ*G*V) r s=matrixPair G (fun i => V i r) (fun i => V i s) := by + simp only [Matrix.mul_apply,Matrix.transpose_apply,matrixPair,Matrix.mulVec, dotProduct, + Finset.sum_mul,Finset.mul_sum] + rw [Finset.sum_comm] + apply Finset.sum_congr rfl; intro i _ + apply Finset.sum_congr rfl; intro k _ + ring + +theorem augmented_gram_error [DecidableEq ι] [DecidableEq κ] {G W : Matrix ι ι ℝ} + (hG : Gᵀ=G) (hW : Wᵀ=W) (A : Matrix ι ι ℝ) {B ε : ℝ} + (hB : 0 < B) (hε : 0 ≤ ε) (p : κ → ι → ℝ) (u : ι → ℝ) (hu : u⬝ᵥu=1) + (h00 : ∀ r s,|matrixPair (G-A) (p r) (p s)| ≤ ε) + (h0u : ∀ r,|matrixPair (G-A) (p r) u| ≤ ε) + (h1u : ∀ r,|matrixPair (G*W-B • A) (p r) u| ≤ ε) + (h0 : |matrixPair (G-A) u u| ≤ ε) + (h1 : |matrixPair (G*W-B • A) u u| ≤ ε) + (h2 : |matrixPair (W*G*W-B • 1-B^2 • A) u u| ≤ ε) : + let V := extendColumns p (residualGramVector B W u) + ‖Vᵀ*G*V-fromBlocks (fun r s => matrixPair A (p r) (p s)) 0 0 (1 : Matrix Unit Unit ℝ)‖ ≤ + ((Fintype.card κ:ℝ)+1)* + (ε+(sqrt B)⁻¹*(1+B)*ε+B⁻¹*(1+2*B+B^2)*ε) := by + dsimp only + have hx (r : κ) := centered_gram_mixed_bound G W A hB (p r) u (h0u r) (h1u r) + have hn := centered_gram_diagonal_bound hG hW A hB u hu h0 h1 h2 + let e₁ := (sqrt B)⁻¹*(1+B)*ε + let e₂ := B⁻¹*(1+2*B+B^2)*ε + have he₁ : 0 ≤ e₁ := by dsimp [e₁]; positivity + have he₂ : 0 ≤ e₂ := by dsimp [e₂]; positivity + have hεle : ε ≤ ε+e₁+e₂ := (le_add_of_nonneg_right he₁).trans (le_add_of_nonneg_right he₂) + have he₁le : e₁ ≤ ε+e₁+e₂ := (le_add_of_nonneg_left hε).trans (le_add_of_nonneg_right he₂) + have he₂le : e₂ ≤ ε+e₁+e₂ := le_add_of_nonneg_left (add_nonneg hε he₁) + have hall : ∀ r s : κ ⊕ Unit, + |((extendColumns p (residualGramVector B W u))ᵀ*G*extendColumns p (residualGramVector B W u)- + fromBlocks (fun r s => matrixPair A (p r) (p s)) 0 0 (1 : Matrix Unit Unit ℝ)) r s| ≤ ε+e₁+e₂ := by + intro r s + rw [Matrix.sub_apply,gram_entry] + cases r with + | inl r => cases s with + | inl s => + change |matrixPair G (p r) (p s)-matrixPair A (p r) (p s)| ≤ ε+e₁+e₂ + rw [← matrixPair_sub] + exact (h00 r s).trans hεle + | inr s => + change |matrixPair G (p r) (residualGramVector B W u)-0| ≤ ε+e₁+e₂ + rw [sub_zero] + exact (hx r).trans he₁le + | inr r => cases s with + | inl s => + change |matrixPair G (residualGramVector B W u) (p s)-0| ≤ ε+e₁+e₂ + rw [sub_zero,matrixPair_symm hG] + exact (hx s).trans he₁le + | inr s => + cases r; cases s + change |matrixPair G (residualGramVector B W u) (residualGramVector B W u)-1| ≤ ε+e₁+e₂ + exact hn.trans he₂le + convert frobenius_le_card_bound (by positivity : 0 ≤ ε+e₁+e₂) hall using 1 + simp only [Fintype.card_sum,Fintype.card_unique,Nat.cast_add,Nat.cast_one,e₁,e₂] +end SKGap +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/GramRobust.lean b/lean/OAI/Probability/SKGap/Localization/GramRobust.lean new file mode 100644 index 0000000000000000000000000000000000000000..f2542f317c7d1d2991ce960c196381234cbfe0d4 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/GramRobust.lean @@ -0,0 +1,95 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.FiniteRankPositive + +namespace OAI + +section +noncomputable section +namespace SKGap +open Matrix Set Filter +open scoped Topology Matrix.Norms.Frobenius + +end SKGap + +namespace SKGap +open Matrix Set Filter +open scoped Topology Matrix.Norms.Frobenius + +lemma positive_from_gram_path {ι κ : Type*} [Fintype ι] [DecidableEq ι] + [Fintype κ] [DecidableEq κ] {a d : ℝ} (ha : 0 ≤ a) (hd : 0 < d) + (Q : Matrix ι κ ℝ) (C : ℝ → Matrix κ κ ℝ) (hc : Continuous C) + (hherm : ∀ r ∈ Icc 0 a, (C r).IsHermitian) (hz : C 0=0) + (hdet : ∀ r ∈ Icc 0 a, (1-(d⁻¹ • (Qᵀ*Q)) * C r).det ≠ 0) : + (d • (1 : Matrix ι ι ℝ)-Q*C a*Qᵀ).PosDef := by + apply matrix_path_posDef ha (fun r => d • (1 : Matrix ι ι ℝ)-Q*C r*Qᵀ) + · fun_prop + · intro r hr + apply (Matrix.isHermitian_one.smul (R := ℝ) (isSelfAdjoint_iff.mpr (star_trivial d))).sub + simpa only [Matrix.conjTranspose_eq_transpose_of_trivial] using + Matrix.isHermitian_mul_mul_conjTranspose Q (hherm r hr) + · intro r hr + have hid : d • (1 : Matrix ι ι ℝ)-Q*C r*Qᵀ = + d • (1-((d⁻¹ • Q)*C r)*Qᵀ) := by + simp only [smul_sub,Matrix.smul_mul,smul_smul,mul_inv_cancel₀ hd.ne',one_smul] + rw [hid,Matrix.det_smul] + apply mul_ne_zero (pow_ne_zero _ hd.ne') + rw [Matrix.det_one_sub_mul_comm,← Matrix.mul_assoc,Matrix.mul_smul,← Matrix.smul_mul] + simpa only [Matrix.smul_mul] using hdet r hr + · simpa only [hz,Matrix.mul_zero,Matrix.zero_mul,sub_zero] using + (Matrix.PosDef.one : (1 : Matrix ι ι ℝ).PosDef).smul hd + +theorem limiting_gram_robust {j b e s : ℝ} + (hj : 0 < j) (hj1 : j < 1) (hb1 : b ≤ 1) (he : 0 ≤ e) : + ∃ δ ρ : ℝ, 0 < δ ∧ δ < 1 ∧ 0 < ρ ∧ + ∀ (ι : Type) [Fintype ι] [DecidableEq ι] (Q : Matrix ι (Fin 3) ℝ) + (C : Matrix (Fin 3) (Fin 3) ℝ), C.IsHermitian → + dist (Qᵀ*Q) (limitingGram b e s) < ρ → + dist C (rankCoefficient j b s) < ρ → + ((1-δ) • (1 : Matrix ι ι ℝ)-Q*C*Qᵀ).PosDef := by + let H := limitingGram b e s + let C₀ := rankCoefficient j b s + let F := fun (p : ℝ × (Matrix (Fin 3) (Fin 3) ℝ × Matrix (Fin 3) (Fin 3) ℝ)) (r : ℝ) => + (1-((1-p.1)⁻¹ • p.2.1) * + (rankCoefficient r b s+(r/j) • (p.2.2-C₀))).det + have hnear : ∀ᶠ p in 𝓝 (0,(H,C₀)), ∀ r ∈ Icc 0 j, F p r ≠ 0 := by + apply isCompact_Icc.eventually_forall_of_forall_eventually + intro r hr + have hbase : F (0,(H,C₀)) r ≠ 0 := by + simp only [F,sub_zero,inv_one,one_smul,sub_self,smul_zero,add_zero,H] + rw [limiting_rank_determinant] + have hrb : r*b < 1 := lt_of_le_of_lt (mul_le_of_le_one_right hr.1 hb1) (hr.2.trans_lt hj1) + have hre : 0 ≤ r*e := mul_nonneg hr.1 he + exact ne_of_gt (mul_pos (by nlinarith) (sq_pos_of_pos (by linarith))) + have hc : ContinuousAt (fun z => F z.1 z.2) ((0,(H,C₀)),r) := by + unfold F rankCoefficient + fun_prop (disch := norm_num) + exact hc.eventually (eventually_ne_nhds hbase) + obtain ⟨ε,hε,hball⟩ := Metric.eventually_nhds_iff.mp hnear + let δ := min (ε/2) (1/2) + have hδ : 0 < δ := lt_min (half_pos hε) (by norm_num) + have hδ1 : δ < 1 := (min_le_right _ _).trans_lt (by norm_num) + have hδε : δ < ε := (min_le_left _ _).trans_lt (half_lt_self hε) + refine ⟨δ,ε,hδ,hδ1,hε,?_⟩ + intro ι _ _ Q C hC hQ hCC + have hin : dist (δ,(Qᵀ*Q,C)) (0,(H,C₀)) < ε := by + simp only [Prod.dist_eq,dist_zero_right,Real.norm_eq_abs,abs_of_pos hδ,max_lt_iff] + exact ⟨hδε,hQ,hCC⟩ + have hh := hball hin + let D := fun r => rankCoefficient r b s+(r/j) • (C-C₀) + have hc : Continuous D := by unfold D rankCoefficient; fun_prop + have hhD : ∀ r ∈ Icc 0 j, (D r).IsHermitian := by + intro r _ + exact (rankCoefficient_hermitian r b s).add + ((hC.sub (rankCoefficient_hermitian j b s)).smul (R := ℝ) (isSelfAdjoint_iff.mpr (star_trivial (r/j)))) + have hz : D 0=0 := by + ext i k; fin_cases i <;> fin_cases k <;> simp [D,rankCoefficient] + have heq : D j=C := by simp [D,C₀,div_self hj.ne'] + rw [← heq] + apply positive_from_gram_path hj.le (sub_pos.mpr hδ1) Q D hc hhD hz + intro r hr + exact hh r hr +end SKGap +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/GramUniformRobust.lean b/lean/OAI/Probability/SKGap/Localization/GramUniformRobust.lean new file mode 100644 index 0000000000000000000000000000000000000000..732b2a8bf663562ed89ec597ff499d0bb344ad78 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/GramUniformRobust.lean @@ -0,0 +1,170 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.GramRobust + +namespace OAI + +section +noncomputable section +namespace SKGap +open Matrix Set Filter +open scoped Topology Matrix.Norms.Frobenius + +theorem compact_gram_path_robust {α κ : Type*} [TopologicalSpace α] [CompactSpace α] + [Fintype κ] [DecidableEq κ] {a : ℝ} (ha : 0 < a) + (H : α → Matrix κ κ ℝ) (C₀ : α → ℝ → Matrix κ κ ℝ) + (hH : Continuous H) (hc₀ : Continuous (Function.uncurry C₀)) + (hherm : ∀ x r, r ∈ Icc 0 a → (C₀ x r).IsHermitian) + (hzero : ∀ x, C₀ x 0=0) + (hdet : ∀ x r, r ∈ Icc 0 a → (1-H x*C₀ x r).det ≠ 0) : + ∃ δ ρ : ℝ, 0 < δ ∧ δ < 1 ∧ 0 < ρ ∧ + ∀ x (ι : Type) [Fintype ι] [DecidableEq ι] (Q : Matrix ι κ ℝ) + (C : Matrix κ κ ℝ), C.IsHermitian → ‖Qᵀ*Q-H x‖ < ρ → + ‖C-C₀ x a‖ < ρ → ((1-δ) • (1 : Matrix ι ι ℝ)-Q*C*Qᵀ).PosDef := by + let F := fun (p : ℝ × (Matrix κ κ ℝ × Matrix κ κ ℝ)) (z : α × ℝ) => + (1-((1-p.1)⁻¹ • (H z.1+p.2.1)) * (C₀ z.1 z.2+(z.2/a) • p.2.2)).det + have hnear : ∀ᶠ p in 𝓝 (0,(0,0)), ∀ z ∈ (univ : Set α) ×ˢ Icc 0 a, F p z ≠ 0 := by + apply (isCompact_univ.prod isCompact_Icc).eventually_forall_of_forall_eventually + intro z hz + have hbase : F (0,(0,0)) z ≠ 0 := by + simpa only [F,sub_zero,inv_one,one_smul,smul_zero,add_zero] using hdet z.1 z.2 hz.2 + have hc : ContinuousAt (fun z => F z.1 z.2) ((0,(0,0)),z) := by + unfold F + have hc' : Continuous (fun z : (ℝ × (Matrix κ κ ℝ × Matrix κ κ ℝ)) × (α × ℝ) => + C₀ z.2.1 z.2.2) := hc₀.comp continuous_snd + fun_prop (disch := norm_num) + exact hc.eventually (eventually_ne_nhds hbase) + obtain ⟨ε,hε,hball⟩ := Metric.eventually_nhds_iff.mp hnear + let δ := min (ε/2) (1/2) + have hδ : 0 < δ := lt_min (half_pos hε) (by norm_num) + have hδ1 : δ < 1 := (min_le_right _ _).trans_lt (by norm_num) + have hδε : δ < ε := (min_le_left _ _).trans_lt (half_lt_self hε) + refine ⟨δ,ε,hδ,hδ1,hε,?_⟩ + intro x ι _ _ Q C hC hQ hCC + have hin : dist (δ,(Qᵀ*Q-H x,C-C₀ x a)) (0,(0,0)) < ε := by + simp only [Prod.dist_eq,dist_zero_right,Real.norm_eq_abs,abs_of_pos hδ,max_lt_iff] + exact ⟨hδε,hQ,hCC⟩ + have hh := hball hin + let D := fun r => C₀ x r+(r/a) • (C-C₀ x a) + have hc : Continuous D := by + have hx : Continuous (fun r => C₀ x r) := hc₀.comp (continuous_const.prodMk continuous_id) + unfold D + fun_prop + have hhD : ∀ r ∈ Icc 0 a, (D r).IsHermitian := by + intro r hr + exact (hherm x r hr).add + ((hC.sub (hherm x a ⟨ha.le,le_rfl⟩)).smul (R := ℝ) (isSelfAdjoint_iff.mpr (star_trivial (r/a)))) + have hz : D 0=0 := by simp [D,hzero] + have heq : D a=C := by simp [D,div_self ha.ne'] + rw [← heq] + apply positive_from_gram_path ha.le (sub_pos.mpr hδ1) Q D hc hhD hz + intro r hr + simpa only [F,add_sub_cancel] using hh (x,r) ⟨mem_univ _,hr⟩ +end SKGap +end +end + +section +noncomputable section +namespace SKGap +open Matrix Set Filter +open scoped Topology Matrix.Norms.Frobenius + +variable {κ ν : Type*} [Fintype κ] [DecidableEq κ] [Fintype ν] [DecidableEq ν] + +def augmentedGram (H : Matrix κ κ ℝ) : Matrix (κ ⊕ ν) (κ ⊕ ν) ℝ := + fromBlocks H 0 0 1 + +def augmentedCoefficient (C : Matrix κ κ ℝ) (V : Matrix κ ν ℝ) : + Matrix (κ ⊕ ν) (κ ⊕ ν) ℝ := fromBlocks (C-V*Vᵀ) V Vᵀ 0 + +lemma augmented_determinant (H C : Matrix κ κ ℝ) (V : Matrix κ ν ℝ) : + (1-augmentedGram (ν := ν) H*augmentedCoefficient C V).det=(1-H*C).det := by + have he : (1 : Matrix (κ ⊕ ν) (κ ⊕ ν) ℝ)-augmentedGram H*augmentedCoefficient C V = + fromBlocks (1-H*(C-V*Vᵀ)) (-H*V) (-Vᵀ) 1 := by + simp only [augmentedGram,augmentedCoefficient,Matrix.fromBlocks_multiply] + ext i k + cases i <;> cases k <;> simp [Matrix.one_apply] + rw [he,Matrix.det_fromBlocks_one₂₂] + congr 1 + simp only [Matrix.mul_sub,Matrix.neg_mul,Matrix.mul_neg,neg_neg,Matrix.mul_assoc] + abel + +omit [Fintype κ] [DecidableEq κ] [DecidableEq ν] in +lemma augmentedCoefficient_hermitian {C : Matrix κ κ ℝ} (hC : C.IsHermitian) + (V : Matrix κ ν ℝ) : (augmentedCoefficient C V).IsHermitian := by + apply Matrix.IsHermitian.fromBlocks + · apply hC.sub + simpa only [Matrix.conjTranspose_eq_transpose_of_trivial] using Matrix.isHermitian_mul_conjTranspose_self V + · simp only [Matrix.conjTranspose_eq_transpose_of_trivial] + · exact Matrix.isHermitian_zero + +omit [Fintype κ] [DecidableEq κ] [DecidableEq ν] in +lemma continuous_augmentedCoefficient {α : Type*} [TopologicalSpace α] + {C : α → Matrix κ κ ℝ} {V : α → Matrix κ ν ℝ} (hC : Continuous C) (hV : Continuous V) : + Continuous (fun x => augmentedCoefficient (C x) (V x)) := by + unfold augmentedCoefficient + fun_prop + +omit [Fintype κ] [DecidableEq κ] [DecidableEq ν] in +lemma augmentedCoefficient_zero : augmentedCoefficient (0 : Matrix κ κ ℝ) (0 : Matrix κ ν ℝ)=0 := by + ext i k + cases i <;> cases k <;> simp [augmentedCoefficient] + +end SKGap +end +end + +section +noncomputable section +namespace SKGap +open Matrix Set Filter +open scoped Topology Matrix.Norms.Frobenius + +theorem compact_limiting_augmented_gram_robust {α ν : Type*} + [TopologicalSpace α] [CompactSpace α] [Fintype ν] [DecidableEq ν] + {j : ℝ} (hj : 0 < j) (hj1 : j < 1) (b e s : α → ℝ) + (V : α → Matrix (Fin 3) ν ℝ) (hb : Continuous b) (he : Continuous e) + (hs : Continuous s) (hV : Continuous V) + (hb1 : ∀ x, b x ≤ 1) (he0 : ∀ x, 0 ≤ e x) (hs0 : ∀ x, s x ≠ 0) : + ∃ δ ρ : ℝ, 0 < δ ∧ δ < 1 ∧ 0 < ρ ∧ + ∀ x (ι : Type) [Fintype ι] [DecidableEq ι] (Q : Matrix ι ((Fin 3) ⊕ ν) ℝ) + (C : Matrix ((Fin 3) ⊕ ν) ((Fin 3) ⊕ ν) ℝ), C.IsHermitian → + ‖Qᵀ*Q-augmentedGram (limitingGram (b x) (e x) (s x))‖ < ρ → + ‖C-augmentedCoefficient (rankCoefficient j (b x) (s x)) (V x)‖ < ρ → + ((1-δ) • (1 : Matrix ι ι ℝ)-Q*C*Qᵀ).PosDef := by + let H := fun x => augmentedGram (ν := ν) (limitingGram (b x) (e x) (s x)) + let C₀ := fun x r => augmentedCoefficient (rankCoefficient r (b x) (s x)) ((r/j) • V x) + have hH : Continuous H := by + unfold H augmentedGram limitingGram + fun_prop (disch := aesop) + have hC : Continuous (Function.uncurry C₀) := by + apply continuous_augmentedCoefficient + · unfold rankCoefficient + fun_prop (disch := aesop) + · fun_prop + have hherm : ∀ x r, r ∈ Icc 0 j → (C₀ x r).IsHermitian := by + intro x r _ + exact augmentedCoefficient_hermitian (rankCoefficient_hermitian r (b x) (s x)) _ + have hz : ∀ x, C₀ x 0=0 := by + intro x + have hc : rankCoefficient 0 (b x) (s x)=0 := by + ext i k; fin_cases i <;> fin_cases k <;> simp [rankCoefficient] + simp only [C₀,hc,zero_div,zero_smul,augmentedCoefficient_zero] + have hd : ∀ x r, r ∈ Icc 0 j → (1-H x*C₀ x r).det ≠ 0 := by + intro x r hr + change (1-augmentedGram (limitingGram (b x) (e x) (s x))* + augmentedCoefficient (rankCoefficient r (b x) (s x)) ((r/j) • V x)).det ≠ 0 + rw [augmented_determinant,limiting_rank_determinant] + have hrb : r*b x < 1 := lt_of_le_of_lt (mul_le_of_le_one_right hr.1 (hb1 x)) (hr.2.trans_lt hj1) + have hre : 0 ≤ r*e x := mul_nonneg hr.1 (he0 x) + exact ne_of_gt (mul_pos (by nlinarith) (sq_pos_of_pos (by linarith))) + obtain ⟨δ,ρ,hδ,hδ1,hρ,hfinal⟩ := compact_gram_path_robust hj H C₀ hH hC hherm hz hd + refine ⟨δ,ρ,hδ,hδ1,hρ,?_⟩ + intro x ι _ _ Q C hc hq hcc + apply hfinal x ι Q C hc hq + simpa only [C₀,div_self hj.ne',one_smul] using hcc +end SKGap +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/GraphPrediction.lean b/lean/OAI/Probability/SKGap/Localization/GraphPrediction.lean new file mode 100644 index 0000000000000000000000000000000000000000..840f77b2daeab931694381874768ab2672c079d1 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/GraphPrediction.lean @@ -0,0 +1,151 @@ +import Mathlib +import OAI.Probability.SKGap.Matrix.PrimaryMatrix + +namespace OAI + +section + +noncomputable section +open scoped BigOperators +namespace SKGap.Noncrossing.Primary +open Diagram +variable {ι : Type*} [Fintype ι] + +lemma annihilation_diagonal_creation (a : D (ι:=ι)) (v : Space (ι:=ι)) : + annihilation (diagonal a (creation v))=Diagram.mean a • v := by + have he : annihilation.comp ((diagonal a).comp creation)= + Diagram.mean a • (LinearMap.id : Space (ι:=ι)→ₗ[ℝ] Space (ι:=ι)) := by + apply Finsupp.lhom_ext' + intro s + apply LinearMap.ext + intro r + simp [creation,diagonal,annihilation,ket,mul_comm] + exact LinearMap.congr_fun he v + +omit [Fintype ι] in +lemma project_diagonal_creation (a : D (ι:=ι)) (v : Space (ι:=ι)) : + project (diagonal a (creation v))=0 := by + have he : project.comp ((diagonal a).comp creation)= + (0 : Space (ι:=ι)→ₗ[ℝ] D (ι:=ι)) := by + apply Finsupp.lhom_ext' + intro s + apply LinearMap.ext + intro r + simp [creation,diagonal,project,ket] + exact LinearMap.congr_fun he v + +omit [Fintype ι] in +lemma project_creation (v : Space (ι:=ι)) : project (creation v)=0 := by + have he : project.comp creation=(0 : Space (ι:=ι)→ₗ[ℝ] D (ι:=ι)) := by + apply Finsupp.lhom_ext' + intro s + apply LinearMap.ext + intro r + simp [creation,project,ket] + exact LinearMap.congr_fun he v + +namespace Graph +variable {α : Type*} [Fintype α] + +def sumWords (P : α→WordPolynomial (ι:=ι)) : WordPolynomial (ι:=ι) := + (Finset.univ.toList.map P).flatten + +lemma polynomialOperator_sumWords (j : ℝ) (P : α→WordPolynomial (ι:=ι)) : + polynomialOperator j (sumWords P)=∑ a,polynomialOperator j (P a) := by + simp [sumWords,polynomialOperator,List.map_flatten,List.map_map,Function.comp_def] + +lemma matrixPolynomial_sumWords [DecidableEq ι] (J : Matrix ι ι ℝ) (P : α→WordPolynomial (ι:=ι)) : + matrixPolynomial J (sumWords P)=∑ a,matrixPolynomial J (P a) := by + simp [sumWords,matrixPolynomial,List.map_flatten,List.map_map,Function.comp_def] + +abbrev Partials := α→α→D (ι:=ι) + +def sourceWords (p : Partials (ι:=ι) (α:=α)) (H : α→WordPolynomial (ι:=ι)) + (a : α) : WordPolynomial (ι:=ι) := + sumWords (fun d => prependWords [.diag (p a d)] (H d)) +def fieldWords (j : ℝ) (p : Partials (ι:=ι) (α:=α)) + (S T : α→WordPolynomial (ι:=ι)) (a : α) : WordPolynomial (ι:=ι) := + prependWords [.noise] (S a) ++ + sumWords (fun d => scale (-(j*Diagram.mean (p a d))) (T d)) + +def coefficients (j : ℝ) (p : Partials (ι:=ι) (α:=α)) (r : α→ℝ) : + ℕ→(α→WordPolynomial (ι:=ι))×(α→WordPolynomial (ι:=ι)) + | 0 => (fun a => [(r a,[])],fun _ => []) + | 1 => + let H := fun a => prependWords [.noise] [(r a,[])] + (sourceWords p H,H) + | m+2 => + let H := fieldWords j p (coefficients j p r (m+1)).1 (coefficients j p r m).1 + (sourceWords p H,H) + +def sourceOp (j : ℝ) (p : Partials (ι:=ι) (α:=α)) (r : α→ℝ) (m : ℕ) (a : α) := + polynomialOperator j ((coefficients j p r m).1 a) +def fieldOp (j : ℝ) (p : Partials (ι:=ι) (α:=α)) (r : α→ℝ) (m : ℕ) (a : α) := + polynomialOperator j ((coefficients j p r m).2 a) + +lemma sourceOp_zero (j : ℝ) (p : Partials (ι:=ι) (α:=α)) (r : α→ℝ) (a : α) : + sourceOp j p r 0 a=r a • LinearMap.id := by + simp [sourceOp,coefficients,polynomialOperator,word] +lemma fieldOp_zero (j : ℝ) (p : Partials (ι:=ι) (α:=α)) (r : α→ℝ) (a : α) : + fieldOp j p r 0 a=0 := by simp [fieldOp,coefficients,polynomialOperator] +lemma fieldOp_one (j : ℝ) (p : Partials (ι:=ι) (α:=α)) (r : α→ℝ) (a : α) : + fieldOp j p r 1 a=(noise j).comp (sourceOp j p r 0 a) := by + change polynomialOperator j (prependWords [.noise] [(r a,[])])=_ + rw [polynomialOperator_prefix,sourceOp_zero] + simp [polynomialOperator,word,letter] +lemma sourceOp_succ (j : ℝ) (p : Partials (ι:=ι) (α:=α)) (r : α→ℝ) (m : ℕ) (a : α) : + sourceOp j p r (m+1) a=∑ d,(diagonal (p a d)).comp (fieldOp j p r (m+1) d) := by + cases m <;> simp [sourceOp,fieldOp,coefficients,sourceWords,polynomialOperator_sumWords, + polynomialOperator_prefix,word,letter] +lemma fieldOp_add_two (j : ℝ) (p : Partials (ι:=ι) (α:=α)) (r : α→ℝ) (m : ℕ) (a : α) : + fieldOp j p r (m+2) a=(noise j).comp (sourceOp j p r (m+1) a)- + ∑ d,(j*Diagram.mean (p a d)) • sourceOp j p r m d := by + simp only [fieldOp,sourceOp,coefficients,fieldWords,polynomialOperator_append, + polynomialOperator_sumWords,polynomialOperator_prefix,polynomialOperator_scale, + word,letter,LinearMap.comp_id] + ext v s + simp [LinearMap.sub_apply,LinearMap.sum_apply,LinearMap.smul_apply, + Finset.sum_neg_distrib,sub_eq_add_neg] + +theorem field_vacuum (j : ℝ) (p : Partials (ι:=ι) (α:=α)) (r : α→ℝ) (m : ℕ) (a : α) : + fieldOp j p r (m+1) a vacuum=creation (sourceOp j p r m a vacuum) := by + induction m generalizing a with + | zero => simp [fieldOp_one,sourceOp_zero,noise,vacuum] + | succ m ih => + rw [show m+1+1=m+2 by omega,fieldOp_add_two] + simp only [LinearMap.sub_apply,LinearMap.comp_apply,LinearMap.sum_apply, + LinearMap.smul_apply,noise,LinearMap.add_apply] + have hs : annihilation (sourceOp j p r (m+1) a vacuum)= + ∑ d,Diagram.mean (p a d) • sourceOp j p r m d vacuum := by + rw [sourceOp_succ] + simp only [LinearMap.sum_apply,LinearMap.comp_apply,map_sum,ih, + annihilation_diagonal_creation] + rw [hs] + simp only [Finset.smul_sum,smul_smul] + exact add_sub_cancel_right _ _ + +theorem field_prediction_zero (j : ℝ) (p : Partials (ι:=ι) (α:=α)) (r : α→ℝ) + (m : ℕ) (a : α) (i : ι) : + polynomialPrediction j ((coefficients j p r m).2 a) i=0 := by + rw [polynomialPrediction_eq_project] + change project (fieldOp j p r m a vacuum) i=0 + cases m with + | zero => simp [fieldOp_zero] + | succ m => rw [field_vacuum,project_creation]; rfl + +theorem source_prediction_zero (j : ℝ) (p : Partials (ι:=ι) (α:=α)) (r : α→ℝ) + (m : ℕ) (a : α) (i : ι) : + polynomialPrediction j ((coefficients j p r (m+1)).1 a) i=0 := by + rw [polynomialPrediction_eq_project] + change project (sourceOp j p r (m+1) a vacuum) i=0 + rw [sourceOp_succ] + simp only [LinearMap.sum_apply,LinearMap.comp_apply,map_sum,field_vacuum, + project_diagonal_creation,Finset.sum_const_zero,Pi.zero_apply] + +end Graph +end SKGap.Noncrossing.Primary + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/GridSteps.lean b/lean/OAI/Probability/SKGap/Localization/GridSteps.lean new file mode 100644 index 0000000000000000000000000000000000000000..00b3f4def6c8ad72fe93a20d119a01cc010f2953 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/GridSteps.lean @@ -0,0 +1,168 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.CondSubConst + +namespace OAI + +namespace SKGap.GaussianHistory +open Real Filter +open scoped Topology +noncomputable section + +def gridSteps (n : ℕ) : ℕ := (n+1)^4 +def gridStep (T : ℝ) (n : ℕ) : ℝ := T/(gridSteps n:ℝ) + +lemma gridSteps_pos (n : ℕ) : 0((n:ℝ)+1)⁻¹) atTop (𝓝 0) := by + apply Tendsto.inv_tendsto_atTop + exact tendsto_atTop_add_const_right atTop 1 tendsto_natCast_atTop_atTop + +lemma gridStep_tendsto (T : ℝ) : Tendsto (gridStep T) atTop (𝓝 0) := by + change Tendsto (fun n=>gridStep T n) atTop (𝓝 0) + simpa only [gridStep_eq,zero_pow (by decide : 4≠0),mul_zero] using + (tendsto_const_nhds.mul (inv_succ_tendsto.pow 4) : + Tendsto (fun n : ℕ=>T*((n:ℝ)+1)⁻¹^4) atTop (𝓝 (T*0^4))) + +lemma nat_mul_gridStep_tendsto (T : ℝ) : + Tendsto (fun n : ℕ=>(n:ℝ)*gridStep T n) atTop (𝓝 0) := by + have H:=(((tendsto_const_nhds (x:=(1:ℝ))).sub inv_succ_tendsto).mul + (inv_succ_tendsto.pow 3)).const_mul T + have he (n : ℕ) : (n:ℝ)*gridStep T n=T*(1-((n:ℝ)+1)⁻¹)*((n:ℝ)+1)⁻¹^3 := by + rw [gridStep_eq] + field_simp [show (n:ℝ)+1≠0 by positivity] + ring + simpa only [he,sub_zero,zero_pow (by decide : 3≠0),mul_zero,mul_assoc] using H + +lemma nat_sq_mul_gridStep_tendsto (T : ℝ) : + Tendsto (fun n : ℕ=>(n:ℝ)^2*gridStep T n) atTop (𝓝 0) := by + have H:=((((tendsto_const_nhds (x:=(1:ℝ))).sub inv_succ_tendsto).pow 2).mul + (inv_succ_tendsto.pow 2)).const_mul T + have he (n : ℕ) : (n:ℝ)^2*gridStep T n=T*(1-((n:ℝ)+1)⁻¹)^2*((n:ℝ)+1)⁻¹^2 := by + rw [gridStep_eq] + field_simp [show (n:ℝ)+1≠0 by positivity] + ring + simpa only [he,sub_zero,zero_pow (by decide : 2≠0),mul_zero,mul_assoc] using H + +lemma nat_inv_tendsto : Tendsto (fun n : ℕ=>(n:ℝ)⁻¹) atTop (𝓝 0) := + tendsto_natCast_atTop_atTop.inv_tendsto_atTop + +lemma sqrt_div_nat_tendsto : + Tendsto (fun n : ℕ=>sqrt (n:ℝ)/(n:ℝ)) atTop (𝓝 0) := by + have H := (tendsto_sqrt_atTop.comp tendsto_natCast_atTop_atTop).inv_tendsto_atTop + apply H.congr' + filter_upwards [eventually_ge_atTop 1] with n hn + have hp : 0<(n:ℝ) := by exact_mod_cast (show 0localizationLoss n (gridStep T n) W A a b T) atTop + (𝓝 (exp (4*T/a)*T*W/b)) := by + have h1 := (nat_sq_mul_gridStep_tendsto T).const_mul (16*T) + have h2 := ((tendsto_const_nhds (x:=W)).add ((sqrt_div_nat_tendsto.const_mul (2*A)).add + (nat_inv_tendsto.const_mul (4/a)))).const_mul T + have h3 := (nat_mul_gridStep_tendsto T).const_mul (64*T) + have H := (h1.add ((h2.add h3).const_mul (exp (4*T/a)/b))).add + (nat_inv_tendsto.const_mul (1/b)) + have H' : Tendsto (fun n : ℕ=>16*T*((n:ℝ)^2*gridStep T n)+ + exp (4*T/a)/b*(T*(W+(2*A*(sqrt (n:ℝ)/(n:ℝ))+4/a*(n:ℝ)⁻¹))+ + 64*T*((n:ℝ)*gridStep T n))+1/b*(n:ℝ)⁻¹) atTop + (𝓝 (exp (4*T/a)*T*W/b)) := by convert H using 1; ring_nf + apply H'.congr' + filter_upwards [eventually_ge_atTop 1] with n hn + have hp : (n:ℝ)≠0 := by exact_mod_cast (show n≠0 by omega) + unfold localizationLoss + field_simp + ring + +lemma localizationCost_tendsto (A a b D L T : ℝ) : + Tendsto (fun n=>localizationCost n A a b D L T) atTop (𝓝 (D*T+L)) := by + have H := (tendsto_const_nhds (x:=D*T+L)).add (sqrt_div_nat_tendsto.const_mul (exp (4*T/a)*T*A/b)) + convert H using 1 + · ext n + unfold localizationCost + ring + · ring_nf + +theorem localization_numeric_choice (D L T a b : ℝ) (hT : 0(n:ℝ)^k*exp (-a*(n:ℝ))) atTop (𝓝 0) := by + have H := (tendsto_pow_mul_exp_neg_atTop_nhds_zero k).comp + (tendsto_natCast_atTop_atTop.const_mul_atTop ha) + have H' := H.const_mul (a^k)⁻¹ + convert H' using 1 + · ext n + dsimp + rw [mul_pow] + field_simp + · simp + +lemma grid_polynomial_exp_tendsto {a : ℝ} (ha : 0((gridSteps n:ℝ)+1)*exp (-a*(n:ℝ))) atTop (𝓝 0) := by + have H := ((((nat_pow_exp_tendsto ha 4).add ((nat_pow_exp_tendsto ha 3).const_mul 4)).add + ((nat_pow_exp_tendsto ha 2).const_mul 6)).add ((nat_pow_exp_tendsto ha 1).const_mul 4)).add + ((nat_pow_exp_tendsto ha 0).const_mul 2) + convert H using 1 + · ext n + simp only [gridSteps,Nat.cast_pow,Nat.cast_add,Nat.cast_one] + ring + · ring_nf + +lemma grid_exp_absorb {a : ℝ} (ha : 0C*exp (-(a/2)*(n:ℝ))) atTop (𝓝 0) := by + simpa only [pow_zero,one_mul,mul_zero] using (nat_pow_exp_tendsto (half_pos ha) 0).const_mul C + filter_upwards [H.eventually_lt_const zero_lt_one] with n hn + have he : exp (-a*(n:ℝ))= exp (-(a/2)*(n:ℝ))*exp (-(a/2)*(n:ℝ)) := by + rw [← exp_add] + congr 1 + ring + rw [he,← mul_assoc] + exact (mul_le_mul_of_nonneg_right hn.le (exp_pos _).le).trans_eq (one_mul _) + +end +end SKGap.GaussianHistory + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/IntegrableLinearCombinationSq.lean b/lean/OAI/Probability/SKGap/Localization/IntegrableLinearCombinationSq.lean new file mode 100644 index 0000000000000000000000000000000000000000..4780b7309d02fd62a67bde697e8c897724c1e8ff --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/IntegrableLinearCombinationSq.lean @@ -0,0 +1,260 @@ +import Mathlib +import OAI.Probability.SKGap.Entropy.UpperRare + +namespace OAI + +section +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open scoped BigOperators +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open scoped BigOperators +open scoped BigOperators NNReal ENNReal +open MeasureTheory Metric Set +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators NNReal ENNReal Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Set +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators ENNReal NNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Matrix +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators ENNReal NNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal +open scoped BigOperators +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise NNReal ENNReal +open scoped BigOperators +open Filter Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal Topology +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +namespace SKGapCutoff.Regression + +lemma integrable_linear_combination_sq + {E ι : Type*} [MeasurableSpace E] [Fintype ι] {ν : Measure E} + (f : ι → E → ℝ) (c : ι → ℝ) + (hm : ∀ i, AEStronglyMeasurable (f i) ν) + (hi : ∀ i, Integrable (fun x => f i x^2) ν) : + Integrable (fun x => (∑ i, c i*f i x)^2) ν := by + have hpoint x : (∑ i, c i*f i x)^2 = ∑ i, ∑ j, c i*(f i x*f j x)*c j := by + simp only [pow_two, Finset.sum_mul, Finset.mul_sum] + apply Finset.sum_congr rfl + intro i _ + apply Finset.sum_congr rfl + intro j _ + ring + simp_rw [hpoint] + apply integrable_finsetSum + intro i _ + apply integrable_finsetSum + intro j _ + exact ((integrable_mul_of_sq (hm i) (hm j) (hi i) (hi j)).const_mul (c i)).mul_const (c j) + +theorem ExponentialEmpiricalConcentration.unbounded_linear_energy + {E : Type*} [PseudoMetricSpace E] [MeasurableSpace E] [BorelSpace E] + [SecondCountableTopology E] + {H : ℕ → Type*} [∀ n, MeasurableSpace (H n)] + {ρ : ∀ n, Measure (H n)} {X : ∀ n, H n → Fin n → E} + {ν : Measure E} [IsProbabilityMeasure ν] + (hX : ExponentialEmpiricalConcentration ρ X ν) + {ι : Type*} [Fintype ι] (f : ι → E → ℝ) {K : ℝ≥0} + (hf : ∀ i, LipschitzWith K (f i)) + (hT : ∀ j, ExponentialSquareTails ρ (fun n h i => f j (X n h i))) + (hi : ∀ j, Integrable (fun x => f j x^2) ν) + (C : ∀ n, H n → ι → ℝ) (c : ι → ℝ) (hC : ExponentialConvergence ρ C c) : + ExponentialConvergence ρ (fun n h => (∑ i, (∑ j, C n h j*f j (X n h i))^2)/(n:ℝ)) + (∫ x, (∑ j, c j*f j x)^2 ∂ν) := by + have hh := hX.append_unbounded_linear f hf hT hi C c hC + let φ : E → E × ℝ := fun x => (x,∑ j, c j*f j x) + have hφ : Measurable φ := (append_linear_combination_lipschitz f hf c).continuous.measurable + have hiφ : Integrable (fun z : E × ℝ => z.2^2) (ν.map φ) := by + rw [integrable_map_measure (by fun_prop) hφ.aemeasurable] + exact integrable_linear_combination_sq f c (fun i => (hf i).continuous.measurable.aestronglyMeasurable) hi + have hs := hh.1.lipschitz_secondMoment Prod.snd LipschitzWith.prod_snd hh.2 hiφ + rw [integral_map hφ.aemeasurable (by fun_prop)] at hs + exact hs + +theorem ExponentialEmpiricalConcentration.normalized_unbounded_linear + {E : Type*} [PseudoMetricSpace E] [MeasurableSpace E] [BorelSpace E] + [SecondCountableTopology E] + {H : ℕ → Type*} [∀ n, MeasurableSpace (H n)] + {ρ : ∀ n, Measure (H n)} {X : ∀ n, H n → Fin n → E} + {ν : Measure E} [IsProbabilityMeasure ν] + (hX : ExponentialEmpiricalConcentration ρ X ν) + {ι : Type*} [Fintype ι] (f : ι → E → ℝ) {K : ℝ≥0} + (hf : ∀ i, LipschitzWith K (f i)) + (hT : ∀ j, ExponentialSquareTails ρ (fun n h i => f j (X n h i))) + (hi : ∀ j, Integrable (fun x => f j x^2) ν) + (C : ∀ n, H n → ι → ℝ) (c : ι → ℝ) (hC : ExponentialConvergence ρ C c) + (hs : 0 < ∫ x, (∑ j, c j*f j x)^2 ∂ν) : + let S := fun n h => (∑ i, (∑ j, C n h j*f j (X n h i))^2)/(n:ℝ) + let s := ∫ x, (∑ j, c j*f j x)^2 ∂ν + ExponentialConvergence ρ S s ∧ + ExponentialEmpiricalConcentration ρ + (fun n h i => (X n h i,(∑ j, C n h j*f j (X n h i))/Real.sqrt (S n h))) + (ν.map (fun x => (x,(∑ j, c j*f j x)/Real.sqrt s))) ∧ + ExponentialSquareTails ρ + (fun n h i => (∑ j, C n h j*f j (X n h i))/Real.sqrt (S n h)) := by + let S := fun n h => (∑ i, (∑ j, C n h j*f j (X n h i))^2)/(n:ℝ) + let s := ∫ x, (∑ j, c j*f j x)^2 ∂ν + have hS : ExponentialConvergence ρ S s := hX.unbounded_linear_energy f hf hT hi C c hC + have hc : ContinuousAt (fun z : (ι → ℝ) × ℝ => fun j => z.1 j/Real.sqrt z.2) (c,s) := by + apply continuousAt_pi.mpr + intro j + exact ((continuous_apply j).comp continuous_fst).continuousAt.div + (Real.continuous_sqrt.comp continuous_snd).continuousAt (ne_of_gt (Real.sqrt_pos.mpr hs)) + have hcoeff := (hC.prod hS).continuous_map hc + have hh := hX.append_unbounded_linear f hf hT hi _ _ hcoeff + simp only [div_mul_eq_mul_div, ← Finset.sum_div] at hh + exact ⟨hS,hh⟩ + +end SKGapCutoff.Regression + +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology + +namespace SKGapCutoff.Regression + +lemma revealedCompletion_mulVec {n r : ℕ} (U Y : Matrix (Fin n) (Fin r) ℝ) + (v : Fin n → ℝ) : + revealedCompletion U Y *ᵥ v = Y *ᵥ (Uᵀ *ᵥ v)+U *ᵥ (Yᵀ *ᵥ v) - + U *ᵥ ((Uᵀ*Y) *ᵥ (Uᵀ *ᵥ v)) := by + simp only [revealedCompletion, Matrix.add_mulVec, Matrix.sub_mulVec, Matrix.mulVec_mulVec, Matrix.mul_assoc] + +lemma revealedCompletion_perpendicular {n r : ℕ} (U Y : Matrix (Fin n) (Fin r) ℝ) + (q : Fin n → ℝ) (hq : Uᵀ *ᵥ q = 0) : + revealedCompletion U Y *ᵥ q = U *ᵥ (Yᵀ *ᵥ q) := by + simp only [revealedCompletion_mulVec, hq, Matrix.mulVec_zero, zero_add, sub_zero] + +lemma queryAnswer_mulVec {n : ℕ} (P : Matrix (Fin n) (Fin n) ℝ) + (q : Fin n → ℝ) (g : (Fin n × Fin n) → ℝ) : + queryAnswer P q g = P *ᵥ (goe g *ᵥ q) := by + rw [Matrix.mulVec_mulVec] + ext i + simp only [queryAnswer, Matrix.mul_apply, queryColumn, + Matrix.mulVec, dotProduct] + +lemma completed_query_answer {n r : ℕ} (U Y : Matrix (Fin n) (Fin r) ℝ) + (q : Fin n → ℝ) (g : (Fin n × Fin n) → ℝ) (hq : Uᵀ *ᵥ q = 0) + (hPq : residualProjection U *ᵥ q = q) : + (revealedCompletion U Y+residualProjection U*goe g*residualProjection U) *ᵥ q = + U *ᵥ (Yᵀ *ᵥ q)+queryAnswer (residualProjection U) q g := by + rw [Matrix.add_mulVec, revealedCompletion_perpendicular U Y q hq] + simp only [← Matrix.mulVec_mulVec, hPq, queryAnswer_mulVec] + +lemma scaled_query_predictor {n r : ℕ} (hn : 0 < n) + (U Y : Matrix (Fin n) (Fin r) ℝ) (q : Fin n → ℝ) (i : Fin n) : + Real.sqrt n*(U *ᵥ (Yᵀ *ᵥ q)) i = + ∑ a, (Real.sqrt n*U i a)*((∑ j, (Real.sqrt n*Y j a)*(Real.sqrt n*q j))/(n:ℝ)) := by + have hn0 : (n:ℝ) ≠ 0 := Nat.cast_ne_zero.mpr (Nat.ne_of_gt hn) + have hs : (Real.sqrt (n:ℝ))^2 = n := Real.sq_sqrt (Nat.cast_nonneg _) + simp only [Matrix.mulVec, dotProduct, Matrix.transpose_apply, Finset.mul_sum] + apply Finset.sum_congr rfl + intro a _ + rw [Finset.sum_div, Finset.mul_sum] + apply Finset.sum_congr rfl + intro j _ + field_simp + nlinarith [congrArg (fun z : ℝ => z*(U i a*Y j a*q j)) hs] + +def extendFrame {n r : ℕ} (U : Matrix (Fin n) (Fin r) ℝ) (q : Fin n → ℝ) : + Matrix (Fin n) (Fin (r+1)) ℝ := fun i => Fin.cons (q i) (U i) + +lemma extendFrame_zero {n r : ℕ} (U : Matrix (Fin n) (Fin r) ℝ) (q : Fin n → ℝ) + (i : Fin n) : extendFrame U q i 0 = q i := rfl + +lemma extendFrame_succ {n r : ℕ} (U : Matrix (Fin n) (Fin r) ℝ) (q : Fin n → ℝ) + (i : Fin n) (a : Fin r) : extendFrame U q i a.succ = U i a := rfl + +lemma extendFrame_orthonormal {n r : ℕ} (U : Matrix (Fin n) (Fin r) ℝ) + (q : Fin n → ℝ) (hU : Uᵀ*U=1) (hq : ∑ i, q i^2=1) (ho : Uᵀ *ᵥ q=0) : + (extendFrame U q)ᵀ*extendFrame U q=1 := by + ext a b + obtain ha | ⟨a, rfl⟩ := Fin.eq_zero_or_eq_succ a + · subst a + obtain hb | ⟨b,rfl⟩ := Fin.eq_zero_or_eq_succ b + · subst b + simpa only [Matrix.mul_apply, Matrix.transpose_apply, extendFrame_zero, + Matrix.one_apply_eq, ← pow_two] using hq + · have hb := congrFun ho b + simpa only [Matrix.mul_apply, Matrix.transpose_apply, extendFrame_zero, + extendFrame_succ, Matrix.one_apply, Ne.symm (Fin.succ_ne_zero b), ↓reduceIte, + Matrix.mulVec, dotProduct, Pi.zero_apply, mul_comm] using hb + · obtain hb | ⟨b,rfl⟩ := Fin.eq_zero_or_eq_succ b + · subst b + have ha := congrFun ho a + simpa only [Matrix.mul_apply, Matrix.transpose_apply, extendFrame_zero, + extendFrame_succ, Matrix.one_apply, Fin.succ_ne_zero, ↓reduceIte, + Matrix.mulVec, dotProduct, Pi.zero_apply] using ha + · have hab := congrFun (congrFun hU a) b + simpa only [Matrix.mul_apply, Matrix.transpose_apply, extendFrame_succ, + Matrix.one_apply, Fin.succ_inj] using hab + +lemma extendFrame_projection {n r : ℕ} (U : Matrix (Fin n) (Fin r) ℝ) + (q : Fin n → ℝ) : + residualProjection (extendFrame U q) = queryComplement (residualProjection U) q := by + ext i j + simp only [residualProjection, Matrix.sub_apply, Matrix.mul_apply, + Matrix.transpose_apply, Fin.sum_univ_succ, extendFrame_zero, extendFrame_succ, + queryComplement_apply] + ring + +end SKGapCutoff.Regression + +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology + +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/IntegrableMulBounded.lean b/lean/OAI/Probability/SKGap/Localization/IntegrableMulBounded.lean new file mode 100644 index 0000000000000000000000000000000000000000..1dcc6f77654fcf0b179d99b84da716577a61d372 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/IntegrableMulBounded.lean @@ -0,0 +1,271 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.StepMass + +namespace OAI + +section +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open scoped BigOperators +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open scoped BigOperators +open scoped BigOperators NNReal ENNReal +open MeasureTheory Metric Set +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators NNReal ENNReal Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Set +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators ENNReal NNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Matrix +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators ENNReal NNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal +open scoped BigOperators +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise NNReal ENNReal +open scoped BigOperators +open Filter Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal Topology +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Set Matrix +open scoped BigOperators NNReal ENNReal Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open Filter MeasureTheory ProbabilityTheory +open scoped Topology NNReal ENNReal +open Filter MeasureTheory ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter +open scoped Topology NNReal ENNReal +open MeasureTheory Filter ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter +open scoped Topology +namespace SKGapCutoff.Clock + +lemma integrable_mul_bounded {f u : ℝ → ℝ} {B : ℝ} (hf : Integrable f) + (hu : AEStronglyMeasurable u) (hb : ∀ x, |u x| ≤ B) : Integrable (fun x => f x*u x) := by + apply (hf.abs.mul_const B).mono' (hf.aestronglyMeasurable.mul hu) + exact Filter.Eventually.of_forall (fun x => by + simpa only [Real.norm_eq_abs,Pi.mul_apply,abs_mul] using mul_le_mul_of_nonneg_left (hb x) (abs_nonneg (f x))) + +lemma pairing_abs_le {f u : ℝ → ℝ} {B : ℝ} (hf : Integrable f) + (hu : AEStronglyMeasurable u) (hb : ∀ x, |u x| ≤ B) : + |∫ x : ℝ, f x*u x| ≤ B*(∫ x : ℝ, |f x|) := by + calc + _ ≤ ∫ x : ℝ, |f x*u x| := abs_integral_le_integral_abs + _ ≤ ∫ x : ℝ, |f x| * B := integral_mono (integrable_mul_bounded hf hu hb).abs + (hf.abs.mul_const B) (fun x => by rw [abs_mul]; exact mul_le_mul_of_nonneg_left (hb x) (abs_nonneg _)) + _ = _ := by rw [integral_mul_const]; ring + +lemma pairing_sub_abs_le {f g u : ℝ → ℝ} {B : ℝ} + (hf : Integrable f) (hg : Integrable g) (hu : AEStronglyMeasurable u) + (hb : ∀ x, |u x| ≤ B) : + |(∫ x : ℝ, f x*u x)-(∫ x : ℝ, g x*u x)| ≤ B*(∫ x : ℝ, |f x-g x|) := by + rw [← integral_sub (integrable_mul_bounded hf hu hb) (integrable_mul_bounded hg hu hb)] + simpa only [Pi.sub_apply,sub_mul] using pairing_abs_le (hf.sub hg) hu hb + +lemma pairing_of_L1_limit {f : ℕ → ℝ → ℝ} {g : ℝ → ℝ} {u : ℕ → ℝ → ℝ} {B : ℝ} + (hf : ∀ᶠ n in atTop, Integrable (f n)) (hg : Integrable g) + (hu : ∀ n, AEStronglyMeasurable (u n)) (hb : ∀ n x, |u n x| ≤ B) + (ht : Tendsto (fun n => ∫ x : ℝ, |f n x-g x|) atTop (𝓝 0)) : + Tendsto (fun n => (∫ x : ℝ, f n x*u n x)-(∫ x : ℝ, g x*u n x)) atTop (𝓝 0) := by + apply squeeze_zero_norm' _ (by simpa using ht.const_mul B) + filter_upwards [hf] with n hn + simpa only [Real.norm_eq_abs] using pairing_sub_abs_le hn hg (hu n) (hb n) + +theorem pairing_of_finite_approximation {ρ : ℝ → ℝ} {φ : ℝ → ℝ → ℝ} + {u : ℕ → ℝ → ℝ} {B : ℝ} + (hρ : Integrable ρ) (hφ : ∀ y, Integrable (φ y)) (hB : 0 < B) + (hu : ∀ n, AEStronglyMeasurable (u n)) (hb : ∀ n x, |u n x| ≤ B) + (ha : ∀ ε : ℝ, 0 < ε → ∃ (s : Finset ℝ) (c : ℝ → ℝ), + (∫ x : ℝ, |ρ x-∑ y ∈ s, c y*φ y x|) < ε) + (ht : ∀ y, Tendsto (fun n => ∫ x : ℝ, φ y x*u n x) atTop (𝓝 0)) : + Tendsto (fun n => ∫ x : ℝ, ρ x*u n x) atTop (𝓝 0) := by + classical + apply Metric.tendsto_atTop.mpr + intro ε hε + obtain ⟨s,c,happrox⟩ := ha (ε/(2*B)) (by positivity) + let F : ℝ → ℝ := fun x => ∑ y ∈ s, c y*φ y x + have hF : Integrable F := integrable_finsetSum s (fun y _ => (hφ y).const_mul (c y)) + have hsum (n : ℕ) : (∫ x : ℝ, F x*u n x) = ∑ y ∈ s, c y*(∫ x : ℝ, φ y x*u n x) := by + unfold F + simp_rw [Finset.sum_mul,mul_assoc] + rw [integral_finsetSum s (fun y _ => (integrable_mul_bounded (hφ y) (hu n) (hb n)).const_mul (c y))] + apply Finset.sum_congr rfl + intro y _ + simp only [integral_const_mul] + have hconv : Tendsto (fun n => ∫ x : ℝ, F x*u n x) atTop (𝓝 0) := by + simp_rw [hsum] + have hh := tendsto_finsetSum s (fun y _ => (ht y).const_mul (c y)) + simpa using hh + obtain ⟨N,hN⟩ := Metric.tendsto_atTop.mp hconv (ε/2) (by positivity) + refine ⟨N,fun n hn => ?_⟩ + have hclose := pairing_sub_abs_le hρ hF (hu n) (hb n) + have hh := hN n hn + simp only [Real.dist_eq,sub_zero] at hh ⊢ + have he : B*(∫ x : ℝ, |ρ x-F x|) < ε/2 := by + have := mul_lt_mul_of_pos_left happrox hB + have he : B*(ε/(2*B))=ε/2 := by field_simp + rwa [he] at this + have htri : |∫ x : ℝ, ρ x*u n x| ≤ + |(∫ x : ℝ, ρ x*u n x)-(∫ x : ℝ, F x*u n x)|+|∫ x : ℝ, F x*u n x| := by + simpa only [Real.norm_eq_abs] using norm_le_norm_sub_add + (∫ x : ℝ, ρ x*u n x) (∫ x : ℝ, F x*u n x) + linarith + +end SKGapCutoff.Clock + +open MeasureTheory Filter ProbabilityTheory +open scoped Topology NNReal ENNReal + +namespace SKGapCutoff.Clock + +lemma measurable_stepMass (p : ℕ → ℝ) : Measurable (stepMass p) := by + unfold stepMass + exact Measurable.tsum (fun _ => measurable_const.indicator measurableSet_Ico) + +lemma stepMass_abs_le {a : ℕ → ℝ} {B : ℝ} (hB : 0 ≤ B) (ha : ∀ j, |a j| ≤ B) + (x : ℝ) : |stepMass a x| ≤ B := by + by_cases hx : 0 ≤ x + · rw [stepMass_of_nonneg _ hx] + exact ha _ + · rw [stepMass_of_neg _ (lt_of_not_ge hx),abs_zero] + exact hB + +lemma stepMass_mul (p a : ℕ → ℝ) (x : ℝ) : + stepMass p x*stepMass a x=stepMass (fun j => p j*a j) x := by + by_cases hx : 0 ≤ x + · simp only [stepMass_of_nonneg _ hx] + · simp only [stepMass_of_neg _ (lt_of_not_ge hx),mul_zero] + +lemma summable_mul_bounded {p a : ℕ → ℝ} {B : ℝ} (hp : Summable p) + (ha : ∀ j, |a j| ≤ B) : Summable (fun j => p j*a j) := by + apply Summable.of_norm_bounded (hp.abs.mul_right B) + intro j + simpa only [Real.norm_eq_abs,abs_mul] using mul_le_mul_of_nonneg_left (ha j) (abs_nonneg (p j)) + +lemma integral_histogram_summable {p : ℕ → ℝ} (hp : Summable p) (q : ℝ) {n : ℕ} + (hn : 0 < n) : ∫ x : ℝ, histogram q n p x = ∑' j, p j := by + have hs : Real.sqrt (n:ℝ) ≠ 0 := by positivity + unfold histogram + rw [integral_const_mul] + have hh : (fun x : ℝ => stepMass p (q*n+x*Real.sqrt n)) = + (fun x : ℝ => (fun t => stepMass p (t+q*n)) (Real.sqrt n*x)) := by + ext x + congr 1 + ring + rw [hh,Measure.integral_comp_mul_left (fun t : ℝ => stepMass p (t+q*n)) + (Real.sqrt (n:ℝ)),integral_add_right_eq_self,integral_stepMass hp,smul_eq_mul, + abs_of_nonneg (inv_nonneg.mpr (Real.sqrt_nonneg _)),← mul_assoc,mul_inv_cancel₀ hs,one_mul] + +noncomputable def testHistogram (q : ℝ) (n : ℕ) (a : ℕ → ℝ) (x : ℝ) : ℝ := + stepMass a (q*n+x*Real.sqrt n) + +lemma measurable_testHistogram (q : ℝ) (n : ℕ) (a : ℕ → ℝ) : + Measurable (testHistogram q n a) := by + apply (measurable_stepMass a).comp + fun_prop + +lemma testHistogram_bound {a : ℕ → ℝ} {B : ℝ} (hB : 0 ≤ B) (ha : ∀ j, |a j| ≤ B) + (q : ℝ) (n : ℕ) (x : ℝ) : |testHistogram q n a x| ≤ B := + stepMass_abs_le hB ha _ + +lemma integral_histogram_test {p a : ℕ → ℝ} {B : ℝ} (hp : Summable p) + (ha : ∀ j, |a j| ≤ B) (q : ℝ) {n : ℕ} (hn : 0 < n) : + (∫ x : ℝ, histogram q n p x*testHistogram q n a x) = ∑' j, p j*a j := by + have he (x : ℝ) : histogram q n p x*testHistogram q n a x = + histogram q n (fun j => p j*a j) x := by + unfold histogram testHistogram + rw [mul_assoc,stepMass_mul] + simp_rw [he] + exact integral_histogram_summable (summable_mul_bounded hp ha) q hn + +end SKGapCutoff.Clock + +open MeasureTheory Filter ProbabilityTheory +open scoped Topology NNReal ENNReal + +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/IntegrableResidualRecipeSq.lean b/lean/OAI/Probability/SKGap/Localization/IntegrableResidualRecipeSq.lean new file mode 100644 index 0000000000000000000000000000000000000000..1e9d2e2551aacb923bba6df57e8857632d076026 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/IntegrableResidualRecipeSq.lean @@ -0,0 +1,254 @@ +import Mathlib +import OAI.Probability.SKGap.Entropy.AdaptiveTrueAffineQuery +import OAI.Probability.SKGap.Matrix.CompletedMatrix +import OAI.Probability.SKGap.Entropy.OrthogonalCoefficients + +namespace OAI + +section +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open scoped BigOperators +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open scoped BigOperators +open scoped BigOperators NNReal ENNReal +open MeasureTheory Metric Set +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators NNReal ENNReal Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Set +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators ENNReal NNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Matrix +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators ENNReal NNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal +open scoped BigOperators +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise NNReal ENNReal +open scoped BigOperators +open Filter Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal Topology +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +namespace SKGapCutoff.Regression + +local instance {n m : ℕ} : MeasurableSpace (Matrix (Fin n) (Fin m) ℝ) := + inferInstanceAs (MeasurableSpace (Fin n → Fin m → ℝ)) + +lemma integrable_residualRecipe_sq {E : Type*} [MeasurableSpace E] + {ν : Measure E} {r : ℕ} (u : Fin r → E → ℝ) (g : E → ℝ) (c : Fin r → ℝ) + (hu : ∀ a, AEStronglyMeasurable (u a) ν) (hg : AEStronglyMeasurable g ν) + (hui : ∀ a, Integrable (fun x => u a x^2) ν) (hgi : Integrable (fun x => g x^2) ν) : + Integrable (fun x => residualRecipe u g c x^2) ν := by + have h := integrable_linear_combination_sq + (fun a : Option (Fin r) => a.elim g u) (fun a : Option (Fin r) => a.elim 1 (fun a => -c a)) + (by intro a; cases a with | none => exact hg | some a => exact hu a) + (by intro a; cases a with | none => exact hgi | some a => exact hui a) + simpa only [Fintype.sum_option,Option.elim_none,Option.elim_some,one_mul,neg_mul, + Finset.sum_neg_distrib,← sub_eq_add_neg,residualRecipe] using h + +theorem ExponentialEmpiricalConcentration.nondegenerate_query_step + {E : Type*} [PseudoMetricSpace E] [MeasurableSpace E] [BorelSpace E] + [SecondCountableTopology E] + {H : ℕ → Type*} [∀ n, MeasurableSpace (H n)] + (ρ : ∀ n, Measure (H n)) [∀ n, IsProbabilityMeasure (ρ n)] + (ν : Measure E) [IsProbabilityMeasure ν] + (X : ∀ n, H n → Fin n → E) (hXm : ∀ n, Measurable (X n)) + (hX : ExponentialEmpiricalConcentration ρ X ν) + (r : ℕ) (U Y : ∀ n, H n → Matrix (Fin n) (Fin r) ℝ) + (hUm : ∀ n, Measurable (U n)) + (hU : ∀ n h a, ∑ i, U n h i a^2 ≤ 1) + (G : ∀ n, Set (H n)) (hG : ∀ n, MeasurableSet (G n)) + (hrare : ExponentiallyRare ρ (fun n => (G n)ᶜ)) + (hgood : ∀ n h, h ∈ G n → (U n h)ᵀ*U n h=1) + (u y : Fin r → E → ℝ) (g : E → ℝ) {K : ℝ≥0} (hK : 1 ≤ K) + (hu : ∀ a, LipschitzWith K (u a)) (hy : ∀ a, LipschitzWith K (y a)) + (hg : LipschitzWith K g) + (huT : ∀ a, ExponentialSquareTails ρ (fun n h i => u a (X n h i))) + (hyT : ∀ a, ExponentialSquareTails ρ (fun n h i => y a (X n h i))) + (hgT : ExponentialSquareTails ρ (fun n h i => g (X n h i))) + (hui : ∀ a, Integrable (fun x => u a x^2) ν) + (hyi : ∀ a, Integrable (fun x => y a x^2) ν) (hgi : Integrable (fun x => g x^2) ν) + (heu : ∀ (n : ℕ) h i a, Real.sqrt n*U n h i a=u a (X n h i)) + (hey : ∀ (n : ℕ) h i a, Real.sqrt n*Y n h i a=y a (X n h i)) + (hs : 0 < ∫ x, residualRecipe u g (fun a => ∫ z, u a z*g z ∂ν) x^2 ∂ν) : + let R := fun n h => residualProjection (U n h) *ᵥ (fun i => g (X n h i)) + let q := fun n h => unitVector (R n h) + let s := ∫ x, residualRecipe u g (fun a => ∫ z, u a z*g z ∂ν) x^2 ∂ν + let φ := fun x => (x,residualRecipe u g (fun a => ∫ z, u a z*g z ∂ν) x/Real.sqrt s) + let ν' := ν.map φ + let W := fun n (z : H n × ((Fin n × Fin n) → ℝ)) i => + Real.sqrt n*(completedMatrix (U n z.1) (Y n z.1) z.2 *ᵥ q n z.1) i + ExponentialConvergence ρ (fun n h => (∑ i, R n h i^2)/(n:ℝ)) s ∧ + ExponentialEmpiricalConcentration + (fun n => (ρ n).prod (standardArrayLaw (Fin n × Fin n))) + (fun n z i => ((X n z.1 i,Real.sqrt n*q n z.1 i),W n z i)) + ((ν'.prod (gaussianReal 0 1)).map + (fun z => (z.1,z.2+∑ a, (∫ x, y a x.1*x.2 ∂ν')*u a z.1.1))) ∧ + ExponentialSquareTails ρ (fun n h i => Real.sqrt n*q n h i) ∧ + ExponentialSquareTails (fun n => (ρ n).prod (standardArrayLaw (Fin n × Fin n))) W := by + dsimp only + let R := fun n h => residualProjection (U n h) *ᵥ (fun i => g (X n h i)) + let S := fun n h => (∑ i, R n h i^2)/(n:ℝ) + let q := fun n h => unitVector (R n h) + let c := fun a => ∫ z, u a z*g z ∂ν + let s := ∫ x, residualRecipe u g c x^2 ∂ν + let φ := fun x => (x,residualRecipe u g c x/Real.sqrt s) + let ν' := ν.map φ + have hφ : Measurable φ := by + apply measurable_id.prodMk + apply Measurable.div_const + exact hg.continuous.measurable.sub (Finset.measurable_sum _ (fun a _ => + (hu a).continuous.measurable.const_mul (c a))) + let : IsProbabilityMeasure ν' := inferInstance + have hh := hX.normalized_projected_query U u g hu hg huT hgT hui hgi heu hs + change ExponentialConvergence ρ S s ∧ + ExponentialEmpiricalConcentration ρ + (fun n h i => (X n h i,Real.sqrt n*q n h i)) ν' ∧ + ExponentialSquareTails ρ (fun n h i => Real.sqrt n*q n h i) at hh + let X' := fun n h i => (X n h i,Real.sqrt n*q n h i) + have hRm n : Measurable (R n) := by + have hP := measurable_residualProjection_comp (U n) (hUm n) + have hgX : Measurable (fun h i => g (X n h i)) := by + exact Measurable.of_eval (fun i => hg.continuous.measurable.comp + ((measurable_pi_apply i).comp (hXm n))) + apply Measurable.of_eval + intro i + simp only [R,Matrix.mulVec,dotProduct] + apply Finset.measurable_sum + intro j _ + exact (((measurable_pi_apply j).comp (measurable_pi_apply i)).comp hP).mul + ((measurable_pi_apply j).comp hgX) + have hqm n : Measurable (q n) := measurable_unitVector.comp (hRm n) + have hSm n : Measurable (S n) := by + apply Measurable.div_const + exact Finset.measurable_sum _ (fun i _ => + (((measurable_pi_apply i).comp (hRm n)).pow_const 2)) + have hX'm n : Measurable (X' n) := by + apply Measurable.of_eval + intro i + exact ((measurable_pi_apply i).comp (hXm n)).prodMk + (((measurable_pi_apply i).comp (hqm n)).const_mul (Real.sqrt n)) + let G' := fun n => G n ∩ {h | 0 < S n h} + have hG' n : MeasurableSet (G' n) := (hG n).inter + (measurableSet_lt measurable_const (hSm n)) + have hrare' : ExponentiallyRare ρ (fun n => (G' n)ᶜ) := by + apply (hrare.union (hh.1.positive_rare hs)).mono + refine Filter.Eventually.of_forall ?_ + intro n h he + by_cases hh : h ∈ G n + · apply Or.inr + change S n h ≤ 0 + exact le_of_not_gt (fun hp => he ⟨hh,hp⟩) + · exact Or.inl hh + have hgood' n h (he : h ∈ G' n) : (U n h)ᵀ*U n h=1 ∧ + (∑ i, q n h i^2)=1 ∧ (U n h)ᵀ *ᵥ q n h=0 := by + have horth := hgood n h he.1 + refine ⟨horth,unitVector_sq_eq _ ?_,normalized_residual_perpendicular _ horth _⟩ + by_contra! hn + have hnp : S n h ≤ 0 := div_nonpos_of_nonpos_of_nonneg hn (Nat.cast_nonneg n) + exact not_le_of_gt he.2 hnp + have hu' a : LipschitzWith K (fun z : E × ℝ => u a z.1) := by + simpa only [Function.comp_def,mul_one] using (hu a).comp (LipschitzWith.prod_fst (α := E) (β := ℝ)) + have hy' a : LipschitzWith K (fun z : E × ℝ => y a z.1) := by + simpa only [Function.comp_def,mul_one] using (hy a).comp (LipschitzWith.prod_fst (α := E) (β := ℝ)) + have hg' : LipschitzWith K (Prod.snd : E × ℝ → ℝ) := + LipschitzWith.prod_snd.weaken hK + have hui' a : Integrable (fun z : E × ℝ => u a z.1^2) ν' := by + apply (integrable_map_measure (((hu a).continuous.measurable.comp measurable_fst).pow_const 2).aestronglyMeasurable hφ.aemeasurable).2 + exact hui a + have hyi' a : Integrable (fun z : E × ℝ => y a z.1^2) ν' := by + apply (integrable_map_measure (((hy a).continuous.measurable.comp measurable_fst).pow_const 2).aestronglyMeasurable hφ.aemeasurable).2 + exact hyi a + have hgi' : Integrable (fun z : E × ℝ => z.2^2) ν' := by + rw [integrable_map_measure (by fun_prop) hφ.aemeasurable] + simp only [φ,Function.comp_def,div_pow] + exact (integrable_residualRecipe_sq u g c + (fun a => (hu a).continuous.measurable.aestronglyMeasurable) + hg.continuous.measurable.aestronglyMeasurable hui hgi).div_const _ + have hqle n h : ∑ i, q n h i^2 ≤ 1 := unitVector_sq_le _ + have hstep := hh.2.1.completed_normalized_query ρ ν' X' hX'm r U Y q + hUm hqm hU hqle G' hG' hrare' hgood' + (fun a z => u a z.1) (fun a z => y a z.1) Prod.snd hu' hy' hg' + huT hyT hh.2.2 hui' hyi' hgi' heu hey (fun _ _ _ => rfl) + exact ⟨hh.1,hstep.1,hh.2.2,hstep.2⟩ + +end SKGapCutoff.Regression + +open MeasureTheory ProbabilityTheory Filter Set Matrix +open scoped BigOperators NNReal ENNReal Matrix.Norms.L2Operator + +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/IntegralAbsSet.lean b/lean/OAI/Probability/SKGap/Localization/IntegralAbsSet.lean new file mode 100644 index 0000000000000000000000000000000000000000..5a75e61d2c17a6242a93d0f48ea6d73608b5821c --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/IntegralAbsSet.lean @@ -0,0 +1,195 @@ +import Mathlib +import OAI.Probability.SKGap.Gaussian.GaussianCoordinateMemLp + +namespace OAI + +section +noncomputable section +open MeasureTheory ProbabilityTheory InformationTheory Real Set +open scoped NNReal ENNReal +open Filter +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius ENNReal NNReal +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius NNReal +noncomputable section +open MeasureTheory ProbabilityTheory Real Set Filter +open MeasureTheory.Measure +open scoped ENNReal NNReal MeasureTheory Topology +open MeasureTheory +noncomputable section +noncomputable section +open MeasureTheory Set NormedSpace +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius +noncomputable section +open Set Real +open scoped Topology +noncomputable section +open Matrix Set Filter +open scoped Topology Matrix.Norms.Frobenius +noncomputable section +open Matrix NormedSpace ContinuousLinearMap +open scoped Matrix.Norms.Frobenius +noncomputable section +open Matrix +noncomputable section +open MeasureTheory ProbabilityTheory Real Set +open scoped ENNReal NNReal +namespace SKGap +variable {Ω : Type*} [MeasurableSpace Ω] {μ : Measure Ω} [IsProbabilityMeasure μ] + +lemma integral_abs_on_set_le {F : Ω → ℝ} (hF : MemLp F 2 μ) + {s : Set Ω} (hs : MeasurableSet s) : + (∫ x in s, |F x| ∂μ) ≤ sqrt (∫ x, (F x)^2 ∂μ)*sqrt (μ.real s) := by + have hG : MemLp (s.indicator (fun _ : Ω => (1:ℝ))) 2 μ := + memLp_indicator_const 2 hs 1 (Or.inr (measure_ne_top _ _)) + have hh := integral_mul_norm_le_Lp_mul_Lq Real.HolderConjugate.two_two + (by simpa using hF) (by simpa using hG) + have he : (fun x => ‖F x‖*‖s.indicator (fun _ : Ω => (1:ℝ)) x‖) = + s.indicator (fun x => |F x|) := by + funext x + by_cases hx : x ∈ s <;> simp [hx,Real.norm_eq_abs] + have hg : (fun x => ‖s.indicator (fun _ : Ω => (1:ℝ)) x‖^(2:ℝ)) = + s.indicator (fun _ : Ω => (1:ℝ)) := by + funext x + by_cases hx : x ∈ s <;> simp [hx] + rw [he,hg,integral_indicator hs,integral_indicator hs] at hh + simpa only [Real.rpow_two,Real.norm_eq_abs,sq_abs,← Real.sqrt_eq_rpow, + integral_const,smul_eq_mul,mul_one,measureReal_restrict_apply_univ] using hh + +omit [IsProbabilityMeasure μ] in +lemma integral_exceptional_equal_bound {F G H : Ω → ℝ} {s : Set Ω} + (hs : MeasurableSet s) (hF : Integrable F μ) (hG : Integrable G μ) + (hH : Integrable H μ) (he : ∀ x ∉ s, F x=G x) + (hb : ∀ x ∈ s, ‖F x-G x‖ ≤ H x) : + |(∫ x, F x ∂μ)-(∫ x, G x ∂μ)| ≤ ∫ x in s, H x ∂μ := by + rw [← integral_sub hF hG] + rw [← Real.norm_eq_abs] + apply (norm_integral_le_integral_norm _).trans + rw [← integral_indicator hs] + apply integral_mono ((hF.sub hG).norm) (hH.indicator hs) + intro x + change ‖F x-G x‖ ≤ s.indicator H x + by_cases hx : x∈s + · simpa only [Set.indicator_of_mem hx] using hb x hx + · simp only [Set.indicator_of_notMem hx,he x hx,sub_self,norm_zero,le_refl] + +end SKGap + +namespace SKGap +open Matrix MeasureTheory ProbabilityTheory Real +open scoped BigOperators Matrix.Norms.Frobenius NNReal ENNReal +variable {ι : Type*} [Fintype ι] [DecidableEq ι] + +omit [DecidableEq ι] in +lemma abs_mul_entry_bound (M K : Matrix ι ι ℝ) (C : ℝ) (hK : ∀ a b, |K a b| ≤ C) (i : ι) : + |(M*K) i i| ≤ C*∑ b, |M i b| := by + rw [Matrix.mul_apply] + apply (Finset.abs_sum_le_sum_abs _ _).trans + rw [Finset.mul_sum] + apply Finset.sum_le_sum + intro b _ + rw [abs_mul,mul_comm C] + exact mul_le_mul_of_nonneg_left (hK b i) (abs_nonneg _) + +omit [DecidableEq ι] in + +theorem goe_diagonal_inverse_loop {r : ℝ} (hr : 0 ≤ r) (a c : ι → ℝ) (i : ι) + {K : (MatrixCoordinates ι → ℝ) → Matrix ι ι ℝ} {C : ℝ} + {s : Set (MatrixCoordinates ι → ℝ)} (hK : Continuous K) + (hC : ∀ g a b, |K g a b| ≤ C) (hs : MeasurableSet s) + (he : ∀ g ∈ s, K g i i = 1+a i*((goeMatrix r g*K g) i i-c i*K g i i)) : + let μ := Measure.pi (fun _ : MatrixCoordinates ι => gaussianReal 0 1) + |(∫ g, K g i i ∂μ)- + (1+a i*((∫ g, (goeMatrix r g*K g) i i ∂μ)-c i*(∫ g, K g i i ∂μ)))| ≤ + (C+1+|a i*c i| *C)*μ.real sᶜ+ + (|a i| *C)*(Fintype.card ι:ℝ)*sqrt (2*r)*sqrt (μ.real sᶜ) := by + intro μ + have hC0 : 0 ≤ C := (abs_nonneg _).trans (hC 0 i i) + have hKi (a b : ι) : Integrable (fun g => K g a b) μ := + Integrable.mono' (integrable_const C) (hK.matrix_elem a b).aestronglyMeasurable + (ae_of_all _ (fun g => by simpa only [Real.norm_eq_abs] using hC g a b)) + have hW (b : ι) : Integrable (fun g => goeMatrix r g i b) μ := + (goeEntry_memLp r i b).integrable (by norm_num) + have hWK (b : ι) : Integrable (fun g => goeMatrix r g i b*K g b i) μ := by + simpa only [mul_comm] using (hW b).bdd_mul (hK.matrix_elem b i).aestronglyMeasurable + (ae_of_all _ (fun g => by simpa only [Real.norm_eq_abs] using hC g b i)) + have hWI : Integrable (fun g => (goeMatrix r g*K g) i i) μ := + integrable_finsetSum _ (fun b _ => hWK b) + let A := C+1+|a i*c i| *C + let B := |a i| *C + let H := fun g => A+B*∑ b, |goeMatrix r g i b| + have hHA : Integrable (fun g => ∑ b, |goeMatrix r g i b|) μ := + integrable_finsetSum _ (fun b _ => (hW b).norm) + have hHI : Integrable H μ := (integrable_const A).add (hHA.const_mul B) + have hGI : Integrable (fun g => 1+a i*((goeMatrix r g*K g) i i-c i*K g i i)) μ := + (integrable_const 1).add ((hWI.sub ((hKi i i).const_mul _)).const_mul _) + have hb (g : MatrixCoordinates ι → ℝ) : + ‖K g i i-(1+a i*((goeMatrix r g*K g) i i-c i*K g i i))‖ ≤ H g := by + rw [Real.norm_eq_abs] + have hid : K g i i-(1+a i*((goeMatrix r g*K g) i i-c i*K g i i)) = + (K g i i-1)+(a i*c i)*K g i i+(-a i)*(goeMatrix r g*K g) i i := by ring + rw [hid] + apply (abs_add_le _ _).trans + apply (add_le_add (abs_add_le _ _) le_rfl).trans + have hk1 : |K g i i-1| ≤ C+1 := (abs_sub _ _).trans (by simpa using add_le_add_right (hC g i i) 1) + have hk2 : |(a i*c i)*K g i i| ≤ |a i*c i| *C := by + rw [abs_mul]; exact mul_le_mul_of_nonneg_left (hC g i i) (abs_nonneg _) + have hk3 : |(-a i)*(goeMatrix r g*K g) i i| ≤ |a i| *(C*∑ b, |goeMatrix r g i b|) := by + rw [abs_mul,abs_neg] + exact mul_le_mul_of_nonneg_left (abs_mul_entry_bound _ _ C (hC g) i) (abs_nonneg _) + exact (add_le_add (add_le_add hk1 hk2) hk3).trans_eq (by dsimp [H,A,B]; ring) + have hraw := integral_exceptional_equal_bound hs.compl (hKi i i) hGI hHI + (fun g hg => he g (by simpa using hg)) (fun g _ => hb g) + have hbad (b : ι) : (∫ g in sᶜ, |goeMatrix r g i b| ∂μ) ≤ + sqrt (2*r)*sqrt (μ.real sᶜ) := by + apply (integral_abs_on_set_le (goeEntry_memLp r i b) hs.compl).trans + exact mul_le_mul_of_nonneg_right (sqrt_le_sqrt (goeEntry_integral_sq_le hr i b)) (sqrt_nonneg _) + have hHr : (∫ g in sᶜ, H g ∂μ) ≤ A*μ.real sᶜ+B*(Fintype.card ι:ℝ)*sqrt (2*r)*sqrt (μ.real sᶜ) := by + rw [show H = fun g => A+B*∑ b, |goeMatrix r g i b| from rfl, + integral_add (integrable_const A) ((hHA.const_mul B).mono_measure Measure.restrict_le_self), + integral_const,integral_const_mul] + have hWa (b : ι) : Integrable (fun g => |goeMatrix r g i b|) (μ.restrict sᶜ) := by + simpa only [Real.norm_eq_abs] using (hW b).norm.mono_measure Measure.restrict_le_self + rw [integral_finsetSum _ (fun b _ => hWa b)] + simp only [measureReal_restrict_apply_univ,smul_eq_mul] + calc + _ ≤ μ.real sᶜ*A+B*(∑ _b : ι, sqrt (2*r)*sqrt (μ.real sᶜ)) := + add_le_add le_rfl (mul_le_mul_of_nonneg_left (Finset.sum_le_sum (fun b _ => hbad b)) + (mul_nonneg (abs_nonneg _) hC0)) + _ = _ := by simp only [Finset.sum_const,Finset.card_univ,nsmul_eq_mul]; ring + have heI : (∫ g, 1+a i*((goeMatrix r g*K g) i i-c i*K g i i) ∂μ) = + 1+a i*((∫ g, (goeMatrix r g*K g) i i ∂μ)-c i*(∫ g, K g i i ∂μ)) := by + have ht := integral_add (integrable_const (1:ℝ)) + ((hWI.sub ((hKi i i).const_mul (c i))).const_mul (a i)) + change (∫ g, 1+a i*((goeMatrix r g*K g) i i-c i*K g i i) ∂μ) = _ at ht + rw [ht,integral_const_mul] + simp only [Pi.sub_apply] + rw [integral_sub hWI ((hKi i i).const_mul (c i)),integral_const_mul] + simp + rw [heI] at hraw + exact hraw.trans hHr + +end SKGap + +end +end +end +end +end +end +end +end +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/IntegralProductDeviation.lean b/lean/OAI/Probability/SKGap/Localization/IntegralProductDeviation.lean new file mode 100644 index 0000000000000000000000000000000000000000..3700a5289b20657b0df04b049ec8ee825173789c --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/IntegralProductDeviation.lean @@ -0,0 +1,86 @@ +import Mathlib +import OAI.Probability.SKGap.Model + +namespace OAI + +section +noncomputable section +open MeasureTheory ProbabilityTheory InformationTheory Real Set +open scoped NNReal ENNReal +open Filter +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius ENNReal NNReal +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius NNReal +noncomputable section +open MeasureTheory ProbabilityTheory Real Set Filter +open MeasureTheory.Measure +open scoped ENNReal NNReal MeasureTheory Topology +open MeasureTheory +noncomputable section +namespace SKGap +variable {Ω : Type*} [MeasurableSpace Ω] {μ : Measure Ω} [IsProbabilityMeasure μ] + +lemma integral_product_deviation {X Y : Ω → ℝ} {C T : ℝ} + (hX : Integrable X μ) (hY : AEStronglyMeasurable Y μ) + (hC : ∀ᵐ x ∂μ, ‖Y x‖ ≤ C) + (hT : (∫ x, |X x-∫ y, X y ∂μ| ∂μ) ≤ T) : + |(∫ x, X x*Y x ∂μ)-(∫ x, X x ∂μ)*(∫ x, Y x ∂μ)| ≤ C*T := by + have hC0 : 0 ≤ C := by + obtain ⟨x,hx⟩ := hC.exists + exact (norm_nonneg _).trans hx + have hYi : Integrable Y μ := (integrable_const C).mono' hY hC + have hXY : Integrable (fun x => X x*Y x) μ := by + simpa only [mul_comm] using hX.bdd_mul hY hC + have hcenter : Integrable (fun x => X x-∫ y, X y ∂μ) μ := hX.sub (integrable_const _) + have hci : Integrable (fun x => (X x-∫ y, X y ∂μ)*Y x) μ := by + simpa only [mul_comm] using hcenter.bdd_mul hY hC + have he : (∫ x, X x*Y x ∂μ)-(∫ x, X x ∂μ)*(∫ x, Y x ∂μ) = + ∫ x, (X x-∫ y, X y ∂μ)*Y x ∂μ := by + simp_rw [sub_mul] + rw [integral_sub hXY (hYi.const_mul _),integral_const_mul] + rw [he] + calc + _ ≤ ∫ x, ‖(X x-∫ y, X y ∂μ)*Y x‖ ∂μ := norm_integral_le_integral_norm _ + _ ≤ ∫ x, C*|X x-∫ y, X y ∂μ| ∂μ := by + apply integral_mono_ae hci.norm (hcenter.norm.const_mul C) + filter_upwards [hC] with x hx + simpa only [norm_mul,Real.norm_eq_abs,mul_comm] using + mul_le_mul_of_nonneg_left hx (norm_nonneg (X x-∫ y, X y ∂μ)) + _ = C*(∫ x, |X x-∫ y, X y ∂μ| ∂μ) := integral_const_mul _ _ + _ ≤ _ := mul_le_mul_of_nonneg_left hT hC0 + +lemma integral_loop_deviation {X Y Z V : Ω → ℝ} {r C T B E : ℝ} + (hr : 0 ≤ r) (hX : Integrable X μ) (hY : AEStronglyMeasurable Y μ) + (hC : ∀ᵐ x ∂μ, ‖Y x‖ ≤ C) + (hZ : Integrable Z μ) (hB : ∀ᵐ x ∂μ, ‖Z x‖ ≤ B) + (hT : (∫ x, |X x-∫ y, X y ∂μ| ∂μ) ≤ T) + (hE : |(∫ x, V x ∂μ)-r*(∫ x, X x*Y x+Z x ∂μ)| ≤ E) : + |(∫ x, V x ∂μ)-r*(∫ x, X x ∂μ)*(∫ x, Y x ∂μ)| ≤ E+r*(C*T+B) := by + have hXY : Integrable (fun x => X x*Y x) μ := by + simpa only [mul_comm] using hX.bdd_mul hY hC + have hbound := integral_product_deviation hX hY hC hT + have hb : |∫ x, Z x ∂μ| ≤ B := by + exact (norm_integral_le_integral_norm _).trans ((integral_mono_ae hZ.norm (integrable_const B) hB).trans_eq (by simp)) + have he : (∫ x, V x ∂μ)-r*(∫ x, X x ∂μ)*(∫ x, Y x ∂μ) = + ((∫ x, V x ∂μ)-r*(∫ x, X x*Y x+Z x ∂μ))+ + r*((∫ x, X x*Y x ∂μ)-(∫ x, X x ∂μ)*(∫ x, Y x ∂μ)+(∫ x, Z x ∂μ)) := by + rw [integral_add hXY hZ]; ring + rw [he] + exact (abs_add_le _ _).trans (add_le_add hE (by + rw [abs_mul,abs_of_nonneg hr] + exact mul_le_mul_of_nonneg_left ((abs_add_le _ _).trans (add_le_add hbound hb)) hr)) + +end SKGap + +end +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/Invert.lean b/lean/OAI/Probability/SKGap/Localization/Invert.lean new file mode 100644 index 0000000000000000000000000000000000000000..08d1062c8c4837466dc7016c989d9b04651d6908 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/Invert.lean @@ -0,0 +1,173 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.StationaryInner + +namespace OAI + +section +open scoped BigOperators +namespace SKGapCutoff + +def invert {n : ℕ} (x : Spin n) : Spin n := fun i => !x i +@[simp] lemma invert_invert {n : ℕ} (x : Spin n) : invert (invert x) = x := by + funext i; simp [invert] +@[simp] lemma spin_invert {n : ℕ} (x : Spin n) (i : Fin n) : + spin (invert x) i = -spin x i := by + cases hi : x i <;> simp [spin, invert, hi] +def invertEquiv (n : ℕ) : Spin n ≃ Spin n where + toFun := invert + invFun := invert + left_inv := invert_invert + right_inv := invert_invert +lemma sum_invert {n : ℕ} (f : Spin n → ℝ) : (∑ x, f (invert x)) = ∑ x, f x := + (invertEquiv n).sum_comp f +@[simp] lemma energy_invert {n : ℕ} (J : Interaction n) (x : Spin n) : + energy J (invert x) = energy J x := by + simp [energy] +@[simp] lemma gibbs_invert {n : ℕ} (J : Interaction n) (x : Spin n) : + gibbs J (invert x) = gibbs J x := by simp [gibbs] + +theorem gibbs_spin_centered {n : ℕ} (J : Interaction n) (i : Fin n) : + gibbsExpectation J (fun x => spin x i) = 0 := by + have h := sum_invert (fun x => gibbs J x * spin x i) + simp only [gibbs_invert, spin_invert, mul_neg, Finset.sum_neg_distrib] at h + unfold gibbsExpectation + linarith + +@[simp] lemma generator_spin {n : ℕ} (J : Interaction n) (x : Spin n) (i : Fin n) : + generator J (fun y => spin y i) x = mean J x i - spin x i := by + simp [generator, halfDiff_spin] + +lemma siteVariance_pos {n : ℕ} (J : Interaction n) (x : Spin n) (i : Fin n) : + 0 < siteVariance J x i := by + have hl := Real.neg_one_lt_tanh (field J x i) + have hu := Real.tanh_lt_one (field J x i) + unfold siteVariance mean + nlinarith +lemma siteVariance_le_one {n : ℕ} (J : Interaction n) (x : Spin n) (i : Fin n) : + siteVariance J x i ≤ 1 := by + unfold siteVariance + nlinarith [sq_nonneg (mean J x i)] + +lemma dirichlet_nonneg {n : ℕ} (J : Interaction n) (f : Observables n) : + 0 ≤ dirichlet J f f := by + apply Finset.sum_nonneg + intro x _ + apply mul_nonneg (le_of_lt (gibbs_pos J x)) + apply Finset.sum_nonneg + intro i _ + nlinarith [mul_nonneg (le_of_lt (siteVariance_pos J x i)) (sq_nonneg (halfDiff i f x))] + +theorem spin_first_second {n : ℕ} (J : Interaction n) + (hJ : ∀ i j, J i j = J j i) (hdiag : ∀ i, J i i = 0) (i : Fin n) : + stationaryInner J (fun x => spin x i) (fun x => -generator J (fun y => spin y i) x) = + gibbsExpectation J (fun x => siteVariance J x i) ∧ + stationaryInner J (generator J (fun x => spin x i)) (generator J (fun x => spin x i)) = + gibbsExpectation J (fun x => siteVariance J x i) := by + constructor + · rw [stationaryInner, gibbs_dirichlet J hJ hdiag] + simp [dirichlet, halfDiff_spin] + · have hm := gibbs_coordinate_mean J hJ hdiag i (fun x => mean J x i) + (by intro x; exact mean_flip J hdiag x i) + simp only [stationaryInner, gibbsExpectation, generator_spin] + have he (x : Spin n) : + gibbs J x * ((mean J x i - spin x i) * (mean J x i - spin x i)) = + gibbs J x * siteVariance J x i + + 2 * (gibbs J x * mean J x i * mean J x i - gibbs J x * spin x i * mean J x i) := by + unfold siteVariance + nlinarith [congrArg (fun a : ℝ => gibbs J x * a) (spin_sq x i)] + simp_rw [he] + rw [Finset.sum_add_distrib, ← Finset.mul_sum, Finset.sum_sub_distrib, hm] + ring + +noncomputable def gibbsEuclideanEquiv {n : ℕ} (J : Interaction n) : + Observables n ≃ₗ[ℝ] EuclideanSpace ℝ (Spin n) where + toFun f := WithLp.toLp 2 (fun x => Real.sqrt (gibbs J x) * f x) + invFun u x := u x / Real.sqrt (gibbs J x) + left_inv f := by + funext x + exact mul_div_cancel_left₀ (f x) (ne_of_gt (Real.sqrt_pos.2 (gibbs_pos J x))) + right_inv u := by + ext x + exact mul_div_cancel₀ (u x) (ne_of_gt (Real.sqrt_pos.2 (gibbs_pos J x))) + map_add' f g := by ext x; simp [mul_add] + map_smul' a f := by ext x; simp [mul_left_comm] + +@[simp] lemma gibbsEuclideanEquiv_apply {n : ℕ} (J : Interaction n) (f : Observables n) (x : Spin n) : + gibbsEuclideanEquiv J f x = Real.sqrt (gibbs J x) * f x := rfl +@[simp] lemma gibbsEuclideanEquiv_symm_apply {n : ℕ} (J : Interaction n) + (u : EuclideanSpace ℝ (Spin n)) (x : Spin n) : + (gibbsEuclideanEquiv J).symm u x = u x / Real.sqrt (gibbs J x) := rfl + +lemma gibbsEuclideanEquiv_inner {n : ℕ} (J : Interaction n) (f g : Observables n) : + inner (𝕜 := ℝ) (gibbsEuclideanEquiv J f) (gibbsEuclideanEquiv J g) = stationaryInner J f g := by + rw [PiLp.inner_apply] + unfold stationaryInner gibbsExpectation + apply Finset.sum_congr rfl + intro x _ + simp only [gibbsEuclideanEquiv_apply, RCLike.inner_apply, conj_trivial] + have hs := Real.sq_sqrt (le_of_lt (gibbs_pos J x)) + nlinarith only [congrArg (fun a : ℝ => a * f x * g x) hs] + +noncomputable def negativeGeneratorEuclidean {n : ℕ} (J : Interaction n) : + EuclideanSpace ℝ (Spin n) →ₗ[ℝ] EuclideanSpace ℝ (Spin n) := + (gibbsEuclideanEquiv J).toLinearMap.comp + ((-generatorLM J).comp (gibbsEuclideanEquiv J).symm.toLinearMap) + +lemma negativeGeneratorEuclidean_lift {n : ℕ} (J : Interaction n) (f : Observables n) : + negativeGeneratorEuclidean J (gibbsEuclideanEquiv J f) = + gibbsEuclideanEquiv J (-generator J f) := by + simp [negativeGeneratorEuclidean, generatorLM] + +lemma negativeGeneratorEuclidean_symmetric {n : ℕ} (J : Interaction n) + (hJ : ∀ i j, J i j = J j i) (hdiag : ∀ i, J i i = 0) : + (negativeGeneratorEuclidean J).IsSymmetric := by + intro u v + obtain ⟨f, rfl⟩ := (gibbsEuclideanEquiv J).surjective u + obtain ⟨g, rfl⟩ := (gibbsEuclideanEquiv J).surjective v + rw [negativeGeneratorEuclidean_lift, negativeGeneratorEuclidean_lift, + gibbsEuclideanEquiv_inner, gibbsEuclideanEquiv_inner] + have he := scalar_generator_symmetric J hJ hdiag f g + simp only [stationaryInner, gibbsExpectation] at he ⊢ + simpa only [Pi.neg_apply, neg_mul, mul_neg, Finset.sum_neg_distrib] using congrArg Neg.neg he.symm + +lemma negativeGeneratorEuclidean_nonneg {n : ℕ} (J : Interaction n) + (hJ : ∀ i j, J i j = J j i) (hdiag : ∀ i, J i i = 0) + (u : EuclideanSpace ℝ (Spin n)) : + 0 ≤ inner (𝕜 := ℝ) u (negativeGeneratorEuclidean J u) := by + obtain ⟨f, rfl⟩ := (gibbsEuclideanEquiv J).surjective u + rw [negativeGeneratorEuclidean_lift, gibbsEuclideanEquiv_inner] + change 0 ≤ gibbsExpectation J (fun x => f x * -generator J f x) + rw [gibbs_dirichlet J hJ hdiag] + exact dirichlet_nonneg J f + +noncomputable def spinEigenvalues {n : ℕ} (J : Interaction n) + (hJ : ∀ i j, J i j = J j i) (hdiag : ∀ i, J i i = 0) : + Fin (Fintype.card (Spin n)) → ℝ := + (negativeGeneratorEuclidean_symmetric J hJ hdiag).eigenvalues finrank_euclideanSpace + +noncomputable def spinEigenbasis {n : ℕ} (J : Interaction n) + (hJ : ∀ i j, J i j = J j i) (hdiag : ∀ i, J i i = 0) : + OrthonormalBasis (Fin (Fintype.card (Spin n))) ℝ (EuclideanSpace ℝ (Spin n)) := + (negativeGeneratorEuclidean_symmetric J hJ hdiag).eigenvectorBasis finrank_euclideanSpace + +noncomputable def spinSpectralCoefficient {n : ℕ} (J : Interaction n) + (hJ : ∀ i j, J i j = J j i) (hdiag : ∀ i, J i i = 0) + (i : Fin n) (a : Fin (Fintype.card (Spin n))) : ℝ := + (spinEigenbasis J hJ hdiag).repr (gibbsEuclideanEquiv J (fun x => spin x i)) a + +noncomputable def spinSpectralMass {n : ℕ} (J : Interaction n) + (hJ : ∀ i j, J i j = J j i) (hdiag : ∀ i, J i i = 0) + (a : Fin (Fintype.card (Spin n))) : ℝ := + (∑ i, spinSpectralCoefficient J hJ hdiag i a ^ 2) / n + +noncomputable def spinSpectralMeasure {n : ℕ} (J : Interaction n) + (hJ : ∀ i j, J i j = J j i) (hdiag : ∀ i, J i i = 0) : MeasureTheory.Measure ℝ := + ∑ a : Fin (Fintype.card (Spin n)), + ENNReal.ofReal (spinSpectralMass J hJ hdiag a) • + MeasureTheory.Measure.dirac (spinEigenvalues J hJ hdiag a) + +end SKGapCutoff + +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/JumpBilinear.lean b/lean/OAI/Probability/SKGap/Localization/JumpBilinear.lean new file mode 100644 index 0000000000000000000000000000000000000000..ac98e9a66be60de6502ee0e8aa7cf4f93eda76bd --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/JumpBilinear.lean @@ -0,0 +1,502 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.Centered +import OAI.Probability.SKGap.Localization.JumpWeight +import OAI.Probability.SKGap.Stability.ConditionalMean + +namespace OAI + +section +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open scoped BigOperators +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open scoped BigOperators +open scoped BigOperators NNReal ENNReal +open MeasureTheory Metric Set +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators NNReal ENNReal Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Set +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators ENNReal NNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Matrix +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators ENNReal NNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal +open scoped BigOperators +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise NNReal ENNReal +open scoped BigOperators +open Filter Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal Topology +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Set Matrix +open scoped BigOperators NNReal ENNReal Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open Filter MeasureTheory ProbabilityTheory +open scoped Topology NNReal ENNReal +open Filter MeasureTheory ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter +open scoped Topology NNReal ENNReal +open MeasureTheory Filter ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter +open scoped Topology +open MeasureTheory Filter ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter ProbabilityTheory ContinuousLinearMap +open scoped Topology NNReal ENNReal +open Filter MeasureTheory ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter +open scoped BigOperators Topology +open MeasureTheory Filter +open scoped BigOperators Topology +open MeasureTheory Filter +open scoped BigOperators Topology +open MeasureTheory Filter +open scoped BigOperators Topology +open MeasureTheory Filter +open scoped BigOperators Topology +open Filter Set Metric +open scoped Topology RealInnerProductSpace +open scoped BigOperators +open ContinuousLinearMap +open scoped BigOperators +open ContinuousLinearMap +open scoped Topology Interval +open MeasureTheory +open MeasureTheory +open scoped BigOperators Topology Interval +open MeasureTheory +open scoped BigOperators Topology Interval +open scoped Topology +open MeasureTheory +open scoped BigOperators Topology Interval +open scoped BigOperators Topology +open MeasureTheory +open scoped BigOperators Topology Interval RealInnerProductSpace +open MeasureTheory Filter +open scoped BigOperators Topology Interval +namespace SKGapCutoff + +lemma jumpWeight_conditional_first {n : ℕ} (J : Interaction n) + (hJ : ∀ i j, J i j=J j i) (hdiag : ∀ i, J i i=0) + (i : Fin n) (f : Observables n) (hf : ∀ x, f (flip x i)=f x) : + gibbsExpectation J (fun x => jumpWeight J x i*f x) = + gibbsExpectation J (fun x => siteVariance J x i*f x) := by + have hm := gibbs_coordinate_mean J hJ hdiag i (fun x => mean J x i*f x) + (fun x => by rw [mean_flip J hdiag,hf]) + have he (x : Spin n) : gibbs J x*(jumpWeight J x i*f x-siteVariance J x i*f x) = + gibbs J x*mean J x i*(mean J x i*f x)-gibbs J x*spin x i*(mean J x i*f x) := by + unfold jumpWeight siteVariance + ring + have hz : gibbsExpectation J (fun x => jumpWeight J x i*f x)- + gibbsExpectation J (fun x => siteVariance J x i*f x) = 0 := by + unfold gibbsExpectation + rw [← Finset.sum_sub_distrib] + simp_rw [← mul_sub,he] + rw [Finset.sum_sub_distrib,hm,sub_self] + linarith + +lemma jumpWeight_conditional_square {n : ℕ} (J : Interaction n) + (hJ : ∀ i j, J i j=J j i) (hdiag : ∀ i, J i i=0) + (i : Fin n) (f : Observables n) (hf : ∀ x, f (flip x i)=f x) : + gibbsExpectation J (fun x => (jumpWeight J x i)^2*f x) = + gibbsExpectation J (fun x => siteVariance J x i*f x) := by + have hm := gibbs_coordinate_mean J hJ hdiag i (fun x => mean J x i*f x) + (fun x => by rw [mean_flip J hdiag,hf]) + have he (x : Spin n) : gibbs J x*((jumpWeight J x i)^2*f x-siteVariance J x i*f x) = + 2*(gibbs J x*mean J x i*(mean J x i*f x)-gibbs J x*spin x i*(mean J x i*f x)) := by + unfold jumpWeight siteVariance + nlinarith only [congrArg (fun a : ℝ => gibbs J x*(mean J x i)^2*f x*a) (spin_sq x i)] + have hz : gibbsExpectation J (fun x => (jumpWeight J x i)^2*f x)- + gibbsExpectation J (fun x => siteVariance J x i*f x) = 0 := by + unfold gibbsExpectation + rw [← Finset.sum_sub_distrib] + simp_rw [← mul_sub,he] + rw [← Finset.mul_sum,Finset.sum_sub_distrib,hm,sub_self,mul_zero] + linarith + +theorem jumpWeight_isometry {n : ℕ} (J : Interaction n) + (hJ : ∀ i j, J i j=J j i) (hdiag : ∀ i, J i i=0) + (p : VectorFields n) (hp : ∀ x i, p (flip x i) i=p x i) : + gibbsExpectation J (vectorSquare (fun x i => jumpWeight J x i*p x i)) = + weightedInner J p p := by + unfold vectorSquare weightedInner + rw [gibbsExpectation_sum,gibbsExpectation_sum] + apply Finset.sum_congr rfl + intro i _ + have he := jumpWeight_conditional_square J hJ hdiag i (fun x => (p x i)^2) + (fun x => by rw [hp]) + convert he using 1 <;> (congr 1; funext x; ring) + +lemma exact_gradient_jumpWeight_isometry {n : ℕ} (J : Interaction n) + (hJ : ∀ i j, J i j=J j i) (hdiag : ∀ i, J i i=0) + (f : Observables n) : + gibbsExpectation J (vectorSquare (fun x i => jumpWeight J x i*halfDiff i f x)) = + dirichlet J f f := by + exact jumpWeight_isometry J hJ hdiag (fun x i => halfDiff i f x) + (fun x i => halfDiff_flip i f x) + +noncomputable def jumpBilinear {n : ℕ} (J : Interaction n) (f g : Observables n) : Observables n := + fun x => 2*∑ i, jumpWeight J x i*halfDiff i f x*halfDiff i g x + +lemma backward_product_hasDerivAt {n : ℕ} (J : Interaction n) + (f g : Observables n) (d s : ℝ) : + HasDerivAt (fun r : ℝ => fun x : Spin n => + semigroup J (d-r) f x*semigroup J (d-r) g x) + (fun x => -generator J (semigroup J (d-s) f) x*semigroup J (d-s) g x- + semigroup J (d-s) f x*generator J (semigroup J (d-s) g) x) s := by + apply hasDerivAt_pi.mpr + intro x + have hh := (hasDerivAt_pi.mp (backward_flow_hasDerivAt J f d s) x).mul + (hasDerivAt_pi.mp (backward_flow_hasDerivAt J g d s) x) + convert hh using 1 + ring + +lemma interpolated_product_hasDerivAt {n : ℕ} (J : Interaction n) + (f g : Observables n) (d s : ℝ) : + HasDerivAt (fun r : ℝ => semigroup J r (fun x => + semigroup J (d-r) f x*semigroup J (d-r) g x)) + (semigroup J s (jumpBilinear J (semigroup J (d-s) f) (semigroup J (d-s) g))) s := by + have hd := (semigroup_hasDerivAt J s).clm_apply (backward_product_hasDerivAt J f g d s) + apply hd.congr_deriv + simp only [mul_apply_eq_comp] + change semigroup J s (generator J (fun x => semigroup J (d-s) f x*semigroup J (d-s) g x))+ + semigroup J s (fun x => -generator J (semigroup J (d-s) f) x*semigroup J (d-s) g x- + semigroup J (d-s) f x*generator J (semigroup J (d-s) g) x) = _ + rw [← map_add] + congr 1 + funext x + simp only [Pi.add_apply] + rw [generator_mul] + simp only [jumpBilinear,jumpWeight] + ring + +lemma jumpBilinear_continuous {n : ℕ} (J : Interaction n) : + Continuous (fun p : Observables n × Observables n => jumpBilinear J p.1 p.2) := by + unfold jumpBilinear halfDiff + fun_prop + +lemma interpolated_bilinear_continuous {n : ℕ} (J : Interaction n) + (f g : Observables n) (d : ℝ) (x : Spin n) : + Continuous (fun s : ℝ => semigroup J s + (jumpBilinear J (semigroup J (d-s) f) (semigroup J (d-s) g)) x) := by + have hf : Continuous (fun s : ℝ => semigroup J (d-s) f) := + ((semigroup_continuous J).comp (continuous_const.sub continuous_id)).clm_apply continuous_const + have hg : Continuous (fun s : ℝ => semigroup J (d-s) g) := + ((semigroup_continuous J).comp (continuous_const.sub continuous_id)).clm_apply continuous_const + exact (continuous_apply x).comp ((semigroup_continuous J).clm_apply + ((jumpBilinear_continuous J).comp (hf.prodMk hg))) + +theorem semigroup_covariance_integral {n : ℕ} (J : Interaction n) + (f g : Observables n) (d : ℝ) (x : Spin n) : + semigroup J d (fun y => f y*g y) x-semigroup J d f x*semigroup J d g x = + ∫ s in (0:ℝ)..d, semigroup J s + (jumpBilinear J (semigroup J (d-s) f) (semigroup J (d-s) g)) x := by + have hd (s : ℝ) := hasDerivAt_pi.mp (interpolated_product_hasDerivAt J f g d s) x + have hi := (interpolated_bilinear_continuous J f g d x).intervalIntegrable + (μ := volume) 0 d + have he := intervalIntegral.integral_eq_sub_of_hasDerivAt (fun s _ => hd s) hi + simpa only [sub_self,sub_zero,semigroup_zero,one_apply_eq_self] using he.symm + +lemma equilibriumPotential_pairing_covariance {n : ℕ} (J : Interaction n) + (hJ : ∀ i j, J i j=J j i) (hdiag : ∀ i, J i i=0) + (G : Observables n) (B : VectorFields n) (d : ℝ) : + stationaryInner J G (equilibriumPotential J d B) = d⁻¹ * ∑ i, + stationaryInner J (fun x => B x i) (fun x => + semigroup J d (fun y => spin y i*G y) x- + semigroup J d (fun y => spin y i) x*semigroup J d G x) := by + have hp (i : Fin n) : stationaryInner J (fun x => spin x i*G x) + (semigroup J d (fun y => B y i)) = + stationaryInner J (fun x => B x i) (semigroup J d (fun y => spin y i*G y)) := by + rw [scalar_semigroup_symmetric J hJ hdiag,stationaryInner_symm] + have hq := scalar_semigroup_symmetric J hJ hdiag d G + (fun y => ∑ i, semigroup J d (fun z => spin z i) y*B y i) + unfold stationaryInner at hp hq ⊢ + unfold equilibriumPotential + simp only [mul_sub,gibbsExpectation_sub,gibbsExpectation_sum,Finset.mul_sum, + mul_left_comm (G _) d⁻¹, gibbsExpectation_mul_const] + rw [hq] + simp only [Finset.mul_sum,gibbsExpectation_sum] + have hp' (i : Fin n) : gibbsExpectation J (fun x => G x*(spin x i*semigroup J d (fun y => B y i) x)) = + gibbsExpectation J (fun x => B x i*semigroup J d (fun y => spin y i*G y) x) := by + simpa only [mul_assoc,mul_comm (G _) (spin _ i),mul_left_comm (G _) (spin _ i)] using hp i + simp_rw [hp'] + rw [Finset.sum_sub_distrib] + congr 2 + funext i + congr 1 + congr 1 + funext x + ring + +lemma semigroup_covariance_zero_hasDerivAt {n : ℕ} (J : Interaction n) + (f g : Observables n) : + HasDerivAt (fun d : ℝ => semigroup J d (f*g)-semigroup J d f*semigroup J d g) + (jumpBilinear J f g) 0 := by + have hd := (semigroup_apply_hasDerivAt J (f*g) 0).sub + ((semigroup_apply_hasDerivAt J f 0).mul (semigroup_apply_hasDerivAt J g 0)) + apply hd.congr_deriv + simp only [semigroup_zero,one_apply_eq_self] + funext x + change generator J (fun y => f y*g y) x- + (generator J f x*g x+f x*generator J g x) = _ + rw [generator_mul] + dsimp [jumpBilinear,jumpWeight] + ring + +lemma semigroup_covariance_slope {n : ℕ} (J : Interaction n) (f g : Observables n) : + Tendsto (fun d : ℝ => d⁻¹ • (semigroup J d (f*g)-semigroup J d f*semigroup J d g)) + (nhdsWithin 0 (Set.Ioi 0)) (nhds (jumpBilinear J f g)) := by + simpa only [zero_add,semigroup_zero,one_apply_eq_self,sub_self,sub_zero] using + (semigroup_covariance_zero_hasDerivAt J f g).tendsto_slope_zero_right + +lemma stationaryInner_covariance_slope {n : ℕ} (J : Interaction n) + (f g b : Observables n) : + Tendsto (fun d : ℝ => d⁻¹*stationaryInner J b + (semigroup J d (f*g)-semigroup J d f*semigroup J d g)) + (nhdsWithin 0 (Set.Ioi 0)) (nhds (stationaryInner J b (jumpBilinear J f g))) := by + have hh := (stationaryPairingCLM J b).continuous.tendsto _ |>.comp + (semigroup_covariance_slope J f g) + simpa only [Function.comp_def,map_smul,smul_eq_mul,stationaryPairingCLM_apply] using hh + +theorem equilibriumPotential_pairing_small_time {n : ℕ} (J : Interaction n) + (hJ : ∀ i j, J i j=J j i) (hdiag : ∀ i, J i i=0) + (G : Observables n) (B : VectorFields n) : + Tendsto (fun d : ℝ => stationaryInner J G (equilibriumPotential J d B)) + (nhdsWithin 0 (Set.Ioi 0)) (nhds + (2*gibbsExpectation J (fun x => ∑ i, B x i*jumpWeight J x i*halfDiff i G x))) := by + have hh := tendsto_finsetSum Finset.univ (fun i _ => + stationaryInner_covariance_slope J (fun x => spin x i) G (fun x => B x i)) + have he (d : ℝ) : stationaryInner J G (equilibriumPotential J d B) = + ∑ i, d⁻¹*stationaryInner J (fun x => B x i) + (semigroup J d ((fun x => spin x i)*G)-semigroup J d (fun x => spin x i)*semigroup J d G) := by + rw [equilibriumPotential_pairing_covariance J hJ hdiag,Finset.mul_sum] + rfl + simp_rw [he] + have hl : (∑ i, stationaryInner J (fun x => B x i) + (jumpBilinear J (fun x => spin x i) G)) = + 2*gibbsExpectation J (fun x => ∑ i, B x i*jumpWeight J x i*halfDiff i G x) := by + have hj (i : Fin n) : jumpBilinear J (fun x => spin x i) G = + fun x => 2*jumpWeight J x i*halfDiff i G x := by + funext x + simp [jumpBilinear,halfDiff_spin,mul_ite,ite_mul,mul_assoc] + simp_rw [hj] + unfold stationaryInner + rw [← gibbsExpectation_sum,← gibbsExpectation_mul_const] + congr 1 + funext x + rw [Finset.mul_sum] + apply Finset.sum_congr rfl + intro i _ + ring + rw [← hl] + exact hh + +lemma exact_gradient_pairing_integral {n : ℕ} (J : Interaction n) + (hJ : ∀ i j, J i j=J j i) (hdiag : ∀ i, J i i=0) + (G f : Observables n) (T : ℝ) : + (∫ t in (0 : ℝ)..T, weightedInner J (gradientCLM n G) + (gradientSemigroup J t (gradientCLM n f))) = + stationaryInner J G f-stationaryInner J G (semigroup J T f) := by + have he (t : ℝ) : weightedInner J (gradientCLM n G) + (gradientSemigroup J t (gradientCLM n f)) = + -stationaryInner J G (generator J (semigroup J t f)) := by + change weightedInner J (fun x i => halfDiff i G x) + (gradientSemigroup J t (fun x i => halfDiff i f x)) = _ + rw [exact_gradient_semigroup_identity J hJ hdiag] + change stationaryPairingCLM J G (-generator J (semigroup J t f)) = _ + simp only [map_neg,stationaryPairingCLM_apply] + have hd (t : ℝ) : HasDerivAt (fun s : ℝ => -stationaryInner J G (semigroup J s f)) + (-stationaryInner J G (generator J (semigroup J t f))) t := by + exact ((stationaryPairingCLM J G).hasFDerivAt.comp_hasDerivAt t + (semigroup_apply_hasDerivAt' J f t)).neg + have hc : Continuous (fun t : ℝ => -stationaryInner J G (generator J (semigroup J t f))) := by + exact ((stationaryPairingCLM J G).continuous.comp + ((generatorCLM J).continuous.comp + ((semigroup_continuous J).clm_apply continuous_const))).neg + simp_rw [he] + have hh := intervalIntegral.integral_eq_sub_of_hasDerivAt (fun t _ => hd t) + (hc.intervalIntegrable (μ := volume) 0 T) + simpa only [semigroup_zero,one_apply_eq_self,sub_neg_eq_add,neg_add_eq_sub] using hh + +lemma stationaryInner_centered_semigroup_tendsto_zero {n : ℕ} (J : Interaction n) + (hJ : ∀ i j, J i j=J j i) (hdiag : ∀ i, J i i=0) + (G f : Observables n) : + Tendsto (fun t : ℝ => stationaryInner J G (semigroup J t (centered J f))) + atTop (nhds 0) := by + simp_rw [← spectral_parseval J hJ hdiag,spectral_semigroup_coordinates] + have he (a : Fin (Fintype.card (Spin n))) : + Tendsto (fun t : ℝ => (spinEigenbasis J hJ hdiag).repr (gibbsEuclideanEquiv J G) a * + (Real.exp (-spinEigenvalues J hJ hdiag a*t)* + (spinEigenbasis J hJ hdiag).repr (gibbsEuclideanEquiv J (centered J f)) a)) + atTop (nhds 0) := by + by_cases ha : spinEigenvalues J hJ hdiag a=0 + · simp only [centered_spectral_coordinate_zero J hJ hdiag f a ha,mul_zero] + exact tendsto_const_nhds + · have hp := lt_of_le_of_ne (spinEigenvalues_nonneg J hJ hdiag a) (Ne.symm ha) + have hh := Real.tendsto_exp_atBot.comp + (tendsto_id.const_mul_atTop_of_neg (neg_lt_zero.mpr hp)) + simpa only [Function.comp_def,id_eq,zero_mul,mul_zero] using + (hh.mul_const ((spinEigenbasis J hJ hdiag).repr (gibbsEuclideanEquiv J (centered J f)) a)).const_mul + ((spinEigenbasis J hJ hdiag).repr (gibbsEuclideanEquiv J G) a) + simpa only [Finset.sum_const_zero] using tendsto_finsetSum Finset.univ (fun a _ => he a) + +theorem exact_gradient_pairing_integral_tendsto {n : ℕ} (J : Interaction n) + (hJ : ∀ i j, J i j=J j i) (hdiag : ∀ i, J i i=0) + (G f : Observables n) : + Tendsto (fun T : ℝ => ∫ t in (0 : ℝ)..T, weightedInner J (gradientCLM n G) + (gradientSemigroup J t (gradientCLM n (centered J f)))) atTop + (nhds (stationaryInner J G (centered J f))) := by + simp_rw [exact_gradient_pairing_integral J hJ hdiag] + simpa only [sub_zero] using tendsto_const_nhds.sub + (stationaryInner_centered_semigroup_tendsto_zero J hJ hdiag G f) + +lemma centered_semigroup_gap_variance {n : ℕ} (J : Interaction n) + (hJ : ∀ i j, J i j=J j i) (hdiag : ∀ i, J i i=0) + {γ : ℝ} (hγ : HasGap J γ) (f : Observables n) {t : ℝ} (ht : 0 ≤ t) : + stationaryInner J (semigroup J t (centered J f)) (semigroup J t (centered J f)) ≤ + Real.exp (-2*γ*t)*gibbsVariance J f := by + rw [← centered_variance,← spectral_parseval J hJ hdiag,← spectral_parseval J hJ hdiag, + Finset.mul_sum] + simp_rw [spectral_semigroup_coordinates] + apply Finset.sum_le_sum + intro a _ + by_cases ha : spinEigenvalues J hJ hdiag a=0 + · simp only [centered_spectral_coordinate_zero J hJ hdiag f a ha,mul_zero,le_refl] + · have hp := lt_of_le_of_ne (spinEigenvalues_nonneg J hJ hdiag a) (Ne.symm ha) + have hle := gap_le_positive_eigenvalue J hJ hdiag hγ a hp + have he : Real.exp (-spinEigenvalues J hJ hdiag a*t)^2 ≤ Real.exp (-2*γ*t) := by + rw [← Real.exp_nat_mul] + apply Real.exp_le_exp.mpr + norm_num only [Nat.cast_ofNat] + nlinarith only [mul_nonneg (sub_nonneg.mpr hle) ht] + have hh := mul_le_mul_of_nonneg_right he + (sq_nonneg ((spinEigenbasis J hJ hdiag).repr (gibbsEuclideanEquiv J (centered J f)) a)) + convert hh using 1 <;> ring + +lemma stationaryInner_cauchy_sq {n : ℕ} (J : Interaction n) (f g : Observables n) : + (stationaryInner J f g)^2 ≤ stationaryInner J f f*stationaryInner J g g := by + simpa only [stationaryInner,gibbsExpectation,pow_two,mul_assoc] using + Static.weighted_cauchy_sq (gibbs J) f g (fun x => (gibbs_pos J x).le) + +lemma gibbsVariance_nonneg {n : ℕ} (J : Interaction n) (f : Observables n) : + 0 ≤ gibbsVariance J f := by + exact Finset.sum_nonneg (fun x _ => mul_nonneg (gibbs_pos J x).le (sq_nonneg _)) + +theorem exact_gradient_pairing_uniform_tail {n : ℕ} (J : Interaction n) + (hJ : ∀ i j, J i j=J j i) (hdiag : ∀ i, J i i=0) + {γ : ℝ} (hγ0 : 0 ≤ γ) (hγ : HasGap J γ) + (G f : Observables n) {T : ℝ} (hT : 0 ≤ T) : + γ^2 * (stationaryInner J (centered J G) (centered J f) - + ∫ t in (0 : ℝ)..T, weightedInner J (gradientCLM n (centered J G)) + (gradientSemigroup J t (gradientCLM n (centered J f))))^2 ≤ + Real.exp (-2*γ*T)*dirichlet J G G*dirichlet J f f := by + rw [exact_gradient_pairing_integral J hJ hdiag,sub_sub_cancel] + have hc := stationaryInner_cauchy_sq J (centered J G) (semigroup J T (centered J f)) + rw [centered_variance] at hc + have he := mul_le_mul_of_nonneg_left (centered_semigroup_gap_variance J hJ hdiag hγ f hT) + (gibbsVariance_nonneg J G) + have hsmall := mul_le_mul_of_nonneg_left (hc.trans he) (sq_nonneg γ) + have hlarge := mul_le_mul (hγ G) (hγ f) + (mul_nonneg hγ0 (gibbsVariance_nonneg J f)) (dirichlet_nonneg J G) + have hb := mul_le_mul_of_nonneg_left hlarge (Real.exp_pos (-2*γ*T)).le + nlinarith only [hsmall,hb] + +end SKGapCutoff + +open MeasureTheory Filter +open scoped Topology + +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/JumpEnergy.lean b/lean/OAI/Probability/SKGap/Localization/JumpEnergy.lean new file mode 100644 index 0000000000000000000000000000000000000000..18d8c5c178440dfcb49c1e2ec6efc05e154740a9 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/JumpEnergy.lean @@ -0,0 +1,200 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.Magnetization + +namespace OAI + +section +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +namespace SKGapCutoff + +lemma semigroup_hasDerivAt {n : ℕ} (J : Interaction n) (t : ℝ) : + HasDerivAt (fun s : ℝ => semigroup J s) + (semigroup J t * generatorCLM J) t := + hasDerivAt_exp_smul_const (generatorCLM J) t + +lemma semigroup_hasDerivAt' {n : ℕ} (J : Interaction n) (t : ℝ) : + HasDerivAt (fun s : ℝ => semigroup J s) + (generatorCLM J * semigroup J t) t := + hasDerivAt_exp_smul_const' (generatorCLM J) t + +lemma semigroup_apply_hasDerivAt {n : ℕ} (J : Interaction n) (f : Observables n) (t : ℝ) : + HasDerivAt (fun s : ℝ => semigroup J s f) (semigroup J t (generator J f)) t := by + simpa only [mul_apply_eq_comp, map_zero, add_zero, generatorCLM, generatorLM, + LinearMap.coe_toContinuousLinearMap', LinearMap.coe_mk, AddHom.coe_mk] using + (semigroup_hasDerivAt J t).clm_apply (hasDerivAt_const t f) + +lemma semigroup_apply_hasDerivAt' {n : ℕ} (J : Interaction n) (f : Observables n) (t : ℝ) : + HasDerivAt (fun s : ℝ => semigroup J s f) (generator J (semigroup J t f)) t := by + simpa only [mul_apply_eq_comp, map_zero, add_zero, generatorCLM, generatorLM, + LinearMap.coe_toContinuousLinearMap', LinearMap.coe_mk, AddHom.coe_mk] using + (semigroup_hasDerivAt' J t).clm_apply (hasDerivAt_const t f) + +lemma semigroup_continuous {n : ℕ} (J : Interaction n) : + Continuous (fun s : ℝ => semigroup J s) := by + have hd : Differentiable ℝ (fun s : ℝ => semigroup J s) := + fun t => (semigroup_hasDerivAt J t).differentiableAt + exact hd.continuous + +@[simp] lemma semigroup_zero {n : ℕ} (J : Interaction n) : semigroup J 0 = 1 := by + simp [semigroup] + +noncomputable def jumpEnergy {n : ℕ} (J : Interaction n) (f : Observables n) (x : Spin n) : ℝ := + 2 * ∑ i, (1 - mean J x i * spin x i) * (halfDiff i f x) ^ 2 + +lemma generator_square {n : ℕ} (J : Interaction n) (f : Observables n) : + generator J (fun x => f x ^ 2) = + fun x => 2 * f x * generator J f x + jumpEnergy J f x := by + funext x + simpa only [pow_two, mul_assoc, ← two_mul, jumpEnergy] using generator_mul J f f x + +lemma backward_flow_hasDerivAt {n : ℕ} (J : Interaction n) (f : Observables n) (d s : ℝ) : + HasDerivAt (fun r : ℝ => semigroup J (d - r) f) + (fun x => -generator J (semigroup J (d - s) f) x) s := by + have h := (semigroup_apply_hasDerivAt' J f (d - s)).scomp s + ((hasDerivAt_id s).const_sub d) + simpa only [id_eq, neg_smul, one_smul, Pi.neg_def, Function.comp_def] using h + +lemma backward_square_hasDerivAt {n : ℕ} (J : Interaction n) (f : Observables n) (d s : ℝ) : + HasDerivAt (fun r : ℝ => fun x : Spin n => (semigroup J (d - r) f x) ^ 2) + (fun x => -2 * semigroup J (d - s) f x * generator J (semigroup J (d - s) f) x) s := by + apply hasDerivAt_pi.mpr + intro x + have h := (hasDerivAt_pi.mp (backward_flow_hasDerivAt J f d s) x).pow 2 + have he : (2 : ℝ) * semigroup J (d - s) f x * + -generator J (semigroup J (d - s) f) x = + -2 * semigroup J (d - s) f x * generator J (semigroup J (d - s) f) x := by ring + convert h using 1 + simpa only [Nat.cast_ofNat, Nat.reduceSub, pow_one] using he.symm + +lemma interpolated_square_hasDerivAt {n : ℕ} (J : Interaction n) (f : Observables n) (d s : ℝ) : + HasDerivAt (fun r : ℝ => semigroup J r + (fun x => (semigroup J (d - r) f x) ^ 2)) + (semigroup J s (jumpEnergy J (semigroup J (d - s) f))) s := by + have h := (semigroup_hasDerivAt J s).clm_apply (backward_square_hasDerivAt J f d s) + apply h.congr_deriv + simp only [mul_apply_eq_comp] + change semigroup J s (generator J (fun x => semigroup J (d - s) f x ^ 2)) + + semigroup J s (fun x => -2 * semigroup J (d - s) f x * + generator J (semigroup J (d - s) f) x) = _ + rw [← map_add] + congr 1 + funext x + rw [generator_square] + simp only [Pi.add_apply] + ring + +lemma jumpEnergy_continuous {n : ℕ} (J : Interaction n) : + Continuous (jumpEnergy J) := by + unfold jumpEnergy halfDiff + fun_prop + +lemma interpolated_energy_continuous {n : ℕ} (J : Interaction n) (f : Observables n) + (d : ℝ) (x : Spin n) : + Continuous (fun s : ℝ => semigroup J s (jumpEnergy J (semigroup J (d - s) f)) x) := by + have hc : Continuous (fun s : ℝ => semigroup J (d - s) f) := + ((semigroup_continuous J).comp (continuous_const.sub continuous_id)).clm_apply continuous_const + exact continuous_apply x |>.comp ((semigroup_continuous J).clm_apply + ((jumpEnergy_continuous J).comp hc)) + +lemma semigroup_variance_integral {n : ℕ} (J : Interaction n) (f : Observables n) + (d : ℝ) (x : Spin n) : + semigroup J d (fun y => f y ^ 2) x - (semigroup J d f x) ^ 2 = + ∫ s in (0 : ℝ)..d, semigroup J s (jumpEnergy J (semigroup J (d - s) f)) x := by + have hd (s : ℝ) := hasDerivAt_pi.mp (interpolated_square_hasDerivAt J f d s) x + have hi := (interpolated_energy_continuous J f d x).intervalIntegrable + (μ := MeasureTheory.volume) 0 d + have he := intervalIntegral.integral_eq_sub_of_hasDerivAt (fun s _ => hd s) hi + simpa only [sub_self, sub_zero, semigroup_zero, one_apply_eq_self] using he.symm + +lemma jumpWeight_bounds {n : ℕ} (J : Interaction n) (x : Spin n) (i : Fin n) : + 0 ≤ 1 - mean J x i * spin x i ∧ 1 - mean J x i * spin x i ≤ 2 := by + have hl := Real.neg_one_lt_tanh (field J x i) + have hu := Real.tanh_lt_one (field J x i) + cases hs : x i <;> simp only [spin, hs, Bool.false_eq_true, ↓reduceIte, mul_one, + mul_neg, sub_neg_eq_add, mean] <;> constructor <;> linarith + +lemma jumpEnergy_nonneg {n : ℕ} (J : Interaction n) (f : Observables n) (x : Spin n) : + 0 ≤ jumpEnergy J f x := by + unfold jumpEnergy + exact mul_nonneg (by norm_num) (Finset.sum_nonneg + (fun i _ => mul_nonneg (jumpWeight_bounds J x i).1 (sq_nonneg _))) + +lemma jumpEnergy_le_gradient {n : ℕ} (J : Interaction n) (f : Observables n) (x : Spin n) : + jumpEnergy J f x ≤ 4 * ∑ i, (halfDiff i f x) ^ 2 := by + unfold jumpEnergy + calc + _ ≤ 2 * ∑ i, 2 * (halfDiff i f x) ^ 2 := by + apply mul_le_mul_of_nonneg_left (Finset.sum_le_sum _) (by norm_num) + intro i _ + exact mul_le_mul_of_nonneg_right (jumpWeight_bounds J x i).2 (sq_nonneg _) + _ = _ := by rw [← Finset.mul_sum]; ring + +lemma semigroup_mono {n : ℕ} (J : Interaction n) (t : ℝ) (ht : 0 ≤ t) + {f g : Observables n} (hfg : ∀ x, f x ≤ g x) (x : Spin n) : + semigroup J t f x ≤ semigroup J t g x := by + have h := semigroup_nonneg J t ht (g - f) (fun x => sub_nonneg.mpr (hfg x)) x + simpa only [map_sub, Pi.sub_apply, sub_nonneg] using h + +lemma semigroup_le_const {n : ℕ} (J : Interaction n) (t : ℝ) (ht : 0 ≤ t) + {f : Observables n} {C : ℝ} (hf : ∀ x, f x ≤ C) (x : Spin n) : + semigroup J t f x ≤ C := by + simpa only [semigroup_const] using semigroup_mono J t ht hf x + +theorem semigroup_variance_le {n : ℕ} (J : Interaction n) (f : Observables n) + (d : ℝ) (hd : 0 ≤ d) (b : ℝ → ℝ) + (hb : IntervalIntegrable b MeasureTheory.volume 0 d) + (hbound : ∀ r ∈ Set.Icc (0 : ℝ) d, ∀ x, ∑ i, (halfDiff i (semigroup J r f) x) ^ 2 ≤ b r) + (x : Spin n) : + semigroup J d (fun y => f y ^ 2) x - (semigroup J d f x) ^ 2 ≤ + 4 * ∫ r in (0 : ℝ)..d, b r := by + rw [semigroup_variance_integral] + have hbr : IntervalIntegrable (fun s => b (d - s)) MeasureTheory.volume 0 d := by + simpa only [sub_self, sub_zero] using (hb.comp_sub_left d).symm + calc + _ ≤ ∫ s in (0 : ℝ)..d, 4 * b (d - s) := by + apply intervalIntegral.integral_mono_on hd + ((interpolated_energy_continuous J f d x).intervalIntegrable 0 d) + (hbr.const_mul 4) + intro s hs + apply semigroup_le_const J s hs.1 + intro y + exact (jumpEnergy_le_gradient J (semigroup J (d - s) f) y).trans + (mul_le_mul_of_nonneg_left (hbound (d - s) ⟨sub_nonneg.mpr hs.2, by linarith [hs.1]⟩ y) + (by norm_num)) + _ = _ := by + rw [intervalIntegral.integral_const_mul, intervalIntegral.integral_comp_sub_left] + simp only [sub_self, sub_zero] + +end SKGapCutoff + +lemma real_exp_remainder_le (z : ℝ) : + Real.exp z - 1 - z ≤ z ^ 2 * Real.exp |z| / 2 := by + by_cases hz : z = 0 + · simp [hz] + have hn : (0 : ℝ) ≠ z := Ne.symm hz + obtain ⟨u, hu, he⟩ := taylor_mean_remainder_lagrange_iteratedDeriv + (n := 1) (f := Real.exp) hn Real.contDiff_exp.contDiffOn + have hd : derivWithin Real.exp (Set.uIcc 0 z) 0 = 1 := by + simpa using (Real.hasDerivAt_exp 0).hasDerivWithinAt.derivWithin + ((uniqueDiffOn_uIcc hn) 0 (Set.left_mem_uIcc)) + have hi : iteratedDeriv 2 Real.exp = Real.exp := by + simpa using iteratedDeriv_exp_const_mul 2 (1 : ℝ) + simp [taylorWithinEval_succ, iteratedDerivWithin_one, hd, hi] at he + have hu' : u ≤ |z| := by + calc + u ≤ max 0 z := le_of_lt hu.2 + _ ≤ |z| := max_le (abs_nonneg _) (le_abs_self _) + calc + Real.exp z - 1 - z = Real.exp u * z ^ 2 / 2 := by linarith [he] + _ ≤ z ^ 2 * Real.exp |z| / 2 := by + have h := mul_le_mul_of_nonneg_right (Real.exp_le_exp.mpr hu') (sq_nonneg z) + nlinarith + +open scoped BigOperators + +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/JumpWeight.lean b/lean/OAI/Probability/SKGap/Localization/JumpWeight.lean new file mode 100644 index 0000000000000000000000000000000000000000..7b0c616b0bb1f304cfb7feb7f4b00396e84fd9d8 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/JumpWeight.lean @@ -0,0 +1,304 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.JumpEnergy + +namespace OAI + +section +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open scoped BigOperators +namespace SKGapCutoff + +noncomputable def jumpWeight {n : ℕ} (J : Interaction n) (x : Spin n) (j : Fin n) : ℝ := + 1 - mean J x j * spin x j + +lemma jumpWeight_pos {n : ℕ} (J : Interaction n) (x : Spin n) (j : Fin n) : + 0 < jumpWeight J x j := by + have ht := Real.abs_tanh_lt_one (field J x j) + have hm : |mean J x j| < 1 := ht + unfold jumpWeight spin + cases x j <;> simp only [Bool.false_eq_true, ↓reduceIte, mul_neg, mul_one] <;> + linarith [(abs_lt.mp hm).1, (abs_lt.mp hm).2] + +noncomputable def influence {n : ℕ} (J : Interaction n) (x : Spin n) : Interaction n := + fun i j => halfDiff i (fun y => mean J y j) x + +noncomputable def vectorSquare {n : ℕ} (p : VectorFields n) (x : Spin n) : ℝ := + ∑ i, p x i ^ 2 + +noncomputable def vectorDissipation {n : ℕ} (J : Interaction n) + (p : VectorFields n) (x : Spin n) : ℝ := + ∑ i, ∑ j, jumpWeight J x j * (halfDiff j (fun y => p y i) x) ^ 2 + +lemma vectorSquare_nonneg {n : ℕ} (p : VectorFields n) (x : Spin n) : + 0 ≤ vectorSquare p x := Finset.sum_nonneg (fun _ _ => sq_nonneg _) + +lemma vectorDissipation_nonneg {n : ℕ} (J : Interaction n) + (p : VectorFields n) (x : Spin n) : 0 ≤ vectorDissipation J p x := by + exact Finset.sum_nonneg (fun _ _ => Finset.sum_nonneg (fun j _ => + mul_nonneg (jumpWeight_pos J x j).le (sq_nonneg _))) + +lemma generator_vectorSquare {n : ℕ} (J : Interaction n) + (p : VectorFields n) (x : Spin n) : + generator J (vectorSquare p) x = ∑ i, generator J (fun y => p y i ^ 2) x := by + have hv : vectorSquare p = ∑ i, fun y => p y i ^ 2 := by + funext y + simp only [vectorSquare, Finset.sum_apply] + rw [hv] + change generatorLM J (∑ i, fun y => p y i ^ 2) x = _ + rw [map_sum, Finset.sum_apply] + rfl + +lemma gradient_square_identity {n : ℕ} (J : Interaction n) + (p : VectorFields n) (x : Spin n) : + (∑ i, 2 * p x i * gradientGenerator J p x i) - generator J (vectorSquare p) x = + -2 * vectorSquare p x + + 2 * ∑ i, p x i * (∑ j, influence J x i j * p x j) - + 4 * ∑ i, (p x i * spin x i) * (∑ j, influence J x i j * halfDiff j (fun y => p y i) x) - + 2 * vectorDissipation J p x := by + rw [generator_vectorSquare, ← Finset.sum_sub_distrib] + have hloc (i : Fin n) : + 2 * p x i * gradientGenerator J p x i - generator J (fun y => p y i ^ 2) x = + -2 * p x i ^ 2 + 2 * (p x i * (∑ j, influence J x i j * p x j)) - + 4 * ((p x i * spin x i) * (∑ j, influence J x i j * halfDiff j (fun y => p y i) x)) - + 2 * (∑ j, jumpWeight J x j * (halfDiff j (fun y => p y i) x) ^ 2) := by + rw [generator_square] + dsimp only [gradientGenerator, influence, jumpEnergy, jumpWeight] + ring + simp_rw [hloc] + simp only [Finset.sum_sub_distrib, Finset.sum_add_distrib, ← Finset.mul_sum, + vectorSquare, vectorDissipation] + +lemma weighted_cross_young (q a d w : ℝ) (hw : 0 < w) : + -4 * q * a * d ≤ 4 * (a ^ 2 / w) * q ^ 2 + w * d ^ 2 := by + apply (mul_le_mul_iff_left₀ hw).mp + have he : (4 * (a ^ 2 / w) * q ^ 2 + w * d ^ 2) * w = + 4 * (q*a)^2 + (w*d)^2 := by field_simp + rw [he] + nlinarith [sq_nonneg (2*q*a+w*d)] + +lemma gradient_first_order_bound {n : ℕ} (J : Interaction n) + (p : VectorFields n) (x : Spin n) (R : ℝ) + (hR : ∀ i, ∑ j, influence J x i j ^ 2 / jumpWeight J x j ≤ R) : + -4 * (∑ i, (p x i * spin x i) * + (∑ j, influence J x i j * halfDiff j (fun y => p y i) x)) ≤ + 4 * R * vectorSquare p x + vectorDissipation J p x := by + have hrow (i : Fin n) : + -4 * ((p x i * spin x i) * + (∑ j, influence J x i j * halfDiff j (fun y => p y i) x)) ≤ + 4 * R * p x i ^ 2 + + ∑ j, jumpWeight J x j * (halfDiff j (fun y => p y i) x) ^ 2 := by + have hs := Finset.sum_le_sum (s := Finset.univ) (fun j _ => weighted_cross_young + (p x i * spin x i) (influence J x i j) + (halfDiff j (fun y => p y i) x) (jumpWeight J x j) (jumpWeight_pos J x j)) + simp only [mul_pow, spin_sq, mul_one, Finset.sum_add_distrib, + ← Finset.sum_mul, ← Finset.mul_sum] at hs + calc + _ ≤ 4 * (∑ j, influence J x i j ^ 2 / jumpWeight J x j) * p x i ^ 2 + + ∑ j, jumpWeight J x j * (halfDiff j (fun y => p y i) x) ^ 2 := by + have he : -4 * ((p x i * spin x i) * + (∑ j, influence J x i j * halfDiff j (fun y => p y i) x)) = + ∑ j, -4 * (p x i * spin x i) * influence J x i j * + halfDiff j (fun y => p y i) x := by + simp only [Finset.mul_sum] + apply Finset.sum_congr rfl + intro j _ + ring + rw [he] + exact hs + _ ≤ _ := by + have hm := mul_le_mul_of_nonneg_right (hR i) (sq_nonneg (p x i)) + nlinarith + have hs := Finset.sum_le_sum (s := Finset.univ) (fun i _ => hrow i) + simpa only [Finset.sum_add_distrib, ← Finset.mul_sum, + vectorSquare, vectorDissipation] using hs + +lemma gradient_square_le {n : ℕ} (J : Interaction n) + (p : VectorFields n) (x : Spin n) (A R : ℝ) + (hA : ∑ i, p x i * (∑ j, influence J x i j * p x j) ≤ A * vectorSquare p x) + (hR : ∀ i, ∑ j, influence J x i j ^ 2 / jumpWeight J x j ≤ R) : + (∑ i, 2 * p x i * gradientGenerator J p x i) - generator J (vectorSquare p) x ≤ + (2*A+4*R-2) * vectorSquare p x - vectorDissipation J p x := by + rw [gradient_square_identity] + have h := gradient_first_order_bound J p x R hR + linarith + +lemma gradientSemigroup_apply_hasDerivAt {n : ℕ} (J : Interaction n) + (p : VectorFields n) (t : ℝ) : + HasDerivAt (fun s : ℝ => gradientSemigroup J s p) + (gradientGenerator J (gradientSemigroup J t p)) t := by + simpa only [gradientSemigroup, mul_apply_eq_comp, map_zero, add_zero, gradientGeneratorCLM, + gradientGeneratorLM, LinearMap.coe_toContinuousLinearMap', LinearMap.coe_mk, + AddHom.coe_mk] using + (hasDerivAt_exp_smul_const' (gradientGeneratorCLM J) t).clm_apply + (hasDerivAt_const t p) + +lemma backward_gradient_hasDerivAt {n : ℕ} (J : Interaction n) + (p : VectorFields n) (t s : ℝ) : + HasDerivAt (fun r : ℝ => gradientSemigroup J (t-r) p) + (-gradientGenerator J (gradientSemigroup J (t-s) p)) s := by + have h := (gradientSemigroup_apply_hasDerivAt J p (t-s)).scomp s + ((hasDerivAt_id s).const_sub t) + simpa only [id_eq, neg_smul, one_smul, Function.comp_def] using h + +lemma backward_vectorSquare_hasDerivAt {n : ℕ} (J : Interaction n) + (p : VectorFields n) (t s : ℝ) : + HasDerivAt (fun r : ℝ => vectorSquare (gradientSemigroup J (t-r) p)) + (fun x => -(∑ i, 2 * gradientSemigroup J (t-s) p x i * + gradientGenerator J (gradientSemigroup J (t-s) p) x i)) s := by + apply hasDerivAt_pi.mpr + intro x + have hi (i : Fin n) := (hasDerivAt_pi.mp + (hasDerivAt_pi.mp (backward_gradient_hasDerivAt J p t s) x) i).pow 2 + have hs := HasDerivAt.fun_sum (u := Finset.univ) (fun i _ => hi i) + simpa only [vectorSquare, Pi.pow_apply, Nat.cast_ofNat, Nat.reduceSub, pow_one, Pi.neg_apply, mul_neg, + Finset.sum_neg_distrib] using hs + +noncomputable def roughDefect {n : ℕ} (J : Interaction n) (C : ℝ) + (p : VectorFields n) (x : Spin n) : ℝ := + C * vectorSquare p x + generator J (vectorSquare p) x - + ∑ i, 2 * p x i * gradientGenerator J p x i + +lemma roughDefect_nonneg {n : ℕ} (J : Interaction n) + (p : VectorFields n) (x : Spin n) (A R : ℝ) + (hA : ∑ i, p x i * (∑ j, influence J x i j * p x j) ≤ A * vectorSquare p x) + (hR : ∀ i, ∑ j, influence J x i j ^ 2 / jumpWeight J x j ≤ R) : + 0 ≤ roughDefect J (2*A+4*R-2) p x := by + have hs := gradient_square_le J p x A R hA hR + have hd := vectorDissipation_nonneg J p x + unfold roughDefect + linarith + +lemma interpolated_vectorSquare_hasDerivAt {n : ℕ} (J : Interaction n) + (p : VectorFields n) (t C s : ℝ) (x : Spin n) : + HasDerivAt (fun r : ℝ => Real.exp (C*r) * semigroup J r + (vectorSquare (gradientSemigroup J (t-r) p)) x) + (Real.exp (C*s) * semigroup J s + (roughDefect J C (gradientSemigroup J (t-s) p)) x) s := by + have hv := (semigroup_hasDerivAt J s).clm_apply + (backward_vectorSquare_hasDerivAt J p t s) + have he := (hasDerivAt_id s).const_mul C |>.exp + have hh := he.mul (hasDerivAt_pi.mp hv x) + apply hh.congr_deriv + simp only [mul_one, mul_apply_eq_comp] + let q := gradientSemigroup J (t-s) p + change Real.exp (C*s) * C * semigroup J s (vectorSquare q) x + + Real.exp (C*s) * (semigroup J s (generator J (vectorSquare q)) + + semigroup J s (fun y => -(∑ i, 2*q y i*gradientGenerator J q y i))) x = _ + have hd : roughDefect J C q = C • vectorSquare q + generator J (vectorSquare q) + + (fun y => -(∑ i, 2*q y i*gradientGenerator J q y i)) := by + funext y + simp only [roughDefect, Pi.add_apply, Pi.smul_apply, smul_eq_mul, sub_eq_add_neg] + rw [hd, map_add, map_add, map_smul] + simp only [Pi.add_apply, Pi.smul_apply, smul_eq_mul] + ring + +lemma rough_vector_propagation {n : ℕ} (J : Interaction n) (A R : ℝ) + (hA : ∀ x (q : Fin n → ℝ), + ∑ i, q i * (∑ j, influence J x i j * q j) ≤ A * ∑ i, q i ^ 2) + (hR : ∀ x i, ∑ j, influence J x i j ^ 2 / jumpWeight J x j ≤ R) + (p : VectorFields n) (t : ℝ) (ht : 0 ≤ t) (x : Spin n) : + vectorSquare (gradientSemigroup J t p) x ≤ + Real.exp ((2*A+4*R-2)*t) * semigroup J t (vectorSquare p) x := by + let C := 2*A+4*R-2 + let F (s : ℝ) := Real.exp (C*s) * semigroup J s + (vectorSquare (gradientSemigroup J (t-s) p)) x + let F' (s : ℝ) := Real.exp (C*s) * semigroup J s + (roughDefect J C (gradientSemigroup J (t-s) p)) x + have hd (s : ℝ) : HasDerivAt F (F' s) s := + interpolated_vectorSquare_hasDerivAt J p t C s x + have hc : Continuous F := (show Differentiable ℝ F from + fun s => (hd s).differentiableAt).continuous + have hpos (s : ℝ) (hs : 0 ≤ s) : 0 ≤ F' s := by + apply mul_nonneg (Real.exp_pos _).le + apply semigroup_nonneg J s hs + intro y + exact roughDefect_nonneg J _ y A R (hA y _) (hR y) + have hm : MonotoneOn F (Set.Icc 0 t) := + monotoneOn_of_hasDerivWithinAt_nonneg (convex_Icc 0 t) hc.continuousOn + (fun s _ => (hd s).hasDerivWithinAt) + (fun s hs => hpos s ((interior_subset hs).1)) + have hv := hm (show (0 : ℝ) ∈ Set.Icc 0 t from ⟨le_rfl, ht⟩) + (show t ∈ Set.Icc (0 : ℝ) t from ⟨ht, le_rfl⟩) ht + simpa only [F, mul_zero, Real.exp_zero, semigroup_zero, sub_zero, sub_self, + gradientSemigroup, zero_smul, NormedSpace.exp_zero, one_apply_eq_self, one_mul, C] using hv + +lemma gradientSemigroup_continuous {n : ℕ} (J : Interaction n) (p : VectorFields n) : + Continuous (fun t : ℝ => gradientSemigroup J t p) := + (show Differentiable ℝ (fun t : ℝ => gradientSemigroup J t p) from + fun t => (gradientSemigroup_apply_hasDerivAt J p t).differentiableAt).continuous + +lemma vectorDissipation_continuous {n : ℕ} (J : Interaction n) : + Continuous (vectorDissipation J) := by + unfold vectorDissipation halfDiff + fun_prop + +lemma roughDefect_continuous {n : ℕ} (J : Interaction n) (C : ℝ) : + Continuous (roughDefect J C) := by + unfold roughDefect vectorSquare gradientGenerator generator halfDiff + fun_prop + +lemma interpolated_vector_continuous {n : ℕ} (J : Interaction n) + (p : VectorFields n) (G : VectorFields n → Observables n) + (hG : Continuous G) (C t : ℝ) (x : Spin n) : + Continuous (fun s : ℝ => Real.exp (C*s) * + semigroup J s (G (gradientSemigroup J (t-s) p)) x) := by + have hq : Continuous (fun s : ℝ => gradientSemigroup J (t-s) p) := + (gradientSemigroup_continuous J p).comp (continuous_const.sub continuous_id) + exact (continuous_const.mul continuous_id).rexp.mul + ((continuous_apply x).comp ((semigroup_continuous J).clm_apply (hG.comp hq))) + +lemma rough_vector_dissipation {n : ℕ} (J : Interaction n) (A R : ℝ) + (hA : ∀ x (q : Fin n → ℝ), + ∑ i, q i * (∑ j, influence J x i j * q j) ≤ A * ∑ i, q i ^ 2) + (hR : ∀ x i, ∑ j, influence J x i j ^ 2 / jumpWeight J x j ≤ R) + (p : VectorFields n) (t : ℝ) (ht : 0 ≤ t) (x : Spin n) : + (∫ s in (0 : ℝ)..t, Real.exp ((2*A+4*R-2)*s) * + semigroup J s (vectorDissipation J (gradientSemigroup J (t-s) p)) x) ≤ + Real.exp ((2*A+4*R-2)*t) * semigroup J t (vectorSquare p) x - + vectorSquare (gradientSemigroup J t p) x := by + let C := 2*A+4*R-2 + have h1 := interpolated_vector_continuous J p (vectorDissipation J) + (vectorDissipation_continuous J) C t x + have h2 := interpolated_vector_continuous J p (roughDefect J C) + (roughDefect_continuous J C) C t x + have he := intervalIntegral.integral_eq_sub_of_hasDerivAt + (fun s _ => interpolated_vectorSquare_hasDerivAt J p t C s x) + (h2.intervalIntegrable (μ := MeasureTheory.volume) 0 t) + have hi : (∫ s in (0 : ℝ)..t, Real.exp (C*s) * + semigroup J s (vectorDissipation J (gradientSemigroup J (t-s) p)) x) ≤ + ∫ s in (0 : ℝ)..t, Real.exp (C*s) * + semigroup J s (roughDefect J C (gradientSemigroup J (t-s) p)) x := by + apply intervalIntegral.integral_mono_on ht (h1.intervalIntegrable 0 t) (h2.intervalIntegrable 0 t) + intro s hs + apply mul_le_mul_of_nonneg_left _ (Real.exp_pos _).le + apply semigroup_mono J s hs.1 + intro y + have hg := gradient_square_le J (gradientSemigroup J (t-s) p) y A R (hA y _) (hR y) + dsimp only [roughDefect, C] + linarith + rw [he] at hi + simpa only [C, sub_self, sub_zero, mul_zero, Real.exp_zero, semigroup_zero, + gradientSemigroup, zero_smul, NormedSpace.exp_zero, one_apply_eq_self, one_mul] using hi + +end SKGapCutoff + +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise + +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/KernelDensity.lean b/lean/OAI/Probability/SKGap/Localization/KernelDensity.lean new file mode 100644 index 0000000000000000000000000000000000000000..4ac9be9133df967b6c341488891ae8d7fcb280c9 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/KernelDensity.lean @@ -0,0 +1,76 @@ +import Mathlib +import OAI.Probability.SKGap.Model + +namespace OAI + +section +noncomputable section +namespace SKGap.GaussianDensity +open MeasureTheory ProbabilityTheory Matrix +open scoped BigOperators ENNReal NNReal +variable {ι κ : Type*} [Fintype κ] + +theorem additive_noise_lintegral (μ : Measure (ι → ℝ)) [SFinite μ] + (φ : (κ → ℝ) → ℝ≥0∞) (hφ : Measurable φ) + (L : (ι → ℝ) → (κ → ℝ)) (hL : Measurable L) + (F : (ι → ℝ) × (κ → ℝ) → ℝ≥0∞) (hF : Measurable F) : + (∫⁻ z, F (z.1,L z.1+z.2) ∂μ.prod ((volume : Measure (κ → ℝ)).withDensity φ)) = + ∫⁻ y, ∫⁻ x, φ (y-L x)*F (x,y) ∂μ ∂volume := by + rw [lintegral_prod _ (by fun_prop)] + have he (x : ι → ℝ) : + (∫⁻ e, F (x,L x+e) ∂(volume : Measure (κ → ℝ)).withDensity φ)= + ∫⁻ y, φ (y-L x)*F (x,y) ∂volume := by + rw [lintegral_withDensity_eq_lintegral_mul _ hφ (by fun_prop)] + have hh := lintegral_add_left_eq_self + (μ := (volume : Measure (κ → ℝ))) (fun y => φ (y-L x)*F (x,y)) (L x) + simpa only [Pi.mul_apply,add_sub_cancel_left] using hh + simp only [he] + exact lintegral_lintegral_swap (by fun_prop) + +theorem residual_density_lintegral (ρ : Measure (ι → ℝ)) [SFinite ρ] + (p : (κ → ℝ) → ℝ≥0∞) (hp : Measurable p) + (K : (κ → ℝ) → (ι → ℝ)) (hK : Measurable K) + (F : (ι → ℝ) × (κ → ℝ) → ℝ≥0∞) (hF : Measurable F) : + (∫⁻ z, F (z.1+K z.2,z.2) ∂ρ.prod ((volume : Measure (κ → ℝ)).withDensity p)) = + ∫⁻ y, p y*(∫⁻ r, F (r+K y,y) ∂ρ) ∂volume := by + rw [lintegral_prod_symm _ (by fun_prop), + lintegral_withDensity_eq_lintegral_mul _ hp (by fun_prop)] + rfl + +theorem kernel_test_ae (μ ρ : Measure (ι → ℝ)) [SFinite μ] [SFinite ρ] + {φ p : (κ → ℝ) → ℝ≥0∞} (hφ : Measurable φ) (hp : Measurable p) + {L : (ι → ℝ) → (κ → ℝ)} {K : (κ → ℝ) → (ι → ℝ)} + (hL : Measurable L) (hK : Measurable K) + (hjoint : (μ.prod ((volume : Measure (κ → ℝ)).withDensity φ)).map + (fun z => (z.1,L z.1+z.2)) = + (ρ.prod ((volume : Measure (κ → ℝ)).withDensity p)).map + (fun z => (z.1+K z.2,z.2))) + (f : (ι → ℝ) → ℝ≥0∞) (hf : Measurable f) : + (fun y => ∫⁻ x, φ (y-L x)*f x ∂μ)=ᵐ[volume] + (fun y => p y*(∫⁻ r, f (r+K y) ∂ρ)) := by + have h1 : Measurable (fun y => ∫⁻ x, φ (y-L x)*f x ∂μ) := by fun_prop + have h2 : Measurable (fun y => p y*(∫⁻ r, f (r+K y) ∂ρ)) := by fun_prop + apply (withDensity_eq_iff_of_sigmaFinite h1.aemeasurable h2.aemeasurable).mp + ext s hs + rw [withDensity_apply _ hs,withDensity_apply _ hs] + let F : (ι → ℝ) × (κ → ℝ) → ℝ≥0∞ := fun z => s.indicator (fun _ => f z.1) z.2 + have hF : Measurable F := by + exact (hf.comp measurable_fst).indicator (hs.preimage measurable_snd) + have hh := congrArg (fun ν => ∫⁻ z, F z ∂ν) hjoint + rw [lintegral_map hF (by fun_prop),lintegral_map hF (by fun_prop), + additive_noise_lintegral μ φ hφ L hL F hF, + residual_density_lintegral ρ p hp K hK F hF] at hh + have he1 (y : κ → ℝ) : (∫⁻ x, φ (y-L x)*F (x,y) ∂μ)= + s.indicator (fun y => ∫⁻ x, φ (y-L x)*f x ∂μ) y := by + by_cases hy : y ∈ s <;> simp [F,hy] + have he2 (y : κ → ℝ) : p y*(∫⁻ r, F (r+K y,y) ∂ρ)= + s.indicator (fun y => p y*(∫⁻ r, f (r+K y) ∂ρ)) y := by + by_cases hy : y ∈ s <;> simp [F,hy] + simp_rw [he1,he2] at hh + simpa only [lintegral_indicator hs] using hh + +end SKGap.GaussianDensity +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/Letter.lean b/lean/OAI/Probability/SKGap/Localization/Letter.lean new file mode 100644 index 0000000000000000000000000000000000000000..de674553f9a2236b43e8b377d27a831f7486e427 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/Letter.lean @@ -0,0 +1,414 @@ +import Mathlib +import OAI.Probability.SKGap.Model + +namespace OAI + +section + +noncomputable section +namespace SKGap.Noncrossing +universe u v + +inductive Letter (D : Type*) where + | diag : D → Letter D + | noise : Letter D + deriving DecidableEq + +inductive Diagram (D : Type*) where + | nil : Diagram D + | diag : D → Diagram D → Diagram D + | arch : Diagram D → Diagram D → Diagram D + deriving DecidableEq + +namespace Diagram +variable {D : Type*} + +def word : Diagram D → List (Letter D) + | nil => [] + | diag a d => .diag a :: d.word + | arch a b => .noise :: (a.word ++ (.noise :: b.word)) + +def size : Diagram D → ℕ + | nil => 0 + | diag _ d => d.size+1 + | arch a b => a.size+b.size+2 + +@[simp] lemma word_length (d : Diagram D) : d.word.length = d.size := by + induction d with + | nil => rfl + | diag a d ih => simp [word, size, ih] + | arch a b ia ib => simp [word, size, ia, ib]; omega + +def insert (outer : Diagram D) (p : ℕ) (inside : Diagram D) : Diagram D := + if p=0 then .arch inside outer else + match outer with + | nil => .arch inside .nil + | diag a d => .diag a (d.insert (p-1) inside) + | arch a b => + if p ≤ a.size+1 then .arch (a.insert (p-1) inside) b + else .arch a (b.insert (p-(a.size+2)) inside) + +@[simp] lemma insert_zero (d e : Diagram D) : d.insert 0 e = .arch e d := by + cases d <;> simp [insert] + +lemma insert_size (d e : Diagram D) (p : ℕ) : + (d.insert p e).size = d.size+e.size+2 := by + induction d generalizing p with + | nil => simp [insert, size] + | diag a d ih => + by_cases hp : p=0 + · simp [insert, hp, size]; omega + · simp [insert, hp, size, ih]; omega + | arch a b ia ib => + by_cases hp : p=0 + · simp [insert, hp, size]; omega + · simp only [insert, hp, ↓reduceIte] + split_ifs <;> simp only [size, ia, ib] <;> omega + +lemma insert_word (d e : Diagram D) (p : ℕ) (hp : p≤d.size) : + (d.insert p e).word = d.word.take p ++ + (.noise :: (e.word ++ (.noise :: d.word.drop p))) := by + induction d generalizing p with + | nil => have : p=0 := by simpa [size] using hp + subst p; simp [insert, word] + | diag a d ih => + cases p with + | zero => simp [word] + | succ p => + have h : p≤d.size := by simpa [size] using hp + simpa [insert, word, List.take_succ_cons, List.drop_succ_cons] using + congrArg (List.cons (.diag a)) (ih p h) + | arch a b ia ib => + cases p with + | zero => simp [word] + | succ p => + by_cases h : p≤a.size + · have he := ia p h + simp only [insert, Nat.succ_ne_zero, ↓reduceIte, Nat.add_one_sub_one] + rw [ite_eq_left (by omega), word, he] + simp [word, List.take_append_of_le_length (l₁ := a.word) (i := p) (by simpa using h), + List.drop_append_of_le_length (l₁ := a.word) (i := p) (by simpa using h), List.append_assoc] + · have h' : p-(a.size+1)≤b.size := by simp only [size] at hp; omega + have he := ib (p-(a.size+1)) h' + simp only [insert, Nat.succ_ne_zero, ↓reduceIte] + rw [ite_eq_right (by omega)] + have hh : p+1-(a.size+2)=p-(a.size+1) := by omega + rw [hh, word, he] + simp only [word, List.take_succ_cons, List.drop_succ_cons] + rw [List.take_append, List.drop_append] + have hle : a.word.length≤p := by simp; omega + rw [List.take_of_length_le hle, List.drop_eq_nil_of_le hle] + simp only [List.nil_append, word_length] + have hk : p-a.size = (p-(a.size+1))+1 := by omega + rw [hk] + simp [List.append_assoc] + +structure Cut (D : Type*) where + start : ℕ + inside : Diagram D + outside : Diagram D + closing : Bool + deriving DecidableEq + +def Cut.diag (a : D) (c : Cut D) : Cut D := + ⟨c.start+1,c.inside,.diag a c.outside,c.closing⟩ +def Cut.inner (b : Diagram D) (c : Cut D) : Cut D := + ⟨c.start+1,c.inside,.arch c.outside b,c.closing⟩ +def Cut.tail (a : Diagram D) (c : Cut D) : Cut D := + ⟨a.size+2+c.start,c.inside,.arch a c.outside,c.closing⟩ + +def cut : Diagram D → ℕ → Option (Cut D) + | nil, _ => none + | diag _ _, 0 => none + | diag a d, i+1 => (d.cut i).map (Cut.diag a) + | arch a b, 0 => some ⟨0,a,b,false⟩ + | arch a b, i+1 => + if i simp [cut] at hc + | diag a d ih => + cases i with + | zero => simp [cut] at hc + | succ i => + simp only [cut, Option.map_eq_some_iff] at hc + obtain ⟨e,he,rfl⟩ := hc + obtain ⟨h1,h2,h3⟩ := ih i e he + refine ⟨by simpa [Cut.diag,size] using h1, ?_, ?_⟩ + · cases hcl : e.closing <;> + simp only [Cut.diag, hcl, Bool.false_eq_true, ↓reduceIte] at h2 ⊢ <;> omega + · simpa [Cut.diag,insert] using congrArg (Diagram.diag a) h3 + | arch a b ia ib => + cases i with + | zero => + simp only [cut,Option.some.injEq] at hc + subst c; simp + | succ i => + simp only [cut] at hc + split_ifs at hc with hi he + · obtain ⟨e,he,rfl⟩ := Option.map_eq_some_iff.mp hc + obtain ⟨h1,h2,h3⟩ := ia i e he + refine ⟨by simp only [Cut.inner,size]; omega, ?_, ?_⟩ + · cases hcl : e.closing <;> + simp only [Cut.inner, hcl, Bool.false_eq_true, ↓reduceIte] at h2 ⊢ <;> omega + · simp only [Cut.inner,insert,Nat.add_eq_zero_iff,Nat.one_ne_zero,and_false, + ↓reduceIte,Nat.add_one_sub_one] + rw [ite_eq_left (by omega),h3] + · simp only [Option.some.injEq] at hc + subst c; simp [he] + · obtain ⟨e,he',rfl⟩ := Option.map_eq_some_iff.mp hc + obtain ⟨h1,h2,h3⟩ := ib (i-(a.size+1)) e he' + refine ⟨by simp only [Cut.tail,size]; omega, ?_, ?_⟩ + · cases hcl : e.closing <;> + simp only [Cut.tail, hcl, Bool.false_eq_true, ↓reduceIte] at h2 ⊢ <;> omega + · simp only [Cut.tail,insert] + rw [ite_eq_right (by omega), ite_eq_right (by omega)] + rw [show a.size+2+e.start-(a.size+2)=e.start by omega, h3] + +lemma cut_insert (d e : Diagram D) (p : ℕ) (hp : p≤d.size) (cl : Bool) : + (d.insert p e).cut (p+(if cl then e.size+1 else 0)) = + some ⟨p,e,d,cl⟩ := by + induction d generalizing p with + | nil => + have hh : p=0 := by simpa [size] using hp + subst p + cases cl <;> simp [insert,cut] + | diag a d ih => + cases p with + | zero => cases cl <;> simp [cut] + | succ p => + have h : p≤d.size := by simpa [size] using hp + have he := ih p h + rw [show (Diagram.diag a d).insert (p+1) e = .diag a (d.insert p e) by simp [insert]] + have hi : p+1+(if cl then e.size+1 else 0) = (p+(if cl then e.size+1 else 0))+1 := by omega + rw [hi, cut, he] + simp [Cut.diag] + | arch a b ia ib => + cases p with + | zero => cases cl <;> simp [cut] + | succ p => + by_cases h : p≤a.size + · have he := ia p h + rw [show (a.arch b).insert (p+1) e = .arch (a.insert p e) b by + simp [insert, show p+1≤a.size+1 by omega]] + have hi : p+1+(if cl then e.size+1 else 0) = (p+(if cl then e.size+1 else 0))+1 := by omega + rw [hi,cut,ite_eq_left] + · rw [he]; simp [Cut.inner] + · rw [insert_size]; cases cl <;> simp <;> omega + · have hp' : p-(a.size+1)≤b.size := by simp only [size] at hp; omega + have he := ib (p-(a.size+1)) hp' + rw [show (a.arch b).insert (p+1) e = .arch a (b.insert (p-(a.size+1)) e) by + simp [insert, show ¬p+1≤a.size+1 by omega, + show p+1-(a.size+2)=p-(a.size+1) by omega]] + have hi : p+1+(if cl then e.size+1 else 0) = (p+(if cl then e.size+1 else 0))+1 := by omega + rw [hi,cut,ite_eq_right (by omega),ite_eq_right (by omega)] + have hh : p+(if cl then e.size+1 else 0)-(a.size+1) = + p-(a.size+1)+(if cl then e.size+1 else 0) := by omega + rw [hh,he] + simp only [Option.map_some,Cut.tail] + congr 2 + omega + +lemma cut_exists_iff (d : Diagram D) (i : ℕ) : + (∃ c, d.cut i=some c) ↔ d.word[i]?=some .noise := by + induction d generalizing i with + | nil => simp [cut, word] + | diag a d ih => + cases i with + | zero => simp [cut,word] + | succ i => simpa [cut,word,Option.map_eq_some_iff] using ih i + | arch a b ia ib => + cases i with + | zero => simp [cut,word] + | succ i => + by_cases hi : i match l with | .diag a => some a | .noise => none)).toFinset + +@[simp] lemma labels_nil : labels ([] : List (Letter D)) = ∅ := rfl +@[simp] lemma labels_diag [DecidableEq D] (a : D) (F : List (Letter D)) : + labels (.diag a::F) = Insert.insert a (labels F) := by + ext x + simp [labels] +@[simp] lemma labels_noise (F : List (Letter D)) : labels (.noise::F)=labels F := by + simp [labels] +@[simp] lemma labels_append [DecidableEq D] (F G : List (Letter D)) : labels (F++G)=labels F∪labels G := by + ext x + simp [labels,List.filterMap_append] + +def supply (A : Finset D) : ℕ → Finset (Diagram D) + | 0 => {.nil} + | n+1 => by + classical + exact {.nil} ∪ A.biUnion (fun a => (supply A n).image (.diag a)) ∪ + (supply A n).biUnion (fun a => (supply A n).image (.arch a)) + +lemma mem_supply (A : Finset D) (n : ℕ) (d : Diagram D) + (hn : d.size≤n) (hA : labels d.word⊆A) : d∈supply A n := by + classical + induction n generalizing d with + | zero => + cases d with + | nil => simp [supply] + | diag a d => simp [size] at hn + | arch a b => simp [size] at hn + | succ n ih => + cases d with + | nil => simp [supply] + | diag a d => + have ha : a∈A := hA (by simp [word]) + have hd : labels d.word⊆A := by + intro x hx; apply hA; simp [word,hx] + have hs : d.size≤n := by simpa [size] using hn + simp only [supply,Finset.mem_union,Finset.mem_singleton,Finset.mem_biUnion,Finset.mem_image] + exact Or.inl (Or.inr ⟨a,ha,d,ih d hs hd,rfl⟩) + | arch a b => + have ha : labels a.word⊆A := by + intro x hx; apply hA; simp [word,hx] + have hb : labels b.word⊆A := by + intro x hx; apply hA; simp [word,hx] + have hs : a.size≤n ∧ b.size≤n := by simp only [size] at hn; omega + simp only [supply,Finset.mem_union,Finset.mem_biUnion,Finset.mem_image] + exact Or.inr ⟨a,ih a hs.1 ha,b,ih b hs.2 hb,rfl⟩ + +def enumerate (F : List (Letter D)) : Finset (Diagram D) := by + classical + exact (supply (labels F) F.length).filter (fun d => d.word=F) + +@[simp] theorem mem_enumerate (F : List (Letter D)) (d : Diagram D) : + d∈enumerate F ↔ d.word=F := by + classical + simp only [enumerate,Finset.mem_filter] + exact ⟨And.right, fun h => ⟨mem_supply _ _ d (by rw [← word_length,h]) (by rw [h]),h⟩⟩ + +def Paired (F : List (Letter D)) := {d : Diagram D // d.word=F} + +instance pairedFintype (F : List (Letter D)) : Fintype (Paired F) := + Fintype.ofFinset (enumerate F) (fun d => mem_enumerate F d) + +def CutAt (F : List (Letter D)) (k : ℕ) := + {c : Cut D // c.start≤c.outside.size ∧ + k=c.start+(if c.closing then c.inside.size+1 else 0) ∧ + (c.outside.insert c.start c.inside).word=F} + +def markedCut (d : Diagram D) (k : ℕ) (hk : d.word[k]?=some .noise) : Cut D := + Classical.choose ((cut_exists_iff d k).mpr hk) +lemma cut_markedCut (d : Diagram D) (k : ℕ) (hk : d.word[k]?=some .noise) : + d.cut k=some (d.markedCut k hk) := + Classical.choose_spec ((cut_exists_iff d k).mpr hk) + +def cutEquiv (F : List (Letter D)) (k : ℕ) (hk : F[k]?=some .noise) : + Paired F ≃ CutAt F k where + toFun d := by + have hd : d.val.word[k]?=some .noise := by rw [d.property]; exact hk + let c := d.val.markedCut k hd + have hs := cut_spec d.val k c (cut_markedCut _ _ _) + exact ⟨c,hs.1,hs.2.1,by rw [hs.2.2]; exact d.property⟩ + invFun c := ⟨c.val.outside.insert c.val.start c.val.inside,c.property.2.2⟩ + left_inv d := by + apply Subtype.ext + have hd : d.val.word[k]?=some .noise := by rw [d.property]; exact hk + exact (cut_spec d.val k _ (cut_markedCut d.val k hd)).2.2 + right_inv c := by + apply Subtype.ext + have hc := cut_insert c.val.outside c.val.inside c.val.start c.property.1 c.val.closing + rw [← c.property.2.1] at hc + have hd : (c.val.outside.insert c.val.start c.val.inside).word[k]?=some .noise := by + rw [c.property.2.2]; exact hk + exact Option.some.inj ((cut_markedCut _ k hd).symm.trans hc) + +@[ext] +structure PairShape (F : List (Letter D)) (k : ℕ) where + before : List (Letter D) + between : List (Letter D) + after : List (Letter D) + closing : Bool + word_eq : F = before ++ (.noise :: (between ++ (.noise :: after))) + mark_eq : k = before.length+(if closing then between.length+1 else 0) + +lemma PairShape.length_bound {F : List (Letter D)} {k : ℕ} (s : PairShape F k) : + s.before.length x.1.val) h + have h2 : a.between.length=b.between.length := congrArg (fun x => x.2.1.val) h + have h3 : a.closing=b.closing := congrArg (fun x => x.2.2) h + apply PairShape.ext + · rw [a.before_eq_take,b.before_eq_take,h1] + · rw [a.between_eq_take,b.between_eq_take,h1,h2] + · rw [a.after_eq_drop,b.after_eq_drop,h1,h2] + · exact h3 + +instance pairShapeFinite (F : List (Letter D)) (k : ℕ) : Finite (PairShape F k) := + Finite.of_injective _ (PairShape.code_injective F k) +instance pairShapeFintype (F : List (Letter D)) (k : ℕ) : Fintype (PairShape F k) := + Fintype.ofFinite _ + +def Separated (F : List (Letter D)) (k : ℕ) := + Σ s : PairShape F k, Paired s.between × Paired (s.before++s.after) + +instance separatedFintype (F : List (Letter D)) (k : ℕ) : Fintype (Separated F k) := + inferInstanceAs (Fintype (Σ s : PairShape F k, Paired s.between × Paired (s.before++s.after))) + +def shapeOfCut {F : List (Letter D)} {k : ℕ} (c : CutAt F k) : PairShape F k where + before := c.val.outside.word.take c.val.start + between := c.val.inside.word + after := c.val.outside.word.drop c.val.start + closing := c.val.closing + word_eq := c.property.2.2.symm.trans (insert_word _ _ _ c.property.1) + mark_eq := by + simp only [List.length_take,word_length,Nat.min_eq_left c.property.1] + exact c.property.2.1 + +end Diagram +end SKGap.Noncrossing +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/LinSub.lean b/lean/OAI/Probability/SKGap/Localization/LinSub.lean new file mode 100644 index 0000000000000000000000000000000000000000..f51dce1b4eb92868d870c3a7a22e76af95042acf --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/LinSub.lean @@ -0,0 +1,226 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.ExpDuhamel + +namespace OAI + +noncomputable section + +open MeasureTheory ProbabilityTheory InformationTheory Real Set +open scoped NNReal ENNReal +open Filter +open scoped Topology +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius ENNReal NNReal +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius NNReal +open MeasureTheory ProbabilityTheory Real Set Filter +open MeasureTheory.Measure +open scoped ENNReal NNReal MeasureTheory Topology +open MeasureTheory +open MeasureTheory Set NormedSpace +open scoped Topology +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius +namespace SKGap.ComplexMatrix + +section +open MeasureTheory Set NormedSpace +open scoped Topology +variable {ι : Type*} [Fintype ι] [DecidableEq ι] + +lemma lin_sub (M N : Matrix ι ι ℂ) : lin (M-N) = lin M - lin N := linEquiv.map_sub M N +lemma lin_neg (M : Matrix ι ι ℂ) : lin (-M) = - lin M := linEquiv.map_neg M +lemma opNorm_smul (t : ℝ) (M : Matrix ι ι ℂ) : opNorm (t • M) = |t| * opNorm M := by + change ‖lin (t • M)‖ = _ + have hh : lin (t • M) = t • lin M := by ext x i; simp [lin,Matrix.toEuclideanLin,Matrix.toLpLin_apply,Matrix.smul_mulVec] + rw [hh,norm_smul,Real.norm_eq_abs] + rfl + +lemma unitary_exp_smul (M : Matrix ι ι ℂ) (hM : Mᴴ = -M) (u : ℝ) : + exp (u • M) ∈ unitary (Matrix ι ι ℂ) := by + apply exp_mem_unitary_of_mem_skewAdjoint + change (u • M)ᴴ = -(u • M) + simp [hM] + +lemma opNorm_exp_sub (M N : Matrix ι ι ℂ) (hM : Mᴴ = -M) (hN : Nᴴ = -N) : + opNorm (exp M-exp N) ≤ opNorm (M-N) := by + have hMl : star (lin M) = -lin M := by rw [ContinuousLinearMap.star_eq_adjoint,← lin_adjoint,hM,lin_neg] + have hNl : star (lin N) = -lin N := by rw [ContinuousLinearMap.star_eq_adjoint,← lin_adjoint,hN,lin_neg] + let : NormedAlgebra ℚ (EuclideanSpace ℂ ι →L[ℂ] EuclideanSpace ℂ ι) := .restrictScalars ℚ ℝ _ + let : CompleteSpace (EuclideanSpace ℂ ι →L[ℂ] EuclideanSpace ℂ ι) := + ContinuousLinearMap.instCompleteSpace + have hh := SKGap.exp_skew_difference (lin M) (lin N) hMl hNl + simpa only [opNorm,lin_sub,lin_exp] using hh + +lemma frobenius_exp_sub (M N : Matrix ι ι ℂ) (hM : Mᴴ = -M) (hN : Nᴴ = -N) : + ‖exp M-exp N‖ ≤ ‖M-N‖ := by + rw [show exp M-exp N = _ from SKGap.exp_duhamel M N] + have hh (u : ℝ) : ‖exp ((1-u) • M) * (M-N) * exp (u • N)‖ = ‖M-N‖ := by + rw [frobenius_mul_unitary _ _ (unitary_exp_smul N hN u), + frobenius_unitary_mul _ _ (unitary_exp_smul M hM (1-u))] + calc + _ ≤ ∫ u : ℝ in (0 : ℝ)..1, ‖exp ((1-u) • M) * (M-N) * exp (u • N)‖ := + intervalIntegral.norm_integral_le_integral_norm (by norm_num) + _ = ‖M-N‖ := by simp only [hh]; simp + +lemma exp_four_point (a b c d : Matrix ι ι ℂ) + (ha : aᴴ = -a) (hb : bᴴ = -b) (hc : cᴴ = -c) (hd : dᴴ = -d) : + ‖(exp a-exp b)-(exp c-exp d)‖ ≤ + ‖(a-b)-(c-d)‖ + (opNorm (a-c)+opNorm (b-d))*‖c-d‖ := by + let F := fun a b : Matrix ι ι ℂ => fun u : ℝ => exp ((1-u) • a) * (a-b) * exp (u • b) + have hF (a b : Matrix ι ι ℂ) : Continuous (F a b) := by dsimp [F]; fun_prop + have hbound (u : ℝ) (hu : u ∈ Icc (0 : ℝ) 1) : + ‖F a b u-F c d u‖ ≤ ‖(a-b)-(c-d)‖ + (opNorm (a-c)+opNorm (b-d))*‖c-d‖ := by + have hsa : ((1-u) • a)ᴴ = -((1-u) • a) := by simp [ha] + have hsc : ((1-u) • c)ᴴ = -((1-u) • c) := by simp [hc] + have hsb : (u • b)ᴴ = -(u • b) := by simp [hb] + have hsd : (u • d)ᴴ = -(u • d) := by simp [hd] + have h₁ := opNorm_exp_sub ((1-u) • a) ((1-u) • c) hsa hsc + have h₂ := opNorm_exp_sub (u • b) (u • d) hsb hsd + rw [← smul_sub,opNorm_smul,abs_of_nonneg (sub_nonneg.mpr hu.2)] at h₁ + rw [← smul_sub,opNorm_smul,abs_of_nonneg hu.1] at h₂ + have ha0 : 0 ≤ opNorm (a-c) := norm_nonneg _ + have hb0 : 0 ≤ opNorm (b-d) := norm_nonneg _ + have h₁' : opNorm (exp ((1-u) • a)-exp ((1-u) • c)) ≤ opNorm (a-c) := by nlinarith [hu.1] + have h₂' : opNorm (exp (u • b)-exp (u • d)) ≤ opNorm (b-d) := by nlinarith [hu.2] + have hid : F a b u-F c d u = + exp ((1-u) • a)*((a-b)-(c-d))*exp (u • b) + + (exp ((1-u) • a)-exp ((1-u) • c))*(c-d)*exp (u • b) + + exp ((1-u) • c)*(c-d)*(exp (u • b)-exp (u • d)) := by dsimp [F]; noncomm_ring + rw [hid] + have hfirst : ‖exp ((1-u) • a)*((a-b)-(c-d))*exp (u • b)‖ = ‖(a-b)-(c-d)‖ := by + rw [frobenius_mul_unitary _ _ (unitary_exp_smul b hb u), + frobenius_unitary_mul _ _ (unitary_exp_smul a ha (1-u))] + have hsecond : ‖(exp ((1-u) • a)-exp ((1-u) • c))*(c-d)*exp (u • b)‖ ≤ opNorm (a-c)*‖c-d‖ := by + rw [frobenius_mul_unitary _ _ (unitary_exp_smul b hb u)] + exact (frobenius_mul_le_opNorm _ _).trans (mul_le_mul_of_nonneg_right h₁' (norm_nonneg _)) + have hthird : ‖exp ((1-u) • c)*(c-d)*(exp (u • b)-exp (u • d))‖ ≤ opNorm (b-d)*‖c-d‖ := by + rw [mul_assoc,frobenius_unitary_mul _ _ (unitary_exp_smul c hc (1-u))] + exact (frobenius_mul_le_opNorm_right _ _).trans (by nlinarith [norm_nonneg (c-d)]) + calc + _ ≤ ‖exp ((1-u) • a)*((a-b)-(c-d))*exp (u • b)‖ + + ‖(exp ((1-u) • a)-exp ((1-u) • c))*(c-d)*exp (u • b)‖ + + ‖exp ((1-u) • c)*(c-d)*(exp (u • b)-exp (u • d))‖ := norm_add₃_le + _ ≤ _ := by rw [hfirst]; nlinarith + rw [show exp a-exp b = _ from SKGap.exp_duhamel a b, show exp c-exp d = _ from SKGap.exp_duhamel c d] + change ‖(∫ u : ℝ in (0 : ℝ)..1, F a b u)-(∫ u : ℝ in (0 : ℝ)..1, F c d u)‖ ≤ _ + rw [← intervalIntegral.integral_sub ((hF a b).intervalIntegrable 0 1) ((hF c d).intervalIntegrable 0 1)] + calc + _ ≤ ∫ u : ℝ in (0 : ℝ)..1, ‖F a b u-F c d u‖ := intervalIntegral.norm_integral_le_integral_norm (by norm_num) + _ ≤ ∫ _ : ℝ in (0 : ℝ)..1, ‖(a-b)-(c-d)‖ + (opNorm (a-c)+opNorm (b-d))*‖c-d‖ := by + apply intervalIntegral.integral_mono_on (by norm_num) (((hF a b).sub (hF c d)).norm.intervalIntegrable 0 1) + (intervalIntegrable_const) + exact hbound + _ = _ := by simp + +end + +open MeasureTheory Set NormedSpace +open scoped Topology FourierTransform SchwartzMap +variable {ι : Type*} [Fintype ι] [DecidableEq ι] + +local instance : ContinuousENorm (Matrix ι ι ℂ) := + @SeminormedAddGroup.toContinuousENorm _ Matrix.frobeniusSeminormedAddCommGroup.toSeminormedAddGroup +local instance : TopologicalSpace.PseudoMetrizableSpace (Matrix ι ι ℂ) := + inferInstanceAs (TopologicalSpace.PseudoMetrizableSpace (ι → ι → ℂ)) + +lemma lin_csmul (z : ℂ) (M : Matrix ι ι ℂ) : lin (z • M) = z • lin M := + (linEquiv (ι := ι)).map_smul z M + +lemma opNorm_csmul (z : ℂ) (M : Matrix ι ι ℂ) : opNorm (z • M) = ‖z‖ * opNorm M := by + simp only [opNorm,lin_csmul,norm_smul] + +noncomputable def imaginary (t : ℝ) (M : Matrix ι ι ℂ) : Matrix ι ι ℂ := + ((t : ℂ)*Complex.I) • M + +omit [Fintype ι] [DecidableEq ι] in +lemma imaginary_skew (t : ℝ) (M : Matrix ι ι ℂ) (hM : Mᴴ = M) : + (imaginary t M)ᴴ = -(imaginary t M) := by + simp [imaginary,Matrix.conjTranspose_smul,hM,star_mul,mul_comm] + +lemma imaginary_norm (t : ℝ) (M : Matrix ι ι ℂ) : ‖imaginary t M‖ = |t| * ‖M‖ := by + simp [imaginary,norm_smul] + +lemma imaginary_opNorm (t : ℝ) (M : Matrix ι ι ℂ) : opNorm (imaginary t M) = |t| * opNorm M := by + simp [imaginary,opNorm_csmul] + +omit [Fintype ι] [DecidableEq ι] in +lemma imaginary_sub (t : ℝ) (M N : Matrix ι ι ℂ) : + imaginary t (M-N) = imaginary t M-imaginary t N := by simp [imaginary,smul_sub] + +lemma imaginary_exp_unitary (t : ℝ) (M : Matrix ι ι ℂ) (hM : Mᴴ = M) : + exp (imaginary t M) ∈ unitary (Matrix ι ι ℂ) := by + simpa using unitary_exp_smul _ (imaginary_skew t M hM) 1 + +lemma imaginary_exp_norm (t : ℝ) (M : Matrix ι ι ℂ) (hM : Mᴴ = M) : + ‖exp (imaginary t M)‖ = ‖(1 : Matrix ι ι ℂ)‖ := by + simpa using frobenius_unitary_mul (exp (imaginary t M)) 1 (imaginary_exp_unitary t M hM) + +lemma imaginary_exp_opNorm_le (t : ℝ) (M : Matrix ι ι ℂ) (hM : Mᴴ = M) : + opNorm (exp (imaginary t M)) ≤ 1 := by + apply ContinuousLinearMap.opNorm_le_bound _ (by norm_num) + intro x + rw [ContinuousLinearMap.norm_map_of_mem_unitary (lin_unitary _ (imaginary_exp_unitary t M hM))] + simp + +noncomputable def kernelMatrix (g : ℝ → ℂ) (M : Matrix ι ι ℂ) : Matrix ι ι ℂ := + ∫ t : ℝ, g t • exp (imaginary t M) + +lemma kernel_integrable {g : ℝ → ℂ} (hg : Integrable g) (M : Matrix ι ι ℂ) (hM : Mᴴ = M) : + Integrable (fun t : ℝ => g t • exp (imaginary t M)) := by + have hc : Continuous (fun t : ℝ => exp (imaginary t M)) := by dsimp [imaginary]; fun_prop + apply (hg.norm.mul_const ‖(1 : Matrix ι ι ℂ)‖).mono' (hg.aestronglyMeasurable.smul hc.aestronglyMeasurable) + filter_upwards [] with t + change ‖g t • exp (imaginary t M)‖ ≤ _ + rw [norm_smul,imaginary_exp_norm t M hM] + +lemma kernelMatrix_lipschitz {g : ℝ → ℂ} (hg : Integrable g) + (hg₁ : Integrable (fun t : ℝ => ‖g t‖*|t|)) + (M N : Matrix ι ι ℂ) (hM : Mᴴ = M) (hN : Nᴴ = N) : + ‖kernelMatrix g M-kernelMatrix g N‖ ≤ (∫ t : ℝ, ‖g t‖*|t|) * ‖M-N‖ := by + rw [kernelMatrix,kernelMatrix,← integral_sub (kernel_integrable hg M hM) (kernel_integrable hg N hN)] + calc + _ ≤ ∫ t : ℝ, ‖g t • exp (imaginary t M)-g t • exp (imaginary t N)‖ := norm_integral_le_integral_norm _ + _ ≤ ∫ t : ℝ, (‖g t‖*|t|)*‖M-N‖ := by + apply integral_mono ((kernel_integrable hg M hM).sub (kernel_integrable hg N hN)).norm (hg₁.mul_const _) + intro t + dsimp only [Pi.sub_apply] + rw [← smul_sub,norm_smul] + have hh := frobenius_exp_sub _ _ (imaginary_skew t M hM) (imaginary_skew t N hN) + rw [← imaginary_sub,imaginary_norm] at hh + exact (mul_le_mul_of_nonneg_left hh (norm_nonneg _)).trans_eq (mul_assoc _ _ _).symm + _ = _ := integral_mul_const _ _ + +lemma kernelMatrix_four_point {g : ℝ → ℂ} (hg : Integrable g) + (hg₁ : Integrable (fun t : ℝ => ‖g t‖*|t|)) + (hg₂ : Integrable (fun t : ℝ => ‖g t‖*|t|^2)) + (a b c d : Matrix ι ι ℂ) (ha : aᴴ = a) (hb : bᴴ = b) (hc : cᴴ = c) (hd : dᴴ = d) : + ‖(kernelMatrix g a-kernelMatrix g b)-(kernelMatrix g c-kernelMatrix g d)‖ ≤ + (∫ t : ℝ, ‖g t‖*|t|)*‖(a-b)-(c-d)‖ + + (∫ t : ℝ, ‖g t‖*|t|^2)*(opNorm (a-c)+opNorm (b-d))*‖c-d‖ := by + let F := fun (M : Matrix ι ι ℂ) (t : ℝ) => g t • exp (imaginary t M) + have hi (M : Matrix ι ι ℂ) (hM : Mᴴ = M) : Integrable (F M) := kernel_integrable hg M hM + have hi' := ((hi a ha).sub (hi b hb)).sub ((hi c hc).sub (hi d hd)) + change ‖((∫ t, F a t)-(∫ t, F b t))-((∫ t, F c t)-(∫ t, F d t))‖ ≤ _ + rw [← integral_sub (hi a ha) (hi b hb),← integral_sub (hi c hc) (hi d hd), + ← integral_sub (f := fun t => F a t-F b t) (g := fun t => F c t-F d t) + ((hi a ha).sub (hi b hb)) ((hi c hc).sub (hi d hd))] + calc + _ ≤ ∫ t : ℝ, ‖(F a t-F b t)-(F c t-F d t)‖ := norm_integral_le_integral_norm _ + _ ≤ ∫ t : ℝ, (‖g t‖*|t|)*‖(a-b)-(c-d)‖ + + (‖g t‖*|t|^2)*(opNorm (a-c)+opNorm (b-d))*‖c-d‖ := by + apply integral_mono hi'.norm ((hg₁.mul_const _).add ((hg₂.mul_const _).mul_const _)) + intro t + dsimp only [F,Pi.sub_apply] + rw [← smul_sub,← smul_sub,← smul_sub,norm_smul] + have hh := exp_four_point (imaginary t a) (imaginary t b) (imaginary t c) (imaginary t d) + (imaginary_skew t a ha) (imaginary_skew t b hb) (imaginary_skew t c hc) (imaginary_skew t d hd) + simp only [← imaginary_sub,imaginary_norm,imaginary_opNorm] at hh + exact (mul_le_mul_of_nonneg_left hh (norm_nonneg _)).trans_eq (by dsimp only [Pi.add_apply]; ring) + _ = _ := by rw [integral_add (hg₁.mul_const _) ((hg₂.mul_const _).mul_const _)]; simp only [integral_mul_const] + +end SKGap.ComplexMatrix + +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/LinearObservable.lean b/lean/OAI/Probability/SKGap/Localization/LinearObservable.lean new file mode 100644 index 0000000000000000000000000000000000000000..5364ef9e098e70442a5a8e549cef19376060b7df --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/LinearObservable.lean @@ -0,0 +1,188 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.Magnetization +import OAI.Probability.SKGap.Terminal.GibbsExpectationMono +import OAI.Probability.SKGap.Localization.CubeWeight + +namespace OAI + +section +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +namespace SKGapCutoff + +lemma stationary_deviation_le_oscillation {n : ℕ} (J : Interaction n) (f : Observables n) + (x : Spin n) (C : ℝ) (hf : ∀ y, f x - f y ≤ C) : + f x - gibbsExpectation J f ≤ C := by + have h := gibbsExpectation_mono J (fun y => f x - f y) (fun _ => C) hf + simpa only [gibbsExpectation_sub, gibbsExpectation_const] using h + +lemma semigroup_deviation_le_gradient {n : ℕ} (J : Interaction n) + (hJ : ∀ i j, J i j = J j i) (hdiag : ∀ i, J i i = 0) + (t : ℝ) (f : Observables n) (C : ℝ) (hC : 0 ≤ C) + (hgrad : ∀ y, ∑ i, (halfDiff i (semigroup J t f) y) ^ 2 ≤ C ^ 2) (x : Spin n) : + semigroup J t f x - gibbsExpectation J f ≤ 2 * Real.sqrt n * C := by + rw [← gibbsExpectation_semigroup J hJ hdiag t f] + apply stationary_deviation_le_oscillation J _ x + intro y + exact (le_abs_self _).trans (euclidean_oscillation _ C hC hgrad x y) + +theorem continuous_tv_le_gradient {n : ℕ} (J : Interaction n) + (hJ : ∀ i j, J i j = J j i) (hdiag : ∀ i, J i i = 0) + (t C : ℝ) (hC : 0 ≤ C) + (hgrad : ∀ f : Observables n, (∀ y, |f y| ≤ 1) → + ∀ y, ∑ i, (halfDiff i (semigroup J t f) y) ^ 2 ≤ C ^ 2) (x : Spin n) : + totalVariation (continuousKernel J t x) (gibbs J) ≤ Real.sqrt n * C := by + let f : Observables n := fun y => if 0 ≤ continuousKernel J t x y - gibbs J y then 1 else -1 + have hf (y : Spin n) : |f y| ≤ 1 := by dsimp [f]; split_ifs <;> norm_num + have he : semigroup J t f x - gibbsExpectation J f = + 2 * totalVariation (continuousKernel J t x) (gibbs J) := by + rw [← kernel_apply (semigroup J t) f x] + simp only [gibbsExpectation, totalVariation, mul_div_cancel₀ _ (show (2 : ℝ) ≠ 0 by norm_num), + ← Finset.sum_sub_distrib, ← sub_mul] + apply Finset.sum_congr rfl + intro y _ + change (continuousKernel J t x y - gibbs J y) * f y = |continuousKernel J t x y - gibbs J y| + dsimp [f] + split_ifs with h + · rw [mul_one, abs_of_nonneg h] + · rw [mul_neg_one, abs_of_neg (lt_of_not_ge h)] + have hb := semigroup_deviation_le_gradient J hJ hdiag t f C hC (hgrad f hf) x + rw [he] at hb + nlinarith + +lemma worstContinuous_le_gradient {n : ℕ} (J : Interaction n) + (hJ : ∀ i j, J i j = J j i) (hdiag : ∀ i, J i i = 0) + (t C : ℝ) (hC : 0 ≤ C) + (hgrad : ∀ f : Observables n, (∀ y, |f y| ≤ 1) → + ∀ y, ∑ i, (halfDiff i (semigroup J t f) y) ^ 2 ≤ C ^ 2) : + worstContinuous J t ≤ Real.sqrt n * C := by + exact Finset.sup'_le _ _ (fun x _ => continuous_tv_le_gradient J hJ hdiag t C hC hgrad x) + +noncomputable def linearObservable {n : ℕ} (u : Fin n → ℝ) (x : Spin n) : ℝ := + ∑ i, u i * spin x i + +lemma halfDiff_linearObservable {n : ℕ} (u : Fin n → ℝ) (x : Spin n) (i : Fin n) : + halfDiff i (linearObservable u) x = u i := by + have hmul (c : ℝ) (f : Observables n) : + halfDiff i (fun y => c * f y) x = c * halfDiff i f x := by + simp only [halfDiff] + ring + change halfDiff i (fun y => ∑ j, u j * spin y j) x = _ + simp only [halfDiff_sum, hmul, halfDiff_spin] + simp + +lemma linearObservable_centered {n : ℕ} (J : Interaction n) (u : Fin n → ℝ) : + gibbsExpectation J (linearObservable u) = 0 := by + change gibbsExpectation J (fun x => ∑ i, u i * spin x i) = 0 + simp only [gibbsExpectation_sum, gibbsExpectation_mul_const, + gibbs_spin_centered, mul_zero, Finset.sum_const_zero] + +lemma dirichlet_linearObservable_le {n : ℕ} (J : Interaction n) (u : Fin n → ℝ) : + dirichlet J (linearObservable u) (linearObservable u) ≤ ∑ i, u i ^ 2 := by + simp only [dirichlet, halfDiff_linearObservable] + calc + _ ≤ gibbsExpectation J (fun _ => ∑ i, u i ^ 2) := by + apply gibbsExpectation_mono + intro x + apply Finset.sum_le_sum + intro i _ + rw [mul_assoc, ← pow_two] + exact mul_le_of_le_one_left (sq_nonneg _) (siteVariance_le_one J x i) + _ = _ := gibbsExpectation_const J _ + +lemma linearObservable_second_moment_le {n : ℕ} (J : Interaction n) + {γ V : ℝ} (hγ : 0 < γ) (hgap : HasGap J γ) (hV : 1 ≤ γ * V) + (u : Fin n → ℝ) : + gibbsExpectation J (fun x => linearObservable u x ^ 2) ≤ V * ∑ i, u i ^ 2 := by + have hg := (hgap (linearObservable u)).trans (dirichlet_linearObservable_le J u) + rw [gibbsVariance, linearObservable_centered] at hg + simp only [sub_zero] at hg + apply (mul_le_mul_iff_right₀ hγ).mp + calc + γ * gibbsExpectation J (fun x => linearObservable u x ^ 2) ≤ ∑ i, u i ^ 2 := hg + _ ≤ γ * (V * ∑ i, u i ^ 2) := by + have h := mul_le_mul_of_nonneg_right hV + (show (0 : ℝ) ≤ ∑ i, u i ^ 2 from Finset.sum_nonneg (fun i _ => sq_nonneg (u i))) + simpa only [one_mul, mul_assoc] using h + +noncomputable def overlap {n : ℕ} (x y : Spin n) : ℝ := linearObservable (spin x) y + +lemma overlap_coeff_norm_sq {n : ℕ} (x : Spin n) : ∑ i, spin x i ^ 2 = (n : ℝ) := by simp + +noncomputable def spinCorrelation {n : ℕ} (J : Interaction n) (t : ℝ) : ℝ := + (∑ i, stationaryInner J (fun x => spin x i) (semigroup J t (fun x => spin x i))) / n + +lemma overlap_correlates {n : ℕ} (hn : 0 < n) (J : Interaction n) (t : ℝ) : + gibbsExpectation J (fun x => semigroup J t (overlap x) x) = + (n : ℝ) * spinCorrelation J t := by + have hs (x : Spin n) : semigroup J t (overlap x) x = + ∑ i, spin x i * semigroup J t (fun y => spin y i) x := by + have heq : overlap x = ∑ i, spin x i • (fun y => spin y i) := by + funext y + simp only [overlap, linearObservable, Finset.sum_apply, Pi.smul_apply, smul_eq_mul] + rw [heq] + simp only [map_sum, map_smul, Finset.sum_apply, Pi.smul_apply, smul_eq_mul] + simp only [hs, gibbsExpectation_sum, stationaryInner, spinCorrelation] + field_simp + +lemma exists_overlap_mean_ge {n : ℕ} (hn : 0 < n) (J : Interaction n) (t : ℝ) : + ∃ x, (n : ℝ) * spinCorrelation J t ≤ semigroup J t (overlap x) x := by + obtain ⟨x, _, hx⟩ := Finset.exists_max_image (Finset.univ : Finset (Spin n)) + (fun x => semigroup J t (overlap x) x) Finset.univ_nonempty + refine ⟨x, ?_⟩ + rw [← overlap_correlates hn J t] + exact (gibbsExpectation_mono J _ (fun _ => semigroup J t (overlap x) x) + (fun y => hx y (Finset.mem_univ y))).trans_eq (gibbsExpectation_const J _) + +lemma kernel_centered_second_moment {n : ℕ} (J : Interaction n) (t : ℝ) + (f : Observables n) (x : Spin n) : + ∑ y, continuousKernel J t x y * (f y - semigroup J t f x) ^ 2 = + semigroup J t (fun y => f y ^ 2) x - (semigroup J t f x) ^ 2 := by + simpa only [zero_add] using + quadratic_centered_identity (continuousKernel J t x) f (semigroup J t f x) 0 + (semigroup J t (fun y => f y ^ 2) x) (continuousKernel_sum J t x) + (kernel_apply _ _ _) + (by simpa only [sub_zero, continuousKernel] using kernel_apply (semigroup J t) (fun y => f y ^ 2) x) + +theorem worstContinuous_lower_from_spin {n : ℕ} (hn : 0 < n) (J : Interaction n) + {γ V c t : ℝ} (ht : 0 ≤ t) (hγ : 0 < γ) (hgap : HasGap J γ) + (hV : 1 ≤ γ * V) (hc : 0 < c) (hcor : c ≤ spinCorrelation J t) + (hvar : ∀ x, semigroup J t (fun y => overlap x y ^ 2) x - + (semigroup J t (overlap x) x) ^ 2 ≤ (n : ℝ) * V) : + (n : ℝ) * c ^ 2 * (1 - worstContinuous J t) ≤ 8 * V := by + have hn' : (0 : ℝ) < n := by exact_mod_cast hn + obtain ⟨x, hx⟩ := exists_overlap_mean_ge hn J t + let m := semigroup J t (overlap x) x + have hm : (n : ℝ) * c ≤ m := (mul_le_mul_of_nonneg_left hcor hn'.le).trans hx + have hmpos : 0 < m := (mul_pos hn' hc).trans_le hm + have heq : ∑ y, gibbs J y * overlap x y ^ 2 ≤ (n : ℝ) * V := by + have h := linearObservable_second_moment_le J hγ hgap hV (spin x) + simpa only [overlap_coeff_norm_sq, mul_comm, gibbsExpectation, overlap] using h + have htrans : ∑ y, continuousKernel J t x y * (overlap x y - m) ^ 2 ≤ (n : ℝ) * V := by + rw [kernel_centered_second_moment] + exact hvar x + have htv := totalVariation_lower_from_quadratic_test (continuousKernel J t x) (gibbs J) + (overlap x) (continuousKernel_nonneg J t ht x) (fun y => (gibbs_pos J y).le) + (continuousKernel_sum J t x) (gibbs_sum J) m ((n : ℝ) * V) hmpos htrans heq + have hmax : totalVariation (continuousKernel J t x) (gibbs J) ≤ worstContinuous J t := + Finset.le_sup' (f := fun y => totalVariation (continuousKernel J t y) (gibbs J)) + (Finset.mem_univ x) + have hnonneg : 0 ≤ 1 - worstContinuous J t := sub_nonneg.mpr (worstContinuous_le_one J t ht) + have hsquare : ((n : ℝ) * c) ^ 2 ≤ m ^ 2 := sq_le_sq₀ (mul_pos hn' hc).le hmpos.le |>.mpr hm + have h := calc + (n : ℝ) * ((n : ℝ) * c ^ 2 * (1 - worstContinuous J t)) = + ((n : ℝ) * c) ^ 2 * (1 - worstContinuous J t) := by ring + _ ≤ m ^ 2 * (1 - worstContinuous J t) := mul_le_mul_of_nonneg_right hsquare hnonneg + _ ≤ m ^ 2 * (1 - totalVariation (continuousKernel J t x) (gibbs J)) := + mul_le_mul_of_nonneg_left (sub_le_sub_left hmax 1) (sq_nonneg m) + _ ≤ (n : ℝ) * (8 * V) := by nlinarith [htv] + exact (mul_le_mul_iff_right₀ hn').mp h + +end SKGapCutoff + +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/LiteralConstruction.lean b/lean/OAI/Probability/SKGap/Localization/LiteralConstruction.lean new file mode 100644 index 0000000000000000000000000000000000000000..3e8d230efd9b95f06cb4d62872680a9bf7478043 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/LiteralConstruction.lean @@ -0,0 +1,164 @@ +import Mathlib +import OAI.Probability.SKGap.Stability.LiteralStableControl + +namespace OAI + +section + +noncomputable section +open scoped BigOperators Matrix.Norms.Frobenius +namespace SKGapCutoff.Recipe +open SKGap.Stein Primary SKGap.ImplicitSystem Matrix +variable {n : ℕ} + +lemma literalBudget_exists (f : KernelExpr) (R T L : ℝ) (hT : 0≤T) : + ∃B,LiteralBudget f R T L B := by + let U:=ratioSmallBudget (.kernel f) T + let P:=ratioSmallBudget ((RatioExpr.kernel f).d .z) T*kernelSmallBudget phiExpr R T + let V:=(phiExpr.dBudget R+phiExpr.ddBudget R)*T + let E:=((RatioExpr.kernel phiExpr.dz).dBudget+(RatioExpr.kernel phiExpr.dz).ddBudget)*T + let B:=2+Real.sqrt (Real.exp (R/2))+|L|+T+U+P+V+E + have hs:=Real.sqrt_nonneg (Real.exp (R/2)) + have hU:0≤U:=ratioSmallBudget_nonneg _ _ hT + have hP:0≤P:=mul_nonneg (ratioSmallBudget_nonneg _ _ hT) (kernelSmallBudget_nonneg _ _ _ hT) + have hV:0≤V:=mul_nonneg (add_nonneg (phiExpr.dBudget_nonneg _) (phiExpr.ddBudget_nonneg _)) hT + have hE:0≤E:=mul_nonneg (add_nonneg (RatioExpr.dBudget_nonneg _) (RatioExpr.ddBudget_nonneg _)) hT + have hB:0≤B:=by dsimp [B]; positivity + have hsB : Real.sqrt (Real.exp (R/2))≤B:=by dsimp [B]; linarith [abs_nonneg L] + refine ⟨B,⟨hB,?_,hsB,?_,?_,?_,?_,?_,?_,?_⟩⟩ + · dsimp [B]; linarith [abs_nonneg L] + · have h:=pow_le_pow_left₀ hs hsB 2 + rwa [Real.sq_sqrt (Real.exp_pos _).le] at h + · dsimp [B]; linarith [le_abs_self L] + all_goals dsimp [B]; linarith [abs_nonneg L] + +lemma literal_system_extension (J : Interaction n) (j : ℝ) (f : KernelExpr) + (z m : VectorFields n) (a : Spin n→ℝ) (r e : Fin n→ℝ) + (hn : 0 + LiteralStableAt J j z m a r R ρ δ x→ + Equations j ((∑i,phi (z x i) (r i) (a x))/(n:ℝ)) (n:ℝ)⁻¹ + (siteMean (initialP f z a r e) x) (phiDiagonal (z x) r (a x)) + (toEuclideanCLM (𝕜:=ℝ) J) (WithLp.toLp 2 (initialU f z a r e x)) (WithLp.toLp 2 (m x)) + (WithLp.toLp 2 (fun i=>Real.tanh (r i))) (WithLp.toLp 2 (fun i=>logSlope (z x i) (r i) (a x))) + v.1 v.2.1 v.2.2 + have hex : ∀x,∃v,P x v := by + intro x + by_cases H:LiteralStableAt J j z m a r R ρ δ x + · obtain ⟨v,hv,-⟩:=literal_implicit_exists_unique (z x) r (m x) (a x) j + (siteMean (initialP f z a r e) x) (toEuclideanCLM (𝕜:=ℝ) J) + (WithLp.toLp 2 (initialU f z a r e x)) hn hδ hρ H.a_bound H.a_small H.z_near H.m_near hsmall H.stable + exact ⟨v,fun _=>hv⟩ + · exact ⟨0,fun H'=>False.elim (H H')⟩ + choose v hv using hex + exact ⟨fun x=>(v x).1.ofLp,fun x=>(v x).2.1.ofLp,fun x=>(v x).2.2,hv⟩ + +theorem literal_implicit_construction (j R ρ δ T L : ℝ) (f : KernelExpr) + (hδ : 0<δ) (hρ : 0≤ρ) (hT : 0≤T) + (hsmall : ρ≤δ/(2*(|j| *Real.exp (R/2)*(3*Real.exp (R/2)+16)+1))) : + ∃C≥0,∀n : ℕ,0Real.sqrt n*c v) x‖≤C) := by + obtain ⟨B,hB⟩:=literalBudget_exists f R T L hT + refine ⟨uniformControlBudget j δ B,uniformControlBudget_nonneg hδ hB.nonneg,?_⟩ + intro n hn J z m a r e hJ he + obtain ⟨w,y,c,h⟩:=literal_system_extension J j f z m a r e hn hδ hρ hsmall + refine ⟨w,y,c,h,?_⟩ + intro x H Hf hD hDm + exact literal_initial_control J j f z m w y a c r e x hn hδ hρ hT hsmall hB hJ he + H Hf hD hDm (h x H) (fun k=>h (flip x k) (Hf k)) +end SKGapCutoff.Recipe + +end +end + +section + +noncomputable section +open scoped BigOperators +namespace SKGapCutoff.Recipe +open SKGap.Stein Primary SKGap.ImplicitSystem Matrix +variable {n : ℕ} + +lemma initialU_size (f : KernelExpr) (z : VectorFields n) (a : Spin n→ℝ) + (r e : Fin n→ℝ) (x : Spin n) (he : vectorNorm e≤1) : + vectorNorm (initialU f z a r e x)≤f.mass := by + exact (vectorNorm_mul _ e f.mass_nonneg (fun i=>(RatioExpr.kernel f).bounded _ _ _)).trans + (mul_le_of_le_one_right f.mass_nonneg he) + +lemma initialP_size (f : KernelExpr) (z : VectorFields n) (a : Spin n→ℝ) + (r e : Fin n→ℝ) (x : Spin n) {R : ℝ} (ha : |a x|≤R) (he : vectorNorm e≤1) : + vectorNorm (initialP f z a r e x)≤ + Real.exp (R/2)*((RatioExpr.kernel f).d .z).mass := by + rw [initialP_ratio] + apply (vectorNorm_mul _ _ (Real.exp_pos _).le (fun i=>?_)).trans + (mul_le_mul_of_nonneg_left ((vectorNorm_mul _ e (RatioExpr.mass_nonneg _) + (fun i=>RatioExpr.bounded _ _ _ _)).trans + (mul_le_of_le_one_right (RatioExpr.mass_nonneg _) he)) (Real.exp_pos _).le) + rw [abs_of_pos (phi_pos _ _ _)] + exact (phi_le_exp ..).trans (Real.exp_le_exp.mpr (by linarith)) + +def literalSizeBudget (j δ R L : ℝ) (f : KernelExpr) : ℝ := + let A:=Real.exp (R/2) + let P:=A*((RatioExpr.kernel f).d .z).mass + let W:=(1+A*(δ/2)⁻¹*(L+|j| *A+4*|j|))*A*(f.mass+2*|j| *P) + W+(2*W+P)+((L+|j| *A)*W+|j| *(2*W+P)) + +lemma literal_initial_size (J : Interaction n) (j : ℝ) (f : KernelExpr) + (z m w y : VectorFields n) (a c : Spin n→ℝ) (r e : Fin n→ℝ) (x : Spin n) + (hn : 0phi (z v i) (r i) (a v)) x|≤Real.exp (R/2) := by + apply coefficient_mean_value _ _ (Real.exp_pos _).le + intro i + rw [abs_of_pos (phi_pos _ _ _)] + exact (phi_le_exp ..).trans (Real.exp_le_exp.mpr (by linarith [H.a_bound])) + have hP:=initialP_size f z a r e x H.a_bound he + have hp:=scaledMean_size hn (initialP f z a r e) x + (mul_nonneg (Real.exp_pos _).le (RatioExpr.mass_nonneg _)) hP + rw [abs_mul,abs_of_nonneg hd.le] at hp + have heq:=h + unfold LiteralEquations at heq + rw [←phiSqrt_square] at heq + obtain ⟨hw,hc,hy⟩:=implicit_uniform_size j _ _ _ _ (phiSqrt (z x) r (a x)) + (toEuclideanCLM (𝕜:=ℝ) J) (WithLp.toLp 2 (initialU f z a r e x)) + (WithLp.toLp 2 (m x)) (WithLp.toLp 2 (fun i=>Real.tanh (r i))) + (WithLp.toLp 2 (fun i=>logSlope (z x i) (r i) (a x))) + (WithLp.toLp 2 (fun i=>Real.tanh (z x i))) (WithLp.toLp 2 (w x)) + (WithLp.toLp 2 (y x)) (c x) hδ hd (by positivity) hscale + (Real.exp_pos _).le hL (by norm_num : (0:ℝ)≤2) f.mass_nonneg + (mul_nonneg (Real.exp_pos _).le (RatioExpr.mass_nonneg _)) + (phiSqrt_bound _ _ _ H.a_bound) hJ hχ (initialU_size f z a r e x he) + H.m_size (vectorNorm_tanh r) (vectorNorm_logSlope (z x) r (a x)) hp + H.stable (H.perturbation hn hδ hρ hsmall) heq + dsimp only [literalSizeBudget] + change vectorNorm (w x)≤_ at hw + change vectorNorm (y x)≤_ at hy + linarith + +end SKGapCutoff.Recipe + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/LiteralInitialRecipe.lean b/lean/OAI/Probability/SKGap/Localization/LiteralInitialRecipe.lean new file mode 100644 index 0000000000000000000000000000000000000000..c15a743338cfa2e3bc4941fb5749640d45901453 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/LiteralInitialRecipe.lean @@ -0,0 +1,93 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.PhiRegularity +import OAI.Probability.SKGap.Stability.ImplicitNode + +namespace OAI + +section + +noncomputable section +open scoped BigOperators +namespace SKGapCutoff.Recipe +open SKGap.Stein Primary +variable {n : ℕ} + +abbrev InitialArgs := Args (ι:=Unit) (κ:=Bool) +def initialKernel (f : KernelExpr) (r : ℝ) (u : InitialArgs) : ℝ := + f.eval (u (.inl ())) r (u (.inr false)) +def initialGradient (f : KernelExpr) (r : ℝ) (u : InitialArgs) : InitialArgs→L[ℝ]ℝ := + (f.gradient (phiSelect () false u+(0,(r,0)))).comp (phiSelect () false) +def phiExpr : KernelExpr := .atom 0 0 false + +lemma initialKernel_phi (r : ℝ) (u : InitialArgs) : + initialKernel phiExpr r u=phi (u (.inl ())) r (u (.inr false)) := moment_base _ _ _ +lemma phiExpr_dz (z r a : ℝ) : phiExpr.dz.eval z r a=phiZ z r a := by + have H:=phiExpr.hasDerivAt_z z r a + have He : phiExpr.eval=phi := funext fun _=>funext fun _=>funext fun _=>moment_base _ _ _ + rw [He] at H + exact H.unique (phi_hasDerivAt z r a) + +lemma initialGradient_primary (f : KernelExpr) (r : ℝ) (u : InitialArgs) : + partialAt (initialGradient f r u) (.inl ())=f.dz.eval (u (.inl ())) r (u (.inr false)) := by + simp [partialAt,initialGradient,phiSelect,KernelExpr.gradient,grad3,grad2, + ContinuousLinearMap.toSpanSingleton_apply,eval3] + +lemma initialKernel_hasFDerivAt (f : KernelExpr) (r : ℝ) (u : InitialArgs) : + HasFDerivAt (initialKernel f r) (initialGradient f r u) u := by + have H:=(f.hasFDerivAt_eval (phiSelect () false u+(0,(r,0)))).comp u + ((phiSelect () false).hasFDerivAt.add_const (0,(r,0))) + convert! H using 1 + ext v + simp [initialKernel,eval3,phiSelect_apply] + +def literalInitial (J : Interaction n) (j d : ℝ) (f : KernelExpr) + (z m : VectorFields n) (a c : Spin n→ℝ) (r e : Fin n→ℝ) : OrdinaryData n Unit Bool Bool where + J:=J + j:=j + H:=fun _=>z + predecessor:=fun _=>m + θ:=fun b x=>if b then d*c x else a x + seed:=fun b i=>if b then Real.tanh (r i)/d else e i + seedFunction:=fun _ b i u=>if b then -j*u (.inr true)*initialKernel phiExpr (r i) u else initialKernel f (r i) u + seedDerivative:=fun _ b i u=>if b then (-j) • + (u (.inr true) • initialGradient phiExpr (r i) u+ + (initialKernel phiExpr (r i) u) • ContinuousLinearMap.proj (.inr true)) + else initialGradient f (r i) u + auxFunction:=fun _ _ i u=>initialKernel phiExpr (r i) u + auxDerivative:=fun _ _ i u=>initialGradient phiExpr (r i) u + +lemma literalInitial_coefficient (J : Interaction n) (j d : ℝ) (f : KernelExpr) + (z m : VectorFields n) (a c : Spin n→ℝ) (r e : Fin n→ℝ) (x : Spin n) (i : Fin n) : + (literalInitial J j d f z m a c r e).implicitCoefficient x i=phi (z x i) (r i) (a x) := by + simp [OrdinaryData.implicitCoefficient,OrdinaryData.auxCoefficient,literalInitial, + coefficient,initialKernel_phi,localArgs] + +lemma literalInitial_source (J : Interaction n) (j d : ℝ) (f : KernelExpr) + (z m y : VectorFields n) (a c : Spin n→ℝ) (r e : Fin n→ℝ) (hd : d≠0) (x : Spin n) (i : Fin n) : + (literalInitial J j d f z m a c r e).sourceOf 1 (fun _=>y) x i= + f.eval (z x i) (r i) (a x)*e i+ + phi (z x i) (r i) (a x)*(y x i-j*c x*Real.tanh (r i)) := by + simp [OrdinaryData.sourceOf,OrdinaryData.seedCoefficient,OrdinaryData.auxCoefficient, + literalInitial,coefficient,initialKernel,phiExpr,KernelExpr.eval,moment_base,localArgs] + field_simp + ring + +lemma literalInitial_partial (J : Interaction n) (j d : ℝ) (f : KernelExpr) + (z m y : VectorFields n) (a c : Spin n→ℝ) (r e : Fin n→ℝ) (hd : d≠0) (x : Spin n) (i : Fin n) : + (literalInitial J j d f z m a c r e).implicitPartial y x i= + f.dz.eval (z x i) (r i) (a x)*e i+ + phiZ (z x i) (r i) (a x)*(y x i-j*c x*Real.tanh (r i)) := by + simp only [OrdinaryData.implicitPartial,OrdinaryData.partialOf,OrdinaryData.seedPartial, + OrdinaryData.auxPartial,localPartial,literalInitial,Fintype.sum_bool,Fin.sum_univ_one] + simp only [Bool.false_eq_true,↓reduceIte,initialGradient_primary] + simp [partialAt,initialGradient,phiSelect,KernelExpr.gradient,grad3,grad2, + ContinuousLinearMap.toSpanSingleton_apply,eval3,localArgs,phiExpr_dz] + field_simp + ring + +end SKGapCutoff.Recipe + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/LiteralInitialSystem.lean b/lean/OAI/Probability/SKGap/Localization/LiteralInitialSystem.lean new file mode 100644 index 0000000000000000000000000000000000000000..263a9371676096161967d97561ed521d09662b88 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/LiteralInitialSystem.lean @@ -0,0 +1,221 @@ +import Mathlib +import OAI.Probability.SKGap.Matrix.NormalizedPrimaryRecipe +import OAI.Probability.SKGap.Stability.ImplicitPerturb +import OAI.Probability.SKGap.Localization.LiteralInitialRecipe + +namespace OAI + +section + +noncomputable section +open scoped BigOperators +namespace SKGapCutoff.Recipe +open SKGap.Stein Primary SKGap.ImplicitSystem Matrix +variable {n : ℕ} + +def initialU (f : KernelExpr) (z : VectorFields n) (a : Spin n→ℝ) (r e : Fin n→ℝ) : VectorFields n := + fun x i=>f.eval (z x i) (r i) (a x)/phi (z x i) (r i) (a x)*e i + +def initialP (f : KernelExpr) (z : VectorFields n) (a : Spin n→ℝ) (r e : Fin n→ℝ) : VectorFields n := + fun x i=>(f.dz.eval (z x i) (r i) (a x)-logSlope (z x i) (r i) (a x)*f.eval (z x i) (r i) (a x))*e i + +lemma ratio_dz_phi (f : KernelExpr) (z r a : ℝ) : + phi z r a*((RatioExpr.kernel f).d .z).eval z r a= + f.dz.eval z r a-logSlope z r a*f.eval z r a := by + change phi z r a*(f.dz.eval z r a/phi z r a+ + -1*(f.eval z r a/phi z r a*(phiExpr.dz.eval z r a/phi z r a)))=_ + rw [phiExpr_dz,logSlope] + field_simp [(phi_pos z r a).ne'] + ring + +lemma initialP_ratio (f : KernelExpr) (z : VectorFields n) (a : Spin n→ℝ) (r e : Fin n→ℝ) : + initialP f z a r e=fun x i=>phi (z x i) (r i) (a x)* + (((RatioExpr.kernel f).d .z).eval (z x i) (r i) (a x)*e i) := by + ext x i + rw [←mul_assoc,ratio_dz_phi] + rfl + +lemma literalInitial_partial_source (J : Interaction n) (j d : ℝ) (f : KernelExpr) + (z m w y : VectorFields n) (a c : Spin n→ℝ) (r e : Fin n→ℝ) (hd : d≠0) (x : Spin n) + (hw : w x=(literalInitial J j d f z m a c r e).sourceOf 1 (fun _=>y) x) : + (literalInitial J j d f z m a c r e).implicitPartial y x= + fun i=>logSlope (z x i) (r i) (a x)*w x i+initialP f z a r e x i := by + ext i + rw [literalInitial_partial _ _ _ _ _ _ _ _ _ _ _ hd,hw,literalInitial_source _ _ _ _ _ _ _ _ _ _ _ hd] + dsimp only [initialP,logSlope] + field_simp [(phi_pos (z x i) (r i) (a x)).ne'] + ring + +lemma literalInitial_field (J : Interaction n) (j d : ℝ) (f : KernelExpr) + (z m w y : VectorFields n) (a c : Spin n→ℝ) (r e : Fin n→ℝ) (x : Spin n) + (hw : w x=(literalInitial J j d f z m a c r e).sourceOf 1 (fun _=>y) x) + (hc : c x=siteMean ((literalInitial J j d f z m a c r e).implicitPartial y) x) : + (literalInitial J j d f z m a c r e).fieldOf 1 (fun _=>w) (fun _=>y) x= + fun i=>J.mulVec (w x) i-j*siteMean (fun x i=>phi (z x i) (r i) (a x)) x*w x i-j*c x*m x i := by + ext i + simp only [OrdinaryData.fieldOf,←hw,Fintype.sum_unique] + change J.mulVec (w x) i-j*(siteMean ((literalInitial J j d f z m a c r e).implicitPartial y) x*m x i)- + j*(siteMean ((literalInitial J j d f z m a c r e).implicitCoefficient) x*w x i)=_ + have he : (literalInitial J j d f z m a c r e).implicitCoefficient=fun x i=>phi (z x i) (r i) (a x) := by + ext v k; exact literalInitial_coefficient .. + rw [he,←hc] + ring + +lemma initial_scalar_equation (f : KernelExpr) (z w : VectorFields n) + (a c : Spin n→ℝ) (r e : Fin n→ℝ) (x : Spin n) : + c x=(n:ℝ)⁻¹*inner ℝ (WithLp.toLp 2 (fun i=>logSlope (z x i) (r i) (a x)) : Euclid n) + (WithLp.toLp 2 (w x))+siteMean (initialP f z a r e) x ↔ + c x=siteMean (fun x i=>logSlope (z x i) (r i) (a x)*w x i+initialP f z a r e x i) x := by + simp only [EuclideanSpace.inner_eq_star_dotProduct,star_trivial,dotProduct,siteMean, + Finset.sum_add_distrib,div_eq_mul_inv] + simp [mul_comm,add_comm,mul_add] + +end SKGapCutoff.Recipe + +end +end + +section + +noncomputable section +open scoped BigOperators Matrix.Norms.Frobenius +namespace SKGapCutoff.Recipe +open SKGap.Stein Primary +variable {n : ℕ} {ι κ : Type*} [Fintype ι] [Fintype κ] + +lemma fixed_root_ratio_regular (f : RatioExpr) (H : ι→VectorFields n) + (θ : κ→Spin n→ℝ) (x : Spin n) (l : ι) (α : κ) (r : Fin n→ℝ) : + SegmentRegular H θ (fun i u=>eval3 f.eval (phiSelect l α u+(0,(r i,0)))) + (fun i u=>(f.gradient (phiSelect l α u+(0,(r i,0)))).comp (phiSelect l α)) x + (f.dBudget+f.ddBudget) := by + have h:=phi_ratio_segmentRegular f H θ x (phiSelect l α) (fun i=>(0,(r i,0))) + apply h.mono + have h1:=phiSelect_norm l α + have h2:=pow_le_pow_left₀ (norm_nonneg (phiSelect l α)) h1 2 + simpa only [mul_one,one_pow] using add_le_add + (mul_le_mul_of_nonneg_left h1 f.dBudget_nonneg) + (mul_le_mul_of_nonneg_left h2 f.ddBudget_nonneg) + +lemma SegmentRegular.coefficientBound {H : ι→VectorFields n} {θ : κ→Spin n→ℝ} + {F : Fin n→Args (ι:=ι) (κ:=κ)→ℝ} + {F' : Fin n→Args (ι:=ι) (κ:=κ)→Args (ι:=ι) (κ:=κ)→L[ℝ]ℝ} + {x : Spin n} {L A T : ℝ} (h : SegmentRegular H θ F F' x L) + (hA : 0≤A) (hT : 0≤T) (ha : ∀i,|F i (localArgs H θ x i)|≤A) + (hD : (∑l,SKGap.opNorm (derivativeMatrix (H l) x))+(∑α,‖derivativeVector (θ α) x‖)≤T) : + CoefficientBound (coefficient H θ F) x A (L*T) := by + refine ⟨hA,mul_nonneg h.nonneg hT,ha,?_⟩ + intro i + have hr:=(coefficient_row_bound H θ F F' x i h.nonneg (h.deriv i) (h.bound i)).trans + (mul_le_mul_of_nonneg_left hD h.nonneg) + simpa only [vectorNorm_sq] using pow_le_pow_left₀ (vectorNorm_nonneg _) hr 2 + +lemma fixed_root_kernel_coefficientBound (f : KernelExpr) (H : ι→VectorFields n) + (θ : κ→Spin n→ℝ) (x : Spin n) (l : ι) (α : κ) (r : Fin n→ℝ) + {R T : ℝ} (hT : 0≤T) (hx : |θ α x|≤R) (hf : ∀k,|θ α (flip x k)|≤R) + (hD : (∑l,SKGap.opNorm (derivativeMatrix (H l) x))+(∑α,‖derivativeVector (θ α) x‖)≤T) : + CoefficientBound (fun y i=>f.eval (H l y i) (r i) (θ α y)) x + (f.mass*Real.exp (R/2)) ((f.dBudget R+f.ddBudget R)*T) := by + have h:=fixed_root_kernel_regular f H θ x l α r R hx hf + have hb:=h.coefficientBound (mul_nonneg f.mass_nonneg (Real.exp_pos _).le) hT + (fun i=>f.absolute_bound (R:=R) (x:=phiSelect l α (localArgs H θ x i)+(0,(r i,0))) + (by simpa [strip,phiSelect,localArgs] using hx)) hD + simp only [eval3,phiSelect_apply,Prod.fst_add,Prod.snd_add,zero_add,add_zero] at hb + exact hb + +lemma fixed_root_ratio_coefficientBound (f : RatioExpr) (H : ι→VectorFields n) + (θ : κ→Spin n→ℝ) (x : Spin n) (l : ι) (α : κ) (r : Fin n→ℝ) + {T : ℝ} (hT : 0≤T) + (hD : (∑l,SKGap.opNorm (derivativeMatrix (H l) x))+(∑α,‖derivativeVector (θ α) x‖)≤T) : + CoefficientBound (fun y i=>f.eval (H l y i) (r i) (θ α y)) x + f.mass ((f.dBudget+f.ddBudget)*T) := by + have h:=fixed_root_ratio_regular f H θ x l α r + have hb:=h.coefficientBound f.mass_nonneg hT (fun i=>f.bounded _ _ _) hD + simp only [eval3,phiSelect_apply,Prod.fst_add,Prod.snd_add,zero_add,add_zero] at hb + exact hb +end SKGapCutoff.Recipe + +end +end + +section + +noncomputable section +open scoped BigOperators Matrix.Norms.Frobenius +namespace SKGapCutoff.Recipe +open SKGap.Stein Primary SKGap.ImplicitSystem +variable {n : ℕ} + +def kernelSmallBudget (f : KernelExpr) (R T : ℝ) : ℝ := + f.mass*Real.exp (R/2)+3*((f.dBudget R+f.ddBudget R)*T) +def ratioSmallBudget (f : RatioExpr) (T : ℝ) : ℝ := + f.mass+3*((f.dBudget+f.ddBudget)*T) +lemma kernelSmallBudget_nonneg (f : KernelExpr) (R T : ℝ) (hT : 0≤T) : + 0≤kernelSmallBudget f R T := by + exact add_nonneg (mul_nonneg f.mass_nonneg (Real.exp_pos _).le) + (mul_nonneg (by norm_num) (mul_nonneg (add_nonneg (f.dBudget_nonneg _) (f.ddBudget_nonneg _)) hT)) +lemma ratioSmallBudget_nonneg (f : RatioExpr) (T : ℝ) (hT : 0≤T) : + 0≤ratioSmallBudget f T := by + exact add_nonneg f.mass_nonneg + (mul_nonneg (by norm_num) (mul_nonneg (add_nonneg f.dBudget_nonneg f.ddBudget_nonneg) hT)) + +lemma initial_kernel_bound (f : KernelExpr) (z : VectorFields n) (a : Spin n→ℝ) + (r : Fin n→ℝ) (x : Spin n) {R T : ℝ} (hT : 0≤T) + (ha : |a x|≤R) (haf : ∀k,|a (flip x k)|≤R) + (hD : SKGap.opNorm (derivativeMatrix z x)+‖derivativeVector a x‖≤T) : + CoefficientBound (fun v i=>f.eval (z v i) (r i) (a v)) x + (f.mass*Real.exp (R/2)) ((f.dBudget R+f.ddBudget R)*T) := by + apply fixed_root_kernel_coefficientBound f (fun _ : Unit=>z) (fun _ : Unit=>a) x () () r hT ha haf + simpa only [Fintype.sum_unique] using hD + +lemma initial_ratio_bound (f : RatioExpr) (z : VectorFields n) (a : Spin n→ℝ) + (r : Fin n→ℝ) (x : Spin n) {T : ℝ} (hT : 0≤T) + (hD : SKGap.opNorm (derivativeMatrix z x)+‖derivativeVector a x‖≤T) : + CoefficientBound (fun v i=>f.eval (z v i) (r i) (a v)) x + f.mass ((f.dBudget+f.ddBudget)*T) := by + apply fixed_root_ratio_coefficientBound f (fun _ : Unit=>z) (fun _ : Unit=>a) x () () r hT + simpa only [Fintype.sum_unique] using hD + +lemma initialU_small (f : KernelExpr) (z : VectorFields n) (a : Spin n→ℝ) + (r e : Fin n→ℝ) (x : Spin n) {T : ℝ} (hT : 0≤T) (he : vectorNorm e≤1) + (hD : SKGap.opNorm (derivativeMatrix z x)+‖derivativeVector a x‖≤T) : + SmallBound (initialU f z a r e) x (ratioSmallBudget (.kernel f) T) := by + have H:=(initial_ratio_bound (.kernel f) z a r x hT hD).small_product ((SmallBound.seed e x).mono he) + simp only [one_mul] at H + convert! H using 1 + +lemma initialP_small (f : KernelExpr) (z : VectorFields n) (a : Spin n→ℝ) + (r e : Fin n→ℝ) (x : Spin n) {R T : ℝ} (hT : 0≤T) (he : vectorNorm e≤1) + (ha : |a x|≤R) (haf : ∀k,|a (flip x k)|≤R) + (hD : SKGap.opNorm (derivativeMatrix z x)+‖derivativeVector a x‖≤T) : + SmallBound (initialP f z a r e) x + (ratioSmallBudget ((RatioExpr.kernel f).d .z) T*kernelSmallBudget phiExpr R T) := by + have hu:=(initial_ratio_bound ((RatioExpr.kernel f).d .z) z a r x hT hD).small_product ((SmallBound.seed e x).mono he) + simp only [one_mul] at hu + have hp:=(initial_kernel_bound phiExpr z a r x hT ha haf hD).small_product hu + rw [initialP_ratio] + convert! hp using 1 + ext v i + rw [phiExpr,KernelExpr.eval,moment_base] + +lemma scaledMean_norm (hn : 0Real.sqrt (n:ℝ)*c v) x‖≤Vc) + (hcoeff : (literalFullData j J h l f a c r e).CoefficientClass N x A) : + LocalOrdinaryInput (literalFullData j J h l f a c r e) + (fun q=>primaryTree j J h x q.val) x N + (literalEnvironmentConstants j K B A Va Vc M hK hB hA hVa hVc) := by + have hp:=primary_local_input J h x hn hK hB hop M hformal + refine ⟨hn,hop,hp.primaryShape,hp.primaryFieldError,hp.primarySourceError, + hp.primaryValue,hp.primaryDerivative,?_,?_,hcoeff.seedRegular,hcoeff.auxRegular,?_,?_⟩ + · exact literalInitial_seed_bound J j f (fld j J h l.val) (mag j J h l.val) a c r e hn he + · change (∑q : Fin M⊕Bool,‖derivativeVector (literalFullParameters j J h a c q) x‖)≤_ + rw [Fintype.sum_sum_type,Fintype.sum_bool] + have hh:=hp.parameter + change (∑q : Fin M,‖derivativeVector (fun v=>j*(onsager j J h (q.val+1) v-onsager j J h q.val v)) x‖)≤_ at hh + change (∑q : Fin M,‖derivativeVector (fun v=>j*(onsager j J h (q.val+1) v-onsager j J h q.val v)) x‖)+ + (‖derivativeVector (fun v=>Real.sqrt (n:ℝ)*c v) x‖+‖derivativeVector a x‖)≤_ + dsimp only [literalEnvironmentConstants] + linarith + · intro b hb s i;exact (hcoeff.seedValue b hb s).at i + · intro b hb s i;exact (hcoeff.auxValue b hb s).at i + +end SKGapCutoff.Recipe + +end +end + +section + +noncomputable section +open scoped BigOperators Matrix.Norms.Frobenius +namespace SKGapCutoff.Recipe +open Primary Static SKGap.Stein SKGap.Noncrossing.Primary SKGap.Noncrossing.Primary.Tensor.Series SKGap.Noncrossing.ClosedMarked +universe u +variable {Ω : Type u} {n : Ω→ℕ} {M : ℕ} + +theorem literal_finite_control (j : ℝ) (J : ∀b,Interaction (n b)) + (h : ∀b,Fin (n b)→ℝ) (l : Fin M) (f : KernelExpr) + (a c : ∀b,Spin (n b)→ℝ) (r e : ∀b,Fin (n b)→ℝ) + (w y : ∀b,VectorFields (n b)) (E : ∀b,Set (Spin (n b))) + (hn : ∀b,0Real.sqrt (n b:ℝ)*c b v) x‖≤Vc) + (heq : ∀b x,x∈E b→LiteralEquations (J b) j f (fld j (J b) (h b) l.val) + (mag j (J b) (h b) l.val) (w b) (y b) (a b) (c b) (r b) (e b) x) + (hdiag : ∀b x,x∈flipNeighborhood (E b)→LiteralInitialDiagnostics + (literalInitial (J b) j (Real.sqrt (n b:ℝ)) f (fld j (J b) (h b) l.val) + (mag j (J b) (h b) l.val) (a b) (c b) (r b) (e b)) + (w b) (y b) (primaryTree j (J b) (h b) x l.val) x V S F A) + (Nmax : ℕ) + (hw : ∀b x,x∈flipNeighborhood (E b)→ClosedWordTestBound j + (fun i=>phi (fld j (J b) (h b) l.val x i) (r b i) (a b x)) (J b) A W (2*Nmax+5)) + (hd : ∀b x,x∈flipNeighborhood (E b)→ClosedWordDiagramBound j + (fun i=>phi (fld j (J b) (h b) l.val x i) (r b i) (a b x)) (J b) A C (2*M+2*Nmax+4)) : + FiniteLocalRecipeControl E j J h (fun b=>literalFullParameters (M:=M) j (J b) (h b) (a b) (c b)) + w y M Nmax A := by + let D:=fun b=>literalFullData j (J b) (h b) l f (a b) (c b) (r b) (e b) + let I:=fun b=>literalInitial (J b) j (Real.sqrt (n b:ℝ)) f (fld j (J b) (h b) l.val) + (mag j (J b) (h b) l.val) (a b) (c b) (r b) (e b) + let K₀:=literalCoefficientBudget f j R Bc + have hK₀ : 1≤K₀ := by + have h2 : 0≤f.mass*Real.exp (R/2):=mul_nonneg f.mass_nonneg (Real.exp_pos _).le + have h3 : 0≤(1+|j| *|Bc|)*phiExpr.mass*Real.exp (R/2):=by positivity [phiExpr.mass_nonneg] + dsimp [K₀,literalCoefficientBudget];linarith [abs_nonneg (initialRegularBudget f j R Bc)] + have H:=literal_full_local_family j J h l f a c r e w y E hn he hBc ha hc heq + have H₀:=H.mono (Nat.zero_le l.val) le_rfl le_rfl (le_refl K₀) + have hi : ∀b x,x∈flipNeighborhood (E b)→LocalOrdinaryInput (D b) + (fun q=>primaryTree j (J b) (h b) x q.val) x 1 + (literalEnvironmentConstants j K B K₀ Va Vc M hK hB hK₀ hVa hVc) := by + intro b x hx + exact literal_full_local_input j (J b) (h b) l f (a b) (c b) (r b) (e b) x 1 + (hn b) (he b) hK hB hK₀ hVa hVc (hop b) (hformal b x) (hDa b x hx) (hDc b x hx) + (H.coefficients b x hx) + have hm (b : Ω) (x : Spin (n b)) (q : Fin M) : + Marked.mass (GradedWords.ordinaryWords j (primaryTree j (J b) (h b) x q.val)).1≤(2+|j|)^M ∧ + Marked.mass (GradedWords.ordinaryWords j (primaryTree j (J b) (h b) x q.val)).2≤(2+|j|)^M := by + have hb:=ordinary_mass_bridge j (primaryTree j (J b) (h b) x q.val) + rw [hb.1,hb.2] + have hm:=primaryTree_mass (hn b) j (J b) (h b) x q.val + have hp : (2+|j|)^q.val≤(2+|j|)^M:=pow_le_pow_right₀ (by linarith [abs_nonneg j]) q.isLt.le + exact ⟨hm.1.trans hp,hm.2.trans hp⟩ + have ht (b : Ω) (x : Spin (n b)) (q : Fin M) : + GradedControl A (2*M+1) (GradedWords.ordinaryWords j (primaryTree j (J b) (h b) x q.val)).1 ∧ + GradedControl A (2*M+1) (GradedWords.ordinaryWords j (primaryTree j (J b) (h b) x q.val)).2 := by + apply ordinary_control_bridge + have hv:=primaryTree_control j (J b) (h b) x q.val hA + exact ⟨hv.1.mono (by omega),hv.2.mono (by omega)⟩ + apply finite_started_control_seeds D K₀ H₀ I (fun _=>rfl) (fun _=>rfl) + (fun b x q=>primaryTree j (J b) (h b) x q.val) (fun b x=>primaryTree j (J b) (h b) x l.val) + (literalEnvironmentConstants j K B K₀ Va Vc M hK hB hK₀ hVa hVc) A hi Sum.inl + (fun _ _=>rfl) Nmax (2*M+1) S F V W C ((2+|j|)^M) hA hS hF hV hW hC (by positivity) + · exact fun b x hx=>(hdiag b x hx).source + · exact fun b x hx=>(hdiag b x hx).source_flip + · exact fun b x hx=>(hdiag b x hx).field + · exact fun b x hx=>(hdiag b x hx).field_flip + · exact fun b x hx=>(hdiag b x hx).coefficient_nonneg + · exact fun b x hx=>(hdiag b x hx).inverse_pos + · exact fun b x hx=>(hdiag b x hx).source_bound + · exact fun b x hx=>(hdiag b x hx).field_bound + · exact fun b x hx=>(hdiag b x hx).partial_bound.size + · exact fun b x hx=>(hdiag b x hx).source_trace + · exact fun b x hx=>(hdiag b x hx).field_trace + · exact fun b x hx=>(hdiag b x hx).coefficient_bound + · exact fun b x _ q=>hm b x q + · exact fun b x _=>hm b x l + · exact fun b x _ q=>ht b x q + · exact fun b x _=>ht b x l + · intro b x hx + have hcoef : (I b).implicitCoefficient x=fun i=>phi (fld j (J b) (h b) l.val x i) (r b i) (a b x) := + funext fun i=>literalInitial_coefficient _ _ _ _ _ _ _ _ _ _ _ _ + rw [hcoef];exact hw b x hx + · intro b x hx + have hcoef : (I b).implicitCoefficient x=fun i=>phi (fld j (J b) (h b) l.val x i) (r b i) (a b x) := + funext fun i=>literalInitial_coefficient _ _ _ _ _ _ _ _ _ _ _ _ + rw [hcoef] + convert hd b x hx using 1 + omega + +end SKGapCutoff.Recipe + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/LiteralLocalWeak.lean b/lean/OAI/Probability/SKGap/Localization/LiteralLocalWeak.lean new file mode 100644 index 0000000000000000000000000000000000000000..0a97f5c11b5c6fbe8ae943b006d14bfd5c8fbb54 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/LiteralLocalWeak.lean @@ -0,0 +1,159 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.LocalResidualInduction +import OAI.Probability.SKGap.Localization.LiteralLocalInput + +namespace OAI + +section + +noncomputable section +open scoped BigOperators Matrix.Norms.Frobenius +namespace SKGapCutoff.Recipe +open Primary Static SKGap.Stein SKGap.Noncrossing.Primary SKGap.Noncrossing.Primary.Tensor.Series SKGap.Noncrossing.ClosedMarked +universe u +variable {Ω : Type u} {n : Ω→ℕ} {M : ℕ} + +def literalResidualBudget (j : ℝ) (f : KernelExpr) (R B : ℝ) (p : ℕ) : ℝ := + residualCoefficientBudget j (2+|literalCoefficientBudget f j R B|) p 0 + +theorem literal_local_weak_residual (j : ℝ) (J : ∀b,Interaction (n b)) + (h : ∀b,Fin (n b)→ℝ) (l : Fin M) (f : KernelExpr) + (a c : ∀b,Spin (n b)→ℝ) (r e : ∀b,Fin (n b)→ℝ) + (w y : ∀b,VectorFields (n b)) (E : ∀b,Set (Spin (n b))) + (hn : ∀b,0Real.sqrt (n b:ℝ)*c b v) x‖≤Vc) + (heq : ∀b x,x∈E b→LiteralEquations (J b) j f (fld j (J b) (h b) l.val) + (mag j (J b) (h b) l.val) (w b) (y b) (a b) (c b) (r b) (e b) x) + (hdiag : ∀b x,x∈flipNeighborhood (E b)→LiteralInitialDiagnostics + (literalInitial (J b) j (Real.sqrt (n b:ℝ)) f (fld j (J b) (h b) l.val) + (mag j (J b) (h b) l.val) (a b) (c b) (r b) (e b)) + (w b) (y b) (primaryTree j (J b) (h b) x l.val) x V S F (literalResidualBudget j f R Bc l.val)) + (P : ∀b,Observables (n b)) (hP : ∀b x,0≤P b x) (hp : ∀b,∑x,P b x=1) + (hm : ∀b x i,conditionalMean (P b) x i=mag j (J b) (h b) 1 x i) + (hJ : ∀b,(J b).IsSymm) + (hw : ∀b x,x∈flipNeighborhood (E b)→ClosedWordTestBound j + (fun i=>phi (fld j (J b) (h b) l.val x i) (r b i) (a b x)) (J b) (literalResidualBudget j f R Bc l.val) W (2*(1+2*l.val)+5)) + (hd : ∀b x,x∈flipNeighborhood (E b)→ClosedWordDiagramBound j + (fun i=>phi (fld j (J b) (h b) l.val x i) (r b i) (a b x)) (J b) (literalResidualBudget j f R Bc l.val) C (2*M+2*(1+2*l.val)+4)) : + LocalUniformWeak E P (fun b x=>∑i,residual j (J b) (h b) l.val x i*w b x i) := by + let Kt:=2+|literalCoefficientBudget f j R Bc| + have hKt : 2≤Kt := by dsimp [Kt];linarith [abs_nonneg (literalCoefficientBudget f j R Bc)] + have hKt0 : 0≤Kt:=by linarith + have hA : 1≤literalResidualBudget j f R Bc l.val := + (by linarith : 1≤Kt).trans (residualCoefficientBudget_ge j hKt0 l.val 0) + have C:=literal_finite_control j J h l f a c r e w y E hn he + hK hB hBc hVa hVc hA hV hS hF hW hC hop hformal ha hc hDa hDc heq hdiag + (1+2*l.val) hw hd + have H:=literal_full_local_family j J h l f a c r e w y E hn he hBc ha hc heq + have hclass : literalCoefficientBudget f j R Bc≤Kt := by + dsimp [Kt];linarith [le_abs_self (literalCoefficientBudget f j R Bc)] + have HH:=H.mono le_rfl le_rfl le_rfl hclass + have hwk:=uniform_local_weak_residual l.val 1 hKt l.isLt Sum.inl (fun _ _=>rfl) + C hP hp hm hn hJ (fun b=>literalFullData j (J b) (h b) l f (a b) (c b) (r b) (e b)) HH + apply hwk.congr_on + intro b x hx + rw [(H.initial b x hx).1] + +end SKGapCutoff.Recipe + +end +end + +section + +noncomputable section +open scoped BigOperators Matrix.Norms.Frobenius +namespace SKGapCutoff.Recipe +open SKGap.Stein Primary +variable {n : ℕ} + +theorem literal_complete_diagnostics (j R ρ δ T L Q E : ℝ) (f : KernelExpr) + (hj : 0≤j) (hδ : 0<δ) (hρ : 0≤ρ) (hT : 0≤T) (hQ : 0≤Q) + (hsmall : ρ≤δ/(2*(|j| *Real.exp (R/2)*(3*Real.exp (R/2)+16)+1))) : + ∃B≥0,∃S≥0,∃F≥0,∃Bc≥0,∃Vc≥0,∀n : ℕ,0Real.sqrt n*c v) x‖≤Vc) ∧ + (∀x (t : SKGap.Noncrossing.Primary.SourceTree (Fin n→ℝ)), + LiteralStableAt J j z m a r R ρ δ x→ + (∀k,LiteralStableAt J j z m a r R ρ δ (flip x k))→ + SKGap.opNorm (derivativeMatrix z x)+‖derivativeVector a x‖≤T→ + SKGap.opNorm (derivativeMatrix m x)≤T→(∀i,|m x i|≤1)→ + ‖derivativeMatrix z x-t.fieldMatrix j J‖≤E→ + ‖derivativeMatrix m x-t.sourceMatrix j J‖≤E→ + (∑i,∑k,(derivativeMatrix z x i k)^4)≤Q^4→ + (∑i,(derivativeMatrix z x i i)^2)≤T^2→ + LiteralInitialDiagnostics (literalInitial J j (Real.sqrt n) f z m a c r e) + w y t x B S F (Real.exp (R/2))) := by + obtain ⟨C,hC,hsol⟩:=literal_implicit_construction j R ρ δ T L f hδ hρ hT hsmall + let Cp:=initialPartialBudget f R T C + have hCp : 0≤Cp := by + dsimp only [Cp,initialPartialBudget] + exact add_nonneg (mul_nonneg hC (ratioSmallBudget_nonneg _ _ hT)) + (mul_nonneg (ratioSmallBudget_nonneg _ _ hT) (kernelSmallBudget_nonneg _ _ _ hT)) + let Bs:=|literalSizeBudget j δ R L f| + let Cr:=initialRegularBudget f j R Bs + let S:=(2*Cr+Cr*C)*initialTraceFactor Q T C+Cp*E + let F:=|j| *(Cp*E)+|j| *(Cp*(1+2*T)+3*C*((phiExpr.dBudget R+phiExpr.ddBudget R)*T)) + refine ⟨C+Cp,add_nonneg hC hCp,|S|,abs_nonneg _,|F|,abs_nonneg _,Bs,abs_nonneg _,C,hC,?_⟩ + intro n hn J z m a r e hJ hJL he + obtain ⟨w,y,c,heq,hb⟩:=hsol n hn J z m a r e hJL he + have hcs {v : Spin n} (HV : LiteralStableAt J j z m a r R ρ δ v) : + |Real.sqrt n*c v|≤Bs := by + have hh:=literal_initial_size J j f z m w y a c r e v hn hδ hρ hsmall hJL he HV (heq v HV) + rw [abs_mul,abs_of_nonneg (Real.sqrt_nonneg _)] + dsimp only [Bs] + exact le_trans (by linarith [vectorNorm_nonneg (w v),vectorNorm_nonneg (y v)]) (le_abs_self _) + refine ⟨w,y,c,heq,fun x H=>hcs H,fun x H Hf hD hDm=>(hb x H Hf hD hDm).2.2.2,?_⟩ + intro x t H Hf hD hDm hm hEz hEm hQ4 hdi + have hd : Real.sqrt (n:ℝ)≠0:=(Real.sqrt_pos.mpr (Nat.cast_pos.mpr hn)).ne' + have heqr {v : Spin n} (HV : LiteralStableAt J j z m a r R ρ δ v) := + (literalEquations_recipe J j (Real.sqrt n) f z m w y a c r e hd v).mp (heq v HV) + have hsize {v : Spin n} (HV : LiteralStableAt J j z m a r R ρ δ v) : + |Real.sqrt n*c v|≤Bs := by + have hh:=literal_initial_size J j f z m w y a c r e v hn hδ hρ hsmall hJL he HV (heq v HV) + rw [abs_mul,abs_of_nonneg (Real.sqrt_nonneg _)] + dsimp only [Bs] + exact le_trans (by linarith [vectorNorm_nonneg (w v),vectorNorm_nonneg (y v)]) (le_abs_self _) + obtain ⟨hw,hy,hc,hDc⟩:=hb x H Hf hD hDm + have hp:=literalInitial_partial_small J j (Real.sqrt n) f z m w y a c r e x hd hT he + H.a_bound (fun k=>(Hf k).a_bound) hD hw (heqr H).1 (fun k=>(heqr (Hf k)).1) + obtain ⟨hS,hF⟩:=literalInitial_traces J j f z m w y a c r e x t hn hT hQ + (abs_nonneg _) he H.a_bound (fun k=>(Hf k).a_bound) (hsize H) (fun k=>hsize (Hf k)) + hD hDm hm hw hy hDc (heqr H).1 (fun k=>(heqr (Hf k)).1) hEz hEm hQ4 hdi + refine ⟨(heqr H).1,(fun k=>(heqr (Hf k)).1),(heqr H).2.1, + (fun k=>(heqr (Hf k)).2.1),?_,?_,?_,hw.mono (le_add_of_nonneg_right hCp), + hy.mono (le_add_of_nonneg_right hCp),hp.mono (le_add_of_nonneg_left hC), + hS.mono (le_abs_self _),hF.mono (le_abs_self _)⟩ + · intro i + rw [literalInitial_coefficient] + exact (phi_pos ..).le + · intro i + rw [literalInitial_coefficient,abs_of_pos (phi_pos ..)] + exact (phi_le_exp ..).trans (Real.exp_le_exp.mpr (by linarith [H.a_bound])) + · have hcoef : (literalInitial J j (Real.sqrt n) f z m a c r e).implicitCoefficient= + fun v i=>phi (z v i) (r i) (a v) := by + ext v i + exact literalInitial_coefficient .. + rw [hcoef] + exact literal_inverse_stability J j z m a r x hn hj hJ hδ hρ hsmall H +end SKGapCutoff.Recipe + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/LiteralMargin.lean b/lean/OAI/Probability/SKGap/Localization/LiteralMargin.lean new file mode 100644 index 0000000000000000000000000000000000000000..3de215fd5cb337d0ee92aacd7eb7c68076f9ab27 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/LiteralMargin.lean @@ -0,0 +1,163 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.LiteralConstruction +import OAI.Probability.SKGap.Matrix.LiteralTrace +import OAI.Probability.SKGap.Matrix.StartedMatrixEvent + +namespace OAI + +section + +noncomputable section +open scoped BigOperators +namespace SKGapCutoff.Recipe +open SKGap.Stein Primary SKGap.ImplicitSystem Matrix +variable {n : ℕ} + +lemma realQuadratic_eq_inner (M : Interaction n) (v : Euclid n) : + SKGap.RealComplex.realQuadratic M v=inner ℝ v (toEuclideanCLM (𝕜:=ℝ) M v) := by + rw [inner_toEuclideanCLM] + simp only [SKGap.RealComplex.realQuadratic,dotProduct,mulVec,Finset.mul_sum,mul_assoc] + +lemma literal_inverse_margin (J : Interaction n) (j : ℝ) + (z m : VectorFields n) (a : Spin n→ℝ) (r : Fin n→ℝ) (x : Spin n) + (hn : 0phi (z x i) (r i) (a x)) 1 + ((j/n)*∑i,phi (z x i) (r i) (a x)) J)) := by + have : Nonempty (Fin n):=Fin.pos_iff_nonempty.mp hn + let D:=SKGap.pathDiagonal (fun i=>phi (z x i) (r i) (a x)) 1 + let χ:=siteMean (fun v i=>phi (z v i) (r i) (a v)) x + have hq : (j/n)*∑i,phi (z x i) (r i) (a x)=j*χ := by dsimp [χ,siteMean];ring + have hshift : SKGap.pathShift 1 (j*χ)=(j*χ) • (1:Interaction n) := by + simp only [SKGap.pathShift,one_mul,Matrix.smul_one_eq_diagonal] + rw [SKGap.stabilityMatrix_path_rep _ (fun i=>(phi_pos _ _ _).le) (by norm_num),hq,hshift] + apply SKGap.RealComplex.lowerRayleigh_lift_ge + intro v + rw [realQuadratic_eq_inner] + have hpert:=H.perturbation hn hδ hρ hsmall + have hsmall' : |j| *|χ-(∑i,scalarVariance (z x i))/(n:ℝ)| *‖phiSqrt (z x) r (a x)‖^2≤δ/2 := + (le_add_of_nonneg_right (by positivity)).trans hpert + have hp:=ordinary_matrix_margin j χ _ (n:ℝ)⁻¹ δ (phiSqrt (z x) r (a x)) + (toEuclideanCLM (𝕜:=ℝ) J) (WithLp.toLp 2 (fun i=>Real.tanh (z x i))) + hj (by positivity) (phiSqrt_inner _ _ _) H.stable hsmall' v + have hrep : toEuclideanCLM (𝕜:=ℝ) (1-D*(J-(j*χ) • 1)*D)= + 1-phiSqrt (z x) r (a x)*(toEuclideanCLM (𝕜:=ℝ) J-(j*χ) • 1)*phiSqrt (z x) r (a x) := by + simp only [map_sub,map_mul,map_one,map_smul,D,SKGap.pathDiagonal,Real.sqrt_one,one_mul,phiSqrt] + simpa only [←hrep] using hp + +lemma literal_closed_word_event (J : Interaction n) (j : ℝ) + (z m : VectorFields n) (a : Spin n→ℝ) (r : Fin n→ℝ) (x : Spin n) + (hn : 0phi (z x i) (r i) (a x)) J A W (2*Nmax+5) ∧ + ClosedWordDiagramBound j (fun i=>phi (z x i) (r i) (a x)) J A C (2*M+2*Nmax+4) := by + apply hEvent.2.2 _ + · intro i + refine ⟨(phi_pos _ _ _).le,?_⟩ + exact (phi_le_exp ..).trans (Real.exp_le_exp.mpr (by linarith [H.a_bound])) + · exact literal_inverse_margin J j z m a r x hn hj hδ hρ hsmall H +end SKGapCutoff.Recipe + +end +end + +section + +noncomputable section +open scoped BigOperators Matrix.Norms.Frobenius +namespace SKGapCutoff.Recipe +open SKGap.Stein Primary +variable {n : ℕ} + +structure LiteralInitialDiagnostics (D : OrdinaryData n Unit Bool Bool) + (w y : VectorFields n) (t : SKGap.Noncrossing.Primary.SourceTree (Fin n→ℝ)) + (x : Spin n) (B S F A : ℝ) : Prop where + source : w x=D.sourceOf 1 (fun _=>y) x + source_flip : ∀k,w (flip x k)=D.sourceOf 1 (fun _=>y) (flip x k) + field : y x=D.fieldOf 1 (fun _=>w) (fun _=>y) x + field_flip : ∀k,y (flip x k)=D.fieldOf 1 (fun _=>w) (fun _=>y) (flip x k) + coefficient_nonneg : ∀i,0≤D.implicitCoefficient x i + coefficient_bound : ∀i,|D.implicitCoefficient x i|≤A + inverse_pos : (1-SKGap.pathDiagonal (D.implicitCoefficient x) 1* + (D.J-(D.j*siteMean D.implicitCoefficient x) • 1)*SKGap.pathDiagonal (D.implicitCoefficient x) 1).PosDef + source_bound : SmallBound w x B + field_bound : SmallBound y x B + partial_bound : SmallBound (D.implicitPartial y) x B + source_trace : TraceControl (D.implicitSourcePrimitive t y x) S + field_trace : TraceControl (D.implicitFieldPrimitive t w y x) F + +theorem literal_initial_diagnostics (j R ρ δ T L Q E : ℝ) (f : KernelExpr) + (hj : 0≤j) (hδ : 0<δ) (hρ : 0≤ρ) (hT : 0≤T) (hQ : 0≤Q) + (hsmall : ρ≤δ/(2*(|j| *Real.exp (R/2)*(3*Real.exp (R/2)+16)+1))) : + ∃B≥0,∃S≥0,∃F≥0,∀n : ℕ,0(Hf k).a_bound) hD hw (heqr H).1 (fun k=>(heqr (Hf k)).1) + obtain ⟨hS,hF⟩:=literalInitial_traces J j f z m w y a c r e x t hn hT hQ + (abs_nonneg _) he H.a_bound (fun k=>(Hf k).a_bound) (hsize H) (fun k=>hsize (Hf k)) + hD hDm hm hw hy hDc (heqr H).1 (fun k=>(heqr (Hf k)).1) hEz hEm hQ4 hdi + refine ⟨(heqr H).1,(fun k=>(heqr (Hf k)).1),(heqr H).2.1, + (fun k=>(heqr (Hf k)).2.1),?_,?_,?_,hw.mono (le_add_of_nonneg_right hCp), + hy.mono (le_add_of_nonneg_right hCp),hp.mono (le_add_of_nonneg_left hC), + hS.mono (le_abs_self _),hF.mono (le_abs_self _)⟩ + · intro i + rw [literalInitial_coefficient] + exact (phi_pos ..).le + · intro i + rw [literalInitial_coefficient,abs_of_pos (phi_pos ..)] + exact (phi_le_exp ..).trans (Real.exp_le_exp.mpr (by linarith [H.a_bound])) + · have hcoef : (literalInitial J j (Real.sqrt n) f z m a c r e).implicitCoefficient= + fun v i=>phi (z v i) (r i) (a v) := by + ext v i + exact literalInitial_coefficient .. + rw [hcoef] + exact literal_inverse_stability J j z m a r x hn hj hJ hδ hρ hsmall H +end SKGapCutoff.Recipe + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/LiteralPartial.lean b/lean/OAI/Probability/SKGap/Localization/LiteralPartial.lean new file mode 100644 index 0000000000000000000000000000000000000000..e88f693043907452aefc10008af3d91dbc2d8818 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/LiteralPartial.lean @@ -0,0 +1,48 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.LiteralInitialSystem +import OAI.Probability.SKGap.Stability.LocalImplicitNode + +namespace OAI + +section + +noncomputable section +open scoped BigOperators Matrix.Norms.Frobenius +namespace SKGapCutoff.Recipe +open SKGap.Stein Primary +variable {n : ℕ} +lemma SmallBound.of_local_eq {U V : VectorFields n} {x : Spin n} {C : ℝ} + (h : SmallBound V x C) (hx : U x=V x) (hf : ∀k,U (flip x k)=V (flip x k)) : + SmallBound U x C := by + refine ⟨h.nonneg,?_,?_⟩ + · simpa only [hx] using h.size + · rw [derivativeMatrix_congr_on_flips U V x hx hf] + exact h.derivative + +lemma literalInitial_partial_small (J : Interaction n) (j d : ℝ) (f : KernelExpr) + (z m w y : VectorFields n) (a c : Spin n→ℝ) (r e : Fin n→ℝ) (x : Spin n) + (hd : d≠0) {R T B : ℝ} (hT : 0≤T) (he : vectorNorm e≤1) + (ha : |a x|≤R) (haf : ∀k,|a (flip x k)|≤R) + (hD : SKGap.opNorm (derivativeMatrix z x)+‖derivativeVector a x‖≤T) + (hW : SmallBound w x B) + (hw : w x=(literalInitial J j d f z m a c r e).sourceOf 1 (fun _=>y) x) + (hwf : ∀k,w (flip x k)=(literalInitial J j d f z m a c r e).sourceOf 1 (fun _=>y) (flip x k)) : + SmallBound ((literalInitial J j d f z m a c r e).implicitPartial y) x + (B*ratioSmallBudget (.kernel phiExpr.dz) T+ + ratioSmallBudget ((RatioExpr.kernel f).d .z) T*kernelSmallBudget phiExpr R T) := by + have hel:=initial_ratio_bound (.kernel phiExpr.dz) z a r x hT hD + have hs:=(hel.small_product hW).add (initialP_small f z a r e x hT he ha haf hD) + have H : SmallBound (fun v i=>logSlope (z v i) (r i) (a v)*w v i+initialP f z a r e v i) x + (B*ratioSmallBudget (.kernel phiExpr.dz) T+ + ratioSmallBudget ((RatioExpr.kernel f).d .z) T*kernelSmallBudget phiExpr R T) := by + convert! hs using 1 + ext v i + rw [logSlope_ratio] + exact H.of_local_eq (literalInitial_partial_source _ _ _ _ _ _ _ _ _ _ _ _ hd x hw) + (fun k=>literalInitial_partial_source _ _ _ _ _ _ _ _ _ _ _ _ hd _ (hwf k)) +end SKGapCutoff.Recipe + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/LiteralRegularity.lean b/lean/OAI/Probability/SKGap/Localization/LiteralRegularity.lean new file mode 100644 index 0000000000000000000000000000000000000000..b1672f7cf5a8fefeb3ef53950b116819647ecaae --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/LiteralRegularity.lean @@ -0,0 +1,120 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.LiteralInitialRecipe +import OAI.Probability.SKGap.Localization.ResidualAdmissibility + +namespace OAI + +section + +noncomputable section +open scoped BigOperators +namespace SKGapCutoff.Recipe +open SKGap.Stein Primary +variable {n : ℕ} {ι κ : Type*} [Fintype ι] [DecidableEq ι] [Fintype κ] [DecidableEq κ] + +omit [DecidableEq ι] [DecidableEq κ] in +lemma SegmentRegular.const_mul {H : ι→VectorFields n} {θ : κ→Spin n→ℝ} + {F : Fin n→Args (ι:=ι) (κ:=κ)→ℝ} + {F' : Fin n→Args (ι:=ι) (κ:=κ)→Args (ι:=ι) (κ:=κ)→L[ℝ]ℝ} + {x : Spin n} {C : ℝ} (h : SegmentRegular H θ F F' x C) (b : ℝ) : + SegmentRegular H θ (fun i u=>b*F i u) (fun i u=>b • F' i u) x (|b| *C) := by + refine ⟨mul_nonneg (abs_nonneg _) h.nonneg,?_,?_,?_⟩ + · intro i k t ht; exact (h.deriv i k t ht).const_mul b + · intro i k t ht + rw [norm_smul,Real.norm_eq_abs] + exact mul_le_mul_of_nonneg_left (h.bound i k t ht) (abs_nonneg _) + · intro i k t ht + rw [←smul_sub b (F' i _) (F' i _),norm_smul,Real.norm_eq_abs] + exact (mul_le_mul_of_nonneg_left (h.lip i k t ht) (abs_nonneg _)).trans_eq (by ring) + +omit [DecidableEq ι] [DecidableEq κ] in +lemma parameter_regular (H : ι→VectorFields n) (θ : κ→Spin n→ℝ) (x : Spin n) (α : κ) : + SegmentRegular H θ (fun _ u=>u (.inr α)) + (fun _ _=>ContinuousLinearMap.proj (.inr α)) x 1 := by + refine ⟨by norm_num,?_,?_,?_⟩ + · intro i k t ht; exact (ContinuousLinearMap.proj (Sum.inr α : ι ⊕ κ) : Args (ι:=ι) (κ:=κ) →L[ℝ] ℝ).hasFDerivAt + · intro i k t ht + apply ContinuousLinearMap.opNorm_le_bound _ (by norm_num) + intro u + simpa using norm_le_pi_norm u (.inr α) + · intro i k t ht; simp + +omit [Fintype ι] [DecidableEq ι] [Fintype κ] [DecidableEq κ] in +lemma parameter_segment_value (H : ι→VectorFields n) (θ : κ→Spin n→ℝ) (x : Spin n) + (α : κ) {B : ℝ} (hx : |θ α x|≤B) (hf : ∀k,|θ α (flip x k)|≤B) + (i k : Fin n) (t : ℝ) (ht : t∈Set.Icc (0:ℝ) 1) : + |(localArgs H θ x i+t • (localArgs H θ (flip x k) i-localArgs H θ x i)) (.inr α)|≤B := by + change |θ α x+t*(θ α (flip x k)-θ α x)|≤B + have hx' := abs_le.mp hx + have hf' := abs_le.mp (hf k) + apply abs_le.mpr + constructor + · nlinarith [mul_nonneg ht.1 (sub_nonneg.mpr hf'.1), + mul_nonneg (sub_nonneg.mpr ht.2) (sub_nonneg.mpr hx'.1)] + · nlinarith [mul_nonneg ht.1 (sub_nonneg.mpr hf'.2), + mul_nonneg (sub_nonneg.mpr ht.2) (sub_nonneg.mpr hx'.2)] + +lemma initialKernel_regular (f : KernelExpr) (H : Unit→VectorFields n) + (θ : Bool→Spin n→ℝ) (x : Spin n) (r : Fin n→ℝ) (R : ℝ) + (hx : |θ false x|≤R) (hf : ∀k,|θ false (flip x k)|≤R) : + SegmentRegular H θ (fun i=>initialKernel f (r i)) + (fun i=>initialGradient f (r i)) x (f.dBudget R+f.ddBudget R) := by + convert fixed_root_kernel_regular f H θ x () false r R hx hf using 1 + · ext i u; simp [initialKernel,phiSelect_apply,eval3] + · rfl + +lemma initialKernel_segment_value (f : KernelExpr) (H : Unit→VectorFields n) + (θ : Bool→Spin n→ℝ) (x : Spin n) (r : Fin n→ℝ) (R : ℝ) + (hx : |θ false x|≤R) (hf : ∀k,|θ false (flip x k)|≤R) + (i k : Fin n) (t : ℝ) (ht : t∈Set.Icc (0:ℝ) 1) : + |initialKernel f (r i) (localArgs H θ x i+t • (localArgs H θ (flip x k) i-localArgs H θ x i))|≤ + f.mass*Real.exp (R/2) := by + change |eval3 f.eval (_, r i, _)| ≤ _ + apply f.absolute_bound + exact parameter_segment_value H θ x false hx hf i k t ht + +def initialRegularBudget (f : KernelExpr) (j R B : ℝ) : ℝ := + f.dBudget R+f.ddBudget R+(phiExpr.dBudget R+phiExpr.ddBudget R)+ + |j| *(B*(phiExpr.dBudget R+phiExpr.ddBudget R)+phiExpr.mass*Real.exp (R/2)+ + 2*(phiExpr.dBudget R+phiExpr.ddBudget R)) + +lemma literalInitial_regular (J : Interaction n) (j d : ℝ) (f : KernelExpr) + (z m : VectorFields n) (a c : Spin n→ℝ) (r e : Fin n→ℝ) (x : Spin n) + {R B : ℝ} (hB : 0≤B) (ha : |a x|≤R) (haf : ∀k,|a (flip x k)|≤R) + (hc : |d*c x|≤B) (hcf : ∀k,|d*c (flip x k)|≤B) : + let D:=literalInitial J j d f z m a c r e + (∀s,SegmentRegular D.H D.θ (D.seedFunction 1 s) (D.seedDerivative 1 s) x + (initialRegularBudget f j R B)) ∧ + SegmentRegular D.H D.θ (D.auxFunction 1 0) (D.auxDerivative 1 0) x + (initialRegularBudget f j R B) := by + let D:=literalInitial J j d f z m a c r e + have hp:=initialKernel_regular phiExpr D.H D.θ x r R ha haf + have hF:=initialKernel_regular f D.H D.θ x r R ha haf + have hT:=parameter_regular D.H D.θ x true + have hm:=hT.mul hp hB (mul_nonneg phiExpr.mass_nonneg (Real.exp_pos _).le) + (parameter_segment_value D.H D.θ x true hc hcf) + (initialKernel_segment_value phiExpr D.H D.θ x r R ha haf) + have hm':=hm.const_mul (-j) + simp only [abs_neg,mul_one] at hm' + have hphi : 0≤phiExpr.dBudget R+phiExpr.ddBudget R:=add_nonneg (phiExpr.dBudget_nonneg _) (phiExpr.ddBudget_nonneg _) + have hf0 : 0≤f.dBudget R+f.ddBudget R:=add_nonneg (f.dBudget_nonneg _) (f.ddBudget_nonneg _) + have he : 0≤|j| *(B*(phiExpr.dBudget R+phiExpr.ddBudget R)+phiExpr.mass*Real.exp (R/2)+ + 2*(phiExpr.dBudget R+phiExpr.ddBudget R)):=by positivity [phiExpr.mass_nonneg] + constructor + · intro s + cases s + · exact hF.mono (by dsimp [initialRegularBudget]; linarith) + · convert hm'.mono (show |j| *(B*(phiExpr.dBudget R+phiExpr.ddBudget R)+phiExpr.mass*Real.exp (R/2)+ + 2*(phiExpr.dBudget R+phiExpr.ddBudget R))≤ initialRegularBudget f j R B by + dsimp [initialRegularBudget]; linarith) using 1 + · ext i u + dsimp [D,literalInitial] + ring + · rfl + · exact hp.mono (by dsimp [initialRegularBudget]; linarith) +end SKGapCutoff.Recipe + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/LiteralSeriesLiftAppend.lean b/lean/OAI/Probability/SKGap/Localization/LiteralSeriesLiftAppend.lean new file mode 100644 index 0000000000000000000000000000000000000000..4f13e4e85d23e2883be74962c1b465c48eb6aae8 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/LiteralSeriesLiftAppend.lean @@ -0,0 +1,231 @@ +import Mathlib +import OAI.Probability.SKGap.Matrix.WordBaseBias +import OAI.Probability.SKGap.Terminal.ConsDiag +import OAI.Probability.SKGap.Matrix.InverseSeries + +namespace OAI + +section +noncomputable section +noncomputable section +open scoped BigOperators +noncomputable section +noncomputable section +noncomputable section +open scoped BigOperators +noncomputable section +open scoped BigOperators +noncomputable section +open scoped BigOperators +noncomputable section +open scoped BigOperators +noncomputable section +open scoped BigOperators +noncomputable section +open scoped BigOperators +noncomputable section +open scoped BigOperators +noncomputable section +open scoped BigOperators +noncomputable section +open scoped BigOperators +noncomputable section +open scoped BigOperators +noncomputable section +open scoped BigOperators +noncomputable section +open scoped BigOperators +namespace SKGap.Noncrossing +open Diagram InverseDiagram WordSeries PowerSeries +variable {ι : Type*} [Fintype ι] + +@[simp] lemma literalSeries_lift_append (j : ℝ) (a : ι→ℝ) (P Q : List (Letter (ι→ℝ))) (i : ι) : + literalSeries j a (liftWord P++liftWord Q) i=C (ordinary j (P++Q) i) := by + rw [← liftWord_append,literalSeries_lift] +@[simp] lemma literalSeries_two_prefix (j : ℝ) (a : ι→ℝ) + (P R Q : List (Letter (ι→ℝ))) (i : ι) : + literalSeries j a (liftWord P++(liftWord R++(.inverse::liftWord Q))) i= + inverseSeries j a (P++R) Q i := by + rw [← List.append_assoc,← liftWord_append,literalSeries_oneInverse] +@[simp] lemma literalSeries_two_suffix (j : ℝ) (a : ι→ℝ) + (P Q R : List (Letter (ι→ℝ))) (i : ι) : + literalSeries j a ((liftWord P++(.inverse::liftWord Q))++liftWord R) i= + inverseSeries j a P (Q++R) i := by + rw [List.append_assoc,List.cons_append,← liftWord_append,literalSeries_oneInverse] +@[simp] lemma literalSeries_cons_inverse (j : ℝ) (a : ι→ℝ) + (Q : List (Letter (ι→ℝ))) (i : ι) : + literalSeries j a (.inverse::liftWord Q) i=inverseSeries j a [] Q i := by + exact literalSeries_oneInverse j a [] Q i + +@[simp] lemma literalSeries_lift_fun (j : ℝ) (a : ι→ℝ) (F : List (Letter (ι→ℝ))) : + literalSeries j a (liftWord F)=(fun i=>C (ordinary j F i)) := by + funext i; exact literalSeries_lift j a F i +@[simp] lemma literalSeries_oneInverse_fun (j : ℝ) (a : ι→ℝ) + (P Q : List (Letter (ι→ℝ))) : + literalSeries j a (liftWord P++(.inverse::liftWord Q))=inverseSeries j a P Q := by + funext i; exact literalSeries_oneInverse j a P Q i +@[simp] lemma literalSeries_inverse_diag_fun (j : ℝ) (a : ι→ℝ) + (P : List (Letter (ι→ℝ))) : + literalSeries j a (liftWord P++[.inverse,.diag a])=inverseSeries j a P [.diag a] := by + exact literalSeries_oneInverse_fun j a P [.diag a] +@[simp] lemma literalSeries_inverse_single_append (j : ℝ) (a : ι→ℝ) + (P Q : List (Letter (ι→ℝ))) : + literalSeries j a (liftWord P++([.inverse]++liftWord Q))=inverseSeries j a P Q := by + exact literalSeries_oneInverse_fun j a P Q +@[simp] lemma literalSeries_cons_inverse_fun (j : ℝ) (a : ι→ℝ) + (Q : List (Letter (ι→ℝ))) : + literalSeries j a (.inverse::liftWord Q)=inverseSeries j a [] Q := by + exact literalSeries_oneInverse_fun j a [] Q + +@[simp] lemma literalSeries_inverse_diag_suffix (j : ℝ) (a : ι→ℝ) + (P Q : List (Letter (ι→ℝ))) : + literalSeries j a ((liftWord P++[.inverse,.diag a])++liftWord Q)= + inverseSeries j a P (.diag a::Q) := by + rw [List.append_assoc] + exact literalSeries_oneInverse_fun j a P (.diag a::Q) + +lemma literalSeries_at_noInverse (j : ℝ) (a : ι→ℝ) + (P Q : List (Letter (ι→ℝ))) (i : ι) : + literalSeries j a (liftWord P++(.noise::liftWord Q)) i= + ((wordRecursionAt a (liftWord P) (liftWord Q)).map (fun t=> + (if t.inversePartner then X else 1)*C j*meanSeries (literalSeries j a t.inner)* + literalSeries j a t.outer i)).sum := by + rw [show liftWord P++(.noise::liftWord Q)=liftWord (P++(.noise::Q)) by + simp [liftWord,Letter.toWord]] + simp only [wordRecursionAt,List.map_append,List.sum_append,List.map_map, + WordCut.asLeft,WordCut.asRight,Function.comp_def] + rw [sum_wordPartners_lift,sum_wordPartners_lift] + simp only [Bool.false_eq_true,↓reduceIte,one_mul,literalSeries_lift,literalSeries_lift_append, + literalSeries_lift_fun,meanSeries_C] + have hh := congrArg C (expect_at j (id : (ι→ℝ)→ι→ℝ) P Q i) + simpa only [map_add,map_sum,map_mul,ordinary,mul_assoc] using hh + +lemma literalSeries_at_rightInverse (j : ℝ) (a : ι→ℝ) + (P R T : List (Letter (ι→ℝ))) (i : ι) : + literalSeries j a (liftWord P++(.noise::(liftWord R++(.inverse::liftWord T)))) i= + ((wordRecursionAt a (liftWord P) (liftWord R++(.inverse::liftWord T))).map (fun t=> + (if t.inversePartner then X else 1)*C j*meanSeries (literalSeries j a t.inner)* + literalSeries j a t.outer i)).sum := by + rw [show liftWord P++(.noise::(liftWord R++(.inverse::liftWord T)))= + liftWord (P++(.noise::R))++(.inverse::liftWord T) by + simp [liftWord,Letter.toWord,List.append_assoc]] + simp only [wordRecursionAt,List.map_append,List.sum_append,List.map_map, + WordCut.asLeft,WordCut.asRight,Function.comp_def] + rw [sum_wordPartners_lift,sum_wordPartners_oneInverse] + simp only [Bool.false_eq_true,↓reduceIte,one_mul,literalSeries_lift_append, + literalSeries_oneInverse,literalSeries_two_prefix,literalSeries_oneInverse_fun, + literalSeries_inverse_diag_fun,literalSeries_inverse_single_append,literalSeries_lift_fun,meanSeries_C] + simpa only [map_mul,mul_assoc,add_assoc] using inverseSeries_right j a P R T i + +lemma literalSeries_at_leftInverse (j : ℝ) (a : ι→ℝ) + (P R T : List (Letter (ι→ℝ))) (i : ι) : + literalSeries j a ((liftWord P++(.inverse::liftWord R))++(.noise::liftWord T)) i= + ((wordRecursionAt a (liftWord P++(.inverse::liftWord R)) (liftWord T)).map (fun t=> + (if t.inversePartner then X else 1)*C j*meanSeries (literalSeries j a t.inner)* + literalSeries j a t.outer i)).sum := by + rw [show (liftWord P++(.inverse::liftWord R))++(.noise::liftWord T)= + liftWord P++(.inverse::liftWord (R++(.noise::T))) by + simp [liftWord,Letter.toWord,List.append_assoc]] + simp only [wordRecursionAt,List.map_append,List.sum_append,List.map_map, + WordCut.asLeft,WordCut.asRight,Function.comp_def] + rw [sum_wordPartners_oneInverse,sum_wordPartners_lift] + simp only [Bool.false_eq_true,↓reduceIte,one_mul,literalSeries_lift_append, + literalSeries_oneInverse,literalSeries_two_suffix,literalSeries_oneInverse_fun, + literalSeries_inverse_diag_suffix,List.singleton_append,literalSeries_cons_inverse_fun, + literalSeries_lift_fun,meanSeries_C] + have hh := inverseSeries_left j a P R T i + simp only [map_mul,mul_assoc,add_assoc] at hh ⊢ + exact hh + +lemma literalSeries_at (j : ℝ) (a : ι→ℝ) (P Q : List (WordLetter ι)) + (hI : inverseCount (P++(.noise::Q))≤1) (i : ι) : + literalSeries j a (P++(.noise::Q)) i= + ((wordRecursionAt a P Q).map (fun t=> + (if t.inversePartner then X else 1)*C j*meanSeries (literalSeries j a t.inner)* + literalSeries j a t.outer i)).sum := by + have hP : inverseCount P≤1 := by simp only [inverseCount_append,inverseCount_noise] at hI; omega + have hQ : inverseCount Q≤1 := by simp only [inverseCount_append,inverseCount_noise] at hI; omega + rcases one_inverse_cases P hP with ⟨P,rfl⟩ | ⟨P,R,rfl⟩ + · rcases one_inverse_cases Q hQ with ⟨Q,rfl⟩ | ⟨R,T,rfl⟩ + · exact literalSeries_at_noInverse j a P Q i + · exact literalSeries_at_rightInverse j a P R T i + · have hQ0 : inverseCount Q=0 := by + simp only [inverseCount_append,inverseCount_inverse,inverseCount_noise,inverseCount_lift] at hI + omega + obtain ⟨T,rfl⟩ := exists_lift_of_no_inverse Q hQ0 + exact literalSeries_at_leftInverse j a P R T i + +end SKGap.Noncrossing + +noncomputable section +open scoped BigOperators +namespace SKGap.Noncrossing +open Diagram InverseDiagram WordSeries PowerSeries +variable {ι : Type*} [Fintype ι] + +omit [Fintype ι] in +lemma exists_diagonals_of_count_zero (F : List (Letter (ι→ℝ))) + (h : ordinaryCount (liftWord F)=0) : ∃ D : List (ι→ℝ), D.map Letter.diag=F := by + induction F with + | nil => exact ⟨[],rfl⟩ + | cons l F ih => + cases l with + | noise => simp [liftWord,Letter.toWord,ordinaryCount] at h + | diag d => + have ht : ordinaryCount (liftWord F)=0 := by simpa [liftWord,Letter.toWord,ordinaryCount] using h + obtain ⟨D,rfl⟩ := ih ht + exact ⟨d::D,rfl⟩ + +omit [Fintype ι] in +@[simp] lemma wordDiagonal_diags (D : List (ι→ℝ)) (i : ι) : + wordDiagonal (liftWord (D.map Letter.diag)) i=(D.map (fun d=>d i)).prod := by + simp [wordDiagonal,liftWord,Function.comp_def,Letter.toWord] +omit [Fintype ι] in +@[simp] lemma wordDiagonal_append (P Q : List (WordLetter ι)) (i : ι) : + wordDiagonal (P++Q) i=wordDiagonal P i*wordDiagonal Q i := by simp [wordDiagonal] +omit [Fintype ι] in +@[simp] lemma wordDiagonal_inverse (Q : List (WordLetter ι)) (i : ι) : + wordDiagonal (.inverse::Q) i=wordDiagonal Q i := by simp [wordDiagonal] + +lemma literalSeries_base (j : ℝ) (a : ι→ℝ) (F : List (WordLetter ι)) + (hI : inverseCount F≤1) (ho : ordinaryCount F=0) (i : ι) : + literalSeries j a F i=C (wordDiagonal F i) := by + rcases one_inverse_cases F hI with ⟨P,rfl⟩ | ⟨P,Q,rfl⟩ + · obtain ⟨D,rfl⟩ := exists_diagonals_of_count_zero P ho + rw [literalSeries_lift,wordDiagonal_diags] + congr 1 + simpa using ordinary_diag_prefix j D [] i + · have hc : ordinaryCount (liftWord P)+ordinaryCount (liftWord Q)=0 := by + simpa [ordinaryCount,List.countP_append] using ho + obtain ⟨D,rfl⟩ := exists_diagonals_of_count_zero P (by omega) + obtain ⟨E,rfl⟩ := exists_diagonals_of_count_zero Q (by omega) + rw [literalSeries_oneInverse,wordDiagonal_append,wordDiagonal_inverse,wordDiagonal_diags,wordDiagonal_diags] + ext n + rw [coeff_inverseSeries,inverseCoefficient_diagonal,coeff_C] + +end SKGap.Noncrossing + +noncomputable section +open scoped BigOperators + +end +end +end +end +end +end +end +end +end +end +end +end +end +end +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/LiteralSystemBridge.lean b/lean/OAI/Probability/SKGap/Localization/LiteralSystemBridge.lean new file mode 100644 index 0000000000000000000000000000000000000000..60869668e02738d85e095bf648748f810d7bfd17 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/LiteralSystemBridge.lean @@ -0,0 +1,86 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.LiteralInitialSystem + +namespace OAI + +section + +noncomputable section +open scoped BigOperators +namespace SKGapCutoff.Recipe +open SKGap.Stein Primary SKGap.ImplicitSystem Matrix +variable {n : ℕ} + +def LiteralEquations (J : Interaction n) (j : ℝ) (f : KernelExpr) + (z m w y : VectorFields n) (a c : Spin n→ℝ) (r e : Fin n→ℝ) (x : Spin n) : Prop := + Equations j (siteMean (fun v i=>phi (z v i) (r i) (a v)) x) (n:ℝ)⁻¹ + (siteMean (initialP f z a r e) x) (phiDiagonal (z x) r (a x)) + (toEuclideanCLM (𝕜:=ℝ) J) (WithLp.toLp 2 (initialU f z a r e x)) + (WithLp.toLp 2 (m x)) (WithLp.toLp 2 (fun i=>Real.tanh (r i))) + (WithLp.toLp 2 (fun i=>logSlope (z x i) (r i) (a x))) + (WithLp.toLp 2 (w x)) (WithLp.toLp 2 (y x)) (c x) + +lemma phiDiagonal_apply (z r : Fin n→ℝ) (a : ℝ) (v : Euclid n) (i : Fin n) : + phiDiagonal z r a v i=phi (z i) (r i) a*v i := by + change (toEuclideanCLM (𝕜:=ℝ) (diagonal (fun k=>phi (z k) (r k) a)) (WithLp.toLp 2 v.ofLp)) i=_ + simp only [toEuclideanCLM_toLp,WithLp.ofLp_toLp,mulVec_diagonal] + +lemma literal_first_equation (J : Interaction n) (j d : ℝ) (f : KernelExpr) + (z m w y : VectorFields n) (a c : Spin n→ℝ) (r e : Fin n→ℝ) (hd : d≠0) (x : Spin n) : + ((WithLp.toLp 2 (w x) : Euclid n)=phiDiagonal (z x) r (a x) + (WithLp.toLp 2 (initialU f z a r e x)+WithLp.toLp 2 (y x)- + (j*c x) • WithLp.toLp 2 (fun i=>Real.tanh (r i)))) ↔ + w x=(literalInitial J j d f z m a c r e).sourceOf 1 (fun _=>y) x := by + have he : (phiDiagonal (z x) r (a x) + (WithLp.toLp 2 (initialU f z a r e x)+WithLp.toLp 2 (y x)- + (j*c x) • WithLp.toLp 2 (fun i=>Real.tanh (r i)))).ofLp= + (literalInitial J j d f z m a c r e).sourceOf 1 (fun _=>y) x := by + ext i + rw [literalInitial_source _ _ _ _ _ _ _ _ _ _ _ hd] + change phiDiagonal _ _ _ _ i=_ + rw [phiDiagonal_apply] + change phi (z x i) (r i) (a x)* + (f.eval (z x i) (r i) (a x)/phi (z x i) (r i) (a x)*e i+y x i-j*c x*Real.tanh (r i))=_ + field_simp [(phi_pos (z x i) (r i) (a x)).ne'] + ring + constructor + · intro h; exact (congrArg WithLp.ofLp h).trans he + · intro h; exact WithLp.ofLp_injective 2 (h.trans he.symm) + +lemma literalEquations_recipe (J : Interaction n) (j d : ℝ) (f : KernelExpr) + (z m w y : VectorFields n) (a c : Spin n→ℝ) (r e : Fin n→ℝ) (hd : d≠0) (x : Spin n) : + LiteralEquations J j f z m w y a c r e x ↔ + w x=(literalInitial J j d f z m a c r e).sourceOf 1 (fun _=>y) x ∧ + y x=(literalInitial J j d f z m a c r e).fieldOf 1 (fun _=>w) (fun _=>y) x ∧ + c x=siteMean ((literalInitial J j d f z m a c r e).implicitPartial y) x := by + have hc (hw : w x=(literalInitial J j d f z m a c r e).sourceOf 1 (fun _=>y) x) : + c x=(n:ℝ)⁻¹*inner ℝ (WithLp.toLp 2 (fun i=>logSlope (z x i) (r i) (a x)) : Euclid n) + (WithLp.toLp 2 (w x))+siteMean (initialP f z a r e) x ↔ + c x=siteMean ((literalInitial J j d f z m a c r e).implicitPartial y) x := by + rw [initial_scalar_equation] + change c x=(∑i,(logSlope (z x i) (r i) (a x)*w x i+initialP f z a r e x i))/(n:ℝ) ↔ _ + rw [siteMean,literalInitial_partial_source _ _ _ _ _ _ _ _ _ _ _ _ hd x hw] + have hy (hw : w x=(literalInitial J j d f z m a c r e).sourceOf 1 (fun _=>y) x) + (hc : c x=siteMean ((literalInitial J j d f z m a c r e).implicitPartial y) x) : + (WithLp.toLp 2 (y x) : Euclid n)=toEuclideanCLM (𝕜:=ℝ) J (WithLp.toLp 2 (w x))- + (j*siteMean (fun v i=>phi (z v i) (r i) (a v)) x) • WithLp.toLp 2 (w x)- + (j*c x) • WithLp.toLp 2 (m x) ↔ + y x=(literalInitial J j d f z m a c r e).fieldOf 1 (fun _=>w) (fun _=>y) x := by + rw [literalInitial_field _ _ _ _ _ _ _ _ _ _ _ _ x hw hc] + constructor + · intro h; exact congrArg WithLp.ofLp h + · intro h; exact WithLp.ofLp_injective 2 h + constructor + · intro h + have hw:=(literal_first_equation J j d f z m w y a c r e hd x).mp h.1 + have hs:=(hc hw).mp h.2.2 + exact ⟨hw,(hy hw hs).mp h.2.1,hs⟩ + · rintro ⟨hw,hy',hc'⟩ + exact ⟨(literal_first_equation J j d f z m w y a c r e hd x).mpr hw, + (hy hw hc').mpr hy',(hc hw).mpr hc'⟩ +end SKGapCutoff.Recipe + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/LiteralValues.lean b/lean/OAI/Probability/SKGap/Localization/LiteralValues.lean new file mode 100644 index 0000000000000000000000000000000000000000..83f919ac44360710729054cc125a552a449e4f7c --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/LiteralValues.lean @@ -0,0 +1,154 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.SusceptibilityTest +import OAI.Probability.SKGap.Localization.LiteralWeak + +namespace OAI + +section + +noncomputable section +open scoped BigOperators +namespace SKGapCutoff.Recipe +open Primary SKGap.Stein +variable {n : ℕ} + +lemma literal_source_phi (j : ℝ) (J : Interaction n) (h r e : Fin n→ℝ) + (k : ℕ) (x : Spin n) : + literalSourceBracket j J h r e k (KernelExpr.atom 0 0 false) x= + ∑i,(Real.tanh (fld j J h (k+1) x i)-Real.tanh (r i))*e i := by + simp only [literalSourceBracket,←phiZ_kernel,KernelExpr.eval,moment_base] + have hh:=implicit_phi_source (fld j J h (k+1) x) r + (j*(1-onsager j J h (k+1) x-SKGap.overlap r)) e + simpa only [mul_assoc] using hh + +lemma literal_source_phiR (hn : 01/Real.sqrt (n:ℝ)) k + (KernelExpr.dr (KernelExpr.atom 0 0 false)) x = + literalSusceptibility (fld j J h (k+1)) + (fun v=>j*(1-onsager j J h (k+1) v-SKGap.overlap r)) r x := by + have hh:=implicit_phiR_source (fld j J h (k+1) x) r + (j*(1-onsager j J h (k+1) x-SKGap.overlap r)) + have hh' : literalSourceBracket j J h r (fun _=>1/Real.sqrt (n:ℝ)) k + (KernelExpr.dr (KernelExpr.atom 0 0 false)) x= + (∑i,(phi (fld j J h (k+1) x i) (r i) + (j*(1-onsager j J h (k+1) x-SKGap.overlap r))-SKGapCutoff.scalarVariance (r i)))/Real.sqrt (n:ℝ) := by + convert hh using 1 + apply Finset.sum_congr rfl + intro i _ + dsimp only [literalSourceBracket,phiR,phiRZ] + ring + rw [hh'] + have hn0 : (n:ℝ)≠0:=ne_of_gt (Nat.cast_pos.mpr hn) + have hs0 : Real.sqrt (n:ℝ)≠0:=ne_of_gt (Real.sqrt_pos.mpr (Nat.cast_pos.mpr hn)) + have hs : (Real.sqrt (n:ℝ))^2=(n:ℝ):=Real.sq_sqrt (Nat.cast_nonneg _) + simp only [literalSusceptibility,siteMean,SKGap.overlap,SKGap.magnetization, + SKGapCutoff.scalarVariance,Finset.sum_sub_distrib,Finset.sum_const,Finset.card_univ, + Fintype.card_fin,nsmul_eq_mul,mul_one] + field_simp + rw [hs] + ring + +end SKGapCutoff.Recipe + +end +end + +section + +noncomputable section +open scoped BigOperators Matrix.Norms.Frobenius +namespace SKGapCutoff.Recipe +open SKGap.Stein Primary Static +universe u + +theorem buffered_root_susceptibility_bound {j K B Aroot ε c r₀ R ρ : ℝ} + (hj : 0≤j) (hK : 0≤K) (hB : 0≤B) (hA : 1≤Aroot) (hc : 0j*(1-onsager j (J b) (h b) (k+1) v-SKGap.overlap (r b))) (r b) x)^2≤D := by + let f:=KernelExpr.dr (KernelExpr.atom 0 0 false) + let η:=(1+2*j)*(1+(1+(K+3*j)/c)*(K+4*j))*(2*ρ) + have hη : 0≤η:=by dsimp [η];positivity + obtain ⟨A,hA',hh⟩:=buffered_root_source_weak hj hK hB hA hc hr₀ hρ hε + hAR hbuffer hR hsmall himplicit k f + refine ⟨A,hA',?_⟩ + intro W C hW hC Ω n J h P hn hJ hevent hbad hdim hP hp hm + let e:=fun b=>fun _ : Fin (n b)=>1/Real.sqrt (n b:ℝ) + have he : ∀b,vectorNorm (e b)≤1 := by + intro b + dsimp [e] + rw [vectorNorm_const,abs_of_nonneg (by positivity)] + have hs : Real.sqrt (n b:ℝ)≠0:=ne_of_gt (Real.sqrt_pos.mpr (Nat.cast_pos.mpr (hn b))) + exact le_of_eq (by field_simp) + obtain ⟨r,hr,w,y,c₀,heq,hweak⟩:=hh W C hW hC Ω n J h e P hn hJ he hevent hbad hdim hP hp hm + let E:=fun b=>{x | residualCutoff ρ j (J b) (h b) k x≠0} + let L:=fun b=>literalSusceptibility (fld j (J b) (h b) (k+1)) + (fun v=>j*(1-onsager j (J b) (h b) (k+1) v-SKGap.overlap (r b))) (r b) + let M:=fun b=>literalMiddle j (J b) (h b) (r b) k (w b) + have hstable : ∀b x,x∈E b→ + LiteralStableAt (J b) j (fld j (J b) (h b) (k+1)) (mag j (J b) (h b) (k+1)) + (fun v=>j*(1-onsager j (J b) (h b) (k+1) v-SKGap.overlap (r b))) (r b) R η c x := by + intro b x hx + have hact (v : Fin (n b)→ℝ) : vectorNorm ((J b).mulVec v)≤K*vectorNorm v := + (vectorNorm_matrix_mul _ v).trans (mul_le_mul_of_nonneg_right (hevent b).1 (vectorNorm_nonneg v)) + obtain ⟨r',hr',hu',hs⟩:=stable_primary_buffer (hn b) hj hK hA hc hr₀ + (mul_nonneg (by norm_num) hρ.le) hε hAR hbuffer hR hsmall (J b) (hJ b) (h b) hact (hbad b) + have heqroot : r'=r b:=(hr b).2 r' hr' + rw [heqroot] at hs + obtain ⟨h0,h1⟩:=residualCutoff_support (hn b) hρ (J b) (h b) k x hx + have hρ2 : ρ*Real.sqrt (n b:ℝ)≤(2*ρ)*Real.sqrt (n b:ℝ) := by nlinarith [mul_nonneg hρ.le (Real.sqrt_nonneg (n b:ℝ))] + exact hs k x (h0.trans hρ2) (h1.trans hρ2) + have hmiddle : ∀b x,x∈E b→|M b x|≤|L b x|/2 := by + intro b x hx + have H:=literal_middle_error (J b) j f (fld j (J b) (h b) (k+1)) + (mag j (J b) (h b) (k+1)) (w b) (y b) + (fun v=>j*(1-onsager j (J b) (h b) (k+1) v-SKGap.overlap (r b))) (c₀ b) (r b) (e b) x + (hn b) hc hη himplicit (hevent b).1 (he b) (hstable b x hx) (heq b x hx) + change |M b x|≤(|j| *|literalSizeBudget j c R K f|)*η*|L b x| at H + have H':=(mul_le_mul_of_nonneg_right habsorb (abs_nonneg (L b x))) + exact H.trans (H'.trans_eq (by ring)) + have hweakL : LocalUniformWeak E P (fun b x=>L b x+M b x) := by + apply hweak.congr + intro b x + rw [literal_source_phiR (hn b)] + obtain ⟨D,hD,hstar⟩:=literalSusceptibility_cutoff_test j K B ρ hK hB hρ k + obtain ⟨Q,hQ,hQbound⟩:=hweakL + refine ⟨r,hr,4*Q^2+D,by positivity,?_⟩ + intro b + apply tested_susceptibility_absorption (P b) (residualCutoff ρ j (J b) (h b) k) (L b) (M b) + (hP b) hQ hD (hmiddle b) + · apply hQbound b + intro x hx + have hc0 : residualCutoff ρ j (J b) (h b) k x=0 := by simpa only [E,Set.mem_ofPred_eq,not_not] using hx + simp [hc0] + · exact hstar (n b) (hn b) (J b) (h b) (r b) (P b) (hP b) (hp b) + (hevent b).1 (fun x l hl=>(hevent b).2.1 (h b) x l hl) + +end SKGapCutoff.Recipe + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/LiteralWeak.lean b/lean/OAI/Probability/SKGap/Localization/LiteralWeak.lean new file mode 100644 index 0000000000000000000000000000000000000000..8ca87fb156b8297edb89b3d4f8776542b408771f --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/LiteralWeak.lean @@ -0,0 +1,146 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.BufferedComparisonBound + +namespace OAI + +section + +noncomputable section +open scoped BigOperators +namespace SKGapCutoff.Recipe +open Primary Static SKGap.Stein +universe u +variable {n : ℕ} + +def literalSourceBracket (j : ℝ) (J : Interaction n) (h r e : Fin n→ℝ) + (k : ℕ) (f : KernelExpr) : Observables n := fun x=> + ∑i,((fld j J h (k+1) x i-r i-j*(1-onsager j J h (k+1) x-SKGap.overlap r)* + Real.tanh (fld j J h (k+1) x i))*f.eval (fld j J h (k+1) x i) (r i) + (j*(1-onsager j J h (k+1) x-SKGap.overlap r))*e i- + j*(1-onsager j J h (k+1) x-SKGap.overlap r)*f.dz.eval (fld j J h (k+1) x i) (r i) + (j*(1-onsager j J h (k+1) x-SKGap.overlap r))*e i) + +def literalMiddle (j : ℝ) (J : Interaction n) (h r : Fin n→ℝ) + (k : ℕ) (w : VectorFields n) : Observables n := fun x=> + j*(1-SKGap.overlap r-siteMean (fun v i=>phi (fld j J h (k+1) v i) (r i) + (j*(1-onsager j J h (k+1) v-SKGap.overlap r))) x)* + (∑i,(Real.tanh (fld j J h (k+1) x i)-Real.tanh (r i))*w x i) + +variable {Ω : Type u} {N : Ω→ℕ} +theorem literal_source_middle_weak (j : ℝ) (J : ∀b,Interaction (N b)) + (h r e : ∀b,Fin (N b)→ℝ) (k : ℕ) (f : KernelExpr) + (w y : ∀b,VectorFields (N b)) (c : ∀b,Observables (N b)) + (E : ∀b,Set (Spin (N b))) (P : ∀b,Observables (N b)) + (hn : ∀b,0j*(1-onsager j (J b) (h b) (k+1) v-SKGap.overlap (r b))) (c b) (r b) (e b) x) + (hT : LocalUniformWeak E P (fun b=>literalTerminal j (J b) (h b) k (w b) (c b))) + (hR : LocalUniformWeak E P (fun b x=>j*c b x*(∑i,residual j (J b) (h b) (k+1) x i* + (Real.tanh (fld j (J b) (h b) (k+1) x i)-Real.tanh (r b i))))) : + LocalUniformWeak E P (fun b x=>literalSourceBracket j (J b) (h b) (r b) (e b) k f x+ + literalMiddle j (J b) (h b) (r b) k (w b) x) := by + apply (hT.add hR).congr_on + intro b x hx + rw [literal_comparison_identity (hn b) j (J b) (hJ b) (h b) (r b) (e b) k f + (w b) (y b) (c b) x (hroot b) (heq b x hx)] + dsimp only [literalSourceBracket,literalMiddle] + ring + +end SKGapCutoff.Recipe + +end +end + +section + +noncomputable section +open scoped BigOperators Matrix.Norms.Frobenius +namespace SKGapCutoff.Recipe +open SKGap.Stein Primary Static +universe u + +theorem buffered_root_source_weak {j K B Aroot ε c r₀ R ρ : ℝ} + (hj : 0≤j) (hK : 0≤K) (hB : 0≤B) (hA : 1≤Aroot) (hc : 0j*(1-onsager j (J b) (h b) (k+1) v-SKGap.overlap (r b))) + (c₀ b) (r b) (e b) x) ∧ + LocalUniformWeak (fun b=>{x | residualCutoff ρ j (J b) (h b) k x≠0}) P + (fun b x=>literalSourceBracket j (J b) (h b) (r b) (e b) k f x+ + literalMiddle j (J b) (h b) (r b) k (w b) x) := by + obtain ⟨A,hA',hh⟩:=buffered_root_comparison_weak hj hK hB hA hc hr₀ hρ hε + hAR hbuffer hR hsmall himplicit k f + refine ⟨A,hA',?_⟩ + intro W C hW hC Ω n J h e P hn hJ he hevent hbad hdim hP hp hm + obtain ⟨r,hr,w,y,c₀,heq,hT,hrem⟩:=hh W C hW hC Ω n J h e P hn hJ he hevent hbad hdim hP hp hm + exact ⟨r,hr,w,y,c₀,heq,literal_source_middle_weak j J h r e k f w y c₀ _ P hn hJ + (fun b=>(hr b).1) heq hT hrem⟩ + +end SKGapCutoff.Recipe + +end +end + +section + +noncomputable section +open scoped BigOperators +namespace SKGapCutoff.Static +open Primary Recipe +variable {n : ℕ} + +lemma tested_susceptibility_absorption (P C L M : Observables n) + (hP : ∀x,0≤P x) {K D : ℝ} (hK : 0≤K) (hD : 0≤D) + (hM : ∀x,C x≠0→|M x|≤|L x|/2) + (hweak : |∑x,P x*((C x)^2*L x)*(L x+M x)|≤K*starNorm P (fun x=>(C x)^2*L x)) + (hstar : starSquared P (fun x=>(C x)^2*L x)≤(∑x,P x*(C x*L x)^2)+D) : + (∑x,P x*(C x*L x)^2)≤4*K^2+D := by + let S:=∑x,P x*(C x*L x)^2 + have hS : 0≤S := Finset.sum_nonneg fun x _=>mul_nonneg (hP x) (sq_nonneg _) + have hsum : S/2≤∑x,P x*((C x)^2*L x)*(L x+M x) := by + rw [show S/2=∑x,P x*(C x*L x)^2/2 by simp only [S,Finset.sum_div]] + apply Finset.sum_le_sum + intro x _ + by_cases hx:C x=0 + · simp [hx] + have habs : |L x*M x|≤(L x)^2/2 := by + rw [abs_mul] + have H:=mul_le_mul_of_nonneg_left (hM x hx) (abs_nonneg (L x)) + simpa only [←mul_div_assoc,←sq,sq_abs] using H + have hh := (neg_abs_le (L x*M x)).trans' (neg_le_neg habs) + have hh' := mul_le_mul_of_nonneg_left hh (mul_nonneg (hP x) (sq_nonneg (C x))) + nlinarith only [hh'] + have htest : S/2≤K*Real.sqrt (S+D) := + (hsum.trans (le_abs_self _)).trans (hweak.trans + (mul_le_mul_of_nonneg_left (Real.sqrt_le_sqrt hstar) hK)) + have hsqrt : (Real.sqrt (S+D))^2=S+D := Real.sq_sqrt (add_nonneg hS hD) + have H:=sq_nonneg (Real.sqrt (S+D)-2*K) + change S≤4*K^2+D + nlinarith only [htest,H,hsqrt] + +end SKGapCutoff.Static + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/LocalCoefficient.lean b/lean/OAI/Probability/SKGap/Localization/LocalCoefficient.lean new file mode 100644 index 0000000000000000000000000000000000000000..2adca113c1596d59953d5192ab268a1e7473e5b9 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/LocalCoefficient.lean @@ -0,0 +1,121 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.CoefficientFlip +import OAI.Probability.SKGap.Matrix.DiscreteMatrixCalculus + +namespace OAI + +section + +noncomputable section +open scoped BigOperators +namespace SKGapCutoff.Recipe +open Primary +variable {n : ℕ} {ι κ : Type*} [Fintype ι] [DecidableEq ι] [Fintype κ] [DecidableEq κ] + +abbrev Args := ι⊕κ→ℝ + +def localArgs (H : ι→VectorFields n) (θ : κ→Spin n→ℝ) (x : Spin n) (i : Fin n) : Args (ι:=ι) (κ:=κ) := + Sum.elim (fun l=>H l x i) (fun α=>θ α x) + +def partialAt (T : Args (ι:=ι) (κ:=κ)→L[ℝ]ℝ) (l : ι⊕κ) : ℝ := T (Pi.single l 1) + +lemma linear_apply_coordinates {α : Type*} [Fintype α] [DecidableEq α] + (T : (α→ℝ)→L[ℝ]ℝ) (v : α→ℝ) : T v=∑l,v l*T (Pi.single l 1) := by + have he : v=∑l,v l • Pi.single l (1:ℝ) := by + funext i + simp [Finset.sum_apply,Pi.single_apply] + conv_lhs => rw [he] + simp only [map_sum,map_smul,smul_eq_mul] + +lemma flipHalfDiff_coordinate {α : Type*} [Fintype α] (P : Spin n→α→ℝ) + (k : Fin n) (x : Spin n) (l : α) : + flipHalfDiff k P x l=halfDiff k (fun y=>P y l) x := by + rw [halfDiff_as_flip] + dsimp only [flipHalfDiff,Pi.smul_apply,Pi.sub_apply,smul_eq_mul] + ring + +lemma coefficient_chain (H : ι→VectorFields n) (θ : κ→Spin n→ℝ) (x : Spin n) (i k : Fin n) + (T : Args (ι:=ι) (κ:=κ)→L[ℝ]ℝ) : + T (flipHalfDiff k (fun y=>localArgs H θ y i) x)= + (∑l,partialAt T (.inl l)*derivativeMatrix (H l) x i k)+ + ∑α,partialAt T (.inr α)*halfDiff k (θ α) x := by + rw [linear_apply_coordinates,Fintype.sum_sum_type] + simp only [flipHalfDiff_coordinate,partialAt,localArgs,Sum.elim_inl,Sum.elim_inr,derivativeMatrix,mul_comm] + +omit [DecidableEq ι] [DecidableEq κ] in +lemma local_argument_bound (H : ι→VectorFields n) (θ : κ→Spin n→ℝ) (x : Spin n) (i k : Fin n) : + ‖flipHalfDiff k (fun y=>localArgs H θ y i) x‖ ≤ + (∑l,|derivativeMatrix (H l) x i k|)+(∑α,|halfDiff k (θ α) x|) := by + apply (pi_norm_le_iff_of_nonneg (add_nonneg + (Finset.sum_nonneg fun l _=>abs_nonneg _) (Finset.sum_nonneg fun α _=>abs_nonneg _))).mpr + intro l + rw [Real.norm_eq_abs,flipHalfDiff_coordinate] + cases l with + | inl l => + dsimp only [localArgs,Sum.elim_inl] + exact (Finset.single_le_sum (fun l _=>abs_nonneg (derivativeMatrix (H l) x i k)) (Finset.mem_univ l)).trans + (le_add_of_nonneg_right (Finset.sum_nonneg fun α _=>abs_nonneg _)) + | inr α => + dsimp only [localArgs,Sum.elim_inr] + exact (Finset.single_le_sum (fun α _=>abs_nonneg (halfDiff k (θ α) x)) (Finset.mem_univ α)).trans + (le_add_of_nonneg_left (Finset.sum_nonneg fun l _=>abs_nonneg _)) + +def coefficient (H : ι→VectorFields n) (θ : κ→Spin n→ℝ) + (F : Fin n→Args (ι:=ι) (κ:=κ)→ℝ) : VectorFields n := + fun x i=>F i (localArgs H θ x i) + +def localPartial (H : ι→VectorFields n) (θ : κ→Spin n→ℝ) + (F' : Fin n→Args (ι:=ι) (κ:=κ)→Args (ι:=ι) (κ:=κ)→L[ℝ]ℝ) + (l : ι⊕κ) : VectorFields n := fun x i=>partialAt (F' i (localArgs H θ x i)) l + +def taylorError (H : ι→VectorFields n) (θ : κ→Spin n→ℝ) + (F : Fin n→Args (ι:=ι) (κ:=κ)→ℝ) + (F' : Fin n→Args (ι:=ι) (κ:=κ)→Args (ι:=ι) (κ:=κ)→L[ℝ]ℝ) + (x : Spin n) (i k : Fin n) : ℝ := + derivativeMatrix (coefficient H θ F) x i k- + F' i (localArgs H θ x i) (flipHalfDiff k (fun y=>localArgs H θ y i) x) + +lemma source_derivative_exact (H : ι→VectorFields n) (θ : κ→Spin n→ℝ) + (F : Fin n→Args (ι:=ι) (κ:=κ)→ℝ) + (F' : Fin n→Args (ι:=ι) (κ:=κ)→Args (ι:=ι) (κ:=κ)→L[ℝ]ℝ) + (s : VectorFields n) (x : Spin n) (i k : Fin n) : + derivativeMatrix (fun x i=>coefficient H θ F x i*s x i) x i k= + coefficient H θ F x i*derivativeMatrix s x i k+ + (∑l,s x i*localPartial H θ F' (.inl l) x i*derivativeMatrix (H l) x i k)+ + (∑α,s x i*localPartial H θ F' (.inr α) x i*halfDiff k (θ α) x)+ + s x i*taylorError H θ F F' x i k- + 2*spin x k*derivativeMatrix (coefficient H θ F) x i k*derivativeMatrix s x i k := by + dsimp only [taylorError,localPartial] + rw [coefficient_chain] + simp only [←Finset.mul_sum,mul_assoc] + rw [derivativeMatrix,halfDiff_mul] + dsimp only [derivativeMatrix] + ring + +omit [DecidableEq ι] [DecidableEq κ] in +lemma taylor_error_bound (H : ι→VectorFields n) (θ : κ→Spin n→ℝ) + (F : Fin n→Args (ι:=ι) (κ:=κ)→ℝ) + (F' : Fin n→Args (ι:=ι) (κ:=κ)→Args (ι:=ι) (κ:=κ)→L[ℝ]ℝ) + (x : Spin n) (i k : Fin n) {L Q T : ℝ} (hL : 0≤L) (hQ : 0≤Q) (hT : 0≤T) + (hargs : ‖flipHalfDiff k (fun y=>localArgs H θ y i) x‖≤Q+T) + (hF : ∀t∈Set.Icc (0:ℝ) 1,HasFDerivAt (F i) + (F' i (localArgs H θ x i+t • (localArgs H θ (flip x k) i-localArgs H θ x i))) + (localArgs H θ x i+t • (localArgs H θ (flip x k) i-localArgs H θ x i))) + (hLip : ∀t∈Set.Icc (0:ℝ) 1, + ‖F' i (localArgs H θ x i+t • (localArgs H θ (flip x k) i-localArgs H θ x i))- + F' i (localArgs H θ x i)‖≤L*‖t • (localArgs H θ (flip x k) i-localArgs H θ x i)‖) : + |taylorError H θ F F' x i k|≤4*L*(Q^2+Q*T+T^2) := by + have h:=coefficient_taylor k (fun y=>localArgs H θ y i) x (F i) (F' i) hL hF hLip + have hs:=(pow_le_pow_iff_left₀ (norm_nonneg _) (add_nonneg hQ hT) + (by decide : 2 ≠ 0)).2 hargs + have hh:=mul_le_mul_of_nonneg_left hs (mul_nonneg (by norm_num : (0:ℝ)≤2) hL) + change |taylorError H θ F F' x i k|≤_ at h + refine h.trans (hh.trans ?_) + nlinarith [sq_nonneg Q,sq_nonneg T,mul_nonneg hL (sq_nonneg Q),mul_nonneg hL (sq_nonneg T)] + +end SKGapCutoff.Recipe + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/LocalExtraction.lean b/lean/OAI/Probability/SKGap/Localization/LocalExtraction.lean new file mode 100644 index 0000000000000000000000000000000000000000..004a0c12ff0ac21a8e2dd57e140bf11505838360 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/LocalExtraction.lean @@ -0,0 +1,215 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.LiteralValues + +namespace OAI + +section + +noncomputable section +open scoped BigOperators +namespace SKGapCutoff.Static +variable {n : ℕ} + +lemma tested_l2_to_star (P G H : Observables n) (hP : ∀x,0≤P x) + {D : ℝ} (hD : 0≤D) (hH : (∑x,P x*(H x)^2)≤D) : + |∑x,P x*G x*H x|≤Real.sqrt D*starNorm P G := by + have hG : 0≤∑x,P x*(G x)^2:=Finset.sum_nonneg fun x _=>mul_nonneg (hP x) (sq_nonneg _) + have hS : (∑x,P x*(G x)^2)≤ starSquared P G := + le_add_of_nonneg_right (varianceEnergy_nonneg P hP G) + have H':=(weighted_cauchy_sq P G H hP).trans + (mul_le_mul hS hH (Finset.sum_nonneg fun x _=>mul_nonneg (hP x) (sq_nonneg _)) + (starSquared_nonneg P hP G)) + have H'' := Real.sqrt_le_sqrt H' + rw [Real.sqrt_sq_eq_abs,mul_comm (starSquared P G) D,Real.sqrt_mul hD] at H'' + exact H'' + +lemma local_source_extract (P C F M G : Observables n) (hP : ∀x,0≤P x) + {Q L D : ℝ} (hQ : 0≤Q) (hL : 0≤L) (hD : 0≤D) + (hC : ∀x,|C x|≤1) (hdC : ∀x,∑i,(halfDiff i C x)^2≤L^2) + (hM : (∑x,P x*(C x*M x)^2)≤D) + (hw : ∀U,(∀x,C x=0→U x=0)→ + |∑x,P x*U x*(F x+M x)|≤Q*starNorm P U) : + |∑x,P x*(C x*G x)*F x|≤(Q*Real.sqrt (3+2*L^2)+Real.sqrt D)*starNorm P G := by + have hh:=hw (fun x=>C x*G x) (by intro x hx;simp [hx]) + have hc:=star_multiplier P hP C G (by norm_num : (0:ℝ)≤1) hL hC hdC + norm_num only [one_pow,mul_one] at hc + have hm:=tested_l2_to_star P G (fun x=>C x*M x) hP hD hM + have he : (∑x,P x*(C x*G x)*F x)= + (∑x,P x*(C x*G x)*(F x+M x))-(∑x,P x*G x*(C x*M x)) := by + rw [←Finset.sum_sub_distrib] + apply Finset.sum_congr rfl;intro x _;ring + rw [he] + exact ((abs_sub _ _).trans (add_le_add + (hh.trans (mul_le_mul_of_nonneg_left hc hQ)) hm)).trans_eq (by ring) + +end SKGapCutoff.Static + +noncomputable section +open scoped BigOperators +namespace SKGapCutoff.Recipe +open Primary Static +variable {n : ℕ} + +lemma StartedMatrixEvent.mono_budget {j R A₀ A A' c B W C : ℝ} {M N : ℕ} + {J : Interaction n} (H : StartedMatrixEvent j R A₀ A c B W C M N J) (hA : A'≤A) : + StartedMatrixEvent j R A₀ A' c B W C M N J := by + refine ⟨H.1,H.2.1,?_⟩ + intro a ha hc + have h:=(H.2.2 a ha hc) + have hb : ∀w : List (SKGap.WordLetter (Fin n)),closedWordBounded A' w→closedWordBounded A w := by + intro w hw l hl + have hh:=hw l hl + cases l with + | diag p=>exact fun i=>(hh i).trans hA + | noise=>trivial + | inverse=>trivial + exact ⟨fun w hw hi hwa=>h.1 w hw hi (hb w hwa),fun w hw hi hwa=>h.2 w hw hi (hb w hwa)⟩ + +lemma residualCutoff_uniform_gradient (j K B ρ : ℝ) (hK : 0≤K) (hB : 0≤B) + (hρ : 0<ρ) (k : ℕ) : + ∃L≥0,∀n:ℕ,0hformal v l (by omega)) x) + (residual_derivative_bound hn hK hB J h hop (k+1) (fun v l hl=>hformal v l (by omega)) x) + have hs : (1:ℝ)≤Real.sqrt (n:ℝ) := by + rw [←Real.sqrt_one] + apply Real.sqrt_le_sqrt + exact_mod_cast (Nat.succ_le_of_lt hn) + have H:=hd.trans (div_le_self hA hs) + simpa only [norm_derivativeVector_sq] using pow_le_pow_left₀ (norm_nonneg _) H 2 + +end SKGapCutoff.Recipe + +end +end +end + +section + +noncomputable section +open scoped BigOperators Matrix.Norms.Frobenius +namespace SKGapCutoff.Recipe +open SKGap.Stein Primary Static +universe u + +theorem buffered_root_direction_weak {j K B Aroot ε c r₀ R ρ : ℝ} + (hj : 0≤j) (hK : 0≤K) (hB : 0≤B) (hA : 1≤Aroot) (hc : 0(hevent b).mono_budget (le_max_left A₁ A₂) + have he₂:=fun b=>(hevent b).mono_budget (le_max_right A₁ A₂) + obtain ⟨r₁,hr₁,D,hD,hL⟩:=hhs W C hW hC Ω n J h P hn hJ he₁ hbad hdim hP hp hm + obtain ⟨r,hr,w,y,c₀,heq,hweak⟩:=hh W C hW hC Ω n J h e P hn hJ he he₂ hbad hdim hP hp hm + have heqr : r₁=r:=funext fun b=>(hr b).2 (r₁ b) (hr₁ b).1 + rw [heqr] at hL + let E:=fun b=>{x | residualCutoff ρ j (J b) (h b) k x≠0} + let L:=fun b=>literalSusceptibility (fld j (J b) (h b) (k+1)) + (fun v=>j*(1-onsager j (J b) (h b) (k+1) v-SKGap.overlap (r b))) (r b) + let M:=fun b=>literalMiddle j (J b) (h b) (r b) k (w b) + let F:=fun b x=>∑i,(Real.tanh (fld j (J b) (h b) (k+1) x i)-Real.tanh (r b i))*e b i + let S:=(|j| *|literalSizeBudget j c R K f|)*η + have hS : 0≤S:=by dsimp [S];positivity + have hstable : ∀b x,x∈E b→ + LiteralStableAt (J b) j (fld j (J b) (h b) (k+1)) (mag j (J b) (h b) (k+1)) + (fun v=>j*(1-onsager j (J b) (h b) (k+1) v-SKGap.overlap (r b))) (r b) R η c x := by + intro b x hx + have hact (v : Fin (n b)→ℝ) : vectorNorm ((J b).mulVec v)≤K*vectorNorm v := + (vectorNorm_matrix_mul _ v).trans (mul_le_mul_of_nonneg_right (hevent b).1 (vectorNorm_nonneg v)) + obtain ⟨r',hr',hu',hs⟩:=stable_primary_buffer (hn b) hj hK hA hc hr₀ + (mul_nonneg (by norm_num) hρ.le) hε hAR hbuffer hR hsmall (J b) (hJ b) (h b) hact (hbad b) + have heqroot : r'=r b:=(hr b).2 r' hr' + rw [heqroot] at hs + obtain ⟨h0,h1⟩:=residualCutoff_support (hn b) hρ (J b) (h b) k x hx + have hρ2 : ρ*Real.sqrt (n b:ℝ)≤(2*ρ)*Real.sqrt (n b:ℝ) := by nlinarith [mul_nonneg hρ.le (Real.sqrt_nonneg (n b:ℝ))] + exact hs k x (h0.trans hρ2) (h1.trans hρ2) + have hmiddle : ∀b x,x∈E b→|M b x|≤S*|L b x| := by + intro b x hx + exact literal_middle_error (J b) j f (fld j (J b) (h b) (k+1)) + (mag j (J b) (h b) (k+1)) (w b) (y b) + (fun v=>j*(1-onsager j (J b) (h b) (k+1) v-SKGap.overlap (r b))) (c₀ b) (r b) (e b) x + (hn b) hc hη himplicit (hevent b).1 (he b) (hstable b x hx) (heq b x hx) + have hM : ∀b,(∑x,P b x*(residualCutoff ρ j (J b) (h b) k x*M b x)^2)≤S^2*D := by + intro b + calc + _ ≤ S^2*(∑x,P b x*(residualCutoff ρ j (J b) (h b) k x*L b x)^2) := by + rw [Finset.mul_sum] + apply Finset.sum_le_sum + intro x _ + by_cases hx:residualCutoff ρ j (J b) (h b) k x=0 + · simp [hx] + have H:=hmiddle b x hx + have H':=mul_le_mul_of_nonneg_left H (abs_nonneg (residualCutoff ρ j (J b) (h b) k x)) + have H'' : |residualCutoff ρ j (J b) (h b) k x*M b x|≤ + S*|residualCutoff ρ j (J b) (h b) k x*L b x| := by + simpa only [abs_mul,mul_left_comm] using H' + have H2:=pow_le_pow_left₀ (abs_nonneg _) H'' 2 + simp only [sq_abs,mul_pow] at H2 + have H3:=mul_le_mul_of_nonneg_left H2 (hP b x) + nlinarith only [H3] + _ ≤ _ := mul_le_mul_of_nonneg_left (hL b) (sq_nonneg S) + have hweakF : LocalUniformWeak E P (fun b x=>F b x+M b x) := by + apply hweak.congr + intro b x + rw [literal_source_phi] + obtain ⟨Q,hQ,hQbound⟩:=hweakF + obtain ⟨T,hT,hd⟩:=residualCutoff_uniform_gradient j K B ρ hK hB hρ k + refine ⟨r,hr,Q*Real.sqrt (3+2*T^2)+Real.sqrt (S^2*D),by positivity,?_⟩ + intro b G + apply local_source_extract (P b) (residualCutoff ρ j (J b) (h b) k) (F b) (M b) G + (hP b) hQ hT (mul_nonneg (sq_nonneg S) hD) _ + (hd (n b) (hn b) (J b) (h b) (hevent b).1 ((hevent b).2.1 (h b))) (hM b) + · intro U hU + apply hQbound b U + intro x hx + exact hU x (by simpa only [E,Set.mem_ofPred_eq,not_not] using hx) + · intro x + rw [abs_of_nonneg (residualCutoff_bounds ρ j (J b) (h b) k x).1] + exact (residualCutoff_bounds ρ j (J b) (h b) k x).2 + +end SKGapCutoff.Recipe + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/LocalFixedRecipe.lean b/lean/OAI/Probability/SKGap/Localization/LocalFixedRecipe.lean new file mode 100644 index 0000000000000000000000000000000000000000..8faa6d18d8f78aae86ab1b53c8a74c785e75af00 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/LocalFixedRecipe.lean @@ -0,0 +1,141 @@ +import Mathlib +import OAI.Probability.SKGap.Gaussian.LiteralWeakTail +import OAI.Probability.SKGap.Localization.StartedFixed + +namespace OAI + +section + +noncomputable section +open scoped BigOperators +namespace SKGapCutoff.Recipe.LocalFamilyRecipe +open Primary Static +universe u +variable {Ω : Type u} {n : Ω→ℕ} {M : ℕ} {κ : Type} [Fintype κ] [DecidableEq κ] +variable {σ : Type} [Fintype σ] +variable {E : ∀a,Set (Spin (n a))} {j : ℝ} {J : ∀a,Interaction (n a)} {h : ∀a,Fin (n a)→ℝ} +variable {Θ : ∀a,κ→Observables (n a)} {w y : ∀a,VectorFields (n a)} +variable {D : ∀a,OrdinaryData (n a) (Fin M) κ σ} {N p : ℕ} {K : ℝ} + +lemma appendFixed (H : LocalFamilyRecipe E j J h Θ w y D N p K) + (v : ∀a,Fin (n a)→ℝ) (hv : ∀a,vectorNorm (v a)≤1) (hK : 1≤K) : + LocalFamilyRecipe E j J h Θ w y (fun a=>(D a).appendFixed N (v a)) (N+1) p K := by + refine ⟨by omega,H.interaction,H.coupling,H.primary,H.predecessor,H.parameter,?_, + fun a x hx=>(H.coefficients a x hx).appendFixed hK (v a), + fun a=>(D a).appendFixed_Admissible N p (v a) (H.admissible a),?_⟩ + · obtain ⟨S,hS,hs⟩:=H.seed + refine ⟨S+1,by positivity,fun a=>?_⟩ + rw [(D a).appendFixed_seed N (v a)] + linarith [hs a,hv a] + · intro a x hx + have hp:=(D a).appendFixed_started_prefix (w a) (y a) N (v a) 1 H.positive + simpa only [hp.1,hp.2] using H.initial a x hx + +end SKGapCutoff.Recipe.LocalFamilyRecipe + +end +end + +section + +noncomputable section +open scoped BigOperators Matrix.Norms.Frobenius +namespace SKGapCutoff.Recipe +open Primary Static SKGap.Stein SKGap.Noncrossing.Primary SKGap.Noncrossing.Primary.Tensor.Series SKGap.Noncrossing.ClosedMarked +universe u +variable {Ω : Type u} {n : Ω→ℕ} {M : ℕ} +theorem literal_local_weak_comparison_targets (j : ℝ) (J : ∀b,Interaction (n b)) + (h : ∀b,Fin (n b)→ℝ) (l : Fin M) (f : KernelExpr) + (a c : ∀b,Spin (n b)→ℝ) (r e : ∀b,Fin (n b)→ℝ) + (w y : ∀b,VectorFields (n b)) (E : ∀b,Set (Spin (n b))) + (hn : ∀b,0Real.sqrt (n b:ℝ)*c b v) x‖≤Vc) + (heq : ∀b x,x∈E b→LiteralEquations (J b) j f (fld j (J b) (h b) l.val) + (mag j (J b) (h b) l.val) (w b) (y b) (a b) (c b) (r b) (e b) x) + (hdiag : ∀b x,x∈flipNeighborhood (E b)→LiteralInitialDiagnostics + (literalInitial (J b) j (Real.sqrt (n b:ℝ)) f (fld j (J b) (h b) l.val) + (mag j (J b) (h b) l.val) (a b) (c b) (r b) (e b)) + (w b) (y b) (primaryTree j (J b) (h b) x l.val) x V S F (literalResidualBudget j f R Bc l.val)) + (P : ∀b,Observables (n b)) (hP : ∀b x,0≤P b x) (hp : ∀b,∑x,P b x=1) + (hm : ∀b x i,conditionalMean (P b) x i=mag j (J b) (h b) 1 x i) + (hJ : ∀b,(J b).IsSymm) + (hw : ∀b x,x∈flipNeighborhood (E b)→ClosedWordTestBound j + (fun i=>phi (fld j (J b) (h b) l.val x i) (r b i) (a b x)) (J b) (literalResidualBudget j f R Bc l.val) W (2*(2+2*l.val)+5)) + (hd : ∀b x,x∈flipNeighborhood (E b)→ClosedWordDiagramBound j + (fun i=>phi (fld j (J b) (h b) l.val x i) (r b i) (a b x)) (J b) (literalResidualBudget j f R Bc l.val) C (2*M+2*(2+2*l.val)+4)) : + ((∀p≤l.val,LocalUniformWeak E P (fun b x=>∑i,residual j (J b) (h b) p x i*w b x i)) ∧ + LocalUniformWeak E P (fun b x=>∑i,residual j (J b) (h b) l.val x i*y b x i) ∧ + LocalUniformWeak E P (fun b x=>∑i,residual j (J b) (h b) l.val x i* + (Real.tanh (fld j (J b) (h b) l.val x i)/Real.sqrt (n b:ℝ))) ∧ + LocalUniformMultiplier E (fun b=>siteMean (fun x i=>phi (fld j (J b) (h b) l.val x i) (r b i) (a b x))) ∧ + LocalUniformMultiplier E (fun b x=>j*onsager j (J b) (h b) l.val x) ∧ + LocalUniformMultiplier E (fun b x=>Real.sqrt (n b:ℝ)*c b x)) ∧ + LocalUniformWeak E P (fun b x=>j*c b x*(∑i,residual j (J b) (h b) l.val x i* + (Real.tanh (fld j (J b) (h b) l.val x i)-Real.tanh (r b i)))) := by + let Kt:=2+|literalCoefficientBudget f j R Bc| + have hKt : 2≤Kt := by dsimp [Kt];linarith [abs_nonneg (literalCoefficientBudget f j R Bc)] + have hKt0 : 0≤Kt:=by linarith + have hA : 1≤literalResidualBudget j f R Bc l.val := + (by linarith : 1≤Kt).trans (residualCoefficientBudget_ge j hKt0 l.val 0) + have C:=literal_finite_control j J h l f a c r e w y E hn he + hK hB hBc hVa hVc hA hV hS hF hW hC hop hformal ha hc hDa hDc heq hdiag + (2+2*l.val) hw hd + have H:=literal_full_local_family j J h l f a c r e w y E hn he hBc ha hc heq + have hclass : literalCoefficientBudget f j R Bc≤Kt := by + dsimp [Kt];linarith [le_abs_self (literalCoefficientBudget f j R Bc)] + have HH:=H.mono le_rfl le_rfl le_rfl hclass + have hb:=residualCoefficientBudget_antitone j hKt0 l.val + have rule:=local_uniform_residual_rule C hP hp hm hn hJ Sum.inl (fun _ _=>rfl) + (residualCoefficientBudget j Kt l.val) hb l.val l.isLt + (fun p _=>hb (Nat.zero_le p)) + (fun p _=>hKt.trans (residualCoefficientBudget_ge j hKt0 l.val p)) + (fun p hp=>le_of_eq (residualCoefficientBudget_step j Kt hp)) + let D:=fun b=>literalFullData j (J b) (h b) l f (a b) (c b) (r b) (e b) + have hterms:=literal_local_weak_terminal_targets j J h l f a c r e w y E hn he + hK hB hBc hVa hVc hV hS hF hW hC hop hformal ha hc hDa hDc heq hdiag P hP hp hm hJ hw hd + let v:=fun b i=>Real.tanh (r b i)/Real.sqrt (n b:ℝ) + have hv : ∀b,vectorNorm (v b)≤1 := by + intro b + have hs : 0Real.tanh (r b i)):=by + ext i; simp [v,div_eq_mul_inv,mul_comm] + rw [hscale,vectorNorm_smul,abs_of_nonneg (inv_nonneg.mpr hs.le)] + exact (mul_le_mul_of_nonneg_left (vectorNorm_tanh (r b)) (inv_nonneg.mpr hs.le)).trans_eq + (inv_mul_cancel₀ hs.ne') + have H':=HH.appendFixed v hv (by linarith : 1≤Kt) + have hfixed:=rule l.val le_rfl (fun b=>(D b).appendFixed 1 (v b)) 2 + (H'.mono le_rfl le_rfl (by norm_num) (residualCoefficientBudget_ge j hKt0 l.val l.val)) (by omega) + have hroot : LocalUniformWeak E P (fun b x=>∑i,residual j (J b) (h b) l.val x i*v b i) := by + apply hfixed.congr + intro b x + rw [show 2=1+1 from rfl,OrdinaryData.appendFixed_started_source] + have hnorm := hterms.2.2.1.sub hroot + have hnorm' : LocalUniformWeak E P (fun b x=>∑i,residual j (J b) (h b) l.val x i* + ((Real.tanh (fld j (J b) (h b) l.val x i)-Real.tanh (r b i))/Real.sqrt (n b:ℝ))) := by + apply hnorm.congr + intro b x + simp only [v,←Finset.sum_sub_distrib] + apply Finset.sum_congr rfl + intro i _ + ring + refine ⟨hterms,?_⟩ + apply ((hnorm'.mul hP hterms.2.2.2.2.2).smul hP j).congr + intro b x + rw [normalized_pair_cancel (hn b) (residual j (J b) (h b) l.val) + (fun x i=>Real.tanh (fld j (J b) (h b) l.val x i)-Real.tanh (r b i)) (c b) x] + ring + +end SKGapCutoff.Recipe + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/LocalRecipeClass.lean b/lean/OAI/Probability/SKGap/Localization/LocalRecipeClass.lean new file mode 100644 index 0000000000000000000000000000000000000000..1820c7c949837d2ab5e013a1596808d9e6283401 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/LocalRecipeClass.lean @@ -0,0 +1,167 @@ +import Mathlib +import OAI.Probability.SKGap.Gaussian.SteinRecipeRegularity +import OAI.Probability.SKGap.Localization.LocalUniformWeak +import OAI.Probability.SKGap.Localization.StartedPrimary +import OAI.Probability.SKGap.Localization.UniformRecipeClass + +namespace OAI + +section + +noncomputable section +open scoped BigOperators +namespace SKGapCutoff.Recipe +open Primary Static +universe u +variable {Ω : Type u} {n : Ω→ℕ} {M : ℕ} {κ : Type} [Fintype κ] [DecidableEq κ] +variable {σ τ : Type} [Fintype σ] [Fintype τ] + +structure LocalFamilyRecipe (E : ∀a,Set (Spin (n a))) (j : ℝ) + (J : ∀a,Interaction (n a)) (h : ∀a,Fin (n a)→ℝ) (Θ : ∀a,κ→Observables (n a)) + (w y : ∀a,VectorFields (n a)) (D : ∀a,OrdinaryData (n a) (Fin M) κ σ) (N p : ℕ) (K : ℝ) : Prop where + positive : 1≤N + interaction : ∀a,(D a).J=J a + coupling : ∀a,(D a).j=j + primary : ∀a q,(D a).H q=fld j (J a) (h a) q.val + predecessor : ∀a q,(D a).predecessor q=mag j (J a) (h a) q.val + parameter : ∀a,(D a).θ=Θ a + seed : ∃S : ℝ,0≤S ∧ ∀a,(∑s,vectorNorm ((D a).seed s))≤S + coefficients : ∀a x,x∈flipNeighborhood (E a)→(D a).CoefficientClass N x K + admissible : ∀a,(D a).Admissible N p + initial : ∀a x,x∈E a→(D a).startedSource (w a) (y a) 1 x=w a x ∧ + (D a).startedAuxiliary (w a) (y a) 1 x=y a x + +namespace LocalFamilyRecipe +variable {E : ∀a,Set (Spin (n a))} {j : ℝ} {J : ∀a,Interaction (n a)} {h : ∀a,Fin (n a)→ℝ} +variable {Θ : ∀a,κ→Observables (n a)} {w y : ∀a,VectorFields (n a)} +variable {D : ∀a,OrdinaryData (n a) (Fin M) κ σ} {N p : ℕ} {K : ℝ} + +lemma mono (H : LocalFamilyRecipe E j J h Θ w y D N p K) {r A : ℕ} {L : ℝ} + (hr : r≤p) (hA : A≤N) (hpos : 1≤A) (hK : K≤L) : LocalFamilyRecipe E j J h Θ w y D A r L := + ⟨hpos,H.interaction,H.coupling,H.primary,H.predecessor,H.parameter,H.seed, + fun a x hx=>((H.coefficients a x hx).prefix hA).mono hK, + fun a=>(H.admissible a).prefix hA |>.mono hr,H.initial⟩ + +lemma appendStein (H : LocalFamilyRecipe E j J h Θ w y D N p K) (l m : Fin M) (α : κ) + (hl : p≤l.val) (hm : p ≤ m.val) {R : ℝ} + (ht : ∀a x,|(D a).θ α x|≤R) : + LocalFamilyRecipe E j J h Θ w y (fun a=>(D a).appendStein N l m α) (N+1) p + (K+4*steinCoefficientBudget R*K) := by + refine ⟨by omega,H.interaction,H.coupling,H.primary,H.predecessor,H.parameter,H.seed,?_,?_,?_⟩ + · intro a x hx + exact (H.coefficients a x hx).appendStein l m α R (ht a x) (fun k=>ht a (flip x k)) + · intro a;exact (D a).appendStein_Admissible N p l m α hl hm (H.admissible a) + · intro a x hx + have hp:=(D a).appendProduct_started_prefix (w a) (y a) N + (phiCoefficient l m α) (phiDerivative l m α) 1 H.positive + simpa only [OrdinaryData.appendStein,hp.1,hp.2] using H.initial a x hx + +lemma appendAuxiliary (H : LocalFamilyRecipe E j J h Θ w y D N p K) : + LocalFamilyRecipe E j J h Θ w y (fun a=>(D a).appendAuxiliary N) (N+1) p K := by + refine ⟨by omega,H.interaction,H.coupling,H.primary,H.predecessor,H.parameter,H.seed, + fun a x hx=>(H.coefficients a x hx).appendAuxiliary, + fun a=>(D a).appendAuxiliary_Admissible N p (H.admissible a),?_⟩ + intro a x hx + have hp:=(D a).appendAuxiliary_started_prefix (w a) (y a) N 1 H.positive + simpa only [hp.1,hp.2] using H.initial a x hx + +lemma appendPrimary (H : LocalFamilyRecipe E j J h Θ w y D N p K) (hn : ∀a,0(D a).appendPrimary N q) (N+1) p K := by + refine ⟨by omega,H.interaction,H.coupling,H.primary,H.predecessor,H.parameter,?_, + fun a x hx=>(H.coefficients a x hx).appendPrimary hK q, + fun a=>(D a).appendPrimary_Admissible N p q hq (H.admissible a),?_⟩ + · obtain ⟨S,hS,hs⟩:=H.seed + exact ⟨S+1,by positivity,fun a=>by rw [(D a).appendPrimary_seed N q (hn a)];linarith [hs a]⟩ + · intro a x hx + have hp:=(D a).appendPrimary_started_prefix (w a) (y a) N q 1 H.positive + simpa only [hp.1,hp.2] using H.initial a x hx + +lemma sameEnvironment (H : LocalFamilyRecipe E j J h Θ w y D N p K) + {F : ∀a,OrdinaryData (n a) (Fin M) κ τ} {A r : ℕ} {L : ℝ} + (H' : LocalFamilyRecipe E j J h Θ w y F A r L) (a : Ω) : + (D a).J=(F a).J ∧ (D a).j=(F a).j ∧ (D a).H=(F a).H ∧ + (D a).predecessor=(F a).predecessor ∧ (D a).θ=(F a).θ := by + exact ⟨(H.interaction a).trans (H'.interaction a).symm, + (H.coupling a).trans (H'.coupling a).symm, + funext fun q=>(H.primary a q).trans (H'.primary a q).symm, + funext fun q=>(H.predecessor a q).trans (H'.predecessor a q).symm, + (H.parameter a).trans (H'.parameter a).symm⟩ + +end LocalFamilyRecipe +end SKGapCutoff.Recipe + +end +end + +section + +noncomputable section +open scoped BigOperators +namespace SKGapCutoff.Recipe +open Primary Static +universe u +variable {Ω : Type u} {n : Ω→ℕ} {κ : Type} [Fintype κ] [DecidableEq κ] + +structure FiniteLocalRecipeControl (E : ∀a,Set (Spin (n a))) (j : ℝ) + (J : ∀a,Interaction (n a)) (h : ∀a,Fin (n a)→ℝ) (Θ : ∀a,κ→Observables (n a)) + (w y : ∀a,VectorFields (n a)) (M Nmax : ℕ) (A : ℝ) : Prop where + small : ∀ {σ : Type} [Fintype σ] (D : ∀a,OrdinaryData (n a) (Fin M) κ σ) + (N p : ℕ) (K : ℝ), LocalFamilyRecipe E j J h Θ w y D N p K → N≤Nmax → K≤A → + ∃C : ℝ,0≤C ∧ ∀a x,x∈flipNeighborhood (E a)→SmallBound ((D a).startedSource (w a) (y a) N) x C ∧ + (∀q,SmallBound ((D a).startedPartial (w a) (y a) N q) x C) ∧ + (∑i,|derivativeMatrix ((D a).startedSource (w a) (y a) N) x i i|)≤C + means : ∀ {σ : Type} [Fintype σ] (D : ∀a,OrdinaryData (n a) (Fin M) κ σ) + (N p : ℕ) (K : ℝ), LocalFamilyRecipe E j J h Θ w y D N p K → N≤Nmax → K≤A → + ∀b:Fin N,LocalUniformMultiplier E (fun a=>siteMean ((D a).auxCoefficient N b)) + parameter : ∀q:Fin M,LocalUniformMultiplier E + (fun a x=>j*(onsager j (J a) (h a) (q.val+1) x-onsager j (J a) (h a) q.val x)) + +end SKGapCutoff.Recipe +end +end + +section + +noncomputable section +open scoped BigOperators +namespace SKGapCutoff.Static +universe u +variable {Ω : Type u} {n : Ω→ℕ} {E : ∀a,Set (Spin (n a))} +lemma LocalUniformMultiplier.congr {F H : ∀a,Observables (n a)} (hF : LocalUniformMultiplier E F) + (he : ∀a x,F a x=H a x) : LocalUniformMultiplier E H := by + have : F=H:=funext fun a=>funext (he a) + rwa [←this] +lemma LocalUniformMultiplier.add {F H : ∀a,Observables (n a)} (hF : LocalUniformMultiplier E F) + (hH : LocalUniformMultiplier E H) : LocalUniformMultiplier E (fun a x=>F a x+H a x) := by + obtain ⟨B,L,hB,hL,hF,hdF⟩:=hF + obtain ⟨C,K,hC,hK,hH,hdH⟩:=hH + refine ⟨B+C,Real.sqrt (2*L^2+2*K^2),add_nonneg hB hC,Real.sqrt_nonneg _, + fun a x hx=>(abs_add_le _ _).trans (add_le_add (hF a x hx) (hH a x hx)),fun a x hx=>?_⟩ + rw [Real.sq_sqrt (by positivity)] + have he (i : Fin (n a)) : halfDiff i (fun y=>F a y+H a y) x=halfDiff i (F a) x+halfDiff i (H a) x := by + unfold halfDiff; ring + simp only [he] + calc + _ ≤ ∑i,(2*(halfDiff i (F a) x)^2+2*(halfDiff i (H a) x)^2) := by + apply Finset.sum_le_sum; intro i _; nlinarith [sq_nonneg (halfDiff i (F a) x-halfDiff i (H a) x)] + _ = 2*(∑i,(halfDiff i (F a) x)^2)+2*(∑i,(halfDiff i (H a) x)^2) := by + simp only [Finset.sum_add_distrib,Finset.mul_sum] + _ ≤ _ := by linarith [hdF a x hx,hdH a x hx] +lemma LocalUniformMultiplier.finset_sum {τ : Type*} {F : τ→∀a,Observables (n a)} (s : Finset τ) + (h : ∀t∈s,LocalUniformMultiplier E (F t)) : LocalUniformMultiplier E (fun a x=>∑t∈s,F t a x) := by + classical + induction s using Finset.induction_on with + | empty=>simpa using (LocalUniformMultiplier.const (n:=n) E 0) + | @insert t s ht ih=> + simpa only [Finset.sum_insert ht] using (h t (Finset.mem_insert_self ..)).add + (ih (fun r hr=>h r (Finset.mem_insert_of_mem hr))) +lemma LocalUniformMultiplier.sum {τ : Type*} [Fintype τ] {F : τ→∀a,Observables (n a)} + (h : ∀t,LocalUniformMultiplier E (F t)) : LocalUniformMultiplier E (fun a x=>∑t,F t a x) := + LocalUniformMultiplier.finset_sum Finset.univ (fun t _=>h t) +end SKGapCutoff.Static + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/LocalResidualInduction.lean b/lean/OAI/Probability/SKGap/Localization/LocalResidualInduction.lean new file mode 100644 index 0000000000000000000000000000000000000000..8e841c153d09762b3d59f427de5b7e8a4476f471 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/LocalResidualInduction.lean @@ -0,0 +1,204 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.UniformResidual +import OAI.Probability.SKGap.Localization.StartedPrimary +import OAI.Probability.SKGap.Localization.LocalRecipeClass + +namespace OAI + +section + +noncomputable section +open scoped BigOperators +namespace SKGapCutoff.Recipe +open Primary Static +universe u +variable {Ω : Type u} {n : Ω→ℕ} {M Nmax : ℕ} {A j : ℝ} +variable {J : ∀a,Interaction (n a)} {h : ∀a,Fin (n a)→ℝ} +variable {P : ∀a,Observables (n a)} +variable {κ : Type} [Fintype κ] [DecidableEq κ] +variable {Z : ∀a,Set (Spin (n a))} {Θ : ∀a,κ→Observables (n a)} +variable {w y : ∀a,VectorFields (n a)} + +def LocalRecipeResidualRule (Z : ∀a,Set (Spin (n a))) (Θ : ∀a,κ→Observables (n a)) + (w y : ∀a,VectorFields (n a)) (j : ℝ) (J : ∀a,Interaction (n a)) (h : ∀a,Fin (n a)→ℝ) + (P : ∀a,Observables (n a)) (M Nmax p : ℕ) (B : ℝ) : Prop := + ∀ {σ : Type} [Fintype σ] (D : ∀a,OrdinaryData (n a) (Fin M) κ σ) (N : ℕ), + LocalFamilyRecipe Z j J h Θ w y D N p B → N+2*p≤Nmax → + LocalUniformWeak Z P (fun a x=>∑i,residual j (J a) (h a) p x i*(D a).startedSource (w a) (y a) N x i) + +lemma FiniteLocalRecipeControl.local_onsager_multiplier (H : FiniteLocalRecipeControl Z j J h Θ w y M Nmax A) (k : ℕ) (hk : k≤M) : + LocalUniformMultiplier Z (fun a x=>j*onsager j (J a) (h a) k x) := by + have hh : LocalUniformMultiplier Z (fun a x=>∑q∈Finset.range k, + j*(onsager j (J a) (h a) (q+1) x-onsager j (J a) (h a) q x)) := by + apply LocalUniformMultiplier.finset_sum + intro q hq + exact H.parameter ⟨q,(Finset.mem_range.mp hq).trans_le hk⟩ + exact hh.congr (fun a x=>onsager_telescope j (J a) (h a) k x) + +lemma local_residual_rule_base (C : FiniteLocalRecipeControl Z j J h Θ w y M Nmax A) + (hP : ∀a x,0≤P a x) (hp : ∀a,∑x,P a x=1) + (hm : ∀a x i,conditionalMean (P a) x i=mag j (J a) (h a) 1 x i) + (B : ℝ) (hB : B≤A) : LocalRecipeResidualRule Z Θ w y j J h P M Nmax 0 B := by + intro σ inst D N H hN + obtain ⟨K,hK,hbound⟩:=C.small D N 0 B H (by omega) hB + have hh:=LocalUniformWeak.base P hP hp (fun a=>(D a).startedSource (w a) (y a) N) hK hK + (fun a x hx=>(hbound a x hx).2.2) (fun a x hx=>(hbound a x hx).1.size) + apply hh.congr + intro a x + simp only [Primary.residual,mag_zero,hm] + +lemma local_residual_rule_step (C : FiniteLocalRecipeControl Z j J h Θ w y M Nmax A) + (hP : ∀a x,0≤P a x) (hn : ∀a,0j*(onsager j (J a) (h a) (q.val+1) x-onsager j (J a) (h a) q.val x)) (k : ℕ) (hkM : k+1(D a).appendStein N l m (α l) + have HE : LocalFamilyRecipe Z j J h Θ w y E (N+1) k (b k) := by + have HH:=(H.mono (show k≤k+1 by omega) le_rfl H.positive le_rfl).appendStein l m (α l) le_rfl + (show k ≤ m.val by dsimp [m]; omega) + (R:=|j|) (fun a x=>by rw [H.parameter a,hΘ a l]; exact onsager_parameter_bound j (J a) (h a) k x) + exact HH.mono le_rfl le_rfl (by omega) hstep + have hEN : N+1+2*k≤Nmax := by omega + have source : LocalUniformWeak Z P (fun a x=>∑i,residual j (J a) (h a) k x i*(E a).startedSource (w a) (y a) (N+1) x i) := + ih k (by omega) E (N+1) HE hEN + have aux : LocalUniformWeak Z P (fun a x=>∑i,residual j (J a) (h a) k x i*(E a).startedAuxiliary (w a) (y a) (N+1) x i) := by + have HH:=ih k (by omega) (fun a=>(E a).appendAuxiliary (N+1)) (N+1+1) + HE.appendAuxiliary (by omega) + exact HH.congr (fun a x=>by rw [OrdinaryData.appendAuxiliary_started_source]) + have param := source.mul hP (C.parameter l) + have prev : LocalUniformWeak Z P (fun a x=>∑i,previousResidual j (J a) (h a) k x i*(E a).startedSource (w a) (y a) (N+1) x i) := by + cases k with + | zero=>exact (uniform_prev_zero P (fun a=>(E a).startedSource (w a) (y a) (N+1))).localize Z + | succ r=> + have HH:=ih r (by omega) E (N+1) (HE.mono (by omega) le_rfl HE.positive (hmono (by omega))) (by omega) + exact HH.congr (fun a x=>by simp only [previousResidual,Primary.residual,Nat.add_sub_cancel]) + have old:=prev.mul hP (C.local_onsager_multiplier k (by omega)) + have earlier : LocalUniformWeak Z P (fun a x=>j*(∑t:Fin (N+1),siteMean ((E a).auxCoefficient (N+1) t) x* + (∑i,residual j (J a) (h a) k x i*(E a).startedSource (w a) (y a) t.val x i))) := by + apply LocalUniformWeak.smul hP _ j + apply LocalUniformWeak.sum + intro t + have ht : LocalUniformWeak Z P (fun a x=>∑i,residual j (J a) (h a) k x i*(E a).startedSource (w a) (y a) t.val x i) := by + by_cases hz:t.val=0 + · have HH:=ih k (by omega) E 1 (HE.mono le_rfl HE.positive le_rfl le_rfl) (by omega) + apply HH.congr_on + intro a x hx + simp only [hz,OrdinaryData.startedSource_zero,(HE.initial a x hx).1] + · exact ih k (by omega) E t.val (HE.mono le_rfl t.isLt.le (by omega) le_rfl) (by omega) + exact ht.mul hP (C.means E (N+1) k (b k) HE (by omega) hkA t) + obtain ⟨V,hV,hbound⟩:=C.small E (N+1) k (b k) HE (by omega) hkA + have primary (q : Fin M) (hr : k≤q.val) : + LocalUniformWeak Z P (fun a x=>∑i,residual j (J a) (h a) k x i* + (mag j (J a) (h a) (q.val+1) x i/Real.sqrt (n a:ℝ))) := by + have HQ:=HE.appendPrimary hn hk2 q hr + have HH:=ih k (by omega) (fun a=>(E a).appendPrimary (N+1) q) (N+1+1) HQ (by omega) + apply HH.congr + intro a x + rw [OrdinaryData.appendPrimary_started_source] + simp only [HE.primary a q,mag_succ] + + have future : LocalUniformWeak Z P (fun a x=>j*(∑q:{q:Fin M//q≠l},siteMean ((E a).startedPartial (w a) (y a) (N+1) q) x* + (∑i,residual j (J a) (h a) k x i*mag j (J a) (h a) q.val.val x i))) := by + apply LocalUniformWeak.smul hP _ j + apply LocalUniformWeak.sum + intro q + by_cases hq : q.val.valresidual j (J a) (h a) k) + (fun a=>(E a).startedPartial (w a) (y a) (N+1) q.val) (fun a=>mag j (J a) (h a) (r.val+1)) + (primary r (by dsimp [r]; omega)) hV (fun a x hx=>(hbound a x hx).2.1 q.val) + simpa only [hr] using HH + have last : LocalUniformWeak Z P (fun a x=>j*(siteMean ((E a).startedPartial (w a) (y a) (N+1) l) x* + (∑i,residual j (J a) (h a) k x i*mag j (J a) (h a) (k+1) x i))) := by + apply LocalUniformWeak.smul hP _ j + exact local_uniform_normalized_pair P hP hn (fun a=>residual j (J a) (h a) k) + (fun a=>(E a).startedPartial (w a) (y a) (N+1) l) (fun a=>mag j (J a) (h a) (k+1)) + (primary l le_rfl) hV (fun a x hx=>(hbound a x hx).2.1 l) + apply ((((aux.add param).sub old).add earlier).add future).sub last |>.congr + intro a x + have hid:=(D a).started_residual_step (w a) (y a) N (by have:=H.positive; omega) l m (α l) hlm (hn a) j (J a) (hJ a) (h a) k Fin.val + (H.coupling a) (H.interaction a) (H.predecessor a) rfl (H.primary a l) (H.primary a m) + ((congrFun (H.parameter a) (α l)).trans (hΘ a l)) ((H.admissible a).startedPartial (w a) (y a) N le_rfl l (by dsimp [l]; omega)) x + dsimp only at hid + rw [hid] + dsimp only [E,l] + ring + +end SKGapCutoff.Recipe + +end +end + +section + +noncomputable section +open scoped BigOperators +namespace SKGapCutoff.Recipe +open Primary Static +universe u +variable {Ω : Type u} {n : Ω→ℕ} {M Nmax : ℕ} {A j : ℝ} +variable {J : ∀a,Interaction (n a)} {h : ∀a,Fin (n a)→ℝ} +variable {P : ∀a,Observables (n a)} +variable {κ : Type} [Fintype κ] [DecidableEq κ] +variable {Z : ∀a,Set (Spin (n a))} {Θ : ∀a,κ→Observables (n a)} +variable {w y : ∀a,VectorFields (n a)} + +theorem local_uniform_residual_rule (C : FiniteLocalRecipeControl Z j J h Θ w y M Nmax A) + (hP : ∀a x,0≤P a x) (hp : ∀a,∑x,P a x=1) + (hm : ∀a x i,conditionalMean (P a) x i=mag j (J a) (h a) 1 x i) + (hn : ∀a,0j*(onsager j (J a) (h a) (q.val+1) x-onsager j (J a) (h a) q.val x)) + (b : ℕ→ℝ) (hmono : Antitone b) (pmax : ℕ) (hM : pmax + intro hpmax + cases p with + | zero=>exact local_residual_rule_base C hP hp hm (b 0) (hA 0 hpmax) + | succ k=> + exact local_residual_rule_step C hP hn hJ b hmono α hΘ k (hpmax.trans_lt hM) + (hA k (by omega)) (h2 k (by omega)) (hstep k (by omega)) + (fun r hr=>ih r hr (by omega)) + +theorem uniform_local_weak_residual (p N : ℕ) {K : ℝ} (hK : 2≤K) (hM : pj*(onsager j (J a) (h a) (q.val+1) x-onsager j (J a) (h a) q.val x)) + (C : FiniteLocalRecipeControl Z j J h Θ w y M (N+2*p) (residualCoefficientBudget j K p 0)) + (hP : ∀a x,0≤P a x) (hp : ∀a,∑x,P a x=1) + (hm : ∀a x i,conditionalMean (P a) x i=mag j (J a) (h a) 1 x i) + (hn : ∀a,0∑i,residual j (J a) (h a) p x i*(D a).startedSource (w a) (y a) N x i) := by + have hK0 : 0≤K := by linarith + have hb:=residualCoefficientBudget_antitone j hK0 p + have HH:=local_uniform_residual_rule C hP hp hm hn hJ α hΘ (residualCoefficientBudget j K p) hb p hM + (fun r _=>hb (Nat.zero_le r)) (fun r _=>hK.trans (residualCoefficientBudget_ge j hK0 p r)) + (fun k hk=>le_of_eq (residualCoefficientBudget_step j K hk)) p le_rfl D N + apply HH _ le_rfl + simpa [residualCoefficientBudget] using H + +end SKGapCutoff.Recipe + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/LocalStartedDiagonal.lean b/lean/OAI/Probability/SKGap/Localization/LocalStartedDiagonal.lean new file mode 100644 index 0000000000000000000000000000000000000000..9df5f20cfbecb0c2539cfabe48c8412ee8fb3508 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/LocalStartedDiagonal.lean @@ -0,0 +1,170 @@ +import Mathlib +import OAI.Probability.SKGap.Matrix.ClosedErrorTrace +import OAI.Probability.SKGap.Localization.StartedMarked +import OAI.Probability.SKGap.Stability.LocalStartedImplicit + +namespace OAI + +section + +noncomputable section +open scoped BigOperators +namespace SKGapCutoff.Recipe.OrdinaryData +open Primary Matrix SKGap SKGap.Noncrossing SKGap.Noncrossing.Primary SKGap.Noncrossing.Primary.Tensor.Series +open SKGap.Noncrossing.ClosedMarked +variable {n : ℕ} {ι κ σ κ₀ σ₀ : Type*} [Fintype ι] [DecidableEq ι] [Fintype κ] [DecidableEq κ] [Fintype σ] +variable [Fintype κ₀] [DecidableEq κ₀] [Fintype σ₀] +variable (D : OrdinaryData n ι κ σ) (I : OrdinaryData n Unit κ₀ σ₀) +variable (w y : VectorFields n) (T : ι→SourceTree (Fin n→ℝ)) (t : SourceTree (Fin n→ℝ)) + +theorem implicit_started_diagonal_local (hj : D.j=I.j) (hJ : D.J=I.J) + (x : Spin n) + (hW : w x=I.sourceOf 1 (fun _=>y) x) + (hWf : ∀i,w (flip x i)=I.sourceOf 1 (fun _=>y) (flip x i)) + (hY : y x=I.fieldOf 1 (fun _=>w) (fun _=>y) x) + (hYf : ∀i,y (flip x i)=I.fieldOf 1 (fun _=>w) (fun _=>y) (flip x i)) (hn : 0if a=0 then C+F else Cs a + let Bf:=fun a=>if a=0 then |q| *(C+F)+F else Cf a + ∀a≤N, + (∑i,|derivativeMatrix (D.startedSource w y a) x i i|)≤ + ((D.startedSmallTree w y T (.implicit (I.implicitPartial y x) t) x a).marked D.j (I.implicitCoefficient x)).1.budget*B+ + (errorBudget R Bs Bf a).1*M ∧ + (∑i,|derivativeMatrix (D.startedAuxiliary w y a) x i i|)≤ + ((D.startedSmallTree w y T (.implicit (I.implicitPartial y x) t) x a).marked D.j (I.implicitCoefficient x)).2.budget*B+ + (errorBudget R Bs Bf a).2*M := by + have H:=D.implicit_started_error_words_local I w y T t hj hJ x hW hWf hY hYf ha0 hS hP hQ hR hM ha hp hr hs hf + (L:=2*N+3) (by simpa only [Nat.add_assoc] using hw) + dsimp only at H ⊢ + intro a haN + let t₀:SmallTree n:=.implicit (I.implicitPartial y x) t + let a₀:=I.implicitCoefficient x + have hret:=D.started_retained_diagonal w y T t₀ a₀ x a hn hB (hd a haN) + have hword (d : Fin n→ℝ) (hd' : ∀i,|d i|≤1) : wordBounded A [.diag d] := by + intro l hl + have he:l=Letter.diag d:=List.mem_singleton.mp hl + subst l + exact fun i=>(hd' i).trans hA + have herrorS : (∑i,|D.startedSourceError w y T t₀.tree a₀ x a i i|)≤ + (errorBudget R (fun a=>if a=0 then C+F else Cs a) + (fun a=>if a=0 then |I.j*siteMean I.implicitCoefficient x| *(C+F)+F else Cf a) a).1*M := by + apply diagonal_abs_sum_of_tests + intro d hd' + have HH:=(H a haN).1 [.diag d] (by simp only [List.length_singleton];omega) (hword d hd') + simpa [matrixWord,matrixLetter,t₀,a₀,SmallTree.tree] using HH + have herrorF : (∑i,|D.startedFieldError w y T t₀.tree a₀ x a i i|)≤ + (errorBudget R (fun a=>if a=0 then C+F else Cs a) + (fun a=>if a=0 then |I.j*siteMean I.implicitCoefficient x| *(C+F)+F else Cf a) a).2*M := by + apply diagonal_abs_sum_of_tests + intro d hd' + have HH:=(H a haN).2 [.diag d] (by simp only [List.length_singleton];omega) (hword d hd') + simpa [matrixWord,matrixLetter,t₀,a₀,SmallTree.tree] using HH + have hadd (Q R : Interaction n) : (∑i,|Q i i|)≤(∑i,|R i i|)+(∑i,|(Q-R) i i|) := by + rw [←Finset.sum_add_distrib] + apply Finset.sum_le_sum + intro i _ + simpa only [Matrix.sub_apply,add_sub_cancel] using abs_add_le (R i i) (Q i i-R i i) + exact ⟨(hadd _ _).trans (add_le_add hret.1 herrorS),(hadd _ _).trans (add_le_add hret.2 herrorF)⟩ + +end SKGapCutoff.Recipe.OrdinaryData + +end +end + +section + +noncomputable section +open scoped BigOperators +namespace SKGap.Noncrossing.ClosedMarked +open Matrix Primary Primary.Tensor.Series +variable {n : ℕ} +open Marked + +def pairBudget (V : Pair n) : ℝ := V.1.budget+V.2.budget +lemma pairBudget_nonneg (V : Pair n) : 0≤pairBudget V := add_nonneg (budget_nonneg _) (budget_nonneg _) +lemma mass_nonneg (P : GradedWords (Fin n)) : 0≤Marked.mass P := by + unfold Marked.mass + exact List.sum_nonneg (by intro r hr; obtain ⟨t,_,rfl⟩:=List.mem_map.mp hr;exact abs_nonneg _) +lemma smallBranch_budget (j : ℝ) (p : Fin n→ℝ) (T : GradedWords (Fin n)×GradedWords (Fin n)) (V : Pair n) : + pairBudget (smallBranch j p T V)= + SKGapCutoff.Recipe.vectorNorm p*(2*Marked.mass T.2+|j| *Marked.mass T.1)+pairBudget V := by + simp only [pairBudget,smallBranch,budget_append,budget_prefix,budget_diagonalWords,budget_averageWords,abs_neg] + ring +lemma boundedBranch_budget (j : ℝ) (p : Fin n→ℝ) (U V : Pair n) {A : ℝ} + (hp : |Diagram.mean p|≤A) : + pairBudget (boundedBranch j p U V)≤(2+|j| *A)*pairBudget U+pairBudget V := by + simp only [pairBudget,boundedBranch,budget_append,budget_prefix,budget_scale,abs_neg,abs_mul] + have H:=mul_le_mul_of_nonneg_left hp (mul_nonneg (abs_nonneg j) (budget_nonneg U.1)) + nlinarith [budget_nonneg U.1,budget_nonneg U.2, + mul_nonneg (mul_nonneg (abs_nonneg j) (le_trans (abs_nonneg _) hp)) (budget_nonneg U.2)] +lemma implicitPair_pairBudget (j : ℝ) (a p : Fin n→ℝ) (t : SourceTree (Fin n→ℝ)) : + pairBudget (implicitPair j a p t)= + (2+|j*Diagram.mean a|)*(SKGapCutoff.Recipe.vectorNorm p* + (Marked.mass (GradedWords.ordinaryWords j t).2+|j| *Marked.mass (GradedWords.ordinaryWords j t).1))+ + |j| *SKGapCutoff.Recipe.vectorNorm p*Marked.mass (GradedWords.ordinaryWords j t).1 := by + simp only [pairBudget,implicitPair,budget_append,budget_prefix,budget_scale,budget_diagonalWords,budget_averageWords,abs_neg] + ring +lemma implicitPair_budget_le (j : ℝ) (a p : Fin n→ℝ) (t : SourceTree (Fin n→ℝ)) + {A B Q : ℝ} (hp : SKGapCutoff.Recipe.vectorNorm p≤B) (hQ : 0≤Q) + (hq : Marked.mass (GradedWords.ordinaryWords j t).1≤Q ∧ Marked.mass (GradedWords.ordinaryWords j t).2≤Q) + (ha : |Diagram.mean a|≤A) : + pairBudget (implicitPair j a p t)≤(2+|j| *A)*(B*((1+|j|)*Q))+|j| *B*Q := by + rw [implicitPair_pairBudget,abs_mul] + have hB:0≤B:=(SKGapCutoff.Recipe.vectorNorm_nonneg _).trans hp + have hA:0≤A:=(abs_nonneg _).trans ha + apply add_le_add + · apply mul_le_mul + · exact add_le_add le_rfl (mul_le_mul_of_nonneg_left ha (abs_nonneg _)) + · apply le_trans (mul_le_mul_of_nonneg_left (show _ ≤ (1+|j|)*Q from ?_) (SKGapCutoff.Recipe.vectorNorm_nonneg p)) + · exact mul_le_mul_of_nonneg_right hp (mul_nonneg (by positivity) hQ) + · nlinarith [mul_le_mul_of_nonneg_left hq.1 (abs_nonneg j),hq.2] + · positivity [SKGapCutoff.Recipe.vectorNorm_nonneg p,mass_nonneg (GradedWords.ordinaryWords j t).1,mass_nonneg (GradedWords.ordinaryWords j t).2] + · positivity + · exact mul_le_mul (mul_le_mul_of_nonneg_left hp (abs_nonneg _)) hq.1 (mass_nonneg _) (mul_nonneg (abs_nonneg _) hB) + +namespace SmallTree +lemma smallBranches_budget (j : ℝ) (a₀ : Fin n→ℝ) + (xs : List ((Fin n→ℝ)×ClosedTree (Fin n→ℝ))) (U : SmallTree n) : + pairBudget ((smallBranches xs U).marked j a₀)= + (xs.map (fun t=>SKGapCutoff.Recipe.vectorNorm t.1*(2*Marked.mass (t.2.words j a₀).2+ + |j| *Marked.mass (t.2.words j a₀).1))).sum+pairBudget (U.marked j a₀) := by + induction xs with + | nil => simp [smallBranches] + | cons t xs ih => + simp only [smallBranches,List.foldr_cons,marked,smallBranch_budget,List.map_cons,List.sum_cons] at * + rw [ih];ring +lemma boundedBranches_budget (j : ℝ) (a₀ : Fin n→ℝ) + (xs : List ((Fin n→ℝ)×SmallTree n)) (U : SmallTree n) {A : ℝ} + (ha : ∀t∈xs,|Diagram.mean t.1|≤A) : + pairBudget ((boundedBranches xs U).marked j a₀)≤ + (xs.map (fun t=>(2+|j| *A)*pairBudget (t.2.marked j a₀))).sum+pairBudget (U.marked j a₀) := by + induction xs with + | nil => simp [boundedBranches] + | cons t xs ih => + simp only [boundedBranches,List.foldr_cons,marked,List.map_cons,List.sum_cons] + exact (boundedBranch_budget j _ _ _ (ha t (by simp))).trans + (by simpa only [add_assoc,boundedBranches] using add_le_add (le_refl ((2+|j| *A)*pairBudget (t.2.marked j a₀))) (ih (fun v hv=>ha v (by simp [hv])))) +end SmallTree +end SKGap.Noncrossing.ClosedMarked + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/LocalUniformWeak.lean b/lean/OAI/Probability/SKGap/Localization/LocalUniformWeak.lean new file mode 100644 index 0000000000000000000000000000000000000000..bfff576e0a138e1618122a7da40f4d5ad6830506 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/LocalUniformWeak.lean @@ -0,0 +1,150 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.StartedResidualStep + +namespace OAI + +section + +noncomputable section +open scoped BigOperators +namespace SKGapCutoff.Static +open Primary Recipe +universe u +variable {Ω : Type u} {n : Ω→ℕ} + +def LocalUniformMultiplier (E : ∀a,Set (Spin (n a))) (θ : ∀a,Observables (n a)) : Prop := + ∃B L : ℝ,0≤B ∧ 0≤L ∧ (∀a x,x∈flipNeighborhood (E a)→|θ a x|≤B) ∧ + (∀a x,x∈E a→∑i,(halfDiff i (θ a) x)^2≤L^2) + +def LocalUniformWeak (E : ∀a,Set (Spin (n a))) (P F : ∀a,Observables (n a)) : Prop := + ∃C : ℝ,0≤C ∧ ∀a G,(∀x,x∉E a→G x=0)→|∑x,P a x*G x*F a x|≤C*starNorm (P a) G + +lemma LocalUniformWeak.zero (E : ∀a,Set (Spin (n a))) (P : ∀a,Observables (n a)) : LocalUniformWeak E P (fun _ _=>0) := by + refine ⟨0,le_rfl,?_⟩ + simp + +variable {E : ∀a,Set (Spin (n a))} + +lemma LocalUniformWeak.congr {P F F' : ∀a,Observables (n a)} (h : LocalUniformWeak E P F) + (he : ∀a x,F a x=F' a x) : LocalUniformWeak E P F' := by + have : F=F' := funext fun a=>funext (he a) + rwa [←this] + +lemma LocalUniformWeak.add {P F H : ∀a,Observables (n a)} (hF : LocalUniformWeak E P F) + (hH : LocalUniformWeak E P H) : LocalUniformWeak E P (fun a x=>F a x+H a x) := by + obtain ⟨C,hC,hF⟩:=hF + obtain ⟨D,hD,hH⟩:=hH + refine ⟨C+D,add_nonneg hC hD,fun a G hG=>?_⟩ + simp only [mul_add,Finset.sum_add_distrib] + exact (abs_add_le _ _).trans ((add_le_add (hF a G hG) (hH a G hG)).trans_eq (by ring)) + +lemma LocalUniformWeak.neg {P F : ∀a,Observables (n a)} (hF : LocalUniformWeak E P F) : + LocalUniformWeak E P (fun a x=>-F a x) := by + obtain ⟨C,hC,hF⟩:=hF + refine ⟨C,hC,fun a G hG=>?_⟩ + simpa using hF a G hG + +lemma LocalUniformWeak.sub {P F H : ∀a,Observables (n a)} (hF : LocalUniformWeak E P F) + (hH : LocalUniformWeak E P H) : LocalUniformWeak E P (fun a x=>F a x-H a x) := by + simpa only [sub_eq_add_neg] using hF.add hH.neg + +lemma LocalUniformWeak.sum {τ : Type*} [Fintype τ] {P : ∀a,Observables (n a)} + {F : τ→∀a,Observables (n a)} (h : ∀t,LocalUniformWeak E P (F t)) : + LocalUniformWeak E P (fun a x=>∑t,F t a x) := by + classical + choose C hC hb using h + refine ⟨∑t,C t,Finset.sum_nonneg (fun t _=>hC t),fun a G hG=>?_⟩ + simp only [Finset.mul_sum] + rw [Finset.sum_comm] + exact (Finset.abs_sum_le_sum_abs ..).trans + ((Finset.sum_le_sum fun t _=>hb t a G hG).trans_eq (Finset.sum_mul ..).symm) + +lemma LocalUniformWeak.mul {P F θ : ∀a,Observables (n a)} (hP : ∀a x,0≤P a x) + (hF : LocalUniformWeak E P F) (hθ : LocalUniformMultiplier E θ) : + LocalUniformWeak E P (fun a x=>θ a x*F a x) := by + obtain ⟨C,hC,hF⟩:=hF + obtain ⟨B,L,hB,hL,hθ,hd⟩:=hθ + refine ⟨C*Real.sqrt (3*B^2+2*L^2),by positivity,fun a G hG=>?_⟩ + have hf:=hF a (fun x=>θ a x*G x) (by intro x hx; simp [hG x hx]) + have hm:=mul_le_mul_of_nonneg_left (local_star_multiplier (P a) (hP a) (E a) (θ a) G hG (hθ a) (hd a)) hC + calc + _ = |∑x,P a x*(θ a x*G x)*F a x| := by + congr 1; apply Finset.sum_congr rfl; intro x _; ring + _ ≤ C*(Real.sqrt (3*B^2+2*L^2)*starNorm (P a) G) := hf.trans hm + _ = _ := by ring + +lemma LocalUniformMultiplier.const (E : ∀a,Set (Spin (n a))) (c : ℝ) : LocalUniformMultiplier (n:=n) E (fun _ _=>c) := by + refine ⟨|c|,0,abs_nonneg _,le_rfl,fun _ _ _=>le_rfl,?_⟩ + intro a x hx + simp [halfDiff] + +lemma LocalUniformWeak.smul {P F : ∀a,Observables (n a)} (hP : ∀a x,0≤P a x) + (hF : LocalUniformWeak E P F) (c : ℝ) : LocalUniformWeak E P (fun a x=>c*F a x) := + hF.mul hP (LocalUniformMultiplier.const E c) + +lemma LocalUniformWeak.base (P : ∀a,Observables (n a)) (hP : ∀a x,0≤P a x) + (hp : ∀a,∑x,P a x=1) (U : ∀a,VectorFields (n a)) + {A B : ℝ} (hA : 0≤A) (hB : 0≤B) + (hD : ∀a x,x∈flipNeighborhood (E a)→∑i,|halfDiff i (fun y=>U a y i) x|≤A) + (hU : ∀a x,x∈flipNeighborhood (E a)→vectorNorm (U a x)≤B) : + LocalUniformWeak E P (fun a x=>∑i,(spin x i-conditionalMean (P a) x i)*U a x i) := by + refine ⟨2*B+5*A,by positivity,fun a G hG=>?_⟩ + apply local_signed_base_star (P a) (hP a) (hp a) (E a) G (U a) hA hB hG (hD a) + intro x hx + simpa only [vectorNorm_sq] using pow_le_pow_left₀ (vectorNorm_nonneg _) (hU a x hx) 2 + +lemma UniformWeak.localize {P F : ∀a,Observables (n a)} + (h : UniformWeak P F) (E : ∀a,Set (Spin (n a))) : LocalUniformWeak E P F := by + obtain ⟨C,hC,hh⟩:=h + exact ⟨C,hC,fun a G _=>hh a G⟩ + +lemma UniformMultiplier.localize {θ : ∀a,Observables (n a)} + (h : UniformMultiplier θ) (E : ∀a,Set (Spin (n a))) : LocalUniformMultiplier E θ := by + obtain ⟨B,L,hB,hL,hθ,hd⟩:=h + exact ⟨B,L,hB,hL,fun a x _=>hθ a x,fun a x _=>hd a x⟩ + +end SKGapCutoff.Static + +end +end + +section + +noncomputable section +open scoped BigOperators +namespace SKGapCutoff.Static +open Primary Recipe +universe u +variable {Ω : Type u} {n : Ω→ℕ} {E : ∀a,Set (Spin (n a))} + +lemma LocalUniformWeak.congr_on {P F F' : ∀a,Observables (n a)} (h : LocalUniformWeak E P F) + (he : ∀a x,x∈E a→F a x=F' a x) : LocalUniformWeak E P F' := by + obtain ⟨C,hC,hh⟩:=h + refine ⟨C,hC,fun a G hG=>?_⟩ + convert hh a G hG using 2 + apply Finset.sum_congr rfl + intro x _ + by_cases hx:x∈E a + · rw [he a x hx] + · simp [hG x hx] + +lemma LocalUniformMultiplier.normedMean (hn : ∀a,0Real.sqrt (n a:ℝ)*siteMean (U a) x) := by + exact ⟨B,B,hB,hB,fun a x hx=>scaledMean_size (hn a) _ _ hB (hU a x hx).size, + fun a x hx=>scaledMean_difference (hn a) _ _ hB (hU a x (Or.inl hx)).derivative⟩ + +lemma local_uniform_normalized_pair (P : ∀a,Observables (n a)) (hP : ∀a x,0≤P a x) + (hn : ∀a,0∑i,R a x i*(V a x i/Real.sqrt (n a:ℝ)))) + {B : ℝ} (hB : 0≤B) (hU : ∀a x,x∈flipNeighborhood (E a)→SmallBound (U a) x B) : + LocalUniformWeak E P (fun a x=>siteMean (U a) x*(∑i,R a x i*V a x i)) := by + exact (hV.mul hP (LocalUniformMultiplier.normedMean hn U hB hU)).congr + (fun a x=>normalized_pair_cancel (hn a) (R a) (V a) (siteMean (U a)) x) + +end SKGapCutoff.Static + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/LocalVolumeChange.lean b/lean/OAI/Probability/SKGap/Localization/LocalVolumeChange.lean new file mode 100644 index 0000000000000000000000000000000000000000..c346e986e0a7050d53f00cf083112b2b09836d98 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/LocalVolumeChange.lean @@ -0,0 +1,206 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.LocalVolumeEnergy +import OAI.Probability.SKGap.Gaussian.ProductGaussianDensity + +namespace OAI + +section +noncomputable section +namespace SKGap +open MeasureTheory ProbabilityTheory Matrix Real Set +open scoped BigOperators ENNReal NNReal + +lemma map_affine_matrix_volume {n : ℕ} (y : Field n) (A : Matrix (Fin n) (Fin n) ℝ) + (hA : A.det ≠ 0) : + Measure.map (fun g : Field n => y+A*ᵥg) volume = ENNReal.ofReal |A.det⁻¹| • volume := by + have he : (fun g : Field n => y+A*ᵥg) = (fun z => y+z) ∘ (fun g => A*ᵥg) := rfl + rw [he,← Measure.map_map (by fun_prop) (by fun_prop)] + have hm := Real.map_matrix_volume_pi_eq_smul_volume_pi hA + change Measure.map (fun g => A*ᵥg) volume=_ at hm + rw [hm,Measure.map_smul _ (by fun_prop),map_add_left_eq_self] + +lemma affine_set_lintegral_le {n : ℕ} (y : Field n) (A : Matrix (Fin n) (Fin n) ℝ) + (hA : A.det ≠ 0) {B E : Set (Field n)} (hB : MeasurableSet B) (hE : MeasurableSet E) + (hBE : ∀ g ∈ B,y+A*ᵥg ∈ E) (f : Field n → ℝ≥0∞) (hf : Measurable f) : + (∫⁻ g in B,f (y+A*ᵥg)) ≤ ENNReal.ofReal |A.det⁻¹| * ∫⁻ z in E,f z := by + calc + _ = ∫⁻ g,(B.indicator (fun g => f (y+A*ᵥg))) g := (lintegral_indicator hB _).symm + _ ≤ ∫⁻ g,(E.indicator f) (y+A*ᵥg) := by + apply lintegral_mono + intro g + by_cases hg : g ∈ B + · simp only [indicator_of_mem hg, indicator_of_mem (hBE g hg),le_refl] + · rw [indicator_of_notMem hg] + exact bot_le + _ = ∫⁻ z,E.indicator f z ∂Measure.map (fun g : Field n => y+A*ᵥg) volume := + (lintegral_map (hf.indicator hE) (by fun_prop)).symm + _ = _ := by rw [map_affine_matrix_volume y A hA,lintegral_smul_measure,lintegral_indicator hE]; rfl + +lemma gaussian_standard_density {n : ℕ} : gaussianCoordinates (Fin n) = + (volume : Measure (Field n)).withDensity (fun g => + ENNReal.ofReal (((sqrt (2*Real.pi))⁻¹)^(n:ℕ)*exp (-vectorNorm g^2/2))) := by + rw [gaussianCoordinates,GaussianDensity.pi_gaussian_density (hv := fun _ => one_ne_zero)] + congr 1 + funext g + congr 1 + simp only [gaussianPDFReal,sub_zero,NNReal.coe_one,mul_one,Finset.prod_mul_distrib, + Finset.prod_const,Finset.card_univ,Fintype.card_fin,← exp_sum,← Finset.sum_div, + ← Finset.sum_neg_distrib,vectorNorm_sq,vectorSqNorm] + +lemma gaussian_tilt_cancellation {n : ℕ} {B : Set (Field n)} (hB : MeasurableSet B) + (φ : Field n → ℝ) (hφ : Measurable φ) : + (∫⁻ g in B,ENNReal.ofReal (exp (vectorNorm g^2/2+φ g)) ∂gaussianCoordinates (Fin n)) = + ENNReal.ofReal (((sqrt (2*Real.pi))⁻¹)^n) * ∫⁻ g in B,ENNReal.ofReal (exp (φ g)) := by + have hnorm : Measurable (vectorNorm (n := n)) := (continuous_vectorNorm n).measurable + rw [gaussian_standard_density,restrict_withDensity hB, + lintegral_withDensity_eq_lintegral_mul _ (by fun_prop) (by fun_prop)] + have he (g : Field n) : + ENNReal.ofReal (((sqrt (2*Real.pi))⁻¹)^n*exp (-vectorNorm g^2/2)) * + ENNReal.ofReal (exp (vectorNorm g^2/2+φ g)) = + ENNReal.ofReal (((sqrt (2*Real.pi))⁻¹)^n) * ENNReal.ofReal (exp (φ g)) := by + rw [← ENNReal.ofReal_mul (by positivity),mul_assoc,← exp_add] + have hh : -vectorNorm g^2/2+(vectorNorm g^2/2+φ g)=φ g := by ring + rw [hh,ENNReal.ofReal_mul (by positivity)] + simp_rw [Pi.mul_apply,he] + exact lintegral_const_mul _ (by fun_prop) + +theorem local_volume_change_of_variables {n : ℕ} (y : Field n) + (U : Matrix (Fin n) (Fin n) ℝ) (hU : U.det ≠ 0) {σ : ℝ} (hσ : 0 < σ) + {B E : Set (Field n)} (hB : MeasurableSet B) (hE : MeasurableSet E) + (hBE : ∀ g ∈ B,y+(σ • U)*ᵥg ∈ E) (φ : Field n → ℝ) (hφ : Measurable φ) : + ENNReal.ofReal |U.det| * + (∫⁻ g in B,ENNReal.ofReal (exp (vectorNorm g^2/2+φ (y+(σ • U)*ᵥg))) + ∂gaussianCoordinates (Fin n)) ≤ + ENNReal.ofReal (((sqrt (2*Real.pi)*σ)⁻¹)^n) * ∫⁻ z in E,ENNReal.ofReal (exp (φ z)) := by + have hA : (σ • U).det ≠ 0 := by rw [Matrix.det_smul]; exact mul_ne_zero (pow_ne_zero _ hσ.ne') hU + rw [gaussian_tilt_cancellation hB (fun g => φ (y+(σ • U)*ᵥg)) (hφ.comp (by fun_prop))] + have hh := affine_set_lintegral_le y (σ • U) hA hB hE hBE (fun z => ENNReal.ofReal (exp (φ z))) (by fun_prop) + calc + _ ≤ ENNReal.ofReal |U.det| * (ENNReal.ofReal (((sqrt (2*Real.pi))⁻¹)^n)* + (ENNReal.ofReal |(σ • U).det⁻¹| * ∫⁻ z in E,ENNReal.ofReal (exp (φ z)))) := by gcongr + _ = _ := by + rw [← mul_assoc,← mul_assoc,← ENNReal.ofReal_mul (by positivity),← ENNReal.ofReal_mul (by positivity)] + congr 2 + rw [Matrix.det_smul,Fintype.card_fin,abs_inv,abs_mul,abs_pow,abs_of_pos hσ,mul_inv] + have hUd : |U.det| ≠ 0 := abs_ne_zero.mpr hU + rw [mul_inv,mul_pow] + simp only [← inv_pow] + field_simp + +end SKGap +end +end + +section +noncomputable section +namespace SKGap +open MeasureTheory ProbabilityTheory Matrix Real Set +open scoped BigOperators ENNReal NNReal + +lemma conditional_lintegral_identity {Ω : Type*} [MeasurableSpace Ω] {μ : Measure Ω} + [IsFiniteMeasure μ] {B : Set Ω} (hB : μ B ≠ 0) (f : Ω → ℝ≥0∞) : + μ B*(∫⁻ x,f x ∂cond μ B)=∫⁻ x in B,f x ∂μ := by + rw [ProbabilityTheory.cond,lintegral_smul_measure] + change μ B*((μ B)⁻¹*(∫⁻ x in B,f x ∂μ))=_ + rw [← mul_assoc,ENNReal.mul_inv_cancel hB (measure_ne_top _ _),one_mul] + +lemma whitening_logdet {n : ℕ} (U Q : Matrix (Fin n) (Fin n) ℝ) + (hU : U.det ≠ 0) (hQ : 0 < Q.det) (he : U*Q*U=1) : + log |U.det| = -log Q.det/2 := by + have hd : |U.det|^2*Q.det=1 := by + have hh := congrArg Matrix.det he + rw [Matrix.det_mul,Matrix.det_mul,Matrix.det_one] at hh + rw [sq_abs] + nlinarith only [hh] + have hh := congrArg log hd + rw [log_mul (pow_ne_zero _ (abs_ne_zero.mpr hU)) hQ.ne',log_pow,log_one] at hh + norm_num only [Nat.cast_ofNat] at hh + linarith + +def localAction {n : ℕ} (j σ : ℝ) (J : Matrix (Fin n) (Fin n) ℝ) + (h z : Field n) : ℝ := + -vectorNorm (tapField j J h z)^2/(2*σ^2)+(n:ℝ)*j*varianceAverage z^2/2 + +def localVolume {n : ℕ} (j σ : ℝ) (J : Matrix (Fin n) (Fin n) ℝ) + (h : Field n) (E : Set (Field n)) : ℝ≥0∞ := + ENNReal.ofReal (((sqrt (2*Real.pi)*σ)⁻¹)^n) * + ∫⁻ z in E,ENNReal.ofReal (exp (localAction j σ J h z)) + +lemma localAction_continuous {n : ℕ} (j σ : ℝ) (J : Matrix (Fin n) (Fin n) ℝ) + (h : Field n) : Continuous (localAction j σ J h) := by + have hb : Continuous (varianceAverage (n := n)) := by + unfold varianceAverage + exact continuous_const.sub (continuous_iff_continuousAt.mpr (fun y => (overlap_hasFDerivAt y).continuousAt)) + exact (((continuous_vectorNorm n).comp (continuous_tapField j J h)).pow 2 |>.neg |>.div_const _).add + ((hb.pow 2 |>.const_mul _).div_const _) + +theorem local_volume_quantitative {n : ℕ} (hn : 0 < n) {j K γ σ η ρ r ε₁ : ℝ} + (hj : 0 ≤ j) (hK : 0 ≤ K) (hγ : 0 < γ) (hσ : 0 < σ) (hη : 0 < η) (hρ : 0 ≤ ρ) + (J : Matrix (Fin n) (Fin n) ℝ) + (hJ : ∀ z : Field n, vectorNorm (J*ᵥz) ≤ K*vectorNorm z) (h y : Field n) + {E : Set (Field n)} (hE : MeasurableSet E) + (hball : ∀ d : Field n,vectorNorm d ≤ r*sqrt (n:ℝ) → y+d ∈ E) + (hsmall : 2*σ/sqrt γ ≤ r) + (hdet : log ((fieldJacobian j J y)ᵀ*(fieldJacobian j J y)+γ • 1).det ≤ + (n:ℝ)*(j*varianceAverage y^2+ε₁)) + (hres : vectorNorm (tapField j J h y) ≤ ρ*sqrt (n:ℝ)) : + ENNReal.ofReal ((3/4:ℝ)*exp (-(n:ℝ)*(ε₁/2+2*η+ + (1+η⁻¹)*(ρ^2/σ^2+6*(8*(j+K)^2+128*j^2)*σ^2/γ^2)+4*j*σ/sqrt γ))) ≤ + localVolume j σ J h E := by + let L := fieldJacobian j J y + let Q := Lᵀ*L+γ • (1 : Matrix (Fin n) (Fin n) ℝ) + obtain ⟨U,hUH,hUd,hUQ,hlin,hbound⟩ := localGaussian_whitening L hγ + have hU : U.det ≠ 0 := isUnit_iff_ne_zero.mp hUd + have hQ : 0 < Q.det := (regularizedGram_posDef L hγ).det_pos + have hlog := whitening_logdet U Q hU hQ hUQ + let μ := gaussianCoordinates (Fin n) + let B := localGaussianBall n + let l : ℝ := j*varianceAverage y^2/2-2*η- + (1+η⁻¹)*(ρ^2/σ^2+6*(8*(j+K)^2+128*j^2)*σ^2/γ^2)-4*j*σ/sqrt γ + have hjensen : exp ((n:ℝ)*l) ≤ ∫ g,exp (localExponent j σ J U h y g) ∂cond μ B := by + exact (exp_le_exp.mpr (localGaussian_exponent_bound hn hj hK hγ hσ hη hρ + J U hJ h y hUH hbound hlin hres)).trans (localGaussian_jensen hn j σ J U h y) + have hp : ENNReal.ofReal (3/4:ℝ) ≤ μ B := by + have hh := ENNReal.ofReal_le_ofReal (localGaussianBall_probability hn) + simpa only [measureReal_def,ENNReal.ofReal_toReal (measure_ne_top _ _)] using hh + have hcond : ENNReal.ofReal (exp ((n:ℝ)*l)) ≤ + ∫⁻ g,ENNReal.ofReal (exp (localExponent j σ J U h y g)) ∂cond μ B := by + have hi : Integrable (fun g => exp (localExponent j σ J U h y g)) (cond μ B) := + localGaussian_cond_integrable hn (continuous_exp.comp (localExponent_continuous _ _ _ _ _ _)) + rw [← ofReal_integral_eq_lintegral_ofReal hi (ae_of_all _ (fun _ => (exp_pos _).le))] + exact ENNReal.ofReal_le_ofReal hjensen + have hvol := local_volume_change_of_variables y U hU hσ (localGaussianBall_measurable n) hE + (fun g hg => hball _ ((localGaussian_displacement hγ hσ.le hbound hg).trans + (mul_le_mul_of_nonneg_right hsmall (sqrt_nonneg _)))) + (localAction j σ J h) (localAction_continuous _ _ _ _).measurable + have hexp (g : Field n) : vectorNorm g^2/2+localAction j σ J h (y+(σ • U)*ᵥg)= + localExponent j σ J U h y g := by unfold localAction localExponent; ring + simp_rw [hexp] at hvol + change ENNReal.ofReal |U.det| *(∫⁻ g in B,ENNReal.ofReal (exp (localExponent j σ J U h y g)) ∂μ) ≤ + localVolume j σ J h E at hvol + rw [← conditional_lintegral_identity (localGaussianBall_ne_zero hn)] at hvol + have hscalar : (3/4:ℝ)*exp (-(n:ℝ)*(ε₁/2+2*η+ + (1+η⁻¹)*(ρ^2/σ^2+6*(8*(j+K)^2+128*j^2)*σ^2/γ^2)+4*j*σ/sqrt γ)) ≤ + |U.det| *((3/4:ℝ)*exp ((n:ℝ)*l)) := by + rw [← exp_log (abs_pos.mpr hU)] + calc + _ ≤ (3/4:ℝ)*exp (log |U.det|+(n:ℝ)*l) := by + apply mul_le_mul_of_nonneg_left (exp_le_exp.mpr ?_) (by norm_num) + rw [hlog] + change log Q.det ≤ _ at hdet + dsimp [l] + linarith only [hdet] + _ = _ := by rw [exp_add]; ring + calc + _ ≤ ENNReal.ofReal (|U.det| *((3/4:ℝ)*exp ((n:ℝ)*l))) := ENNReal.ofReal_le_ofReal hscalar + _ = ENNReal.ofReal |U.det| *(ENNReal.ofReal (3/4:ℝ)*ENNReal.ofReal (exp ((n:ℝ)*l))) := by + rw [ENNReal.ofReal_mul (abs_nonneg _),ENNReal.ofReal_mul (by norm_num)] + _ ≤ ENNReal.ofReal |U.det| *(μ B*(∫⁻ g,ENNReal.ofReal (exp (localExponent j σ J U h y g)) ∂cond μ B)) := by + gcongr + _ ≤ _ := hvol + +end SKGap +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/LocalVolumeEnergy.lean b/lean/OAI/Probability/SKGap/Localization/LocalVolumeEnergy.lean new file mode 100644 index 0000000000000000000000000000000000000000..2b8a904bad1f9511eb47c8002653d377c8df5fad --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/LocalVolumeEnergy.lean @@ -0,0 +1,255 @@ +import Mathlib +import OAI.Probability.SKGap.Gaussian.LocalGaussianMoments + +namespace OAI + +section +noncomputable section +namespace SKGap +open MeasureTheory ProbabilityTheory Matrix Real Set +open scoped BigOperators ENNReal NNReal + +lemma continuous_vectorNorm (n : ℕ) : Continuous (vectorNorm (n := n)) := by + unfold vectorNorm + exact continuous_norm.comp (PiLp.continuous_toLp 2 _) + +lemma continuous_tapField {n : ℕ} (j : ℝ) (J : Matrix (Fin n) (Fin n) ℝ) (h : Field n) : + Continuous (tapField j J h) := by + exact continuous_iff_continuousAt.mpr (fun y => (tapField_hasFDerivAt j J h y).continuousAt) + +lemma tap_remainder_sq_integrable {n : ℕ} (hn : 0 < n) {j K : ℝ} + (hj : 0 ≤ j) (hK : 0 ≤ K) (J : Matrix (Fin n) (Fin n) ℝ) + (hJ : ∀ z : Field n, vectorNorm (J*ᵥz) ≤ K*vectorNorm z) (h y : Field n) + (A : Matrix (Fin n) (Fin n) ℝ) : + Integrable (fun g => vectorNorm (tapField j J h (y+A*ᵥg)-tapField j J h y- + (fieldJacobian j J y)*ᵥ(A*ᵥg))^2) (gaussianCoordinates (Fin n)) := by + apply ((matrix_fourth_sum_integrable A).const_mul (8*(j+K)^2+128*j^2)).mono' ?_ ?_ + · apply Continuous.aestronglyMeasurable + exact ((continuous_vectorNorm n).comp + (((continuous_tapField j J h).comp (by fun_prop)).sub continuous_const |>.sub (by fun_prop))).pow 2 + · filter_upwards [] with g + rw [Real.norm_eq_abs,abs_of_nonneg (sq_nonneg _)] + exact tap_remainder_sq hn hj hK J hJ h y (A*ᵥg) + +theorem localGaussian_remainder_cond {n : ℕ} (hn : 0 < n) {j K : ℝ} + (hj : 0 ≤ j) (hK : 0 ≤ K) (J : Matrix (Fin n) (Fin n) ℝ) + (hJ : ∀ z : Field n, vectorNorm (J*ᵥz) ≤ K*vectorNorm z) (h y : Field n) + {U : Matrix (Fin n) (Fin n) ℝ} (hU : U.IsHermitian) {γ σ : ℝ} (hγ : 0 < γ) + (hbound : ∀ g : Field n, vectorNorm (U*ᵥg) ≤ vectorNorm g/sqrt γ) : + (∫ g,vectorNorm (tapField j J h (y+(σ • U)*ᵥg)-tapField j J h y- + (fieldJacobian j J y)*ᵥ((σ • U)*ᵥg))^2 + ∂cond (gaussianCoordinates (Fin n)) (localGaussianBall n)) ≤ + 6*(8*(j+K)^2+128*j^2)*(n:ℝ)*σ^4/γ^2 := by + let C := 8*(j+K)^2+128*j^2 + have hC : 0 ≤ C := by dsimp [C]; positivity + have hi := tap_remainder_sq_integrable hn hj hK J hJ h y (σ • U) + have hp : 1/2 ≤ (gaussianCoordinates (Fin n)).real (localGaussianBall n) := + (by norm_num : (1:ℝ)/2 ≤ 3/4).trans (localGaussianBall_probability hn) + have hc := integral_cond_nonneg_le_two hp hi (ae_of_all _ (fun g => sq_nonneg _)) + have hb : (∫ g,vectorNorm (tapField j J h (y+(σ • U)*ᵥg)-tapField j J h y- + (fieldJacobian j J y)*ᵥ((σ • U)*ᵥg))^2 ∂gaussianCoordinates (Fin n)) ≤ + C*(3*(n:ℝ)*σ^4/γ^2) := by + calc + _ ≤ ∫ g,C*(∑ i,(((σ • U)*ᵥg) i)^4) ∂gaussianCoordinates (Fin n) := + integral_mono hi ((matrix_fourth_sum_integrable _).const_mul _) + (fun g => tap_remainder_sq hn hj hK J hJ h y _) + _ = C*(∫ g,∑ i,(((σ • U)*ᵥg) i)^4 ∂gaussianCoordinates (Fin n)) := integral_const_mul _ _ + _ ≤ _ := mul_le_mul_of_nonneg_left (localGaussian_fourth_moments hU hγ hbound).1 hC + calc + _ ≤ 2*(C*(3*(n:ℝ)*σ^4/γ^2)) := hc.trans (mul_le_mul_of_nonneg_left hb (by norm_num)) + _ = _ := by dsimp [C]; ring + +lemma vectorNorm_add_sq_young {n : ℕ} (u v : Field n) {η : ℝ} (hη : 0 < η) : + vectorNorm (u+v)^2 ≤ (1+η)*vectorNorm u^2+(1+η⁻¹)*vectorNorm v^2 := by + have hh := (sq_le_sq₀ (vectorNorm_nonneg _) (add_nonneg (vectorNorm_nonneg u) + (vectorNorm_nonneg v))).mpr (vectorNorm_add_le u v) + have hy : 2*vectorNorm u*vectorNorm v ≤ η*vectorNorm u^2+η⁻¹*vectorNorm v^2 := by + apply (mul_le_mul_iff_right₀ hη).mp + have he : η⁻¹*η=1 := inv_mul_cancel₀ hη.ne' + nlinarith [sq_nonneg (η*vectorNorm u-vectorNorm v)] + nlinarith + +theorem local_energy_pointwise {n : ℕ} (u v R g : Field n) {σ η ρ : ℝ} + (hσ : 0 < σ) (hη : 0 < η) (hρ : 0 ≤ ρ) + (hu : vectorNorm u ≤ ρ*sqrt (n:ℝ)) + (hv : vectorNorm v ≤ σ*vectorNorm g) (hg : g ∈ localGaussianBall n) : + vectorNorm g^2/2-vectorNorm (u+v+R)^2/(2*σ^2) ≥ + -2*η*(n:ℝ)-(1+η⁻¹)*(ρ^2*(n:ℝ)+vectorNorm R^2)/σ^2 := by + have hsσ : 0 < σ^2 := sq_pos_of_pos hσ + have hu2 := (sq_le_sq₀ (vectorNorm_nonneg u) (by positivity)).mpr hu + rw [mul_pow,Real.sq_sqrt (Nat.cast_nonneg _)] at hu2 + have hv2 := (sq_le_sq₀ (vectorNorm_nonneg v) (mul_nonneg hσ.le (vectorNorm_nonneg g))).mpr hv + rw [mul_pow] at hv2 + have hUR := vectorNorm_add_sq_young u R (η := 1) (by norm_num) + norm_num only [inv_one,one_add_one_eq_two] at hUR + have hh := vectorNorm_add_sq_young v (u+R) hη + have he : v+(u+R)=u+v+R := by abel + rw [he] at hh + have hpos : 0 ≤ 1+η⁻¹ := by positivity + have hcombine : vectorNorm (u+v+R)^2 ≤ (1+η)*σ^2*vectorNorm g^2+ + 2*(1+η⁻¹)*(ρ^2*(n:ℝ)+vectorNorm R^2) := by + calc + _ ≤ (1+η)*vectorNorm v^2+(1+η⁻¹)*(2*vectorNorm u^2+2*vectorNorm R^2) := + hh.trans (add_le_add le_rfl (mul_le_mul_of_nonneg_left hUR hpos)) + _ ≤ (1+η)*(σ^2*vectorNorm g^2)+(1+η⁻¹)*(2*(ρ^2*(n:ℝ))+2*vectorNorm R^2) := + add_le_add (mul_le_mul_of_nonneg_left hv2 (by positivity)) + (mul_le_mul_of_nonneg_left (by linarith) hpos) + _ = _ := by ring + have hgn : vectorNorm g^2 ≤ 4*(n:ℝ) := by rw [vectorNorm_sq]; exact hg + apply (mul_le_mul_iff_right₀ hsσ).mp + have he1 : (-2*η*(n:ℝ)-(1+η⁻¹)*(ρ^2*(n:ℝ)+vectorNorm R^2)/σ^2)*σ^2= + -2*η*(n:ℝ)*σ^2-(1+η⁻¹)*(ρ^2*(n:ℝ)+vectorNorm R^2) := by + rw [sub_mul,div_mul_cancel₀ _ hsσ.ne'] + have he2 : (vectorNorm g^2/2-vectorNorm (u+v+R)^2/(2*σ^2))*σ^2= + (σ^2*vectorNorm g^2-vectorNorm (u+v+R)^2)/2 := by + field_simp + rw [mul_comm (σ^2) _,mul_comm (σ^2) _,he1,he2] + nlinarith [mul_le_mul_of_nonneg_left hgn (mul_nonneg hη.le hsσ.le)] + +end SKGap +end +end + +section +noncomputable section +namespace SKGap +open MeasureTheory ProbabilityTheory Matrix Real Set +open scoped BigOperators ENNReal NNReal + +lemma localGaussianBall_compact (n : ℕ) : IsCompact (localGaussianBall n) := by + apply (isCompact_Icc : IsCompact (Icc (fun _ : Fin n => -2*sqrt (n:ℝ)) (fun _ : Fin n => 2*sqrt (n:ℝ)))).of_isClosed_subset + · apply isClosed_le _ continuous_const + unfold vectorSqNorm + fun_prop + · intro g hg + have hb := localGaussianBall_norm hg + have hc (i : Fin n) : |g i| ≤ 2*sqrt (n:ℝ) := by + have hh := PiLp.norm_apply_le (WithLp.toLp 2 g) i + exact (show |g i| ≤ vectorNorm g by simpa only [Real.norm_eq_abs,vectorNorm] using hh).trans hb + exact ⟨fun i => by simpa only [neg_mul] using (abs_le.mp (hc i)).1,fun i => (abs_le.mp (hc i)).2⟩ + +lemma localGaussian_cond_integrable {n : ℕ} (hn : 0 < n) {f : Field n → ℝ} + (hf : Continuous f) : Integrable f (cond (gaussianCoordinates (Fin n)) (localGaussianBall n)) := by + exact (hf.continuousOn.integrableOn_compact (localGaussianBall_compact n)).smul_measure + (ENNReal.inv_ne_top.mpr (localGaussianBall_ne_zero hn)) + +def localExponent {n : ℕ} (j σ : ℝ) (J U : Matrix (Fin n) (Fin n) ℝ) (h y g : Field n) : ℝ := + vectorNorm g^2/2-vectorNorm (tapField j J h (y+(σ • U)*ᵥg))^2/(2*σ^2)+ + (n:ℝ)*j*varianceAverage (y+(σ • U)*ᵥg)^2/2 + +lemma localExponent_continuous {n : ℕ} (j σ : ℝ) (J U : Matrix (Fin n) (Fin n) ℝ) (h y : Field n) : + Continuous (localExponent j σ J U h y) := by + have hb : Continuous (varianceAverage (n := n)) := by + unfold varianceAverage + exact continuous_const.sub (continuous_iff_continuousAt.mpr (fun y => (overlap_hasFDerivAt y).continuousAt)) + exact (((continuous_vectorNorm n).pow 2 |>.div_const 2).sub + (((continuous_vectorNorm n).comp ((continuous_tapField j J h).comp (by fun_prop))).pow 2 |>.div_const _)).add + (((hb.comp (by fun_prop)).pow 2 |>.const_mul ((n:ℝ)*j)).div_const 2) + +lemma localGaussian_displacement {n : ℕ} {U : Matrix (Fin n) (Fin n) ℝ} {γ σ : ℝ} + (_hγ : 0 < γ) (hσ : 0 ≤ σ) + (hbound : ∀ g : Field n, vectorNorm (U*ᵥg) ≤ vectorNorm g/sqrt γ) + {g : Field n} (hg : g ∈ localGaussianBall n) : + vectorNorm ((σ • U)*ᵥg) ≤ (2*σ/sqrt γ)*sqrt (n:ℝ) := by + rw [Matrix.smul_mulVec] + change vectorNorm (fun i => σ*(U*ᵥg) i) ≤ _ + rw [vectorNorm_smul,abs_of_nonneg hσ] + calc + _ ≤ σ*(vectorNorm g/sqrt γ) := mul_le_mul_of_nonneg_left (hbound g) hσ + _ ≤ σ*((2*sqrt (n:ℝ))/sqrt γ) := mul_le_mul_of_nonneg_left + (div_le_div_of_nonneg_right (localGaussianBall_norm hg) (sqrt_nonneg _)) hσ + _ = _ := by ring + +lemma localGaussian_variance_change {n : ℕ} (hn : 0 < n) (y : Field n) + {U : Matrix (Fin n) (Fin n) ℝ} {γ σ : ℝ} (hγ : 0 < γ) (hσ : 0 ≤ σ) + (hbound : ∀ g : Field n, vectorNorm (U*ᵥg) ≤ vectorNorm g/sqrt γ) + {g : Field n} (hg : g ∈ localGaussianBall n) : + |varianceAverage (y+(σ • U)*ᵥg)^2-varianceAverage y^2| ≤ 8*σ/sqrt γ := by + have hn0 : sqrt (n:ℝ) ≠ 0 := by positivity + calc + _ ≤ 4/sqrt (n:ℝ)*vectorNorm ((σ • U)*ᵥg) := varianceAverage_sq_difference hn y _ + _ ≤ 4/sqrt (n:ℝ)*((2*σ/sqrt γ)*sqrt (n:ℝ)) := mul_le_mul_of_nonneg_left + (localGaussian_displacement hγ hσ hbound hg) (by positivity) + _ = _ := by field_simp; ring + +theorem localGaussian_exponent_bound {n : ℕ} (hn : 0 < n) {j K γ σ η ρ : ℝ} + (hj : 0 ≤ j) (hK : 0 ≤ K) (hγ : 0 < γ) (hσ : 0 < σ) (hη : 0 < η) (hρ : 0 ≤ ρ) + (J U : Matrix (Fin n) (Fin n) ℝ) + (hJ : ∀ z : Field n, vectorNorm (J*ᵥz) ≤ K*vectorNorm z) (h y : Field n) + (hU : U.IsHermitian) + (hbound : ∀ g : Field n, vectorNorm (U*ᵥg) ≤ vectorNorm g/sqrt γ) + (hlin : ∀ g : Field n, vectorNorm ((fieldJacobian j J y)*ᵥ(U*ᵥg)) ≤ vectorNorm g) + (hres : vectorNorm (tapField j J h y) ≤ ρ*sqrt (n:ℝ)) : + (n:ℝ)*(j*varianceAverage y^2/2-2*η- + (1+η⁻¹)*(ρ^2/σ^2+6*(8*(j+K)^2+128*j^2)*σ^2/γ^2)-4*j*σ/sqrt γ) ≤ + ∫ g,localExponent j σ J U h y g + ∂cond (gaussianCoordinates (Fin n)) (localGaussianBall n) := by + let μ := cond (gaussianCoordinates (Fin n)) (localGaussianBall n) + let : IsProbabilityMeasure μ := cond_isProbabilityMeasure (localGaussianBall_ne_zero hn) + let R : Field n → Field n := fun g => tapField j J h (y+(σ • U)*ᵥg)-tapField j J h y- + (fieldJacobian j J y)*ᵥ((σ • U)*ᵥg) + have hiR : Integrable (fun g => vectorNorm (R g)^2) μ := + integrable_cond_of_integrable (localGaussianBall_ne_zero hn) + (tap_remainder_sq_integrable hn hj hK J hJ h y _) + have hR := localGaussian_remainder_cond hn hj hK J hJ h y hU hγ hbound (σ := σ) + change (∫ g,vectorNorm (R g)^2 ∂μ) ≤ _ at hR + let f : Field n → ℝ := fun g => (n:ℝ)*j*varianceAverage y^2/2-2*η*(n:ℝ)- + (1+η⁻¹)*(ρ^2*(n:ℝ)+vectorNorm (R g)^2)/σ^2-4*(n:ℝ)*j*σ/sqrt γ + have hif : Integrable f μ := by + exact (((integrable_const _).sub (integrable_const _)).sub + (((integrable_const _).add hiR).const_mul _ |>.div_const _)).sub (integrable_const _) + have hmono : (∫ g,f g ∂μ) ≤ ∫ g,localExponent j σ J U h y g ∂μ := by + apply integral_mono_ae hif (localGaussian_cond_integrable hn (localExponent_continuous _ _ _ _ _ _)) + apply ae_cond_of_forall_mem (localGaussianBall_measurable n) + intro g hg + let v := (fieldJacobian j J y)*ᵥ((σ • U)*ᵥg) + have hv : vectorNorm v ≤ σ*vectorNorm g := by + dsimp [v] + rw [Matrix.smul_mulVec,Matrix.mulVec_smul] + change vectorNorm (fun i => σ*((fieldJacobian j J y)*ᵥ(U*ᵥg)) i) ≤ _ + rw [vectorNorm_smul,abs_of_pos hσ] + exact mul_le_mul_of_nonneg_left (hlin g) hσ.le + have hh := local_energy_pointwise (tapField j J h y) v (R g) g hσ hη hρ hres hv hg + have he : tapField j J h y+v+R g=tapField j J h (y+(σ • U)*ᵥg) := by dsimp [v,R]; abel + rw [he] at hh + have hb := (abs_le.mp (localGaussian_variance_change hn y hγ hσ.le hbound hg)).1 + have hbj := mul_le_mul_of_nonneg_left hb (show 0 ≤ (n:ℝ)*j/2 by positivity) + dsimp [f,localExponent] + ring_nf at hh hbj ⊢ + linarith only [hh,hbj] + have he : (∫ g,f g ∂μ)=(n:ℝ)*j*varianceAverage y^2/2-2*η*(n:ℝ)- + (1+η⁻¹)*(ρ^2*(n:ℝ)+∫ g,vectorNorm (R g)^2 ∂μ)/σ^2-4*(n:ℝ)*j*σ/sqrt γ := by + have hfEq : f=fun g => ((n:ℝ)*j*varianceAverage y^2/2-2*η*(n:ℝ)- + (1+η⁻¹)*ρ^2*(n:ℝ)/σ^2-4*(n:ℝ)*j*σ/sqrt γ)- + ((1+η⁻¹)/σ^2)*vectorNorm (R g)^2 := by + funext g + dsimp [f] + ring + rw [hfEq,integral_sub (integrable_const _) (hiR.const_mul _),integral_const_mul] + simp only [integral_const,probReal_univ,one_smul] + ring + rw [he] at hmono + apply le_trans ?_ hmono + have hh := mul_le_mul_of_nonneg_left hR (show 0 ≤ (1+η⁻¹)/σ^2 by positivity) + have hsσ : σ ≠ 0 := hσ.ne' + have heq : (1+η⁻¹)*(ρ^2*(n:ℝ)+6*(8*(j+K)^2+128*j^2)*(n:ℝ)*σ^4/γ^2)/σ^2= + (n:ℝ)*(1+η⁻¹)*(ρ^2/σ^2+6*(8*(j+K)^2+128*j^2)*σ^2/γ^2) := by + field_simp + ring_nf at hh heq ⊢ + linarith only [hh,heq] + +theorem localGaussian_jensen {n : ℕ} (hn : 0 < n) (j σ : ℝ) + (J U : Matrix (Fin n) (Fin n) ℝ) (h y : Field n) : + exp (∫ g,localExponent j σ J U h y g ∂cond (gaussianCoordinates (Fin n)) (localGaussianBall n)) ≤ + ∫ g,exp (localExponent j σ J U h y g) ∂cond (gaussianCoordinates (Fin n)) (localGaussianBall n) := by + let := cond_isProbabilityMeasure (localGaussianBall_ne_zero hn) + exact convexOn_exp.map_integral_le continuous_exp.continuousOn isClosed_univ + (ae_of_all _ (fun _ => mem_univ _)) + (localGaussian_cond_integrable hn (localExponent_continuous _ _ _ _ _ _)) + (localGaussian_cond_integrable hn (continuous_exp.comp (localExponent_continuous _ _ _ _ _ _))) + +end SKGap +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/LocalVolumeFull.lean b/lean/OAI/Probability/SKGap/Localization/LocalVolumeFull.lean new file mode 100644 index 0000000000000000000000000000000000000000..19b697a1357c2815546199f3549c904169b71608 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/LocalVolumeFull.lean @@ -0,0 +1,97 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.LocalVolumeChange + +namespace OAI + +section +noncomputable section +namespace SKGap +open MeasureTheory ProbabilityTheory Matrix Real Set Filter +open scoped BigOperators ENNReal NNReal + +lemma nonnegative_continuous_small {f : ℝ → ℝ} (hf : ContinuousAt f 0) (hzero : f 0=0) + {ε : ℝ} (hε : 0 < ε) : ∃ δ : ℝ,0 < δ ∧ ∀ x : ℝ,0 ≤ x → x < δ → f x < ε := by + have hh : ∀ᶠ x in nhds (0:ℝ), f x < ε := + hf.tendsto.eventually_lt_const (by rw [hzero]; exact hε) + obtain ⟨δ,hδ,hnear⟩ := Metric.eventually_nhds_iff.mp hh + refine ⟨δ,hδ,fun x hx hxd => hnear ?_⟩ + simpa only [Real.dist_eq,sub_zero,abs_of_nonneg hx] using hxd + +lemma absorb_three_quarters_exp {ε : ℝ} (hε : 0 < ε) : + ∃ N : ℕ, 0 < N ∧ ∀ n : ℕ,N ≤ n → + exp (-ε*(n:ℝ)) ≤ (3/4:ℝ)*exp (-(3*ε/4)*(n:ℝ)) := by + obtain ⟨N,hN⟩ := exists_nat_ge (4/ε) + refine ⟨max N 1,by omega,?_⟩ + intro n hn + have hnn : 4/ε ≤ (n:ℝ) := hN.trans (by exact_mod_cast (le_trans (le_max_left N 1) hn)) + have hx : 1 ≤ ε*(n:ℝ)/4 := by + have hh := (div_le_iff₀ hε).mp hnn + nlinarith + have he : exp (-(ε*(n:ℝ)/4)) ≤ 3/4 := by + rw [exp_neg,inv_eq_one_div,div_le_iff₀ (exp_pos _)] + have hh := add_one_le_exp (ε*(n:ℝ)/4) + nlinarith only [hh,hx] + have hsplit : -ε*(n:ℝ)=-(ε*(n:ℝ)/4)+(-(3*ε/4)*(n:ℝ)) := by ring + rw [hsplit,exp_add] + exact mul_le_mul_of_nonneg_right he (exp_pos _).le + +theorem local_volume_uniform {j K r ε : ℝ} (hj : 0 ≤ j) (hK : 0 ≤ K) + (hr : 0 < r) (hε : 0 < ε) : + ∃ ε₁ : ℝ,0 < ε₁ ∧ ∀ γ : ℝ,0 < γ → + ∃ σ₀ : ℝ,0 < σ₀ ∧ ∀ σ : ℝ,0 < σ → σ < σ₀ → + ∃ ρ : ℝ,0 < ρ ∧ ∃ N : ℕ,0 < N ∧ ∀ n,N ≤ n → + ∀ J : Matrix (Fin n) (Fin n) ℝ, + (∀ z : Field n,vectorNorm (J*ᵥz) ≤ K*vectorNorm z) → + ∀ h y : Field n,∀ E : Set (Field n),MeasurableSet E → + (∀ d : Field n,vectorNorm d ≤ r*sqrt (n:ℝ) → y+d ∈ E) → + log ((fieldJacobian j J y)ᵀ*(fieldJacobian j J y)+γ • 1).det ≤ + (n:ℝ)*(j*varianceAverage y^2+ε₁) → + vectorNorm (tapField j J h y) ≤ ρ*sqrt (n:ℝ) → + ENNReal.ofReal (exp (-ε*(n:ℝ))) ≤ localVolume j σ J h E := by + let η := ε/16 + have hη : 0 < η := by dsimp [η]; positivity + refine ⟨ε/4,by positivity,?_⟩ + intro γ hγ + let noise : ℝ → ℝ := fun σ => (1+η⁻¹)*(6*(8*(j+K)^2+128*j^2)*σ^2/γ^2)+4*j*σ/sqrt γ + have hncont : ContinuousAt noise 0 := by dsimp [noise]; fun_prop + have hnzero : noise 0=0 := by simp [noise] + obtain ⟨a,ha,hasmall⟩ := nonnegative_continuous_small hncont hnzero (show 0 < ε/4 by positivity) + refine ⟨min a (r*sqrt γ/2),lt_min ha (by positivity),?_⟩ + intro σ hσ hσ₀ + have hsnoise : noise σ < ε/4 := hasmall σ hσ.le (lt_of_lt_of_le hσ₀ (min_le_left _ _)) + have hsr : 2*σ/sqrt γ ≤ r := by + apply (div_le_iff₀ (sqrt_pos.mpr hγ)).mpr + have hh := lt_of_lt_of_le hσ₀ (min_le_right _ _) + linarith + let residual : ℝ → ℝ := fun ρ => (1+η⁻¹)*ρ^2/σ^2 + have hrcont : ContinuousAt residual 0 := by dsimp [residual]; fun_prop + have hrzero : residual 0=0 := by simp [residual] + obtain ⟨b,hb,hbsmall⟩ := nonnegative_continuous_small hrcont hrzero (show 0 < ε/4 by positivity) + obtain ⟨N,hN,habsorb⟩ := absorb_three_quarters_exp hε + refine ⟨b/2,by positivity,N,hN,?_⟩ + intro n hn J hJ h y E hE hball hdet hres + have hresmall : residual (b/2) < ε/4 := hbsmall _ (by positivity) (by linarith) + have hloss : (ε/4)/2+2*η+ + (1+η⁻¹)*((b/2)^2/σ^2+6*(8*(j+K)^2+128*j^2)*σ^2/γ^2)+4*j*σ/sqrt γ ≤ 3*ε/4 := by + dsimp [noise] at hsnoise + dsimp [residual] at hresmall + dsimp [η] at * + ring_nf at hsnoise hresmall ⊢ + linarith only [hsnoise,hresmall] + have hnn : (0:ℝ) ≤ n := Nat.cast_nonneg _ + calc + _ ≤ ENNReal.ofReal ((3/4:ℝ)*exp (-(3*ε/4)*(n:ℝ))) := + ENNReal.ofReal_le_ofReal (habsorb n hn) + _ ≤ ENNReal.ofReal ((3/4:ℝ)*exp (-(n:ℝ)*((ε/4)/2+2*η+ + (1+η⁻¹)*((b/2)^2/σ^2+6*(8*(j+K)^2+128*j^2)*σ^2/γ^2)+4*j*σ/sqrt γ))) := by + apply ENNReal.ofReal_le_ofReal + apply mul_le_mul_of_nonneg_left (exp_le_exp.mpr ?_) (by norm_num) + nlinarith only [mul_le_mul_of_nonneg_left hloss hnn] + _ ≤ _ := local_volume_quantitative (hN.trans_le hn) hj hK hγ hσ hη (by positivity) + J hJ h y hE hball hsr hdet hres + +end SKGap +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/LocalWeakBase.lean b/lean/OAI/Probability/SKGap/Localization/LocalWeakBase.lean new file mode 100644 index 0000000000000000000000000000000000000000..5c6bc79cbb044fe0d6eb97a1b21f2828a013419c --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/LocalWeakBase.lean @@ -0,0 +1,78 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.ResidualMultiplier + +namespace OAI + +section + +noncomputable section +open scoped BigOperators +namespace SKGapCutoff.Static +open Classical +variable {n : ℕ} + +def flipNeighborhood (E : Set (Spin n)) : Set (Spin n) := + {x | x∈E ∨ ∃i,flip x i∈E} + +def edgeCut (E : Set (Spin n)) (U : VectorFields n) : VectorFields n := + fun x i=>if x∈E ∨ flip x i∈E then U x i else 0 + +lemma halfDiff_edgeCut (E : Set (Spin n)) (U : VectorFields n) (x : Spin n) (i : Fin n) : + halfDiff i (fun y=>edgeCut E U y i) x= + if x∈E ∨ flip x i∈E then halfDiff i (fun y=>U y i) x else 0 := by + classical + by_cases he : x∈E ∨ flip x i∈E + · have hf : flip x i∈E ∨ x∈E:=he.symm + simp [halfDiff_as_flip,edgeCut,he,hf] + · have hf : ¬(flip x i∈E ∨ x∈E):=by tauto + simp [halfDiff_as_flip,edgeCut,he,hf] + +lemma edgeCut_size (E : Set (Spin n)) (U : VectorFields n) {B : ℝ} + (hU : ∀x∈flipNeighborhood E,∑i,(U x i)^2≤B^2) : + ∀x,∑i,(edgeCut E U x i)^2≤B^2 := by + classical + intro x + by_cases hx:x∈flipNeighborhood E + · apply (Finset.sum_le_sum (fun i _=>show (edgeCut E U x i)^2≤(U x i)^2 by + dsimp [edgeCut]; split_ifs <;> simp [sq_nonneg])).trans (hU x hx) + · have hh : ∀i,¬(x∈E ∨ flip x i∈E):=by + intro i hi; exact hx (hi.elim Or.inl (fun h=>Or.inr ⟨i,h⟩)) + simp [edgeCut,hh,sq_nonneg] + +lemma edgeCut_diagonal (E : Set (Spin n)) (U : VectorFields n) {A : ℝ} + (hA : 0≤A) (hD : ∀x∈flipNeighborhood E,∑i,|halfDiff i (fun y=>U y i) x|≤A) : + ∀x,∑i,|halfDiff i (fun y=>edgeCut E U y i) x|≤A := by + classical + intro x + by_cases hx:x∈flipNeighborhood E + · apply (Finset.sum_le_sum (fun i _=>show + |halfDiff i (fun y=>edgeCut E U y i) x|≤|halfDiff i (fun y=>U y i) x| by + rw [halfDiff_edgeCut]; split_ifs <;> simp)).trans (hD x hx) + · have hh : ∀i,¬(x∈E ∨ flip x i∈E):=by + intro i hi; exact hx (hi.elim Or.inl (fun h=>Or.inr ⟨i,h⟩)) + simpa only [halfDiff_edgeCut,hh,↓reduceIte,abs_zero,Finset.sum_const_zero] using hA + +theorem local_signed_base_star (P : Spin n→ℝ) (hP : ∀x,0≤P x) (hp : ∑x,P x=1) + (E : Set (Spin n)) (G : Observables n) (U : VectorFields n) {A B : ℝ} + (hA : 0≤A) (hB : 0≤B) (hG : ∀x,x∉E→G x=0) + (hD : ∀x∈flipNeighborhood E,∑i,|halfDiff i (fun y=>U y i) x|≤A) + (hU : ∀x∈flipNeighborhood E,∑i,(U x i)^2≤B^2) : + |∑x,P x*G x*∑i,(spin x i-conditionalMean P x i)*U x i|≤ + (2*B+5*A)*starNorm P G := by + classical + have hh:=signed_base_star P hP hp G (edgeCut E U) hA hB (edgeCut_diagonal E U hA hD) + (edgeCut_size E U hU) + convert hh using 1 + congr 1 + apply Finset.sum_congr rfl + intro x _ + by_cases hx:x∈E + · simp [edgeCut,hx] + · simp [hG x hx] + +end SKGapCutoff.Static + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/LocalWhitening.lean b/lean/OAI/Probability/SKGap/Localization/LocalWhitening.lean new file mode 100644 index 0000000000000000000000000000000000000000..53ab758cae22d3e6b2831e3f10454950c5cc5d5a --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/LocalWhitening.lean @@ -0,0 +1,142 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.TAPVectorTaylor +import OAI.Probability.SKGap.Matrix.MatrixWhitening + +namespace OAI + +section +noncomputable section +namespace SKGap +open Matrix Real +open scoped BigOperators MatrixOrder + +lemma vectorNorm_sq_dot {n : ℕ} (x : Field n) : vectorNorm x^2=x⬝ᵥx := by + rw [vectorNorm_sq] + simp only [vectorSqNorm,dotProduct,pow_two] + +lemma gram_energy {n : ℕ} (L : Matrix (Fin n) (Fin n) ℝ) (x : Field n) : + x⬝ᵥ((Lᵀ*L)*ᵥx)=vectorNorm (L*ᵥx)^2 := by + rw [← Matrix.mulVec_mulVec,Matrix.dotProduct_transpose_mulVec,vectorNorm_sq_dot] + +lemma regularizedGram_posDef {n : ℕ} (L : Matrix (Fin n) (Fin n) ℝ) + {γ : ℝ} (hγ : 0 < γ) : (Lᵀ*L+γ • (1 : Matrix (Fin n) (Fin n) ℝ)).PosDef := by + have hL : (Lᵀ*L).PosSemidef := by + simpa only [Matrix.conjTranspose_eq_transpose_of_trivial] using + Matrix.posSemidef_conjTranspose_mul_self L + exact Matrix.PosDef.posSemidef_add hL (Matrix.PosDef.one.smul hγ) + +lemma squareRoot_energy {n : ℕ} (L R : Matrix (Fin n) (Fin n) ℝ) + (hR : R.IsHermitian) (γ : ℝ) (hRR : R*R=Lᵀ*L+γ • 1) (x : Field n) : + vectorNorm (R*ᵥx)^2=vectorNorm (L*ᵥx)^2+γ*vectorNorm x^2 := by + have ht : Rᵀ=R := hR.eq + rw [← gram_energy,ht,hRR,Matrix.add_mulVec,dotProduct_add,gram_energy, + Matrix.smul_mulVec,Matrix.one_mulVec,dotProduct_smul,smul_eq_mul] + simp only [vectorNorm_sq_dot] + +theorem localGaussian_whitening {n : ℕ} (L : Matrix (Fin n) (Fin n) ℝ) + {γ : ℝ} (hγ : 0 < γ) : + ∃ U : Matrix (Fin n) (Fin n) ℝ, U.IsHermitian ∧ IsUnit U.det ∧ + U*(Lᵀ*L+γ • 1)*U=1 ∧ + (∀ g : Field n, vectorNorm (L*ᵥ(U*ᵥg)) ≤ vectorNorm g) ∧ + (∀ g : Field n, vectorNorm (U*ᵥg) ≤ vectorNorm g/sqrt γ) := by + obtain ⟨R,hR,hRR,hu⟩ := positive_sqrt_data (regularizedGram_posDef L hγ) + have hi : R⁻¹.IsHermitian := by + change (R⁻¹)ᵀ=R⁻¹ + rw [Matrix.transpose_nonsing_inv,show Rᵀ=R from hR.eq] + refine ⟨R⁻¹,hi,?_,?_,?_,?_⟩ + · rw [Matrix.det_nonsing_inv,Ring.inverse_eq_inv] + exact hu.inv + · rw [← hRR] + simp only [← Matrix.mul_assoc,Matrix.nonsing_inv_mul _ hu,Matrix.one_mul, + Matrix.mul_nonsing_inv _ hu] + · intro g + have he := squareRoot_energy L R hR γ hRR (R⁻¹*ᵥg) + rw [Matrix.mulVec_mulVec,Matrix.mul_nonsing_inv _ hu,Matrix.one_mulVec] at he + exact (sq_le_sq₀ (vectorNorm_nonneg _) (vectorNorm_nonneg _)).mp + (by nlinarith [mul_nonneg hγ.le (sq_nonneg (vectorNorm (R⁻¹*ᵥg)))]) + · intro g + have he := squareRoot_energy L R hR γ hRR (R⁻¹*ᵥg) + rw [Matrix.mulVec_mulVec,Matrix.mul_nonsing_inv _ hu,Matrix.one_mulVec] at he + apply (le_div_iff₀ (sqrt_pos.mpr hγ)).mpr + apply (sq_le_sq₀ (mul_nonneg (vectorNorm_nonneg _) (sqrt_nonneg _)) (vectorNorm_nonneg _)).mp + rw [mul_pow,Real.sq_sqrt hγ.le] + nlinarith [sq_nonneg (vectorNorm (L*ᵥ(R⁻¹*ᵥg)))] + +lemma symmetric_row_sq_bound {n : ℕ} {U : Matrix (Fin n) (Fin n) ℝ} + (hU : U.IsHermitian) {c : ℝ} (hc : 0 ≤ c) + (hbound : ∀ g : Field n, vectorNorm (U*ᵥg) ≤ c*vectorNorm g) (i : Fin n) : + ∑ k,U i k^2 ≤ c^2 := by + let e : Field n := Pi.single i 1 + have he : vectorNorm e=1 := by + apply (sq_eq_sq₀ (vectorNorm_nonneg _) zero_le_one).mp + simp [vectorNorm_sq,vectorSqNorm,e,Pi.single_apply] + have hx : U*ᵥe=fun k => U i k := by + ext k + simp only [e,Matrix.mulVec_single,MulOpposite.op_one,one_smul,Matrix.col_apply] + simpa only [Matrix.conjTranspose_eq_transpose_of_trivial,Matrix.transpose_apply] using congrFun (congrFun hU.eq i) k + have hh := hbound e + rw [hx,he,mul_one] at hh + simpa only [vectorNorm_sq,vectorSqNorm] using + (sq_le_sq₀ (vectorNorm_nonneg _) hc).mpr hh + +end SKGap +end +end + +section +noncomputable section +namespace SKGap +open Matrix Real +open scoped BigOperators +attribute [local irreducible] vectorNorm varianceAverage varianceLinear magnetizationRemainder tapField fieldJacobian magnetization + +lemma vectorNorm_fourth_le {n : ℕ} (d : Field n) : + vectorNorm d^4 ≤ (n:ℝ)*∑ i,d i^4 := by + have hc := Finset.sum_mul_sq_le_sq_mul_sq Finset.univ (fun _ : Fin n => (1:ℝ)) (fun i => d i^2) + simp only [one_mul,one_pow,Finset.sum_const,Finset.card_univ,Fintype.card_fin,nsmul_eq_mul,mul_one, + ← pow_mul] at hc + rw [show vectorNorm d^4=(vectorNorm d^2)^2 by ring,vectorNorm_sq] + exact hc + +lemma tap_remainder_sq {n : ℕ} (hn : 0 < n) {j K : ℝ} + (hj : 0 ≤ j) (hK : 0 ≤ K) (J : Matrix (Fin n) (Fin n) ℝ) + (hJ : ∀ z : Field n, vectorNorm (J*ᵥz) ≤ K*vectorNorm z) (h y d : Field n) : + vectorNorm (tapField j J h (y+d)-tapField j J h y-(fieldJacobian j J y)*ᵥd)^2 ≤ + (8*(j+K)^2+128*j^2)*∑ i,d i^4 := by + have hn0 : (0:ℝ) < n := by exact_mod_cast hn + have hs : 0 ≤ ∑ i,d i^4 := Finset.sum_nonneg (fun i _ => by positivity) + have h1 := tap_remainder_norm hn hj hK J hJ h y d + have ha : 0 ≤ 2*(j+K)*sqrt (∑ i,d i^4) := by positivity + have hb : 0 ≤ (8*j/sqrt (n:ℝ))*vectorNorm d^2 := by positivity + have hsq := (sq_le_sq₀ (vectorNorm_nonneg _) (add_nonneg ha hb)).mpr h1 + have hcs : (2*(j+K)*sqrt (∑ i,d i^4)+(8*j/sqrt (n:ℝ))*vectorNorm d^2)^2 ≤ + 2*(2*(j+K)*sqrt (∑ i,d i^4))^2+2*((8*j/sqrt (n:ℝ))*vectorNorm d^2)^2 := by + nlinarith [sq_nonneg (2*(j+K)*sqrt (∑ i,d i^4)-(8*j/sqrt (n:ℝ))*vectorNorm d^2)] + have he : 2*(2*(j+K)*sqrt (∑ i,d i^4))^2+2*((8*j/sqrt (n:ℝ))*vectorNorm d^2)^2= + 8*(j+K)^2*(∑ i,d i^4)+(128*j^2/(n:ℝ))*vectorNorm d^4 := by + simp only [mul_pow,div_pow,Real.sq_sqrt hs,Real.sq_sqrt hn0.le] + ring + apply (hsq.trans hcs).trans + rw [he] + calc + _ ≤ 8*(j+K)^2*(∑ i,d i^4)+(128*j^2/(n:ℝ))*((n:ℝ)*∑ i,d i^4) := + add_le_add le_rfl (mul_le_mul_of_nonneg_left (vectorNorm_fourth_le d) (by positivity)) + _ = _ := by field_simp + +lemma varianceAverage_sq_difference {n : ℕ} (hn : 0 < n) (y d : Field n) : + |varianceAverage (y+d)^2-varianceAverage y^2| ≤ 4/sqrt (n:ℝ)*vectorNorm d := by + have hb := varianceAverage_bounds hn y + have hb' := varianceAverage_bounds hn (y+d) + rw [sq_sub_sq,abs_mul,abs_of_nonneg (add_nonneg hb'.1 hb.1)] + have hh := varianceAverage_difference hn y d + calc + _ ≤ 2*(2/sqrt (n:ℝ)*vectorNorm d) := mul_le_mul + (show varianceAverage (y+d)+varianceAverage y ≤ 2 by linarith) hh + (abs_nonneg _) (by norm_num) + _ = _ := by ring + +end SKGap +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/LogPartitionDeviationProbability.lean b/lean/OAI/Probability/SKGap/Localization/LogPartitionDeviationProbability.lean new file mode 100644 index 0000000000000000000000000000000000000000..6bac250f0adc52c8b450f9406e80364ac776842b --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/LogPartitionDeviationProbability.lean @@ -0,0 +1,82 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.CoordinateLipschitz + +namespace OAI + +section +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal +namespace SKGapCutoff +open ProbabilityTheory + +lemma log_partition_deviation_probability_le (β : ℝ) (hβ : β ^ 2 < 1) + {n : ℕ} (hn : 0 < n) {ε : ℝ} (hε : 0 < ε) : + (disorderLaw β n) {g | ε < |(Real.log (partition (sampledInteraction g)) - + Real.log (∫ h, partition (sampledInteraction h) ∂disorderLaw β n)) / n|} ≤ + ENNReal.ofReal (((β ^ 2 + 2 * β ^ 2 / (Real.sqrt (1 - β ^ 2) / 4)) * n + + 2 * (Real.log 2)^2) / (ε^2 * n^2)) := by + let μ := disorderLaw β n + let : IsProbabilityMeasure μ := by dsimp [μ, disorderLaw]; infer_instance + let c := Real.log (∫ g, partition (sampledInteraction g) ∂μ) + let Y := fun g : GaussianCoordinates n => (Real.log (partition (sampledInteraction g)) - c)^2 + have hY : Integrable Y μ := (memLp_log_partition β n |>.sub (memLp_const c)).integrable_sq + have hnR : 0 < (n : ℝ) := by exact_mod_cast hn + have hhR : 0 < ε^2 * (n : ℝ)^2 := mul_pos (sq_pos_of_pos hε) (sq_pos_of_pos hnR) + have hs := mul_meas_ge_le_integral_of_nonneg + (μ := μ) (f := Y) (Filter.Eventually.of_forall (fun g => sq_nonneg _)) hY (ε^2*n^2) + have hgsub : {g | ε < |(Real.log (partition (sampledInteraction g)) - c) / n|} ⊆ + {g | ε^2*(n : ℝ)^2 ≤ Y g} := by + intro g hg + change ε < |(Real.log (partition (sampledInteraction g)) - c) / n| at hg + rw [abs_div, abs_of_pos hnR, lt_div_iff₀ hnR] at hg + change _ ≤ (Real.log (partition (sampledInteraction g)) - c)^2 + have hsq := sq_le_sq₀ (by positivity : 0 ≤ ε * (n : ℝ)) (abs_nonneg _) |>.mpr (le_of_lt hg) + simpa only [mul_pow, sq_abs] using hsq + have hreal := mul_le_mul_of_nonneg_left (measureReal_mono (μ := μ) hgsub) (le_of_lt hhR) + have hmoment := second_moment_log_partition_centered_le β hβ hn + have ht := hreal.trans (hs.trans hmoment) + rw [mul_comm (ε^2*(n : ℝ)^2), ← le_div_iff₀ hhR] at ht + rw [← ENNReal.ofReal_toReal (measure_ne_top μ _)] + exact ENNReal.ofReal_le_ofReal ht + +lemma log_partition_annealed_difference_limit (β : ℝ) (hβ : β ^ 2 < 1) : + DisorderLimit β (fun n J => (Real.log (partition J) - + Real.log (∫ h, partition (sampledInteraction h) ∂disorderLaw β n)) / n) 0 := by + intro ε hε + let A := β^2 + 2 * β^2 / (Real.sqrt (1-β^2)/4) + let B := 2 * (Real.log 2)^2 + have hi : Tendsto (fun n : ℕ => (n : ℝ)⁻¹) atTop (nhds 0) := + tendsto_inv_atTop_zero.comp tendsto_natCast_atTop_atTop + have hlim : Tendsto (fun n : ℕ => (A/ε^2) * (n : ℝ)⁻¹ + + (B/ε^2) * ((n : ℝ)⁻¹)^2) atTop (nhds 0) := by + simpa using (hi.const_mul (A/ε^2)).add ((hi.pow 2).const_mul (B/ε^2)) + have heq : ∀ᶠ n : ℕ in atTop, (A * n + B)/(ε^2*(n : ℝ)^2) = + (A/ε^2) * (n : ℝ)⁻¹ + (B/ε^2) * ((n : ℝ)⁻¹)^2 := by + filter_upwards [eventually_ge_atTop 1] with n hn + have hnR : (n : ℝ) ≠ 0 := by exact_mod_cast (by omega : n ≠ 0) + field_simp + have hlim' : Tendsto (fun n : ℕ => ENNReal.ofReal ((A*n+B)/(ε^2*(n : ℝ)^2))) + atTop (nhds 0) := by + have hreal := hlim.congr' (heq.mono fun _ h => h.symm) + simpa only [Function.comp_def, ENNReal.ofReal_zero] using + ENNReal.continuous_ofReal.continuousAt.tendsto.comp hreal + apply tendsto_of_tendsto_of_tendsto_of_le_of_le' tendsto_const_nhds hlim' + (Eventually.of_forall (fun _ => bot_le)) + filter_upwards [eventually_ge_atTop 1] with n hn + simpa only [sub_zero] using log_partition_deviation_probability_le β hβ (by omega) hε + +end SKGapCutoff + +open MeasureTheory ProbabilityTheory +open scoped BigOperators NNReal ENNReal + +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/LogQuadratic.lean b/lean/OAI/Probability/SKGap/Localization/LogQuadratic.lean new file mode 100644 index 0000000000000000000000000000000000000000..b59c8bc7f1b9c8af038cec41a99d340cbd67deba --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/LogQuadratic.lean @@ -0,0 +1,504 @@ +import Mathlib +import OAI.Probability.SKGap.Model + +namespace OAI + +section +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open scoped BigOperators +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open scoped BigOperators +open scoped BigOperators NNReal ENNReal +open MeasureTheory Metric Set +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators NNReal ENNReal Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Set +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators ENNReal NNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Matrix +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators ENNReal NNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal +open scoped BigOperators +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise NNReal ENNReal +open scoped BigOperators +open Filter Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal Topology +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Set Matrix +open scoped BigOperators NNReal ENNReal Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open Filter MeasureTheory ProbabilityTheory +open scoped Topology NNReal ENNReal +namespace SKGapCutoff.Clock + +noncomputable def logQuadratic : ℝ → ℝ := + Function.update (fun x => (Real.log (1+x)-x)/x^2) 0 (-(1/2:ℝ)) + +lemma logQuadratic_mul_sq (x : ℝ) : + logQuadratic x*x^2 = Real.log (1+x)-x := by + classical + by_cases hx : x=0 + · subst x + simp [logQuadratic] + · simp only [logQuadratic, Function.update_of_ne hx] + exact div_mul_cancel₀ _ (pow_ne_zero 2 hx) + +lemma continuousAt_logQuadratic : ContinuousAt logQuadratic 0 := by + classical + apply continuousAt_update_same.mpr + have hdom : ∀ᶠ x : ℝ in 𝓝[≠] 0, 0 < 1+x := by + filter_upwards [(eventually_gt_nhds (by norm_num : (-1:ℝ)<0)).filter_mono nhdsWithin_le_nhds] + with x hx + linarith + have hne : ∀ᶠ x : ℝ in 𝓝[≠] 0, x ≠ 0 := self_mem_nhdsWithin + apply HasDerivAt.lhopital_zero_nhdsNE + (f' := fun x => 1/(1+x)-1) (g' := fun x => 2*x) + · filter_upwards [hdom] with x hx + exact ((hasDerivAt_id x).const_add 1 |>.log hx.ne').sub (hasDerivAt_id x) + · exact Filter.Eventually.of_forall fun x => by + convert! (hasDerivAt_id x).mul (hasDerivAt_id x) using 1 + · ext t + simp [pow_two] + · simp [two_mul] + · filter_upwards [hne] with x hx + exact mul_ne_zero (by norm_num) hx + · have h : Tendsto (fun x : ℝ => Real.log (1+x)-x) (𝓝 0) (𝓝 0) := by + have hc : ContinuousAt (fun x : ℝ => Real.log (1+x)-x) 0 := by + apply ContinuousAt.sub + · apply ContinuousAt.log + · fun_prop + · norm_num + · fun_prop + simpa using hc.tendsto + exact h.mono_left nhdsWithin_le_nhds + · have hc : ContinuousAt (fun x : ℝ => x^2) 0 := by fun_prop + simpa using hc.tendsto.mono_left nhdsWithin_le_nhds + · have ht : Tendsto (fun x : ℝ => -1/(2*(1+x))) (𝓝[≠] 0) (𝓝 (-(1/2:ℝ))) := by + have hc : ContinuousAt (fun x : ℝ => -1/(2*(1+x))) 0 := by + apply ContinuousAt.div <;> first | fun_prop | norm_num + convert hc.tendsto.mono_left nhdsWithin_le_nhds using 1; norm_num + apply ht.congr' + filter_upwards [hne,hdom] with x hx hd + field_simp + ring + +noncomputable def poissonMass (m : ℝ) (k : ℕ) : ℝ := + Real.exp (-m)*m^k/(k.factorial:ℝ) + +lemma poissonMass_stirling {m : ℝ} (hm : 0 < m) {k : ℕ} (hk : 0 < k) : + Real.sqrt k*poissonMass m k = + Real.exp ((k:ℝ)*(Real.log (m/k)-(m-k)/k))/ + (Real.sqrt 2*Stirling.stirlingSeq k) := by + have hk0 : (k:ℝ) ≠ 0 := by exact_mod_cast hk.ne' + have hkp : (0:ℝ) (m n-(k n:ℝ))/Real.sqrt (k n)) atTop (𝓝 z)) : + Tendsto (fun n => Real.sqrt (k n)*poissonMass (m n) (k n)) atTop + (𝓝 (Real.exp (-(z^2)/2)/(Real.sqrt 2*Real.sqrt Real.pi))) := by + have hkn : Tendsto (fun n => (k n:ℝ)) atTop atTop := + tendsto_natCast_atTop_atTop.comp hk + have hks : Tendsto (fun n => Real.sqrt (k n:ℝ)) atTop atTop := + Real.tendsto_sqrt_atTop.comp hkn + have hkpos : ∀ᶠ n in atTop, 0 < k n := hk.eventually (eventually_gt_atTop 0) + have hh : Tendsto (fun n => (m n-(k n:ℝ))/(k n:ℝ)) atTop (𝓝 0) := by + apply (hd.div_atTop hks).congr' + filter_upwards [hkpos] with n hn + have hn0 : (0:ℝ)≤k n := Nat.cast_nonneg _ + rw [div_div, Real.mul_self_sqrt hn0] + have hq : Tendsto (fun n => logQuadratic ((m n-(k n:ℝ))/(k n:ℝ))) atTop + (𝓝 (-(1/2:ℝ))) := by + have h := continuousAt_logQuadratic.tendsto.comp hh + simpa [Function.comp_def,logQuadratic] using h + have hprod := hq.mul (hd.pow 2) + have he : Tendsto (fun n => (k n:ℝ)*(Real.log (m n/k n)-(m n-k n)/k n)) + atTop (𝓝 (-(z^2)/2)) := by + have ht : (-(1/2:ℝ))*z^2 = -(z^2)/2 := by ring + rw [ht] at hprod + apply hprod.congr' + filter_upwards [hkpos] with n hn + have hn0 : (k n:ℝ) ≠ 0 := by exact_mod_cast hn.ne' + have hsn : Real.sqrt (k n:ℝ)^2 = k n := Real.sq_sqrt (Nat.cast_nonneg _) + have hlog : 1+(m n-(k n:ℝ))/(k n:ℝ) = m n/k n := by field_simp; ring + have h := logQuadratic_mul_sq ((m n-(k n:ℝ))/(k n:ℝ)) + rw [hlog] at h + rw [div_pow,hsn] + calc + _ = (k n:ℝ)*(logQuadratic ((m n-(k n:ℝ))/(k n:ℝ))* + ((m n-(k n:ℝ))/(k n:ℝ))^2) := by field_simp + _ = _ := by rw [h] + have hdnom : Tendsto (fun n => Real.sqrt 2*Stirling.stirlingSeq (k n)) atTop + (𝓝 (Real.sqrt 2*Real.sqrt Real.pi)) := + tendsto_const_nhds.mul (Stirling.tendsto_stirlingSeq_sqrt_pi.comp hk) + have heexp := Real.continuous_exp.continuousAt.tendsto.comp he + apply (heexp.div hdnom (by positivity)).congr' + filter_upwards [hm,hkpos] with n hn hnk + exact (poissonMass_stirling hn hnk).symm + +noncomputable def centralIndex (q x : ℝ) (M : ℕ) : ℕ := + ⌊q*(M:ℝ)+x*Real.sqrt M⌋₊ + +lemma center_ratio_tendsto (q x : ℝ) : + Tendsto (fun n : ℕ => (q*n+x*Real.sqrt n)/(n:ℝ)) atTop (𝓝 q) := by + have hs := Real.tendsto_sqrt_atTop.comp (tendsto_natCast_atTop_atTop (R := ℝ)) + have h : Tendsto (fun n : ℕ => q+x/Real.sqrt n) atTop (𝓝 q) := by + simpa using (tendsto_const_nhds.add (tendsto_const_nhds.div_atTop hs)) + apply h.congr' + filter_upwards [eventually_gt_atTop 0] with n hn + have hn0 : (n:ℝ) ≠ 0 := by exact_mod_cast hn.ne' + have hsn : Real.sqrt (n:ℝ) ≠ 0 := by positivity + have hsq := Real.sq_sqrt (Nat.cast_nonneg n) + field_simp + nlinarith [congrArg (fun t => x*t) hsq] + +lemma center_tendsto_atTop {q : ℝ} (hq : 0 < q) (x : ℝ) : + Tendsto (fun n : ℕ => q*n+x*Real.sqrt n) atTop atTop := by + have h := (center_ratio_tendsto q x).pos_mul_atTop hq + (tendsto_natCast_atTop_atTop (R := ℝ)) + apply h.congr' + filter_upwards [eventually_gt_atTop 0] with n hn + exact div_mul_cancel₀ _ (by exact_mod_cast hn.ne') + +lemma centralIndex_atTop {q : ℝ} (hq : 0 < q) (x : ℝ) : + Tendsto (centralIndex q x) atTop atTop := + tendsto_nat_floor_atTop.comp (center_tendsto_atTop hq x) + +lemma centralIndex_deviation {q : ℝ} (hq : 0 < q) (x : ℝ) : + Tendsto (fun n => ((centralIndex q x n:ℝ)-q*n)/Real.sqrt n) atTop (𝓝 x) := by + have hs := Real.tendsto_sqrt_atTop.comp (tendsto_natCast_atTop_atTop (R := ℝ)) + have hzero : Tendsto (fun n : ℕ => 1/Real.sqrt n) atTop (𝓝 0) := + tendsto_const_nhds.div_atTop hs + have hneg : Tendsto (fun n : ℕ => -(1/Real.sqrt n)) atTop (𝓝 0) := by + simpa using hzero.neg + have he : Tendsto (fun n => ((centralIndex q x n:ℝ)- + (q*n+x*Real.sqrt n))/Real.sqrt n) atTop (𝓝 0) := by + apply hneg.squeeze' tendsto_const_nhds + · filter_upwards [(center_tendsto_atTop hq x).eventually (eventually_ge_atTop 0), + eventually_gt_atTop 0] with n hn hn0 + have hspos : 0 < Real.sqrt (n:ℝ) := by positivity + have hh := Nat.lt_floor_add_one (q*n+x*Real.sqrt n) + change -(1/Real.sqrt (n:ℝ)) ≤ _ + rw [← neg_div] + apply div_le_div_of_nonneg_right _ hspos.le + dsimp [centralIndex] + linarith + · filter_upwards [(center_tendsto_atTop hq x).eventually (eventually_ge_atTop 0)] + with n hn + apply div_nonpos_of_nonpos_of_nonneg _ (Real.sqrt_nonneg _) + exact sub_nonpos.mpr (Nat.floor_le hn) + have htt : Tendsto (fun n => (((centralIndex q x n:ℝ)- + (q*n+x*Real.sqrt n))/Real.sqrt n)+x) atTop (𝓝 x) := by + simpa using he.add_const x + apply htt.congr' + filter_upwards [eventually_gt_atTop 0] with n hn + have hsn : Real.sqrt (n:ℝ) ≠ 0 := by positivity + field_simp + ring + +lemma centralIndex_ratio {q : ℝ} (hq : 0 < q) (x : ℝ) : + Tendsto (fun n => (centralIndex q x n:ℝ)/(n:ℝ)) atTop (𝓝 q) := by + have hs := Real.tendsto_sqrt_atTop.comp (tendsto_natCast_atTop_atTop (R := ℝ)) + have ht : Tendsto (fun n => q+(((centralIndex q x n:ℝ)-q*n)/Real.sqrt n)/Real.sqrt n) + atTop (𝓝 q) := by + simpa using tendsto_const_nhds.add ((centralIndex_deviation hq x).div_atTop hs) + apply ht.congr' + filter_upwards [eventually_gt_atTop 0] with n hn + have hn0 : (n:ℝ) ≠ 0 := by exact_mod_cast hn.ne' + rw [div_div, Real.mul_self_sqrt (Nat.cast_nonneg _)] + field_simp + ring + +theorem poisson_scaled_local {q : ℝ} (hq : 0 < q) (x y : ℝ) + (k : ℕ → ℕ) (hk : Tendsto k atTop atTop) + (hkr : Tendsto (fun n => (k n:ℝ)/(n:ℝ)) atTop (𝓝 q)) + (hkd : Tendsto (fun n => ((k n:ℝ)-q*n)/Real.sqrt n) atTop (𝓝 x)) : + Tendsto (fun n : ℕ => Real.sqrt (n:ℝ)* + poissonMass (q*n+y*Real.sqrt n) (k n)) atTop + (𝓝 (Real.exp (-((y-x)/Real.sqrt q)^2/2)/ + (Real.sqrt q*(Real.sqrt 2*Real.sqrt Real.pi)))) := by + have hratio : Tendsto (fun n => Real.sqrt (k n:ℝ)/Real.sqrt n) + atTop (𝓝 (Real.sqrt q)) := by + have hh := Real.continuous_sqrt.continuousAt.tendsto.comp hkr + simpa only [Function.comp_def,Real.sqrt_div (Nat.cast_nonneg _)] using hh + have hstd : Tendsto (fun n : ℕ => ((q*n+y*Real.sqrt n)-(k n:ℝ))/ + Real.sqrt (k n)) atTop (𝓝 ((y-x)/Real.sqrt q)) := by + have hh := ((tendsto_const_nhds (x := y)).sub hkd).div hratio + ((Real.sqrt_pos.2 hq).ne') + apply hh.congr' + filter_upwards [eventually_gt_atTop 0, hk.eventually (eventually_gt_atTop 0)] + with n hn hk0 + have hsn : Real.sqrt (n:ℝ) ≠ 0 := by positivity + have hsk : Real.sqrt (k n:ℝ) ≠ 0 := by positivity + change (y-((k n:ℝ)-q*n)/Real.sqrt n)/ + (Real.sqrt (k n:ℝ)/Real.sqrt n) = _ + field_simp + ring + have hp := poisson_local_limit hk + ((center_tendsto_atTop hq y).eventually (eventually_gt_atTop 0)) hstd + have ht := hp.div hratio ((Real.sqrt_pos.2 hq).ne') + have heconst : (Real.exp (-((y-x)/Real.sqrt q)^2/2)/ + (Real.sqrt 2*Real.sqrt Real.pi))/Real.sqrt q = + Real.exp (-((y-x)/Real.sqrt q)^2/2)/ + (Real.sqrt q*(Real.sqrt 2*Real.sqrt Real.pi)) := by ring + rw [heconst] at ht + apply ht.congr' + filter_upwards [hk.eventually (eventually_gt_atTop 0)] with n hn + have hsk : Real.sqrt (k n:ℝ) ≠ 0 := by positivity + change (Real.sqrt (k n:ℝ)*poissonMass _ _)/ + (Real.sqrt (k n:ℝ)/Real.sqrt n) = _ + field_simp + +theorem poisson_histogram_pointwise {q : ℝ} (hq : 0 < q) (x y : ℝ) : + Tendsto (fun n : ℕ => Real.sqrt (n:ℝ)* + poissonMass (q*n+y*Real.sqrt n) (centralIndex q x n)) atTop + (𝓝 (Real.exp (-((y-x)/Real.sqrt q)^2/2)/ + (Real.sqrt q*(Real.sqrt 2*Real.sqrt Real.pi)))) := + poisson_scaled_local hq x y (centralIndex q x) (centralIndex_atTop hq x) + (centralIndex_ratio hq x) (centralIndex_deviation hq x) + +noncomputable def binomialMass (q : ℝ) (M k : ℕ) : ℝ := + (M.choose k:ℝ)*q^k*(1-q)^(M-k) + +lemma binomialMass_poisson {q : ℝ} {M k : ℕ} (hk : k ≤ M) (hM : 0 < M) : + binomialMass q M k = + poissonMass (q*M) k*poissonMass ((1-q)*M) (M-k)/poissonMass M M := by + have hM0 : (M:ℝ) ≠ 0 := by exact_mod_cast hM.ne' + unfold binomialMass poissonMass + rw [Nat.cast_choose ℝ hk] + have he : Real.exp (-(q*(M:ℝ)))*Real.exp (-((1-q)*M)) = Real.exp (-(M:ℝ)) := by + rw [← Real.exp_add] + congr 1 + ring + have hp : (M:ℝ)^k*(M:ℝ)^(M-k) = (M:ℝ)^M := by + rw [← pow_add, Nat.add_sub_of_le hk] + simp only [mul_pow] + have hf1 : (k.factorial:ℝ) ≠ 0 := by positivity + have hf2 : ((M-k).factorial:ℝ) ≠ 0 := by positivity + have hf3 : (M.factorial:ℝ) ≠ 0 := by positivity + have he0 : Real.exp (-(M:ℝ)) ≠ 0 := Real.exp_ne_zero _ + field_simp + calc + _ = (M:ℝ)^M * Real.exp (-(M:ℝ)) *q^k*(1-q)^(M-k) := by ring + _ = _ := by rw [← hp, ← he]; ring + +lemma gaussian_formula {q : ℝ} (hq : 0 < q) (x y : ℝ) : + Real.exp (-((y-x)/Real.sqrt q)^2/2)/ + (Real.sqrt q*(Real.sqrt 2*Real.sqrt Real.pi)) = + gaussianPDFReal y ⟨q,hq.le⟩ x := by + change _ = (Real.sqrt (2*Real.pi*q))⁻¹ * Real.exp (-(x-y)^2/(2*q)) + rw [Real.sqrt_mul (mul_nonneg (by norm_num) Real.pi_pos.le), + Real.sqrt_mul (by norm_num : (0:ℝ)≤2)] + have he : -((y-x)/Real.sqrt q)^2/2 = -(x-y)^2/(2*q) := by + rw [div_pow, Real.sq_sqrt hq.le] + ring + rw [he] + ring + +lemma index_atTop_of_ratio {k : ℕ → ℕ} {q : ℝ} (hq : 0 < q) + (hkr : Tendsto (fun n => (k n:ℝ)/(n:ℝ)) atTop (𝓝 q)) : Tendsto k atTop atTop := by + apply (tendsto_natCast_atTop_iff (R := ℝ)).mp + apply (hkr.pos_mul_atTop hq (tendsto_natCast_atTop_atTop (R := ℝ))).congr' + filter_upwards [eventually_gt_atTop 0] with n hn + exact div_mul_cancel₀ _ (by exact_mod_cast hn.ne') + +lemma centralIndex_le {q : ℝ} (hql : 0 < q) (hqu : q < 1) (x : ℝ) : + ∀ᶠ n in atTop, centralIndex q x n ≤ n := by + filter_upwards [(centralIndex_ratio hql x).eventually (eventually_lt_nhds hqu), + eventually_gt_atTop 0] with n hn hn0 + have hnpos : (0:ℝ) < n := by exact_mod_cast hn0 + have hh := (div_lt_iff₀ hnpos).mp hn + have hh' : (centralIndex q x n:ℝ) < n := by simpa using hh + exact le_of_lt (by exact_mod_cast hh') + +lemma complementIndex_ratio {q : ℝ} (hql : 0 < q) (hqu : q < 1) (x : ℝ) : + Tendsto (fun n => ((n-centralIndex q x n:ℕ):ℝ)/(n:ℝ)) atTop (𝓝 (1-q)) := by + apply ((tendsto_const_nhds (x := (1:ℝ))).sub (centralIndex_ratio hql x)).congr' + filter_upwards [centralIndex_le hql hqu x,eventually_gt_atTop 0] with n hn hn0 + rw [Nat.cast_sub hn] + have hne : (n:ℝ) ≠ 0 := by exact_mod_cast hn0.ne' + field_simp + +lemma complementIndex_deviation {q : ℝ} (hql : 0 < q) (hqu : q < 1) (x : ℝ) : + Tendsto (fun n => (((n-centralIndex q x n:ℕ):ℝ)-(1-q)*n)/Real.sqrt n) + atTop (𝓝 (-x)) := by + apply (centralIndex_deviation hql x).neg.congr' + filter_upwards [centralIndex_le hql hqu x] with n hn + rw [Nat.cast_sub hn] + ring + +lemma gaussian_product_quotient {q : ℝ} (hql : 0 < q) (hqu : q < 1) (x : ℝ) : + gaussianPDFReal 0 ⟨q,hql.le⟩ x * + gaussianPDFReal 0 ⟨1-q,by linarith⟩ (-x) / + gaussianPDFReal 0 1 0 = + gaussianPDFReal 0 ⟨q*(1-q),mul_nonneg hql.le (by linarith)⟩ x := by + have hg1 : gaussianPDFReal 0 1 0 = 1/(Real.sqrt 2*Real.sqrt Real.pi) := by + norm_num [gaussianPDFReal, Real.sqrt_mul (by norm_num : (0:ℝ)≤2)] + rw [← gaussian_formula hql x 0, ← gaussian_formula (by linarith : 0 < 1-q) (-x) 0, + hg1, ← gaussian_formula (mul_pos hql (by linarith : 0 < 1-q)) x 0] + simp only [zero_sub, neg_div, neg_sq, neg_neg] + have hq0 : q ≠ 0 := hql.ne' + have hr0 : 1-q ≠ 0 := by linarith + have he : -(x/Real.sqrt q)^2/2 + -(x/Real.sqrt (1-q))^2/2 = + -(x/Real.sqrt (q*(1-q)))^2/2 := by + simp only [div_pow, Real.sq_sqrt hql.le, Real.sq_sqrt (show 0≤1-q by linarith), + Real.sq_sqrt (mul_nonneg hql.le (show 0≤1-q by linarith))] + field_simp + ring + rw [mul_div_assoc, div_div, div_mul_div_comm] + rw [← Real.exp_add] + simp only [← neg_div] + rw [he, Real.sqrt_mul hql.le] + have hs : Real.sqrt q ≠ 0 := by positivity + have hr : Real.sqrt (1-q) ≠ 0 := by positivity + have h2 : Real.sqrt (2:ℝ) ≠ 0 := by positivity + have hpi : Real.sqrt Real.pi ≠ 0 := by positivity + field_simp + +theorem binomial_histogram_pointwise {q : ℝ} (hql : 0 < q) (hqu : q < 1) (x : ℝ) : + Tendsto (fun n : ℕ => Real.sqrt (n:ℝ)*binomialMass q n (centralIndex q x n)) atTop + (𝓝 (gaussianPDFReal 0 ⟨q*(1-q),mul_nonneg hql.le (by linarith)⟩ x)) := by + have ha := poisson_scaled_local hql x 0 (centralIndex q x) (centralIndex_atTop hql x) + (centralIndex_ratio hql x) (centralIndex_deviation hql x) + have hb := poisson_scaled_local (by linarith : 0 < 1-q) (-x) 0 + (fun n => n-centralIndex q x n) + (index_atTop_of_ratio (by linarith) (complementIndex_ratio hql hqu x)) + (complementIndex_ratio hql hqu x) (complementIndex_deviation hql hqu x) + have hc := poisson_scaled_local (by norm_num : (0:ℝ)<1) 0 0 (fun n => n) tendsto_id + (by + apply tendsto_const_nhds.congr' + filter_upwards [eventually_gt_atTop 0] with n hn + exact (div_self (by exact_mod_cast hn.ne' : (n:ℝ) ≠ 0)).symm) + (by simp) + rw [gaussian_formula hql x 0] at ha + rw [gaussian_formula (by linarith : 0 < 1-q) (-x) 0] at hb + rw [gaussian_formula (by norm_num : (0:ℝ)<1) 0 0] at hc + have hc1 : (⟨(1:ℝ),by norm_num⟩ : ℝ≥0) = 1 := by rfl + rw [hc1] at hc + have hh := (ha.mul hb).div hc (gaussianPDFReal_pos 0 1 0 (by norm_num)).ne' + have heq : gaussianPDFReal 0 ⟨q,hql.le⟩ x * + gaussianPDFReal 0 ⟨1-q,by linarith⟩ (-x) / gaussianPDFReal 0 1 0 = + gaussianPDFReal 0 ⟨q*(1-q),mul_nonneg hql.le (by linarith)⟩ x := + gaussian_product_quotient hql hqu x + have hh' : Tendsto (fun n : ℕ => + (Real.sqrt (n:ℝ)*poissonMass (q*n+0*Real.sqrt n) (centralIndex q x n))* + (Real.sqrt (n:ℝ)*poissonMass ((1-q)*n+0*Real.sqrt n) (n-centralIndex q x n))/ + (Real.sqrt (n:ℝ)*poissonMass (1*n+0*Real.sqrt n) n)) atTop + (𝓝 (gaussianPDFReal 0 ⟨q,hql.le⟩ x * + gaussianPDFReal 0 ⟨1-q,by linarith⟩ (-x) / gaussianPDFReal 0 1 0)) := hh + rw [heq] at hh' + apply hh'.congr' + filter_upwards [centralIndex_le hql hqu x,eventually_gt_atTop 0] with n hn hn0 + simp only [zero_mul,add_zero,one_mul] + rw [binomialMass_poisson hn hn0] + have hs : Real.sqrt (n:ℝ) ≠ 0 := by positivity + field_simp + +end SKGapCutoff.Clock + +open Filter MeasureTheory ProbabilityTheory +open scoped Topology NNReal ENNReal + +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/Magnetization.lean b/lean/OAI/Probability/SKGap/Localization/Magnetization.lean new file mode 100644 index 0000000000000000000000000000000000000000..61396d7826156d18e032f1683dbc5e4e5dac196e --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/Magnetization.lean @@ -0,0 +1,429 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.Character + +namespace OAI + +section +open scoped BigOperators +namespace SKGapCutoff + +lemma one_add_pow_le_exp (q : ℝ) (hq : 0 ≤ q) (n : ℕ) : + (1 + q) ^ n ≤ Real.exp ((n : ℝ) * q) := by + rw [Real.exp_nat_mul] + exact pow_le_pow_left₀ (by linarith) (by linarith [Real.add_one_le_exp q]) _ + +lemma kernel_apply {n : ℕ} (A : Observables n →L[ℝ] Observables n) + (f : Observables n) (x : Spin n) : + ∑ y : Spin n, A (fun z => if z = y then 1 else 0) x * f y = A f x := by + have hf : (∑ y : Spin n, f y • (fun z => if z = y then (1 : ℝ) else 0)) = f := by + funext z + simp + calc + _ = A (∑ y : Spin n, f y • (fun z => if z = y then (1 : ℝ) else 0)) x := by + simp only [map_sum, map_smul, Finset.sum_apply, Pi.smul_apply, smul_eq_mul] + apply Finset.sum_congr rfl + intro y _ + ring + _ = A f x := by rw [hf] + +lemma generator_mul {n : ℕ} (J : Interaction n) (f g : Observables n) (x : Spin n) : + generator J (fun y => f y * g y) x = + f x * generator J g x + g x * generator J f x + + 2 * ∑ i, (1 - mean J x i * spin x i) * halfDiff i f x * halfDiff i g x := by + simp only [generator, halfDiff_mul, Finset.mul_sum, ← Finset.sum_add_distrib] + apply Finset.sum_congr rfl + intro i _ + have hx := spin_sq x i + linear_combination 2 * halfDiff i f x * halfDiff i g x * hx + +noncomputable def magnetization {n : ℕ} (x : Spin n) : ℝ := ∑ i, spin x i + +def plusSpin (n : ℕ) : Spin n := fun _ => true + +@[simp] lemma magnetization_plus (n : ℕ) : magnetization (plusSpin n) = (n : ℝ) := by + simp [magnetization, spin, plusSpin] + +@[simp] lemma character_singleton {n : ℕ} (i : Fin n) (x : Spin n) : + character {i} x = spin x i := by simp [character] + +@[simp] lemma halfDiff_magnetization {n : ℕ} (i : Fin n) (x : Spin n) : + halfDiff i magnetization x = 1 := by + change halfDiff i (fun y => ∑ j, spin y j) x = _ + simp only [halfDiff_sum, halfDiff_spin, Fintype.sum_ite_eq] + +lemma generator_zero_magnetization {n : ℕ} : + generatorCLM (0 : Interaction n) magnetization = (-1 : ℝ) • magnetization := by + funext x + change generator (0 : Interaction n) magnetization x = -1 * magnetization x + simp [generator, magnetization] + +noncomputable def centeredMagnetizationSq {n : ℕ} (x : Spin n) : ℝ := + magnetization x ^ 2 - (n : ℝ) + +lemma generator_zero_centeredMagnetizationSq {n : ℕ} : + generatorCLM (0 : Interaction n) centeredMagnetizationSq = + (-2 : ℝ) • centeredMagnetizationSq := by + funext x + have hg := generator_mul (0 : Interaction n) magnetization magnetization x + have hl : generator (0 : Interaction n) magnetization x = -magnetization x := by + have h := congrFun (generator_zero_magnetization (n := n)) x + change generator (0 : Interaction n) magnetization x = -1 * magnetization x at h + simpa only [neg_one_mul] using h + simp only [mean_zero, zero_mul, sub_zero, halfDiff_magnetization, mul_one, + Finset.sum_const, Finset.card_univ, Fintype.card_fin, nsmul_eq_mul, mul_one, hl] at hg + change generator (0 : Interaction n) centeredMagnetizationSq x = + -2 * centeredMagnetizationSq x + have heq : generator (0 : Interaction n) centeredMagnetizationSq x = + generator (0 : Interaction n) (fun y => magnetization y * magnetization y) x := by + change generator (0 : Interaction n) (fun y => magnetization y ^ 2 - (n : ℝ)) x = _ + simp only [generator, halfDiff_sub, halfDiff_const, sub_zero, pow_two] + rw [heq, hg] + unfold centeredMagnetizationSq + ring + +lemma semigroup_zero_magnetization {n : ℕ} (t : ℝ) : + semigroup (0 : Interaction n) t magnetization = Real.exp (-t) • magnetization := by + apply exp_apply_of_eigenvector + rw [smul_apply, generator_zero_magnetization, smul_smul] + simp + +lemma semigroup_zero_centeredMagnetizationSq {n : ℕ} (t : ℝ) : + semigroup (0 : Interaction n) t centeredMagnetizationSq = + Real.exp (-2 * t) • centeredMagnetizationSq := by + apply exp_apply_of_eigenvector + rw [smul_apply, generator_zero_centeredMagnetizationSq, smul_smul] + congr 1 + ring + +lemma pow_apply_of_eigenvector {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] + (A : E →L[ℝ] E) (f : E) (a : ℝ) (ha : A f = a • f) (k : ℕ) : + (A ^ k) f = a ^ k • f := by + induction k with + | zero => simp + | succ k ih => rw [pow_succ', mul_apply_eq_comp, ih, map_smul, ha, smul_smul, pow_succ] + +lemma attempt_pow_zero_magnetization {n : ℕ} (k : ℕ) : + (attemptLM (0 : Interaction n) ^ k) magnetization = + (1 - (n : ℝ)⁻¹) ^ k • magnetization := by + apply pow_apply_of_eigenvector + change magnetization + (n : ℝ)⁻¹ • generatorCLM (0 : Interaction n) magnetization = _ + rw [generator_zero_magnetization, smul_smul] + module + +lemma attempt_pow_zero_centeredMagnetizationSq {n : ℕ} (k : ℕ) : + (attemptLM (0 : Interaction n) ^ k) centeredMagnetizationSq = + (1 - 2 / (n : ℝ)) ^ k • centeredMagnetizationSq := by + apply pow_apply_of_eigenvector + change centeredMagnetizationSq + + (n : ℝ)⁻¹ • generatorCLM (0 : Interaction n) centeredMagnetizationSq = _ + rw [generator_zero_centeredMagnetizationSq, smul_smul] + module + +lemma uniform_magnetization_second_moment (n : ℕ) : + ∑ x : Spin n, gibbs (0 : Interaction n) x * magnetization x ^ 2 = (n : ℝ) := by + have hinner (i j : Fin n) : (∑ x : Spin n, spin x i * spin x j) = + if i = j then (2 : ℝ) ^ n else 0 := by + simpa only [character_singleton, Finset.singleton_inj] using character_inner {i} {j} + simp only [gibbs_zero, ← Finset.mul_sum] + have hsum : (∑ x : Spin n, magnetization x ^ 2) = (n : ℝ) * (2 : ℝ) ^ n := by + simp only [magnetization, pow_two, Finset.sum_mul_sum] + rw [Finset.sum_comm] + simp_rw [Finset.sum_comm (s := (Finset.univ : Finset (Spin n))), hinner, + Fintype.sum_ite_eq] + simp + rw [hsum] + field_simp + +lemma totalVariation_nonneg {n : ℕ} (p q : Spin n → ℝ) : 0 ≤ totalVariation p q := + div_nonneg (Finset.sum_nonneg (fun _ _ => abs_nonneg _)) (by norm_num) + +lemma totalVariation_le_one {n : ℕ} (p q : Spin n → ℝ) + (hp : ∀ x, 0 ≤ p x) (hq : ∀ x, 0 ≤ q x) (hp1 : ∑ x, p x = 1) + (hq1 : ∑ x, q x = 1) : totalVariation p q ≤ 1 := by + have hs : ∑ x, |p x - q x| ≤ ∑ x, (p x + q x) := by + apply Finset.sum_le_sum + intro x _ + exact abs_le.mpr ⟨by linarith [hp x, hq x], by linarith [hp x, hq x]⟩ + rw [Finset.sum_add_distrib, hp1, hq1] at hs + unfold totalVariation + linarith + +lemma event_difference_le_totalVariation {n : ℕ} (p q : Spin n → ℝ) + (hpq : ∑ x, p x = ∑ x, q x) (A : Spin n → Prop) [DecidablePred A] : + (∑ x, if A x then p x else 0) - (∑ x, if A x then q x else 0) ≤ + totalVariation p q := by + have h (x : Spin n) : + 2 * ((if A x then p x else 0) - (if A x then q x else 0)) ≤ + |p x - q x| + (p x - q x) := by + split_ifs <;> linarith [le_abs_self (p x - q x), neg_le_abs (p x - q x)] + have hs := Finset.sum_le_sum (fun x (_ : x ∈ (Finset.univ : Finset (Spin n))) => h x) + simp only [← Finset.mul_sum, Finset.sum_sub_distrib, Finset.sum_add_distrib, hpq, + sub_self, add_zero] at hs + unfold totalVariation + linarith + +lemma totalVariation_lower_from_quadratic_test {n : ℕ} (p q f : Spin n → ℝ) + (hp : ∀ x, 0 ≤ p x) (hq : ∀ x, 0 ≤ q x) + (hp1 : ∑ x, p x = 1) (hq1 : ∑ x, q x = 1) + (m V : ℝ) (hm : 0 < m) + (hpV : ∑ x, p x * (f x - m) ^ 2 ≤ V) + (hqV : ∑ x, q x * f x ^ 2 ≤ V) : + m ^ 2 * (1 - totalVariation p q) ≤ 8 * V := by + let A : Spin n → Prop := fun x => m / 2 ≤ f x + have hP (x : Spin n) : + (m ^ 2 / 4) * (p x - if A x then p x else 0) ≤ p x * (f x - m) ^ 2 := by + by_cases hx : A x + · simp only [hx, ↓reduceIte, sub_self, mul_zero] + exact mul_nonneg (hp x) (sq_nonneg _) + · have hfx : f x < m / 2 := lt_of_not_ge hx + simp only [hx, ↓reduceIte, sub_zero] + have hs : m ^ 2 / 4 ≤ (f x - m) ^ 2 := by nlinarith [sq_nonneg (f x - m / 2)] + simpa only [mul_comm] using mul_le_mul_of_nonneg_left hs (hp x) + have hQ (x : Spin n) : + (m ^ 2 / 4) * (if A x then q x else 0) ≤ q x * f x ^ 2 := by + by_cases hx : A x + · have hfx : m / 2 ≤ f x := hx + simp only [hx, ↓reduceIte] + have hs : m ^ 2 / 4 ≤ f x ^ 2 := by nlinarith [sq_nonneg (f x - m / 2)] + simpa only [mul_comm] using mul_le_mul_of_nonneg_left hs (hq x) + · simp only [hx, ↓reduceIte, mul_zero] + exact mul_nonneg (hq x) (sq_nonneg _) + have hpbd := (Finset.sum_le_sum (fun x (_ : x ∈ (Finset.univ : Finset (Spin n))) => hP x)).trans hpV + have hqbd := (Finset.sum_le_sum (fun x (_ : x ∈ (Finset.univ : Finset (Spin n))) => hQ x)).trans hqV + simp only [← Finset.mul_sum, Finset.sum_sub_distrib, hp1] at hpbd + simp only [← Finset.mul_sum] at hqbd + have hd := event_difference_le_totalVariation p q (hp1.trans hq1.symm) A + have hd' := mul_le_mul_of_nonneg_left hd (show 0 ≤ m ^ 2 / 4 by positivity) + nlinarith + +lemma quadratic_centered_identity {n : ℕ} (p f : Spin n → ℝ) (m b a : ℝ) + (hp : ∑ y, p y = 1) (hm : ∑ y, p y * f y = m) + (hs : ∑ y, p y * (f y ^ 2 - b) = a) : + ∑ y, p y * (f y - m) ^ 2 = b + a - m ^ 2 := by + have he (y : Spin n) : p y * (f y - m) ^ 2 = + p y * (f y ^ 2 - b) - 2 * m * (p y * f y) + (b + m ^ 2) * p y := by ring + simp_rw [he] + rw [Finset.sum_add_distrib, Finset.sum_sub_distrib, ← Finset.mul_sum, + ← Finset.mul_sum, hs, hm, hp] + ring + +lemma continuous_zero_variance {n : ℕ} (t : ℝ) : + ∑ y, continuousKernel (0 : Interaction n) t (plusSpin n) y * + (magnetization y - (n : ℝ) * Real.exp (-t)) ^ 2 ≤ (n : ℝ) := by + have hm : ∑ y, continuousKernel (0 : Interaction n) t (plusSpin n) y * + magnetization y = (n : ℝ) * Real.exp (-t) := by + change (∑ y, semigroup (0 : Interaction n) t (fun z => if z = y then 1 else 0) + (plusSpin n) * magnetization y) = _ + rw [kernel_apply, semigroup_zero_magnetization] + simp [mul_comm] + have hs : ∑ y, continuousKernel (0 : Interaction n) t (plusSpin n) y * + (magnetization y ^ 2 - (n : ℝ)) = + Real.exp (-2 * t) * ((n : ℝ) ^ 2 - n) := by + change (∑ y, semigroup (0 : Interaction n) t (fun z => if z = y then 1 else 0) + (plusSpin n) * centeredMagnetizationSq y) = _ + rw [kernel_apply, semigroup_zero_centeredMagnetizationSq] + simp [centeredMagnetizationSq] + rw [quadratic_centered_identity _ _ _ _ _ (continuousKernel_sum _ _ _) hm hs] + have he : Real.exp (-2 * t) = Real.exp (-t) ^ 2 := by + rw [← Real.exp_nat_mul]; congr 1; ring + rw [he] + nlinarith [mul_nonneg (Nat.cast_nonneg n) (sq_nonneg (Real.exp (-t)))] + +lemma discrete_zero_variance {n : ℕ} (hn : 2 ≤ n) (k : ℕ) : + ∑ y, discreteKernel (0 : Interaction n) k (plusSpin n) y * + (magnetization y - (n : ℝ) * (1 - (n : ℝ)⁻¹) ^ k) ^ 2 ≤ (n : ℝ) := by + have hn' : (2 : ℝ) ≤ n := by exact_mod_cast hn + have hn0 : (0 : ℝ) < n := by linarith + have hi : 0 < (n : ℝ)⁻¹ := inv_pos.mpr hn0 + have hi1 : (n : ℝ)⁻¹ ≤ 1 := (inv_le_one₀ hn0).mpr (by linarith) + have hi2 : 2 / (n : ℝ) ≤ 1 := (div_le_iff₀ hn0).mpr (by linarith) + have hm : ∑ y, discreteKernel (0 : Interaction n) k (plusSpin n) y * + magnetization y = (n : ℝ) * (1 - (n : ℝ)⁻¹) ^ k := by + change (∑ y, (attemptLM (0 : Interaction n) ^ k) + (fun z => if z = y then 1 else 0) (plusSpin n) * magnetization y) = _ + rw [kernel_apply, attempt_pow_zero_magnetization] + simp [mul_comm] + have hs : ∑ y, discreteKernel (0 : Interaction n) k (plusSpin n) y * + (magnetization y ^ 2 - (n : ℝ)) = + (1 - 2 / (n : ℝ)) ^ k * ((n : ℝ) ^ 2 - n) := by + change (∑ y, (attemptLM (0 : Interaction n) ^ k) + (fun z => if z = y then 1 else 0) (plusSpin n) * centeredMagnetizationSq y) = _ + rw [kernel_apply, attempt_pow_zero_centeredMagnetizationSq] + simp [centeredMagnetizationSq] + rw [quadratic_centered_identity _ _ _ _ _ (discreteKernel_sum _ _ _) hm hs] + have hbase : 1 - 2 / (n : ℝ) ≤ (1 - (n : ℝ)⁻¹) ^ 2 := by + rw [div_eq_mul_inv]; nlinarith [sq_nonneg (n : ℝ)⁻¹] + have hpow : (1 - 2 / (n : ℝ)) ^ k ≤ ((1 - (n : ℝ)⁻¹) ^ k) ^ 2 := by + rw [← pow_mul, Nat.mul_comm, pow_mul] + exact pow_le_pow_left₀ (by linarith) hbase k + have hn2 : 0 ≤ (n : ℝ) ^ 2 - n := by nlinarith + have hmul := mul_le_mul_of_nonneg_right hpow hn2 + have hs0 := sq_nonneg ((1 - (n : ℝ)⁻¹) ^ k) + nlinarith [mul_nonneg (Nat.cast_nonneg n) hs0] + +lemma continuous_zero_lower {n : ℕ} (hn : 0 < n) (t : ℝ) (ht : 0 ≤ t) : + 1 - 8 * Real.exp (2 * t) / (n : ℝ) ≤ + totalVariation (continuousKernel (0 : Interaction n) t (plusSpin n)) (gibbs 0) := by + have hn' : (0 : ℝ) < n := by exact_mod_cast hn + have hm : 0 < (n : ℝ) * Real.exp (-t) := mul_pos hn' (Real.exp_pos _) + have h := totalVariation_lower_from_quadratic_test + (continuousKernel (0 : Interaction n) t (plusSpin n)) (gibbs 0) magnetization + (continuousKernel_nonneg _ _ ht _) (fun y => le_of_lt (gibbs_pos _ y)) + (continuousKernel_sum _ _ _) (gibbs_sum _) _ _ hm (continuous_zero_variance t) + (le_of_eq (uniform_magnetization_second_moment n)) + have he : Real.exp (-t) ^ 2 * Real.exp (2 * t) = 1 := by + rw [← Real.exp_nat_mul, ← Real.exp_add] + convert Real.exp_zero using 1; congr 1; ring + have hmul := mul_le_mul_of_nonneg_right h (le_of_lt (Real.exp_pos (2 * t))) + have heq : ((n : ℝ) * Real.exp (-t)) ^ 2 * Real.exp (2 * t) = (n : ℝ) ^ 2 := by + rw [mul_pow, mul_assoc, he, mul_one] + have hmul' : (n : ℝ) ^ 2 * (1 - totalVariation + (continuousKernel (0 : Interaction n) t (plusSpin n)) (gibbs 0)) ≤ + 8 * n * Real.exp (2 * t) := by + calc + _ = ((n : ℝ) * Real.exp (-t)) ^ 2 * (1 - totalVariation + (continuousKernel (0 : Interaction n) t (plusSpin n)) (gibbs 0)) * + Real.exp (2 * t) := by rw [mul_right_comm, heq] + _ ≤ _ := hmul + have hscaled : (n : ℝ) * ((1 - totalVariation + (continuousKernel (0 : Interaction n) t (plusSpin n)) (gibbs 0)) * n) ≤ + (n : ℝ) * (8 * Real.exp (2 * t)) := by nlinarith only [hmul'] + have hsmall := (mul_le_mul_iff_right₀ hn').mp hscaled + have hdiv := (le_div_iff₀ hn').mpr hsmall + linarith + +lemma exp_neg_inv_le_one_sub_inv (a : ℝ) (ha : 1 < a) : + Real.exp (-1 / (a - 1)) ≤ 1 - a⁻¹ := by + have ha0 : 0 < a := by linarith + have hsub : 0 < a - 1 := by linarith + have h := Real.add_one_le_exp (1 / (a - 1)) + have heq : 1 / (a - 1) + 1 = a / (a - 1) := by field_simp; ring + rw [heq] at h + have hi := one_div_le_one_div_of_le (div_pos ha0 hsub) h + rw [one_div, ← Real.exp_neg] at hi + calc + _ = Real.exp (-(1 / (a - 1))) := by congr 1; ring + _ ≤ 1 / (a / (a - 1)) := hi + _ = 1 - a⁻¹ := by field_simp + +lemma discrete_zero_lower {n : ℕ} (hn : 2 ≤ n) (k : ℕ) : + 1 - 8 * Real.exp (2 * (k : ℝ) / ((n : ℝ) - 1)) / (n : ℝ) ≤ + totalVariation (discreteKernel (0 : Interaction n) k (plusSpin n)) (gibbs 0) := by + have hn' : (1 : ℝ) < n := by exact_mod_cast (show 1 < n by omega) + have hn0 : (0 : ℝ) < n := by linarith + have hb := exp_neg_inv_le_one_sub_inv (n : ℝ) hn' + have hpow : Real.exp (-(k : ℝ) / ((n : ℝ) - 1)) ≤ (1 - (n : ℝ)⁻¹) ^ k := by + calc + _ = Real.exp (-1 / ((n : ℝ) - 1)) ^ k := by + rw [← Real.exp_nat_mul]; congr 1; ring + _ ≤ _ := pow_le_pow_left₀ (le_of_lt (Real.exp_pos _)) hb k + have hp : 0 < (1 - (n : ℝ)⁻¹) ^ k := lt_of_lt_of_le (Real.exp_pos _) hpow + have h := totalVariation_lower_from_quadratic_test + (discreteKernel (0 : Interaction n) k (plusSpin n)) (gibbs 0) magnetization + (discreteKernel_nonneg _ _ _) (fun y => le_of_lt (gibbs_pos _ y)) + (discreteKernel_sum _ _ _) (gibbs_sum _) _ _ (mul_pos hn0 hp) + (discrete_zero_variance hn k) (le_of_eq (uniform_magnetization_second_moment n)) + have he : Real.exp (-(k : ℝ) / ((n : ℝ) - 1)) ^ 2 * + Real.exp (2 * (k : ℝ) / ((n : ℝ) - 1)) = 1 := by + rw [← Real.exp_nat_mul, ← Real.exp_add] + convert Real.exp_zero using 1; congr 1; ring + have hbE : 1 ≤ ((1 - (n : ℝ)⁻¹) ^ k) ^ 2 * + Real.exp (2 * (k : ℝ) / ((n : ℝ) - 1)) := by + calc + 1 = Real.exp (-(k : ℝ) / ((n : ℝ) - 1)) ^ 2 * + Real.exp (2 * (k : ℝ) / ((n : ℝ) - 1)) := he.symm + _ ≤ _ := mul_le_mul_of_nonneg_right + (pow_le_pow_left₀ (le_of_lt (Real.exp_pos _)) hpow 2) (le_of_lt (Real.exp_pos _)) + have hTV := totalVariation_le_one + (discreteKernel (0 : Interaction n) k (plusSpin n)) (gibbs 0) + (discreteKernel_nonneg _ _ _) (fun y => le_of_lt (gibbs_pos _ y)) + (discreteKernel_sum _ _ _) (gibbs_sum _) + have hl := mul_le_mul_of_nonneg_right hbE + (mul_nonneg (sq_nonneg (n : ℝ)) (sub_nonneg.mpr hTV)) + have hr := mul_le_mul_of_nonneg_right h + (le_of_lt (Real.exp_pos (2 * (k : ℝ) / ((n : ℝ) - 1)))) + have hs : (n : ℝ) * ((1 - totalVariation + (discreteKernel (0 : Interaction n) k (plusSpin n)) (gibbs 0)) * n) ≤ + (n : ℝ) * (8 * Real.exp (2 * (k : ℝ) / ((n : ℝ) - 1))) := by + nlinarith only [hl, hr] + have hsmall := (mul_le_mul_iff_right₀ hn0).mp hs + have hdiv := (le_div_iff₀ hn0).mpr hsmall + linarith + +lemma worstContinuous_nonneg {n : ℕ} (J : Interaction n) (t : ℝ) : + 0 ≤ worstContinuous J t := by + unfold worstContinuous + exact (totalVariation_nonneg _ _).trans + (Finset.le_sup' (fun x => totalVariation (continuousKernel J t x) (gibbs J)) + (Finset.mem_univ (plusSpin n))) + +lemma worstDiscrete_nonneg {n : ℕ} (J : Interaction n) (k : ℕ) : + 0 ≤ worstDiscrete J k := by + unfold worstDiscrete + exact (totalVariation_nonneg _ _).trans + (Finset.le_sup' (fun x => totalVariation (discreteKernel J k x) (gibbs J)) + (Finset.mem_univ (plusSpin n))) + +lemma worstContinuous_le_one {n : ℕ} (J : Interaction n) (t : ℝ) (ht : 0 ≤ t) : + worstContinuous J t ≤ 1 := by + apply Finset.sup'_le + intro x _ + exact totalVariation_le_one _ _ (continuousKernel_nonneg _ _ ht _) + (fun y => le_of_lt (gibbs_pos _ y)) (continuousKernel_sum _ _ _) (gibbs_sum _) + +lemma worstDiscrete_le_one {n : ℕ} (J : Interaction n) (k : ℕ) : + worstDiscrete J k ≤ 1 := by + apply Finset.sup'_le + intro x _ + exact totalVariation_le_one _ _ (discreteKernel_nonneg _ _ _) + (fun y => le_of_lt (gibbs_pos _ y)) (discreteKernel_sum _ _ _) (gibbs_sum _) + +lemma worstContinuous_zero_lower {n : ℕ} (hn : 0 < n) (t : ℝ) (ht : 0 ≤ t) : + 1 - 8 * Real.exp (2 * t) / (n : ℝ) ≤ worstContinuous (0 : Interaction n) t := by + unfold worstContinuous + exact (continuous_zero_lower hn t ht).trans + (Finset.le_sup' (fun x => totalVariation (continuousKernel 0 t x) (gibbs 0)) + (Finset.mem_univ _)) + +lemma worstDiscrete_zero_lower {n : ℕ} (hn : 2 ≤ n) (k : ℕ) : + 1 - 8 * Real.exp (2 * (k : ℝ) / ((n : ℝ) - 1)) / (n : ℝ) ≤ + worstDiscrete (0 : Interaction n) k := by + unfold worstDiscrete + exact (discrete_zero_lower hn k).trans + (Finset.le_sup' (fun x => totalVariation (discreteKernel 0 k x) (gibbs 0)) + (Finset.mem_univ _)) + +lemma worstContinuous_zero_upper {n : ℕ} (t : ℝ) : + worstContinuous (0 : Interaction n) t ≤ + Real.sqrt (Real.exp ((n : ℝ) * Real.exp (-2 * t)) - 1) / 2 := by + apply Finset.sup'_le + intro x _ + have h := (continuous_zero_tv_sq_le t x).trans + (sub_le_sub_right (one_add_pow_le_exp _ (le_of_lt (Real.exp_pos _)) n) 1) + have hnonneg : 0 ≤ Real.exp ((n : ℝ) * Real.exp (-2 * t)) - 1 := by + exact sub_nonneg.mpr (Real.one_le_exp (mul_nonneg (Nat.cast_nonneg n) + (le_of_lt (Real.exp_pos _)))) + have hs := Real.sq_sqrt hnonneg + have hs0 := Real.sqrt_nonneg (Real.exp ((n : ℝ) * Real.exp (-2 * t)) - 1) + nlinarith [totalVariation_nonneg (continuousKernel (0 : Interaction n) t x) (gibbs 0)] + +lemma worstDiscrete_zero_upper {n : ℕ} (hn : 0 < n) (k : ℕ) : + worstDiscrete (0 : Interaction n) k ≤ + Real.sqrt (Real.exp ((n : ℝ) * Real.exp (-2 * (k : ℝ) / n)) - 1) / 2 := by + apply Finset.sup'_le + intro x _ + have h := (discrete_zero_tv_sq_le hn k x).trans + (sub_le_sub_right (one_add_pow_le_exp _ (le_of_lt (Real.exp_pos _)) n) 1) + have hnonneg : 0 ≤ Real.exp ((n : ℝ) * Real.exp (-2 * (k : ℝ) / n)) - 1 := by + exact sub_nonneg.mpr (Real.one_le_exp (mul_nonneg (Nat.cast_nonneg n) + (le_of_lt (Real.exp_pos _)))) + have hs := Real.sq_sqrt hnonneg + have hs0 := Real.sqrt_nonneg (Real.exp ((n : ℝ) * Real.exp (-2 * (k : ℝ) / n)) - 1) + nlinarith [totalVariation_nonneg (discreteKernel (0 : Interaction n) k x) (gibbs 0)] + +open Filter Topology + +end SKGapCutoff +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/Map.lean b/lean/OAI/Probability/SKGap/Localization/Map.lean new file mode 100644 index 0000000000000000000000000000000000000000..bcd9e1583f0654f29563db54179f05424cb034bf --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/Map.lean @@ -0,0 +1,289 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.BlockDegree +import OAI.Probability.SKGap.Localization.NoiseSplit + +namespace OAI + +section +noncomputable section +noncomputable section +open scoped BigOperators +noncomputable section +noncomputable section +noncomputable section +open scoped BigOperators +noncomputable section +open scoped BigOperators +noncomputable section +open scoped BigOperators +namespace SKGap.Noncrossing +namespace Diagram +variable {D E : Type*} + +def NoiseSplit.map (f : D→E) {F : List (Letter D)} (s : NoiseSplit F) : + NoiseSplit (F.map (Letter.map f)) where + before := s.before.map (Letter.map f) + after := s.after.map (Letter.map f) + word_eq := by simpa [Letter.map] using congrArg (List.map (Letter.map f)) s.word_eq + +lemma NoiseSplit.map_bijective (f : D→E) (F : List (Letter D)) : + Function.Bijective (NoiseSplit.map f (F := F)) := by + constructor + · intro s t h + apply NoiseSplit.code_injective F + apply Fin.ext + have hh := congrArg (fun s => s.before.length) h + simpa [NoiseSplit.map,NoiseSplit.code] using hh + · intro s + obtain ⟨p,q,hF,hp,hq⟩ := List.map_eq_append_iff.mp s.word_eq + cases q with + | nil => simp at hq + | cons l q => + cases l with + | diag a => simp [Letter.map] at hq + | noise => + simp only [List.map_cons,Letter.map,List.cons.injEq,true_and] at hq + refine ⟨⟨p,q,hF⟩,?_⟩ + apply NoiseSplit.ext <;> simp [NoiseSplit.map,hp,hq] + +def NoiseSplit.mapEquiv (f : D→E) (F : List (Letter D)) : + NoiseSplit F ≃ NoiseSplit (F.map (Letter.map f)) := + Equiv.ofBijective (NoiseSplit.map f) (NoiseSplit.map_bijective f F) + +def NoiseSplit.appendLeft (P Q : List (Letter D)) (s : NoiseSplit P) : + NoiseSplit (P++Q) := + ⟨s.before,s.after++Q,by + simpa only [List.append_assoc,List.cons_append] using + congrArg (fun f => f++Q) s.word_eq⟩ +def NoiseSplit.appendRight (P Q : List (Letter D)) (s : NoiseSplit Q) : + NoiseSplit (P++Q) := + ⟨P++s.before,s.after,by + simpa only [List.append_assoc] using + congrArg (fun f => P++f) s.word_eq⟩ + +def NoiseSplit.appendMap (P Q : List (Letter D)) : + NoiseSplit P ⊕ NoiseSplit Q → NoiseSplit (P++Q) := + Sum.elim (NoiseSplit.appendLeft P Q) (NoiseSplit.appendRight P Q) + +lemma take_noise_drop {F : List (Letter D)} {k : ℕ} (h : F[k]?=some .noise) : + F=F.take k++(.noise::F.drop (k+1)) := by + have he := List.take_append_drop k F + rw [List.drop_eq_getElem?_toList_append,h] at he + simpa using he.symm + +lemma NoiseSplit.appendMap_bijective (P Q : List (Letter D)) : + Function.Bijective (NoiseSplit.appendMap P Q) := by + constructor + · intro s t h + cases s with + | inl s => + cases t with + | inl t => + apply congrArg Sum.inl + apply NoiseSplit.code_injective P + apply Fin.ext + exact congrArg (fun s => s.before.length) h + | inr t => + have hh := congrArg (fun s => s.before.length) h + change s.before.length=(P++t.before).length at hh + have hs := s.length_bound + simp only [List.length_append] at hh + omega + | inr s => + cases t with + | inl t => + have hh := congrArg (fun s => s.before.length) h + change (P++s.before).length=t.before.length at hh + have ht := t.length_bound + simp only [List.length_append] at hh + omega + | inr t => + apply congrArg Sum.inr + apply NoiseSplit.code_injective Q + apply Fin.ext + have hh := congrArg (fun s => s.before.length) h + change (P++s.before).length=(P++t.before).length at hh + simpa [NoiseSplit.code] using hh + · intro s + by_cases h : s.before.length f[s.before.length]?) s.word_eq + have hP : P[s.before.length]?=some .noise := by simpa [List.getElem?_append,h] using he + let t : NoiseSplit P := + ⟨P.take s.before.length,P.drop (s.before.length+1), + take_noise_drop hP⟩ + refine ⟨.inl t,?_⟩ + apply NoiseSplit.code_injective (P++Q) + apply Fin.ext + change (P.take s.before.length).length=s.before.length + simp [Nat.min_eq_left h.le] + · have he : (P++Q)[s.before.length]?=some .noise := by + simpa using congrArg (fun f => f[s.before.length]?) s.word_eq + have hQ : Q[s.before.length-P.length]?=some .noise := by + simpa [List.getElem?_append,h] using he + let t : NoiseSplit Q := + ⟨Q.take (s.before.length-P.length),Q.drop (s.before.length-P.length+1), + take_noise_drop hQ⟩ + refine ⟨.inr t,?_⟩ + apply NoiseSplit.code_injective (P++Q) + apply Fin.ext + change (P++Q.take (s.before.length-P.length)).length=s.before.length + have hs := s.length_bound + simp only [List.length_append,List.length_take] + simp only [List.length_append] at hs + rw [Nat.min_eq_left (by omega)] + omega + +def NoiseSplit.appendEquiv (P Q : List (Letter D)) : + (NoiseSplit P ⊕ NoiseSplit Q) ≃ NoiseSplit (P++Q) := + Equiv.ofBijective (NoiseSplit.appendMap P Q) (NoiseSplit.appendMap_bijective P Q) + +lemma NoiseSplit.sum_append {M : Type*} [AddCommMonoid M] + (P Q : List (Letter D)) (f : List (Letter D)→List (Letter D)→M) : + (∑ s : NoiseSplit (P++Q), f s.before s.after) = + (∑ s : NoiseSplit P, f s.before (s.after++Q))+ + (∑ s : NoiseSplit Q, f (P++s.before) s.after) := by + have he := Fintype.sum_equiv (NoiseSplit.appendEquiv P Q) + (fun s => match s with + | .inl s => f s.before (s.after++Q) + | .inr s => f (P++s.before) s.after) + (fun s => f s.before s.after) (by intro s; cases s <;> rfl) + rw [← he,Fintype.sum_sum_type] + +end Diagram +end SKGap.Noncrossing + +noncomputable section +open scoped BigOperators +namespace SKGap.Noncrossing +namespace InverseDiagram +open Diagram + +lemma expandBlocks_injective : Function.Injective expandBlocks := by + intro p q h + induction p generalizing q with + | nil => + cases q with + | nil => rfl + | cons b q => cases b <;> simp at h + | cons b p ih => + cases q with + | nil => cases b <;> simp at h + | cons c q => + cases b <;> cases c <;> simp only [expandBlocks_false, + expandBlocks_true,List.cons.injEq,Letter.diag.injEq,Bool.false_eq_true, + Bool.true_eq_false,false_and,true_and] at h + · exact congrArg (false::·) (ih h) + · exact congrArg (true::·) (ih h) + +@[simp] lemma blockDegree_append (p q : List Bool) : + blockDegree (p++q)=blockDegree p+blockDegree q := by simp [blockDegree] + +def SplitBlocks (n : ℕ) := {pq : List Bool × List Bool // blockDegree pq.1+blockDegree pq.2=n} +def SplitChoices (n : ℕ) := Σ k : Fin (n+1), Blocks k.val × Blocks (n-k.val) +def MarkedBlocks (n : ℕ) := Σ bs : Blocks (n+1), NoiseSplit (expandBlocks bs.val) + +instance splitChoicesFintype (n : ℕ) : Fintype (SplitChoices n) := inferInstanceAs + (Fintype (Σ k : Fin (n+1), Blocks k.val × Blocks (n-k.val))) +instance markedBlocksFintype (n : ℕ) : Fintype (MarkedBlocks n) := inferInstanceAs + (Fintype (Σ bs : Blocks (n+1), NoiseSplit (expandBlocks bs.val))) + +def splitChoice (n : ℕ) (z : SplitChoices n) : SplitBlocks n := + ⟨(z.2.1.val,z.2.2.val),by + rw [z.2.1.property,z.2.2.property] + have h := z.1.isLt + omega⟩ + +lemma splitChoice_bijective (n : ℕ) : Function.Bijective (splitChoice n) := by + constructor + · rintro ⟨k,p,q⟩ ⟨l,r,s⟩ h + have hp : p.val=r.val := congrArg (fun z => z.val.1) h + have hq : q.val=s.val := congrArg (fun z => z.val.2) h + have hk : k=l := by + apply Fin.ext + simpa only [p.property,r.property] using congrArg blockDegree hp + subst l + have hp' : p=r := Subtype.ext hp + have hq' : q=s := Subtype.ext hq + subst r; subst s; rfl + · intro p + refine ⟨⟨⟨blockDegree p.val.1,by have h := p.property; omega⟩, + ⟨p.val.1,rfl⟩,⟨p.val.2,by + change blockDegree p.val.2=n-blockDegree p.val.1 + have h := p.property; omega⟩⟩,?_⟩ + rfl + +def splitChoiceEquiv (n : ℕ) : SplitChoices n ≃ SplitBlocks n := + Equiv.ofBijective (splitChoice n) (splitChoice_bijective n) +instance splitBlocksFintype (n : ℕ) : Fintype (SplitBlocks n) := + Fintype.ofEquiv (SplitChoices n) (splitChoiceEquiv n) + +def splitToMarked (n : ℕ) (p : SplitBlocks n) : MarkedBlocks n := + ⟨⟨p.val.1++(true::p.val.2),by + simp only [blockDegree_append,blockDegree_true] + have h := p.property; omega⟩, + ⟨expandBlocks p.val.1++[.diag true],expandBlocks p.val.2,by + simp only [expandBlocks_append,expandBlocks_true,List.append_assoc,List.cons_append, + List.nil_append]⟩⟩ + +lemma splitToMarked_bijective (n : ℕ) : Function.Bijective (splitToMarked n) := by + constructor + · intro p q h + apply Subtype.ext + apply Prod.ext + · apply expandBlocks_injective + have he := congrArg (fun z : MarkedBlocks n => z.2.before) h + change expandBlocks p.val.1++[.diag true]=expandBlocks q.val.1++[.diag true] at he + exact List.append_cancel_right he + · apply expandBlocks_injective + exact congrArg (fun z : MarkedBlocks n => z.2.after) h + · rintro ⟨⟨bs,hbs⟩,s⟩ + obtain ⟨p,q,hpq,hp,hq⟩ := split_noise bs s.before s.after s.word_eq + have hd : blockDegree p+blockDegree q=n := by + rw [hpq,blockDegree_append,blockDegree_true] at hbs + omega + refine ⟨⟨(p,q),hd⟩,?_⟩ + subst bs + have hs : (splitToMarked n ⟨(p,q),hd⟩).snd = s := by + apply NoiseSplit.ext + · exact hp.symm + · exact hq.symm + exact congrArg (Sigma.mk (⟨p++true::q,hbs⟩ : Blocks (n+1))) hs + +def markedBlockEquiv (n : ℕ) : SplitChoices n ≃ MarkedBlocks n := + (splitChoiceEquiv n).trans (Equiv.ofBijective (splitToMarked n) (splitToMarked_bijective n)) + +theorem sum_marked_blocks {M : Type*} [AddCommMonoid M] (n : ℕ) + (f : List (Letter Bool)→List (Letter Bool)→M) : + (∑ bs : Blocks (n+1), ∑ s : NoiseSplit (expandBlocks bs.val), f s.before s.after) = + ∑ k : Fin (n+1), ∑ p : Blocks k.val, ∑ q : Blocks (n-k.val), + f (expandBlocks p.val++[.diag true]) (expandBlocks q.val) := by + have he := Fintype.sum_equiv (markedBlockEquiv n) + (fun z => f (expandBlocks z.2.1.val++[.diag true]) (expandBlocks z.2.2.val)) + (fun z => f z.2.before z.2.after) (by intro z; rfl) + change (∑ z : Σ k : Fin (n+1), Blocks k.val × Blocks (n-k.val), + f (expandBlocks z.2.1.val++[.diag true]) (expandBlocks z.2.2.val)) = + (∑ z : Σ bs : Blocks (n+1), NoiseSplit (expandBlocks bs.val), + f z.2.before z.2.after) at he + rw [Fintype.sum_sigma,Fintype.sum_sigma] at he + simp_rw [Fintype.sum_prod_type] at he + exact he.symm + +end InverseDiagram +end SKGap.Noncrossing + +noncomputable section +open scoped BigOperators + +end +end +end +end +end +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/MarkedDiagnostic.lean b/lean/OAI/Probability/SKGap/Localization/MarkedDiagnostic.lean new file mode 100644 index 0000000000000000000000000000000000000000..14794573a423f7c6ea64bcbf9ff531df1c965800 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/MarkedDiagnostic.lean @@ -0,0 +1,137 @@ +import Mathlib +import OAI.Probability.SKGap.Matrix.PrimitiveTrace +import OAI.Probability.SKGap.Localization.RecipeMarked + +namespace OAI + +section + +noncomputable section +open scoped BigOperators +namespace SKGapCutoff.Recipe +open SKGap.Noncrossing SKGap.Noncrossing.Primary SKGap.Noncrossing.Primary.MarkedPolynomial +variable {n : ℕ} +lemma wordBounded_append {A : ℝ} {u v : OrdinaryWord n} + (hu : wordBounded A u) (hv : wordBounded A v) : wordBounded A (u++v) := by + intro l hl; rcases List.mem_append.mp hl with hl|hl + · exact hu l hl + · exact hv l hl + +lemma wordBounded_mono {A B : ℝ} {u : OrdinaryWord n} (h : wordBounded A u) (hab : A≤B) : + wordBounded B u := by + intro l hl; cases l with + | noise=>trivial + | diag p=>exact fun i=>(h (.diag p) hl i).trans hab + +def MarkControl (A : ℝ) (L : ℕ) (t : SmallMark n) : Prop := + ∀d:Fin n→ℝ,(∀i,|d i|≤1)→ wordBounded A (t.diagnostic d) ∧ (t.diagnostic d).length≤L + +def MarkedControl (A : ℝ) (L : ℕ) (P : MarkedPolynomial n) : Prop := ∀t∈P,MarkControl A L t.2 + +def PairControl (A : ℝ) (L : ℕ) (P : Pair n) : Prop := MarkedControl A L P.1 ∧ MarkedControl A L P.2 + +lemma MarkControl.mono {A : ℝ} {L K : ℕ} {t : SmallMark n} (h : MarkControl A L t) (hLK : L≤K) : + MarkControl A K t := fun d hd=>⟨(h d hd).1,(h d hd).2.trans hLK⟩ + +lemma MarkControl.prepend {A : ℝ} {L : ℕ} {t : SmallMark n} (h : MarkControl A L t) + (P : OrdinaryWord n) (hp : wordBounded A P) : MarkControl A (L+P.length) (t.prepend P) := by + intro d hd + rcases h d hd with ⟨hb,hl⟩ + cases t with + | diagonal Q s R=> + simp only [SmallMark.prepend,SmallMark.diagnostic,List.length_append,List.length_cons] at * + constructor + · intro l hh + simp only [List.mem_append,List.mem_cons] at hh + rcases hh with hh|hh|hh|hh + · exact hb l (List.mem_append_left _ hh) + · subst l; exact hb (.diag d) (by simp) + · exact hp l hh + · exact hb l (by simp [hh]) + · omega + | average s Q=> + simp only [SmallMark.prepend,SmallMark.diagnostic] at * + exact ⟨wordBounded_append hp hb,by simp only [List.length_append]; omega⟩ + +lemma MarkedControl.append {A : ℝ} {L : ℕ} {P Q : MarkedPolynomial n} + (hp : MarkedControl A L P) (hq : MarkedControl A L Q) : MarkedControl A L (P++Q) := by + intro t ht; rcases List.mem_append.mp ht with ht|ht + · exact hp t ht + · exact hq t ht + +lemma MarkedControl.mono {A : ℝ} {L K : ℕ} {P : MarkedPolynomial n} + (h : MarkedControl A L P) (hLK : L≤K) : MarkedControl A K P := fun t ht=>(h t ht).mono hLK + +lemma MarkedControl.prepend {A : ℝ} {L : ℕ} {P : MarkedPolynomial n} + (h : MarkedControl A L P) (w : OrdinaryWord n) (hw : wordBounded A w) : + MarkedControl A (L+w.length) (P.prepend w) := by + intro t ht + obtain ⟨s,hs,rfl⟩:=List.mem_map.mp ht + exact (h s hs).prepend w hw + +lemma MarkedControl.scale {A : ℝ} {L : ℕ} {P : MarkedPolynomial n} + (h : MarkedControl A L P) (c : ℝ) : MarkedControl A L (P.scale c) := by + intro t ht + obtain ⟨s,hs,rfl⟩:=List.mem_map.mp ht + exact h s hs + +lemma diagonalWords_control {A : ℝ} {L : ℕ} (hA : 1≤A) (s : Fin n→ℝ) + (P : WordPolynomial (ι:=Fin n)) (hP : ∀t∈P,wordBounded A t.2 ∧ t.2.length≤L) : + MarkedControl A (L+1) (diagonalWords s P) := by + intro t ht d hd + obtain ⟨r,hr,he⟩:=List.mem_map.mp ht + subst t + simp only [SmallMark.diagnostic,List.length_append,List.length_cons,List.length_nil] + exact ⟨wordBounded_diag (hP r hr).1 d (fun i=>(hd i).trans hA),by have hh:=(hP r hr).2; omega⟩ + +lemma averageWords_control {A : ℝ} {L : ℕ} (c : ℝ) (s : Fin n→ℝ) + (P : WordPolynomial (ι:=Fin n)) (hP : ∀t∈P,wordBounded A t.2 ∧ t.2.length≤L) : + MarkedControl A L (averageWords c s P) := by + intro t ht d hd + obtain ⟨r,hr,he⟩:=List.mem_map.mp ht + subst t + exact hP r hr + +lemma zeroPair_control {A : ℝ} {L : ℕ} (hL : 1≤L) : PairControl (n:=n) A L zeroPair := by + constructor + · intro t ht; have he:=List.mem_singleton.mp ht; subst t + intro d hd; exact ⟨by intro l hl; simp [SmallMark.diagnostic] at hl,by simp [SmallMark.diagnostic]⟩ + · intro t ht; have he:=List.mem_singleton.mp ht; subst t + intro d hd + constructor + · intro l hl + have he : l=Letter.noise := by simpa [SmallMark.diagnostic] using hl + subst l + trivial + · simpa [SmallMark.diagnostic] using hL + +lemma smallBranch_control {A : ℝ} {L K : ℕ} (hA : 1≤A) (hLK : L+2≤K) + (j : ℝ) (p : Fin n→ℝ) (T : SourceTree (Fin n→ℝ)) (V : Pair n) + (hT : (∀t∈(T.words j).1,wordBounded A t.2 ∧ t.2.length≤L) ∧ + (∀t∈(T.words j).2,wordBounded A t.2 ∧ t.2.length≤L)) + (hV : PairControl A K V) : PairControl A K (smallBranch j p T V) := by + have hd:=diagonalWords_control hA p _ hT.2 + have ha:=averageWords_control (-j) p _ hT.1 + have hn : wordBounded (n:=n) A [.noise] := by intro l hl; have he:=List.mem_singleton.mp hl; subst l; trivial + refine ⟨(hd.mono (by omega)).append hV.1,?_⟩ + exact (((hd.prepend [.noise] hn).mono (by simp only [List.length_cons,List.length_nil]; omega)).append (ha.mono (by omega))).append hV.2 + +lemma boundedBranch_control {A : ℝ} {L K : ℕ} (hLK : L+2≤K) + (j : ℝ) (p : Fin n→ℝ) (hp : ∀i,|p i|≤A) (U V : Pair n) + (hU : PairControl A L U) (hV : PairControl A K V) : PairControl A K (boundedBranch j p U V) := by + have hd : wordBounded (n:=n) A [.diag p] := by intro l hl; have he:=List.mem_singleton.mp hl; subst l; exact hp + have hd' : wordBounded (n:=n) A [.noise,.diag p] := by + intro l hl; simp only [List.mem_cons,List.not_mem_nil,or_false] at hl + rcases hl with rfl|rfl + · trivial + · exact hp + refine ⟨((hU.2.prepend [.diag p] hd).mono (by simp only [List.length_singleton]; omega)).append hV.1,?_⟩ + exact (((hU.2.prepend [.noise,.diag p] hd').mono (by simp only [List.length_cons,List.length_nil]; omega)).append + ((hU.1.scale _).mono (by omega))).append hV.2 + +end SKGapCutoff.Recipe + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/MarkedErrorRate.lean b/lean/OAI/Probability/SKGap/Localization/MarkedErrorRate.lean new file mode 100644 index 0000000000000000000000000000000000000000..e71f88fdf58c0598aad806b520980ee7f3050284 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/MarkedErrorRate.lean @@ -0,0 +1,118 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.ProjectedMarkedIBP + +namespace OAI + +section +noncomputable section +namespace SKGap +open Real +open scoped NNReal ENNReal + +lemma power_tail_absorptions (k : ℕ) {c n p : ℝ} (hc : 0u x*v x) := by + apply LipschitzWith.of_dist_le_mul + intro x y + rw [dist_eq_norm] + have he : u x*v x-u y*v y=(u x-u y)*v x+u y*(v x-v y) := by ring + rw [he] + apply (norm_add_le _ _).trans + rw [norm_mul,norm_mul] + have hut := hu.dist_le_mul x y + have hvt := hv.dist_le_mul x y + rw [dist_eq_norm] at hut hvt + have hh := mul_le_mul hut (hC x) (norm_nonneg _) (mul_nonneg L.coe_nonneg dist_nonneg) + have hh' := mul_le_mul (hB y) hvt (norm_nonneg _) B.coe_nonneg + apply (add_le_add hh hh').trans_eq + simp only [NNReal.coe_add,NNReal.coe_mul] + ring + +variable {ι : Type*} [Fintype ι] [DecidableEq ι] + +theorem goe_marked_product_IBP {r : ℝ} (hr : 0≤r) + (U Q : Matrix ι ι ℝ→Matrix ι ι ℝ) + (DU DQ : ι→ι→Matrix ι ι ℝ→Matrix ι ι ℝ) + {L K B C : NNReal} {D E : ℝ} + (hU : LipschitzWith L U) (hQ : LipschitzWith K Q) + (hB : ∀ M,opNorm (U M)≤B) (hC : ∀ M,opNorm (Q M)≤C) + (hDU : ∀ a b,Continuous (DU a b)) (hDQ : ∀ a b,Continuous (DQ a b)) + (hD : ∀ a b M,opNorm (DU a b M)≤D) (hE : ∀ a b M,opNorm (DQ a b M)≤E) + {s : Set (MatrixCoordinates ι→ℝ)} (hs : MeasurableSet s) + (hUd : ∀ a b g,g∈s→HasDerivAt (fun t : ℝ=>U (goeMatrix r g+t • symmetricElementary a b)) (DU a b (goeMatrix r g)) 0) + (hQd : ∀ a b g,g∈s→HasDerivAt (fun t : ℝ=>Q (goeMatrix r g+t • symmetricElementary a b)) (DQ a b (goeMatrix r g)) 0) + (i : ι) : + let μ := Measure.pi (fun _ : MatrixCoordinates ι=>gaussianReal 0 1) + |(∫ g,(U (goeMatrix r g)*goeMatrix r g*Q (goeMatrix r g)) i i ∂μ)- + r*(∫ g,∑ a,∑ b,(DU a b (goeMatrix r g) i a*Q (goeMatrix r g) b i+ + U (goeMatrix r g) i a*DQ a b (goeMatrix r g) b i) ∂μ)|≤ + (Fintype.card ι:ℝ)^2*(sqrt (2*r)*((L*C+B*K:NNReal)*(⟨sqrt (2*r),sqrt_nonneg _⟩*(Fintype.card (MatrixCoordinates ι):NNReal)^(1/(2:ℝ≥0∞)).toReal):NNReal)+ + r*(D*C+B*E))*μ.real sᶜ := by + intro μ + let H := fun a b M=>(U M) i a*(Q M) b i + let d := fun a b g=>(DU a b (goeMatrix r g)) i a*(Q (goeMatrix r g)) b i+ + (U (goeMatrix r g)) i a*(DQ a b (goeMatrix r g)) b i + have hG := (goeMatrix_pi_lipschitz (ι:=ι) r) + have hu (a : ι) : LipschitzWith L (fun M=>(U M) i a) := by + simpa only [one_mul,Function.comp_def] using! (matrixEntry_lipschitz i a).comp hU + have hq (b : ι) : LipschitzWith K (fun M=>(Q M) b i) := by + simpa only [one_mul,Function.comp_def] using! (matrixEntry_lipschitz b i).comp hQ + have hub (M : Matrix ι ι ℝ) (a : ι) : ‖(U M) i a‖≤(B:ℝ) := + (matrix_entry_le_opNorm _ i a).trans (hB M) + have hqb (M : Matrix ι ι ℝ) (b : ι) : ‖(Q M) b i‖≤(C:ℝ) := + (matrix_entry_le_opNorm _ b i).trans (hC M) + have hdh (a b : ι) : Measurable (d a b) := by + exact (((hDU a b).comp hG.continuous).matrix_elem i a |>.mul ((hQ.continuous.comp hG.continuous).matrix_elem b i) |>.add + (((hU.continuous.comp hG.continuous).matrix_elem i a).mul (((hDQ a b).comp hG.continuous).matrix_elem b i))).measurable + have hdb (a b : ι) (g : MatrixCoordinates ι→ℝ) : ‖d a b g‖≤D*C+B*E := by + apply (norm_add_le _ _).trans + simp only [norm_mul] + exact add_le_add (mul_le_mul ((matrix_entry_le_opNorm _ i a).trans (hD a b _)) (hqb _ b) (norm_nonneg _) + (le_trans (show 0≤opNorm (DU a b (goeMatrix r g)) from norm_nonneg _) (hD a b _))) + (mul_le_mul (hub _ a) ((matrix_entry_le_opNorm _ b i).trans (hE a b _)) (norm_nonneg _) B.coe_nonneg) + have hh := goe_marked_sum_IBP hr H d + (fun a b=>(scalar_bounded_product_lipschitz (hu a) (hq b) (fun M=>hub M a) (fun M=>hqb M b)).comp hG) + (C:=(B:ℝ)*C) (fun a b g=>by rw [norm_mul];exact mul_le_mul (hub _ a) (hqb _ b) (norm_nonneg _) B.coe_nonneg) + hdh hdb hs (fun a b g hg=>by + have ha := matrixEntry_derivative (hUd a b g hg) i a + have hb := matrixEntry_derivative (hQd a b g hg) b i + simpa only [H,d,zero_smul,add_zero] using! ha.fun_mul hb) + simpa only [H,d,← matrix_marked_expand,μ] using! hh +end SKGap +end +end + +section +noncomputable section +namespace SKGap +open Matrix Real MeasureTheory ProbabilityTheory Set +open scoped BigOperators Matrix.Norms.Frobenius +variable {ι : Type*} [Fintype ι] [DecidableEq ι] + +lemma marked_entry_bound (U W Q : Matrix ι ι ℝ) {B C : ℝ} (hB : 0≤B) ( _hC : 0≤C) + (hU : opNorm U≤B) (hQ : opNorm Q≤C) (i : ι) : + |(U*W*Q) i i|≤B*C*(∑ a,∑ b,|W a b|) := by + rw [matrix_marked_expand] + apply (Finset.abs_sum_le_sum_abs _ _).trans + simp only [Finset.mul_sum] + apply Finset.sum_le_sum + intro a _ + apply (Finset.abs_sum_le_sum_abs _ _).trans + apply Finset.sum_le_sum + intro b _ + rw [abs_mul,abs_mul] + have hh := mul_le_mul ((matrix_entry_le_opNorm _ i a).trans hU) + ((matrix_entry_le_opNorm _ b i).trans hQ) (abs_nonneg _) hB + nlinarith [mul_le_mul_of_nonneg_left hh (abs_nonneg (W a b))] + +theorem projected_marked_expectation_error {r R B C : ℝ} (hr : 0≤r) (hR : 0≤R) + (hB : 0≤B) (hC : 0≤C) (U Q : Matrix ι ι ℝ→Matrix ι ι ℝ) + (hU : Continuous U) (hQ : Continuous Q) (hUb : ∀ M,opNorm (U M)≤B) (hQb : ∀ M,opNorm (Q M)≤C) + {s : Set (MatrixCoordinates ι→ℝ)} (hs : MeasurableSet s) + (hgood : ∀ g∈s,opNorm (goeMatrix r g)≤R) (i : ι) : + let μ := Measure.pi (fun _ : MatrixCoordinates ι=>gaussianReal 0 1) + |(∫ g,(U (goeMatrix r g)*realProject R hR (goeMatrix r g)*Q (goeMatrix r g)) i i ∂μ)- + (∫ g,(U (goeMatrix r g)*goeMatrix r g*Q (goeMatrix r g)) i i ∂μ)|≤ + B*R*C*μ.real sᶜ+B*C*(Fintype.card ι:ℝ)^2*sqrt (2*r)*sqrt (μ.real sᶜ) := by + intro μ + let W := goeMatrix (ι:=ι) r + have hWc := (goeMatrix_pi_lipschitz (ι:=ι) r).continuous + have hUc := hU.comp hWc + have hQc := hQ.comp hWc + have hPc := (realProject_lipschitz hR).continuous.comp hWc + have hpb (g : MatrixCoordinates ι→ℝ) : ‖(U (W g)*realProject R hR (W g)*Q (W g)) i i‖≤B*R*C := by + exact (matrix_entry_le_opNorm _ i i).trans ((opNorm_mul _ _).trans + (mul_le_mul ((opNorm_mul _ _).trans (mul_le_mul (hUb _) (realProject_opNorm hR _) (norm_nonneg _) hB)) + (hQb _) (norm_nonneg _) (mul_nonneg hB hR))) + have hpi : Integrable (fun g=>(U (W g)*realProject R hR (W g)*Q (W g)) i i) μ := + (integrable_const (B*R*C)).mono' (((hUc.matrix_mul hPc).matrix_mul hQc).matrix_elem i i).aestronglyMeasurable (ae_of_all _ hpb) + have hwa (a b : ι) : Integrable (fun g=>|W g a b|) μ := by + exact ((goeEntry_memLp r a b).integrable (by norm_num)).norm + have hwai : Integrable (fun g=>∑ a,∑ b,|W g a b|) μ := + integrable_finsetSum _ (fun a _=>integrable_finsetSum _ (fun b _=>hwa a b)) + have hwb (g : MatrixCoordinates ι→ℝ) : ‖(U (W g)*W g*Q (W g)) i i‖≤B*C*(∑ a,∑ b,|W g a b|) := + marked_entry_bound _ _ _ hB hC (hUb _) (hQb _) i + have hwi : Integrable (fun g=>(U (W g)*W g*Q (W g)) i i) μ := + (hwai.const_mul (B*C)).mono' (((hUc.matrix_mul hWc).matrix_mul hQc).matrix_elem i i).aestronglyMeasurable (ae_of_all _ hwb) + have herr := integral_exceptional_equal_bound hs.compl hpi hwi + ((integrable_const (B*R*C)).add (hwai.const_mul (B*C))) + (fun g hg=>by rw [realProject_eq_self hR _ (goeMatrix_transpose r g) (hgood g (by simpa using hg))]) + (fun g _=>(norm_sub_le _ _).trans (add_le_add (hpb g) (hwb g))) + apply herr.trans + have hwas (a b : ι) : Integrable (fun g=>|W g a b|) (μ.restrict sᶜ) := (hwa a b).mono_measure Measure.restrict_le_self + simp only [Pi.add_apply] + rw [integral_add (integrable_const _) ((hwai.const_mul (B*C)).mono_measure Measure.restrict_le_self),integral_const,integral_const_mul] + rw [integral_finsetSum _ (fun a _=>integrable_finsetSum _ (fun b _=>hwas a b))] + simp_rw [integral_finsetSum _ (fun b _=>hwas _ b)] + have hbad (a b : ι) : (∫ g in sᶜ,|W g a b| ∂μ)≤ sqrt (2*r)*sqrt (μ.real sᶜ) := + (integral_abs_on_set_le (goeEntry_memLp r a b) hs.compl).trans + (mul_le_mul_of_nonneg_right (sqrt_le_sqrt (goeEntry_integral_sq_le hr a b)) (sqrt_nonneg _)) + simp only [measureReal_restrict_apply_univ,smul_eq_mul] + calc + _ ≤ μ.real sᶜ*(B*R*C)+B*C*(∑ a : ι,∑ b : ι,sqrt (2*r)*sqrt (μ.real sᶜ)) := + add_le_add le_rfl (mul_le_mul_of_nonneg_left (Finset.sum_le_sum (fun a _=>Finset.sum_le_sum (fun b _=>hbad a b))) (mul_nonneg hB hC)) + _ = _ := by simp only [Finset.sum_const,Finset.card_univ,nsmul_eq_mul];ring +end SKGap +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/ModelLocalization.lean b/lean/OAI/Probability/SKGap/Localization/ModelLocalization.lean new file mode 100644 index 0000000000000000000000000000000000000000..604aab70c639aef1da8c93f8e4dde7c4c81e6ca8 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/ModelLocalization.lean @@ -0,0 +1,87 @@ +import Mathlib +import OAI.Probability.SKGap.Stability.RootGrid +import OAI.Probability.SKGap.Posterior.StaticExperimentBridge + +namespace OAI + +namespace SKGap.FullMain +open MeasureTheory ProbabilityTheory Filter Real Set +open scoped Topology BigOperators ENNReal +open GaussianStep GaussianHistory ObservationBridge SKGapCutoff.Recipe SKGapCutoff.Static +noncomputable section +variable {n : ℕ} + +theorem poincare_from_model_data (g : Disorder n) (hn : 0sqrt T*z i) f≤2*dirichlet g (fun i=>sqrt T*z i) f}≤exp (-aT*(n:ℝ))) + (hcov : PosteriorCovarianceProperty j Ar ε c r₀ D₀ g) + (hmean : StableSquareMeanProperty j c r₀ ρ C₀ Cmean (coupling g)) + (hrare : exp (-a*(n:ℝ))+exp (-aT*(n:ℝ))≤exp (-b*(n:ℝ))) + (hmesh : 4*(n:ℝ)*gridStep T n≤1) + (hmeshD : D₀^2*gridStep T n≤1/2) + (hloss : localizationLoss n (gridStep T n) W (2*Cmean) a b T≤exp (-2*D₀^2*T)/2) + (hcost : localizationCost n (2*Cmean) a b (D₀^2) 2 T≤D₀^2*T+3) : + ∀f:Spin n→ℝ,variance g 0 f≤(2*(D₀^2*T+3)/exp (-2*D₀^2*T))*dirichlet g 0 f := by + let t:=gridStep T n + have ht : 0≤t:=gridStep_nonneg hT.le n + let B : ∀k,Set (History n k):=fun k=>{h | rootBad j Ar ε c r₀ (coupling g) (GaussianHistory.field t h)} + have hB (k : ℕ) : MeasurableSet (B k):= + (measurable_rootFields g j Ar ε c r₀).preimage (continuous_field t k).measurable + let F:Set (History n (gridSteps n)):= {h | ¬∀f:Spin n→ℝ, + variance g (GaussianHistory.field t h) f≤2*dirichlet g (GaussianHistory.field t h) f} + have hF : MeasurableSet F:= + ((terminal_goodSet_closed g 2).measurableSet.compl).preimage (continuous_field t (gridSteps n)).measurable + let E:Set (History n (gridSteps n)):=(goodPrefix B (gridSteps n))ᶜ∪F + have hE : MeasurableSet E:=(measurable_goodPrefix B hB _).compl.union hF + have hsum : (∑k∈Finset.range (gridSteps n+1),eventProbability (gibbsPrior g 0) t (B k))= + gridFailure n j Ar K ε c r₀ T g := by + apply Finset.sum_congr rfl + intro k _ + exact history_root_probability g ht k j Ar K ε c r₀ hop + have hsmall (k : ℕ) (hk : kgoodPrefix_previous B k h hh) subset_union_left + (D₀^2) W (2*Cmean) a b 2 T (D₀^2*T+3) hD hW (by positivity) ha hb (by norm_num) hconst + hmeshD (grid_total T n) hsmall hEsmall + (fun f hf k _ h hh=>?_) (fun f k _ h hh=>?_) (fun f h hh=>?_) hloss hcost + · intro f + simpa only [gibbsPrior_var,gibbsPrior_energy] using H f + · have hppos : 0(f x)^2) := by + rw [←hpfield h] + exact posterior_square_pos (gibbsPrior g 0) f hf t h + have hm:=drift_square_of_stable_mean hn hAr hmean (GaussianHistory.field t h) hh f hppos + simp only [driftSquare,GaussianHistory.squarePrior_posterior,hpfield] + apply hm.trans + exact add_le_add (mul_le_mul_of_nonneg_right hlead (Nat.cast_nonneg n)) le_rfl + · rw [hpfield h] + exact covariance_square_bound hD₀ hcov (GaussianHistory.field t h) + (goodPrefix_not_bad B k h hh) f + · rw [hpfield h,gibbsPrior_var,gibbsPrior_energy] + have hnF : h∉F:=fun hhF=>hh (Or.inr hhF) + exact (not_not.mp hnF) f + +end +end SKGap.FullMain + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/NoiseSplit.lean b/lean/OAI/Probability/SKGap/Localization/NoiseSplit.lean new file mode 100644 index 0000000000000000000000000000000000000000..bf7aea378400349109ce67ff5b810c20b4aa83f4 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/NoiseSplit.lean @@ -0,0 +1,197 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.Append +import OAI.Probability.SKGap.Localization.SeparateCut + +namespace OAI + +section +noncomputable section +noncomputable section +open scoped BigOperators +noncomputable section +noncomputable section +noncomputable section +open scoped BigOperators +noncomputable section +open scoped BigOperators +namespace SKGap.Noncrossing +namespace Diagram +variable {D : Type*} + +@[ext] structure NoiseSplit (F : List (Letter D)) where + before : List (Letter D) + after : List (Letter D) + word_eq : F=before++(.noise::after) + +lemma NoiseSplit.before_take {F : List (Letter D)} (s : NoiseSplit F) : + s.before=F.take s.before.length := by + simpa using (congrArg (List.take s.before.length) s.word_eq).symm +lemma NoiseSplit.after_drop {F : List (Letter D)} (s : NoiseSplit F) : + s.after=F.drop (s.before.length+1) := by + simpa using (congrArg (List.drop (s.before.length+1)) s.word_eq).symm +lemma NoiseSplit.length_bound {F : List (Letter D)} (s : NoiseSplit F) : + s.before.length ⟨s.before,s.after,Q,true,by + simpa only [List.append_assoc,List.cons_append] using + congrArg (fun f => f++(.noise::Q)) s.word_eq,by + have h := congrArg List.length s.word_eq + simpa using h⟩ + | .inr s => ⟨P,s.before,s.after,false,congrArg (fun f => P++(.noise::f)) s.word_eq,by simp⟩ + +lemma shapeAt_bijective (P Q : List (Letter D)) : Function.Bijective (shapeAt P Q) := by + constructor + · intro a b he + cases a with + | inl a => + cases b with + | inl b => + apply congrArg Sum.inl + exact NoiseSplit.ext (congrArg PairShape.before he) (congrArg PairShape.between he) + | inr b => have hh := congrArg PairShape.closing he; cases hh + | inr a => + cases b with + | inl b => have hh := congrArg PairShape.closing he; cases hh + | inr b => + apply congrArg Sum.inr + exact NoiseSplit.ext (congrArg PairShape.between he) (congrArg PairShape.after he) + · intro s + cases hc : s.closing with + | false => + have hlen : P.length=s.before.length := by simpa [hc] using s.mark_eq + have hparts := List.append_inj s.word_eq hlen + have hP : P=s.before := hparts.1 + have hQ : Q=s.between++(.noise::s.after) := List.cons.inj hparts.2 |>.2 + refine ⟨.inr ⟨s.between,s.after,hQ⟩,?_⟩ + apply PairShape.ext <;> simp [shapeAt,hP,hc] + | true => + have hlen : P.length=(s.before++(.noise::s.between)).length := by + simpa [hc] using s.mark_eq + have hw : P++(.noise::Q)=(s.before++(.noise::s.between))++(.noise::s.after) := by + simpa only [List.append_assoc,List.cons_append] using s.word_eq + have hparts := List.append_inj hw hlen + have hP := hparts.1 + have hQ : Q=s.after := List.cons.inj hparts.2 |>.2 + refine ⟨.inl ⟨s.before,s.between,hP⟩,?_⟩ + apply PairShape.ext <;> simp [shapeAt,hQ,hc] + +def shapeAtEquiv (P Q : List (Letter D)) : + (NoiseSplit P ⊕ NoiseSplit Q) ≃ PairShape (P++(.noise::Q)) P.length := + Equiv.ofBijective (shapeAt P Q) (shapeAt_bijective P Q) + +section Evaluate +variable {ι : Type*} [Fintype ι] + +def evaluate (j : ℝ) (v : D→ι→ℝ) (d : Diagram D) : ι→ℝ := (d.map v).value j + +@[simp] lemma evaluate_nil (j : ℝ) (v : D→ι→ℝ) (i : ι) : + evaluate j v .nil i=1 := rfl +@[simp] lemma evaluate_diag (j : ℝ) (v : D→ι→ℝ) (a : D) (d : Diagram D) (i : ι) : + evaluate j v (.diag a d) i=v a i*evaluate j v d i := rfl +@[simp] lemma evaluate_arch (j : ℝ) (v : D→ι→ℝ) (d e : Diagram D) (i : ι) : + evaluate j v (.arch d e) i=j*mean (evaluate j v d)*evaluate j v e i := rfl + +lemma evaluate_insert (j : ℝ) (v : D→ι→ℝ) (d e : Diagram D) (p : ℕ) (i : ι) : + evaluate j v (d.insert p e) i = j*mean (evaluate j v e)*evaluate j v d i := by + induction d generalizing p i with + | nil => simp only [insert]; split_ifs <;> rfl + | diag a d ih => + by_cases hp : p=0 + · simp [hp] + · simp only [insert,hp,↓reduceIte,evaluate_diag,ih]; ring + | arch a b ia ib => + by_cases hp : p=0 + · simp [hp] + · simp only [insert,hp,↓reduceIte] + split_ifs + · have hh : evaluate j v (a.insert (p-1) e) = + fun k => j*mean (evaluate j v e)*evaluate j v a k := funext (ia (p-1)) + simp only [evaluate_arch,hh,mean_const_mul]; ring + · simp only [evaluate_arch,ib]; ring + +def expect (j : ℝ) (v : D→ι→ℝ) (F : List (Letter D)) (i : ι) : ℝ := + ∑ d : Paired F, evaluate j v d.val i + +lemma mean_expect (j : ℝ) (v : D→ι→ℝ) (F : List (Letter D)) : + mean (expect j v F) = ∑ d : Paired F, mean (evaluate j v d.val) := by + simp only [mean,expect] + rw [Finset.sum_comm,Finset.sum_div] + +lemma expect_cut (j : ℝ) (v : D→ι→ℝ) (F : List (Letter D)) (k : ℕ) + (hk : F[k]?=some .noise) (i : ι) : + expect j v F i = ∑ s : PairShape F k, + j * mean (expect j v s.between) * expect j v (s.before++s.after) i := by + let e := (cutEquiv F k hk).trans (separateEquiv F k) + have he : expect j v F i = ∑ z : Separated F k, + j*mean (evaluate j v z.2.1.val)*evaluate j v z.2.2.val i := by + apply Fintype.sum_equiv e + intro d + have hd : d.val.word[k]?=some .noise := by rw [d.property]; exact hk + have hc := cut_spec d.val k _ (cut_markedCut d.val k hd) + change evaluate j v d.val i = + j*mean (evaluate j v (d.val.markedCut k hd).inside)* + evaluate j v (d.val.markedCut k hd).outside i + exact (congrArg (fun a => evaluate j v a i) hc.2.2).symm.trans + (evaluate_insert j v _ _ _ i) + rw [he] + change (∑ z : Σ s : PairShape F k, Paired s.between × Paired (s.before++s.after), + j*mean (evaluate j v z.2.1.val)*evaluate j v z.2.2.val i) = _ + rw [Fintype.sum_sigma] + apply Finset.sum_congr rfl + intro s _ + rw [Fintype.sum_prod_type] + change (∑ a : Paired s.between, ∑ b : Paired (s.before++s.after), + j*mean (evaluate j v a.val)*evaluate j v b.val i) = _ + simp_rw [← Finset.mul_sum] + rw [← Finset.sum_mul,← Finset.mul_sum,← mean_expect] + rfl + +theorem expect_at (j : ℝ) (v : D→ι→ℝ) (P Q : List (Letter D)) (i : ι) : + expect j v (P++(.noise::Q)) i = + (∑ s : NoiseSplit P, j*mean (expect j v s.after)*expect j v (s.before++Q) i) + + (∑ s : NoiseSplit Q, j*mean (expect j v s.before)*expect j v (P++s.after) i) := by + rw [expect_cut j v _ P.length (by simp)] + have hh := Fintype.sum_equiv (shapeAtEquiv P Q) + (fun s : NoiseSplit P ⊕ NoiseSplit Q => match s with + | .inl s => j*mean (expect j v s.after)*expect j v (s.before++Q) i + | .inr s => j*mean (expect j v s.before)*expect j v (P++s.after) i) + (fun s => j*mean (expect j v s.between)*expect j v (s.before++s.after) i) + (by intro s; cases s <;> rfl) + rw [← hh,Fintype.sum_sum_type] + +end Evaluate +end Diagram +end SKGap.Noncrossing + +noncomputable section +open scoped BigOperators + +end +end +end +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/Operation.lean b/lean/OAI/Probability/SKGap/Localization/Operation.lean new file mode 100644 index 0000000000000000000000000000000000000000..85048a5bbcc97f1824635a775f2c4a3a9ab6f8f2 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/Operation.lean @@ -0,0 +1,236 @@ +import Mathlib +import OAI.Probability.SKGap.Matrix.DiscreteMatrixCalculus +import OAI.Probability.SKGap.Localization.Error + +namespace OAI + +section + +noncomputable section +open scoped BigOperators Matrix.Norms.Frobenius +namespace SKGapCutoff.Recipe +open Primary Matrix +variable {n : ℕ} + +def vectorNorm (u : Fin n→ℝ) : ℝ := ‖(WithLp.toLp 2 u : EuclideanSpace ℝ (Fin n))‖ + +lemma vectorNorm_sq (u : Fin n→ℝ) : vectorNorm u^2=∑i,(u i)^2 := by + exact EuclideanSpace.real_norm_sq_eq _ + +lemma vectorNorm_nonneg (u : Fin n→ℝ) : 0 ≤ vectorNorm u := norm_nonneg _ + +lemma vectorNorm_mul (a s : Fin n→ℝ) {A : ℝ} (hA : 0 ≤ A) (ha : ∀i,|a i| ≤ A) : + vectorNorm (fun i=>a i*s i) ≤ A*vectorNorm s := by + apply nonneg_le_nonneg_of_sq_le_sq (mul_nonneg hA (vectorNorm_nonneg _)) + simp only [←sq,vectorNorm_sq,mul_pow] + rw [Finset.mul_sum] + exact Finset.sum_le_sum fun i _=>mul_le_mul_of_nonneg_right + (by nlinarith [sq_abs (a i),ha i,abs_nonneg (a i)]) (sq_nonneg _) + +lemma row_scaled_frobenius (D : Interaction n) (s : Fin n→ℝ) {R : ℝ} + (hR : 0 ≤ R) (hD : ∀i,∑k,(D i k)^2 ≤ R^2) : + ‖Matrix.of (fun i k=>s i*D i k)‖ ≤ R*vectorNorm s := by + apply nonneg_le_nonneg_of_sq_le_sq (mul_nonneg hR (vectorNorm_nonneg _)) + simp only [←sq] + rw [SKGap.frobenius_sq,mul_pow,vectorNorm_sq] + simp only [Matrix.of_apply,mul_pow,←Finset.mul_sum] + calc + _ ≤ ∑i,(s i)^2*R^2 := Finset.sum_le_sum fun i _=>mul_le_mul_of_nonneg_left (hD i) (sq_nonneg _) + _ = _ := by rw [←Finset.sum_mul]; ring + +lemma row_entry_bound (D : Interaction n) {R : ℝ} (hR : 0 ≤ R) + (hD : ∀i,∑k,(D i k)^2 ≤ R^2) (i k : Fin n) : |D i k| ≤ R := by + have H: (D i k)^2 ≤ R^2 := + (Finset.single_le_sum (fun l _=>sq_nonneg (D i l)) (Finset.mem_univ k)).trans (hD i) + nlinarith [sq_abs (D i k),abs_nonneg (D i k)] + +lemma multiplier_frobenius (a : Fin n→ℝ) (D : Interaction n) {A : ℝ} + (hA : 0 ≤ A) (ha : ∀i,|a i| ≤ A) : ‖Matrix.of (fun i k=>a i*D i k)‖ ≤ A*‖D‖ := by + apply nonneg_le_nonneg_of_sq_le_sq (mul_nonneg hA (norm_nonneg _)) + simp only [←sq] + rw [SKGap.frobenius_sq,mul_pow,SKGap.frobenius_sq] + simp only [Matrix.of_apply,mul_pow,Finset.mul_sum] + apply Finset.sum_le_sum; intro i _ + apply Finset.sum_le_sum; intro k _ + exact mul_le_mul_of_nonneg_right (by simpa only [sq_abs] using pow_le_pow_left₀ (abs_nonneg (a i)) (ha i) 2) (sq_nonneg _) + +lemma product_remainder_frobenius (A D : Interaction n) (x : Spin n) {R : ℝ} + (hR : 0 ≤ R) (hA : ∀i,∑k,(A i k)^2 ≤ R^2) : + ‖Matrix.of (fun i k=>2*spin x k*A i k*D i k)‖ ≤ 2*R*‖D‖ := by + apply nonneg_le_nonneg_of_sq_le_sq (by positivity) + simp only [←sq] + rw [SKGap.frobenius_sq,mul_pow,mul_pow,SKGap.frobenius_sq] + simp only [Matrix.of_apply,mul_pow,spin_sq,mul_one,Finset.mul_sum] + apply Finset.sum_le_sum; intro i _ + apply Finset.sum_le_sum; intro k _ + have H:=row_entry_bound A hR hA i k + have HH : (A i k)^2 ≤ R^2 := by simpa only [sq_abs] using pow_le_pow_left₀ (abs_nonneg (A i k)) H 2 + nlinarith [mul_nonneg (sq_nonneg (D i k)) (sub_nonneg.mpr HH)] + +lemma source_derivative_product (a s : VectorFields n) (x : Spin n) : + derivativeMatrix (fun x i=>a x i*s x i) x= + (fun i k=>a x i*derivativeMatrix s x i k)+ + (fun i k=>s x i*derivativeMatrix a x i k)- + (fun i k=>2*spin x k*derivativeMatrix a x i k*derivativeMatrix s x i k) := by + ext i k + exact halfDiff_mul k (fun x=>a x i) (fun x=>s x i) x + +lemma source_frobenius (a s : VectorFields n) (x : Spin n) {A R : ℝ} + (hA : 0 ≤ A) (hR : 0 ≤ R) (ha : ∀i,|a x i| ≤ A) + (hda : ∀i,∑k,(derivativeMatrix a x i k)^2 ≤ R^2) : + ‖derivativeMatrix (fun x i=>a x i*s x i) x‖ ≤ + A*‖derivativeMatrix s x‖+R*vectorNorm (s x)+2*R*‖derivativeMatrix s x‖ := by + rw [source_derivative_product] + exact (norm_sub_le _ _).trans (add_le_add + ((norm_add_le _ _).trans (add_le_add (multiplier_frobenius _ _ hA ha) + (row_scaled_frobenius _ _ hR hda))) (product_remainder_frobenius _ _ x hR hda)) + +lemma source_sum_frobenius {ι : Type*} [Fintype ι] (a s : ι→VectorFields n) (x : Spin n) + (A R : ι→ℝ) (hA : ∀l,0 ≤ A l) (hR : ∀l,0 ≤ R l) (ha : ∀l i,|a l x i| ≤ A l) + (hda : ∀l i,∑k,(derivativeMatrix (a l) x i k)^2 ≤ (R l)^2) : + ‖derivativeMatrix (fun x i=>∑l,a l x i*s l x i) x‖ ≤ + ∑l,(A l*‖derivativeMatrix (s l) x‖+R l*vectorNorm (s l x)+2*R l*‖derivativeMatrix (s l) x‖) := by + have he : derivativeMatrix (fun x i=>∑l,a l x i*s l x i) x= + ∑l,derivativeMatrix (fun x i=>a l x i*s l x i) x := by + ext i k + simp only [Matrix.sum_apply,derivativeMatrix,halfDiff_sum] + rw [he] + exact (norm_sum_le _ _).trans (Finset.sum_le_sum fun l _=>source_frobenius _ _ x (hA l) (hR l) (ha l) (hda l)) + +end SKGapCutoff.Recipe + +end +end + +section + +noncomputable section +open scoped BigOperators Matrix.Norms.Frobenius +namespace SKGapCutoff.Recipe +open Primary Matrix +variable {n : ℕ} + +lemma vectorNorm_add (u v : Fin n→ℝ) : + vectorNorm (u+v) ≤ vectorNorm u+vectorNorm v := by + exact norm_add_le (WithLp.toLp 2 u : EuclideanSpace ℝ (Fin n)) (WithLp.toLp 2 v) + +lemma vectorNorm_smul (c : ℝ) (u : Fin n→ℝ) : + vectorNorm (c • u)=|c| *vectorNorm u := by + exact norm_smul c (WithLp.toLp 2 u : EuclideanSpace ℝ (Fin n)) + +lemma vectorNorm_sum {ι : Type*} [Fintype ι] (u : ι→Fin n→ℝ) : + vectorNorm (∑l,u l) ≤ ∑l,vectorNorm (u l) := by + change ‖(WithLp.toLp 2 (∑l,u l) : EuclideanSpace ℝ (Fin n))‖≤_ + have he : (WithLp.toLp 2 (∑l,u l) : EuclideanSpace ℝ (Fin n))=∑l,WithLp.toLp 2 (u l) := by + ext i; simp [Finset.sum_apply] + rw [he] + exact norm_sum_le _ _ + +lemma vectorNorm_mono {u v : Fin n→ℝ} (h : ∀i,|u i|≤|v i|) : vectorNorm u ≤ vectorNorm v := by + apply nonneg_le_nonneg_of_sq_le_sq (vectorNorm_nonneg _) + simp only [←sq,vectorNorm_sq] + exact Finset.sum_le_sum fun i _=>by + simpa only [sq_abs] using pow_le_pow_left₀ (abs_nonneg (u i)) (h i) 2 + +lemma vectorNorm_abs (u : Fin n→ℝ) : vectorNorm (fun i=>|u i|)=vectorNorm u := by + apply (sq_eq_sq₀ (vectorNorm_nonneg _) (vectorNorm_nonneg _)).mp + simp [vectorNorm_sq] + +lemma vectorNorm_matrix_mul (J : Interaction n) (u : Fin n→ℝ) : + vectorNorm (J.mulVec u) ≤ SKGap.opNorm J*vectorNorm u := by + exact (Matrix.toEuclideanCLM (𝕜:=ℝ) J).le_opNorm (WithLp.toLp 2 u) + +lemma siteMean_square (U : VectorFields n) (x : Spin n) (hn : 0siteMean U x*m x i) ≤ vectorNorm (U x) := by + apply nonneg_le_nonneg_of_sq_le_sq (vectorNorm_nonneg _) + simp only [←sq,vectorNorm_sq,mul_pow] + calc + _ ≤ ∑_i:Fin n,(siteMean U x)^2 := by + apply Finset.sum_le_sum; intro i _ + have H : (m x i)^2≤1 := by + simpa only [sq_abs,one_pow] using pow_le_pow_left₀ (abs_nonneg (m x i)) (hm i) 2 + nlinarith [sq_nonneg (siteMean U x)] + _ = (n:ℝ)*(siteMean U x)^2 := by simp + _ ≤ _ := by simpa only [vectorNorm_sq] using siteMean_square U x hn + +lemma scaled_frobenius_by_rows (D : Interaction n) (a : ℝ) {C P : ℝ} + (hC : 0≤C) (hP : 0≤P) (ha : (n:ℝ)*a^2≤C^2) + (hD : ∀i,∑k,(D i k)^2≤P^2) : ‖a • D‖≤C*P := by + apply nonneg_le_nonneg_of_sq_le_sq (mul_nonneg hC hP) + simp only [←sq] + rw [SKGap.frobenius_sq,mul_pow] + simp only [Matrix.smul_apply,smul_eq_mul,mul_pow] + calc + _ ≤ ∑_i:Fin n,a^2*P^2 := Finset.sum_le_sum fun i _=>by + rw [←Finset.mul_sum]; exact mul_le_mul_of_nonneg_left (hD i) (sq_nonneg _) + _ = ((n:ℝ)*a^2)*P^2 := by simp; ring + _ ≤ _ := mul_le_mul_of_nonneg_right ha (sq_nonneg _) + +lemma primary_mean_frobenius (U m : VectorFields n) (x : Spin n) (hn : 0siteMean U y*m y i) x‖≤C*(1+3*P) := by + have hav : (n:ℝ)*(siteMean U x)^2≤C^2 := (siteMean_square U x hn).trans + (pow_le_pow_left₀ (vectorNorm_nonneg _) hu 2) + have hdav : (n:ℝ)*‖derivativeVector (siteMean U) x‖^2≤C^2 := + siteMean_derivative_square_bound hn ((opNorm_le_frobenius _).trans hdu) + have hs := scaled_frobenius_by_rows (derivativeMatrix m x) (siteMean U x) hC hP hav (fun i=> + (SKGap.SourceError.matrix_row_square_le _ i).trans (pow_le_pow_left₀ (norm_nonneg _) hdm 2)) + have he := product_derivative_error hn hC hdm hm hdav + calc + _ ≤ ‖derivativeMatrix (fun y i=>siteMean U y*m y i) x-siteMean U x • derivativeMatrix m x‖+ + ‖siteMean U x • derivativeMatrix m x‖ := norm_le_norm_sub_add _ _ + _ ≤ (C+2*P*C)+C*P := add_le_add he hs + _ = _ := by ring + +lemma coefficient_mean_value (a : VectorFields n) (x : Spin n) {A : ℝ} + (hA : 0≤A) (ha : ∀i,|a x i|≤A) : |siteMean a x|≤A := by + by_cases hn : n=0 + · subst n; simp [siteMean,hA] + have hnR : (0:ℝ)ha i + _ = _ := by simp [mul_comm] + +lemma coefficient_mean_difference (a : VectorFields n) (x : Spin n) {R : ℝ} + (hR : 0≤R) (hda : ∀i,∑k,(derivativeMatrix a x i k)^2≤R^2) : + ‖derivativeVector (siteMean a) x‖≤R := by + have he : derivativeVector (siteMean a) x = (n:ℝ)⁻¹ • + ∑i,WithLp.toLp 2 (fun k=>derivativeMatrix a x i k) := by + ext k + simp only [derivativeVector,WithLp.ofLp_toLp,PiLp.smul_apply,smul_eq_mul,WithLp.ofLp_sum,Finset.sum_apply,WithLp.ofLp_toLp] + simp only [halfDiff,siteMean,derivativeMatrix] + rw [←Finset.sum_div,Finset.sum_sub_distrib] + ring + rw [he,norm_smul,Real.norm_eq_abs,abs_inv,abs_of_nonneg (Nat.cast_nonneg n)] + by_cases hn : n=0 + · subst n; simp [hR] + have hnR : (0:ℝ)by + apply nonneg_le_nonneg_of_sq_le_sq hR + simpa only [←sq,EuclideanSpace.real_norm_sq_eq,WithLp.ofLp_toLp] using hda i)) (inv_nonneg.mpr hnR.le) + _ = R := by simp [hnR.ne'] + +end SKGapCutoff.Recipe + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/OperatorQuenched.lean b/lean/OAI/Probability/SKGap/Localization/OperatorQuenched.lean new file mode 100644 index 0000000000000000000000000000000000000000..1c78ab29df192bae536c0c86409409af08ac4c51 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/OperatorQuenched.lean @@ -0,0 +1,120 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.PlantedMarginalLaw + +namespace OAI + +section + +noncomputable section +namespace SKGap.ObservationBridge +open Matrix Real Set MeasureTheory ProbabilityTheory Filter +open scoped BigOperators ENNReal NNReal Topology +local instance (n : ℕ) : MeasurableSpace (Matrix (Fin n) (Fin n) ℝ) := borel _ +local instance (n : ℕ) : BorelSpace (Matrix (Fin n) (Fin n) ℝ) := ⟨rfl⟩ + +lemma coupling_goeEdges {n : ℕ} (r : ℝ) (g : MatrixCoordinates (Fin n)→ℝ) : + coupling (goeEdges r g)=eraseDiagonal (goeMatrix r g) := by + ext i k + by_cases hik : i < k + · simp [coupling,hik,goeEdges,eraseDiagonal,ne_of_lt hik] + · by_cases hki : k < i + · simp [coupling,hik,hki,goeEdges,eraseDiagonal, + (ne_of_lt hki).symm,goeMatrix,add_comm] + · have he : i=k := le_antisymm (le_of_not_gt hki) (le_of_not_gt hik) + subst k + simp [coupling,eraseDiagonal] + +lemma operatorBound_of_opNorm {n : ℕ} {K : ℝ} {J : Matrix (Fin n) (Fin n) ℝ} + (hJ : opNorm J ≤ K) : operatorBound K J := by + intro z + have hh := J.toEuclideanLin.toContinuousLinearMap.le_opNorm + (WithLp.toLp 2 z : EuclideanSpace ℝ (Fin n)) + exact hh.trans (mul_le_mul_of_nonneg_right hJ (vectorNorm_nonneg z)) + +lemma zero_diagonal_operator_tail {j d : ℝ} (hj : 0le_of_not_gt (fun hi=>hh'.2 ⟨i,hi⟩)) + calc + _ ≤ opNorm (goeMatrix r g)+opNorm (diagonal (fun i=>goeMatrix r g i i)) := opNorm_sub _ _ + _ ≤ (2*sqrt j+d)+d := add_le_add (le_of_not_gt hh'.1) hdg + _ = _ := by ring + have he : μ.real E ≤ 2*exp (-(d^2/(π^2*j))*(n:ℝ)) := by + have hh := goe_norm_tail (ι:=Fin n) hj hd.le + have heq : -(d^2/(π^2*j))*(n:ℝ) = -d^2*(n:ℝ)/(π^2*j) := by ring + rw [heq] + simpa only [Fintype.card_fin,matrixOperator,opNorm,μ,E,r] using hh + have hv : μ.real V ≤ 2*(n:ℝ)*exp (-(d^2/(8*j))*(n:ℝ)) := by + have hh := goe_diagonal_tail (ι:=Fin n) hr hd.le + apply hh.trans_eq + simp only [Fintype.card_fin] + congr 2 + dsimp [r] + field_simp + exact (measureReal_mono hs).trans ((measureReal_union_le E V).trans (add_le_add he hv)) + +lemma disorder_operator_tail {β d : ℝ} (hβ : 0<β) (hd : 0exp (-a*(n:ℝ))) atTop (𝓝 0) := by + have hh : Tendsto (fun n : ℕ=>a*(n:ℝ)) atTop atTop := + tendsto_natCast_atTop_atTop.const_mul_atTop ha + simpa only [Function.comp_def,neg_mul] using tendsto_exp_neg_atTop_nhds_zero.comp hh + +theorem quenched_operator_bound {β K : ℝ} (hβ : 0<β) (hK : 2*β(disorderLaw β n).real {J | ¬operatorBound K (coupling J)}) atTop (𝓝 0) := by + let d := (K-2*β)/2 + have hd : 0measureReal_nonneg)) hbound ht +end SKGap.ObservationBridge + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/OriginalEventRegeneration.lean b/lean/OAI/Probability/SKGap/Localization/OriginalEventRegeneration.lean new file mode 100644 index 0000000000000000000000000000000000000000..8b2d7eb3572a8843f70a6922b644acc727839e8e --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/OriginalEventRegeneration.lean @@ -0,0 +1,423 @@ +import Mathlib +import OAI.Probability.SKGap.Matrix.NormalizedRecipeLaw +import OAI.Probability.SKGap.Entropy.RegeneratedNormalizedQuery + +namespace OAI + +section +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open scoped BigOperators +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open scoped BigOperators +open scoped BigOperators NNReal ENNReal +open MeasureTheory Metric Set +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators NNReal ENNReal Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Set +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators ENNReal NNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Matrix +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators ENNReal NNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal +open scoped BigOperators +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise NNReal ENNReal +open scoped BigOperators +open Filter Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal Topology +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Set Matrix +open scoped BigOperators NNReal ENNReal Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +namespace SKGapCutoff.Regression + +local instance reverseMatrixMeasurable {n m : ℕ} : MeasurableSpace (Matrix (Fin n) (Fin m) ℝ) := + inferInstanceAs (MeasurableSpace (Fin n → Fin m → ℝ)) + +lemma original_event_le_regeneration {n r : ℕ} (hn : 0 < n) {H : Type*} [MeasurableSpace H] + (ρ : Measure H) (U Y : H → Matrix (Fin n) (Fin r) ℝ) (q : H → Fin n → ℝ) + (hUm : Measurable U) (hYm : Measurable Y) (hqm : Measurable q) + (G : Set H) (hG : MeasurableSet G) + (hgood : ∀ h ∈ G, (U h)ᵀ*U h=1 ∧ (U h)ᵀ*Y h=(Y h)ᵀ*U h ∧ + (∑ i, q h i^2)=1 ∧ (U h)ᵀ *ᵥ q h=0) + (T : Set (H × ((Fin n → ℝ) × Matrix (Fin n) (Fin n) ℝ))) (hT : MeasurableSet T) : + (ρ.prod (standardArrayLaw (Fin n × Fin n))) + ((fun z => (z.1,(completedMatrix (U z.1) (Y z.1) z.2 *ᵥ q z.1, + completedMatrix (U z.1) (Y z.1) z.2))) ⁻¹' T) ≤ + (ρ.prod ((standardArrayLaw (Fin n × Fin n)).prod (standardArrayLaw (Fin n ⊕ Unit)))) + ((fun z => (z.1,(regeneratedAnswer (U z.1) (Y z.1) (q z.1) z.2.2, + completedMatrix (extendFrame (U z.1) (q z.1)) + (extendFrame (Y z.1) (regeneratedAnswer (U z.1) (Y z.1) (q z.1) z.2.2)) z.2.1))) ⁻¹' T)+ρ Gᶜ := by + let F : H × ((Fin n × Fin n) → ℝ) → + H × ((Fin n → ℝ) × Matrix (Fin n) (Fin n) ℝ) := fun z => + (z.1,(completedMatrix (U z.1) (Y z.1) z.2 *ᵥ q z.1, + completedMatrix (U z.1) (Y z.1) z.2)) + let R : H × (((Fin n × Fin n) → ℝ) × ((Fin n ⊕ Unit) → ℝ)) → + H × ((Fin n → ℝ) × Matrix (Fin n) (Fin n) ℝ) := fun z => + (z.1,(regeneratedAnswer (U z.1) (Y z.1) (q z.1) z.2.2, + completedMatrix (extendFrame (U z.1) (q z.1)) + (extendFrame (Y z.1) (regeneratedAnswer (U z.1) (Y z.1) (q z.1) z.2.2)) z.2.1)) + have hA : Measurable (fun z : H × ((Fin n × Fin n) → ℝ) => + completedMatrix (U z.1) (Y z.1) z.2) := + measurable_completedMatrix_comp _ _ _ (hUm.comp measurable_fst) (hYm.comp measurable_fst) measurable_snd + have hF : Measurable F := measurable_fst.prodMk + ((measurable_matrix_mulVec_comp _ _ hA (hqm.comp measurable_fst)).prodMk hA) + have hb : Measurable (fun z : H × (((Fin n × Fin n) → ℝ) × ((Fin n ⊕ Unit) → ℝ)) => + regeneratedAnswer (U z.1) (Y z.1) (q z.1) z.2.2) := + measurable_regeneratedAnswer_comp _ _ _ _ (hUm.comp measurable_fst) + (hYm.comp measurable_fst) (hqm.comp measurable_fst) (measurable_snd.comp measurable_snd) + have hUn : Measurable (fun z : H × (((Fin n × Fin n) → ℝ) × ((Fin n ⊕ Unit) → ℝ)) => + extendFrame (U z.1) (q z.1)) := + measurable_extendFrame.comp ((hUm.comp measurable_fst).prodMk (hqm.comp measurable_fst)) + have hYn : Measurable (fun z : H × (((Fin n × Fin n) → ℝ) × ((Fin n ⊕ Unit) → ℝ)) => + extendFrame (Y z.1) (regeneratedAnswer (U z.1) (Y z.1) (q z.1) z.2.2)) := + measurable_extendFrame.comp ((hYm.comp measurable_fst).prodMk hb) + have hR : Measurable R := measurable_fst.prodMk (hb.prodMk + (measurable_completedMatrix_comp _ _ _ hUn hYn (measurable_fst.comp measurable_snd))) + apply prod_event_le_of_section_law ρ + (standardArrayLaw (Fin n × Fin n)) + ((standardArrayLaw (Fin n × Fin n)).prod (standardArrayLaw (Fin n ⊕ Unit))) F R hF hR G hG _ T hT + intro h hh + have hsec := completedMatrix_section_law hn (U h) (Y h) (q h) + (hgood h hh).1 (hgood h hh).2.1 (hgood h hh).2.2.1 (hgood h hh).2.2.2 + have hfo : Measurable (fun g => (completedMatrix (U h) (Y h) g *ᵥ q h, + completedMatrix (U h) (Y h) g)) := + measurable_snd.comp (hF.comp measurable_prodMk_left) + have hro : Measurable (fun z : ((Fin n × Fin n) → ℝ) × ((Fin n ⊕ Unit) → ℝ) => (regeneratedAnswer (U h) (Y h) (q h) z.2, + completedMatrix (extendFrame (U h) (q h)) + (extendFrame (Y h) (regeneratedAnswer (U h) (Y h) (q h) z.2)) z.1)) := + measurable_snd.comp (hR.comp measurable_prodMk_left) + have hout : Measurable (fun t : (Fin n → ℝ) × Matrix (Fin n) (Fin n) ℝ => (h,t)) := + measurable_const.prodMk measurable_id + have he := congrArg (Measure.map (fun t : (Fin n → ℝ) × Matrix (Fin n) (Fin n) ℝ => (h,t))) hsec + have hmfo := Measure.map_map (μ := standardArrayLaw (Fin n × Fin n)) hout hfo + have hmro := Measure.map_map (μ := (standardArrayLaw (Fin n × Fin n)).prod + (standardArrayLaw (Fin n ⊕ Unit))) hout hro + exact hmfo.symm.trans (he.trans hmro) + +theorem original_exponentiallyRare_of_regenerated + {H : ℕ → Type*} [∀ n, MeasurableSpace (H n)] + (ρ : ∀ n, Measure (H n)) (r : ℕ) + (U Y : ∀ n, H n → Matrix (Fin n) (Fin r) ℝ) + (q : ∀ n, H n → Fin n → ℝ) + (hUm : ∀ n, Measurable (U n)) (hYm : ∀ n, Measurable (Y n)) + (hqm : ∀ n, Measurable (q n)) + (G : ∀ n, Set (H n)) (hG : ∀ n, MeasurableSet (G n)) + (hrare : ExponentiallyRare ρ (fun n => (G n)ᶜ)) + (hgood : ∀ᶠ n in atTop, ∀ h ∈ G n, + (U n h)ᵀ*U n h=1 ∧ (U n h)ᵀ*Y n h=(Y n h)ᵀ*U n h ∧ + (∑ i, q n h i^2)=1 ∧ (U n h)ᵀ *ᵥ q n h=0) + (T : ∀ n, Set (H n × ((Fin n → ℝ) × Matrix (Fin n) (Fin n) ℝ))) + (hT : ∀ n, MeasurableSet (T n)) + (hbad : ExponentiallyRare + (fun n => (ρ n).prod ((standardArrayLaw (Fin n × Fin n)).prod + (standardArrayLaw (Fin n ⊕ Unit)))) + (fun n => (fun z => (z.1,(regeneratedAnswer (U n z.1) (Y n z.1) (q n z.1) z.2.2, + completedMatrix (extendFrame (U n z.1) (q n z.1)) + (extendFrame (Y n z.1) + (regeneratedAnswer (U n z.1) (Y n z.1) (q n z.1) z.2.2)) z.2.1))) ⁻¹' T n)) : + ExponentiallyRare (fun n => (ρ n).prod (standardArrayLaw (Fin n × Fin n))) + (fun n => (fun z => (z.1,(completedMatrix (U n z.1) (Y n z.1) z.2 *ᵥ q n z.1, + completedMatrix (U n z.1) (Y n z.1) z.2))) ⁻¹' T n) := by + apply exponentiallyRare_of_measure_le_add _ _ ρ _ _ _ hbad hrare + filter_upwards [hgood,eventually_gt_atTop 0] with n hn hn0 + exact original_event_le_regeneration hn0 (ρ n) (U n) (Y n) (q n) + (hUm n) (hYm n) (hqm n) (G n) (hG n) hn (T n) (hT n) + +end SKGapCutoff.Regression + +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise + +namespace SKGapCutoff.Regression + +local instance sampledRawMatrixMeasurable {n m : ℕ} : MeasurableSpace (Matrix (Fin n) (Fin m) ℝ) := + inferInstanceAs (MeasurableSpace (Fin n → Fin m → ℝ)) + +noncomputable def sampledRawAnswer {n r : ℕ} (U Y : Matrix (Fin n) (Fin r) ℝ) + (v : Fin n → ℝ) (z : (Fin n ⊕ Unit) → ℝ) : Fin n → ℝ := + Y *ᵥ (Uᵀ *ᵥ v) + Real.sqrt (∑ i, (residualProjection U *ᵥ v) i^2) • + regeneratedAnswer U Y (unitVector (residualProjection U *ᵥ v)) z + +lemma sampledRawAnswer_scaled {n r : ℕ} (hn : 0 < n) + (U Y : Matrix (Fin n) (Fin r) ℝ) (v : Fin n → ℝ) (z : (Fin n ⊕ Unit) → ℝ) (i : Fin n) : + sampledRawAnswer U Y v z i = + Real.sqrt ((∑ j, (residualProjection U *ᵥ v) j^2)/(n:ℝ))* + (Real.sqrt n*regeneratedAnswer U Y (unitVector (residualProjection U *ᵥ v)) z i)+ + ∑ a, ((∑ j, Real.sqrt n*U j a*v j)/(n:ℝ))*(Real.sqrt n*Y i a) := by + have hn0 : (n:ℝ) ≠ 0 := Nat.cast_ne_zero.mpr (Nat.ne_of_gt hn) + have hsn : Real.sqrt (n:ℝ) ≠ 0 := ne_of_gt (Real.sqrt_pos.mpr (Nat.cast_pos.mpr hn)) + have hs : (Real.sqrt (n:ℝ))^2=n := Real.sq_sqrt (Nat.cast_nonneg _) + have hp : (Y *ᵥ (Uᵀ *ᵥ v)) i = + ∑ a, ((∑ j, Real.sqrt n*U j a*v j)/(n:ℝ))*(Real.sqrt n*Y i a) := by + simp only [Matrix.mulVec,dotProduct,Matrix.transpose_apply] + apply Finset.sum_congr rfl + intro a _ + rw [Finset.sum_div,Finset.sum_mul,Finset.mul_sum] + apply Finset.sum_congr rfl + intro j _ + field_simp + nlinarith [congrArg (fun t : ℝ => t*(U j a*v j*Y i a)) hs] + simp only [sampledRawAnswer,Pi.add_apply,Pi.smul_apply,smul_eq_mul,hp] + rw [Real.sqrt_div (Finset.sum_nonneg (fun _ _ => sq_nonneg _))] + field_simp + ring + +lemma ExponentialEmpiricalConcentration.congr_eventually + {E : Type*} [PseudoMetricSpace E] [MeasurableSpace E] + {H : ℕ → Type*} [∀ n, MeasurableSpace (H n)] + {ρ : ∀ n, Measure (H n)} {X Y : ∀ n, H n → Fin n → E} {ν : Measure E} + (hX : ExponentialEmpiricalConcentration ρ X ν) (he : ∀ᶠ n in atTop, X n=Y n) : + ExponentialEmpiricalConcentration ρ Y ν := by + intro f K hf B hB ε hε + have hr : ExponentiallyRare ρ (fun n => {h | ε ≤ |(∑ i, f (X n h i))/(n:ℝ)-∫ x, f x ∂ν|}) := + hX f K hf B hB ε hε + apply hr.mono + filter_upwards [he] with n hn + intro h hh + simpa only [hn] using hh + +lemma ExponentialSquareTails.congr_eventually + {H : ℕ → Type*} [∀ n, MeasurableSpace (H n)] + {ρ : ∀ n, Measure (H n)} {X Y : ∀ n, H n → Fin n → ℝ} + (hX : ExponentialSquareTails ρ X) (he : ∀ᶠ n in atTop, X n=Y n) : + ExponentialSquareTails ρ Y := by + intro ε hε + obtain ⟨R,hR,ht⟩ := hX ε hε + refine ⟨R,hR,ht.mono ?_⟩ + filter_upwards [he] with n hn + intro h hh + simpa only [hn] using hh + +theorem ExponentialEmpiricalConcentration.sampled_unnormalized_assembly + {E : Type*} [PseudoMetricSpace E] [MeasurableSpace E] [BorelSpace E] + {H : ℕ → Type*} [∀ n, MeasurableSpace (H n)] + (ρ : ∀ n, Measure (H n)) [∀ n, IsProbabilityMeasure (ρ n)] + (X : ∀ n, H n → Fin n → E) + {r : ℕ} (U Y : ∀ n, H n → Matrix (Fin n) (Fin r) ℝ) + (u y : Fin r → E → ℝ) (g : E → ℝ) {K : ℝ≥0} (hK : 1 ≤ K) + (hy : ∀ a, LipschitzWith K (y a)) + (hyT : ∀ a, ExponentialSquareTails ρ (fun n h i => y a (X n h i))) + (heu : ∀ (n : ℕ) h i a, Real.sqrt n*U n h i a=u a (X n h i)) + (hey : ∀ (n : ℕ) h i a, Real.sqrt n*Y n h i a=y a (X n h i)) + (c : Fin r → ℝ) (s : ℝ) + (hC : ExponentialConvergence ρ + (fun n h a => (∑ i, u a (X n h i)*g (X n h i))/(n:ℝ)) c) + (hS : ExponentialConvergence ρ + (fun n h => (∑ i, (residualProjection (U n h) *ᵥ (fun j => g (X n h j))) i^2)/(n:ℝ)) s) + (ν : Measure ((E × ℝ) × ℝ)) [IsProbabilityMeasure ν] + (hX : ExponentialEmpiricalConcentration + (fun n => (ρ n).prod (standardArrayLaw (Fin n ⊕ Unit))) + (fun n z i => ((X n z.1 i, Real.sqrt n* + unitVector (residualProjection (U n z.1) *ᵥ (fun j => g (X n z.1 j))) i), + Real.sqrt n*regeneratedAnswer (U n z.1) (Y n z.1) (unitVector (residualProjection (U n z.1) *ᵥ (fun j => g (X n z.1 j)))) z.2 i)) ν) + (hWT : ExponentialSquareTails + (fun n => (ρ n).prod (standardArrayLaw (Fin n ⊕ Unit))) + (fun n z i => Real.sqrt n*regeneratedAnswer (U n z.1) (Y n z.1) (unitVector (residualProjection (U n z.1) *ᵥ (fun j => g (X n z.1 j)))) z.2 i)) + (hyi : ∀ a, Integrable (fun z => y a z.1.1^2) ν) + (hWi : Integrable (fun z => z.2^2) ν) : + ExponentialEmpiricalConcentration + (fun n => (ρ n).prod (standardArrayLaw (Fin n ⊕ Unit))) + (fun n z i => (((X n z.1 i, Real.sqrt n* + unitVector (residualProjection (U n z.1) *ᵥ (fun j => g (X n z.1 j))) i), + Real.sqrt n*regeneratedAnswer (U n z.1) (Y n z.1) (unitVector (residualProjection (U n z.1) *ᵥ (fun j => g (X n z.1 j)))) z.2 i), + sampledRawAnswer (U n z.1) (Y n z.1) (fun j => g (X n z.1 j)) z.2 i)) + (ν.map (fun z => (z,Real.sqrt s*z.2+∑ a, c a*y a z.1.1))) ∧ + ExponentialSquareTails (fun n => (ρ n).prod (standardArrayLaw (Fin n ⊕ Unit))) + (fun n z i => sampledRawAnswer (U n z.1) (Y n z.1) (fun j => g (X n z.1 j)) z.2 i) := by + let f : Option (Fin r) → ((E × ℝ) × ℝ) → ℝ := fun a => + a.elim Prod.snd (fun a z => y a z.1.1) + let C : ∀ n, H n → Option (Fin r) → ℝ := fun n h a => a.elim + (Real.sqrt ((∑ i, (residualProjection (U n h) *ᵥ (fun j => g (X n h j))) i^2)/(n:ℝ))) + (fun a => (∑ i, u a (X n h i)*g (X n h i))/(n:ℝ)) + let c' : Option (Fin r) → ℝ := fun a => a.elim (Real.sqrt s) c + have hcoef : ExponentialConvergence ρ C c' := by + apply ExponentialConvergence.pi_finite + intro a + cases a with + | none => exact hS.continuous_map Real.continuous_sqrt.continuousAt + | some a => exact hC.continuous_map (continuous_apply a).continuousAt + have hf : ∀ a, LipschitzWith K (f a) := by + intro a + cases a with + | none => exact LipschitzWith.prod_snd.weaken hK + | some a => + simpa only [f,Option.elim_some,Function.comp_def,mul_one] using + ((hy a).comp LipschitzWith.prod_fst).comp LipschitzWith.prod_fst + have ht := hX.append_unbounded_linear f hf + (fun a => by + cases a with + | none => exact hWT + | some a => exact (hyT a).prod_fst (fun n => standardArrayLaw (Fin n ⊕ Unit))) + (fun a => by cases a with | none => exact hWi | some a => exact hyi a) + (fun n z => C n z.1) c' (hcoef.prod_fst (fun n => standardArrayLaw (Fin n ⊕ Unit))) + simp only [f,C,c',Fintype.sum_option,Option.elim_none,Option.elim_some] at ht + have he : ∀ᶠ n in atTop, ∀ z : H n × ((Fin n ⊕ Unit) → ℝ), ∀ i : Fin n, + Real.sqrt ((∑ j, (residualProjection (U n z.1) *ᵥ (fun k => g (X n z.1 k))) j^2)/(n:ℝ))* + (Real.sqrt n*regeneratedAnswer (U n z.1) (Y n z.1) + (unitVector (residualProjection (U n z.1) *ᵥ (fun k => g (X n z.1 k)))) z.2 i)+ + ∑ a, ((∑ j, u a (X n z.1 j)*g (X n z.1 j))/(n:ℝ))*y a (X n z.1 i) = + sampledRawAnswer (U n z.1) (Y n z.1) (fun j => g (X n z.1 j)) z.2 i := by + filter_upwards [eventually_ge_atTop 1] with n hn + intro z i + have h := sampledRawAnswer_scaled hn (U n z.1) (Y n z.1) (fun j => g (X n z.1 j)) z.2 i + simpa only [heu,hey] using h.symm + constructor + · apply ht.1.congr_eventually + filter_upwards [he] with n hn + funext z i + congr 1 + exact hn z i + · apply ht.2.congr_eventually + filter_upwards [he] with n hn + funext z i + exact hn z i + +theorem ExponentialEmpiricalConcentration.sampled_full_query + {E : Type*} [PseudoMetricSpace E] [MeasurableSpace E] [BorelSpace E] + [SecondCountableTopology E] + {H : ℕ → Type*} [∀ n, MeasurableSpace (H n)] + (ρ : ∀ n, Measure (H n)) [∀ n, IsProbabilityMeasure (ρ n)] + (ν : Measure E) [IsProbabilityMeasure ν] + (X : ∀ n, H n → Fin n → E) (hXm : ∀ n, Measurable (X n)) + (hX : ExponentialEmpiricalConcentration ρ X ν) + (r : ℕ) (U Y : ∀ n, H n → Matrix (Fin n) (Fin r) ℝ) + (hUm : ∀ n, Measurable (U n)) + (hU : ∀ n h a, ∑ i, U n h i a^2 ≤ 1) + (u y : Fin r → E → ℝ) (g : E → ℝ) {K : ℝ≥0} (hK : 1 ≤ K) + (hu : ∀ a, LipschitzWith K (u a)) (hy : ∀ a, LipschitzWith K (y a)) + (hg : LipschitzWith K g) + (huT : ∀ a, ExponentialSquareTails ρ (fun n h i => u a (X n h i))) + (hyT : ∀ a, ExponentialSquareTails ρ (fun n h i => y a (X n h i))) + (hgT : ExponentialSquareTails ρ (fun n h i => g (X n h i))) + (hui : ∀ a, Integrable (fun x => u a x^2) ν) + (hyi : ∀ a, Integrable (fun x => y a x^2) ν) (hgi : Integrable (fun x => g x^2) ν) + (heu : ∀ (n : ℕ) h i a, Real.sqrt n*U n h i a=u a (X n h i)) + (hey : ∀ (n : ℕ) h i a, Real.sqrt n*Y n h i a=y a (X n h i)) + (hs : 0 < ∫ x, residualRecipe u g (fun a => ∫ z, u a z*g z ∂ν) x^2 ∂ν) : + + let R := fun n h => residualProjection (U n h) *ᵥ (fun i => g (X n h i)) + let q := fun n h => unitVector (R n h) + let c := fun a => ∫ x, u a x*g x ∂ν + let s := ∫ x, residualRecipe u g c x^2 ∂ν + let W := fun n (z : H n × ((Fin n ⊕ Unit) → ℝ)) i => + Real.sqrt n*regeneratedAnswer (U n z.1) (Y n z.1) (q n z.1) z.2 i + ExponentialConvergence ρ (fun n h => (∑ i, R n h i^2)/(n:ℝ)) s ∧ + ExponentialEmpiricalConcentration + (fun n => (ρ n).prod (standardArrayLaw (Fin n ⊕ Unit))) + (fun n z i => (((X n z.1 i,Real.sqrt n*q n z.1 i),W n z i), + sampledRawAnswer (U n z.1) (Y n z.1) (fun j => g (X n z.1 j)) z.2 i)) + ((normalizedRecipeLaw ν u y g).map (fun z => (z, Real.sqrt s*z.2+∑ a, c a*y a z.1.1))) ∧ + ExponentialSquareTails ρ (fun n h i => Real.sqrt n*q n h i) ∧ + ExponentialSquareTails (fun n => (ρ n).prod (standardArrayLaw (Fin n ⊕ Unit))) W ∧ + ExponentialSquareTails (fun n => (ρ n).prod (standardArrayLaw (Fin n ⊕ Unit))) + (fun n z i => sampledRawAnswer (U n z.1) (Y n z.1) (fun j => g (X n z.1 j)) z.2 i) := by + dsimp only + have h := hX.regenerated_nondegenerate_step ρ ν X hXm r U Y hUm hU + u y g hK hu hy hg huT hyT hgT hui hyi hgi heu hey hs + dsimp only at h + let : IsProbabilityMeasure (normalizedRecipeLaw ν u y g) := + normalizedRecipeLaw_probability ν u y g (fun a => (hu a).continuous.measurable) hg.continuous.measurable + have hm := normalizedRecipeLaw_moments ν u y g + (fun a => (hu a).continuous.measurable) (fun a => (hy a).continuous.measurable) + hg.continuous.measurable hui hyi hgi + have hC : ExponentialConvergence ρ + (fun n h a => (∑ i, u a (X n h i)*g (X n h i))/(n:ℝ)) + (fun a => ∫ x, u a x*g x ∂ν) := by + apply ExponentialConvergence.pi_finite + intro a + exact hX.product_average (u a) g (hu a) hg (huT a) hgT (hui a) hgi + have hh := h.2.1.sampled_unnormalized_assembly ρ X U Y u y g hK hy hyT heu hey (fun a => ∫ x, u a x*g x ∂ν) + (∫ x, residualRecipe u g (fun a => ∫ z, u a z*g z ∂ν) x^2 ∂ν) + hC h.1 (normalizedRecipeLaw ν u y g) h.2.2.2 hm.2.1 hm.2.2.2 + exact ⟨h.1,hh.1,h.2.2.1,h.2.2.2,hh.2⟩ + +end SKGapCutoff.Regression + +open Filter MeasureTheory ProbabilityTheory +open scoped Topology NNReal ENNReal + +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/PartitionChangeMeasure.lean b/lean/OAI/Probability/SKGap/Localization/PartitionChangeMeasure.lean new file mode 100644 index 0000000000000000000000000000000000000000..c88b5d97caba7a472a6a1d801e13996f500c6325 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/PartitionChangeMeasure.lean @@ -0,0 +1,65 @@ +import Mathlib +import OAI.Probability.SKGap.Model + +namespace OAI + +section +noncomputable section +namespace SKGap +open MeasureTheory ProbabilityTheory Real Set Filter +open scoped Topology + +lemma weighted_markov_transfer {Ω : Type*} [MeasurableSpace Ω] + (μ : Measure Ω) [IsFiniteMeasure μ] (L p : Ω→ℝ) + (hL : ∀ x,0 ≤ L x) (hp : ∀ x,0 ≤ p x) + (hi : Integrable (fun x=>L x*p x) μ) {l v : ℝ} (hl : 0 < l) (hv : 0 < v) : + μ.real {x | v < p x} ≤ μ.real {x | L x < l}+(∫ x,L x*p x ∂μ)/(l*v) := by + have hs : {x | v < p x} ⊆ {x | L x < l} ∪ {x | l*v ≤ L x*p x} := by + intro x hx + by_cases hh : L x < l + · exact Or.inl hh + · exact Or.inr (mul_le_mul (not_lt.mp hh) hx.le hv.le (hL x)) + have hm := mul_meas_ge_le_integral_of_nonneg + (ae_of_all μ (fun x=>mul_nonneg (hL x) (hp x))) hi (l*v) + have hm' : μ.real {x | l*v ≤ L x*p x} ≤ (∫ x,L x*p x ∂μ)/(l*v) := by + apply (le_div_iff₀ (mul_pos hl hv)).mpr + rwa [mul_comm] + exact (measureReal_mono hs (measure_ne_top _ _)).trans + ((measureReal_union_le _ _).trans (add_le_add_right hm' _)) + +lemma exponential_size_bias_transfer + {Ω : ℕ→Type*} [∀ n,MeasurableSpace (Ω n)] + (μ : ∀ n,Measure (Ω n)) [∀ n,IsProbabilityMeasure (μ n)] + (L p : ∀ n,Ω n→ℝ) + (hL : ∀ n x,0 ≤ L n x) (hp : ∀ n x,0 ≤ p n x) + (hi : ∀ n,Integrable (fun x=>L n x*p n x) (μ n)) + {a C : ℝ} (ha : 0 < a) (_hC : 0 ≤ C) + (htail : Tendsto (fun n=>(μ n).real {x | L n x < exp (-(a/4)*(n:ℝ))}) atTop (𝓝 0)) + (hann : ∀ᶠ n : ℕ in atTop,(∫ x,L n x*p n x ∂μ n) ≤ C*exp (-a*(n:ℝ))) : + Tendsto (fun n=>(μ n).real {x | exp (-(a/4)*(n:ℝ)) < p n x}) atTop (𝓝 0) := by + have hn : ∀ᶠ n : ℕ in atTop,(μ n).real {x | exp (-(a/4)*(n:ℝ)) < p n x} ≤ + (μ n).real {x | L n x < exp (-(a/4)*(n:ℝ))}+C*exp (-(a/2)*(n:ℝ)) := by + filter_upwards [hann] with n hn + have hh := weighted_markov_transfer (μ n) (L n) (p n) (hL n) (hp n) (hi n) + (exp_pos (-(a/4)*(n:ℝ))) (exp_pos (-(a/4)*(n:ℝ))) + apply hh.trans + apply add_le_add_right + apply (div_le_iff₀ (mul_pos (exp_pos _) (exp_pos _))).mpr + apply hn.trans_eq + rw [mul_assoc,← exp_add,← exp_add] + congr 2 + ring + have he : Tendsto (fun n : ℕ=>C*exp (-(a/2)*(n:ℝ))) atTop (𝓝 0) := by + have hh : Tendsto (fun n : ℕ=>(a/2)*(n:ℝ)) atTop atTop := + tendsto_natCast_atTop_atTop.const_mul_atTop (by positivity : 0 < a/2) + have hx := tendsto_exp_neg_atTop_nhds_zero.comp hh + have hce := hx.const_mul C + simpa only [mul_zero,neg_mul,Function.comp_def] using hce + have ht := htail.add he + rw [add_zero] at ht + exact squeeze_zero' (Eventually.of_forall (fun _=>measureReal_nonneg)) hn ht +end SKGap +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/PartitionLogLipschitz.lean b/lean/OAI/Probability/SKGap/Localization/PartitionLogLipschitz.lean new file mode 100644 index 0000000000000000000000000000000000000000..b8299a62a721bd2496a09ccfef54a4b0f4c09668 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/PartitionLogLipschitz.lean @@ -0,0 +1,54 @@ +import Mathlib +import OAI.Probability.SKGap.Gaussian.PartitionSecondMoment + +namespace OAI + +section +noncomputable section +namespace SKGap +open MeasureTheory ProbabilityTheory Real +open scoped BigOperators NNReal + +lemma finite_linear_lipschitz {κ : Type*} [Fintype κ] (a : κ→ℝ) {L : ℝ≥0} + (ha : (∑ i,a i^2) ≤ (L:ℝ)^2) : + LipschitzWith L (fun x : EuclideanSpace ℝ κ=>∑ i,a i*x i) := by + have hn : ‖(WithLp.toLp 2 a : EuclideanSpace ℝ κ)‖ ≤ (L:ℝ) := by + apply (sq_le_sq₀ (norm_nonneg _) (NNReal.coe_nonneg _)).mp + simpa only [EuclideanSpace.real_norm_sq_eq,PiLp.toLp_apply] using ha + apply LipschitzWith.of_dist_le_mul + intro x y + have hh := norm_inner_le_norm (𝕜:=ℝ) (WithLp.toLp 2 a : EuclideanSpace ℝ κ) (x-y) + have he : inner ℝ (WithLp.toLp 2 a : EuclideanSpace ℝ κ) (x-y)= + (∑ i,a i*x i)-(∑ i,a i*y i) := by + simp only [EuclideanSpace.inner_eq_star_dotProduct,star_trivial] + change (∑ i,(x i-y i)*a i)=(∑ i,a i*x i)-(∑ i,a i*y i) + rw [← Finset.sum_sub_distrib] + apply Finset.sum_congr rfl + intro i _ + ring + rw [Real.dist_eq,← he] + exact hh.trans ((mul_le_mul_of_nonneg_right hn (norm_nonneg _)).trans_eq (by rw [dist_eq_norm])) + +lemma edge_card_real_le_square (n : ℕ) : (Fintype.card (Edge n):ℝ) ≤ (n:ℝ)^2 := by + have h := Fintype.card_subtype_le (fun p : Fin n×Fin n=>p.1 < p.2) + simp only [Fintype.card_prod,Fintype.card_fin] at h + exact_mod_cast (show Fintype.card (Edge n) ≤ n^2 by simpa only [sq] using h) + +lemma gaussianSpinPartition_log_lipschitz {n : ℕ} {r : ℝ} (hr : 0 ≤ r) + (hnr : (n:ℝ)*r ≤ 1) : + LipschitzWith ⟨sqrt (n:ℝ),sqrt_nonneg _⟩ (fun x : EuclideanSpace ℝ (Edge n)=> + log (gaussianSpinPartition n r x.ofLp)) := by + change LipschitzWith ⟨sqrt (n:ℝ),sqrt_nonneg _⟩ (fun g : EuclideanSpace ℝ (Edge n)=> + log (∑ x : Spin n,exp (∑ e,edgeCoefficient r x e*g e))) + refine log_sum_exp_lipschitz (fun (x : Spin n) (g : EuclideanSpace ℝ (Edge n))=>∑ e,edgeCoefficient r x e*g e) ?_ + intro x + apply finite_linear_lipschitz + change (∑ e,edgeCoefficient r x e^2) ≤ (sqrt (n:ℝ))^2 + rw [edgeCoefficient_sq_sum hr,sq_sqrt (by positivity)] + have hh := mul_le_mul_of_nonneg_left (edge_card_real_le_square n) hr + nlinarith [mul_le_mul_of_nonneg_right hnr (show (0:ℝ) ≤ n by positivity)] +end SKGap +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/PhiAlgebra.lean b/lean/OAI/Probability/SKGap/Localization/PhiAlgebra.lean new file mode 100644 index 0000000000000000000000000000000000000000..3740b39a2eb7d313835bdd0bf8af9d5aa61eac59 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/PhiAlgebra.lean @@ -0,0 +1,159 @@ +import Mathlib +import OAI.Probability.SKGap.Terminal.FiniteSpinCalculus +import OAI.Probability.SKGap.Localization.CoordinateDeriv +import OAI.Probability.SKGap.Gaussian.PhiMoments + +namespace OAI + +section + +noncomputable section +namespace SKGap.Stein + +inductive KernelExpr where + | atom (p q : ℕ) (b : Bool) + | add (f g : KernelExpr) + | scale (c : ℝ) (f : KernelExpr) + | tz (f : KernelExpr) + | tr (f : KernelExpr) + +namespace KernelExpr + +def eval : KernelExpr → ℝ → ℝ → ℝ → ℝ + | atom p q b,z,r,a => moment p q b z r a + | add f g,z,r,a => eval f z r a+eval g z r a + | scale c f,z,r,a => c*eval f z r a + | tz f,z,r,a => Real.tanh z*eval f z r a + | tr f,z,r,a => Real.tanh r*eval f z r a + +def mass : KernelExpr → ℝ + | atom _ _ _ => 1 + | add f g => mass f+mass g + | scale c f => |c| *mass f + | tz f => mass f + | tr f => mass f + +lemma mass_nonneg (f : KernelExpr) : 0 ≤ mass f := by + induction f <;> simp only [mass] <;> positivity + +lemma relative_bound (f : KernelExpr) (z r a : ℝ) : |eval f z r a| ≤ mass f*phi z r a := by + induction f with + | atom p q b => simpa only [eval,mass,one_mul] using moment_relative_bound p q b z r a + | add f g hf hg => + exact (abs_add_le _ _).trans (by simpa only [eval,mass,add_mul] using add_le_add hf hg) + | scale c f hf => + dsimp only [eval,mass] + rw [abs_mul,mul_assoc] + exact mul_le_mul_of_nonneg_left hf (abs_nonneg c) + | tz f hf => + dsimp only [eval,mass] + rw [abs_mul] + exact (mul_le_mul_of_nonneg_right (Real.abs_tanh_lt_one z).le (abs_nonneg _)).trans + (by simpa only [one_mul] using hf) + | tr f hf => + dsimp only [eval,mass] + rw [abs_mul] + exact (mul_le_mul_of_nonneg_right (Real.abs_tanh_lt_one r).le (abs_nonneg _)).trans + (by simpa only [one_mul] using hf) + +def dz : KernelExpr → KernelExpr + | atom p q b => add (atom (p+1) q (!b)) (scale (-1) (tz (atom p q b))) + | add f g => add (dz f) (dz g) + | scale c f => scale c (dz f) + | tz f => add (add f (scale (-1) (tz (tz f)))) (tz (dz f)) + | tr f => tr (dz f) + +def dr : KernelExpr → KernelExpr + | atom p q b => add (scale (-1) (atom (p+1) q (!b))) (scale (-1) (tr (atom p q b))) + | add f g => add (dr f) (dr g) + | scale c f => scale c (dr f) + | tz f => tz (dr f) + | tr f => add (add f (scale (-1) (tr (tr f)))) (tr (dr f)) + +def da : KernelExpr → KernelExpr + | atom p q b => atom p (q+1) b + | add f g => add (da f) (da g) + | scale c f => scale c (da f) + | tz f => tz (da f) + | tr f => tr (da f) + +lemma hasDerivAt_z (f : KernelExpr) (z r a : ℝ) : + HasDerivAt (fun z => eval f z r a) (eval (dz f) z r a) z := by + induction f with + | atom p q b => simpa only [eval,dz,neg_mul,one_mul,←sub_eq_add_neg] using moment_hasDerivAt_z p q b z r a + | add f g hf hg => exact hf.add hg + | scale c f hf => exact hf.const_mul c + | tz f hf => + convert! (SKGapCutoff.tanh_hasDerivAt z).mul hf using 1 + dsimp only [eval,dz,SKGapCutoff.scalarVariance] + ring + | tr f hf => exact hf.const_mul _ + +lemma hasDerivAt_r (f : KernelExpr) (z r a : ℝ) : + HasDerivAt (fun r => eval f z r a) (eval (dr f) z r a) r := by + induction f with + | atom p q b => simpa only [eval,dr,neg_mul,one_mul,←sub_eq_add_neg] using moment_hasDerivAt_r p q b z r a + | add f g hf hg => exact hf.add hg + | scale c f hf => exact hf.const_mul c + | tz f hf => exact hf.const_mul _ + | tr f hf => + convert! (SKGapCutoff.tanh_hasDerivAt r).mul hf using 1 + dsimp only [eval,dr,SKGapCutoff.scalarVariance] + ring + +lemma hasDerivAt_a (f : KernelExpr) (z r a : ℝ) : + HasDerivAt (fun a => eval f z r a) (eval (da f) z r a) a := by + induction f with + | atom p q b => exact moment_hasDerivAt_a p q b z r a + | add f g hf hg => exact hf.add hg + | scale c f hf => exact hf.const_mul c + | tz f hf => exact hf.const_mul _ + | tr f hf => exact hf.const_mul _ + +end KernelExpr + +inductive Axis where | z | r | a + +def coordinateDeriv (i : Axis) (F : ℝ→ℝ→ℝ→ℝ) : ℝ→ℝ→ℝ→ℝ := match i with + | .z => fun z r a => deriv (fun z => F z r a) z + | .r => fun z r a => deriv (fun r => F z r a) r + | .a => fun z r a => deriv (fun a => F z r a) a + +def mixed (l : List Axis) (F : ℝ→ℝ→ℝ→ℝ) : ℝ→ℝ→ℝ→ℝ := match l with + | [] => F + | i::l => coordinateDeriv i (mixed l F) + +namespace KernelExpr + +def d (i : Axis) : KernelExpr → KernelExpr := match i with + | .z => dz | .r => dr | .a => da + +def mixedExpr (l : List Axis) (f : KernelExpr) : KernelExpr := match l with + | [] => f + | i::l => d i (mixedExpr l f) + +lemma partial_eval (i : Axis) (f : KernelExpr) : coordinateDeriv i (eval f)=eval (d i f) := by + funext z r a + cases i with + | z => exact (hasDerivAt_z f z r a).deriv + | r => exact (hasDerivAt_r f z r a).deriv + | a => exact (hasDerivAt_a f z r a).deriv + +lemma mixed_eval (l : List Axis) (f : KernelExpr) : mixed l (eval f)=eval (mixedExpr l f) := by + induction l with + | nil => rfl + | cons i l ih => rw [mixed,ih,partial_eval]; rfl + +theorem all_mixed_relative_bound (l : List Axis) (z r a : ℝ) : + |mixed l phi z r a| ≤ mass (mixedExpr l (atom 0 0 false))*phi z r a := by + have he : phi=eval (atom 0 0 false) := funext fun z => funext fun r => funext fun a => (moment_base z r a).symm + rw [he,mixed_eval] + simpa only [eval,moment_base] using relative_bound (mixedExpr l (atom 0 0 false)) z r a + +end KernelExpr +end SKGap.Stein + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/PhiBounds.lean b/lean/OAI/Probability/SKGap/Localization/PhiBounds.lean new file mode 100644 index 0000000000000000000000000000000000000000..dffb6943106802433f72bb1c5bc119af307bfce6 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/PhiBounds.lean @@ -0,0 +1,172 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.ScalarVariance +import OAI.Probability.SKGap.Gaussian.PhiStein + +namespace OAI + +section + +noncomputable section +open MeasureTheory +namespace SKGap.Stein + +lemma phi_zero_diagonal (r : ℝ) : phi r r 0=1/(Real.cosh r)^2 := by + simp [phi,weight,pow_two] + +lemma phi_zero_le_one (z r : ℝ) : phi z r 0≤1 := by + by_cases h : z=r + · subst z + rw [phi_zero_diagonal,←SKGapCutoff.scalarVariance_eq] + exact SKGapCutoff.scalarVariance_le_one _ + · have H:=phi_stein z r 0 + simp only [zero_mul,sub_zero] at H + have H':=congrArg abs H + rw [abs_mul,abs_of_pos (phi_pos z r 0)] at H' + have hz : 0 < |z-r| := abs_pos.mpr (sub_ne_zero.mpr h) + have hl:=SKGapCutoff.tanh_lipschitz r z + nlinarith + +lemma weight_le (a u : ℝ) (hu : u∈Set.Icc (0:ℝ) 1) : weight a u≤Real.exp (|a|/2) := by + unfold weight + apply Real.exp_le_exp.mpr + have hu2 : u^2≤1 := by nlinarith [hu.1,hu.2] + have hm : a*(1-u^2)≤|a| := by + calc + _ ≤ |a| *(1-u^2) := mul_le_mul_of_nonneg_right (le_abs_self _) (by linarith) + _ ≤ |a| *1 := mul_le_mul_of_nonneg_left (by nlinarith [sq_nonneg u]) (abs_nonneg _) + _ = |a| := mul_one _ + linarith + +lemma continuous_integrand (z r a : ℝ) : Continuous (fun u=> + weight a u*Real.cosh (u*(z-r))/(Real.cosh z*Real.cosh r)) := by + exact Continuous.div_const ((continuous_weight a).mul (by fun_prop)) _ + +lemma phi_le_exp (z r a : ℝ) : phi z r a≤Real.exp (|a|/2) := by + have H:=intervalIntegral.integral_mono_on (μ:=volume) (a:=(0:ℝ)) (b:=1) (by norm_num) + ((continuous_integrand z r a).intervalIntegrable 0 1) + (((continuous_integrand z r 0).const_mul (Real.exp (|a|/2))).intervalIntegrable 0 1) + (by + intro u hu + simp only [weight,zero_mul,zero_div,Real.exp_zero,one_mul] + rw [←mul_div_assoc] + apply div_le_div_of_nonneg_right _ (le_of_lt (mul_pos (Real.cosh_pos _) (Real.cosh_pos _))) + exact mul_le_mul_of_nonneg_right (weight_le a u hu) (Real.cosh_pos _).le) + rw [intervalIntegral.integral_const_mul] at H + exact H.trans ((mul_le_mul_of_nonneg_left (phi_zero_le_one z r) (Real.exp_pos _).le).trans_eq (mul_one _)) + +lemma abs_sinh_le_cosh (t : ℝ) : |Real.sinh t|≤Real.cosh t := by + have h:=Real.cosh_sq_sub_sinh_sq t + have ha:=sq_abs (Real.sinh t) + nlinarith [Real.cosh_pos t,abs_nonneg (Real.sinh t)] + +lemma numerator_pos (z r a : ℝ) : 0.mul continuous_id).mul (by fun_prop) |>.abs).intervalIntegrable _ _ + · exact ((continuous_weight a).mul (by fun_prop)).intervalIntegrable _ _ + · intro u hu + rw [abs_mul,abs_mul,abs_of_pos (show 0numeratorZ z r a) (numeratorZZ z r a) z := by + unfold numeratorZ numeratorZZ + apply hasDerivAt_integral01 (F:=fun z u=>weight a u*u*Real.sinh (u*(z-r))) + (F':=fun z u=>weight a u*u^2*Real.cosh (u*(z-r))) + · unfold weight; fun_prop + · unfold weight; fun_prop + · intro z u + convert! ((Real.hasDerivAt_sinh (u*(z-r))).comp z + (((hasDerivAt_id z).sub_const r).const_mul u)).const_mul (weight a u*u) using 1 + ring + +lemma numeratorZZ_nonneg (z r a : ℝ) : 0≤numeratorZZ z r a := by + apply intervalIntegral.integral_nonneg (by norm_num : (0:ℝ)≤1) + intro u _; exact mul_nonneg (mul_nonneg (Real.exp_pos _).le (sq_nonneg _)) (Real.cosh_pos _).le + +lemma numeratorZZ_le (z r a : ℝ) : numeratorZZ z r a≤numerator z r a := by + apply intervalIntegral.integral_mono_on (by norm_num : (0:ℝ)≤1) + · apply Continuous.intervalIntegrable; unfold weight; fun_prop + · exact ((continuous_weight a).mul (by fun_prop)).intervalIntegrable _ _ + · intro u hu + have hu2 : u^2≤1 := by nlinarith [hu.1,hu.2] + have H:=mul_le_mul_of_nonneg_left hu2 + (mul_pos (Real.exp_pos (a*(1-u^2)/2)) (Real.cosh_pos (u*(z-r)))).le + dsimp [weight] at * + nlinarith only [H] + +def logSlope (z r a : ℝ) : ℝ := phiZ z r a/phi z r a + +def logSlopeZ (z r a : ℝ) : ℝ := numeratorZZ z r a/numerator z r a- + (numeratorZ z r a/numerator z r a)^2-SKGapCutoff.scalarVariance z + +lemma logSlope_eq (z r a : ℝ) : logSlope z r a= + numeratorZ z r a/numerator z r a-Real.tanh z := by + rw [logSlope,phiZ,phi_eq] + field_simp [ne_of_gt (numerator_pos z r a),ne_of_gt (Real.cosh_pos z),ne_of_gt (Real.cosh_pos r)] + +lemma logSlope_hasDerivAt (z r a : ℝ) : + HasDerivAt (fun z=>logSlope z r a) (logSlopeZ z r a) z := by + have H:=((numeratorZ_hasDerivAt z r a).div (numerator_hasDerivAt z r a) + (ne_of_gt (numerator_pos z r a))).sub (SKGapCutoff.tanh_hasDerivAt z) + convert! H using 1 + · funext x; exact logSlope_eq x r a + · unfold logSlopeZ + field_simp [ne_of_gt (numerator_pos z r a)] + +lemma logSlopeZ_bound (z r a : ℝ) : |logSlopeZ z r a|≤3 := by + have hN : 0 nlinarith [SKGapCutoff.scalarVariance_pos z,SKGapCutoff.scalarVariance_le_one z, + sq_nonneg (numeratorZ z r a/numerator z r a)] + +lemma logSlope_lipschitz (z z' r a : ℝ) : |logSlope z' r a-logSlope z r a|≤3*|z'-z| := by + have H:=Convex.norm_image_sub_le_of_norm_hasDerivWithin_le + (fun q (_ : q∈(Set.univ : Set ℝ))=>(logSlope_hasDerivAt q r a).hasDerivWithinAt) + (fun q _=>show ‖logSlopeZ q r a‖≤3 by simpa only [Real.norm_eq_abs] using logSlopeZ_bound q r a) + convex_univ (Set.mem_univ z) (Set.mem_univ z') + simpa only [Real.norm_eq_abs] using H + +lemma logSlope_diagonal (r a : ℝ) : logSlope r r a= -Real.tanh r := by + rw [logSlope,phiZ_at_diagonal] + exact mul_div_cancel_right₀ _ (ne_of_gt (phi_pos r r a)) + +theorem logSlope_near_diagonal (z r a : ℝ) : |logSlope z r a+Real.tanh r|≤3*|z-r| := by + simpa only [logSlope_diagonal,sub_neg_eq_add] using logSlope_lipschitz r z r a + +end SKGap.Stein + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/PhiCoefficient.lean b/lean/OAI/Probability/SKGap/Localization/PhiCoefficient.lean new file mode 100644 index 0000000000000000000000000000000000000000..d89fb53c3fb0f4430f41a299565a7fcf19b20805 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/PhiCoefficient.lean @@ -0,0 +1,94 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.PhiBounds + +namespace OAI + +section + +noncomputable section +open MeasureTheory +namespace SKGap.Stein + +def phiA (z r a : ℝ) : ℝ := ∫u in (0:ℝ)..1, + ((1-u^2)/2)*(weight a u*Real.cosh (u*(z-r))/(Real.cosh z*Real.cosh r)) + +lemma phi_hasDerivAt_a (z r a : ℝ) : HasDerivAt (fun a=>phi z r a) (phiA z r a) a := by + unfold phi phiA + apply hasDerivAt_integral01 + (F:=fun a u=>weight a u*Real.cosh (u*(z-r))/(Real.cosh z*Real.cosh r)) + (F':=fun a u=>((1-u^2)/2)*(weight a u*Real.cosh (u*(z-r))/(Real.cosh z*Real.cosh r))) + · unfold weight; fun_prop + · unfold weight; fun_prop + · intro a u + have h:=((((hasDerivAt_id a).mul_const (1-u^2)).div_const 2).exp.mul_const + (Real.cosh (u*(z-r)))).div_const (Real.cosh z*Real.cosh r) + convert! h using 1 + try dsimp [weight] + ring + +lemma phiA_nonneg (z r a : ℝ) : 0≤phiA z r a := by + apply intervalIntegral.integral_nonneg (by norm_num : (0:ℝ)≤1) + intro u hu + have hu2 : u^2≤1 := by nlinarith [hu.1,hu.2] + apply mul_nonneg (by linarith) + exact div_nonneg (mul_pos (Real.exp_pos _) (Real.cosh_pos _)).le + (mul_pos (Real.cosh_pos _) (Real.cosh_pos _)).le + +lemma phiA_relative_bound (z r a : ℝ) : phiA z r a≤phi z r a/2 := by + have H:=intervalIntegral.integral_mono_on (μ:=volume) (a:=(0:ℝ)) (b:=1) (by norm_num) + (f:=fun u=>((1-u^2)/2)*(weight a u*Real.cosh (u*(z-r))/(Real.cosh z*Real.cosh r))) + (g:=fun u=>(weight a u*Real.cosh (u*(z-r))/(Real.cosh z*Real.cosh r))/2) + (by apply Continuous.intervalIntegrable; unfold weight; fun_prop) + (((continuous_integrand z r a).div_const 2).intervalIntegrable _ _) + (by + intro u hu + have hp : 0≤weight a u*Real.cosh (u*(z-r))/(Real.cosh z*Real.cosh r) := by + apply div_nonneg (mul_pos (Real.exp_pos _) (Real.cosh_pos _)).le + exact (mul_pos (Real.cosh_pos _) (Real.cosh_pos _)).le + nlinarith [mul_nonneg (sq_nonneg u) hp]) + simpa only [intervalIntegral.integral_div,phiA,phi] using H + +lemma phi_lipschitz_z (z z' r a : ℝ) : + |phi z' r a-phi z r a|≤(2*Real.exp (|a|/2))*|z'-z| := by + have H:=Convex.norm_image_sub_le_of_norm_hasDerivWithin_le + (fun q (_ : q∈(Set.univ : Set ℝ))=>(phi_hasDerivAt q r a).hasDerivWithinAt) + (fun q _=>show ‖phiZ q r a‖≤2*Real.exp (|a|/2) by + rw [Real.norm_eq_abs] + exact (phiZ_relative_bound q r a).trans (by nlinarith [phi_le_exp q r a])) + convex_univ (Set.mem_univ z) (Set.mem_univ z') + simpa only [Real.norm_eq_abs] using H + +lemma phi_lipschitz_a (z r a : ℝ) : + |phi z r a-phi z r 0|≤(Real.exp (|a|/2)/2)*|a| := by + have H:=Convex.norm_image_sub_le_of_norm_hasDerivWithin_le + (fun q (_ : q∈Set.Icc (-|a|) |a|)=>(phi_hasDerivAt_a z r q).hasDerivWithinAt) + (fun q hq=>show ‖phiA z r q‖≤Real.exp (|a|/2)/2 by + rw [Real.norm_eq_abs,abs_of_nonneg (phiA_nonneg _ _ _)] + have hq' : |q|≤|a| := abs_le.mpr hq + have he : Real.exp (|q|/2)≤Real.exp (|a|/2) := Real.exp_le_exp.mpr (by linarith) + exact (phiA_relative_bound z r q).trans (by linarith [phi_le_exp z r q])) + (convex_Icc (-|a|) |a|) + (show (0:ℝ)∈Set.Icc (-|a|) |a| by constructor <;> linarith [abs_nonneg a]) + (show a∈Set.Icc (-|a|) |a| from ⟨neg_abs_le a,le_abs_self a⟩) + simpa only [Real.norm_eq_abs,sub_zero] using H + +theorem phi_near_root (z r a : ℝ) : + |phi z r a-SKGapCutoff.scalarVariance r|≤ + Real.exp (|a|/2)*(2*|z-r|+|a|/2) := by + have he : phi r r 0=SKGapCutoff.scalarVariance r := by + rw [phi_zero_diagonal,SKGapCutoff.scalarVariance_eq] + have h1:=phi_lipschitz_z r z r a + have h2:=phi_lipschitz_a r r a + have h3:=abs_add_le (phi z r a-phi r r a) (phi r r a-phi r r 0) + rw [he] at h2 h3 + have hh : phi z r a-phi r r a+(phi r r a-SKGapCutoff.scalarVariance r)= + phi z r a-SKGapCutoff.scalarVariance r := by ring + rw [hh] at h3 + nlinarith only [h1,h2,h3] + +end SKGap.Stein + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/PhiFrechet.lean b/lean/OAI/Probability/SKGap/Localization/PhiFrechet.lean new file mode 100644 index 0000000000000000000000000000000000000000..f69e668800c91af931c81cfdada061d2195eae82 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/PhiFrechet.lean @@ -0,0 +1,215 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.ScalarParametersJoined +import OAI.Probability.SKGap.Localization.PhiRatio + +namespace OAI + +section + +noncomputable section +open Filter +open scoped Topology +namespace SKGap.Stein + +abbrev Triple := ℝ × (ℝ × ℝ) +def eval3 (F : ℝ→ℝ→ℝ→ℝ) (x : Triple) : ℝ := F x.1 x.2.1 x.2.2 + +def grad2 (a b : ℝ) : (ℝ×ℝ)→L[ℝ]ℝ := + (ContinuousLinearMap.toSpanSingleton ℝ a).coprod (ContinuousLinearMap.toSpanSingleton ℝ b) +def grad3 (a b c : ℝ) : Triple→L[ℝ]ℝ := + (ContinuousLinearMap.toSpanSingleton ℝ a).coprod (grad2 b c) + +lemma grad2_eq (a b : ℝ) : grad2 a b= + a • ContinuousLinearMap.fst ℝ ℝ ℝ+b • ContinuousLinearMap.snd ℝ ℝ ℝ := by + apply ContinuousLinearMap.ext; intro x; simp [grad2,ContinuousLinearMap.toSpanSingleton_apply,mul_comm] +lemma grad3_eq (a b c : ℝ) : grad3 a b c= + a • ContinuousLinearMap.fst ℝ ℝ (ℝ×ℝ)+ + (grad2 b c).comp (ContinuousLinearMap.snd ℝ ℝ (ℝ×ℝ)) := by + apply ContinuousLinearMap.ext; intro x; simp [grad3,ContinuousLinearMap.toSpanSingleton_apply,mul_comm] + +lemma continuous_grad2 : Continuous (fun x : ℝ×ℝ=>grad2 x.1 x.2) := by + simp only [grad2_eq]; fun_prop +lemma continuous_grad3 : Continuous (fun x : Triple=>grad3 x.1 x.2.1 x.2.2) := by + simp only [grad3_eq,grad2_eq]; fun_prop + +lemma hasFDerivAt_of_three_partials (F Fz Fr Fa : ℝ→ℝ→ℝ→ℝ) + (hz : ∀z r a,HasDerivAt (fun z=>F z r a) (Fz z r a) z) + (hr : ∀z r a,HasDerivAt (fun r=>F z r a) (Fr z r a) r) + (ha : ∀z r a,HasDerivAt (fun a=>F z r a) (Fa z r a) a) + (cz : Continuous (eval3 Fz)) (cr : Continuous (eval3 Fr)) (ca : Continuous (eval3 Fa)) + (x : Triple) : HasFDerivAt (eval3 F) (grad3 (eval3 Fz x) (eval3 Fr x) (eval3 Fa x)) x := by + have hpair (z : ℝ) (y : ℝ×ℝ) : HasFDerivAt (fun v : ℝ×ℝ=>F z v.1 v.2) + (grad2 (Fr z y.1 y.2) (Fa z y.1 y.2)) y := by + apply HasStrictFDerivAt.hasFDerivAt + apply hasStrictFDerivAt_uncurry_coprod + (f:=fun r a=>F z r a) + (f₁:=fun r a=>ContinuousLinearMap.toSpanSingleton ℝ (Fr z r a)) + (f₂:=fun r a=>ContinuousLinearMap.toSpanSingleton ℝ (Fa z r a)) + · exact Eventually.of_forall fun v=>(hr z v.1 v.2).hasFDerivAt + · exact Eventually.of_forall fun v=>(ha z v.1 v.2).hasFDerivAt + · exact ((ContinuousLinearMap.toSpanSingletonLIE ℝ ℝ).continuous.comp + (cr.comp (continuous_const.prodMk continuous_id))).continuousAt + · exact ((ContinuousLinearMap.toSpanSingletonLIE ℝ ℝ).continuous.comp + (ca.comp (continuous_const.prodMk continuous_id))).continuousAt + apply HasStrictFDerivAt.hasFDerivAt + apply hasStrictFDerivAt_uncurry_coprod + (f:=fun (z : ℝ) (v : ℝ×ℝ)=>F z v.1 v.2) + (f₁:=fun z v=>ContinuousLinearMap.toSpanSingleton ℝ (Fz z v.1 v.2)) + (f₂:=fun z v=>grad2 (Fr z v.1 v.2) (Fa z v.1 v.2)) + · exact Eventually.of_forall fun v=>(hz v.1 v.2.1 v.2.2).hasFDerivAt + · exact Eventually.of_forall fun v=>hpair v.1 v.2 + · exact ((ContinuousLinearMap.toSpanSingletonLIE ℝ ℝ).continuous.comp cz).continuousAt + · exact (continuous_grad2.comp (cr.prodMk ca)).continuousAt + +lemma continuous_momentNum (p q : ℕ) (b : Bool) : + Continuous (fun x : ℝ×ℝ=>momentNum p q b x.1 x.2) := by + unfold momentNum + apply intervalIntegral.continuous_parametric_intervalIntegral_of_continuous' + apply Continuous.mul + · unfold weight; fun_prop + · exact (continuous_hyper b).comp (continuous_snd.mul (continuous_fst.fst)) + +lemma continuous_moment (p q : ℕ) (b : Bool) : Continuous (eval3 (moment p q b)) := by + change Continuous (fun x : Triple=>momentNum p q b (x.1-x.2.1) x.2.2/(Real.cosh x.1*Real.cosh x.2.1)) + exact ((continuous_momentNum p q b).comp + ((continuous_fst.sub continuous_snd.fst).prodMk continuous_snd.snd)).div + ((Real.continuous_cosh.comp continuous_fst).mul (Real.continuous_cosh.comp continuous_snd.fst)) + (fun x=>(mul_pos (Real.cosh_pos _) (Real.cosh_pos _)).ne') + +lemma continuous_tanh : Continuous Real.tanh := + continuous_iff_continuousAt.mpr fun z=>(SKGapCutoff.tanh_hasDerivAt z).continuousAt + +namespace KernelExpr +lemma continuous_eval (f : KernelExpr) : Continuous (eval3 f.eval) := by + induction f with + | atom p q b => exact continuous_moment p q b + | add f g hf hg => exact hf.add hg + | scale c f hf => exact hf.const_mul c + | tz f hf => exact (continuous_tanh.comp continuous_fst).mul hf + | tr f hf => exact (continuous_tanh.comp continuous_snd.fst).mul hf + +def gradient (f : KernelExpr) (x : Triple) : Triple→L[ℝ]ℝ := + grad3 (eval3 f.dz.eval x) (eval3 f.dr.eval x) (eval3 f.da.eval x) + +lemma hasFDerivAt_eval (f : KernelExpr) (x : Triple) : + HasFDerivAt (eval3 f.eval) (f.gradient x) x := + hasFDerivAt_of_three_partials f.eval f.dz.eval f.dr.eval f.da.eval + f.hasDerivAt_z f.hasDerivAt_r f.hasDerivAt_a + f.dz.continuous_eval f.dr.continuous_eval f.da.continuous_eval x +end KernelExpr + +lemma grad3_norm (a b c : ℝ) : ‖grad3 a b c‖≤|a|+|b|+|c| := by + apply (grad3 a b c).opNorm_le_bound (by positivity) + intro x + have hz := norm_fst_le x + have hr := (norm_fst_le x.2).trans (norm_snd_le x) + have ha := (norm_snd_le x.2).trans (norm_snd_le x) + change |x.1*a+(x.2.1*b+x.2.2*c)|≤(|a|+|b|+|c|)*‖x‖ + calc + _ ≤ |x.1*a|+(|x.2.1*b|+|x.2.2*c|) := (abs_add_le _ _).trans + (add_le_add (le_refl _) (abs_add_le _ _)) + _ ≤ ‖x‖*|a|+(‖x‖*|b|+‖x‖*|c|) := by + simp only [abs_mul] + exact add_le_add (mul_le_mul_of_nonneg_right hz (abs_nonneg _)) + (add_le_add (mul_le_mul_of_nonneg_right hr (abs_nonneg _)) + (mul_le_mul_of_nonneg_right ha (abs_nonneg _))) + _ = _ := by ring + +lemma grad3_sub (a b c d e f : ℝ) : + grad3 a b c-grad3 d e f=grad3 (a-d) (b-e) (c-f) := by + apply ContinuousLinearMap.ext; intro x + simp only [grad3,grad2,sub_apply,ContinuousLinearMap.coprod_apply, + ContinuousLinearMap.toSpanSingleton_apply,smul_eq_mul] + ring + +def strip (R : ℝ) : Set Triple := {x | |x.2.2|≤R} +lemma convex_strip (R : ℝ) : Convex ℝ (strip R) := by + intro x hx y hy a b ha hb hab + change |a*x.2.2+b*y.2.2|≤R + calc + _ ≤ |a*x.2.2|+|b*y.2.2| := abs_add_le _ _ + _ = a*|x.2.2|+b*|y.2.2| := by rw [abs_mul,abs_mul,abs_of_nonneg ha,abs_of_nonneg hb] + _ ≤ a*R+b*R := add_le_add (mul_le_mul_of_nonneg_left hx ha) (mul_le_mul_of_nonneg_left hy hb) + _ = R := by rw [←add_mul,hab,one_mul] + +namespace KernelExpr +lemma absolute_bound (f : KernelExpr) {R : ℝ} {x : Triple} (hx : x∈strip R) : + |eval3 f.eval x|≤f.mass*Real.exp (R/2) := by + exact (f.relative_bound x.1 x.2.1 x.2.2).trans (mul_le_mul_of_nonneg_left + ((phi_le_exp ..).trans (Real.exp_le_exp.mpr (by dsimp [strip] at hx; linarith))) f.mass_nonneg) + +def dBudget (f : KernelExpr) (R : ℝ) : ℝ := + (f.dz.mass+f.dr.mass+f.da.mass)*Real.exp (R/2) +lemma dBudget_nonneg (f : KernelExpr) (R : ℝ) : 0≤f.dBudget R := by + unfold dBudget + exact mul_nonneg (add_nonneg (add_nonneg f.dz.mass_nonneg f.dr.mass_nonneg) f.da.mass_nonneg) + (Real.exp_pos _).le +lemma gradient_bound (f : KernelExpr) {R : ℝ} {x : Triple} (hx : x∈strip R) : + ‖f.gradient x‖≤f.dBudget R := by + apply (grad3_norm ..).trans + exact (add_le_add (add_le_add (f.dz.absolute_bound hx) (f.dr.absolute_bound hx)) + (f.da.absolute_bound hx)).trans_eq (by dsimp [dBudget]; ring) + +lemma lipschitz_strip (f : KernelExpr) {R : ℝ} {x y : Triple} + (hx : x∈strip R) (hy : y∈strip R) : + |eval3 f.eval y-eval3 f.eval x|≤f.dBudget R*‖y-x‖ := by + exact Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le + (fun z _=>(f.hasFDerivAt_eval z).hasFDerivWithinAt) + (fun _ hz=>f.gradient_bound hz) (convex_strip R) hx hy + +def ddBudget (f : KernelExpr) (R : ℝ) : ℝ := + f.dz.dBudget R+f.dr.dBudget R+f.da.dBudget R +lemma ddBudget_nonneg (f : KernelExpr) (R : ℝ) : 0≤f.ddBudget R := + add_nonneg (add_nonneg (f.dz.dBudget_nonneg R) (f.dr.dBudget_nonneg R)) (f.da.dBudget_nonneg R) + +lemma gradient_lipschitz (f : KernelExpr) {R : ℝ} {x y : Triple} + (hx : x∈strip R) (hy : y∈strip R) : + ‖f.gradient y-f.gradient x‖≤f.ddBudget R*‖y-x‖ := by + rw [gradient,gradient,grad3_sub] + apply (grad3_norm ..).trans + exact (add_le_add (add_le_add (f.dz.lipschitz_strip hx hy) (f.dr.lipschitz_strip hx hy)) + (f.da.lipschitz_strip hx hy)).trans_eq (by dsimp [ddBudget]; ring) +end KernelExpr + +namespace RatioExpr +lemma continuous_eval (f : RatioExpr) : Continuous (eval3 f.eval) := by + induction f with + | constant c => exact continuous_const + | kernel f => + have hp : Continuous (eval3 phi) := by simpa only [KernelExpr.eval,moment_base] using + (KernelExpr.atom 0 0 false).continuous_eval + exact f.continuous_eval.div hp (fun x=>(phi_pos x.1 x.2.1 x.2.2).ne') + | add f g hf hg => exact hf.add hg + | mul f g hf hg => exact hf.mul hg + +def gradient (f : RatioExpr) (x : Triple) : Triple→L[ℝ]ℝ := + grad3 (eval3 (f.d .z).eval x) (eval3 (f.d .r).eval x) (eval3 (f.d .a).eval x) +lemma hasFDerivAt_eval (f : RatioExpr) (x : Triple) : + HasFDerivAt (eval3 f.eval) (f.gradient x) x := + hasFDerivAt_of_three_partials f.eval (f.d .z).eval (f.d .r).eval (f.d .a).eval + f.hasDerivAt_z f.hasDerivAt_r f.hasDerivAt_a + (f.d .z).continuous_eval (f.d .r).continuous_eval (f.d .a).continuous_eval x + +def dBudget (f : RatioExpr) : ℝ := (f.d .z).mass+(f.d .r).mass+(f.d .a).mass +lemma gradient_bound (f : RatioExpr) (x : Triple) : ‖f.gradient x‖≤f.dBudget := by + exact (grad3_norm ..).trans (add_le_add + (add_le_add ((f.d .z).bounded ..) ((f.d .r).bounded ..)) ((f.d .a).bounded ..)) +lemma lipschitz_global (f : RatioExpr) (x y : Triple) : + |eval3 f.eval y-eval3 f.eval x|≤f.dBudget*‖y-x‖ := by + exact Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le + (fun z (_ : z∈(Set.univ:Set Triple))=>(f.hasFDerivAt_eval z).hasFDerivWithinAt) + (fun z _=>f.gradient_bound z) convex_univ (Set.mem_univ x) (Set.mem_univ y) +def ddBudget (f : RatioExpr) : ℝ := (f.d .z).dBudget+(f.d .r).dBudget+(f.d .a).dBudget +lemma gradient_lipschitz (f : RatioExpr) (x y : Triple) : + ‖f.gradient y-f.gradient x‖≤f.ddBudget*‖y-x‖ := by + rw [gradient,gradient,grad3_sub] + apply (grad3_norm ..).trans + exact (add_le_add (add_le_add ((f.d .z).lipschitz_global x y) ((f.d .r).lipschitz_global x y)) + ((f.d .a).lipschitz_global x y)).trans_eq (by dsimp [ddBudget]; ring) +end RatioExpr +end SKGap.Stein + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/PhiHessianBridge.lean b/lean/OAI/Probability/SKGap/Localization/PhiHessianBridge.lean new file mode 100644 index 0000000000000000000000000000000000000000..3dc2a3d3d21c6be70995034ca6f5f587eedc6158 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/PhiHessianBridge.lean @@ -0,0 +1,78 @@ +import Mathlib +import OAI.Probability.SKGap.Stability.ImplicitPerturb + +namespace OAI + +section + +noncomputable section +open scoped BigOperators Matrix +namespace SKGapCutoff.Recipe +open SKGap.Stein Primary SKGap.ImplicitSystem Matrix +variable {n : ℕ} + +lemma rank_toEuclideanCLM (m : Fin n→ℝ) : + toEuclideanCLM (𝕜:=ℝ) (vecMulVec m m)=rank (WithLp.toLp 2 m) (WithLp.toLp 2 m) := by + ext v i + change ((vecMulVec m m).mulVec v.ofLp) i=(inner ℝ (WithLp.toLp 2 m) v)*m i + simp only [mulVec, dotProduct, vecMulVec] + change (∑k,m i*m k*v k)=(∑k,v k*m k)*m i + rw [Finset.sum_mul] + congr 1 + ext k + ring + +lemma fieldHessian_matrix (j : ℝ) (J : Interaction n) (z A : Fin n→ℝ) : + SKGap.fieldHessian j J z A= + 1+(SKGap.onsager j z) • ((diagonal (fun i=>Real.sqrt (A i)))*(diagonal (fun i=>Real.sqrt (A i))))- + diagonal (fun i=>Real.sqrt (A i))*J*diagonal (fun i=>Real.sqrt (A i))- + (2*j/(n:ℝ)) • (diagonal (fun i=>Real.sqrt (A i))* + vecMulVec (SKGap.magnetization z) (SKGap.magnetization z)*diagonal (fun i=>Real.sqrt (A i))) := by + ext i k + simp only [SKGap.fieldHessian,SKGap.hessianCore,Matrix.add_apply,Matrix.sub_apply, + Matrix.smul_apply,smul_eq_mul,Matrix.one_apply,Matrix.diagonal_mul,Matrix.mul_diagonal, + Matrix.diagonal_apply,vecMulVec,Matrix.of_apply] + by_cases h:i=k + · subst k; simp only [ite_true];ring + · simp only [h,ite_false];ring + +lemma onsager_scalarVariance (hn : 0Real.tanh (z i)))= + toEuclideanCLM (𝕜:=ℝ) (SKGap.fieldHessian j J z (fun i=>phi (z i) (r i) a)) := by + rw [fieldHessian_matrix] + simp only [map_sub,map_add,map_one,map_smul,map_mul,rank_toEuclideanCLM] + rw [onsager_scalarVariance hn] + simp only [stableMatrix,phiSqrt,div_eq_mul_inv] + rfl + +lemma literal_stableMatrix_quadratic (hn : 0Real.tanh (z i))) v)= + SKGap.quadraticForm (SKGap.fieldHessian j J z (fun i=>phi (z i) (r i) a)) v.ofLp := by + rw [literal_stableMatrix_eq_hessian hn,Matrix.inner_toEuclideanCLM] + simp only [dotProduct,mulVec,SKGap.quadraticForm,Finset.mul_sum] + congr 1 + ext i + congr 1 + ext k + ring + +end SKGapCutoff.Recipe + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/PhiRatio.lean b/lean/OAI/Probability/SKGap/Localization/PhiRatio.lean new file mode 100644 index 0000000000000000000000000000000000000000..06deea47965d97f65e011d5d2d611abf195b9b67 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/PhiRatio.lean @@ -0,0 +1,147 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.PhiAlgebra + +namespace OAI + +section + +noncomputable section +namespace SKGap.Stein + +inductive RatioExpr where + | constant (c : ℝ) + | kernel (f : KernelExpr) + | add (f g : RatioExpr) + | mul (f g : RatioExpr) +namespace RatioExpr + +def eval : RatioExpr → ℝ → ℝ → ℝ → ℝ + | constant c,_,_,_ => c + | kernel f,z,r,a => f.eval z r a/phi z r a + | add f g,z,r,a => eval f z r a+eval g z r a + | mul f g,z,r,a => eval f z r a*eval g z r a + +def mass : RatioExpr → ℝ + | constant c => |c| + | kernel f => f.mass + | add f g => mass f+mass g + | mul f g => mass f*mass g + +lemma mass_nonneg (f : RatioExpr) : 0 ≤ mass f := by + induction f with + | constant c => exact abs_nonneg c + | kernel f => exact f.mass_nonneg + | add f g hf hg => exact add_nonneg hf hg + | mul f g hf hg => exact mul_nonneg hf hg + +lemma bounded (f : RatioExpr) (z r a : ℝ) : |eval f z r a| ≤ mass f := by + induction f with + | constant c => exact le_refl _ + | kernel f => + dsimp only [eval,mass] + rw [abs_div,abs_of_pos (phi_pos z r a),div_le_iff₀ (phi_pos z r a)] + exact f.relative_bound z r a + | add f g hf hg => exact (abs_add_le _ _).trans (add_le_add hf hg) + | mul f g hf hg => + dsimp only [eval,mass] + rw [abs_mul] + exact mul_le_mul hf hg (abs_nonneg _) f.mass_nonneg + +def d (i : Axis) : RatioExpr → RatioExpr + | constant _ => constant 0 + | kernel f => add (kernel (f.d i)) + (mul (constant (-1)) (mul (kernel f) (kernel ((KernelExpr.atom 0 0 false).d i)))) + | add f g => add (d i f) (d i g) + | mul f g => add (mul (d i f) g) (mul f (d i g)) + +lemma kernel_deriv_z (f : KernelExpr) (z r a : ℝ) : + HasDerivAt (fun z => eval (kernel f) z r a) (eval (d .z (kernel f)) z r a) z := by + have hphi : HasDerivAt (fun z => phi z r a) + ((KernelExpr.atom 0 0 false).dz.eval z r a) z := by + simpa only [KernelExpr.eval,moment_base] using (KernelExpr.atom 0 0 false).hasDerivAt_z z r a + convert! (f.hasDerivAt_z z r a).div hphi (phi_pos z r a).ne' using 1 + dsimp only [eval,d,KernelExpr.d] + field_simp + ring + +lemma kernel_deriv_r (f : KernelExpr) (z r a : ℝ) : + HasDerivAt (fun r => eval (kernel f) z r a) (eval (d .r (kernel f)) z r a) r := by + have hphi : HasDerivAt (fun r => phi z r a) + ((KernelExpr.atom 0 0 false).dr.eval z r a) r := by + simpa only [KernelExpr.eval,moment_base] using (KernelExpr.atom 0 0 false).hasDerivAt_r z r a + convert! (f.hasDerivAt_r z r a).div hphi (phi_pos z r a).ne' using 1 + dsimp only [eval,d,KernelExpr.d] + field_simp + ring + +lemma kernel_deriv_a (f : KernelExpr) (z r a : ℝ) : + HasDerivAt (fun a => eval (kernel f) z r a) (eval (d .a (kernel f)) z r a) a := by + have hphi : HasDerivAt (fun a => phi z r a) + ((KernelExpr.atom 0 0 false).da.eval z r a) a := by + simpa only [KernelExpr.eval,moment_base] using (KernelExpr.atom 0 0 false).hasDerivAt_a z r a + convert! (f.hasDerivAt_a z r a).div hphi (phi_pos z r a).ne' using 1 + dsimp only [eval,d,KernelExpr.d] + field_simp + ring + +lemma hasDerivAt_z (f : RatioExpr) (z r a : ℝ) : + HasDerivAt (fun z => eval f z r a) (eval (d .z f) z r a) z := by + induction f with + | constant c => exact hasDerivAt_const z c + | kernel f => exact kernel_deriv_z f z r a + | add f g hf hg => exact hf.add hg + | mul f g hf hg => exact hf.mul hg + +lemma hasDerivAt_r (f : RatioExpr) (z r a : ℝ) : + HasDerivAt (fun r => eval f z r a) (eval (d .r f) z r a) r := by + induction f with + | constant c => exact hasDerivAt_const r c + | kernel f => exact kernel_deriv_r f z r a + | add f g hf hg => exact hf.add hg + | mul f g hf hg => exact hf.mul hg + +lemma hasDerivAt_a (f : RatioExpr) (z r a : ℝ) : + HasDerivAt (fun a => eval f z r a) (eval (d .a f) z r a) a := by + induction f with + | constant c => exact hasDerivAt_const a c + | kernel f => exact kernel_deriv_a f z r a + | add f g hf hg => exact hf.add hg + | mul f g hf hg => exact hf.mul hg + +lemma partial_eval (i : Axis) (f : RatioExpr) : coordinateDeriv i (eval f)=eval (d i f) := by + funext z r a + cases i with + | z => exact (hasDerivAt_z f z r a).deriv + | r => exact (hasDerivAt_r f z r a).deriv + | a => exact (hasDerivAt_a f z r a).deriv + +def mixedExpr (l : List Axis) (f : RatioExpr) : RatioExpr := match l with + | [] => f + | i::l => d i (mixedExpr l f) + +lemma mixed_eval (l : List Axis) (f : RatioExpr) : mixed l (eval f)=eval (mixedExpr l f) := by + induction l with + | nil => rfl + | cons i l ih => rw [mixed,ih,partial_eval]; rfl + +theorem all_mixed_ratio_bounded (k l : List Axis) : + ∃ C : ℝ, 0 ≤ C ∧ ∀ z r a, + |mixed l (fun z r a => mixed k phi z r a/phi z r a) z r a| ≤ C := by + let f:=kernel (KernelExpr.mixedExpr k (.atom 0 0 false)) + refine ⟨mass (mixedExpr l f),mass_nonneg _,?_⟩ + intro z r a + have he : (fun z r a => mixed k phi z r a/phi z r a)=eval f := by + have hp : phi=KernelExpr.eval (.atom 0 0 false) := + funext fun z => funext fun r => funext fun a => (moment_base z r a).symm + rw [hp,KernelExpr.mixed_eval] + simp only [f,eval,KernelExpr.eval,moment_base] + rw [he,mixed_eval] + exact bounded _ z r a + +end RatioExpr +end SKGap.Stein + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/PhiRegularity.lean b/lean/OAI/Probability/SKGap/Localization/PhiRegularity.lean new file mode 100644 index 0000000000000000000000000000000000000000..30e31e882dea0a37601579621f325cf34b84c97f --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/PhiRegularity.lean @@ -0,0 +1,163 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.PhiFrechet +import OAI.Probability.SKGap.Matrix.Trace + +namespace OAI + +section + +noncomputable section +open scoped BigOperators +namespace SKGapCutoff.Recipe +open SKGap.Stein +variable {n : ℕ} {ι κ : Type*} [Fintype ι] [Fintype κ] + +omit [Fintype ι] [Fintype κ] in +lemma affine_segment (L : Args (ι:=ι) (κ:=κ)→L[ℝ]Triple) (s : Triple) + (u v : Args (ι:=ι) (κ:=κ)) (t : ℝ) : + L (u+t • (v-u))+s=(L u+s)+t • ((L v+s)-(L u+s)) := by + simp only [map_add,map_smul,map_sub] + module + +lemma affine_segmentRegular (H : ι→VectorFields n) (θ : κ→Spin n→ℝ) (x : Spin n) + (F : Triple→ℝ) (F' : Triple→Triple→L[ℝ]ℝ) + (L : Args (ι:=ι) (κ:=κ)→L[ℝ]Triple) (s : Fin n→Triple) + (S : Set Triple) (hS : Convex ℝ S) {B D : ℝ} (hB : 0≤B) (hD : 0≤D) + (hderiv : ∀u∈S,HasFDerivAt F (F' u) u) + (hbound : ∀u∈S,‖F' u‖≤B) + (hlip : ∀u∈S,∀v∈S,‖F' v-F' u‖≤D*‖v-u‖) + (hbase : ∀i,L (localArgs H θ x i)+s i∈S) + (hflip : ∀i k,L (localArgs H θ (flip x k) i)+s i∈S) : + SegmentRegular H θ (fun i u=>F (L u+s i)) + (fun i u=>(F' (L u+s i)).comp L) x (B*‖L‖+D*‖L‖^2) := by + have hc : 0≤B*‖L‖+D*‖L‖^2 := by positivity + have hm (i : Fin n) (k : Fin n) (t : ℝ) (ht : t∈Set.Icc (0:ℝ) 1) : + L (localArgs H θ x i+t • (localArgs H θ (flip x k) i-localArgs H θ x i))+s i∈S := by + rw [affine_segment] + exact hS.add_smul_sub_mem (hbase i) (hflip i k) ht + refine ⟨hc,?_,?_,?_⟩ + · intro i k t ht + exact (hderiv _ (hm i k t ht)).comp + (f:=fun u : Args (ι:=ι) (κ:=κ)=>L u+s i) + (localArgs H θ x i+t • (localArgs H θ (flip x k) i-localArgs H θ x i)) + (L.hasFDerivAt.add_const (s i)) + · intro i k t ht + exact ((F' _).opNorm_comp_le L).trans ((mul_le_mul_of_nonneg_right + (hbound _ (hm i k t ht)) (norm_nonneg L)).trans (le_add_of_nonneg_right (by positivity))) + · intro i k t ht + rw [←ContinuousLinearMap.sub_comp] + apply (ContinuousLinearMap.opNorm_comp_le _ L).trans + have hd := hlip _ (hbase i) _ (hm i k t ht) + have hid : L (localArgs H θ x i+t • (localArgs H θ (flip x k) i-localArgs H θ x i))+s i- + (L (localArgs H θ x i)+s i)=L (t • (localArgs H θ (flip x k) i-localArgs H θ x i)) := by + simp only [map_add]; abel + rw [hid] at hd + have hb := L.le_opNorm (t • (localArgs H θ (flip x k) i-localArgs H θ x i)) + have h₁ := (mul_le_mul_of_nonneg_left hb hD) + have h₂ := mul_le_mul_of_nonneg_right (hd.trans h₁) (norm_nonneg L) + apply h₂.trans + nlinarith only [mul_nonneg (mul_nonneg hB (norm_nonneg L)) + (norm_nonneg (t • (localArgs H θ (flip x k) i-localArgs H θ x i)))] + +lemma phi_kernel_segmentRegular (f : KernelExpr) (H : ι→VectorFields n) + (θ : κ→Spin n→ℝ) (x : Spin n) + (L : Args (ι:=ι) (κ:=κ)→L[ℝ]Triple) (s : Fin n→Triple) (R : ℝ) + (hbase : ∀i,L (localArgs H θ x i)+s i∈strip R) + (hflip : ∀i k,L (localArgs H θ (flip x k) i)+s i∈strip R) : + SegmentRegular H θ (fun i u=>eval3 f.eval (L u+s i)) + (fun i u=>(f.gradient (L u+s i)).comp L) x + (f.dBudget R*‖L‖+f.ddBudget R*‖L‖^2) := + affine_segmentRegular H θ x (eval3 f.eval) f.gradient L s (strip R) (convex_strip R) + (f.dBudget_nonneg R) (f.ddBudget_nonneg R) + (fun u _=>f.hasFDerivAt_eval u) (fun _ hu=>f.gradient_bound hu) + (fun _ hu _ hv=>f.gradient_lipschitz hu hv) hbase hflip + +lemma _root_.OAI.SKGap.Stein.RatioExpr.dBudget_nonneg (f : RatioExpr) : 0≤f.dBudget := by + exact add_nonneg (add_nonneg (f.d .z).mass_nonneg (f.d .r).mass_nonneg) (f.d .a).mass_nonneg +lemma _root_.OAI.SKGap.Stein.RatioExpr.ddBudget_nonneg (f : RatioExpr) : 0≤f.ddBudget := + add_nonneg (add_nonneg (f.d .z).dBudget_nonneg (f.d .r).dBudget_nonneg) (f.d .a).dBudget_nonneg + +lemma phi_ratio_segmentRegular (f : RatioExpr) (H : ι→VectorFields n) + (θ : κ→Spin n→ℝ) (x : Spin n) + (L : Args (ι:=ι) (κ:=κ)→L[ℝ]Triple) (s : Fin n→Triple) : + SegmentRegular H θ (fun i u=>eval3 f.eval (L u+s i)) + (fun i u=>(f.gradient (L u+s i)).comp L) x + (f.dBudget*‖L‖+f.ddBudget*‖L‖^2) := + affine_segmentRegular H θ x (eval3 f.eval) f.gradient L s Set.univ convex_univ + f.dBudget_nonneg f.ddBudget_nonneg + (fun u _=>f.hasFDerivAt_eval u) (fun u _=>f.gradient_bound u) + (fun u _ v _=>f.gradient_lipschitz u v) (fun _=>Set.mem_univ _) (fun _ _=>Set.mem_univ _) + +def phiSelect (l : ι) (α : κ) : Args (ι:=ι) (κ:=κ)→L[ℝ]Triple := + (ContinuousLinearMap.proj (.inl l)).prod + ((0 : Args (ι:=ι) (κ:=κ)→L[ℝ]ℝ).prod (ContinuousLinearMap.proj (.inr α))) +omit [Fintype ι] [Fintype κ] in +lemma phiSelect_apply (l : ι) (α : κ) (u : Args (ι:=ι) (κ:=κ)) : + phiSelect l α u=(u (.inl l),(0,u (.inr α))) := rfl +lemma phiSelect_norm (l : ι) (α : κ) : ‖phiSelect l α‖≤1 := by + apply (phiSelect l α).opNorm_le_bound (by norm_num) + intro u + rw [one_mul,phiSelect_apply,Prod.norm_def,Prod.norm_def] + exact max_le (norm_le_pi_norm u _) (max_le (by simp) (norm_le_pi_norm u _)) + +end SKGapCutoff.Recipe + +namespace SKGapCutoff.Recipe +open SKGap.Stein +variable {n : ℕ} {ι κ : Type*} [Fintype ι] [Fintype κ] +lemma SegmentRegular.mono {H : ι→VectorFields n} {θ : κ→Spin n→ℝ} + {F : Fin n→Args (ι:=ι) (κ:=κ)→ℝ} + {F' : Fin n→Args (ι:=ι) (κ:=κ)→Args (ι:=ι) (κ:=κ)→L[ℝ]ℝ} + {x : Spin n} {C D : ℝ} (h : SegmentRegular H θ F F' x C) (hCD : C≤D) : + SegmentRegular H θ F F' x D := + ⟨h.nonneg.trans hCD,h.deriv,(fun i k t ht=>(h.bound i k t ht).trans hCD), + (fun i k t ht=>(h.lip i k t ht).trans (mul_le_mul_of_nonneg_right hCD (norm_nonneg _)))⟩ + +lemma fixed_root_kernel_regular (f : KernelExpr) (H : ι→VectorFields n) + (θ : κ→Spin n→ℝ) (x : Spin n) (l : ι) (α : κ) (r : Fin n→ℝ) (R : ℝ) + (hx : |θ α x|≤R) (hf : ∀k,|θ α (flip x k)|≤R) : + SegmentRegular H θ (fun i u=>eval3 f.eval (phiSelect l α u+(0,(r i,0)))) + (fun i u=>(f.gradient (phiSelect l α u+(0,(r i,0)))).comp (phiSelect l α)) x + (f.dBudget R+f.ddBudget R) := by + have h:=phi_kernel_segmentRegular f H θ x (phiSelect l α) (fun i=>(0,(r i,0))) R + (fun _=>by simpa [strip,phiSelect,localArgs] using hx) + (fun _ k=>by simpa [strip,phiSelect,localArgs] using hf k) + apply h.mono + have h1:=phiSelect_norm l α + have h2:=pow_le_pow_left₀ (norm_nonneg (phiSelect l α)) h1 2 + simpa only [mul_one,one_pow] using add_le_add + (mul_le_mul_of_nonneg_left h1 (f.dBudget_nonneg R)) + (mul_le_mul_of_nonneg_left h2 (f.ddBudget_nonneg R)) + +def phiPairSelect (l m : ι) (α : κ) : Args (ι:=ι) (κ:=κ)→L[ℝ]Triple := + (ContinuousLinearMap.proj (.inl l)).prod + ((ContinuousLinearMap.proj (.inl m)).prod (ContinuousLinearMap.proj (.inr α))) +lemma phiPairSelect_norm (l m : ι) (α : κ) : ‖phiPairSelect l m α‖≤1 := by + apply (phiPairSelect l m α).opNorm_le_bound (by norm_num) + intro u + change ‖(u (.inl l),(u (.inl m),u (.inr α)))‖≤1*‖u‖ + rw [one_mul,Prod.norm_def,Prod.norm_def] + exact max_le (norm_le_pi_norm u _) (max_le (norm_le_pi_norm u _) (norm_le_pi_norm u _)) + +lemma two_field_kernel_regular (f : KernelExpr) (H : ι→VectorFields n) + (θ : κ→Spin n→ℝ) (x : Spin n) (l m : ι) (α : κ) (R : ℝ) + (hx : |θ α x|≤R) (hf : ∀k,|θ α (flip x k)|≤R) : + SegmentRegular H θ (fun _ u=>eval3 f.eval (phiPairSelect l m α u)) + (fun _ u=>(f.gradient (phiPairSelect l m α u)).comp (phiPairSelect l m α)) x + (f.dBudget R+f.ddBudget R) := by + have h:=phi_kernel_segmentRegular f H θ x (phiPairSelect l m α) (fun _=>0) R + (fun _=>by simpa [strip,phiPairSelect,localArgs] using hx) + (fun _ k=>by simpa [strip,phiPairSelect,localArgs] using hf k) + simp only [add_zero] at h + apply h.mono + have h1:=phiPairSelect_norm l m α + have h2:=pow_le_pow_left₀ (norm_nonneg (phiPairSelect l m α)) h1 2 + simpa only [mul_one,one_pow] using add_le_add + (mul_le_mul_of_nonneg_left h1 (f.dBudget_nonneg R)) + (mul_le_mul_of_nonneg_left h2 (f.ddBudget_nonneg R)) +end SKGapCutoff.Recipe + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/PhiResponse.lean b/lean/OAI/Probability/SKGap/Localization/PhiResponse.lean new file mode 100644 index 0000000000000000000000000000000000000000..7db412f122f2a1fd0157884a876a565255eaeede --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/PhiResponse.lean @@ -0,0 +1,53 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.PhiAlgebra + +namespace OAI + +section + +noncomputable section +namespace SKGap.Stein +open KernelExpr + +def phiR (z r a : ℝ) : ℝ := eval (dr (atom 0 0 false)) z r a +def phiRZ (z r a : ℝ) : ℝ := eval (dz (dr (atom 0 0 false))) z r a + +lemma phiR_hasDerivAt (z r a : ℝ) : HasDerivAt (fun r=>phi z r a) (phiR z r a) r := by + simpa only [eval,moment_base,phiR] using hasDerivAt_r (atom 0 0 false) z r a +lemma phiR_hasDerivAt_z (z r a : ℝ) : HasDerivAt (fun z=>phiR z r a) (phiRZ z r a) z := + hasDerivAt_z (dr (atom 0 0 false)) z r a +lemma phiZR_commute (z r a : ℝ) : + eval (dr (dz (atom 0 0 false))) z r a=phiRZ z r a := by + simp only [phiRZ,dz,dr,eval] + ring +lemma phiZ_kernel (z r a : ℝ) : phiZ z r a=eval (dz (atom 0 0 false)) z r a := by + exact (phi_hasDerivAt z r a).unique (by simpa only [eval,moment_base] using hasDerivAt_z (atom 0 0 false) z r a) +lemma phiZ_hasDerivAt_r (z r a : ℝ) : HasDerivAt (fun r=>phiZ z r a) (phiRZ z r a) r := by + simpa only [phiZ_kernel,phiZR_commute] using hasDerivAt_r (dz (atom 0 0 false)) z r a + +theorem phiR_stein (z r a : ℝ) : + (z-r-a*Real.tanh z)*phiR z r a-a*phiRZ z r a=phi z r a-SKGapCutoff.scalarVariance r := by + have hc : HasDerivAt (fun r=>z-r-a*Real.tanh z) (-1) r := by + convert! ((hasDerivAt_const r z).sub (hasDerivAt_id r)).sub_const (a*Real.tanh z) using 1 + simp + have hleft := (hc.mul (phiR_hasDerivAt z r a)).sub ((phiZ_hasDerivAt_r z r a).const_mul a) + have hright : HasDerivAt (fun r=>Real.tanh z-Real.tanh r) (-SKGapCutoff.scalarVariance r) r := by + convert! (hasDerivAt_const r (Real.tanh z)).sub (SKGapCutoff.tanh_hasDerivAt r) using 1 + simp + have hh : (fun r=>(z-r-a*Real.tanh z)*phi z r a-a*phiZ z r a)= + (fun r=>Real.tanh z-Real.tanh r) := funext fun r=>phi_stein z r a + change HasDerivAt (fun r=>(z-r-a*Real.tanh z)*phi z r a-a*phiZ z r a) _ r at hleft + rw [hh] at hleft + have he:=hleft.unique hright + linarith + +lemma phiR_bound (z r a : ℝ) : |phiR z r a|≤2*phi z r a := by + convert! KernelExpr.relative_bound (dr (atom 0 0 false)) z r a using 1 + norm_num [phiR,KernelExpr.mass,dr] + +end SKGap.Stein + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/PlantedFixedTime.lean b/lean/OAI/Probability/SKGap/Localization/PlantedFixedTime.lean new file mode 100644 index 0000000000000000000000000000000000000000..471f7488df05246245818a7bcdf3fb33f73416a0 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/PlantedFixedTime.lean @@ -0,0 +1,163 @@ +import Mathlib +import OAI.Probability.SKGap.Stability.PositiveRootStability +import OAI.Probability.SKGap.Stability.SmallRootStability + +namespace OAI + +section +noncomputable section +namespace SKGap +open Matrix Real Set MeasureTheory ProbabilityTheory GaussianDensity +open scoped BigOperators ENNReal + +lemma badFieldSet_mono_margin {n : ℕ} (j A ε : ℝ) {c c' : ℝ} (h : c ≤ c') : + badFieldSet n j A ε c ⊆ badFieldSet n j A ε c' := by + rintro p ⟨a,ha,hd,x,hx,hq⟩ + exact ⟨a,ha,hd,x,hx,hq.trans h⟩ + +def plantedRootBad (n : ℕ) (j A K ε c ρ t : ℝ) : + Set ((MatrixCoordinates (Fin n) → ℝ) × (Fin n → ℝ)) := + {p | (∀ z : Field n,vectorNorm (plantedInteraction j (goeMatrix (j/(n:ℝ)) p.1)*ᵥz) ≤ K*vectorNorm z) ∧ + ∃ y : Field n,vectorNorm (tapField j (plantedInteraction j (goeMatrix (j/(n:ℝ)) p.1)) + (fun i=>t+p.2 i) y) ≤ ρ*sqrt (n:ℝ) ∧ + (goeMatrix (j/(n:ℝ)) p.1,y)∈badFieldSet n j A ε c} + +lemma plantedRootBad_mono {n : ℕ} (j A K ε t : ℝ) {c c' ρ ρ' : ℝ} + (hc : c ≤ c') (hρ : ρ ≤ ρ') : + plantedRootBad n j A K ε c ρ t ⊆ plantedRootBad n j A K ε c' ρ' t := by + rintro p ⟨hJ,y,hres,hy⟩ + exact ⟨hJ,y,hres.trans (mul_le_mul_of_nonneg_right hρ (sqrt_nonneg _)), + badFieldSet_mono_margin j A ε hc hy⟩ + +lemma two_exponential_tails {a b : ℝ} (ha : 0 < a) (hb : 0 < b) : + ∃ r : ℝ,0 < r ∧ ∃ N : ℕ, ∀ n : ℕ,N ≤ n → + 4*exp (-a*(n:ℝ))+exp (-b*(n:ℝ)) ≤ exp (-r*(n:ℝ)) := by + let r := min a b/2 + have hr : 0 < r := half_pos (lt_min ha hb) + obtain ⟨N,hN⟩ := absorb_finite_exponential_factor 5 hr + refine ⟨r,hr,N,fun n hn=>?_⟩ + have he₁ : exp (-a*(n:ℝ)) ≤ exp (-(2*r)*(n:ℝ)) := + exp_le_exp.mpr (mul_le_mul_of_nonneg_right (by dsimp [r];linarith [min_le_left a b]) (Nat.cast_nonneg _)) + have he₂ : exp (-b*(n:ℝ)) ≤ exp (-(2*r)*(n:ℝ)) := + exp_le_exp.mpr (mul_le_mul_of_nonneg_right (by dsimp [r];linarith [min_le_right a b]) (Nat.cast_nonneg _)) + have hh := hN n hn (-(2*r)) + calc + _ ≤ 5*exp (-(2*r)*(n:ℝ)) := by linarith only [he₁,he₂] + _ ≤ exp (-r*(n:ℝ)) := by + convert hh using 1 <;> congr 1 <;> ring_nf + +theorem planted_fixed_time_root_stability {j T : ℝ} (hj : 0 < j) (hj1 : j < 1) + (hT : 0 < T) : + ∃ A K ε c ρ a : ℝ,1 < A ∧ 2*sqrt j < K ∧ sqrt j*A < 1 ∧ + 0 < ε ∧ 0 < c ∧ 0 < ρ ∧ 0 < a ∧ ∃ N : ℕ,0 < N ∧ + ∀ n : ℕ,N ≤ n → ∀ t ∈ Icc 0 T, + ((gaussianCoordinates (MatrixCoordinates (Fin n))).prod + (Measure.pi (fun _ : Fin n=>gaussianReal 0 t.toNNReal))).real + (plantedRootBad n j A K ε c ρ t) ≤ exp (-a*(n:ℝ)) := by + obtain ⟨A,K,q₀,cs,hA,hK,hq₀,hcs,hsub,hKj,hmargin⟩ := high_temperature_small_margin hj hj1 + have hK0 : 0 ≤ K := (mul_nonneg (by norm_num : (0:ℝ)≤2) (sqrt_nonneg _)).trans hK.le + obtain ⟨ts,ρs,as,hts,hρs,has,Ns,hNs,hs⟩ := small_time_root_stability hj hj1 hA.le hK0 hKj hq₀ hmargin + obtain ⟨ε,cp,ρp,ap,hε,hcp,hρp,hap,Np,hNp,hp⟩ := positive_time_root_stability hj hj1 hA.le hsub hK0 + (lt_min hts hT) (min_le_right ts T) + have hd : 0 < min 1 (1/(π^2*j)) := lt_min zero_lt_one (by positivity) + obtain ⟨a,ha,Na,hNa⟩ := two_exponential_tails hd (lt_min has hap) + refine ⟨A,K,ε,min cs cp,min ρs ρp,a,hA,hK,hsub,hε,lt_min hcs hcp, + lt_min hρs hρp,ha,max Na (max Ns Np),hNs.trans_le ((le_max_left _ _).trans (le_max_right _ _)),?_⟩ + intro n hn t ht + have hns : Ns ≤ n := (le_max_left _ _).trans ((le_max_right _ _).trans hn) + have hnp : Np ≤ n := (le_max_right _ _).trans ((le_max_right _ _).trans hn) + have hna : Na ≤ n := (le_max_left _ _).trans hn + apply le_trans ?_ (hNa n hna) + by_cases htt : t ≤ ts + · have hh := hs n hns t ⟨ht.1,htt⟩ ε + apply (measureReal_mono (plantedRootBad_mono j A K ε t (min_le_left _ _) (min_le_left _ _)) + (measure_ne_top _ _)).trans + exact hh.trans (add_le_add le_rfl (exp_le_exp.mpr + (mul_le_mul_of_nonneg_right (neg_le_neg (min_le_left as ap)) (Nat.cast_nonneg _)))) + · have hh := hp n hnp t ⟨(min_le_left ts T).trans (not_le.mp htt).le,ht.2⟩ + apply (measureReal_mono (plantedRootBad_mono j A K ε t (min_le_right _ _) (min_le_right _ _)) + (measure_ne_top _ _)).trans + exact hh.trans (add_le_add le_rfl (exp_le_exp.mpr + (mul_le_mul_of_nonneg_right (neg_le_neg (min_le_right as ap)) (Nat.cast_nonneg _)))) +end SKGap +end +end + +section +noncomputable section +namespace SKGap +open Matrix Real Set +open scoped BigOperators + +lemma tapField_add_diagonal {n : ℕ} (j : ℝ) (J : Matrix (Fin n) (Fin n) ℝ) + (h y d : Field n) : + tapField j (J+diagonal d) h y=tapField j J h y-(fun i=>d i*magnetization y i) := by + ext i + simp only [tapField,Matrix.add_apply,add_mul,Finset.sum_add_distrib,Pi.sub_apply] + rw [show (∑ k,diagonal d i k*magnetization y k)=d i*magnetization y i by + simp [Matrix.diagonal_apply]] + ring + +lemma tapField_diagonal_difference_bound {n : ℕ} {δ : ℝ} (hδ : 0 ≤ δ) + (j : ℝ) (J : Matrix (Fin n) (Fin n) ℝ) (h y d : Field n) + (hd : ∀ i,|d i| ≤ δ) : + vectorNorm (tapField j (J+diagonal d) h y-tapField j J h y) ≤ δ*sqrt (n:ℝ) := by + rw [tapField_add_diagonal,sub_sub_cancel_left] + change ‖-(WithLp.toLp 2 (fun i=>d i*magnetization y i))‖ ≤ _ + rw [norm_neg] + exact (vectorNorm_diag_le hδ hd (magnetization y)).trans + (mul_le_mul_of_nonneg_left (magnetization_norm_bound y) hδ) + +lemma hessian_diagonal_difference {n : ℕ} (j : ℝ) (J : Matrix (Fin n) (Fin n) ℝ) + (y a d x : Field n) (ha : ∀ i,0 ≤ a i) : + quadraticForm (fieldHessian j (J+diagonal d) y a) x- + quadraticForm (fieldHessian j J y a) x = -(∑ i,a i*d i*x i^2) := by + let v : Field n := fun i=>sqrt (a i)*x i + have hq : quadraticForm (J+diagonal d) v-quadraticForm J v=∑ i,d i*v i^2 := by + simp only [quadraticForm,Matrix.add_apply,mul_add,add_mul,Finset.sum_add_distrib,add_sub_cancel_left] + apply Finset.sum_congr rfl + intro i _ + simp only [Matrix.diagonal_apply,ite_mul,mul_ite,mul_zero,zero_mul] + simp only [Finset.sum_ite_eq,Finset.mem_univ,ite_true] + ring + rw [hessian_quadratic_formula,hessian_quadratic_formula] + have hv : (∑ i,d i*v i^2)=∑ i,a i*d i*x i^2 := by + apply Finset.sum_congr rfl + intro i _ + dsimp [v] + rw [mul_pow,sq_sqrt (ha i)] + ring + change _-quadraticForm (J+diagonal d) v-_ - (_-quadraticForm J v-_) = _ + rw [← hv] + linarith only [hq] + +lemma hessian_diagonal_difference_bound {n : ℕ} {A δ : ℝ} (hA : 0 ≤ A) (_hδ : 0 ≤ δ) + (j : ℝ) (J : Matrix (Fin n) (Fin n) ℝ) (y a d x : Field n) + (ha0 : ∀ i,0 ≤ a i) (haA : ∀ i,a i ≤ A) (hd : ∀ i,|d i| ≤ δ) : + |quadraticForm (fieldHessian j (J+diagonal d) y a) x- + quadraticForm (fieldHessian j J y a) x| ≤ A*δ*vectorSqNorm x := by + rw [hessian_diagonal_difference j J y a d x ha0,abs_neg] + apply (Finset.abs_sum_le_sum_abs _ _).trans + unfold vectorSqNorm + rw [Finset.mul_sum] + apply Finset.sum_le_sum + intro i _ + simp only [abs_mul, abs_of_nonneg (ha0 i),abs_of_nonneg (sq_nonneg (x i))] + exact mul_le_mul_of_nonneg_right (mul_le_mul (haA i) (hd i) (abs_nonneg _) hA) (sq_nonneg _) + +lemma mulvec_add_diagonal_bound {n : ℕ} {K δ : ℝ} (hδ : 0 ≤ δ) + (J : Matrix (Fin n) (Fin n) ℝ) (d : Field n) + (hJ : ∀ z : Field n,vectorNorm (J*ᵥz) ≤ K*vectorNorm z) (hd : ∀ i,|d i| ≤ δ) : + ∀ z : Field n,vectorNorm ((J+diagonal d)*ᵥz) ≤ (K+δ)*vectorNorm z := by + intro z + have he : diagonal d*ᵥz=(fun i=>d i*z i) := by ext i; exact mulVec_diagonal d z i + rw [add_mulVec,he] + calc + _ ≤ vectorNorm (J*ᵥz)+vectorNorm (fun i=>d i*z i) := vectorNorm_add_le _ _ + _ ≤ K*vectorNorm z+δ*vectorNorm z := add_le_add (hJ z) (vectorNorm_diag_le hδ hd z) + _ = _ := by ring +end SKGap +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/PlantedMarginalLaw.lean b/lean/OAI/Probability/SKGap/Localization/PlantedMarginalLaw.lean new file mode 100644 index 0000000000000000000000000000000000000000..ab5de55f864b5a15ed6eb352dec038ba9d5785d2 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/PlantedMarginalLaw.lean @@ -0,0 +1,135 @@ +import Mathlib +import OAI.Probability.SKGap.Stability.GaugeStabilityLaw +import OAI.Probability.SKGap.Stability.DiagonalStability + +namespace OAI + +section + +noncomputable section +namespace SKGap.ObservationBridge +open Matrix Real Set MeasureTheory ProbabilityTheory +open scoped BigOperators ENNReal NNReal +variable {n : ℕ} +local instance marginalMatrixMeasurable : MeasurableSpace (Matrix (Fin n) (Fin n) ℝ) := borel _ +local instance marginalMatrixBorel : BorelSpace (Matrix (Fin n) (Fin n) ℝ) := ⟨rfl⟩ + +def goeEdges (r : ℝ) (g : MatrixCoordinates (Fin n)→ℝ) : Disorder n := + fun e=>goeMatrix r g e.1.1 e.1.2 +lemma continuous_goeEdges (r : ℝ) : Continuous (goeEdges (n:=n) r) := by + apply continuous_pi + intro e + unfold goeEdges goeMatrix + fun_prop +lemma goeEdges_gaussian (r : ℝ) : + HasGaussianLaw (goeEdges (n:=n) r) (gaussianCoordinates (MatrixCoordinates (Fin n))) := by + let L : ((Fin n×Fin n)→ℝ)→L[ℝ] Disorder n := + ContinuousLinearMap.pi (fun e=>ContinuousLinearMap.proj e.1) + exact (goe_matrix_gaussian r).map L +lemma goeEdges_hasLaw {r : ℝ} (hr : 0≤r) (e : Edge n) : + HasLaw (fun g : MatrixCoordinates (Fin n)→ℝ=>goeEdges r g e) + (gaussianReal 0 r.toNNReal) (gaussianCoordinates (MatrixCoordinates (Fin n))) := by + have hg := (goeEdges_gaussian (n:=n) r).eval e + refine ⟨hg.aemeasurable,?_⟩ + have hm : (∫ g,goeEdges r g e ∂gaussianCoordinates (MatrixCoordinates (Fin n)))=0 := + goe_mean_zero r e.1.1 e.1.2 + rw [hg.map_eq_gaussianReal,hm,← covariance_self hg.aemeasurable] + change gaussianReal 0 (cov[fun g=>goeMatrix r g e.1.1 e.1.2, + fun g=>goeMatrix r g e.1.1 e.1.2; gaussianCoordinates (MatrixCoordinates (Fin n))]).toNNReal = _ + rw [goe_entry_cov hr] + have hne := ne_of_lt e.property + simp [hne,hne.symm] +lemma goeEdges_independent {r : ℝ} (hr : 0≤r) : + iIndepFun (fun e : Edge n=>fun g=>goeEdges r g e) + (gaussianCoordinates (MatrixCoordinates (Fin n))) := by + apply (goeEdges_gaussian (n:=n) r).iIndepFun_of_covariance_eq_zero + intro e f hef + change cov[fun g=>goeMatrix r g e.1.1 e.1.2, + fun g=>goeMatrix r g f.1.1 f.1.2; gaussianCoordinates (MatrixCoordinates (Fin n))]=0 + rw [goe_entry_cov hr] + have h1 : ¬(e.1.1=f.1.1 ∧ e.1.2=f.1.2) := by + intro h; apply hef; exact Subtype.ext (Prod.ext h.1 h.2) + have h2 : ¬(e.1.1=f.1.2 ∧ e.1.2=f.1.1) := by + intro h + have he := e.property + have hf := f.property + simp only [h.1,h.2] at he + exact (not_lt_of_ge hf.le) he + split_ifs <;> simp_all + +theorem measurePreserving_goeEdges {r : ℝ} (hr : 0≤r) : + MeasurePreserving (goeEdges (n:=n) r) + (gaussianCoordinates (MatrixCoordinates (Fin n))) + (Measure.pi (fun _ : Edge n=>gaussianReal 0 r.toNNReal)) := by + refine ⟨(continuous_goeEdges _).measurable,?_⟩ + rw [iIndepFun.map_fun_eq_pi_map (fun e=>(goeEdges_hasLaw hr e).aemeasurable) + (goeEdges_independent hr)] + exact congrArg Measure.pi (funext fun e=>(goeEdges_hasLaw hr e).map_eq) + +lemma measurePreserving_scaled_edges {r : ℝ} (hr : 0≤r) : + MeasurePreserving (fun g : Disorder n=>fun e=>sqrt r*g e) + (gaussianCoordinates (Edge n)) (Measure.pi (fun _ : Edge n=>gaussianReal 0 r.toNNReal)) := by + refine ⟨by fun_prop,?_⟩ + change (Measure.pi (fun _ : Edge n=>gaussianReal 0 1)).map (fun g e=>sqrt r*g e)=_ + rw [Measure.pi_map_pi (fun _=>by fun_prop)] + apply congrArg Measure.pi + funext e + rw [gaussianReal_map_const_mul] + congr 1 + · simp + · apply NNReal.eq + change (sqrt r)^2*1=↑r.toNNReal + rw [mul_one,sq_sqrt hr,coe_toNNReal _ hr] + +lemma coupling_shifted_goe (j : ℝ) (g : MatrixCoordinates (Fin n)→ℝ) : + coupling (fun e=>goeEdges (j/(n:ℝ)) g e+j/(n:ℝ)) = + eraseDiagonal (plantedInteraction j (goeMatrix (j/(n:ℝ)) g)) := by + ext i k + by_cases hik : i < k + · have hne := ne_of_lt hik + simp [coupling,hik,goeEdges,eraseDiagonal,plantedInteraction,hne,Matrix.vecMulVec] + · by_cases hki : k < i + · have hne := ne_of_lt hki + simp [coupling,hik,hki,goeEdges,eraseDiagonal,plantedInteraction,hne.symm, + Matrix.vecMulVec,goeMatrix,add_comm] + · have he : i=k := le_antisymm (le_of_not_gt hki) (le_of_not_gt hik) + subst k + simp [coupling,eraseDiagonal] + +theorem plus_planted_marginal_probability {j : ℝ} (hj : 0≤j) (A K ε c ρ t : ℝ) : + ((gaussianCoordinates (Edge n)).prod (Measure.pi (fun _ : Fin n=>gaussianReal 0 t.toNNReal))) + {p | (coupling (plusPlantedEdges (j/(n:ℝ)) p.1),(fun i=>t+p.2 i))∈literalBadPair j A K ε c ρ} = + ((gaussianCoordinates (MatrixCoordinates (Fin n))).prod + (Measure.pi (fun _ : Fin n=>gaussianReal 0 t.toNNReal))) + (erasedPlantedRootBad n j A K ε c ρ t) := by + let r := j/(n:ℝ) + have hr : 0≤r := div_nonneg hj (Nat.cast_nonneg _) + let ν := Measure.pi (fun _ : Fin n=>gaussianReal 0 t.toNNReal) + let E := {p : Disorder n × Field n | + (coupling (fun e=>p.1 e+r),(fun i=>t+p.2 i))∈literalBadPair j A K ε c ρ} + have hmap : Continuous (fun p : Disorder n × Field n=> + (coupling (fun e=>p.1 e+r),(fun i=>t+p.2 i)) : + Disorder n × Field n → Matrix (Fin n) (Fin n) ℝ × Field n) := + (continuous_coupling.comp (by fun_prop)).prodMk (by fun_prop) + have hmmap : Measurable (fun p : Disorder n × Field n=> + (coupling (fun e=>p.1 e+r),(fun i=>t+p.2 i)) : + Disorder n × Field n → Matrix (Fin n) (Fin n) ℝ × Field n) := hmap.measurable + have hE : MeasurableSet E := (measurableSet_literalBadPair j A K ε c ρ).preimage hmmap + have h1 := ((measurePreserving_scaled_edges (n:=n) hr).prod (MeasurePreserving.id ν)).measure_preimage hE.nullMeasurableSet + have h2 := ((measurePreserving_goeEdges (n:=n) hr).prod (MeasurePreserving.id ν)).measure_preimage hE.nullMeasurableSet + calc + _ = _ := h1 + _ = ((gaussianCoordinates (MatrixCoordinates (Fin n))).prod ν) + ((Prod.map (goeEdges r) id) ⁻¹' E) := h2.symm + _ = _ := by + congr 1 + ext p + change (coupling (fun e=>goeEdges r p.1 e+r),fun i=>t+p.2 i)∈literalBadPair j A K ε c ρ ↔ _ + rw [coupling_shifted_goe] + rfl +end SKGap.ObservationBridge + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/PlantedTilt.lean b/lean/OAI/Probability/SKGap/Localization/PlantedTilt.lean new file mode 100644 index 0000000000000000000000000000000000000000..ceaa055e77666aecdeb30f7cfe50baebf3b15ab0 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/PlantedTilt.lean @@ -0,0 +1,94 @@ +import Mathlib +import OAI.Probability.SKGap.Gaussian.GaussianTailScale +import OAI.Probability.SKGap.Gaussian.GaussianTiltIdentity + +namespace OAI + +section +noncomputable section +namespace SKGap +open MeasureTheory ProbabilityTheory Real Set +open scoped BigOperators ENNReal + +lemma scaled_weight_eq {n : ℕ} (r : ℝ) (x : Spin n) (g : Disorder n) : + weight (fun e=>sqrt r*g e) 0 x=exp (∑ e,edgeCoefficient r x e*g e) := by + unfold weight + rw [edge_energy_formula] + congr 1 + apply Finset.sum_congr rfl + intro e _ + unfold edgeCoefficient + ring + +lemma scaled_spin_weight_measurable {n : ℕ} (r : ℝ) (x : Spin n) : + Measurable (fun g : Disorder n=>weight (fun e=>sqrt r*g e) 0 x) := by + simp_rw [scaled_weight_eq] + fun_prop + +lemma scaled_spin_mass_measurable {n : ℕ} (r : ℝ) (x : Spin n) : + Measurable (fun g : Disorder n=>mass (fun e=>sqrt r*g e) 0 x) := + (scaled_spin_weight_measurable r x).div ((partition_zero_measurable n).comp (by fun_prop)) + +lemma partition_mass_normalized {n : ℕ} {r : ℝ} (hr : 0 ≤ r) + (g : Disorder n) (x : Spin n) : + gaussianSpinPartition n r g/(∫ g,gaussianSpinPartition n r g ∂gaussianCoordinates (Edge n))* + mass (fun e=>sqrt r*g e) 0 x = + (1/(Fintype.card (Spin n):ℝ))* + exp ((∑ e,edgeCoefficient r x e*g e)-(∑ e,edgeCoefficient r x e^2)/2) := by + rw [gaussianSpinPartition_integral hr,edgeCoefficient_sq_sum hr] + rw [mass,← gaussianSpinPartition_eq_partition,scaled_weight_eq,exp_sub] + have hp := gaussianSpinPartition_pos n r g + have hc : (Fintype.card (Spin n):ℝ) ≠ 0 := by positivity + field_simp + +theorem planted_joint_tilt {n : ℕ} {r : ℝ} (hr : 0 ≤ r) + (F : Spin n→Disorder n→ℝ≥0∞) (hF : ∀ x,Measurable (F x)) : + (∫⁻ g, ENNReal.ofReal (gaussianSpinPartition n r g/ + (∫ g,gaussianSpinPartition n r g ∂gaussianCoordinates (Edge n)))* + ∑ x,ENNReal.ofReal (mass (fun e=>sqrt r*g e) 0 x)*F x (fun e=>sqrt r*g e) + ∂gaussianCoordinates (Edge n)) = + ENNReal.ofReal (1/(Fintype.card (Spin n):ℝ))*∑ x : Spin n, + ∫⁻ g,F x (fun e=>sqrt r*g e+r*spinValue (x e.1.1)*spinValue (x e.1.2)) + ∂gaussianCoordinates (Edge n) := by + have hM : 0 < ∫ g,gaussianSpinPartition n r g ∂gaussianCoordinates (Edge n) := + gaussianSpinPartition_mean_pos hr + simp_rw [Finset.mul_sum,← mul_assoc,← ENNReal.ofReal_mul (div_nonneg + (gaussianSpinPartition_pos n r _).le hM.le),partition_mass_normalized hr, + ENNReal.ofReal_mul (by positivity : (0:ℝ) ≤ 1/(Fintype.card (Spin n):ℝ)),mul_assoc] + rw [lintegral_finsetSum _ (fun x _=>by fun_prop)] + apply Finset.sum_congr rfl + intro x _ + rw [lintegral_const_mul _ (by fun_prop)] + congr 1 + rw [gaussian_tilt_lintegral (edgeCoefficient r x) (fun g : Disorder n=>F x (fun e=>sqrt r*g e)) ((hF x).comp (by fun_prop))] + apply lintegral_congr + intro g + congr 1 + ext e + unfold edgeCoefficient + calc + _ = sqrt r*g e+(sqrt r)^2*(spinValue (x e.1.1)*spinValue (x e.1.2)) := by ring + _ = _ := by rw [sq_sqrt hr] + +theorem planted_disorder_joint_tilt {n : ℕ} (β : ℝ) + (F : Spin n→Disorder n→ℝ≥0∞) (hF : ∀ x,Measurable (F x)) : + (∫⁻ J,ENNReal.ofReal (partition J 0/(∫ J,partition J 0 ∂disorderLaw β n))* + ∑ x,ENNReal.ofReal (mass J 0 x)*F x J ∂disorderLaw β n)= + ENNReal.ofReal (1/(Fintype.card (Spin n):ℝ))*∑ x : Spin n, + ∫⁻ g,F x (fun e=>sqrt (β^2/(n:ℝ))*g e+(β^2/(n:ℝ))*spinValue (x e.1.1)*spinValue (x e.1.2)) + ∂gaussianCoordinates (Edge n) := by + have hmass (x : Spin n) : Measurable (fun J : Disorder n=>mass J 0 x) := by + simpa only [sqrt_one,one_mul] using scaled_spin_mass_measurable 1 x + have hi : Measurable (fun J : Disorder n=> + ENNReal.ofReal (partition J 0/(∫ J,partition J 0 ∂disorderLaw β n))* + ∑ x,ENNReal.ofReal (mass J 0 x)*F x J) := + ((partition_zero_measurable n).div_const _).ennreal_ofReal.mul + (Finset.measurable_sum _ (fun x _=>(hmass x).ennreal_ofReal.mul (hF x))) + rw [← (gaussian_disorder_hasLaw β n).lintegral_comp hi.aemeasurable] + simpa only [disorder_partition_mean,← gaussianSpinPartition_eq_partition] using + planted_joint_tilt (n:=n) (r:=β^2/(n:ℝ)) (by positivity) F hF +end SKGap +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/PoissonBinomial.lean b/lean/OAI/Probability/SKGap/Localization/PoissonBinomial.lean new file mode 100644 index 0000000000000000000000000000000000000000..a0fcff72d037a3284f29f514460f9b5a274edfdf --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/PoissonBinomial.lean @@ -0,0 +1,261 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.SumPoissonMass +import OAI.Probability.SKGap.Gaussian.GaussianPDFMoment +import OAI.Probability.SKGap.Localization.IntegrableMulBounded + +namespace OAI + +section +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open scoped BigOperators +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open scoped BigOperators +open scoped BigOperators NNReal ENNReal +open MeasureTheory Metric Set +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators NNReal ENNReal Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Set +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators ENNReal NNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Matrix +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators ENNReal NNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal +open scoped BigOperators +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise NNReal ENNReal +open scoped BigOperators +open Filter Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal Topology +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Set Matrix +open scoped BigOperators NNReal ENNReal Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open Filter MeasureTheory ProbabilityTheory +open scoped Topology NNReal ENNReal +open Filter MeasureTheory ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter +open scoped Topology NNReal ENNReal +open MeasureTheory Filter ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter +open scoped Topology +open MeasureTheory Filter ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter ProbabilityTheory +open scoped Topology NNReal ENNReal +namespace SKGapCutoff.Clock + +theorem poisson_to_binomial {q B : ℝ} (hq : 0 < q) (hq1 : q < 1) (hB : 0 < B) + (M : ℕ → ℕ) (hM : Tendsto M atTop atTop) (a : ℕ → ℕ → ℝ) + (hab : ∀ n j, |a n j| ≤ B) + (hp : ∀ y : ℝ, Tendsto (fun n => ∑' j, + poissonMass (q*M n+y*Real.sqrt (M n)) j*a n j) atTop (𝓝 0)) : + Tendsto (fun n => ∑' j, binomialMass q (M n) j*a n j) atTop (𝓝 0) := by + let u : ℕ → ℝ → ℝ := fun n => testHistogram q (M n) (a n) + have hu (n : ℕ) : AEStronglyMeasurable (u n) := + (measurable_testHistogram q (M n) (a n)).aestronglyMeasurable + have hub (n : ℕ) (x : ℝ) : |u n x| ≤ B := testHistogram_bound hB.le (hab n) q (M n) x + have hMn : ∀ᶠ n in atTop, 0 < M n := hM.eventually (eventually_gt_atTop 0) + have hPi (y : ℝ) : ∀ᶠ n in atTop, + Integrable (histogram q (M n) (poissonMass (q*M n+y*Real.sqrt (M n)))) := by + filter_upwards [hMn] with n hn + exact integrable_histogram (hasSum_poissonMass _) q hn + have hdiff (y : ℝ) := pairing_of_L1_limit (hPi y) + (integrable_gaussianPDFReal y ⟨q,hq.le⟩) hu hub ((poisson_density_L1 hq y).comp hM) + have hP (y : ℝ) : Tendsto (fun n => ∫ x : ℝ, + histogram q (M n) (poissonMass (q*M n+y*Real.sqrt (M n))) x*u n x) + atTop (𝓝 0) := by + apply (hp y).congr' + filter_upwards [hMn] with n hn + exact (integral_histogram_test (hasSum_poissonMass _).summable (hab n) q hn).symm + have hG (y : ℝ) : Tendsto (fun n => ∫ x : ℝ, gaussianPDFReal y ⟨q,hq.le⟩ x*u n x) + atTop (𝓝 0) := by + have hh := (hP y).sub (hdiff y) + simpa only [sub_sub_cancel,sub_zero] using hh + let v : ℝ≥0 := ⟨q,hq.le⟩ + let w : ℝ≥0 := ⟨q*(1-q),mul_nonneg hq.le (by linarith)⟩ + have hv : 0 < v := hq + have hw : 0 < w := mul_pos hq (by linarith) + have hwv : w ≤ v := by + change q*(1-q) ≤ q + nlinarith [sq_nonneg q] + have hGb : Tendsto (fun n => ∫ x : ℝ, gaussianPDFReal 0 w x*u n x) + atTop (𝓝 0) := + pairing_of_finite_approximation (integrable_gaussianPDFReal 0 w) + (fun y => integrable_gaussianPDFReal (-y) v) hB hu hub + (fun ε hε => finite_gaussianPDF_approximation hv hw hwv hε) (fun y => hG (-y)) + have hBi : ∀ᶠ n in atTop, Integrable (histogram q (M n) (binomialMass q (M n))) := by + filter_upwards [hMn] with n hn + exact integrable_histogram (hasSum_binomialMass q _) q hn + have hBd := pairing_of_L1_limit hBi (integrable_gaussianPDFReal 0 w) hu hub + ((binomial_density_L1 hq hq1).comp hM) + have hBin : Tendsto (fun n => ∫ x : ℝ, + histogram q (M n) (binomialMass q (M n)) x*u n x) atTop (𝓝 0) := by + have hh := hBd.add hGb + simpa only [sub_add_cancel,zero_add] using hh + apply hBin.congr' + filter_upwards [hMn] with n hn + exact integral_histogram_test (hasSum_binomialMass q _).summable (hab n) q hn + +lemma uniform_zero_of_selections {ι : ℕ → Type*} [∀ n, Nonempty (ι n)] + (f : (n : ℕ) → ι n → ℝ) + (hf : ∀ i : (n : ℕ) → ι n, Tendsto (fun n => f n (i n)) atTop (𝓝 0)) : + ∀ ε : ℝ, 0 < ε → ∀ᶠ n in atTop, ∀ i : ι n, |f n i| < ε := by + classical + intro ε hε + let i : (n : ℕ) → ι n := fun n => + if h : ∃ i : ι n, ε ≤ |f n i| then Classical.choose h else Classical.choice (inferInstance : Nonempty (ι n)) + have hh : ∀ᶠ n in atTop, |f n (i n)| < ε := by + have he := (hf i).eventually (Metric.ball_mem_nhds 0 hε) + simpa only [Metric.mem_ball,Real.dist_eq,sub_zero] using he + filter_upwards [hh] with n hn + intro j + by_contra h + have hbad : ∃ j : ι n, ε ≤ |f n j| := ⟨j,le_of_not_gt h⟩ + have hlarge : ε ≤ |f n (i n)| := by simpa only [i,dite_eq_left hbad] using Classical.choose_spec hbad + exact (not_le.mpr hn) hlarge + +theorem poisson_to_binomial_uniform {q B : ℝ} (hq : 0 < q) (hq1 : q < 1) (hB : 0 < B) + (M : ℕ → ℕ) (hM : Tendsto M atTop atTop) + {ι : ℕ → Type*} [∀ n, Nonempty (ι n)] + (a : (n : ℕ) → ι n → ℕ → ℝ) (hab : ∀ n i j, |a n i j| ≤ B) + (hp : ∀ y ε : ℝ, 0 < ε → ∀ᶠ n in atTop, ∀ i : ι n, + |∑' j, poissonMass (q*M n+y*Real.sqrt (M n)) j*a n i j| < ε) : + ∀ ε : ℝ, 0 < ε → ∀ᶠ n in atTop, ∀ i : ι n, + |∑' j, binomialMass q (M n) j*a n i j| < ε := by + apply uniform_zero_of_selections + intro i + apply poisson_to_binomial hq hq1 hB M hM (fun n => a n (i n)) + (fun n j => hab n (i n) j) + intro y + apply Metric.tendsto_atTop.mpr + intro ε hε + obtain ⟨N,hN⟩ := eventually_atTop.mp (hp y ε hε) + refine ⟨N,fun n hn => ?_⟩ + simpa only [Real.dist_eq,sub_zero] using hN n hn (i n) + +theorem poisson_to_binomial_bounded {q B : ℝ} (hq : 0 < q) (hq1 : q < 1) + (M : ℕ → ℕ) (hM : Tendsto M atTop atTop) (a : ℕ → ℕ → ℝ) + (hab : ∀ n j, |a n j| ≤ B) + (hp : ∀ y : ℝ, Tendsto (fun n => ∑' j, + poissonMass (q*M n+y*Real.sqrt (M n)) j*a n j) atTop (𝓝 0)) : + Tendsto (fun n => ∑' j, binomialMass q (M n) j*a n j) atTop (𝓝 0) := by + apply poisson_to_binomial hq hq1 (show 0 < |B|+1 by positivity) M hM a + (fun n j => (hab n j).trans ((le_abs_self B).trans (by linarith))) hp + +theorem poisson_to_binomial_uniform_clocks {q B : ℝ} (hq : 0 < q) (hq1 : q < 1) + {ι : ℕ → Type*} [∀ n, Nonempty (ι n)] (M : (n : ℕ) → ι n → ℕ) + (hM : ∀ K : ℕ, ∀ᶠ n in atTop, ∀ i : ι n, K ≤ M n i) + (a : (n : ℕ) → ι n → ℕ → ℝ) (hab : ∀ n i j, |a n i j| ≤ B) + (hp : ∀ y ε : ℝ, 0 < ε → ∀ᶠ n in atTop, ∀ i : ι n, + |∑' j, poissonMass (q*M n i+y*Real.sqrt (M n i)) j*a n i j| < ε) : + ∀ ε : ℝ, 0 < ε → ∀ᶠ n in atTop, ∀ i : ι n, + |∑' j, binomialMass q (M n i) j*a n i j| < ε := by + apply uniform_zero_of_selections + intro i + have hMi : Tendsto (fun n => M n (i n)) atTop atTop := by + apply Filter.tendsto_atTop.mpr + intro K + filter_upwards [hM K] with n hn + exact hn (i n) + apply poisson_to_binomial_bounded hq hq1 (fun n => M n (i n)) hMi (fun n => a n (i n)) + (fun n j => hab n (i n) j) + intro y + apply Metric.tendsto_atTop.mpr + intro ε hε + obtain ⟨N,hN⟩ := eventually_atTop.mp (hp y ε hε) + refine ⟨N,fun n hn => ?_⟩ + simpa only [Real.dist_eq,sub_zero] using hN n hn (i n) + +end SKGapCutoff.Clock + +open MeasureTheory Filter ProbabilityTheory +open scoped Topology NNReal ENNReal + +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/PoissonBinomialProbability.lean b/lean/OAI/Probability/SKGap/Localization/PoissonBinomialProbability.lean new file mode 100644 index 0000000000000000000000000000000000000000..011e5e4b76acf31664bd8149d97216731fa33e1c --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/PoissonBinomialProbability.lean @@ -0,0 +1,461 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.PoissonWeight +import OAI.Probability.SKGap.Terminal.PairingPairingAddError + +namespace OAI + +section +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open scoped BigOperators +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open scoped BigOperators +open scoped BigOperators NNReal ENNReal +open MeasureTheory Metric Set +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators NNReal ENNReal Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Set +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators ENNReal NNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Matrix +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators ENNReal NNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal +open scoped BigOperators +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise NNReal ENNReal +open scoped BigOperators +open Filter Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal Topology +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Set Matrix +open scoped BigOperators NNReal ENNReal Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open Filter MeasureTheory ProbabilityTheory +open scoped Topology NNReal ENNReal +open Filter MeasureTheory ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter +open scoped Topology NNReal ENNReal +open MeasureTheory Filter ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter +open scoped Topology +open MeasureTheory Filter ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter ProbabilityTheory +open scoped Topology NNReal ENNReal +namespace SKGapCutoff.Clock + +theorem poisson_to_binomial_in_probability {q B : ℝ} (hq : 0 < q) (hq1 : q < 1) + (hB : 0 < B) {Ω : ℕ → Type*} [∀ n, MeasurableSpace (Ω n)] + (μ : ∀ n, Measure (Ω n)) (good : (n : ℕ) → Ω n → Prop) + (hgood : Tendsto (fun n => μ n {ω | ¬good n ω}) atTop (𝓝 0)) + {ι : ℕ → Type*} (M : (n : ℕ) → Ω n → ℕ) + (hM : ∀ K : ℕ, ∀ᶠ n in atTop, ∀ ω, good n ω → K ≤ M n ω) + (a : (n : ℕ) → Ω n → ι n → ℕ → ℝ) + (hab : ∀ n ω, good n ω → ∀ i j, |a n ω i j| ≤ B) + (hp : ∀ y ε : ℝ, 0 < ε → Tendsto (fun n => μ n + {ω | good n ω ∧ ∃ i, ε < |∑' j, + poissonMass (q*M n ω+y*Real.sqrt (M n ω)) j*a n ω i j|}) atTop (𝓝 0)) : + ∀ ε : ℝ, 0 < ε → Tendsto (fun n => μ n + {ω | ∃ i, ε < |∑' j, binomialMass q (M n ω) j*a n ω i j|}) atTop (𝓝 0) := by + classical + intro ε hε + obtain ⟨s,δ,hδ,N,hN⟩ := finite_clock_certificate hq hq1 hB hε + let E : (n : ℕ) → ℝ → Set (Ω n) := fun n y => + {ω | good n ω ∧ ∃ i, δ/2 < |∑' j, + poissonMass (q*M n ω+(-y)*Real.sqrt (M n ω)) j*a n ω i j|} + have hsum : Tendsto (fun n => ∑ y ∈ s, μ n (E n y)) atTop (𝓝 0) := by + simpa only [E, Finset.sum_const_zero] using tendsto_finsetSum s (fun y _ => hp (-y) (δ/2) (by positivity)) + have hlimit := hgood.add hsum + simp only [add_zero] at hlimit + apply tendsto_const_nhds.squeeze' hlimit (Eventually.of_forall (fun _ => zero_le)) + filter_upwards [hM N] with n hn + calc + _ ≤ μ n ({ω | ¬good n ω} ∪ ⋃ y ∈ s, E n y) := by + apply measure_mono + intro ω hω + by_cases hg : good n ω + · apply Or.inr + by_contra hnone + have hsmall : ∀ i y, y ∈ s → |∑' j, + poissonMass (q*M n ω+(-y)*Real.sqrt (M n ω)) j*a n ω i j| < δ := by + intro i y hy + have hnE : ω ∉ E n y := by + intro hh + exact hnone (Set.mem_iUnion.mpr ⟨y,Set.mem_iUnion.mpr ⟨hy,hh⟩⟩) + have hle : |∑' j, poissonMass (q*M n ω+(-y)*Real.sqrt (M n ω)) j* + a n ω i j| ≤ δ/2 := by + by_contra h + exact hnE ⟨hg,i,lt_of_not_ge h⟩ + linarith + obtain ⟨i,hi⟩ := hω + exact (not_lt_of_ge (hN (M n ω) (hn ω hg) (a n ω i) (hab n ω hg i) + (hsmall i)).le) hi + · exact Or.inl hg + _ ≤ μ n {ω | ¬good n ω}+μ n (⋃ y ∈ s, E n y) := measure_union_le _ _ + _ ≤ μ n {ω | ¬good n ω}+∑ y ∈ s, μ n (E n y) := + add_le_add le_rfl (measure_biUnion_finset_le s (E n)) + +end SKGapCutoff.Clock + +open MeasureTheory Filter ProbabilityTheory ContinuousLinearMap +open scoped Topology NNReal ENNReal + +namespace SKGapCutoff + +noncomputable def residualAttempt {n : ℕ} (J : Interaction n) (q : ℝ) : + Observables n →L[ℝ] Observables n := + q⁻¹ • (attemptLM J-(1-q) • 1) + +lemma residualAttempt_apply {n : ℕ} (J : Interaction n) (q : ℝ) + (f : Observables n) (x : Spin n) : + residualAttempt J q f x = (attemptLM J f x-(1-q)*f x)/q := by + simp [residualAttempt,div_eq_mul_inv,mul_comm] + +lemma attempt_eq_lazy_residual {n : ℕ} (J : Interaction n) {q : ℝ} (hq : q ≠ 0) : + attemptLM J = q • residualAttempt J q+(1-q) • 1 := by + simp only [residualAttempt,smul_smul,mul_inv_cancel₀ hq,one_smul,sub_add_cancel] + +lemma residualAttempt_const {n : ℕ} (J : Interaction n) {q : ℝ} (hq : q ≠ 0) + (c : ℝ) : residualAttempt J q (fun _ => c) = fun _ => c := by + ext x + rw [residualAttempt_apply,attempt_const] + field_simp + ring + +lemma residualAttempt_pow_const {n : ℕ} (J : Interaction n) {q : ℝ} (hq : q ≠ 0) + (k : ℕ) (c : ℝ) : (residualAttempt J q ^ k) (fun _ => c) = fun _ => c := by + induction k with + | zero => simp + | succ k ih => rw [pow_succ',mul_apply_eq_comp,ih,residualAttempt_const J hq] + +lemma residualAttempt_nonneg {n : ℕ} (J : Interaction n) {q : ℝ} (hq : 0 < q) + (hhold : ∀ x, 1-q ≤ discreteKernel J 1 x x) + (f : Observables n) (hf : ∀ x, 0 ≤ f x) (x : Spin n) : + 0 ≤ residualAttempt J q f x := by + rw [← kernel_apply (residualAttempt J q) f x] + apply Finset.sum_nonneg + intro y _ + apply mul_nonneg _ (hf y) + rw [residualAttempt_apply] + apply div_nonneg _ hq.le + by_cases hxy : x=y + · subst y + simpa [discreteKernel,pow_one] using sub_nonneg.mpr (hhold x) + · simpa only [hxy,↓reduceIte,mul_zero,sub_zero,discreteKernel,pow_one] using + discreteKernel_nonneg J 1 x y + +lemma residualAttempt_pow_nonneg {n : ℕ} (J : Interaction n) {q : ℝ} (hq : 0 < q) + (hhold : ∀ x, 1-q ≤ discreteKernel J 1 x x) + (k : ℕ) (f : Observables n) (hf : ∀ x, 0 ≤ f x) (x : Spin n) : + 0 ≤ (residualAttempt J q ^ k) f x := by + induction k generalizing x with + | zero => exact hf x + | succ k ih => + rw [pow_succ',mul_apply_eq_comp] + exact residualAttempt_nonneg J hq hhold _ (fun x => ih x) x + +lemma residualAttempt_pow_abs_le {n : ℕ} (J : Interaction n) {q : ℝ} (hq : 0 < q) + (hhold : ∀ x, 1-q ≤ discreteKernel J 1 x x) + (k : ℕ) (f : Observables n) (hf : ∀ x, |f x| ≤ 1) (x : Spin n) : + |(residualAttempt J q ^ k) f x| ≤ 1 := by + have hup := residualAttempt_pow_nonneg J hq hhold k (fun y => 1-f y) + (fun y => by have := (abs_le.mp (hf y)).2; linarith) x + have hlo := residualAttempt_pow_nonneg J hq hhold k (fun y => f y+1) + (fun y => by have := (abs_le.mp (hf y)).1; linarith) x + change 0 ≤ (residualAttempt J q ^ k) ((fun _ => 1)-f) x at hup + change 0 ≤ (residualAttempt J q ^ k) (f+(fun _ => 1)) x at hlo + rw [map_sub,residualAttempt_pow_const J hq.ne'] at hup + rw [map_add,residualAttempt_pow_const J hq.ne'] at hlo + simp only [Pi.add_apply,Pi.sub_apply] at hlo hup + exact abs_le.mpr ⟨by linarith,by linarith⟩ + +lemma residual_semigroup_uniformization {n : ℕ} (hn : 0 < n) + (J : Interaction n) {q : ℝ} (hq : q ≠ 0) (t : ℝ) : + semigroup J t = Real.exp (-(q*n*t)) • + NormedSpace.exp ((q*n*t) • residualAttempt J q) := by + have hn' : (n : ℝ) ≠ 0 := by exact_mod_cast hn.ne' + have heq : t • generatorCLM J = + (-(q*n*t)) • (1 : Observables n →L[ℝ] Observables n) + + (q*n*t) • residualAttempt J q := by + unfold residualAttempt attemptLM + simp only [smul_smul,smul_sub,smul_add] + have hc : q*n*t*q⁻¹ = (n:ℝ)*t := by field_simp + have hc' : q*n*t*(q⁻¹*(n:ℝ)⁻¹) = t := by field_simp + have hc'' : q*n*t*(q⁻¹*(1-q)) = (n:ℝ)*t*(1-q) := by field_simp + rw [hc,hc',hc''] + module + let : NormedAlgebra ℚ (Observables n →L[ℝ] Observables n) := + NormedAlgebra.restrictScalars ℚ ℝ _ + unfold semigroup + rw [heq,NormedSpace.exp_add_of_commute + (((Commute.one_left (residualAttempt J q)).smul_left _).smul_right _), + exp_smul_identity,smul_mul_assoc,one_mul] + +lemma residual_poisson_hasSum {n : ℕ} (hn : 0 < n) + (J : Interaction n) {q : ℝ} (hq : q ≠ 0) (t : ℝ) + (f : Observables n) (x : Spin n) : + HasSum (fun j => Clock.poissonMass (q*n*t) j*(residualAttempt J q ^ j) f x) + (semigroup J t f x) := by + have hs := (Pi.hasSum.mp (exp_apply_hasSum ((q*n*t) • residualAttempt J q) f) x).mul_left + (Real.exp (-(q*n*t))) + convert! hs using 1 + · funext j + simp only [smul_pow,_root_.smul_apply,Pi.smul_apply,smul_eq_mul,Clock.poissonMass] + ring + · rw [residual_semigroup_uniformization hn J hq] + rfl + +lemma natCastCLM_apply {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] + (k : ℕ) (f : E) : (k : E →L[ℝ] E) f = (k:ℝ) • f := by + induction k with + | zero => simp + | succ k ih => simp [Nat.cast_succ,ih,add_smul] + +lemma residual_binomial_sum {n : ℕ} (J : Interaction n) {q : ℝ} (hq : q ≠ 0) + (M : ℕ) (f : Observables n) (x : Spin n) : + (∑ j ∈ Finset.range (M+1), Clock.binomialMass q M j* + (residualAttempt J q ^ j) f x) = (attemptLM J ^ M) f x := by + rw [attempt_eq_lazy_residual J hq] + rw [(((Commute.one_right (residualAttempt J q)).smul_left q).smul_right (1-q)).add_pow] + simp only [_root_.sum_apply,smul_pow,one_pow,smul_mul_assoc,mul_smul_comm,mul_one, + Clock.binomialMass,mul_apply_eq_comp,_root_.smul_apply,Finset.sum_apply,Pi.smul_apply,smul_eq_mul] + apply Finset.sum_congr rfl + intro j _ + simp only [natCastCLM_apply,map_smul,Pi.smul_apply,smul_eq_mul] + ring + +lemma residual_binomial_hasSum {n : ℕ} (J : Interaction n) {q : ℝ} (hq : q ≠ 0) + (M : ℕ) (f : Observables n) (x : Spin n) : + HasSum (fun j => Clock.binomialMass q M j*(residualAttempt J q ^ j) f x) + ((attemptLM J ^ M) f x) := by + rw [← residual_binomial_sum J hq M f x] + apply hasSum_sum_of_ne_finset_zero + intro j hj + have hj' : M < j := by simp only [Finset.mem_range,not_lt] at hj; omega + simp [Clock.binomialMass,Nat.choose_eq_zero_of_lt hj'] + +lemma gibbsExpectation_abs_le_one {n : ℕ} (J : Interaction n) (f : Observables n) + (hf : ∀ x, |f x| ≤ 1) : |gibbsExpectation J f| ≤ 1 := by + unfold gibbsExpectation + calc + _ ≤ ∑ x, |gibbs J x*f x| := Finset.abs_sum_le_sum_abs _ _ + _ ≤ ∑ x, gibbs J x := by + apply Finset.sum_le_sum + intro x _ + rw [abs_mul,abs_of_nonneg (gibbs_pos J x).le] + exact mul_le_of_le_one_right (gibbs_pos J x).le (hf x) + _ = _ := gibbs_sum J + +lemma residual_test_bound {n : ℕ} (J : Interaction n) {q : ℝ} (hq : 0 < q) + (hhold : ∀ x, 1-q ≤ discreteKernel J 1 x x) + (f : Observables n) (hf : ∀ x, |f x| ≤ 1) (x : Spin n) (j : ℕ) : + |(residualAttempt J q ^ j) f x-gibbsExpectation J f| ≤ 2 := by + have h := abs_sub ((residualAttempt J q ^ j) f x) (gibbsExpectation J f) + linarith [residualAttempt_pow_abs_le J hq hhold j f hf x, + gibbsExpectation_abs_le_one J f hf] + +lemma residual_poisson_test {n : ℕ} (hn : 0 < n) + (J : Interaction n) {q : ℝ} (hq : q ≠ 0) (m : ℝ) + (f : Observables n) (x : Spin n) : + (∑' j, Clock.poissonMass m j*((residualAttempt J q ^ j) f x-gibbsExpectation J f)) = + semigroup J (m/(q*n)) f x-gibbsExpectation J f := by + have hn' : (n : ℝ) ≠ 0 := by exact_mod_cast hn.ne' + have he : q*n*(m/(q*n)) = m := by field_simp + have hs := residual_poisson_hasSum hn J hq (m/(q*n)) f x + rw [he] at hs + have hh := hs.sub ((Clock.hasSum_poissonMass m).mul_right (gibbsExpectation J f)) + simpa only [one_mul,← mul_sub] using hh.tsum_eq + +lemma residual_binomial_test {n : ℕ} (J : Interaction n) {q : ℝ} (hq : q ≠ 0) + (M : ℕ) (f : Observables n) (x : Spin n) : + (∑' j, Clock.binomialMass q M j*((residualAttempt J q ^ j) f x-gibbsExpectation J f)) = + (attemptLM J ^ M) f x-gibbsExpectation J f := by + have hs := residual_binomial_hasSum J hq M f x + have hh := hs.sub ((Clock.hasSum_binomialMass q M).mul_right (gibbsExpectation J f)) + simpa only [one_mul,← mul_sub] using hh.tsum_eq + +lemma totalVariation_test_bound {n : ℕ} (p r f : Spin n → ℝ) + (hf : ∀ y, |f y| ≤ 1) : + |(∑ y, p y*f y)-(∑ y, r y*f y)| ≤ 2*totalVariation p r := by + rw [← Finset.sum_sub_distrib] + simp_rw [← sub_mul] + calc + _ ≤ ∑ y, |(p y-r y)*f y| := Finset.abs_sum_le_sum_abs _ _ + _ ≤ ∑ y, |p y-r y| := by + apply Finset.sum_le_sum + intro y _ + rw [abs_mul] + exact mul_le_of_le_one_right (abs_nonneg _) (hf y) + _ = _ := by dsimp [totalVariation]; ring + +lemma continuous_test_bound {n : ℕ} (J : Interaction n) (t : ℝ) + (f : Observables n) (hf : ∀ y, |f y| ≤ 1) (x : Spin n) : + |semigroup J t f x-gibbsExpectation J f| ≤ 2*worstContinuous J t := by + rw [← kernel_apply (semigroup J t) f x] + apply (totalVariation_test_bound (continuousKernel J t x) (gibbs J) f hf).trans + apply mul_le_mul_of_nonneg_left _ (by norm_num) + exact Finset.le_sup' (fun x => totalVariation (continuousKernel J t x) (gibbs J)) + (Finset.mem_univ x) + +lemma totalVariation_has_test {n : ℕ} (p r : Spin n → ℝ) : + ∃ f : Observables n, (∀ y, |f y| ≤ 1) ∧ + (∑ y, p y*f y)-(∑ y, r y*f y) = 2*totalVariation p r := by + let f : Observables n := fun y => if 0 ≤ p y-r y then 1 else -1 + refine ⟨f,fun y => ?_,?_⟩ + · dsimp [f]; split_ifs <;> norm_num + · rw [← Finset.sum_sub_distrib] + have hf (y : Spin n) : p y*f y-r y*f y = |p y-r y| := by + dsimp [f] + split_ifs with h + · rw [abs_of_nonneg h]; ring + · rw [abs_of_neg (lt_of_not_ge h)]; ring + simp_rw [hf] + dsimp [totalVariation] + ring + +lemma worstDiscrete_has_test {n : ℕ} (J : Interaction n) (M : ℕ) : + ∃ (x : Spin n) (f : Observables n), (∀ y, |f y| ≤ 1) ∧ + (attemptLM J ^ M) f x-gibbsExpectation J f = 2*worstDiscrete J M := by + obtain ⟨x,_,hx⟩ := Finset.exists_max_image (Finset.univ : Finset (Spin n)) + (fun x => totalVariation (discreteKernel J M x) (gibbs J)) Finset.univ_nonempty + obtain ⟨f,hf,hfe⟩ := totalVariation_has_test (discreteKernel J M x) (gibbs J) + refine ⟨x,f,hf,?_⟩ + have hm : worstDiscrete J M = totalVariation (discreteKernel J M x) (gibbs J) := by + apply le_antisymm + · exact Finset.sup'_le _ _ (fun y hy => hx y hy) + · exact Finset.le_sup' (fun z => totalVariation (discreteKernel J M z) (gibbs J)) + (Finset.mem_univ x) + rw [hm,← kernel_apply (attemptLM J ^ M) f x] + exact hfe + +lemma semigroup_add_eq_comp {n : ℕ} (J : Interaction n) (s t : ℝ) : + semigroup J (s+t) = semigroup J s*semigroup J t := by + let : NormedAlgebra ℚ (Observables n →L[ℝ] Observables n) := + NormedAlgebra.restrictScalars ℚ ℝ _ + unfold semigroup + rw [add_smul,NormedSpace.exp_add_of_commute + (((Commute.refl (generatorCLM J)).smul_left s).smul_right t)] + +lemma continuousKernel_add {n : ℕ} (J : Interaction n) (s t : ℝ) (x y : Spin n) : + continuousKernel J (s+t) x y = ∑ z, continuousKernel J s x z*continuousKernel J t z y := by + unfold continuousKernel + rw [semigroup_add_eq_comp,mul_apply_eq_comp] + exact (kernel_apply (semigroup J s) _ x).symm + +lemma worstContinuous_add_le {n : ℕ} (J : Interaction n) (s t : ℝ) (hs : 0 ≤ s) : + worstContinuous J (s+t) ≤ worstContinuous J t := by + apply Finset.sup'_le + intro x _ + change totalVariation (fun y => continuousKernel J (s+t) x y) (gibbs J) ≤ _ + simp_rw [continuousKernel_add] + apply (totalVariation_mixture_le _ (continuousKernel_nonneg J s hs x) + (continuousKernel_sum J s x) _ _).trans + calc + _ ≤ ∑ z, continuousKernel J s x z*worstContinuous J t := by + apply Finset.sum_le_sum + intro z _ + apply mul_le_mul_of_nonneg_left _ (continuousKernel_nonneg J s hs x z) + exact Finset.le_sup' (fun z => totalVariation (continuousKernel J t z) (gibbs J)) + (Finset.mem_univ z) + _ = _ := by rw [← Finset.sum_mul,continuousKernel_sum,one_mul] + +lemma worstContinuous_mono_time {n : ℕ} (J : Interaction n) {s t : ℝ} (h : s ≤ t) : + worstContinuous J t ≤ worstContinuous J s := by + simpa only [sub_add_cancel] using worstContinuous_add_le J (t-s) s (sub_nonneg.mpr h) + +end SKGapCutoff + +open Filter MeasureTheory ProbabilityTheory +open scoped Topology NNReal ENNReal + +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/PoissonWeight.lean b/lean/OAI/Probability/SKGap/Localization/PoissonWeight.lean new file mode 100644 index 0000000000000000000000000000000000000000..916103febaf9619702ad02dc5071eaf3c9ce3d62 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/PoissonWeight.lean @@ -0,0 +1,386 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.ThresholdChoice + +namespace OAI + +section +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open scoped BigOperators +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open scoped BigOperators +open scoped BigOperators NNReal ENNReal +open MeasureTheory Metric Set +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators NNReal ENNReal Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Set +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators ENNReal NNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Matrix +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators ENNReal NNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal +open scoped BigOperators +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise NNReal ENNReal +open scoped BigOperators +open Filter Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal Topology +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +namespace SKGapCutoff + +lemma totalVariation_mixture_le {n : ℕ} (w : Spin n → ℝ) + (hw : ∀ x, 0 ≤ w x) (hs : ∑ x, w x = 1) + (p : Spin n → Spin n → ℝ) (q : Spin n → ℝ) : + totalVariation (fun y => ∑ x, w x*p x y) q ≤ + ∑ x, w x*totalVariation (p x) q := by + unfold totalVariation + have he y : (∑ x, w x*p x y)-q y = ∑ x, w x*(p x y-q y) := by + simp_rw [mul_sub, Finset.sum_sub_distrib] + rw [← Finset.sum_mul, hs, one_mul] + simp_rw [he] + calc + _ ≤ (∑ y, ∑ x, |w x*(p x y-q y)|)/2 := by + gcongr + exact Finset.abs_sum_le_sum_abs _ _ + _ = _ := by + simp only [abs_mul, abs_of_nonneg (hw _)] + rw [Finset.sum_comm] + simp only [Finset.sum_div, Finset.mul_sum, mul_div_assoc] + +lemma discreteKernel_add {n : ℕ} (J : Interaction n) (j k : ℕ) (x y : Spin n) : + discreteKernel J (j+k) x y = ∑ z, discreteKernel J j x z*discreteKernel J k z y := by + unfold discreteKernel + rw [pow_add, mul_apply_eq_comp] + exact (kernel_apply (attemptLM J ^ j) _ x).symm + +lemma worstDiscrete_add_le {n : ℕ} (J : Interaction n) (j k : ℕ) : + worstDiscrete J (j+k) ≤ worstDiscrete J k := by + apply Finset.sup'_le + intro x _ + change totalVariation (fun y => discreteKernel J (j+k) x y) (gibbs J) ≤ _ + simp_rw [discreteKernel_add] + apply (totalVariation_mixture_le _ (discreteKernel_nonneg J j x) + (discreteKernel_sum J j x) _ _).trans + calc + _ ≤ ∑ z, discreteKernel J j x z * worstDiscrete J k := by + apply Finset.sum_le_sum + intro z _ + apply mul_le_mul_of_nonneg_left _ (discreteKernel_nonneg J j x z) + exact Finset.le_sup' (fun z => totalVariation (discreteKernel J k z) (gibbs J)) (Finset.mem_univ z) + _ = _ := by rw [← Finset.sum_mul, discreteKernel_sum, one_mul] + +lemma worstDiscrete_antitone {n : ℕ} (J : Interaction n) : + Antitone (worstDiscrete J) := by + intro k j h + obtain ⟨d, rfl⟩ := Nat.exists_eq_add_of_le h + rw [Nat.add_comm] + exact worstDiscrete_add_le J d k + +noncomputable def poissonWeight (r : ℝ) (j : ℕ) : ℝ := + Real.exp (-r)*r^j/(j.factorial : ℝ) + +lemma poissonWeight_nonneg {r : ℝ} (hr : 0 ≤ r) (j : ℕ) : + 0 ≤ poissonWeight r j := by unfold poissonWeight; positivity + +lemma poissonWeight_hasSum {r : ℝ} (hr : 0 ≤ r) : HasSum (poissonWeight r) 1 := + hasSum_one_poissonMeasure ⟨r,hr⟩ + +lemma poissonWeight_exp_hasSum (r s : ℝ) : + HasSum (fun j => poissonWeight r j*Real.exp (s*(j:ℝ))) + (Real.exp (r*(Real.exp s-1))) := by + have h := (NormedSpace.expSeries_div_hasSum_exp (r*Real.exp s)).mul_left (Real.exp (-r)) + convert! h using 1 + · funext j + rw [mul_pow, ← Real.exp_nat_mul] + unfold poissonWeight + ring_nf + · rw [← Real.exp_eq_exp_ℝ, ← Real.exp_add] + congr 1 + ring + +lemma poisson_head_le {r s : ℝ} (hr : 0 ≤ r) (hs : 0 ≤ s) (k : ℕ) : + (∑ j ∈ Finset.range k, poissonWeight r j) ≤ + Real.exp (s*(k:ℝ)+r*(Real.exp (-s)-1)) := by + have hsum := (poissonWeight_exp_hasSum r (-s)).mul_left (Real.exp (s*k)) + have hle : (∑ j ∈ Finset.range k, poissonWeight r j) ≤ + ∑ j ∈ Finset.range k, Real.exp (s*k)*(poissonWeight r j*Real.exp (-s*j)) := by + apply Finset.sum_le_sum + intro j hj + have hj' : (j:ℝ) ≤ k := by exact_mod_cast (Finset.mem_range.mp hj).le + calc + _ ≤ poissonWeight r j * Real.exp (s*((k:ℝ)-j)) := by + exact le_mul_of_one_le_right (poissonWeight_nonneg hr j) + ((Real.one_le_exp_iff).mpr (mul_nonneg hs (sub_nonneg.mpr hj'))) + _ = _ := by + calc + _ = poissonWeight r j * (Real.exp (s*k)*Real.exp (-s*j)) := by + rw [← Real.exp_add]; congr 2; ring + _ = _ := by ring + apply hle.trans + have ht := Summable.sum_le_tsum (Finset.range k) (fun j _ => by + exact mul_nonneg (Real.exp_pos _).le + (mul_nonneg (poissonWeight_nonneg hr j) (Real.exp_pos _).le)) hsum.summable + rw [hsum.tsum_eq] at ht + simpa only [Real.exp_add] using ht + +lemma continuousKernel_poisson_hasSum {n : ℕ} (hn : 0 < n) + (J : Interaction n) (t : ℝ) (x y : Spin n) : + HasSum (fun j => poissonWeight ((n:ℝ)*t) j * discreteKernel J j x y) + (continuousKernel J t x y) := by + have hs := (Pi.hasSum.mp + (exp_apply_hasSum (((n:ℝ)*t) • attemptLM J) + (fun z => if z = y then 1 else 0)) x).mul_left (Real.exp (-((n:ℝ)*t))) + convert! hs using 1 + · funext j + simp only [smul_pow, _root_.smul_apply, Pi.smul_apply, smul_eq_mul, discreteKernel, poissonWeight] + ring + · rw [continuousKernel, semigroup_uniformization hn] + simp only [_root_.smul_apply, Pi.smul_apply, smul_eq_mul, neg_mul] + +lemma continuousKernel_poisson_integral {n : ℕ} (hn : 0 < n) + (J : Interaction n) (t : ℝ) (ht : 0 ≤ t) (x y : Spin n) : + continuousKernel J t x y = ∫ j, discreteKernel J j x y + ∂poissonMeasure (⟨(n:ℝ)*t, mul_nonneg (Nat.cast_nonneg n) ht⟩ : ℝ≥0) := by + erw [integral_poissonMeasure] + exact (continuousKernel_poisson_hasSum hn J t x y).tsum_eq.symm + +lemma integrable_discreteKernel_poisson {n : ℕ} (J : Interaction n) + (r : ℝ≥0) (x y : Spin n) : Integrable (fun j => discreteKernel J j x y) (poissonMeasure r) := by + apply Integrable.mono' (integrable_const (1 : ℝ)) (.of_discrete) (ae_of_all _ ?_) + intro j + rw [Real.norm_eq_abs, abs_of_nonneg (discreteKernel_nonneg J j x y)] + exact (Finset.single_le_sum (fun z _ => discreteKernel_nonneg J j x z) + (Finset.mem_univ y)).trans_eq (discreteKernel_sum J j x) + +lemma totalVariation_integral_le {n : ℕ} {Ω : Type*} [MeasurableSpace Ω] + (μ : Measure Ω) [IsProbabilityMeasure μ] (p : Ω → Spin n → ℝ) + (q : Spin n → ℝ) (hi : ∀ y, Integrable (fun j => p j y) μ) : + totalVariation (fun y => ∫ j, p j y ∂μ) q ≤ ∫ j, totalVariation (p j) q ∂μ := by + unfold totalVariation + rw [integral_div, integral_finsetSum] + swap + · intro y _ + exact ((hi y).sub (integrable_const (q y))).abs + gcongr with y + have he : (∫ j, p j y ∂μ)-q y = ∫ j, (p j y-q y) ∂μ := by + rw [integral_sub (hi y) (integrable_const _)] + simp + rw [he] + exact abs_integral_le_integral_abs + +lemma integrable_totalVariation_poisson {n : ℕ} (J : Interaction n) + (r : ℝ≥0) (x : Spin n) : + Integrable (fun j => totalVariation (discreteKernel J j x) (gibbs J)) (poissonMeasure r) := by + unfold totalVariation + apply Integrable.div_const + apply integrable_finsetSum + intro y _ + exact ((integrable_discreteKernel_poisson J r x y).sub (integrable_const _)).abs + +lemma poisson_head_integral (r : ℝ≥0) (k : ℕ) : + (∫ j : ℕ, (if j < k then (1:ℝ) else 0) ∂poissonMeasure r) = + ∑ j ∈ Finset.range k, poissonWeight r j := by + erw [integral_poissonMeasure] + simp only [smul_eq_mul, mul_ite, mul_one, mul_zero] + rw [tsum_eq_sum (s := Finset.range k) (fun j hj => by + simp only [Finset.mem_range, not_lt] at hj + simp only [not_lt.mpr hj, ite_false])] + apply Finset.sum_congr rfl + intro j hj + rw [ite_eq_left (Finset.mem_range.mp hj)] + rfl + +lemma continuous_le_poisson_head_add_discrete {n : ℕ} (hn : 0 < n) + (J : Interaction n) (t : ℝ) (ht : 0 ≤ t) (k : ℕ) : + worstContinuous J t ≤ (∑ j ∈ Finset.range k, poissonWeight ((n:ℝ)*t) j) + + worstDiscrete J k := by + let r : ℝ≥0 := ⟨(n:ℝ)*t,mul_nonneg (Nat.cast_nonneg n) ht⟩ + apply Finset.sup'_le + intro x _ + change totalVariation (continuousKernel J t x) (gibbs J) ≤ _ + have he : continuousKernel J t x = fun y => ∫ j, discreteKernel J j x y ∂poissonMeasure r := by + funext y + exact continuousKernel_poisson_integral hn J t ht x y + rw [he] + apply (totalVariation_integral_le _ _ _ (integrable_discreteKernel_poisson J r x)).trans + have hbi : Integrable (fun j : ℕ => if j < k then (1:ℝ) else 0) (poissonMeasure r) := by + apply Integrable.mono' (integrable_const (1:ℝ)) (.of_discrete) + exact ae_of_all _ (fun j => by split_ifs <;> norm_num) + calc + _ ≤ ∫ j : ℕ, (if j < k then (1:ℝ) else 0)+worstDiscrete J k ∂poissonMeasure r := by + apply integral_mono (integrable_totalVariation_poisson J r x) + (hbi.add (integrable_const _)) + intro j + change totalVariation (discreteKernel J j x) (gibbs J) ≤ + (if j < k then (1:ℝ) else 0)+worstDiscrete J k + by_cases hj : j < k + · simp only [ite_eq_left hj] + have hb := totalVariation_le_one _ _ (discreteKernel_nonneg J j x) + (fun y => (gibbs_pos J y).le) (discreteKernel_sum J j x) (gibbs_sum J) + linarith [worstDiscrete_nonneg J k] + · simp only [ite_eq_right hj, zero_add] + apply (Finset.le_sup' (fun x => totalVariation (discreteKernel J j x) (gibbs J)) + (Finset.mem_univ x)).trans + exact worstDiscrete_antitone J (not_lt.mp hj) + _ = _ := by + rw [integral_add hbi (integrable_const _), poisson_head_integral] + have hu : (poissonMeasure r).real Set.univ = 1 := by + simp [Measure.real, measure_univ] + simp only [integral_const, smul_eq_mul, hu, one_mul] + rfl + +lemma exists_poisson_head_exponent {a : ℝ} (_ha : 0 ≤ a) (ha1 : a < 1) : + ∃ s c : ℝ, 0 < s ∧ 0 < c ∧ s*a+Real.exp (-s)-1 = -c := by + let s := (1-a)/2 + have hs : 0 < s := by dsimp [s]; linarith + have he : Real.exp (-s) ≤ (1+s)⁻¹ := by + rw [Real.exp_neg] + simp only [← one_div] + apply one_div_le_one_div_of_le (by linarith : 0 < 1+s) + linarith [Real.add_one_le_exp s] + have ha' : a*(1+s) < 1 := by + have hm := mul_le_mul_of_nonneg_right ha1.le hs.le + dsimp [s] at * + nlinarith + have hh : s*a+(1+s)⁻¹-1 < 0 := by + have hpos : 0 < 1+s := by linarith + have hid : (s*a+(1+s)⁻¹-1)*(1+s) = s*(a*(1+s)-1) := by + field_simp + ring + have hp := mul_neg_of_pos_of_neg hs (sub_neg.mpr ha') + rw [← hid] at hp + nlinarith + refine ⟨s, -(s*a+Real.exp (-s)-1),hs,?_,by ring⟩ + linarith + +lemma poisson_head_tendsto_zero {r : ℕ → ℝ} {k : ℕ → ℕ} {a : ℝ} + (hr : Tendsto r atTop atTop) (ha : 0 ≤ a) (ha1 : a < 1) + (hkr : ∀ᶠ n in atTop, 0 ≤ r n ∧ (k n : ℝ) ≤ a*r n) : + Tendsto (fun n => ∑ j ∈ Finset.range (k n), poissonWeight (r n) j) atTop (𝓝 0) := by + obtain ⟨s,c,hs,hc,he⟩ := exists_poisson_head_exponent ha ha1 + have hh : Tendsto (fun n => Real.exp (-c*r n)) atTop (𝓝 0) := by + simpa only [Function.comp_def, neg_mul] using + Real.tendsto_exp_neg_atTop_nhds_zero.comp (hr.const_mul_atTop hc) + apply tendsto_const_nhds.squeeze' hh + · filter_upwards [hkr] with n hn + exact Finset.sum_nonneg (fun j _ => poissonWeight_nonneg hn.1 j) + · filter_upwards [hkr] with n hn + apply (poisson_head_le hn.1 hs.le (k n)).trans + apply Real.exp_le_exp.mpr + calc + s*(k n:ℝ)+r n*(Real.exp (-s)-1) ≤ s*(a*r n)+r n*(Real.exp (-s)-1) := by + gcongr + exact hn.2 + _ = (s*a+Real.exp (-s)-1)*r n := by ring + _ = -c*r n := by rw [he] + +lemma disorderLimit_one_of_clock_transfer {β : ℝ} + {F G : (n : ℕ) → Interaction n → ℝ} {e : ℕ → ℝ} + (hF : DisorderLimit β F 1) (he : Tendsto e atTop (𝓝 0)) + (hcomp : ∀ᶠ n in atTop, ∀ J, G n J ≤ 1 ∧ F n J ≤ e n+G n J) : + DisorderLimit β G 1 := by + intro δ hδ + apply tendsto_const_nhds.squeeze' (hF (δ/2) (by positivity)) + (Eventually.of_forall (fun _ => zero_le)) + filter_upwards [hcomp, he.eventually (gt_mem_nhds (by linarith : 0 < δ/2))] with n hn hen + apply measure_mono + intro g hg + obtain ⟨hG,hFG⟩ := hn (sampledInteraction g) + change δ < |G n (sampledInteraction g)-1| at hg + rw [abs_of_nonpos (sub_nonpos.mpr hG)] at hg + have hh := neg_le_abs (F n (sampledInteraction g)-1) + change δ/2 < |F n (sampledInteraction g)-1| + linarith + +lemma cutoffTime_tendsto_atTop {rate : ℝ} (hrate : 0 < rate) : + Tendsto (cutoffTime rate) atTop atTop := by + change Tendsto (fun n : ℕ => Real.log (n:ℝ)/(2*rate)) atTop atTop + have hlog : Tendsto (fun n : ℕ => Real.log (n:ℝ)) atTop atTop := + Real.tendsto_log_atTop.comp tendsto_natCast_atTop_atTop + simpa only [div_eq_mul_inv] using hlog.atTop_mul_const + (inv_pos.mpr (by positivity : 0 < 2*rate)) + +theorem discrete_lower_from_continuous {β rate ε : ℝ} (hrate : 0 < rate) + (hε : 0 < ε) (hε1 : ε < 1) + (hcont : DisorderLimit β + (fun n J => worstContinuous J ((1-ε/2)*cutoffTime rate n)) 1) : + DisorderLimit β (fun n J => worstDiscrete J + ⌊(1-ε)*(n:ℝ)*cutoffTime rate n⌋₊) 1 := by + let r : ℕ → ℝ := fun n => (n:ℝ)*((1-ε/2)*cutoffTime rate n) + let k : ℕ → ℕ := fun n => ⌊(1-ε)*(n:ℝ)*cutoffTime rate n⌋₊ + let a : ℝ := (1-ε)/(1-ε/2) + have hmid : 0 < 1-ε/2 := by linarith + have ha : 0 ≤ a := div_nonneg (by linarith) hmid.le + have ha1 : a < 1 := by + apply (div_lt_one hmid).mpr + linarith + have hr : Tendsto r atTop atTop := + (tendsto_natCast_atTop_atTop : Tendsto (fun n : ℕ => (n:ℝ)) atTop atTop).atTop_mul_atTop₀ + ((cutoffTime_tendsto_atTop hrate).const_mul_atTop hmid) + have hkr : ∀ᶠ n in atTop, 0 ≤ r n ∧ (k n:ℝ) ≤ a*r n := by + filter_upwards [eventually_ge_atTop 1] with n hn + have ht := cutoffTime_nonneg hn hrate + constructor + · exact mul_nonneg (Nat.cast_nonneg _) (mul_nonneg hmid.le ht) + · apply (Nat.floor_le (mul_nonneg (mul_nonneg (by linarith) (Nat.cast_nonneg _)) ht)).trans + dsimp [a,r] + apply le_of_eq + have hne : (2-ε) ≠ 0 := by linarith + field_simp [hne] + apply disorderLimit_one_of_clock_transfer hcont (poisson_head_tendsto_zero hr ha ha1 hkr) + filter_upwards [eventually_ge_atTop 1] with n hn + intro J + exact ⟨worstDiscrete_le_one J _, continuous_le_poisson_head_add_discrete hn J _ + (mul_nonneg hmid.le (cutoffTime_nonneg hn hrate)) _⟩ + +end SKGapCutoff + +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators + +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/PositiveRamp.lean b/lean/OAI/Probability/SKGap/Localization/PositiveRamp.lean new file mode 100644 index 0000000000000000000000000000000000000000..7a0dba13fd4b50d35e92b9e6dc8621aac27b7ff5 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/PositiveRamp.lean @@ -0,0 +1,291 @@ +import Mathlib +import OAI.Probability.SKGap.Entropy.ExponentiallyRare + +namespace OAI + +section +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open scoped BigOperators +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open scoped BigOperators +open scoped BigOperators NNReal ENNReal +open MeasureTheory Metric Set +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators NNReal ENNReal Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Set +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators ENNReal NNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Matrix +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators ENNReal NNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal +open scoped BigOperators +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise NNReal ENNReal +open scoped BigOperators +open Filter Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +namespace SKGapCutoff.Regression + +noncomputable def positiveRamp (k : ℕ) (x : ℝ) : ℝ := min 1 (max 0 ((k:ℝ)*x)) +noncomputable def positiveIndicator (x : ℝ) : ℝ := if 0 < x then 1 else 0 +noncomputable def boundaryRamp (k : ℕ) (x : ℝ) : ℝ := + 1-positiveRamp k x-positiveRamp k (-x) + +lemma positiveRamp_bounds (k : ℕ) (x : ℝ) : + 0 ≤ positiveRamp k x ∧ positiveRamp k x ≤ 1 := + ⟨le_min (by norm_num) (le_max_left _ _), min_le_left _ _⟩ + +lemma positiveRamp_eq_zero {x : ℝ} (hx : x ≤ 0) (k : ℕ) : + positiveRamp k x = 0 := by + simp [positiveRamp, max_eq_left (mul_nonpos_of_nonneg_of_nonpos (Nat.cast_nonneg _) hx)] + +lemma positiveRamp_lipschitz (k : ℕ) : LipschitzWith (k:ℝ≥0) (positiveRamp k) := by + have hs : LipschitzWith (k:ℝ≥0) (fun x : ℝ => (k:ℝ)*x) := by + apply LipschitzWith.of_dist_le_mul + intro x y + rw [Real.dist_eq, ← mul_sub, abs_mul, abs_of_nonneg (Nat.cast_nonneg k : (0:ℝ)≤k)] + rfl + exact (hs.const_max 0).const_min 1 + +lemma positiveIndicator_measurable : Measurable positiveIndicator := by + exact Measurable.ite (measurableSet_lt measurable_const measurable_id) + measurable_const measurable_const + +lemma positiveIndicator_bounds (x : ℝ) : 0 ≤ positiveIndicator x ∧ positiveIndicator x ≤ 1 := by + unfold positiveIndicator + split_ifs <;> norm_num + +lemma boundaryRamp_bounds (k : ℕ) (x : ℝ) : + 0 ≤ boundaryRamp k x ∧ boundaryRamp k x ≤ 1 := by + have hp := positiveRamp_bounds k x + have hn := positiveRamp_bounds k (-x) + unfold boundaryRamp + by_cases hx : 0 ≤ x + · rw [positiveRamp_eq_zero (neg_nonpos.mpr hx)] + constructor <;> linarith + · rw [positiveRamp_eq_zero (le_of_lt (lt_of_not_ge hx))] + constructor <;> linarith + +lemma positiveRamp_error (k : ℕ) (x : ℝ) : + |positiveIndicator x-positiveRamp k x| ≤ boundaryRamp k x := by + unfold positiveIndicator + split_ifs with hx + · rw [boundaryRamp, positiveRamp_eq_zero (neg_nonpos.mpr hx.le), sub_zero, + abs_of_nonneg (sub_nonneg.mpr (positiveRamp_bounds k x).2)] + · rw [positiveRamp_eq_zero (le_of_not_gt hx)] + simpa using (boundaryRamp_bounds k x).1 + +lemma positiveRamp_tendsto (x : ℝ) : + Tendsto (fun k => positiveRamp k x) atTop (𝓝 (positiveIndicator x)) := by + by_cases hx : 0 < x + · apply tendsto_const_nhds.congr' + filter_upwards [eventually_ge_atTop ⌈1/x⌉₊] with k hk + have hkx : 1/x ≤ (k:ℝ) := (Nat.le_ceil _).trans (by exact_mod_cast hk) + have hkx' : 1 ≤ (k:ℝ)*x := (div_le_iff₀ hx).mp hkx + simp only [positiveRamp, positiveIndicator, ite_eq_left hx] + exact (min_eq_left (le_max_of_le_right hkx')).symm + · simpa only [positiveIndicator, ite_eq_right hx, positiveRamp_eq_zero (le_of_not_gt hx)] using + (tendsto_const_nhds : Tendsto (fun _k : ℕ => (0:ℝ)) atTop (𝓝 0)) + +lemma boundaryRamp_tendsto {x : ℝ} (hx : x ≠ 0) : + Tendsto (fun k => boundaryRamp k x) atTop (𝓝 0) := by + have hh := ((tendsto_const_nhds : Tendsto (fun _k : ℕ => (1:ℝ)) atTop (𝓝 1)).sub + (positiveRamp_tendsto x)).sub (positiveRamp_tendsto (-x)) + have he : 1-positiveIndicator x-positiveIndicator (-x) = 0 := by + rcases lt_or_gt_of_ne hx with h | h + · simp [positiveIndicator, not_lt.mpr h.le, neg_pos.mpr h] + · simp [positiveIndicator, h, not_lt.mpr (neg_nonpos.mpr h.le)] + simpa only [he, boundaryRamp] using hh + +lemma boundaryRamp_lipschitz (k : ℕ) : + LipschitzWith (2*(k:ℝ≥0)) (boundaryRamp k) := by + have hn : LipschitzWith (k:ℝ≥0) (fun x : ℝ => positiveRamp k (-x)) := by + have hid : LipschitzWith 1 (fun x : ℝ => x) := LipschitzWith.id + simpa only [mul_one, Function.comp_def, Pi.neg_apply] using + (positiveRamp_lipschitz k).comp hid.neg + apply LipschitzWith.of_dist_le_mul + intro x y + have hp := (positiveRamp_lipschitz k).dist_le_mul x y + have hq := hn.dist_le_mul x y + rw [Real.dist_eq] at hp hq ⊢ + have he : boundaryRamp k x-boundaryRamp k y = + -(positiveRamp k x-positiveRamp k y)-(positiveRamp k (-x)-positiveRamp k (-y)) := by + unfold boundaryRamp + ring + rw [he] + calc + _ ≤ |-(positiveRamp k x-positiveRamp k y)|+ + |positiveRamp k (-x)-positiveRamp k (-y)| := abs_sub _ _ + _ ≤ (2*(k:ℝ≥0):ℝ)*dist x y := by + rw [abs_neg] + push_cast at hp hq ⊢ + linarith + +lemma boundaryRamp_integral_tendsto + {E : Type*} [MeasurableSpace E] {ν : Measure E} [IsProbabilityMeasure ν] + (g : E → ℝ) (hg : Measurable g) (hz : ν {x | g x = 0} = 0) : + Tendsto (fun k => ∫ x, boundaryRamp k (g x) ∂ν) atTop (𝓝 0) := by + have hne : ∀ᵐ x ∂ν, g x ≠ 0 := by + rw [ae_iff] + simpa only [not_not] using hz + have ht : Tendsto (fun k => ∫ x, boundaryRamp k (g x) ∂ν) + atTop (𝓝 (∫ _x : E, (0:ℝ) ∂ν)) := by + apply tendsto_integral_of_dominated_convergence (fun _ => (1:ℝ)) + · intro k + exact ((boundaryRamp_lipschitz k).continuous.measurable.comp hg).aestronglyMeasurable + · exact integrable_const _ + · intro k + filter_upwards [] with x + rw [Real.norm_eq_abs, abs_of_nonneg (boundaryRamp_bounds k (g x)).1] + exact (boundaryRamp_bounds k (g x)).2 + · filter_upwards [hne] with x hx + exact boundaryRamp_tendsto hx + simpa using ht + +lemma positiveRamp_mul_integral_tendsto + {E : Type*} [MeasurableSpace E] {ν : Measure E} [IsProbabilityMeasure ν] + (f g : E → ℝ) (hf : Measurable f) (hg : Measurable g) + (B : ℝ) (hB : ∀ x, |f x| ≤ B) : + Tendsto (fun k => ∫ x, f x*positiveRamp k (g x) ∂ν) atTop + (𝓝 (∫ x, f x*positiveIndicator (g x) ∂ν)) := by + apply tendsto_integral_of_dominated_convergence (fun _ => B) + · intro k + exact (hf.mul ((positiveRamp_lipschitz k).continuous.measurable.comp hg)).aestronglyMeasurable + · exact integrable_const _ + · intro k + filter_upwards [] with x + rw [Real.norm_eq_abs, abs_mul, abs_of_nonneg (positiveRamp_bounds k (g x)).1] + exact (mul_le_mul_of_nonneg_left (positiveRamp_bounds k (g x)).2 (abs_nonneg _)).trans + (by simpa using hB x) + · filter_upwards [] with x + exact tendsto_const_nhds.mul (positiveRamp_tendsto (g x)) + +theorem ExponentialEmpiricalConcentration.threshold_average + {E : Type*} [PseudoMetricSpace E] [MeasurableSpace E] [BorelSpace E] + {H : ℕ → Type*} [∀ n, MeasurableSpace (H n)] + {ρ : ∀ n, Measure (H n)} {X : ∀ n, H n → Fin n → E} + {ν : Measure E} [IsProbabilityMeasure ν] + (hX : ExponentialEmpiricalConcentration ρ X ν) + (f g : E → ℝ) {K L B : ℝ≥0} + (hf : LipschitzWith K f) (hg : LipschitzWith L g) + (hB : ∀ x, |f x| ≤ B) (hz : ν {x | g x = 0} = 0) : + ExponentialConvergence ρ + (fun n h => (∑ i, f (X n h i)*positiveIndicator (g (X n h i)))/(n:ℝ)) + (∫ x, f x*positiveIndicator (g x) ∂ν) := by + intro ε hε + let D : ℝ := B+1 + have hD : 0 < D := by dsimp [D]; positivity + let δ := ε/(6*D) + have hδ : 0 < δ := by dsimp [δ]; positivity + have hδeq : D*δ = ε/6 := by dsimp [δ]; field_simp + have hbias : ∀ᶠ k : ℕ in atTop, + |(∫ x, f x*positiveRamp k (g x) ∂ν) - + ∫ x, f x*positiveIndicator (g x) ∂ν| < ε/3 := by + simpa only [Real.dist_eq] using (Metric.tendsto_nhds.mp + (positiveRamp_mul_integral_tendsto f g hf.continuous.measurable + hg.continuous.measurable B hB)) (ε/3) (by positivity) + have hboundary : ∀ᶠ k : ℕ in atTop, |∫ x, boundaryRamp k (g x) ∂ν| < δ := by + simpa only [Real.dist_eq, sub_zero] using (Metric.tendsto_nhds.mp + (boundaryRamp_integral_tendsto g hg.continuous.measurable hz)) δ hδ + obtain ⟨k,hbias,hboundary⟩ := (hbias.and hboundary).exists + have hramp : LipschitzWith ((k:ℝ≥0)*L) (fun x => positiveRamp k (g x)) := + (positiveRamp_lipschitz k).comp hg + have hbramp : ∀ x, |positiveRamp k (g x)| ≤ (1:ℝ≥0) := by + intro x + rw [abs_of_nonneg (positiveRamp_bounds k (g x)).1] + exact (positiveRamp_bounds k (g x)).2 + have hsmooth := hX.average (fun x => f x*positiveRamp k (g x)) + (bounded_product_lipschitz hf hramp hB hbramp) B (fun x => by + rw [abs_mul] + exact (mul_le_mul (hB x) (hbramp x) (abs_nonneg _) B.coe_nonneg).trans (by simp)) + have hb := hX.average (fun x => boundaryRamp k (g x)) + ((boundaryRamp_lipschitz k).comp hg) 1 (fun x => by + rw [abs_of_nonneg (boundaryRamp_bounds k (g x)).1] + exact (boundaryRamp_bounds k (g x)).2) + apply ((hsmooth (ε/3) (by positivity)).union (hb δ hδ)).mono + refine Filter.Eventually.of_forall ?_ + intro n h hh + change ε ≤ |(∑ i, f (X n h i)*positiveIndicator (g (X n h i)))/(n:ℝ) - + ∫ x, f x*positiveIndicator (g x) ∂ν| at hh + by_cases hs : ε/3 ≤ dist + ((∑ i, f (X n h i)*positiveRamp k (g (X n h i)))/(n:ℝ)) + (∫ x, f x*positiveRamp k (g x) ∂ν) + · exact Or.inl hs + apply Or.inr + by_contra hb' + have hsmall : (∑ i, boundaryRamp k (g (X n h i)))/(n:ℝ) < 2*δ := by + have hh' : |(∑ i, boundaryRamp k (g (X n h i)))/(n:ℝ) - + ∫ x, boundaryRamp k (g x) ∂ν| < δ := lt_of_not_ge hb' + have hi := le_abs_self (∫ x, boundaryRamp k (g x) ∂ν) + have ha := le_abs_self ((∑ i, boundaryRamp k (g (X n h i)))/(n:ℝ) - + ∫ x, boundaryRamp k (g x) ∂ν) + linarith + have herror : |(∑ i, f (X n h i)*positiveIndicator (g (X n h i)))/(n:ℝ) - + (∑ i, f (X n h i)*positiveRamp k (g (X n h i)))/(n:ℝ)| ≤ + D*((∑ i, boundaryRamp k (g (X n h i)))/(n:ℝ)) := by + rw [← sub_div, abs_div, abs_of_nonneg (Nat.cast_nonneg n : (0:ℝ) ≤ n), + ← Finset.sum_sub_distrib, ← mul_div_assoc, Finset.mul_sum] + apply div_le_div_of_nonneg_right _ (Nat.cast_nonneg _) + refine (Finset.abs_sum_le_sum_abs _ _).trans (Finset.sum_le_sum ?_) + intro i _ + rw [← mul_sub, abs_mul] + apply mul_le_mul ((hB _).trans (by dsimp [D]; linarith)) + (positiveRamp_error k _) (abs_nonneg _) hD.le + have htriangle := abs_add_three + ((∑ i, f (X n h i)*positiveIndicator (g (X n h i)))/(n:ℝ) - + (∑ i, f (X n h i)*positiveRamp k (g (X n h i)))/(n:ℝ)) + ((∑ i, f (X n h i)*positiveRamp k (g (X n h i)))/(n:ℝ) - + ∫ x, f x*positiveRamp k (g x) ∂ν) + ((∫ x, f x*positiveRamp k (g x) ∂ν) - ∫ x, f x*positiveIndicator (g x) ∂ν) + rw [sub_add_sub_cancel, sub_add_sub_cancel] at htriangle + have hs' : |(∑ i, f (X n h i)*positiveRamp k (g (X n h i)))/(n:ℝ) - + ∫ x, f x*positiveRamp k (g x) ∂ν| < ε/3 := lt_of_not_ge hs + have herror' : D*((∑ i, boundaryRamp k (g (X n h i)))/(n:ℝ)) < ε/3 := by + nlinarith + linarith + +end SKGapCutoff.Regression + +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology + +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/Prediction.lean b/lean/OAI/Probability/SKGap/Localization/Prediction.lean new file mode 100644 index 0000000000000000000000000000000000000000..b663acf5a5908f3a26930e18ad4a983026a66428 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/Prediction.lean @@ -0,0 +1,83 @@ +import Mathlib +import OAI.Probability.SKGap.Matrix.PolynomialCoeListSum + +namespace OAI + +section +noncomputable section +noncomputable section +open scoped BigOperators +noncomputable section +noncomputable section +noncomputable section +open scoped BigOperators +noncomputable section +open scoped BigOperators +noncomputable section +open scoped BigOperators +noncomputable section +open scoped BigOperators +noncomputable section +open scoped BigOperators +noncomputable section +open scoped BigOperators +noncomputable section +open scoped BigOperators +noncomputable section +open scoped BigOperators +noncomputable section +open scoped BigOperators +noncomputable section +open scoped BigOperators +noncomputable section +open scoped BigOperators +noncomputable section +open scoped BigOperators +noncomputable section +open scoped BigOperators +noncomputable section +open scoped BigOperators +namespace SKGap.Noncrossing +open PowerSeries +variable {ι : Type*} [Fintype ι] + +theorem literalSeries_coeff_eq_zero (j : ℝ) (a : ι→ℝ) (F : List (WordLetter ι)) + (hI : inverseCount F≤1) (i : ι) (n : ℕ) (hn : ordinaryCount F (hd s).differentiableAt).continuous + have hpos (s : ℝ) (hs : 0 ≤ s) : 0 ≤ F' s := by + apply mul_nonneg (Real.exp_pos _).le + apply refreshSemigroup_nonneg m (fun x i => (hm x i).le) s hs + intro y + exact refreshRoughDefect_nonneg m hm _ y A R (hA y _) (hR y) + have hm : MonotoneOn F (Set.Icc 0 t) := + monotoneOn_of_hasDerivWithinAt_nonneg (convex_Icc 0 t) hc.continuousOn + (fun s _ => (hd s).hasDerivWithinAt) + (fun s hs => hpos s ((interior_subset hs).1)) + have hv := hm (show (0 : ℝ) ∈ Set.Icc 0 t from ⟨le_rfl, ht⟩) + (show t ∈ Set.Icc (0 : ℝ) t from ⟨ht, le_rfl⟩) ht + simpa only [F, mul_zero, Real.exp_zero, refreshSemigroup_zero, sub_zero, sub_self, + refreshGradientSemigroup, zero_smul, NormedSpace.exp_zero, one_apply_eq_self, one_mul, C] using hv + +lemma refreshField_flip {n : ℕ} (H : VectorFields n) (x : Spin n) (i j : Fin n) : + H (flip x i) j = H x j - 2*spin x i*halfDiff i (fun y => H y j) x := by + have h := flip_sub i (fun y => H y j) x + linarith + +lemma refreshField_abs_change {n : ℕ} (H : VectorFields n) (x : Spin n) (i j : Fin n) : + |H x j-H (flip x i) j| = 2*|halfDiff i (fun y => H y j) x| := by + rw [refreshField_flip H x i j] + ring_nf + simp [abs_mul, abs_spin_eq_one, mul_comm] + +lemma refreshInfluence_error_le {n : ℕ} (H : VectorFields n) (x : Spin n) (i j : Fin n) : + |refreshInfluence (fun y k => Real.tanh (H y k)) x i j - + halfDiff i (fun y => H y j) x*scalarVariance (H x j)| ≤ + 4*(halfDiff i (fun y => H y j) x)^2 := by + have hr := tanh_linear_remainder (H x j) (H (flip x i) j) + have he : refreshInfluence (fun y k => Real.tanh (H y k)) x i j - + halfDiff i (fun y => H y j) x*scalarVariance (H x j) = + -(spin x i/2)*(Real.tanh (H (flip x i) j)-Real.tanh (H x j)- + scalarVariance (H x j)*(H (flip x i) j-H x j)) := by + simp only [refreshInfluence, halfDiff_as_flip] + ring + rw [he, abs_mul, abs_neg, abs_div, abs_spin_eq_one] + norm_num only [abs_of_pos (show (0:ℝ)<2 by norm_num)] + have ha : |H (flip x i) j-H x j| = 2*|halfDiff i (fun y => H y j) x| := by + rw [abs_sub_comm, refreshField_abs_change] + rw [ha] at hr + nlinarith [sq_abs (halfDiff i (fun y => H y j) x)] + +lemma refreshInfluence_variance_le {n : ℕ} (H : VectorFields n) (x : Spin n) (i j : Fin n) : + |refreshInfluence (fun y k => Real.tanh (H y k)) x i j| ≤ + |halfDiff i (fun y => H y j) x| *Real.exp (4*|halfDiff i (fun y => H y j) x|)*scalarVariance (H x j) := by + have h := tanh_difference_variance_le (H (flip x i) j) (H x j) + rw [refreshField_abs_change] at h + rw [refreshInfluence, halfDiff_as_flip, abs_div, abs_mul, abs_spin_eq_one, one_mul] + norm_num only [abs_of_pos (show (0:ℝ)<2 by norm_num)] + have he : 2*(2*|halfDiff i (fun y => H y j) x|) = 4*|halfDiff i (fun y => H y j) x| := by ring + rw [he] at h + linarith + +lemma refreshVariance_sq_le_jumpWeight {n : ℕ} (H : VectorFields n) (x : Spin n) (j : Fin n) : + scalarVariance (H x j)^2 ≤ 2*refreshJumpWeight (fun y k => Real.tanh (H y k)) x j := by + have hv := scalarVariance_pos (H x j) + have hv1 := scalarVariance_le_one (H x j) + have hw := refreshJumpWeight_pos (fun y k => Real.tanh (H y k)) (fun y k => Real.abs_tanh_lt_one _) x j + have hm : Real.tanh (H x j)*spin x j ≤ 1 := by + have ha : |Real.tanh (H x j)*spin x j| < 1 := by + simpa only [abs_mul, abs_spin_eq_one, mul_one] using Real.abs_tanh_lt_one (H x j) + exact (le_abs_self _).trans ha.le + have he : scalarVariance (H x j) = + refreshJumpWeight (fun y k => Real.tanh (H y k)) x j*(1+Real.tanh (H x j)*spin x j) := by + unfold scalarVariance refreshJumpWeight + have hs := spin_sq x j + nlinarith + have h2 := mul_le_mul_of_nonneg_left (show 1+Real.tanh (H x j)*spin x j ≤ 2 by linarith) hw.le + rw [← he] at h2 + nlinarith + +open RandomMatrix + +lemma matrix_row_sq_le {n : ℕ} (J : Interaction n) (i : Fin n) : + ∑ j, J i j^2 ≤ ‖Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) J‖^2 := by + have hs : Matrix.transpose J = star J := rfl + have hn : ‖Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) (Matrix.transpose J)‖ = + ‖Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) J‖ := by + rw [hs, map_star] + exact ContinuousLinearMap.adjoint.norm_map _ + simpa only [Matrix.transpose_apply, hn] using matrix_column_sq_le (Matrix.transpose J) i + +lemma refreshInfluence_weighted_entry_le {n : ℕ} (H : VectorFields n) (x : Spin n) (i j : Fin n) + (c : ℝ) (hc : |halfDiff i (fun y => H y j) x| ≤ c) : + refreshInfluence (fun y k => Real.tanh (H y k)) x i j ^ 2 / refreshJumpWeight (fun y k => Real.tanh (H y k)) x j ≤ 2 * Real.exp (8*c) * (halfDiff i (fun y => H y j) x)^2 := by + have h := refreshInfluence_variance_le H x i j + have h' : |refreshInfluence (fun y k => Real.tanh (H y k)) x i j| ≤ |halfDiff i (fun y => H y j) x| * Real.exp (4*c) * scalarVariance (H x j) := by + apply h.trans + apply mul_le_mul_of_nonneg_right _ (scalarVariance_pos (H x j)).le + apply mul_le_mul_of_nonneg_left _ (abs_nonneg _) + exact Real.exp_le_exp.mpr (mul_le_mul_of_nonneg_left hc (by norm_num)) + have hs := sq_le_sq₀ (abs_nonneg (refreshInfluence (fun y k => Real.tanh (H y k)) x i j)) + (mul_nonneg (mul_nonneg (abs_nonneg _) (Real.exp_pos _).le) (scalarVariance_pos (H x j)).le) |>.mpr h' + simp only [sq_abs, mul_pow] at hs + have hv := mul_le_mul_of_nonneg_left (refreshVariance_sq_le_jumpWeight H x j) + (mul_nonneg (sq_nonneg (halfDiff i (fun y => H y j) x)) (sq_nonneg (Real.exp (4*c)))) + have he : Real.exp (4*c)^2 = Real.exp (8*c) := by rw [← Real.exp_nat_mul]; congr 1; ring + rw [he] at hs hv + apply (div_le_iff₀ (refreshJumpWeight_pos (fun y k => Real.tanh (H y k)) (fun y k => Real.abs_tanh_lt_one _) x j)).mpr + nlinarith + +lemma refreshInfluence_weighted_row_le {n : ℕ} (H : VectorFields n) (x : Spin n) + (c M : ℝ) (hc : ∀ i j, |halfDiff j (fun y => H y i) x| ≤ c) (hM : ∀ i, ∑ j, (halfDiff i (fun y => H y j) x)^2 ≤ M) (i : Fin n) : + ∑ j, refreshInfluence (fun y k => Real.tanh (H y k)) x i j ^ 2 / refreshJumpWeight (fun y k => Real.tanh (H y k)) x j ≤ 2 * Real.exp (8*c) * M := by + calc + _ ≤ ∑ j, 2 * Real.exp (8*c) * (halfDiff i (fun y => H y j) x)^2 := + Finset.sum_le_sum (fun j _ => refreshInfluence_weighted_entry_le H x i j c (hc j i)) + _ = 2 * Real.exp (8*c) * ∑ j, (halfDiff i (fun y => H y j) x)^2 := by rw [Finset.mul_sum] + _ ≤ _ := mul_le_mul_of_nonneg_left (hM i) (by positivity) + +lemma refreshInfluence_error_quadratic_le {n : ℕ} (H : VectorFields n) + (x : Spin n) (u : Fin n → ℝ) (M : ℝ) (hM : ∀ i, ∑ j, (halfDiff i (fun y => H y j) x)^2 ≤ M) + (hMc : ∀ j, ∑ i, (halfDiff i (fun y => H y j) x)^2 ≤ M) : + |∑ i, ∑ j, u i * (refreshInfluence (fun y k => Real.tanh (H y k)) x i j - halfDiff i (fun y => H y j) x * scalarVariance (H x j)) * u j| ≤ + 4 * M * ∑ i, u i ^ 2 := by + have he (i j : Fin n) : + |u i * (refreshInfluence (fun y k => Real.tanh (H y k)) x i j - halfDiff i (fun y => H y j) x * scalarVariance (H x j)) * u j| ≤ + 2 * (halfDiff i (fun y => H y j) x)^2 * (u i ^ 2 + u j ^ 2) := by + rw [abs_mul, abs_mul] + have hm := mul_le_mul_of_nonneg_right + (mul_le_mul_of_nonneg_left (refreshInfluence_error_le H x i j) (abs_nonneg (u i))) + (abs_nonneg (u j)) + have hs : 2 * |u i| * |u j| ≤ u i ^ 2 + u j ^ 2 := by + nlinarith [sq_nonneg (|u i|-|u j|), sq_abs (u i), sq_abs (u j)] + have hh := mul_le_mul_of_nonneg_left hs (show 0 ≤ 2 * (halfDiff i (fun y => H y j) x)^2 by positivity) + nlinarith + have ha : |∑ i, ∑ j, u i * (refreshInfluence (fun y k => Real.tanh (H y k)) x i j - halfDiff i (fun y => H y j) x * scalarVariance (H x j)) * u j| ≤ + ∑ i, ∑ j, 2 * (halfDiff i (fun y => H y j) x)^2 * (u i ^ 2 + u j ^ 2) := by + exact (Finset.abs_sum_le_sum_abs _ _).trans (Finset.sum_le_sum (fun i _ => + (Finset.abs_sum_le_sum_abs _ _).trans (Finset.sum_le_sum (fun j _ => he i j)))) + have hr : (∑ i, ∑ j, (halfDiff i (fun y => H y j) x)^2 * u i ^ 2) ≤ M * ∑ i, u i ^ 2 := by + calc + _ = ∑ i, (∑ j, (halfDiff i (fun y => H y j) x)^2) * u i ^ 2 := by simp_rw [Finset.sum_mul] + _ ≤ ∑ i, M * u i ^ 2 := Finset.sum_le_sum (fun i _ => + mul_le_mul_of_nonneg_right (hM i) (sq_nonneg _)) + _ = _ := (Finset.mul_sum _ _ _).symm + have hc : (∑ i, ∑ j, (halfDiff i (fun y => H y j) x)^2 * u j ^ 2) ≤ M * ∑ i, u i ^ 2 := by + calc + _ = ∑ j, (∑ i, (halfDiff i (fun y => H y j) x)^2) * u j^2 := by + rw [Finset.sum_comm]; simp_rw [Finset.sum_mul] + _ ≤ ∑ j, M * u j^2 := Finset.sum_le_sum (fun j _ => + mul_le_mul_of_nonneg_right (hMc j) (sq_nonneg _)) + _ = _ := (Finset.mul_sum _ _ _).symm + have hs : (∑ i, ∑ j, 2 * (halfDiff i (fun y => H y j) x)^2 * (u i ^ 2 + u j ^ 2)) = + 2 * (∑ i, ∑ j, (halfDiff i (fun y => H y j) x)^2 * u i ^ 2) + + 2 * (∑ i, ∑ j, (halfDiff i (fun y => H y j) x)^2 * u j ^ 2) := by + simp_rw [mul_add, mul_assoc, Finset.sum_add_distrib, ← Finset.mul_sum] + rw [hs] at ha + linarith + +lemma refreshInfluence_quadratic_le {n : ℕ} (H : VectorFields n) + (x : Spin n) (u : Fin n → ℝ) (B M : ℝ) (hB : 0 ≤ B) + (hJB : ∀ a b : Fin n → ℝ, |∑ i, ∑ j, a i * halfDiff i (fun y => H y j) x * b j| ≤ + B / 2 * ((∑ i, a i ^ 2) + ∑ j, b j ^ 2)) + (hM : ∀ i, ∑ j, (halfDiff i (fun y => H y j) x)^2 ≤ M) + (hMc : ∀ j, ∑ i, (halfDiff i (fun y => H y j) x)^2 ≤ M) : + ∑ i, u i * (∑ j, refreshInfluence (fun y k => Real.tanh (H y k)) x i j * u j) ≤ (B + 4*M) * ∑ i, u i ^ 2 := by + have hv : (∑ j, (scalarVariance (H x j) * u j)^2) ≤ ∑ j, u j ^ 2 := by + apply Finset.sum_le_sum + intro j _ + have hp := scalarVariance_pos (H x j) + have h1 := scalarVariance_le_one (H x j) + have hv : scalarVariance (H x j) ^ 2 ≤ 1 := by nlinarith + simpa only [mul_pow, one_mul] using mul_le_mul_of_nonneg_right hv (sq_nonneg (u j)) + have hb := hJB u (fun j => scalarVariance (H x j) * u j) + have hb' : (∑ i, ∑ j, u i * halfDiff i (fun y => H y j) x * (scalarVariance (H x j) * u j)) ≤ B * ∑ i, u i ^ 2 := by + have hmul := mul_le_mul_of_nonneg_left hv (show 0 ≤ B/2 by positivity) + linarith [le_abs_self (∑ i, ∑ j, u i * halfDiff i (fun y => H y j) x * (scalarVariance (H x j) * u j))] + have he := refreshInfluence_error_quadratic_le H x u M hM hMc + have hs : (∑ i, u i * (∑ j, refreshInfluence (fun y k => Real.tanh (H y k)) x i j * u j)) = + (∑ i, ∑ j, u i * halfDiff i (fun y => H y j) x * (scalarVariance (H x j) * u j)) + + (∑ i, ∑ j, u i * (refreshInfluence (fun y k => Real.tanh (H y k)) x i j - halfDiff i (fun y => H y j) x * scalarVariance (H x j)) * u j) := by + simp_rw [Finset.mul_sum] + rw [← Finset.sum_add_distrib] + apply Finset.sum_congr rfl + intro i _ + rw [← Finset.sum_add_distrib] + apply Finset.sum_congr rfl + intro j _ + ring + rw [hs] + have hh := le_abs_self (∑ i, ∑ j, u i * (refreshInfluence (fun y k => Real.tanh (H y k)) x i j - halfDiff i (fun y => H y j) x * scalarVariance (H x j)) * u j) + nlinarith + +lemma refreshRough_of_field_opNorm {n : ℕ} (H : VectorFields n) (C : ℝ) (hC : 0 ≤ C) + (hHC : ∀ x, ‖Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) + (fun j i => halfDiff i (fun y => H y j) x)‖ ≤ C) + (p : VectorFields n) (t : ℝ) (ht : 0 ≤ t) (x : Spin n) : + vectorSquare (refreshGradientSemigroup (fun y k => Real.tanh (H y k)) t p) x ≤ + Real.exp ((2*(C+4*C^2)+4*(2*Real.exp (8*C)*C^2)-2)*t) * + refreshSemigroup (fun y k => Real.tanh (H y k)) t (vectorSquare p) x := by + let K (x : Spin n) : Interaction n := fun j i => halfDiff i (fun y => H y j) x + have hr (x : Spin n) (i : Fin n) : ∑ j, K x j i^2 ≤ C^2 := by + exact (matrix_column_sq_le (K x) i).trans (pow_le_pow_left₀ (norm_nonneg _) (hHC x) 2) + have hc (x : Spin n) (j : Fin n) : ∑ i, K x j i^2 ≤ C^2 := by + exact (matrix_row_sq_le (K x) j).trans (pow_le_pow_left₀ (norm_nonneg _) (hHC x) 2) + apply refreshRough_vector_propagation _ (fun y k => Real.abs_tanh_lt_one _) + (C+4*C^2) (2*Real.exp (8*C)*C^2) _ _ p t ht x + · intro y q + apply refreshInfluence_quadratic_le H y q C (C^2) hC _ (hr y) (hc y) + intro a b + exact (matrix_bilinear_le (K y) a b).trans + (mul_le_mul_of_nonneg_right (div_le_div_of_nonneg_right (hHC y) (by norm_num)) + (by positivity)) + · intro y i + apply refreshInfluence_weighted_row_le H y C (C^2) _ (hr y) i + intro j k + exact (matrix_entry_le_opNorm (K y) j k).trans (hHC y) + +lemma refreshGradient_of_field_opNorm {n : ℕ} (H : VectorFields n) (C : ℝ) (hC : 0 ≤ C) + (hHC : ∀ x, ‖Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) + (fun j i => halfDiff i (fun y => H y j) x)‖ ≤ C) + (f : Observables n) (t : ℝ) (ht : 0 ≤ t) (x : Spin n) : + (∑ i, (halfDiff i (refreshSemigroup (fun y k => Real.tanh (H y k)) t f) x)^2) ≤ + Real.exp ((2*(C+4*C^2)+4*(2*Real.exp (8*C)*C^2)-2)*t) * + refreshSemigroup (fun y k => Real.tanh (H y k)) t + (fun y => ∑ i, (halfDiff i f y)^2) x := by + have h := refreshRough_of_field_opNorm H C hC hHC (fun y i => halfDiff i f y) t ht x + dsimp only [vectorSquare] at h + simp_rw [← refreshHalfDiff_semigroup] at h + exact h + +lemma refreshSemigroup_mono {n : ℕ} (m : VectorFields n) + (hm : ∀ x i, |m x i| ≤ 1) (t : ℝ) (ht : 0 ≤ t) + {f g : Observables n} (hfg : ∀ x, f x ≤ g x) (x : Spin n) : + refreshSemigroup m t f x ≤ refreshSemigroup m t g x := by + have h := refreshSemigroup_nonneg m hm t ht (g-f) (fun x => sub_nonneg.mpr (hfg x)) x + simpa only [map_sub, Pi.sub_apply, sub_nonneg] using h + +lemma refreshSemigroup_add {n : ℕ} (m : VectorFields n) (s t : ℝ) : + refreshSemigroup m (s+t) = refreshSemigroup m s*refreshSemigroup m t := by + let : NormedAlgebra ℚ (Observables n →L[ℝ] Observables n) := + NormedAlgebra.restrictScalars ℚ ℝ _ + unfold refreshSemigroup + rw [add_smul, NormedSpace.exp_add_of_commute + (((Commute.refl (refreshGeneratorCLM m)).smul_left s).smul_right t)] + +lemma refreshJumpEnergy_le_gradient {n : ℕ} (m : VectorFields n) + (hm : ∀ x i, |m x i| ≤ 1) (f : Observables n) (x : Spin n) : + refreshJumpEnergy m f x ≤ 4*∑ i, (halfDiff i f x)^2 := by + unfold refreshJumpEnergy + calc + _ ≤ 2*∑ i, 2*(halfDiff i f x)^2 := by + apply mul_le_mul_of_nonneg_left (Finset.sum_le_sum _) (by norm_num) + intro i _ + exact mul_le_mul_of_nonneg_right (refreshJumpWeight_le_two m hm x i) (sq_nonneg _) + _ = _ := by rw [← Finset.mul_sum]; ring + +lemma exp_growth_integral (C t : ℝ) (hC : C ≠ 0) : + (∫ s in (0:ℝ)..t, Real.exp (C*(t-s))) = (Real.exp (C*t)-1)/C := by + have hd (s : ℝ) : HasDerivAt (fun s => -Real.exp (C*(t-s))/C) + (Real.exp (C*(t-s))) s := by + convert! (((Real.hasDerivAt_exp (C*(t-s))).comp s + ((hasDerivAt_const s t).sub (hasDerivAt_id s) |>.const_mul C)).neg.div_const C) using 1 + simp [hC] + have he := intervalIntegral.integral_eq_sub_of_hasDerivAt (fun s _ => hd s) + ((show Continuous (fun s : ℝ => Real.exp (C*(t-s))) by fun_prop).intervalIntegrable 0 t) + rw [he]; simp only [sub_self, mul_zero, Real.exp_zero, sub_zero]; ring + +lemma refreshVariance_from_gradient {n : ℕ} (m : VectorFields n) + (hm : ∀ x i, |m x i| ≤ 1) (C : ℝ) (hC : C ≠ 0) + (hgrad : ∀ f : Observables n, ∀ t : ℝ, 0 ≤ t → ∀ x, + (∑ i, (halfDiff i (refreshSemigroup m t f) x)^2) ≤ + Real.exp (C*t)*refreshSemigroup m t (fun y => ∑ i, (halfDiff i f y)^2) x) + (f : Observables n) (t : ℝ) (ht : 0 ≤ t) (x : Spin n) : + refreshSemigroup m t (fun y => f y^2) x - (refreshSemigroup m t f x)^2 ≤ + 4*((Real.exp (C*t)-1)/C)*refreshSemigroup m t (fun y => ∑ i, (halfDiff i f y)^2) x := by + rw [refreshSemigroup_variance_integral] + let E := refreshSemigroup m t (fun y => ∑ i, (halfDiff i f y)^2) x + calc + _ ≤ ∫ s in (0:ℝ)..t, (4*Real.exp (C*(t-s)))*E := by + apply intervalIntegral.integral_mono_on ht + ((refreshInterpolated_energy_continuous m f t x).intervalIntegrable 0 t) + ((show Continuous (fun s : ℝ => (4*Real.exp (C*(t-s)))*E) by fun_prop).intervalIntegrable 0 t) + intro s hs + have hb : ∀ y, refreshJumpEnergy m (refreshSemigroup m (t-s) f) y ≤ + (4*Real.exp (C*(t-s)))*refreshSemigroup m (t-s) (fun z => ∑ i, (halfDiff i f z)^2) y := by + intro y + exact (refreshJumpEnergy_le_gradient m hm _ y).trans (by + have hh := mul_le_mul_of_nonneg_left (hgrad f (t-s) (by linarith [hs.2]) y) (show (0:ℝ) ≤ 4 by norm_num) + simpa only [mul_assoc] using hh) + have hh := refreshSemigroup_mono m hm s hs.1 hb x + have hlin (a : ℝ) (g : Observables n) : + refreshSemigroup m s (fun y => a*g y) x = a*refreshSemigroup m s g x := by + exact congrFun (map_smul (refreshSemigroup m s) a g) x + rw [hlin] at hh + have hc : refreshSemigroup m s (refreshSemigroup m (t-s) + (fun y => ∑ i, (halfDiff i f y)^2)) x = E := by + rw [← mul_apply_eq_comp, ← refreshSemigroup_add, add_sub_cancel] + rwa [hc] at hh + _ = _ := by rw [intervalIntegral.integral_mul_const, intervalIntegral.integral_const_mul, + exp_growth_integral C t hC] + +lemma gibbsVariance_moments {n : ℕ} (J : Interaction n) (f : Observables n) : + gibbsVariance J f = gibbsExpectation J (fun x => f x^2)-(gibbsExpectation J f)^2 := by + have he : (fun x => (f x-gibbsExpectation J f)^2) = + ((fun x => f x^2) - (2*gibbsExpectation J f) • f)+(fun _ => (gibbsExpectation J f)^2) := by + funext x; simp only [Pi.add_apply, Pi.sub_apply, Pi.smul_apply, smul_eq_mul]; ring + unfold gibbsVariance + rw [he] + change expectationCLM J (_+_) = _ + rw [map_add, map_sub, map_smul] + change gibbsExpectation J (fun x => f x^2) - (2*gibbsExpectation J f)*gibbsExpectation J f + + gibbsExpectation J (fun _ => (gibbsExpectation J f)^2) = _ + rw [gibbsExpectation_const] + ring + +lemma gibbsVariance_gradient_le {n : ℕ} (J : Interaction n) (γ : ℝ) + (hγ : 0 < γ) (hg : HasGap J γ) (f : Observables n) : + gibbsVariance J f ≤ γ⁻¹*gibbsExpectation J (fun x => ∑ i, (halfDiff i f x)^2) := by + have hd : dirichlet J f f ≤ gibbsExpectation J (fun x => ∑ i, (halfDiff i f x)^2) := by + apply gibbsExpectation_mono + intro x + apply Finset.sum_le_sum + intro i _ + have h := mul_le_mul_of_nonneg_right (siteVariance_le_one J x i) (sq_nonneg (halfDiff i f x)) + nlinarith only [h] + have hh := mul_le_mul_of_nonneg_left ((hg f).trans hd) (inv_nonneg.mpr hγ.le) + simpa only [← mul_assoc, inv_mul_cancel₀ hγ.ne', one_mul] using hh + +lemma refreshGibbs_poincare_from_gradient {n : ℕ} (J : Interaction n) + (γ : ℝ) (hγ : 0 < γ) (hg : HasGap J γ) + (m : VectorFields n) (hm : ∀ x i, |m x i| ≤ 1) (C : ℝ) (hC : C ≠ 0) + (hgrad : ∀ f : Observables n, ∀ t : ℝ, 0 ≤ t → ∀ x, + (∑ i, (halfDiff i (refreshSemigroup m t f) x)^2) ≤ + Real.exp (C*t)*refreshSemigroup m t (fun y => ∑ i, (halfDiff i f y)^2) x) + (f : Observables n) (t : ℝ) (ht : 0 ≤ t) : + gibbsExpectation J (refreshSemigroup m t (fun y => f y^2)) - + (gibbsExpectation J (refreshSemigroup m t f))^2 ≤ + (γ⁻¹*Real.exp (C*t)+4*((Real.exp (C*t)-1)/C))* + gibbsExpectation J (refreshSemigroup m t (fun y => ∑ i, (halfDiff i f y)^2)) := by + have hcond := gibbsExpectation_mono J _ _ (fun x => + refreshVariance_from_gradient m hm C hC hgrad f t ht x) + rw [gibbsExpectation_sub, gibbsExpectation_mul_const] at hcond + have hinitial := gibbsVariance_gradient_le J γ hγ hg (refreshSemigroup m t f) + have hgr := gibbsExpectation_mono J _ _ (hgrad f t ht) + rw [gibbsExpectation_mul_const] at hgr + have hh := hinitial.trans (mul_le_mul_of_nonneg_left hgr (inv_nonneg.mpr hγ.le)) + rw [gibbsVariance_moments] at hh + nlinarith only [hcond, hh] + +noncomputable def preparationGrowth (C : ℝ) : ℝ := + 2*(C+4*C^2)+8*Real.exp (8*C)*C^2+1 + +lemma preparationGrowth_pos (C : ℝ) (hC : 0 ≤ C) : 0 < preparationGrowth C := by + unfold preparationGrowth; positivity + +lemma refreshGradient_field_bound {n : ℕ} (H : VectorFields n) (C : ℝ) (hC : 0 ≤ C) + (hHC : ∀ x, ‖Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) + (fun j i => halfDiff i (fun y => H y j) x)‖ ≤ C) + (f : Observables n) (t : ℝ) (ht : 0 ≤ t) (x : Spin n) : + (∑ i, (halfDiff i (refreshSemigroup (fun y k => Real.tanh (H y k)) t f) x)^2) ≤ + Real.exp (preparationGrowth C*t)*refreshSemigroup (fun y k => Real.tanh (H y k)) t + (fun y => ∑ i, (halfDiff i f y)^2) x := by + apply (refreshGradient_of_field_opNorm H C hC hHC f t ht x).trans + apply mul_le_mul_of_nonneg_right + · apply Real.exp_le_exp.mpr + apply mul_le_mul_of_nonneg_right _ ht + unfold preparationGrowth + linarith + · exact refreshSemigroup_nonneg _ (fun y k => (Real.abs_tanh_lt_one _).le) t ht _ + (fun y => Finset.sum_nonneg (fun i _ => sq_nonneg _)) x + +theorem preparation_poincare_field {n : ℕ} (J : Interaction n) + (γ : ℝ) (hγ : 0 < γ) (hg : HasGap J γ) + (H : VectorFields n) (C : ℝ) (hC : 0 ≤ C) + (hHC : ∀ x, ‖Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) + (fun j i => halfDiff i (fun y => H y j) x)‖ ≤ C) + (f : Observables n) (t : ℝ) (ht : 0 ≤ t) : + gibbsExpectation J (refreshSemigroup (fun y k => Real.tanh (H y k)) t (fun y => f y^2)) - + (gibbsExpectation J (refreshSemigroup (fun y k => Real.tanh (H y k)) t f))^2 ≤ + (γ⁻¹*Real.exp (preparationGrowth C*t)+4*((Real.exp (preparationGrowth C*t)-1)/preparationGrowth C))* + gibbsExpectation J (refreshSemigroup (fun y k => Real.tanh (H y k)) t + (fun y => ∑ i, (halfDiff i f y)^2)) := by + exact refreshGibbs_poincare_from_gradient J γ hγ hg _ + (fun y k => (Real.abs_tanh_lt_one _).le) (preparationGrowth C) + (preparationGrowth_pos C hC).ne' (refreshGradient_field_bound H C hC hHC) f t ht + +end SKGapCutoff +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/PrimaryDifferentiation.lean b/lean/OAI/Probability/SKGap/Localization/PrimaryDifferentiation.lean new file mode 100644 index 0000000000000000000000000000000000000000..ba7d4b755b0fe0a9417b4f21cae32051a8653ca5 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/PrimaryDifferentiation.lean @@ -0,0 +1,224 @@ +import Mathlib +import OAI.Probability.SKGap.Matrix.PrimaryMatrix +import OAI.Probability.SKGap.Matrix.DiscreteMatrixCalculus + +namespace OAI + +section + +noncomputable section +open scoped BigOperators Matrix.Norms.Frobenius +namespace SKGapCutoff.Primary +open SKGap Matrix +variable {n : ℕ} + +def primaryState (j : ℝ) (J : Interaction n) (h : Fin n→ℝ) : + ℕ → VectorFields n × VectorFields n + | 0 => (spin,fun x i => h i+∑ a,J i a*spin x a) + | k+1 => + let s := primaryState j J h k + let m : VectorFields n := fun x i => Real.tanh (s.2 x i) + let b : Spin n→ℝ := siteMean (fun x i => 1-(m x i)^2) + (m,fun x i => h i+∑ a,J i a*m x a-j*b x*s.1 x i) + +def primaryDiagonal (j : ℝ) (J : Interaction n) (h : Fin n→ℝ) (x : Spin n) : + ℕ→Fin n→ℝ := fun k i => scalarVariance ((primaryState j J h k).2 x i) + +def formalField (j : ℝ) (J : Interaction n) (h : Fin n→ℝ) (x : Spin n) (k : ℕ) : + Interaction n := + SKGap.Noncrossing.Primary.primaryMatrix j J (primaryDiagonal j J h x) (k+1) + +def formalMag (j : ℝ) (J : Interaction n) (h : Fin n→ℝ) (x : Spin n) : ℕ→Interaction n + | 0 => 1 + | k+1 => Matrix.diagonal (primaryDiagonal j J h x k)*formalField j J h x k + +lemma primaryDiagonal_bounded (j : ℝ) (J : Interaction n) (h : Fin n→ℝ) (x : Spin n) : + ∀ k i, |primaryDiagonal j J h x k i|≤1 := by + intro k i + rw [primaryDiagonal,abs_of_pos (scalarVariance_pos _)] + exact scalarVariance_le_one _ + +lemma primaryState_mag_bounded (j : ℝ) (J : Interaction n) (h : Fin n→ℝ) (k : ℕ) + (x : Spin n) (i : Fin n) : |(primaryState j J h k).1 x i|≤1 := by + cases k with + | zero => simp [primaryState,abs_spin_eq_one] + | succ k => exact (Real.abs_tanh_lt_one _).le + +lemma formalMag_previous (j : ℝ) (J : Interaction n) (h : Fin n→ℝ) (x : Spin n) (k : ℕ) : + formalMag j J h x k = + Matrix.diagonal (SKGap.Noncrossing.Primary.previousDiagonal (primaryDiagonal j J h x) k)* + SKGap.Noncrossing.Primary.primaryMatrix j J (primaryDiagonal j J h x) k := by + cases k <;> simp [formalMag,formalField,SKGap.Noncrossing.Primary.previousDiagonal, + SKGap.Noncrossing.Primary.primaryMatrix] + +lemma formalField_succ (j : ℝ) (J : Interaction n) (h : Fin n→ℝ) (x : Spin n) (k : ℕ) : + formalField j J h x (k+1) = J*formalMag j J h x (k+1)- + (j*SKGap.Noncrossing.Diagram.mean (primaryDiagonal j J h x k)) • formalMag j J h x k := by + change SKGap.Noncrossing.Primary.primaryMatrix j J (primaryDiagonal j J h x) (k+2) = + J*(Matrix.diagonal (primaryDiagonal j J h x k)* + SKGap.Noncrossing.Primary.primaryMatrix j J (primaryDiagonal j J h x) (k+1))- + (j*SKGap.Noncrossing.Diagram.mean (primaryDiagonal j J h x k)) • formalMag j J h x k + rw [formalMag_previous,SKGap.Noncrossing.Primary.primaryMatrix,Matrix.mul_assoc] + +def differentiationBound (j R B : ℝ) : ℕ→ℝ + | 0 => B+1 + | k+1 => + let C := differentiationBound j R B k + let T := C+8*C^2 + let Q := 2*T+4*T^2 + B+1+(R*T+|j| *(C+Q+2*C*Q))+T + +lemma differentiationBound_nonneg {j R B : ℝ} (hR : 0≤R) (hB : 0≤B) (k : ℕ) : + 0≤differentiationBound j R B k := by + induction k with + | zero => dsimp [differentiationBound]; positivity + | succ k hk => dsimp only [differentiationBound]; positivity + +lemma onsager_derivative_error {F G : VectorFields n} {x : Spin n} {H P : Interaction n} + (j : ℝ) (J : Interaction n) (h : Fin n→ℝ) {C R : ℝ} (hn : 0 Real.tanh (F y i) + let b : Spin n→ℝ := siteMean (fun y i => 1-(m y i)^2) + let T := C+8*C^2 + let Q := 2*T+4*T^2 + ‖derivativeMatrix (fun y i => h i+∑ a,J i a*m y a-j*b y*G y i) x- + (J*(Matrix.diagonal (fun i => scalarVariance (F x i))*H)-(j*b x) • P)‖ ≤ + R*T+|j| *(C+Q+2*C*Q) := by + let m : VectorFields n := fun y i => Real.tanh (F y i) + let b : Spin n→ℝ := siteMean (fun y i => 1-(m y i)^2) + let T := C+8*C^2 + let Q := 2*T+4*T^2 + change ‖derivativeMatrix (fun y i => h i+∑ a,J i a*m y a-j*b y*G y i) x- + (J*(Matrix.diagonal (fun i => scalarVariance (F x i))*H)-(j*b x) • P)‖≤_ + have hT : 0≤T := by dsimp [T]; positivity + have hQ : 0≤Q := by dsimp [Q]; positivity + have hm : ShapeBound (derivativeMatrix m x) T := tanh_derivative_shape hC hF + have hmE : ‖derivativeMatrix m x-Matrix.diagonal (fun i => scalarVariance (F x i))*H‖≤T := by + convert tanh_derivative_formal_error hC hF hFE using 1 + dsimp [T] + ring + have hbQ : (n:ℝ)*‖derivativeVector b x‖^2≤Q^2 := + siteMean_derivative_square_bound hn (variance_derivative_opNorm hT + (fun i => (Real.abs_tanh_lt_one _).le) hm) + have hp : ‖derivativeMatrix (fun y i => b y*G y i) x-b x • derivativeMatrix G x‖≤Q+2*C*Q := + product_derivative_error hn hQ hG hGb hbQ + have hb : |b x|≤1 := by + let : Nonempty (Fin n) := Fin.pos_iff_nonempty.mp hn + have hv (i : Fin n) : |1-(m x i)^2|≤1 := by + change |scalarVariance (F x i)|≤1 + rw [abs_of_pos (scalarVariance_pos _)] + exact scalarVariance_le_one _ + simpa only [b,siteMean,SKGap.Noncrossing.Diagram.mean,Fintype.card_fin] using + SKGap.Noncrossing.Primary.mean_abs_le_one hv + have hpE : ‖derivativeMatrix (fun y i => b y*G y i) x-b x • P‖≤C+Q+2*C*Q := by + have he : derivativeMatrix (fun y i => b y*G y i) x-b x • P = + (derivativeMatrix (fun y i => b y*G y i) x-b x • derivativeMatrix G x)+ + b x • (derivativeMatrix G x-P) := by module + rw [he] + apply (norm_add_le _ _).trans + have hs : ‖b x • (derivativeMatrix G x-P)‖≤C := by + rw [norm_smul,Real.norm_eq_abs] + exact (mul_le_mul_of_nonneg_right hb (norm_nonneg _)).trans (by simpa using hGE) + have hh := add_le_add hp hs + linarith + have hd : derivativeMatrix (fun y i => h i+∑ a,J i a*m y a-j*b y*G y i) x = + J*derivativeMatrix m x-j • derivativeMatrix (fun y i => b y*G y i) x := by + rw [derivativeMatrix_sub,derivativeMatrix_linear] + congr 1 + convert derivativeMatrix_smul j (fun y i => b y*G y i) x using 1 + congr 1 + funext y i + ring + rw [hd] + have he : J*derivativeMatrix m x-j • derivativeMatrix (fun y i => b y*G y i) x- + (J*(Matrix.diagonal (fun i => scalarVariance (F x i))*H)-(j*b x) • P) = + J*(derivativeMatrix m x-Matrix.diagonal (fun i => scalarVariance (F x i))*H)- + j • (derivativeMatrix (fun y i => b y*G y i) x-b x • P) := by + simp only [mul_sub,smul_sub,mul_smul] + abel + rw [he] + apply (norm_sub_le _ _).trans + apply add_le_add + · exact (SKGap.frobenius_mul_le_opNorm _ _).trans (mul_le_mul hJ hmE (norm_nonneg _) hR) + · rw [norm_smul,Real.norm_eq_abs] + exact mul_le_mul_of_nonneg_left hpE (abs_nonneg _) + +theorem primary_differentiation {j R B : ℝ} (J : Interaction n) (h : Fin n→ℝ) + (x : Spin n) (hn : 0 + have hd : derivativeMatrix (primaryState j J h 0).2 x=J := by + change derivativeMatrix (fun y i => h i+∑ a,J i a*spin y a) x=J + rw [derivativeMatrix_linear,derivativeMatrix_spin,mul_one] + have hm : derivativeMatrix (primaryState j J h 0).1 x=1 := derivativeMatrix_spin x + have hf : formalField j J h x 0=J := rfl + change _≤B+1 ∧ _≤B+1 ∧ _≤B+1 ∧ ShapeBound _ (B+1) + rw [hd,hm,hf,formalMag,sub_self,norm_zero,sub_self,norm_zero] + refine ⟨by positivity,by positivity,(SKGap.opNorm_one_le).trans ?_,?_⟩ + · linarith + · exact (show ShapeBound J B by simpa only [hf] using hformal 0 le_rfl).mono (by linarith) + | succ k ih => + obtain ⟨hFE,hGE,hG,hF⟩ := ih (fun l hl => hformal l (hl.trans (Nat.le_succ _))) + let C := differentiationBound j R B k + let T := C+8*C^2 + let Q := 2*T+4*T^2 + let E := R*T+|j| *(C+Q+2*C*Q) + have hC : 0≤C := differentiationBound_nonneg hR hB k + have hT : 0≤T := by dsimp [T]; positivity + have hQ : 0≤Q := by dsimp [Q]; positivity + have hE : 0≤E := by dsimp [E]; positivity + have hnext : differentiationBound j R B (k+1)=B+1+E+T := rfl + have hFE' : ‖derivativeMatrix (primaryState j J h (k+1)).2 x-formalField j J h x (k+1)‖≤E := by + have hh := onsager_derivative_error (F := (primaryState j J h k).2) + (G := (primaryState j J h k).1) j J h hn hC hR hJ hF hFE hGE hG + (primaryState_mag_bounded j J h k x) + have hb : siteMean (fun y i => 1-(Real.tanh ((primaryState j J h k).2 y i))^2) x = + SKGap.Noncrossing.Diagram.mean (primaryDiagonal j J h x k) := by + simp only [siteMean,SKGap.Noncrossing.Diagram.mean,primaryDiagonal,scalarVariance,Fintype.card_fin] + dsimp only at hh + rw [hb] at hh + rw [formalField_succ] + exact hh + have hGE' : ‖derivativeMatrix (primaryState j J h (k+1)).1 x-formalMag j J h x (k+1)‖≤T := by + have hh := tanh_derivative_formal_error hC hF hFE + change ‖derivativeMatrix (fun y i => Real.tanh ((primaryState j J h k).2 y i)) x- + Matrix.diagonal (fun i => scalarVariance ((primaryState j J h k).2 x i))*formalField j J h x k‖≤T + convert hh using 1 + dsimp [T] + ring + have hG' : SKGap.opNorm (derivativeMatrix (primaryState j J h (k+1)).1 x)≤T := + (tanh_derivative_shape hC hF).1 + have hF' : ShapeBound (derivativeMatrix (primaryState j J h (k+1)).2 x) (B+E) := + (hformal (k+1) le_rfl).perturb hFE' + rw [hnext] + exact ⟨hFE'.trans (by linarith),hGE'.trans (by linarith),hG'.trans (by linarith), + hF'.mono (by linarith)⟩ + +theorem primary_average_differentiation {j R B : ℝ} (J : Interaction n) (h : Fin n→ℝ) + (x : Spin n) (hn : 0 + scalarVariance ((primaryState j J h k).2 y i))) x‖^2≤(2*T+4*T^2)^2 := by + have hC := differentiationBound_nonneg (j:=j) hR hB k + have hF := (primary_differentiation J h x hn hR hB hJ k hformal).2.2.2 + apply siteMean_derivative_square_bound hn + exact variance_derivative_opNorm (by positivity) + (fun i => (Real.abs_tanh_lt_one _).le) (tanh_derivative_shape hC hF) + +end SKGapCutoff.Primary + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/PrimaryFiniteControl.lean b/lean/OAI/Probability/SKGap/Localization/PrimaryFiniteControl.lean new file mode 100644 index 0000000000000000000000000000000000000000..d47d3980a33bc914ab366f42eaedc2eaeba8a77d --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/PrimaryFiniteControl.lean @@ -0,0 +1,49 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.RecipePrimaryMass +import OAI.Probability.SKGap.Localization.PrimaryLocalInput + +namespace OAI + +section + +noncomputable section +open scoped BigOperators +namespace SKGapCutoff.Recipe +open Primary Static SKGap.Noncrossing.Primary SKGap.Noncrossing.Primary.MarkedPolynomial +universe u +variable {Ω : Type u} {n : Ω→ℕ} + +theorem primary_finite_control (j R B : ℝ) (hR : 0≤R) (hB : 0≤B) + (J : ∀a,Interaction (n a)) (h : ∀a,Fin (n a)→ℝ) (M Nmax : ℕ) + (hn : ∀a,0emptyRecipe j (J a) (h a) M) + (emptyRecipe_family j J h M) (fun a x q=>primaryTree j (J a) (h a) x q.val) + c (fun a x=>primary_local_input (J a) (h a) x (hn a) hR hB (hJ a) M (hformal a x)) + Nmax (2*M+1) A W D ((2+|j|)^M) hA hW hD (by positivity) + · intro a x q + have hm:=primaryTree_mass (hn a) j (J a) (h a) x q.val + have hp : (2+|j|)^q.val≤(2+|j|)^M:= + pow_le_pow_right₀ (by linarith [abs_nonneg j]) q.isLt.le + exact ⟨hm.1.trans hp,hm.2.trans hp⟩ + · intro a x q + have ht:=primaryTree_control j (J a) (h a) x q.val hA + exact ⟨ht.1.mono (by omega),ht.2.mono (by omega)⟩ + · exact hw + · exact hd + +end SKGapCutoff.Recipe + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/PrimaryLocalInput.lean b/lean/OAI/Probability/SKGap/Localization/PrimaryLocalInput.lean new file mode 100644 index 0000000000000000000000000000000000000000..0b0eba83d563c681381cc1168d54311140374b24 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/PrimaryLocalInput.lean @@ -0,0 +1,255 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.FiniteRecipeControl + +namespace OAI + +section + +noncomputable section +open scoped BigOperators Matrix.Norms.Frobenius +namespace SKGapCutoff.Primary +open Recipe SKGap.Noncrossing.Primary +variable {n : ℕ} + +def averageBudget (j R B : ℝ) (k : ℕ) : ℝ := + let C:=differentiationBound j R B k + let T:=C+8*C^2 + 2*T+4*T^2 +lemma averageBudget_nonneg {j R B : ℝ} (hR : 0≤R) (hB : 0≤B) (k : ℕ) : + 0≤averageBudget j R B k := by + have hh:=differentiationBound_nonneg (j:=j) hR hB k + unfold averageBudget + positivity + +def localPrimaryBudget (j R B : ℝ) (M : ℕ) : ℝ := + ∑q:Fin M,(differentiationBound j R B q.val+averageBudget j R B q.val) +lemma localPrimaryBudget_nonneg {j R B : ℝ} (hR : 0≤R) (hB : 0≤B) (M : ℕ) : + 0≤localPrimaryBudget j R B M := + Finset.sum_nonneg (fun index _=>add_nonneg + (differentiationBound_nonneg hR hB index.val) (averageBudget_nonneg hR hB index.val)) +lemma localPrimaryBudget_bounds {j R B : ℝ} (hR : 0≤R) (hB : 0≤B) (M : ℕ) (q : Fin M) : + differentiationBound j R B q.val≤localPrimaryBudget j R B M ∧ + averageBudget j R B q.val≤localPrimaryBudget j R B M := by + have hh:=Finset.single_le_sum (s:=Finset.univ) + (fun r (_:r∈Finset.univ)=>add_nonneg (differentiationBound_nonneg (j:=j) hR hB r.val) + (averageBudget_nonneg (j:=j) hR hB r.val)) (Finset.mem_univ q) + have h1:=differentiationBound_nonneg (j:=j) hR hB q.val + have h2:=averageBudget_nonneg (j:=j) hR hB q.val + exact ⟨(le_add_of_nonneg_right h2).trans hh,(le_add_of_nonneg_left h1).trans hh⟩ + +lemma onsager_derivative_bound {j R B : ℝ} (J : Interaction n) (h : Fin n→ℝ) (x : Spin n) + (hn : 0 + have he : onsager j J h 0=0:=funext (onsager_zero j J h) + rw [he] + have hz : derivativeVector (0 : Spin n→ℝ) x=0 := by + ext i; simp [derivativeVector,halfDiff] + rw [hz,norm_zero] + exact localPrimaryBudget_nonneg (j:=j) hR hB M + | succ k=> + have hh:=primary_average_differentiation J h x hn hR hB hJ k (fun l hl=>hformal l (by omega)) + have hh':(n:ℝ)*‖derivativeVector (onsager j J h (k+1)) x‖^2≤(averageBudget j R B k)^2 := by + simpa only [onsager,mag,primaryState,scalarVariance,averageBudget] using hh + exact (derivative_norm_of_mean_square hn (averageBudget_nonneg hR hB k) hh').trans + (localPrimaryBudget_bounds hR hB M ⟨k,by omega⟩).2 + +lemma derivativeVector_mul_sub (c : ℝ) (f g : Spin n→ℝ) (x : Spin n) : + derivativeVector (fun y=>c*(f y-g y)) x=c • (derivativeVector f x-derivativeVector g x) := by + ext i + simp only [derivativeVector,WithLp.ofLp_toLp,PiLp.smul_apply,PiLp.sub_apply] + simp only [halfDiff] + ring + +theorem primary_local_input {j R B : ℝ} (J : Interaction n) (h : Fin n→ℝ) (x : Spin n) + (hn : 0primaryTree j J h x q.val) x 0 + ⟨1,1,C,R,C,(M:ℝ)*(|j| *(C+C)),0,le_rfl,zero_le_one,le_rfl, + localPrimaryBudget_nonneg hR hB M,hR,localPrimaryBudget_nonneg hR hB M, + by positivity [localPrimaryBudget_nonneg (j:=j) hR hB M],le_rfl⟩ := by + dsimp only + have hC:=localPrimaryBudget_nonneg (j:=j) hR hB M + have hb:=localPrimaryBudget_bounds (j:=j) hR hB M + have hd (q : Fin M):=primary_differentiation J h x hn hR hB hJ q.val + (fun l hl=>hformal l (by omega)) + apply emptyRecipe_local j J h M _ x hC hR hC _ hn hJ + · intro q; exact (hd q).2.2.2.mono (hb q).1 + · intro q; rw [(primaryTree_matrices j J h x q.val).2] + exact (hd q).1.trans (hb q).1 + · intro q; rw [(primaryTree_matrices j J h x q.val).1] + exact (hd q).2.1.trans (hb q).1 + · intro q; exact (hd q).2.2.1.trans (hb q).1 + · calc + _ ≤ ∑q:Fin M,|j| *(localPrimaryBudget j R B M+localPrimaryBudget j R B M) := by + apply Finset.sum_le_sum; intro q _ + rw [derivativeVector_mul_sub,norm_smul,Real.norm_eq_abs] + apply mul_le_mul_of_nonneg_left _ (abs_nonneg _) + exact (norm_sub_le _ _).trans (add_le_add + (onsager_derivative_bound J h x hn hR hB hJ M hformal (by omega)) + (onsager_derivative_bound J h x hn hR hB hJ M hformal (by omega))) + _ = _ := by simp + +end SKGapCutoff.Primary + +end +end + +section + +noncomputable section +open scoped BigOperators +namespace SKGapCutoff.Recipe +open Primary Static +universe u +variable {Ω : Type u} {n : Ω→ℕ} {M Nmax : ℕ} {A j : ℝ} +variable {J : ∀a,Interaction (n a)} {h : ∀a,Fin (n a)→ℝ} + +lemma FiniteRecipeControl.onsager_multiplier (H : FiniteRecipeControl j J h M Nmax A) (k : ℕ) (hk : k≤M) : + UniformMultiplier (fun a x=>j*onsager j (J a) (h a) k x) := by + have hh : UniformMultiplier (fun a x=>∑q∈Finset.range k, + j*(onsager j (J a) (h a) (q+1) x-onsager j (J a) (h a) q x)) := by + apply UniformMultiplier.finset_sum + intro q hq + exact H.parameter ⟨q,(Finset.mem_range.mp hq).trans_le hk⟩ + exact hh.congr (fun a x=>onsager_telescope j (J a) (h a) k x) + +lemma uniform_normalized_pair (P : ∀a,Observables (n a)) (hP : ∀a x,0≤P a x) + (hn : ∀a,0∑i,R a x i*(V a x i/Real.sqrt (n a:ℝ)))) + {C : ℝ} (hC : 0≤C) (hU : ∀a x,SmallBound (U a) x C) : + UniformWeak P (fun a x=>siteMean (U a) x*(∑i,R a x i*V a x i)) := by + exact (hV.mul hP (UniformMultiplier.normedMean hn U hC hU)).congr + (fun a x=>normalized_pair_cancel (hn a) (R a) (V a) (siteMean (U a)) x) + +lemma uniform_prev_zero (P : ∀a,Observables (n a)) (U : ∀a,VectorFields (n a)) : + UniformWeak P (fun a x=>∑i,previousResidual j (J a) (h a) 0 x i*U a x i) := by + convert UniformWeak.zero P using 1 + ext a x + simp [previousResidual] + +end SKGapCutoff.Recipe + +end +end + +section + +noncomputable section +open scoped BigOperators +namespace SKGapCutoff.Recipe +open Primary Static +universe u +variable {Ω : Type u} {n : Ω→ℕ} {M Nmax : ℕ} {A j : ℝ} +variable {J : ∀a,Interaction (n a)} {h : ∀a,Fin (n a)→ℝ} +variable {P : ∀a,Observables (n a)} + +def RecipeResidualRule (j : ℝ) (J : ∀a,Interaction (n a)) (h : ∀a,Fin (n a)→ℝ) + (P : ∀a,Observables (n a)) (M Nmax p : ℕ) (B : ℝ) : Prop := + ∀ {σ : Type} [Fintype σ] (D : ∀a,OrdinaryData (n a) (Fin M) (Fin M) σ) (N : ℕ), + FamilyRecipe j J h D N p B → N+2*p≤Nmax → + UniformWeak P (fun a x=>∑i,residual j (J a) (h a) p x i*(D a).source N x i) + +lemma residual_rule_base (C : FiniteRecipeControl j J h M Nmax A) + (hP : ∀a x,0≤P a x) (hp : ∀a,∑x,P a x=1) + (hm : ∀a x i,conditionalMean (P a) x i=mag j (J a) (h a) 1 x i) + (B : ℝ) (hB : B≤A) : RecipeResidualRule j J h P M Nmax 0 B := by + intro σ inst D N H hN + obtain ⟨K,hK,hbound⟩:=C.small D N 0 B H (by omega) hB + have hh:=UniformWeak.base P hP hp (fun a=>(D a).source N) hK hK + (fun a x=>(hbound a x).2.2) (fun a x=>(hbound a x).1.size) + apply hh.congr + intro a x + simp only [Primary.residual,mag_zero,hm] + +lemma residual_rule_step (C : FiniteRecipeControl j J h M Nmax A) + (hP : ∀a x,0≤P a x) (hn : ∀a,0(D a).appendStein N l m l + have HE : FamilyRecipe j J h E (N+1) k (b k) := by + have HH:=(H.mono (show k≤k+1 by omega) le_rfl le_rfl).appendStein l m l le_rfl + (show k ≤ m.val by dsimp [m]; omega) + (R:=|j|) (fun a x=>by rw [H.parameter a l]; exact onsager_parameter_bound j (J a) (h a) k x) + exact HH.mono le_rfl le_rfl hstep + have hEN : N+1+2*k≤Nmax := by omega + have source : UniformWeak P (fun a x=>∑i,residual j (J a) (h a) k x i*(E a).source (N+1) x i) := + ih k (by omega) E (N+1) HE hEN + have aux : UniformWeak P (fun a x=>∑i,residual j (J a) (h a) k x i*(E a).auxiliary (N+1) x i) := by + have HH:=ih k (by omega) (fun a=>(E a).appendAuxiliary (N+1)) (N+1+1) + HE.appendAuxiliary (by omega) + exact HH.congr (fun a x=>by rw [OrdinaryData.appendAuxiliary_source]) + have param := source.mul hP (C.parameter l) + have prev : UniformWeak P (fun a x=>∑i,previousResidual j (J a) (h a) k x i*(E a).source (N+1) x i) := by + cases k with + | zero=>exact uniform_prev_zero P (fun a=>(E a).source (N+1)) + | succ r=> + have HH:=ih r (by omega) E (N+1) (HE.mono (by omega) le_rfl (hmono (by omega))) (by omega) + exact HH.congr (fun a x=>by simp only [previousResidual,Primary.residual,Nat.add_sub_cancel]) + have old:=prev.mul hP (C.onsager_multiplier k (by omega)) + have earlier : UniformWeak P (fun a x=>j*(∑t:Fin (N+1),siteMean ((E a).auxCoefficient (N+1) t) x* + (∑i,residual j (J a) (h a) k x i*(E a).source t.val x i))) := by + apply UniformWeak.smul hP _ j + apply UniformWeak.sum + intro t + exact (ih k (by omega) E t.val (HE.mono le_rfl t.isLt.le le_rfl) (by omega)).mul hP + (C.means E (N+1) k (b k) HE (by omega) hkA t) + obtain ⟨V,hV,hbound⟩:=C.small E (N+1) k (b k) HE (by omega) hkA + have primary (q : Fin M) (hr : k≤q.val) : + UniformWeak P (fun a x=>∑i,residual j (J a) (h a) k x i* + (mag j (J a) (h a) (q.val+1) x i/Real.sqrt (n a:ℝ))) := by + have HQ:=(HE.normalizedPrimary hn q k hr).mono le_rfl le_rfl hk2 + have HH:=ih k (by omega) (fun a=>(E a).normalizedPrimary q) 0 HQ (by omega) + exact HH.congr (fun a x=>by rw [OrdinaryData.normalizedPrimary_magnetization _ _ j (J a) (h a) q.val (HE.primary a q)]) + have future : UniformWeak P (fun a x=>j*(∑q:{q:Fin M//q≠l},siteMean ((E a).sourcePartial (N+1) q) x* + (∑i,residual j (J a) (h a) k x i*mag j (J a) (h a) q.val.val x i))) := by + apply UniformWeak.smul hP _ j + apply UniformWeak.sum + intro q + by_cases hq : q.val.valresidual j (J a) (h a) k) + (fun a=>(E a).sourcePartial (N+1) q.val) (fun a=>mag j (J a) (h a) (r.val+1)) + (primary r (by dsimp [r]; omega)) hV (fun a x=>(hbound a x).2.1 q.val) + simpa only [hr] using HH + have last : UniformWeak P (fun a x=>j*(siteMean ((E a).sourcePartial (N+1) l) x* + (∑i,residual j (J a) (h a) k x i*mag j (J a) (h a) (k+1) x i))) := by + apply UniformWeak.smul hP _ j + exact uniform_normalized_pair P hP hn (fun a=>residual j (J a) (h a) k) + (fun a=>(E a).sourcePartial (N+1) l) (fun a=>mag j (J a) (h a) (k+1)) + (primary l le_rfl) hV (fun a x=>(hbound a x).2.1 l) + apply ((((aux.add param).sub old).add earlier).add future).sub last |>.congr + intro a x + have hid:=(D a).residual_step N l m l hlm (hn a) j (J a) (hJ a) (h a) k Fin.val + (H.coupling a) (H.interaction a) (H.predecessor a) rfl (H.primary a l) (H.primary a m) + (H.parameter a l) ((H.admissible a).sourcePartial N le_rfl l (by dsimp [l]; omega)) x + dsimp only at hid + rw [hid] + dsimp only [E,l] + ring + +end SKGapCutoff.Recipe + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/PrimaryPrediction.lean b/lean/OAI/Probability/SKGap/Localization/PrimaryPrediction.lean new file mode 100644 index 0000000000000000000000000000000000000000..886e4663461286ff7b41cd5cedf7b37f985b0eb5 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/PrimaryPrediction.lean @@ -0,0 +1,411 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.Append + +namespace OAI + +section + +noncomputable section +open scoped BigOperators +namespace SKGap.Noncrossing.Primary +open Diagram + +inductive Partial (D : Type*) where + | done : Diagram D → Partial D + | more : Diagram D → Partial D → Partial D + deriving DecidableEq +namespace Partial +variable {D : Type*} +def word : Partial D → List (Letter D) + | .done d => d.word + | .more d p => d.word ++ (.noise :: p.word) +def head : Partial D → Diagram D + | .done d => d + | .more d _ => d +def diag (a : D) : Partial D → Partial D + | .done d => .done (.diag a d) + | .more d p => .more (.diag a d) p +def create (p : Partial D) : Partial D := .more .nil p +def contract : Partial D → Option (Partial D) + | .done _ => none + | .more d (.done e) => some (.done (.arch d e)) + | .more d (.more e p) => some (.more (.arch d e) p) +def noise (p : Partial D) : List (Partial D) := create p :: (contract p).toList + +@[simp] lemma word_diag (a : D) (p : Partial D) : (p.diag a).word = .diag a :: p.word := by + cases p <;> rfl +@[simp] lemma word_create (p : Partial D) : p.create.word = .noise :: p.word := rfl +lemma word_contract (p q : Partial D) (h : p.contract=some q) : q.word = .noise :: p.word := by + cases p with + | done d => simp [contract] at h + | more d p => cases p <;> simp only [contract,Option.some.injEq] at h <;> subst q <;> + simp [word,Diagram.word,List.append_assoc] +lemma diag_injective (a : D) : Function.Injective (diag a : Partial D → Partial D) := by + intro p q h; cases p <;> cases q <;> simp_all [diag] +lemma create_injective : Function.Injective (create : Partial D → Partial D) := by + intro p q h; exact Partial.more.inj h |>.2 +lemma contract_injective {p q r : Partial D} (hp : p.contract=some r) (hq : q.contract=some r) : p=q := by + cases p with + | done d => simp [contract] at hp + | more d p => + cases q with + | done e => simp [contract] at hq + | more e q => + cases p <;> cases q <;> simp only [contract,Option.some.injEq] at hp hq <;> + subst r <;> simp_all +lemma create_ne_contract (p q r : Partial D) (h : q.contract=some r) : p.create≠r := by + cases q with + | done d => simp [contract] at h + | more d q => cases q <;> simp only [contract,Option.some.injEq] at h <;> subst r <;> simp [create] + +lemma diag_preimage (a : D) (F : List (Letter D)) (p : Partial D) + (h : p.word = .diag a :: F) : ∃ q : Partial D, q.word=F ∧ p=q.diag a := by + cases p with + | done d => cases d <;> simp only [word,Diagram.word] at h + case diag b d => simp only [List.cons.injEq,Letter.diag.injEq] at h + obtain ⟨rfl,h⟩ := h; exact ⟨.done d,h,rfl⟩ + all_goals simp at h + | more d p => + cases d with + | nil => simp [word,Diagram.word] at h + | arch d e => simp [word,Diagram.word] at h + | diag b d => + simp only [word,Diagram.word,List.cons_append,List.cons.injEq,Letter.diag.injEq] at h + obtain ⟨rfl,h⟩ := h; exact ⟨.more d p,h,rfl⟩ +lemma noise_preimage (F : List (Letter D)) (p : Partial D) + (h : p.word = .noise :: F) : + ∃ q : Partial D, q.word=F ∧ (p=q.create ∨ q.contract=some p) := by + cases p with + | done d => + cases d with + | nil => simp [word,Diagram.word] at h + | diag a d => simp [word,Diagram.word] at h + | arch d e => + simp only [word,Diagram.word,List.cons.injEq,true_and] at h + exact ⟨.more d (.done e),h,Or.inr rfl⟩ + | more d p => + cases d with + | nil => + simp only [word,Diagram.word,List.nil_append,List.cons.injEq,true_and] at h + exact ⟨p,h,Or.inl rfl⟩ + | diag a d => simp [word,Diagram.word] at h + | arch d e => + simp only [word,Diagram.word,List.cons_append,List.cons.injEq,true_and,List.append_assoc] at h + exact ⟨.more d (.more e p),h,Or.inr rfl⟩ + +def enumerate : List (Letter D) → List (Partial D) + | [] => [.done .nil] + | .diag a :: F => (enumerate F).map (diag a) + | .noise :: F => (enumerate F).flatMap noise + +@[simp] lemma mem_enumerate (F : List (Letter D)) (p : Partial D) : + p∈enumerate F ↔ p.word=F := by + induction F generalizing p with + | nil => + cases p with + | done d => cases d <;> simp [enumerate,word,Diagram.word] + | more d p => simp [enumerate,word] + | cons a F ih => + cases a with + | diag a => + simp only [enumerate,List.mem_map,ih] + constructor + · rintro ⟨q,hq,rfl⟩; simp [hq] + · intro hp; obtain ⟨q,hq,hp⟩ := diag_preimage a F p hp; exact ⟨q,hq,hp.symm⟩ + | noise => + simp only [enumerate,List.mem_flatMap,noise,List.mem_cons,Option.mem_toList,ih] + constructor + · rintro ⟨q,hq,hp|hp⟩ + · subst p; simp [hq] + · rw [word_contract q p hp,hq] + · intro hp; obtain ⟨q,hq,hp⟩ := noise_preimage F p hp; exact ⟨q,hq,hp⟩ + +lemma noise_nodup (p : Partial D) : p.noise.Nodup := by + cases p with + | done d => simp [noise,contract] + | more d p => cases p <;> simp [noise,contract,create] +lemma noise_disjoint {p q : Partial D} (h : p≠q) : List.Disjoint p.noise q.noise := by + apply List.disjoint_left.mpr + intro r hr hq + simp only [noise,List.mem_cons,Option.mem_toList] at hr hq + rcases hr with hr|hr <;> rcases hq with hq|hq + · exact h (create_injective (hr.symm.trans hq)) + · exact create_ne_contract p q r hq hr.symm + · exact create_ne_contract q p r hr hq.symm + · exact h (contract_injective hr hq) +lemma enumerate_nodup (F : List (Letter D)) : (enumerate F).Nodup := by + induction F with + | nil => simp [enumerate] + | cons a F ih => + cases a with + | diag a => exact ih.map (diag_injective a) + | noise => + rw [enumerate,List.nodup_flatMap] + exact ⟨fun p _ => noise_nodup p, List.Pairwise.imp (fun h => noise_disjoint h) ih⟩ +end Partial + +section Fock +variable {ι : Type*} [Fintype ι] +abbrev D := ι → ℝ +abbrev Stack := D (ι:=ι) × List (D (ι:=ι)) +abbrev Space := Stack (ι:=ι) →₀ ℝ + +def ket (s : Stack (ι:=ι)) : Space (ι:=ι) := Finsupp.single s 1 + +def diagonal (a : D (ι:=ι)) : Space (ι:=ι) →ₗ[ℝ] Space (ι:=ι) := + Finsupp.linearCombination ℝ (fun s => ket (a*s.1,s.2)) +def creation : Space (ι:=ι) →ₗ[ℝ] Space (ι:=ι) := + Finsupp.linearCombination ℝ (fun s => ket (1,s.1::s.2)) +def annihilation : Space (ι:=ι) →ₗ[ℝ] Space (ι:=ι) := + Finsupp.linearCombination ℝ (fun s => match s.2 with + | [] => 0 + | a::L => Diagram.mean s.1 • ket (a,L)) +def noise (j : ℝ) : Space (ι:=ι) →ₗ[ℝ] Space (ι:=ι) := creation + j • annihilation + +def vacuum : Space (ι:=ι) := ket (1,[]) +def project : Space (ι:=ι) →ₗ[ℝ] D (ι:=ι) := + Finsupp.linearCombination ℝ (fun s => if s.2=[] then s.1 else 0) + +omit [Fintype ι] in +@[simp] lemma diagonal_ket (a : D (ι:=ι)) (s : Stack (ι:=ι)) : + diagonal a (ket s)=ket (a*s.1,s.2) := by simp [diagonal,ket] +omit [Fintype ι] in +@[simp] lemma creation_ket (s : Stack (ι:=ι)) : + creation (ket s)=ket (1,s.1::s.2) := by simp [creation,ket] +@[simp] lemma annihilation_ket_nil (a : D (ι:=ι)) : + annihilation (ket (a,[]))=0 := by simp [annihilation,ket] +@[simp] lemma annihilation_ket_cons (a b : D (ι:=ι)) (L : List (D (ι:=ι))) : + annihilation (ket (a,b::L))=Diagram.mean a • ket (b,L) := by simp [annihilation,ket] +omit [Fintype ι] in +@[simp] lemma project_ket_nil (a : D (ι:=ι)) : project (ket (a,[])) = a := by + simp [project,ket] +omit [Fintype ι] in +@[simp] lemma project_ket_cons (a b : D (ι:=ι)) (L : List (D (ι:=ι))) : + project (ket (a,b::L)) = 0 := by simp [project,ket] + +def letter (j : ℝ) : Letter (D (ι:=ι)) → Space (ι:=ι) →ₗ[ℝ] Space (ι:=ι) + | .diag a => diagonal a + | .noise => noise j + +def word (j : ℝ) : List (Letter (D (ι:=ι))) → Space (ι:=ι) →ₗ[ℝ] Space (ι:=ι) + | [] => LinearMap.id + | a::F => (letter j a).comp (word j F) + +def outer : Diagram (D (ι:=ι)) → D (ι:=ι) + | .nil => 1 + | .diag a d => a * outer d + | .arch _ d => outer d + +def coefficient (j : ℝ) : Diagram (D (ι:=ι)) → ℝ + | .nil => 1 + | .diag _ d => coefficient j d + | .arch a b => j * Diagram.mean (a.value j) * coefficient j b + +lemma value_factor (j : ℝ) (d : Diagram (D (ι:=ι))) (i : ι) : + d.value j i=coefficient j d * outer d i := by + induction d with + | nil => simp [Diagram.value,coefficient,outer] + | diag a d ih => simp [Diagram.value,coefficient,outer,ih]; ring + | arch a b ia ib => simp [Diagram.value,coefficient,outer,ib]; ring +lemma mean_value (j : ℝ) (d : Diagram (D (ι:=ι))) : + Diagram.mean (d.value j)=coefficient j d * Diagram.mean (outer d) := by + simp only [funext (value_factor j d),Diagram.mean_const_mul] + +def Partial.stack : Partial (D (ι:=ι)) → Stack (ι:=ι) + | .done d => (outer d,[]) + | .more d p => (outer d,p.stack.1::p.stack.2) +def Partial.coefficient (j : ℝ) : Partial (D (ι:=ι)) → ℝ + | .done d => Primary.coefficient j d + | .more d p => Primary.coefficient j d * p.coefficient j + +def Partial.state (j : ℝ) (p : Partial (D (ι:=ι))) : Space (ι:=ι) := + p.coefficient j • ket p.stack + +lemma Partial.state_diag (j : ℝ) (a : D (ι:=ι)) (p : Partial (D (ι:=ι))) : + (p.diag a).state j = diagonal a (p.state j) := by + cases p <;> simp [state,stack,Partial.diag,Partial.coefficient,Primary.coefficient,Primary.outer] +lemma Partial.state_create (j : ℝ) (p : Partial (D (ι:=ι))) : + p.create.state j = creation (p.state j) := by + simp [state,stack,create,Partial.coefficient,Primary.coefficient,Primary.outer] +lemma Partial.state_contract (j : ℝ) (p : Partial (D (ι:=ι))) : + ((p.contract.toList).map (Partial.state j)).sum = j • annihilation (p.state j) := by + cases p with + | done d => simp [state,stack,Partial.contract] + | more d p => + cases p <;> simp [state,stack,Partial.contract,Partial.coefficient, + Primary.coefficient,Primary.outer,mean_value,smul_smul,mul_assoc,mul_left_comm,mul_comm] +lemma Partial.state_noise (j : ℝ) (p : Partial (D (ι:=ι))) : + ((p.noise).map (Partial.state j)).sum = Primary.noise j (p.state j) := by + simp only [Partial.noise,List.map_cons,List.sum_cons,state_create,state_contract] + rfl + +lemma word_vacuum (j : ℝ) (F : List (Letter (D (ι:=ι)))) : + word j F vacuum = ((Partial.enumerate F).map (Partial.state j)).sum := by + induction F with + | nil => simp [word,vacuum,Partial.enumerate,Partial.state,Partial.stack, + Partial.coefficient,Primary.coefficient,Primary.outer] + | cons a F ih => + cases a with + | diag a => + simp only [word,letter,LinearMap.comp_apply,ih,Partial.enumerate,List.map_map] + simp only [map_list_sum,Function.comp_def,Partial.state_diag,List.map_map] + | noise => + simp only [word,letter,LinearMap.comp_apply,ih,Partial.enumerate,List.map_flatMap] + rw [SKGap.Noncrossing.InverseDiagram.sum_flatMap] + simp only [Partial.state_noise,map_list_sum,List.map_map,Function.comp_def] + +lemma Partial.project_state_done (j : ℝ) (d : Diagram (D (ι:=ι))) (i : ι) : + project ((.done d : Partial _).state j) i = d.value j i := by + simp [Partial.state,Partial.stack,Partial.coefficient,value_factor] +lemma Partial.project_state_more (j : ℝ) (d : Diagram (D (ι:=ι))) + (p : Partial (D (ι:=ι))) : project ((Partial.more d p).state j) = 0 := by + simp [Partial.state,Partial.stack] + +lemma prediction_as_finset (j : ℝ) (F : List (Letter (D (ι:=ι)))) (i : ι) : + Diagram.prediction j F i = ∑ d∈Diagram.enumerate F, d.value j i := by + classical + let e : Diagram.Paired F ≃ {d // d∈Diagram.enumerate F} := + { toFun := fun d => ⟨d.val,(Diagram.mem_enumerate F d.val).mpr d.property⟩ + invFun := fun d => ⟨d.val,(Diagram.mem_enumerate F d.val).mp d.property⟩ + left_inv := fun _ => rfl + right_inv := fun _ => rfl } + change (∑ d : Diagram.Paired F, d.val.value j i) = _ + calc + _ = ∑ d : {d // d∈Diagram.enumerate F}, d.val.value j i := + Fintype.sum_equiv e _ _ (fun _ => rfl) + _ = _ := Finset.sum_coe_sort (Diagram.enumerate F) (fun d => d.value j i) + +theorem project_word (j : ℝ) (F : List (Letter (D (ι:=ι)))) (i : ι) : + project (word j F vacuum) i = Diagram.prediction j F i := by + classical + rw [word_vacuum,map_list_sum,List.map_map] + change (((Partial.enumerate F).map (fun p => project (p.state j))).sum) i = _ + have heval : (((Partial.enumerate F).map (fun p => project (p.state j))).sum) i = + ((Partial.enumerate F).map (fun p => project (p.state j) i)).sum := by + induction Partial.enumerate F with + | nil => rfl + | cons p L ih => simp [ih] + rw [heval,← List.sum_toFinset _ (Partial.enumerate_nodup F),prediction_as_finset] + have hsub : (Diagram.enumerate F).image Partial.done ⊆ (Partial.enumerate F).toFinset := by + intro p hp + obtain ⟨d,hd,rfl⟩ := Finset.mem_image.mp hp + simpa [Partial.word] using hd + rw [← Finset.sum_subset hsub (fun p hp hn => ?_)] + · rw [Finset.sum_image (fun d _ e _ h => Partial.done.inj h)] + exact Finset.sum_congr rfl (fun d _ => Partial.project_state_done j d i) + · cases p with + | done d => + exfalso; apply hn + exact Finset.mem_image.mpr ⟨d,by simpa [Partial.word] using hp,rfl⟩ + | more d p => simp [Partial.project_state_more] + +def previousDiagonal (a : ℕ → D (ι:=ι)) : ℕ → D (ι:=ι) + | 0 => 1 + | n+1 => a n + +def creationLabels (a : ℕ → D (ι:=ι)) : ℕ → List (D (ι:=ι)) + | 0 => [] + | n+1 => previousDiagonal a n :: creationLabels a n + +def primaryOperator (j : ℝ) (a : ℕ → D (ι:=ι)) : + ℕ → Space (ι:=ι) →ₗ[ℝ] Space (ι:=ι) + | 0 => LinearMap.id + | 1 => noise j + | n+2 => (noise j).comp ((diagonal (a n)).comp (primaryOperator j a (n+1))) - + (j*Diagram.mean (a n)) • + (diagonal (previousDiagonal a n)).comp (primaryOperator j a n) + +theorem primaryOperator_vacuum (j : ℝ) (a : ℕ → D (ι:=ι)) (n : ℕ) : + primaryOperator j a n vacuum = ket (1,creationLabels a n) := by + induction n using Nat.twoStepInduction with + | zero => rfl + | one => simp [primaryOperator,noise,vacuum,creationLabels,previousDiagonal] + | more n hn hn1 => + simp [primaryOperator,LinearMap.comp_apply,hn,hn1,noise,creationLabels, + previousDiagonal,smul_smul] + +theorem primaryOperator_prediction_zero (j : ℝ) (a : ℕ → D (ι:=ι)) + (n : ℕ) (hn : 0 omega + | succ n => rw [primaryOperator_vacuum]; simp [creationLabels] + +abbrev WordPolynomial := List (ℝ × List (Letter (D (ι:=ι)))) + +def prependWords (F : List (Letter (D (ι:=ι)))) (P : WordPolynomial (ι:=ι)) : + WordPolynomial (ι:=ι) := P.map (fun p => (p.1,F++p.2)) +def scale (c : ℝ) (P : WordPolynomial (ι:=ι)) : WordPolynomial (ι:=ι) := + P.map (fun p => (c*p.1,p.2)) + +def polynomialOperator (j : ℝ) (P : WordPolynomial (ι:=ι)) : + Space (ι:=ι) →ₗ[ℝ] Space (ι:=ι) := + (P.map (fun p => p.1 • word j p.2)).sum + +def polynomialPrediction (j : ℝ) (P : WordPolynomial (ι:=ι)) (i : ι) : ℝ := + (P.map (fun p => p.1 * Diagram.prediction j p.2 i)).sum + +def primaryPolynomial (j : ℝ) (a : ℕ → D (ι:=ι)) : ℕ → WordPolynomial (ι:=ι) + | 0 => [(1,[])] + | 1 => [(1,[.noise])] + | n+2 => prependWords [.noise,.diag (a n)] (primaryPolynomial j a (n+1)) ++ + scale (-(j*Diagram.mean (a n))) + (prependWords [.diag (previousDiagonal a n)] (primaryPolynomial j a n)) + +lemma word_append (j : ℝ) (F G : List (Letter (D (ι:=ι)))) : + word j (F++G) = (word j F).comp (word j G) := by + induction F with + | nil => simp [word] + | cons a F ih => simp [word,ih,LinearMap.comp_assoc] +lemma polynomialOperator_append (j : ℝ) (P Q : WordPolynomial (ι:=ι)) : + polynomialOperator j (P++Q) = polynomialOperator j P + polynomialOperator j Q := by + simp [polynomialOperator] +lemma polynomialOperator_prefix (j : ℝ) (F : List (Letter (D (ι:=ι)))) + (P : WordPolynomial (ι:=ι)) : + polynomialOperator j (prependWords F P) = (word j F).comp (polynomialOperator j P) := by + induction P with + | nil => simp [prependWords,polynomialOperator] + | cons p P ih => + simp only [prependWords,List.map_cons,polynomialOperator,List.sum_cons] at * + rw [word_append,ih,LinearMap.comp_add,LinearMap.comp_smul] +lemma polynomialOperator_scale (j c : ℝ) (P : WordPolynomial (ι:=ι)) : + polynomialOperator j (scale c P)=c • polynomialOperator j P := by + induction P with + | nil => simp [scale,polynomialOperator] + | cons p P ih => + simp only [scale,List.map_cons,polynomialOperator,List.sum_cons] at * + rw [ih,smul_add,mul_smul] + +lemma primaryPolynomial_operator (j : ℝ) (a : ℕ → D (ι:=ι)) (n : ℕ) : + polynomialOperator j (primaryPolynomial j a n)=primaryOperator j a n := by + induction n using Nat.twoStepInduction with + | zero => simp [primaryPolynomial,polynomialOperator,primaryOperator,word] + | one => simp [primaryPolynomial,polynomialOperator,primaryOperator,word,letter] + | more n hn hn1 => + simp only [primaryPolynomial,polynomialOperator_append,polynomialOperator_prefix, + polynomialOperator_scale,hn,hn1,word,letter,LinearMap.comp_id,primaryOperator] + ext v k + simp [LinearMap.comp_apply,sub_eq_add_neg,neg_smul] + +lemma polynomialPrediction_eq_project (j : ℝ) (P : WordPolynomial (ι:=ι)) (i : ι) : + polynomialPrediction j P i = project (polynomialOperator j P vacuum) i := by + induction P with + | nil => simp [polynomialPrediction,polynomialOperator] + | cons p P ih => + simp only [polynomialPrediction,polynomialOperator,List.map_cons,List.sum_cons, + LinearMap.add_apply,LinearMap.smul_apply,map_add,map_smul,Pi.add_apply,Pi.smul_apply, + smul_eq_mul] at * + rw [project_word,ih] + +theorem primaryPolynomial_prediction_zero (j : ℝ) (a : ℕ → D (ι:=ι)) + (n : ℕ) (hn : 0 1 + | 1 => R + | k+2 => R*formalOpBound j R (k+1)+|j| *formalOpBound j R k + +lemma formalOpBound_nonneg (j : ℝ) {R : ℝ} (hR : 0≤R) (k : ℕ) : + 0≤formalOpBound j R k := by + induction k using Nat.twoStepInduction with + | zero => norm_num [formalOpBound] + | one => exact hR + | more k hk hk1 => dsimp only [formalOpBound]; positivity + +lemma primaryMatrix_opNorm {j R : ℝ} (J : Interaction n) (a : ℕ→Fin n→ℝ) + (hn : 0 simp [previousDiagonal] + | succ l => exact ha l + induction k using Nat.twoStepInduction with + | zero => exact SKGap.opNorm_one_le + | one => exact hJ + | more k hk hk1 => + dsimp only [primaryMatrix,formalOpBound] + apply (SKGap.opNorm_sub _ _).trans + apply add_le_add + · apply (SKGap.opNorm_mul _ _).trans + have hJD : SKGap.opNorm (J*Matrix.diagonal (a k))≤R := + (SKGap.opNorm_mul _ _).trans ((mul_le_mul hJ (hd k) (norm_nonneg _) hR).trans_eq (mul_one _)) + exact mul_le_mul hJD hk1 (norm_nonneg _) hR + · rw [opNorm_smul,abs_mul] + have hm : SKGap.opNorm (Matrix.diagonal (previousDiagonal a k)*primaryMatrix j J a k)≤ + formalOpBound j R k := + (SKGap.opNorm_mul _ _).trans ((mul_le_mul (hp k) hk (norm_nonneg _) + zero_le_one).trans_eq (one_mul _)) + calc + _ ≤ (|j| *1)*formalOpBound j R k := mul_le_mul + (mul_le_mul_of_nonneg_left (mean_abs_le_one (ha k)) (abs_nonneg _)) hm + (norm_nonneg _) (by positivity) + _ = _ := by ring + +def primaryWordTail (j : ℝ) (k n : ℕ) : ENNReal := + 2*((wordPatternSet (2*k) (2*k)).card*ENNReal.ofReal (3*exp (-(n:ℝ)))+ + ENNReal.ofReal (exp (-2*(n:ℝ)/(π^2*(sqrt (2*j))^2)))+ + (ENNReal.ofReal (2*exp (-(n:ℝ)/(π^2*j)))+ + ENNReal.ofReal (2*(n:ℝ)*exp (-1/(8*(j/n)))))) +def primaryNormTail (j : ℝ) (n : ℕ) : ENNReal := + ENNReal.ofReal (2*exp (-(n:ℝ)/(π^2*j)))+ + ENNReal.ofReal (2*(n:ℝ)*exp (-1/(8*(j/n)))) + +theorem primary_uniform_actual_derivatives {j : ℝ} (hj : 0gaussianReal 0 1)) + {g | ∃ (h : Fin n→ℝ) (x : Spin n), + let J := removeDiagonal (goeMatrix (j/n) g) + ¬ (‖derivativeMatrix (primaryState j J h k).2 x-formalField j J h x k‖≤C ∧ + ‖derivativeMatrix (primaryState j J h k).1 x-formalMag j J h x k‖≤C ∧ + SKGap.opNorm (derivativeMatrix (primaryState j J h k).1 x)≤C ∧ + ShapeBound (derivativeMatrix (primaryState j J h k).2 x) C ∧ + (n:ℝ)*‖derivativeVector (siteMean (fun y i => + scalarVariance ((primaryState j J h k).2 y i))) x‖^2≤(2*T+4*T^2)^2)} ≤ + primaryNormTail j n+∑ l : Fin (k+1),primaryWordTail j (l.val+1) n := by + classical + have hchoice (l : Fin (k+1)) := primary_uniform_two_seminorms hj hj1 (l.val+1) (by omega) + choose c N hc hN hbound using hchoice + let R := 2*sqrt j+1+1 + have hR : 0≤R := by dsimp [R]; positivity + let B := 1+∑ l : Fin (k+1), (c l+formalOpBound j R (l.val+1)) + have hB : 0 add_nonneg (hc l).le (formalOpBound_nonneg j hR _)) + linarith + have hcB (l : Fin (k+1)) : c l≤B := by + have hs := Finset.single_le_sum (s:=Finset.univ) + (fun q (_ : q∈Finset.univ) => add_nonneg (hc q).le (formalOpBound_nonneg j hR (q.val+1))) + (Finset.mem_univ l) + have hp := formalOpBound_nonneg j hR (l.val+1) + dsimp [B]; linarith + have hoB (l : Fin (k+1)) : formalOpBound j R (l.val+1)≤B := by + have hs := Finset.single_le_sum (s:=Finset.univ) + (fun q (_ : q∈Finset.univ) => add_nonneg (hc q).le (formalOpBound_nonneg j hR (q.val+1))) + (Finset.mem_univ l) + have hp := hc l + dsimp [B]; linarith + let N₀ := 1+∑ l : Fin (k+1),N l + refine ⟨B,N₀,hB,by dsimp [N₀]; omega,?_⟩ + intro n hn + have hn0 : 0gaussianReal 0 1) + let A : Fin (k+1) → Set (MatrixCoordinates (Fin n)→ℝ) := fun l => + {g | ∃ (p : Bool) (a : ℕ→Fin n→ℝ), (∀ d i,|a d i|≤1) ∧ + c l < matrixWordSeminorm p (primaryMatrix j (removeDiagonal (goeMatrix (j/n) g)) a (l.val+1))} + let E : Set (MatrixCoordinates (Fin n)→ℝ) := + {g | R hA l)))))) + intro g hg + by_contra hbad + have hJ : SKGap.opNorm (removeDiagonal (goeMatrix (j/n) g))≤R := by + apply le_of_not_gt; intro hh; exact hbad (.inl hh) + obtain ⟨h,x,hfail⟩ := hg + have hf : ∀ l≤k,ShapeBound (formalField j (removeDiagonal (goeMatrix (j/n) g)) h x l) B := by + intro l hl + let q : Fin (k+1) := ⟨l,by omega⟩ + have ha := primaryDiagonal_bounded j (removeDiagonal (goeMatrix (j/n) g)) h x + refine ⟨(primaryMatrix_opNorm _ _ hn0 hR hJ ha (l+1)).trans (hoB q),?_,?_⟩ + · apply (le_of_not_gt ?_).trans (hcB q) + intro hh + apply hbad + exact .inr (Set.mem_iUnion.mpr ⟨q,false,_,ha,hh⟩) + · apply (le_of_not_gt ?_).trans (hcB q) + intro hh + apply hbad + exact .inr (Set.mem_iUnion.mpr ⟨q,true,_,ha,hh⟩) + obtain ⟨h1,h2,h3,h4⟩ := primary_differentiation _ h x hn0 hR hB.le hJ k hf + exact hfail ⟨h1,h2,h3,h4,primary_average_differentiation _ h x hn0 hR hB.le hJ k hf⟩ + +end SKGapCutoff.Primary + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/ProdEventSectionLaw.lean b/lean/OAI/Probability/SKGap/Localization/ProdEventSectionLaw.lean new file mode 100644 index 0000000000000000000000000000000000000000..1ad432cc491a1a4148fb3961383ad113ba5620a5 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/ProdEventSectionLaw.lean @@ -0,0 +1,283 @@ +import Mathlib +import OAI.Probability.SKGap.Gaussian.SquareTail2 + +namespace OAI + +section +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open scoped BigOperators +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open scoped BigOperators +open scoped BigOperators NNReal ENNReal +open MeasureTheory Metric Set +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators NNReal ENNReal Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Set +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators ENNReal NNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Matrix +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators ENNReal NNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal +open scoped BigOperators +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise NNReal ENNReal +open scoped BigOperators +open Filter Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal Topology +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +namespace SKGapCutoff.Regression + +lemma prod_event_le_of_section_law {H A B C : Type*} + [MeasurableSpace H] [MeasurableSpace A] [MeasurableSpace B] [MeasurableSpace C] + (ρ : Measure H) (μ : Measure A) (ν : Measure B) + [IsProbabilityMeasure μ] [SFinite ν] + (f : H × A → C) (g : H × B → C) (hf : Measurable f) (hg : Measurable g) + (G : Set H) (hG : MeasurableSet G) + (hfg : ∀ h ∈ G, μ.map (fun a => f (h,a)) = ν.map (fun b => g (h,b))) + (T : Set C) (hT : MeasurableSet T) : + (ρ.prod μ) (f ⁻¹' T) ≤ (ρ.prod ν) (g ⁻¹' T)+ρ Gᶜ := by + rw [Measure.prod_apply (hf hT), Measure.prod_apply (hg hT)] + have hm := measurable_measure_prodMk_left (ν := ν) (hg hT) + calc + _ ≤ ∫⁻ h, ν (Prod.mk h ⁻¹' (g ⁻¹' T)) + Gᶜ.indicator (fun _ => (1:ℝ≥0∞)) h ∂ρ := by + apply lintegral_mono + intro h + change μ (Prod.mk h ⁻¹' (f ⁻¹' T)) ≤ ν (Prod.mk h ⁻¹' (g ⁻¹' T)) + + Gᶜ.indicator (fun _ => (1:ℝ≥0∞)) h + by_cases hh : h ∈ G + · have he := congrArg (fun m : Measure C => m T) (hfg h hh) + rw [Measure.map_apply (show Measurable (fun a => f (h,a)) from hf.comp measurable_prodMk_left) hT, + Measure.map_apply (show Measurable (fun b => g (h,b)) from hg.comp measurable_prodMk_left) hT] at he + rw [Set.indicator_of_notMem (show h ∉ Gᶜ from fun hc => hc hh), add_zero] + change μ ((fun a => f (h,a)) ⁻¹' T) ≤ ν ((fun b => g (h,b)) ⁻¹' T) + exact le_of_eq he + · simp only [Set.indicator_of_mem (show h ∈ Gᶜ from hh)] + exact (prob_le_one (μ := μ)).trans (le_add_left le_rfl) + _ = _ := by + rw [lintegral_add_left hm, lintegral_indicator hG.compl] + simp + +lemma exponentiallyRare_of_measure_le_add + {H A B : ℕ → Type*} [∀ n, MeasurableSpace (H n)] + [∀ n, MeasurableSpace (A n)] [∀ n, MeasurableSpace (B n)] + (ρ : ∀ n, Measure (H n)) (μ : ∀ n, Measure (A n)) (ν : ∀ n, Measure (B n)) + (S : ∀ n, Set (H n)) (T : ∀ n, Set (A n)) (V : ∀ n, Set (B n)) + (hT : ExponentiallyRare μ T) (hV : ExponentiallyRare ν V) + (hS : ∀ᶠ n in atTop, ρ n (S n) ≤ μ n (T n)+ν n (V n)) : + ExponentiallyRare ρ S := by + obtain ⟨C,c,hC,hc,hTc⟩ := hT + obtain ⟨D,d,hD,hd,hVd⟩ := hV + refine ⟨C+D,min c d,by positivity,lt_min hc hd,?_⟩ + filter_upwards [hTc,hVd,hS] with n hn hm hs + refine hs.trans ((add_le_add hn hm).trans ?_) + have hc' : Real.exp (-c*(n:ℝ)) ≤ Real.exp (-min c d*(n:ℝ)) := by + apply Real.exp_le_exp.mpr + nlinarith [min_le_left c d,Nat.cast_nonneg (α := ℝ) n] + have hd' : Real.exp (-d*(n:ℝ)) ≤ Real.exp (-min c d*(n:ℝ)) := by + apply Real.exp_le_exp.mpr + nlinarith [min_le_right c d,Nat.cast_nonneg (α := ℝ) n] + rw [add_mul,ENNReal.ofReal_add (by positivity) (by positivity)] + exact add_le_add (ENNReal.ofReal_le_ofReal (mul_le_mul_of_nonneg_left hc' hC.le)) + (ENNReal.ofReal_le_ofReal (mul_le_mul_of_nonneg_left hd' hD.le)) + +theorem ExponentialEmpiricalConcentration.of_section_law + {E : Type*} [PseudoMetricSpace E] [MeasurableSpace E] [BorelSpace E] + {H A B : ℕ → Type*} [∀ n, MeasurableSpace (H n)] + [∀ n, MeasurableSpace (A n)] [∀ n, MeasurableSpace (B n)] + (ρ : ∀ n, Measure (H n)) (μ : ∀ n, Measure (A n)) (η : ∀ n, Measure (B n)) + [∀ n, IsProbabilityMeasure (μ n)] [∀ n, SFinite (η n)] + (X : ∀ n, H n × A n → Fin n → E) (Y : ∀ n, H n × B n → Fin n → E) + (hXm : ∀ n, Measurable (X n)) (hYm : ∀ n, Measurable (Y n)) + (G : ∀ n, Set (H n)) (hG : ∀ n, MeasurableSet (G n)) + (hrare : ExponentiallyRare ρ (fun n => (G n)ᶜ)) + (hXY : ∀ᶠ n in atTop, ∀ h ∈ G n, + (μ n).map (fun a => X n (h,a)) = (η n).map (fun b => Y n (h,b))) + {ν : Measure E} + (hY : ExponentialEmpiricalConcentration (fun n => (ρ n).prod (η n)) Y ν) : + ExponentialEmpiricalConcentration (fun n => (ρ n).prod (μ n)) X ν := by + intro f K hf B hB ε hε + apply exponentiallyRare_of_measure_le_add + (fun n => (ρ n).prod (μ n)) (fun n => (ρ n).prod (η n)) ρ _ _ _ + (hY f K hf B hB ε hε) hrare + filter_upwards [hXY] with n hn + let T : Set (Fin n → E) := {z | ε ≤ |(∑ i, f (z i))/(n:ℝ)-∫ x, f x ∂ν|} + have hT : MeasurableSet T := by + apply measurableSet_le measurable_const + exact (Measurable.sub ((Finset.measurable_sum _ (fun i _ => + hf.continuous.measurable.comp (measurable_pi_apply i))).div_const _) measurable_const).abs + exact prod_event_le_of_section_law (ρ n) (μ n) (η n) (X n) (Y n) + (hXm n) (hYm n) (G n) (hG n) hn T hT + +theorem ExponentialSquareTails.of_section_law + {H A B : ℕ → Type*} [∀ n, MeasurableSpace (H n)] + [∀ n, MeasurableSpace (A n)] [∀ n, MeasurableSpace (B n)] + (ρ : ∀ n, Measure (H n)) (μ : ∀ n, Measure (A n)) (η : ∀ n, Measure (B n)) + [∀ n, IsProbabilityMeasure (μ n)] [∀ n, SFinite (η n)] + (X : ∀ n, H n × A n → Fin n → ℝ) (Y : ∀ n, H n × B n → Fin n → ℝ) + (hXm : ∀ n, Measurable (X n)) (hYm : ∀ n, Measurable (Y n)) + (G : ∀ n, Set (H n)) (hG : ∀ n, MeasurableSet (G n)) + (hrare : ExponentiallyRare ρ (fun n => (G n)ᶜ)) + (hXY : ∀ᶠ n in atTop, ∀ h ∈ G n, + (μ n).map (fun a => X n (h,a)) = (η n).map (fun b => Y n (h,b))) + (hY : ExponentialSquareTails (fun n => (ρ n).prod (η n)) Y) : + ExponentialSquareTails (fun n => (ρ n).prod (μ n)) X := by + intro ε hε + obtain ⟨R,hR,hYR⟩ := hY ε hε + refine ⟨R,hR,?_⟩ + apply exponentiallyRare_of_measure_le_add + (fun n => (ρ n).prod (μ n)) (fun n => (ρ n).prod (η n)) ρ _ _ _ hYR hrare + filter_upwards [hXY] with n hn + let T : Set (Fin n → ℝ) := {z | ε ≤ (∑ i, squareTail R (z i))/(n:ℝ)} + have hT : MeasurableSet T := by + apply measurableSet_le measurable_const + exact (Finset.measurable_sum _ (fun i _ => + (measurable_squareTail R).comp (measurable_pi_apply i))).div_const _ + exact prod_event_le_of_section_law (ρ n) (μ n) (η n) (X n) (Y n) + (hXm n) (hYm n) (G n) (hG n) hn T hT + +end SKGapCutoff.Regression + +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology + +namespace SKGapCutoff.Regression + +noncomputable def unitVector {n : ℕ} (v : Fin n → ℝ) : Fin n → ℝ := + fun i => v i/Real.sqrt (∑ j, v j^2) + +lemma unitVector_sq_sum {n : ℕ} (v : Fin n → ℝ) : + ∑ i, unitVector v i^2 = if ∑ i, v i^2 = 0 then 0 else 1 := by + have hs : 0 ≤ ∑ i, v i^2 := Finset.sum_nonneg (fun _ _ => sq_nonneg _) + simp only [unitVector, div_pow, ← Finset.sum_div, Real.sq_sqrt hs] + split_ifs with h + · simp [h] + · exact div_self h + +lemma unitVector_sq_le {n : ℕ} (v : Fin n → ℝ) : ∑ i, unitVector v i^2 ≤ 1 := by + rw [unitVector_sq_sum] + split_ifs <;> norm_num + +lemma unitVector_sq_eq {n : ℕ} (v : Fin n → ℝ) (hv : 0 < ∑ i, v i^2) : + ∑ i, unitVector v i^2 = 1 := by + rw [unitVector_sq_sum, ite_eq_right (ne_of_gt hv)] + +lemma residualProjection_idem {n r : ℕ} (U : Matrix (Fin n) (Fin r) ℝ) + (hU : Uᵀ*U=1) : residualProjection U*residualProjection U=residualProjection U := by + rw [residualProjection, Matrix.mul_sub, Matrix.mul_one, ← Matrix.mul_assoc, + ← residualProjection, residualProjection_mul U hU, Matrix.zero_mul, sub_zero] + +lemma normalized_residual_perpendicular {n r : ℕ} (U : Matrix (Fin n) (Fin r) ℝ) + (hU : Uᵀ*U=1) (v : Fin n → ℝ) : + Uᵀ *ᵥ unitVector (residualProjection U *ᵥ v)=0 := by + have he : unitVector (residualProjection U *ᵥ v) = + (Real.sqrt (∑ i, (residualProjection U *ᵥ v) i^2))⁻¹ • (residualProjection U *ᵥ v) := by + ext i + change _ = (Real.sqrt (∑ j, (residualProjection U *ᵥ v) j^2))⁻¹ * (residualProjection U *ᵥ v) i + simp only [unitVector, div_eq_mul_inv, mul_comm] + rw [he, Matrix.mulVec_smul, Matrix.mulVec_mulVec, mul_residualProjection U hU, + Matrix.zero_mulVec, smul_zero] + +lemma normalized_residual_fixed {n r : ℕ} (U : Matrix (Fin n) (Fin r) ℝ) + (hU : Uᵀ*U=1) (v : Fin n → ℝ) : + residualProjection U *ᵥ unitVector (residualProjection U *ᵥ v)= + unitVector (residualProjection U *ᵥ v) := by + change (1-U*Uᵀ) *ᵥ unitVector (residualProjection U *ᵥ v) = _ + rw [Matrix.sub_mulVec, Matrix.one_mulVec, ← Matrix.mulVec_mulVec, + normalized_residual_perpendicular U hU, Matrix.mulVec_zero, sub_zero] + +lemma residual_scaled_predictor {n r : ℕ} (hn : 0 < n) + (U : Matrix (Fin n) (Fin r) ℝ) (v : Fin n → ℝ) (i : Fin n) : + (residualProjection U *ᵥ v) i = v i- + ∑ a, (Real.sqrt n*U i a)*((∑ j, Real.sqrt n*U j a*v j)/(n:ℝ)) := by + have hn0 : (n:ℝ) ≠ 0 := Nat.cast_ne_zero.mpr (Nat.ne_of_gt hn) + have hs : (Real.sqrt (n:ℝ))^2 = n := Real.sq_sqrt (Nat.cast_nonneg _) + simp only [residualProjection, Matrix.sub_mulVec, Matrix.one_mulVec, + ← Matrix.mulVec_mulVec,Pi.sub_apply] + congr 1 + simp only [Matrix.mulVec,dotProduct,Matrix.transpose_apply] + apply Finset.sum_congr rfl + intro a _ + rw [Finset.sum_div,Finset.mul_sum,Finset.mul_sum] + apply Finset.sum_congr rfl + intro j _ + field_simp + nlinarith [congrArg (fun z : ℝ => z*(U i a*U j a*v j)) hs] + +lemma scaled_unitVector {n : ℕ} (hn : 0 < n) (v : Fin n → ℝ) (i : Fin n) : + Real.sqrt n*unitVector v i = v i/Real.sqrt ((∑ j, v j^2)/(n:ℝ)) := by + have hn0 : (n:ℝ) ≠ 0 := Nat.cast_ne_zero.mpr (Nat.ne_of_gt hn) + have hsn : Real.sqrt (n:ℝ) ≠ 0 := ne_of_gt (Real.sqrt_pos.mpr (Nat.cast_pos.mpr hn)) + rw [Real.sqrt_div (Finset.sum_nonneg (fun _ _ => sq_nonneg _))] + simp only [unitVector,div_div_eq_mul_div] + ring + +@[fun_prop] lemma measurable_unitVector {n : ℕ} : Measurable (@unitVector n) := by + unfold unitVector + fun_prop + +end SKGapCutoff.Regression + +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise + +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/ProjectedMarkedIBP.lean b/lean/OAI/Probability/SKGap/Localization/ProjectedMarkedIBP.lean new file mode 100644 index 0000000000000000000000000000000000000000..1bddc91421c051a9fa6a800636f5dffc6fc5696c --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/ProjectedMarkedIBP.lean @@ -0,0 +1,46 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.MarkedProductIBP + +namespace OAI + +section +noncomputable section +namespace SKGap +open Matrix Real MeasureTheory ProbabilityTheory Set +open scoped BigOperators Matrix.Norms.Frobenius NNReal ENNReal +variable {ι : Type*} [Fintype ι] [DecidableEq ι] + +def markedError (r R : ℝ) (L K B C : NNReal) (D E p : ℝ) : ℝ := + B*R*C*p+B*C*(Fintype.card ι:ℝ)^2*sqrt (2*r)*sqrt p+ + (Fintype.card ι:ℝ)^2*(sqrt (2*r)*((L*C+B*K:NNReal)* + (⟨sqrt (2*r),sqrt_nonneg _⟩*(Fintype.card (MatrixCoordinates ι):NNReal)^(1/(2:ℝ≥0∞)).toReal):NNReal)+ + r*(D*C+B*E))*p + +theorem projected_marked_product_IBP {r R : ℝ} (hr : 0≤r) (hR : 0≤R) + (U Q : Matrix ι ι ℝ→Matrix ι ι ℝ) + (DU DQ : ι→ι→Matrix ι ι ℝ→Matrix ι ι ℝ) + {L K B C : NNReal} {D E : ℝ} + (hU : LipschitzWith L U) (hQ : LipschitzWith K Q) + (hB : ∀ M,opNorm (U M)≤B) (hC : ∀ M,opNorm (Q M)≤C) + (hDU : ∀ a b,Continuous (DU a b)) (hDQ : ∀ a b,Continuous (DQ a b)) + (hD : ∀ a b M,opNorm (DU a b M)≤D) (hE : ∀ a b M,opNorm (DQ a b M)≤E) + {s : Set (MatrixCoordinates ι→ℝ)} (hs : MeasurableSet s) + (hgood : ∀ g∈s,opNorm (goeMatrix r g)≤R) + (hUd : ∀ a b g,g∈s→HasDerivAt (fun t : ℝ=>U (goeMatrix r g+t • symmetricElementary a b)) (DU a b (goeMatrix r g)) 0) + (hQd : ∀ a b g,g∈s→HasDerivAt (fun t : ℝ=>Q (goeMatrix r g+t • symmetricElementary a b)) (DQ a b (goeMatrix r g)) 0) + (i : ι) : + let μ := Measure.pi (fun _ : MatrixCoordinates ι=>gaussianReal 0 1) + |(∫ g,(U (goeMatrix r g)*realProject R hR (goeMatrix r g)*Q (goeMatrix r g)) i i ∂μ)- + r*(∫ g,∑ a,∑ b,(DU a b (goeMatrix r g) i a*Q (goeMatrix r g) b i+ + U (goeMatrix r g) i a*DQ a b (goeMatrix r g) b i) ∂μ)|≤ + markedError (ι:=ι) r R L K B C D E (μ.real sᶜ) := by + intro μ + have h1 := projected_marked_expectation_error hr hR B.coe_nonneg C.coe_nonneg U Q + hU.continuous hQ.continuous hB hC hs hgood i + have h2 := goe_marked_product_IBP hr U Q DU DQ hU hQ hB hC hDU hDQ hD hE hs hUd hQd i + exact (abs_sub_le _ _ _).trans (add_le_add h1 h2) +end SKGap +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/ProjectedReal.lean b/lean/OAI/Probability/SKGap/Localization/ProjectedReal.lean new file mode 100644 index 0000000000000000000000000000000000000000..fc2d307d332787a8c8c281007c13b6d613d28b44 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/ProjectedReal.lean @@ -0,0 +1,176 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.IntegralAbsSet +import OAI.Probability.SKGap.Brownian.PathBiasBase +import OAI.Probability.SKGap.Localization.Conjugation + +namespace OAI + +section +noncomputable section +namespace SKGap +open Matrix MeasureTheory ProbabilityTheory Real +open RealComplex +open scoped BigOperators Matrix.Norms.Frobenius NNReal ENNReal SchwartzMap +variable {ι : Type*} [Fintype ι] [DecidableEq ι] + +omit [DecidableEq ι] in +lemma signConjugate_mul (s : ι → ℝ) (hs : ∀ i, s i^2=1) (M N : Matrix ι ι ℝ) : + signConjugate s (M*N) = signConjugate s M*signConjugate s N := by + ext i k + change s i*s k*(∑ b, M i b*N b k) = ∑ b, (s i*s b*M i b)*(s b*s k*N b k) + rw [Finset.mul_sum] + apply Finset.sum_congr rfl + intro b _ + calc + _ = (s i*s k*(M i b*N b k))*1 := by ring + _ = (s i*s k*(M i b*N b k))*(s b)^2 := by rw [hs b] + _ = _ := by ring + +noncomputable def realProject (R : ℝ) (hR : 0 ≤ R) (M : Matrix ι ι ℝ) : Matrix ι ι ℝ := + RealComplex.realPart (ComplexMatrix.matrixProject R hR (liftMatrix M)) + +lemma realProject_opNorm {R : ℝ} (hR : 0 ≤ R) (M : Matrix ι ι ℝ) : + opNorm (realProject R hR M) ≤ R := + (operator_realPart_le _).trans (ComplexMatrix.matrixProject_bound R hR (liftMatrix M)).2 + +lemma realProject_sub_norm {R : ℝ} (hR : 0 ≤ R) (M N : Matrix ι ι ℝ) : + ‖realProject R hR M-realProject R hR N‖ ≤ ‖M-N‖ := by + unfold realProject + rw [← realPart_sub] + apply (norm_realPart_le _).trans + simpa only [← liftMatrix_sub,norm_liftMatrix] using + ComplexMatrix.matrixProject_sub_norm R hR (liftMatrix M) (liftMatrix N) + +lemma realProject_eq_self {R : ℝ} (hR : 0 ≤ R) (M : Matrix ι ι ℝ) + (hM : Mᵀ=M) (hMR : opNorm M ≤ R) : realProject R hR M=M := by + unfold realProject + rw [ComplexMatrix.matrixProject_eq_self R hR (liftMatrix M) (liftMatrix_hermitian M hM) + (by simpa only [ComplexMatrix.opNorm,ComplexMatrix.lin,operator_norm_lift] using hMR)] + ext i k + simp [RealComplex.realPart,liftMatrix] + +lemma realProject_sign {R : ℝ} (hR : 0 ≤ R) (s : ι → ℝ) (hs : ∀ i, s i^2=1) + (M : Matrix ι ι ℝ) : realProject R hR (signConjugate s M) = signConjugate s (realProject R hR M) := by + unfold realProject + rw [← sign_conjugate_lift s hs M,ComplexMatrix.matrixProject_conjugate,realPart_sign_conjugate] + +lemma realProject_lipschitz {R : ℝ} (hR : 0 ≤ R) : + LipschitzWith 1 (realProject (ι := ι) R hR) := by + apply LipschitzWith.of_dist_le_mul + intro M N + simpa only [dist_eq_norm,NNReal.coe_one,one_mul] using realProject_sub_norm hR M N + +lemma realProjectedProduct_opNorm {R B : ℝ} (hR : 0 ≤ R) + (K : Matrix ι ι ℝ → Matrix ι ι ℝ) (hK : ∀ M, opNorm (K M) ≤ B) (M : Matrix ι ι ℝ) : + opNorm (realProject R hR M*K M) ≤ R*B := by + apply (opNorm_mul _ _).trans + exact mul_le_mul (realProject_opNorm hR M) (hK M) (norm_nonneg _) hR + +lemma realProjectedProduct_sub_norm {R B L : ℝ} (hR : 0 ≤ R) + (K : Matrix ι ι ℝ → Matrix ι ι ℝ) (hK : ∀ M, opNorm (K M) ≤ B) + (hLip : ∀ M N, ‖K M-K N‖ ≤ L*‖M-N‖) (M N : Matrix ι ι ℝ) : + ‖realProject R hR M*K M-realProject R hR N*K N‖ ≤ (B+R*L)*‖M-N‖ := by + have he : realProject R hR M*K M-realProject R hR N*K N = + (realProject R hR M-realProject R hR N)*K M+realProject R hR N*(K M-K N) := by noncomm_ring + rw [he] + apply (norm_add_le _ _).trans + calc + _ ≤ ‖realProject R hR M-realProject R hR N‖*opNorm (K M)+ + opNorm (realProject R hR N)*‖K M-K N‖ := + add_le_add (frobenius_mul_le_opNorm_right _ _) (frobenius_mul_le_opNorm _ _) + _ ≤ ‖M-N‖*B+R*(L*‖M-N‖) := by + apply add_le_add + · exact mul_le_mul (realProject_sub_norm hR M N) (hK M) (norm_nonneg _) (norm_nonneg _) + · exact mul_le_mul (realProject_opNorm hR N) (hLip M N) (norm_nonneg _) hR + _ = _ := by ring +end SKGap +end +end + +section +noncomputable section +namespace SKGap +open Matrix MeasureTheory ProbabilityTheory Real +open scoped BigOperators Matrix.Norms.Frobenius NNReal ENNReal +variable {ι : Type*} [Fintype ι] [DecidableEq ι] + +lemma projected_product_expectation_error {R r B : ℝ} (hR : 0 ≤ R) (hr : 0 ≤ r) + (hB : 0 ≤ B) (K : Matrix ι ι ℝ → Matrix ι ι ℝ) (hK : Continuous K) + (hKB : ∀ M, opNorm (K M) ≤ B) {s : Set (MatrixCoordinates ι → ℝ)} + (hs : MeasurableSet s) (hgood : ∀ g ∈ s, opNorm (goeMatrix r g) ≤ R) (i : ι) : + let μ := Measure.pi (fun _ : MatrixCoordinates ι => gaussianReal 0 1) + |(∫ g, (realProject R hR (goeMatrix r g)*K (goeMatrix r g)) i i ∂μ)- + (∫ g, (goeMatrix r g*K (goeMatrix r g)) i i ∂μ)| ≤ + R*B*μ.real sᶜ+B*(Fintype.card ι:ℝ)*sqrt (2*r)*sqrt (μ.real sᶜ) := by + intro μ + let KG := fun g : MatrixCoordinates ι → ℝ => K (goeMatrix r g) + have hKG : Continuous KG := hK.comp (goeMatrix_pi_lipschitz r).continuous + have hKe (g : MatrixCoordinates ι → ℝ) (a b : ι) : |KG g a b| ≤ B := + (matrix_entry_le_opNorm _ a b).trans (hKB _) + have hP : Continuous (fun g : MatrixCoordinates ι → ℝ => realProject R hR (goeMatrix r g)*KG g) := + ((realProject_lipschitz hR).continuous.comp (goeMatrix_pi_lipschitz r).continuous).matrix_mul hKG + have hPe (g : MatrixCoordinates ι → ℝ) : + |(realProject R hR (goeMatrix r g)*KG g) i i| ≤ R*B := + (matrix_entry_le_opNorm _ i i).trans (realProjectedProduct_opNorm hR K hKB _) + have hPI : Integrable (fun g => (realProject R hR (goeMatrix r g)*KG g) i i) μ := + Integrable.mono' (integrable_const (R*B)) (hP.matrix_elem i i).aestronglyMeasurable + (ae_of_all _ (fun g => by simpa only [Real.norm_eq_abs] using hPe g)) + have hW (b : ι) : Integrable (fun g => goeMatrix r g i b) μ := + (goeEntry_memLp r i b).integrable (by norm_num) + have hWi (b : ι) : Integrable (fun g => goeMatrix r g i b*KG g b i) μ := by + simpa only [mul_comm] using (hW b).bdd_mul (hKG.matrix_elem b i).aestronglyMeasurable + (ae_of_all _ (fun g => by simpa only [Real.norm_eq_abs] using hKe g b i)) + have hWI : Integrable (fun g => (goeMatrix r g*KG g) i i) μ := + integrable_finsetSum _ (fun b _ => hWi b) + have hHA : Integrable (fun g => ∑ b, |goeMatrix r g i b|) μ := + integrable_finsetSum _ (fun b _ => (hW b).norm) + let H := fun g => R*B+B*∑ b, |goeMatrix r g i b| + have hHI : Integrable H μ := (integrable_const _).add (hHA.const_mul B) + have hb (g : MatrixCoordinates ι → ℝ) : + ‖(realProject R hR (goeMatrix r g)*KG g) i i-(goeMatrix r g*KG g) i i‖ ≤ H g := by + rw [Real.norm_eq_abs] + exact (abs_sub _ _).trans (add_le_add (hPe g) (abs_mul_entry_bound _ _ B (hKe g) i)) + have hraw := integral_exceptional_equal_bound hs.compl hPI hWI hHI + (fun g hg => by rw [realProject_eq_self hR _ (goeMatrix_transpose r g) (hgood g (by simpa using hg))]) + (fun g _ => hb g) + have hbad (b : ι) : (∫ g in sᶜ, |goeMatrix r g i b| ∂μ) ≤ + sqrt (2*r)*sqrt (μ.real sᶜ) := by + apply (integral_abs_on_set_le (goeEntry_memLp r i b) hs.compl).trans + exact mul_le_mul_of_nonneg_right (sqrt_le_sqrt (goeEntry_integral_sq_le hr i b)) (sqrt_nonneg _) + apply hraw.trans + change (∫ g in sᶜ, R*B+B*∑ b, |goeMatrix r g i b| ∂μ) ≤ _ + rw [integral_add (integrable_const _) ((hHA.const_mul B).mono_measure Measure.restrict_le_self), + integral_const,integral_const_mul] + have hWa (b : ι) : Integrable (fun g => |goeMatrix r g i b|) (μ.restrict sᶜ) := by + simpa only [Real.norm_eq_abs] using (hW b).norm.mono_measure Measure.restrict_le_self + rw [integral_finsetSum _ (fun b _ => hWa b)] + simp only [measureReal_restrict_apply_univ,smul_eq_mul] + calc + _ ≤ μ.real sᶜ*(R*B)+B*(∑ _b : ι, sqrt (2*r)*sqrt (μ.real sᶜ)) := + add_le_add le_rfl (mul_le_mul_of_nonneg_left (Finset.sum_le_sum (fun b _ => hbad b)) hB) + _ = _ := by simp only [Finset.sum_const,Finset.card_univ,nsmul_eq_mul]; ring + +end SKGap +namespace SKGap +open Real + +def projectedErrorConstant (j R B rate : ℝ) : ℝ := + R*B*(3/rate)+B*sqrt (2*j)*(8*sqrt 3/rate^2) + +lemma projected_error_absorption {j R B rate n p : ℝ} + (hj : 0 ≤ j) (hR : 0 ≤ R) (hB : 0 ≤ B) (hc : 0 < rate) + (hn : 1 ≤ n) (hp : p ≤ 3*Real.exp (-rate*n)) : + R*B*p+B*n*sqrt (2*(j/n))*sqrt p ≤ projectedErrorConstant j R B rate/n := by + have hn0 : 0 < n := lt_of_lt_of_le (by norm_num) hn + have hjn : j/n ≤ j := (div_le_iff₀ hn0).mpr (by nlinarith) + obtain ⟨h₁,_,h₃⟩ := exponential_tail_absorptions hc hn hp + calc + _ ≤ R*B*p+B*n*sqrt (2*j)*sqrt p := by gcongr + _ = R*B*p+B*sqrt (2*j)*(n*sqrt p) := by ring + _ ≤ R*B*((3/rate)/n)+B*sqrt (2*j)*((8*sqrt 3/rate^2)/n) := by gcongr + _ = _ := by unfold projectedErrorConstant; ring +end SKGap +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/Quadratic.lean b/lean/OAI/Probability/SKGap/Localization/Quadratic.lean new file mode 100644 index 0000000000000000000000000000000000000000..fdfff8b267a7a9d99d9f50122bfdc3406defa1e6 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/Quadratic.lean @@ -0,0 +1,123 @@ +import Mathlib +import OAI.Probability.SKGap.Model + +namespace OAI + +section +noncomputable section +open MeasureTheory ProbabilityTheory InformationTheory Real Set +open scoped NNReal ENNReal +open Filter +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius ENNReal NNReal +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius NNReal +noncomputable section +open MeasureTheory ProbabilityTheory Real Set Filter +open MeasureTheory.Measure +open scoped ENNReal NNReal MeasureTheory Topology +open MeasureTheory +noncomputable section +noncomputable section +open MeasureTheory Set NormedSpace +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius +noncomputable section +open Set Real +open scoped Topology +noncomputable section +open Matrix Set Filter +open scoped Topology Matrix.Norms.Frobenius +namespace SKGap.ComplexSpectral +variable {ι : Type*} [Fintype ι] + +def quadratic (M : Matrix ι ι ℂ) (x : EuclideanSpace ℂ ι) : ℝ := + (dotProduct (star x.ofLp) (M *ᵥ x.ofLp)).re + +def unitSphere (ι : Type*) [Fintype ι] : Set (EuclideanSpace ℂ ι) := Metric.sphere 0 1 + +def lowerRayleigh (M : Matrix ι ι ℂ) : ℝ := sInf (quadratic M '' unitSphere ι) + +lemma continuous_quadratic : + Continuous (fun p : Matrix ι ι ℂ × EuclideanSpace ℂ ι => quadratic p.1 p.2) := by + unfold quadratic dotProduct mulVec + fun_prop + +lemma compact_unitSphere : IsCompact (unitSphere ι) := isCompact_sphere _ _ + +lemma continuous_lowerRayleigh : Continuous (lowerRayleigh (ι := ι)) := + compact_unitSphere.continuous_sInf continuous_quadratic + +lemma quadratic_neg (M : Matrix ι ι ℂ) (x : EuclideanSpace ℂ ι) : + quadratic (-M) x = -quadratic M x := by simp [quadratic,Matrix.neg_mulVec,dotProduct_neg] + +lemma lowerRayleigh_le (M : Matrix ι ι ℂ) {x : EuclideanSpace ℂ ι} + (hx : x ∈ unitSphere ι) : lowerRayleigh M ≤ quadratic M x := by + have hb : BddBelow (quadratic M '' unitSphere ι) := + (compact_unitSphere.image (continuous_quadratic.comp (continuous_const.prodMk continuous_id))).bddBelow + exact csInf_le hb ⟨x,hx,rfl⟩ + +lemma lowerRayleigh_ge [Nonempty ι] {M : Matrix ι ι ℂ} {c : ℝ} + (hc : ∀ x ∈ unitSphere ι, c ≤ quadratic M x) : c ≤ lowerRayleigh M := by + classical + obtain ⟨i⟩ := ‹Nonempty ι› + have hn : (quadratic M '' unitSphere ι).Nonempty := by + refine ⟨quadratic M (EuclideanSpace.single i (1:ℂ)),?_⟩ + exact ⟨_,by simp [unitSphere],rfl⟩ + exact le_csInf hn (by rintro _ ⟨x,hx,rfl⟩; exact hc x hx) + +variable [DecidableEq ι] + +lemma quadratic_eigenvector {M : Matrix ι ι ℂ} (hM : M.IsHermitian) (i : ι) : + quadratic M (hM.eigenvectorBasis i) = hM.eigenvalues i := by + exact (hM.eigenvalues_eq i).symm + +lemma eigenvalue_lower_bound {M : Matrix ι ι ℂ} (hM : M.IsHermitian) (i : ι) : + lowerRayleigh M ≤ hM.eigenvalues i := by + rw [← quadratic_eigenvector hM i] + apply lowerRayleigh_le + simpa only [unitSphere,Metric.mem_sphere,dist_zero_right] using hM.eigenvectorBasis.orthonormal.1 i + +lemma eigenvalue_upper_bound {M : Matrix ι ι ℂ} (hM : M.IsHermitian) (i : ι) : + hM.eigenvalues i ≤ -lowerRayleigh (-M) := by + have hh := lowerRayleigh_le (-M) (x := hM.eigenvectorBasis i) + (by simpa only [unitSphere,Metric.mem_sphere,dist_zero_right] using hM.eigenvectorBasis.orthonormal.1 i) + rw [quadratic_neg,quadratic_eigenvector] at hh + linarith + +lemma spectral_interval_eventually {S : ℝ → Matrix ι ι ℂ} {t lo hi : ℝ} + (hS : ContinuousAt S t) (hself : ∀ s, (S s).IsHermitian) + (hlo : lo < lowerRayleigh (S t)) (hhi : lowerRayleigh (-(S t)) > -hi) : + ∀ᶠ s in 𝓝 t, ∀ i, (hself s).eigenvalues i ∈ Icc lo hi := by + have hl := (continuous_lowerRayleigh.continuousAt.comp hS).eventually (lt_mem_nhds hlo) + have hu := (continuous_lowerRayleigh.continuousAt.comp hS.neg).eventually (lt_mem_nhds hhi) + filter_upwards [hl,hu] with s hs hs' i + refine ⟨hs.le.trans (eigenvalue_lower_bound (hself s) i),?_⟩ + have hh := eigenvalue_upper_bound (hself s) i + change -hi < lowerRayleigh (-(S s)) at hs' + linarith + +end SKGap.ComplexSpectral + +noncomputable section +open Matrix NormedSpace ContinuousLinearMap +open scoped Matrix.Norms.Frobenius + +end +end +end +end +end +end +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/QuadraticCoeff.lean b/lean/OAI/Probability/SKGap/Localization/QuadraticCoeff.lean new file mode 100644 index 0000000000000000000000000000000000000000..7a0a9ccf3fabaf6ed5a18f5227273b4d34910e09 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/QuadraticCoeff.lean @@ -0,0 +1,170 @@ +import Mathlib +import OAI.Probability.SKGap.Matrix.MatrixCoordinates + +namespace OAI + +section +noncomputable section +open MeasureTheory ProbabilityTheory InformationTheory Real Set +open scoped NNReal ENNReal +open Filter +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius ENNReal NNReal +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius NNReal +noncomputable section +open MeasureTheory ProbabilityTheory Real Set Filter +open MeasureTheory.Measure +open scoped ENNReal NNReal MeasureTheory Topology +open MeasureTheory +noncomputable section +noncomputable section +open MeasureTheory Set NormedSpace +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius +noncomputable section +open Set Real +open scoped Topology +noncomputable section +open Matrix Set Filter +open scoped Topology Matrix.Norms.Frobenius +noncomputable section +open Matrix NormedSpace ContinuousLinearMap +open scoped Matrix.Norms.Frobenius +noncomputable section +open Matrix +noncomputable section +open MeasureTheory ProbabilityTheory Real Set +open scoped ENNReal NNReal +noncomputable section +open MeasureTheory ProbabilityTheory InformationTheory Real Set +open scoped NNReal ENNReal +noncomputable section +open scoped BigOperators +open MeasureTheory ProbabilityTheory +namespace SKGap +section GaussianQuadratic +variable {ι : Type*} [Fintype ι] + +def quadraticCoeff (r : ℝ) (w : EuclideanSpace ℝ ι) : MatrixCoordinates ι → ℝ + | Sum.inl (i, k) => Real.sqrt (2 * r) * w i * w k + | Sum.inr _ => 0 + +def linearCoeff (r : ℝ) (w : EuclideanSpace ℝ ι) : MatrixCoordinates ι → ℝ + | Sum.inl _ => 0 + | Sum.inr i => 2 * Real.sqrt r * ‖w‖ * w i + +lemma sum_coord_sq (w : EuclideanSpace ℝ ι) : ∑ i, (w i)^2 = ‖w‖^2 := by + simp only [EuclideanSpace.norm_sq_eq, Real.norm_eq_abs, sq_abs] + +lemma sum_outer_sq (w v : ι → ℝ) : + (∑ i, ∑ k, (w i * w k - v i * v k)^2) = + (∑ i, w i ^ 2)^2 + (∑ i, v i ^ 2)^2 - 2 * (∑ i, w i * v i)^2 := by + simp_rw [show ∀ i k, (w i * w k - v i * v k)^2 = + w i ^ 2 * w k ^ 2 + v i ^ 2 * v k ^ 2 - 2 * (w i * v i) * (w k * v k) by + intros; ring] + simp only [Finset.sum_add_distrib, Finset.sum_sub_distrib, ← Finset.mul_sum, + ← Finset.sum_mul] + ring + +lemma quadraticCoeff_increment (r : ℝ) (hr : 0 ≤ r) (w v : EuclideanSpace ℝ ι) : + (∑ k, (quadraticCoeff r w k - quadraticCoeff r v k)^2) = + 2 * r * (‖w‖^4 + ‖v‖^4 - 2 * (∑ i, w i * v i)^2) := by + rw [Fintype.sum_sum_type] + simp only [quadraticCoeff, sub_self, zero_pow (by norm_num : (2 : ℕ) ≠ 0), + Finset.sum_const_zero, add_zero, Fintype.sum_prod_type] + simp_rw [show ∀ i k, (Real.sqrt (2*r) * w i * w k - + Real.sqrt (2*r) * v i * v k)^2 = 2*r*(w i*w k-v i*v k)^2 by + intro i k + calc + _ = (Real.sqrt (2*r))^2 * (w i*w k-v i*v k)^2 := by ring + _ = _ := by rw [Real.sq_sqrt (by positivity)]] + simp_rw [← Finset.mul_sum] + rw [sum_outer_sq, sum_coord_sq, sum_coord_sq] + ring + +lemma linearCoeff_increment (r : ℝ) (hr : 0 ≤ r) (w v : EuclideanSpace ℝ ι) : + (∑ k, (linearCoeff r w k - linearCoeff r v k)^2) = + 4 * r * (‖w‖^4 + ‖v‖^4 - 2 * ‖w‖ * ‖v‖ * (∑ i, w i * v i)) := by + rw [Fintype.sum_sum_type] + simp only [linearCoeff, sub_self, zero_pow (by norm_num : (2 : ℕ) ≠ 0), + Finset.sum_const_zero, zero_add] + simp_rw [show ∀ i, (2 * Real.sqrt r * ‖w‖ * w i - + 2 * Real.sqrt r * ‖v‖ * v i)^2 = + 4*r*(‖w‖^2*(w i)^2 + ‖v‖^2*(v i)^2 - 2*‖w‖*‖v‖*(w i*v i)) by + intro i + calc + _ = 4*(Real.sqrt r)^2*(‖w‖^2*(w i)^2 + ‖v‖^2*(v i)^2 - + 2*‖w‖*‖v‖*(w i*v i)) := by ring + _ = _ := by rw [Real.sq_sqrt hr]] + simp only [← Finset.mul_sum, Finset.sum_add_distrib, Finset.sum_sub_distrib] + simp only [sum_coord_sq] + ring + +theorem quadratic_linear_increment_difference (r : ℝ) (hr : 0 ≤ r) + (w v : EuclideanSpace ℝ ι) : + (∑ k, (linearCoeff r w k - linearCoeff r v k)^2) - + (∑ k, (quadraticCoeff r w k - quadraticCoeff r v k)^2) = + 2*r*((‖w‖^2 - ‖v‖^2)^2 + + 2*(‖w‖*‖v‖ - ∑ i, w i*v i)^2) := by + rw [linearCoeff_increment r hr, quadraticCoeff_increment r hr] + ring + +theorem quadratic_linear_increment_le (r : ℝ) (hr : 0 ≤ r) + (w v : EuclideanSpace ℝ ι) : + (∑ k, (quadraticCoeff r w k - quadraticCoeff r v k)^2) ≤ + ∑ k, (linearCoeff r w k - linearCoeff r v k)^2 := by + have h := quadratic_linear_increment_difference r hr w v + have : 0 ≤ 2*r*((‖w‖^2 - ‖v‖^2)^2 + + 2*(‖w‖*‖v‖ - ∑ i, w i*v i)^2) := by positivity + linarith + +lemma quadratic_linear_orthogonal (r : ℝ) (w v : EuclideanSpace ℝ ι) : + ∑ k, (linearCoeff r w k - linearCoeff r v k) * + (quadraticCoeff r w k - quadraticCoeff r v k) = 0 := by + rw [Fintype.sum_sum_type] + simp only [linearCoeff, quadraticCoeff, sub_self, zero_mul, mul_zero, + Finset.sum_const_zero, add_zero] + +omit [Fintype ι] in +lemma continuous_quadraticCoeff (r : ℝ) : Continuous (quadraticCoeff (ι := ι) r) := by + apply continuous_pi + intro k + cases k with + | inl ik => + exact ((continuous_const.mul (PiLp.continuous_apply 2 (fun _ : ι => ℝ) ik.1)).mul + (PiLp.continuous_apply 2 (fun _ : ι => ℝ) ik.2)) + | inr i => exact continuous_const + +lemma continuous_linearCoeff (r : ℝ) : Continuous (linearCoeff (ι := ι) r) := by + apply continuous_pi + intro k + cases k with + | inl ik => exact continuous_const + | inr i => exact (continuous_const.mul continuous_norm).mul (PiLp.continuous_apply 2 (fun _ : ι => ℝ) i) + +end GaussianQuadratic +end SKGap + +end +end +end +end +end +end +end +end +end +end +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/QuenchedHelpers.lean b/lean/OAI/Probability/SKGap/Localization/QuenchedHelpers.lean new file mode 100644 index 0000000000000000000000000000000000000000..c1c005996c6e9578e4307e549cd7e379080c50f5 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/QuenchedHelpers.lean @@ -0,0 +1,96 @@ +import Mathlib +import OAI.Probability.SKGap.Model + +namespace OAI + +namespace SKGap.FullMain +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology ENNReal NNReal BigOperators +noncomputable section + +def Whp (β : ℝ) (P : ∀n,Disorder n→Prop) : Prop := + Tendsto (fun n=>disorderLaw β n {g | ¬P n g}) atTop (𝓝 0) + +lemma whp_iff_real (β : ℝ) (P : ∀n,Disorder n→Prop) : + Whp β P ↔ Tendsto (fun n=>(disorderLaw β n).real {g | ¬P n g}) atTop (𝓝 0) := by + let (n : ℕ) : IsProbabilityMeasure (disorderLaw β n) := by unfold disorderLaw; infer_instance + constructor + · intro h + simpa only [Measure.real, ENNReal.toReal_zero, Function.comp_def] using (ENNReal.continuousAt_toReal ENNReal.zero_ne_top).tendsto.comp h + · intro h + have H:=(ENNReal.continuous_ofReal.tendsto 0).comp h + change Tendsto (fun n=>disorderLaw β n {g | ¬P n g}) atTop (𝓝 0) + simpa only [Function.comp_def,Measure.real,ENNReal.ofReal_toReal (measure_ne_top _ _),ENNReal.ofReal_zero] using H + +lemma Whp.mono {β : ℝ} {P Q : ∀n,Disorder n→Prop} (hP : Whp β P) + (hPQ : ∀ᶠ n : ℕ in atTop,∀g,P n g→Q n g) : Whp β Q := by + apply tendsto_of_tendsto_of_tendsto_of_le_of_le' tendsto_const_nhds hP + (Eventually.of_forall (fun _=>bot_le)) + filter_upwards [hPQ] with n hn + apply measure_mono + intro g hg hp + exact hg (hn g hp) + +lemma Whp.of_eventually {β : ℝ} {P : ℕ→Prop} (hP : ∀ᶠ n : ℕ in atTop,P n) : + Whp β (fun n _=>P n) := by + apply Tendsto.congr' _ tendsto_const_nhds + filter_upwards [hP] with n hn + simp [hn] + +lemma Whp.and {β : ℝ} {P Q : ∀n,Disorder n→Prop} (hP : Whp β P) (hQ : Whp β Q) : + Whp β (fun n g=>P n g ∧ Q n g) := by + classical + have H:=hP.add hQ + rw [add_zero] at H + apply tendsto_of_tendsto_of_tendsto_of_le_of_le' tendsto_const_nhds H + (Eventually.of_forall (fun _=>bot_le)) + apply Eventually.of_forall + intro n + have he : {g:Disorder n | ¬(P n g ∧ Q n g)}={g | ¬P n g}∪{g | ¬Q n g} := by + ext g + simp only [mem_ofPred_eq,mem_union] + tauto + rw [he] + exact measure_union_le _ _ + +lemma whp_finset {β : ℝ} {ι : Type*} (s : Finset ι) (P : ι→∀n,Disorder n→Prop) + (hP : ∀i∈s,Whp β (P i)) : Whp β (fun n g=>∀i∈s,P i n g) := by + classical + induction s using Finset.induction_on with + | empty => + apply Whp.mono (Whp.of_eventually (β:=β) (P:=fun _=>True) (Eventually.of_forall (fun _=>True.intro))) + exact Eventually.of_forall (fun n g _=>by simp) + | @insert i s hi ih => + have H := (hP i (by simp)).and (ih (fun j hj=>hP j (by simp [hj]))) + exact H.mono (Eventually.of_forall (fun n g hg=>by simpa only [Finset.mem_insert,forall_eq_or_imp] using hg)) + +lemma whp_forall_lt {β : ℝ} (r : ℕ) (P : ℕ→∀n,Disorder n→Prop) + (hP : ∀k∀kdisorderLaw β n {g | P n g}) atTop (𝓝 1) := by + classical + let (n : ℕ) : IsProbabilityMeasure (disorderLaw β n) := by unfold disorderLaw; infer_instance + have H := (whp_iff_real β P).mp hP + have H' := (tendsto_const_nhds (x:=(1:ℝ))).sub H + rw [sub_zero] at H' + have ht : Tendsto (fun n=>(disorderLaw β n).real {g | P n g}) atTop (𝓝 1) := by + apply tendsto_of_tendsto_of_tendsto_of_le_of_le H' tendsto_const_nhds + · intro n + have hs := measureReal_union_le (μ:=disorderLaw β n) {g | P n g} {g | ¬P n g} + have he : ({g:Disorder n | P n g}∪{g | ¬P n g})=univ := by + ext g + simp only [mem_ofPred_eq,mem_union,mem_univ] + tauto + rw [he,probReal_univ] at hs + linarith + · intro n + exact measureReal_le_one + have hh:=(ENNReal.continuous_ofReal.tendsto 1).comp ht + simpa only [Function.comp_def,Measure.real,ENNReal.ofReal_toReal (measure_ne_top _ _),ENNReal.ofReal_one] using hh + +end +end SKGap.FullMain + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/QueryColumn.lean b/lean/OAI/Probability/SKGap/Localization/QueryColumn.lean new file mode 100644 index 0000000000000000000000000000000000000000..ca46fb5e010b177345b0547d35dfca242df5dc25 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/QueryColumn.lean @@ -0,0 +1,296 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.StandardArrayLaw + +namespace OAI + +section +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open scoped BigOperators +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise +namespace SKGapCutoff.Regression + +lemma clm_pi_expansion {ι : Type*} [Fintype ι] [DecidableEq ι] + (L : (ι → ℝ) →L[ℝ] ℝ) (v : ι → ℝ) : + L v = ∑ i, L (Pi.single i 1) * v i := by + conv_lhs => rw [← LinearMap.sum_single_apply (fun _ : ι => ℝ) v] + rw [map_sum] + apply Finset.sum_congr rfl + intro i _ + have he : Pi.single i (v i) = v i • Pi.single i (1 : ℝ) := by + ext j + by_cases h : i = j <;> simp [h] + rw [he, map_smul] + simp only [smul_eq_mul, mul_comm] + +lemma gaussian_mean_linear {ι Ω : Type*} [Fintype ι] [DecidableEq ι] + [MeasurableSpace Ω] {μ : Measure Ω} {X : Ω → ι → ℝ} + (hX : HasGaussianLaw X μ) (L : (ι → ℝ) →L[ℝ] ℝ) : + (∫ ω, L (X ω) ∂μ) = ∑ i, L (Pi.single i 1) * ∫ ω, X ω i ∂μ := by + have he : (fun ω => L (X ω)) = (fun ω => ∑ i, L (Pi.single i 1) * X ω i) := + funext fun ω => clm_pi_expansion L (X ω) + rw [he] + rw [integral_finsetSum] + · simp only [integral_const_mul] + · exact fun i _ => (hX.eval i).integrable.const_mul _ + +lemma gaussian_variance_linear {ι Ω : Type*} [Fintype ι] [DecidableEq ι] + [MeasurableSpace Ω] {μ : Measure Ω} {X : Ω → ι → ℝ} + (hX : HasGaussianLaw X μ) (L : (ι → ℝ) →L[ℝ] ℝ) : + Var[fun ω => L (X ω); μ] = + ∑ i, ∑ j, L (Pi.single i 1) * L (Pi.single j 1) * + cov[fun ω => X ω i, fun ω => X ω j; μ] := by + let := hX.isProbabilityMeasure + rw [← covariance_self (hX.map_fun L).aemeasurable] + have he : (fun ω => L (X ω)) = (fun ω => ∑ i, L (Pi.single i 1) * X ω i) := + funext fun ω => clm_pi_expansion L (X ω) + rw [he] + rw [covariance_fun_sum_fun_sum] + · simp_rw [covariance_const_mul_left, covariance_const_mul_right] + apply Finset.sum_congr rfl + intro i _ + apply Finset.sum_congr rfl + intro j _ + ring + · exact fun i => (hX.eval i).memLp_two.const_mul _ + · exact fun i => (hX.eval i).memLp_two.const_mul _ + +lemma gaussian_vector_law_ext {ι Ω Ω' : Type*} [Fintype ι] [DecidableEq ι] + [MeasurableSpace Ω] [MeasurableSpace Ω'] {μ : Measure Ω} {ν : Measure Ω'} + {X : Ω → ι → ℝ} {Y : Ω' → ι → ℝ} + (hX : HasGaussianLaw X μ) (hY : HasGaussianLaw Y ν) + (hm : ∀ i, (∫ ω, X ω i ∂μ) = ∫ ω, Y ω i ∂ν) + (hc : ∀ i j, cov[fun ω => X ω i, fun ω => X ω j; μ] = + cov[fun ω => Y ω i, fun ω => Y ω j; ν]) : μ.map X = ν.map Y := by + let := hX.isGaussian_map + let := hY.isGaussian_map + apply Measure.ext_of_charFunDual + funext L + rw [hX.charFunDual_map_eq_fun L, hY.charFunDual_map_eq_fun L, + gaussian_mean_linear hX L, gaussian_mean_linear hY L, + gaussian_variance_linear hX L, gaussian_variance_linear hY L] + simp_rw [hm, hc] + +lemma coordinate_mean {ι : Type*} [Fintype ι] (i : ι) : + (∫ g : ι → ℝ, g i ∂standardArrayLaw ι) = 0 := by + rw [(coordinate_hasLaw i).integral_eq, integral_id_gaussianReal] + +lemma goe_entry_mean {n : ℕ} (i j : Fin n) : + (∫ g : (Fin n × Fin n) → ℝ, goe g i j ∂standardArrayLaw (Fin n × Fin n)) = 0 := by + simp only [goe, integral_div] + rw [integral_add (coordinate_hasLaw (i,j)).hasGaussianLaw.integrable + (coordinate_hasLaw (j,i)).hasGaussianLaw.integrable] + simp only [coordinate_mean, add_zero, zero_div] + +lemma sandwich_entry_mean {n r s : ℕ} + (A : Matrix (Fin r) (Fin n) ℝ) (B : Matrix (Fin n) (Fin s) ℝ) + (i : Fin r) (j : Fin s) : + (∫ g : (Fin n × Fin n) → ℝ, (A * goe g * B) i j + ∂standardArrayLaw (Fin n × Fin n)) = 0 := by + have hterm (k l : Fin n) : Integrable (fun g : (Fin n × Fin n) → ℝ => + A i l * goe g l k * B k j) (standardArrayLaw (Fin n × Fin n)) := + ((goe_entry_memLp l k).integrable (by norm_num)).const_mul _ |>.mul_const _ + have he (g : (Fin n × Fin n) → ℝ) : (A * goe g * B) i j = + ∑ k, ∑ l, A i l * goe g l k * B k j := by + simp [Matrix.mul_apply, Finset.sum_mul] + simp_rw [he] + rw [integral_finsetSum Finset.univ (fun k _ => integrable_finsetSum Finset.univ (fun l _ => hterm k l))] + have inner (k : Fin n) : (∫ g : (Fin n × Fin n) → ℝ, + ∑ l, A i l * goe g l k * B k j ∂standardArrayLaw (Fin n × Fin n)) = 0 := by + rw [integral_finsetSum Finset.univ (fun l _ => hterm k l)] + simp only [integral_mul_const, integral_const_mul, goe_entry_mean, mul_zero, + zero_mul, Finset.sum_const_zero] + simp only [inner, Finset.sum_const_zero] + +def queryColumn {n : ℕ} (q : Fin n → ℝ) : Matrix (Fin n) (Fin 1) ℝ := fun i _ => q i + +def queryComplement {n : ℕ} (P : Matrix (Fin n) (Fin n) ℝ) (q : Fin n → ℝ) := + P - queryColumn q * (queryColumn q)ᵀ + +lemma queryColumn_unit {n : ℕ} (q : Fin n → ℝ) (hq : ∑ i, q i ^ 2 = 1) : + (queryColumn q)ᵀ * queryColumn q = 1 := by + ext i j + have hi : i = 0 := Subsingleton.elim _ _ + have hj : j = 0 := Subsingleton.elim _ _ + subst i; subst j + simpa [Matrix.mul_apply, queryColumn, pow_two] using hq + +lemma queryComplement_symmetric {n : ℕ} (P : Matrix (Fin n) (Fin n) ℝ) + (hP : Pᵀ = P) (q : Fin n → ℝ) : (queryComplement P q)ᵀ = queryComplement P q := by + simp [queryComplement, hP] + +lemma queryComplement_mul_column {n : ℕ} (P : Matrix (Fin n) (Fin n) ℝ) + (q : Fin n → ℝ) (hq : ∑ i, q i ^ 2 = 1) (hPq : P * queryColumn q = queryColumn q) : + queryComplement P q * queryColumn q = 0 := by + simp [queryComplement, Matrix.sub_mul, Matrix.mul_assoc, queryColumn_unit q hq, hPq] + +lemma queryComplement_sq {n : ℕ} (P : Matrix (Fin n) (Fin n) ℝ) + (hP : Pᵀ = P) (hPP : P*P = P) (q : Fin n → ℝ) + (hq : ∑ i, q i ^ 2 = 1) (hPq : P * queryColumn q = queryColumn q) : + queryComplement P q * queryComplement P q = queryComplement P q := by + have hqP : (queryColumn q)ᵀ * P = (queryColumn q)ᵀ := by + simpa [Matrix.transpose_mul, hP] using congrArg Matrix.transpose hPq + simp only [queryComplement, Matrix.sub_mul, Matrix.mul_sub] + rw [hPP, ← Matrix.mul_assoc P, hPq, Matrix.mul_assoc _ _ P, hqP] + rw [Matrix.mul_assoc (queryColumn q), ← Matrix.mul_assoc (queryColumn q)ᵀ, + queryColumn_unit q hq, Matrix.one_mul] + abel + +noncomputable def queryInnovation {n : ℕ} (P : Matrix (Fin n) (Fin n) ℝ) + (q : Fin n → ℝ) (g : (Fin n ⊕ Unit) → ℝ) (i : Fin n) : ℝ := + (∑ k, queryComplement P q i k * g (Sum.inl k) + + Real.sqrt 2 * q i * g (Sum.inr ())) / Real.sqrt n + +noncomputable def queryInnovationCoefficient {n : ℕ} + (P : Matrix (Fin n) (Fin n) ℝ) (q : Fin n → ℝ) (i : Fin n) : (Fin n ⊕ Unit) → ℝ := + Sum.elim (fun k => queryComplement P q i k / Real.sqrt n) + (fun _ => Real.sqrt 2 * q i / Real.sqrt n) + +lemma queryInnovation_as_linearTest {n : ℕ} (P : Matrix (Fin n) (Fin n) ℝ) + (q : Fin n → ℝ) (g : (Fin n ⊕ Unit) → ℝ) (i : Fin n) : + queryInnovation P q g i = linearTest (queryInnovationCoefficient P q i) g := by + simp [queryInnovation, queryInnovationCoefficient, Fintype.sum_sum_type, + add_div, ← Finset.sum_div, div_mul_eq_mul_div] + +lemma queryInnovation_gaussian {n : ℕ} (P : Matrix (Fin n) (Fin n) ℝ) + (q : Fin n → ℝ) : + HasGaussianLaw (queryInnovation P q) (standardArrayLaw (Fin n ⊕ Unit)) := by + have h := coordinates_gaussian.map_fun (ContinuousLinearMap.pi fun i => + linearTest (queryInnovationCoefficient P q i)) + apply h.congr + filter_upwards [] with g + funext i + exact (queryInnovation_as_linearTest P q g i).symm + +lemma queryInnovation_mean {n : ℕ} (P : Matrix (Fin n) (Fin n) ℝ) + (q : Fin n → ℝ) (i : Fin n) : + (∫ g, queryInnovation P q g i ∂standardArrayLaw (Fin n ⊕ Unit)) = 0 := by + simp_rw [queryInnovation_as_linearTest] + rw [gaussian_mean_linear coordinates_gaussian] + simp only [coordinate_mean, mul_zero, Finset.sum_const_zero] + +lemma queryInnovation_covariance {n : ℕ} (hn : 0 < n) + (P : Matrix (Fin n) (Fin n) ℝ) (hP : Pᵀ = P) (hPP : P*P = P) + (q : Fin n → ℝ) (hq : ∑ i, q i ^ 2 = 1) (hPq : P * queryColumn q = queryColumn q) + (i j : Fin n) : + cov[fun g => queryInnovation P q g i, fun g => queryInnovation P q g j; + standardArrayLaw (Fin n ⊕ Unit)] = (P i j + q i * q j) / n := by + simp_rw [queryInnovation_as_linearTest, linearTest_apply] + rw [linearTest_covariance] + have hnR : (0 : ℝ) < n := by exact_mod_cast hn + have hsq : Real.sqrt (n : ℝ) ^ 2 = n := Real.sq_sqrt hnR.le + have htwo : Real.sqrt 2 ^ 2 = (2 : ℝ) := Real.sq_sqrt (by norm_num) + have hR : ∑ k, queryComplement P q i k * queryComplement P q j k = + P i j - q i * q j := by + have he := congrArg (fun M : Matrix (Fin n) (Fin n) ℝ => M i j) + (queryComplement_sq P hP hPP q hq hPq) + have hs := queryComplement_symmetric P hP q + have hs' (k : Fin n) : queryComplement P q k j = queryComplement P q j k := + congrArg (fun M : Matrix (Fin n) (Fin n) ℝ => M j k) hs + simp only [Matrix.mul_apply] at he + have he' : (∑ k, queryComplement P q i k * queryComplement P q j k) = + queryComplement P q i j := by + calc + _ = ∑ k, queryComplement P q i k * queryComplement P q k j := by + apply Finset.sum_congr rfl + intro k _ + rw [hs' k] + _ = _ := he + simpa only [queryComplement, Matrix.sub_apply, + queryColumn, Matrix.mul_apply, Matrix.transpose_apply, Fin.sum_univ_one] using he' + simp only [Fintype.sum_sum_type, queryInnovationCoefficient, Sum.elim_inl, + Sum.elim_inr, Fintype.sum_unique] + simp only [div_mul_div_comm, ← pow_two, hsq, ← Finset.sum_div] + rw [hR] + have ht : Real.sqrt 2 * q i * (Real.sqrt 2 * q j) = 2 * q i * q j := by + calc + _ = (Real.sqrt 2)^2 * (q i * q j) := by ring + _ = _ := by rw [htwo]; ring + rw [ht] + ring + +noncomputable def queryAnswerCLM {n : ℕ} (P : Matrix (Fin n) (Fin n) ℝ) + (q : Fin n → ℝ) : ((Fin n × Fin n) → ℝ) →L[ℝ] (Fin n → ℝ) := + ContinuousLinearMap.pi fun i => ((entryCLM i 0).comp + (sandwichCLM P (queryColumn q))).comp (goeCLM n) + +lemma queryAnswerCLM_apply {n : ℕ} (P : Matrix (Fin n) (Fin n) ℝ) + (q : Fin n → ℝ) (g : (Fin n × Fin n) → ℝ) : + queryAnswerCLM P q g = fun i => (P * goe g * queryColumn q) i 0 := by + simp [queryAnswerCLM] + +lemma queryAnswer_covariance {n : ℕ} (hn : 0 < n) + (P : Matrix (Fin n) (Fin n) ℝ) (hP : Pᵀ = P) (hPP : P*P = P) + (q : Fin n → ℝ) (hq : ∑ i, q i ^ 2 = 1) (hPq : P * queryColumn q = queryColumn q) + (i j : Fin n) : + cov[fun g : (Fin n × Fin n) → ℝ => (P * goe g * queryColumn q) i 0, + fun g => (P * goe g * queryColumn q) j 0; standardArrayLaw (Fin n × Fin n)] = + (P i j + q i * q j) / n := by + rw [goe_sandwich_covariance hn] + simp [queryColumn_unit q hq, hP, hPP, hPq, queryColumn, mul_comm] + +lemma query_innovation_law {n : ℕ} (hn : 0 < n) + (P : Matrix (Fin n) (Fin n) ℝ) (hP : Pᵀ = P) (hPP : P*P = P) + (q : Fin n → ℝ) (hq : ∑ i, q i ^ 2 = 1) (hPq : P * queryColumn q = queryColumn q) : + (standardArrayLaw (Fin n × Fin n)).map + (fun g => fun i => (P * goe g * queryColumn q) i 0) = + (standardArrayLaw (Fin n ⊕ Unit)).map (queryInnovation P q) := by + apply gaussian_vector_law_ext + ((coordinates_gaussian.map_fun (queryAnswerCLM P q)).congr + (Filter.Eventually.of_forall (queryAnswerCLM_apply P q))) + (queryInnovation_gaussian P q) + · intro i + rw [sandwich_entry_mean, queryInnovation_mean] + · intro i j + rw [queryAnswer_covariance hn P hP hPP q hq hPq, + queryInnovation_covariance hn P hP hPP q hq hPq] + +noncomputable def freshRegressionCLM {n : ℕ} (P : Matrix (Fin n) (Fin n) ℝ) + (q : Fin n → ℝ) : ((Fin n × Fin n) → ℝ) →L[ℝ] + (((Fin n × Fin n) → ℝ) × (Fin n → ℝ)) := + (ContinuousLinearMap.pi fun p : Fin n × Fin n => ((entryCLM p.1 p.2).comp + (sandwichCLM (queryComplement P q) (queryComplement P q))).comp (goeCLM n)).prod + (queryAnswerCLM P q) + +lemma freshRegressionCLM_apply {n : ℕ} (P : Matrix (Fin n) (Fin n) ℝ) + (q : Fin n → ℝ) (g : (Fin n × Fin n) → ℝ) : + freshRegressionCLM P q g = + (fun p : Fin n × Fin n => (queryComplement P q * goe g * queryComplement P q) p.1 p.2, + fun i => (P * goe g * queryColumn q) i 0) := by + simp [freshRegressionCLM, queryAnswerCLM_apply] + +lemma fresh_residual_independent {n : ℕ} (hn : 0 < n) + (P : Matrix (Fin n) (Fin n) ℝ) (hP : Pᵀ = P) + (q : Fin n → ℝ) (hq : ∑ i, q i ^ 2 = 1) (hPq : P * queryColumn q = queryColumn q) : + IndepFun (fun g : (Fin n × Fin n) → ℝ => fun p : Fin n × Fin n => + (queryComplement P q * goe g * queryComplement P q) p.1 p.2) + (fun g => fun i => (P * goe g * queryColumn q) i 0) + (standardArrayLaw (Fin n × Fin n)) := by + have hXY := (coordinates_gaussian.map_fun (freshRegressionCLM P q)).congr + (Filter.Eventually.of_forall (freshRegressionCLM_apply P q)) + apply hXY.indepFun_of_covariance_eval + intro p i + rw [goe_sandwich_covariance hn] + simp [queryComplement_symmetric P hP q, queryComplement_mul_column P q hq hPq] + +end SKGapCutoff.Regression + +open scoped BigOperators + +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/QueryResidual.lean b/lean/OAI/Probability/SKGap/Localization/QueryResidual.lean new file mode 100644 index 0000000000000000000000000000000000000000..c32a47785dc8fba1c5725a7104de64a374b4b401 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/QueryResidual.lean @@ -0,0 +1,294 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.QueryColumn + +namespace OAI + +section +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open scoped BigOperators +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open scoped BigOperators +open scoped BigOperators NNReal ENNReal +open MeasureTheory Metric Set +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators NNReal ENNReal Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Set +namespace SKGapCutoff.Regression + +local instance adaptiveMatrixMeasurable {n m : ℕ} : MeasurableSpace (Matrix (Fin n) (Fin m) ℝ) := + inferInstanceAs (MeasurableSpace (Fin n → Fin m → ℝ)) + +local instance adaptiveMatrixBorel {n m : ℕ} : BorelSpace (Matrix (Fin n) (Fin m) ℝ) := + inferInstanceAs (BorelSpace (Fin n → Fin m → ℝ)) + +lemma map_prod_section_congr {H A B C : Type*} + [MeasurableSpace H] [MeasurableSpace A] [MeasurableSpace B] [MeasurableSpace C] + (ρ : Measure H) (μ : Measure A) (ν : Measure B) [SFinite μ] [SFinite ν] + (f : H × A → C) (g : H × B → C) (hf : Measurable f) (hg : Measurable g) + (hfg : ∀ h, μ.map (fun a => f (h,a)) = ν.map (fun b => g (h,b))) : + (ρ.prod μ).map f = (ρ.prod ν).map g := by + ext s hs + rw [Measure.map_apply hf hs, Measure.map_apply hg hs, + Measure.prod_apply (hf hs), Measure.prod_apply (hg hs)] + apply lintegral_congr + intro h + have hh := congrArg (fun m : Measure C => m s) (hfg h) + exact (Measure.map_apply (hf.comp measurable_prodMk_left) hs).symm.trans + (hh.trans (Measure.map_apply (hg.comp measurable_prodMk_left) hs)) + +noncomputable def queryResidual {n : ℕ} (P : Matrix (Fin n) (Fin n) ℝ) + (q : Fin n → ℝ) (g : (Fin n × Fin n) → ℝ) : (Fin n × Fin n) → ℝ := + fun p => (queryComplement P q * goe g * queryComplement P q) p.1 p.2 + +noncomputable def queryAnswer {n : ℕ} (P : Matrix (Fin n) (Fin n) ℝ) + (q : Fin n → ℝ) (g : (Fin n × Fin n) → ℝ) : Fin n → ℝ := + fun i => (P * goe g * queryColumn q) i 0 + +lemma queryComplement_apply {n : ℕ} (P : Matrix (Fin n) (Fin n) ℝ) + (q : Fin n → ℝ) (i j : Fin n) : queryComplement P q i j = P i j - q i*q j := by + simp [queryComplement, queryColumn, Matrix.mul_apply] + +@[fun_prop] lemma measurable_queryResidual {n : ℕ} : + Measurable (fun x : (Matrix (Fin n) (Fin n) ℝ × (Fin n → ℝ)) × + ((Fin n × Fin n) → ℝ) => queryResidual x.1.1 x.1.2 x.2) := by + apply Measurable.of_eval + intro p + simp only [queryResidual, Matrix.mul_apply, queryComplement_apply, goe] + fun_prop + +@[fun_prop] lemma measurable_queryAnswer {n : ℕ} : + Measurable (fun x : (Matrix (Fin n) (Fin n) ℝ × (Fin n → ℝ)) × + ((Fin n × Fin n) → ℝ) => queryAnswer x.1.1 x.1.2 x.2) := by + apply Measurable.of_eval + intro i + simp only [queryAnswer, Matrix.mul_apply, queryColumn, goe] + fun_prop + +@[fun_prop] lemma measurable_queryInnovation {n : ℕ} : + Measurable (fun x : (Matrix (Fin n) (Fin n) ℝ × (Fin n → ℝ)) × + ((Fin n ⊕ Unit) → ℝ) => queryInnovation x.1.1 x.1.2 x.2) := by + apply Measurable.of_eval + intro i + simp only [queryInnovation, queryComplement_apply] + fun_prop + +lemma measurable_queryResidual_comp {n : ℕ} {Ω : Type*} [MeasurableSpace Ω] + (P : Ω → Matrix (Fin n) (Fin n) ℝ) (q : Ω → Fin n → ℝ) + (g : Ω → (Fin n × Fin n) → ℝ) + (hP : Measurable P) (hq : Measurable q) (hg : Measurable g) : + Measurable (fun ω => queryResidual (P ω) (q ω) (g ω)) := by + apply Measurable.of_eval + intro p + simp only [queryResidual, Matrix.mul_apply, queryComplement_apply, goe] + have hP' : Measurable (fun ω => fun i j => P ω i j) := hP + fun_prop + +lemma measurable_queryAnswer_comp {n : ℕ} {Ω : Type*} [MeasurableSpace Ω] + (P : Ω → Matrix (Fin n) (Fin n) ℝ) (q : Ω → Fin n → ℝ) + (g : Ω → (Fin n × Fin n) → ℝ) + (hP : Measurable P) (hq : Measurable q) (hg : Measurable g) : + Measurable (fun ω => queryAnswer (P ω) (q ω) (g ω)) := by + apply Measurable.of_eval + intro i + simp only [queryAnswer, Matrix.mul_apply, queryColumn, goe] + have hP' : Measurable (fun ω => fun i j => P ω i j) := hP + fun_prop + +lemma measurable_queryInnovation_comp {n : ℕ} {Ω : Type*} [MeasurableSpace Ω] + (P : Ω → Matrix (Fin n) (Fin n) ℝ) (q : Ω → Fin n → ℝ) + (g : Ω → (Fin n ⊕ Unit) → ℝ) + (hP : Measurable P) (hq : Measurable q) (hg : Measurable g) : + Measurable (fun ω => queryInnovation (P ω) (q ω) (g ω)) := by + apply Measurable.of_eval + intro i + simp only [queryInnovation, queryComplement_apply] + have hP' : Measurable (fun ω => fun i j => P ω i j) := hP + fun_prop + +lemma queryResidual_measurable {n : ℕ} (P : Matrix (Fin n) (Fin n) ℝ) + (q : Fin n → ℝ) : Measurable (queryResidual P q) := by + exact measurable_queryResidual_comp (fun _ => P) (fun _ => q) id + measurable_const measurable_const measurable_id + +lemma queryAnswer_measurable {n : ℕ} (P : Matrix (Fin n) (Fin n) ℝ) + (q : Fin n → ℝ) : Measurable (queryAnswer P q) := by + exact measurable_queryAnswer_comp (fun _ => P) (fun _ => q) id + measurable_const measurable_const measurable_id + +lemma queryInnovation_measurable {n : ℕ} (P : Matrix (Fin n) (Fin n) ℝ) + (q : Fin n → ℝ) : Measurable (queryInnovation P q) := by + exact measurable_queryInnovation_comp (fun _ => P) (fun _ => q) id + measurable_const measurable_const measurable_id + +lemma query_joint_law {n : ℕ} (hn : 0 < n) + (P : Matrix (Fin n) (Fin n) ℝ) (hP : Pᵀ = P) (hPP : P*P = P) + (q : Fin n → ℝ) (hq : ∑ i, q i ^ 2 = 1) (hPq : P * queryColumn q = queryColumn q) : + (standardArrayLaw (Fin n × Fin n)).map (fun g => + (queryResidual P q g, queryAnswer P q g)) = + ((standardArrayLaw (Fin n × Fin n)).prod (standardArrayLaw (Fin n ⊕ Unit))).map + (fun z => (queryResidual P q z.1, queryInnovation P q z.2)) := by + rw [(fresh_residual_independent hn P hP q hq hPq).map_prod_eq_prod_map_map + (queryResidual_measurable P q).aemeasurable (queryAnswer_measurable P q).aemeasurable] + rw [show (standardArrayLaw (Fin n × Fin n)).map (queryAnswer P q) = + (standardArrayLaw (Fin n ⊕ Unit)).map (queryInnovation P q) from + query_innovation_law hn P hP hPP q hq hPq] + exact Measure.map_prod_map _ _ (queryResidual_measurable P q) + (queryInnovation_measurable P q) + +theorem adaptive_query_joint_law {n : ℕ} (hn : 0 < n) {H : Type*} + [MeasurableSpace H] (ρ : Measure H) + (P : H → Matrix (Fin n) (Fin n) ℝ) (q : H → Fin n → ℝ) + (hPm : Measurable P) (hqm : Measurable q) + (hP : ∀ h, (P h)ᵀ = P h) (hPP : ∀ h, P h * P h = P h) + (hq : ∀ h, ∑ i, q h i ^ 2 = 1) + (hPq : ∀ h, P h * queryColumn (q h) = queryColumn (q h)) : + (ρ.prod (standardArrayLaw (Fin n × Fin n))).map (fun z => + (z.1, queryResidual (P z.1) (q z.1) z.2, queryAnswer (P z.1) (q z.1) z.2)) = + (ρ.prod ((standardArrayLaw (Fin n × Fin n)).prod + (standardArrayLaw (Fin n ⊕ Unit)))).map (fun z => + (z.1, queryResidual (P z.1) (q z.1) z.2.1, + queryInnovation (P z.1) (q z.1) z.2.2)) := by + have hmL : Measurable (fun z : H × ((Fin n × Fin n) → ℝ) => + (z.1, queryResidual (P z.1) (q z.1) z.2, queryAnswer (P z.1) (q z.1) z.2)) := + measurable_fst.prodMk ((measurable_queryResidual_comp _ _ _ + (hPm.comp measurable_fst) (hqm.comp measurable_fst) measurable_snd).prodMk + (measurable_queryAnswer_comp _ _ _ (hPm.comp measurable_fst) + (hqm.comp measurable_fst) measurable_snd)) + have hmR : Measurable (fun z : H × (((Fin n × Fin n) → ℝ) × ((Fin n ⊕ Unit) → ℝ)) => + (z.1, queryResidual (P z.1) (q z.1) z.2.1, + queryInnovation (P z.1) (q z.1) z.2.2)) := + measurable_fst.prodMk ((measurable_queryResidual_comp _ _ _ + (hPm.comp measurable_fst) (hqm.comp measurable_fst) measurable_snd.fst).prodMk + (measurable_queryInnovation_comp _ _ _ (hPm.comp measurable_fst) + (hqm.comp measurable_fst) measurable_snd.snd)) + apply map_prod_section_congr _ _ _ _ _ hmL hmR + intro h + have hh := congrArg (Measure.map (Prod.mk h)) + (query_joint_law hn (P h) (hP h) (hPP h) (q h) (hq h) (hPq h)) + have hm1 := (queryResidual_measurable (P h) (q h)).prodMk + (queryAnswer_measurable (P h) (q h)) + have hm2 : Measurable (fun z : (((Fin n × Fin n) → ℝ) × ((Fin n ⊕ Unit) → ℝ)) => + (queryResidual (P h) (q h) z.1, queryInnovation (P h) (q h) z.2)) := + ((queryResidual_measurable (P h) (q h)).comp measurable_fst).prodMk + ((queryInnovation_measurable (P h) (q h)).comp measurable_snd) + rw [Measure.map_map measurable_prodMk_left hm1, + Measure.map_map measurable_prodMk_left hm2] at hh + exact hh + +lemma map_triple_exchange {H A B C : Type*} + [MeasurableSpace H] [MeasurableSpace A] [MeasurableSpace B] [MeasurableSpace C] + (ρ : Measure H) (μ : Measure A) (ν : Measure B) + [SFinite ρ] [SFinite μ] [SFinite ν] + (f : H × (A × B) → C) (hf : Measurable f) : + (ρ.prod (μ.prod ν)).map f = + ((ρ.prod ν).prod μ).map (fun z => f (z.1.1, z.2, z.1.2)) := by + calc + _ = (ρ.prod (ν.prod μ)).map (fun z => f (z.1, z.2.2, z.2.1)) := by + apply map_prod_section_congr ρ (μ.prod ν) (ν.prod μ) _ _ hf + (hf.comp (measurable_fst.prodMk + (measurable_snd.snd.prodMk measurable_snd.fst))) + intro h + have hm : Measurable (fun z : B × A => f (h,z.2,z.1)) := + hf.comp (measurable_const.prodMk (measurable_snd.prodMk measurable_fst)) + have hh := congrArg (Measure.map (fun z : B × A => f (h,z.2,z.1))) + (Measure.prod_swap (μ := μ) (ν := ν)) + simpa only [Measure.map_map hm measurable_swap, Function.comp_def, + Prod.fst_swap, Prod.snd_swap] using hh + _ = _ := by + rw [← Measure.prodAssoc_prod] + exact Measure.map_map + (show Measurable (fun z : H × (B × A) => f (z.1,z.2.2,z.2.1)) from + hf.comp (measurable_fst.prodMk (measurable_snd.snd.prodMk measurable_snd.fst))) + MeasurableEquiv.prodAssoc.measurable + +noncomputable def answerHistoryLaw {n : ℕ} {H : Type*} [MeasurableSpace H] + (ρ : Measure H) (P : H → Matrix (Fin n) (Fin n) ℝ) (q : H → Fin n → ℝ) : + Measure (H × (Fin n → ℝ)) := + (ρ.prod (standardArrayLaw (Fin n ⊕ Unit))).map + (fun z => (z.1, queryInnovation (P z.1) (q z.1) z.2)) + +theorem adaptive_query_regeneration {n : ℕ} (hn : 0 < n) {H : Type*} + [MeasurableSpace H] (ρ : Measure H) [SFinite ρ] + (P : H → Matrix (Fin n) (Fin n) ℝ) (q : H → Fin n → ℝ) + (hPm : Measurable P) (hqm : Measurable q) + (hP : ∀ h, (P h)ᵀ = P h) (hPP : ∀ h, P h * P h = P h) + (hq : ∀ h, ∑ i, q h i ^ 2 = 1) + (hPq : ∀ h, P h * queryColumn (q h) = queryColumn (q h)) : + (ρ.prod (standardArrayLaw (Fin n × Fin n))).map (fun z => + ((z.1, queryAnswer (P z.1) (q z.1) z.2), + queryResidual (P z.1) (q z.1) z.2)) = + ((answerHistoryLaw ρ P q).prod (standardArrayLaw (Fin n × Fin n))).map + (fun z => (z.1, queryResidual (P z.1.1) (q z.1.1) z.2)) := by + let μ := standardArrayLaw (Fin n × Fin n) + let ν := standardArrayLaw (Fin n ⊕ Unit) + let hist : H × ((Fin n ⊕ Unit) → ℝ) → H × (Fin n → ℝ) := + fun z => (z.1, queryInnovation (P z.1) (q z.1) z.2) + have hhist : Measurable hist := measurable_fst.prodMk + (measurable_queryInnovation_comp _ _ _ (hPm.comp measurable_fst) + (hqm.comp measurable_fst) measurable_snd) + let out : (H × (Fin n → ℝ)) × ((Fin n × Fin n) → ℝ) → + (H × (Fin n → ℝ)) × ((Fin n × Fin n) → ℝ) := + fun z => (z.1, queryResidual (P z.1.1) (q z.1.1) z.2) + have hout : Measurable out := measurable_fst.prodMk + (measurable_queryResidual_comp _ _ _ (hPm.comp measurable_fst.fst) + (hqm.comp measurable_fst.fst) measurable_snd) + have hleft : Measurable (fun z : H × ((Fin n × Fin n) → ℝ) => + (z.1, queryResidual (P z.1) (q z.1) z.2, queryAnswer (P z.1) (q z.1) z.2)) := + measurable_fst.prodMk ((measurable_queryResidual_comp _ _ _ + (hPm.comp measurable_fst) (hqm.comp measurable_fst) measurable_snd).prodMk + (measurable_queryAnswer_comp _ _ _ (hPm.comp measurable_fst) + (hqm.comp measurable_fst) measurable_snd)) + have hright : Measurable (fun z : H × (((Fin n × Fin n) → ℝ) × ((Fin n ⊕ Unit) → ℝ)) => + (z.1, queryResidual (P z.1) (q z.1) z.2.1, + queryInnovation (P z.1) (q z.1) z.2.2)) := + measurable_fst.prodMk ((measurable_queryResidual_comp _ _ _ + (hPm.comp measurable_fst) (hqm.comp measurable_fst) measurable_snd.fst).prodMk + (measurable_queryInnovation_comp _ _ _ (hPm.comp measurable_fst) + (hqm.comp measurable_fst) measurable_snd.snd)) + have hreorder : Measurable (fun z : H × (((Fin n × Fin n) → ℝ) × (Fin n → ℝ)) => + ((z.1,z.2.2),z.2.1)) := (measurable_fst.prodMk measurable_snd.snd).prodMk + measurable_snd.fst + have hj := congrArg (Measure.map (fun z : H × (((Fin n × Fin n) → ℝ) × (Fin n → ℝ)) => + ((z.1,z.2.2),z.2.1))) + (adaptive_query_joint_law hn ρ P q hPm hqm hP hPP hq hPq) + rw [Measure.map_map hreorder hleft, Measure.map_map hreorder hright] at hj + calc + _ = (ρ.prod (μ.prod ν)).map (fun z => out (hist (z.1,z.2.2),z.2.1)) := hj + _ = ((ρ.prod ν).prod μ).map (fun z => out (hist z.1,z.2)) := + map_triple_exchange ρ μ ν _ (hout.comp + ((hhist.comp (measurable_fst.prodMk measurable_snd.snd)).prodMk measurable_snd.fst)) + _ = _ := by + change _ = (((ρ.prod ν).map hist).prod μ).map out + conv_rhs => rw [← Measure.map_id (μ := μ)] + rw [Measure.map_prod_map _ _ hhist measurable_id, Measure.map_map hout + (hhist.prodMap measurable_id)] + rfl + +end SKGapCutoff.Regression + +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators ENNReal NNReal + +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/RankCovariance.lean b/lean/OAI/Probability/SKGap/Localization/RankCovariance.lean new file mode 100644 index 0000000000000000000000000000000000000000..8176d21312c7ed294bd7830b356949b559f868d9 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/RankCovariance.lean @@ -0,0 +1,147 @@ +import Mathlib +import OAI.Probability.SKGap.Model + +namespace OAI + +section +noncomputable section +namespace SKGap +open Matrix +open scoped BigOperators +variable {ι : Type*} [Fintype ι] [DecidableEq ι] + +def rankOneCovariance (s r : ℝ) (m : ι → ℝ) : Matrix ι ι ℝ := + s • (1 : Matrix ι ι ℝ)+r • vecMulVec m m + +def rankOneCovarianceInverse (s r : ℝ) (m : ι → ℝ) : Matrix ι ι ℝ := + s⁻¹ • (1 : Matrix ι ι ℝ)-(r/(s*(s+r*(m⬝ᵥm)))) • vecMulVec m m + +lemma rankOneCovarianceInverse_mul (s r : ℝ) (m : ι → ℝ) + (hs : s ≠ 0) (hS : s+r*(m⬝ᵥm) ≠ 0) : + rankOneCovarianceInverse s r m * rankOneCovariance s r m=1 := by + simp only [rankOneCovarianceInverse,rankOneCovariance,Matrix.sub_mul,Matrix.mul_add, + Matrix.smul_mul,Matrix.mul_smul,Matrix.one_mul,Matrix.mul_one, + Matrix.vecMulVec_mul_vecMulVec] + ext i k + simp only [Matrix.add_apply,Matrix.sub_apply,Matrix.smul_apply,smul_eq_mul, + Matrix.vecMulVec_apply,Pi.smul_apply] + field_simp [hs,hS] + ring + +lemma rankOneCovarianceInverse_mulVec (s r : ℝ) (m y : ι → ℝ) (i : ι) : + (rankOneCovarianceInverse s r m*ᵥy) i = + s⁻¹*y i-r/(s*(s+r*(m⬝ᵥm)))*(m⬝ᵥy)*m i := by + simp only [rankOneCovarianceInverse,Matrix.sub_mulVec,Matrix.smul_mulVec, + Matrix.one_mulVec,Matrix.vecMulVec_mulVec,Pi.sub_apply,Pi.smul_apply, + smul_eq_mul,op_smul_eq_smul] + ring + +lemma rankOneCovariance_posDef {s r : ℝ} (hs : 0 < s) (hr : 0 ≤ r) (m : ι → ℝ) : + (rankOneCovariance s r m).PosDef := by + apply (Matrix.PosDef.smul (Matrix.PosDef.one : (1 : Matrix ι ι ℝ).PosDef) hs).add_posSemidef + have hh : (vecMulVec m m).PosSemidef := by + simpa only [star_trivial] using Matrix.posSemidef_vecMulVec_self_star m + exact hh.smul hr + +end SKGap +end +end + +section +noncomputable section +namespace SKGap +open Matrix Real +open scoped BigOperators +variable {ι : Type*} [Fintype ι] [DecidableEq ι] + +lemma rankOneCovariance_det {s : ℝ} (hs : s ≠ 0) (r : ℝ) (m : ι → ℝ) : + (rankOneCovariance s r m).det=s^(Fintype.card ι)*(1+(r/s)*(m⬝ᵥm)) := by + have he : rankOneCovariance s r m=s • (1+vecMulVec ((r/s) • m) m) := by + ext i k + simp only [rankOneCovariance,Matrix.add_apply,Matrix.smul_apply,smul_eq_mul, + Matrix.vecMulVec_apply,Pi.smul_apply] + field_simp + rw [he,Matrix.det_smul,Matrix.vecMulVec_eq Unit,Matrix.det_one_add_replicateCol_mul_replicateRow] + simp only [dotProduct_smul,smul_eq_mul] + +lemma rankOneCovarianceInverse_quad (s r : ℝ) (m x : ι → ℝ) : + x⬝ᵥ(rankOneCovarianceInverse s r m*ᵥx)= + s⁻¹*(x⬝ᵥx)-r/(s*(s+r*(m⬝ᵥm)))*(m⬝ᵥx)^2 := by + simp only [dotProduct,rankOneCovarianceInverse_mulVec,mul_sub,Finset.sum_sub_distrib] + congr 1 + · rw [Finset.mul_sum] + apply Finset.sum_congr rfl + intro i _ + ring + · have hh : (∑ i,x i*(r/(s*(s+r*∑ j,m j*m j))*(∑ j,m j*x j)*m i))= + (r/(s*(s+r*∑ j,m j*m j))*(∑ j,m j*x j))*(∑ i,m i*x i) := by + conv_rhs => rw [Finset.mul_sum] + apply Finset.sum_congr rfl + intro i _ + ring + rw [hh] + ring + +end SKGap +end +end + +section +noncomputable section +namespace SKGap +open Matrix Real +open scoped BigOperators +variable {ι : Type*} [Fintype ι] [DecidableEq ι] + +def rankOneTransform (a b : ℝ) (u : ι → ℝ) : Matrix ι ι ℝ := + a • (1 : Matrix ι ι ℝ)+(b-a) • vecMulVec u u + +omit [Fintype ι] in +lemma rankOneTransform_transpose (a b : ℝ) (u : ι → ℝ) : + (rankOneTransform a b u)ᵀ=rankOneTransform a b u := by + ext i k + simp [rankOneTransform,Matrix.one_apply,Matrix.vecMulVec_apply,eq_comm,mul_comm] + +lemma rankOneTransform_mul {u : ι → ℝ} (hu : u⬝ᵥu=1) (a b c d : ℝ) : + rankOneTransform a b u *rankOneTransform c d u =rankOneTransform (a*c) (b*d) u := by + simp only [rankOneTransform,Matrix.add_mul,Matrix.mul_add,Matrix.smul_mul,Matrix.mul_smul, + Matrix.one_mul,Matrix.mul_one,Matrix.vecMulVec_mul_vecMulVec,hu] + ext i k + simp only [Matrix.add_apply,Matrix.smul_apply,smul_eq_mul,Matrix.vecMulVec_apply,Pi.smul_apply] + ring + +lemma rankOneTransform_det {a : ℝ} (ha : a ≠ 0) (b : ℝ) {u : ι → ℝ} (hu : u⬝ᵥu=1) : + (rankOneTransform a b u).det=a^(Fintype.card ι)*(b/a) := by + have he : rankOneTransform a b u=rankOneCovariance a (b-a) u := rfl + rw [he,rankOneCovariance_det ha,hu,mul_one] + congr 1 + field_simp + ring + +lemma rankOneTransform_inv {a b : ℝ} (ha : a ≠ 0) (hb : b ≠ 0) + {u : ι → ℝ} (hu : u⬝ᵥu=1) : + (rankOneTransform a b u)⁻¹=rankOneTransform a⁻¹ b⁻¹ u := by + apply Matrix.inv_eq_left_inv + rw [rankOneTransform_mul hu,inv_mul_cancel₀ ha,inv_mul_cancel₀ hb] + simp [rankOneTransform] + +lemma rankOneTransform_mulVec (a b : ℝ) (u x : ι → ℝ) : + rankOneTransform a b u*ᵥx=a • x+((b-a)*(u⬝ᵥx)) • u := by + ext i + simp only [rankOneTransform,Matrix.add_mulVec,Matrix.smul_mulVec,Matrix.one_mulVec, + Matrix.vecMulVec_mulVec,Pi.add_apply,Pi.smul_apply,smul_eq_mul,op_smul_eq_smul] + ring + +lemma rankOneTransform_norm_sq {u : ι → ℝ} (hu : u⬝ᵥu=1) (a b : ℝ) (x : ι → ℝ) : + (rankOneTransform a b u*ᵥx)⬝ᵥ(rankOneTransform a b u*ᵥx)= + a^2*(x⬝ᵥx)+(b^2-a^2)*(u⬝ᵥx)^2 := by + rw [rankOneTransform_mulVec] + simp only [add_dotProduct,dotProduct_add,smul_dotProduct,dotProduct_smul,smul_eq_mul,hu] + rw [dotProduct_comm x u] + ring + +end SKGap +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/RareCoordinate.lean b/lean/OAI/Probability/SKGap/Localization/RareCoordinate.lean new file mode 100644 index 0000000000000000000000000000000000000000..1a2dca5ee2d76ebf4ee42800eaa884cdc8b9e988 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/RareCoordinate.lean @@ -0,0 +1,127 @@ +import Mathlib +import OAI.Probability.SKGap.Model + +namespace OAI + +section +noncomputable section +namespace SKGap +open MeasureTheory ProbabilityTheory Real Set +open scoped BigOperators + +lemma gaussian_standard_subgaussian : HasSubgaussianMGF (fun x : ℝ=>x) 1 (gaussianReal 0 1) where + integrable_exp_mul t := integrable_exp_mul_gaussianReal t + mgf_le t := by + change mgf id (gaussianReal 0 1) t ≤ _ + rw [mgf_id_gaussianReal] + simp + +lemma gaussian_observation_small {T : ℝ} (hT : 0 < T) {s : ℝ} (hs : s=1 ∨ s= -1) : + (gaussianReal 0 1).real {z : ℝ | |T*s+sqrt T*z| < T/2} ≤ exp (-T/8) := by + have ht : 0 < sqrt T := sqrt_pos.mpr hT + have ht2 := sq_sqrt hT.le + rcases hs with rfl | rfl + · have hsub : {z : ℝ | |T*1+sqrt T*z| < T/2} ⊆ {z | sqrt T/2 ≤ -z} := by + intro z hz + change |T*1+sqrt T*z| < T/2 at hz + have hz' := (abs_lt.mp hz).2 + have hm : sqrt T/2*sqrt T ≤ -z*sqrt T := by nlinarith only [hz',ht2] + exact le_of_mul_le_mul_right hm ht + apply (measureReal_mono hsub (measure_ne_top _ _)).trans + have hh := gaussian_standard_subgaussian.neg.measure_ge_le (show 0 ≤ sqrt T/2 by positivity) + have he : -(sqrt T/2)^2/(2*(1:ℝ))= -T/8 := by + simp only [div_pow,ht2] + ring + simpa only [NNReal.coe_one,Pi.neg_apply,he] using hh + · have hsub : {z : ℝ | |T*(-1)+sqrt T*z| < T/2} ⊆ {z | sqrt T/2 ≤ z} := by + intro z hz + change |T*(-1)+sqrt T*z| < T/2 at hz + have hz' := (abs_lt.mp hz).1 + have hm : sqrt T/2*sqrt T ≤ z*sqrt T := by nlinarith only [hz',ht2] + exact le_of_mul_le_mul_right hm ht + apply (measureReal_mono hsub (measure_ne_top _ _)).trans + have hh := gaussian_standard_subgaussian.measure_ge_le (show 0 ≤ sqrt T/2 by positivity) + have he : -(sqrt T/2)^2/(2*(1:ℝ))= -T/8 := by + simp only [div_pow,ht2] + ring + simpa only [NNReal.coe_one,he] using hh + +variable {ι : Type*} [Fintype ι] {E : ι→Type*} [∀ i,MeasurableSpace (E i)] + +def rareCount (B : ∀ i,Set (E i)) (x : ∀ i,E i) : ℝ := by + classical + exact ∑ i,if x i∈B i then 1 else 0 + +lemma rareCount_measurable (B : ∀ i,Set (E i)) (hB : ∀ i,MeasurableSet (B i)) : + Measurable (rareCount B) := by + classical + unfold rareCount + apply Finset.measurable_sum + intro i _ + exact ((measurable_const (a:=(1:ℝ))).indicator (hB i)).comp (measurable_pi_apply i) + +omit [∀ i,MeasurableSpace (E i)] in +lemma rareCount_bounds (B : ∀ i,Set (E i)) (x : ∀ i,E i) : + 0 ≤ rareCount B x ∧ rareCount B x ≤ Fintype.card ι := by + classical + constructor + · exact Finset.sum_nonneg (fun i _=>by split_ifs <;> norm_num) + · apply (Finset.sum_le_sum (g:=fun _=>(1:ℝ)) (fun i _=>by split_ifs <;> norm_num)).trans_eq + simp + +lemma rareCount_exp_integral (μ : ∀ i,Measure (E i)) [∀ i,IsProbabilityMeasure (μ i)] + (B : ∀ i,Set (E i)) (hB : ∀ i,MeasurableSet (B i)) : + (∫ x,exp (rareCount B x) ∂Measure.pi μ)=∏ i,(1+((μ i).real (B i))*(exp 1-1)) := by + classical + have hi (i : ι) : (∫ z,exp (if z∈B i then (1:ℝ) else 0) ∂μ i)= + 1+(μ i).real (B i)*(exp 1-1) := by + have he : (fun z=>exp (if z∈B i then (1:ℝ) else 0))= + fun z=>1+(B i).indicator (fun _=>exp 1-1) z := by + funext z + by_cases hz : z∈B i <;> simp [hz] + rw [he,integral_add (integrable_const _) ((integrable_const _).indicator (hB i)),integral_indicator_const _ (hB i)] + simp + simp only [rareCount,exp_sum] + rw [integral_fintype_prod_eq_prod (μ:=μ) (fun i z=>exp (if z∈B i then (1:ℝ) else 0))] + exact Finset.prod_congr rfl (fun i _=>hi i) + +theorem rareCount_tail (μ : ∀ i,Measure (E i)) [∀ i,IsProbabilityMeasure (μ i)] + (B : ∀ i,Set (E i)) (hB : ∀ i,MeasurableSet (B i)) + {p a : ℝ} (hp : ∀ i,(μ i).real (B i) ≤ p) : + (Measure.pi μ).real {x | a < rareCount B x} ≤ + exp (-a+(Fintype.card ι:ℝ)*p*(exp 1-1)) := by + classical + have hmono : 0 ≤ exp (1:ℝ)-1 := by linarith only [one_le_exp (by norm_num : (0:ℝ) ≤ 1)] + have hi : Integrable (fun x=>exp (rareCount B x)) (Measure.pi μ) := + Integrable.of_bound (rareCount_measurable B hB |>.exp.aestronglyMeasurable) + (exp (Fintype.card ι:ℝ)) (ae_of_all _ (fun x=>by + rw [Real.norm_eq_abs,abs_of_pos (exp_pos _)] + exact exp_le_exp.mpr (rareCount_bounds B x).2)) + have hm := mul_meas_ge_le_integral_of_nonneg (μ:=Measure.pi μ) + (ae_of_all _ (fun x=>(exp_pos (rareCount B x)).le)) hi (exp a) + rw [rareCount_exp_integral μ B hB] at hm + have hset : {x | a < rareCount B x} ⊆ {x | exp a ≤ exp (rareCount B x)} := + fun _ hx=>exp_le_exp.mpr hx.le + have hh := measureReal_mono hset (measure_ne_top (Measure.pi μ) _) + have hprod : (∏ i,(1+(μ i).real (B i)*(exp 1-1))) ≤ + exp ((Fintype.card ι:ℝ)*p*(exp 1-1)) := by + have hp' (i : ι) : 1+(μ i).real (B i)*(exp 1-1) ≤ exp (p*(exp 1-1)) := by + calc + _ ≤ 1+p*(exp 1-1) := add_le_add_right (mul_le_mul_of_nonneg_right (hp i) hmono) 1 + _ ≤ _ := by linarith only [add_one_le_exp (p*(exp 1-1))] + calc + _ ≤ ∏ _i : ι,exp (p*(exp 1-1)) := Finset.prod_le_prod₀ + (fun i _=>add_nonneg (by norm_num) (mul_nonneg (measureReal_nonneg) hmono)) (fun i _=>hp' i) + _ = _ := by rw [Finset.prod_const,Finset.card_univ,← exp_nat_mul];congr 1;ring + have hm' := (mul_le_mul_of_nonneg_left hh (exp_pos a).le).trans (hm.trans hprod) + have he : exp (-a+(Fintype.card ι:ℝ)*p*(exp 1-1))= + exp ((Fintype.card ι:ℝ)*p*(exp 1-1))/exp a := by rw [← exp_sub];congr 1;ring + rw [he] + apply (le_div_iff₀ (exp_pos a)).mpr + simpa only [mul_comm] using hm' +end SKGap + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/RealParameterIncrement.lean b/lean/OAI/Probability/SKGap/Localization/RealParameterIncrement.lean new file mode 100644 index 0000000000000000000000000000000000000000..25bf4bd9134f6828662577633f3e000b920f59c4 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/RealParameterIncrement.lean @@ -0,0 +1,155 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.RealPart + +namespace OAI + +section +noncomputable section +open Matrix Real Set +open scoped Matrix.Norms.Frobenius SchwartzMap +namespace SKGap.ComplexMatrix +variable {ι : Type*} [Fintype ι] [DecidableEq ι] +def kChange (f : 𝓢(ℝ,ℂ)) (R : ℝ) (B B' D D' C C' : Matrix ι ι ℂ) : ℝ := + gChange f R B B' D D'*(R+opNorm C)+gBound f D'*opNorm (C-C') +lemma kChange_nonneg (f : 𝓢(ℝ,ℂ)) {R : ℝ} (hR : 0≤R) + (B B' D D' C C' : Matrix ι ι ℂ) : 0≤kChange f R B B' D D' C C' := by + have hh := g_constants_nonneg f hR B B' D D' + have hh' := (g_constants_nonneg f hR B B' D' D').1 + unfold kChange + exact add_nonneg (mul_nonneg hh.2.2.1 (add_nonneg hR (opNorm_nonneg C))) + (mul_nonneg hh' (opNorm_nonneg (C-C'))) +lemma kMixed_nonneg (f : 𝓢(ℝ,ℂ)) {R : ℝ} (hR : 0≤R) + (B B' D D' C C' : Matrix ι ι ℂ) : 0≤kMixed f R B B' D D' C C' := by + have hh := g_constants_nonneg f hR B B' D D' + have hh' := (g_constants_nonneg f hR B B' D' D').2.1 + unfold kMixed + exact add_nonneg (add_nonneg (mul_nonneg hh.2.2.2 (add_nonneg hR (opNorm_nonneg C))) + (mul_nonneg hh' (opNorm_nonneg (C-C')))) hh.2.2.1 +lemma truncatedK_parameter (f : 𝓢(ℝ,ℂ)) {R : ℝ} (hR : 0≤R) + (B B' D D' C C' M : Matrix ι ι ℂ) + (hB : Bᴴ=B) (hB' : B'ᴴ=B') (hD : Dᴴ=D) (hD' : D'ᴴ=D') : + opNorm (truncatedK f R hR B D C M-truncatedK f R hR B' D' C' M)≤ + kChange f R B B' D D' C C' := by + have he : truncatedK f R hR B D C M-truncatedK f R hR B' D' C' M= + (truncatedG f R hR B D M-truncatedG f R hR B' D' M)*(matrixProject R hR M-C)+ + truncatedG f R hR B' D' M*(C'-C) := by unfold truncatedK;noncomm_ring + rw [he] + apply (opNorm_add _ _).trans + apply (add_le_add (opNorm_mul _ _) (opNorm_mul _ _)).trans + have h1 := mul_le_mul (truncatedG_parameter f hR B B' D D' M hB hB' hD hD') + (projected_sub_bound hR M C) (opNorm_nonneg _) (g_constants_nonneg f hR B B' D D').2.2.1 + have h2 := mul_le_mul_of_nonneg_right (truncatedG_opNorm f R hR B' D' M hB' hD') + (opNorm_nonneg (C'-C)) + have hs : opNorm (C'-C)=opNorm (C-C') := by rw [← neg_sub C C',opNorm_neg] + rw [hs] at h2 + simpa only [kChange,hs,gBound] using add_le_add h1 h2 +end SKGap.ComplexMatrix +namespace SKGap.RealComplex +open SKGap.ComplexMatrix +variable {ι : Type*} [Fintype ι] [DecidableEq ι] +lemma liftedSand_hermitian (D C : Matrix ι ι ℝ) (hD : Dᵀ=D) (hC : Cᵀ=C) : + (1+liftMatrix D*liftMatrix C*liftMatrix D)ᴴ=1+liftMatrix D*liftMatrix C*liftMatrix D := by + simp [Matrix.conjTranspose_mul,liftMatrix_hermitian D hD,liftMatrix_hermitian C hC,mul_assoc] +lemma realTruncatedK_parameter (f : 𝓢(ℝ,ℂ)) {R : ℝ} (hR : 0≤R) + (D D' C C' M : Matrix ι ι ℝ) (hD : Dᵀ=D) (hD' : D'ᵀ=D') (hC : Cᵀ=C) (hC' : C'ᵀ=C') : + SKGap.opNorm (realTruncatedK f R hR D C M-realTruncatedK f R hR D' C' M)≤ + kChange f R (1+liftMatrix D*liftMatrix C*liftMatrix D) + (1+liftMatrix D'*liftMatrix C'*liftMatrix D') (liftMatrix D) (liftMatrix D') (liftMatrix C) (liftMatrix C') := by + unfold realTruncatedK + rw [← realPart_sub] + exact (operator_realPart_le _).trans (truncatedK_parameter f hR _ _ _ _ _ _ _ + (liftedSand_hermitian D C hD hC) (liftedSand_hermitian D' C' hD' hC') + (liftMatrix_hermitian D hD) (liftMatrix_hermitian D' hD')) + +lemma realTruncatedK_four_point (f : 𝓢(ℝ,ℂ)) {R : ℝ} (hR : 0≤R) + (D D' C C' M N : Matrix ι ι ℝ) (hD : Dᵀ=D) (hD' : D'ᵀ=D') (hC : Cᵀ=C) (hC' : C'ᵀ=C') : + ‖(realTruncatedK f R hR D C M-realTruncatedK f R hR D C N)- + (realTruncatedK f R hR D' C' M-realTruncatedK f R hR D' C' N)‖≤ + kMixed f R (1+liftMatrix D*liftMatrix C*liftMatrix D) + (1+liftMatrix D'*liftMatrix C'*liftMatrix D') (liftMatrix D) (liftMatrix D') (liftMatrix C) (liftMatrix C')*‖M-N‖ := by + unfold realTruncatedK + rw [← realPart_sub,← realPart_sub,← realPart_sub] + apply (norm_realPart_le _).trans + simpa only [← liftMatrix_sub,norm_liftMatrix] using! truncatedK_four_point f hR _ _ _ _ _ _ + (liftMatrix M) (liftMatrix N) (liftedSand_hermitian D C hD hC) + (liftedSand_hermitian D' C' hD' hC') (liftMatrix_hermitian D hD) (liftMatrix_hermitian D' hD') +end SKGap.RealComplex +end +end + +section +noncomputable section +namespace SKGap.ComplexMatrix +open Matrix Real +open scoped Matrix.Norms.Frobenius SchwartzMap +variable {ι : Type*} [Fintype ι] [DecidableEq ι] + +def parameterGC (f : 𝓢(ℝ,ℂ)) (R V H : ℝ) : ℝ := + 2*V*fourierMoment f 0+V^2*fl1 f*(H+2*V*R) +def parameterGM (f : 𝓢(ℝ,ℂ)) (R V H : ℝ) : ℝ := + 2*V*fl1 f*V^2+V^2*(fl1 f*(2*V)+fl2 f*(2*(H+2*V*R))*V^2) +def parameterKC (f : 𝓢(ℝ,ℂ)) (R V T H : ℝ) : ℝ := + parameterGC f R V H*(R+T)+V^2*fourierMoment f 0 +def parameterKM (f : 𝓢(ℝ,ℂ)) (R V T H : ℝ) : ℝ := + parameterGM f R V H*(R+T)+fl1 f*V^4+parameterGC f R V H + +theorem cutoff_parameter_constants (f : 𝓢(ℝ,ℂ)) + {R V T H δ : ℝ} (hR : 0≤R) (hV : 0≤V) (_hT : 0≤T) (hH : 0≤H) (hδ : 0≤δ) + (B B' D D' C C' : Matrix ι ι ℂ) + (hD : opNorm D≤V) (hD' : opNorm D'≤V) (hC : opNorm C≤T) + (hBD : opNorm (B-B')≤H*δ) (hDD : opNorm (D-D')≤δ) (hCD : opNorm (C-C')≤δ) : + kChange f R B B' D D' C C'≤parameterKC f R V T H*δ ∧ + kMixed f R B B' D D' C C'≤parameterKM f R V T H*δ := by + have hf0 := fourierMoment_nonneg f 0 + obtain ⟨hf1,hf2⟩ := fl_nonneg f + have hDC : diagonalChange D D'≤(2*V)*δ := by + unfold diagonalChange + exact mul_le_mul (by linarith) hDD (opNorm_nonneg _) (by positivity) + have hSC : shiftChange R B B' D D'≤(H+2*V*R)*δ := by + unfold shiftChange + have hh := add_le_add hBD (mul_le_mul_of_nonneg_right hDC hR) + nlinarith only [hh] + have hGH : 0≤H+2*V*R := by positivity + have hgc : gChange f R B B' D D'≤parameterGC f R V H*δ := by + unfold gChange parameterGC + calc + _ ≤ ((2*V)*δ)*fourierMoment f 0+V^2*fl1 f*((H+2*V*R)*δ) := by + apply add_le_add (mul_le_mul_of_nonneg_right hDC hf0) + apply mul_le_mul _ hSC (shiftChange_nonneg hR _ _ _ _) (by positivity) + exact mul_le_mul_of_nonneg_right (pow_le_pow_left₀ (opNorm_nonneg D') hD' 2) hf1 + _ = _ := by ring + have hgm : gMixed f R B B' D D'≤parameterGM f R V H*δ := by + unfold gMixed parameterGM + calc + _ ≤ ((2*V)*δ)*fl1 f*V^2+V^2*(fl1 f*((2*V)*δ)+fl2 f*(2*((H+2*V*R)*δ))*V^2) := by + apply add_le_add + · apply mul_le_mul _ (pow_le_pow_left₀ (opNorm_nonneg D) hD 2) (by positivity [fl_nonneg f]) (by positivity) + exact mul_le_mul_of_nonneg_right hDC hf1 + · apply mul_le_mul (pow_le_pow_left₀ (opNorm_nonneg D') hD' 2) _ (by positivity [diagonalChange_nonneg D D',shiftChange_nonneg hR B B' D D']) (by positivity) + apply add_le_add (mul_le_mul_of_nonneg_left hDC hf1) + apply mul_le_mul _ (pow_le_pow_left₀ (opNorm_nonneg D') hD' 2) (by positivity [opNorm_nonneg D']) (by positivity) + exact mul_le_mul_of_nonneg_left (mul_le_mul_of_nonneg_left hSC (by norm_num)) hf2 + _ = _ := by ring + have hgc0 : 0≤parameterGC f R V H := by unfold parameterGC;positivity + have hgm0 : 0≤parameterGM f R V H := by unfold parameterGM;positivity + constructor + · unfold kChange parameterKC + calc + _ ≤ (parameterGC f R V H*δ)*(R+T)+(V^2*fourierMoment f 0)*δ := by + apply add_le_add + · exact mul_le_mul hgc (add_le_add le_rfl hC) (by positivity [opNorm_nonneg C]) (by positivity) + · exact mul_le_mul (mul_le_mul_of_nonneg_right (pow_le_pow_left₀ (opNorm_nonneg D') hD' 2) hf0) hCD (opNorm_nonneg _) (by positivity) + _ = _ := by ring + · unfold kMixed parameterKM + calc + _ ≤ (parameterGM f R V H*δ)*(R+T)+(fl1 f*V^4)*δ+parameterGC f R V H*δ := by + apply add_le_add _ hgc + apply add_le_add + · exact mul_le_mul hgm (add_le_add le_rfl hC) (by positivity [opNorm_nonneg C]) (by positivity) + · exact mul_le_mul (mul_le_mul_of_nonneg_left (pow_le_pow_left₀ (opNorm_nonneg D') hD' 4) hf1) hCD (opNorm_nonneg _) (by positivity) + _ = _ := by ring +end SKGap.ComplexMatrix +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/RealPart.lean b/lean/OAI/Probability/SKGap/Localization/RealPart.lean new file mode 100644 index 0000000000000000000000000000000000000000..0f8b67a700f689d07d8e644638bd595aa13e255d --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/RealPart.lean @@ -0,0 +1,269 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.SandShiftSpecial +import OAI.Probability.SKGap.Matrix.LiftMatrix + +namespace OAI + +section +noncomputable section +open MeasureTheory ProbabilityTheory InformationTheory Real Set +open scoped NNReal ENNReal +open Filter +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius ENNReal NNReal +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius NNReal +noncomputable section +open MeasureTheory ProbabilityTheory Real Set Filter +open MeasureTheory.Measure +open scoped ENNReal NNReal MeasureTheory Topology +open MeasureTheory +noncomputable section +noncomputable section +open MeasureTheory Set NormedSpace +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius +noncomputable section +open Set Real +open scoped Topology +noncomputable section +open Matrix Set Filter +open scoped Topology Matrix.Norms.Frobenius +noncomputable section +open Matrix NormedSpace ContinuousLinearMap +open scoped Matrix.Norms.Frobenius +noncomputable section +open Matrix +namespace SKGap.RealComplex +open scoped Matrix.Norms.Frobenius +variable {ι : Type*} [Fintype ι] [DecidableEq ι] + +def realPart (M : Matrix ι ι ℂ) : Matrix ι ι ℝ := M.map Complex.re + +lemma norm_realPart_le (M : Matrix ι ι ℂ) : ‖realPart M‖ ≤ ‖M‖ := by + rw [Matrix.frobenius_norm_def,Matrix.frobenius_norm_def] + apply Real.rpow_le_rpow (by positivity) _ (by norm_num) + apply Finset.sum_le_sum + intro i _ + apply Finset.sum_le_sum + intro k _ + simp only [realPart,Matrix.map_apply,Real.rpow_two] + exact pow_le_pow_left₀ (norm_nonneg _) (by simpa only [Real.norm_eq_abs] using Complex.abs_re_le_norm (M i k)) 2 + +omit [Fintype ι] [DecidableEq ι] in +lemma realPart_sub (M N : Matrix ι ι ℂ) : realPart (M-N) = realPart M-realPart N := by + ext i k; simp [realPart] +omit [Fintype ι] [DecidableEq ι] in +lemma realPart_liftMatrix (M : Matrix ι ι ℝ) : realPart (liftMatrix M) = M := by + ext i k; simp [realPart,liftMatrix] + +lemma realPart_lipschitz : LipschitzWith 1 (realPart (ι := ι)) := by + apply LipschitzWith.of_dist_le_mul + intro M N + simpa only [dist_eq_norm,NNReal.coe_one,one_mul,realPart_sub] using norm_realPart_le (M-N) + +omit [DecidableEq ι] in +lemma reVec_norm_le (x : EuclideanSpace ℂ ι) : ‖reVec x‖ ≤ ‖x‖ := by + have h := vec_norm_split x + nlinarith [sq_nonneg ‖imVec x‖,norm_nonneg (reVec x),norm_nonneg x] + +lemma realPart_operator (M : Matrix ι ι ℂ) (x : EuclideanSpace ℝ ι) : + rlin (realPart M) x = reVec (clin M (liftVec x)) := by + ext i + change (∑ k, (M i k).re*x k) = (∑ k, M i k*(x k : ℂ)).re + simp + +lemma operator_realPart_le (M : Matrix ι ι ℂ) : opNorm (realPart M) ≤ ‖clin M‖ := by + apply ContinuousLinearMap.opNorm_le_bound _ (norm_nonneg _) + intro x + rw [realPart_operator] + exact (reVec_norm_le _).trans ((clin M).le_opNorm (liftVec x) |>.trans_eq (by rw [norm_liftVec])) + +lemma liftMatrix_inverse {M : Matrix ι ι ℝ} (hM : IsUnit M) : + liftMatrix M⁻¹ = (liftMatrix M)⁻¹ := by + symm + apply Matrix.inv_eq_right_inv + rw [← liftMatrix_mul,Matrix.mul_nonsing_inv M (M.isUnit_iff_isUnit_det.mp hM),liftMatrix_one] + +end SKGap.RealComplex + +namespace SKGap.RealComplex +open scoped Matrix.Norms.Frobenius SchwartzMap ComplexOrder +open SKGap.ComplexMatrix +variable {ι : Type*} [Fintype ι] [DecidableEq ι] + +lemma liftMatrix_isUnit_iff (M : Matrix ι ι ℝ) : IsUnit (liftMatrix M) ↔ IsUnit M := by + rw [(liftMatrix M).isUnit_iff_isUnit_det,M.isUnit_iff_isUnit_det, + isUnit_iff_ne_zero,isUnit_iff_ne_zero] + have he : (liftMatrix M).det = (M.det : ℂ) := (Complex.ofRealHom.map_det M).symm + rw [he] + exact not_congr Complex.ofReal_eq_zero + +noncomputable def realPartCLM : Matrix ι ι ℂ →L[ℝ] Matrix ι ι ℝ := + ({ toFun := realPart + map_add' := by intros; ext; simp [realPart] + map_smul' := by intros; ext; simp [realPart] } : Matrix ι ι ℂ →ₗ[ℝ] Matrix ι ι ℝ).mkContinuous + 1 (fun M => by simpa using norm_realPart_le M) + +noncomputable def realTruncatedK (f : 𝓢(ℝ,ℂ)) (R : ℝ) (hR : 0 ≤ R) + (D C M : Matrix ι ι ℝ) : Matrix ι ι ℝ := + realPart (truncatedK f R hR (1+liftMatrix D*liftMatrix C*liftMatrix D) + (liftMatrix D) (liftMatrix C) (liftMatrix M)) + +lemma realTruncatedK_sub_norm (f : 𝓢(ℝ,ℂ)) {R : ℝ} (hR : 0 ≤ R) + (D C M N : Matrix ι ι ℝ) (hD : Dᵀ = D) (hC : Cᵀ = C) : + ‖realTruncatedK f R hR D C M-realTruncatedK f R hR D C N‖ ≤ + kLip f R (liftMatrix D) (liftMatrix C)*‖M-N‖ := by + have hD' := liftMatrix_hermitian D hD + have hC' := liftMatrix_hermitian C hC + have hB : (1+liftMatrix D*liftMatrix C*liftMatrix D)ᴴ = + 1+liftMatrix D*liftMatrix C*liftMatrix D := by simp [Matrix.conjTranspose_mul,hD',hC',mul_assoc] + unfold realTruncatedK + rw [← realPart_sub] + apply (norm_realPart_le _).trans + simpa only [← liftMatrix_sub,norm_liftMatrix] using + truncatedK_sub_norm f hR _ _ _ (liftMatrix M) (liftMatrix N) hB hD' + +lemma realTruncatedK_opNorm (f : 𝓢(ℝ,ℂ)) {R : ℝ} (hR : 0 ≤ R) + (D C M : Matrix ι ι ℝ) (hD : Dᵀ = D) (hC : Cᵀ = C) : + SKGap.opNorm (realTruncatedK f R hR D C M) ≤ kBound f R (liftMatrix D) (liftMatrix C) := by + have hD' := liftMatrix_hermitian D hD + have hC' := liftMatrix_hermitian C hC + have hB : (1+liftMatrix D*liftMatrix C*liftMatrix D)ᴴ = + 1+liftMatrix D*liftMatrix C*liftMatrix D := by simp [Matrix.conjTranspose_mul,hD',hC',mul_assoc] + exact (operator_realPart_le _).trans (truncatedK_opNorm f hR _ _ _ _ hB hD') + +lemma realTruncatedK_eq_inverse (f : 𝓢(ℝ,ℂ)) {lo hi : ℝ} (hlo : 0 < lo) + (hf : ∀ x ∈ Set.Icc lo hi, f x = (x : ℂ)⁻¹) + {R : ℝ} (hR : 0 ≤ R) (D C M : Matrix ι ι ℝ) + (hD : Dᵀ = D) (hC : Cᵀ = C) (hM : Mᵀ = M) (hMR : SKGap.opNorm M ≤ R) + (hl : lo ≤ SKGap.ComplexSpectral.lowerRayleigh (liftMatrix (1-D*(M-C)*D))) + (hu : -hi ≤ SKGap.ComplexSpectral.lowerRayleigh (-liftMatrix (1-D*(M-C)*D))) : + realTruncatedK f R hR D C M = (1-D*D*(M-C))⁻¹ := by + have hD' := liftMatrix_hermitian D hD + have hC' := liftMatrix_hermitian C hC + have hM' := liftMatrix_hermitian M hM + have hB : (1+liftMatrix D*liftMatrix C*liftMatrix D)ᴴ = + 1+liftMatrix D*liftMatrix C*liftMatrix D := by simp [Matrix.conjTranspose_mul,hD',hC',mul_assoc] + have hid : sandShift (1+liftMatrix D*liftMatrix C*liftMatrix D) (liftMatrix D) (liftMatrix M) = + liftMatrix (1-D*(M-C)*D) := by + rw [sandShift_special]; simp only [liftMatrix_sub,liftMatrix_mul,liftMatrix_one] + have hS : (sandShift (1+liftMatrix D*liftMatrix C*liftMatrix D) (liftMatrix D) (liftMatrix M)).IsHermitian := + sandShift_hermitian _ _ _ hB hD' hM' + have hspec : ∀ i, hS.eigenvalues i ∈ Set.Icc lo hi := by + intro i + have hm := SKGap.ComplexSpectral.eigenvalue_lower_bound hS i + have hp := SKGap.ComplexSpectral.eigenvalue_upper_bound hS i + have hl' : lo ≤ SKGap.ComplexSpectral.lowerRayleigh + (sandShift (1+liftMatrix D*liftMatrix C*liftMatrix D) (liftMatrix D) (liftMatrix M)) := by + simpa only [hid] using hl + have hu' : -hi ≤ SKGap.ComplexSpectral.lowerRayleigh + (-sandShift (1+liftMatrix D*liftMatrix C*liftMatrix D) (liftMatrix D) (liftMatrix M)) := by + simpa only [hid] using hu + constructor <;> linarith + have hsunit : IsUnit (1-liftMatrix D*(liftMatrix M-liftMatrix C)*liftMatrix D) := by + rw [← sandShift_special] + exact (hS.posDef_iff_eigenvalues_pos.mpr (fun i => hlo.trans_le (hspec i).1)).isUnit + have hrunit : IsUnit (1-D*D*(M-C)) := by + apply (liftMatrix_isUnit_iff _).mp + simpa only [liftMatrix_sub,liftMatrix_mul,liftMatrix_one] using + SKGap.ResolventIdentity.inverse_one_sub_square_mul_unit (liftMatrix D) (liftMatrix M-liftMatrix C) hsunit + unfold realTruncatedK + rw [truncatedK_eq_inverse f hlo hf hR _ _ _ hD' hC' hM' + (by simpa only [SKGap.ComplexMatrix.opNorm,SKGap.ComplexMatrix.lin,operator_norm_lift] using hMR) hspec] + rw [← liftMatrix_one,← liftMatrix_mul,← liftMatrix_sub,← liftMatrix_mul,← liftMatrix_sub, + ← liftMatrix_inverse hrunit,realPart_liftMatrix] + +lemma real_matrix_hasDerivAt_inverse {Q : ℝ → Matrix ι ι ℝ} {Q' : Matrix ι ι ℝ} {t : ℝ} + (hQ : HasDerivAt Q Q' t) (hunit : IsUnit (Q t)) : + HasDerivAt (fun s => (Q s)⁻¹) (-(Q t)⁻¹*Q'*(Q t)⁻¹) t := by + obtain ⟨u,hu⟩ := hunit + have hfi := hasFDerivAt_ringInverse (𝕜 := ℝ) u + rw [hu] at hfi + have hi := hfi.comp_hasDerivAt t hQ + have hv : (↑u⁻¹ : Matrix ι ι ℝ) = (Q t)⁻¹ := by + rw [← hu,Matrix.nonsing_inv_eq_ringInverse,Ring.inverse_unit] + simpa only [Function.comp_def,← Matrix.nonsing_inv_eq_ringInverse,_root_.neg_apply, + ContinuousLinearMap.mulLeftRight_apply,hv,neg_mul] using! hi + +lemma continuous_realOpNorm : Continuous (SKGap.opNorm : Matrix ι ι ℝ → ℝ) := by + have h : Continuous (fun M : Matrix ι ι ℝ => liftMatrix M) := by + dsimp [liftMatrix]; fun_prop + have hc := SKGap.ComplexMatrix.continuous_lin.norm.comp h + simpa only [Function.comp_def,SKGap.ComplexMatrix.lin,operator_norm_lift] using hc + +lemma realTruncatedK_eventually_inverse (f : 𝓢(ℝ,ℂ)) {lo hi : ℝ} (hlo : 0 < lo) + (hf : ∀ x ∈ Set.Icc lo hi, f x = (x : ℂ)⁻¹) + {R : ℝ} (hR : 0 ≤ R) (D C M E : Matrix ι ι ℝ) + (hD : Dᵀ = D) (hC : Cᵀ = C) (hM : Mᵀ = M) (hE : Eᵀ = E) + (hMR : SKGap.opNorm M < R) + (hl : lo < SKGap.ComplexSpectral.lowerRayleigh (liftMatrix (1-D*(M-C)*D))) + (hu : -hi < SKGap.ComplexSpectral.lowerRayleigh (-liftMatrix (1-D*(M-C)*D))) : + (fun t : ℝ => realTruncatedK f R hR D C (M+t • E)) =ᶠ[𝓝 (0:ℝ)] + (fun t => (1-D*D*(M+t • E-C))⁻¹) := by + have hcont : Continuous (fun t : ℝ => liftMatrix (1-D*(M+t • E-C)*D)) := by + dsimp [liftMatrix]; fun_prop + have hcont' : Continuous (fun t : ℝ => SKGap.opNorm (M+t • E)) := + continuous_realOpNorm.comp (continuous_const.add (continuous_id.smul continuous_const)) + have hl' : ∀ᶠ t in 𝓝 (0:ℝ), lo < SKGap.ComplexSpectral.lowerRayleigh (liftMatrix (1-D*(M+t • E-C)*D)) := + (SKGap.ComplexSpectral.continuous_lowerRayleigh.comp hcont).continuousAt.eventually + (lt_mem_nhds (by simpa using hl)) + have hu' : ∀ᶠ t in 𝓝 (0:ℝ), -hi < SKGap.ComplexSpectral.lowerRayleigh (-liftMatrix (1-D*(M+t • E-C)*D)) := + (SKGap.ComplexSpectral.continuous_lowerRayleigh.comp hcont.neg).continuousAt.eventually + (lt_mem_nhds (by simpa using hu)) + have hm' : ∀ᶠ t in 𝓝 (0:ℝ), SKGap.opNorm (M+t • E) < R := + hcont'.continuousAt.eventually (gt_mem_nhds (by simpa using hMR)) + filter_upwards [hl',hu',hm'] with t ht ht' hm + exact realTruncatedK_eq_inverse f hlo hf hR D C (M+t • E) hD hC + (by simp [Matrix.transpose_smul,hM,hE]) hm.le ht.le ht'.le + +lemma realTruncatedK_derivative (f : 𝓢(ℝ,ℂ)) {lo hi : ℝ} (hlo : 0 < lo) + (hf : ∀ x ∈ Set.Icc lo hi, f x = (x : ℂ)⁻¹) + {R : ℝ} (hR : 0 ≤ R) (D C M E : Matrix ι ι ℝ) + (hD : Dᵀ = D) (hC : Cᵀ = C) (hM : Mᵀ = M) (hE : Eᵀ = E) + (hMR : SKGap.opNorm M < R) + (hl : lo < SKGap.ComplexSpectral.lowerRayleigh (liftMatrix (1-D*(M-C)*D))) + (hu : -hi < SKGap.ComplexSpectral.lowerRayleigh (-liftMatrix (1-D*(M-C)*D))) : + HasDerivAt (fun t : ℝ => realTruncatedK f R hR D C (M+t • E)) + (realTruncatedK f R hR D C M*(D*D)*E*realTruncatedK f R hR D C M) 0 := by + have hid := realTruncatedK_eq_inverse f hlo hf hR D C M hD hC hM hMR.le hl.le hu.le + have he := realTruncatedK_eventually_inverse f hlo hf hR D C M E hD hC hM hE hMR hl hu + have hunit : IsUnit (1-D*D*(M-C)) := by + have hSH : (liftMatrix (1-D*(M-C)*D)).IsHermitian := + liftMatrix_hermitian _ (by simp [Matrix.transpose_mul,hD,hC,hM,mul_assoc]) + have hp : (liftMatrix (1-D*(M-C)*D)).PosDef := hSH.posDef_iff_eigenvalues_pos.mpr (fun i => + hlo.trans (hl.trans_le (SKGap.ComplexSpectral.eigenvalue_lower_bound hSH i))) + have hS : IsUnit (1-D*(M-C)*D) := (liftMatrix_isUnit_iff _).mp hp.isUnit + exact SKGap.ResolventIdentity.inverse_one_sub_square_mul_unit D (M-C) hS + have hm : HasDerivAt (fun t : ℝ => M+t • E-C) E 0 := by + convert! ((hasDerivAt_id (0:ℝ)).smul_const E |>.const_add M).sub_const C using 1 + simp only [one_smul] + have hq := (hm.const_mul (D*D)).const_sub 1 + have hi := real_matrix_hasDerivAt_inverse hq (by simpa using hunit) + rw [hid] + have hi' : HasDerivAt (fun t : ℝ => (1-D*D*(M+t • E-C))⁻¹) + ((1-D*D*(M-C))⁻¹*(D*D)*E*(1-D*D*(M-C))⁻¹) 0 := by + simpa only [zero_smul,add_zero,mul_neg,neg_mul,neg_neg,mul_assoc] using! hi + exact hi'.congr_of_eventuallyEq he + +end SKGap.RealComplex + +end +end +end +end +end +end +end +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/RealQuadratic.lean b/lean/OAI/Probability/SKGap/Localization/RealQuadratic.lean new file mode 100644 index 0000000000000000000000000000000000000000..678827d5a373226fb1f7a85d8d8a2abdeb97a833 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/RealQuadratic.lean @@ -0,0 +1,138 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.Quadratic +import OAI.Probability.SKGap.Matrix.LiftMatrix + +namespace OAI + +section +noncomputable section +open MeasureTheory ProbabilityTheory InformationTheory Real Set +open scoped NNReal ENNReal +open Filter +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius ENNReal NNReal +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius NNReal +noncomputable section +open MeasureTheory ProbabilityTheory Real Set Filter +open MeasureTheory.Measure +open scoped ENNReal NNReal MeasureTheory Topology +open MeasureTheory +noncomputable section +noncomputable section +open MeasureTheory Set NormedSpace +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius +noncomputable section +open Set Real +open scoped Topology +noncomputable section +open Matrix Set Filter +open scoped Topology Matrix.Norms.Frobenius +noncomputable section +open Matrix NormedSpace ContinuousLinearMap +open scoped Matrix.Norms.Frobenius +noncomputable section +open Matrix +noncomputable section +open MeasureTheory ProbabilityTheory Real Set +open scoped ENNReal NNReal +noncomputable section +open MeasureTheory ProbabilityTheory InformationTheory Real Set +open scoped NNReal ENNReal +noncomputable section +open scoped BigOperators +open MeasureTheory ProbabilityTheory +open Real +noncomputable section +open scoped BigOperators Topology +open Filter Real +namespace SKGap.RealComplex +open SKGap.ComplexSpectral +open scoped BigOperators Matrix.Norms.Frobenius +variable {ι : Type*} [Fintype ι] [DecidableEq ι] + +def realQuadratic (M : Matrix ι ι ℝ) (x : EuclideanSpace ℝ ι) : ℝ := + ∑ i, ∑ k, x i * M i k * x k + +omit [DecidableEq ι] in +lemma quadratic_lift_split (M : Matrix ι ι ℝ) (x : EuclideanSpace ℂ ι) : + quadratic (liftMatrix M) x = realQuadratic M (reVec x)+realQuadratic M (imVec x) := by + change (∑ i, star (x i)*∑ k, (M i k:ℂ)*x k).re = _ + simp only [Finset.mul_sum,Complex.re_sum,Complex.mul_re,Complex.mul_im,Complex.star_def, + Complex.conj_re,Complex.conj_im,Complex.ofReal_re,Complex.ofReal_im, + zero_mul,sub_zero,realQuadratic,reVec,imVec,PiLp.toLp_apply, + ← Finset.sum_add_distrib] + apply Finset.sum_congr rfl + intro i _ + apply Finset.sum_congr rfl + intro k _ + ring + +omit [DecidableEq ι] in +lemma lowerRayleigh_lift_ge [Nonempty ι] {M : Matrix ι ι ℝ} {c : ℝ} + (hc : ∀ x : EuclideanSpace ℝ ι, c*‖x‖^2 ≤ realQuadratic M x) : + c ≤ lowerRayleigh (liftMatrix M) := by + apply lowerRayleigh_ge + intro x hx + have hn : ‖x‖ = 1 := by simpa only [unitSphere,Metric.mem_sphere,dist_zero_right] using hx + have h := add_le_add (hc (reVec x)) (hc (imVec x)) + rw [← mul_add,← vec_norm_split,hn,one_pow,mul_one,← quadratic_lift_split] at h + exact h + +lemma quadratic_eq_inner (M : Matrix ι ι ℂ) (x : EuclideanSpace ℂ ι) : + quadratic M x = (inner ℂ x (clin M x)).re := by + rw [PiLp.inner_apply] + change (∑ i, star (x i)*(∑ k, M i k*x k)).re = + (∑ i, (∑ k, M i k*x k)*star (x i)).re + congr 1 + apply Finset.sum_congr rfl + intro i _ + ring + +lemma lowerRayleigh_ge_neg_norm [Nonempty ι] (M : Matrix ι ι ℂ) : + -‖clin M‖ ≤ lowerRayleigh M := by + apply lowerRayleigh_ge + intro x hx + have hn : ‖x‖ = 1 := by simpa only [unitSphere,Metric.mem_sphere,dist_zero_right] using hx + rw [quadratic_eq_inner] + have hh := (norm_inner_le_norm (𝕜 := ℂ) x (clin M x)).trans + (mul_le_mul_of_nonneg_left ((clin M).le_opNorm x) (norm_nonneg x)) + rw [hn,mul_one,one_mul] at hh + exact (neg_le_neg ((Complex.abs_re_le_norm _).trans hh)).trans (neg_abs_le _) + +lemma lowerRayleigh_neg_lift_ge [Nonempty ι] (M : Matrix ι ι ℝ) : + -opNorm M ≤ lowerRayleigh (-liftMatrix M) := by + have h := lowerRayleigh_ge_neg_norm (-liftMatrix M) + have he : clin (-liftMatrix M) = -clin (liftMatrix M) := by + ext x i + change (∑ k, -(liftMatrix M i k)*x k) = -(∑ k, liftMatrix M i k*x k) + simp only [neg_mul,Finset.sum_neg_distrib] + rw [he,norm_neg,operator_norm_lift] at h + exact h + +end SKGap.RealComplex + +end +end +end +end +end +end +end +end +end +end +end +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/RecipeArgumentPullback.lean b/lean/OAI/Probability/SKGap/Localization/RecipeArgumentPullback.lean new file mode 100644 index 0000000000000000000000000000000000000000..9be2df1cb2d5e97801a7a335184c2b2a48acaf7b --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/RecipeArgumentPullback.lean @@ -0,0 +1,221 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.RecipeCoefficientClosure +import OAI.Probability.SKGap.Localization.StartedRecipe + +namespace OAI + +section + +noncomputable section +open scoped BigOperators +namespace SKGapCutoff.Recipe +open Primary +variable {n : ℕ} {ι κ ι₀ κ₀ : Type*} +variable [Fintype ι] [DecidableEq ι] [Fintype κ] [DecidableEq κ] +variable [Fintype ι₀] [DecidableEq ι₀] [Fintype κ₀] [DecidableEq κ₀] + +def argumentSelect (l : ι₀→ι) (p : κ₀→κ) : + Args (ι:=ι) (κ:=κ)→L[ℝ]Args (ι:=ι₀) (κ:=κ₀) := + ContinuousLinearMap.pi (fun q=>ContinuousLinearMap.proj (Sum.map l p q)) + +omit [Fintype ι] [DecidableEq ι] [Fintype κ] [DecidableEq κ] + [Fintype ι₀] [DecidableEq ι₀] [Fintype κ₀] [DecidableEq κ₀] in +@[simp] lemma argumentSelect_apply (l : ι₀→ι) (p : κ₀→κ) + (u : Args (ι:=ι) (κ:=κ)) (q : ι₀⊕κ₀) : + argumentSelect l p u q=u (Sum.map l p q) := rfl + +omit [DecidableEq ι] [DecidableEq κ] [DecidableEq ι₀] [DecidableEq κ₀] in +lemma argumentSelect_norm (l : ι₀→ι) (p : κ₀→κ) : ‖argumentSelect l p‖≤1 := by + apply ContinuousLinearMap.opNorm_le_bound _ (by norm_num) + intro u + rw [one_mul] + apply (pi_norm_le_iff_of_nonneg (norm_nonneg u)).mpr + intro q + exact norm_le_pi_norm u (Sum.map l p q) + +omit [Fintype ι] [DecidableEq ι] [Fintype κ] [DecidableEq κ] + [Fintype ι₀] [DecidableEq ι₀] [Fintype κ₀] [DecidableEq κ₀] in +lemma argumentSelect_local (l : ι₀→ι) (p : κ₀→κ) + (H : ι→VectorFields n) (θ : κ→Spin n→ℝ) (x : Spin n) (i : Fin n) : + argumentSelect l p (localArgs H θ x i)=localArgs (H∘l) (θ∘p) x i := by + ext q;cases q <;> rfl + +omit [DecidableEq ι] [DecidableEq κ] [DecidableEq ι₀] [DecidableEq κ₀] in +lemma SegmentRegular.argumentPullback (l : ι₀→ι) (p : κ₀→κ) + {H : ι→VectorFields n} {θ : κ→Spin n→ℝ} + {F : Fin n→Args (ι:=ι₀) (κ:=κ₀)→ℝ} + {F' : Fin n→Args (ι:=ι₀) (κ:=κ₀)→Args (ι:=ι₀) (κ:=κ₀)→L[ℝ]ℝ} + {x : Spin n} {C : ℝ} (h : SegmentRegular (H∘l) (θ∘p) F F' x C) : + SegmentRegular H θ (fun i u=>F i (argumentSelect l p u)) + (fun i u=>(F' i (argumentSelect l p u)).comp (argumentSelect l p)) x C := by + let P:=argumentSelect l p + have hp : ‖P‖≤1:=argumentSelect_norm l p + have hn (G : Args (ι:=ι₀) (κ:=κ₀)→L[ℝ]ℝ) : ‖G.comp P‖≤‖G‖ := + (G.opNorm_comp_le P).trans (by simpa using mul_le_mul_of_nonneg_left hp (norm_nonneg G)) + have hs (i k : Fin n) (t : ℝ) : + P (localArgs H θ x i+t • (localArgs H θ (flip x k) i-localArgs H θ x i))= + localArgs (H∘l) (θ∘p) x i+t • + (localArgs (H∘l) (θ∘p) (flip x k) i-localArgs (H∘l) (θ∘p) x i) := by + simp [P,map_add,map_smul,map_sub,argumentSelect_local] + refine ⟨h.nonneg,?_,?_,?_⟩ + · intro i k t ht + have hh:=h.deriv i k t ht + rw [←hs] at hh + exact hh.comp + (localArgs H θ x i+t • (localArgs H θ (flip x k) i-localArgs H θ x i)) P.hasFDerivAt + · intro i k t ht + exact (hn _).trans (by rw [hs];exact h.bound i k t ht) + · intro i k t ht + rw [←ContinuousLinearMap.sub_comp] + apply (hn _).trans + rw [hs,show P (localArgs H θ x i)=localArgs (H∘l) (θ∘p) x i from argumentSelect_local l p H θ x i] + apply (h.lip i k t ht).trans + apply mul_le_mul_of_nonneg_left _ h.nonneg + have hh:=P.le_opNorm (t • (localArgs H θ (flip x k) i-localArgs H θ x i)) + have hh':=hh.trans (mul_le_mul_of_nonneg_right hp (norm_nonneg _)) + simpa only [P,map_smul,map_sub,argumentSelect_local,one_mul] using hh' + +namespace OrdinaryData +variable {σ : Type*} [Fintype σ] + +def argumentPullback (D : OrdinaryData n ι₀ κ₀ σ) (l : ι₀→ι) (p : κ₀→κ) + (H U : ι→VectorFields n) (θ : κ→Spin n→ℝ) : OrdinaryData n ι κ σ where + J:=D.J + j:=D.j + H:=H + predecessor:=U + θ:=θ + seed:=D.seed + seedFunction:=fun a b i u=>D.seedFunction a b i (argumentSelect l p u) + seedDerivative:=fun a b i u=>(D.seedDerivative a b i (argumentSelect l p u)).comp (argumentSelect l p) + auxFunction:=fun a b i u=>D.auxFunction a b i (argumentSelect l p u) + auxDerivative:=fun a b i u=>(D.auxDerivative a b i (argumentSelect l p u)).comp (argumentSelect l p) + +omit [Fintype σ] in +lemma CoefficientClass.argumentPullback {D : OrdinaryData n ι₀ κ₀ σ} {N : ℕ} + {x : Spin n} {K : ℝ} (h : D.CoefficientClass N x K) + (l : ι₀→ι) (p : κ₀→κ) (H U : ι→VectorFields n) (θ : κ→Spin n→ℝ) + (hH : H∘l=D.H) (hθ : θ∘p=D.θ) : + (D.argumentPullback l p H U θ).CoefficientClass N x K := by + refine ⟨h.one_le,?_,?_,?_,?_⟩ + · intro a ha b + dsimp only [OrdinaryData.argumentPullback] + apply SegmentRegular.argumentPullback l p + simpa only [hH,hθ] using h.seedRegular a ha b + · intro a ha b + dsimp only [OrdinaryData.argumentPullback] + apply SegmentRegular.argumentPullback l p + simpa only [hH,hθ] using h.auxRegular a ha b + · intro a ha b i k t ht + dsimp only [OrdinaryData.argumentPullback] + simpa only [map_add,map_smul,map_sub,argumentSelect_local,hH,hθ] using + h.seedValue a ha b i k t ht + · intro a ha b i k t ht + dsimp only [OrdinaryData.argumentPullback] + simpa only [map_add,map_smul,map_sub,argumentSelect_local,hH,hθ] using + h.auxValue a ha b i k t ht +end OrdinaryData +end SKGapCutoff.Recipe + +end +end + +section + +noncomputable section +open scoped BigOperators +namespace SKGapCutoff.Recipe +open Primary +variable {n : ℕ} {ι κ κ₀ σ : Type*} +variable [Fintype ι] [DecidableEq ι] [Fintype κ] [DecidableEq κ] +variable [Fintype κ₀] [DecidableEq κ₀] [Fintype σ] + +omit [Fintype ι] [Fintype κ] [Fintype κ₀] in +lemma argumentSelect_single_primary (l : ι) (p : κ₀→κ) (q : ι) : + argumentSelect (fun _ : Unit=>l) p (Pi.single (.inl q) 1)= + if q=l then (Pi.single (.inl ()) 1 : Args (ι:=Unit) (κ:=κ₀)) else 0 := by + by_cases hq : q=l + · subst q; ext s; cases s with + | inl s=>cases s;simp [argumentSelect_apply] + | inr s=>simp [argumentSelect_apply] + · ext s; cases s with + | inl s=>cases s;simp [argumentSelect_apply,hq,Ne.symm hq] + | inr s=>simp [argumentSelect_apply,hq] + +namespace OrdinaryData +variable (D : OrdinaryData n Unit κ₀ σ) (l : ι) (p : κ₀→κ) +variable (H U : ι→VectorFields n) (θ : κ→Spin n→ℝ) +variable (hH : H∘(fun _:Unit=>l)=D.H) (hθ : θ∘p=D.θ) +include hH hθ + +omit [Fintype σ] in +lemma unitPullback_seedCoefficient (a : ℕ) (s : σ) : + (D.argumentPullback (fun _:Unit=>l) p H U θ).seedCoefficient a s=D.seedCoefficient a s := by + ext x i + simp only [seedCoefficient,coefficient,argumentPullback,argumentSelect_local,hH,hθ] + +omit [Fintype σ] in +lemma unitPullback_auxCoefficient (a : ℕ) (b : Fin a) : + (D.argumentPullback (fun _:Unit=>l) p H U θ).auxCoefficient a b=D.auxCoefficient a b := by + ext x i + simp only [auxCoefficient,coefficient,argumentPullback,argumentSelect_local,hH,hθ] + +lemma unitPullback_sourceOf (a : ℕ) (Y : Fin a→VectorFields n) : + (D.argumentPullback (fun _:Unit=>l) p H U θ).sourceOf a Y=D.sourceOf a Y := by + ext x i + simp only [sourceOf,unitPullback_seedCoefficient D l p H U θ hH hθ, + unitPullback_auxCoefficient D l p H U θ hH hθ] + rfl + +omit [Fintype σ] in +lemma unitPullback_seedPartial (a : ℕ) (q : ι) (s : σ) : + (D.argumentPullback (fun _:Unit=>l) p H U θ).seedPartial a q s= + if q=l then D.seedPartial a () s else 0 := by + by_cases hq : q=l <;> ext x i <;> + simp [seedPartial,localPartial,argumentPullback,partialAt, + ContinuousLinearMap.comp_apply,argumentSelect_local,hH,hθ,argumentSelect_single_primary,hq] + +omit [Fintype σ] in +lemma unitPullback_auxPartial (a : ℕ) (q : ι) (b : Fin a) : + (D.argumentPullback (fun _:Unit=>l) p H U θ).auxPartial a q b= + if q=l then D.auxPartial a () b else 0 := by + by_cases hq : q=l <;> ext x i <;> + simp [auxPartial,localPartial,argumentPullback,partialAt, + ContinuousLinearMap.comp_apply,argumentSelect_local,hH,hθ,argumentSelect_single_primary,hq] + +lemma unitPullback_partialOf (a : ℕ) (q : ι) (Y : Fin a→VectorFields n) : + (D.argumentPullback (fun _:Unit=>l) p H U θ).partialOf a q Y= + if q=l then D.partialOf a () Y else 0 := by + ext x i + simp only [partialOf,unitPullback_seedPartial D l p H U θ hH hθ, + unitPullback_auxPartial D l p H U θ hH hθ] + by_cases hq : q=l <;> simp [hq,argumentPullback,partialOf] + +lemma unitPullback_fieldOf (hU : U l=D.predecessor ()) (a : ℕ) (W Y : Fin a→VectorFields n) : + (D.argumentPullback (fun _:Unit=>l) p H U θ).fieldOf a W Y=D.fieldOf a W Y := by + ext x i + simp only [fieldOf,unitPullback_sourceOf D l p H U θ hH hθ, + unitPullback_partialOf D l p H U θ hH hθ, + unitPullback_auxCoefficient D l p H U θ hH hθ] + have hm (q : ι) : siteMean (if q=l then D.partialOf a () Y else 0) x*U q x i= + if q=l then siteMean (D.partialOf a () Y) x*U l x i else 0 := by + split_ifs with hq + · subst q;rfl + · simp [siteMean] + simp only [argumentPullback,hm,Finset.sum_ite_eq',Finset.mem_univ,ite_true,hU,Fintype.sum_unique] + +lemma unitPullback_started_duplicate (hU : U l=D.predecessor ()) (w y : VectorFields n) + (x : Spin n) (hw : w x=D.sourceOf 1 (fun _=>y) x) + (hy : y x=D.fieldOf 1 (fun _=>w) (fun _=>y) x) : + (D.argumentPullback (fun _:Unit=>l) p H U θ).startedSource w y 1 x=w x ∧ + (D.argumentPullback (fun _:Unit=>l) p H U θ).startedAuxiliary w y 1 x=y x := by + rw [startedSource_one,startedAuxiliary_one,unitPullback_sourceOf D l p H U θ hH hθ, + unitPullback_fieldOf D l p H U θ hH hθ hU] + exact ⟨hw.symm,hy.symm⟩ +end OrdinaryData +end SKGapCutoff.Recipe + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/RecipeBound.lean b/lean/OAI/Probability/SKGap/Localization/RecipeBound.lean new file mode 100644 index 0000000000000000000000000000000000000000..e786fc2b36f15e8ade26330924d9e1366263749e --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/RecipeBound.lean @@ -0,0 +1,96 @@ +import Mathlib +import OAI.Probability.SKGap.Stability.OrdinaryRecipe + +namespace OAI + +section + +noncomputable section +open scoped BigOperators Matrix.Norms.Frobenius +namespace SKGapCutoff.Recipe +open Primary Matrix + +def recipeBudget (c S : ℝ) (a : ℕ) : ℝ := c*(S+∑b:Fin a,recipeBudget c S b) +termination_by a + +lemma recipeBudget_nonneg {c S : ℝ} (hc : 0≤c) (hS : 0≤S) (a : ℕ) : 0≤recipeBudget c S a := by + induction a using Nat.strong_induction_on with + | h a ih => + rw [recipeBudget] + exact mul_nonneg hc (add_nonneg hS (Finset.sum_nonneg fun b _=>ih b b.isLt)) + +def recipeCost (A R L P j : ℝ) (d : ℕ) : ℝ := + (A+3*R)*(1+L+|j| *((d:ℝ)*(1+3*P)+1)) + +lemma recipeCost_nonneg {A R L P j : ℝ} {d : ℕ} (hA : 0≤A) (hR : 0≤R) (hL : 0≤L) (hP : 0≤P) : + 0≤recipeCost A R L P j d := by unfold recipeCost; positivity + +lemma recipeCost_ge {A R L P j : ℝ} {d : ℕ} (hA : 0≤A) (hR : 0≤R) (hL : 0≤L) (hP : 0≤P) : + A+3*R ≤ recipeCost A R L P j d := by + have hT : 0≤A+3*R := by positivity + have hd : 0≤|j| *((d:ℝ)*(1+3*P)+1) := by positivity + unfold recipeCost + nlinarith [mul_nonneg hT hL,mul_nonneg hT hd] + +variable {n : ℕ} {ι κ σ : Type*} [Fintype ι] [DecidableEq ι] [Fintype κ] [DecidableEq κ] [Fintype σ] +namespace OrdinaryData +variable (D : OrdinaryData n ι κ σ) + +theorem evaluation_small (N : ℕ) (x : Spin n) (hn : 0 + intro haN + let B : Fin a→ℝ := fun b=>recipeBudget c S b + let I : ℝ := S+∑b,B b + let Z : ℝ := I*(A+3*R) + have hB : ∀b,0≤B b := fun b=>recipeBudget_nonneg hc hS b + have hI : 0≤I := add_nonneg hS (Finset.sum_nonneg fun b _=>hB b) + have hY : ∀b:Fin a,SmallBound (D.auxiliary b) x (B b) := fun b=>(ih b b.isLt (b.isLt.le.trans haN)).2.1 + have hW : ∀b:Fin a,SmallBound (D.source b) x (B b) := fun b=>(ih b b.isLt (b.isLt.le.trans haN)).1 + have hw : SmallBound (D.sourceOf a (fun b=>D.auxiliary b)) x Z := + (D.sourceOf_bound a _ x B hY (hs a haN) (ha a haN)).mono + (mul_le_mul_of_nonneg_right (show (∑s,vectorNorm (D.seed s))+(∑b,B b) ≤ I from add_le_add hseed le_rfl) hT) + have hp : ∀l,SmallBound (D.partialOf a l (fun b=>D.auxiliary b)) x Z := fun l=> + (D.partialOf_bound a l _ x B hY (hsp a haN l) (hap a haN l)).mono + (mul_le_mul_of_nonneg_right (show (∑s,vectorNorm (D.seed s))+(∑b,B b) ≤ I from add_le_add hseed le_rfl) hT) + have hZ : Z≤recipeBudget c S a := by + rw [recipeBudget] + exact (mul_le_mul_of_nonneg_left hcg hI).trans_eq (by dsimp [I,B]; ring) + have hf:=D.fieldOf_bound a (fun b=>D.source b) (fun b=>D.auxiliary b) x hn B hL hP hJ hw hp hW hm hdm (ha a haN) + have hfC : (L*Z+|D.j| *((Fintype.card ι:ℝ)*(Z*(1+3*P))))+ + |D.j| *((∑b,B b)*(A+3*R))≤recipeBudget c S a := by + rw [recipeBudget] + change _ ≤ c*I + dsimp [c,recipeCost,Z,I] + have h1 : 0≤(S+∑b,B b)*(A+3*R) := mul_nonneg hI hT + have h2 : 0≤|D.j| *(S*(A+3*R)) := mul_nonneg (abs_nonneg _) (mul_nonneg hS hT) + nlinarith only [h1,h2] + refine ⟨?_,?_,?_⟩ + · rw [D.source_eq]; exact hw.mono hZ + · rw [D.auxiliary_eq]; exact hf.mono hfC + · intro l; exact (hp l).mono hZ + +end OrdinaryData +end SKGapCutoff.Recipe + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/RecipeCoefficientClosure.lean b/lean/OAI/Probability/SKGap/Localization/RecipeCoefficientClosure.lean new file mode 100644 index 0000000000000000000000000000000000000000..9a2e02b5251c7772ddc3c105fc8a3d6d7db3267d --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/RecipeCoefficientClosure.lean @@ -0,0 +1,133 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.ResidualAdmissibility + +namespace OAI + +section + +noncomputable section +open scoped BigOperators +namespace SKGapCutoff.Recipe +variable {n : ℕ} {ι κ σ : Type*} [Fintype ι] [DecidableEq ι] [Fintype κ] [DecidableEq κ] [Fintype σ] + +def SegmentValue (H : ι→VectorFields n) (θ : κ→Spin n→ℝ) + (F : Fin n→Args (ι:=ι) (κ:=κ)→ℝ) (x : Spin n) (K : ℝ) : Prop := + ∀i k t,t∈Set.Icc (0:ℝ) 1→|F i (localArgs H θ x i+t • (localArgs H θ (flip x k) i-localArgs H θ x i))|≤K + +omit [Fintype ι] [DecidableEq ι] [Fintype κ] [DecidableEq κ] in +lemma SegmentValue.at {H : ι→VectorFields n} {θ : κ→Spin n→ℝ} + {F : Fin n→Args (ι:=ι) (κ:=κ)→ℝ} {x : Spin n} {K : ℝ} + (h : SegmentValue H θ F x K) (i : Fin n) : |coefficient H θ F x i|≤K := by + simpa [coefficient] using h i i 0 (by constructor <;> norm_num) + +omit [DecidableEq ι] [DecidableEq κ] in +lemma segmentRegular_const (H : ι→VectorFields n) (θ : κ→Spin n→ℝ) (x : Spin n) (c : ℝ) : + SegmentRegular H θ (fun _ _=>c) (fun _ _=>0) x 0 := by + refine ⟨le_rfl,fun _ _ _ _=>hasFDerivAt_const _ _,?_,?_⟩ + · intros; simp + · intros; simp + +namespace OrdinaryData + +structure CoefficientClass (D : OrdinaryData n ι κ σ) (N : ℕ) (x : Spin n) (K : ℝ) : Prop where + one_le : 1≤K + seedRegular : ∀a≤N,∀s,SegmentRegular D.H D.θ (D.seedFunction a s) (D.seedDerivative a s) x K + auxRegular : ∀a≤N,∀b,SegmentRegular D.H D.θ (D.auxFunction a b) (D.auxDerivative a b) x K + seedValue : ∀a≤N,∀s,SegmentValue D.H D.θ (D.seedFunction a s) x K + auxValue : ∀a≤N,∀b,SegmentValue D.H D.θ (D.auxFunction a b) x K + +omit [Fintype σ] in +lemma CoefficientClass.prefix {D : OrdinaryData n ι κ σ} {N A : ℕ} {x : Spin n} {K : ℝ} + (h : D.CoefficientClass N x K) (ha : A≤N) : D.CoefficientClass A x K := + ⟨h.one_le,fun a hh=>h.seedRegular a (hh.trans ha),fun a hh=>h.auxRegular a (hh.trans ha), + fun a hh=>h.seedValue a (hh.trans ha),fun a hh=>h.auxValue a (hh.trans ha)⟩ + +omit [Fintype σ] in +lemma CoefficientClass.appendProduct {D : OrdinaryData n ι κ σ} {N : ℕ} {x : Spin n} {K B : ℝ} + (h : D.CoefficientClass N x K) (hB : 0≤B) + (F : Fin n→Args (ι:=ι) (κ:=κ)→ℝ) (F') + (hr : SegmentRegular D.H D.θ F F' x B) (hv : SegmentValue D.H D.θ F x B) : + (D.appendProduct N F F').CoefficientClass (N+1) x (K+4*B*K) := by + have hK : 0≤K := le_trans (by norm_num) h.one_le + have hk : K≤K+4*B*K := le_add_of_nonneg_right (by positivity) + have hbk : B*K≤K+4*B*K := by nlinarith [mul_nonneg hB hK] + have hrk : B*K+K*B+2*B*K≤K+4*B*K := by nlinarith + have hrold (G G') (hg : SegmentRegular D.H D.θ G G' x K) : + SegmentRegular D.H D.θ G G' x (K+4*B*K) := hg.mono hk + have hrnew (G G') (hg : SegmentRegular D.H D.θ G G' x K) + (hgv : SegmentValue D.H D.θ G x K) : + SegmentRegular D.H D.θ (fun i u=>F i u*G i u) + (fun i u=>F i u • G' i u+G i u • F' i u) x (K+4*B*K) := + (hr.mul hg hB hK hv hgv).mono hrk + refine ⟨h.one_le.trans hk,?_,?_,?_,?_⟩ + · intro a ha s + by_cases he : a=N+1 + · subst a + simpa only [OrdinaryData.appendProduct,ite_true] using hrnew _ _ (h.seedRegular N le_rfl s) (h.seedValue N le_rfl s) + · have haN : a≤N := by omega + simpa only [OrdinaryData.appendProduct,ite_eq_right he] using hrold _ _ (h.seedRegular a haN s) + · intro a ha b + by_cases he : a=N+1 + · subst a + by_cases hb : b.valcoefficient H θ F x i*s x i) x= + Matrix.diagonal (coefficient H θ F x)*derivativeMatrix s x+ + (∑l,Matrix.diagonal (fun i=>s x i*localPartial H θ F' (.inl l) x i)*derivativeMatrix (H l) x)+ + sourceError H θ F F' s x := by unfold sourceError; abel + +namespace OrdinaryData +variable (D : OrdinaryData n ι κ σ) + +def sourceAtoms (a : ℕ) (Y : Fin a→VectorFields n) (x : Spin n) : Interaction n := + (∑s,sourceError D.H D.θ (D.seedFunction a s) (D.seedDerivative a s) (fun _=>D.seed s) x)+ + ∑b,sourceError D.H D.θ (D.auxFunction a b) (D.auxDerivative a b) (Y b) x + +lemma sourceOf_derivative (a : ℕ) (Y : Fin a→VectorFields n) (x : Spin n) : + derivativeMatrix (D.sourceOf a Y) x= + (∑b,Matrix.diagonal (D.auxCoefficient a b x)*derivativeMatrix (Y b) x)+ + (∑l,Matrix.diagonal (D.partialOf a l Y x)*derivativeMatrix (D.H l) x)+D.sourceAtoms a Y x := by + have he : D.sourceOf a Y=(fun x i=>(∑s,D.seedCoefficient a s x i*D.seed s i)+ + (∑b,D.auxCoefficient a b x i*Y b x i)) := rfl + rw [he,derivativeMatrix_add,derivativeMatrix_sum,derivativeMatrix_sum] + have hs (s : σ) := sourceError_rearrange D.H D.θ (D.seedFunction a s) + (D.seedDerivative a s) (fun _=>D.seed s) x + have hb (b : Fin a) := sourceError_rearrange D.H D.θ (D.auxFunction a b) + (D.auxDerivative a b) (Y b) x + change (∑s,derivativeMatrix (fun x i=>coefficient D.H D.θ (D.seedFunction a s) x i*D.seed s i) x)+ + (∑b,derivativeMatrix (fun x i=>coefficient D.H D.θ (D.auxFunction a b) x i*Y b x i) x)=_ + simp_rw [hs,hb] + simp only [Finset.sum_add_distrib] + have hz (s : σ) : derivativeMatrix (fun _ : Spin n=>D.seed s) x=0 := by + ext i k; simp [derivativeMatrix,halfDiff] + simp only [hz,mul_zero,Finset.sum_const_zero,zero_add] + have hparts : + (∑s,∑l,Matrix.diagonal (fun i=>D.seed s i*localPartial D.H D.θ (D.seedDerivative a s) (.inl l) x i)*derivativeMatrix (D.H l) x)+ + (∑b,∑l,Matrix.diagonal (fun i=>Y b x i*localPartial D.H D.θ (D.auxDerivative a b) (.inl l) x i)*derivativeMatrix (D.H l) x)= + ∑l,Matrix.diagonal (D.partialOf a l Y x)*derivativeMatrix (D.H l) x := by + rw [Finset.sum_comm (f:=fun s l=>Matrix.diagonal (fun i=>D.seed s i*localPartial D.H D.θ (D.seedDerivative a s) (.inl l) x i)*derivativeMatrix (D.H l) x), + Finset.sum_comm (f:=fun b l=>Matrix.diagonal (fun i=>Y b x i*localPartial D.H D.θ (D.auxDerivative a b) (.inl l) x i)*derivativeMatrix (D.H l) x), + ←Finset.sum_add_distrib] + apply Finset.sum_congr rfl; intro l _ + ext i k + simp only [Matrix.add_apply,Matrix.sum_apply,Matrix.diagonal_mul,partialOf,seedPartial,auxPartial, + add_mul,Finset.sum_mul] + congr 1 <;> (apply Finset.sum_congr rfl; intro b _; ring) + dsimp only [sourceAtoms] + rw [←hparts] + simp only [auxCoefficient] + abel + +def sourceDerivativeError (T : ι→SourceTree (Fin n→ℝ)) (x : Spin n) (a : ℕ) : Interaction n := + derivativeMatrix (D.source a) x-D.retainedSource T x a + +def fieldDerivativeError (T : ι→SourceTree (Fin n→ℝ)) (x : Spin n) (a : ℕ) : Interaction n := + derivativeMatrix (D.auxiliary a) x-D.retainedField T x a + +lemma source_error_recursion (T : ι→SourceTree (Fin n→ℝ)) (x : Spin n) (a : ℕ) : + D.sourceDerivativeError T x a= + (∑b:Fin a,Matrix.diagonal (D.auxCoefficient a b x)*D.fieldDerivativeError T x b)+ + (∑l,Matrix.diagonal (D.sourcePartial a l x)* + (derivativeMatrix (D.H l) x-SourceTree.fieldMatrix D.j D.J (T l)))+ + D.sourceAtoms a (fun b=>D.auxiliary b) x := by + rw [sourceDerivativeError,D.source_eq,D.sourceOf_derivative,D.retainedSource_eq] + simp only [fieldDerivativeError,mul_sub,Finset.sum_sub_distrib,sourcePartial] + abel + +lemma fieldOf_derivative (a : ℕ) (W Y : Fin a→VectorFields n) (x : Spin n) : + derivativeMatrix (D.fieldOf a W Y) x= + D.J*derivativeMatrix (D.sourceOf a Y) x- + (∑l,(D.j*siteMean (D.partialOf a l Y) x) • derivativeMatrix (D.predecessor l) x)- + (∑b,(D.j*siteMean (D.auxCoefficient a b) x) • derivativeMatrix (W b) x)- + D.j • ((∑l,averageError (siteMean (D.partialOf a l Y)) (D.predecessor l) x)+ + ∑b,averageError (siteMean (D.auxCoefficient a b)) (W b) x) := by + have he : D.fieldOf a W Y=(fun x i=>(0+D.J.mulVec (D.sourceOf a Y x) i)- + (D.j*(∑l,siteMean (D.partialOf a l Y) x*D.predecessor l x i))- + (D.j*(∑b,siteMean (D.auxCoefficient a b) x*W b x i))) := by + ext x i; simp [fieldOf] + rw [he,derivativeMatrix_sub,derivativeMatrix_sub] + simp only [Matrix.mulVec, dotProduct] + rw [derivativeMatrix_linear, + derivativeMatrix_smul,derivativeMatrix_smul,derivativeMatrix_sum,derivativeMatrix_sum] + have he₁ (l : ι) : derivativeMatrix (fun y i=>siteMean (D.partialOf a l Y) y*D.predecessor l y i) x= + siteMean (D.partialOf a l Y) x • derivativeMatrix (D.predecessor l) x+ + averageError (siteMean (D.partialOf a l Y)) (D.predecessor l) x := by unfold averageError; abel + have he₂ (b : Fin a) : derivativeMatrix (fun y i=>siteMean (D.auxCoefficient a b) y*W b y i) x= + siteMean (D.auxCoefficient a b) x • derivativeMatrix (W b) x+ + averageError (siteMean (D.auxCoefficient a b)) (W b) x := by unfold averageError; abel + simp only [he₁,he₂,Finset.sum_add_distrib,smul_add,Finset.smul_sum,smul_smul] + abel + +lemma field_error_recursion (T : ι→SourceTree (Fin n→ℝ)) (x : Spin n) (a : ℕ) : + D.fieldDerivativeError T x a=D.J*D.sourceDerivativeError T x a- + (∑l,(D.j*siteMean (D.sourcePartial a l) x) • + (derivativeMatrix (D.predecessor l) x-SourceTree.sourceMatrix D.j D.J (T l)))- + (∑b:Fin a,(D.j*siteMean (D.auxCoefficient a b) x) • D.sourceDerivativeError T x b)- + D.j • ((∑l,averageError (siteMean (D.sourcePartial a l)) (D.predecessor l) x)+ + ∑b:Fin a,averageError (siteMean (D.auxCoefficient a b)) (D.source b) x) := by + rw [fieldDerivativeError,D.auxiliary_eq,D.fieldOf_derivative,D.retainedField_eq] + rw [sourceDerivativeError,D.source_eq] + simp only [sourceDerivativeError,smul_sub,Finset.sum_sub_distrib,mul_sub,sourcePartial] + abel + +end OrdinaryData +end SKGapCutoff.Recipe + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/RecipeGraph.lean b/lean/OAI/Probability/SKGap/Localization/RecipeGraph.lean new file mode 100644 index 0000000000000000000000000000000000000000..55591db36abf59fb196255965bbd5b17cf1d41aa --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/RecipeGraph.lean @@ -0,0 +1,115 @@ +import Mathlib +import OAI.Probability.SKGap.Stability.OrdinaryRecipe +import OAI.Probability.SKGap.Localization.PrimaryDifferentiation +import OAI.Probability.SKGap.Stability.OrdinaryGraph + +namespace OAI + +section + +noncomputable section +open scoped BigOperators +namespace SKGap.Noncrossing.Primary.SourceTree +open Diagram +variable {ι : Type*} [Fintype ι] [DecidableEq ι] + +def branches : List ((ι→ℝ)×SourceTree (ι→ℝ))→SourceTree (ι→ℝ) + | [] => .leaf 0 + | (p,t)::ts => .branch p t (branches ts) + +omit [Fintype ι] [DecidableEq ι] in +lemma branches_leafMass (ts : List ((ι→ℝ)×SourceTree (ι→ℝ))) : (branches ts).leafMass=0 := by + induction ts with + | nil => rfl + | cons t ts ih => exact ih + +lemma branches_source (j : ℝ) (J : Matrix ι ι ℝ) (ts : List ((ι→ℝ)×SourceTree (ι→ℝ))) : + sourceMatrix j J (branches ts)=(ts.map (fun t=>Matrix.diagonal t.1*fieldMatrix j J t.2)).sum := by + induction ts with + | nil => simp [branches,sourceMatrix_leaf] + | cons t ts ih => simp [branches,sourceMatrix_branch,ih] + +lemma branches_field (j : ℝ) (J : Matrix ι ι ℝ) (ts : List ((ι→ℝ)×SourceTree (ι→ℝ))) : + fieldMatrix j J (branches ts)=J*sourceMatrix j J (branches ts)- + (ts.map (fun t=>(j*Diagram.mean t.1) • sourceMatrix j J t.2)).sum := by + induction ts with + | nil => simp [branches,sourceMatrix_leaf,fieldMatrix_leaf] + | cons t ts ih => + simp only [branches,sourceMatrix_branch,fieldMatrix_branch,List.map_cons,List.sum_cons,ih,mul_add] + abel + +end SKGap.Noncrossing.Primary.SourceTree +namespace SKGapCutoff.Primary +open SKGap.Noncrossing.Primary +variable {n : ℕ} + +def primaryTree (j : ℝ) (J : Interaction n) (h : Fin n→ℝ) (x : Spin n) : ℕ→SourceTree (Fin n→ℝ) + | 0 => .leaf 1 + | k+1 => .branch (primaryDiagonal j J h x k) (primaryTree j J h x k) (.leaf 0) + +lemma primaryTree_matrices (j : ℝ) (J : Interaction n) (h : Fin n→ℝ) (x : Spin n) (k : ℕ) : + SourceTree.sourceMatrix j J (primaryTree j J h x k)=formalMag j J h x k ∧ + SourceTree.fieldMatrix j J (primaryTree j J h x k)=formalField j J h x k := by + induction k with + | zero => simp [primaryTree,SourceTree.sourceMatrix_leaf,SourceTree.fieldMatrix_leaf, + formalMag,formalField,primaryMatrix] + | succ k ih => + constructor + · simp [primaryTree,SourceTree.sourceMatrix_branch,SourceTree.sourceMatrix_leaf,ih.2,formalMag] + · simp only [primaryTree,SourceTree.fieldMatrix_branch,SourceTree.fieldMatrix_leaf,zero_smul, + add_zero,ih.1,ih.2] + rw [formalField_succ,formalMag] + +end SKGapCutoff.Primary +namespace SKGapCutoff.Recipe.OrdinaryData +open SKGap.Noncrossing.Primary SKGap.Noncrossing.Diagram Primary Matrix +variable {n : ℕ} {ι κ σ : Type*} [Fintype ι] [DecidableEq ι] [Fintype κ] [DecidableEq κ] [Fintype σ] + +def retainedTree (D : OrdinaryData n ι κ σ) (T : ι→SourceTree (Fin n→ℝ)) (x : Spin n) + (a : ℕ) : SourceTree (Fin n→ℝ) := + SourceTree.branches ((Finset.univ.toList.map (fun l=>(D.sourcePartial a l x,T l)))++ + (Finset.univ.toList.map (fun b : Fin a=>(D.auxCoefficient a b x,retainedTree D T x b)))) +termination_by a + +lemma retainedTree_leafMass (D : OrdinaryData n ι κ σ) (T : ι→SourceTree (Fin n→ℝ)) + (x : Spin n) (a : ℕ) : (D.retainedTree T x a).leafMass=0 := by + rw [retainedTree,SourceTree.branches_leafMass] + +def retainedSource (D : OrdinaryData n ι κ σ) (T : ι→SourceTree (Fin n→ℝ)) (x : Spin n) (a : ℕ) := + SourceTree.sourceMatrix D.j D.J (D.retainedTree T x a) +def retainedField (D : OrdinaryData n ι κ σ) (T : ι→SourceTree (Fin n→ℝ)) (x : Spin n) (a : ℕ) := + SourceTree.fieldMatrix D.j D.J (D.retainedTree T x a) + +lemma retainedSource_eq (D : OrdinaryData n ι κ σ) (T : ι→SourceTree (Fin n→ℝ)) (x : Spin n) (a : ℕ) : + D.retainedSource T x a= + (∑l,Matrix.diagonal (D.sourcePartial a l x)*SourceTree.fieldMatrix D.j D.J (T l))+ + ∑b:Fin a,Matrix.diagonal (D.auxCoefficient a b x)*D.retainedField T x b := by + rw [retainedSource,retainedTree,SourceTree.branches_source] + simp [List.map_append,List.sum_append,List.map_map,Function.comp_def,retainedField] + +lemma retainedField_eq (D : OrdinaryData n ι κ σ) (T : ι→SourceTree (Fin n→ℝ)) (x : Spin n) (a : ℕ) : + D.retainedField T x a=D.J*D.retainedSource T x a- + (∑l,(D.j*siteMean (D.sourcePartial a l) x) • SourceTree.sourceMatrix D.j D.J (T l))- + ∑b:Fin a,(D.j*siteMean (D.auxCoefficient a b) x) • D.retainedSource T x b := by + have h:=SourceTree.branches_field D.j D.J + ((Finset.univ.toList.map (fun l=>(D.sourcePartial a l x,T l)))++ + (Finset.univ.toList.map (fun b:Fin a=>(D.auxCoefficient a b x,D.retainedTree T x b)))) + rw [show SourceTree.branches _=D.retainedTree T x a from (by rw [retainedTree])] at h + simpa [List.map_append,List.sum_append,List.map_map,Function.comp_def, + retainedField,retainedSource,siteMean,SKGap.Noncrossing.Diagram.mean, + sub_add_eq_sub_sub] using h + +theorem retained_prediction_zero (D : OrdinaryData n ι κ σ) (T : ι→SourceTree (Fin n→ℝ)) + (x : Spin n) (a : ℕ) (i : Fin n) : + polynomialPrediction D.j ((D.retainedTree T x a).words D.j).1 i=0 ∧ + polynomialPrediction D.j ((D.retainedTree T x a).words D.j).2 i=0 := by + constructor + · rw [SourceTree.source_prediction,retainedTree_leafMass] + · exact SourceTree.field_prediction_zero .. + +end SKGapCutoff.Recipe.OrdinaryData + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/RecipeIncrement.lean b/lean/OAI/Probability/SKGap/Localization/RecipeIncrement.lean new file mode 100644 index 0000000000000000000000000000000000000000..0988ba75dcb4c15cdd0588c866c1b8095ea95168 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/RecipeIncrement.lean @@ -0,0 +1,159 @@ +import Mathlib +import OAI.Probability.SKGap.Stability.OrdinaryRecipe +import OAI.Probability.SKGap.Matrix.Trace + +namespace OAI + +section + +noncomputable section +open scoped BigOperators Matrix.Norms.Frobenius +namespace SKGapCutoff.Recipe +open Primary Matrix +variable {n : ℕ} {ι κ : Type*} [Fintype ι] [Fintype κ] + +lemma finite_sum_fourth (f : ι→ℝ) : + (∑l,f l)^4≤(Fintype.card ι:ℝ)^3*∑l,(f l)^4 := by + have h1:=sq_sum_le_card_mul_sum_sq (s:=Finset.univ) (f:=f) + have h2:=sq_sum_le_card_mul_sum_sq (s:=Finset.univ) (f:=fun l=>(f l)^2) + simp only [Finset.card_univ] at h1 h2 + have hsq:=pow_le_pow_left₀ (sq_nonneg (∑l,f l)) h1 2 + have hh:=mul_le_mul_of_nonneg_left h2 (sq_nonneg (Fintype.card ι:ℝ)) + simp only [←pow_mul] at hsq hh + norm_num only [Nat.reduceMul] at hsq hh + nlinarith only [hsq,hh] + +lemma primaryIncrement_fourth (H : ι→VectorFields n) (x : Spin n) {P : ℝ} + (hP : 0≤P) (hH : ∀l,ShapeBound (derivativeMatrix (H l) x) P) : + (∑i,∑k,(primaryIncrement H x i k)^4)≤(2*(Fintype.card ι:ℝ)*P)^4 := by + have h1 : (∑i,∑k,(primaryIncrement H x i k)^4)≤ + (Fintype.card ι:ℝ)^3*∑l,∑i,∑k,(derivativeMatrix (H l) x i k)^4 := by + calc + _ ≤ ∑i,∑k,(Fintype.card ι:ℝ)^3*∑l,(derivativeMatrix (H l) x i k)^4 := by + apply Finset.sum_le_sum; intro i _; apply Finset.sum_le_sum; intro k _ + simpa only [primaryIncrement,show (4:ℕ)=2*2 from rfl,pow_mul,sq_abs] using finite_sum_fourth (fun l=>|derivativeMatrix (H l) x i k|) + _ = _ := by + simp_rw [←Finset.mul_sum] + congr 1 + rw [show (∑i,∑k,∑l,(derivativeMatrix (H l) x i k)^4)= + ∑i,∑l,∑k,(derivativeMatrix (H l) x i k)^4 from + Finset.sum_congr rfl (fun i _=>Finset.sum_comm)] + exact Finset.sum_comm + have h2 : (∑l,∑i,∑k,(derivativeMatrix (H l) x i k)^4)≤(Fintype.card ι:ℝ)*(2*P^4) := by + exact (Finset.sum_le_sum (fun l _=>fourth_sum_le hP (hH l))).trans_eq (by simp) + have h3 := h1.trans (mul_le_mul_of_nonneg_left h2 (by positivity)) + have hnn : 0≤(Fintype.card ι:ℝ)^4*P^4 := by positivity + nlinarith only [h3,hnn] + +lemma primaryIncrement_row (H : ι→VectorFields n) (x : Spin n) {P : ℝ} + (hP : 0≤P) (hH : ∀l,SKGap.opNorm (derivativeMatrix (H l) x)≤P) (i : Fin n) : + (∑k,(primaryIncrement H x i k)^2)≤((Fintype.card ι:ℝ)*P)^2 := by + have H₁ : vectorNorm (primaryIncrement H x i)≤(Fintype.card ι:ℝ)*P := by + calc + _ ≤ ∑l,vectorNorm (fun k=>|derivativeMatrix (H l) x i k|) := by + convert! vectorNorm_sum (fun l k=>|derivativeMatrix (H l) x i k|) using 1 + congr 1; ext k; simp [primaryIncrement] + _ ≤ ∑_l:ι,P := Finset.sum_le_sum fun l _=>by rw [vectorNorm_abs]; exact (row_vectorNorm_le_opNorm _ _).trans (hH l) + _ = _ := by simp + rw [←vectorNorm_sq] + exact (pow_le_pow_iff_left₀ (vectorNorm_nonneg _) + (mul_nonneg (Nat.cast_nonneg _) hP) (by decide : 2 ≠ 0)).2 H₁ + +lemma primaryIncrement_diagonal (H : ι→VectorFields n) (x : Spin n) {P : ℝ} + (hP : 0≤P) (hH : ∀l,SKGap.diagonalSeminorm (derivativeMatrix (H l) x)≤P) : + (∑i,(primaryIncrement H x i i)^2)≤((Fintype.card ι:ℝ)*P)^2 := by + have H₁ : vectorNorm (fun i=>primaryIncrement H x i i)≤(Fintype.card ι:ℝ)*P := by + calc + _ ≤ ∑l,vectorNorm (fun i=>|derivativeMatrix (H l) x i i|) := by + convert! vectorNorm_sum (fun l i=>|derivativeMatrix (H l) x i i|) using 1 + congr 1; ext i; simp [primaryIncrement] + _ ≤ ∑_l:ι,P := Finset.sum_le_sum fun l _=>by rw [vectorNorm_abs]; exact hH l + _ = _ := by simp + rw [←vectorNorm_sq] + exact (pow_le_pow_iff_left₀ (vectorNorm_nonneg _) + (mul_nonneg (Nat.cast_nonneg _) hP) (by decide : 2 ≠ 0)).2 H₁ + +lemma parameterIncrement_bound (θ : κ→Spin n→ℝ) (x : Spin n) : + vectorNorm (parameterIncrement θ x)≤∑α,‖derivativeVector (θ α) x‖ := by + calc + _ ≤ ∑α,vectorNorm (fun k=>|halfDiff k (θ α) x|) := by + convert! vectorNorm_sum (fun α k=>|halfDiff k (θ α) x|) using 1 + congr 1; ext k; simp [parameterIncrement] + _ = _ := by apply Finset.sum_congr rfl; intro α _; rw [vectorNorm_abs]; rfl + +end SKGapCutoff.Recipe + +end +end + +section + +noncomputable section +open scoped BigOperators +namespace SKGapCutoff.Recipe +open Primary Matrix +variable {n : ℕ} {ι κ : Type*} [Fintype ι] [DecidableEq ι] [Fintype κ] [DecidableEq κ] +variable {H : ι→VectorFields n} {θ : κ→Spin n→ℝ} +variable {F : Fin n→Args (ι:=ι) (κ:=κ)→ℝ} +variable {F' : Fin n→Args (ι:=ι) (κ:=κ)→Args (ι:=ι) (κ:=κ)→L[ℝ]ℝ} +variable {x : Spin n} {C : ℝ} + +lemma SegmentRegular.partial_difference (h : SegmentRegular H θ F F' x C) + (l : ι⊕κ) (i k : Fin n) : + |derivativeMatrix (localPartial H θ F' l) x i k|≤ + C*‖flipHalfDiff k (fun y=>localArgs H θ y i) x‖ := by + have hv : ‖(Pi.single l 1 : Args (ι:=ι) (κ:=κ))‖≤1 := by + apply (pi_norm_le_iff_of_nonneg (by norm_num : (0:ℝ)≤1)).mpr + intro a; simp only [Pi.single_apply]; split_ifs <;> norm_num + have hh:=h.lip i k 1 (by constructor <;> norm_num) + simp only [one_smul,add_sub_cancel] at hh + have H₁ := (F' i (localArgs H θ (flip x k) i)-F' i (localArgs H θ x i)).le_opNorm (Pi.single l 1) + have H₂ : |localPartial H θ F' l (flip x k) i-localPartial H θ F' l x i|≤ + C*‖localArgs H θ (flip x k) i-localArgs H θ x i‖ := by + apply H₁.trans + exact (mul_le_mul_of_nonneg_left hv (norm_nonneg _)).trans (by simpa only [mul_one] using hh) + rw [derivativeMatrix,halfDiff_as_flip,abs_div,abs_mul,abs_spin_eq_one,one_mul, + abs_of_pos (by norm_num : (0:ℝ)<2),flipHalfDiff_norm,abs_sub_comm] + exact (div_le_div_of_nonneg_right H₂ (by norm_num : (0:ℝ)≤2)).trans_eq (by ring) + +lemma SegmentRegular.partial_row (h : SegmentRegular H θ F F' x C) (l : ι⊕κ) (i : Fin n) : + vectorNorm (derivativeMatrix (localPartial H θ F' l) x i)≤ + C*((∑q,SKGap.opNorm (derivativeMatrix (H q) x))+(∑α,‖derivativeVector (θ α) x‖)) := by + calc + _ ≤ vectorNorm (fun k=>C*‖flipHalfDiff k (fun y=>localArgs H θ y i) x‖) := + vectorNorm_mono fun k=>by + rw [abs_of_nonneg (mul_nonneg h.nonneg (norm_nonneg _))] + exact h.partial_difference l i k + _ = C*vectorNorm (fun k=>‖flipHalfDiff k (fun y=>localArgs H θ y i) x‖) := by + convert! vectorNorm_smul C (fun k=>‖flipHalfDiff k (fun y=>localArgs H θ y i) x‖) using 1 + rw [abs_of_nonneg h.nonneg] + _ ≤ _ := mul_le_mul_of_nonneg_left (local_argument_row_bound H θ x i) h.nonneg + +omit [DecidableEq ι] [DecidableEq κ] in +lemma SegmentRegular.coefficient_bound (h : SegmentRegular H θ F F' x C) + {A G : ℝ} (hA : 0≤A) (hG : 0≤G) (hv : ∀i,|coefficient H θ F x i|≤A) + (hg : (∑q,SKGap.opNorm (derivativeMatrix (H q) x))+(∑α,‖derivativeVector (θ α) x‖)≤G) : + CoefficientBound (coefficient H θ F) x A (C*G) := by + refine ⟨hA,mul_nonneg h.nonneg hG,hv,?_⟩ + intro i + have H₁ := (coefficient_row_bound H θ F F' x i h.nonneg (h.deriv i) (h.bound i)).trans + (mul_le_mul_of_nonneg_left hg h.nonneg) + rw [←vectorNorm_sq] + exact pow_le_pow_left₀ (vectorNorm_nonneg _) H₁ 2 + +lemma SegmentRegular.partial_bound_coefficient (h : SegmentRegular H θ F F' x C) + (l : ι⊕κ) {A G : ℝ} (hA : 0≤A) (hG : 0≤G) (hCA : C≤A) + (hg : (∑q,SKGap.opNorm (derivativeMatrix (H q) x))+(∑α,‖derivativeVector (θ α) x‖)≤G) : + CoefficientBound (localPartial H θ F' l) x A (C*G) := by + refine ⟨hA,mul_nonneg h.nonneg hG,fun i=>(h.partial_bound i l).trans hCA,?_⟩ + intro i + have H₁ := (h.partial_row l i).trans (mul_le_mul_of_nonneg_left hg h.nonneg) + rw [←vectorNorm_sq] + exact pow_le_pow_left₀ (vectorNorm_nonneg _) H₁ 2 + +end SKGapCutoff.Recipe + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/RecipeMarked.lean b/lean/OAI/Probability/SKGap/Localization/RecipeMarked.lean new file mode 100644 index 0000000000000000000000000000000000000000..c6c410352f7b4cf3db101d65db14cf6ebb8aebc5 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/RecipeMarked.lean @@ -0,0 +1,120 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.RecipeGraph +import OAI.Probability.SKGap.Matrix.ClosedTrace + +namespace OAI + +section + +noncomputable section +open scoped BigOperators +namespace SKGap.Noncrossing.Primary.MarkedPolynomial +open Diagram +variable {n : ℕ} + +def diagonalWords (s : Fin n→ℝ) (P : WordPolynomial (ι:=Fin n)) : MarkedPolynomial n := + P.map (fun t=>(t.1,SmallMark.diagonal [] s t.2)) +def averageWords (c : ℝ) (s : Fin n→ℝ) (P : WordPolynomial (ι:=Fin n)) : MarkedPolynomial n := + P.map (fun t=>(c*t.1,SmallMark.average s t.2)) +def mass (P : WordPolynomial (ι:=Fin n)) : ℝ := (P.map (fun t=>|t.1|)).sum + +lemma plain_diagonalWords (s : Fin n→ℝ) (P : WordPolynomial (ι:=Fin n)) : + (diagonalWords s P).plain=prependWords [.diag s] P := by + simp [diagonalWords,plain,prependWords,List.map_map,Function.comp_def,SmallMark.scalar,SmallMark.word] +lemma plain_averageWords (c : ℝ) (s : Fin n→ℝ) (P : WordPolynomial (ι:=Fin n)) : + (averageWords c s P).plain=Primary.scale (c*Diagram.mean s) P := by + simp only [averageWords,plain,Primary.scale,List.map_map,Function.comp_def,SmallMark.scalar,SmallMark.word] + congr 1; funext t; congr 1; ring +lemma budget_diagonalWords (s : Fin n→ℝ) (P : WordPolynomial (ι:=Fin n)) : + (diagonalWords s P).budget=SKGapCutoff.Recipe.vectorNorm s*mass P := by + induction P with + | nil => simp [diagonalWords,budget,mass] + | cons t P ih => + simp only [diagonalWords,List.map_cons,budget,List.sum_cons,SmallMark.vector,mass] at * + rw [ih]; ring +lemma budget_averageWords (c : ℝ) (s : Fin n→ℝ) (P : WordPolynomial (ι:=Fin n)) : + (averageWords c s P).budget=|c| *SKGapCutoff.Recipe.vectorNorm s*mass P := by + induction P with + | nil => simp [averageWords,budget,mass] + | cons t P ih => + simp only [averageWords,List.map_cons,budget,List.sum_cons,SmallMark.vector,mass,abs_mul] at * + rw [ih]; ring + +abbrev Pair (n : ℕ) := MarkedPolynomial n×MarkedPolynomial n + +def pairPlain (V : Pair n) : WordPolynomial (ι:=Fin n)×WordPolynomial (ι:=Fin n) := (V.1.plain,V.2.plain) + +def zeroPair : Pair n := ([(0,.average 0 [])],[(0,.average 0 [.noise])]) +lemma zeroPair_plain (j : ℝ) : pairPlain (zeroPair (n:=n))=(SourceTree.leaf 0).words j := by + simp [pairPlain,zeroPair,plain,SmallMark.scalar,SmallMark.word,SourceTree.words] + +def smallBranch (j : ℝ) (p : Fin n→ℝ) (T : SourceTree (Fin n→ℝ)) (V : Pair n) : Pair n := + (diagonalWords p (T.words j).2++V.1, + ((diagonalWords p (T.words j).2).prepend [.noise]++averageWords (-j) p (T.words j).1)++V.2) + +def boundedBranch (j : ℝ) (p : Fin n→ℝ) (U V : Pair n) : Pair n := + (U.2.prepend [.diag p]++V.1, + (U.2.prepend [.noise,.diag p]++U.1.scale (-(j*Diagram.mean p)))++V.2) + +lemma smallBranch_plain (j : ℝ) (p : Fin n→ℝ) (T S : SourceTree (Fin n→ℝ)) (V : Pair n) + (hV : pairPlain V=S.words j) : pairPlain (smallBranch j p T V)=(SourceTree.branch p T S).words j := by + have hv₁ : V.1.plain=(S.words j).1 := congrArg Prod.fst hV + have hv₂ : V.2.plain=(S.words j).2 := congrArg Prod.snd hV + simp only [pairPlain,smallBranch,plain_append,plain_prefix,plain_diagonalWords,plain_averageWords,hv₁,hv₂, + SourceTree.words] + congr 1 + simp [prependWords,List.map_map,Function.comp_def,neg_mul] + +lemma boundedBranch_plain (j : ℝ) (p : Fin n→ℝ) (T S : SourceTree (Fin n→ℝ)) (U V : Pair n) + (hU : pairPlain U=T.words j) (hV : pairPlain V=S.words j) : + pairPlain (boundedBranch j p U V)=(SourceTree.branch p T S).words j := by + have hu₁ : U.1.plain=(T.words j).1 := congrArg Prod.fst hU + have hu₂ : U.2.plain=(T.words j).2 := congrArg Prod.snd hU + have hv₁ : V.1.plain=(S.words j).1 := congrArg Prod.fst hV + have hv₂ : V.2.plain=(S.words j).2 := congrArg Prod.snd hV + simp only [pairPlain,boundedBranch,plain_append,plain_prefix,plain_scale,hu₁,hu₂,hv₁,hv₂,SourceTree.words] + +lemma fold_plain {α : Type*} (j : ℝ) (xs : List α) (p : α→Fin n→ℝ) + (T : α→SourceTree (Fin n→ℝ)) (step : α→Pair n→Pair n) + (hstep : ∀a V S,pairPlain V=S.words j→pairPlain (step a V)=(SourceTree.branch (p a) (T a) S).words j) : + pairPlain (xs.foldr step zeroPair)=(SourceTree.branches (xs.map (fun a=>(p a,T a)))).words j := by + induction xs with + | nil => exact zeroPair_plain j + | cons a xs ih => exact hstep a _ _ ih + +end SKGap.Noncrossing.Primary.MarkedPolynomial +namespace SKGapCutoff.Recipe.OrdinaryData +open SKGap.Noncrossing.Primary SKGap.Noncrossing.Diagram MarkedPolynomial +variable {n : ℕ} {ι κ σ : Type*} [Fintype ι] [DecidableEq ι] [Fintype κ] [DecidableEq κ] [Fintype σ] + +def markedRecipe (D : OrdinaryData n ι κ σ) (T : ι→SourceTree (Fin n→ℝ)) (x : Spin n) (a : ℕ) : Pair n := + let entries : List (ι⊕Fin a) := Finset.univ.toList.map Sum.inl++Finset.univ.toList.map Sum.inr + entries.foldr (fun e V=>match e with + | .inl l => smallBranch D.j (D.sourcePartial a l x) (T l) V + | .inr b => boundedBranch D.j (D.auxCoefficient a b x) (markedRecipe D T x b) V) zeroPair +termination_by a + +theorem markedRecipe_plain (D : OrdinaryData n ι κ σ) (T : ι→SourceTree (Fin n→ℝ)) (x : Spin n) (a : ℕ) : + pairPlain (D.markedRecipe T x a)=(D.retainedTree T x a).words D.j := by + induction a using Nat.strong_induction_on with + | h a ih => + rw [markedRecipe,retainedTree] + have H:=fold_plain D.j (Finset.univ.toList.map (Sum.inl : ι→ι⊕Fin a)++Finset.univ.toList.map Sum.inr) + (Sum.elim (fun l=>D.sourcePartial a l x) (fun b=>D.auxCoefficient a b x)) + (Sum.elim T (fun b=>D.retainedTree T x b)) + (fun e V=>match e with + | .inl l=>smallBranch D.j (D.sourcePartial a l x) (T l) V + | .inr b=>boundedBranch D.j (D.auxCoefficient a b x) (D.markedRecipe T x b) V) + (by + intro e V S hV + cases e with + | inl l=>exact smallBranch_plain D.j _ _ _ _ hV + | inr b=>exact boundedBranch_plain D.j _ _ _ _ _ (ih b b.isLt) hV) + simpa only [List.map_append,List.map_map,Function.comp_def,Sum.elim_inl,Sum.elim_inr] using H + +end SKGapCutoff.Recipe.OrdinaryData + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/RecipePrimaryMass.lean b/lean/OAI/Probability/SKGap/Localization/RecipePrimaryMass.lean new file mode 100644 index 0000000000000000000000000000000000000000..69fd3f31ad8c6b81163b3aafb516656626e0436e --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/RecipePrimaryMass.lean @@ -0,0 +1,54 @@ +import Mathlib +import OAI.Probability.SKGap.Matrix.RecipeTraceBudget + +namespace OAI + +section + +noncomputable section +open scoped BigOperators +namespace SKGap.Noncrossing.Primary.MarkedPolynomial +variable {n : ℕ} +lemma mass_append (P Q : WordPolynomial (ι:=Fin n)) : mass (P++Q)=mass P+mass Q := by + simp [mass] +lemma mass_prefix (F : List (Letter (Fin n→ℝ))) (P : WordPolynomial (ι:=Fin n)) : + mass (prependWords F P)=mass P := by simp [mass,prependWords,List.map_map,Function.comp_def] +lemma mass_scale (c : ℝ) (P : WordPolynomial (ι:=Fin n)) : mass (Primary.scale c P)=|c| *mass P := by + induction P with + | nil => simp [mass,Primary.scale] + | cons t P ih => + simp only [Primary.scale,List.map_cons,mass,List.sum_cons,abs_mul] at * + rw [ih]; ring +end SKGap.Noncrossing.Primary.MarkedPolynomial +namespace SKGapCutoff.Primary +open SKGap.Noncrossing.Primary MarkedPolynomial +variable {n : ℕ} + +lemma primaryTree_mass (hn : 0 simp [primaryTree,SourceTree.words,mass] + | succ k ih => + have hm := mean_abs_le_one (primaryDiagonal_bounded j J h x k) + have hc : 0≤(2+|j|)^k := by positivity + have hj : 0≤|j| := abs_nonneg _ + have ht : |j*SKGap.Noncrossing.Diagram.mean (primaryDiagonal j J h x k)|≤|j| := by + rw [abs_mul]; simpa using mul_le_mul_of_nonneg_left hm hj + simp only [primaryTree,SourceTree.words,mass_append,mass_prefix,mass_scale] + have hz₁ : mass ([(0,[])] : WordPolynomial (ι:=Fin n))=0 := by simp [mass] + have hz₂ : mass ([(0,[.noise])] : WordPolynomial (ι:=Fin n))=0 := by simp [mass] + simp only [hz₁,hz₂,add_zero,abs_neg] + constructor + · rw [pow_succ]; nlinarith [ih.2,mul_nonneg hj hc] + · have ht' := mul_le_mul ht ih.1 (mass_nonneg _) hj + rw [pow_succ] + nlinarith [ih.2] + +end SKGapCutoff.Primary + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/Reference.lean b/lean/OAI/Probability/SKGap/Localization/Reference.lean new file mode 100644 index 0000000000000000000000000000000000000000..3f2902d1a585d5476e6d15b7bf42238d936fb67a --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/Reference.lean @@ -0,0 +1,418 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.LiteralRegularity + +namespace OAI + +namespace SKGap.GaussianStep +open MeasureTheory ProbabilityTheory Real Set Filter +open scoped BigOperators ENNReal NNReal +noncomputable section +variable {n : ℕ} + +def reference (n : ℕ) : Measure (Fin n → ℝ) := + Measure.pi (fun _ => gaussianReal 0 1) + +instance reference_probability (n : ℕ) : IsProbabilityMeasure (reference n) := + inferInstanceAs (IsProbabilityMeasure (Measure.pi _)) + +lemma integrable_exp_linear (a : Fin n → ℝ) : + Integrable (fun z => exp (∑ i, a i * z i)) (reference n) := by + simp_rw [exp_sum] + exact Integrable.fintype_prod (fun i => integrable_exp_mul_gaussianReal (μ := 0) (v := 1) (a i)) + +lemma integral_exp_linear (a : Fin n → ℝ) : + (∫ z, exp (∑ i, a i * z i) ∂reference n) = exp ((∑ i, (a i)^2) / 2) := by + simp_rw [exp_sum] + rw [reference, integral_fintype_prod_eq_prod (fun i (z : ℝ) => exp (a i*z))] + have hi (i : Fin n) : (∫ z : ℝ, exp (a i * z) ∂gaussianReal 0 1) = exp ((a i)^2/2) := by + simpa only [mgf, zero_mul, NNReal.coe_one, one_mul, zero_add, id_eq] using + mgf_gaussianReal (μ := 0) (v := 1) (X := id) (p := gaussianReal 0 1) (by simp) (a i) + simp_rw [hi] + rw [← exp_sum, Finset.sum_div] + +structure Prior (n : ℕ) where + mass : Spin n → ℝ + nonneg : ∀ x, 0 ≤ mass x + sum_one : ∑ x, mass x = 1 + +@[ext] lemma Prior.ext {p q : Prior n} (h : p.mass = q.mass) : p = q := by + cases p + cases q + congr + +instance : CoeFun (Prior n) (fun _ => Spin n → ℝ) := ⟨Prior.mass⟩ + +def gibbsPrior (g : Disorder n) (h : Fin n → ℝ) : Prior n := + ⟨mass g h, mass_nonneg g h, sum_mass g h⟩ + +def mean (p : Prior n) (i : Fin n) : ℝ := ∑ x, p x * spinValue (x i) + +def likelihood (t : ℝ) (x : Spin n) (z : Fin n → ℝ) : ℝ := + exp (sqrt t * (∑ i, spinValue (x i) * z i) - t * n / 2) + +def density (p : Prior n) (t : ℝ) (z : Fin n → ℝ) : ℝ := + ∑ x, p x * likelihood t x z + +lemma likelihood_pos (t : ℝ) (x : Spin n) (z : Fin n → ℝ) : + 0 < likelihood t x z := exp_pos _ + +lemma integrable_likelihood (t : ℝ) (x : Spin n) : + Integrable (likelihood t x) (reference n) := by + have he : likelihood t x = fun z => exp (∑ i, (sqrt t * spinValue (x i)) * z i) * + exp (-(t*n/2)) := by + funext z + simp only [likelihood, exp_sub, exp_neg, ← Finset.mul_sum, mul_assoc, div_eq_mul_inv] + rw [he] + exact (integrable_exp_linear _).mul_const _ + +lemma integral_likelihood {t : ℝ} (ht : 0 ≤ t) (x : Spin n) : + (∫ z, likelihood t x z ∂reference n) = 1 := by + have he : likelihood t x = fun z => exp (∑ i, (sqrt t * spinValue (x i)) * z i) * + exp (-(t*n/2)) := by + funext z + simp only [likelihood, exp_sub, exp_neg, ← Finset.mul_sum, mul_assoc, div_eq_mul_inv] + rw [he, integral_mul_const, integral_exp_linear, ← exp_add] + have hs : (∑ i, (sqrt t * spinValue (x i)) ^ 2) = t*n := by + simp [mul_pow, sq_sqrt ht, spinValue_sq, mul_comm] + rw [hs] + simp + +lemma density_jensen (p : Prior n) (t : ℝ) (z : Fin n → ℝ) : + exp (sqrt t * (∑ i, mean p i * z i) - t*n/2) ≤ density p t z := by + have he : (∑ x, p x * (sqrt t * (∑ i, spinValue (x i) * z i) - t*n/2)) = + sqrt t * (∑ i, mean p i * z i) - t*n/2 := by + simp only [mul_sub, Finset.sum_sub_distrib] + rw [← Finset.sum_mul, p.sum_one, one_mul] + congr 1 + simp only [mean, Finset.sum_mul, Finset.mul_sum] + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro i _ + apply Finset.sum_congr rfl + intro x _ + ring + have hj := convexOn_exp.map_sum_le (t := Finset.univ) (w := p.mass) + (p := fun x => sqrt t * (∑ i, spinValue (x i) * z i) - t*n/2) + (fun x _ => p.nonneg x) p.sum_one (fun _ _ => Set.mem_univ _) + simpa only [smul_eq_mul, he, density, likelihood] using hj + +lemma density_pos (p : Prior n) (t : ℝ) (z : Fin n → ℝ) : + 0 < density p t z := (exp_pos _).trans_le (density_jensen p t z) + +lemma integrable_density (p : Prior n) (t : ℝ) : + Integrable (density p t) (reference n) := + integrable_finsetSum _ (fun x _ => (integrable_likelihood t x).const_mul (p x)) + +lemma integral_density (p : Prior n) {t : ℝ} (ht : 0 ≤ t) : + (∫ z, density p t z ∂reference n) = 1 := by + change (∫ z, ∑ x, p x * likelihood t x z ∂reference n) = 1 + rw [integral_finsetSum _ (fun x _ => (integrable_likelihood t x).const_mul (p x))] + simp_rw [integral_const_mul, integral_likelihood ht, mul_one] + exact p.sum_one + +lemma mean_abs_le_one (p : Prior n) (i : Fin n) : |mean p i| ≤ 1 := by + calc + |mean p i| ≤ ∑ x, |p x * spinValue (x i)| := Finset.abs_sum_le_sum_abs _ _ + _ = ∑ x, p x := by + apply Finset.sum_congr rfl + intro x _ + rw [abs_mul, abs_of_nonneg (p.nonneg x)] + have hs : |spinValue (x i)| = 1 := by cases x i <;> norm_num [spinValue] + rw [hs, mul_one] + _ = 1 := p.sum_one + +def interaction (p : Prior n) (x y : Spin n) : ℝ := + ((∑ i, (spinValue (x i) + spinValue (y i) - mean p i)^2) - n) / 2 + +lemma interaction_abs_le (p : Prior n) (x y : Spin n) : + |interaction p x y| ≤ 4*n := by + have hl : (0 : ℝ) ≤ ∑ i : Fin n, (spinValue (x i) + spinValue (y i) - mean p i)^2 := + Finset.sum_nonneg (fun _ _ => sq_nonneg _) + have hu : (∑ i : Fin n, (spinValue (x i) + spinValue (y i) - mean p i)^2) ≤ 9*n := by + calc + _ ≤ ∑ _i : Fin n, (9 : ℝ) := by + apply Finset.sum_le_sum + intro i _ + have hx : |spinValue (x i)| = 1 := by cases x i <;> norm_num [spinValue] + have hy : |spinValue (y i)| = 1 := by cases y i <;> norm_num [spinValue] + have hb : |spinValue (x i) + spinValue (y i) - mean p i| ≤ 3 := by + calc + _ ≤ |spinValue (x i) + spinValue (y i)| + |mean p i| := abs_sub _ _ + _ ≤ |spinValue (x i)| + |spinValue (y i)| + |mean p i| := + add_le_add (abs_add_le _ _) le_rfl + _ ≤ 3 := by rw [hx, hy]; linarith [mean_abs_le_one p i] + have hh := (sq_le_sq₀ (abs_nonneg _) (by norm_num : (0:ℝ) ≤ 3)).mpr hb + simpa only [sq_abs, show (3:ℝ)^2 = 9 by norm_num] using hh + _ = 9*n := by simp [mul_comm] + rw [abs_le] + unfold interaction + constructor <;> nlinarith [Nat.cast_nonneg (α := ℝ) n] + +lemma interaction_remainder_bound (p : Prior n) {t : ℝ} (ht : 0 ≤ t) + (htn : 4*(n:ℝ)*t ≤ 1) (x y : Spin n) : + |exp (t * interaction p x y) - 1 - t * interaction p x y| ≤ + 16*(n:ℝ)^2*t^2 := by + have hb := interaction_abs_le p x y + have htb : |t * interaction p x y| ≤ 4*(n:ℝ)*t := by + rw [abs_mul, abs_of_nonneg ht] + nlinarith [mul_le_mul_of_nonneg_left hb ht] + apply (abs_exp_sub_one_sub_id_le (htb.trans htn)).trans + have hs := sq_le_sq₀ (abs_nonneg (t * interaction p x y)) (by positivity) |>.mpr htb + simpa only [sq_abs] using (hs.trans_eq (by ring : (4*(n:ℝ)*t)^2 = 16*(n:ℝ)^2*t^2)) + +lemma interaction_sum (p : Prior n) (x y : Spin n) : + interaction p x y = ∑ i, ((1/2 : ℝ) + spinValue (x i)*spinValue (y i) - + spinValue (x i)*mean p i - spinValue (y i)*mean p i + (mean p i)^2/2) := by + have ha : interaction p x y = ∑ i, ((spinValue (x i) + spinValue (y i) - mean p i)^2 - 1)/2 := by + unfold interaction + rw [← Finset.sum_div, Finset.sum_sub_distrib] + simp + rw [ha] + apply Finset.sum_congr rfl + intro i _ + nlinarith [spinValue_sq (x i), spinValue_sq (y i)] + +lemma signed_sum_left (a u : Spin n → ℝ) (ha : ∑ x, a x = 0) : + (∑ x, ∑ y, a x * a y * u x) = 0 := by + apply Finset.sum_eq_zero + intro x _ + calc + _ = (a x * u x) * ∑ y, a y := by + rw [Finset.mul_sum] + apply Finset.sum_congr rfl + intro y _ + ring + _ = 0 := by rw [ha, mul_zero] + +lemma signed_sum_right (a u : Spin n → ℝ) (ha : ∑ x, a x = 0) : + (∑ x, ∑ y, a x * a y * u y) = 0 := by + rw [Finset.sum_comm] + convert signed_sum_left a u ha using 1 + apply Finset.sum_congr rfl + intro x _ + apply Finset.sum_congr rfl + intro y _ + ring + +lemma signed_sum_product (a u : Spin n → ℝ) : + (∑ x, ∑ y, a x * a y * (u x * u y)) = (∑ x, a x*u x)^2 := by + rw [pow_two, Finset.sum_mul_sum] + apply Finset.sum_congr rfl + intro x _ + apply Finset.sum_congr rfl + intro y _ + ring + +lemma signed_interaction (p : Prior n) (a : Spin n → ℝ) (ha : ∑ x, a x = 0) : + (∑ x, ∑ y, a x*a y*interaction p x y) = + ∑ i, (∑ x, a x*spinValue (x i))^2 := by + simp_rw [interaction_sum, Finset.mul_sum] + calc + _ = ∑ x, ∑ i, ∑ y, a x*a y* ((1/2 : ℝ) + spinValue (x i)*spinValue (y i) - + spinValue (x i)*mean p i - spinValue (y i)*mean p i + (mean p i)^2/2) := by + apply Finset.sum_congr rfl + intro x _ + exact Finset.sum_comm + _ = ∑ i, ∑ x, ∑ y, a x*a y* ((1/2 : ℝ) + spinValue (x i)*spinValue (y i) - + spinValue (x i)*mean p i - spinValue (y i)*mean p i + (mean p i)^2/2) := Finset.sum_comm + _ = _ := by + apply Finset.sum_congr rfl + intro i _ + simp only [mul_add, mul_sub, Finset.sum_add_distrib, Finset.sum_sub_distrib] + rw [signed_sum_left a (fun _ => (1/2 : ℝ)) ha, + signed_sum_product a (fun x => spinValue (x i)), + signed_sum_left a (fun x => spinValue (x i)*mean p i) ha, + signed_sum_right a (fun y => spinValue (y i)*mean p i) ha, + signed_sum_left a (fun _ => (mean p i)^2/2) ha] + ring + +def pairKernel (p : Prior n) (t : ℝ) (x y : Spin n) (z : Fin n → ℝ) : ℝ := + exp ((∑ i, (sqrt t * (spinValue (x i) + spinValue (y i) - mean p i)) * z i) - t*n/2) + +lemma integrable_pairKernel (p : Prior n) (t : ℝ) (x y : Spin n) : + Integrable (pairKernel p t x y) (reference n) := by + have he : pairKernel p t x y = fun z => + exp (∑ i, (sqrt t * (spinValue (x i) + spinValue (y i) - mean p i)) * z i) * + exp (-(t*n/2)) := by funext z; simp [pairKernel, exp_sub, exp_neg, div_eq_mul_inv] + rw [he] + exact (integrable_exp_linear _).mul_const _ + +lemma integral_pairKernel (p : Prior n) {t : ℝ} (ht : 0 ≤ t) (x y : Spin n) : + (∫ z, pairKernel p t x y z ∂reference n) = exp (t*interaction p x y) := by + have he : pairKernel p t x y = fun z => + exp (∑ i, (sqrt t * (spinValue (x i) + spinValue (y i) - mean p i)) * z i) * + exp (-(t*n/2)) := by funext z; simp [pairKernel, exp_sub, exp_neg, div_eq_mul_inv] + rw [he, integral_mul_const, integral_exp_linear, ← exp_add] + congr 1 + simp only [mul_pow, sq_sqrt ht, ← Finset.mul_sum, interaction] + ring + +lemma likelihood_pair (p : Prior n) (t : ℝ) (x y : Spin n) (z : Fin n → ℝ) : + likelihood t x z * likelihood t y z * + exp (-(sqrt t * (∑ i, mean p i * z i) - t*n/2)) = pairKernel p t x y z := by + unfold likelihood pairKernel + rw [← exp_add, ← exp_add] + congr 1 + simp only [add_mul, sub_mul, mul_add, mul_sub, Finset.mul_sum, Finset.sum_add_distrib, + Finset.sum_sub_distrib, mul_assoc] + ring + +def majorant (p : Prior n) (a : Spin n → ℝ) (t : ℝ) (z : Fin n → ℝ) : ℝ := + (∑ x, a x*likelihood t x z)^2 * exp (-(sqrt t * (∑ i, mean p i * z i) - t*n/2)) + +lemma majorant_eq_sum (p : Prior n) (a : Spin n → ℝ) (t : ℝ) (z : Fin n → ℝ) : + majorant p a t z = ∑ x, ∑ y, (a x*a y)*pairKernel p t x y z := by + unfold majorant + rw [pow_two, Finset.sum_mul_sum] + simp only [Finset.sum_mul] + apply Finset.sum_congr rfl + intro x _ + apply Finset.sum_congr rfl + intro y _ + calc + _ = (a x*a y)*(likelihood t x z*likelihood t y z* + exp (-(sqrt t * (∑ i, mean p i * z i) - t*n/2))) := by ring + _ = _ := by rw [likelihood_pair] + +lemma majorant_nonneg (p : Prior n) (a : Spin n → ℝ) (t : ℝ) (z : Fin n → ℝ) : + 0 ≤ majorant p a t z := mul_nonneg (sq_nonneg _) (exp_pos _).le + +lemma integrable_majorant (p : Prior n) (a : Spin n → ℝ) (t : ℝ) : + Integrable (majorant p a t) (reference n) := by + simp_rw [show majorant p a t = fun z => ∑ x, ∑ y, (a x*a y)*pairKernel p t x y z from + funext (majorant_eq_sum p a t)] + exact integrable_finsetSum _ (fun x _ => integrable_finsetSum _ (fun y _ => + (integrable_pairKernel p t x y).const_mul _)) + +lemma integral_majorant (p : Prior n) (a : Spin n → ℝ) {t : ℝ} (ht : 0 ≤ t) : + (∫ z, majorant p a t z ∂reference n) = ∑ x, ∑ y, (a x*a y)*exp (t*interaction p x y) := by + simp_rw [majorant_eq_sum] + rw [integral_finsetSum _ (fun x _ => integrable_finsetSum _ (fun y _ => + (integrable_pairKernel p t x y).const_mul _))] + apply Finset.sum_congr rfl + intro x _ + rw [integral_finsetSum _ (fun y _ => (integrable_pairKernel p t x y).const_mul _)] + simp_rw [integral_const_mul, integral_pairKernel p ht] + +lemma interaction_exp_sum_bound (p : Prior n) (a : Spin n → ℝ) + (ha : ∑ x, a x = 0) {t : ℝ} (ht : 0 ≤ t) (htn : 4*(n:ℝ)*t ≤ 1) : + (∑ x, ∑ y, a x*a y*exp (t*interaction p x y)) ≤ + t*(∑ i, (∑ x, a x*spinValue (x i))^2) + + 16*(n:ℝ)^2*t^2*(∑ x, |a x|)^2 := by + calc + _ ≤ ∑ x, ∑ y, ((a x*a y + t*(a x*a y*interaction p x y)) + + (16*(n:ℝ)^2*t^2)*(|a x| * |a y|)) := by + apply Finset.sum_le_sum + intro x _ + apply Finset.sum_le_sum + intro y _ + have hr := interaction_remainder_bound p ht htn x y + have hb : a x*a y*(exp (t*interaction p x y)-1-t*interaction p x y) ≤ + |a x| * |a y| * (16*(n:ℝ)^2*t^2) := by + calc + _ ≤ |a x*a y*(exp (t*interaction p x y)-1-t*interaction p x y)| := le_abs_self _ + _ = |a x| * |a y| * |exp (t*interaction p x y)-1-t*interaction p x y| := by simp [abs_mul] + _ ≤ _ := mul_le_mul_of_nonneg_left hr (mul_nonneg (abs_nonneg _) (abs_nonneg _)) + nlinarith only [hb] + _ = _ := by + simp only [Finset.sum_add_distrib, ← Finset.mul_sum] + rw [ha, signed_interaction p a ha] + simp only [mul_zero, Finset.sum_const_zero, zero_add, ← Finset.sum_mul] + ring + +def quadraticIntegrand (p : Prior n) (a : Spin n → ℝ) (t : ℝ) (z : Fin n → ℝ) : ℝ := + (∑ x, a x*likelihood t x z)^2 / density p t z + +lemma quadraticIntegrand_nonneg (p : Prior n) (a : Spin n → ℝ) (t : ℝ) (z : Fin n → ℝ) : + 0 ≤ quadraticIntegrand p a t z := div_nonneg (sq_nonneg _) (density_pos p t z).le + +lemma quadraticIntegrand_le_majorant (p : Prior n) (a : Spin n → ℝ) (t : ℝ) (z : Fin n → ℝ) : + quadraticIntegrand p a t z ≤ majorant p a t z := by + unfold quadraticIntegrand + calc + _ ≤ (∑ x, a x*likelihood t x z)^2 / + exp (sqrt t * (∑ i, mean p i*z i) - t*n/2) := + div_le_div_of_nonneg_left (sq_nonneg _) (exp_pos _) (density_jensen p t z) + _ = _ := by simp only [majorant, div_eq_mul_inv, exp_neg] + +lemma continuous_likelihood (t : ℝ) (x : Spin n) : Continuous (likelihood t x) := by + unfold likelihood + fun_prop + +lemma continuous_density (p : Prior n) (t : ℝ) : Continuous (density p t) := by + unfold density + exact continuous_finsetSum _ (fun x _ => (continuous_likelihood t x).const_mul _) + +lemma continuous_quadraticIntegrand (p : Prior n) (a : Spin n → ℝ) (t : ℝ) : + Continuous (quadraticIntegrand p a t) := by + apply Continuous.div + ((continuous_finsetSum _ (fun x _ => (continuous_likelihood t x).const_mul (a x))).pow 2) + (continuous_density p t) + intro z + exact (density_pos p t z).ne' + +lemma integrable_quadraticIntegrand (p : Prior n) (a : Spin n → ℝ) (t : ℝ) : + Integrable (quadraticIntegrand p a t) (reference n) := by + apply (integrable_majorant p a t).mono' (continuous_quadraticIntegrand p a t).aestronglyMeasurable + filter_upwards [] with z + rw [Real.norm_eq_abs, abs_of_nonneg (quadraticIntegrand_nonneg p a t z)] + exact quadraticIntegrand_le_majorant p a t z + +theorem quadratic_bound (p : Prior n) (a : Spin n → ℝ) (ha : ∑ x, a x = 0) + {t : ℝ} (ht : 0 ≤ t) (htn : 4*(n:ℝ)*t ≤ 1) : + (∫ z, quadraticIntegrand p a t z ∂reference n) ≤ + t*(∑ i, (∑ x, a x*spinValue (x i))^2) + + 16*(n:ℝ)^2*t^2*(∑ x, |a x|)^2 := by + calc + _ ≤ ∫ z, majorant p a t z ∂reference n := + integral_mono (integrable_quadraticIntegrand p a t) (integrable_majorant p a t) + (quadraticIntegrand_le_majorant p a t) + _ = _ := integral_majorant p a ht + _ ≤ _ := interaction_exp_sum_bound p a ha ht htn + +def avg (p : Prior n) (f : Spin n → ℝ) : ℝ := ∑ x, p x * f x + +def var (p : Prior n) (f : Spin n → ℝ) : ℝ := + avg p (fun x => (f x - avg p f)^2) + +def posterior (p : Prior n) (t : ℝ) (z : Fin n → ℝ) : Prior n where + mass x := p x * likelihood t x z / density p t z + nonneg x := div_nonneg (mul_nonneg (p.nonneg x) (likelihood_pos t x z).le) + (density_pos p t z).le + sum_one := by + rw [← Finset.sum_div] + exact div_self (density_pos p t z).ne' + +lemma var_nonneg (p : Prior n) (f : Spin n → ℝ) : 0 ≤ var p f := + Finset.sum_nonneg (fun _ _ => mul_nonneg (p.nonneg _) (sq_nonneg _)) + +lemma avg_const (p : Prior n) (c : ℝ) : avg p (fun _ => c) = c := by + rw [avg, ← Finset.sum_mul, p.sum_one, one_mul] + +lemma avg_sub (p : Prior n) (f g : Spin n → ℝ) : + avg p (fun x => f x-g x) = avg p f-avg p g := by + simp only [avg, mul_sub, Finset.sum_sub_distrib] + +lemma avg_mul_const (p : Prior n) (f : Spin n → ℝ) (c : ℝ) : + avg p (fun x => f x*c) = avg p f*c := by + simp only [avg, mul_assoc, Finset.sum_mul] + +lemma avg_center (p : Prior n) (f : Spin n → ℝ) : + avg p (fun x => f x-avg p f) = 0 := by rw [avg_sub, avg_const, sub_self] + +lemma avg_shift_square (p : Prior n) (f : Spin n → ℝ) (c : ℝ) : + avg p (fun x => (f x-c)^2) = avg p (fun x => (f x)^2)-2*c*avg p f+c^2 := by + unfold avg + calc + _ = ∑ x, ((p x*(f x)^2-(p x*f x)*(2*c))+p x*c^2) := by + apply Finset.sum_congr rfl + intro x _ + ring + _ = _ := by + simp only [Finset.sum_add_distrib, Finset.sum_sub_distrib, ← Finset.sum_mul, p.sum_one] + ring + +end +end SKGap.GaussianStep + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/RefreshGenerator.lean b/lean/OAI/Probability/SKGap/Localization/RefreshGenerator.lean new file mode 100644 index 0000000000000000000000000000000000000000..1a45cc17cb94e369fd54fe19daa7e5c388729b5a --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/RefreshGenerator.lean @@ -0,0 +1,580 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.ResidualRecipe +import OAI.Probability.SKGap.Localization.TargetAttempt + +namespace OAI + +section +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open scoped BigOperators +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open scoped BigOperators +open scoped BigOperators NNReal ENNReal +open MeasureTheory Metric Set +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators NNReal ENNReal Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Set +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators ENNReal NNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Matrix +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators ENNReal NNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal +open scoped BigOperators +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise NNReal ENNReal +open scoped BigOperators +open Filter Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal Topology +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Set Matrix +open scoped BigOperators NNReal ENNReal Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open Filter MeasureTheory ProbabilityTheory +open scoped Topology NNReal ENNReal +open Filter MeasureTheory ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter +open scoped Topology NNReal ENNReal +open MeasureTheory Filter ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter +open scoped Topology +open MeasureTheory Filter ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter ProbabilityTheory ContinuousLinearMap +open scoped Topology NNReal ENNReal +open Filter MeasureTheory ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter +open scoped BigOperators Topology +open MeasureTheory Filter +open scoped BigOperators Topology +open MeasureTheory Filter +open scoped BigOperators Topology +open MeasureTheory Filter +open scoped BigOperators Topology +open MeasureTheory Filter +open scoped BigOperators Topology +open Filter Set Metric +open scoped Topology RealInnerProductSpace +open scoped BigOperators +open ContinuousLinearMap +open scoped BigOperators +open ContinuousLinearMap +namespace SKGapCutoff + +noncomputable def refreshGenerator {n : ℕ} (m : VectorFields n) (f : Spin n → ℝ) + (x : Spin n) : ℝ := ∑ j, (m x j - spin x j) * halfDiff j f x + +noncomputable def refreshGradientGenerator {n : ℕ} (m : VectorFields n) + (p : Spin n → Fin n → ℝ) (x : Spin n) (i : Fin n) : ℝ := + refreshGenerator m (fun y => p y i) x - p x i - + 2 * spin x i * ∑ j, halfDiff i (fun y => m y j) x * + halfDiff j (fun y => p y i) x + + ∑ j, halfDiff i (fun y => m y j) x * p x j + +theorem refreshHalfDiff_generator {n : ℕ} (m : VectorFields n) (f : Spin n → ℝ) + (x : Spin n) (i : Fin n) : + halfDiff i (refreshGenerator m f) x = + refreshGradientGenerator m (fun y j => halfDiff j f y) x i := by + change halfDiff i (fun y => refreshGenerator m f y) x = _ + unfold refreshGradientGenerator + simp only [refreshGenerator, halfDiff_sum, halfDiff_mul, halfDiff_sub, halfDiff_spin] + simp_rw [halfDiff_comm i] + simp only [mul_sub, sub_mul, Finset.sum_add_distrib, Finset.sum_sub_distrib] + simp only [mul_ite, mul_one, mul_zero, ite_mul, zero_mul, + Fintype.sum_ite_eq, halfDiff_self, sub_zero] + rw [Finset.mul_sum] + simp only [mul_assoc] + simp_rw [mul_comm (halfDiff _ f x)] + ring + +noncomputable def refreshGeneratorLM {n : ℕ} (m : VectorFields n) : + Observables n →ₗ[ℝ] Observables n where + toFun := refreshGenerator m + map_add' f g := by + funext x + simp only [refreshGenerator] + change (∑ j, (m x j - spin x j) * + (gradientLM n (f + g) x j)) = _ + simp [map_add, gradientLM, refreshGenerator, mul_add, Finset.sum_add_distrib] + map_smul' a f := by + funext x + simp only [refreshGenerator] + change (∑ j, (m x j - spin x j) * + (gradientLM n (a • f) x j)) = _ + simp [map_smul, gradientLM, refreshGenerator, mul_left_comm, Finset.mul_sum] + +noncomputable def refreshGradientGeneratorLM {n : ℕ} (m : VectorFields n) : + VectorFields n →ₗ[ℝ] VectorFields n where + toFun := refreshGradientGenerator m + map_add' p q := by + funext x i + simp only [refreshGradientGenerator, Pi.add_apply] + have h1 : (fun y => p y i + q y i) = + (fun y => p y i) + (fun y => q y i) := rfl + rw [h1] + change (refreshGeneratorLM m ((fun y => p y i) + (fun y => q y i))) x - _ - + 2 * spin x i * (∑ j, halfDiff i (fun y => m y j) x * + gradientLM n ((fun y => p y i) + (fun y => q y i)) x j) + _ = _ + simp only [map_add, Pi.add_apply, mul_add, Finset.sum_add_distrib] + change refreshGenerator m (fun y => p y i) x + refreshGenerator m (fun y => q y i) x - _ - _ + _ = _ + simp only [gradientLM, LinearMap.coe_mk, AddHom.coe_mk] + ring + map_smul' a p := by + funext x i + simp only [refreshGradientGenerator, Pi.smul_apply, smul_eq_mul, RingHom.id_apply] + have h1 : (fun y => a * p y i) = a • (fun y => p y i) := rfl + rw [h1] + change (refreshGeneratorLM m (a • (fun y => p y i))) x - _ - + 2 * spin x i * (∑ j, halfDiff i (fun y => m y j) x * + gradientLM n (a • (fun y => p y i)) x j) + _ = _ + simp only [map_smul, Pi.smul_apply, smul_eq_mul] + simp only [gradientLM, refreshGeneratorLM, LinearMap.coe_mk, AddHom.coe_mk] + simp_rw [mul_left_comm _ a, ← Finset.mul_sum] + ring + +noncomputable def refreshGeneratorCLM {n : ℕ} (m : VectorFields n) : + Observables n →L[ℝ] Observables n := (refreshGeneratorLM m).toContinuousLinearMap + +noncomputable def refreshGradientGeneratorCLM {n : ℕ} (m : VectorFields n) : + VectorFields n →L[ℝ] VectorFields n := + (refreshGradientGeneratorLM m).toContinuousLinearMap + +noncomputable def refreshSemigroup {n : ℕ} (m : VectorFields n) (t : ℝ) : + Observables n →L[ℝ] Observables n := NormedSpace.exp (t • refreshGeneratorCLM m) + +noncomputable def refreshGradientSemigroup {n : ℕ} (m : VectorFields n) (t : ℝ) : + VectorFields n →L[ℝ] VectorFields n := + NormedSpace.exp (t • refreshGradientGeneratorCLM m) + +theorem refreshHalfDiff_semigroup {n : ℕ} (m : VectorFields n) (t : ℝ) + (f : Observables n) (x : Spin n) (i : Fin n) : + halfDiff i (refreshSemigroup m t f) x = + refreshGradientSemigroup m t (fun y j => halfDiff j f y) x i := by + have h (g : Observables n) : + gradientCLM n ((t • refreshGeneratorCLM m) g) = + (t • refreshGradientGeneratorCLM m) (gradientCLM n g) := by + rw [_root_.smul_apply, map_smul, _root_.smul_apply] + congr 1 + funext y j + exact refreshHalfDiff_generator m g y j + exact congrFun (congrFun + (exp_intertwine (t • refreshGeneratorCLM m) (t • refreshGradientGeneratorCLM m) + (gradientCLM n) h f) x) i + +@[simp] theorem refreshGenerator_const {n : ℕ} (m : VectorFields n) (a : ℝ) (x : Spin n) : + refreshGenerator m (fun _ => a) x = 0 := by + simp [refreshGenerator] + +@[simp] theorem refreshSemigroup_const {n : ℕ} (m : VectorFields n) (t a : ℝ) : + refreshSemigroup m t (fun _ => a) = fun _ => a := by + apply exp_apply_of_apply_eq_zero + funext x + change t * refreshGenerator m (fun _ => a) x = 0 + simp + +lemma refreshGenerator_mul {n : ℕ} (m : VectorFields n) (f g : Observables n) (x : Spin n) : + refreshGenerator m (fun y => f y * g y) x = + f x * refreshGenerator m g x + g x * refreshGenerator m f x + + 2 * ∑ i, (1 - m x i * spin x i) * halfDiff i f x * halfDiff i g x := by + simp only [refreshGenerator, halfDiff_mul, Finset.mul_sum, ← Finset.sum_add_distrib] + apply Finset.sum_congr rfl + intro i _ + have hx := spin_sq x i + linear_combination 2 * halfDiff i f x * halfDiff i g x * hx + +lemma refreshSemigroup_hasDerivAt {n : ℕ} (m : VectorFields n) (t : ℝ) : + HasDerivAt (fun s : ℝ => refreshSemigroup m s) + (refreshSemigroup m t * refreshGeneratorCLM m) t := + hasDerivAt_exp_smul_const (refreshGeneratorCLM m) t + +lemma refreshSemigroup_hasDerivAt' {n : ℕ} (m : VectorFields n) (t : ℝ) : + HasDerivAt (fun s : ℝ => refreshSemigroup m s) + (refreshGeneratorCLM m * refreshSemigroup m t) t := + hasDerivAt_exp_smul_const' (refreshGeneratorCLM m) t + +lemma refreshSemigroup_apply_hasDerivAt {n : ℕ} (m : VectorFields n) (f : Observables n) (t : ℝ) : + HasDerivAt (fun s : ℝ => refreshSemigroup m s f) (refreshSemigroup m t (refreshGenerator m f)) t := by + simpa only [mul_apply_eq_comp, map_zero, add_zero, refreshGeneratorCLM, refreshGeneratorLM, + LinearMap.coe_toContinuousLinearMap', LinearMap.coe_mk, AddHom.coe_mk] using + (refreshSemigroup_hasDerivAt m t).clm_apply (hasDerivAt_const t f) + +lemma refreshSemigroup_apply_hasDerivAt' {n : ℕ} (m : VectorFields n) (f : Observables n) (t : ℝ) : + HasDerivAt (fun s : ℝ => refreshSemigroup m s f) (refreshGenerator m (refreshSemigroup m t f)) t := by + simpa only [mul_apply_eq_comp, map_zero, add_zero, refreshGeneratorCLM, refreshGeneratorLM, + LinearMap.coe_toContinuousLinearMap', LinearMap.coe_mk, AddHom.coe_mk] using + (refreshSemigroup_hasDerivAt' m t).clm_apply (hasDerivAt_const t f) + +lemma refreshSemigroup_continuous {n : ℕ} (m : VectorFields n) : + Continuous (fun s : ℝ => refreshSemigroup m s) := by + have hd : Differentiable ℝ (fun s : ℝ => refreshSemigroup m s) := + fun t => (refreshSemigroup_hasDerivAt m t).differentiableAt + exact hd.continuous + +@[simp] lemma refreshSemigroup_zero {n : ℕ} (m : VectorFields n) : refreshSemigroup m 0 = 1 := by + simp [refreshSemigroup] + +noncomputable def refreshJumpEnergy {n : ℕ} (m : VectorFields n) (f : Observables n) (x : Spin n) : ℝ := + 2 * ∑ i, (1 - m x i * spin x i) * (halfDiff i f x) ^ 2 + +lemma refreshGenerator_square {n : ℕ} (m : VectorFields n) (f : Observables n) : + refreshGenerator m (fun x => f x ^ 2) = + fun x => 2 * f x * refreshGenerator m f x + refreshJumpEnergy m f x := by + funext x + simpa only [pow_two, mul_assoc, ← two_mul, refreshJumpEnergy] using refreshGenerator_mul m f f x + +lemma refreshBackward_flow_hasDerivAt {n : ℕ} (m : VectorFields n) (f : Observables n) (d s : ℝ) : + HasDerivAt (fun r : ℝ => refreshSemigroup m (d - r) f) + (fun x => -refreshGenerator m (refreshSemigroup m (d - s) f) x) s := by + have h := (refreshSemigroup_apply_hasDerivAt' m f (d - s)).scomp s + ((hasDerivAt_id s).const_sub d) + simpa only [id_eq, neg_smul, one_smul, Pi.neg_def, Function.comp_def] using h + +lemma refreshBackward_square_hasDerivAt {n : ℕ} (m : VectorFields n) (f : Observables n) (d s : ℝ) : + HasDerivAt (fun r : ℝ => fun x : Spin n => (refreshSemigroup m (d - r) f x) ^ 2) + (fun x => -2 * refreshSemigroup m (d - s) f x * refreshGenerator m (refreshSemigroup m (d - s) f) x) s := by + apply hasDerivAt_pi.mpr + intro x + have h := (hasDerivAt_pi.mp (refreshBackward_flow_hasDerivAt m f d s) x).pow 2 + have he : (2 : ℝ) * refreshSemigroup m (d - s) f x * + -refreshGenerator m (refreshSemigroup m (d - s) f) x = + -2 * refreshSemigroup m (d - s) f x * refreshGenerator m (refreshSemigroup m (d - s) f) x := by ring + convert h using 1 + simpa only [Nat.cast_ofNat, Nat.reduceSub, pow_one] using he.symm + +lemma refreshInterpolated_square_hasDerivAt {n : ℕ} (m : VectorFields n) (f : Observables n) (d s : ℝ) : + HasDerivAt (fun r : ℝ => refreshSemigroup m r + (fun x => (refreshSemigroup m (d - r) f x) ^ 2)) + (refreshSemigroup m s (refreshJumpEnergy m (refreshSemigroup m (d - s) f))) s := by + have h := (refreshSemigroup_hasDerivAt m s).clm_apply (refreshBackward_square_hasDerivAt m f d s) + apply h.congr_deriv + simp only [mul_apply_eq_comp] + change refreshSemigroup m s (refreshGenerator m (fun x => refreshSemigroup m (d - s) f x ^ 2)) + + refreshSemigroup m s (fun x => -2 * refreshSemigroup m (d - s) f x * + refreshGenerator m (refreshSemigroup m (d - s) f) x) = _ + rw [← map_add] + congr 1 + funext x + rw [refreshGenerator_square] + simp only [Pi.add_apply] + ring + +lemma refreshJumpEnergy_continuous {n : ℕ} (m : VectorFields n) : + Continuous (refreshJumpEnergy m) := by + unfold refreshJumpEnergy halfDiff + fun_prop + +lemma refreshInterpolated_energy_continuous {n : ℕ} (m : VectorFields n) (f : Observables n) + (d : ℝ) (x : Spin n) : + Continuous (fun s : ℝ => refreshSemigroup m s (refreshJumpEnergy m (refreshSemigroup m (d - s) f)) x) := by + have hc : Continuous (fun s : ℝ => refreshSemigroup m (d - s) f) := + ((refreshSemigroup_continuous m).comp (continuous_const.sub continuous_id)).clm_apply continuous_const + exact continuous_apply x |>.comp ((refreshSemigroup_continuous m).clm_apply + ((refreshJumpEnergy_continuous m).comp hc)) + +lemma refreshSemigroup_variance_integral {n : ℕ} (m : VectorFields n) (f : Observables n) + (d : ℝ) (x : Spin n) : + refreshSemigroup m d (fun y => f y ^ 2) x - (refreshSemigroup m d f x) ^ 2 = + ∫ s in (0 : ℝ)..d, refreshSemigroup m s (refreshJumpEnergy m (refreshSemigroup m (d - s) f)) x := by + have hd (s : ℝ) := hasDerivAt_pi.mp (refreshInterpolated_square_hasDerivAt m f d s) x + have hi := (refreshInterpolated_energy_continuous m f d x).intervalIntegrable + (μ := MeasureTheory.volume) 0 d + have he := intervalIntegral.integral_eq_sub_of_hasDerivAt (fun s _ => hd s) hi + simpa only [sub_self, sub_zero, refreshSemigroup_zero, one_apply_eq_self] using he.symm + +noncomputable def refreshJumpWeight {n : ℕ} (m : VectorFields n) (x : Spin n) (j : Fin n) : ℝ := + 1 - m x j * spin x j + +noncomputable def refreshInfluence {n : ℕ} (m : VectorFields n) (x : Spin n) : Interaction n := + fun i j => halfDiff i (fun y => m y j) x + +noncomputable def refreshVectorDissipation {n : ℕ} (m : VectorFields n) + (p : VectorFields n) (x : Spin n) : ℝ := + ∑ i, ∑ j, refreshJumpWeight m x j * (halfDiff j (fun y => p y i) x) ^ 2 + +lemma refreshGenerator_vectorSquare {n : ℕ} (m : VectorFields n) + (p : VectorFields n) (x : Spin n) : + refreshGenerator m (vectorSquare p) x = ∑ i, refreshGenerator m (fun y => p y i ^ 2) x := by + have hv : vectorSquare p = ∑ i, fun y => p y i ^ 2 := by + funext y + simp only [vectorSquare, Finset.sum_apply] + rw [hv] + change refreshGeneratorLM m (∑ i, fun y => p y i ^ 2) x = _ + rw [map_sum, Finset.sum_apply] + rfl + +lemma refreshGradient_square_identity {n : ℕ} (m : VectorFields n) + (p : VectorFields n) (x : Spin n) : + (∑ i, 2 * p x i * refreshGradientGenerator m p x i) - refreshGenerator m (vectorSquare p) x = + -2 * vectorSquare p x + + 2 * ∑ i, p x i * (∑ j, refreshInfluence m x i j * p x j) - + 4 * ∑ i, (p x i * spin x i) * (∑ j, refreshInfluence m x i j * halfDiff j (fun y => p y i) x) - + 2 * refreshVectorDissipation m p x := by + rw [refreshGenerator_vectorSquare, ← Finset.sum_sub_distrib] + have hloc (i : Fin n) : + 2 * p x i * refreshGradientGenerator m p x i - refreshGenerator m (fun y => p y i ^ 2) x = + -2 * p x i ^ 2 + 2 * (p x i * (∑ j, refreshInfluence m x i j * p x j)) - + 4 * ((p x i * spin x i) * (∑ j, refreshInfluence m x i j * halfDiff j (fun y => p y i) x)) - + 2 * (∑ j, refreshJumpWeight m x j * (halfDiff j (fun y => p y i) x) ^ 2) := by + rw [refreshGenerator_square] + dsimp only [refreshGradientGenerator, refreshInfluence, refreshJumpEnergy, refreshJumpWeight] + ring + simp_rw [hloc] + simp only [Finset.sum_sub_distrib, Finset.sum_add_distrib, ← Finset.mul_sum, + vectorSquare, refreshVectorDissipation] + +lemma refreshGradientSemigroup_apply_hasDerivAt {n : ℕ} (m : VectorFields n) + (p : VectorFields n) (t : ℝ) : + HasDerivAt (fun s : ℝ => refreshGradientSemigroup m s p) + (refreshGradientGenerator m (refreshGradientSemigroup m t p)) t := by + simpa only [refreshGradientSemigroup, mul_apply_eq_comp, map_zero, add_zero, refreshGradientGeneratorCLM, + refreshGradientGeneratorLM, LinearMap.coe_toContinuousLinearMap', LinearMap.coe_mk, + AddHom.coe_mk] using + (hasDerivAt_exp_smul_const' (refreshGradientGeneratorCLM m) t).clm_apply + (hasDerivAt_const t p) + +lemma refreshBackward_gradient_hasDerivAt {n : ℕ} (m : VectorFields n) + (p : VectorFields n) (t s : ℝ) : + HasDerivAt (fun r : ℝ => refreshGradientSemigroup m (t-r) p) + (-refreshGradientGenerator m (refreshGradientSemigroup m (t-s) p)) s := by + have h := (refreshGradientSemigroup_apply_hasDerivAt m p (t-s)).scomp s + ((hasDerivAt_id s).const_sub t) + simpa only [id_eq, neg_smul, one_smul, Function.comp_def] using h + +lemma refreshBackward_vectorSquare_hasDerivAt {n : ℕ} (m : VectorFields n) + (p : VectorFields n) (t s : ℝ) : + HasDerivAt (fun r : ℝ => vectorSquare (refreshGradientSemigroup m (t-r) p)) + (fun x => -(∑ i, 2 * refreshGradientSemigroup m (t-s) p x i * + refreshGradientGenerator m (refreshGradientSemigroup m (t-s) p) x i)) s := by + apply hasDerivAt_pi.mpr + intro x + have hi (i : Fin n) := (hasDerivAt_pi.mp + (hasDerivAt_pi.mp (refreshBackward_gradient_hasDerivAt m p t s) x) i).pow 2 + have hs := HasDerivAt.fun_sum (u := Finset.univ) (fun i _ => hi i) + simpa only [vectorSquare, Pi.pow_apply, Nat.cast_ofNat, Nat.reduceSub, pow_one, Pi.neg_apply, mul_neg, + Finset.sum_neg_distrib] using hs + +noncomputable def refreshRoughDefect {n : ℕ} (m : VectorFields n) (C : ℝ) + (p : VectorFields n) (x : Spin n) : ℝ := + C * vectorSquare p x + refreshGenerator m (vectorSquare p) x - + ∑ i, 2 * p x i * refreshGradientGenerator m p x i + +lemma refreshInterpolated_vectorSquare_hasDerivAt {n : ℕ} (m : VectorFields n) + (p : VectorFields n) (t C s : ℝ) (x : Spin n) : + HasDerivAt (fun r : ℝ => Real.exp (C*r) * refreshSemigroup m r + (vectorSquare (refreshGradientSemigroup m (t-r) p)) x) + (Real.exp (C*s) * refreshSemigroup m s + (refreshRoughDefect m C (refreshGradientSemigroup m (t-s) p)) x) s := by + have hv := (refreshSemigroup_hasDerivAt m s).clm_apply + (refreshBackward_vectorSquare_hasDerivAt m p t s) + have he := (hasDerivAt_id s).const_mul C |>.exp + have hh := he.mul (hasDerivAt_pi.mp hv x) + apply hh.congr_deriv + simp only [mul_one, mul_apply_eq_comp] + let q := refreshGradientSemigroup m (t-s) p + change Real.exp (C*s) * C * refreshSemigroup m s (vectorSquare q) x + + Real.exp (C*s) * (refreshSemigroup m s (refreshGenerator m (vectorSquare q)) + + refreshSemigroup m s (fun y => -(∑ i, 2*q y i*refreshGradientGenerator m q y i))) x = _ + have hd : refreshRoughDefect m C q = C • vectorSquare q + refreshGenerator m (vectorSquare q) + + (fun y => -(∑ i, 2*q y i*refreshGradientGenerator m q y i)) := by + funext y + simp only [refreshRoughDefect, Pi.add_apply, Pi.smul_apply, smul_eq_mul, sub_eq_add_neg] + rw [hd, map_add, map_add, map_smul] + simp only [Pi.add_apply, Pi.smul_apply, smul_eq_mul] + ring + +lemma refreshGeneratorCLM_eq {n : ℕ} (m : VectorFields n) : + refreshGeneratorCLM m = (n:ℝ) • (targetAttempt m-1) := by + ext f x + by_cases hn : n=0 + · subst n; simp [refreshGeneratorCLM, refreshGeneratorLM, refreshGenerator] + · exact (targetAttempt_generator (Nat.pos_of_ne_zero hn) m f x).symm + +lemma refreshSemigroup_uniformization {n : ℕ} (m : VectorFields n) (t : ℝ) : + refreshSemigroup m t = Real.exp (-(n:ℝ)*t) • NormedSpace.exp (((n:ℝ)*t) • targetAttempt m) := by + rw [refreshSemigroup, refreshGeneratorCLM_eq, smul_smul, mul_comm t, + exp_refresh_uniformization] + congr 2 + ring + +lemma refreshSemigroup_nonneg {n : ℕ} (m : VectorFields n) + (hm : ∀ x i, |m x i| ≤ 1) (t : ℝ) (ht : 0 ≤ t) + (f : Observables n) (hf : ∀ x, 0 ≤ f x) (x : Spin n) : + 0 ≤ refreshSemigroup m t f x := by + have hp (k : ℕ) : ∀ y, 0 ≤ (targetAttempt m^k) f y := by + induction k with + | zero => simpa using hf + | succ k ih => + simpa only [pow_succ', mul_apply_eq_comp] using targetAttempt_nonneg m hm _ ih + rw [refreshSemigroup_uniformization] + simp only [_root_.smul_apply, Pi.smul_apply, smul_eq_mul] + apply mul_nonneg (Real.exp_pos _).le + have hs := Pi.hasSum.mp (exp_apply_hasSum (((n:ℝ)*t) • targetAttempt m) f) x + apply HasSum.nonneg _ hs + intro k + simp only [smul_pow, _root_.smul_apply, Pi.smul_apply, smul_eq_mul] + exact mul_nonneg (inv_nonneg.mpr (Nat.cast_nonneg _)) + (mul_nonneg (pow_nonneg (mul_nonneg (Nat.cast_nonneg _) ht) _) (hp k x)) + +lemma refreshJumpWeight_pos {n : ℕ} (m : VectorFields n) + (hm : ∀ x i, |m x i| < 1) (x : Spin n) (i : Fin n) : + 0 < refreshJumpWeight m x i := by + have hh := abs_lt.mp (hm x i) + cases hi : x i <;> simp only [refreshJumpWeight, spin, hi, Bool.false_eq_true, + ↓reduceIte, mul_one, mul_neg_one, sub_neg_eq_add] <;> linarith + +lemma refreshJumpWeight_le_two {n : ℕ} (m : VectorFields n) + (hm : ∀ x i, |m x i| ≤ 1) (x : Spin n) (i : Fin n) : + refreshJumpWeight m x i ≤ 2 := by + have hh := abs_le.mp (hm x i) + cases hi : x i <;> simp only [refreshJumpWeight, spin, hi, Bool.false_eq_true, + ↓reduceIte, mul_one, mul_neg_one, sub_neg_eq_add] <;> linarith + +lemma refreshVectorDissipation_nonneg {n : ℕ} (m : VectorFields n) + (hm : ∀ x i, |m x i| < 1) (p : VectorFields n) (x : Spin n) : + 0 ≤ refreshVectorDissipation m p x := by + exact Finset.sum_nonneg (fun _ _ => Finset.sum_nonneg (fun j _ => + mul_nonneg (refreshJumpWeight_pos m hm x j).le (sq_nonneg _))) + +lemma refreshGradient_first_order_bound {n : ℕ} (m : VectorFields n) + (hm : ∀ x i, |m x i| < 1) + (p : VectorFields n) (x : Spin n) (R : ℝ) + (hR : ∀ i, ∑ j, refreshInfluence m x i j ^ 2 / refreshJumpWeight m x j ≤ R) : + -4 * (∑ i, (p x i * spin x i) * + (∑ j, refreshInfluence m x i j * halfDiff j (fun y => p y i) x)) ≤ + 4 * R * vectorSquare p x + refreshVectorDissipation m p x := by + have hrow (i : Fin n) : + -4 * ((p x i * spin x i) * + (∑ j, refreshInfluence m x i j * halfDiff j (fun y => p y i) x)) ≤ + 4 * R * p x i ^ 2 + + ∑ j, refreshJumpWeight m x j * (halfDiff j (fun y => p y i) x) ^ 2 := by + have hs := Finset.sum_le_sum (s := Finset.univ) (fun j _ => weighted_cross_young + (p x i * spin x i) (refreshInfluence m x i j) + (halfDiff j (fun y => p y i) x) (refreshJumpWeight m x j) (refreshJumpWeight_pos m hm x j)) + simp only [mul_pow, spin_sq, mul_one, Finset.sum_add_distrib, + ← Finset.sum_mul, ← Finset.mul_sum] at hs + calc + _ ≤ 4 * (∑ j, refreshInfluence m x i j ^ 2 / refreshJumpWeight m x j) * p x i ^ 2 + + ∑ j, refreshJumpWeight m x j * (halfDiff j (fun y => p y i) x) ^ 2 := by + have he : -4 * ((p x i * spin x i) * + (∑ j, refreshInfluence m x i j * halfDiff j (fun y => p y i) x)) = + ∑ j, -4 * (p x i * spin x i) * refreshInfluence m x i j * + halfDiff j (fun y => p y i) x := by + simp only [Finset.mul_sum] + apply Finset.sum_congr rfl + intro j _ + ring + rw [he] + exact hs + _ ≤ _ := by + have hm := mul_le_mul_of_nonneg_right (hR i) (sq_nonneg (p x i)) + nlinarith + have hs := Finset.sum_le_sum (s := Finset.univ) (fun i _ => hrow i) + simpa only [Finset.sum_add_distrib, ← Finset.mul_sum, + vectorSquare, refreshVectorDissipation] using hs + +lemma refreshGradient_square_le {n : ℕ} (m : VectorFields n) + (hm : ∀ x i, |m x i| < 1) + (p : VectorFields n) (x : Spin n) (A R : ℝ) + (hA : ∑ i, p x i * (∑ j, refreshInfluence m x i j * p x j) ≤ A * vectorSquare p x) + (hR : ∀ i, ∑ j, refreshInfluence m x i j ^ 2 / refreshJumpWeight m x j ≤ R) : + (∑ i, 2 * p x i * refreshGradientGenerator m p x i) - refreshGenerator m (vectorSquare p) x ≤ + (2*A+4*R-2) * vectorSquare p x - refreshVectorDissipation m p x := by + rw [refreshGradient_square_identity] + have h := refreshGradient_first_order_bound m hm p x R hR + linarith + +end SKGapCutoff +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/RegeneratedAnswer.lean b/lean/OAI/Probability/SKGap/Localization/RegeneratedAnswer.lean new file mode 100644 index 0000000000000000000000000000000000000000..2373de825f6d585a4d9dc4d960e92817eb6196e9 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/RegeneratedAnswer.lean @@ -0,0 +1,300 @@ +import Mathlib +import OAI.Probability.SKGap.Matrix.MeasurableCompletedMatrix + +namespace OAI + +section +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open scoped BigOperators +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open scoped BigOperators +open scoped BigOperators NNReal ENNReal +open MeasureTheory Metric Set +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators NNReal ENNReal Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Set +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators ENNReal NNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Matrix +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators ENNReal NNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal +open scoped BigOperators +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise NNReal ENNReal +open scoped BigOperators +open Filter Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal Topology +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Set Matrix +open scoped BigOperators NNReal ENNReal Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +namespace SKGapCutoff.Regression + +local instance transferMatrixMeasurable {n m : ℕ} : MeasurableSpace (Matrix (Fin n) (Fin m) ℝ) := + inferInstanceAs (MeasurableSpace (Fin n → Fin m → ℝ)) + +lemma extendFrame_compatible {n r : ℕ} (U Y : Matrix (Fin n) (Fin r) ℝ) + (q b : Fin n → ℝ) (hY : Uᵀ*Y=Yᵀ*U) (hb : Uᵀ *ᵥ b=Yᵀ *ᵥ q) : + (extendFrame U q)ᵀ*extendFrame Y b=(extendFrame Y b)ᵀ*extendFrame U q := by + ext a c + obtain rfl | ⟨a,rfl⟩ := Fin.eq_zero_or_eq_succ a + · obtain rfl | ⟨c,rfl⟩ := Fin.eq_zero_or_eq_succ c + · simp only [Matrix.mul_apply,Matrix.transpose_apply,extendFrame_zero,mul_comm] + · have hh := congrFun hb c + simpa only [Matrix.mul_apply,Matrix.transpose_apply,extendFrame_zero,extendFrame_succ, + Matrix.mulVec,dotProduct,mul_comm] using hh.symm + · obtain rfl | ⟨c,rfl⟩ := Fin.eq_zero_or_eq_succ c + · have hh := congrFun hb a + simpa only [Matrix.mul_apply,Matrix.transpose_apply,extendFrame_zero,extendFrame_succ, + Matrix.mulVec,dotProduct] using hh + · exact congrFun (congrFun hY a) c + +lemma queryInnovation_perpendicular {n r : ℕ} (U : Matrix (Fin n) (Fin r) ℝ) + (q : Fin n → ℝ) (hU : Uᵀ*U=1) (ho : Uᵀ *ᵥ q=0) + (g : (Fin n ⊕ Unit) → ℝ) : + Uᵀ *ᵥ queryInnovation (residualProjection U) q g=0 := by + have he : queryInnovation (residualProjection U) q g = + (Real.sqrt n)⁻¹ • + (queryComplement (residualProjection U) q *ᵥ (fun k => g (Sum.inl k))+ + (Real.sqrt 2*g (Sum.inr ())) • q) := by + ext i + simp only [queryInnovation,Matrix.mulVec,dotProduct,Pi.smul_apply,smul_eq_mul,Pi.add_apply] + ring + have hR : Uᵀ*queryComplement (residualProjection U) q=0 := by + rw [← extendFrame_projection] + have hp : Uᵀ*residualProjection U=0 := mul_residualProjection U hU + simp only [extendFrame_projection,queryComplement,Matrix.mul_sub,← Matrix.mul_assoc,hp] + have hcol : Uᵀ*queryColumn q=0 := by + ext a b + fin_cases b + exact congrFun ho a + rw [hcol,Matrix.zero_mul,sub_zero] + rw [he,Matrix.mulVec_smul,Matrix.mulVec_add,Matrix.mulVec_smul, + Matrix.mulVec_mulVec,hR,Matrix.zero_mulVec,ho,smul_zero,add_zero,smul_zero] + +lemma regenerated_frame_compatible {n r : ℕ} (U Y : Matrix (Fin n) (Fin r) ℝ) + (q : Fin n → ℝ) (hU : Uᵀ*U=1) (hY : Uᵀ*Y=Yᵀ*U) + (ho : Uᵀ *ᵥ q=0) (g : (Fin n ⊕ Unit) → ℝ) : + let b := U *ᵥ (Yᵀ *ᵥ q)+queryInnovation (residualProjection U) q g + (extendFrame U q)ᵀ*extendFrame Y b=(extendFrame Y b)ᵀ*extendFrame U q := by + apply extendFrame_compatible U Y q _ hY + rw [Matrix.mulVec_add,Matrix.mulVec_mulVec,hU,Matrix.one_mulVec, + queryInnovation_perpendicular U q hU ho g,add_zero] + +@[fun_prop] lemma measurable_completedMatrix_comp {n r : ℕ} {H : Type*} [MeasurableSpace H] + (U Y : H → Matrix (Fin n) (Fin r) ℝ) (g : H → (Fin n × Fin n) → ℝ) + (hU : Measurable U) (hY : Measurable Y) (hg : Measurable g) : + Measurable (fun h => completedMatrix (U h) (Y h) (g h)) := by + have hU' : Measurable (fun h i j => U h i j) := hU + have hY' : Measurable (fun h i j => Y h i j) := hY + apply Measurable.of_eval + intro i + apply Measurable.of_eval + intro j + simp only [completedMatrix,revealedCompletion,residualProjection,goe, + Matrix.add_apply,Matrix.sub_apply,Matrix.mul_apply,Matrix.transpose_apply] + fun_prop + +@[fun_prop] lemma measurable_matrix_mulVec_comp {n m : ℕ} {H : Type*} [MeasurableSpace H] + (A : H → Matrix (Fin n) (Fin m) ℝ) (v : H → Fin m → ℝ) + (hA : Measurable A) (hv : Measurable v) : Measurable (fun h => A h *ᵥ v h) := by + have hA' : Measurable (fun h i j => A h i j) := hA + apply Measurable.of_eval + intro i + simp only [Matrix.mulVec,dotProduct] + fun_prop + +noncomputable def regeneratedAnswer {n r : ℕ} (U Y : Matrix (Fin n) (Fin r) ℝ) + (q : Fin n → ℝ) (g : (Fin n ⊕ Unit) → ℝ) : Fin n → ℝ := + U *ᵥ (Yᵀ *ᵥ q)+queryInnovation (residualProjection U) q g + +@[fun_prop] lemma measurable_regeneratedAnswer_comp {n r : ℕ} {H : Type*} [MeasurableSpace H] + (U Y : H → Matrix (Fin n) (Fin r) ℝ) (q : H → Fin n → ℝ) + (g : H → (Fin n ⊕ Unit) → ℝ) + (hU : Measurable U) (hY : Measurable Y) (hq : Measurable q) (hg : Measurable g) : + Measurable (fun h => regeneratedAnswer (U h) (Y h) (q h) (g h)) := by + have hY' : Measurable (fun h => (Y h)ᵀ) := by + apply Measurable.of_eval + intro i + apply Measurable.of_eval + intro j + exact ((measurable_pi_apply i).comp (measurable_pi_apply j)).comp hY + exact (measurable_matrix_mulVec_comp U _ hU + (measurable_matrix_mulVec_comp _ q hY' hq)).add + (measurable_queryInnovation_comp _ q g (measurable_residualProjection_comp U hU) hq hg) + +lemma regeneration_event_le {n r : ℕ} (hn : 0 < n) {H : Type*} [MeasurableSpace H] + (ρ : Measure H) (U Y : H → Matrix (Fin n) (Fin r) ℝ) (q : H → Fin n → ℝ) + (hUm : Measurable U) (hYm : Measurable Y) (hqm : Measurable q) + (G : Set H) (hG : MeasurableSet G) + (hgood : ∀ h ∈ G, (U h)ᵀ*U h=1 ∧ (U h)ᵀ*Y h=(Y h)ᵀ*U h ∧ + (∑ i, q h i^2)=1 ∧ (U h)ᵀ *ᵥ q h=0) + (T : Set (H × ((Fin n → ℝ) × Matrix (Fin n) (Fin n) ℝ))) (hT : MeasurableSet T) : + (ρ.prod ((standardArrayLaw (Fin n × Fin n)).prod (standardArrayLaw (Fin n ⊕ Unit)))) + ((fun z => (z.1,(regeneratedAnswer (U z.1) (Y z.1) (q z.1) z.2.2, + completedMatrix (extendFrame (U z.1) (q z.1)) + (extendFrame (Y z.1) (regeneratedAnswer (U z.1) (Y z.1) (q z.1) z.2.2)) z.2.1))) ⁻¹' T) ≤ + (ρ.prod (standardArrayLaw (Fin n × Fin n))) + ((fun z => (z.1,(completedMatrix (U z.1) (Y z.1) z.2 *ᵥ q z.1, + completedMatrix (U z.1) (Y z.1) z.2))) ⁻¹' T)+ρ Gᶜ := by + let F : H × ((Fin n × Fin n) → ℝ) → + H × ((Fin n → ℝ) × Matrix (Fin n) (Fin n) ℝ) := fun z => + (z.1,(completedMatrix (U z.1) (Y z.1) z.2 *ᵥ q z.1, + completedMatrix (U z.1) (Y z.1) z.2)) + let R : H × (((Fin n × Fin n) → ℝ) × ((Fin n ⊕ Unit) → ℝ)) → + H × ((Fin n → ℝ) × Matrix (Fin n) (Fin n) ℝ) := fun z => + (z.1,(regeneratedAnswer (U z.1) (Y z.1) (q z.1) z.2.2, + completedMatrix (extendFrame (U z.1) (q z.1)) + (extendFrame (Y z.1) (regeneratedAnswer (U z.1) (Y z.1) (q z.1) z.2.2)) z.2.1)) + have hA : Measurable (fun z : H × ((Fin n × Fin n) → ℝ) => + completedMatrix (U z.1) (Y z.1) z.2) := + measurable_completedMatrix_comp _ _ _ (hUm.comp measurable_fst) (hYm.comp measurable_fst) measurable_snd + have hF : Measurable F := measurable_fst.prodMk + ((measurable_matrix_mulVec_comp _ _ hA (hqm.comp measurable_fst)).prodMk hA) + have hb : Measurable (fun z : H × (((Fin n × Fin n) → ℝ) × ((Fin n ⊕ Unit) → ℝ)) => + regeneratedAnswer (U z.1) (Y z.1) (q z.1) z.2.2) := + measurable_regeneratedAnswer_comp _ _ _ _ (hUm.comp measurable_fst) + (hYm.comp measurable_fst) (hqm.comp measurable_fst) (measurable_snd.comp measurable_snd) + have hUn : Measurable (fun z : H × (((Fin n × Fin n) → ℝ) × ((Fin n ⊕ Unit) → ℝ)) => + extendFrame (U z.1) (q z.1)) := + measurable_extendFrame.comp ((hUm.comp measurable_fst).prodMk (hqm.comp measurable_fst)) + have hYn : Measurable (fun z : H × (((Fin n × Fin n) → ℝ) × ((Fin n ⊕ Unit) → ℝ)) => + extendFrame (Y z.1) (regeneratedAnswer (U z.1) (Y z.1) (q z.1) z.2.2)) := + measurable_extendFrame.comp ((hYm.comp measurable_fst).prodMk hb) + have hR : Measurable R := measurable_fst.prodMk (hb.prodMk + (measurable_completedMatrix_comp _ _ _ hUn hYn (measurable_fst.comp measurable_snd))) + apply prod_event_le_of_section_law ρ + ((standardArrayLaw (Fin n × Fin n)).prod (standardArrayLaw (Fin n ⊕ Unit))) + (standardArrayLaw (Fin n × Fin n)) R F hR hF G hG _ T hT + intro h hh + have hsec := completedMatrix_section_law hn (U h) (Y h) (q h) + (hgood h hh).1 (hgood h hh).2.1 (hgood h hh).2.2.1 (hgood h hh).2.2.2 + have hfo : Measurable (fun g => (completedMatrix (U h) (Y h) g *ᵥ q h, + completedMatrix (U h) (Y h) g)) := + measurable_snd.comp (hF.comp measurable_prodMk_left) + have hro : Measurable (fun z : ((Fin n × Fin n) → ℝ) × ((Fin n ⊕ Unit) → ℝ) => (regeneratedAnswer (U h) (Y h) (q h) z.2, + completedMatrix (extendFrame (U h) (q h)) + (extendFrame (Y h) (regeneratedAnswer (U h) (Y h) (q h) z.2)) z.1)) := + measurable_snd.comp (hR.comp measurable_prodMk_left) + have hout : Measurable (fun t : (Fin n → ℝ) × Matrix (Fin n) (Fin n) ℝ => (h,t)) := + measurable_const.prodMk measurable_id + have he := congrArg (Measure.map (fun t : (Fin n → ℝ) × Matrix (Fin n) (Fin n) ℝ => (h,t))) hsec + have hmfo := Measure.map_map (μ := standardArrayLaw (Fin n × Fin n)) hout hfo + have hmro := Measure.map_map (μ := (standardArrayLaw (Fin n × Fin n)).prod + (standardArrayLaw (Fin n ⊕ Unit))) hout hro + exact hmro.symm.trans (he.symm.trans hmfo) + +theorem regenerated_exponentiallyRare + {H : ℕ → Type*} [∀ n, MeasurableSpace (H n)] + (ρ : ∀ n, Measure (H n)) (r : ℕ) + (U Y : ∀ n, H n → Matrix (Fin n) (Fin r) ℝ) + (q : ∀ n, H n → Fin n → ℝ) + (hUm : ∀ n, Measurable (U n)) (hYm : ∀ n, Measurable (Y n)) + (hqm : ∀ n, Measurable (q n)) + (G : ∀ n, Set (H n)) (hG : ∀ n, MeasurableSet (G n)) + (hrare : ExponentiallyRare ρ (fun n => (G n)ᶜ)) + (hgood : ∀ᶠ n in atTop, ∀ h ∈ G n, + (U n h)ᵀ*U n h=1 ∧ (U n h)ᵀ*Y n h=(Y n h)ᵀ*U n h ∧ + (∑ i, q n h i^2)=1 ∧ (U n h)ᵀ *ᵥ q n h=0) + (T : ∀ n, Set (H n × ((Fin n → ℝ) × Matrix (Fin n) (Fin n) ℝ))) + (hT : ∀ n, MeasurableSet (T n)) + (hbad : ExponentiallyRare (fun n => (ρ n).prod (standardArrayLaw (Fin n × Fin n))) + (fun n => (fun z => (z.1,(completedMatrix (U n z.1) (Y n z.1) z.2 *ᵥ q n z.1, + completedMatrix (U n z.1) (Y n z.1) z.2))) ⁻¹' T n)) : + ExponentiallyRare + (fun n => (ρ n).prod ((standardArrayLaw (Fin n × Fin n)).prod + (standardArrayLaw (Fin n ⊕ Unit)))) + (fun n => (fun z => (z.1,(regeneratedAnswer (U n z.1) (Y n z.1) (q n z.1) z.2.2, + completedMatrix (extendFrame (U n z.1) (q n z.1)) + (extendFrame (Y n z.1) + (regeneratedAnswer (U n z.1) (Y n z.1) (q n z.1) z.2.2)) z.2.1))) ⁻¹' T n) := by + apply exponentiallyRare_of_measure_le_add _ _ ρ _ _ _ hbad hrare + filter_upwards [hgood,eventually_gt_atTop 0] with n hn hn0 + exact regeneration_event_le hn0 (ρ n) (U n) (Y n) (q n) + (hUm n) (hYm n) (hqm n) (G n) (hG n) hn (T n) (hT n) + +end SKGapCutoff.Regression + +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise + +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/ResidualAdmissibility.lean b/lean/OAI/Probability/SKGap/Localization/ResidualAdmissibility.lean new file mode 100644 index 0000000000000000000000000000000000000000..8f2e210ceed31b3069db4ed99f22a17bd6485e37 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/ResidualAdmissibility.lean @@ -0,0 +1,201 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.ResidualRecipe2 + +namespace OAI + +section + +noncomputable section +open scoped BigOperators +namespace SKGapCutoff.Recipe +open Primary +variable {n M : ℕ} {κ σ : Type*} [Fintype κ] [DecidableEq κ] [Fintype σ] +namespace OrdinaryData + +def Admissible (D : OrdinaryData n (Fin M) κ σ) (N p : ℕ) : Prop := + ∀a≤N,∀q:Fin M,q.valh a ha q (hq.trans_le hr) + +omit [Fintype σ] in +lemma Admissible.prefix {D : OrdinaryData n (Fin M) κ σ} {N p A : ℕ} + (h : D.Admissible N p) (hr : A≤N) : D.Admissible A p := + fun a ha=>h a (ha.trans hr) + +lemma Admissible.sourcePartial {D : OrdinaryData n (Fin M) κ σ} {N p : ℕ} + (h : D.Admissible N p) (a : ℕ) (ha : a≤N) (q : Fin M) (hq : q.valif a=N+1 then 0 else D.seedFunction a s i u + seedDerivative := fun a s i u=>if a=N+1 then 0 else D.seedDerivative a s i u + auxFunction := fun a b i u=>if a=N+1 then if b.val=N then 1 else 0 else D.auxFunction a b i u + auxDerivative := fun a b i u=>if a=N+1 then 0 else D.auxDerivative a b i u } + +lemma appendAuxiliary_prefix (D : OrdinaryData n (Fin M) κ σ) (N : ℕ) : + ∀a≤N,(D.appendAuxiliary N).source a=D.source a ∧ + (D.appendAuxiliary N).auxiliary a=D.auxiliary a := by + apply evaluation_prefix_eq D (D.appendAuxiliary N) N rfl rfl rfl rfl + all_goals + intro a ha + have hh : a≠N+1 := by omega + simp [seedCoefficient,auxCoefficient,seedPartial,auxPartial,appendAuxiliary,hh] + +lemma appendAuxiliary_source (D : OrdinaryData n (Fin M) κ σ) (N : ℕ) : + (D.appendAuxiliary N).source (N+1)=D.auxiliary N := by + rw [source_eq] + ext x i + dsimp only [sourceOf] + rw [Fin.sum_univ_castSucc] + have hy : (D.appendAuxiliary N).auxiliary N=D.auxiliary N := (D.appendAuxiliary_prefix N N le_rfl).2 + dsimp only [appendAuxiliary] at hy + simp [seedCoefficient,auxCoefficient,coefficient,appendAuxiliary,hy, + show ∀b:Fin N,b.val≠N from fun b=>Nat.ne_of_lt b.isLt] + +omit [Fintype σ] in +lemma appendAuxiliary_Admissible (D : OrdinaryData n (Fin M) κ σ) (N p : ℕ) + (h : D.Admissible N p) : (D.appendAuxiliary N).Admissible (N+1) p := by + intro a ha q hq + by_cases he : a=N+1 + · subst a + constructor + · intro s; ext x i; simp [seedPartial,localPartial,appendAuxiliary,partialAt] + · intro b; ext x i; simp [auxPartial,localPartial,appendAuxiliary,partialAt] + · have haN : a≤N := by omega + simpa only [seedPartial,auxPartial,localPartial,appendAuxiliary,ite_eq_right he] using h a haN q hq + +end OrdinaryData +end SKGapCutoff.Recipe + +end +end + +section + +noncomputable section +open scoped BigOperators +namespace SKGapCutoff.Recipe +variable {n : ℕ} {ι κ : Type*} [Fintype ι] [DecidableEq ι] [Fintype κ] [DecidableEq κ] + +namespace SegmentRegular +variable {H : ι→VectorFields n} {θ : κ→Spin n→ℝ} +variable {F G : Fin n→Args (ι:=ι) (κ:=κ)→ℝ} +variable {F' G' : Fin n→Args (ι:=ι) (κ:=κ)→Args (ι:=ι) (κ:=κ)→L[ℝ]ℝ} +variable {x : Spin n} {C D : ℝ} + +omit [DecidableEq ι] [DecidableEq κ] in +lemma value_difference (h : SegmentRegular H θ F F' x C) (i k : Fin n) + (t : ℝ) (ht : t∈Set.Icc (0:ℝ) 1) : + |F i (localArgs H θ x i+t • (localArgs H θ (flip x k) i-localArgs H θ x i))- + F i (localArgs H θ x i)|≤C*‖t • (localArgs H θ (flip x k) i-localArgs H θ x i)‖ := by + let u:=localArgs H θ x i + let v:=localArgs H θ (flip x k) i + have hm (s : ℝ) (hs : s∈Set.Icc (0:ℝ) 1) : s*t∈Set.Icc (0:ℝ) 1 := + ⟨mul_nonneg hs.1 ht.1,(mul_le_mul hs.2 ht.2 ht.1 (by norm_num)).trans_eq (by norm_num)⟩ + have he (s : ℝ) : u+s • (u+t • (v-u)-u)=u+(s*t) • (v-u) := by module + have hb:=SKGap.SourceTaylor.segment_lipschitz (F i) (F' i) u (u+t • (v-u)) h.nonneg + (fun s hs=>by rw [he]; exact h.deriv i k (s*t) (hm s hs)) + (fun s hs=>by rw [he]; exact h.bound i k (s*t) (hm s hs)) + simpa only [add_sub_cancel_left] using hb + +omit [DecidableEq ι] [DecidableEq κ] in +lemma mul (hF : SegmentRegular H θ F F' x C) (hG : SegmentRegular H θ G G' x D) + {A B : ℝ} (hA : 0≤A) (hB : 0≤B) + (hvF : ∀i k t, t∈Set.Icc (0:ℝ) 1→ + |F i (localArgs H θ x i+t • (localArgs H θ (flip x k) i-localArgs H θ x i))|≤A) + (hvG : ∀i k t, t∈Set.Icc (0:ℝ) 1→ + |G i (localArgs H θ x i+t • (localArgs H θ (flip x k) i-localArgs H θ x i))|≤B) : + SegmentRegular H θ (fun i u=>F i u*G i u) + (fun i u=>F i u • G' i u+G i u • F' i u) x (A*D+B*C+2*C*D) := by + refine ⟨by positivity [hF.nonneg,hG.nonneg],?_,?_,?_⟩ + · intro i k t ht + exact (hF.deriv i k t ht).mul (hG.deriv i k t ht) + · intro i k t ht + let u:=localArgs H θ x i+t • (localArgs H θ (flip x k) i-localArgs H θ x i) + have h₁ : ‖F i u • G' i u‖≤A*D := by + rw [norm_smul,Real.norm_eq_abs] + exact mul_le_mul (hvF i k t ht) (hG.bound i k t ht) (norm_nonneg _) hA + have h₂ : ‖G i u • F' i u‖≤B*C := by + rw [norm_smul,Real.norm_eq_abs] + exact mul_le_mul (hvG i k t ht) (hF.bound i k t ht) (norm_nonneg _) hB + have hh := (norm_add_le _ _).trans (add_le_add h₁ h₂) + exact hh.trans (le_add_of_nonneg_right (by positivity [hF.nonneg,hG.nonneg])) + · intro i k t ht + let u:=localArgs H θ x i + let v:=u+t • (localArgs H θ (flip x k) i-u) + let d:=‖t • (localArgs H θ (flip x k) i-u)‖ + have hf : |F i v-F i u|≤C*d := hF.value_difference i k t ht + have hg : |G i v-G i u|≤D*d := hG.value_difference i k t ht + have hf' : ‖F' i v-F' i u‖≤C*d := hF.lip i k t ht + have hg' : ‖G' i v-G' i u‖≤D*d := hG.lip i k t ht + have hfu : ‖F' i u‖≤C := by simpa [u] using hF.bound i k 0 (by constructor <;> norm_num) + have hgu : ‖G' i u‖≤D := by simpa [u] using hG.bound i k 0 (by constructor <;> norm_num) + have he : (F i v • G' i v+G i v • F' i v)-(F i u • G' i u+G i u • F' i u)= + (F i v • (G' i v-G' i u)+(F i v-F i u) • G' i u)+ + (G i v • (F' i v-F' i u)+(G i v-G i u) • F' i u) := by module + change ‖(F i v • G' i v+G i v • F' i v)-(F i u • G' i u+G i u • F' i u)‖≤_ + rw [he] + have h₁ : ‖F i v • (G' i v-G' i u)‖≤A*(D*d) := by + rw [norm_smul,Real.norm_eq_abs]; exact mul_le_mul (hvF i k t ht) hg' (norm_nonneg _) hA + have h₂ : ‖(F i v-F i u) • G' i u‖≤(C*d)*D := by + rw [norm_smul,Real.norm_eq_abs]; exact mul_le_mul hf hgu (norm_nonneg _) (by positivity [hF.nonneg]) + have h₃ : ‖G i v • (F' i v-F' i u)‖≤B*(C*d) := by + rw [norm_smul,Real.norm_eq_abs]; exact mul_le_mul (hvG i k t ht) hf' (norm_nonneg _) hB + have h₄ : ‖(G i v-G i u) • F' i u‖≤(D*d)*C := by + rw [norm_smul,Real.norm_eq_abs]; exact mul_le_mul hg hfu (norm_nonneg _) (by positivity [hG.nonneg]) + have hh := (norm_add_le _ _).trans (add_le_add + ((norm_add_le _ _).trans (add_le_add h₁ h₂)) + ((norm_add_le _ _).trans (add_le_add h₃ h₄))) + exact hh.trans_eq (by dsimp only [d]; ring) + +end SegmentRegular +end SKGapCutoff.Recipe + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/ResidualInduction.lean b/lean/OAI/Probability/SKGap/Localization/ResidualInduction.lean new file mode 100644 index 0000000000000000000000000000000000000000..e56be9100227de84223b27c4a53ef930e901945d --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/ResidualInduction.lean @@ -0,0 +1,163 @@ +import Mathlib +import OAI.Probability.SKGap.Gaussian.PhiStein +import OAI.Probability.SKGap.Localization.PrimaryDifferentiation + +namespace OAI + +section + +noncomputable section +open scoped BigOperators +namespace SKGapCutoff.Primary +open Matrix SKGap.Stein +variable {n : ℕ} + +def mag (j : ℝ) (J : Interaction n) (h : Fin n→ℝ) (k : ℕ) : VectorFields n := + (primaryState j J h k).1 + +def fld (j : ℝ) (J : Interaction n) (h : Fin n→ℝ) (k : ℕ) : VectorFields n := + (primaryState j J h k).2 + +def onsager (j : ℝ) (J : Interaction n) (h : Fin n→ℝ) (k : ℕ) : Spin n→ℝ := + siteMean (fun x i=>1-(mag j J h k x i)^2) + +def residual (j : ℝ) (J : Interaction n) (h : Fin n→ℝ) (k : ℕ) : VectorFields n := + fun x i=>mag j J h k x i-mag j J h (k+1) x i + +def previousResidual (j : ℝ) (J : Interaction n) (h : Fin n→ℝ) (k : ℕ) : VectorFields n := + fun x i=>mag j J h (k-1) x i-mag j J h k x i + +lemma mag_zero (j : ℝ) (J : Interaction n) (h : Fin n→ℝ) : mag j J h 0=spin := rfl +lemma mag_succ (j : ℝ) (J : Interaction n) (h : Fin n→ℝ) (k : ℕ) (x : Spin n) (i : Fin n) : + mag j J h (k+1) x i=Real.tanh (fld j J h k x i) := rfl +lemma onsager_zero (j : ℝ) (J : Interaction n) (h : Fin n→ℝ) (x : Spin n) : + onsager j J h 0 x=0 := by simp [onsager,siteMean,mag_zero,spin_sq] + +lemma fld_eq (j : ℝ) (J : Interaction n) (h : Fin n→ℝ) (k : ℕ) (x : Spin n) (i : Fin n) : + fld j J h k x i=h i+∑a,J i a*mag j J h k x a- + j*onsager j J h k x*mag j J h (k-1) x i := by + cases k with + | zero => simp [fld,primaryState,mag,onsager_zero] + | succ k => rfl + +lemma primary_residual_field (j : ℝ) (J : Interaction n) (h : Fin n→ℝ) + (k : ℕ) (x : Spin n) (i : Fin n) : + let a:=j*(onsager j J h (k+1) x-onsager j J h k x) + fld j J h k x i-fld j J h (k+1) x i-a*mag j J h (k+1) x i= + (∑l,J i l*residual j J h k x l)+a*residual j J h k x i- + j*onsager j J h k x*previousResidual j J h k x i := by + dsimp only + rw [fld_eq,fld_eq] + simp only [Nat.add_sub_cancel,residual,previousResidual,mul_sub,Finset.sum_sub_distrib] + ring + +lemma residual_inner_product (hn : 0 + phi (fld j J h k x i) (fld j J h (k+1) x i) + (j*(onsager j J h (k+1) x-onsager j J h k x))*U x i + +def steinPartial (j : ℝ) (J : Interaction n) (h : Fin n→ℝ) (k : ℕ) + (U : VectorFields n) : VectorFields n := fun x i=> + phiZ (fld j J h k x i) (fld j J h (k+1) x i) + (j*(onsager j J h (k+1) x-onsager j J h k x))*U x i + +lemma stein_residual_pointwise (j : ℝ) (J : Interaction n) (h : Fin n→ℝ) (k : ℕ) + (U : VectorFields n) (x : Spin n) (i : Fin n) : + residual j J h (k+1) x i*U x i= + (fld j J h k x i-fld j J h (k+1) x i- + j*(onsager j J h (k+1) x-onsager j J h k x)*mag j J h (k+1) x i)* + steinSource j J h k U x i- + j*(onsager j J h (k+1) x-onsager j J h k x)*steinPartial j J h k U x i := by + dsimp only [steinSource,steinPartial,residual] + simp only [mag_succ] + rw [←phi_stein (fld j J h k x i) (fld j J h (k+1) x i) + (j*(onsager j J h (k+1) x-onsager j J h k x))] + ring + +def nextField {ι κ : Type*} [Fintype ι] [Fintype κ] + (j : ℝ) (J : Interaction n) (h : Fin n→ℝ) (k : ℕ) + (U : VectorFields n) (L : ι→ℕ) (α : ι→Spin n→ℝ) + (W : κ→VectorFields n) (γ : κ→Spin n→ℝ) : VectorFields n := fun x i=> + (∑l,J i l*steinSource j J h k U x l)- + j*siteMean (steinPartial j J h k U) x*mag j J h k x i- + j*(∑l,α l x*mag j J h (L l) x i)-j*∑b,γ b x*W b x i + +theorem residual_induction_identity {ι κ : Type*} [Fintype ι] [Fintype κ] + (hn : 0mul_nonneg (hP x) (sq_nonneg _)) + (varianceEnergy_nonneg P hP f) + +lemma halfDiff_mul_flipped (i : Fin n) (θ G : Observables n) (x : Spin n) : + halfDiff i (fun y=>θ y*G y) x=θ (flip x i)*halfDiff i G x+G x*halfDiff i θ x := by + rw [halfDiff_mul] + have h:=flip_sub i θ x + rw [show θ (flip x i)=θ x-2*spin x i*halfDiff i θ x by linarith] + ring + +lemma multiplier_energy (P : Spin n→ℝ) (hP : ∀x,0≤P x) + (θ G : Observables n) {B L : ℝ} + (hB : 0≤B) (hL : 0≤L) (hθ : ∀x,|θ x|≤B) + (hd : ∀x,∑i,(halfDiff i θ x)^2≤L^2) : + varianceEnergy P (fun x=>θ x*G x)≤ + 2*B^2*varianceEnergy P G+2*L^2*(∑x,P x*(G x)^2) := by + have ht (x : Spin n) (i : Fin n) : (θ (flip x i))^2≤B^2 := by + simpa only [sq_abs] using (sq_le_sq₀ (abs_nonneg _) hB).2 (hθ (flip x i)) + calc + _ ≤ ∑x,P x*∑i,conditionalVariance P x i* + (2*B^2*(halfDiff i G x)^2+2*(G x)^2*(halfDiff i θ x)^2) := by + apply Finset.sum_le_sum; intro x _ + apply mul_le_mul_of_nonneg_left _ (hP x) + apply Finset.sum_le_sum; intro i _ + apply mul_le_mul_of_nonneg_left _ (conditionalVariance_nonneg P hP x i) + rw [halfDiff_mul_flipped] + have hh:=mul_le_mul_of_nonneg_right (ht x i) (sq_nonneg (halfDiff i G x)) + nlinarith only [hh,sq_nonneg (θ (flip x i)*halfDiff i G x-G x*halfDiff i θ x)] + _ ≤ ∑x,P x*(2*B^2*(∑i,conditionalVariance P x i*(halfDiff i G x)^2)+2*(G x)^2*L^2) := by + apply Finset.sum_le_sum; intro x _ + apply mul_le_mul_of_nonneg_left _ (hP x) + simp only [mul_add,Finset.sum_add_distrib] + have h1 : (∑i,conditionalVariance P x i*(2*B^2*(halfDiff i G x)^2))= + 2*B^2*(∑i,conditionalVariance P x i*(halfDiff i G x)^2) := by + simp only [Finset.mul_sum]; apply Finset.sum_congr rfl; intro i _; ring + rw [h1] + apply add_le_add_right + calc + _ ≤ ∑i,2*(G x)^2*(halfDiff i θ x)^2 := by + apply Finset.sum_le_sum; intro i _ + exact mul_le_of_le_one_left (by positivity) (conditionalVariance_le_one P x i) + _ = 2*(G x)^2*(∑i,(halfDiff i θ x)^2) := by rw [Finset.mul_sum] + _ ≤ _ := by + simpa only [mul_comm (2*(G x)^2)] using + mul_le_mul (hd x) (le_refl (2*(G x)^2)) (by positivity) (pow_nonneg hL 2) + _ = _ := by + simp only [mul_add,Finset.sum_add_distrib,varianceEnergy,Finset.mul_sum] + congr 1 <;> apply Finset.sum_congr rfl <;> intro x _ <;> ring_nf + +lemma multiplier_starSquared (P : Spin n→ℝ) (hP : ∀x,0≤P x) + (θ G : Observables n) {B L : ℝ} + (hB : 0≤B) (hL : 0≤L) (hθ : ∀x,|θ x|≤B) + (hd : ∀x,∑i,(halfDiff i θ x)^2≤L^2) : + starSquared P (fun x=>θ x*G x)≤(3*B^2+2*L^2)*starSquared P G := by + have hs : (∑x,P x*(θ x*G x)^2)≤B^2*(∑x,P x*(G x)^2) := by + rw [Finset.mul_sum] + apply Finset.sum_le_sum; intro x _ + have ht : (θ x)^2≤B^2 := by simpa only [sq_abs] using pow_le_pow_left₀ (abs_nonneg _) (hθ x) 2 + nlinarith only [mul_le_mul_of_nonneg_left + (mul_le_mul_of_nonneg_right ht (sq_nonneg (G x))) (hP x)] + have he:=multiplier_energy P hP θ G hB hL hθ hd + have hn:=varianceEnergy_nonneg P hP G + have hn' : 0≤∑x,P x*(G x)^2 := Finset.sum_nonneg fun x _=>mul_nonneg (hP x) (sq_nonneg _) + dsimp only [starSquared] + nlinarith [mul_nonneg (sq_nonneg B) hn,mul_nonneg (sq_nonneg L) hn, + mul_nonneg (sq_nonneg B) hn'] + +lemma star_multiplier (P : Spin n→ℝ) (hP : ∀x,0≤P x) + (θ G : Observables n) {B L : ℝ} + (hB : 0≤B) (hL : 0≤L) (hθ : ∀x,|θ x|≤B) + (hd : ∀x,∑i,(halfDiff i θ x)^2≤L^2) : + starNorm P (fun x=>θ x*G x)≤Real.sqrt (3*B^2+2*L^2)*starNorm P G := by + exact (Real.sqrt_le_sqrt (multiplier_starSquared P hP θ G hB hL hθ hd)).trans_eq + (Real.sqrt_mul (by positivity) _) + +lemma expected_abs_le_star (P : Spin n→ℝ) (hP : ∀x,0≤P x) (hPsum : ∑x,P x=1) + (G : Observables n) : (∑x,P x*|G x|)≤ starNorm P G := by + have hc:=weighted_cauchy_sq P (fun x=>|G x|) (fun _=>1) hP + simp only [mul_one,one_pow,sq_abs,hPsum] at hc + have hn : 0≤∑x,P x*|G x| := Finset.sum_nonneg fun x _=>mul_nonneg (hP x) (abs_nonneg _) + apply (sq_le_sq₀ hn (Real.sqrt_nonneg _)).1 + rw [Real.sq_sqrt (starSquared_nonneg P hP G)] + exact hc.trans (le_add_of_nonneg_right (varianceEnergy_nonneg P hP G)) + +lemma sqrt_energy_le_star (P : Spin n→ℝ) (hP : ∀x,0≤P x) (G : Observables n) : + Real.sqrt (varianceEnergy P G)≤ starNorm P G := by + apply Real.sqrt_le_sqrt + exact le_add_of_nonneg_left (Finset.sum_nonneg fun x _=>mul_nonneg (hP x) (sq_nonneg _)) + +theorem signed_base_star (P : Spin n→ℝ) (hP : ∀x,0≤P x) (hPsum : ∑x,P x=1) + (G : Observables n) (U : VectorFields n) {A B : ℝ} (hA : 0≤A) (hB : 0≤B) + (hD : ∀x,∑i,|halfDiff i (fun y=>U y i) x|≤A) (hU : ∀x,∑i,(U x i)^2≤B^2) : + |∑x,P x*G x*∑i,(spin x i-conditionalMean P x i)*U x i|≤(2*B+5*A)*starNorm P G := by + have H:=signed_weak_residual_base P hP hPsum G U hA hB hD hU + have h1:=mul_le_mul_of_nonneg_left (expected_abs_le_star P hP hPsum G) hA + have h2:=mul_le_mul_of_nonneg_left (sqrt_energy_le_star P hP G) (show 0≤2*B+4*A by positivity) + linarith + +end SKGapCutoff.Static + +end +end + +section + +noncomputable section +open scoped BigOperators Matrix.Norms.Frobenius +namespace SKGapCutoff.Static +open Primary Recipe +universe u +variable {Ω : Type u} {n : Ω→ℕ} + +def UniformMultiplier (θ : ∀a,Observables (n a)) : Prop := + ∃B L : ℝ,0≤B ∧ 0≤L ∧ (∀a x,|θ a x|≤B) ∧ + (∀a x,∑i,(halfDiff i (θ a) x)^2≤L^2) + +def UniformWeak (P F : ∀a,Observables (n a)) : Prop := + ∃C : ℝ,0≤C ∧ ∀a G,|∑x,P a x*G x*F a x|≤C*starNorm (P a) G + +lemma UniformWeak.zero (P : ∀a,Observables (n a)) : UniformWeak P (fun _ _=>0) := by + refine ⟨0,le_rfl,?_⟩ + simp + +lemma UniformWeak.congr {P F F' : ∀a,Observables (n a)} (h : UniformWeak P F) + (he : ∀a x,F a x=F' a x) : UniformWeak P F' := by + have : F=F' := funext fun a=>funext (he a) + rwa [←this] + +lemma UniformWeak.add {P F H : ∀a,Observables (n a)} (hF : UniformWeak P F) + (hH : UniformWeak P H) : UniformWeak P (fun a x=>F a x+H a x) := by + obtain ⟨C,hC,hF⟩:=hF + obtain ⟨D,hD,hH⟩:=hH + refine ⟨C+D,add_nonneg hC hD,fun a G=>?_⟩ + simp only [mul_add,Finset.sum_add_distrib] + exact (abs_add_le _ _).trans ((add_le_add (hF a G) (hH a G)).trans_eq (by ring)) + +lemma UniformWeak.neg {P F : ∀a,Observables (n a)} (hF : UniformWeak P F) : + UniformWeak P (fun a x=>-F a x) := by + obtain ⟨C,hC,hF⟩:=hF + refine ⟨C,hC,fun a G=>?_⟩ + simpa using hF a G + +lemma UniformWeak.sub {P F H : ∀a,Observables (n a)} (hF : UniformWeak P F) + (hH : UniformWeak P H) : UniformWeak P (fun a x=>F a x-H a x) := by + simpa only [sub_eq_add_neg] using hF.add hH.neg + +lemma UniformWeak.sum {τ : Type*} [Fintype τ] {P : ∀a,Observables (n a)} + {F : τ→∀a,Observables (n a)} (h : ∀t,UniformWeak P (F t)) : + UniformWeak P (fun a x=>∑t,F t a x) := by + classical + choose C hC hb using h + refine ⟨∑t,C t,Finset.sum_nonneg (fun t _=>hC t),fun a G=>?_⟩ + simp only [Finset.mul_sum] + rw [Finset.sum_comm] + exact (Finset.abs_sum_le_sum_abs ..).trans + ((Finset.sum_le_sum fun t _=>hb t a G).trans_eq (Finset.sum_mul ..).symm) + +lemma UniformWeak.mul {P F θ : ∀a,Observables (n a)} (hP : ∀a x,0≤P a x) + (hF : UniformWeak P F) (hθ : UniformMultiplier θ) : + UniformWeak P (fun a x=>θ a x*F a x) := by + obtain ⟨C,hC,hF⟩:=hF + obtain ⟨B,L,hB,hL,hθ,hd⟩:=hθ + refine ⟨C*Real.sqrt (3*B^2+2*L^2),by positivity,fun a G=>?_⟩ + have hf:=hF a (fun x=>θ a x*G x) + have hm:=mul_le_mul_of_nonneg_left (star_multiplier (P a) (hP a) (θ a) G hB hL (hθ a) (hd a)) hC + calc + _ = |∑x,P a x*(θ a x*G x)*F a x| := by + congr 1; apply Finset.sum_congr rfl; intro x _; ring + _ ≤ C*(Real.sqrt (3*B^2+2*L^2)*starNorm (P a) G) := hf.trans hm + _ = _ := by ring + +lemma UniformMultiplier.const (c : ℝ) : UniformMultiplier (n:=n) (fun _ _=>c) := by + refine ⟨|c|,0,abs_nonneg _,le_rfl,fun _ _=>le_rfl,?_⟩ + intro a x + simp [halfDiff] + +lemma UniformWeak.smul {P F : ∀a,Observables (n a)} (hP : ∀a x,0≤P a x) + (hF : UniformWeak P F) (c : ℝ) : UniformWeak P (fun a x=>c*F a x) := + hF.mul hP (UniformMultiplier.const c) + +lemma UniformWeak.base (P : ∀a,Observables (n a)) (hP : ∀a x,0≤P a x) + (hp : ∀a,∑x,P a x=1) (U : ∀a,VectorFields (n a)) + {A B : ℝ} (hA : 0≤A) (hB : 0≤B) + (hD : ∀a x,∑i,|halfDiff i (fun y=>U a y i) x|≤A) + (hU : ∀a x,vectorNorm (U a x)≤B) : + UniformWeak P (fun a x=>∑i,(spin x i-conditionalMean (P a) x i)*U a x i) := by + refine ⟨2*B+5*A,by positivity,fun a G=>?_⟩ + apply signed_base_star (P a) (hP a) (hp a) G (U a) hA hB (hD a) + intro x + simpa only [vectorNorm_sq] using pow_le_pow_left₀ (vectorNorm_nonneg _) (hU a x) 2 + +lemma UniformMultiplier.normedMean (hn : ∀a,0Real.sqrt (n a:ℝ)*siteMean (U a) x) := by + refine ⟨B,B,hB,hB,fun a x=>scaledMean_size (hn a) _ _ hB (hU a x).size, + fun a x=>scaledMean_difference (hn a) _ _ hB (hU a x).derivative⟩ + +end SKGapCutoff.Static + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/ResidualRecipe.lean b/lean/OAI/Probability/SKGap/Localization/ResidualRecipe.lean new file mode 100644 index 0000000000000000000000000000000000000000..9d862d784cdb448e212b71dacc659bca0106fb68 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/ResidualRecipe.lean @@ -0,0 +1,361 @@ +import Mathlib +import OAI.Probability.SKGap.Entropy.ParameterMapWeight + +namespace OAI + +section +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open scoped BigOperators +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open scoped BigOperators +open scoped BigOperators NNReal ENNReal +open MeasureTheory Metric Set +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators NNReal ENNReal Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Set +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators ENNReal NNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Matrix +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators ENNReal NNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal +open scoped BigOperators +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise NNReal ENNReal +open scoped BigOperators +open Filter Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +namespace SKGapCutoff.Regression + +lemma linear_combination_lipschitz {E : Type*} [PseudoMetricSpace E] + {ι : Type*} [Fintype ι] (f : ι → E → ℝ) {K : ℝ≥0} + (hf : ∀ i, LipschitzWith K (f i)) (c : ι → ℝ) : + LipschitzWith (∑ i, ‖c i‖₊ * K) (fun x => ∑ i, c i*f i x) := by + apply LipschitzWith.of_dist_le_mul + intro x y + rw [Real.dist_eq, ← Finset.sum_sub_distrib] + calc + |∑ i, (c i*f i x-c i*f i y)| ≤ ∑ i, |c i*f i x-c i*f i y| := + Finset.abs_sum_le_sum_abs _ _ + _ ≤ ∑ i, |c i| *((K:ℝ)*dist x y) := by + apply Finset.sum_le_sum + intro i _ + rw [← mul_sub, abs_mul] + exact mul_le_mul_of_nonneg_left (hf i |>.dist_le_mul x y) (abs_nonneg _) + _ = _ := by simp only [NNReal.coe_sum, NNReal.coe_mul, coe_nnnorm, Real.norm_eq_abs]; + rw [Finset.sum_mul]; apply Finset.sum_congr rfl; intro i _; ring + +lemma linear_combination_coefficient_bound {E : Type*} + {ι : Type*} [Fintype ι] (f : ι → E → ℝ) {B : ℝ≥0} + (hB : ∀ i x, |f i x| ≤ B) (a c : ι → ℝ) (x : E) : + dist (∑ i, a i*f i x) (∑ i, c i*f i x) ≤ + (Fintype.card ι:ℝ)*B*dist a c := by + rw [Real.dist_eq, ← Finset.sum_sub_distrib] + calc + |∑ i, (a i*f i x-c i*f i x)| ≤ ∑ i, |a i*f i x-c i*f i x| := + Finset.abs_sum_le_sum_abs _ _ + _ ≤ ∑ _i : ι, dist a c*(B:ℝ) := by + apply Finset.sum_le_sum + intro i _ + rw [← sub_mul, abs_mul] + exact mul_le_mul (dist_le_pi_dist a c i) (hB i x) (abs_nonneg _) dist_nonneg + _ = _ := by simp; ring + + theorem ExponentialEmpiricalConcentration.linear_combination + {E : Type*} [PseudoMetricSpace E] [MeasurableSpace E] [BorelSpace E] + {H : ℕ → Type*} [∀ n, MeasurableSpace (H n)] + {ρ : ∀ n, Measure (H n)} {X : ∀ n, H n → Fin n → E} {ν : Measure E} + (hX : ExponentialEmpiricalConcentration ρ X ν) + {ι : Type*} [Fintype ι] (f : ι → E → ℝ) {K B : ℝ≥0} + (hf : ∀ i, LipschitzWith K (f i)) (hB : ∀ i x, |f i x| ≤ B) + (C : ∀ n, H n → ι → ℝ) (c : ι → ℝ) (hC : ExponentialConvergence ρ C c) : + ExponentialEmpiricalConcentration ρ (fun n h a => ∑ i, C n h i*f i (X n h a)) + (ν.map (fun x => ∑ i, c i*f i x)) := by + exact hX.parameter_map C c hC (fun c x => ∑ i, c i*f i x) + (linear_combination_lipschitz f hf c) ((Fintype.card ι:ℝ)*B) (by positivity) + (fun a x => linear_combination_coefficient_bound f hB a c x) + +lemma integral_quadratic_expansion + {E : Type*} [MeasurableSpace E] {ν : Measure E} + {ι : Type*} [Fintype ι] (f : ι → E → ℝ) (c : ι → ℝ) + (hf : ∀ i j, Integrable (fun x => f i x*f j x) ν) : + (∫ x, (∑ i, c i*f i x)^2 ∂ν) = + ∑ i, ∑ j, c i*(∫ x, f i x*f j x ∂ν)*c j := by + have hid x : (∑ i, c i*f i x)^2 = ∑ i, ∑ j, c i*(f i x*f j x)*c j := by + simp only [pow_two, Finset.sum_mul, Finset.mul_sum] + apply Finset.sum_congr rfl + intro i _ + apply Finset.sum_congr rfl + intro j _ + ring + simp_rw [hid] + rw [integral_finsetSum] + · apply Finset.sum_congr rfl + intro i _ + rw [integral_finsetSum] + · simp only [integral_mul_const, integral_const_mul] + · intro j _ + exact ((hf i j).const_mul (c i)).mul_const (c j) + · intro i _ + exact integrable_finsetSum _ (fun j _ => ((hf i j).const_mul (c i)).mul_const (c j)) + +lemma ExponentialEmpiricalConcentration.linear_combination_energy + {E : Type*} [PseudoMetricSpace E] [MeasurableSpace E] [BorelSpace E] + {H : ℕ → Type*} [∀ n, MeasurableSpace (H n)] + {ρ : ∀ n, Measure (H n)} {X : ∀ n, H n → Fin n → E} {ν : Measure E} + [IsProbabilityMeasure ν] (hX : ExponentialEmpiricalConcentration ρ X ν) + {ι : Type*} [Fintype ι] (f : ι → E → ℝ) {K B : ℝ≥0} + (hf : ∀ i, LipschitzWith K (f i)) (hB : ∀ i x, |f i x| ≤ B) + (C : ∀ n, H n → ι → ℝ) (c : ι → ℝ) (hC : ExponentialConvergence ρ C c) : + ExponentialConvergence ρ (fun n h => (∑ a, (∑ i, C n h i*f i (X n h a))^2)/(n:ℝ)) + (∫ x, (∑ i, c i*f i x)^2 ∂ν) := by + rw [integral_quadratic_expansion f c] + · exact hX.linear_combination_second_moment f hf hB C c hC + · intro i j + apply integrable_bounded_lipschitz ν + (bounded_product_lipschitz (hf i) (hf j) (hB i) (hB j)) ((B:ℝ)^2) + intro x + rw [abs_mul, pow_two] + exact mul_le_mul (hB i x) (hB j x) (abs_nonneg _) B.coe_nonneg + +def residualRecipe {E ι : Type*} [Fintype ι] + (f : ι → E → ℝ) (g : E → ℝ) (c : ι → ℝ) (x : E) : ℝ := + g x - ∑ i, c i*f i x + +lemma ExponentialConvergence.residual_coefficients + {H : ℕ → Type*} [∀ n, MeasurableSpace (H n)] {ρ : ∀ n, Measure (H n)} + {ι : Type*} [Fintype ι] {C : ∀ n, H n → ι → ℝ} {c : ι → ℝ} + (hC : ExponentialConvergence ρ C c) : + ExponentialConvergence ρ (fun n h (i : Option ι) => i.elim 1 (fun j => -C n h j)) + (fun i : Option ι => i.elim 1 (fun j => -c j)) := by + apply hC.continuous_map (f := fun a (i : Option ι) => i.elim 1 (fun j => -a j)) + apply Continuous.continuousAt + apply continuous_pi + intro i + cases i <;> simp only [Option.elim_none, Option.elim_some] <;> fun_prop + +lemma residualRecipe_eq_option {E ι : Type*} [Fintype ι] + (f : ι → E → ℝ) (g : E → ℝ) (c : ι → ℝ) (x : E) : + residualRecipe f g c x = + ∑ i : Option ι, i.elim 1 (fun j => -c j)*i.elim (g x) (fun j => f j x) := by + simp [residualRecipe, Fintype.sum_option, neg_mul, Finset.sum_neg_distrib, sub_eq_add_neg] + +lemma ExponentialEmpiricalConcentration.residual + {E : Type*} [PseudoMetricSpace E] [MeasurableSpace E] [BorelSpace E] + {H : ℕ → Type*} [∀ n, MeasurableSpace (H n)] + {ρ : ∀ n, Measure (H n)} {X : ∀ n, H n → Fin n → E} {ν : Measure E} + (hX : ExponentialEmpiricalConcentration ρ X ν) + {ι : Type*} [Fintype ι] (f : ι → E → ℝ) (g : E → ℝ) {K B : ℝ≥0} + (hf : ∀ i, LipschitzWith K (f i)) (hg : LipschitzWith K g) + (hB : ∀ i x, |f i x| ≤ B) (hBg : ∀ x, |g x| ≤ B) + (C : ∀ n, H n → ι → ℝ) (c : ι → ℝ) (hC : ExponentialConvergence ρ C c) : + ExponentialEmpiricalConcentration ρ + (fun n h a => residualRecipe f g (C n h) (X n h a)) + (ν.map (residualRecipe f g c)) := by + change ExponentialEmpiricalConcentration ρ + (fun n h a => residualRecipe f g (C n h) (X n h a)) + (ν.map (fun x => residualRecipe f g c x)) + have hh := hX.linear_combination + (fun i : Option ι => i.elim g f) + (K := K) (B := B) (fun i => by cases i <;> simp_all) + (fun i x => by cases i <;> simp_all) + _ _ hC.residual_coefficients + simpa only [residualRecipe, Fintype.sum_option, Option.elim_apply, Option.elim_none, + Option.elim_some, one_mul, neg_mul, Finset.sum_neg_distrib, sub_eq_add_neg] using hh + +lemma ExponentialEmpiricalConcentration.residual_energy + {E : Type*} [PseudoMetricSpace E] [MeasurableSpace E] [BorelSpace E] + {H : ℕ → Type*} [∀ n, MeasurableSpace (H n)] + {ρ : ∀ n, Measure (H n)} {X : ∀ n, H n → Fin n → E} {ν : Measure E} + [IsProbabilityMeasure ν] (hX : ExponentialEmpiricalConcentration ρ X ν) + {ι : Type*} [Fintype ι] (f : ι → E → ℝ) (g : E → ℝ) {K B : ℝ≥0} + (hf : ∀ i, LipschitzWith K (f i)) (hg : LipschitzWith K g) + (hB : ∀ i x, |f i x| ≤ B) (hBg : ∀ x, |g x| ≤ B) + (C : ∀ n, H n → ι → ℝ) (c : ι → ℝ) (hC : ExponentialConvergence ρ C c) : + ExponentialConvergence ρ + (fun n h => (∑ a, (residualRecipe f g (C n h) (X n h a))^2)/(n:ℝ)) + (∫ x, (residualRecipe f g c x)^2 ∂ν) := by + have hh := hX.linear_combination_energy + (fun i : Option ι => i.elim g f) + (K := K) (B := B) (fun i => by cases i <;> simp_all) + (fun i x => by cases i <;> simp_all) + _ _ hC.residual_coefficients + simpa only [residualRecipe, Fintype.sum_option, Option.elim_apply, Option.elim_none, + Option.elim_some, one_mul, neg_mul, Finset.sum_neg_distrib, sub_eq_add_neg] using hh + +theorem ExponentialEmpiricalConcentration.normalized_residual + {E : Type*} [PseudoMetricSpace E] [MeasurableSpace E] [BorelSpace E] + {H : ℕ → Type*} [∀ n, MeasurableSpace (H n)] + {ρ : ∀ n, Measure (H n)} {X : ∀ n, H n → Fin n → E} {ν : Measure E} + [IsProbabilityMeasure ν] (hX : ExponentialEmpiricalConcentration ρ X ν) + {ι : Type*} [Fintype ι] (f : ι → E → ℝ) (g : E → ℝ) {K B : ℝ≥0} + (hf : ∀ i, LipschitzWith K (f i)) (hg : LipschitzWith K g) + (hB : ∀ i x, |f i x| ≤ B) (hBg : ∀ x, |g x| ≤ B) + (C : ∀ n, H n → ι → ℝ) (c : ι → ℝ) (hC : ExponentialConvergence ρ C c) + (hs : 0 < ∫ x, (residualRecipe f g c x)^2 ∂ν) : + ExponentialEmpiricalConcentration ρ + (fun n h a => residualRecipe f g (C n h) (X n h a) / + Real.sqrt ((∑ b, (residualRecipe f g (C n h) (X n h b))^2)/(n:ℝ))) + (ν.map (fun x => residualRecipe f g c x / + Real.sqrt (∫ y, (residualRecipe f g c y)^2 ∂ν))) := by + let S n h := (∑ b, (residualRecipe f g (C n h) (X n h b))^2)/(n:ℝ) + let s := ∫ x, (residualRecipe f g c x)^2 ∂ν + have hS : ExponentialConvergence ρ S s := hX.residual_energy f g hf hg hB hBg C c hC + have hc : ContinuousAt (fun z : (Option ι → ℝ) × ℝ => + fun i => z.1 i / Real.sqrt z.2) + ((fun i : Option ι => i.elim 1 (fun j => -c j)),s) := by + apply continuousAt_pi.mpr + intro i + exact (by fun_prop : Continuous (fun z : (Option ι → ℝ) × ℝ => z.1 i)).continuousAt.div + (Real.continuous_sqrt.comp continuous_snd).continuousAt (ne_of_gt (Real.sqrt_pos.mpr hs)) + have hcoeff := (hC.residual_coefficients.prod hS).continuous_map hc + have hh := hX.linear_combination (fun i : Option ι => i.elim g f) + (K := K) (B := B) (fun i => by cases i <;> simp_all) + (fun i x => by cases i <;> simp_all) _ _ hcoeff + simp only [Option.elim_apply, Fintype.sum_option, Option.elim_none, Option.elim_some] at hh + simpa only [residualRecipe, one_div, div_mul_eq_mul_div, neg_mul, + ← Finset.sum_div, Finset.sum_neg_distrib, neg_div, ← sub_eq_add_neg, ← sub_div, S, s, + inv_mul_eq_div] using hh + +lemma ExponentialConvergence.positive_rare + {H : ℕ → Type*} [∀ n, MeasurableSpace (H n)] {ρ : ∀ n, Measure (H n)} + {S : ∀ n, H n → ℝ} {s : ℝ} (hS : ExponentialConvergence ρ S s) (hs : 0 < s) : + ExponentiallyRare ρ (fun n => {h | S n h ≤ 0}) := by + apply (hS s hs).mono + refine Filter.Eventually.of_forall ?_ + intro n h hh + change S n h ≤ 0 at hh + change s ≤ dist (S n h) s + rw [Real.dist_eq, abs_of_nonpos (by linarith)] + linarith + +lemma empirical_normalized_square {n : ℕ} (hn : 0 < n) (v : Fin n → ℝ) + (hv : 0 < (∑ i, (v i)^2)/(n:ℝ)) : + (∑ i, (v i/Real.sqrt ((∑ j, (v j)^2)/(n:ℝ)))^2)/(n:ℝ) = 1 := by + simp only [div_pow] + rw [← Finset.sum_div, Real.sq_sqrt hv.le] + have hn' : (n:ℝ) ≠ 0 := Nat.cast_ne_zero.mpr (Nat.ne_of_gt hn) + have hv' : (∑ i, (v i)^2) ≠ 0 := by + intro hz + rw [hz, zero_div] at hv + exact (lt_irrefl 0) hv + field_simp + +noncomputable def empiricalProjection {n : ℕ} {E ι : Type*} [Fintype ι] [DecidableEq ι] + (x : Fin n → E) (f : ι → E → ℝ) (g : E → ℝ) : ι → ℝ := + (show Matrix ι ι ℝ from fun i j => (∑ a, f i (x a)*f j (x a))/(n:ℝ))⁻¹ *ᵥ + (fun i => (∑ a, f i (x a)*g (x a))/(n:ℝ)) + +noncomputable def limitingProjection {E ι : Type*} [MeasurableSpace E] [Fintype ι] [DecidableEq ι] + (ν : Measure E) (f : ι → E → ℝ) (g : E → ℝ) : ι → ℝ := + (show Matrix ι ι ℝ from fun i j => ∫ x, f i x*f j x ∂ν)⁻¹ *ᵥ + (fun i => ∫ x, f i x*g x ∂ν) + +lemma empirical_residual_orthogonal {n : ℕ} {E ι : Type*} [Fintype ι] [DecidableEq ι] + (x : Fin n → E) (f : ι → E → ℝ) (g : E → ℝ) + (hdet : Matrix.det (fun i j => (∑ a, f i (x a)*f j (x a))/(n:ℝ)) ≠ 0) (i : ι) : + (∑ a, f i (x a)*residualRecipe f g (empiricalProjection x f g) (x a))/(n:ℝ) = 0 := by + let A : Matrix ι ι ℝ := fun i j => (∑ a, f i (x a)*f j (x a))/(n:ℝ) + let b : ι → ℝ := fun i => (∑ a, f i (x a)*g (x a))/(n:ℝ) + have he : A *ᵥ (A⁻¹ *ᵥ b) = b := by + rw [Matrix.mulVec_mulVec, Matrix.mul_nonsing_inv _ (isUnit_iff_ne_zero.mpr hdet), + Matrix.one_mulVec] + have hi := congrFun he i + change (∑ j, A i j*(empiricalProjection x f g) j) = b i at hi + have hexp : (∑ a, f i (x a)*residualRecipe f g (empiricalProjection x f g) (x a))/(n:ℝ) = + b i - ∑ j, A i j*(empiricalProjection x f g) j := by + simp only [residualRecipe, mul_sub, Finset.sum_sub_distrib, sub_div, A, b] + congr 1 + simp_rw [Finset.mul_sum] + rw [Finset.sum_comm, Finset.sum_div] + apply Finset.sum_congr rfl + intro j _ + rw [div_mul_eq_mul_div, Finset.sum_mul] + congr 1 + apply Finset.sum_congr rfl + intro a _ + ring + rw [hexp, hi, sub_self] + +lemma ExponentialConvergence.nonzero_rare + {H : ℕ → Type*} [∀ n, MeasurableSpace (H n)] {ρ : ∀ n, Measure (H n)} + {S : ∀ n, H n → ℝ} {s : ℝ} (hS : ExponentialConvergence ρ S s) (hs : s ≠ 0) : + ExponentiallyRare ρ (fun n => {h | S n h = 0}) := by + apply (hS |s| (abs_pos.mpr hs)).mono + refine Filter.Eventually.of_forall ?_ + intro n h hh + change S n h = 0 at hh + change |s| ≤ dist (S n h) s + simp [hh, Real.dist_eq] + +lemma ExponentialEmpiricalConcentration.singular_gram_rare + {E : Type*} [PseudoMetricSpace E] [MeasurableSpace E] + {H : ℕ → Type*} [∀ n, MeasurableSpace (H n)] + {ρ : ∀ n, Measure (H n)} {X : ∀ n, H n → Fin n → E} {ν : Measure E} + (hX : ExponentialEmpiricalConcentration ρ X ν) + {ι : Type*} [Fintype ι] [DecidableEq ι] (f : ι → E → ℝ) {K B : ℝ≥0} + (hf : ∀ i, LipschitzWith K (f i)) (hB : ∀ i x, |f i x| ≤ B) + (hdet : Matrix.det (fun i j => ∫ x, f i x*f j x ∂ν) ≠ 0) : + ExponentiallyRare ρ (fun n => {h | + Matrix.det (fun i j => (∑ a, f i (X n h a)*f j (X n h a))/(n:ℝ)) = 0}) := by + apply ExponentialConvergence.nonzero_rare _ hdet + exact (hX.gram f hf hB).continuous_map (f := fun a : ι → ι → ℝ => Matrix.det a) + continuous_id.matrix_det.continuousAt + +theorem ExponentialEmpiricalConcentration.gram_residual + {E : Type*} [PseudoMetricSpace E] [MeasurableSpace E] [BorelSpace E] + {H : ℕ → Type*} [∀ n, MeasurableSpace (H n)] + {ρ : ∀ n, Measure (H n)} {X : ∀ n, H n → Fin n → E} {ν : Measure E} + [IsProbabilityMeasure ν] (hX : ExponentialEmpiricalConcentration ρ X ν) + {ι : Type*} [Fintype ι] [DecidableEq ι] (f : ι → E → ℝ) (g : E → ℝ) {K B : ℝ≥0} + (hf : ∀ i, LipschitzWith K (f i)) (hg : LipschitzWith K g) + (hB : ∀ i x, |f i x| ≤ B) (hBg : ∀ x, |g x| ≤ B) + (hdet : Matrix.det (fun i j => ∫ x, f i x*f j x ∂ν) ≠ 0) : + ExponentialEmpiricalConcentration ρ + (fun n h a => residualRecipe f g (empiricalProjection (X n h) f g) (X n h a)) + (ν.map (residualRecipe f g (limitingProjection ν f g))) ∧ + ExponentialConvergence ρ + (fun n h => (∑ a, (residualRecipe f g (empiricalProjection (X n h) f g) (X n h a))^2)/(n:ℝ)) + (∫ x, (residualRecipe f g (limitingProjection ν f g) x)^2 ∂ν) := by + have hc : ExponentialConvergence ρ (fun n h => empiricalProjection (X n h) f g) + (limitingProjection ν f g) := hX.projection_coefficients f g hf hg hB hBg hdet + exact ⟨hX.residual f g hf hg hB hBg _ _ hc, hX.residual_energy f g hf hg hB hBg _ _ hc⟩ + +end SKGapCutoff.Regression + +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Topology + +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/ResidualRecipe2.lean b/lean/OAI/Probability/SKGap/Localization/ResidualRecipe2.lean new file mode 100644 index 0000000000000000000000000000000000000000..93f95415574e3816d9ff021bd3b3c5e83720c727 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/ResidualRecipe2.lean @@ -0,0 +1,257 @@ +import Mathlib +import OAI.Probability.SKGap.Stability.OrdinaryRecipe +import OAI.Probability.SKGap.Localization.PhiRegularity +import OAI.Probability.SKGap.Localization.ResidualInduction + +namespace OAI + +section + +noncomputable section +open scoped BigOperators +namespace SKGapCutoff.Recipe +open Primary +variable {n : ℕ} {ι κ σ : Type*} [Fintype ι] [DecidableEq ι] [Fintype κ] [DecidableEq κ] [Fintype σ] +namespace OrdinaryData + +lemma evaluation_prefix_eq (D E : OrdinaryData n ι κ σ) (N : ℕ) + (hJ : E.J=D.J) (hj : E.j=D.j) (hp : E.predecessor=D.predecessor) (hs : E.seed=D.seed) + (hseed : ∀a≤N,∀s,E.seedCoefficient a s=D.seedCoefficient a s) + (haux : ∀a≤N,∀b,E.auxCoefficient a b=D.auxCoefficient a b) + (hseedp : ∀a≤N,∀l s,E.seedPartial a l s=D.seedPartial a l s) + (hauxp : ∀a≤N,∀l b,E.auxPartial a l b=D.auxPartial a l b) : + ∀a≤N,E.source a=D.source a ∧ E.auxiliary a=D.auxiliary a := by + intro a + induction a using Nat.strong_induction_on with + | h a ih => + intro ha + have hy : ∀ b:Fin a, E.auxiliary b=D.auxiliary b := by + intro b; exact (ih b b.isLt (b.isLt.le.trans ha)).2 + have hw : ∀ b:Fin a, E.source b=D.source b := by + intro b; exact (ih b b.isLt (b.isLt.le.trans ha)).1 + have hsrc : E.sourceOf a (fun b=>E.auxiliary b)=D.sourceOf a (fun b=>D.auxiliary b) := by + funext x i + unfold sourceOf + simp only [hseed a ha,haux a ha,hs,hy] + have hpart : ∀l,E.partialOf a l (fun b=>E.auxiliary b)=D.partialOf a l (fun b=>D.auxiliary b) := by + intro l + funext x i + unfold partialOf + simp only [hseedp a ha,hauxp a ha,hs,hy] + constructor + · simpa only [source_eq] using hsrc + · rw [auxiliary_eq,auxiliary_eq] + funext x i + simp only [fieldOf,hJ,hj,hp,hsrc,hpart,hw,haux a ha] + +def appendProduct (D : OrdinaryData n ι κ σ) (N : ℕ) + (F : Fin n→Args (ι:=ι) (κ:=κ)→ℝ) + (F' : Fin n→Args (ι:=ι) (κ:=κ)→Args (ι:=ι) (κ:=κ)→L[ℝ]ℝ) : OrdinaryData n ι κ σ := + { D with + seedFunction := fun a s i u=>if a=N+1 then F i u*D.seedFunction N s i u else D.seedFunction a s i u + seedDerivative := fun a s i u=>if a=N+1 then + F i u • D.seedDerivative N s i u+D.seedFunction N s i u • F' i u else D.seedDerivative a s i u + auxFunction := fun a b i u=>if a=N+1 then + if hb:b.valif a=N+1 then + if hb:b.valcoefficient D.H D.θ F x i*D.source N x i := by + have hprev:=D.appendProduct_prefix N F F' + ext x i + rw [source_eq] + dsimp only [sourceOf] + rw [Fin.sum_univ_castSucc] + simp only [auxCoefficient,seedCoefficient,coefficient,appendProduct,ite_true,Fin.val_castSucc, + Fin.val_last,Fin.isLt,dite_true,lt_self_iff_false,dite_false,zero_mul,add_zero] + have hy : ∀b:Fin N,(D.appendProduct N F F').auxiliary b=D.auxiliary b := + fun b=>(hprev b (by omega)).2 + dsimp only [appendProduct] at hy + simp only [hy,Fin.eta] + rw [D.source_eq] + simp only [sourceOf,seedCoefficient,coefficient,auxCoefficient,mul_add,Finset.mul_sum,mul_assoc] + +lemma appendProduct_partial (D : OrdinaryData n ι κ σ) (N : ℕ) (F F') (l : ι) : + (D.appendProduct N F F').sourcePartial (N+1) l= + fun x i=>coefficient D.H D.θ F x i*D.sourcePartial N l x i+ + localPartial D.H D.θ F' (.inl l) x i*D.source N x i := by + have hprev:=D.appendProduct_prefix N F F' + ext x i + dsimp only [sourcePartial,partialOf] + rw [Fin.sum_univ_castSucc] + simp only [auxPartial,seedPartial,localPartial,appendProduct,ite_true,Fin.val_castSucc, + Fin.val_last,Fin.isLt,dite_true,lt_self_iff_false,dite_false] + have hy : ∀b:Fin N,(D.appendProduct N F F').auxiliary b=D.auxiliary b := + fun b=>(hprev b (by omega)).2 + dsimp only [appendProduct] at hy + simp only [hy,Fin.eta] + rw [D.source_eq] + simp only [sourceOf,seedCoefficient,coefficient,auxCoefficient,partialAt,add_apply, + smul_apply,smul_eq_mul,add_mul,mul_add,Finset.sum_add_distrib,Finset.mul_sum, + zero_apply,zero_mul,add_zero,mul_assoc] + simp only [mul_assoc,mul_comm,mul_left_comm] + ring + +lemma appendProduct_new_partial (D : OrdinaryData n ι κ σ) (N : ℕ) (F F') (l : ι) + (hzero : D.sourcePartial N l=0) : + (D.appendProduct N F F').sourcePartial (N+1) l= + fun x i=>localPartial D.H D.θ F' (.inl l) x i*D.source N x i := by + rw [appendProduct_partial,hzero] + ext x i; simp + +end OrdinaryData +end SKGapCutoff.Recipe + +end +end + +section + +noncomputable section +open scoped BigOperators +namespace SKGapCutoff.Recipe +open SKGap.Stein Primary Matrix +variable {n : ℕ} {ι κ σ : Type*} [Fintype ι] [DecidableEq ι] [Fintype κ] [DecidableEq κ] [Fintype σ] + +def phiCoefficient (l m : ι) (α : κ) : Fin n→Args (ι:=ι) (κ:=κ)→ℝ := + fun _ u=>eval3 (KernelExpr.atom 0 0 false).eval (phiPairSelect l m α u) +def phiDerivative (l m : ι) (α : κ) : Fin n→Args (ι:=ι) (κ:=κ)→Args (ι:=ι) (κ:=κ)→L[ℝ]ℝ := + fun _ u=>((KernelExpr.atom 0 0 false).gradient (phiPairSelect l m α u)).comp (phiPairSelect l m α) + +omit [Fintype ι] [DecidableEq ι] [Fintype κ] [DecidableEq κ] in +lemma phiCoefficient_eq (l m : ι) (α : κ) (i : Fin n) (u : Args (ι:=ι) (κ:=κ)) : + phiCoefficient l m α i u=phi (u (.inl l)) (u (.inl m)) (u (.inr α)) := by + simp [phiCoefficient,eval3,phiPairSelect,KernelExpr.eval,moment_base] + +lemma base_dz (z r a : ℝ) : (KernelExpr.atom 0 0 false).dz.eval z r a=phiZ z r a := by + have H:=(KernelExpr.atom 0 0 false).hasDerivAt_z z r a + simp only [KernelExpr.eval,moment_base] at H + exact H.unique (phi_hasDerivAt z r a) + +omit [Fintype ι] [Fintype κ] in +lemma phiDerivative_first (l m : ι) (α : κ) (hlm : l≠m) (i : Fin n) (u : Args (ι:=ι) (κ:=κ)) : + partialAt (phiDerivative l m α i u) (.inl l)=phiZ (u (.inl l)) (u (.inl m)) (u (.inr α)) := by + simp [partialAt,phiDerivative,phiPairSelect,KernelExpr.gradient,grad3,grad2, + ContinuousLinearMap.toSpanSingleton_apply,hlm.symm,eval3,base_dz] + +omit [Fintype ι] [Fintype κ] in +lemma phiDerivative_other (l m q : ι) (α : κ) (hql : q≠l) (hqm : q≠m) + (i : Fin n) (u : Args (ι:=ι) (κ:=κ)) : + partialAt (phiDerivative l m α i u) (.inl q)=0 := by + simp [partialAt,phiDerivative,phiPairSelect,KernelExpr.gradient,grad3,grad2, + ContinuousLinearMap.toSpanSingleton_apply,hql.symm,hqm.symm] + +namespace OrdinaryData + +def appendStein (D : OrdinaryData n ι κ σ) (N : ℕ) (l m : ι) (α : κ) : OrdinaryData n ι κ σ := + D.appendProduct N (phiCoefficient l m α) (phiDerivative l m α) + +lemma appendStein_source (D : OrdinaryData n ι κ σ) (N : ℕ) (l m : ι) (α : κ) + (j : ℝ) (J : Interaction n) (h : Fin n→ℝ) (k : ℕ) + (hl : D.H l=fld j J h k) (hm : D.H m=fld j J h (k+1)) + (ha : D.θ α=fun x=>j*(onsager j J h (k+1) x-onsager j J h k x)) : + (D.appendStein N l m α).source (N+1)=steinSource j J h k (D.source N) := by + rw [appendStein,appendProduct_source] + ext x i + simp [coefficient,phiCoefficient_eq,localArgs,hl,hm,ha,steinSource] + +lemma appendStein_partial (D : OrdinaryData n ι κ σ) (N : ℕ) (l m : ι) (α : κ) + (hlm : l≠m) (j : ℝ) (J : Interaction n) (h : Fin n→ℝ) (k : ℕ) + (hl : D.H l=fld j J h k) (hm : D.H m=fld j J h (k+1)) + (ha : D.θ α=fun x=>j*(onsager j J h (k+1) x-onsager j J h k x)) + (hzero : D.sourcePartial N l=0) : + (D.appendStein N l m α).sourcePartial (N+1) l=steinPartial j J h k (D.source N) := by + rw [appendStein,appendProduct_new_partial _ _ _ _ _ hzero] + ext x i + simp [localPartial,phiDerivative_first l m α hlm,localArgs,hl,hm,ha,steinPartial] + +lemma appendStein_preserves_vanishing (D : OrdinaryData n ι κ σ) (N : ℕ) (l m q : ι) (α : κ) + (hql : q≠l) (hqm : q≠m) (hzero : D.sourcePartial N q=0) : + (D.appendStein N l m α).sourcePartial (N+1) q=0 := by + rw [appendStein,appendProduct_new_partial _ _ _ _ _ hzero] + ext x i + simp only [localPartial,phiDerivative_other l m q α hql hqm,zero_mul,Pi.zero_apply] + +lemma sum_split (f : ι→ℝ) (l : ι) : (∑q,f q)=f l+∑q:{q:ι//q≠l},f q := by + rw [←Finset.sum_erase_add _ _ (Finset.mem_univ l),add_comm] + congr 1 + exact Finset.sum_subtype (Finset.univ.erase l) (fun q=>show q∈Finset.univ.erase l ↔ q≠l by simp) f + +lemma auxiliary_split (D : OrdinaryData n ι κ σ) (a : ℕ) (l : ι) (x : Spin n) (i : Fin n) : + D.auxiliary a x i=(∑b,D.J i b*D.source a x b)- + D.j*siteMean (D.sourcePartial a l) x*D.predecessor l x i- + D.j*(∑q:{q:ι//q≠l},siteMean (D.sourcePartial a q) x*D.predecessor q x i)- + D.j*∑b:Fin a,siteMean (D.auxCoefficient a b) x*D.source b x i := by + rw [auxiliary_eq] + simp only [fieldOf,←D.source_eq,sourcePartial,Matrix.mulVec,dotProduct] + rw [sum_split _ l] + ring + +lemma appendStein_auxiliary (D : OrdinaryData n ι κ σ) (N : ℕ) (l m : ι) (α : κ) + (hlm : l≠m) (j : ℝ) (J : Interaction n) (h : Fin n→ℝ) (k : ℕ) + (L : ι→ℕ) (hj : D.j=j) (hJ : D.J=J) + (hp : ∀q,D.predecessor q=mag j J h (L q)) (hL : L l=k) + (hl : D.H l=fld j J h k) (hm : D.H m=fld j J h (k+1)) + (ha : D.θ α=fun x=>j*(onsager j J h (k+1) x-onsager j J h k x)) + (hzero : D.sourcePartial N l=0) : + let E:=D.appendStein N l m α + E.auxiliary (N+1)=nextField j J h k (D.source N) + (fun q:{q:ι//q≠l}=>L q) (fun q=>siteMean (E.sourcePartial (N+1) q)) + (fun b:Fin (N+1)=>E.source b) (fun b=>siteMean (E.auxCoefficient (N+1) b)) := by + dsimp only + funext x i + rw [auxiliary_split _ _ l,appendStein_source D N l m α j J h k hl hm ha, + appendStein_partial D N l m α hlm j J h k hl hm ha hzero] + simp only [appendStein,appendProduct,hJ,hj,hp,hL,nextField] + +theorem residual_step (D : OrdinaryData n ι κ σ) (N : ℕ) (l m : ι) (α : κ) + (hlm : l≠m) (hn : 0j*(onsager j J h (k+1) x-onsager j J h k x)) + (hzero : D.sourcePartial N l=0) (x : Spin n) : + let E:=D.appendStein N l m α + (∑i,residual j J h (k+1) x i*D.source N x i)= + (∑i,residual j J h k x i*E.auxiliary (N+1) x i)+ + j*(onsager j J h (k+1) x-onsager j J h k x)*(∑i,residual j J h k x i*E.source (N+1) x i)- + j*onsager j J h k x*(∑i,previousResidual j J h k x i*E.source (N+1) x i)+ + j*(∑b:Fin (N+1),siteMean (E.auxCoefficient (N+1) b) x*∑i,residual j J h k x i*E.source b x i)+ + j*(∑q:{q:ι//q≠l},siteMean (E.sourcePartial (N+1) q) x*∑i,residual j J h k x i*mag j J h (L q) x i)- + j*siteMean (E.sourcePartial (N+1) l) x*(∑i,residual j J h k x i*mag j J h (k+1) x i) := by + dsimp only + rw [appendStein_auxiliary D N l m α hlm j J h k L hj hJ hp hL hl hm ha hzero, + appendStein_source D N l m α j J h k hl hm ha, + appendStein_partial D N l m α hlm j J h k hl hm ha hzero] + exact residual_induction_identity hn j J hJs h k (D.source N) + (fun q:{q:ι//q≠l}=>L q) + (fun q=>siteMean ((D.appendStein N l m α).sourcePartial (N+1) q)) + (fun b:Fin (N+1)=>(D.appendStein N l m α).source b) + (fun b=>siteMean ((D.appendStein N l m α).auxCoefficient (N+1) b)) x + +end OrdinaryData +end SKGapCutoff.Recipe + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/ResidualSelection.lean b/lean/OAI/Probability/SKGap/Localization/ResidualSelection.lean new file mode 100644 index 0000000000000000000000000000000000000000..8eba4615025257388c2aa8a32e8d6792360b186f --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/ResidualSelection.lean @@ -0,0 +1,108 @@ +import Mathlib +import OAI.Probability.SKGap.Terminal.ResidualPairMoments + +namespace OAI + +section + +noncomputable section +open scoped BigOperators +namespace SKGapCutoff.Recipe +open Primary Static +variable {n : ℕ} + +def residualEnergy (j : ℝ) (J : Interaction n) (h : Fin n→ℝ) (k : ℕ) (x : Spin n) : ℝ := + (vectorNorm (residual j J h k x))^2/(n:ℝ) + +lemma residualEnergy_nonneg (j : ℝ) (J : Interaction n) (h : Fin n→ℝ) (k : ℕ) (x : Spin n) : + 0≤residualEnergy j J h k x := div_nonneg (sq_nonneg _) (Nat.cast_nonneg n) + +lemma residualEnergy_eq (_ : 0simp [onsager_zero] + | succ d ih=> + rw [Finset.sum_range_succ,Finset.sum_range_succ,ih,residualEnergy_eq hn] + ring + +lemma residualEnergy_sum_le (hn : 0by + have H:=hs k (Finset.mem_range.mp hk) + have H' : |primaryPair j J h k x/Real.sqrt (n:ℝ)|≤ε := by + simpa only [abs_div,abs_of_nonneg (Real.sqrt_nonneg _)] using H + exact (abs_le.mp H').1) + nlinarith + +lemma sum_range_pairs (E : ℕ→ℝ) (m : ℕ) : + (∑k∈Finset.range (2*m),E k)=∑k∈Finset.range m,(E (2*k)+E (2*k+1)) := by + induction m with + | zero=>simp + | succ m ih=> + rw [show 2*(m+1)=2*m+1+1 by omega,Finset.sum_range_succ,Finset.sum_range_succ,ih, + Finset.sum_range_succ] + ring + +lemma disjoint_small_pair (E : ℕ→ℝ) (hE : ∀k,0≤E k) (m : ℕ) {a K : ℝ} + (_ : 0≤a) (hm : K<(m:ℝ)*a) (he : (∑k∈Finset.range (2*m),E k)≤K) : + ∃ k < m,E (2*k)≤a ∧ E (2*k+1)≤a := by + by_contra hh + have hb : ∀ k < m,ahh ⟨k,hk,ht⟩ + by_cases h : E (2*k)≤a + · have ht : aH ⟨h,ht⟩) + linarith [hE (2*k)] + · have ht:=lt_of_not_ge h + linarith [hE (2*k+1)] + have H : (m:ℝ)*a≤∑k∈Finset.range (2*m),E k := by + rw [sum_range_pairs] + calc + _ = ∑_k∈Finset.range m,a := by simp + _ ≤ _ := Finset.sum_le_sum (fun k hk=>(hb k (Finset.mem_range.mp hk)).le) + linarith + +lemma small_residual_pair (hn : 0residualEnergy j J h k x) + (fun k=>residualEnergy_nonneg j J h k x) m (a:=ρ^2/4) (K:=2) (by positivity) + (by nlinarith) ((residualEnergy_sum_le hn j J h (2*m) x hs).trans (by linarith)) + have hnorm (k : ℕ) (hk : residualEnergy j J h k x≤ρ^2/4) : + vectorNorm (residual j J h k x)≤ρ*Real.sqrt (n:ℝ)/2 := by + apply nonneg_le_nonneg_of_sq_le_sq (by positivity) + simp only [←sq,div_pow,mul_pow,Real.sq_sqrt (Nat.cast_nonneg n)] + have hnR : (0:ℝ) X ω + c) μ := by + have := hX.isGaussian_map + refine ⟨by fun_prop, ?_⟩ + change IsGaussian (μ.map ((fun x : ι → ℝ => x+c) ∘ X)) + rw [← AEMeasurable.map_map_of_aemeasurable + (by fun_prop : AEMeasurable (fun x : ι → ℝ => x+c) (μ.map X)) hX.aemeasurable] + infer_instance + +lemma piGaussian_coordinates {ι : Type*} [Fintype ι] (m : ι → ℝ) (v : ℝ≥0) : + HasGaussianLaw (fun g : ι → ℝ => g) (Measure.pi (fun i => gaussianReal (m i) v)) := + (iIndepFun_pi (fun _ => measurable_id.aemeasurable)).hasGaussianLaw + (fun i => (measurePreserving_eval (fun j => gaussianReal (m j) v) i).hasLaw.hasGaussianLaw) + +lemma piGaussian_coordinate_mean {ι : Type*} [Fintype ι] (m : ι → ℝ) (v : ℝ≥0) (i : ι) : + (∫ g : ι → ℝ, g i ∂Measure.pi (fun j => gaussianReal (m j) v)) = m i := by + rw [(measurePreserving_eval (fun j => gaussianReal (m j) v) i).hasLaw.integral_eq] + exact integral_id_gaussianReal + +lemma piGaussian_coordinate_covariance {ι : Type*} [Fintype ι] [DecidableEq ι] + (m : ι → ℝ) (v : ℝ≥0) (i j : ι) : + cov[fun g : ι → ℝ => g i, fun g => g j; Measure.pi (fun k => gaussianReal (m k) v)] = + if i = j then (v:ℝ) else 0 := by + by_cases h : i=j + · subst j + rw [covariance_self (measurePreserving_eval (fun k => gaussianReal (m k) v) i).aemeasurable, + (measurePreserving_eval (fun k => gaussianReal (m k) v) i).hasLaw.variance_eq, + variance_id_gaussianReal] + simp + · rw [ite_eq_right h] + exact ((iIndepFun_pi (fun _ => measurable_id.aemeasurable)).indepFun h).covariance_eq_zero + (((piGaussian_coordinates m v).eval i).memLp_two) + (((piGaussian_coordinates m v).eval j).memLp_two) + +lemma upperCoefficient_min_max {n : ℕ} (x : Spin n) (i j : Fin n) (hij : i ≠ j) : + upperCoefficient x (min i j,max i j) = spin x i * spin x j := by + rcases lt_or_gt_of_ne hij with h|h + · simp [upperCoefficient, min_eq_left h.le, max_eq_right h.le, h] + · simp [upperCoefficient, min_eq_right h.le, max_eq_left h.le, h, mul_comm] + +lemma minmax_pair_eq_iff {n : ℕ} (i j k l : Fin n) : + (min i j,max i j) = (min k l,max k l) ↔ (i=k ∧ j=l) ∨ (i=l ∧ j=k) := by + simp only [Prod.mk.injEq, min_def, max_def] + split_ifs <;> omega + +noncomputable def sampledFlatCLM (n : ℕ) : GaussianCoordinates n →L[ℝ] GaussianCoordinates n := + ContinuousLinearMap.pi fun p => if p.1 = p.2 then 0 else + ContinuousLinearMap.proj (min p.1 p.2,max p.1 p.2) + +@[simp] lemma sampledFlatCLM_apply {n : ℕ} (g : GaussianCoordinates n) (p : Fin n × Fin n) : + sampledFlatCLM n g p = sampledInteraction g p.1 p.2 := by + classical + by_cases h : p.1=p.2 <;> simp [sampledFlatCLM, sampledInteraction, h] + +noncomputable def plantedGOEArray {n : ℕ} (β : ℝ) (x : Spin n) (g : GaussianCoordinates n) : + GaussianCoordinates n := fun p => if p.1=p.2 then 0 else + β * goe g p.1 p.2 + β^2/(n:ℝ) * spin x p.1 * spin x p.2 + +noncomputable def offDiagonalGOECLM (n : ℕ) : GaussianCoordinates n →L[ℝ] GaussianCoordinates n := + ContinuousLinearMap.pi fun p => if p.1=p.2 then 0 else + (Real.sqrt (2*n))⁻¹ • ((ContinuousLinearMap.proj p : GaussianCoordinates n →L[ℝ] ℝ) + ContinuousLinearMap.proj (p.2,p.1)) + +lemma plantedGOEArray_gaussian {n : ℕ} (β : ℝ) (x : Spin n) : + HasGaussianLaw (plantedGOEArray β x) (standardArrayLaw (Fin n × Fin n)) := by + have hh := gaussian_add_constant + (coordinates_gaussian.map_fun (β • offDiagonalGOECLM n)) + (fun p : Fin n × Fin n => if p.1=p.2 then 0 else β^2/(n:ℝ)*spin x p.1*spin x p.2) + apply hh.congr + exact Eventually.of_forall (fun g => by + ext p + by_cases h : p.1=p.2 + · simp [offDiagonalGOECLM, plantedGOEArray, h] + · simp only [offDiagonalGOECLM, plantedGOEArray, goe, h, ite_false, + smul_apply, ContinuousLinearMap.pi_apply, + add_apply, ContinuousLinearMap.proj_apply, Pi.smul_apply, + Pi.add_apply, smul_eq_mul] + ring) + +lemma sampled_planted_gaussian (β : ℝ) {n : ℕ} (hn : 0 < n) (x : Spin n) : + HasGaussianLaw (fun g : GaussianCoordinates n => fun p : Fin n × Fin n => + sampledInteraction g p.1 p.2) (singleSpinPlantedLaw β x) := by + rw [singleSpinPlantedLaw_eq_gaussianPi β hn] + have hh := (piGaussian_coordinates (fun p => β^2/(n:ℝ)*upperCoefficient x p) + (Real.toNNReal (β^2/(n:ℝ)))).map_fun (sampledFlatCLM n) + exact hh.congr (Eventually.of_forall fun g => funext fun p => sampledFlatCLM_apply g p) + +lemma plantedGOEArray_mean {n : ℕ} (β : ℝ) (x : Spin n) (p : Fin n × Fin n) : + (∫ g, plantedGOEArray β x g p ∂standardArrayLaw (Fin n × Fin n)) = + if p.1=p.2 then 0 else β^2/(n:ℝ)*spin x p.1*spin x p.2 := by + by_cases h : p.1=p.2 + · simp [plantedGOEArray, h] + · simp only [plantedGOEArray, h, ite_false] + rw [integral_add (((goe_gaussian n).eval p.1 |>.eval p.2).integrable.const_mul β) + (integrable_const _), integral_const_mul, goe_entry_mean] + simp + +lemma sampled_planted_mean (β : ℝ) {n : ℕ} (hn : 0 < n) (x : Spin n) (p : Fin n × Fin n) : + (∫ g, sampledInteraction g p.1 p.2 ∂singleSpinPlantedLaw β x) = + if p.1=p.2 then 0 else β^2/(n:ℝ)*spin x p.1*spin x p.2 := by + rw [singleSpinPlantedLaw_eq_gaussianPi β hn] + by_cases h : p.1=p.2 + · simp [sampledInteraction, h] + · simp only [sampledInteraction, h, ite_false] + rw [piGaussian_coordinate_mean, upperCoefficient_min_max x _ _ h] + ring + +lemma plantedGOEArray_covariance {n : ℕ} (hn : 0 < n) (β : ℝ) (x : Spin n) + (p q : Fin n × Fin n) : + cov[fun g => plantedGOEArray β x g p, fun g => plantedGOEArray β x g q; + standardArrayLaw (Fin n × Fin n)] = + if p.1=p.2 ∨ q.1=q.2 then 0 else + (β^2/(n:ℝ)) * ((if p.1=q.1 ∧ p.2=q.2 then 1 else 0) + + (if p.1=q.2 ∧ p.2=q.1 then 1 else 0)) := by + by_cases hp : p.1=p.2 + · simp [plantedGOEArray, hp] + by_cases hq : q.1=q.2 + · simp [plantedGOEArray, hq] + simp only [plantedGOEArray, hp, hq, false_or, ite_false] + rw [covariance_add_const_left (((goe_gaussian n).eval p.1 |>.eval p.2).integrable.const_mul β), + covariance_add_const_right (((goe_gaussian n).eval q.1 |>.eval q.2).integrable.const_mul β), + covariance_const_mul_left, covariance_const_mul_right, goe_entry_covariance hn] + ring + +lemma sampled_planted_covariance (β : ℝ) {n : ℕ} (hn : 0 < n) (x : Spin n) + (p q : Fin n × Fin n) : + cov[fun g => sampledInteraction g p.1 p.2, fun g => sampledInteraction g q.1 q.2; + singleSpinPlantedLaw β x] = + if p.1=p.2 ∨ q.1=q.2 then 0 else + (β^2/(n:ℝ)) * ((if p.1=q.1 ∧ p.2=q.2 then 1 else 0) + + (if p.1=q.2 ∧ p.2=q.1 then 1 else 0)) := by + rw [singleSpinPlantedLaw_eq_gaussianPi β hn] + by_cases hp : p.1=p.2 + · simp [sampledInteraction, hp] + by_cases hq : q.1=q.2 + · simp [sampledInteraction, hq] + simp only [sampledInteraction, hp, hq, false_or, ite_false] + rw [piGaussian_coordinate_covariance, Real.coe_toNNReal _ (by positivity)] + simp only [minmax_pair_eq_iff] + by_cases h1 : p.1=q.1 ∧ p.2=q.2 + · have h2 : ¬ (p.1=q.2 ∧ p.2=q.1) := by omega + rw [ite_eq_left (Or.inl h1), ite_eq_left h1, ite_eq_right h2, add_zero, mul_one] + by_cases h2 : p.1=q.2 ∧ p.2=q.1 + · rw [ite_eq_left (Or.inr h2), ite_eq_right h1, ite_eq_left h2, zero_add, mul_one] + · rw [ite_eq_right (not_or.mpr ⟨h1,h2⟩), ite_eq_right h1, ite_eq_right h2, + add_zero, mul_zero] + +lemma planted_matrix_representation (β : ℝ) {n : ℕ} (hn : 0 < n) (x : Spin n) : + (singleSpinPlantedLaw β x).map (fun g : GaussianCoordinates n => + fun p : Fin n × Fin n => sampledInteraction g p.1 p.2) = + (standardArrayLaw (Fin n × Fin n)).map (plantedGOEArray β x) := by + apply gaussian_vector_law_ext (sampled_planted_gaussian β hn x) (plantedGOEArray_gaussian β x) + · intro p + rw [sampled_planted_mean β hn, plantedGOEArray_mean] + · intro p q + rw [sampled_planted_covariance β hn, plantedGOEArray_covariance hn] + +end SKGapCutoff.Regression + +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators ENNReal NNReal + +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/SandShift.lean b/lean/OAI/Probability/SKGap/Localization/SandShift.lean new file mode 100644 index 0000000000000000000000000000000000000000..29af3a61aae51936ccdc28aaf450d60c7329475a --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/SandShift.lean @@ -0,0 +1,201 @@ +import Mathlib +import OAI.Probability.SKGap.Matrix.OpNormKernelMatrixSub + +namespace OAI + +section +noncomputable section +open MeasureTheory ProbabilityTheory InformationTheory Real Set +open scoped NNReal ENNReal +open Filter +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius ENNReal NNReal +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius NNReal +noncomputable section +open MeasureTheory ProbabilityTheory Real Set Filter +open MeasureTheory.Measure +open scoped ENNReal NNReal MeasureTheory Topology +open MeasureTheory +noncomputable section +noncomputable section +open MeasureTheory Set NormedSpace +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius +namespace SKGap.ComplexMatrix +open scoped FourierTransform SchwartzMap +variable {ι : Type*} [Fintype ι] [DecidableEq ι] + +def sandShift (B D M : Matrix ι ι ℂ) : Matrix ι ι ℂ := B-D*M*D + +omit [DecidableEq ι] in +lemma sandShift_hermitian (B D M : Matrix ι ι ℂ) (hB : Bᴴ = B) (hD : Dᴴ = D) (hM : Mᴴ = M) : + (sandShift B D M)ᴴ = sandShift B D M := by + simp [sandShift,Matrix.conjTranspose_mul,hB,hD,hM,mul_assoc] + +lemma sandShift_sub (B D M N : Matrix ι ι ℂ) : + sandShift B D M-sandShift B D N = -(D*(M-N)*D) := by dsimp [sandShift]; noncomm_ring + +lemma sandShift_lipschitz (B D M N : Matrix ι ι ℂ) : + ‖sandShift B D M-sandShift B D N‖ ≤ opNorm D^2*‖M-N‖ := by + rw [sandShift_sub,norm_neg] + exact sandwich_frobenius _ _ + +lemma sandShift_parameter (B B' D D' M : Matrix ι ι ℂ) : + opNorm (sandShift B D M-sandShift B' D' M) ≤ + opNorm (B-B')+(opNorm D+opNorm D')*opNorm (D-D')*opNorm M := by + have he : sandShift B D M-sandShift B' D' M = (B-B')-(D*M*D-D'*M*D') := by dsimp [sandShift]; abel + rw [he] + calc + _ ≤ opNorm (B-B')+opNorm (D*M*D-D'*M*D') := opNorm_sub (B-B') (D*M*D-D'*M*D') + _ ≤ _ := by + have hh := sandwich_difference_opNorm D D' M + linarith only [hh] + +lemma sandShift_four_point (B B' D D' M N : Matrix ι ι ℂ) : + ‖(sandShift B D M-sandShift B D N)-(sandShift B' D' M-sandShift B' D' N)‖ ≤ + (opNorm D+opNorm D')*opNorm (D-D')*‖M-N‖ := by + rw [sandShift_sub,sandShift_sub,← norm_neg] + have he : -(-(D*(M-N)*D)- -(D'*(M-N)*D')) = D*(M-N)*D-D'*(M-N)*D' := by abel + rw [he] + exact sandwich_difference_frobenius _ _ _ + +lemma schwartzMatrix_sandShift_lipschitz (f : 𝓢(ℝ,ℂ)) (B D M N : Matrix ι ι ℂ) + (hB : Bᴴ = B) (hD : Dᴴ = D) (hM : Mᴴ = M) (hN : Nᴴ = N) : + ‖schwartzMatrix f (sandShift B D M)-schwartzMatrix f (sandShift B D N)‖ ≤ + (2*Real.pi*fourierMoment f 1)*opNorm D^2*‖M-N‖ := by + exact (schwartzMatrix_lipschitz f _ _ (sandShift_hermitian _ _ _ hB hD hM) + (sandShift_hermitian _ _ _ hB hD hN)).trans + ((mul_le_mul_of_nonneg_left (sandShift_lipschitz B D M N) + (by positivity [fourierMoment_nonneg f 1])).trans_eq (by ring)) + +lemma schwartzMatrix_sandShift_four_point (f : 𝓢(ℝ,ℂ)) (B B' D D' M N : Matrix ι ι ℂ) + (hB : Bᴴ = B) (hB' : B'ᴴ = B') (hD : Dᴴ = D) (hD' : D'ᴴ = D') + (hM : Mᴴ = M) (hN : Nᴴ = N) : + ‖(schwartzMatrix f (sandShift B D M)-schwartzMatrix f (sandShift B D N))- + (schwartzMatrix f (sandShift B' D' M)-schwartzMatrix f (sandShift B' D' N))‖ ≤ + ((2*Real.pi*fourierMoment f 1)*(opNorm D+opNorm D')*opNorm (D-D')+ + ((2*Real.pi)^2*fourierMoment f 2)* + (2*opNorm (B-B')+(opNorm D+opNorm D')*opNorm (D-D')*(opNorm M+opNorm N))*opNorm D'^2)*‖M-N‖ := by + have hL : 0 ≤ 2*Real.pi*fourierMoment f 1 := by have := fourierMoment_nonneg f 1; positivity + have hQ : 0 ≤ (2*Real.pi)^2*fourierMoment f 2 := by have := fourierMoment_nonneg f 2; positivity + have hP : 0 ≤ (opNorm D+opNorm D')*opNorm (D-D') := + mul_nonneg (add_nonneg (opNorm_nonneg _) (opNorm_nonneg _)) (opNorm_nonneg _) + have hp := add_le_add (sandShift_parameter B B' D D' M) (sandShift_parameter B B' D D' N) + have hp' : opNorm (sandShift B D M-sandShift B' D' M)+opNorm (sandShift B D N-sandShift B' D' N) ≤ + 2*opNorm (B-B')+(opNorm D+opNorm D')*opNorm (D-D')*(opNorm M+opNorm N) := by nlinarith only [hp] + have hx := schwartzMatrix_four_point f (sandShift B D M) (sandShift B D N) (sandShift B' D' M) (sandShift B' D' N) + (sandShift_hermitian _ _ _ hB hD hM) (sandShift_hermitian _ _ _ hB hD hN) + (sandShift_hermitian _ _ _ hB' hD' hM) (sandShift_hermitian _ _ _ hB' hD' hN) + apply hx.trans + calc + _ ≤ (2*Real.pi*fourierMoment f 1)*((opNorm D+opNorm D')*opNorm (D-D')*‖M-N‖)+ + ((2*Real.pi)^2*fourierMoment f 2)* + (2*opNorm (B-B')+(opNorm D+opNorm D')*opNorm (D-D')*(opNorm M+opNorm N))*(opNorm D'^2*‖M-N‖) := by + apply add_le_add + · exact mul_le_mul_of_nonneg_left (sandShift_four_point _ _ _ _ _ _) hL + · apply mul_le_mul (mul_le_mul_of_nonneg_left hp' hQ) (sandShift_lipschitz B' D' M N) (norm_nonneg _) + exact mul_nonneg hQ (add_nonneg (mul_nonneg (by norm_num) (opNorm_nonneg _)) + (mul_nonneg hP (add_nonneg (opNorm_nonneg _) (opNorm_nonneg _)))) + _ = _ := by ring + +end SKGap.ComplexMatrix + +noncomputable section +open Set Real +open scoped Topology +namespace SKGap +section Projection +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] + +structure ClosedConvexNonempty (K : Set E) : Prop where + nonempty : K.Nonempty + complete : IsComplete K + convex : Convex ℝ K + +noncomputable def convexProject {K : Set E} (hK : ClosedConvexNonempty K) (x : E) : E := + Classical.choose (exists_norm_eq_iInf_of_complete_convex hK.nonempty hK.complete hK.convex x) + +lemma convexProject_mem {K : Set E} (hK : ClosedConvexNonempty K) (x : E) : + convexProject hK x ∈ K := + (Classical.choose_spec (exists_norm_eq_iInf_of_complete_convex hK.nonempty hK.complete hK.convex x)).1 + +lemma convexProject_minimal {K : Set E} (hK : ClosedConvexNonempty K) (x : E) : + ‖x-convexProject hK x‖ = ⨅ y : K, ‖x-y‖ := + (Classical.choose_spec (exists_norm_eq_iInf_of_complete_convex hK.nonempty hK.complete hK.convex x)).2 + +lemma convexProject_inner {K : Set E} (hK : ClosedConvexNonempty K) (x : E) + {y : E} (hy : y ∈ K) : + inner ℝ (x-convexProject hK x) (y-convexProject hK x) ≤ 0 := by + exact ((norm_eq_iInf_iff_real_inner_le_zero hK.convex (convexProject_mem hK x)).mp + (convexProject_minimal hK x)) y hy + +lemma convexProject_lipschitz {K : Set E} (hK : ClosedConvexNonempty K) : + LipschitzWith 1 (convexProject hK) := by + apply LipschitzWith.of_dist_le_mul + intro x y + simp only [NNReal.coe_one,one_mul,dist_eq_norm] + let p := convexProject hK x + let q := convexProject hK y + have hx := convexProject_inner hK x (convexProject_mem hK y) + have hy := convexProject_inner hK y (convexProject_mem hK x) + change inner ℝ (x-p) (q-p) ≤ 0 at hx + change inner ℝ (y-q) (p-q) ≤ 0 at hy + have hi : ‖p-q‖^2 ≤ inner ℝ (p-q) (x-y) := by + rw [← real_inner_self_eq_norm_sq] + simp only [inner_sub_left,inner_sub_right,real_inner_comm] at * + nlinarith + have hb := real_inner_le_norm (p-q) (x-y) + nlinarith [norm_nonneg (p-q),norm_nonneg (x-y)] + +lemma convexProject_eq_self {K : Set E} (hK : ClosedConvexNonempty K) {x : E} + (hx : x ∈ K) : convexProject hK x = x := by + have hh := convexProject_inner hK x hx + rw [real_inner_self_eq_norm_sq] at hh + have hz : ‖x-convexProject hK x‖ = 0 := by nlinarith [norm_nonneg (x-convexProject hK x)] + exact (sub_eq_zero.mp (norm_eq_zero.mp hz)).symm + +lemma convexProject_unique {K : Set E} (hK : ClosedConvexNonempty K) {x p : E} + (hp : p ∈ K) (hmin : ∀ y ∈ K, inner ℝ (x-p) (y-p) ≤ 0) : + p = convexProject hK x := by + let q := convexProject hK x + have h₁ := hmin q (convexProject_mem hK x) + have h₂ := convexProject_inner hK x hp + change inner ℝ (x-q) (p-q) ≤ 0 at h₂ + have hh : ‖p-q‖^2 ≤ 0 := by + rw [← real_inner_self_eq_norm_sq] + simp only [inner_sub_right,inner_sub_left,real_inner_comm] at * + nlinarith + have hz : ‖p-q‖ = 0 := by nlinarith [norm_nonneg (p-q)] + exact sub_eq_zero.mp (norm_eq_zero.mp hz) + +lemma convexProject_equivariant {K : Set E} (hK : ClosedConvexNonempty K) + (U : E ≃ₗᵢ[ℝ] E) (hU : ∀ x, U x ∈ K ↔ x ∈ K) (x : E) : + convexProject hK (U x) = U (convexProject hK x) := by + apply Eq.symm + apply convexProject_unique hK ((hU _).mpr (convexProject_mem hK x)) + intro y hy + have hy' : U.symm y ∈ K := (hU _).mp (by simpa using hy) + have hh := convexProject_inner hK x hy' + rw [← U.inner_map_map] at hh + simpa only [map_sub,LinearIsometryEquiv.apply_symm_apply] using hh + +end Projection +end SKGap + +end +end +end +end +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/SandShiftSpecial.lean b/lean/OAI/Probability/SKGap/Localization/SandShiftSpecial.lean new file mode 100644 index 0000000000000000000000000000000000000000..b9702eb5b97bfb9bfc438b843fe1f928e259e88f --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/SandShiftSpecial.lean @@ -0,0 +1,144 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.Vectorize +import OAI.Probability.SKGap.Localization.Quadratic +import OAI.Probability.SKGap.Brownian.PathResolvent +import OAI.Probability.SKGap.Matrix.InverseSubSquareMul + +namespace OAI + +section +noncomputable section +open MeasureTheory ProbabilityTheory InformationTheory Real Set +open scoped NNReal ENNReal +open Filter +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius ENNReal NNReal +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius NNReal +noncomputable section +open MeasureTheory ProbabilityTheory Real Set Filter +open MeasureTheory.Measure +open scoped ENNReal NNReal MeasureTheory Topology +open MeasureTheory +noncomputable section +noncomputable section +open MeasureTheory Set NormedSpace +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius +noncomputable section +open Set Real +open scoped Topology +noncomputable section +open Matrix Set Filter +open scoped Topology Matrix.Norms.Frobenius +noncomputable section +open Matrix NormedSpace ContinuousLinearMap +open scoped Matrix.Norms.Frobenius +noncomputable section +open Matrix +namespace SKGap.ComplexMatrix +open scoped SchwartzMap ComplexOrder +open Set Filter +open scoped Topology +variable {ι : Type*} [Fintype ι] [DecidableEq ι] + +lemma sandShift_special (D C M : Matrix ι ι ℂ) : + sandShift (1+D*C*D) D M = 1-D*(M-C)*D := by + dsimp [sandShift]; noncomm_ring + +lemma truncatedK_eq_inverse (f : 𝓢(ℝ,ℂ)) {lo hi : ℝ} (hlo : 0 < lo) + (hf : ∀ x ∈ Icc lo hi, f x = (x : ℂ)⁻¹) + {R : ℝ} (hR : 0 ≤ R) (D C M : Matrix ι ι ℂ) + (hD : Dᴴ = D) (hC : Cᴴ = C) (hM : Mᴴ = M) (hMR : opNorm M ≤ R) + (hspec : ∀ i, Matrix.IsHermitian.eigenvalues (sandShift_hermitian (1+D*C*D) D M + (by simp [Matrix.conjTranspose_mul,hD,hC,mul_assoc]) hD hM) i ∈ Icc lo hi) : + truncatedK f R hR (1+D*C*D) D C M = (1-D*D*(M-C))⁻¹ := by + have hB : (1+D*C*D)ᴴ = 1+D*C*D := by simp [Matrix.conjTranspose_mul,hD,hC,mul_assoc] + have hS : IsUnit (sandShift (1+D*C*D) D M) := + ((Matrix.IsHermitian.posDef_iff_eigenvalues_pos (sandShift_hermitian _ _ _ hB hD hM)).mpr + (fun i => hlo.trans_le (hspec i).1)).isUnit + rw [truncatedK,truncatedG_eq_inverse f hlo hf R hR _ _ _ hB hD hM hMR hspec, + matrixProject_eq_self R hR M hM hMR,sandShift_special] + exact (SKGap.ResolventIdentity.inverse_one_sub_square_mul D (M-C) (by + simpa only [sandShift_special] using hS)).symm + +lemma truncatedK_eventually_eq_inverse (f : 𝓢(ℝ,ℂ)) {lo hi : ℝ} (hlo : 0 < lo) + (hf : ∀ x ∈ Icc lo hi, f x = (x : ℂ)⁻¹) + {R : ℝ} (hR : 0 ≤ R) (D C : Matrix ι ι ℂ) + {M : ℝ → Matrix ι ι ℂ} {t : ℝ} (hMc : ContinuousAt M t) + (hD : Dᴴ = D) (hC : Cᴴ = C) (hM : ∀ s, (M s)ᴴ = M s) + (hMR : opNorm (M t) < R) + (hl : lo < SKGap.ComplexSpectral.lowerRayleigh (sandShift (1+D*C*D) D (M t))) + (hu : -hi < SKGap.ComplexSpectral.lowerRayleigh (-sandShift (1+D*C*D) D (M t))) : + (fun s => truncatedK f R hR (1+D*C*D) D C (M s)) =ᶠ[𝓝 t] + (fun s => (1-D*D*(M s-C))⁻¹) := by + have hB : (1+D*C*D)ᴴ = 1+D*C*D := by simp [Matrix.conjTranspose_mul,hD,hC,mul_assoc] + have hs : ContinuousAt (fun s => sandShift (1+D*C*D) D (M s)) t := by + dsimp [sandShift]; fun_prop + have he := SKGap.ComplexSpectral.spectral_interval_eventually hs + (fun s => sandShift_hermitian _ _ _ hB hD (hM s)) hl hu + have hm := ((continuous_lin.norm).continuousAt.comp hMc).eventually (gt_mem_nhds hMR) + filter_upwards [he,hm] with s hs hm + exact truncatedK_eq_inverse f hlo hf hR D C (M s) hD hC (hM s) hm.le hs + +lemma square_resolvent_derivative (D C M E : Matrix ι ι ℂ) + (hunit : IsUnit (1-D*D*(M-C))) : + HasDerivAt (fun t : ℝ => (1-D*D*(M+t • E-C))⁻¹) + ((1-D*D*(M-C))⁻¹*(D*D)*E*(1-D*D*(M-C))⁻¹) 0 := by + have hm : HasDerivAt (fun t : ℝ => M+t • E-C) E 0 := by + convert! ((hasDerivAt_id (0:ℝ)).smul_const E |>.const_add M).sub_const C using 1 + simp only [one_smul] + have hq := (hm.const_mul (D*D)).const_sub 1 + have hi := matrix_hasDerivAt_inverse hq (by simpa using hunit) + simpa only [zero_smul,add_zero,mul_neg,neg_mul,neg_neg,mul_assoc] using! hi + +lemma truncatedK_derivative (f : 𝓢(ℝ,ℂ)) {lo hi : ℝ} (hlo : 0 < lo) + (hf : ∀ x ∈ Icc lo hi, f x = (x : ℂ)⁻¹) + {R : ℝ} (hR : 0 ≤ R) (D C M E : Matrix ι ι ℂ) + (hD : Dᴴ = D) (hC : Cᴴ = C) (hM : Mᴴ = M) (hE : Eᴴ = E) + (hMR : opNorm M < R) + (hl : lo < SKGap.ComplexSpectral.lowerRayleigh (sandShift (1+D*C*D) D M)) + (hu : -hi < SKGap.ComplexSpectral.lowerRayleigh (-sandShift (1+D*C*D) D M)) : + HasDerivAt (fun t : ℝ => truncatedK f R hR (1+D*C*D) D C (M+t • E)) + (truncatedK f R hR (1+D*C*D) D C M*(D*D)*E* + truncatedK f R hR (1+D*C*D) D C M) 0 := by + have hB : (1+D*C*D)ᴴ = 1+D*C*D := by simp [Matrix.conjTranspose_mul,hD,hC,mul_assoc] + have hSM : (sandShift (1+D*C*D) D M).IsHermitian := sandShift_hermitian _ _ _ hB hD hM + have hspec : ∀ i, hSM.eigenvalues i ∈ Icc lo hi := by + intro i + have hm := SKGap.ComplexSpectral.eigenvalue_lower_bound hSM i + have hp := SKGap.ComplexSpectral.eigenvalue_upper_bound hSM i + constructor <;> linarith + have hS : IsUnit (1-D*(M-C)*D) := by + rw [← sandShift_special] + exact (hSM.posDef_iff_eigenvalues_pos.mpr (fun i => hlo.trans_le (hspec i).1)).isUnit + have hunit := SKGap.ResolventIdentity.inverse_one_sub_square_mul_unit D (M-C) hS + have hid := truncatedK_eq_inverse f hlo hf hR D C M hD hC hM hMR.le hspec + rw [hid] + have he := truncatedK_eventually_eq_inverse f hlo hf hR D C + (M := fun t : ℝ => M+t • E) (t := 0) (by fun_prop) hD hC + (fun t => by simp [Matrix.conjTranspose_smul,hM,hE]) + (by simpa using hMR) (by simpa using hl) (by simpa using hu) + exact (square_resolvent_derivative D C M E hunit).congr_of_eventuallyEq he + +end SKGap.ComplexMatrix + +end +end +end +end +end +end +end +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/ScalarClosedIsolation.lean b/lean/OAI/Probability/SKGap/Localization/ScalarClosedIsolation.lean new file mode 100644 index 0000000000000000000000000000000000000000..91e98aafec03550dc57b48c681837cdd607e9a8b --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/ScalarClosedIsolation.lean @@ -0,0 +1,180 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.ScalarEmpirical + +namespace OAI + +section +noncomputable section +open MeasureTheory ProbabilityTheory InformationTheory Real Set Filter +open scoped NNReal ENNReal Topology +noncomputable section +open Real Set +noncomputable section +open MeasureTheory ProbabilityTheory Real Set Filter +open scoped Topology NNReal ENNReal BoundedContinuousFunction +open MeasureTheory ProbabilityTheory Filter Set Topology Real +open scoped NNReal ENNReal BoundedContinuousFunction +noncomputable section +open Set Filter Topology +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set Topology Real +open scoped NNReal ENNReal BoundedContinuousFunction +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set Topology Real +open scoped NNReal ENNReal BoundedContinuousFunction +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set Topology Real +open scoped NNReal ENNReal +namespace SKGap + +theorem scalar_closed_isolation {j T smin : ℝ} (hj : 0 < j) (hj1 : j < 1) + (hT : 0 ≤ T) (hsmin : 0 < smin) {C : Set ScalarPoint} (hC : IsClosed C) + (hne : ∀ p ∈ C, p.2.1 ∈ Icc 0 T → p.2.2 = 0 → p.1 ≠ scalarCurve j p.2.1) : + ∃ a > 0, ∃ δ > 0, ∃ N : ℕ, ∀ n ≥ N, ∀ hn : 0 < n, ∀ t ∈ Icc 0 T, + ∀ σ ∈ Icc 0 (min δ 1), ∀ E : Set (Fin n → ℝ), MeasurableSet E → + (∀ y ∈ E, @scalarEmpirical (Fin n) _ ⟨⟨0,hn⟩⟩ y t σ ∈ C) → + (∀ y ∈ E, smin ≤ scalarS j (@scalarEmpirical (Fin n) _ ⟨⟨0,hn⟩⟩ y t σ)) → + (∫⁻ y in E, ENNReal.ofReal (@scalarIntegrand (Fin n) _ ⟨⟨0,hn⟩⟩ j t σ y)) ≤ + ENNReal.ofReal (exp (-a*(n:ℝ))) := by + obtain ⟨R,hR,hTail⟩ := scalar_uniform_tail hj.le hT hsmin 1 + let K := scalarBox j R T smin ∩ C + have hK : IsCompact K := (isCompact_scalarBox j R T smin).inter_right hC + have hmom : K ⊆ scalarMomentDomain R := fun p hp => ⟨hp.1.1.1,mem_univ _⟩ + obtain ⟨a,ha,δ,hδ,N,hN⟩ := scalar_compact_isolation hj hj1 hR.le hK hmom + (fun p hp => hp.1.1.2.1.1) (fun p hp => hp.1.1.2.2.1) + (fun p hp => hsmin.trans_le hp.1.2) (fun p hp hz => hne p hp.2 hp.1.1.2.1 hz) + let b := min a 1 + have hb : 0 < b := lt_min ha zero_lt_one + obtain ⟨M,hM⟩ := absorb_finite_exponential_factor 2 (half_pos hb) + refine ⟨b/2,half_pos hb,δ,hδ,max N M,?_⟩ + intro n hn hn' t ht σ hσ E hE hforbid hs + let : Nonempty (Fin n) := ⟨⟨0,hn'⟩⟩ + have hσ' : σ ∈ Icc (0:ℝ) 1 := ⟨hσ.1,hσ.2.trans (min_le_right _ _)⟩ + let B : Set (Fin n → ℝ) := {y | ∑ i, (y i)^2 ≤ (n:ℝ)*R} + have hB : MeasurableSet B := isClosed_le (by fun_prop) continuous_const |>.measurableSet + have hc := hN n (le_trans (le_max_left _ _) hn) hn' (fun y => scalarEmpirical y t σ) + (E ∩ B) (hE.inter hB) (fun y hy => ⟨⟨⟨⟨empirical_momentBall y hR.le + (by simpa only [Fintype.card_fin] using (show ∑ i, (y i)^2 ≤ (n:ℝ)*R from hy.2)),ht,hσ'⟩, + hs y hy.1⟩,hforbid y hy.1⟩,hσ.2.trans (min_le_left _ _)⟩) + (fun _ _ => rfl) (fun _ hy => hy.2) + have hc' : (∫⁻ y in E ∩ B, ENNReal.ofReal (scalarIntegrand j t σ y)) ≤ + ENNReal.ofReal (exp (-b*(n:ℝ))) := by + have hab : exp (-a*(n:ℝ)) ≤ exp (-b*(n:ℝ)) := exp_le_exp.mpr (by + have hh := mul_le_mul_of_nonneg_right (min_le_left a 1) (Nat.cast_nonneg (α := ℝ) n) + dsimp [b]; linarith only [hh]) + simpa only [scalarIntegrand, Fintype.card_fin] using hc.trans (ENNReal.ofReal_le_ofReal hab) + have htail := hTail n hn' t ht σ hσ' (E ∩ Bᶜ) (hE.inter hB.compl) + (fun y hy => hs y hy.1) (fun y hy => le_of_lt (not_le.mp hy.2)) + have he : exp (-(1:ℝ)*(n:ℝ)) ≤ exp (-b*(n:ℝ)) := exp_le_exp.mpr (by + have hh := mul_le_mul_of_nonneg_right (min_le_right a 1) (Nat.cast_nonneg (α := ℝ) n) + dsimp [b]; linarith only [hh]) + have htotal := (lintegral_split_le volume (fun y => ENNReal.ofReal (scalarIntegrand j t σ y)) E B).trans + (add_le_add hc' (htail.trans (ENNReal.ofReal_le_ofReal he))) + have hadd : ENNReal.ofReal (exp (-b*(n:ℝ)))+ENNReal.ofReal (exp (-b*(n:ℝ))) = + ENNReal.ofReal (2*exp ((n:ℝ)*(-b))) := by + rw [← ENNReal.ofReal_add (exp_pos _).le (exp_pos _).le] + congr 1 + ring_nf + rw [hadd] at htotal + refine htotal.trans (ENNReal.ofReal_le_ofReal ?_) + convert hM n (le_trans (le_max_right _ _) hn) (-b) using 1 + congr 1 + ring + +lemma scalar_neighborhood_forbidden {j t₀ T : ℝ} {U : Set ScalarPoint} + (hU : IsOpen U) (hcurve : ∀ t ∈ Icc t₀ T, (scalarCurve j t,(t,0)) ∈ U) : + IsClosed ({p : ScalarPoint | t₀ ≤ p.2.1} ∩ Uᶜ) ∧ + ∀ p ∈ ({p : ScalarPoint | t₀ ≤ p.2.1} ∩ Uᶜ), p.2.1 ∈ Icc 0 T → + p.2.2 = 0 → p.1 ≠ scalarCurve j p.2.1 := by + refine ⟨(isClosed_le continuous_const (by fun_prop)).inter hU.isClosed_compl,?_⟩ + intro p hp ht hz he + apply hp.2 + have h := hcurve p.2.1 ⟨hp.1,ht.2⟩ + have hp' : p = (scalarCurve j p.2.1,(p.2.1,0)) := by + apply Prod.ext he + exact Prod.ext rfl hz + rwa [hp'] + +lemma scalar_smalltime_forbidden {j q₀ : ℝ} (hj : 0 < j) (hj1 : j < 1) (hq : 0 < q₀) : + ∃ T > 0, IsClosed {p : ScalarPoint | q₀ ≤ scalarQMoment p.1} ∧ + (∀ p ∈ {p : ScalarPoint | q₀ ≤ scalarQMoment p.1}, p.2.1 ∈ Icc 0 T → + p.2.2 = 0 → p.1 ≠ scalarCurve j p.2.1) ∧ + (∀ p ∈ {p : ScalarPoint | q₀ ≤ scalarQMoment p.1}, 0 ≤ p.2.1 → + j*q₀ ≤ scalarS j p) := by + let T := q₀*(1-j)/4 + have hT : 0 < T := by dsimp [T]; positivity + refine ⟨T,hT,isClosed_le continuous_const (continuous_scalarQMoment.comp continuous_fst),?_,?_⟩ + · intro p hp ht _ he + have hqspec := scalarQ_spec hj hj1 ht.1 + have heq : scalarQMoment p.1 = scalarQ j p.2.1 := by + rw [he] + exact hqspec.1.symm + have hsmall : p.2.1/(1-j) ≤ q₀/4 := by + apply (div_le_iff₀ (by linarith : 0 < 1-j)).mpr + dsimp [T] at ht + linarith only [ht.2] + change q₀ ≤ scalarQMoment p.1 at hp + rw [heq] at hp + have hh := hqspec.2.2.trans hsmall + change q₀ ≤ scalarQ j p.2.1 at hp + linarith + · intro p hp ht + exact (mul_le_mul_of_nonneg_left hp hj.le).trans (scalar_consistency ht) + +end SKGap + +namespace SKGap + +theorem scalar_rate_ii {j t₀ T : ℝ} (hj : 0 < j) (hj1 : j < 1) + (ht₀ : 0 < t₀) (hT : t₀ ≤ T) {U : Set ScalarPoint} (hU : IsOpen U) + (hcurve : ∀ t ∈ Icc t₀ T, (scalarCurve j t,(t,0)) ∈ U) : + ∃ a > 0, ∃ δ > 0, ∃ N : ℕ, ∀ n ≥ N, ∀ hn : 0 < n, + ∀ t ∈ Icc t₀ T, ∀ σ ∈ Icc 0 (min δ 1), + ∀ E : Set (Fin n → ℝ), MeasurableSet E → + (∀ y ∈ E, @scalarEmpirical (Fin n) _ ⟨⟨0,hn⟩⟩ y t σ ∉ U) → + (∫⁻ y in E, ENNReal.ofReal (@scalarIntegrand (Fin n) _ ⟨⟨0,hn⟩⟩ j t σ y)) ≤ + ENNReal.ofReal (exp (-a*(n:ℝ))) := by + obtain ⟨hC,hne⟩ := scalar_neighborhood_forbidden hU hcurve + obtain ⟨a,ha,δ,hδ,N,hN⟩ := scalar_closed_isolation hj hj1 (ht₀.le.trans hT) ht₀ hC hne + refine ⟨a,ha,δ,hδ,N,?_⟩ + intro n hn hn' t ht σ hσ E hE hbad + let : Nonempty (Fin n) := ⟨⟨0,hn'⟩⟩ + apply hN n hn hn' t ⟨ht₀.le.trans ht.1,ht.2⟩ σ hσ E hE + (fun y hy => ⟨ht.1,hbad y hy⟩) + intro y _ + unfold scalarS scalarEmpirical + dsimp only + have hq := mul_nonneg hj.le (scalarQMoment_bounds (empiricalLaw y)).1 + nlinarith [sq_nonneg σ,ht.1] + +theorem scalar_rate_iii {j q₀ : ℝ} (hj : 0 < j) (hj1 : j < 1) (hq₀ : 0 < q₀) : + ∃ t₀ > 0, ∃ δ > 0, ∃ a > 0, ∃ N : ℕ, ∀ n ≥ N, ∀ hn : 0 < n, + ∀ t ∈ Icc 0 t₀, ∀ σ ∈ Icc 0 (min δ 1), + ∀ E : Set (Fin n → ℝ), MeasurableSet E → + (∀ y ∈ E, q₀ ≤ scalarQMoment (@empiricalLaw (Fin n) _ ⟨⟨0,hn⟩⟩ y)) → + (∫⁻ y in E, ENNReal.ofReal (@scalarIntegrand (Fin n) _ ⟨⟨0,hn⟩⟩ j t σ y)) ≤ + ENNReal.ofReal (exp (-a*(n:ℝ))) := by + obtain ⟨T,hT,hC,hne,hfloor⟩ := scalar_smalltime_forbidden hj hj1 hq₀ + obtain ⟨a,ha,δ,hδ,N,hN⟩ := scalar_closed_isolation hj hj1 hT.le (mul_pos hj hq₀) hC hne + refine ⟨T,hT,δ,hδ,a,ha,N,?_⟩ + intro n hn hn' t ht σ hσ E hE hbad + let : Nonempty (Fin n) := ⟨⟨0,hn'⟩⟩ + exact hN n hn hn' t ht σ hσ E hE hbad (fun y hy => hfloor (scalarEmpirical y t σ) (hbad y hy) ht.1) + +end SKGap + +noncomputable section +open MeasureTheory ProbabilityTheory Real Filter Set +open scoped Topology NNReal ENNReal BoundedContinuousFunction + +end +end +end +end +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/ScalarConsistency.lean b/lean/OAI/Probability/SKGap/Localization/ScalarConsistency.lean new file mode 100644 index 0000000000000000000000000000000000000000..87c19ff238718ed79516fb16c6998e43c726e4ff --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/ScalarConsistency.lean @@ -0,0 +1,232 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.EqualityCurve +import OAI.Probability.SKGap.Entropy.EntropyTestBoundQPos + +namespace OAI + +section +noncomputable section +open MeasureTheory ProbabilityTheory InformationTheory Real Set Filter +open scoped NNReal ENNReal Topology +noncomputable section +open Real Set +noncomputable section +open MeasureTheory ProbabilityTheory Real Set Filter +open scoped Topology NNReal ENNReal BoundedContinuousFunction +namespace SKGap +end SKGap + +namespace SKGap +open Filter +open scoped Topology + +end SKGap + +namespace SKGap +open Filter +open scoped Topology + +end SKGap + +namespace SKGap +open Filter +open scoped Topology + +end SKGap + +namespace SKGap + +end SKGap + +open MeasureTheory ProbabilityTheory Filter Set Topology Real +open scoped NNReal ENNReal BoundedContinuousFunction + +namespace SKGap + +end SKGap + +namespace SKGap + +end SKGap + +namespace SKGap + +lemma scalar_consistency {j : ℝ} {p : ScalarPoint} (ht : 0 ≤ p.2.1) : + j*scalarQMoment p.1 ≤ scalarS j p := by + unfold scalarS + nlinarith [sq_nonneg p.2.2] + +lemma scalarPsi_eq_entropy {R j : ℝ} {p : ScalarPoint} + (hp : p ∈ scalarMomentDomain R) (hs : 0 ≤ scalarS j p) : + scalarPsi j p = scalarEntropyTarget (p.1 : Measure ℝ) j (scalarD j p) (scalarS j p).toNNReal := by + simp only [scalarPsi, scalarEntropyTarget, Real.coe_toNNReal _ hs, scalarA_eq hp, scalarQMoment] + +lemma scalar_weak_test {R j : ℝ} {p : ScalarPoint} + (hp : p ∈ scalarMomentDomain R) (hj : 0 < j) (hj1 : j < 1) + (ht : 0 ≤ p.2.1) (hs : 0 < scalarS j p) {ε : ℝ} (hε : 0 < ε) : + ∃ f : ℝ →ᵇ ℝ, scalarPsi j p-(∫ y, f y ∂p.1)+ + log (∫ y, exp (f y) ∂gaussianReal (scalarD j p) (scalarS j p).toNNReal) < ε := by + by_contra hh + push Not at hh + have hD : EntropyTestBound (p.1 : Measure ℝ) + (gaussianReal (scalarD j p) (scalarS j p).toNNReal) (scalarPsi j p-ε) := by + intro f + linarith [hh f] + have hcons : j * (∫ y, tanh y^2 ∂p.1) ≤ ((scalarS j p).toNNReal : ℝ) := by + rw [Real.coe_toNNReal _ hs.le] + exact scalar_consistency ht + have h := (test_scalar_inequality (momentBall_integrable hp.1) hj hj1 + (ne_of_gt (Real.toNNReal_pos.mpr hs)) hcons hD).1 + change scalarEntropyTarget (p.1 : Measure ℝ) j (scalarD j p) (scalarS j p).toNNReal ≤ _ at h + rw [← scalarPsi_eq_entropy hp hs.le] at h + linarith + +lemma scalar_strict_test {R j : ℝ} {p : ScalarPoint} + (hp : p ∈ scalarMomentDomain R) (hj : 0 < j) (hj1 : j < 1) + (ht : 0 ≤ p.2.1) (hs : 0 < scalarS j p) + (hne : (p.1 : Measure ℝ) ≠ gaussianReal (scalarD j p) (scalarS j p).toNNReal) : + ∃ f : ℝ →ᵇ ℝ, scalarPsi j p-(∫ y, f y ∂p.1)+ + log (∫ y, exp (f y) ∂gaussianReal (scalarD j p) (scalarS j p).toNNReal) < 0 := by + have hcons : j * (∫ y, tanh y^2 ∂p.1) ≤ ((scalarS j p).toNNReal : ℝ) := by + rw [Real.coe_toNNReal _ hs.le] + exact scalar_consistency ht + obtain ⟨f,hf⟩ := scalar_strict_witness (momentBall_integrable hp.1) hj hj1 + (ne_of_gt (Real.toNNReal_pos.mpr hs)) hcons hne + rw [← scalarPsi_eq_entropy hp hs.le] at hf + exact ⟨f, by linarith⟩ + +lemma scalar_gaussian_curve {j : ℝ} {p : ScalarPoint} + (hj : 0 < j) (hj1 : j < 1) (ht : 0 ≤ p.2.1) + (hσ : p.2.2 = 0) (hs : 0 ≤ scalarS j p) + (hP : (p.1 : Measure ℝ) = gaussianReal (scalarD j p) (scalarS j p).toNNReal) : + p.1 = scalarCurve j p.2.1 := by + have hd : scalarD j p = p.2.1+j*(∫ y, tanh y ∂gaussianReal (scalarD j p) (scalarS j p).toNNReal) := by + rw [← hP] + rfl + have hv : ((scalarS j p).toNNReal : ℝ) = + p.2.1+j*(∫ y, tanh y^2 ∂gaussianReal (scalarD j p) (scalarS j p).toNNReal) := by + rw [Real.coe_toNNReal _ hs, ← hP] + simp [scalarS, scalarQMoment, hσ] + obtain ⟨hd',hs'⟩ := consistent_gaussian_unique hj hj1 ht hd hv + rw [Real.coe_toNNReal _ hs] at hs' + apply ProbabilityMeasure.toMeasure_injective + change (p.1 : Measure ℝ) = gaussianReal (scalarFixedPoint j p.2.1) (scalarFixedPoint j p.2.1).toNNReal + rw [hP, hd', hs'] + +lemma continuousOn_scalar_test {R j : ℝ} (hR : 0 ≤ R) (hj : 0 ≤ j) + (f : ℝ →ᵇ ℝ) : ContinuousOn (fun p : ScalarPoint => + scalarPsi j p-(∫ y, f y ∂p.1)+scalarLogMoment f (scalarD j p) (scalarS j p)) + (scalarMomentDomain R ∩ {p | 0 < scalarS j p}) := by + have hψ : ContinuousOn (scalarPsi j) + (scalarMomentDomain R ∩ {p | 0 < scalarS j p}) := (continuousOn_scalarPsi hR j).mono (by + intro p hp + refine ⟨hp.1,hp.2.ne',ne_of_gt ?_⟩ + exact add_pos_of_pos_of_nonneg hp.2 (mul_nonneg hj (scalarQMoment_bounds p.1).1)) + exact (hψ.sub ((ProbabilityMeasure.continuous_integral_boundedContinuousFunction f).comp + continuous_fst).continuousOn).add + ((continuous_scalarLogMoment f).comp ((continuous_scalarD j).prodMk (continuous_scalarS j))).continuousOn + +end SKGap + +noncomputable section +open Set Filter Topology +namespace SKGap + +lemma finite_pos_lower_bound {X : Type*} (C : Finset X) (a : X → ℝ) + (ha : ∀ x ∈ C, 0 < a x) : ∃ ε > 0, ∀ x ∈ C, ε ≤ a x := by + classical + induction C using Finset.induction_on with + | empty => exact ⟨1,by norm_num,by simp⟩ + | insert x C hx ih => + obtain ⟨ε,hε,he⟩ := ih (fun y hy => ha y (Finset.mem_insert_of_mem hy)) + refine ⟨min (a x) ε, lt_min (ha x (Finset.mem_insert_self _ _)) hε, ?_⟩ + intro y hy + rcases Finset.mem_insert.mp hy with rfl | hy + · exact min_le_left _ _ + · exact (min_le_right _ _).trans (he y hy) + +theorem compact_strict_witness {X F : Type*} [TopologicalSpace X] {K : Set X} + (hK : IsCompact K) (w : F → X → ℝ) (hw : ∀ f, ContinuousOn (w f) K) + (hW : ∀ x ∈ K, ∃ f, w f x < 0) : + ∃ a > 0, ∀ x ∈ K, ∃ f, w f x < -a := by + classical + let : CompactSpace K := isCompact_iff_compactSpace.mp hK + choose f hf using fun x : K => hW x.1 x.2 + let a (x : K) := -(w (f x) x)/2 + have ha (x : K) : 0 < a x := by dsimp [a]; linarith [hf x] + let U (x : K) : Set K := {z | w (f x) z < -a x} + have hU (x : K) : IsOpen (U x) := isOpen_lt (hw (f x)).domRestrict continuous_const + have hcov : (univ : Set K) ⊆ ⋃ x, U x := by + intro x _ + apply mem_iUnion.mpr + refine ⟨x,?_⟩ + change w (f x) x < -a x + dsimp [a] + linarith [hf x] + obtain ⟨C,hC⟩ := isCompact_univ.elim_finite_subcover U hU hcov + obtain ⟨ε,hε,he⟩ := finite_pos_lower_bound C a (fun x _ => ha x) + refine ⟨ε,hε,?_⟩ + intro z hz + obtain ⟨x,hx⟩ := mem_iUnion.mp (hC (mem_univ (⟨z,hz⟩ : K))) + obtain ⟨hxC,hxz⟩ := mem_iUnion.mp hx + refine ⟨f x,?_⟩ + change w (f x) z < -a x at hxz + linarith [he x hxC] + +lemma compact_zero_fiber_neighborhood {X : Type*} [TopologicalSpace X] [CompactSpace X] + {σ : X → ℝ} (hσ : Continuous σ) (hnn : ∀ x, 0 ≤ σ x) + {U : Set X} (hU : IsOpen U) (hzero : ∀ x, σ x = 0 → x ∈ U) : + ∃ δ > 0, ∀ x, σ x ≤ δ → x ∈ U := by + by_cases he : Uᶜ = ∅ + · refine ⟨1,by norm_num,?_⟩ + intro x _ + by_contra hx + have hx' : x ∈ Uᶜ := hx + simp only [he, mem_empty_iff_false] at hx' + obtain ⟨x,hx,hmin⟩ := hU.isClosed_compl.isCompact.exists_isMinOn (nonempty_iff_ne_empty.mpr he) hσ.continuousOn + have hxpos : 0 < σ x := lt_of_le_of_ne (hnn x) (by + intro hh + exact hx (hzero x hh.symm)) + refine ⟨σ x/2,by positivity,?_⟩ + intro y hy + by_contra hny + have h : σ x ≤ σ y := hmin hny + linarith + +theorem compact_small_noise_witness {X F : Type*} [TopologicalSpace X] {K : Set X} + (hK : IsCompact K) (w : F → X → ℝ) (hw : ∀ f, ContinuousOn (w f) K) + {σ : X → ℝ} (hσ : ContinuousOn σ K) (hnn : ∀ x ∈ K, 0 ≤ σ x) + (hW : ∀ x ∈ K, σ x = 0 → ∃ f, w f x < 0) : + ∃ a > 0, ∃ δ > 0, ∀ x ∈ K, σ x ≤ δ → ∃ f, w f x < -a := by + classical + let : CompactSpace K := isCompact_iff_compactSpace.mp hK + let Z : Set K := {x | σ x = 0} + have hZ : IsCompact Z := (isClosed_eq hσ.domRestrict continuous_const).isCompact + obtain ⟨a,ha,hA⟩ := compact_strict_witness hZ (fun f (x : K) => w f x) + (fun f => (hw f).domRestrict.continuousOn) (fun x hx => hW x.1 x.2 hx) + let U : Set K := {x | ∃ f, w f x < -(a/2)} + have hU : IsOpen U := by + have hu : U = ⋃ f : F, {x : K | w f x < -(a/2)} := by ext x; simp [U] + rw [hu] + exact isOpen_iUnion (fun f => isOpen_lt (hw f).domRestrict continuous_const) + have hzU (x : K) (hx : σ x = 0) : x ∈ U := by + obtain ⟨f,hf⟩ := hA x hx + exact ⟨f,by linarith⟩ + obtain ⟨δ,hδ,hd⟩ := compact_zero_fiber_neighborhood hσ.domRestrict + (fun x : K => hnn x.1 x.2) hU hzU + exact ⟨a/2,by positivity,δ,hδ,fun x hx hσx => hd ⟨x,hx⟩ hσx⟩ + +end SKGap + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set Topology Real +open scoped NNReal ENNReal BoundedContinuousFunction + +end +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/ScalarEigenfunction.lean b/lean/OAI/Probability/SKGap/Localization/ScalarEigenfunction.lean new file mode 100644 index 0000000000000000000000000000000000000000..ad9a1416e02b4ba9d88440b5ca1a8722bf1c0c68 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/ScalarEigenfunction.lean @@ -0,0 +1,288 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.Invert + +namespace OAI + +section +open scoped BigOperators +namespace SKGapCutoff +open MeasureTheory + +lemma spectral_parseval {n : ℕ} (J : Interaction n) + (hJ : ∀ i j, J i j = J j i) (hdiag : ∀ i, J i i = 0) (f g : Observables n) : + (∑ a, (spinEigenbasis J hJ hdiag).repr (gibbsEuclideanEquiv J f) a * + (spinEigenbasis J hJ hdiag).repr (gibbsEuclideanEquiv J g) a) = stationaryInner J f g := by + have he := (spinEigenbasis J hJ hdiag).repr.inner_map_map + (gibbsEuclideanEquiv J f) (gibbsEuclideanEquiv J g) + rw [PiLp.inner_apply, gibbsEuclideanEquiv_inner] at he + simpa only [RCLike.inner_apply, conj_trivial, mul_comm] using he + +lemma spectral_generator_coordinates {n : ℕ} (J : Interaction n) + (hJ : ∀ i j, J i j = J j i) (hdiag : ∀ i, J i i = 0) + (f : Observables n) (a : Fin (Fintype.card (Spin n))) : + (spinEigenbasis J hJ hdiag).repr (gibbsEuclideanEquiv J (-generator J f)) a = + spinEigenvalues J hJ hdiag a * + (spinEigenbasis J hJ hdiag).repr (gibbsEuclideanEquiv J f) a := by + rw [← negativeGeneratorEuclidean_lift] + exact (negativeGeneratorEuclidean_symmetric J hJ hdiag).eigenvectorBasis_apply_self_apply + finrank_euclideanSpace (gibbsEuclideanEquiv J f) a + +lemma spinEigenvalues_nonneg {n : ℕ} (J : Interaction n) + (hJ : ∀ i j, J i j = J j i) (hdiag : ∀ i, J i i = 0) + (a : Fin (Fintype.card (Spin n))) : 0 ≤ spinEigenvalues J hJ hdiag a := by + have he : negativeGeneratorEuclidean J (spinEigenbasis J hJ hdiag a) = + spinEigenvalues J hJ hdiag a • spinEigenbasis J hJ hdiag a := + (negativeGeneratorEuclidean_symmetric J hJ hdiag).apply_eigenvectorBasis finrank_euclideanSpace a + have hp := negativeGeneratorEuclidean_nonneg J hJ hdiag (spinEigenbasis J hJ hdiag a) + rw [he, inner_smul_right] at hp + simpa only [real_inner_self_eq_norm_sq, (spinEigenbasis J hJ hdiag).orthonormal.norm_eq_one, + one_pow, mul_one] using hp + +lemma sum_spinSpectralCoefficient_sq {n : ℕ} (J : Interaction n) + (hJ : ∀ i j, J i j = J j i) (hdiag : ∀ i, J i i = 0) (i : Fin n) : + ∑ a, spinSpectralCoefficient J hJ hdiag i a ^ 2 = 1 := by + have he := spectral_parseval J hJ hdiag (fun x => spin x i) (fun x => spin x i) + simp only [stationaryInner, ← sq, spin_sq, gibbsExpectation_const] at he + simpa only [spinSpectralCoefficient, pow_two] using he + +lemma spinSpectralMass_nonneg {n : ℕ} (J : Interaction n) + (hJ : ∀ i j, J i j = J j i) (hdiag : ∀ i, J i i = 0) + (a : Fin (Fintype.card (Spin n))) : 0 ≤ spinSpectralMass J hJ hdiag a := + div_nonneg (Finset.sum_nonneg (by intro i _; exact sq_nonneg _)) (Nat.cast_nonneg n) + +lemma sum_spinSpectralMass {n : ℕ} (hn : 0 < n) (J : Interaction n) + (hJ : ∀ i j, J i j = J j i) (hdiag : ∀ i, J i i = 0) : + ∑ a, spinSpectralMass J hJ hdiag a = 1 := by + simp only [spinSpectralMass, ← Finset.sum_div] + rw [Finset.sum_comm] + simp only [sum_spinSpectralCoefficient_sq, Finset.sum_const, Finset.card_univ, + Fintype.card_fin, nsmul_eq_mul, mul_one] + exact div_self (ne_of_gt (Nat.cast_pos.mpr hn)) + +theorem spinSpectralMeasure_probability {n : ℕ} (hn : 0 < n) (J : Interaction n) + (hJ : ∀ i j, J i j = J j i) (hdiag : ∀ i, J i i = 0) : + IsProbabilityMeasure (spinSpectralMeasure J hJ hdiag) := by + constructor + simp only [spinSpectralMeasure, Measure.finsetSum_apply, Measure.smul_apply, + Measure.dirac_apply_of_mem (Set.mem_univ _), smul_eq_mul, mul_one] + rw [← ENNReal.ofReal_sum_of_nonneg (by intro a _; exact spinSpectralMass_nonneg J hJ hdiag a), + sum_spinSpectralMass hn J hJ hdiag, ENNReal.ofReal_one] + +lemma spinSpectralMeasure_integral {n : ℕ} (J : Interaction n) + (hJ : ∀ i j, J i j = J j i) (hdiag : ∀ i, J i i = 0) (F : ℝ → ℝ) : + (∫ u, F u ∂spinSpectralMeasure J hJ hdiag) = + ∑ a, spinSpectralMass J hJ hdiag a * F (spinEigenvalues J hJ hdiag a) := by + unfold spinSpectralMeasure + rw [integral_finsetSum_measure] + · simp only [integral_smul_measure, integral_dirac, smul_eq_mul, + ENNReal.toReal_ofReal (spinSpectralMass_nonneg J hJ hdiag _)] + · intro a _ + exact (integrable_dirac (by simp)).smul_measure ENNReal.ofReal_ne_top + +lemma spinSpectralMeasure_integral_trace {n : ℕ} (J : Interaction n) + (hJ : ∀ i j, J i j = J j i) (hdiag : ∀ i, J i i = 0) (F : ℝ → ℝ) : + (∫ u, F u ∂spinSpectralMeasure J hJ hdiag) = + (∑ i, ∑ a, spinSpectralCoefficient J hJ hdiag i a ^ 2 * + F (spinEigenvalues J hJ hdiag a)) / n := by + rw [spinSpectralMeasure_integral] + simp only [spinSpectralMass, div_mul_eq_mul_div, Finset.sum_mul, ← Finset.sum_div] + rw [Finset.sum_comm] + +lemma spin_first_moment_sum {n : ℕ} (J : Interaction n) + (hJ : ∀ i j, J i j = J j i) (hdiag : ∀ i, J i i = 0) (i : Fin n) : + (∑ a, spinSpectralCoefficient J hJ hdiag i a ^ 2 * spinEigenvalues J hJ hdiag a) = + gibbsExpectation J (fun x => siteVariance J x i) := by + have he := spectral_parseval J hJ hdiag (fun x => spin x i) (-generator J (fun x => spin x i)) + simp_rw [spectral_generator_coordinates] at he + have hm : stationaryInner J (fun x => spin x i) (-generator J (fun x => spin x i)) = + gibbsExpectation J (fun x => siteVariance J x i) := (spin_first_second J hJ hdiag i).1 + rw [hm] at he + convert he using 1 + apply Finset.sum_congr rfl + intro a _ + unfold spinSpectralCoefficient + ring + +lemma spin_second_moment_sum {n : ℕ} (J : Interaction n) + (hJ : ∀ i j, J i j = J j i) (hdiag : ∀ i, J i i = 0) (i : Fin n) : + (∑ a, spinSpectralCoefficient J hJ hdiag i a ^ 2 * spinEigenvalues J hJ hdiag a ^ 2) = + gibbsExpectation J (fun x => siteVariance J x i) := by + have he := spectral_parseval J hJ hdiag (-generator J (fun x => spin x i)) + (-generator J (fun x => spin x i)) + simp_rw [spectral_generator_coordinates] at he + have hn : stationaryInner J (-generator J (fun x => spin x i)) (-generator J (fun x => spin x i)) = + stationaryInner J (generator J (fun x => spin x i)) (generator J (fun x => spin x i)) := by + simp only [stationaryInner, Pi.neg_apply, neg_mul_neg] + rw [hn, (spin_first_second J hJ hdiag i).2] at he + convert he using 1 + apply Finset.sum_congr rfl + intro a _ + unfold spinSpectralCoefficient + ring + +theorem spinSpectralMeasure_moments {n : ℕ} (J : Interaction n) + (hJ : ∀ i j, J i j = J j i) (hdiag : ∀ i, J i i = 0) : + (∫ u, u ∂spinSpectralMeasure J hJ hdiag) = + (∑ i, gibbsExpectation J (fun x => siteVariance J x i)) / n ∧ + (∫ u, u ^ 2 ∂spinSpectralMeasure J hJ hdiag) = + (∑ i, gibbsExpectation J (fun x => siteVariance J x i)) / n := by + constructor + · rw [spinSpectralMeasure_integral_trace] + simp_rw [spin_first_moment_sum] + · rw [spinSpectralMeasure_integral_trace] + simp_rw [spin_second_moment_sum] + +noncomputable def scalarEigenfunction {n : ℕ} (J : Interaction n) + (hJ : ∀ i j, J i j = J j i) (hdiag : ∀ i, J i i = 0) + (a : Fin (Fintype.card (Spin n))) : Observables n := + (gibbsEuclideanEquiv J).symm (spinEigenbasis J hJ hdiag a) + +@[simp] lemma lift_scalarEigenfunction {n : ℕ} (J : Interaction n) + (hJ : ∀ i j, J i j = J j i) (hdiag : ∀ i, J i i = 0) + (a : Fin (Fintype.card (Spin n))) : + gibbsEuclideanEquiv J (scalarEigenfunction J hJ hdiag a) = spinEigenbasis J hJ hdiag a := + (gibbsEuclideanEquiv J).apply_symm_apply _ + +lemma generator_scalarEigenfunction {n : ℕ} (J : Interaction n) + (hJ : ∀ i j, J i j = J j i) (hdiag : ∀ i, J i i = 0) + (a : Fin (Fintype.card (Spin n))) : + generator J (scalarEigenfunction J hJ hdiag a) = + -spinEigenvalues J hJ hdiag a • scalarEigenfunction J hJ hdiag a := by + have he : negativeGeneratorEuclidean J (spinEigenbasis J hJ hdiag a) = + spinEigenvalues J hJ hdiag a • spinEigenbasis J hJ hdiag a := + (negativeGeneratorEuclidean_symmetric J hJ hdiag).apply_eigenvectorBasis finrank_euclideanSpace a + have hf : -generator J (scalarEigenfunction J hJ hdiag a) = + spinEigenvalues J hJ hdiag a • scalarEigenfunction J hJ hdiag a := by + apply (gibbsEuclideanEquiv J).injective + rw [← negativeGeneratorEuclidean_lift, map_smul, lift_scalarEigenfunction] + exact he + simpa only [neg_neg, neg_smul] using congrArg Neg.neg hf + +lemma semigroup_scalarEigenfunction {n : ℕ} (J : Interaction n) + (hJ : ∀ i j, J i j = J j i) (hdiag : ∀ i, J i i = 0) + (a : Fin (Fintype.card (Spin n))) (t : ℝ) : + semigroup J t (scalarEigenfunction J hJ hdiag a) = + Real.exp (-spinEigenvalues J hJ hdiag a * t) • scalarEigenfunction J hJ hdiag a := by + apply exp_apply_of_eigenvector + rw [smul_apply] + change t • generator J (scalarEigenfunction J hJ hdiag a) = _ + rw [generator_scalarEigenfunction, smul_smul, mul_comm] + +lemma spectral_coordinates_inner {n : ℕ} (J : Interaction n) + (hJ : ∀ i j, J i j = J j i) (hdiag : ∀ i, J i i = 0) + (f : Observables n) (a : Fin (Fintype.card (Spin n))) : + (spinEigenbasis J hJ hdiag).repr (gibbsEuclideanEquiv J f) a = + stationaryInner J (scalarEigenfunction J hJ hdiag a) f := by + rw [OrthonormalBasis.repr_apply_apply, ← lift_scalarEigenfunction J hJ hdiag a, + gibbsEuclideanEquiv_inner] + +lemma spectral_semigroup_coordinates {n : ℕ} (J : Interaction n) + (hJ : ∀ i j, J i j = J j i) (hdiag : ∀ i, J i i = 0) + (f : Observables n) (t : ℝ) (a : Fin (Fintype.card (Spin n))) : + (spinEigenbasis J hJ hdiag).repr (gibbsEuclideanEquiv J (semigroup J t f)) a = + Real.exp (-spinEigenvalues J hJ hdiag a * t) * + (spinEigenbasis J hJ hdiag).repr (gibbsEuclideanEquiv J f) a := by + rw [spectral_coordinates_inner, spectral_coordinates_inner, + scalar_semigroup_symmetric J hJ hdiag, semigroup_scalarEigenfunction] + simp only [stationaryInner, Pi.smul_apply, smul_eq_mul, mul_assoc, + gibbsExpectation_mul_const] + +theorem spinSpectralMeasure_correlation {n : ℕ} (J : Interaction n) + (hJ : ∀ i j, J i j = J j i) (hdiag : ∀ i, J i i = 0) (t : ℝ) : + (∫ u, Real.exp (-u*t) ∂spinSpectralMeasure J hJ hdiag) = + (∑ i, stationaryInner J (fun x => spin x i) (semigroup J t (fun x => spin x i))) / n := by + rw [spinSpectralMeasure_integral_trace] + congr 1 + apply Finset.sum_congr rfl + intro i _ + rw [← spectral_parseval J hJ hdiag] + simp_rw [spectral_semigroup_coordinates] + apply Finset.sum_congr rfl + intro a _ + unfold spinSpectralCoefficient + ring + +lemma replace_eq_of_halfDiff_zero {n : ℕ} (f : Observables n) + (h : ∀ i x, halfDiff i f x = 0) (x : Spin n) (i : Fin n) (b : Bool) : + f (replace x i b) = f x := by + have hh := h i x + have hp : f (replace x i true) = f (replace x i false) := by + unfold halfDiff at hh + linarith + have hs := congrArg f (replace_self x i) + cases hi : x i <;> cases b <;> simp_all + +lemma constant_of_halfDiff_zero {n : ℕ} (f : Observables n) + (h : ∀ i x, halfDiff i f x = 0) (x y : Spin n) : f x = f y := by + let blend (s : Finset (Fin n)) : Spin n := fun i => if i ∈ s then y i else x i + have hs (s : Finset (Fin n)) : f (blend s) = f x := by + induction s using Finset.induction_on with + | empty => simp [blend] + | @insert i s hi ih => + have he : blend (insert i s) = replace (blend s) i (y i) := by + funext j + by_cases hj : j = i + · subst j; simp [blend] + · simp [blend, replace, hj] + rw [he, replace_eq_of_halfDiff_zero f h, ih] + have hu := hs Finset.univ + simpa only [blend, Finset.mem_univ, ↓reduceIte] using hu.symm + +lemma halfDiff_zero_of_dirichlet_zero {n : ℕ} (J : Interaction n) (f : Observables n) + (h : dirichlet J f f = 0) (i : Fin n) (x : Spin n) : halfDiff i f x = 0 := by + have hs (y : Spin n) (j : Fin n) : 0 ≤ siteVariance J y j * halfDiff j f y * halfDiff j f y := by + rw [mul_assoc] + exact mul_nonneg (le_of_lt (siteVariance_pos J y j)) (mul_self_nonneg _) + have hx : gibbs J x * (∑ j, siteVariance J x j * halfDiff j f x * halfDiff j f x) = 0 := + (Finset.sum_eq_zero_iff_of_nonneg (by + intro y _ + exact mul_nonneg (le_of_lt (gibbs_pos J y)) (Finset.sum_nonneg (by intro j _; exact hs y j)))).mp h x (Finset.mem_univ _) + have hrow := (mul_eq_zero.mp hx).resolve_left (ne_of_gt (gibbs_pos J x)) + have hi := (Finset.sum_eq_zero_iff_of_nonneg (by intro j _; exact hs x j)).mp hrow i (Finset.mem_univ _) + rw [mul_assoc] at hi + exact mul_self_eq_zero.mp ((mul_eq_zero.mp hi).resolve_left (ne_of_gt (siteVariance_pos J x i))) + +lemma constant_of_generator_zero {n : ℕ} (J : Interaction n) + (hJ : ∀ i j, J i j = J j i) (hdiag : ∀ i, J i i = 0) (f : Observables n) + (h : generator J f = 0) (x y : Spin n) : f x = f y := by + have hd : dirichlet J f f = 0 := by + rw [← gibbs_dirichlet J hJ hdiag, h] + simp [gibbsExpectation] + exact constant_of_halfDiff_zero f (fun i x => halfDiff_zero_of_dirichlet_zero J f hd i x) x y + +lemma spinSpectralCoefficient_zero_eigenvalue {n : ℕ} (J : Interaction n) + (hJ : ∀ i j, J i j = J j i) (hdiag : ∀ i, J i i = 0) + (a : Fin (Fintype.card (Spin n))) (ha : spinEigenvalues J hJ hdiag a = 0) (i : Fin n) : + spinSpectralCoefficient J hJ hdiag i a = 0 := by + have hg : generator J (scalarEigenfunction J hJ hdiag a) = 0 := by + rw [generator_scalarEigenfunction, ha, neg_zero, zero_smul] + have hc (x : Spin n) : scalarEigenfunction J hJ hdiag a x = + scalarEigenfunction J hJ hdiag a (fun _ => false) := + constant_of_generator_zero J hJ hdiag _ hg x _ + unfold spinSpectralCoefficient + rw [spectral_coordinates_inner] + unfold stationaryInner + simp_rw [hc] + rw [gibbsExpectation_mul_const, gibbs_spin_centered, mul_zero] + +theorem spinSpectralMeasure_nonpositive {n : ℕ} (J : Interaction n) + (hJ : ∀ i j, J i j = J j i) (hdiag : ∀ i, J i i = 0) : + spinSpectralMeasure J hJ hdiag (Set.Iic 0) = 0 := by + simp only [spinSpectralMeasure, Measure.finsetSum_apply, Measure.smul_apply] + apply Finset.sum_eq_zero + intro a _ + by_cases ha : spinEigenvalues J hJ hdiag a ≤ 0 + · have hz := le_antisymm ha (spinEigenvalues_nonneg J hJ hdiag a) + have hw : spinSpectralMass J hJ hdiag a = 0 := by + simp [spinSpectralMass, spinSpectralCoefficient_zero_eigenvalue J hJ hdiag a hz] + simp [hw] + · have he : Measure.dirac (spinEigenvalues J hJ hdiag a) (Set.Iic 0) = 0 := by + simp [Set.mem_Iic, ha] + rw [he] + exact smul_zero _ + +end SKGapCutoff + +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/ScalarEmpirical.lean b/lean/OAI/Probability/SKGap/Localization/ScalarEmpirical.lean new file mode 100644 index 0000000000000000000000000000000000000000..a4ec44cb096176214edcecc0d096cbd6adc0f182 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/ScalarEmpirical.lean @@ -0,0 +1,242 @@ +import Mathlib +import OAI.Probability.SKGap.Matrix.NormalLogDensityCentered + +namespace OAI + +section +noncomputable section +open MeasureTheory ProbabilityTheory InformationTheory Real Set Filter +open scoped NNReal ENNReal Topology +noncomputable section +open Real Set +noncomputable section +open MeasureTheory ProbabilityTheory Real Set Filter +open scoped Topology NNReal ENNReal BoundedContinuousFunction +open MeasureTheory ProbabilityTheory Filter Set Topology Real +open scoped NNReal ENNReal BoundedContinuousFunction +noncomputable section +open Set Filter Topology +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set Topology Real +open scoped NNReal ENNReal BoundedContinuousFunction +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set Topology Real +open scoped NNReal ENNReal BoundedContinuousFunction +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set Topology Real +open scoped NNReal ENNReal +namespace SKGap +variable {ι : Type*} [Fintype ι] [Nonempty ι] + +def scalarEmpirical (y : ι → ℝ) (t σ : ℝ) : ScalarPoint := (empiricalLaw y,(t,σ)) + +def scalarIntegrand (j t σ : ℝ) (y : ι → ℝ) : ℝ := + exp ((Fintype.card ι:ℝ)*scalarPsi j (scalarEmpirical y t σ))* + productNormal (scalarD j (scalarEmpirical y t σ)) (scalarS j (scalarEmpirical y t σ)) y + +lemma scalarA_empirical (y : ι → ℝ) (j t σ : ℝ) : + scalarA j (scalarEmpirical y t σ) = (Fintype.card ι:ℝ)⁻¹ * + ∑ i, (y i-scalarD j (scalarEmpirical y t σ))*tanh (y i) := by + unfold scalarA scalarM scalarEmpirical + simp only [integral_empiricalLaw, sub_mul, Finset.sum_sub_distrib, ← Finset.mul_sum] + ring + +lemma empirical_scalar_cauchy (y : ι → ℝ) (j t σ : ℝ) : + (scalarA j (scalarEmpirical y t σ))^2 ≤ scalarQMoment (empiricalLaw y)* + ((Fintype.card ι:ℝ)⁻¹ * ∑ i, (y i-scalarD j (scalarEmpirical y t σ))^2) := by + have h := Finset.sum_mul_sq_le_sq_mul_sq Finset.univ + (fun i => y i-scalarD j (scalarEmpirical y t σ)) (fun i => tanh (y i)) + have hh := mul_le_mul_of_nonneg_left h (sq_nonneg (Fintype.card ι:ℝ)⁻¹) + rw [scalarA_empirical, scalarQMoment, integral_empiricalLaw] + nlinarith only [hh] + +lemma scalar_empirical_quadratic_envelope (y : ι → ℝ) {j t σ : ℝ} + (hj : 0 ≤ j) (ht : 0 ≤ t) (hs : 0 < scalarS j (scalarEmpirical y t σ)) : + (Fintype.card ι:ℝ)*scalarPsi j (scalarEmpirical y t σ) ≤ + 3/(8*scalarS j (scalarEmpirical y t σ)) * + (∑ i, (y i-scalarD j (scalarEmpirical y t σ))^2)+3*(Fintype.card ι:ℝ)*j/2 := by + have hn : (0:ℝ) < Fintype.card ι := by exact_mod_cast (Fintype.card_pos (α := ι)) + have h := scalar_quadratic_envelope hj (scalarQMoment_bounds (empiricalLaw y)).1 + (scalarQMoment_bounds (empiricalLaw y)).2 hs (scalar_consistency (p := scalarEmpirical y t σ) ht) + (show 0 ≤ (Fintype.card ι:ℝ)⁻¹*∑ i, (y i-scalarD j (scalarEmpirical y t σ))^2 by positivity) + (empirical_scalar_cauchy y j t σ) + have hh := mul_le_mul_of_nonneg_left h hn.le + change (Fintype.card ι:ℝ)*scalarPsi j (scalarEmpirical y t σ) ≤ _ at hh + convert hh using 1 + field_simp + +lemma scalar_empirical_parameter_bounds (y : ι → ℝ) {j t σ T : ℝ} + (hj : 0 ≤ j) (ht : 0 ≤ t) (htT : t ≤ T) (hσ : 0 ≤ σ) (hσ1 : σ ≤ 1) : + |scalarD j (scalarEmpirical y t σ)| ≤ T+j ∧ scalarS j (scalarEmpirical y t σ) ≤ T+1+j := by + have hM := scalarM_bounds (empiricalLaw y) + have hq := (scalarQMoment_bounds (empiricalLaw y)).2 + constructor + · unfold scalarD scalarEmpirical + dsimp only + calc + |t+j*scalarM (empiricalLaw y)| ≤ |t|+|j*scalarM (empiricalLaw y)| := abs_add_le _ _ + _ ≤ T+j := by + rw [abs_of_nonneg ht, abs_mul, abs_of_nonneg hj] + nlinarith + · unfold scalarS scalarEmpirical + dsimp only + have hsq : σ^2 ≤ 1 := by nlinarith + nlinarith + +theorem scalar_integrand_envelope {j T smin : ℝ} (hj : 0 ≤ j) (hT : 0 ≤ T) (hsmin : 0 < smin) + (y : ι → ℝ) {t σ : ℝ} (ht : 0 ≤ t) (htT : t ≤ T) (hσ : 0 ≤ σ) (hσ1 : σ ≤ 1) + (hsl : smin ≤ scalarS j (scalarEmpirical y t σ)) : + scalarIntegrand j t σ y ≤ + exp ((Fintype.card ι:ℝ)*(|log (sqrt (2*Real.pi*smin))|+3*j/2+(T+j)^2/(8*smin))- + (1/(16*(T+1+j)))*∑ i, (y i)^2) := by + have hb := scalar_empirical_parameter_bounds y hj ht htT hσ hσ1 + have hd : (scalarD j (scalarEmpirical y t σ))^2 ≤ (T+j)^2 := by + have hD : 0 ≤ T+j := add_nonneg hT hj + have hsq := (sq_le_sq₀ (abs_nonneg _) hD).mpr hb.1 + simpa only [sq_abs] using hsq + exact gaussian_pointwise_envelope y hsmin hsl hb.2 hd + (scalar_empirical_quadratic_envelope y hj ht (hsmin.trans_le hsl)) + +theorem scalar_integrand_tail {j T smin : ℝ} (hj : 0 ≤ j) (hT : 0 ≤ T) (hsmin : 0 < smin) + (L : ℝ) : ∃ R > 0, ∀ t ∈ Icc 0 T, ∀ σ ∈ Icc 0 1, + ∀ E : Set (ι → ℝ), MeasurableSet E → + (∀ y ∈ E, smin ≤ scalarS j (scalarEmpirical y t σ)) → + (∀ y ∈ E, (Fintype.card ι:ℝ)*R ≤ ∑ i, (y i)^2) → + (∫⁻ y in E, ENNReal.ofReal (scalarIntegrand j t σ y)) ≤ + ENNReal.ofReal (exp (-L*(Fintype.card ι:ℝ))) := by + let c := 1/(16*(T+1+j)) + let C := |log (sqrt (2*Real.pi*smin))|+3*j/2+(T+j)^2/(8*smin) + have hc : 0 < c := by dsimp [c]; positivity + obtain ⟨R,hR,hrate⟩ := choose_quadratic_tail_radius (C := C) hc L + refine ⟨R,hR,?_⟩ + intro t ht σ hσ E hE hs htE + have he := quadratic_envelope_tail (C := C) hc hE (scalarIntegrand j t σ) + (fun y hy => scalar_integrand_envelope hj hT hsmin y ht.1 ht.2 hσ.1 hσ.2 (hs y hy)) htE + refine he.trans (ENNReal.ofReal_le_ofReal (exp_le_exp.mpr ?_)) + have h := mul_le_mul_of_nonneg_left hrate (show (0:ℝ) ≤ Fintype.card ι from Nat.cast_nonneg _) + nlinarith only [h] + +end SKGap + +namespace SKGap + +lemma empirical_momentBall {ι : Type*} [Fintype ι] [Nonempty ι] + (y : ι → ℝ) {R : ℝ} (_hR : 0 ≤ R) + (h : ∑ i, (y i)^2 ≤ (Fintype.card ι:ℝ)*R) : empiricalLaw y ∈ momentBall R := by + change (∫⁻ x : ℝ, ENNReal.ofReal (x^2) ∂empiricalLaw y) ≤ ENNReal.ofReal R + rw [← ofReal_integral_eq_lintegral_ofReal (integrable_empiricalLaw y _) (ae_of_all _ sq_nonneg)] + apply ENNReal.ofReal_le_ofReal + rw [integral_empiricalLaw] + have hn : (0:ℝ) < Fintype.card ι := by exact_mod_cast (Fintype.card_pos (α := ι)) + have hh := mul_le_mul_of_nonneg_left h (inv_nonneg.mpr hn.le) + simpa only [← mul_assoc, inv_mul_cancel₀ hn.ne', one_mul] using hh + +def scalarBox (j R T smin : ℝ) : Set ScalarPoint := + (momentBall R ×ˢ (Icc 0 T ×ˢ Icc 0 1)) ∩ {p | smin ≤ scalarS j p} + +lemma isCompact_scalarBox (j R T smin : ℝ) : IsCompact (scalarBox j R T smin) := + ((isCompact_momentBall R).prod (isCompact_Icc.prod isCompact_Icc)).inter_right + (isClosed_le continuous_const (continuous_scalarS j)) + +lemma scalar_compact_nonpositive {j R : ℝ} (hj : 0 < j) (hj1 : j < 1) (hR : 0 ≤ R) + {K : Set ScalarPoint} (hK : IsCompact K) (hmom : K ⊆ scalarMomentDomain R) + (ht : ∀ p ∈ K, 0 ≤ p.2.1) (hs : ∀ p ∈ K, 0 < scalarS j p) + {ε : ℝ} (hε : 0 < ε) : ∃ N : ℕ, ∀ n ≥ N, ∀ hn : 0 < n, + ∀ z : (Fin n → ℝ) → ScalarPoint, ∀ E : Set (Fin n → ℝ), MeasurableSet E → + (∀ y ∈ E, z y ∈ K) → + (∀ y ∈ E, (z y).1 = @empiricalLaw (Fin n) _ ⟨⟨0,hn⟩⟩ y) → + (∀ y ∈ E, ∑ i, (y i)^2 ≤ (n:ℝ)*R) → + (∫⁻ y in E, ENNReal.ofReal (exp ((n:ℝ)*scalarPsi j (z y))* + productNormal (scalarD j (z y)) (scalarS j (z y)) y)) ≤ ENNReal.ofReal (exp (ε*(n:ℝ))) := by + obtain ⟨N,hN⟩ := gaussian_compact_rate hK (P := fun p : ScalarPoint => p.1) + continuous_fst.continuousOn (continuous_scalarD j).continuousOn (continuous_scalarS j).continuousOn + (continuousOn_scalarPsi_of_pos hj.le hR hmom hs) hs R (ε/2) + (fun p hp => scalar_weak_test (hmom hp) hj hj1 (ht p hp) (hs p hp) (half_pos hε)) (half_pos hε) + refine ⟨N,?_⟩ + intro n hn hn' z E hE hz hemp hsum + convert hN n hn hn' z E hE hz hemp hsum using 1 + congr 1 + ring_nf + +theorem scalar_uniform_tail {j T smin : ℝ} (hj : 0 ≤ j) (hT : 0 ≤ T) (hsmin : 0 < smin) + (L : ℝ) : ∃ R > 0, ∀ n : ℕ, ∀ hn : 0 < n, + ∀ t ∈ Icc 0 T, ∀ σ ∈ Icc 0 1, ∀ E : Set (Fin n → ℝ), MeasurableSet E → + (∀ y ∈ E, smin ≤ scalarS j (@scalarEmpirical (Fin n) _ ⟨⟨0,hn⟩⟩ y t σ)) → + (∀ y ∈ E, (n:ℝ)*R ≤ ∑ i, (y i)^2) → + (∫⁻ y in E, ENNReal.ofReal (@scalarIntegrand (Fin n) _ ⟨⟨0,hn⟩⟩ j t σ y)) ≤ + ENNReal.ofReal (exp (-L*(n:ℝ))) := by + let c := 1/(16*(T+1+j)) + let C := |log (sqrt (2*Real.pi*smin))|+3*j/2+(T+j)^2/(8*smin) + have hc : 0 < c := by dsimp [c]; positivity + obtain ⟨R,hR,hrate⟩ := choose_quadratic_tail_radius (C := C) hc L + refine ⟨R,hR,?_⟩ + intro n hn t ht σ hσ E hE hs htE + let : Nonempty (Fin n) := ⟨⟨0,hn⟩⟩ + have he := quadratic_envelope_tail (C := C) hc hE (scalarIntegrand j t σ) + (fun y hy => scalar_integrand_envelope hj hT hsmin y ht.1 ht.2 hσ.1 hσ.2 (hs y hy)) + (by simpa only [Fintype.card_fin] using htE) + simp only [Fintype.card_fin] at he + refine he.trans (ENNReal.ofReal_le_ofReal (exp_le_exp.mpr ?_)) + have h := mul_le_mul_of_nonneg_left hrate (show (0:ℝ) ≤ n from Nat.cast_nonneg _) + nlinarith only [h] + +lemma lintegral_split_le {α : Type*} [MeasurableSpace α] (μ : Measure α) + (f : α → ℝ≥0∞) (E B : Set α) : + (∫⁻ x in E, f x ∂μ) ≤ (∫⁻ x in E ∩ B, f x ∂μ)+(∫⁻ x in E ∩ Bᶜ, f x ∂μ) := by + have h : E = (E ∩ B) ∪ (E ∩ Bᶜ) := by aesop + conv_lhs => rw [h] + exact lintegral_union_le _ _ _ + +theorem scalar_unrestricted_rate {j T smin : ℝ} (hj : 0 < j) (hj1 : j < 1) + (hT : 0 ≤ T) (hsmin : 0 < smin) {ε : ℝ} (hε : 0 < ε) : + ∃ N : ℕ, ∀ n ≥ N, ∀ hn : 0 < n, ∀ t ∈ Icc 0 T, ∀ σ ∈ Icc 0 1, + ∀ E : Set (Fin n → ℝ), MeasurableSet E → + (∀ y ∈ E, smin ≤ scalarS j (@scalarEmpirical (Fin n) _ ⟨⟨0,hn⟩⟩ y t σ)) → + (∫⁻ y in E, ENNReal.ofReal (@scalarIntegrand (Fin n) _ ⟨⟨0,hn⟩⟩ j t σ y)) ≤ + ENNReal.ofReal (exp (ε*(n:ℝ))) := by + obtain ⟨R,hR,hTail⟩ := scalar_uniform_tail hj.le hT hsmin 1 + have hbox : scalarBox j R T smin ⊆ scalarMomentDomain R := fun p hp => ⟨hp.1.1,mem_univ _⟩ + obtain ⟨N,hN⟩ := scalar_compact_nonpositive hj hj1 hR.le (isCompact_scalarBox j R T smin) + hbox (fun p hp => hp.1.2.1.1) (fun p hp => hsmin.trans_le hp.2) (half_pos hε) + obtain ⟨M,hM⟩ := absorb_finite_exponential_factor 2 (half_pos hε) + refine ⟨max N M,?_⟩ + intro n hn hn' t ht σ hσ E hE hs + let : Nonempty (Fin n) := ⟨⟨0,hn'⟩⟩ + let B : Set (Fin n → ℝ) := {y | ∑ i, (y i)^2 ≤ (n:ℝ)*R} + have hB : MeasurableSet B := isClosed_le (by fun_prop) continuous_const |>.measurableSet + have hc := hN n (le_trans (le_max_left _ _) hn) hn' (fun y => scalarEmpirical y t σ) + (E ∩ B) (hE.inter hB) (fun y hy => ⟨⟨empirical_momentBall y hR.le + (by simpa only [Fintype.card_fin] using (show ∑ i, (y i)^2 ≤ (n:ℝ)*R from hy.2)),ht,hσ⟩,hs y hy.1⟩) + (fun _ _ => rfl) (fun _ hy => hy.2) + have hc' : (∫⁻ y in E ∩ B, ENNReal.ofReal (scalarIntegrand j t σ y)) ≤ + ENNReal.ofReal (exp ((ε/2)*(n:ℝ))) := by + simpa only [scalarIntegrand, Fintype.card_fin] using hc + have htail := hTail n hn' t ht σ hσ (E ∩ Bᶜ) (hE.inter hB.compl) + (fun y hy => hs y hy.1) (fun y hy => le_of_lt (not_le.mp hy.2)) + have he : exp (-(1:ℝ)*(n:ℝ)) ≤ exp ((ε/2)*(n:ℝ)) := + exp_le_exp.mpr (by nlinarith [Nat.cast_nonneg (α := ℝ) n]) + have htotal := (lintegral_split_le volume (fun y => ENNReal.ofReal (scalarIntegrand j t σ y)) E B).trans + (add_le_add hc' (htail.trans (ENNReal.ofReal_le_ofReal he))) + have hadd : ENNReal.ofReal (exp ((ε/2)*(n:ℝ)))+ENNReal.ofReal (exp ((ε/2)*(n:ℝ))) = + ENNReal.ofReal (2*exp ((n:ℝ)*(ε/2))) := by + rw [← ENNReal.ofReal_add (exp_pos _).le (exp_pos _).le] + congr 1 + ring_nf + rw [hadd] at htotal + refine htotal.trans (ENNReal.ofReal_le_ofReal ?_) + convert hM n (le_trans (le_max_right _ _) hn) (ε/2) using 1 + congr 1 + ring + +end SKGap + +end +end +end +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/ScalarFixedPointJoined.lean b/lean/OAI/Probability/SKGap/Localization/ScalarFixedPointJoined.lean new file mode 100644 index 0000000000000000000000000000000000000000..2303ba9eb3d98f91b8f90bd1f8d342eb6ff2a30e --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/ScalarFixedPointJoined.lean @@ -0,0 +1,569 @@ +import Mathlib +import OAI.Probability.SKGap.Gaussian.StandardGaussianProduct +import OAI.Probability.SKGap.Localization.ScalarParametersJoined + +namespace OAI + +section + +noncomputable section +open MeasureTheory ProbabilityTheory InformationTheory Real Set +open scoped NNReal ENNReal +namespace SKGap + +theorem integrable_tanh {P : Measure ℝ} [IsFiniteMeasure P] : Integrable tanh P := by + apply Integrable.of_bound continuous_tanh.aestronglyMeasurable 1 + exact ae_of_all _ (fun y => by simpa using (abs_tanh_lt_one y).le) + +theorem integrable_tanh_sq {P : Measure ℝ} [IsFiniteMeasure P] : + Integrable (fun y => tanh y ^ 2) P := by + apply Integrable.of_bound (by fun_prop) 1 + exact ae_of_all _ (fun y => by simpa only [Real.norm_eq_abs, abs_of_nonneg (sq_nonneg (tanh y))] + using (tanh_sq_lt_one y).le) + +def oddVariance (y : ℝ) : ℝ := tanh y * (1 - tanh y^2) + +lemma abs_oddVariance_le_one (y : ℝ) : |oddVariance y| ≤ 1 := by + have ht := (abs_tanh_lt_one y).le + have hs := (tanh_sq_lt_one y).le + dsimp [oddVariance] + rw [abs_mul, abs_of_nonneg (sub_nonneg.mpr hs)] + exact (mul_le_mul_of_nonneg_right ht (sub_nonneg.mpr hs)).trans (by nlinarith [sq_nonneg (tanh y)]) + +lemma integrable_oddVariance {P : Measure ℝ} [IsFiniteMeasure P] : + Integrable oddVariance P := by + apply Integrable.of_bound (by unfold oddVariance; fun_prop) 1 + exact ae_of_all _ (fun y => by simpa using abs_oddVariance_le_one y) + +lemma gaussianPDFReal_diagonal_factor {s : ℝ≥0} (hs : s ≠ 0) (y : ℝ) : + gaussianPDFReal s s y = + (1 / sqrt (2*π*s) * exp (-y^2/(2*s) - s/2)) * exp y := by + have hs' : (s : ℝ) ≠ 0 := NNReal.coe_ne_zero.mpr hs + have he : -(y-(s:ℝ))^2/(2*s) = (-y^2/(2*s)-s/2)+y := by + field_simp + ring + rw [gaussianPDFReal, he, exp_add] + ring + +lemma gaussianPDFReal_diagonal_symmetry {s : ℝ≥0} (hs : s ≠ 0) (y : ℝ) : + gaussianPDFReal s s y - gaussianPDFReal s s (-y) = + tanh y * (gaussianPDFReal s s y + gaussianPDFReal s s (-y)) := by + rw [gaussianPDFReal_diagonal_factor hs y, gaussianPDFReal_diagonal_factor hs (-y)] + rw [neg_sq, tanh_eq] + have he : exp y + exp (-y) ≠ 0 := (add_pos (exp_pos _) (exp_pos _)).ne' + field_simp + +theorem gaussian_nishimori (s : ℝ≥0) : + (∫ y, tanh y ∂gaussianReal s s) = (∫ y, tanh y^2 ∂gaussianReal s s) := by + by_cases hs : s = 0 + · subst s + simp + have hi := (integrable_gaussian_iff hs).mp + (integrable_tanh.sub (integrable_tanh_sq (P := gaussianReal s s))) + set f : ℝ → ℝ := fun y => gaussianPDFReal s s y * (tanh y - tanh y^2) + have hf : Integrable f := hi + have hid (y : ℝ) : f y + f (-y) = 0 := by + have hh := gaussianPDFReal_diagonal_symmetry hs y + dsimp [f] + rw [tanh_neg, neg_sq] + nlinarith [congrArg (fun x => tanh y * x) hh] + have hz : (∫ y, f y) + ∫ y, f (-y) = 0 := by + rw [← integral_add hf hf.comp_neg] + simp only [hid, integral_zero] + rw [integral_neg_eq_self] at hz + have h0 : ∫ y, f y = 0 := by linarith + have hsub : ∫ y, tanh y - tanh y^2 ∂gaussianReal s s = 0 := by + rw [integral_gaussianReal_eq_integral_smul hs] + exact h0 + rw [integral_sub integrable_tanh integrable_tanh_sq] at hsub + exact sub_eq_zero.mp hsub + +lemma tanh_nonneg_of_nonneg {x : ℝ} (hx : 0 ≤ x) : 0 ≤ tanh x := by + rw [tanh_eq] + exact div_nonneg (sub_nonneg.mpr (exp_le_exp.mpr (by linarith))) (by positivity) + +lemma tanh_nonpos_of_nonpos {x : ℝ} (hx : x ≤ 0) : tanh x ≤ 0 := by + rw [tanh_eq] + exact div_nonpos_of_nonpos_of_nonneg (sub_nonpos.mpr (exp_le_exp.mpr (by linarith))) (by positivity) + +lemma gaussianPDFReal_reflection_le {d : ℝ} (hd : 0 ≤ d) (s : ℝ≥0) + {y : ℝ} (hy : 0 ≤ y) : gaussianPDFReal d s (-y) ≤ gaussianPDFReal d s y := by + unfold gaussianPDFReal + apply mul_le_mul_of_nonneg_left _ (by positivity) + apply exp_le_exp.mpr + apply div_le_div_of_nonneg_right _ (by positivity) + nlinarith + +theorem gaussian_odd_sign {d : ℝ} (hd : 0 ≤ d) (s : ℝ≥0) : + 0 ≤ ∫ y, oddVariance y ∂gaussianReal d s := by + by_cases hs : s = 0 + · subst s + simp only [gaussianReal_zero_var, integral_dirac] + exact mul_nonneg (tanh_nonneg_of_nonneg hd) (sub_nonneg.mpr (tanh_sq_lt_one d).le) + have hi := (integrable_gaussian_iff hs).mp (integrable_oddVariance (P := gaussianReal d s)) + set f : ℝ → ℝ := fun y => gaussianPDFReal d s y * oddVariance y + have hf : Integrable f := hi + have hodd (y : ℝ) : oddVariance (-y) = -oddVariance y := by + simp [oddVariance, tanh_neg] + have hid (y : ℝ) : 0 ≤ f y + f (-y) := by + have he : f y + f (-y) = (gaussianPDFReal d s y - gaussianPDFReal d s (-y)) * oddVariance y := by + dsimp [f]; rw [hodd]; ring + rw [he] + by_cases hy : 0 ≤ y + · exact mul_nonneg (sub_nonneg.mpr (gaussianPDFReal_reflection_le hd s hy)) + (mul_nonneg (tanh_nonneg_of_nonneg hy) (sub_nonneg.mpr (tanh_sq_lt_one y).le)) + · have hy' : 0 ≤ -y := by linarith + have hp := gaussianPDFReal_reflection_le hd s hy' + rw [neg_neg] at hp + apply mul_nonneg_of_nonpos_of_nonpos (sub_nonpos.mpr hp) + exact mul_nonpos_of_nonpos_of_nonneg (tanh_nonpos_of_nonpos (le_of_not_ge hy)) + (sub_nonneg.mpr (tanh_sq_lt_one y).le) + have hn := MeasureTheory.integral_nonneg (μ := volume) (f := fun y : ℝ => f y + f (-y)) hid + rw [integral_add hf hf.comp_neg, integral_neg_eq_self] at hn + rw [integral_gaussianReal_eq_integral_smul hs] + change 0 ≤ ∫ y, f y + linarith + +end SKGap + +namespace SKGap +open Filter +open scoped Topology + +lemma gaussianAverage_hasDerivAt_mean {f f' : ℝ → ℝ} (hf : Continuous f) (hf' : Continuous f') + (hd : ∀ y, HasDerivAt f (f' y) y) {C C' : ℝ} + (hb : ∀ y, ‖f y‖ ≤ C) (hb' : ∀ y, ‖f' y‖ ≤ C') (d s : ℝ) : + HasDerivAt (fun d => gaussianAverage f d s) (gaussianAverage f' d s) d := by + exact (hasDerivAt_integral_of_dominated_loc_of_deriv_le + (μ := gaussianReal 0 1) (s := univ) (x₀ := d) + (F := fun d x => f (d+sqrt s*x)) (F' := fun d x => f' (d+sqrt s*x)) + (bound := fun _ => C') univ_mem + (Eventually.of_forall (fun d => (by fun_prop : Continuous (fun x : ℝ => f (d+sqrt s*x))).aestronglyMeasurable)) + (integrable_gaussian_comp_of_bound hf hb d s) + (by fun_prop) + (ae_of_all _ (fun x d _ => hb' _)) + (integrable_const _) + (ae_of_all _ (fun x d _ => by + convert! (hd (d+sqrt s*x)).comp d ((hasDerivAt_id d).add_const (sqrt s*x)) using 1 + simp))).2 + +lemma gaussianAverage_tanh_mean_deriv (d s : ℝ) : + HasDerivAt (fun d => gaussianAverage tanh d s) + (gaussianAverage (fun y => 1-tanh y^2) d s) d := by + apply gaussianAverage_hasDerivAt_mean continuous_tanh (by fun_prop) hasDerivAt_tanh + (C := 1) (C' := 1) + · intro y; simpa using (abs_tanh_lt_one y).le + · intro y + rw [Real.norm_eq_abs, abs_le] + constructor <;> nlinarith [tanh_sq_lt_one y, sq_nonneg (tanh y)] + +lemma gaussianAverage_tanh_diff_deriv (d s : ℝ) : + HasDerivAt (fun d => gaussianAverage (fun y => tanh y-tanh y^2) d s) + (gaussianAverage (fun y => (1-tanh y^2)*(1-2*tanh y)) d s) d := by + apply gaussianAverage_hasDerivAt_mean (by fun_prop) (by fun_prop) + (C := 2) (C' := 3) + · intro y + convert! (hasDerivAt_tanh y).sub ((hasDerivAt_tanh y).pow 2) using 1 + ring + · intro y + calc + ‖tanh y-tanh y^2‖ ≤ ‖tanh y‖+‖tanh y^2‖ := norm_sub_le _ _ + _ ≤ 2 := by + rw [Real.norm_eq_abs, Real.norm_eq_abs, abs_of_nonneg (sq_nonneg (tanh y))] + linarith [(abs_tanh_lt_one y).le, (tanh_sq_lt_one y).le] + · intro y + rw [norm_mul] + have h1 : ‖1-tanh y^2‖ ≤ 1 := by + rw [Real.norm_eq_abs, abs_le]; constructor <;> nlinarith [tanh_sq_lt_one y, sq_nonneg (tanh y)] + have h2 : ‖1-2*tanh y‖ ≤ 3 := by + have ht := (abs_le.mp (abs_tanh_lt_one y).le) + rw [Real.norm_eq_abs, abs_le]; constructor <;> linarith + exact (mul_le_mul h1 h2 (norm_nonneg _) (by norm_num)).trans_eq (by norm_num) + +end SKGap + +namespace SKGap +open Filter +open scoped Topology + +def gaussianF (s : ℝ) : ℝ := gaussianAverage tanh s s + +lemma gaussianF_zero : gaussianF 0 = 0 := by simp [gaussianF, gaussianAverage] + +lemma continuous_gaussianF : Continuous gaussianF := + (continuous_gaussianAverage continuous_tanh + (fun y => by simpa using (abs_tanh_lt_one y).le)).comp (continuous_id.prodMk continuous_id) + +lemma gaussianF_eq_square {s : ℝ} (hs : 0 ≤ s) : + gaussianF s = gaussianAverage (fun y => tanh y^2) s s := by + rw [gaussianF, gaussianAverage_eq_integral continuous_tanh s hs, + gaussianAverage_eq_integral (by fun_prop) s hs] + convert gaussian_nishimori s.toNNReal using 1 <;> rw [Real.coe_toNNReal _ hs] + +lemma gaussianF_nonneg {s : ℝ} (hs : 0 ≤ s) : 0 ≤ gaussianF s := by + rw [gaussianF_eq_square hs] + exact MeasureTheory.integral_nonneg (f := fun x => tanh (s+sqrt s*x)^2) (fun x => sq_nonneg _) + +lemma gaussianF_raw_deriv {s : ℝ} (hs : 0 < s) : + HasDerivAt gaussianF + (∫ x, (1-tanh (s+sqrt s*x)^2)*(1+x/(2*sqrt s)) ∂gaussianReal 0 1) s := by + let bound : ℝ → ℝ := fun x => 1+|x|/(2*sqrt (s/2)) + have hb : Integrable bound (gaussianReal 0 1) := + (integrable_const 1).add ((IsGaussian.integrable_id (μ := gaussianReal 0 1)).abs.div_const _) + have hnorm (t x : ℝ) (ht : t ∈ Ioi (s/2)) : + ‖(1-tanh (t+sqrt t*x)^2)*(1+x/(2*sqrt t))‖ ≤ bound x := by + have ht0 : 0 < t := lt_trans (half_pos hs) ht + have hsqrt : 0 < sqrt (s/2) := sqrt_pos.2 (half_pos hs) + have htqrt : 0 < sqrt t := sqrt_pos.2 ht0 + have h1 : |1-tanh (t+sqrt t*x)^2| ≤ 1 := by + rw [abs_le]; constructor <;> nlinarith [tanh_sq_lt_one (t+sqrt t*x), sq_nonneg (tanh (t+sqrt t*x))] + rw [Real.norm_eq_abs, abs_mul] + calc + _ ≤ 1*|1+x/(2*sqrt t)| := mul_le_mul_of_nonneg_right h1 (abs_nonneg _) + _ ≤ 1+|x|/(2*sqrt t) := by + simpa only [one_mul, abs_one, abs_div, abs_of_pos (mul_pos (by norm_num : (0:ℝ)<2) htqrt)] using abs_add_le (1:ℝ) (x/(2*sqrt t)) + _ ≤ bound x := by + dsimp [bound] + gcongr + exact ht.le + have hder (t x : ℝ) (ht : t ∈ Ioi (s/2)) : + HasDerivAt (fun t => tanh (t+sqrt t*x)) + ((1-tanh (t+sqrt t*x)^2)*(1+x/(2*sqrt t))) t := by + have ht0 : 0 < t := lt_trans (half_pos hs) ht + convert! (hasDerivAt_tanh (t+sqrt t*x)).comp t + ((hasDerivAt_id t).add ((hasDerivAt_sqrt ht0.ne').mul_const x)) using 1 + ring + exact (hasDerivAt_integral_of_dominated_loc_of_deriv_le + (μ := gaussianReal 0 1) (s := Ioi (s/2)) (x₀ := s) + (F := fun t x => tanh (t+sqrt t*x)) + (F' := fun t x => (1-tanh (t+sqrt t*x)^2)*(1+x/(2*sqrt t))) + (bound := bound) (Ioi_mem_nhds (half_lt_self hs)) + (Eventually.of_forall (fun t => (by fun_prop : Continuous (fun x : ℝ => tanh (t+sqrt t*x))).aestronglyMeasurable)) + (integrable_gaussian_comp_of_bound continuous_tanh (fun y => by simpa using (abs_tanh_lt_one y).le) s s) + (by fun_prop) + (ae_of_all _ (fun x t ht => hnorm t x ht)) hb + (ae_of_all _ (fun x t ht => hder t x ht))).2 + +lemma gaussian_diagonal_stein (s : ℝ) : + (∫ x, x*(1-tanh (s+sqrt s*x)^2) ∂gaussianReal 0 1) = + -2*sqrt s * (∫ x, oddVariance (s+sqrt s*x) ∂gaussianReal 0 1) := by + have hv (x : ℝ) : ‖1-tanh (s+sqrt s*x)^2‖ ≤ 1 := by + rw [Real.norm_eq_abs, abs_le] + constructor <;> nlinarith [tanh_sq_lt_one (s+sqrt s*x), sq_nonneg (tanh (s+sqrt s*x))] + have hi : Integrable (fun x => 1-tanh (s+sqrt s*x)^2) (gaussianReal 0 1) := + Integrable.of_bound (by fun_prop) 1 (ae_of_all _ hv) + have hid : Integrable (fun x => -2*sqrt s*oddVariance (s+sqrt s*x)) (gaussianReal 0 1) := + (integrable_gaussian_comp_of_bound (by unfold oddVariance; fun_prop) + (fun y => by simpa using abs_oddVariance_le_one y) s s).const_mul _ + have hxi : Integrable (fun x => (x-0)*(1-tanh (s+sqrt s*x)^2)) (gaussianReal 0 1) := by + simpa only [sub_zero, id_eq] using + (IsGaussian.integrable_id (μ := gaussianReal 0 1)).mul_bdd (c := 1) (by fun_prop) (ae_of_all _ hv) + have hd (x : ℝ) : HasDerivAt (fun x => 1-tanh (s+sqrt s*x)^2) + (-2*sqrt s*oddVariance (s+sqrt s*x)) x := by + convert! (((hasDerivAt_tanh (s+sqrt s*x)).comp x + (((hasDerivAt_id x).const_mul (sqrt s)).const_add s)).pow 2).const_sub 1 using 1 + dsimp [oddVariance] + ring + have h := gaussian_integration_by_parts (d := 0) (s := 1) (by norm_num) hd hi hid hxi + simpa only [sub_zero, NNReal.coe_one, one_mul, integral_const_mul] using h + +lemma gaussianF_deriv {s : ℝ} (hs : 0 < s) : + HasDerivAt gaussianF (gaussianAverage (fun y => (1-tanh y^2)*(1-tanh y)) s s) s := by + have h := gaussianF_raw_deriv hs + convert! h using 1 + have hi := integrable_gaussian_comp_of_bound (f := fun y => 1-tanh y^2) (by fun_prop) + (C := 1) (fun y => by + rw [Real.norm_eq_abs, abs_le]; constructor <;> nlinarith [tanh_sq_lt_one y, sq_nonneg (tanh y)]) s s + have ho := integrable_gaussian_comp_of_bound (f := oddVariance) (by unfold oddVariance; fun_prop) + (C := 1) (fun y => by simpa using abs_oddVariance_le_one y) s s + have hxi : Integrable (fun x => x*(1-tanh (s+sqrt s*x)^2)) (gaussianReal 0 1) := + (IsGaussian.integrable_id (μ := gaussianReal 0 1)).mul_bdd (c := 1) (by fun_prop) + (ae_of_all _ (fun x => by + rw [Real.norm_eq_abs, abs_le]; constructor <;> nlinarith [tanh_sq_lt_one (s+sqrt s*x), sq_nonneg (tanh (s+sqrt s*x))])) + have h1 : gaussianAverage (fun y => (1-tanh y^2)*(1-tanh y)) s s = + (∫ x, 1-tanh (s+sqrt s*x)^2 ∂gaussianReal 0 1) - + ∫ x, oddVariance (s+sqrt s*x) ∂gaussianReal 0 1 := by + rw [← integral_sub hi ho] + apply integral_congr_ae + exact ae_of_all _ (fun x => by dsimp [oddVariance]; ring) + rw [h1] + have he (x : ℝ) : (1-tanh (s+sqrt s*x)^2)*(1+x/(2*sqrt s)) = + (1-tanh (s+sqrt s*x)^2) + (x*(1-tanh (s+sqrt s*x)^2))/(2*sqrt s) := by ring + simp_rw [he] + rw [integral_add hi (hxi.div_const _), integral_div, gaussian_diagonal_stein] + field_simp + ring + +lemma gaussianF_derivative_bounds {s : ℝ} (hs : 0 ≤ s) : + 0 ≤ gaussianAverage (fun y => (1-tanh y^2)*(1-tanh y)) s s ∧ + gaussianAverage (fun y => (1-tanh y^2)*(1-tanh y)) s s ≤ 1 := by + have hm (y : ℝ) : 0 ≤ (1-tanh y^2)*(1-tanh y) := + mul_nonneg (sub_nonneg.mpr (tanh_sq_lt_one y).le) + (sub_nonneg.mpr (le_trans (le_abs_self _) (abs_tanh_lt_one y).le)) + constructor + · exact MeasureTheory.integral_nonneg (f := fun x => (1-tanh (s+sqrt s*x)^2)*(1-tanh (s+sqrt s*x))) (fun x => hm _) + · rw [gaussianAverage_eq_integral (by fun_prop) s hs] + have he (y : ℝ) : (1-tanh y^2)*(1-tanh y) = (1-tanh y^2)-oddVariance y := by + dsimp [oddVariance]; ring + simp_rw [he] + rw [integral_sub (f := fun y => 1-tanh y^2) (g := oddVariance) + ((integrable_const 1).sub (integrable_tanh_sq (P := gaussianReal s s.toNNReal))) + integrable_oddVariance, + integral_sub (integrable_const 1) (integrable_tanh_sq (P := gaussianReal s s.toNNReal)), integral_const] + simp only [probReal_univ, smul_eq_mul, one_mul] + have ho := gaussian_odd_sign hs s.toNNReal + have hq : 0 ≤ ∫ y, tanh y^2 ∂gaussianReal s s.toNNReal := + MeasureTheory.integral_nonneg (f := fun y => tanh y^2) (fun y => sq_nonneg _) + linarith + +end SKGap + +namespace SKGap +open Filter +open scoped Topology + +lemma gaussianF_lipschitz : LipschitzOnWith 1 gaussianF (Ici 0) := by + have h : LipschitzOnWith 1 gaussianF (Ioi 0) := + Convex.lipschitzOnWith_of_nnnorm_deriv_le + (fun s hs => (gaussianF_deriv hs).differentiableAt) + (fun s hs => by + rw [(gaussianF_deriv hs).deriv] + have hb := gaussianF_derivative_bounds hs.le + exact_mod_cast (show ‖gaussianAverage (fun y => (1-tanh y^2)*(1-tanh y)) s s‖ ≤ 1 by + rw [Real.norm_eq_abs, abs_of_nonneg hb.1]; exact hb.2)) + (convex_Ioi 0) + simpa only [closure_Ioi] using LipschitzOnWith.closure continuous_gaussianF.continuousOn h + +lemma gaussianF_le_self {s : ℝ} (hs : 0 ≤ s) : gaussianF s ≤ s := by + have h := gaussianF_lipschitz.dist_le_mul s hs 0 (by simp) + rw [gaussianF_zero, dist_zero_right, NNReal.coe_one, one_mul, dist_zero_right, + Real.norm_eq_abs, abs_of_nonneg (gaussianF_nonneg hs), Real.norm_eq_abs, abs_of_nonneg hs] at h + exact h + +lemma gaussianF_le_one {s : ℝ} (hs : 0 ≤ s) : gaussianF s ≤ 1 := by + rw [gaussianF_eq_square hs, gaussianAverage_eq_integral (by fun_prop) s hs] + have h := integral_mono (integrable_tanh_sq (P := gaussianReal s s.toNNReal)) (integrable_const 1) + (fun y => (tanh_sq_lt_one y).le) + simpa using h + +lemma gaussian_mean_lipschitz (s : ℝ) : LipschitzWith 1 (fun d => gaussianAverage tanh d s) := by + apply lipschitzWith_of_nnnorm_deriv_le + (fun d => (gaussianAverage_tanh_mean_deriv d s).differentiableAt) + intro d + rw [(gaussianAverage_tanh_mean_deriv d s).deriv] + have hm (y : ℝ) : 0 ≤ 1-tanh y^2 ∧ 1-tanh y^2 ≤ 1 := + ⟨sub_nonneg.mpr (tanh_sq_lt_one y).le, by nlinarith [sq_nonneg (tanh y)]⟩ + have hlo : 0 ≤ gaussianAverage (fun y => 1-tanh y^2) d s := + MeasureTheory.integral_nonneg (f := fun x => 1-tanh (d+sqrt s*x)^2) (fun x => (hm _).1) + have hhi : gaussianAverage (fun y => 1-tanh y^2) d s ≤ 1 := by + have hi := integrable_gaussian_comp_of_bound (f := fun y => 1-tanh y^2) (by fun_prop) + (C := 1) (fun y => by rw [Real.norm_eq_abs, abs_of_nonneg (hm y).1]; exact (hm y).2) d s + have h := integral_mono hi (integrable_const 1) (fun x => (hm _).2) + simpa [gaussianAverage] using h + exact_mod_cast (show ‖gaussianAverage (fun y => 1-tanh y^2) d s‖ ≤ 1 by + rw [Real.norm_eq_abs, abs_of_nonneg hlo]; exact hhi) + +lemma gaussian_mean_zero (s : ℝ) : gaussianAverage tanh 0 s = 0 := by + have hn : HasLaw (fun x : ℝ => -x) (gaussianReal 0 1) (gaussianReal 0 1) := by + simpa only [neg_zero, Pi.neg_def, id_eq] using gaussianReal_neg (HasLaw.id (μ := gaussianReal 0 1)) + have h := hn.integral_comp (f := fun x => tanh (sqrt s*x)) (by fun_prop) + simp only [Function.comp_def, mul_neg, tanh_neg, integral_neg] at h + dsimp [gaussianAverage] + simp only [zero_add] + linarith + +lemma gaussian_mean_fixed_nonneg {j t d s : ℝ} (hj : 0 < j) (hj1 : j < 1) (ht : 0 ≤ t) + (hd : d = t+j*gaussianAverage tanh d s) : 0 ≤ d := by + by_contra hh + have hdneg : d < 0 := lt_of_not_ge hh + have h := (gaussian_mean_lipschitz s).dist_le_mul d 0 + rw [gaussian_mean_zero, dist_zero_right, NNReal.coe_one, one_mul, dist_zero_right, + Real.norm_eq_abs, Real.norm_eq_abs, abs_of_neg hdneg] at h + have hm := (abs_le.mp h).1 + have hmul := mul_le_mul_of_nonneg_left hm hj.le + nlinarith + +lemma gaussian_H_derivative_bounds {d s : ℝ} (hd : 0 ≤ d) (hs : 0 ≤ s) : + -1 ≤ gaussianAverage (fun y => (1-tanh y^2)*(1-2*tanh y)) d s ∧ + gaussianAverage (fun y => (1-tanh y^2)*(1-2*tanh y)) d s ≤ 1 := by + rw [gaussianAverage_eq_integral (by fun_prop) d hs] + have he (y : ℝ) : (1-tanh y^2)*(1-2*tanh y) = (1-tanh y^2)-2*oddVariance y := by + dsimp [oddVariance]; ring + have hi : Integrable (fun y => (1-tanh y^2)*(1-2*tanh y)) (gaussianReal d s.toNNReal) := by + simp_rw [he] + exact ((integrable_const 1).sub integrable_tanh_sq).sub (integrable_oddVariance.const_mul 2) + constructor + · have hp (y : ℝ) : -1 ≤ (1-tanh y^2)*(1-2*tanh y) := by + have hm := (abs_le.mp (abs_tanh_lt_one y).le) + have hv : 0 ≤ 1-tanh y^2 := sub_nonneg.mpr (tanh_sq_lt_one y).le + have h1 : -1 ≤ 1-2*tanh y := by linarith + have h2 := mul_le_mul_of_nonneg_left h1 hv + nlinarith [sq_nonneg (tanh y)] + have h := integral_mono (integrable_const (-1)) hi hp + simpa using h + · simp_rw [he] + rw [integral_sub (f := fun y => 1-tanh y^2) (g := fun y => 2*oddVariance y) + ((integrable_const 1).sub (integrable_tanh_sq (P := gaussianReal d s.toNNReal))) + (integrable_oddVariance.const_mul 2), + integral_sub (integrable_const 1) (integrable_tanh_sq (P := gaussianReal d s.toNNReal)), + integral_const_mul, integral_const] + simp only [probReal_univ, smul_eq_mul, one_mul] + have ho := gaussian_odd_sign hd s.toNNReal + have hq : 0 ≤ ∫ y, tanh y^2 ∂gaussianReal d s.toNNReal := + MeasureTheory.integral_nonneg (f := fun y => tanh y^2) (fun y => sq_nonneg _) + linarith + +lemma gaussian_H_lipschitz {s : ℝ} (hs : 0 ≤ s) : + LipschitzOnWith 1 (fun d => gaussianAverage (fun y => tanh y-tanh y^2) d s) (Ici 0) := by + apply Convex.lipschitzOnWith_of_nnnorm_deriv_le + (fun d _ => (gaussianAverage_tanh_diff_deriv d s).differentiableAt) _ (convex_Ici 0) + intro d hd + rw [(gaussianAverage_tanh_diff_deriv d s).deriv] + exact_mod_cast (show ‖gaussianAverage (fun y => (1-tanh y^2)*(1-2*tanh y)) d s‖ ≤ 1 by + rw [Real.norm_eq_abs, abs_le]; exact gaussian_H_derivative_bounds hd hs) + +lemma gaussian_H_diagonal_zero {s : ℝ} (hs : 0 ≤ s) : + gaussianAverage (fun y => tanh y-tanh y^2) s s = 0 := by + rw [gaussianAverage_eq_integral (by fun_prop) s hs, + integral_sub integrable_tanh integrable_tanh_sq] + have he := gaussian_nishimori s.toNNReal + rw [Real.coe_toNNReal _ hs] at he + exact sub_eq_zero.mpr he + +lemma consistent_gaussian_diagonal {j t d : ℝ} {s : ℝ≥0} + (hj : 0 < j) (hj1 : j < 1) (ht : 0 ≤ t) + (hd : d = t+j*(∫ y, tanh y ∂gaussianReal d s)) + (hs : (s:ℝ) = t+j*(∫ y, tanh y^2 ∂gaussianReal d s)) : d = s := by + have he (f : ℝ → ℝ) (hf : Continuous f) : gaussianAverage f d s = ∫ y, f y ∂gaussianReal d s := by + simpa only [Real.toNNReal_coe] using gaussianAverage_eq_integral hf d s.coe_nonneg + have hd0 := gaussian_mean_fixed_nonneg hj hj1 ht (hd.trans (by rw [he tanh continuous_tanh])) + have h := (gaussian_H_lipschitz s.coe_nonneg).dist_le_mul d hd0 s s.coe_nonneg + rw [gaussian_H_diagonal_zero s.coe_nonneg, dist_zero_right, NNReal.coe_one, one_mul, + Real.norm_eq_abs, Real.dist_eq] at h + have hdiff : d-(s:ℝ) = j*gaussianAverage (fun y => tanh y-tanh y^2) d s := by + rw [he _ (by fun_prop), integral_sub integrable_tanh integrable_tanh_sq] + linarith + have ha := congrArg abs hdiff + rw [abs_mul, abs_of_pos hj] at ha + have hh : |gaussianAverage (fun y => tanh y-tanh y^2) d s| = 0 := by + nlinarith [abs_nonneg (gaussianAverage (fun y => tanh y-tanh y^2) d s)] + have hz := abs_eq_zero.mp hh + rw [hz, mul_zero] at hdiff + exact sub_eq_zero.mp hdiff + +end SKGap + +namespace SKGap + +lemma gaussianF_pos {s : ℝ} (hs : 0 < s) : 0 < gaussianF s := by + rw [gaussianF_eq_square hs.le, gaussianAverage_eq_integral (by fun_prop) s hs.le] + have hv : s.toNNReal ≠ 0 := by exact_mod_cast (show 0 < s.toNNReal from Real.toNNReal_pos.mpr hs).ne' + have := nullSingletonClass_gaussianReal (μ := s) hv + have hsupp : Function.support (fun y : ℝ => tanh y ^ 2) = ({0} : Set ℝ)ᶜ := by + ext y + simp only [Function.mem_support, mem_compl_iff, mem_singleton_iff, ne_eq, sq_eq_zero_iff] + have he : tanh y = 0 ↔ y = 0 := by + simpa only [tanh_zero] using (show tanh y = tanh 0 ↔ y = 0 from tanh_injective.eq_iff) + exact not_congr he + rw [integral_pos_iff_support_of_nonneg (fun y => sq_nonneg (tanh y)) integrable_tanh_sq, + hsupp, measure_compl (measurableSet_singleton 0) (by simp)] + simp + +lemma gaussian_fixed_unique {j t s r : ℝ} (hj : 0 < j) (hj1 : j < 1) + (hs : 0 ≤ s) (hr : 0 ≤ r) (hes : s = t+j*gaussianF s) + (her : r = t+j*gaussianF r) : s = r := by + have h := gaussianF_lipschitz.dist_le_mul s hs r hr + simp only [NNReal.coe_one, one_mul, Real.dist_eq] at h + have he : |s-r| = j*|gaussianF s-gaussianF r| := by + have he' : s-r = j*(gaussianF s-gaussianF r) := by linarith + rw [he', abs_mul, abs_of_pos hj] + have hz : |s-r| = 0 := by nlinarith [abs_nonneg (s-r), abs_nonneg (gaussianF s-gaussianF r)] + exact sub_eq_zero.mp (abs_eq_zero.mp hz) + +lemma exists_gaussian_fixed {j t : ℝ} (hj : 0 < j) (hj1 : j < 1) (ht : 0 ≤ t) : + ∃! s : ℝ, 0 ≤ s ∧ s = t+j*gaussianF s := by + let g : ℝ → ℝ := fun s => s-t-j*gaussianF s + have hg : Continuous g := (continuous_id.sub continuous_const).sub (continuous_const.mul continuous_gaussianF) + have hl : g t ≤ 0 := by dsimp [g]; nlinarith [gaussianF_nonneg ht] + have hu : 0 ≤ g (t+j) := by dsimp [g]; nlinarith [gaussianF_le_one (by linarith : 0 ≤ t+j)] + obtain ⟨s, hs, he⟩ := intermediate_value_Icc (by linarith : t ≤ t+j) hg.continuousOn ⟨hl, hu⟩ + have hs0 : 0 ≤ s := le_trans ht hs.1 + have hes : s = t+j*gaussianF s := by change s-t-j*gaussianF s = 0 at he; linarith + refine ⟨s, ⟨hs0, hes⟩, ?_⟩ + intro r hr + exact gaussian_fixed_unique hj hj1 hr.1 hs0 hr.2 hes + +def scalarFixedPoint (j t : ℝ) : ℝ := + if h : 0 < j ∧ j < 1 ∧ 0 ≤ t then (exists_gaussian_fixed h.1 h.2.1 h.2.2).choose else 0 + +lemma scalarFixedPoint_spec {j t : ℝ} (hj : 0 < j) (hj1 : j < 1) (ht : 0 ≤ t) : + 0 ≤ scalarFixedPoint j t ∧ scalarFixedPoint j t = t+j*gaussianF (scalarFixedPoint j t) := by + simp only [scalarFixedPoint, dite_eq_left (show 0 < j ∧ j < 1 ∧ 0 ≤ t from ⟨hj, hj1, ht⟩)] + exact (exists_gaussian_fixed hj hj1 ht).choose_spec.1 + +lemma scalarFixedPoint_bounds {j t : ℝ} (hj : 0 < j) (hj1 : j < 1) (ht : 0 ≤ t) : + t ≤ scalarFixedPoint j t ∧ scalarFixedPoint j t ≤ t/(1-j) := by + obtain ⟨hs, he⟩ := scalarFixedPoint_spec hj hj1 ht + constructor + · nlinarith [gaussianF_nonneg hs] + · apply (le_div_iff₀ (by linarith : 0 < 1-j)).mpr + nlinarith [gaussianF_le_self hs] + +lemma scalarFixedPoint_zero {j : ℝ} (hj : 0 < j) (hj1 : j < 1) : scalarFixedPoint j 0 = 0 := by + obtain ⟨hl, hu⟩ := scalarFixedPoint_bounds hj hj1 (le_refl 0) + simp only [zero_div] at hu + exact le_antisymm hu hl + +lemma scalarFixedPoint_lipschitz {j t u : ℝ} (hj : 0 < j) (hj1 : j < 1) + (ht : 0 ≤ t) (hu : 0 ≤ u) : + |scalarFixedPoint j t-scalarFixedPoint j u| ≤ 1/(1-j)*|t-u| := by + obtain ⟨hst, het⟩ := scalarFixedPoint_spec hj hj1 ht + obtain ⟨hsu, heu⟩ := scalarFixedPoint_spec hj hj1 hu + have h := gaussianF_lipschitz.dist_le_mul _ hst _ hsu + simp only [NNReal.coe_one, one_mul, Real.dist_eq] at h + have htri : |scalarFixedPoint j t-scalarFixedPoint j u| ≤ + |t-u|+j*|gaussianF (scalarFixedPoint j t)-gaussianF (scalarFixedPoint j u)| := by + calc + _ = |(t-u)+j*(gaussianF (scalarFixedPoint j t)-gaussianF (scalarFixedPoint j u))| := by congr 1; linarith + _ ≤ |t-u|+|j*(gaussianF (scalarFixedPoint j t)-gaussianF (scalarFixedPoint j u))| := abs_add_le _ _ + _ = _ := by rw [abs_mul, abs_of_pos hj] + rw [one_div, inv_mul_eq_div] + apply (le_div_iff₀ (by linarith : 0 < 1-j)).mpr + nlinarith + +lemma consistent_gaussian_unique {j t d : ℝ} {s : ℝ≥0} + (hj : 0 < j) (hj1 : j < 1) (ht : 0 ≤ t) + (hd : d = t+j*(∫ y, tanh y ∂gaussianReal d s)) + (hs : (s:ℝ) = t+j*(∫ y, tanh y^2 ∂gaussianReal d s)) : + d = scalarFixedPoint j t ∧ (s:ℝ) = scalarFixedPoint j t := by + have hds := consistent_gaussian_diagonal hj hj1 ht hd hs + have he : (s:ℝ) = t+j*gaussianF s := by + rw [hds] at hd + rw [gaussianF, gaussianAverage_eq_integral continuous_tanh _ s.coe_nonneg, + Real.toNNReal_coe] + exact hd + have hroot := scalarFixedPoint_spec hj hj1 ht + have hh := gaussian_fixed_unique hj hj1 s.coe_nonneg hroot.1 he hroot.2 + exact ⟨hds.trans hh, hh⟩ + +def scalarQ (j t : ℝ) : ℝ := gaussianF (scalarFixedPoint j t) + +lemma scalarQ_spec {j t : ℝ} (hj : 0 < j) (hj1 : j < 1) (ht : 0 ≤ t) : + scalarQ j t = (∫ y, tanh y^2 ∂gaussianReal (scalarFixedPoint j t) (scalarFixedPoint j t).toNNReal) ∧ + scalarQ j t = (scalarFixedPoint j t-t)/j ∧ scalarQ j t ≤ t/(1-j) := by + obtain ⟨hs, he⟩ := scalarFixedPoint_spec hj hj1 ht + refine ⟨?_, ?_, ?_⟩ + · exact (gaussianF_eq_square hs).trans (gaussianAverage_eq_integral (by fun_prop) _ hs) + · dsimp [scalarQ]; apply (eq_div_iff hj.ne').mpr; nlinarith + · exact (gaussianF_le_self hs).trans (scalarFixedPoint_bounds hj hj1 ht).2 + +lemma scalar_fixed_pos {j t : ℝ} (hj : 0 < j) (hj1 : j < 1) (ht : 0 < t) : + 0 < scalarFixedPoint j t ∧ 0 < scalarQ j t := by + have hs := ht.trans_le (scalarFixedPoint_bounds hj hj1 ht.le).1 + exact ⟨hs, gaussianF_pos hs⟩ + +end SKGap +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/ScalarParametersJoined.lean b/lean/OAI/Probability/SKGap/Localization/ScalarParametersJoined.lean new file mode 100644 index 0000000000000000000000000000000000000000..32fb7d86b062d20163c912c51d00eb4b7180e122 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/ScalarParametersJoined.lean @@ -0,0 +1,356 @@ +import Mathlib +import OAI.Probability.SKGap.Stability.StableFields + +namespace OAI + +section +noncomputable section + +open MeasureTheory ProbabilityTheory Filter Set Topology Real +open scoped NNReal ENNReal BoundedContinuousFunction + +namespace SKGap + +def momentBall (R : ℝ) : Set (ProbabilityMeasure ℝ) := + {P | ∫⁻ x : ℝ, ENNReal.ofReal (x^2) ∂P ≤ ENNReal.ofReal R} + +def momentCut (n : ℕ) : ℝ →ᵇ ℝ := + BoundedContinuousFunction.ofNormedAddCommGroup (fun x => min (n:ℝ) (x^2)) + (by fun_prop) n (fun x => by + rw [Real.norm_eq_abs, abs_of_nonneg (le_min (Nat.cast_nonneg _) (sq_nonneg _))] + exact min_le_left _ _) + +lemma momentCut_nonneg (n : ℕ) (x : ℝ) : 0 ≤ momentCut n x := + le_min (Nat.cast_nonneg _) (sq_nonneg _) + +lemma momentCut_tendsto (x : ℝ) : Tendsto (fun n => momentCut n x) atTop (𝓝 (x^2)) := by + have he : ∀ᶠ n : ℕ in atTop, momentCut n x = x^2 := by + obtain ⟨N,hN⟩ := exists_nat_ge (x^2) + filter_upwards [eventually_ge_atTop N] with n hn + exact min_eq_right (hN.trans (by exact_mod_cast hn)) + exact (tendsto_congr' he).2 tendsto_const_nhds + +lemma momentBall_iff (R : ℝ) (hR : 0 ≤ R) (P : ProbabilityMeasure ℝ) : + P ∈ momentBall R ↔ ∀ n, (∫ x, momentCut n x ∂P) ≤ R := by + constructor + · intro h n + apply (ENNReal.ofReal_le_ofReal_iff hR).mp + rw [ofReal_integral_eq_lintegral_ofReal ((momentCut n).integrable (μ := (P : Measure ℝ))) + (ae_of_all _ (momentCut_nonneg n))] + exact (lintegral_mono (fun x => ENNReal.ofReal_le_ofReal (min_le_right _ _))).trans h + · intro h + have ht : Tendsto (fun n => ∫⁻ x, ENNReal.ofReal (momentCut n x) ∂P) atTop + (𝓝 (∫⁻ x : ℝ, ENNReal.ofReal (x^2) ∂P)) := by + apply lintegral_tendsto_of_tendsto_of_monotone + · intro n; exact (ENNReal.continuous_ofReal.comp (momentCut n).continuous).aemeasurable + · exact ae_of_all _ (fun x a b hab => ENNReal.ofReal_le_ofReal (min_le_min_right _ (by exact_mod_cast hab))) + · exact ae_of_all _ (fun x => ENNReal.continuous_ofReal.continuousAt.tendsto.comp (momentCut_tendsto x)) + apply le_of_tendsto ht + exact Eventually.of_forall (fun n => by + rw [← ofReal_integral_eq_lintegral_ofReal ((momentCut n).integrable (μ := (P : Measure ℝ))) (ae_of_all _ (momentCut_nonneg n))] + exact ENNReal.ofReal_le_ofReal (h n)) + +lemma isClosed_momentBall (R : ℝ) : IsClosed (momentBall R) := by + have he : momentBall R = momentBall (max 0 R) := by simp only [momentBall, ENNReal.ofReal_max, ENNReal.ofReal_zero, max_eq_right (show (0:ℝ≥0∞) ≤ ENNReal.ofReal R from bot_le)] + rw [he] + have hR : 0 ≤ max 0 R := le_max_left _ _ + have hes : momentBall (max 0 R) = ⋂ n, {P : ProbabilityMeasure ℝ | (∫ x, momentCut n x ∂P) ≤ max 0 R} := by + ext P; simp only [mem_iInter, mem_ofPred_eq]; exact momentBall_iff _ hR P + rw [hes] + exact isClosed_iInter (fun n => isClosed_le (ProbabilityMeasure.continuous_integral_boundedContinuousFunction _) continuous_const) + +lemma momentBall_integrable {R : ℝ} {P : ProbabilityMeasure ℝ} (hP : P ∈ momentBall R) : + Integrable (fun x : ℝ => x^2) (P : Measure ℝ) := by + refine ⟨(by fun_prop), ?_⟩ + rw [hasFiniteIntegral_iff_ofReal (ae_of_all _ (fun x : ℝ => sq_nonneg x))] + exact lt_of_le_of_lt hP ENNReal.ofReal_lt_top + +lemma momentBall_integral_le {R : ℝ} (hR : 0 ≤ R) {P : ProbabilityMeasure ℝ} (hP : P ∈ momentBall R) : + (∫ x : ℝ, x^2 ∂P) ≤ R := by + apply (ENNReal.ofReal_le_ofReal_iff hR).mp + rw [ofReal_integral_eq_lintegral_ofReal (momentBall_integrable hP) (ae_of_all _ (fun x : ℝ => sq_nonneg x))] + exact hP + +lemma mem_momentBall {R : ℝ} {P : ProbabilityMeasure ℝ} + (hi : Integrable (fun x : ℝ => x^2) (P : Measure ℝ)) (hb : (∫ x : ℝ, x^2 ∂P) ≤ R) : + P ∈ momentBall R := by + change (∫⁻ x : ℝ, ENNReal.ofReal (x^2) ∂P) ≤ ENNReal.ofReal R + rw [← ofReal_integral_eq_lintegral_ofReal hi (ae_of_all _ (fun x : ℝ => sq_nonneg x))] + exact ENNReal.ofReal_le_ofReal hb + +lemma momentBall_tail {R K : ℝ} (hK : 0 < K) {P : ProbabilityMeasure ℝ} + (hP : P ∈ momentBall R) : + (P : Measure ℝ) (Metric.closedBall 0 K)ᶜ ≤ ENNReal.ofReal R / ENNReal.ofReal (K^2) := by + have hmeas : Measurable (fun x : ℝ => ENNReal.ofReal (x^2)) := by fun_prop + calc + _ ≤ (P : Measure ℝ) {x : ℝ | ENNReal.ofReal (K^2) ≤ ENNReal.ofReal (x^2)} := by + apply measure_mono + intro x hx + have hx' : K < |x| := by simpa only [mem_compl_iff, Metric.mem_closedBall, Real.dist_eq, sub_zero, not_le] using hx + apply ENNReal.ofReal_le_ofReal + nlinarith [sq_abs x] + _ ≤ (∫⁻ x : ℝ, ENNReal.ofReal (x^2) ∂P) / ENNReal.ofReal (K^2) := + meas_ge_le_lintegral_div hmeas.aemeasurable + (ENNReal.ofReal_ne_zero_iff.mpr (sq_pos_of_pos hK)) ENNReal.ofReal_ne_top + _ ≤ _ := ENNReal.div_le_div_right hP _ + +lemma isTight_momentBall (R : ℝ) : + IsTightMeasureSet {((P : ProbabilityMeasure ℝ) : Measure ℝ) | P ∈ momentBall R} := by + rw [isTightMeasureSet_iff_exists_isCompact_measure_compl_le] + intro ε hε + obtain ⟨δ, _, hδ, hδε⟩ := ENNReal.lt_iff_exists_real_btwn.mp hε + have hd : 0 < δ := ENNReal.ofReal_pos.mp hδ + let K := max 0 R / δ + 1 + have hK : 0 < K := by dsimp [K]; positivity + refine ⟨Metric.closedBall 0 K, isCompact_closedBall _ _, ?_⟩ + rintro _ ⟨P,hP,rfl⟩ + calc + _ ≤ ENNReal.ofReal R / ENNReal.ofReal (K^2) := momentBall_tail hK hP + _ ≤ ENNReal.ofReal δ := by + rw [← ENNReal.ofReal_div_of_pos (sq_pos_of_pos hK)] + apply ENNReal.ofReal_le_ofReal + rw [div_le_iff₀ (sq_pos_of_pos hK)] + have hK1 : 1 ≤ K := by dsimp [K]; linarith [div_nonneg (le_max_left 0 R) hd.le] + have he : δ * (K-1) = max 0 R := by dsimp [K]; field_simp; ring + have hab : 0 ≤ (K-1)^2 := sq_nonneg _ + nlinarith [le_max_right 0 R, mul_nonneg hd.le hab] + _ ≤ ε := hδε.le + +lemma isCompact_momentBall (R : ℝ) : IsCompact (momentBall R) := by + have h := isCompact_closure_of_isTightMeasureSet (isTight_momentBall R) + simpa only [(isClosed_momentBall R).closure_eq] using h + +lemma integrable_of_linear_bound {P : Measure ℝ} [IsProbabilityMeasure P] + (hP : Integrable (fun x : ℝ => x^2) P) {f : ℝ → ℝ} (hf : Continuous f) + {C : ℝ} (hC : 0 ≤ C) (hb : ∀ x, |f x| ≤ C*(1+|x|)) : Integrable f P := by + apply (((integrable_const (2:ℝ)).add hP).const_mul C).mono' hf.aestronglyMeasurable + exact ae_of_all _ (fun x => by + rw [Real.norm_eq_abs] + have hx : |x| ≤ 1+x^2 := by nlinarith [sq_nonneg (|x|-1), sq_abs x] + exact (hb x).trans (mul_le_mul_of_nonneg_left (by change 1+|x| ≤ 2+x^2; linarith) hC)) + +def momentClip {f : ℝ → ℝ} (hf : Continuous f) (n : ℕ) : ℝ →ᵇ ℝ := + BoundedContinuousFunction.ofNormedAddCommGroup (fun x => max (-(n:ℝ)) (min (n:ℝ) (f x))) + (by fun_prop) n (fun x => by + rw [Real.norm_eq_abs, abs_le] + exact ⟨le_max_left _ _, max_le (by linarith [Nat.cast_nonneg (α := ℝ) n]) (min_le_left _ _)⟩) + +lemma momentClip_error {n : ℕ} (hn : 0 < n) (x : ℝ) : + |x - max (-(n:ℝ)) (min (n:ℝ) x)| ≤ x^2/(n:ℝ) := by + have hn' : 0 < (n:ℝ) := by exact_mod_cast hn + rw [le_div_iff₀ hn'] + by_cases hx : x ≤ (n:ℝ) + · rw [min_eq_right hx] + by_cases hx' : -(n:ℝ) ≤ x + · rw [max_eq_right hx', sub_self, abs_zero, zero_mul]; positivity + · rw [max_eq_left (le_of_not_ge hx'), abs_of_nonpos (by linarith)] + nlinarith [sq_nonneg (x+(n:ℝ))] + · rw [min_eq_left (le_of_not_ge hx), max_eq_right (by linarith), abs_of_nonneg (by linarith)] + nlinarith [sq_nonneg (x-(n:ℝ))] + +lemma moment_integral_approx {R C : ℝ} (hR : 0 ≤ R) (hC : 0 ≤ C) + {f : ℝ → ℝ} (hf : Continuous f) (hb : ∀ x, |f x| ≤ C*(1+|x|)) + {n : ℕ} (hn : 0 < n) {P : ProbabilityMeasure ℝ} (hP : P ∈ momentBall R) : + |(∫ x, f x ∂P) - (∫ x, momentClip hf n x ∂P)| ≤ 2*C^2*(1+R)/(n:ℝ) := by + have hpi := momentBall_integrable hP + have hfi := integrable_of_linear_bound hpi hf hC hb + have hn' : 0 < (n:ℝ) := by exact_mod_cast hn + rw [← integral_sub hfi ((momentClip hf n).integrable (μ := (P : Measure ℝ))), ← Real.norm_eq_abs] + have hbound : ∀ x, ‖f x - momentClip hf n x‖ ≤ (2*C^2/(n:ℝ))*(1+x^2) := by + intro x + rw [Real.norm_eq_abs] + change |f x - max (-(n:ℝ)) (min (n:ℝ) (f x))| ≤ _ + apply (momentClip_error hn (f x)).trans + rw [div_mul_eq_mul_div, div_le_div_iff_of_pos_right hn'] + have hsq : (f x)^2 ≤ (C*(1+|x|))^2 := by + have h := mul_self_le_mul_self (abs_nonneg (f x)) (hb x) + simpa only [← sq, sq_abs] using h + have hs : (1+|x|)^2 ≤ 2*(1+x^2) := by nlinarith [sq_nonneg (|x|-1), sq_abs x] + calc + _ ≤ (C*(1+|x|))^2 := hsq + _ ≤ _ := by nlinarith [mul_le_mul_of_nonneg_left hs (sq_nonneg C)] + have he := norm_integral_le_of_norm_le + (((integrable_const (1:ℝ)).add hpi).const_mul (2*C^2/(n:ℝ))) (ae_of_all _ hbound) + calc + _ ≤ ∫ x, (2*C^2/(n:ℝ))*(1+x^2) ∂P := he + _ = (2*C^2/(n:ℝ))*(1+∫ x : ℝ, x^2 ∂P) := by + rw [integral_const_mul, integral_add (integrable_const 1) hpi] + simp only [integral_const, probReal_univ, smul_eq_mul, one_mul] + _ ≤ (2*C^2/(n:ℝ))*(1+R) := mul_le_mul_of_nonneg_left + (by linarith [momentBall_integral_le hR hP]) (by positivity) + _ = _ := by ring + +lemma continuousOn_integral_of_linear_bound {R C : ℝ} (hR : 0 ≤ R) (hC : 0 ≤ C) + {f : ℝ → ℝ} (hf : Continuous f) (hb : ∀ x, |f x| ≤ C*(1+|x|)) : + ContinuousOn (fun P : ProbabilityMeasure ℝ => ∫ x, f x ∂P) (momentBall R) := by + have ht : TendstoUniformlyOn (fun n (P : ProbabilityMeasure ℝ) => ∫ x, momentClip hf n x ∂P) + (fun P : ProbabilityMeasure ℝ => ∫ x, f x ∂P) atTop (momentBall R) := by + rw [Metric.tendstoUniformlyOn_iff] + intro ε hε + have he := (tendsto_const_div_atTop_nhds_zero_nat (2*C^2*(1+R))).eventually (gt_mem_nhds hε) + filter_upwards [he, eventually_gt_atTop 0] with n hn hn0 + intro P hP + rw [Real.dist_eq] + exact (moment_integral_approx hR hC hf hb hn0 hP).trans_lt hn + apply ht.continuousOn + exact Frequently.of_forall (fun n => (ProbabilityMeasure.continuous_integral_boundedContinuousFunction (momentClip hf n)).continuousOn) + +end SKGap + +namespace SKGap +open Filter +open scoped Topology + +lemma gaussian_affine_hasLaw (d : ℝ) (s : ℝ≥0) : + HasLaw (fun x : ℝ => d + sqrt s*x) (gaussianReal d s) (gaussianReal 0 1) := by + have h := gaussianReal_const_add (gaussianReal_const_mul + (HasLaw.id (μ := gaussianReal 0 1)) (sqrt s)) d + have hv : (NNReal.mk ((sqrt (s:ℝ))^2) (sq_nonneg _) : ℝ≥0) = s := by + ext + exact sq_sqrt s.coe_nonneg + simp only [id_eq, mul_zero, zero_add, mul_one] at h + rw [hv] at h + exact h + +def gaussianAverage (f : ℝ → ℝ) (d s : ℝ) : ℝ := ∫ x, f (d + sqrt s*x) ∂gaussianReal 0 1 + +lemma gaussianAverage_eq_integral {f : ℝ → ℝ} (hf : Continuous f) (d : ℝ) {s : ℝ} + (hs : 0 ≤ s) : gaussianAverage f d s = ∫ y, f y ∂gaussianReal d s.toNNReal := by + have h := (gaussian_affine_hasLaw d s.toNNReal).integral_comp hf.aestronglyMeasurable + simpa only [gaussianAverage, Function.comp_def, Real.coe_toNNReal s hs] using h + +lemma integrable_gaussian_comp_of_bound {f : ℝ → ℝ} (hf : Continuous f) {C : ℝ} + (hC : ∀ x, ‖f x‖ ≤ C) (d s : ℝ) : + Integrable (fun x => f (d+sqrt s*x)) (gaussianReal 0 1) := + Integrable.of_bound (by fun_prop) C (ae_of_all _ (fun x => hC _)) + +lemma continuous_gaussianAverage {f : ℝ → ℝ} (hf : Continuous f) {C : ℝ} + (hC : ∀ x, ‖f x‖ ≤ C) : Continuous (fun p : ℝ×ℝ => gaussianAverage f p.1 p.2) := by + apply continuous_of_dominated (bound := fun _ => C) + · intro p + exact (by fun_prop : Continuous (fun x : ℝ => f (p.1+sqrt p.2*x))).aestronglyMeasurable + · intro p + exact ae_of_all _ (fun x => hC _) + · exact integrable_const _ + · exact ae_of_all _ (fun x => by fun_prop) +end SKGap + +namespace SKGap +@[fun_prop] theorem continuous_tanh : Continuous tanh := + continuous_iff_continuousAt.mpr (fun y => (hasDerivAt_tanh y).continuousAt) +end SKGap + +namespace SKGap + +abbrev ScalarPoint := ProbabilityMeasure ℝ × (ℝ × ℝ) + +def scalarM (P : ProbabilityMeasure ℝ) : ℝ := ∫ x, tanh x ∂P + +def scalarQMoment (P : ProbabilityMeasure ℝ) : ℝ := ∫ x, tanh x^2 ∂P + +def scalarD (j : ℝ) (p : ScalarPoint) : ℝ := p.2.1+j*scalarM p.1 + +def scalarS (j : ℝ) (p : ScalarPoint) : ℝ := p.2.1+p.2.2^2+j*scalarQMoment p.1 + +def scalarA (j : ℝ) (p : ScalarPoint) : ℝ := + (∫ x, x*tanh x ∂p.1) - scalarD j p*scalarM p.1 + +def scalarPsi (j : ℝ) (p : ScalarPoint) : ℝ := + j*(scalarA j p-scalarS j p*(1-scalarQMoment p.1))^2 / + (2*scalarS j p*(scalarS j p+j*scalarQMoment p.1)) + +def scalarMomentDomain (R : ℝ) : Set ScalarPoint := momentBall R ×ˢ univ + +lemma continuous_scalarM : Continuous scalarM := by + let f : ℝ →ᵇ ℝ := BoundedContinuousFunction.ofNormedAddCommGroup tanh continuous_tanh 1 + (fun x => by simpa only [Real.norm_eq_abs] using (abs_tanh_lt_one x).le) + exact ProbabilityMeasure.continuous_integral_boundedContinuousFunction f + +lemma continuous_scalarQMoment : Continuous scalarQMoment := by + let f : ℝ →ᵇ ℝ := BoundedContinuousFunction.ofNormedAddCommGroup (fun x => tanh x^2) (by fun_prop) 1 + (fun x => by simpa only [Real.norm_eq_abs, abs_of_nonneg (sq_nonneg (tanh x))] using (tanh_sq_lt_one x).le) + exact ProbabilityMeasure.continuous_integral_boundedContinuousFunction f + +lemma continuous_scalarD (j : ℝ) : Continuous (scalarD j) := + (continuous_fst.comp continuous_snd).add (continuous_const.mul (continuous_scalarM.comp continuous_fst)) + +lemma continuous_scalarS (j : ℝ) : Continuous (scalarS j) := + ((continuous_fst.comp continuous_snd).add ((continuous_snd.comp continuous_snd).pow 2)).add + (continuous_const.mul (continuous_scalarQMoment.comp continuous_fst)) + +lemma scalarQMoment_bounds (P : ProbabilityMeasure ℝ) : 0 ≤ scalarQMoment P ∧ scalarQMoment P ≤ 1 := by + refine ⟨integral_nonneg (fun x => sq_nonneg _), ?_⟩ + have hi : Integrable (fun x : ℝ => tanh x^2) (P : Measure ℝ) := Integrable.of_bound + (by fun_prop) 1 (ae_of_all _ (fun x => by simpa only [Real.norm_eq_abs, abs_of_nonneg (sq_nonneg (tanh x))] using (tanh_sq_lt_one x).le)) + have h := integral_mono hi (integrable_const (1:ℝ)) (fun x => (tanh_sq_lt_one x).le) + simpa only [scalarQMoment, integral_const, probReal_univ, smul_eq_mul, one_mul] using h + +lemma scalarM_bounds (P : ProbabilityMeasure ℝ) : |scalarM P| ≤ 1 := by + have h := norm_integral_le_of_norm_le (μ := (P : Measure ℝ)) (f := tanh) (integrable_const (1:ℝ)) + (ae_of_all _ (fun x : ℝ => by simpa only [Real.norm_eq_abs] using (abs_tanh_lt_one x).le)) + simpa only [scalarM, Real.norm_eq_abs, integral_const, probReal_univ, smul_eq_mul, one_mul] using h + +lemma continuousOn_scalarA {R : ℝ} (hR : 0 ≤ R) (j : ℝ) : + ContinuousOn (scalarA j) (scalarMomentDomain R) := by + have hi := continuousOn_integral_of_linear_bound hR (C := 1) zero_le_one + (show Continuous (fun x : ℝ => x*tanh x) by fun_prop) (fun x => by + rw [abs_mul, one_mul] + have hm := mul_le_mul_of_nonneg_left (abs_tanh_lt_one x).le (abs_nonneg x) + linarith) + have hc : ContinuousOn (fun p : ScalarPoint => ∫ x, x*tanh x ∂p.1) (scalarMomentDomain R) := + hi.comp continuous_fst.continuousOn (fun p hp => hp.1) + exact hc.sub ((continuous_scalarD j).mul (continuous_scalarM.comp continuous_fst)).continuousOn + +lemma scalarA_eq {R : ℝ} {p : ScalarPoint} (hp : p ∈ scalarMomentDomain R) (j : ℝ) : + scalarA j p = ∫ x, (x-scalarD j p)*tanh x ∂p.1 := by + have hi := integrable_of_linear_bound (momentBall_integrable hp.1) + (show Continuous (fun x : ℝ => x*tanh x) by fun_prop) zero_le_one (fun x => by + rw [abs_mul, one_mul] + have hm := mul_le_mul_of_nonneg_left (abs_tanh_lt_one x).le (abs_nonneg x) + linarith) + have ht : Integrable tanh (p.1 : Measure ℝ) := Integrable.of_bound + continuous_tanh.aestronglyMeasurable 1 (ae_of_all _ (fun x => by simpa only [Real.norm_eq_abs] using (abs_tanh_lt_one x).le)) + simp_rw [sub_mul] + rw [integral_sub hi (ht.const_mul _), integral_const_mul] + rfl + +lemma continuousOn_scalarPsi {R : ℝ} (hR : 0 ≤ R) (j : ℝ) : + ContinuousOn (scalarPsi j) (scalarMomentDomain R ∩ {p | scalarS j p ≠ 0 ∧ scalarS j p+j*scalarQMoment p.1 ≠ 0}) := by + unfold scalarPsi + apply ContinuousOn.div + · exact continuousOn_const.mul ((((continuousOn_scalarA hR j).mono inter_subset_left).sub + ((continuous_scalarS j).continuousOn.mul (continuousOn_const.sub (continuous_scalarQMoment.comp continuous_fst).continuousOn))).pow 2) + · exact (continuous_const.mul (continuous_scalarS j)).continuousOn.mul + ((continuous_scalarS j).add (continuous_const.mul (continuous_scalarQMoment.comp continuous_fst))).continuousOn + · intro p hp; exact mul_ne_zero (mul_ne_zero (by norm_num) hp.2.1) hp.2.2 + +def scalarLogMoment (f : ℝ →ᵇ ℝ) (d s : ℝ) : ℝ := + log (gaussianAverage (fun x => exp (f x)) d s) + +lemma continuous_scalarLogMoment (f : ℝ →ᵇ ℝ) : + Continuous (fun p : ℝ×ℝ => scalarLogMoment f p.1 p.2) := by + have hc := continuous_gaussianAverage (continuous_exp.comp f.continuous) + (C := exp ‖f‖) (fun x => by + simp only [Function.comp_def]; rw [Real.norm_eq_abs, abs_of_pos (exp_pos _)] + exact exp_le_exp.mpr ((le_abs_self _).trans (f.norm_coe_le_norm x))) + apply hc.log + intro p + apply ne_of_gt + exact integral_pos_iff_support_of_nonneg (fun _ => (exp_pos _).le) + (integrable_gaussian_comp_of_bound (continuous_exp.comp f.continuous) + (C := exp ‖f‖) (fun x => by + simp only [Function.comp_def]; rw [Real.norm_eq_abs, abs_of_pos (exp_pos _)] + exact exp_le_exp.mpr ((le_abs_self _).trans (f.norm_coe_le_norm x))) p.1 p.2) |>.mpr + (by simp [Function.support, (exp_pos _).ne']) + +lemma scalarLogMoment_eq (f : ℝ →ᵇ ℝ) (d : ℝ) {s : ℝ} (hs : 0 ≤ s) : + scalarLogMoment f d s = log (∫ x, exp (f x) ∂gaussianReal d s.toNNReal) := by + unfold scalarLogMoment + congr 1 + exact gaussianAverage_eq_integral (continuous_exp.comp f.continuous) d hs + +end SKGap +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/ScalarRelativeIsolation.lean b/lean/OAI/Probability/SKGap/Localization/ScalarRelativeIsolation.lean new file mode 100644 index 0000000000000000000000000000000000000000..c7392fc008fe9f22fc1bb9ca0a373f4c6edc75eb --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/ScalarRelativeIsolation.lean @@ -0,0 +1,68 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.CompactTube +import OAI.Probability.SKGap.Localization.ScalarClosedIsolation + +namespace OAI + +section +noncomputable section +namespace SKGap +open MeasureTheory ProbabilityTheory Real Set +open scoped NNReal ENNReal + +def scalarRelativeForbidden {R t0 T : ℝ} (U : Set (ScalarTimeDomain R t0 T)) : Set ScalarPoint := + (fun p : ScalarPoint => (p.1,p.2.1)) ⁻¹' + ((fun x : ScalarTimeDomain R t0 T => ((x.1 : ProbabilityMeasure ℝ),(x.2 : ℝ))) '' Uᶜ) + +lemma isClosed_scalarRelativeForbidden {R t0 T : ℝ} {U : Set (ScalarTimeDomain R t0 T)} + (hU : IsOpen U) : IsClosed (scalarRelativeForbidden U) := by + let : CompactSpace (momentBall R) := isCompact_iff_compactSpace.mp (isCompact_momentBall R) + let : CompactSpace (Icc t0 T) := isCompact_iff_compactSpace.mp isCompact_Icc + have hc : IsCompact ((fun x : ScalarTimeDomain R t0 T => + ((x.1 : ProbabilityMeasure ℝ),(x.2 : ℝ))) '' Uᶜ) := + hU.isClosed_compl.isCompact.image (by fun_prop) + exact hc.isClosed.preimage (by fun_prop) + +lemma scalarRelativeForbidden_curve {j R t0 T : ℝ} {U : Set (ScalarTimeDomain R t0 T)} + (hK : scalarEqualitySet j R t0 T ⊆ U) {p : ScalarPoint} + (hp : p ∈ scalarRelativeForbidden U) : p.1 ≠ scalarCurve j p.2.1 := by + intro he + obtain ⟨x,hx,hxe⟩ := hp + have hP := congrArg Prod.fst hxe + have ht := congrArg Prod.snd hxe + dsimp only at hP ht + have hxK : x ∈ scalarEqualitySet j R t0 T := by + change (x.1 : ProbabilityMeasure ℝ)=scalarCurve j (x.2:ℝ) + rw [hP,ht,he] + exact hx (hK hxK) + +theorem scalar_relative_neighborhood_rate {j R t0 T : ℝ} (hj : 0 < j) (hj1 : j < 1) + (ht0 : 0 < t0) (hT : t0 ≤ T) {U : Set (ScalarTimeDomain R t0 T)} + (hU : IsOpen U) (hK : scalarEqualitySet j R t0 T ⊆ U) : + ∃ a > 0, ∃ δ > 0, ∃ N : ℕ, ∀ n ≥ N, ∀ hn : 0 < n, + ∀ t ∈ Icc t0 T, ∀ σ ∈ Icc 0 (min δ 1), + ∀ E : Set (Fin n → ℝ), MeasurableSet E → + (∀ y ∈ E, @empiricalLaw (Fin n) _ ⟨⟨0,hn⟩⟩ y ∈ momentBall R) → + (∀ y ∈ E, ∀ x ∈ U, @empiricalLaw (Fin n) _ ⟨⟨0,hn⟩⟩ y ≠ (x.1:ProbabilityMeasure ℝ) ∨ t ≠ (x.2:ℝ)) → + (∫⁻ y in E, ENNReal.ofReal (@scalarIntegrand (Fin n) _ ⟨⟨0,hn⟩⟩ j t σ y)) ≤ + ENNReal.ofReal (exp (-a*(n:ℝ))) := by + obtain ⟨a,ha,δ,hδ,N,hbound⟩ := scalar_closed_isolation hj hj1 (ht0.le.trans hT) ht0 + (isClosed_scalarRelativeForbidden hU) (fun p hp _ _ => scalarRelativeForbidden_curve hK hp) + refine ⟨a,ha,δ,hδ,N,?_⟩ + intro n hn hn' t ht σ hσ E hE hmom hnot + let : Nonempty (Fin n) := ⟨⟨0,hn'⟩⟩ + apply hbound n hn hn' t ⟨ht0.le.trans ht.1,ht.2⟩ σ hσ E hE + · intro y hy + let x : ScalarTimeDomain R t0 T := (⟨empiricalLaw y,hmom y hy⟩,⟨t,ht⟩) + refine ⟨x,?_,rfl⟩ + intro hx + rcases hnot y hy x hx with hh | hh <;> exact hh rfl + · intro y _ + have hq := (scalarQMoment_bounds (empiricalLaw y)).1 + change t0 ≤ t+σ^2+j*scalarQMoment (empiricalLaw y) + linarith [ht.1,sq_nonneg σ,mul_nonneg hj.le hq] +end SKGap +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/ScalarSlowConeStep.lean b/lean/OAI/Probability/SKGap/Localization/ScalarSlowConeStep.lean new file mode 100644 index 0000000000000000000000000000000000000000..c41813d9e0767544850504c931d6177a2b3a7f9b --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/ScalarSlowConeStep.lean @@ -0,0 +1,274 @@ +import Mathlib +import OAI.Probability.SKGap.Model + +namespace OAI + +section +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open scoped BigOperators +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open scoped BigOperators +open scoped BigOperators NNReal ENNReal +open MeasureTheory Metric Set +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators NNReal ENNReal Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Set +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators ENNReal NNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Matrix +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators ENNReal NNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal +open scoped BigOperators +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise NNReal ENNReal +open scoped BigOperators +open Filter Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal Topology +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Set Matrix +open scoped BigOperators NNReal ENNReal Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open Filter MeasureTheory ProbabilityTheory +open scoped Topology NNReal ENNReal +open Filter MeasureTheory ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter +open scoped Topology NNReal ENNReal +open MeasureTheory Filter ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter +open scoped Topology +open MeasureTheory Filter ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter ProbabilityTheory ContinuousLinearMap +open scoped Topology NNReal ENNReal +open Filter MeasureTheory ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter +open scoped BigOperators Topology +open MeasureTheory Filter +open scoped BigOperators Topology +open MeasureTheory Filter +open scoped BigOperators Topology +open MeasureTheory Filter +open scoped BigOperators Topology +open MeasureTheory Filter +open scoped BigOperators Topology +open Filter Set Metric +open scoped Topology RealInnerProductSpace +open scoped BigOperators +open ContinuousLinearMap +open scoped BigOperators +open ContinuousLinearMap +open scoped Topology Interval +open MeasureTheory +open MeasureTheory +open scoped BigOperators Topology Interval +open MeasureTheory +open scoped BigOperators Topology Interval +open scoped Topology +namespace SKGapCutoff + +lemma scalar_slow_cone_step {a a' N N' r q K η ε CE : ℝ} + (ha : 0 ≤ a) (hr : 0 ≤ r) (hq : 0 ≤ q) (hη : 0 ≤ η) (hε : 0 ≤ ε) + (hsmall : K*η ≤ ε*(1-K*η)) (hwidth : CE+ε ≤ K) + (hcone : N ≤ K*a) (hnew : N' ≤ CE*a'+r) + (halign : |a'-q*a|+r ≤ η*q*N) (ha' : 0 ≤ a') : + (1-K*η)*q*a ≤ a' ∧ r ≤ ε*a' ∧ N' ≤ K*a' := by + have herror : |a'-q*a|+r ≤ η*q*K*a := + halign.trans (by nlinarith only [mul_le_mul_of_nonneg_left hcone (mul_nonneg hη hq)]) + have hlow : (1-K*η)*q*a ≤ a' := by + have hh := neg_abs_le (a'-q*a) + nlinarith only [hh, herror, hr] + have hqa : 0 ≤ q*a := mul_nonneg hq ha + have hres : r ≤ ε*a' := by + have hh := mul_le_mul_of_nonneg_right hsmall hqa + have hh' := mul_le_mul_of_nonneg_left hlow hε + nlinarith only [herror, abs_nonneg (a'-q*a), hh, hh'] + refine ⟨hlow,hres,?_⟩ + calc + N' ≤ CE*a'+r := hnew + _ ≤ CE*a'+ε*a' := by linarith only [hres] + _ ≤ K*a' := by nlinarith only [mul_le_mul_of_nonneg_right hwidth ha'] + +lemma norm_scalar_alignment {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] + (v w : E) {q : ℝ} (hq : 0 ≤ q) : + |‖v‖-q*‖w‖| ≤ ‖v-q • w‖ := by + simpa only [norm_smul, Real.norm_eq_abs, abs_of_nonneg hq] using abs_norm_sub_norm_le v (q • w) + +theorem finite_slow_cone_iteration (a N r : ℕ → ℝ) (L : ℕ) + (q K η ε CE CA δ c : ℝ) + (hq : 0 < q) (hK : 0 ≤ K) (hη : 0 ≤ η) (hε : 0 ≤ ε) + (hCA : 0 < CA) (hc : 0 ≤ c) (hden : 0 < 1-K*η) + (hdecay : (1-K*η)*q ≤ 1) + (hsmall : K*η ≤ ε*(1-K*η)) (hwidth : CE+ε ≤ K) + (ha : ∀ k, 0 ≤ a k) (hr : ∀ k, 0 ≤ r k) + (hobs : ∀ k ≤ L, a k ≤ CA*N k) + (hnew : ∀ k < L, N (k+1) ≤ CE*a (k+1)+r (k+1)) + (hinit : c ≤ a 0) (hcone : N 0 ≤ K*a 0) + (hthreshold : δ*CA ≤ c*((1-K*η)*q)^L) + (halign : ∀ k < L, δ ≤ N k → + (k=0 ∨ N (k-1) ≤ (K*CA/((1-K*η)*q))*N k) → + |a (k+1)-q*a k|+r (k+1) ≤ η*q*N k) : + ∀ k ≤ L, c*((1-K*η)*q)^k ≤ a k ∧ N k ≤ K*a k ∧ + δ ≤ N k ∧ (0 + have hg : c*b^0 ≤ a 0 := by simpa using hinit + exact ⟨hg,hcone,hcut 0 hk hg,by omega,by omega⟩ + | succ k ih => + have hkL : k < L := by omega + obtain ⟨hg,hc0,hc1,_,hratio⟩ := ih (by omega) + have hs := halign k hkL hc1 (by + by_cases hz : k=0 + · exact Or.inl hz + · exact Or.inr (hratio (Nat.pos_of_ne_zero hz))) + obtain ⟨hlow,hres,hcone'⟩ := scalar_slow_cone_step (ha k) (hr (k+1)) hq.le hη hε + hsmall hwidth hc0 (hnew k hkL) hs (ha (k+1)) + have hg' : c*b^(k+1) ≤ a (k+1) := by + calc + c*b^(k+1) = b*(c*b^k) := by rw [pow_succ]; ring + _ ≤ b*a k := mul_le_mul_of_nonneg_left hg hb.le + _ ≤ _ := hlow + have hratio' : N k ≤ (K*CA/b)*N (k+1) := by + have hh : b*N k ≤ K*CA*N (k+1) := by + calc + b*N k ≤ b*(K*a k) := mul_le_mul_of_nonneg_left hc0 hb.le + _ = K*(b*a k) := by ring + _ ≤ K*a (k+1) := mul_le_mul_of_nonneg_left hlow hK + _ ≤ K*(CA*N (k+1)) := mul_le_mul_of_nonneg_left (hobs (k+1) hk) hK + _ = _ := by ring + rw [div_mul_eq_mul_div] + exact (le_div_iff₀ hb).mpr (by nlinarith only [hh]) + exact ⟨hg',hcone',hcut (k+1) hk hg',fun _ => hres,fun _ => by simpa using hratio'⟩ + +lemma one_sub_ge_exp {x : ℝ} (hx : 0≤x) (hx1 : x≤1/2) : + Real.exp (-2*x) ≤ 1-x := by + have hd : 0<1-x := by linarith + have hi : (1-x)⁻¹ ≤ 1+2*x := by + rw [inv_eq_one_div] + apply (div_le_iff₀ hd).mpr + nlinarith [mul_nonneg hx (show 0≤1-2*x by linarith)] + have hl := Real.one_sub_inv_le_log_of_pos hd + have hh : -2*x ≤ Real.log (1-x) := by linarith + simpa only [Real.exp_log hd] using Real.exp_le_exp.mpr hh + +lemma slow_cone_geometric_exponential {K η lam ξ D : ℝ} + (hx : 0≤K*η) (hx1 : K*η≤1/2) (hxi : 2*K*η≤ξ*D) (k : ℕ) : + Real.exp (-(lam+ξ)*(k*D)) ≤ ((1-K*η)*Real.exp (-lam*D))^k := by + have he : Real.exp (-(lam+ξ)*D) ≤ (1-K*η)*Real.exp (-lam*D) := by + have hh : Real.exp (-ξ*D) ≤ 1-K*η := + (Real.exp_le_exp.mpr (by linarith)).trans (one_sub_ge_exp hx hx1) + calc + _ = Real.exp (-ξ*D)*Real.exp (-lam*D) := by rw [← Real.exp_add]; congr 1; ring + _ ≤ _ := mul_le_mul_of_nonneg_right hh (Real.exp_pos _).le + have hh := pow_le_pow_left₀ (Real.exp_pos _).le he k + rw [← Real.exp_nat_mul] at hh + convert hh using 1; congr 1; ring + +end SKGapCutoff + +open MeasureTheory +open scoped BigOperators Topology Interval + +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/ScalarSmallNoiseTests.lean b/lean/OAI/Probability/SKGap/Localization/ScalarSmallNoiseTests.lean new file mode 100644 index 0000000000000000000000000000000000000000..b5ca9710463ca2832bd7edee6ce6dda1dfb59f0a --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/ScalarSmallNoiseTests.lean @@ -0,0 +1,184 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.ScalarConsistency +import OAI.Probability.SKGap.Gaussian.GaussianTiltMass + +namespace OAI + +section +noncomputable section +open MeasureTheory ProbabilityTheory InformationTheory Real Set Filter +open scoped NNReal ENNReal Topology +noncomputable section +open Real Set +noncomputable section +open MeasureTheory ProbabilityTheory Real Set Filter +open scoped Topology NNReal ENNReal BoundedContinuousFunction +open MeasureTheory ProbabilityTheory Filter Set Topology Real +open scoped NNReal ENNReal BoundedContinuousFunction +noncomputable section +open Set Filter Topology +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set Topology Real +open scoped NNReal ENNReal BoundedContinuousFunction +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set Topology Real +open scoped NNReal ENNReal BoundedContinuousFunction +namespace SKGap + +lemma scalar_small_noise_tests {j R : ℝ} (hj : 0 < j) (hj1 : j < 1) (hR : 0 ≤ R) + {K : Set ScalarPoint} (hK : IsCompact K) + (hmom : K ⊆ scalarMomentDomain R) (ht : ∀ p ∈ K, 0 ≤ p.2.1) + (hσ : ∀ p ∈ K, 0 ≤ p.2.2) (hs : ∀ p ∈ K, 0 < scalarS j p) + (hne : ∀ p ∈ K, p.2.2 = 0 → p.1 ≠ scalarCurve j p.2.1) : + ∃ a > 0, ∃ δ > 0, ∀ p ∈ K, p.2.2 ≤ δ → ∃ f : ℝ →ᵇ ℝ, + scalarPsi j p-(∫ y, f y ∂p.1)+ + log (∫ y, exp (f y) ∂gaussianReal (scalarD j p) (scalarS j p).toNNReal) < -a := by + have hw (f : ℝ →ᵇ ℝ) : ContinuousOn (fun p : ScalarPoint => + scalarPsi j p-(∫ y, f y ∂p.1)+scalarLogMoment f (scalarD j p) (scalarS j p)) K := + (continuousOn_scalar_test hR hj.le f).mono (fun p hp => ⟨hmom hp,hs p hp⟩) + have hW (p : ScalarPoint) (hp : p ∈ K) (hz : p.2.2 = 0) : + ∃ f : ℝ →ᵇ ℝ, scalarPsi j p-(∫ y, f y ∂p.1)+scalarLogMoment f (scalarD j p) (scalarS j p) < 0 := by + have hng : (p.1 : Measure ℝ) ≠ gaussianReal (scalarD j p) (scalarS j p).toNNReal := by + intro he + exact hne p hp hz (scalar_gaussian_curve hj hj1 (ht p hp) hz (hs p hp).le he) + obtain ⟨f,hf⟩ := scalar_strict_test (hmom hp) hj hj1 (ht p hp) (hs p hp) hng + rw [← scalarLogMoment_eq f _ (hs p hp).le] at hf + exact ⟨f,hf⟩ + obtain ⟨a,ha,δ,hδ,hall⟩ := compact_small_noise_witness hK _ hw + (σ := fun p : ScalarPoint => p.2.2) (by fun_prop) hσ hW + refine ⟨a,ha,δ,hδ,?_⟩ + intro p hp hδp + obtain ⟨f,hf⟩ := hall p hp hδp + rw [scalarLogMoment_eq f _ (hs p hp).le] at hf + exact ⟨f,hf⟩ + +lemma continuousOn_scalarPsi_of_pos {j R : ℝ} (hj : 0 ≤ j) (hR : 0 ≤ R) + {K : Set ScalarPoint} (hmom : K ⊆ scalarMomentDomain R) (hs : ∀ p ∈ K, 0 < scalarS j p) : + ContinuousOn (scalarPsi j) K := (continuousOn_scalarPsi hR j).mono (by + intro p hp + exact ⟨hmom hp,(hs p hp).ne',ne_of_gt (add_pos_of_pos_of_nonneg (hs p hp) + (mul_nonneg hj (scalarQMoment_bounds p.1).1))⟩) + +theorem scalar_compact_isolation {j R : ℝ} (hj : 0 < j) (hj1 : j < 1) (hR : 0 ≤ R) + {K : Set ScalarPoint} (hK : IsCompact K) + (hmom : K ⊆ scalarMomentDomain R) (ht : ∀ p ∈ K, 0 ≤ p.2.1) + (hσ : ∀ p ∈ K, 0 ≤ p.2.2) (hs : ∀ p ∈ K, 0 < scalarS j p) + (hne : ∀ p ∈ K, p.2.2 = 0 → p.1 ≠ scalarCurve j p.2.1) : + ∃ a > 0, ∃ δ > 0, ∃ N : ℕ, ∀ n ≥ N, ∀ hn : 0 < n, + ∀ z : (Fin n → ℝ) → ScalarPoint, ∀ E : Set (Fin n → ℝ), MeasurableSet E → + (∀ y ∈ E, z y ∈ K ∧ (z y).2.2 ≤ δ) → + (∀ y ∈ E, (z y).1 = @empiricalLaw (Fin n) _ ⟨⟨0,hn⟩⟩ y) → + (∀ y ∈ E, ∑ i, (y i)^2 ≤ (n:ℝ)*R) → + (∫⁻ y in E, ENNReal.ofReal (exp ((n:ℝ)*scalarPsi j (z y))* + productNormal (scalarD j (z y)) (scalarS j (z y)) y)) ≤ ENNReal.ofReal (exp (-a*(n:ℝ))) := by + obtain ⟨a,ha,δ,hδ,hW⟩ := scalar_small_noise_tests hj hj1 hR hK hmom ht hσ hs hne + let K' := K ∩ {p : ScalarPoint | p.2.2 ≤ δ} + have hK' : IsCompact K' := hK.inter_right (isClosed_le (by fun_prop) continuous_const) + have hmom' : K' ⊆ scalarMomentDomain R := fun _ hp => hmom hp.1 + have hs' : ∀ p ∈ K', 0 < scalarS j p := fun p hp => hs p hp.1 + obtain ⟨N,hN⟩ := gaussian_compact_rate hK' (P := fun p : ScalarPoint => p.1) + continuous_fst.continuousOn (continuous_scalarD j).continuousOn (continuous_scalarS j).continuousOn + (continuousOn_scalarPsi_of_pos hj.le hR hmom' hs') hs' R (-a) + (fun p hp => hW p hp.1 hp.2) (half_pos ha) + refine ⟨a/2,half_pos ha,δ,hδ,N,?_⟩ + intro n hn hn' z E hE hz hemp hmomE + have hh := hN n hn hn' z E hE hz hemp hmomE + convert hh using 1 + congr 1 + ring_nf + +end SKGap +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set Topology Real +open scoped NNReal ENNReal +namespace SKGap + +lemma scalar_quadratic_envelope {j q a s Q : ℝ} (hj : 0 ≤ j) (hq : 0 ≤ q) + (hq1 : q ≤ 1) (hs : 0 < s) (hc : j*q ≤ s) (hQ : 0 ≤ Q) (ha : a^2 ≤ q*Q) : + j*(a-s*(1-q))^2/(2*s*(s+j*q)) ≤ 3*Q/(8*s)+3*j/2 := by + have hS : 0 < s+j*q := add_pos_of_pos_of_nonneg hs (mul_nonneg hj hq) + have hsq : (a-s*(1-q))^2 ≤ 3/2*a^2+3*(s*(1-q))^2 := by + nlinarith [sq_nonneg (a+2*s*(1-q))] + have hb : (1-q)^2 ≤ 1 := by nlinarith + have hb' := mul_le_mul_of_nonneg_left hb (sq_nonneg s) + have ha' := mul_le_mul_of_nonneg_left ha (show 0 ≤ 3/2*j by positivity) + have hc' := mul_le_mul_of_nonneg_right hc hQ + have hss := mul_nonneg hs.le (mul_nonneg hj hq) + have hsqj := mul_le_mul_of_nonneg_left hsq hj + have hb'' := mul_le_mul_of_nonneg_left hb' (show 0 ≤ 3*j by positivity) + apply (div_le_iff₀ (by positivity : 0 < 2*s*(s+j*q))).mpr + have he : (3*Q/(8*s)+3*j/2)*(2*s*(s+j*q)) = 3/4*Q*(s+j*q)+3*j*s*(s+j*q) := by + field_simp + ring + rw [he] + have hjs := mul_nonneg hj hss + nlinarith + +lemma sum_centered_sq_lower {ι : Type*} [Fintype ι] (y : ι → ℝ) (d : ℝ) : + (∑ i, (y i)^2)/2-(Fintype.card ι:ℝ)*d^2 ≤ ∑ i, (y i-d)^2 := by + have h := Finset.sum_le_sum (s := Finset.univ) (fun i _ => + show (y i)^2/2-d^2 ≤ (y i-d)^2 by nlinarith [sq_nonneg (y i-2*d)]) + simpa only [Finset.sum_sub_distrib, Finset.sum_div, Finset.sum_const, + Finset.card_univ, nsmul_eq_mul] using h + +lemma multiple_gaussian_integrable {ι : Type*} [Fintype ι] {c : ℝ} (hc : 0 < c) : + Integrable (fun y : ι → ℝ => exp (-c*∑ i, (y i)^2)) := by + have h := Integrable.fintype_prod (fun _ : ι => integrable_exp_neg_mul_sq hc) + simpa only [volume_pi, ← exp_sum, ← Finset.mul_sum] using h + +lemma multiple_gaussian_integral {ι : Type*} [Fintype ι] {c : ℝ} (hc : 0 < c) : + (∫ y : ι → ℝ, exp (-c*∑ i, (y i)^2)) = exp ((Fintype.card ι:ℝ)*log (sqrt (Real.pi/c))) := by + have he (y : ι → ℝ) : exp (-c*∑ i, (y i)^2) = ∏ i, exp (-c*(y i)^2) := by + rw [Finset.mul_sum, exp_sum] + simp_rw [he] + rw [integral_fintype_prod_volume_eq_pow (fun x : ℝ => exp (-c*x^2)), integral_gaussian] + rw [exp_nat_mul, exp_log (sqrt_pos.mpr (div_pos Real.pi_pos hc))] + +theorem quadratic_envelope_tail {ι : Type*} [Fintype ι] {c C R : ℝ} (hc : 0 < c) + {E : Set (ι → ℝ)} (hE : MeasurableSet E) (f : (ι → ℝ) → ℝ) + (hf : ∀ y ∈ E, f y ≤ exp ((Fintype.card ι:ℝ)*C-c*∑ i, (y i)^2)) + (htail : ∀ y ∈ E, (Fintype.card ι:ℝ)*R ≤ ∑ i, (y i)^2) : + (∫⁻ y in E, ENNReal.ofReal (f y)) ≤ ENNReal.ofReal + (exp ((Fintype.card ι:ℝ)*(C-c*R/2+log (sqrt (Real.pi/(c/2)))))) := by + let g (y : ι → ℝ) := exp ((Fintype.card ι:ℝ)*(C-c*R/2))*exp (-(c/2)*∑ i, (y i)^2) + have hg : Integrable g := (multiple_gaussian_integrable (half_pos hc)).const_mul _ + have hgnn (y : ι → ℝ) : 0 ≤ g y := mul_nonneg (exp_pos _).le (exp_pos _).le + have hdom (y : ι → ℝ) (hy : y ∈ E) : f y ≤ g y := by + refine (hf y hy).trans ?_ + dsimp [g] + rw [← exp_add] + apply exp_le_exp.mpr + have h := mul_le_mul_of_nonneg_left (htail y hy) hc.le + nlinarith + calc + _ ≤ ∫⁻ y in E, ENNReal.ofReal (g y) := lintegral_mono_ae + ((ae_restrict_mem hE).mono (fun y hy => ENNReal.ofReal_le_ofReal (hdom y hy))) + _ ≤ ∫⁻ y, ENNReal.ofReal (g y) := lintegral_mono' Measure.restrict_le_self (fun _ => le_rfl) + _ = ENNReal.ofReal (∫ y, g y) := (ofReal_integral_eq_lintegral_ofReal hg (ae_of_all _ hgnn)).symm + _ = _ := by + congr 1 + dsimp [g] + rw [integral_const_mul, multiple_gaussian_integral (half_pos hc), ← exp_add] + congr 1 + ring + +lemma choose_quadratic_tail_radius {c C : ℝ} (hc : 0 < c) (L : ℝ) : + ∃ R > 0, C-c*R/2+log (sqrt (Real.pi/(c/2))) ≤ -L := by + let R := max 1 (2*(C+log (sqrt (Real.pi/(c/2)))+L)/c) + refine ⟨R, (by dsimp [R]; exact lt_of_lt_of_le zero_lt_one (le_max_left _ _)), ?_⟩ + have h : 2*(C+log (sqrt (Real.pi/(c/2)))+L)/c ≤ R := le_max_right _ _ + rw [div_le_iff₀ hc] at h + nlinarith + +end SKGap + +end +end +end +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/ScalarVariance.lean b/lean/OAI/Probability/SKGap/Localization/ScalarVariance.lean new file mode 100644 index 0000000000000000000000000000000000000000..6d091d1b5a196bc6823ff90b37bb483518f4ba74 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/ScalarVariance.lean @@ -0,0 +1,311 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.Invert +import OAI.Probability.SKGap.Localization.JumpWeight + +namespace OAI + +section +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open scoped BigOperators +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open scoped BigOperators +namespace SKGapCutoff + +noncomputable def scalarVariance (y : ℝ) : ℝ := 1 - Real.tanh y ^ 2 + +lemma scalarVariance_pos (y : ℝ) : 0 < scalarVariance y := + sub_pos.mpr (Real.tanh_sq_lt_one y) + +lemma scalarVariance_le_one (y : ℝ) : scalarVariance y ≤ 1 := by + unfold scalarVariance + nlinarith [sq_nonneg (Real.tanh y)] + +lemma scalarVariance_eq (y : ℝ) : scalarVariance y = 1 / Real.cosh y ^ 2 := by + have hc := Real.cosh_sq_sub_sinh_sq y + unfold scalarVariance + rw [Real.tanh_eq_sinh_div_cosh] + field_simp + nlinarith + +lemma tanh_hasDerivAt (y : ℝ) : HasDerivAt Real.tanh (scalarVariance y) y := by + have h := (Real.hasDerivAt_sinh y).div (Real.hasDerivAt_cosh y) (Real.cosh_pos y).ne' + convert! h using 1 + · ext z; exact Real.tanh_eq_sinh_div_cosh z + · rw [scalarVariance_eq] + congr 1 + nlinarith [Real.cosh_sq_sub_sinh_sq y] + +lemma tanh_lipschitz (x y : ℝ) : |Real.tanh y - Real.tanh x| ≤ |y-x| := by + have h := Convex.norm_image_sub_le_of_norm_hasDerivWithin_le + (fun z (_ : z ∈ (Set.univ : Set ℝ)) => (tanh_hasDerivAt z).hasDerivWithinAt) + (fun z _ => (show ‖scalarVariance z‖ ≤ 1 by + rw [Real.norm_eq_abs, abs_of_pos (scalarVariance_pos z)] + exact scalarVariance_le_one z)) convex_univ (Set.mem_univ x) (Set.mem_univ y) + simpa only [one_mul, Real.norm_eq_abs] using h + +lemma scalarVariance_lipschitz (x y : ℝ) : |scalarVariance y - scalarVariance x| ≤ 2*|y-x| := by + have h1 := tanh_lipschitz x y + have h2 : |Real.tanh y + Real.tanh x| ≤ 2 := + (abs_add_le _ _).trans (by linarith [Real.abs_tanh_lt_one x, Real.abs_tanh_lt_one y]) + have he : scalarVariance y - scalarVariance x = + -(Real.tanh y - Real.tanh x) * (Real.tanh y + Real.tanh x) := by + unfold scalarVariance + ring + rw [he, abs_mul, abs_neg] + nlinarith [mul_le_mul h1 h2 (abs_nonneg _) (abs_nonneg _)] + +lemma tanh_linear_remainder (x y : ℝ) : + |Real.tanh y - Real.tanh x - scalarVariance x * (y-x)| ≤ 2 * |y-x| ^ 2 := by + let f (z : ℝ) := Real.tanh z - Real.tanh x - scalarVariance x * (z-x) + have hd (z : ℝ) : HasDerivAt f (scalarVariance z - scalarVariance x) z := by + convert! ((tanh_hasDerivAt z).sub_const (Real.tanh x)).sub + (((hasDerivAt_id z).sub_const x).const_mul (scalarVariance x)) using 1 + simp only [mul_one] + have hb (z : ℝ) (hz : z ∈ segment ℝ x y) : ‖scalarVariance z - scalarVariance x‖ ≤ + 2 * |y-x| := by + have hh : |z-x| ≤ |y-x| := by simpa only [Real.norm_eq_abs] using norm_sub_le_of_mem_segment hz + simpa only [Real.norm_eq_abs] using (scalarVariance_lipschitz x z).trans + (mul_le_mul_of_nonneg_left hh (by norm_num)) + have h := Convex.norm_image_sub_le_of_norm_hasDerivWithin_le + (fun z (_ : z ∈ segment ℝ x y) => (hd z).hasDerivWithinAt) hb + (convex_segment x y) (left_mem_segment ℝ x y) (right_mem_segment ℝ x y) + simpa only [f, sub_self, mul_zero, sub_zero, Real.norm_eq_abs, pow_two, mul_assoc] using h + +lemma cosh_le_exp_abs (x : ℝ) : Real.cosh x ≤ Real.exp |x| := by + rw [Real.cosh_eq] + have h1 := Real.exp_le_exp.mpr (le_abs_self x) + have h2 := Real.exp_le_exp.mpr (neg_le_abs x) + linarith + +lemma cosh_shift_le (x y : ℝ) : Real.cosh y ≤ Real.exp |y-x| * Real.cosh x := by + rw [Real.cosh_eq, Real.cosh_eq] + have h1 : Real.exp y ≤ Real.exp |y-x| * Real.exp x := by + rw [← Real.exp_add] + apply Real.exp_le_exp.mpr + linarith [le_abs_self (y-x)] + have h2 : Real.exp (-y) ≤ Real.exp |y-x| * Real.exp (-x) := by + rw [← Real.exp_add] + apply Real.exp_le_exp.mpr + linarith [neg_le_abs (y-x)] + nlinarith + +lemma sinh_abs_le (d : ℝ) : |Real.sinh d| ≤ |d| * Real.exp |d| := by + have hb (z : ℝ) (hz : z ∈ segment ℝ 0 d) : ‖Real.cosh z‖ ≤ Real.exp |d| := by + have hh : |z| ≤ |d| := by + simpa only [sub_zero, Real.norm_eq_abs] using norm_sub_le_of_mem_segment hz + rw [Real.norm_eq_abs, abs_of_pos (Real.cosh_pos z)] + exact (cosh_le_exp_abs z).trans (Real.exp_le_exp.mpr hh) + have h := Convex.norm_image_sub_le_of_norm_hasDerivWithin_le + (fun z (_ : z ∈ segment ℝ 0 d) => (Real.hasDerivAt_sinh z).hasDerivWithinAt) hb + (convex_segment 0 d) (left_mem_segment ℝ 0 d) (right_mem_segment ℝ 0 d) + simpa only [Real.sinh_zero, sub_zero, Real.norm_eq_abs, mul_comm] using h + +lemma tanh_difference_eq (x y : ℝ) : Real.tanh y - Real.tanh x = + Real.sinh (y-x) / (Real.cosh y * Real.cosh x) := by + rw [Real.tanh_eq_sinh_div_cosh, Real.tanh_eq_sinh_div_cosh, Real.sinh_sub] + field_simp + +lemma tanh_difference_variance_le (x y : ℝ) : + |Real.tanh y - Real.tanh x| ≤ |y-x| * Real.exp (2*|y-x|) * scalarVariance y := by + have hc := cosh_shift_le x y + have hs := sinh_abs_le (y-x) + have hp := mul_le_mul hs hc (Real.cosh_pos y).le + (mul_nonneg (abs_nonneg _) (Real.exp_pos _).le) + rw [scalarVariance_eq, tanh_difference_eq, abs_div, + abs_of_pos (mul_pos (Real.cosh_pos y) (Real.cosh_pos x))] + rw [mul_one_div, div_le_div_iff₀ (mul_pos (Real.cosh_pos y) (Real.cosh_pos x)) + (sq_pos_of_pos (Real.cosh_pos y))] + have he : Real.exp (2*|y-x|) = Real.exp |y-x| * Real.exp |y-x| := by + rw [two_mul, Real.exp_add] + rw [he] + have hh := mul_le_mul_of_nonneg_right hp (Real.cosh_pos y).le + nlinarith + +lemma field_flip_general {n : ℕ} (J : Interaction n) (x : Spin n) (i j : Fin n) : + field J (flip x i) j = field J x j - 2 * J j i * spin x i := by + simp only [field, spin_flip, mul_sub, Finset.sum_sub_distrib] + simp [mul_ite] + ring + +lemma halfDiff_as_flip {n : ℕ} (f : Observables n) (x : Spin n) (i : Fin n) : + halfDiff i f x = spin x i * (f x - f (flip x i)) / 2 := by + have hx := replace_self x i + cases hi : x i <;> simp only [hi] at hx + · simp only [spin, hi, Bool.false_eq_true, ↓reduceIte, flip, Bool.not_false, halfDiff] + rw [hx]; ring + · simp only [spin, hi, ↓reduceIte, flip, Bool.not_true, halfDiff] + rw [hx]; ring + +lemma abs_spin_eq_one {n : ℕ} (x : Spin n) (i : Fin n) : |spin x i| = 1 := by + cases hi : x i <;> simp [spin, hi] + +lemma abs_field_change {n : ℕ} (J : Interaction n) (x : Spin n) (i j : Fin n) : + |field J x j - field J (flip x i) j| = 2 * |J j i| := by + rw [field_flip_general] + ring_nf + simp [abs_mul, abs_spin_eq_one, mul_comm] + +lemma influence_error_le {n : ℕ} (J : Interaction n) (x : Spin n) (i j : Fin n) : + |influence J x i j - J j i * siteVariance J x j| ≤ 4 * J j i ^ 2 := by + + have hr := tanh_linear_remainder (field J x j) (field J (flip x i) j) + have he : influence J x i j - J j i * siteVariance J x j = + -(spin x i / 2) * (Real.tanh (field J (flip x i) j) - Real.tanh (field J x j) - + scalarVariance (field J x j) * (field J (flip x i) j - field J x j)) := by + simp only [influence, halfDiff_as_flip, mean, siteVariance, scalarVariance, field_flip_general] + linear_combination J j i * (1 - Real.tanh (field J x j) ^ 2) * (spin_sq x i) + rw [he, abs_mul, abs_neg, abs_div, abs_spin_eq_one] + norm_num only [abs_of_pos (show (0:ℝ) < 2 by norm_num)] + have ha : |field J (flip x i) j - field J x j| = 2 * |J j i| := by + rw [abs_sub_comm, abs_field_change] + rw [ha] at hr + nlinarith [sq_abs (J j i)] + +lemma influence_variance_le {n : ℕ} (J : Interaction n) (x : Spin n) (i j : Fin n) : + |influence J x i j| ≤ |J j i| * Real.exp (4*|J j i|) * siteVariance J x j := by + have h := tanh_difference_variance_le (field J (flip x i) j) (field J x j) + rw [abs_field_change] at h + rw [influence, halfDiff_as_flip, abs_div, abs_mul, abs_spin_eq_one, one_mul] + norm_num only [abs_of_pos (show (0:ℝ) < 2 by norm_num)] + change |Real.tanh (field J x j) - Real.tanh (field J (flip x i) j)| / 2 ≤ _ + change _ ≤ |J j i| * Real.exp (4*|J j i|) * scalarVariance (field J x j) + have he : 2 * (2 * |J j i|) = 4*|J j i| := by ring + rw [he] at h + linarith + +lemma siteVariance_sq_le_jumpWeight {n : ℕ} (J : Interaction n) (x : Spin n) (j : Fin n) : + siteVariance J x j ^ 2 ≤ 2 * jumpWeight J x j := by + have hv := siteVariance_pos J x j + have hv1 := siteVariance_le_one J x j + have hw := jumpWeight_pos J x j + have hm : mean J x j * spin x j ≤ 1 := by + have ha : |mean J x j * spin x j| < 1 := by + simpa only [mean, abs_mul, abs_spin_eq_one, mul_one] using Real.abs_tanh_lt_one (field J x j) + exact (le_abs_self _).trans ha.le + have he : siteVariance J x j = jumpWeight J x j * (1 + mean J x j * spin x j) := by + unfold siteVariance jumpWeight + have hs := spin_sq x j + nlinarith + have h2 := mul_le_mul_of_nonneg_left (show 1 + mean J x j * spin x j ≤ 2 by linarith) hw.le + rw [← he] at h2 + nlinarith + +lemma influence_weighted_entry_le {n : ℕ} (J : Interaction n) (x : Spin n) (i j : Fin n) + (c : ℝ) (hc : |J j i| ≤ c) : + influence J x i j ^ 2 / jumpWeight J x j ≤ 2 * Real.exp (8*c) * J j i ^ 2 := by + have h := influence_variance_le J x i j + have h' : |influence J x i j| ≤ |J j i| * Real.exp (4*c) * siteVariance J x j := by + apply h.trans + apply mul_le_mul_of_nonneg_right _ (siteVariance_pos J x j).le + apply mul_le_mul_of_nonneg_left _ (abs_nonneg _) + exact Real.exp_le_exp.mpr (mul_le_mul_of_nonneg_left hc (by norm_num)) + have hs := sq_le_sq₀ (abs_nonneg (influence J x i j)) + (mul_nonneg (mul_nonneg (abs_nonneg _) (Real.exp_pos _).le) (siteVariance_pos J x j).le) |>.mpr h' + simp only [sq_abs, mul_pow] at hs + have hv := mul_le_mul_of_nonneg_left (siteVariance_sq_le_jumpWeight J x j) + (mul_nonneg (sq_nonneg (J j i)) (sq_nonneg (Real.exp (4*c)))) + have he : Real.exp (4*c)^2 = Real.exp (8*c) := by rw [← Real.exp_nat_mul]; congr 1; ring + rw [he] at hs hv + apply (div_le_iff₀ (jumpWeight_pos J x j)).mpr + nlinarith + +lemma influence_weighted_row_le {n : ℕ} (J : Interaction n) (x : Spin n) + (c M : ℝ) (hc : ∀ i j, |J i j| ≤ c) (hM : ∀ i, ∑ j, J j i ^ 2 ≤ M) (i : Fin n) : + ∑ j, influence J x i j ^ 2 / jumpWeight J x j ≤ 2 * Real.exp (8*c) * M := by + calc + _ ≤ ∑ j, 2 * Real.exp (8*c) * J j i ^ 2 := + Finset.sum_le_sum (fun j _ => influence_weighted_entry_le J x i j c (hc j i)) + _ = 2 * Real.exp (8*c) * ∑ j, J j i ^ 2 := by rw [Finset.mul_sum] + _ ≤ _ := mul_le_mul_of_nonneg_left (hM i) (by positivity) + +lemma influence_error_quadratic_le {n : ℕ} (J : Interaction n) (hJ : ∀ i j, J i j = J j i) + (x : Spin n) (u : Fin n → ℝ) (M : ℝ) (hM : ∀ i, ∑ j, J j i ^ 2 ≤ M) : + |∑ i, ∑ j, u i * (influence J x i j - J j i * siteVariance J x j) * u j| ≤ + 4 * M * ∑ i, u i ^ 2 := by + have he (i j : Fin n) : + |u i * (influence J x i j - J j i * siteVariance J x j) * u j| ≤ + 2 * J j i ^ 2 * (u i ^ 2 + u j ^ 2) := by + rw [abs_mul, abs_mul] + have hm := mul_le_mul_of_nonneg_right + (mul_le_mul_of_nonneg_left (influence_error_le J x i j) (abs_nonneg (u i))) + (abs_nonneg (u j)) + have hs : 2 * |u i| * |u j| ≤ u i ^ 2 + u j ^ 2 := by + nlinarith [sq_nonneg (|u i|-|u j|), sq_abs (u i), sq_abs (u j)] + have hh := mul_le_mul_of_nonneg_left hs (show 0 ≤ 2 * J j i ^ 2 by positivity) + nlinarith + have ha : |∑ i, ∑ j, u i * (influence J x i j - J j i * siteVariance J x j) * u j| ≤ + ∑ i, ∑ j, 2 * J j i ^ 2 * (u i ^ 2 + u j ^ 2) := by + exact (Finset.abs_sum_le_sum_abs _ _).trans (Finset.sum_le_sum (fun i _ => + (Finset.abs_sum_le_sum_abs _ _).trans (Finset.sum_le_sum (fun j _ => he i j)))) + have hr : (∑ i, ∑ j, J j i ^ 2 * u i ^ 2) ≤ M * ∑ i, u i ^ 2 := by + calc + _ = ∑ i, (∑ j, J j i ^ 2) * u i ^ 2 := by simp_rw [Finset.sum_mul] + _ ≤ ∑ i, M * u i ^ 2 := Finset.sum_le_sum (fun i _ => + mul_le_mul_of_nonneg_right (hM i) (sq_nonneg _)) + _ = _ := (Finset.mul_sum _ _ _).symm + have hc : (∑ i, ∑ j, J j i ^ 2 * u j ^ 2) ≤ M * ∑ i, u i ^ 2 := by + rw [Finset.sum_comm] + simpa only [hJ] using hr + have hs : (∑ i, ∑ j, 2 * J j i ^ 2 * (u i ^ 2 + u j ^ 2)) = + 2 * (∑ i, ∑ j, J j i ^ 2 * u i ^ 2) + + 2 * (∑ i, ∑ j, J j i ^ 2 * u j ^ 2) := by + simp_rw [mul_add, mul_assoc, Finset.sum_add_distrib, ← Finset.mul_sum] + rw [hs] at ha + linarith + +lemma influence_quadratic_le {n : ℕ} (J : Interaction n) (hJ : ∀ i j, J i j = J j i) + (x : Spin n) (u : Fin n → ℝ) (B M : ℝ) (hB : 0 ≤ B) + (hJB : ∀ a b : Fin n → ℝ, |∑ i, ∑ j, a i * J j i * b j| ≤ + B / 2 * ((∑ i, a i ^ 2) + ∑ j, b j ^ 2)) + (hM : ∀ i, ∑ j, J j i ^ 2 ≤ M) : + ∑ i, u i * (∑ j, influence J x i j * u j) ≤ (B + 4*M) * ∑ i, u i ^ 2 := by + have hv : (∑ j, (siteVariance J x j * u j)^2) ≤ ∑ j, u j ^ 2 := by + apply Finset.sum_le_sum + intro j _ + have hp := siteVariance_pos J x j + have h1 := siteVariance_le_one J x j + have hv : siteVariance J x j ^ 2 ≤ 1 := by nlinarith + simpa only [mul_pow, one_mul] using mul_le_mul_of_nonneg_right hv (sq_nonneg (u j)) + have hb := hJB u (fun j => siteVariance J x j * u j) + have hb' : (∑ i, ∑ j, u i * J j i * (siteVariance J x j * u j)) ≤ B * ∑ i, u i ^ 2 := by + have hmul := mul_le_mul_of_nonneg_left hv (show 0 ≤ B/2 by positivity) + linarith [le_abs_self (∑ i, ∑ j, u i * J j i * (siteVariance J x j * u j))] + have he := influence_error_quadratic_le J hJ x u M hM + have hs : (∑ i, u i * (∑ j, influence J x i j * u j)) = + (∑ i, ∑ j, u i * J j i * (siteVariance J x j * u j)) + + (∑ i, ∑ j, u i * (influence J x i j - J j i * siteVariance J x j) * u j) := by + simp_rw [Finset.mul_sum] + rw [← Finset.sum_add_distrib] + apply Finset.sum_congr rfl + intro i _ + rw [← Finset.sum_add_distrib] + apply Finset.sum_congr rfl + intro j _ + ring + rw [hs] + have hh := le_abs_self (∑ i, ∑ j, u i * (influence J x i j - J j i * siteVariance J x j) * u j) + nlinarith + +end SKGapCutoff + +open scoped BigOperators NNReal ENNReal +open MeasureTheory Metric Set + +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/SelectionDeficit.lean b/lean/OAI/Probability/SKGap/Localization/SelectionDeficit.lean new file mode 100644 index 0000000000000000000000000000000000000000..70ca25ee11c8b14d794e33a99052ae9e2d951aad --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/SelectionDeficit.lean @@ -0,0 +1,125 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.LocalExtraction + +namespace OAI + +section + +noncomputable section +open scoped BigOperators +namespace SKGapCutoff.Recipe +open Primary Static +variable {n : ℕ} + +lemma selection_deficit_l2 (hn : 0C k x) d then P x else 0)≤T/(n:ℝ)) : + (∑x,P x*(cutoffDeficit (fun k=>C k x) d*H x)^2)≤B^2*T := by + classical + let D:=fun x=>cutoffDeficit (fun k=>C k x) d + have hD x : 0≤D x ∧ D x≤1:=cutoffDeficit_bounds _ _ (fun k=>hC k x) + have hn0 : (n:ℝ)≠0:=ne_of_gt (Nat.cast_pos.mpr hn) + calc + _ ≤ ∑x,(if 0spin x i-Real.tanh (r i))≤2*Real.sqrt (n:ℝ) := by + apply (vectorNorm_sub (spin x) (fun i=>Real.tanh (r i))).trans + have hs : vectorNorm (spin x)≤Real.sqrt (n:ℝ) := by + simpa only [vectorNorm_const,abs_one,one_mul] using + (vectorNorm_mono (u:=spin x) (v:=fun _=>1) (fun i=>by simp [spin];split_ifs <;> norm_num)) + exact (add_le_add hs (vectorNorm_tanh r)).trans_eq (by ring) + have hpair:=vectorPair_abs (fun _ : Spin n=>fun i=>spin x i-Real.tanh (r i)) (fun _=>e) x + change |∑i,(spin x i-Real.tanh (r i))*e i|≤_ at hpair + exact hpair.trans ((mul_le_mul hv he (vectorNorm_nonneg _) (by positivity)).trans_eq (mul_one _)) + +universe u +variable {Ω : Type u} {N : Ω→ℕ} {j R B W C ρ ε : ℝ} +variable {J : ∀a,Interaction (N a)} {h : ∀a,Fin (N a)→ℝ} + +theorem gibbs_residual_selection_deficit (m : ℕ) (hρ : 0<ρ) (hε : 0<ε) + (hm : 2<(m:ℝ)*ρ^2/4) (he : 2*(2*m:ℕ)*ε≤1) + (hR : 0≤R) (hB : 0≤B) (hW : 0≤W) (hC : 0≤C) + (hn : ∀a,0residualCutoff ρ j (J a) (h a) k x) (2*m-1)* + (∑i,(spin x i-Real.tanh (r i))*e i))|≤D*starNorm (fieldGibbs (J a) (h a)) G := by + obtain ⟨T,U,hT,hU,ht⟩:=gibbs_residual_selection_tail (h:=h) m hρ hε hm he hR hB hW hC hn hJ hdiag hevent + refine ⟨Real.sqrt (2^2*T),Real.sqrt_nonneg _,?_⟩ + intro a r e he G + apply tested_l2_to_star _ _ _ (fun x=>(fieldGibbs_pos _ _ _).le) (by positivity) + exact selection_deficit_l2 (hn a) _ _ _ (2*m-1) (fun x=>(fieldGibbs_pos _ _ _).le) + (fun k x=>residualCutoff_bounds ρ j (J a) (h a) k x) (by norm_num) + (spin_root_direction_size r e he) (ht a).1 + +end SKGapCutoff.Recipe + +end +end + +section + +noncomputable section +open scoped BigOperators +namespace SKGapCutoff.Recipe +open Primary Static +universe u +variable {Ω : Type u} {N : Ω→ℕ} + +lemma uniform_cutoff_partition {P H : ∀a,Observables (N a)} + {C F : ℕ→∀a,Observables (N a)} (d : ℕ) + (hP : ∀a x,0≤P a x) + (hmult : ∀kH a x-F k a x)) + (hlocal : ∀kC k a x*F k a x)) + (hdef : UniformWeak P (fun a x=>cutoffDeficit (fun k=>C k a x) d*H a x)) : + UniformWeak P H := by + classical + let Q:=fun k a x=>∏l∈Finset.range k,(1-C l a x) + have hQ (k : ℕ) (hk : kcutoffWeight (fun l=>C l a x) k*H a x) := by + have hr:=(hres k hk).mul hP (cutoffWeight_uniform k (fun l hl=>hmult l (lt_of_le_of_lt hl hk))) + have hf:=(hlocal k hk).mul hP (hQ k hk) + apply (hr.add hf).congr + intro a x + dsimp [cutoffWeight,Q] + ring + have hs:=(UniformWeak.finset_sum (Finset.range d) (fun k hk=>hw k (Finset.mem_range.mp hk))).add hdef + apply hs.congr + intro a x + rw [←Finset.sum_mul] + dsimp [cutoffDeficit] + ring + +end SKGapCutoff.Recipe + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/SelectionPartition.lean b/lean/OAI/Probability/SKGap/Localization/SelectionPartition.lean new file mode 100644 index 0000000000000000000000000000000000000000..a02a6a00a9675807874963f23e2a1508e0c9768e --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/SelectionPartition.lean @@ -0,0 +1,97 @@ +import Mathlib +import OAI.Probability.SKGap.Terminal.FinitePairTail +import OAI.Probability.SKGap.Localization.SmoothSelection + +namespace OAI + +section + +noncomputable section +open scoped BigOperators +namespace SKGapCutoff.Recipe +open Primary Static +variable {n : ℕ} + +def cutoffWeight (C : ℕ→ℝ) (k : ℕ) : ℝ := C k*∏i∈Finset.range k,(1-C i) +def cutoffDeficit (C : ℕ→ℝ) (d : ℕ) : ℝ := 1-∑k∈Finset.range d,cutoffWeight C k + +lemma cutoffDeficit_prod (C : ℕ→ℝ) (d : ℕ) : + cutoffDeficit C d=∏k∈Finset.range d,(1-C k) := by + induction d with + | zero=>simp [cutoffDeficit] + | succ d ih=> + simp only [cutoffDeficit,Finset.sum_range_succ] at ih ⊢ + rw [Finset.prod_range_succ,cutoffWeight,←ih] + ring + +lemma cutoffDeficit_bounds (C : ℕ→ℝ) (d : ℕ) (hC : ∀k,0≤C k ∧ C k≤1) : + 0≤cutoffDeficit C d ∧ cutoffDeficit C d≤1 := by + rw [cutoffDeficit_prod] + refine ⟨Finset.prod_nonneg (fun k _=>sub_nonneg.mpr (hC k).2),?_⟩ + exact Finset.prod_le_one₀ (fun k _=>sub_nonneg.mpr (hC k).2) (fun k _=>by linarith [(hC k).1]) + +lemma cutoffWeight_bounds (C : ℕ→ℝ) (k : ℕ) (hC : ∀k,0≤C k ∧ C k≤1) : + 0≤cutoffWeight C k ∧ cutoffWeight C k≤C k := by + have H:=cutoffDeficit_bounds C k hC + rw [cutoffDeficit_prod] at H + exact ⟨mul_nonneg (hC k).1 H.1,mul_le_of_le_one_right (hC k).1 H.2⟩ + +lemma cutoffDeficit_zero_of_one {C : ℕ→ℝ} {d k : ℕ} (hk : kresidualCutoff ρ j J h k x) (2*m-1)) : + ∃k:Fin (2*m),ε < |primaryPair j J h k x|/Real.sqrt (n:ℝ) := by + by_contra hh + have hs : ∀k<2*m,|primaryPair j J h k x|/Real.sqrt (n:ℝ)≤ε := by + intro k hk + exact le_of_not_gt (fun H=>hh ⟨⟨k,hk⟩,H⟩) + obtain ⟨k,hk,h0,h1⟩:=small_residual_pair hn j J h m x hρ hm he hs + have hC:=residualCutoff_one hn hρ J h (2*k) x h0 h1 + have hz:=cutoffDeficit_zero_of_one (C:=fun k=>residualCutoff ρ j J h k x) (by omega : 2*k<2*m-1) hC + linarith + +lemma weighted_indicator_mono (w : Spin n→ℝ) (hw : ∀x,0≤w x) (P Q : Spin n→Prop) + [DecidablePred P] [DecidablePred Q] (hh : ∀x,P x→Q x) : + (∑x,if P x then w x else 0)≤∑x,if Q x then w x else 0 := by + apply Finset.sum_le_sum + intro x _ + split_ifs with hp hq + · exact le_rfl + · exact False.elim (hq (hh x hp)) + · exact hw x + · exact le_rfl + +universe u +variable {Ω : Type u} {N : Ω→ℕ} {j R B W C ρ ε : ℝ} +variable {J : ∀a,Interaction (N a)} {h : ∀a,Fin (N a)→ℝ} + +theorem gibbs_residual_selection_tail (m : ℕ) (hρ : 0<ρ) (hε : 0<ε) + (hm : 2<(m:ℝ)*ρ^2/4) (he : 2*(2*m:ℕ)*ε≤1) + (hR : 0≤R) (hB : 0≤B) (hW : 0≤W) (hC : 0≤C) + (hn : ∀a,0residualCutoff ρ j (J a) (h a) k x) (2*m-1) + then fieldGibbs (J a) (h a) x else 0)≤C₁/(N a:ℝ) ∧ + ∀f : Observables (N a), + (∑x,if 0residualCutoff ρ j (J a) (h a) k x) (2*m-1) + then fieldGibbs (J a) (h a) x*(f x)^2 else 0)≤ + C₂/Real.sqrt (N a:ℝ)*starSquared (fieldGibbs (J a) (h a)) f := by + classical + obtain ⟨C₁,C₂,hC₁,hC₂,ht⟩:=gibbs_pairing_tail (h:=h) (2*m) hε hR hB hW hC hn hJ hdiag hevent + refine ⟨C₁,C₂,hC₁,hC₂,fun a=>⟨?_,fun f=>?_⟩⟩ + · exact (weighted_indicator_mono _ (fun x=>(fieldGibbs_pos _ _ _).le) _ _ + (fun x=>residualCutoff_deficit_inclusion (hn a) hρ (J a) (h a) m x hm he)).trans (ht a).1 + · exact (weighted_indicator_mono _ (fun x=>mul_nonneg (fieldGibbs_pos _ _ _).le (sq_nonneg _)) _ _ + (fun x=>residualCutoff_deficit_inclusion (hn a) hρ (J a) (h a) m x hm he)).trans ((ht a).2 f) + +end SKGapCutoff.Recipe + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/SemicircleDensity.lean b/lean/OAI/Probability/SKGap/Localization/SemicircleDensity.lean new file mode 100644 index 0000000000000000000000000000000000000000..f373b0bf76400e0b144f84f03072bde11a3de205 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/SemicircleDensity.lean @@ -0,0 +1,349 @@ +import Mathlib +import OAI.Probability.SKGap.Model + +namespace OAI + +section +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open scoped BigOperators +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open scoped BigOperators +open scoped BigOperators NNReal ENNReal +open MeasureTheory Metric Set +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators NNReal ENNReal Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Set +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators ENNReal NNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Matrix +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators ENNReal NNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal +open scoped BigOperators +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise NNReal ENNReal +open scoped BigOperators +open Filter Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal Topology +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Set Matrix +open scoped BigOperators NNReal ENNReal Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open Filter MeasureTheory ProbabilityTheory +open scoped Topology NNReal ENNReal +open Filter MeasureTheory ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter +open scoped Topology NNReal ENNReal +open MeasureTheory Filter ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter +open scoped Topology +open MeasureTheory Filter ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter ProbabilityTheory ContinuousLinearMap +open scoped Topology NNReal ENNReal +open Filter MeasureTheory ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter +open scoped BigOperators Topology +open MeasureTheory Filter +open scoped BigOperators Topology +open MeasureTheory Filter +open scoped BigOperators Topology +open MeasureTheory Filter +open scoped BigOperators Topology +open MeasureTheory Filter +open scoped BigOperators Topology +open Filter Set Metric +open scoped Topology RealInnerProductSpace +open scoped BigOperators +open ContinuousLinearMap +open scoped BigOperators +open ContinuousLinearMap +open scoped Topology Interval +open MeasureTheory +open MeasureTheory +open scoped BigOperators Topology Interval +open MeasureTheory +open scoped BigOperators Topology Interval +open scoped Topology +open MeasureTheory +open scoped BigOperators Topology Interval +open scoped BigOperators Topology +open MeasureTheory +open scoped BigOperators Topology Interval RealInnerProductSpace +open MeasureTheory Filter +open scoped BigOperators Topology Interval +open MeasureTheory Filter +open scoped Topology +namespace SKGapCutoff + +noncomputable def semicircleDensity (u : ℝ) : ℝ := + Real.sqrt (4-u^2)/(2*Real.pi) +noncomputable def semicircleMeasure : Measure ℝ := + volume.withDensity (fun u => ENNReal.ofReal (semicircleDensity u)) + +lemma semicircleDensity_continuous : Continuous semicircleDensity := by + unfold semicircleDensity + fun_prop +lemma semicircleDensity_pos {u : ℝ} (hu : u ∈ Set.Ioo (-2:ℝ) 2) : + 0 < semicircleDensity u := by + apply div_pos _ (mul_pos (by norm_num) Real.pi_pos) + apply Real.sqrt_pos.mpr + nlinarith only [hu.1,hu.2,mul_pos (sub_pos.mpr hu.1) (sub_pos.mpr hu.2)] + +instance semicircleMeasure_locallyFinite : IsLocallyFiniteMeasure semicircleMeasure := + IsLocallyFiniteMeasure.withDensity_ofReal semicircleDensity_continuous + +lemma semicircleMeasure_right_neighborhood {U : Set ℝ} (hU : IsOpen U) (h2 : (2:ℝ) ∈ U) : + 0 < semicircleMeasure (U ∩ Set.Icc (-2:ℝ) 2) := by + have hcl : (2:ℝ) ∈ closure (Set.Ioo (-2:ℝ) 2) := by + rw [closure_Ioo (by norm_num : (-2:ℝ) ≠ 2)] + norm_num + have hn : (U ∩ Set.Ioo (-2:ℝ) 2).Nonempty := + mem_closure_iff.mp hcl U hU h2 + have hp := (hU.inter isOpen_Ioo).measure_pos volume hn + apply pos_iff_ne_zero.mpr + intro hz + have hz' := (withDensity_apply_eq_zero + (ENNReal.measurable_ofReal.comp semicircleDensity_continuous.measurable)).mp hz + have hs : U ∩ Set.Ioo (-2:ℝ) 2 ⊆ + {u | ENNReal.ofReal (semicircleDensity u) ≠ 0} ∩ (U ∩ Set.Icc (-2:ℝ) 2) := by + intro u hu + exact ⟨ne_of_gt (ENNReal.ofReal_pos.mpr (semicircleDensity_pos hu.2)), + hu.1,hu.2.1.le,hu.2.2.le⟩ + exact hp.ne' (measure_mono_null hs hz') + +lemma semicircleDensity_eq_zero_outside (u : ℝ) (hu : u ∉ Set.Icc (-2:ℝ) 2) : + semicircleDensity u=0 := by + have hneg : 4-u^2 ≤ 0 := by + simp only [Set.mem_Icc,not_and_or,not_le] at hu + rcases hu with h | h <;> nlinarith [sq_nonneg (u+2),sq_nonneg (u-2)] + simp only [semicircleDensity,Real.sqrt_eq_zero_of_nonpos hneg,zero_div] + +lemma semicircleDensity_integrable : Integrable semicircleDensity volume := by + apply semicircleDensity_continuous.integrable_of_hasCompactSupport + apply HasCompactSupport.of_support_subset_isCompact isCompact_Icc + intro u hu + by_contra hh + exact hu (semicircleDensity_eq_zero_outside u hh) + +lemma integral_semicircleDensity : (∫ u, semicircleDensity u)=1 := by + have he (u : ℝ) : Real.sqrt (4-(2*u)^2)=2*Real.sqrt (1-u^2) := by + have h : 4-(2*u)^2=(2:ℝ)^2*(1-u^2) := by ring + rw [h,Real.sqrt_mul (sq_nonneg (2:ℝ))] + norm_num + have hh := intervalIntegral.smul_integral_comp_mul_left + (a := (-1:ℝ)) (b := (1:ℝ)) (fun u : ℝ => Real.sqrt (4-u^2)) (2:ℝ) + simp only [he,intervalIntegral.integral_const_mul,smul_eq_mul, + integral_sqrt_one_sub_sq] at hh + norm_num only [mul_neg,mul_one] at hh + have hi : (∫ u in (-2:ℝ)..2, semicircleDensity u)=1 := by + unfold semicircleDensity + rw [intervalIntegral.integral_div,← hh] + field_simp + rw [← setIntegral_eq_integral_of_forall_compl_eq_zero semicircleDensity_eq_zero_outside] + rw [integral_Icc_eq_integral_Ioc,← intervalIntegral.integral_of_le (by norm_num : (-2:ℝ) ≤ 2)] + exact hi + +instance semicircleMeasure_probability : IsProbabilityMeasure semicircleMeasure where + measure_univ := by + rw [semicircleMeasure,withDensity_apply _ MeasurableSet.univ,Measure.restrict_univ, + ← ofReal_integral_eq_lintegral_ofReal semicircleDensity_integrable] + · rw [integral_semicircleDensity] + norm_num + · exact Eventually.of_forall (fun u => div_nonneg (Real.sqrt_nonneg _) (mul_pos (by norm_num) Real.pi_pos).le) + +noncomputable def spinEdgeWeight (m : ℕ) (u : ℝ) : ℝ := (((u+2)/4)^2)^m +lemma spinEdgeWeight_eq_squared (m : ℕ) (u : ℝ) : + spinEdgeWeight m u = (((u+2)/4)^m)^2 := by + simp only [spinEdgeWeight,← pow_mul,Nat.mul_comm 2 m] + +lemma spinCovariance_denominator_pos {β : ℝ} (hβ0 : 0 ≤ β) (hβ1 : β < 1) + {u : ℝ} (hu : u ∈ Set.Icc (-2:ℝ) 2) : 0 < 1-β*u+β^2 := by + have hs : 0 < (1-β)^2 := sq_pos_of_pos (sub_pos.mpr hβ1) + nlinarith only [hs,mul_nonneg hβ0 (sub_nonneg.mpr hu.2)] + +lemma spin_edge_localization {β : ℝ} (hβ0 : 0 ≤ β) (hβ1 : β < 1) : + Tendsto (fun m : ℕ => + (∫ u in Set.Icc (-2:ℝ) 2, spinEdgeWeight m u ∂semicircleMeasure)⁻¹ * + ∫ u in Set.Icc (-2:ℝ) 2, spinEdgeWeight m u/(1-β*u+β^2) ∂semicircleMeasure) + atTop (nhds ((1-β)^2)⁻¹) := by + have hc : ContinuousOn (fun u : ℝ => ((u+2)/4)^2) (Set.Icc (-2:ℝ) 2) := by + fun_prop + have hmax (u : ℝ) (hu : u ∈ Set.Icc (-2:ℝ) 2) (hne : u ≠ 2) : + ((u+2)/4)^2 < ((2+2)/4:ℝ)^2 := by + have hl : 0 ≤ (u+2)/4 := by linarith [hu.1] + have hh : (u+2)/4 < 1 := by + have := lt_of_le_of_ne hu.2 hne + linarith + nlinarith only [hl,hh,sq_nonneg ((u+2)/4-1)] + have hg : ContinuousOn (fun u : ℝ => (1-β*u+β^2)⁻¹) (Set.Icc (-2:ℝ) 2) := by + apply ContinuousOn.inv₀ + · fun_prop + · intro u hu + exact (spinCovariance_denominator_pos hβ0 hβ1 hu).ne' + have hh := tendsto_setIntegral_pow_smul_of_unique_maximum_of_isCompact_of_measure_nhdsWithin_pos + (μ := semicircleMeasure) (x₀ := (2:ℝ)) isCompact_Icc + (fun U hU h2 => semicircleMeasure_right_neighborhood hU h2) hc hmax + (fun u _ => sq_nonneg ((u+2)/4)) (by norm_num) (by norm_num) + (hg.integrableOn_compact isCompact_Icc) (hg 2 (by norm_num)) + have he : 1-β*2+β^2=(1-β)^2 := by ring + simpa only [smul_eq_mul,spinEdgeWeight,div_eq_mul_inv,he] using hh + +theorem spin_edge_bound_from_polynomial_tests {β rate : ℝ} + (hβ0 : 0 ≤ β) (hβ1 : β < 1) + (htest : ∀ m : ℕ, + rate*(∫ u in Set.Icc (-2:ℝ) 2, spinEdgeWeight m u/(1-β*u+β^2) ∂semicircleMeasure) ≤ + ∫ u in Set.Icc (-2:ℝ) 2, spinEdgeWeight m u ∂semicircleMeasure) : + rate ≤ (1-β)^2 := by + have hp (m : ℕ) : rate*((∫ u in Set.Icc (-2:ℝ) 2, spinEdgeWeight m u ∂semicircleMeasure)⁻¹ * + ∫ u in Set.Icc (-2:ℝ) 2, spinEdgeWeight m u/(1-β*u+β^2) ∂semicircleMeasure) ≤ 1 := by + have hn : 0 ≤ ∫ u in Set.Icc (-2:ℝ) 2, spinEdgeWeight m u ∂semicircleMeasure := by + exact integral_nonneg (fun u => pow_nonneg (sq_nonneg _) _) + calc + _ = (∫ u in Set.Icc (-2:ℝ) 2, spinEdgeWeight m u ∂semicircleMeasure)⁻¹ * + (rate*∫ u in Set.Icc (-2:ℝ) 2, spinEdgeWeight m u/(1-β*u+β^2) ∂semicircleMeasure) := by ring + _ ≤ (∫ u in Set.Icc (-2:ℝ) 2, spinEdgeWeight m u ∂semicircleMeasure)⁻¹ * + (∫ u in Set.Icc (-2:ℝ) 2, spinEdgeWeight m u ∂semicircleMeasure) := + mul_le_mul_of_nonneg_left (htest m) (inv_nonneg.mpr hn) + _ ≤ 1 := by + by_cases hz : (∫ u in Set.Icc (-2:ℝ) 2, spinEdgeWeight m u ∂semicircleMeasure)=0 + · simp [hz] + · rw [inv_mul_cancel₀ hz] + have hh := le_of_tendsto ((spin_edge_localization hβ0 hβ1).const_mul rate) + (Eventually.of_forall hp) + have hpos : 0 < (1-β)^2 := sq_pos_of_pos (sub_pos.mpr hβ1) + exact (div_le_one hpos).mp (by simpa only [div_eq_mul_inv] using hh) + +lemma le_one_of_polynomial_power_bound {r : ℝ} + (hr : ∀ k : ℕ, r^k ≤ (k:ℝ)+1) : r ≤ 1 := by + by_contra h + have hp : 1 < r := lt_of_not_ge h + have hh := (tendsto_pow_const_div_const_pow_of_one_lt 1 hp).add + (tendsto_pow_const_div_const_pow_of_one_lt 0 hp) + have hlim : Tendsto (fun k : ℕ => ((k:ℝ)+1)/r^k) atTop (nhds 0) := by + simpa only [pow_one,pow_zero,← add_div,zero_add] using hh + have he : ∀ k : ℕ, 1 ≤ ((k:ℝ)+1)/r^k := by + intro k + exact (le_div_iff₀ (pow_pos (lt_trans zero_lt_one hp) _)).mpr (by simpa only [one_mul] using hr k) + have hz : (1:ℝ) ≤ 0 := ge_of_tendsto hlim (Eventually.of_forall he) + norm_num at hz + +lemma strict_renewal_bound {β edge : ℝ} (hβ : 0 < β) + (R : ℝ → ℝ) (hR : StrictMonoOn R (Set.Iio edge)) + (hpow : ∀ z < edge, ∀ k : ℕ, (β*R z)^k ≤ (k:ℝ)+1) + {z : ℝ} (hz : z < edge) : β*R z < 1 := by + obtain ⟨z',hzz',hz'⟩ := exists_between hz + exact (mul_lt_mul_of_pos_left (hR hz hz' hzz') hβ).trans_le + (le_one_of_polynomial_power_bound (hpow z' hz')) + +lemma second_renewal_bound {β edge z : ℝ} (hβ0 : 0 < β) (hβ1 : β < 1) + (hedge : edge ≤ (1-β)^2) (hz : z < edge) (R : ℝ → ℝ) + (hstrict : β*R z < 1) (hnegative : z < 0 → R z ≤ 1) : + β^2*R z < 1-z := by + by_cases hzn : z < 0 + · have hh := mul_le_mul_of_nonneg_left (hnegative hzn) (sq_nonneg β) + have hb : β^2 < 1 := by nlinarith + nlinarith only [hh,hb,hzn] + · have hh := mul_lt_mul_of_pos_left hstrict hβ0 + have hb : β < 2*β-β^2 := by nlinarith + nlinarith only [hh,hb,hedge,hz] + +end SKGapCutoff + +open MeasureTheory Filter +open scoped Topology + +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/SemigroupAbs.lean b/lean/OAI/Probability/SKGap/Localization/SemigroupAbs.lean new file mode 100644 index 0000000000000000000000000000000000000000..a4d693b40feed024f05130e38bf0f87896e67b74 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/SemigroupAbs.lean @@ -0,0 +1,291 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.JumpEnergy +import OAI.Probability.SKGap.Localization.LinearObservable + +namespace OAI + +section +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open scoped BigOperators +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open scoped BigOperators +open scoped BigOperators NNReal ENNReal +open MeasureTheory Metric Set +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators NNReal ENNReal Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Set +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators ENNReal NNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Matrix +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators ENNReal NNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal +open scoped BigOperators +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise NNReal ENNReal +open scoped BigOperators +open Filter Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal Topology +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Set Matrix +open scoped BigOperators NNReal ENNReal Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open Filter MeasureTheory ProbabilityTheory +open scoped Topology NNReal ENNReal +open Filter MeasureTheory ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter +open scoped Topology NNReal ENNReal +open MeasureTheory Filter ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter +open scoped Topology +open MeasureTheory Filter ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter ProbabilityTheory ContinuousLinearMap +open scoped Topology NNReal ENNReal +open Filter MeasureTheory ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter +open scoped BigOperators Topology +namespace SKGapCutoff + +lemma semigroup_abs_le_one {n : ℕ} (J : Interaction n) {t : ℝ} (ht : 0 ≤ t) + {f : Observables n} (hf : ∀ x, |f x| ≤ 1) (x : Spin n) : + |semigroup J t f x| ≤ 1 := by + apply abs_le.mpr + constructor + · have h := semigroup_mono J t ht (fun y => (abs_le.mp (hf y)).1) x + simpa only [semigroup_const] using h + · exact semigroup_le_const J t ht (fun y => (abs_le.mp (hf y)).2) x + +lemma halfDiff_abs_le_one {n : ℕ} {f : Observables n} + (hf : ∀ x, |f x| ≤ 1) (x : Spin n) (i : Fin n) : |halfDiff i f x| ≤ 1 := by + have hp := abs_le.mp (hf (replace x i true)) + have hm := abs_le.mp (hf (replace x i false)) + unfold halfDiff + exact abs_le.mpr ⟨by linarith, by linarith⟩ + +lemma backward_energy_budget {n : ℕ} (J : Interaction n) {f : Observables n} + (hf : ∀ x, |f x| ≤ 1) {a T : ℝ} (ha : 0 ≤ a) (haT : a ≤ T) (x : Spin n) : + (∫ s in a..T, semigroup J s (jumpEnergy J (semigroup J (T-s) f)) x) ≤ 1 := by + have hT := ha.trans haT + have hnonneg : 0 ≤ᵐ[volume.restrict (Set.Ioc 0 T)] + (fun s => semigroup J s (jumpEnergy J (semigroup J (T-s) f)) x) := by + filter_upwards [ae_restrict_mem measurableSet_Ioc] with s hs + exact semigroup_nonneg J s hs.1.le _ (jumpEnergy_nonneg J _) x + calc + _ ≤ ∫ s in (0:ℝ)..T, semigroup J s (jumpEnergy J (semigroup J (T-s) f)) x := + intervalIntegral.integral_mono_interval ha haT le_rfl hnonneg + ((interpolated_energy_continuous J f T x).intervalIntegrable 0 T) + _ = semigroup J T (fun y => f y^2) x - (semigroup J T f x)^2 := + (semigroup_variance_integral J f T x).symm + _ ≤ 1 := by + have hb : semigroup J T (fun y => f y^2) x ≤ 1 := by + apply semigroup_le_const J T hT + intro y + nlinarith [sq_abs (f y), hf y, abs_nonneg (f y)] + nlinarith [sq_nonneg (semigroup J T f x)] + +lemma gradient_le_energy_bad {n : ℕ} (J : Interaction n) {f : Observables n} + (hf : ∀ x, |f x| ≤ 1) {w : ℝ} (hw : 0 < w) + (bad : Spin n → Prop) [DecidablePred bad] + (hgood : ∀ x, ¬bad x → ∀ i, w ≤ 1-mean J x i*spin x i) (x : Spin n) : + (∑ i, (halfDiff i f x)^2) ≤ jumpEnergy J f x/(2*w) + (n:ℝ)*(if bad x then 1 else 0) := by + by_cases hx : bad x + · simp only [hx, ↓reduceIte, mul_one] + have hb : (∑ i, (halfDiff i f x)^2) ≤ (n:ℝ) := by + calc + _ ≤ ∑ _i : Fin n, (1:ℝ) := by + apply Finset.sum_le_sum + intro i _ + nlinarith [sq_abs (halfDiff i f x), halfDiff_abs_le_one hf x i, + abs_nonneg (halfDiff i f x)] + _ = _ := by simp + exact hb.trans (le_add_of_nonneg_left (div_nonneg (jumpEnergy_nonneg J f x) (by positivity))) + · simp only [hx, ↓reduceIte, mul_zero, add_zero] + apply (le_div_iff₀ (by positivity : 0 < 2*w)).mpr + unfold jumpEnergy + have hh := Finset.sum_le_sum (s := Finset.univ) (fun i _ => + mul_le_mul_of_nonneg_right (hgood x hx i) (sq_nonneg (halfDiff i f x))) + rw [← Finset.mul_sum] at hh + nlinarith + +lemma backward_gradient_energy_bound {n : ℕ} (J : Interaction n) {f : Observables n} + (hf : ∀ x, |f x| ≤ 1) {s T w p : ℝ} (hs : 0 ≤ s) (hsT : s ≤ T) (hw : 0 < w) + (bad : Spin n → Prop) [DecidablePred bad] + (hgood : ∀ y, ¬bad y → ∀ i, w ≤ 1-mean J y i*spin y i) + (x : Spin n) (hbad : semigroup J s (fun y => if bad y then 1 else 0) x ≤ p) : + semigroup J s (fun y => ∑ i, (halfDiff i (semigroup J (T-s) f) y)^2) x ≤ + semigroup J s (jumpEnergy J (semigroup J (T-s) f)) x/(2*w) + (n:ℝ)*p := by + have hf' := semigroup_abs_le_one J (sub_nonneg.mpr hsT) hf + have hh := semigroup_mono J s hs (gradient_le_energy_bad J hf' hw bad hgood) x + have he : (fun y => jumpEnergy J (semigroup J (T-s) f) y/(2*w)+(n:ℝ)*(if bad y then 1 else 0)) = + (2*w)⁻¹ • jumpEnergy J (semigroup J (T-s) f) + (n:ℝ) • (fun y => if bad y then 1 else 0) := by + funext y + simp only [Pi.add_apply, Pi.smul_apply, smul_eq_mul, div_eq_mul_inv] + ring + rw [he, map_add, map_smul, map_smul] at hh + simp only [Pi.add_apply, Pi.smul_apply, smul_eq_mul] at hh + calc + _ ≤ (2*w)⁻¹ * semigroup J s (jumpEnergy J (semigroup J (T-s) f)) x + + (n:ℝ)*semigroup J s (fun y => if bad y then 1 else 0) x := hh + _ ≤ _ := by + rw [div_eq_mul_inv, mul_comm _ (2*w)⁻¹] + exact add_le_add le_rfl (mul_le_mul_of_nonneg_left hbad (Nat.cast_nonneg n)) + +lemma gradient_bound_from_backward_energy {n : ℕ} (J : Interaction n) + {f : Observables n} (hf : ∀ x, |f x| ≤ 1) {a T w p K η : ℝ} + (ha : 0 ≤ a) (haT : a < T) (hw : 0 < w) (hK : 0 ≤ K) + (bad : Spin n → Prop) [DecidablePred bad] + (hgood : ∀ y, ¬bad y → ∀ i, w ≤ 1-mean J y i*spin y i) + (x : Spin n) + (hbad : ∀ s ∈ Set.Icc a T, semigroup J s (fun y => if bad y then 1 else 0) x ≤ p) + (hprop : ∀ s ∈ Set.Icc a T, + (∑ i, (halfDiff i (semigroup J T f) x)^2) ≤ + K * semigroup J s (fun y => ∑ i, (halfDiff i (semigroup J (T-s) f) y)^2) x + η) : + (∑ i, (halfDiff i (semigroup J T f) x)^2) ≤ + K * (1/(2*w*(T-a))+(n:ℝ)*p) + η := by + let E : ℝ → ℝ := fun s => semigroup J s (jumpEnergy J (semigroup J (T-s) f)) x + have hE : Continuous E := interpolated_energy_continuous J f T x + have hbound : ∀ s ∈ Set.Icc a T, + (∑ i, (halfDiff i (semigroup J T f) x)^2) ≤ + K/(2*w)*E s + (K*(n:ℝ)*p+η) := by + intro s hs + have hh := backward_gradient_energy_bound J hf (ha.trans hs.1) hs.2 hw bad hgood x (hbad s hs) + have hh' := (hprop s hs).trans (add_le_add (mul_le_mul_of_nonneg_left hh hK) le_rfl) + calc + _ ≤ K*(E s/(2*w)+(n:ℝ)*p)+η := hh' + _ = _ := by ring + have hi := intervalIntegral.integral_mono_on (μ := volume) haT.le + (intervalIntegrable_const (a := a) (b := T)) + ((hE.const_mul (K/(2*w))).add continuous_const |>.intervalIntegrable a T) hbound + simp only [Pi.add_apply, intervalIntegral.integral_const, smul_eq_mul] at hi + rw [intervalIntegral.integral_add ((hE.const_mul (K/(2*w))).intervalIntegrable a T) + (intervalIntegrable_const (a := a) (b := T)), + intervalIntegral.integral_const_mul, intervalIntegral.integral_const, smul_eq_mul] at hi + have hbudget : (∫ s in a..T, E s) ≤ 1 := backward_energy_budget J hf ha haT.le x + have hKbudget := mul_le_mul_of_nonneg_left hbudget (div_nonneg hK (by positivity : 0 ≤ 2*w)) + have hfinal : (T-a)*(∑ i, (halfDiff i (semigroup J T f) x)^2) ≤ + K/(2*w)+(T-a)*(K*(n:ℝ)*p+η) := by linarith + apply (mul_le_mul_iff_right₀ (sub_pos.mpr haT)).mp + calc + _ = (T-a)*(∑ i, (halfDiff i (semigroup J T f) x)^2) := by ring + _ ≤ K/(2*w)+(T-a)*(K*(n:ℝ)*p+η) := hfinal + _ = _ := by field_simp [ne_of_gt hw, ne_of_gt (sub_pos.mpr haT)]; ring + +lemma worstContinuous_le_of_backward_energy {n : ℕ} (J : Interaction n) + (hJ : ∀ i j, J i j = J j i) (hdiag : ∀ i, J i i = 0) + {a T w p K η : ℝ} (ha : 0 ≤ a) (haT : a < T) (hw : 0 < w) + (hp : 0 ≤ p) (hK : 0 ≤ K) (hη : 0 ≤ η) + (bad : Spin n → Prop) [DecidablePred bad] + (hgood : ∀ y, ¬bad y → ∀ i, w ≤ 1-mean J y i*spin y i) + (hbad : ∀ s ∈ Set.Icc a T, ∀ x, + semigroup J s (fun y => if bad y then 1 else 0) x ≤ p) + (hprop : ∀ f : Observables n, (∀ y, |f y| ≤ 1) → ∀ x, ∀ s ∈ Set.Icc a T, + (∑ i, (halfDiff i (semigroup J T f) x)^2) ≤ + K * semigroup J s (fun y => ∑ i, (halfDiff i (semigroup J (T-s) f) y)^2) x + η) : + worstContinuous J T ≤ Real.sqrt n * Real.sqrt (K*(1/(2*w*(T-a))+(n:ℝ)*p)+η) := by + have hL : 0 ≤ K*(1/(2*w*(T-a))+(n:ℝ)*p)+η := by positivity + apply worstContinuous_le_gradient J hJ hdiag T _ (Real.sqrt_nonneg _) + intro f hf x + rw [Real.sq_sqrt hL] + exact gradient_bound_from_backward_energy J hf ha haT hw hK bad hgood x + (fun s hs => hbad s hs x) (hprop f hf x) + +end SKGapCutoff + +open MeasureTheory Filter +open scoped BigOperators Topology + +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/SeparateCut.lean b/lean/OAI/Probability/SKGap/Localization/SeparateCut.lean new file mode 100644 index 0000000000000000000000000000000000000000..eb4c1e97375635f843e389aec351243f6fb5d892 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/SeparateCut.lean @@ -0,0 +1,142 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.Letter + +namespace OAI + +section +noncomputable section +namespace SKGap.Noncrossing +universe u v +namespace Diagram +variable {D : Type*} + +def separateCut {F : List (Letter D)} {k : ℕ} (c : CutAt F k) : Separated F k := + ⟨shapeOfCut c,⟨c.val.inside,rfl⟩, + ⟨c.val.outside,(List.take_append_drop _ _).symm⟩⟩ + +def joinCut {F : List (Letter D)} {k : ℕ} (z : Separated F k) : CutAt F k := by + have hb : z.1.before.length≤z.2.2.val.size := by + rw [← word_length,z.2.2.property,List.length_append] + omega + refine ⟨⟨z.1.before.length,z.2.1.val,z.2.2.val,z.1.closing⟩,hb,?_,?_⟩ + · have hs : z.2.1.val.size=z.1.between.length := by rw [← word_length,z.2.1.property] + simpa only [hs] using z.1.mark_eq + · rw [insert_word _ _ _ hb,z.2.2.property,z.2.1.property] + simpa using z.1.word_eq.symm + +@[simp] lemma join_separate {F : List (Letter D)} {k : ℕ} (c : CutAt F k) : + joinCut (separateCut c) = c := by + apply Subtype.ext + rcases c with ⟨⟨p,a,b,cl⟩,hp,hk,hF⟩ + dsimp [joinCut,separateCut,shapeOfCut] + simp only [List.length_take,word_length,Nat.min_eq_left hp] + +lemma pair_heq {α γ : Type u} {β δ : Type v} {a : α} {b : β} {c : γ} {d : δ} + (ha : a ≍ c) (hb : b ≍ d) : (a,b) ≍ (c,d) := by + cases ha + cases hb + rfl + +@[simp] lemma separate_join {F : List (Letter D)} {k : ℕ} (z : Separated F k) : + separateCut (joinCut z) = z := by + rcases z with ⟨s,a,b⟩ + have hs : shapeOfCut (joinCut (⟨s,a,b⟩ : Separated F k)) = s := by + apply PairShape.ext <;> + simp [shapeOfCut,joinCut,a.property,b.property] + apply Sigma.ext hs + apply pair_heq + · refine (Subtype.heq_iff_coe_eq (fun d => ?_)).mpr ?_ + · rw [hs] + · rfl + · refine (Subtype.heq_iff_coe_eq (fun d => ?_)).mpr ?_ + · rw [hs] + · rfl + +def separateEquiv (F : List (Letter D)) (k : ℕ) : CutAt F k ≃ Separated F k where + toFun := separateCut + invFun := joinCut + left_inv := join_separate + right_inv := separate_join + +section Value +variable {ι : Type*} [Fintype ι] + +def mean (a : ι→ℝ) : ℝ := (∑ i,a i)/(Fintype.card ι:ℝ) + +def value (j : ℝ) : Diagram (ι→ℝ) → ι→ℝ + | nil => fun _ => 1 + | diag a d => fun i => a i * d.value j i + | arch a b => fun i => j * mean (a.value j) * b.value j i + +lemma mean_const_mul (c : ℝ) (a : ι→ℝ) : + mean (fun i => c*a i) = c*mean a := by + simp only [mean,← Finset.mul_sum,mul_div_assoc] + +lemma value_insert (j : ℝ) (d e : Diagram (ι→ℝ)) (p : ℕ) (i : ι) : + (d.insert p e).value j i = j*mean (e.value j)*d.value j i := by + induction d generalizing p i with + | nil => simp only [insert,value]; split_ifs <;> rfl + | diag a d ih => + by_cases hp : p=0 + · simp [hp,value] + · simp only [insert,hp,↓reduceIte,value,ih]; ring + | arch a b ia ib => + by_cases hp : p=0 + · simp [hp,value] + · simp only [insert,hp,↓reduceIte] + split_ifs + · have hh : value j (a.insert (p-1) e) = fun k => j*mean (e.value j)*a.value j k := funext (ia (p-1)) + simp only [value,hh,mean_const_mul]; ring + · simp only [value,ib]; ring + +lemma value_cut (j : ℝ) (d : Diagram (ι→ℝ)) (k : ℕ) (c : Cut (ι→ℝ)) + (hc : d.cut k=some c) (i : ι) : + d.value j i = j*mean (c.inside.value j)*c.outside.value j i := by + rw [← (cut_spec d k c hc).2.2] + exact value_insert j c.outside c.inside c.start i + +def prediction (j : ℝ) (F : List (Letter (ι→ℝ))) (i : ι) : ℝ := + ∑ d : Paired F, d.val.value j i + +lemma mean_prediction (j : ℝ) (F : List (Letter (ι→ℝ))) : + mean (prediction j F) = ∑ d : Paired F, mean (d.val.value j) := by + simp only [mean,prediction] + rw [Finset.sum_comm,Finset.sum_div] + +theorem prediction_cut (j : ℝ) (F : List (Letter (ι→ℝ))) (k : ℕ) + (hk : F[k]?=some .noise) (i : ι) : + prediction j F i = ∑ s : PairShape F k, + j * mean (prediction j s.between) * prediction j (s.before++s.after) i := by + let e := (cutEquiv F k hk).trans (separateEquiv F k) + have he : prediction j F i = ∑ z : Separated F k, + j*mean (z.2.1.val.value j)*z.2.2.val.value j i := by + apply Fintype.sum_equiv e + intro d + have hd : d.val.word[k]?=some .noise := by rw [d.property]; exact hk + exact value_cut j d.val k (d.val.markedCut k hd) (cut_markedCut _ _ _) i + rw [he] + change (∑ z : Σ s : PairShape F k, Paired s.between × Paired (s.before++s.after), + j*mean (z.2.1.val.value j)*z.2.2.val.value j i) = _ + rw [Fintype.sum_sigma] + apply Finset.sum_congr rfl + intro s _ + rw [Fintype.sum_prod_type] + change (∑ a : Paired s.between, ∑ b : Paired (s.before++s.after), + j*mean (a.val.value j)*b.val.value j i) = _ + simp_rw [← Finset.mul_sum] + rw [← Finset.sum_mul, ← Finset.mul_sum, ← mean_prediction] + rfl + +end Value + +end Diagram +end SKGap.Noncrossing + +noncomputable section +open scoped BigOperators + +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/SeparatedCard.lean b/lean/OAI/Probability/SKGap/Localization/SeparatedCard.lean new file mode 100644 index 0000000000000000000000000000000000000000..ac9cb2c0b9d53eac9ee85b4764710d5ea3d72ec3 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/SeparatedCard.lean @@ -0,0 +1,144 @@ +import Mathlib +import OAI.Probability.SKGap.Model + +namespace OAI + +section +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open scoped BigOperators +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open scoped BigOperators +open scoped BigOperators NNReal ENNReal +open MeasureTheory Metric Set +namespace SKGapCutoff.RandomMatrix + +lemma separated_card_le {n : ℕ} (s : Finset (EuclideanSpace ℝ (Fin n))) + (hb : ∀ x ∈ s, ‖x‖ ≤ 1) + (hs : ∀ x ∈ s, ∀ y ∈ s, x ≠ y → (1/4:ℝ) < dist x y) : + (s.card : ℝ) ≤ (9:ℝ)^n := by + have hd : Set.PairwiseDisjoint (↑s) (fun x : EuclideanSpace ℝ (Fin n) => ball x (1/8)) := by + intro x hx y hy hxy + exact ball_disjoint_ball (by linarith [hs x hx y hy hxy]) + have hsub : (⋃ x ∈ s, ball x (1/8)) ⊆ ball (0 : EuclideanSpace ℝ (Fin n)) (9/8) := by + intro y hy + obtain ⟨x, hx, hy⟩ := Set.mem_iUnion₂.mp hy + have h := dist_triangle y x (0 : EuclideanSpace ℝ (Fin n)) + simp only [mem_ball, dist_zero_right] at hy h ⊢ + linarith [hb x hx] + have hm := measureReal_mono (μ := volume) hsub measure_ball_ne_top + rw [measureReal_biUnion_finset hd (fun _ _ => measurableSet_ball)] at hm + have hvol (x : EuclideanSpace ℝ (Fin n)) (r : ℝ) (hr : 0 < r) : + volume.real (ball x r) = r ^ n * volume.real (ball (0 : EuclideanSpace ℝ (Fin n)) 1) := by + simp only [measureReal_def, Measure.addHaar_ball_of_pos volume x hr, + ENNReal.toReal_mul, ENNReal.toReal_ofReal (pow_nonneg hr.le _), finrank_euclideanSpace, + Fintype.card_fin] + simp only [hvol _ _ (by norm_num : (0:ℝ) < 1/8), + hvol _ _ (by norm_num : (0:ℝ) < 9/8), Finset.sum_const, nsmul_eq_mul] at hm + have hp : 0 < volume.real (ball (0 : EuclideanSpace ℝ (Fin n)) 1) := by + exact ENNReal.toReal_pos (measure_ball_pos volume _ zero_lt_one).ne' measure_ball_ne_top + have hh : (s.card : ℝ) * (1/8:ℝ)^n ≤ (9/8:ℝ)^n := + (mul_le_mul_iff_left₀ hp).mp (by simpa only [mul_assoc] using hm) + have he : (9/8:ℝ)^n = (9:ℝ)^n * (1/8:ℝ)^n := by rw [← mul_pow]; congr 1; norm_num + rw [he] at hh + exact (mul_le_mul_iff_left₀ (show 0 < (1/8:ℝ)^n by positivity)).mp + (by simpa only [mul_comm] using hh) + +lemma unit_ball_net (n : ℕ) : + ∃ s : Finset (EuclideanSpace ℝ (Fin n)), + (∀ x ∈ s, ‖x‖ ≤ 1) ∧ + (∀ x : EuclideanSpace ℝ (Fin n), ‖x‖ ≤ 1 → ∃ y ∈ s, dist x y ≤ 1/4) ∧ + (s.card : ℝ) ≤ (9:ℝ)^n := by + classical + let A := closedBall (0 : EuclideanSpace ℝ (Fin n)) 1 + obtain ⟨C, _, hCf, hC⟩ := exists_finite_isCover_of_isCompact + (by norm_num : (1/8 : ℝ≥0) ≠ 0) (isCompact_closedBall (0 : EuclideanSpace ℝ (Fin n)) 1) + have hpack : packingNumber (1/4 : ℝ≥0) A ≠ ⊤ := by + have hle := (packingNumber_two_mul_le_externalCoveringNumber (1/8 : ℝ≥0) A).trans + hC.externalCoveringNumber_le_encard + norm_num only [show (2:ℝ≥0)*(1/8) = 1/4 by norm_num] at hle + exact ne_top_of_le_ne_top (Set.encard_ne_top_iff.mpr hCf) hle + + let D := maximalSeparatedSet (1/4 : ℝ≥0) A + have hDf : D.Finite := Set.encard_ne_top_iff.mp (by + rw [show D = maximalSeparatedSet (1/4 : ℝ≥0) A from rfl, encard_maximalSeparatedSet hpack] + exact hpack) + refine ⟨hDf.toFinset, ?_, ?_, ?_⟩ + · intro x hx + have h := maximalSeparatedSet_subset (ε := (1/4 : ℝ≥0)) (A := A) (hDf.mem_toFinset.mp hx) + simpa only [A, mem_closedBall, dist_zero_right] using h + · intro x hx + have hxA : x ∈ A := by simpa only [A, mem_closedBall, dist_zero_right] using hx + obtain ⟨y, hy, hdist⟩ := isCover_maximalSeparatedSet hpack hxA + refine ⟨y, hDf.mem_toFinset.mpr hy, ?_⟩ + change edist x y ≤ ((1/4 : ℝ≥0) : ℝ≥0∞) at hdist + have h := ENNReal.toReal_mono (by norm_num : ((1/4 : ℝ≥0) : ℝ≥0∞) ≠ ⊤) hdist + simpa only [edist_dist, ENNReal.toReal_ofReal (dist_nonneg : 0 ≤ dist x y), + ENNReal.coe_toReal, NNReal.coe_div, NNReal.coe_one, NNReal.coe_ofNat] using h + · apply separated_card_le + · intro x hx + have h := maximalSeparatedSet_subset (ε := (1/4 : ℝ≥0)) (A := A) (hDf.mem_toFinset.mp hx) + simpa only [A, mem_closedBall, dist_zero_right] using h + · intro x hx y hy hxy + have h := isSeparated_maximalSeparatedSet (ε := (1/4 : ℝ≥0)) (A := A) + (hDf.mem_toFinset.mp hx) (hDf.mem_toFinset.mp hy) hxy + simpa only [edist_dist, ENNReal.coe_lt_ofReal, NNReal.coe_div, NNReal.coe_one, + NNReal.coe_ofNat] using h + +lemma opNorm_le_of_net {n : ℕ} (A : EuclideanSpace ℝ (Fin n) →L[ℝ] EuclideanSpace ℝ (Fin n)) + (s : Finset (EuclideanSpace ℝ (Fin n))) + (hb : ∀ x ∈ s, ‖x‖ ≤ 1) + (hcover : ∀ x : EuclideanSpace ℝ (Fin n), ‖x‖ ≤ 1 → ∃ y ∈ s, dist x y ≤ 1/4) + (M : ℝ) (hM : 0 ≤ M) + (hnet : ∀ x ∈ s, ∀ y ∈ s, |inner (𝕜 := ℝ) (A x) y| ≤ M) : ‖A‖ ≤ 2*M := by + have hh : ‖A‖ ≤ M + ‖A‖/2 := by + apply ContinuousLinearMap.opNorm_le_of_re_inner_le (by positivity) + intro x y hx hy + obtain ⟨a, ha, hxa⟩ := hcover x hx.le + obtain ⟨b, hb', hyb⟩ := hcover y hy.le + have hxan : ‖x-a‖ ≤ 1/4 := by simpa only [dist_eq_norm] using hxa + have hybn : ‖y-b‖ ≤ 1/4 := by simpa only [dist_eq_norm] using hyb + have h₁ : |inner (𝕜 := ℝ) (A (x-a)) y| ≤ ‖A‖/4 := by + calc + _ ≤ ‖A (x-a)‖ * ‖y‖ := abs_real_inner_le_norm _ _ + _ ≤ (‖A‖ * ‖x-a‖) * ‖y‖ := mul_le_mul_of_nonneg_right (A.le_opNorm _) (norm_nonneg _) + _ ≤ ‖A‖/4 := by rw [hy, mul_one]; nlinarith [norm_nonneg A] + have h₂ : |inner (𝕜 := ℝ) (A a) (y-b)| ≤ ‖A‖/4 := by + calc + _ ≤ ‖A a‖ * ‖y-b‖ := abs_real_inner_le_norm _ _ + _ ≤ (‖A‖ * ‖a‖) * ‖y-b‖ := mul_le_mul_of_nonneg_right (A.le_opNorm _) (norm_nonneg _) + _ ≤ ‖A‖ * (1:ℝ) * (1/4) := mul_le_mul + (mul_le_mul_of_nonneg_left (hb a ha) (norm_nonneg A)) hybn (norm_nonneg _) (by positivity) + _ = ‖A‖/4 := by ring + have he : inner (𝕜 := ℝ) (A x) y = inner (𝕜 := ℝ) (A (x-a)) y + + inner (𝕜 := ℝ) (A a) (y-b) + inner (𝕜 := ℝ) (A a) b := by + simp only [map_sub, inner_sub_left, inner_sub_right]; ring + change inner (𝕜 := ℝ) (A x) y ≤ M + ‖A‖/2 + rw [he] + have hh := hnet a ha b hb' + linarith [le_abs_self (inner (𝕜 := ℝ) (A (x-a)) y), + le_abs_self (inner (𝕜 := ℝ) (A a) (y-b)), le_abs_self (inner (𝕜 := ℝ) (A a) b)] + linarith + +end SKGapCutoff.RandomMatrix + +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter Set + +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/SmallOverlap.lean b/lean/OAI/Probability/SKGap/Localization/SmallOverlap.lean new file mode 100644 index 0000000000000000000000000000000000000000..653433d8a8f62f7956454edcbcc2fbd0c5ed18bf --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/SmallOverlap.lean @@ -0,0 +1,79 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.TAPVectorTaylor +import OAI.Probability.SKGap.Entropy.ConditionalBadSet + +namespace OAI + +section +noncomputable section +namespace SKGap +open Matrix Real Set +open scoped BigOperators + +lemma quadraticForm_le_mulvec_bound {n : ℕ} {K : ℝ} (J : Matrix (Fin n) (Fin n) ℝ) + (hJ : ∀ z : Field n,vectorNorm (J*ᵥz) ≤ K*vectorNorm z) (x : Field n) : + quadraticForm J x ≤ K*vectorSqNorm x := by + have he : quadraticForm J x=∑ i,x i*(J*ᵥx) i := by + simp only [quadraticForm,mulVec,dotProduct,Finset.mul_sum,mul_assoc] + rw [he] + calc + _ ≤ |∑ i,x i*(J*ᵥx) i| := le_abs_self _ + _ ≤ vectorNorm x*vectorNorm (J*ᵥx) := vector_dot_abs_le _ _ + _ ≤ vectorNorm x*(K*vectorNorm x) := mul_le_mul_of_nonneg_left (hJ x) (vectorNorm_nonneg _) + _ = _ := by rw [← vectorNorm_sq];ring + +lemma badField_small_overlap_impossible {n : ℕ} (hn : 0 < n) {j A K q₀ ε c : ℝ} + (hj : 0 ≤ j) (hA : 0 ≤ A) (hK : 0 ≤ K-j) + (hmargin : c < 1-A*(K-j+6*j*q₀)) + (W : Matrix (Fin n) (Fin n) ℝ) (y : Field n) + (hJ : ∀ z : Field n,vectorNorm (plantedInteraction j W*ᵥz) ≤ K*vectorNorm z) + (hy : (W,y)∈badFieldSet n j A ε c) : 2*q₀ < overlap y := by + by_contra! hq + obtain ⟨a,ha,_hclose,x,hx,hquad⟩ := hy + have hv : vectorSqNorm x.ofLp=1 := by + rw [← vectorNorm_sq] + change ‖WithLp.toLp 2 x.ofLp‖^2=1 + simp only [WithLp.toLp_ofLp,hx,one_pow] + have hcoef : 0 ≤ K-j+3*j*overlap y := add_nonneg hK (mul_nonneg (mul_nonneg (by norm_num : (0:ℝ)≤3) hj) (overlap_nonneg y)) + have hh := hessian_lower_bound hn hj y a (fun i=>(ha i).1) (fun i=>(ha i).2) + (quadraticForm_le_mulvec_bound _ hJ) hcoef x.ofLp + rw [hv,mul_one] at hh + have hc := mul_le_mul_of_nonneg_left hq (mul_nonneg (mul_nonneg (by norm_num : (0:ℝ)≤3) hj) hA) + nlinarith only [hh,hquad,hmargin,hc] + +lemma overlap_neighborhood {n : ℕ} (hn : 0 < n) {q₀ r : ℝ} (hr : 2*r ≤ q₀) + (y d : Field n) (hy : 2*q₀ < overlap y) (hd : vectorNorm d ≤ r*sqrt (n:ℝ)) : + q₀ ≤ overlap (y+d) := by + have hn0 : (0:ℝ) < n := Nat.cast_pos.mpr hn + have hh := varianceAverage_difference hn y d + have hb := mul_le_mul_of_nonneg_left hd (by positivity : 0 ≤ 2/sqrt (n:ℝ)) + have he : 2/sqrt (n:ℝ)*(r*sqrt (n:ℝ))=2*r := by field_simp + rw [he] at hb + unfold varianceAverage at hh + linarith [le_abs_self ((1-overlap (y+d))-(1-overlap y))] + +lemma high_temperature_small_margin {j : ℝ} (hj : 0 < j) (hj1 : j < 1) : + ∃ A K q₀ c : ℝ,1 < A ∧ 2*sqrt j < K ∧ 0 < q₀ ∧ 0 < c ∧ + sqrt j*A < 1 ∧ 0 ≤ K-j ∧ c < 1-A*(K-j+6*j*q₀) := by + have hs : 0 < sqrt j := sqrt_pos.mpr hj + have hs1 : sqrt j < 1 := by simpa using sqrt_lt_sqrt hj.le hj1 + have hjroot : j < 2*sqrt j := by nlinarith [sq_sqrt hj.le] + let f : ℝ → ℝ := fun δ=>1-(1+δ)*(2*sqrt j+2*δ-j+6*j*δ) + let g : ℝ → ℝ := fun δ=>sqrt j*(1+δ) + have hf0 : 0 < f 0 := by dsimp [f];nlinarith [sq_sqrt hj.le,sq_pos_of_pos (sub_pos.mpr hs1)] + have hc : ContinuousAt f 0 := by dsimp [f];fun_prop + have hg : ContinuousAt g 0 := by dsimp [g];fun_prop + have he : ∀ᶠ δ in nhds (0:ℝ),0 < f δ ∧ g δ < 1 := + (hc.tendsto.eventually_const_lt hf0).and (hg.tendsto.eventually_lt_const (by simpa [g] using hs1)) + obtain ⟨r,hr,hrgood⟩ := Metric.eventually_nhds_iff.mp he + have hd : dist (r/2) (0:ℝ) < r := by rw [Real.dist_eq,sub_zero,abs_of_pos (half_pos hr)];linarith + obtain ⟨hf,hg⟩ := hrgood hd + refine ⟨1+r/2,2*sqrt j+2*(r/2),r/2,f (r/2)/2,by linarith,by linarith, + half_pos hr,half_pos hf,hg,by linarith,?_⟩ + change f (r/2)/2 < f (r/2) + linarith +end SKGap +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/SmoothSelection.lean b/lean/OAI/Probability/SKGap/Localization/SmoothSelection.lean new file mode 100644 index 0000000000000000000000000000000000000000..ab1bb945081e53a418d187348806c19b00b4b7e2 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/SmoothSelection.lean @@ -0,0 +1,213 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.ResidualSelection + +namespace OAI + +section + +noncomputable section +open scoped BigOperators NNReal ContDiff +namespace SKGapCutoff.Recipe +open Primary Static +variable {n : ℕ} + +def residualScalarCutoff (u : ℝ) : ℝ := + Real.smoothTransition ((1-u)*4/3)*Real.smoothTransition ((1+u)*4/3) + +lemma residualScalarCutoff_bounds (u : ℝ) : + 0≤residualScalarCutoff u ∧ residualScalarCutoff u≤1 := by + refine ⟨mul_nonneg (Real.smoothTransition.nonneg _) (Real.smoothTransition.nonneg _),?_⟩ + exact (mul_le_mul (Real.smoothTransition.le_one _) (Real.smoothTransition.le_one _) + (Real.smoothTransition.nonneg _) (by norm_num)).trans_eq (by simp) + +lemma residualScalarCutoff_one {u : ℝ} (h0 : 0≤u) (h1 : u≤1/4) : + residualScalarCutoff u=1 := by + simp only [residualScalarCutoff,Real.smoothTransition.one_of_one_le (by linarith : 1≤(1-u)*4/3), + Real.smoothTransition.one_of_one_le (by linarith : 1≤(1+u)*4/3),one_mul] + +lemma residualScalarCutoff_zero {u : ℝ} (hu : 1≤u) : residualScalarCutoff u=0 := by + simp [residualScalarCutoff,Real.smoothTransition.zero_of_nonpos (by linarith : (1-u)*4/3≤0)] + +lemma residualScalarCutoff_smooth : ContDiff ℝ ∞ residualScalarCutoff := by + unfold residualScalarCutoff + fun_prop + +lemma residualScalarCutoff_lipschitz : ∃K,LipschitzWith K residualScalarCutoff := by + have hc : HasCompactSupport residualScalarCutoff := by + apply HasCompactSupport.intro' (K:=Set.Icc (-1:ℝ) 1) isCompact_Icc isClosed_Icc + intro x hx + simp only [Set.mem_Icc,not_and_or,not_le] at hx + rcases hx with hx|hx + · simp [residualScalarCutoff,Real.smoothTransition.zero_of_nonpos (by linarith : (1+x)*4/3≤0)] + · exact residualScalarCutoff_zero hx.le + exact ContDiff.lipschitzWith_of_hasCompactSupport hc residualScalarCutoff_smooth (by simp) + +lemma norm_derivativeVector_sq (f : Spin n→ℝ) (x : Spin n) : + ‖derivativeVector f x‖^2=∑i,(halfDiff i f x)^2 := by + exact vectorNorm_sq (fun i=>halfDiff i f x) + +lemma derivativeVector_norm_mono (f g : Spin n→ℝ) (x : Spin n) {C : ℝ} (hC : 0≤C) + (h : ∀i,|halfDiff i f x|≤C*|halfDiff i g x|) : + ‖derivativeVector f x‖≤C*‖derivativeVector g x‖ := by + apply nonneg_le_nonneg_of_sq_le_sq (by positivity) + simp only [←sq,mul_pow,norm_derivativeVector_sq,Finset.mul_sum] + apply Finset.sum_le_sum + intro i _ + simpa only [sq_abs,mul_pow] using pow_le_pow_left₀ (abs_nonneg _) (h i) 2 + +lemma derivativeVector_comp_lipschitz {φ : ℝ→ℝ} {K : ℝ≥0} (hφ : LipschitzWith K φ) + (f : Spin n→ℝ) (x : Spin n) : + ‖derivativeVector (fun x=>φ (f x)) x‖≤(K:ℝ)*‖derivativeVector f x‖ := by + apply derivativeVector_norm_mono _ _ _ K.coe_nonneg + intro i + have h:=hφ.dist_le_mul (f (replace x i true)) (f (replace x i false)) + simpa only [halfDiff,abs_div,Real.dist_eq,abs_of_pos (by norm_num : (0:ℝ)<2),mul_div_assoc] using + div_le_div_of_nonneg_right h (by norm_num : (0:ℝ)≤2) + +lemma derivativeVector_scale (c : ℝ) (f : Spin n→ℝ) (x : Spin n) : + derivativeVector (fun y=>c*f y) x=c • derivativeVector f x := by + ext i + simp only [derivativeVector,WithLp.ofLp_toLp,PiLp.smul_apply,smul_eq_mul,halfDiff] + ring + +lemma residualEnergy_as_pair (j : ℝ) (J : Interaction n) (h : Fin n→ℝ) (k : ℕ) (x : Spin n) : + residualEnergy j J h k x = + (Real.sqrt (n:ℝ))⁻¹*normalizedPair (residual j J h k) (residual j J h k) x := by + simp only [residualEnergy,vectorNorm_sq,normalizedPair,vectorPair] + simp only [inv_mul_eq_div,div_div,Real.mul_self_sqrt (Nat.cast_nonneg n),sq] + +lemma residualEnergy_gradient (hn : 0(Real.sqrt (n:ℝ))⁻¹* + normalizedPair (residual j J h k) (residual j J h k) y := funext (residualEnergy_as_pair j J h k) + rw [he,derivativeVector_scale,norm_smul,Real.norm_eq_abs,abs_of_nonneg (inv_nonneg.mpr (Real.sqrt_nonneg _))] + have hb:=normalizedPair_derivative_bound hn (residual j J h k) (residual j J h k) x hA hA hd hd + (residual_vectorNorm j J h k x) (residual_vectorNorm j J h k x) + exact (mul_le_mul_of_nonneg_left hb (inv_nonneg.mpr (Real.sqrt_nonneg _))).trans_eq (by ring) + +end SKGapCutoff.Recipe + +end +end + +section + +noncomputable section +open scoped BigOperators NNReal +namespace SKGapCutoff.Recipe +open Primary Static +variable {n : ℕ} + +def residualStepCutoff (ρ j : ℝ) (J : Interaction n) (h : Fin n→ℝ) (k : ℕ) (x : Spin n) : ℝ := + residualScalarCutoff (residualEnergy j J h k x/ρ^2) + +def residualCutoff (ρ j : ℝ) (J : Interaction n) (h : Fin n→ℝ) (k : ℕ) (x : Spin n) : ℝ := + residualStepCutoff ρ j J h k x*residualStepCutoff ρ j J h (k+1) x + +lemma residualStepCutoff_bounds (ρ j : ℝ) (J : Interaction n) (h : Fin n→ℝ) (k : ℕ) (x : Spin n) : + 0≤residualStepCutoff ρ j J h k x ∧ residualStepCutoff ρ j J h k x≤1 := residualScalarCutoff_bounds _ +lemma residualCutoff_bounds (ρ j : ℝ) (J : Interaction n) (h : Fin n→ℝ) (k : ℕ) (x : Spin n) : + 0≤residualCutoff ρ j J h k x ∧ residualCutoff ρ j J h k x≤1 := by + have h0:=residualStepCutoff_bounds ρ j J h k x + have h1:=residualStepCutoff_bounds ρ j J h (k+1) x + exact ⟨mul_nonneg h0.1 h1.1,(mul_le_mul h0.2 h1.2 h1.1 (by norm_num)).trans_eq (by simp)⟩ + +lemma residualStepCutoff_support (hn : 0hc (residualScalarCutoff_zero hh)) + have he : residualEnergy j J h k x≤ρ^2 := by + exact ((div_lt_one (sq_pos_of_pos hρ)).mp hr).le + apply nonneg_le_nonneg_of_sq_le_sq (by positivity) + simp only [←sq,mul_pow,Real.sq_sqrt (Nat.cast_nonneg n)] + exact (div_le_iff₀ (Nat.cast_pos.mpr hn)).mp he + +lemma residualCutoff_support (hn : 0f y*g y) x‖≤2*(A+B) := by + have ht (i : Fin n) : (halfDiff i (fun y=>f y*g y) x)^2≤ + 2*(halfDiff i f x)^2+2*(halfDiff i g x)^2 := by + have hf' : (f (flip x i))^2≤1 := by simpa only [sq_abs,one_pow] using pow_le_pow_left₀ (abs_nonneg _) (hf (flip x i)) 2 + have hg' : (g x)^2≤1 := by simpa only [sq_abs,one_pow] using pow_le_pow_left₀ (abs_nonneg _) (hg x) 2 + rw [halfDiff_mul_flipped] + nlinarith [mul_le_mul_of_nonneg_right hf' (sq_nonneg (halfDiff i g x)), + mul_le_mul_of_nonneg_right hg' (sq_nonneg (halfDiff i f x)), + sq_nonneg (f (flip x i)*halfDiff i g x-g x*halfDiff i f x)] + have hb : ‖derivativeVector (fun y=>f y*g y) x‖^2≤2*A^2+2*B^2 := by + calc + _ ≤ ∑i,(2*(halfDiff i f x)^2+2*(halfDiff i g x)^2) := by + rw [norm_derivativeVector_sq]; exact Finset.sum_le_sum (fun i _=>ht i) + _ = 2*‖derivativeVector f x‖^2+2*‖derivativeVector g x‖^2 := by + simp only [norm_derivativeVector_sq,Finset.sum_add_distrib,Finset.mul_sum] + _ ≤ _ := by nlinarith [pow_le_pow_left₀ (norm_nonneg _) hdF 2,pow_le_pow_left₀ (norm_nonneg _) hdG 2] + apply nonneg_le_nonneg_of_sq_le_sq (by positivity) + simp only [←sq] + nlinarith [mul_nonneg hA hB,sq_nonneg A,sq_nonneg B] + +lemma residualStepCutoff_gradient (hn : 0residualEnergy j J h k y/ρ^2) x).trans + have he : (fun y=>residualEnergy j J h k y/ρ^2)=fun y=>(ρ^2)⁻¹*residualEnergy j J h k y := by + funext y; ring + rw [he,derivativeVector_scale,norm_smul,Real.norm_eq_abs,abs_of_nonneg (inv_nonneg.mpr (sq_nonneg _))] + exact (mul_le_mul_of_nonneg_left (mul_le_mul_of_nonneg_left + (residualEnergy_gradient hn j J h k x hA hd) (inv_nonneg.mpr (sq_nonneg _))) K.coe_nonneg).trans_eq (by ring) + +lemma residualCutoff_gradient (hn : 0by rw [abs_of_nonneg (residualStepCutoff_bounds ρ j J h k y).1];exact (residualStepCutoff_bounds ρ j J h k y).2) + (fun y=>by rw [abs_of_nonneg (residualStepCutoff_bounds ρ j J h (k+1) y).1];exact (residualStepCutoff_bounds ρ j J h (k+1) y).2) + (by positivity) (by positivity) + (residualStepCutoff_gradient hn hρ hK J h k x hA h0) + (residualStepCutoff_gradient hn hρ hK J h (k+1) x hB h1)).trans_eq + ring + +end SKGapCutoff.Recipe + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/SparseCubeNet.lean b/lean/OAI/Probability/SKGap/Localization/SparseCubeNet.lean new file mode 100644 index 0000000000000000000000000000000000000000..d9546214bf468caf9bb81b4839b31ed691264aa1 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/SparseCubeNet.lean @@ -0,0 +1,222 @@ +import Mathlib +import OAI.Probability.SKGap.Model + +namespace OAI + +section +noncomputable section +namespace SKGap +open Set Real +open scoped BigOperators +variable {ι κ : Type*} [Fintype ι] [Fintype κ] + +def optionSupport [DecidableEq ι] (f : ι → Option κ) : Finset ι := + Finset.univ.filter (fun i => (f i).isSome) + +omit [Fintype κ] in +lemma option_support_weight [DecidableEq ι] (h : ℝ) (f : ι → Option κ) : + (∏ i, if (f i).isSome then h else 1) = h^(optionSupport f).card := by + rw [← Finset.prod_filter] + simp [optionSupport] + +lemma option_weight_sum [DecidableEq ι] (h : ℝ) : + (∑ f : ι → Option κ, h^(optionSupport f).card)=(1+(Fintype.card κ:ℝ)*h)^(Fintype.card ι) := by + simp only [← option_support_weight] + rw [← Fintype.prod_sum (fun (_ : ι) (o : Option κ) => if o.isSome then h else 1)] + simp [Fintype.sum_option] + +theorem sparse_option_count [DecidableEq ι] [DecidableEq κ] + {h α : ℝ} (hh : 0 < h) (hh1 : h ≤ 1) + (s : Finset (ι → Option κ)) + (hs : ∀ f ∈ s, ((optionSupport f).card:ℝ) ≤ α*(Fintype.card ι:ℝ)) : + (s.card:ℝ) ≤ exp (((Fintype.card κ:ℝ)*h-α*log h)*(Fintype.card ι:ℝ)) := by + have hb : (s.card:ℝ)*exp (α*(Fintype.card ι:ℝ)*log h) ≤ + (1+(Fintype.card κ:ℝ)*h)^(Fintype.card ι) := by + calc + _ = ∑ _f ∈ s, exp (α*(Fintype.card ι:ℝ)*log h) := by simp + _ ≤ ∑ f ∈ s, h^(optionSupport f).card := by + apply Finset.sum_le_sum + intro f hf + rw [mul_comm (α*(Fintype.card ι:ℝ)) (log h),← Real.rpow_def_of_pos hh,← Real.rpow_natCast] + exact Real.rpow_le_rpow_of_exponent_ge hh hh1 (hs f hf) + _ ≤ ∑ f : ι → Option κ, h^(optionSupport f).card := + Finset.sum_le_sum_of_subset_of_nonneg (Finset.subset_univ _) (fun _ _ _ => pow_nonneg hh.le _) + _ = _ := option_weight_sum h + have ht : 0 < 1+(Fintype.card κ:ℝ)*h := by positivity + have he : (1+(Fintype.card κ:ℝ)*h)^(Fintype.card ι) ≤ + exp ((Fintype.card ι:ℝ)*(Fintype.card κ:ℝ)*h) := by + rw [← Real.exp_log ht,← exp_nat_mul] + apply exp_le_exp.mpr + have hl := log_le_sub_one_of_pos ht + nlinarith [mul_le_mul_of_nonneg_left hl (Nat.cast_nonneg (α := ℝ) (Fintype.card ι))] + have hb := (le_div_iff₀ (exp_pos _)).mpr hb + apply hb.trans + calc + _ ≤ exp ((Fintype.card ι:ℝ)*(Fintype.card κ:ℝ)*h) / + exp (α*(Fintype.card ι:ℝ)*log h) := div_le_div_of_nonneg_right he (exp_pos _).le + _ = _ := by rw [← exp_sub]; congr 1; ring + +theorem sparse_option_small_entropy {ε : ℝ} (hε : 0 < ε) : + ∃ α : ℝ, 0 < α ∧ ∀ (ι : Type*) [Fintype ι] [DecidableEq ι] + [DecidableEq κ] (s : Finset (ι → Option κ)), + (∀ f ∈ s, ((optionSupport f).card:ℝ) ≤ α*(Fintype.card ι:ℝ)) → + (s.card:ℝ) ≤ exp (ε*(Fintype.card ι:ℝ)) := by + let h : ℝ := min (1/2) (ε/(2*((Fintype.card κ:ℝ)+1))) + have hh : 0 < h := lt_min (by norm_num) (by positivity) + have hh1 : h < 1 := lt_of_le_of_lt (min_le_left _ _) (by norm_num) + have hlog : 0 < -log h := neg_pos.mpr (log_neg hh hh1) + let α := ε/(2*(-log h)) + refine ⟨α,by positivity,?_⟩ + intro ι _ _ _ s hs + apply (sparse_option_count hh hh1.le s hs).trans + apply exp_le_exp.mpr + have hNh : (Fintype.card κ:ℝ)*h ≤ ε/2 := by + have hd := (le_div_iff₀ (show 0 < 2*((Fintype.card κ:ℝ)+1) by positivity)).mp + (show h ≤ ε/(2*((Fintype.card κ:ℝ)+1)) from min_le_right _ _) + nlinarith + have ha : α*(-log h)=ε/2 := by dsimp [α]; field_simp [ne_of_lt (log_neg hh hh1)] + exact mul_le_mul_of_nonneg_right (by nlinarith) (Nat.cast_nonneg _) + +def optionCube (v : ι → ℝ) (grid : κ → ℝ) (f : ι → Option κ) : ι → ℝ := + fun i => (f i).elim (v i) grid + +omit [Fintype κ] in + +theorem sparse_cube_approx [DecidableEq ι] {M ζ α : ℝ} (hζ : 0 < ζ) + (v a : ι → ℝ) (grid : κ → ℝ) (ha : ∀ i, a i ∈ Icc 0 M) + (hgrid : ∀ x ∈ Icc (0:ℝ) M, ∃ k, |x-grid k| ≤ ζ) + (hsq : (∑ i,(a i-v i)^2) ≤ α*ζ^2*(Fintype.card ι:ℝ)) : + ∃ f : ι → Option κ, + ((optionSupport f).card:ℝ) ≤ α*(Fintype.card ι:ℝ) ∧ + (∀ i, |a i-optionCube v grid f i| ≤ ζ) ∧ + (∀ i, |optionCube v grid f i-v i| ≤ 2*|a i-v i|) := by + classical + choose k hk using (fun i => hgrid (a i) (ha i)) + let f : ι → Option κ := fun i => if ζ < |a i-v i| then some (k i) else none + have hsupp : optionSupport f = Finset.univ.filter (fun i => ζ < |a i-v i|) := by + ext i + simp [optionSupport,f] + have hb : ((optionSupport f).card:ℝ)*ζ^2 ≤ ∑ i,(a i-v i)^2 := by + calc + _ = ∑ i ∈ optionSupport f, ζ^2 := by simp + _ ≤ ∑ i ∈ optionSupport f, (a i-v i)^2 := by + apply Finset.sum_le_sum + intro i hi + have hi' := (Finset.mem_filter.mp (hsupp ▸ hi)).2 + nlinarith [sq_abs (a i-v i)] + _ ≤ _ := Finset.sum_le_sum_of_subset_of_nonneg (Finset.subset_univ _) (fun _ _ _ => sq_nonneg _) + refine ⟨f,?_,?_,?_⟩ + · apply (mul_le_mul_iff_left₀ (sq_pos_of_pos hζ)).mp + calc + _ ≤ _ := hb.trans hsq + _ = _ := by ring + · intro i + by_cases hi : ζ < |a i-v i| + · simpa [optionCube,f,hi] using hk i + · simpa [optionCube,f,hi] using le_of_not_gt hi + · intro i + by_cases hi : ζ < |a i-v i| + · simp only [optionCube,f,hi,ite_eq_left,Option.elim_some] + have h := abs_sub_le (grid (k i)) (a i) (v i) + rw [abs_sub_comm (grid (k i)) (a i)] at h + linarith [hk i] + · simp [optionCube,f,hi,abs_nonneg] + +omit [Fintype ι] [Fintype κ] in +lemma optionCube_bounds {M : ℝ} (v : ι → ℝ) (grid : κ → ℝ) + (hv : ∀ i, v i ∈ Icc 0 M) (hg : ∀ k,grid k ∈ Icc 0 M) (f : ι → Option κ) : + ∀ i, optionCube v grid f i ∈ Icc 0 M := by + intro i + cases h : f i with + | none => simpa [optionCube,h] using hv i + | some k => simpa [optionCube,h] using hg k + +end SKGap +end +end + +section +noncomputable section +namespace SKGap +open MeasureTheory Real Set +open scoped BigOperators + +lemma interval_mesh {M ζ : ℝ} (hζ : 0 < ζ) : + ∃ s : Finset ℝ, (∀ x ∈ s,x ∈ Icc (0:ℝ) M) ∧ + ∀ x ∈ Icc (0:ℝ) M,∃ y ∈ s,|x-y| ≤ ζ := by + classical + obtain ⟨s,hs,hfin,hcover⟩ := (isCompact_Icc : IsCompact (Icc (0:ℝ) M)).finite_cover_balls hζ + refine ⟨hfin.toFinset,fun x hx => hs (hfin.mem_toFinset.mp hx),?_⟩ + intro x hx + obtain ⟨y,hy,hxy⟩ := mem_iUnion₂.mp (hcover hx) + exact ⟨y,hfin.mem_toFinset.mpr hy,(show |x-y| < ζ from Metric.mem_ball.mp hxy).le⟩ + +theorem sparse_uniform_exponential {M ζ r : ℝ} (hζ : 0 < ζ) (hr : 0 < r) : + ∃ ε : ℝ,0 < ε ∧ ∀ (Ω : Type*) [MeasurableSpace Ω] (μ : Measure Ω) + [IsFiniteMeasure μ] (n : ℕ) (v : Fin n → ℝ) (_hv : ∀ i,v i ∈ Icc 0 M) + (E : Set Ω) (GoodHigh GoodLow : (Fin n → ℝ) → Ω → Prop) (C : ℝ), + 0 ≤ C → + (∀ b, (∀ i,b i ∈ Icc 0 M) → (∑ i,(b i-v i)^2) ≤ 4*ε^2*(n:ℝ) → + μ.real {ω | ¬GoodHigh b ω} ≤ C*exp (-r*(n:ℝ))) → + (∀ ω ∈ E,∀ a b, (∀ i,a i ∈ Icc 0 M) → (∀ i,b i ∈ Icc 0 M) → + (∀ i,|a i-b i| ≤ ζ) → GoodHigh b ω → GoodLow a ω) → + μ.real {ω | ∃ a, (∀ i,a i ∈ Icc 0 M) ∧ (∑ i,(a i-v i)^2) ≤ ε^2*(n:ℝ) ∧ + ¬GoodLow a ω} ≤ μ.real Eᶜ+C*exp (-(r/2)*(n:ℝ)) := by + classical + obtain ⟨grid,hgrid,hcover⟩ := interval_mesh (M := M) hζ + let κ := {x : ℝ // x ∈ grid} + obtain ⟨α,hα,hcount⟩ := sparse_option_small_entropy (κ := κ) (half_pos hr) + let ε := sqrt α*ζ + have hε : 0 < ε := mul_pos (sqrt_pos.mpr hα) hζ + have heq : ε^2=α*ζ^2 := by dsimp [ε]; rw [mul_pow,sq_sqrt hα.le] + refine ⟨ε,hε,?_⟩ + intro Ω _ μ _ n v hv E GoodHigh GoodLow C hC hfixed hnear + let val : κ → ℝ := Subtype.val + let s : Finset (Fin n → Option κ) := Finset.univ.filter (fun f => + ((optionSupport f).card:ℝ) ≤ α*(n:ℝ) ∧ + (∑ i,(optionCube v val f i-v i)^2) ≤ 4*ε^2*(n:ℝ)) + have hsize : (s.card:ℝ) ≤ exp ((r/2)*(n:ℝ)) := by + simpa only [Fintype.card_fin] using hcount (Fin n) s (fun f hf => by simpa only [Fintype.card_fin] using (Finset.mem_filter.mp hf).2.1) + let B : (Fin n → Option κ) → Set Ω := fun f => {ω | ¬GoodHigh (optionCube v val f) ω} + have hsub : {ω | ∃ a, (∀ i,a i ∈ Icc 0 M) ∧ (∑ i,(a i-v i)^2) ≤ ε^2*(n:ℝ) ∧ + ¬GoodLow a ω} ⊆ Eᶜ ∪ ⋃ f ∈ s,B f := by + intro ω ⟨a,ha,ha2,hbad⟩ + by_cases hE : ω ∈ E + · obtain ⟨f,hf,hap,hfp⟩ := sparse_cube_approx hζ v a val ha + (fun x hx => by obtain ⟨y,hy,hyx⟩ := hcover x hx; exact ⟨⟨y,hy⟩,hyx⟩) + (by simpa only [Fintype.card_fin,heq] using ha2) + have hb : ∀ i,optionCube v val f i ∈ Icc 0 M := + optionCube_bounds v val hv (fun k => hgrid k.val k.property) f + have hd : (∑ i,(optionCube v val f i-v i)^2) ≤ 4*ε^2*(n:ℝ) := by + calc + _ ≤ ∑ i,4*(a i-v i)^2 := by + apply Finset.sum_le_sum; intro i _ + have h := hfp i + have hh := mul_self_le_mul_self (abs_nonneg (optionCube v val f i-v i)) h + nlinarith only [hh,sq_abs (optionCube v val f i-v i),sq_abs (a i-v i)] + _ = 4*(∑ i,(a i-v i)^2) := by rw [Finset.mul_sum] + _ ≤ _ := by linarith + have hfs : f ∈ s := Finset.mem_filter.mpr ⟨Finset.mem_univ _,by simpa only [Fintype.card_fin] using And.intro hf hd⟩ + exact Or.inr (mem_iUnion₂.mpr ⟨f,hfs,fun hg => hbad (hnear ω hE a _ ha hb hap hg)⟩) + · exact Or.inl hE + have hsum : (∑ f ∈ s,μ.real (B f)) ≤ (s.card:ℝ)*(C*exp (-r*(n:ℝ))) := by + calc + _ ≤ ∑ _f ∈ s,C*exp (-r*(n:ℝ)) := by + apply Finset.sum_le_sum + intro f hf + exact hfixed _ (optionCube_bounds v val hv (fun k => hgrid k.val k.property) f) + (Finset.mem_filter.mp hf).2.2 + _ = _ := by simp + apply (measureReal_mono hsub (measure_ne_top _ _)).trans + apply (measureReal_union_le _ _).trans + apply add_le_add le_rfl + apply (measureReal_biUnion_finset_le s B).trans + apply hsum.trans + calc + _ ≤ exp ((r/2)*(n:ℝ))*(C*exp (-r*(n:ℝ))) := mul_le_mul_of_nonneg_right hsize (by positivity) + _ = _ := by rw [← mul_assoc,mul_comm (exp _) C,mul_assoc,← exp_add]; congr 2; ring +end SKGap +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/SparseQuadratic.lean b/lean/OAI/Probability/SKGap/Localization/SparseQuadratic.lean new file mode 100644 index 0000000000000000000000000000000000000000..e89d6b722043c1bfae74d3ee62816049173a7de8 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/SparseQuadratic.lean @@ -0,0 +1,63 @@ +import Mathlib +import OAI.Probability.SKGap.Model + +namespace OAI + +section +noncomputable section +open Real +open scoped RealInnerProductSpace +namespace SKGap + +lemma norm_product_le_sqrt {E : Type*} [SeminormedAddCommGroup E] + (b c : E) {q η : ℝ} (hq : 0 ≤ q) (hη : 0 ≤ η) + (hb : ‖b‖^2 ≤ q) (hc : ‖c‖^2 ≤ η*q) : ‖b‖*‖c‖ ≤ sqrt η*q := by + have hs := sq_sqrt hη + have hh := mul_le_mul hb hc (sq_nonneg ‖c‖) hq + have hplus : 0 ≤ sqrt η*q := mul_nonneg (sqrt_nonneg η) hq + have hnorm : 0 ≤ ‖b‖*‖c‖ := mul_nonneg (norm_nonneg b) (norm_nonneg c) + apply (sq_le_sq₀ hnorm hplus).mp + calc + (‖b‖*‖c‖)^2=‖b‖^2*‖c‖^2 := by ring + _ ≤ q*(η*q) := hh + _ = (sqrt η*q)^2 := by rw [mul_pow,hs];ring + +lemma sparse_quadratic_split {E : Type*} [NormedAddCommGroup E] + [InnerProductSpace ℝ E] (B : E →L[ℝ] E) (b c : E) + {q η ε M : ℝ} (hq : 0 ≤ q) (hη : 0 ≤ η) (hM : 0 ≤ M) + (hB : ‖B‖ ≤ M) (hb : ‖b‖^2 ≤ q) (hc : ‖c‖^2 ≤ η*q) + (hs : |⟪b,B b⟫| ≤ ε*q) : + |⟪b+c,B (b+c)⟫| ≤ (ε+M*(2*sqrt η+η))*q := by + have hbound (u v : E) : |⟪u,B v⟫| ≤ M*‖u‖*‖v‖ := by + calc + _ ≤ ‖u‖*‖B v‖ := abs_real_inner_le_norm u (B v) + _ ≤ ‖u‖*(‖B‖*‖v‖) := mul_le_mul_of_nonneg_left (B.le_opNorm v) (norm_nonneg u) + _ ≤ ‖u‖*(M*‖v‖) := mul_le_mul_of_nonneg_left + (mul_le_mul_of_nonneg_right hB (norm_nonneg v)) (norm_nonneg u) + _ = _ := by ring + have hprod := norm_product_le_sqrt b c hq hη hb hc + have hbc : |⟪b,B c⟫| ≤ M*(sqrt η*q) := by + calc + _ ≤ M*(‖b‖*‖c‖) := by simpa only [mul_assoc] using hbound b c + _ ≤ _ := mul_le_mul_of_nonneg_left hprod hM + have hcb : |⟪c,B b⟫| ≤ M*(sqrt η*q) := by + calc + _ ≤ M*(‖b‖*‖c‖) := by simpa only [mul_comm,mul_left_comm,mul_assoc] using hbound c b + _ ≤ _ := mul_le_mul_of_nonneg_left hprod hM + have hcc : |⟪c,B c⟫| ≤ M*(η*q) := by + calc + _ ≤ M*‖c‖^2 := by simpa only [sq,mul_assoc] using hbound c c + _ ≤ _ := mul_le_mul_of_nonneg_left hc hM + rw [map_add,inner_add_left,inner_add_right,inner_add_right] + calc + _ ≤ (|⟪b,B b⟫|+|⟪b,B c⟫|)+(|⟪c,B b⟫|+|⟪c,B c⟫|) := + (abs_add_le _ _).trans (add_le_add (abs_add_le _ _) (abs_add_le _ _)) + _ ≤ (ε*q+M*(sqrt η*q))+(M*(sqrt η*q)+M*(η*q)) := + add_le_add (add_le_add hs hbc) (add_le_add hcb hcc) + _ = _ := by ring +end SKGap + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/SparseShrink.lean b/lean/OAI/Probability/SKGap/Localization/SparseShrink.lean new file mode 100644 index 0000000000000000000000000000000000000000..e51a14cc31c58faf49b9128d7d77fd7ce1b1fe43 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/SparseShrink.lean @@ -0,0 +1,157 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.DiagonalHessianJoined +import OAI.Probability.SKGap.Localization.SparseCubeNet + +namespace OAI + +section +noncomputable section +namespace SKGap +open MeasureTheory Real Set +open scoped BigOperators + +theorem sparse_uniform_exponential_shrink {M ζ r : ℝ} (hζ : 0 < ζ) (hr : 0 < r) : + ∃ ε₀ : ℝ,0 < ε₀ ∧ ∀ ε : ℝ, 0 < ε → ε ≤ ε₀ → ∀ (Ω : Type*) [MeasurableSpace Ω] (μ : Measure Ω) + [IsFiniteMeasure μ] (n : ℕ) (v : Fin n → ℝ) (_hv : ∀ i,v i ∈ Icc 0 M) + (E : Set Ω) (GoodHigh GoodLow : (Fin n → ℝ) → Ω → Prop) (C : ℝ), + 0 ≤ C → + (∀ b, (∀ i,b i ∈ Icc 0 M) → (∑ i,(b i-v i)^2) ≤ 4*ε^2*(n:ℝ) → + μ.real {ω | ¬GoodHigh b ω} ≤ C*exp (-r*(n:ℝ))) → + (∀ ω ∈ E,∀ a b, (∀ i,a i ∈ Icc 0 M) → (∀ i,b i ∈ Icc 0 M) → + (∀ i,|a i-b i| ≤ ζ) → GoodHigh b ω → GoodLow a ω) → + μ.real {ω | ∃ a, (∀ i,a i ∈ Icc 0 M) ∧ (∑ i,(a i-v i)^2) ≤ ε^2*(n:ℝ) ∧ + ¬GoodLow a ω} ≤ μ.real Eᶜ+C*exp (-(r/2)*(n:ℝ)) := by + classical + obtain ⟨grid,hgrid,hcover⟩ := interval_mesh (M := M) hζ + let κ := {x : ℝ // x ∈ grid} + obtain ⟨α,hα,hcount⟩ := sparse_option_small_entropy (κ := κ) (half_pos hr) + let ε₀ := sqrt α*ζ + have hε₀ : 0 < ε₀ := mul_pos (sqrt_pos.mpr hα) hζ + have heq₀ : ε₀^2=α*ζ^2 := by dsimp [ε₀]; rw [mul_pow,sq_sqrt hα.le] + refine ⟨ε₀,hε₀,?_⟩ + intro ε hε hεle + have heq : ε^2 ≤ α*ζ^2 := by rw [← heq₀]; exact pow_le_pow_left₀ hε.le hεle 2 + intro Ω _ μ _ n v hv E GoodHigh GoodLow C hC hfixed hnear + let val : κ → ℝ := Subtype.val + let s : Finset (Fin n → Option κ) := Finset.univ.filter (fun f => + ((optionSupport f).card:ℝ) ≤ α*(n:ℝ) ∧ + (∑ i,(optionCube v val f i-v i)^2) ≤ 4*ε^2*(n:ℝ)) + have hsize : (s.card:ℝ) ≤ exp ((r/2)*(n:ℝ)) := by + simpa only [Fintype.card_fin] using hcount (Fin n) s (fun f hf => by simpa only [Fintype.card_fin] using (Finset.mem_filter.mp hf).2.1) + let B : (Fin n → Option κ) → Set Ω := fun f => {ω | ¬GoodHigh (optionCube v val f) ω} + have hsub : {ω | ∃ a, (∀ i,a i ∈ Icc 0 M) ∧ (∑ i,(a i-v i)^2) ≤ ε^2*(n:ℝ) ∧ + ¬GoodLow a ω} ⊆ Eᶜ ∪ ⋃ f ∈ s,B f := by + intro ω ⟨a,ha,ha2,hbad⟩ + by_cases hE : ω ∈ E + · obtain ⟨f,hf,hap,hfp⟩ := sparse_cube_approx hζ v a val ha + (fun x hx => by obtain ⟨y,hy,hyx⟩ := hcover x hx; exact ⟨⟨y,hy⟩,hyx⟩) + (by + simp only [Fintype.card_fin] + exact ha2.trans (mul_le_mul_of_nonneg_right heq (Nat.cast_nonneg n))) + have hb : ∀ i,optionCube v val f i ∈ Icc 0 M := + optionCube_bounds v val hv (fun k => hgrid k.val k.property) f + have hd : (∑ i,(optionCube v val f i-v i)^2) ≤ 4*ε^2*(n:ℝ) := by + calc + _ ≤ ∑ i,4*(a i-v i)^2 := by + apply Finset.sum_le_sum; intro i _ + have h := hfp i + have hh := mul_self_le_mul_self (abs_nonneg (optionCube v val f i-v i)) h + nlinarith only [hh,sq_abs (optionCube v val f i-v i),sq_abs (a i-v i)] + _ = 4*(∑ i,(a i-v i)^2) := by rw [Finset.mul_sum] + _ ≤ _ := by linarith + have hfs : f ∈ s := Finset.mem_filter.mpr ⟨Finset.mem_univ _,by simpa only [Fintype.card_fin] using And.intro hf hd⟩ + exact Or.inr (mem_iUnion₂.mpr ⟨f,hfs,fun hg => hbad (hnear ω hE a _ ha hb hap hg)⟩) + · exact Or.inl hE + have hsum : (∑ f ∈ s,μ.real (B f)) ≤ (s.card:ℝ)*(C*exp (-r*(n:ℝ))) := by + calc + _ ≤ ∑ _f ∈ s,C*exp (-r*(n:ℝ)) := by + apply Finset.sum_le_sum + intro f hf + exact hfixed _ (optionCube_bounds v val hv (fun k => hgrid k.val k.property) f) + (Finset.mem_filter.mp hf).2.2 + _ = _ := by simp + apply (measureReal_mono hsub (measure_ne_top _ _)).trans + apply (measureReal_union_le _ _).trans + apply add_le_add le_rfl + apply (measureReal_biUnion_finset_le s B).trans + apply hsum.trans + calc + _ ≤ exp ((r/2)*(n:ℝ))*(C*exp (-r*(n:ℝ))) := mul_le_mul_of_nonneg_right hsize (by positivity) + _ = _ := by rw [← mul_assoc,mul_comm (exp _) C,mul_assoc,← exp_add]; congr 2; ring +end SKGap +end +end + +section +noncomputable section +namespace SKGap +open Matrix Real Set MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix.Norms.L2Operator + +lemma conditional_mesh_size {A L m : ℝ} (hA : 0 < A) (hL : 0 < L) (hm : 0 < m) : + ∃ ζ : ℝ, 0 < ζ ∧ 2*sqrt A*L*sqrt ζ ≤ m/2 := by + let r := m/(4*sqrt A*L) + have hr : 0 < r := by dsimp [r]; positivity + refine ⟨r^2,sq_pos_of_pos hr,?_⟩ + rw [sqrt_sq hr.le] + dsimp [r] + have hd : sqrt A ≠ 0 := (sqrt_pos.mpr hA).ne' + field_simp + ring_nf + rfl + +theorem conditional_sparse_uniform {j A L m c : ℝ} + (hj : 0 < j) (hA : 0 < A) (hL : 0 < L) (hm : 0 < m) (hc : 0 < c) : + ∃ ε0 : ℝ,0 < ε0 ∧ ∀ ε : ℝ,0 < ε → ε ≤ ε0 → + ∀ (n : ℕ) [NeZero n] (v : Fin n → ℝ), (∀ i,v i ∈ Icc 0 A) → + ∀ K : (MatrixCoordinates (Fin n) → ℝ) → Matrix (Fin n) (Fin n) ℝ, + (∀ g,(K g).IsHermitian) → + (∀ g,opNorm (goeMatrix (j/(n:ℝ)) g) ≤ 2*sqrt j+1 → opNorm (K g) ≤ L) → + (∀ b, (∀ i,b i ∈ Icc 0 A) → (∑ i,(b i-v i)^2) ≤ 4*ε^2*(n:ℝ) → + (Measure.pi (fun _ : MatrixCoordinates (Fin n)=>gaussianReal 0 1)).real + {g | ¬(diagonalHessian b (K g)-m • (1 : Matrix (Fin n) (Fin n) ℝ)).PosDef} ≤ + 101*exp (-c*(n:ℝ))) → + (Measure.pi (fun _ : MatrixCoordinates (Fin n)=>gaussianReal 0 1)).real + {g | ∃ a, (∀ i,a i ∈ Icc 0 A) ∧ (∑ i,(a i-v i)^2) ≤ ε^2*(n:ℝ) ∧ + ¬(diagonalHessian a (K g)-(m/2) • (1 : Matrix (Fin n) (Fin n) ℝ)).PosSemidef} ≤ + 103*exp (-(min (1/(π^2*j)) (c/2))*(n:ℝ)) := by + obtain ⟨ζ,hζ,hζm⟩ := conditional_mesh_size hA hL hm + obtain ⟨ε0,hε0,hsmall⟩ := sparse_uniform_exponential_shrink (M := A) hζ hc + refine ⟨ε0,hε0,?_⟩ + intro ε hε hεle n _ v hv K hK hKn hfixed + let μ := Measure.pi (fun _ : MatrixCoordinates (Fin n)=>gaussianReal 0 1) + let E : Set (MatrixCoordinates (Fin n) → ℝ) := {g | opNorm (goeMatrix (j/(n:ℝ)) g) ≤ 2*sqrt j+1} + have hevent : μ.real Eᶜ ≤ 2*exp (-(n:ℝ)/(π^2*j)) := by + change (gaussianCoordinates (MatrixCoordinates (Fin n))).real + {g | ¬‖matrixOperator (goeMatrix (j/(n:ℝ)) g)‖ ≤ 2*sqrt j+1} ≤ _ + simp only [not_le] + simpa only [one_pow,_root_.neg_one_mul,Fintype.card_fin] using + (goe_norm_tail (ι := Fin n) hj (by norm_num : (0:ℝ) ≤ 1)) + have hsparse := hsmall ε hε hεle (MatrixCoordinates (Fin n) → ℝ) μ n v hv E + (fun b g=>(diagonalHessian b (K g)-m • (1 : Matrix (Fin n) (Fin n) ℝ)).PosDef) + (fun a g=>(diagonalHessian a (K g)-(m/2) • (1 : Matrix (Fin n) (Fin n) ℝ)).PosSemidef) + 101 (by norm_num) hfixed (by + intro g hg a b ha hb hab hh + have hnorm : ‖K g‖ ≤ L := hKn g hg + have hd := diagonalHessian_half_holder hA.le hζ.le hL.le ha hb hab (K g) hnorm + have htrans := hermitian_margin_transfer (diagonalHessian_hermitian a (hK g)) + (diagonalHessian_hermitian b (hK g)) (hd.trans hζm) hh.posSemidef + have hhalf : m-m/2=m/2 := by ring + simpa only [hhalf] using htrans) + apply hsparse.trans + have h1 : -(n:ℝ)/(π^2*j) ≤ -(min (1/(π^2*j)) (c/2))*(n:ℝ) := by + have h := mul_le_mul_of_nonneg_right (min_le_left (1/(π^2*j)) (c/2)) (Nat.cast_nonneg n) + calc + _ = -((1/(π^2*j))*(n:ℝ)) := by ring + _ ≤ _ := by linarith only [h] + have h2 : -(c/2)*(n:ℝ) ≤ -(min (1/(π^2*j)) (c/2))*(n:ℝ) := by + have h := mul_le_mul_of_nonneg_right (min_le_right (1/(π^2*j)) (c/2)) (Nat.cast_nonneg n) + linarith only [h] + have h1' := exp_le_exp.mpr h1 + have h2' := exp_le_exp.mpr h2 + nlinarith only [hevent,h1',h2'] +end SKGap +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/StandardArrayLaw.lean b/lean/OAI/Probability/SKGap/Localization/StandardArrayLaw.lean new file mode 100644 index 0000000000000000000000000000000000000000..6ab6ab9b52e65567656a79ef130bce2508986d23 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/StandardArrayLaw.lean @@ -0,0 +1,326 @@ +import Mathlib +import OAI.Probability.SKGap.Model + +namespace OAI + +section +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise +namespace SKGapCutoff.Regression + +local instance matrixMeasurable {n m : ℕ} : MeasurableSpace (Matrix (Fin n) (Fin m) ℝ) := + inferInstanceAs (MeasurableSpace (Fin n → Fin m → ℝ)) + +local instance matrixBorel {n m : ℕ} : BorelSpace (Matrix (Fin n) (Fin m) ℝ) := + inferInstanceAs (BorelSpace (Fin n → Fin m → ℝ)) + +noncomputable def standardArrayLaw (ι : Type*) [Fintype ι] : Measure (ι → ℝ) := + Measure.pi (fun _ => gaussianReal 0 1) + +instance {ι : Type*} [Fintype ι] : IsProbabilityMeasure (standardArrayLaw ι) := by + unfold standardArrayLaw + infer_instance + +lemma coordinate_hasLaw {ι : Type*} [Fintype ι] (i : ι) : + HasLaw (fun g : ι → ℝ => g i) (gaussianReal 0 1) (standardArrayLaw ι) := + (measurePreserving_eval (fun _ : ι => gaussianReal 0 1) i).hasLaw + +lemma coordinates_independent {ι : Type*} [Fintype ι] : + iIndepFun (fun i (g : ι → ℝ) => g i) (standardArrayLaw ι) := + iIndepFun_pi (fun _ => measurable_id.aemeasurable) + +lemma coordinates_gaussian {ι : Type*} [Fintype ι] : + HasGaussianLaw (fun g : ι → ℝ => g) (standardArrayLaw ι) := + coordinates_independent.hasGaussianLaw (fun i => (coordinate_hasLaw i).hasGaussianLaw) + +lemma coordinate_covariance {ι : Type*} [Fintype ι] [DecidableEq ι] (i j : ι) : + cov[fun g : ι → ℝ => g i, fun g => g j; standardArrayLaw ι] = if i = j then 1 else 0 := by + by_cases h : i = j + · subst j + rw [covariance_self (coordinate_hasLaw i).aemeasurable, + (coordinate_hasLaw i).variance_eq, variance_id_gaussianReal] + simp + · rw [ite_eq_right h] + exact (coordinates_independent.indepFun h).covariance_eq_zero + ((coordinate_hasLaw i).hasGaussianLaw.memLp_two) + ((coordinate_hasLaw j).hasGaussianLaw.memLp_two) + +noncomputable def linearTest {ι : Type*} [Fintype ι] (a : ι → ℝ) : (ι → ℝ) →L[ℝ] ℝ := + ∑ i, a i • ContinuousLinearMap.proj i + +@[simp] lemma linearTest_apply {ι : Type*} [Fintype ι] (a g : ι → ℝ) : + linearTest a g = ∑ i, a i * g i := by simp [linearTest] + +lemma linearTest_covariance {ι : Type*} [Fintype ι] [DecidableEq ι] (a b : ι → ℝ) : + cov[fun g : ι → ℝ => ∑ i, a i * g i, + fun g => ∑ i, b i * g i; standardArrayLaw ι] = ∑ i, a i * b i := by + rw [covariance_fun_sum_fun_sum] + · simp_rw [covariance_const_mul_left, covariance_const_mul_right, coordinate_covariance] + simp + · exact fun i => ((coordinate_hasLaw i).hasGaussianLaw.memLp_two).const_mul _ + · exact fun i => ((coordinate_hasLaw i).hasGaussianLaw.memLp_two).const_mul _ + +noncomputable def goe {n : ℕ} (g : (Fin n × Fin n) → ℝ) : Matrix (Fin n) (Fin n) ℝ := + fun i j => (g (i,j) + g (j,i)) / Real.sqrt (2*n) + +lemma goe_symmetric {n : ℕ} (g : (Fin n × Fin n) → ℝ) : (goe g)ᵀ = goe g := by + ext i j + simp [goe, add_comm] + +noncomputable def goeCLM (n : ℕ) : ((Fin n × Fin n) → ℝ) →L[ℝ] Matrix (Fin n) (Fin n) ℝ := + ContinuousLinearMap.pi fun i => ContinuousLinearMap.pi fun j => + (Real.sqrt (2*n))⁻¹ • ((ContinuousLinearMap.proj (i,j) : ((Fin n × Fin n) → ℝ) →L[ℝ] ℝ) + ContinuousLinearMap.proj (j,i)) + +@[simp] lemma goeCLM_apply (n : ℕ) (g : (Fin n × Fin n) → ℝ) : goeCLM n g = goe g := by + ext i j + change (Real.sqrt (2*n))⁻¹ * (g (i,j) + g (j,i)) = + (g (i,j) + g (j,i)) / Real.sqrt (2*n) + rw [div_eq_mul_inv, mul_comm] + +lemma goe_gaussian (n : ℕ) : + HasGaussianLaw (fun g : (Fin n × Fin n) → ℝ => goe g) + (standardArrayLaw (Fin n × Fin n)) := by + have h := coordinates_gaussian.map_fun + (show ((Fin n × Fin n) → ℝ) →L[ℝ] (Fin n → Fin n → ℝ) from goeCLM n) + exact h.congr (Filter.Eventually.of_forall (goeCLM_apply n)) + +lemma goe_entry_memLp {n : ℕ} (i j : Fin n) : + MemLp (fun g : (Fin n × Fin n) → ℝ => goe g i j) 2 (standardArrayLaw (Fin n × Fin n)) := + ((goe_gaussian n).eval i |>.eval j).memLp_two + +lemma goe_entry_covariance {n : ℕ} (hn : 0 < n) (i j k l : Fin n) : + cov[fun g : (Fin n × Fin n) → ℝ => goe g i j, fun g => goe g k l; + standardArrayLaw (Fin n × Fin n)] = + ((if i = k ∧ j = l then 1 else 0) + (if i = l ∧ j = k then 1 else 0)) / n := by + have hLp (a : Fin n × Fin n) := (coordinate_hasLaw a).hasGaussianLaw.memLp_two + simp only [goe, covariance_fun_div_left, covariance_fun_div_right] + change cov[(fun g => g (i,j)) + (fun g => g (j,i)), + (fun g => g (k,l)) + (fun g => g (l,k)); standardArrayLaw (Fin n × Fin n)] / + Real.sqrt (2*n) / Real.sqrt (2*n) = _ + rw [covariance_add_left (hLp _) (hLp _) ((hLp _).add (hLp _)), + covariance_add_right (hLp _) (hLp _) (hLp _), + covariance_add_right (hLp _) (hLp _) (hLp _)] + simp only [coordinate_covariance, Prod.mk.injEq] + have hnR : (0 : ℝ) < n := by exact_mod_cast hn + have hs : Real.sqrt (2*n) ^ 2 = 2*n := Real.sq_sqrt (by positivity) + have hs0 : Real.sqrt (2*(n : ℝ)) ≠ 0 := (Real.sqrt_pos.2 (by positivity)).ne' + rw [div_div, ← pow_two] + rw [hs] + have ha : (j = k ∧ i = l) ↔ (i = l ∧ j = k) := and_comm + have hb : (j = l ∧ i = k) ↔ (i = k ∧ j = l) := and_comm + simp only [ha, hb] + ring + +noncomputable def sandwichCLM {a n b : ℕ} + (A : Matrix (Fin a) (Fin n) ℝ) (B : Matrix (Fin n) (Fin b) ℝ) : + Matrix (Fin n) (Fin n) ℝ →L[ℝ] Matrix (Fin a) (Fin b) ℝ := + LinearMap.toContinuousLinearMap { + toFun := fun G => A * G * B + map_add' := by intro G H; simp [Matrix.mul_add, Matrix.add_mul] + map_smul' := by intro c G; simp [Matrix.mul_smul, Matrix.smul_mul] } + +@[simp] lemma sandwichCLM_apply {a n b : ℕ} + (A : Matrix (Fin a) (Fin n) ℝ) (B : Matrix (Fin n) (Fin b) ℝ) + (G : Matrix (Fin n) (Fin n) ℝ) : sandwichCLM A B G = A * G * B := rfl + +def residualProjection {n r : ℕ} (U : Matrix (Fin n) (Fin r) ℝ) : Matrix (Fin n) (Fin n) ℝ := + 1 - U * Uᵀ + +lemma residualProjection_symmetric {n r : ℕ} (U : Matrix (Fin n) (Fin r) ℝ) : + (residualProjection U)ᵀ = residualProjection U := by + simp [residualProjection] + +lemma residualProjection_mul {n r : ℕ} (U : Matrix (Fin n) (Fin r) ℝ) (hU : Uᵀ * U = 1) : + residualProjection U * U = 0 := by + simp [residualProjection, Matrix.sub_mul, Matrix.mul_assoc, hU] + +lemma mul_residualProjection {n r : ℕ} (U : Matrix (Fin n) (Fin r) ℝ) (hU : Uᵀ * U = 1) : + Uᵀ * residualProjection U = 0 := by + simp [residualProjection, Matrix.mul_sub, ← Matrix.mul_assoc, hU] + +lemma regression_decomposition {n r : ℕ} (G : Matrix (Fin n) (Fin n) ℝ) + (U : Matrix (Fin n) (Fin r) ℝ) (hG : Gᵀ = G) : + G = (G*U)*Uᵀ + U*(G*U)ᵀ - U*(Uᵀ*(G*U))*Uᵀ + + residualProjection U * G * residualProjection U := by + simp only [Matrix.transpose_mul, hG, residualProjection] + simp only [Matrix.sub_mul, Matrix.mul_sub, Matrix.one_mul, Matrix.mul_one] + simp only [Matrix.mul_assoc] + abel + +lemma goe_entry_sandwich_covariance {n a b : ℕ} (hn : 0 < n) + (C : Matrix (Fin a) (Fin n) ℝ) (D : Matrix (Fin n) (Fin b) ℝ) + (i j : Fin n) (k : Fin a) (l : Fin b) : + cov[fun g : (Fin n × Fin n) → ℝ => goe g i j, + fun g => (C * goe g * D) k l; standardArrayLaw (Fin n × Fin n)] = + (C k i * D j l + C k j * D i l) / n := by + have hterm (p q : Fin n) : MemLp (fun g : (Fin n × Fin n) → ℝ => + C k q * goe g q p * D p l) 2 (standardArrayLaw (Fin n × Fin n)) := + ((goe_entry_memLp q p).const_mul _).mul_const _ + have hsum (p : Fin n) := memLp_finsetSum Finset.univ (fun q _ => hterm p q) + have he (g : (Fin n × Fin n) → ℝ) : (C * goe g * D) k l = + ∑ p, ∑ q, C k q * goe g q p * D p l := by + simp [Matrix.mul_apply, Finset.sum_mul] + simp_rw [he] + rw [covariance_fun_sum_right hsum (goe_entry_memLp i j)] + simp_rw [covariance_fun_sum_right (fun q => hterm _ q) (goe_entry_memLp i j), + covariance_mul_const_right, covariance_const_mul_right, goe_entry_covariance hn] + simp only [ite_and, add_div, mul_add, add_mul, Finset.sum_add_distrib, + ite_div, mul_ite, ite_mul, zero_div, mul_zero, zero_mul] + simp + ring + +lemma goe_sandwich_covariance {n a b c d : ℕ} (hn : 0 < n) + (A : Matrix (Fin a) (Fin n) ℝ) (B : Matrix (Fin n) (Fin b) ℝ) + (C : Matrix (Fin c) (Fin n) ℝ) (D : Matrix (Fin n) (Fin d) ℝ) + (i : Fin a) (j : Fin b) (k : Fin c) (l : Fin d) : + cov[fun g : (Fin n × Fin n) → ℝ => (A * goe g * B) i j, + fun g => (C * goe g * D) k l; standardArrayLaw (Fin n × Fin n)] = + ((Bᵀ * D) j l * (A * Cᵀ) i k + (C * B) k j * (A * D) i l) / n := by + have hterm (p q : Fin n) : MemLp (fun g : (Fin n × Fin n) → ℝ => + A i q * goe g q p * B p j) 2 (standardArrayLaw (Fin n × Fin n)) := + ((goe_entry_memLp q p).const_mul _).mul_const _ + have hsum (p : Fin n) := memLp_finsetSum Finset.univ (fun q _ => hterm p q) + have hCD : MemLp (fun g : (Fin n × Fin n) → ℝ => (C * goe g * D) k l) + 2 (standardArrayLaw (Fin n × Fin n)) := by + simp only [Matrix.mul_apply, Finset.sum_mul] + exact memLp_finsetSum _ (fun p _ => memLp_finsetSum _ + (fun q _ => ((goe_entry_memLp q p).const_mul _).mul_const _)) + have he (g : (Fin n × Fin n) → ℝ) : (A * goe g * B) i j = + ∑ p, ∑ q, A i q * goe g q p * B p j := by + simp [Matrix.mul_apply, Finset.sum_mul] + simp_rw [he] + rw [covariance_fun_sum_left hsum hCD] + simp_rw [covariance_fun_sum_left (fun q => hterm _ q) hCD, + covariance_mul_const_left, covariance_const_mul_left, goe_entry_sandwich_covariance hn] + simp only [Matrix.mul_apply, Matrix.transpose_apply, Finset.sum_mul, Finset.mul_sum, + ← Finset.sum_add_distrib] + rw [Finset.sum_comm] + simp only [← mul_div_assoc, div_mul_eq_mul_div, ← Finset.sum_div] + apply congrArg (fun x : ℝ => x / n) + apply Finset.sum_congr rfl + intro p _ + apply Finset.sum_congr rfl + intro q _ + ring + +lemma residual_answer_covariance {n r : ℕ} (hn : 0 < n) + (U : Matrix (Fin n) (Fin r) ℝ) (hU : Uᵀ * U = 1) + (i j k : Fin n) (l : Fin r) : + cov[fun g : (Fin n × Fin n) → ℝ => + (residualProjection U * goe g * residualProjection U) i j, + fun g => (goe g * U) k l; standardArrayLaw (Fin n × Fin n)] = 0 := by + have h := goe_sandwich_covariance hn (residualProjection U) (residualProjection U) + (1 : Matrix (Fin n) (Fin n) ℝ) U i j k l + simpa [residualProjection_symmetric, residualProjection_mul U hU] using h + +noncomputable def entryCLM {n m : ℕ} (i : Fin n) (j : Fin m) : + Matrix (Fin n) (Fin m) ℝ →L[ℝ] ℝ := + (ContinuousLinearMap.proj j : (Fin m → ℝ) →L[ℝ] ℝ).comp + (ContinuousLinearMap.proj i : (Fin n → Fin m → ℝ) →L[ℝ] (Fin m → ℝ)) + +@[simp] lemma entryCLM_apply {n m : ℕ} (i : Fin n) (j : Fin m) + (G : Matrix (Fin n) (Fin m) ℝ) : entryCLM i j G = G i j := rfl + +noncomputable def regressionCLM {n r : ℕ} (U : Matrix (Fin n) (Fin r) ℝ) : + ((Fin n × Fin n) → ℝ) →L[ℝ] + (((Fin n × Fin n) → ℝ) × ((Fin n × Fin r) → ℝ)) := + (ContinuousLinearMap.pi (fun p : Fin n × Fin n => + ((entryCLM p.1 p.2).comp (sandwichCLM (residualProjection U) (residualProjection U))).comp + (goeCLM n))).prod + (ContinuousLinearMap.pi (fun p : Fin n × Fin r => + ((entryCLM p.1 p.2).comp (sandwichCLM (1 : Matrix (Fin n) (Fin n) ℝ) U)).comp + (goeCLM n))) + +lemma regressionCLM_apply {n r : ℕ} (U : Matrix (Fin n) (Fin r) ℝ) + (g : (Fin n × Fin n) → ℝ) : + regressionCLM U g = + (fun p : Fin n × Fin n => (residualProjection U * goe g * residualProjection U) p.1 p.2, + fun p : Fin n × Fin r => (goe g * U) p.1 p.2) := by + change (fun p : Fin n × Fin n => + (residualProjection U * (goeCLM n) g * residualProjection U) p.1 p.2, + fun p : Fin n × Fin r => ((1 : Matrix (Fin n) (Fin n) ℝ) * (goeCLM n) g * U) p.1 p.2) = _ + rw [goeCLM_apply, Matrix.one_mul] + +lemma residual_answer_independent {n r : ℕ} (hn : 0 < n) + (U : Matrix (Fin n) (Fin r) ℝ) (hU : Uᵀ * U = 1) : + IndepFun (fun g : (Fin n × Fin n) → ℝ => fun p : Fin n × Fin n => + (residualProjection U * goe g * residualProjection U) p.1 p.2) + (fun g => fun p : Fin n × Fin r => (goe g * U) p.1 p.2) + (standardArrayLaw (Fin n × Fin n)) := by + have hXY := (coordinates_gaussian.map_fun (regressionCLM U)).congr + (Filter.Eventually.of_forall (regressionCLM_apply U)) + exact hXY.indepFun_of_covariance_eval (fun p q => + residual_answer_covariance hn U hU p.1 p.2 q.1 q.2) + +def revealedCompletion {n r : ℕ} (U Y : Matrix (Fin n) (Fin r) ℝ) : + Matrix (Fin n) (Fin n) ℝ := + Y * Uᵀ + U * Yᵀ - U * (Uᵀ * Y) * Uᵀ + +lemma revealedCompletion_answer {n r : ℕ} (U Y : Matrix (Fin n) (Fin r) ℝ) + (hU : Uᵀ * U = 1) (hY : Uᵀ * Y = Yᵀ * U) : + revealedCompletion U Y * U = Y := by + simp only [revealedCompletion, Matrix.sub_mul, Matrix.add_mul] + rw [Matrix.mul_assoc Y, hU, Matrix.mul_one, Matrix.mul_assoc U Yᵀ, + Matrix.mul_assoc (U * (Uᵀ * Y)), hU, Matrix.mul_one, hY] + abel + +lemma revealedCompletion_symmetric {n r : ℕ} (U Y : Matrix (Fin n) (Fin r) ℝ) + (hY : Uᵀ * Y = Yᵀ * U) : + (revealedCompletion U Y)ᵀ = revealedCompletion U Y := by + simp only [revealedCompletion, Matrix.transpose_sub, Matrix.transpose_add, + Matrix.transpose_mul, Matrix.transpose_transpose] + rw [← hY] + simp only [Matrix.mul_assoc] + abel + +lemma revealedCompletion_residual {n r : ℕ} (U Y : Matrix (Fin n) (Fin r) ℝ) + (hU : Uᵀ * U = 1) : + residualProjection U * revealedCompletion U Y * residualProjection U = 0 := by + simp only [revealedCompletion, Matrix.mul_sub, Matrix.mul_add, Matrix.sub_mul, + Matrix.add_mul] + rw [Matrix.mul_assoc (residualProjection U) (Y * Uᵀ) (residualProjection U)] + rw [Matrix.mul_assoc Y Uᵀ (residualProjection U), mul_residualProjection U hU, + Matrix.mul_zero, Matrix.mul_zero] + simp only [← Matrix.mul_assoc, residualProjection_mul U hU, Matrix.zero_mul, + add_zero, sub_zero] + +lemma revealedCompletion_unique {n r : ℕ} (G : Matrix (Fin n) (Fin n) ℝ) + (U Y : Matrix (Fin n) (Fin r) ℝ) (hG : Gᵀ = G) (hY : G*U = Y) + (hR : residualProjection U * G * residualProjection U = 0) : + G = revealedCompletion U Y := by + simpa only [hY, hR, add_zero, revealedCompletion] using regression_decomposition G U hG + +lemma regression_factorization {n r : ℕ} (hn : 0 < n) + (U : Matrix (Fin n) (Fin r) ℝ) (hU : Uᵀ * U = 1) : + (standardArrayLaw (Fin n × Fin n)).map (fun g => + (fun p : Fin n × Fin n => (residualProjection U * goe g * residualProjection U) p.1 p.2, + fun p : Fin n × Fin r => (goe g * U) p.1 p.2)) = + ((standardArrayLaw (Fin n × Fin n)).map (fun g => fun p : Fin n × Fin n => + (residualProjection U * goe g * residualProjection U) p.1 p.2)).prod + ((standardArrayLaw (Fin n × Fin n)).map (fun g => fun p : Fin n × Fin r => + (goe g * U) p.1 p.2)) := by + have hXY := (coordinates_gaussian.map_fun (regressionCLM U)).congr + (Filter.Eventually.of_forall (regressionCLM_apply U)) + exact (residual_answer_independent hn U hU).map_prod_eq_prod_map_map + hXY.fst.aemeasurable hXY.snd.aemeasurable + +end SKGapCutoff.Regression + +open scoped BigOperators + +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/StartedFixed.lean b/lean/OAI/Probability/SKGap/Localization/StartedFixed.lean new file mode 100644 index 0000000000000000000000000000000000000000..582c7be4f3230c5993551ede372f306a56966e28 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/StartedFixed.lean @@ -0,0 +1,157 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.RecipeCoefficientClosure +import OAI.Probability.SKGap.Localization.StartedRecipe + +namespace OAI + +section + +noncomputable section +open scoped BigOperators +namespace SKGapCutoff.Recipe.OrdinaryData +open Primary +variable {n M : ℕ} {κ σ : Type*} [Fintype κ] [DecidableEq κ] [Fintype σ] + +def appendFixed (D : OrdinaryData n (Fin M) κ σ) (N : ℕ) (v : Fin n→ℝ) : + OrdinaryData n (Fin M) κ (σ⊕Unit) where + J:=D.J + j:=D.j + H:=D.H + predecessor:=D.predecessor + θ:=D.θ + seed:=Sum.elim D.seed (fun _=>v) + seedFunction:=fun a s i u=>if a=N+1 then + Sum.elim (fun _=>0) (fun _=>1) s + else Sum.elim (fun s=>D.seedFunction a s i u) (fun _=>0) s + seedDerivative:=fun a s i u=>if a=N+1 then + Sum.elim (fun _=>0) (fun _=>0) s + else Sum.elim (fun s=>D.seedDerivative a s i u) (fun _=>0) s + auxFunction:=fun a b i u=>if a=N+1 then 0 else D.auxFunction a b i u + auxDerivative:=fun a b i u=>if a=N+1 then 0 else D.auxDerivative a b i u + +lemma appendFixed_sourceOf (D : OrdinaryData n (Fin M) κ σ) (N : ℕ) (v : Fin n→ℝ) + (a : ℕ) (ha : a≤N) (Y : Fin a→VectorFields n) : + (D.appendFixed N v).sourceOf a Y=D.sourceOf a Y := by + ext x i + have hh:a≠N+1:=by omega + simp [sourceOf,seedCoefficient,auxCoefficient,coefficient,appendFixed,hh,Fintype.sum_sum_type] + +lemma appendFixed_partialOf (D : OrdinaryData n (Fin M) κ σ) (N : ℕ) (v : Fin n→ℝ) + (a : ℕ) (ha : a≤N) (l : Fin M) (Y : Fin a→VectorFields n) : + (D.appendFixed N v).partialOf a l Y=D.partialOf a l Y := by + ext x i + have hh:a≠N+1:=by omega + simp [partialOf,seedPartial,auxPartial,localPartial,partialAt,appendFixed,hh,Fintype.sum_sum_type] + +lemma appendFixed_fieldOf (D : OrdinaryData n (Fin M) κ σ) (N : ℕ) (v : Fin n→ℝ) + (a : ℕ) (ha : a≤N) (W Y : Fin a→VectorFields n) : + (D.appendFixed N v).fieldOf a W Y=D.fieldOf a W Y := by + have hh:a≠N+1:=by omega + ext x i + simp only [fieldOf,D.appendFixed_sourceOf N v a ha,D.appendFixed_partialOf N v a ha] + simp only [appendFixed,auxCoefficient,ite_eq_right hh] + +lemma appendFixed_started_prefix (D : OrdinaryData n (Fin M) κ σ) (w y : VectorFields n) + (N : ℕ) (v : Fin n→ℝ) : ∀a≤N, + (D.appendFixed N v).startedSource w y a=D.startedSource w y a ∧ + (D.appendFixed N v).startedAuxiliary w y a=D.startedAuxiliary w y a := by + intro a + induction a using Nat.strong_induction_on with + | h a ih=> + intro ha + by_cases hz:a=0 + · subst a;simp + have hp:0(ih b b.isLt (b.isLt.le.trans ha)).1 + have hf:∀b:Fin a,(D.appendFixed N v).startedAuxiliary w y b=D.startedAuxiliary w y b:= + fun b=>(ih b b.isLt (b.isLt.le.trans ha)).2 + constructor + · rw [startedSource_eq _ _ _ hp,startedSource_eq _ _ _ hp] + simp only [hf,D.appendFixed_sourceOf N v a ha] + · rw [startedAuxiliary_eq _ _ _ hp,startedAuxiliary_eq _ _ _ hp] + simp only [hs,hf,D.appendFixed_fieldOf N v a ha] + +lemma appendFixed_started_source (D : OrdinaryData n (Fin M) κ σ) (w y : VectorFields n) + (N : ℕ) (v : Fin n→ℝ) : (D.appendFixed N v).startedSource w y (N+1)= + fun _=>v := by + rw [startedSource_eq _ _ _ (by omega)] + ext x i + simp [sourceOf,seedCoefficient,auxCoefficient,coefficient,appendFixed, + Fintype.sum_sum_type,localArgs] + +lemma appendFixed_seed (D : OrdinaryData n (Fin M) κ σ) (N : ℕ) (v : Fin n→ℝ) : + (∑s,vectorNorm ((D.appendFixed N v).seed s))=(∑s,vectorNorm (D.seed s))+vectorNorm v := by + simp [appendFixed,Fintype.sum_sum_type] + +omit [Fintype σ] in +lemma appendFixed_Admissible (D : OrdinaryData n (Fin M) κ σ) (N p : ℕ) (v : Fin n→ℝ) + (h : D.Admissible N p) : (D.appendFixed N v).Admissible (N+1) p := by + intro a ha l hl + by_cases he:a=N+1 + · subst a + constructor <;> intro s + · cases s <;> ext x i <;> + simp [seedPartial,localPartial,appendFixed,partialAt] + · ext x i;simp [auxPartial,localPartial,appendFixed,partialAt] + · have haN:a≤N:=by omega + constructor + · intro s;cases s with + | inl s=>simpa [seedPartial,localPartial,appendFixed,he] using (h a haN l hl).1 s + | inr s=>ext x i;simp [seedPartial,localPartial,appendFixed,he,partialAt] + · intro b;simpa [auxPartial,localPartial,appendFixed,he] using (h a haN l hl).2 b + +end SKGapCutoff.Recipe.OrdinaryData + +end +end + +section + +noncomputable section +open scoped BigOperators +namespace SKGapCutoff.Recipe.OrdinaryData +variable {n M : ℕ} {κ σ : Type*} [Fintype κ] [DecidableEq κ] [Fintype σ] + +omit [Fintype σ] in +lemma CoefficientClass.appendFixed {D : OrdinaryData n (Fin M) κ σ} {N : ℕ} {x : Spin n} + {K : ℝ} (h : D.CoefficientClass N x K) (hK : 1≤K) (v : Fin n→ℝ) : + (D.appendFixed N v).CoefficientClass (N+1) x K := by + have h0:0≤K:=by linarith [h.one_le] + refine ⟨h.one_le,?_,?_,?_,?_⟩ + · intro a ha s + by_cases he:a=N+1 + · subst a;cases s with + | inl s=>simpa only [OrdinaryData.appendFixed,ite_eq_left rfl,ite_true,Sum.elim_inl] using + (segmentRegular_const D.H D.θ x 0).mono h0 + | inr s=>simpa only [OrdinaryData.appendFixed,ite_eq_left rfl,ite_true,Sum.elim_inr] using + (segmentRegular_const D.H D.θ x 1).mono h0 + · cases s with + | inl s=>simpa only [OrdinaryData.appendFixed,ite_eq_right he,Sum.elim_inl] using h.seedRegular a (by omega) s + | inr s=>simpa only [OrdinaryData.appendFixed,ite_eq_right he,Sum.elim_inr] using + (segmentRegular_const D.H D.θ x 0).mono h0 + · intro a ha b + by_cases he:a=N+1 + · subst a;simpa only [OrdinaryData.appendFixed,ite_eq_left rfl,ite_true] using (segmentRegular_const D.H D.θ x 0).mono h0 + · simpa only [OrdinaryData.appendFixed,ite_eq_right he] using h.auxRegular a (by omega) b + · intro a ha s + by_cases he:a=N+1 + · subst a;cases s with + | inl s=>intro i k t ht;simpa only [OrdinaryData.appendFixed,ite_eq_left rfl,ite_true,Sum.elim_inl,abs_zero] using h0 + | inr s=>intro i k t ht + simpa only [OrdinaryData.appendFixed,ite_eq_left rfl,ite_true,Sum.elim_inr] using + (show |(1:ℝ)|≤K by simpa using hK) + · cases s with + | inl s=>simpa only [OrdinaryData.appendFixed,ite_eq_right he,Sum.elim_inl] using h.seedValue a (by omega) s + | inr s=>intro i k t ht;simpa only [OrdinaryData.appendFixed,ite_eq_right he,Sum.elim_inr,abs_zero] using h0 + · intro a ha b + by_cases he:a=N+1 + · subst a;intro i k t ht;simpa only [OrdinaryData.appendFixed,ite_eq_left rfl,ite_true,abs_zero] using h0 + · simpa only [OrdinaryData.appendFixed,ite_eq_right he] using h.auxValue a (by omega) b + +end SKGapCutoff.Recipe.OrdinaryData + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/StartedGraph.lean b/lean/OAI/Probability/SKGap/Localization/StartedGraph.lean new file mode 100644 index 0000000000000000000000000000000000000000..8fb20c786a9221a9148df7acd819118d427d83bb --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/StartedGraph.lean @@ -0,0 +1,126 @@ +import Mathlib +import OAI.Probability.SKGap.Stability.OrdinaryRecipe +import OAI.Probability.SKGap.Localization.StartedRecipe +import OAI.Probability.SKGap.Matrix.CorrectionTrace +import OAI.Probability.SKGap.Matrix.ClosedTreeMatrix + +namespace OAI + +section + +noncomputable section +open scoped BigOperators +namespace SKGapCutoff.Recipe.OrdinaryData +open Primary Matrix SKGap.Noncrossing.Primary SKGap.Noncrossing.Primary.Tensor.Series +variable {n : ℕ} {ι κ σ : Type*} [Fintype ι] [DecidableEq ι] [Fintype κ] [DecidableEq κ] [Fintype σ] + +def startedTree (D : OrdinaryData n ι κ σ) (w y : VectorFields n) + (T : ι→SourceTree (Fin n→ℝ)) (t₀ : ClosedTree (Fin n→ℝ)) (x : Spin n) + (a : ℕ) : ClosedTree (Fin n→ℝ) := + match a with + | 0 => t₀ + | a+1 => ClosedTree.branches + ((Finset.univ.toList.map (fun l=>(D.startedPartial w y (a+1) l x,ClosedTree.ofOrdinary (T l))))++ + (Finset.univ.toList.map (fun b : Fin (a+1)=>(D.auxCoefficient (a+1) b x,startedTree D w y T t₀ x b)))) +termination_by a + +lemma startedTree_pos (D : OrdinaryData n ι κ σ) (w y : VectorFields n) + (T : ι→SourceTree (Fin n→ℝ)) (t₀ : ClosedTree (Fin n→ℝ)) (x : Spin n) + {a : ℕ} (ha : 0(D.startedPartial w y a l x,ClosedTree.ofOrdinary (T l))))++ + (Finset.univ.toList.map (fun b : Fin a=>(D.auxCoefficient a b x,D.startedTree w y T t₀ x b)))) := by + obtain ⟨a,rfl⟩:=Nat.exists_eq_succ_of_ne_zero (by omega : a≠0) + rw [startedTree] + +lemma startedTree_leafMass (D : OrdinaryData n ι κ σ) (w y : VectorFields n) + (T : ι→SourceTree (Fin n→ℝ)) (t₀ : ClosedTree (Fin n→ℝ)) (ht : t₀.leafMass=0) + (x : Spin n) (a : ℕ) : (D.startedTree w y T t₀ x a).leafMass=0 := by + cases a with + | zero => simpa only [startedTree] using ht + | succ a => rw [startedTree,ClosedTree.branches_leafMass] + +variable (D : OrdinaryData n ι κ σ) (w y : VectorFields n) + (T : ι→SourceTree (Fin n→ℝ)) (t₀ : ClosedTree (Fin n→ℝ)) (a₀ : Fin n→ℝ) (x : Spin n) +def startedRetainedSource (a : ℕ) := (D.startedTree w y T t₀ x a).sourceMatrix D.j a₀ D.J +def startedRetainedField (a : ℕ) := (D.startedTree w y T t₀ x a).fieldMatrix D.j a₀ D.J + +lemma startedRetainedSource_eq {a : ℕ} (ha : 0(D.startedPartial w y a l x,ClosedTree.ofOrdinary (T l))))++ + (Finset.univ.toList.map (fun b:Fin a=>(D.auxCoefficient a b x,D.startedTree w y T t₀ x b)))) + rw [←D.startedTree_pos w y T t₀ x ha] at h + simpa [List.map_append,List.sum_append,List.map_map,Function.comp_def, + startedRetainedField,startedRetainedSource,siteMean,SKGap.Noncrossing.Diagram.mean, + sub_add_eq_sub_sub,ClosedTree.sourceMatrix_ofOrdinary] using h + +theorem started_prediction_zero (ht : t₀.leafMass=0) (a : ℕ) (z : ℝ) (i : Fin n) : + GradedWords.prediction D.j a₀ z ((D.startedTree w y T t₀ x a).words D.j a₀).1 i=0 ∧ + GradedWords.prediction D.j a₀ z ((D.startedTree w y T t₀ x a).words D.j a₀).2 i=0 := by + exact ⟨ClosedTree.source_prediction_zero D.j a₀ _ (D.startedTree_leafMass w y T t₀ ht x a) z i, + ClosedTree.field_prediction_zero ..⟩ + +end SKGapCutoff.Recipe.OrdinaryData + +end +end + +section + +noncomputable section +open scoped BigOperators +namespace SKGapCutoff.Recipe.OrdinaryData +open Primary Matrix SKGap.Noncrossing.Primary SKGap.Noncrossing.Primary.Tensor.Series +variable {n : ℕ} {ι κ σ : Type*} [Fintype ι] [DecidableEq ι] [Fintype κ] [DecidableEq κ] [Fintype σ] +variable (D : OrdinaryData n ι κ σ) (w y : VectorFields n) + (T : ι→SourceTree (Fin n→ℝ)) (t₀ : ClosedTree (Fin n→ℝ)) (a₀ : Fin n→ℝ) (x : Spin n) + +def startedSourceError (a : ℕ) : Interaction n := + derivativeMatrix (D.startedSource w y a) x-D.startedRetainedSource w y T t₀ a₀ x a +def startedFieldError (a : ℕ) : Interaction n := + derivativeMatrix (D.startedAuxiliary w y a) x-D.startedRetainedField w y T t₀ a₀ x a + +lemma started_source_error_recursion {a : ℕ} (ha : 0D.startedAuxiliary w y b) x := by + rw [startedSourceError,D.started_source_derivative w y ha,D.startedRetainedSource_eq w y T t₀ a₀ x ha] + simp only [startedFieldError,mul_sub,Finset.sum_sub_distrib] + abel + +lemma started_field_error_recursion {a : ℕ} (ha : 0.small t.1 t.2 v) U +def boundedBranches (xs : List ((Fin n→ℝ)×SmallTree n)) (U : SmallTree n) : SmallTree n := + xs.foldr (fun t v=>.bounded t.1 t.2 v) U +lemma tree_smallBranches (xs : List ((Fin n→ℝ)×ClosedTree (Fin n→ℝ))) (U : SmallTree n) : + (smallBranches xs U).tree=xs.foldr (fun t v=>ClosedTree.branch t.1 t.2 v) U.tree := by + induction xs with + | nil => rfl + | cons t xs ih => simpa only [smallBranches,List.foldr_cons,tree] using congrArg (ClosedTree.branch t.1 t.2) ih +lemma tree_boundedBranches (xs : List ((Fin n→ℝ)×SmallTree n)) (U : SmallTree n) : + (boundedBranches xs U).tree=(xs.map (fun t=>(t.1,t.2.tree))).foldr (fun t v=>ClosedTree.branch t.1 t.2 v) U.tree := by + induction xs with + | nil => rfl + | cons t xs ih => + simpa only [boundedBranches,List.foldr_cons,tree,List.map_cons] using congrArg (ClosedTree.branch t.1 t.2.tree) ih +end SKGap.Noncrossing.ClosedMarked.SmallTree + +namespace SKGapCutoff.Recipe.OrdinaryData +open Primary Matrix SKGap SKGap.Noncrossing SKGap.Noncrossing.Primary SKGap.Noncrossing.Primary.Tensor.Series +open SKGap.Noncrossing.ClosedMarked +variable {n : ℕ} {ι κ σ : Type*} [Fintype ι] [DecidableEq ι] [Fintype κ] [DecidableEq κ] [Fintype σ] + +def startedSmallTree (D : OrdinaryData n ι κ σ) (w y : VectorFields n) + (T : ι→SourceTree (Fin n→ℝ)) (t₀ : SmallTree n) (x : Spin n) (a : ℕ) : SmallTree n := + match a with + | 0 => t₀ + | a+1 => SmallTree.smallBranches + (Finset.univ.toList.map (fun l=>(D.startedPartial w y (a+1) l x,ClosedTree.ofOrdinary (T l)))) + (SmallTree.boundedBranches + (Finset.univ.toList.map (fun b : Fin (a+1)=>(D.auxCoefficient (a+1) b x,startedSmallTree D w y T t₀ x b))) .zero) +termination_by a + +lemma startedSmallTree_tree (D : OrdinaryData n ι κ σ) (w y : VectorFields n) + (T : ι→SourceTree (Fin n→ℝ)) (t₀ : SmallTree n) (x : Spin n) (a : ℕ) : + (D.startedSmallTree w y T t₀ x a).tree=D.startedTree w y T t₀.tree x a := by + induction a using Nat.strong_induction_on with + | h a ih => + cases a with + | zero => simp only [startedSmallTree,startedTree] + | succ a => + rw [startedSmallTree,SmallTree.tree_smallBranches,SmallTree.tree_boundedBranches,startedTree] + simp only [ClosedTree.branches,List.foldr_append,List.map_map,Function.comp_def,SmallTree.tree] + congr 2 + apply List.map_congr_left + intro b hb + exact congrArg (fun t=>(D.auxCoefficient (a+1) b x,t)) (ih b b.isLt) + +theorem started_retained_diagonal (D : OrdinaryData n ι κ σ) (w y : VectorFields n) + (T : ι→SourceTree (Fin n→ℝ)) (t₀ : SmallTree n) (a₀ : Fin n→ℝ) (x : Spin n) + (a : ℕ) (hn : 0 + intro ha + by_cases hzero:a=0 + · subst a; simp + have hapos:0E.startedAuxiliary w y b)=D.sourceOf a (fun b=>D.startedAuxiliary w y b) := by + funext x i + unfold sourceOf + simp only [hseed a ha,haux a ha,hs,hy] + have hpart : ∀l,E.partialOf a l (fun b=>E.startedAuxiliary w y b)=D.partialOf a l (fun b=>D.startedAuxiliary w y b) := by + intro l + funext x i + unfold partialOf + simp only [hseedp a ha,hauxp a ha,hs,hy] + constructor + · simpa only [startedSource_eq _ _ _ hapos] using hsrc + · rw [startedAuxiliary_eq _ _ _ hapos,startedAuxiliary_eq _ _ _ hapos] + funext x i + simp only [fieldOf,hJ,hj,hp,hsrc,hpart,hw,haux a ha] + +lemma appendProduct_started_prefix (D : OrdinaryData n ι κ σ) (w y : VectorFields n) (N : ℕ) (F F') : + ∀a≤N,(D.appendProduct N F F').startedSource w y a=D.startedSource w y a ∧ + (D.appendProduct N F F').startedAuxiliary w y a=D.startedAuxiliary w y a := by + apply started_evaluation_prefix_eq + · rfl + · rfl + · rfl + · rfl + all_goals + intro a ha + have hn : a≠N+1 := by omega + · intro s; ext x i; simp [seedCoefficient,coefficient,appendProduct,hn] + · intro b; ext x i; simp [auxCoefficient,coefficient,appendProduct,hn] + · intro l s; ext x i; simp [seedPartial,localPartial,appendProduct,hn] + · intro l b; ext x i; simp [auxPartial,localPartial,appendProduct,hn] + +lemma appendProduct_started_source (D : OrdinaryData n ι κ σ) (w y : VectorFields n) (N : ℕ) (hN : 0coefficient D.H D.θ F x i*D.startedSource w y N x i := by + have hprev:=D.appendProduct_started_prefix w y N F F' + ext x i + rw [startedSource_eq _ _ _ (by omega)] + dsimp only [sourceOf] + rw [Fin.sum_univ_castSucc] + simp only [auxCoefficient,seedCoefficient,coefficient,appendProduct,ite_true,Fin.val_castSucc, + Fin.val_last,Fin.isLt,dite_true,lt_self_iff_false,dite_false,zero_mul,add_zero] + have hy : ∀b:Fin N,(D.appendProduct N F F').startedAuxiliary w y b=D.startedAuxiliary w y b := + fun b=>(hprev b (by omega)).2 + dsimp only [appendProduct] at hy + simp only [hy,Fin.eta] + rw [D.startedSource_eq w y hN] + simp only [sourceOf,seedCoefficient,coefficient,auxCoefficient,mul_add,Finset.mul_sum,mul_assoc] + +lemma appendProduct_started_partial (D : OrdinaryData n ι κ σ) (w y : VectorFields n) (N : ℕ) (hN : 0coefficient D.H D.θ F x i*D.startedPartial w y N l x i+ + localPartial D.H D.θ F' (.inl l) x i*D.startedSource w y N x i := by + have hprev:=D.appendProduct_started_prefix w y N F F' + ext x i + dsimp only [startedPartial,partialOf] + rw [Fin.sum_univ_castSucc] + simp only [auxPartial,seedPartial,localPartial,appendProduct,ite_true,Fin.val_castSucc, + Fin.val_last,Fin.isLt,dite_true,lt_self_iff_false,dite_false] + have hy : ∀b:Fin N,(D.appendProduct N F F').startedAuxiliary w y b=D.startedAuxiliary w y b := + fun b=>(hprev b (by omega)).2 + dsimp only [appendProduct] at hy + simp only [hy,Fin.eta] + rw [D.startedSource_eq w y hN] + simp only [sourceOf,seedCoefficient,coefficient,auxCoefficient,partialAt,add_apply, + smul_apply,smul_eq_mul,add_mul,mul_add,Finset.sum_add_distrib,Finset.mul_sum, + zero_apply,zero_mul,add_zero,mul_assoc] + simp only [mul_assoc,mul_comm,mul_left_comm] + ring + +end SKGapCutoff.Recipe.OrdinaryData + +end +end + +section + +noncomputable section +open scoped BigOperators +namespace SKGapCutoff.Recipe.OrdinaryData +open Primary +variable {n M : ℕ} {κ σ : Type*} [Fintype κ] [DecidableEq κ] [Fintype σ] + +lemma appendAuxiliary_started_prefix (D : OrdinaryData n (Fin M) κ σ) (w y : VectorFields n) (N : ℕ) : + ∀a≤N,(D.appendAuxiliary N).startedSource w y a=D.startedSource w y a ∧ + (D.appendAuxiliary N).startedAuxiliary w y a=D.startedAuxiliary w y a := by + apply started_evaluation_prefix_eq D (D.appendAuxiliary N) w y N rfl rfl rfl rfl + all_goals + intro a ha + have hh : a≠N+1 := by omega + simp [seedCoefficient,auxCoefficient,seedPartial,auxPartial,appendAuxiliary,hh] + +lemma appendAuxiliary_started_source (D : OrdinaryData n (Fin M) κ σ) (w y : VectorFields n) (N : ℕ) : + (D.appendAuxiliary N).startedSource w y (N+1)=D.startedAuxiliary w y N := by + rw [startedSource_eq _ _ _ (by omega)] + ext x i + dsimp only [sourceOf] + rw [Fin.sum_univ_castSucc] + have hy : (D.appendAuxiliary N).startedAuxiliary w y N=D.startedAuxiliary w y N := (D.appendAuxiliary_started_prefix w y N N le_rfl).2 + dsimp only [appendAuxiliary] at hy + simp [seedCoefficient,auxCoefficient,coefficient,appendAuxiliary,hy, + show ∀b:Fin N,b.val≠N from fun b=>Nat.ne_of_lt b.isLt] + +lemma Admissible.startedPartial {D : OrdinaryData n (Fin M) κ σ} {N p : ℕ} + (h : D.Admissible N p) (w y : VectorFields n) (a : ℕ) (ha : a≤N) + (q : Fin M) (hq : q.val(Real.sqrt (n:ℝ))⁻¹) + seedFunction:=fun a s i u=>if a=N+1 then + Sum.elim (fun _=>0) (fun _=>Real.tanh (u (.inl q))) s + else Sum.elim (fun s=>D.seedFunction a s i u) (fun _=>0) s + seedDerivative:=fun a s i u=>if a=N+1 then + Sum.elim (fun _=>0) (fun _=>(1-(Real.tanh (u (.inl q)))^2) • ContinuousLinearMap.proj (.inl q)) s + else Sum.elim (fun s=>D.seedDerivative a s i u) (fun _=>0) s + auxFunction:=fun a b i u=>if a=N+1 then 0 else D.auxFunction a b i u + auxDerivative:=fun a b i u=>if a=N+1 then 0 else D.auxDerivative a b i u + +lemma appendPrimary_sourceOf (D : OrdinaryData n (Fin M) κ σ) (N : ℕ) (q : Fin M) + (a : ℕ) (ha : a≤N) (Y : Fin a→VectorFields n) : + (D.appendPrimary N q).sourceOf a Y=D.sourceOf a Y := by + ext x i + have hh:a≠N+1:=by omega + simp [sourceOf,seedCoefficient,auxCoefficient,coefficient,appendPrimary,hh,Fintype.sum_sum_type] + +lemma appendPrimary_partialOf (D : OrdinaryData n (Fin M) κ σ) (N : ℕ) (q : Fin M) + (a : ℕ) (ha : a≤N) (l : Fin M) (Y : Fin a→VectorFields n) : + (D.appendPrimary N q).partialOf a l Y=D.partialOf a l Y := by + ext x i + have hh:a≠N+1:=by omega + simp [partialOf,seedPartial,auxPartial,localPartial,partialAt,appendPrimary,hh,Fintype.sum_sum_type] + +lemma appendPrimary_fieldOf (D : OrdinaryData n (Fin M) κ σ) (N : ℕ) (q : Fin M) + (a : ℕ) (ha : a≤N) (W Y : Fin a→VectorFields n) : + (D.appendPrimary N q).fieldOf a W Y=D.fieldOf a W Y := by + have hh:a≠N+1:=by omega + ext x i + simp only [fieldOf,D.appendPrimary_sourceOf N q a ha,D.appendPrimary_partialOf N q a ha] + simp only [appendPrimary,auxCoefficient,ite_eq_right hh] + +lemma appendPrimary_started_prefix (D : OrdinaryData n (Fin M) κ σ) (w y : VectorFields n) + (N : ℕ) (q : Fin M) : ∀a≤N, + (D.appendPrimary N q).startedSource w y a=D.startedSource w y a ∧ + (D.appendPrimary N q).startedAuxiliary w y a=D.startedAuxiliary w y a := by + intro a + induction a using Nat.strong_induction_on with + | h a ih=> + intro ha + by_cases hz:a=0 + · subst a;simp + have hp:0(ih b b.isLt (b.isLt.le.trans ha)).1 + have hf:∀b:Fin a,(D.appendPrimary N q).startedAuxiliary w y b=D.startedAuxiliary w y b:= + fun b=>(ih b b.isLt (b.isLt.le.trans ha)).2 + constructor + · rw [startedSource_eq _ _ _ hp,startedSource_eq _ _ _ hp] + simp only [hf,D.appendPrimary_sourceOf N q a ha] + · rw [startedAuxiliary_eq _ _ _ hp,startedAuxiliary_eq _ _ _ hp] + simp only [hs,hf,D.appendPrimary_fieldOf N q a ha] + +lemma appendPrimary_started_source (D : OrdinaryData n (Fin M) κ σ) (w y : VectorFields n) + (N : ℕ) (q : Fin M) : (D.appendPrimary N q).startedSource w y (N+1)= + fun x i=>Real.tanh (D.H q x i)/Real.sqrt (n:ℝ) := by + rw [startedSource_eq _ _ _ (by omega)] + ext x i + simp [sourceOf,seedCoefficient,auxCoefficient,coefficient,appendPrimary, + Fintype.sum_sum_type,localArgs,div_eq_mul_inv] + +lemma appendPrimary_seed (D : OrdinaryData n (Fin M) κ σ) (N : ℕ) (q : Fin M) (hn : 0 ext x i <;> + simp [seedPartial,localPartial,appendPrimary,partialAt,hne.symm] + · intro b;ext x i;simp [auxPartial,localPartial,appendPrimary,partialAt] + · have haN:a≤N:=by omega + constructor + · intro s;cases s with + | inl s=>simpa [seedPartial,localPartial,appendPrimary,he] using (h a haN l hl).1 s + | inr s=>ext x i;simp [seedPartial,localPartial,appendPrimary,he,partialAt] + · intro b;simpa [auxPartial,localPartial,appendPrimary,he] using (h a haN l hl).2 b + +end SKGapCutoff.Recipe.OrdinaryData + +end +end + +section + +noncomputable section +open scoped BigOperators +namespace SKGapCutoff.Recipe.OrdinaryData +variable {n M : ℕ} {κ σ : Type*} [Fintype κ] [DecidableEq κ] [Fintype σ] + +omit [Fintype σ] in +lemma CoefficientClass.appendPrimary {D : OrdinaryData n (Fin M) κ σ} {N : ℕ} {x : Spin n} + {K : ℝ} (h : D.CoefficientClass N x K) (hK : 2≤K) (q : Fin M) : + (D.appendPrimary N q).CoefficientClass (N+1) x K := by + have h0:0≤K:=by linarith [h.one_le] + refine ⟨h.one_le,?_,?_,?_,?_⟩ + · intro a ha s + by_cases he:a=N+1 + · subst a;cases s with + | inl s=>simpa only [OrdinaryData.appendPrimary,ite_eq_left rfl,ite_true,Sum.elim_inl] using + (segmentRegular_const D.H D.θ x 0).mono h0 + | inr s=>simpa only [OrdinaryData.appendPrimary,ite_eq_left rfl,ite_true,Sum.elim_inr] using + (tanh_segmentRegular D.H D.θ x q).mono hK + · cases s with + | inl s=>simpa only [OrdinaryData.appendPrimary,ite_eq_right he,Sum.elim_inl] using h.seedRegular a (by omega) s + | inr s=>simpa only [OrdinaryData.appendPrimary,ite_eq_right he,Sum.elim_inr] using + (segmentRegular_const D.H D.θ x 0).mono h0 + · intro a ha b + by_cases he:a=N+1 + · subst a;simpa only [OrdinaryData.appendPrimary,ite_eq_left rfl,ite_true] using (segmentRegular_const D.H D.θ x 0).mono h0 + · simpa only [OrdinaryData.appendPrimary,ite_eq_right he] using h.auxRegular a (by omega) b + · intro a ha s + by_cases he:a=N+1 + · subst a;cases s with + | inl s=>intro i k t ht;simpa only [OrdinaryData.appendPrimary,ite_eq_left rfl,ite_true,Sum.elim_inl,abs_zero] using h0 + | inr s=>intro i k t ht + simpa only [OrdinaryData.appendPrimary,ite_eq_left rfl,ite_true,Sum.elim_inr] using + ((tanh_segmentValue D.H D.θ x q) i k t ht).trans hK + · cases s with + | inl s=>simpa only [OrdinaryData.appendPrimary,ite_eq_right he,Sum.elim_inl] using h.seedValue a (by omega) s + | inr s=>intro i k t ht;simpa only [OrdinaryData.appendPrimary,ite_eq_right he,Sum.elim_inr,abs_zero] using h0 + · intro a ha b + by_cases he:a=N+1 + · subst a;intro i k t ht;simpa only [OrdinaryData.appendPrimary,ite_eq_left rfl,ite_true,abs_zero] using h0 + · simpa only [OrdinaryData.appendPrimary,ite_eq_right he] using h.auxValue a (by omega) b + +end SKGapCutoff.Recipe.OrdinaryData + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/StartedRecipe.lean b/lean/OAI/Probability/SKGap/Localization/StartedRecipe.lean new file mode 100644 index 0000000000000000000000000000000000000000..f85d150416884b29c74ef623d5055f1fb1b827bf --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/StartedRecipe.lean @@ -0,0 +1,85 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.PrimaryPrediction +import OAI.Probability.SKGap.Stability.OrdinaryRecipe +import OAI.Probability.SKGap.Matrix.CorrectionTrace +import OAI.Probability.SKGap.Localization.RecipeError + +namespace OAI + +section + +noncomputable section +open scoped BigOperators Matrix.Norms.Frobenius +namespace SKGapCutoff.Recipe.OrdinaryData +open Primary Matrix SKGap.Noncrossing.Primary +variable {n : ℕ} {ι κ σ : Type*} [Fintype ι] [DecidableEq ι] [Fintype κ] [DecidableEq κ] [Fintype σ] +variable (D : OrdinaryData n ι κ σ) + +def startedEvaluate (D : OrdinaryData n ι κ σ) (w y : VectorFields n) (a : ℕ) : VectorFields n×VectorFields n := + match a with + | 0 => (w,y) + | a+1 => let prev:=fun b : Fin (a+1)=>startedEvaluate D w y b + (D.sourceOf (a+1) (fun b=>(prev b).2), + D.fieldOf (a+1) (fun b=>(prev b).1) (fun b=>(prev b).2)) +termination_by a + +def startedSource (w y : VectorFields n) (a : ℕ) : VectorFields n := (D.startedEvaluate w y a).1 +def startedAuxiliary (w y : VectorFields n) (a : ℕ) : VectorFields n := (D.startedEvaluate w y a).2 +def startedPartial (w y : VectorFields n) (a : ℕ) (l : ι) : VectorFields n := + D.partialOf a l (fun b=>D.startedAuxiliary w y b) + +@[simp] lemma startedSource_zero (w y : VectorFields n) : D.startedSource w y 0=w := by + rw [startedSource,startedEvaluate] +@[simp] lemma startedAuxiliary_zero (w y : VectorFields n) : D.startedAuxiliary w y 0=y := by + rw [startedAuxiliary,startedEvaluate] +lemma startedSource_eq (w y : VectorFields n) {a : ℕ} (ha : 0D.startedAuxiliary w y b) := by + obtain ⟨a,rfl⟩:=Nat.exists_eq_succ_of_ne_zero (by omega : a≠0) + rw [startedSource,startedEvaluate];rfl +lemma startedAuxiliary_eq (w y : VectorFields n) {a : ℕ} (ha : 0D.startedSource w y b) (fun b=>D.startedAuxiliary w y b) := by + obtain ⟨a,rfl⟩:=Nat.exists_eq_succ_of_ne_zero (by omega : a≠0) + rw [startedAuxiliary,startedEvaluate];rfl + +lemma startedSource_one (w y : VectorFields n) : + D.startedSource w y 1=D.sourceOf 1 (fun _=>y) := by + rw [D.startedSource_eq w y (by omega)] + congr 1;funext index + simp +lemma startedAuxiliary_one (w y : VectorFields n) : + D.startedAuxiliary w y 1=D.fieldOf 1 (fun _=>w) (fun _=>y) := by + rw [D.startedAuxiliary_eq w y (by omega)] + congr 1 <;> funext index + all_goals simp + +lemma started_duplicate (w y : VectorFields n) + (hw : w=D.sourceOf 1 (fun _=>y)) + (hy : y=D.fieldOf 1 (fun _=>w) (fun _=>y)) : + D.startedSource w y 1=w ∧ D.startedAuxiliary w y 1=y := by + exact ⟨(D.startedSource_one w y).trans hw.symm,(D.startedAuxiliary_one w y).trans hy.symm⟩ + +lemma started_source_derivative (w y : VectorFields n) {a : ℕ} (ha : 0D.startedAuxiliary w y b) x := by + rw [D.startedSource_eq w y ha,D.sourceOf_derivative] + dsimp only [startedPartial] + abel + +lemma started_field_derivative (w y : VectorFields n) {a : ℕ} (ha : 0localPartial D.H D.θ F' (.inl l) x i*D.startedSource w y N x i := by + rw [appendProduct_started_partial _ _ _ _ hN,hzero] + ext x i; simp + +lemma appendStein_started_source (D : OrdinaryData n ι κ σ) (w y : VectorFields n) (N : ℕ) (hN : 0j*(onsager j J h (k+1) x-onsager j J h k x)) : + (D.appendStein N l m α).startedSource w y (N+1)=steinSource j J h k (D.startedSource w y N) := by + rw [appendStein,appendProduct_started_source _ w y N hN] + ext x i + simp [coefficient,phiCoefficient_eq,localArgs,hl,hm,ha,steinSource] + +lemma appendStein_started_partial (D : OrdinaryData n ι κ σ) (w y : VectorFields n) (N : ℕ) (hN : 0j*(onsager j J h (k+1) x-onsager j J h k x)) + (hzero : D.startedPartial w y N l=0) : + (D.appendStein N l m α).startedPartial w y (N+1) l=steinPartial j J h k (D.startedSource w y N) := by + rw [appendStein,appendProduct_started_new_partial _ w y N hN _ _ _ hzero] + ext x i + simp [localPartial,phiDerivative_first l m α hlm,localArgs,hl,hm,ha,steinPartial] + +lemma appendStein_started_preserves_vanishing (D : OrdinaryData n ι κ σ) (w y : VectorFields n) (N : ℕ) (hN : 0j*(onsager j J h (k+1) x-onsager j J h k x)) + (hzero : D.startedPartial w y N l=0) : + let E:=D.appendStein N l m α + E.startedAuxiliary w y (N+1)=nextField j J h k (D.startedSource w y N) + (fun q:{q:ι//q≠l}=>L q) (fun q=>siteMean (E.startedPartial w y (N+1) q)) + (fun b:Fin (N+1)=>E.startedSource w y b) (fun b=>siteMean (E.auxCoefficient (N+1) b)) := by + dsimp only + funext x i + rw [started_auxiliary_split _ w y _ (by omega) l,appendStein_started_source D w y N hN l m α j J h k hl hm ha, + appendStein_started_partial D w y N hN l m α hlm j J h k hl hm ha hzero] + simp only [appendStein,appendProduct,hJ,hj,hp,hL,nextField] + +theorem started_residual_step (D : OrdinaryData n ι κ σ) (w y : VectorFields n) (N : ℕ) (hN : 0j*(onsager j J h (k+1) x-onsager j J h k x)) + (hzero : D.startedPartial w y N l=0) (x : Spin n) : + let E:=D.appendStein N l m α + (∑i,residual j J h (k+1) x i*D.startedSource w y N x i)= + (∑i,residual j J h k x i*E.startedAuxiliary w y (N+1) x i)+ + j*(onsager j J h (k+1) x-onsager j J h k x)*(∑i,residual j J h k x i*E.startedSource w y (N+1) x i)- + j*onsager j J h k x*(∑i,previousResidual j J h k x i*E.startedSource w y (N+1) x i)+ + j*(∑b:Fin (N+1),siteMean (E.auxCoefficient (N+1) b) x*∑i,residual j J h k x i*E.startedSource w y b x i)+ + j*(∑q:{q:ι//q≠l},siteMean (E.startedPartial w y (N+1) q) x*∑i,residual j J h k x i*mag j J h (L q) x i)- + j*siteMean (E.startedPartial w y (N+1) l) x*(∑i,residual j J h k x i*mag j J h (k+1) x i) := by + dsimp only + rw [appendStein_started_auxiliary D w y N hN l m α hlm j J h k L hj hJ hp hL hl hm ha hzero, + appendStein_started_source D w y N hN l m α j J h k hl hm ha, + appendStein_started_partial D w y N hN l m α hlm j J h k hl hm ha hzero] + exact residual_induction_identity hn j J hJs h k (D.startedSource w y N) + (fun q:{q:ι//q≠l}=>L q) + (fun q=>siteMean ((D.appendStein N l m α).startedPartial w y (N+1) q)) + (fun b:Fin (N+1)=>(D.appendStein N l m α).startedSource w y b) + (fun b=>siteMean ((D.appendStein N l m α).auxCoefficient (N+1) b)) x + +end SKGapCutoff.Recipe.OrdinaryData + +end +end + +section + +noncomputable section +open scoped BigOperators +namespace SKGapCutoff.Static +variable {n : ℕ} + +lemma halfDiff_zero_off_neighborhood (E : Set (Spin n)) (G : Observables n) + (hG : ∀x,x∉E→G x=0) (x : Spin n) (i : Fin n) (hx : x∉E) (hi : flip x i∉E) : + halfDiff i G x=0 := by + simp [halfDiff_as_flip,hG x hx,hG (flip x i) hi] + +lemma local_multiplier_energy (P : Spin n→ℝ) (hP : ∀x,0≤P x) + (E : Set (Spin n)) (θ G : Observables n) {B L : ℝ} + (hG : ∀x,x∉E→G x=0) (hθ : ∀x∈flipNeighborhood E,|θ x|≤B) + (hd : ∀x∈E,∑i,(halfDiff i θ x)^2≤L^2) : + varianceEnergy P (fun x=>θ x*G x)≤ + 2*B^2*varianceEnergy P G+2*L^2*(∑x,P x*(G x)^2) := by + have ht (x : Spin n) (i : Fin n) : + (θ (flip x i))^2*(halfDiff i G x)^2≤B^2*(halfDiff i G x)^2 := by + by_cases hx:x∈E + · have hf : flip x i∈flipNeighborhood E:=Or.inr ⟨i,by simpa⟩ + exact mul_le_mul_of_nonneg_right (by + simpa only [sq_abs] using pow_le_pow_left₀ (abs_nonneg _) (hθ _ hf) 2) (sq_nonneg _) + · by_cases hi:flip x i∈E + · exact mul_le_mul_of_nonneg_right (by + simpa only [sq_abs] using pow_le_pow_left₀ (abs_nonneg _) (hθ _ (Or.inl hi)) 2) (sq_nonneg _) + · simp [halfDiff_zero_off_neighborhood E G hG x i hx hi] + calc + _ ≤ ∑x,P x*∑i,conditionalVariance P x i* + (2*B^2*(halfDiff i G x)^2+2*(G x)^2*(halfDiff i θ x)^2) := by + apply Finset.sum_le_sum; intro x _ + apply mul_le_mul_of_nonneg_left _ (hP x) + apply Finset.sum_le_sum; intro i _ + apply mul_le_mul_of_nonneg_left _ (conditionalVariance_nonneg P hP x i) + rw [halfDiff_mul_flipped] + nlinarith only [ht x i,sq_nonneg (θ (flip x i)*halfDiff i G x-G x*halfDiff i θ x)] + _ ≤ ∑x,P x*(2*B^2*(∑i,conditionalVariance P x i*(halfDiff i G x)^2)+2*(G x)^2*L^2) := by + apply Finset.sum_le_sum; intro x _ + apply mul_le_mul_of_nonneg_left _ (hP x) + simp only [mul_add,Finset.sum_add_distrib] + have h1 : (∑i,conditionalVariance P x i*(2*B^2*(halfDiff i G x)^2))= + 2*B^2*(∑i,conditionalVariance P x i*(halfDiff i G x)^2) := by + simp only [Finset.mul_sum]; apply Finset.sum_congr rfl; intro i _; ring + rw [h1] + apply add_le_add_right + calc + _ ≤ ∑i,2*(G x)^2*(halfDiff i θ x)^2 := by + apply Finset.sum_le_sum; intro i _ + exact mul_le_of_le_one_left (by positivity) (conditionalVariance_le_one P x i) + _ = 2*(G x)^2*(∑i,(halfDiff i θ x)^2) := by rw [Finset.mul_sum] + _ ≤ _ := by + by_cases hx:x∈E + · exact mul_le_mul_of_nonneg_left (hd x hx) (by positivity) + · simp [hG x hx] + _ = _ := by + simp only [mul_add,Finset.sum_add_distrib,varianceEnergy,Finset.mul_sum] + congr 1 <;> apply Finset.sum_congr rfl <;> intro x _ <;> ring_nf + +lemma local_multiplier_starSquared (P : Spin n→ℝ) (hP : ∀x,0≤P x) + (E : Set (Spin n)) (θ G : Observables n) {B L : ℝ} + (hG : ∀x,x∉E→G x=0) (hθ : ∀x∈flipNeighborhood E,|θ x|≤B) + (hd : ∀x∈E,∑i,(halfDiff i θ x)^2≤L^2) : + starSquared P (fun x=>θ x*G x)≤(3*B^2+2*L^2)*starSquared P G := by + have hs : (∑x,P x*(θ x*G x)^2)≤B^2*(∑x,P x*(G x)^2) := by + rw [Finset.mul_sum] + apply Finset.sum_le_sum; intro x _ + by_cases hx:x∈E + · have ht : (θ x)^2≤B^2 := by + simpa only [sq_abs] using pow_le_pow_left₀ (abs_nonneg _) (hθ x (Or.inl hx)) 2 + have hm := mul_le_mul_of_nonneg_left + (mul_le_mul_of_nonneg_right ht (sq_nonneg (G x))) (hP x) + nlinarith only [hm] + · simp [hG x hx] + have he:=local_multiplier_energy P hP E θ G hG hθ hd + have hn:=varianceEnergy_nonneg P hP G + have hn' : 0≤∑x,P x*(G x)^2 := Finset.sum_nonneg fun x _=>mul_nonneg (hP x) (sq_nonneg _) + dsimp only [starSquared] + nlinarith [mul_nonneg (sq_nonneg B) hn,mul_nonneg (sq_nonneg L) hn, + mul_nonneg (sq_nonneg B) hn'] + +lemma local_star_multiplier (P : Spin n→ℝ) (hP : ∀x,0≤P x) + (E : Set (Spin n)) (θ G : Observables n) {B L : ℝ} + (hG : ∀x,x∉E→G x=0) (hθ : ∀x∈flipNeighborhood E,|θ x|≤B) + (hd : ∀x∈E,∑i,(halfDiff i θ x)^2≤L^2) : + starNorm P (fun x=>θ x*G x)≤Real.sqrt (3*B^2+2*L^2)*starNorm P G := by + exact (Real.sqrt_le_sqrt (local_multiplier_starSquared P hP E θ G hG hθ hd)).trans_eq + (Real.sqrt_mul (by positivity) _) + +end SKGapCutoff.Static + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/StartedSmall.lean b/lean/OAI/Probability/SKGap/Localization/StartedSmall.lean new file mode 100644 index 0000000000000000000000000000000000000000..e9243e298dbf4abaa593df659bb1a994223ebdad --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/StartedSmall.lean @@ -0,0 +1,173 @@ +import Mathlib +import OAI.Probability.SKGap.Stability.OrdinaryClosure +import OAI.Probability.SKGap.Matrix.StartedNodeTrace + +namespace OAI + +section + +noncomputable section +open scoped BigOperators Matrix.Norms.Frobenius +namespace SKGapCutoff.Recipe +variable {n : ℕ} + +def startedBudget (c S B : ℝ) (a : ℕ) : ℝ := + c*(S+∑b:Fin a,startedBudget c S B b)+B +termination_by a +lemma startedBudget_nonneg {c S B : ℝ} (hc : 0≤c) (hS : 0≤S) (hB : 0≤B) (a : ℕ) : + 0≤ startedBudget c S B a := by + induction a using Nat.strong_induction_on with + | h a ih => + rw [startedBudget] + exact add_nonneg (mul_nonneg hc (add_nonneg hS (Finset.sum_nonneg fun b _=>ih b b.isLt))) hB +lemma startedBudget_ge {c S B : ℝ} (hc : 0≤c) (hS : 0≤S) (hB : 0≤B) (a : ℕ) : + B≤ startedBudget c S B a := by + rw [startedBudget] + exact le_add_of_nonneg_left (mul_nonneg hc (add_nonneg hS + (Finset.sum_nonneg fun b _=>startedBudget_nonneg hc hS hB b))) + +namespace OrdinaryData +open Primary Matrix +variable {ι κ σ : Type*} [Fintype ι] [DecidableEq ι] [Fintype κ] [DecidableEq κ] [Fintype σ] +variable (D : OrdinaryData n ι κ σ) + +theorem started_evaluation_small (w y : VectorFields n) (N : ℕ) (x : Spin n) (hn : 0 + intro haN + let V : Fin a→ℝ:=fun b=>startedBudget c S B b + let I:=S+∑b,V b + let Z:=I*(A+3*R) + have hV : ∀b,0≤V b:=fun b=>startedBudget_nonneg hc hS hB b + have hI : 0≤I:=add_nonneg hS (Finset.sum_nonneg fun b _=>hV b) + have hY : ∀b:Fin a,SmallBound (D.startedAuxiliary w y b) x (V b):= + fun b=>(ih b b.isLt (b.isLt.le.trans haN)).2.1 + have hW : ∀b:Fin a,SmallBound (D.startedSource w y b) x (V b):= + fun b=>(ih b b.isLt (b.isLt.le.trans haN)).1 + have hw : SmallBound (D.sourceOf a (fun b=>D.startedAuxiliary w y b)) x Z:= + (D.sourceOf_bound a _ x V hY (hs a haN) (ha a haN)).mono + (mul_le_mul_of_nonneg_right (show (∑s,vectorNorm (D.seed s))+(∑b,V b)≤I from + add_le_add hseed le_rfl) hT) + have hp : ∀l,SmallBound (D.partialOf a l (fun b=>D.startedAuxiliary w y b)) x Z:=fun l=> + (D.partialOf_bound a l _ x V hY (hsp a haN l) (hap a haN l)).mono + (mul_le_mul_of_nonneg_right (show (∑s,vectorNorm (D.seed s))+(∑b,V b)≤I from + add_le_add hseed le_rfl) hT) + have hZ : Z≤ startedBudget c S B a:=by + rw [startedBudget] + exact (mul_le_mul_of_nonneg_left hcg hI).trans (by dsimp [I,V];nlinarith only [hB]) + have hf:=D.fieldOf_bound a (fun b=>D.startedSource w y b) (fun b=>D.startedAuxiliary w y b) + x hn V hL hP hJ hw hp hW hm hdm (ha a haN) + have hfC : (L*Z+|D.j| *((Fintype.card ι:ℝ)*(Z*(1+3*P))))+ + |D.j| *((∑b,V b)*(A+3*R))≤ startedBudget c S B a:=by + rw [startedBudget] + change _≤c*I+B + dsimp [c,recipeCost,Z,I] + have h1 : 0≤(S+∑b,V b)*(A+3*R):=mul_nonneg hI hT + have h2 : 0≤|D.j| *(S*(A+3*R)):=mul_nonneg (abs_nonneg _) (mul_nonneg hS hT) + nlinarith only [h1,h2,hB] + refine ⟨?_,?_,fun l=>(hp l).mono hZ⟩ + · by_cases ha0:a=0 + · subst a;simpa using hw₀.mono (startedBudget_ge hc hS hB 0) + · rw [D.startedSource_eq w y (by omega)];exact hw.mono hZ + · by_cases ha0:a=0 + · subst a;simpa using hy₀.mono (startedBudget_ge hc hS hB 0) + · rw [D.startedAuxiliary_eq w y (by omega)];exact hf.mono hfC + +end OrdinaryData +end SKGapCutoff.Recipe + +end +end + +section + +noncomputable section +open scoped BigOperators Matrix.Norms.Frobenius +namespace SKGapCutoff.Recipe +open Primary Matrix SKGap.Noncrossing SKGap.Noncrossing.Primary MarkedPolynomial + +namespace LocalConstants +variable (c : LocalConstants) +def startedNormBudget (j : ℝ) (d : ℕ) (B : ℝ) : ℕ→ℝ := startedBudget (recipeCost c.A (c.row d) c.L c.P j d) c.S B +def startedSourceCost (j : ℝ) (d s : ℕ) (B : ℝ) (a : ℕ) : ℝ := + (s:ℝ)*(c.C*c.S*c.traceCost d)+(∑b:Fin a,c.C*c.startedNormBudget j d B b*c.traceCost d)+ + (d:ℝ)*(c.startedNormBudget j d B a*c.E) +def startedFieldCost (j : ℝ) (d : ℕ) (B : ℝ) (a : ℕ) : ℝ := + (d:ℝ)*(|j| *(c.startedNormBudget j d B a*c.E))+ + |j| *((d:ℝ)*(c.startedNormBudget j d B a*(1+2*c.P))+(∑b:Fin a,3*c.startedNormBudget j d B b*c.row d)) +lemma startedNormBudget_nonneg (j : ℝ) (d a : ℕ) {B : ℝ} (hB : 0≤B) : 0≤c.startedNormBudget j d B a := + startedBudget_nonneg (recipeCost_nonneg c.A_nonneg (c.row_nonneg d) c.L_nonneg c.P_nonneg) c.S_nonneg hB a +end LocalConstants + +variable {n : ℕ} {ι κ σ : Type*} [Fintype ι] [DecidableEq ι] [Fintype κ] [DecidableEq κ] [Fintype σ] +namespace LocalOrdinaryInput +variable {D : OrdinaryData n ι κ σ} {T : ι→SourceTree (Fin n→ℝ)} +variable {x : Spin n} {N : ℕ} {c : LocalConstants} {w y : VectorFields n} {B : ℝ} +variable (h : LocalOrdinaryInput D T x N c) (hB : 0≤B) (hw₀ : SmallBound w x B) (hy₀ : SmallBound y x B) +include h hB hw₀ hy₀ + +lemma started_small (a : ℕ) (ha : a≤N) : + SmallBound (D.startedSource w y a) x (c.startedNormBudget D.j (Fintype.card ι) B a) ∧ + SmallBound (D.startedAuxiliary w y a) x (c.startedNormBudget D.j (Fintype.card ι) B a) ∧ + ∀l,SmallBound (D.startedPartial w y a l) x (c.startedNormBudget D.j (Fintype.card ι) B a) := + D.started_evaluation_small w y N x h.dimension c.A_nonneg (c.row_nonneg _) c.L_nonneg c.P_nonneg c.S_nonneg hB hw₀ hy₀ + h.interaction h.seed h.primaryValue h.primaryDerivative h.seed_bound h.aux_bound h.seed_partial_bound h.aux_partial_bound a ha + +lemma started_source_control (a : ℕ) (ha : a≤N) : + TraceControl (D.startedNodeSourceError w y T x a) (c.startedSourceCost D.j (Fintype.card ι) (Fintype.card σ) B a) := by + let d:=Fintype.card ι + let W:=c.startedNormBudget D.j d B + have hn (s : σ) : vectorNorm (D.seed s)≤c.S := + (Finset.single_le_sum (fun s _=>vectorNorm_nonneg (D.seed s)) (Finset.mem_univ s)).trans h.seed + have H:=D.startedNodeSource_control w y T x a c.C_nonneg + (show 0≤2*(d:ℝ)*c.P by positivity [c.P_nonneg]) + (show 0≤(d:ℝ)*c.P by positivity [c.P_nonneg]) + (show 0≤(d:ℝ)*c.P by positivity [c.P_nonneg]) c.V_nonneg + (fun b:Fin a=>(h.started_small hB hw₀ hy₀ b (b.isLt.le.trans ha)).2.1) (h.started_small hB hw₀ hy₀ a ha).2.2 h.primaryFieldError + (h.seedRegular a ha) (h.auxRegular a ha) + ((parameterIncrement_bound D.θ x).trans h.parameter) + (primaryIncrement_fourth D.H x c.P_nonneg h.primaryShape) + (primaryIncrement_row D.H x c.P_nonneg (fun l=>(h.primaryShape l).1)) + (primaryIncrement_diagonal D.H x c.P_nonneg (fun l=>(h.primaryShape l).2.1)) + (show _≤c.traceCost d from add_le_add (add_le_add h.parameter le_rfl) le_rfl) + apply H.mono + have hs : (∑s,c.C*vectorNorm (D.seed s)*c.traceCost d)≤(Fintype.card σ:ℝ)*(c.C*c.S*c.traceCost d) := + (Finset.sum_le_sum fun s _=>mul_le_mul_of_nonneg_right + (mul_le_mul_of_nonneg_left (hn s) c.C_nonneg) (c.traceCost_nonneg d)).trans_eq (by simp) + dsimp only [LocalConstants.startedSourceCost] + have hp : (∑_l:ι,c.startedNormBudget D.j d B a*c.E)=(d:ℝ)*(c.startedNormBudget D.j d B a*c.E) := by simp [d] + rw [hp] + exact add_le_add (add_le_add hs le_rfl) le_rfl + +lemma started_field_control (a : ℕ) (ha : a≤N) : + TraceControl (D.startedNodeFieldError w y T x a) (c.startedFieldCost D.j (Fintype.card ι) B a) := by + have H:=D.startedNodeField_control w y T x a h.dimension c.P_nonneg (c.row_nonneg _) + (fun b:Fin a=>(h.started_small hB hw₀ hy₀ b (b.isLt.le.trans ha)).1) (h.started_small hB hw₀ hy₀ a ha).2.2 h.primarySourceError + h.primaryValue h.primaryDerivative (fun b=>(h.aux_bound a ha b).difference) + simpa only [LocalConstants.startedFieldCost,Finset.sum_const,Finset.card_univ,nsmul_eq_mul] using H + +end LocalOrdinaryInput +end SKGapCutoff.Recipe + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/StationaryInner.lean b/lean/OAI/Probability/SKGap/Localization/StationaryInner.lean new file mode 100644 index 0000000000000000000000000000000000000000..f907737cc135821a6e55e086f563dca818a076a2 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/StationaryInner.lean @@ -0,0 +1,160 @@ +import Mathlib +import OAI.Probability.SKGap.Terminal.GibbsExpectation + +namespace OAI + +section +open scoped BigOperators +namespace SKGapCutoff +noncomputable def stationaryInner {n : ℕ} (J : Interaction n) (f g : Observables n) : ℝ := + gibbsExpectation J (fun x => f x * g x) +noncomputable def weightedInner {n : ℕ} (J : Interaction n) (p q : VectorFields n) : ℝ := + gibbsExpectation J (fun x => ∑ i, siteVariance J x i * p x i * q x i) +noncomputable def equilibriumPotential {n : ℕ} (J : Interaction n) (δ : ℝ) + (B : VectorFields n) (x : Spin n) : ℝ := + δ⁻¹ * ((∑ i, spin x i * semigroup J δ (fun y => B y i) x) - + semigroup J δ (fun y => ∑ i, semigroup J δ (fun z => spin z i) y * B y i) x) + +noncomputable def expectationLM {n : ℕ} (J : Interaction n) : Observables n →ₗ[ℝ] ℝ where + toFun := gibbsExpectation J + map_add' f g := by simp [gibbsExpectation, mul_add, Finset.sum_add_distrib] + map_smul' c f := by simp [gibbsExpectation, mul_left_comm, ← Finset.mul_sum] + +noncomputable def expectationCLM {n : ℕ} (J : Interaction n) : Observables n →L[ℝ] ℝ := + (expectationLM J).toContinuousLinearMap + +lemma gibbsExpectation_const {n : ℕ} (J : Interaction n) (c : ℝ) : + gibbsExpectation J (fun _ => c) = c := by + simp only [gibbsExpectation, ← Finset.sum_mul, gibbs_sum, one_mul] + +lemma gibbsExpectation_sum {n : ℕ} {α : Type*} [Fintype α] (J : Interaction n) + (f : α → Observables n) : + gibbsExpectation J (fun x => ∑ a, f a x) = ∑ a, gibbsExpectation J (f a) := by + simp only [gibbsExpectation, Finset.mul_sum] + exact Finset.sum_comm + +lemma gibbsExpectation_sub {n : ℕ} (J : Interaction n) (f g : Observables n) : + gibbsExpectation J (fun x => f x - g x) = gibbsExpectation J f - gibbsExpectation J g := by + simp only [gibbsExpectation, mul_sub, Finset.sum_sub_distrib] + +lemma gibbsExpectation_mul_const {n : ℕ} (J : Interaction n) (c : ℝ) (f : Observables n) : + gibbsExpectation J (fun x => c * f x) = c * gibbsExpectation J f := by + simp only [gibbsExpectation, mul_left_comm (gibbs J _) c, ← Finset.mul_sum] + +noncomputable def stationaryPairingCLM {n : ℕ} (J : Interaction n) (f : Observables n) : + Observables n →L[ℝ] ℝ := + (show Observables n →ₗ[ℝ] ℝ from + { toFun := stationaryInner J f + map_add' g h := by simp [stationaryInner, gibbsExpectation, mul_add, Finset.sum_add_distrib] + map_smul' c g := by simp [stationaryInner, gibbsExpectation, mul_left_comm, ← Finset.mul_sum] + }).toContinuousLinearMap + +@[simp] lemma expectationCLM_apply {n : ℕ} (J : Interaction n) (f : Observables n) : + expectationCLM J f = gibbsExpectation J f := rfl + +@[simp] lemma stationaryPairingCLM_apply {n : ℕ} (J : Interaction n) (f g : Observables n) : + stationaryPairingCLM J f g = stationaryInner J f g := rfl + +lemma stationaryInner_symm {n : ℕ} (J : Interaction n) (f g : Observables n) : + stationaryInner J f g = stationaryInner J g f := by + simp only [stationaryInner, mul_comm (f _) (g _)] + +lemma dirichlet_symm {n : ℕ} (J : Interaction n) (f g : Observables n) : + dirichlet J f g = dirichlet J g f := by + unfold dirichlet + congr 1 + funext x + apply Finset.sum_congr rfl + intro i _ + ring + +lemma scalar_generator_symmetric {n : ℕ} (J : Interaction n) + (hJ : ∀ i j, J i j = J j i) (hdiag : ∀ i, J i i = 0) + (f g : Observables n) : + stationaryInner J f (generator J g) = stationaryInner J (generator J f) g := by + have hf := gibbs_dirichlet J hJ hdiag f g + have hg := gibbs_dirichlet J hJ hdiag g f + rw [dirichlet_symm J g f, ← hf] at hg + simp only [gibbsExpectation, mul_neg, Finset.sum_neg_distrib] at hg + unfold stationaryInner gibbsExpectation + simpa only [mul_comm (g _) (generator J f _)] using (neg_inj.mp hg).symm + +lemma stationaryInner_pow_symm {n : ℕ} (J : Interaction n) + (A : Observables n →L[ℝ] Observables n) + (hA : ∀ f g, stationaryInner J f (A g) = stationaryInner J (A f) g) + (k : ℕ) (f g : Observables n) : + stationaryInner J f ((A ^ k) g) = stationaryInner J ((A ^ k) f) g := by + induction k generalizing f g with + | zero => simp + | succ k ih => + calc + _ = stationaryInner J (A f) ((A ^ k) g) := by + rw [pow_succ', mul_apply_eq_comp, hA] + _ = stationaryInner J ((A ^ k) (A f)) g := ih (A f) g + _ = _ := by rw [pow_succ, mul_apply_eq_comp] + +lemma stationaryInner_exp_symm {n : ℕ} (J : Interaction n) + (A : Observables n →L[ℝ] Observables n) + (hA : ∀ f g, stationaryInner J f (A g) = stationaryInner J (A f) g) + (f g : Observables n) : + stationaryInner J f (NormedSpace.exp A g) = stationaryInner J (NormedSpace.exp A f) g := by + have hf : HasSum (fun k : ℕ => ((k.factorial : ℝ)⁻¹) * stationaryInner J f ((A ^ k) g)) + (stationaryInner J f (NormedSpace.exp A g)) := by + simpa only [map_smul, smul_eq_mul, stationaryPairingCLM_apply] using (stationaryPairingCLM J f).hasSum (exp_apply_hasSum A g) + have hg : HasSum (fun k : ℕ => ((k.factorial : ℝ)⁻¹) * stationaryInner J g ((A ^ k) f)) + (stationaryInner J g (NormedSpace.exp A f)) := by + simpa only [map_smul, smul_eq_mul, stationaryPairingCLM_apply] using (stationaryPairingCLM J g).hasSum (exp_apply_hasSum A f) + have hp (k : ℕ) : stationaryInner J f ((A ^ k) g) = stationaryInner J g ((A ^ k) f) := by + rw [stationaryInner_pow_symm J A hA, stationaryInner_symm] + simp_rw [hp] at hf + rw [← stationaryInner_symm J g] + exact hf.unique hg + +theorem scalar_semigroup_symmetric {n : ℕ} (J : Interaction n) + (hJ : ∀ i j, J i j = J j i) (hdiag : ∀ i, J i i = 0) + (t : ℝ) (f g : Observables n) : + stationaryInner J f (semigroup J t g) = stationaryInner J (semigroup J t f) g := by + apply stationaryInner_exp_symm + intro a b + change gibbsExpectation J (fun x => a x * (t * generator J b x)) = + gibbsExpectation J (fun x => (t * generator J a x) * b x) + simp only [mul_assoc, mul_left_comm (a _) t, gibbsExpectation_mul_const] + exact congrArg (fun r : ℝ => t * r) (scalar_generator_symmetric J hJ hdiag a b) + +lemma gibbsExpectation_semigroup {n : ℕ} (J : Interaction n) + (hJ : ∀ i j, J i j = J j i) (hdiag : ∀ i, J i i = 0) + (t : ℝ) (f : Observables n) : gibbsExpectation J (semigroup J t f) = gibbsExpectation J f := by + have h (g : Observables n) : expectationCLM J ((t • generatorCLM J) g) = + (0 : ℝ →L[ℝ] ℝ) (expectationCLM J g) := by + rw [smul_apply, map_smul] + change t * gibbsExpectation J (generator J g) = 0 + rw [gibbs_generator_zero J hJ hdiag, mul_zero] + simpa only [NormedSpace.exp_zero, one_apply_eq_self, expectationCLM_apply, semigroup] using + exp_intertwine (t • generatorCLM J) (0 : ℝ →L[ℝ] ℝ) (expectationCLM J) h f + +theorem equilibriumPotential_centered {n : ℕ} (J : Interaction n) + (hJ : ∀ i j, J i j = J j i) (hdiag : ∀ i, J i i = 0) + (δ : ℝ) (B : VectorFields n) : gibbsExpectation J (equilibriumPotential J δ B) = 0 := by + unfold equilibriumPotential + rw [gibbsExpectation_mul_const, gibbsExpectation_sub, + gibbsExpectation_semigroup J hJ hdiag, gibbsExpectation_sum, gibbsExpectation_sum] + have he (i : Fin n) := scalar_semigroup_symmetric J hJ hdiag δ + (fun x => spin x i) (fun x => B x i) + simp only [stationaryInner] at he + simp_rw [he] + simp + +lemma exact_gradient_semigroup_identity {n : ℕ} (J : Interaction n) + (hJ : ∀ i j, J i j = J j i) (hdiag : ∀ i, J i i = 0) + (t : ℝ) (f g : Observables n) : + weightedInner J (fun x i => halfDiff i f x) + (gradientSemigroup J t (fun x i => halfDiff i g x)) = + stationaryInner J f (fun x => -generator J (semigroup J t g) x) := by + simp_rw [weightedInner, ← halfDiff_semigroup] + exact (gibbs_dirichlet J hJ hdiag f (semigroup J t g)).symm + +end SKGapCutoff + +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/StepMass.lean b/lean/OAI/Probability/SKGap/Localization/StepMass.lean new file mode 100644 index 0000000000000000000000000000000000000000..34fa355d84b2822d37fdb4c12b0f92340a4ab0b1 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/StepMass.lean @@ -0,0 +1,291 @@ +import Mathlib +import OAI.Probability.SKGap.Model + +namespace OAI + +section +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open scoped BigOperators +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open scoped BigOperators +open scoped BigOperators NNReal ENNReal +open MeasureTheory Metric Set +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators NNReal ENNReal Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Set +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators ENNReal NNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Matrix +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators ENNReal NNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal +open scoped BigOperators +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise NNReal ENNReal +open scoped BigOperators +open Filter Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal Topology +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Set Matrix +open scoped BigOperators NNReal ENNReal Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open Filter MeasureTheory ProbabilityTheory +open scoped Topology NNReal ENNReal +open Filter MeasureTheory ProbabilityTheory +open scoped Topology NNReal ENNReal +namespace SKGapCutoff.Clock + +theorem scheffe_density {α : Type*} [MeasurableSpace α] {μ : Measure α} + {f : ℕ → α → ℝ} {g : α → ℝ} + (hf : ∀ n, Integrable (f n) μ) (hg : Integrable g μ) + (hf0 : ∀ n, ∀ᵐ x ∂μ, 0 ≤ f n x) (hg0 : ∀ᵐ x ∂μ, 0 ≤ g x) + (hlim : ∀ᵐ x ∂μ, Tendsto (fun n => f n x) atTop (𝓝 (g x))) + (hmass : Tendsto (fun n => ∫ x, f n x ∂μ) atTop (𝓝 (∫ x, g x ∂μ))) : + Tendsto (fun n => ∫ x, |f n x-g x| ∂μ) atTop (𝓝 0) := by + have hmin : Tendsto (fun n => ∫ x, min (f n x) (g x) ∂μ) + atTop (𝓝 (∫ x, g x ∂μ)) := by + apply tendsto_integral_of_dominated_convergence g + · intro n + exact (hf n).aestronglyMeasurable.inf hg.aestronglyMeasurable + · exact hg + · intro n + filter_upwards [hf0 n,hg0] with x hx hy + rw [Real.norm_eq_abs, abs_of_nonneg (le_min hx hy)] + exact min_le_right _ _ + · filter_upwards [hlim] with x hx + simpa using hx.min (tendsto_const_nhds (x := g x)) + have ht := (hmass.add (tendsto_const_nhds (x := ∫ x, g x ∂μ))).sub + (hmin.const_mul 2) + have hz : (∫ x, g x ∂μ)+(∫ x, g x ∂μ)-2*(∫ x, g x ∂μ)=0 := by ring + rw [hz] at ht + apply ht.congr + intro n + rw [← integral_add (hf n) hg, ← integral_const_mul] + have hi : Integrable (fun x => f n x+g x) μ := (hf n).add hg + have hj : Integrable (fun x => 2*min (f n x) (g x)) μ := ((hf n).inf hg).const_mul 2 + rw [← integral_sub hi hj] + congr 1 + ext x + rcases le_total (f n x) (g x) with h|h + · rw [min_eq_left h,abs_of_nonpos (sub_nonpos.mpr h)] + ring + · rw [min_eq_right h,abs_of_nonneg (sub_nonneg.mpr h)] + ring + +theorem scheffe_density_filter {ι : Type*} {l : Filter ι} [l.IsCountablyGenerated] + {α : Type*} [MeasurableSpace α] {μ : Measure α} + {f : ι → α → ℝ} {g : α → ℝ} + (hf : ∀ᶠ n in l, Integrable (f n) μ) (hg : Integrable g μ) + (hf0 : ∀ᶠ n in l, ∀ᵐ x ∂μ, 0 ≤ f n x) (hg0 : ∀ᵐ x ∂μ, 0 ≤ g x) + (hlim : ∀ᵐ x ∂μ, Tendsto (fun n => f n x) l (𝓝 (g x))) + (hmass : Tendsto (fun n => ∫ x, f n x ∂μ) l (𝓝 (∫ x, g x ∂μ))) : + Tendsto (fun n => ∫ x, |f n x-g x| ∂μ) l (𝓝 0) := by + have hmin : Tendsto (fun n => ∫ x, min (f n x) (g x) ∂μ) + l (𝓝 (∫ x, g x ∂μ)) := by + apply tendsto_integral_filter_of_dominated_convergence g + · filter_upwards [hf] with n hn + exact hn.aestronglyMeasurable.inf hg.aestronglyMeasurable + · filter_upwards [hf0] with n hn + filter_upwards [hn,hg0] with x hx hy + rw [Real.norm_eq_abs, abs_of_nonneg (le_min hx hy)] + exact min_le_right _ _ + · exact hg + · filter_upwards [hlim] with x hx + simpa using hx.min (tendsto_const_nhds (x := g x)) + have ht := (hmass.add (tendsto_const_nhds (x := ∫ x, g x ∂μ))).sub + (hmin.const_mul 2) + have hz : (∫ x, g x ∂μ)+(∫ x, g x ∂μ)-2*(∫ x, g x ∂μ)=0 := by ring + rw [hz] at ht + apply ht.congr' + filter_upwards [hf] with n hn + rw [← integral_add hn hg, ← integral_const_mul] + have hi : Integrable (fun x => f n x+g x) μ := hn.add hg + have hj : Integrable (fun x => 2*min (f n x) (g x)) μ := (hn.inf hg).const_mul 2 + rw [← integral_sub hi hj] + congr 1 + ext x + rcases le_total (f n x) (g x) with h|h + · rw [min_eq_left h,abs_of_nonpos (sub_nonpos.mpr h)] + ring + · rw [min_eq_right h,abs_of_nonneg (sub_nonneg.mpr h)] + ring + +noncomputable def stepMass (p : ℕ → ℝ) (x : ℝ) : ℝ := + ∑' j : ℕ, (Set.Ico (j:ℝ) (j+1)).indicator (fun _ => p j) x + +lemma stepMass_of_nonneg (p : ℕ → ℝ) {x : ℝ} (hx : 0 ≤ x) : + stepMass p x = p ⌊x⌋₊ := by + unfold stepMass + rw [tsum_eq_single ⌊x⌋₊] + · exact Set.indicator_of_mem (show x ∈ Set.Ico (⌊x⌋₊:ℝ) (⌊x⌋₊+1) from + ⟨Nat.floor_le hx,Nat.lt_floor_add_one x⟩) _ + · intro j hj + apply Set.indicator_of_notMem + intro h + exact hj ((Nat.floor_eq_iff hx).mpr h).symm + +lemma stepMass_of_neg (p : ℕ → ℝ) {x : ℝ} (hx : x < 0) : stepMass p x = 0 := by + unfold stepMass + suffices hh : (fun j : ℕ => (Set.Ico (j:ℝ) (j+1)).indicator (fun _ => p j) x) = 0 by + rw [hh] + change (∑' _ : ℕ, (0:ℝ)) = 0 + exact tsum_zero + ext j + apply Set.indicator_of_notMem + intro h + exact (not_le.mpr hx) ((Nat.cast_nonneg j).trans h.1) + +lemma stepMass_nonneg {p : ℕ → ℝ} (hp : ∀ j, 0 ≤ p j) (x : ℝ) : 0 ≤ stepMass p x := by + by_cases hx : 0 ≤ x + · rw [stepMass_of_nonneg p hx] + exact hp _ + · rw [stepMass_of_neg p (lt_of_not_ge hx)] + +lemma integral_step_interval (p : ℕ → ℝ) (j : ℕ) : + ∫ x : ℝ, (Set.Ico (j:ℝ) (j+1)).indicator (fun _ => p j) x = p j := by + rw [integral_indicator measurableSet_Ico,integral_const] + simp [Measure.real,Real.volume_Ico] + +lemma integrable_step_interval (p : ℕ → ℝ) (j : ℕ) : + Integrable ((Set.Ico (j:ℝ) (j+1)).indicator (fun _ => p j)) := + (integrableOn_const (μ := volume) (C := p j) (by simp [Real.volume_Ico])).integrable_indicator + measurableSet_Ico + +lemma integral_step_interval_norm (p : ℕ → ℝ) (j : ℕ) : + ∫ x : ℝ, ‖(Set.Ico (j:ℝ) (j+1)).indicator (fun _ => p j) x‖ = |p j| := by + rw [← integral_step_interval (fun j => |p j|) j] + congr 1 + ext x + by_cases hx : x ∈ Set.Ico (j:ℝ) (j+1) + · simp [Set.indicator_of_mem hx] + · simp [Set.indicator_of_notMem hx] + +lemma integral_stepMass {p : ℕ → ℝ} (hp : Summable p) : + ∫ x, stepMass p x = ∑' j, p j := by + unfold stepMass + rw [← integral_tsum_of_summable_integral_norm (integrable_step_interval p)] + · simp only [integral_step_interval] + · simpa only [integral_step_interval_norm] using hp.abs + +lemma integrable_stepMass {p : ℕ → ℝ} (hp : HasSum p 1) : Integrable (stepMass p) := by + apply Integrable.of_integral_ne_zero + rw [integral_stepMass hp.summable,hp.tsum_eq] + norm_num + +noncomputable def histogram (q : ℝ) (n : ℕ) (p : ℕ → ℝ) (x : ℝ) : ℝ := + Real.sqrt n*stepMass p (q*n+x*Real.sqrt n) + +lemma integrable_histogram {p : ℕ → ℝ} (hp : HasSum p 1) (q : ℝ) {n : ℕ} + (hn : 0 < n) : Integrable (histogram q n p) := by + have hs : Real.sqrt (n:ℝ) ≠ 0 := by positivity + have hi := ((integrable_stepMass hp).comp_add_right (q*n)).comp_mul_right' hs + convert! hi.const_mul (Real.sqrt (n:ℝ)) using 1 + ext x + simp only [histogram,add_comm] + +lemma integral_histogram {p : ℕ → ℝ} (hp : HasSum p 1) (q : ℝ) {n : ℕ} + (hn : 0 < n) : ∫ x, histogram q n p x = 1 := by + have hs : Real.sqrt (n:ℝ) ≠ 0 := by positivity + unfold histogram + rw [integral_const_mul] + have hh : (fun x : ℝ => stepMass p (q*n+x*Real.sqrt n)) = + (fun x : ℝ => (fun t => stepMass p (t+q*n)) (Real.sqrt n*x)) := by + ext x + congr 1 + ring + rw [hh,Measure.integral_comp_mul_left (fun t : ℝ => stepMass p (t+q*n)) + (Real.sqrt (n:ℝ)),integral_add_right_eq_self, + integral_stepMass hp.summable,hp.tsum_eq,smul_eq_mul,mul_one, + abs_of_nonneg (inv_nonneg.mpr (Real.sqrt_nonneg _)),mul_inv_cancel₀ hs] + +lemma histogram_nonneg {p : ℕ → ℝ} (hp : ∀ j, 0 ≤ p j) (q : ℝ) (n : ℕ) (x : ℝ) : + 0 ≤ histogram q n p x := + mul_nonneg (Real.sqrt_nonneg _) (stepMass_nonneg hp _) + +end SKGapCutoff.Clock + +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/SumPoissonMass.lean b/lean/OAI/Probability/SKGap/Localization/SumPoissonMass.lean new file mode 100644 index 0000000000000000000000000000000000000000..ccfe527e37f9743235d01bb88ec2f9224ced419f --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/SumPoissonMass.lean @@ -0,0 +1,215 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.LogQuadratic +import OAI.Probability.SKGap.Localization.StepMass + +namespace OAI + +section +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open scoped BigOperators +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open scoped BigOperators +open scoped BigOperators NNReal ENNReal +open MeasureTheory Metric Set +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators NNReal ENNReal Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Set +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators ENNReal NNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Matrix +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators ENNReal NNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal +open scoped BigOperators +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise NNReal ENNReal +open scoped BigOperators +open Filter Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal Topology +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Set Matrix +open scoped BigOperators NNReal ENNReal Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open Filter MeasureTheory ProbabilityTheory +open scoped Topology NNReal ENNReal +open Filter MeasureTheory ProbabilityTheory +open scoped Topology NNReal ENNReal +namespace SKGapCutoff.Clock + +lemma hasSum_poissonMass (m : ℝ) : HasSum (poissonMass m) 1 := by + convert! (NormedSpace.expSeries_div_hasSum_exp m).mul_left (Real.exp (-m)) using 1 + · ext n + simp only [poissonMass,mul_div_assoc] + · simp [← Real.exp_eq_exp_ℝ, ← Real.exp_add] + +lemma hasSum_binomialMass (q : ℝ) (n : ℕ) : HasSum (binomialMass q n) 1 := by + have hh : HasSum (binomialMass q n) + (∑ k ∈ Finset.range (n+1), binomialMass q n k) := + hasSum_sum_of_ne_finset_zero (s := Finset.range (n+1)) + (f := binomialMass q n) (by + intro k hk + have hnk : n < k := by simpa only [Finset.mem_range,not_lt,Nat.add_one_le_iff] using hk + simp only [binomialMass,Nat.choose_eq_zero_of_lt hnk,Nat.cast_zero,zero_mul]) + convert! hh using 1 + have hb := add_pow q (1-q) n + have hq : q+(1-q)=1 := by ring + rw [hq,one_pow] at hb + rw [hb] + apply Finset.sum_congr rfl + intro i hi + simp only [binomialMass] + ring + +lemma poisson_density_pointwise {q : ℝ} (hq : 0 < q) (y x : ℝ) : + Tendsto (fun n : ℕ => histogram q n (poissonMass (q*n+y*Real.sqrt n)) x) + atTop (𝓝 (gaussianPDFReal y ⟨q,hq.le⟩ x)) := by + have hh := poisson_histogram_pointwise hq x y + rw [gaussian_formula hq x y] at hh + apply hh.congr' + filter_upwards [(center_tendsto_atTop hq x).eventually (eventually_ge_atTop 0)] with n hn + simp only [histogram,stepMass_of_nonneg _ hn,centralIndex] + +lemma binomial_density_pointwise {q : ℝ} (hql : 0 < q) (hqu : q < 1) (x : ℝ) : + Tendsto (fun n : ℕ => histogram q n (binomialMass q n) x) + atTop (𝓝 (gaussianPDFReal 0 ⟨q*(1-q),mul_nonneg hql.le (by linarith)⟩ x)) := by + apply (binomial_histogram_pointwise hql hqu x).congr' + filter_upwards [(center_tendsto_atTop hql x).eventually (eventually_ge_atTop 0)] with n hn + simp only [histogram,stepMass_of_nonneg _ hn,centralIndex] + +theorem poisson_density_L1 {q : ℝ} (hq : 0 < q) (y : ℝ) : + Tendsto (fun n : ℕ => ∫ x : ℝ, + |histogram q n (poissonMass (q*n+y*Real.sqrt n)) x- + gaussianPDFReal y ⟨q,hq.le⟩ x|) atTop (𝓝 0) := by + apply scheffe_density_filter + · filter_upwards [eventually_gt_atTop 0] with n hn + exact integrable_histogram (hasSum_poissonMass _) q hn + · exact integrable_gaussianPDFReal _ _ + · filter_upwards [(center_tendsto_atTop hq y).eventually (eventually_ge_atTop 0)] with n hn + exact Filter.Eventually.of_forall (histogram_nonneg (fun j => by + unfold poissonMass + positivity) q n) + · exact Filter.Eventually.of_forall (gaussianPDFReal_nonneg _ _) + · exact Filter.Eventually.of_forall (poisson_density_pointwise hq y) + · have hv : (⟨q,hq.le⟩ : ℝ≥0) ≠ 0 := by + intro h + have hh := congrArg (fun r : ℝ≥0 => (r:ℝ)) h + exact hq.ne' hh + rw [integral_gaussianPDFReal_eq_one _ hv] + apply tendsto_const_nhds.congr' + filter_upwards [eventually_gt_atTop 0] with n hn + exact (integral_histogram (hasSum_poissonMass _) q hn).symm + +theorem binomial_density_L1 {q : ℝ} (hql : 0 < q) (hqu : q < 1) : + Tendsto (fun n : ℕ => ∫ x : ℝ, + |histogram q n (binomialMass q n) x- + gaussianPDFReal 0 ⟨q*(1-q),mul_nonneg hql.le (by linarith)⟩ x|) atTop (𝓝 0) := by + apply scheffe_density_filter + · filter_upwards [eventually_gt_atTop 0] with n hn + exact integrable_histogram (hasSum_binomialMass q n) q hn + · exact integrable_gaussianPDFReal _ _ + · apply Filter.Eventually.of_forall + intro n + exact Filter.Eventually.of_forall (histogram_nonneg (fun j => by + unfold binomialMass + positivity) q n) + · exact Filter.Eventually.of_forall (gaussianPDFReal_nonneg _ _) + · exact Filter.Eventually.of_forall (binomial_density_pointwise hql hqu) + · have hv : (⟨q*(1-q),mul_nonneg hql.le (by linarith)⟩ : ℝ≥0) ≠ 0 := by + intro h + have hh := congrArg (fun r : ℝ≥0 => (r:ℝ)) h + exact (mul_pos hql (by linarith : 0 < 1-q)).ne' hh + rw [integral_gaussianPDFReal_eq_one _ hv] + apply tendsto_const_nhds.congr' + filter_upwards [eventually_gt_atTop 0] with n hn + exact (integral_histogram (hasSum_binomialMass q n) q hn).symm + +end SKGapCutoff.Clock + +open MeasureTheory Filter +open scoped Topology NNReal ENNReal + +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/SusceptibilityMiddle.lean b/lean/OAI/Probability/SKGap/Localization/SusceptibilityMiddle.lean new file mode 100644 index 0000000000000000000000000000000000000000..9d2f93c057511e7f162e95f6425d4717e9b774bc --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/SusceptibilityMiddle.lean @@ -0,0 +1,232 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.BufferedFlip + +namespace OAI + +section + +noncomputable section +open scoped BigOperators +namespace SKGapCutoff.Recipe +open SKGap.Stein Primary +variable {n : ℕ} + +def literalSusceptibility (z : VectorFields n) (a : Spin n→ℝ) (r : Fin n→ℝ) : Spin n→ℝ := + fun x=>Real.sqrt (n:ℝ)*(siteMean (fun v i=>phi (z v i) (r i) (a v)) x-(1-SKGap.overlap r)) + +lemma literal_middle_error (J : Interaction n) (j : ℝ) (f : KernelExpr) + (z m w y : VectorFields n) (a c : Spin n→ℝ) (r e : Fin n→ℝ) (x : Spin n) + (hn : 0phi (z v i) (r i) (a v)) x)* + (∑i,(Real.tanh (z x i)-Real.tanh (r i))*w x i)|≤ + (|j| *|literalSizeBudget j δ R L f|)*ρ*|literalSusceptibility z a r x| := by + have hh:=literal_initial_size J j f z m w y a c r e x hn hδ hρ hsmall hJ he H h + have hw : vectorNorm (w x)≤|literalSizeBudget j δ R L f| := by + have hrest : 0 ≤ vectorNorm (y x) + Real.sqrt (n:ℝ)*|c x| := by + exact add_nonneg (vectorNorm_nonneg _) (mul_nonneg (Real.sqrt_nonneg _) (abs_nonneg _)) + exact (le_trans (by linarith) hh).trans (le_abs_self _) + have hp : vectorNorm (fun i=>Real.tanh (z x i)-Real.tanh (r i))≤ρ*Real.sqrt (n:ℝ) := + (magnetization_vector_lipschitz (z x) r).trans H.z_near + have hd : |∑i,(Real.tanh (z x i)-Real.tanh (r i))*w x i|≤ + (ρ*Real.sqrt (n:ℝ))*|literalSizeBudget j δ R L f| := + (SKGap.vector_dot_abs_le _ _).trans (mul_le_mul hp hw (vectorNorm_nonneg _) (by positivity)) + rw [abs_mul,abs_mul] + apply (mul_le_mul_of_nonneg_left hd (mul_nonneg (abs_nonneg _) (abs_nonneg _))).trans_eq + rw [literalSusceptibility,abs_mul,abs_of_nonneg (Real.sqrt_nonneg _),abs_sub_comm] + ring + +lemma primary_auxiliary_global (hn : 0j*(1-Primary.onsager j J h k v-SKGap.overlap r)) r x|≤ + (Real.exp (|j|/2)+1)*Real.sqrt (n:ℝ) := by + have ha:=primary_auxiliary_global hn j J h r k x + have hphi : |siteMean (fun v i=>phi (fld j J h k v i) (r i) + (j*(1-Primary.onsager j J h k v-SKGap.overlap r))) x|≤Real.exp (|j|/2) := by + apply coefficient_mean_value _ _ (Real.exp_pos _).le + intro i + rw [abs_of_pos (phi_pos ..)] + exact (phi_le_exp ..).trans (Real.exp_le_exp.mpr (by linarith)) + have hq : |1-SKGap.overlap r|≤1 := by + rw [abs_of_nonneg (sub_nonneg.mpr (SKGap.overlap_lt_one hn r).le)] + linarith [SKGap.overlap_nonneg r] + have H:=(abs_sub _ _).trans (add_le_add hphi hq) + rw [literalSusceptibility,abs_mul,abs_of_nonneg (Real.sqrt_nonneg _)] + exact (mul_le_mul_of_nonneg_left H (Real.sqrt_nonneg _)).trans_eq (by ring) + +end SKGapCutoff.Recipe + +end +end + +section + +noncomputable section +open scoped BigOperators Matrix.Norms.Frobenius +namespace SKGapCutoff.Recipe +open Primary SKGap.Stein +variable {n : ℕ} + +lemma parameter_fourth_bound (hn : 0(halfDiff k a x)^2) (fun _ _=>sq_nonneg _) + have he : (∑k:Fin n,(halfDiff k a x)^2)=‖derivativeVector a x‖^2 := by + simp only [EuclideanSpace.real_norm_sq_eq,derivativeVector] + rw [he] at hh + have hp:=mul_le_mul_of_nonneg_left hh (Nat.cast_nonneg n : (0:ℝ)≤n) + have hq:=pow_le_pow_left₀ (mul_nonneg (Nat.cast_nonneg n) (sq_nonneg _)) hD 2 + have hs:=mul_nonneg (sub_nonneg.mpr hn1) (sq_nonneg ((n:ℝ)*‖derivativeVector a x‖^2)) + simp only [Finset.sum_const,Finset.card_univ,Fintype.card_fin,nsmul_eq_mul,←pow_mul] at hp ⊢ + have ht:=mul_le_mul_of_nonneg_left hn1 (pow_nonneg (norm_nonneg (derivativeVector a x)) 4) + have ht':=mul_le_mul_of_nonneg_left ht (Nat.cast_nonneg n : (0:ℝ)≤n) + norm_num only at hp + nlinarith + +lemma one_coefficient_derivative_bound (hn : 0z) (fun _:Unit=>a) F F' x L) + (hz : ShapeBound (derivativeMatrix z x) C) + (ha : (n:ℝ)*‖derivativeVector a x‖^2≤D^2) : + SKGap.opNorm (derivativeMatrix (coefficient (fun _:Unit=>z) (fun _:Unit=>a) F) x)≤ + L*C+L*D+12*L*(C^2+D^2) := by + have hL:=H.nonneg + let T:Fin n→ℝ:=localPartial (fun _:Unit=>z) (fun _:Unit=>a) F' (.inl ()) x + let U:Fin n→ℝ:=localPartial (fun _:Unit=>z) (fun _:Unit=>a) F' (.inr ()) x + let V:Interaction n:=Matrix.of (fun i k=>(1:ℝ)*halfDiff k a x) + let R:Interaction n:=Matrix.of (taylorError (fun _:Unit=>z) (fun _:Unit=>a) F F' x) + have hT : SKGap.opNorm (Matrix.diagonal T)≤L := + SKGap.opNorm_diagonal_le H.nonneg (fun i=>H.partial_bound i (.inl ())) + have hU : SKGap.opNorm (Matrix.diagonal U)≤L := + SKGap.opNorm_diagonal_le H.nonneg (fun i=>H.partial_bound i (.inr ())) + have hV : ‖V‖≤D := outer_frobenius_bound (fun _=>by norm_num) hD ha + have hRpoint (i k:Fin n) : |R i k|≤6*L*((derivativeMatrix z x i k)^2+(halfDiff k a x)^2) := by + have hh:=taylor_error_bound (fun _:Unit=>z) (fun _:Unit=>a) F F' x i k H.nonneg + (abs_nonneg (derivativeMatrix z x i k)) (abs_nonneg (halfDiff k a x)) + (by simpa only [Fintype.sum_unique] using local_argument_bound (fun _:Unit=>z) (fun _:Unit=>a) x i k) + (H.deriv i k) (H.lip i k) + change |R i k|≤_ at hh + simp only [sq_abs] at hh + have hs:=mul_nonneg H.nonneg (sq_nonneg (|derivativeMatrix z x i k|-|halfDiff k a x|)) + simp only [sub_sq,sq_abs] at hs + nlinarith + have hR : ‖R‖≤12*L*(C^2+D^2) := by + have hs : ‖R‖^2≤72*L^2*(2*C^4+D^4) := by + rw [SKGap.frobenius_sq] + calc + _≤∑i,∑k,72*L^2*((derivativeMatrix z x i k)^4+(halfDiff k a x)^4) := by + apply Finset.sum_le_sum;intro i _ + apply Finset.sum_le_sum;intro k _ + have h:=pow_le_pow_left₀ (abs_nonneg (R i k)) (hRpoint i k) 2 + have ht:=mul_nonneg (sq_nonneg L) (sq_nonneg ((derivativeMatrix z x i k)^2-(halfDiff k a x)^2)) + nlinarith [sq_abs (R i k)] + _=72*L^2*((∑i,∑k,(derivativeMatrix z x i k)^4)+(∑i,∑k,(halfDiff k a x)^4)) := by + simp only [mul_add,Finset.mul_sum,Finset.sum_add_distrib] + _≤72*L^2*(2*C^4+D^4) := mul_le_mul_of_nonneg_left + (add_le_add (fourth_sum_le hC hz) (parameter_fourth_bound hn a x ha)) (by positivity) + apply nonneg_le_nonneg_of_sq_le_sq (by positivity) + simp only [←sq] + apply hs.trans + nlinarith [mul_nonneg (sq_nonneg L) (mul_nonneg (sq_nonneg C) (sq_nonneg D)), + mul_nonneg (sq_nonneg L) (pow_nonneg hD 4)] + have he : derivativeMatrix (coefficient (fun _:Unit=>z) (fun _:Unit=>a) F) x= + Matrix.diagonal T*derivativeMatrix z x+Matrix.diagonal U*V+R := by + ext i k + simp only [Matrix.add_apply,Matrix.diagonal_mul,R,V,Matrix.of_apply,T,U,taylorError,localPartial] + rw [coefficient_chain] + simp only [Fintype.sum_unique] + ring + rw [he] + have hmain : SKGap.opNorm (Matrix.diagonal T*derivativeMatrix z x)≤L*C := + (SKGap.opNorm_mul _ _).trans (mul_le_mul hT hz.1 (norm_nonneg _) H.nonneg) + have hparam : SKGap.opNorm (Matrix.diagonal U*V)≤L*D := + (opNorm_le_frobenius _).trans ((SKGap.frobenius_mul_le_opNorm _ _).trans + (mul_le_mul hU hV (norm_nonneg _) H.nonneg)) + exact (opNorm_add _ _).trans (add_le_add + ((opNorm_add _ _).trans (add_le_add hmain hparam)) ((opNorm_le_frobenius _).trans hR)) + +end SKGapCutoff.Recipe + +noncomputable section +open scoped BigOperators Matrix.Norms.Frobenius +namespace SKGapCutoff.Recipe +open Primary SKGap.Stein + +theorem literalSusceptibility_global_derivative (j K B : ℝ) (hK : 0≤K) (hB : 0≤B) (k : ℕ) : + ∃S≥0,∀n:ℕ,0j*(1-onsager j J h (k+1) v-SKGap.overlap r)) r) x‖≤S := by + let f:=KernelExpr.atom 0 0 false + let L:=f.dBudget |j|+f.ddBudget |j| + let C:=localPrimaryBudget j K B (k+3) + let D := |j| * averageBudget j K B k + have hL : 0≤L:=add_nonneg (f.dBudget_nonneg _) (f.ddBudget_nonneg _) + have hC : 0≤C:=localPrimaryBudget_nonneg hK hB _ + have hD : 0≤D:=mul_nonneg (abs_nonneg _) (averageBudget_nonneg hK hB _) + refine ⟨L*C+L*D+12*L*(C^2+D^2),by positivity,?_⟩ + intro n hn J h r hop hformal x + let z:=fld j J h (k+1) + let a:=fun v:Spin n=>j*(1-onsager j J h (k+1) v-SKGap.overlap r) + let F:=fun i:Fin n=>fun u:Args (ι:=Unit) (κ:=Unit)=>eval3 f.eval (phiSelect () () u+(0,(r i,0))) + let F':=fun i:Fin n=>fun u:Args (ι:=Unit) (κ:=Unit)=> + (f.gradient (phiSelect () () u+(0,(r i,0)))).comp (phiSelect () ()) + have hreg : SegmentRegular (fun _:Unit=>z) (fun _:Unit=>a) F F' x L := + fixed_root_kernel_regular f (fun _:Unit=>z) (fun _:Unit=>a) x () () r |j| + (primary_auxiliary_global hn j J h r (k+1) x) + (fun v=>primary_auxiliary_global hn j J h r (k+1) (flip x v)) + have hz : ShapeBound (derivativeMatrix z x) C := + ((primary_differentiation J h x hn hK hB hop (k+1) + (fun l hl=>hformal x l (by omega))).2.2.2).mono + (localPrimaryBudget_bounds hK hB (k+3) ⟨k+1,by omega⟩).1 + have hm : (n:ℝ)*‖derivativeVector (onsager j J h (k+1)) x‖^2≤(averageBudget j K B k)^2 := by + simpa only [onsager,mag,primaryState,scalarVariance,averageBudget] using + primary_average_differentiation J h x hn hK hB hop k (fun l hl=>hformal x l (by omega)) + have ha : (n:ℝ)*‖derivativeVector a x‖^2≤D^2 := by + dsimp only [a] + rw [auxiliary_derivative,norm_smul,Real.norm_eq_abs,abs_neg,mul_pow] + calc + _=|j|^2*((n:ℝ)*‖derivativeVector (onsager j J h (k+1)) x‖^2) := by ring + _≤|j|^2*(averageBudget j K B k)^2 := mul_le_mul_of_nonneg_left hm (sq_nonneg _) + _=D^2 := by dsimp [D];ring + have he : coefficient (fun _:Unit=>z) (fun _:Unit=>a) F=(fun v i=>phi (z v i) (r i) (a v)) := by + funext v i + simp only [coefficient,F,eval3,phiSelect_apply,Prod.fst_add,Prod.snd_add, + localArgs,Sum.elim_inl,Sum.elim_inr,zero_add,add_zero,f,KernelExpr.eval,moment_base] + have hmat:=one_coefficient_derivative_bound hn z a x F F' hC hD hreg hz ha + rw [he] at hmat + have hav:=siteMean_derivative_square_bound hn hmat + have hed : derivativeVector (literalSusceptibility z a r) x= + Real.sqrt (n:ℝ) • derivativeVector (siteMean (fun v i=>phi (z v i) (r i) (a v))) x := by + ext i + simp only [derivativeVector,WithLp.ofLp_toLp,PiLp.smul_apply,literalSusceptibility,halfDiff] + ring + change ‖derivativeVector (literalSusceptibility z a r) x‖≤_ + rw [hed,norm_smul,Real.norm_eq_abs,abs_of_nonneg (Real.sqrt_nonneg _)] + apply nonneg_le_nonneg_of_sq_le_sq (by positivity) + simpa only [←sq,mul_pow,Real.sq_sqrt (Nat.cast_nonneg n)] using hav + +end SKGapCutoff.Recipe + +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/SusceptibilityTest.lean b/lean/OAI/Probability/SKGap/Localization/SusceptibilityTest.lean new file mode 100644 index 0000000000000000000000000000000000000000..7a69c0613e297384abded57eb9373318157a60ca --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/SusceptibilityTest.lean @@ -0,0 +1,99 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.SusceptibilityMiddle + +namespace OAI + +section + +noncomputable section +open scoped BigOperators +namespace SKGapCutoff.Static +open Primary Recipe +variable {n : ℕ} + +lemma cutoff_square_derivative (C : Observables n) {s A : ℝ} (hs : 0(C y)^2) x)^2≤(4*A/s)^2 := by + intro x + have H:=derivativeVector_mul_bound C C x hc hc (div_nonneg hA hs.le) (div_nonneg hA hs.le) (hd x) (hd x) + have H' : ‖derivativeVector (fun y=>(C y)^2) x‖≤4*A/s := by + simpa only [←sq] using H.trans_eq (show 2*(A/s+A/s)=4*A/s by ring) + simpa only [norm_derivativeVector_sq] using pow_le_pow_left₀ (norm_nonneg _) H' 2 + +lemma cutoff_susceptibility_star (P C L : Observables n) (hP : ∀x,0≤P x) + (hp : ∑x,P x=1) {s A B D : ℝ} (hs : 0(C x)^2*L x)≤ + (∑x,P x*(C x*L x)^2)+(32*A^2*B^2+2*D^2) := by + have hc2 : ∀x,|(C x)^2|≤1 := by + intro x + simpa only [sq_abs,abs_sq,one_pow] using pow_le_pow_left₀ (abs_nonneg _) (hc x) 2 + have hdC2:=cutoff_square_derivative C hs hA hc hdC + have hdL2 : ∀x,∑i,(halfDiff i L x)^2≤D^2 := by + intro x + simpa only [norm_derivativeVector_sq] using pow_le_pow_left₀ (norm_nonneg _) (hdL x) 2 + have hg:= (scalar_product_bounds (fun x=>(C x)^2) L (by norm_num) (by positivity) + (mul_nonneg hB hs.le) hD hc2 hdC2 hL hdL2).2 + have he : varianceEnergy P (fun x=>(C x)^2*L x)≤32*A^2*B^2+2*D^2 := by + have H:=varianceEnergy_gradient_bound P hP hp (fun x=>(C x)^2*L x) hg + rw [Real.sq_sqrt (by positivity)] at H + convert H using 1 + field_simp + ring + have hv : (∑x,P x*((C x)^2*L x)^2)≤∑x,P x*(C x*L x)^2 := by + apply Finset.sum_le_sum + intro x _ + apply mul_le_mul_of_nonneg_left _ (hP x) + have H : (C x)^2≤1 := by + simpa only [sq_abs,one_pow] using pow_le_pow_left₀ (abs_nonneg _) (hc x) 2 + have H':=mul_le_mul_of_nonneg_right H (sq_nonneg (C x*L x)) + nlinarith only [H'] + exact add_le_add hv he + +end SKGapCutoff.Static + +noncomputable section +open scoped BigOperators +namespace SKGapCutoff.Recipe +open Primary Static + +theorem literalSusceptibility_cutoff_test (j K B ρ : ℝ) (hK : 0≤K) (hB : 0≤B) + (hρ : 0<ρ) (k : ℕ) : + ∃D≥0,∀n:ℕ,0j*(1-onsager j J h (k+1) v-SKGap.overlap r)) r + starSquared P (fun x=>(C x)^2*L x)≤(∑x,P x*(C x*L x)^2)+D := by + obtain ⟨S,hS,hdL⟩:=literalSusceptibility_global_derivative j K B hK hB k + obtain ⟨Q,hQ⟩:=residualScalarCutoff_lipschitz + let U:=residualDerivativeBudget j K B k + let V:=residualDerivativeBudget j K B (k+1) + let A:=2*(Q:ℝ)/ρ^2*((4*U+2*U^2)+(4*V+2*V^2)) + have hU : 0≤U:=residualDerivativeBudget_nonneg hK hB _ + have hV : 0≤V:=residualDerivativeBudget_nonneg hK hB _ + have hA : 0≤A:=by dsimp [A];positivity + refine ⟨32*A^2*(Real.exp (|j|/2)+1)^2+2*S^2,by positivity,?_⟩ + intro n hn J h r P hP hp hop hformal + dsimp only + apply cutoff_susceptibility_star P _ _ hP hp (Real.sqrt_pos.mpr (Nat.cast_pos.mpr hn)) + hA (by positivity) hS + · intro x + rw [abs_of_nonneg (residualCutoff_bounds ρ j J h k x).1] + exact (residualCutoff_bounds ρ j J h k x).2 + · intro x + exact residualCutoff_gradient hn hρ hQ J h k x hU hV + (residual_derivative_bound hn hK hB J h hop k (fun v l hl=>hformal v l (by omega)) x) + (residual_derivative_bound hn hK hB J h hop (k+1) (fun v l hl=>hformal v l (by omega)) x) + · exact literalSusceptibility_global_size hn j J h r (k+1) + · exact hdL n hn J h r hop hformal + +end SKGapCutoff.Recipe + +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/SymmetricElementaryComm.lean b/lean/OAI/Probability/SKGap/Localization/SymmetricElementaryComm.lean new file mode 100644 index 0000000000000000000000000000000000000000..b35074135cb23cc36e21945b74e46499e300c03a --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/SymmetricElementaryComm.lean @@ -0,0 +1,94 @@ +import Mathlib +import OAI.Probability.SKGap.Gaussian.GaussianFiniteIBPError +import OAI.Probability.SKGap.Matrix.MatrixCoordinates + +namespace OAI + +noncomputable section + +open MeasureTheory ProbabilityTheory InformationTheory Real Set +open scoped NNReal ENNReal +open Filter +open scoped Topology +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius ENNReal NNReal +namespace SKGap +open MeasureTheory ProbabilityTheory +open scoped ENNReal NNReal +variable {ι : Type*} [Fintype ι] [DecidableEq ι] + +omit [Fintype ι] in +lemma symmetricElementary_comm (a b : ι) : symmetricElementary a b = symmetricElementary b a := + add_comm _ _ + +omit [Fintype ι] in +lemma goeMatrix_updated_observable_derivative {r : ℝ} + {H : Matrix ι ι ℝ → ℝ} {g : MatrixCoordinates ι → ℝ} {a b : ι} {d : ℝ} + (hd : HasDerivAt (fun t : ℝ => H (goeMatrix r g+t • symmetricElementary a b)) d 0) : + HasDerivAt (fun t => H (goeMatrix r (Function.update g (.inl (a,b)) t))) + ((sqrt (2*r)/2)*d) (g (.inl (a,b))) := by + have ha := ((hasDerivAt_id (g (.inl (a,b)))).sub_const (g (.inl (a,b)))).const_mul (sqrt (2*r)/2) + have ho : HasDerivAt (fun t : ℝ => H (goeMatrix r g+t • symmetricElementary a b)) d + ((fun y : ℝ => (sqrt (2*r)/2)*(y-g (.inl (a,b)))) (g (.inl (a,b)))) := by simpa using hd + have hh := ho.comp (g (.inl (a,b))) ha + simpa only [Function.comp_def,goeMatrix_update,mul_one,one_mul,mul_comm,id_eq] using! hh + +theorem goe_IBP_error {r : ℝ} (hr : 0 ≤ r) (a b : ι) + {H : Matrix ι ι ℝ → ℝ} {d : (MatrixCoordinates ι → ℝ) → ℝ} + {L : ℝ≥0} {C D : ℝ} {s : Set (MatrixCoordinates ι → ℝ)} + (hf : LipschitzWith L (fun g => H (goeMatrix r g))) + (hC : ∀ g, ‖H (goeMatrix r g)‖ ≤ C) + (hd : Measurable d) (hD : ∀ g, ‖d g‖ ≤ D) (hs : MeasurableSet s) + (hder : ∀ g ∈ s, HasDerivAt (fun t : ℝ => H (goeMatrix r g+t • symmetricElementary a b)) (d g) 0) : + |(∫ g, goeMatrix r g a b * H (goeMatrix r g) + ∂Measure.pi (fun _ : MatrixCoordinates ι => gaussianReal 0 1)) - + r*(∫ g, d g ∂Measure.pi (fun _ : MatrixCoordinates ι => gaussianReal 0 1))| ≤ + (sqrt (2*r)*(L:ℝ)+r*D)* + (Measure.pi (fun _ : MatrixCoordinates ι => gaussianReal 0 1)).real sᶜ := by + let μ := Measure.pi (fun _ : MatrixCoordinates ι => gaussianReal 0 1) + let c : ℝ := sqrt (2*r)/2 + have hc : 0 ≤ c := by dsimp [c]; positivity + have hc2 : 2*c^2 = r := by + dsimp [c]; rw [div_pow,Real.sq_sqrt (by positivity)]; ring + have hD' : ∀ g, ‖c*d g‖ ≤ c*D := fun g => by + rw [norm_mul,Real.norm_eq_abs,abs_of_nonneg hc] + exact mul_le_mul_of_nonneg_left (hD g) hc + have h₁ := gaussianFinite_IBP_error (.inl (a,b)) hf hC (hd.const_mul c) hD' hs + (fun g hg => goeMatrix_updated_observable_derivative (hder g hg)) + have h₂ := gaussianFinite_IBP_error (.inl (b,a)) hf hC (hd.const_mul c) hD' hs + (fun g hg => goeMatrix_updated_observable_derivative (by + simpa only [symmetricElementary_comm b a] using hder g hg)) + rw [integral_const_mul] at h₁ h₂ + have hi (i : MatrixCoordinates ι) : Integrable (fun g : MatrixCoordinates ι → ℝ => + g i*H (goeMatrix r g)) μ := by + simpa only [mul_comm] using (integrable_eval (i := i) IsGaussian.integrable_id).bdd_mul + hf.continuous.aestronglyMeasurable (ae_of_all _ hC) + have he : (∫ g, goeMatrix r g a b*H (goeMatrix r g) ∂μ) = + c*((∫ g, g (.inl (a,b))*H (goeMatrix r g) ∂μ)+ + ∫ g, g (.inl (b,a))*H (goeMatrix r g) ∂μ) := by + simp_rw [goeMatrix,mul_assoc,add_mul] + rw [integral_const_mul,integral_add (hi _) (hi _)] + change |(∫ g, goeMatrix r g a b*H (goeMatrix r g) ∂μ)-r*(∫ g, d g ∂μ)| ≤ _ + rw [he] + have he' : c*((∫ g, g (.inl (a,b))*H (goeMatrix r g) ∂μ)+ + ∫ g, g (.inl (b,a))*H (goeMatrix r g) ∂μ)-r*(∫ g, d g ∂μ) = + c*(((∫ g, g (.inl (a,b))*H (goeMatrix r g) ∂μ)-c*(∫ g, d g ∂μ))+ + ((∫ g, g (.inl (b,a))*H (goeMatrix r g) ∂μ)-c*(∫ g, d g ∂μ))) := by + rw [← hc2]; ring + rw [he',abs_mul,abs_of_nonneg hc] + calc + _ ≤ c*(|((∫ g, g (.inl (a,b))*H (goeMatrix r g) ∂μ)-c*(∫ g, d g ∂μ))|+ + |((∫ g, g (.inl (b,a))*H (goeMatrix r g) ∂μ)-c*(∫ g, d g ∂μ))|) := + mul_le_mul_of_nonneg_left (abs_add_le _ _) hc + _ ≤ c*(((L:ℝ)+c*D)*μ.real sᶜ+((L:ℝ)+c*D)*μ.real sᶜ) := + mul_le_mul_of_nonneg_left (add_le_add h₁ h₂) hc + _ = _ := by + change _ = (sqrt (2*r)*(L:ℝ)+r*D)*μ.real sᶜ + have hec : sqrt (2*r) = 2*c := by dsimp [c]; ring + rw [hec,← hc2]; ring + +end SKGap + +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/TAPGauge.lean b/lean/OAI/Probability/SKGap/Localization/TAPGauge.lean new file mode 100644 index 0000000000000000000000000000000000000000..76065e6bad85aca8fff33bb283471177569744a0 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/TAPGauge.lean @@ -0,0 +1,102 @@ +import Mathlib +import OAI.Probability.SKGap.Stability.RootDiagonalTransfer + +namespace OAI + +section +noncomputable section +namespace SKGap +open Matrix Real Set +open scoped BigOperators + +def spinAct {n : ℕ} (s : Spin n) (y : Field n) : Field n := + fun i=>spinValue (s i)*y i + +def spinMatrixAct {n : ℕ} (s : Spin n) (J : Matrix (Fin n) (Fin n) ℝ) : + Matrix (Fin n) (Fin n) ℝ := fun i k=>spinValue (s i)*J i k*spinValue (s k) + +lemma spinAct_involutive {n : ℕ} (s : Spin n) (y : Field n) : spinAct s (spinAct s y)=y := by + ext i + simp only [spinAct,← mul_assoc,← sq,spinValue_sq,one_mul] + +lemma spinAct_tanh {n : ℕ} (s : Spin n) (y : Field n) : + magnetization (spinAct s y)=spinAct s (magnetization y) := by + ext i + cases h : s i <;> simp [magnetization,spinAct,spinValue,h,tanh_neg] + +lemma spinAct_overlap {n : ℕ} (s : Spin n) (y : Field n) : overlap (spinAct s y)=overlap y := by + unfold overlap + rw [spinAct_tanh] + simp only [spinAct,mul_pow,spinValue_sq,one_mul] + +lemma spinAct_variance {n : ℕ} (s : Spin n) (y : Field n) : + spinVariance (spinAct s y)=spinVariance y := by + ext i + simp only [spinVariance,spinAct_tanh,spinAct,mul_pow,spinValue_sq,one_mul] + +lemma spinAct_sqnorm {n : ℕ} (s : Spin n) (y : Field n) : vectorSqNorm (spinAct s y)=vectorSqNorm y := by + simp only [vectorSqNorm,spinAct,mul_pow,spinValue_sq,one_mul] + +lemma spinAct_norm {n : ℕ} (s : Spin n) (y : Field n) : vectorNorm (spinAct s y)=vectorNorm y := by + have hh : vectorNorm (spinAct s y)^2=vectorNorm y^2 := by + rw [vectorNorm_sq,vectorNorm_sq,spinAct_sqnorm] + nlinarith only [hh,vectorNorm_nonneg (spinAct s y),vectorNorm_nonneg y] + +lemma spinAct_quadratic {n : ℕ} (s : Spin n) (J : Matrix (Fin n) (Fin n) ℝ) (y : Field n) : + quadraticForm (spinMatrixAct s J) (spinAct s y)=quadraticForm J y := by + unfold quadraticForm + apply Finset.sum_congr rfl + intro i _ + apply Finset.sum_congr rfl + intro k _ + simp only [spinMatrixAct,spinAct] + calc + _ = spinValue (s i)^2*spinValue (s k)^2*(y i*J i k*y k) := by ring + _ = _ := by rw [spinValue_sq,spinValue_sq,one_mul,one_mul] + +lemma spinAct_tap {n : ℕ} (s : Spin n) (j : ℝ) (J : Matrix (Fin n) (Fin n) ℝ) (h y : Field n) : + tapField j (spinMatrixAct s J) (spinAct s h) (spinAct s y)=spinAct s (tapField j J h y) := by + ext i + simp only [tapField,spinAct_tanh,onsager,spinAct_overlap,spinAct,spinMatrixAct] + have hs : (∑ k, spinValue (s i)*J i k*spinValue (s k)*(spinValue (s k)*magnetization y k))= + spinValue (s i)*∑ k,J i k*magnetization y k := by + rw [Finset.mul_sum] + apply Finset.sum_congr rfl + intro k _ + calc + _ = spinValue (s i)*(J i k*magnetization y k)*spinValue (s k)^2 := by ring + _ = _ := by rw [spinValue_sq,mul_one] + rw [hs] + ring + +lemma spinAct_hessian {n : ℕ} (s : Spin n) (j : ℝ) (J : Matrix (Fin n) (Fin n) ℝ) (y a : Field n) : + fieldHessian j (spinMatrixAct s J) (spinAct s y) a=spinMatrixAct s (fieldHessian j J y a) := by + ext i k + simp only [fieldHessian,hessianCore,onsager,spinAct_overlap,spinAct_tanh,spinAct,spinMatrixAct] + by_cases hik : i=k + · subst k + cases hi : s i <;> simp [spinValue] + · simp only [ite_eq_right hik] + ring + +lemma spinAct_bad {n : ℕ} (s : Spin n) (j A ε c ρ : ℝ) + (J : Matrix (Fin n) (Fin n) ℝ) (h : Field n) : + rootBad j A ε c ρ J h → rootBad j A ε c ρ (spinMatrixAct s J) (spinAct s h) := by + rintro ⟨y,hy,a,ha,hd,x,hx,hq⟩ + let z : EuclideanSpace ℝ (Fin n) := WithLp.toLp 2 (spinAct s x.ofLp) + have hz : ‖z‖=1 := by + change vectorNorm (spinAct s x.ofLp)=1 + rw [spinAct_norm] + exact hx + refine ⟨spinAct s y,?_,a,ha,?_,z,hz,?_⟩ + · rw [spinAct_tap,spinAct_norm] + exact hy + · rw [spinAct_variance] + exact hd + · rw [spinAct_hessian] + exact (spinAct_quadratic s (fieldHessian j J y a) x.ofLp).trans_le hq +end SKGap +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/TAPScalarTaylor.lean b/lean/OAI/Probability/SKGap/Localization/TAPScalarTaylor.lean new file mode 100644 index 0000000000000000000000000000000000000000..5e4b6071257cc721e63bb475d3bbe495e10eb0a6 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/TAPScalarTaylor.lean @@ -0,0 +1,85 @@ +import Mathlib +import OAI.Probability.SKGap.Stability.StableFields + +namespace OAI + +section +noncomputable section +namespace SKGap +open Real Set + +lemma scalar_remainder_of_lipschitz_derivative {f f' : ℝ → ℝ} {L : ℝ} + (hL : 0 ≤ L) (hd : ∀ x, HasDerivAt f (f' x) x) + (hl : ∀ x y, |f' x-f' y| ≤ L*|x-y|) (x d : ℝ) : + |f (x+d)-f x-f' x*d| ≤ L*d^2 := by + let R : ℝ → ℝ := fun z => f z-f x-f' x*(z-x) + have hder (z : ℝ) : HasDerivAt R (f' z-f' x) z := by + dsimp [R] + convert! ((hd z).sub_const (f x)).sub (((hasDerivAt_id z).sub_const x).const_mul (f' x)) using 1; simp + have bnd (z : ℝ) (hz : z ∈ segment ℝ x (x+d)) : ‖f' z-f' x‖ ≤ L*|d| := by + rw [Real.norm_eq_abs] + apply (hl z x).trans + apply mul_le_mul_of_nonneg_left _ hL + simpa only [Real.norm_eq_abs,add_sub_cancel_left] using norm_sub_le_of_mem_segment hz + have hh := Convex.norm_image_sub_le_of_norm_hasDerivWithin_le + (fun z (_ : z ∈ segment ℝ x (x+d)) => (hder z).hasDerivWithinAt) bnd + (convex_segment x (x+d)) (left_mem_segment ℝ x (x+d)) (right_mem_segment ℝ x (x+d)) + simpa only [R,sub_self,mul_zero,sub_zero,add_sub_cancel_left,Real.norm_eq_abs, + mul_assoc,← pow_two,sq_abs] using hh + +lemma tanh_lipschitz_abs (x y : ℝ) : |tanh x-tanh y| ≤ |x-y| := by + have hh := Convex.norm_image_sub_le_of_norm_hasDerivWithin_le + (fun z (_ : z ∈ (univ : Set ℝ)) => (hasDerivAt_tanh z).hasDerivWithinAt) + (C := 1) (fun z _ => by + rw [Real.norm_eq_abs,abs_of_nonneg (sub_nonneg.mpr (tanh_sq_lt_one z).le)] + linarith [sq_nonneg (tanh z)]) convex_univ (mem_univ y) (mem_univ x) + simpa only [Real.norm_eq_abs,one_mul] using hh + +lemma scalar_variance_lipschitz_abs (x y : ℝ) : + |(1-tanh x^2)-(1-tanh y^2)| ≤ 2*|x-y| := by + have hsum : |tanh x+tanh y| ≤ 2 := (abs_add_le _ _).trans (by + linarith [(abs_tanh_lt_one x).le,(abs_tanh_lt_one y).le]) + calc + _ = |tanh x-tanh y| * |tanh x+tanh y| := by + rw [show (1-tanh x^2)-(1-tanh y^2) = -((tanh x-tanh y)*(tanh x+tanh y)) by ring, abs_neg, abs_mul] + _ ≤ |x-y| * 2 := mul_le_mul (tanh_lipschitz_abs x y) hsum (abs_nonneg _) (abs_nonneg _) + _ = _ := mul_comm _ _ + +lemma tanh_scalar_remainder (x d : ℝ) : + |tanh (x+d)-tanh x-(1-tanh x^2)*d| ≤ 2*d^2 := + scalar_remainder_of_lipschitz_derivative (by norm_num) hasDerivAt_tanh + scalar_variance_lipschitz_abs x d + +lemma scalar_variance_hasDeriv (x : ℝ) : + HasDerivAt (fun z => 1-tanh z^2) (-2*tanh x*(1-tanh x^2)) x := by + convert! (hasDerivAt_const x (1:ℝ)).sub ((hasDerivAt_tanh x).pow 2) using 1; ring + +lemma scalar_variance_deriv_lipschitz_abs (x y : ℝ) : + |(-2*tanh x*(1-tanh x^2))-(-2*tanh y*(1-tanh y^2))| ≤ 6*|x-y| := by + have hu : |tanh x| ≤ 1 := (abs_tanh_lt_one x).le + have hv : |1-tanh y^2| ≤ 1 := by + rw [abs_of_nonneg (sub_nonneg.mpr (tanh_sq_lt_one y).le)] + linarith [sq_nonneg (tanh y)] + calc + _ = 2*|tanh x*((1-tanh x^2)-(1-tanh y^2))+ + (tanh x-tanh y)*(1-tanh y^2)| := by + rw [show (-2*tanh x*(1-tanh x^2))-(-2*tanh y*(1-tanh y^2))= + -(2*(tanh x*((1-tanh x^2)-(1-tanh y^2))+ + (tanh x-tanh y)*(1-tanh y^2))) by ring,abs_neg,abs_mul,abs_of_pos (by norm_num : (0:ℝ)<2)] + _ ≤ 2*(|tanh x| * |(1-tanh x^2)-(1-tanh y^2)|+ + |tanh x-tanh y| * |1-tanh y^2|) := by gcongr; exact (abs_add_le _ _).trans_eq (by rw [abs_mul,abs_mul]) + _ ≤ 2*(1*(2*|x-y|)+|x-y| * 1) := by + apply mul_le_mul_of_nonneg_left _ (by norm_num) + exact add_le_add (mul_le_mul hu (scalar_variance_lipschitz_abs x y) (abs_nonneg _) (by norm_num)) + (mul_le_mul (tanh_lipschitz_abs x y) hv (abs_nonneg _) (abs_nonneg _)) + _ = _ := by ring + +lemma scalar_variance_remainder (x d : ℝ) : + |(1-tanh (x+d)^2)-(1-tanh x^2)-(-2*tanh x*(1-tanh x^2))*d| ≤ 6*d^2 := + scalar_remainder_of_lipschitz_derivative (by norm_num) scalar_variance_hasDeriv + scalar_variance_deriv_lipschitz_abs x d +end SKGap +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/TAPVectorTaylor.lean b/lean/OAI/Probability/SKGap/Localization/TAPVectorTaylor.lean new file mode 100644 index 0000000000000000000000000000000000000000..a8e3c4a3619b57e5e49f6e33061cb059ca94c196 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/TAPVectorTaylor.lean @@ -0,0 +1,200 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.TAPScalarTaylor +import OAI.Probability.SKGap.Entropy.WeightedMomentComparison + +namespace OAI + +section +noncomputable section +namespace SKGap +open Matrix Real +open scoped BigOperators + +def varianceAverage {n : ℕ} (y : Field n) : ℝ := 1-overlap y + +def varianceLinear {n : ℕ} (y d : Field n) : ℝ := + (-2/(n:ℝ))*∑ i,magnetization y i*spinVariance y i*d i + +def magnetizationRemainder {n : ℕ} (y d : Field n) : Field n := + magnetization (y+d)-magnetization y-(fun i => spinVariance y i*d i) + +lemma varianceAverage_eq_average {n : ℕ} (hn : 0 < n) (y : Field n) : + varianceAverage y=(∑ i,spinVariance y i)/(n:ℝ) := by + have hn0 : (n:ℝ) ≠ 0 := by positivity + dsimp [varianceAverage,overlap,spinVariance] + simp only [Finset.sum_sub_distrib,Finset.sum_const,Finset.card_univ,Fintype.card_fin,nsmul_eq_mul,mul_one] + field_simp + +lemma varianceAverage_bounds {n : ℕ} (hn : 0 < n) (y : Field n) : + 0 ≤ varianceAverage y ∧ varianceAverage y ≤ 1 := by + dsimp [varianceAverage] + exact ⟨sub_nonneg.mpr (overlap_lt_one hn y).le,sub_le_self _ (overlap_nonneg y)⟩ + +lemma magnetization_norm_bound {n : ℕ} (y : Field n) : + vectorNorm (magnetization y) ≤ sqrt (n:ℝ) := by + apply (sq_le_sq₀ (vectorNorm_nonneg _) (sqrt_nonneg _)).mp + rw [vectorNorm_sq,Real.sq_sqrt (Nat.cast_nonneg _)] + calc + _ ≤ ∑ _i : Fin n,(1:ℝ) := Finset.sum_le_sum (fun i _ => (tanh_sq_lt_one (y i)).le) + _ = _ := by simp + +lemma vectorNorm_le_of_sq_sum {n : ℕ} {v : Field n} {c : ℝ} (hc : 0 ≤ c) + (hb : ∑ i,v i^2 ≤ c^2) : vectorNorm v ≤ c := by + apply (sq_le_sq₀ (vectorNorm_nonneg _) hc).mp + exact (vectorNorm_sq v).trans_le hb + +lemma magnetization_difference_norm {n : ℕ} (y d : Field n) : + vectorNorm (magnetization (y+d)-magnetization y) ≤ vectorNorm d := by + apply vectorNorm_le_of_sq_sum (vectorNorm_nonneg _) + rw [vectorNorm_sq] + apply Finset.sum_le_sum + intro i _ + have hh := tanh_lipschitz_abs (y i+d i) (y i) + rw [add_sub_cancel_left] at hh + simpa only [Pi.sub_apply,Pi.add_apply,magnetization,sq_abs] using + (sq_le_sq₀ (abs_nonneg _) (abs_nonneg _)).mpr hh |>.trans_eq (sq_abs (d i)) + +lemma magnetization_remainder_norm {n : ℕ} (y d : Field n) : + vectorNorm (magnetizationRemainder y d) ≤ 2*sqrt (∑ i,d i^4) := by + apply vectorNorm_le_of_sq_sum (by positivity) + rw [mul_pow,Real.sq_sqrt (Finset.sum_nonneg (fun i _ => (by positivity : 0 ≤ d i^4))),Finset.mul_sum] + apply Finset.sum_le_sum + intro i _ + have hh := tanh_scalar_remainder (y i) (d i) + have hh' := (sq_le_sq₀ (abs_nonneg _) (by positivity)).mpr hh + simpa only [magnetizationRemainder,Pi.sub_apply,Pi.add_apply,magnetization,spinVariance, + sq_abs,mul_pow,← pow_mul] using hh' + +lemma varianceAverage_remainder {n : ℕ} (hn : 0 < n) (y d : Field n) : + |varianceAverage (y+d)-varianceAverage y-varianceLinear y d| ≤ + 6/(n:ℝ)*vectorNorm d^2 := by + have hn0 : (0:ℝ) < n := by exact_mod_cast hn + rw [varianceAverage_eq_average hn,varianceAverage_eq_average hn,vectorNorm_sq] + have he : (∑ i,spinVariance (y+d) i)/(n:ℝ)- + (∑ i,spinVariance y i)/(n:ℝ)-varianceLinear y d= + (∑ i,(spinVariance (y+d) i-spinVariance y i- + (-2*magnetization y i*spinVariance y i)*d i))/(n:ℝ) := by + have hlin : (∑ i,(-2*magnetization y i*spinVariance y i)*d i)= + -2*∑ i,magnetization y i*spinVariance y i*d i := by + rw [Finset.mul_sum] + apply Finset.sum_congr rfl + intro i _; ring + simp only [varianceLinear,Finset.sum_sub_distrib,hlin] + field_simp + rw [he,abs_div,abs_of_pos hn0] + apply (div_le_iff₀ hn0).mpr + calc + _ ≤ ∑ i,|(spinVariance (y+d) i-spinVariance y i-(-2*magnetization y i*spinVariance y i)*d i)| := + Finset.abs_sum_le_sum_abs _ _ + _ ≤ ∑ i,6*d i^2 := Finset.sum_le_sum (fun i _ => scalar_variance_remainder (y i) (d i)) + _ = _ := by simp only [vectorSqNorm,← Finset.mul_sum]; field_simp + +lemma varianceAverage_difference {n : ℕ} (hn : 0 < n) (y d : Field n) : + |varianceAverage (y+d)-varianceAverage y| ≤ 2/sqrt (n:ℝ)*vectorNorm d := by + have hn0 : (0:ℝ) < n := by exact_mod_cast hn + have hs0 : sqrt (n:ℝ) ≠ 0 := ne_of_gt (sqrt_pos.mpr hn0) + rw [varianceAverage_eq_average hn,varianceAverage_eq_average hn,← sub_div, + ← Finset.sum_sub_distrib,abs_div,abs_of_pos hn0] + apply (div_le_iff₀ hn0).mpr + calc + _ ≤ ∑ i,|spinVariance (y+d) i-spinVariance y i| := Finset.abs_sum_le_sum_abs _ _ + _ ≤ ∑ i,2*|d i| := Finset.sum_le_sum (fun i _ => by + simpa only [spinVariance,magnetization,Pi.add_apply,add_sub_cancel_left] using scalar_variance_lipschitz_abs (y i+d i) (y i)) + _ = 2*∑ i,|d i| := by rw [Finset.mul_sum] + _ ≤ 2*(sqrt (n:ℝ)*vectorNorm d) := by + apply mul_le_mul_of_nonneg_left _ (by norm_num) + have hh := sum_abs_le_sqrt_card_l2 d + have he : sqrt (∑ i,d i^2)=vectorNorm d := by + change sqrt (vectorSqNorm d)=vectorNorm d + rw [← vectorNorm_sq,Real.sqrt_sq (vectorNorm_nonneg _)] + simpa only [Fintype.card_fin,he] using hh + _ = _ := by field_simp; rw [Real.sq_sqrt hn0.le]; ring + +lemma tap_remainder_identity {n : ℕ} (j : ℝ) (J : Matrix (Fin n) (Fin n) ℝ) + (h y d : Field n) : + tapField j J h (y+d)-tapField j J h y-(fieldJacobian j J y)*ᵥd= + (j*varianceAverage y) • magnetizationRemainder y d+ + (j*(varianceAverage (y+d)-varianceAverage y-varianceLinear y d)) • magnetization y+ + (j*(varianceAverage (y+d)-varianceAverage y)) • (magnetization (y+d)-magnetization y)- + J*ᵥmagnetizationRemainder y d := by + have hjac (i : Fin n) : (fieldJacobian j J y*ᵥd) i= + d i+onsager j y*(spinVariance y i*d i)- + (∑ k,J i k*(spinVariance y k*d k))+j*varianceLinear y d*magnetization y i := by + change (∑ k,fieldJacobian j J y i k*d k)=_ + have he : (∑ k,fieldJacobian j J y i k*d k)= + (∑ k,(if i=k then 1 else (0:ℝ))*d k)+ + onsager j y*(∑ k,(if i=k then 1 else (0:ℝ))*spinVariance y k*d k)- + (∑ k,J i k*(spinVariance y k*d k))- + (2*j/(n:ℝ))*magnetization y i*(∑ k,magnetization y k*spinVariance y k*d k) := by + simp only [Finset.mul_sum,← Finset.sum_add_distrib,← Finset.sum_sub_distrib] + apply Finset.sum_congr rfl + intro k _ + dsimp [fieldJacobian,hessianCore] + ring + rw [he] + simp only [ite_mul,one_mul,zero_mul,Finset.sum_ite_eq,Finset.mem_univ,ite_true] + dsimp [varianceLinear] + ring + ext i + simp only [Pi.sub_apply,Pi.add_apply,Pi.smul_apply,smul_eq_mul] + rw [hjac] + simp only [tapField,Pi.add_apply,onsager,varianceAverage,magnetizationRemainder,Pi.sub_apply, + Matrix.mulVec,dotProduct,mul_sub,Finset.sum_sub_distrib] + ring + +attribute [local irreducible] vectorNorm varianceAverage varianceLinear magnetizationRemainder tapField fieldJacobian magnetization + +theorem tap_remainder_norm {n : ℕ} (hn : 0 < n) {j K : ℝ} + (hj : 0 ≤ j) (hK : 0 ≤ K) (J : Matrix (Fin n) (Fin n) ℝ) + (hJ : ∀ z : Field n, vectorNorm (J*ᵥz) ≤ K*vectorNorm z) (h y d : Field n) : + vectorNorm (tapField j J h (y+d)-tapField j J h y-(fieldJacobian j J y)*ᵥd) ≤ + 2*(j+K)*sqrt (∑ i,d i^4)+(8*j/sqrt (n:ℝ))*vectorNorm d^2 := by + have hn0 : (0:ℝ) < n := by exact_mod_cast hn + have hsn : sqrt (n:ℝ) ≠ 0 := ne_of_gt (sqrt_pos.mpr hn0) + have hnd := vectorNorm_nonneg d + let rm := magnetizationRemainder y d + let rb := varianceAverage (y+d)-varianceAverage y-varianceLinear y d + let db := varianceAverage (y+d)-varianceAverage y + have hb := varianceAverage_bounds hn y + have h₁ : vectorNorm ((j*varianceAverage y) • rm) ≤ j*vectorNorm rm := by + change vectorNorm (fun i => (j*varianceAverage y)*rm i) ≤ _ + rw [vectorNorm_smul,abs_of_nonneg (mul_nonneg hj hb.1)] + exact mul_le_mul_of_nonneg_right (by nlinarith [hb.2]) (vectorNorm_nonneg _) + have h₂ : vectorNorm ((j*rb) • magnetization y) ≤ + (6*j/sqrt (n:ℝ))*vectorNorm d^2 := by + change vectorNorm (fun i => (j*rb)*magnetization y i) ≤ _ + rw [vectorNorm_smul,abs_mul,abs_of_nonneg hj] + calc + _ ≤ (j*(6/(n:ℝ)*vectorNorm d^2))*sqrt (n:ℝ) := + mul_le_mul (mul_le_mul_of_nonneg_left (varianceAverage_remainder hn y d) hj) + (magnetization_norm_bound y) (vectorNorm_nonneg _) (by positivity) + _ = _ := by field_simp; rw [Real.sq_sqrt hn0.le]; ring + have h₃ : vectorNorm ((j*db) • (magnetization (y+d)-magnetization y)) ≤ + (2*j/sqrt (n:ℝ))*vectorNorm d^2 := by + change vectorNorm (fun i => (j*db)*(magnetization (y+d)-magnetization y) i) ≤ _ + rw [vectorNorm_smul,abs_mul,abs_of_nonneg hj] + calc + _ ≤ (j*(2/sqrt (n:ℝ)*vectorNorm d))*vectorNorm d := + mul_le_mul (mul_le_mul_of_nonneg_left (varianceAverage_difference hn y d) hj) + (magnetization_difference_norm y d) (vectorNorm_nonneg _) (by positivity) + _ = _ := by ring + rw [tap_remainder_identity] + calc + _ ≤ (vectorNorm ((j*varianceAverage y) • rm)+vectorNorm ((j*rb) • magnetization y)+ + vectorNorm ((j*db) • (magnetization (y+d)-magnetization y)))+vectorNorm (J*ᵥrm) := by + exact (vectorNorm_sub_le _ _).trans + (add_le_add ((vectorNorm_add_le _ _).trans + (add_le_add (vectorNorm_add_le _ _) le_rfl)) le_rfl) + _ ≤ (j*vectorNorm rm+(6*j/sqrt (n:ℝ))*vectorNorm d^2+ + (2*j/sqrt (n:ℝ))*vectorNorm d^2)+K*vectorNorm rm := + add_le_add (add_le_add (add_le_add h₁ h₂) h₃) (hJ rm) + _ = (j+K)*vectorNorm rm+(8*j/sqrt (n:ℝ))*vectorNorm d^2 := by ring + _ ≤ (j+K)*(2*sqrt (∑ i,d i^4))+(8*j/sqrt (n:ℝ))*vectorNorm d^2 := + add_le_add (mul_le_mul_of_nonneg_left (magnetization_remainder_norm y d) (add_nonneg hj hK)) le_rfl + _ = _ := by ring + +end SKGap +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/TanhContDiff.lean b/lean/OAI/Probability/SKGap/Localization/TanhContDiff.lean new file mode 100644 index 0000000000000000000000000000000000000000..546fd008dfe1042c4539b50c8b3fc3052bdbe279 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/TanhContDiff.lean @@ -0,0 +1,284 @@ +import Mathlib +import OAI.Probability.SKGap.Stability.LawMean + +namespace OAI + +section +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open scoped BigOperators +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open scoped BigOperators +open scoped BigOperators NNReal ENNReal +open MeasureTheory Metric Set +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators NNReal ENNReal Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Set +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators ENNReal NNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Matrix +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators ENNReal NNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal +open scoped BigOperators +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise NNReal ENNReal +open scoped BigOperators +open Filter Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal Topology +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Set Matrix +open scoped BigOperators NNReal ENNReal Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open Filter MeasureTheory ProbabilityTheory +open scoped Topology NNReal ENNReal +open Filter MeasureTheory ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter +open scoped Topology NNReal ENNReal +open MeasureTheory Filter ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter +open scoped Topology +open MeasureTheory Filter ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter ProbabilityTheory ContinuousLinearMap +open scoped Topology NNReal ENNReal +open Filter MeasureTheory ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter +open scoped BigOperators Topology +open MeasureTheory Filter +open scoped BigOperators Topology +open MeasureTheory Filter +open scoped BigOperators Topology +open MeasureTheory Filter +open scoped BigOperators Topology +open MeasureTheory Filter +open scoped BigOperators Topology +open Filter Set Metric +open scoped Topology RealInnerProductSpace +open scoped BigOperators +open ContinuousLinearMap +open scoped BigOperators +open ContinuousLinearMap +open scoped Topology Interval +open MeasureTheory +open MeasureTheory +open scoped BigOperators Topology Interval +open MeasureTheory +open scoped BigOperators Topology Interval +open scoped Topology +open MeasureTheory +open scoped BigOperators Topology Interval +open scoped BigOperators Topology +open MeasureTheory +open scoped BigOperators Topology Interval RealInnerProductSpace +namespace SKGapCutoff + +lemma tanh_contDiff : ContDiff ℝ ⊤ Real.tanh := by + have hh : ContDiff ℝ ⊤ (fun x : ℝ => Real.sinh x/Real.cosh x) := + Real.contDiff_sinh.div Real.contDiff_cosh (fun x => (Real.cosh_pos x).ne') + simpa only [← Real.tanh_eq_sinh_div_cosh] using hh + +lemma parameter_refresh_contDiff {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] + {n : ℕ} (H : VectorFields n) (B : E →L[ℝ] VectorFields n) (h : ℝ) : + ContDiff ℝ ⊤ (fun z : E => refreshSemigroup (fun x i => Real.tanh (H x i+B z x i)) h) := by + have hm : ContDiff ℝ ⊤ (fun z : E => (fun x i => Real.tanh (H x i+B z x i) : VectorFields n)) := by + apply contDiff_pi.mpr + intro x + apply contDiff_pi.mpr + intro i + apply tanh_contDiff.comp + exact contDiff_const.add (contDiff_pi.mp (contDiff_pi.mp B.contDiff x) i) + have hg : ContDiff ℝ ⊤ (fun z : E => refreshGeneratorCLM (fun x i => Real.tanh (H x i+B z x i))) := by + have hh := ((meanGeneratorMap n).contDiff.comp hm).add (contDiff_const (c := refreshGeneratorCLM 0)) + convert hh using 1 + funext z + exact refreshGeneratorCLM_eq_mean _ + exact algebra_exp_contDiff.comp (hg.const_smul h) + +lemma parameter_preparation_contDiff {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] + {n : ℕ} (J : Interaction n) (B : E →L[ℝ] VectorFields n) (h : ℝ) : + ContDiff ℝ ⊤ (fun z : E => preparationFlow J (B z) h) := by + simp_rw [← refreshSemigroup_eq_preparationFlow] + exact parameter_refresh_contDiff (field J) B h + +lemma parameter_preparationLaw_contDiff {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] + {n : ℕ} (J : Interaction n) (B : E →L[ℝ] VectorFields n) (h : ℝ) : + ContDiff ℝ ⊤ (fun z : E => preparationLaw J (B z) h) := by + apply contDiff_pi.mpr + intro y + unfold preparationLaw pushLaw + apply ContDiff.sum + intro x _ + exact contDiff_const.mul (contDiff_pi.mp + ((parameter_preparation_contDiff J B h).clm_apply contDiff_const) x) + +lemma preparation_meanMap_contDiff {E F : Type*} + [NormedAddCommGroup E] [NormedSpace ℝ E] [NormedAddCommGroup F] [NormedSpace ℝ F] + {n : ℕ} (J : Interaction n) (B : E →L[ℝ] VectorFields n) (h t : ℝ) + (f : Spin n → F) : + ContDiff ℝ ⊤ (fun z : E => lawBarycenter + (pushLaw (semigroup J t) (preparationLaw J (B z) h)) f) := by + unfold lawBarycenter pushLaw + apply ContDiff.sum + intro y _ + apply ContDiff.smul _ contDiff_const + apply ContDiff.sum + intro x _ + exact (contDiff_pi.mp (parameter_preparationLaw_contDiff J B h) x).mul contDiff_const + +lemma lawBarycenter_inner {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] + {n : ℕ} (p : Spin n → ℝ) (F : Spin n → E) (u : E) : + ⟪u, lawBarycenter p F⟫ = lawMean p (fun x => ⟪u,F x⟫) := by + simp [lawBarycenter, lawMean, inner_sum, inner_smul_right] + +theorem preparation_meanMap_jacobian {E : Type*} + [NormedAddCommGroup E] [InnerProductSpace ℝ E] [FiniteDimensional ℝ E] + {n : ℕ} (J : Interaction n) (B : E →L[ℝ] VectorFields n) (h t : ℝ) + (F : Spin n → E) (z w u : E) : + ⟪u, fderiv ℝ (fun z : E => lawBarycenter + (pushLaw (semigroup J t) (preparationLaw J (B z) h)) F) z w⟫ = + ∫ s in 0..h, gibbsExpectation J (preparationFlow J (B z) s + (fun x => ∑ i, scalarVariance (field J x i+B z x i)*B w x i* + halfDiff i (preparationFlow J (B z) (h-s) + (semigroup J t (fun y => ⟪u,F y⟫))) x)) := by + let M : E → E := fun z => lawBarycenter + (pushLaw (semigroup J t) (preparationLaw J (B z) h)) F + have hd := (preparation_meanMap_contDiff J B h t F).differentiable (by simp) z + have hline : HasDerivAt (fun θ : ℝ => z+θ • w) w 0 := by + simpa using ((hasDerivAt_id (0:ℝ)).smul_const w).const_add z + have hf : HasFDerivAt M (fderiv ℝ M z) (z+(0:ℝ) • w) := by simpa only [zero_smul,add_zero] using hd.hasFDerivAt + have hm := hf.comp_hasDerivAt 0 hline + have hu := (hasDerivAt_const (0:ℝ) u).inner ℝ hm + simp only [inner_zero_left,add_zero] at hu + have he : (fun θ : ℝ => ⟪u,M (z+θ • w)⟫) = fun θ : ℝ => + gibbsExpectation J (preparationFlow J (fun x i => B z x i+θ*B w x i) h + (semigroup J t (fun y => ⟪u,F y⟫))) := by + funext θ + dsimp only [M] + rw [lawBarycenter_inner,lawMean_pushLaw,lawMean_preparationLaw] + congr 3 + ext x i + simp + change HasDerivAt (fun θ : ℝ => ⟪u,M (z+θ • w)⟫) _ 0 at hu + rw [he] at hu + have hc := preparation_expectation_hasDerivAt J (B z) (B w) 0 h + (semigroup J t (fun y => ⟪u,F y⟫)) + simp only [zero_mul,add_zero] at hc + exact hu.unique hc + +lemma preparation_conorm_of_alignment {E : Type*} + [NormedAddCommGroup E] [InnerProductSpace ℝ E] [CompleteSpace E] + (A : E →L[ℝ] E) (h c ε : ℝ) (hh : 0≤h) (he : ε≤1) + (halign : ∀ u : E, ∃ v : E, c*‖u‖≤‖v‖ ∧ + ‖A.adjoint u-h • v‖ ≤ h*ε*‖v‖) : + ∀ u : E, (h*(1-ε)*c)*‖u‖ ≤ ‖A.adjoint u‖ := by + intro u + obtain ⟨v,hv,herr⟩ := halign u + have htri : ‖h • v‖ ≤ ‖A.adjoint u-h • v‖+‖A.adjoint u‖ := by + calc + _ = ‖A.adjoint u-(A.adjoint u-h • v)‖ := by congr 1; abel + _ ≤ ‖A.adjoint u‖+‖A.adjoint u-h • v‖ := norm_sub_le _ _ + _ = _ := add_comm _ _ + rw [norm_smul,Real.norm_eq_abs,abs_of_nonneg hh] at htri + have hlow : h*(1-ε)*‖v‖≤‖A.adjoint u‖ := by nlinarith only [htri,herr] + have hm := mul_le_mul_of_nonneg_left hv (mul_nonneg hh (sub_nonneg.mpr he)) + nlinarith only [hlow,hm] + +end SKGapCutoff + +open MeasureTheory Filter +open scoped BigOperators Topology Interval + +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/TanhCubic.lean b/lean/OAI/Probability/SKGap/Localization/TanhCubic.lean new file mode 100644 index 0000000000000000000000000000000000000000..c9a2de628e1b0faa17e8ed68ef0b315ee97e4454 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/TanhCubic.lean @@ -0,0 +1,38 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.TAPScalarTaylor + +namespace OAI + +section +noncomputable section +namespace SKGap +open Real Set + +lemma abs_tanh_le_abs (x : ℝ) : |tanh x| ≤ |x| := by + simpa only [tanh_zero,sub_zero] using tanh_lipschitz_abs x 0 + +lemma tanh_cubic_error (x : ℝ) : |tanh x-x| ≤ |x|^3/3 := by + let f : ℝ→ℝ := fun y=>y^3/3-y+tanh y + have hd (y : ℝ) : HasDerivAt f (y^2-tanh y^2) y := by + dsimp [f] + convert! ((((hasDerivAt_id y).pow 3).div_const 3).sub (hasDerivAt_id y)).add (hasDerivAt_tanh y) using 1; simp only [id_eq]; ring + have hm : Monotone f := monotone_of_deriv_nonneg (fun y=>(hd y).differentiableAt) (fun y=>by + rw [(hd y).deriv] + have hs := (sq_le_sq₀ (abs_nonneg _) (abs_nonneg _)).mpr (abs_tanh_le_abs y) + simpa only [sq_abs,sub_nonneg] using hs) + have hp (y : ℝ) (hy : 0 ≤ y) : |tanh y-y| ≤ |y|^3/3 := by + have h := hm hy + have ht : tanh y ≤ y := (le_abs_self _).trans ((abs_tanh_le_abs y).trans_eq (abs_of_nonneg hy)) + rw [abs_of_nonpos (sub_nonpos.mpr ht),abs_of_nonneg hy] + simp only [f,tanh_zero,zero_pow (by decide : (3:ℕ) ≠ 0),zero_div,sub_zero,zero_add] at h + linarith only [h] + rcases le_or_gt 0 x with hx | hx + · exact hp x hx + · have h := hp (-x) (by linarith) + simpa only [tanh_neg,neg_sub_neg,abs_sub_comm,abs_neg] using h +end SKGap + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/TapPotential.lean b/lean/OAI/Probability/SKGap/Localization/TapPotential.lean new file mode 100644 index 0000000000000000000000000000000000000000..8f2ccdf9e510b871634af82487c21ee8633dcf89 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/TapPotential.lean @@ -0,0 +1,422 @@ +import Mathlib +import OAI.Probability.SKGap.Stability.StableFields + +namespace OAI + +section + +noncomputable section +open scoped BigOperators +open Real Matrix Set Filter Function +open scoped Topology +namespace SKGap + +def tapPotential {n : ℕ} (j : ℝ) (J : Matrix (Fin n) (Fin n) ℝ) + (h y : Field n) : ℝ := + (∑ i, (y i * magnetization y i - log (cosh (y i)))) - + (∑ i, h i * magnetization y i) - + (1/2:ℝ) * quadraticForm J (magnetization y) + + (j/2) * vectorSqNorm (magnetization y) - + (j/(4*n)) * vectorSqNorm (magnetization y)^2 + +def weightedTap {n : ℕ} (j : ℝ) (J : Matrix (Fin n) (Fin n) ℝ) + (h y : Field n) : Field n := fun i => spinVariance y i * tapField j J h y i + +lemma singlePotential_hasDerivAt (x : ℝ) : + HasDerivAt (fun z : ℝ => z * tanh z - log (cosh z)) + (x*(1-tanh x^2)) x := by + have hc : cosh x ≠ 0 := (cosh_pos x).ne' + convert! ((hasDerivAt_id x).mul (hasDerivAt_tanh x)).sub + ((hasDerivAt_cosh x).log hc) using 1 + simp only [id_eq, one_mul, tanh_eq_sinh_div_cosh] + ring + +lemma quadraticForm_derivative_algebra {n : ℕ} {J : Matrix (Fin n) (Fin n) ℝ} + (hJ : J.IsSymm) (m w : Field n) : + (∑ i, ∑ k, (w i * J i k * m k + m i * J i k * w k)) = + 2 * ∑ i, w i * (∑ k, J i k * m k) := by + simp only [Finset.sum_add_distrib] + have he : (∑ i, ∑ k, m i * J i k * w k) = ∑ i, ∑ k, w i * J i k * m k := by + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro i _ + apply Finset.sum_congr rfl + intro k _ + rw [hJ.apply k i] + ring + rw [he] + simp only [← Finset.mul_sum, mul_assoc] + ring + +lemma quadratic_magnetization_hasFDerivAt {n : ℕ} {J : Matrix (Fin n) (Fin n) ℝ} + (hJ : J.IsSymm) (y : Field n) : + HasFDerivAt (fun z => quadraticForm J (magnetization z)) + (2 • ∑ i, (spinVariance y i * (∑ k, J i k * magnetization y k)) • + (ContinuousLinearMap.proj i : Field n →L[ℝ] ℝ)) y := by + have hd := HasFDerivAt.sum (u := Finset.univ) (fun i _ => + HasFDerivAt.sum (u := Finset.univ) (fun k _ => + ((magnetization_hasFDerivAt y i).mul_const (J i k)).mul + (magnetization_hasFDerivAt y k))) + convert! hd using 1 + · ext z + simp only [quadraticForm, Finset.sum_apply, Pi.mul_apply] + ext v + simp only [_root_.smul_apply, _root_.sum_apply, _root_.add_apply, + ContinuousLinearMap.proj_apply, smul_eq_mul, nsmul_eq_mul] + have he := quadraticForm_derivative_algebra hJ (magnetization y) + (fun i => spinVariance y i * v i) + calc + _ = 2 * ∑ i, (spinVariance y i * v i) * (∑ k, J i k * magnetization y k) := by + congr 1 + apply Finset.sum_congr rfl + intro i _ + ring + _ = ∑ i, ∑ k, ((spinVariance y i * v i) * J i k * magnetization y k + + magnetization y i * J i k * (spinVariance y k * v k)) := he.symm + _ = _ := by + apply Finset.sum_congr rfl + intro i _ + apply Finset.sum_congr rfl + intro k _ + ring + +lemma squared_magnetization_hasFDerivAt {n : ℕ} (y : Field n) : + HasFDerivAt (fun z => vectorSqNorm (magnetization z)) + (∑ i, (2*magnetization y i*spinVariance y i) • + (ContinuousLinearMap.proj i : Field n →L[ℝ] ℝ)) y := by + convert! (HasFDerivAt.sum (u := Finset.univ) + (fun i _ => (magnetization_hasFDerivAt y i).pow 2)) using 1 + · ext z + simp only [vectorSqNorm, Finset.sum_apply] + ext v + simp only [_root_.sum_apply, _root_.smul_apply, ContinuousLinearMap.proj_apply, + smul_eq_mul, Nat.reduceSub, pow_one] + apply Finset.sum_congr rfl + intro i _ + ring + +lemma tapPotential_hasFDerivAt {n : ℕ} (j : ℝ) + {J : Matrix (Fin n) (Fin n) ℝ} (hJ : J.IsSymm) (h y : Field n) : + HasFDerivAt (tapPotential j J h) + (∑ i, weightedTap j J h y i • + (ContinuousLinearMap.proj i : Field n →L[ℝ] ℝ)) y := by + have hsinglei (i : Fin n) : + HasFDerivAt (fun z : Field n => z i * tanh (z i) - log (cosh (z i))) + ((y i*(1-tanh (y i)^2)) • (ContinuousLinearMap.proj i : Field n →L[ℝ] ℝ)) y := by + have hd := ((hasFDerivAt_apply (𝕜 := ℝ) i y).mul + (magnetization_hasFDerivAt y i)).sub + (((hasFDerivAt_apply (𝕜 := ℝ) i y).cosh).log (cosh_pos (y i)).ne') + convert! hd using 1 + ext v + simp only [_root_.smul_apply, _root_.sub_apply, _root_.add_apply, + ContinuousLinearMap.proj_apply, smul_eq_mul, spinVariance, magnetization, + tanh_eq_sinh_div_cosh] + ring + have hsingle := HasFDerivAt.sum (u := Finset.univ) (fun i _ => hsinglei i) + have hext := HasFDerivAt.sum (u := Finset.univ) (fun i _ => + (magnetization_hasFDerivAt y i).const_mul (h i)) + have hquad := (quadratic_magnetization_hasFDerivAt hJ y).const_mul (1/2:ℝ) + have hsq := (squared_magnetization_hasFDerivAt y).const_mul (j/2) + have hfour := ((squared_magnetization_hasFDerivAt y).pow 2).const_mul (j/(4*n)) + convert! (((hsingle.sub hext).sub hquad).add hsq).sub hfour using 1 + · ext z + simp only [tapPotential, Finset.sum_apply, Pi.sub_apply, Pi.add_apply, magnetization] + ext v + simp only [_root_.sum_apply, _root_.smul_apply, _root_.sub_apply, _root_.add_apply, + ContinuousLinearMap.proj_apply, smul_eq_mul, nsmul_eq_mul, + Nat.cast_ofNat, Nat.reduceSub, pow_one] + simp only [weightedTap, tapField, onsager, overlap, vectorSqNorm, spinVariance, + magnetization] + simp only [Finset.mul_sum, Finset.sum_mul, ← Finset.sum_sub_distrib, + ← Finset.sum_add_distrib] + apply Finset.sum_congr rfl + intro i _ + simp only [← Finset.mul_sum, ← Finset.sum_mul] + ring + +lemma contDiff_tanh_SK {m : WithTop ℕ∞} : ContDiff ℝ m tanh := by + have he : tanh = sinh / cosh := funext tanh_eq_sinh_div_cosh + rw [he] + exact contDiff_sinh.div contDiff_cosh (fun x => (cosh_pos x).ne') + +lemma magnetization_contDiff {n : ℕ} {m : WithTop ℕ∞} (i : Fin n) : + ContDiff ℝ m (fun y : Field n => magnetization y i) := + contDiff_tanh_SK.comp (contDiff_apply ℝ ℝ i) + +lemma spinVariance_contDiff {n : ℕ} {m : WithTop ℕ∞} (i : Fin n) : + ContDiff ℝ m (fun y : Field n => spinVariance y i) := + contDiff_const.sub ((magnetization_contDiff i).pow 2) + +lemma overlap_contDiff {n : ℕ} {m : WithTop ℕ∞} : + ContDiff ℝ m (overlap (n := n)) := + (ContDiff.sum (fun i _ => (magnetization_contDiff i).pow 2)).div_const _ + +lemma tapField_contDiff {n : ℕ} {m : WithTop ℕ∞} (j : ℝ) + (J : Matrix (Fin n) (Fin n) ℝ) (h : Field n) : ContDiff ℝ m (tapField j J h) := by + apply contDiff_pi.mpr + intro i + exact ((contDiff_apply ℝ ℝ i).sub contDiff_const).add + ((contDiff_const.mul (contDiff_const.sub overlap_contDiff)).mul + (magnetization_contDiff i)) |>.sub + (ContDiff.sum (fun k _ => contDiff_const.mul (magnetization_contDiff k))) + +lemma weightedTap_contDiff {n : ℕ} {m : WithTop ℕ∞} (j : ℝ) + (J : Matrix (Fin n) (Fin n) ℝ) (h : Field n) : ContDiff ℝ m (weightedTap j J h) := by + apply contDiff_pi.mpr + intro i + exact (spinVariance_contDiff i).mul (contDiff_pi.mp (tapField_contDiff j J h) i) + +abbrev EField (n : ℕ) := EuclideanSpace ℝ (Fin n) + +def tapPotentialE {n : ℕ} (j : ℝ) (J : Matrix (Fin n) (Fin n) ℝ) + (h : Field n) (y : EField n) : ℝ := tapPotential j J h (WithLp.ofLp y) + +def weightedTapE {n : ℕ} (j : ℝ) (J : Matrix (Fin n) (Fin n) ℝ) + (h : Field n) (y : EField n) : EField n := + WithLp.toLp 2 (weightedTap j J h (WithLp.ofLp y)) + +lemma weightedTapE_contDiff {n : ℕ} {m : WithTop ℕ∞} (j : ℝ) + (J : Matrix (Fin n) (Fin n) ℝ) (h : Field n) : ContDiff ℝ m (weightedTapE j J h) := + (EuclideanSpace.equiv (ι := Fin n) (𝕜 := ℝ)).symm.contDiff.comp + ((weightedTap_contDiff j J h).comp + (EuclideanSpace.equiv (ι := Fin n) (𝕜 := ℝ)).contDiff) + +lemma tapPotentialE_hasFDerivAt {n : ℕ} (j : ℝ) + {J : Matrix (Fin n) (Fin n) ℝ} (hJ : J.IsSymm) (h : Field n) (y : EField n) : + HasFDerivAt (tapPotentialE j J h) (innerSL ℝ (weightedTapE j J h y)) y := by + have hd := (tapPotential_hasFDerivAt j hJ h (WithLp.ofLp y)).comp y + (EuclideanSpace.equiv (ι := Fin n) (𝕜 := ℝ)).hasFDerivAt + convert! hd using 1 + ext v + simp only [innerSL_apply_apply, weightedTapE, PiLp.inner_apply, RCLike.inner_apply, + conj_trivial, ContinuousLinearMap.comp_apply, + _root_.sum_apply, _root_.smul_apply, ContinuousLinearMap.proj_apply, smul_eq_mul] + apply Finset.sum_congr rfl + intro i _ + change v i * weightedTap j J h (WithLp.ofLp y) i = + weightedTap j J h (WithLp.ofLp y) i * v i + ring + +def weightedJacobianMap {n : ℕ} (j : ℝ) (J : Matrix (Fin n) (Fin n) ℝ) + (y : Field n) : Field n →L[ℝ] Field n := + ContinuousLinearMap.pi (fun i => spinVariance y i • + ((ContinuousLinearMap.proj i : Field n →L[ℝ] ℝ).comp + (fieldJacobian j J y).mulVecLin.toContinuousLinearMap)) + +lemma weightedTap_hasFDerivAt_zero {n : ℕ} (j : ℝ) + (J : Matrix (Fin n) (Fin n) ℝ) (h y : Field n) + (hz : tapField j J h y = 0) : + HasFDerivAt (weightedTap j J h) (weightedJacobianMap j J y) y := by + rw [hasFDerivAt_pi'] + intro i + have hV := ((spinVariance_contDiff i (m := 1)).differentiable (by norm_num) y).hasFDerivAt + have hF := hasFDerivAt_pi'.mp (tapField_hasFDerivAt j J h y) i + have hzi : tapField j J h y i = 0 := congrFun hz i + have hd := hV.mul hF + simp only [hzi, zero_smul, add_zero] at hd + convert! hd using 1 + +lemma weightedTapE_fderiv_zero {n : ℕ} (j : ℝ) + (J : Matrix (Fin n) (Fin n) ℝ) (h : Field n) (y v : EField n) + (hz : tapField j J h (WithLp.ofLp y) = 0) (i : Fin n) : + (fderiv ℝ (weightedTapE j J h) y v) i = + spinVariance (WithLp.ofLp y) i * + ((fieldJacobian j J (WithLp.ofLp y)).mulVec (WithLp.ofLp v)) i := by + let e := EuclideanSpace.equiv (ι := Fin n) (𝕜 := ℝ) + have hd := e.symm.hasFDerivAt.comp y + ((weightedTap_hasFDerivAt_zero j J h (WithLp.ofLp y) hz).comp y e.hasFDerivAt) + have he : fderiv ℝ (weightedTapE j J h) y = + e.symm.toContinuousLinearMap.comp ((weightedJacobianMap j J (WithLp.ofLp y)).comp + e.toContinuousLinearMap) := hd.fderiv + rw [he] + rfl + +lemma weighted_jacobian_quadratic_form {n : ℕ} (j : ℝ) + (J : Matrix (Fin n) (Fin n) ℝ) (y v : Field n) : + (∑ i, v i * (spinVariance y i * ((fieldJacobian j J y).mulVec v) i)) = + quadraticForm (fieldHessian j J y (spinVariance y)) (sqrtVarianceMul y v) := by + simp only [Matrix.mulVec, dotProduct, quadraticForm, sqrtVarianceMul, + Finset.mul_sum] + apply Finset.sum_congr rfl + intro i _ + apply Finset.sum_congr rfl + intro k _ + have hi := sq_sqrt (spinVariance_pos y i).le + calc + _ = (sqrt (spinVariance y i) * v i) * + (sqrt (spinVariance y i)*fieldJacobian j J y i k) * v k := by + conv_lhs => rw [← hi] + ring + _ = _ := by rw [← fieldHessian_variance_intertwine]; ring + +lemma weightedTapE_derivative_energy {n : ℕ} (j : ℝ) + (J : Matrix (Fin n) (Fin n) ℝ) (h : Field n) (y v : EField n) + (hz : tapField j J h (WithLp.ofLp y) = 0) : + inner ℝ v (fderiv ℝ (weightedTapE j J h) y v) = + quadraticForm (fieldHessian j J (WithLp.ofLp y) (spinVariance (WithLp.ofLp y))) + (sqrtVarianceMul (WithLp.ofLp y) (WithLp.ofLp v)) := by + rw [← weighted_jacobian_quadratic_form] + simp only [PiLp.inner_apply, RCLike.inner_apply, conj_trivial] + apply Finset.sum_congr rfl + intro i _ + rw [weightedTapE_fderiv_zero j J h y v hz i] + ring + +lemma spinVariance_eq_inv_cosh_sq {n : ℕ} (y : Field n) (i : Fin n) : + spinVariance y i = 1 / cosh (y i)^2 := by + simp only [spinVariance, magnetization, tanh_eq_sinh_div_cosh] + field_simp + exact cosh_sq_sub_sinh_sq _ + +lemma spinVariance_bound_on_box {n : ℕ} (y : Field n) {R : ℝ} (hR : 0 ≤ R) + (hy : ∀ i, |y i| ≤ R) (i : Fin n) : + 1 / cosh R^2 ≤ spinVariance y i := by + rw [spinVariance_eq_inv_cosh_sq] + apply one_div_le_one_div_of_le (sq_pos_of_pos (cosh_pos (y i))) + have h : cosh (y i) ≤ cosh R := cosh_le_cosh.mpr + (by simpa only [abs_of_nonneg hR] using hy i) + exact pow_le_pow_left₀ (cosh_pos (y i)).le h 2 + +lemma tapField_shift_bound {n : ℕ} (hn : 0 < n) {j : ℝ} (hj : 0 ≤ j) + (J : Matrix (Fin n) (Fin n) ℝ) (h y : Field n) (i : Fin n) : + |y i - tapField j J h y i| ≤ |h i| + j + ∑ k, |J i k| := by + have hm (k : Fin n) : |magnetization y k| ≤ 1 := by + exact (abs_lt.mpr ⟨neg_one_lt_tanh _, tanh_lt_one _⟩).le + have hB0 : 0 ≤ onsager j y := mul_nonneg hj (sub_nonneg.mpr (overlap_lt_one hn y).le) + have hBj : onsager j y ≤ j := by + dsimp [onsager] + nlinarith [overlap_nonneg y] + have hBm : |onsager j y * magnetization y i| ≤ j := by + rw [abs_mul, abs_of_nonneg hB0] + exact (mul_le_of_le_one_right hB0 (hm i)).trans hBj + have hJm : |∑ k, J i k * magnetization y k| ≤ ∑ k, |J i k| := by + exact (Finset.abs_sum_le_sum_abs _ _).trans (Finset.sum_le_sum fun k _ => by + rw [abs_mul] + exact mul_le_of_le_one_right (abs_nonneg _) (hm k)) + have he : y i-tapField j J h y i = h i-onsager j y*magnetization y i + + ∑ k, J i k*magnetization y k := by simp only [tapField]; ring + rw [he] + have hs : |h i-onsager j y*magnetization y i| ≤ |h i|+j := by + calc + _ ≤ |h i|+|onsager j y*magnetization y i| := by + simpa only [sub_eq_add_neg, abs_neg] using + abs_add_le (h i) (-(onsager j y*magnetization y i)) + _ ≤ _ := add_le_add_right hBm _ + exact (abs_add_le _ _).trans (add_le_add hs hJm) + +lemma exists_tapBox_radius {n : ℕ} (hn : 0 < n) {j : ℝ} (hj : 0 ≤ j) + (J : Matrix (Fin n) (Fin n) ℝ) (h : Field n) : + ∃ R : ℝ, 0 < R ∧ ∀ y : Field n, ∀ i, |y i-tapField j J h y i| ≤ R := by + let b := fun i => |h i| + j + ∑ k, |J i k| + have hb (i : Fin n) : 0 ≤ b i := by dsimp [b]; positivity + refine ⟨1+∑ i, b i, by positivity, fun y i => ?_⟩ + exact (tapField_shift_bound hn hj J h y i).trans + ((Finset.single_le_sum (fun k _ => hb k) (Finset.mem_univ i)).trans (by linarith)) + +lemma weightedTap_step_box {n : ℕ} (j : ℝ) (J : Matrix (Fin n) (Fin n) ℝ) + (h y : Field n) {R ε : ℝ} (hε : ε ∈ Set.Icc (0:ℝ) 1) + (hbound : ∀ i, |y i-tapField j J h y i| ≤ R) (hy : ∀ i, |y i| ≤ R) : + ∀ i, |(y-ε • weightedTap j J h y) i| ≤ R := by + intro i + let a := ε*spinVariance y i + have ha0 : 0 ≤ a := mul_nonneg hε.1 (spinVariance_pos y i).le + have ha1 : a ≤ 1 := (mul_le_mul_of_nonneg_left (spinVariance_le_one y i) hε.1).trans + (by simpa using hε.2) + have he : (y-ε • weightedTap j J h y) i = + (1-a)*y i + a*(y i-tapField j J h y i) := by + simp only [Pi.sub_apply, Pi.smul_apply, smul_eq_mul, weightedTap, a] + ring + rw [he] + calc + _ ≤ |(1-a)*y i| + |a*(y i-tapField j J h y i)| := abs_add_le _ _ + _ = (1-a)*|y i| + a*|y i-tapField j J h y i| := by + rw [abs_mul, abs_mul, abs_of_nonneg ha0, abs_of_nonneg (sub_nonneg.mpr ha1)] + _ ≤ (1-a)*R+a*R := add_le_add + (mul_le_mul_of_nonneg_left (hy i) (sub_nonneg.mpr ha1)) + (mul_le_mul_of_nonneg_left (hbound i) ha0) + _ = R := by ring + +def fieldBoxE (n : ℕ) (R : ℝ) : Set (EField n) := + (EuclideanSpace.equiv (ι := Fin n) (𝕜 := ℝ)).symm '' Metric.closedBall (0:Field n) R + +lemma mem_fieldBoxE {n : ℕ} {R : ℝ} (hR : 0 ≤ R) (y : EField n) : + y ∈ fieldBoxE n R ↔ ∀ i, |y i| ≤ R := by + simp only [fieldBoxE, Set.mem_image] + constructor + · rintro ⟨x, hx, rfl⟩ + have hn : ‖x‖ ≤ R := by simpa only [Metric.mem_closedBall, dist_zero_right] using hx + change ∀ i, |x i| ≤ R + simpa only [Real.norm_eq_abs] using (pi_norm_le_iff_of_nonneg hR).mp hn + · intro hy + refine ⟨WithLp.ofLp y, ?_, rfl⟩ + rw [Metric.mem_closedBall, dist_zero_right, pi_norm_le_iff_of_nonneg hR] + exact hy + +lemma isCompact_fieldBoxE (n : ℕ) (R : ℝ) : IsCompact (fieldBoxE n R) := + (isCompact_closedBall (0:Field n) R).image + (EuclideanSpace.equiv (ι := Fin n) (𝕜 := ℝ)).symm.continuous + +lemma convex_fieldBoxE (n : ℕ) (R : ℝ) : Convex ℝ (fieldBoxE n R) := + (convex_closedBall (0:Field n) R).linear_image + (EuclideanSpace.equiv (ι := Fin n) (𝕜 := ℝ)).symm.toLinearMap + +lemma nonempty_fieldBoxE (n : ℕ) {R : ℝ} (hR : 0 ≤ R) : (fieldBoxE n R).Nonempty := + ⟨0, (mem_fieldBoxE hR 0).mpr (fun _ => by simpa using hR)⟩ + +theorem lyapunov_eventually_hits {X : Type*} [TopologicalSpace X] [CompactSpace X] + (T : X → X) (hT : Continuous T) (φ : X → ℝ) (hφ : Continuous φ) + (hstrict : ∀ x, T x ≠ x → φ (T x) < φ x) + {U : Set X} (hU : IsOpen U) (hfix : ∀ x, T x = x → x ∈ U) (x : X) : + ∃ n : ℕ, T^[n] x ∈ U := by + by_contra! hnever + have hK : IsCompact Uᶜ := hU.isClosed_compl.isCompact + have hne : Uᶜ.Nonempty := ⟨x, by simpa using hnever 0⟩ + obtain ⟨y, hy, hmin⟩ := hK.exists_isMinOn hne (hφ.sub (hφ.comp hT)).continuousOn + let δ := φ y - φ (T y) + have hd : 0 < δ := sub_pos.mpr (hstrict y (fun h => hy (hfix y h))) + have hdec (n : ℕ) : δ ≤ φ (T^[n] x) - φ (T (T^[n] x)) := + hmin (hnever n) + obtain ⟨m, hm⟩ := isCompact_univ.bddBelow_image hφ.continuousOn + have hlower (z : X) : m ≤ φ z := hm ⟨z, mem_univ _, rfl⟩ + have hbound (n : ℕ) : φ (T^[n] x) ≤ φ x - (n:ℝ)*δ := by + induction n with + | zero => simp + | succ n ih => + rw [iterate_succ_apply'] + have h := hdec n + push_cast + nlinarith + obtain ⟨n, hn⟩ := exists_nat_gt ((φ x - m)/δ) + have hn' : φ x - m < (n:ℝ)*δ := (div_lt_iff₀ hd).mp hn + have hb := hbound n + have hl := hlower (T^[n] x) + linarith + +theorem lyapunov_fixed_point {X : Type*} [TopologicalSpace X] [CompactSpace X] + [Nonempty X] (T : X → X) (φ : X → ℝ) (hφ : Continuous φ) + (hstrict : ∀ x, T x ≠ x → φ (T x) < φ x) : ∃ x, T x = x := by + obtain ⟨x, _, hx⟩ := isCompact_univ.exists_isMinOn univ_nonempty hφ.continuousOn + refine ⟨x, by_contra fun h => ?_⟩ + exact (not_lt_of_ge (hx (mem_univ (T x)))) (hstrict x h) + +section Basins +variable {X : Type*} [TopologicalSpace X] (T : X → X) + +def attractionBasin (p : X) : Set X := + {x | Tendsto (fun n : ℕ => T^[n] x) atTop (𝓝 p)} + +lemma mem_attractionBasin_iterate_iff (p x : X) (k : ℕ) : + T^[k] x ∈ attractionBasin T p ↔ x ∈ attractionBasin T p := by + simpa only [attractionBasin, mem_ofPred_eq, iterate_add_apply] using + (tendsto_add_atTop_iff_nat (f := fun n : ℕ => T^[n] x) (l := 𝓝 p) k) + +lemma fixed_mem_attractionBasin {p : X} (hp : T p = p) : p ∈ attractionBasin T p := by + simp only [attractionBasin, mem_ofPred_eq, iterate_fixed hp] + exact tendsto_const_nhds + +end Basins +end SKGap +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/TargetAttempt.lean b/lean/OAI/Probability/SKGap/Localization/TargetAttempt.lean new file mode 100644 index 0000000000000000000000000000000000000000..19581dc49cb0caa4d3800f76b4fc398c41fd1205 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/TargetAttempt.lean @@ -0,0 +1,336 @@ +import Mathlib +import OAI.Probability.SKGap.Stability.FieldSquareSum + +namespace OAI + +section +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open scoped BigOperators +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open scoped BigOperators +open scoped BigOperators NNReal ENNReal +open MeasureTheory Metric Set +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators NNReal ENNReal Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Set +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators ENNReal NNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Matrix +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators ENNReal NNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal +open scoped BigOperators +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise NNReal ENNReal +open scoped BigOperators +open Filter Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal Topology +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Set Matrix +open scoped BigOperators NNReal ENNReal Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open Filter MeasureTheory ProbabilityTheory +open scoped Topology NNReal ENNReal +open Filter MeasureTheory ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter +open scoped Topology NNReal ENNReal +open MeasureTheory Filter ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter +open scoped Topology +open MeasureTheory Filter ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter ProbabilityTheory ContinuousLinearMap +open scoped Topology NNReal ENNReal +open Filter MeasureTheory ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter +open scoped BigOperators Topology +open MeasureTheory Filter +open scoped BigOperators Topology +open MeasureTheory Filter +open scoped BigOperators Topology +open MeasureTheory Filter +open scoped BigOperators Topology +open MeasureTheory Filter +open scoped BigOperators Topology +open Filter Set Metric +open scoped Topology RealInnerProductSpace +open scoped BigOperators +open ContinuousLinearMap +namespace SKGapCutoff + +noncomputable def targetAttempt {n : ℕ} (m : Spin n → Fin n → ℝ) : + Observables n →L[ℝ] Observables n := + ({ toFun := fun f x => (n:ℝ)⁻¹ * ∑ i, + ((1+m x i)/2*f (replace x i true)+(1-m x i)/2*f (replace x i false)) + map_add' := by + intro f g; funext x + simp only [Pi.add_apply, mul_add, Finset.sum_add_distrib] + ring + map_smul' := by + intro a f; funext x + simp only [Pi.smul_apply, smul_eq_mul, RingHom.id_apply] + simp_rw [mul_left_comm _ a, ← mul_add, ← Finset.mul_sum] + ring } : Observables n →ₗ[ℝ] Observables n).toContinuousLinearMap + +lemma targetAttempt_nonneg {n : ℕ} (m : Spin n → Fin n → ℝ) + (hm : ∀ x i, |m x i| ≤ 1) (f : Observables n) (hf : ∀ x, 0 ≤ f x) : + ∀ x, 0 ≤ targetAttempt m f x := by + intro x + change 0 ≤ (n:ℝ)⁻¹ * _ + apply mul_nonneg (by positivity) + apply Finset.sum_nonneg + intro i _ + have hh := abs_le.mp (hm x i) + exact add_nonneg (mul_nonneg (by linarith) (hf _)) (mul_nonneg (by linarith) (hf _)) + +lemma targetAttempt_generator {n : ℕ} (hn : 0 < n) + (m : Spin n → Fin n → ℝ) (f : Observables n) (x : Spin n) : + (n:ℝ)*((targetAttempt m-1) f x) = ∑ i, (m x i-spin x i)*halfDiff i f x := by + have hn' : (n:ℝ) ≠ 0 := by exact_mod_cast hn.ne' + change (n:ℝ)*((n:ℝ)⁻¹*(∑ i, _)-f x) = _ + rw [mul_sub, ← mul_assoc, mul_inv_cancel₀ hn', one_mul] + have hh : (n:ℝ)*f x = ∑ _i : Fin n, f x := by simp + rw [hh, ← Finset.sum_sub_distrib] + apply Finset.sum_congr rfl + intro i _ + have hx := replace_self x i + cases hi : x i <;> simp only [hi] at hx + · simp only [spin, hi, Bool.false_eq_true, ↓reduceIte, halfDiff] + rw [hx]; ring + · simp only [spin, hi, ↓reduceIte, halfDiff] + rw [hx]; ring + +lemma targetAttempt_mean {n : ℕ} (hn : 0 < n) (J : Interaction n) : + targetAttempt (mean J) = attemptLM J := by + ext f x + rw [attempt_apply_of_pos hn] + change (n:ℝ)⁻¹ * (∑ i, siteRefresh J i f x) = _ + rw [div_eq_mul_inv, mul_comm] + +lemma logistic_shift_bound {a b s : ℝ} (hs : 0 ≤ s) (hb : -s ≤ b) : + 1/(1+Real.exp (a+b)) ≤ Real.exp s * (1/(1+Real.exp a)) := by + rw [mul_one_div, div_le_div_iff₀ (by positivity) (by positivity)] + have ha := Real.exp_le_exp.mpr (show a ≤ s+(a+b) by linarith) + rw [Real.exp_add s (a+b)] at ha + have h1 := Real.one_le_exp_iff.mpr hs + nlinarith + +lemma tanh_outcome_shift_bound {a b ε : ℝ} (hε : 0 ≤ ε) (hb : |b| ≤ ε) : + (1+Real.tanh (a+b))/2 ≤ Real.exp (2*ε)*((1+Real.tanh a)/2) ∧ + (1-Real.tanh (a+b))/2 ≤ Real.exp (2*ε)*((1-Real.tanh a)/2) := by + have hb' := abs_le.mp hb + constructor + · rw [one_add_tanh_half, one_add_tanh_half] + convert logistic_shift_bound (a := -2*a) (b := -2*b) + (s := 2*ε) (by positivity) (by linarith) using 1 + ring_nf + · rw [one_sub_tanh_half, one_sub_tanh_half] + convert logistic_shift_bound (a := 2*a) (b := 2*b) + (s := 2*ε) (by positivity) (by linarith) using 1 + ring_nf + +lemma targetAttempt_perturbed_le {n : ℕ} (hn : 0 < n) (J : Interaction n) + (g : Spin n → Fin n → ℝ) {ε : ℝ} (hε : 0 ≤ ε) (hg : ∀ x i, |g x i| ≤ ε) + (f : Observables n) (hf : ∀ x, 0 ≤ f x) (x : Spin n) : + targetAttempt (fun x i => Real.tanh (field J x i+g x i)) f x ≤ + Real.exp (2*ε)*attemptLM J f x := by + rw [attempt_apply_of_pos hn] + change (n:ℝ)⁻¹*(∑ i, _) ≤ _ + rw [div_eq_mul_inv, mul_comm (∑ i, siteRefresh J i f x), mul_left_comm] + apply mul_le_mul_of_nonneg_left _ (by positivity) + rw [Finset.mul_sum] + apply Finset.sum_le_sum + intro i _ + have h := tanh_outcome_shift_bound (a := field J x i) hε (hg x i) + dsimp [siteRefresh, mean] + calc + _ ≤ (Real.exp (2*ε)*((1+Real.tanh (field J x i))/2))*f (replace x i true) + + (Real.exp (2*ε)*((1-Real.tanh (field J x i))/2))*f (replace x i false) := + add_le_add (mul_le_mul_of_nonneg_right h.1 (hf _)) (mul_le_mul_of_nonneg_right h.2 (hf _)) + _ = _ := by ring + +lemma gibbsExpectation_attempt {n : ℕ} (J : Interaction n) + (hJ : ∀ i j, J i j = J j i) (hdiag : ∀ i, J i i = 0) (f : Observables n) : + gibbsExpectation J (attemptLM J f) = gibbsExpectation J f := by + have h := gibbs_generator_zero J hJ hdiag f + change expectationCLM J (f + (n:ℝ)⁻¹ • generatorCLM J f) = _ + rw [map_add, map_smul] + change gibbsExpectation J f + (n:ℝ)⁻¹ * gibbsExpectation J (generator J f) = _ + rw [h, mul_zero, add_zero] + +lemma expectation_pow_le {n : ℕ} (J : Interaction n) + (K : Observables n →L[ℝ] Observables n) {c : ℝ} (hc : 0 ≤ c) + (hK : ∀ f, (∀ x, 0 ≤ f x) → ∀ x, 0 ≤ K f x) + (hμ : ∀ f, (∀ x, 0 ≤ f x) → gibbsExpectation J (K f) ≤ c*gibbsExpectation J f) + (k : ℕ) (f : Observables n) (hf : ∀ x, 0 ≤ f x) : + gibbsExpectation J ((K^k) f) ≤ c^k*gibbsExpectation J f := by + have hp (j : ℕ) : ∀ x, 0 ≤ (K^j) f x := by + induction j with + | zero => simpa using hf + | succ j ih => simpa only [pow_succ', mul_apply_eq_comp] using hK _ ih + induction k with + | zero => simp + | succ k ih => + rw [pow_succ', mul_apply_eq_comp] + exact (hμ _ (hp k)).trans ((mul_le_mul_of_nonneg_left ih hc).trans_eq (by ring)) + +lemma exp_refresh_uniformization {n : ℕ} (K : Observables n →L[ℝ] Observables n) (r : ℝ) : + NormedSpace.exp (r • (K-1)) = Real.exp (-r) • NormedSpace.exp (r • K) := by + have h : r • (K-1) = (-r) • (1 : Observables n →L[ℝ] Observables n) + r • K := by module + let : NormedAlgebra ℚ (Observables n →L[ℝ] Observables n) := + NormedAlgebra.restrictScalars ℚ ℝ _ + rw [h, NormedSpace.exp_add_of_commute (((Commute.one_left K).smul_left _).smul_right _), + exp_smul_identity, smul_mul_assoc, one_mul] + +lemma gibbsExpectation_exp_refresh_le {n : ℕ} (J : Interaction n) + (K : Observables n →L[ℝ] Observables n) {c r : ℝ} (hc : 0 ≤ c) (hr : 0 ≤ r) + (hK : ∀ f, (∀ x, 0 ≤ f x) → ∀ x, 0 ≤ K f x) + (hμ : ∀ f, (∀ x, 0 ≤ f x) → gibbsExpectation J (K f) ≤ c*gibbsExpectation J f) + (f : Observables n) (hf : ∀ x, 0 ≤ f x) : + gibbsExpectation J (NormedSpace.exp (r • (K-1)) f) ≤ + Real.exp (r*(c-1))*gibbsExpectation J f := by + have hs := (expectationCLM J).hasSum (exp_apply_hasSum (r • K) f) + simp only [smul_pow, _root_.smul_apply, map_smul, smul_eq_mul, expectationCLM_apply] at hs + have ht := (NormedSpace.expSeries_div_hasSum_exp (r*c)).mul_right (gibbsExpectation J f) + rw [← Real.exp_eq_exp_ℝ] at ht + have hle : gibbsExpectation J (NormedSpace.exp (r • K) f) ≤ + Real.exp (r*c)*gibbsExpectation J f := by + apply hasSum_le _ hs ht + intro k + have h := mul_le_mul_of_nonneg_left (expectation_pow_le J K hc hK hμ k f hf) + (show 0 ≤ (k.factorial:ℝ)⁻¹ * r^k by positivity) + calc + _ = ((k.factorial:ℝ)⁻¹*r^k)*gibbsExpectation J ((K^k) f) := by ring + _ ≤ _ := h + _ = _ := by rw [mul_pow]; ring + rw [exp_refresh_uniformization, _root_.smul_apply] + change expectationCLM J (Real.exp (-r) • _) ≤ _ + rw [map_smul] + change Real.exp (-r)*gibbsExpectation J (NormedSpace.exp (r • K) f) ≤ _ + refine (mul_le_mul_of_nonneg_left hle (Real.exp_pos _).le).trans_eq ?_ + rw [← mul_assoc, ← Real.exp_add] + congr 2 + ring + +noncomputable def preparationFlow {n : ℕ} (J : Interaction n) + (g : Spin n → Fin n → ℝ) (t : ℝ) : Observables n →L[ℝ] Observables n := + NormedSpace.exp (((n:ℝ)*t) • + (targetAttempt (fun x i => Real.tanh (field J x i+g x i))-1)) + +lemma preparationFlow_density_bound {n : ℕ} (hn : 0 < n) (J : Interaction n) + (hJ : ∀ i j, J i j = J j i) (hdiag : ∀ i, J i i = 0) + (g : Spin n → Fin n → ℝ) {ε t : ℝ} (hε : 0 ≤ ε) (ht : 0 ≤ t) + (hg : ∀ x i, |g x i| ≤ ε) (f : Observables n) (hf : ∀ x, 0 ≤ f x) : + gibbsExpectation J (preparationFlow J g t f) ≤ + Real.exp ((n:ℝ)*t*(Real.exp (2*ε)-1))*gibbsExpectation J f := by + apply gibbsExpectation_exp_refresh_le J _ (Real.exp_pos _).le (by positivity) _ _ f hf + · apply targetAttempt_nonneg + intro x i + exact (abs_lt.mpr ⟨Real.neg_one_lt_tanh _, Real.tanh_lt_one _⟩).le + · intro F hF + have hh : gibbsExpectation J (targetAttempt (fun x i => Real.tanh (field J x i+g x i)) F) ≤ + gibbsExpectation J (fun x => Real.exp (2*ε)*attemptLM J F x) := by + apply Finset.sum_le_sum + intro x _ + exact mul_le_mul_of_nonneg_left (targetAttempt_perturbed_le hn J g hε hg F hF x) (gibbs_pos J x).le + simpa only [gibbsExpectation_mul_const, gibbsExpectation_attempt J hJ hdiag] using hh + +end SKGapCutoff + +open scoped BigOperators +open ContinuousLinearMap + +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/Taylor.lean b/lean/OAI/Probability/SKGap/Localization/Taylor.lean new file mode 100644 index 0000000000000000000000000000000000000000..f77ad62281b204162641277d42183ebf4a153827 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/Taylor.lean @@ -0,0 +1,62 @@ +import Mathlib +import OAI.Probability.SKGap.Model + +namespace OAI + +section + +noncomputable section +open Set +namespace SKGap.SourceTaylor +variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] + +lemma segment_taylor (F : E→ℝ) (F' : E→E→L[ℝ]ℝ) (x y : E) {L : ℝ} + (hL : 0≤L) + (hF : ∀t∈Icc (0:ℝ) 1,HasFDerivAt F (F' (x+t • (y-x))) (x+t • (y-x))) + (hLip : ∀t∈Icc (0:ℝ) 1,‖F' (x+t • (y-x))-F' x‖≤L*‖t • (y-x)‖) : + |F y-F x-F' x (y-x)|≤L*‖y-x‖^2 := by + let g : ℝ→ℝ:=fun t=>F (x+t • (y-x))-F x-t*(F' x (y-x)) + let g' : ℝ→ℝ:=fun t=>(F' (x+t • (y-x))-F' x) (y-x) + have hg (t : ℝ) (ht : t∈Icc (0:ℝ) 1) : HasDerivAt g (g' t) t := by + have H:=(((hF t ht).comp_hasDerivAt t + (((hasDerivAt_id t).smul_const (y-x)).const_add x)).sub_const (F x)).sub + ((hasDerivAt_id t).mul_const (F' x (y-x))) + convert! H using 1 + simp only [g',sub_apply,one_smul,one_mul] + have hb (t : ℝ) (ht : t∈Ico (0:ℝ) 1) : ‖g' t‖≤L*‖y-x‖^2 := by + calc + _ ≤ ‖F' (x+t • (y-x))-F' x‖*‖y-x‖ := (F' (x+t • (y-x))-F' x).le_opNorm _ + _ ≤ (L*‖t • (y-x)‖)*‖y-x‖ := mul_le_mul_of_nonneg_right (hLip t ⟨ht.1,ht.2.le⟩) (norm_nonneg _) + _ ≤ (L*‖y-x‖)*‖y-x‖ := by + rw [norm_smul,Real.norm_eq_abs,abs_of_nonneg ht.1] + gcongr + exact mul_le_of_le_one_left (norm_nonneg _) ht.2.le + _ = _ := by ring + have H:=norm_image_sub_le_of_norm_deriv_le_segment_01' + (fun t ht=>(hg t ht).hasDerivWithinAt) hb + simpa only [g,one_smul,zero_smul,add_sub_cancel,add_zero,one_mul,zero_mul,sub_self,sub_zero, + Real.norm_eq_abs] using H + +lemma segment_lipschitz (F : E→ℝ) (F' : E→E→L[ℝ]ℝ) (x y : E) {C : ℝ} + (hC : 0≤C) + (hF : ∀t∈Icc (0:ℝ) 1,HasFDerivAt F (F' (x+t • (y-x))) (x+t • (y-x))) + (hBound : ∀t∈Icc (0:ℝ) 1,‖F' (x+t • (y-x))‖≤C) : + |F y-F x|≤C*‖y-x‖ := by + let g : ℝ→ℝ:=fun t=>F (x+t • (y-x)) + let g' : ℝ→ℝ:=fun t=>F' (x+t • (y-x)) (y-x) + have hg (t : ℝ) (ht : t∈Icc (0:ℝ) 1) : HasDerivAt g (g' t) t := by + convert! (hF t ht).comp_hasDerivAt t (((hasDerivAt_id t).smul_const (y-x)).const_add x) using 1 + simp only [g',one_smul] + have hb (t : ℝ) (ht : t∈Ico (0:ℝ) 1) : ‖g' t‖≤C*‖y-x‖ := + ((F' (x+t • (y-x))).le_opNorm _).trans + (mul_le_mul (hBound t ⟨ht.1,ht.2.le⟩) le_rfl (norm_nonneg _) hC) + have H:=norm_image_sub_le_of_norm_deriv_le_segment_01' + (fun t ht=>(hg t ht).hasDerivWithinAt) hb + simpa only [g,one_smul,zero_smul,add_sub_cancel,add_zero,Real.norm_eq_abs] using H + +end SKGap.SourceTaylor + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/TemplateChaining.lean b/lean/OAI/Probability/SKGap/Localization/TemplateChaining.lean new file mode 100644 index 0000000000000000000000000000000000000000..5bca58bb66e7f9501cfcfa8c6e45f5badd482470 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/TemplateChaining.lean @@ -0,0 +1,165 @@ +import Mathlib +import OAI.Probability.SKGap.Brownian.MatrixMeanContinuous +import OAI.Probability.SKGap.Gaussian.GaussianMatrixChaining + +namespace OAI + +section +noncomputable section +namespace SKGap +open Matrix Real Set MeasureTheory ProbabilityTheory Filter +open scoped BigOperators Matrix.Norms.Frobenius SchwartzMap Topology + +lemma sqrt_mesh_increment {δ : ℝ} (hδ : 0 ≤ δ) (k : ℕ) (h : δ ≤ 2*(1/4:ℝ)^k) : + sqrt δ ≤ 2*(1/2:ℝ)^k := by + have he : (1/4:ℝ)^k=(1/2:ℝ)^k*(1/2:ℝ)^k := by rw [←mul_pow]; norm_num + rw [he] at h + have hs := sq_sqrt hδ + have hp : 0 ≤ (1/2:ℝ)^k := by positivity + nlinarith [sqrt_nonneg δ] + +theorem templateWord_gaussian_chaining {m : ℕ} (f : 𝓢(ℝ,ℂ)) {R j D : ℝ} + (hR : 0 ≤ R) (hj : 0 ≤ j) (hD : 0 ≤ D) (F : List (WordTemplateLetter m)) : + ∃ C : ℝ,0gaussianReal 0 1)) + {g | ∃ θ : WordParameter m (Fin n),C< matrixWordSeminorm p + (matrixCentered (fun x : EuclideanSpace ℝ (MatrixCoordinates (Fin n))=> + templateMatrix f R hR j D F θ (goeMatrix (j/n) x)) (WithLp.toLp 2 g))} ≤ + ENNReal.ofReal (3*exp (-(n:ℝ))) := by + let B : NNReal := ⟨actualWordBound f R j 1 D,(actualWordBound_pos f hR hj zero_le_one hD).le⟩ + let L : NNReal := (F.length:NNReal)*B^F.length + let V : NNReal := wordMixedCoeff B F.length*⟨templateHolder f R j D,templateHolder_nonneg f hj hD⟩ + let H : ℝ := 1+((L:ℝ)+2*V)*sqrt (2*j) + let E : ℝ := log 16*((m:ℝ)+1) + have hH : 0templateMatrix f R hR j D F θ (goeMatrix (j/n) x) + have hsqrt : sqrt (2*(j/n))=sqrt (2*j)/sqrt n := by + rw [show 2*(j/n)=(2*j)/n by ring,Real.sqrt_div (by positivity)] + have hT (θ : WordParameter m (Fin n)) : LipschitzWith (Real.toNNReal (H/sqrt n)) (T θ) := by + have hh := (templateMatrix_bounds f hR hj hD F θ).2.comp (goeMatrix_L2_lipschitz (j/n)) + apply hh.weaken + change (L:ℝ)*sqrt (2*(j/n)) ≤ (Real.toNNReal (H/sqrt n):ℝ) + rw [Real.coe_toNNReal _ (by positivity),hsqrt] + calc + _ = ((L:ℝ)*sqrt (2*j))/sqrt n := by ring + _ ≤ H/sqrt n := div_le_div_of_nonneg_right hHL (sqrt_nonneg _) + have hi (k : ℕ) (θ η : WordParameter m (Fin n)) (hθη : dist θ η ≤ 2*(1/4:ℝ)^k) : + LipschitzWith (Real.toNNReal (H*(1/2:ℝ)^k/sqrt n)) (fun x=>T θ x-T η x) := by + have hh := (templateMatrix_increments f hR hj hD F θ η).2.comp (goeMatrix_L2_lipschitz (j/n)) + apply hh.weaken + change (((wordMixedCoeff B F.length:ℝ)*(templateHolder f R j D*sqrt (dist θ η)))*sqrt (2*(j/n))) ≤ + (Real.toNNReal (H*(1/2:ℝ)^k/sqrt n):ℝ) + rw [Real.coe_toNNReal _ (by positivity),hsqrt] + have he : (wordMixedCoeff B F.length:ℝ)*(templateHolder f R j D*sqrt (dist θ η))= + (V:ℝ)*sqrt (dist θ η) := by + change (wordMixedCoeff B F.length:ℝ)*(templateHolder f R j D*sqrt (dist θ η)) = + ((wordMixedCoeff B F.length:ℝ)*templateHolder f R j D)*sqrt (dist θ η) + ring + rw [he] + calc + _ ≤ (V:ℝ)*(2*(1/2:ℝ)^k)*(sqrt (2*j)/sqrt n) := + mul_le_mul_of_nonneg_right (mul_le_mul_of_nonneg_left (sqrt_mesh_increment dist_nonneg k hθη) V.coe_nonneg) (by positivity) + _ = (2*(V:ℝ)*sqrt (2*j))*(1/2:ℝ)^k/sqrt n := by ring + _ ≤ H*(1/2:ℝ)^k/sqrt n := div_le_div_of_nonneg_right (mul_le_mul_of_nonneg_right hHV (by positivity)) (sqrt_nonneg _) + exact gaussianMatrix_box_chaining hn hH hE hdim T hT hi + (fun g=>templateGaussian_centered_continuous f hR hj hD F (j/n) (WithLp.toLp 2 g)) p +end SKGap +end +end + +section +noncomputable section +namespace SKGap +open Matrix Real Set MeasureTheory ProbabilityTheory Filter +open scoped BigOperators Matrix.Norms.Frobenius SchwartzMap Topology + +theorem generalTemplateWord_gaussian_chaining {m : ℕ} (f : 𝓢(ℝ,ℂ)) {R j A D : ℝ} + (hR : 0 ≤ R) (hj : 0 ≤ j) (hA : 0 ≤ A) (hD : 0 ≤ D) (F : List (WordTemplateLetter m)) : + ∃ C : ℝ,0gaussianReal 0 1)) + {g | ∃ θ : WordParameter m (Fin n),C< matrixWordSeminorm p + (matrixCentered (fun x : EuclideanSpace ℝ (MatrixCoordinates (Fin n))=> + generalTemplateMatrix f R hR j A D F θ (goeMatrix (j/n) x)) (WithLp.toLp 2 g))} ≤ + ENNReal.ofReal (3*exp (-(n:ℝ))) := by + let B : NNReal := ⟨actualWordBound f R j A D,(actualWordBound_pos f hR hj hA hD).le⟩ + let L : NNReal := (F.length:NNReal)*B^F.length + let V : NNReal := wordMixedCoeff B F.length*⟨generalTemplateHolder f R j A D,generalTemplateHolder_nonneg f hR hj hA hD⟩ + let H : ℝ := 1+((L:ℝ)+2*V)*sqrt (2*j) + let E : ℝ := log 16*((m:ℝ)+1) + have hH : 0generalTemplateMatrix f R hR j A D F θ (goeMatrix (j/n) x) + have hsqrt : sqrt (2*(j/n))=sqrt (2*j)/sqrt n := by + rw [show 2*(j/n)=(2*j)/n by ring,Real.sqrt_div (by positivity)] + have hT (θ : WordParameter m (Fin n)) : LipschitzWith (Real.toNNReal (H/sqrt n)) (T θ) := by + have hh := (generalTemplateMatrix_bounds f hR hj hA hD F θ).2.comp (goeMatrix_L2_lipschitz (j/n)) + apply hh.weaken + change (L:ℝ)*sqrt (2*(j/n)) ≤ (Real.toNNReal (H/sqrt n):ℝ) + rw [Real.coe_toNNReal _ (by positivity),hsqrt] + calc + _ = ((L:ℝ)*sqrt (2*j))/sqrt n := by ring + _ ≤ H/sqrt n := div_le_div_of_nonneg_right hHL (sqrt_nonneg _) + have hi (k : ℕ) (θ η : WordParameter m (Fin n)) (hθη : dist θ η ≤ 2*(1/4:ℝ)^k) : + LipschitzWith (Real.toNNReal (H*(1/2:ℝ)^k/sqrt n)) (fun x=>T θ x-T η x) := by + have hh := (generalTemplateMatrix_increments f hR hj hA hD F θ η).2.comp (goeMatrix_L2_lipschitz (j/n)) + apply hh.weaken + change (((wordMixedCoeff B F.length:ℝ)*(generalTemplateHolder f R j A D*sqrt (dist θ η)))*sqrt (2*(j/n))) ≤ + (Real.toNNReal (H*(1/2:ℝ)^k/sqrt n):ℝ) + rw [Real.coe_toNNReal _ (by positivity),hsqrt] + have he : (wordMixedCoeff B F.length:ℝ)*(generalTemplateHolder f R j A D*sqrt (dist θ η))= + (V:ℝ)*sqrt (dist θ η) := by + change (wordMixedCoeff B F.length:ℝ)*(generalTemplateHolder f R j A D*sqrt (dist θ η)) = + ((wordMixedCoeff B F.length:ℝ)*generalTemplateHolder f R j A D)*sqrt (dist θ η) + ring + rw [he] + calc + _ ≤ (V:ℝ)*(2*(1/2:ℝ)^k)*(sqrt (2*j)/sqrt n) := + mul_le_mul_of_nonneg_right (mul_le_mul_of_nonneg_left (sqrt_mesh_increment dist_nonneg k hθη) V.coe_nonneg) (by positivity) + _ = (2*(V:ℝ)*sqrt (2*j))*(1/2:ℝ)^k/sqrt n := by ring + _ ≤ H*(1/2:ℝ)^k/sqrt n := div_le_div_of_nonneg_right (mul_le_mul_of_nonneg_right hHV (by positivity)) (sqrt_nonneg _) + exact gaussianMatrix_box_chaining hn hH hE hdim T hT hi + (fun g=>generalTemplateGaussian_centered_continuous f hR hj hA hD F (j/n) (WithLp.toLp 2 g)) p +end SKGap +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/TemplatePatterns.lean b/lean/OAI/Probability/SKGap/Localization/TemplatePatterns.lean new file mode 100644 index 0000000000000000000000000000000000000000..54d111e798704c0ab6034874d3226b7135991554 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/TemplatePatterns.lean @@ -0,0 +1,81 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.TemplateChaining + +namespace OAI + +section +noncomputable section +namespace SKGap +open scoped BigOperators + +def wordPatternSet (m : ℕ) : ℕ→Finset (List (WordTemplateLetter m)) + | 0 => {[]} + | L+1 => insert [] ((Finset.univ×ˢ wordPatternSet m L).image (fun p=>p.1::p.2)) + +@[simp] lemma mem_wordPatternSet {m L : ℕ} (F : List (WordTemplateLetter m)) : + F∈wordPatternSet m L ↔ F.length ≤ L := by + induction L generalizing F with + | zero => simp [wordPatternSet] + | succ L ih => + cases F with + | nil => simp [wordPatternSet] + | cons l F => + simp only [wordPatternSet,Finset.mem_insert,List.cons_ne_nil,Finset.mem_image, + Finset.mem_product,Finset.mem_univ,true_and,Prod.exists,List.cons.injEq,false_or] + constructor + · rintro ⟨a,G,hG,ha,hFG⟩ + subst a G + exact Nat.succ_le_succ ((ih F).mp hG) + · intro h + exact ⟨l,F,(ih F).mpr (Nat.le_of_succ_le_succ h),rfl,rfl⟩ +end SKGap +end +end + +section +noncomputable section +namespace SKGap +open Matrix Real Set MeasureTheory ProbabilityTheory Filter +open scoped BigOperators Matrix.Norms.Frobenius SchwartzMap Topology + +theorem all_generalTemplateWords_gaussian_chaining {m : ℕ} (f : 𝓢(ℝ,ℂ)) {R j A D : ℝ} + (hR : 0 ≤ R) (hj : 0 ≤ j) (hA : 0 ≤ A) (hD : 0 ≤ D) (L : ℕ) : + ∃ C : ℝ,0gaussianReal 0 1)) + {g | ∃ F : List (WordTemplateLetter m),F.length ≤ L ∧ ∃ θ : WordParameter m (Fin n), + C< matrixWordSeminorm p + (matrixCentered (fun x : EuclideanSpace ℝ (MatrixCoordinates (Fin n))=> + generalTemplateMatrix f R hR j A D F θ (goeMatrix (j/n) x)) (WithLp.toLp 2 g))} ≤ + (wordPatternSet m L).card*ENNReal.ofReal (3*exp (-(n:ℝ))) := by + classical + choose C hC htail using (fun F : List (WordTemplateLetter m)=>generalTemplateWord_gaussian_chaining f hR hj hA hD F) + let G := wordPatternSet m L + let T := 1+∑ F∈G,C F + have hT : 0(hC F).le) + dsimp [T] + linarith + have hF (F : List (WordTemplateLetter m)) (hF : F∈G) : C F ≤ T := by + have hh : C F ≤ ∑ F∈G,C F := Finset.single_le_sum (fun F _=>(hC F).le) hF + dsimp [T] + linarith + refine ⟨T,hT,?_⟩ + intro n hn p + let E : List (WordTemplateLetter m)→Set (MatrixCoordinates (Fin n)→ℝ) := fun F=> + {g | ∃ θ : WordParameter m (Fin n),C F< matrixWordSeminorm p + (matrixCentered (fun x : EuclideanSpace ℝ (MatrixCoordinates (Fin n))=> + generalTemplateMatrix f R hR j A D F θ (goeMatrix (j/n) x)) (WithLp.toLp 2 g))} + apply (measure_mono (show _⊆⋃ F∈G,E F from ?_)).trans + ((measure_biUnion_finset_le G E).trans ?_) + · intro g hg + obtain ⟨F,hFl,θ,hθ⟩ := hg + have hFm : F∈G := (mem_wordPatternSet F).mpr hFl + exact mem_iUnion.mpr ⟨F,mem_iUnion.mpr ⟨hFm,θ,lt_of_le_of_lt (hF F hFm) hθ⟩⟩ + · calc + _ ≤ ∑ F∈G,ENNReal.ofReal (3*exp (-(n:ℝ))) := Finset.sum_le_sum (fun F _=>htail F n hn p) + _ = _ := by simp [G] +end SKGap +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/ThresholdChoice.lean b/lean/OAI/Probability/SKGap/Localization/ThresholdChoice.lean new file mode 100644 index 0000000000000000000000000000000000000000..1095883b068ad2993ebb6ad89cb0e310e69724f9 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/ThresholdChoice.lean @@ -0,0 +1,289 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.DimensionDecay +import OAI.Probability.SKGap.Terminal.SpinSpectralMassBelow +import OAI.Probability.SKGap.Localization.PositiveRamp + +namespace OAI + +section +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open scoped BigOperators +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open scoped BigOperators +open scoped BigOperators NNReal ENNReal +open MeasureTheory Metric Set +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators NNReal ENNReal Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Set +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators ENNReal NNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Matrix +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators ENNReal NNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal +open scoped BigOperators +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise NNReal ENNReal +open scoped BigOperators +open Filter Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +namespace SKGapCutoff.Regression + +noncomputable def thresholdChoice {E F : Type*} (g : E → ℝ) (p q : E → F) (x : E) : F := + if 0 < g x then p x else q x + +lemma thresholdChoice_measurable {E F : Type*} [MeasurableSpace E] [MeasurableSpace F] + {g : E → ℝ} {p q : E → F} (hg : Measurable g) (hp : Measurable p) (hq : Measurable q) : + Measurable (thresholdChoice g p q) := + Measurable.ite (measurableSet_lt measurable_const hg) hp hq + +lemma thresholdChoice_decomposition {E F : Type*} (g : E → ℝ) (p q : E → F) + (f : F → ℝ) (x : E) : + f (thresholdChoice g p q x) = f (q x)+(f (p x)-f (q x))*positiveIndicator (g x) := by + by_cases hx : 0 < g x <;> simp [thresholdChoice, positiveIndicator, hx] + +theorem ExponentialEmpiricalConcentration.threshold_map + {E F : Type*} [PseudoMetricSpace E] [MeasurableSpace E] [BorelSpace E] + [PseudoMetricSpace F] [MeasurableSpace F] [BorelSpace F] + {H : ℕ → Type*} [∀ n, MeasurableSpace (H n)] + {ρ : ∀ n, Measure (H n)} {X : ∀ n, H n → Fin n → E} + {ν : Measure E} [IsProbabilityMeasure ν] + (hX : ExponentialEmpiricalConcentration ρ X ν) + (g : E → ℝ) (p q : E → F) {K P Q : ℝ≥0} + (hg : LipschitzWith K g) (hp : LipschitzWith P p) (hq : LipschitzWith Q q) + (hz : ν {x | g x = 0} = 0) : + ExponentialEmpiricalConcentration ρ + (fun n h i => thresholdChoice g p q (X n h i)) (ν.map (thresholdChoice g p q)) := by + intro f L hf B hB ε hε + let D : ℝ≥0 := ‖B‖₊+1 + have hD : ∀ z, |f z| ≤ D := by + intro z + change |f z| ≤ |B|+1 + linarith [hB z, le_abs_self B] + have hdiff : LipschitzWith (L*P+L*Q) (fun x => f (p x)-f (q x)) := + (hf.comp hp).sub (hf.comp hq) + have hdiffB : ∀ x, |f (p x)-f (q x)| ≤ (2*D:ℝ≥0) := by + intro x + have ht := abs_sub (f (p x)) (f (q x)) + push_cast + linarith [hD (p x), hD (q x)] + have hbase := hX.average (fun x => f (q x)) (hf.comp hq) D (fun x => hD (q x)) + have hth := hX.threshold_average (fun x => f (p x)-f (q x)) g hdiff hg hdiffB hz + have hh := (hbase.prod hth).continuous_map + (f := fun z : ℝ × ℝ => z.1+z.2) (by fun_prop) + have hiq := integrable_bounded_lipschitz ν (hf.comp hq) D (fun x => hD (q x)) + have hit : Integrable (fun x => (f (p x)-f (q x))*positiveIndicator (g x)) ν := by + apply Integrable.of_bound + ((hf.continuous.measurable.comp hp.continuous.measurable).sub + (hf.continuous.measurable.comp hq.continuous.measurable) |>.mul + (positiveIndicator_measurable.comp hg.continuous.measurable)).aestronglyMeasurable (2*D) + filter_upwards [] with x + change |(f (p x)-f (q x))*positiveIndicator (g x)| ≤ 2*(D:ℝ) + rw [abs_mul, abs_of_nonneg (positiveIndicator_bounds (g x)).1] + exact (mul_le_mul_of_nonneg_left (positiveIndicator_bounds (g x)).2 (abs_nonneg _)).trans + (by simpa using hdiffB x) + have hm : ∫ z, f z ∂ν.map (thresholdChoice g p q) = + (∫ x, f (q x) ∂ν) + ∫ x, (f (p x)-f (q x))*positiveIndicator (g x) ∂ν := by + rw [integral_map (thresholdChoice_measurable hg.continuous.measurable + hp.continuous.measurable hq.continuous.measurable).aemeasurable + hf.continuous.measurable.aestronglyMeasurable] + simp_rw [thresholdChoice_decomposition] + exact integral_add hiq hit + have ha (n : ℕ) (h : H n) : + (∑ i, f (thresholdChoice g p q (X n h i)))/(n:ℝ) = + (∑ i, f (q (X n h i)))/(n:ℝ) + + (∑ i, (f (p (X n h i))-f (q (X n h i)))*positiveIndicator (g (X n h i)))/(n:ℝ) := by + simp_rw [thresholdChoice_decomposition] + rw [Finset.sum_add_distrib, add_div] + have hc := hh ε hε + simpa only [ExponentiallyRare, Real.dist_eq, hm, ha] using hc + +noncomputable def uniformSeedLaw : Measure ℝ := volume.restrict (Set.Icc 0 1) + +instance uniformSeedLaw_probability : IsProbabilityMeasure uniformSeedLaw := by + constructor + simp [uniformSeedLaw] + +instance uniformSeedLaw_noAtoms : NullSingletonClass uniformSeedLaw := by + unfold uniformSeedLaw + infer_instance + +lemma uniform_threshold_boundary_null + {E : Type*} [MeasurableSpace E] (ν : Measure E) + (g : E → ℝ) (hg : Measurable g) : + (ν.prod uniformSeedLaw) {z | g z.1-z.2 = 0} = 0 := by + have hs : MeasurableSet {z : E × ℝ | g z.1-z.2 = 0} := + measurableSet_eq_fun + (show Measurable (fun z : E × ℝ => g z.1-z.2) from + (hg.comp measurable_fst).sub measurable_snd) measurable_const + rw [Measure.prod_apply hs] + have hz (x : E) : uniformSeedLaw (Prod.mk x ⁻¹' {z | g z.1-z.2 = 0}) = 0 := by + have he : Prod.mk x ⁻¹' {z | g z.1-z.2 = 0} = {g x} := by + ext y + simp only [Set.mem_preimage, Set.mem_ofPred_eq, Set.mem_singleton_iff, sub_eq_zero] + exact eq_comm + rw [he, measure_singleton] + simp_rw [hz] + simp + +end SKGapCutoff.Regression + +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal Topology + +namespace SKGapCutoff + +def DisorderTypical (β : ℝ) (P : (n : ℕ) → GaussianCoordinates n → Prop) : Prop := + Tendsto (fun n => disorderLaw β n {g | ¬ P n g}) atTop (𝓝 0) + +lemma DisorderTypical.mono {β : ℝ} + {P Q : (n : ℕ) → GaussianCoordinates n → Prop} + (hP : DisorderTypical β P) (hPQ : ∀ᶠ n in atTop, ∀ g, P n g → Q n g) : + DisorderTypical β Q := by + unfold DisorderTypical at hP ⊢ + apply tendsto_const_nhds.squeeze' hP (Eventually.of_forall (fun _ => zero_le)) + filter_upwards [hPQ] with n hn + exact measure_mono (fun g hg h => hg (hn g h)) + +lemma DisorderTypical.and {β : ℝ} + {P Q : (n : ℕ) → GaussianCoordinates n → Prop} + (hP : DisorderTypical β P) (hQ : DisorderTypical β Q) : + DisorderTypical β (fun n g => P n g ∧ Q n g) := by + unfold DisorderTypical at hP hQ ⊢ + have hh : Tendsto (fun n => disorderLaw β n {g | ¬P n g} + + disorderLaw β n {g | ¬Q n g}) atTop (𝓝 0) := by + simpa using hP.add hQ + apply tendsto_const_nhds.squeeze hh (fun _ => zero_le) + intro n + apply (measure_mono ?_).trans (measure_union_le _ _) + intro g hg + simp only [Set.mem_union, Set.mem_ofPred_eq] + tauto + +lemma disorderLimit_of_typical_bound {β a : ℝ} + {F : (n : ℕ) → Interaction n → ℝ} + {P : (n : ℕ) → GaussianCoordinates n → Prop} + {b : ℕ → ℝ} (hP : DisorderTypical β P) (hb : Tendsto b atTop (𝓝 0)) + (hbound : ∀ᶠ n in atTop, ∀ g, P n g → |F n (sampledInteraction g) - a| ≤ b n) : + DisorderLimit β F a := by + intro δ hδ + unfold DisorderTypical at hP + apply tendsto_const_nhds.squeeze' hP (Eventually.of_forall (fun _ => zero_le)) + filter_upwards [hbound, (tendsto_order.mp hb).2 δ hδ] with n hn hbn + apply measure_mono + intro g hg hgood + exact (not_lt_of_ge ((hn g hgood).trans hbn.le)) hg + +lemma cutoffTime_nonneg {n : ℕ} (hn : 0 < n) {rate : ℝ} (hrate : 0 < rate) : + 0 ≤ cutoffTime rate n := by + exact div_nonneg (Real.log_nonneg (by exact_mod_cast hn)) (by positivity) + +lemma spin_mass_cutoff_error {n : ℕ} (hn : 0 < n) + (J : Interaction n) (hJ : ∀ i j, J i j = J j i) (hd : ∀ i, J i i = 0) + {rate ε γ V c L : ℝ} (hrate : 0 < rate) (hε : ε < 1) + (hγ : 0 < γ) (hgap : HasGap J γ) (hV : 1 ≤ γ * V) + (hc : 0 < c) (hmass : c ≤ spinSpectralMassBelow J hJ hd L) + (hvar : ∀ x, semigroup J ((1-ε)*cutoffTime rate n) (fun y => overlap x y ^ 2) x - + (semigroup J ((1-ε)*cutoffTime rate n) (overlap x) x) ^ 2 ≤ (n : ℝ) * V) : + |worstContinuous J ((1-ε)*cutoffTime rate n) - 1| ≤ + (8*V/c^2) * dimensionDecay (1-(1-ε)*L/rate) n := by + have ht : 0 ≤ (1-ε)*cutoffTime rate n := + mul_nonneg (by linarith) (cutoffTime_nonneg hn hrate) + have hn' : (0 : ℝ) < n := by exact_mod_cast hn + have hat : 0 < (n : ℝ)*c^2*Real.exp (-2*L*((1-ε)*cutoffTime rate n)) := by + positivity + have hprod : (n : ℝ)*Real.exp (-2*L*((1-ε)*cutoffTime rate n)) * + dimensionDecay (1-(1-ε)*L/rate) n = 1 := by + rw [dimensionDecay, mul_assoc, ← Real.exp_add] + have he : -2*L*((1-ε)*cutoffTime rate n) + + -(1-(1-ε)*L/rate)*Real.log (n : ℝ) = -Real.log (n : ℝ) := by + unfold cutoffTime + field_simp + ; ring + rw [he, Real.exp_neg, Real.exp_log hn', mul_inv_cancel₀ hn'.ne'] + have heq : (n : ℝ)*c^2*Real.exp (-2*L*((1-ε)*cutoffTime rate n)) * + ((8*V/c^2)*dimensionDecay (1-(1-ε)*L/rate) n) = 8*V := by + calc + _ = (8*V)*((n : ℝ)*Real.exp (-2*L*((1-ε)*cutoffTime rate n))* + dimensionDecay (1-(1-ε)*L/rate) n) := by field_simp + _ = _ := by rw [hprod, mul_one] + rw [abs_of_nonpos (sub_nonpos.mpr (worstContinuous_le_one J _ ht))] + have hs := worstContinuous_lower_from_spectralMass hn J hJ hd ht hγ hgap hV hc hmass hvar + have hh : 1-worstContinuous J ((1-ε)*cutoffTime rate n) ≤ + (8*V/c^2)*dimensionDecay (1-(1-ε)*L/rate) n := by + apply (mul_le_mul_iff_right₀ hat).mp + simpa [mul_comm] using hs.trans_eq heq.symm + linarith + +theorem continuous_lower_from_typical_spin_mass + {β rate ε γ V c L : ℝ} (hrate : 0 < rate) (hε : ε < 1) + (hγ : 0 < γ) (hV : 1 ≤ γ * V) (hc : 0 < c) + (hedge : (1-ε)*L < rate) + (hgood : DisorderTypical β (fun n g => + HasGap (sampledInteraction g) γ ∧ + c ≤ spinSpectralMassBelow (sampledInteraction g) + (sampledInteraction_symm g) (sampledInteraction_diag g) L ∧ + ∀ x, semigroup (sampledInteraction g) ((1-ε)*cutoffTime rate n) + (fun y => overlap x y ^ 2) x - + (semigroup (sampledInteraction g) ((1-ε)*cutoffTime rate n) (overlap x) x)^2 ≤ + (n : ℝ)*V)) : + DisorderLimit β (fun n J => worstContinuous J ((1-ε)*cutoffTime rate n)) 1 := by + apply disorderLimit_of_typical_bound hgood + (show Tendsto (fun n => (8*V/c^2)*dimensionDecay (1-(1-ε)*L/rate) n) + atTop (𝓝 0) from by + simpa using (dimensionDecay_tendsto (1-(1-ε)*L/rate) (by + have := (div_lt_one hrate).mpr hedge + linarith)).const_mul (8*V/c^2)) + filter_upwards [eventually_gt_atTop 0] with n hn + intro g ⟨hgap, hmass, hvar⟩ + exact spin_mass_cutoff_error hn (sampledInteraction g) + (sampledInteraction_symm g) (sampledInteraction_diag g) hrate hε hγ hgap hV hc hmass hvar + +end SKGapCutoff + +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators + +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/TruncationGoodSet.lean b/lean/OAI/Probability/SKGap/Localization/TruncationGoodSet.lean new file mode 100644 index 0000000000000000000000000000000000000000..db9c8ff00380b0ec26769fa1e39cb808124e03cd --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/TruncationGoodSet.lean @@ -0,0 +1,139 @@ +import Mathlib +import OAI.Probability.SKGap.Matrix.GoeInverseLoopCentered +import OAI.Probability.SKGap.Localization.RealPart + +namespace OAI + +section +noncomputable section +open MeasureTheory ProbabilityTheory InformationTheory Real Set +open scoped NNReal ENNReal +open Filter +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius ENNReal NNReal +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius NNReal +noncomputable section +open MeasureTheory ProbabilityTheory Real Set Filter +open MeasureTheory.Measure +open scoped ENNReal NNReal MeasureTheory Topology +open MeasureTheory +noncomputable section +noncomputable section +open MeasureTheory Set NormedSpace +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius +noncomputable section +open Set Real +open scoped Topology +noncomputable section +open Matrix Set Filter +open scoped Topology Matrix.Norms.Frobenius +noncomputable section +open Matrix NormedSpace ContinuousLinearMap +open scoped Matrix.Norms.Frobenius +noncomputable section +open Matrix +namespace SKGap +open Matrix Real MeasureTheory ProbabilityTheory +open SKGap.RealComplex +open scoped BigOperators Matrix.Norms.Frobenius NNReal ENNReal SchwartzMap +variable {ι : Type*} [Fintype ι] [DecidableEq ι] + +def truncationGoodSet (r R lo hi : ℝ) (D C : Matrix ι ι ℝ) : Set (MatrixCoordinates ι → ℝ) := + {g | opNorm (goeMatrix r g) < R ∧ + lo < ComplexSpectral.lowerRayleigh (liftMatrix (1-D*(goeMatrix r g-C)*D)) ∧ + -hi < ComplexSpectral.lowerRayleigh (-liftMatrix (1-D*(goeMatrix r g-C)*D))} + +lemma truncationGoodSet_measurable (r R lo hi : ℝ) (D C : Matrix ι ι ℝ) : + MeasurableSet (truncationGoodSet r R lo hi D C) := by + have hg := (goeMatrix_pi_lipschitz (ι := ι) r).continuous + have hc : Continuous (fun g => liftMatrix (1-D*(goeMatrix r g-C)*D)) := by + dsimp [liftMatrix]; fun_prop + exact (measurableSet_lt (continuous_realOpNorm.comp hg).measurable measurable_const).inter + ((measurableSet_lt measurable_const (ComplexSpectral.continuous_lowerRayleigh.comp hc).measurable).inter + (measurableSet_lt measurable_const (ComplexSpectral.continuous_lowerRayleigh.comp hc.neg).measurable)) + +lemma realTruncatedK_lipschitz (f : 𝓢(ℝ,ℂ)) {R : ℝ} (hR : 0 ≤ R) + (D C : Matrix ι ι ℝ) (hD : Dᵀ = D) (hC : Cᵀ = C) : + LipschitzWith (Real.toNNReal (ComplexMatrix.kLip f R (liftMatrix D) (liftMatrix C))) + (realTruncatedK f R hR D C) := by + apply LipschitzWith.of_dist_le_mul + intro M N + simp only [dist_eq_norm] + exact (realTruncatedK_sub_norm f hR D C M N hD hC).trans + (mul_le_mul_of_nonneg_right (Real.le_coe_toNNReal _) (norm_nonneg _)) + +omit [Fintype ι] [DecidableEq ι] in +lemma goeMatrix_transpose (r : ℝ) (g : MatrixCoordinates ι → ℝ) : + (goeMatrix r g)ᵀ = goeMatrix r g := by + ext i k + simp [goeMatrix,add_comm] + +omit [Fintype ι] in +lemma symmetricElementary_transpose (i k : ι) : + (symmetricElementary i k)ᵀ = symmetricElementary i k := by + simp [symmetricElementary,Matrix.transpose_add,Matrix.transpose_single,add_comm] + +lemma realTruncatedK_goe_derivative (f : 𝓢(ℝ,ℂ)) {lo hi : ℝ} (hlo : 0 < lo) + (hf : ∀ x ∈ Set.Icc lo hi, f x = (x : ℂ)⁻¹) + {R : ℝ} (hR : 0 ≤ R) (D C : Matrix ι ι ℝ) (r : ℝ) + (hD : Dᵀ = D) (hC : Cᵀ = C) (g : MatrixCoordinates ι → ℝ) + (hg : g ∈ truncationGoodSet r R lo hi D C) (i b : ι) : + HasDerivAt (fun t : ℝ => realTruncatedK f R hR D C (goeMatrix r g+t • symmetricElementary i b) b i) + ((realTruncatedK f R hR D C (goeMatrix r g)*(D*D)*symmetricElementary i b* + realTruncatedK f R hR D C (goeMatrix r g)) b i) 0 := by + exact matrixEntry_derivative + (realTruncatedK_derivative f hlo hf hR D C (goeMatrix r g) (symmetricElementary i b) + hD hC (goeMatrix_transpose r g) (symmetricElementary_transpose i b) hg.1 hg.2.1 hg.2.2) b i + +theorem realTruncatedK_first_loop (f : 𝓢(ℝ,ℂ)) {lo hi : ℝ} (hlo : 0 < lo) + (hf : ∀ x ∈ Set.Icc lo hi, f x = (x : ℂ)⁻¹) + {R r : ℝ} (hR : 0 ≤ R) (hr : 0 ≤ r) (D C : Matrix ι ι ℝ) + (hD : Dᵀ = D) (hC : Cᵀ = C) (i : ι) : + let K := realTruncatedK f R hR D C + let c := ComplexMatrix.kBound f R (liftMatrix D) (liftMatrix C) + let L := Real.toNNReal (ComplexMatrix.kLip f R (liftMatrix D) (liftMatrix C)) + let Lπ : ℝ≥0 := L*(⟨sqrt (2*r),sqrt_nonneg _⟩ * + (Fintype.card (MatrixCoordinates ι) : ℝ≥0) ^ (1/(2:ℝ≥0∞)).toReal) + let T : ℝ≥0 := (⟨sqrt (Fintype.card ι)*opNorm (D*D), + mul_nonneg (sqrt_nonneg _) (norm_nonneg _)⟩*L)*⟨sqrt (2*r),sqrt_nonneg _⟩+1 + let μ := Measure.pi (fun _ : MatrixCoordinates ι => gaussianReal 0 1) + |(∫ g, (goeMatrix r g*K (goeMatrix r g)) i i ∂μ)- + r*(∫ g, Matrix.trace (K (goeMatrix r g)*(D*D)) ∂μ)*(∫ g, K (goeMatrix r g) i i ∂μ)| ≤ + (Fintype.card ι:ℝ)*(sqrt (2*r)*(Lπ:ℝ)+r*(2*c*opNorm (D*D)*c))* + μ.real (truncationGoodSet r R lo hi D C)ᶜ+ + r*(c*((2*Real.exp (π^2/8))*(T:ℝ))+c*opNorm (D*D)*c) := by + intro K c L Lπ T μ + have hK : LipschitzWith L K := realTruncatedK_lipschitz f hR D C hD hC + have ht : LipschitzWith T (fun g : EuclideanSpace ℝ (MatrixCoordinates ι) => + Matrix.trace (K (goeMatrix r g)*(D*D))) := by + exact ((matrixTrace_mul_lipschitz hK (D*D)).comp (goeMatrix_L2_lipschitz r)).weaken + (le_add_of_nonneg_right (by norm_num)) + have ht0 : 0 < T := by dsimp [T]; positivity + exact goe_inverse_loop_centered hr (D*D) i hK + (fun M => realTruncatedK_opNorm f hR D C M hD hC) ht ht0 + (truncationGoodSet_measurable r R lo hi D C) + (fun g hg b => realTruncatedK_goe_derivative f hlo hf hR D C r hD hC g hg i b) + +end SKGap + +end +end +end +end +end +end +end +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/UniformRecipeClass.lean b/lean/OAI/Probability/SKGap/Localization/UniformRecipeClass.lean new file mode 100644 index 0000000000000000000000000000000000000000..b44c54aa47962131eaa552c615690f8eb4c2076f --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/UniformRecipeClass.lean @@ -0,0 +1,159 @@ +import Mathlib +import OAI.Probability.SKGap.Gaussian.SteinRecipeRegularity +import OAI.Probability.SKGap.Localization.ResidualMultiplier + +namespace OAI + +section + +noncomputable section +open scoped BigOperators +namespace SKGapCutoff.Recipe +open Primary Static +universe u +variable {Ω : Type u} {n : Ω→ℕ} {M : ℕ} +variable {σ τ : Type*} [Fintype σ] [Fintype τ] + +structure FamilyRecipe (j : ℝ) (J : ∀a,Interaction (n a)) (h : ∀a,Fin (n a)→ℝ) + (D : ∀a,OrdinaryData (n a) (Fin M) (Fin M) σ) (N p : ℕ) (K : ℝ) : Prop where + interaction : ∀a,(D a).J=J a + coupling : ∀a,(D a).j=j + primary : ∀a q,(D a).H q=fld j (J a) (h a) q.val + predecessor : ∀a q,(D a).predecessor q=mag j (J a) (h a) q.val + parameter : ∀a q,(D a).θ q=fun x=>j*(onsager j (J a) (h a) (q.val+1) x-onsager j (J a) (h a) q.val x) + seed : ∃S : ℝ,0≤S ∧ ∀a,(∑s,vectorNorm ((D a).seed s))≤S + coefficients : ∀a x,(D a).CoefficientClass N x K + admissible : ∀a,(D a).Admissible N p + +namespace OrdinaryData +lemma CoefficientClass.mono {n : ℕ} {ι κ σ : Type*} [Fintype ι] [DecidableEq ι] + [Fintype κ] [DecidableEq κ] [Fintype σ] {D : OrdinaryData n ι κ σ} {N : ℕ} {x : Spin n} + {K L : ℝ} (h : D.CoefficientClass N x K) (hKL : K≤L) : D.CoefficientClass N x L := by + refine ⟨h.one_le.trans hKL,fun a ha s=>(h.seedRegular a ha s).mono hKL, + fun a ha b=>(h.auxRegular a ha b).mono hKL,?_,?_⟩ + · intro a ha s i k t ht; exact (h.seedValue a ha s i k t ht).trans hKL + · intro a ha b i k t ht; exact (h.auxValue a ha b i k t ht).trans hKL +end OrdinaryData + +namespace FamilyRecipe +variable {j : ℝ} {J : ∀a,Interaction (n a)} {h : ∀a,Fin (n a)→ℝ} +variable {D : ∀a,OrdinaryData (n a) (Fin M) (Fin M) σ} {N p : ℕ} {K : ℝ} +lemma mono (H : FamilyRecipe j J h D N p K) {r A : ℕ} {L : ℝ} + (hr : r≤p) (hA : A≤N) (hK : K≤L) : FamilyRecipe j J h D A r L := + ⟨H.interaction,H.coupling,H.primary,H.predecessor,H.parameter,H.seed, + fun a x=>((H.coefficients a x).prefix hA).mono hK,fun a=>(H.admissible a).prefix hA |>.mono hr⟩ + +lemma appendStein (H : FamilyRecipe j J h D N p K) (l m α : Fin M) + (hl : p≤l.val) (hm : p ≤ m.val) {R : ℝ} + (ht : ∀a x,|(D a).θ α x|≤R) : + FamilyRecipe j J h (fun a=>(D a).appendStein N l m α) (N+1) p (K+4*steinCoefficientBudget R*K) := by + refine ⟨H.interaction,H.coupling,H.primary,H.predecessor,H.parameter,H.seed,?_,?_⟩ + · intro a x + exact (H.coefficients a x).appendStein l m α R (ht a x) (fun k=>ht a (flip x k)) + · intro a; exact (D a).appendStein_Admissible N p l m α hl hm (H.admissible a) + +lemma appendAuxiliary (H : FamilyRecipe j J h D N p K) : + FamilyRecipe j J h (fun a=>(D a).appendAuxiliary N) (N+1) p K := + ⟨H.interaction,H.coupling,H.primary,H.predecessor,H.parameter,H.seed, + fun a x=>(H.coefficients a x).appendAuxiliary, + fun a=>(D a).appendAuxiliary_Admissible N p (H.admissible a)⟩ + +lemma normalizedPrimary (H : FamilyRecipe j J h D N p K) (hn : ∀a,0(D a).normalizedPrimary q) 0 r 2 := by + refine ⟨H.interaction,H.coupling,H.primary,H.predecessor,H.parameter, + ⟨1,by norm_num,fun a=>le_of_eq ((D a).normalizedPrimary_seed q (hn a))⟩, + fun a x=>(D a).normalizedPrimary_coefficientClass q 0 x, + fun a=>(D a).normalizedPrimary_Admissible q r hr 0⟩ + +lemma sameEnvironment (H : FamilyRecipe j J h D N p K) + {E : ∀a,OrdinaryData (n a) (Fin M) (Fin M) τ} {A r : ℕ} {L : ℝ} + (H' : FamilyRecipe j J h E A r L) (a : Ω) : + (D a).J=(E a).J ∧ (D a).j=(E a).j ∧ (D a).H=(E a).H ∧ + (D a).predecessor=(E a).predecessor ∧ (D a).θ=(E a).θ := by + exact ⟨(H.interaction a).trans (H'.interaction a).symm, + (H.coupling a).trans (H'.coupling a).symm, + funext fun q=>(H.primary a q).trans (H'.primary a q).symm, + funext fun q=>(H.predecessor a q).trans (H'.predecessor a q).symm, + funext fun q=>(H.parameter a q).trans (H'.parameter a q).symm⟩ + +end FamilyRecipe +end SKGapCutoff.Recipe + +end +end + +section + +noncomputable section +open scoped BigOperators +namespace SKGapCutoff.Static +universe u +variable {Ω : Type u} {n : Ω→ℕ} +lemma UniformMultiplier.congr {F H : ∀a,Observables (n a)} (hF : UniformMultiplier F) + (he : ∀a x,F a x=H a x) : UniformMultiplier H := by + have : F=H:=funext fun a=>funext (he a) + rwa [←this] +lemma UniformMultiplier.add {F H : ∀a,Observables (n a)} (hF : UniformMultiplier F) + (hH : UniformMultiplier H) : UniformMultiplier (fun a x=>F a x+H a x) := by + obtain ⟨B,L,hB,hL,hF,hdF⟩:=hF + obtain ⟨C,K,hC,hK,hH,hdH⟩:=hH + refine ⟨B+C,Real.sqrt (2*L^2+2*K^2),add_nonneg hB hC,Real.sqrt_nonneg _, + fun a x=>(abs_add_le _ _).trans (add_le_add (hF a x) (hH a x)),fun a x=>?_⟩ + rw [Real.sq_sqrt (by positivity)] + have he (i : Fin (n a)) : halfDiff i (fun y=>F a y+H a y) x=halfDiff i (F a) x+halfDiff i (H a) x := by + unfold halfDiff; ring + simp only [he] + calc + _ ≤ ∑i,(2*(halfDiff i (F a) x)^2+2*(halfDiff i (H a) x)^2) := by + apply Finset.sum_le_sum; intro i _; nlinarith [sq_nonneg (halfDiff i (F a) x-halfDiff i (H a) x)] + _ = 2*(∑i,(halfDiff i (F a) x)^2)+2*(∑i,(halfDiff i (H a) x)^2) := by + simp only [Finset.sum_add_distrib,Finset.mul_sum] + _ ≤ _ := by linarith [hdF a x,hdH a x] +lemma UniformMultiplier.finset_sum {τ : Type*} {F : τ→∀a,Observables (n a)} (s : Finset τ) + (h : ∀t∈s,UniformMultiplier (F t)) : UniformMultiplier (fun a x=>∑t∈s,F t a x) := by + classical + induction s using Finset.induction_on with + | empty=>simpa using (UniformMultiplier.const (n:=n) 0) + | @insert t s ht ih=> + simpa only [Finset.sum_insert ht] using (h t (Finset.mem_insert_self ..)).add + (ih (fun r hr=>h r (Finset.mem_insert_of_mem hr))) +lemma UniformMultiplier.sum {τ : Type*} [Fintype τ] {F : τ→∀a,Observables (n a)} + (h : ∀t,UniformMultiplier (F t)) : UniformMultiplier (fun a x=>∑t,F t a x) := + UniformMultiplier.finset_sum Finset.univ (fun t _=>h t) +end SKGapCutoff.Static +namespace SKGapCutoff.Primary +variable {n : ℕ} +lemma onsager_bounds (j : ℝ) (J : Interaction n) (h : Fin n→ℝ) (k : ℕ) (x : Spin n) : + 0≤onsager j J h k x ∧ onsager j J h k x≤1 := by + have hm (i : Fin n) : (mag j J h k x i)^2≤1 := by + have H:=primaryState_mag_bounded j J h k x i + have H':=sq_le_sq₀ (abs_nonneg (mag j J h k x i)) (by norm_num : (0:ℝ)≤1) + simpa only [sq_abs,one_pow] using H'.mpr H + constructor + · exact div_nonneg (Finset.sum_nonneg (fun i _=>sub_nonneg.mpr (hm i))) (Nat.cast_nonneg n) + · by_cases hn : n=0 + · simp [onsager,siteMean,hn] + · apply (div_le_iff₀ (Nat.cast_pos.mpr (Nat.pos_of_ne_zero hn))).mpr + calc + (∑i:Fin n,(1-(mag j J h k x i)^2)) ≤ ∑i:Fin n,(1:ℝ) := + Finset.sum_le_sum fun i _=>sub_le_self _ (sq_nonneg _) + _ = _ := by simp +lemma onsager_parameter_bound (j : ℝ) (J : Interaction n) (h : Fin n→ℝ) (k : ℕ) (x : Spin n) : + |j*(onsager j J h (k+1) x-onsager j J h k x)|≤|j| := by + have H:=onsager_bounds j J h k x + have H':=onsager_bounds j J h (k+1) x + rw [abs_mul] + simpa using mul_le_mul_of_nonneg_left (show |onsager j J h (k+1) x-onsager j J h k x|≤1 from + abs_le.mpr ⟨by linarith,by linarith⟩) (abs_nonneg j) +lemma onsager_telescope (j : ℝ) (J : Interaction n) (h : Fin n→ℝ) (k : ℕ) (x : Spin n) : + (∑q∈Finset.range k,j*(onsager j J h (q+1) x-onsager j J h q x))=j*onsager j J h k x := by + induction k with + | zero=>simp [onsager_zero] + | succ k ih=>rw [Finset.sum_range_succ,ih]; ring +end SKGapCutoff.Primary + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/UniformResidual.lean b/lean/OAI/Probability/SKGap/Localization/UniformResidual.lean new file mode 100644 index 0000000000000000000000000000000000000000..5f1446dd0cc226338eec66ca25600d97b2571be0 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/UniformResidual.lean @@ -0,0 +1,200 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.PrimaryLocalInput + +namespace OAI + +section + +noncomputable section +open scoped BigOperators +namespace SKGapCutoff.Recipe +open Primary Static +universe u +variable {Ω : Type u} {n : Ω→ℕ} {M Nmax : ℕ} {A j : ℝ} +variable {J : ∀a,Interaction (n a)} {h : ∀a,Fin (n a)→ℝ} +variable {P : ∀a,Observables (n a)} + +theorem uniform_residual_rule (C : FiniteRecipeControl j J h M Nmax A) + (hP : ∀a x,0≤P a x) (hp : ∀a,∑x,P a x=1) + (hm : ∀a x i,conditionalMean (P a) x i=mag j (J a) (h a) 1 x i) + (hn : ∀a,0 + intro hpmax + cases p with + | zero=>exact residual_rule_base C hP hp hm (b 0) (hA 0 hpmax) + | succ k=> + exact residual_rule_step C hP hn hJ b hmono k (hpmax.trans_lt hM) + (hA k (by omega)) (h2 k (by omega)) (hstep k (by omega)) + (fun r hr=>ih r hr (by omega)) + +def residualCoefficientBudget (j K : ℝ) (t p : ℕ) : ℝ := + K*(1+4*steinCoefficientBudget |j|)^(t-p) +lemma residualCoefficientBudget_antitone (j : ℝ) {K : ℝ} (hK : 0≤K) (t : ℕ) : + Antitone (residualCoefficientBudget j K t) := by + intro p q hpq + apply mul_le_mul_of_nonneg_left _ hK + exact pow_le_pow_right₀ (by linarith [steinCoefficientBudget_nonneg |j|]) (Nat.sub_le_sub_left hpq t) +lemma residualCoefficientBudget_ge (j : ℝ) {K : ℝ} (hK : 0≤K) (t p : ℕ) : + K≤residualCoefficientBudget j K t p := by + simpa only [mul_one,residualCoefficientBudget] using mul_le_mul_of_nonneg_left + (one_le_pow₀ (by linarith [steinCoefficientBudget_nonneg |j|]) : + 1≤(1+4*steinCoefficientBudget |j|)^(t-p)) hK +lemma residualCoefficientBudget_step (j K : ℝ) {t k : ℕ} (hk : k∑i,residual j (J a) (h a) p x i*(D a).source N x i) := by + have hK0 : 0≤K := by linarith + have hb:=residualCoefficientBudget_antitone j hK0 p + have HH:=uniform_residual_rule C hP hp hm hn hJ (residualCoefficientBudget j K p) hb p hM + (fun r _=>hb (Nat.zero_le r)) (fun r _=>hK.trans (residualCoefficientBudget_ge j hK0 p r)) + (fun k hk=>le_of_eq (residualCoefficientBudget_step j K hk)) p le_rfl D N + apply HH _ le_rfl + simpa [residualCoefficientBudget] using H + +end SKGapCutoff.Recipe + +end +end + +section + +noncomputable section +open scoped BigOperators +namespace SKGapCutoff.Static +open Primary Recipe +universe u +variable {Ω : Type u} {n : Ω→ℕ} + +def UniformSquare (P F : ∀a,Observables (n a)) : Prop := + ∀B L:ℝ,0≤B→0≤L→∃C:ℝ,0≤C ∧ ∀a (f θ : Observables (n a)), + (∀x,|θ x|≤B)→(∀x,∑i,(halfDiff i θ x)^2≤L^2)→ + |∑x,P a x*(f x)^2*θ x*F a x|≤C*starSquared (P a) f + +lemma UniformSquare.zero (P : ∀a,Observables (n a)) : UniformSquare P (fun _ _=>0) := by + intro B L hB hL + exact ⟨0,le_rfl,by simp⟩ +lemma UniformSquare.congr {P F H : ∀a,Observables (n a)} (hF : UniformSquare P F) + (he : ∀a x,F a x=H a x) : UniformSquare P H := by + have : F=H:=funext fun a=>funext (he a) + rwa [←this] +lemma UniformSquare.add {P F H : ∀a,Observables (n a)} (hF : UniformSquare P F) + (hH : UniformSquare P H) : UniformSquare P (fun a x=>F a x+H a x) := by + intro B L hB hL + obtain ⟨C,hC,hF⟩:=hF B L hB hL + obtain ⟨D,hD,hH⟩:=hH B L hB hL + refine ⟨C+D,add_nonneg hC hD,fun a f θ ht hd=>?_⟩ + simp only [mul_add,Finset.sum_add_distrib] + exact (abs_add_le _ _).trans ((add_le_add (hF a f θ ht hd) (hH a f θ ht hd)).trans_eq (by ring)) +lemma UniformSquare.neg {P F : ∀a,Observables (n a)} (hF : UniformSquare P F) : + UniformSquare P (fun a x=>-F a x) := by + intro B L hB hL + obtain ⟨C,hC,hF⟩:=hF B L hB hL + refine ⟨C,hC,fun a f θ ht hd=>?_⟩ + simpa using hF a f θ ht hd +lemma UniformSquare.sub {P F H : ∀a,Observables (n a)} (hF : UniformSquare P F) + (hH : UniformSquare P H) : UniformSquare P (fun a x=>F a x-H a x) := by + simpa only [sub_eq_add_neg] using hF.add hH.neg +lemma UniformSquare.sum {τ : Type*} [Fintype τ] {P : ∀a,Observables (n a)} + {F : τ→∀a,Observables (n a)} (h : ∀t,UniformSquare P (F t)) : + UniformSquare P (fun a x=>∑t,F t a x) := by + classical + intro B L hB hL + choose C hC hb using (fun t=>h t B L hB hL) + refine ⟨∑t,C t,Finset.sum_nonneg (fun t _=>hC t),fun a f θ ht hd=>?_⟩ + simp only [Finset.mul_sum] + rw [Finset.sum_comm] + exact (Finset.abs_sum_le_sum_abs ..).trans + ((Finset.sum_le_sum fun t _=>hb t a f θ ht hd).trans_eq (Finset.sum_mul ..).symm) + +lemma scalar_product_bounds {n : ℕ} (θ η : Observables n) {B L D K : ℝ} + (hB : 0≤B) (_ : 0≤L) (_ : 0≤D) (_ : 0≤K) + (ht : ∀x,|θ x|≤B) (hdt : ∀x,∑i,(halfDiff i θ x)^2≤L^2) + (he : ∀x,|η x|≤D) (hde : ∀x,∑i,(halfDiff i η x)^2≤K^2) : + (∀x,|θ x*η x|≤B*D) ∧ + (∀x,∑i,(halfDiff i (fun y=>θ y*η y) x)^2≤(Real.sqrt (2*B^2*K^2+2*D^2*L^2))^2) := by + constructor + · intro x; rw [abs_mul]; exact mul_le_mul (ht x) (he x) (abs_nonneg _) hB + · intro x + rw [Real.sq_sqrt (by positivity)] + calc + _ ≤ ∑i,(2*B^2*(halfDiff i η x)^2+2*D^2*(halfDiff i θ x)^2) := by + apply Finset.sum_le_sum; intro i _ + rw [halfDiff_mul_flipped] + have h1 : (θ (flip x i))^2≤B^2 := by simpa only [sq_abs] using pow_le_pow_left₀ (abs_nonneg _) (ht (flip x i)) 2 + have h2 : (η x)^2≤D^2 := by simpa only [sq_abs] using pow_le_pow_left₀ (abs_nonneg _) (he x) 2 + have h1':=mul_le_mul_of_nonneg_right h1 (sq_nonneg (halfDiff i η x)) + have h2':=mul_le_mul_of_nonneg_right h2 (sq_nonneg (halfDiff i θ x)) + nlinarith only [h1',h2',sq_nonneg (θ (flip x i)*halfDiff i η x-η x*halfDiff i θ x)] + _ = 2*B^2*(∑i,(halfDiff i η x)^2)+2*D^2*(∑i,(halfDiff i θ x)^2) := by + simp only [Finset.sum_add_distrib,Finset.mul_sum] + _ ≤ _ := add_le_add (mul_le_mul_of_nonneg_left (hde x) (by positivity)) + (mul_le_mul_of_nonneg_left (hdt x) (by positivity)) + +lemma UniformSquare.mul {P F η : ∀a,Observables (n a)} (_ : ∀a x,0≤P a x) + (hF : UniformSquare P F) (hη : UniformMultiplier η) : + UniformSquare P (fun a x=>η a x*F a x) := by + obtain ⟨D,K,hD,hK,he,hde⟩:=hη + intro B L hB hL + obtain ⟨C,hC,hF⟩:=hF (B*D) (Real.sqrt (2*B^2*K^2+2*D^2*L^2)) + (mul_nonneg hB hD) (Real.sqrt_nonneg _) + refine ⟨C,hC,fun a f θ ht hd=>?_⟩ + obtain ⟨h1,h2⟩:=scalar_product_bounds θ (η a) hB hL hD hK ht hd (he a) (hde a) + convert hF a f (fun x=>θ x*η a x) h1 h2 using 1 + congr 1 + apply Finset.sum_congr rfl; intro x _; ring +lemma UniformSquare.smul {P F : ∀a,Observables (n a)} (hP : ∀a x,0≤P a x) + (hF : UniformSquare P F) (c : ℝ) : UniformSquare P (fun a x=>c*F a x) := + hF.mul hP (UniformMultiplier.const c) + +lemma UniformSquare.base (P : ∀a,Observables (n a)) (hP : ∀a x,0≤P a x) + (U : ∀a,VectorFields (n a)) {A B : ℝ} (hA : 0≤A) (hB : 0≤B) + (hD : ∀a x,∑i,|halfDiff i (fun y=>U a y i) x|≤A) + (hU : ∀a x,vectorNorm (U a x)≤B) : + UniformSquare P (fun a x=>∑i,(spin x i-conditionalMean (P a) x i)*U a x i) := by + intro H L hH hL + refine ⟨13*(H*A+(2*B+4*A)*L)+6*(H*B),by positivity,fun a f θ ht hd=>?_⟩ + apply square_multiplier_weak_residual_base (P a) (hP a) f θ (U a) hA hB hH hL (hD a) _ ht hd + intro x + simpa only [vectorNorm_sq] using pow_le_pow_left₀ (vectorNorm_nonneg _) (hU a x) 2 + +end SKGapCutoff.Static +namespace SKGapCutoff.Recipe +open Primary Static +universe u +variable {Ω : Type u} {n : Ω→ℕ} {j : ℝ} {J : ∀a,Interaction (n a)} {h : ∀a,Fin (n a)→ℝ} +lemma uniform_square_normalized_pair (P : ∀a,Observables (n a)) (hP : ∀a x,0≤P a x) + (hn : ∀a,0∑i,R a x i*(V a x i/Real.sqrt (n a:ℝ)))) + {C : ℝ} (hC : 0≤C) (hU : ∀a x,SmallBound (U a) x C) : + UniformSquare P (fun a x=>siteMean (U a) x*(∑i,R a x i*V a x i)) := by + exact (hV.mul hP (UniformMultiplier.normedMean hn U hC hU)).congr + (fun a x=>normalized_pair_cancel (hn a) (R a) (V a) (siteMean (U a)) x) +lemma uniform_square_prev_zero (P : ∀a,Observables (n a)) (U : ∀a,VectorFields (n a)) : + UniformSquare P (fun a x=>∑i,previousResidual j (J a) (h a) 0 x i*U a x i) := by + convert UniformSquare.zero P using 1 + ext a x + simp [previousResidual] +end SKGapCutoff.Recipe + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/UniformSquareInduction.lean b/lean/OAI/Probability/SKGap/Localization/UniformSquareInduction.lean new file mode 100644 index 0000000000000000000000000000000000000000..d621c9763dfaddd799cd0ff920098e8bfcb8d705 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/UniformSquareInduction.lean @@ -0,0 +1,173 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.UniformResidual + +namespace OAI + +section + +noncomputable section +open scoped BigOperators +namespace SKGapCutoff.Recipe +open Primary Static +universe u +variable {Ω : Type u} {n : Ω→ℕ} {M Nmax : ℕ} {A j : ℝ} +variable {J : ∀a,Interaction (n a)} {h : ∀a,Fin (n a)→ℝ} +variable {P : ∀a,Observables (n a)} + +def RecipeSquareResidualRule (j : ℝ) (J : ∀a,Interaction (n a)) (h : ∀a,Fin (n a)→ℝ) + (P : ∀a,Observables (n a)) (M Nmax p : ℕ) (B : ℝ) : Prop := + ∀ {σ : Type} [Fintype σ] (D : ∀a,OrdinaryData (n a) (Fin M) (Fin M) σ) (N : ℕ), + FamilyRecipe j J h D N p B → N+2*p≤Nmax → + UniformSquare P (fun a x=>∑i,residual j (J a) (h a) p x i*(D a).source N x i) + +lemma residual_square_rule_base (C : FiniteRecipeControl j J h M Nmax A) + (hP : ∀a x,0≤P a x) (_ : ∀a,∑x,P a x=1) + (hm : ∀a x i,conditionalMean (P a) x i=mag j (J a) (h a) 1 x i) + (B : ℝ) (hB : B≤A) : RecipeSquareResidualRule j J h P M Nmax 0 B := by + intro σ inst D N H hN + obtain ⟨K,hK,hbound⟩:=C.small D N 0 B H (by omega) hB + have hh:=UniformSquare.base P hP (fun a=>(D a).source N) hK hK + (fun a x=>(hbound a x).2.2) (fun a x=>(hbound a x).1.size) + apply hh.congr + intro a x + simp only [Primary.residual,mag_zero,hm] + +lemma residual_square_rule_step (C : FiniteRecipeControl j J h M Nmax A) + (hP : ∀a x,0≤P a x) (hn : ∀a,0(D a).appendStein N l m l + have HE : FamilyRecipe j J h E (N+1) k (b k) := by + have HH:=(H.mono (show k≤k+1 by omega) le_rfl le_rfl).appendStein l m l le_rfl + (show k ≤ m.val by dsimp [m]; omega) + (R:=|j|) (fun a x=>by rw [H.parameter a l]; exact onsager_parameter_bound j (J a) (h a) k x) + exact HH.mono le_rfl le_rfl hstep + have hEN : N+1+2*k≤Nmax := by omega + have source : UniformSquare P (fun a x=>∑i,residual j (J a) (h a) k x i*(E a).source (N+1) x i) := + ih k (by omega) E (N+1) HE hEN + have aux : UniformSquare P (fun a x=>∑i,residual j (J a) (h a) k x i*(E a).auxiliary (N+1) x i) := by + have HH:=ih k (by omega) (fun a=>(E a).appendAuxiliary (N+1)) (N+1+1) + HE.appendAuxiliary (by omega) + exact HH.congr (fun a x=>by rw [OrdinaryData.appendAuxiliary_source]) + have param := source.mul hP (C.parameter l) + have prev : UniformSquare P (fun a x=>∑i,previousResidual j (J a) (h a) k x i*(E a).source (N+1) x i) := by + cases k with + | zero=>exact uniform_square_prev_zero P (fun a=>(E a).source (N+1)) + | succ r=> + have HH:=ih r (by omega) E (N+1) (HE.mono (by omega) le_rfl (hmono (by omega))) (by omega) + exact HH.congr (fun a x=>by simp only [previousResidual,Primary.residual,Nat.add_sub_cancel]) + have old:=prev.mul hP (C.onsager_multiplier k (by omega)) + have earlier : UniformSquare P (fun a x=>j*(∑t:Fin (N+1),siteMean ((E a).auxCoefficient (N+1) t) x* + (∑i,residual j (J a) (h a) k x i*(E a).source t.val x i))) := by + apply UniformSquare.smul hP _ j + apply UniformSquare.sum + intro t + exact (ih k (by omega) E t.val (HE.mono le_rfl t.isLt.le le_rfl) (by omega)).mul hP + (C.means E (N+1) k (b k) HE (by omega) hkA t) + obtain ⟨V,hV,hbound⟩:=C.small E (N+1) k (b k) HE (by omega) hkA + have primary (q : Fin M) (hr : k≤q.val) : + UniformSquare P (fun a x=>∑i,residual j (J a) (h a) k x i* + (mag j (J a) (h a) (q.val+1) x i/Real.sqrt (n a:ℝ))) := by + have HQ:=(HE.normalizedPrimary hn q k hr).mono le_rfl le_rfl hk2 + have HH:=ih k (by omega) (fun a=>(E a).normalizedPrimary q) 0 HQ (by omega) + exact HH.congr (fun a x=>by rw [OrdinaryData.normalizedPrimary_magnetization _ _ j (J a) (h a) q.val (HE.primary a q)]) + have future : UniformSquare P (fun a x=>j*(∑q:{q:Fin M//q≠l},siteMean ((E a).sourcePartial (N+1) q) x* + (∑i,residual j (J a) (h a) k x i*mag j (J a) (h a) q.val.val x i))) := by + apply UniformSquare.smul hP _ j + apply UniformSquare.sum + intro q + by_cases hq : q.val.valresidual j (J a) (h a) k) + (fun a=>(E a).sourcePartial (N+1) q.val) (fun a=>mag j (J a) (h a) (r.val+1)) + (primary r (by dsimp [r]; omega)) hV (fun a x=>(hbound a x).2.1 q.val) + simpa only [hr] using HH + have last : UniformSquare P (fun a x=>j*(siteMean ((E a).sourcePartial (N+1) l) x* + (∑i,residual j (J a) (h a) k x i*mag j (J a) (h a) (k+1) x i))) := by + apply UniformSquare.smul hP _ j + exact uniform_square_normalized_pair P hP hn (fun a=>residual j (J a) (h a) k) + (fun a=>(E a).sourcePartial (N+1) l) (fun a=>mag j (J a) (h a) (k+1)) + (primary l le_rfl) hV (fun a x=>(hbound a x).2.1 l) + apply ((((aux.add param).sub old).add earlier).add future).sub last |>.congr + intro a x + have hid:=(D a).residual_step N l m l hlm (hn a) j (J a) (hJ a) (h a) k Fin.val + (H.coupling a) (H.interaction a) (H.predecessor a) rfl (H.primary a l) (H.primary a m) + (H.parameter a l) ((H.admissible a).sourcePartial N le_rfl l (by dsimp [l]; omega)) x + dsimp only at hid + rw [hid] + dsimp only [E,l] + ring + +end SKGapCutoff.Recipe + +end +end + +section + +noncomputable section +open scoped BigOperators +namespace SKGapCutoff.Recipe +open Primary Static +universe u +variable {Ω : Type u} {n : Ω→ℕ} {M Nmax : ℕ} {A j : ℝ} +variable {J : ∀a,Interaction (n a)} {h : ∀a,Fin (n a)→ℝ} +variable {P : ∀a,Observables (n a)} + +theorem uniform_residual_square_rule (C : FiniteRecipeControl j J h M Nmax A) + (hP : ∀a x,0≤P a x) (hp : ∀a,∑x,P a x=1) + (hm : ∀a x i,conditionalMean (P a) x i=mag j (J a) (h a) 1 x i) + (hn : ∀a,0 + intro hpmax + cases p with + | zero=>exact residual_square_rule_base C hP hp hm (b 0) (hA 0 hpmax) + | succ k=> + exact residual_square_rule_step C hP hn hJ b hmono k (hpmax.trans_lt hM) + (hA k (by omega)) (h2 k (by omega)) (hstep k (by omega)) + (fun r hr=>ih r hr (by omega)) + +theorem uniform_ordinary_square_residual (p N : ℕ) {K : ℝ} (hK : 2≤K) (hM : p∑i,residual j (J a) (h a) p x i*(D a).source N x i) := by + have hK0 : 0≤K := by linarith + have hb:=residualCoefficientBudget_antitone j hK0 p + have HH:=uniform_residual_square_rule C hP hp hm hn hJ (residualCoefficientBudget j K p) hb p hM + (fun r _=>hb (Nat.zero_le r)) (fun r _=>hK.trans (residualCoefficientBudget_ge j hK0 p r)) + (fun k hk=>le_of_eq (residualCoefficientBudget_step j K hk)) p le_rfl D N + apply HH _ le_rfl + simpa [residualCoefficientBudget] using H + +end SKGapCutoff.Recipe + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/UniformStarted.lean b/lean/OAI/Probability/SKGap/Localization/UniformStarted.lean new file mode 100644 index 0000000000000000000000000000000000000000..bbddc18788bf0abf17840065fdb84496517f9447 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/UniformStarted.lean @@ -0,0 +1,196 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.CoefficientInputBridge +import OAI.Probability.SKGap.Localization.UniformRecipeClass +import OAI.Probability.SKGap.Matrix.StartedWordClosure +import OAI.Probability.SKGap.Localization.LocalRecipeClass + +namespace OAI + +section + +noncomputable section +open scoped BigOperators Matrix.Norms.Frobenius +namespace SKGapCutoff.Recipe +open Primary Matrix SKGap SKGap.Noncrossing SKGap.Noncrossing.Primary SKGap.Noncrossing.Primary.Tensor.Series +open SKGap.Noncrossing.ClosedMarked Static +universe u +variable {Ω : Type u} {n : Ω→ℕ} +variable {ι κ σ κ₀ σ₀ : Type*} [Fintype ι] [DecidableEq ι] [Fintype κ] [DecidableEq κ] [Fintype σ] +variable [Fintype κ₀] [DecidableEq κ₀] [Fintype σ₀] + +lemma errorBudget_mono {r : ℝ} (hr : 0 ≤ r) {s f s' f' : ℕ→ℝ} + (hs : ∀a,s a ≤ s' a) (hf : ∀a,f a ≤ f' a) (k : ℕ) : + (errorBudget r s f k).1 ≤ (errorBudget r s' f' k).1 ∧ + (errorBudget r s f k).2 ≤ (errorBudget r s' f' k).2 := by + induction k using Nat.strong_induction_on with + | h k ih=> + rw [errorBudget,errorBudget] + have h1:=Finset.sum_le_sum (fun (b : Fin k) (_:b∈Finset.univ)=>(ih b b.isLt).1) + have h2:=Finset.sum_le_sum (fun (b : Fin k) (_:b∈Finset.univ)=>(ih b b.isLt).2) + exact ⟨add_le_add (hs k) h2,add_le_add (add_le_add (add_le_add (hs k) h2) + (mul_le_mul_of_nonneg_left h1 hr)) (hf k)⟩ + +theorem uniform_started_control (E : ∀a,Set (Spin (n a))) + (D : ∀a,OrdinaryData (n a) ι κ σ) (I : ∀a,OrdinaryData (n a) Unit κ₀ σ₀) + (w y : ∀a,VectorFields (n a)) + (T : ∀a,Spin (n a)→ι→SourceTree (Fin (n a)→ℝ)) + (t : ∀a,Spin (n a)→SourceTree (Fin (n a)→ℝ)) + (N L : ℕ) (c : LocalConstants) (j : ℝ) + (hj : ∀a,(D a).j=j) (hij : ∀a,(I a).j=j) (hJ : ∀a,(D a).J=(I a).J) + (h : ∀a x,x∈E a→LocalOrdinaryInput (D a) (T a x) x N c) + (hW : ∀a x,x∈E a→w a x=(I a).sourceOf 1 (fun _=>y a) x) + (hWf : ∀a x,x∈E a→∀i,w a (flip x i)=(I a).sourceOf 1 (fun _=>y a) (flip x i)) + (hY : ∀a x,x∈E a→y a x=(I a).fieldOf 1 (fun _=>w a) (fun _=>y a) x) + (hYf : ∀a x,x∈E a→∀i,y a (flip x i)=(I a).fieldOf 1 (fun _=>w a) (fun _=>y a) (flip x i)) + (ha0 : ∀a x,x∈E a→∀i,0 ≤ (I a).implicitCoefficient x i) + (hS : ∀a x,x∈E a→(1-SKGap.pathDiagonal ((I a).implicitCoefficient x) 1* + ((I a).J-((I a).j*siteMean (I a).implicitCoefficient x) • 1)*SKGap.pathDiagonal ((I a).implicitCoefficient x) 1).PosDef) + {C F B₀ M B Q : ℝ} (hB₀ : 0 ≤ B₀) (hM : 0 ≤ M) (hB : 0 ≤ B) (hQ : 0 ≤ Q) (hC : 0 ≤ C) (hF : 0 ≤ F) + (hw₀ : ∀a x,x∈E a→SmallBound (w a) x B₀) (hy₀ : ∀a x,x∈E a→SmallBound (y a) x B₀) + (hp₀ : ∀a x,x∈E a→vectorNorm ((I a).implicitPartial (y a) x) ≤ B₀) + (hP : ∀a x,x∈E a→TraceControl ((I a).implicitSourcePrimitive (t a x) (y a) x) C) + (hF' : ∀a x,x∈E a→TraceControl ((I a).implicitFieldPrimitive (t a x) (w a) (y a) x) F) + (ha : ∀a x,x∈E a→∀i,|(I a).implicitCoefficient x i| ≤ c.A) + (hm : ∀a x,x∈E a→∀l,Marked.mass (GradedWords.ordinaryWords j (T a x l)).1 ≤ Q ∧ Marked.mass (GradedWords.ordinaryWords j (T a x l)).2 ≤ Q) + (hm₀ : ∀a x,x∈E a→Marked.mass (GradedWords.ordinaryWords j (t a x)).1 ≤ Q ∧ Marked.mass (GradedWords.ordinaryWords j (t a x)).2 ≤ Q) + (hT : ∀a x,x∈E a→∀l,GradedControl c.A L (GradedWords.ordinaryWords j (T a x l)).1 ∧ GradedControl c.A L (GradedWords.ordinaryWords j (T a x l)).2) + (ht : ∀a x,x∈E a→GradedControl c.A L (GradedWords.ordinaryWords j (t a x)).1 ∧ GradedControl c.A L (GradedWords.ordinaryWords j (t a x)).2) + (hw : ∀a x,x∈E a→ClosedWordTestBound j ((I a).implicitCoefficient x) (D a).J c.A M (2*N+5)) + (hd : ∀a x,x∈E a→ClosedWordDiagramBound j ((I a).implicitCoefficient x) (D a).J c.A B (L+2*N+3)) : + ∃K : ℝ,0 ≤ K ∧ ∀a x,x∈E a→SmallBound ((D a).startedSource (w a) (y a) N) x K ∧ + (∀l,SmallBound ((D a).startedPartial (w a) (y a) N l) x K) ∧ + (∑i,|derivativeMatrix ((D a).startedSource (w a) (y a) N) x i i|) ≤ K := by + let W:=c.startedNormBudget j (Fintype.card ι) B₀ + let q:=|j| *c.A + let Cs:=fun a=>if a=0 then C+F else c.startedSourceCost j (Fintype.card ι) (Fintype.card σ) B₀ a + let Cf:=fun a=>if a=0 then q*(C+F)+F else c.startedFieldCost j (Fintype.card ι) B₀ a + let R:=errorBudget q Cs Cf + let V:=startedTraceBudget ((Fintype.card ι:ℝ)*((2+|j|)*Q)) (2+|j| *c.A) W (initialTraceBudget j c.A B₀ Q) + let K:=|W N|+|V N*B+(R N).1*M| + have hWK : W N ≤ K:=(le_abs_self _).trans (le_add_of_nonneg_right (abs_nonneg _)) + have hRK : V N*B+(R N).1*M ≤ K:=(le_abs_self _).trans (le_add_of_nonneg_left (abs_nonneg _)) + refine ⟨K,by dsimp [K];positivity,fun a x hx=>?_⟩ + have hh:=(D a).implicit_started_word_closure (I a) (w a) (y a) (T a x) (t a x) + ((hj a).trans (hij a).symm) (hJ a) x N L c (h a x hx) (hW a x hx) (hWf a x hx) (hY a x hx) (hYf a x hx) + (ha0 a x hx) (hS a x hx) hB₀ hM hB hQ (hw₀ a x hx) (hy₀ a x hx) (hp₀ a x hx) (hP a x hx) (hF' a x hx) + (ha a x hx) (by simpa only [hj a] using hm a x hx) (by simpa only [hj a] using hm₀ a x hx) + (by simpa only [hj a] using hT a x hx) (by simpa only [hj a] using ht a x hx) + (by simpa only [hj a] using hw a x hx) (by simpa only [hj a] using hd a x hx) N le_rfl + rw [hj a,hij a] at hh + have hmean : |j*siteMean (I a).implicitCoefficient x| ≤ q := by + rw [abs_mul] + exact mul_le_mul_of_nonneg_left (coefficient_mean_value (I a).implicitCoefficient x c.A_nonneg (ha a x hx)) (abs_nonneg j) + have hb := errorBudget_mono (mul_nonneg (abs_nonneg j) c.A_nonneg) + (fun k=>show Cs k ≤ Cs k from le_rfl) + (s:=Cs) (f:=fun k=>if k=0 then |j*siteMean (I a).implicitCoefficient x| *(C+F)+F else c.startedFieldCost j (Fintype.card ι) B₀ k) + (f':=Cf) (fun k=>by + dsimp [Cf,q] + split_ifs + · exact add_le_add (mul_le_mul_of_nonneg_right hmean (add_nonneg hC hF)) le_rfl + · rfl) N + refine ⟨hh.1.mono hWK,fun l=>(hh.2.1 l).mono hWK,?_⟩ + exact (hh.2.2.trans (add_le_add le_rfl (mul_le_mul_of_nonneg_right hb.1 hM))).trans hRK + +theorem local_uniform_auxiliary_mean (E : ∀a,Set (Spin (n a))) (D : ∀a,OrdinaryData (n a) ι κ σ) + (T : ∀a,Spin (n a)→ι→SourceTree (Fin (n a)→ℝ)) (N : ℕ) (c : LocalConstants) + (h : ∀a x,x∈flipNeighborhood (E a)→LocalOrdinaryInput (D a) (T a x) x N c) (b : Fin N) : + LocalUniformMultiplier E (fun a=>siteMean ((D a).auxCoefficient N b)) := by + refine ⟨c.A,c.row (Fintype.card ι),c.A_nonneg,c.row_nonneg _, + fun a x hx=>(h a x hx).mean_bound N le_rfl b,fun a x hx=>?_⟩ + have hm:=coefficient_mean_difference ((D a).auxCoefficient N b) x (c.row_nonneg _) + ((h a x (Or.inl hx)).aux_bound N le_rfl b).difference + have hs:=pow_le_pow_left₀ (norm_nonneg _) hm 2 + rw [EuclideanSpace.real_norm_sq_eq] at hs + exact hs + +end SKGapCutoff.Recipe + +end +end + +section + +noncomputable section +open scoped BigOperators Matrix.Norms.Frobenius +namespace SKGapCutoff.Recipe +open Primary Static Matrix SKGap SKGap.Noncrossing SKGap.Noncrossing.Primary SKGap.Noncrossing.Primary.Tensor.Series SKGap.Noncrossing.ClosedMarked +universe u +variable {Ω : Type u} {n : Ω→ℕ} {κ κ₀ σ₀ : Type} [Fintype κ] [DecidableEq κ] [Fintype κ₀] [DecidableEq κ₀] [Fintype σ₀] +variable {M : ℕ} {j : ℝ} {J : ∀a,Interaction (n a)} {h : ∀a,Fin (n a)→ℝ} +variable {E : ∀a,Set (Spin (n a))} {Θ : ∀a,κ→Observables (n a)} {w y : ∀a,VectorFields (n a)} + +theorem finite_started_control (D₀ : ∀a,OrdinaryData (n a) (Fin M) κ Unit) + (K₀ : ℝ) (H₀ : LocalFamilyRecipe E j J h Θ w y D₀ 1 0 K₀) + (I : ∀a,OrdinaryData (n a) Unit κ₀ σ₀) + (hij : ∀a,(I a).j=j) (hIJ : ∀a,(I a).J=J a) + (T : ∀a,Spin (n a)→Fin M→SourceTree (Fin (n a)→ℝ)) + (t : ∀a,Spin (n a)→SourceTree (Fin (n a)→ℝ)) + (c : LocalConstants) (A : ℝ) + (hc : ∀a x,x∈flipNeighborhood (E a)→LocalOrdinaryInput (D₀ a) (T a x) x 1 c) + (index : Fin M→κ) + (hθ : ∀a q,(D₀ a).θ (index q)=fun x=>j*(onsager j (J a) (h a) (q.val+1) x-onsager j (J a) (h a) q.val x)) + (Nmax L : ℕ) (C F B₀ W B Q : ℝ) (hA : 1≤A) + (hC : 0≤C) (hF : 0≤F) (hB₀ : 0≤B₀) (hW : 0≤W) (hB : 0≤B) (hQ : 0≤Q) + (hW₀ : ∀a x,x∈flipNeighborhood (E a)→w a x=(I a).sourceOf 1 (fun _=>y a) x) + (hWf : ∀a x,x∈flipNeighborhood (E a)→∀i,w a (flip x i)=(I a).sourceOf 1 (fun _=>y a) (flip x i)) + (hY₀ : ∀a x,x∈flipNeighborhood (E a)→y a x=(I a).fieldOf 1 (fun _=>w a) (fun _=>y a) x) + (hYf : ∀a x,x∈flipNeighborhood (E a)→∀i,y a (flip x i)=(I a).fieldOf 1 (fun _=>w a) (fun _=>y a) (flip x i)) + (ha0 : ∀a x,x∈flipNeighborhood (E a)→∀i,0≤(I a).implicitCoefficient x i) + (hS : ∀a x,x∈flipNeighborhood (E a)→(1-SKGap.pathDiagonal ((I a).implicitCoefficient x) 1* + ((I a).J-((I a).j*siteMean (I a).implicitCoefficient x) • 1)*SKGap.pathDiagonal ((I a).implicitCoefficient x) 1).PosDef) + (hw₀ : ∀a x,x∈flipNeighborhood (E a)→SmallBound (w a) x B₀) + (hy₀ : ∀a x,x∈flipNeighborhood (E a)→SmallBound (y a) x B₀) + (hp₀ : ∀a x,x∈flipNeighborhood (E a)→vectorNorm ((I a).implicitPartial (y a) x)≤B₀) + (hP : ∀a x,x∈flipNeighborhood (E a)→TraceControl ((I a).implicitSourcePrimitive (t a x) (y a) x) C) + (hF' : ∀a x,x∈flipNeighborhood (E a)→TraceControl ((I a).implicitFieldPrimitive (t a x) (w a) (y a) x) F) + (ha : ∀a x,x∈flipNeighborhood (E a)→∀i,|(I a).implicitCoefficient x i|≤A) + (hm : ∀a x,x∈flipNeighborhood (E a)→∀l,Marked.mass (GradedWords.ordinaryWords j (T a x l)).1≤Q ∧ Marked.mass (GradedWords.ordinaryWords j (T a x l)).2≤Q) + (hm₀ : ∀a x,x∈flipNeighborhood (E a)→Marked.mass (GradedWords.ordinaryWords j (t a x)).1≤Q ∧ Marked.mass (GradedWords.ordinaryWords j (t a x)).2≤Q) + (hT : ∀a x,x∈flipNeighborhood (E a)→∀l,GradedControl A L (GradedWords.ordinaryWords j (T a x l)).1 ∧ GradedControl A L (GradedWords.ordinaryWords j (T a x l)).2) + (ht : ∀a x,x∈flipNeighborhood (E a)→GradedControl A L (GradedWords.ordinaryWords j (t a x)).1 ∧ GradedControl A L (GradedWords.ordinaryWords j (t a x)).2) + (hw : ∀a x,x∈flipNeighborhood (E a)→ClosedWordTestBound j ((I a).implicitCoefficient x) (J a) A W (2*Nmax+5)) + (hd : ∀a x,x∈flipNeighborhood (E a)→ClosedWordDiagramBound j ((I a).implicitCoefficient x) (J a) A B (L+2*Nmax+3)) : + FiniteLocalRecipeControl E j J h Θ w y M Nmax A := by + have transfer {σ : Type} [Fintype σ] (D : ∀a,OrdinaryData (n a) (Fin M) κ σ) + (N p : ℕ) (K : ℝ) (H : LocalFamilyRecipe E j J h Θ w y D N p K) (hKA : K≤A) : + ∃c' : LocalConstants,c'.A=A ∧ ∀a x,x∈flipNeighborhood (E a)→LocalOrdinaryInput (D a) (T a x) x N c' := by + obtain ⟨S,hS,hs⟩:=H.seed + refine ⟨c.withCoefficient A S hA hS,rfl,fun a x hx=>?_⟩ + obtain ⟨hJ,hj,hH,hp,hθ'⟩:=H.sameEnvironment H₀ a + exact (hc a x hx).with_coefficients (D a) hJ hj hH hp hθ' N A S hA hS (hs a) + ((H.coefficients a x hx).mono hKA) + constructor + · intro σ inst D N p K H hN hKA + obtain ⟨c',hAc',hi⟩:=transfer D N p K H hKA + apply uniform_started_control (fun a=>flipNeighborhood (E a)) D I w y T t N L c' j H.coupling hij + (fun a=>(H.interaction a).trans (hIJ a).symm) hi hW₀ hWf hY₀ hYf ha0 hS hB₀ hW hB hQ hC hF hw₀ hy₀ hp₀ hP hF' + · simpa only [hAc'] using ha + · exact hm + · exact hm₀ + · simpa only [hAc'] using hT + · simpa only [hAc'] using ht + · intro a x hx v hl hi hb + rw [H.interaction a,hAc'] at * + exact hw a x hx v (hl.trans (by omega)) hi hb + · intro a x hx v hl hi hb + rw [H.interaction a,hAc'] at * + exact hd a x hx v (hl.trans (by omega)) hi hb + · intro σ inst D N p K H hN hKA b + obtain ⟨c',hAc',hi⟩:=transfer D N p K H hKA + exact local_uniform_auxiliary_mean E D T N c' hi b + · intro q + refine ⟨|j|,c.V,abs_nonneg _,c.V_nonneg, + fun a x hx=>onsager_parameter_bound j (J a) (h a) q.val x,fun a x hx=>?_⟩ + have hh' : ‖derivativeVector ((D₀ a).θ (index q)) x‖≤c.V := + (Finset.single_le_sum (fun r _=>norm_nonneg (derivativeVector ((D₀ a).θ r) x)) + (Finset.mem_univ (index q))).trans (hc a x (Or.inl hx)).parameter + have hs:=pow_le_pow_left₀ (norm_nonneg _) hh' 2 + rw [hθ a q,EuclideanSpace.real_norm_sq_eq] at hs + exact hs + +end SKGapCutoff.Recipe + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/UnitBall.lean b/lean/OAI/Probability/SKGap/Localization/UnitBall.lean new file mode 100644 index 0000000000000000000000000000000000000000..2883bb6029f0ecdbdfff1fbdd618c9e68dcd98fe --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/UnitBall.lean @@ -0,0 +1,315 @@ +import Mathlib +import OAI.Probability.SKGap.Gaussian.GaussianQuadraticSupComparison +import OAI.Probability.SKGap.Localization.DiagonalSqrt +import OAI.Probability.SKGap.Gaussian.GaussianQuadratic + +namespace OAI + +section +noncomputable section +open MeasureTheory ProbabilityTheory InformationTheory Real Set +open scoped NNReal ENNReal +open Filter +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius ENNReal NNReal +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius NNReal +noncomputable section +open MeasureTheory ProbabilityTheory Real Set Filter +open MeasureTheory.Measure +open scoped ENNReal NNReal MeasureTheory Topology +open MeasureTheory +noncomputable section +noncomputable section +open MeasureTheory Set NormedSpace +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius +noncomputable section +open Set Real +open scoped Topology +noncomputable section +open Matrix Set Filter +open scoped Topology Matrix.Norms.Frobenius +noncomputable section +open Matrix NormedSpace ContinuousLinearMap +open scoped Matrix.Norms.Frobenius +noncomputable section +open Matrix +noncomputable section +open MeasureTheory ProbabilityTheory Real Set +open scoped ENNReal NNReal +noncomputable section +open MeasureTheory ProbabilityTheory InformationTheory Real Set +open scoped NNReal ENNReal +noncomputable section +open scoped BigOperators +open MeasureTheory ProbabilityTheory +open Real +namespace SKGap +lemma quadratic_interpolation {z q v c : ℝ} (hz0 : 0 ≤ z) (hz1 : z ≤ 1) + (hc : 0 ≤ c) (hqc : q*v ≤ c) {X : ℝ} (hX : X - q*v ≤ c) : + z*X-z^2*q*v ≤ c := by + have h1 := mul_le_mul_of_nonneg_left hX hz0 + have h2 := mul_le_mul_of_nonneg_left hqc (mul_nonneg hz0 (sub_nonneg.mpr hz1)) + have h3 := mul_nonneg hc (sq_nonneg (1-z)) + nlinarith only [h1, h2, h3] + +section DiagonalProcess +variable {ι : Type*} [Fintype ι] + +abbrev UnitBall (ι : Type*) [Fintype ι] := + ↥(Metric.closedBall (0 : EuclideanSpace ℝ ι) 1) + +instance : Nonempty (UnitBall ι) := ⟨⟨0, by simp⟩⟩ + +lemma norm_UnitBall_le (p : UnitBall ι) : ‖(p : EuclideanSpace ℝ ι)‖ ≤ 1 := by + simpa only [Metric.mem_closedBall, dist_zero_right] using p.property + +def diagonalOffset (a : ι → ℝ) (z q : ℝ) (p : UnitBall ι) : ℝ := + -z^2 * q * ‖diagonalSqrt a p‖^2 + +def diagonalProcess (r : ℝ) (a : ι → ℝ) (z q : ℝ) + (g : MatrixCoordinates ι → ℝ) : ℝ := + gaussianSup (diagonalOffset a z q) + (fun p k => z * quadraticCoeff r (diagonalSqrt a p) k) g + +def diagonalLinearProcess (r : ℝ) (a : ι → ℝ) (z q : ℝ) + (g : MatrixCoordinates ι → ℝ) : ℝ := + gaussianSup (diagonalOffset a z q) + (fun p k => z * linearCoeff r (diagonalSqrt a p) k) g + +def diagonalWeights (r : ℝ) (a : ι → ℝ) : MatrixCoordinates ι → ℝ + | Sum.inl _ => 0 + | Sum.inr i => r * a i + +def diagonalT (r : ℝ) (a : ι → ℝ) (g : MatrixCoordinates ι → ℝ) : ℝ := + sqrt (gaussianQuadratic (diagonalWeights r a) g) + +lemma continuous_diagonalOffset (a : ι → ℝ) (z q : ℝ) : + Continuous (diagonalOffset a z q) := by + exact continuous_const.mul (((continuous_diagonalSqrt a).comp continuous_subtype_val).norm.pow 2) + +lemma continuous_diagonalCoeff {f : EuclideanSpace ℝ ι → MatrixCoordinates ι → ℝ} + (hf : Continuous f) (a : ι → ℝ) (z : ℝ) : + Continuous (fun p : UnitBall ι => fun k => z * f (diagonalSqrt a p) k) := by + apply continuous_pi + intro k + exact continuous_const.mul ((continuous_apply k).comp + (hf.comp ((continuous_diagonalSqrt a).comp continuous_subtype_val))) + +lemma integrable_diagonalProcess (r : ℝ) (a : ι → ℝ) (z q : ℝ) : + Integrable (diagonalProcess r a z q) (gaussianCoordinates (MatrixCoordinates ι)) := + integrable_gaussianSup (continuous_diagonalOffset a z q) + (continuous_diagonalCoeff (continuous_quadraticCoeff r) a z) + +lemma integrable_diagonalLinearProcess (r : ℝ) (a : ι → ℝ) (z q : ℝ) : + Integrable (diagonalLinearProcess r a z q) (gaussianCoordinates (MatrixCoordinates ι)) := + integrable_gaussianSup (continuous_diagonalOffset a z q) + (continuous_diagonalCoeff (continuous_linearCoeff r) a z) + +lemma diagonalT_norm {r : ℝ} (hr : 0 ≤ r) {a : ι → ℝ} (ha : ∀ i, 0 ≤ a i) + (g : MatrixCoordinates ι → ℝ) : + diagonalT r a g = sqrt r * ‖diagonalSqrt a (WithLp.toLp 2 (fun i => g (.inr i)))‖ := by + unfold diagonalT gaussianQuadratic + rw [Fintype.sum_sum_type] + simp only [diagonalWeights, zero_mul, Finset.sum_const_zero, zero_add] + simp_rw [mul_assoc] + rw [← Finset.mul_sum, Real.sqrt_mul hr] + have he := diagonalSqrt_norm_sq a ha (WithLp.toLp 2 (fun i => g (.inr i))) + rw [← he, Real.sqrt_sq (norm_nonneg _)] + +lemma diagonalWeights_sum (r : ℝ) (a : ι → ℝ) : + (∑ k, diagonalWeights r a k) = r * ∑ i, a i := by + simp only [Fintype.sum_sum_type, diagonalWeights, Finset.sum_const_zero, zero_add, + Finset.mul_sum] + +lemma diagonalWeights_sum_sq (r : ℝ) (a : ι → ℝ) : + (∑ k, (diagonalWeights r a k)^2) = r^2 * ∑ i, (a i)^2 := by + simp only [Fintype.sum_sum_type, diagonalWeights, zero_pow (by norm_num : (2:ℕ)≠0), + Finset.sum_const_zero, zero_add, mul_pow, Finset.mul_sum] + +lemma diagonalT_integrable {r : ℝ} (hr : 0 ≤ r) {a : ι → ℝ} (ha : ∀ i, 0 ≤ a i) : + Integrable (diagonalT r a) (gaussianCoordinates (MatrixCoordinates ι)) := by + apply (memLp_sqrt_of_nonneg ((gaussianQuadratic_memLp (diagonalWeights r a)).integrable + (by norm_num)) ?_).integrable (by norm_num) + intro g + apply Finset.sum_nonneg + intro k _ + apply mul_nonneg _ (sq_nonneg _) + cases k <;> simp only [diagonalWeights] + · exact le_rfl + · exact mul_nonneg hr (ha _) + +lemma diagonalT_fluctuation {r : ℝ} (hr : 0 ≤ r) {a : ι → ℝ} (ha : ∀ i, 0 ≤ a i) : + (∫ g, |diagonalT r a g - sqrt (r * ∑ i, a i)| + ∂gaussianCoordinates (MatrixCoordinates ι)) ≤ + sqrt (sqrt (2*r^2 * ∑ i, (a i)^2)) := by + have hp (g) : 0 ≤ gaussianQuadratic (diagonalWeights r a) g := by + apply Finset.sum_nonneg + intro k _ + apply mul_nonneg _ (sq_nonneg _) + cases k <;> simp only [diagonalWeights] + · exact le_rfl + · exact mul_nonneg hr (ha _) + have h := integral_sqrt_fluctuation (gaussianQuadratic_memLp (diagonalWeights r a)) hp + rw [gaussianQuadratic_mean, gaussianQuadratic_variance, + diagonalWeights_sum, diagonalWeights_sum_sq, ← mul_assoc] at h + exact h + +lemma diagonalLinearProcess_le {r z q A b : ℝ} {a : ι → ℝ} + (hr : 0 ≤ r) (ha : ∀ i, 0 ≤ a i) (hA : ∀ i, a i ≤ A) (hA0 : 0 ≤ A) + (hz0 : 0 ≤ z) (hz1 : z ≤ 1) (hq : 0 ≤ q) + (hqb : sqrt q * sqrt A ≤ b) (hb : b ≤ 1) + (g : MatrixCoordinates ι → ℝ) : + diagonalLinearProcess r a z q g ≤ + 1-(1-b)^2 + 2 * sqrt A * |diagonalT r a g - sqrt q| := by + unfold diagonalLinearProcess + apply gaussianSup_le (continuous_diagonalOffset a z q) + (continuous_diagonalCoeff (continuous_linearCoeff r) a z) + intro p + let w := diagonalSqrt a p + let v := ‖w‖ + have hv0 : 0 ≤ v := norm_nonneg _ + have hv : v ≤ sqrt A := diagonalSqrt_norm_le_sqrt ha hA0 hA (norm_UnitBall_le p) + have hdot := diagonal_sum_mul_le_norm a (p : EuclideanSpace ℝ ι) + (WithLp.toLp 2 (fun i => g (.inr i))) + have hdot' : (∑ i, w i * g (.inr i)) ≤ + ‖diagonalSqrt a (WithLp.toLp 2 (fun i => g (.inr i)))‖ := + hdot.trans ((mul_le_mul_of_nonneg_right (norm_UnitBall_le p) (norm_nonneg _)).trans_eq + (one_mul _)) + have hcoeff : (∑ k, (z * linearCoeff r w k) * g k) = + 2*z*sqrt r*v * (∑ i, w i * g (.inr i)) := by + simp only [Fintype.sum_sum_type, linearCoeff, mul_zero, zero_mul, + Finset.sum_const_zero, zero_add, Finset.mul_sum] + apply Finset.sum_congr rfl + intro i _ + dsimp [v] + ring + have hlin := mul_le_mul_of_nonneg_left hdot' (show 0 ≤ 2*z*sqrt r*v by positivity) + have hT := diagonalT_norm hr ha g + have hlin' : (∑ k, (z * linearCoeff r w k) * g k) ≤ 2*z*v*diagonalT r a g := by + rw [hcoeff, hT] + nlinarith only [hlin] + have hd0 : 0 ≤ z * sqrt q * v := by positivity + have hzb : z * sqrt q * v ≤ b := by + calc + _ ≤ sqrt q * v := by nlinarith [mul_nonneg (sqrt_nonneg q) hv0] + _ ≤ sqrt q * sqrt A := mul_le_mul_of_nonneg_left hv (sqrt_nonneg q) + _ ≤ b := hqb + have hmargin := quadratic_margin hd0 hzb hb + have hs := sq_sqrt hq + have hab := le_abs_self (diagonalT r a g - sqrt q) + have hvz : z*v ≤ sqrt A := (mul_le_of_le_one_left hv0 hz1).trans hv + have herr : 2*z*v*(diagonalT r a g - sqrt q) ≤ + 2*sqrt A*|diagonalT r a g - sqrt q| := by + exact (mul_le_mul_of_nonneg_left hab (by positivity)).trans + (mul_le_mul_of_nonneg_right (by nlinarith) (abs_nonneg _)) + change -z^2*q*v^2 + (∑ k, (z * linearCoeff r w k) * g k) ≤ _ + nlinarith only [hlin', hmargin, herr, hs, sq_nonneg (z*v)] + +theorem diagonalProcess_expected_margin [Nonempty ι] + {r z A b : ℝ} {a : ι → ℝ} + (hr : 0 ≤ r) (ha : ∀ i, 0 ≤ a i) (hA : ∀ i, a i ≤ A) (hA0 : 0 ≤ A) + (hz0 : 0 ≤ z) (hz1 : z ≤ 1) + (hqb : sqrt (r * ∑ i, a i) * sqrt A ≤ b) (hb : b ≤ 1) : + (∫ g, diagonalProcess r a z (r * ∑ i, a i) g + ∂gaussianCoordinates (MatrixCoordinates ι)) ≤ + 1-(1-b)^2 + 2*sqrt A * sqrt (sqrt (2*r^2 * ∑ i, (a i)^2)) := by + let q := r * ∑ i, a i + have hq : 0 ≤ q := mul_nonneg hr (Finset.sum_nonneg (fun i _ => ha i)) + have hcomp := gaussian_quadraticSup_comparison + (continuous_diagonalOffset a z q) + ((continuous_diagonalSqrt a).comp continuous_subtype_val) hr z + have hfluct := diagonalT_fluctuation hr ha + have hi : Integrable (fun g => |diagonalT r a g - sqrt q|) + (gaussianCoordinates (MatrixCoordinates ι)) := + ((diagonalT_integrable hr ha).sub (integrable_const _)).abs + have hbound : (∫ g, diagonalLinearProcess r a z q g + ∂gaussianCoordinates (MatrixCoordinates ι)) ≤ + 1-(1-b)^2 + 2*sqrt A * + (∫ g, |diagonalT r a g - sqrt q| ∂gaussianCoordinates (MatrixCoordinates ι)) := by + calc + _ ≤ ∫ g, (1-(1-b)^2 + 2*sqrt A*|diagonalT r a g - sqrt q|) + ∂gaussianCoordinates (MatrixCoordinates ι) := + integral_mono (integrable_diagonalLinearProcess r a z q) + ((integrable_const _).add (hi.const_mul _)) + (diagonalLinearProcess_le hr ha hA hA0 hz0 hz1 hq hqb hb) + _ = _ := by rw [integral_add (integrable_const _) (hi.const_mul _), + integral_const, probReal_univ, one_smul, integral_const_mul] + exact hcomp.trans (hbound.trans (add_le_add le_rfl + (mul_le_mul_of_nonneg_left hfluct (show 0 ≤ 2*sqrt A by positivity)))) + +lemma diagonalProcess_lipschitz {r z A : ℝ} {a : ι → ℝ} + (hr : 0 ≤ r) (ha : ∀ i, 0 ≤ a i) (hA : ∀ i, a i ≤ A) (hA0 : 0 ≤ A) + (hz : 0 ≤ z) (q : ℝ) : + LipschitzWith (Real.toNNReal (z * sqrt (2*r) * A)) + (fun g : EuclideanSpace ℝ (MatrixCoordinates ι) => + diagonalProcess r a z q g.ofLp) := by + apply gaussianSup_lipschitz (continuous_diagonalOffset a z q) + (continuous_diagonalCoeff (continuous_quadraticCoeff r) a z) + intro p + have hsq := diagonalSqrt_norm_sq_le ha hA (p : EuclideanSpace ℝ ι) + have hp2 : ‖(p : EuclideanSpace ℝ ι)‖^2 ≤ 1 := by + nlinarith [norm_UnitBall_le p, norm_nonneg (p : EuclideanSpace ℝ ι)] + have hw : ‖diagonalSqrt a p‖^2 ≤ A := + hsq.trans ((mul_le_mul_of_nonneg_left hp2 hA0).trans_eq (mul_one A)) + have he : WithLp.toLp 2 (fun k => z * quadraticCoeff r (diagonalSqrt a p) k) = + z • WithLp.toLp 2 (quadraticCoeff r (diagonalSqrt a p)) := rfl + rw [he, norm_smul, Real.norm_eq_abs, abs_of_nonneg hz, quadraticCoeff_norm hr, + Real.toNNReal_of_nonneg (by positivity)] + simpa only [mul_assoc, NNReal.coe_mk] using + mul_le_mul_of_nonneg_left hw (show 0 ≤ z * sqrt (2*r) by positivity) + +theorem diagonalProcess_path_le {r A q c : ℝ} {a : ι → ℝ} + (ha : ∀ i, 0 ≤ a i) (hA : ∀ i, a i ≤ A) (hA0 : 0 ≤ A) + (hq : 0 ≤ q) (hc : 0 ≤ c) (hqc : q*A ≤ c) + {g : MatrixCoordinates ι → ℝ} (hg : diagonalProcess r a 1 q g ≤ c) + {z : ℝ} (hz0 : 0 ≤ z) (hz1 : z ≤ 1) : + diagonalProcess r a z q g ≤ c := by + apply gaussianSup_le (continuous_diagonalOffset a z q) + (continuous_diagonalCoeff (continuous_quadraticCoeff r) a z) + intro p + let w := diagonalSqrt a p + let v := ‖w‖^2 + let X := ∑ k, quadraticCoeff r w k * g k + have hp2 : ‖(p : EuclideanSpace ℝ ι)‖^2 ≤ 1 := by + nlinarith [norm_UnitBall_le p, norm_nonneg (p : EuclideanSpace ℝ ι)] + have hv : v ≤ A := (diagonalSqrt_norm_sq_le ha hA _).trans + ((mul_le_mul_of_nonneg_left hp2 hA0).trans_eq (mul_one A)) + have hqv : q*v ≤ c := (mul_le_mul_of_nonneg_left hv hq).trans hqc + have hX : X - q*v ≤ c := by + have h := (gaussianAffine_le_gaussianSup (continuous_diagonalOffset a 1 q) + (continuous_diagonalCoeff (continuous_quadraticCoeff r) a 1) g p).trans hg + simp only [gaussianAffine, diagonalOffset, one_mul, one_pow, neg_mul] at h + simpa only [sub_eq_add_neg, add_comm, X, v, w] using h + have h := quadratic_interpolation hz0 hz1 hc hqv hX + convert h using 1 + simp only [gaussianAffine, diagonalOffset, X, v, w, Finset.mul_sum] + simp_rw [mul_assoc] + ring + +end DiagonalProcess +end SKGap + +end +end +end +end +end +end +end +end +end +end +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/UpperClockTendstoTop.lean b/lean/OAI/Probability/SKGap/Localization/UpperClockTendstoTop.lean new file mode 100644 index 0000000000000000000000000000000000000000..8ca4f54e8fd6d8aba541d5c8bd013f25eda8e870 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/UpperClockTendstoTop.lean @@ -0,0 +1,258 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.PoissonBinomialProbability + +namespace OAI + +section +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open scoped BigOperators +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open scoped BigOperators +open scoped BigOperators NNReal ENNReal +open MeasureTheory Metric Set +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators NNReal ENNReal Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Set +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators ENNReal NNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Matrix +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators ENNReal NNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal +open scoped BigOperators +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise NNReal ENNReal +open scoped BigOperators +open Filter Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal Topology +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Set Matrix +open scoped BigOperators NNReal ENNReal Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open Filter MeasureTheory ProbabilityTheory +open scoped Topology NNReal ENNReal +open Filter MeasureTheory ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter +open scoped Topology NNReal ENNReal +open MeasureTheory Filter ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter +open scoped Topology +open MeasureTheory Filter ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter ProbabilityTheory ContinuousLinearMap +open scoped Topology NNReal ENNReal +open Filter MeasureTheory ProbabilityTheory +open scoped Topology NNReal ENNReal +namespace SKGapCutoff + +lemma upperClock_tendsto_atTop {rate ε : ℝ} (hrate : 0 < rate) (hε : 0 < ε) : + Tendsto (fun n : ℕ => ⌈(1+ε)*(n:ℝ)*cutoffTime rate n⌉₊) atTop atTop := by + apply tendsto_nat_ceil_atTop.comp + exact (tendsto_natCast_atTop_atTop.const_mul_atTop (by linarith : 0 < 1+ε)).atTop_mul_atTop₀ + (cutoffTime_tendsto_atTop hrate) + +lemma upperClock_shifted_time {rate ε q : ℝ} (hrate : 0 < rate) (hε : 0 < ε) + (hq : 0 < q) (y : ℝ) : + ∀ᶠ n : ℕ in atTop, (1+ε/2)*cutoffTime rate n ≤ + (q*(⌈(1+ε)*(n:ℝ)*cutoffTime rate n⌉₊:ℝ)+ + y*Real.sqrt (⌈(1+ε)*(n:ℝ)*cutoffTime rate n⌉₊:ℝ))/(q*n) := by + let M : ℕ → ℕ := fun n => ⌈(1+ε)*(n:ℝ)*cutoffTime rate n⌉₊ + let c := q*ε/(2*(1+ε)) + have hc : 0 < c := by dsimp [c]; positivity + have hcq : c < q := by + dsimp [c] + apply (div_lt_iff₀ (by positivity : 0 < 2*(1+ε))).mpr + nlinarith + have hs : Tendsto (fun n => c*Real.sqrt (M n : ℝ)) atTop atTop := by + exact (Real.tendsto_sqrt_atTop.comp (tendsto_natCast_atTop_atTop.comp + (upperClock_tendsto_atTop hrate hε))).const_mul_atTop hc + filter_upwards [eventually_ge_atTop 1, hs.eventually_ge_atTop |y|] with n hn hy + have hn' : (0:ℝ) < n := Nat.cast_pos.mpr (by omega) + have hM : (1+ε)*(n:ℝ)*cutoffTime rate n ≤ (M n:ℝ) := Nat.le_ceil _ + have hsq : Real.sqrt (M n:ℝ)^2 = (M n:ℝ) := Real.sq_sqrt (Nat.cast_nonneg _) + have herr : -c*(M n:ℝ) ≤ y*Real.sqrt (M n:ℝ) := by + have hh := mul_le_mul_of_nonneg_right hy (Real.sqrt_nonneg (M n:ℝ)) + have hy' := mul_le_mul_of_nonneg_right (neg_abs_le y) (Real.sqrt_nonneg (M n:ℝ)) + nlinarith + apply (le_div_iff₀ (mul_pos hq hn')).mpr + have hmain := mul_le_mul_of_nonneg_left hM (sub_pos.mpr hcq).le + have hid : (q-c)*(1+ε) = q*(1+ε/2) := by + dsimp [c] + field_simp + ring + change _ ≤ q*(M n:ℝ)+y*Real.sqrt (M n:ℝ) + calc + _ = (q-c)*((1+ε)*(n:ℝ)*cutoffTime rate n) := by + calc + _ = ((q-c)*(1+ε))*(n:ℝ)*cutoffTime rate n := by rw [hid]; ring + _ = _ := by ring + _ ≤ (q-c)*(M n:ℝ) := hmain + _ ≤ _ := by nlinarith + +end SKGapCutoff + +namespace SKGapCutoff + +abbrev BoundedTVTest (n : ℕ) := Spin n × {f : Observables n // ∀ x, |f x| ≤ 1} + +theorem discrete_upper_of_holding {β rate ε q : ℝ} (hrate : 0 < rate) + (hε : 0 < ε) (hq : 0 < q) (hq1 : q < 1) + (good : (n : ℕ) → GaussianCoordinates n → Prop) + (hgood : Tendsto (fun n => disorderLaw β n {g | ¬good n g}) atTop (𝓝 0)) + (hhold : ∀ n, 0 < n → ∀ g, good n g → ∀ x, + 1-q ≤ discreteKernel (sampledInteraction g) 1 x x) + (hcont : DisorderLimit β + (fun n J => worstContinuous J ((1+ε/2)*cutoffTime rate n)) 0) : + DisorderLimit β (fun n J => worstDiscrete J + ⌈(1+ε)*(n:ℝ)*cutoffTime rate n⌉₊) 0 := by + let M : ℕ → ℕ := fun n => ⌈(1+ε)*(n:ℝ)*cutoffTime rate n⌉₊ + let a : (n : ℕ) → GaussianCoordinates n → BoundedTVTest n → ℕ → ℝ := + fun n g i j => (residualAttempt (sampledInteraction g) q ^ j) i.2.val i.1 - + gibbsExpectation (sampledInteraction g) i.2.val + let good' : (n : ℕ) → GaussianCoordinates n → Prop := fun n g => 0 < n ∧ good n g + have hgood' : Tendsto (fun n => disorderLaw β n {g | ¬good' n g}) atTop (𝓝 0) := by + apply hgood.congr' + filter_upwards [eventually_ge_atTop 1] with n hn + congr 1 + ext g + simp only [good',show 0 < n by omega,true_and] + have hab : ∀ n g, good' n g → ∀ i j, |a n g i j| ≤ 2 := by + intro n g hg i j + exact residual_test_bound (sampledInteraction g) hq (hhold n hg.1 g hg.2) + i.2.val i.2.property i.1 j + have hp : ∀ y δ : ℝ, 0 < δ → Tendsto (fun n => disorderLaw β n + {g | good' n g ∧ ∃ i, δ < |∑' j, + Clock.poissonMass (q*M n+y*Real.sqrt (M n)) j*a n g i j|}) atTop (𝓝 0) := by + intro y δ hδ + apply tendsto_const_nhds.squeeze' (hcont (δ/2) (by positivity)) + (Eventually.of_forall (fun _ => zero_le)) + filter_upwards [upperClock_shifted_time hrate hε hq y,eventually_ge_atTop 1] with n hs hn + have hn' : 0 < n := by omega + apply measure_mono + rintro g ⟨_hg,i,hi⟩ + have he := residual_poisson_test hn' (sampledInteraction g) hq.ne' + (q*(M n:ℝ)+y*Real.sqrt (M n:ℝ)) i.2.val i.1 + change _ < |∑' j, Clock.poissonMass (q*M n+y*Real.sqrt (M n)) j* + ((residualAttempt (sampledInteraction g) q ^ j) i.2.val i.1- + gibbsExpectation (sampledInteraction g) i.2.val)| at hi + rw [he] at hi + have hb := (continuous_test_bound (sampledInteraction g) _ i.2.val i.2.property i.1).trans + (mul_le_mul_of_nonneg_left (worstContinuous_mono_time (sampledInteraction g) hs) (by norm_num : (0:ℝ)≤2)) + change δ/2 < |worstContinuous (sampledInteraction g) ((1+ε/2)*cutoffTime rate n)-0| + rw [sub_zero,abs_of_nonneg (worstContinuous_nonneg _ _)] + linarith + have hbin := Clock.poisson_to_binomial_in_probability hq hq1 (by norm_num : (0:ℝ)<2) + (disorderLaw β) good' hgood' (fun n _ => M n) + (fun K => ((upperClock_tendsto_atTop hrate hε).eventually_ge_atTop K).mono (fun n hn _ _ => hn)) a hab hp + intro δ hδ + apply tendsto_const_nhds.squeeze' (hbin δ hδ) (Eventually.of_forall (fun _ => zero_le)) + apply Eventually.of_forall + intro n + apply measure_mono + intro g hg + obtain ⟨x,f,hf,he⟩ := worstDiscrete_has_test (sampledInteraction g) (M n) + refine ⟨(x,⟨f,hf⟩),?_⟩ + change δ < |∑' j, Clock.binomialMass q (M n) j* + ((residualAttempt (sampledInteraction g) q ^ j) f x- + gibbsExpectation (sampledInteraction g) f)| + rw [residual_binomial_test (sampledInteraction g) hq.ne' (M n) f x,he] + change δ < |worstDiscrete (sampledInteraction g) (M n)-0| at hg + rw [sub_zero] at hg + rw [abs_mul,abs_of_pos (by norm_num : (0:ℝ)<2)] + linarith [abs_nonneg (worstDiscrete (sampledInteraction g) (M n))] + +end SKGapCutoff + +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/UpperCoefficient.lean b/lean/OAI/Probability/SKGap/Localization/UpperCoefficient.lean new file mode 100644 index 0000000000000000000000000000000000000000..46dbcc790c1665a5d2297b45d3e10f2f77aaaaac --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/UpperCoefficient.lean @@ -0,0 +1,341 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.Magnetization + +namespace OAI + +section +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +namespace SKGapCutoff + +noncomputable def upperCoefficient {n : ℕ} (x : Spin n) (p : Fin n × Fin n) : ℝ := + if p.1 < p.2 then spin x p.1 * spin x p.2 else 0 + +lemma energy_sampled {n : ℕ} (g : GaussianCoordinates n) (x : Spin n) : + energy (sampledInteraction g) x = ∑ p, upperCoefficient x p * g p := by + have hp (i j : Fin n) : + spin x i * sampledInteraction g i j * spin x j = + upperCoefficient x (i,j) * g (i,j) + upperCoefficient x (j,i) * g (j,i) := by + rcases lt_trichotomy i j with h | h | h + · simp [sampledInteraction, upperCoefficient, ne_of_lt h, h, + not_lt_of_ge (le_of_lt h), min_eq_left (le_of_lt h), max_eq_right (le_of_lt h)] + ring + · subst j + simp [sampledInteraction, upperCoefficient] + · simp [sampledInteraction, upperCoefficient, ne_of_gt h, h, + not_lt_of_ge (le_of_lt h), min_eq_right (le_of_lt h), max_eq_left (le_of_lt h)] + ring + unfold energy + simp_rw [hp] + rw [Fintype.sum_prod_type] + simp only [Finset.sum_add_distrib] + rw [Finset.sum_comm (f := fun i j => upperCoefficient x (j, i) * g (j, i))] + ring + +lemma integral_exp_gaussian_linear {ι : Type*} [Fintype ι] (v : ℝ≥0) (a : ι → ℝ) : + (∫ g : ι → ℝ, Real.exp (∑ p, a p * g p) + ∂Measure.pi (fun _ => gaussianReal 0 v)) = + Real.exp (v * (∑ p, a p ^ 2) / 2) := by + simp_rw [Real.exp_sum] + rw [integral_fintype_prod_eq_prod (fun p z => Real.exp (a p * z))] + have h (p : ι) : (∫ z : ℝ, Real.exp (a p * z) ∂gaussianReal 0 v) = + Real.exp (v * a p ^ 2 / 2) := by + have he := congrFun (mgf_fun_id_gaussianReal (μ := 0) (v := v)) (a p) + simpa [mgf] using he + simp_rw [h] + rw [← Real.exp_sum] + congr 1 + simp [Finset.mul_sum, Finset.sum_div] + +lemma integrable_exp_gaussian_linear {ι : Type*} [Fintype ι] (v : ℝ≥0) + (a : ι → ℝ) : + Integrable (fun g : ι → ℝ => Real.exp (∑ p, a p * g p)) + (Measure.pi (fun _ => gaussianReal 0 v)) := by + simpa only [Real.exp_sum] using + (Integrable.fintype_prod (fun p => integrable_exp_mul_gaussianReal (μ := 0) (v := v) (a p))) + +lemma sum_upperCoefficient_sq {n : ℕ} (x : Spin n) : + ∑ p, upperCoefficient x p ^ 2 = (n : ℝ) * (n - 1) / 2 := by + have hp (i j : Fin n) : upperCoefficient x (i,j) ^ 2 + + upperCoefficient x (j,i) ^ 2 = 1 - if i = j then 1 else 0 := by + rcases lt_trichotomy i j with h | h | h + · simp [upperCoefficient, h, not_lt_of_ge (le_of_lt h), ne_of_lt h, + mul_pow, spin_sq] + · subst j; simp [upperCoefficient] + · simp [upperCoefficient, h, not_lt_of_ge (le_of_lt h), ne_of_gt h, + mul_pow, spin_sq] + have hs := congrArg (fun f : Fin n → Fin n → ℝ => ∑ i, ∑ j, f i j) + (funext fun i => funext fun j => hp i j) + simp only [Finset.sum_add_distrib, Finset.sum_sub_distrib] at hs + rw [Finset.sum_comm (f := fun i j => upperCoefficient x (j,i) ^ 2)] at hs + simp only [Finset.sum_const, Finset.card_univ, Fintype.card_fin, nsmul_eq_mul, + mul_one, Fintype.sum_ite_eq, Finset.sum_const] at hs + rw [Fintype.sum_prod_type] + nlinarith + +noncomputable def replicaOverlap {n : ℕ} (x y : Spin n) : ℝ := + ∑ i, spin x i * spin y i + +lemma sum_upperCoefficient_mul {n : ℕ} (x y : Spin n) : + ∑ p, upperCoefficient x p * upperCoefficient y p = + (replicaOverlap x y ^ 2 - n) / 2 := by + have hp (i j : Fin n) : upperCoefficient x (i,j) * upperCoefficient y (i,j) + + upperCoefficient x (j,i) * upperCoefficient y (j,i) = + (spin x i * spin y i) * (spin x j * spin y j) - if i = j then 1 else 0 := by + rcases lt_trichotomy i j with h | h | h + · simp [upperCoefficient, h, not_lt_of_ge (le_of_lt h), ne_of_lt h] + ring + · subst j + simp [upperCoefficient, mul_pow, ← sq, spin_sq] + · simp [upperCoefficient, h, not_lt_of_ge (le_of_lt h), ne_of_gt h] + ring + have hs := congrArg (fun f : Fin n → Fin n → ℝ => ∑ i, ∑ j, f i j) + (funext fun i => funext fun j => hp i j) + simp only [Finset.sum_add_distrib, Finset.sum_sub_distrib] at hs + rw [Finset.sum_comm (f := fun i j => upperCoefficient x (j,i) * upperCoefficient y (j,i))] at hs + simp only [Fintype.sum_ite_eq, Finset.sum_const, Finset.card_univ, + Fintype.card_fin, nsmul_eq_mul, mul_one] at hs + simp only [← Finset.mul_sum, ← Finset.sum_mul] at hs + rw [Fintype.sum_prod_type] + unfold replicaOverlap + nlinarith + +lemma integrable_exp_energy_sampled (β : ℝ) {n : ℕ} (x : Spin n) : + Integrable (fun g => Real.exp (energy (sampledInteraction g) x)) (disorderLaw β n) := by + simp_rw [energy_sampled] + exact integrable_exp_gaussian_linear _ _ + +lemma integral_exp_energy_sampled (β : ℝ) {n : ℕ} (hn : 0 < n) (x : Spin n) : + (∫ g, Real.exp (energy (sampledInteraction g) x) ∂disorderLaw β n) = + Real.exp (β ^ 2 * (n - 1) / 4) := by + simp_rw [energy_sampled] + unfold disorderLaw + rw [integral_exp_gaussian_linear _ (upperCoefficient x), sum_upperCoefficient_sq] + rw [Real.coe_toNNReal _ (div_nonneg (sq_nonneg _) (Nat.cast_nonneg _))] + congr 1 + have hn0 : (n : ℝ) ≠ 0 := by exact_mod_cast (ne_of_gt hn) + field_simp + ring + +lemma integrable_partition_sampled (β : ℝ) (n : ℕ) : + Integrable (fun g => partition (sampledInteraction g)) (disorderLaw β n) := by + exact integrable_finsetSum _ (fun x _ => integrable_exp_energy_sampled β x) + +lemma integral_partition_sampled (β : ℝ) {n : ℕ} (hn : 0 < n) : + (∫ g, partition (sampledInteraction g) ∂disorderLaw β n) = + (2 : ℝ) ^ n * Real.exp (β ^ 2 * (n - 1) / 4) := by + unfold partition + rw [integral_finsetSum _ (fun x _ => integrable_exp_energy_sampled β x)] + simp only [integral_exp_energy_sampled β hn, Finset.sum_const, Finset.card_univ, + card_spin, nsmul_eq_mul, Nat.cast_pow, Nat.cast_ofNat] + +lemma sum_upperCoefficient_add_sq {n : ℕ} (x y : Spin n) : + ∑ p, (upperCoefficient x p + upperCoefficient y p) ^ 2 = + (n : ℝ) ^ 2 - 2 * n + replicaOverlap x y ^ 2 := by + simp_rw [add_sq] + rw [Finset.sum_add_distrib, Finset.sum_add_distrib] + simp only [mul_assoc, ← Finset.mul_sum, sum_upperCoefficient_sq, + sum_upperCoefficient_mul] + ring + +lemma combined_energy_sampled {n : ℕ} (g : GaussianCoordinates n) (x y : Spin n) : + energy (sampledInteraction g) x + energy (sampledInteraction g) y = + ∑ p, (upperCoefficient x p + upperCoefficient y p) * g p := by + simp [energy_sampled, add_mul, Finset.sum_add_distrib] + +lemma integrable_exp_combined_energy (β : ℝ) {n : ℕ} (x y : Spin n) : + Integrable (fun g => Real.exp (energy (sampledInteraction g) x + + energy (sampledInteraction g) y)) (disorderLaw β n) := by + simp_rw [combined_energy_sampled] + exact integrable_exp_gaussian_linear _ _ + +lemma integral_exp_combined_energy (β : ℝ) {n : ℕ} (hn : 0 < n) (x y : Spin n) : + (∫ g, Real.exp (energy (sampledInteraction g) x + energy (sampledInteraction g) y) + ∂disorderLaw β n) = + Real.exp (β ^ 2 * (n - 2) / 2 + β ^ 2 * replicaOverlap x y ^ 2 / (2 * n)) := by + simp_rw [combined_energy_sampled] + unfold disorderLaw + rw [integral_exp_gaussian_linear _ (fun p => upperCoefficient x p + upperCoefficient y p), + sum_upperCoefficient_add_sq] + rw [Real.coe_toNNReal _ (div_nonneg (sq_nonneg _) (Nat.cast_nonneg _))] + congr 1 + have hn0 : (n : ℝ) ≠ 0 := by exact_mod_cast (ne_of_gt hn) + field_simp + +lemma partition_sq_eq_sum {n : ℕ} (J : Interaction n) : + partition J ^ 2 = ∑ x, ∑ y, Real.exp (energy J x + energy J y) := by + simp [partition, pow_two, Real.exp_add, Finset.sum_mul, Finset.mul_sum] + rw [Finset.sum_comm] + +lemma integrable_partition_sq_sampled (β : ℝ) (n : ℕ) : + Integrable (fun g => partition (sampledInteraction g) ^ 2) (disorderLaw β n) := by + simp_rw [partition_sq_eq_sum] + exact integrable_finsetSum _ (fun x _ => integrable_finsetSum _ + (fun y _ => integrable_exp_combined_energy β x y)) + +lemma integral_partition_sq_sampled (β : ℝ) {n : ℕ} (hn : 0 < n) : + (∫ g, partition (sampledInteraction g) ^ 2 ∂disorderLaw β n) = + Real.exp (β ^ 2 * (n - 2) / 2) * + ∑ x : Spin n, ∑ y : Spin n, Real.exp (β ^ 2 * replicaOverlap x y ^ 2 / (2 * n)) := by + simp_rw [partition_sq_eq_sum] + rw [integral_finsetSum _ (fun x _ => integrable_finsetSum _ + (fun y _ => integrable_exp_combined_energy β x y))] + simp_rw [integral_finsetSum _ (fun y _ => integrable_exp_combined_energy β _ y), + integral_exp_combined_energy β hn, Real.exp_add, ← Finset.mul_sum] + +def multiplySpin {n : ℕ} (x y : Spin n) : Spin n := fun i => if x i then y i else !(y i) + +@[simp] lemma spin_multiplySpin {n : ℕ} (x y : Spin n) (i : Fin n) : + spin (multiplySpin x y) i = spin x i * spin y i := by + cases hx : x i <;> cases hy : y i <;> simp [spin, multiplySpin, hx, hy] + +@[simp] lemma multiplySpin_self {n : ℕ} (x y : Spin n) : + multiplySpin x (multiplySpin x y) = y := by + funext i + cases hx : x i <;> cases hy : y i <;> simp [multiplySpin, hx, hy] + +def multiplySpinEquiv {n : ℕ} (x : Spin n) : Spin n ≃ Spin n where + toFun := multiplySpin x + invFun := multiplySpin x + left_inv := multiplySpin_self x + right_inv := multiplySpin_self x + +lemma replicaOverlap_eq_magnetization {n : ℕ} (x y : Spin n) : + replicaOverlap x y = magnetization (multiplySpin x y) := by + simp [replicaOverlap, magnetization] + +lemma sum_replicaOverlap {n : ℕ} (x : Spin n) (f : ℝ → ℝ) : + ∑ y, f (replicaOverlap x y) = ∑ y : Spin n, f (magnetization y) := by + simp_rw [replicaOverlap_eq_magnetization] + exact (multiplySpinEquiv x).sum_comp (fun y => f (magnetization y)) + +lemma partition_second_moment_identity (β : ℝ) {n : ℕ} (hn : 0 < n) : + (∫ g, partition (sampledInteraction g) ^ 2 ∂disorderLaw β n) / + (∫ g, partition (sampledInteraction g) ∂disorderLaw β n) ^ 2 = + Real.exp (-β ^ 2 / 2) * + ((∑ x : Spin n, Real.exp (β ^ 2 * magnetization x ^ 2 / (2 * n))) / (2 : ℝ) ^ n) := by + rw [integral_partition_sq_sampled β hn, integral_partition_sampled β hn] + simp_rw [sum_replicaOverlap _ (fun z => Real.exp (β ^ 2 * z ^ 2 / (2 * n)))] + simp only [Finset.sum_const, Finset.card_univ, card_spin, nsmul_eq_mul, + Nat.cast_pow, Nat.cast_ofNat, mul_pow] + have he : Real.exp (β ^ 2 * (n - 2) / 2) = + Real.exp (-β ^ 2 / 2) * Real.exp (β ^ 2 * (n - 1) / 4) ^ 2 := by + rw [← Real.exp_nat_mul, ← Real.exp_add] + congr 1 + ring + rw [he] + field_simp + +lemma integral_exp_gaussian_quadratic {a : ℝ} (ha : a < 1) : + (∫ z : ℝ, Real.exp (a * z ^ 2 / 2) ∂gaussianReal 0 1) = + (Real.sqrt (1 - a))⁻¹ := by + rw [integral_gaussianReal_eq_integral_smul (by norm_num : (1 : ℝ≥0) ≠ 0)] + have he (z : ℝ) : gaussianPDFReal 0 1 z * Real.exp (a * z ^ 2 / 2) = + (Real.sqrt (2 * Real.pi))⁻¹ * Real.exp (-((1 - a) / 2) * z ^ 2) := by + simp only [gaussianPDFReal, sub_zero, NNReal.coe_one, mul_one] + rw [mul_assoc, ← Real.exp_add] + congr 2 + ring + simp only [smul_eq_mul, he] + rw [integral_const_mul, integral_gaussian] + have hd : Real.pi / ((1 - a) / 2) = (2 * Real.pi) / (1 - a) := by + field_simp [ne_of_gt (sub_pos.mpr ha)] + rw [hd, Real.sqrt_div (by positivity : 0 ≤ 2 * Real.pi)] + have hπ : Real.sqrt (2 * Real.pi) ≠ 0 := ne_of_gt (Real.sqrt_pos.2 (by positivity)) + field_simp + +lemma integrable_exp_gaussian_quadratic {a : ℝ} (ha : a < 1) : + Integrable (fun z : ℝ => Real.exp (a * z ^ 2 / 2)) (gaussianReal 0 1) := by + by_contra h + have hz := integral_undef h + rw [integral_exp_gaussian_quadratic ha] at hz + exact (inv_ne_zero (ne_of_gt (Real.sqrt_pos.2 (by linarith)))) hz + +lemma sign_sum_exponential (n : ℕ) (t : ℝ) : + ∑ x : Spin n, Real.exp (t * magnetization x) = (2 * Real.cosh t) ^ n := by + simp_rw [magnetization, Finset.mul_sum, Real.exp_sum] + have he : (∑ x : Spin n, ∏ i, Real.exp (t * spin x i)) = + ∏ i : Fin n, ∑ b : Bool, Real.exp (t * if b then 1 else -1) := by + exact (Fintype.prod_sum (fun (_ : Fin n) (b : Bool) => + Real.exp (t * if b then 1 else -1))).symm + rw [he] + simp only [Fintype.sum_bool, Bool.false_eq_true, ↓reduceIte, mul_neg_one, mul_one, + Finset.prod_const, Finset.card_univ, Fintype.card_fin] + congr 1 + rw [Real.cosh_eq] + ring + +lemma gaussian_sign_square_identity (β : ℝ) {n : ℕ} (x : Spin n) : + (∫ z : ℝ, Real.exp ((β * magnetization x / Real.sqrt n) * z) ∂gaussianReal 0 1) = + Real.exp (β ^ 2 * magnetization x ^ 2 / (2 * n)) := by + have he := congrFun (mgf_fun_id_gaussianReal (μ := 0) (v := 1)) + (β * magnetization x / Real.sqrt n) + simp only [mgf, zero_mul, NNReal.coe_one, one_mul, zero_add] at he + rw [he] + congr 1 + rw [div_pow, mul_pow, Real.sq_sqrt (Nat.cast_nonneg n)] + ring + +lemma cosh_scaled_pow_le (β z : ℝ) {n : ℕ} (hn : 0 < n) : + Real.cosh (β * z / Real.sqrt n) ^ n ≤ Real.exp (β ^ 2 * z ^ 2 / 2) := by + calc + _ ≤ (Real.exp ((β * z / Real.sqrt n) ^ 2 / 2)) ^ n := + pow_le_pow_left₀ (le_of_lt (Real.cosh_pos _)) (Real.cosh_le_exp_half_sq _) n + _ = _ := by + rw [← Real.exp_nat_mul] + congr 1 + rw [div_pow, mul_pow, Real.sq_sqrt (Nat.cast_nonneg n)] + have hn0 : (n : ℝ) ≠ 0 := by exact_mod_cast (ne_of_gt hn) + field_simp + +lemma sign_square_moment_le (β : ℝ) (hβ : β ^ 2 < 1) {n : ℕ} (hn : 0 < n) : + (∑ x : Spin n, Real.exp (β ^ 2 * magnetization x ^ 2 / (2 * n))) / (2 : ℝ) ^ n ≤ + (Real.sqrt (1 - β ^ 2))⁻¹ := by + let f : ℝ → ℝ := fun z => + (∑ x : Spin n, Real.exp ((β * magnetization x / Real.sqrt n) * z)) / (2 : ℝ) ^ n + have hf : Integrable f (gaussianReal 0 1) := + (integrable_finsetSum _ (fun x _ => integrable_exp_mul_gaussianReal + (μ := 0) (v := 1) (β * magnetization x / Real.sqrt n))).div_const _ + have hid (z : ℝ) : f z = Real.cosh (β * z / Real.sqrt n) ^ n := by + dsimp [f] + have he (x : Spin n) : (β * magnetization x / Real.sqrt n) * z = + (β * z / Real.sqrt n) * magnetization x := by ring + simp_rw [he] + rw [sign_sum_exponential, mul_pow] + field_simp + have hle := integral_mono hf (integrable_exp_gaussian_quadratic hβ) + (fun z => by rw [hid]; exact cosh_scaled_pow_le β z hn) + rw [integral_exp_gaussian_quadratic hβ] at hle + dsimp [f] at hle + rw [integral_div, integral_finsetSum _ (fun x _ => + integrable_exp_mul_gaussianReal (μ := 0) (v := 1) + (β * magnetization x / Real.sqrt n))] at hle + simpa only [gaussian_sign_square_identity] using hle + +lemma partition_second_moment_bound (β : ℝ) (hβ : β ^ 2 < 1) {n : ℕ} (hn : 0 < n) : + (∫ g, partition (sampledInteraction g) ^ 2 ∂disorderLaw β n) / + (∫ g, partition (sampledInteraction g) ∂disorderLaw β n) ^ 2 ≤ + (Real.sqrt (1 - β ^ 2))⁻¹ := by + rw [partition_second_moment_identity β hn] + have hm := sign_square_moment_le β hβ hn + have he : Real.exp (-β ^ 2 / 2) ≤ 1 := + Real.exp_le_one_iff.2 (by nlinarith [sq_nonneg β]) + calc + _ ≤ Real.exp (-β ^ 2 / 2) * (Real.sqrt (1 - β ^ 2))⁻¹ := + mul_le_mul_of_nonneg_left hm (Real.exp_pos _).le + _ ≤ _ := by + simpa using mul_le_mul_of_nonneg_right he (by positivity : 0 ≤ (Real.sqrt (1 - β ^ 2))⁻¹) + +end SKGapCutoff + +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal + +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/Vectorize.lean b/lean/OAI/Probability/SKGap/Localization/Vectorize.lean new file mode 100644 index 0000000000000000000000000000000000000000..ec3e30c190084b4a8c2908a730778b6c8700ca1a --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/Vectorize.lean @@ -0,0 +1,387 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.SandShift + +namespace OAI + +section +noncomputable section +open MeasureTheory ProbabilityTheory InformationTheory Real Set +open scoped NNReal ENNReal +open Filter +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius ENNReal NNReal +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius NNReal +noncomputable section +open MeasureTheory ProbabilityTheory Real Set Filter +open MeasureTheory.Measure +open scoped ENNReal NNReal MeasureTheory Topology +open MeasureTheory +noncomputable section +noncomputable section +open MeasureTheory Set NormedSpace +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius +noncomputable section +open Set Real +open scoped Topology +namespace SKGap.ComplexMatrix +open Set +variable {ι : Type*} [Fintype ι] [DecidableEq ι] + +def vectorize : Matrix ι ι ℂ →ₗ[ℝ] EuclideanSpace ℂ (ι × ι) where + toFun M := WithLp.toLp 2 (fun p => M p.1 p.2) + map_add' _ _ := rfl + map_smul' _ _ := rfl + +lemma vectorize_norm (M : Matrix ι ι ℂ) : ‖vectorize M‖ = ‖M‖ := by + have hh : ‖vectorize M‖^2 = ‖M‖^2 := by + rw [EuclideanSpace.norm_sq_eq,frobenius_sq] + change (∑ p : ι × ι, ‖M p.1 p.2‖^2) = ∑ i, ∑ k, ‖M i k‖^2 + exact Fintype.sum_prod_type _ + nlinarith [norm_nonneg (vectorize M),norm_nonneg M] + +noncomputable instance frobeniusInnerProduct : InnerProductSpace ℝ (Matrix ι ι ℂ) where + inner M N := inner ℝ (vectorize M) (vectorize N) + norm_sq_eq_re_inner M := by + change ‖M‖^2 = inner ℝ (vectorize M) (vectorize M) + rw [real_inner_self_eq_norm_sq,vectorize_norm] + conj_inner_symm M N := by simp only [conj_trivial]; exact real_inner_comm _ _ + add_left M N P := by rw [map_add,inner_add_left] + smul_left M N r := by rw [map_smul,inner_smul_left] + +noncomputable def hermitianBall (R : ℝ) : Set (Matrix ι ι ℂ) := + {M | Mᴴ = M ∧ opNorm M ≤ R} + +lemma hermitianBall_closed (R : ℝ) : IsClosed (hermitianBall (ι := ι) R) := by + apply IsClosed.inter + · exact isClosed_eq (by fun_prop : Continuous (fun M : Matrix ι ι ℂ => Mᴴ)) continuous_id + · exact isClosed_le continuous_lin.norm continuous_const + +lemma hermitianBall_convex (R : ℝ) : Convex ℝ (hermitianBall (ι := ι) R) := by + intro M hM N hN a b ha hb hab + constructor + · simp only [Matrix.conjTranspose_add,Matrix.conjTranspose_smul,hM.1,hN.1,star_trivial] + · have he : lin (a • M+b • N) = a • lin M+b • lin N := by + exact (linEquiv (ι := ι)).toLinearMap.restrictScalars ℝ |>.map_add _ _ |>.trans + (by rw [LinearMap.map_smul,LinearMap.map_smul]; rfl) + change ‖lin (a • M+b • N)‖ ≤ R + rw [he] + calc + _ ≤ ‖a • lin M‖+‖b • lin N‖ := norm_add_le _ _ + _ = a*opNorm M+b*opNorm N := by simp [norm_smul,Real.norm_eq_abs,abs_of_nonneg ha,abs_of_nonneg hb,opNorm] + _ ≤ a*R+b*R := add_le_add (mul_le_mul_of_nonneg_left hM.2 ha) (mul_le_mul_of_nonneg_left hN.2 hb) + _ = R := by rw [← add_mul,hab,one_mul] + +lemma hermitianBall_good {R : ℝ} (hR : 0 ≤ R) : SKGap.ClosedConvexNonempty (hermitianBall (ι := ι) R) where + nonempty := ⟨0,by simp [hermitianBall,opNorm,lin,hR]⟩ + complete := (hermitianBall_closed R).isComplete + convex := by convert hermitianBall_convex (ι := ι) R using 0 + +noncomputable def matrixProject (R : ℝ) (hR : 0 ≤ R) : Matrix ι ι ℂ → Matrix ι ι ℂ := + SKGap.convexProject (hermitianBall_good hR) + +lemma matrixProject_lipschitz (R : ℝ) (hR : 0 ≤ R) : + LipschitzWith 1 (matrixProject (ι := ι) R hR) := + SKGap.convexProject_lipschitz _ + +lemma matrixProject_bound (R : ℝ) (hR : 0 ≤ R) (M : Matrix ι ι ℂ) : + (matrixProject R hR M)ᴴ = matrixProject R hR M ∧ opNorm (matrixProject R hR M) ≤ R := + SKGap.convexProject_mem (hermitianBall_good (ι := ι) hR) M + +lemma matrixProject_eq_self (R : ℝ) (hR : 0 ≤ R) (M : Matrix ι ι ℂ) + (hM : Mᴴ = M) (hMR : opNorm M ≤ R) : matrixProject R hR M = M := + SKGap.convexProject_eq_self _ ⟨hM,hMR⟩ + +end SKGap.ComplexMatrix + +namespace SKGap.ComplexMatrix +open scoped FourierTransform SchwartzMap +variable {ι : Type*} [Fintype ι] [DecidableEq ι] + +noncomputable def truncatedG (f : 𝓢(ℝ,ℂ)) (R : ℝ) (hR : 0 ≤ R) + (B D M : Matrix ι ι ℂ) : Matrix ι ι ℂ := + D*schwartzMatrix f (sandShift B D (matrixProject R hR M))*D + +lemma matrixProject_sub_norm (R : ℝ) (hR : 0 ≤ R) (M N : Matrix ι ι ℂ) : + ‖matrixProject R hR M-matrixProject R hR N‖ ≤ ‖M-N‖ := by + simpa only [dist_eq_norm,NNReal.coe_one,one_mul] using (matrixProject_lipschitz R hR).dist_le_mul M N + +lemma truncatedG_opNorm (f : 𝓢(ℝ,ℂ)) (R : ℝ) (hR : 0 ≤ R) (B D M : Matrix ι ι ℂ) + (hB : Bᴴ = B) (hD : Dᴴ = D) : + opNorm (truncatedG f R hR B D M) ≤ opNorm D^2*fourierMoment f 0 := by + have hS := sandShift_hermitian B D (matrixProject R hR M) hB hD (matrixProject_bound R hR M).1 + apply (sandwich_opNorm D _).trans + apply mul_le_mul_of_nonneg_left _ (sq_nonneg _) + simpa only [fourierMoment,pow_zero,mul_one] using schwartzMatrix_opNorm f _ hS + +lemma truncatedG_sub_norm (f : 𝓢(ℝ,ℂ)) (R : ℝ) (hR : 0 ≤ R) (B D M N : Matrix ι ι ℂ) + (hB : Bᴴ = B) (hD : Dᴴ = D) : + ‖truncatedG f R hR B D M-truncatedG f R hR B D N‖ ≤ + (2*Real.pi*fourierMoment f 1)*opNorm D^4*‖M-N‖ := by + have hL : 0 ≤ 2*Real.pi*fourierMoment f 1 := by have := fourierMoment_nonneg f 1; positivity + have hM := (matrixProject_bound R hR M).1 + have hN := (matrixProject_bound R hR N).1 + have hl := schwartzMatrix_sandShift_lipschitz f B D (matrixProject R hR M) (matrixProject R hR N) hB hD hM hN + have he : truncatedG f R hR B D M-truncatedG f R hR B D N = + D*(schwartzMatrix f (sandShift B D (matrixProject R hR M))- + schwartzMatrix f (sandShift B D (matrixProject R hR N)))*D := by dsimp [truncatedG]; noncomm_ring + rw [he] + calc + _ ≤ opNorm D^2*‖schwartzMatrix f (sandShift B D (matrixProject R hR M))- + schwartzMatrix f (sandShift B D (matrixProject R hR N))‖ := sandwich_frobenius _ _ + _ ≤ opNorm D^2*((2*Real.pi*fourierMoment f 1)*opNorm D^2*‖matrixProject R hR M-matrixProject R hR N‖) := + mul_le_mul_of_nonneg_left hl (sq_nonneg _) + _ ≤ opNorm D^2*((2*Real.pi*fourierMoment f 1)*opNorm D^2*‖M-N‖) := by + gcongr + exact matrixProject_sub_norm _ _ _ _ + _ = _ := by ring + +lemma truncatedG_hermitian (f : 𝓢(ℝ,ℂ)) (hf : ∀ x, star (f x) = f x) + (R : ℝ) (hR : 0 ≤ R) (B D M : Matrix ι ι ℂ) (hB : Bᴴ = B) (hD : Dᴴ = D) : + (truncatedG f R hR B D M)ᴴ = truncatedG f R hR B D M := by + have hs := schwartzMatrix_hermitian f hf (sandShift B D (matrixProject R hR M)) + (sandShift_hermitian B D (matrixProject R hR M) hB hD (matrixProject_bound R hR M).1) + change (D*schwartzMatrix f (sandShift B D (matrixProject R hR M))*D)ᴴ = _ + simp only [Matrix.conjTranspose_mul,hD,hs.eq,truncatedG,mul_assoc] + +lemma truncatedG_eq_inverse (f : 𝓢(ℝ,ℂ)) {lo hi : ℝ} (hlo : 0 < lo) + (hf : ∀ x ∈ Set.Icc lo hi, f x = (x : ℂ)⁻¹) + (R : ℝ) (hR : 0 ≤ R) (B D M : Matrix ι ι ℂ) (hB : Bᴴ = B) (hD : Dᴴ = D) + (hM : Mᴴ = M) (hMR : opNorm M ≤ R) + (hspec : ∀ i, Matrix.IsHermitian.eigenvalues (sandShift_hermitian B D M hB hD hM) i ∈ Set.Icc lo hi) : + truncatedG f R hR B D M = D*(sandShift B D M)⁻¹*D := by + rw [truncatedG,matrixProject_eq_self R hR M hM hMR, + schwartzMatrix_eq_inverse f hlo hf _ (sandShift_hermitian B D M hB hD hM) hspec] + +end SKGap.ComplexMatrix + +namespace SKGap.ComplexMatrix +open scoped SchwartzMap +variable {ι : Type*} [Fintype ι] [DecidableEq ι] + +def fl1 (f : 𝓢(ℝ,ℂ)) : ℝ := 2*Real.pi*fourierMoment f 1 +def fl2 (f : 𝓢(ℝ,ℂ)) : ℝ := (2*Real.pi)^2*fourierMoment f 2 +lemma fl_nonneg (f : 𝓢(ℝ,ℂ)) : 0 ≤ fl1 f ∧ 0 ≤ fl2 f := by + have h₁ := fourierMoment_nonneg f 1 + have h₂ := fourierMoment_nonneg f 2 + unfold fl1 fl2 + constructor <;> positivity + +def diagonalChange (D D' : Matrix ι ι ℂ) : ℝ := + (opNorm D+opNorm D')*opNorm (D-D') +def shiftChange (R : ℝ) (B B' D D' : Matrix ι ι ℂ) : ℝ := + opNorm (B-B')+diagonalChange D D'*R +def gBound (f : 𝓢(ℝ,ℂ)) (D : Matrix ι ι ℂ) : ℝ := + opNorm D^2*fourierMoment f 0 +def gLip (f : 𝓢(ℝ,ℂ)) (D : Matrix ι ι ℂ) : ℝ := + fl1 f*opNorm D^4 +def gChange (f : 𝓢(ℝ,ℂ)) (R : ℝ) (B B' D D' : Matrix ι ι ℂ) : ℝ := + diagonalChange D D'*fourierMoment f 0+opNorm D'^2*fl1 f*shiftChange R B B' D D' +def gMixed (f : 𝓢(ℝ,ℂ)) (R : ℝ) (B B' D D' : Matrix ι ι ℂ) : ℝ := + diagonalChange D D'*fl1 f*opNorm D^2+ + opNorm D'^2*(fl1 f*diagonalChange D D'+fl2 f*(2*shiftChange R B B' D D')*opNorm D'^2) + +lemma diagonalChange_nonneg (D D' : Matrix ι ι ℂ) : 0 ≤ diagonalChange D D' := by + unfold diagonalChange + positivity [opNorm_nonneg D,opNorm_nonneg D',opNorm_nonneg (D-D')] +lemma shiftChange_nonneg {R : ℝ} (hR : 0 ≤ R) (B B' D D' : Matrix ι ι ℂ) : + 0 ≤ shiftChange R B B' D D' := by + unfold shiftChange + positivity [opNorm_nonneg (B-B'),diagonalChange_nonneg D D'] +lemma g_constants_nonneg (f : 𝓢(ℝ,ℂ)) {R : ℝ} (hR : 0 ≤ R) + (B B' D D' : Matrix ι ι ℂ) : + 0 ≤ gBound f D ∧ 0 ≤ gLip f D ∧ 0 ≤ gChange f R B B' D D' ∧ 0 ≤ gMixed f R B B' D D' := by + have h₀ := fourierMoment_nonneg f 0 + have h₁ := (fl_nonneg f).1 + have h₂ := (fl_nonneg f).2 + have hd := diagonalChange_nonneg D D' + have hs := shiftChange_nonneg hR B B' D D' + unfold gBound gLip gChange gMixed + exact ⟨by positivity,by positivity,by positivity,by positivity⟩ + +lemma truncatedG_parameter (f : 𝓢(ℝ,ℂ)) {R : ℝ} (hR : 0 ≤ R) + (B B' D D' M : Matrix ι ι ℂ) + (hB : Bᴴ = B) (hB' : B'ᴴ = B') (hD : Dᴴ = D) (hD' : D'ᴴ = D') : + opNorm (truncatedG f R hR B D M-truncatedG f R hR B' D' M) ≤ + gChange f R B B' D D' := by + let P := matrixProject R hR M + let F := schwartzMatrix f (sandShift B D P) + let F' := schwartzMatrix f (sandShift B' D' P) + have hP := matrixProject_bound R hR M + have hF : opNorm F ≤ fourierMoment f 0 := by + simpa only [F,fourierMoment,pow_zero,mul_one] using + schwartzMatrix_opNorm f _ (sandShift_hermitian _ _ _ hB hD hP.1) + have hs : opNorm (sandShift B D P-sandShift B' D' P) ≤ shiftChange R B B' D D' := by + apply (sandShift_parameter B B' D D' P).trans + unfold shiftChange diagonalChange + exact add_le_add_right (mul_le_mul_of_nonneg_left hP.2 (diagonalChange_nonneg D D')) _ + have hL : opNorm (F-F') ≤ fl1 f*shiftChange R B B' D D' := + (schwartzMatrix_opNorm_lipschitz f _ _ (sandShift_hermitian _ _ _ hB hD hP.1) + (sandShift_hermitian _ _ _ hB' hD' hP.1)).trans + (mul_le_mul_of_nonneg_left hs (fl_nonneg f).1) + have he : truncatedG f R hR B D M-truncatedG f R hR B' D' M = + (D*F*D-D'*F*D')+D'*(F-F')*D' := by dsimp [truncatedG,F,F',P]; noncomm_ring + rw [he] + calc + _ ≤ opNorm (D*F*D-D'*F*D')+opNorm (D'*(F-F')*D') := opNorm_add _ _ + _ ≤ diagonalChange D D'*opNorm F+opNorm D'^2*opNorm (F-F') := + add_le_add (sandwich_difference_opNorm _ _ _) (sandwich_opNorm _ _) + _ ≤ diagonalChange D D'*fourierMoment f 0+opNorm D'^2*(fl1 f*shiftChange R B B' D D') := + add_le_add (mul_le_mul_of_nonneg_left hF (diagonalChange_nonneg _ _)) + (mul_le_mul_of_nonneg_left hL (sq_nonneg _)) + _ = _ := by unfold gChange; ring + +lemma truncatedG_four_point (f : 𝓢(ℝ,ℂ)) {R : ℝ} (hR : 0 ≤ R) + (B B' D D' M N : Matrix ι ι ℂ) + (hB : Bᴴ = B) (hB' : B'ᴴ = B') (hD : Dᴴ = D) (hD' : D'ᴴ = D') : + ‖(truncatedG f R hR B D M-truncatedG f R hR B D N)- + (truncatedG f R hR B' D' M-truncatedG f R hR B' D' N)‖ ≤ + gMixed f R B B' D D'*‖M-N‖ := by + let P := matrixProject R hR M + let Q := matrixProject R hR N + let F := schwartzMatrix f (sandShift B D P)-schwartzMatrix f (sandShift B D Q) + let F' := schwartzMatrix f (sandShift B' D' P)-schwartzMatrix f (sandShift B' D' Q) + have hP := matrixProject_bound R hR M + have hQ := matrixProject_bound R hR N + have hPQ : ‖P-Q‖ ≤ ‖M-N‖ := matrixProject_sub_norm _ _ _ _ + have hF : ‖F‖ ≤ fl1 f*opNorm D^2*‖M-N‖ := + (schwartzMatrix_sandShift_lipschitz f B D P Q hB hD hP.1 hQ.1).trans + (mul_le_mul_of_nonneg_left hPQ (mul_nonneg (fl_nonneg f).1 (sq_nonneg _))) + have hFF : ‖F-F'‖ ≤ + (fl1 f*diagonalChange D D'+fl2 f*(2*shiftChange R B B' D D')*opNorm D'^2)*‖M-N‖ := by + apply (schwartzMatrix_sandShift_four_point f B B' D D' P Q hB hB' hD hD' hP.1 hQ.1).trans + simp only [mul_assoc (2*Real.pi*fourierMoment f 1) (opNorm D+opNorm D')] + change (fl1 f*diagonalChange D D'+fl2 f* + (2*opNorm (B-B')+diagonalChange D D'*(opNorm P+opNorm Q))*opNorm D'^2)*‖P-Q‖ ≤ _ + have hd := diagonalChange_nonneg D D' + have hs := shiftChange_nonneg hR B B' D D' + have hc : 2*opNorm (B-B')+diagonalChange D D'*(opNorm P+opNorm Q) ≤ + 2*shiftChange R B B' D D' := by + calc + _ ≤ 2*opNorm (B-B')+diagonalChange D D'*(R+R) := + add_le_add_right (mul_le_mul_of_nonneg_left (add_le_add hP.2 hQ.2) hd) _ + _ = _ := by unfold shiftChange; ring + have hc' := mul_le_mul_of_nonneg_right + (mul_le_mul_of_nonneg_left hc (fl_nonneg f).2) (sq_nonneg (opNorm D')) + have hcoef := add_le_add_right hc' (fl1 f*diagonalChange D D') + have hn : 0 ≤ fl1 f*diagonalChange D D'+fl2 f*(2*shiftChange R B B' D D')*opNorm D'^2 := + add_nonneg (mul_nonneg (fl_nonneg f).1 hd) + (mul_nonneg (mul_nonneg (fl_nonneg f).2 (mul_nonneg (by norm_num) hs)) (sq_nonneg _)) + exact mul_le_mul hcoef hPQ (norm_nonneg _) hn + have he : (truncatedG f R hR B D M-truncatedG f R hR B D N)- + (truncatedG f R hR B' D' M-truncatedG f R hR B' D' N) = + (D*F*D-D'*F*D')+D'*(F-F')*D' := by dsimp [truncatedG,F,F',P,Q]; noncomm_ring + rw [he] + calc + _ ≤ ‖D*F*D-D'*F*D'‖+‖D'*(F-F')*D'‖ := norm_add_le _ _ + _ ≤ diagonalChange D D'*‖F‖+opNorm D'^2*‖F-F'‖ := + add_le_add (sandwich_difference_frobenius _ _ _) (sandwich_frobenius _ _) + _ ≤ diagonalChange D D'*(fl1 f*opNorm D^2*‖M-N‖)+opNorm D'^2* + ((fl1 f*diagonalChange D D'+fl2 f*(2*shiftChange R B B' D D')*opNorm D'^2)*‖M-N‖) := + add_le_add (mul_le_mul_of_nonneg_left hF (diagonalChange_nonneg _ _)) + (mul_le_mul_of_nonneg_left hFF (sq_nonneg _)) + _ = _ := by unfold gMixed; ring + +noncomputable def truncatedK (f : 𝓢(ℝ,ℂ)) (R : ℝ) (hR : 0 ≤ R) + (B D C M : Matrix ι ι ℂ) : Matrix ι ι ℂ := + 1+truncatedG f R hR B D M*(matrixProject R hR M-C) + +def kBound (f : 𝓢(ℝ,ℂ)) (R : ℝ) (D C : Matrix ι ι ℂ) : ℝ := + 1+gBound f D*(R+opNorm C) +def kLip (f : 𝓢(ℝ,ℂ)) (R : ℝ) (D C : Matrix ι ι ℂ) : ℝ := + gLip f D*(R+opNorm C)+gBound f D +def kMixed (f : 𝓢(ℝ,ℂ)) (R : ℝ) (B B' D D' C C' : Matrix ι ι ℂ) : ℝ := + gMixed f R B B' D D'*(R+opNorm C)+gLip f D'*opNorm (C-C')+gChange f R B B' D D' + +lemma projected_sub_bound {R : ℝ} (hR : 0 ≤ R) (M C : Matrix ι ι ℂ) : + opNorm (matrixProject R hR M-C) ≤ R+opNorm C := + (opNorm_sub _ _).trans (add_le_add_left (matrixProject_bound R hR M).2 _) + +lemma truncatedK_opNorm (f : 𝓢(ℝ,ℂ)) {R : ℝ} (hR : 0 ≤ R) + (B D C M : Matrix ι ι ℂ) (hB : Bᴴ = B) (hD : Dᴴ = D) : + opNorm (truncatedK f R hR B D C M) ≤ kBound f R D C := by + apply (opNorm_add _ _).trans + apply add_le_add opNorm_one_le + exact (opNorm_mul _ _).trans + (mul_le_mul (truncatedG_opNorm _ _ _ _ _ _ hB hD) (projected_sub_bound hR M C) + (opNorm_nonneg _) (g_constants_nonneg f hR B B D D).1) + +lemma truncatedK_sub_norm (f : 𝓢(ℝ,ℂ)) {R : ℝ} (hR : 0 ≤ R) + (B D C M N : Matrix ι ι ℂ) (hB : Bᴴ = B) (hD : Dᴴ = D) : + ‖truncatedK f R hR B D C M-truncatedK f R hR B D C N‖ ≤ + kLip f R D C*‖M-N‖ := by + let G := truncatedG f R hR B D + let P : Matrix ι ι ℂ → Matrix ι ι ℂ := matrixProject R hR + have he : truncatedK f R hR B D C M-truncatedK f R hR B D C N = + (G M-G N)*(P M-C)+G N*(P M-P N) := by dsimp [truncatedK,G,P]; noncomm_ring + rw [he] + calc + _ ≤ ‖(G M-G N)*(P M-C)‖+‖G N*(P M-P N)‖ := norm_add_le _ _ + _ ≤ ‖G M-G N‖*opNorm (P M-C)+opNorm (G N)*‖P M-P N‖ := + add_le_add (frobenius_mul_le_opNorm_right _ _) (frobenius_mul_le_opNorm _ _) + _ ≤ (gLip f D*‖M-N‖)*(R+opNorm C)+gBound f D*‖M-N‖ := by + apply add_le_add + · exact mul_le_mul (truncatedG_sub_norm _ _ _ _ _ _ _ hB hD) (projected_sub_bound hR M C) + (opNorm_nonneg _) (mul_nonneg (g_constants_nonneg f hR B B D D).2.1 (norm_nonneg _)) + · exact mul_le_mul (truncatedG_opNorm _ _ _ _ _ _ hB hD) (matrixProject_sub_norm _ _ _ _) + (norm_nonneg _) (g_constants_nonneg f hR B B D D).1 + _ = _ := by unfold kLip; ring + +lemma truncatedK_four_point (f : 𝓢(ℝ,ℂ)) {R : ℝ} (hR : 0 ≤ R) + (B B' D D' C C' M N : Matrix ι ι ℂ) + (hB : Bᴴ = B) (hB' : B'ᴴ = B') (hD : Dᴴ = D) (hD' : D'ᴴ = D') : + ‖(truncatedK f R hR B D C M-truncatedK f R hR B D C N)- + (truncatedK f R hR B' D' C' M-truncatedK f R hR B' D' C' N)‖ ≤ + kMixed f R B B' D D' C C'*‖M-N‖ := by + let G := truncatedG f R hR B D + let G' := truncatedG f R hR B' D' + let P : Matrix ι ι ℂ → Matrix ι ι ℂ := matrixProject R hR + have he : (truncatedK f R hR B D C M-truncatedK f R hR B D C N)- + (truncatedK f R hR B' D' C' M-truncatedK f R hR B' D' C' N) = + (G M*(P M-C)-G N*(P N-C))-(G' M*(P M-C')-G' N*(P N-C')) := by + dsimp [truncatedK,G,G',P]; abel + rw [he] + have h₁ : (P M-C)-(P M-C') = -(C-C') := by abel + have h₂ : (P M-C)-(P N-C) = P M-P N := by abel + have h₃ : ((P M-C)-(P N-C))-((P M-C')-(P N-C')) = 0 := by abel + have hh := product_four_point (G M) (G N) (G' M) (G' N) (P M-C) (P N-C) (P M-C') (P N-C') + rw [h₃,h₁,h₂,opNorm_neg,norm_zero,mul_zero,add_zero] at hh + apply hh.trans + calc + _ ≤ (gMixed f R B B' D D'*‖M-N‖)*(R+opNorm C)+ + (gLip f D'*‖M-N‖)*opNorm (C-C')+gChange f R B B' D D'*‖M-N‖ := by + apply add_le_add + · apply add_le_add + · exact mul_le_mul (truncatedG_four_point f hR B B' D D' M N hB hB' hD hD') + (projected_sub_bound hR M C) (opNorm_nonneg _) + (mul_nonneg (g_constants_nonneg f hR B B' D D').2.2.2 (norm_nonneg _)) + · exact mul_le_mul_of_nonneg_right (truncatedG_sub_norm _ _ _ _ _ _ _ hB' hD') (opNorm_nonneg _) + · exact mul_le_mul (truncatedG_parameter f hR B B' D D' N hB hB' hD hD') + (matrixProject_sub_norm _ _ _ _) (norm_nonneg _) + (g_constants_nonneg f hR B B' D D').2.2.1 + _ = _ := by unfold kMixed; ring + +end SKGap.ComplexMatrix + +noncomputable section +open Matrix Set Filter +open scoped Topology Matrix.Norms.Frobenius + +end +end +end +end +end +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Localization/WeakResidual.lean b/lean/OAI/Probability/SKGap/Localization/WeakResidual.lean new file mode 100644 index 0000000000000000000000000000000000000000..57612c3531956594992702c90447c0357b51695a --- /dev/null +++ b/lean/OAI/Probability/SKGap/Localization/WeakResidual.lean @@ -0,0 +1,306 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.ScalarVariance +import OAI.Probability.SKGap.Stability.ConditionalMean + +namespace OAI + +section + +noncomputable section +open scoped BigOperators +namespace SKGapCutoff.Static +variable {n : ℕ} + +def conditionalVariance (P : Spin n→ℝ) (x : Spin n) (i : Fin n) : ℝ := + 1-(conditionalMean P x i)^2 + +def varianceEnergy (P : Spin n→ℝ) (f : Observables n) : ℝ := + ∑ x,P x*∑ i,conditionalVariance P x i*(halfDiff i f x)^2 + +lemma conditionalVariance_nonneg (P : Spin n→ℝ) (hP : ∀ x,0≤P x) + (x : Spin n) (i : Fin n) : 0≤conditionalVariance P x i := by + have h:=conditionalMean_abs_le P hP x i + have hh:=pow_le_pow_left₀ (abs_nonneg (conditionalMean P x i)) h 2 + simpa only [sq_abs,one_pow,conditionalVariance,sub_nonneg] using hh + +lemma conditionalVariance_le_one (P : Spin n→ℝ) (x : Spin n) (i : Fin n) : + conditionalVariance P x i≤1 := by dsimp [conditionalVariance]; nlinarith [sq_nonneg (conditionalMean P x i)] + +lemma varianceEnergy_nonneg (P : Spin n→ℝ) (hP : ∀ x,0≤P x) (f : Observables n) : + 0≤varianceEnergy P f := by + exact Finset.sum_nonneg (fun x _=>mul_nonneg (hP x) + (Finset.sum_nonneg (fun i _=>mul_nonneg (conditionalVariance_nonneg P hP x i) (sq_nonneg _)))) + +lemma residual_product_identity (P : Spin n→ℝ) (hP : ∀ x,0≤P x) + (G : Observables n) (U : VectorFields n) : + (∑ x,P x*G x*∑ i,(spin x i-conditionalMean P x i)*U x i)= + (∑ x,P x*G x*∑ i,conditionalVariance P x i*halfDiff i (fun y=>U y i) x)+ + ∑ x,P x*∑ i,conditionalVariance P x i*halfDiff i G x* + (U x i-2*spin x i*halfDiff i (fun y=>U y i) x) := by + have H (i : Fin n):=law_integration_by_parts_variance P hP i (fun x=>G x*U x i) + simp_rw [halfDiff_mul] at H + simp only [Finset.mul_sum,←Finset.sum_add_distrib] + rw [Finset.sum_comm,Finset.sum_comm (f:=fun x i=> + P x*G x*(conditionalVariance P x i*halfDiff i (fun y=>U y i) x)+ + P x*(conditionalVariance P x i*halfDiff i G x* + (U x i-2*spin x i*halfDiff i (fun y=>U y i) x)))] + apply Finset.sum_congr rfl + intro i _ + convert H i using 1 + · apply Finset.sum_congr rfl; intro x _; ring + · apply Finset.sum_congr rfl; intro x _; dsimp [conditionalVariance]; ring + +lemma diagonal_reflected_bound (U : VectorFields n) {A B : ℝ} + (hA : 0≤A) (hB : 0≤B) + (hD : ∀ x,∑ i,|halfDiff i (fun y=>U y i) x|≤A) + (hU : ∀ x,∑ i,(U x i)^2≤B^2) (x : Spin n) : + (∑ i,(U x i-2*spin x i*halfDiff i (fun y=>U y i) x)^2)≤(2*B+4*A)^2 := by + have hd : (∑ i,(halfDiff i (fun y=>U y i) x)^2)≤A^2 := by + have h:=Finset.sum_sq_le_sq_sum_of_nonneg (s:=Finset.univ) + (f:=fun i=>|halfDiff i (fun y=>U y i) x|) (fun i _=>abs_nonneg _) + simp only [sq_abs] at h + exact h.trans (pow_le_pow_left₀ (Finset.sum_nonneg (fun i _=>abs_nonneg _)) (hD x) 2) + calc + _ ≤ ∑ i,(2*(U x i)^2+8*(halfDiff i (fun y=>U y i) x)^2) := by + apply Finset.sum_le_sum + intro i _ + have hs:=spin_sq x i + have he : (spin x i*halfDiff i (fun y=>U y i) x)^2= + (halfDiff i (fun y=>U y i) x)^2 := by rw [mul_pow,hs,one_mul] + nlinarith only [sq_nonneg (U x i+2*spin x i*halfDiff i (fun y=>U y i) x),he] + _ = 2*(∑ i,(U x i)^2)+8*(∑ i,(halfDiff i (fun y=>U y i) x)^2) := by + simp only [Finset.sum_add_distrib,←Finset.mul_sum] + _ ≤ (2*B+4*A)^2 := by nlinarith [hU x,mul_nonneg hA hB] + +lemma weighted_residual_derivative_bound (P : Spin n→ℝ) (hP : ∀ x,0≤P x) + (G : Observables n) (U : VectorFields n) {A : ℝ} + (hD : ∀ x,∑ i,|halfDiff i (fun y=>U y i) x|≤A) : + |∑ x,P x*G x*∑ i,conditionalVariance P x i*halfDiff i (fun y=>U y i) x|≤ + A*(∑ x,P x*|G x|) := by + calc + _ ≤ ∑ x,|P x*G x*∑ i,conditionalVariance P x i*halfDiff i (fun y=>U y i) x| := + Finset.abs_sum_le_sum_abs .. + _ ≤ ∑ x,P x*|G x| *A := by + apply Finset.sum_le_sum; intro x _ + rw [abs_mul,abs_mul,abs_of_nonneg (hP x)] + apply mul_le_mul_of_nonneg_left _ (mul_nonneg (hP x) (abs_nonneg _)) + calc + _ ≤ ∑ i,|conditionalVariance P x i*halfDiff i (fun y=>U y i) x| := + Finset.abs_sum_le_sum_abs .. + _ ≤ ∑ i,|halfDiff i (fun y=>U y i) x| := by + apply Finset.sum_le_sum; intro i _ + rw [abs_mul,abs_of_nonneg (conditionalVariance_nonneg P hP x i)] + exact mul_le_of_le_one_left (abs_nonneg _) (conditionalVariance_le_one P x i) + _ ≤ A := hD x + _ = _ := by rw [←Finset.sum_mul,mul_comm] + +lemma energy_pair_bound (P : Spin n→ℝ) (hP : ∀ x,0≤P x) + (hPsum : ∑ x,P x=1) (f : Observables n) (V : VectorFields n) {C : ℝ} + (hC : 0≤C) (hV : ∀ x,∑ i,(V x i)^2≤C^2) : + |∑ x,P x*∑ i,conditionalVariance P x i*halfDiff i f x*V x i|≤ + C*Real.sqrt (varianceEnergy P f) := by + have H:=weighted_cauchy_sq (fun a : Spin n×Fin n=>P a.1*conditionalVariance P a.1 a.2) + (fun a=>halfDiff a.2 f a.1) (fun a=>V a.1 a.2) + (fun a=>mul_nonneg (hP _) (conditionalVariance_nonneg P hP _ _)) + simp only [Fintype.sum_prod_type,mul_assoc,←Finset.mul_sum] at H + have hv : (∑ x,P x*∑ i,conditionalVariance P x i*(V x i)^2)≤C^2 := by + calc + _ ≤ ∑ x,P x*C^2 := by + apply Finset.sum_le_sum; intro x _ + apply mul_le_mul_of_nonneg_left _ (hP x) + exact (Finset.sum_le_sum (fun i _=>mul_le_of_le_one_left (sq_nonneg _) (conditionalVariance_le_one P x i))).trans (hV x) + _ = C^2 := by rw [←Finset.sum_mul,hPsum,one_mul] + have hn:=varianceEnergy_nonneg P hP f + have ht:=H.trans (mul_le_mul_of_nonneg_left hv hn) + apply (sq_le_sq₀ (abs_nonneg _) (mul_nonneg hC (Real.sqrt_nonneg _))).1 + rw [sq_abs,mul_pow,Real.sq_sqrt hn] + simpa only [varianceEnergy,mul_assoc,mul_comm,mul_left_comm] using ht + +theorem signed_weak_residual_base (P : Spin n→ℝ) (hP : ∀ x,0≤P x) + (hPsum : ∑ x,P x=1) (G : Observables n) (U : VectorFields n) {A B : ℝ} + (hA : 0≤A) (hB : 0≤B) + (hD : ∀ x,∑ i,|halfDiff i (fun y=>U y i) x|≤A) + (hU : ∀ x,∑ i,(U x i)^2≤B^2) : + |∑ x,P x*G x*∑ i,(spin x i-conditionalMean P x i)*U x i|≤ + A*(∑ x,P x*|G x|)+(2*B+4*A)*Real.sqrt (varianceEnergy P G) := by + rw [residual_product_identity P hP G U] + exact (abs_add_le _ _).trans (add_le_add (weighted_residual_derivative_bound P hP G U hD) + (energy_pair_bound P hP hPsum G _ (by positivity) (diagonal_reflected_bound U hA hB hD hU))) + +lemma coordinate_abs_le_of_square_sum (V : VectorFields n) {C : ℝ} + (hC : 0≤C) (hV : ∀ x,∑ i,(V x i)^2≤C^2) (x : Spin n) (i : Fin n) : + |V x i|≤C := by + apply (sq_le_sq₀ (abs_nonneg _) hC).1 + rw [sq_abs] + exact (Finset.single_le_sum (fun k _=>sq_nonneg (V x k)) (Finset.mem_univ i)).trans (hV x) + +lemma energy_cross_square_bound (P : Spin n→ℝ) (hP : ∀ x,0≤P x) + (f : Observables n) (V : VectorFields n) {C : ℝ} + (hC : 0≤C) (hV : ∀ x,∑ i,(V x i)^2≤C^2) : + |2*(∑ x,P x*∑ i,conditionalVariance P x i*f x*halfDiff i f x*V x i)|≤ + C*((∑ x,P x*(f x)^2)+varianceEnergy P f) := by + have H:=weighted_cauchy_sq (fun a : Spin n×Fin n=>P a.1*conditionalVariance P a.1 a.2) + (fun a=>halfDiff a.2 f a.1) (fun a=>f a.1*V a.1 a.2) + (fun a=>mul_nonneg (hP _) (conditionalVariance_nonneg P hP _ _)) + simp only [Fintype.sum_prod_type,mul_assoc,←Finset.mul_sum] at H + have hv : (∑ x,P x*∑ i,conditionalVariance P x i*(f x*V x i)^2)≤ + C^2*(∑ x,P x*(f x)^2) := by + calc + _ ≤ ∑ x,P x*((f x)^2*C^2) := by + apply Finset.sum_le_sum; intro x _ + apply mul_le_mul_of_nonneg_left _ (hP x) + have he : (∑ i,conditionalVariance P x i*(f x*V x i)^2)= + (f x)^2*(∑ i,conditionalVariance P x i*(V x i)^2) := by + rw [Finset.mul_sum]; apply Finset.sum_congr rfl; intro i _; ring + rw [he] + apply mul_le_mul_of_nonneg_left _ (sq_nonneg _) + exact (Finset.sum_le_sum (fun i _=>mul_le_of_le_one_left (sq_nonneg _) (conditionalVariance_le_one P x i))).trans (hV x) + _ = _ := by rw [Finset.mul_sum]; apply Finset.sum_congr rfl; intro x _; ring + have hn:=varianceEnergy_nonneg P hP f + have hz : 0≤∑ x,P x*(f x)^2 := Finset.sum_nonneg (fun x _=>mul_nonneg (hP x) (sq_nonneg _)) + have he : (∑ x,P x*∑ i,conditionalVariance P x i*(halfDiff i f x*(f x*V x i)))= + ∑ x,P x*∑ i,conditionalVariance P x i*f x*halfDiff i f x*V x i := by + apply Finset.sum_congr rfl; intro x _; congr 1 + apply Finset.sum_congr rfl; intro i _; ring + rw [he] at H + have ht:=H.trans (mul_le_mul_of_nonneg_left hv hn) + change _≤varianceEnergy P f*(C^2*(∑ x,P x*(f x)^2)) at ht + apply (sq_le_sq₀ (abs_nonneg _) (mul_nonneg hC (add_nonneg hz hn))).1 + rw [sq_abs] + nlinarith [mul_nonneg (sq_nonneg C) (sq_nonneg ((∑ x,P x*(f x)^2)-varianceEnergy P f))] + +lemma energy_square_coefficient_bound (P : Spin n→ℝ) (hP : ∀ x,0≤P x) + (f : Observables n) (V : VectorFields n) {C : ℝ} + (hC : 0≤C) (hV : ∀ x,∑ i,(V x i)^2≤C^2) : + |∑ x,P x*∑ i,conditionalVariance P x i*spin x i*(halfDiff i f x)^2*V x i|≤ + C*varianceEnergy P f := by + calc + _ ≤ ∑ x,|P x*∑ i,conditionalVariance P x i*spin x i*(halfDiff i f x)^2*V x i| := + Finset.abs_sum_le_sum_abs .. + _ ≤ ∑ x,P x*∑ i,C*(conditionalVariance P x i*(halfDiff i f x)^2) := by + apply Finset.sum_le_sum; intro x _ + rw [abs_mul,abs_of_nonneg (hP x)] + apply mul_le_mul_of_nonneg_left _ (hP x) + apply (Finset.abs_sum_le_sum_abs ..).trans + apply Finset.sum_le_sum; intro i _ + simp only [abs_mul,abs_of_nonneg (conditionalVariance_nonneg P hP x i),abs_spin_eq_one, + mul_one,abs_of_nonneg (sq_nonneg (halfDiff i f x))] + simpa only [mul_comm] using mul_le_mul_of_nonneg_left + (coordinate_abs_le_of_square_sum V hC hV x i) + (mul_nonneg (conditionalVariance_nonneg P hP x i) (sq_nonneg (halfDiff i f x))) + _ = _ := by + simp only [varianceEnergy,Finset.mul_sum] + apply Finset.sum_congr rfl; intro x _ + apply Finset.sum_congr rfl; intro i _; ring + +lemma halfDiff_square (i : Fin n) (f : Observables n) (x : Spin n) : + halfDiff i (fun y=>(f y)^2) x=2*f x*halfDiff i f x-2*spin x i*(halfDiff i f x)^2 := by + simp only [pow_two,halfDiff_mul]; ring + +theorem square_weak_residual_base (P : Spin n→ℝ) (hP : ∀ x,0≤P x) + (f : Observables n) (U : VectorFields n) {A B : ℝ} + (hA : 0≤A) (hB : 0≤B) + (hD : ∀ x,∑ i,|halfDiff i (fun y=>U y i) x|≤A) + (hU : ∀ x,∑ i,(U x i)^2≤B^2) : + |∑ x,P x*(f x)^2*∑ i,(spin x i-conditionalMean P x i)*U x i|≤ + (13*A+6*B)*((∑ x,P x*(f x)^2)+varianceEnergy P f) := by + let V : VectorFields n:=fun x i=>U x i-2*spin x i*halfDiff i (fun y=>U y i) x + let C:=2*B+4*A + have hC : 0≤C := by dsimp [C]; positivity + have hV : ∀ x,∑ i,(V x i)^2≤C^2 := diagonal_reflected_bound U hA hB hD hU + rw [residual_product_identity P hP (fun x=>(f x)^2) U] + have hd:=weighted_residual_derivative_bound P hP (fun x=>(f x)^2) U hD + simp only [abs_pow,sq_abs] at hd + have he : (∑ x,P x*∑ i,conditionalVariance P x i*halfDiff i (fun y=>(f y)^2) x*V x i)= + 2*(∑ x,P x*∑ i,conditionalVariance P x i*f x*halfDiff i f x*V x i)- + 2*(∑ x,P x*∑ i,conditionalVariance P x i*spin x i*(halfDiff i f x)^2*V x i) := by + simp only [halfDiff_square,Finset.mul_sum,←Finset.sum_sub_distrib] + apply Finset.sum_congr rfl; intro x _ + apply Finset.sum_congr rfl; intro i _; ring + change |_+(∑ x,P x*∑ i,conditionalVariance P x i*halfDiff i (fun y=>(f y)^2) x*V x i)|≤_ + rw [he] + have ht:=energy_cross_square_bound P hP f V hC hV + have hs:=energy_square_coefficient_bound P hP f V hC hV + have hr:=abs_sub + (2*(∑ x,P x*∑ i,conditionalVariance P x i*f x*halfDiff i f x*V x i)) + (2*(∑ x,P x*∑ i,conditionalVariance P x i*spin x i*(halfDiff i f x)^2*V x i)) + simp only [abs_mul,abs_of_pos (by norm_num : (0:ℝ)<2)] at hr ht + have hu:=abs_add_le + (∑ x,P x*(f x)^2*∑ i,conditionalVariance P x i*halfDiff i (fun y=>U y i) x) + (2*(∑ x,P x*∑ i,conditionalVariance P x i*f x*halfDiff i f x*V x i)- + 2*(∑ x,P x*∑ i,conditionalVariance P x i*spin x i*(halfDiff i f x)^2*V x i)) + have hn:=varianceEnergy_nonneg P hP f + have hz : 0≤∑ x,P x*(f x)^2 := Finset.sum_nonneg (fun x _=>mul_nonneg (hP x) (sq_nonneg _)) + dsimp only [C] at * + nlinarith [mul_nonneg hA hn,mul_nonneg (add_nonneg (mul_nonneg (by norm_num : (0:ℝ)≤2) hB) + (mul_nonneg (by norm_num : (0:ℝ)≤4) hA)) hz] + +lemma varianceEnergy_gibbs (J : Interaction n) + (hJ : ∀ i k,J i k=J k i) (hd : ∀ i,J i i=0) (f : Observables n) : + varianceEnergy (gibbs J) f=dirichlet J f f := by + simp only [varianceEnergy,conditionalVariance,conditionalMean_gibbs J hJ hd, + dirichlet,gibbsExpectation,siteVariance,pow_two,mul_assoc] + +lemma sum_abs_mul_le_of_squares {ι : Type*} [Fintype ι] (u v : ι→ℝ) + {A B : ℝ} (hA : 0≤A) (hB : 0≤B) + (hu : ∑ i,(u i)^2≤A^2) (hv : ∑ i,(v i)^2≤B^2) : + (∑ i,|u i*v i|)≤A*B := by + have H:=Finset.sum_mul_sq_le_sq_mul_sq Finset.univ (fun i=>|u i|) (fun i=>|v i|) + simp only [sq_abs,←abs_mul] at H + apply (sq_le_sq₀ (Finset.sum_nonneg (fun i _=>abs_nonneg _)) (mul_nonneg hA hB)).1 + rw [mul_pow] + exact H.trans (mul_le_mul hu hv (Finset.sum_nonneg (fun i _=>sq_nonneg _)) (sq_nonneg _)) + +lemma multiplier_vector_bounds (U : VectorFields n) (θ : Observables n) {A B H L : ℝ} + (hA : 0≤A) (hB : 0≤B) (hH : 0≤H) (hL : 0≤L) + (hD : ∀ x,∑ i,|halfDiff i (fun y=>U y i) x|≤A) + (hU : ∀ x,∑ i,(U x i)^2≤B^2) + (hθ : ∀ x,|θ x|≤H) (hdθ : ∀ x,∑ i,(halfDiff i θ x)^2≤L^2) : + (∀ x,∑ i,|halfDiff i (fun y=>θ y*U y i) x|≤H*A+(2*B+4*A)*L) ∧ + (∀ x,∑ i,(θ x*U x i)^2≤(H*B)^2) := by + constructor + · intro x + have hc:=sum_abs_mul_le_of_squares + (fun i=>U x i-2*spin x i*halfDiff i (fun y=>U y i) x) + (fun i=>halfDiff i θ x) (show 0≤2*B+4*A by positivity) hL + (diagonal_reflected_bound U hA hB hD hU x) (hdθ x) + have ht : (∑ i,|θ x*halfDiff i (fun y=>U y i) x|)≤H*A := by + simp only [abs_mul,←Finset.mul_sum] + exact mul_le_mul (hθ x) (hD x) (Finset.sum_nonneg (fun i _=>abs_nonneg _)) hH + calc + _ ≤ ∑ i,(|θ x*halfDiff i (fun y=>U y i) x|+ + |(U x i-2*spin x i*halfDiff i (fun y=>U y i) x)*halfDiff i θ x|) := by + apply Finset.sum_le_sum; intro i _ + rw [halfDiff_mul] + convert abs_add_le (θ x*halfDiff i (fun y=>U y i) x) + ((U x i-2*spin x i*halfDiff i (fun y=>U y i) x)*halfDiff i θ x) using 1 + ring_nf + _ ≤ _ := by rw [Finset.sum_add_distrib]; exact add_le_add ht hc + · intro x + simp only [mul_pow,←Finset.mul_sum] + exact mul_le_mul (by simpa only [sq_abs] using pow_le_pow_left₀ (abs_nonneg (θ x)) (hθ x) 2) + (hU x) (Finset.sum_nonneg (fun i _=>sq_nonneg _)) (sq_nonneg _) + +theorem square_multiplier_weak_residual_base (P : Spin n→ℝ) (hP : ∀ x,0≤P x) + (f θ : Observables n) (U : VectorFields n) {A B H L : ℝ} + (hA : 0≤A) (hB : 0≤B) (hH : 0≤H) (hL : 0≤L) + (hD : ∀ x,∑ i,|halfDiff i (fun y=>U y i) x|≤A) + (hU : ∀ x,∑ i,(U x i)^2≤B^2) + (hθ : ∀ x,|θ x|≤H) (hdθ : ∀ x,∑ i,(halfDiff i θ x)^2≤L^2) : + |∑ x,P x*(f x)^2*θ x*∑ i,(spin x i-conditionalMean P x i)*U x i|≤ + (13*(H*A+(2*B+4*A)*L)+6*(H*B))* + ((∑ x,P x*(f x)^2)+varianceEnergy P f) := by + obtain ⟨hD',hU'⟩:=multiplier_vector_bounds U θ hA hB hH hL hD hU hθ hdθ + convert square_weak_residual_base P hP f (fun x i=>θ x*U x i) + (by positivity) (by positivity) hD' hU' using 1 + congr 1 + apply Finset.sum_congr rfl; intro x _ + simp only [Finset.mul_sum] + apply Finset.sum_congr rfl; intro i _; ring + +end SKGapCutoff.Static + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Main.lean b/lean/OAI/Probability/SKGap/Main.lean new file mode 100644 index 0000000000000000000000000000000000000000..7bee50ab510b1f9004c85f5f849e67e514d6516a --- /dev/null +++ b/lean/OAI/Probability/SKGap/Main.lean @@ -0,0 +1,120 @@ +import Mathlib +import OAI.Probability.SKGap.Brownian.GramPathRobust +import OAI.Probability.SKGap.Matrix.WordSimultaneousPrediction +import OAI.Probability.SKGap.Stability.WordStablePrediction +import OAI.Probability.SKGap.Stability.QuenchedStableFields +import OAI.Probability.SKGap.Terminal.PairInteraction +import OAI.Probability.SKGap.Entropy.QuenchedFieldAverageExponential +import OAI.Probability.SKGap.Localization.CurieWeiss +import OAI.Probability.SKGap.Gaussian.IndependentBoundedAverageTailLaw +import OAI.Probability.SKGap.Matrix.DoublePlantedGOEArray +import OAI.Probability.SKGap.Localization.DoublePlantedLawTransfer +import OAI.Probability.SKGap.Terminal.PairSpinFrequency +import OAI.Probability.SKGap.Matrix.GapHalfSmallOpNorm +import OAI.Probability.SKGap.Localization.OriginalEventRegeneration +import OAI.Probability.SKGap.Localization.PoissonBinomial +import OAI.Probability.SKGap.Brownian.DiscreteUpperContinuous +import OAI.Probability.SKGap.Brownian.WorstContinuousPolynomialUpper +import OAI.Probability.SKGap.Localization.ScalarSlowConeStep +import OAI.Probability.SKGap.Terminal.SpinDifferenceEnergyReplace +import OAI.Probability.SKGap.Localization.TanhContDiff +import OAI.Probability.SKGap.Localization.JumpBilinear +import OAI.Probability.SKGap.Matrix.StaticCovarianceMatrix +import OAI.Probability.SKGap.Localization.Prediction +import OAI.Probability.SKGap.Matrix.RecipeNodeTrace +import OAI.Probability.SKGap.Matrix.StartedNodeTrace +import OAI.Probability.SKGap.Stability.LocalStartedImplicit +import OAI.Probability.SKGap.Localization.StartedSmall +import OAI.Probability.SKGap.Terminal.TerminalChannel +import OAI.Probability.SKGap.Localization.ModelLocalization + +namespace OAI + +namespace SKGap.FullMain +open MeasureTheory ProbabilityTheory Filter Real Set +open scoped Topology BigOperators ENNReal +open GaussianStep GaussianHistory ObservationBridge SKGapCutoff.Recipe SKGapCutoff.Static +noncomputable section + +lemma whp_of_measurable_full {β : ℝ} (Ω : ∀n,Set (Disorder n)) + (hΩ : ∀n,MeasurableSet (Ω n)) + (hfull : Tendsto (fun n=>(disorderLaw β n).real (Ω n)) atTop (𝓝 1)) : + Whp β (fun n g=>g∈Ω n) := by + apply (whp_iff_real _ _).mpr + have H:=(tendsto_const_nhds (x:=(1:ℝ))).sub hfull + simpa only [sub_self,show ∀n,{g:Disorder n | ¬g∈Ω n}=(Ω n)ᶜ from fun _=>rfl, + probReal_compl_eq_one_sub (hΩ _)] using H + +lemma weighted_accuracy {B C₀ r W : ℝ} (hB : 0≤B) (hC₀ : 0≤C₀) (hr : 0∀f:Spin n→ℝ,variance g 0 f≤C*dirichlet g 0 f) := by + obtain ⟨T,aT,hT,haT,Ω,hΩ,hΩfull,hterminal⟩:=terminal_gap_high_probability hβ + obtain ⟨Ar,K,ε,c,r₀,a,hAr,hK,hs,hε,hc,hr₀,ha,hroot⟩:=quenched_grid_root_stability hβ hβ1 hT + obtain ⟨D₀,hD₀,hcov⟩:=quenched_posterior_covariance hβ hβ1 hAr hs hε hc hr₀ + let b:=min a aT/2 + have hb : 0StableSquareMeanProperty (β^2) c r₀ ρ C₀ Cmean (coupling g)) from hmean) + apply hevents.mono + filter_upwards [hnum (2*Cmean),exponential_pair_eventually ha haT] with n hn hr + intro g hg + rcases hg with ⟨⟨⟨hgΩ,hgr⟩,hgc⟩,hgm⟩ + rcases hn with ⟨hn,hmesh,hmeshD,hloss,hcost⟩ + have hcost' : localizationCost n (2*Cmean) a b (D₀^2) 2 T≤D₀^2*T+3 := by + convert hcost using 1; ring + exact poincare_from_model_data g hn (β^2) Ar K ε c r₀ ρ C₀ Cmean D₀ W a aT b T + hAr.le hD₀ hW.le hCmean ha hb hT hlead hgr.1 hgr.2 (hterminal n g hgΩ) hgc hgm hr + hmesh hmeshD hloss hcost' + +end +end SKGap.FullMain + +namespace SKGap +open MeasureTheory ProbabilityTheory Filter Real Set +open scoped Topology + +theorem sk_main (β : ℝ) (hβ0 : 0 < β) (hβ1 : β < 1) : MainStatement β := by + obtain ⟨C,hC,hwhp⟩:=FullMain.quenched_poincare hβ0 hβ1 + have hP : Tendsto (fun n:ℕ=>disorderLaw β n (poincareEvent n C)) atTop (𝓝 1):= + FullMain.whp_full_probability hwhp + exact ⟨C,hC,hP,gap_probability_of_poincare β C hC hP⟩ + +end SKGap + +end OAI diff --git a/lean/OAI/Probability/SKGap/Matrix/BufferedClosedWord.lean b/lean/OAI/Probability/SKGap/Matrix/BufferedClosedWord.lean new file mode 100644 index 0000000000000000000000000000000000000000..b70d9504f68737956d9594bf7646f2e4bc85c4af --- /dev/null +++ b/lean/OAI/Probability/SKGap/Matrix/BufferedClosedWord.lean @@ -0,0 +1,200 @@ +import Mathlib +import OAI.Probability.SKGap.Matrix.StartedMatrixEvent +import OAI.Probability.SKGap.Localization.DisorderRecipeEvent + +namespace OAI + +section + +noncomputable section +open scoped BigOperators Topology Matrix.Norms.Frobenius +namespace SKGapCutoff.Recipe +open SKGap SKGap.Noncrossing SKGap.Noncrossing.Primary Matrix MeasureTheory ProbabilityTheory Real Set Filter +variable {n : ℕ} + +def inverseDenominator (j : ℝ) (a : Fin n→ℝ) (J : Interaction n) : Interaction n := + 1-Matrix.diagonal a*(J-((j/n)*∑i,a i) • 1) + +lemma continuous_inverseDenominator (j : ℝ) (a : Fin n→ℝ) : + Continuous (inverseDenominator j a) := by + unfold inverseDenominator + exact continuous_const.sub (continuous_const.matrix_mul (continuous_id.sub continuous_const)) + +lemma continuousAt_exactWord (j : ℝ) (a : Fin n→ℝ) (w : List (WordLetter (Fin n))) + (J : Interaction n) (hJ : (inverseDenominator j a J).det≠0) : + ContinuousAt (fun M=>exactWord j a w M) J := by + have hletter (l : WordLetter (Fin n)) : ContinuousAt (l.exactEval j a) J := by + cases l with + | diag d=>exact continuousAt_const + | noise=>exact continuousAt_id + | inverse=> + have h : ContinuousAt Inv.inv (inverseDenominator j a J) := by + apply continuousAt_matrix_inv + simpa only [Ring.inverse_eq_inv'] using continuousAt_inv₀ hJ + have he : WordLetter.exactEval j a WordLetter.inverse=(fun M=>(inverseDenominator j a M)⁻¹) := by + funext M + simp only [WordLetter.exactEval,inverseDenominator,Fintype.card_fin] + rw [he] + exact h.comp (continuous_inverseDenominator j a).continuousAt + induction w with + | nil=>exact continuousAt_const + | cons l w ih=> + change ContinuousAt (fun M=>l.exactEval j a M*exactWord j a w M) J + exact (continuous_fst.matrix_mul continuous_snd).continuousAt.comp ((hletter l).prodMk ih) + +lemma continuous_stability_lower (j : ℝ) (a : Fin n→ℝ) : + Continuous (fun J : Interaction n=>ComplexSpectral.lowerRayleigh + (RealComplex.liftMatrix (stabilityMatrix a 1 ((j/n)*∑i,a i) J))) := by + apply ComplexSpectral.continuous_lowerRayleigh.comp + unfold RealComplex.liftMatrix stabilityMatrix Matrix.map + fun_prop + +def BufferedClosedWordEvent (j A D c C : ℝ) (L : ℕ) (J : Interaction n) : Prop := + ∀a:Fin n→ℝ,(∀i,a i∈Icc 0 A)→ + c?_⟩ + rw [disorder_closed_matrix_event β _ (isClosed_bufferedClosedWordEvent _ _ _ _ _ _)] + apply (measure_mono ?_).trans (h n hn) + intro g hg H + exact hg H.buffered + +lemma inverseDenominator_det_ne (hn : 0(ha i).1) J hJ hc hm) + +theorem disorder_closed_word_event {β A D c : ℝ} (hβ : 0<β) (hA : 0?_⟩ + apply (measure_mono ?_).trans (h n hn) + intro g hg H + exact hg (H.unbuffer (hN.trans_le hn) (by ext i k; exact coupling_symm g k i) hc) + +end SKGapCutoff.Recipe + +end +end + +section + +noncomputable section +open scoped BigOperators Topology +namespace SKGapCutoff.Recipe +open Primary Matrix SKGap SKGap.Noncrossing SKGap.Noncrossing.Primary MeasureTheory ProbabilityTheory Real Set Filter + +theorem disorder_started_matrix_event {β A₀ A c : ℝ} (hβ : 0<β) (hβ1 : β<1) + (hA₀ : 0SKGap.disorderLaw β n + {g | ¬StartedMatrixEvent (β^2) (physicalNormBound (β^2)) A₀ A c B W C M Nmax + (coupling g)}) atTop (𝓝 0) := by + let j:=β^2 + have hj : 0recipeNormTail j n+ordinaryWordTail j (2*M+2*Nmax+5) n+ + ordinaryWordTail j (2*M+2*Nmax+5) n) atTop (𝓝 0) from by + simpa using ((recipeNormTail_limit hj).add (ordinaryWordTail_limit hj _)).add (ordinaryWordTail_limit hj _)) + (Filter.Eventually.of_forall (fun _=>bot_le)) + filter_upwards [eventually_ge_atTop (max N N')] with n hn + have hnN : N≤n:=(le_max_left ..).trans hn + have hnN' : N'≤n:=(le_max_right ..).trans hn + have hn0 : 0hh (.inl (.inl hbad))) + have hu : WordSeminormBound (coupling g) j A B (2*M+2*Nmax+5):=by + by_contra hbad; exact hh (.inl (.inr hbad)) + have hf : ClosedWordEvent j A₀ A c C (2*M+2*Nmax+5) (coupling g):=by + by_contra hbad; exact hh (.inr hbad) + apply hg + refine ⟨hJ,fun h x l hl=>wordEvent_formal _ hn0 (by linarith) hB.le hA (hJ.trans (le_max_right _ _)) M _ (by omega) hu h x l hl,?_⟩ + intro a ha hstable + have hb:=hf a ha hstable + have hsym : (coupling g)ᵀ=coupling g := by + ext i k;exact coupling_symm g k i + exact ⟨(htest n hn0 a _ C ha hsym hJ hstable hb).mono (by omega),hb.diagram.mono (by omega)⟩ + +end SKGapCutoff.Recipe + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Matrix/ClosedErrorTrace.lean b/lean/OAI/Probability/SKGap/Matrix/ClosedErrorTrace.lean new file mode 100644 index 0000000000000000000000000000000000000000..32ff5ef0c5287d88e7008d3ee34eb58fa1716750 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Matrix/ClosedErrorTrace.lean @@ -0,0 +1,241 @@ +import Mathlib +import OAI.Probability.SKGap.Matrix.PrimitiveTrace +import OAI.Probability.SKGap.Matrix.ClosedTrace + +namespace OAI + +section + +noncomputable section +open scoped BigOperators +namespace SKGapCutoff.Recipe +open Matrix SKGap SKGap.Noncrossing SKGap.Noncrossing.Primary SKGap.Noncrossing.Diagram +variable {n : ℕ} + +theorem finite_graph_trace_tested (J : Interaction n) (E F Es Ef : ℕ→Interaction n) + (p : (a : ℕ)→Fin a→Fin n→ℝ) (r : (a : ℕ)→Fin a→ℝ) + (hE : ∀a,E a=(∑b:Fin a,Matrix.diagonal (p a b)*F b)+Es a) + (hF : ∀a,F a=J*E a-(∑b:Fin a,r a b • E b)+Ef a) + {A R M : ℝ} {Cs Cf : ℕ→ℝ} {N L : ℕ} + (_ : 0≤R) (_ : 0≤M) + (hp : ∀a≤N,∀b i,|p a b i|≤A) (hr : ∀a≤N,∀b,|r a b|≤R) + (hsn : ∀a≤N,0≤Cs a) (hfn : ∀a≤N,0≤Cf a) + (hs : ∀a≤N,∀w:OrdinaryWord n,w.length≤L→wordBounded A w→ + |trace (matrixWord J w*Es a)|≤Cs a*M) + (hf : ∀a≤N,∀w:OrdinaryWord n,w.length≤L→wordBounded A w→ + |trace (matrixWord J w*Ef a)|≤Cf a*M) : + ∀a≤N, + (∀w:OrdinaryWord n,w.length+2*a+1≤L→wordBounded A w→ + |trace (matrixWord J w*E a)|≤(errorBudget R Cs Cf a).1*M) ∧ + (∀w:OrdinaryWord n,w.length+2*a+2≤L→wordBounded A w→ + |trace (matrixWord J w*F a)|≤(errorBudget R Cs Cf a).2*M) := by + intro a + induction a using Nat.strong_induction_on with + | h a ih => + intro ha + have hs₀ : 0≤Cs a := hsn a ha + have hf₀ : 0≤Cf a := hfn a ha + have hprev (b : Fin a) := ih b b.isLt (b.isLt.le.trans ha) + have hCs (w : OrdinaryWord n) (hlen : w.length≤L) (hwb : wordBounded A w) : + |trace (matrixWord J w*Es a)|≤Cs a*M := + hs a ha w hlen hwb + have hCf (w : OrdinaryWord n) (hlen : w.length≤L) (hwb : wordBounded A w) : + |trace (matrixWord J w*Ef a)|≤Cf a*M := + hf a ha w hlen hwb + have hsource : ∀w:OrdinaryWord n,w.length+2*a+1≤L→wordBounded A w→ + |trace (matrixWord J w*E a)|≤(errorBudget R Cs Cf a).1*M := by + intro w hlen hwb + have hterms (b : Fin a) : |trace (matrixWord J w*(Matrix.diagonal (p a b)*F b))|≤ + (errorBudget R Cs Cf b).2*M := by + have H:=(hprev b).2 (w++[.diag (p a b)]) (by simp only [List.length_append,List.length_singleton]; omega) + (wordBounded_diag hwb _ (hp a ha b)) + simpa only [matrixWord_append,matrixWord,List.map_cons,List.map_nil,List.prod_cons,List.prod_nil, + matrixLetter,List.map_append,List.prod_append,mul_one,mul_assoc] using H + rw [hE a,mul_add,trace_add,errorBudget] + dsimp only + have H:=(Finset.abs_sum_le_sum_abs (s:=Finset.univ) (f:=fun b:Fin a=>trace (matrixWord J w*(Matrix.diagonal (p a b)*F b)))).trans + (Finset.sum_le_sum fun b _=>hterms b) + rw [←trace_sum,←Matrix.mul_sum,←Finset.sum_mul] at H + exact ((abs_add_le _ _).trans (add_le_add H (hCs w (by omega) hwb))).trans_eq (by ring) + refine ⟨hsource,?_⟩ + intro w hlen hwb + have hsnew:=hsource (w++[.noise]) (by simp only [List.length_append,List.length_singleton]; omega) + (wordBounded_noise hwb) + have Hs : |trace (matrixWord J w*(J*E a))|≤(errorBudget R Cs Cf a).1*M := by + simpa only [matrixWord_append,matrixWord,List.map_cons,List.map_nil,List.prod_cons,List.prod_nil, + matrixLetter,List.map_append,List.prod_append,mul_one,mul_assoc] using hsnew + have hterms (b : Fin a) : |trace (matrixWord J w*(r a b • E b))|≤ + R*(errorBudget R Cs Cf b).1*M := by + have H:=(hprev b).1 w (by omega) hwb + have hB : 0≤(errorBudget R Cs Cf b).1*M := (abs_nonneg _).trans H + rw [Matrix.mul_smul,trace_smul,smul_eq_mul,abs_mul] + exact ((mul_le_mul_of_nonneg_left H (abs_nonneg _)).trans + (mul_le_mul_of_nonneg_right (hr a ha b) hB)).trans_eq (by ring) + have H:=(Finset.abs_sum_le_sum_abs (s:=Finset.univ) (f:=fun b:Fin a=>trace (matrixWord J w*(r a b • E b)))).trans + (Finset.sum_le_sum fun b _=>hterms b) + rw [←trace_sum,←Matrix.mul_sum] at H + rw [hF a,mul_add,mul_sub,trace_add,trace_sub] + apply ((abs_add_le _ _).trans (add_le_add ((abs_sub _ _).trans (add_le_add Hs H)) + (hCf w (by omega) hwb))).trans_eq + rw [errorBudget] + dsimp only + rw [←Finset.sum_mul,←Finset.mul_sum] + ring + +def closedWordBounded (A : ℝ) (w : List (WordLetter (Fin n))) : Prop := + ∀l∈w,match l with | .diag p=>∀i,|p i|≤A | .noise=>True | .inverse=>True + +def ClosedWordTestBound (j : ℝ) (a : Fin n→ℝ) (J : Interaction n) + (A M : ℝ) (L : ℕ) : Prop := + ∀w:List (WordLetter (Fin n)),w.length≤L→inverseCount w≤1→closedWordBounded A w→ + testSize (exactWord j a w J)≤M + +lemma closedWordBounded_append {A : ℝ} {P Q : List (WordLetter (Fin n))} + (hP : closedWordBounded A P) (hQ : closedWordBounded A Q) : closedWordBounded A (P++Q) := by + intro l hl;rcases List.mem_append.mp hl with hl|hl + · exact hP l hl + · exact hQ l hl +lemma closedWordBounded_lift {A : ℝ} {w : OrdinaryWord n} (hw : wordBounded A w) : + closedWordBounded A (liftWord w) := by + intro l hl + obtain ⟨q,hq,rfl⟩:=List.mem_map.mp hl + cases q with + | diag p=>exact hw _ hq + | noise=>trivial + +lemma implicit_error_elimination (A J K E F Es Ef : Interaction n) (q : ℝ) + (hK : K*(1-A*(J-q • 1))=1) + (hE : E=A*F+Es) (hF : F=(J-q • 1)*E+Ef) : + E=K*(Es+A*Ef) := by + have he : (1-A*(J-q • 1))*E=Es+A*Ef := by + rw [sub_mul,one_mul,mul_assoc] + rw [hF,mul_add] at hE + nth_rw 1 [hE] + abel + have hk:=congrArg (fun P:Interaction n=>K*P) he + rw [←mul_assoc,hK,one_mul] at hk + exact hk + +theorem implicit_trace_bound (j : ℝ) (a : Fin n→ℝ) (J Es Ef : Interaction n) + {C D A M : ℝ} {L : ℕ} (hs : TraceControl Es C) (hf : TraceControl Ef D) + (ha : ∀i,|a i|≤A) (hw : ClosedWordTestBound j a J A M L) + (w : OrdinaryWord n) (hlen : w.length+2≤L) (hwb : wordBounded A w) : + |trace (matrixWord J w*((WordLetter.inverse.exactEval j a J)*(Es+Matrix.diagonal a*Ef)))| + ≤(C+D)*M := by + have hb₁ : closedWordBounded (n:=n) A [WordLetter.inverse] := by + intro l hl;have hl₀:=List.mem_singleton.mp hl;subst l;trivial + have hb₂ : closedWordBounded A [WordLetter.inverse,.diag a] := by + intro l hl;simp only [List.mem_cons,List.not_mem_nil,or_false] at hl + rcases hl with rfl|rfl + · trivial + · exact ha + have h₁ := hw (liftWord w++[.inverse]) + (by simpa only [liftWord,List.length_map,List.length_append,List.length_singleton] using (show w.length+1≤L by omega)) + (by rw [inverseCount_append,inverseCount_lift];simp [inverseCount]) (closedWordBounded_append (closedWordBounded_lift hwb) hb₁) + have h₂ := hw (liftWord w++[.inverse,.diag a]) + (by simpa only [liftWord,List.length_map,List.length_append,List.length_cons,List.length_nil] using hlen) + (by rw [inverseCount_append,inverseCount_lift];simp [inverseCount]) (closedWordBounded_append (closedWordBounded_lift hwb) hb₂) + rw [exactWord_append,exactWord_lift] at h₁ h₂ + simp only [exactWord,matrixFactorProduct,List.map_cons,List.map_nil, + List.prod_cons,List.prod_nil,mul_one,WordLetter.exactEval] at h₁ h₂ + have H₁:=(hs.bound (matrixWord J w*WordLetter.inverse.exactEval j a J)).trans + (mul_le_mul_of_nonneg_left h₁ hs.nonneg) + have H₂:=(hf.bound (matrixWord J w*WordLetter.inverse.exactEval j a J*Matrix.diagonal a)).trans + (mul_le_mul_of_nonneg_left (by simpa only [mul_assoc,WordLetter.exactEval] using h₂) hf.nonneg) + rw [mul_add,mul_add,trace_add] + exact ((abs_add_le _ _).trans (add_le_add + (by simpa only [mul_assoc] using H₁) (by simpa only [mul_assoc] using H₂))).trans_eq (by ring) + +theorem implicit_source_field_trace (j : ℝ) (a : Fin n→ℝ) (J E F Es Ef : Interaction n) (q : ℝ) + (hE : E=WordLetter.inverse.exactEval j a J*(Es+Matrix.diagonal a*Ef)) + (hF : F=(J-q • 1)*E+Ef) + {C D A M : ℝ} {L : ℕ} (hs : TraceControl Es C) (hf : TraceControl Ef D) + (ha : ∀i,|a i|≤A) (hw : ClosedWordTestBound j a J A M L) + (w : OrdinaryWord n) (hlen : w.length+3≤L) (hwb : wordBounded A w) : + |trace (matrixWord J w*E)|≤(C+D)*M ∧ + |trace (matrixWord J w*F)|≤((1+|q|)*(C+D)+D)*M := by + have HE : |trace (matrixWord J w*E)|≤(C+D)*M := by + rw [hE];exact implicit_trace_bound j a J Es Ef hs hf ha hw w (by omega) hwb + have HJ : |trace (matrixWord J w*(J*E))|≤(C+D)*M := by + have H:=implicit_trace_bound j a J Es Ef hs hf ha hw (w++[.noise]) + (by simp only [List.length_append,List.length_singleton];omega) (wordBounded_noise hwb) + simpa only [←hE,matrixWord_append,matrixWord,List.map_cons,List.map_nil,List.prod_cons, + List.prod_nil,List.map_append,List.prod_append,matrixLetter,mul_one,mul_assoc] using H + have Hf : |trace (matrixWord J w*Ef)|≤D*M := by + have H:=hw (liftWord w) (by simp only [liftWord,List.length_map];omega) + (by simp) (closedWordBounded_lift hwb) + rw [exactWord_lift] at H + exact (hf.bound _).trans (mul_le_mul_of_nonneg_left H hf.nonneg) + refine ⟨HE,?_⟩ + rw [hF,sub_mul,smul_mul_assoc,one_mul,mul_add,mul_sub,Matrix.mul_smul, + trace_add,trace_sub,trace_smul,smul_eq_mul] + have HQ : |q*trace (matrixWord J w*E)|≤|q| *((C+D)*M) := by + rw [abs_mul];exact mul_le_mul_of_nonneg_left HE (abs_nonneg _) + exact ((abs_add_le _ _).trans (add_le_add ((abs_sub _ _).trans (add_le_add HJ HQ)) Hf)).trans_eq (by ring) + +lemma ClosedWordTestBound.ordinary {j : ℝ} {a : Fin n→ℝ} {J : Interaction n} + {A M : ℝ} {L : ℕ} (h : ClosedWordTestBound j a J A M L) : WordTestBound J A M L := by + intro w hw hb + have H:=h (liftWord w) (by simpa only [liftWord,List.length_map] using hw) + (by simp) (closedWordBounded_lift hb) + simpa only [exactWord_lift] using H + +theorem closed_finite_graph_trace (j : ℝ) (a₀ : Fin n→ℝ) (J : Interaction n) + (E F Es Ef : ℕ→Interaction n) (P Q : Interaction n) (q : ℝ) + (p : (a : ℕ)→Fin a→Fin n→ℝ) (r : (a : ℕ)→Fin a→ℝ) + (hE : ∀a,E a=(∑b:Fin a,Matrix.diagonal (p a b)*F b)+Es a) + (hF : ∀a,F a=J*E a-(∑b:Fin a,r a b • E b)+Ef a) + (hEs : Es 0=WordLetter.inverse.exactEval j a₀ J*(P+Matrix.diagonal a₀*Q)) + (hEf : Ef 0=(-q) • Es 0+Q) + {C D A R M : ℝ} {Cs Cf : ℕ→ℝ} {N L : ℕ} + (hP : TraceControl P C) (hQ : TraceControl Q D) + (hR : 0≤R) (hM : 0≤M) (ha : ∀i,|a₀ i|≤A) + (hp : ∀a≤N,∀b i,|p a b i|≤A) (hr : ∀a≤N,∀b,|r a b|≤R) + (hs : ∀a≤N,0if a=0 then C+D else Cs a + let Bf:=fun a=>if a=0 then |q| *(C+D)+D else Cf a + ∀a≤N, + (∀w:OrdinaryWord n,w.length+2*a+1≤L→wordBounded A w→ + |trace (matrixWord J w*E a)|≤(errorBudget R Bs Bf a).1*M) ∧ + (∀w:OrdinaryWord n,w.length+2*a+2≤L→wordBounded A w→ + |trace (matrixWord J w*F a)|≤(errorBudget R Bs Bf a).2*M) := by + dsimp only + have hsource (w : OrdinaryWord n) (hlen : w.length≤L) (hwb : wordBounded A w) : + |trace (matrixWord J w*Es 0)|≤(C+D)*M := by + rw [hEs] + exact implicit_trace_bound j a₀ J P Q hP hQ ha hw w (by omega) hwb + have hfield (w : OrdinaryWord n) (hlen : w.length≤L) (hwb : wordBounded A w) : + |trace (matrixWord J w*Ef 0)|≤(|q| *(C+D)+D)*M := by + have H₁:=hsource w hlen hwb + have H₂:=(hQ.bound (matrixWord J w)).trans (mul_le_mul_of_nonneg_left + (hw.ordinary w (by omega) hwb) hQ.nonneg) + rw [hEf,mul_add,Matrix.mul_smul,trace_add,trace_smul,smul_eq_mul] + have H₃ : |(-q)*trace (matrixWord J w*Es 0)|≤|q| *((C+D)*M) := by + rw [abs_mul,abs_neg];exact mul_le_mul_of_nonneg_left H₁ (abs_nonneg q) + exact ((abs_add_le _ _).trans (add_le_add H₃ H₂)).trans_eq (by ring) + apply finite_graph_trace_tested J E F Es Ef p r hE hF hR hM hp hr + · intro a haN;split_ifs with h + · exact add_nonneg hP.nonneg hQ.nonneg + · exact (hs a haN (Nat.pos_of_ne_zero h)).nonneg + · intro a haN;split_ifs with h + · exact add_nonneg (mul_nonneg (abs_nonneg _) (add_nonneg hP.nonneg hQ.nonneg)) hQ.nonneg + · exact (hf a haN (Nat.pos_of_ne_zero h)).nonneg + · intro a haN w hlen hwb + by_cases ha0 : a=0 + · subst a;simpa only [ite_true] using hsource w hlen hwb + · simpa only [ite_eq_right ha0] using (hs a haN (Nat.pos_of_ne_zero ha0)).bound (matrixWord J w) |>.trans + (mul_le_mul_of_nonneg_left (hw.ordinary w (by omega) hwb) (hs a haN (Nat.pos_of_ne_zero ha0)).nonneg) + · intro a haN w hlen hwb + by_cases ha0 : a=0 + · subst a;simpa only [ite_true] using hfield w hlen hwb + · simpa only [ite_eq_right ha0] using (hf a haN (Nat.pos_of_ne_zero ha0)).bound (matrixWord J w) |>.trans + (mul_le_mul_of_nonneg_left (hw.ordinary w (by omega) hwb) (hf a haN (Nat.pos_of_ne_zero ha0)).nonneg) + +end SKGapCutoff.Recipe + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Matrix/ClosedMatrix.lean b/lean/OAI/Probability/SKGap/Matrix/ClosedMatrix.lean new file mode 100644 index 0000000000000000000000000000000000000000..f722474b07af81f165e3ed7160a4fb3e348d1cca --- /dev/null +++ b/lean/OAI/Probability/SKGap/Matrix/ClosedMatrix.lean @@ -0,0 +1,79 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.ClosedPrediction +import OAI.Probability.SKGap.Matrix.ClosedTrace + +namespace OAI + +section + +noncomputable section +open scoped BigOperators +namespace SKGap.Noncrossing.Primary.Tensor.Series.GradedWords +open Matrix Diagram InverseDiagram +variable {ι : Type*} [Fintype ι] [DecidableEq ι] + +lemma matrixValue_append (j : ℝ) (a : ι→ℝ) (J : Matrix ι ι ℝ) (P Q : GradedWords ι) : + matrixValue j a J (P++Q)=matrixValue j a J P+matrixValue j a J Q := by + simp [matrixValue] +lemma matrixValue_scalar (j c : ℝ) (a : ι→ℝ) (J : Matrix ι ι ℝ) : + matrixValue j a J (scalar c)=c • 1 := by + simp [matrixValue,scalar,exactWord,matrixFactorProduct] +lemma matrixValue_bump (j : ℝ) (a : ι→ℝ) (J : Matrix ι ι ℝ) (P : GradedWords ι) : + matrixValue j a J (bump P)=matrixValue j a J P := by + simp [matrixValue,bump,List.map_map,Function.comp_def] +lemma matrixValue_scale (j c : ℝ) (a : ι→ℝ) (J : Matrix ι ι ℝ) (P : GradedWords ι) : + matrixValue j a J (scale c P)=c • matrixValue j a J P := by + induction P with + | nil => simp [matrixValue,scale] + | cons t P ih => + simp only [scale,List.map_cons,matrixValue,List.sum_cons] + change (c*t.1) • _+matrixValue j a J (scale c P)=c • (t.1 • _+matrixValue j a J P) + rw [ih,smul_add,smul_smul] +lemma matrixValue_prepend (j : ℝ) (a : ι→ℝ) (J : Matrix ι ι ℝ) (P : GradedWords ι) (l : WordLetter ι) : + matrixValue j a J (prepend l P)=l.exactEval j a J*matrixValue j a J P := by + induction P with + | nil => simp [matrixValue,prepend] + | cons t P ih => + simp only [prepend,List.map_cons,matrixValue,List.sum_cons] + change t.1 • (l.exactEval j a J*exactWord j a t.2.2 J)+matrixValue j a J (prepend l P)=_ + rw [ih,mul_add,mul_smul_comm] + rfl +lemma matrixValue_ordinaryWords (j : ℝ) (a : ι→ℝ) (J : Matrix ι ι ℝ) (t : SourceTree (ι→ℝ)) : + (matrixValue j a J (ordinaryWords j t).1,matrixValue j a J (ordinaryWords j t).2)= + (t.sourceMatrix j J,t.fieldMatrix j J) := by + induction t with + | leaf c => simp [ordinaryWords,matrixValue_bump,matrixValue_prepend,matrixValue_scalar, + SourceTree.sourceMatrix_leaf,SourceTree.fieldMatrix_leaf,WordLetter.exactEval] + | branch p t u ht hu => + have hs:=congrArg Prod.fst ht + have hf:=congrArg Prod.snd ht + have us:=congrArg Prod.fst hu + have uf:=congrArg Prod.snd hu + dsimp only at hs hf us uf + simp only [ordinaryWords,branch,matrixValue_append,matrixValue_bump,matrixValue_prepend, + matrixValue_scale,WordLetter.exactEval,hs,hf,us,uf, + SourceTree.sourceMatrix_branch,SourceTree.fieldMatrix_branch,neg_smul,sub_eq_add_neg] +lemma matrixValue_implicitSource (j : ℝ) (a p : ι→ℝ) (J : Matrix ι ι ℝ) (t : SourceTree (ι→ℝ)) : + matrixValue j a J (implicitSource j a p t)=WordLetter.inverse.exactEval j a J* + (Matrix.diagonal p*t.fieldMatrix j J-(j*Diagram.mean p) • (Matrix.diagonal a*t.sourceMatrix j J)) := by + have hs:=congrArg Prod.fst (matrixValue_ordinaryWords j a J t) + have hf:=congrArg Prod.snd (matrixValue_ordinaryWords j a J t) + dsimp only at hs hf + simp only [implicitSource,matrixValue_prepend,matrixValue_append,matrixValue_scale, + matrixValue_bump,WordLetter.exactEval,hs,hf,neg_smul,sub_eq_add_neg] +lemma matrixValue_implicitField (j : ℝ) (a p : ι→ℝ) (J : Matrix ι ι ℝ) (t : SourceTree (ι→ℝ)) : + matrixValue j a J (implicitField j a p t)= + (J-(j*Diagram.mean a) • 1)*matrixValue j a J (implicitSource j a p t)- + (j*Diagram.mean p) • t.sourceMatrix j J := by + have hs:=congrArg Prod.fst (matrixValue_ordinaryWords j a J t) + dsimp only at hs + simp only [implicitField,matrixValue_append,matrixValue_bump,matrixValue_prepend, + matrixValue_scale,WordLetter.exactEval,hs,neg_smul,smul_mul_assoc,one_mul, + sub_eq_add_neg,add_mul,neg_mul] + +end SKGap.Noncrossing.Primary.Tensor.Series.GradedWords + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Matrix/ClosedTrace.lean b/lean/OAI/Probability/SKGap/Matrix/ClosedTrace.lean new file mode 100644 index 0000000000000000000000000000000000000000..3436197a27a0c8ccf54318074f3d977e27b4844a --- /dev/null +++ b/lean/OAI/Probability/SKGap/Matrix/ClosedTrace.lean @@ -0,0 +1,273 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.Operation +import OAI.Probability.SKGap.Localization.CyclicPrediction +import OAI.Probability.SKGap.Matrix.WordFockSeries +import OAI.Probability.SKGap.Localization.ClosedPrediction + +namespace OAI + +section + +noncomputable section +open scoped BigOperators Matrix.Norms.Frobenius +namespace SKGap.Noncrossing +open Matrix +variable {ι : Type*} [Fintype ι] [DecidableEq ι] + +lemma exactWord_append (j : ℝ) (a : ι→ℝ) (J : Matrix ι ι ℝ) (P Q : List (WordLetter ι)) : + exactWord j a (P++Q) J=exactWord j a P J*exactWord j a Q J := by + induction P with + | nil => simp [exactWord,matrixFactorProduct] + | cons l P ih => + change l.exactEval j a J*exactWord j a (P++Q) J= + (l.exactEval j a J*exactWord j a P J)*exactWord j a Q J + rw [ih,mul_assoc] +lemma exactWord_diag (j : ℝ) (a d : ι→ℝ) (J : Matrix ι ι ℝ) (F : List (WordLetter ι)) : + exactWord j a (.diag d::F) J=Matrix.diagonal d*exactWord j a F J := rfl + +omit [DecidableEq ι] in +lemma wordPrediction_diag (j : ℝ) (a d : ι→ℝ) (z : ℝ) (F : List (WordLetter ι)) + (hF : inverseCount F≤1) (i : ι) : + wordPrediction j a z (.diag d::F) i=d i*wordPrediction j a z F i := by + have hp : wordPredictionPolynomial j a (.diag d::F) i= + Polynomial.C (d i)*wordPredictionPolynomial j a F i := by + apply Polynomial.ext + intro n + rw [←Primary.Tensor.Series.wordSeq_project_coeff j a (.diag d::F) (show inverseCount (.diag d::F)≤1 from hF), + Polynomial.coeff_C_mul,←Primary.Tensor.Series.wordSeq_project_coeff j a F hF, + Primary.Tensor.Series.wordSeq_cons] + rfl + have h:=congrArg (Polynomial.eval z) hp + simpa only [Polynomial.eval_mul,Polynomial.eval_C, + fun F i=>(wordPredictionPolynomial_spec j a F i).2 z] using h + +lemma trace_small_diagonal_error (s v : ι→ℝ) (Q : Matrix ι ι ℝ) : + |trace (Matrix.diagonal s*Q)-∑ i,s i*v i|≤ + ‖(WithLp.toLp 2 s : EuclideanSpace ℝ ι)‖*diagonalSeminorm (Q-Matrix.diagonal v) := by + have h:=abs_real_inner_le_norm (WithLp.toLp 2 s : EuclideanSpace ℝ ι) + (diagonalVector (Q-Matrix.diagonal v)) + simpa only [trace,diag,Matrix.diagonal_mul,Matrix.sub_apply,Matrix.diagonal_apply_eq, + diagonalVector,PiLp.inner_apply,Real.inner_apply,PiLp.toLp_apply, + mul_sub,Finset.sum_sub_distrib,diagonalSeminorm] using h + +theorem rotated_small_word_trace_error (j : ℝ) (a d s : ι→ℝ) (J : Matrix ι ι ℝ) + (P Q : List (WordLetter ι)) (hF : inverseCount (P++(.diag s::Q))≤1) : + |trace (Matrix.diagonal d*exactWord j a (P++(.diag s::Q)) J)- + ∑ i,d i*wordPrediction j a 1 (P++(.diag s::Q)) i|≤ + ‖(WithLp.toLp 2 s : EuclideanSpace ℝ ι)‖* + diagonalSeminorm (exactWord j a (Q++(.diag d::P)) J- + Matrix.diagonal (wordPrediction j a 1 (Q++(.diag d::P)))) := by + have hrot : inverseCount (Q++(.diag d::P))≤1 := by + simp only [inverseCount_append] at hF ⊢ + change inverseCount Q+inverseCount P≤1 + change inverseCount P+inverseCount Q≤1 at hF + omega + have hc : (∑ i,d i*wordPrediction j a 1 (P++(.diag s::Q)) i)= + ∑ i,s i*wordPrediction j a 1 (Q++(.diag d::P)) i := by + have h0 : inverseCount ((.diag d::P)++(.diag s::Q))≤1 := hF + have h:=wordPrediction_mean_cyclic j a 1 (.diag d::P) (.diag s::Q) h0 + simpa only [List.cons_append,wordPrediction_diag j a d 1 _ hF, + wordPrediction_diag j a s 1 _ hrot] using h + rw [hc,exactWord_append,exactWord_diag,←mul_assoc, + trace_mul_comm (Matrix.diagonal d*exactWord j a P J),mul_assoc] + rw [←exactWord_diag,←exactWord_append] + exact trace_small_diagonal_error s _ _ + +namespace Primary.Tensor.Series.GradedWords + +def matrixValue (j : ℝ) (a : ι→ℝ) (J : Matrix ι ι ℝ) (P : GradedWords ι) : Matrix ι ι ℝ := + (P.map (fun t=>t.1 • exactWord j a t.2.2 J)).sum + +lemma trace_list_error (j : ℝ) (a d : ι→ℝ) (J : Matrix ι ι ℝ) (P : GradedWords ι) + (b : List (WordLetter ι)→ℝ) + (h : ∀ t∈P,|trace (Matrix.diagonal d*exactWord j a t.2.2 J)- + ∑ i,d i*wordPrediction j a 1 t.2.2 i|≤b t.2.2) : + |trace (Matrix.diagonal d*matrixValue j a J P)-∑ i,d i*prediction j a 1 P i|≤ + (P.map (fun t=>|t.1| *b t.2.2)).sum := by + induction P with + | nil => simp [matrixValue,prediction] + | cons t P ih => + have ht:=h t (by simp) + have hP:=ih (by intro s hs; exact h s (List.mem_cons_of_mem _ hs)) + simp only [matrixValue,prediction,List.map_cons,List.sum_cons] at * + simp only [one_pow,mul_one] at * + simp only [mul_add,mul_smul_comm,trace_add,trace_smul,smul_eq_mul, + Finset.sum_add_distrib] + have he : (∑ i,d i*(t.1*wordPrediction j a 1 t.2.2 i))= + t.1*(∑ i,d i*wordPrediction j a 1 t.2.2 i) := by + rw [Finset.mul_sum]; apply Finset.sum_congr rfl; intro i _; ring + rw [he] + have ha := abs_add_le + (t.1*(trace (Matrix.diagonal d*exactWord j a t.2.2 J)-∑ i,d i*wordPrediction j a 1 t.2.2 i)) + (trace (Matrix.diagonal d*(List.map (fun t=>t.1 • exactWord j a t.2.2 J) P).sum)- + ∑ i,d i*(List.map (fun t=>t.1*wordPrediction j a 1 t.2.2 i) P).sum) + rw [abs_mul] at ha + calc + _ = |t.1*(trace (Matrix.diagonal d*exactWord j a t.2.2 J)-∑ i,d i*wordPrediction j a 1 t.2.2 i)+ + (trace (Matrix.diagonal d*(List.map (fun t=>t.1 • exactWord j a t.2.2 J) P).sum)- + ∑ i,d i*(List.map (fun t=>t.1*wordPrediction j a 1 t.2.2 i) P).sum)| := by congr 1; ring + _ ≤ _ := ha.trans (add_le_add (mul_le_mul_of_nonneg_left ht (abs_nonneg _)) hP) + +theorem closed_source_trace_bound (j : ℝ) (a d : ι→ℝ) (J : Matrix ι ι ℝ) + (t : ClosedTree (ι→ℝ)) (ht : t.leafMass=0) (b : List (WordLetter ι)→ℝ) + (h : ∀ w∈(t.words j a).1,|trace (Matrix.diagonal d*exactWord j a w.2.2 J)- + ∑ i,d i*wordPrediction j a 1 w.2.2 i|≤b w.2.2) : + |trace (Matrix.diagonal d*matrixValue j a J (t.words j a).1)|≤ + ((t.words j a).1.map (fun w=>|w.1| *b w.2.2)).sum := by + have H:=trace_list_error j a d J (t.words j a).1 b h + simpa only [t.source_prediction_zero j a ht, mul_zero,Finset.sum_const_zero,sub_zero] using H +end Primary.Tensor.Series.GradedWords +end SKGap.Noncrossing + +end +end + +section + +noncomputable section +open scoped BigOperators Matrix.Norms.Frobenius +namespace SKGap.Noncrossing.Primary +open Diagram WordSeries Matrix +variable {n : ℕ} + +inductive SmallMark (n : ℕ) where + | diagonal : List (Letter (Fin n→ℝ))→(Fin n→ℝ)→List (Letter (Fin n→ℝ))→SmallMark n + | average : (Fin n→ℝ)→List (Letter (Fin n→ℝ))→SmallMark n + +namespace SmallMark + +def vector : SmallMark n→Fin n→ℝ + | .diagonal _ s _ => s + | .average s _ => s + +def word : SmallMark n→List (Letter (Fin n→ℝ)) + | .diagonal P s Q => P++(.diag s::Q) + | .average _ P => P + +def scalar : SmallMark n→ℝ + | .diagonal _ _ _ => 1 + | .average s _ => Diagram.mean s + +def prepend (P : List (Letter (Fin n→ℝ))) : SmallMark n→SmallMark n + | .diagonal Q s R => .diagonal (P++Q) s R + | .average s Q => .average s (P++Q) + +lemma prefix_vector (P : List (Letter (Fin n→ℝ))) (t : SmallMark n) : (t.prepend P).vector=t.vector := by cases t <;> rfl +lemma prefix_scalar (P : List (Letter (Fin n→ℝ))) (t : SmallMark n) : (t.prepend P).scalar=t.scalar := by cases t <;> rfl +lemma prefix_word (P : List (Letter (Fin n→ℝ))) (t : SmallMark n) : (t.prepend P).word=P++t.word := by + cases t <;> simp [prepend,word,List.append_assoc] + +def diagnostic (d : Fin n→ℝ) : SmallMark n→List (Letter (Fin n→ℝ)) + | .diagonal P _ Q => Q++(.diag d::P) + | .average _ P => P + +lemma average_norm_product (hn : 0s) (fun _=>d) (fun _=>false) hn + (fun i=>hd i) + change SKGapCutoff.Recipe.vectorNorm ((SKGapCutoff.Primary.siteMean (fun _=>s) (fun _=>false)) • d)≤_ at H + rw [SKGapCutoff.Recipe.vectorNorm_smul] at H + simpa only [SKGapCutoff.Primary.siteMean,Diagram.mean,Fintype.card_fin] using H + +lemma rotated_trace_error (j : ℝ) (J : Matrix (Fin n) (Fin n) ℝ) (d s : Fin n→ℝ) + (P Q : List (Letter (Fin n→ℝ))) : + |trace (Matrix.diagonal d*matrixWord J (P++(.diag s::Q)))- + ∑i,d i*Diagram.prediction j (P++(.diag s::Q)) i| ≤ + SKGapCutoff.Recipe.vectorNorm s * diagonalSeminorm + (matrixWord J (Q++(.diag d::P))-Matrix.diagonal (Diagram.prediction j (Q++(.diag d::P)))) := by + have h1 : liftWord P++(.diag s::liftWord Q)=liftWord (P++(.diag s::Q)) := by simp [liftWord,Letter.toWord] + have h2 : liftWord Q++(.diag d::liftWord P)=liftWord (Q++(.diag d::P)) := by simp [liftWord,Letter.toWord] + have H:=rotated_small_word_trace_error j (fun _:Fin n=>0) d s J (liftWord P) (liftWord Q) + (by rw [h1,inverseCount_lift]; omega) + rw [h1,h2,exactWord_lift,exactWord_lift] at H + have he : wordPrediction j (fun _:Fin n=>0) 1 (liftWord (Q++(.diag d::P)))= + Diagram.prediction j (Q++(.diag d::P)) := by funext i; exact wordPrediction_lift .. + rw [he] at H + simpa only [wordPrediction_lift,SKGapCutoff.Recipe.vectorNorm] using H + +theorem trace_error (j : ℝ) (J : Matrix (Fin n) (Fin n) ℝ) (hn : 0 + simpa only [scalar,one_mul,word,diagnostic,vector] using + (rotated_trace_error j J d s P Q).trans + (mul_le_mul_of_nonneg_left hb (norm_nonneg _)) + | average s P => + have H:=trace_small_diagonal_error d (Diagram.prediction j P) (matrixWord J P) + rw [abs_mul] + exact (mul_le_mul_of_nonneg_left H (abs_nonneg _)).trans + (by + change |Diagram.mean s| * (SKGapCutoff.Recipe.vectorNorm d*_)≤SKGapCutoff.Recipe.vectorNorm s*B + calc + _ ≤ |Diagram.mean s| *(SKGapCutoff.Recipe.vectorNorm d*B) := + mul_le_mul_of_nonneg_left (mul_le_mul_of_nonneg_left hb (norm_nonneg _)) (abs_nonneg _) + _ = (|Diagram.mean s| * SKGapCutoff.Recipe.vectorNorm d)*B := by ring + _ ≤ _ := mul_le_mul_of_nonneg_right (average_norm_product hn s d hd) hB) + +end SmallMark + +abbrev MarkedPolynomial (n : ℕ) := List (ℝ×SmallMark n) +namespace MarkedPolynomial + +def plain (P : MarkedPolynomial n) : WordPolynomial (ι:=Fin n) := + P.map (fun t=>(t.1*t.2.scalar,t.2.word)) +def budget (P : MarkedPolynomial n) : ℝ := + (P.map (fun t=>|t.1| *SKGapCutoff.Recipe.vectorNorm t.2.vector)).sum + +def prepend (F : List (Letter (Fin n→ℝ))) (P : MarkedPolynomial n) : MarkedPolynomial n := + P.map (fun t=>(t.1,t.2.prepend F)) +def scale (c : ℝ) (P : MarkedPolynomial n) : MarkedPolynomial n := P.map (fun t=>(c*t.1,t.2)) + +lemma plain_prefix (F : List (Letter (Fin n→ℝ))) (P : MarkedPolynomial n) : + (P.prepend F).plain=prependWords F P.plain := by + simp [prepend,plain,prependWords,List.map_map,Function.comp_def,SmallMark.prefix_scalar,SmallMark.prefix_word] +lemma plain_scale (c : ℝ) (P : MarkedPolynomial n) : (P.scale c).plain=Primary.scale c P.plain := by + simp [scale,plain,Primary.scale,List.map_map,Function.comp_def,mul_assoc] +lemma plain_append (P Q : MarkedPolynomial n) : (P++Q).plain=P.plain++Q.plain := by simp [plain] +lemma budget_prefix (F : List (Letter (Fin n→ℝ))) (P : MarkedPolynomial n) : (P.prepend F).budget=P.budget := by + simp [prepend,budget,List.map_map,Function.comp_def,SmallMark.prefix_vector] +lemma budget_scale (c : ℝ) (P : MarkedPolynomial n) : (P.scale c).budget=|c| *P.budget := by + induction P with + | nil => simp [scale,budget] + | cons t P ih => simp [scale,budget,abs_mul,mul_assoc,mul_add] at *; exact ih +lemma budget_append (P Q : MarkedPolynomial n) : (P++Q).budget=P.budget+Q.budget := by simp [budget] + +theorem trace_error (j : ℝ) (J : Matrix (Fin n) (Fin n) ℝ) (hn : 0 simp [plain,budget,matrixPolynomial,polynomialPrediction] + | cons t P ih => + have ht:=SmallMark.trace_error j J hn d hd t.2 hB (hb t (by simp)) + have hh:=ih (fun s hs=>hb s (List.mem_cons_of_mem _ hs)) + simp only [plain,List.map_cons,matrixPolynomial,List.sum_cons,polynomialPrediction,budget] at * + simp only [mul_add,mul_smul_comm,trace_add,trace_smul,smul_eq_mul,Finset.sum_add_distrib,add_mul] + have he : (∑i,d i*(t.1*t.2.scalar*Diagram.prediction j t.2.word i))= + t.1*t.2.scalar*(∑i,d i*Diagram.prediction j t.2.word i) := by + rw [Finset.mul_sum]; apply Finset.sum_congr rfl; intro i _; ring + rw [he] + have hc:=mul_le_mul_of_nonneg_left ht (abs_nonneg t.1) + rw [←abs_mul] at hc + calc + _ = |t.1*(t.2.scalar*(trace (Matrix.diagonal d*matrixWord J t.2.word)- + ∑i,d i*Diagram.prediction j t.2.word i))+ + (trace (Matrix.diagonal d*(List.map (fun p=>p.1 • matrixWord J p.2) + (List.map (fun t=>(t.1*t.2.scalar,t.2.word)) P)).sum)- + ∑i,d i*(List.map (fun p=>p.1*Diagram.prediction j p.2 i) + (List.map (fun t=>(t.1*t.2.scalar,t.2.word)) P)).sum)| := by congr 1; ring + _ ≤ _ := (abs_add_le _ _).trans (add_le_add (by convert! hc using 1; ring) hh) + +end MarkedPolynomial +end SKGap.Noncrossing.Primary + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Matrix/ClosedTreeMatrix.lean b/lean/OAI/Probability/SKGap/Matrix/ClosedTreeMatrix.lean new file mode 100644 index 0000000000000000000000000000000000000000..242f537e54bb5990ddc4da5c5e0fa500d6dfb3aa --- /dev/null +++ b/lean/OAI/Probability/SKGap/Matrix/ClosedTreeMatrix.lean @@ -0,0 +1,91 @@ +import Mathlib +import OAI.Probability.SKGap.Matrix.ClosedMatrix + +namespace OAI + +section + +noncomputable section +open scoped BigOperators +namespace SKGap.Noncrossing.Primary.Tensor.Series.ClosedTree +open Matrix GradedWords +variable {ι : Type*} [Fintype ι] [DecidableEq ι] + +def ofOrdinary : SourceTree (ι→ℝ)→ClosedTree (ι→ℝ) + | .leaf c => .leaf c + | .branch p t u => .branch p (ofOrdinary t) (ofOrdinary u) +omit [DecidableEq ι] in +lemma words_ofOrdinary (j : ℝ) (a : ι→ℝ) (t : SourceTree (ι→ℝ)) : + (ofOrdinary t).words j a=ordinaryWords j t := by + induction t with + | leaf c => rfl + | branch p t u ht hu => simp only [ofOrdinary,words,ordinaryWords,ht,hu] + +def sourceMatrix (j : ℝ) (a : ι→ℝ) (J : Matrix ι ι ℝ) (t : ClosedTree (ι→ℝ)) := + GradedWords.matrixValue j a J (t.words j a).1 +def fieldMatrix (j : ℝ) (a : ι→ℝ) (J : Matrix ι ι ℝ) (t : ClosedTree (ι→ℝ)) := + GradedWords.matrixValue j a J (t.words j a).2 +lemma sourceMatrix_ofOrdinary (j : ℝ) (a : ι→ℝ) (J : Matrix ι ι ℝ) (t : SourceTree (ι→ℝ)) : + (ofOrdinary t).sourceMatrix j a J=t.sourceMatrix j J := by + rw [sourceMatrix,words_ofOrdinary] + exact congrArg Prod.fst (matrixValue_ordinaryWords j a J t) +lemma fieldMatrix_ofOrdinary (j : ℝ) (a : ι→ℝ) (J : Matrix ι ι ℝ) (t : SourceTree (ι→ℝ)) : + (ofOrdinary t).fieldMatrix j a J=t.fieldMatrix j J := by + rw [fieldMatrix,words_ofOrdinary] + exact congrArg Prod.snd (matrixValue_ordinaryWords j a J t) +lemma sourceMatrix_leaf (j c : ℝ) (a : ι→ℝ) (J : Matrix ι ι ℝ) : + (ClosedTree.leaf c).sourceMatrix j a J=c • 1 := by + simp [sourceMatrix,words,ordinaryWords,matrixValue_scalar] +lemma fieldMatrix_leaf (j c : ℝ) (a : ι→ℝ) (J : Matrix ι ι ℝ) : + (ClosedTree.leaf c).fieldMatrix j a J=c • J := by + simp [fieldMatrix,words,ordinaryWords,matrixValue_bump,matrixValue_prepend, + matrixValue_scalar,WordLetter.exactEval] +lemma sourceMatrix_branch (j : ℝ) (a p : ι→ℝ) (J : Matrix ι ι ℝ) (t u : ClosedTree (ι→ℝ)) : + (ClosedTree.branch p t u).sourceMatrix j a J= + Matrix.diagonal p*t.fieldMatrix j a J+u.sourceMatrix j a J := by + simp [sourceMatrix,fieldMatrix,words,GradedWords.branch,matrixValue_append,matrixValue_prepend, + WordLetter.exactEval] +lemma fieldMatrix_branch (j : ℝ) (a p : ι→ℝ) (J : Matrix ι ι ℝ) (t u : ClosedTree (ι→ℝ)) : + (ClosedTree.branch p t u).fieldMatrix j a J= + J*(Matrix.diagonal p*t.fieldMatrix j a J)- + (j*Diagram.mean p) • t.sourceMatrix j a J+u.fieldMatrix j a J := by + simp [sourceMatrix,fieldMatrix,words,GradedWords.branch,matrixValue_append,matrixValue_prepend, + matrixValue_bump,matrixValue_scale,WordLetter.exactEval,sub_eq_add_neg] + abel + +def branches (xs : List ((ι→ℝ)×ClosedTree (ι→ℝ))) : ClosedTree (ι→ℝ) := + xs.foldr (fun t v=>.branch t.1 t.2 v) (.leaf 0) +omit [Fintype ι] [DecidableEq ι] in +lemma branches_leafMass (xs : List ((ι→ℝ)×ClosedTree (ι→ℝ))) : (branches xs).leafMass=0 := by + induction xs with + | nil => rfl + | cons t xs ih => exact ih +lemma branches_source (j : ℝ) (a : ι→ℝ) (J : Matrix ι ι ℝ) + (xs : List ((ι→ℝ)×ClosedTree (ι→ℝ))) : + (branches xs).sourceMatrix j a J= + (xs.map (fun t=>Matrix.diagonal t.1*t.2.fieldMatrix j a J)).sum := by + induction xs with + | nil => simp [branches,sourceMatrix_leaf] + | cons t xs ih => + simpa only [branches,List.foldr_cons,sourceMatrix_branch,List.map_cons,List.sum_cons] using + (congrArg (fun Z=>Matrix.diagonal t.1*t.2.fieldMatrix j a J+Z) ih) +lemma branches_field (j : ℝ) (a : ι→ℝ) (J : Matrix ι ι ℝ) + (xs : List ((ι→ℝ)×ClosedTree (ι→ℝ))) : + (branches xs).fieldMatrix j a J=J*(branches xs).sourceMatrix j a J- + (xs.map (fun t=>(j*Diagram.mean t.1) • t.2.sourceMatrix j a J)).sum := by + induction xs with + | nil => simp [branches,sourceMatrix_leaf,fieldMatrix_leaf] + | cons t xs ih => + change (ClosedTree.branch t.1 t.2 (branches xs)).fieldMatrix j a J=_ + rw [fieldMatrix_branch,ih] + change _=J*(ClosedTree.branch t.1 t.2 (branches xs)).sourceMatrix j a J-_ + rw [sourceMatrix_branch,mul_add] + simp only [List.map_cons,List.sum_cons] + abel + +end SKGap.Noncrossing.Primary.Tensor.Series.ClosedTree + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Matrix/CompletedMatrix.lean b/lean/OAI/Probability/SKGap/Matrix/CompletedMatrix.lean new file mode 100644 index 0000000000000000000000000000000000000000..cf1d7aef3d2a63c65c3a181459fe6f304209fdf5 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Matrix/CompletedMatrix.lean @@ -0,0 +1,320 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.IntegrableLinearCombinationSq +import OAI.Probability.SKGap.Localization.ProdEventSectionLaw + +namespace OAI + +section +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open scoped BigOperators +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open scoped BigOperators +open scoped BigOperators NNReal ENNReal +open MeasureTheory Metric Set +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators NNReal ENNReal Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Set +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators ENNReal NNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Matrix +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators ENNReal NNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal +open scoped BigOperators +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise NNReal ENNReal +open scoped BigOperators +open Filter Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal Topology +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +namespace SKGapCutoff.Regression + +local instance {n m : ℕ} : MeasurableSpace (Matrix (Fin n) (Fin m) ℝ) := + inferInstanceAs (MeasurableSpace (Fin n → Fin m → ℝ)) + +noncomputable def completedMatrix {n r : ℕ} (U Y : Matrix (Fin n) (Fin r) ℝ) + (g : (Fin n × Fin n) → ℝ) : Matrix (Fin n) (Fin n) ℝ := + revealedCompletion U Y + residualProjection U*goe g*residualProjection U + +lemma completedMatrix_symmetric {n r : ℕ} (U Y : Matrix (Fin n) (Fin r) ℝ) + (hY : Uᵀ*Y=Yᵀ*U) (g : (Fin n × Fin n) → ℝ) : + (completedMatrix U Y g)ᵀ=completedMatrix U Y g := by + simp only [completedMatrix,Matrix.transpose_add,Matrix.transpose_mul, + revealedCompletion_symmetric U Y hY,residualProjection_symmetric,goe_symmetric, + Matrix.mul_assoc] + +lemma completedMatrix_answer {n r : ℕ} (U Y : Matrix (Fin n) (Fin r) ℝ) + (hU : Uᵀ*U=1) (hY : Uᵀ*Y=Yᵀ*U) (g : (Fin n × Fin n) → ℝ) : + completedMatrix U Y g*U=Y := by + rw [completedMatrix,Matrix.add_mul,revealedCompletion_answer U Y hU hY, + Matrix.mul_assoc,residualProjection_mul U hU,Matrix.mul_zero,add_zero] + +lemma mul_extendFrame {n r : ℕ} (A : Matrix (Fin n) (Fin n) ℝ) + (U : Matrix (Fin n) (Fin r) ℝ) (q : Fin n → ℝ) : + A*extendFrame U q=extendFrame (A*U) (A *ᵥ q) := by + funext i a + obtain rfl | ⟨a,rfl⟩ := Fin.eq_zero_or_eq_succ a + · rfl + · rfl + +lemma extendedProjection_mul_old {n r : ℕ} (U : Matrix (Fin n) (Fin r) ℝ) + (q : Fin n → ℝ) (hU : Uᵀ*U=1) (ho : Uᵀ *ᵥ q=0) : + residualProjection (extendFrame U q)*residualProjection U= + residualProjection (extendFrame U q) := by + have hqU : (queryColumn q)ᵀ*U=0 := by + ext a b + fin_cases a + have hh := congrFun ho b + simpa only [Matrix.mul_apply,Matrix.transpose_apply,queryColumn,Matrix.mulVec, + dotProduct,Matrix.zero_apply,Pi.zero_apply,mul_comm] using hh + have hqP : (queryColumn q)ᵀ*residualProjection U=(queryColumn q)ᵀ := by + rw [residualProjection,Matrix.mul_sub,Matrix.mul_one, + ← Matrix.mul_assoc,hqU,Matrix.zero_mul,sub_zero] + rw [extendFrame_projection,queryComplement,Matrix.sub_mul, + residualProjection_idem U hU,Matrix.mul_assoc,hqP] + +lemma old_mul_extendedProjection {n r : ℕ} (U : Matrix (Fin n) (Fin r) ℝ) + (q : Fin n → ℝ) (hU : Uᵀ*U=1) (ho : Uᵀ *ᵥ q=0) : + residualProjection U*residualProjection (extendFrame U q)= + residualProjection (extendFrame U q) := by + have hh := congrArg Matrix.transpose (extendedProjection_mul_old U q hU ho) + simpa only [Matrix.transpose_mul,residualProjection_symmetric] using hh + +lemma completedMatrix_new_residual {n r : ℕ} (U Y : Matrix (Fin n) (Fin r) ℝ) + (q : Fin n → ℝ) (hU : Uᵀ*U=1) (ho : Uᵀ *ᵥ q=0) + (g : (Fin n × Fin n) → ℝ) : + residualProjection (extendFrame U q)*completedMatrix U Y g* + residualProjection (extendFrame U q)= + residualProjection (extendFrame U q)*goe g*residualProjection (extendFrame U q) := by + let P := residualProjection U + let Q := residualProjection (extendFrame U q) + have hQP : Q*P=Q := extendedProjection_mul_old U q hU ho + have hPQ : P*Q=Q := old_mul_extendedProjection U q hU ho + have hR : Q*revealedCompletion U Y*Q=0 := by + calc + _ = Q*(P*revealedCompletion U Y*P)*Q := by + simp only [← Matrix.mul_assoc,hQP] + rw [Matrix.mul_assoc (Q*revealedCompletion U Y) P Q,hPQ] + _ = 0 := by rw [revealedCompletion_residual U Y hU,Matrix.mul_zero,Matrix.zero_mul] + change Q*(revealedCompletion U Y+P*goe g*P)*Q=Q*goe g*Q + rw [Matrix.mul_add,Matrix.add_mul,hR,zero_add] + simp only [← Matrix.mul_assoc,hQP] + rw [Matrix.mul_assoc (Q*goe g) P Q,hPQ] + +theorem completedMatrix_update {n r : ℕ} (U Y : Matrix (Fin n) (Fin r) ℝ) + (q : Fin n → ℝ) (hU : Uᵀ*U=1) (hY : Uᵀ*Y=Yᵀ*U) (ho : Uᵀ *ᵥ q=0) + (g : (Fin n × Fin n) → ℝ) : + completedMatrix U Y g = + revealedCompletion (extendFrame U q) (extendFrame Y (completedMatrix U Y g *ᵥ q))+ + residualProjection (extendFrame U q)*goe g*residualProjection (extendFrame U q) := by + have hh := regression_decomposition (completedMatrix U Y g) (extendFrame U q) + (completedMatrix_symmetric U Y hY g) + simpa only [mul_extendFrame,completedMatrix_answer U Y hU hY, + revealedCompletion,completedMatrix_new_residual U Y q hU ho] using hh + +lemma completedMatrix_new_compatibility {n r : ℕ} (U Y : Matrix (Fin n) (Fin r) ℝ) + (q : Fin n → ℝ) (hU : Uᵀ*U=1) (hY : Uᵀ*Y=Yᵀ*U) (g : (Fin n × Fin n) → ℝ) : + (extendFrame U q)ᵀ*extendFrame Y (completedMatrix U Y g *ᵥ q)= + (extendFrame Y (completedMatrix U Y g *ᵥ q))ᵀ*extendFrame U q := by + have he : completedMatrix U Y g*extendFrame U q= + extendFrame Y (completedMatrix U Y g *ᵥ q) := by + rw [mul_extendFrame,completedMatrix_answer U Y hU hY g] + rw [← he,Matrix.transpose_mul,completedMatrix_symmetric U Y hY g,Matrix.mul_assoc] + +lemma completedMatrix_input_decomposition {n r : ℕ} (U Y : Matrix (Fin n) (Fin r) ℝ) + (hU : Uᵀ*U=1) (hY : Uᵀ*Y=Yᵀ*U) (v : Fin n → ℝ) + (g : (Fin n × Fin n) → ℝ) : + completedMatrix U Y g *ᵥ v = Y *ᵥ (Uᵀ *ᵥ v)+ + completedMatrix U Y g *ᵥ (residualProjection U *ᵥ v) := by + simp only [residualProjection,Matrix.sub_mulVec,Matrix.one_mulVec, + Matrix.mulVec_sub,Matrix.mulVec_mulVec] + rw [← Matrix.mul_assoc,completedMatrix_answer U Y hU hY g] + abel + +@[fun_prop] lemma measurable_revealedCompletion {n r : ℕ} : + Measurable (fun z : Matrix (Fin n) (Fin r) ℝ × Matrix (Fin n) (Fin r) ℝ => + revealedCompletion z.1 z.2) := by + apply Measurable.of_eval + intro i + apply Measurable.of_eval + intro j + simp only [revealedCompletion,Matrix.add_apply,Matrix.sub_apply, + Matrix.mul_apply,Matrix.transpose_apply] + fun_prop + +@[fun_prop] lemma measurable_extendFrame {n r : ℕ} : + Measurable (fun z : Matrix (Fin n) (Fin r) ℝ × (Fin n → ℝ) => extendFrame z.1 z.2) := by + apply Measurable.of_eval + intro i + apply Measurable.of_eval + intro a + obtain rfl | ⟨a,rfl⟩ := Fin.eq_zero_or_eq_succ a + · exact (measurable_pi_apply i).comp measurable_snd + · exact (measurable_pi_apply a).comp ((measurable_pi_apply i).comp measurable_fst) + +theorem completedMatrix_regeneration {n r : ℕ} (hn : 0 < n) {H : Type*} + [MeasurableSpace H] (ρ : Measure H) [SFinite ρ] + (U Y : H → Matrix (Fin n) (Fin r) ℝ) (q : H → Fin n → ℝ) + (hUm : Measurable U) (hYm : Measurable Y) (hqm : Measurable q) + (hU : ∀ h, (U h)ᵀ*U h=1) (hY : ∀ h, (U h)ᵀ*Y h=(Y h)ᵀ*U h) + (hq : ∀ h, ∑ i, q h i^2=1) (ho : ∀ h, (U h)ᵀ *ᵥ q h=0) : + let p := fun h => U h *ᵥ ((Y h)ᵀ *ᵥ q h) + (ρ.prod (standardArrayLaw (Fin n × Fin n))).map + (fun z => ((z.1,completedMatrix (U z.1) (Y z.1) z.2 *ᵥ q z.1), + completedMatrix (U z.1) (Y z.1) z.2)) = + ((answerHistoryLaw ρ (fun h => residualProjection (U h)) q).prod + (standardArrayLaw (Fin n × Fin n))).map + (fun z => ((z.1.1,p z.1.1+z.1.2), + completedMatrix (extendFrame (U z.1.1) (q z.1.1)) + (extendFrame (Y z.1.1) (p z.1.1+z.1.2)) z.2)) := by + dsimp only + let P := fun h => residualProjection (U h) + let p := fun h => U h *ᵥ ((Y h)ᵀ *ᵥ q h) + have hU' : Measurable (fun h => fun i j => U h i j) := hUm + have hY' : Measurable (fun h => fun i j => Y h i j) := hYm + have hPm : Measurable P := by + apply Measurable.of_eval + intro i + apply Measurable.of_eval + intro j + simp only [P,residualProjection,Matrix.sub_apply,Matrix.mul_apply,Matrix.transpose_apply] + fun_prop + have hpm : Measurable p := by + apply Measurable.of_eval + intro i + simp only [p,Matrix.mulVec,dotProduct,Matrix.transpose_apply] + fun_prop + have hPq h : P h *ᵥ q h=q h := by + dsimp [P,residualProjection] + rw [Matrix.sub_mulVec,Matrix.one_mulVec,← Matrix.mulVec_mulVec,ho, + Matrix.mulVec_zero,sub_zero] + have hPqc h : P h*queryColumn (q h)=queryColumn (q h) := by + ext i a + fin_cases a + exact congrFun (hPq h) i + have hj := adaptive_query_regeneration hn ρ P q hPm hqm + (fun h => residualProjection_symmetric (U h)) + (fun h => residualProjection_idem (U h) (hU h)) hq hPqc + let out : (H × (Fin n → ℝ)) × ((Fin n × Fin n) → ℝ) → + (H × (Fin n → ℝ)) × Matrix (Fin n) (Fin n) ℝ := fun z => + ((z.1.1,p z.1.1+z.1.2), + revealedCompletion (extendFrame (U z.1.1) (q z.1.1)) + (extendFrame (Y z.1.1) (p z.1.1+z.1.2))+Matrix.of (fun i j => z.2 (i,j))) + have hout : Measurable out := by + have ha : Measurable (fun z : (H × (Fin n → ℝ)) × ((Fin n × Fin n) → ℝ) => + p z.1.1+z.1.2) := (hpm.comp measurable_fst.fst).add measurable_fst.snd + have hu' : Measurable (fun z : (H × (Fin n → ℝ)) × ((Fin n × Fin n) → ℝ) => + extendFrame (U z.1.1) (q z.1.1)) := measurable_extendFrame.comp + ((hUm.comp measurable_fst.fst).prodMk (hqm.comp measurable_fst.fst)) + have hy' : Measurable (fun z : (H × (Fin n → ℝ)) × ((Fin n × Fin n) → ℝ) => + extendFrame (Y z.1.1) (p z.1.1+z.1.2)) := measurable_extendFrame.comp ((hYm.comp measurable_fst.fst).prodMk ha) + have hc := measurable_revealedCompletion.comp (hu'.prodMk hy') + apply (measurable_fst.fst.prodMk ha).prodMk + apply Measurable.of_eval + intro i + apply Measurable.of_eval + intro j + exact (((measurable_pi_apply j).comp (measurable_pi_apply i)).comp hc).add + ((measurable_pi_apply (i,j)).comp measurable_snd) + have hmL : Measurable (fun z : H × ((Fin n × Fin n) → ℝ) => + ((z.1, queryAnswer (P z.1) (q z.1) z.2),queryResidual (P z.1) (q z.1) z.2)) := + (measurable_fst.prodMk (measurable_queryAnswer_comp _ _ _ + (hPm.comp measurable_fst) (hqm.comp measurable_fst) measurable_snd)).prodMk + (measurable_queryResidual_comp _ _ _ (hPm.comp measurable_fst) + (hqm.comp measurable_fst) measurable_snd) + have hmR : Measurable (fun z : (H × (Fin n → ℝ)) × ((Fin n × Fin n) → ℝ) => + (z.1,queryResidual (P z.1.1) (q z.1.1) z.2)) := + measurable_fst.prodMk (measurable_queryResidual_comp _ _ _ + (hPm.comp measurable_fst.fst) (hqm.comp measurable_fst.fst) measurable_snd) + have he := congrArg (Measure.map out) hj + rw [Measure.map_map hout hmL,Measure.map_map hout hmR] at he + have hof (A : Matrix (Fin n) (Fin n) ℝ) : Matrix.of (fun i j => A i j)=A := rfl + have hpoint (z : H × ((Fin n × Fin n) → ℝ)) : out ((z.1,queryAnswer (P z.1) (q z.1) z.2), + queryResidual (P z.1) (q z.1) z.2) = + ((z.1,completedMatrix (U z.1) (Y z.1) z.2 *ᵥ q z.1), + completedMatrix (U z.1) (Y z.1) z.2) := by + have ha := completed_query_answer (U z.1) (Y z.1) (q z.1) z.2 (ho z.1) (hPq z.1) + change completedMatrix (U z.1) (Y z.1) z.2 *ᵥ q z.1=p z.1+queryAnswer (P z.1) (q z.1) z.2 at ha + dsimp only [out] + rw [← ha] + congr 1 + simpa only [extendFrame_projection,P,queryResidual,hof] using + (completedMatrix_update (U z.1) (Y z.1) (q z.1) (hU z.1) (hY z.1) (ho z.1) z.2).symm + simp_rw [Function.comp_def,hpoint] at he + simpa only [out,completedMatrix,queryResidual,← extendFrame_projection,P,p,hof] using he + +end SKGapCutoff.Regression + +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise + +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Matrix/ConditionalEmpiricalNorm.lean b/lean/OAI/Probability/SKGap/Matrix/ConditionalEmpiricalNorm.lean new file mode 100644 index 0000000000000000000000000000000000000000..182076861446f5444074c9c8b3eea1cc9e63512d --- /dev/null +++ b/lean/OAI/Probability/SKGap/Matrix/ConditionalEmpiricalNorm.lean @@ -0,0 +1,143 @@ +import Mathlib +import OAI.Probability.SKGap.Matrix.ConditionalMiddleNorm +import OAI.Probability.SKGap.Localization.ConditionalMiddleSize + +namespace OAI + +section +noncomputable section +namespace SKGap +open Matrix Real Set MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix.Norms.Frobenius + +lemma outer_symmetric {ι : Type*} (x : ι → ℝ) : (vecMulVec x x).IsHermitian := by + ext i k + simp only [conjTranspose_apply,star_trivial,vecMulVec_apply] + ring + +lemma outer_sum_symmetric {ι : Type*} (x y : ι → ℝ) : (vecMulVec x y+vecMulVec y x).IsHermitian := by + ext i k + simp only [conjTranspose_apply,star_trivial,Matrix.add_apply,vecMulVec_apply] + ring + +lemma conditionalBlockMatrix_hermitian {ι : Type*} [Fintype ι] [DecidableEq ι] + (r j q s S a B κ ell : ℝ) (u Z : ι → ℝ) (g : MatrixCoordinates ι → ℝ) : + (conditionalBlockMatrix r j q s S a B κ ell u Z g).IsHermitian := by + unfold conditionalBlockMatrix + rw [goeBlockResidual_expand] + have hh := (goeMatrix_symm r g).add ((outer_sum_symmetric u (goeMatrix r g*ᵥu)).smul + (R := ℝ) (isSelfAdjoint_iff.mpr (star_trivial (κ-1)))) + have hh' := hh.add ((outer_symmetric u).smul (R := ℝ) + (isSelfAdjoint_iff.mpr (star_trivial ((ell-2*κ+1)*goeBilinear r u u g)))) + convert (hh'.add (outer_sum_symmetric u ((j*sqrt (q/s)) • Z-(j*a/s) • u))).add + ((outer_symmetric u).smul (R := ℝ) (isSelfAdjoint_iff.mpr (star_trivial (2*j*(a+B*q)/S)))) using 1 + congr 1 + abel + +lemma empiricalConditionalMiddle_hermitian {n : ℕ} [NeZero n] (j t σ : ℝ) + (y : Fin n → ℝ) (g : MatrixCoordinates (Fin n) → ℝ) : + (empiricalConditionalMiddle j t σ y g).IsHermitian := by + unfold empiricalConditionalMiddle + exact (((conditionalBlockMatrix_hermitian _ _ _ _ _ _ _ _ _ _ _ _).add + ((outer_symmetric _).smul (R := ℝ) (isSelfAdjoint_iff.mpr (star_trivial _)))).add + ((outer_symmetric _).smul (R := ℝ) (isSelfAdjoint_iff.mpr (star_trivial _)))).sub + (Matrix.isHermitian_one.smul (R := ℝ) (isSelfAdjoint_iff.mpr (star_trivial _))) + +lemma empiricalConditionalMiddle_norm {n : ℕ} [NeZero n] (j t σ : ℝ) + (y : Fin n → ℝ) {V W : ℝ} (hV : 0 ≤ V) + (g : MatrixCoordinates (Fin n) → ℝ) + (hq : 0 < scalarQMoment (empiricalLaw y)) + (hcols : ∀ k, ‖empiricalGramColumns y (scalarD j (empiricalLaw y,t,σ)) + (scalarS j (empiricalLaw y,t,σ)) k‖ ≤ V) + (hW : opNorm (goeMatrix (j/(n:ℝ)) g) ≤ W) : + opNorm (empiricalConditionalMiddle j t σ y g) ≤ + conditionalMiddleSize j V W (empiricalLaw y,t,σ) := by + let p : ScalarPoint := (empiricalLaw y,t,σ) + let q := scalarQMoment p.1 + let s := scalarS j p + let B := j*scalarBMoment p.1 + let u := empiricalUnit y q + let X := empiricalGramColumns y (scalarD j p) s 0 + let Z := sqrt s • empiricalGramColumns y (scalarD j p) s 2 + have hu : ‖u‖=1 := empiricalUnit_norm y hq + have hZ : ‖Z‖ ≤ sqrt s*V := by + dsimp [Z] + rw [norm_smul,Real.norm_eq_abs,abs_of_nonneg (sqrt_nonneg _)] + exact mul_le_mul_of_nonneg_left (hcols 2) (sqrt_nonneg _) + have hX : opNorm (vecMulVec X.ofLp X.ofLp) ≤ V^2 := by + apply (operator_vecMulVec_le X X).trans + simpa only [pow_two] using mul_le_mul (hcols 0) (hcols 0) (norm_nonneg _) hV + have hu' : opNorm (vecMulVec u.ofLp u.ofLp) ≤ 1 := by + simpa only [hu,mul_one] using operator_vecMulVec_le u u + have hI : opNorm (1 : Matrix (Fin n) (Fin n) ℝ) ≤ 1 := by + simpa only [Matrix.diagonal_one] using opNorm_diagonal_le (ι := Fin n) zero_le_one (d := fun _=>1) + (fun _=>by norm_num) + have hb := conditionalBlockMatrix_norm (r := j/(n:ℝ)) (j := j) (q := q) (s := s) + (S := s+j*q) (a := scalarA j p) (B := B) (κ := conditionalKappa j p) + (ell := conditionalEll j p) u Z g hu + have hc : opNorm (conditionalBlockMatrix (j/(n:ℝ)) j q s (s+j*q) (scalarA j p) B + (conditionalKappa j p) (conditionalEll j p) u.ofLp Z.ofLp g) ≤ + (1+2*|conditionalKappa j p-1|+|conditionalEll j p-2*conditionalKappa j p+1|)*W+ + 2*(|j*sqrt (q/s)| * (sqrt s*V)+|j*scalarA j p/s|)+|2*j*(scalarA j p+B*q)/(s+j*q)| := by + apply hb.trans + have hn := mul_le_mul_of_nonneg_left hW (by positivity : 0 ≤ 1+2*|conditionalKappa j p-1|+|conditionalEll j p-2*conditionalKappa j p+1|) + have hz := mul_le_mul_of_nonneg_left hZ (abs_nonneg (j*sqrt (q/s))) + linarith + change opNorm (_+j • vecMulVec X.ofLp X.ofLp+(2*j*q) • vecMulVec u.ofLp u.ofLp-B • 1) ≤ _ + rw [sub_eq_add_neg,← neg_smul] + apply (real_opNorm_add _ _).trans + have h1 := real_opNorm_add (conditionalBlockMatrix (j/(n:ℝ)) j q s (s+j*q) (scalarA j p) B + (conditionalKappa j p) (conditionalEll j p) u.ofLp Z.ofLp g+j • vecMulVec X.ofLp X.ofLp) + ((2*j*q) • vecMulVec u.ofLp u.ofLp) + have h2 := real_opNorm_add (conditionalBlockMatrix (j/(n:ℝ)) j q s (s+j*q) (scalarA j p) B + (conditionalKappa j p) (conditionalEll j p) u.ofLp Z.ofLp g) + (j • vecMulVec X.ofLp X.ofLp) + rw [real_opNorm_smul] at h1 h2 + rw [real_opNorm_smul,abs_neg] + have h3 := mul_le_mul_of_nonneg_left hX (abs_nonneg j) + have h4 := mul_le_mul_of_nonneg_left hu' (abs_nonneg (2*j*q)) + have h5 := mul_le_mul_of_nonneg_left hI (abs_nonneg B) + dsimp [conditionalMiddleSize,p,q,s,B,u,X,Z] at hc h1 h2 h3 h4 h5 ⊢ + nlinarith only [hc,h1,h2,h3,h4,h5] +end SKGap +end +end + +section +noncomputable section +namespace SKGap +open Matrix Real Set MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix.Norms.Frobenius + +lemma scalarS_pos_of_time {j t σ : ℝ} (hj : 0 ≤ j) (ht : 0 < t) (P : ProbabilityMeasure ℝ) : + 0 < scalarS j (P,t,σ) := + add_pos_of_pos_of_nonneg (add_pos_of_pos_of_nonneg ht (sq_nonneg _)) + (mul_nonneg hj (scalarQMoment_bounds _).1) + +theorem empiricalConditionalMiddle_uniform_norm {j R t0 T : ℝ} + (hj : 0 ≤ j) (hR : 0 ≤ R) (ht0 : 0 < t0) (W : ℝ) : + ∃ L : ℝ, 1 ≤ L ∧ ∀ (n : ℕ) [NeZero n] (y : Fin n → ℝ), + empiricalLaw y ∈ momentBall R → 0 < scalarQMoment (empiricalLaw y) → + ∀ t ∈ Icc t0 T,∀ σ : ℝ, |σ| ≤ 1 → + ∀ g : MatrixCoordinates (Fin n) → ℝ, opNorm (goeMatrix (j/(n:ℝ)) g) ≤ W → + opNorm (empiricalConditionalMiddle j t σ y g) ≤ L := by + let K := max 1 ((1+|T|+j)/t0) + have hK : 1 ≤ K := le_max_left _ _ + let V := 2*K*(R+2) + have hV : 0 ≤ V := by dsimp [V]; positivity + obtain ⟨L,hL,hbd⟩ := conditionalMiddleSize_uniform (T := T) hj hR ht0 V W + refine ⟨L,hL,?_⟩ + intro n _ y hy hq t ht σ hσ g hg + have hs := scalarS_pos_of_time (σ := σ) hj (ht0.trans_le ht.1) (empiricalLaw y) + have hcol : ∀ k,‖empiricalGramColumns y (scalarD j (empiricalLaw y,t,σ)) + (scalarS j (empiricalLaw y,t,σ)) k‖ ≤ V := by + intro k + convert empiricalGramColumns_norm (NeZero.pos n) y hs hK (by linarith : 0 ≤ R+1) + (empirical_column_coefficient hj ht0 ht y) (empirical_moment_vector_bound hR y hy) k using 1 + dsimp [V]; ring + exact (empiricalConditionalMiddle_norm j t σ y hV g hq hcol hg).trans (hbd _ hy t ht σ hσ) +end SKGap +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Matrix/ConditionalMiddleNorm.lean b/lean/OAI/Probability/SKGap/Matrix/ConditionalMiddleNorm.lean new file mode 100644 index 0000000000000000000000000000000000000000..3fa21b865d773615dd8c2bf8759b8685bbd9f012 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Matrix/ConditionalMiddleNorm.lean @@ -0,0 +1,117 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.DiagonalHessianJoined + +namespace OAI + +section +noncomputable section +namespace SKGap +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius +variable {ι : Type*} [Fintype ι] [DecidableEq ι] + +lemma real_opNorm_add (M N : Matrix ι ι ℝ) : opNorm (M+N) ≤ opNorm M+opNorm N := by + unfold opNorm + rw [map_add,map_add] + exact norm_add_le _ _ + +lemma real_opNorm_smul (c : ℝ) (M : Matrix ι ι ℝ) : opNorm (c • M)=|c| * opNorm M := by + unfold opNorm + rw [map_smul,map_smul,norm_smul,Real.norm_eq_abs] + +lemma operator_vecMulVec_le (u v : EuclideanSpace ℝ ι) : + opNorm (vecMulVec u.ofLp v.ofLp) ≤ ‖u‖*‖v‖ := by + apply (operator_le_frobenius _).trans + apply (sq_le_sq₀ (norm_nonneg _) (mul_nonneg (norm_nonneg _) (norm_nonneg _))).mp + rw [Matrix.frobenius_norm_def] + simp only [Real.rpow_two,← Real.sqrt_eq_rpow] + rw [Real.sq_sqrt (Finset.sum_nonneg (fun i _=>Finset.sum_nonneg (fun k _=>sq_nonneg _))), + mul_pow,EuclideanSpace.real_norm_sq_eq,EuclideanSpace.real_norm_sq_eq] + simp only [vecMulVec_apply,Real.norm_eq_abs,abs_mul,mul_pow,sq_abs] + rw [Finset.sum_mul] + apply le_of_eq + apply Finset.sum_congr rfl + intro i _ + rw [Finset.mul_sum] + +lemma operator_mulVec_norm_le (W : Matrix ι ι ℝ) (u : EuclideanSpace ℝ ι) : + ‖WithLp.toLp 2 (W*ᵥu.ofLp)‖ ≤ opNorm W*‖u‖ := by + exact W.toEuclideanLin.toContinuousLinearMap.le_opNorm u + +lemma goeBilinear_norm_bound (r : ℝ) (u : EuclideanSpace ℝ ι) + (g : MatrixCoordinates ι → ℝ) : + |goeBilinear r u.ofLp u.ofLp g| ≤ opNorm (goeMatrix r g)*‖u‖^2 := by + have hh := matrix_quadratic_op_bound (goeMatrix r g) u.ofLp + change |goeBilinear r u.ofLp u.ofLp g| ≤ opNorm (goeMatrix r g)*(u.ofLp⬝ᵥu.ofLp) at hh + convert hh using 1 + rw [EuclideanSpace.real_norm_sq_eq] + simp only [dotProduct,← sq] + +lemma conditionalBlockMatrix_norm {r j q s S a B κ ell : ℝ} + (u Z : EuclideanSpace ℝ ι) (g : MatrixCoordinates ι → ℝ) (hu : ‖u‖=1) : + opNorm (conditionalBlockMatrix r j q s S a B κ ell u.ofLp Z.ofLp g) ≤ + (1+2*|κ-1|+|ell-2*κ+1|)*opNorm (goeMatrix r g)+ + 2*(|j*sqrt (q/s)| * ‖Z‖+|j*a/s|)+|2*j*(a+B*q)/S| := by + let W := goeMatrix r g + let Wu : EuclideanSpace ℝ ι := WithLp.toLp 2 (W*ᵥu.ofLp) + let w : EuclideanSpace ℝ ι := (j*sqrt (q/s)) • Z-(j*a/s) • u + have hW : 0 ≤ opNorm W := norm_nonneg _ + have hwu : ‖Wu‖ ≤ opNorm W := by simpa only [hu,mul_one] using operator_mulVec_norm_le W u + have huu : opNorm (vecMulVec u.ofLp u.ofLp) ≤ 1 := by simpa only [hu,mul_one] using operator_vecMulVec_le u u + have h1 : opNorm (vecMulVec u.ofLp Wu.ofLp+vecMulVec Wu.ofLp u.ofLp) ≤ 2*opNorm W := by + apply (real_opNorm_add _ _).trans + have ha := operator_vecMulVec_le u Wu + have hb := operator_vecMulVec_le Wu u + rw [hu,one_mul] at ha + rw [hu,mul_one] at hb + linarith + have hα : |goeBilinear r u.ofLp u.ofLp g| ≤ opNorm W := by + simpa only [hu,one_pow,mul_one] using goeBilinear_norm_bound r u g + have hw : ‖w‖ ≤ |j*sqrt (q/s)| * ‖Z‖+|j*a/s| := by + apply (norm_sub_le _ _).trans + simp only [norm_smul,Real.norm_eq_abs,hu,mul_one] + rfl + have h2 : opNorm (vecMulVec u.ofLp w.ofLp+vecMulVec w.ofLp u.ofLp) ≤ + 2*(|j*sqrt (q/s)| * ‖Z‖+|j*a/s|) := by + apply (real_opNorm_add _ _).trans + have ha := operator_vecMulVec_le u w + have hb := operator_vecMulVec_le w u + rw [hu,one_mul] at ha + rw [hu,mul_one] at hb + linarith + have he : conditionalBlockMatrix r j q s S a B κ ell u.ofLp Z.ofLp g= + (W+(κ-1) • (vecMulVec u.ofLp Wu.ofLp+vecMulVec Wu.ofLp u.ofLp)+ + ((ell-2*κ+1)*goeBilinear r u.ofLp u.ofLp g) • vecMulVec u.ofLp u.ofLp)+ + (vecMulVec u.ofLp w.ofLp+vecMulVec w.ofLp u.ofLp)+ + (2*j*(a+B*q)/S) • vecMulVec u.ofLp u.ofLp := by + unfold conditionalBlockMatrix + rw [goeBlockResidual_expand] + dsimp [W,Wu,w] + abel + rw [he] + have hn := real_opNorm_add ((W+(κ-1) • (vecMulVec u.ofLp Wu.ofLp+vecMulVec Wu.ofLp u.ofLp)+ + ((ell-2*κ+1)*goeBilinear r u.ofLp u.ofLp g) • vecMulVec u.ofLp u.ofLp)+ + (vecMulVec u.ofLp w.ofLp+vecMulVec w.ofLp u.ofLp)) ((2*j*(a+B*q)/S) • vecMulVec u.ofLp u.ofLp) + apply hn.trans + have hd := real_opNorm_add (W+(κ-1) • (vecMulVec u.ofLp Wu.ofLp+vecMulVec Wu.ofLp u.ofLp)+ + ((ell-2*κ+1)*goeBilinear r u.ofLp u.ofLp g) • vecMulVec u.ofLp u.ofLp) + (vecMulVec u.ofLp w.ofLp+vecMulVec w.ofLp u.ofLp) + have hc := real_opNorm_add (W+(κ-1) • (vecMulVec u.ofLp Wu.ofLp+vecMulVec Wu.ofLp u.ofLp)) + (((ell-2*κ+1)*goeBilinear r u.ofLp u.ofLp g) • vecMulVec u.ofLp u.ofLp) + have hb := real_opNorm_add W ((κ-1) • (vecMulVec u.ofLp Wu.ofLp+vecMulVec Wu.ofLp u.ofLp)) + rw [real_opNorm_smul] at hb + rw [real_opNorm_smul,abs_mul] at hc + rw [real_opNorm_smul] + have hp1 := mul_le_mul_of_nonneg_left h1 (abs_nonneg (κ-1)) + have hp2 : |ell-2*κ+1| * |goeBilinear r u.ofLp u.ofLp g| * opNorm (vecMulVec u.ofLp u.ofLp) ≤ + |ell-2*κ+1| * opNorm W := by + apply (mul_le_mul_of_nonneg_left huu (by positivity)).trans + rw [mul_one] + exact mul_le_mul_of_nonneg_left hα (abs_nonneg _) + have hp3 := mul_le_mul_of_nonneg_left huu (abs_nonneg (2*j*(a+B*q)/S)) + nlinarith only [hd,hc,hb,hp1,hp2,hp3,h2] +end SKGap +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Matrix/CorrectionTrace.lean b/lean/OAI/Probability/SKGap/Matrix/CorrectionTrace.lean new file mode 100644 index 0000000000000000000000000000000000000000..ebbbad82f47bc6fd10fbaf31ab70d953d9ded101 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Matrix/CorrectionTrace.lean @@ -0,0 +1,114 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.Operation + +namespace OAI + +section + +noncomputable section +open scoped BigOperators Matrix.Norms.Frobenius +namespace SKGapCutoff.Recipe +open Primary Matrix SKGap.SourceError +variable {n : ℕ} + +lemma trace_frobenius (P E : Interaction n) : |trace (P*E)|≤‖P‖*‖E‖ := by + have H := double_cauchy (fun i k=>P k i) (fun i k=>E i k) + (norm_nonneg P) (norm_nonneg E) + (by rw [Finset.sum_comm]; exact le_of_eq (SKGap.frobenius_sq P).symm) + (le_of_eq (SKGap.frobenius_sq E).symm) + rw [Matrix.trace_mul_comm] + simpa only [trace,diag,Matrix.mul_apply,mul_comm] using H + +lemma trace_small_diagonal (P E : Interaction n) (u : Fin n→ℝ) : + |trace (P*(Matrix.diagonal u*E))|≤SKGap.opNorm P*vectorNorm u*‖E‖ := by + apply (trace_le_traceAbsolute P (Matrix.diagonal u*E)).trans + have H := double_cauchy (fun i k=>|P k i| *|u i|) (fun i k=>|E i k|) + (mul_nonneg (real_op_norm_nonneg P) (vectorNorm_nonneg u)) (norm_nonneg E) + (by simpa only [mul_pow,vectorNorm_sq] using small_column_square P u) + (by simpa only [sq_abs] using le_of_eq (SKGap.frobenius_sq E).symm) + have HH := (le_abs_self (∑i,∑k,(|P k i| * |u i|)*|E i k|)).trans H + simpa only [traceAbsolute,Matrix.diagonal_mul,abs_mul,mul_assoc] using HH + +lemma trace_small_mean (P E : Interaction n) (U : VectorFields n) (x : Spin n) (hn : 0a x*U x i) x-a x • derivativeMatrix U x + +lemma averageError_eq (a : Spin n→ℝ) (U : VectorFields n) (x : Spin n) : + averageError a U x=Matrix.of (fun i k=>U x i*halfDiff k a x)- + Matrix.of (fun i k=>2*spin x k*derivativeMatrix U x i k*halfDiff k a x) := by + ext i k + simp only [averageError,Matrix.sub_apply,Matrix.smul_apply,smul_eq_mul,Matrix.of_apply,derivativeMatrix] + rw [halfDiff_mul] + ring + +lemma trace_column_scaled (P D : Interaction n) (t : Fin n→ℝ) (x : Spin n) : + |trace (P*Matrix.of (fun i k=>2*spin x k*D i k*t k))|≤ + 2*‖D‖*(SKGap.opNorm P*vectorNorm t) := by + apply (trace_le_traceAbsolute P _).trans + have H:=parameter_product_trace_bound P D t (norm_nonneg D) (vectorNorm_nonneg t) + (le_of_eq (SKGap.frobenius_sq D).symm) (le_of_eq (vectorNorm_sq t).symm) + have he : traceAbsolute P (Matrix.of (fun i k=>2*spin x k*D i k*t k))= + 2*(∑i,∑k,|P k i| *|D i k| *|t k|) := by + simp only [traceAbsolute,Matrix.of_apply,abs_mul,abs_spin_eq_one,mul_one, + abs_of_pos (by norm_num : (0:ℝ)<2),Finset.mul_sum] + apply Finset.sum_congr rfl; intro i _ + apply Finset.sum_congr rfl; intro k _; ring + rw [he] + exact (mul_le_mul_of_nonneg_left H (by norm_num)).trans_eq (by ring) + +lemma averageError_trace (P : Interaction n) (a : Spin n→ℝ) (U : VectorFields n) (x : Spin n) : + |trace (P*averageError a U x)|≤ + SKGap.opNorm P*(vectorNorm (U x)+2*‖derivativeMatrix U x‖)*‖derivativeVector a x‖ := by + rw [averageError_eq,mul_sub,trace_sub] + have h₁:=rank_one_trace_bound P (WithLp.toLp 2 (U x)) (derivativeVector a x) + have h₂:=trace_column_scaled P (derivativeMatrix U x) (fun k=>halfDiff k a x) x + apply ((abs_sub _ _).trans (add_le_add h₁ h₂)).trans_eq + change SKGap.opNorm P*vectorNorm (U x)*‖derivativeVector a x‖+ + 2*‖derivativeMatrix U x‖*(SKGap.opNorm P*‖derivativeVector a x‖)=_ + ring + +lemma primary_averageError_trace (P : Interaction n) (U m : VectorFields n) (x : Spin n) (hn : 0by nlinarith [hm i,sq_abs (m x i),abs_nonneg (m x i)] + _ = _ := by simp + have hdm2 : ‖derivativeMatrix m x‖^2≤(n:ℝ)*R^2 := by + rw [SKGap.frobenius_sq] + calc + _ ≤ ∑_i:Fin n,R^2 := Finset.sum_le_sum fun i _=> + (matrix_row_square_le _ i).trans (pow_le_pow_left₀ (real_op_norm_nonneg _) hdm 2) + _ = _ := by simp + have h₁ : vectorNorm (m x)*‖derivativeVector (siteMean U) x‖≤C := by + apply nonneg_le_nonneg_of_sq_le_sq hC + simp only [←sq,mul_pow] + exact (mul_le_mul_of_nonneg_right hm2 (sq_nonneg _)).trans hd + have h₂ : ‖derivativeMatrix m x‖*‖derivativeVector (siteMean U) x‖≤C*R := by + apply nonneg_le_nonneg_of_sq_le_sq (mul_nonneg hC hR) + simp only [←sq,mul_pow] + have H := (mul_le_mul_of_nonneg_right hdm2 (sq_nonneg ‖derivativeVector (siteMean U) x‖)).trans + (show (n:ℝ)*R^2*‖derivativeVector (siteMean U) x‖^2≤C^2*R^2 by + nlinarith [mul_le_mul_of_nonneg_right hd (sq_nonneg R)]) + exact H + apply (averageError_trace P (siteMean U) m x).trans + have H := mul_le_mul_of_nonneg_left (add_le_add h₁ (mul_le_mul_of_nonneg_left h₂ (by norm_num : (0:ℝ)≤2))) + (real_op_norm_nonneg P) + nlinarith only [H] + +end SKGapCutoff.Recipe + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Matrix/DiscreteMatrixCalculus.lean b/lean/OAI/Probability/SKGap/Matrix/DiscreteMatrixCalculus.lean new file mode 100644 index 0000000000000000000000000000000000000000..230d7f12d561e981eb3769789e90b943a6aca09b --- /dev/null +++ b/lean/OAI/Probability/SKGap/Matrix/DiscreteMatrixCalculus.lean @@ -0,0 +1,341 @@ +import Mathlib +import OAI.Probability.SKGap.Matrix.OpNormDiagonal +import OAI.Probability.SKGap.Matrix.MatrixSeminorm +import OAI.Probability.SKGap.Gaussian.SquaredGaussianFourth +import OAI.Probability.SKGap.Localization.PreparationGrowth + +namespace OAI + +section + +noncomputable section +open scoped BigOperators Matrix.Norms.Frobenius +namespace SKGapCutoff.Primary +open SKGap Matrix +variable {n : ℕ} +local instance : Fact (1≤(4:ENNReal)) := ⟨by norm_num⟩ + +def derivativeMatrix (F : VectorFields n) (x : Spin n) : Interaction n := + fun i k => halfDiff k (fun y => F y i) x + +def ShapeBound (M : Interaction n) (C : ℝ) : Prop := + SKGap.opNorm M ≤ C ∧ SKGap.diagonalSeminorm M ≤ C ∧ SKGap.offDiagonalSeminorm M ≤ C + +lemma opNorm_eq (M : Interaction n) : + SKGap.opNorm M = ‖Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) M‖ := rfl + +lemma opNorm_le_frobenius (M : Interaction n) : SKGap.opNorm M ≤ ‖M‖ := by + apply nonneg_le_nonneg_of_sq_le_sq (norm_nonneg M) + simp only [← sq] + rw [SKGap.frobenius_sq,opNorm_eq] + exact RandomMatrix.matrix_opNorm_sq_le_frobenius M + +lemma opNorm_add (M N : Interaction n) : SKGap.opNorm (M+N) ≤ SKGap.opNorm M+SKGap.opNorm N := by + simp only [opNorm_eq,map_add] + exact norm_add_le _ _ + +lemma opNorm_smul (c : ℝ) (M : Interaction n) : SKGap.opNorm (c • M) = |c| * SKGap.opNorm M := by + simp only [opNorm_eq,map_smul,norm_smul,Real.norm_eq_abs] + +lemma ShapeBound.mono {M : Interaction n} {C D : ℝ} (h : ShapeBound M C) (hCD : C≤D) : + ShapeBound M D := ⟨h.1.trans hCD,h.2.1.trans hCD,h.2.2.trans hCD⟩ + +lemma ShapeBound.add {M N : Interaction n} {C D : ℝ} + (hM : ShapeBound M C) (hN : ShapeBound N D) : ShapeBound (M+N) (C+D) := by + exact ⟨(opNorm_add M N).trans (add_le_add hM.1 hN.1), + (SKGap.diagonalSeminorm_add M N).trans (add_le_add hM.2.1 hN.2.1), + (SKGap.offDiagonalSeminorm_add M N).trans (add_le_add hM.2.2 hN.2.2)⟩ + +lemma shapeBound_of_frobenius {M : Interaction n} {C : ℝ} (h : ‖M‖≤C) : ShapeBound M C := + ⟨(opNorm_le_frobenius M).trans h,(SKGap.diagonalSeminorm_le M).trans h, + (SKGap.offDiagonalSeminorm_le M).trans h⟩ + +lemma ShapeBound.perturb {M H : Interaction n} {C E : ℝ} + (hH : ShapeBound H C) (hE : ‖M-H‖≤E) : ShapeBound M (C+E) := by + simpa only [add_sub_cancel] using hH.add (shapeBound_of_frobenius hE) + +lemma fourth_sum (M : Interaction n) : + (∑ i,∑ k,(M i k)^4) = (∑ i,(M i i)^4)+SKGap.offDiagonalSeminorm M^4 := by + rw [SKGap.offDiagonalSeminorm_fourth,Fintype.sum_prod_type,← Finset.sum_add_distrib] + apply Finset.sum_congr rfl + intro i _ + have hs : (M i i)^4 = ∑ k : Fin n, if i=k then (M i k)^4 else 0 := by simp + rw [hs,← Finset.sum_add_distrib] + apply Finset.sum_congr rfl + intro k _ + by_cases h : i=k <;> simp [h] + +lemma fourth_sum_le {M : Interaction n} {C : ℝ} (hC : 0≤C) (hM : ShapeBound M C) : + (∑ i,∑ k,(M i k)^4) ≤ 2*C^4 := by + rw [fourth_sum] + have hd : (∑ i,(M i i)^4) ≤ SKGap.diagonalSeminorm M^4 := by + rw [show (4:ℕ)=2*2 by rfl,pow_mul,SKGap.diagonalSeminorm_sq] + simpa only [pow_mul] using + (Finset.sum_sq_le_sq_sum_of_nonneg (s:=Finset.univ) (f:=fun i => (M i i)^2) + (fun i _ => sq_nonneg _)) + have hdC := (pow_le_pow_iff_left₀ (norm_nonneg (SKGap.diagonalVector M)) hC + (by decide : 4 ≠ 0)).2 hM.2.1 + have hoC := pow_le_pow_left₀ (norm_nonneg (SKGap.offDiagonalVector M)) hM.2.2 4 + dsimp only [SKGap.diagonalSeminorm,SKGap.offDiagonalSeminorm] at hd ⊢ + nlinarith + +lemma quadratic_entry_error {D R : Interaction n} {C A : ℝ} (hC : 0≤C) (hA : 0≤A) + (hD : ShapeBound D C) (he : ∀ i k, |R i k|≤A*(D i k)^2) : + ‖R‖ ≤ 2*A*C^2 := by + have hs : ‖R‖^2 ≤ A^2*(2*C^4) := by + rw [SKGap.frobenius_sq] + calc + _ ≤ ∑ i,∑ k,A^2*(D i k)^4 := by + apply Finset.sum_le_sum + intro i _ + apply Finset.sum_le_sum + intro k _ + have h := pow_le_pow_left₀ (abs_nonneg (R i k)) (he i k) 2 + nlinarith only [h,sq_abs (R i k)] + _ = A^2*(∑ i,∑ k,(D i k)^4) := by simp_rw [← Finset.mul_sum] + _ ≤ A^2*(2*C^4) := mul_le_mul_of_nonneg_left (fourth_sum_le hC hD) (sq_nonneg _) + have hp : 0≤2*A*C^2 := by positivity + nlinarith [sq_nonneg (A*C^2)] + +lemma diagonal_mul_shape {M : Interaction n} {C : ℝ} {a : Fin n→ℝ} + (ha : ∀ i,|a i|≤1) (hM : ShapeBound M C) : + ShapeBound (Matrix.diagonal a*M) C := by + have haN : SKGap.opNorm (Matrix.diagonal a)≤1 := SKGap.opNorm_diagonal_le (by norm_num) ha + refine ⟨(SKGap.opNorm_mul _ _).trans ?_,?_,?_⟩ + · calc + _ ≤ 1*SKGap.opNorm M := mul_le_mul_of_nonneg_right haN (norm_nonneg _) + _ = SKGap.opNorm M := one_mul _ + _ ≤ C := hM.1 + · apply le_trans ?_ hM.2.1 + apply le_of_pow_le_pow_left₀ (by decide : 2≠0) (norm_nonneg _) + change SKGap.diagonalSeminorm _ ^2 ≤ SKGap.diagonalSeminorm M ^2 + simp only [SKGap.diagonalSeminorm_sq,Matrix.diagonal_mul] + apply Finset.sum_le_sum + intro i _ + have hi := pow_le_pow_left₀ (abs_nonneg (a i)) (ha i) 2 + simp only [sq_abs,one_pow] at hi + simpa only [mul_pow,one_mul] using mul_le_mul_of_nonneg_right hi (sq_nonneg (M i i)) + · apply le_trans ?_ hM.2.2 + apply le_of_pow_le_pow_left₀ (by decide : 4≠0) (norm_nonneg _) + change SKGap.offDiagonalSeminorm _ ^4 ≤ SKGap.offDiagonalSeminorm M ^4 + simp only [SKGap.offDiagonalSeminorm_fourth] + apply Finset.sum_le_sum + intro p _ + split_ifs + · exact le_rfl + · simp only [Matrix.diagonal_mul,mul_pow] + have hi := pow_le_pow_left₀ (abs_nonneg (a p.1)) (ha p.1) 4 + rw [← abs_pow,abs_of_nonneg (by positivity : 0≤a p.1^4)] at hi + simpa only [one_pow,one_mul] using mul_le_mul_of_nonneg_right hi + (by positivity : 0≤(M p.1 p.2)^4) + +lemma tanh_derivative_error {F : VectorFields n} {x : Spin n} {C : ℝ} + (hC : 0≤C) (hD : ShapeBound (derivativeMatrix F x) C) : + ‖derivativeMatrix (fun y i => Real.tanh (F y i)) x- + Matrix.diagonal (fun i => scalarVariance (F x i))*derivativeMatrix F x‖ ≤ 8*C^2 := by + convert quadratic_entry_error hC (by norm_num : (0:ℝ)≤4) hD ?_ using 1 <;> try norm_num + intro i k + simpa only [derivativeMatrix,Matrix.sub_apply,Matrix.diagonal_mul,mul_comm, + refreshInfluence] using refreshInfluence_error_le F x k i + +lemma tanh_derivative_shape {F : VectorFields n} {x : Spin n} {C : ℝ} + (hC : 0≤C) (hD : ShapeBound (derivativeMatrix F x) C) : + ShapeBound (derivativeMatrix (fun y i => Real.tanh (F y i)) x) (C+8*C^2) := by + apply ShapeBound.perturb _ (tanh_derivative_error hC hD) + apply diagonal_mul_shape ?_ hD + intro i + rw [abs_of_pos (scalarVariance_pos _)] + exact scalarVariance_le_one _ + +def derivativeVector (f : Spin n→ℝ) (x : Spin n) : EuclideanSpace ℝ (Fin n) := + WithLp.toLp 2 (fun k => halfDiff k f x) + +def siteMean (F : VectorFields n) (x : Spin n) : ℝ := (∑ i,F x i)/(n:ℝ) + +lemma siteMean_derivative (F : VectorFields n) (x : Spin n) : + derivativeVector (siteMean F) x = (n:ℝ)⁻¹ • + (Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) ((derivativeMatrix F x)ᵀ)) + (WithLp.toLp 2 (fun _ => 1)) := by + ext k + change halfDiff k (siteMean F) x = (n:ℝ)⁻¹*(∑ i,halfDiff k (fun y => F y i) x*1) + simp only [mul_one,halfDiff,siteMean] + rw [← Finset.sum_div,Finset.sum_sub_distrib] + ring + +lemma euclidean_ones_norm_sq : + ‖(WithLp.toLp 2 (fun _ : Fin n => (1:ℝ)) : EuclideanSpace ℝ (Fin n))‖^2 = n := by + simp [EuclideanSpace.real_norm_sq_eq] + +lemma siteMean_derivative_square (F : VectorFields n) (x : Spin n) (hn : 0 (1:ℝ))) + change ‖(Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) ((derivativeMatrix F x)ᵀ)) + (WithLp.toLp 2 (fun _ : Fin n => (1:ℝ)))‖ ≤ + SKGap.opNorm ((derivativeMatrix F x)ᵀ) * ‖(WithLp.toLp 2 (fun _ : Fin n => (1:ℝ)) : EuclideanSpace ℝ (Fin n))‖ at h + rw [SKGap.opNorm_transpose] at h + have hs := pow_le_pow_left₀ (norm_nonneg _) h 2 + rw [mul_pow,euclidean_ones_norm_sq] at hs + rw [siteMean_derivative,norm_smul,Real.norm_eq_abs,abs_inv,abs_of_pos hnR,mul_pow] + field_simp + nlinarith + +lemma siteMean_derivative_square_bound {F : VectorFields n} {x : Spin n} {B : ℝ} + (hn : 0 v i*halfDiff k f x)‖≤B := by + apply nonneg_le_nonneg_of_sq_le_sq hB + simp only [← sq] + rw [SKGap.frobenius_sq] + calc + _ ≤ ∑ _i : Fin n,∑ k,(halfDiff k f x)^2 := by + apply Finset.sum_le_sum + intro i _ + apply Finset.sum_le_sum + intro k _ + have hi := pow_le_pow_left₀ (abs_nonneg (v i)) (hv i) 2 + simp only [sq_abs,one_pow] at hi + change (v i*halfDiff k f x)^2 ≤ _ + rw [mul_pow] + nlinarith [sq_nonneg (halfDiff k f x)] + _ = (n:ℝ)*‖derivativeVector f x‖^2 := by + simp only [Finset.sum_const,Finset.card_univ,Fintype.card_fin,nsmul_eq_mul, + EuclideanSpace.real_norm_sq_eq,derivativeVector] + _ ≤ B^2 := h + +lemma spin_diagonal_frobenius (f : Spin n→ℝ) (x : Spin n) : + ‖Matrix.diagonal (fun k => spin x k*halfDiff k f x)‖ = ‖derivativeVector f x‖ := by + apply (sq_eq_sq₀ (norm_nonneg _) (norm_nonneg _)).mp + rw [SKGap.frobenius_sq,EuclideanSpace.real_norm_sq_eq] + simp [Matrix.diagonal_apply,derivativeVector,mul_pow,spin_sq] + +lemma derivativeMatrix_product (f : Spin n→ℝ) (F : VectorFields n) (x : Spin n) : + derivativeMatrix (fun y i => f y*F y i) x = f x • derivativeMatrix F x + + Matrix.of (fun i k => F x i*halfDiff k f x) - + (2:ℝ) • (derivativeMatrix F x*Matrix.diagonal (fun k => spin x k*halfDiff k f x)) := by + ext i k + simp only [derivativeMatrix,Matrix.sub_apply,Matrix.add_apply,Matrix.smul_apply, + smul_eq_mul,Matrix.mul_diagonal,halfDiff_mul,Matrix.of_apply] + ring + +lemma product_derivative_error {f : Spin n→ℝ} {F : VectorFields n} {x : Spin n} {B C : ℝ} + (hn : 0 f y*F y i) x-f x • derivativeMatrix F x‖ ≤ B+2*C*B := by + have hdb := derivative_norm_of_mean_square hn hB hf + have hC0 : 0≤C := (norm_nonneg _).trans hC + rw [derivativeMatrix_product] + have he (A R T : Interaction n) : A+R-T-A=R-T := by abel + rw [he] + calc + _ ≤ ‖Matrix.of (fun i k => F x i*halfDiff k f x)‖+ + ‖(2:ℝ) • (derivativeMatrix F x*Matrix.diagonal (fun k => spin x k*halfDiff k f x))‖ := norm_sub_le _ _ + _ ≤ B+2*C*B := by + apply add_le_add (outer_frobenius_bound hF hB hf) + rw [norm_smul,Real.norm_eq_abs,abs_of_pos (by norm_num : (0:ℝ)<2)] + calc + _ ≤ 2*(SKGap.opNorm (derivativeMatrix F x)*‖Matrix.diagonal (fun k => spin x k*halfDiff k f x)‖) := + mul_le_mul_of_nonneg_left (SKGap.frobenius_mul_le_opNorm _ _) (by norm_num) + _ ≤ 2*(C*B) := by + rw [spin_diagonal_frobenius] + exact mul_le_mul_of_nonneg_left (mul_le_mul hC hdb (norm_nonneg _) hC0) (by norm_num) + _ = _ := by ring + +lemma derivativeMatrix_linear (J : Interaction n) (F : VectorFields n) (h : Fin n→ℝ) + (x : Spin n) : + derivativeMatrix (fun y i => h i+∑ k,J i k*F y k) x = J*derivativeMatrix F x := by + ext i l + simp only [derivativeMatrix,Matrix.mul_apply,halfDiff] + simp_rw [← mul_div_assoc,mul_sub] + rw [← Finset.sum_div,Finset.sum_sub_distrib] + ring + +lemma derivativeMatrix_sub (F G : VectorFields n) (x : Spin n) : + derivativeMatrix (fun y i => F y i-G y i) x=derivativeMatrix F x-derivativeMatrix G x := by + ext i k + exact halfDiff_sub k (fun y => F y i) (fun y => G y i) x + +lemma derivativeMatrix_smul (c : ℝ) (F : VectorFields n) (x : Spin n) : + derivativeMatrix (fun y i => c*F y i) x=c • derivativeMatrix F x := by + ext i k + simp only [derivativeMatrix,halfDiff,Matrix.smul_apply,smul_eq_mul] + ring + +lemma derivativeMatrix_spin (x : Spin n) : derivativeMatrix spin x=1 := by + ext i k + simp [derivativeMatrix,Matrix.one_apply,eq_comm] + +lemma variance_derivative_error {F : VectorFields n} {x : Spin n} {C : ℝ} + (hC : 0≤C) (hD : ShapeBound (derivativeMatrix F x) C) : + ‖derivativeMatrix (fun y i => 1-(F y i)^2) x- + (-2:ℝ) • (Matrix.diagonal (F x)*derivativeMatrix F x)‖ ≤ 4*C^2 := by + convert quadratic_entry_error hC (by norm_num : (0:ℝ)≤2) hD ?_ using 1 <;> try norm_num + intro i k + have hs : halfDiff k (fun y => 1-(F y i)^2) x = + -2*F x i*halfDiff k (fun y => F y i) x+ + 2*spin x k*(halfDiff k (fun y => F y i) x)^2 := by + have hh := halfDiff_mul k (fun y => F y i) (fun y => F y i) x + rw [halfDiff_sub,halfDiff_const] + simpa only [pow_two,zero_sub] using (show -(halfDiff k (fun y => F y i*F y i) x) = + -2*F x i*halfDiff k (fun y => F y i) x+ + 2*spin x k*(halfDiff k (fun y => F y i) x)^2 by rw [hh]; ring) + simp only [derivativeMatrix,hs] + have he (a b c : ℝ) : -2*a*b+2*c*b^2+2*(a*b)=2*c*b^2 := by ring + rw [he,abs_mul,abs_mul,abs_spin_eq_one,mul_one] + norm_num [abs_of_nonneg (sq_nonneg (halfDiff k (fun y => F y i) x))] + +lemma variance_derivative_opNorm {F : VectorFields n} {x : Spin n} {C : ℝ} + (hC : 0≤C) (hF : ∀ i,|F x i|≤1) (hD : ShapeBound (derivativeMatrix F x) C) : + SKGap.opNorm (derivativeMatrix (fun y i => 1-(F y i)^2) x) ≤ 2*C+4*C^2 := by + let A := (-2:ℝ) • (Matrix.diagonal (F x)*derivativeMatrix F x) + have hA : SKGap.opNorm A≤2*C := by + dsimp only [A] + rw [opNorm_smul] + norm_num only [abs_neg,abs_of_nonneg (by norm_num : (0:ℝ)≤2)] + exact mul_le_mul_of_nonneg_left (diagonal_mul_shape hF hD).1 (by norm_num) + have hE := (opNorm_le_frobenius + (derivativeMatrix (fun y i => 1-(F y i)^2) x-A)).trans (variance_derivative_error hC hD) + have he : derivativeMatrix (fun y i => 1-(F y i)^2) x = + A+(derivativeMatrix (fun y i => 1-(F y i)^2) x-A) := by abel + rw [he] + exact (opNorm_add _ _).trans (add_le_add hA hE) + +lemma tanh_derivative_formal_error {F : VectorFields n} {x : Spin n} + {H : Interaction n} {C E : ℝ} (hC : 0≤C) (hD : ShapeBound (derivativeMatrix F x) C) + (hE : ‖derivativeMatrix F x-H‖≤E) : + ‖derivativeMatrix (fun y i => Real.tanh (F y i)) x- + Matrix.diagonal (fun i => scalarVariance (F x i))*H‖ ≤ 8*C^2+E := by + let V := Matrix.diagonal (fun i => scalarVariance (F x i)) + have hV : SKGap.opNorm V≤1 := by + apply SKGap.opNorm_diagonal_le (by norm_num) + intro i + rw [abs_of_pos (scalarVariance_pos _)] + exact scalarVariance_le_one _ + have he : derivativeMatrix (fun y i => Real.tanh (F y i)) x-V*H = + (derivativeMatrix (fun y i => Real.tanh (F y i)) x-V*derivativeMatrix F x)+ + V*(derivativeMatrix F x-H) := by noncomm_ring + change ‖derivativeMatrix (fun y i => Real.tanh (F y i)) x-V*H‖≤_ + rw [he] + apply (norm_add_le _ _).trans + apply add_le_add (tanh_derivative_error hC hD) + exact (SKGap.frobenius_mul_le_opNorm _ _).trans + ((mul_le_mul_of_nonneg_right hV (norm_nonneg _)).trans (by simpa using hE)) + +end SKGapCutoff.Primary +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Matrix/DoublePlantLogNorm.lean b/lean/OAI/Probability/SKGap/Matrix/DoublePlantLogNorm.lean new file mode 100644 index 0000000000000000000000000000000000000000..f6e67a27bb5159404111387203294346ca23c041 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Matrix/DoublePlantLogNorm.lean @@ -0,0 +1,281 @@ +import Mathlib +import OAI.Probability.SKGap.Terminal.SingleSpinPlantedLaw +import OAI.Probability.SKGap.Gaussian.ReplicaTailWeight + +namespace OAI + +section +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open scoped BigOperators +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open scoped BigOperators +open scoped BigOperators NNReal ENNReal +open MeasureTheory Metric Set +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators NNReal ENNReal Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Set +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators ENNReal NNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Matrix +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators ENNReal NNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal +open scoped BigOperators +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise NNReal ENNReal +open scoped BigOperators +open Filter Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal Topology +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +namespace SKGapCutoff + +noncomputable def doublePlantLogNorm (β : ℝ) {n : ℕ} (x y : Spin n) : ℝ := + β^2*((n:ℝ)-2)/2 + β^2*replicaOverlap x y^2/(2*n) + +noncomputable def doubleSpinPlantedLaw (β : ℝ) {n : ℕ} (x y : Spin n) : + Measure (GaussianCoordinates n) := + (disorderLaw β n).withDensity (fun g => ENNReal.ofReal + (Real.exp (energy (sampledInteraction g) x + energy (sampledInteraction g) y - + doublePlantLogNorm β x y))) + +lemma doubleSpinPlantedLaw_eq_gaussianPi (β : ℝ) {n : ℕ} (hn : 0 < n) + (x y : Spin n) : + doubleSpinPlantedLaw β x y = Measure.pi (fun p : Fin n × Fin n => + gaussianReal (β^2/n * (upperCoefficient x p + upperCoefficient y p)) + (Real.toNNReal (β^2/n))) := by + unfold doubleSpinPlantedLaw disorderLaw + have hv : (Real.toNNReal (β^2/(n:ℝ)) : ℝ) = β^2/n := + Real.coe_toNNReal _ (div_nonneg (sq_nonneg _) (Nat.cast_nonneg _)) + have hnR : (n:ℝ) ≠ 0 := by exact_mod_cast (Nat.ne_of_gt hn) + have hc : (Real.toNNReal (β^2/(n:ℝ)) : ℝ) * + (∑ p, (upperCoefficient x p + upperCoefficient y p)^2)/2 = + doublePlantLogNorm β x y := by + rw [hv, sum_upperCoefficient_add_sq] + unfold doublePlantLogNorm + field_simp + simp_rw [combined_energy_sampled, ← hc] + rw [gaussianPi_exponential_tilt] + simp only [hv] + +lemma doubleSpinPlantedLaw_probability (β : ℝ) {n : ℕ} (hn : 0 < n) + (x y : Spin n) : IsProbabilityMeasure (doubleSpinPlantedLaw β x y) := by + rw [doubleSpinPlantedLaw_eq_gaussianPi β hn] + infer_instance + +noncomputable def doublePlantNorm (β : ℝ) (n : ℕ) : ℝ := + ∫ g, partition (sampledInteraction g)^2 ∂disorderLaw β n + +lemma doublePlantNorm_eq_sum (β : ℝ) {n : ℕ} (hn : 0 < n) : + doublePlantNorm β n = ∑ x : Spin n, ∑ y : Spin n, + Real.exp (doublePlantLogNorm β x y) := by + rw [doublePlantNorm, integral_partition_sq_sampled β hn] + simp only [doublePlantLogNorm, Real.exp_add, Finset.mul_sum] + +lemma doublePlantNorm_pos (β : ℝ) {n : ℕ} (hn : 0 < n) : + 0 < doublePlantNorm β n := by + rw [doublePlantNorm_eq_sum β hn] + exact Finset.sum_pos (fun x _ => Finset.sum_pos (fun y _ => Real.exp_pos _) + Finset.univ_nonempty) Finset.univ_nonempty + +noncomputable def doublePlantWeight (β : ℝ) {n : ℕ} (x y : Spin n) : ℝ := + Real.exp (doublePlantLogNorm β x y) / doublePlantNorm β n + +lemma doublePlantWeight_pos (β : ℝ) {n : ℕ} (hn : 0 < n) (x y : Spin n) : + 0 < doublePlantWeight β x y := + div_pos (Real.exp_pos _) (doublePlantNorm_pos β hn) + +lemma doublePlantWeight_sum (β : ℝ) {n : ℕ} (hn : 0 < n) : + ∑ x : Spin n, ∑ y : Spin n, doublePlantWeight β x y = 1 := by + simp only [doublePlantWeight, ← Finset.sum_div] + rw [← doublePlantNorm_eq_sum β hn, div_self (doublePlantNorm_pos β hn).ne'] + +noncomputable def doublePlantedDisorderLaw (β : ℝ) (n : ℕ) : + Measure (GaussianCoordinates n) := + (disorderLaw β n).withDensity (fun g => ENNReal.ofReal + (partition (sampledInteraction g)^2/doublePlantNorm β n)) + +lemma doublePlantedDisorderLaw_probability (β : ℝ) {n : ℕ} (hn : 0 < n) : + IsProbabilityMeasure (doublePlantedDisorderLaw β n) := by + constructor + rw [doublePlantedDisorderLaw, withDensity_apply _ MeasurableSet.univ, + Measure.restrict_univ] + rw [← ofReal_integral_eq_lintegral_ofReal + ((integrable_partition_sq_sampled β n).div_const _) + (Eventually.of_forall (fun g => div_nonneg (sq_nonneg _) (doublePlantNorm_pos β hn).le))] + rw [integral_div] + change ENNReal.ofReal (doublePlantNorm β n / doublePlantNorm β n) = 1 + rw [div_self (doublePlantNorm_pos β hn).ne', ENNReal.ofReal_one] + +noncomputable def doubleGibbsLExpectation {n : ℕ} + (q : GaussianCoordinates n → Spin n → Spin n → ℝ≥0∞) + (g : GaussianCoordinates n) : ℝ≥0∞ := + ∑ x, ∑ y, ENNReal.ofReal (gibbs (sampledInteraction g) x) * + ENNReal.ofReal (gibbs (sampledInteraction g) y) * q g x y + +lemma measurable_doubleGibbsLExpectation {n : ℕ} + (q : GaussianCoordinates n → Spin n → Spin n → ℝ≥0∞) + (hq : ∀ x y, Measurable (fun g => q g x y)) : + Measurable (doubleGibbsLExpectation q) := by + unfold doubleGibbsLExpectation + exact Finset.measurable_sum _ (fun x _ => Finset.measurable_sum _ (fun y _ => + ((((continuous_gibbs x).comp (continuous_sampledInteraction n)).measurable.ennreal_ofReal).mul + (((continuous_gibbs y).comp (continuous_sampledInteraction n)).measurable.ennreal_ofReal)).mul + (hq x y))) + +lemma double_planted_gibbs_density (β : ℝ) {n : ℕ} (hn : 0 < n) + (g : GaussianCoordinates n) (x y : Spin n) : + (partition (sampledInteraction g)^2/doublePlantNorm β n) * + gibbs (sampledInteraction g) x * gibbs (sampledInteraction g) y = + doublePlantWeight β x y * Real.exp (energy (sampledInteraction g) x + + energy (sampledInteraction g) y - doublePlantLogNorm β x y) := by + unfold gibbs doublePlantWeight + rw [Real.exp_sub, Real.exp_add] + field_simp [(partition_pos (sampledInteraction g)).ne', (doublePlantNorm_pos β hn).ne'] + +lemma double_planted_gibbs_lintegral (β : ℝ) {n : ℕ} (hn : 0 < n) + (q : GaussianCoordinates n → Spin n → Spin n → ℝ≥0∞) + (hq : ∀ x y, Measurable (fun g => q g x y)) : + (∫⁻ g, doubleGibbsLExpectation q g ∂doublePlantedDisorderLaw β n) = + ∑ x : Spin n, ∑ y : Spin n, ENNReal.ofReal (doublePlantWeight β x y) * + ∫⁻ g, q g x y ∂doubleSpinPlantedLaw β x y := by + have hZ := (continuous_partition n).comp (continuous_sampledInteraction n) + have hr : Measurable (fun g : GaussianCoordinates n => ENNReal.ofReal + (partition (sampledInteraction g)^2/doublePlantNorm β n)) := + ((hZ.measurable.pow_const 2).div_const _).ennreal_ofReal + have hE (x y : Spin n) : Measurable (fun g : GaussianCoordinates n => + ENNReal.ofReal (Real.exp (energy (sampledInteraction g) x + + energy (sampledInteraction g) y - doublePlantLogNorm β x y))) := by + exact (((((continuous_energy x).comp (continuous_sampledInteraction n)).measurable.add + (((continuous_energy y).comp (continuous_sampledInteraction n)).measurable)).sub_const _).exp).ennreal_ofReal + rw [doublePlantedDisorderLaw, lintegral_withDensity_eq_lintegral_mul _ hr + (measurable_doubleGibbsLExpectation q hq)] + have hp (g : GaussianCoordinates n) (x y : Spin n) : + ENNReal.ofReal (partition (sampledInteraction g)^2/doublePlantNorm β n) * + ENNReal.ofReal (gibbs (sampledInteraction g) x) * + ENNReal.ofReal (gibbs (sampledInteraction g) y) = + ENNReal.ofReal (doublePlantWeight β x y) * ENNReal.ofReal (Real.exp + (energy (sampledInteraction g) x + energy (sampledInteraction g) y - + doublePlantLogNorm β x y)) := by + rw [← ENNReal.ofReal_mul (div_nonneg (sq_nonneg _) (doublePlantNorm_pos β hn).le), + ← ENNReal.ofReal_mul (mul_nonneg (div_nonneg (sq_nonneg _) (doublePlantNorm_pos β hn).le) + (gibbs_pos _ _).le), double_planted_gibbs_density β hn, + ENNReal.ofReal_mul (doublePlantWeight_pos β hn x y).le] + change (∫⁻ g, ENNReal.ofReal (partition (sampledInteraction g)^2/doublePlantNorm β n) * + (∑ x, ∑ y, ENNReal.ofReal (gibbs (sampledInteraction g) x) * + ENNReal.ofReal (gibbs (sampledInteraction g) y) * q g x y) ∂disorderLaw β n) = _ + simp only [Finset.mul_sum, ← mul_assoc] + simp_rw [hp, mul_assoc] + have hterm (x y : Spin n) : Measurable (fun g : GaussianCoordinates n => + ENNReal.ofReal (doublePlantWeight β x y) * + (ENNReal.ofReal (Real.exp (energy (sampledInteraction g) x + + energy (sampledInteraction g) y - doublePlantLogNorm β x y)) * q g x y)) := + measurable_const.mul ((hE x y).mul (hq x y)) + rw [lintegral_finsetSum Finset.univ (fun x _ => + Finset.measurable_sum _ (fun y _ => hterm x y))] + apply Finset.sum_congr rfl + intro x _ + rw [lintegral_finsetSum Finset.univ (fun y _ => hterm x y)] + apply Finset.sum_congr rfl + intro y _ + have hf : Measurable (fun g : GaussianCoordinates n => + ENNReal.ofReal (Real.exp (energy (sampledInteraction g) x + + energy (sampledInteraction g) y - doublePlantLogNorm β x y)) * q g x y) := + (hE x y).mul (hq x y) + rw [lintegral_const_mul _ hf, doubleSpinPlantedLaw, + lintegral_withDensity_eq_lintegral_mul _ (hE x y) (hq x y)] + rfl + +lemma doublePlantWeight_eq_overlap_tilt (β : ℝ) {n : ℕ} (hn : 0 < n) (x y : Spin n) : + doublePlantWeight β x y = Real.exp (β^2*replicaOverlap x y^2/(2*n)) / + (∑ u : Spin n, ∑ v : Spin n, Real.exp (β^2*replicaOverlap u v^2/(2*n))) := by + unfold doublePlantWeight doublePlantLogNorm doublePlantNorm + rw [integral_partition_sq_sampled β hn, Real.exp_add, + mul_div_mul_left _ _ (Real.exp_ne_zero _)] + +lemma doublePlantWeight_overlap_tail (β q ε : ℝ) (hβq : β^2 < q) (hq : q < 1) + (hε : 0 < ε) {n : ℕ} (hn : 0 < n) : + (∑ x : Spin n, ∑ y : Spin n, if ε*n < |replicaOverlap x y| then + doublePlantWeight β x y else 0) ≤ + Real.exp (-((q-β^2)*ε^2*n/2)) * (Real.sqrt (1-q))⁻¹ := by + let D := ∑ x : Spin n, ∑ y : Spin n, Real.exp (β^2*replicaOverlap x y^2/(2*n)) + have hD : ((2:ℝ)^n)^2 ≤ D := by + have he (x y : Spin n) : (1:ℝ) ≤ Real.exp (β^2*replicaOverlap x y^2/(2*n)) := + Real.one_le_exp_iff.mpr (by positivity) + have hh := Finset.sum_le_sum (s := Finset.univ) (fun x _ => + Finset.sum_le_sum (s := Finset.univ) (fun y _ => he x y)) + simpa only [Finset.sum_const, Finset.card_univ, card_spin, nsmul_eq_mul, + Nat.cast_pow, Nat.cast_ofNat, mul_one, pow_two, D] using hh + have hid : (∑ x : Spin n, ∑ y : Spin n, if ε*n < |replicaOverlap x y| then + doublePlantWeight β x y else 0) = + (∑ x : Spin n, ∑ y : Spin n, if ε*n < |replicaOverlap x y| then + Real.exp (β^2*replicaOverlap x y^2/(2*n)) else 0) / D := by + simp only [doublePlantWeight_eq_overlap_tilt β hn, Finset.sum_div] + apply Finset.sum_congr rfl + intro x _ + apply Finset.sum_congr rfl + intro y _ + split_ifs <;> simp [D] + rw [hid] + calc + _ ≤ (∑ x : Spin n, ∑ y : Spin n, if ε*n < |replicaOverlap x y| then + Real.exp (β^2*replicaOverlap x y^2/(2*n)) else 0) / ((2:ℝ)^n)^2 := by + exact div_le_div_of_nonneg_left (Finset.sum_nonneg (fun x _ => + Finset.sum_nonneg (fun y _ => by split_ifs <;> positivity))) (by positivity) hD + _ = (∑ x : Spin n, if ε*n < |magnetization x| then + Real.exp (β^2*magnetization x^2/(2*n)) else 0) / (2:ℝ)^n := by + simp_rw [sum_replicaOverlap _ (fun z => if ε*n < |z| then Real.exp (β^2*z^2/(2*n)) else 0)] + simp only [Finset.sum_const, Finset.card_univ, card_spin, nsmul_eq_mul, + Nat.cast_pow, Nat.cast_ofNat] + field_simp + _ ≤ _ := sign_square_tail_le β q ε hβq hq hε hn + +end SKGapCutoff + +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Matrix/DoublePlantedGOEArray.lean b/lean/OAI/Probability/SKGap/Matrix/DoublePlantedGOEArray.lean new file mode 100644 index 0000000000000000000000000000000000000000..afc92cbde3bb160f451568dfe6088555d3c1e1f6 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Matrix/DoublePlantedGOEArray.lean @@ -0,0 +1,164 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.SampledFlatCLM +import OAI.Probability.SKGap.Matrix.DoublePlantLogNorm + +namespace OAI + +section +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open scoped BigOperators +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open scoped BigOperators +open scoped BigOperators NNReal ENNReal +open MeasureTheory Metric Set +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators NNReal ENNReal Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Set +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators ENNReal NNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Matrix +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators ENNReal NNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal +open scoped BigOperators +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise NNReal ENNReal +open scoped BigOperators +open Filter Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal Topology +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +namespace SKGapCutoff.Regression + +noncomputable def doublePlantedGOEArray {n : ℕ} (β : ℝ) (x y : Spin n) + (g : GaussianCoordinates n) : GaussianCoordinates n := + plantedGOEArray β x g + fun p => if p.1=p.2 then 0 else β^2/(n:ℝ)*spin y p.1*spin y p.2 + +lemma doublePlantedGOEArray_gaussian {n : ℕ} (β : ℝ) (x y : Spin n) : + HasGaussianLaw (doublePlantedGOEArray β x y) (standardArrayLaw (Fin n × Fin n)) := + gaussian_add_constant (plantedGOEArray_gaussian β x) _ + +lemma sampled_double_planted_gaussian (β : ℝ) {n : ℕ} (hn : 0 < n) (x y : Spin n) : + HasGaussianLaw (fun g : GaussianCoordinates n => fun p : Fin n × Fin n => + sampledInteraction g p.1 p.2) (doubleSpinPlantedLaw β x y) := by + rw [doubleSpinPlantedLaw_eq_gaussianPi β hn] + have hh := (piGaussian_coordinates (fun p => β^2/(n:ℝ)*(upperCoefficient x p + upperCoefficient y p)) + (Real.toNNReal (β^2/(n:ℝ)))).map_fun (sampledFlatCLM n) + exact hh.congr (Eventually.of_forall fun g => funext fun p => sampledFlatCLM_apply g p) + +lemma doublePlantedGOEArray_mean {n : ℕ} (β : ℝ) (x y : Spin n) (p : Fin n × Fin n) : + (∫ g, doublePlantedGOEArray β x y g p ∂standardArrayLaw (Fin n × Fin n)) = + if p.1=p.2 then 0 else β^2/(n:ℝ)*(spin x p.1*spin x p.2+spin y p.1*spin y p.2) := by + change (∫ g, plantedGOEArray β x g p + _ ∂standardArrayLaw (Fin n × Fin n)) = _ + rw [integral_add ((plantedGOEArray_gaussian β x).eval p).integrable + (integrable_const _), plantedGOEArray_mean, integral_const] + by_cases h : p.1=p.2 + · simp [h] + · simp [h] + ring + +lemma sampled_double_planted_mean (β : ℝ) {n : ℕ} (hn : 0 < n) (x y : Spin n) + (p : Fin n × Fin n) : + (∫ g, sampledInteraction g p.1 p.2 ∂doubleSpinPlantedLaw β x y) = + if p.1=p.2 then 0 else β^2/(n:ℝ)*(spin x p.1*spin x p.2+spin y p.1*spin y p.2) := by + rw [doubleSpinPlantedLaw_eq_gaussianPi β hn] + by_cases h : p.1=p.2 + · simp [sampledInteraction, h] + · simp only [sampledInteraction, h, ite_false] + rw [piGaussian_coordinate_mean, upperCoefficient_min_max x _ _ h, + upperCoefficient_min_max y _ _ h] + +lemma doublePlantedGOEArray_covariance {n : ℕ} (hn : 0 < n) (β : ℝ) (x y : Spin n) + (p q : Fin n × Fin n) : + cov[fun g => doublePlantedGOEArray β x y g p, fun g => doublePlantedGOEArray β x y g q; + standardArrayLaw (Fin n × Fin n)] = + if p.1=p.2 ∨ q.1=q.2 then 0 else + (β^2/(n:ℝ)) * ((if p.1=q.1 ∧ p.2=q.2 then 1 else 0) + + (if p.1=q.2 ∧ p.2=q.1 then 1 else 0)) := by + change cov[fun g => plantedGOEArray β x g p + _, fun g => plantedGOEArray β x g q + _; _] = _ + rw [covariance_add_const_left ((plantedGOEArray_gaussian β x).eval p).integrable, + covariance_add_const_right ((plantedGOEArray_gaussian β x).eval q).integrable, + plantedGOEArray_covariance hn] + +lemma sampled_double_planted_covariance (β : ℝ) {n : ℕ} (hn : 0 < n) (x y : Spin n) + (p q : Fin n × Fin n) : + cov[fun g => sampledInteraction g p.1 p.2, fun g => sampledInteraction g q.1 q.2; + doubleSpinPlantedLaw β x y] = + if p.1=p.2 ∨ q.1=q.2 then 0 else + (β^2/(n:ℝ)) * ((if p.1=q.1 ∧ p.2=q.2 then 1 else 0) + + (if p.1=q.2 ∧ p.2=q.1 then 1 else 0)) := by + rw [doubleSpinPlantedLaw_eq_gaussianPi β hn] + by_cases hp : p.1=p.2 + · simp [sampledInteraction, hp] + by_cases hq : q.1=q.2 + · simp [sampledInteraction, hq] + simp only [sampledInteraction, hp, hq, false_or, ite_false] + rw [piGaussian_coordinate_covariance, Real.coe_toNNReal _ (by positivity)] + simp only [minmax_pair_eq_iff] + by_cases h1 : p.1=q.1 ∧ p.2=q.2 + · have h2 : ¬ (p.1=q.2 ∧ p.2=q.1) := by omega + rw [ite_eq_left (Or.inl h1), ite_eq_left h1, ite_eq_right h2, add_zero, mul_one] + by_cases h2 : p.1=q.2 ∧ p.2=q.1 + · rw [ite_eq_left (Or.inr h2), ite_eq_right h1, ite_eq_left h2, zero_add, mul_one] + · rw [ite_eq_right (not_or.mpr ⟨h1,h2⟩), ite_eq_right h1, ite_eq_right h2, add_zero, mul_zero] + +lemma double_planted_matrix_representation (β : ℝ) {n : ℕ} (hn : 0 < n) (x y : Spin n) : + (doubleSpinPlantedLaw β x y).map (fun g : GaussianCoordinates n => + fun p : Fin n × Fin n => sampledInteraction g p.1 p.2) = + (standardArrayLaw (Fin n × Fin n)).map (doublePlantedGOEArray β x y) := by + apply gaussian_vector_law_ext (sampled_double_planted_gaussian β hn x y) + (doublePlantedGOEArray_gaussian β x y) + · intro p + rw [sampled_double_planted_mean β hn, doublePlantedGOEArray_mean] + · intro p q + rw [sampled_double_planted_covariance β hn, doublePlantedGOEArray_covariance hn] + +end SKGapCutoff.Regression + +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Matrix/FixedNormRecipeEvent.lean b/lean/OAI/Probability/SKGap/Matrix/FixedNormRecipeEvent.lean new file mode 100644 index 0000000000000000000000000000000000000000..d8d3308dc64a60b654ecfca74d6cbdac7520432a --- /dev/null +++ b/lean/OAI/Probability/SKGap/Matrix/FixedNormRecipeEvent.lean @@ -0,0 +1,261 @@ +import Mathlib +import OAI.Probability.SKGap.Gaussian.GaussianRecipeEvent + +namespace OAI + +section + +noncomputable section +open scoped BigOperators Topology +open Filter MeasureTheory ProbabilityTheory Real +namespace SKGapCutoff.Recipe +open SKGap SKGap.Noncrossing SKGap.Noncrossing.Primary + +def physicalNormBound (j : ℝ) : ℝ := 2*Real.sqrt j+1+1 + +lemma physicalNormBound_pos (j : ℝ) : 0(Measure.pi (fun _ : MatrixCoordinates (Fin n)=>gaussianReal 0 1)) + {g | ¬RecipeMatrixEvent j (physicalNormBound j) A B W C M Nmax + (removeDiagonal (goeMatrix (j/n) g))}) atTop (𝓝 0) := by + obtain ⟨R,B,W,C,hR,hB,hW,hC,hprob⟩:=gaussian_recipe_event_probability hj hj1 hA M Nmax + refine ⟨B,W,C,hB,hW,hC,?_⟩ + have hup := hprob.add (recipeNormTail_limit hj) + apply tendsto_of_tendsto_of_tendsto_of_le_of_le' tendsto_const_nhds (by simpa using hup) + (Filter.Eventually.of_forall (fun _=>bot_le)) + filter_upwards [eventually_ge_atTop 1] with n hn + let μ:=Measure.pi (fun _ : MatrixCoordinates (Fin n)=>gaussianReal 0 1) + let E : Set (MatrixCoordinates (Fin n)→ℝ):={g | ¬RecipeMatrixEvent j R A B W C M Nmax + (removeDiagonal (goeMatrix (j/n) g))} + let F : Set (MatrixCoordinates (Fin n)→ℝ):={g | physicalNormBound jhh (.inr hbad) + have he : RecipeMatrixEvent j R A B W C M Nmax (removeDiagonal (goeMatrix (j/n) g)):= by + by_contra hbad;exact hh (.inl hbad) + exact hg ⟨ho,he.2⟩ + +end SKGapCutoff.Recipe + +end +end + +section + +noncomputable section +open scoped BigOperators +open MeasureTheory ProbabilityTheory Filter + +namespace SKGapCutoff +namespace GapBridge + +def restrictUpper {n : ℕ} (g : GaussianCoordinates n) : SKGap.Disorder n := + fun e => g e.val + +lemma measurable_restrictUpper (n : ℕ) : Measurable (restrictUpper (n := n)) := by + exact Measurable.of_eval (fun edge => measurable_pi_apply edge.val) + +lemma coupling_restrictUpper {n : ℕ} (g : GaussianCoordinates n) : + SKGap.coupling (restrictUpper g) = sampledInteraction g := by + funext i k + rcases lt_trichotomy i k with h | rfl | h + · simp [SKGap.coupling, restrictUpper, sampledInteraction, h, ne_of_lt h, + min_eq_left h.le, max_eq_right h.le] + · simp [SKGap.coupling, sampledInteraction] + · simp [SKGap.coupling, restrictUpper, sampledInteraction, h, ne_of_gt h, + not_lt_of_gt h, min_eq_right h.le, max_eq_left h.le] + +def edgeInteraction {n : ℕ} (g : SKGap.Disorder n) : Interaction n := Matrix.of (SKGap.coupling g) + +lemma edgeInteraction_restrictUpper {n : ℕ} (g : GaussianCoordinates n) : + edgeInteraction (restrictUpper g) = sampledInteraction g := coupling_restrictUpper g + +lemma coupling_symmetric {n : ℕ} (g : SKGap.Disorder n) (i k : Fin n) : + SKGap.coupling g i k = SKGap.coupling g k i := by + rcases lt_trichotomy i k with h | rfl | h + · simp [SKGap.coupling, h, not_lt_of_gt h] + · rfl + · simp [SKGap.coupling, h, not_lt_of_gt h] + +lemma coupling_diagonal {n : ℕ} (g : SKGap.Disorder n) (i : Fin n) : + SKGap.coupling g i i = 0 := by simp [SKGap.coupling] + +lemma hamiltonian_zero {n : ℕ} (g : SKGap.Disorder n) (x : Spin n) : + SKGap.hamiltonian g 0 x = energy (edgeInteraction g) x := by + simp only [SKGap.hamiltonian, Pi.zero_apply, zero_mul, Finset.sum_const_zero, + add_zero, SKGap.spinValue, energy, spin, edgeInteraction, Matrix.of_apply] + ring + +lemma weight_zero {n : ℕ} (g : SKGap.Disorder n) (x : Spin n) : + SKGap.weight g 0 x = Real.exp (energy (edgeInteraction g) x) := by + rw [SKGap.weight, hamiltonian_zero] + +lemma partition_zero {n : ℕ} (g : SKGap.Disorder n) : + SKGap.partition g 0 = partition (edgeInteraction g) := by + simp only [SKGap.partition, partition, weight_zero] + +lemma mass_zero {n : ℕ} (g : SKGap.Disorder n) (x : Spin n) : + SKGap.mass g 0 x = gibbs (edgeInteraction g) x := by + simp only [SKGap.mass, weight_zero, partition_zero] + rfl + +lemma expectation_zero {n : ℕ} (g : SKGap.Disorder n) (f : Observables n) : + SKGap.expectation g 0 f = gibbsExpectation (edgeInteraction g) f := by + simp only [SKGap.expectation, gibbsExpectation, mass_zero] + +lemma variance_zero {n : ℕ} (g : SKGap.Disorder n) (f : Observables n) : + SKGap.variance g 0 f = gibbsVariance (edgeInteraction g) f := by + simp only [SKGap.variance, gibbsVariance, expectation_zero] + +lemma flip_eq {n : ℕ} (i : Fin n) (x : Spin n) : SKGap.flip i x = flip x i := rfl + +def pairConditional {n : ℕ} (J : Interaction n) (i : Fin n) + (f : Observables n) (x : Spin n) : ℝ := + (gibbs J x * f x + gibbs J (flip x i) * f (flip x i)) / + (gibbs J x + gibbs J (flip x i)) + +lemma conditionalExpectation_zero {n : ℕ} (g : SKGap.Disorder n) (i : Fin n) + (f : Observables n) (x : Spin n) : + SKGap.conditionalExpectation g 0 i f x = pairConditional (edgeInteraction g) i f x := by + simp only [SKGap.conditionalExpectation, weight_zero, flip_eq, pairConditional, gibbs] + field_simp [ne_of_gt (partition_pos (edgeInteraction g))] + +lemma pairConditional_flip {n : ℕ} (J : Interaction n) (i : Fin n) + (f : Observables n) (x : Spin n) : + pairConditional J i f (flip x i) = pairConditional J i f x := by + simp only [pairConditional, flip_flip, add_comm] + +lemma flipRate_complement {n : ℕ} (J : Interaction n) (hd : ∀ i, J i i = 0) + (i : Fin n) (x : Spin n) : flipRate J (flip x i) i = 1 - flipRate J x i := by + simp only [flipRate, spin_flip_self, mean_flip J hd] + ring + +lemma flipRate_eq_mass {n : ℕ} (J : Interaction n) + (hJ : ∀ i k, J i k = J k i) (hd : ∀ i, J i i = 0) + (i : Fin n) (x : Spin n) : + flipRate J x i = gibbs J (flip x i) / (gibbs J x + gibbs J (flip x i)) := by + apply (eq_div_iff (ne_of_gt (add_pos (gibbs_pos J x) (gibbs_pos J (flip x i))))).2 + have hb := gibbs_detailed_balance J hJ hd x i + rw [flipRate_complement J hd] at hb + nlinarith only [hb] + +lemma pairConditional_residual {n : ℕ} (J : Interaction n) + (hJ : ∀ i k, J i k = J k i) (hd : ∀ i, J i i = 0) + (i : Fin n) (f : Observables n) (x : Spin n) : + f x - pairConditional J i f x = flipRate J x i * (f x - f (flip x i)) := by + rw [flipRate_eq_mass J hJ hd] + unfold pairConditional + field_simp [ne_of_gt (add_pos (gibbs_pos J x) (gibbs_pos J (flip x i)))] + ring + +lemma conditional_variance_projection {n : ℕ} (J : Interaction n) + (i : Fin n) (f : Observables n) : + (∑ x, gibbs J x * (f x - pairConditional J i f x) ^ 2) = + ∑ x, gibbs J x * f x * (f x - pairConditional J i f x) := by + let l : Observables n := fun x => gibbs J x * (f x - pairConditional J i f x) ^ 2 + let r : Observables n := fun x => gibbs J x * f x * (f x - pairConditional J i f x) + have hp (x : Spin n) : l x + l (flip x i) = r x + r (flip x i) := by + dsimp only [l, r] + rw [pairConditional_flip] + simp only [pairConditional] + field_simp [ne_of_gt (add_pos (gibbs_pos J x) (gibbs_pos J (flip x i)))] + ring + have hh := congrArg (fun u : Observables n => ∑ x, u x) (funext hp) + simp only [Finset.sum_add_distrib, sum_flip] at hh + change (∑ x, l x) = ∑ x, r x + linarith + +theorem dirichlet_zero {n : ℕ} (g : SKGap.Disorder n) (f : Observables n) : + SKGap.dirichlet g 0 f = dirichlet (edgeInteraction g) f f := by + simp only [SKGap.dirichlet, expectation_zero, conditionalExpectation_zero, gibbsExpectation] + simp_rw [conditional_variance_projection, + pairConditional_residual (edgeInteraction g) (coupling_symmetric g) (coupling_diagonal g)] + simp_rw [gibbs_edge_dirichlet (edgeInteraction g) (coupling_symmetric g) (coupling_diagonal g)] + simp only [dirichlet, gibbsExpectation, Finset.mul_sum] + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro x _ + apply Finset.sum_congr rfl + intro i _ + ring + +theorem measurePreserving_restrictUpper (β : ℝ) (n : ℕ) : + MeasurePreserving (restrictUpper (n := n)) (disorderLaw β n) (SKGap.disorderLaw β n) := by + let μ : (Fin n × Fin n) → Measure ℝ := fun _ => + gaussianReal 0 (Real.toNNReal (β ^ 2 / (n : ℝ))) + have h := measurePreserving_fst.comp + (measurePreserving_piEquivPiSubtypeProd μ (fun e : Fin n × Fin n => e.1 < e.2)) + change MeasurePreserving (fun g : Fin n × Fin n → ℝ => fun e : SKGap.Edge n => g e.val) + (Measure.pi μ) (Measure.pi (fun e : SKGap.Edge n => μ e.val)) + simpa only [MeasurableEquiv.piEquivPiSubtypeProd_apply, Function.comp_def] using h + +lemma continuous_coupling (n : ℕ) : Continuous (edgeInteraction (n := n)) := by + apply continuous_pi + intro i + apply continuous_pi + intro k + change Continuous (fun g : SKGap.Disorder n => SKGap.coupling g i k) + by_cases hik : i < k + · simp only [SKGap.coupling, dite_eq_left hik] + exact continuous_apply _ + · simp only [SKGap.coupling, dite_eq_right hik] + by_cases hki : k < i + · simp only [dite_eq_left hki] + exact continuous_apply _ + · simp only [dite_eq_right hki] + exact continuous_const + +lemma poincare_iff_hasGap {n : ℕ} (g : SKGap.Disorder n) {C : ℝ} (hC : 0 < C) : + g ∈ SKGap.poincareEvent n C ↔ HasGap (edgeInteraction g) (1 / C) := by + simp only [SKGap.poincareEvent, Set.mem_ofPred_eq, HasGap, variance_zero, dirichlet_zero] + apply forall_congr' + intro f + rw [show (1 / C) * gibbsVariance (edgeInteraction g) f = + gibbsVariance (edgeInteraction g) f / C by ring, div_le_iff₀ hC, mul_comm] + +lemma measurableSet_poincareEvent (n : ℕ) {C : ℝ} (hC : 0 < C) : + MeasurableSet (SKGap.poincareEvent n C) := by + have he : SKGap.poincareEvent n C = + edgeInteraction ⁻¹' {J : Interaction n | HasGap J (1/C)} := by + ext g + exact poincare_iff_hasGap g hC + rw [he] + exact ((isClosed_hasGap (1/C)).preimage (continuous_coupling n)).measurableSet + +theorem probability_poincare_eq (β : ℝ) (n : ℕ) {C : ℝ} (hC : 0 < C) : + (SKGap.disorderLaw β n) (SKGap.poincareEvent n C) = + (disorderLaw β n) {g | HasGap (sampledInteraction g) (1/C)} := by + rw [← (measurePreserving_restrictUpper β n).measure_preimage + (measurableSet_poincareEvent n hC).nullMeasurableSet] + congr 1 + ext g + simpa only [Set.mem_preimage, Set.mem_ofPred_eq, edgeInteraction_restrictUpper] using + poincare_iff_hasGap (restrictUpper g) hC + +theorem quenchedGap_iff_edgePoincare (β : ℝ) : QuenchedGap β ↔ + ∃ C : ℝ, 0 < C ∧ Tendsto (fun n => SKGap.disorderLaw β n (SKGap.poincareEvent n C)) + atTop (nhds 1) := by + constructor + · rintro ⟨γ, hγ, h⟩ + refine ⟨1/γ, one_div_pos.mpr hγ, ?_⟩ + have he (n : ℕ) : SKGap.disorderLaw β n (SKGap.poincareEvent n (1/γ)) = + disorderLaw β n {g | HasGap (sampledInteraction g) γ} := by + simpa only [one_div_one_div] using probability_poincare_eq β n (one_div_pos.mpr hγ) + simpa only [he] using h + · rintro ⟨C, hC, h⟩ + refine ⟨1/C, one_div_pos.mpr hC, ?_⟩ + simpa only [probability_poincare_eq β _ hC] using h + +end GapBridge +end SKGapCutoff +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Matrix/FockTensor.lean b/lean/OAI/Probability/SKGap/Matrix/FockTensor.lean new file mode 100644 index 0000000000000000000000000000000000000000..0d3b534c24c71e467d2fb3132ab572877f12320e --- /dev/null +++ b/lean/OAI/Probability/SKGap/Matrix/FockTensor.lean @@ -0,0 +1,134 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.GraphPrediction + +namespace OAI + +section + +noncomputable section +open scoped BigOperators +namespace SKGap.Noncrossing.Primary.Tensor +open Diagram +variable {ι : Type*} [Fintype ι] +abbrev Space := ι→List ι→ℝ + +def tensorValue : List (ι→ℝ)→List ι→ℝ + | [],[] => 1 + | a::A,i::I => a i*tensorValue A I + | _,_ => 0 + +def realize : Primary.Space (ι:=ι)→ₗ[ℝ] Space (ι:=ι) := + Finsupp.linearCombination ℝ (fun s i I =>s.1 i*tensorValue s.2 I) +omit [Fintype ι] in +lemma realize_ket (s : Stack (ι:=ι)) (i : ι) (I : List ι) : + realize (ket s) i I=s.1 i*tensorValue s.2 I := by simp [realize,ket] + +def diagonal (a : ι→ℝ) : Space (ι:=ι)→ₗ[ℝ] Space (ι:=ι) where + toFun v i I := a i*v i I + map_add' v w := by ext i I; simp [mul_add] + map_smul' c v := by ext i I; simp [mul_left_comm] +def creation : Space (ι:=ι)→ₗ[ℝ] Space (ι:=ι) where + toFun v i I := match I with | [] => 0 | q::Q => v q Q + map_add' v w := by ext i I; cases I <;> simp + map_smul' c v := by ext i I; cases I <;> simp +def annihilation : Space (ι:=ι)→ₗ[ℝ] Space (ι:=ι) where + toFun v i I := Diagram.mean (fun q =>v q (i::I)) + map_add' v w := by ext i I; simp [Diagram.mean,Finset.sum_add_distrib,add_div] + map_smul' c v := by ext i I; simp [Diagram.mean,←Finset.mul_sum,mul_div_assoc] +def noise (j : ℝ) : Space (ι:=ι)→ₗ[ℝ] Space (ι:=ι) := creation+j • annihilation +def project : Space (ι:=ι)→ₗ[ℝ] (ι→ℝ) where + toFun v i := v i [] + map_add' _ _ := rfl + map_smul' _ _ := rfl + +def vacuum : Space (ι:=ι) := realize Primary.vacuum + +def letter (j : ℝ) : Letter (ι→ℝ)→Space (ι:=ι)→ₗ[ℝ] Space (ι:=ι) + | .diag a => diagonal a + | .noise => noise j +def word (j : ℝ) : List (Letter (ι→ℝ))→Space (ι:=ι)→ₗ[ℝ] Space (ι:=ι) + | [] => LinearMap.id + | a::F => (letter j a).comp (word j F) + +omit [Fintype ι] in +lemma realize_diagonal (a : ι→ℝ) (v : Primary.Space (ι:=ι)) : + realize (Primary.diagonal a v)=diagonal a (realize v) := by + have h : realize.comp (Primary.diagonal a)=(diagonal a).comp realize := by + apply Finsupp.lhom_ext' + intro s + ext i I + change realize (Primary.diagonal a (ket s)) i I = diagonal a (realize (ket s)) i I + rw [Primary.diagonal_ket,realize_ket] + change (a i*s.1 i)*tensorValue s.2 I=a i*realize (ket s) i I + rw [realize_ket]; ring + exact LinearMap.congr_fun h v +omit [Fintype ι] in +lemma realize_creation (v : Primary.Space (ι:=ι)) : + realize (Primary.creation v)=creation (realize v) := by + have h : (realize (ι:=ι)).comp Primary.creation=creation.comp realize := by + apply Finsupp.lhom_ext' + intro s + ext i I + change realize (Primary.creation (ket s)) i I = creation (realize (ket s)) i I + rw [Primary.creation_ket,realize_ket] + cases I <;> simp [creation,tensorValue,realize_ket] + exact LinearMap.congr_fun h v +lemma realize_annihilation (v : Primary.Space (ι:=ι)) : + realize (Primary.annihilation v)=annihilation (realize v) := by + have h : (realize (ι:=ι)).comp Primary.annihilation=annihilation.comp realize := by + apply Finsupp.lhom_ext' + rintro ⟨a,L⟩ + ext i I + change realize (Primary.annihilation (ket (a,L))) i I = annihilation (realize (ket (a,L))) i I + cases L <;> simp [annihilation,realize_ket,tensorValue,Diagram.mean,←Finset.sum_mul,div_mul_eq_mul_div] + exact LinearMap.congr_fun h v +lemma realize_noise (j : ℝ) (v : Primary.Space (ι:=ι)) : + realize (Primary.noise j v)=noise j (realize v) := by + simp [Primary.noise,noise,realize_annihilation,realize_creation] +omit [Fintype ι] in +lemma project_realize (v : Primary.Space (ι:=ι)) : project (realize v)=Primary.project v := by + have h : (project (ι:=ι)).comp realize=Primary.project := by + apply Finsupp.lhom_ext' + rintro ⟨a,L⟩ + ext i + change project (realize (ket (a,L))) i = Primary.project (ket (a,L)) i + cases L <;> simp [project,realize_ket,tensorValue] + exact LinearMap.congr_fun h v +lemma realize_word (j : ℝ) (F : List (Letter (ι→ℝ))) (v : Primary.Space (ι:=ι)) : + realize (Primary.word j F v)=word j F (realize v) := by + induction F generalizing v with + | nil => rfl + | cons a F ih => + cases a <;> simp [Primary.word,Primary.letter,word,letter,realize_noise,realize_diagonal,ih] +omit [Fintype ι] in +lemma diagram_map_id (d : Diagram (ι→ℝ)) : d.map id=d := by + induction d <;> simp_all [Diagram.map] +lemma project_word (j : ℝ) (F : List (Letter (ι→ℝ))) (i : ι) : + project (word j F vacuum) i=WordSeries.ordinary j F i := by + rw [vacuum,←realize_word,project_realize,Primary.project_word] + simp [WordSeries.ordinary,Diagram.expect,Diagram.evaluate,Diagram.prediction,diagram_map_id] +lemma word_append (j : ℝ) (F G : List (Letter (ι→ℝ))) : + word j (F++G)=(word j F).comp (word j G) := by + induction F with + | nil => simp [word] + | cons a F ih => simp [word,ih,LinearMap.comp_assoc] +omit [Fintype ι] in +lemma diagonal_scale (c : ℝ) (a : ι→ℝ) : diagonal (fun i=>c*a i)=c • diagonal a := by + ext v i I + change (c*a i)*v i I=c*(a i*v i I) + ring +lemma annihilation_diagonal_creation (a : ι→ℝ) (v : Space (ι:=ι)) : + annihilation (diagonal a (creation v))=Diagram.mean a • v := by + ext i I + simp [annihilation,diagonal,creation,Diagram.mean,←Finset.sum_mul,mul_div_right_comm] +omit [Fintype ι] in +lemma project_diagonal_creation (a : ι→ℝ) (v : Space (ι:=ι)) : + project (diagonal a (creation v))=0 := by ext i; simp [project,diagonal,creation] +omit [Fintype ι] in +lemma project_creation (v : Space (ι:=ι)) : project (creation v)=0 := rfl +end SKGap.Noncrossing.Primary.Tensor + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Matrix/GOEBilinearCov.lean b/lean/OAI/Probability/SKGap/Matrix/GOEBilinearCov.lean new file mode 100644 index 0000000000000000000000000000000000000000..aeab6b1ebe18bd241568e87f091f802fa883eaf2 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Matrix/GOEBilinearCov.lean @@ -0,0 +1,138 @@ +import Mathlib +import OAI.Probability.SKGap.Posterior.GOEObservation + +namespace OAI + +section +noncomputable section +namespace SKGap +open MeasureTheory ProbabilityTheory Matrix Real +open scoped BigOperators ENNReal +variable {ι : Type*} [Fintype ι] [DecidableEq ι] + +lemma goe_entry_mulVec_cov {r : ℝ} (hr : 0 ≤ r) (v : ι → ℝ) (i k l : ι) : + cov[fun g => goeMatrix r g i k,fun g => (goeMatrix r g*ᵥv) l; + gaussianCoordinates (MatrixCoordinates ι)] = + r*((if i=l then v k else 0)+(if k=l then v i else 0)) := by + simpa only [goeObservation,sqrt_zero,zero_mul,add_zero] using + goe_entry_observation_cov hr 0 v i k l + +lemma goe_mulVec_cross_cov {r : ℝ} (hr : 0 ≤ r) (u v : ι → ℝ) (i l : ι) : + cov[fun g => (goeMatrix r g*ᵥu) i,fun g => (goeMatrix r g*ᵥv) l; + gaussianCoordinates (MatrixCoordinates ι)] = + r*((if i=l then u⬝ᵥv else 0)+v i*u l) := by + change cov[fun g => ∑ k,goeMatrix r g i k*u k,fun g => (goeMatrix r g*ᵥv) l;_]=_ + rw [covariance_fun_sum_left + (fun k => (goe_matrix_gaussian (ι := ι) r).eval (i,k) |>.memLp_two.mul_const (u k)) + (goe_mulVec_memLp r v l)] + simp only [covariance_mul_const_left,goe_entry_mulVec_cov hr] + by_cases hil : i=l + · subst l + simp only [ite_true,mul_add,add_mul,Finset.sum_add_distrib] + have hsum : (∑ k,r*v k*u k)=r*(u⬝ᵥv) := by + simp only [dotProduct,Finset.mul_sum] + apply Finset.sum_congr rfl + intro k _ + ring + rw [hsum] + simp [mul_ite,ite_mul,mul_assoc] + · simp [hil,mul_ite,ite_mul] + ring + +def goeBilinear (r : ℝ) (x y : ι → ℝ) (g : MatrixCoordinates ι → ℝ) : ℝ := + x⬝ᵥ(goeMatrix r g*ᵥy) + +lemma goeBilinear_memLp (r : ℝ) (x y : ι → ℝ) : + MemLp (goeBilinear r x y) 2 (gaussianCoordinates (MatrixCoordinates ι)) := by + exact memLp_finsetSum _ (fun i _ => (goe_mulVec_memLp r y i).const_mul (x i)) + +lemma goe_bilinear_cov {r : ℝ} (hr : 0 ≤ r) (x y u v : ι → ℝ) : + cov[goeBilinear r x y,goeBilinear r u v;gaussianCoordinates (MatrixCoordinates ι)] = + r*((x⬝ᵥu)*(y⬝ᵥv)+(x⬝ᵥv)*(y⬝ᵥu)) := by + change cov[fun g => ∑ i,x i*(goeMatrix r g*ᵥy) i, + fun g => ∑ k,u k*(goeMatrix r g*ᵥv) k;_]=_ + rw [covariance_fun_sum_fun_sum (fun i => (goe_mulVec_memLp r y i).const_mul (x i)) + (fun k => (goe_mulVec_memLp r v k).const_mul (u k))] + simp only [covariance_const_mul_left,covariance_const_mul_right,goe_mulVec_cross_cov hr] + have hsum (i : ι) : (∑ k,u k*(x i*(r*((if i=k then y⬝ᵥv else 0)+v i*y k))))= + r*((x i*u i)*(y⬝ᵥv)+(x i*v i)*(y⬝ᵥu)) := by + simp only [mul_add,Finset.sum_add_distrib] + have hf : (∑ k,u k*(x i*(r*(v i*y k))))=(r*(x i*v i))*(y⬝ᵥu) := by + simp only [dotProduct,Finset.mul_sum] + apply Finset.sum_congr rfl + intro k _ + ring + rw [hf] + simp [mul_ite] + ring + simp_rw [hsum] + simp only [mul_add,Finset.sum_add_distrib] + have h1 : (∑ i,r*((x i*u i)*(y⬝ᵥv)))=r*((x⬝ᵥu)*(y⬝ᵥv)) := by + rw [← Finset.mul_sum,← Finset.sum_mul] + rfl + have h2 : (∑ i,r*((x i*v i)*(y⬝ᵥu)))=r*((x⬝ᵥv)*(y⬝ᵥu)) := by + rw [← Finset.mul_sum,← Finset.sum_mul] + rfl + rw [h1,h2] + +end SKGap +end +end + +section +noncomputable section +namespace SKGap +open MeasureTheory ProbabilityTheory Matrix Real +open scoped BigOperators ENNReal +variable {ι : Type*} [Fintype ι] [DecidableEq ι] + +def unitRow (κ : ℝ) (u : ι → ℝ) (i : ι) : ι → ℝ := + Pi.single i 1+((κ-1)*u i) • u + +lemma unitRow_dot {u : ι → ℝ} (hu : u⬝ᵥu=1) (κ : ℝ) (i : ι) : + unitRow κ u i⬝ᵥu=κ*u i := by + simp only [unitRow,add_dotProduct,single_one_dotProduct,smul_dotProduct,hu,smul_eq_mul,mul_one] + ring + +lemma unitRow_dot_unitRow {u : ι → ℝ} (hu : u⬝ᵥu=1) (κ : ℝ) (i l : ι) : + unitRow κ u i⬝ᵥunitRow κ u l=(if i=l then 1 else 0)+(κ^2-1)*u i*u l := by + simp only [unitRow,add_dotProduct,dotProduct_add,smul_dotProduct,dotProduct_smul, + single_one_dotProduct,dotProduct_single_one,hu,smul_eq_mul,mul_one] + by_cases hil : i=l <;> simp [hil] <;> ring + +def goeBlockResidual (r κ ell : ℝ) (u : ι → ℝ) (g : MatrixCoordinates ι → ℝ) : Matrix ι ι ℝ := + fun i k => goeBilinear r (unitRow κ u i) (unitRow κ u k) g+ + ((ell-κ^2)*u i*u k)*goeBilinear r u u g + +lemma goeBlockResidual_memLp (r κ ell : ℝ) (u : ι → ℝ) (i k : ι) : + MemLp (fun g => goeBlockResidual r κ ell u g i k) 2 (gaussianCoordinates (MatrixCoordinates ι)) := + (goeBilinear_memLp r _ _).add ((goeBilinear_memLp r u u).const_mul _) + +lemma goeBlockResidual_cov {r : ℝ} (hr : 0 ≤ r) {u : ι → ℝ} (hu : u⬝ᵥu=1) + (κ ell : ℝ) (i k l a : ι) : + cov[fun g => goeBlockResidual r κ ell u g i k, + fun g => goeBlockResidual r κ ell u g l a;gaussianCoordinates (MatrixCoordinates ι)] = + r*((if i=l then 1 else 0)*(if k=a then 1 else 0)+(if i=a then 1 else 0)*(if k=l then 1 else 0))+ + r*(κ^2-1)*((if i=l then 1 else 0)*u k*u a+(if k=a then 1 else 0)*u i*u l+ + (if i=a then 1 else 0)*u k*u l+(if k=l then 1 else 0)*u i*u a)+ + 2*r*(ell^2-2*κ^2+1)*u i*u k*u l*u a := by + have hB (i k : ι) := goeBilinear_memLp r (unitRow κ u i) (unitRow κ u k) + have hU := goeBilinear_memLp r u u + change cov[goeBilinear r (unitRow κ u i) (unitRow κ u k)+ + (fun g => ((ell-κ^2)*u i*u k)*goeBilinear r u u g), + goeBilinear r (unitRow κ u l) (unitRow κ u a)+ + (fun g => ((ell-κ^2)*u l*u a)*goeBilinear r u u g);_]=_ + rw [covariance_add_left (hB i k) (hU.const_mul _) ((hB l a).add (hU.const_mul _)), + covariance_add_right (hB i k) (hB l a) (hU.const_mul _), + covariance_add_right (hU.const_mul _) (hB l a) (hU.const_mul _)] + simp only [covariance_const_mul_left,covariance_const_mul_right,goe_bilinear_cov hr, + unitRow_dot_unitRow hu,unitRow_dot hu,hu] + have hUT (q : ι) : u⬝ᵥunitRow κ u q=κ*u q := by rw [dotProduct_comm,unitRow_dot hu] + simp only [hUT] + ring + +end SKGap +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Matrix/GOEBlockExpansion.lean b/lean/OAI/Probability/SKGap/Matrix/GOEBlockExpansion.lean new file mode 100644 index 0000000000000000000000000000000000000000..b32b24584be12d4505122f7178230dbbf26882a2 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Matrix/GOEBlockExpansion.lean @@ -0,0 +1,65 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.TruncationGoodSet +import OAI.Probability.SKGap.Matrix.GOERegression +import OAI.Probability.SKGap.Matrix.GOEBilinearCov + +namespace OAI + +section +noncomputable section +namespace SKGap +open Matrix Real +open scoped BigOperators +variable {ι : Type*} [Fintype ι] [DecidableEq ι] + +lemma symmetric_dot_mulVec (W : Matrix ι ι ℝ) (hW : Wᵀ=W) (u : ι → ℝ) (k : ι) : + u⬝ᵥ(W*ᵥPi.single k 1)=(W*ᵥu) k := by + rw [Matrix.mulVec_single_one] + change (∑ i,u i*W i k)=∑ i,W k i*u i + apply Finset.sum_congr rfl + intro i _ + have h := congrArg (fun M : Matrix ι ι ℝ => M k i) hW + simpa only [Matrix.transpose_apply,mul_comm] using congrArg (fun a => a*u i) h + +theorem goeBlockResidual_expand (r κ ell : ℝ) (u : ι → ℝ) + (g : MatrixCoordinates ι → ℝ) : + goeBlockResidual r κ ell u g=goeMatrix r g+ + (κ-1) • (vecMulVec u (goeMatrix r g*ᵥu)+vecMulVec (goeMatrix r g*ᵥu) u)+ + ((ell-2*κ+1)*goeBilinear r u u g) • vecMulVec u u := by + ext i k + simp only [goeBlockResidual,goeBilinear,unitRow,Matrix.mulVec_add,Matrix.mulVec_smul, + dotProduct_add,add_dotProduct,smul_dotProduct,dotProduct_smul,smul_eq_mul, + single_one_dotProduct,Matrix.mulVec_single_one,Matrix.add_apply, + Matrix.smul_apply,vecMulVec_apply] + have h := symmetric_dot_mulVec (goeMatrix r g) (goeMatrix_transpose _ _) u k + simp only [Matrix.mulVec_single_one] at h + rw [h] + change _+_ = _ + dsimp only [Matrix.col, Matrix.transpose_apply] + ring + +theorem goeRegressionCoefficient_block_mean {r v c : ℝ} (hr : 0 ≤ r) (hv : 0 < v) + {u : ι → ℝ} (hu : u⬝ᵥu=1) (z : ι → ℝ) : + (fun i k => (goeRegressionCoefficient r v (c • u)*ᵥz) (i,k))= + vecMulVec u ((r*c/(r*c^2+v)) • (z-(u⬝ᵥz) • u))+ + vecMulVec ((r*c/(r*c^2+v)) • (z-(u⬝ᵥz) • u)) u+ + (2*r*c/(v+2*r*c^2)*(u⬝ᵥz)) • vecMulVec u u := by + have hs : r*c^2+v ≠ 0 := ne_of_gt (add_pos_of_nonneg_of_pos (mul_nonneg hr (sq_nonneg c)) hv) + have hS : v+2*r*c^2 ≠ 0 := ne_of_gt (add_pos_of_pos_of_nonneg hv (by positivity)) + ext i k + change (goeRegressionCoefficient r v (c • u)*ᵥz) (i,k)= + u i*(r*c/(r*c^2+v)*(z k-(u⬝ᵥz)*u k))+ + (r*c/(r*c^2+v)*(z i-(u⬝ᵥz)*u i))*u k+ + (2*r*c/(v+2*r*c^2)*(u⬝ᵥz))*(u i*u k) + rw [goeRegressionCoefficient_mulVec] + simp only [smul_dotProduct,dotProduct_smul,smul_eq_mul,hu,mul_one,Pi.smul_apply] + have hcc : c*c=c^2 := by ring + rw [hcc] + field_simp + ring + +end SKGap +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Matrix/GOEDiagonalSquare.lean b/lean/OAI/Probability/SKGap/Matrix/GOEDiagonalSquare.lean new file mode 100644 index 0000000000000000000000000000000000000000..9ae51444b023ed4651c1e63ba6720fae9dc41712 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Matrix/GOEDiagonalSquare.lean @@ -0,0 +1,136 @@ +import Mathlib +import OAI.Probability.SKGap.Gaussian.GOEGaussian +import OAI.Probability.SKGap.Matrix.WordBiasCutoff + +namespace OAI + +section +noncomputable section +namespace SKGap +open Matrix Real MeasureTheory ProbabilityTheory Set +open scoped BigOperators Matrix.Norms.Frobenius + +lemma gaussian_goe_centered {ι : Type*} [Fintype ι] [DecidableEq ι] (r : ℝ) + (x : EuclideanSpace ℝ (MatrixCoordinates ι)) : + matrixCentered (fun y : EuclideanSpace ℝ (MatrixCoordinates ι)=>goeMatrix r y) x=goeMatrix r x := by + have hm : matrixEntryMean (fun y : EuclideanSpace ℝ (MatrixCoordinates ι)=>goeMatrix r y)=0 := by + ext i k + exact goe_mean_zero r i k + simp only [matrixCentered,hm,sub_zero] + +theorem goe_diagonal_frobenius_tail {j : ℝ} (hj : 0gaussianReal 0 1)) + {g | matrixNormConstant*sqrt (2*j)+1< + ‖Matrix.diagonal (fun i=>goeMatrix (j/n) g i i)‖}≤ + ENNReal.ofReal (exp (-2*(n:ℝ)/(π^2*(sqrt (2*j))^2))) := by + have hs : 0goeMatrix (j/n) x) := by + apply (goeMatrix_L2_lipschitz (j/n)).weaken + change sqrt (2*(j/n))≤(Real.toNNReal (sqrt (2*j)*1/sqrt n):ℝ) + rw [Real.coe_toNNReal _ (by positivity),mul_one,show 2*(j/n)=(2*j)/n by ring,Real.sqrt_div (by positivity)] + have ht := gaussianMatrix_scaled_semnorm_tail hn hs (by norm_num : (0:ℝ)<1) + (by norm_num : (0:ℝ)≤1) (by norm_num : (0:ℝ)≤1) hL false + simpa only [one_pow,mul_one,gaussian_goe_centered,matrixWordSeminorm,Bool.false_eq_true,ite_false, + Matrix.frobenius_norm_diagonal,diagonalSeminorm,diagonalVector] using ht +end SKGap +end +end + +section +noncomputable section +namespace SKGap +open Matrix Real Set MeasureTheory ProbabilityTheory Filter +open scoped BigOperators Matrix.Norms.Frobenius SchwartzMap Topology +variable {ι : Type*} [Fintype ι] [DecidableEq ι] + +def removeDiagonal (M : Matrix ι ι ℝ) : Matrix ι ι ℝ := M-Matrix.diagonal (fun i=>M i i) +lemma matrixWordSeminorm_le (p : Bool) (M : Matrix ι ι ℝ) : matrixWordSeminorm p M≤‖M‖ := by + cases p + · exact diagonalSeminorm_le M + · exact offDiagonalSeminorm_le M + +lemma actualWord_removeDiagonal [Nonempty ι] (f : 𝓢(ℝ,ℂ)) {R j A D : ℝ} + (hR : 0≤R) (hj : 0≤j) (hA : 0≤A) (hD : 0≤D) {a : ι→ℝ} + (ha : ∀ i,0≤a i) (haA : ∀ i,a i≤A) (L : ℕ) (F : List (WordLetter ι)) + (hFL : F.length≤L) (hF : ∀ l∈F,l.bounded D) (M : Matrix ι ι ℝ) : + ‖actualWord f R hR j a 1 F (removeDiagonal M)-actualWord f R hR j a 1 F M‖≤ + (L:ℝ)*(actualWordBound f R j A D)^L*‖Matrix.diagonal (fun i=>M i i)‖ := by + have hB : 1≤actualWordBound f R j A D := by + have hh := path_constants_nonneg f hR hj hA + unfold actualWordBound + linarith + have ht := ((actualWord_bounds f hR hj hA hD ha haA + (show (1:ℝ)∈Icc 0 1 from ⟨zero_le_one,le_rfl⟩) F hF).2).dist_le_mul (removeDiagonal M) M + have hd : ‖removeDiagonal M-M‖=‖Matrix.diagonal (fun i=>M i i)‖ := by + rw [show removeDiagonal M-M= -Matrix.diagonal (fun i=>M i i) by unfold removeDiagonal;abel,norm_neg] + simp only [dist_eq_norm,NNReal.coe_mul,NNReal.coe_natCast,hd] at ht + apply ht.trans + apply mul_le_mul_of_nonneg_right _ (norm_nonneg _) + exact mul_le_mul (by exact_mod_cast hFL) (pow_le_pow_right₀ hB hFL) + (pow_nonneg (zero_le_one.trans hB) _) (Nat.cast_nonneg _) + +theorem actual_word_simultaneous_zerodiag_of_cutoff {j A D : ℝ} (hj : 0gaussianReal 0 1)) + {g | ∃ (a : Fin n→ℝ) (F : List (WordLetter (Fin n))), + (∀ i,a i∈Icc 0 A) ∧ F.length≤L ∧ (∀ l∈F,l.bounded D) ∧ inverseCount F≤1 ∧ + C< matrixWordSeminorm p + (actualWord f (2*sqrt j+1+1) hR j a 1 F (removeDiagonal (goeMatrix (j/n) g))- + Matrix.diagonal (wordPrediction j a 1 F))} ≤ + (wordPatternSet L L).card*ENNReal.ofReal (3*exp (-(n:ℝ)))+ + ENNReal.ofReal (exp (-2*(n:ℝ)/(π^2*(sqrt (2*j))^2))) := by + obtain ⟨C,N,hC,hN,hw⟩ := actual_word_simultaneous_prediction_of_cutoff hj hA hs hD hAD L f hf hR + let R := 2*sqrt j+1+1 + let B := actualWordBound f R j A D + let T := matrixNormConstant*sqrt (2*j)+1 + have hD0 := zero_le_one.trans hD + have hB : 0≤B := (actualWordBound_pos f hR hj.le hA.le hD0).le + have hT : 0≤T := by + have hc := matrixNormConstant_bounds.1 + dsimp [T] + positivity + let K := (L:ℝ)*B^L*T + have hK : 0≤K := by dsimp [K];positivity + refine ⟨C+K,N,by linarith,hN,?_⟩ + intro n hn p + have hn0 : 0goeMatrix (j/n) g i i)‖} + have hsub : {g | ∃ (a : Fin n→ℝ) (F : List (WordLetter (Fin n))), + (∀ i,a i∈Icc 0 A) ∧ F.length≤L ∧ (∀ l∈F,l.bounded D) ∧ inverseCount F≤1 ∧ + C+K < matrixWordSeminorm p (actualWord f R hR j a 1 F (removeDiagonal (goeMatrix (j/n) g))- + Matrix.diagonal (wordPrediction j a 1 F))}⊆E∪V := by + intro g hg + by_contra hh + obtain ⟨a,F,ha,hFL,hF,hI,hbad⟩ := hg + have hd : ‖Matrix.diagonal (fun i=>goeMatrix (j/n) g i i)‖≤T := by + by_contra hd + exact hh (Or.inr (lt_of_not_ge hd)) + have he : matrixWordSeminorm p (actualWord f R hR j a 1 F (goeMatrix (j/n) g)-Matrix.diagonal (wordPrediction j a 1 F))≤C := by + by_contra he + exact hh (Or.inl ⟨a,F,ha,hFL,hF,hI,lt_of_not_ge he⟩) + have hp := (matrixWordSeminorm_le p _).trans (actualWord_removeDiagonal f hR hj.le hA.le hD0 + (fun i=>(ha i).1) (fun i=>(ha i).2) L F hFL hF (goeMatrix (j/n) g)) + have hp' : matrixWordSeminorm p + (actualWord f R hR j a 1 F (removeDiagonal (goeMatrix (j/n) g))-actualWord f R hR j a 1 F (goeMatrix (j/n) g))≤K := + hp.trans (mul_le_mul_of_nonneg_left hd (mul_nonneg (Nat.cast_nonneg _) (pow_nonneg hB _))) + have hac := matrixWordSeminorm_add p + (actualWord f R hR j a 1 F (removeDiagonal (goeMatrix (j/n) g))-actualWord f R hR j a 1 F (goeMatrix (j/n) g)) + (actualWord f R hR j a 1 F (goeMatrix (j/n) g)-Matrix.diagonal (wordPrediction j a 1 F)) + rw [sub_add_sub_cancel] at hac + linarith + exact (measure_mono hsub).trans ((measure_union_le E V).trans + (add_le_add (hw n hn p) (goe_diagonal_frobenius_tail hj (Nat.succ_le_iff.mpr hn0)))) +end SKGap +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Matrix/GOEGlobalEvents.lean b/lean/OAI/Probability/SKGap/Matrix/GOEGlobalEvents.lean new file mode 100644 index 0000000000000000000000000000000000000000..c1b017afd8265711e2366f3624b9331978b5c66b --- /dev/null +++ b/lean/OAI/Probability/SKGap/Matrix/GOEGlobalEvents.lean @@ -0,0 +1,62 @@ +import Mathlib +import OAI.Probability.SKGap.Gaussian.GOERowTail + +namespace OAI + +section +noncomputable section +namespace SKGap +open MeasureTheory ProbabilityTheory Matrix Real Set +open scoped BigOperators +variable {n : ℕ} + +lemma coupling_goe_all_rows_tail [NeZero n] {j t : ℝ} (hj : 0 < j) : + (gaussianCoordinates (MatrixCoordinates (Fin n))).real + {g | ∃ i : Fin n,t < ∑ k,coupling (goeDisorder (j/(n:ℝ)) g) i k^2} ≤ + (n:ℝ)*exp (-(n:ℝ)*(t/(4*j)-log 2)) := by + have hn : (0:ℝ) < n := by exact_mod_cast NeZero.pos n + have he : {g : MatrixCoordinates (Fin n)→ℝ | ∃ i : Fin n,t < ∑ k,coupling (goeDisorder (j/(n:ℝ)) g) i k^2}= + ⋃ i : Fin n,{g | t < ∑ k,coupling (goeDisorder (j/(n:ℝ)) g) i k^2} := by ext g;simp + rw [he] + apply (measureReal_iUnion_fintype_le _).trans + have hb (i : Fin n) := coupling_goe_row_tail (div_pos hj hn) i Finset.univ t + simp only [Finset.card_univ,Fintype.card_fin] at hb + apply (Finset.sum_le_sum (fun i _=>hb i)).trans_eq + simp only [Finset.sum_const,Finset.card_univ,Fintype.card_fin,nsmul_eq_mul] + congr 2 + field_simp + ring + +lemma coupling_goe_max_entry_tail [NeZero n] {j d : ℝ} (hj : 0 < j) (hd : 0 ≤ d) : + (gaussianCoordinates (MatrixCoordinates (Fin n))).real + {g | ∃ i k : Fin n,d < |coupling (goeDisorder (j/(n:ℝ)) g) i k|} ≤ + 2*(n:ℝ)^2*exp (-(n:ℝ)*d^2/(4*j)) := by + have hn : (0:ℝ) < n := by exact_mod_cast NeZero.pos n + have hsingle (i k : Fin n) : + (gaussianCoordinates (MatrixCoordinates (Fin n))).real + {g | d < |coupling (goeDisorder (j/(n:ℝ)) g) i k|} ≤ + 2*exp (-(n:ℝ)*d^2/(4*j)) := by + have he : {g : MatrixCoordinates (Fin n)→ℝ | d < |coupling (goeDisorder (j/(n:ℝ)) g) i k|}= + {g | d^2 < ∑ l∈({k} : Finset (Fin n)),coupling (goeDisorder (j/(n:ℝ)) g) i l^2} := by + ext g + simp only [Finset.sum_singleton,Set.mem_ofPred_eq] + simpa only [sq_abs] using (sq_lt_sq₀ hd (abs_nonneg (coupling (goeDisorder (j/(n:ℝ)) g) i k))).symm + rw [he] + apply (coupling_goe_row_tail (div_pos hj hn) i {k} (d^2)).trans_eq + simp only [Finset.card_singleton,Nat.cast_one,one_mul,exp_add,exp_log (by norm_num : (0:ℝ) < 2)] + rw [mul_comm] + congr 2 + field_simp + have he : {g : MatrixCoordinates (Fin n)→ℝ | ∃ i k : Fin n,d < |coupling (goeDisorder (j/(n:ℝ)) g) i k|}= + ⋃ i : Fin n,⋃ k : Fin n,{g | d < |coupling (goeDisorder (j/(n:ℝ)) g) i k|} := by ext g;simp + rw [he] + apply (measureReal_iUnion_fintype_le _).trans + apply (Finset.sum_le_sum (fun i _=>(measureReal_iUnion_fintype_le _).trans (Finset.sum_le_sum (fun k _=>hsingle i k)))).trans_eq + simp only [Finset.sum_const,Finset.card_univ,Fintype.card_fin,nsmul_eq_mul] + ring +end SKGap + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Matrix/GOERegression.lean b/lean/OAI/Probability/SKGap/Matrix/GOERegression.lean new file mode 100644 index 0000000000000000000000000000000000000000..ae6269309f878e11f954ee34e5081e4d5c672aaf --- /dev/null +++ b/lean/OAI/Probability/SKGap/Matrix/GOERegression.lean @@ -0,0 +1,164 @@ +import Mathlib +import OAI.Probability.SKGap.Gaussian.GaussianLinearDensity +import OAI.Probability.SKGap.Posterior.GOEObservation +import OAI.Probability.SKGap.Gaussian.GaussianDisintegration + +namespace OAI + +section +noncomputable section +namespace SKGap +open MeasureTheory ProbabilityTheory Matrix Real +open scoped BigOperators ENNReal +variable {ι : Type*} [Fintype ι] [DecidableEq ι] + +def goeCrossCovariance (r : ℝ) (m : ι → ℝ) : Matrix (ι × ι) ι ℝ := + fun p l => r*((if p.1=l then m p.2 else 0)+(if p.2=l then m p.1 else 0)) + +def goeRegressionCoefficient (r v : ℝ) (m : ι → ℝ) : Matrix (ι × ι) ι ℝ := + goeCrossCovariance r m * rankOneCovarianceInverse (r*(m⬝ᵥm)+v) r m + +lemma goeCrossCovariance_mulVec (r : ℝ) (m y : ι → ℝ) (i k : ι) : + (goeCrossCovariance r m*ᵥy) (i,k)=r*(m k*y i+m i*y k) := by + simp [goeCrossCovariance,mulVec,dotProduct,add_mul,mul_add,Finset.sum_add_distrib, + mul_assoc] + +lemma goeRegressionCoefficient_mulVec (r v : ℝ) (m y : ι → ℝ) (i k : ι) : + (goeRegressionCoefficient r v m*ᵥy) (i,k) = + r/(r*(m⬝ᵥm)+v)*(m k*y i+m i*y k)- + (2*r^2/((r*(m⬝ᵥm)+v)*(v+2*r*(m⬝ᵥm))))*(m⬝ᵥy)*m i*m k := by + rw [goeRegressionCoefficient,← Matrix.mulVec_mulVec,goeCrossCovariance_mulVec] + simp only [rankOneCovarianceInverse_mulVec] + have hden : r*(m⬝ᵥm)+v+r*(m⬝ᵥm)=v+2*r*(m⬝ᵥm) := by ring + rw [hden] + ring + +lemma goe_observation_cov_matrix {r v : ℝ} (hr : 0 ≤ r) (hv : 0 ≤ v) (m : ι → ℝ) : + (fun i l => cov[fun g => goeObservation r v m g i,fun g => goeObservation r v m g l; + gaussianCoordinates (MatrixCoordinates ι)])=rankOneCovariance (r*(m⬝ᵥm)+v) r m := by + ext i l + rw [goe_observation_cov hr hv] + simp only [rankOneCovariance,Matrix.add_apply,Matrix.smul_apply,smul_eq_mul, + Matrix.one_apply,Matrix.vecMulVec_apply,dotProduct,← pow_two] + ring + +lemma goe_regression_covariance {r v : ℝ} (hr : 0 ≤ r) (hv : 0 < v) (m : ι → ℝ) + (p : ι × ι) (l : ι) : + cov[fun g => goeMatrix r g p.1 p.2,fun g => goeObservation r v m g l; + gaussianCoordinates (MatrixCoordinates ι)] = + ∑ k, goeRegressionCoefficient r v m p k * + cov[fun g => goeObservation r v m g k,fun g => goeObservation r v m g l; + gaussianCoordinates (MatrixCoordinates ι)] := by + have hq : 0 ≤ m⬝ᵥm := Finset.sum_nonneg (fun k _ => mul_self_nonneg (m k)) + have hs : 0 < r*(m⬝ᵥm)+v := add_pos_of_nonneg_of_pos (mul_nonneg hr hq) hv + have hS : 0 < r*(m⬝ᵥm)+v+r*(m⬝ᵥm) := add_pos_of_pos_of_nonneg hs (mul_nonneg hr hq) + have hmat := goe_observation_cov_matrix hr hv.le m + rw [goe_entry_observation_cov hr] + change goeCrossCovariance r m p l = + (goeRegressionCoefficient r v m * (show Matrix ι ι ℝ from fun k l => cov[fun g => goeObservation r v m g k, + fun g => goeObservation r v m g l;gaussianCoordinates (MatrixCoordinates ι)])) p l + rw [hmat,goeRegressionCoefficient,Matrix.mul_assoc, + rankOneCovarianceInverse_mul _ _ _ hs.ne' hS.ne',Matrix.mul_one] + +theorem goe_regression_lintegral {r v : ℝ} (hr : 0 ≤ r) (hv : 0 < v) (m : ι → ℝ) + (F : ((ι × ι) → ℝ) × (ι → ℝ) → ℝ≥0∞) (hF : Measurable F) : + (∫⁻ g, F ((fun p => goeMatrix r g p.1 p.2),goeObservation r v m g) ∂gaussianCoordinates (MatrixCoordinates ι)) = + ∫⁻ y, ∫⁻ R, F (R+goeRegressionCoefficient r v m*ᵥy,y) + ∂(gaussianCoordinates (MatrixCoordinates ι)).map (fun g => + (fun p => goeMatrix r g p.1 p.2)-goeRegressionCoefficient r v m*ᵥgoeObservation r v m g) + ∂(gaussianCoordinates (MatrixCoordinates ι)).map (goeObservation r v m) := + GaussianRegression.regression_lintegral (goe_observation_joint_gaussian r v m) + (goeRegressionCoefficient r v m) (goe_regression_covariance hr hv m) F hF + +end SKGap +end +end + +section +noncomputable section +namespace SKGap +open MeasureTheory ProbabilityTheory Matrix Real GaussianDensity +open scoped BigOperators ENNReal NNReal +variable {ι : Type*} [Fintype ι] [DecidableEq ι] + +omit [DecidableEq ι] in +lemma radialDensity_pos {a : ℝ} (ha : 0 < a) (x : ι → ℝ) : 0 < radialDensity a x := by + unfold radialDensity + positivity + +omit [DecidableEq ι] in +lemma radialDensity_le {a : ℝ} (ha : 0 < a) (x : ι → ℝ) : + radialDensity a x ≤ ((sqrt (2*Real.pi)*a)⁻¹)^(Fintype.card ι) := by + unfold radialDensity + apply mul_le_of_le_one_right (by positivity) + apply exp_le_one_iff.mpr + have hx : 0 ≤ x⬝ᵥx := Finset.sum_nonneg (fun i _ => mul_self_nonneg (x i)) + exact div_nonpos_of_nonpos_of_nonneg (neg_nonpos.mpr hx) (by positivity) + +omit [DecidableEq ι] in +lemma continuous_radialDensity (a : ℝ) : Continuous (radialDensity (ι := ι) a) := by + unfold radialDensity dotProduct + fun_prop + +omit [DecidableEq ι] in +lemma continuous_rankOneDensity (s r : ℝ) (m : ι → ℝ) : + Continuous (rankOneDensity s r m) := by + unfold rankOneDensity radialDensity dotProduct + fun_prop + +omit [DecidableEq ι] in +lemma rankOneDensity_pos {s r : ℝ} (hs : 0 < s) (hr : 0 ≤ r) (m x : ι → ℝ) : + 0 < rankOneDensity s r m x := by + have hq : 0 ≤ m⬝ᵥm := Finset.sum_nonneg (fun i _ => mul_self_nonneg (m i)) + have hS : 0 < s+r*(m⬝ᵥm) := add_pos_of_pos_of_nonneg hs (mul_nonneg hr hq) + unfold rankOneDensity + exact mul_pos (mul_pos (sqrt_pos.mpr (div_pos hs hS)) (radialDensity_pos (sqrt_pos.mpr hs) x)) (exp_pos _) + +theorem goe_observation_density [Nonempty ι] {r v : ℝ} (hr : 0 ≤ r) (hv : 0 < v) (m : ι → ℝ) : + (gaussianCoordinates (MatrixCoordinates ι)).map (goeObservation r v m)= + (volume : Measure (ι → ℝ)).withDensity (fun x => + ENNReal.ofReal (rankOneDensity (r*(m⬝ᵥm)+v) r m x)) := by + have hq : 0 ≤ m⬝ᵥm := Finset.sum_nonneg (fun i _ => mul_self_nonneg (m i)) + apply gaussian_rankOne_covariance_density (goe_observation_joint_gaussian r v m).snd + (add_pos_of_nonneg_of_pos (mul_nonneg hr hq) hv) hr m (goe_observation_mean r v m) + intro i k + exact congrFun (congrFun (goe_observation_cov_matrix hr hv.le m) i) k + +lemma goe_noise_density [Nonempty ι] {r v : ℝ} (hr : 0 ≤ r) (hv : 0 < v) : + (gaussianCoordinates (MatrixCoordinates ι)).map (goeObservation r v 0)= + (volume : Measure (ι → ℝ)).withDensity (fun x => ENNReal.ofReal (radialDensity (sqrt v) x)) := by + rw [goe_observation_density hr hv] + congr 1 + ext x + simp [rankOneDensity,hv.ne'] + +lemma goe_noise_independent (r v : ℝ) : + IndepFun (fun g (p : ι × ι) => goeMatrix r g p.1 p.2) (goeObservation r v 0) + (gaussianCoordinates (MatrixCoordinates ι)) := by + apply (goe_observation_joint_gaussian r v 0).indepFun_of_covariance_eval + intro p i + have he (g : MatrixCoordinates ι → ℝ) : goeObservation r v 0 g i=sqrt v*g (.inr i) := by + simp [goeObservation] + simp only [he,covariance_const_mul_right,goe_noise_cov,mul_zero] + +lemma goe_joint_noise_law (r v : ℝ) (m : ι → ℝ) : + (((gaussianCoordinates (MatrixCoordinates ι)).map (fun g (p : ι × ι) => goeMatrix r g p.1 p.2)).prod + ((gaussianCoordinates (MatrixCoordinates ι)).map (goeObservation r v 0))).map + (fun z : ((ι × ι) → ℝ) × (ι → ℝ) => (z.1,(fun i => ∑ k, z.1 (i,k)*m k)+z.2)) = + (gaussianCoordinates (MatrixCoordinates ι)).map (fun g => + ((fun p : ι × ι => goeMatrix r g p.1 p.2),goeObservation r v m g)) := by + have hXY := goe_observation_joint_gaussian (ι := ι) r v 0 + rw [← (goe_noise_independent (ι := ι) r v).map_prod_eq_prod_map_map hXY.fst.aemeasurable hXY.snd.aemeasurable, + AEMeasurable.map_map_of_aemeasurable (by fun_prop) hXY.aemeasurable] + apply congrArg (fun f => (gaussianCoordinates (MatrixCoordinates ι)).map f) + funext g + apply Prod.ext + · rfl + ext i + simp [goeObservation,mulVec,dotProduct] + +end SKGap +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Matrix/GOEResidualCov.lean b/lean/OAI/Probability/SKGap/Matrix/GOEResidualCov.lean new file mode 100644 index 0000000000000000000000000000000000000000..3896bb095331e75221b91b76c5c3392012ea90db --- /dev/null +++ b/lean/OAI/Probability/SKGap/Matrix/GOEResidualCov.lean @@ -0,0 +1,134 @@ +import Mathlib +import OAI.Probability.SKGap.Matrix.GOERegression +import OAI.Probability.SKGap.Matrix.GOEBilinearCov +import OAI.Probability.SKGap.Gaussian.RegressionMoments + +namespace OAI + +section +noncomputable section +namespace SKGap +open MeasureTheory ProbabilityTheory Matrix Real +open scoped BigOperators ENNReal +variable {ι : Type*} [Fintype ι] [DecidableEq ι] + +def goeRegressionResidual (r v : ℝ) (m : ι → ℝ) (g : MatrixCoordinates ι → ℝ) : (ι × ι) → ℝ := + (fun p => goeMatrix r g p.1 p.2)-goeRegressionCoefficient r v m*ᵥgoeObservation r v m g + +lemma goe_cross_row_dot (r : ℝ) (m : ι → ℝ) (l a : ι) : + m⬝ᵥ(fun b => goeCrossCovariance r m (l,a) b)=2*r*m l*m a := by + simp only [dotProduct,goeCrossCovariance,mul_add,Finset.sum_add_distrib] + simp [mul_ite,mul_assoc] + ring + +lemma goeRegressionResidual_cov {r v : ℝ} (hr : 0 ≤ r) (hv : 0 < v) + (m : ι → ℝ) (i k l a : ι) : + cov[fun g => goeRegressionResidual r v m g (i,k), + fun g => goeRegressionResidual r v m g (l,a);gaussianCoordinates (MatrixCoordinates ι)] = + r*((if i=l then 1 else 0)*(if k=a then 1 else 0)+(if i=a then 1 else 0)*(if k=l then 1 else 0))- + r^2/(r*(m⬝ᵥm)+v)*((if i=l then 1 else 0)*m k*m a+(if k=a then 1 else 0)*m i*m l+ + (if i=a then 1 else 0)*m k*m l+(if k=l then 1 else 0)*m i*m a)+ + 4*r^3/((r*(m⬝ᵥm)+v)*(v+2*r*(m⬝ᵥm)))*m i*m k*m l*m a := by + unfold goeRegressionResidual + rw [GaussianRegression.residual_covariance + (goe_observation_joint_gaussian r v m) (goeRegressionCoefficient r v m) + (goe_regression_covariance hr hv m)] + have hc (b : ι) : cov[fun g => goeObservation r v m g b, + fun g => goeMatrix r g l a;gaussianCoordinates (MatrixCoordinates ι)] = + goeCrossCovariance r m (l,a) b := by + rw [covariance_comm,goe_entry_observation_cov hr] + rfl + simp only [hc] + change cov[fun g => goeMatrix r g i k,fun g => goeMatrix r g l a;_] - + (goeRegressionCoefficient r v m*ᵥ(fun b => goeCrossCovariance r m (l,a) b)) (i,k)=_ + rw [goe_entry_cov hr,goeRegressionCoefficient_mulVec,goe_cross_row_dot] + have he (p q : ι) (x : ℝ) : (if p=q then x else 0)=(if q=p then 1 else 0)*x := by + by_cases hpq : p=q <;> simp [hpq,Ne.symm] + simp only [goeCrossCovariance] + rw [he l i (m a),he a i (m l),he l k (m a),he a k (m l)] + ring + +lemma goeRegressionResidual_gaussian (r v : ℝ) (m : ι → ℝ) : + HasGaussianLaw (goeRegressionResidual r v m) (gaussianCoordinates (MatrixCoordinates ι)) := + (GaussianRegression.residual_joint_gaussian (goe_observation_joint_gaussian r v m) + (goeRegressionCoefficient r v m)).fst + +lemma goeRegressionResidual_mean (r v : ℝ) (m : ι → ℝ) (p : ι × ι) : + (∫ g, goeRegressionResidual r v m g p ∂gaussianCoordinates (MatrixCoordinates ι))=0 := by + exact GaussianRegression.residual_mean_zero (goe_observation_joint_gaussian r v m) + (goeRegressionCoefficient r v m) (fun p => goe_mean_zero r p.1 p.2) + (goe_observation_mean r v m) p + +end SKGap +end +end + +section +noncomputable section +namespace SKGap +open MeasureTheory ProbabilityTheory Matrix Real +open scoped BigOperators ENNReal +variable {ι : Type*} [Fintype ι] [DecidableEq ι] + +def blockCoefficient (κ ell : ℝ) (u : ι → ℝ) : Matrix (ι × ι) (ι × ι) ℝ := + fun p q => unitRow κ u p.1 q.1*unitRow κ u p.2 q.2+ + ((ell-κ^2)*u p.1*u p.2)*(u q.1*u q.2) + +lemma blockCoefficient_sample (r κ ell : ℝ) (u : ι → ℝ) (g : MatrixCoordinates ι → ℝ) : + blockCoefficient κ ell u*ᵥ(fun p => goeMatrix r g p.1 p.2)= + fun p => goeBlockResidual r κ ell u g p.1 p.2 := by + ext p + simp only [mulVec,dotProduct,blockCoefficient,goeBlockResidual,goeBilinear, + Fintype.sum_prod_type,add_mul,Finset.sum_add_distrib,Finset.mul_sum] + congr 1 <;> apply Finset.sum_congr rfl <;> intro i _ <;> + apply Finset.sum_congr rfl <;> intro k _ <;> ring + +lemma goeBlockResidual_gaussian (r κ ell : ℝ) (u : ι → ℝ) : + HasGaussianLaw (fun g (p : ι × ι) => goeBlockResidual r κ ell u g p.1 p.2) + (gaussianCoordinates (MatrixCoordinates ι)) := by + exact ((goe_matrix_gaussian (ι := ι) r).map_fun + (GaussianRegression.matrixCLM (blockCoefficient κ ell u))).congr + (Filter.Eventually.of_forall (blockCoefficient_sample r κ ell u)) + +lemma goeBlockResidual_mean (r κ ell : ℝ) (u : ι → ℝ) (p : ι × ι) : + (∫ g, goeBlockResidual r κ ell u g p.1 p.2 ∂gaussianCoordinates (MatrixCoordinates ι))=0 := by + have he (g : MatrixCoordinates ι → ℝ) : goeBlockResidual r κ ell u g p.1 p.2= + (blockCoefficient κ ell u*ᵥ(fun q => goeMatrix r g q.1 q.2)) p := + (congrFun (blockCoefficient_sample r κ ell u g) p).symm + simp only [he,mulVec,dotProduct] + rw [integral_finsetSum _ (fun q _ => ((goe_matrix_gaussian r).eval q).integrable.const_mul _)] + simp only [integral_const_mul,goe_mean_zero,mul_zero,Finset.sum_const_zero] + +lemma block_regression_cov_algebra {r v c : ℝ} (hr : 0 ≤ r) (hv : 0 < v) + {u : ι → ℝ} (hu : u⬝ᵥu=1) (i k l a : ι) : + cov[fun g => goeRegressionResidual r v (c • u) g (i,k), + fun g => goeRegressionResidual r v (c • u) g (l,a);gaussianCoordinates (MatrixCoordinates ι)] = + cov[fun g => goeBlockResidual r (sqrt (v/(r*c^2+v))) (sqrt (v/(v+2*r*c^2))) u g i k, + fun g => goeBlockResidual r (sqrt (v/(r*c^2+v))) (sqrt (v/(v+2*r*c^2))) u g l a; + gaussianCoordinates (MatrixCoordinates ι)] := by + have hs : 0 < r*c^2+v := add_pos_of_nonneg_of_pos (mul_nonneg hr (sq_nonneg c)) hv + have hS : 0 < v+2*r*c^2 := add_pos_of_pos_of_nonneg hv (by positivity) + rw [goeRegressionResidual_cov hr hv,goeBlockResidual_cov hr hu] + simp only [smul_dotProduct,dotProduct_smul,smul_eq_mul,hu,mul_one,Pi.smul_apply] + have hq : c*c=c^2 := by ring + rw [hq,sq_sqrt (div_nonneg hv.le hs.le),sq_sqrt (div_nonneg hv.le hS.le)] + field_simp + ring + +theorem goe_regression_residual_law {r v c : ℝ} (hr : 0 ≤ r) (hv : 0 < v) + {u : ι → ℝ} (hu : u⬝ᵥu=1) : + (gaussianCoordinates (MatrixCoordinates ι)).map (goeRegressionResidual r v (c • u))= + (gaussianCoordinates (MatrixCoordinates ι)).map (fun g p => + goeBlockResidual r (sqrt (v/(r*c^2+v))) (sqrt (v/(v+2*r*c^2))) u g p.1 p.2) := by + apply GaussianRegression.law_eq_of_mean_covariance (goeRegressionResidual_gaussian r v (c • u)) + (goeBlockResidual_gaussian r _ _ u) + · intro p + rw [goeRegressionResidual_mean,goeBlockResidual_mean] + · intro p q + exact block_regression_cov_algebra hr hv hu p.1 p.2 q.1 q.2 + +end SKGap +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Matrix/GOERowLaw.lean b/lean/OAI/Probability/SKGap/Matrix/GOERowLaw.lean new file mode 100644 index 0000000000000000000000000000000000000000..52f9333ece35387758c1c570197fa3433ee20890 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Matrix/GOERowLaw.lean @@ -0,0 +1,52 @@ +import Mathlib +import OAI.Probability.SKGap.Gaussian.GOEGaussian + +namespace OAI + +section +noncomputable section +namespace SKGap +open MeasureTheory ProbabilityTheory Matrix Real +open scoped BigOperators +variable {ι κ : Type*} [Fintype ι] [DecidableEq ι] [Fintype κ] [DecidableEq κ] + +omit [DecidableEq κ] in +lemma goe_row_gaussian (r : ℝ) (i : ι) (e : κ→ι) : + HasGaussianLaw (fun g : MatrixCoordinates ι→ℝ=>fun k=>goeMatrix r g i (e k)) + (gaussianCoordinates (MatrixCoordinates ι)) := by + exact (goe_matrix_gaussian r).map_fun + (ContinuousLinearMap.pi (fun k=>ContinuousLinearMap.proj (i,e k)) : + ((ι × ι)→ℝ) →L[ℝ] (κ→ℝ)) + +omit [Fintype κ] in +lemma goe_row_cov {r : ℝ} (hr : 0 ≤ r) (i : ι) (e : κ ↪ ι) + (he : ∀ k,e k≠i) (k l : κ) : + cov[fun g=>goeMatrix r g i (e k),fun g=>goeMatrix r g i (e l); + gaussianCoordinates (MatrixCoordinates ι)]=if k=l then r else 0 := by + classical + rw [goe_entry_cov hr] + have hi : ∀ k,¬i=e k := fun k=>Ne.symm (he k) + simp only [ite_true,hi,he,e.injective.eq_iff] + simp only [ite_false,mul_zero,add_zero] + split_ifs <;> simp_all + +lemma goe_row_hasLaw {r : ℝ} (hr : 0 ≤ r) (i : ι) (e : κ ↪ ι) + (he : ∀ k,e k≠i) : + HasLaw (fun g : MatrixCoordinates ι→ℝ=>fun k=>goeMatrix r g i (e k)) + (Measure.pi (fun _ : κ=>gaussianReal 0 (Real.toNNReal r))) + (gaussianCoordinates (MatrixCoordinates ι)) := by + classical + have hg := goe_row_gaussian r i e + have hl (k : κ) : HasLaw (fun g=>goeMatrix r g i (e k)) + (gaussianReal 0 (Real.toNNReal r)) (gaussianCoordinates (MatrixCoordinates ι)) := by + refine ⟨(hg.eval k).aemeasurable,?_⟩ + rw [(hg.eval k).map_eq_gaussianReal,goe_mean_zero, + ← covariance_self (hg.eval k).aemeasurable,goe_row_cov hr i e he,ite_eq_left rfl] + exact iIndepFun.hasLaw_pi hl (hg.iIndepFun_of_covariance_eq_zero + (fun k l h=>by rw [goe_row_cov hr i e he,ite_eq_right h])) +end SKGap + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Matrix/GOESparse.lean b/lean/OAI/Probability/SKGap/Matrix/GOESparse.lean new file mode 100644 index 0000000000000000000000000000000000000000..9a74a917206f105d0897ae9543d731fa4c9ca462 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Matrix/GOESparse.lean @@ -0,0 +1,139 @@ +import Mathlib +import OAI.Probability.SKGap.Matrix.GOESubmatrix +import OAI.Probability.SKGap.Entropy.SparseSubsetEntropy + +namespace OAI + +section +noncomputable section +namespace SKGap +open MeasureTheory ProbabilityTheory Matrix Real Set +open scoped BigOperators RealInnerProductSpace +variable {ι : Type*} [Fintype ι] [DecidableEq ι] + +def principalOperatorNorm (M : Matrix ι ι ℝ) (S : Finset ι) : ℝ := + ‖matrixOperator (M.submatrix (fun i : S=>i.1) (fun i : S=>i.1))‖ + +omit [Fintype ι] in +lemma principalOperatorNorm_empty (M : Matrix ι ι ℝ) : principalOperatorNorm M ∅=0 := by + unfold principalOperatorNorm + have hz : matrixOperator (M.submatrix (fun i : (∅ : Finset ι)=>i.1) (fun i : (∅ : Finset ι)=>i.1))=0 := + Subsingleton.elim _ _ + rw [hz,norm_zero] + +lemma goe_sparse_one_tail [Nonempty ι] (S : Finset ι) {j α ε : ℝ} + (hj : 0 < j) (_hα : 0 ≤ α) (hε : 0 < ε) (hS : (S.card:ℝ) ≤ α*(Fintype.card ι:ℝ)) + (hedge : 2*sqrt (j*α) ≤ ε/2) : + (gaussianCoordinates (MatrixCoordinates ι)).real + {g | ε < principalOperatorNorm (goeMatrix (j/(Fintype.card ι:ℝ)) g) S} ≤ + 2*exp (-(Fintype.card ι:ℝ)*ε^2/(4*π^2*j)) := by + by_cases hne : S.Nonempty + · let : Nonempty S := Finset.Nonempty.to_subtype hne + have hn : (0:ℝ) < Fintype.card ι := Nat.cast_pos.mpr Fintype.card_pos + let e : S ↪ ι := ⟨Subtype.val,Subtype.val_injective⟩ + have hsqrt : 2*sqrt (j/(Fintype.card ι:ℝ)*(Fintype.card S:ℝ)) ≤ ε/2 := by + apply le_trans _ hedge + apply mul_le_mul_of_nonneg_left (sqrt_le_sqrt _) (by norm_num) + rw [Fintype.card_coe] + have hm := mul_le_mul_of_nonneg_left hS hj.le + rw [div_mul_eq_mul_div] + apply (div_le_iff₀ hn).mpr + convert hm using 1; ring + have ht := goe_restricted_norm_tail e (div_pos hj hn) (by positivity : 0 ≤ ε/2) + apply (measureReal_mono (μ:=gaussianCoordinates (MatrixCoordinates ι)) ?_).trans + (ht.trans_eq ?_) + · intro g hg + change ε < principalOperatorNorm (goeMatrix (j/(Fintype.card ι:ℝ)) g) S at hg + change 2*sqrt (j/(Fintype.card ι:ℝ)*(Fintype.card S:ℝ))+ε/2 < + principalOperatorNorm (goeMatrix (j/(Fintype.card ι:ℝ)) g) S + linarith only [hsqrt,hg] + · congr 2 + field_simp + ring + · have he : S=∅ := Finset.not_nonempty_iff_eq_empty.mp hne + subst S + simp only [principalOperatorNorm_empty,not_lt_of_ge hε.le,Set.ofPred_false,measureReal_empty] + positivity + +theorem goe_sparse_union_tail [Nonempty ι] {j α ε l : ℝ} + (hj : 0 < j) (hα : 0 ≤ α) (hε : 0 < ε) (hl : 0 ≤ l) + (hedge : 2*sqrt (j*α) ≤ ε/2) : + (gaussianCoordinates (MatrixCoordinates ι)).real + {g | ∃ S : Finset ι,(S.card:ℝ) ≤ α*(Fintype.card ι:ℝ) ∧ + ε < principalOperatorNorm (goeMatrix (j/(Fintype.card ι:ℝ)) g) S} ≤ + 2*exp (-(Fintype.card ι:ℝ)*(ε^2/(4*π^2*j)-(l*α+log (1+exp (-l))))) := by + classical + have he : {g : MatrixCoordinates ι→ℝ | ∃ S : Finset ι,(S.card:ℝ) ≤ α*(Fintype.card ι:ℝ) ∧ + ε < principalOperatorNorm (goeMatrix (j/(Fintype.card ι:ℝ)) g) S} = + ⋃ S∈smallSupports (ι:=ι) α,{g | ε < principalOperatorNorm (goeMatrix (j/(Fintype.card ι:ℝ)) g) S} := by + ext g + simp [smallSupports] + rw [he] + apply sparse_union_bound _ _ hl (by norm_num : (0:ℝ) ≤ 2) + intro S hS + have hc := (Finset.mem_filter.mp hS).2 + convert goe_sparse_one_tail S hj hα hε hc hedge using 1 + congr 2 + ring +end SKGap + +end +end + +section +noncomputable section +namespace SKGap +open Matrix Real +open scoped BigOperators RealInnerProductSpace Matrix.Norms.L2Operator +variable {ι : Type*} [Fintype ι] [DecidableEq ι] + +omit [DecidableEq ι] in +lemma supported_quad_eq (M : Matrix ι ι ℝ) (S : Finset ι) + (w : EuclideanSpace ℝ ι) (hw : ∀ i,i ∉ S → w i=0) : + matrixQuad M w=matrixQuad (M.submatrix (fun i : S=>i.1) (fun i : S=>i.1)) + (WithLp.toLp 2 (fun i : S=>w i.1)) := by + change (∑ i,∑ k,w i*M i k*w k)=(∑ i : S,∑ k : S,w i.1*M i.1 k.1*w k.1) + calc + _ = ∑ i∈S,∑ k,w i*M i k*w k := (Finset.sum_subset (Finset.subset_univ S) (by + intro i _ hi + simp [hw i hi])).symm + _ = ∑ i : S,∑ k,w i.1*M i.1 k*w k := + (Finset.sum_coe_sort S (fun i=>∑ k,w i*M i k*w k)).symm + _ = _ := by + apply Finset.sum_congr rfl + intro i _ + rw [Finset.sum_coe_sort S (fun k=>w i.1*M i.1 k*w k)] + exact (Finset.sum_subset (Finset.subset_univ S) (by + intro k _ hk + simp [hw k hk])).symm + +omit [DecidableEq ι] in +lemma supported_norm_sq_eq (S : Finset ι) (w : EuclideanSpace ℝ ι) + (hw : ∀ i,i ∉ S → w i=0) : + ‖WithLp.toLp 2 (fun i : S=>w i.1)‖^2=‖w‖^2 := by + rw [EuclideanSpace.real_norm_sq_eq,EuclideanSpace.real_norm_sq_eq] + change (∑ i : S,w i.1^2)=(∑ i,w i^2) + rw [Finset.sum_coe_sort S (fun i=>w i^2)] + exact Finset.sum_subset (Finset.subset_univ S) (by intro i _ hi;simp [hw i hi]) + +lemma supported_quad_le_principal (M : Matrix ι ι ℝ) (S : Finset ι) {ε : ℝ} + (hM : principalOperatorNorm M S ≤ ε) (w : EuclideanSpace ℝ ι) + (hw : ∀ i,i ∉ S → w i=0) : + |⟪w,Matrix.toEuclideanCLM (𝕜:=ℝ) (n:=ι) M w⟫| ≤ ε*‖w‖^2 := by + rw [← matrixOperator_eq_toEuclideanCLM,← matrixQuad_inner,supported_quad_eq M S w hw,matrixQuad_inner] + let v := WithLp.toLp 2 (fun i : S=>w i.1) + calc + _ ≤ ‖v‖*‖matrixOperator (M.submatrix (fun i : S=>i.1) (fun i : S=>i.1)) v‖ := + abs_real_inner_le_norm _ _ + _ ≤ ‖v‖*(principalOperatorNorm M S*‖v‖) := + mul_le_mul_of_nonneg_left ((matrixOperator _).le_opNorm v) (norm_nonneg v) + _ ≤ ‖v‖*(ε*‖v‖) := mul_le_mul_of_nonneg_left + (mul_le_mul_of_nonneg_right hM (norm_nonneg v)) (norm_nonneg v) + _ = ε*‖w‖^2 := by + rw [show ‖v‖*(ε*‖v‖)=ε*‖v‖^2 by ring,supported_norm_sq_eq S w hw] +end SKGap + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Matrix/GOESubmatrix.lean b/lean/OAI/Probability/SKGap/Matrix/GOESubmatrix.lean new file mode 100644 index 0000000000000000000000000000000000000000..260940337cd1ec854bc588d03267c97005ab0c18 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Matrix/GOESubmatrix.lean @@ -0,0 +1,162 @@ +import Mathlib +import OAI.Probability.SKGap.Matrix.MatrixQuad +import OAI.Probability.SKGap.Gaussian.GOEGaussian +import OAI.Probability.SKGap.Gaussian.GaussianSquareTail + +namespace OAI + +section +noncomputable section +namespace SKGap +open MeasureTheory ProbabilityTheory Matrix Real +open scoped BigOperators RealInnerProductSpace +variable {ι κ : Type*} [Fintype ι] [Fintype κ] + +lemma coordinates_restrict_hasLaw (e : κ ↪ ι) : + HasLaw (fun g : ι→ℝ=>fun i=>g (e i)) (gaussianCoordinates κ) (gaussianCoordinates ι) := by + exact iIndepFun.hasLaw_pi (fun i=>coordinate_hasLaw (e i)) + ((iIndepFun_pi (fun _ : ι=>aemeasurable_id)).precomp e.injective) + +def matrixCoordinatesEmbedding (e : κ ↪ ι) : MatrixCoordinates κ ↪ MatrixCoordinates ι := + (e.prodMap e).sumMap e + +omit [Fintype ι] [Fintype κ] in +lemma goeMatrix_submatrix (r : ℝ) (e : κ ↪ ι) (g : MatrixCoordinates ι→ℝ) : + (goeMatrix r g).submatrix e e=goeMatrix r (fun i=>g (matrixCoordinatesEmbedding e i)) := rfl + +lemma continuous_matrixOperator [DecidableEq ι] : Continuous (matrixOperator (ι:=ι)) := by + let L : Matrix ι ι ℝ →ₗ[ℝ] (EuclideanSpace ℝ ι →L[ℝ] EuclideanSpace ℝ ι) := + { toFun := matrixOperator + map_add' := by intro A B;ext x i;simp [matrixOperator_apply,Finset.sum_add_distrib,add_mul] + map_smul' := by intro c A;ext x i;simp [matrixOperator_apply,Finset.mul_sum,mul_assoc] } + exact L.continuous_of_finiteDimensional + +omit [Fintype ι] in +lemma continuous_goeMatrix (r : ℝ) : Continuous (goeMatrix (ι:=ι) r) := by + unfold goeMatrix + fun_prop + +lemma goe_restricted_norm_tail [DecidableEq κ] [Nonempty κ] + (e : κ ↪ ι) {r ε : ℝ} (hr : 0 < r) (hε : 0 ≤ ε) : + (gaussianCoordinates (MatrixCoordinates ι)).real + {g | 2*sqrt (r*(Fintype.card κ:ℝ))+ε < ‖matrixOperator ((goeMatrix r g).submatrix e e)‖} ≤ + 2*exp (-ε^2/(π^2*r)) := by + have hk : (0:ℝ) < Fintype.card κ := Nat.cast_pos.mpr Fintype.card_pos + have he := coordinates_restrict_hasLaw (matrixCoordinatesEmbedding e) + have hm : MeasurableSet {g : MatrixCoordinates κ→ℝ | + 2*sqrt (r*(Fintype.card κ:ℝ))+ε < ‖matrixOperator (goeMatrix r g)‖} := + measurableSet_lt measurable_const ((continuous_matrixOperator.comp (continuous_goeMatrix r)).norm.measurable) + simp only [goeMatrix_submatrix] + rw [he.measureReal_eq hm] + have ht := goe_norm_tail (ι:=κ) (mul_pos hr hk) hε + have heq : r*(Fintype.card κ:ℝ)/(Fintype.card κ:ℝ)=r := mul_div_cancel_right₀ _ hk.ne' + rw [heq] at ht + convert ht using 1 + congr 2 + field_simp +end SKGap +end +end + +section +noncomputable section +namespace SKGap +open Matrix Real +open scoped BigOperators RealInnerProductSpace +variable {ι : Type*} [Fintype ι] [DecidableEq ι] + +omit [DecidableEq ι] in +lemma matrix_quad_row_bound (M : Matrix ι ι ℝ) (hM : ∀ i k,M i k=M k i) + {R : ℝ} (hrow : ∀ i,∑ k,|M i k| ≤ R) (p : EuclideanSpace ℝ ι) : + |matrixQuad M p| ≤ R*‖p‖^2 := by + have hsingle (i k : ι) : |p i*M i k*p k| ≤ |M i k| *(p i^2+p k^2)/2 := by + have hs : 2*|p i| *|p k| ≤ p i^2+p k^2 := by + nlinarith only [sq_nonneg (|p i|-|p k|),sq_abs (p i),sq_abs (p k)] + have hm := mul_le_mul_of_nonneg_left hs (abs_nonneg (M i k)) + simp only [abs_mul] + nlinarith only [hm] + have hswap : (∑ i,∑ k,|M i k| *p k^2)=(∑ i,∑ k,|M i k| *p i^2) := by + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro i _ + apply Finset.sum_congr rfl + intro k _ + rw [hM k i] + calc + _ ≤ ∑ i,∑ k,|p i*M i k*p k| := + (Finset.abs_sum_le_sum_abs _ _).trans (Finset.sum_le_sum (fun i _=>Finset.abs_sum_le_sum_abs _ _)) + _ ≤ ∑ i,∑ k,|M i k| *(p i^2+p k^2)/2 := + Finset.sum_le_sum (fun i _=>Finset.sum_le_sum (fun k _=>hsingle i k)) + _ = ∑ i,(∑ k,|M i k|)*p i^2 := by + simp only [mul_add,add_div,Finset.sum_add_distrib] + simp only [← Finset.sum_div] + rw [hswap] + simp only [Finset.sum_mul] + ring + _ ≤ ∑ i,R*p i^2 := Finset.sum_le_sum (fun i _=>mul_le_mul_of_nonneg_right (hrow i) (sq_nonneg _)) + _ = R*‖p‖^2 := by rw [← Finset.mul_sum,EuclideanSpace.norm_sq_eq];simp only [Real.norm_eq_abs,sq_abs] + +lemma matrixOperator_norm_le_row (M : Matrix ι ι ℝ) (hM : ∀ i k,M i k=M k i) + {R : ℝ} (hR : 0 ≤ R) (hrow : ∀ i,∑ k,|M i k| ≤ R) : + ‖matrixOperator M‖ ≤ R := by + apply matrixOperator_norm_le_of_quad (by + ext i k + simpa only [conjTranspose_apply,star_trivial] using hM k i) hR + intro p hp + apply (matrix_quad_row_bound M hM hrow p).trans + have hs : ‖p‖^2 ≤ 1 := by nlinarith only [hp,norm_nonneg p] + exact (mul_le_mul_of_nonneg_left hs hR).trans_eq (mul_one R) + +lemma matrixOperator_eq_toEuclideanCLM (M : Matrix ι ι ℝ) : + matrixOperator M=Matrix.toEuclideanCLM (𝕜:=ℝ) (n:=ι) M := by + ext x i + rfl +end SKGap +end +end + +section +noncomputable section +namespace SKGap +open MeasureTheory ProbabilityTheory Matrix Real Set +open scoped BigOperators Matrix.Norms.L2Operator +variable {ι : Type*} [Fintype ι] [DecidableEq ι] + +lemma goe_diagonal_hasLaw {r : ℝ} (hr : 0 ≤ r) (i : ι) : + HasLaw (fun g : MatrixCoordinates ι→ℝ=>goeMatrix r g i i) + (gaussianReal 0 (Real.toNNReal (2*r))) (gaussianCoordinates (MatrixCoordinates ι)) := by + have hg := (goe_matrix_gaussian (ι:=ι) r).eval (i,i) + refine ⟨hg.aemeasurable,?_⟩ + rw [hg.map_eq_gaussianReal,goe_mean_zero,← covariance_self hg.aemeasurable,goe_entry_cov hr] + simp only [ite_true,mul_one] + congr 2 + ring + +lemma goe_diagonal_tail {r d : ℝ} (hr : 0 < r) (hd : 0 ≤ d) : + (gaussianCoordinates (MatrixCoordinates ι)).real + {g | ∃ i : ι,d < |goeMatrix r g i i|} ≤ + 2*(Fintype.card ι:ℝ)*exp (-d^2/(8*r)) := by + have hsingle (i : ι) : + (gaussianCoordinates (MatrixCoordinates ι)).real {g | d < |goeMatrix r g i i|} ≤ + 2*exp (-d^2/(8*r)) := by + rw [(goe_diagonal_hasLaw hr.le i).measureReal_eq + (by measurability : MeasurableSet {x : ℝ | d < |x|})] + convert gaussian_real_abs_tail (r:=2*r) (by positivity) hd using 1 + ring_nf + have he : {g : MatrixCoordinates ι→ℝ | ∃ i : ι,d < |goeMatrix r g i i|}= + ⋃ i : ι,{g | d < |goeMatrix r g i i|} := by ext g;simp + rw [he] + apply (measureReal_iUnion_fintype_le _).trans + apply (Finset.sum_le_sum (fun i _=>hsingle i)).trans_eq + simp only [Finset.sum_const,Finset.card_univ,nsmul_eq_mul] + ring + +lemma diagonal_norm_le {d : ℝ} (hd : 0 ≤ d) (v : ι→ℝ) (hv : ∀ i,|v i| ≤ d) : + ‖Matrix.diagonal v‖ ≤ d := by + rw [Matrix.l2_opNorm_diagonal] + exact (pi_norm_le_iff_of_nonneg hd).mpr (fun i=>by simpa only [Real.norm_eq_abs] using hv i) +end SKGap +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Matrix/GapHalfSmallOpNorm.lean b/lean/OAI/Probability/SKGap/Matrix/GapHalfSmallOpNorm.lean new file mode 100644 index 0000000000000000000000000000000000000000..c875232231f7b9cd65d9f80409a479119cbc3706 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Matrix/GapHalfSmallOpNorm.lean @@ -0,0 +1,155 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.GeneratorNonposMax +import OAI.Probability.SKGap.Gaussian.SampledInnerTailScaled + +namespace OAI + +section +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open scoped BigOperators +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open scoped BigOperators +open scoped BigOperators NNReal ENNReal +open MeasureTheory Metric Set +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators NNReal ENNReal Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Set +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators ENNReal NNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Matrix +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators ENNReal NNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal +open scoped BigOperators +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise NNReal ENNReal +open scoped BigOperators +open Filter Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal Topology +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Set Matrix +open scoped BigOperators NNReal ENNReal Matrix.Norms.L2Operator +namespace SKGapCutoff + +theorem hasGap_half_of_small_opNorm {n : ℕ} (J : Interaction n) + (hJ : ∀ i j, J i j=J j i) (hdiag : ∀ i, J i i=0) + (hJC : ‖Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) J‖ ≤ (1:ℝ)/8) : + HasGap J (1/2) := by + have hg := hasGap_of_opNorm J hJ hdiag (1/8) (by norm_num) hJC + have he : Real.exp (8*((1:ℝ)/8)) ≤ 3 := by norm_num; exact Real.exp_one_lt_three.le + have hc : (1:ℝ)/2 ≤ 1-1/8-4*(1/8)^2-4*Real.exp (8*(1/8))*(1/8)^2 := by + norm_num at he ⊢ + linarith + intro f + have hv : 0 ≤ gibbsVariance J f := by + unfold gibbsVariance gibbsExpectation + exact Finset.sum_nonneg (fun x _ => mul_nonneg (gibbs_pos J x).le (sq_nonneg _)) + exact (mul_le_mul_of_nonneg_right hc hv).trans (hg f) + +theorem quenchedGap_small_beta (β : ℝ) (hβ : 0 < β) (hβ' : β ≤ 1/176) : + QuenchedGap β := by + have hsmall : 2*(11*β) ≤ (1:ℝ)/8 := by linarith + have hbad : Tendsto (fun n => disorderLaw β n + {g | ¬ HasGap (sampledInteraction g) (1/2)}) atTop (nhds 0) := by + apply tendsto_of_tendsto_of_tendsto_of_le_of_le' tendsto_const_nhds + (RandomMatrix.sampled_opNorm_tendsto_scaled β hβ) + (Eventually.of_forall (fun _ => bot_le)) + apply Eventually.of_forall + intro n + apply measure_mono + intro g hg + by_contra hnot + apply hg + exact hasGap_half_of_small_opNorm (sampledInteraction g) (sampledInteraction_symm g) + (sampledInteraction_diag g) ((le_of_not_gt hnot).trans hsmall) + refine ⟨1/2, by norm_num, ?_⟩ + have hl := (ENNReal.continuous_sub_left (by simp : (1:ℝ≥0∞) ≠ ∞)).continuousAt.tendsto.comp hbad + have he (n : ℕ) : disorderLaw β n {g | HasGap (sampledInteraction g) (1/2)} = + 1-disorderLaw β n {g | ¬ HasGap (sampledInteraction g) (1/2)} := by + let : IsProbabilityMeasure (disorderLaw β n) := by unfold disorderLaw; infer_instance + have hh := measure_compl (μ := disorderLaw β n) (measurableSet_sampledGap n (1/2)).compl + (measure_ne_top _ _) + simpa only [Set.compl_ofPred,not_not,measure_univ] using hh + simpa only [Function.comp_def,tsub_zero,← he] using hl + +end SKGapCutoff + +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise + +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Matrix/GlobalWordIncrement.lean b/lean/OAI/Probability/SKGap/Matrix/GlobalWordIncrement.lean new file mode 100644 index 0000000000000000000000000000000000000000..2d454dbad4d628b74c284d203410aab4f7d7840c --- /dev/null +++ b/lean/OAI/Probability/SKGap/Matrix/GlobalWordIncrement.lean @@ -0,0 +1,99 @@ +import Mathlib +import OAI.Probability.SKGap.Matrix.WordIncrement + +namespace OAI + +section +noncomputable section +namespace SKGap +open Matrix Real Set +open scoped BigOperators Matrix.Norms.Frobenius SchwartzMap +variable {ι : Type*} [Fintype ι] [DecidableEq ι] + +def globalWordHolder (f : 𝓢(ℝ,ℂ)) (R j A D : ℝ) : ℝ := + wordHolderScale f R j A+2*actualWordBound f R j A D+1 +lemma globalWordHolder_nonneg (f : 𝓢(ℝ,ℂ)) {R j A D : ℝ} + (hR : 0 ≤ R) (hj : 0 ≤ j) (hA : 0 ≤ A) (hD : 0 ≤ D) : + 0 ≤ globalWordHolder f R j A D := by + have hh := wordHolderScale_ge_one f R A hj + have hb := actualWordBound_pos f hR hj hA hD + dsimp [globalWordHolder] + linarith + +lemma WordLetter.eval_pair_global [Nonempty ι] (f : 𝓢(ℝ,ℂ)) {R j A D δ : ℝ} + (hR : 0 ≤ R) (hj : 0 ≤ j) (hA : 0 ≤ A) (hD : 0 ≤ D) (hδ : 0 ≤ δ) + {a b : ι→ℝ} (ha : ∀ i,0 ≤ a i) (hb : ∀ i,0 ≤ b i) (haA : ∀ i,a i ≤ A) (hbA : ∀ i,b i ≤ A) + (hab : ∀ i,|a i-b i| ≤ δ) (l m : WordLetter ι) (hl : l.bounded D) (hm : m.bounded D) + (hlm : l.close δ m) : + let B : NNReal := ⟨actualWordBound f R j A D,(actualWordBound_pos f hR hj hA hD).le⟩ + let Δ : NNReal := ⟨globalWordHolder f R j A D*sqrt δ,mul_nonneg (globalWordHolder_nonneg f hR hj hA hD) (sqrt_nonneg _)⟩ + MatrixFactorPairBounds B Δ (l.eval f R hR j a 1) (m.eval f R hR j b 1) := by + intro B Δ + have hG : wordHolderScale f R j A ≤ globalWordHolder f R j A D := by + have hh := actualWordBound_pos f hR hj hA hD + dsimp [globalWordHolder] + linarith + by_cases hs : δ ≤ 1 + · have hh := l.eval_pair f hR hj hA hD hδ hs ha hb haA hbA hab m hl hm hlm + have hΔ : (⟨wordHolderScale f R j A*sqrt δ,mul_nonneg (zero_le_one.trans (wordHolderScale_ge_one f R A hj)) (sqrt_nonneg _)⟩:NNReal) ≤ Δ := + mul_le_mul_of_nonneg_right hG (sqrt_nonneg _) + exact ⟨hh.leftBound,hh.rightBound,hh.leftLip,hh.rightLip, + fun M=>(hh.parameter M).trans hΔ,hh.increment.weaken hΔ⟩ + · have hδ1 : 1 ≤ sqrt δ := by simpa only [sqrt_one] using sqrt_le_sqrt (le_of_not_ge hs) + have hGB : 2*(B:ℝ) ≤ globalWordHolder f R j A D := by + have hh := wordHolderScale_ge_one f R A hj + change 2*actualWordBound f R j A D ≤ wordHolderScale f R j A+2*actualWordBound f R j A D+1 + linarith + have hBΔ : 2*(B:ℝ) ≤ (Δ:ℝ) := by + change 2*(B:ℝ) ≤ globalWordHolder f R j A D*sqrt δ + exact (le_mul_of_one_le_right (by positivity : 0 ≤ 2*(B:ℝ)) hδ1).trans + (mul_le_mul_of_nonneg_right hGB (sqrt_nonneg _)) + obtain ⟨h1,h2⟩ := l.eval_bounds f hR hj hA hD ha haA ⟨zero_le_one,le_rfl⟩ hl + obtain ⟨h3,h4⟩ := m.eval_bounds f hR hj hA hD hb hbA ⟨zero_le_one,le_rfl⟩ hm + refine ⟨h1,h3,h2,h4,?_,?_⟩ + · intro M + exact (opNorm_sub _ _).trans ((add_le_add (h1 M) (h3 M)).trans (by + change actualWordBound f R j A D + actualWordBound f R j A D ≤ (Δ:ℝ) + change 2*actualWordBound f R j A D ≤ (Δ:ℝ) at hBΔ + linarith)) + · apply LipschitzWith.of_dist_le_mul + intro M N + rw [dist_eq_norm] + have he : (l.eval f R hR j a 1 M-m.eval f R hR j b 1 M)- + (l.eval f R hR j a 1 N-m.eval f R hR j b 1 N)= + (l.eval f R hR j a 1 M-l.eval f R hR j a 1 N)- + (m.eval f R hR j b 1 M-m.eval f R hR j b 1 N) := by abel + rw [he] + apply (norm_sub_le _ _).trans + have h2' := h2.dist_le_mul M N + have h4' := h4.dist_le_mul M N + rw [dist_eq_norm] at h2' h4' + calc + _ ≤ (B:ℝ)*dist M N+(B:ℝ)*dist M N := add_le_add h2' h4' + _ = (2*(B:ℝ))*dist M N := by ring + _ ≤ (Δ:ℝ)*dist M N := mul_le_mul_of_nonneg_right hBΔ dist_nonneg + +theorem actualWord_pair_global [Nonempty ι] (f : 𝓢(ℝ,ℂ)) {R j A D δ : ℝ} + (hR : 0 ≤ R) (hj : 0 ≤ j) (hA : 0 ≤ A) (hD : 0 ≤ D) (hδ : 0 ≤ δ) + {a b : ι→ℝ} (ha : ∀ i,0 ≤ a i) (hb : ∀ i,0 ≤ b i) (haA : ∀ i,a i ≤ A) (hbA : ∀ i,b i ≤ A) + (hab : ∀ i,|a i-b i| ≤ δ) (F : List (WordLetter ι×WordLetter ι)) + (hF : ∀ p∈F,p.1.bounded D ∧ p.2.bounded D ∧ p.1.close δ p.2) : + let B : NNReal := ⟨actualWordBound f R j A D,(actualWordBound_pos f hR hj hA hD).le⟩ + let Δ : NNReal := ⟨globalWordHolder f R j A D*sqrt δ,mul_nonneg (globalWordHolder_nonneg f hR hj hA hD) (sqrt_nonneg _)⟩ + (∀ M,opNorm (actualWord f R hR j a 1 (F.map Prod.fst) M-actualWord f R hR j b 1 (F.map Prod.snd) M) ≤ + (wordParameterCoeff B F.length:ℝ)*Δ) ∧ + LipschitzWith (wordMixedCoeff B F.length*Δ) + (fun M=>actualWord f R hR j a 1 (F.map Prod.fst) M-actualWord f R hR j b 1 (F.map Prod.snd) M) := by + intro B Δ + let G := F.map (fun p=>(p.1.eval f R hR j a 1,p.2.eval f R hR j b 1)) + have hG : ∀ p∈G,MatrixFactorPairBounds B Δ p.1 p.2 := by + intro p hp + obtain ⟨q,hq,rfl⟩ := List.mem_map.mp hp + obtain ⟨h1,h2,h3⟩ := hF q hq + exact WordLetter.eval_pair_global f hR hj hA hD hδ ha hb haA hbA hab q.1 q.2 h1 h2 h3 + simpa only [G,List.length_map,List.map_map,Function.comp_def,actualWord] using! matrixWord_pair_increments G hG +end SKGap +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Matrix/GoeInverseLoopCentered.lean b/lean/OAI/Probability/SKGap/Matrix/GoeInverseLoopCentered.lean new file mode 100644 index 0000000000000000000000000000000000000000..02dd4a485d91ed589b10715ffb707f0a2e556a16 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Matrix/GoeInverseLoopCentered.lean @@ -0,0 +1,108 @@ +import Mathlib +import OAI.Probability.SKGap.Matrix.MatrixEntryCLM +import OAI.Probability.SKGap.Gaussian.GaussianProductIntegral +import OAI.Probability.SKGap.Localization.IntegralProductDeviation + +namespace OAI + +section +noncomputable section +open MeasureTheory ProbabilityTheory InformationTheory Real Set +open scoped NNReal ENNReal +open Filter +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius ENNReal NNReal +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius NNReal +noncomputable section +open MeasureTheory ProbabilityTheory Real Set Filter +open MeasureTheory.Measure +open scoped ENNReal NNReal MeasureTheory Topology +open MeasureTheory +noncomputable section +namespace SKGap +open Matrix Real MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix.Norms.Frobenius NNReal ENNReal +variable {ι : Type*} [Fintype ι] [DecidableEq ι] + +theorem goe_inverse_loop_centered {r : ℝ} (hr : 0 ≤ r) (B : Matrix ι ι ℝ) (i : ι) + {K : Matrix ι ι ℝ → Matrix ι ι ℝ} {L T : ℝ≥0} {C : ℝ} + {s : Set (MatrixCoordinates ι → ℝ)} + (hK : LipschitzWith L K) (hC : ∀ M, opNorm (K M) ≤ C) + (hT : LipschitzWith T (fun g : EuclideanSpace ℝ (MatrixCoordinates ι) => + Matrix.trace (K (goeMatrix r g)*B))) (hT0 : 0 < T) + (hs : MeasurableSet s) + (hder : ∀ g ∈ s, ∀ b, HasDerivAt + (fun t : ℝ => K (goeMatrix r g+t • symmetricElementary i b) b i) + ((K (goeMatrix r g)*B*symmetricElementary i b*K (goeMatrix r g)) b i) 0) : + let μ := Measure.pi (fun _ : MatrixCoordinates ι => gaussianReal 0 1) + let Lπ : ℝ≥0 := L*(⟨sqrt (2*r),sqrt_nonneg _⟩ * + (Fintype.card (MatrixCoordinates ι) : ℝ≥0) ^ (1/(2:ℝ≥0∞)).toReal) + |(∫ g, (goeMatrix r g*K (goeMatrix r g)) i i ∂μ)- + r*(∫ g, Matrix.trace (K (goeMatrix r g)*B) ∂μ)*(∫ g, K (goeMatrix r g) i i ∂μ)| ≤ + (Fintype.card ι:ℝ)*(sqrt (2*r)*(Lπ:ℝ)+r*(2*C*opNorm B*C))*μ.real sᶜ+ + r*(C*((2*exp (π^2/8))*(T:ℝ))+C*opNorm B*C) := by + intro μ Lπ + have hC0 : 0 ≤ C := (norm_nonneg _).trans (hC 0) + have hcomp : LipschitzWith Lπ (fun g => K (goeMatrix r g)) := + hK.comp (goeMatrix_pi_lipschitz r) + have hf (a b : ι) : LipschitzWith Lπ (fun g => K (goeMatrix r g) a b) := by + simpa only [one_mul] using! (matrixEntry_lipschitz a b).comp hcomp + have hc (g : MatrixCoordinates ι → ℝ) (a b : ι) : + ‖K (goeMatrix r g) a b‖ ≤ C := by + simpa only [Real.norm_eq_abs] using (matrix_entry_le_opNorm _ a b).trans (hC _) + have hd (g : MatrixCoordinates ι → ℝ) (b : ι) : + ‖(K (goeMatrix r g)*B*symmetricElementary i b*K (goeMatrix r g)) b i‖ ≤ + 2*C*opNorm B*C := by + have he : ‖(K (goeMatrix r g)*B*symmetricElementary i b*K (goeMatrix r g)) b i‖ ≤ + ‖K (goeMatrix r g)*B*symmetricElementary i b*K (goeMatrix r g)‖ := by + simpa only [Real.norm_eq_abs] using! + matrix_entry_le_frobenius (K (goeMatrix r g)*B*symmetricElementary i b*K (goeMatrix r g)) b i + apply he.trans + apply (matrix_inverse_diff_bound _ _ _).trans + calc + _ ≤ C*(opNorm B*2)*C := by + exact mul_le_mul + (mul_le_mul (hC _) (mul_le_mul_of_nonneg_left (symmetricElementary_norm_le i b) (norm_nonneg _)) + (mul_nonneg (norm_nonneg _) (norm_nonneg _)) hC0) + (hC _) (norm_nonneg _) (mul_nonneg hC0 (mul_nonneg (norm_nonneg _) (by norm_num))) + _ = _ := by ring + have hz (g : MatrixCoordinates ι → ℝ) : + ‖∑ b, (K (goeMatrix r g)*B) b i*K (goeMatrix r g) b i‖ ≤ C*opNorm B*C := by + rw [Real.norm_eq_abs] + apply (goe_cross_contraction_bound _ _ _).trans + exact mul_le_mul (mul_le_mul_of_nonneg_right (hC _) (norm_nonneg _)) (hC _) + (norm_nonneg _) (mul_nonneg hC0 (norm_nonneg _)) + have hzi : Integrable (fun g => ∑ b, (K (goeMatrix r g)*B) b i*K (goeMatrix r g) b i) μ := + Integrable.mono' (integrable_const (C*opNorm B*C)) (by + have hc := hcomp.continuous + exact (continuous_finsetSum _ (fun b _ => + ((hc.mul continuous_const).matrix_elem b i).mul (hc.matrix_elem b i))).aestronglyMeasurable) + (ae_of_all _ hz) + have hi : Integrable (fun g => Matrix.trace (K (goeMatrix r g)*B)) μ := + gaussianProduct_integrable_lipschitz hT + have ht : (∫ g, |Matrix.trace (K (goeMatrix r g)*B)- + ∫ h, Matrix.trace (K (goeMatrix r h)*B) ∂μ| ∂μ) ≤ (2*exp (π^2/8))*(T:ℝ) := + gaussianProduct_centered_L1 hT hT0 + exact integral_loop_deviation hr hi (hf i i).continuous.aestronglyMeasurable + (ae_of_all _ (fun g => hc g i i)) hzi (ae_of_all _ hz) ht + (goe_inverse_loop_raw hr B i hf hc hd hs hder) + +end SKGap + +noncomputable section +open MeasureTheory Set NormedSpace +open scoped Topology + +end +end +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Matrix/InverseDiagram.lean b/lean/OAI/Probability/SKGap/Matrix/InverseDiagram.lean new file mode 100644 index 0000000000000000000000000000000000000000..5c024b27da8bbfdcdac84eef4ed2b2794c717e20 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Matrix/InverseDiagram.lean @@ -0,0 +1,232 @@ +import Mathlib +import OAI.Probability.SKGap.Model + +namespace OAI + +section +noncomputable section +noncomputable section +open scoped BigOperators +namespace SKGap.Noncrossing + +inductive InverseDiagram where + | empty + | counterterm (rest : InverseDiagram) + | arch (inside rest : InverseDiagram) + deriving DecidableEq + +namespace InverseDiagram + +def degree : InverseDiagram → ℕ + | .empty => 0 + | .counterterm d => d.degree + 1 + | .arch d e => d.degree + e.degree + 1 + +def blocks : InverseDiagram → List Bool + | .empty => [] + | .counterterm d => false :: d.blocks + | .arch d e => true :: (d.blocks ++ true :: e.blocks) + +theorem blocks_degree (d : InverseDiagram) : + ((d.blocks.map (fun b => if b then 1 else 2)).sum : ℕ) = 2 * d.degree := by + induction d with + | empty => rfl + | counterterm d ih => simp only [blocks, List.map_cons, List.sum_cons, Bool.false_eq_true, + ↓reduceIte, ih, degree]; omega + | arch d e ihd ihe => simp only [blocks, List.map_cons, List.map_append, List.sum_cons, + List.sum_append, ↓reduceIte, ihd, ihe, degree]; omega + +def enumerate : ℕ → List InverseDiagram + | 0 => [.empty] + | n + 1 => (enumerate n).map .counterterm ++ + (List.finRange (n+1)).flatMap fun k => + (enumerate k.val).flatMap fun u => + (enumerate (n-k.val)).map (fun v => .arch u v) +termination_by n => n +decreasing_by all_goals omega + +lemma mem_enumerate (d : InverseDiagram) (n : ℕ) : d ∈ enumerate n ↔ d.degree = n := by + induction n using Nat.strong_induction_on generalizing d with + | h n ih => + cases n with + | zero => + cases d <;> simp [enumerate, degree] + | succ n => + rw [enumerate] + cases d with + | empty => simp [degree] + | counterterm d => + simpa [degree] using ih n (by omega) d + | arch u v => + simp only [List.mem_append, List.mem_map, List.mem_flatMap] + constructor + · rintro (⟨d, -, he⟩ | ⟨k, -, u', hu', v', hv', he⟩) + · cases he + · cases he + have hu := (ih k.val (by omega) u).mp hu' + have hv := (ih (n-k.val) (by omega) v).mp hv' + simp only [degree] + omega + · intro hd + have hu : u.degree < n+1 := by simp only [degree] at hd; omega + refine Or.inr ⟨⟨u.degree, hu⟩, List.mem_finRange _, u, (ih _ hu u).mpr rfl, + v, (ih _ (by omega) v).mpr ?_, rfl⟩ + change v.degree = n - u.degree + simp only [degree] at hd + omega + +lemma nodup_arch_list (U V : List InverseDiagram) (hU : U.Nodup) (hV : V.Nodup) : + (U.flatMap fun u => V.map (fun v => InverseDiagram.arch u v)).Nodup := by + apply List.nodup_flatMap.mpr + constructor + · intro u _ + exact (List.nodup_map_iff (fun v w h => (InverseDiagram.arch.inj h).2)).mpr hV + · apply List.Pairwise.imp (fun {u v} huv => ?_) hU + apply List.disjoint_left.mpr + intro t htU htV + obtain ⟨u', -, hu'⟩ := List.mem_map.mp htU + obtain ⟨v', -, hv'⟩ := List.mem_map.mp htV + exact huv (InverseDiagram.arch.inj (hu'.trans hv'.symm)).1 + +theorem enumerate_nodup (n : ℕ) : (enumerate n).Nodup := by + induction n using Nat.strong_induction_on with + | h n ih => + cases n with + | zero => simp [enumerate] + | succ n => + rw [enumerate, List.nodup_append] + refine ⟨?_, ?_, ?_⟩ + · exact (List.nodup_map_iff (fun u v h => InverseDiagram.counterterm.inj h)).mpr + (ih n (by omega)) + · apply List.nodup_flatMap.mpr + constructor + · intro k _ + exact nodup_arch_list _ _ (ih k.val k.isLt) (ih (n-k.val) (by omega)) + · apply List.Pairwise.imp (fun {k l} hkl => ?_) (List.nodup_finRange (n+1)) + apply List.disjoint_left.mpr + intro t htK htL + simp only [List.mem_flatMap, List.mem_map] at htK htL + obtain ⟨u, hu, v, -, he⟩ := htK + obtain ⟨u', hu', v', -, he'⟩ := htL + have huu : u = u' := (InverseDiagram.arch.inj (he.trans he'.symm)).1 + have hk := (mem_enumerate u k.val).mp hu + have hl := (mem_enumerate u' l.val).mp hu' + apply hkl + apply Fin.ext + exact hk.symm.trans ((congrArg degree huu).trans hl) + · intro t ht1 s ht2 he + subst s + obtain ⟨u, -, hu⟩ := List.mem_map.mp ht1 + simp only [List.mem_flatMap, List.mem_map] at ht2 + obtain ⟨k, -, a, -, b, -, ht⟩ := ht2 + cases hu.trans ht.symm + +variable {ι : Type*} [Fintype ι] + +def average (x : ι → ℝ) : ℝ := (∑ i, x i) / Fintype.card ι + +def value (j : ℝ) (a : ι → ℝ) : InverseDiagram → ι → ℝ + | .empty, _ => 1 + | .counterterm d, i => -(j * average a) * a i * value j a d i + | .arch u v, i => j * a i * average (fun k => a k * value j a u k) * value j a v i + +def coefficient (j : ℝ) (a : ι → ℝ) (n : ℕ) (i : ι) : ℝ := + ((enumerate n).map (fun d => value j a d i)).sum + +@[simp] lemma coefficient_zero (j : ℝ) (a : ι → ℝ) (i : ι) : + coefficient j a 0 i = 1 := by simp [coefficient, enumerate, value] + +lemma average_add (x y : ι → ℝ) : average (x+y) = average x + average y := by + simp [average, Finset.sum_add_distrib, add_div] + +@[simp] lemma average_zero : average (0 : ι → ℝ) = 0 := by simp [average] + +lemma average_list_sum {α : Type*} (l : List α) (f : α → ι → ℝ) : + average (fun i => (l.map (fun u => f u i)).sum) = + (l.map (fun u => average (f u))).sum := by + induction l with + | nil => simp [average] + | cons u l ih => + simp only [List.map_cons, List.sum_cons] + change average (f u + fun i => (l.map (fun v => f v i)).sum) = _ + rw [average_add, ih] + +lemma sum_flatMap {α : Type*} {R : Type*} [AddMonoid R] + (l : List α) (f : α → List R) : (l.flatMap f).sum = (l.map (fun x => (f x).sum)).sum := by + induction l with + | nil => rfl + | cons x l ih => simp only [List.flatMap_cons, List.sum_append, List.map_cons, List.sum_cons, ih] + +lemma sum_arch (j : ℝ) (a : ι → ℝ) (U V : List InverseDiagram) (i : ι) : + ((U.flatMap fun u => V.map (fun v => .arch u v)).map (fun d => value j a d i)).sum = + j * a i * average (fun k => a k * (U.map (fun u => value j a u k)).sum) * + (V.map (fun v => value j a v i)).sum := by + simp only [List.map_flatMap, List.map_map, Function.comp_def, sum_flatMap, value, + List.sum_map_mul_left] + rw [List.sum_map_mul_right, List.sum_map_mul_left] + congr 2 + rw [← average_list_sum] + congr 1 + funext k + exact List.sum_map_mul_left U (fun u => value j a u k) (a k) + +lemma coefficient_succ (j : ℝ) (a : ι → ℝ) (n : ℕ) (i : ι) : + coefficient j a (n+1) i = -(j * average a) * a i * coefficient j a n i + + ∑ k : Fin (n+1), j * a i * average (fun u => a u * coefficient j a k.val u) * + coefficient j a (n-k.val) i := by + rw [coefficient, enumerate] + simp only [List.map_append, List.sum_append, List.map_map, Function.comp_def, + value, List.sum_map_mul_left, List.map_flatMap, sum_flatMap] + rw [Fin.sum_univ_def] + congr 1 + apply congrArg List.sum + apply List.map_congr_left + intro k _ + simpa only [List.map_flatMap, List.map_map, Function.comp_def, sum_flatMap, + value, List.sum_map_mul_left, coefficient] using + sum_arch j a (enumerate k.val) (enumerate (n-k.val)) i + +theorem coefficient_positive (j : ℝ) (a : ι → ℝ) (n : ℕ) (hn : 0 < n) (i : ι) : + coefficient j a n i = 0 := by + induction n using Nat.strong_induction_on generalizing i with + | h n ih => + obtain ⟨n, rfl⟩ := Nat.exists_eq_succ_of_ne_zero (Nat.ne_of_gt hn) + rw [coefficient_succ] + have hs : (∑ k : Fin (n+1), j * a i * average (fun u => a u * coefficient j a k.val u) * + coefficient j a (n-k.val) i) = j * a i * average a * coefficient j a n i := by + rw [Finset.sum_eq_single (0 : Fin (n+1))] + · simp + · intro k _ hk + have hk0 : 0 < k.val := by have hne : k.val ≠ 0 := fun he => hk (Fin.ext he); omega + have hz (u : ι) : coefficient j a k.val u = 0 := ih k.val k.isLt hk0 u + simp [hz, average] + · simp + rw [hs] + ring + +def predictionSeries (j : ℝ) (a : ι → ℝ) : PowerSeries (ι → ℝ) := + PowerSeries.mk fun n => fun i => if Even n then coefficient j a (n/2) i else 0 + +theorem predictionSeries_eq_one (j : ℝ) (a : ι → ℝ) : predictionSeries j a = 1 := by + ext n i + simp only [predictionSeries, PowerSeries.coeff_mk] + by_cases hn : n = 0 + · subst n + simp + · have hp : 0 < n := Nat.pos_of_ne_zero hn + by_cases he : Even n + · have hn2 : 0 < n/2 := by rcases he with ⟨k, hk⟩; omega + simp [he, coefficient_positive j a (n/2) hn2 i, hn] + · simp [he, hn] + +end InverseDiagram +end SKGap.Noncrossing + +noncomputable section + +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Matrix/InverseSeries.lean b/lean/OAI/Probability/SKGap/Matrix/InverseSeries.lean new file mode 100644 index 0000000000000000000000000000000000000000..574de1341f90870d8dd7fbe1df58401dd3317d72 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Matrix/InverseSeries.lean @@ -0,0 +1,286 @@ +import Mathlib +import OAI.Probability.SKGap.Matrix.WordPartnerContraction +import OAI.Probability.SKGap.Stability.OrdinaryCutLeft + +namespace OAI + +section +noncomputable section +noncomputable section +open scoped BigOperators +noncomputable section +noncomputable section +noncomputable section +open scoped BigOperators +noncomputable section +open scoped BigOperators +noncomputable section +open scoped BigOperators +noncomputable section +open scoped BigOperators +noncomputable section +open scoped BigOperators +noncomputable section +open scoped BigOperators +noncomputable section +open scoped BigOperators +noncomputable section +open scoped BigOperators +noncomputable section +open scoped BigOperators +noncomputable section +open scoped BigOperators +namespace SKGap.Noncrossing.WordSeries +open Diagram InverseDiagram PowerSeries +variable {ι : Type*} [Fintype ι] + +instance noiseSplitNilIsEmpty {D : Type*} : IsEmpty (NoiseSplit ([] : List (Letter D))) := + ⟨fun s => by have h := congrArg List.length s.word_eq; simp at h⟩ + +def inverseSeries (j : ℝ) (a : ι→ℝ) (P Q : List (Letter (ι→ℝ))) (i : ι) : ℝ⟦X⟧ := + PowerSeries.mk (fun n => inverseCoefficient j a P Q n i) +def meanSeries (f : ι→ℝ⟦X⟧) : ℝ⟦X⟧ := C ((Fintype.card ι:ℝ)⁻¹)*(∑ i,f i) +@[simp] lemma coeff_inverseSeries (j : ℝ) (a : ι→ℝ) (P Q : List (Letter (ι→ℝ))) (n : ℕ) (i : ι) : + coeff n (inverseSeries j a P Q i)=inverseCoefficient j a P Q n i := coeff_mk _ _ +@[simp] lemma coeff_meanSeries (f : ι→ℝ⟦X⟧) (n : ℕ) : + coeff n (meanSeries f)=mean (fun i=>coeff n (f i)) := by + simp [meanSeries,mean,div_eq_mul_inv,mul_comm] +@[simp] lemma meanSeries_C (f : ι→ℝ) : meanSeries (fun i=>C (f i))=C (mean f) := by + ext n + simp only [coeff_meanSeries,coeff_C] + split_ifs with hn + · rfl + · simp [mean] + +lemma coeff_mul_fin (p q : ℝ⟦X⟧) (n : ℕ) : + coeff n (p*q)=∑ k : Fin (n+1), coeff k.val p*coeff (n-k.val) q := by + rw [coeff_mul,Finset.Nat.sum_antidiagonal_eq_sum_range_succ (fun k l => coeff k p*coeff l q) n] + exact (Fin.sum_univ_eq_sum_range (fun k => coeff k p*coeff (n-k) q) (n+1)).symm + +lemma inverseSeries_right (j : ℝ) (a : ι→ℝ) (P R T : List (Letter (ι→ℝ))) (i : ι) : + inverseSeries j a (P++(.noise::R)) T i = + (∑ s : NoiseSplit P, C (j*mean (ordinary j s.after))*inverseSeries j a (s.before++R) T i) + + (∑ s : NoiseSplit R, C (j*mean (ordinary j s.before))*inverseSeries j a (P++s.after) T i) + + X*(C j*meanSeries (inverseSeries j a R [.diag a])*inverseSeries j a P T i) + + (∑ s : NoiseSplit T, C j*meanSeries (inverseSeries j a R s.before)*C (ordinary j (P++s.after) i)) := by + ext n + cases n with + | zero => + simp only [map_add,map_sum,coeff_inverseSeries,coeff_C_mul,coeff_mul_C,coeff_meanSeries, + inverseCoefficient_zero,coeff_zero_X_mul,add_zero] + simpa only [ordinary,List.append_assoc,List.nil_append,List.append_nil,Finset.univ_eq_empty, + Finset.sum_empty,add_zero] using + ordinary_cut_right j P R ([] : List (Letter (ι→ℝ))) T i + | succ n => + simp only [map_add,map_sum,coeff_inverseSeries,coeff_C_mul,coeff_mul_C,coeff_meanSeries, + coeff_succ_X_mul,coeff_mul_fin] + exact inverseCoefficient_right j a P R T n i + +lemma inverseSeries_left (j : ℝ) (a : ι→ℝ) (P R T : List (Letter (ι→ℝ))) (i : ι) : + inverseSeries j a P (R++(.noise::T)) i = + (∑ s : NoiseSplit P, C j*meanSeries (inverseSeries j a s.after R)*C (ordinary j (s.before++T) i)) + + X*(C j*meanSeries (inverseSeries j a [] R)*inverseSeries j a P (.diag a::T) i) + + (∑ s : NoiseSplit R, C (j*mean (ordinary j s.after))*inverseSeries j a P (s.before++T) i) + + (∑ s : NoiseSplit T, C (j*mean (ordinary j s.before))*inverseSeries j a P (R++s.after) i) := by + ext n + cases n with + | zero => + simp only [map_add,map_sum,coeff_inverseSeries,coeff_C_mul,coeff_mul_C,coeff_meanSeries, + inverseCoefficient_zero,coeff_zero_X_mul,add_zero] + simpa only [ordinary,List.append_assoc,List.nil_append,List.append_nil,Finset.univ_eq_empty, + Finset.sum_empty,add_zero] using + ordinary_cut_left j P ([] : List (Letter (ι→ℝ))) R T i + | succ n => + simp only [map_add,map_sum,coeff_inverseSeries,coeff_C_mul,coeff_mul_C,coeff_meanSeries, + coeff_succ_X_mul,coeff_mul_fin] + rw [inverseCoefficient_left] + congr 2 + congr 1 + apply Fintype.sum_equiv (Fin.revPerm (n := n+1)) + intro k + simp only [Fin.revPerm_apply,Fin.val_rev] + rw [show n+1-(k.val+1)=n-k.val by omega, Nat.sub_sub_self (Nat.le_of_lt_succ k.isLt)] + +end SKGap.Noncrossing.WordSeries + +noncomputable section +open scoped BigOperators +namespace SKGap.Noncrossing +open Diagram InverseDiagram WordSeries PowerSeries +variable {ι : Type*} + +def Letter.toWord : Letter (ι→ℝ)→WordLetter ι + | .diag d => .diag d + | .noise => .noise +def liftWord (F : List (Letter (ι→ℝ))) : List (WordLetter ι) := F.map Letter.toWord +@[simp] lemma liftWord_nil : liftWord ([] : List (Letter (ι→ℝ)))=[] := rfl +@[simp] lemma liftWord_cons (l : Letter (ι→ℝ)) (F : List (Letter (ι→ℝ))) : + liftWord (l::F)=l.toWord::liftWord F := rfl +@[simp] lemma liftWord_append (P Q : List (Letter (ι→ℝ))) : liftWord (P++Q)=liftWord P++liftWord Q := List.map_append +@[simp] lemma inverseCount_lift (F : List (Letter (ι→ℝ))) : inverseCount (liftWord F)=0 := by + induction F with + | nil => rfl + | cons l F ih => cases l <;> simpa [liftWord,Letter.toWord,inverseCount] using ih + +lemma exists_lift_of_no_inverse (F : List (WordLetter ι)) (h : inverseCount F=0) : + ∃ P : List (Letter (ι→ℝ)), liftWord P=F := by + induction F with + | nil => exact ⟨[],rfl⟩ + | cons l F ih => + cases l with + | inverse => simp [inverseCount] at h + | diag d => + obtain ⟨P,rfl⟩ := ih (by simpa [inverseCount] using h) + exact ⟨.diag d::P,rfl⟩ + | noise => + obtain ⟨P,rfl⟩ := ih (by simpa [inverseCount] using h) + exact ⟨.noise::P,rfl⟩ + +@[simp] lemma inverseCount_inverse (F : List (WordLetter ι)) : + inverseCount (.inverse::F)=inverseCount F+1 := by simp [inverseCount] + +lemma one_inverse_cases (F : List (WordLetter ι)) (h : inverseCount F≤1) : + (∃ P, F=liftWord P) ∨ (∃ P Q, F=liftWord P++(.inverse::liftWord Q)) := by + induction F with + | nil => exact Or.inl ⟨[],rfl⟩ + | cons l F ih => + cases l with + | inverse => + have hz : inverseCount F=0 := by rw [inverseCount_inverse] at h; omega + obtain ⟨P,rfl⟩ := exists_lift_of_no_inverse F hz + exact Or.inr ⟨[],P,rfl⟩ + | diag d => + have ht : inverseCount F≤1 := by simpa [inverseCount] using h + rcases ih ht with ⟨P,rfl⟩ | ⟨P,Q,rfl⟩ + · exact Or.inl ⟨.diag d::P,rfl⟩ + · exact Or.inr ⟨.diag d::P,Q,rfl⟩ + | noise => + have ht : inverseCount F≤1 := by simpa [inverseCount] using h + rcases ih ht with ⟨P,rfl⟩ | ⟨P,Q,rfl⟩ + · exact Or.inl ⟨.noise::P,rfl⟩ + · exact Or.inr ⟨.noise::P,Q,rfl⟩ + +def expandWord [Fintype ι] (j : ℝ) (a : ι→ℝ) (bs : List Bool) (F : List (WordLetter ι)) := + F.flatMap (fun l=>match l with + | .diag d => [Letter.diag d] + | .noise => [.noise] + | .inverse => chain j a bs) +@[simp] lemma expandWord_lift [Fintype ι] (j : ℝ) (a : ι→ℝ) (bs : List Bool) (F : List (Letter (ι→ℝ))) : + expandWord j a bs (liftWord F)=F := by + induction F with + | nil => rfl + | cons l F ih => cases l <;> simp [expandWord,liftWord,Letter.toWord] at * <;> exact ih +@[simp] lemma expandWord_oneInverse [Fintype ι] (j : ℝ) (a : ι→ℝ) (bs : List Bool) + (P Q : List (Letter (ι→ℝ))) : + expandWord j a bs (liftWord P++(.inverse::liftWord Q))=P++chain j a bs++Q := by + simp only [expandWord,List.flatMap_append,List.flatMap_cons] + change expandWord j a bs (liftWord P)++(chain j a bs++expandWord j a bs (liftWord Q))=_ + simp [List.append_assoc] + +def literalSeries [Fintype ι] (j : ℝ) (a : ι→ℝ) (F : List (WordLetter ι)) (i : ι) : ℝ⟦X⟧ := + if inverseCount F=0 then PowerSeries.C (ordinary j (expandWord j a [] F) i) + else PowerSeries.mk (fun n=>∑ bs : Blocks n, ordinary j (expandWord j a bs.val F) i) +@[simp] lemma literalSeries_lift [Fintype ι] (j : ℝ) (a : ι→ℝ) (F : List (Letter (ι→ℝ))) (i : ι) : + literalSeries j a (liftWord F) i=PowerSeries.C (ordinary j F i) := by + simp [literalSeries] +@[simp] lemma literalSeries_oneInverse [Fintype ι] (j : ℝ) (a : ι→ℝ) + (P Q : List (Letter (ι→ℝ))) (i : ι) : + literalSeries j a (liftWord P++(.inverse::liftWord Q)) i=inverseSeries j a P Q i := by + have hc : inverseCount (liftWord P++(.inverse::liftWord Q))=1 := by simp only [inverseCount_append,inverseCount_inverse,inverseCount_lift,zero_add] + simp [literalSeries,hc,inverseSeries,inverseCoefficient] + +instance noiseSplitDiagIsEmpty {D : Type*} (d : D) : IsEmpty (NoiseSplit [Letter.diag d]) := + ⟨fun s => by + have hle := s.length_bound + have hp : s.before=[] := List.eq_nil_of_length_eq_zero (by simpa using hle) + have hh := s.word_eq + simp [hp] at hh⟩ +instance noiseSplitNoiseUnique {D : Type*} : Unique (NoiseSplit [Letter.noise (D := D)]) where + default := ⟨[],[],rfl⟩ + uniq s := by + have hle := s.length_bound + have hp : s.before=[] := List.eq_nil_of_length_eq_zero (by simpa using hle) + have hq : s.after=[] := by have hh := s.word_eq; simpa [hp] using hh.symm + apply NoiseSplit.ext <;> assumption + +lemma sum_noiseSplit_cons_diag {D M : Type*} [AddCommMonoid M] (d : D) (F : List (Letter D)) + (f : List (Letter D)→List (Letter D)→M) : + (∑ s : NoiseSplit (.diag d::F), f s.before s.after)= + ∑ s : NoiseSplit F, f (.diag d::s.before) s.after := by + have hh := NoiseSplit.sum_append [Letter.diag d] F f + simpa using hh +lemma sum_noiseSplit_cons_noise {D M : Type*} [AddCommMonoid M] (F : List (Letter D)) + (f : List (Letter D)→List (Letter D)→M) : + (∑ s : NoiseSplit (.noise::F), f s.before s.after)= + f [] F+∑ s : NoiseSplit F, f (.noise::s.before) s.after := by + have hh := NoiseSplit.sum_append [Letter.noise] F f + have he : (default : NoiseSplit [Letter.noise (D := D)])=⟨[],[],rfl⟩ := Subsingleton.elim _ _ + simpa only [Fintype.sum_unique,he,List.nil_append,List.singleton_append] using hh + +lemma sum_wordPartners_lift {M : Type*} [AddCommMonoid M] (a : ι→ℝ) + (F : List (Letter (ι→ℝ))) (f : WordCut ι→M) : + ((wordPartners a (liftWord F)).map f).sum= + ∑ s : NoiseSplit F, f ⟨liftWord s.before,liftWord s.after,false⟩ := by + induction F generalizing f with + | nil => simp [wordPartners] + | cons l F ih => + cases l with + | diag d => + simp only [liftWord_cons,Letter.toWord,wordPartners,List.nil_append,List.map_map] + rw [ih,sum_noiseSplit_cons_diag d F (fun U V=>f ⟨liftWord U,liftWord V,false⟩)] + rfl + | noise => + simp only [liftWord_cons,Letter.toWord,wordPartners,List.singleton_append,List.map_cons, + List.sum_cons,List.map_map] + rw [ih,sum_noiseSplit_cons_noise F (fun U V=>f ⟨liftWord U,liftWord V,false⟩)] + rfl + +lemma sum_wordPartners_append {M : Type*} [AddCommMonoid M] (a : ι→ℝ) + (P Q : List (WordLetter ι)) (f : WordCut ι→M) : + ((wordPartners a (P++Q)).map f).sum= + ((wordPartners a P).map (fun c=>f ⟨c.left,c.right++Q,c.inversePartner⟩)).sum+ + ((wordPartners a Q).map (fun c=>f ⟨P++c.left,c.right,c.inversePartner⟩)).sum := by + induction P generalizing f with + | nil => simp [wordPartners] + | cons l P ih => + cases l <;> + simp only [List.cons_append,wordPartners,List.nil_append, + List.map_cons,List.sum_cons,List.map_map,Function.comp_def,WordCut.prepend] <;> + rw [ih] <;> simp only [add_assoc] + +lemma sum_wordPartners_oneInverse {M : Type*} [AddCommMonoid M] (a : ι→ℝ) + (P Q : List (Letter (ι→ℝ))) (f : WordCut ι→M) : + ((wordPartners a (liftWord P++(.inverse::liftWord Q))).map f).sum= + (∑ s : NoiseSplit P, f ⟨liftWord s.before,liftWord s.after++(.inverse::liftWord Q),false⟩)+ + f ⟨liftWord P++[.inverse,.diag a],[.inverse]++liftWord Q,true⟩+ + (∑ s : NoiseSplit Q, f ⟨liftWord P++(.inverse::liftWord s.before),liftWord s.after,false⟩) := by + rw [sum_wordPartners_append,sum_wordPartners_lift] + simp only [wordPartners,List.singleton_append,List.map_cons,List.sum_cons,List.map_map, + Function.comp_def,WordCut.prepend] + rw [sum_wordPartners_lift] + simp [add_assoc] + +end SKGap.Noncrossing + +noncomputable section +open scoped BigOperators + +end +end +end +end +end +end +end +end +end +end +end +end +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Matrix/InverseSubSquareMul.lean b/lean/OAI/Probability/SKGap/Matrix/InverseSubSquareMul.lean new file mode 100644 index 0000000000000000000000000000000000000000..e28b2898a165127e69bd6a0719cfd07be3a682b7 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Matrix/InverseSubSquareMul.lean @@ -0,0 +1,91 @@ +import Mathlib +import OAI.Probability.SKGap.Model + +namespace OAI + +section +noncomputable section +open MeasureTheory ProbabilityTheory InformationTheory Real Set +open scoped NNReal ENNReal +open Filter +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius ENNReal NNReal +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius NNReal +noncomputable section +open MeasureTheory ProbabilityTheory Real Set Filter +open MeasureTheory.Measure +open scoped ENNReal NNReal MeasureTheory Topology +open MeasureTheory +noncomputable section +noncomputable section +open MeasureTheory Set NormedSpace +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius +noncomputable section +open Set Real +open scoped Topology +noncomputable section +open Matrix Set Filter +open scoped Topology Matrix.Norms.Frobenius +noncomputable section +open Matrix NormedSpace ContinuousLinearMap +open scoped Matrix.Norms.Frobenius +noncomputable section +open Matrix +namespace SKGap.ResolventIdentity +variable {ι : Type*} [Fintype ι] [DecidableEq ι] +variable {𝕜 : Type*} [RCLike 𝕜] + +lemma inverse_one_sub_square_mul (D V : Matrix ι ι 𝕜) + (hS : IsUnit (1-D*V*D)) : + (1-D*D*V)⁻¹ = 1+D*(1-D*V*D)⁻¹*D*V := by + apply Matrix.inv_eq_right_inv + have hSS : (1-D*V*D)*(1-D*V*D)⁻¹ = 1 := + Matrix.mul_nonsing_inv _ (((1-D*V*D).isUnit_iff_isUnit_det).mp hS) + calc + _ = (1-D*D*V)+D*((1-D*V*D)*(1-D*V*D)⁻¹)*D*V := by noncomm_ring + _ = 1 := by rw [hSS]; noncomm_ring + +lemma inverse_one_sub_square_mul_unit (D V : Matrix ι ι 𝕜) + (hS : IsUnit (1-D*V*D)) : IsUnit (1-D*D*V) := by + have hSS : (1-D*V*D)*(1-D*V*D)⁻¹ = 1 := + Matrix.mul_nonsing_inv _ (((1-D*V*D).isUnit_iff_isUnit_det).mp hS) + apply ((1-D*D*V).isUnit_iff_isUnit_det).mpr + have hh : (1-D*D*V)*(1+D*(1-D*V*D)⁻¹*D*V) = 1 := by + calc + _ = (1-D*D*V)+D*((1-D*V*D)*(1-D*V*D)⁻¹)*D*V := by noncomm_ring + _ = 1 := by rw [hSS]; noncomm_ring + exact Matrix.isUnit_det_of_right_inverse hh + +lemma inverse_one_sub_square_mul_square (D V : Matrix ι ι 𝕜) + (hS : IsUnit (1-D*V*D)) : + (1-D*D*V)⁻¹*(D*D) = D*(1-D*V*D)⁻¹*D := by + rw [inverse_one_sub_square_mul D V hS] + have hSS : (1-D*V*D)⁻¹*(1-D*V*D) = 1 := + Matrix.nonsing_inv_mul _ (((1-D*V*D).isUnit_iff_isUnit_det).mp hS) + calc + _ = D*(1-D*V*D)⁻¹*D+D*(1-(1-D*V*D)⁻¹*(1-D*V*D))*D := by noncomm_ring + _ = _ := by rw [hSS]; simp + +end SKGap.ResolventIdentity + +end +end +end +end +end +end +end +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Matrix/LiftMatrix.lean b/lean/OAI/Probability/SKGap/Matrix/LiftMatrix.lean new file mode 100644 index 0000000000000000000000000000000000000000..c63de6c72cf228eda3b5f30b8a0f09e7b626ac14 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Matrix/LiftMatrix.lean @@ -0,0 +1,157 @@ +import Mathlib +import OAI.Probability.SKGap.Matrix.OpNorm + +namespace OAI + +section +noncomputable section +open MeasureTheory ProbabilityTheory InformationTheory Real Set +open scoped NNReal ENNReal +open Filter +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius ENNReal NNReal +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius NNReal +noncomputable section +open MeasureTheory ProbabilityTheory Real Set Filter +open MeasureTheory.Measure +open scoped ENNReal NNReal MeasureTheory Topology +open MeasureTheory +noncomputable section +noncomputable section +open MeasureTheory Set NormedSpace +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius +noncomputable section +open Set Real +open scoped Topology +noncomputable section +open Matrix Set Filter +open scoped Topology Matrix.Norms.Frobenius +noncomputable section +open Matrix NormedSpace ContinuousLinearMap +open scoped Matrix.Norms.Frobenius +noncomputable section +open Matrix +namespace SKGap.RealComplex +open scoped Matrix.Norms.Frobenius +variable {ι : Type*} [Fintype ι] [DecidableEq ι] + +def liftMatrix (M : Matrix ι ι ℝ) : Matrix ι ι ℂ := M.map Complex.ofReal +abbrev clin (M : Matrix ι ι ℂ) := M.toEuclideanLin.toContinuousLinearMap +abbrev rlin (M : Matrix ι ι ℝ) := M.toEuclideanLin.toContinuousLinearMap + +def reVec (x : EuclideanSpace ℂ ι) : EuclideanSpace ℝ ι := + WithLp.toLp 2 (fun i => (x i).re) +def imVec (x : EuclideanSpace ℂ ι) : EuclideanSpace ℝ ι := + WithLp.toLp 2 (fun i => (x i).im) +def liftVec (x : EuclideanSpace ℝ ι) : EuclideanSpace ℂ ι := + WithLp.toLp 2 (fun i => (x i : ℂ)) + +omit [DecidableEq ι] in +lemma vec_norm_split (x : EuclideanSpace ℂ ι) : + ‖x‖^2 = ‖reVec x‖^2+‖imVec x‖^2 := by + simp only [EuclideanSpace.norm_sq_eq,← Finset.sum_add_distrib] + apply Finset.sum_congr rfl + intro i _ + change ‖x i‖^2 = ‖(x i).re‖^2+‖(x i).im‖^2 + rw [Complex.sq_norm,Complex.normSq_apply] + simp only [Real.norm_eq_abs] + rw [sq_abs,sq_abs] + ring + +omit [DecidableEq ι] in +lemma norm_liftVec (x : EuclideanSpace ℝ ι) : ‖liftVec x‖ = ‖x‖ := by + have hh : ‖liftVec x‖^2 = ‖x‖^2 := by simp [EuclideanSpace.norm_sq_eq,liftVec] + nlinarith [norm_nonneg (liftVec x),norm_nonneg x] + +lemma reVec_clin (M : Matrix ι ι ℝ) (x : EuclideanSpace ℂ ι) : + reVec (clin (liftMatrix M) x) = rlin M (reVec x) := by + ext i + change (∑ j, (M i j : ℂ)*x j).re = ∑ j, M i j*(x j).re + simp + +lemma imVec_clin (M : Matrix ι ι ℝ) (x : EuclideanSpace ℂ ι) : + imVec (clin (liftMatrix M) x) = rlin M (imVec x) := by + ext i + change (∑ j, (M i j : ℂ)*x j).im = ∑ j, M i j*(x j).im + simp + +lemma clin_liftVec (M : Matrix ι ι ℝ) (x : EuclideanSpace ℝ ι) : + clin (liftMatrix M) (liftVec x) = liftVec (rlin M x) := by + ext i + change (∑ j, (M i j : ℂ)*(x j : ℂ)) = ((∑ j, M i j*x j : ℝ) : ℂ) + simp + +lemma operator_norm_lift (M : Matrix ι ι ℝ) : ‖clin (liftMatrix M)‖ = opNorm M := by + apply le_antisymm + · apply ContinuousLinearMap.opNorm_le_bound _ (norm_nonneg _) + intro x + apply nonneg_le_nonneg_of_sq_le_sq (mul_nonneg (norm_nonneg _) (norm_nonneg _)) + simp only [← sq] + change ‖clin (liftMatrix M) x‖^2 ≤ (opNorm M*‖x‖)^2 + rw [vec_norm_split,reVec_clin,imVec_clin,mul_pow,vec_norm_split,mul_add] + have hr := (rlin M).le_opNorm (reVec x) + have hi := (rlin M).le_opNorm (imVec x) + change ‖rlin M (reVec x)‖ ≤ opNorm M*‖reVec x‖ at hr + change ‖rlin M (imVec x)‖ ≤ opNorm M*‖imVec x‖ at hi + nlinarith [norm_nonneg (rlin M (reVec x)),norm_nonneg (rlin M (imVec x)), + mul_nonneg (norm_nonneg (rlin M)) (norm_nonneg (reVec x)), + mul_nonneg (norm_nonneg (rlin M)) (norm_nonneg (imVec x))] + · apply ContinuousLinearMap.opNorm_le_bound _ (norm_nonneg _) + intro x + have hh := (clin (liftMatrix M)).le_opNorm (liftVec x) + rwa [clin_liftVec,norm_liftVec,norm_liftVec] at hh + +lemma norm_liftMatrix (M : Matrix ι ι ℝ) : ‖liftMatrix M‖ = ‖M‖ := + Matrix.frobenius_norm_map_eq M Complex.ofReal (fun x => by simp) + +omit [Fintype ι] [DecidableEq ι] in +lemma liftMatrix_sub (M N : Matrix ι ι ℝ) : + liftMatrix (M-N) = liftMatrix M-liftMatrix N := by ext i j; simp [liftMatrix] +omit [Fintype ι] [DecidableEq ι] in +lemma liftMatrix_add (M N : Matrix ι ι ℝ) : + liftMatrix (M+N) = liftMatrix M+liftMatrix N := by ext i j; simp [liftMatrix] +omit [DecidableEq ι] in +lemma liftMatrix_mul (M N : Matrix ι ι ℝ) : + liftMatrix (M*N) = liftMatrix M*liftMatrix N := by + exact Matrix.map_mul (f := Complex.ofRealHom) +omit [Fintype ι] in +lemma liftMatrix_one : liftMatrix (1 : Matrix ι ι ℝ) = 1 := + Matrix.map_one Complex.ofReal (by simp) (by simp) +omit [Fintype ι] [DecidableEq ι] in +lemma liftMatrix_smul (s : ℝ) (M : Matrix ι ι ℝ) : + liftMatrix (s • M) = s • liftMatrix M := by ext i j; simp [liftMatrix] +omit [Fintype ι] [DecidableEq ι] in +lemma liftMatrix_conjTranspose (M : Matrix ι ι ℝ) : + (liftMatrix M)ᴴ = liftMatrix Mᵀ := by ext i j; simp [liftMatrix] +omit [Fintype ι] [DecidableEq ι] in +lemma liftMatrix_hermitian (M : Matrix ι ι ℝ) (hM : Mᵀ = M) : + (liftMatrix M)ᴴ = liftMatrix M := by rw [liftMatrix_conjTranspose,hM] +omit [Fintype ι] [DecidableEq ι] in +lemma liftMatrix_injective : Function.Injective (liftMatrix (ι := ι)) := by + intro M N h + ext i j + exact Complex.ofReal_injective (congrFun (congrFun h i) j) + +end SKGap.RealComplex + +end +end +end +end +end +end +end +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Matrix/LipschitzNormedConvolution.lean b/lean/OAI/Probability/SKGap/Matrix/LipschitzNormedConvolution.lean new file mode 100644 index 0000000000000000000000000000000000000000..3af5c909f803f7db4cc8b9700f94e8c7b0e0793d --- /dev/null +++ b/lean/OAI/Probability/SKGap/Matrix/LipschitzNormedConvolution.lean @@ -0,0 +1,438 @@ +import Mathlib +import OAI.Probability.SKGap.Model + +namespace OAI + +section +noncomputable section +open MeasureTheory ProbabilityTheory InformationTheory Real Set +open scoped NNReal ENNReal +open Filter +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius ENNReal NNReal +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius NNReal +noncomputable section +open MeasureTheory ProbabilityTheory Real Set Filter +open MeasureTheory.Measure +open scoped ENNReal NNReal MeasureTheory Topology +namespace SKGap + +section Smoothing +open NormedSpace +open scoped Convolution ContDiff +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] + [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] + +theorem lipschitz_normed_convolution {f : E → ℝ} {L : ℝ≥0} + (hf : LipschitzWith L f) (φ : ContDiffBump (0 : E)) + (μ : Measure E) [μ.IsAddHaarMeasure] : + LipschitzWith L (φ.normed μ ⋆[ContinuousLinearMap.lsmul ℝ ℝ, μ] f) := by + have hcv : ConvolutionExists (φ.normed μ) f (ContinuousLinearMap.lsmul ℝ ℝ) μ := + (φ.hasCompactSupport_normed (μ := μ)).convolutionExists_left + (ContinuousLinearMap.lsmul ℝ ℝ) φ.continuous_normed + (hf.continuous.locallyIntegrable (μ := μ)) + apply LipschitzWith.of_dist_le_mul + intro x y + simp only [dist_eq_norm, convolution_def, ContinuousLinearMap.lsmul_apply, smul_eq_mul] + have hx : Integrable (fun t => φ.normed μ t * f (x - t)) μ := hcv x + have hy : Integrable (fun t => φ.normed μ t * f (y - t)) μ := hcv y + rw [← integral_sub hx hy] + calc + _ ≤ ∫ t, φ.normed μ t * ((L : ℝ) * ‖x - y‖) ∂μ := by + apply norm_integral_le_of_norm_le (φ.integrable_normed.mul_const _) + filter_upwards [] with t + rw [← mul_sub, norm_mul, Real.norm_eq_abs (φ.normed μ t), + abs_of_nonneg (φ.nonneg_normed _)] + apply mul_le_mul_of_nonneg_left _ (φ.nonneg_normed _) + simpa only [sub_sub_sub_cancel_right] using hf.norm_sub_le (x - t) (y - t) + _ = (L : ℝ) * ‖x - y‖ := by rw [integral_mul_const, φ.integral_normed, one_mul] + +theorem exists_smooth_lipschitz_approx {f : E → ℝ} {L : ℝ≥0} + (hf : LipschitzWith L f) {ε : ℝ} (hε : 0 < ε) : + ∃ g : E → ℝ, ContDiff ℝ ∞ g ∧ LipschitzWith L g ∧ + ∀ x, dist (g x) (f x) ≤ (L : ℝ) * ε := by + let μ : Measure E := addHaar + let φ : ContDiffBump (0 : E) := ⟨ε / 2, ε, half_pos hε, half_lt_self hε⟩ + let g := φ.normed μ ⋆[ContinuousLinearMap.lsmul ℝ ℝ, μ] f + refine ⟨g, ?_, lipschitz_normed_convolution hf φ μ, ?_⟩ + · exact φ.hasCompactSupport_normed.contDiff_convolution_left + (ContinuousLinearMap.lsmul ℝ ℝ) φ.contDiff_normed hf.continuous.locallyIntegrable + · intro x + apply ContDiffBump.dist_normed_convolution_le hf.continuous.aestronglyMeasurable + intro y hy + apply (hf.dist_le_mul y x).trans + exact mul_le_mul_of_nonneg_left (Metric.mem_ball.mp hy).le L.coe_nonneg + +end Smoothing + +section GaussianMoments +variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] + [MeasurableSpace E] [BorelSpace E] [SecondCountableTopology E] [CompleteSpace E] + {μ : Measure E} [IsGaussian μ] + +theorem gaussian_integrable_exp_norm (a : ℝ) : + Integrable (fun x : E => exp (a * ‖x‖)) μ := by + obtain ⟨C, hC, hI⟩ := IsGaussian.exists_integrable_exp_sq μ + apply (hI.const_mul (exp (a ^ 2 / (4 * C)))).mono' (by fun_prop) + filter_upwards [] with x + rw [Real.norm_eq_abs, abs_of_pos (exp_pos _), ← exp_add] + apply exp_le_exp.mpr + have hs := sq_nonneg (‖x‖ - a / (2 * C)) + have hC0 : C ≠ 0 := ne_of_gt hC + have heq : C * (‖x‖ - a / (2 * C)) ^ 2 = + C * ‖x‖ ^ 2 - a * ‖x‖ + a ^ 2 / (4 * C) := by field_simp; ring + nlinarith [mul_nonneg (le_of_lt hC) hs] + +end GaussianMoments + +section StandardGaussian +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] + [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] + +theorem stdGaussian_map_dual (L : StrongDual ℝ E) : + (stdGaussian E).map L = gaussianReal 0 (Real.toNNReal (‖L‖ ^ 2)) := by + rw [IsGaussian.map_eq_gaussianReal, integral_strongDual_stdGaussian, + variance_dual_stdGaussian] + +theorem stdGaussian_integrable_exp_dual (L : StrongDual ℝ E) (r : ℝ) : + Integrable (fun x => exp (r * L x)) (stdGaussian E) := by + have h := integrable_exp_mul_gaussianReal (μ := 0) + (v := Real.toNNReal (‖L‖ ^ 2)) r + rw [← stdGaussian_map_dual L] at h + exact h.comp_measurable L.continuous.measurable + +theorem stdGaussian_integral_exp_dual (L : StrongDual ℝ E) (r : ℝ) : + (∫ x, exp (r * L x) ∂stdGaussian E) = exp (r ^ 2 * ‖L‖ ^ 2 / 2) := by + have hm := mgf_gaussianReal + ⟨L.continuous.measurable.aemeasurable, stdGaussian_map_dual L⟩ r + simpa [mgf, Real.toNNReal_of_nonneg (sq_nonneg _), mul_div_assoc, mul_comm] using hm + +theorem gaussian_integrable_exp_lipschitz {μ : Measure E} [IsGaussian μ] + {f : E → ℝ} {L : ℝ≥0} (hf : LipschitzWith L f) (r : ℝ) : + Integrable (fun x => exp (r * f x)) μ := by + have hfc := hf.continuous + have hI := (gaussian_integrable_exp_norm (μ := μ) (|r| * L)).const_mul + (exp (|r| * |f 0|)) + apply hI.mono' (by fun_prop) + filter_upwards [] with x + rw [Real.norm_eq_abs, abs_of_pos (exp_pos _), ← exp_add] + apply exp_le_exp.mpr + have hx : |f x| ≤ |f 0| + L * ‖x‖ := by + have hh := hf.norm_sub_le x 0 + simp only [sub_zero, Real.norm_eq_abs] at hh + have ht := abs_add_le (f x - f 0) (f 0) + rw [sub_add_cancel] at ht + linarith + calc + r * f x ≤ |r * f x| := le_abs_self _ + _ = |r| * |f x| := abs_mul _ _ + _ ≤ |r| * (|f 0| + L * ‖x‖) := mul_le_mul_of_nonneg_left hx (abs_nonneg _) + _ = _ := by ring + +theorem gaussian_integrable_lipschitz {μ : Measure E} [IsGaussian μ] + {f : E → ℝ} {L : ℝ≥0} (hf : LipschitzWith L f) : Integrable f μ := by + have hI := ((IsGaussian.integrable_id (μ := μ)).norm.const_mul (L : ℝ)).add + (integrable_const |f 0|) + apply hI.mono' hf.continuous.aestronglyMeasurable + filter_upwards [] with x + change |f x| ≤ (L : ℝ) * ‖x‖ + |f 0| + have hh := hf.norm_sub_le x 0 + simp only [sub_zero, Real.norm_eq_abs] at hh ⊢ + have ht := abs_add_le (f x - f 0) (f 0) + rw [sub_add_cancel] at ht + linarith + +end StandardGaussian + +theorem exp_interval_average_le {a : ℝ} (ha : 0 < a) {g : ℝ → ℝ} + (hg : Continuous g) : + exp (a⁻¹ * ∫ t in (0 : ℝ)..a, g t) ≤ + a⁻¹ * ∫ t in (0 : ℝ)..a, exp (g t) := by + have h0 : volume (Icc (0 : ℝ) a) ≠ 0 := by + rw [volume_Icc, sub_zero, ENNReal.ofReal_ne_zero_iff] + exact ha + have ht : volume (Icc (0 : ℝ) a) ≠ ∞ := by simp + have hJ := convexOn_exp.map_set_average_le continuous_exp.continuousOn isClosed_univ + h0 ht (by filter_upwards [] with x; exact mem_univ _) + hg.integrableOn_Icc (continuous_exp.comp hg).integrableOn_Icc + have hvol : volume.real (Icc (0 : ℝ) a) = a := by + simp [measureReal_def, volume_Icc, ha.le] + simpa only [setAverage_eq, hvol, smul_eq_mul, + integral_Icc_eq_integral_Ioc, ← intervalIntegral.integral_of_le ha.le] using hJ + +section Rotation +variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] + +theorem rotation_snd_norm_le (θ : ℝ) (p : E × E) : + ‖(ContinuousLinearMap.rotation θ p).2‖ ≤ ‖p.1‖ + ‖p.2‖ := by + rw [ContinuousLinearMap.rotation_apply] + calc + ‖-sin θ • p.1 + cos θ • p.2‖ ≤ ‖-sin θ • p.1‖ + ‖cos θ • p.2‖ := norm_add_le _ _ + _ = |sin θ| * ‖p.1‖ + |cos θ| * ‖p.2‖ := by simp [norm_smul, Real.norm_eq_abs] + _ ≤ 1 * ‖p.1‖ + 1 * ‖p.2‖ := + add_le_add (mul_le_mul_of_nonneg_right (abs_sin_le_one _) (norm_nonneg _)) + (mul_le_mul_of_nonneg_right (abs_cos_le_one _) (norm_nonneg _)) + _ = _ := by ring + +theorem hasDerivAt_rotation_fst (θ : ℝ) (p : E × E) : + HasDerivAt (fun t => (ContinuousLinearMap.rotation t p).1) + (ContinuousLinearMap.rotation θ p).2 θ := by + exact ((hasDerivAt_cos θ).smul_const p.1).add + ((hasDerivAt_sin θ).smul_const p.2) + +theorem rotation_fundamental_theorem {f : E → ℝ} {df : E → StrongDual ℝ E} + (hf : ∀ x, HasFDerivAt f (df x) x) (hdf : Continuous df) (p : E × E) : + (∫ θ in (0 : ℝ)..π / 2, + df (ContinuousLinearMap.rotation θ p).1 (ContinuousLinearMap.rotation θ p).2) = + f p.2 - f p.1 := by + have hd : ∀ θ, HasDerivAt (fun t => f (ContinuousLinearMap.rotation t p).1) + (df (ContinuousLinearMap.rotation θ p).1 (ContinuousLinearMap.rotation θ p).2) θ := + fun θ => (hf _).comp_hasDerivAt θ (hasDerivAt_rotation_fst θ p) + have hc : Continuous (fun θ => + df (ContinuousLinearMap.rotation θ p).1 (ContinuousLinearMap.rotation θ p).2) := by + simp only [ContinuousLinearMap.rotation_apply] + fun_prop + have hi := intervalIntegral.integral_eq_sub_of_hasDerivAt (fun θ _ => hd θ) + (hc.intervalIntegrable 0 (π / 2)) + simpa [ContinuousLinearMap.rotation_apply] using hi + +theorem rotation_exp_difference_le {f : E → ℝ} {df : E → StrongDual ℝ E} + (hf : ∀ x, HasFDerivAt f (df x) x) (hdf : Continuous df) (r : ℝ) (p : E × E) : + exp (r * (f p.2 - f p.1)) ≤ (π / 2)⁻¹ * + ∫ θ in (0 : ℝ)..π / 2, exp (r * (π / 2) * + df (ContinuousLinearMap.rotation θ p).1 (ContinuousLinearMap.rotation θ p).2) := by + have hc : Continuous (fun θ => r * (π / 2) * + df (ContinuousLinearMap.rotation θ p).1 (ContinuousLinearMap.rotation θ p).2) := by + simp only [ContinuousLinearMap.rotation_apply] + fun_prop + have hJ := exp_interval_average_le (half_pos pi_pos) hc + rw [intervalIntegral.integral_const_mul, rotation_fundamental_theorem hf hdf] at hJ + convert hJ using 1 + congr 1 + field_simp + +theorem exp_dual_le {L : ℝ≥0} (D : StrongDual ℝ E) (hD : ‖D‖ ≤ L) (r : ℝ) (y : E) : + exp (r * D y) ≤ exp (|r| * L * ‖y‖) := by + apply exp_le_exp.mpr + calc + r * D y ≤ |r * D y| := le_abs_self _ + _ = |r| * ‖D y‖ := by rw [abs_mul, Real.norm_eq_abs] + _ ≤ |r| * (‖D‖ * ‖y‖) := mul_le_mul_of_nonneg_left (D.le_opNorm y) (abs_nonneg _) + _ ≤ |r| * ((L : ℝ) * ‖y‖) := by gcongr + _ = _ := by ring + +theorem rotation_exp_dual_le {L : ℝ≥0} {df : E → StrongDual ℝ E} + (hdf : ∀ x, ‖df x‖ ≤ L) (r θ : ℝ) (p : E × E) : + exp (r * df (ContinuousLinearMap.rotation θ p).1 (ContinuousLinearMap.rotation θ p).2) ≤ + exp (|r| * L * ‖p.1‖) * exp (|r| * L * ‖p.2‖) := by + calc + _ ≤ exp (|r| * L * ‖(ContinuousLinearMap.rotation θ p).2‖) := exp_dual_le _ (hdf _) _ _ + _ ≤ exp (|r| * L * (‖p.1‖ + ‖p.2‖)) := by + gcongr + exact rotation_snd_norm_le θ p + _ = _ := by rw [mul_add, exp_add] + +end Rotation + +section StandardGaussianRotation +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] + [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] + +theorem stdGaussian_integrable_variable_dual {df : E → StrongDual ℝ E} (hc : Continuous df) + {L : ℝ≥0} (hdf : ∀ x, ‖df x‖ ≤ L) (r : ℝ) : + Integrable (fun p : E × E => exp (r * df p.1 p.2)) + ((stdGaussian E).prod (stdGaussian E)) := by + apply ((gaussian_integrable_exp_norm (μ := stdGaussian E) (|r| * L)).comp_snd + (stdGaussian E)).mono' (by fun_prop) + filter_upwards [] with p + rw [Real.norm_eq_abs, abs_of_pos (exp_pos _)] + exact exp_dual_le _ (hdf _) _ _ + +theorem stdGaussian_integral_variable_dual_le {df : E → StrongDual ℝ E} (hc : Continuous df) + {L : ℝ≥0} (hdf : ∀ x, ‖df x‖ ≤ L) (r : ℝ) : + (∫ p : E × E, exp (r * df p.1 p.2) ∂(stdGaussian E).prod (stdGaussian E)) ≤ + exp (r ^ 2 * (L : ℝ) ^ 2 / 2) := by + have hi := stdGaussian_integrable_variable_dual hc hdf r + have hio := hi.integral_prod_left + simp only [stdGaussian_integral_exp_dual] at hio + rw [integral_prod _ hi] + simp only [stdGaussian_integral_exp_dual] + calc + _ ≤ ∫ _x : E, exp (r ^ 2 * (L : ℝ) ^ 2 / 2) ∂stdGaussian E := by + apply integral_mono hio (integrable_const _) + intro x + apply exp_le_exp.mpr + gcongr + exact hdf x + _ = _ := by simp + +theorem stdGaussian_integral_rotation_variable_dual_le {df : E → StrongDual ℝ E} + (hc : Continuous df) {L : ℝ≥0} (hdf : ∀ x, ‖df x‖ ≤ L) (r θ : ℝ) : + (∫ p : E × E, exp (r * df (ContinuousLinearMap.rotation θ p).1 + (ContinuousLinearMap.rotation θ p).2) ∂(stdGaussian E).prod (stdGaussian E)) ≤ + exp (r ^ 2 * (L : ℝ) ^ 2 / 2) := by + have hm := IsGaussian.map_rotation_eq_self (μ := stdGaussian E) (by simp) θ + rw [← integral_map (ContinuousLinearMap.rotation θ).continuous.aemeasurable + (f := fun p : E × E => exp (r * df p.1 p.2)) (by fun_prop), hm] + exact stdGaussian_integral_variable_dual_le hc hdf r + +theorem stdGaussian_integrable_rotation_variable_dual {df : E → StrongDual ℝ E} + (hc : Continuous df) {L : ℝ≥0} (hdf : ∀ x, ‖df x‖ ≤ L) (r : ℝ) + (ν : Measure ℝ) [IsFiniteMeasure ν] : + Integrable (fun z : ℝ × (E × E) => + exp (r * df (ContinuousLinearMap.rotation z.1 z.2).1 + (ContinuousLinearMap.rotation z.1 z.2).2)) + (ν.prod ((stdGaussian E).prod (stdGaussian E))) := by + have hI := gaussian_integrable_exp_norm (μ := stdGaussian E) (|r| * L) + apply ((hI.mul_prod hI).comp_snd ν).mono' + · simp only [ContinuousLinearMap.rotation_apply] + fun_prop + · filter_upwards [] with z + rw [Real.norm_eq_abs, abs_of_pos (exp_pos _)] + exact rotation_exp_dual_le hdf _ _ _ + +omit [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] in +theorem lipschitz_of_bounded_derivative {f : E → ℝ} {df : E → StrongDual ℝ E} + (hf : ∀ x, HasFDerivAt f (df x) x) {L : ℝ≥0} (hdf : ∀ x, ‖df x‖ ≤ L) : + LipschitzWith L f := by + apply lipschitzWith_of_nnnorm_fderiv_le (fun x => (hf x).differentiableAt) + intro x + rw [(hf x).fderiv] + exact hdf x + +lemma exp_mul_sub (r a b : ℝ) : exp (r * (a - b)) = exp (-r * b) * exp (r * a) := by + rw [← exp_add] + congr 1 + ring + +theorem stdGaussian_integrable_exp_difference {f : E → ℝ} {L : ℝ≥0} + (hf : LipschitzWith L f) (r : ℝ) : + Integrable (fun p : E × E => exp (r * (f p.2 - f p.1))) + ((stdGaussian E).prod (stdGaussian E)) := by + simp_rw [exp_mul_sub] + exact (gaussian_integrable_exp_lipschitz hf (-r)).mul_prod + (gaussian_integrable_exp_lipschitz hf r) + +theorem stdGaussian_mgf_difference_le {f : E → ℝ} {df : E → StrongDual ℝ E} + (hf : ∀ x, HasFDerivAt f (df x) x) (hc : Continuous df) + {L : ℝ≥0} (hdf : ∀ x, ‖df x‖ ≤ L) (r : ℝ) : + (∫ p : E × E, exp (r * (f p.2 - f p.1)) ∂(stdGaussian E).prod (stdGaussian E)) ≤ + exp (π ^ 2 * r ^ 2 * (L : ℝ) ^ 2 / 8) := by + let ν : Measure ℝ := volume.restrict (Ioc (0 : ℝ) (π / 2)) + have hν : IsFiniteMeasure ν := by dsimp [ν]; infer_instance + let R := r * (π / 2) + let G : ℝ → E × E → ℝ := fun θ p => exp (R * + df (ContinuousLinearMap.rotation θ p).1 (ContinuousLinearMap.rotation θ p).2) + have hI : Integrable (Function.uncurry G) (ν.prod ((stdGaussian E).prod (stdGaussian E))) := + stdGaussian_integrable_rotation_variable_dual hc hdf R ν + have hD := stdGaussian_integrable_exp_difference (lipschitz_of_bounded_derivative hf hdf) r + have hpos : 0 < π / 2 := half_pos pi_pos + have hvol : ν.real univ = π / 2 := by + simp [ν, measureReal_def, Real.volume_Ioc, hpos.le] + have hpoint (p : E × E) : exp (r * (f p.2 - f p.1)) ≤ + (π / 2)⁻¹ * ∫ θ, G θ p ∂ν := by + simpa only [intervalIntegral.integral_of_le hpos.le] using rotation_exp_difference_le hf hc r p + calc + _ ≤ ∫ p : E × E, (π / 2)⁻¹ * (∫ θ, G θ p ∂ν) + ∂(stdGaussian E).prod (stdGaussian E) := + integral_mono hD (hI.integral_prod_right.const_mul _) hpoint + _ = (π / 2)⁻¹ * ∫ θ, (∫ p : E × E, G θ p + ∂(stdGaussian E).prod (stdGaussian E)) ∂ν := by + rw [integral_const_mul, ← integral_integral_swap hI] + _ ≤ (π / 2)⁻¹ * ∫ _θ, exp (R ^ 2 * (L : ℝ) ^ 2 / 2) ∂ν := by + apply mul_le_mul_of_nonneg_left _ (inv_nonneg.mpr hpos.le) + apply integral_mono hI.integral_prod_left (integrable_const _) + intro θ + exact stdGaussian_integral_rotation_variable_dual_le hc hdf R θ + _ = exp (π ^ 2 * r ^ 2 * (L : ℝ) ^ 2 / 8) := by + rw [integral_const, smul_eq_mul, hvol, ← mul_assoc, inv_mul_cancel₀ hpos.ne', one_mul] + congr 1 + dsimp [R] + ring + +theorem stdGaussian_mgf_centered_le {f : E → ℝ} {df : E → StrongDual ℝ E} + (hf : ∀ x, HasFDerivAt f (df x) x) (hc : Continuous df) + {L : ℝ≥0} (hdf : ∀ x, ‖df x‖ ≤ L) (r : ℝ) : + (∫ x, exp (r * (f x - ∫ y, f y ∂stdGaussian E)) ∂stdGaussian E) ≤ + exp (π ^ 2 * r ^ 2 * (L : ℝ) ^ 2 / 8) := by + have hLip := lipschitz_of_bounded_derivative hf hdf + have hF := gaussian_integrable_lipschitz (μ := stdGaussian E) hLip + have hG := gaussian_integrable_exp_lipschitz (μ := stdGaussian E) hLip (-r) + have hpair := stdGaussian_integrable_exp_difference hLip (-r) + have hcenter : Integrable (fun x => exp (r * (f x - ∫ y, f y ∂stdGaussian E))) + (stdGaussian E) := by + simp_rw [exp_mul_sub] + exact (gaussian_integrable_exp_lipschitz hLip r).const_mul _ + have hj (x : E) : exp (r * (f x - ∫ y, f y ∂stdGaussian E)) ≤ + ∫ y, exp (r * (f x - f y)) ∂stdGaussian E := by + have hsub := ((integrable_const (f x)).sub hF).const_mul r + have he : Integrable (fun y => exp (r * (f x - f y))) (stdGaussian E) := by + simp_rw [exp_mul_sub] + exact hG.mul_const _ + have h := convexOn_exp.map_integral_le continuous_exp.continuousOn isClosed_univ + (by filter_upwards [] with y; exact mem_univ _) hsub he + simp only [Pi.sub_apply] at h + simpa only [integral_const_mul, integral_sub (integrable_const _) hF, + integral_const, probReal_univ, one_smul] using h + have heq (x y : E) : r * (f x - f y) = -r * (f y - f x) := by ring + simp_rw [heq] at hj + calc + _ ≤ ∫ x, (∫ y, exp (-r * (f y - f x)) ∂stdGaussian E) ∂stdGaussian E := + integral_mono hcenter hpair.integral_prod_left hj + _ = ∫ p : E × E, exp (-r * (f p.2 - f p.1)) + ∂(stdGaussian E).prod (stdGaussian E) := (integral_prod _ hpair).symm + _ ≤ exp (π ^ 2 * r ^ 2 * (L : ℝ) ^ 2 / 8) := by + simpa using stdGaussian_mgf_difference_le hf hc hdf (-r) + +theorem centered_mgf_le_of_uniform_dist {f g : E → ℝ} {L M : ℝ≥0} + (hf : LipschitzWith L f) (hg : LipschitzWith M g) {δ : ℝ} + (hfg : ∀ x, dist (f x) (g x) ≤ δ) (r : ℝ) : + (∫ x, exp (r * (f x - ∫ y, f y ∂stdGaussian E)) ∂stdGaussian E) ≤ + exp (2 * |r| * δ) * + (∫ x, exp (r * (g x - ∫ y, g y ∂stdGaussian E)) ∂stdGaussian E) := by + let μ := stdGaussian E + have hfi : Integrable f μ := gaussian_integrable_lipschitz hf + have hgi : Integrable g μ := gaussian_integrable_lipschitz hg + have hmean : |(∫ y, f y ∂μ) - ∫ y, g y ∂μ| ≤ δ := by + have hi : ‖∫ x, f x - g x ∂μ‖ ≤ δ * μ.real univ := + norm_integral_le_of_norm_le_const (μ := μ) + (Eventually.of_forall (fun x => by simpa only [dist_eq_norm] using hfg x)) + rw [integral_sub hfi hgi] at hi + simpa only [Real.norm_eq_abs, probReal_univ, mul_one] using hi + have he (h : E → ℝ) {K : ℝ≥0} (hh : LipschitzWith K h) : + Integrable (fun x => exp (r * (h x - ∫ y, h y ∂μ))) μ := by + simp_rw [exp_mul_sub] + exact (gaussian_integrable_exp_lipschitz hh r).const_mul _ + rw [← integral_const_mul] + apply integral_mono (he f hf) ((he g hg).const_mul _) + intro x + dsimp only + rw [← exp_add] + apply exp_le_exp.mpr + have hdiff : |(f x - ∫ y, f y ∂μ) - (g x - ∫ y, g y ∂μ)| ≤ 2 * δ := by + have hx : |f x - g x| ≤ δ := by simpa only [Real.dist_eq] using hfg x + calc + _ = |(f x - g x) - ((∫ y, f y ∂μ) - ∫ y, g y ∂μ)| := by congr 1; ring + _ ≤ |f x - g x| + |(∫ y, f y ∂μ) - ∫ y, g y ∂μ| := by + simpa only [Real.norm_eq_abs] using norm_sub_le + (f x - g x) ((∫ y, f y ∂μ) - ∫ y, g y ∂μ) + _ ≤ 2 * δ := by linarith + have hh := le_abs_self (r * ((f x - ∫ y, f y ∂μ) - (g x - ∫ y, g y ∂μ))) + rw [abs_mul] at hh + have hb := mul_le_mul_of_nonneg_left hdiff (abs_nonneg r) + dsimp [μ] at * + nlinarith + +end StandardGaussianRotation +end SKGap +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Matrix/LiteralTrace.lean b/lean/OAI/Probability/SKGap/Matrix/LiteralTrace.lean new file mode 100644 index 0000000000000000000000000000000000000000..112d476f756e0a416652999e1f87d7bea1cda423 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Matrix/LiteralTrace.lean @@ -0,0 +1,187 @@ +import Mathlib +import OAI.Probability.SKGap.Stability.LiteralStableControl +import OAI.Probability.SKGap.Localization.LiteralRegularity +import OAI.Probability.SKGap.Stability.ImplicitTraceControl +import OAI.Probability.SKGap.Localization.LiteralPartial + +namespace OAI + +section + +noncomputable section +open scoped BigOperators Matrix.Norms.Frobenius +namespace SKGapCutoff.Recipe +open SKGap.Stein Primary +variable {n : ℕ} + +def initialPartialBudget (f : KernelExpr) (R T B : ℝ) : ℝ := + B*ratioSmallBudget (.kernel phiExpr.dz) T+ + ratioSmallBudget ((RatioExpr.kernel f).d .z) T*kernelSmallBudget phiExpr R T + +def initialTraceFactor (Q T B : ℝ) : ℝ := + (T+B)+4*(Q^2+T*(T+B)+(T+B)^2)+2*(Q+T+(T+B)) + +lemma literalInitial_parameter (J : Interaction n) (j d : ℝ) (f : KernelExpr) + (z m : VectorFields n) (a c : Spin n→ℝ) (r e : Fin n→ℝ) (x : Spin n) : + (∑α,‖derivativeVector ((literalInitial J j d f z m a c r e).θ α) x‖)= + ‖derivativeVector a x‖+‖derivativeVector (fun v=>d*c v) x‖ := by + simp only [Fintype.sum_bool,literalInitial,Bool.false_eq_true,ite_false,ite_true] + ring + +lemma literalInitial_traces (J : Interaction n) (j : ℝ) (f : KernelExpr) + (z m w y : VectorFields n) (a c : Spin n→ℝ) (r e : Fin n→ℝ) (x : Spin n) + (t : SKGap.Noncrossing.Primary.SourceTree (Fin n→ℝ)) (hn : 0Real.sqrt n*c v) x‖≤B) + (hw : w x=(literalInitial J j (Real.sqrt n) f z m a c r e).sourceOf 1 (fun _=>y) x) + (hwf : ∀k,w (flip x k)=(literalInitial J j (Real.sqrt n) f z m a c r e).sourceOf 1 (fun _=>y) (flip x k)) + (hEz : ‖derivativeMatrix z x-t.fieldMatrix j J‖≤E) + (hEm : ‖derivativeMatrix m x-t.sourceMatrix j J‖≤E) + (hQ4 : (∑i,∑k,(derivativeMatrix z x i k)^4)≤Q^4) + (hdiag : (∑i,(derivativeMatrix z x i i)^2)≤T^2) : + let D:=literalInitial J j (Real.sqrt n) f z m a c r e + let C:=initialRegularBudget f j R Bs + let Cp:=initialPartialBudget f R T B + TraceControl (D.implicitSourcePrimitive t y x) + ((2*C+C*B)*initialTraceFactor Q T B+Cp*E) ∧ + TraceControl (D.implicitFieldPrimitive t w y x) + (|j| *(Cp*E)+|j| *(Cp*(1+2*T)+3*B*((phiExpr.dBudget R+phiExpr.ddBudget R)*T))) := by + let D:=literalInitial J j (Real.sqrt n) f z m a c r e + let C:=initialRegularBudget f j R Bs + have hd : Real.sqrt (n:ℝ)≠0:=(Real.sqrt_pos.mpr (Nat.cast_pos.mpr hn)).ne' + have hp:=literalInitial_partial_small J j (Real.sqrt n) f z m w y a c r e x hd hT he ha haf hD hW hw hwf + obtain ⟨hreg,har⟩:=literalInitial_regular J j (Real.sqrt n) f z m a c r e x hBs ha haf hc hcf + have hC : 0≤ initialRegularBudget f j R Bs:=(hreg false).nonneg + have hparam : (∑α,‖derivativeVector (D.θ α) x‖)≤T+B := by + rw [literalInitial_parameter] + exact add_le_add (by linarith [show 0≤SKGap.opNorm (derivativeMatrix z x) from norm_nonneg _]) hDc + have hrow (i : Fin n) : (∑k,(primaryIncrement D.H x i k)^2)≤T^2 := by + simpa only [primaryIncrement,D,literalInitial,Fintype.sum_unique,sq_abs] using + (SKGap.SourceError.matrix_row_square_le (derivativeMatrix z x) i).trans + (pow_le_pow_left₀ (norm_nonneg _) (le_trans (le_add_of_nonneg_right (norm_nonneg _)) hD) 2) + have h4 : (∑i,∑k,(primaryIncrement D.H x i k)^4)≤Q^4 := by + simpa only [primaryIncrement,D,literalInitial,Fintype.sum_unique,show (4:ℕ)=2*2 from rfl,pow_mul,sq_abs] using hQ4 + have hdi : (∑i,(primaryIncrement D.H x i i)^2)≤T^2 := by + simpa only [primaryIncrement,D,literalInitial,Fintype.sum_unique,sq_abs] using hdiag + have hseed (s : Bool) : vectorNorm (D.seed s)≤1 := by + cases s + · exact he + · change vectorNorm (fun i=>Real.tanh (r i)/Real.sqrt n)≤1 + have H:=(vectorNorm_tanh r) + rw [show (fun i=>Real.tanh (r i)/Real.sqrt n)=((Real.sqrt n)⁻¹ • (fun i=>Real.tanh (r i))) by ext i; simp only [Pi.smul_apply,smul_eq_mul];ring, + vectorNorm_smul,abs_of_nonneg (inv_nonneg.mpr (Real.sqrt_nonneg _))] + exact (mul_le_mul_of_nonneg_left H (inv_nonneg.mpr (Real.sqrt_nonneg _))).trans_eq (inv_mul_cancel₀ hd) + have hZ : (∑α,‖derivativeVector (D.θ α) x‖)+4*(Q^2+T*(T+B)+(T+B)^2)+2*(Q+T+(T+B))≤ initialTraceFactor Q T B := by + dsimp only [initialTraceFactor]; linarith + have Hs:=D.implicitSource_control t y x hC hQ hT hT (add_nonneg hT hW.nonneg) hY hp hEz hreg har + ((parameterIncrement_bound D.θ x).trans hparam) h4 hrow hdi + hZ + have Hb : (∑s,C*vectorNorm (D.seed s))≤2*C := by + simpa only [Fintype.sum_bool,mul_one,two_mul] using add_le_add + (mul_le_mul_of_nonneg_left (hseed true) hC) (mul_le_mul_of_nonneg_left (hseed false) hC) + have hcoef:=initial_kernel_bound phiExpr z a r x hT ha haf hD + have hcoef' : D.implicitCoefficient=fun v i=>phiExpr.eval (z v i) (r i) (a v) := by + ext v i; rw [literalInitial_coefficient,phiExpr,KernelExpr.eval,moment_base] + constructor + · apply Hs.mono + dsimp only [initialPartialBudget,initialTraceFactor] at * + rw [←Finset.sum_mul] + nlinarith [mul_nonneg (sub_nonneg.mpr Hb) + (show 0≤T+B+4*(Q^2+T*(T+B)+(T+B)^2)+2*(Q+T+(T+B)) by positivity [hW.nonneg])] + · apply D.implicitField_control t w y x hn hT hcoef.row_nonneg hW hp hEm hm hDm + simpa only [hcoef'] using hcoef.difference +end SKGapCutoff.Recipe + +end +end + +section + +noncomputable section +open scoped BigOperators +namespace SKGap.ImplicitSystem +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] +lemma ordinary_matrix_margin (j χ b r δ : ℝ) (X J : E→L[ℝ]E) (q : E) + (hj : 0≤j) (hr : 0≤r) + (hself : ∀u v,inner ℝ u (X v)=inner ℝ (X u) v) + (hStable : ∀v,δ*‖v‖^2≤ inner ℝ v (stableMatrix j b r X J q v)) + (hSmall : |j| *|χ-b| *‖X‖^2≤δ/2) (v : E) : + (δ/2)*‖v‖^2≤ inner ℝ v ((1-X*(J-(j*χ) • 1)*X) v) := by + let S:=1+(j*b) • (X*X)-X*J*X + have hS : ∀u,δ*‖u‖^2≤ inner ℝ u (S u) := by + intro u + have hh : inner ℝ u ((X*rank q q*X) u)=(inner ℝ q (X u))^2 := by + simp only [mul_apply_eq_comp,rank_apply,map_smul,inner_smul_right] + rw [hself u q,real_inner_comm (X u) q] + ring + have hs:=hStable u + change δ*‖u‖^2≤ inner ℝ u ((S-(2*j*r) • (X*rank q q*X)) u) at hs + simp only [sub_apply,smul_apply,inner_sub_right, + inner_smul_right,hh] at hs + nlinarith [mul_nonneg (by positivity : 0≤2*j*r) (sq_nonneg (inner ℝ q (X u)))] + have hd : (1-X*(J-(j*χ) • 1)*X)-S=(j*(χ-b)) • (X*X) := by + dsimp only [S] + simp only [mul_sub,sub_mul,mul_smul_comm,smul_mul_assoc,mul_one,sub_smul] + module + have hnorm : ‖(1-X*(J-(j*χ) • 1)*X)-S‖≤δ/2 := by + rw [hd,norm_smul,Real.norm_eq_abs,abs_mul] + exact ((mul_le_mul_of_nonneg_left (norm_mul_le X X) (by positivity)).trans_eq + (by ring)).trans hSmall + have hp:=SKGap.ImplicitLinear.quadratic_perturbation (1-X*(J-(j*χ) • 1)*X) S hS hnorm v + convert hp using 1 + ring +end SKGap.ImplicitSystem + +namespace SKGapCutoff.Recipe +open SKGap.Stein Primary SKGap.ImplicitSystem Matrix +variable {n : ℕ} +lemma phiSqrt_inner (z r : Fin n→ℝ) (a : ℝ) (u v : Euclid n) : + inner ℝ u (phiSqrt z r a v)=inner ℝ (phiSqrt z r a u) v := by + simp only [phiSqrt,EuclideanSpace.inner_eq_star_dotProduct, + star_trivial,ofLp_toEuclideanCLM,dotProduct,mulVec_diagonal] + apply Finset.sum_congr rfl + intro i _ + ring + +lemma literal_inverse_stability (J : Interaction n) (j : ℝ) + (z m : VectorFields n) (a : Spin n→ℝ) (r : Fin n→ℝ) (x : Spin n) + (hn : 0phi (z x i) (r i) (a x)) 1* + (J-(j*siteMean (fun v i=>phi (z v i) (r i) (a v)) x) • 1)* + SKGap.pathDiagonal (fun i=>phi (z x i) (r i) (a x)) 1).PosDef := by + let D:=SKGap.pathDiagonal (fun i=>phi (z x i) (r i) (a x)) 1 + let χ:=siteMean (fun v i=>phi (z v i) (r i) (a v)) x + have hD : D.IsHermitian := by simp [D,SKGap.pathDiagonal] + have hM : (J-(j*χ) • 1).IsHermitian := + (isHermitian_iff_isSymm.mpr hJ).sub (isHermitian_one.smul (IsSelfAdjoint.all (j*χ))) + have hHerm : (1-D*(J-(j*χ) • 1)*D).IsHermitian := by + apply isHermitian_one.sub + simpa only [hD.eq] using isHermitian_conjTranspose_mul_mul D hM + apply PosDef.of_dotProduct_mulVec_pos hHerm + intro v hv + have hpert:=H.perturbation hn hδ hρ hsmall + have hsmall' : |j| *|χ-(∑i,scalarVariance (z x i))/(n:ℝ)| *‖phiSqrt (z x) r (a x)‖^2≤δ/2 := + (le_add_of_nonneg_right (by positivity)).trans hpert + have hp:=ordinary_matrix_margin j χ _ (n:ℝ)⁻¹ δ (phiSqrt (z x) r (a x)) + (toEuclideanCLM (𝕜:=ℝ) J) (WithLp.toLp 2 (fun i=>Real.tanh (z x i))) + hj (by positivity) (phiSqrt_inner _ _ _) H.stable hsmall' (WithLp.toLp 2 v) + have hrep : toEuclideanCLM (𝕜:=ℝ) (1-D*(J-(j*χ) • 1)*D)= + 1-phiSqrt (z x) r (a x)*(toEuclideanCLM (𝕜:=ℝ) J-(j*χ) • 1)*phiSqrt (z x) r (a x) := by + simp only [map_sub,map_mul,map_one,map_smul,D,SKGap.pathDiagonal,Real.sqrt_one,one_mul,phiSqrt] + rw [←hrep,inner_toEuclideanCLM] at hp + have hnorm : 0<‖(WithLp.toLp 2 v : Euclid n)‖^2 := by + exact sq_pos_of_pos (norm_pos_iff.mpr (by simpa using hv)) + simpa only [star_trivial] using lt_of_lt_of_le (mul_pos (half_pos hδ) hnorm) hp +end SKGapCutoff.Recipe + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Matrix/LogDetConcentration.lean b/lean/OAI/Probability/SKGap/Matrix/LogDetConcentration.lean new file mode 100644 index 0000000000000000000000000000000000000000..dfe8cda85386569a1ca3c44f557bf5c7696fe5d4 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Matrix/LogDetConcentration.lean @@ -0,0 +1,68 @@ +import Mathlib +import OAI.Probability.SKGap.Matrix.LogDetIntegral + +namespace OAI + +section +noncomputable section +namespace SKGap +open Matrix MeasureTheory ProbabilityTheory Real Set Filter +open scoped BigOperators Matrix.Norms.Frobenius NNReal Topology +variable {ι : Type*} [Fintype ι] [DecidableEq ι] + +lemma regularizedLogDet_lipschitzWith [Nonempty ι] {γ : ℝ} (hγ : 0 < γ) : + LipschitzWith ⟨1/sqrt ((Fintype.card ι:ℝ)*γ),by positivity⟩ + (LogDet.regularizedLogDet γ : Matrix ι ι ℝ → ℝ) := by + apply LipschitzWith.of_dist_le_mul + intro M N + change |LogDet.regularizedLogDet γ M-LogDet.regularizedLogDet γ N| ≤ + (1/sqrt ((Fintype.card ι:ℝ)*γ))*‖M-N‖ + exact LogDet.regularizedLogDet_lipschitz hγ M N + +lemma logPath_regularized_tail [Nonempty ι] {j γ u : ℝ} (hj : 0 < j) (hγ : 0 < γ) + (hu : 0 ≤ u) {a : ι → ℝ} (ha : ∀ i, 0 ≤ a i) (ha1 : ∀ i, a i ≤ 1) : + let F := fun g => LogDet.regularizedLogDet γ (logPath ((j/(Fintype.card ι:ℝ))*∑ i,a i) a + (goeMatrix (j/(Fintype.card ι:ℝ)) g) 1) + let μ := Measure.pi (fun _ : MatrixCoordinates ι => gaussianReal 0 1) + μ.real {g | u ≤ |F g-∫ x,F x ∂μ|} ≤ + 2*Real.exp (-γ*(Fintype.card ι:ℝ)^2*u^2/(π^2*j)) := by + have hn : (0:ℝ) < Fintype.card ι := Nat.cast_pos.mpr Fintype.card_pos + have hc := (regularizedLogDet_lipschitzWith hγ).comp + ((logPath_one_lipschitz (j := j) ha ha1).comp (goeMatrix_L2_lipschitz (j/(Fintype.card ι:ℝ)))) + let L : ℝ≥0 := ⟨(1/sqrt ((Fintype.card ι:ℝ)*γ))*sqrt (2*(j/(Fintype.card ι:ℝ))),by positivity⟩ + have hc' : LipschitzWith L (fun x : EuclideanSpace ℝ (MatrixCoordinates ι) => + LogDet.regularizedLogDet γ (logPath ((j/(Fintype.card ι:ℝ))*∑ i,a i) a + (goeMatrix (j/(Fintype.card ι:ℝ)) x.ofLp) 1)) := by + exact hc.weaken (by + change (1/sqrt ((Fintype.card ι:ℝ)*γ))*(1*sqrt (2*(j/(Fintype.card ι:ℝ)))) ≤ + (1/sqrt ((Fintype.card ι:ℝ)*γ))*sqrt (2*(j/(Fintype.card ι:ℝ))) + rw [_root_.one_mul]) + have hL : 0 < L := NNReal.coe_pos.mp (by + change 0 < (1/sqrt ((Fintype.card ι:ℝ)*γ))*sqrt (2*(j/(Fintype.card ι:ℝ))) + exact mul_pos (one_div_pos.mpr (sqrt_pos.mpr (mul_pos hn hγ))) + (sqrt_pos.mpr (mul_pos (by norm_num) (div_pos hj hn)))) + have h := gaussianProduct_tail_lipschitz + (f := fun g => LogDet.regularizedLogDet γ (logPath ((j/(Fintype.card ι:ℝ))*∑ i,a i) a + (goeMatrix (j/(Fintype.card ι:ℝ)) g) 1)) hc' hL hu + apply h.trans_eq + congr 2 + change -2*u^2/(π^2*((1/sqrt ((Fintype.card ι:ℝ)*γ))*sqrt (2*(j/(Fintype.card ι:ℝ))))^2)=_ + rw [mul_pow,_root_.one_div_pow,sq_sqrt (by positivity : 0 ≤ (Fintype.card ι:ℝ)*γ), + sq_sqrt (by positivity : 0 ≤ 2*(j/(Fintype.card ι:ℝ)))] + field_simp + +lemma regularizedLogDet_transpose {γ : ℝ} (hγ : γ ≠ 0) (M : Matrix ι ι ℝ) : + LogDet.regularizedLogDet γ Mᵀ=LogDet.regularizedLogDet γ M := by + have e₁ : γ • (1+(γ⁻¹ • M)*Mᵀ)=M*Mᵀ+γ • 1 := by + rw [smul_add,smul_mul_assoc,smul_smul,mul_inv_cancel₀ hγ,one_smul] + ac_rfl + have e₂ : γ • (1+Mᵀ*(γ⁻¹ • M))=Mᵀ*M+γ • 1 := by + rw [smul_add,mul_smul_comm,smul_smul,mul_inv_cancel₀ hγ,one_smul] + ac_rfl + unfold LogDet.regularizedLogDet LogDet.regularizedGram + rw [transpose_transpose,← e₁,← e₂,det_smul,det_smul,det_one_add_mul_comm] +end SKGap +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Matrix/LogDetExpected.lean b/lean/OAI/Probability/SKGap/Matrix/LogDetExpected.lean new file mode 100644 index 0000000000000000000000000000000000000000..ccb59dab23de620fbe3987f328910b4f334c1384 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Matrix/LogDetExpected.lean @@ -0,0 +1,116 @@ +import Mathlib +import OAI.Probability.SKGap.Matrix.LogDetIntegral +import OAI.Probability.SKGap.Stability.LogDetMean +import OAI.Probability.SKGap.Localization.BoundedIntervalFubini + +namespace OAI + +section +noncomputable section +namespace SKGap +open Matrix MeasureTheory ProbabilityTheory Real Set Filter +open RealComplex +open scoped BigOperators Matrix.Norms.Frobenius SchwartzMap Topology +variable {ι : Type*} [Fintype ι] [DecidableEq ι] + +lemma rare_logdet_coefficients {n j γ : ℝ} (hn : 0 < n) (hj : 0 ≤ j) (hγ : 0 < γ) : + sqrt n*(1+j)/sqrt (n*γ)=(1+j)/sqrt γ ∧ + n^2*sqrt (2*j/n)/sqrt (n*γ)=n*sqrt (2*j)/sqrt γ := by + have hs : 0 < sqrt n := sqrt_pos.mpr hn + have hg : 0 < sqrt γ := sqrt_pos.mpr hγ + rw [sqrt_mul hn.le,sqrt_div (by positivity : 0 ≤ 2*j)] + constructor + · field_simp + · field_simp + rw [sq_sqrt hn.le] + ring + +def logdetMeanError (j R B C rate γ : ℝ) : ℝ := + 2*(2*j+1)*C+(|log γ|+(1+j)/sqrt γ+2*((2*j+R)*B))*(3/rate)+ + (sqrt (2*j)/sqrt γ)*(8*sqrt 3/rate^2) + +lemma logdetMeanError_nonneg {j R B C rate γ : ℝ} (hj : 0 ≤ j) (hR : 0 ≤ R) + (hB : 0 ≤ B) (hC : 0 ≤ C) (hrate : 0 < rate) (hγ : 0 < γ) : + 0 ≤ logdetMeanError j R B C rate γ := by unfold logdetMeanError; positivity + +lemma logPath_regularized_expected [Nonempty ι] (f : 𝓢(ℝ,ℂ)) {R lo hi j C γ rate : ℝ} + (hR : 0 ≤ R) (hlo : 0 < lo) (hf : ∀ x ∈ Icc lo hi, f x=(x:ℂ)⁻¹) + (hj : 0 ≤ j) (hC : 0 ≤ C) (hγ : 0 < γ) (hrate : 0 < rate) + {a : ι → ℝ} (ha : ∀ i, 0 ≤ a i) (ha1 : ∀ i, a i ≤ 1) + (hK : ∀ z ∈ Icc (0:ℝ) 1, ∀ i, |pathExpected f R hR j a z i-1| ≤ C/(Fintype.card ι:ℝ)) + (hWK : ∀ z ∈ Icc (0:ℝ) 1, ∀ i, + |(∫ g, (realProject R hR (goeMatrix (j/(Fintype.card ι:ℝ)) g)* + pathK f R hR j a z (goeMatrix (j/(Fintype.card ι:ℝ)) g)) i i + ∂Measure.pi (fun _ : MatrixCoordinates ι => gaussianReal 0 1))- + z*((j/(Fintype.card ι:ℝ))*∑ b,a b)| ≤ C/(Fintype.card ι:ℝ)) + (hp : (Measure.pi (fun _ : MatrixCoordinates ι => gaussianReal 0 1)).real + {g | goeMatrix (j/(Fintype.card ι:ℝ)) g ∉ logPathGood R lo hi ((j/(Fintype.card ι:ℝ))*∑ b,a b) a} ≤ + 3*Real.exp (-rate*(Fintype.card ι:ℝ))) : + (∫ g, LogDet.regularizedLogDet γ (logPath ((j/(Fintype.card ι:ℝ))*∑ b,a b) a + (goeMatrix (j/(Fintype.card ι:ℝ)) g) 1) + ∂Measure.pi (fun _ : MatrixCoordinates ι => gaussianReal 0 1)) ≤ + j*((∑ i,a i)/(Fintype.card ι:ℝ))^2+γ*(pathBound f R j 1)^2+ + logdetMeanError j R (pathBound f R j 1) C rate γ/(Fintype.card ι:ℝ) := by + let μ := Measure.pi (fun _ : MatrixCoordinates ι => gaussianReal 0 1) + let r := j/(Fintype.card ι:ℝ) + let q := r*∑ i,a i + let B := pathBound f R j 1 + let D := (2*j+R)*B + let T := fun p : ℝ × (MatrixCoordinates ι → ℝ) => logPathCutoffDerivative f R hR j a (goeMatrix r p.2) p.1 + let I := fun g => ∫ z in (0:ℝ)..1, T (z,g) + let F := fun g => LogDet.regularizedLogDet γ (logPath q a (goeMatrix r g) 1) + let s := {g | goeMatrix r g ∉ logPathGood R lo hi q a} + have hn : (0:ℝ) < Fintype.card ι := Nat.cast_pos.mpr Fintype.card_pos + have hn1 : (1:ℝ) ≤ Fintype.card ι := by exact_mod_cast Fintype.card_pos + have hB : 0 ≤ B := (path_constants_nonneg f hR hj (by norm_num : (0:ℝ)≤1)).1 + have hD : 0 ≤ D := by dsimp [D]; positivity + have ht : Continuous T := (continuous_logPathCutoffDerivative f hR j a).comp + (continuous_fst.prodMk ((goeMatrix_pi_lipschitz r).continuous.comp continuous_snd)) + have htb (z : ℝ) (hz : z ∈ Icc (0:ℝ) 1) (g) : |T (z,g)| ≤ D := + logPathCutoffDerivative_bound f hR hj ha ha1 hz _ + have htm (z : ℝ) (hz : z ∈ Icc (0:ℝ) 1) : + |(∫ g, T (z,g) ∂μ)-z*(j*((∑ i,a i)/(Fintype.card ι:ℝ))^2)| ≤ (2*j+1)*C/(Fintype.card ι:ℝ) := by + simpa only [mul_assoc] using logPathCutoffDerivative_mean_error f hR hj hC ha ha1 hz (hK z hz) (hWK z hz) + obtain ⟨hI,hIm⟩ := bounded_interval_mean (μ := μ) ht htb htm + have hIb (g) : |I g| ≤ D := by + have hh := intervalIntegral.norm_integral_le_of_norm_le_const (a := (0:ℝ)) (b := 1) + (f := fun z => T (z,g)) (C := D) (fun z hz => by + have hz' : z ∈ Ioc (0:ℝ) 1 := by simpa only [uIoc_of_le (by norm_num : (0:ℝ)≤1)] using hz + simpa only [Real.norm_eq_abs] using htb z ⟨hz'.1.le,hz'.2⟩ g) + simpa only [I,Real.norm_eq_abs,sub_zero,abs_one,mul_one] using hh + have hs : MeasurableSet s := ((logPathGood_isClosed R lo hi q a).preimage (goeMatrix_pi_lipschitz r).continuous).measurableSet.compl + have hF : Integrable F μ := logPath_regularized_integrable hγ ha ha1 + have hgood (g) (hg : g ∉ s) : F g ≤ 2*I g+γ*B^2 := by + have hg' : goeMatrix r g ∈ logPathGood R lo hi q a := by simpa only [s,mem_ofPred_eq,not_not] using hg + have hsymm : (goeMatrix r g)ᵀ=goeMatrix r g := goeMatrix_transpose r g + have hev := logdetPath_integral f hlo hf hR j ha (goeMatrix r g) hsymm hg' + have hu := pathK_agrees_at f hlo hf hR j ha (by norm_num : (0:ℝ)≤1) (goeMatrix r g) hsymm hg'.1 + (hg'.2 1 (by constructor <;> norm_num)).1 (hg'.2 1 (by constructor <;> norm_num)).2 + have hb : opNorm (logPath q a (goeMatrix r g) 1)⁻¹ ≤ B := by + rw [← hu.2] + exact (pathK_bounds f hR hj (by norm_num : (0:ℝ)≤1) ha ha1 (by constructor <;> norm_num)).1 _ + have hh := LogDet.regularizedLogDet_le_logdet_opNorm hγ.le _ hu.1 hb + change F g ≤ 2*I g+γ*B^2 + dsimp only [I,T] + rw [hev] + exact hh.trans_eq (by ring) + have hex := expectation_upper_good hs hF hI (mul_nonneg hγ.le (sq_nonneg B)) hIb hgood + have hrare := logPath_regularized_rare hj hγ ha ha1 hs + obtain ⟨hc₁,hc₂⟩ := rare_logdet_coefficients hn hj hγ + rw [hc₁,hc₂] at hrare + obtain ⟨hp₁,_,hp₃⟩ := exponential_tail_absorptions hrate hn1 hp + have hsmall : (|log γ|+(1+j)/sqrt γ+2*D)*μ.real s+ + (sqrt (2*j)/sqrt γ)*((Fintype.card ι:ℝ)*sqrt (μ.real s)) ≤ + (|log γ|+(1+j)/sqrt γ+2*D)*((3/rate)/(Fintype.card ι:ℝ))+ + (sqrt (2*j)/sqrt γ)*((8*sqrt 3/rate^2)/(Fintype.card ι:ℝ)) := by + exact add_le_add (mul_le_mul_of_nonneg_left hp₁ (by positivity)) + (mul_le_mul_of_nonneg_left hp₃ (by positivity)) + have hib := (abs_le.mp hIm).2 + dsimp only [F,I,T,q,r,μ,B,D,logdetMeanError] at hex hrare hib hsmall ⊢ + simp only [div_eq_mul_inv] at hex hrare hib hsmall ⊢ + nlinarith only [hex,hrare,hib,hsmall] +end SKGap +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Matrix/LogDetIntegral.lean b/lean/OAI/Probability/SKGap/Matrix/LogDetIntegral.lean new file mode 100644 index 0000000000000000000000000000000000000000..f785044089d110984dda9033fa4c4b61e695a775 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Matrix/LogDetIntegral.lean @@ -0,0 +1,248 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.Bilinear2 +import OAI.Probability.SKGap.Matrix.RegularizedLogDet +import OAI.Probability.SKGap.Brownian.LogDetPath + +namespace OAI + +section +noncomputable section +namespace SKGap +open Matrix MeasureTheory ProbabilityTheory Real Set +open RealComplex +open scoped BigOperators Matrix.Norms.Frobenius SchwartzMap +variable {ι : Type*} [Fintype ι] [DecidableEq ι] + +def logPathGood (R lo hi q : ℝ) (a : ι → ℝ) : Set (Matrix ι ι ℝ) := + {M | opNorm M ≤ R ∧ ∀ z ∈ Icc (0:ℝ) 1, + lo ≤ ComplexSpectral.lowerRayleigh (liftMatrix (1-pathDiagonal a z*(M-pathShift z q)*pathDiagonal a z)) ∧ + -hi ≤ ComplexSpectral.lowerRayleigh (-liftMatrix (1-pathDiagonal a z*(M-pathShift z q)*pathDiagonal a z))} + +lemma logPathGood_isClosed (R lo hi q : ℝ) (a : ι → ℝ) : + IsClosed (logPathGood R lo hi q a) := by + have hc (z : ℝ) : Continuous (fun M : Matrix ι ι ℝ => liftMatrix (1-pathDiagonal a z*(M-pathShift z q)*pathDiagonal a z)) := by + dsimp only [liftMatrix]; fun_prop + have hl (z : ℝ) := isClosed_le (continuous_const (y := lo)) (ComplexSpectral.continuous_lowerRayleigh.comp (hc z)) + have hu (z : ℝ) := isClosed_le (continuous_const (y := -hi)) (ComplexSpectral.continuous_lowerRayleigh.comp (hc z).neg) + change IsClosed ({M | opNorm M ≤ R} ∩ {M | ∀ z ∈ Icc (0:ℝ) 1, _}) + apply (isClosed_le continuous_realOpNorm continuous_const).inter + simp only [ofPred_forall] + exact isClosed_iInter (fun z => isClosed_iInter (fun _ => (hl z).inter (hu z))) + +lemma logPathGood_exponential [Nonempty ι] {j A : ℝ} {a : ι → ℝ} + (hj : 0 < j) (hA : 0 < A) (ha : ∀ i, 0 ≤ a i) (haA : ∀ i, a i ≤ A) + (hs : sqrt j*A < 1) + (herr : 2*sqrt A*sqrt (sqrt (2*j^2*A^2/(Fintype.card ι:ℝ))) ≤ (1-sqrt j*A)^2/4) : + (Measure.pi (fun _ : MatrixCoordinates ι => gaussianReal 0 1)).real + {g | goeMatrix (j/(Fintype.card ι:ℝ)) g ∉ + logPathGood (2*sqrt j+1+1) ((1-sqrt j*A)^2/4) (2+A*(2*sqrt j+1+j*A)) + ((j/(Fintype.card ι:ℝ))*∑ b,a b) a} ≤ 3*Real.exp (-pathRate j A*(Fintype.card ι:ℝ)) := by + apply (measureReal_mono (s₂ := {g | ∃ z ∈ Icc (0:ℝ) 1, g ∉ truncationGoodSet (j/(Fintype.card ι:ℝ)) + (2*sqrt j+1+1) ((1-sqrt j*A)^2/4) (2+A*(2*sqrt j+1+j*A)) + (pathDiagonal a z) (pathShift z ((j/(Fintype.card ι:ℝ))*∑ b,a b))}) ?_ (measure_ne_top _ _)).trans + (path_all_good_exponential hj hA ha haA hs herr) + intro g hg + by_contra hcontra + change ¬(∃ z ∈ Icc (0:ℝ) 1, _) at hcontra + push Not at hcontra + apply hg + constructor + · exact (hcontra 0 (by constructor <;> norm_num)).1.le + · intro z hz + exact ⟨(hcontra z hz).2.1.le,(hcontra z hz).2.2.le⟩ + +lemma logdetPath_integral [Nonempty ι] (f : 𝓢(ℝ,ℂ)) {lo hi : ℝ} (hlo : 0 < lo) + (hf : ∀ x ∈ Icc lo hi, f x=(x:ℂ)⁻¹) {R : ℝ} (hR : 0 ≤ R) + (j : ℝ) {a : ι → ℝ} (ha : ∀ i, 0 ≤ a i) (M : Matrix ι ι ℝ) (hM : Mᵀ=M) + (hg : M ∈ logPathGood R lo hi ((j/(Fintype.card ι:ℝ))*∑ b,a b) a) : + (∫ z in (0:ℝ)..1, logPathCutoffDerivative f R hR j a M z)= + log (logPath ((j/(Fintype.card ι:ℝ))*∑ b,a b) a M 1).det/(Fintype.card ι:ℝ) := by + have hc : Continuous (fun z => logPathCutoffDerivative f R hR j a M z) := + (continuous_logPathCutoffDerivative f hR j a).comp (continuous_id.prodMk continuous_const) + have hh := intervalIntegral.integral_eq_sub_of_hasDerivAt + (f := fun z => log (logPath ((j/(Fintype.card ι:ℝ))*∑ b,a b) a M z).det/(Fintype.card ι:ℝ)) + (f' := fun z => logPathCutoffDerivative f R hR j a M z) + (fun z hz => ?_) (hc.intervalIntegrable 0 1) + · simpa only [logPath,zero_pow (by norm_num : 2 ≠ 0),zero_mul,zero_smul,add_zero, + sub_zero,Matrix.det_one,log_one,zero_div] using hh + · have hz' : z ∈ Icc (0:ℝ) 1 := by simpa only [uIcc_of_le (by norm_num : (0:ℝ)≤1)] using hz + obtain ⟨hunit,hagree⟩ := pathK_agrees_at f hlo hf hR j ha hz'.1 M hM hg.1 (hg.2 z hz').1 (hg.2 z hz').2 + have hd := (LogDet.hasDerivAt_logdet (hasDerivAt_logPath ((j/(Fintype.card ι:ℝ))*∑ b,a b) a M z) hunit).div_const (Fintype.card ι:ℝ) + rw [logPath_trace_derivative,← hagree] at hd + simpa only [logPathCutoffDerivative,realProject_eq_self hR M hM hg.1] using hd + +lemma trace_abs_le_card_opNorm (M : Matrix ι ι ℝ) : |M.trace| ≤ (Fintype.card ι:ℝ)*opNorm M := by + unfold Matrix.trace Matrix.diag + exact (Finset.abs_sum_le_sum_abs _ _).trans (by simpa only [Finset.sum_const,Finset.card_univ,nsmul_eq_mul] using Finset.sum_le_sum (s := Finset.univ) (fun i _ => matrix_entry_le_opNorm M i i)) + +lemma logPathCutoffDerivative_bound [Nonempty ι] (f : 𝓢(ℝ,ℂ)) {R j : ℝ} (hR : 0 ≤ R) (hj : 0 ≤ j) + {a : ι → ℝ} (ha : ∀ i, 0 ≤ a i) (haA : ∀ i, a i ≤ 1) {z : ℝ} (hz : z ∈ Icc (0:ℝ) 1) + (M : Matrix ι ι ℝ) : + |logPathCutoffDerivative f R hR j a M z| ≤ (2*j+R)*pathBound f R j 1 := by + have hn : (0:ℝ) < Fintype.card ι := Nat.cast_pos.mpr Fintype.card_pos + have hB := (path_constants_nonneg f hR hj (by norm_num : (0:ℝ)≤1)).1 + have hq := diagonal_mean_bounds hj ha haA + simp only [mul_one] at hq + have hK := (pathK_bounds f hR hj (by norm_num : (0:ℝ)≤1) ha haA hz).1 M + have hD : opNorm (diagonal a) ≤ 1 := opNorm_diagonal_le (by norm_num) (fun i => by rw [abs_of_nonneg (ha i)]; exact haA i) + have hKD : opNorm (pathK f R hR j a z M*diagonal a) ≤ pathBound f R j 1 := + (opNorm_mul _ _).trans (by simpa only [mul_one] using mul_le_mul hK hD (norm_nonneg _) hB) + have hWKD : opNorm (realProject R hR M*pathK f R hR j a z M*diagonal a) ≤ R*pathBound f R j 1 := by + rw [mul_assoc] + exact (opNorm_mul _ _).trans (mul_le_mul (realProject_opNorm hR M) hKD (norm_nonneg _) hR) + have ht₁ := (trace_abs_le_card_opNorm _).trans (mul_le_mul_of_nonneg_left hKD hn.le) + have ht₂ := (trace_abs_le_card_opNorm _).trans (mul_le_mul_of_nonneg_left hWKD hn.le) + have hzq : |2*z*((j/(Fintype.card ι:ℝ))*∑ b,a b)| ≤ 2*j := by + rw [abs_of_nonneg (mul_nonneg (mul_nonneg (by norm_num) hz.1) hq.1)] + nlinarith [mul_le_mul hz.2 hq.2 hq.1 (by norm_num : (0:ℝ)≤1)] + unfold logPathCutoffDerivative + rw [abs_div,abs_of_pos hn] + apply (div_le_iff₀ hn).mpr + have hterm : |(2*z*((j/(Fintype.card ι:ℝ))*∑ b,a b))*(pathK f R hR j a z M*diagonal a).trace| ≤ + 2*j*((Fintype.card ι:ℝ)*pathBound f R j 1) := by + rw [abs_mul] + exact mul_le_mul hzq ht₁ (abs_nonneg _) (by positivity) + have hh := (abs_sub (2*z*((j/(Fintype.card ι:ℝ))*∑ b,a b)*(pathK f R hR j a z M*diagonal a).trace) + (realProject R hR M*pathK f R hR j a z M*diagonal a).trace).trans (add_le_add hterm ht₂) + exact hh.trans_eq (by ring) +end SKGap +end +end + +section +noncomputable section +namespace SKGap +open Matrix MeasureTheory ProbabilityTheory Real Set +open RealComplex +open scoped BigOperators Matrix.Norms.Frobenius SchwartzMap +variable {ι : Type*} [Fintype ι] [DecidableEq ι] + +lemma frobenius_le_sum_abs (M : Matrix ι ι ℝ) : ‖M‖ ≤ ∑ i,∑ k,|M i k| := by + apply (sq_le_sq₀ (norm_nonneg M) (by positivity : 0 ≤ ∑ i,∑ k,|M i k|)).mp + rw [frobenius_sq] + calc + _ ≤ ∑ i,(∑ k,|M i k|)^2 := Finset.sum_le_sum (fun i _ => by + simpa only [sq_abs] using Finset.sum_sq_le_sq_sum_of_nonneg (s := Finset.univ) (fun k _ => abs_nonneg (M i k))) + _ ≤ (∑ i,∑ k,|M i k|)^2 := Finset.sum_sq_le_sq_sum_of_nonneg (fun i _ => by positivity) + +lemma frobenius_one : ‖(1:Matrix ι ι ℝ)‖=sqrt (Fintype.card ι:ℝ) := by + have hs := LogDet.frobenius_sq_trace (1:Matrix ι ι ℝ) + simp only [transpose_one,one_mul,Matrix.trace_one] at hs + nlinarith [norm_nonneg (1:Matrix ι ι ℝ),sqrt_nonneg (Fintype.card ι:ℝ),sq_sqrt (Nat.cast_nonneg (Fintype.card ι))] + +lemma logPath_one_frobenius [Nonempty ι] {j : ℝ} (hj : 0 ≤ j) + {a : ι → ℝ} (ha : ∀ i, 0 ≤ a i) (ha1 : ∀ i, a i ≤ 1) (M : Matrix ι ι ℝ) : + ‖logPath ((j/(Fintype.card ι:ℝ))*∑ i,a i) a M 1‖ ≤ sqrt (Fintype.card ι:ℝ)*(1+j)+‖M‖ := by + have hq := diagonal_mean_bounds hj ha ha1 + simp only [mul_one] at hq + have hD : opNorm (diagonal a) ≤ 1 := opNorm_diagonal_le (by norm_num) (fun i => by rw [abs_of_nonneg (ha i)]; exact ha1 i) + have hDn := (LogDet.frobenius_le_sqrt_card_opNorm (diagonal a)).trans + (mul_le_mul_of_nonneg_left hD (sqrt_nonneg _)) + simp only [mul_one] at hDn + have hDM := (frobenius_mul_le_opNorm (diagonal a) M).trans (mul_le_mul_of_nonneg_right hD (norm_nonneg M)) + simp only [one_mul] at hDM + simp only [logPath,one_pow,one_mul,one_smul] + apply (norm_sub_le _ _).trans + apply (add_le_add (norm_add_le _ _) hDM).trans + rw [norm_smul,Real.norm_eq_abs,abs_of_nonneg hq.1,frobenius_one] + have hh := mul_le_mul hq.2 hDn (norm_nonneg _) hj + nlinarith + +lemma logPath_one_lipschitz {j : ℝ} {a : ι → ℝ} + (ha : ∀ i, 0 ≤ a i) (ha1 : ∀ i, a i ≤ 1) : + LipschitzWith 1 (fun M : Matrix ι ι ℝ => logPath ((j/(Fintype.card ι:ℝ))*∑ i,a i) a M 1) := by + apply LipschitzWith.of_dist_le_mul + intro M N + simp only [dist_eq_norm,NNReal.coe_one,one_mul] + have he : logPath ((j/(Fintype.card ι:ℝ))*∑ i,a i) a M 1- + logPath ((j/(Fintype.card ι:ℝ))*∑ i,a i) a N 1= -(diagonal a*(M-N)) := by + simp only [logPath,one_pow,one_mul,one_smul,Matrix.mul_sub]; abel + rw [he,norm_neg] + have hD : opNorm (diagonal a) ≤ 1 := opNorm_diagonal_le (by norm_num) (fun i => by rw [abs_of_nonneg (ha i)]; exact ha1 i) + exact (frobenius_mul_le_opNorm _ _).trans (by simpa only [one_mul] using mul_le_mul_of_nonneg_right hD (norm_nonneg (M-N))) + +lemma logPath_regularized_integrable [Nonempty ι] {j γ : ℝ} (hγ : 0 < γ) + {a : ι → ℝ} (ha : ∀ i, 0 ≤ a i) (ha1 : ∀ i, a i ≤ 1) : + Integrable (fun g => LogDet.regularizedLogDet γ (logPath ((j/(Fintype.card ι:ℝ))*∑ i,a i) a + (goeMatrix (j/(Fintype.card ι:ℝ)) g) 1)) + (Measure.pi (fun _ : MatrixCoordinates ι => gaussianReal 0 1)) := by + have hF : LipschitzWith ⟨1/sqrt ((Fintype.card ι:ℝ)*γ),by positivity⟩ (LogDet.regularizedLogDet γ : Matrix ι ι ℝ → ℝ) := by + apply LipschitzWith.of_dist_le_mul + intro M N + change |LogDet.regularizedLogDet γ M-LogDet.regularizedLogDet γ N| ≤ (1/sqrt ((Fintype.card ι:ℝ)*γ))*‖M-N‖ + exact LogDet.regularizedLogDet_lipschitz hγ M N + exact gaussianProduct_integrable_lipschitz (hF.comp ((logPath_one_lipschitz ha ha1).comp (goeMatrix_L2_lipschitz _))) + +lemma logPath_regularized_rare [Nonempty ι] {j γ : ℝ} (hj : 0 ≤ j) (hγ : 0 < γ) + {a : ι → ℝ} (ha : ∀ i, 0 ≤ a i) (ha1 : ∀ i, a i ≤ 1) + {s : Set (MatrixCoordinates ι → ℝ)} (hs : MeasurableSet s) : + (∫ g in s, |LogDet.regularizedLogDet γ (logPath ((j/(Fintype.card ι:ℝ))*∑ i,a i) a + (goeMatrix (j/(Fintype.card ι:ℝ)) g) 1)| + ∂Measure.pi (fun _ : MatrixCoordinates ι => gaussianReal 0 1)) ≤ + (|log γ|+sqrt (Fintype.card ι:ℝ)*(1+j)/sqrt ((Fintype.card ι:ℝ)*γ))* + (Measure.pi (fun _ : MatrixCoordinates ι => gaussianReal 0 1)).real s+ + (Fintype.card ι:ℝ)^2*sqrt (2*j/(Fintype.card ι:ℝ))/sqrt ((Fintype.card ι:ℝ)*γ)* + sqrt ((Measure.pi (fun _ : MatrixCoordinates ι => gaussianReal 0 1)).real s) := by + let μ := Measure.pi (fun _ : MatrixCoordinates ι => gaussianReal 0 1) + let r := j/(Fintype.card ι:ℝ) + have hentry (i k : ι) : Integrable (fun g => |goeMatrix r g i k|) μ := + ((goeEntry_memLp r i k).integrable (by norm_num)).abs + have hsum : Integrable (fun g => ∑ i,∑ k,|goeMatrix r g i k|) μ := + integrable_finsetSum _ (fun i _ => integrable_finsetSum _ (fun k _ => hentry i k)) + have hpoint (g) : |LogDet.regularizedLogDet γ (logPath ((j/(Fintype.card ι:ℝ))*∑ i,a i) a (goeMatrix r g) 1)| ≤ + (|log γ|+sqrt (Fintype.card ι:ℝ)*(1+j)/sqrt ((Fintype.card ι:ℝ)*γ))+ + (∑ i,∑ k,|goeMatrix r g i k|)/sqrt ((Fintype.card ι:ℝ)*γ) := by + apply (LogDet.regularizedLogDet_abs hγ _).trans + have hh := (logPath_one_frobenius hj ha ha1 (goeMatrix r g)).trans (add_le_add_right (frobenius_le_sum_abs _) _) + have ht := add_le_add_right (div_le_div_of_nonneg_right hh (sqrt_nonneg ((Fintype.card ι:ℝ)*γ))) |log γ| + exact ht.trans_eq (by ring) + have hm := integral_mono (μ := μ.restrict s) (logPath_regularized_integrable hγ ha ha1).abs.integrableOn + ((integrable_const _).add (hsum.div_const _)).integrableOn hpoint + simp only [Pi.add_apply] at hm + rw [integral_add (integrable_const (|log γ|+sqrt (Fintype.card ι:ℝ)*(1+j)/sqrt ((Fintype.card ι:ℝ)*γ))) + (hsum.div_const (sqrt ((Fintype.card ι:ℝ)*γ))).integrableOn,integral_const,smul_eq_mul, + measureReal_restrict_apply_univ,integral_div] at hm + have hsumle : (∫ g in s, (∑ i,∑ k,|goeMatrix r g i k|) ∂μ) ≤ + (Fintype.card ι:ℝ)^2*sqrt (2*j/(Fintype.card ι:ℝ))*sqrt (μ.real s) := by + rw [integral_finsetSum _ (fun i _ => (integrable_finsetSum _ (fun k _ => hentry i k)).integrableOn)] + simp_rw [integral_finsetSum _ (fun k _ => (hentry _ k).integrableOn)] + have ht := Finset.sum_le_sum (s := Finset.univ) (fun i _ => Finset.sum_le_sum (s := Finset.univ) (fun k _ => + (integral_abs_on_set_le (goeEntry_memLp r i k) hs).trans (mul_le_mul_of_nonneg_right + (sqrt_le_sqrt (goeEntry_integral_sq_le (by dsimp [r]; positivity) i k)) (sqrt_nonneg _)))) + simp only [Finset.sum_const,Finset.card_univ,nsmul_eq_mul] at ht + exact ht.trans_eq (by + dsimp only [r,μ] + rw [show 2*(j/(Fintype.card ι:ℝ))=2*j/(Fintype.card ι:ℝ) by ring] + ring) + apply hm.trans + have hh := div_le_div_of_nonneg_right hsumle (sqrt_nonneg ((Fintype.card ι:ℝ)*γ)) + exact (add_le_add_right hh (μ.real s*(|log γ|+sqrt (Fintype.card ι:ℝ)*(1+j)/sqrt ((Fintype.card ι:ℝ)*γ)))).trans_eq (by ring) +end SKGap + +namespace SKGap +open MeasureTheory Real Set +lemma expectation_upper_good {Ω : Type*} [MeasurableSpace Ω] {μ : Measure Ω} [IsProbabilityMeasure μ] + {F I : Ω → ℝ} {s : Set Ω} (hs : MeasurableSet s) (hF : Integrable F μ) (hI : Integrable I μ) + {D c : ℝ} (hc : 0 ≤ c) (hD : ∀ x, |I x| ≤ D) + (hgood : ∀ x ∉ s, F x ≤ 2*I x+c) : + (∫ x, F x ∂μ) ≤ 2*(∫ x, I x ∂μ)+c+(∫ x in s, |F x| ∂μ)+2*D*μ.real s := by + have hi : Integrable (fun x => 2*I x+c+s.indicator (fun x => |F x|+2*D) x) μ := + ((hI.const_mul 2).add (integrable_const c)).add ((hF.abs.add (integrable_const (2*D))).indicator hs) + have hp (x) : F x ≤ 2*I x+c+s.indicator (fun x => |F x|+2*D) x := by + by_cases hx : x ∈ s + · simp only [Set.indicator_of_mem hx] + have hh := (abs_le.mp (hD x)).1 + nlinarith [le_abs_self (F x)] + · simpa only [Set.indicator_of_notMem hx,add_zero] using hgood x hx + have hh := integral_mono hF hi hp + have hi₁ : Integrable (fun x => 2*I x+c) μ := (hI.const_mul 2).add (integrable_const c) + have hi₂ : Integrable (s.indicator (fun x => |F x|+2*D)) μ := (hF.abs.add (integrable_const (2*D))).indicator hs + rw [integral_add hi₁ hi₂,integral_add (hI.const_mul 2) (integrable_const c), + integral_const_mul,integral_indicator hs,integral_add hF.abs.integrableOn (integrable_const (2*D)), + integral_const,integral_const] at hh + simpa only [probReal_univ,mul_one,smul_eq_mul,measureReal_restrict_apply_univ,one_mul,mul_comm,add_assoc] using hh +end SKGap +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Matrix/LogDetUniform.lean b/lean/OAI/Probability/SKGap/Matrix/LogDetUniform.lean new file mode 100644 index 0000000000000000000000000000000000000000..66cfbc073ecd4b9d52963615afa6c5d89908859d --- /dev/null +++ b/lean/OAI/Probability/SKGap/Matrix/LogDetUniform.lean @@ -0,0 +1,178 @@ +import Mathlib +import OAI.Probability.SKGap.Matrix.RankNorm +import OAI.Probability.SKGap.Brownian.LogDetMesh +import OAI.Probability.SKGap.Stability.LogDetUniformMean + +namespace OAI + +section +noncomputable section +namespace SKGap +open Matrix MeasureTheory ProbabilityTheory Real Set Filter +open scoped BigOperators Matrix.Norms.Frobenius Topology + +theorem actual_logdet_uniform {j ε : ℝ} (hj : 0 < j) (hj1 : j < 1) (hε : 0 < ε) : + ∃ γ₀ : ℝ, 0 < γ₀ ∧ ∀ γ : ℝ, 0 < γ → γ ≤ γ₀ → ∃ N : ℕ, 0 < N ∧ + ∀ n : ℕ, N ≤ n → + (Measure.pi (fun _ : MatrixCoordinates (Fin n) => gaussianReal 0 1)).real + {g | ∃ a : Fin n → ℝ, (∀ i,0 ≤ a i) ∧ (∀ i,a i ≤ 1) ∧ + j*(coordAverage a)^2+ε < LogDet.regularizedLogDet γ + (logPath (j*coordAverage a) a (goeMatrix (j/(n:ℝ)) g) 1)} ≤ + 4*Real.exp (-min 1 (1/(π^2*j))*(n:ℝ)) := by + classical + obtain ⟨B,hB,hmean⟩ := actual_logdet_mean hj hj1 + refine ⟨ε/(4*(B^2+1)),by positivity,?_⟩ + intro γ hγ hγ₀ + obtain ⟨C,hC,N₀,hN₀,hm⟩ := hmean γ hγ + have hγB : γ*B^2 ≤ ε/4 := by + have hh := (le_div_iff₀ (by positivity : 0 < 4*(B^2+1))).mp hγ₀ + nlinarith + let R := 2*sqrt j+1 + have hR : 0 ≤ R := by dsimp [R]; positivity + let K := (2*j+R)/sqrt γ+2*j + have hK : 0 ≤ K := by dsimp [K]; positivity + let δ := ε/(4*(K+1)) + have hδ : 0 < δ := by dsimp [δ]; positivity + have hKδ : K*δ ≤ ε/4 := by + have hh : δ*(4*(K+1))=ε := div_mul_cancel₀ ε (ne_of_gt (by positivity : 0 < 4*(K+1))) + nlinarith + obtain ⟨s,hs,hcover⟩ := scalar_cube_net hδ + let q := γ*(ε/4)^2/(π^2*j) + have hq : 0 < q := by dsimp [q]; positivity + obtain ⟨N₁,hN₁⟩ := exists_nat_ge (4*C/ε) + obtain ⟨N₂,hN₂⟩ := exists_nat_ge (((s.card:ℝ)+1)/q) + refine ⟨max N₀ (max N₁ N₂),hN₀.trans_le (le_max_left _ _),?_⟩ + intro n hn + have hn₀ := (le_max_left N₀ (max N₁ N₂)).trans hn + have hn₁ := (le_max_left N₁ N₂).trans ((le_max_right N₀ (max N₁ N₂)).trans hn) + have hn₂ := (le_max_right N₁ N₂).trans ((le_max_right N₀ (max N₁ N₂)).trans hn) + have hnpos := hN₀.trans_le hn₀ + have hnreal : (0:ℝ) < n := Nat.cast_pos.mpr hnpos + let : Nonempty (Fin n) := Fin.pos_iff_nonempty.mp hnpos + have hCn : C/(n:ℝ) ≤ ε/4 := by + have hh := hN₁.trans (Nat.cast_le.mpr hn₁) + have hh' := (div_le_iff₀ hε).mp hh + apply (div_le_iff₀ hnreal).mpr + nlinarith + let μ := Measure.pi (fun _ : MatrixCoordinates (Fin n) => gaussianReal 0 1) + let M := fun g : MatrixCoordinates (Fin n) → ℝ => goeMatrix (j/(n:ℝ)) g + let T := {g | ∃ v : Fin n → s, j*(coordAverage (fun i => (v i:ℝ)))^2+ε/2+ε/4 < + LogDet.regularizedLogDet γ (logPath (j*coordAverage (fun i => (v i:ℝ))) + (fun i => (v i:ℝ)) (M g) 1)} + let U := {g | R < opNorm (M g)} + have hT : μ.real T ≤ 2*Real.exp (-(n:ℝ)) := by + apply (logdet_mesh_tail hj hγ (by positivity : 0 ≤ ε/4) hnpos s hs ?_).trans + · have hh := product_mesh_absorption hq s.card n (hN₂.trans (Nat.cast_le.mpr hn₂)) + have he : -γ*(n:ℝ)^2*(ε/4)^2/(π^2*j)= -q*(n:ℝ)^2 := by dsimp only [q]; ring + simpa only [he] using hh + · intro a ha ha1 + have hh := hm n hn₀ a ha ha1 + have he : (j/(n:ℝ))*∑ i,a i=j*coordAverage a := by simp only [coordAverage,Fintype.card_fin]; ring + rw [he] at hh + change (∫ g, LogDet.regularizedLogDet γ (logPath (j*coordAverage a) a (M g) 1) ∂μ) ≤ _ + have heavg : (∑ i,a i)/(n:ℝ)=coordAverage a := by simp only [coordAverage,Fintype.card_fin] + rw [heavg] at hh + linarith + have hU : μ.real U ≤ 2*Real.exp (-(n:ℝ)/(π^2*j)) := by + change (gaussianCoordinates (MatrixCoordinates (Fin n))).real + {g | 2*sqrt j+1 < ‖matrixOperator (goeMatrix (j/(n:ℝ)) g)‖} ≤ _ + simpa only [one_pow,_root_.neg_one_mul,Fintype.card_fin] using + (goe_norm_tail (ι := Fin n) hj (by norm_num : (0:ℝ) ≤ 1)) + have hsub : {g | ∃ a : Fin n → ℝ, (∀ i,0 ≤ a i) ∧ (∀ i,a i ≤ 1) ∧ + j*(coordAverage a)^2+ε < LogDet.regularizedLogDet γ (logPath (j*coordAverage a) a (M g) 1)} ⊆ T ∪ U := by + rintro g ⟨a,ha,ha1,hbad⟩ + by_contra hg + have hnot := not_or.mp hg + have hop : opNorm (M g) ≤ R := le_of_not_gt hnot.2 + have hnet (v : Fin n → s) : LogDet.regularizedLogDet γ (logPath (j*coordAverage (fun i => (v i:ℝ))) + (fun i => (v i:ℝ)) (M g) 1) ≤ j*(coordAverage (fun i => (v i:ℝ)))^2+(ε/2+ε/4) := by + have hh : ¬ j*(coordAverage (fun i => (v i:ℝ)))^2+ε/2+ε/4 < + LogDet.regularizedLogDet γ (logPath (j*coordAverage (fun i => (v i:ℝ))) + (fun i => (v i:ℝ)) (M g) 1) := fun hv => hnot.1 ⟨v,hv⟩ + linarith [le_of_not_gt hh] + have hh := logdet_cube_net_transfer hj.le hδ hR hγ s hs hcover hop hnet ha ha1 + change LogDet.regularizedLogDet γ (logPath (j*coordAverage a) a (M g) 1) ≤ + j*(coordAverage a)^2+(ε/2+ε/4)+K*δ at hh + linarith + have hb := (measureReal_mono hsub (measure_ne_top _ _)).trans + ((measureReal_union_le T U).trans (add_le_add hT hU)) + apply hb.trans + have e₁ : Real.exp (-(n:ℝ)) ≤ Real.exp (-min 1 (1/(π^2*j))*(n:ℝ)) := by + apply Real.exp_le_exp.mpr + nlinarith [mul_nonneg (Nat.cast_nonneg n) (sub_nonneg.mpr (min_le_left 1 (1/(π^2*j))))] + have e₂ : Real.exp (-(n:ℝ)/(π^2*j)) ≤ Real.exp (-min 1 (1/(π^2*j))*(n:ℝ)) := by + apply Real.exp_le_exp.mpr + have hh := mul_le_mul_of_nonneg_right (min_le_right 1 (1/(π^2*j))) (Nat.cast_nonneg n) + simp only [div_eq_mul_inv,_root_.one_mul] at hh ⊢ + nlinarith + linarith +end SKGap +end +end + +section +noncomputable section +namespace SKGap +open Matrix MeasureTheory ProbabilityTheory Real Set Filter +open scoped BigOperators Matrix.Norms.Frobenius Topology + +theorem actual_simultaneous_logdet {j ε : ℝ} (hj : 0 < j) (hj1 : j < 1) (hε : 0 < ε) : + ∃ γ₀ : ℝ, 0 < γ₀ ∧ ∀ γ : ℝ, 0 < γ → γ ≤ γ₀ → ∀ r₀ : ℕ, ∀ M₂ : ℝ, + ∃ N : ℕ, 0 < N ∧ ∀ n : ℕ, N ≤ n → + (Measure.pi (fun _ : MatrixCoordinates (Fin n) => gaussianReal 0 1)).real + {g | ∃ a : Fin n → ℝ, (∀ i,0 ≤ a i) ∧ (∀ i,a i ≤ 1) ∧ + ∃ E : Matrix (Fin n) (Fin n) ℝ, E.rank ≤ r₀ ∧ opNorm E ≤ M₂ ∧ + j*(coordAverage a)^2+ε < LogDet.regularizedLogDet γ + (1+((j*coordAverage a) • 1-goeMatrix (j/(n:ℝ)) g)*diagonal a+E)} ≤ + 4*Real.exp (-min 1 (1/(π^2*j))*(n:ℝ)) := by + obtain ⟨γ₀,hγ₀,hbound⟩ := actual_logdet_uniform hj hj1 (half_pos hε) + refine ⟨γ₀,hγ₀,?_⟩ + intro γ hγ hγle r₀ M₂ + obtain ⟨N₀,hN₀,hb⟩ := hbound γ hγ hγle + let D := max 0 M₂ + have hD : 0 ≤ D := le_max_left _ _ + obtain ⟨N₁,hN₁⟩ := exists_nat_ge ((2*D*sqrt (r₀:ℝ)/ε)^2/γ) + refine ⟨max N₀ N₁,hN₀.trans_le (le_max_left _ _),?_⟩ + intro n hn + have hn₀ := (le_max_left N₀ N₁).trans hn + have hn₁ := (le_max_right N₀ N₁).trans hn + have hnpos := hN₀.trans_le hn₀ + have hnreal : (0:ℝ) < n := Nat.cast_pos.mpr hnpos + let : Nonempty (Fin n) := Fin.pos_iff_nonempty.mp hnpos + have hroot : 2*D*sqrt (r₀:ℝ)/ε ≤ sqrt ((n:ℝ)*γ) := by + apply (sq_le_sq₀ (by positivity) (sqrt_nonneg _)).mp + rw [sq_sqrt (by positivity)] + have hh := (div_le_iff₀ hγ).mp (hN₁.trans (Nat.cast_le.mpr hn₁)) + exact hh + have hpert : D*sqrt (r₀:ℝ)/sqrt ((n:ℝ)*γ) ≤ ε/2 := by + apply (div_le_iff₀ (sqrt_pos.mpr (mul_pos hnreal hγ))).mpr + have hh := (div_le_iff₀ hε).mp hroot + nlinarith + apply (measureReal_mono (s₂ := {g | ∃ a : Fin n → ℝ, (∀ i,0 ≤ a i) ∧ (∀ i,a i ≤ 1) ∧ + j*(coordAverage a)^2+ε/2 < LogDet.regularizedLogDet γ + (logPath (j*coordAverage a) a (goeMatrix (j/(n:ℝ)) g) 1)}) ?_ (measure_ne_top _ _)).trans (hb n hn₀) + rintro g ⟨a,ha,ha1,E,hr,hE,hbad⟩ + refine ⟨a,ha,ha1,?_⟩ + let W := goeMatrix (j/(n:ℝ)) g + let L := 1+((j*coordAverage a) • 1-W)*diagonal a + have htr : Lᵀ=logPath (j*coordAverage a) a W 1 := by + have hW : Wᵀ=W := goeMatrix_symm (j/(n:ℝ)) g + simp only [L,transpose_add,transpose_one,transpose_mul,transpose_sub,transpose_smul, + diagonal_transpose,hW,logPath,one_pow,one_mul,one_smul,Matrix.mul_sub,Matrix.mul_smul,Matrix.mul_one] + abel + have hf : LogDet.regularizedLogDet γ (L+E)= + LogDet.regularizedLogDet γ (logPath (j*coordAverage a) a W 1+Eᵀ) := by + rw [← regularizedLogDet_transpose (ne_of_gt hγ) (L+E),transpose_add,htr] + have hh := (abs_le.mp (logdet_rank_perturbation hγ hD + (logPath (j*coordAverage a) a W 1) Eᵀ + (by simpa only [Matrix.rank_transpose] using hr) + (by rw [opNorm_transpose]; exact hE.trans (le_max_right _ _)))).2 + simp only [Fintype.card_fin] at hh + change j*(coordAverage a)^2+ε < LogDet.regularizedLogDet γ (L+E) at hbad + rw [hf] at hbad + linarith +end SKGap +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Matrix/LoopPrediction.lean b/lean/OAI/Probability/SKGap/Matrix/LoopPrediction.lean new file mode 100644 index 0000000000000000000000000000000000000000..a12574496a76c99c4551121ac59e9305fdd3b4b1 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Matrix/LoopPrediction.lean @@ -0,0 +1,125 @@ +import Mathlib +import OAI.Probability.SKGap.Matrix.FockTensor + +namespace OAI + +section + +noncomputable section +open scoped BigOperators +namespace SKGap.Noncrossing.Primary.Tensor.Loop +open Diagram InverseDiagram WordSeries +variable {ι : Type*} [Fintype ι] + +lemma blockDegree_reverse (bs : List Bool) : blockDegree bs.reverse=blockDegree bs := by + simp [blockDegree,List.map_reverse] +def blockReverse (n : ℕ) : Blocks n ≃ Blocks n where + toFun bs := ⟨bs.val.reverse,by rw [blockDegree_reverse]; exact bs.property⟩ + invFun bs := ⟨bs.val.reverse,by rw [blockDegree_reverse]; exact bs.property⟩ + left_inv bs := Subtype.ext (List.reverse_reverse bs.val) + right_inv bs := Subtype.ext (List.reverse_reverse bs.val) + +def blockPrepend (n : ℕ) : Blocks (n+1) ⊕ Blocks n → Blocks (n+2) + | .inl bs => ⟨true::bs.val,by rw [blockDegree_true,bs.property]⟩ + | .inr bs => ⟨false::bs.val,by rw [blockDegree_false,bs.property]⟩ +lemma blockPrepend_bijective (n : ℕ) : Function.Bijective (blockPrepend n) := by + constructor + · intro x y h + have hv := congrArg (fun q : Blocks (n+2) => q.val) h + cases x <;> cases y <;> simp only [blockPrepend] at hv + · exact congrArg Sum.inl (Subtype.ext (List.cons.inj hv).2) + · exact False.elim (Bool.noConfusion (List.cons.inj hv).1) + · exact False.elim (Bool.noConfusion (List.cons.inj hv).1) + · exact congrArg Sum.inr (Subtype.ext (List.cons.inj hv).2) + · rintro ⟨bs,hbs⟩ + cases bs with + | nil => simp only [blockDegree_nil] at hbs; omega + | cons b bs => + cases b with + | true => exact ⟨.inl ⟨bs,by rw [blockDegree_true] at hbs; omega⟩,rfl⟩ + | false => exact ⟨.inr ⟨bs,by rw [blockDegree_false] at hbs; omega⟩,rfl⟩ + +def blockSnocEquiv (n : ℕ) : Blocks (n+1) ⊕ Blocks n ≃ Blocks (n+2) := + ((blockReverse (n+1)).sumCongr (blockReverse n)).trans + ((Equiv.ofBijective (blockPrepend n) (blockPrepend_bijective n)).trans (blockReverse (n+2))) +@[simp] lemma blockSnocEquiv_inl (n : ℕ) (bs : Blocks (n+1)) : + (blockSnocEquiv n (.inl bs)).val=bs.val++[true] := by + change (true::bs.val.reverse).reverse=bs.val++[true] + simp +@[simp] lemma blockSnocEquiv_inr (n : ℕ) (bs : Blocks n) : + (blockSnocEquiv n (.inr bs)).val=bs.val++[false] := by + change (false::bs.val.reverse).reverse=bs.val++[false] + simp + +lemma sum_blocks_snoc {M : Type*} [AddCommMonoid M] (n : ℕ) (f : List Bool→M) : + (∑ bs : Blocks (n+2),f bs.val)= + (∑ bs : Blocks (n+1),f (bs.val++[true]))+(∑ bs : Blocks n,f (bs.val++[false])) := by + have h := Fintype.sum_equiv (blockSnocEquiv n) + (fun s => match s with | .inl bs => f (bs.val++[true]) | .inr bs => f (bs.val++[false])) + (fun bs => f bs.val) (by intro s; cases s <;> simp) + exact h.symm.trans (Fintype.sum_sum_type _) + +lemma blocks_one (bs : Blocks 1) : bs.val=[true] := by + have h := (mem_blockEnumerate bs.val 1).mpr bs.property + simpa [blockEnumerate] using h +instance blocksOneUnique : Unique (Blocks 1) where + default := ⟨[true],rfl⟩ + uniq bs := Subtype.ext (blocks_one bs) + +def kernel (j : ℝ) (a : ι→ℝ) (n : ℕ) : Space (ι:=ι)→ₗ[ℝ] Space (ι:=ι) := + ∑ bs : Blocks n,word j (chain j a bs.val) +lemma kernel_zero (j : ℝ) (a : ι→ℝ) : kernel j a 0=LinearMap.id := by + simp [kernel,blocks_zero,word] +lemma kernel_one (j : ℝ) (a : ι→ℝ) : kernel j a 1=(diagonal a).comp (noise j) := by + simp [kernel,blocks_one,word,letter] +lemma kernel_add_two (j : ℝ) (a : ι→ℝ) (n : ℕ) : + kernel j a (n+2)=(kernel j a (n+1)).comp ((diagonal a).comp (noise j))- + (j*Diagram.mean a) • (kernel j a n).comp (diagonal a) := by + refine (sum_blocks_snoc n (fun bs => word j (chain j a bs))).trans ?_ + simp only [chain_append,chain_true,chain_false,chain_nil,word_append,word,letter, + LinearMap.comp_id,diagonal_scale,LinearMap.comp_smul] + ext v i I + simp [kernel,LinearMap.sum_apply,LinearMap.comp_apply,Finset.sum_neg_distrib, + ←Finset.mul_sum,sub_eq_add_neg] + +lemma project_kernel_zero_creation (j : ℝ) (a p : ι→ℝ) (v : Space (ι:=ι)) : + project (kernel j a 0 (diagonal p (creation v)))=0 := by + rw [kernel_zero]; exact project_diagonal_creation p v + +lemma project_kernel_creation (j : ℝ) (a : ι→ℝ) (n : ℕ) (v : Space (ι:=ι)) : + project (kernel j a (n+1) (diagonal a (creation v)))= + (j*Diagram.mean a) • project (kernel j a n (diagonal a v)) := by + induction n generalizing v with + | zero => + simp only [kernel_one,kernel_zero,LinearMap.comp_apply,LinearMap.id_apply,noise, + LinearMap.add_apply,LinearMap.smul_apply,map_add,map_smul, + annihilation_diagonal_creation,project_diagonal_creation,zero_add,smul_smul] + | succ n ih => + rw [show n+1+1=n+2 by omega,kernel_add_two] + simp only [LinearMap.sub_apply,LinearMap.comp_apply,LinearMap.smul_apply,noise, + LinearMap.add_apply,annihilation_diagonal_creation,map_add,map_sub,map_smul, + smul_smul] + rw [ih] + abel + +lemma project_kernel_incoming (j : ℝ) (a p : ι→ℝ) (n : ℕ) (v : Space (ι:=ι)) : + project (kernel j a (n+1) (diagonal p (creation v)))= + (j*Diagram.mean p) • project (kernel j a n (diagonal a v)) := by + cases n with + | zero => + simp only [kernel_one,kernel_zero,LinearMap.comp_apply,LinearMap.id_apply,noise, + LinearMap.add_apply,LinearMap.smul_apply,map_add,map_smul, + annihilation_diagonal_creation,project_diagonal_creation,zero_add,smul_smul] + | succ n => + rw [show n+1+1=n+2 by omega,kernel_add_two] + simp only [LinearMap.sub_apply,LinearMap.comp_apply,LinearMap.smul_apply,noise, + LinearMap.add_apply,annihilation_diagonal_creation,map_add,map_sub,map_smul, + smul_smul] + rw [project_kernel_creation] + abel +end SKGap.Noncrossing.Primary.Tensor.Loop + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Matrix/MarkedWordIBP.lean b/lean/OAI/Probability/SKGap/Matrix/MarkedWordIBP.lean new file mode 100644 index 0000000000000000000000000000000000000000..eabc24d0347abcc0bb73c4d009426dfb1b2bb0fe --- /dev/null +++ b/lean/OAI/Probability/SKGap/Matrix/MarkedWordIBP.lean @@ -0,0 +1,234 @@ +import Mathlib +import OAI.Probability.SKGap.Matrix.WordDerivative + +namespace OAI + +section +noncomputable section +namespace SKGap +open Matrix Real MeasureTheory ProbabilityTheory Set +open scoped BigOperators Matrix.Norms.Frobenius SchwartzMap +variable {ι : Type*} [Fintype ι] [DecidableEq ι] + +omit [DecidableEq ι] in +lemma matrix_marked_expand (U W Q : Matrix ι ι ℝ) (i : ι) : + (U*W*Q) i i=∑ a,∑ b,W a b*(U i a*Q b i) := by + simp only [Matrix.mul_apply,Finset.sum_mul] + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro a _;apply Finset.sum_congr rfl + intro b _;ring + +theorem goe_marked_sum_IBP {r : ℝ} (hr : 0≤r) + (H : ι→ι→Matrix ι ι ℝ→ℝ) (d : ι→ι→(MatrixCoordinates ι→ℝ)→ℝ) + {L : NNReal} {C D : ℝ} {s : Set (MatrixCoordinates ι→ℝ)} + (hL : ∀ a b,LipschitzWith L (fun g=>H a b (goeMatrix r g))) + (hC : ∀ a b g,‖H a b (goeMatrix r g)‖≤C) + (hd : ∀ a b,Measurable (d a b)) (hD : ∀ a b g,‖d a b g‖≤D) + (hs : MeasurableSet s) + (hder : ∀ a b g,g∈s→HasDerivAt (fun t : ℝ=>H a b (goeMatrix r g+t • symmetricElementary a b)) (d a b g) 0) : + let μ := Measure.pi (fun _ : MatrixCoordinates ι=>gaussianReal 0 1) + |(∫ g,∑ a,∑ b,goeMatrix r g a b*H a b (goeMatrix r g) ∂μ)- + r*(∫ g,∑ a,∑ b,d a b g ∂μ)|≤ + (Fintype.card ι:ℝ)^2*(sqrt (2*r)*(L:ℝ)+r*D)*μ.real sᶜ := by + intro μ + have hWi (a b : ι) : Integrable (fun g=>goeMatrix r g a b*H a b (goeMatrix r g)) μ := by + simpa only [mul_comm] using ((goeEntry_memLp r a b).integrable (by norm_num)).bdd_mul + (hL a b).continuous.aestronglyMeasurable (ae_of_all _ (hC a b)) + have hdi (a b : ι) : Integrable (d a b) μ := + (integrable_const D).mono' (hd a b).aestronglyMeasurable (ae_of_all _ (hD a b)) + rw [integral_finsetSum _ (fun a _=>integrable_finsetSum _ (fun b _=>hWi a b)), + integral_finsetSum _ (fun a _=>integrable_finsetSum _ (fun b _=>hdi a b))] + simp_rw [integral_finsetSum _ (fun b _=>hWi _ b),integral_finsetSum _ (fun b _=>hdi _ b), + Finset.mul_sum,← Finset.sum_sub_distrib] + apply (Finset.abs_sum_le_sum_abs _ _).trans + calc + _ ≤ ∑ a : ι,∑ b : ι,(sqrt (2*r)*(L:ℝ)+r*D)*μ.real sᶜ := by + apply Finset.sum_le_sum + intro a _ + apply (Finset.abs_sum_le_sum_abs _ _).trans + exact Finset.sum_le_sum (fun b _=>goe_IBP_error hr a b (hL a b) (hC a b) + (hd a b) (hD a b) hs (hder a b)) + _ = _ := by simp only [Finset.sum_const,Finset.card_univ,nsmul_eq_mul];ring + +lemma actualWord_append (f : 𝓢(ℝ,ℂ)) {R : ℝ} (hR : 0≤R) (j : ℝ) (a : ι→ℝ) (z : ℝ) + (F G : List (WordLetter ι)) (M : Matrix ι ι ℝ) : + actualWord f R hR j a z (F++G) M=actualWord f R hR j a z F M*actualWord f R hR j a z G M := by + simp only [actualWord,matrixFactorProduct,List.map_append,List.prod_append] + +lemma actualWordDirection_append (f : 𝓢(ℝ,ℂ)) {R : ℝ} (hR : 0≤R) (j : ℝ) (a : ι→ℝ) (z : ℝ) + (F G : List (WordLetter ι)) (M E : Matrix ι ι ℝ) : + actualWordDirection f R hR j a z M E (F++G)= + actualWordDirection f R hR j a z M E F*actualWord f R hR j a z G M+ + actualWord f R hR j a z F M*actualWordDirection f R hR j a z M E G := by + induction F with + | nil => simp [actualWordDirection,actualWord,matrixFactorProduct] + | cons l F ih => + simp only [List.cons_append,actualWordDirection,actualWord_append,ih] + change l.direction f R hR j a z M E*(actualWord f R hR j a z F M*actualWord f R hR j a z G M)+ + l.eval f R hR j a z M*(actualWordDirection f R hR j a z M E F*actualWord f R hR j a z G M+ + actualWord f R hR j a z F M*actualWordDirection f R hR j a z M E G)= + (l.direction f R hR j a z M E*actualWord f R hR j a z F M+ + l.eval f R hR j a z M*actualWordDirection f R hR j a z M E F)*actualWord f R hR j a z G M+ + (l.eval f R hR j a z M*actualWord f R hR j a z F M)*actualWordDirection f R hR j a z M E G + noncomm_ring +end SKGap +end +end + +section +noncomputable section +namespace SKGap +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius +variable {ι : Type*} [Fintype ι] [DecidableEq ι] + +lemma matrix_word_contraction (U V Q : Matrix ι ι ℝ) (i : ι) : + (∑ a,∑ b,U i a*(V*symmetricElementary a b*Q) b i) = + (U*Q) i i*trace V+(U*Vᵀ*Q) i i := by + simp_rw [mul_symmetricElementary_mul,mul_add] + simp only [Finset.sum_add_distrib] + have h1 : (∑ a,∑ b,U i a*(V b a*Q b i))=(U*Vᵀ*Q) i i := by + simp only [Matrix.mul_apply,transpose_apply,Finset.sum_mul] + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro b _;apply Finset.sum_congr rfl + intro a _;ring + have h2 : (∑ a,∑ b,U i a*(V b b*Q a i))=(U*Q) i i*trace V := by + simp only [Matrix.mul_apply,Matrix.trace,Finset.sum_mul,Finset.mul_sum] + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro a _;apply Finset.sum_congr rfl + intro b _;dsimp only [Matrix.diag];ring + rw [h1,h2,add_comm] + +lemma matrix_word_reverse_bound (U V Q : Matrix ι ι ℝ) (i : ι) : + |(U*Vᵀ*Q) i i| ≤ opNorm U*opNorm V*opNorm Q := by + apply (matrix_entry_le_opNorm (U*Vᵀ*Q) i i).trans + apply (opNorm_mul (U*Vᵀ) Q).trans + have hh := mul_le_mul_of_nonneg_right (opNorm_mul U Vᵀ) (show 0 ≤ opNorm Q from norm_nonneg _) + simpa only [opNorm_transpose] using hh + +lemma matrix_word_scaled_contraction (U V Q : Matrix ι ι ℝ) (i : ι) {j : ℝ} (hj : 0 ≤ j) : + |(j/Fintype.card ι)*(∑ a,∑ b,U i a*(V*symmetricElementary a b*Q) b i)- + j*(trace V/Fintype.card ι)*(U*Q) i i| ≤ + (j/Fintype.card ι)*(opNorm U*opNorm V*opNorm Q) := by + rw [matrix_word_contraction] + have he : (j/Fintype.card ι)*((U*Q) i i*trace V+(U*Vᵀ*Q) i i)- + j*(trace V/Fintype.card ι)*(U*Q) i i= + (j/Fintype.card ι)*(U*Vᵀ*Q) i i := by ring + rw [he,abs_mul,abs_of_nonneg (div_nonneg hj (Nat.cast_nonneg _))] + exact mul_le_mul_of_nonneg_left (matrix_word_reverse_bound U V Q i) (div_nonneg hj (Nat.cast_nonneg _)) +end SKGap +end +end + +section +noncomputable section +namespace SKGap +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius SchwartzMap + +structure WordCut (ι : Type*) where + left : List (WordLetter ι) + right : List (WordLetter ι) + inversePartner : Bool + +variable {ι : Type*} + +def WordCut.prepend (l : WordLetter ι) (c : WordCut ι) : WordCut ι := + ⟨l::c.left,c.right,c.inversePartner⟩ + +def wordPartners (a : ι→ℝ) : List (WordLetter ι)→List (WordCut ι) + | [] => [] + | l::F => (match l with + | .diag _ => [] + | .noise => [⟨[],F,false⟩] + | .inverse => [⟨[.inverse,.diag a],.inverse::F,true⟩]) ++ + (wordPartners a F).map (WordCut.prepend l) + +lemma wordPartners_cons (a : ι→ℝ) (l : WordLetter ι) (F : List (WordLetter ι)) : + wordPartners a (l::F)=(match l with + | .diag _ => [] + | .noise => [⟨[],F,false⟩] + | .inverse => [⟨[.inverse,.diag a],.inverse::F,true⟩]) ++ + (wordPartners a F).map (WordCut.prepend l) := rfl + +variable [Fintype ι] [DecidableEq ι] + +lemma actualWord_nil (f : 𝓢(ℝ,ℂ)) {R : ℝ} (hR : 0≤R) (j : ℝ) (a : ι→ℝ) (z : ℝ) + (M : Matrix ι ι ℝ) : actualWord f R hR j a z [] M=1 := rfl +lemma actualWord_cons (f : 𝓢(ℝ,ℂ)) {R : ℝ} (hR : 0≤R) (j : ℝ) (a : ι→ℝ) (z : ℝ) + (M : Matrix ι ι ℝ) (l : WordLetter ι) (F : List (WordLetter ι)) : + actualWord f R hR j a z (l::F) M=l.eval f R hR j a z M*actualWord f R hR j a z F M := rfl + +def WordCut.value (f : 𝓢(ℝ,ℂ)) {R : ℝ} (hR : 0≤R) (j : ℝ) (a : ι→ℝ) (z : ℝ) + (M E : Matrix ι ι ℝ) (c : WordCut ι) : Matrix ι ι ℝ := + (if c.inversePartner then z else 1) • + (actualWord f R hR j a z c.left M*E*actualWord f R hR j a z c.right M) + +lemma WordCut.value_prepend (f : 𝓢(ℝ,ℂ)) {R : ℝ} (hR : 0≤R) (j : ℝ) (a : ι→ℝ) (z : ℝ) + (M E : Matrix ι ι ℝ) (l : WordLetter ι) (c : WordCut ι) : + (c.prepend l).value f hR j a z M E=l.eval f R hR j a z M*c.value f hR j a z M E := by + simp only [WordCut.value,WordCut.prepend,actualWord_cons,Matrix.mul_smul,mul_assoc] + rfl + +theorem actualWordDirection_partners (f : 𝓢(ℝ,ℂ)) {R : ℝ} (hR : 0≤R) (j : ℝ) + (a : ι→ℝ) (z : ℝ) (M E : Matrix ι ι ℝ) (F : List (WordLetter ι)) : + actualWordDirection f R hR j a z M E F= + ((wordPartners a F).map (WordCut.value f hR j a z M E)).sum := by + induction F with + | nil => rfl + | cons l F ih => + rw [actualWordDirection,ih] + rw [wordPartners_cons a l F,List.map_append,List.sum_append] + have hm : (((wordPartners a F).map (WordCut.prepend l)).map (WordCut.value f hR j a z M E)).sum= + l.eval f R hR j a z M*((wordPartners a F).map (WordCut.value f hR j a z M E)).sum := by + simp only [List.map_map,Function.comp_def,WordCut.value_prepend,List.sum_map_mul_left] + rw [hm] + congr 1 + cases l with + | diag d => simp [WordLetter.direction] + | noise => simp [WordLetter.direction,WordCut.value,actualWord_nil] + | inverse => + simp only [WordLetter.direction,WordCut.value,ite_true,List.map_cons, + List.map_nil,List.sum_cons,List.sum_nil,add_zero,actualWord_cons,actualWord_nil, + WordLetter.eval,mul_one,Matrix.smul_mul,mul_assoc] + +omit [Fintype ι] [DecidableEq ι] in +def ordinaryCount (F : List (WordLetter ι)) : ℕ := + F.countP (fun l=>match l with | .noise=>true | _=>false) +omit [Fintype ι] [DecidableEq ι] in +def inverseCount (F : List (WordLetter ι)) : ℕ := + F.countP (fun l=>match l with | .inverse=>true | _=>false) + +omit [Fintype ι] [DecidableEq ι] in +lemma wordPartners_counts (a : ι→ℝ) (F : List (WordLetter ι)) (c : WordCut ι) + (hc : c∈wordPartners a F) : + ordinaryCount c.left+ordinaryCount c.right+(if c.inversePartner then 0 else 1)=ordinaryCount F ∧ + inverseCount c.left+inverseCount c.right=inverseCount F+(if c.inversePartner then 1 else 0) := by + induction F generalizing c with + | nil => simp [wordPartners] at hc + | cons l F ih => + rw [wordPartners_cons a l F,List.mem_append] at hc + rcases hc with hc|hc + · cases l with + | diag d => simp at hc + | noise => + simp only [List.mem_singleton] at hc + subst c + simp [ordinaryCount,inverseCount] + | inverse => + simp only [List.mem_singleton] at hc + subst c + simp [ordinaryCount,inverseCount] + omega + · obtain ⟨d,hd,rfl⟩ := List.mem_map.mp hc + obtain ⟨h1,h2⟩ := ih d hd + cases hf : d.inversePartner <;> cases l <;> + simp [WordCut.prepend,ordinaryCount,inverseCount,hf] at * <;> omega +end SKGap +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Matrix/MatrixCoordinates.lean b/lean/OAI/Probability/SKGap/Matrix/MatrixCoordinates.lean new file mode 100644 index 0000000000000000000000000000000000000000..d283b0344ee9e414981c90b8e55e518e4b9f300f --- /dev/null +++ b/lean/OAI/Probability/SKGap/Matrix/MatrixCoordinates.lean @@ -0,0 +1,99 @@ +import Mathlib +import OAI.Probability.SKGap.Model + +namespace OAI + +noncomputable section + +open MeasureTheory ProbabilityTheory InformationTheory Real Set +open scoped NNReal ENNReal +open Filter +open scoped Topology +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius ENNReal NNReal +namespace SKGap +abbrev MatrixCoordinates (ι : Type*) := (ι × ι) ⊕ ι + +variable {ι : Type*} + +def goeMatrix (r : ℝ) (g : MatrixCoordinates ι → ℝ) : Matrix ι ι ℝ := + fun i k => sqrt (2*r)/2 * (g (.inl (i,k)) + g (.inl (k,i))) + +variable [Fintype ι] + +def rawCoordinateMatrix (g : MatrixCoordinates ι → ℝ) : Matrix ι ι ℝ := + fun i k => g (.inl (i,k)) + +lemma rawCoordinateMatrix_norm (g : EuclideanSpace ℝ (MatrixCoordinates ι)) : + ‖rawCoordinateMatrix g‖ ≤ ‖g‖ := by + apply nonneg_le_nonneg_of_sq_le_sq (norm_nonneg _) + simp only [← sq] + rw [Matrix.frobenius_norm_def,← Real.sqrt_eq_rpow,Real.sq_sqrt (by positivity), + EuclideanSpace.norm_sq_eq] + simp only [Real.rpow_two,Real.norm_eq_abs,sq_abs,Fintype.sum_sum_type,Fintype.sum_prod_type, + rawCoordinateMatrix] + exact le_add_of_nonneg_right (Finset.sum_nonneg (fun _ _ => sq_nonneg _)) + +lemma goeMatrix_norm (r : ℝ) (g : EuclideanSpace ℝ (MatrixCoordinates ι)) : + ‖goeMatrix r g‖ ≤ sqrt (2*r)*‖g‖ := by + have he : goeMatrix r g = (sqrt (2*r)/2) • + (rawCoordinateMatrix g+(rawCoordinateMatrix g)ᵀ) := by ext; rfl + rw [he,norm_smul,Real.norm_eq_abs,abs_of_nonneg (by positivity)] + calc + _ ≤ (sqrt (2*r)/2)*(‖rawCoordinateMatrix g‖+‖(rawCoordinateMatrix g)ᵀ‖) := + mul_le_mul_of_nonneg_left (norm_add_le _ _) (by positivity) + _ = sqrt (2*r)*‖rawCoordinateMatrix g‖ := by rw [Matrix.frobenius_norm_transpose]; ring + _ ≤ _ := mul_le_mul_of_nonneg_left (rawCoordinateMatrix_norm g) (sqrt_nonneg _) + +omit [Fintype ι] in +lemma goeMatrix_sub (r : ℝ) (g h : MatrixCoordinates ι → ℝ) : + goeMatrix r (g-h) = goeMatrix r g-goeMatrix r h := by + ext i k; simp only [goeMatrix,Pi.sub_apply,Matrix.sub_apply]; ring + +lemma goeMatrix_L2_lipschitz (r : ℝ) : + LipschitzWith ⟨sqrt (2*r),sqrt_nonneg _⟩ + (fun g : EuclideanSpace ℝ (MatrixCoordinates ι) => goeMatrix r g) := by + apply LipschitzWith.of_dist_le_mul + intro g h + simpa only [dist_eq_norm,← goeMatrix_sub] using! goeMatrix_norm r (g-h) + +lemma goeMatrix_pi_lipschitz (r : ℝ) : + LipschitzWith (⟨sqrt (2*r),sqrt_nonneg _⟩ * + (Fintype.card (MatrixCoordinates ι) : ℝ≥0) ^ (1/(2:ℝ≥0∞)).toReal) + (goeMatrix (ι := ι) r) := by + exact (goeMatrix_L2_lipschitz (ι := ι) r).comp + (PiLp.lipschitzWith_toLp 2 (fun _ : MatrixCoordinates ι => ℝ)) + +variable [DecidableEq ι] + +def symmetricElementary (a b : ι) : Matrix ι ι ℝ := + Matrix.single a b 1+Matrix.single b a 1 + +omit [Fintype ι] in +lemma goeMatrix_update (r : ℝ) (g : MatrixCoordinates ι → ℝ) (a b : ι) (t : ℝ) : + goeMatrix r (Function.update g (.inl (a,b)) t) = + goeMatrix r g + ((sqrt (2*r)/2)*(t-g (.inl (a,b)))) • symmetricElementary a b := by + ext i k + simp only [goeMatrix,Matrix.add_apply,Matrix.smul_apply,smul_eq_mul,symmetricElementary, + Matrix.single_apply] + by_cases hi : i=a <;> by_cases hk : k=b <;> by_cases hi' : i=b <;> by_cases hk' : k=a <;> + simp_all [Function.update_apply,Prod.ext_iff,eq_comm] <;> ring + +lemma symmetricElementary_norm_le (a b : ι) : ‖symmetricElementary a b‖ ≤ 2 := by + unfold symmetricElementary + exact (norm_add_le _ _).trans (by simpa [Matrix.frobenius_norm_def,Matrix.single_apply,ite_and] using (show (1:ℝ)+1 ≤ 2 by norm_num)) + +lemma goeMatrix_updated_hasDerivAt (r : ℝ) (g : MatrixCoordinates ι → ℝ) (a b : ι) : + HasDerivAt (fun t => goeMatrix r (Function.update g (.inl (a,b)) t)) + ((sqrt (2*r)/2) • symmetricElementary a b) (g (.inl (a,b))) := by + simp_rw [goeMatrix_update] + have ha := (hasDerivAt_id (g (.inl (a,b)))).sub_const (g (.inl (a,b))) + have hb := ha.const_mul (sqrt (2*r)/2) + have hh := (hb.smul_const (symmetricElementary a b)).const_add (goeMatrix r g) + simpa only [mul_one,id_eq] using! hh + +end SKGap + +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Matrix/MatrixEntryCLM.lean b/lean/OAI/Probability/SKGap/Matrix/MatrixEntryCLM.lean new file mode 100644 index 0000000000000000000000000000000000000000..e684c140a01cd865e4b0f57aa3174d6d9174f6ae --- /dev/null +++ b/lean/OAI/Probability/SKGap/Matrix/MatrixEntryCLM.lean @@ -0,0 +1,113 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.FrobeniusSq + +namespace OAI + +section +noncomputable section +open MeasureTheory ProbabilityTheory InformationTheory Real Set +open scoped NNReal ENNReal +open Filter +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius ENNReal NNReal +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius NNReal +namespace SKGap +variable {ι : Type*} [Fintype ι] [DecidableEq ι] + +lemma matrix_entry_le_frobenius (M : Matrix ι ι ℝ) (i k : ι) : |M i k| ≤ ‖M‖ := by + have h₁ : (M i k)^2 ≤ ∑ j, (M i j)^2 := + Finset.single_le_sum (fun j _ => sq_nonneg _) (Finset.mem_univ k) + have h₂ : (∑ j, (M i j)^2) ≤ ∑ a,∑ j, (M a j)^2 := + Finset.single_le_sum (fun a _ => Finset.sum_nonneg (fun j _ => sq_nonneg _)) (Finset.mem_univ i) + have hh : (M i k)^2 ≤ ‖M‖^2 := by rw [frobenius_sq]; exact h₁.trans h₂ + nlinarith only [hh,sq_abs (M i k),abs_nonneg (M i k),norm_nonneg M] + +noncomputable def matrixEntryCLM (i k : ι) : Matrix ι ι ℝ →L[ℝ] ℝ := + ({ toFun := fun M => M i k + map_add' := by intros; rfl + map_smul' := by intros; rfl } : Matrix ι ι ℝ →ₗ[ℝ] ℝ).mkContinuous 1 + (fun M => by simpa [Real.norm_eq_abs] using! matrix_entry_le_frobenius M i k) + +lemma matrixEntry_lipschitz (i k : ι) : LipschitzWith 1 (fun M : Matrix ι ι ℝ => M i k) := by + apply LipschitzWith.of_dist_le_mul + intro M N + simpa only [dist_eq_norm,Real.norm_eq_abs,NNReal.coe_one,one_mul,Matrix.sub_apply] using! + matrix_entry_le_frobenius (M-N) i k + +omit [DecidableEq ι] in +lemma matrixEntry_derivative {f : ℝ → Matrix ι ι ℝ} {v : Matrix ι ι ℝ} {t : ℝ} + (hf : HasDerivAt f v t) (i k : ι) : HasDerivAt (fun s => f s i k) (v i k) t := by + classical + exact (matrixEntryCLM i k).hasFDerivAt.comp_hasDerivAt t hf + +lemma matrix_inverse_diff_bound (K B E : Matrix ι ι ℝ) : + ‖K*B*E*K‖ ≤ opNorm K*(opNorm B*‖E‖)*opNorm K := by + calc + _ ≤ ‖K*B*E‖*opNorm K := frobenius_mul_le_opNorm_right _ _ + _ = ‖K*(B*E)‖*opNorm K := by rw [mul_assoc K B E] + _ ≤ (opNorm K*‖B*E‖)*opNorm K := + mul_le_mul_of_nonneg_right (frobenius_mul_le_opNorm _ _) (norm_nonneg _) + _ ≤ _ := mul_le_mul_of_nonneg_right + (mul_le_mul_of_nonneg_left (frobenius_mul_le_opNorm _ _) (norm_nonneg _)) (norm_nonneg _) + +noncomputable def diagonalVector (M : Matrix ι ι ℝ) : EuclideanSpace ℝ ι := + WithLp.toLp 2 (fun i => M i i) + +lemma diagonalVector_norm_le (M : Matrix ι ι ℝ) : ‖diagonalVector M‖ ≤ ‖M‖ := by + apply nonneg_le_nonneg_of_sq_le_sq (norm_nonneg M) + simp only [← sq] + rw [EuclideanSpace.norm_sq_eq,frobenius_sq] + apply Finset.sum_le_sum + intro i _ + simpa only [diagonalVector,Real.norm_eq_abs,sq_abs] using + (Finset.single_le_sum (fun j _ => sq_nonneg (M i j)) (Finset.mem_univ i)) + +lemma abs_trace_le_frobenius (M : Matrix ι ι ℝ) : + |Matrix.trace M| ≤ sqrt (Fintype.card ι)*‖M‖ := by + let v : EuclideanSpace ℝ ι := WithLp.toLp 2 (fun _ => 1) + have hv : ‖v‖ = sqrt (Fintype.card ι) := by + rw [EuclideanSpace.norm_eq]; simp [v] + have hi := abs_real_inner_le_norm (diagonalVector M) v + change |∑ i, 1*M i i| ≤ ‖diagonalVector M‖*‖v‖ at hi + simp only [one_mul,hv] at hi + change |Matrix.trace M| ≤ ‖diagonalVector M‖*sqrt (Fintype.card ι) at hi + exact hi.trans ((mul_le_mul_of_nonneg_right (diagonalVector_norm_le M) (sqrt_nonneg _)).trans_eq (mul_comm _ _)) + +lemma matrixTrace_mul_lipschitz {Ω : Type*} [PseudoMetricSpace Ω] + {K : Ω → Matrix ι ι ℝ} {L : ℝ≥0} (hK : LipschitzWith L K) + (B : Matrix ι ι ℝ) : + LipschitzWith (⟨sqrt (Fintype.card ι)*opNorm B,by exact mul_nonneg (sqrt_nonneg _) (norm_nonneg _)⟩*L) + (fun x => Matrix.trace (K x*B)) := by + apply LipschitzWith.of_dist_le_mul + intro x y + change |Matrix.trace (K x*B)-Matrix.trace (K y*B)| ≤ + (sqrt (Fintype.card ι)*opNorm B*(L:ℝ))*dist x y + rw [← Matrix.trace_sub,← sub_mul] + calc + _ ≤ sqrt (Fintype.card ι)*‖(K x-K y)*B‖ := abs_trace_le_frobenius _ + _ ≤ sqrt (Fintype.card ι)*(‖K x-K y‖*opNorm B) := + mul_le_mul_of_nonneg_left (frobenius_mul_le_opNorm_right _ _) (sqrt_nonneg _) + _ ≤ sqrt (Fintype.card ι)*(((L:ℝ)*dist x y)*opNorm B) := by + exact mul_le_mul_of_nonneg_left + (mul_le_mul_of_nonneg_right (by simpa only [dist_eq_norm] using hK.dist_le_mul x y) + (norm_nonneg _)) (sqrt_nonneg _) + _ = _ := by ring + +end SKGap + +noncomputable section +open MeasureTheory ProbabilityTheory Real Set Filter +open MeasureTheory.Measure +open scoped ENNReal NNReal MeasureTheory Topology + +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Matrix/MatrixLogDet.lean b/lean/OAI/Probability/SKGap/Matrix/MatrixLogDet.lean new file mode 100644 index 0000000000000000000000000000000000000000..808d354806b00a7b318e257a2e6ed7dd234e4e03 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Matrix/MatrixLogDet.lean @@ -0,0 +1,70 @@ +import Mathlib +import OAI.Probability.SKGap.Model + +namespace OAI + +section + +noncomputable section +namespace SKGap.LogDet +open Matrix +open scoped BigOperators +variable {ι : Type*} [Fintype ι] [DecidableEq ι] + +private def detMultilinear : ContinuousMultilinearMap ℝ (fun _ : ι => ι → ℝ) ℝ := + { (Matrix.detRowAlternating : (ι → ℝ) [⋀^ι]→ₗ[ℝ] ℝ).toMultilinearMap with + cont := by change Continuous (fun M : Matrix ι ι ℝ => M.det); fun_prop } + +lemma hasDerivAt_det_update {Q : ℝ → Matrix ι ι ℝ} {Q' : Matrix ι ι ℝ} {t : ℝ} + (hQ : ∀ i k, HasDerivAt (fun x => Q x i k) (Q' i k) t) : + HasDerivAt (fun x => (Q x).det) (∑ i, ((Q t).updateRow i (Q' i)).det) t := by + have hrow (i : ι) : HasDerivAt (fun x => Q x i) (Q' i) t := hasDerivAt_pi.mpr (hQ i) + have h := (HasFDerivAt.multilinear_comp (f := detMultilinear (ι := ι)) + (fun i => (hrow i).hasFDerivAt)).hasDerivAt + convert h using 1 <;> try rfl + simp only [_root_.sum_apply,ContinuousLinearMap.comp_apply, + ContinuousLinearMap.toSpanSingleton_apply,one_smul, + ContinuousMultilinearMap.toContinuousLinearMap_apply] + rfl + +lemma det_updateRow_trace (M H : Matrix ι ι ℝ) : + (∑ i, (M.updateRow i (H i)).det)= (H*M.adjugate).trace := by + simp only [Matrix.trace,Matrix.diag,Matrix.mul_apply] + apply Finset.sum_congr rfl + intro i _ + rw [← Matrix.cramer_transpose_apply,Matrix.cramer_eq_adjugate_mulVec, + ← Matrix.adjugate_transpose] + simp only [Matrix.mulVec,Matrix.transpose_apply,dotProduct] + apply Finset.sum_congr rfl + intro k _ + ring + +lemma hasDerivAt_det_adjugate {Q : ℝ → Matrix ι ι ℝ} {Q' : Matrix ι ι ℝ} {t : ℝ} + (hQ : ∀ i k, HasDerivAt (fun x => Q x i k) (Q' i k) t) : + HasDerivAt (fun x => (Q x).det) (Q'*(Q t).adjugate).trace t := by + simpa only [det_updateRow_trace] using hasDerivAt_det_update hQ + +lemma adjugate_eq_det_smul_inv (M : Matrix ι ι ℝ) (hM : IsUnit M) : + M.adjugate=M.det • M⁻¹ := by + have hd : M.det ≠ 0 := (Matrix.isUnit_iff_isUnit_det M).mp hM |>.ne_zero + rw [Matrix.inv_def,Ring.inverse_eq_inv,smul_smul,mul_inv_cancel₀ hd,one_smul] + +lemma hasDerivAt_det {Q : ℝ → Matrix ι ι ℝ} {Q' : Matrix ι ι ℝ} {t : ℝ} + (hQ : ∀ i k, HasDerivAt (fun x => Q x i k) (Q' i k) t) (hunit : IsUnit (Q t)) : + HasDerivAt (fun x => (Q x).det) ((Q t).det*(Q'*(Q t)⁻¹).trace) t := by + have h := hasDerivAt_det_adjugate hQ + rw [adjugate_eq_det_smul_inv _ hunit,Matrix.mul_smul,Matrix.trace_smul,smul_eq_mul] at h + exact h + +lemma hasDerivAt_logdet {Q : ℝ → Matrix ι ι ℝ} {Q' : Matrix ι ι ℝ} {t : ℝ} + (hQ : ∀ i k, HasDerivAt (fun x => Q x i k) (Q' i k) t) (hunit : IsUnit (Q t)) : + HasDerivAt (fun x => Real.log (Q x).det) (Q'*(Q t)⁻¹).trace t := by + have hd : (Q t).det ≠ 0 := (Matrix.isUnit_iff_isUnit_det _).mp hunit |>.ne_zero + have h := (hasDerivAt_det hQ hunit).log hd + convert h using 1 + field_simp +end SKGap.LogDet +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Matrix/MatrixQuad.lean b/lean/OAI/Probability/SKGap/Matrix/MatrixQuad.lean new file mode 100644 index 0000000000000000000000000000000000000000..ed82d9f1d5cd4d1283ca8d5b3b2d74fc9e387245 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Matrix/MatrixQuad.lean @@ -0,0 +1,259 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.DiagonalTMemLp + +namespace OAI + +section +noncomputable section +open MeasureTheory ProbabilityTheory InformationTheory Real Set +open scoped NNReal ENNReal +open Filter +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius ENNReal NNReal +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius NNReal +noncomputable section +open MeasureTheory ProbabilityTheory Real Set Filter +open MeasureTheory.Measure +open scoped ENNReal NNReal MeasureTheory Topology +open MeasureTheory +noncomputable section +noncomputable section +open MeasureTheory Set NormedSpace +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius +noncomputable section +open Set Real +open scoped Topology +noncomputable section +open Matrix Set Filter +open scoped Topology Matrix.Norms.Frobenius +noncomputable section +open Matrix NormedSpace ContinuousLinearMap +open scoped Matrix.Norms.Frobenius +noncomputable section +open Matrix +noncomputable section +open MeasureTheory ProbabilityTheory Real Set +open scoped ENNReal NNReal +noncomputable section +open MeasureTheory ProbabilityTheory InformationTheory Real Set +open scoped NNReal ENNReal +noncomputable section +open scoped BigOperators +open MeasureTheory ProbabilityTheory +open Real +noncomputable section +open scoped BigOperators Topology +open Filter Real +namespace SKGap +variable {ι : Type*} [Fintype ι] [DecidableEq ι] +def matrixQuad (M : Matrix ι ι ℝ) (p : EuclideanSpace ℝ ι) : ℝ := + ∑ i, ∑ k, p i * M i k * p k + +def matrixOperator (M : Matrix ι ι ℝ) : + EuclideanSpace ℝ ι →L[ℝ] EuclideanSpace ℝ ι := + M.toEuclideanLin.toContinuousLinearMap + +lemma matrixOperator_apply (M : Matrix ι ι ℝ) (p : EuclideanSpace ℝ ι) (i : ι) : + matrixOperator M p i = ∑ k, M i k * p k := by + rfl + +lemma matrixQuad_inner (M : Matrix ι ι ℝ) (p : EuclideanSpace ℝ ι) : + matrixQuad M p = inner ℝ p (matrixOperator M p) := by + simp only [PiLp.inner_apply, RCLike.inner_apply, conj_trivial, matrixOperator_apply, + matrixQuad, Finset.sum_mul] + apply Finset.sum_congr rfl + intro i _ + apply Finset.sum_congr rfl + intro k _ + ring + +omit [DecidableEq ι] in +lemma matrixQuad_smul (M : Matrix ι ι ℝ) (p : EuclideanSpace ℝ ι) (c : ℝ) : + matrixQuad M (c • p) = c^2 * matrixQuad M p := by + simp only [matrixQuad, PiLp.smul_apply, smul_eq_mul, Finset.mul_sum] + apply Finset.sum_congr rfl + intro i _ + apply Finset.sum_congr rfl + intro k _ + ring + +omit [Fintype ι] [DecidableEq ι] in +lemma goeMatrix_symm (r : ℝ) (g : MatrixCoordinates ι → ℝ) : + (goeMatrix r g).IsHermitian := by + ext i k + simp [goeMatrix, add_comm] + +omit [Fintype ι] [DecidableEq ι] in +lemma goeMatrix_neg (r : ℝ) (g : MatrixCoordinates ι → ℝ) : + goeMatrix r (-g) = -goeMatrix r g := by + ext i k + simp only [goeMatrix, Pi.neg_apply, Matrix.neg_apply] + ring + +omit [DecidableEq ι] in +lemma goeMatrix_quad (r : ℝ) (g : MatrixCoordinates ι → ℝ) (p : EuclideanSpace ℝ ι) : + matrixQuad (goeMatrix r g) p = + ∑ i, ∑ k, sqrt (2*r) * p i * p k * g (.inl (i,k)) := by + have hs : (∑ i, ∑ k, p i * g (.inl (k,i)) * p k) = + ∑ i, ∑ k, p i * g (.inl (i,k)) * p k := by + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro i _ + apply Finset.sum_congr rfl + intro k _ + ring + calc + _ = sqrt (2*r)/2 * ((∑ i, ∑ k, p i * g (.inl (i,k)) * p k) + + ∑ i, ∑ k, p i * g (.inl (k,i)) * p k) := by + simp only [matrixQuad, goeMatrix, Finset.mul_sum, ← Finset.sum_add_distrib] + apply Finset.sum_congr rfl + intro i _ + apply Finset.sum_congr rfl + intro k _ + ring + _ = _ := by + rw [hs] + simp only [Finset.mul_sum, ← Finset.sum_add_distrib] + apply Finset.sum_congr rfl + intro i _ + apply Finset.sum_congr rfl + intro k _ + ring + +lemma matrixOperator_norm_le_of_quad {M : Matrix ι ι ℝ} (hM : M.IsHermitian) + {R : ℝ} (hR : 0 ≤ R) + (hq : ∀ p : EuclideanSpace ℝ ι, ‖p‖ ≤ 1 → |matrixQuad M p| ≤ R) : + ‖matrixOperator M‖ ≤ R := by + have hs : (matrixOperator M).IsSymmetric := Matrix.isSymmetric_toEuclideanLin_iff.mpr hM + rw [ContinuousLinearMap.norm_eq_iSup_rayleighQuotient (T := matrixOperator M) hs] + apply ciSup_le + intro p + by_cases hp : p = 0 + · simp [hp, ContinuousLinearMap.rayleighQuotient, hR] + have hp0 : 0 < ‖p‖ := norm_pos_iff.mpr hp + have hunit : ‖‖p‖⁻¹ • p‖ ≤ 1 := by + rw [norm_smul, Real.norm_eq_abs, abs_inv, abs_of_pos hp0, inv_mul_cancel₀ hp0.ne'] + have hh := hq (‖p‖⁻¹ • p) hunit + rw [matrixQuad_smul, abs_mul, abs_pow, abs_inv, abs_of_pos hp0] at hh + simpa only [ContinuousLinearMap.rayleighQuotient, ContinuousLinearMap.reApplyInnerSelf_apply, + RCLike.re_to_real, real_inner_comm, ← matrixQuad_inner, abs_div, + abs_pow, abs_of_pos hp0, inv_pow, div_eq_mul_inv, mul_comm, abs_mul, abs_inv] using hh + +end SKGap + +namespace SKGap +section GOEEvents +variable {ι : Type*} [Fintype ι] [DecidableEq ι] [Nonempty ι] + +omit [DecidableEq ι] [Nonempty ι] in +lemma goeMatrix_quad_coeff (r : ℝ) (g : MatrixCoordinates ι → ℝ) + (p : EuclideanSpace ℝ ι) : + matrixQuad (goeMatrix r g) p = ∑ k, quadraticCoeff r p k * g k := by + rw [goeMatrix_quad, Fintype.sum_sum_type] + simp only [quadraticCoeff, zero_mul, Finset.sum_const_zero, add_zero, + Fintype.sum_prod_type] + +omit [DecidableEq ι] [Nonempty ι] in +lemma diagonal_affine_matrix (r z q : ℝ) (a : ι → ℝ) + (g : MatrixCoordinates ι → ℝ) (p : UnitBall ι) : + gaussianAffine (diagonalOffset a z q) + (fun p k => z * quadraticCoeff r (diagonalSqrt a p) k) g p = + z * matrixQuad (goeMatrix r g) (diagonalSqrt a p) - + z^2*q*‖diagonalSqrt a p‖^2 := by + rw [goeMatrix_quad_coeff] + simp only [gaussianAffine, diagonalOffset, Finset.mul_sum] + simp_rw [mul_assoc] + ring + +omit [Fintype ι] [DecidableEq ι] [Nonempty ι] in +lemma diagonalSqrt_one (p : EuclideanSpace ℝ ι) : + diagonalSqrt (fun _ : ι => 1) p = p := by + ext i + simp [diagonalSqrt] + +omit [DecidableEq ι] [Nonempty ι] in +lemma goe_quad_le_top (r : ℝ) (g : MatrixCoordinates ι → ℝ) + (p : EuclideanSpace ℝ ι) (hp : ‖p‖ ≤ 1) : + matrixQuad (goeMatrix r g) p ≤ diagonalProcess r (fun _ : ι => 1) 1 0 g := by + let p' : UnitBall ι := ⟨p, by simpa only [Metric.mem_closedBall, dist_zero_right] using hp⟩ + have h := gaussianAffine_le_gaussianSup (continuous_diagonalOffset (fun _ : ι => 1) 1 0) + (continuous_diagonalCoeff (continuous_quadraticCoeff r) (fun _ : ι => 1) 1) g p' + rw [diagonal_affine_matrix, diagonalSqrt_one] at h + simpa only [one_mul, mul_zero, zero_mul, sub_zero, diagonalProcess, p'] using h + +omit [DecidableEq ι] [Nonempty ι] in +lemma matrixQuad_neg (M : Matrix ι ι ℝ) (p : EuclideanSpace ℝ ι) : + matrixQuad (-M) p = -matrixQuad M p := by + simp [matrixQuad, Finset.sum_neg_distrib] + +omit [Nonempty ι] in +lemma goe_norm_le_of_top {r R : ℝ} (hR : 0 ≤ R) (g : MatrixCoordinates ι → ℝ) + (hpos : diagonalProcess r (fun _ : ι => 1) 1 0 g ≤ R) + (hneg : diagonalProcess r (fun _ : ι => 1) 1 0 (-g) ≤ R) : + ‖matrixOperator (goeMatrix r g)‖ ≤ R := by + apply matrixOperator_norm_le_of_quad (goeMatrix_symm r g) hR + intro p hp + apply abs_le.mpr + constructor + · have h := (goe_quad_le_top r (-g) p hp).trans hneg + rw [goeMatrix_neg, matrixQuad_neg] at h + linarith + · exact (goe_quad_le_top r g p hp).trans hpos + +theorem goe_norm_tail {j ε : ℝ} (hj : 0 < j) (hε : 0 ≤ ε) : + (gaussianCoordinates (MatrixCoordinates ι)).real + {g | 2*sqrt j+ε < ‖matrixOperator (goeMatrix (j/(Fintype.card ι:ℝ)) g)‖} ≤ + 2*Real.exp (-ε^2*(Fintype.card ι:ℝ)/(π^2*j)) := by + let r := j/(Fintype.card ι:ℝ) + let R := 2*sqrt j+ε + let P := diagonalProcess r (fun _ : ι => 1) 1 0 + let E : Set (MatrixCoordinates ι → ℝ) := {g | R < P g} + have hc : Continuous P := continuous_gaussianSup + (continuous_diagonalOffset (fun _ : ι => 1) 1 0) + (continuous_diagonalCoeff (continuous_quadraticCoeff r) (fun _ : ι => 1) 1) + have hm : MeasurableSet E := measurableSet_lt measurable_const hc.measurable + have hp := goe_top_tail (ι := ι) hj hε + have hn : (gaussianCoordinates (MatrixCoordinates ι)).real {g | R < P (-g)} = + (gaussianCoordinates (MatrixCoordinates ι)).real E := by + exact congrArg ENNReal.toReal (gaussianCoordinates_preserving_neg.measure_preimage hm.nullMeasurableSet) + have hs : {g : MatrixCoordinates ι → ℝ | R < ‖matrixOperator (goeMatrix r g)‖} ⊆ E ∪ {g | R < P (-g)} := by + intro g hg + by_contra hh + have hh' : ¬ R < P g ∧ ¬ R < P (-g) := by simpa only [Set.mem_union, E, Set.mem_ofPred_eq, not_or] using hh + exact (not_lt_of_ge (goe_norm_le_of_top (by dsimp [R]; positivity) g + (le_of_not_gt hh'.1) (le_of_not_gt hh'.2))) hg + calc + _ ≤ (gaussianCoordinates (MatrixCoordinates ι)).real (E ∪ {g | R < P (-g)}) := measureReal_mono hs + _ ≤ (gaussianCoordinates (MatrixCoordinates ι)).real E + + (gaussianCoordinates (MatrixCoordinates ι)).real {g | R < P (-g)} := measureReal_union_le _ _ + _ = 2*(gaussianCoordinates (MatrixCoordinates ι)).real E := by rw [hn]; ring + _ ≤ _ := mul_le_mul_of_nonneg_left hp (by norm_num) + +end GOEEvents +end SKGap + +end +end +end +end +end +end +end +end +end +end +end +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Matrix/MatrixSeminorm.lean b/lean/OAI/Probability/SKGap/Matrix/MatrixSeminorm.lean new file mode 100644 index 0000000000000000000000000000000000000000..e7b4e90bc8296bb28896e454dffc7f7d0f7cdd4a --- /dev/null +++ b/lean/OAI/Probability/SKGap/Matrix/MatrixSeminorm.lean @@ -0,0 +1,106 @@ +import Mathlib +import OAI.Probability.SKGap.Matrix.MatrixEntryCLM + +namespace OAI + +section +noncomputable section +namespace SKGap +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius +variable {ι : Type*} [Fintype ι] [DecidableEq ι] + +local instance : Fact (1≤(4:ENNReal)) := ⟨by norm_num⟩ +def offDiagonalVector (M : Matrix ι ι ℝ) : PiLp 4 (fun _ : ι×ι=>ℝ) := + WithLp.toLp 4 (fun p=>if p.1=p.2 then 0 else M p.1 p.2) +def diagonalSeminorm (M : Matrix ι ι ℝ) : ℝ := ‖diagonalVector M‖ +def offDiagonalSeminorm (M : Matrix ι ι ℝ) : ℝ := ‖offDiagonalVector M‖ + +omit [DecidableEq ι] in +lemma diagonalSeminorm_sq (M : Matrix ι ι ℝ) : diagonalSeminorm M^2=∑ i,(M i i)^2 := by + simp only [diagonalSeminorm,EuclideanSpace.norm_sq_eq,diagonalVector,Real.norm_eq_abs,sq_abs] + +lemma offDiagonalSeminorm_fourth (M : Matrix ι ι ℝ) : + offDiagonalSeminorm M^4=∑ p : ι×ι,if p.1=p.2 then 0 else (M p.1 p.2)^4 := by + rw [offDiagonalSeminorm,PiLp.norm_eq_of_nat (p:=4) 4 (by norm_num)] + rw [←Real.rpow_natCast,←Real.rpow_mul (Finset.sum_nonneg (fun _ _=>pow_nonneg (norm_nonneg _) _))] + norm_num only [Nat.cast_ofNat,one_div,mul_inv_cancel₀ (by norm_num : (4:ℝ)≠0),Real.rpow_one] + apply Finset.sum_congr rfl + intro p _ + simp only [offDiagonalVector,WithLp.ofLp_toLp] + split_ifs + · simp + · rw [Real.norm_eq_abs] + calc + |M p.1 p.2|^4=(|M p.1 p.2|^2)^2 := by ring + _ = ((M p.1 p.2)^2)^2 := by rw [sq_abs] + _ = (M p.1 p.2)^4 := by ring + +lemma diagonalSeminorm_le (M : Matrix ι ι ℝ) : diagonalSeminorm M≤‖M‖ := by + apply le_of_pow_le_pow_left₀ (by decide : 2≠0) (norm_nonneg _) + rw [diagonalSeminorm_sq,frobenius_sq] + exact Finset.sum_le_sum (fun i _=>Finset.single_le_sum (fun k _=>sq_nonneg (M i k)) (Finset.mem_univ i)) + +lemma offDiagonalSeminorm_le (M : Matrix ι ι ℝ) : offDiagonalSeminorm M≤‖M‖ := by + let a : ι×ι→ℝ := fun p=>if p.1=p.2 then 0 else (M p.1 p.2)^2 + have ha : ∀ p,0≤a p := by intro p;dsimp [a];split_ifs <;> positivity + have hs : (∑ p,a p)≤‖M‖^2 := by + rw [frobenius_sq] + rw [show (∑ i,∑ k,(M i k)^2) = ∑ p : ι×ι,(M p.1 p.2)^2 from (Fintype.sum_prod_type fun p : ι×ι=>(M p.1 p.2)^2).symm] + apply Finset.sum_le_sum + intro p _ + dsimp [a] + split_ifs + · exact sq_nonneg _ + · exact le_rfl + apply le_of_pow_le_pow_left₀ (by decide : 4≠0) (norm_nonneg _) + rw [offDiagonalSeminorm_fourth] + calc + _ = ∑ p,a p^2 := by + apply Finset.sum_congr rfl + intro p _ + dsimp [a] + split_ifs <;> ring + _ ≤ (∑ p,a p)^2 := Finset.sum_sq_le_sq_sum_of_nonneg (fun p _=>ha p) + _ ≤ (‖M‖^2)^2 := pow_le_pow_left₀ (Finset.sum_nonneg (fun p _=>ha p)) hs 2 + _ = ‖M‖^4 := by ring + +omit [Fintype ι] [DecidableEq ι] in +@[simp] lemma diagonalVector_sub (M N : Matrix ι ι ℝ) : diagonalVector (M-N)=diagonalVector M-diagonalVector N := by rfl +omit [Fintype ι] [DecidableEq ι] in +@[simp] lemma diagonalVector_add (M N : Matrix ι ι ℝ) : diagonalVector (M+N)=diagonalVector M+diagonalVector N := by rfl +omit [Fintype ι] in +@[simp] lemma offDiagonalVector_sub (M N : Matrix ι ι ℝ) : offDiagonalVector (M-N)=offDiagonalVector M-offDiagonalVector N := by + ext p + simp only [offDiagonalVector,WithLp.ofLp_toLp,PiLp.sub_apply] + split_ifs <;> simp +omit [Fintype ι] in +@[simp] lemma offDiagonalVector_add (M N : Matrix ι ι ℝ) : offDiagonalVector (M+N)=offDiagonalVector M+offDiagonalVector N := by + ext p + simp only [offDiagonalVector,WithLp.ofLp_toLp,PiLp.add_apply] + split_ifs <;> simp + +lemma diagonalSeminorm_lipschitz : LipschitzWith 1 (diagonalSeminorm (ι:=ι)) := by + apply LipschitzWith.of_dist_le_mul + intro M N + simpa only [NNReal.coe_one,one_mul,dist_eq_norm,Real.norm_eq_abs,diagonalSeminorm,←diagonalVector_sub] using! + (abs_norm_sub_norm_le (diagonalVector M) (diagonalVector N)).trans (diagonalSeminorm_le (M-N)) +lemma offDiagonalSeminorm_lipschitz : LipschitzWith 1 (offDiagonalSeminorm (ι:=ι)) := by + apply LipschitzWith.of_dist_le_mul + intro M N + have hh : ‖offDiagonalVector M-offDiagonalVector N‖≤‖M-N‖ := by + simpa only [←offDiagonalVector_sub,offDiagonalSeminorm] using! offDiagonalSeminorm_le (M-N) + simpa only [NNReal.coe_one,one_mul,dist_eq_norm,Real.norm_eq_abs,offDiagonalSeminorm] using! + (abs_norm_sub_norm_le (offDiagonalVector M) (offDiagonalVector N)).trans hh +omit [DecidableEq ι] in +lemma diagonalSeminorm_add (M N : Matrix ι ι ℝ) : + diagonalSeminorm (M+N)≤diagonalSeminorm M+diagonalSeminorm N := by + simpa only [diagonalSeminorm,diagonalVector_add] using norm_add_le (diagonalVector M) (diagonalVector N) +lemma offDiagonalSeminorm_add (M N : Matrix ι ι ℝ) : + offDiagonalSeminorm (M+N)≤offDiagonalSeminorm M+offDiagonalSeminorm N := by + simpa only [offDiagonalSeminorm,offDiagonalVector_add] using norm_add_le (offDiagonalVector M) (offDiagonalVector N) +end SKGap +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Matrix/MatrixWhitening.lean b/lean/OAI/Probability/SKGap/Matrix/MatrixWhitening.lean new file mode 100644 index 0000000000000000000000000000000000000000..6cdb826f3ed0ce123e2e4a6449c641c79e7bba07 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Matrix/MatrixWhitening.lean @@ -0,0 +1,61 @@ +import Mathlib +import OAI.Probability.SKGap.Model + +namespace OAI + +section +noncomputable section +namespace SKGap +open Matrix +open scoped MatrixOrder Matrix.Norms.Frobenius +variable {ι κ : Type*} [Fintype ι] [DecidableEq ι] [Fintype κ] + +omit [Fintype κ] in +lemma positive_sqrt_data {S : Matrix ι ι ℝ} (hS : S.PosDef) : + ∃ R : Matrix ι ι ℝ, R.IsHermitian ∧ R*R=S ∧ IsUnit R.det := by + let R := CFC.sqrt S + have hR : R.IsHermitian := (CFC.sqrt_nonneg S).posSemidef.isHermitian + have hsq : R*R=S := CFC.sqrt_mul_sqrt_self S hS.posSemidef.nonneg + have hu : IsUnit R := isUnit_of_mul_isUnit_left (hsq.symm ▸ hS.isUnit) + exact ⟨R,hR,hsq,(Matrix.isUnit_iff_isUnit_det R).mp hu⟩ + +omit [Fintype κ] in + +theorem positive_whitening_gram {S : Matrix ι ι ℝ} (hS : S.PosDef) + (D : Matrix ι ι ℝ) (hD : D.IsHermitian) (V : Matrix ι κ ℝ) : + ∃ R : Matrix ι ι ℝ, R.IsHermitian ∧ R*R=S ∧ IsUnit R.det ∧ + (R⁻¹*D*V)ᵀ*(R⁻¹*D*V)=Vᵀ*D*S⁻¹*D*V := by + obtain ⟨R,hR,hsq,hu⟩ := positive_sqrt_data hS + refine ⟨R,hR,hsq,hu,?_⟩ + have ht : Rᵀ=R := by simpa only [Matrix.conjTranspose_eq_transpose_of_trivial] using hR.eq + have htD : Dᵀ=D := by simpa only [Matrix.conjTranspose_eq_transpose_of_trivial] using hD.eq + have hi : R⁻¹*R⁻¹=S⁻¹ := by rw [← hsq,Matrix.mul_inv_rev] + simp only [Matrix.transpose_mul,Matrix.transpose_nonsing_inv,ht,htD,Matrix.mul_assoc] + rw [← Matrix.mul_assoc R⁻¹ R⁻¹,hi] + +theorem positive_unwhitening {S R D : Matrix ι ι ℝ} (hR : R.IsHermitian) + (hD : D.IsHermitian) (hRR : R*R=S) (hu : IsUnit R.det) + (V : Matrix ι κ ℝ) (C : Matrix κ κ ℝ) (δ : ℝ) + (hpos : ((1-δ) • (1 : Matrix ι ι ℝ)- + (R⁻¹*D*V)*C*(R⁻¹*D*V)ᵀ).PosDef) : + ((1-δ) • S-D*V*C*Vᵀ*D).PosDef := by + have ht : Rᵀ=R := by simpa only [Matrix.conjTranspose_eq_transpose_of_trivial] using hR.eq + have htD : Dᵀ=D := by simpa only [Matrix.conjTranspose_eq_transpose_of_trivial] using hD.eq + have hinj : Function.Injective R.mulVec := by + intro x y hxy + have h := congrArg (fun z => R⁻¹*ᵥz) hxy + simpa only [Matrix.mulVec_mulVec,Matrix.nonsing_inv_mul _ hu,Matrix.one_mulVec] using h + have hp := hpos.conjTranspose_mul_mul_same hinj + simp only [Matrix.conjTranspose_eq_transpose_of_trivial,ht,Matrix.mul_sub,Matrix.sub_mul, + Matrix.mul_smul,Matrix.smul_mul,Matrix.mul_one,hRR] at hp + convert hp using 1 + congr 1 + simp only [Matrix.transpose_mul,Matrix.transpose_nonsing_inv,ht,htD,Matrix.mul_assoc] + simp only [← Matrix.mul_assoc R R⁻¹,Matrix.mul_nonsing_inv _ hu,Matrix.one_mul] + simp only [← Matrix.mul_assoc,Matrix.nonsing_inv_mul_cancel_right _ _ hu] + +end SKGap +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Matrix/MatrixWordIncrement.lean b/lean/OAI/Probability/SKGap/Matrix/MatrixWordIncrement.lean new file mode 100644 index 0000000000000000000000000000000000000000..2bc952199cec88687c02044fe10c97803c8bd50c --- /dev/null +++ b/lean/OAI/Probability/SKGap/Matrix/MatrixWordIncrement.lean @@ -0,0 +1,130 @@ +import Mathlib +import OAI.Probability.SKGap.Matrix.MatrixWordRegularity + +namespace OAI + +section +noncomputable section +namespace SKGap +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius +variable {ι X : Type*} [Fintype ι] [DecidableEq ι] [PseudoMetricSpace X] + +omit [PseudoMetricSpace X] in +lemma word_opNorm_add (M N : Matrix ι ι ℝ) : opNorm (M+N) ≤ opNorm M+opNorm N := by + unfold opNorm + rw [map_add,map_add] + exact norm_add_le _ _ + +omit [PseudoMetricSpace X] in +lemma real_product_four_point (a b c d e f g h : Matrix ι ι ℝ) : + ‖(a*e-b*f)-(c*g-d*h)‖ ≤ + ‖(a-b)-(c-d)‖*opNorm e+‖c-d‖*opNorm (e-g)+ + opNorm (b-d)*‖e-f‖+opNorm d*‖(e-f)-(g-h)‖ := by + have he : (a*e-b*f)-(c*g-d*h)= + ((a-b)-(c-d))*e+(c-d)*(e-g)+(b-d)*(e-f)+d*((e-f)-(g-h)) := by noncomm_ring + rw [he] + calc + _ ≤ ‖((a-b)-(c-d))*e+(c-d)*(e-g)+(b-d)*(e-f)‖+‖d*((e-f)-(g-h))‖ := norm_add_le _ _ + _ ≤ (‖((a-b)-(c-d))*e+(c-d)*(e-g)‖+‖(b-d)*(e-f)‖)+‖d*((e-f)-(g-h))‖ := by gcongr;exact norm_add_le _ _ + _ ≤ ((‖((a-b)-(c-d))*e‖+‖(c-d)*(e-g)‖)+‖(b-d)*(e-f)‖)+‖d*((e-f)-(g-h))‖ := by gcongr;exact norm_add_le _ _ + _ ≤ _ := by + gcongr + · exact frobenius_mul_le_opNorm_right _ _ + · exact frobenius_mul_le_opNorm_right _ _ + · exact frobenius_mul_le_opNorm _ _ + · exact frobenius_mul_le_opNorm _ _ + +structure MatrixFactorPairBounds (B Δ : NNReal) (f g : X→Matrix ι ι ℝ) : Prop where + leftBound : ∀ x,opNorm (f x)≤B + rightBound : ∀ x,opNorm (g x)≤B + leftLip : LipschitzWith B f + rightLip : LipschitzWith B g + parameter : ∀ x,opNorm (f x-g x)≤Δ + increment : LipschitzWith Δ (fun x=>f x-g x) + +def wordParameterCoeff (B : NNReal) : ℕ→NNReal + | 0 => 0 + | r+1 => B^r+B*wordParameterCoeff B r + +def wordMixedCoeff (B : NNReal) : ℕ→NNReal + | 0 => 0 + | r+1 => B^r+B*wordParameterCoeff B r+(r:NNReal)*B^r+B*wordMixedCoeff B r + +theorem matrixWord_pair_increments (F : List ((X→Matrix ι ι ℝ)×(X→Matrix ι ι ℝ))) + {B Δ : NNReal} (hF : ∀ p∈F,MatrixFactorPairBounds B Δ p.1 p.2) : + (∀ x,opNorm (matrixFactorProduct (F.map Prod.fst) x-matrixFactorProduct (F.map Prod.snd) x)≤ + (wordParameterCoeff B F.length:ℝ)*Δ) ∧ + LipschitzWith (wordMixedCoeff B F.length*Δ) + (fun x=>matrixFactorProduct (F.map Prod.fst) x-matrixFactorProduct (F.map Prod.snd) x) := by + induction F with + | nil => + constructor + · intro x;simp [matrixFactorProduct,wordParameterCoeff,opNorm] + · simp [matrixFactorProduct,wordMixedCoeff] + | cons p F ih => + have hp := hF p List.mem_cons_self + have hFt : ∀ q∈F,MatrixFactorPairBounds B Δ q.1 q.2 := fun q hq=>hF q (List.mem_cons_of_mem p hq) + have ht := ih hFt + have hbL : ∀ f∈F.map Prod.fst,∀ x,opNorm (f x)≤B := by + intro f hf;obtain ⟨q,hq,rfl⟩ := List.mem_map.mp hf;exact (hFt q hq).leftBound + have hlL : ∀ f∈F.map Prod.fst,LipschitzWith B f := by + intro f hf;obtain ⟨q,hq,rfl⟩ := List.mem_map.mp hf;exact (hFt q hq).leftLip + have htl := matrixFactorProduct_lipschitz (F.map Prod.fst) hbL hlL + constructor + · intro x + simp only [List.map_cons,matrixFactorProduct_cons,List.length_cons,wordParameterCoeff,NNReal.coe_add,NNReal.coe_mul,NNReal.coe_pow] + have he : p.1 x*matrixFactorProduct (F.map Prod.fst) x-p.2 x*matrixFactorProduct (F.map Prod.snd) x= + (p.1 x-p.2 x)*matrixFactorProduct (F.map Prod.fst) x+ + p.2 x*(matrixFactorProduct (F.map Prod.fst) x-matrixFactorProduct (F.map Prod.snd) x) := by noncomm_ring + rw [he] + apply (word_opNorm_add _ _).trans + apply (add_le_add (opNorm_mul _ _) (opNorm_mul _ _)).trans + have h1 := mul_le_mul (hp.parameter x) (matrixFactorProduct_opNorm (F.map Prod.fst) hbL x) + (show 0≤opNorm (matrixFactorProduct (F.map Prod.fst) x) from norm_nonneg _) Δ.coe_nonneg + have h2 := mul_le_mul (hp.rightBound x) (ht.1 x) (show 0≤opNorm + (matrixFactorProduct (F.map Prod.fst) x-matrixFactorProduct (F.map Prod.snd) x) from norm_nonneg _) B.coe_nonneg + apply (add_le_add h1 h2).trans_eq + simp only [List.length_map] + ring + · apply LipschitzWith.of_dist_le_mul + intro x y + simp only [dist_eq_norm,List.map_cons,matrixFactorProduct_cons] + have he : (p.1 x*matrixFactorProduct (F.map Prod.fst) x-p.2 x*matrixFactorProduct (F.map Prod.snd) x)- + (p.1 y*matrixFactorProduct (F.map Prod.fst) y-p.2 y*matrixFactorProduct (F.map Prod.snd) y)= + (p.1 x*matrixFactorProduct (F.map Prod.fst) x-p.1 y*matrixFactorProduct (F.map Prod.fst) y)- + (p.2 x*matrixFactorProduct (F.map Prod.snd) x-p.2 y*matrixFactorProduct (F.map Prod.snd) y) := by abel + rw [he] + apply (real_product_four_point _ _ _ _ _ _ _ _).trans + have hi : ‖(p.1 x-p.1 y)-(p.2 x-p.2 y)‖≤(Δ:ℝ)*dist x y := by + have hh := hp.increment.dist_le_mul x y + rw [dist_eq_norm] at hh + convert! hh using 1 + congr 1;abel + have hr : ‖p.2 x-p.2 y‖≤(B:ℝ)*dist x y := by simpa only [dist_eq_norm] using hp.rightLip.dist_le_mul x y + have hli : ‖matrixFactorProduct (F.map Prod.fst) x-matrixFactorProduct (F.map Prod.fst) y‖≤ + ((F.length:ℝ)*(B:ℝ)^F.length)*dist x y := by + simpa only [dist_eq_norm,List.length_map,NNReal.coe_mul,NNReal.coe_natCast,NNReal.coe_pow] using htl.dist_le_mul x y + have hm : ‖(matrixFactorProduct (F.map Prod.fst) x-matrixFactorProduct (F.map Prod.fst) y)- + (matrixFactorProduct (F.map Prod.snd) x-matrixFactorProduct (F.map Prod.snd) y)‖≤ + ((wordMixedCoeff B F.length:ℝ)*Δ)*dist x y := by + have hh := ht.2.dist_le_mul x y + rw [dist_eq_norm] at hh + convert! hh using 1 + congr 1;abel + have h1 := mul_le_mul hi (matrixFactorProduct_opNorm (F.map Prod.fst) hbL x) + (show 0≤opNorm (matrixFactorProduct (F.map Prod.fst) x) from norm_nonneg _) (mul_nonneg Δ.coe_nonneg dist_nonneg) + have h2 := mul_le_mul hr (ht.1 x) (show 0≤opNorm + (matrixFactorProduct (F.map Prod.fst) x-matrixFactorProduct (F.map Prod.snd) x) from norm_nonneg _) + (mul_nonneg B.coe_nonneg dist_nonneg) + have h3 := mul_le_mul (hp.parameter y) hli (norm_nonneg _) Δ.coe_nonneg + have h4 := mul_le_mul (hp.rightBound y) hm (norm_nonneg _) B.coe_nonneg + apply (add_le_add (add_le_add (add_le_add h1 h2) h3) h4).trans_eq + simp only [List.length_map,List.length_cons,wordMixedCoeff,NNReal.coe_add,NNReal.coe_mul, + NNReal.coe_natCast,NNReal.coe_pow] + ring +end SKGap +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Matrix/MatrixWordRegularity.lean b/lean/OAI/Probability/SKGap/Matrix/MatrixWordRegularity.lean new file mode 100644 index 0000000000000000000000000000000000000000..345dbf1008a766769dee6cb56b141830a215cc29 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Matrix/MatrixWordRegularity.lean @@ -0,0 +1,115 @@ +import Mathlib +import OAI.Probability.SKGap.Matrix.MatrixEntryCLM +import OAI.Probability.SKGap.Matrix.OpNormDiagonal + +namespace OAI + +section +noncomputable section +namespace SKGap +open Real Matrix MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix.Norms.Frobenius +variable {ι X : Type*} [Fintype ι] [DecidableEq ι] [PseudoMetricSpace X] + +def matrixFactorProduct (F : List (X→Matrix ι ι ℝ)) (x : X) : Matrix ι ι ℝ := + (F.map (fun f=>f x)).prod + +omit [PseudoMetricSpace X] in +@[simp] lemma matrixFactorProduct_nil (x : X) : matrixFactorProduct ([] : List (X→Matrix ι ι ℝ)) x=1 := rfl +omit [PseudoMetricSpace X] in +@[simp] lemma matrixFactorProduct_cons (f : X→Matrix ι ι ℝ) (F : List (X→Matrix ι ι ℝ)) (x : X) : + matrixFactorProduct (f::F) x=f x*matrixFactorProduct F x := rfl + +omit [PseudoMetricSpace X] in +lemma matrixFactorProduct_opNorm (F : List (X→Matrix ι ι ℝ)) {R : NNReal} + (hF : ∀ f∈F,∀ x,opNorm (f x) ≤ R) (x : X) : + opNorm (matrixFactorProduct F x) ≤ (R:ℝ)^F.length := by + induction F with + | nil => simpa using opNorm_one_le (ι:=ι) + | cons f F ih => + rw [matrixFactorProduct_cons,List.length_cons,pow_succ'] + exact (opNorm_mul _ _).trans (mul_le_mul (hF f (List.mem_cons_self) x) + (ih (fun p hp=>hF p (List.mem_cons_of_mem f hp))) (show 0 ≤ opNorm (matrixFactorProduct F x) from norm_nonneg _) R.coe_nonneg) + +theorem matrixFactorProduct_lipschitz (F : List (X→Matrix ι ι ℝ)) {R : NNReal} + (hF : ∀ f∈F,∀ x,opNorm (f x) ≤ R) + (hL : ∀ f∈F,LipschitzWith R f) : + LipschitzWith ((F.length:NNReal)*R^F.length) (matrixFactorProduct F) := by + induction F with + | nil => simp [matrixFactorProduct] + | cons f F ih => + have hFt : ∀ p∈F,∀ x,opNorm (p x) ≤ R := fun p hp=>hF p (List.mem_cons_of_mem f hp) + have hLt : ∀ p∈F,LipschitzWith R p := fun p hp=>hL p (List.mem_cons_of_mem f hp) + have ht := ih hFt hLt + apply LipschitzWith.of_dist_le_mul + intro x y + rw [dist_eq_norm,matrixFactorProduct_cons,matrixFactorProduct_cons] + have he : f x*matrixFactorProduct F x-f y*matrixFactorProduct F y= + f x*(matrixFactorProduct F x-matrixFactorProduct F y)+(f x-f y)*matrixFactorProduct F y := by noncomm_ring + rw [he] + apply (norm_add_le _ _).trans + apply (add_le_add (frobenius_mul_le_opNorm _ _) (frobenius_mul_le_opNorm_right _ _)).trans + have hd : ‖matrixFactorProduct F x-matrixFactorProduct F y‖ ≤ ((F.length:ℝ)*(R:ℝ)^F.length)*dist x y := by + simpa only [dist_eq_norm,NNReal.coe_mul,NNReal.coe_natCast,NNReal.coe_pow] using ht.dist_le_mul x y + have hf : ‖f x-f y‖ ≤ (R:ℝ)*dist x y := by + simpa only [dist_eq_norm] using (hL f List.mem_cons_self).dist_le_mul x y + have hb := matrixFactorProduct_opNorm F hFt y + have hp := hF f List.mem_cons_self x + have h1 := mul_le_mul hp hd (norm_nonneg _) R.coe_nonneg + have h2 := mul_le_mul hf hb (show 0 ≤ opNorm (matrixFactorProduct F y) from norm_nonneg _) (mul_nonneg R.coe_nonneg dist_nonneg) + apply (add_le_add h1 h2).trans_eq + norm_num only [NNReal.coe_mul,NNReal.coe_natCast,NNReal.coe_pow,List.length_cons,Nat.cast_add,Nat.cast_one,NNReal.coe_add,NNReal.coe_one,pow_succ] + ring + +lemma matrixFactorProduct_entry_lipschitz (F : List (X→Matrix ι ι ℝ)) {R : NNReal} + (hF : ∀ f∈F,∀ x,opNorm (f x) ≤ R) (hL : ∀ f∈F,LipschitzWith R f) (i k : ι) : + LipschitzWith ((F.length:NNReal)*R^F.length) (fun x=>matrixFactorProduct F x i k) := by + simpa only [one_mul,Function.comp_def] using (matrixEntry_lipschitz i k).comp (matrixFactorProduct_lipschitz F hF hL) + +lemma matrixFactorProduct_trace_lipschitz (F : List (X→Matrix ι ι ℝ)) {R : NNReal} + (hF : ∀ f∈F,∀ x,opNorm (f x) ≤ R) (hL : ∀ f∈F,LipschitzWith R f) : + LipschitzWith (⟨sqrt (Fintype.card ι),sqrt_nonneg _⟩*((F.length:NNReal)*R^F.length)) + (fun x=>trace (matrixFactorProduct F x)) := by + apply LipschitzWith.of_dist_le_mul + intro x y + have hh := (matrixFactorProduct_lipschitz F hF hL).dist_le_mul x y + have ht := abs_trace_le_frobenius (matrixFactorProduct F x-matrixFactorProduct F y) + rw [trace_sub] at ht + have hm := mul_le_mul_of_nonneg_left hh (sqrt_nonneg (Fintype.card ι:ℝ)) + change |trace (matrixFactorProduct F x)-trace (matrixFactorProduct F y)| ≤ + (sqrt (Fintype.card ι)*((F.length:ℝ)*(R:ℝ)^F.length))*dist x y + simpa only [dist_eq_norm,NNReal.coe_mul,NNReal.coe_natCast,NNReal.coe_pow,mul_assoc] using ht.trans hm + +lemma goe_word_entry_lipschitz (F : List (Matrix ι ι ℝ→Matrix ι ι ℝ)) {R : NNReal} + (hF : ∀ f∈F,∀ M,opNorm (f M) ≤ R) (hL : ∀ f∈F,LipschitzWith R f) + (r : ℝ) (i k : ι) : + LipschitzWith (((F.length:NNReal)*R^F.length)*⟨sqrt (2*r),sqrt_nonneg _⟩) + (fun z : EuclideanSpace ℝ (MatrixCoordinates ι)=>matrixFactorProduct F (goeMatrix r z) i k) := + (matrixFactorProduct_entry_lipschitz F hF hL i k).comp (goeMatrix_L2_lipschitz r) + +lemma goe_word_normalized_trace_lipschitz (F : List (Matrix ι ι ℝ→Matrix ι ι ℝ)) {R : NNReal} + (hF : ∀ f∈F,∀ M,opNorm (f M) ≤ R) (hL : ∀ f∈F,LipschitzWith R f) (r : ℝ) : + LipschitzWith (⟨(Fintype.card ι:ℝ)⁻¹,inv_nonneg.mpr (Nat.cast_nonneg _)⟩* + (⟨sqrt (Fintype.card ι),sqrt_nonneg _⟩*((F.length:NNReal)*R^F.length))*⟨sqrt (2*r),sqrt_nonneg _⟩) + (fun z : EuclideanSpace ℝ (MatrixCoordinates ι)=>trace (matrixFactorProduct F (goeMatrix r z))/(Fintype.card ι:ℝ)) := by + apply LipschitzWith.of_dist_le_mul + intro z w + have hg := (goeMatrix_L2_lipschitz (ι:=ι) r).dist_le_mul z w + have ht := (matrixFactorProduct_trace_lipschitz F hF hL).dist_le_mul (goeMatrix r z) (goeMatrix r w) + change dist (goeMatrix r z) (goeMatrix r w) ≤ sqrt (2*r)*dist z w at hg + change dist (trace (matrixFactorProduct F (goeMatrix r z))) (trace (matrixFactorProduct F (goeMatrix r w))) ≤ + (sqrt (Fintype.card ι)*((F.length:ℝ)*(R:ℝ)^F.length))*dist (goeMatrix r z) (goeMatrix r w) at ht + have hc : 0 ≤ sqrt (Fintype.card ι)*((F.length:ℝ)*(R:ℝ)^F.length) := by positivity + have hi : 0 ≤ (Fintype.card ι:ℝ)⁻¹ := inv_nonneg.mpr (Nat.cast_nonneg _) + have hb := mul_le_mul_of_nonneg_left (ht.trans (mul_le_mul_of_nonneg_left hg hc)) hi + change dist (trace (matrixFactorProduct F (goeMatrix r z))/(Fintype.card ι:ℝ)) + (trace (matrixFactorProduct F (goeMatrix r w))/(Fintype.card ι:ℝ)) ≤ + ((Fintype.card ι:ℝ)⁻¹*(sqrt (Fintype.card ι)*((F.length:ℝ)*(R:ℝ)^F.length))*sqrt (2*r))*dist z w + rw [Real.dist_eq,← sub_div,abs_div] + simp only [abs_of_nonneg (show (0:ℝ) ≤ (Fintype.card ι:ℝ) by positivity)] + simpa only [Real.dist_eq,div_eq_mul_inv,mul_assoc,mul_comm (Fintype.card ι:ℝ)⁻¹] using hb +end SKGap +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Matrix/MeasurableCompletedMatrix.lean b/lean/OAI/Probability/SKGap/Matrix/MeasurableCompletedMatrix.lean new file mode 100644 index 0000000000000000000000000000000000000000..31415eff7ebb1d14057af85015067249f4e62b44 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Matrix/MeasurableCompletedMatrix.lean @@ -0,0 +1,200 @@ +import Mathlib +import OAI.Probability.SKGap.Matrix.CompletedMatrix + +namespace OAI + +section +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open scoped BigOperators +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open scoped BigOperators +open scoped BigOperators NNReal ENNReal +open MeasureTheory Metric Set +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators NNReal ENNReal Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Set +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators ENNReal NNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Matrix +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators ENNReal NNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal +open scoped BigOperators +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise NNReal ENNReal +open scoped BigOperators +open Filter Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal Topology +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +namespace SKGapCutoff.Regression + +local instance completedMatrixMeasurableSpace {n m : ℕ} : + MeasurableSpace (Matrix (Fin n) (Fin m) ℝ) := + inferInstanceAs (MeasurableSpace (Fin n → Fin m → ℝ)) + +@[fun_prop] lemma measurable_completedMatrix {n r : ℕ} : + Measurable (fun z : (Matrix (Fin n) (Fin r) ℝ × Matrix (Fin n) (Fin r) ℝ) × + ((Fin n × Fin n) → ℝ) => completedMatrix z.1.1 z.1.2 z.2) := by + apply Measurable.of_eval + intro i + apply Measurable.of_eval + intro j + simp only [completedMatrix,revealedCompletion,residualProjection,goe, + Matrix.add_apply,Matrix.sub_apply,Matrix.mul_apply,Matrix.transpose_apply] + fun_prop + +@[fun_prop] lemma measurable_revealedCompletion_comp {n r : ℕ} {H : Type*} + [MeasurableSpace H] (U Y : H → Matrix (Fin n) (Fin r) ℝ) + (hU : Measurable U) (hY : Measurable Y) : + Measurable (fun h => revealedCompletion (U h) (Y h)) := by + have hU' : Measurable (fun h i j => U h i j) := hU + have hY' : Measurable (fun h i j => Y h i j) := hY + apply Measurable.of_eval + intro i + apply Measurable.of_eval + intro j + simp only [revealedCompletion,Matrix.add_apply,Matrix.sub_apply, + Matrix.mul_apply,Matrix.transpose_apply] + fun_prop + +theorem completedMatrix_section_law {n r : ℕ} (hn : 0 < n) + (U Y : Matrix (Fin n) (Fin r) ℝ) (q : Fin n → ℝ) + (hU : Uᵀ*U=1) (hY : Uᵀ*Y=Yᵀ*U) + (hq : ∑ i, q i^2=1) (ho : Uᵀ *ᵥ q=0) : + let p := U *ᵥ (Yᵀ *ᵥ q) + (standardArrayLaw (Fin n × Fin n)).map + (fun g => (completedMatrix U Y g *ᵥ q,completedMatrix U Y g)) = + ((standardArrayLaw (Fin n × Fin n)).prod (standardArrayLaw (Fin n ⊕ Unit))).map + (fun z => (p+queryInnovation (residualProjection U) q z.2, + completedMatrix (extendFrame U q) + (extendFrame Y (p+queryInnovation (residualProjection U) q z.2)) z.1)) := by + dsimp only + let P := residualProjection U + let p := U *ᵥ (Yᵀ *ᵥ q) + have hPq : P *ᵥ q=q := by + simp only [P,residualProjection,Matrix.sub_mulVec,Matrix.one_mulVec, + ← Matrix.mulVec_mulVec,ho,Matrix.mulVec_zero,sub_zero] + have hqc : P*queryColumn q=queryColumn q := by + ext i a + fin_cases a + exact congrFun hPq i + have hj := query_joint_law hn P (residualProjection_symmetric U) + (residualProjection_idem U hU) q hq hqc + let out : ((Fin n × Fin n) → ℝ) × (Fin n → ℝ) → + (Fin n → ℝ) × Matrix (Fin n) (Fin n) ℝ := fun z => + (p+z.2,revealedCompletion (extendFrame U q) (extendFrame Y (p+z.2))+ + Matrix.of (fun i j => z.1 (i,j))) + have ha : Measurable (fun z : ((Fin n × Fin n) → ℝ) × (Fin n → ℝ) => p+z.2) := + measurable_const.add measurable_snd + have hy : Measurable (fun z : ((Fin n × Fin n) → ℝ) × (Fin n → ℝ) => + extendFrame Y (p+z.2)) := measurable_extendFrame.comp (measurable_const.prodMk ha) + have hc : Measurable (fun z : ((Fin n × Fin n) → ℝ) × (Fin n → ℝ) => + revealedCompletion (extendFrame U q) (extendFrame Y (p+z.2))) := + measurable_revealedCompletion_comp _ _ measurable_const hy + have hout : Measurable out := by + apply ha.prodMk + apply Measurable.of_eval + intro i + apply Measurable.of_eval + intro j + exact (((measurable_pi_apply j).comp (measurable_pi_apply i)).comp hc).add + ((measurable_pi_apply (i,j)).comp measurable_fst) + have hm1 := (queryResidual_measurable P q).prodMk (queryAnswer_measurable P q) + have hm2 : Measurable (fun z : ((Fin n × Fin n) → ℝ) × ((Fin n ⊕ Unit) → ℝ) => + (queryResidual P q z.1,queryInnovation P q z.2)) := + ((queryResidual_measurable P q).comp measurable_fst).prodMk + ((queryInnovation_measurable P q).comp measurable_snd) + have he := congrArg (Measure.map out) hj + rw [Measure.map_map hout hm1,Measure.map_map hout hm2] at he + have hof (A : Matrix (Fin n) (Fin n) ℝ) : Matrix.of (fun i j => A i j)=A := rfl + have hpoint g : out (queryResidual P q g,queryAnswer P q g)= + (completedMatrix U Y g *ᵥ q,completedMatrix U Y g) := by + have ha := completed_query_answer U Y q g ho hPq + change completedMatrix U Y g *ᵥ q=p+queryAnswer P q g at ha + dsimp only [out] + rw [← ha] + congr 1 + simpa only [extendFrame_projection,P,queryResidual,hof] using + (completedMatrix_update U Y q hU hY ho g).symm + simp_rw [Function.comp_def,hpoint] at he + simpa only [out,completedMatrix,queryResidual,← extendFrame_projection,P,p,hof] using he + +end SKGapCutoff.Regression + +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise + +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Matrix/NormalLogConst.lean b/lean/OAI/Probability/SKGap/Matrix/NormalLogConst.lean new file mode 100644 index 0000000000000000000000000000000000000000..d7993be1f01f62a5136bc71b695263f1d781f411 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Matrix/NormalLogConst.lean @@ -0,0 +1,216 @@ +import Mathlib +import OAI.Probability.SKGap.Model + +namespace OAI + +section +noncomputable section +open MeasureTheory ProbabilityTheory InformationTheory Real Set Filter +open scoped NNReal ENNReal Topology +noncomputable section +open Real Set +noncomputable section +open MeasureTheory ProbabilityTheory Real Set Filter +open scoped Topology NNReal ENNReal BoundedContinuousFunction +open MeasureTheory ProbabilityTheory Filter Set Topology Real +open scoped NNReal ENNReal BoundedContinuousFunction +noncomputable section +open Set Filter Topology +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set Topology Real +open scoped NNReal ENNReal BoundedContinuousFunction +namespace SKGap + +variable {ι : Type*} [Fintype ι] + +def normalLogConst (d s : ℝ) : ℝ := -log (sqrt (2*Real.pi*s))-d^2/(2*s) + +def normalLogDensity (d s x : ℝ) : ℝ := normalLogConst d s+d/s*x-x^2/(2*s) + +lemma exp_normalLogDensity (d : ℝ) {s : ℝ} (hs : 0 < s) (x : ℝ) : + exp (normalLogDensity d s x) = gaussianPDFReal d s.toNNReal x := by + have hsp : 0 < sqrt (2*Real.pi*s) := sqrt_pos.mpr (by positivity) + have he : normalLogDensity d s x = -log (sqrt (2*Real.pi*s)) - (x-d)^2/(2*s) := by + unfold normalLogDensity normalLogConst + field_simp + ring + rw [he, sub_eq_add_neg, exp_add, exp_neg, exp_log hsp] + simp only [gaussianPDFReal, Real.coe_toNNReal s hs.le] + congr 1 + congr 1 + ring + +lemma continuousOn_normalLogConst : ContinuousOn (fun p : ℝ×ℝ => normalLogConst p.1 p.2) + {p | 0 < p.2} := by + unfold normalLogConst + apply ContinuousOn.sub + · apply ContinuousOn.neg + apply ContinuousOn.log + · fun_prop + · intro p hp + have hp' : 0 < p.2 := hp + exact (sqrt_pos.mpr (by positivity : 0 < 2*Real.pi*p.2)).ne' + · exact (continuous_fst.pow 2).continuousOn.div (continuous_const.mul continuous_snd).continuousOn + (fun p hp => mul_ne_zero (by norm_num) (ne_of_gt hp)) + +lemma normalLogDensity_sub_le (d' s' d s x : ℝ) : + normalLogDensity d' s' x-normalLogDensity d s x ≤ + |normalLogConst d' s'-normalLogConst d s| + |d'/s'-d/s| *|x| + + |1/(2*s')-1/(2*s)| *x^2 := by + have hx := le_abs_self ((d'/s'-d/s)*x) + rw [abs_mul] at hx + have hq := neg_le_abs (1/(2*s')-1/(2*s)) + have hm := mul_le_mul_of_nonneg_right hq (sq_nonneg x) + have hc := le_abs_self (normalLogConst d' s'-normalLogConst d s) + have he : normalLogDensity d' s' x-normalLogDensity d s x = + (normalLogConst d' s'-normalLogConst d s)+(d'/s'-d/s)*x - + (1/(2*s')-1/(2*s))*x^2 := by + unfold normalLogDensity + ring + rw [he] + linarith + +lemma normalLogDensity_sum_sub_le {y : ι → ℝ} {R : ℝ} + (hy : ∑ i, (y i)^2 ≤ (Fintype.card ι : ℝ)*R) (d' s' d s : ℝ) : + (∑ i, normalLogDensity d' s' (y i))-(∑ i, normalLogDensity d s (y i)) ≤ + (Fintype.card ι : ℝ) * (|normalLogConst d' s'-normalLogConst d s| + + |d'/s'-d/s| *(1+R)+|1/(2*s')-1/(2*s)| *R) := by + have hl : ∑ i, |y i| ≤ (Fintype.card ι : ℝ)*(1+R) := by + calc + _ ≤ ∑ i, (1+(y i)^2) := Finset.sum_le_sum (fun i _ => by + nlinarith [sq_abs (y i), sq_nonneg (|y i|-1)]) + _ = (Fintype.card ι : ℝ) + ∑ i, (y i)^2 := by simp [Finset.sum_add_distrib] + _ ≤ _ := by nlinarith + have hh := Finset.sum_le_sum (s := Finset.univ) (fun i _ => normalLogDensity_sub_le d' s' d s (y i)) + simp only [Finset.sum_sub_distrib, Finset.sum_add_distrib, Finset.sum_const, Finset.card_univ, + nsmul_eq_mul, ← Finset.mul_sum] at hh + have h1 := mul_le_mul_of_nonneg_left hl (abs_nonneg (d'/s'-d/s)) + have h2 := mul_le_mul_of_nonneg_left hy (abs_nonneg (1/(2*s')-1/(2*s))) + calc + _ ≤ _ := hh + _ ≤ _ := by nlinarith + +def productNormal (d s : ℝ) (y : ι → ℝ) : ℝ := ∏ i, gaussianPDFReal d s.toNNReal (y i) + +lemma productNormal_eq_exp (d : ℝ) {s : ℝ} (hs : 0 < s) (y : ι → ℝ) : + productNormal d s y = exp (∑ i, normalLogDensity d s (y i)) := by + rw [exp_sum] + unfold productNormal + apply Finset.prod_congr rfl + intro i hi + exact (exp_normalLogDensity d hs (y i)).symm + +lemma productNormal_nonneg (d s : ℝ) (y : ι → ℝ) : 0 ≤ productNormal d s y := + Finset.prod_nonneg (fun i _ => gaussianPDFReal_nonneg d s.toNNReal (y i)) + +lemma integrable_tiltedNormal (f : ℝ →ᵇ ℝ) (d : ℝ) (s : ℝ≥0) : + Integrable (fun x => exp (f x)*gaussianPDFReal d s x) := by + have h := (integrable_gaussianPDFReal d s).bdd_mul + (continuous_exp.comp f.continuous).aestronglyMeasurable + (c := exp ‖f‖) (ae_of_all _ (fun x => by + dsimp only [Function.comp_def] + rw [Real.norm_eq_abs, abs_of_pos (exp_pos _)] + exact exp_le_exp.mpr ((le_abs_self _).trans (f.norm_coe_le_norm x)))) + exact h + +lemma integral_tiltedNormal (f : ℝ →ᵇ ℝ) (d : ℝ) {s : ℝ≥0} (hs : s ≠ 0) : + (∫ x, exp (f x)*gaussianPDFReal d s x) = ∫ x, exp (f x) ∂gaussianReal d s := by + rw [integral_gaussianReal_eq_integral_smul hs] + simp only [smul_eq_mul, mul_comm] + +lemma tiltedNormal_mass_pos (f : ℝ →ᵇ ℝ) (d : ℝ) (s : ℝ≥0) : + 0 < ∫ x, exp (f x) ∂gaussianReal d s := by + have hi : Integrable (fun x => exp (f x)) (gaussianReal d s) := Integrable.of_bound + (by fun_prop) (exp ‖f‖) (ae_of_all _ (fun x => by + rw [Real.norm_eq_abs, abs_of_pos (exp_pos _)] + exact exp_le_exp.mpr ((le_abs_self _).trans (f.norm_coe_le_norm x)))) + exact integral_pos_iff_support_of_nonneg (fun _ => (exp_pos _).le) hi |>.mpr + (by simp [Function.support, (exp_pos _).ne']) + +lemma product_tiltedNormal_integral (f : ℝ →ᵇ ℝ) (d : ℝ) {s : ℝ} (hs : 0 < s) : + (∫ y : ι → ℝ, exp (∑ i, f (y i))*productNormal d s y) = + exp ((Fintype.card ι : ℝ)*log (∫ x, exp (f x) ∂gaussianReal d s.toNNReal)) := by + have hs' : s.toNNReal ≠ 0 := ne_of_gt (Real.toNNReal_pos.mpr hs) + have he (y : ι → ℝ) : exp (∑ i, f (y i))*productNormal d s y = + ∏ i, (exp (f (y i))*gaussianPDFReal d s.toNNReal (y i)) := by + rw [exp_sum, productNormal, Finset.prod_mul_distrib] + simp_rw [he] + rw [integral_fintype_prod_volume_eq_pow (fun x : ℝ => exp (f x)*gaussianPDFReal d s.toNNReal x), integral_tiltedNormal f d hs', + exp_nat_mul, exp_log (tiltedNormal_mass_pos f d s.toNNReal)] + +lemma product_tiltedNormal_integrable (f : ℝ →ᵇ ℝ) (d s : ℝ) : + Integrable (fun y : ι → ℝ => exp (∑ i, f (y i))*productNormal d s y) := by + have h := Integrable.fintype_prod (fun _ : ι => integrable_tiltedNormal f d s.toNNReal) + simpa only [exp_sum, productNormal, Finset.prod_mul_distrib, volume_pi] using h + +end SKGap + +namespace SKGap + +def normalDensityError (R d s d₀ s₀ : ℝ) : ℝ := + |normalLogConst d s-normalLogConst d₀ s₀| + |d/s-d₀/s₀| * (1+R) + + |1/(2*s)-1/(2*s₀)| * R + +lemma normalDensityError_self (R d s : ℝ) : normalDensityError R d s d s = 0 := by + simp [normalDensityError] + +lemma continuous_normalDensityError {X : Type*} [TopologicalSpace X] + {d s : X → ℝ} (hd : Continuous d) (hs : Continuous s) (hspos : ∀ x, 0 < s x) + (R d₀ s₀ : ℝ) : Continuous (fun x => normalDensityError R (d x) (s x) d₀ s₀) := by + have hlog : Continuous (fun x => normalLogConst (d x) (s x)) := + continuousOn_normalLogConst.comp_continuous (hd.prodMk hs) (fun x => hspos x) + have hdiv := hd.div hs (fun x => (hspos x).ne') + have hinv : Continuous (fun x => (1 : ℝ)/(2*s x)) := continuous_const.div (continuous_const.mul hs) (fun x => mul_ne_zero (by norm_num) (hspos x).ne') + exact ((hlog.sub continuous_const).abs.add ((hdiv.sub continuous_const).abs.mul continuous_const)).add + ((hinv.sub continuous_const).abs.mul continuous_const) + +theorem finite_gaussian_test_cover {X : Type*} [TopologicalSpace X] {K : Set X} + (hK : IsCompact K) {P : X → ProbabilityMeasure ℝ} {d s ψ : X → ℝ} + (hP : ContinuousOn P K) (hd : ContinuousOn d K) (hs : ContinuousOn s K) + (hψ : ContinuousOn ψ K) (hpos : ∀ x ∈ K, 0 < s x) (R r : ℝ) + (hW : ∀ x ∈ K, ∃ f : ℝ →ᵇ ℝ, ψ x-(∫ y, f y ∂P x)+ + log (∫ y, exp (f y) ∂gaussianReal (d x) (s x).toNNReal) < r) : + ∃ (C : Finset K) (f : K → ℝ →ᵇ ℝ), ∀ z ∈ K, ∃ x ∈ C, + ψ z-(∫ y, f x y ∂P z)+normalDensityError R (d z) (s z) (d x) (s x)+ + log (∫ y, exp (f x y) ∂gaussianReal (d x) (s x).toNNReal) < r := by + classical + let : CompactSpace K := isCompact_iff_compactSpace.mp hK + choose f hf using (fun x : K => hW x.1 x.2) + let U (x : K) : Set K := {z | ψ z-(∫ y, f x y ∂P z)+ + normalDensityError R (d z) (s z) (d x) (s x)+ + log (∫ y, exp (f x y) ∂gaussianReal (d x) (s x).toNNReal) < r} + have hU (x : K) : IsOpen (U x) := by + apply isOpen_lt _ continuous_const + have hint : Continuous (fun z : K => ∫ y, f x y ∂P z) := + (ProbabilityMeasure.continuous_integral_boundedContinuousFunction (f x)).comp hP.domRestrict + exact ((hψ.domRestrict.sub hint).add + (continuous_normalDensityError hd.domRestrict hs.domRestrict + (fun z : K => hpos z.1 z.2) R (d x) (s x))).add continuous_const + have hcov : (univ : Set K) ⊆ ⋃ x : K, U x := by + intro z _ + refine mem_iUnion.mpr ⟨z, ?_⟩ + change ψ z-(∫ y, f z y ∂P z)+normalDensityError R (d z) (s z) (d z) (s z)+ + log (∫ y, exp (f z y) ∂gaussianReal (d z) (s z).toNNReal) < r + simpa only [normalDensityError_self, add_zero] using hf z + obtain ⟨C,hC⟩ := isCompact_univ.elim_finite_subcover U hU hcov + refine ⟨C,f,?_⟩ + intro z hz + have hh := hC (mem_univ (⟨z,hz⟩ : K)) + obtain ⟨x,hx⟩ := mem_iUnion.mp hh + obtain ⟨hxC,hxU⟩ := mem_iUnion.mp hx + exact ⟨x,hxC,hxU⟩ + +end SKGap +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set Topology Real +open scoped NNReal ENNReal BoundedContinuousFunction + +end +end +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Matrix/NormalLogDensityCentered.lean b/lean/OAI/Probability/SKGap/Matrix/NormalLogDensityCentered.lean new file mode 100644 index 0000000000000000000000000000000000000000..64d3ba341b83616189cc6a292e896f4550f35e1b --- /dev/null +++ b/lean/OAI/Probability/SKGap/Matrix/NormalLogDensityCentered.lean @@ -0,0 +1,94 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.ScalarSmallNoiseTests + +namespace OAI + +section +noncomputable section +open MeasureTheory ProbabilityTheory InformationTheory Real Set Filter +open scoped NNReal ENNReal Topology +noncomputable section +open Real Set +noncomputable section +open MeasureTheory ProbabilityTheory Real Set Filter +open scoped Topology NNReal ENNReal BoundedContinuousFunction +open MeasureTheory ProbabilityTheory Filter Set Topology Real +open scoped NNReal ENNReal BoundedContinuousFunction +noncomputable section +open Set Filter Topology +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set Topology Real +open scoped NNReal ENNReal BoundedContinuousFunction +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set Topology Real +open scoped NNReal ENNReal BoundedContinuousFunction +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set Topology Real +open scoped NNReal ENNReal +namespace SKGap +lemma normalLogDensity_centered (d s x : ℝ) : + normalLogDensity d s x = -log (sqrt (2*Real.pi*s))-(x-d)^2/(2*s) := by + unfold normalLogDensity normalLogConst + ring + +lemma gaussian_pointwise_envelope {ι : Type*} [Fintype ι] (y : ι → ℝ) + {d s j D smin smax ψ : ℝ} (hsmin : 0 < smin) (hsl : smin ≤ s) (hsu : s ≤ smax) + (hd : d^2 ≤ D^2) + (hψ : (Fintype.card ι:ℝ)*ψ ≤ 3/(8*s)*(∑ i, (y i-d)^2)+3*(Fintype.card ι:ℝ)*j/2) : + exp ((Fintype.card ι:ℝ)*ψ)*productNormal d s y ≤ + exp ((Fintype.card ι:ℝ)*(|log (sqrt (2*Real.pi*smin))|+3*j/2+D^2/(8*smin))- + (1/(16*smax))*∑ i, (y i)^2) := by + have hs : 0 < s := hsmin.trans_le hsl + have hmax : 0 < smax := hs.trans_le hsu + have hn : (0:ℝ) ≤ Fintype.card ι := Nat.cast_nonneg _ + have hQ : 0 ≤ ∑ i, (y i)^2 := Finset.sum_nonneg (fun i _ => sq_nonneg _) + have hc := sum_centered_sq_lower y d + have hnd := mul_le_mul_of_nonneg_left hd hn + have h1 : -(∑ i, (y i-d)^2)/(8*s) ≤ + -(∑ i, (y i)^2)/(16*s)+(Fintype.card ι:ℝ)*D^2/(8*s) := by + have he : -(∑ i, (y i)^2)/(16*s)+(Fintype.card ι:ℝ)*D^2/(8*s) = + (-(∑ i, (y i)^2)/2+(Fintype.card ι:ℝ)*D^2)/(8*s) := by ring + rw [he] + apply div_le_div_of_nonneg_right _ (by positivity : 0 ≤ 8*s) + linarith + have h2 : -(∑ i, (y i)^2)/(16*s) ≤ -(∑ i, (y i)^2)/(16*smax) := by + rw [neg_div, neg_div, neg_le_neg_iff] + gcongr + have h3 : (Fintype.card ι:ℝ)*D^2/(8*s) ≤ (Fintype.card ι:ℝ)*D^2/(8*smin) := by + gcongr + have hp : 0 < sqrt (2*Real.pi*smin) := sqrt_pos.mpr (by positivity) + have hlog : log (sqrt (2*Real.pi*smin)) ≤ log (sqrt (2*Real.pi*s)) := + log_le_log hp (sqrt_le_sqrt (by nlinarith [Real.pi_pos])) + have hlog' : -log (sqrt (2*Real.pi*s)) ≤ |log (sqrt (2*Real.pi*smin))| := + (neg_le_neg hlog).trans (neg_le_abs _) + have hnlog := mul_le_mul_of_nonneg_left hlog' hn + have he : (∑ i, normalLogDensity d s (y i)) = + -(Fintype.card ι:ℝ)*log (sqrt (2*Real.pi*s))-(∑ i, (y i-d)^2)/(2*s) := by + simp only [normalLogDensity_centered, Finset.sum_sub_distrib, Finset.sum_const, + Finset.card_univ, nsmul_eq_mul, Finset.sum_div] + ring + rw [productNormal_eq_exp _ hs, ← exp_add, he] + apply exp_le_exp.mpr + calc + _ ≤ 3/(8*s)*(∑ i, (y i-d)^2)+3*(Fintype.card ι:ℝ)*j/2+ + (-(Fintype.card ι:ℝ)*log (sqrt (2*Real.pi*s))-(∑ i, (y i-d)^2)/(2*s)) := + by linarith only [hψ] + _ = (Fintype.card ι:ℝ)*(-log (sqrt (2*Real.pi*s)))+3*(Fintype.card ι:ℝ)*j/2+ + (-(∑ i, (y i-d)^2)/(8*s)) := by ring + _ ≤ (Fintype.card ι:ℝ)*|log (sqrt (2*Real.pi*smin))|+3*(Fintype.card ι:ℝ)*j/2+ + (-(∑ i, (y i)^2)/(16*smax)+(Fintype.card ι:ℝ)*D^2/(8*smin)) := + add_le_add (by linarith only [hnlog]) (h1.trans (add_le_add h2 h3)) + _ = _ := by ring + +end SKGap + +end +end +end +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Matrix/NormalizedInfluence.lean b/lean/OAI/Probability/SKGap/Matrix/NormalizedInfluence.lean new file mode 100644 index 0000000000000000000000000000000000000000..8d5ce0352f2fc0b8d24e1da82a5901bb117bef00 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Matrix/NormalizedInfluence.lean @@ -0,0 +1,406 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.BilinearCoefficient +import OAI.Probability.SKGap.Gaussian.SquaredGaussianFourth + +namespace OAI + +section +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open scoped BigOperators +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open scoped BigOperators +open scoped BigOperators NNReal ENNReal +open MeasureTheory Metric Set +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators NNReal ENNReal Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Set +namespace SKGapCutoff + +lemma tanh_cubic_remainder (d : ℝ) : |Real.tanh d - d| ≤ |d|^3 := by + let f (z : ℝ) := Real.tanh z - z + have hd (z : ℝ) : HasDerivAt f (-(Real.tanh z)^2) z := by + convert! (tanh_hasDerivAt z).sub (hasDerivAt_id z) using 1 + unfold scalarVariance + ring + have hb (z : ℝ) (hz : z ∈ segment ℝ 0 d) : ‖-(Real.tanh z)^2‖ ≤ |d|^2 := by + have h1 : |Real.tanh z| ≤ |z| := by simpa using tanh_lipschitz 0 z + have h2 : |z| ≤ |d| := by + simpa only [sub_zero, Real.norm_eq_abs] using norm_sub_le_of_mem_segment hz + rw [norm_neg, norm_pow, Real.norm_eq_abs] + exact pow_le_pow_left₀ (abs_nonneg _) (h1.trans h2) 2 + have h := Convex.norm_image_sub_le_of_norm_hasDerivWithin_le + (fun z (_ : z ∈ segment ℝ 0 d) => (hd z).hasDerivWithinAt) hb + (convex_segment 0 d) (left_mem_segment ℝ 0 d) (right_mem_segment ℝ 0 d) + simpa only [f, Real.tanh_zero, sub_zero, Real.norm_eq_abs, pow_succ] using h + +lemma normalized_tanh_difference (h d : ℝ) : + (Real.tanh h - Real.tanh (h-d)) / scalarVariance h = + Real.tanh d / (1 - Real.tanh h * Real.tanh d) := by + have hc : Real.cosh (h-d) ≠ 0 := (Real.cosh_pos _).ne' + have hh : Real.cosh h ≠ 0 := (Real.cosh_pos _).ne' + have hd : Real.cosh d ≠ 0 := (Real.cosh_pos _).ne' + have hm : Real.cosh h * Real.cosh d - Real.sinh h * Real.sinh d ≠ 0 := by + simpa only [Real.cosh_sub] using hc + rw [tanh_difference_eq, show h-(h-d)=d by ring, scalarVariance_eq] + simp only [Real.tanh_eq_sinh_div_cosh] + rw [Real.cosh_sub] + field_simp + +lemma rational_cubic_remainder (m u d : ℝ) (hm : |m| ≤ 1) + (hd : |d| ≤ 1/2) (hu : |u| ≤ |d|) (hud : |u-d| ≤ |d|^3) : + |u/(1-m*u) - d - m*d^2| ≤ 4*|d|^3 := by + have hmud : |m*u| ≤ |d| := by + rw [abs_mul] + exact (mul_le_mul hm hu (abs_nonneg _) (by norm_num)).trans_eq (one_mul _) + have hden : 1/2 ≤ 1-m*u := by linarith [le_abs_self (m*u)] + have hdenpos : 0 < 1-m*u := by linarith + have hd0 := abs_nonneg d + have he : u/(1-m*u) - d - m*d^2 = + (u-d) + m*(u^2-d^2) + m^2*u^3/(1-m*u) := by + apply mul_right_cancel₀ hdenpos.ne' + simp only [sub_mul, add_mul, div_mul_cancel₀ _ hdenpos.ne'] + ring + have hs : |u^2-d^2| ≤ |d|^3 := by + have hh : |u^2-d^2| = |u-d| * |u+d| := by rw [← abs_mul]; congr 1; ring + rw [hh] + have ha : |u+d| ≤ 1 := (abs_add_le _ _).trans (by linarith) + nlinarith [mul_le_mul hud ha (abs_nonneg _) (pow_nonneg hd0 3)] + have ht : |m*(u^2-d^2)| ≤ |d|^3 := by + rw [abs_mul] + simpa only [one_mul] using mul_le_mul hm hs (abs_nonneg _) (by norm_num : (0:ℝ) ≤ 1) + have hq : |m^2*u^3/(1-m*u)| ≤ 2*|d|^3 := by + rw [abs_div, abs_mul, abs_pow, abs_pow, abs_of_pos hdenpos, div_le_iff₀ hdenpos] + have hm2 : |m|^2 ≤ 1 := by nlinarith [abs_nonneg m] + have hu3 : |u|^3 ≤ |d|^3 := pow_le_pow_left₀ (abs_nonneg _) hu 3 + have hp := mul_le_mul hm2 hu3 (pow_nonneg (abs_nonneg _) _) (by norm_num : (0:ℝ) ≤ 1) + nlinarith [mul_le_mul_of_nonneg_left hden (pow_nonneg hd0 3)] + rw [he] + exact (abs_add_le _ _).trans ((add_le_add ((abs_add_le _ _).trans (add_le_add hud ht)) hq).trans (by ring_nf; rfl)) + +lemma normalized_tanh_cubic (h d : ℝ) (hd : |d| ≤ 1/2) : + |(Real.tanh h - Real.tanh (h-d))/scalarVariance h - d - Real.tanh h*d^2| ≤ + 4*|d|^3 := by + rw [normalized_tanh_difference] + exact rational_cubic_remainder _ _ _ (Real.abs_tanh_lt_one h).le hd + (by simpa using tanh_lipschitz 0 d) (tanh_cubic_remainder d) + +lemma normalized_influence_cubic {n : ℕ} (J : Interaction n) (x : Spin n) (i j : Fin n) + (hJ : |J j i| ≤ 1/4) : + |influence J x i j / siteVariance J x j - J j i - 2*spin x i*mean J x j*(J j i)^2| ≤ + 16*|J j i|^3 := by + have ha : |2*J j i*spin x i| = 2*|J j i| := by + rw [abs_mul, abs_mul, abs_spin_eq_one]; norm_num + have hd : |2*J j i*spin x i| ≤ 1/2 := by rw [ha]; linarith + have hh := normalized_tanh_cubic (field J x j) (2*J j i*spin x i) hd + have hv : siteVariance J x j ≠ 0 := (siteVariance_pos J x j).ne' + have he : influence J x i j / siteVariance J x j - J j i - 2*spin x i*mean J x j*(J j i)^2 = + (spin x i / 2) * ((Real.tanh (field J x j) - + Real.tanh (field J x j - 2*J j i*spin x i))/scalarVariance (field J x j) - + 2*J j i*spin x i - Real.tanh (field J x j)*(2*J j i*spin x i)^2) := by + simp only [influence, halfDiff_as_flip, mean, field_flip_general, scalarVariance, siteVariance] + have hs := spin_sq x i + have ht : 1 - Real.tanh (field J x j)^2 ≠ 0 := (scalarVariance_pos _).ne' + field_simp [ht] + linear_combination (2 * J j i * (1 - Real.tanh (field J x j)^2) + + 4 * spin x i * Real.tanh (field J x j) * (J j i)^2 * (1 - Real.tanh (field J x j)^2)) * hs + rw [he, abs_mul, abs_div, abs_spin_eq_one] + rw [ha] at hh + norm_num only [abs_of_pos (show (0:ℝ) < 2 by norm_num)] + nlinarith + +lemma matrix_opNorm_le_schur {n : ℕ} (A : Interaction n) (R : ℝ) (hR : 0 ≤ R) + (hr : ∀ i, ∑ j, |A i j| ≤ R) (hc : ∀ j, ∑ i, |A i j| ≤ R) : + ‖Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) A‖ ≤ R := by + apply ContinuousLinearMap.opNorm_le_of_re_inner_le hR + intro x y hx hy + change inner (𝕜 := ℝ) (Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) A x) y ≤ R + rw [real_inner_comm, Matrix.inner_toEuclideanCLM] + change (∑ i, y i * ∑ j, A i j*x j) ≤ R + simp only [Finset.mul_sum] + calc + _ ≤ ∑ i, ∑ j, |A i j| * ((y i)^2 + (x j)^2)/2 := by + apply Finset.sum_le_sum + intro i _ + apply Finset.sum_le_sum + intro j _ + have hab : 2*|y i| *|x j| ≤ (y i)^2+(x j)^2 := by + nlinarith [sq_nonneg (|y i|-|x j|), sq_abs (y i), sq_abs (x j)] + have hp := mul_le_mul_of_nonneg_left hab (abs_nonneg (A i j)) + have hh : y i*(A i j*x j) ≤ |y i| *|A i j| *|x j| := by + simpa only [abs_mul, mul_assoc] using le_abs_self (y i*(A i j*x j)) + nlinarith + _ = ((∑ i, (y i)^2 * ∑ j, |A i j|) + ∑ j, (x j)^2 * ∑ i, |A i j|)/2 := by + simp only [mul_add, add_div, Finset.sum_add_distrib, ← Finset.sum_div] + rw [Finset.sum_comm (f := fun i j => |A i j| * (x j)^2)] + simp only [← Finset.sum_mul] + congr 2 <;> apply Finset.sum_congr rfl <;> intro i _ <;> ring + _ ≤ ((∑ i, (y i)^2 * R) + ∑ j, (x j)^2*R)/2 := by + apply div_le_div_of_nonneg_right _ (by norm_num) + exact add_le_add + (Finset.sum_le_sum (fun i _ => mul_le_mul_of_nonneg_left (hr i) (sq_nonneg _))) + (Finset.sum_le_sum (fun i _ => mul_le_mul_of_nonneg_left (hc i) (sq_nonneg _))) + _ = R := by + rw [← Finset.sum_mul, ← Finset.sum_mul, ← EuclideanSpace.real_norm_sq_eq, + ← EuclideanSpace.real_norm_sq_eq, hx, hy] + ring + +lemma matrix_diagonal_opNorm_le {n : ℕ} (d : Fin n → ℝ) (R : ℝ) (hR : 0 ≤ R) + (hd : ∀ i, |d i| ≤ R) : + ‖Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) (Matrix.diagonal d)‖ ≤ R := by + apply matrix_opNorm_le_schur _ R hR + · intro i + simpa [Matrix.diagonal, apply_ite, abs_zero] using hd i + · intro i + simpa [Matrix.diagonal, apply_ite, abs_zero] using hd i + +noncomputable def normalizedInfluence {n : ℕ} (J : Interaction n) (x : Spin n) : Interaction n := + fun i j => influence J x i j / siteVariance J x j + +noncomputable def influenceCubicError {n : ℕ} (J : Interaction n) (x : Spin n) : Interaction n := + fun i j => normalizedInfluence J x i j - J j i - 2*spin x i*mean J x j*(J j i)^2 + +lemma influenceCubicError_norm_le {n : ℕ} (J : Interaction n) + (hsymm : ∀ i j, J i j=J j i) (x : Spin n) (c B : ℝ) (hc : 0 ≤ c) (hc1 : c ≤ 1/4) + (hB : 0 ≤ B) (hmax : ∀ i j, |J i j| ≤ c) + (hcol : ∀ i, ∑ j, J j i^2 ≤ B) : + ‖Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) (influenceCubicError J x)‖ ≤ 16*c*B := by + have hp (i j : Fin n) : |influenceCubicError J x i j| ≤ 16*c*(J j i)^2 := by + have hh := normalized_influence_cubic J x i j ((hmax j i).trans hc1) + change |influenceCubicError J x i j| ≤ _ at hh + apply hh.trans + have hmul := mul_le_mul_of_nonneg_right (hmax j i) (sq_nonneg |J j i|) + nlinarith [sq_abs (J j i)] + apply matrix_opNorm_le_schur _ (16*c*B) (by positivity) + · intro i + calc + _ ≤ ∑ j, 16*c*(J j i)^2 := Finset.sum_le_sum (fun j _ => hp i j) + _ = 16*c*∑ j, J j i^2 := by rw [Finset.mul_sum] + _ ≤ _ := mul_le_mul_of_nonneg_left (hcol i) (by positivity) + · intro j + calc + _ ≤ ∑ i, 16*c*(J j i)^2 := Finset.sum_le_sum (fun i _ => hp i j) + _ = 16*c*∑ i, J i j^2 := by simp only [hsymm j, Finset.mul_sum] + _ ≤ _ := mul_le_mul_of_nonneg_left (hcol j) (by positivity) + +noncomputable def normalizedInfluenceApprox {n : ℕ} (β : ℝ) (J : Interaction n) (x : Spin n) : Interaction n := + fun i j => J i j + 2*β^2/(n:ℝ)*spin x i*mean J x j + +lemma normalizedInfluence_sub_approx {n : ℕ} (β : ℝ) (g : GaussianCoordinates n) (x : Spin n) : + normalizedInfluence (sampledInteraction g) x - normalizedInfluenceApprox β (sampledInteraction g) x = + influenceCubicError (sampledInteraction g) x + (2:ℝ) • + (Matrix.diagonal (spin x) * RandomMatrix.sampledSquaredDeviation β g * + Matrix.diagonal (mean (sampledInteraction g) x)) := by + ext i j + simp only [Matrix.sub_apply, Matrix.add_apply, Matrix.smul_apply, smul_eq_mul, + Matrix.mul_diagonal, Matrix.diagonal_mul, normalizedInfluenceApprox, + influenceCubicError, RandomMatrix.sampledSquaredDeviation, sampledInteraction_symm g j i] + ring + +lemma normalizedInfluence_approx_norm_le {n : ℕ} (β : ℝ) (g : GaussianCoordinates n) (x : Spin n) + (c B : ℝ) (hc : 0 ≤ c) (hc1 : c ≤ 1/4) (hB : 0 ≤ B) + (hmax : ∀ i j, |sampledInteraction g i j| ≤ c) + (hcol : ∀ i, ∑ j, sampledInteraction g j i^2 ≤ B) : + ‖Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) + (normalizedInfluence (sampledInteraction g) x - normalizedInfluenceApprox β (sampledInteraction g) x)‖ ≤ + 16*c*B+2*‖Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) (RandomMatrix.sampledSquaredDeviation β g)‖ := by + have hs : ‖Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) (Matrix.diagonal (spin x))‖ ≤ 1 := + matrix_diagonal_opNorm_le _ 1 (by norm_num) (fun i => (abs_spin_eq_one x i).le) + have hm : ‖Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) + (Matrix.diagonal (mean (sampledInteraction g) x))‖ ≤ 1 := + matrix_diagonal_opNorm_le _ 1 (by norm_num) (fun i => (Real.abs_tanh_lt_one _).le) + have hp : ‖Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) + (Matrix.diagonal (spin x) * RandomMatrix.sampledSquaredDeviation β g * + Matrix.diagonal (mean (sampledInteraction g) x))‖ ≤ + ‖Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) (RandomMatrix.sampledSquaredDeviation β g)‖ := by + rw [map_mul, map_mul] + calc + _ ≤ _ * _ := norm_mul_le _ _ + _ ≤ (‖Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) (Matrix.diagonal (spin x))‖ * + ‖Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) (RandomMatrix.sampledSquaredDeviation β g)‖) * + ‖Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) (Matrix.diagonal (mean (sampledInteraction g) x))‖ := by + exact mul_le_mul_of_nonneg_right (norm_mul_le _ _) (norm_nonneg _) + _ ≤ (1 * ‖Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) (RandomMatrix.sampledSquaredDeviation β g)‖) * 1 := by + gcongr + _ = _ := by ring + rw [normalizedInfluence_sub_approx, map_add] + calc + _ ≤ _ + _ := norm_add_le _ _ + _ ≤ _ := add_le_add + (influenceCubicError_norm_le _ (sampledInteraction_symm g) x c B hc hc1 hB hmax hcol) + (by rw [map_smul, norm_smul]; norm_num only [Real.norm_eq_abs, abs_of_pos (show (0:ℝ)<2 by norm_num)]; exact mul_le_mul_of_nonneg_left hp (by norm_num)) + +lemma normalizedInfluence_approx_tendsto (β ε : ℝ) (hε : 0 < ε) : + Tendsto (fun n => disorderLaw β n {g | ∃ x : Spin n, ε < + ‖Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) + (normalizedInfluence (sampledInteraction g) x - normalizedInfluenceApprox β (sampledInteraction g) x)‖}) + atTop (nhds 0) := by + let B : ℝ := (2*(β^2+10))^2 + let c : ℝ := min (1/4) (ε/(64*(B+1))) + have hB : 0 ≤ B := sq_nonneg _ + have hc : 0 < c := lt_min (by norm_num) (by positivity) + have hc1 : c ≤ 1/4 := min_le_left _ _ + have hcd : 16*c*B ≤ ε/4 := by + calc + _ ≤ 16*(ε/(64*(B+1)))*(B+1) := mul_le_mul + (mul_le_mul_of_nonneg_left (min_le_right _ _) (by norm_num)) (by linarith) + hB (by positivity) + _ = ε/4 := by field_simp; ring + have hl := (RandomMatrix.sampled_opNorm_tendsto β).add + ((RandomMatrix.sampled_maxEntry_tendsto β c hc).add + (RandomMatrix.sampledSquaredDeviation_tendsto β (ε/8) (by positivity))) + simp only [add_zero] at hl + apply tendsto_of_tendsto_of_tendsto_of_le_of_le' tendsto_const_nhds hl + (Eventually.of_forall (fun _ => bot_le)) + apply Eventually.of_forall + intro n + let N : Set (GaussianCoordinates n) := {g | 2*(β^2+10) < + ‖Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) (sampledInteraction g)‖} + let E : Set (GaussianCoordinates n) := {g | ∃ i j, c ≤ |sampledInteraction g i j|} + let V : Set (GaussianCoordinates n) := {g | ε/8 < + ‖Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) (RandomMatrix.sampledSquaredDeviation β g)‖} + have hs : {g | ∃ x : Spin n, ε < ‖Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) + (normalizedInfluence (sampledInteraction g) x - normalizedInfluenceApprox β (sampledInteraction g) x)‖} ⊆ + N ∪ (E ∪ V) := by + intro g hg + by_cases hN : g ∈ N + · exact Or.inl hN + by_cases hE : g ∈ E + · exact Or.inr (Or.inl hE) + by_cases hV : g ∈ V + · exact Or.inr (Or.inr hV) + have hn : ‖Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) (sampledInteraction g)‖ ≤ 2*(β^2+10) := + le_of_not_gt hN + have he (i j : Fin n) : |sampledInteraction g i j| ≤ c := + (not_le.mp (fun h => hE ⟨i,j,h⟩)).le + have hv : ‖Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) (RandomMatrix.sampledSquaredDeviation β g)‖ ≤ ε/8 := + le_of_not_gt hV + obtain ⟨x,hx⟩ := hg + have hp := normalizedInfluence_approx_norm_le β g x c B hc.le hc1 hB he (fun i => + (RandomMatrix.matrix_column_sq_le _ i).trans (pow_le_pow_left₀ (norm_nonneg _) hn 2)) + exfalso + linarith + exact (measure_mono hs).trans ((measure_union_le N (E ∪ V)).trans + (add_le_add le_rfl (measure_union_le E V))) + +noncomputable def influenceApprox {n : ℕ} (β : ℝ) (J : Interaction n) (x : Spin n) : Interaction n := + normalizedInfluenceApprox β J x * Matrix.diagonal (siteVariance J x) + +lemma influence_eq_normalized_mul {n : ℕ} (J : Interaction n) (x : Spin n) : + influence J x = normalizedInfluence J x * Matrix.diagonal (siteVariance J x) := by + ext i j + simp only [Matrix.mul_diagonal, normalizedInfluence] + rw [div_mul_cancel₀ _ (siteVariance_pos J x j).ne'] + +lemma influenceApprox_apply {n : ℕ} (β : ℝ) (J : Interaction n) (x : Spin n) (i j : Fin n) : + influenceApprox β J x i j = J i j*siteVariance J x j + + 2*β^2/(n:ℝ)*spin x i*(mean J x j*siteVariance J x j) := by + simp only [influenceApprox, Matrix.mul_diagonal, normalizedInfluenceApprox] + ring + +lemma influence_approx_error_le {n : ℕ} (β : ℝ) (J : Interaction n) (x : Spin n) : + ‖Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) (influence J x - influenceApprox β J x)‖ ≤ + ‖Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) (normalizedInfluence J x - normalizedInfluenceApprox β J x)‖ := by + have hv : ‖Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) (Matrix.diagonal (siteVariance J x))‖ ≤ 1 := by + apply matrix_diagonal_opNorm_le _ 1 (by norm_num) + intro i + rw [abs_of_pos (siteVariance_pos J x i)] + exact siteVariance_le_one J x i + rw [influence_eq_normalized_mul, influenceApprox, ← Matrix.sub_mul, map_mul] + exact (norm_mul_le _ _).trans (by simpa only [mul_one] using mul_le_mul_of_nonneg_left hv (norm_nonneg _)) + +lemma influence_approx_tendsto (β ε : ℝ) (hε : 0 < ε) : + Tendsto (fun n => disorderLaw β n {g | ∃ x : Spin n, ε < + ‖Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) + (influence (sampledInteraction g) x - influenceApprox β (sampledInteraction g) x)‖}) + atTop (nhds 0) := by + apply tendsto_of_tendsto_of_tendsto_of_le_of_le' tendsto_const_nhds + (normalizedInfluence_approx_tendsto β ε hε) (Eventually.of_forall (fun _ => bot_le)) + apply Eventually.of_forall + intro n + apply measure_mono + rintro g ⟨x,hx⟩ + exact ⟨x,hx.trans_le (influence_approx_error_le β (sampledInteraction g) x)⟩ + +lemma normalizedInfluenceApprox_norm_le {n : ℕ} (β : ℝ) (J : Interaction n) (x : Spin n) : + ‖Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) (normalizedInfluenceApprox β J x)‖ ≤ + ‖Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) J‖ + 2*β^2 := by + let R : Interaction n := fun i j => 2*β^2/(n:ℝ)*spin x i*mean J x j + have he : normalizedInfluenceApprox β J x = J+R := rfl + have hr : ‖Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) R‖ ≤ 2*β^2 := by + by_cases hn : n=0 + · subst n + have hz : R=0 := Subsingleton.elim _ _ + rw [hz, map_zero, norm_zero]; positivity + have hn0 : 0 < (n:ℝ) := Nat.cast_pos.mpr (Nat.pos_of_ne_zero hn) + have hp (i j : Fin n) : |R i j| ≤ 2*β^2/(n:ℝ) := by + change |2*β^2/(n:ℝ)*spin x i*mean J x j| ≤ _ + rw [abs_mul, abs_mul, abs_spin_eq_one, mul_one, abs_of_nonneg (by positivity : 0 ≤ 2*β^2/(n:ℝ))] + exact (mul_le_mul_of_nonneg_left (Real.abs_tanh_lt_one _).le (by positivity)).trans_eq (mul_one _) + apply matrix_opNorm_le_schur _ (2*β^2) (by positivity) + · intro i + calc + _ ≤ ∑ j : Fin n, 2*β^2/(n:ℝ) := Finset.sum_le_sum (fun j _ => hp i j) + _ = _ := by simp only [Finset.sum_const, Finset.card_univ, Fintype.card_fin, nsmul_eq_mul]; field_simp + · intro j + calc + _ ≤ ∑ i : Fin n, 2*β^2/(n:ℝ) := Finset.sum_le_sum (fun i _ => hp i j) + _ = _ := by simp only [Finset.sum_const, Finset.card_univ, Fintype.card_fin, nsmul_eq_mul]; field_simp + rw [he, map_add] + exact (norm_add_le _ _).trans (add_le_add le_rfl hr) + +lemma normalizedInfluence_opNorm_tight (β : ℝ) : + Tendsto (fun n => disorderLaw β n {g | ∃ x : Spin n, + 2*(β^2+10)+2*β^2+1 < + ‖Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) (normalizedInfluence (sampledInteraction g) x)‖}) + atTop (nhds 0) := by + have hl := (RandomMatrix.sampled_opNorm_tendsto β).add + (normalizedInfluence_approx_tendsto β 1 (by norm_num)) + simp only [add_zero] at hl + apply tendsto_of_tendsto_of_tendsto_of_le_of_le' tendsto_const_nhds hl + (Eventually.of_forall (fun _ => bot_le)) + apply Eventually.of_forall + intro n + refine (measure_mono (show {g | ∃ x : Spin n, 2*(β^2+10)+2*β^2+1 < + ‖Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) (normalizedInfluence (sampledInteraction g) x)‖} ⊆ + {g | 2*(β^2+10) < ‖Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) (sampledInteraction g)‖} ∪ + {g | ∃ x : Spin n, 1 < ‖Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) + (normalizedInfluence (sampledInteraction g) x - normalizedInfluenceApprox β (sampledInteraction g) x)‖} + from ?_)).trans (measure_union_le _ _) + rintro g ⟨x,hx⟩ + by_cases hJ : 2*(β^2+10) < ‖Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) (sampledInteraction g)‖ + · exact Or.inl hJ + apply Or.inr + refine ⟨x,?_⟩ + have hh := normalizedInfluenceApprox_norm_le β (sampledInteraction g) x + have ht := norm_le_norm_sub_add + (Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) (normalizedInfluence (sampledInteraction g) x)) + (Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) (normalizedInfluenceApprox β (sampledInteraction g) x)) + rw [← map_sub] at ht + linarith [le_of_not_gt hJ] + +end SKGapCutoff + +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Set + +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Matrix/NormalizedPrimaryRecipe.lean b/lean/OAI/Probability/SKGap/Matrix/NormalizedPrimaryRecipe.lean new file mode 100644 index 0000000000000000000000000000000000000000..90a6c646dcf9364ed727d777939585c1323ee7ae --- /dev/null +++ b/lean/OAI/Probability/SKGap/Matrix/NormalizedPrimaryRecipe.lean @@ -0,0 +1,156 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.RecipeCoefficientClosure + +namespace OAI + +section + +noncomputable section +open scoped BigOperators Matrix.Norms.Frobenius +namespace SKGapCutoff.Recipe +open Primary +variable {n M : ℕ} {κ σ : Type*} [Fintype κ] [DecidableEq κ] +namespace OrdinaryData + +def normalizedPrimary (D : OrdinaryData n (Fin M) κ σ) (q : Fin M) : + OrdinaryData n (Fin M) κ Unit where + J:=D.J + j:=D.j + H:=D.H + predecessor:=D.predecessor + θ:=D.θ + seed:=fun _ _=>(Real.sqrt (n:ℝ))⁻¹ + seedFunction:=fun _ _ _ u=>Real.tanh (u (.inl q)) + seedDerivative:=fun _ _ _ u=>(1-(Real.tanh (u (.inl q)))^2) • ContinuousLinearMap.proj (.inl q) + auxFunction:=fun _ _ _ _=>0 + auxDerivative:=fun _ _ _ _=>0 + +lemma normalizedPrimary_source (D : OrdinaryData n (Fin M) κ σ) (q : Fin M) : + (D.normalizedPrimary q).source 0=fun x i=>Real.tanh (D.H q x i)/Real.sqrt (n:ℝ) := by + rw [source_eq] + ext x i + simp [sourceOf,normalizedPrimary,seedCoefficient,coefficient,localArgs,div_eq_mul_inv] + +lemma normalizedPrimary_magnetization (D : OrdinaryData n (Fin M) κ σ) (q : Fin M) + (j : ℝ) (J : Interaction n) (h : Fin n→ℝ) (k : ℕ) (hh : D.H q=fld j J h k) : + (D.normalizedPrimary q).source 0=fun x i=>mag j J h (k+1) x i/Real.sqrt (n:ℝ) := by + rw [normalizedPrimary_source,hh] + rfl + +lemma normalizedPrimary_Admissible (D : OrdinaryData n (Fin M) κ σ) (q : Fin M) + (p : ℕ) (hp : p≤q.val) (N : ℕ) : (D.normalizedPrimary q).Admissible N p := by + intro a ha l hl + have hne : l≠q := by intro he; subst l; omega + constructor + · intro s; ext x i + simp [seedPartial,localPartial,normalizedPrimary,partialAt,hne.symm] + · intro b; ext x i + simp [auxPartial,localPartial,normalizedPrimary,partialAt] + +lemma normalizedPrimary_seed (D : OrdinaryData n (Fin M) κ σ) (q : Fin M) (hn : 0Real.sqrt (n:ℝ)*siteMean U y) x)^2)≤C^2 := by + have H := (siteMean_derivative_square U x hn).trans + ((sq_le_sq₀ (norm_nonneg _) hC).2 ((Primary.opNorm_le_frobenius _).trans hU)) + have he (i : Fin n) : halfDiff i (fun y=>Real.sqrt (n:ℝ)*siteMean U y) x= + Real.sqrt (n:ℝ)*halfDiff i (siteMean U) x := by unfold halfDiff; ring + simp only [he,mul_pow,Real.sq_sqrt (Nat.cast_nonneg n),←Finset.mul_sum] + convert H using 1 + rw [EuclideanSpace.real_norm_sq_eq] + rfl + +end SKGapCutoff.Recipe + +end +end + +section + +noncomputable section +open scoped BigOperators +namespace SKGapCutoff.Recipe +variable {n : ℕ} {ι κ : Type*} [Fintype ι] [DecidableEq ι] [Fintype κ] [DecidableEq κ] + +omit [DecidableEq ι] [DecidableEq κ] in +lemma tanh_segmentRegular (H : ι→VectorFields n) (θ : κ→Spin n→ℝ) (x : Spin n) (q : ι) : + SegmentRegular H θ (fun _ u=>Real.tanh (u (.inl q))) + (fun _ u=>(1-(Real.tanh (u (.inl q)))^2) • ContinuousLinearMap.proj (.inl q)) x 2 := by + let L : Args (ι:=ι) (κ:=κ)→L[ℝ]ℝ:=ContinuousLinearMap.proj (.inl q) + have hL : ‖L‖≤1 := by + apply L.opNorm_le_bound (by norm_num) + intro u + exact (norm_le_pi_norm u (.inl q)).trans_eq (by rw [one_mul]) + refine ⟨by norm_num,?_,?_,?_⟩ + · intro i k t ht + exact (tanh_hasDerivAt _).comp_hasFDerivAt _ L.hasFDerivAt + · intro i k t ht + rw [norm_smul,Real.norm_eq_abs] + have hv : |1-(Real.tanh ((localArgs H θ x i+t • (localArgs H θ (flip x k) i-localArgs H θ x i)) (.inl q)))^2|≤1 := + (abs_of_pos (scalarVariance_pos _)).trans_le (scalarVariance_le_one _) + exact (mul_le_mul hv hL (norm_nonneg _) (by norm_num)).trans (by norm_num) + · intro i k t ht + let u:=localArgs H θ x i + let v:=localArgs H θ x i+t • (localArgs H θ (flip x k) i-localArgs H θ x i) + change ‖scalarVariance (v (.inl q)) • L-scalarVariance (u (.inl q)) • L‖≤_ + have he : scalarVariance (v (.inl q)) • L-scalarVariance (u (.inl q)) • L= + (scalarVariance (v (.inl q))-scalarVariance (u (.inl q))) • L := by module + rw [he,norm_smul,Real.norm_eq_abs] + have hv:=scalarVariance_lipschitz (u (.inl q)) (v (.inl q)) + have hu : |v (.inl q)-u (.inl q)|≤‖v-u‖ := norm_le_pi_norm (v-u) (.inl q) + calc + _ ≤ 2*|v (.inl q)-u (.inl q)| := (mul_le_mul hv hL (norm_nonneg _) (by positivity)).trans_eq (by ring) + _ ≤ 2*‖v-u‖ := mul_le_mul_of_nonneg_left hu (by norm_num) + _ = _ := by dsimp only [u,v]; rw [add_sub_cancel_left] + +omit [Fintype ι] [DecidableEq ι] [Fintype κ] [DecidableEq κ] in +lemma tanh_segmentValue (H : ι→VectorFields n) (θ : κ→Spin n→ℝ) (x : Spin n) (q : ι) : + SegmentValue H θ (fun _ u=>Real.tanh (u (.inl q))) x 2 := by + intro i k t ht + exact (Real.abs_tanh_lt_one _).le.trans (by norm_num) + +namespace OrdinaryData +variable {M : ℕ} {σ : Type*} +lemma normalizedPrimary_coefficientClass (D : OrdinaryData n (Fin M) κ σ) + (q : Fin M) (N : ℕ) (x : Spin n) : (D.normalizedPrimary q).CoefficientClass N x 2 := by + refine ⟨by norm_num,?_,?_,?_,?_⟩ + · intros + exact tanh_segmentRegular D.H D.θ x q + · intros + exact (segmentRegular_const D.H D.θ x 0).mono (by norm_num) + · intros + exact tanh_segmentValue D.H D.θ x q + · intro a ha b i k t ht + norm_num [normalizedPrimary] +end OrdinaryData +end SKGapCutoff.Recipe + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Matrix/NormalizedRecipeLaw.lean b/lean/OAI/Probability/SKGap/Matrix/NormalizedRecipeLaw.lean new file mode 100644 index 0000000000000000000000000000000000000000..66ae5aae370a097935fd399fc9407f935c6a781d --- /dev/null +++ b/lean/OAI/Probability/SKGap/Matrix/NormalizedRecipeLaw.lean @@ -0,0 +1,412 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.IntegrableResidualRecipeSq + +namespace OAI + +section +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open scoped BigOperators +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open scoped BigOperators +open scoped BigOperators NNReal ENNReal +open MeasureTheory Metric Set +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators NNReal ENNReal Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Set +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators ENNReal NNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Matrix +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators ENNReal NNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal +open scoped BigOperators +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise NNReal ENNReal +open scoped BigOperators +open Filter Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal Topology +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Set Matrix +open scoped BigOperators NNReal ENNReal Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +namespace SKGapCutoff.Regression + +local instance rawQueryMatrixMeasurable {n m : ℕ} : MeasurableSpace (Matrix (Fin n) (Fin m) ℝ) := + inferInstanceAs (MeasurableSpace (Fin n → Fin m → ℝ)) + +lemma sqrt_sum_smul_unitVector {n : ℕ} (v : Fin n → ℝ) : + Real.sqrt (∑ j, v j^2) • unitVector v = v := by + have hs : 0 ≤ ∑ j, v j^2 := Finset.sum_nonneg (fun _ _ => sq_nonneg _) + by_cases hz : ∑ j, v j^2=0 + · have hv : ∀ i, v i=0 := by + intro i + have hh : v i^2 ≤ ∑ j, v j^2 := Finset.single_le_sum + (fun j _ => sq_nonneg (v j)) (Finset.mem_univ i) + rw [hz] at hh + nlinarith [sq_nonneg (v i)] + ext i + simp only [Pi.smul_apply,smul_eq_mul,unitVector,hv,mul_zero,zero_div] + · ext i + change Real.sqrt (∑ j, v j^2)*(v i/Real.sqrt (∑ j, v j^2))=v i + exact mul_div_cancel₀ _ (ne_of_gt (Real.sqrt_pos.mpr (lt_of_le_of_ne hs (Ne.symm hz)))) + +lemma completedMatrix_scaled_input {n r : ℕ} (hn : 0 < n) + (U Y : Matrix (Fin n) (Fin r) ℝ) (hU : Uᵀ*U=1) (hY : Uᵀ*Y=Yᵀ*U) + (v : Fin n → ℝ) (z : (Fin n × Fin n) → ℝ) (i : Fin n) : + (completedMatrix U Y z *ᵥ v) i = + Real.sqrt ((∑ j, (residualProjection U *ᵥ v) j^2)/(n:ℝ))* + (Real.sqrt n*(completedMatrix U Y z *ᵥ unitVector (residualProjection U *ᵥ v)) i)+ + ∑ a, ((∑ j, Real.sqrt n*U j a*v j)/(n:ℝ))*(Real.sqrt n*Y i a) := by + have hn0 : (n:ℝ) ≠ 0 := Nat.cast_ne_zero.mpr (Nat.ne_of_gt hn) + have hsn : Real.sqrt (n:ℝ) ≠ 0 := ne_of_gt (Real.sqrt_pos.mpr (Nat.cast_pos.mpr hn)) + have hs : (Real.sqrt (n:ℝ))^2=n := Real.sq_sqrt (Nat.cast_nonneg _) + rw [completedMatrix_input_decomposition U Y hU hY v z] + simp only [Pi.add_apply] + have hp : (Y *ᵥ (Uᵀ *ᵥ v)) i = + ∑ a, ((∑ j, Real.sqrt n*U j a*v j)/(n:ℝ))*(Real.sqrt n*Y i a) := by + simp only [Matrix.mulVec,dotProduct,Matrix.transpose_apply] + apply Finset.sum_congr rfl + intro a _ + rw [Finset.sum_div,Finset.sum_mul,Finset.mul_sum] + apply Finset.sum_congr rfl + intro j _ + field_simp + nlinarith [congrArg (fun t : ℝ => t*(U j a*v j*Y i a)) hs] + rw [hp,add_comm] + congr 1 + conv_lhs => rw [← sqrt_sum_smul_unitVector (residualProjection U *ᵥ v)] + rw [Matrix.mulVec_smul] + simp only [Pi.smul_apply,smul_eq_mul] + rw [Real.sqrt_div (Finset.sum_nonneg (fun _ _ => sq_nonneg _))] + field_simp + +theorem ExponentialEmpiricalConcentration.unnormalized_query_assembly + {E : Type*} [PseudoMetricSpace E] [MeasurableSpace E] [BorelSpace E] + {H : ℕ → Type*} [∀ n, MeasurableSpace (H n)] + (ρ : ∀ n, Measure (H n)) [∀ n, IsProbabilityMeasure (ρ n)] + (X : ∀ n, H n → Fin n → E) + {r : ℕ} (U Y : ∀ n, H n → Matrix (Fin n) (Fin r) ℝ) + (u y : Fin r → E → ℝ) (g : E → ℝ) {K : ℝ≥0} (hK : 1 ≤ K) + (hy : ∀ a, LipschitzWith K (y a)) + (hyT : ∀ a, ExponentialSquareTails ρ (fun n h i => y a (X n h i))) + (heu : ∀ (n : ℕ) h i a, Real.sqrt n*U n h i a=u a (X n h i)) + (hey : ∀ (n : ℕ) h i a, Real.sqrt n*Y n h i a=y a (X n h i)) + (G : ∀ n, Set (H n)) (hrare : ExponentiallyRare ρ (fun n => (G n)ᶜ)) + (hgood : ∀ n h, h ∈ G n → (U n h)ᵀ*U n h=1 ∧ (U n h)ᵀ*Y n h=(Y n h)ᵀ*U n h) + (c : Fin r → ℝ) (s : ℝ) + (hC : ExponentialConvergence ρ + (fun n h a => (∑ i, u a (X n h i)*g (X n h i))/(n:ℝ)) c) + (hS : ExponentialConvergence ρ + (fun n h => (∑ i, (residualProjection (U n h) *ᵥ (fun j => g (X n h j))) i^2)/(n:ℝ)) s) + (ν : Measure ((E × ℝ) × ℝ)) [IsProbabilityMeasure ν] + (hX : ExponentialEmpiricalConcentration + (fun n => (ρ n).prod (standardArrayLaw (Fin n × Fin n))) + (fun n z i => ((X n z.1 i, Real.sqrt n* + unitVector (residualProjection (U n z.1) *ᵥ (fun j => g (X n z.1 j))) i), + Real.sqrt n*(completedMatrix (U n z.1) (Y n z.1) z.2 *ᵥ + unitVector (residualProjection (U n z.1) *ᵥ (fun j => g (X n z.1 j)))) i)) ν) + (hWT : ExponentialSquareTails + (fun n => (ρ n).prod (standardArrayLaw (Fin n × Fin n))) + (fun n z i => Real.sqrt n*(completedMatrix (U n z.1) (Y n z.1) z.2 *ᵥ + unitVector (residualProjection (U n z.1) *ᵥ (fun j => g (X n z.1 j)))) i)) + (hyi : ∀ a, Integrable (fun z => y a z.1.1^2) ν) + (hWi : Integrable (fun z => z.2^2) ν) : + ExponentialEmpiricalConcentration + (fun n => (ρ n).prod (standardArrayLaw (Fin n × Fin n))) + (fun n z i => (((X n z.1 i, Real.sqrt n* + unitVector (residualProjection (U n z.1) *ᵥ (fun j => g (X n z.1 j))) i), + Real.sqrt n*(completedMatrix (U n z.1) (Y n z.1) z.2 *ᵥ + unitVector (residualProjection (U n z.1) *ᵥ (fun j => g (X n z.1 j)))) i), + (completedMatrix (U n z.1) (Y n z.1) z.2 *ᵥ (fun j => g (X n z.1 j))) i)) + (ν.map (fun z => (z,Real.sqrt s*z.2+∑ a, c a*y a z.1.1))) ∧ + ExponentialSquareTails (fun n => (ρ n).prod (standardArrayLaw (Fin n × Fin n))) + (fun n z i => (completedMatrix (U n z.1) (Y n z.1) z.2 *ᵥ (fun j => g (X n z.1 j))) i) := by + let f : Option (Fin r) → ((E × ℝ) × ℝ) → ℝ := fun a => + a.elim Prod.snd (fun a z => y a z.1.1) + let C : ∀ n, H n → Option (Fin r) → ℝ := fun n h a => a.elim + (Real.sqrt ((∑ i, (residualProjection (U n h) *ᵥ (fun j => g (X n h j))) i^2)/(n:ℝ))) + (fun a => (∑ i, u a (X n h i)*g (X n h i))/(n:ℝ)) + let c' : Option (Fin r) → ℝ := fun a => a.elim (Real.sqrt s) c + have hcoef : ExponentialConvergence ρ C c' := by + apply ExponentialConvergence.pi_finite + intro a + cases a with + | none => exact hS.continuous_map Real.continuous_sqrt.continuousAt + | some a => exact hC.continuous_map (continuous_apply a).continuousAt + have hf : ∀ a, LipschitzWith K (f a) := by + intro a + cases a with + | none => exact LipschitzWith.prod_snd.weaken hK + | some a => + simpa only [f,Option.elim_some,Function.comp_def,mul_one] using + ((hy a).comp LipschitzWith.prod_fst).comp LipschitzWith.prod_fst + have ht := hX.append_unbounded_linear f hf + (fun a => by + cases a with + | none => exact hWT + | some a => exact (hyT a).prod_fst (fun n => standardArrayLaw (Fin n × Fin n))) + (fun a => by cases a with | none => exact hWi | some a => exact hyi a) + (fun n z => C n z.1) c' (hcoef.prod_fst (fun n => standardArrayLaw (Fin n × Fin n))) + simp only [f,C,c',Fintype.sum_option,Option.elim_none,Option.elim_some] at ht + have he : ∀ᶠ n in atTop, ∀ z : H n × ((Fin n × Fin n) → ℝ), z.1 ∈ G n → + ∀ i : Fin n, + Real.sqrt ((∑ j, (residualProjection (U n z.1) *ᵥ (fun k => g (X n z.1 k))) j^2)/(n:ℝ))* + (Real.sqrt n*(completedMatrix (U n z.1) (Y n z.1) z.2 *ᵥ + unitVector (residualProjection (U n z.1) *ᵥ (fun k => g (X n z.1 k)))) i)+ + ∑ a, ((∑ j, u a (X n z.1 j)*g (X n z.1 j))/(n:ℝ))*y a (X n z.1 i) = + (completedMatrix (U n z.1) (Y n z.1) z.2 *ᵥ (fun j => g (X n z.1 j))) i := by + filter_upwards [eventually_ge_atTop 1] with n hn + intro z hz i + have h := completedMatrix_scaled_input hn (U n z.1) (Y n z.1) + (hgood n z.1 hz).1 (hgood n z.1 hz).2 (fun j => g (X n z.1 j)) z.2 i + simpa only [heu,hey] using h.symm + have hr := hrare.prod_fst (fun n => standardArrayLaw (Fin n × Fin n)) + constructor + · apply ht.1.congr_on_good (fun n => Prod.fst ⁻¹' G n) hr + filter_upwards [he] with n hn + intro z hz + funext i + congr 1 + exact (hn z hz i).symm + · apply ht.2.congr_on_good (fun n => Prod.fst ⁻¹' G n) hr + filter_upwards [he] with n hn + intro z hz + funext i + exact (hn z hz i).symm + +noncomputable def normalizedRecipeLaw {E : Type*} [MeasurableSpace E] + {r : ℕ} (ν : Measure E) (u y : Fin r → E → ℝ) (g : E → ℝ) : + Measure ((E × ℝ) × ℝ) := + let c := fun a => ∫ x, u a x*g x ∂ν + let s := ∫ x, residualRecipe u g c x^2 ∂ν + let μ := ν.map (fun x => (x,residualRecipe u g c x/Real.sqrt s)) + (μ.prod (gaussianReal 0 1)).map + (fun z => (z.1,z.2+∑ a, (∫ x, y a x.1*x.2 ∂μ)*u a z.1.1)) + +lemma normalizedRecipeLaw_probability {E : Type*} [PseudoMetricSpace E] + [MeasurableSpace E] [BorelSpace E] [SecondCountableTopology E] + {r : ℕ} (ν : Measure E) [IsProbabilityMeasure ν] + (u y : Fin r → E → ℝ) (g : E → ℝ) + (hu : ∀ a, Measurable (u a)) (hg : Measurable g) : + IsProbabilityMeasure (normalizedRecipeLaw ν u y g) := by + unfold normalizedRecipeLaw + have hm : Measurable (fun x => (x,residualRecipe u g (fun a => ∫ x, u a x*g x ∂ν) x / + Real.sqrt (∫ x, residualRecipe u g (fun a => ∫ x, u a x*g x ∂ν) x^2 ∂ν))) := by + unfold residualRecipe + exact measurable_id.prodMk ((hg.sub (Finset.measurable_sum _ + (fun a _ => (hu a).const_mul _))).div_const _) + let := (Measure.isProbabilityMeasure_map_iff (μ := ν) hm.aemeasurable).2 inferInstance + refine (Measure.isProbabilityMeasure_map_iff ?_).2 inferInstance + apply Measurable.aemeasurable + refine measurable_fst.prodMk (measurable_snd.add ?_) + exact Finset.measurable_sum _ (fun a _ => + ((hu a).comp (measurable_fst.comp measurable_fst)).const_mul _) + +lemma normalizedRecipeLaw_moments {E : Type*} [PseudoMetricSpace E] + [MeasurableSpace E] [BorelSpace E] [SecondCountableTopology E] + {r : ℕ} (ν : Measure E) [IsProbabilityMeasure ν] + (u y : Fin r → E → ℝ) (g : E → ℝ) + (hu : ∀ a, Measurable (u a)) (hy : ∀ a, Measurable (y a)) (hg : Measurable g) + (hui : ∀ a, Integrable (fun x => u a x^2) ν) + (hyi : ∀ a, Integrable (fun x => y a x^2) ν) + (hgi : Integrable (fun x => g x^2) ν) : + (∀ a, Integrable (fun z => u a z.1.1^2) (normalizedRecipeLaw ν u y g)) ∧ + (∀ a, Integrable (fun z => y a z.1.1^2) (normalizedRecipeLaw ν u y g)) ∧ + Integrable (fun z => z.1.2^2) (normalizedRecipeLaw ν u y g) ∧ + Integrable (fun z => z.2^2) (normalizedRecipeLaw ν u y g) := by + let c := fun a => ∫ x, u a x*g x ∂ν + let s := ∫ x, residualRecipe u g c x^2 ∂ν + let φ := fun x => (x,residualRecipe u g c x/Real.sqrt s) + let μ := ν.map φ + let b := fun a => ∫ x, y a x.1*x.2 ∂μ + let T := fun z : (E × ℝ) × ℝ => (z.1,z.2+∑ a, b a*u a z.1.1) + have hφ : Measurable φ := by + exact measurable_id.prodMk ((hg.sub (Finset.measurable_sum _ + (fun a _ => (hu a).const_mul _))).div_const _) + let : IsProbabilityMeasure μ := inferInstance + have hTm : Measurable T := measurable_fst.prodMk (measurable_snd.add + (Finset.measurable_sum _ (fun a _ => + ((hu a).comp (measurable_fst.comp measurable_fst)).const_mul _))) + have hu' a : Integrable (fun x : E × ℝ => u a x.1^2) μ := by + apply (integrable_map_measure (((hu a).comp measurable_fst).pow_const 2).aestronglyMeasurable hφ.aemeasurable).2 + exact hui a + have hy' a : Integrable (fun x : E × ℝ => y a x.1^2) μ := by + apply (integrable_map_measure (((hy a).comp measurable_fst).pow_const 2).aestronglyMeasurable hφ.aemeasurable).2 + exact hyi a + have hq : Integrable (fun x : E × ℝ => x.2^2) μ := by + rw [integrable_map_measure (by fun_prop) hφ.aemeasurable] + simp only [φ,Function.comp_def,div_pow] + exact (integrable_residualRecipe_sq u g c (fun a => (hu a).aestronglyMeasurable) + hg.aestronglyMeasurable hui hgi).div_const _ + change (∀ a, Integrable (fun z => u a z.1.1^2) ((μ.prod (gaussianReal 0 1)).map T)) ∧ + (∀ a, Integrable (fun z => y a z.1.1^2) ((μ.prod (gaussianReal 0 1)).map T)) ∧ + Integrable (fun z => z.1.2^2) ((μ.prod (gaussianReal 0 1)).map T) ∧ + Integrable (fun z => z.2^2) ((μ.prod (gaussianReal 0 1)).map T) + refine ⟨?_,?_,?_,?_⟩ + · intro a + apply (integrable_map_measure (((hu a).comp (measurable_fst.comp measurable_fst)).pow_const 2).aestronglyMeasurable hTm.aemeasurable).2 + exact (hu' a).comp_fst (gaussianReal 0 1) + · intro a + apply (integrable_map_measure (((hy a).comp (measurable_fst.comp measurable_fst)).pow_const 2).aestronglyMeasurable hTm.aemeasurable).2 + exact (hy' a).comp_fst (gaussianReal 0 1) + · rw [integrable_map_measure (by fun_prop) hTm.aemeasurable] + exact hq.comp_fst (gaussianReal 0 1) + · rw [integrable_map_measure (by fun_prop) hTm.aemeasurable] + have hi := integrable_linear_combination_sq (ν := μ.prod (gaussianReal 0 1)) + (fun a : Option (Fin r) => a.elim (fun z : (E × ℝ) × ℝ => z.2) (fun a z => u a z.1.1)) + (fun a => a.elim 1 b) + (fun a => by + cases a with + | none => exact measurable_snd.aestronglyMeasurable + | some a => exact ((hu a).comp (measurable_fst.comp measurable_fst)).aestronglyMeasurable) + (fun a => by + cases a with + | none => exact (memLp_id_gaussianReal (μ := 0) (v := 1) 2).integrable_sq.comp_snd μ + | some a => exact (hu' a).comp_fst (gaussianReal 0 1)) + simpa only [T,Function.comp_def,Fintype.sum_option,Option.elim_none,Option.elim_some,one_mul] using hi + +theorem ExponentialEmpiricalConcentration.nondegenerate_full_query + {E : Type*} [PseudoMetricSpace E] [MeasurableSpace E] [BorelSpace E] + [SecondCountableTopology E] + {H : ℕ → Type*} [∀ n, MeasurableSpace (H n)] + (ρ : ∀ n, Measure (H n)) [∀ n, IsProbabilityMeasure (ρ n)] + (ν : Measure E) [IsProbabilityMeasure ν] + (X : ∀ n, H n → Fin n → E) (hXm : ∀ n, Measurable (X n)) + (hX : ExponentialEmpiricalConcentration ρ X ν) + (r : ℕ) (U Y : ∀ n, H n → Matrix (Fin n) (Fin r) ℝ) + (hUm : ∀ n, Measurable (U n)) + (hU : ∀ n h a, ∑ i, U n h i a^2 ≤ 1) + (G : ∀ n, Set (H n)) (hG : ∀ n, MeasurableSet (G n)) + (hrare : ExponentiallyRare ρ (fun n => (G n)ᶜ)) + (hgood : ∀ n h, h ∈ G n → (U n h)ᵀ*U n h=1 ∧ (U n h)ᵀ*Y n h=(Y n h)ᵀ*U n h) + (u y : Fin r → E → ℝ) (g : E → ℝ) {K : ℝ≥0} (hK : 1 ≤ K) + (hu : ∀ a, LipschitzWith K (u a)) (hy : ∀ a, LipschitzWith K (y a)) + (hg : LipschitzWith K g) + (huT : ∀ a, ExponentialSquareTails ρ (fun n h i => u a (X n h i))) + (hyT : ∀ a, ExponentialSquareTails ρ (fun n h i => y a (X n h i))) + (hgT : ExponentialSquareTails ρ (fun n h i => g (X n h i))) + (hui : ∀ a, Integrable (fun x => u a x^2) ν) + (hyi : ∀ a, Integrable (fun x => y a x^2) ν) (hgi : Integrable (fun x => g x^2) ν) + (heu : ∀ (n : ℕ) h i a, Real.sqrt n*U n h i a=u a (X n h i)) + (hey : ∀ (n : ℕ) h i a, Real.sqrt n*Y n h i a=y a (X n h i)) + (hs : 0 < ∫ x, residualRecipe u g (fun a => ∫ z, u a z*g z ∂ν) x^2 ∂ν) : + + let R := fun n h => residualProjection (U n h) *ᵥ (fun i => g (X n h i)) + let q := fun n h => unitVector (R n h) + let c := fun a => ∫ x, u a x*g x ∂ν + let s := ∫ x, residualRecipe u g c x^2 ∂ν + let W := fun n (z : H n × ((Fin n × Fin n) → ℝ)) i => + Real.sqrt n*(completedMatrix (U n z.1) (Y n z.1) z.2 *ᵥ q n z.1) i + ExponentialConvergence ρ (fun n h => (∑ i, R n h i^2)/(n:ℝ)) s ∧ + ExponentialEmpiricalConcentration + (fun n => (ρ n).prod (standardArrayLaw (Fin n × Fin n))) + (fun n z i => (((X n z.1 i,Real.sqrt n*q n z.1 i),W n z i), + (completedMatrix (U n z.1) (Y n z.1) z.2 *ᵥ (fun j => g (X n z.1 j))) i)) + ((normalizedRecipeLaw ν u y g).map (fun z => (z, Real.sqrt s*z.2+∑ a, c a*y a z.1.1))) ∧ + ExponentialSquareTails ρ (fun n h i => Real.sqrt n*q n h i) ∧ + ExponentialSquareTails (fun n => (ρ n).prod (standardArrayLaw (Fin n × Fin n))) W ∧ + ExponentialSquareTails (fun n => (ρ n).prod (standardArrayLaw (Fin n × Fin n))) + (fun n z i => (completedMatrix (U n z.1) (Y n z.1) z.2 *ᵥ (fun j => g (X n z.1 j))) i) := by + dsimp only + have h := hX.nondegenerate_query_step ρ ν X hXm r U Y hUm hU G hG hrare + (fun n h hh => (hgood n h hh).1) u y g hK hu hy hg huT hyT hgT hui hyi hgi heu hey hs + dsimp only at h + let : IsProbabilityMeasure (normalizedRecipeLaw ν u y g) := + normalizedRecipeLaw_probability ν u y g (fun a => (hu a).continuous.measurable) hg.continuous.measurable + have hm := normalizedRecipeLaw_moments ν u y g + (fun a => (hu a).continuous.measurable) (fun a => (hy a).continuous.measurable) + hg.continuous.measurable hui hyi hgi + have hC : ExponentialConvergence ρ + (fun n h a => (∑ i, u a (X n h i)*g (X n h i))/(n:ℝ)) + (fun a => ∫ x, u a x*g x ∂ν) := by + apply ExponentialConvergence.pi_finite + intro a + exact hX.product_average (u a) g (hu a) hg (huT a) hgT (hui a) hgi + have hh := h.2.1.unnormalized_query_assembly ρ X U Y u y g hK hy hyT heu hey G hrare + hgood (fun a => ∫ x, u a x*g x ∂ν) + (∫ x, residualRecipe u g (fun a => ∫ z, u a z*g z ∂ν) x^2 ∂ν) + hC h.1 (normalizedRecipeLaw ν u y g) h.2.2.2 hm.2.1 hm.2.2.2 + exact ⟨h.1,hh.1,h.2.2.1,h.2.2.2,hh.2⟩ + +end SKGapCutoff.Regression + +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise + +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Matrix/OpNorm.lean b/lean/OAI/Probability/SKGap/Matrix/OpNorm.lean new file mode 100644 index 0000000000000000000000000000000000000000..8c1809f45df9f4d7d31e181b751bcee47a514a13 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Matrix/OpNorm.lean @@ -0,0 +1,127 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.SymmetricElementaryComm + +namespace OAI + +noncomputable section + +open MeasureTheory ProbabilityTheory InformationTheory Real Set +open scoped NNReal ENNReal +open Filter +open scoped Topology +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius ENNReal NNReal +namespace SKGap +open MeasureTheory ProbabilityTheory Matrix +open scoped BigOperators Matrix.Norms.Frobenius +variable {ι : Type*} [Fintype ι] [DecidableEq ι] + +lemma mul_symmetricElementary_mul (P Q : Matrix ι ι ℝ) (a b i k : ι) : + (P*symmetricElementary a b*Q) i k = P i a*Q b k+P i b*Q a k := by + simp [symmetricElementary,Matrix.mul_add, + Matrix.mul_apply,Matrix.single_apply,ite_and,add_mul,Finset.sum_add_distrib,ite_mul] + +lemma goe_inverse_contraction (K B : Matrix ι ι ℝ) (i : ι) : + (∑ b, (K*B*symmetricElementary i b*K) b i) = + (Matrix.trace (K*B))*K i i+∑ b, (K*B) b i*K b i := by + simp_rw [mul_symmetricElementary_mul] + rw [Finset.sum_add_distrib,← Finset.sum_mul,Matrix.trace] + exact add_comm _ _ + +def opNorm (M : Matrix ι ι ℝ) : ℝ := ‖M.toEuclideanLin.toContinuousLinearMap‖ +def colVec (M : Matrix ι ι ℝ) (k : ι) : EuclideanSpace ℝ ι := WithLp.toLp 2 (fun i => M i k) + +lemma colVec_eq (M : Matrix ι ι ℝ) (k : ι) : + colVec M k = M.toEuclideanLin.toContinuousLinearMap (EuclideanSpace.single k (1:ℝ)) := by + ext i + simp [colVec,Matrix.toLpLin_apply] + +lemma colVec_norm_le (M : Matrix ι ι ℝ) (k : ι) : ‖colVec M k‖ ≤ opNorm M := by + rw [colVec_eq] + simpa only [PiLp.norm_single,norm_one,mul_one,opNorm] using! + M.toEuclideanLin.toContinuousLinearMap.le_opNorm (EuclideanSpace.single k (1:ℝ)) + +lemma matrix_entry_le_opNorm (M : Matrix ι ι ℝ) (i k : ι) : |M i k| ≤ opNorm M := by + have h : |M i k| ≤ ‖colVec M k‖ := by + simpa only [colVec,Real.norm_eq_abs] using (PiLp.norm_apply_le (colVec M k) i) + exact h.trans (colVec_norm_le M k) + +lemma opNorm_mul (M N : Matrix ι ι ℝ) : opNorm (M*N) ≤ opNorm M*opNorm N := by + have he : (M*N).toEuclideanLin.toContinuousLinearMap = + M.toEuclideanLin.toContinuousLinearMap * N.toEuclideanLin.toContinuousLinearMap := by + ext x i + exact congrFun (congrArg (fun T : EuclideanSpace ℝ ι →ₗ[ℝ] EuclideanSpace ℝ ι => (T x).ofLp) + (Matrix.toLpLin_mul 2 2 2 M N)) i + exact (congrArg norm he).le.trans (norm_mul_le _ _) + +lemma goe_cross_contraction_bound (K B : Matrix ι ι ℝ) (i : ι) : + |∑ b, (K*B) b i*K b i| ≤ opNorm K*opNorm B*opNorm K := by + have hh := abs_real_inner_le_norm (colVec (K*B) i) (colVec K i) + change |∑ b, K b i*(K*B) b i| ≤ _ at hh + simp_rw [mul_comm (K _ _)] at hh + apply hh.trans + calc + ‖colVec (K*B) i‖*‖colVec K i‖ ≤ opNorm (K*B)*opNorm K := + mul_le_mul (colVec_norm_le _ _) (colVec_norm_le _ _) (norm_nonneg _) (norm_nonneg _) + _ ≤ _ := mul_le_mul_of_nonneg_right (opNorm_mul _ _) (norm_nonneg _) + +lemma trace_mul_diagonal (K : Matrix ι ι ℝ) (a : ι → ℝ) : + Matrix.trace (K*Matrix.diagonal a) = ∑ i, a i*K i i := by + simp [Matrix.trace,Matrix.mul_diagonal,mul_comm] + +theorem goe_inverse_loop_raw {r : ℝ} (hr : 0 ≤ r) (B : Matrix ι ι ℝ) (i : ι) + {K : Matrix ι ι ℝ → Matrix ι ι ℝ} {L : ℝ≥0} {C D : ℝ} + {s : Set (MatrixCoordinates ι → ℝ)} + (hf : ∀ a b, LipschitzWith L (fun g => K (goeMatrix r g) a b)) + (hC : ∀ g a b, ‖K (goeMatrix r g) a b‖ ≤ C) + (hD : ∀ g b, ‖(K (goeMatrix r g)*B*symmetricElementary i b*K (goeMatrix r g)) b i‖ ≤ D) + (hs : MeasurableSet s) + (hder : ∀ g ∈ s, ∀ b, HasDerivAt + (fun t : ℝ => K (goeMatrix r g+t • symmetricElementary i b) b i) + ((K (goeMatrix r g)*B*symmetricElementary i b*K (goeMatrix r g)) b i) 0) : + |(∫ g, (goeMatrix r g*K (goeMatrix r g)) i i + ∂Measure.pi (fun _ : MatrixCoordinates ι => gaussianReal 0 1)) - + r*(∫ g, Matrix.trace (K (goeMatrix r g)*B)*K (goeMatrix r g) i i+ + ∑ b, (K (goeMatrix r g)*B) b i*K (goeMatrix r g) b i + ∂Measure.pi (fun _ : MatrixCoordinates ι => gaussianReal 0 1))| ≤ + (Fintype.card ι:ℝ)*(sqrt (2*r)*(L:ℝ)+r*D)* + (Measure.pi (fun _ : MatrixCoordinates ι => gaussianReal 0 1)).real sᶜ := by + let μ := Measure.pi (fun _ : MatrixCoordinates ι => gaussianReal 0 1) + let d (b : ι) (g : MatrixCoordinates ι → ℝ) := + (K (goeMatrix r g)*B*symmetricElementary i b*K (goeMatrix r g)) b i + have hK : Continuous (fun g => K (goeMatrix r g)) := + continuous_pi (fun a => continuous_pi (fun b => (hf a b).continuous)) + have hd (b : ι) : Continuous (d b) := by + exact ((hK.mul continuous_const).mul continuous_const |>.mul hK).matrix_elem b i + have hdint (b : ι) : Integrable (d b) μ := + Integrable.mono' (integrable_const D) (hd b).aestronglyMeasurable (ae_of_all _ (fun g => hD g b)) + have hwint (b : ι) : Integrable (fun g => goeMatrix r g i b*K (goeMatrix r g) b i) μ := by + have he (a : MatrixCoordinates ι) : Integrable (fun g : MatrixCoordinates ι → ℝ => g a) μ := + integrable_eval (i := a) IsGaussian.integrable_id + have hw : Integrable (fun g => goeMatrix r g i b) μ := + ((he (.inl (i,b))).add (he (.inl (b,i)))).const_mul _ + simpa only [mul_comm] using hw.bdd_mul (hf b i).continuous.aestronglyMeasurable + (ae_of_all _ (fun g => hC g b i)) + have hb (b : ι) := goe_IBP_error hr i b (H := fun M => K M b i) (d := d b) (hf b i) (fun g => hC g b i) + (hd b).measurable (fun g => hD g b) hs (fun g hg => hder g hg b) + have he : (∫ g, Matrix.trace (K (goeMatrix r g)*B)*K (goeMatrix r g) i i+ + ∑ b, (K (goeMatrix r g)*B) b i*K (goeMatrix r g) b i ∂μ) = + ∑ b, ∫ g, d b g ∂μ := by + simp_rw [← goe_inverse_contraction] + exact integral_finsetSum Finset.univ (fun b _ => hdint b) + change |(∫ g, (goeMatrix r g*K (goeMatrix r g)) i i ∂μ)-r*(_)| ≤ _ + rw [he] + simp_rw [Matrix.mul_apply] + rw [integral_finsetSum Finset.univ (fun b _ => hwint b),Finset.mul_sum,← Finset.sum_sub_distrib] + calc + _ ≤ ∑ b, |(∫ g, goeMatrix r g i b*K (goeMatrix r g) b i ∂μ)-r*(∫ g, d b g ∂μ)| := + Finset.abs_sum_le_sum_abs _ _ + _ ≤ ∑ _b : ι, (sqrt (2*r)*(L:ℝ)+r*D)*μ.real sᶜ := + Finset.sum_le_sum (fun b _ => hb b) + _ = _ := by simp only [Finset.sum_const,Finset.card_univ,nsmul_eq_mul]; ring + +end SKGap + +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Matrix/OpNormDiagonal.lean b/lean/OAI/Probability/SKGap/Matrix/OpNormDiagonal.lean new file mode 100644 index 0000000000000000000000000000000000000000..3aff73b1357045bda5b5767d5a754a7a1eb4a3e9 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Matrix/OpNormDiagonal.lean @@ -0,0 +1,115 @@ +import Mathlib +import OAI.Probability.SKGap.Matrix.OpNorm + +namespace OAI + +section +noncomputable section +open MeasureTheory ProbabilityTheory InformationTheory Real Set +open scoped NNReal ENNReal +open Filter +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius ENNReal NNReal +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius NNReal +noncomputable section +open MeasureTheory ProbabilityTheory Real Set Filter +open MeasureTheory.Measure +open scoped ENNReal NNReal MeasureTheory Topology +open MeasureTheory +noncomputable section +noncomputable section +open MeasureTheory Set NormedSpace +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius +noncomputable section +open Set Real +open scoped Topology +noncomputable section +open Matrix Set Filter +open scoped Topology Matrix.Norms.Frobenius +noncomputable section +open Matrix NormedSpace ContinuousLinearMap +open scoped Matrix.Norms.Frobenius +noncomputable section +open Matrix +noncomputable section +open MeasureTheory ProbabilityTheory Real Set +open scoped ENNReal NNReal +noncomputable section +open MeasureTheory ProbabilityTheory InformationTheory Real Set +open scoped NNReal ENNReal +noncomputable section +open scoped BigOperators +open MeasureTheory ProbabilityTheory +open Real +noncomputable section +open scoped BigOperators Topology +open Filter Real +namespace SKGap +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius +variable {ι : Type*} [Fintype ι] [DecidableEq ι] + +lemma opNorm_diagonal_eq (d : ι → ℝ) : opNorm (diagonal d) = ‖d‖ := + Matrix.l2_opNorm_diagonal d + +lemma opNorm_diagonal_le {d : ι → ℝ} {C : ℝ} (hC : 0 ≤ C) (hd : ∀ i, |d i| ≤ C) : + opNorm (diagonal d) ≤ C := by + rw [opNorm_diagonal_eq] + exact (pi_norm_le_iff_of_nonneg hC).mpr (fun i => by simpa only [Real.norm_eq_abs] using hd i) + +lemma opNorm_one_le : opNorm (1 : Matrix ι ι ℝ) ≤ 1 := by + change ‖Matrix.toEuclideanCLM (n := ι) (𝕜 := ℝ) (1 : Matrix ι ι ℝ)‖ ≤ _ + rw [map_one] + exact ContinuousLinearMap.norm_id_le + +lemma opNorm_sub (M N : Matrix ι ι ℝ) : opNorm (M-N) ≤ opNorm M+opNorm N := by + change ‖Matrix.toEuclideanCLM (n := ι) (𝕜 := ℝ) (M-N)‖ ≤ _ + rw [map_sub] + exact norm_sub_le _ _ + +lemma real_sandwich_opNorm (D V : Matrix ι ι ℝ) : + opNorm (D*V*D) ≤ opNorm D^2*opNorm V := by + change ‖Matrix.toEuclideanCLM (n := ι) (𝕜 := ℝ) (D*V*D)‖ ≤ + ‖Matrix.toEuclideanCLM (n := ι) (𝕜 := ℝ) D‖^2*‖Matrix.toEuclideanCLM (n := ι) (𝕜 := ℝ) V‖ + simp only [map_mul] + have h := (norm_mul_le (Matrix.toEuclideanCLM (n := ι) (𝕜 := ℝ) D*Matrix.toEuclideanCLM (n := ι) (𝕜 := ℝ) V) + (Matrix.toEuclideanCLM (n := ι) (𝕜 := ℝ) D)).trans + (mul_le_mul_of_nonneg_right (norm_mul_le (Matrix.toEuclideanCLM (n := ι) (𝕜 := ℝ) D) (Matrix.toEuclideanCLM (n := ι) (𝕜 := ℝ) V)) + (norm_nonneg _)) + exact h.trans_eq (by ring) + +lemma real_sandwich_stability_norm (D C M : Matrix ι ι ℝ) : + opNorm (1-D*(M-C)*D) ≤ 1+opNorm D^2*(opNorm M+opNorm C) := by + calc + _ ≤ opNorm (1 : Matrix ι ι ℝ)+opNorm (D*(M-C)*D) := opNorm_sub _ _ + _ ≤ 1+opNorm D^2*(opNorm M+opNorm C) := + add_le_add opNorm_one_le ((real_sandwich_opNorm _ _).trans + (mul_le_mul_of_nonneg_left (opNorm_sub _ _) (sq_nonneg _))) + +end SKGap + +end +end +end +end +end +end +end +end +end +end +end +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Matrix/OpNormKernelMatrixSub.lean b/lean/OAI/Probability/SKGap/Matrix/OpNormKernelMatrixSub.lean new file mode 100644 index 0000000000000000000000000000000000000000..ba66caa175bc9fa24aaf0f898f54ebdcebea7e1c --- /dev/null +++ b/lean/OAI/Probability/SKGap/Matrix/OpNormKernelMatrixSub.lean @@ -0,0 +1,166 @@ +import Mathlib +import OAI.Probability.SKGap.Gaussian.FourierMoment + +namespace OAI + +noncomputable section + +open MeasureTheory ProbabilityTheory InformationTheory Real Set +open scoped NNReal ENNReal +open Filter +open scoped Topology +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius ENNReal NNReal +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius NNReal +open MeasureTheory ProbabilityTheory Real Set Filter +open MeasureTheory.Measure +open scoped ENNReal NNReal MeasureTheory Topology +open MeasureTheory +open MeasureTheory Set NormedSpace +open scoped Topology +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius +namespace SKGap.ComplexMatrix + +section +open MeasureTheory NormedSpace +open scoped FourierTransform SchwartzMap +variable {ι : Type*} [Fintype ι] [DecidableEq ι] + +local instance : ContinuousENorm (Matrix ι ι ℂ) := + @SeminormedAddGroup.toContinuousENorm _ Matrix.frobeniusSeminormedAddCommGroup.toSeminormedAddGroup +local instance : TopologicalSpace.PseudoMetrizableSpace (Matrix ι ι ℂ) := + inferInstanceAs (TopologicalSpace.PseudoMetrizableSpace (ι → ι → ℂ)) + +lemma opNorm_kernelMatrix_sub {g : ℝ → ℂ} (hg : Integrable g) + (hg₁ : Integrable (fun t : ℝ => ‖g t‖*|t|)) + (M N : Matrix ι ι ℂ) (hM : Mᴴ = M) (hN : Nᴴ = N) : + opNorm (kernelMatrix g M-kernelMatrix g N) ≤ + (∫ t : ℝ, ‖g t‖*|t|)*opNorm (M-N) := by + let F := fun t : ℝ => g t • exp (imaginary t M)-g t • exp (imaginary t N) + have hi : Integrable F := (kernel_integrable hg M hM).sub (kernel_integrable hg N hN) + let : CompleteSpace (EuclideanSpace ℂ ι →L[ℂ] EuclideanSpace ℂ ι) := + ContinuousLinearMap.instCompleteSpace + have hh := linCLM.integral_comp_comm hi + have he : kernelMatrix g M-kernelMatrix g N = ∫ t : ℝ, F t := by + exact (integral_sub (kernel_integrable hg M hM) (kernel_integrable hg N hN)).symm + rw [he] + change ‖linCLM (∫ t : ℝ, F t)‖ ≤ _ + calc + _ = ‖∫ t : ℝ, linCLM (F t)‖ := congrArg norm hh.symm + _ ≤ ∫ t : ℝ, ‖linCLM (F t)‖ := norm_integral_le_integral_norm _ + _ ≤ ∫ t : ℝ, (‖g t‖*|t|)*opNorm (M-N) := by + apply integral_mono (linCLM.integrable_comp hi).norm (hg₁.mul_const _) + intro t + have hb := opNorm_exp_sub (imaginary t M) (imaginary t N) (imaginary_skew t M hM) (imaginary_skew t N hN) + rw [← imaginary_sub,imaginary_opNorm] at hb + change opNorm (F t) ≤ _ + dsimp only [F] + rw [← smul_sub,opNorm_csmul] + exact (mul_le_mul_of_nonneg_left hb (norm_nonneg _)).trans_eq (by ring) + _ = _ := integral_mul_const _ _ + +lemma schwartzMatrix_opNorm_lipschitz (f : 𝓢(ℝ,ℂ)) (M N : Matrix ι ι ℂ) + (hM : Mᴴ = M) (hN : Nᴴ = N) : + opNorm (schwartzMatrix f M-schwartzMatrix f N) ≤ + (2*Real.pi*fourierMoment f 1)*opNorm (M-N) := by + have hf₁ : Integrable (fun t : ℝ => ‖(𝓕 f) t‖*|t|) := by + simpa only [pow_one] using fourierMoment_integrable f 1 + have hh := opNorm_kernelMatrix_sub (𝓕 f).integrable hf₁ + ((2*Real.pi:ℝ) • M) ((2*Real.pi:ℝ) • N) (by simp [hM]) (by simp [hN]) + rw [← smul_sub,opNorm_smul,abs_of_pos (by positivity : 0 < (2*Real.pi:ℝ))] at hh + exact hh.trans_eq (by simp only [fourierMoment,pow_one]; ring) + +end + +variable {ι : Type*} [Fintype ι] [DecidableEq ι] + +lemma opNorm_nonneg (M : Matrix ι ι ℂ) : 0 ≤ opNorm M := norm_nonneg _ +lemma opNorm_add (M N : Matrix ι ι ℂ) : opNorm (M+N) ≤ opNorm M+opNorm N := by + change ‖linEquiv (M+N)‖ ≤ _ + rw [(linEquiv (ι := ι)).map_add] + exact norm_add_le _ _ +lemma opNorm_sub (M N : Matrix ι ι ℂ) : opNorm (M-N) ≤ opNorm M+opNorm N := by + change ‖lin (M-N)‖ ≤ _ + have hh : lin (M-N) = lin M-lin N := linEquiv.map_sub M N + rw [hh] + exact norm_sub_le _ _ +lemma opNorm_mul (M N : Matrix ι ι ℂ) : opNorm (M*N) ≤ opNorm M*opNorm N := by + change ‖lin (M*N)‖ ≤ _ + rw [lin_mul] + exact norm_mul_le _ _ +lemma opNorm_neg (M : Matrix ι ι ℂ) : opNorm (-M) = opNorm M := by + change ‖lin (-M)‖ = _ + have hh : lin (-M) = -lin M := linEquiv.map_neg M + rw [hh,norm_neg] + rfl +lemma opNorm_one_le : opNorm (1 : Matrix ι ι ℂ) ≤ 1 := by + rw [opNorm,lin_one] + exact ContinuousLinearMap.norm_id_le + +lemma sandwich_frobenius (D E : Matrix ι ι ℂ) : + ‖D*E*D‖ ≤ opNorm D^2*‖E‖ := by + calc + _ ≤ ‖D*E‖*opNorm D := frobenius_mul_le_opNorm_right _ _ + _ ≤ (opNorm D*‖E‖)*opNorm D := mul_le_mul_of_nonneg_right (frobenius_mul_le_opNorm _ _) (opNorm_nonneg _) + _ = _ := by ring + +lemma sandwich_opNorm (D E : Matrix ι ι ℂ) : + opNorm (D*E*D) ≤ opNorm D^2*opNorm E := by + calc + _ ≤ opNorm (D*E)*opNorm D := opNorm_mul _ _ + _ ≤ (opNorm D*opNorm E)*opNorm D := mul_le_mul_of_nonneg_right (opNorm_mul _ _) (opNorm_nonneg _) + _ = _ := by ring + +lemma sandwich_difference_frobenius (D D' E : Matrix ι ι ℂ) : + ‖D*E*D-D'*E*D'‖ ≤ (opNorm D+opNorm D')*opNorm (D-D')*‖E‖ := by + have he : D*E*D-D'*E*D' = (D-D')*E*D+D'*E*(D-D') := by noncomm_ring + rw [he] + calc + _ ≤ ‖(D-D')*E*D‖+‖D'*E*(D-D')‖ := norm_add_le _ _ + _ ≤ (opNorm (D-D')*‖E‖)*opNorm D+(opNorm D'*‖E‖)*opNorm (D-D') := by + apply add_le_add + · exact (frobenius_mul_le_opNorm_right _ _).trans + (mul_le_mul_of_nonneg_right (frobenius_mul_le_opNorm _ _) (opNorm_nonneg _)) + · exact (frobenius_mul_le_opNorm_right _ _).trans + (mul_le_mul_of_nonneg_right (frobenius_mul_le_opNorm _ _) (opNorm_nonneg _)) + _ = _ := by ring + +lemma sandwich_difference_opNorm (D D' E : Matrix ι ι ℂ) : + opNorm (D*E*D-D'*E*D') ≤ (opNorm D+opNorm D')*opNorm (D-D')*opNorm E := by + have he : D*E*D-D'*E*D' = (D-D')*E*D+D'*E*(D-D') := by noncomm_ring + rw [he] + calc + _ ≤ opNorm ((D-D')*E*D)+opNorm (D'*E*(D-D')) := opNorm_add _ _ + _ ≤ (opNorm (D-D')*opNorm E)*opNorm D+(opNorm D'*opNorm E)*opNorm (D-D') := by + apply add_le_add + · exact (opNorm_mul _ _).trans + (mul_le_mul_of_nonneg_right (opNorm_mul _ _) (opNorm_nonneg _)) + · exact (opNorm_mul _ _).trans + (mul_le_mul_of_nonneg_right (opNorm_mul _ _) (opNorm_nonneg _)) + _ = _ := by ring + +lemma product_four_point (a b c d e f g h : Matrix ι ι ℂ) : + ‖(a*e-b*f)-(c*g-d*h)‖ ≤ + ‖(a-b)-(c-d)‖*opNorm e + ‖c-d‖*opNorm (e-g) + + opNorm (b-d)*‖e-f‖ + opNorm d*‖(e-f)-(g-h)‖ := by + have he : (a*e-b*f)-(c*g-d*h) = + ((a-b)-(c-d))*e+(c-d)*(e-g)+(b-d)*(e-f)+d*((e-f)-(g-h)) := by noncomm_ring + rw [he] + calc + _ ≤ ‖((a-b)-(c-d))*e+(c-d)*(e-g)+(b-d)*(e-f)‖+‖d*((e-f)-(g-h))‖ := norm_add_le _ _ + _ ≤ (‖((a-b)-(c-d))*e+(c-d)*(e-g)‖+‖(b-d)*(e-f)‖)+‖d*((e-f)-(g-h))‖ := by gcongr; exact norm_add_le _ _ + _ ≤ ((‖((a-b)-(c-d))*e‖+‖(c-d)*(e-g)‖)+‖(b-d)*(e-f)‖)+‖d*((e-f)-(g-h))‖ := by gcongr; exact norm_add_le _ _ + _ ≤ _ := by + gcongr + · exact frobenius_mul_le_opNorm_right _ _ + · exact frobenius_mul_le_opNorm_right _ _ + · exact frobenius_mul_le_opNorm _ _ + · exact frobenius_mul_le_opNorm _ _ + +end SKGap.ComplexMatrix + +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Matrix/PolynomialCoeListSum.lean b/lean/OAI/Probability/SKGap/Matrix/PolynomialCoeListSum.lean new file mode 100644 index 0000000000000000000000000000000000000000..892e8f5e2718bcd286b7383cd5247c6590d97234 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Matrix/PolynomialCoeListSum.lean @@ -0,0 +1,118 @@ +import Mathlib +import OAI.Probability.SKGap.Matrix.WordDiagUniform +import OAI.Probability.SKGap.Localization.LiteralSeriesLiftAppend + +namespace OAI + +section +noncomputable section +noncomputable section +open scoped BigOperators +noncomputable section +noncomputable section +noncomputable section +open scoped BigOperators +noncomputable section +open scoped BigOperators +noncomputable section +open scoped BigOperators +noncomputable section +open scoped BigOperators +noncomputable section +open scoped BigOperators +noncomputable section +open scoped BigOperators +noncomputable section +open scoped BigOperators +noncomputable section +open scoped BigOperators +noncomputable section +open scoped BigOperators +noncomputable section +open scoped BigOperators +noncomputable section +open scoped BigOperators +noncomputable section +open scoped BigOperators +noncomputable section +open scoped BigOperators +noncomputable section +open scoped BigOperators +namespace SKGap.Noncrossing +open Diagram InverseDiagram WordSeries PowerSeries +variable {ι : Type*} [Fintype ι] + +lemma polynomial_coe_list_sum (L : List (Polynomial ℝ)) : + (L.sum : ℝ⟦X⟧)=(L.map (fun p : Polynomial ℝ=> (p : ℝ⟦X⟧))).sum := + map_list_sum Polynomial.coeToPowerSeries.ringHom L +lemma polynomial_coe_finset_sum {α : Type*} (S : Finset α) (f : α→Polynomial ℝ) : + ((∑ k∈S,f k : Polynomial ℝ) : ℝ⟦X⟧)=∑ k∈S,(f k : ℝ⟦X⟧) := + map_sum Polynomial.coeToPowerSeries.ringHom f S + +theorem literalSeries_eq_wordPredictionPolynomial (j : ℝ) (a : ι→ℝ) + (F : List (WordLetter ι)) (hI : inverseCount F≤1) (i : ι) : + literalSeries j a F i=(wordPredictionPolynomial j a F i : ℝ⟦X⟧) := by + generalize hk : ordinaryCount F=k + induction k using Nat.strong_induction_on generalizing F i with + | h k ih => + by_cases ho : ordinaryCount F=0 + · rw [literalSeries_base j a F hI ho,wordPredictionPolynomial,ite_eq_left ho,Polynomial.coe_C] + · have hsub (t : WordRecursionTerm ι) (ht : t∈wordRecursionTerms a F) : + (∀ u,literalSeries j a t.inner u=(wordPredictionPolynomial j a t.inner u : ℝ⟦X⟧)) ∧ + (∀ u,literalSeries j a t.outer u=(wordPredictionPolynomial j a t.outer u : ℝ⟦X⟧)) := by + have hd := wordRecursionTerms_decreases a F t ht + have hI' := wordRecursionTerms_one_inverse a F hI t ht + exact ⟨fun u=>ih _ (by omega) _ hI'.2 u rfl,fun u=>ih _ (by omega) _ hI'.1 u rfl⟩ + have hrec : literalSeries j a F i= + ((wordRecursionTerms a F).map (fun t=> + (if t.inversePartner then X else 1)*C j*meanSeries (literalSeries j a t.inner)* + literalSeries j a t.outer i)).sum := by + cases hs : firstNoiseSplit F with + | none => exact False.elim (ho ((firstNoiseSplit_none F).mp hs)) + | some pq => + rcases pq with ⟨P,Q⟩ + have he := firstNoiseSplit_some F P Q hs + rw [wordRecursionTerms,hs] + simpa only [he] using literalSeries_at j a P Q (by simpa only [he] using hI) i + rw [hrec,wordPredictionPolynomial,ite_eq_right ho,polynomial_coe_list_sum,List.map_map] + rw [← List.attach_map_val (l := wordRecursionTerms a F)] + congr 1 + apply List.map_congr_left + intro t ht + have hs := hsub t.val t.property + simp only [Function.comp_def,Polynomial.coe_mul,Polynomial.coe_C] + have hm : meanSeries (literalSeries j a t.val.inner)= + ((Polynomial.C ((Fintype.card ι:ℝ)⁻¹)*(∑ k,wordPredictionPolynomial j a t.val.inner k) : Polynomial ℝ) : ℝ⟦X⟧) := by + simp only [meanSeries,Polynomial.coe_mul,Polynomial.coe_C,polynomial_coe_finset_sum] + congr 1 + apply Finset.sum_congr rfl + intro u _ + exact hs.1 u + rw [hs.2 i] + rw [hm] + cases t.val.inversePartner <;> simp only [Bool.false_eq_true,↓reduceIte,Polynomial.coe_one,Polynomial.coe_X, + Polynomial.coe_mul,Polynomial.coe_C] + +end SKGap.Noncrossing + +end +end +end +end +end +end +end +end +end +end +end +end +end +end +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Matrix/PrimaryMatrix.lean b/lean/OAI/Probability/SKGap/Matrix/PrimaryMatrix.lean new file mode 100644 index 0000000000000000000000000000000000000000..ddfe4c17629338edbc76e1b0829ee67cdbf60b8e --- /dev/null +++ b/lean/OAI/Probability/SKGap/Matrix/PrimaryMatrix.lean @@ -0,0 +1,252 @@ +import Mathlib +import OAI.Probability.SKGap.Matrix.PolynomialCoeListSum +import OAI.Probability.SKGap.Localization.PrimaryPrediction + +namespace OAI + +section + +noncomputable section +open scoped BigOperators +namespace SKGap.Noncrossing.Primary +open WordSeries +variable {ι : Type*} [Fintype ι] [DecidableEq ι] + +omit [DecidableEq ι] in +lemma wordPrediction_lift (j : ℝ) (a : ι→ℝ) (z : ℝ) + (F : List (Letter (ι→ℝ))) (i : ι) : + wordPrediction j a z (liftWord F) i=Diagram.prediction j F i := by + have h := literalSeries_eq_wordPredictionPolynomial j a (liftWord F) (by simp) i + rw [literalSeries_lift] at h + have hp : wordPredictionPolynomial j a (liftWord F) i=Polynomial.C (ordinary j F i) := by + apply Polynomial.ext + intro k + have hc := congrArg (PowerSeries.coeff k) h + simpa only [← Polynomial.coe_C,Polynomial.coeff_coe] using hc.symm + rw [← (wordPredictionPolynomial_spec j a (liftWord F) i).2 z,hp] + rw [Polynomial.eval_C] + have hm (d : Diagram (ι→ℝ)) : d.map id=d := by + induction d <;> simp [Diagram.map, *] + simp only [ordinary,Diagram.expect,Diagram.evaluate,Diagram.prediction,hm] + +def matrixLetter (J : Matrix ι ι ℝ) : Letter (ι→ℝ) → Matrix ι ι ℝ + | .diag a => Matrix.diagonal a + | .noise => J + +def matrixWord (J : Matrix ι ι ℝ) (F : List (Letter (ι→ℝ))) : Matrix ι ι ℝ := + (F.map (matrixLetter J)).prod + +def matrixPolynomial (J : Matrix ι ι ℝ) (P : WordPolynomial (ι:=ι)) : Matrix ι ι ℝ := + (P.map (fun p => p.1 • matrixWord J p.2)).sum + +lemma exactWord_lift (j : ℝ) (a : ι→ℝ) (J : Matrix ι ι ℝ) (F : List (Letter (ι→ℝ))) : + exactWord j a (liftWord F) J=matrixWord J F := by + induction F with + | nil => rfl + | cons l F ih => + cases l <;> simp [liftWord,Letter.toWord,exactWord,matrixFactorProduct, + WordLetter.exactEval,matrixWord,matrixLetter] at * <;> exact congrArg _ ih + +lemma matrixWord_append (J : Matrix ι ι ℝ) (F G : List (Letter (ι→ℝ))) : + matrixWord J (F++G)=matrixWord J F*matrixWord J G := by simp [matrixWord] +lemma matrixPolynomial_append (J : Matrix ι ι ℝ) (P Q : WordPolynomial (ι:=ι)) : + matrixPolynomial J (P++Q)=matrixPolynomial J P+matrixPolynomial J Q := by + simp [matrixPolynomial] +lemma matrixPolynomial_prefix (J : Matrix ι ι ℝ) (F : List (Letter (ι→ℝ))) + (P : WordPolynomial (ι:=ι)) : + matrixPolynomial J (prependWords F P)=matrixWord J F*matrixPolynomial J P := by + induction P with + | nil => simp [prependWords,matrixPolynomial] + | cons p P ih => + simp only [prependWords,List.map_cons,matrixPolynomial,List.sum_cons] at * + rw [matrixWord_append,ih,mul_add,mul_smul_comm] +lemma matrixPolynomial_scale (J : Matrix ι ι ℝ) (c : ℝ) (P : WordPolynomial (ι:=ι)) : + matrixPolynomial J (scale c P)=c • matrixPolynomial J P := by + induction P with + | nil => simp [scale,matrixPolynomial] + | cons p P ih => + simp only [scale,List.map_cons,matrixPolynomial,List.sum_cons] at * + rw [ih,smul_add,mul_smul] + +def primaryMatrix (j : ℝ) (J : Matrix ι ι ℝ) (a : ℕ→ι→ℝ) : ℕ → Matrix ι ι ℝ + | 0 => 1 + | 1 => J + | n+2 => J*Matrix.diagonal (a n)*primaryMatrix j J a (n+1) - + (j*Diagram.mean (a n)) • (Matrix.diagonal (previousDiagonal a n)*primaryMatrix j J a n) + +lemma primaryPolynomial_matrix (j : ℝ) (J : Matrix ι ι ℝ) (a : ℕ→ι→ℝ) (n : ℕ) : + matrixPolynomial J (primaryPolynomial j a n)=primaryMatrix j J a n := by + induction n using Nat.twoStepInduction with + | zero => simp [primaryPolynomial,matrixPolynomial,primaryMatrix,matrixWord] + | one => simp [primaryPolynomial,matrixPolynomial,primaryMatrix,matrixWord,matrixLetter] + | more n hn hn1 => + simp only [primaryPolynomial,matrixPolynomial_append,matrixPolynomial_prefix, + matrixPolynomial_scale,hn,hn1,primaryMatrix,matrixWord,List.map_cons,List.map_nil, + List.prod_cons,List.prod_nil,mul_one,matrixLetter] + simp [mul_assoc,sub_eq_add_neg,neg_smul] + +lemma matrixWordSeminorm_zero (p : Bool) : matrixWordSeminorm (ι:=ι) p 0=0 := by + let : Fact (1≤(4:ENNReal)) := ⟨by norm_num⟩ + have hd : diagonalVector (0 : Matrix ι ι ℝ)=0 := by ext i; rfl + have ho : offDiagonalVector (0 : Matrix ι ι ℝ)=0 := by ext ⟨i,k⟩; simp [offDiagonalVector] + cases p <;> simp [matrixWordSeminorm,diagonalSeminorm,offDiagonalSeminorm,hd,ho] +lemma matrixWordSeminorm_smul (p : Bool) (c : ℝ) (J : Matrix ι ι ℝ) : + matrixWordSeminorm p (c • J)=|c| *matrixWordSeminorm p J := by + let : Fact (1≤(4:ENNReal)) := ⟨by norm_num⟩ + have hd : diagonalVector (c • J)=c • diagonalVector J := by ext i; rfl + have ho : offDiagonalVector (c • J)=c • offDiagonalVector J := by + ext ⟨i,k⟩ + by_cases h : i=k <;> simp [offDiagonalVector,h] + cases p + · simp [matrixWordSeminorm,diagonalSeminorm,hd,norm_smul,Real.norm_eq_abs] + · simp [matrixWordSeminorm,offDiagonalSeminorm,ho,norm_smul,Real.norm_eq_abs] + +lemma matrixWordSeminorm_list_sum (p : Bool) (L : List (Matrix ι ι ℝ)) : + matrixWordSeminorm p L.sum≤(L.map (matrixWordSeminorm p)).sum := by + induction L with + | nil => simp [matrixWordSeminorm_zero] + | cons M L ih => + simp only [List.sum_cons,List.map_cons] + exact (matrixWordSeminorm_add p M L.sum).trans (add_le_add_right ih _) + +def coefficientMass (P : WordPolynomial (ι:=ι)) : ℝ := (P.map (fun p=>|p.1|)).sum + +lemma polynomial_error (p : Bool) (j : ℝ) (J : Matrix ι ι ℝ) + (P : WordPolynomial (ι:=ι)) {C : ℝ} + (h : ∀ t∈P, matrixWordSeminorm p + (matrixWord J t.2-Matrix.diagonal (Diagram.prediction j t.2))≤C) : + matrixWordSeminorm p (matrixPolynomial J P-Matrix.diagonal (polynomialPrediction j P))≤ + coefficientMass P*C := by + induction P with + | nil => simp [matrixPolynomial,polynomialPrediction,coefficientMass,matrixWordSeminorm_zero] + | cons t P ih => + have he : matrixPolynomial J (t::P)-Matrix.diagonal (polynomialPrediction j (t::P))= + t.1 • (matrixWord J t.2-Matrix.diagonal (Diagram.prediction j t.2))+ + (matrixPolynomial J P-Matrix.diagonal (polynomialPrediction j P)) := by + have hp : polynomialPrediction j (t::P)= + t.1 • Diagram.prediction j t.2+polynomialPrediction j P := by + ext i; simp [polynomialPrediction] + have hd (u v : ι→ℝ) : Matrix.diagonal (u+v)=Matrix.diagonal u+Matrix.diagonal v := + (Matrix.diagonal_add u v).symm + simp only [matrixPolynomial,List.map_cons,List.sum_cons,hp,hd,Matrix.diagonal_smul] + rw [smul_sub] + abel + rw [he] + calc + _ ≤ matrixWordSeminorm p (t.1 • (matrixWord J t.2-Matrix.diagonal (Diagram.prediction j t.2)))+ + matrixWordSeminorm p (matrixPolynomial J P-Matrix.diagonal (polynomialPrediction j P)) := + matrixWordSeminorm_add _ _ _ + _ ≤ |t.1| *C+coefficientMass P*C := by + rw [matrixWordSeminorm_smul] + exact add_le_add (mul_le_mul_of_nonneg_left (h t (by simp)) (abs_nonneg _)) + (ih (fun q hq=>h q (List.mem_cons_of_mem _ hq))) + _ = coefficientMass (t::P)*C := by simp [coefficientMass,add_mul] + +theorem primaryMatrix_seminorm (p : Bool) (j : ℝ) (J : Matrix ι ι ℝ) + (a : ℕ→ι→ℝ) (n : ℕ) (hn : 0 ha i) + +def massBound (j : ℝ) : ℕ→ℝ + | 0 => 1 + | 1 => 1 + | n+2 => massBound j (n+1)+|j| *massBound j n +lemma massBound_pos (j : ℝ) (n : ℕ) : 0< massBound j n := by + induction n using Nat.twoStepInduction with + | zero => norm_num [massBound] + | one => norm_num [massBound] + | more n hn hn1 => exact add_pos_of_pos_of_nonneg hn1 (mul_nonneg (abs_nonneg _) hn.le) +lemma primaryMass_bound [Nonempty ι] (j : ℝ) (a : ℕ→ι→ℝ) + (ha : ∀ n i,|a n i|≤1) (n : ℕ) : + coefficientMass (primaryPolynomial j a n)≤ massBound j n := by + induction n using Nat.twoStepInduction with + | zero => simp [primaryPolynomial,coefficientMass,massBound] + | one => simp [primaryPolynomial,coefficientMass,massBound] + | more n hn hn1 => + simp only [primaryPolynomial,coefficientMass_append,coefficientMass_prefix, + coefficientMass_scale,abs_neg,abs_mul,massBound] + apply add_le_add hn1 + calc + |j| * |Diagram.mean (a n)| * coefficientMass (primaryPolynomial j a n) ≤ + |j| * 1 * coefficientMass (primaryPolynomial j a n) := + mul_le_mul_of_nonneg_right + (mul_le_mul_of_nonneg_left (mean_abs_le_one (ha n)) (abs_nonneg _)) + (coefficientMass_nonneg _) + _ ≤ |j| * massBound j n := by simpa using mul_le_mul_of_nonneg_left hn (abs_nonneg j) + +lemma primaryPolynomial_admissible (j : ℝ) (a : ℕ→ι→ℝ) + (ha : ∀ n i,|a n i|≤1) (n : ℕ) : + ∀ t∈primaryPolynomial j a n, t.2.length≤2*n ∧ + ∀ l∈liftWord t.2,l.bounded 1 := by + have hp (n : ℕ) : ∀ i,|previousDiagonal a n i|≤1 := by + cases n <;> simp [previousDiagonal,ha] + induction n using Nat.twoStepInduction with + | zero => simp [primaryPolynomial,liftWord] + | one => + intro t ht + simp only [primaryPolynomial,List.mem_singleton] at ht + subst t + simp [liftWord,Letter.toWord,WordLetter.bounded] + | more n hn hn1 => + intro t ht + simp only [primaryPolynomial,List.mem_append,prependWords,scale,List.mem_map] at ht + rcases ht with ⟨q,hq,rfl⟩ | ⟨u,⟨q,hq,rfl⟩,rfl⟩ + · obtain ⟨hql,hqb⟩ := hn1 q hq + constructor + · simp only [List.length_append,List.length_cons,List.length_nil]; omega + · intro l hl + simp only [liftWord_append,liftWord_cons,liftWord_nil,Letter.toWord, + List.mem_append,List.mem_cons,List.not_mem_nil,or_false] at hl + rcases hl with (rfl|rfl)|hl + · trivial + · exact ha n + · exact hqb l hl + · obtain ⟨hql,hqb⟩ := hn q hq + constructor + · simp only [List.length_append,List.length_cons,List.length_nil]; omega + · intro l hl + simp only [liftWord_append,liftWord_cons,liftWord_nil,Letter.toWord, + List.mem_append,List.mem_cons,List.not_mem_nil,or_false] at hl + rcases hl with rfl|hl + · exact hp n + · exact hqb l hl + +end SKGap.Noncrossing.Primary +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Matrix/PrimaryWordControl.lean b/lean/OAI/Probability/SKGap/Matrix/PrimaryWordControl.lean new file mode 100644 index 0000000000000000000000000000000000000000..71a170e054c30c6e71f04233aae179c1e81160ae --- /dev/null +++ b/lean/OAI/Probability/SKGap/Matrix/PrimaryWordControl.lean @@ -0,0 +1,80 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.MarkedDiagnostic + +namespace OAI + +section + +noncomputable section +open scoped BigOperators +namespace SKGapCutoff.Recipe +open SKGap.Noncrossing SKGap.Noncrossing.Primary +variable {n : ℕ} +def PolynomialControl (A : ℝ) (L : ℕ) (P : WordPolynomial (ι:=Fin n)) : Prop := + ∀t∈P,wordBounded A t.2 ∧ t.2.length≤L +lemma PolynomialControl.mono {A : ℝ} {L K : ℕ} {P : WordPolynomial (ι:=Fin n)} + (h : PolynomialControl A L P) (hLK : L≤K) : PolynomialControl A K P := + fun t ht=>⟨(h t ht).1,(h t ht).2.trans hLK⟩ +lemma PolynomialControl.append {A : ℝ} {L : ℕ} {P Q : WordPolynomial (ι:=Fin n)} + (h : PolynomialControl A L P) (hQ : PolynomialControl A L Q) : PolynomialControl A L (P++Q) := by + intro t ht; rcases List.mem_append.mp ht with ht|ht + · exact h t ht + · exact hQ t ht +lemma PolynomialControl.prepend {A : ℝ} {L : ℕ} {P : WordPolynomial (ι:=Fin n)} + (h : PolynomialControl A L P) (w : OrdinaryWord n) (hw : wordBounded A w) : + PolynomialControl A (w.length+L) (prependWords w P) := by + intro t ht + obtain ⟨r,hr,he⟩:=List.mem_map.mp ht + subst t + exact ⟨wordBounded_append hw (h r hr).1,by simpa only [List.length_append] using Nat.add_le_add_left (h r hr).2 w.length⟩ +lemma PolynomialControl.scale {A : ℝ} {L : ℕ} {P : WordPolynomial (ι:=Fin n)} + (h : PolynomialControl A L P) (c : ℝ) : PolynomialControl A L (SKGap.Noncrossing.Primary.scale c P) := by + intro t ht + obtain ⟨r,hr,he⟩:=List.mem_map.mp ht + subst t + exact h r hr +lemma polynomialControl_nil (c : ℝ) (A : ℝ) (L : ℕ) : + PolynomialControl (n:=n) A L [(c,[])] := by + intro t ht + have he:=List.mem_singleton.mp ht; subst t + exact ⟨by intro l hl; simp at hl,Nat.zero_le _⟩ +lemma polynomialControl_noise (c : ℝ) (A : ℝ) (L : ℕ) (hL : 1≤L) : + PolynomialControl (n:=n) A L [(c,[.noise])] := by + intro t ht + have he:=List.mem_singleton.mp ht; subst t + constructor + · intro l hl + have he:=List.mem_singleton.mp hl; subst l; trivial + · exact hL +end SKGapCutoff.Recipe +namespace SKGapCutoff.Primary +open Recipe SKGap.Noncrossing SKGap.Noncrossing.Primary +variable {n : ℕ} +theorem primaryTree_control (j : ℝ) (J : Interaction n) (h : Fin n→ℝ) (x : Spin n) (k : ℕ) + {A : ℝ} (hA : 1≤A) : + PolynomialControl A (2*k+1) ((primaryTree j J h x k).words j).1 ∧ + PolynomialControl A (2*k+1) ((primaryTree j J h x k).words j).2 := by + induction k with + | zero=>exact ⟨polynomialControl_nil _ _ _,polynomialControl_noise _ _ _ (by omega)⟩ + | succ k ih=> + have hd : wordBounded A [.diag (primaryDiagonal j J h x k)] := by + intro l hl + have he:=List.mem_singleton.mp hl; subst l + exact fun i=>(primaryDiagonal_bounded j J h x k i).trans hA + have hv : PolynomialControl A (2*(k+1)+1) (prependWords [.diag (primaryDiagonal j J h x k)] + ((primaryTree j J h x k).words j).2) := + (ih.2.prepend _ hd).mono (by simp only [List.length_singleton]; omega) + have hn : wordBounded (n:=n) A [.noise] := by + intro l hl; have he:=List.mem_singleton.mp hl; subst l; trivial + have hh : PolynomialControl A (2*(k+1)+1) (prependWords [.noise,.diag (primaryDiagonal j J h x k)] + ((primaryTree j J h x k).words j).2) := by + exact (ih.2.prepend _ (wordBounded_append hn hd)).mono (by simp only [List.length_append,List.length_cons,List.length_nil]; omega) + simp only [primaryTree,SourceTree.words] + exact ⟨hv.append (polynomialControl_nil _ _ _), + (hh.append ((ih.1.scale _).mono (by omega))).append (polynomialControl_noise _ _ _ (by omega))⟩ +end SKGapCutoff.Primary + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Matrix/PrimaryWordEventBinding.lean b/lean/OAI/Probability/SKGap/Matrix/PrimaryWordEventBinding.lean new file mode 100644 index 0000000000000000000000000000000000000000..e2782d1a8c5d9e80f0b7a810a64c52a0b5199c1b --- /dev/null +++ b/lean/OAI/Probability/SKGap/Matrix/PrimaryWordEventBinding.lean @@ -0,0 +1,69 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.PrimaryQuenched +import OAI.Probability.SKGap.Stability.OrdinaryWordEvent + +namespace OAI + +section + +noncomputable section +open scoped BigOperators +namespace SKGapCutoff.Recipe +open Primary SKGap SKGap.Noncrossing SKGap.Noncrossing.Primary MeasureTheory ProbabilityTheory Real Set +variable {n : ℕ} + +lemma WordSeminormBound.mono {J : Interaction n} {j A C : ℝ} {L K : ℕ} + (h : WordSeminormBound J j A C L) (hK : K≤L) : WordSeminormBound J j A C K := + fun p w hw hb=>h p w (hw.trans hK) hb + +def primaryEventBudget (j R C : ℝ) (M : ℕ) : ℝ := + ∑q:Fin M,(formalOpBound j R (q.val+1)+massBound j (q.val+1)*C) +lemma primaryEventBudget_nonneg {j R C : ℝ} (hR : 0≤R) (hC : 0≤C) (M : ℕ) : + 0≤primaryEventBudget j R C M := + Finset.sum_nonneg (fun _ _=>add_nonneg (formalOpBound_nonneg j hR _) (mul_nonneg (massBound_pos j _).le hC)) + +lemma wordEvent_formal {j R A C : ℝ} (J : Interaction n) (hn : 0formalOpBound j R (q.val+1)+massBound j (q.val+1)*C) + (fun q _=>add_nonneg (formalOpBound_nonneg j hR _) (mul_nonneg (massBound_pos j _).le hC)) + (Finset.mem_univ q) + have ho : formalOpBound j R (l+1)≤primaryEventBudget j R C M := + (le_add_of_nonneg_right hmass).trans hb + have hm : massBound j (l+1)*C≤primaryEventBudget j R C M := + (le_add_of_nonneg_left hnon).trans hb + have ha:=primaryDiagonal_bounded j J h x + have hp (p : Bool) : matrixWordSeminorm p (formalField j J h x l)≤primaryEventBudget j R C M := by + apply (primaryMatrix_seminorm p j J (primaryDiagonal j J h x) (l+1) (by omega) ?_).trans + · exact (mul_le_mul_of_nonneg_right (primaryMass_bound j _ ha (l+1)) hC).trans hm + · intro t ht + have htB:=primaryPolynomial_admissible j _ ha (l+1) t ht + exact hw p t.2 (htB.1.trans (by omega)) + (wordBounded_mono ((wordBounded_lift 1 _).mpr htB.2) hA) + exact ⟨(primaryMatrix_opNorm J _ hn hR hJ ha (l+1)).trans ho,hp false,hp true⟩ + +def RecipeMatrixEvent (j R A B W C : ℝ) (M Nmax : ℕ) (J : Interaction n) : Prop := + SKGap.opNorm J≤R ∧ + (∀h x l,lwordEvent_formal J hn (by linarith) hC hA hJ M _ (by omega) hw h x l hl, + wordSeminormBound_test (hw.mono (by omega)) hn hR hAR hJ,?_⟩ + exact wordSeminormBound_diagram (hw.mono (by omega)) + +end SKGapCutoff.Recipe + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Matrix/PrimitiveTrace.lean b/lean/OAI/Probability/SKGap/Matrix/PrimitiveTrace.lean new file mode 100644 index 0000000000000000000000000000000000000000..e61a1640e26785f3a0b1127d5224e90d6c10e8d0 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Matrix/PrimitiveTrace.lean @@ -0,0 +1,216 @@ +import Mathlib +import OAI.Probability.SKGap.Matrix.PrimaryMatrix +import OAI.Probability.SKGap.Matrix.Trace +import OAI.Probability.SKGap.Matrix.CorrectionTrace + +namespace OAI + +section + +noncomputable section +open scoped BigOperators Matrix.Norms.Frobenius +namespace SKGapCutoff.Recipe +open Primary Matrix SKGap.SourceError +variable {n : ℕ} +local instance : Fact (1≤(4:ENNReal)) := ⟨by norm_num⟩ + +def testSize (P : Interaction n) : ℝ := SKGap.opNorm P+SKGap.offDiagonalSeminorm P +lemma testSize_nonneg (P : Interaction n) : 0≤testSize P := add_nonneg (norm_nonneg _) (norm_nonneg _) +lemma opNorm_le_testSize (P : Interaction n) : SKGap.opNorm P≤testSize P := le_add_of_nonneg_right (norm_nonneg _) + +structure TraceControl (E : Interaction n) (C : ℝ) : Prop where + nonneg : 0≤C + bound : ∀P,|trace (P*E)|≤C*testSize P + +lemma TraceControl.zero : TraceControl (0 : Interaction n) 0 := by constructor <;> simp +lemma TraceControl.mono {E : Interaction n} {C D : ℝ} (h : TraceControl E C) (hCD : C≤D) : TraceControl E D := + ⟨h.nonneg.trans hCD,fun P=>(h.bound P).trans (mul_le_mul_of_nonneg_right hCD (testSize_nonneg P))⟩ +lemma TraceControl.add {E F : Interaction n} {C D : ℝ} (hE : TraceControl E C) (hF : TraceControl F D) : + TraceControl (E+F) (C+D) := by + refine ⟨add_nonneg hE.nonneg hF.nonneg,?_⟩ + intro P; rw [mul_add,trace_add,add_mul] + exact (abs_add_le _ _).trans (add_le_add (hE.bound P) (hF.bound P)) +lemma TraceControl.smul {E : Interaction n} {C : ℝ} (hE : TraceControl E C) (a : ℝ) : + TraceControl (a • E) (|a| *C) := by + refine ⟨mul_nonneg (abs_nonneg _) hE.nonneg,?_⟩ + intro P; rw [Matrix.mul_smul,trace_smul,smul_eq_mul,abs_mul] + exact (mul_le_mul_of_nonneg_left (hE.bound P) (abs_nonneg a)).trans_eq (by ring) +lemma TraceControl.neg {E : Interaction n} {C : ℝ} (hE : TraceControl E C) : TraceControl (-E) C := by + simpa using hE.smul (-1) +lemma TraceControl.sub {E F : Interaction n} {C D : ℝ} (hE : TraceControl E C) (hF : TraceControl F D) : + TraceControl (E-F) (C+D) := by simpa only [sub_eq_add_neg] using hE.add hF.neg +lemma TraceControl.sum {α : Type*} [Fintype α] {E : α→Interaction n} {C : α→ℝ} + (h : ∀a,TraceControl (E a) (C a)) : TraceControl (∑a,E a) (∑a,C a) := by + refine ⟨Finset.sum_nonneg (fun a _=>(h a).nonneg),?_⟩ + intro P; rw [Matrix.mul_sum,trace_sum,Finset.sum_mul] + exact (Finset.abs_sum_le_sum_abs ..).trans (Finset.sum_le_sum fun a _=>(h a).bound P) + +lemma control_of_operator {E : Interaction n} {C : ℝ} (hC : 0≤C) + (h : ∀P,|trace (P*E)|≤C*SKGap.opNorm P) : TraceControl E C := + ⟨hC,fun P=>(h P).trans (mul_le_mul_of_nonneg_left (opNorm_le_testSize P) hC)⟩ + +lemma small_diagonal_control (E : Interaction n) (u : Fin n→ℝ) : + TraceControl (Matrix.diagonal u*E) (vectorNorm u*‖E‖) := by + apply control_of_operator (mul_nonneg (vectorNorm_nonneg _) (norm_nonneg _)) + intro P; exact (trace_small_diagonal P E u).trans_eq (by ring) +lemma small_mean_control (E : Interaction n) (U : VectorFields n) (x : Spin n) (hn : 0norm_nonneg _ + refine ⟨by positivity,?_⟩ + intro P + have hO : 0≤SKGap.offDiagonalSeminorm P := norm_nonneg _ + have hP : (∑i,∑k,if i=k then 0 else (P k i)^4)≤SKGap.offDiagonalSeminorm P^4 := by + rw [SKGap.offDiagonalSeminorm_fourth,Fintype.sum_prod_type,Finset.sum_comm] + simp only [eq_comm]; rfl + apply (sourceError_trace H θ F F' s x P h hS hT hB hR hL hO hs hds ht hQ4 hQr hQd hP).trans + have h₁ : 0≤C*S*((∑α,‖derivativeVector (θ α) x‖)+4*(B^2+R*T+T^2)+2*(L+T)) := by positivity + have h₂ : 0≤2*C*S*B := by positivity + have H₁ := mul_nonneg (real_op_norm_nonneg P) h₂ + have H₂ := mul_nonneg hO h₁ + unfold testSize + nlinarith only [H₁,H₂] + +end SKGapCutoff.Recipe + +end +end + +section + +noncomputable section +open scoped BigOperators +namespace SKGapCutoff.Recipe +open Matrix SKGap.Noncrossing SKGap.Noncrossing.Primary SKGap.Noncrossing.Diagram +variable {n : ℕ} + +abbrev OrdinaryWord (n : ℕ) := List (Letter (Fin n→ℝ)) +def wordBounded (A : ℝ) (w : OrdinaryWord n) : Prop := + ∀l∈w,match l with | .diag p=>∀i,|p i|≤A | .noise=>True +lemma wordBounded_diag {A : ℝ} {w : OrdinaryWord n} (h : wordBounded A w) + (p : Fin n→ℝ) (hp : ∀i,|p i|≤A) : wordBounded A (w++[.diag p]) := by + intro l hl; rcases List.mem_append.mp hl with hl|hl + · exact h l hl + · have he : l=Letter.diag p := List.mem_singleton.mp hl; subst l; exact hp +lemma wordBounded_noise {A : ℝ} {w : OrdinaryWord n} (h : wordBounded A w) : + wordBounded A (w++[.noise]) := by + intro l hl; rcases List.mem_append.mp hl with hl|hl + · exact h l hl + · have he : l=Letter.noise := List.mem_singleton.mp hl; subst l; trivial + +def WordTestBound (J : Interaction n) (A M : ℝ) (L : ℕ) : Prop := + ∀w:OrdinaryWord n,w.length≤L→wordBounded A w→testSize (matrixWord J w)≤M + +def errorBudget (R : ℝ) (Cs Cf : ℕ→ℝ) (a : ℕ) : ℝ×ℝ := + let S:=Cs a+∑b:Fin a,(errorBudget R Cs Cf b).2 + (S,S+R*(∑b:Fin a,(errorBudget R Cs Cf b).1)+Cf a) +termination_by a +lemma errorBudget_nonneg {R : ℝ} (hR : 0≤R) {Cs Cf : ℕ→ℝ} + (hs : ∀a,0≤Cs a) (hf : ∀a,0≤Cf a) (a : ℕ) : + 0≤(errorBudget R Cs Cf a).1 ∧ 0≤(errorBudget R Cs Cf a).2 := by + induction a using Nat.strong_induction_on with + | h a ih => + rw [errorBudget] + have h1 : 0≤∑b:Fin a,(errorBudget R Cs Cf b).1 := Finset.sum_nonneg fun b _=>(ih b b.isLt).1 + have h2 : 0≤∑b:Fin a,(errorBudget R Cs Cf b).2 := Finset.sum_nonneg fun b _=>(ih b b.isLt).2 + exact ⟨add_nonneg (hs a) h2,add_nonneg (add_nonneg (add_nonneg (hs a) h2) (mul_nonneg hR h1)) (hf a)⟩ + +theorem finite_graph_trace (J : Interaction n) (E F Es Ef : ℕ→Interaction n) + (p : (a : ℕ)→Fin a→Fin n→ℝ) (r : (a : ℕ)→Fin a→ℝ) + (hE : ∀a,E a=(∑b:Fin a,Matrix.diagonal (p a b)*F b)+Es a) + (hF : ∀a,F a=J*E a-(∑b:Fin a,r a b • E b)+Ef a) + {A R M : ℝ} {Cs Cf : ℕ→ℝ} {N L : ℕ} + (hR : 0≤R) (hM : 0≤M) + (hp : ∀a≤N,∀b i,|p a b i|≤A) (hr : ∀a≤N,∀b,|r a b|≤R) + (hs : ∀a≤N,TraceControl (Es a) (Cs a)) (hf : ∀a≤N,TraceControl (Ef a) (Cf a)) + (hw : WordTestBound J A M L) : + ∀a≤N, + (∀w:OrdinaryWord n,w.length+2*a+1≤L→wordBounded A w→ + |trace (matrixWord J w*E a)|≤(errorBudget R Cs Cf a).1*M) ∧ + (∀w:OrdinaryWord n,w.length+2*a+2≤L→wordBounded A w→ + |trace (matrixWord J w*F a)|≤(errorBudget R Cs Cf a).2*M) := by + intro a + induction a using Nat.strong_induction_on with + | h a ih => + intro ha + have hs₀ : 0≤Cs a := (hs a ha).nonneg + have hf₀ : 0≤Cf a := (hf a ha).nonneg + have hprev (b : Fin a) := ih b b.isLt (b.isLt.le.trans ha) + have hCs (w : OrdinaryWord n) (hlen : w.length≤L) (hwb : wordBounded A w) : + |trace (matrixWord J w*Es a)|≤Cs a*M := by + apply (hs a ha).bound _ |>.trans + simpa only [mul_comm] using mul_le_mul (hw w hlen hwb) (le_refl (Cs a)) hs₀ hM + have hCf (w : OrdinaryWord n) (hlen : w.length≤L) (hwb : wordBounded A w) : + |trace (matrixWord J w*Ef a)|≤Cf a*M := + (hf a ha).bound _ |>.trans (mul_le_mul_of_nonneg_left (hw w hlen hwb) hf₀) + have hsource : ∀w:OrdinaryWord n,w.length+2*a+1≤L→wordBounded A w→ + |trace (matrixWord J w*E a)|≤(errorBudget R Cs Cf a).1*M := by + intro w hlen hwb + have hterms (b : Fin a) : |trace (matrixWord J w*(Matrix.diagonal (p a b)*F b))|≤ + (errorBudget R Cs Cf b).2*M := by + have H:=(hprev b).2 (w++[.diag (p a b)]) (by simp only [List.length_append,List.length_singleton]; omega) + (wordBounded_diag hwb _ (hp a ha b)) + simpa only [matrixWord_append,matrixWord,List.map_cons,List.map_nil,List.prod_cons,List.prod_nil, + matrixLetter,List.map_append,List.prod_append,mul_one,mul_assoc] using H + rw [hE a,mul_add,trace_add,errorBudget] + dsimp only + have H:=(Finset.abs_sum_le_sum_abs (s:=Finset.univ) (f:=fun b:Fin a=>trace (matrixWord J w*(Matrix.diagonal (p a b)*F b)))).trans + (Finset.sum_le_sum fun b _=>hterms b) + rw [←trace_sum,←Matrix.mul_sum,←Finset.sum_mul] at H + exact ((abs_add_le _ _).trans (add_le_add H (hCs w (by omega) hwb))).trans_eq (by ring) + refine ⟨hsource,?_⟩ + intro w hlen hwb + have hsnew:=hsource (w++[.noise]) (by simp only [List.length_append,List.length_singleton]; omega) + (wordBounded_noise hwb) + have Hs : |trace (matrixWord J w*(J*E a))|≤(errorBudget R Cs Cf a).1*M := by + simpa only [matrixWord_append,matrixWord,List.map_cons,List.map_nil,List.prod_cons,List.prod_nil, + matrixLetter,List.map_append,List.prod_append,mul_one,mul_assoc] using hsnew + have hterms (b : Fin a) : |trace (matrixWord J w*(r a b • E b))|≤ + R*(errorBudget R Cs Cf b).1*M := by + have H:=(hprev b).1 w (by omega) hwb + rw [Matrix.mul_smul,trace_smul,smul_eq_mul,abs_mul] + exact ((mul_le_mul_of_nonneg_right (hr a ha b) (abs_nonneg _)).trans + (mul_le_mul_of_nonneg_left H hR)).trans_eq (by ring) + have H:=(Finset.abs_sum_le_sum_abs (s:=Finset.univ) (f:=fun b:Fin a=>trace (matrixWord J w*(r a b • E b)))).trans + (Finset.sum_le_sum fun b _=>hterms b) + rw [←trace_sum,←Matrix.mul_sum] at H + rw [hF a,mul_add,mul_sub,trace_add,trace_sub] + apply ((abs_add_le _ _).trans (add_le_add ((abs_sub _ _).trans (add_le_add Hs H)) + (hCf w (by omega) hwb))).trans_eq + rw [errorBudget] + dsimp only + rw [←Finset.sum_mul,←Finset.mul_sum] + ring + +end SKGapCutoff.Recipe + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Matrix/RankNorm.lean b/lean/OAI/Probability/SKGap/Matrix/RankNorm.lean new file mode 100644 index 0000000000000000000000000000000000000000..0199be5b73df14b6574db14066dd48f7b5b477a8 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Matrix/RankNorm.lean @@ -0,0 +1,125 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.CubeApprox + +namespace OAI + +section +noncomputable section +namespace SKGap +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius +variable {ι : Type*} [Fintype ι] [DecidableEq ι] +lemma real_eigenvalue_abs_le_opNorm {M : Matrix ι ι ℝ} (hM : M.IsHermitian) (i : ι) : + |hM.eigenvalues i| ≤ opNorm M := by + have he : M.toEuclideanLin.toContinuousLinearMap (hM.eigenvectorBasis i)=hM.eigenvalues i • hM.eigenvectorBasis i := by + ext k + exact congrFun (hM.mulVec_eigenvectorBasis i) k + have hn := hM.eigenvectorBasis.orthonormal.norm_eq_one i + have hh := M.toEuclideanLin.toContinuousLinearMap.le_opNorm (hM.eigenvectorBasis i) + rw [he,norm_smul,Real.norm_eq_abs,hn,mul_one,mul_one] at hh + exact hh + +lemma frobenius_sq_le_rank_opNorm_sq (M : Matrix ι ι ℝ) : + ‖M‖^2 ≤ (M.rank:ℝ)*(opNorm M)^2 := by + classical + let Q := Mᵀ*M + have hQ : Q.PosSemidef := by simpa only [Q,conjTranspose_eq_transpose_of_trivial] using Matrix.posSemidef_conjTranspose_mul_self M + have hqe (i : ι) : hQ.isHermitian.eigenvalues i ≤ (opNorm M)^2 := by + have hi := (le_abs_self (hQ.isHermitian.eigenvalues i)).trans (real_eigenvalue_abs_le_opNorm hQ.isHermitian i) + apply hi.trans + have hh := opNorm_mul Mᵀ M + rw [opNorm_transpose] at hh + exact hh.trans_eq (by ring) + rw [LogDet.frobenius_sq_trace,hQ.isHermitian.trace_eq_sum_eigenvalues] + simp only [RCLike.ofReal_real_eq_id, id_eq] + have ht : (∑ i,hQ.isHermitian.eigenvalues i)=∑ i : {i // hQ.isHermitian.eigenvalues i ≠ 0},hQ.isHermitian.eigenvalues i := by + exact Finset.sum_congr_set {i | hQ.isHermitian.eigenvalues i ≠ 0} _ _ + (fun _ _ => rfl) (fun i hi => by simpa using hi) + rw [ht] + have hh := Finset.sum_le_sum (s := Finset.univ) (fun (i : {i // hQ.isHermitian.eigenvalues i ≠ 0}) _ => hqe i) + simpa only [Finset.sum_const,Finset.card_univ,nsmul_eq_mul,← hQ.isHermitian.rank_eq_card_non_zero_eigs,Q,rank_transpose_mul_self] using hh + +lemma frobenius_le_sqrt_rank_opNorm (M : Matrix ι ι ℝ) : + ‖M‖ ≤ sqrt (M.rank:ℝ)*opNorm M := by + have hop : 0 ≤ opNorm M := norm_nonneg _ + apply (sq_le_sq₀ (norm_nonneg M) (by positivity : 0 ≤ sqrt (M.rank:ℝ)*opNorm M)).mp + rw [mul_pow,sq_sqrt (Nat.cast_nonneg _)] + exact frobenius_sq_le_rank_opNorm_sq M +end SKGap +end +end + +section +noncomputable section +namespace SKGap +open Matrix MeasureTheory ProbabilityTheory Real Set Filter +open scoped BigOperators Matrix.Norms.Frobenius Topology +variable {ι : Type*} [Fintype ι] [DecidableEq ι] [Nonempty ι] + +lemma logdet_cube_difference {j δ R γ : ℝ} (hj : 0 ≤ j) (hδ : 0 ≤ δ) (hR : 0 ≤ R) + (hγ : 0 < γ) {a b : ι → ℝ} (ha : ∀ i,0 ≤ a i) (ha1 : ∀ i,a i ≤ 1) + (hb : ∀ i,0 ≤ b i) (hb1 : ∀ i,b i ≤ 1) (hab : ∀ i,|a i-b i| ≤ δ) + {M : Matrix ι ι ℝ} (hM : opNorm M ≤ R) : + |LogDet.regularizedLogDet γ (logPath (j*coordAverage a) a M 1)- + LogDet.regularizedLogDet γ (logPath (j*coordAverage b) b M 1)| ≤ + ((2*j+R)/sqrt γ)*δ := by + have hn : (0:ℝ) < Fintype.card ι := Nat.cast_pos.mpr Fintype.card_pos + have hs : 0 < sqrt (Fintype.card ι:ℝ) := sqrt_pos.mpr hn + have hh := logPath_cube_difference hj hδ hR ha ha1 hb hb1 hab hM + apply (LogDet.regularizedLogDet_lipschitz hγ _ _).trans + apply (mul_le_mul_of_nonneg_left hh (by positivity : 0 ≤ 1/sqrt ((Fintype.card ι:ℝ)*γ))).trans_eq + rw [sqrt_mul hn.le] + field_simp + +lemma logdet_cube_net_transfer {j δ R γ α : ℝ} (hj : 0 ≤ j) (hδ : 0 < δ) (hR : 0 ≤ R) + (hγ : 0 < γ) (s : Finset ℝ) (hs : ∀ x ∈ s, x ∈ Icc (0:ℝ) 1) + (hcover : ∀ x ∈ Icc (0:ℝ) 1, ∃ y ∈ s, |x-y| ≤ δ) + {M : Matrix ι ι ℝ} (hM : opNorm M ≤ R) + (hnet : ∀ v : ι → s, LogDet.regularizedLogDet γ (logPath (j*coordAverage (fun i => (v i:ℝ))) + (fun i => (v i:ℝ)) M 1) ≤ j*(coordAverage (fun i => (v i:ℝ)))^2+α) + {a : ι → ℝ} (ha : ∀ i,0 ≤ a i) (ha1 : ∀ i,a i ≤ 1) : + LogDet.regularizedLogDet γ (logPath (j*coordAverage a) a M 1) ≤ j*(coordAverage a)^2+ + α+(((2*j+R)/sqrt γ)+2*j)*δ := by + classical + choose b hb hab using fun i => hcover (a i) ⟨ha i,ha1 i⟩ + let v : ι → s := fun i => ⟨b i,hb i⟩ + have hb0 (i) : 0 ≤ b i := (hs _ (hb i)).1 + have hb1 (i) : b i ≤ 1 := (hs _ (hb i)).2 + have hn := hnet v + have hd := (abs_le.mp (logdet_cube_difference hj hδ.le hR hγ ha ha1 hb0 hb1 hab hM)).2 + have hq := (abs_le.mp (coordAverage_sq_sub_le hj ha ha1 hb0 hb1 hab)).1 + change LogDet.regularizedLogDet γ (logPath (j*coordAverage b) b M 1) ≤ j*(coordAverage b)^2+α at hn + linarith + +lemma logdet_rank_perturbation {γ M₂ : ℝ} (hγ : 0 < γ) (_hM₂ : 0 ≤ M₂) {r₀ : ℕ} + (M E : Matrix ι ι ℝ) (hrank : E.rank ≤ r₀) (hop : opNorm E ≤ M₂) : + |LogDet.regularizedLogDet γ (M+E)-LogDet.regularizedLogDet γ M| ≤ + M₂*sqrt (r₀:ℝ)/sqrt ((Fintype.card ι:ℝ)*γ) := by + have hn := frobenius_le_sqrt_rank_opNorm E + have he := (mul_le_mul (sqrt_le_sqrt (Nat.cast_le.mpr hrank)) hop + (norm_nonneg _) (sqrt_nonneg (r₀:ℝ))) + have h := (LogDet.regularizedLogDet_lipschitz hγ (M+E) M) + rw [add_sub_cancel_left] at h + apply h.trans + exact (mul_le_mul_of_nonneg_left (hn.trans he) (by positivity : 0 ≤ 1/sqrt ((Fintype.card ι:ℝ)*γ))).trans_eq (by ring) + +lemma product_mesh_absorption {a : ℝ} (ha : 0 < a) (m n : ℕ) + (hn : ((m:ℝ)+1)/a ≤ (n:ℝ)) : + (m:ℝ)^n*(2*Real.exp (-a*(n:ℝ)^2)) ≤ 2*Real.exp (-(n:ℝ)) := by + have hm : (m:ℝ) ≤ Real.exp (m:ℝ) := by linarith [Real.add_one_le_exp (m:ℝ)] + have hpow := pow_le_pow_left₀ (Nat.cast_nonneg m) hm n + rw [← Real.exp_nat_mul] at hpow + have hmn : (m:ℝ)+1 ≤ a*(n:ℝ) := by nlinarith [(div_le_iff₀ ha).mp hn] + have he : Real.exp ((n:ℝ)*(m:ℝ)-a*(n:ℝ)^2) ≤ Real.exp (-(n:ℝ)) := by + apply Real.exp_le_exp.mpr + nlinarith [mul_nonneg (Nat.cast_nonneg n) (sub_nonneg.mpr hmn)] + have hh := mul_le_mul_of_nonneg_right hpow (show 0 ≤ 2*Real.exp (-a*(n:ℝ)^2) by positivity) + calc + _ ≤ Real.exp ((n:ℝ)*(m:ℝ))*(2*Real.exp (-a*(n:ℝ)^2)) := hh + _ = 2*Real.exp ((n:ℝ)*(m:ℝ)-a*(n:ℝ)^2) := by rw [sub_eq_add_neg,Real.exp_add]; ring_nf + _ ≤ _ := mul_le_mul_of_nonneg_left he (by norm_num) +end SKGap +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Matrix/RealSymmetricResolventUnit.lean b/lean/OAI/Probability/SKGap/Matrix/RealSymmetricResolventUnit.lean new file mode 100644 index 0000000000000000000000000000000000000000..38f5d10bb5b443622138d9ce9b43c9d7bd9ddf5e --- /dev/null +++ b/lean/OAI/Probability/SKGap/Matrix/RealSymmetricResolventUnit.lean @@ -0,0 +1,133 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.TruncationGoodSet +import OAI.Probability.SKGap.Localization.IntegralAbsSet + +namespace OAI + +section +noncomputable section +open MeasureTheory ProbabilityTheory InformationTheory Real Set +open scoped NNReal ENNReal +open Filter +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius ENNReal NNReal +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius NNReal +noncomputable section +open MeasureTheory ProbabilityTheory Real Set Filter +open MeasureTheory.Measure +open scoped ENNReal NNReal MeasureTheory Topology +open MeasureTheory +noncomputable section +noncomputable section +open MeasureTheory Set NormedSpace +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius +noncomputable section +open Set Real +open scoped Topology +noncomputable section +open Matrix Set Filter +open scoped Topology Matrix.Norms.Frobenius +noncomputable section +open Matrix NormedSpace ContinuousLinearMap +open scoped Matrix.Norms.Frobenius +noncomputable section +open Matrix +noncomputable section +open MeasureTheory ProbabilityTheory Real Set +open scoped ENNReal NNReal +namespace SKGap +open RealComplex ComplexSpectral +open Matrix MeasureTheory ProbabilityTheory Real +open scoped BigOperators Matrix.Norms.Frobenius NNReal ENNReal SchwartzMap ComplexOrder +variable {ι : Type*} [Fintype ι] [DecidableEq ι] + +lemma real_symmetric_resolvent_isUnit (D C M : Matrix ι ι ℝ) + (hD : Dᵀ = D) (hC : Cᵀ = C) (hM : Mᵀ = M) + (hl : 0 < lowerRayleigh (liftMatrix (1-D*(M-C)*D))) : + IsUnit (1-D*D*(M-C)) := by + have hs : (liftMatrix (1-D*(M-C)*D)).IsHermitian := by + rw [liftMatrix_sub,liftMatrix_one,liftMatrix_mul,liftMatrix_mul,liftMatrix_sub] + change (1-liftMatrix D*(liftMatrix M-liftMatrix C)*liftMatrix D)ᴴ = _ + simp only [Matrix.conjTranspose_sub,Matrix.conjTranspose_one,Matrix.conjTranspose_mul, + liftMatrix_hermitian D hD,liftMatrix_hermitian C hC,liftMatrix_hermitian M hM,mul_assoc] + have hsu : IsUnit (liftMatrix (1-D*(M-C)*D)) := + (hs.posDef_iff_eigenvalues_pos.mpr (fun i => hl.trans_le (eigenvalue_lower_bound hs i))).isUnit + have hrs := (liftMatrix_isUnit_iff _).mp hsu + exact ResolventIdentity.inverse_one_sub_square_mul_unit D (M-C) hrs + +lemma diagonal_resolvent_identity (d c : ι → ℝ) (M K : Matrix ι ι ℝ) + (hK : (1-diagonal d*diagonal d*(M-diagonal c))*K=1) (i : ι) : + K i i = 1+(d i)^2*((M*K) i i-c i*K i i) := by + have he : (1-diagonal d*diagonal d*(M-diagonal c))*K = + K-diagonal (fun a => (d a)^2)*(M*K-diagonal c*K) := by + have hd : diagonal d*diagonal d = diagonal (fun a => (d a)^2) := by + rw [Matrix.diagonal_mul_diagonal]; congr 1; ext a; simp only [pow_two] + rw [hd] + noncomm_ring + rw [he] at hK + have hh := congrFun (congrFun hK i) i + simp only [Matrix.sub_apply,Matrix.diagonal_mul,Matrix.one_apply_eq] at hh + nlinarith only [hh] + +theorem realTruncatedK_second_loop (f : 𝓢(ℝ,ℂ)) {lo hi : ℝ} (hlo : 0 < lo) + (hf : ∀ x ∈ Set.Icc lo hi, f x = (x : ℂ)⁻¹) + {R r : ℝ} (hR : 0 ≤ R) (hr : 0 ≤ r) (d c : ι → ℝ) (i : ι) : + let D := diagonal d + let C := diagonal c + let K := realTruncatedK f R hR D C + let b := ComplexMatrix.kBound f R (liftMatrix D) (liftMatrix C) + let μ := Measure.pi (fun _ : MatrixCoordinates ι => gaussianReal 0 1) + let s := truncationGoodSet r R lo hi D C + |(∫ g, K (goeMatrix r g) i i ∂μ)- + (1+(d i)^2*((∫ g, (goeMatrix r g*K (goeMatrix r g)) i i ∂μ)- + c i*(∫ g, K (goeMatrix r g) i i ∂μ)))| ≤ + (b+1+|(d i)^2*c i| *b)*μ.real sᶜ+ + (|(d i)^2| *b)*(Fintype.card ι:ℝ)*sqrt (2*r)*sqrt (μ.real sᶜ) := by + intro D C K b μ s + have hD : Dᵀ=D := Matrix.diagonal_transpose _ + have hC : Cᵀ=C := Matrix.diagonal_transpose _ + have hKL := realTruncatedK_lipschitz f hR D C hD hC + apply goe_diagonal_inverse_loop hr (fun a => (d a)^2) c i + (hKL.continuous.comp (goeMatrix_pi_lipschitz r).continuous) + (fun g a b => (matrix_entry_le_opNorm _ a b).trans + (realTruncatedK_opNorm f hR D C _ hD hC)) + (truncationGoodSet_measurable r R lo hi D C) + intro g hg + apply diagonal_resolvent_identity d c (goeMatrix r g) (K (goeMatrix r g)) + have hunit := real_symmetric_resolvent_isUnit D C (goeMatrix r g) hD hC + (goeMatrix_transpose r g) (hlo.trans hg.2.1) + have hid := realTruncatedK_eq_inverse f hlo hf hR D C (goeMatrix r g) hD hC + (goeMatrix_transpose r g) hg.1.le hg.2.1.le hg.2.2.le + change (1-D*D*(goeMatrix r g-C))*K (goeMatrix r g)=1 + rw [show K (goeMatrix r g) = _ from hid] + exact Matrix.mul_nonsing_inv _ (((1-D*D*(goeMatrix r g-C)).isUnit_iff_isUnit_det).mp hunit) + +end SKGap + +noncomputable section +open MeasureTheory ProbabilityTheory InformationTheory Real Set +open scoped NNReal ENNReal + +end +end +end +end +end +end +end +end +end +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Matrix/RecipeNodeTrace.lean b/lean/OAI/Probability/SKGap/Matrix/RecipeNodeTrace.lean new file mode 100644 index 0000000000000000000000000000000000000000..8d84aa0b01a4db63cdfa1d104e2f9d5d994a7217 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Matrix/RecipeNodeTrace.lean @@ -0,0 +1,116 @@ +import Mathlib +import OAI.Probability.SKGap.Stability.OrdinaryRecipe +import OAI.Probability.SKGap.Stability.OrdinaryGraph +import OAI.Probability.SKGap.Matrix.PrimitiveTrace +import OAI.Probability.SKGap.Localization.RecipeError + +namespace OAI + +section + +noncomputable section +open scoped BigOperators Matrix.Norms.Frobenius +namespace SKGapCutoff.Recipe.OrdinaryData +open Primary Matrix SKGap.Noncrossing.Primary +variable {n : ℕ} {ι κ σ : Type*} [Fintype ι] [DecidableEq ι] [Fintype κ] [DecidableEq κ] [Fintype σ] +variable (D : OrdinaryData n ι κ σ) + +def nodeSourceError (T : ι→SourceTree (Fin n→ℝ)) (x : Spin n) (a : ℕ) : Interaction n := + D.sourceAtoms a (fun b=>D.auxiliary b) x+ + ∑l,Matrix.diagonal (D.sourcePartial a l x)* + (derivativeMatrix (D.H l) x-SourceTree.fieldMatrix D.j D.J (T l)) +def nodeFieldError (T : ι→SourceTree (Fin n→ℝ)) (x : Spin n) (a : ℕ) : Interaction n := + -(∑l,(D.j*siteMean (D.sourcePartial a l) x) • + (derivativeMatrix (D.predecessor l) x-SourceTree.sourceMatrix D.j D.J (T l)))- + D.j • ((∑l,averageError (siteMean (D.sourcePartial a l)) (D.predecessor l) x)+ + ∑b:Fin a,averageError (siteMean (D.auxCoefficient a b)) (D.source b) x) + +lemma source_error_nodes (T : ι→SourceTree (Fin n→ℝ)) (x : Spin n) (a : ℕ) : + D.sourceDerivativeError T x a= + (∑b:Fin a,Matrix.diagonal (D.auxCoefficient a b x)*D.fieldDerivativeError T x b)+ + D.nodeSourceError T x a := by + rw [D.source_error_recursion,nodeSourceError]; abel +lemma field_error_nodes (T : ι→SourceTree (Fin n→ℝ)) (x : Spin n) (a : ℕ) : + D.fieldDerivativeError T x a=D.J*D.sourceDerivativeError T x a- + (∑b:Fin a,(D.j*siteMean (D.auxCoefficient a b) x) • D.sourceDerivativeError T x b)+ + D.nodeFieldError T x a := by + rw [D.field_error_recursion,nodeFieldError]; abel + +lemma nodeSource_control (T : ι→SourceTree (Fin n→ℝ)) (x : Spin n) (a : ℕ) + {C Q R L V Z : ℝ} {B : Fin a→ℝ} {Cp E : ι→ℝ} + (hC : 0≤C) (hQ : 0≤Q) (hR : 0≤R) (hL : 0≤L) (hV : 0≤V) + (hY : ∀b:Fin a,SmallBound (D.auxiliary b) x (B b)) + (hp : ∀l,SmallBound (D.sourcePartial a l) x (Cp l)) + (hE : ∀l,‖derivativeMatrix (D.H l) x-SourceTree.fieldMatrix D.j D.J (T l)‖≤E l) + (hs : ∀s,SegmentRegular D.H D.θ (D.seedFunction a s) (D.seedDerivative a s) x C) + (ha : ∀b,SegmentRegular D.H D.θ (D.auxFunction a b) (D.auxDerivative a b) x C) + (ht : vectorNorm (parameterIncrement D.θ x)≤V) + (hQ4 : (∑i,∑k,(primaryIncrement D.H x i k)^4)≤Q^4) + (hQr : ∀i,(∑k,(primaryIncrement D.H x i k)^2)≤R^2) + (hQd : (∑i,(primaryIncrement D.H x i i)^2)≤L^2) + (hZ : (∑α,‖derivativeVector (D.θ α) x‖)+4*(Q^2+R*V+V^2)+2*(Q+L+V)≤Z) : + TraceControl (D.nodeSourceError T x a) + (((∑s,C*vectorNorm (D.seed s)*Z)+(∑b:Fin a,C*B b*Z))+∑l,Cp l*E l) := by + have hc (s : VectorFields n) {S : ℝ} (hS : SmallBound s x S) + (F : Fin n→Args (ι:=ι) (κ:=κ)→ℝ) + (F' : Fin n→Args (ι:=ι) (κ:=κ)→Args (ι:=ι) (κ:=κ)→L[ℝ]ℝ) + (hF : SegmentRegular D.H D.θ F F' x C) : TraceControl (sourceError D.H D.θ F F' s x) (C*S*Z) := + (sourceError_control D.H D.θ F F' s x hF hS.nonneg hV hQ hR hL hS.size hS.derivative ht hQ4 hQr hQd).mono + (mul_le_mul_of_nonneg_left hZ (mul_nonneg hC hS.nonneg)) + have hs' := TraceControl.sum (fun s=>hc (fun _=>D.seed s) (SmallBound.seed _ x) _ _ (hs s)) + have ha' := TraceControl.sum (fun b:Fin a=>hc (D.auxiliary b) (hY b) _ _ (ha b)) + have hp' := TraceControl.sum (fun l=>(small_diagonal_control + (derivativeMatrix (D.H l) x-SourceTree.fieldMatrix D.j D.J (T l)) (D.sourcePartial a l x)).mono + (mul_le_mul (hp l).size (hE l) (norm_nonneg _) (hp l).nonneg)) + exact (hs'.add ha').add hp' + +lemma nodeField_control (T : ι→SourceTree (Fin n→ℝ)) (x : Spin n) (a : ℕ) (hn : 0D.auxCoefficient a b x) + (fun a b=>D.j*siteMean (D.auxCoefficient a b) x) + (D.source_error_nodes T x) (D.field_error_nodes T x) hR hM hp hr hs hf hw + +end SKGapCutoff.Recipe.OrdinaryData + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Matrix/RecipeTraceBudget.lean b/lean/OAI/Probability/SKGap/Matrix/RecipeTraceBudget.lean new file mode 100644 index 0000000000000000000000000000000000000000..bb3b49dfe2ed86f3b2802119273fd9cb9ea97aa6 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Matrix/RecipeTraceBudget.lean @@ -0,0 +1,175 @@ +import Mathlib +import OAI.Probability.SKGap.Stability.StableFields +import OAI.Probability.SKGap.Localization.RecipeMarked + +namespace OAI + +section + +noncomputable section +open scoped BigOperators +namespace SKGap.Noncrossing.Primary.MarkedPolynomial +open Diagram +variable {n : ℕ} + +def pairBudget (V : Pair n) : ℝ := V.1.budget+V.2.budget + +lemma budget_nonneg (P : MarkedPolynomial n) : 0≤P.budget := by + unfold budget + exact List.sum_nonneg (by intro r hr; obtain ⟨t,_,rfl⟩:=List.mem_map.mp hr; exact mul_nonneg (abs_nonneg _) (SKGapCutoff.Recipe.vectorNorm_nonneg _)) +lemma pairBudget_nonneg (V : Pair n) : 0≤pairBudget V := add_nonneg (budget_nonneg _) (budget_nonneg _) +lemma mass_nonneg (P : WordPolynomial (ι:=Fin n)) : 0 ≤ mass P := by + unfold mass + exact List.sum_nonneg (by intro r hr; obtain ⟨t,_,rfl⟩:=List.mem_map.mp hr; exact abs_nonneg _) + +lemma smallBranch_budget (j : ℝ) (p : Fin n→ℝ) (T : SourceTree (Fin n→ℝ)) (V : Pair n) : + pairBudget (smallBranch j p T V)= + SKGapCutoff.Recipe.vectorNorm p*(2*mass (T.words j).2+|j| *mass (T.words j).1)+pairBudget V := by + simp only [pairBudget,smallBranch,budget_append,budget_prefix,budget_diagonalWords,budget_averageWords,abs_neg] + ring +lemma boundedBranch_budget (j : ℝ) (p : Fin n→ℝ) (U V : Pair n) {A : ℝ} + (hp : |Diagram.mean p|≤A) : + pairBudget (boundedBranch j p U V) ≤ (2+|j| *A)*pairBudget U+pairBudget V := by + simp only [pairBudget,boundedBranch,budget_append,budget_prefix,budget_scale,abs_neg,abs_mul] + have h:=mul_le_mul_of_nonneg_left hp (mul_nonneg (abs_nonneg j) (budget_nonneg U.1)) + nlinarith [budget_nonneg U.1,budget_nonneg U.2, + mul_nonneg (mul_nonneg (abs_nonneg j) (le_trans (abs_nonneg _) hp)) (budget_nonneg U.2)] + +lemma fold_budget {α : Type*} (xs : List α) (step : α→Pair n→Pair n) (cost : α→ℝ) + (hstep : ∀a V,pairBudget (step a V)≤cost a+pairBudget V) : + pairBudget (xs.foldr step zeroPair)≤(xs.map cost).sum := by + induction xs with + | nil => simp [zeroPair,pairBudget,budget,SmallMark.vector] + | cons a xs ih => + exact (hstep a _).trans (by simpa only [List.map_cons,List.sum_cons] using add_le_add (le_refl (cost a)) ih) + +end SKGap.Noncrossing.Primary.MarkedPolynomial +namespace SKGapCutoff.Recipe +open Primary Matrix SKGap.Noncrossing.Primary MarkedPolynomial +variable {n : ℕ} {ι κ σ : Type*} [Fintype ι] [DecidableEq ι] [Fintype κ] [DecidableEq κ] [Fintype σ] + +def traceBudget (c k : ℝ) (W : ℕ→ℝ) (a : ℕ) : ℝ := c*W a+k*∑b:Fin a,traceBudget c k W b +termination_by a + +namespace OrdinaryData +variable (D : OrdinaryData n ι κ σ) +theorem markedRecipe_budget (T : ι→SourceTree (Fin n→ℝ)) (x : Spin n) (N : ℕ) + (W : ℕ→ℝ) {A M : ℝ} (hA : 0≤A) (hM : 0≤M) + (hp : ∀a≤N,∀l,vectorNorm (D.sourcePartial a l x)≤W a) + (hm : ∀l,mass ((T l).words D.j).1≤M ∧ mass ((T l).words D.j).2≤M) + (ha : ∀a≤N,∀b:Fin a,|siteMean (D.auxCoefficient a b) x|≤A) : + ∀a≤N,pairBudget (D.markedRecipe T x a)≤ + traceBudget ((Fintype.card ι:ℝ)*((2+|D.j|)*M)) (2+|D.j| *A) W a := by + intro a + induction a using Nat.strong_induction_on with + | h a ih => + intro haN + rw [markedRecipe] + let L : ℝ := (2+|D.j|)*M + let K : ℝ := 2+|D.j| *A + have hL : 0≤L := by dsimp [L]; positivity + have hK : 0≤K := by dsimp [K]; positivity + have H:=fold_budget (Finset.univ.toList.map (Sum.inl : ι→ι⊕Fin a)++Finset.univ.toList.map Sum.inr) + (fun e V=>match e with + | .inl l=>smallBranch D.j (D.sourcePartial a l x) (T l) V + | .inr b=>boundedBranch D.j (D.auxCoefficient a b x) (D.markedRecipe T x b) V) + (Sum.elim (fun _ : ι=>L*W a) (fun b:Fin a=>K*pairBudget (D.markedRecipe T x b))) + (by + intro e V + cases e with + | inl l=> + rw [smallBranch_budget] + apply add_le_add _ le_rfl + have hc : 2*mass ((T l).words D.j).2+|D.j| *mass ((T l).words D.j).1≤L := by + dsimp [L] + nlinarith [(hm l).2,mul_le_mul_of_nonneg_left (hm l).1 (abs_nonneg D.j)] + exact (mul_le_mul_of_nonneg_left hc (vectorNorm_nonneg _)).trans + (by simpa [mul_comm] using mul_le_mul_of_nonneg_right (hp a haN l) hL) + | inr b=> + exact boundedBranch_budget D.j _ _ _ (by simpa only [siteMean,SKGap.Noncrossing.Diagram.mean,Fintype.card_fin] using ha a haN b)) + have hs : (∑b:Fin a,pairBudget (D.markedRecipe T x b))≤ + ∑b:Fin a,traceBudget ((Fintype.card ι:ℝ)*((2+|D.j|)*M)) K W b := by + apply Finset.sum_le_sum; intro b _; exact ih b b.isLt (b.isLt.le.trans haN) + apply H.trans + simp only [List.map_append,List.sum_append,List.map_map,Function.comp_def,Sum.elim_inl,Sum.elim_inr] + rw [traceBudget] + have he : (List.map (fun b:Fin a=>K*pairBudget (D.markedRecipe T x b)) Finset.univ.toList).sum= + K*∑b:Fin a,pairBudget (D.markedRecipe T x b) := by simp [Finset.mul_sum] + have he0 : (List.map (fun _ : ι=>L*W a) Finset.univ.toList).sum=(Fintype.card ι:ℝ)*(L*W a) := by simp + rw [he,he0] + convert! add_le_add (le_refl ((Fintype.card ι:ℝ)*L*W a)) (mul_le_mul_of_nonneg_left hs hK) using 1 + try dsimp [L,K] + ring + +end OrdinaryData +end SKGapCutoff.Recipe + +end +end + +section + +noncomputable section +open scoped BigOperators +namespace SKGap.Noncrossing +open Matrix +variable {ι : Type*} [Fintype ι] [DecidableEq ι] + +lemma diagonal_abs_sum_of_tests (M : Matrix ι ι ℝ) {C : ℝ} + (h : ∀d:ι→ℝ,(∀i,|d i|≤1)→|trace (Matrix.diagonal d*M)|≤C) : + (∑i,|M i i|)≤C := by + let d : ι→ℝ := fun i=>if 0≤M i i then 1 else -1 + have hd : ∀i,|d i|≤1 := by intro i; dsimp [d]; split_ifs <;> norm_num + have ht : trace (Matrix.diagonal d*M)=∑i,|M i i| := by + simp only [trace,diag,Matrix.diagonal_mul] + apply Finset.sum_congr rfl; intro i _ + dsimp [d]; split_ifs with hi + · simp [abs_of_nonneg hi] + · simp [abs_of_neg (lt_of_not_ge hi)] + have H:=h d hd + rw [ht,abs_of_nonneg (Finset.sum_nonneg fun i _=>abs_nonneg _)] at H + exact H + +end SKGap.Noncrossing +namespace SKGapCutoff.Recipe.OrdinaryData +open SKGap.Noncrossing SKGap.Noncrossing.Primary SKGap.Noncrossing.Diagram Matrix MarkedPolynomial +variable {n : ℕ} {ι κ σ : Type*} [Fintype ι] [DecidableEq ι] [Fintype κ] [DecidableEq κ] [Fintype σ] + +theorem retainedSource_diagonal (D : OrdinaryData n ι κ σ) (T : ι→SourceTree (Fin n→ℝ)) + (x : Spin n) (a : ℕ) (hn : 0(D.retained_prediction_zero T x a i).1 + simpa only [hz,mul_zero,Finset.sum_const_zero,sub_zero,retainedSource,SourceTree.sourceMatrix] using H + +theorem retainedField_diagonal (D : OrdinaryData n ι κ σ) (T : ι→SourceTree (Fin n→ℝ)) + (x : Spin n) (a : ℕ) (hn : 0(D.retained_prediction_zero T x a i).2 + simpa only [hz,mul_zero,Finset.sum_const_zero,sub_zero,retainedField,SourceTree.fieldMatrix] using H + +end SKGapCutoff.Recipe.OrdinaryData + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Matrix/RecipeWordEvent.lean b/lean/OAI/Probability/SKGap/Matrix/RecipeWordEvent.lean new file mode 100644 index 0000000000000000000000000000000000000000..b29e5324edda800b3aa988d7b6fbf87387df1b10 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Matrix/RecipeWordEvent.lean @@ -0,0 +1,82 @@ +import Mathlib +import OAI.Probability.SKGap.Stability.OrdinaryClosure +import OAI.Probability.SKGap.Localization.MarkedDiagnostic + +namespace OAI + +section + +noncomputable section +open scoped BigOperators +namespace SKGapCutoff.Recipe +open SKGap.Noncrossing SKGap.Noncrossing.Primary SKGap.Noncrossing.Primary.MarkedPolynomial +variable {n : ℕ} +lemma pairControl_fold {τ : Type*} (xs : List τ) (f : τ→Pair n→Pair n) {A : ℝ} {L : ℕ} + (hL : 1≤L) (hf : ∀t V,PairControl A L V→PairControl A L (f t V)) : + PairControl A L (xs.foldr f zeroPair) := by + induction xs with + | nil=>exact zeroPair_control hL + | cons t xs ih=>exact hf t _ ih + +namespace OrdinaryData +variable {ι κ σ : Type*} [Fintype ι] [DecidableEq ι] [Fintype κ] [DecidableEq κ] [Fintype σ] + +theorem markedRecipe_control (D : OrdinaryData n ι κ σ) (T : ι→SourceTree (Fin n→ℝ)) + (x : Spin n) (N L : ℕ) {A : ℝ} (hA : 1≤A) + (hT : ∀l,(∀t∈((T l).words D.j).1,wordBounded A t.2 ∧ t.2.length≤L) ∧ + (∀t∈((T l).words D.j).2,wordBounded A t.2 ∧ t.2.length≤L)) + (hp : ∀a≤N,∀b i,|D.auxCoefficient a b x i|≤A) : + ∀a≤N,PairControl A (L+2*a+2) (D.markedRecipe T x a) := by + intro a + induction a using Nat.strong_induction_on with + | h a ih=> + intro ha + rw [markedRecipe] + apply pairControl_fold _ _ (by omega) + intro t V hV + cases t with + | inl l=>exact smallBranch_control hA (by omega) D.j _ _ _ (hT l) hV + | inr b=>exact boundedBranch_control (by omega) D.j _ (hp a ha b) _ _ (ih b b.isLt (b.isLt.le.trans ha)) hV + +end OrdinaryData + +def WordDiagramBound (J : Interaction n) (j A B : ℝ) (L : ℕ) : Prop := + ∀w:OrdinaryWord n,w.length≤L→wordBounded A w→ + SKGap.diagonalSeminorm (matrixWord J w-Matrix.diagonal (Diagram.prediction j w))≤B + +namespace OrdinaryData +variable {ι κ σ : Type*} [Fintype ι] [DecidableEq ι] [Fintype κ] [DecidableEq κ] [Fintype σ] + +theorem ordinary_word_closure (D : OrdinaryData n ι κ σ) (T : ι→SourceTree (Fin n→ℝ)) + (x : Spin n) (N L : ℕ) (c : LocalConstants) (h : LocalOrdinaryInput D T x N c) + {M B Q : ℝ} (hM : 0≤M) (hB : 0≤B) (hQ : 0≤Q) + (hm : ∀l,mass ((T l).words D.j).1≤Q ∧ mass ((T l).words D.j).2≤Q) + (hT : ∀l,(∀t∈((T l).words D.j).1,wordBounded c.A t.2 ∧ t.2.length≤L) ∧ + (∀t∈((T l).words D.j).2,wordBounded c.A t.2 ∧ t.2.length≤L)) + (hw : WordTestBound D.J c.A M (2*N+3)) + (hd : WordDiagramBound D.J D.j c.A B (L+2*N+2)) : + let W:=c.normBudget D.j (Fintype.card ι) + let R:=errorBudget (|D.j| *c.A) (c.sourceCost D.j (Fintype.card ι) (Fintype.card σ)) + (c.fieldCost D.j (Fintype.card ι)) + let V:=traceBudget ((Fintype.card ι:ℝ)*((2+|D.j|)*Q)) (2+|D.j| *c.A) W + ∀a≤N,SmallBound (D.source a) x (W a) ∧ SmallBound (D.auxiliary a) x (W a) ∧ + (∑i,|Primary.derivativeMatrix (D.source a) x i i|)≤V a*B+(R a).1*M ∧ + (∑i,|Primary.derivativeMatrix (D.auxiliary a) x i i|)≤V a*B+(R a).2*M := by + apply D.ordinary_local_closure T x N c h hM hB hQ hm hw + intro a ha d hdd + have hc:=D.markedRecipe_control T x N L c.one_le_A hT h.auxValue a ha + constructor + · intro t ht + have H:=(hc.1 t ht) d hdd + exact hd _ (H.2.trans (by omega)) H.1 + · intro t ht + have H:=(hc.2 t ht) d hdd + exact hd _ (H.2.trans (by omega)) H.1 + +end OrdinaryData +end SKGapCutoff.Recipe + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Matrix/RegularizedLogDet.lean b/lean/OAI/Probability/SKGap/Matrix/RegularizedLogDet.lean new file mode 100644 index 0000000000000000000000000000000000000000..a1529cb67d75369615d6961228edec3413905b83 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Matrix/RegularizedLogDet.lean @@ -0,0 +1,230 @@ +import Mathlib +import OAI.Probability.SKGap.Matrix.MatrixLogDet +import OAI.Probability.SKGap.Localization.FrobeniusSq + +namespace OAI + +section +noncomputable section +namespace SKGap.LogDet +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius +variable {ι : Type*} [Fintype ι] [DecidableEq ι] + +def regularizedGram (γ : ℝ) (M : Matrix ι ι ℝ) := Mᵀ*M+γ • 1 + +def regularizedLogDet (γ : ℝ) (M : Matrix ι ι ℝ) : ℝ := + Real.log (regularizedGram γ M).det/(Fintype.card ι:ℝ) + +lemma regularizedGram_posDef {γ : ℝ} (hγ : 0 < γ) (M : Matrix ι ι ℝ) : + (regularizedGram γ M).PosDef := by + exact Matrix.PosDef.posSemidef_add (by simpa using Matrix.posSemidef_conjTranspose_mul_self M) + (Matrix.PosDef.one.smul hγ) + +lemma regularizedGram_transpose (γ : ℝ) (M : Matrix ι ι ℝ) : + (regularizedGram γ M)ᵀ=regularizedGram γ M := by + simp [regularizedGram] + +lemma frobenius_sq_trace (M : Matrix ι ι ℝ) : ‖M‖^2=(Mᵀ*M).trace := by + rw [SKGap.frobenius_sq] + simp only [Matrix.trace,Matrix.diag,Matrix.mul_apply,Matrix.transpose_apply] + rw [Finset.sum_comm] + simp only [sq] + +lemma trace_inner_abs (M H : Matrix ι ι ℝ) : |(Mᵀ*H).trace| ≤ ‖M‖*‖H‖ := by + have hc := Finset.sum_mul_sq_le_sq_mul_sq (Finset.univ : Finset (ι×ι)) + (fun p => M p.1 p.2) (fun p => H p.1 p.2) + simp only [Fintype.sum_prod_type] at hc + have ht : (Mᵀ*H).trace=∑ i,∑ k,M i k*H i k := by + simp only [Matrix.trace,Matrix.diag,Matrix.mul_apply,Matrix.transpose_apply] + exact Finset.sum_comm + rw [ht] + apply nonneg_le_nonneg_of_sq_le_sq (mul_nonneg (norm_nonneg _) (norm_nonneg _)) + simpa only [← sq,sq_abs,mul_pow,SKGap.frobenius_sq] using hc + +lemma regularized_resolvent_square {γ : ℝ} (hγ : 0 < γ) (M : Matrix ι ι ℝ) : + let Q := regularizedGram γ M + (1-(2*γ) • Q⁻¹)ᵀ*(1-(2*γ) • Q⁻¹)=1-(4*γ) • ((M*Q⁻¹)ᵀ*(M*Q⁻¹)) := by + dsimp only + let Q := regularizedGram γ M + have hQ := regularizedGram_posDef hγ M |>.isUnit + have hi : Q⁻¹*Q=1 := Matrix.nonsing_inv_mul Q ((Matrix.isUnit_iff_isUnit_det _).mp hQ) + have ht : (Q⁻¹)ᵀ=Q⁻¹ := by rw [Matrix.transpose_nonsing_inv,regularizedGram_transpose] + have he : Q⁻¹*(Mᵀ*M)*Q⁻¹=Q⁻¹-γ • (Q⁻¹*Q⁻¹) := by + have h := congrArg (fun X : Matrix ι ι ℝ => X*Q⁻¹) hi + dsimp only [Q,regularizedGram] at h ⊢ + simp only [mul_add,Matrix.mul_smul,mul_one,add_mul,Matrix.smul_mul,one_mul] at h + exact eq_sub_of_add_eq h + change (1-(2*γ) • Q⁻¹)ᵀ*(1-(2*γ) • Q⁻¹)=1-(4*γ) • ((M*Q⁻¹)ᵀ*(M*Q⁻¹)) + simp only [Matrix.transpose_sub,Matrix.transpose_one,Matrix.transpose_smul,ht, + Matrix.transpose_mul,one_sub_mul,mul_sub,mul_one,Matrix.smul_mul,Matrix.mul_smul,smul_smul] + have he' : Q⁻¹*Mᵀ*(M*Q⁻¹)=Q⁻¹-γ • (Q⁻¹*Q⁻¹) := by simpa only [mul_assoc] using he + rw [he',smul_sub,smul_smul] + module + +lemma regularized_resolvent_frobenius {γ : ℝ} (hγ : 0 < γ) (M : Matrix ι ι ℝ) : + 4*γ*‖M*(regularizedGram γ M)⁻¹‖^2 ≤ (Fintype.card ι:ℝ) := by + have hp := Matrix.posSemidef_conjTranspose_mul_self + (1-(2*γ) • (regularizedGram γ M)⁻¹) + have ht := hp.trace_nonneg + rw [Matrix.conjTranspose_eq_transpose_of_trivial] at ht + rw [regularized_resolvent_square hγ M,Matrix.trace_sub,Matrix.trace_smul, + Matrix.trace_one,smul_eq_mul,← frobenius_sq_trace] at ht + linarith + +lemma hasDerivAt_regularizedGram (γ : ℝ) (M H : Matrix ι ι ℝ) (t : ℝ) (i k : ι) : + HasDerivAt (fun s : ℝ => regularizedGram γ (M+s • H) i k) + ((Hᵀ*(M+t • H)+(M+t • H)ᵀ*H) i k) t := by + have h (a b : ι) : HasDerivAt (fun s : ℝ => (M+s • H) a b) (H a b) t := by + convert ((hasDerivAt_id t).mul_const (H a b)).const_add (M a b) using 1 <;> first | rfl | simp + have hh := (HasDerivAt.fun_sum (u := Finset.univ) (fun l _ => (h l i).mul (h l k))).add_const ((γ • (1:Matrix ι ι ℝ)) i k) + convert hh using 1 <;> try rfl + simp only [Matrix.add_apply,Matrix.mul_apply,Matrix.transpose_apply,Finset.sum_add_distrib] + +lemma trace_regularized_derivative (M H K : Matrix ι ι ℝ) (hK : Kᵀ=K) : + ((Hᵀ*M+Mᵀ*H)*K).trace=2*((M*K)ᵀ*H).trace := by + rw [add_mul,Matrix.trace_add] + have h₁ : (Hᵀ*M*K).trace=((M*K)ᵀ*H).trace := by + rw [← Matrix.trace_transpose (Hᵀ*M*K)] + simp only [Matrix.transpose_mul,Matrix.transpose_transpose,hK,mul_assoc] + have h₂ : (Mᵀ*H*K).trace=((M*K)ᵀ*H).trace := by + rw [Matrix.trace_mul_cycle] + simp only [Matrix.transpose_mul,hK] + rw [h₁,h₂] + ring + +lemma hasDerivAt_regularizedLogDet (γ : ℝ) (hγ : 0 < γ) (M H : Matrix ι ι ℝ) (t : ℝ) : + HasDerivAt (fun s : ℝ => regularizedLogDet γ (M+s • H)) + (2*(((M+t • H)*(regularizedGram γ (M+t • H))⁻¹)ᵀ*H).trace/(Fintype.card ι:ℝ)) t := by + have hh := (hasDerivAt_logdet (hasDerivAt_regularizedGram γ M H t) + (regularizedGram_posDef hγ (M+t • H)).isUnit).div_const (Fintype.card ι:ℝ) + rw [trace_regularized_derivative] at hh + · exact hh + · rw [Matrix.transpose_nonsing_inv,regularizedGram_transpose] + +lemma regularized_gradient_bound [Nonempty ι] {γ : ℝ} (hγ : 0 < γ) (M : Matrix ι ι ℝ) : + 2*‖M*(regularizedGram γ M)⁻¹‖/(Fintype.card ι:ℝ) ≤ 1/sqrt ((Fintype.card ι:ℝ)*γ) := by + have hn : (0:ℝ) < Fintype.card ι := Nat.cast_pos.mpr Fintype.card_pos + have hg : 0 < (Fintype.card ι:ℝ)*γ := mul_pos hn hγ + apply (div_le_div_iff₀ hn (sqrt_pos.mpr hg)).mpr + rw [one_mul] + apply nonneg_le_nonneg_of_sq_le_sq hn.le + simpa only [← sq,mul_pow,sq_sqrt hg.le] using + (show (2*‖M*(regularizedGram γ M)⁻¹‖)^2*((Fintype.card ι:ℝ)*γ) ≤ (Fintype.card ι:ℝ)^2 by + have hh := mul_le_mul_of_nonneg_left (regularized_resolvent_frobenius hγ M) hn.le + nlinarith only [hh]) + +lemma regularized_derivative_bound [Nonempty ι] {γ : ℝ} (hγ : 0 < γ) (M H : Matrix ι ι ℝ) : + |2*((M*(regularizedGram γ M)⁻¹)ᵀ*H).trace/(Fintype.card ι:ℝ)| ≤ + 1/sqrt ((Fintype.card ι:ℝ)*γ)*‖H‖ := by + have hn : (0:ℝ) < Fintype.card ι := Nat.cast_pos.mpr Fintype.card_pos + rw [abs_div,abs_mul,abs_of_pos hn,abs_of_pos (by norm_num : (0:ℝ)<2)] + calc + _ ≤ 2*(‖M*(regularizedGram γ M)⁻¹‖*‖H‖)/(Fintype.card ι:ℝ) := by + gcongr + exact trace_inner_abs _ _ + _ = (2*‖M*(regularizedGram γ M)⁻¹‖/(Fintype.card ι:ℝ))*‖H‖ := by ring + _ ≤ _ := mul_le_mul_of_nonneg_right (regularized_gradient_bound hγ M) (norm_nonneg _) + +theorem regularizedLogDet_lipschitz [Nonempty ι] {γ : ℝ} (hγ : 0 < γ) + (M N : Matrix ι ι ℝ) : + |regularizedLogDet γ M-regularizedLogDet γ N| ≤ + 1/sqrt ((Fintype.card ι:ℝ)*γ)*‖M-N‖ := by + have hh := Convex.norm_image_sub_le_of_norm_hasDerivWithin_le + (s := Set.univ) (f := fun t : ℝ => regularizedLogDet γ (N+t • (M-N))) + (f' := fun t => 2*(((N+t • (M-N))*(regularizedGram γ (N+t • (M-N)))⁻¹)ᵀ*(M-N)).trace/(Fintype.card ι:ℝ)) + (fun t _ => (hasDerivAt_regularizedLogDet γ hγ N (M-N) t).hasDerivWithinAt) + (fun t _ => by simpa only [Real.norm_eq_abs] using regularized_derivative_bound hγ (N+t • (M-N)) (M-N)) + (convex_univ) (Set.mem_univ (0:ℝ)) (Set.mem_univ (1:ℝ)) + simpa only [one_smul,zero_smul,add_zero,add_sub_cancel,sub_zero,norm_one,mul_one,Real.norm_eq_abs] using hh +end SKGap.LogDet +end +end + +section +noncomputable section +namespace SKGap.LogDet +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius +variable {ι : Type*} [Fintype ι] [DecidableEq ι] + +lemma logdet_le_trace_sub_card {M : Matrix ι ι ℝ} (hM : M.PosDef) : + log M.det ≤ M.trace-(Fintype.card ι:ℝ) := by + rw [hM.isHermitian.det_eq_prod_eigenvalues,hM.isHermitian.trace_eq_sum_eigenvalues] + simp only [RCLike.ofReal_real_eq_id, id_eq] + rw [Real.log_prod (fun i _ => ne_of_gt (hM.eigenvalues_pos i))] + have ht := Finset.sum_le_sum (s := Finset.univ) (fun i _ => Real.log_le_sub_one_of_pos (hM.eigenvalues_pos i)) + simpa using ht + +lemma regularized_factorization (γ : ℝ) (M : Matrix ι ι ℝ) (hM : IsUnit M) : + regularizedGram γ M=Mᵀ*(1+γ • (M⁻¹ᵀ*M⁻¹))*M := by + have hi := (Matrix.isUnit_iff_isUnit_det M).mp hM + have h₁ := Matrix.nonsing_inv_mul M hi + have h₂ : Mᵀ*M⁻¹ᵀ=1 := by rw [← Matrix.transpose_mul,h₁,transpose_one] + unfold regularizedGram + simp only [mul_add,add_mul,mul_one,Matrix.mul_smul,Matrix.smul_mul] + rw [← mul_assoc Mᵀ M⁻¹ᵀ,h₂,one_mul,h₁] + +lemma regularizedLogDet_le_logdet {γ : ℝ} (hγ : 0 ≤ γ) (M : Matrix ι ι ℝ) (hM : IsUnit M) : + regularizedLogDet γ M ≤ 2*log M.det/(Fintype.card ι:ℝ)+ + γ*‖M⁻¹‖^2/(Fintype.card ι:ℝ) := by + let Q := 1+γ • (M⁻¹ᵀ*M⁻¹) + have hQ : Q.PosDef := Matrix.PosDef.one.add_posSemidef (by + simpa using (Matrix.posSemidef_conjTranspose_mul_self M⁻¹).smul hγ) + have hd : M.det ≠ 0 := (Matrix.isUnit_iff_isUnit_det M).mp hM |>.ne_zero + have hn : (0:ℝ) ≤ Fintype.card ι := Nat.cast_nonneg _ + have hl : log (regularizedGram γ M).det=2*log M.det+log Q.det := by + rw [regularized_factorization γ M hM,Matrix.det_mul,Matrix.det_mul,Matrix.det_transpose, + Real.log_mul (mul_ne_zero hd hQ.det_pos.ne') hd,Real.log_mul hd hQ.det_pos.ne'] + ring + have ht := logdet_le_trace_sub_card hQ + have hQt : Q.trace-(Fintype.card ι:ℝ)=γ*‖M⁻¹‖^2 := by + dsimp only [Q] + rw [Matrix.trace_add,Matrix.trace_one,Matrix.trace_smul,smul_eq_mul,← frobenius_sq_trace] + ring + rw [hQt] at ht + unfold regularizedLogDet + rw [hl,add_div] + exact add_le_add_right (div_le_div_of_nonneg_right ht hn) _ + +lemma frobenius_le_sqrt_card_opNorm (M : Matrix ι ι ℝ) : + ‖M‖ ≤ sqrt (Fintype.card ι:ℝ)*opNorm M := by + have hh := SKGap.frobenius_mul_le_opNorm_right (1:Matrix ι ι ℝ) M + have h1 : ‖(1:Matrix ι ι ℝ)‖=sqrt (Fintype.card ι:ℝ) := by + have hs := frobenius_sq_trace (1:Matrix ι ι ℝ) + simp only [transpose_one,one_mul,Matrix.trace_one] at hs + nlinarith [norm_nonneg (1:Matrix ι ι ℝ),sqrt_nonneg (Fintype.card ι:ℝ),sq_sqrt (Nat.cast_nonneg (Fintype.card ι))] + simpa only [one_mul,h1] using hh + +lemma regularizedLogDet_le_logdet_opNorm [Nonempty ι] {γ B : ℝ} (hγ : 0 ≤ γ) + (M : Matrix ι ι ℝ) (hM : IsUnit M) (hB : opNorm M⁻¹ ≤ B) : + regularizedLogDet γ M ≤ 2*log M.det/(Fintype.card ι:ℝ)+γ*B^2 := by + have hn : (0:ℝ) < Fintype.card ι := Nat.cast_pos.mpr Fintype.card_pos + have hb0 : 0 ≤ B := (norm_nonneg _).trans hB + apply (regularizedLogDet_le_logdet hγ M hM).trans + apply add_le_add_right + apply (div_le_iff₀ hn).mpr + have hf := (frobenius_le_sqrt_card_opNorm M⁻¹).trans (mul_le_mul_of_nonneg_left hB (sqrt_nonneg _)) + have hsq := sq_le_sq₀ (norm_nonneg _) (mul_nonneg (sqrt_nonneg _) hb0) |>.mpr hf + rw [mul_pow,sq_sqrt hn.le] at hsq + nlinarith [mul_le_mul_of_nonneg_left hsq hγ] + +lemma regularizedLogDet_zero [Nonempty ι] {γ : ℝ} (_hγ : 0 < γ) : + regularizedLogDet γ (0:Matrix ι ι ℝ)=log γ := by + have hn : (Fintype.card ι:ℝ) ≠ 0 := Nat.cast_ne_zero.mpr Fintype.card_ne_zero + simp only [regularizedLogDet,regularizedGram,transpose_zero,zero_mul,zero_add, + Matrix.det_smul,Matrix.det_one,mul_one,Real.log_pow] + exact mul_div_cancel_left₀ _ hn + +lemma regularizedLogDet_abs [Nonempty ι] {γ : ℝ} (hγ : 0 < γ) (M : Matrix ι ι ℝ) : + |regularizedLogDet γ M| ≤ |log γ|+‖M‖/sqrt ((Fintype.card ι:ℝ)*γ) := by + have hh := regularizedLogDet_lipschitz hγ M 0 + rw [sub_zero,regularizedLogDet_zero hγ] at hh + have ht := (show |regularizedLogDet γ M| ≤ |regularizedLogDet γ M-log γ|+|log γ| by + simpa only [sub_add_cancel] using abs_add_le (regularizedLogDet γ M-log γ) (log γ)).trans (add_le_add_left hh _) + simpa only [div_eq_mul_inv,one_mul,mul_comm,add_comm] using ht +end SKGap.LogDet +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Matrix/StartedMatrixEvent.lean b/lean/OAI/Probability/SKGap/Matrix/StartedMatrixEvent.lean new file mode 100644 index 0000000000000000000000000000000000000000..5f3846c5868a5bf85a9de54b99997d380420bc46 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Matrix/StartedMatrixEvent.lean @@ -0,0 +1,83 @@ +import Mathlib +import OAI.Probability.SKGap.Gaussian.GaussianRecipeEvent +import OAI.Probability.SKGap.Matrix.StartedWordClosure + +namespace OAI + +section + +noncomputable section +open scoped BigOperators Topology +namespace SKGapCutoff.Recipe +open Primary Matrix SKGap SKGap.Noncrossing SKGap.Noncrossing.Primary MeasureTheory ProbabilityTheory Real Set Filter +variable {n : ℕ} + +def StartedMatrixEvent (j R A₀ A c B W C : ℝ) (M Nmax : ℕ) (J : Interaction n) : Prop := + SKGap.opNorm J≤R ∧ (∀h x l,lh w (hw.trans hK) hi hb +lemma ClosedWordDiagramBound.mono {j A C : ℝ} {a : Fin n→ℝ} {J : Interaction n} {L K : ℕ} + (h : ClosedWordDiagramBound j a J A C L) (hK : K≤L) : ClosedWordDiagramBound j a J A C K := + fun w hw hi hb=>h w (hw.trans hK) hi hb + +theorem gaussian_started_matrix_event {j A₀ A c : ℝ} (hj : 0(Measure.pi (fun _ : MatrixCoordinates (Fin n)=>gaussianReal 0 1)) + {g | ¬StartedMatrixEvent j R A₀ A c B W C M Nmax + (removeDiagonal (goeMatrix (j/n) g))}) atTop (𝓝 0) := by + let R:=max A (2*sqrt j+1+1) + have hAR : A≤R:=le_max_left _ _ + have hR : 1≤R:=hA.trans hAR + obtain ⟨C,N,hC,hN,hclosed⟩:=closed_word_event hj hA₀ hs hA hAA hc (2*M+2*Nmax+5) + obtain ⟨B,N',hB,hN',hordinary⟩:=ordinary_word_event hj hj1 hA (2*M+2*Nmax+5) + obtain ⟨W,hW,htest⟩:=closed_word_test_budget hj.le hA₀.le + (by linarith : 0≤A) hc (by linarith : 0≤R) (2*M+2*Nmax+5) + refine ⟨R,primaryEventBudget j R B M,W+C,C,hR, + primaryEventBudget_nonneg (by linarith) hB.le _,by positivity,hC,?_⟩ + apply tendsto_of_tendsto_of_tendsto_of_le_of_le' tendsto_const_nhds + (show Tendsto (fun n=>recipeNormTail j n+ordinaryWordTail j (2*M+2*Nmax+5) n+ + ordinaryWordTail j (2*M+2*Nmax+5) n) atTop (𝓝 0) from by + simpa using ((recipeNormTail_limit hj).add (ordinaryWordTail_limit hj _)).add (ordinaryWordTail_limit hj _)) + (Filter.Eventually.of_forall (fun _=>bot_le)) + filter_upwards [eventually_ge_atTop (max N N')] with n hn + have hnN : N≤n:=(le_max_left ..).trans hn + have hnN' : N'≤n:=(le_max_right ..).trans hn + have hn0 : 0gaussianReal 0 1) + let V : Set (MatrixCoordinates (Fin n)→ℝ):={g | 2*sqrt j+1+1hh (.inl (.inl hbad)))).trans (le_max_right _ _) + have hu : WordSeminormBound (removeDiagonal (goeMatrix (j/n) g)) j A B (2*M+2*Nmax+5):=by + by_contra hbad; exact hh (.inl (.inr hbad)) + have hf : ClosedWordEvent j A₀ A c C (2*M+2*Nmax+5) (removeDiagonal (goeMatrix (j/n) g)):=by + by_contra hbad; exact hh (.inr hbad) + apply hg + refine ⟨hJ,fun h x l hl=>wordEvent_formal _ hn0 (by linarith) hB.le hA hJ M _ (by omega) hu h x l hl,?_⟩ + intro a ha hstable + have hb:=hf a ha hstable + have hsym : (removeDiagonal (goeMatrix (j/n) g))ᵀ=removeDiagonal (goeMatrix (j/n) g) := by + simp only [removeDiagonal,transpose_sub,diagonal_transpose,goeMatrix_transpose] + exact ⟨(htest n hn0 a _ C ha hsym hJ hstable hb).mono (by omega),hb.diagram.mono (by omega)⟩ + +end SKGapCutoff.Recipe + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Matrix/StartedNodeTrace.lean b/lean/OAI/Probability/SKGap/Matrix/StartedNodeTrace.lean new file mode 100644 index 0000000000000000000000000000000000000000..feed843e0ae851b1411e68ff46a16c2d0c1acbea --- /dev/null +++ b/lean/OAI/Probability/SKGap/Matrix/StartedNodeTrace.lean @@ -0,0 +1,148 @@ +import Mathlib +import OAI.Probability.SKGap.Stability.StableFields +import OAI.Probability.SKGap.Stability.OrdinaryRecipe +import OAI.Probability.SKGap.Matrix.ClosedErrorTrace +import OAI.Probability.SKGap.Localization.StartedGraph + +namespace OAI + +section + +noncomputable section +open scoped BigOperators Matrix.Norms.Frobenius +namespace SKGapCutoff.Recipe.OrdinaryData +open Primary Matrix SKGap.Noncrossing.Primary +variable {n : ℕ} {ι κ σ : Type*} [Fintype ι] [DecidableEq ι] [Fintype κ] [DecidableEq κ] [Fintype σ] +variable (D : OrdinaryData n ι κ σ) (w y : VectorFields n) + +def startedNodeSourceError (T : ι→SourceTree (Fin n→ℝ)) (x : Spin n) (a : ℕ) : Interaction n := + D.sourceAtoms a (fun b=>D.startedAuxiliary w y b) x+ + ∑l,Matrix.diagonal (D.startedPartial w y a l x)* + (derivativeMatrix (D.H l) x-SourceTree.fieldMatrix D.j D.J (T l)) +def startedNodeFieldError (T : ι→SourceTree (Fin n→ℝ)) (x : Spin n) (a : ℕ) : Interaction n := + -(∑l,(D.j*siteMean (D.startedPartial w y a l) x) • + (derivativeMatrix (D.predecessor l) x-SourceTree.sourceMatrix D.j D.J (T l)))- + D.j • ((∑l,averageError (siteMean (D.startedPartial w y a l)) (D.predecessor l) x)+ + ∑b:Fin a,averageError (siteMean (D.auxCoefficient a b)) (D.startedSource w y b) x) + +lemma startedNodeSource_control (T : ι→SourceTree (Fin n→ℝ)) (x : Spin n) (a : ℕ) + {C Q R L V Z : ℝ} {B : Fin a→ℝ} {Cp E : ι→ℝ} + (hC : 0≤C) (hQ : 0≤Q) (hR : 0≤R) (hL : 0≤L) (hV : 0≤V) + (hY : ∀b:Fin a,SmallBound (D.startedAuxiliary w y b) x (B b)) + (hp : ∀l,SmallBound (D.startedPartial w y a l) x (Cp l)) + (hE : ∀l,‖derivativeMatrix (D.H l) x-SourceTree.fieldMatrix D.j D.J (T l)‖≤E l) + (hs : ∀s,SegmentRegular D.H D.θ (D.seedFunction a s) (D.seedDerivative a s) x C) + (ha : ∀b,SegmentRegular D.H D.θ (D.auxFunction a b) (D.auxDerivative a b) x C) + (ht : vectorNorm (parameterIncrement D.θ x)≤V) + (hQ4 : (∑i,∑k,(primaryIncrement D.H x i k)^4)≤Q^4) + (hQr : ∀i,(∑k,(primaryIncrement D.H x i k)^2)≤R^2) + (hQd : (∑i,(primaryIncrement D.H x i i)^2)≤L^2) + (hZ : (∑α,‖derivativeVector (D.θ α) x‖)+4*(Q^2+R*V+V^2)+2*(Q+L+V)≤Z) : + TraceControl (D.startedNodeSourceError w y T x a) + (((∑s,C*vectorNorm (D.seed s)*Z)+(∑b:Fin a,C*B b*Z))+∑l,Cp l*E l) := by + have hc (s : VectorFields n) {S : ℝ} (hS : SmallBound s x S) + (F : Fin n→Args (ι:=ι) (κ:=κ)→ℝ) + (F' : Fin n→Args (ι:=ι) (κ:=κ)→Args (ι:=ι) (κ:=κ)→L[ℝ]ℝ) + (hF : SegmentRegular D.H D.θ F F' x C) : TraceControl (sourceError D.H D.θ F F' s x) (C*S*Z) := + (sourceError_control D.H D.θ F F' s x hF hS.nonneg hV hQ hR hL hS.size hS.derivative ht hQ4 hQr hQd).mono + (mul_le_mul_of_nonneg_left hZ (mul_nonneg hC hS.nonneg)) + have hs' := TraceControl.sum (fun s=>hc (fun _=>D.seed s) (SmallBound.seed _ x) _ _ (hs s)) + have ha' := TraceControl.sum (fun b:Fin a=>hc (D.startedAuxiliary w y b) (hY b) _ _ (ha b)) + have hp' := TraceControl.sum (fun l=>(small_diagonal_control + (derivativeMatrix (D.H l) x-SourceTree.fieldMatrix D.j D.J (T l)) (D.startedPartial w y a l x)).mono + (mul_le_mul (hp l).size (hE l) (norm_nonneg _) (hp l).nonneg)) + exact (hs'.add ha').add hp' + +lemma startedNodeField_control (T : ι→SourceTree (Fin n→ℝ)) (x : Spin n) (a : ℕ) (hn : 0if a=0 then C+F else Cs a + let Bf:=fun a=>if a=0 then |q| *(C+F)+F else Cf a + ∀a≤N, + (∀v:OrdinaryWord n,v.length+2*a+1≤L→wordBounded A v→ + |trace (matrixWord D.J v*D.startedSourceError w y T t₀ a₀ x a)|≤(errorBudget R Bs Bf a).1*M) ∧ + (∀v:OrdinaryWord n,v.length+2*a+2≤L→wordBounded A v→ + |trace (matrixWord D.J v*D.startedFieldError w y T t₀ a₀ x a)|≤(errorBudget R Bs Bf a).2*M) := by + let Es:=fun a=>if a=0 then D.startedSourceError w y T t₀ a₀ x 0 else D.startedNodeSourceError w y T x a + let Ef:=fun a=>if a=0 then (-q) • Es 0+Q else D.startedNodeFieldError w y T x a + apply closed_finite_graph_trace D.j a₀ D.J + (D.startedSourceError w y T t₀ a₀ x) (D.startedFieldError w y T t₀ a₀ x) + Es Ef P Q q (fun a b=>D.auxCoefficient a b x) (fun a b=>D.j*siteMean (D.auxCoefficient a b) x) + _ _ _ _ hP hQ hR hM ha hp hr _ _ hw + · intro a + by_cases ha0:a=0 + · subst a;simp [Es] + · rw [D.started_source_error_recursion w y T t₀ a₀ x (Nat.pos_of_ne_zero ha0)] + simp only [Es,ite_eq_right ha0,startedNodeSourceError] + abel + · intro a + by_cases ha0:a=0 + · subst a + simp only [Ef,Es,ite_true,Finset.univ_eq_empty,Finset.sum_empty,sub_zero] + rw [hF₀,sub_mul,smul_mul_assoc,one_mul,neg_smul] + abel + · rw [D.started_field_error_recursion w y T t₀ a₀ x (Nat.pos_of_ne_zero ha0)] + simp only [Ef,ite_eq_right ha0,startedNodeFieldError] + · simpa only [Es,ite_true] using hE₀ + · rfl + · intro a haN ha0;simpa only [Es,ite_eq_right (by omega : a≠0)] using hs a haN ha0 + · intro a haN ha0;simpa only [Ef,ite_eq_right (by omega : a≠0)] using hf a haN ha0 + +end SKGapCutoff.Recipe.OrdinaryData + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Matrix/StartedTraceBudget.lean b/lean/OAI/Probability/SKGap/Matrix/StartedTraceBudget.lean new file mode 100644 index 0000000000000000000000000000000000000000..69fecea05b1bdee1ac611d1eecc0eb6a05a6cda8 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Matrix/StartedTraceBudget.lean @@ -0,0 +1,102 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.LocalStartedDiagonal + +namespace OAI + +section + +noncomputable section +open scoped BigOperators +namespace SKGapCutoff.Recipe +open Primary Matrix SKGap SKGap.Noncrossing SKGap.Noncrossing.Primary SKGap.Noncrossing.Primary.Tensor.Series +open SKGap.Noncrossing.ClosedMarked +variable {n : ℕ} + +def startedTraceBudget (c k : ℝ) (W : ℕ→ℝ) (B : ℝ) (a : ℕ) : ℝ := + c*W a+k*∑b:Fin a,startedTraceBudget c k W B b+B +termination_by a +lemma startedTraceBudget_nonneg {c k B : ℝ} {W : ℕ→ℝ} + (hc : 0≤c) (hk : 0≤k) (hW : ∀a,0≤W a) (hB : 0≤B) (a : ℕ) : + 0≤ startedTraceBudget c k W B a := by + induction a using Nat.strong_induction_on with + | h a ih => + rw [startedTraceBudget] + exact add_nonneg (add_nonneg (mul_nonneg hc (hW a)) + (mul_nonneg hk (Finset.sum_nonneg fun b _=>ih b b.isLt))) hB +lemma startedTraceBudget_ge {c k B : ℝ} {W : ℕ→ℝ} + (hc : 0≤c) (hk : 0≤k) (hW : ∀a,0≤W a) (hB : 0≤B) (a : ℕ) : + B≤ startedTraceBudget c k W B a := by + rw [startedTraceBudget] + exact le_add_of_nonneg_left (add_nonneg (mul_nonneg hc (hW a)) + (mul_nonneg hk (Finset.sum_nonneg fun b _=>startedTraceBudget_nonneg hc hk hW hB b))) + +namespace OrdinaryData +variable {ι κ σ : Type*} [Fintype ι] [DecidableEq ι] [Fintype κ] [DecidableEq κ] [Fintype σ] +variable (D : OrdinaryData n ι κ σ) + +theorem startedMarked_budget (w y : VectorFields n) (T : ι→SourceTree (Fin n→ℝ)) + (t₀ : SmallTree n) (a₀ : Fin n→ℝ) (x : Spin n) (N : ℕ) + (W : ℕ→ℝ) {A Q B : ℝ} (hA : 0≤A) (hQ : 0≤Q) (hB : 0≤B) (hW : ∀a,0≤W a) + (hinit : pairBudget (t₀.marked D.j a₀)≤B) + (hp : ∀a≤N,∀l,vectorNorm (D.startedPartial w y a l x)≤W a) + (hm : ∀l,Marked.mass (GradedWords.ordinaryWords D.j (T l)).1≤Q ∧ + Marked.mass (GradedWords.ordinaryWords D.j (T l)).2≤Q) + (ha : ∀a≤N,∀b:Fin a,|siteMean (D.auxCoefficient a b) x|≤A) : + ∀a≤N,pairBudget ((D.startedSmallTree w y T t₀ x a).marked D.j a₀)≤ + startedTraceBudget ((Fintype.card ι:ℝ)*((2+|D.j|)*Q)) (2+|D.j| *A) W B a := by + let L : ℝ:=(2+|D.j|)*Q + let K : ℝ:=2+|D.j| *A + have hL : 0≤L:=by dsimp [L];positivity + have hK : 0≤K:=by dsimp [K];positivity + have hc : 0≤(Fintype.card ι:ℝ)*L:=mul_nonneg (Nat.cast_nonneg _) hL + intro a + induction a using Nat.strong_induction_on with + | h a ih => + intro haN + rcases a with _|r + · simpa only [startedSmallTree] using hinit.trans (startedTraceBudget_ge hc hK hW hB 0) + · rw [startedSmallTree,SmallTree.smallBranches_budget] + have hsmall : (List.map (fun t : (Fin n→ℝ)×ClosedTree (Fin n→ℝ)=>vectorNorm t.1* + (2*Marked.mass (t.2.words D.j a₀).2+|D.j| *Marked.mass (t.2.words D.j a₀).1)) + (Finset.univ.toList.map (fun l=>(D.startedPartial w y (r+1) l x,ClosedTree.ofOrdinary (T l))))).sum≤ + (Fintype.card ι:ℝ)*(L*W (r+1)) := by + simp only [List.map_map,Function.comp_def,ClosedTree.words_ofOrdinary] + simp only [Finset.sum_map_toList] + have hs : (∑l:ι,vectorNorm (D.startedPartial w y (r+1) l x)* + (2*Marked.mass (GradedWords.ordinaryWords D.j (T l)).2+|D.j| *Marked.mass (GradedWords.ordinaryWords D.j (T l)).1))≤∑_l:ι,L*W (r+1) := by + apply Finset.sum_le_sum + intro l _ + have hc' : 2*Marked.mass (GradedWords.ordinaryWords D.j (T l)).2+ + |D.j| *Marked.mass (GradedWords.ordinaryWords D.j (T l)).1≤L := by + nlinarith [(hm l).2,mul_le_mul_of_nonneg_left (hm l).1 (abs_nonneg D.j)] + exact (mul_le_mul_of_nonneg_left hc' (vectorNorm_nonneg _)).trans + (by simpa [mul_comm] using mul_le_mul_of_nonneg_right (hp (r+1) haN l) hL) + simpa using hs + have H:=SmallTree.boundedBranches_budget D.j a₀ + (Finset.univ.toList.map (fun b:Fin (r+1)=>(D.auxCoefficient (r+1) b x,D.startedSmallTree w y T t₀ x b))) .zero + (A:=A) (by + intro t ht + obtain ⟨b,hb,rfl⟩:=List.mem_map.mp ht + simpa only [siteMean,Diagram.mean,Fintype.card_fin] using ha (r+1) haN b) + have hzero : pairBudget ((SmallTree.zero (n:=n)).marked D.j a₀)=0 := by + simp [SmallTree.marked,zeroPair,pairBudget,Marked.budget,Mark.vector] + rw [hzero,add_zero] at H + simp only [List.map_map,Function.comp_def] at H + have hs : (List.map (fun b:Fin (r+1)=>K*pairBudget ((D.startedSmallTree w y T t₀ x b).marked D.j a₀)) + Finset.univ.toList).sum≤K*∑b:Fin (r+1),startedTraceBudget ((Fintype.card ι:ℝ)*L) K W B b := by + simp only [Finset.sum_map_toList] + rw [Finset.mul_sum] + exact Finset.sum_le_sum fun b _=>mul_le_mul_of_nonneg_left (ih b b.isLt (b.isLt.le.trans haN)) hK + have H' := H.trans hs + apply (add_le_add hsmall H').trans + rw [startedTraceBudget] + change (Fintype.card ι:ℝ)*(L*W (r+1))+K*∑b:Fin (r+1),startedTraceBudget ((Fintype.card ι:ℝ)*L) K W B b≤_ + nlinarith only [hB] + +end OrdinaryData +end SKGapCutoff.Recipe + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Matrix/StartedWordClosure.lean b/lean/OAI/Probability/SKGap/Matrix/StartedWordClosure.lean new file mode 100644 index 0000000000000000000000000000000000000000..7c58f82ca3e086256c283e19f0fc0b0521637daf --- /dev/null +++ b/lean/OAI/Probability/SKGap/Matrix/StartedWordClosure.lean @@ -0,0 +1,169 @@ +import Mathlib +import OAI.Probability.SKGap.Stability.OrdinaryWordEvent +import OAI.Probability.SKGap.Matrix.StartedTraceBudget +import OAI.Probability.SKGap.Localization.ClosedMarkedControl +import OAI.Probability.SKGap.Localization.StartedSmall + +namespace OAI + +section + +noncomputable section +open scoped BigOperators +namespace SKGapCutoff.Recipe +open Primary Matrix SKGap SKGap.Noncrossing SKGap.Noncrossing.Primary SKGap.Noncrossing.Primary.Tensor.Series +open SKGap.Noncrossing.ClosedMarked +variable {n : ℕ} + +def ClosedWordDiagramBound (j : ℝ) (a : Fin n→ℝ) (J : Interaction n) (A B : ℝ) (L : ℕ) : Prop := + ∀w:List (WordLetter (Fin n)),w.length≤L→inverseCount w≤1→closedWordBounded A w→ + diagonalSeminorm (exactWord j a w J-Matrix.diagonal (wordPrediction j a 1 w))≤B + +def initialTraceBudget (j A B Q : ℝ) : ℝ := (2+|j| *A)*(B*((1+|j|)*Q))+|j| *B*Q +lemma initialTraceBudget_nonneg {j A B Q : ℝ} (hA : 0≤A) (hB : 0≤B) (hQ : 0≤Q) : + 0≤ initialTraceBudget j A B Q := by unfold initialTraceBudget;positivity + +namespace OrdinaryData +variable {ι κ σ κ₀ σ₀ : Type*} [Fintype ι] [DecidableEq ι] [Fintype κ] [DecidableEq κ] [Fintype σ] +variable [Fintype κ₀] [DecidableEq κ₀] [Fintype σ₀] +variable (D : OrdinaryData n ι κ σ) (I : OrdinaryData n Unit κ₀ σ₀) + +theorem implicit_started_word_closure (w y : VectorFields n) (T : ι→SourceTree (Fin n→ℝ)) (t : SourceTree (Fin n→ℝ)) + (hj : D.j=I.j) (hJ : D.J=I.J) (x : Spin n) (N L : ℕ) (c : LocalConstants) + (h : LocalOrdinaryInput D T x N c) + (hW : w x=I.sourceOf 1 (fun _=>y) x) (hWf : ∀i,w (flip x i)=I.sourceOf 1 (fun _=>y) (flip x i)) + (hY : y x=I.fieldOf 1 (fun _=>w) (fun _=>y) x) (hYf : ∀i,y (flip x i)=I.fieldOf 1 (fun _=>w) (fun _=>y) (flip x i)) + (ha0 : ∀i,0≤I.implicitCoefficient x i) + (hS : (1-SKGap.pathDiagonal (I.implicitCoefficient x) 1* + (I.J-(I.j*siteMean I.implicitCoefficient x) • 1)*SKGap.pathDiagonal (I.implicitCoefficient x) 1).PosDef) + {C F B₀ M B Q : ℝ} (hB₀ : 0≤B₀) (hM : 0≤M) (hB : 0≤B) (hQ : 0≤Q) + (hw₀ : SmallBound w x B₀) (hy₀ : SmallBound y x B₀) (hp₀ : vectorNorm (I.implicitPartial y x)≤B₀) + (hP : TraceControl (I.implicitSourcePrimitive t y x) C) + (hF : TraceControl (I.implicitFieldPrimitive t w y x) F) + (ha : ∀i,|I.implicitCoefficient x i|≤c.A) + (hm : ∀l,Marked.mass (GradedWords.ordinaryWords D.j (T l)).1≤Q ∧ Marked.mass (GradedWords.ordinaryWords D.j (T l)).2≤Q) + (hm₀ : Marked.mass (GradedWords.ordinaryWords D.j t).1≤Q ∧ Marked.mass (GradedWords.ordinaryWords D.j t).2≤Q) + (hT : ∀l,GradedControl c.A L (GradedWords.ordinaryWords D.j (T l)).1 ∧ GradedControl c.A L (GradedWords.ordinaryWords D.j (T l)).2) + (ht : GradedControl c.A L (GradedWords.ordinaryWords D.j t).1 ∧ GradedControl c.A L (GradedWords.ordinaryWords D.j t).2) + (hw : ClosedWordTestBound D.j (I.implicitCoefficient x) D.J c.A M (2*N+5)) + (hd : ClosedWordDiagramBound D.j (I.implicitCoefficient x) D.J c.A B (L+2*N+3)) : + let W:=c.startedNormBudget D.j (Fintype.card ι) B₀ + let R:=errorBudget (|D.j| *c.A) + (fun a=>if a=0 then C+F else c.startedSourceCost D.j (Fintype.card ι) (Fintype.card σ) B₀ a) + (fun a=>if a=0 then |I.j*siteMean I.implicitCoefficient x| *(C+F)+F else c.startedFieldCost D.j (Fintype.card ι) B₀ a) + let V:=startedTraceBudget ((Fintype.card ι:ℝ)*((2+|D.j|)*Q)) (2+|D.j| *c.A) W (initialTraceBudget D.j c.A B₀ Q) + ∀a≤N,SmallBound (D.startedSource w y a) x (W a) ∧ + (∀l,SmallBound (D.startedPartial w y a l) x (W a)) ∧ + (∑i,|derivativeMatrix (D.startedSource w y a) x i i|)≤V a*B+(R a).1*M := by + dsimp only + let t₀:SmallTree n:=.implicit (I.implicitPartial y x) t + let a₀:=I.implicitCoefficient x + let W:=c.startedNormBudget D.j (Fintype.card ι) B₀ + have hwsmall:=h.started_small hB₀ hw₀ hy₀ + have htrace:=D.implicit_started_diagonal_local I w y T t hj hJ x hW hWf hY hYf h.dimension ha0 hS hP hF + (mul_nonneg (abs_nonneg _) c.A_nonneg) hM hB c.one_le_A ha h.auxValue + (fun a haN b=>by rw [abs_mul];exact mul_le_mul_of_nonneg_left (h.mean_bound a haN b) (abs_nonneg _)) + (fun a haN _=>h.started_source_control hB₀ hw₀ hy₀ a haN) + (fun a haN _=>h.started_field_control hB₀ hw₀ hy₀ a haN) hw (by + intro a haN d hd' P hP' v hv + have hc:=D.startedMarked_control w y T t₀ a₀ x N L c.one_le_A + (implicitPair_control D.j a₀ _ t c.one_le_A ha ht) hT h.auxValue a haN + have hcontrol : SKGap.Noncrossing.ClosedMarked.MarkControl c.A (L+2*a+3) v.2 := by + simp only [List.mem_cons,List.not_mem_nil,or_false] at hP' + rcases hP' with rfl|rfl + · exact hc.1 v hv + · exact hc.2 v hv + have hinv : inverseCount (v.2.diagnostic d)≤1 := by + rw [Mark.diagnostic_inverse] + have hb:=(D.startedSmallTree w y T t₀ x a).plain D.j a₀ + simp only [List.mem_cons,List.not_mem_nil,or_false] at hP' + rcases hP' with rfl|rfl + · exact Marked.bounded_of_plain _ _ (congrArg Prod.fst hb) + ((D.startedSmallTree w y T t₀ x a).tree.words_bounded D.j a₀).1 v hv + · exact Marked.bounded_of_plain _ _ (congrArg Prod.snd hb) + ((D.startedSmallTree w y T t₀ x a).tree.words_bounded D.j a₀).2 v hv + exact hd _ ((hcontrol d hd').2.trans (by omega)) hinv (hcontrol d hd').1) + have hi:pairBudget (t₀.marked D.j a₀)≤ initialTraceBudget D.j c.A B₀ Q := by + apply implicitPair_budget_le D.j a₀ _ t hp₀ hQ hm₀ + simpa only [siteMean,Diagram.mean,Fintype.card_fin] using coefficient_mean_value I.implicitCoefficient x c.A_nonneg ha + have hb:=D.startedMarked_budget w y T t₀ a₀ x N W c.A_nonneg hQ + (initialTraceBudget_nonneg c.A_nonneg hB₀ hQ) (fun a=>c.startedNormBudget_nonneg D.j _ a hB₀) + hi (fun a haN l=>(hwsmall a haN).2.2 l |>.size) hm h.mean_bound + intro a haN + have haB: ((D.startedSmallTree w y T t₀ x a).marked D.j a₀).1.budget≤ + startedTraceBudget ((Fintype.card ι:ℝ)*((2+|D.j|)*Q)) (2+|D.j| *c.A) W (initialTraceBudget D.j c.A B₀ Q) a := + (le_add_of_nonneg_right (Marked.budget_nonneg _)).trans (hb a haN) + exact ⟨(hwsmall a haN).1,(hwsmall a haN).2.2, + ((htrace a haN).1).trans (add_le_add (mul_le_mul_of_nonneg_right haB hB) le_rfl)⟩ +end OrdinaryData +end SKGapCutoff.Recipe + +end +end + +section + +noncomputable section +open scoped BigOperators +namespace SKGapCutoff.Recipe +open Matrix SKGap SKGap.Noncrossing SKGap.Noncrossing.Primary MeasureTheory ProbabilityTheory Real Set +variable {n : ℕ} + +lemma closedWordBounded_iff (A : ℝ) (w : List (WordLetter (Fin n))) : + closedWordBounded A w ↔ ∀l∈w,l.bounded A := by + constructor <;> intro h l hl <;> cases l <;> exact h _ hl + +def ClosedWordSeminormBound (j : ℝ) (a : Fin n→ℝ) (J : Interaction n) + (A C : ℝ) (L : ℕ) : Prop := + ∀(p : Bool) (w : List (WordLetter (Fin n))),w.length≤L→inverseCount w≤1→closedWordBounded A w→ + matrixWordSeminorm p (exactWord j a w J-Matrix.diagonal (wordPrediction j a 1 w))≤C + +lemma ClosedWordSeminormBound.mono {j A C : ℝ} {a : Fin n→ℝ} {J : Interaction n} {L K : ℕ} + (h : ClosedWordSeminormBound j a J A C L) (hK : K≤L) : + ClosedWordSeminormBound j a J A C K := fun p w hw hi hb=>h p w (hw.trans hK) hi hb + +lemma ClosedWordSeminormBound.diagram {j A C : ℝ} {a : Fin n→ℝ} {J : Interaction n} {L : ℕ} + (h : ClosedWordSeminormBound j a J A C L) : ClosedWordDiagramBound j a J A C L := h false + +def ClosedWordEvent (j A D c C : ℝ) (L : ℕ) (J : Interaction n) : Prop := + ∀a:Fin n→ℝ,(∀i,a i∈Icc 0 A)→ + c≤ComplexSpectral.lowerRayleigh (RealComplex.liftMatrix (stabilityMatrix a 1 ((j/n)*∑i,a i) J))→ + ClosedWordSeminormBound j a J D C L + +theorem closed_word_event {j A D c : ℝ} (hj : 0gaussianReal 0 1)) + {g | ¬ClosedWordEvent j A D c C L (removeDiagonal (goeMatrix (j/n) g))}≤ + 2*((wordPatternSet L L).card*ENNReal.ofReal (3*exp (-(n:ℝ)))+ + ENNReal.ofReal (exp (-2*(n:ℝ)/(π^2*(sqrt (2*j))^2)))+ + (ENNReal.ofReal (2*exp (-(n:ℝ)/(π^2*j)))+ + ENNReal.ofReal (2*(n:ℝ)*exp (-1/(8*(j/n)))))) := by + obtain ⟨C,N,hC,hN,hb⟩:=zeroDiag_exact_words_two_seminorms hj hA hs hD hAD hc L + refine ⟨C,N,hC,hN,fun n hn=>?_⟩ + apply (measure_mono ?_).trans (hb n hn) + intro g hg + simp only [ClosedWordEvent,ClosedWordSeminormBound,not_forall,not_le] at hg + obtain ⟨a,ha,hstable,p,w,hw,hi,hwb,hfail⟩:=hg + exact ⟨p,a,w,ha,hw,(closedWordBounded_iff D w).mp hwb,hi,Or.inr hstable,hfail⟩ + +theorem closed_word_test_budget {j A D c R : ℝ} (hj : 0≤j) (hA : 0≤A) + (hD : 0≤D) (hc : 0 gibbsExpectation J (fun x => spin x i*spin x j) + +lemma staticCovarianceMatrix_diag {n : ℕ} (J : Interaction n) (i : Fin n) : + staticCovarianceMatrix J i i=1 := by + simp only [staticCovarianceMatrix,← sq,spin_sq,gibbsExpectation_const] + +lemma staticCovarianceMatrix_trace {n : ℕ} (J : Interaction n) : + Matrix.trace (staticCovarianceMatrix J)=(n:ℝ) := by + simp [Matrix.trace,staticCovarianceMatrix_diag] + +lemma trace_mul_staticCovarianceMatrix {n : ℕ} (J A : Interaction n) : + Matrix.trace (A*staticCovarianceMatrix J) = + gibbsExpectation J (fun x => ∑ i, spin x i*(A *ᵥ spin x) i) := by + simp only [Matrix.trace,Matrix.diag,Matrix.mul_apply,staticCovarianceMatrix, + Matrix.mulVec,dotProduct,Finset.mul_sum,gibbsExpectation_sum] + apply Finset.sum_congr rfl + intro i _ + apply Finset.sum_congr rfl + intro j _ + rw [← gibbsExpectation_mul_const] + congr 1 + funext x + ring + +noncomputable def normalizedStaticCovarianceTrace {n : ℕ} (J A : Interaction n) : ℝ := + Matrix.trace (A*staticCovarianceMatrix J)/(n:ℝ) + +lemma normalizedStaticCovarianceTrace_self {n : ℕ} (g : GaussianCoordinates n) : + normalizedStaticCovarianceTrace (sampledInteraction g) (sampledInteraction g) = + Regression.gibbsSpinEnergyAverage g := by + rw [normalizedStaticCovarianceTrace,trace_mul_staticCovarianceMatrix] + simp only [Regression.gibbsSpinEnergyAverage,Regression.spinEnergyAverage, + Regression.gaugedField,field,Matrix.mulVec,dotProduct,gibbsExpectation,Finset.sum_div,mul_div_assoc] + +lemma normalizedStaticCovarianceTrace_square {n : ℕ} (g : GaussianCoordinates n) : + normalizedStaticCovarianceTrace (sampledInteraction g) ((sampledInteraction g)^2) = + Regression.gibbsSpinFieldSquareAverage g := by + rw [normalizedStaticCovarianceTrace,trace_mul_staticCovarianceMatrix] + have he (x : Spin n) : (∑ i, spin x i*((sampledInteraction g)^2 *ᵥ spin x) i) = + ∑ i, Regression.gaugedField x g i^2 := by + have hgauge (i : Fin n) : Regression.gaugedField x g i^2 = + ((sampledInteraction g) *ᵥ spin x) i^2 := by + simp only [Regression.gaugedField,mul_pow,spin_sq,one_mul] + rfl + simp_rw [hgauge] + rw [pow_two,← Matrix.mulVec_mulVec] + change dotProduct (spin x) ((sampledInteraction g) *ᵥ ((sampledInteraction g) *ᵥ spin x)) = _ + rw [dotProduct_mulVec] + have hvec : spin x ᵥ* sampledInteraction g = sampledInteraction g *ᵥ spin x := by + ext i + simp only [Matrix.vecMul,Matrix.mulVec,dotProduct] + apply Finset.sum_congr rfl + intro j _ + rw [sampledInteraction_symm g j i,mul_comm] + rw [hvec] + simp only [dotProduct,pow_two] + + simp_rw [he] + simp only [Regression.gibbsSpinFieldSquareAverage,Regression.spinFieldSquareAverage, + gibbsExpectation,Finset.sum_div,mul_div_assoc] + +lemma normalizedStaticCovarianceTrace_one {n : ℕ} (hn : 0 disorderLaw β n {g | ε ≤ |normalizedStaticCovarianceTrace + (sampledInteraction g) (β⁻¹ • sampledInteraction g)-β|}) atTop (nhds 0) := by + have hh := Regression.gibbsSpinEnergyAverage_limit β hβ hβ1 (β*ε) (by positivity) + convert! hh using 1 + funext n + congr 1 + ext g + simp only [Set.mem_ofPred_eq] + rw [normalizedStaticCovarianceTrace_smul,normalizedStaticCovarianceTrace_self] + have he : β⁻¹*Regression.gibbsSpinEnergyAverage g-β = + (Regression.gibbsSpinEnergyAverage g-β^2)/β := by field_simp + simp only [he,abs_div,abs_of_pos hβ] + exact (le_div_iff₀ hβ).trans (by rw [mul_comm ε β]) + +theorem staticCovariance_P2_limit (β : ℝ) (hβ : 0<β) (hβ1 : β<1) + (ε : ℝ) (hε : 0<ε) : + Tendsto (fun n => disorderLaw β n {g | ε ≤ |normalizedStaticCovarianceTrace + (sampledInteraction g) ((β⁻¹ • sampledInteraction g)^2-1)-β^2|}) atTop (nhds 0) := by + have hh := Regression.gibbsSpinFieldSquareAverage_limit β hβ hβ1 (β^2*ε) (by positivity) + apply hh.congr' + filter_upwards [eventually_gt_atTop 0] with n hn + congr 1 + ext g + simp only [Set.mem_ofPred_eq] + rw [normalizedStaticCovarianceTrace_sub,smul_pow,normalizedStaticCovarianceTrace_smul, + normalizedStaticCovarianceTrace_square,normalizedStaticCovarianceTrace_one hn] + have he : (β⁻¹)^2*Regression.gibbsSpinFieldSquareAverage g-1-β^2 = + (Regression.gibbsSpinFieldSquareAverage g-(β^2+β^4))/β^2 := by field_simp; ring + simp only [he,abs_div,abs_of_pos (sq_pos_of_pos hβ)] + exact ((le_div_iff₀ (sq_pos_of_pos hβ)).trans (by rw [mul_comm ε (β^2)])).symm + +end SKGapCutoff +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Matrix/TanhMatrixBounds.lean b/lean/OAI/Probability/SKGap/Matrix/TanhMatrixBounds.lean new file mode 100644 index 0000000000000000000000000000000000000000..2637e9a97b7ef5817dd12685717d2a9dfc0b7fa2 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Matrix/TanhMatrixBounds.lean @@ -0,0 +1,131 @@ +import Mathlib +import OAI.Probability.SKGap.Matrix.GOESubmatrix +import OAI.Probability.SKGap.Localization.TanhCubic + +namespace OAI + +section +noncomputable section +namespace SKGap +open Matrix Real +open scoped BigOperators RealInnerProductSpace Matrix.Norms.L2Operator +variable {ι : Type*} [Fintype ι] [DecidableEq ι] + +lemma matrix_l2_norm_le_row (A : Matrix ι ι ℝ) (hA : ∀ i k,A i k=A k i) + {R : ℝ} (hR : 0 ≤ R) (hrow : ∀ i,∑ k,|A i k| ≤ R) : ‖A‖ ≤ R := by + rw [← Matrix.l2_opNorm_toEuclideanCLM,← matrixOperator_eq_toEuclideanCLM] + exact matrixOperator_norm_le_row A hA hR hrow + +lemma tanh_matrix_Q_norm (A : Matrix ι ι ℝ) (hA : ∀ i k,A i k=A k i) + {R : ℝ} (hR : 0 ≤ R) (hrow : ∀ i,∑ k,A i k^2 ≤ R) : + ‖Matrix.of (fun i k=>tanh (A i k)^2)‖ ≤ R := by + apply matrix_l2_norm_le_row _ (fun i k=>by simp only [of_apply,hA i k]) hR + intro i + apply le_trans _ (hrow i) + apply Finset.sum_le_sum + intro k _ + simp only [of_apply,abs_of_nonneg (sq_nonneg (tanh (A i k)))] + simpa only [sq_abs] using (sq_le_sq₀ (abs_nonneg _) (abs_nonneg _)).mpr (abs_tanh_le_abs (A i k)) + +lemma tanh_matrix_remainder_norm (A : Matrix ι ι ℝ) (hA : ∀ i k,A i k=A k i) + {R d : ℝ} (hR : 0 ≤ R) (hd : 0 ≤ d) (hma : ∀ i k,|A i k| ≤ d) + (hrow : ∀ i,∑ k,A i k^2 ≤ R) : + ‖Matrix.of (fun i k=>tanh (A i k))-A‖ ≤ d*R/3 := by + apply matrix_l2_norm_le_row _ (fun i k=>by simp only [Matrix.sub_apply,of_apply,hA i k]) (by positivity) + intro i + calc + _ ≤ ∑ k,d*(A i k)^2/3 := Finset.sum_le_sum (fun k _=>by + apply (tanh_cubic_error (A i k)).trans + have h := mul_le_mul_of_nonneg_right (hma i k) (sq_nonneg (A i k)) + have he : |A i k|^3=|A i k| *(A i k)^2 := by rw [pow_succ,sq_abs];ring + rw [he] + linarith only [h]) + _ = d*(∑ k,A i k^2)/3 := by rw [Finset.mul_sum,Finset.sum_div] + _ ≤ d*R/3 := div_le_div_of_nonneg_right (mul_le_mul_of_nonneg_left (hrow i) hd) (by norm_num) + +omit [DecidableEq ι] in +lemma tanh_matrix_fourth_row (A : Matrix ι ι ℝ) {R d : ℝ} + (hma : ∀ i k,|A i k| ≤ d) (hrow : ∀ i,∑ k,A i k^2 ≤ R) (i : ι) : + (∑ k,tanh (A i k)^4) ≤ d^2*R := by + have hentry (k : ι) : tanh (A i k)^4 ≤ d^2*A i k^2 := by + have habs := abs_tanh_le_abs (A i k) + have hd : 0 ≤ d := (abs_nonneg _).trans (hma i k) + have hs : tanh (A i k)^2 ≤ A i k^2 := by + simpa only [sq_abs] using (sq_le_sq₀ (abs_nonneg _) (abs_nonneg _)).mpr habs + have hs' : tanh (A i k)^2 ≤ d^2 := by + simpa only [sq_abs] using (sq_le_sq₀ (abs_nonneg _) hd).mpr (habs.trans (hma i k)) + have hm := mul_le_mul hs' hs (sq_nonneg _) (sq_nonneg d) + nlinarith only [hm] + calc + _ ≤ ∑ k,d^2*A i k^2 := Finset.sum_le_sum (fun k _=>hentry k) + _ = d^2*(∑ k,A i k^2) := (Finset.mul_sum _ _ _).symm + _ ≤ _ := mul_le_mul_of_nonneg_left (hrow i) (sq_nonneg d) +end SKGap + +end +end + +section +noncomputable section +namespace SKGap +open MeasureTheory ProbabilityTheory Matrix Real +open scoped BigOperators +variable {n : ℕ} + +def goeDisorder (r : ℝ) (g : MatrixCoordinates (Fin n)→ℝ) : Disorder n := + fun e=>goeMatrix r g e.1.1 e.1.2 + +lemma goeDisorder_gaussian (r : ℝ) : + HasGaussianLaw (goeDisorder (n:=n) r) (gaussianCoordinates (MatrixCoordinates (Fin n))) := + (goe_matrix_gaussian (ι:=Fin n) r).map_fun (ContinuousLinearMap.pi (fun e : Edge n=>ContinuousLinearMap.proj e.1)) + +lemma goeDisorder_mean (r : ℝ) (e : Edge n) : + (∫ g,goeDisorder r g e ∂gaussianCoordinates (MatrixCoordinates (Fin n)))=0 := + goe_mean_zero r e.1.1 e.1.2 + +lemma goeDisorder_cov {r : ℝ} (hr : 0 ≤ r) (e f : Edge n) : + cov[fun g=>goeDisorder r g e,fun g=>goeDisorder r g f; + gaussianCoordinates (MatrixCoordinates (Fin n))]=if e=f then r else 0 := by + change cov[fun g=>goeMatrix r g e.1.1 e.1.2,fun g=>goeMatrix r g f.1.1 f.1.2; + gaussianCoordinates (MatrixCoordinates (Fin n))]=_ + rw [goe_entry_cov hr] + have heq : e=f ↔ e.1.1=f.1.1 ∧ e.1.2=f.1.2 := by simp only [Subtype.ext_iff,Prod.ext_iff] + have hcross : ¬(e.1.1=f.1.2 ∧ e.1.2=f.1.1) := by + rintro ⟨h1,h2⟩ + have he := e.2 + rw [h1,h2] at he + exact (lt_asymm f.2 he) + split_ifs <;> simp_all + +lemma goeDisorder_hasLaw {r : ℝ} (hr : 0 ≤ r) : + HasLaw (goeDisorder (n:=n) r) (Measure.pi (fun _ : Edge n=>gaussianReal 0 (Real.toNNReal r))) + (gaussianCoordinates (MatrixCoordinates (Fin n))) := by + have hg := goeDisorder_gaussian (n:=n) r + have hl (e : Edge n) : HasLaw (fun g=>goeDisorder r g e) + (gaussianReal 0 (Real.toNNReal r)) (gaussianCoordinates (MatrixCoordinates (Fin n))) := by + refine ⟨(hg.eval e).aemeasurable,?_⟩ + rw [(hg.eval e).map_eq_gaussianReal,goeDisorder_mean, + ← covariance_self (hg.eval e).aemeasurable,goeDisorder_cov hr,ite_eq_left rfl] + exact iIndepFun.hasLaw_pi hl (hg.iIndepFun_of_covariance_eq_zero + (fun e f h=>by rw [goeDisorder_cov hr,ite_eq_right h])) + +lemma goe_actual_disorder_hasLaw (β : ℝ) (n : ℕ) : + HasLaw (goeDisorder (n:=n) (β^2/(n:ℝ))) (disorderLaw β n) + (gaussianCoordinates (MatrixCoordinates (Fin n))) := + goeDisorder_hasLaw (by positivity) + +lemma coupling_goeDisorder (r : ℝ) (g : MatrixCoordinates (Fin n)→ℝ) : + Matrix.of (coupling (goeDisorder r g))=goeMatrix r g-Matrix.diagonal (fun i=>goeMatrix r g i i) := by + ext i k + by_cases hik : i=k + · subst k + simp [coupling] + · rcases lt_or_gt_of_ne hik with h | h + · simp [coupling,h,hik,goeDisorder] + · simp [coupling,h,not_lt_of_gt h,hik,goeDisorder,goeMatrix,add_comm] +end SKGap + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Matrix/Trace.lean b/lean/OAI/Probability/SKGap/Matrix/Trace.lean new file mode 100644 index 0000000000000000000000000000000000000000..21ca898e8e6b5867cdd3a70b093e65f375646d50 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Matrix/Trace.lean @@ -0,0 +1,135 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.LocalCoefficient +import OAI.Probability.SKGap.Localization.Operation + +namespace OAI + +section + +noncomputable section +open scoped BigOperators Matrix.Norms.Frobenius +namespace SKGapCutoff.Recipe +open Primary Matrix SKGap.SourceError +variable {n : ℕ} {ι κ : Type*} [Fintype ι] [DecidableEq ι] [Fintype κ] [DecidableEq κ] + +structure SegmentRegular (H : ι→VectorFields n) (θ : κ→Spin n→ℝ) + (F : Fin n→Args (ι:=ι) (κ:=κ)→ℝ) + (F' : Fin n→Args (ι:=ι) (κ:=κ)→Args (ι:=ι) (κ:=κ)→L[ℝ]ℝ) + (x : Spin n) (C : ℝ) : Prop where + nonneg : 0≤C + deriv : ∀i k t, t∈Set.Icc (0:ℝ) 1→HasFDerivAt (F i) + (F' i (localArgs H θ x i+t • (localArgs H θ (flip x k) i-localArgs H θ x i))) + (localArgs H θ x i+t • (localArgs H θ (flip x k) i-localArgs H θ x i)) + bound : ∀i k t, t∈Set.Icc (0:ℝ) 1→ + ‖F' i (localArgs H θ x i+t • (localArgs H θ (flip x k) i-localArgs H θ x i))‖≤C + lip : ∀i k t, t∈Set.Icc (0:ℝ) 1→ + ‖F' i (localArgs H θ x i+t • (localArgs H θ (flip x k) i-localArgs H θ x i))- + F' i (localArgs H θ x i)‖≤C*‖t • (localArgs H θ (flip x k) i-localArgs H θ x i)‖ + +lemma SegmentRegular.partial_bound {H : ι→VectorFields n} {θ : κ→Spin n→ℝ} + {F : Fin n→Args (ι:=ι) (κ:=κ)→ℝ} + {F' : Fin n→Args (ι:=ι) (κ:=κ)→Args (ι:=ι) (κ:=κ)→L[ℝ]ℝ} + {x : Spin n} {C : ℝ} (h : SegmentRegular H θ F F' x C) (i : Fin n) (l : ι⊕κ) : + |localPartial H θ F' l x i|≤C := by + have hb : ‖F' i (localArgs H θ x i)‖≤C := by simpa using h.bound i i 0 (by constructor <;> norm_num) + have hs : ‖(Pi.single l (1:ℝ) : Args (ι:=ι) (κ:=κ))‖≤1 := by + apply (pi_norm_le_iff_of_nonneg (by norm_num : (0:ℝ)≤1)).mpr + intro a; simp only [Pi.single_apply]; split_ifs <;> norm_num + have h₁ := (F' i (localArgs H θ x i)).le_opNorm (Pi.single l 1) + exact h₁.trans ((mul_le_mul hb hs (norm_nonneg _) h.nonneg).trans_eq (mul_one C)) + +def sourceError (H : ι→VectorFields n) (θ : κ→Spin n→ℝ) + (F : Fin n→Args (ι:=ι) (κ:=κ)→ℝ) + (F' : Fin n→Args (ι:=ι) (κ:=κ)→Args (ι:=ι) (κ:=κ)→L[ℝ]ℝ) + (s : VectorFields n) (x : Spin n) : Interaction n := + derivativeMatrix (fun x i=>coefficient H θ F x i*s x i) x- + Matrix.diagonal (coefficient H θ F x)*derivativeMatrix s x- + ∑l,Matrix.diagonal (fun i=>s x i*localPartial H θ F' (.inl l) x i)*derivativeMatrix (H l) x + +lemma sourceError_eq (H : ι→VectorFields n) (θ : κ→Spin n→ℝ) + (F : Fin n→Args (ι:=ι) (κ:=κ)→ℝ) + (F' : Fin n→Args (ι:=ι) (κ:=κ)→Args (ι:=ι) (κ:=κ)→L[ℝ]ℝ) + (s : VectorFields n) (x : Spin n) : + sourceError H θ F F' s x= + (∑α,Matrix.of (fun i k=>(s x i*localPartial H θ F' (.inr α) x i)*halfDiff k (θ α) x))+ + Matrix.of (fun i k=>s x i*taylorError H θ F F' x i k)- + Matrix.of (fun i k=>2*spin x k*derivativeMatrix (coefficient H θ F) x i k*derivativeMatrix s x i k) := by + ext i k + simp only [sourceError,Matrix.sub_apply,Matrix.diagonal_mul,Matrix.sum_apply,Matrix.add_apply,Matrix.of_apply] + rw [source_derivative_exact] + ring + +def primaryIncrement (H : ι→VectorFields n) (x : Spin n) : Interaction n := + fun i k=>∑l,|derivativeMatrix (H l) x i k| +def parameterIncrement (θ : κ→Spin n→ℝ) (x : Spin n) : Fin n→ℝ := + fun k=>∑α,|halfDiff k (θ α) x| + +lemma sourceError_trace (H : ι→VectorFields n) (θ : κ→Spin n→ℝ) + (F : Fin n→Args (ι:=ι) (κ:=κ)→ℝ) + (F' : Fin n→Args (ι:=ι) (κ:=κ)→Args (ι:=ι) (κ:=κ)→L[ℝ]ℝ) + (s : VectorFields n) (x : Spin n) (P : Interaction n) {C S T B R L O : ℝ} + (h : SegmentRegular H θ F F' x C) (hS : 0≤S) (hT : 0≤T) (hB : 0≤B) + (hR : 0≤R) (hL : 0≤L) (hO : 0≤O) + (hs : vectorNorm (s x)≤S) (hds : ‖derivativeMatrix s x‖≤S) + (ht : vectorNorm (parameterIncrement θ x)≤T) + (hQ4 : (∑i,∑k,(primaryIncrement H x i k)^4)≤B^4) + (hQr : ∀i,(∑k,(primaryIncrement H x i k)^2)≤R^2) + (hQd : (∑i,(primaryIncrement H x i i)^2)≤L^2) + (hP : (∑i,∑k,if i=k then 0 else (P k i)^4)≤O^4) : + |trace (P*sourceError H θ F F' s x)|≤ + SKGap.opNorm P*C*S*(∑α,‖derivativeVector (θ α) x‖)+ + 4*C*SKGap.opNorm P*S*(B^2+R*T+T^2)+ + 2*C*S*(O*B+SKGap.opNorm P*(L+T)) := by + let Q := primaryIncrement H x + let t := parameterIncrement θ x + have hQ : ∀i k,0≤Q i k := fun i k=>Finset.sum_nonneg fun _ _=>abs_nonneg _ + have htt : ∀k,0≤t k := fun k=>Finset.sum_nonneg fun _ _=>abs_nonneg _ + have hs2 : (∑i,(s x i)^2)≤S^2 := by rw [←vectorNorm_sq]; exact pow_le_pow_left₀ (vectorNorm_nonneg _) hs 2 + have ht2 : (∑k,(t k)^2)≤T^2 := by rw [←vectorNorm_sq]; exact pow_le_pow_left₀ (vectorNorm_nonneg _) ht 2 + have hds2 : (∑i,∑k,(derivativeMatrix s x i k)^2)≤S^2 := by + rw [←SKGap.frobenius_sq]; exact pow_le_pow_left₀ (norm_nonneg _) hds 2 + have htaylor := source_taylor_trace_bound P (Matrix.of (fun i k=>s x i*taylorError H θ F F' x i k)) Q (s x) t + (mul_nonneg (by norm_num : (0:ℝ)≤4) h.nonneg) hS hT hB hR hs2 ht2 hQ4 hQr (by + intro i k + simp only [Matrix.of_apply,abs_mul,abs_of_nonneg (hQ i k),abs_of_nonneg (htt k)] + have hh := taylor_error_bound H θ F F' x i k h.nonneg (hQ i k) (htt k) + (local_argument_bound H θ x i k) (h.deriv i k) (h.lip i k) + nlinarith [mul_le_mul_of_nonneg_left hh (abs_nonneg (s x i))]) + have hproduct := source_product_trace_bound P + (Matrix.of (fun i k=>2*spin x k*derivativeMatrix (coefficient H θ F) x i k*derivativeMatrix s x i k)) + (derivativeMatrix s x) Q t (mul_nonneg (by norm_num : (0:ℝ)≤2) h.nonneg) + hS hT hO hB hL hds2 ht2 hP hQ4 hQd (by + intro i k + simp only [Matrix.of_apply,abs_mul,abs_spin_eq_one,mul_one,abs_of_nonneg (hQ i k),abs_of_nonneg (htt k)] + norm_num only [abs_of_pos (by norm_num : (0:ℝ)<2)] + have hh := (coefficient_lipschitz k (fun y=>localArgs H θ y i) x (F i) (F' i) + h.nonneg (h.deriv i k) (h.bound i k)).trans + (mul_le_mul_of_nonneg_left (local_argument_bound H θ x i k) h.nonneg) + change |derivativeMatrix (coefficient H θ F) x i k|≤C*(Q i k+t k) at hh + nlinarith [mul_le_mul_of_nonneg_right hh (abs_nonneg (derivativeMatrix s x i k))]) + have hrank (α : κ) : + |trace (P*Matrix.of (fun i k=>(s x i*localPartial H θ F' (.inr α) x i)*halfDiff k (θ α) x))|≤ + SKGap.opNorm P*C*S*‖derivativeVector (θ α) x‖ := by + have hu : vectorNorm (fun i=>s x i*localPartial H θ F' (.inr α) x i)≤C*S := by + have H₁ := (vectorNorm_mul (fun i=>localPartial H θ F' (.inr α) x i) (s x) h.nonneg + (fun i=>h.partial_bound i (.inr α))).trans (mul_le_mul_of_nonneg_left hs h.nonneg) + simpa only [mul_comm] using H₁ + have HH:=rank_one_trace_bound P + (WithLp.toLp 2 (fun i=>s x i*localPartial H θ F' (.inr α) x i)) (derivativeVector (θ α) x) + apply HH.trans + change SKGap.opNorm P*vectorNorm _*‖derivativeVector (θ α) x‖≤_ + nlinarith [mul_le_mul_of_nonneg_right (mul_le_mul_of_nonneg_left hu (real_op_norm_nonneg P)) + (norm_nonneg (derivativeVector (θ α) x))] + have hranks : |trace (P*(∑α,Matrix.of (fun i k=>(s x i*localPartial H θ F' (.inr α) x i)*halfDiff k (θ α) x)))|≤ + SKGap.opNorm P*C*S*(∑α,‖derivativeVector (θ α) x‖) := by + rw [Matrix.mul_sum,trace_sum] + exact (Finset.abs_sum_le_sum_abs ..).trans ((Finset.sum_le_sum fun α _=>hrank α).trans_eq (by rw [Finset.mul_sum])) + rw [sourceError_eq,mul_sub,mul_add,trace_sub,trace_add] + exact (abs_sub _ _).trans (add_le_add ((abs_add_le _ _).trans (add_le_add hranks htaylor)) hproduct) + +end SKGapCutoff.Recipe + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Matrix/Word.lean b/lean/OAI/Probability/SKGap/Matrix/Word.lean new file mode 100644 index 0000000000000000000000000000000000000000..3e8f0df1a24ca1de385209377f1ef17a5a1b0af9 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Matrix/Word.lean @@ -0,0 +1,101 @@ +import Mathlib +import OAI.Probability.SKGap.Brownian.PathCutoff +import OAI.Probability.SKGap.Matrix.MatrixWordRegularity + +namespace OAI + +section +noncomputable section +namespace SKGap +open Real Matrix MeasureTheory ProbabilityTheory Set +open RealComplex +open scoped BigOperators Matrix.Norms.Frobenius SchwartzMap + +inductive WordLetter (ι : Type*) + | diag : (ι→ℝ)→WordLetter ι + | noise : WordLetter ι + | inverse : WordLetter ι + +variable {ι : Type*} [Fintype ι] [DecidableEq ι] + +def WordLetter.bounded (D : ℝ) : WordLetter ι→Prop + | .diag d => ∀ i,|d i| ≤ D + | .noise => True + | .inverse => True + +def WordLetter.eval (f : 𝓢(ℝ,ℂ)) (R : ℝ) (hR : 0≤R) (j : ℝ) (a : ι→ℝ) (z : ℝ) : + WordLetter ι→Matrix ι ι ℝ→Matrix ι ι ℝ + | .diag d,_ => diagonal d + | .noise,M => realProject R hR M + | .inverse,M => pathK f R hR j a z M + +def actualWord (f : 𝓢(ℝ,ℂ)) (R : ℝ) (hR : 0≤R) (j : ℝ) (a : ι→ℝ) (z : ℝ) + (F : List (WordLetter ι)) (M : Matrix ι ι ℝ) : Matrix ι ι ℝ := + matrixFactorProduct (F.map (WordLetter.eval f R hR j a z)) M + +def actualWordBound (f : 𝓢(ℝ,ℂ)) (R j A D : ℝ) : ℝ := + 1+R+D+pathBound f R j A+pathLip f R j A + +lemma actualWordBound_pos (f : 𝓢(ℝ,ℂ)) {R j A D : ℝ} + (hR : 0≤R) (hj : 0≤j) (hA : 0≤A) (hD : 0≤D) : 0 + constructor + · intro M;exact (opNorm_diagonal_le hD hl).trans hD' + · exact (LipschitzWith.const (diagonal d)).weaken (show (0:NNReal) ≤ _ from zero_le) + | noise => + constructor + · intro M;exact (realProject_opNorm hR M).trans hR' + · exact (realProject_lipschitz hR).weaken h1 + | inverse => + have hh := pathK_bounds f hR hj hA ha haA hz + constructor + · intro M;exact (hh.1 M).trans hB + · apply LipschitzWith.of_dist_le_mul + intro M N + change ‖pathK f R hR j a z M-pathK f R hR j a z N‖ ≤ actualWordBound f R j A D*‖M-N‖ + exact (hh.2 M N).trans (mul_le_mul_of_nonneg_right hL (norm_nonneg _)) + +theorem actualWord_bounds [Nonempty ι] (f : 𝓢(ℝ,ℂ)) {R j A D z : ℝ} + (hR : 0≤R) (hj : 0≤j) (hA : 0≤A) (hD : 0≤D) {a : ι→ℝ} + (ha : ∀ i,0≤a i) (haA : ∀ i,a i≤A) (hz : z∈Icc (0:ℝ) 1) + (F : List (WordLetter ι)) (hF : ∀ l∈F,l.bounded D) : + (∀ M,opNorm (actualWord f R hR j a z F M) ≤ (actualWordBound f R j A D)^F.length) ∧ + LipschitzWith ((F.length:NNReal)*⟨actualWordBound f R j A D,(actualWordBound_pos f hR hj hA hD).le⟩^F.length) + (actualWord f R hR j a z F) := by + let B : NNReal := ⟨actualWordBound f R j A D,(actualWordBound_pos f hR hj hA hD).le⟩ + let G := F.map (WordLetter.eval f R hR j a z) + have hGb : ∀ p∈G,∀ M,opNorm (p M) ≤ B := by + intro p hp + obtain ⟨l,hl,rfl⟩ := List.mem_map.mp hp + exact (l.eval_bounds f hR hj hA hD ha haA hz (hF l hl)).1 + have hGl : ∀ p∈G,LipschitzWith B p := by + intro p hp + obtain ⟨l,hl,rfl⟩ := List.mem_map.mp hp + exact (l.eval_bounds f hR hj hA hD ha haA hz (hF l hl)).2 + constructor + · intro M + simpa only [G,B,actualWord,List.length_map,NNReal.coe_mk] using! matrixFactorProduct_opNorm G hGb M + · simpa only [G,B,actualWord,List.length_map] using! (@matrixFactorProduct_lipschitz ι (Matrix ι ι ℝ) _ _ (inferInstance : MetricSpace (Matrix ι ι ℝ)).toPseudoMetricSpace G B hGb hGl) +end SKGap +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Matrix/WordBaseBias.lean b/lean/OAI/Probability/SKGap/Matrix/WordBaseBias.lean new file mode 100644 index 0000000000000000000000000000000000000000..118829aee86895de4971265ccf974398b104df8f --- /dev/null +++ b/lean/OAI/Probability/SKGap/Matrix/WordBaseBias.lean @@ -0,0 +1,200 @@ +import Mathlib +import OAI.Probability.SKGap.Gaussian.MatrixWordMoments +import OAI.Probability.SKGap.Matrix.WordPartnerContraction + +namespace OAI + +section +noncomputable section +namespace SKGap +open Matrix Real MeasureTheory ProbabilityTheory Set +open scoped BigOperators Matrix.Norms.Frobenius SchwartzMap +variable {ι : Type*} [Fintype ι] [DecidableEq ι] + +omit [Fintype ι] [DecidableEq ι] in +@[simp] lemma wordDiagonal_nil (i : ι) : wordDiagonal [] i=1 := rfl +omit [Fintype ι] [DecidableEq ι] in +@[simp] lemma wordDiagonal_diag (d : ι→ℝ) (F : List (WordLetter ι)) (i : ι) : + wordDiagonal (.diag d::F) i=d i*wordDiagonal F i := rfl +omit [Fintype ι] [DecidableEq ι] in +@[simp] lemma wordDiagonal_noise (F : List (WordLetter ι)) (i : ι) : + wordDiagonal (.noise::F) i=wordDiagonal F i := by simp [wordDiagonal] +omit [Fintype ι] [DecidableEq ι] in +@[simp] lemma wordDiagonal_inverse (F : List (WordLetter ι)) (i : ι) : + wordDiagonal (.inverse::F) i=wordDiagonal F i := by simp [wordDiagonal] + +lemma actualWord_all_diagonal (f : 𝓢(ℝ,ℂ)) {R : ℝ} (hR : 0≤R) (j : ℝ) + (a : ι→ℝ) (z : ℝ) (F : List (WordLetter ι)) (M : Matrix ι ι ℝ) + (hO : ordinaryCount F=0) (hI : inverseCount F=0) : + actualWord f R hR j a z F M=diagonal (wordDiagonal F) := by + induction F with + | nil => + change (1:Matrix ι ι ℝ)=Matrix.diagonal (fun _=>1) + simp + | cons l F ih => + cases l with + | noise => simp [ordinaryCount] at hO + | inverse => simp [inverseCount] at hI + | diag d => + simp only [ordinaryCount,List.countP_cons] at hO + simp only [inverseCount,List.countP_cons] at hI + have hh := ih (by simpa [ordinaryCount] using hO) (by simpa [inverseCount] using hI) + rw [actualWord_cons,hh] + simp only [WordLetter.eval,Matrix.diagonal_mul_diagonal] + rfl + +lemma actualWord_no_noise_entry (f : 𝓢(ℝ,ℂ)) {R : ℝ} (hR : 0≤R) (j : ℝ) + (a : ι→ℝ) (z : ℝ) (F : List (WordLetter ι)) (M : Matrix ι ι ℝ) (i : ι) + (hO : ordinaryCount F=0) (hI : inverseCount F≤1) : + actualWord f R hR j a z F M i i=wordDiagonal F i* + (if inverseCount F=0 then 1 else pathK f R hR j a z M i i) := by + induction F with + | nil => simp [actualWord_nil,inverseCount] + | cons l F ih => + cases l with + | noise => simp [ordinaryCount] at hO + | diag d => + have hOt : ordinaryCount F=0 := by simpa [ordinaryCount] using hO + have hIt : inverseCount F≤1 := by simpa [inverseCount] using hI + rw [actualWord_cons] + simp only [WordLetter.eval,Matrix.diagonal_mul,ih hOt hIt,wordDiagonal_diag] + have he : inverseCount (.diag d::F)=inverseCount F := by simp [inverseCount] + rw [he] + ring + | inverse => + have hOt : ordinaryCount F=0 := by simpa [ordinaryCount] using hO + have hIt : inverseCount F=0 := by simp [inverseCount] at hI ⊢;omega + rw [actualWord_cons,actualWord_all_diagonal f hR j a z F M hOt hIt] + simp only [WordLetter.eval,Matrix.mul_diagonal,wordDiagonal_inverse] + have hh : inverseCount (.inverse::F)≠0 := by simp [inverseCount] + rw [ite_eq_right hh,mul_comm] + +omit [Fintype ι] [DecidableEq ι] in +lemma wordDiagonal_bound (D : ℝ) (hD : 1≤D) (F : List (WordLetter ι)) + (hF : ∀ l∈F,l.bounded D) (i : ι) : |wordDiagonal F i|≤D^F.length := by + induction F with + | nil => simp + | cons l F ih => + have hFt : ∀ l∈F,l.bounded D := fun l hl=>hF l (List.mem_cons_of_mem _ hl) + have hD0 : 0≤D := zero_le_one.trans hD + cases l with + | diag d => + rw [wordDiagonal_diag,abs_mul] + simpa only [List.length_cons,pow_succ'] using mul_le_mul (hF (.diag d) List.mem_cons_self i) + (ih hFt) (abs_nonneg _) hD0 + | noise => + simp only [wordDiagonal_noise,List.length_cons] + exact (ih hFt).trans (pow_le_pow_right₀ hD (Nat.le_succ _)) + | inverse => + simp only [wordDiagonal_inverse,List.length_cons] + exact (ih hFt).trans (pow_le_pow_right₀ hD (Nat.le_succ _)) + +def wordExpected (f : 𝓢(ℝ,ℂ)) {R : ℝ} (hR : 0≤R) (j : ℝ) + (a : ι→ℝ) (z : ℝ) (F : List (WordLetter ι)) (i : ι) : ℝ := + ∫ g : MatrixCoordinates ι→ℝ,actualWord f R hR j a z F (goeMatrix (j/(Fintype.card ι:ℝ)) g) i i + ∂Measure.pi (fun _=>gaussianReal 0 1) + +theorem word_base_bias (f : 𝓢(ℝ,ℂ)) {R : ℝ} (hR : 0≤R) (j : ℝ) + (a : ι→ℝ) (z : ℝ) (F : List (WordLetter ι)) (i : ι) + (hO : ordinaryCount F=0) (hI : inverseCount F≤1) {D E : ℝ} + (hD : 1≤D) (hF : ∀ l∈F,l.bounded D) (hE : 0≤E) + (hb : |pathExpected f R hR j a z i-1|≤E) : + |wordExpected f hR j a z F i-wordDiagonal F i|≤D^F.length*E := by + have he (g : MatrixCoordinates ι→ℝ) := actualWord_no_noise_entry f hR j a z F + (goeMatrix (j/(Fintype.card ι:ℝ)) g) i hO hI + by_cases hIc : inverseCount F=0 + · have hh : wordExpected f hR j a z F i=wordDiagonal F i := by simp [wordExpected,he,hIc] + rw [hh,sub_self,abs_zero] + positivity + · have hh : wordExpected f hR j a z F i=wordDiagonal F i*pathExpected f R hR j a z i := by + simp only [wordExpected,he,ite_eq_right hIc,integral_const_mul,pathExpected,pathK,expectedCutoff] + rw [hh,← mul_sub_one,abs_mul] + exact mul_le_mul (wordDiagonal_bound D hD F hF i) hb (abs_nonneg _) (pow_nonneg (zero_le_one.trans hD) _) +end SKGap +end +end + +section +noncomputable section +namespace SKGap +open Real Matrix MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix.Norms.Frobenius + +lemma matrix_word_expectation_contraction {Ω : Type*} [MeasurableSpace Ω] + (μ : Measure Ω) [IsProbabilityMeasure μ] {n : ℕ} (hn : 0(U ω*Q ω) i i) μ) + (hZ : AEStronglyMeasurable (fun ω=>(U ω*(V ω)ᵀ*Q ω) i i) μ) + (hX : Integrable (fun ω=>trace (V ω)/(n:ℝ)) μ) + (hT : (∫ ω,|trace (V ω)/(n:ℝ)-∫ v,trace (V v)/(n:ℝ) ∂μ| ∂μ) ≤ T) : + |(j/(n:ℝ))*(∫ ω,∑ a,∑ b,U ω i a*(V ω*symmetricElementary a b*Q ω) b i ∂μ)- + j*(∫ ω,trace (V ω)/(n:ℝ) ∂μ)*(∫ ω,(U ω*Q ω) i i ∂μ)| ≤ + j*(BU*BQ*T+BU*BV*BQ/(n:ℝ)) := by + have hnr : (0:ℝ)(U ω*(V ω)ᵀ*Q ω) i i/(n:ℝ)) μ := + (integrable_const (BU*BV*BQ/(n:ℝ))).mono' (by simpa only [div_eq_mul_inv,Pi.mul_apply] using! hZ.mul (g := fun _ => (n:ℝ)⁻¹) aestronglyMeasurable_const) (ae_of_all _ hZb) + have he : (∫ ω,(j/(n:ℝ))*(∑ a,∑ b,U ω i a*(V ω*symmetricElementary a b*Q ω) b i) ∂μ) = + j*(∫ ω,(trace (V ω)/(n:ℝ))*((U ω*Q ω) i i)+(U ω*(V ω)ᵀ*Q ω) i i/(n:ℝ) ∂μ) := by + rw [← integral_const_mul] + apply integral_congr_ae + filter_upwards [] with ω + rw [matrix_word_contraction] + ring + have hh := integral_loop_deviation (μ:=μ) hj hX hY (ae_of_all _ hYb) + hZi (ae_of_all _ hZb) hT + (V:=fun ω=>(j/(n:ℝ))*(∑ a,∑ b,U ω i a*(V ω*symmetricElementary a b*Q ω) b i)) + (E:=0) (by rw [he,sub_self,abs_zero]) + simpa only [integral_const_mul,zero_add] using hh + +theorem goe_word_leading_contraction {n : ℕ} (hn : 0gaussianReal 0 1) + let W := goeMatrix (j/n) + |(j/(n:ℝ))*(∫ g,∑ a,∑ b,U (W g) i a* + (matrixFactorProduct F (W g)*symmetricElementary a b*Q (W g)) b i ∂μ)- + j*(∫ g,trace (matrixFactorProduct F (W g))/(n:ℝ) ∂μ)*(∫ g,(U (W g)*Q (W g)) i i ∂μ)| ≤ + (j*(BU*BQ*((2*exp (π^2/8))*((F.length:ℝ)*(R:ℝ)^F.length)*sqrt (2*j))+ + BU*(R:ℝ)^F.length*BQ))/(n:ℝ) := by + dsimp only + have hG := (goeMatrix_pi_lipschitz (ι:=Fin n) (j/n)).continuous + have hW := (matrixFactorProduct_lipschitz F hF hL).continuous.comp hG + have hUc' := hUc.comp hG + have hQc' := hQc.comp hG + have hY : Continuous (fun g : MatrixCoordinates (Fin n)→ℝ=>(U (goeMatrix (j/n) g)*Q (goeMatrix (j/n) g)) i i) := by + exact (continuous_apply i).comp ((continuous_apply i).comp (hUc'.mul hQc')) + have hZ : Continuous (fun g : MatrixCoordinates (Fin n)→ℝ=> + (U (goeMatrix (j/n) g)*(matrixFactorProduct F (goeMatrix (j/n) g))ᵀ*Q (goeMatrix (j/n) g)) i i) := by + exact (continuous_apply i).comp ((continuous_apply i).comp ((hUc'.mul hW.matrix_transpose).mul hQc')) + have hh := matrix_word_expectation_contraction + (Measure.pi (fun _ : MatrixCoordinates (Fin n)=>gaussianReal 0 1)) hn + (fun g=>U (goeMatrix (j/n) g)) (fun g=>matrixFactorProduct F (goeMatrix (j/n) g)) + (fun g=>Q (goeMatrix (j/n) g)) i hj.le hBU hBQ (pow_nonneg R.coe_nonneg _) + (fun g=>hU _) (fun g=>hQ _) (fun g=>matrixFactorProduct_opNorm F hF _) + hY.aestronglyMeasurable hZ.aestronglyMeasurable + (gaussianProduct_integrable_lipschitz (goe_word_trace_lip_scaled hn hj.le F hF hL)) + (goe_word_trace_centered_L1_all hn hj F hR hF hL) + apply hh.trans_eq + ring +end SKGap +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Matrix/WordBiasCutoff.lean b/lean/OAI/Probability/SKGap/Matrix/WordBiasCutoff.lean new file mode 100644 index 0000000000000000000000000000000000000000..b46975258e8d6010ee9d8ef209f8c7a03326bdfb --- /dev/null +++ b/lean/OAI/Probability/SKGap/Matrix/WordBiasCutoff.lean @@ -0,0 +1,145 @@ +import Mathlib +import OAI.Probability.SKGap.Matrix.WordBiasInduction +import OAI.Probability.SKGap.Stability.WordMeanSeminorm +import OAI.Probability.SKGap.Brownian.PathBiasCutoff + +namespace OAI + +section +noncomputable section +namespace SKGap +open Matrix Real MeasureTheory ProbabilityTheory Set Filter +open scoped BigOperators Matrix.Norms.Frobenius SchwartzMap Topology + +theorem actual_word_uniform_bias_of_cutoff {j A D : ℝ} (hj : 0(abs_of_nonneg (ha i)).trans_le ((haA i).trans hAD) + have hbnd (G : List (WordLetter (Fin n))) (hGlen : G.length≤L) + (hG : ∀ l∈G,l.bounded D) (_hGI : inverseCount G≤1) (u : Fin n) : + |wordExpected f hR j a z G u|≤(B:ℝ)^L := by + exact (wordExpected_abs_bound f hR hj.le hA.le hD0 ha haA hz G hG u).trans + (pow_le_pow_right₀ hB1 hGlen) + have hbas (G : List (WordLetter (Fin n))) (hGlen : G.length≤L) + (hG : ∀ l∈G,l.bounded D) (hGI : inverseCount G≤1) (hGO : ordinaryCount G=0) (u : Fin n) : + |wordExpected f hR j a z G u-wordDiagonal G u|≤Cbase/(n:ℝ) := by + have hh := word_base_bias f hR j a z G u hGO hGI hD hG (div_nonneg hC0.le hnpos.le) + (hbase n ((le_max_left _ _).trans hn) a ha haA z hz u) + apply hh.trans + have hpow := mul_le_mul_of_nonneg_right (pow_le_pow_right₀ hD hGlen) hC0.le + have hc : D^G.length*C0≤Cbase := by + dsimp [Cbase] + nlinarith [mul_nonneg (Nat.cast_nonneg L) hCL] + simpa only [mul_div_assoc] using div_le_div_of_nonneg_right hc hnpos.le + have hloop (G : List (WordLetter (Fin n))) (hGlen : G.length≤L) + (hG : ∀ l∈G,l.bounded D) (_hGI : inverseCount G≤1) (hGO : ordinaryCount G≠0) (u : Fin n) : + |wordExpected f hR j a z G u-wordRecursionValue j a z (wordExpected f hR j a z) G u|≤Cbase/(n:ℝ) := by + cases hsplit : firstNoiseSplit G with + | none => exact False.elim (hGO ((firstNoiseSplit_none G).mp hsplit)) + | some pq => + rcases pq with ⟨P,Q⟩ + have he := firstNoiseSplit_some G P Q hsplit + have hP : ∀ l∈P,l.bounded D := fun l hl=>hG l (by rw [he];exact List.mem_append_left _ hl) + have hQ : ∀ l∈Q,l.bounded D := fun l hl=>hG l (by rw [he];exact List.mem_append_right _ (List.mem_cons_of_mem _ hl)) + have hlenPQ : P.length+1+Q.length≤L := by simpa [he,List.length_append,List.length_cons,Nat.add_assoc,Nat.add_comm,Nat.add_left_comm] using hGlen + have herr := hsize n (by have hh := (le_max_right N0 (N1+1)).trans hn;omega) + have hh := actualWord_expected_recursion hn0 f hj hA hD0 hs hf herr ha haA haD hz P Q hP hQ u + rw [wordRecursionValue_split f hR j a z G P Q u hsplit,he] + apply hh.trans + have hmc := hmarked z hz P.length (by omega) Q.length (by omega) + have hlc := wordRecursionAtCost_uniform hz hCL L hlead a P Q hlenPQ + have hcost : wordMarkedCost B j R A (pathRate j A) z P.length Q.length+ + wordRecursionAtCost j B z a P Q≤Cbase := by + dsimp [Cbase] + have hh0 : 0≤D^L*C0 := by positivity + linarith + exact div_le_div_of_nonneg_right hcost hnpos.le + have hh := word_bias_induction hj.le (pow_nonneg B.coe_nonneg L) hCb hnr hz a haD L + (wordExpected f hR j a z) hbnd hbas hloop L F hlen hF hI + ((show ordinaryCount F≤F.length from List.countP_le_length).trans hlen) i + apply hh.trans + exact div_le_div_of_nonneg_right (by dsimp [C];linarith) hnpos.le +end SKGap +end +end + +section +noncomputable section +namespace SKGap +open Matrix Real Set MeasureTheory ProbabilityTheory Filter +open scoped BigOperators Matrix.Norms.Frobenius SchwartzMap Topology + +theorem actual_word_simultaneous_prediction_of_cutoff {j A D : ℝ} (hj : 0gaussianReal 0 1)) + {g | ∃ (a : Fin n→ℝ) (F : List (WordLetter (Fin n))), + (∀ i,a i∈Icc 0 A) ∧ F.length≤L ∧ (∀ l∈F,l.bounded D) ∧ inverseCount F≤1 ∧ + C< matrixWordSeminorm p + (actualWord f (2*sqrt j+1+1) hR j a 1 F (goeMatrix (j/n) g)-Matrix.diagonal (wordPrediction j a 1 F))} ≤ + (wordPatternSet L L).card*ENNReal.ofReal (3*exp (-(n:ℝ))) := by + obtain ⟨Cb,N,hCb,hN,hbias⟩ := actual_word_uniform_bias_of_cutoff hj hA hs hD hAD L f hf hR + let R := 2*sqrt j+1+1 + obtain ⟨C0,hC0,hchain⟩ := all_actualWords_gaussian_chaining f hR hj.le hA (lt_of_lt_of_le zero_lt_one hD) L + refine ⟨C0+Cb,N,by positivity,hN,?_⟩ + intro n hn p + have hn0 : 1≤n := (Nat.succ_le_iff.mpr hN).trans hn + apply (measure_mono ?_).trans (hchain n hn0 p) + intro g hg + obtain ⟨a,F,ha,hFL,hF,hFI,hg⟩ := hg + refine ⟨a,F,ha,hFL,hF,?_⟩ + have hb : matrixWordSeminorm p (Matrix.diagonal (fun i=>wordExpected f hR j a 1 F i-wordPrediction j a 1 F i))≤Cb := by + cases p with + | false => + exact diagonalSeminorm_diagonal_bound hn0 hCb.le + (hbias n hn a (fun i=>(ha i).1) (fun i=>(ha i).2) 1 ⟨zero_le_one,le_rfl⟩ F hFL hF hFI) + | true => + change offDiagonalSeminorm (Matrix.diagonal _)≤Cb + rw [offDiagonalSeminorm_diagonal] + exact hCb.le + have hdecomp := actualWord_diagonal_prediction_decompose (j:=j) f hR a 1 F g + simp only [Fintype.card_fin] at hdecomp + rw [hdecomp] at hg + have hh := matrixWordSeminorm_add p + (matrixCentered (fun x : EuclideanSpace ℝ (MatrixCoordinates (Fin n))=> + actualWord f R hR j a 1 F (goeMatrix (j/n) x)) (WithLp.toLp 2 g)) + (Matrix.diagonal (fun i=>wordExpected f hR j a 1 F i-wordPrediction j a 1 F i)) + linarith +end SKGap +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Matrix/WordBiasInduction.lean b/lean/OAI/Probability/SKGap/Matrix/WordBiasInduction.lean new file mode 100644 index 0000000000000000000000000000000000000000..75c1650e46fab9c3d8d5612ea4b66e0ff39a9657 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Matrix/WordBiasInduction.lean @@ -0,0 +1,203 @@ +import Mathlib +import OAI.Probability.SKGap.Entropy.WordUniformCost +import OAI.Probability.SKGap.Stability.WordPredictionStability + +namespace OAI + +section +noncomputable section +namespace SKGap +open Real Set +open scoped BigOperators + +def wordBiasConstant (L : ℕ) (j B C : ℝ) : ℕ → ℝ + | 0 => C + | k+1 => C+(L:ℝ)*j*(2*B+wordBiasConstant L j B C k)*wordBiasConstant L j B C k+ + wordBiasConstant L j B C k + +lemma wordBiasConstant_nonneg (L : ℕ) {j B C : ℝ} (hj : 0≤j) (hB : 0≤B) (hC : 0≤C) (k : ℕ) : + 0≤wordBiasConstant L j B C k := by + induction k with + | zero => exact hC + | succ k ih => simp only [wordBiasConstant];positivity + +lemma wordBiasConstant_ge (L : ℕ) {j B C : ℝ} (hj : 0≤j) (hB : 0≤B) (hC : 0≤C) (k : ℕ) : + C≤wordBiasConstant L j B C k := by + cases k with + | zero => exact le_rfl + | succ k => + have hh := wordBiasConstant_nonneg L hj hB hC k + change C≤C+(L:ℝ)*j*(2*B+wordBiasConstant L j B C k)*wordBiasConstant L j B C k+wordBiasConstant L j B C k + have hp : 0≤(L:ℝ)*j*(2*B+wordBiasConstant L j B C k)*wordBiasConstant L j B C k := by positivity + linarith + +theorem word_bias_induction {ι : Type*} [Fintype ι] [Nonempty ι] + {j B C D n z : ℝ} (hj : 0≤j) (hB : 0≤B) (hC : 0≤C) (hn : 1≤n) + (hz : z∈Icc (0:ℝ) 1) (a : ι → ℝ) (ha : ∀ i,|a i|≤D) (L : ℕ) + (e : List (WordLetter ι) → ι → ℝ) + (hb : ∀ F : List (WordLetter ι),F.length≤L → (∀ l∈F,l.bounded D) → + inverseCount F≤1 → ∀ i,|e F i|≤B) + (hbase : ∀ F : List (WordLetter ι),F.length≤L → (∀ l∈F,l.bounded D) → + inverseCount F≤1 → ordinaryCount F=0 → ∀ i,|e F i-wordDiagonal F i|≤C/n) + (hloop : ∀ F : List (WordLetter ι),F.length≤L → (∀ l∈F,l.bounded D) → + inverseCount F≤1 → ordinaryCount F≠0 → ∀ i, + |e F i-wordRecursionValue j a z e F i|≤C/n) : + ∀ k,∀ F : List (WordLetter ι),F.length≤L → (∀ l∈F,l.bounded D) → + inverseCount F≤1 → ordinaryCount F≤k → ∀ i, + |e F i-wordPrediction j a z F i|≤wordBiasConstant L j B C k/n := by + intro k + induction k with + | zero => + intro F hlen hF hI hO i + have ho : ordinaryCount F=0 := Nat.eq_zero_of_le_zero hO + rw [wordPrediction_base j a z F i ho] + exact hbase F hlen hF hI ho i + | succ k ih => + intro F hlen hF hI hO i + have hn0 : 0gaussianReal 0 1)) + (f:=fun g=>actualWord f R hR j a z F (goeMatrix (j/(Fintype.card ι:ℝ)) g) i i) + (C:=(actualWordBound f R j A D)^F.length) (Filter.Eventually.of_forall (fun g=> + (matrix_entry_le_opNorm _ i i).trans ((actualWord_bounds f hR hj hA hD ha haA hz F hF).1 _))) + simpa [wordExpected,Real.norm_eq_abs,Measure.real] using hh + +lemma wordRecursionValue_split (f : 𝓢(ℝ,ℂ)) {R : ℝ} (hR : 0≤R) (j : ℝ) + (a : ι→ℝ) (z : ℝ) (F P Q : List (WordLetter ι)) (i : ι) + (hs : firstNoiseSplit F=some (P,Q)) : + wordRecursionValue j a z (wordExpected f hR j a z) F i= + wordRecursionAtExpected f hR j a z P Q i := by + simp only [wordRecursionValue,wordRecursionTerms,hs] + rfl + +theorem actual_word_uniform_bias {j A D : ℝ} (hj : 0(abs_of_nonneg (ha i)).trans_le ((haA i).trans hAD) + have hbnd (G : List (WordLetter (Fin n))) (hGlen : G.length≤L) + (hG : ∀ l∈G,l.bounded D) (_hGI : inverseCount G≤1) (u : Fin n) : + |wordExpected f hR j a z G u|≤(B:ℝ)^L := by + exact (wordExpected_abs_bound f hR hj.le hA.le hD0 ha haA hz G hG u).trans + (pow_le_pow_right₀ hB1 hGlen) + have hbas (G : List (WordLetter (Fin n))) (hGlen : G.length≤L) + (hG : ∀ l∈G,l.bounded D) (hGI : inverseCount G≤1) (hGO : ordinaryCount G=0) (u : Fin n) : + |wordExpected f hR j a z G u-wordDiagonal G u|≤Cbase/(n:ℝ) := by + have hh := word_base_bias f hR j a z G u hGO hGI hD hG (div_nonneg hC0.le hnpos.le) + (hbase n ((le_max_left _ _).trans hn) a ha haA z hz u) + apply hh.trans + have hpow := mul_le_mul_of_nonneg_right (pow_le_pow_right₀ hD hGlen) hC0.le + have hc : D^G.length*C0≤Cbase := by + dsimp [Cbase] + nlinarith [mul_nonneg (Nat.cast_nonneg L) hCL] + simpa only [mul_div_assoc] using div_le_div_of_nonneg_right hc hnpos.le + have hloop (G : List (WordLetter (Fin n))) (hGlen : G.length≤L) + (hG : ∀ l∈G,l.bounded D) (_hGI : inverseCount G≤1) (hGO : ordinaryCount G≠0) (u : Fin n) : + |wordExpected f hR j a z G u-wordRecursionValue j a z (wordExpected f hR j a z) G u|≤Cbase/(n:ℝ) := by + cases hsplit : firstNoiseSplit G with + | none => exact False.elim (hGO ((firstNoiseSplit_none G).mp hsplit)) + | some pq => + rcases pq with ⟨P,Q⟩ + have he := firstNoiseSplit_some G P Q hsplit + have hP : ∀ l∈P,l.bounded D := fun l hl=>hG l (by rw [he];exact List.mem_append_left _ hl) + have hQ : ∀ l∈Q,l.bounded D := fun l hl=>hG l (by rw [he];exact List.mem_append_right _ (List.mem_cons_of_mem _ hl)) + have hlenPQ : P.length+1+Q.length≤L := by simpa [he,List.length_append,List.length_cons,Nat.add_assoc,Nat.add_comm,Nat.add_left_comm] using hGlen + have herr := hsize n (by have hh := (le_max_right N0 (N1+1)).trans hn;omega) + have hh := actualWord_expected_recursion hn0 f hj hA hD0 hs hf herr ha haA haD hz P Q hP hQ u + rw [wordRecursionValue_split f hR j a z G P Q u hsplit,he] + apply hh.trans + have hmc := hmarked z hz P.length (by omega) Q.length (by omega) + have hlc := wordRecursionAtCost_uniform hz hCL L hlead a P Q hlenPQ + have hcost : wordMarkedCost B j R A (pathRate j A) z P.length Q.length+ + wordRecursionAtCost j B z a P Q≤Cbase := by + dsimp [Cbase] + have hh0 : 0≤D^L*C0 := by positivity + linarith + exact div_le_div_of_nonneg_right hcost hnpos.le + have hh := word_bias_induction hj.le (pow_nonneg B.coe_nonneg L) hCb hnr hz a haD L + (wordExpected f hR j a z) hbnd hbas hloop L F hlen hF hI + ((show ordinaryCount F≤F.length from List.countP_le_length).trans hlen) i + apply hh.trans + exact div_le_div_of_nonneg_right (by dsimp [C];linarith) hnpos.le +end SKGap +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Matrix/WordDerivative.lean b/lean/OAI/Probability/SKGap/Matrix/WordDerivative.lean new file mode 100644 index 0000000000000000000000000000000000000000..71d3eb602bd5fc3b4361d61bea33de7f9560c98a --- /dev/null +++ b/lean/OAI/Probability/SKGap/Matrix/WordDerivative.lean @@ -0,0 +1,187 @@ +import Mathlib +import OAI.Probability.SKGap.Matrix.Word +import OAI.Probability.SKGap.Matrix.MatrixWordIncrement + +namespace OAI + +section +noncomputable section +namespace SKGap +open Matrix Real Set Filter +open RealComplex +open scoped BigOperators Matrix.Norms.Frobenius SchwartzMap Topology +variable {ι : Type*} [Fintype ι] [DecidableEq ι] + +lemma pathDiagonal_square_all {a : ι→ℝ} (ha : ∀ i,0≤a i) {z : ℝ} (hz : 0≤z) : + pathDiagonal a z*pathDiagonal a z=z • diagonal a := by + simp only [pathDiagonal,diagonal_mul_diagonal] + ext i k + by_cases h : i=k + · subst k + simp only [Matrix.smul_apply,diagonal_apply_eq,smul_eq_mul] + calc + (sqrt z*sqrt (a i))*(sqrt z*sqrt (a i)) = (sqrt z*sqrt z)*(sqrt (a i)*sqrt (a i)) := by ring + _ = z*a i := by rw [mul_self_sqrt hz,mul_self_sqrt (ha i)] + · simp [h] + +lemma realProject_hasDerivAt {R : ℝ} (hR : 0≤R) (M E : Matrix ι ι ℝ) + (hM : Mᵀ=M) (hE : Eᵀ=E) (hMR : opNorm MrealProject R hR (M+t • E)) E 0 := by + have hc : Continuous (fun t : ℝ=>opNorm (M+t • E)) := + continuous_realOpNorm.comp (continuous_const.add (continuous_id.smul continuous_const)) + have he : (fun t : ℝ=>realProject R hR (M+t • E)) =ᶠ[𝓝 (0:ℝ)] (fun t=>M+t • E) := by + have hn : ∀ᶠ t in 𝓝 (0:ℝ),opNorm (M+t • E)M+t • E) E 0 := by + simpa only [one_smul] using! ((hasDerivAt_id (0:ℝ)).smul_const E).const_add M + exact hh.congr_of_eventuallyEq he + +def WordLetter.direction (f : 𝓢(ℝ,ℂ)) (R : ℝ) (hR : 0≤R) (j : ℝ) (a : ι→ℝ) + (z : ℝ) (M E : Matrix ι ι ℝ) : WordLetter ι→Matrix ι ι ℝ + | .diag _ => 0 + | .noise => E + | .inverse => z • (pathK f R hR j a z M*diagonal a*E*pathK f R hR j a z M) + +def actualWordDirection (f : 𝓢(ℝ,ℂ)) (R : ℝ) (hR : 0≤R) (j : ℝ) (a : ι→ℝ) + (z : ℝ) (M E : Matrix ι ι ℝ) : List (WordLetter ι)→Matrix ι ι ℝ + | [] => 0 + | l::F => l.direction f R hR j a z M E*actualWord f R hR j a z F M + + l.eval f R hR j a z M*actualWordDirection f R hR j a z M E F + +lemma WordLetter.hasDerivAt [Nonempty ι] (f : 𝓢(ℝ,ℂ)) {lo hi : ℝ} (hlo : 0l.eval f R hR j a z (M+t • E)) + (l.direction f R hR j a z M E) 0 := by + cases l with + | diag d => exact hasDerivAt_const _ _ + | noise => exact realProject_hasDerivAt hR M E hM hE hMR + | inverse => + have hh := realTruncatedK_derivative f hlo hf hR (pathDiagonal a z) + (pathShift z ((j/(Fintype.card ι:ℝ))*∑ b,a b)) M E (diagonal_transpose _) + (diagonal_transpose _) hM hE hMR hl hu + simpa only [WordLetter.eval,WordLetter.direction,pathK,pathDiagonal_square_all ha hz,Matrix.mul_smul,Matrix.smul_mul] using! hh + +theorem actualWord_hasDerivAt [Nonempty ι] (f : 𝓢(ℝ,ℂ)) {lo hi : ℝ} (hlo : 0actualWord f R hR j a z F (M+t • E)) (actualWordDirection f R hR j a z M E F) 0 := by + induction F with + | nil => exact hasDerivAt_const _ _ + | cons l F ih => + have hh := (l.hasDerivAt f hlo hf hR j ha hz M E hM hE hMR hl hu).mul ih + simpa only [actualWord,actualWordDirection,List.map_cons,matrixFactorProduct_cons,zero_smul,add_zero] using! hh +end SKGap +end +end + +section +noncomputable section +namespace SKGap +open Matrix Real Set +open RealComplex +open scoped BigOperators Matrix.Norms.Frobenius SchwartzMap +variable {ι : Type*} [Fintype ι] [DecidableEq ι] + +lemma word_opNorm_smul (r : ℝ) (M : Matrix ι ι ℝ) : opNorm (r • M)=|r| *opNorm M := by + unfold opNorm + rw [map_smul,map_smul,norm_smul,Real.norm_eq_abs] + +lemma WordLetter.direction_bound [Nonempty ι] (f : 𝓢(ℝ,ℂ)) {R j A D z : ℝ} + (hR : 0≤R) (hj : 0≤j) (hA : 0≤A) (hD : 0≤D) {a : ι→ℝ} + (ha : ∀ i,0≤a i) (haA : ∀ i,a i≤A) (hz : z∈Icc (0:ℝ) 1) + (M E : Matrix ι ι ℝ) (l : WordLetter ι) : + opNorm (l.direction f R hR j a z M E) ≤ + (1+|z| *A*(actualWordBound f R j A D)^2)*opNorm E := by + have hB := (actualWordBound_pos f hR hj hA hD).le + have hn : 0≤opNorm E := norm_nonneg _ + have hh : 0≤|z| *A*(actualWordBound f R j A D)^2 := by positivity + cases l with + | diag d => simp only [WordLetter.direction,opNorm,map_zero,norm_zero];positivity + | noise => change opNorm E ≤ _;nlinarith + | inverse => + have hk : opNorm (pathK f R hR j a z M)≤actualWordBound f R j A D := + (WordLetter.eval_bounds f hR hj hA hD ha haA hz .inverse trivial).1 M + have hd := opNorm_diagonal_le hA (fun i=>by rw [abs_of_nonneg (ha i)];exact haA i) + rw [WordLetter.direction,word_opNorm_smul] + have hprod : opNorm (pathK f R hR j a z M*diagonal a*E*pathK f R hR j a z M)≤ + actualWordBound f R j A D*A*opNorm E*actualWordBound f R j A D := by + apply (opNorm_mul _ _).trans + apply mul_le_mul _ hk (norm_nonneg _) (by positivity) + apply (opNorm_mul _ _).trans + apply mul_le_mul_of_nonneg_right _ hn + exact (opNorm_mul _ _).trans (mul_le_mul hk hd (norm_nonneg _) hB) + apply (mul_le_mul_of_nonneg_left hprod (abs_nonneg z)).trans + nlinarith + +theorem actualWordDirection_bound [Nonempty ι] (f : 𝓢(ℝ,ℂ)) {R j A D z : ℝ} + (hR : 0≤R) (hj : 0≤j) (hA : 0≤A) (hD : 0≤D) {a : ι→ℝ} + (ha : ∀ i,0≤a i) (haA : ∀ i,a i≤A) (hz : z∈Icc (0:ℝ) 1) + (F : List (WordLetter ι)) (hF : ∀ l∈F,l.bounded D) (M E : Matrix ι ι ℝ) : + let B : NNReal := ⟨actualWordBound f R j A D,(actualWordBound_pos f hR hj hA hD).le⟩ + opNorm (actualWordDirection f R hR j a z M E F) ≤ + (1+|z| *A*(B:ℝ)^2)*(wordParameterCoeff B F.length:ℝ)*opNorm E := by + intro B + have hB : 0≤(B:ℝ) := B.coe_nonneg + have hC : 0≤1+|z| *A*(B:ℝ)^2 := by positivity + have hE : 0≤opNorm E := norm_nonneg _ + induction F with + | nil => simp [actualWordDirection,wordParameterCoeff,opNorm] + | cons l F ih => + have hFt : ∀ p∈F,p.bounded D := fun p hp=>hF p (List.mem_cons_of_mem l hp) + have hd := l.direction_bound f hR hj hA hD ha haA hz M E + have ht := (actualWord_bounds f hR hj hA hD ha haA hz F hFt).1 M + have hl := (l.eval_bounds f hR hj hA hD ha haA hz (hF l List.mem_cons_self)).1 M + have hi := ih hFt + change opNorm (l.direction f R hR j a z M E)≤(1+|z| *A*(B:ℝ)^2)*opNorm E at hd + change opNorm (actualWord f R hR j a z F M)≤(B:ℝ)^F.length at ht + change opNorm (l.eval f R hR j a z M)≤(B:ℝ) at hl + rw [actualWordDirection] + apply (word_opNorm_add _ _).trans + apply (add_le_add (opNorm_mul _ _) (opNorm_mul _ _)).trans + have h1 := mul_le_mul hd ht (norm_nonneg _) (mul_nonneg hC hE) + have h2 := mul_le_mul hl hi (norm_nonneg _) hB + apply (add_le_add h1 h2).trans_eq + simp only [List.length_cons,wordParameterCoeff,NNReal.coe_add,NNReal.coe_mul,NNReal.coe_pow] + ring + +lemma WordLetter.direction_continuous [Nonempty ι] (f : 𝓢(ℝ,ℂ)) {R j A z : ℝ} + (hR : 0≤R) (hj : 0≤j) (hA : 0≤A) {a : ι→ℝ} + (ha : ∀ i,0≤a i) (haA : ∀ i,a i≤A) (hz : z∈Icc (0:ℝ) 1) + (E : Matrix ι ι ℝ) (l : WordLetter ι) : Continuous (fun M=>l.direction f R hR j a z M E) := by + cases l with + | diag d => exact continuous_const + | noise => exact continuous_const + | inverse => + have hk := pathK_continuous f hR hj hA ha haA hz + exact ((hk.matrix_mul continuous_const).matrix_mul continuous_const).matrix_mul hk |>.const_smul z + +lemma actualWordDirection_continuous [Nonempty ι] (f : 𝓢(ℝ,ℂ)) {R j A D z : ℝ} + (hR : 0≤R) (hj : 0≤j) (hA : 0≤A) (hD : 0≤D) {a : ι→ℝ} + (ha : ∀ i,0≤a i) (haA : ∀ i,a i≤A) (hz : z∈Icc (0:ℝ) 1) + (F : List (WordLetter ι)) (hF : ∀ l∈F,l.bounded D) (E : Matrix ι ι ℝ) : + Continuous (fun M=>actualWordDirection f R hR j a z M E F) := by + induction F with + | nil => exact continuous_const + | cons l F ih => + have hFt : ∀ p∈F,p.bounded D := fun p hp=>hF p (List.mem_cons_of_mem l hp) + have hl := (l.eval_bounds f hR hj hA hD ha haA hz (hF l List.mem_cons_self)).2.continuous + have ht := (actualWord_bounds f hR hj hA hD ha haA hz F hFt).2.continuous + exact ((l.direction_continuous f hR hj hA ha haA hz E).matrix_mul ht).add (hl.matrix_mul (ih hFt)) +end SKGap +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Matrix/WordDiag.lean b/lean/OAI/Probability/SKGap/Matrix/WordDiag.lean new file mode 100644 index 0000000000000000000000000000000000000000..f82d9731db6a7e84d16931ffdfbb122eaa8dbb21 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Matrix/WordDiag.lean @@ -0,0 +1,161 @@ +import Mathlib +import OAI.Probability.SKGap.Gaussian.DiagonalNormTail +import OAI.Probability.SKGap.Stability.WordOrdinaryAgreement + +namespace OAI + +section +noncomputable section +namespace SKGap +open Matrix Real Set MeasureTheory ProbabilityTheory Filter +open RealComplex +open scoped BigOperators Matrix.Norms.Frobenius SchwartzMap Topology + +theorem zeroDiag_exact_word_source_restriction {j A D c : ℝ} (hj : 0gaussianReal 0 1)) + {g | opNorm (removeDiagonal (goeMatrix (j/n) g))≤2*sqrt j+1+1 ∧ + ∃ (a : Fin n→ℝ) (F : List (WordLetter (Fin n))), + (∀ i,a i∈Icc 0 A) ∧ F.length≤L ∧ (∀ l∈F,l.bounded D) ∧ inverseCount F≤1 ∧ + (inverseCount F=0 ∨ c≤ComplexSpectral.lowerRayleigh (liftMatrix (stabilityMatrix a 1 + ((j/(n:ℝ))*∑ b,a b) (removeDiagonal (goeMatrix (j/n) g))))) ∧ + C< matrixWordSeminorm p + (exactWord j a F (removeDiagonal (goeMatrix (j/n) g))-Matrix.diagonal (wordPrediction j a 1 F))} ≤ + (wordPatternSet L L).card*ENNReal.ofReal (3*exp (-(n:ℝ)))+ + ENNReal.ofReal (exp (-2*(n:ℝ)/(π^2*(sqrt (2*j))^2))) := by + let R := 2*sqrt j+1+1 + let lo := min c ((1-sqrt j*A)^2/4) + let hi := 2+A*(R+j*A) + have hR : 0≤R := by dsimp [R];positivity + have hint := path_interval hj.le hA.le hs + have hlo : 0(ha i).1 + have haA : ∀ i,a i≤A := fun i=>(ha i).2 + have hq := diagonal_mean_bounds hj.le haq haA + simp only [Fintype.card_fin] at hq + have hb := stabilityMatrix_opNorm haq haA hA.le (show (1:ℝ)∈Icc 0 1 from ⟨zero_le_one,le_rfl⟩) hq.1 hMR + have hnrm : opNorm (stabilityMatrix a 1 ((j/(n:ℝ))*∑ b,a b) (removeDiagonal (goeMatrix (j/n) g)))≤hi := by + apply hb.trans + dsimp [hi,R] + nlinarith + have hu : -hi≤ComplexSpectral.lowerRayleigh (-liftMatrix (stabilityMatrix a 1 + ((j/(n:ℝ))*∑ b,a b) (removeDiagonal (goeMatrix (j/n) g)))) := + (neg_le_neg hnrm).trans (lowerRayleigh_neg_lift_ge _) + have hl : lo≤ComplexSpectral.lowerRayleigh (liftMatrix (stabilityMatrix a 1 + ((j/(n:ℝ))*∑ b,a b) (removeDiagonal (goeMatrix (j/n) g)))) := (min_le_left _ _).trans hstable + rw [stabilityMatrix_path_rep a haq zero_le_one] at hl hu + have he := actualWord_agrees f hlo hf hR j haq (removeDiagonal (goeMatrix (j/n) g)) + (by simp [removeDiagonal,Matrix.transpose_sub,goeMatrix_transpose]) hMR (by simpa only [Fintype.card_fin] using hl) + (by simpa only [Fintype.card_fin] using hu) F + rwa [he] +end SKGap +end +end + +section +noncomputable section +namespace SKGap +open Matrix Real Set MeasureTheory ProbabilityTheory Filter +open RealComplex +open scoped BigOperators Matrix.Norms.Frobenius SchwartzMap Topology + +theorem zeroDiag_exact_word_unrestricted_prediction {j A D c : ℝ} (hj : 0gaussianReal 0 1)) + {g | ∃ (a : Fin n→ℝ) (F : List (WordLetter (Fin n))), + (∀ i,a i∈Icc 0 A) ∧ F.length≤L ∧ (∀ l∈F,l.bounded D) ∧ inverseCount F≤1 ∧ + (inverseCount F=0 ∨ c≤ComplexSpectral.lowerRayleigh (liftMatrix (stabilityMatrix a 1 + ((j/(n:ℝ))*∑ b,a b) (removeDiagonal (goeMatrix (j/n) g))))) ∧ + C< matrixWordSeminorm p + (exactWord j a F (removeDiagonal (goeMatrix (j/n) g))-Matrix.diagonal (wordPrediction j a 1 F))} ≤ + (wordPatternSet L L).card*ENNReal.ofReal (3*exp (-(n:ℝ)))+ + ENNReal.ofReal (exp (-2*(n:ℝ)/(π^2*(sqrt (2*j))^2))) + + (ENNReal.ofReal (2*exp (-(n:ℝ)/(π^2*j)))+ + ENNReal.ofReal (2*(n:ℝ)*exp (-1/(8*(j/n))))) := by + obtain ⟨C,N,hC,hN,ht⟩ := zeroDiag_exact_word_source_restriction hj hA hs hD hAD hc L + refine ⟨C,N,hC,hN,?_⟩ + intro n hn p + have hn0 : 0gaussianReal 0 1)) + {g | ∃ (p : Bool) (a : Fin n→ℝ) (F : List (WordLetter (Fin n))), + (∀ i,a i∈Icc 0 A) ∧ F.length≤L ∧ (∀ l∈F,l.bounded D) ∧ inverseCount F≤1 ∧ + (inverseCount F=0 ∨ c≤ComplexSpectral.lowerRayleigh (liftMatrix (stabilityMatrix a 1 + ((j/(n:ℝ))*∑ b,a b) (removeDiagonal (goeMatrix (j/n) g))))) ∧ + C< matrixWordSeminorm p + (exactWord j a F (removeDiagonal (goeMatrix (j/n) g))-Matrix.diagonal (wordPrediction j a 1 F))} ≤ + 2*((wordPatternSet L L).card*ENNReal.ofReal (3*exp (-(n:ℝ)))+ + ENNReal.ofReal (exp (-2*(n:ℝ)/(π^2*(sqrt (2*j))^2))) + + (ENNReal.ofReal (2*exp (-(n:ℝ)/(π^2*j)))+ + ENNReal.ofReal (2*(n:ℝ)*exp (-1/(8*(j/n)))))) := by + obtain ⟨C,N,hC,hN,ht⟩ := zeroDiag_exact_word_unrestricted_prediction hj hA hs hD hAD hc L + refine ⟨C,N,hC,hN,?_⟩ + intro n hn + let B := fun p : Bool=> {g : MatrixCoordinates (Fin n)→ℝ | ∃ (a : Fin n→ℝ) (F : List (WordLetter (Fin n))), + (∀ i,a i∈Icc 0 A) ∧ F.length≤L ∧ (∀ l∈F,l.bounded D) ∧ inverseCount F≤1 ∧ + (inverseCount F=0 ∨ c≤ComplexSpectral.lowerRayleigh (liftMatrix (stabilityMatrix a 1 + ((j/(n:ℝ))*∑ b,a b) (removeDiagonal (goeMatrix (j/n) g))))) ∧ + C< matrixWordSeminorm p + (exactWord j a F (removeDiagonal (goeMatrix (j/n) g))-Matrix.diagonal (wordPrediction j a 1 F))} + have hsub : {g | ∃ (p : Bool),g∈B p}⊆B false∪B true := by + intro g hg + obtain ⟨p,hp⟩ := hg + cases p + · exact Or.inl hp + · exact Or.inr hp + apply ((measure_mono hsub).trans (measure_union_le (B false) (B true))).trans + simpa only [two_mul] using add_le_add (ht n hn false) (ht n hn true) +end SKGap +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Matrix/WordDiagUniform.lean b/lean/OAI/Probability/SKGap/Matrix/WordDiagUniform.lean new file mode 100644 index 0000000000000000000000000000000000000000..d0c1ff8dcb10a39b1ebf8d254a90a28a92dc96dd --- /dev/null +++ b/lean/OAI/Probability/SKGap/Matrix/WordDiagUniform.lean @@ -0,0 +1,207 @@ +import Mathlib +import OAI.Probability.SKGap.Stability.WordDiagStable +import OAI.Probability.SKGap.Gaussian.DiagonalNormTail +import OAI.Probability.SKGap.Stability.WordOrdinaryAgreement + +namespace OAI + +section +noncomputable section +namespace SKGap +open Matrix Real Set MeasureTheory ProbabilityTheory Filter +open RealComplex +open scoped BigOperators Matrix.Norms.Frobenius SchwartzMap Topology + +theorem zeroDiag_exact_word_uniform_prediction {j A D c : ℝ} (hj : 0gaussianReal 0 1)) + {g | ∃ (a : Fin n→ℝ) (F : List (WordLetter (Fin n))), + (∀ i,a i∈Icc 0 A) ∧ F.length≤L ∧ (∀ l∈F,l.bounded D) ∧ inverseCount F≤1 ∧ + c≤ComplexSpectral.lowerRayleigh (liftMatrix (stabilityMatrix a 1 + ((j/(n:ℝ))*∑ b,a b) (removeDiagonal (goeMatrix (j/n) g)))) ∧ + C< matrixWordSeminorm p + (exactWord j a F (removeDiagonal (goeMatrix (j/n) g))-Matrix.diagonal (wordPrediction j a 1 F))} ≤ + (wordPatternSet L L).card*ENNReal.ofReal (3*exp (-(n:ℝ)))+ + ENNReal.ofReal (exp (-2*(n:ℝ)/(π^2*(sqrt (2*j))^2))) + + (ENNReal.ofReal (2*exp (-(n:ℝ)/(π^2*j)))+ + ENNReal.ofReal (2*(n:ℝ)*exp (-1/(8*(j/n))))) := by + obtain ⟨C,N,hC,hN,ht⟩ := zeroDiag_exact_word_simultaneous_prediction hj hA hs hD hAD hc L + refine ⟨C,N,hC,hN,?_⟩ + intro n hn p + have hn0 : 0(ha i).1) (fun i=>(ha i).2) + (show (1:ℝ)∈Icc 0 1 from ⟨zero_le_one,le_rfl⟩) F hF).1 M).trans (pow_le_pow_right₀ hB hFL) + · have haq : ∀ i,0≤a i := fun i=>(ha i).1 + have haA : ∀ i,a i≤A := fun i=>(ha i).2 + have hq := diagonal_mean_bounds hj haq haA + simp only [Fintype.card_fin] at hq + have hb := stabilityMatrix_opNorm haq haA hA (show (1:ℝ)∈Icc 0 1 from ⟨zero_le_one,le_rfl⟩) hq.1 hMR + have hnrm : opNorm (stabilityMatrix a 1 ((j/(n:ℝ))*∑ b,a b) M)≤hi := by + apply hb.trans + apply le_trans _ (le_max_right c (2+A*(R+j*A))) + nlinarith + have hu : -hi≤ComplexSpectral.lowerRayleigh (-liftMatrix (stabilityMatrix a 1 ((j/(n:ℝ))*∑ b,a b) M)) := + (neg_le_neg hnrm).trans (lowerRayleigh_neg_lift_ge _) + rw [stabilityMatrix_path_rep a haq zero_le_one] at hstable hu + have he := actualWord_agrees f hc hf hR j haq M hM hMR + (by simpa only [Fintype.card_fin] using hstable) (by simpa only [Fintype.card_fin] using hu) F + rw [←he] + exact ((actualWord_bounds f hR hj hA hD haq haA + (show (1:ℝ)∈Icc 0 1 from ⟨zero_le_one,le_rfl⟩) F hF).1 M).trans (pow_le_pow_right₀ hB hFL) +end SKGap +end +end + +section +noncomputable section +namespace SKGap +open Polynomial +open scoped BigOperators +variable {ι : Type*} [Fintype ι] + +omit [Fintype ι] in +lemma wordRecursionAt_degree_budget (a : ι→ℝ) (P Q : List (WordLetter ι)) + (t : WordRecursionTerm ι) (ht : t∈wordRecursionAt a P Q) : + (if t.inversePartner then 1 else 0)+ordinaryCount t.inner+ordinaryCount t.outer ≤ + ordinaryCount (P++(.noise::Q)) := by + dsimp only [wordRecursionAt] at ht + rw [List.mem_append] at ht + rcases ht with ht|ht + · obtain ⟨c,hc,rfl⟩ := List.mem_map.mp ht + have hh := (wordPartners_counts a P c hc).1 + cases hi : c.inversePartner <;> simp [WordCut.asLeft,hi] at * <;> omega + · obtain ⟨c,hc,rfl⟩ := List.mem_map.mp ht + have hh := (wordPartners_counts a Q c hc).1 + cases hi : c.inversePartner <;> simp [WordCut.asRight,hi] at * <;> omega + +omit [Fintype ι] in +lemma wordRecursionTerms_degree_budget (a : ι→ℝ) (F : List (WordLetter ι)) + (t : WordRecursionTerm ι) (ht : t∈wordRecursionTerms a F) : + (if t.inversePartner then 1 else 0)+ordinaryCount t.inner+ordinaryCount t.outer ≤ ordinaryCount F := by + unfold wordRecursionTerms at ht + cases hs : firstNoiseSplit F with + | none => simp [hs] at ht + | some pq => + rcases pq with ⟨P,Q⟩ + have he := firstNoiseSplit_some F P Q hs + simp only [hs] at ht + simpa only [he] using wordRecursionAt_degree_budget a P Q t ht + +def wordPredictionPolynomial (j : ℝ) (a : ι→ℝ) (F : List (WordLetter ι)) (i : ι) : ℝ[X] := + if ordinaryCount F=0 then C (wordDiagonal F i) else + ((wordRecursionTerms a F).attach.map (fun th=> + (if th.val.inversePartner then X else 1)*C j* + (C ((Fintype.card ι:ℝ)⁻¹)*(∑ k,wordPredictionPolynomial j a th.val.inner k))* + wordPredictionPolynomial j a th.val.outer i)).sum +termination_by ordinaryCount F +decreasing_by + · exact (wordRecursionTerms_decreases a F th.val th.property).2 + · exact (wordRecursionTerms_decreases a F th.val th.property).1 + +lemma polynomial_list_degree_le (l : List ℝ[X]) (n : ℕ) (h : ∀ p∈l,p.natDegree≤n) : l.sum.natDegree≤n := by + induction l with + | nil => simp + | cons p l ih => + rw [List.sum_cons] + exact (natDegree_add_le p l.sum).trans (max_le (h p (List.mem_cons_self)) (ih (fun q hq=>h q (List.mem_cons_of_mem _ hq)))) +lemma polynomial_eval_list_sum (l : List ℝ[X]) (z : ℝ) : + eval z l.sum=(l.map (eval z)).sum := by + induction l with + | nil => simp + | cons p l ih => simp only [List.sum_cons,eval_add,List.map_cons,ih] + +theorem wordPredictionPolynomial_spec (j : ℝ) (a : ι→ℝ) (F : List (WordLetter ι)) : + ∀ i,(wordPredictionPolynomial j a F i).natDegree≤ordinaryCount F ∧ + ∀ z,eval z (wordPredictionPolynomial j a F i)=wordPrediction j a z F i := by + generalize hk : ordinaryCount F=k + induction k using Nat.strong_induction_on generalizing F with + | h k ih => + have hsub (t : WordRecursionTerm ι) (ht : t∈wordRecursionTerms a F) : + (∀ i,(wordPredictionPolynomial j a t.inner i).natDegree≤ordinaryCount t.inner ∧ + ∀ z,eval z (wordPredictionPolynomial j a t.inner i)=wordPrediction j a z t.inner i) ∧ + (∀ i,(wordPredictionPolynomial j a t.outer i).natDegree≤ordinaryCount t.outer ∧ + ∀ z,eval z (wordPredictionPolynomial j a t.outer i)=wordPrediction j a z t.outer i) := by + have hh := wordRecursionTerms_decreases a F t ht + exact ⟨ih _ (by omega) _ rfl,ih _ (by omega) _ rfl⟩ + intro i + by_cases ho : ordinaryCount F=0 + · rw [wordPredictionPolynomial] + simp only [ho,ite_true,natDegree_C,zero_le,eval_C,true_and] + intro z + exact (wordPrediction_base j a z F i ho).symm + constructor + · rw [wordPredictionPolynomial,ite_eq_right ho] + apply polynomial_list_degree_le + intro p hp + obtain ⟨t,ht,rfl⟩ := List.mem_map.mp hp + have hs := hsub t.val t.property + have hinner : (C ((Fintype.card ι:ℝ)⁻¹)*(∑ u,wordPredictionPolynomial j a t.val.inner u)).natDegree≤ordinaryCount t.val.inner := + (natDegree_C_mul_le _ _).trans (natDegree_sum_le_of_forall_le _ _ (fun u _=>(hs.1 u).1)) + have hw : (if t.val.inversePartner then (X:ℝ[X]) else 1).natDegree≤(if t.val.inversePartner then 1 else 0) := by + cases t.val.inversePartner <;> simp + have hj : ((if t.val.inversePartner then (X:ℝ[X]) else 1)*C j).natDegree≤(if t.val.inversePartner then 1 else 0) := + (natDegree_mul_C_le _ _).trans hw + have hb := wordRecursionTerms_degree_budget a F t.val t.property + rw [hk] at hb + exact natDegree_mul_le.trans ((add_le_add (natDegree_mul_le.trans (add_le_add hj hinner)) (hs.2 i).1).trans hb) + · intro z + rw [wordPredictionPolynomial,ite_eq_right ho,wordPrediction,ite_eq_right ho,polynomial_eval_list_sum,List.map_map] + congr 1 + apply List.map_congr_left + intro t ht + have hs := hsub t.val t.property + simp only [Function.comp_def,eval_mul,eval_C,eval_finsetSum] + simp_rw [(hs.1 _).2 z,(hs.2 _).2 z] + cases t.val.inversePartner <;> simp only [Bool.false_eq_true,ite_false,ite_true,eval_one,eval_X] <;> ring +end SKGap +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Matrix/WordExpectedRecursion.lean b/lean/OAI/Probability/SKGap/Matrix/WordExpectedRecursion.lean new file mode 100644 index 0000000000000000000000000000000000000000..d389e89783de47809f9cca61828aedeffc37b14a --- /dev/null +++ b/lean/OAI/Probability/SKGap/Matrix/WordExpectedRecursion.lean @@ -0,0 +1,61 @@ +import Mathlib +import OAI.Probability.SKGap.Matrix.WordLoopLeading +import OAI.Probability.SKGap.Localization.MarkedErrorRate + +namespace OAI + +section +noncomputable section +namespace SKGap +open Matrix Real MeasureTheory ProbabilityTheory Set +open scoped BigOperators Matrix.Norms.Frobenius SchwartzMap + +def wordMarkedCost (B : NNReal) (j R A c z : ℝ) (p q : ℕ) : ℝ := + markedRateConstant j R c ((p:NNReal)*B^p) ((q:NNReal)*B^q) (B^p) (B^q) + (wordDifferentialBound B A z p) (wordDifferentialBound B A z q) + +theorem actualWord_expected_recursion {n : ℕ} (hn : 0gaussianReal 0 1))|≤ + wordMarkedCost B j R A (pathRate j A) z P.length Q.length/(n:ℝ) := by + simpa only [wordExpected,Fintype.card_fin,wordMarkedCost] using he + have ht := (abs_sub_le (wordExpected f hR j a z (P++(.noise::Q)) i) + ((j/(n:ℝ))*(∫ g : MatrixCoordinates (Fin n)→ℝ, + actualWordLoop f hR j a z P Q (goeMatrix (j/n) g) i + ∂Measure.pi (fun _=>gaussianReal 0 1))) + (wordRecursionAtExpected f hR j a z P Q i)).trans (add_le_add he' hl) + simpa only [wordExpected,Fintype.card_fin,wordMarkedCost,add_div,B,NNReal.coe_mk] using! ht +end SKGap +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Matrix/WordFockSeries.lean b/lean/OAI/Probability/SKGap/Matrix/WordFockSeries.lean new file mode 100644 index 0000000000000000000000000000000000000000..532ed5728f078b07978966882776b9bb409248af --- /dev/null +++ b/lean/OAI/Probability/SKGap/Matrix/WordFockSeries.lean @@ -0,0 +1,211 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.FockSeries + +namespace OAI + +section + +noncomputable section +open scoped BigOperators +namespace SKGap.Noncrossing.Primary.Tensor.Series +open Diagram InverseDiagram WordSeries Loop +variable {ι : Type*} [Fintype ι] + +def wordOperator (j : ℝ) (a : ι→ℝ) : List (WordLetter ι)→Seq (ι:=ι)→ₗ[ℝ] Seq (ι:=ι) + | [] => LinearMap.id + | .diag d::F => (act (diagonal d)).comp (wordOperator j a F) + | .noise::F => (act (noise j)).comp (wordOperator j a F) + | .inverse::F => (inverse j a).comp (wordOperator j a F) + +def wordSeq (j : ℝ) (a : ι→ℝ) (F : List (WordLetter ι)) : Seq (ι:=ι) := + wordOperator j a F (ofVector vacuum) + +omit [Fintype ι] in +lemma act_comp (A B : Space (ι:=ι)→ₗ[ℝ] Space (ι:=ι)) : + act (A.comp B)=(act A).comp (act B) := rfl +omit [Fintype ι] in +lemma act_ofVector (A : Space (ι:=ι)→ₗ[ℝ] Space (ι:=ι)) (v : Space (ι:=ι)) : + act A (ofVector v)=ofVector (A v) := by + funext n + simp only [act_apply,ofVector] + split_ifs <;> simp +lemma wordOperator_append (j : ℝ) (a : ι→ℝ) (P Q : List (WordLetter ι)) : + wordOperator j a (P++Q)=(wordOperator j a P).comp (wordOperator j a Q) := by + induction P with + | nil => simp [wordOperator] + | cons l P ih => cases l <;> simp [wordOperator,ih,LinearMap.comp_assoc] +lemma wordOperator_lift (j : ℝ) (a : ι→ℝ) (P : List (Letter (ι→ℝ))) : + wordOperator j a (liftWord P)=act (word j P) := by + induction P with + | nil => rfl + | cons l P ih => cases l <;> simp only [liftWord_cons,Letter.toWord,wordOperator,word,letter,ih,act_comp] +lemma wordSeq_lift (j : ℝ) (a : ι→ℝ) (P : List (Letter (ι→ℝ))) : + wordSeq j a (liftWord P)=ofVector (word j P vacuum) := by + rw [wordSeq,wordOperator_lift,act_ofVector] +lemma wordSeq_oneInverse (j : ℝ) (a : ι→ℝ) (P Q : List (Letter (ι→ℝ))) (n : ℕ) : + wordSeq j a (liftWord P++(.inverse::liftWord Q)) n= + word j P (kernel j a n (word j Q vacuum)) := by + simp only [wordSeq,wordOperator_append,wordOperator,wordOperator_lift, + LinearMap.comp_apply,act_ofVector,act_apply,inverse_ofVector] +lemma project_kernel_sandwich (j : ℝ) (a : ι→ℝ) (P Q : List (Letter (ι→ℝ))) (n : ℕ) (i : ι) : + project (word j P (kernel j a n (word j Q vacuum))) i=inverseCoefficient j a P Q n i := by + simp only [kernel,LinearMap.sum_apply,map_sum,Finset.sum_apply,inverseCoefficient] + apply Finset.sum_congr rfl + intro bs _ + rw [←Tensor.project_word,word_append,word_append] + rfl + +theorem wordSeq_project_coeff (j : ℝ) (a : ι→ℝ) (F : List (WordLetter ι)) + (hF : inverseCount F≤1) (n : ℕ) (i : ι) : + project (wordSeq j a F n) i=(wordPredictionPolynomial j a F i).coeff n := by + have h:=congrArg (PowerSeries.coeff n) + (literalSeries_eq_wordPredictionPolynomial j a F hF i) + rw [Polynomial.coeff_coe] at h + rw [←h] + rcases one_inverse_cases F hF with ⟨P,rfl⟩ | ⟨P,Q,rfl⟩ + · rw [wordSeq_lift,literalSeries_lift] + simp only [ofVector,PowerSeries.coeff_C] + split_ifs <;> simp_all [Tensor.project_word] + · rw [wordSeq_oneInverse,project_kernel_sandwich,literalSeries_oneInverse,coeff_inverseSeries] + +end SKGap.Noncrossing.Primary.Tensor.Series + +end +end + +section + +noncomputable section +open scoped BigOperators +namespace SKGap.Noncrossing.Primary.Tensor.Series +open Diagram InverseDiagram WordSeries Loop +variable {ι : Type*} [Fintype ι] + +def shifts : ℕ→Seq (ι:=ι)→ₗ[ℝ] Seq (ι:=ι) + | 0 => LinearMap.id + | n+1 => shift.comp (shifts n) + +def letterOperator (j : ℝ) (a : ι→ℝ) : WordLetter ι→Seq (ι:=ι)→ₗ[ℝ] Seq (ι:=ι) + | .diag d => act (diagonal d) + | .noise => act (noise j) + | .inverse => inverse j a +lemma letter_shift (j : ℝ) (a : ι→ℝ) (l : WordLetter ι) (v : Seq (ι:=ι)) : + letterOperator j a l (shift v)=shift (letterOperator j a l v) := by + cases l with + | diag d => exact act_shift _ _ + | noise => exact act_shift _ _ + | inverse => exact inverse_shift _ _ _ +lemma letter_shifts (j : ℝ) (a : ι→ℝ) (l : WordLetter ι) (n : ℕ) (v : Seq (ι:=ι)) : + letterOperator j a l (shifts n v)=shifts n (letterOperator j a l v) := by + induction n with + | zero => rfl + | succ n ih => simpa only [shifts,LinearMap.comp_apply,letter_shift] using congrArg shift ih +lemma wordSeq_cons (j : ℝ) (a : ι→ℝ) (l : WordLetter ι) (F : List (WordLetter ι)) : + wordSeq j a (l::F)=letterOperator j a l (wordSeq j a F) := by cases l <;> rfl + +abbrev GradedWords (ι : Type*) := List (ℝ×ℕ×List (WordLetter ι)) +namespace GradedWords + +def scalar (c : ℝ) : GradedWords ι := [(c,0,[])] +def scale (c : ℝ) (P : GradedWords ι) : GradedWords ι := P.map (fun t=>(c*t.1,t.2)) +def bump (P : GradedWords ι) : GradedWords ι := P.map (fun t=>(t.1,t.2.1+1,t.2.2)) +def prepend (l : WordLetter ι) (P : GradedWords ι) : GradedWords ι := P.map (fun t=>(t.1,t.2.1,l::t.2.2)) +def seq (j : ℝ) (a : ι→ℝ) (P : GradedWords ι) : Seq (ι:=ι) := + (P.map (fun t=>t.1 • shifts t.2.1 (wordSeq j a t.2.2))).sum + +def predictionPolynomial (j : ℝ) (a : ι→ℝ) (P : GradedWords ι) (i : ι) : Polynomial ℝ := + (P.map (fun t=>Polynomial.C t.1*Polynomial.X^t.2.1*wordPredictionPolynomial j a t.2.2 i)).sum + +def prediction (j : ℝ) (a : ι→ℝ) (z : ℝ) (P : GradedWords ι) (i : ι) : ℝ := + (P.map (fun t=>t.1*z^t.2.1*wordPrediction j a z t.2.2 i)).sum + +lemma seq_scalar (j c : ℝ) (a : ι→ℝ) : seq j a (scalar c)=ofVector (c • vacuum) := by + simp only [seq,scalar,List.map_cons,List.map_nil,List.sum_cons,List.sum_nil,add_zero,shifts, + LinearMap.id_coe,wordSeq,wordOperator] + funext n + simp only [Pi.smul_apply,ofVector] + split_ifs <;> simp_all [ofVector] +lemma seq_append (j : ℝ) (a : ι→ℝ) (P Q : GradedWords ι) : + seq j a (P++Q)=seq j a P+seq j a Q := by simp [seq] +lemma seq_scale (j c : ℝ) (a : ι→ℝ) (P : GradedWords ι) : + seq j a (scale c P)=c • seq j a P := by + induction P with + | nil => simp [seq,scale] + | cons t P ih => + simp only [scale,List.map_cons,seq,List.sum_cons] + change (c*t.1) • _+seq j a (scale c P)=c • (t.1 • _+seq j a P) + rw [ih,smul_add,smul_smul] +lemma seq_bump (j : ℝ) (a : ι→ℝ) (P : GradedWords ι) : + seq j a (bump P)=shift (seq j a P) := by + simp [seq,bump,List.map_map,Function.comp_def,shifts,map_list_sum] +lemma seq_prepend (j : ℝ) (a : ι→ℝ) (P : GradedWords ι) (l : WordLetter ι) : + seq j a (prepend l P)=letterOperator j a l (seq j a P) := by + simp [seq,prepend,List.map_map,Function.comp_def,wordSeq_cons,map_list_sum,letter_shifts] +lemma predictionPolynomial_eval (j : ℝ) (a : ι→ℝ) (z : ℝ) (P : GradedWords ι) (i : ι) : + Polynomial.eval z (predictionPolynomial j a P i)=prediction j a z P i := by + simp only [predictionPolynomial,prediction,polynomial_eval_list_sum,List.map_map, + Function.comp_def,Polynomial.eval_mul,Polynomial.eval_C,Polynomial.eval_pow,Polynomial.eval_X] + congr 1 + apply List.map_congr_left + intro t _ + rw [(wordPredictionPolynomial_spec j a _ i).2 z] + +end GradedWords + +def projectSeries (i : ι) : Seq (ι:=ι)→ₗ[ℝ] PowerSeries ℝ where + toFun v := PowerSeries.mk (fun n=>project (v n) i) + map_add' v w := by ext n; simp + map_smul' c v := by ext n; simp +omit [Fintype ι] in +@[simp] lemma projectSeries_coeff (i : ι) (v : Seq (ι:=ι)) (n : ℕ) : + PowerSeries.coeff n (projectSeries i v)=project (v n) i := by simp [projectSeries] +omit [Fintype ι] in +lemma projectSeries_shift (i : ι) (v : Seq (ι:=ι)) : + projectSeries i (shift v)=PowerSeries.X*projectSeries i v := by + ext n + cases n with + | zero => simp + | succ n => simp +omit [Fintype ι] in +lemma projectSeries_shifts (i : ι) (v : Seq (ι:=ι)) (d : ℕ) : + projectSeries i (shifts d v)=PowerSeries.X^d*projectSeries i v := by + induction d with + | zero => simp [shifts] + | succ d ih => simp only [shifts,LinearMap.comp_apply,projectSeries_shift,ih,pow_succ']; ring +lemma projectSeries_word (j : ℝ) (a : ι→ℝ) (F : List (WordLetter ι)) (hF : inverseCount F≤1) (i : ι) : + projectSeries i (wordSeq j a F)=(wordPredictionPolynomial j a F i : PowerSeries ℝ) := by + ext n + simp only [projectSeries_coeff,Polynomial.coeff_coe,wordSeq_project_coeff j a F hF] + +namespace GradedWords + +theorem projectSeries_eq (j : ℝ) (a : ι→ℝ) (P : GradedWords ι) + (hP : ∀ t∈P,inverseCount t.2.2≤1) (i : ι) : + projectSeries i (seq j a P)=(predictionPolynomial j a P i : PowerSeries ℝ) := by + induction P with + | nil => simp [seq,predictionPolynomial] + | cons t P ih => + simp only [seq,predictionPolynomial,List.map_cons,List.sum_cons,map_add,map_smul, + Polynomial.coe_add,Polynomial.coe_mul,Polynomial.coe_pow,Polynomial.coe_C,Polynomial.coe_X] + change _ + projectSeries i (seq j a P)=_+(predictionPolynomial j a P i : PowerSeries ℝ) + rw [ih (by intro s hs; exact hP s (List.mem_cons_of_mem _ hs)), + projectSeries_shifts,projectSeries_word j a _ (hP t (by simp))] + simp [Algebra.smul_def,mul_assoc] + +theorem prediction_zero_of_project (j : ℝ) (a : ι→ℝ) (P : GradedWords ι) + (hP : ∀ t∈P,inverseCount t.2.2≤1) (i : ι) + (hz : ∀ n,project (seq j a P n) i=0) (z : ℝ) : prediction j a z P i=0 := by + have hp : predictionPolynomial j a P i=0 := by + apply Polynomial.ext + intro n + have h:=congrArg (PowerSeries.coeff n) (projectSeries_eq j a P hP i) + simp only [projectSeries_coeff,Polynomial.coeff_coe,hz] at h + simpa using h.symm + rw [←predictionPolynomial_eval,hp,Polynomial.eval_zero] +end GradedWords +end SKGap.Noncrossing.Primary.Tensor.Series + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Matrix/WordIncrement.lean b/lean/OAI/Probability/SKGap/Matrix/WordIncrement.lean new file mode 100644 index 0000000000000000000000000000000000000000..fb28a743a4bfb8ae6361a47c5d2a7225a4ceb0e2 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Matrix/WordIncrement.lean @@ -0,0 +1,212 @@ +import Mathlib +import OAI.Probability.SKGap.Matrix.Word +import OAI.Probability.SKGap.Matrix.MatrixWordIncrement +import OAI.Probability.SKGap.Brownian.PathParameter + +namespace OAI + +section +noncomputable section +namespace SKGap +open Matrix Real Set +open scoped BigOperators Matrix.Norms.Frobenius SchwartzMap +variable {ι : Type*} [Fintype ι] [DecidableEq ι] + +omit [Fintype ι] [DecidableEq ι] in +def WordLetter.close (δ : ℝ) : WordLetter ι→WordLetter ι→Prop + | .diag d,.diag e => ∀ i,|d i-e i|≤δ + | .noise,.noise => True + | .inverse,.inverse => True + | _,_ => False + +def wordHolderScale (f : 𝓢(ℝ,ℂ)) (R j A : ℝ) : ℝ := + (1+j)*(1+|ComplexMatrix.parameterKC f R (sqrt A) (j*A) (2*sqrt A*(j*A)+(sqrt A)^2)|+ + |ComplexMatrix.parameterKM f R (sqrt A) (j*A) (2*sqrt A*(j*A)+(sqrt A)^2)|) + +lemma wordHolderScale_ge_one (f : 𝓢(ℝ,ℂ)) (R A : ℝ) {j : ℝ} (hj : 0≤j) : + 1≤wordHolderScale f R j A := by + unfold wordHolderScale + nlinarith [abs_nonneg (ComplexMatrix.parameterKC f R (sqrt A) (j*A) (2*sqrt A*(j*A)+(sqrt A)^2)), + abs_nonneg (ComplexMatrix.parameterKM f R (sqrt A) (j*A) (2*sqrt A*(j*A)+(sqrt A)^2))] + +lemma wordHolderScale_constants (f : 𝓢(ℝ,ℂ)) (R A : ℝ) {j : ℝ} (hj : 0≤j) : + ComplexMatrix.parameterKC f R (sqrt A) (j*A) (2*sqrt A*(j*A)+(sqrt A)^2)*(1+j)≤wordHolderScale f R j A ∧ + ComplexMatrix.parameterKM f R (sqrt A) (j*A) (2*sqrt A*(j*A)+(sqrt A)^2)*(1+j)≤wordHolderScale f R j A := by + have hc := le_abs_self (ComplexMatrix.parameterKC f R (sqrt A) (j*A) (2*sqrt A*(j*A)+(sqrt A)^2)) + have hm := le_abs_self (ComplexMatrix.parameterKM f R (sqrt A) (j*A) (2*sqrt A*(j*A)+(sqrt A)^2)) + have hc0 := abs_nonneg (ComplexMatrix.parameterKC f R (sqrt A) (j*A) (2*sqrt A*(j*A)+(sqrt A)^2)) + have hm0 := abs_nonneg (ComplexMatrix.parameterKM f R (sqrt A) (j*A) (2*sqrt A*(j*A)+(sqrt A)^2)) + have h1 : 0≤1+j := by linarith + unfold wordHolderScale + constructor + · have h := mul_le_mul_of_nonneg_right hc h1 + nlinarith + · have h := mul_le_mul_of_nonneg_right hm h1 + nlinarith + +lemma WordLetter.eval_pair [Nonempty ι] (f : 𝓢(ℝ,ℂ)) {R j A D δ : ℝ} + (hR : 0≤R) (hj : 0≤j) (hA : 0≤A) (hD : 0≤D) (hδ : 0≤δ) (hδ1 : δ≤1) + {a b : ι→ℝ} (ha : ∀ i,0≤a i) (hb : ∀ i,0≤b i) (haA : ∀ i,a i≤A) (hbA : ∀ i,b i≤A) + (hab : ∀ i,|a i-b i|≤δ) (l m : WordLetter ι) (hl : l.bounded D) (hm : m.bounded D) + (hlm : l.close δ m) : + let B : NNReal := ⟨actualWordBound f R j A D,(actualWordBound_pos f hR hj hA hD).le⟩ + let Δ : NNReal := ⟨wordHolderScale f R j A*sqrt δ,mul_nonneg (zero_le_one.trans (wordHolderScale_ge_one f R A hj)) (sqrt_nonneg _)⟩ + MatrixFactorPairBounds B Δ (l.eval f R hR j a 1) (m.eval f R hR j b 1) := by + intro B Δ + obtain ⟨hlb,hll⟩ := l.eval_bounds f hR hj hA hD ha haA ⟨zero_le_one,le_rfl⟩ hl + obtain ⟨hmb,hml⟩ := m.eval_bounds f hR hj hA hD hb hbA ⟨zero_le_one,le_rfl⟩ hm + refine ⟨hlb,hmb,hll,hml,?_,?_⟩ + · intro M + cases l <;> cases m <;> try contradiction + · rename_i d e + change opNorm (diagonal d-diagonal e)≤wordHolderScale f R j A*sqrt δ + rw [Matrix.diagonal_sub] + exact (opNorm_diagonal_le hδ hlm).trans ((parameter_sqrt_small hδ hδ1).trans + (by nlinarith [wordHolderScale_ge_one f R A hj,sqrt_nonneg δ])) + · simp [WordLetter.eval,opNorm] + · exact ((pathK_parameter_holder f hR hj hA hδ hδ1 ha hb haA hbA hab M M).1).trans + (by have hh := mul_le_mul_of_nonneg_right (wordHolderScale_constants f R A hj).1 (sqrt_nonneg δ) + simpa only [mul_assoc,Δ,NNReal.coe_mk] using! hh) + · cases l <;> cases m <;> try contradiction + · rename_i d e + exact (LipschitzWith.const (diagonal d-diagonal e)).weaken (show (0:NNReal)≤Δ from zero_le) + · simpa only [WordLetter.eval,sub_self] using (LipschitzWith.const (0:Matrix ι ι ℝ)).weaken (show (0:NNReal)≤Δ from zero_le) + · apply LipschitzWith.of_dist_le_mul + intro M N + change ‖(pathK f R hR j a 1 M-pathK f R hR j b 1 M)- + (pathK f R hR j a 1 N-pathK f R hR j b 1 N)‖≤wordHolderScale f R j A*sqrt δ*‖M-N‖ + have he : (pathK f R hR j a 1 M-pathK f R hR j b 1 M)- + (pathK f R hR j a 1 N-pathK f R hR j b 1 N)= + (pathK f R hR j a 1 M-pathK f R hR j a 1 N)- + (pathK f R hR j b 1 M-pathK f R hR j b 1 N) := by abel + rw [he] + apply ((pathK_parameter_holder f hR hj hA hδ hδ1 ha hb haA hbA hab M N).2).trans + apply mul_le_mul_of_nonneg_right _ (norm_nonneg _) + have hh := mul_le_mul_of_nonneg_right (wordHolderScale_constants f R A hj).2 (sqrt_nonneg δ) + simpa only [mul_assoc,Δ,NNReal.coe_mk] using! hh + +theorem actualWord_pair_increments [Nonempty ι] (f : 𝓢(ℝ,ℂ)) {R j A D δ : ℝ} + (hR : 0≤R) (hj : 0≤j) (hA : 0≤A) (hD : 0≤D) (hδ : 0≤δ) (hδ1 : δ≤1) + {a b : ι→ℝ} (ha : ∀ i,0≤a i) (hb : ∀ i,0≤b i) (haA : ∀ i,a i≤A) (hbA : ∀ i,b i≤A) + (hab : ∀ i,|a i-b i|≤δ) (F : List (WordLetter ι×WordLetter ι)) + (hF : ∀ p∈F,p.1.bounded D ∧ p.2.bounded D ∧ p.1.close δ p.2) : + let B : NNReal := ⟨actualWordBound f R j A D,(actualWordBound_pos f hR hj hA hD).le⟩ + let Δ : NNReal := ⟨wordHolderScale f R j A*sqrt δ,mul_nonneg (zero_le_one.trans (wordHolderScale_ge_one f R A hj)) (sqrt_nonneg _)⟩ + (∀ M,opNorm (actualWord f R hR j a 1 (F.map Prod.fst) M-actualWord f R hR j b 1 (F.map Prod.snd) M)≤ + (wordParameterCoeff B F.length:ℝ)*Δ) ∧ + LipschitzWith (wordMixedCoeff B F.length*Δ) + (fun M=>actualWord f R hR j a 1 (F.map Prod.fst) M-actualWord f R hR j b 1 (F.map Prod.snd) M) := by + intro B Δ + let G := F.map (fun p=>(p.1.eval f R hR j a 1,p.2.eval f R hR j b 1)) + have hG : ∀ p∈G,MatrixFactorPairBounds B Δ p.1 p.2 := by + intro p hp + obtain ⟨q,hq,rfl⟩ := List.mem_map.mp hp + obtain ⟨h1,h2,h3⟩ := hF q hq + exact WordLetter.eval_pair f hR hj hA hD hδ hδ1 ha hb haA hbA hab q.1 q.2 h1 h2 h3 + simpa only [G,List.length_map,List.map_map,Function.comp_def,actualWord] using! matrixWord_pair_increments G hG +end SKGap +end +end + +section +noncomputable section +namespace SKGap +open Matrix Real Set +open scoped BigOperators Matrix.Norms.Frobenius SchwartzMap +variable {ι : Type*} [Fintype ι] [DecidableEq ι] {m : ℕ} + +inductive WordTemplateLetter (m : ℕ) where + | diag : Fin m→WordTemplateLetter m + | noise : WordTemplateLetter m + | inverse : WordTemplateLetter m + deriving DecidableEq, Fintype + +abbrev WordParameter (m : ℕ) (ι : Type*) := (Option (Fin m)×ι)→Icc (0:ℝ) 1 + +def templateInverse (A : ℝ) (θ : WordParameter m ι) (i : ι) : ℝ := A*(θ (none,i):ℝ) +def templateDiagonal (D : ℝ) (θ : WordParameter m ι) (k : Fin m) (i : ι) : ℝ := + D*(2*(θ (some k,i):ℝ)-1) +def WordTemplateLetter.realize (D : ℝ) (θ : WordParameter m ι) : WordTemplateLetter m→WordLetter ι + | .diag k => .diag (templateDiagonal D θ k) + | .noise => .noise + | .inverse => .inverse + +def templateWord (D : ℝ) (θ : WordParameter m ι) (F : List (WordTemplateLetter m)) := + F.map (WordTemplateLetter.realize D θ) + +def templateScale (A D : ℝ) : ℝ := 1+A+2*D + +omit [Fintype ι] [DecidableEq ι] in +lemma templateInverse_bounds {A : ℝ} (hA : 0 ≤ A) (θ : WordParameter m ι) (i : ι) : + 0 ≤ templateInverse A θ i ∧ templateInverse A θ i ≤ A := by + obtain ⟨h0,h1⟩ := (θ (none,i)).property + dsimp [templateInverse] + constructor + · positivity + · nlinarith only [mul_le_mul_of_nonneg_left h1 hA] + +omit [Fintype ι] [DecidableEq ι] in +lemma templateDiagonal_bound {D : ℝ} (hD : 0 ≤ D) (θ : WordParameter m ι) (k : Fin m) (i : ι) : + |templateDiagonal D θ k i| ≤ D := by + obtain ⟨h0,h1⟩ := (θ (some k,i)).property + rw [templateDiagonal,abs_mul,abs_of_nonneg hD] + have hf : |2*(θ (some k,i):ℝ)-1| ≤ 1 := abs_le.mpr ⟨by linarith,by linarith⟩ + simpa only [mul_one] using mul_le_mul_of_nonneg_left hf hD + +omit [Fintype ι] [DecidableEq ι] in +lemma templateWord_bounded {D : ℝ} (hD : 0 ≤ D) (θ : WordParameter m ι) + (F : List (WordTemplateLetter m)) : ∀ l∈templateWord D θ F,l.bounded D := by + intro l hl + obtain ⟨q,hq,rfl⟩ := List.mem_map.mp hl + cases q with + | diag k => exact templateDiagonal_bound hD θ k + | noise => trivial + | inverse => trivial + +omit [DecidableEq ι] in +lemma template_coord_dist (θ η : WordParameter m ι) (s : Option (Fin m)×ι) : + |(θ s:ℝ)-(η s:ℝ)| ≤ dist θ η := by + simpa only [Subtype.dist_eq,Real.dist_eq] using dist_le_pi_dist θ η s + +omit [DecidableEq ι] in +lemma templateInverse_dist {A D : ℝ} (hA : 0 ≤ A) (hD : 0 ≤ D) + (θ η : WordParameter m ι) (i : ι) : + |templateInverse A θ i-templateInverse A η i| ≤ templateScale A D*dist θ η := by + rw [templateInverse,templateInverse,←mul_sub,abs_mul,abs_of_nonneg hA] + apply (mul_le_mul_of_nonneg_left (template_coord_dist θ η (none,i)) hA).trans + apply mul_le_mul_of_nonneg_right _ dist_nonneg + dsimp [templateScale] + linarith + +omit [DecidableEq ι] in +lemma templateLetter_close {A D : ℝ} (hA : 0 ≤ A) (hD : 0 ≤ D) + (θ η : WordParameter m ι) (l : WordTemplateLetter m) : + (l.realize D θ).close (templateScale A D*dist θ η) (l.realize D η) := by + cases l with + | noise => trivial + | inverse => trivial + | diag k => + intro i + change |D*(2*(θ (some k,i):ℝ)-1)-D*(2*(η (some k,i):ℝ)-1)| ≤ _ + have he : D*(2*(θ (some k,i):ℝ)-1)-D*(2*(η (some k,i):ℝ)-1)= + (2*D)*((θ (some k,i):ℝ)-(η (some k,i):ℝ)) := by ring + rw [he,abs_mul,abs_of_nonneg (by positivity : 0 ≤ 2*D)] + apply (mul_le_mul_of_nonneg_left (template_coord_dist θ η (some k,i)) (by positivity : 0 ≤ 2*D)).trans + apply mul_le_mul_of_nonneg_right _ dist_nonneg + dsimp [templateScale] + linarith + +omit [DecidableEq ι] in +lemma templateWord_paired {A D : ℝ} (hA : 0 ≤ A) (hD : 0 ≤ D) + (θ η : WordParameter m ι) (F : List (WordTemplateLetter m)) : + ∀ p∈F.map (fun l=>(l.realize D θ,l.realize D η)), + p.1.bounded D ∧ p.2.bounded D ∧ p.1.close (templateScale A D*dist θ η) p.2 := by + intro p hp + obtain ⟨l,hl,rfl⟩ := List.mem_map.mp hp + exact ⟨templateWord_bounded hD θ F _ (List.mem_map.mpr ⟨l,hl,rfl⟩), + templateWord_bounded hD η F _ (List.mem_map.mpr ⟨l,hl,rfl⟩),templateLetter_close hA hD θ η l⟩ +end SKGap +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Matrix/WordLeading.lean b/lean/OAI/Probability/SKGap/Matrix/WordLeading.lean new file mode 100644 index 0000000000000000000000000000000000000000..bc4ca828e8f161bbf9e750199a20c6e0d968fcba --- /dev/null +++ b/lean/OAI/Probability/SKGap/Matrix/WordLeading.lean @@ -0,0 +1,91 @@ +import Mathlib +import OAI.Probability.SKGap.Matrix.WordBaseBias + +namespace OAI + +section +noncomputable section +namespace SKGap +open Matrix Real MeasureTheory ProbabilityTheory Set +open scoped BigOperators Matrix.Norms.Frobenius SchwartzMap +variable {ι : Type*} [Fintype ι] [DecidableEq ι] + +lemma actualWord_entry_integrable [Nonempty ι] (f : 𝓢(ℝ,ℂ)) {R j A D z r : ℝ} + (hR : 0≤R) (hj : 0≤j) (hA : 0≤A) (hD : 0≤D) {a : ι→ℝ} + (ha : ∀ i,0≤a i) (haA : ∀ i,a i≤A) (hz : z∈Icc (0:ℝ) 1) + (F : List (WordLetter ι)) (hF : ∀ l∈F,l.bounded D) (i b : ι) : + Integrable (fun g : MatrixCoordinates ι→ℝ=>actualWord f R hR j a z F (goeMatrix r g) i b) + (Measure.pi (fun _=>gaussianReal 0 1)) := by + have hw := actualWord_bounds f hR hj hA hD ha haA hz F hF + have hc := hw.2.continuous.comp (goeMatrix_pi_lipschitz (ι:=ι) r).continuous + have he : Continuous (fun g : MatrixCoordinates ι→ℝ=>actualWord f R hR j a z F (goeMatrix r g) i b) := + (continuous_apply b).comp ((continuous_apply i).comp hc) + exact (integrable_const ((actualWordBound f R j A D)^F.length)).mono' he.aestronglyMeasurable + (ae_of_all _ (fun g=>(matrix_entry_le_opNorm _ i b).trans (hw.1 _))) + +def wordAverageExpected (f : 𝓢(ℝ,ℂ)) {R : ℝ} (hR : 0≤R) (j : ℝ) + (a : ι→ℝ) (z : ℝ) (F : List (WordLetter ι)) : ℝ := + (∑ i,wordExpected f hR j a z F i)/(Fintype.card ι:ℝ) + +lemma wordAverageExpected_integral [Nonempty ι] (f : 𝓢(ℝ,ℂ)) {R j A D z : ℝ} + (hR : 0≤R) (hj : 0≤j) (hA : 0≤A) (hD : 0≤D) {a : ι→ℝ} + (ha : ∀ i,0≤a i) (haA : ∀ i,a i≤A) (hz : z∈Icc (0:ℝ) 1) + (F : List (WordLetter ι)) (hF : ∀ l∈F,l.bounded D) : + (∫ g : MatrixCoordinates ι→ℝ,trace (actualWord f R hR j a z F + (goeMatrix (j/(Fintype.card ι:ℝ)) g))/(Fintype.card ι:ℝ) + ∂Measure.pi (fun _=>gaussianReal 0 1))=wordAverageExpected f hR j a z F := by + rw [integral_div] + unfold trace + simp only [Matrix.diag] + rw [integral_finsetSum _ (fun i _=>actualWord_entry_integrable f hR hj hA hD ha haA hz F hF i i)] + rfl + +def wordLeadingCost (j B : ℝ) (u v q : ℕ) : ℝ := + j*(B^u*B^q*((2*exp (π^2/8))*((v:ℝ)*B^v)*sqrt (2*j))+B^u*B^v*B^q) + +theorem actualWord_leading {n : ℕ} (hn : 0gaussianReal 0 1) + |(j/(n:ℝ))*(∫ g,markedContraction + (actualWord f R hR j a z U (goeMatrix (j/n) g)) + (actualWord f R hR j a z V (goeMatrix (j/n) g)) + (actualWord f R hR j a z Q (goeMatrix (j/n) g)) i ∂μ)- + j*wordAverageExpected f hR j a z V*wordExpected f hR j a z (U++Q) i|≤ + wordLeadingCost j (actualWordBound f R j A D) U.length V.length Q.length/(n:ℝ) := by + let : Nonempty (Fin n) := Fin.pos_iff_nonempty.mp hn + dsimp only + let B : NNReal := ⟨actualWordBound f R j A D,(actualWordBound_pos f hR hj.le hA hD).le⟩ + let G := V.map (WordLetter.eval f R hR j a z) + have hGb : ∀ p∈G,∀ M,opNorm (p M)≤B := by + intro p hp + obtain ⟨l,hl,rfl⟩ := List.mem_map.mp hp + exact (l.eval_bounds f hR hj.le hA hD ha haA hz (hV l hl)).1 + have hGl : ∀ p∈G,LipschitzWith B p := by + intro p hp + obtain ⟨l,hl,rfl⟩ := List.mem_map.mp hp + exact (l.eval_bounds f hR hj.le hA hD ha haA hz (hV l hl)).2 + have hu := actualWord_bounds f hR hj.le hA hD ha haA hz U hU + have hq := actualWord_bounds f hR hj.le hA hD ha haA hz Q hQ + have hh := goe_word_leading_contraction hn hj G + (show 0gaussianReal 0 1) := by + simp only [wordExpected,Fintype.card_fin,actualWord_append] + rw [← heq] at hh + simpa only [actualWord,wordLeadingCost,markedContraction] using! hh +end SKGap +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Matrix/WordLoop.lean b/lean/OAI/Probability/SKGap/Matrix/WordLoop.lean new file mode 100644 index 0000000000000000000000000000000000000000..0304764a8a9749df6627fb9c4c0d18d6a05a022f --- /dev/null +++ b/lean/OAI/Probability/SKGap/Matrix/WordLoop.lean @@ -0,0 +1,220 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.Bilinear +import OAI.Probability.SKGap.Matrix.WordPartnerContraction +import OAI.Probability.SKGap.Localization.ProjectedMarkedIBP + +namespace OAI + +section +noncomputable section +namespace SKGap +open Matrix Real MeasureTheory ProbabilityTheory Set +open RealComplex +open scoped BigOperators Matrix.Norms.Frobenius NNReal ENNReal SchwartzMap +variable {ι : Type*} [Fintype ι] [DecidableEq ι] + +def wordDifferentialBound (B : NNReal) (A z : ℝ) (k : ℕ) : ℝ := + (1+|z| *A*(B:ℝ)^2)*(wordParameterCoeff B k:ℝ)*2 + +lemma actualWord_elementary_bound [Nonempty ι] (f : 𝓢(ℝ,ℂ)) {R j A D z : ℝ} + (hR : 0≤R) (hj : 0≤j) (hA : 0≤A) (hD : 0≤D) {a : ι→ℝ} + (ha : ∀ i,0≤a i) (haA : ∀ i,a i≤A) (hz : z∈Icc (0:ℝ) 1) + (F : List (WordLetter ι)) (hF : ∀ l∈F,l.bounded D) (M : Matrix ι ι ℝ) (u v : ι) : + opNorm (actualWordDirection f R hR j a z M (symmetricElementary u v) F)≤ + wordDifferentialBound ⟨actualWordBound f R j A D,(actualWordBound_pos f hR hj hA hD).le⟩ A z F.length := by + apply (actualWordDirection_bound f hR hj hA hD ha haA hz F hF M (symmetricElementary u v)).trans + apply mul_le_mul_of_nonneg_left ((operator_le_frobenius _).trans (symmetricElementary_norm_le u v)) + positivity + +def actualWordLoop (f : 𝓢(ℝ,ℂ)) {R : ℝ} (hR : 0≤R) (j : ℝ) (a : ι→ℝ) (z : ℝ) + (P Q : List (WordLetter ι)) (M : Matrix ι ι ℝ) (i : ι) : ℝ := + ((wordPartners a P).map (WordCut.leftContraction f hR j a z M (actualWord f R hR j a z Q M) i)).sum+ + ((wordPartners a Q).map (WordCut.rightContraction f hR j a z M (actualWord f R hR j a z P M) i)).sum + +theorem actualWord_loop [Nonempty ι] (f : 𝓢(ℝ,ℂ)) {lo hi : ℝ} (hlo : 0gaussianReal 0 1) + let s := truncationGoodSet r R lo hi (pathDiagonal a z) (pathShift z ((j/(Fintype.card ι:ℝ))*∑ k,a k)) + |(∫ g,actualWord f R hR j a z (P++(.noise::Q)) (goeMatrix r g) i i ∂μ)- + r*(∫ g,actualWordLoop f hR j a z P Q (goeMatrix r g) i ∂μ)|≤ + markedError (ι:=ι) r R ((P.length:NNReal)*B^P.length) ((Q.length:NNReal)*B^Q.length) + (B^P.length) (B^Q.length) (wordDifferentialBound B A z P.length) + (wordDifferentialBound B A z Q.length) (μ.real sᶜ) := by + intro B μ s + let U := actualWord f R hR j a z P + let V := actualWord f R hR j a z Q + let DU := fun u v M=>actualWordDirection f R hR j a z M (symmetricElementary u v) P + let DV := fun u v M=>actualWordDirection f R hR j a z M (symmetricElementary u v) Q + have hu := actualWord_bounds f hR hj hA hD ha haA hz P hP + have hv := actualWord_bounds f hR hj hA hD ha haA hz Q hQ + have hu' : ∀ M,opNorm (U M)≤(B^P.length:NNReal) := by simpa only [B,NNReal.coe_pow,NNReal.coe_mk] using! hu.1 + have hv' : ∀ M,opNorm (V M)≤(B^Q.length:NNReal) := by simpa only [B,NNReal.coe_pow,NNReal.coe_mk] using! hv.1 + have hdu (u v : ι) : Continuous (DU u v) := actualWordDirection_continuous f hR hj hA hD ha haA hz P hP _ + have hdv (u v : ι) : Continuous (DV u v) := actualWordDirection_continuous f hR hj hA hD ha haA hz Q hQ _ + have hdub (u v : ι) (M : Matrix ι ι ℝ) : opNorm (DU u v M)≤wordDifferentialBound B A z P.length := + actualWord_elementary_bound f hR hj hA hD ha haA hz P hP M u v + have hdvb (u v : ι) (M : Matrix ι ι ℝ) : opNorm (DV u v M)≤wordDifferentialBound B A z Q.length := + actualWord_elementary_bound f hR hj hA hD ha haA hz Q hQ M u v + have hpd (F : List (WordLetter ι)) (u v : ι) (g : MatrixCoordinates ι→ℝ) (hg : g∈s) : + HasDerivAt (fun t : ℝ=>actualWord f R hR j a z F (goeMatrix r g+t • symmetricElementary u v)) + (actualWordDirection f R hR j a z (goeMatrix r g) (symmetricElementary u v) F) 0 := + actualWord_hasDerivAt f hlo hf hR j ha hz.1 _ _ (goeMatrix_transpose _ _) (symmetricElementary_transpose _ _) + hg.1 hg.2.1 hg.2.2 F + have hh := projected_marked_product_IBP hr hR U V DU DV hu.2 hv.2 hu' hv' hdu hdv hdub hdvb + (truncationGoodSet_measurable r R lo hi _ _) (fun g (hg : g∈s)=>hg.1.le) (hpd P) (hpd Q) i + simpa only [U,V,DU,DV,actualWord_append,actualWord_cons,WordLetter.eval,mul_assoc, + actualWord_partner_contractions,actualWordLoop] using! hh +end SKGap +end +end + +section +noncomputable section +namespace SKGap +variable {ι : Type*} + +lemma wordPartners_lengths (a : ι→ℝ) (F : List (WordLetter ι)) (c : WordCut ι) + (hc : c∈wordPartners a F) : + c.left.length+c.right.length+(if c.inversePartner then 0 else 1)= + F.length+(if c.inversePartner then 2 else 0) := by + induction F generalizing c with + | nil => simp [wordPartners] at hc + | cons l F ih => + rw [wordPartners_cons,List.mem_append] at hc + rcases hc with hc|hc + · cases l with + | diag d => simp at hc + | noise => simp only [List.mem_singleton] at hc;subst c;simp + | inverse => simp only [List.mem_singleton] at hc;subst c;simp;omega + · obtain ⟨d,hd,rfl⟩ := List.mem_map.mp hc + have hh := ih d hd + simp only [WordCut.prepend,List.length_cons] at * + by_cases hi : d.inversePartner=true <;> simp [hi] at hh ⊢ <;> omega + +lemma wordPartners_preserves_bound {a : ι→ℝ} {D : ℝ} (ha : ∀ i,|a i|≤D) + (F : List (WordLetter ι)) (hF : ∀ l∈F,l.bounded D) (c : WordCut ι) + (hc : c∈wordPartners a F) : + (∀ l∈c.left,l.bounded D) ∧ (∀ l∈c.right,l.bounded D) := by + induction F generalizing c with + | nil => simp [wordPartners] at hc + | cons l F ih => + have hFt : ∀ l∈F,l.bounded D := fun m hm=>hF m (List.mem_cons_of_mem _ hm) + rw [wordPartners_cons,List.mem_append] at hc + rcases hc with hc|hc + · cases l with + | diag d => simp at hc + | noise => + simp only [List.mem_singleton] at hc;subst c + simpa using hFt + | inverse => + simp only [List.mem_singleton] at hc;subst c + constructor + · intro m hm + simp only [List.mem_cons,List.not_mem_nil,or_false] at hm + rcases hm with rfl|rfl + · trivial + · exact ha + · intro m hm + rcases List.mem_cons.mp hm with rfl|hm + · trivial + · exact hFt m hm + · obtain ⟨d,hd,rfl⟩ := List.mem_map.mp hc + have hh := ih hFt d hd + constructor + · intro m hm + rcases List.mem_cons.mp hm with rfl|hm + · exact hF m List.mem_cons_self + · exact hh.1 m hm + · exact hh.2 + +lemma wordPartners_card_bound (a : ι→ℝ) (F : List (WordLetter ι)) : + (wordPartners a F).length≤F.length := by + induction F with + | nil => simp [wordPartners] + | cons l F ih => cases l <;> simp [wordPartners] <;> omega + +lemma wordRecursionAt_lengths (a : ι→ℝ) (P Q : List (WordLetter ι)) + (t : WordRecursionTerm ι) (ht : t∈wordRecursionAt a P Q) : + t.outer.length≤(P++(.noise::Q)).length ∧ t.inner.length≤(P++(.noise::Q)).length := by + dsimp only [wordRecursionAt] at ht + rw [List.mem_append] at ht + rcases ht with ht|ht + · obtain ⟨c,hc,rfl⟩ := List.mem_map.mp ht + have hh := wordPartners_lengths a P c hc + cases hi : c.inversePartner + · simp [WordCut.asLeft,hi] at *;omega + · have hs := wordPartners_inverse_sides a P c hc hi + have hL : inverseCount c.left≤c.left.length := List.countP_le_length + have hR : inverseCount c.right≤c.right.length := List.countP_le_length + simp [WordCut.asLeft,hi] at *;omega + · obtain ⟨c,hc,rfl⟩ := List.mem_map.mp ht + have hh := wordPartners_lengths a Q c hc + cases hi : c.inversePartner + · simp [WordCut.asRight,hi] at *;omega + · have hs := wordPartners_inverse_sides a Q c hc hi + have hL : inverseCount c.left≤c.left.length := List.countP_le_length + have hR : inverseCount c.right≤c.right.length := List.countP_le_length + simp [WordCut.asRight,hi] at *;omega + +lemma wordRecursionAt_bounds {a : ι→ℝ} {D : ℝ} (ha : ∀ i,|a i|≤D) + (P Q : List (WordLetter ι)) (hP : ∀ l∈P,l.bounded D) (hQ : ∀ l∈Q,l.bounded D) + (t : WordRecursionTerm ι) (ht : t∈wordRecursionAt a P Q) : + (∀ l∈t.outer,l.bounded D) ∧ (∀ l∈t.inner,l.bounded D) := by + dsimp only [wordRecursionAt] at ht + rw [List.mem_append] at ht + rcases ht with ht|ht + · obtain ⟨c,hc,rfl⟩ := List.mem_map.mp ht + have hh := wordPartners_preserves_bound ha P hP c hc + exact ⟨fun l hl=>(List.mem_append.mp hl).elim (hh.1 l) (hQ l),hh.2⟩ + · obtain ⟨c,hc,rfl⟩ := List.mem_map.mp ht + have hh := wordPartners_preserves_bound ha Q hQ c hc + exact ⟨fun l hl=>(List.mem_append.mp hl).elim (hP l) (hh.2 l),hh.1⟩ + +lemma wordRecursionTerms_lengths (a : ι→ℝ) (F : List (WordLetter ι)) + (t : WordRecursionTerm ι) (ht : t∈wordRecursionTerms a F) : + t.outer.length≤F.length ∧ t.inner.length≤F.length := by + unfold wordRecursionTerms at ht + cases hs : firstNoiseSplit F with + | none => simp [hs] at ht + | some pq => + rcases pq with ⟨P,Q⟩ + have he := firstNoiseSplit_some F P Q hs + simp only [hs] at ht + simpa only [he] using wordRecursionAt_lengths a P Q t ht + +lemma wordRecursionTerms_bounds {a : ι→ℝ} {D : ℝ} (ha : ∀ i,|a i|≤D) + (F : List (WordLetter ι)) (hF : ∀ l∈F,l.bounded D) + (t : WordRecursionTerm ι) (ht : t∈wordRecursionTerms a F) : + (∀ l∈t.outer,l.bounded D) ∧ (∀ l∈t.inner,l.bounded D) := by + unfold wordRecursionTerms at ht + cases hs : firstNoiseSplit F with + | none => simp [hs] at ht + | some pq => + rcases pq with ⟨P,Q⟩ + have he := firstNoiseSplit_some F P Q hs + simp only [hs] at ht + have hP : ∀ l∈P,l.bounded D := fun l hl=>hF l (by rw [he];exact List.mem_append_left _ hl) + have hQ : ∀ l∈Q,l.bounded D := fun l hl=>hF l (by rw [he];exact List.mem_append_right _ (List.mem_cons_of_mem _ hl)) + exact wordRecursionAt_bounds ha P Q hP hQ t ht + +lemma wordRecursionTerms_card_bound (a : ι→ℝ) (F : List (WordLetter ι)) : + (wordRecursionTerms a F).length≤F.length := by + unfold wordRecursionTerms + cases hs : firstNoiseSplit F with + | none => simp + | some pq => + rcases pq with ⟨P,Q⟩ + have he := firstNoiseSplit_some F P Q hs + simp only [wordRecursionAt,List.length_append,List.length_map,he,List.length_cons] + have h1 := wordPartners_card_bound a P + have h2 := wordPartners_card_bound a Q + omega +end SKGap +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Matrix/WordLoopLeading.lean b/lean/OAI/Probability/SKGap/Matrix/WordLoopLeading.lean new file mode 100644 index 0000000000000000000000000000000000000000..295d6daa7dde00a345a517b58676cb81badc0336 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Matrix/WordLoopLeading.lean @@ -0,0 +1,204 @@ +import Mathlib +import OAI.Probability.SKGap.Matrix.WordLeading +import OAI.Probability.SKGap.Matrix.WordLoop + +namespace OAI + +section +noncomputable section +namespace SKGap +open Matrix Real MeasureTheory ProbabilityTheory Set +open scoped BigOperators Matrix.Norms.Frobenius SchwartzMap +variable {ι : Type*} [Fintype ι] [DecidableEq ι] + +lemma actualWord_marked_integrable [Nonempty ι] (f : 𝓢(ℝ,ℂ)) {R j A D z r : ℝ} + (hR : 0≤R) (hj : 0≤j) (hA : 0≤A) (hD : 0≤D) {a : ι→ℝ} + (ha : ∀ i,0≤a i) (haA : ∀ i,a i≤A) (hz : z∈Icc (0:ℝ) 1) + (U V Q : List (WordLetter ι)) (hU : ∀ l∈U,l.bounded D) + (hV : ∀ l∈V,l.bounded D) (hQ : ∀ l∈Q,l.bounded D) (i : ι) : + Integrable (fun g : MatrixCoordinates ι→ℝ=>markedContraction + (actualWord f R hR j a z U (goeMatrix r g)) + (actualWord f R hR j a z V (goeMatrix r g)) + (actualWord f R hR j a z Q (goeMatrix r g)) i) + (Measure.pi (fun _=>gaussianReal 0 1)) := by + let B := actualWordBound f R j A D + have hB : 0≤B := (actualWordBound_pos f hR hj hA hD).le + have hb (F : List (WordLetter ι)) (hF : ∀ l∈F,l.bounded D) := + actualWord_bounds f hR hj hA hD ha haA hz F hF + have hc (F : List (WordLetter ι)) (hF : ∀ l∈F,l.bounded D) := + (hb F hF).2.continuous.comp (goeMatrix_pi_lipschitz (ι:=ι) r).continuous + have he : Continuous (fun g : MatrixCoordinates ι→ℝ=>markedContraction + (actualWord f R hR j a z U (goeMatrix r g)) + (actualWord f R hR j a z V (goeMatrix r g)) + (actualWord f R hR j a z Q (goeMatrix r g)) i) := by + have huc := hc U hU + have hvc := hc V hV + have hqc := hc Q hQ + unfold markedContraction Matrix.trace + fun_prop + apply (integrable_const ((Fintype.card ι:ℝ)*B^U.length*B^V.length*B^Q.length+ + B^U.length*B^V.length*B^Q.length)).mono' he.aestronglyMeasurable + filter_upwards [] with g + let u := actualWord f R hR j a z U (goeMatrix r g) + let v := actualWord f R hR j a z V (goeMatrix r g) + let q := actualWord f R hR j a z Q (goeMatrix r g) + have hu : opNorm u≤B^U.length := (hb U hU).1 _ + have hv : opNorm v≤B^V.length := (hb V hV).1 _ + have hq : opNorm q≤B^Q.length := (hb Q hQ).1 _ + have ht : |trace v|≤(Fintype.card ι:ℝ)*B^V.length := by + apply (Finset.abs_sum_le_sum_abs _ _).trans + apply (Finset.sum_le_sum (fun k _=>(matrix_entry_le_opNorm v k k).trans hv)).trans_eq + simp + have huq : |(u*q) i i|≤B^U.length*B^Q.length := + (matrix_entry_le_opNorm _ i i).trans ((opNorm_mul _ _).trans + (mul_le_mul hu hq (norm_nonneg _) (pow_nonneg hB _))) + have hzq : |(u*vᵀ*q) i i|≤B^U.length*B^V.length*B^Q.length := + (matrix_word_reverse_bound u v q i).trans + (mul_le_mul (mul_le_mul hu hv (norm_nonneg _) (pow_nonneg hB _)) hq + (norm_nonneg _) (by positivity)) + change |(u*q) i i*trace v+(u*vᵀ*q) i i|≤_ + apply (abs_add_le _ _).trans + rw [abs_mul] + apply (add_le_add (mul_le_mul huq ht (abs_nonneg _) (by positivity)) hzq).trans_eq + ring + +omit [Fintype ι] [DecidableEq ι] in +lemma integrable_list_map_sum {Ω : Type*} [MeasurableSpace Ω] (μ : Measure Ω) + (C : List ι) (F : ι→Ω→ℝ) (hF : ∀ c∈C,Integrable (F c) μ) : + Integrable (fun x=>(C.map (fun c=>F c x)).sum) μ := by + induction C with + | nil => simp + | cons c C ih => + simpa only [List.map_cons,List.sum_cons,Pi.add_apply] using! + (hF c List.mem_cons_self).add (ih (fun c hc=>hF c (List.mem_cons_of_mem _ hc))) + +omit [Fintype ι] [DecidableEq ι] in +lemma integral_list_sum_bound {Ω : Type*} [MeasurableSpace Ω] (μ : Measure Ω) + (r : ℝ) (C : List ι) (F : ι→Ω→ℝ) (p e : ι→ℝ) + (hF : ∀ c∈C,Integrable (F c) μ) + (hb : ∀ c∈C,|r*(∫ x,F c x ∂μ)-p c|≤e c) : + |r*(∫ x,(C.map (fun c=>F c x)).sum ∂μ)-(C.map p).sum|≤(C.map e).sum := by + induction C with + | nil => simp + | cons c C ih => + have hFi := integrable_list_map_sum μ C F (fun c hc=>hF c (List.mem_cons_of_mem _ hc)) + simp only [List.map_cons,List.sum_cons] + rw [integral_add (hF c List.mem_cons_self) hFi,mul_add] + have ht := ih (fun c hc=>hF c (List.mem_cons_of_mem _ hc)) + (fun c hc=>hb c (List.mem_cons_of_mem _ hc)) + calc + |r*(∫ x,F c x ∂μ)+r*(∫ x,(C.map (fun c=>F c x)).sum ∂μ)-(p c+(C.map p).sum)| = + |(r*(∫ x,F c x ∂μ)-p c)+(r*(∫ x,(C.map (fun c=>F c x)).sum ∂μ)-(C.map p).sum)| := by + congr 1 + ring + _ ≤ _ := (abs_add_le _ _).trans (add_le_add (hb c List.mem_cons_self) ht) + +def wordExpectedRecursion (f : 𝓢(ℝ,ℂ)) {R : ℝ} (hR : 0≤R) (j : ℝ) + (a : ι→ℝ) (z : ℝ) (F : List (WordLetter ι)) (i : ι) : ℝ := + ((wordRecursionTerms a F).map (fun t=>(if t.inversePartner then z else 1)*j* + wordAverageExpected f hR j a z t.inner*wordExpected f hR j a z t.outer i)).sum + +omit [Fintype ι] [DecidableEq ι] in +lemma weighted_integral_error {Ω : Type*} [MeasurableSpace Ω] (μ : Measure Ω) + (F : Ω→ℝ) (c r p e : ℝ) (h : |r*(∫ x,F x ∂μ)-p|≤e) : + |r*(∫ x,c*F x ∂μ)-c*p|≤|c| *e := by + rw [integral_const_mul] + have he : r*(c*(∫ x,F x ∂μ))-c*p=c*(r*(∫ x,F x ∂μ)-p) := by ring + rw [he,abs_mul] + exact mul_le_mul_of_nonneg_left h (abs_nonneg c) + +def wordRecursionAtExpected (f : 𝓢(ℝ,ℂ)) {R : ℝ} (hR : 0≤R) (j : ℝ) + (a : ι→ℝ) (z : ℝ) (P Q : List (WordLetter ι)) (i : ι) : ℝ := + ((wordRecursionAt a P Q).map (fun t=>(if t.inversePartner then z else 1)*j* + wordAverageExpected f hR j a z t.inner*wordExpected f hR j a z t.outer i)).sum + +def wordRecursionAtCost (j B z : ℝ) (a : ι→ℝ) (P Q : List (WordLetter ι)) : ℝ := + ((wordPartners a P).map (fun c=>|if c.inversePartner then z else 1| * + wordLeadingCost j B c.left.length c.right.length Q.length)).sum+ + ((wordPartners a Q).map (fun c=>|if c.inversePartner then z else 1| * + wordLeadingCost j B P.length c.left.length c.right.length)).sum + +theorem actualWord_loop_leading {n : ℕ} (hn : 0gaussianReal 0 1) + |(j/(n:ℝ))*(∫ g,actualWordLoop f hR j a z P Q (goeMatrix (j/n) g) i ∂μ)- + wordRecursionAtExpected f hR j a z P Q i|≤ + wordRecursionAtCost j (actualWordBound f R j A D) z a P Q/(n:ℝ) := by + let : Nonempty (Fin n) := Fin.pos_iff_nonempty.mp hn + intro μ + let B := actualWordBound f R j A D + let L := fun (c : WordCut (Fin n)) (g : MatrixCoordinates (Fin n)→ℝ)=> + c.leftContraction f hR j a z (goeMatrix (j/n) g) + (actualWord f R hR j a z Q (goeMatrix (j/n) g)) i + let Rf := fun (c : WordCut (Fin n)) (g : MatrixCoordinates (Fin n)→ℝ)=> + c.rightContraction f hR j a z (goeMatrix (j/n) g) + (actualWord f R hR j a z P (goeMatrix (j/n) g)) i + let pL := fun c : WordCut (Fin n)=>(if c.inversePartner then z else 1)*j* + wordAverageExpected f hR j a z c.right*wordExpected f hR j a z (c.left++Q) i + let pR := fun c : WordCut (Fin n)=>(if c.inversePartner then z else 1)*j* + wordAverageExpected f hR j a z c.left*wordExpected f hR j a z (P++c.right) i + let eL := fun c : WordCut (Fin n)=>|if c.inversePartner then z else 1| * + wordLeadingCost j B c.left.length c.right.length Q.length/(n:ℝ) + let eR := fun c : WordCut (Fin n)=>|if c.inversePartner then z else 1| * + wordLeadingCost j B P.length c.left.length c.right.length/(n:ℝ) + have hLb (c : WordCut (Fin n)) (hc : c∈wordPartners a P) := wordPartners_preserves_bound haD P hP c hc + have hRb (c : WordCut (Fin n)) (hc : c∈wordPartners a Q) := wordPartners_preserves_bound haD Q hQ c hc + have hLi : ∀ c∈wordPartners a P,Integrable (L c) μ := by + intro c hc + exact (actualWord_marked_integrable f hR hj.le hA hD ha haA hz c.left c.right Q + (hLb c hc).1 (hLb c hc).2 hQ i).const_mul _ + have hRi : ∀ c∈wordPartners a Q,Integrable (Rf c) μ := by + intro c hc + exact (actualWord_marked_integrable f hR hj.le hA hD ha haA hz P c.left c.right + hP (hRb c hc).1 (hRb c hc).2 i).const_mul _ + have hLe : ∀ c∈wordPartners a P,|(j/(n:ℝ))*(∫ g,L c g ∂μ)-pL c|≤eL c := by + intro c hc + have hh := weighted_integral_error μ _ (if c.inversePartner then z else 1) _ _ _ + (actualWord_leading hn f hR hj hA hD ha haA hz c.left c.right Q + (hLb c hc).1 (hLb c hc).2 hQ i) + simpa only [L,pL,eL,WordCut.leftContraction,mul_assoc,mul_div_assoc,B] using hh + have hRe : ∀ c∈wordPartners a Q,|(j/(n:ℝ))*(∫ g,Rf c g ∂μ)-pR c|≤eR c := by + intro c hc + have hh := weighted_integral_error μ _ (if c.inversePartner then z else 1) _ _ _ + (actualWord_leading hn f hR hj hA hD ha haA hz P c.left c.right + hP (hRb c hc).1 (hRb c hc).2 i) + simpa only [Rf,pR,eR,WordCut.rightContraction,mul_assoc,mul_div_assoc,B] using hh + have hL := integral_list_sum_bound μ (j/(n:ℝ)) (wordPartners a P) L pL eL hLi hLe + have hR' := integral_list_sum_bound μ (j/(n:ℝ)) (wordPartners a Q) Rf pR eR hRi hRe + have hI1 := integrable_list_map_sum μ (wordPartners a P) L hLi + have hI2 := integrable_list_map_sum μ (wordPartners a Q) Rf hRi + have heI : (∫ g,actualWordLoop f hR j a z P Q (goeMatrix (j/n) g) i ∂μ)= + (∫ g,((wordPartners a P).map (fun c=>L c g)).sum ∂μ)+ + (∫ g,((wordPartners a Q).map (fun c=>Rf c g)).sum ∂μ) := + integral_add hI1 hI2 + have heP : wordRecursionAtExpected f hR j a z P Q i= + ((wordPartners a P).map pL).sum+((wordPartners a Q).map pR).sum := by + simp [wordRecursionAtExpected,wordRecursionAt,List.map_map,Function.comp_def,WordCut.asLeft,WordCut.asRight,pL,pR] + rfl + have heE : ((wordPartners a P).map eL).sum+((wordPartners a Q).map eR).sum= + wordRecursionAtCost j B z a P Q/(n:ℝ) := by + simp only [eL,eR,wordRecursionAtCost,add_div] + congr 1 <;> induction wordPartners a _ with + | nil => simp + | cons c C ih => simp only [List.map_cons,List.sum_cons,add_div,ih] + rw [heI,heP] + have hsum := (abs_add_le ((j/(n:ℝ))*(∫ g,((wordPartners a P).map (fun c=>L c g)).sum ∂μ)-((wordPartners a P).map pL).sum) + ((j/(n:ℝ))*(∫ g,((wordPartners a Q).map (fun c=>Rf c g)).sum ∂μ)-((wordPartners a Q).map pR).sum)).trans + (add_le_add hL hR') + rw [heE] at hsum + have he : (j/(n:ℝ))*((∫ g,((wordPartners a P).map (fun c=>L c g)).sum ∂μ)+ + (∫ g,((wordPartners a Q).map (fun c=>Rf c g)).sum ∂μ))- + (((wordPartners a P).map pL).sum+((wordPartners a Q).map pR).sum)= + ((j/(n:ℝ))*(∫ g,((wordPartners a P).map (fun c=>L c g)).sum ∂μ)-((wordPartners a P).map pL).sum)+ + ((j/(n:ℝ))*(∫ g,((wordPartners a Q).map (fun c=>Rf c g)).sum ∂μ)-((wordPartners a Q).map pR).sum) := by ring + rw [he] + exact hsum + +end SKGap +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Matrix/WordPartnerContraction.lean b/lean/OAI/Probability/SKGap/Matrix/WordPartnerContraction.lean new file mode 100644 index 0000000000000000000000000000000000000000..3c9671a6e6acc5de41c2edafff8da4996d997f2f --- /dev/null +++ b/lean/OAI/Probability/SKGap/Matrix/WordPartnerContraction.lean @@ -0,0 +1,262 @@ +import Mathlib +import OAI.Probability.SKGap.Matrix.MarkedWordIBP + +namespace OAI + +section +noncomputable section +namespace SKGap +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius SchwartzMap +variable {ι : Type*} [Fintype ι] [DecidableEq ι] + +lemma matrix_word_contraction_left (U V Q : Matrix ι ι ℝ) (i : ι) : + (∑ a,∑ b,(U*symmetricElementary a b*V) i a*Q b i)= + (U*Q) i i*trace V+(U*Vᵀ*Q) i i := by + simp_rw [mul_symmetricElementary_mul,add_mul] + simp only [Finset.sum_add_distrib] + have h1 : (∑ a,∑ b,(U i a*V b a)*Q b i)=(U*Vᵀ*Q) i i := by + simp only [Matrix.mul_apply,transpose_apply,Finset.sum_mul] + rw [Finset.sum_comm] + have h2 : (∑ a,∑ b,(U i b*V a a)*Q b i)=(U*Q) i i*trace V := by + simp only [Matrix.mul_apply,Matrix.trace,Finset.sum_mul,Finset.mul_sum] + apply Finset.sum_congr rfl + intro a _;apply Finset.sum_congr rfl + intro b _;dsimp only [Matrix.diag];ring + rw [h1,h2,add_comm] + +def markedContraction (U V Q : Matrix ι ι ℝ) (i : ι) : ℝ := + (U*Q) i i*trace V+(U*Vᵀ*Q) i i + +def WordCut.leftContraction (f : 𝓢(ℝ,ℂ)) {R : ℝ} (hR : 0≤R) (j : ℝ) (a : ι→ℝ) (z : ℝ) + (M Q : Matrix ι ι ℝ) (i : ι) (c : WordCut ι) : ℝ := + (if c.inversePartner then z else 1)*markedContraction + (actualWord f R hR j a z c.left M) (actualWord f R hR j a z c.right M) Q i + +def WordCut.rightContraction (f : 𝓢(ℝ,ℂ)) {R : ℝ} (hR : 0≤R) (j : ℝ) (a : ι→ℝ) (z : ℝ) + (M U : Matrix ι ι ℝ) (i : ι) (c : WordCut ι) : ℝ := + (if c.inversePartner then z else 1)*markedContraction U + (actualWord f R hR j a z c.left M) (actualWord f R hR j a z c.right M) i + +lemma WordCut.leftContraction_eq (f : 𝓢(ℝ,ℂ)) {R : ℝ} (hR : 0≤R) (j : ℝ) (a : ι→ℝ) (z : ℝ) + (M Q : Matrix ι ι ℝ) (i : ι) (c : WordCut ι) : + (∑ u,∑ v,(c.value f hR j a z M (symmetricElementary u v)) i u*Q v i)= + c.leftContraction f hR j a z M Q i := by + have hh : (∑ u,∑ v,(c.value f hR j a z M (symmetricElementary u v)) i u*Q v i)= + (if c.inversePartner then z else 1)*(∑ u,∑ v, + (actualWord f R hR j a z c.left M*symmetricElementary u v* + actualWord f R hR j a z c.right M) i u*Q v i) := by + simp only [WordCut.value,Matrix.smul_apply,smul_eq_mul,Finset.mul_sum] + apply Finset.sum_congr rfl + intro u _;apply Finset.sum_congr rfl + intro v _;ring + rw [hh,matrix_word_contraction_left] + rfl + +lemma WordCut.rightContraction_eq (f : 𝓢(ℝ,ℂ)) {R : ℝ} (hR : 0≤R) (j : ℝ) (a : ι→ℝ) (z : ℝ) + (M U : Matrix ι ι ℝ) (i : ι) (c : WordCut ι) : + (∑ u,∑ v,U i u*(c.value f hR j a z M (symmetricElementary u v)) v i)= + c.rightContraction f hR j a z M U i := by + have hh : (∑ u,∑ v,U i u*(c.value f hR j a z M (symmetricElementary u v)) v i)= + (if c.inversePartner then z else 1)*(∑ u,∑ v, + U i u*(actualWord f R hR j a z c.left M*symmetricElementary u v* + actualWord f R hR j a z c.right M) v i) := by + simp only [WordCut.value,Matrix.smul_apply,smul_eq_mul,Finset.mul_sum] + apply Finset.sum_congr rfl + intro u _;apply Finset.sum_congr rfl + intro v _;ring + rw [hh,matrix_word_contraction] + rfl + +lemma partnerList_leftContract (f : 𝓢(ℝ,ℂ)) {R : ℝ} (hR : 0≤R) (j : ℝ) (a : ι→ℝ) (z : ℝ) + (M Q : Matrix ι ι ℝ) (i : ι) (C : List (WordCut ι)) : + (∑ u,∑ v,((C.map (WordCut.value f hR j a z M (symmetricElementary u v))).sum) i u*Q v i)= + (C.map (WordCut.leftContraction f hR j a z M Q i)).sum := by + induction C with + | nil => simp + | cons c C ih => + simp only [List.map_cons,List.sum_cons,Matrix.add_apply,add_mul,Finset.sum_add_distrib] + rw [WordCut.leftContraction_eq,ih] + +lemma partnerList_rightContract (f : 𝓢(ℝ,ℂ)) {R : ℝ} (hR : 0≤R) (j : ℝ) (a : ι→ℝ) (z : ℝ) + (M U : Matrix ι ι ℝ) (i : ι) (C : List (WordCut ι)) : + (∑ u,∑ v,U i u*((C.map (WordCut.value f hR j a z M (symmetricElementary u v))).sum) v i)= + (C.map (WordCut.rightContraction f hR j a z M U i)).sum := by + induction C with + | nil => simp + | cons c C ih => + simp only [List.map_cons,List.sum_cons,Matrix.add_apply,mul_add,Finset.sum_add_distrib] + rw [WordCut.rightContraction_eq,ih] + +theorem actualWord_partner_contractions (f : 𝓢(ℝ,ℂ)) {R : ℝ} (hR : 0≤R) (j : ℝ) + (a : ι→ℝ) (z : ℝ) (M : Matrix ι ι ℝ) (P Q : List (WordLetter ι)) (i : ι) : + (∑ u,∑ v,((actualWordDirection f R hR j a z M (symmetricElementary u v) P) i u* + actualWord f R hR j a z Q M v i+actualWord f R hR j a z P M i u* + (actualWordDirection f R hR j a z M (symmetricElementary u v) Q) v i))= + ((wordPartners a P).map (WordCut.leftContraction f hR j a z M (actualWord f R hR j a z Q M) i)).sum+ + ((wordPartners a Q).map (WordCut.rightContraction f hR j a z M (actualWord f R hR j a z P M) i)).sum := by + simp only [Finset.sum_add_distrib,actualWordDirection_partners,partnerList_leftContract,partnerList_rightContract] +end SKGap +end +end + +section +noncomputable section +namespace SKGap +open scoped BigOperators +variable {ι : Type*} + +@[simp] lemma ordinaryCount_append (P Q : List (WordLetter ι)) : + ordinaryCount (P++Q)=ordinaryCount P+ordinaryCount Q := by simp [ordinaryCount] +@[simp] lemma inverseCount_append (P Q : List (WordLetter ι)) : + inverseCount (P++Q)=inverseCount P+inverseCount Q := by simp [inverseCount] +@[simp] lemma ordinaryCount_noise (Q : List (WordLetter ι)) : + ordinaryCount (.noise::Q)=ordinaryCount Q+1 := by simp [ordinaryCount] +@[simp] lemma inverseCount_noise (Q : List (WordLetter ι)) : + inverseCount (.noise::Q)=inverseCount Q := by simp [inverseCount] + +lemma wordPartners_inverse_sides (a : ι→ℝ) (F : List (WordLetter ι)) (c : WordCut ι) + (hc : c∈wordPartners a F) (hi : c.inversePartner=true) : + 1≤ inverseCount c.left ∧ 1≤ inverseCount c.right := by + induction F generalizing c with + | nil => simp [wordPartners] at hc + | cons l F ih => + rw [wordPartners_cons,List.mem_append] at hc + rcases hc with hc|hc + · cases l with + | diag d => simp at hc + | noise => simp only [List.mem_singleton] at hc;subst c;contradiction + | inverse => + simp only [List.mem_singleton] at hc + subst c + simp [inverseCount] + · obtain ⟨d,hd,rfl⟩ := List.mem_map.mp hc + have hh := ih d hd hi + cases l <;> simp [WordCut.prepend,inverseCount] at * <;> tauto + +structure WordRecursionTerm (ι : Type*) where + outer : List (WordLetter ι) + inner : List (WordLetter ι) + inversePartner : Bool + +def WordCut.asLeft (Q : List (WordLetter ι)) (c : WordCut ι) : WordRecursionTerm ι := + ⟨c.left++Q,c.right,c.inversePartner⟩ +def WordCut.asRight (P : List (WordLetter ι)) (c : WordCut ι) : WordRecursionTerm ι := + ⟨P++c.right,c.left,c.inversePartner⟩ +def wordRecursionAt (a : ι→ℝ) (P Q : List (WordLetter ι)) : List (WordRecursionTerm ι) := + ((wordPartners a P).map (WordCut.asLeft Q))++((wordPartners a Q).map (WordCut.asRight P)) + +lemma wordRecursionAt_decreases (a : ι→ℝ) (P Q : List (WordLetter ι)) + (t : WordRecursionTerm ι) (ht : t∈wordRecursionAt a P Q) : + ordinaryCount t.outer simp [WordCut.asLeft,hi] at * <;> omega + · obtain ⟨c,hc,rfl⟩ := List.mem_map.mp ht + have hh := (wordPartners_counts a Q c hc).1 + cases hi : c.inversePartner <;> simp [WordCut.asRight,hi] at * <;> omega + +lemma wordRecursionAt_one_inverse (a : ι→ℝ) (P Q : List (WordLetter ι)) + (hI : inverseCount (P++(.noise::Q))≤1) + (t : WordRecursionTerm ι) (ht : t∈wordRecursionAt a P Q) : + inverseCount t.outer≤1 ∧ inverseCount t.inner≤1 := by + dsimp only [wordRecursionAt] at ht + rw [List.mem_append] at ht + simp only [inverseCount_append,inverseCount_noise] at hI + rcases ht with ht|ht + · obtain ⟨c,hc,rfl⟩ := List.mem_map.mp ht + have hh := (wordPartners_counts a P c hc).2 + cases hi : c.inversePartner + · simp [WordCut.asLeft,hi] at *;omega + · have hs := wordPartners_inverse_sides a P c hc hi + simp [WordCut.asLeft,hi] at *;omega + · obtain ⟨c,hc,rfl⟩ := List.mem_map.mp ht + have hh := (wordPartners_counts a Q c hc).2 + cases hi : c.inversePartner + · simp [WordCut.asRight,hi] at *;omega + · have hs := wordPartners_inverse_sides a Q c hc hi + simp [WordCut.asRight,hi] at *;omega + +def firstNoiseSplit : List (WordLetter ι)→Option (List (WordLetter ι)×List (WordLetter ι)) + | [] => none + | .noise::F => some ([],F) + | l::F => (firstNoiseSplit F).map (fun pq=>(l::pq.1,pq.2)) + +lemma firstNoiseSplit_some (F P Q : List (WordLetter ι)) (h : firstNoiseSplit F=some (P,Q)) : + F=P++(.noise::Q) := by + induction F generalizing P Q with + | nil => simp [firstNoiseSplit] at h + | cons l F ih => + cases l with + | noise => simp only [firstNoiseSplit,Option.some.injEq,Prod.mk.injEq] at h;rcases h with ⟨rfl,rfl⟩;rfl + | diag d => + simp only [firstNoiseSplit,Option.map_eq_some_iff] at h + obtain ⟨⟨P',Q'⟩,h1,h2⟩ := h + simp only [Prod.mk.injEq] at h2 + rcases h2 with ⟨rfl,rfl⟩ + simpa only [List.cons_append] using congrArg (List.cons (.diag d)) (ih P' Q' h1) + | inverse => + simp only [firstNoiseSplit,Option.map_eq_some_iff] at h + obtain ⟨⟨P',Q'⟩,h1,h2⟩ := h + simp only [Prod.mk.injEq] at h2 + rcases h2 with ⟨rfl,rfl⟩ + simpa only [List.cons_append] using congrArg (List.cons (.inverse)) (ih P' Q' h1) + +lemma firstNoiseSplit_none (F : List (WordLetter ι)) : firstNoiseSplit F=none ↔ ordinaryCount F=0 := by + induction F with + | nil => simp [firstNoiseSplit,ordinaryCount] + | cons l F ih => cases l <;> simp [firstNoiseSplit,ordinaryCount] at * <;> exact ih + +def wordRecursionTerms (a : ι→ℝ) (F : List (WordLetter ι)) : List (WordRecursionTerm ι) := + match firstNoiseSplit F with + | none => [] + | some (P,Q) => wordRecursionAt a P Q + +lemma wordRecursionTerms_decreases (a : ι→ℝ) (F : List (WordLetter ι)) + (t : WordRecursionTerm ι) (ht : t∈wordRecursionTerms a F) : + ordinaryCount t.outer simp [hs] at ht + | some pq => + rcases pq with ⟨P,Q⟩ + have he := firstNoiseSplit_some F P Q hs + simp only [hs] at ht + simpa only [he] using wordRecursionAt_decreases a P Q t ht + +lemma wordRecursionTerms_one_inverse (a : ι→ℝ) (F : List (WordLetter ι)) + (hI : inverseCount F≤1) (t : WordRecursionTerm ι) (ht : t∈wordRecursionTerms a F) : + inverseCount t.outer≤1 ∧ inverseCount t.inner≤1 := by + unfold wordRecursionTerms at ht + cases hs : firstNoiseSplit F with + | none => simp [hs] at ht + | some pq => + rcases pq with ⟨P,Q⟩ + have he := firstNoiseSplit_some F P Q hs + simp only [hs] at ht + exact wordRecursionAt_one_inverse a P Q (by simpa only [he] using hI) t ht + +def wordDiagonal (F : List (WordLetter ι)) (i : ι) : ℝ := + ((F.map (fun l=>match l with | .diag d=>d i | _=>1))).prod + +def wordPrediction [Fintype ι] (j : ℝ) (a : ι→ℝ) (z : ℝ) + (F : List (WordLetter ι)) (i : ι) : ℝ := + if ordinaryCount F=0 then wordDiagonal F i else + ((wordRecursionTerms a F).attach.map (fun th=> + (if th.val.inversePartner then z else 1)*j* + ((∑ k,wordPrediction j a z th.val.inner k)/(Fintype.card ι:ℝ))* + wordPrediction j a z th.val.outer i)).sum +termination_by ordinaryCount F +decreasing_by + · exact (wordRecursionTerms_decreases a F th.val th.property).2 + · exact (wordRecursionTerms_decreases a F th.val th.property).1 + +end SKGap +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Matrix/WordSimultaneousPrediction.lean b/lean/OAI/Probability/SKGap/Matrix/WordSimultaneousPrediction.lean new file mode 100644 index 0000000000000000000000000000000000000000..f374a4dc589d1fb92c24ad65fc3322beee56a4bf --- /dev/null +++ b/lean/OAI/Probability/SKGap/Matrix/WordSimultaneousPrediction.lean @@ -0,0 +1,56 @@ +import Mathlib +import OAI.Probability.SKGap.Matrix.WordBiasInduction +import OAI.Probability.SKGap.Stability.WordMeanSeminorm + +namespace OAI + +section +noncomputable section +namespace SKGap +open Matrix Real Set MeasureTheory ProbabilityTheory Filter +open scoped BigOperators Matrix.Norms.Frobenius SchwartzMap Topology + +theorem actual_word_simultaneous_prediction {j A D : ℝ} (hj : 0gaussianReal 0 1)) + {g | ∃ (a : Fin n→ℝ) (F : List (WordLetter (Fin n))), + (∀ i,a i∈Icc 0 A) ∧ F.length≤L ∧ (∀ l∈F,l.bounded D) ∧ inverseCount F≤1 ∧ + C< matrixWordSeminorm p + (actualWord f R hR j a 1 F (goeMatrix (j/n) g)-Matrix.diagonal (wordPrediction j a 1 F))} ≤ + (wordPatternSet L L).card*ENNReal.ofReal (3*exp (-(n:ℝ))) := by + obtain ⟨f,R,hR,Cb,N,hRval,hf,hfr,hCb,hN,hbias⟩ := actual_word_uniform_bias hj hA hs hD hAD L + obtain ⟨C0,hC0,hchain⟩ := all_actualWords_gaussian_chaining f hR hj.le hA (lt_of_lt_of_le zero_lt_one hD) L + refine ⟨f,R,hR,C0+Cb,N,hRval,hf,hfr,by positivity,hN,?_⟩ + intro n hn p + have hn0 : 1≤n := (Nat.succ_le_iff.mpr hN).trans hn + apply (measure_mono ?_).trans (hchain n hn0 p) + intro g hg + obtain ⟨a,F,ha,hFL,hF,hFI,hg⟩ := hg + refine ⟨a,F,ha,hFL,hF,?_⟩ + have hb : matrixWordSeminorm p (Matrix.diagonal (fun i=>wordExpected f hR j a 1 F i-wordPrediction j a 1 F i))≤Cb := by + cases p with + | false => + exact diagonalSeminorm_diagonal_bound hn0 hCb.le + (hbias n hn a (fun i=>(ha i).1) (fun i=>(ha i).2) 1 ⟨zero_le_one,le_rfl⟩ F hFL hF hFI) + | true => + change offDiagonalSeminorm (Matrix.diagonal _)≤Cb + rw [offDiagonalSeminorm_diagonal] + exact hCb.le + have hdecomp := actualWord_diagonal_prediction_decompose (j:=j) f hR a 1 F g + simp only [Fintype.card_fin] at hdecomp + rw [hdecomp] at hg + have hh := matrixWordSeminorm_add p + (matrixCentered (fun x : EuclideanSpace ℝ (MatrixCoordinates (Fin n))=> + actualWord f R hR j a 1 F (goeMatrix (j/n) x)) (WithLp.toLp 2 g)) + (Matrix.diagonal (fun i=>wordExpected f hR j a 1 F i-wordPrediction j a 1 F i)) + linarith +end SKGap +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Matrix/WordTemplateSurjective.lean b/lean/OAI/Probability/SKGap/Matrix/WordTemplateSurjective.lean new file mode 100644 index 0000000000000000000000000000000000000000..993cc7b0cb6f59f24d44f38546320ae56298ceb6 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Matrix/WordTemplateSurjective.lean @@ -0,0 +1,150 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.AffineBilinear +import OAI.Probability.SKGap.Localization.TemplatePatterns + +namespace OAI + +section +noncomputable section +namespace SKGap +open Matrix Real Set +open scoped BigOperators Matrix.Norms.Frobenius SchwartzMap +variable {ι : Type*} + +def inverseChart {A : ℝ} (hA : 0 d i + | _ => 0 +lemma WordLetter.diagonalValue_bound {D : ℝ} (hD : 0≤D) (l : WordLetter ι) + (hl : l.bounded D) (i : ι) : |l.diagonalValue i|≤D := by + cases l with + | diag d => exact hl i + | noise => simpa [diagonalValue] using hD + | inverse => simpa [diagonalValue] using hD + +theorem templateWord_surjective {A D : ℝ} (hA : 0match s.1 with + | none => inverseChart hA (a s.2) (ha s.2) + | some k => if hk : k.valmatch F[k.val] with + | .diag _ => .diag ⟨k.val,lt_of_lt_of_le k.isLt hL⟩ + | .noise => .noise + | .inverse => .inverse + let G := List.ofFn pattern + refine ⟨G,θ,by simp [G],?_,?_⟩ + · funext i + exact inverseChart_exact hA (a i) (ha i) + · have hp (k : Fin F.length) : (pattern k).realize D θ=F[k.val] := by + cases hl : F[k.val] with + | diag d => + dsimp [pattern] + rw [hl] + apply congrArg WordLetter.diag + funext i + simp only [templateDiagonal,θ,dite_eq_left k.isLt,hl,WordLetter.diagonalValue] + exact diagonalChart_exact hD (d i) _ + | noise => simp [pattern,hl,WordTemplateLetter.realize] + | inverse => simp [pattern,hl,WordTemplateLetter.realize] + change (List.ofFn pattern).map (WordTemplateLetter.realize D θ)=F + rw [List.map_ofFn] + calc + _ = List.ofFn (fun k : Fin F.length=>F[k.val]) := congrArg List.ofFn (funext hp) + _ = F := List.ofFn_getElem +end SKGap +end +end + +section +noncomputable section +namespace SKGap +open Matrix Real Set MeasureTheory ProbabilityTheory Filter +open scoped BigOperators Matrix.Norms.Frobenius SchwartzMap Topology + +theorem all_actualWords_gaussian_chaining (f : 𝓢(ℝ,ℂ)) {R j A D : ℝ} + (hR : 0 ≤ R) (hj : 0 ≤ j) (hA : 0gaussianReal 0 1)) + {g | ∃ (a : Fin n→ℝ) (F : List (WordLetter (Fin n))), + (∀ i,a i∈Icc 0 A) ∧ F.length ≤ L ∧ (∀ l∈F,l.bounded D) ∧ + C< matrixWordSeminorm p + (matrixCentered (fun x : EuclideanSpace ℝ (MatrixCoordinates (Fin n))=> + actualWord f R hR j a 1 F (goeMatrix (j/n) x)) (WithLp.toLp 2 g))} ≤ + (wordPatternSet L L).card*ENNReal.ofReal (3*exp (-(n:ℝ))) := by + obtain ⟨C,hC,ht⟩ := all_generalTemplateWords_gaussian_chaining (m:=L) f hR hj hA.le hD.le L + refine ⟨C,hC,?_⟩ + intro n hn p + apply (measure_mono ?_).trans (ht n hn p) + intro g hg + obtain ⟨a,F,ha,hFL,hF,hg⟩ := hg + obtain ⟨G,θ,hG,haθ,hFθ⟩ := templateWord_surjective hA hD ha F hF hFL + refine ⟨G,by omega,θ,?_⟩ + simpa only [generalTemplateMatrix,haθ,hFθ] using hg +end SKGap +end +end + +section +noncomputable section +namespace SKGap +open Matrix Real MeasureTheory ProbabilityTheory +open scoped BigOperators SchwartzMap Matrix.Norms.Frobenius +variable {ι : Type*} [Fintype ι] [DecidableEq ι] + +lemma WordLetter.sign (f : 𝓢(ℝ,ℂ)) {R : ℝ} (hR : 0≤R) (j : ℝ) (a : ι→ℝ) (z : ℝ) + (s : ι→ℝ) (hs : ∀ i,s i^2=1) (M : Matrix ι ι ℝ) (l : WordLetter ι) : + l.eval f R hR j a z (signConjugate s M)=signConjugate s (l.eval f R hR j a z M) := by + cases l with + | diag d => exact (signConjugate_diagonal s hs d).symm + | noise => exact realProject_sign hR s hs M + | inverse => exact pathK_sign f hR j a z s hs M + +lemma actualWord_sign (f : 𝓢(ℝ,ℂ)) {R : ℝ} (hR : 0≤R) (j : ℝ) (a : ι→ℝ) (z : ℝ) + (s : ι→ℝ) (hs : ∀ i,s i^2=1) (M : Matrix ι ι ℝ) (F : List (WordLetter ι)) : + actualWord f R hR j a z F (signConjugate s M)=signConjugate s (actualWord f R hR j a z F M) := by + induction F with + | nil => + change (1:Matrix ι ι ℝ)=signConjugate s 1 + simpa only [diagonal_one] using (signConjugate_diagonal s hs (fun _=>1)).symm + | cons l F ih => + change l.eval f R hR j a z (signConjugate s M)*actualWord f R hR j a z F (signConjugate s M)= + signConjugate s (l.eval f R hR j a z M*actualWord f R hR j a z F M) + rw [l.sign f hR j a z s hs M,ih,signConjugate_mul s hs] + +theorem actualWord_offdiag_mean (f : 𝓢(ℝ,ℂ)) {R : ℝ} (hR : 0≤R) (j r : ℝ) (a : ι→ℝ) (z : ℝ) + (F : List (WordLetter ι)) (i k : ι) (hik : i≠k) : + (∫ g,actualWord f R hR j a z F (goeMatrix r g) i k + ∂Measure.pi (fun _ : MatrixCoordinates ι=>gaussianReal 0 1))=0 := + goe_equivariant_offdiag r (actualWord f R hR j a z F) + (fun s hs M=>actualWord_sign f hR j a z s hs M F) i k hik +end SKGap +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Model.lean b/lean/OAI/Probability/SKGap/Model.lean new file mode 100644 index 0000000000000000000000000000000000000000..4649f3531a7921f1e757a55a28d685a87bef1fbd --- /dev/null +++ b/lean/OAI/Probability/SKGap/Model.lean @@ -0,0 +1,73 @@ +import Mathlib + +namespace OAI + +noncomputable section +open scoped BigOperators +open MeasureTheory ProbabilityTheory Filter + +namespace SKGap + +abbrev Spin (n : ℕ) := Fin n → Bool +abbrev Edge (n : ℕ) := {p : Fin n × Fin n // p.1 < p.2} +abbrev Disorder (n : ℕ) := Edge n → ℝ + +def spinValue (b : Bool) : ℝ := if b then 1 else -1 + +def coupling {n : ℕ} (g : Disorder n) (i k : Fin n) : ℝ := + if h : i < k then g ⟨(i, k), h⟩ else + if h : k < i then g ⟨(k, i), h⟩ else 0 + +def hamiltonian {n : ℕ} (g : Disorder n) (h : Fin n → ℝ) (x : Spin n) : ℝ := + (1 / 2 : ℝ) * ∑ i, ∑ k, spinValue (x i) * coupling g i k * spinValue (x k) + + ∑ i, h i * spinValue (x i) + +def weight {n : ℕ} (g : Disorder n) (h : Fin n → ℝ) (x : Spin n) : ℝ := + Real.exp (hamiltonian g h x) + +def partition {n : ℕ} (g : Disorder n) (h : Fin n → ℝ) : ℝ := + ∑ x, weight g h x + +def mass {n : ℕ} (g : Disorder n) (h : Fin n → ℝ) (x : Spin n) : ℝ := + weight g h x / partition g h + +def expectation {n : ℕ} (g : Disorder n) (h : Fin n → ℝ) (f : Spin n → ℝ) : ℝ := + ∑ x, mass g h x * f x + +def variance {n : ℕ} (g : Disorder n) (h : Fin n → ℝ) (f : Spin n → ℝ) : ℝ := + expectation g h (fun x => (f x - expectation g h f) ^ 2) + +def flip {n : ℕ} (i : Fin n) (x : Spin n) : Spin n := + Function.update x i (!(x i)) + +/-- Conditional expectation under the actual Gibbs law given all other spins. -/ +def conditionalExpectation {n : ℕ} (g : Disorder n) (h : Fin n → ℝ) + (i : Fin n) (f : Spin n → ℝ) (x : Spin n) : ℝ := + (weight g h x * f x + weight g h (flip i x) * f (flip i x)) / + (weight g h x + weight g h (flip i x)) + +/-- Unscaled form: each site has a rate-one clock. -/ +def dirichlet {n : ℕ} (g : Disorder n) (h : Fin n → ℝ) (f : Spin n → ℝ) : ℝ := + ∑ i, expectation g h (fun x => (f x - conditionalExpectation g h i f x) ^ 2) + +def disorderLaw (β : ℝ) (n : ℕ) : Measure (Disorder n) := + Measure.pi (fun _ : Edge n => gaussianReal 0 (Real.toNNReal (β ^ 2 / n))) + +def poincareEvent (n : ℕ) (C : ℝ) : Set (Disorder n) := + {g | ∀ f : Spin n → ℝ, variance g 0 f ≤ C * dirichlet g 0 f} + +/-- Rayleigh quotient definition of the uniform-site discrete heat-bath gap. -/ +def discreteGap {n : ℕ} (g : Disorder n) : ℝ := + sInf {r : ℝ | ∃ f : Spin n → ℝ, 0 < variance g 0 f ∧ + r = dirichlet g 0 f / ((n : ℝ) * variance g 0 f)} + +def MainStatement (β : ℝ) : Prop := + ∃ C : ℝ, 0 < C ∧ + Tendsto (fun n : ℕ => disorderLaw β n (poincareEvent n C)) atTop (nhds 1) ∧ + Tendsto (fun n : ℕ => disorderLaw β n {g | 1 / (C * (n : ℝ)) ≤ discreteGap g}) + atTop (nhds 1) + +end SKGap +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Posterior/BufferedPosteriorCovariance.lean b/lean/OAI/Probability/SKGap/Posterior/BufferedPosteriorCovariance.lean new file mode 100644 index 0000000000000000000000000000000000000000..57c6786b1392fd717890be87fc6e39c136cae52b --- /dev/null +++ b/lean/OAI/Probability/SKGap/Posterior/BufferedPosteriorCovariance.lean @@ -0,0 +1,117 @@ +import Mathlib +import OAI.Probability.SKGap.Posterior.BufferedPosteriorDirection + +namespace OAI + +section + +noncomputable section +open scoped BigOperators Matrix.Norms.Frobenius +namespace SKGapCutoff.Recipe +open SKGap.Stein Primary Static +universe u + +theorem buffered_posterior_covariance {j K B Aroot ε c r₀ R ρ : ℝ} + (hj : 0≤j) (hK : 0≤K) (hB : 0≤B) (hA : 1≤Aroot) (hc : 0n a.1) + (fun a=>J a.1) (fun a=>h a.1) (fun a=>a.2.1) + (fun a=>hn a.1) (fun a=>hJ a.1) (fun a=>hdiag a.1) (fun a=>a.2.2) + (fun a=>hstarted a.1) (fun a=>hevent a.1) (fun a=>hbad a.1) (fun a=>hdim a.1) + refine ⟨D,hD,?_⟩ + intro b G + apply posterior_vectorNorm_le_of_unit_dot _ (mul_nonneg hD (Real.sqrt_nonneg _)) + intro e he + exact weak_direction_center _ G (sum_fieldGibbs _ _) (r ⟨b,e,he⟩) e (hw ⟨b,e,he⟩) + +end SKGapCutoff.Recipe + +end +end + +section + +noncomputable section +open Filter Topology +namespace SKGapCutoff.Recipe +open SKGap.Stein Primary Static + +theorem posterior_buffer_exists (j K c r₀ R ε : ℝ) + (hc : 0] 0,a*(2*ρ) a*(2*ρ)) (𝓝[>] 0) (𝓝 (0:ℝ)) := by + have C : ContinuousAt (fun ρ : ℝ => a*(2*ρ)) 0 := by fun_prop + simpa using C.tendsto.mono_left nhdsWithin_le_nhds + exact H.eventually_lt_const hb + let q := (1+2*j)*(1+(1+(K+3*j)/c)*(K+4*j)) + let d := c/(2*(|j| *Real.exp (R/2)*(3*Real.exp (R/2)+16)+1)) + have hd : 0] 0,0<ρ := self_mem_nhdsWithin + have H : ∀ᶠ ρ : ℝ in 𝓝[>] 0, 0<ρ ∧ (K+4*j)*(2*ρ)fieldGibbs (J b) (h b)) + (fun b x=>∑i,(spin x i-Real.tanh (r b i))*e b i) := by + classical + choose A hA hs using fun k=>buffered_root_direction_weak.{u} hj hK hB hA hc hr₀ hρ hε + hAR hbuffer hR hsmall himplicit habsorb k + refine ⟨A,hA,?_⟩ + intro m δ hδ hm hδm W C hW hC Ω n J h e hn hJ hdiag he hstarted hevent hbad hdim + have hm0 : 0 < m := by + by_contra hh + have hz:m=0:=by omega + subst m + norm_num at hm + have hd0 : 0<2*m-1:=by omega + let P:=fun b=>fieldGibbs (J b) (h b) + have hP : ∀b x,0≤P b x:=fun b x=>(fieldGibbs_pos _ _ _).le + have hp : ∀b,∑x,P b x=1:=fun b=>sum_fieldGibbs _ _ + have hmean : ∀b x i,conditionalMean (P b) x i=mag j (J b) (h b) 1 x i := + fun b=>conditionalMean_primary j (J b) (hJ b) (hdiag b) (h b) + obtain ⟨r,hr,D,hD,hdir⟩:=hs 0 W C hW hC Ω n J h e P hn hJ he + (fun b=>hstarted b 0 hd0) hbad (fun b=>hdim b 0 hd0) hP hp hmean + refine ⟨r,hr,?_⟩ + let F:=fun k b x=>∑i,(mag j (J b) (h b) (k+2) x i-Real.tanh (r b i))*e b i + apply uniform_cutoff_partition (C:=fun k b=>residualCutoff ρ j (J b) (h b) k) + (F:=F) (2*m-1) hP + · intro k hk + exact residualCutoff_uniform hρ hK hB hn (fun b=>(hevent b).1) + (fun b x l hl=>(hevent b).2.1 (h b) x l hl) k (by omega) + · intro k hk + have hh:=(gibbs_constant_residuals (h:=h) (e:=e) (2*m) hK hB hW hC hn hJ hdiag hevent he (k+2) (by omega)).1 + apply hh.congr + intro b x + dsimp [F] + rw [←Finset.sum_sub_distrib] + apply Finset.sum_congr rfl + intro i _ + ring + · intro k hk + obtain ⟨r',hr',D',hD',hh⟩:=hs k W C hW hC Ω n J h e P hn hJ he + (fun b=>hstarted b k hk) hbad (fun b=>hdim b k hk) hP hp hmean + have heqr : r'=r:=funext fun b=>(hr b).2 (r' b) (hr' b).1 + rw [heqr] at hh + refine ⟨D',hD',fun b G=>?_⟩ + have hh':=hh b G + change |∑x,P b x*G x*(residualCutoff ρ j (J b) (h b) k x*F k b x)|≤_ + have heq : (∑x,P b x*G x*(residualCutoff ρ j (J b) (h b) k x*F k b x))= + ∑x,P b x*(residualCutoff ρ j (J b) (h b) k x*G x)* + (∑i,(Real.tanh (fld j (J b) (h b) (k+1) x i)-Real.tanh (r b i))*e b i) := by + apply Finset.sum_congr rfl + intro x _ + simp only [F,mag_succ] + ring + rwa [heq] + · obtain ⟨Q,hQ,hq⟩:=gibbs_residual_selection_deficit (h:=h) m hρ hδ hm hδm hK hB hW hC hn hJ hdiag hevent + exact ⟨Q,hQ,fun b G=>hq b (r b) (e b) (he b) G⟩ + +end SKGapCutoff.Recipe + +end +end + +section + +noncomputable section +open scoped BigOperators +namespace SKGapCutoff.Static +open Primary Recipe +variable {n : ℕ} + +lemma posterior_vectorNorm_le_of_unit_dot {n : ℕ} (v : Fin n→ℝ) {B : ℝ} (hB : 0≤B) + (h : ∀e : Fin n→ℝ,vectorNorm e≤1→|∑i,v i*e i|≤B) : vectorNorm v≤B := by + by_cases hv:vectorNorm v=0 + · simpa [hv] using hB + have hp:0(vectorNorm v)⁻¹*v i + have he:vectorNorm e=1 := by + change SKGap.vectorNorm (fun i=>(vectorNorm v)⁻¹*v i)=1 + rw [SKGap.vectorNorm_smul,abs_of_pos (inv_pos.mpr hp)] + exact inv_mul_cancel₀ hv + have hh:=h e he.le + have hd:(∑i,v i*e i)=vectorNorm v := by + calc + _ = (vectorNorm v)⁻¹*(∑i,(v i)^2) := by + rw [Finset.mul_sum] + apply Finset.sum_congr rfl;intro i _;dsimp [e];ring + _ = (vectorNorm v)⁻¹*(vectorNorm v)^2 := by rw [vectorNorm_sq] + _ = _ := by field_simp + simpa only [hd,abs_of_nonneg (vectorNorm_nonneg _)] using hh + +def centeredSpinCovariance (P G : Observables n) : Fin n→ℝ := + fun i=>∑x,P x*(G x-∑y,P y*G y)*spin x i + +lemma centeredSpinCovariance_eq (P G : Observables n) (i : Fin n) : + centeredSpinCovariance P G i=(∑x,P x*G x*spin x i)- + (∑x,P x*G x)*(∑x,P x*spin x i) := by + dsimp [centeredSpinCovariance] + rw [show (∑x,P x*G x)*(∑x,P x*spin x i)= + ∑x,(∑y,P y*G y)*(P x*spin x i) by rw [Finset.mul_sum]] + rw [←Finset.sum_sub_distrib] + apply Finset.sum_congr rfl + intro x _ + ring + +lemma weak_direction_center (P G : Observables n) (hp : ∑x,P x=1) + (r e : Fin n→ℝ) {D : ℝ} + (hw : ∀U,|∑x,P x*U x*(∑i,(spin x i-Real.tanh (r i))*e i)|≤D*starNorm P U) : + |∑i,centeredSpinCovariance P G i*e i|≤ + D*Real.sqrt ((∑x,P x*(G x-∑y,P y*G y)^2)+varianceEnergy P G) := by + let U:=fun x=>G x-∑y,P y*G y + have hzero : (∑x,P x*U x)=0 := by + dsimp [U] + simp only [mul_sub,Finset.sum_sub_distrib,←Finset.sum_mul,hp,one_mul,sub_self] + have he : varianceEnergy P U=varianceEnergy P G := by + unfold varianceEnergy + apply Finset.sum_congr rfl + intro x _ + congr 1 + apply Finset.sum_congr rfl + intro i _ + have hd : halfDiff i U x=halfDiff i G x:=by dsimp [halfDiff,U];ring + rw [hd] + have hid : (∑x,P x*U x*(∑i,(spin x i-Real.tanh (r i))*e i))= + ∑i,centeredSpinCovariance P G i*e i := by + simp only [sub_mul,Finset.sum_sub_distrib,mul_sub] + rw [←Finset.sum_mul,hzero,zero_mul,sub_zero] + simp only [Finset.mul_sum,centeredSpinCovariance,Finset.sum_mul] + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro i _ + apply Finset.sum_congr rfl + intro x _ + dsimp [U] + ring + have hh:=hw U + rw [hid] at hh + simpa only [starNorm,starSquared,he,U] using hh + +end SKGapCutoff.Static + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Posterior/ChannelTranslation.lean b/lean/OAI/Probability/SKGap/Posterior/ChannelTranslation.lean new file mode 100644 index 0000000000000000000000000000000000000000..c9e0b462d437e71f5d0142bccd239421dcccdd0d --- /dev/null +++ b/lean/OAI/Probability/SKGap/Posterior/ChannelTranslation.lean @@ -0,0 +1,87 @@ +import Mathlib +import OAI.Probability.SKGap.Gaussian.ProductGaussianDensity +import OAI.Probability.SKGap.Posterior.GaussianChannel + +namespace OAI + +section +noncomputable section +namespace SKGap +open MeasureTheory ProbabilityTheory Real Set +open scoped BigOperators ENNReal +variable {n : ℕ} + +lemma channel_pdf_tilt (a x : ℝ) : + gaussianPDFReal a 1 x=gaussianPDFReal 0 1 x*exp (a*x-a^2/2) := by + simp only [gaussianPDFReal,NNReal.coe_one,mul_one,sub_zero] + have he : -(x-a)^2/2= -x^2/2+(a*x-a^2/2) := by ring + rw [he,exp_add] + ring + +lemma channelReference_tilt (a : Fin n→ℝ) : + (channelReference n).withDensity + (fun z=>ENNReal.ofReal (exp ((∑ i,a i*z i)-(∑ i,a i^2)/2))) = + Measure.pi (fun i=>gaussianReal (a i) 1) := by + have hp (z : Fin n→ℝ) : (∏ i,gaussianPDFReal (a i) 1 (z i))= + (∏ i,gaussianPDFReal 0 1 (z i))*exp ((∑ i,a i*z i)-(∑ i,a i^2)/2) := by + calc + _ = ∏ i,(gaussianPDFReal 0 1 (z i)*exp (a i*z i-a i^2/2)) := + Finset.prod_congr rfl (fun i _=>channel_pdf_tilt _ _) + _ = _ := by + rw [Finset.prod_mul_distrib,← exp_sum] + congr 2 + rw [Finset.sum_sub_distrib,Finset.sum_div] + unfold channelReference + rw [GaussianDensity.pi_gaussian_density (fun _ : Fin n=>0) (fun _=>1) (fun _=>one_ne_zero), + GaussianDensity.pi_gaussian_density a (fun _=>1) (fun _=>one_ne_zero)] + rw [← withDensity_mul _ (GaussianDensity.measurable_productPDF _ _) (by fun_prop)] + congr 1 + ext z + simp only [Pi.mul_apply,hp] + exact (ENNReal.ofReal_mul (Finset.prod_nonneg (fun i _=>gaussianPDFReal_nonneg 0 1 (z i)))).symm + +lemma channel_shift_hasLaw (a : Fin n→ℝ) : + HasLaw (fun z : Fin n→ℝ=>fun i=>z i+a i) + (Measure.pi (fun i=>gaussianReal (a i) 1)) (channelReference n) := by + have hl (i : Fin n) : HasLaw (fun z : Fin n→ℝ=>z i+a i) + (gaussianReal (a i) 1) (channelReference n) := by + have hc : HasLaw (fun z : Fin n→ℝ=>z i) (gaussianReal 0 1) (channelReference n) := + ⟨(measurable_pi_apply i).aemeasurable,(measurePreserving_eval (fun _ : Fin n=>gaussianReal 0 1) i).map_eq⟩ + simpa only [zero_add] using gaussianReal_add_const hc (a i) + exact iIndepFun.hasLaw_pi hl ((iIndepFun_pi (fun _ : Fin n=>aemeasurable_id)).comp + (fun i=>fun x : ℝ=>x+a i) (fun _=>by fun_prop)) + +lemma channel_likelihood_tilt {T : ℝ} (hT : 0 ≤ T) (x : Spin n) : + (channelReference n).withDensity (fun z=>ENNReal.ofReal (gaussianChannelLikelihood T x z))= + Measure.pi (fun i=>gaussianReal (sqrt T*spinValue (x i)) 1) := by + have hs : (∑ i,(sqrt T*spinValue (x i))^2)=(n:ℝ)*T := by + simp only [mul_pow,sq_sqrt hT,spinValue_sq,mul_one,Finset.sum_const,Finset.card_univ, + Fintype.card_fin,nsmul_eq_mul] + convert channelReference_tilt (fun i=>sqrt T*spinValue (x i)) using 1 + simp only [hs,gaussianChannelLikelihood] + +lemma gaussianChannel_event (g : Disorder n) {T : ℝ} (hT : 0 ≤ T) (B : Set (Fin n→ℝ)) + (hB : MeasurableSet B) : + gaussianChannelLaw g T B=∑ x,ENNReal.ofReal (mass g 0 x)* + channelReference n ((fun z : Fin n→ℝ=>fun i=>z i+sqrt T*spinValue (x i)) ⁻¹' B) := by + rw [gaussianChannelLaw,withDensity_apply _ hB] + have hd (z : Fin n→ℝ) : ENNReal.ofReal (gaussianChannelDensity g T z)= + ∑ x,ENNReal.ofReal (mass g 0 x)*ENNReal.ofReal (gaussianChannelLikelihood T x z) := by + unfold gaussianChannelDensity + rw [ENNReal.ofReal_sum_of_nonneg (fun x _=>mul_nonneg (mass_nonneg g 0 x) (by unfold gaussianChannelLikelihood; positivity))] + exact Finset.sum_congr rfl (fun x _=>ENNReal.ofReal_mul (mass_nonneg g 0 x)) + simp only [hd] + rw [lintegral_finsetSum _ (fun x _=>by unfold gaussianChannelLikelihood; fun_prop)] + apply Finset.sum_congr rfl + intro x _ + rw [lintegral_const_mul _ (by unfold gaussianChannelLikelihood; fun_prop)] + congr 1 + rw [← withDensity_apply _ hB,channel_likelihood_tilt hT] + exact ((channel_shift_hasLaw (fun i=>sqrt T*spinValue (x i))).map_eq ▸ + Measure.map_apply (by fun_prop) hB) +end SKGap + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Posterior/ConditionalObservationData.lean b/lean/OAI/Probability/SKGap/Posterior/ConditionalObservationData.lean new file mode 100644 index 0000000000000000000000000000000000000000..d2dd100b46f5a8c87b75735d68aa052ec88935ea --- /dev/null +++ b/lean/OAI/Probability/SKGap/Posterior/ConditionalObservationData.lean @@ -0,0 +1,76 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.EmpiricalConditionalData + +namespace OAI + +section +noncomputable section +namespace SKGap +open Matrix Real Set MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix.Norms.Frobenius + +lemma scalarA_empirical_sum {n : ℕ} [NeZero n] (j t σ : ℝ) (y : Fin n → ℝ) : + ∑ i,tanh (y i)*(y i-scalarD j (empiricalLaw y,t,σ))= + (n:ℝ)*scalarA j (empiricalLaw y,t,σ) := by + simp only [scalarA,scalarM,integral_empiricalLaw,Fintype.card_fin] + have hn : (n:ℝ) ≠ 0 := by exact_mod_cast NeZero.ne n + rw [mul_sub,← mul_assoc,mul_inv_cancel₀ hn,one_mul] + simp only [mul_sub] + rw [Finset.sum_sub_distrib] + congr 1 + · apply Finset.sum_congr rfl + intro i _; ring + · rw [← Finset.sum_mul] + field_simp + +lemma empirical_unit_scale {n : ℕ} [NeZero n] (y : Fin n → ℝ) {q : ℝ} (hq : 0 < q) : + sqrt ((n:ℝ)*q) • (empiricalUnit y q).ofLp=(fun i=>tanh (y i)) := by + have hc : sqrt ((n:ℝ)*q) ≠ 0 := ne_of_gt (sqrt_pos.mpr (mul_pos (by exact_mod_cast NeZero.pos n) hq)) + ext i + simp only [empiricalUnit,WithLp.ofLp_toLp,Pi.smul_apply,smul_eq_mul] + field_simp + +lemma empirical_Z_formula {n : ℕ} [NeZero n] (y : Fin n → ℝ) (d : ℝ) {s : ℝ} (hs : 0 < s) : + sqrt s • (empiricalGramColumns y d s 2).ofLp=(fun i=>(y i-d)/(sqrt (n:ℝ)*sqrt s)) := by + have hn : sqrt (n:ℝ) ≠ 0 := ne_of_gt (sqrt_pos.mpr (by exact_mod_cast NeZero.pos n)) + have hss : sqrt s ≠ 0 := (sqrt_pos.mpr hs).ne' + ext i + simp only [empiricalGramColumns,gramCoordinates,Matrix.cons_val,Pi.smul_apply, + WithLp.ofLp_toLp,smul_eq_mul] + field_simp + rw [Real.sq_sqrt hs.le] + ring + +lemma empirical_unit_center_dot {n : ℕ} [NeZero n] (j t σ : ℝ) (y : Fin n → ℝ) : + (empiricalUnit y (scalarQMoment (empiricalLaw y))).ofLp⬝ᵥ + (fun i=>y i-scalarD j (empiricalLaw y,t,σ))= + (n:ℝ)*scalarA j (empiricalLaw y,t,σ)/sqrt ((n:ℝ)*scalarQMoment (empiricalLaw y)) := by + simp only [empiricalUnit,WithLp.ofLp_toLp,dotProduct,div_mul_eq_mul_div,← Finset.sum_div] + rw [scalarA_empirical_sum] + +lemma empirical_unit_observation_dot {n : ℕ} [NeZero n] (j t σ B : ℝ) + (y : Fin n → ℝ) (hq : 0 < scalarQMoment (empiricalLaw y)) : + (empiricalUnit y (scalarQMoment (empiricalLaw y))).ofLp⬝ᵥ + (fun i=>y i-scalarD j (empiricalLaw y,t,σ)+B*tanh (y i))= + (n:ℝ)*(scalarA j (empiricalLaw y,t,σ)+B*scalarQMoment (empiricalLaw y))/ + sqrt ((n:ℝ)*scalarQMoment (empiricalLaw y)) := by + let q := scalarQMoment (empiricalLaw y) + let u := (empiricalUnit y q).ofLp + let c := sqrt ((n:ℝ)*q) + have hc : c ≠ 0 := ne_of_gt (sqrt_pos.mpr (mul_pos (by exact_mod_cast NeZero.pos n) hq)) + have hc2 : c^2=(n:ℝ)*q := sq_sqrt (mul_nonneg (Nat.cast_nonneg n) hq.le) + have hu : u⬝ᵥu=1 := empiricalUnit_unit y hq + have hscale : c • u=(fun i=>tanh (y i)) := empirical_unit_scale y hq + have heq : (fun i=>y i-scalarD j (empiricalLaw y,t,σ)+B*tanh (y i))= + (fun i=>y i-scalarD j (empiricalLaw y,t,σ))+B • (c • u) := by + rw [hscale]; rfl + rw [heq,dotProduct_add,dotProduct_smul,dotProduct_smul,hu,empirical_unit_center_dot] + simp only [smul_eq_mul,mul_one] + change (n:ℝ)*scalarA j (empiricalLaw y,t,σ)/c+B*c=(n:ℝ)*(scalarA j (empiricalLaw y,t,σ)+B*q)/c + field_simp + linear_combination B*hc2 +end SKGap +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Posterior/GOEObservation.lean b/lean/OAI/Probability/SKGap/Posterior/GOEObservation.lean new file mode 100644 index 0000000000000000000000000000000000000000..14c6cfb4e957a2dc5456f964532a37af65781ef7 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Posterior/GOEObservation.lean @@ -0,0 +1,159 @@ +import Mathlib +import OAI.Probability.SKGap.Gaussian.GOEGaussian + +namespace OAI + +section +noncomputable section +namespace SKGap +open MeasureTheory ProbabilityTheory Matrix Real +open scoped BigOperators ENNReal +variable {ι : Type*} [Fintype ι] [DecidableEq ι] + +def goeObservation (r v : ℝ) (m : ι → ℝ) (g : MatrixCoordinates ι → ℝ) : ι → ℝ := + fun i => (goeMatrix r g*ᵥm) i+sqrt v*g (.inr i) + +def observationCoeff (r v : ℝ) (m : ι → ℝ) : Matrix ι (MatrixCoordinates ι) ℝ := + fun i a => (∑ k, m k*goeEntryCoeff r (i,k) a)+sqrt v*(if a=Sum.inr i then 1 else 0) + +lemma observationCoeff_sample (r v : ℝ) (m : ι → ℝ) (g : MatrixCoordinates ι → ℝ) : + observationCoeff r v m*ᵥg=goeObservation r v m g := by + ext i + change (∑ a, ((∑ k, m k*goeEntryCoeff r (i,k) a)+sqrt v*(if a=Sum.inr i then 1 else 0))*g a)= + (∑ k, goeMatrix r g i k*m k)+sqrt v*g (.inr i) + rw [show (∑ a, ((∑ k, m k*goeEntryCoeff r (i,k) a)+sqrt v*(if a=Sum.inr i then 1 else 0))*g a)= + (∑ a, (∑ k, m k*goeEntryCoeff r (i,k) a)*g a)+sqrt v*g (.inr i) by + simp [add_mul,Finset.sum_add_distrib]] + congr 1 + simp only [Finset.sum_mul] + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro k _ + have hh := goeEntryCoeff_sample r g i k + change (∑ a, m k*goeEntryCoeff r (i,k) a*g a)=goeMatrix r g i k*m k + rw [show (∑ a, m k*goeEntryCoeff r (i,k) a*g a)=m k*((goeEntryCoeff r*ᵥg) (i,k)) by + simp only [mulVec,dotProduct,Finset.mul_sum,mul_assoc]] + rw [hh,mul_comm] + +lemma goe_observation_joint_gaussian (r v : ℝ) (m : ι → ℝ) : + HasGaussianLaw (fun g => ((fun p : ι × ι => goeMatrix r g p.1 p.2),goeObservation r v m g)) + (gaussianCoordinates (MatrixCoordinates ι)) := by + have hh := coordinates_gaussian.map_fun + ((GaussianRegression.matrixCLM (goeEntryCoeff (ι := ι) r)).prod + (GaussianRegression.matrixCLM (observationCoeff r v m))) + apply hh.congr + filter_upwards [] with g + simp only [ContinuousLinearMap.prod_apply,GaussianRegression.matrixCLM_apply, + observationCoeff_sample] + congr 1 + funext p + exact goeEntryCoeff_sample r g p.1 p.2 + +lemma goe_noise_cov (r : ℝ) (i k l : ι) : + cov[fun g => goeMatrix r g i k,fun g => g (.inr l);gaussianCoordinates (MatrixCoordinates ι)]=0 := by + have hm (a : MatrixCoordinates ι) := (coordinate_hasLaw a).hasGaussianLaw.memLp_two + change cov[fun g : MatrixCoordinates ι → ℝ => sqrt (2*r)/2*(g (.inl (i,k))+g (.inl (k,i))), + fun g => g (.inr l);gaussianCoordinates (MatrixCoordinates ι)]=0 + rw [covariance_const_mul_left] + change sqrt (2*r)/2*cov[(fun g => g (.inl (i,k)))+(fun g => g (.inl (k,i))), + fun g => g (.inr l);gaussianCoordinates (MatrixCoordinates ι)]=0 + rw [covariance_add_left (hm _) (hm _) (hm _)] + simp [coordinate_covariance] + +lemma goe_mulVec_memLp (r : ℝ) (m : ι → ℝ) (i : ι) : + MemLp (fun g => (goeMatrix r g*ᵥm) i) 2 (gaussianCoordinates (MatrixCoordinates ι)) := by + have hh := memLp_finsetSum (Finset.univ : Finset ι) + (fun k _ => (goe_matrix_gaussian (ι := ι) r).eval (i,k) |>.memLp_two.mul_const (m k)) + simpa only [mulVec,dotProduct] using hh + +lemma goe_entry_observation_cov {r : ℝ} (hr : 0 ≤ r) (v : ℝ) (m : ι → ℝ) (i k l : ι) : + cov[fun g => goeMatrix r g i k,fun g => goeObservation r v m g l; + gaussianCoordinates (MatrixCoordinates ι)] = + r*((if i=l then m k else 0)+(if k=l then m i else 0)) := by + have hW := (goe_matrix_gaussian (ι := ι) r).eval (i,k) |>.memLp_two + have hM := goe_mulVec_memLp r m l + have hN := (coordinate_hasLaw (Sum.inr l : MatrixCoordinates ι)).hasGaussianLaw.memLp_two.const_mul (sqrt v) + change cov[fun g => goeMatrix r g i k,(fun g => (goeMatrix r g*ᵥm) l)+ + (fun g => sqrt v*g (.inr l));gaussianCoordinates (MatrixCoordinates ι)] = _ + rw [covariance_add_right hW hM hN,covariance_const_mul_right,goe_noise_cov,mul_zero,add_zero] + change cov[fun g => goeMatrix r g i k,fun g => ∑ a, goeMatrix r g l a*m a;_]=_ + rw [covariance_fun_sum_right (fun a => (goe_matrix_gaussian (ι := ι) r).eval (l,a) |>.memLp_two.mul_const (m a)) hW] + simp only [covariance_mul_const_right,goe_entry_cov hr] + by_cases hil : i=l <;> by_cases hkl : k=l <;> + simp [hil,hkl,mul_add,add_mul,Finset.sum_add_distrib] + +lemma goe_mulVec_noise_cov (r : ℝ) (m : ι → ℝ) (i l : ι) : + cov[fun g => (goeMatrix r g*ᵥm) i,fun g => g (.inr l);gaussianCoordinates (MatrixCoordinates ι)]=0 := by + change cov[fun g => ∑ a, goeMatrix r g i a*m a,fun g => g (.inr l);_]=_ + rw [covariance_fun_sum_left + (fun a => (goe_matrix_gaussian (ι := ι) r).eval (i,a) |>.memLp_two.mul_const (m a)) + (coordinate_hasLaw (Sum.inr l : MatrixCoordinates ι)).hasGaussianLaw.memLp_two] + simp [covariance_mul_const_left,goe_noise_cov] + +end SKGap +end +end + +section +noncomputable section +namespace SKGap +open MeasureTheory ProbabilityTheory Matrix Real +open scoped BigOperators ENNReal +variable {ι : Type*} [Fintype ι] [DecidableEq ι] + +lemma goe_mulVec_cov {r : ℝ} (hr : 0 ≤ r) (m : ι → ℝ) (i l : ι) : + cov[fun g => (goeMatrix r g*ᵥm) i,fun g => (goeMatrix r g*ᵥm) l; + gaussianCoordinates (MatrixCoordinates ι)] = + r*((if i=l then ∑ k, m k^2 else 0)+m i*m l) := by + have hc (k : ι) : cov[fun g => goeMatrix r g i k,fun g => (goeMatrix r g*ᵥm) l; + gaussianCoordinates (MatrixCoordinates ι)] = + r*((if i=l then m k else 0)+(if k=l then m i else 0)) := by + simpa only [goeObservation,sqrt_zero,zero_mul,add_zero] using + goe_entry_observation_cov hr 0 m i k l + change cov[fun g => ∑ k, goeMatrix r g i k*m k,fun g => (goeMatrix r g*ᵥm) l;_]=_ + rw [covariance_fun_sum_left + (fun k => (goe_matrix_gaussian (ι := ι) r).eval (i,k) |>.memLp_two.mul_const (m k)) + (goe_mulVec_memLp r m l)] + simp only [covariance_mul_const_left,hc] + by_cases h : i=l + · subst l + simp [mul_add,add_mul,mul_assoc,← pow_two,Finset.sum_add_distrib,← Finset.mul_sum] + · simp [h,mul_ite,ite_mul] + ring + +lemma goe_observation_mean (r v : ℝ) (m : ι → ℝ) (i : ι) : + (∫ g, goeObservation r v m g i ∂gaussianCoordinates (MatrixCoordinates ι))=0 := by + simpa only [← observationCoeff_sample,mulVec,dotProduct] using + linear_gaussian_mean (observationCoeff r v m i) + +lemma goe_observation_cov {r v : ℝ} (hr : 0 ≤ r) (hv : 0 ≤ v) (m : ι → ℝ) (i l : ι) : + cov[fun g => goeObservation r v m g i,fun g => goeObservation r v m g l; + gaussianCoordinates (MatrixCoordinates ι)] = + (r*(∑ k,m k^2)+v)*(if i=l then 1 else 0)+r*m i*m l := by + have hm (k : ι) := goe_mulVec_memLp r m k + have hn (k : ι) := (coordinate_hasLaw (Sum.inr k : MatrixCoordinates ι)).hasGaussianLaw.memLp_two + change cov[(fun g => (goeMatrix r g*ᵥm) i)+(fun g => sqrt v*g (.inr i)), + (fun g => (goeMatrix r g*ᵥm) l)+(fun g => sqrt v*g (.inr l));_]=_ + rw [covariance_add_left (hm i) ((hn i).const_mul _) ((hm l).add ((hn l).const_mul _)), + covariance_add_right (hm i) (hm l) ((hn l).const_mul _), + covariance_add_right ((hn i).const_mul _) (hm l) ((hn l).const_mul _)] + have hback : cov[fun g => g (.inr i),fun g => (goeMatrix r g*ᵥm) l; + gaussianCoordinates (MatrixCoordinates ι)]=0 := by + rw [covariance_comm,goe_mulVec_noise_cov] + rw [covariance_const_mul_right,goe_mulVec_noise_cov,mul_zero,add_zero, + covariance_const_mul_left,hback,mul_zero, + covariance_const_mul_left,covariance_const_mul_right,coordinate_covariance, + goe_mulVec_cov hr] + simp only [Sum.inr.injEq] + by_cases hil : i=l + · simp only [hil,ite_true,mul_one] + rw [mul_self_sqrt hv] + ring + · simp only [hil,ite_false,mul_zero,zero_add,add_zero] + ring + +end SKGap +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Posterior/GOEPointwisePosterior.lean b/lean/OAI/Probability/SKGap/Posterior/GOEPointwisePosterior.lean new file mode 100644 index 0000000000000000000000000000000000000000..7ccad570018ea5ef4f966532311f8656e9e7fd18 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Posterior/GOEPointwisePosterior.lean @@ -0,0 +1,75 @@ +import Mathlib +import OAI.Probability.SKGap.Brownian.ContinuousKernel +import OAI.Probability.SKGap.Matrix.GOEResidualCov + +namespace OAI + +section +noncomputable section +namespace SKGap +open MeasureTheory ProbabilityTheory Matrix Real GaussianDensity GaussianRegression +open scoped BigOperators ENNReal NNReal +variable {ι : Type*} [Fintype ι] [DecidableEq ι] [Nonempty ι] + +def goeLaw (r : ℝ) : Measure ((ι × ι) → ℝ) := + (gaussianCoordinates (MatrixCoordinates ι)).map (fun g p => goeMatrix r g p.1 p.2) + +def conditionalGoeLaw (r v : ℝ) (m z : ι → ℝ) : Measure ((ι × ι) → ℝ) := + ((gaussianCoordinates (MatrixCoordinates ι)).map (goeRegressionResidual r v m)).map + (fun R => R+goeRegressionCoefficient r v m*ᵥz) + +theorem goe_pointwise_posterior {r v : ℝ} (hr : 0 ≤ r) (hv : 0 < v) (m z : ι → ℝ) : + (goeLaw (ι := ι) r).withDensity (fun W => ENNReal.ofReal + (radialDensity (sqrt v) (z-(fun i => ∑ k, W (i,k)*m k)))) = + ENNReal.ofReal (rankOneDensity (r*(m⬝ᵥm)+v) r m z) • conditionalGoeLaw r v m z := by + have hXY := goe_observation_joint_gaussian r v m + let : IsProbabilityMeasure (goeLaw (ι := ι) r) := + inferInstanceAs (IsProbabilityMeasure ((gaussianCoordinates (MatrixCoordinates ι)).map _)) + let ρ := (gaussianCoordinates (MatrixCoordinates ι)).map (goeRegressionResidual r v m) + have hreg := regression_joint_law hXY (goeRegressionCoefficient r v m) (goe_regression_covariance hr hv m) + have hj := goe_joint_noise_law r v m + rw [goe_noise_density hr hv] at hj + rw [goe_observation_density hr hv m] at hreg + have hjoint : ((goeLaw (ι := ι) r).prod ((volume : Measure (ι → ℝ)).withDensity + (fun x => ENNReal.ofReal (radialDensity (sqrt v) x)))).map + (fun q => (q.1,(fun i => ∑ k, q.1 (i,k)*m k)+q.2)) = + (ρ.prod ((volume : Measure (ι → ℝ)).withDensity + (fun x => ENNReal.ofReal (rankOneDensity (r*(m⬝ᵥm)+v) r m x)))).map + (fun q => (q.1+goeRegressionCoefficient r v m*ᵥq.2,q.2)) := hj.trans hreg + have hq : 0 ≤ m⬝ᵥm := Finset.sum_nonneg (fun i _ => mul_self_nonneg (m i)) + have hs := add_pos_of_nonneg_of_pos (mul_nonneg hr hq) hv + exact continuous_kernel_posterior (goeLaw (ι := ι) r) ρ (continuous_radialDensity _) + (continuous_rankOneDensity _ _ m) (fun x => (radialDensity_pos (sqrt_pos.mpr hv) x).le) + (fun x => (rankOneDensity_pos hs hr m x).le) (by positivity) + (radialDensity_le (sqrt_pos.mpr hv)) (by fun_prop) (by fun_prop) hjoint z + +omit [Nonempty ι] in + +theorem conditionalGoeLaw_block {r v c : ℝ} (hr : 0 ≤ r) (hv : 0 < v) + {u : ι → ℝ} (hu : u⬝ᵥu=1) (z : ι → ℝ) : + conditionalGoeLaw r v (c • u) z = + (gaussianCoordinates (MatrixCoordinates ι)).map (fun g p => + goeBlockResidual r (sqrt (v/(r*c^2+v))) (sqrt (v/(v+2*r*c^2))) u g p.1 p.2+ + (goeRegressionCoefficient r v (c • u)*ᵥz) p) := by + rw [conditionalGoeLaw,goe_regression_residual_law hr hv hu, + AEMeasurable.map_map_of_aemeasurable (by fun_prop) (goeBlockResidual_gaussian r _ _ u).aemeasurable] + rfl + +theorem goe_pointwise_conditional_integral {r v : ℝ} (hr : 0 ≤ r) (hv : 0 < v) + (m z : ι → ℝ) (f : ((ι × ι) → ℝ) → ℝ≥0∞) (hf : Measurable f) : + (∫⁻ g, ENNReal.ofReal (radialDensity (sqrt v) (z-goeMatrix r g*ᵥm))* + f (fun p => goeMatrix r g p.1 p.2) ∂gaussianCoordinates (MatrixCoordinates ι)) = + ENNReal.ofReal (rankOneDensity (r*(m⬝ᵥm)+v) r m z)* + (∫⁻ W, f W ∂conditionalGoeLaw r v m z) := by + have hh := congrArg (fun ν => ∫⁻ W, f W ∂ν) (goe_pointwise_posterior hr hv m z) + have hφ : Measurable (fun W : (ι × ι) → ℝ => ENNReal.ofReal (radialDensity (sqrt v) (z-(fun i => ∑ k, W (i,k)*m k)))) := + ((continuous_radialDensity _).comp (by fun_prop)).measurable.ennreal_ofReal + rw [lintegral_withDensity_eq_lintegral_mul _ hφ hf,lintegral_smul_measure] at hh + rw [goeLaw,lintegral_map (hφ.mul hf) (by unfold goeMatrix; fun_prop)] at hh + exact hh + +end SKGap +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Posterior/GaussianChannel.lean b/lean/OAI/Probability/SKGap/Posterior/GaussianChannel.lean new file mode 100644 index 0000000000000000000000000000000000000000..d854584469bf854daa8cddbbb551c8187a1489bc --- /dev/null +++ b/lean/OAI/Probability/SKGap/Posterior/GaussianChannel.lean @@ -0,0 +1,138 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.LiteralRegularity + +namespace OAI + +section +noncomputable section +namespace SKGap +open MeasureTheory ProbabilityTheory Real Set +open scoped BigOperators ENNReal +variable {n : ℕ} + +def channelReference (n : ℕ) : Measure (Fin n→ℝ) := Measure.pi (fun _=>gaussianReal 0 1) +instance channelReference_probability (n : ℕ) : IsProbabilityMeasure (channelReference n) := by + unfold channelReference + infer_instance + +def gaussianChannelLikelihood (T : ℝ) (x : Spin n) (z : Fin n→ℝ) : ℝ := + exp ((∑ i,sqrt T*spinValue (x i)*z i)-(n:ℝ)*T/2) + +def gaussianChannelDensity (g : Disorder n) (T : ℝ) (z : Fin n→ℝ) : ℝ := + ∑ x,mass g 0 x*gaussianChannelLikelihood T x z + +def gaussianChannelLaw (g : Disorder n) (T : ℝ) : Measure (Fin n→ℝ) := + (channelReference n).withDensity (fun z=>ENNReal.ofReal (gaussianChannelDensity g T z)) + +lemma channel_linear_exp_integrable (a : Fin n→ℝ) : + Integrable (fun z : Fin n→ℝ=>exp (∑ i,a i*z i)) (channelReference n) := by + simp only [exp_sum,channelReference] + exact Integrable.fintype_prod (fun i=>integrable_exp_mul_gaussianReal (a i)) + +lemma channel_linear_exp_integral (a : Fin n→ℝ) : + (∫ z,exp (∑ i,a i*z i) ∂channelReference n)=exp ((∑ i,a i^2)/2) := by + simp only [exp_sum,channelReference] + rw [integral_fintype_prod_eq_prod (fun i z=>exp (a i*z))] + have he (i : Fin n) : (∫ z : ℝ,exp (a i*z) ∂gaussianReal 0 1)=exp (a i^2/2) := by + change mgf id (gaussianReal 0 1) (a i)=_ + rw [mgf_id_gaussianReal] + simp + simp only [he,← exp_sum,Finset.sum_div] + +lemma gaussianChannelLikelihood_integrable (T : ℝ) (x : Spin n) : + Integrable (gaussianChannelLikelihood T x) (channelReference n) := by + have he : gaussianChannelLikelihood T x=fun z=>exp (∑ i,sqrt T*spinValue (x i)*z i)*exp (-(n:ℝ)*T/2) := by + funext z + rw [gaussianChannelLikelihood,← exp_add] + congr 1;ring + rw [he] + exact (channel_linear_exp_integrable (fun i=>sqrt T*spinValue (x i))).mul_const _ + +lemma gaussianChannelLikelihood_integral {T : ℝ} (hT : 0 ≤ T) (x : Spin n) : + (∫ z,gaussianChannelLikelihood T x z ∂channelReference n)=1 := by + have he : gaussianChannelLikelihood T x=fun z=>exp (∑ i,sqrt T*spinValue (x i)*z i)*exp (-(n:ℝ)*T/2) := by + funext z + rw [gaussianChannelLikelihood,← exp_add] + congr 1;ring + rw [he,integral_mul_const,channel_linear_exp_integral,← exp_add] + simp only [mul_pow,sq_sqrt hT,spinValue_sq,mul_one,Finset.sum_const,Finset.card_univ, + Fintype.card_fin,nsmul_eq_mul] + convert exp_zero using 1 + congr 1;ring + +lemma gaussianChannelDensity_pos (g : Disorder n) (T : ℝ) (z : Fin n→ℝ) : + 0 < gaussianChannelDensity g T z := + Finset.sum_pos (fun x _=>mul_pos (mass_pos g 0 x) (exp_pos _)) Finset.univ_nonempty + +lemma gaussianChannelDensity_continuous (g : Disorder n) (T : ℝ) : + Continuous (gaussianChannelDensity g T) := by + unfold gaussianChannelDensity gaussianChannelLikelihood + fun_prop + +lemma gaussianChannelDensity_integrable (g : Disorder n) (T : ℝ) : + Integrable (gaussianChannelDensity g T) (channelReference n) := + integrable_finsetSum _ (fun x _=>(gaussianChannelLikelihood_integrable T x).const_mul _) + +lemma gaussianChannelDensity_integral (g : Disorder n) {T : ℝ} (hT : 0 ≤ T) : + (∫ z,gaussianChannelDensity g T z ∂channelReference n)=1 := by + unfold gaussianChannelDensity + rw [integral_finsetSum _ (fun x _=>(gaussianChannelLikelihood_integrable T x).const_mul _)] + simp only [integral_const_mul,gaussianChannelLikelihood_integral hT,mul_one,sum_mass] + +lemma gaussianChannelLaw_probability (g : Disorder n) {T : ℝ} (hT : 0 ≤ T) : + IsProbabilityMeasure (gaussianChannelLaw g T) := by + constructor + rw [gaussianChannelLaw,withDensity_apply _ MeasurableSet.univ,Measure.restrict_univ, + ← ofReal_integral_eq_lintegral_ofReal (gaussianChannelDensity_integrable g T) + (ae_of_all _ (fun z=>(gaussianChannelDensity_pos g T z).le)),gaussianChannelDensity_integral g hT] + exact ENNReal.ofReal_one + +lemma weight_field_shift (g : Disorder n) (h : Fin n→ℝ) (x : Spin n) : + weight g h x=weight g 0 x*exp (∑ i,h i*spinValue (x i)) := by + unfold weight hamiltonian + simp only [Pi.zero_apply,zero_mul,Finset.sum_const_zero,add_zero,exp_add] + +lemma gaussianChannelDensity_partition (g : Disorder n) (T : ℝ) (z : Fin n→ℝ) : + gaussianChannelDensity g T z=exp (-(n:ℝ)*T/2)*partition g (fun i=>sqrt T*z i)/partition g 0 := by + unfold gaussianChannelDensity gaussianChannelLikelihood + have he (x : Spin n) : mass g 0 x*exp ((∑ i,sqrt T*spinValue (x i)*z i)-(n:ℝ)*T/2)= + exp (-(n:ℝ)*T/2)*weight g (fun i=>sqrt T*z i) x/partition g 0 := by + rw [weight_field_shift] + have hs : (∑ i,sqrt T*spinValue (x i)*z i)=(∑ i,sqrt T*z i*spinValue (x i)) := + Finset.sum_congr rfl (fun i _=>by ring) + rw [hs,sub_eq_add_neg,exp_add] + unfold mass + have hn : -((n:ℝ)*T/2)=-(n:ℝ)*T/2 := by ring + rw [hn] + ring + simp_rw [he] + rw [← Finset.sum_div,← Finset.mul_sum] + rfl + +lemma gaussianChannel_posterior_identity (g : Disorder n) (T : ℝ) (z : Fin n→ℝ) (x : Spin n) : + gaussianChannelDensity g T z*mass g (fun i=>sqrt T*z i) x= + mass g 0 x*gaussianChannelLikelihood T x z := by + rw [gaussianChannelDensity_partition] + have he := weight_field_shift g (fun i=>sqrt T*z i) x + have hs : (∑ i,sqrt T*spinValue (x i)*z i)=(∑ i,sqrt T*z i*spinValue (x i)) := + Finset.sum_congr rfl (fun i _=>by ring) + unfold mass gaussianChannelLikelihood + rw [hs,sub_eq_add_neg,exp_add,he] + have hn : -((n:ℝ)*T/2)=-(n:ℝ)*T/2 := by ring + rw [hn] + field_simp [(partition_pos g 0).ne',(partition_pos g (fun i=>sqrt T*z i)).ne'] + +lemma gaussianChannel_mass_mean (g : Disorder n) {T : ℝ} (hT : 0 ≤ T) (x : Spin n) : + (∫ z,mass g (fun i=>sqrt T*z i) x ∂gaussianChannelLaw g T)=mass g 0 x := by + rw [gaussianChannelLaw,integral_withDensity_eq_integral_toReal_smul + (gaussianChannelDensity_continuous g T).measurable.ennreal_ofReal + (ae_of_all _ (fun _=>ENNReal.ofReal_lt_top))] + simp only [ENNReal.toReal_ofReal (gaussianChannelDensity_pos g T _).le,smul_eq_mul, + gaussianChannel_posterior_identity] + rw [integral_const_mul,gaussianChannelLikelihood_integral hT,mul_one] +end SKGap + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Posterior/History.lean b/lean/OAI/Probability/SKGap/Posterior/History.lean new file mode 100644 index 0000000000000000000000000000000000000000..def545c0c50059da9e9a1f01e10aa5f5d53268f0 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Posterior/History.lean @@ -0,0 +1,428 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.DivergenceIntegrand + +namespace OAI + +namespace SKGap.GaussianHistory +open MeasureTheory ProbabilityTheory Real Set Filter +open scoped BigOperators ENNReal NNReal +open GaussianStep +noncomputable section +variable {n : ℕ} + +abbrev History (n : ℕ) : ℕ → Type + | 0 => Unit + | k+1 => History n k × (Fin n → ℝ) + +@[reducible] instance historyMeasurable (n : ℕ) : (k : ℕ) → MeasurableSpace (History n k) + | 0 => inferInstanceAs (MeasurableSpace Unit) + | k+1 => by + change MeasurableSpace (History n k × (Fin n → ℝ)) + letI := historyMeasurable n k + infer_instance + +@[reducible] instance historyTopology (n : ℕ) : (k : ℕ) → TopologicalSpace (History n k) + | 0 => inferInstanceAs (TopologicalSpace Unit) + | k+1 => by + change TopologicalSpace (History n k × (Fin n → ℝ)) + letI := historyTopology n k + infer_instance + +instance historySecondCountable (n : ℕ) : (k : ℕ) → SecondCountableTopology (History n k) + | 0 => inferInstanceAs (SecondCountableTopology Unit) + | k+1 => by + change SecondCountableTopology (History n k × (Fin n → ℝ)) + let := historySecondCountable n k + infer_instance + +instance historyBorel (n : ℕ) : (k : ℕ) → BorelSpace (History n k) + | 0 => inferInstanceAs (BorelSpace Unit) + | k+1 => by + change BorelSpace (History n k × (Fin n → ℝ)) + let := historyBorel n k + infer_instance + +def reference (n : ℕ) : (k : ℕ) → Measure (History n k) + | 0 => Measure.dirac () + | k+1 => (reference n k).prod (GaussianStep.reference n) + +instance reference_probability (n : ℕ) : (k : ℕ) → IsProbabilityMeasure (reference n k) + | 0 => inferInstanceAs (IsProbabilityMeasure (Measure.dirac ())) + | k+1 => by + change IsProbabilityMeasure ((reference n k).prod (GaussianStep.reference n)) + let := reference_probability n k + infer_instance + +def likelihood (t : ℝ) (x : Spin n) : {k : ℕ} → History n k → ℝ + | 0, _ => 1 + | _+1, h => likelihood t x h.1 * GaussianStep.likelihood t x h.2 + +lemma likelihood_pos (t : ℝ) (x : Spin n) : ∀ {k : ℕ} (h : History n k), + 0 < likelihood t x h + | 0, _ => zero_lt_one + | _+1, h => mul_pos (likelihood_pos t x h.1) (GaussianStep.likelihood_pos t x h.2) + +lemma continuous_likelihood (t : ℝ) (x : Spin n) : ∀ k, + Continuous (likelihood t x (k := k)) + | 0 => continuous_const + | k+1 => (continuous_likelihood t x k).comp continuous_fst |>.mul + ((GaussianStep.continuous_likelihood t x).comp continuous_snd) + +lemma integrable_likelihood (t : ℝ) (x : Spin n) : ∀ k, + Integrable (likelihood t x (k := k)) (reference n k) + | 0 => by + change Integrable (fun _ : Unit => (1:ℝ)) (Measure.dirac ()) + exact integrable_const 1 + | k+1 => (integrable_likelihood t x k).mul_prod (GaussianStep.integrable_likelihood t x) + +lemma integral_likelihood {t : ℝ} (ht : 0 ≤ t) (x : Spin n) : ∀ k, + (∫ h : History n k, likelihood t x h ∂reference n k) = 1 + | 0 => by + change (∫ _ : Unit, (1:ℝ) ∂Measure.dirac ()) = 1 + rw [integral_dirac] + | k+1 => by + change (∫ h, likelihood t x h.1 * GaussianStep.likelihood t x h.2 + ∂(reference n k).prod (GaussianStep.reference n)) = 1 + rw [integral_prod_mul, integral_likelihood ht x k, GaussianStep.integral_likelihood ht, mul_one] + +def density (p : Prior n) (t : ℝ) {k : ℕ} (h : History n k) : ℝ := + ∑ x, p x*likelihood t x h + +lemma density_pos (p : Prior n) (t : ℝ) {k : ℕ} (h : History n k) : + 0 < density p t h := by + have he : ∃ x, 0 < p x := by + by_contra hn + push Not at hn + have hz : ∑ x, p x = 0 := Finset.sum_eq_zero (fun x _ => le_antisymm (hn x) (p.nonneg x)) + linarith [p.sum_one] + obtain ⟨x,hx⟩ := he + exact Finset.sum_pos' (fun y _ => mul_nonneg (p.nonneg y) (likelihood_pos t y h).le) + ⟨x, Finset.mem_univ _, mul_pos hx (likelihood_pos t x h)⟩ + +lemma continuous_density (p : Prior n) (t : ℝ) (k : ℕ) : Continuous (density p t (k := k)) := + continuous_finsetSum _ (fun x _ => (continuous_likelihood t x k).const_mul (p x)) + +lemma integrable_density (p : Prior n) (t : ℝ) (k : ℕ) : + Integrable (density p t (k := k)) (reference n k) := + integrable_finsetSum _ (fun x _ => (integrable_likelihood t x k).const_mul (p x)) + +lemma integral_density (p : Prior n) {t : ℝ} (ht : 0 ≤ t) (k : ℕ) : + (∫ h : History n k, density p t h ∂reference n k) = 1 := by + unfold density + rw [integral_finsetSum _ (fun x _ => (integrable_likelihood t x k).const_mul (p x))] + simp_rw [integral_const_mul, integral_likelihood ht, mul_one] + exact p.sum_one + +def posterior (p : Prior n) (t : ℝ) {k : ℕ} (h : History n k) : Prior n where + mass x := p x*likelihood t x h/density p t h + nonneg x := div_nonneg (mul_nonneg (p.nonneg x) (likelihood_pos t x h).le) (density_pos p t h).le + sum_one := by rw [← Finset.sum_div]; exact div_self (density_pos p t h).ne' + +lemma density_zero (p : Prior n) (t : ℝ) (h : History n 0) : density p t h=1 := by + simp only [density, likelihood, mul_one, p.sum_one] + +lemma posterior_zero (p : Prior n) (t : ℝ) (h : History n 0) : posterior p t h=p := by + apply Prior.ext + funext x + change p x*1/density p t h=p x + rw [density_zero, mul_one, div_one] + +lemma density_succ (p : Prior n) (t : ℝ) {k : ℕ} (h : History n k) (z : Fin n → ℝ) : + density p t (k := k+1) (h,z) = density p t h*GaussianStep.density (posterior p t h) t z := by + change (∑ x, p x*(likelihood t x h*GaussianStep.likelihood t x z)) = + density p t h*(∑ x, (p x*likelihood t x h/density p t h)*GaussianStep.likelihood t x z) + rw [Finset.mul_sum] + apply Finset.sum_congr rfl + intro x _ + field_simp [(density_pos p t h).ne'] + +lemma posterior_succ (p : Prior n) (t : ℝ) {k : ℕ} (h : History n k) (z : Fin n → ℝ) : + posterior p t (k := k+1) (h,z) = GaussianStep.posterior (posterior p t h) t z := by + apply Prior.ext + funext x + change p x*(likelihood t x h*GaussianStep.likelihood t x z)/density p t (k := k+1) (h,z) = + (p x*likelihood t x h/density p t h)*GaussianStep.likelihood t x z / + GaussianStep.density (posterior p t h) t z + rw [density_succ] + field_simp [(density_pos p t h).ne', (GaussianStep.density_pos (posterior p t h) t z).ne'] + +lemma posterior_avg_weight (p : Prior n) (t : ℝ) {k : ℕ} (h : History n k) (f : Spin n → ℝ) : + density p t h*avg (posterior p t h) f=∑ x, p x*likelihood t x h*f x := by + simp only [avg, posterior, Finset.mul_sum] + apply Finset.sum_congr rfl + intro x _ + field_simp [(density_pos p t h).ne'] + +lemma integrable_posterior_avg_weight (p : Prior n) (t : ℝ) (f : Spin n → ℝ) (k : ℕ) : + Integrable (fun h : History n k => density p t h*avg (posterior p t h) f) (reference n k) := by + simp_rw [posterior_avg_weight] + exact integrable_finsetSum _ (fun x _ => ((integrable_likelihood t x k).const_mul (p x)).mul_const (f x)) + +lemma integral_posterior_avg_weight (p : Prior n) {t : ℝ} (ht : 0 ≤ t) (f : Spin n → ℝ) (k : ℕ) : + (∫ h : History n k, density p t h*avg (posterior p t h) f ∂reference n k)=avg p f := by + simp_rw [posterior_avg_weight] + rw [integral_finsetSum _ (fun x _ => ((integrable_likelihood t x k).const_mul (p x)).mul_const (f x))] + simp_rw [integral_mul_const, integral_const_mul, integral_likelihood ht, mul_one] + rfl + +lemma density_le (p q : Prior n) {B : ℝ} (hB : ∀x, q x ≤ B*p x) + (t : ℝ) {k : ℕ} (h : History n k) : density q t h ≤ B*density p t h := by + unfold density + rw [Finset.mul_sum] + exact Finset.sum_le_sum (fun x _ => by + simpa only [mul_assoc] using mul_le_mul_of_nonneg_right (hB x) (likelihood_pos t x h).le) + +lemma exists_domination (p q : Prior n) (hp : ∀x,0

hnonneg x),?_⟩ + intro x + have hle : q x/p x ≤ B := Finset.single_le_sum (fun y _ => hnonneg y) (Finset.mem_univ x) + exact (div_le_iff₀ (hp x)).mp hle + +def relativeEntropyIntegrand (p q : Prior n) (t : ℝ) {k : ℕ} (h : History n k) : ℝ := + density q t h*log (density q t h/density p t h) + +def divergenceIntegrand (p q : Prior n) (t : ℝ) {k : ℕ} (h : History n k) : ℝ := + relativeEntropyIntegrand p q t h-density q t h+density p t h + +lemma divergenceIntegrand_eq (p q : Prior n) (t : ℝ) {k : ℕ} (h : History n k) : + divergenceIntegrand p q t h = density p t h* + ((density q t h/density p t h)*log (density q t h/density p t h)- + density q t h/density p t h+1) := by + unfold divergenceIntegrand relativeEntropyIntegrand + field_simp [(density_pos p t h).ne'] + +lemma divergenceIntegrand_nonneg (p q : Prior n) (t : ℝ) {k : ℕ} (h : History n k) : + 0≤divergenceIntegrand p q t h := by + rw [divergenceIntegrand_eq] + exact mul_nonneg (density_pos p t h).le + (scalar_entropy_nonneg (div_pos (density_pos q t h) (density_pos p t h))) + +lemma continuous_log_ratio (p q : Prior n) (t : ℝ) (k : ℕ) : + Continuous (fun h : History n k => log (density q t h/density p t h)) := + ((continuous_density q t k).div (continuous_density p t k) + (fun h => (density_pos p t h).ne')).log + (fun h => (div_pos (density_pos q t h) (density_pos p t h)).ne') + +lemma continuous_relativeEntropyIntegrand (p q : Prior n) (t : ℝ) (k : ℕ) : + Continuous (relativeEntropyIntegrand p q t (k := k)) := + (continuous_density q t k).mul (continuous_log_ratio p q t k) + +lemma continuous_divergenceIntegrand (p q : Prior n) (t : ℝ) (k : ℕ) : + Continuous (divergenceIntegrand p q t (k := k)) := + ((continuous_relativeEntropyIntegrand p q t k).sub (continuous_density q t k)).add + (continuous_density p t k) + +lemma integrable_divergenceIntegrand (p q : Prior n) (hp : ∀x,0

density p t h*F h) (reference n k)) : + Integrable (fun h : History n (k+1) => density p t h*F h.1) (reference n (k+1)) := by + change Integrable (fun h : History n k × (Fin n → ℝ) => density p t (k := k+1) h*F h.1) + ((reference n k).prod (GaussianStep.reference n)) + apply (integrable_prod_iff (((continuous_density p t (k+1)).measurable.mul + (hF.comp measurable_fst)).aestronglyMeasurable)).mpr + constructor + · filter_upwards [] with h + change Integrable (fun z => density p t (k := k+1) (h,z)*F h) (GaussianStep.reference n) + simp_rw [density_succ] + have he : (fun z => density p t h*GaussianStep.density (posterior p t h) t z*F h) = + fun z => (density p t h*F h)*GaussianStep.density (posterior p t h) t z := by + funext z; ring + rw [he] + exact (GaussianStep.integrable_density (posterior p t h) t).const_mul _ + · have he (h : History n k) : + (∫z, ‖density p t (k := k+1) (h,z)*F h‖ ∂GaussianStep.reference n) = ‖density p t h*F h‖ := by + simp_rw [density_succ,Real.norm_eq_abs,abs_mul,abs_of_pos (density_pos p t h), + abs_of_pos (GaussianStep.density_pos (posterior p t h) t _)] + rw [integral_mul_const,integral_const_mul,GaussianStep.integral_density _ ht] + ring + change Integrable (fun h : History n k => + ∫z, ‖density p t (k := k+1) (h,z)*F h‖ ∂GaussianStep.reference n) (reference n k) + simp_rw [he] + exact hi.norm + +lemma integral_lift (p : Prior n) {t : ℝ} (ht : 0≤t) {k : ℕ} (F : History n k → ℝ) + (hF : Measurable F) (hi : Integrable (fun h => density p t h*F h) (reference n k)) : + (∫h:History n (k+1),density p t h*F h.1 ∂reference n (k+1)) = + ∫h:History n k,density p t h*F h ∂reference n k := by + rw [show reference n (k+1)=(reference n k).prod (GaussianStep.reference n) from rfl, + integral_prod _ (integrable_lift p ht F hF hi)] + apply integral_congr_ae + filter_upwards [] with h + simp_rw [density_succ] + rw [integral_mul_const,integral_const_mul,GaussianStep.integral_density _ ht,mul_one] + +lemma relativeEntropy_succ (p q : Prior n) (t : ℝ) {k : ℕ} (h : History n k) (z : Fin n → ℝ) : + relativeEntropyIntegrand p q t (k := k+1) (h,z) = + density q t (k := k+1) (h,z)*log (density q t h/density p t h)+ + density q t h*(GaussianStep.density (posterior q t h) t z * + log (GaussianStep.density (posterior q t h) t z/GaussianStep.density (posterior p t h) t z)) := by + unfold relativeEntropyIntegrand + rw [density_succ,density_succ] + rw [mul_div_mul_comm,log_mul + (div_pos (density_pos q t h) (density_pos p t h)).ne' + (div_pos (GaussianStep.density_pos (posterior q t h) t z) + (GaussianStep.density_pos (posterior p t h) t z)).ne'] + ring + +theorem entropy_succ (p q : Prior n) (hp : ∀x,0

log (density q t h/density p t h) + have hL : Measurable L := (continuous_log_ratio p q t k).measurable + have hiL : Integrable (fun h => density q t h*L h) (reference n k) := + integrable_relativeEntropyIntegrand p q hp t k + have hLift := integrable_lift q ht L hL hiL + have hi := (integrable_relativeEntropyIntegrand p q hp t (k+1)).sub hLift + have he : (fun hz : History n (k+1) => relativeEntropyIntegrand p q t hz - density q t hz*L hz.1) = + fun hz => density q t hz.1*(GaussianStep.density (posterior q t hz.1) t hz.2* + log (GaussianStep.density (posterior q t hz.1) t hz.2/GaussianStep.density (posterior p t hz.1) t hz.2)) := by + funext ⟨h,z⟩ + rw [relativeEntropy_succ] + dsimp [L] + ring + have hs := integral_sub (integrable_relativeEntropyIntegrand p q hp t (k+1)) hLift + change (∫hz:History n (k+1),relativeEntropyIntegrand p q t hz-density q t hz*L hz.1 + ∂reference n (k+1)) = _ at hs + rw [integral_lift q ht L hL hiL] at hs + change (∫hz:History n (k+1),relativeEntropyIntegrand p q t hz-density q t hz*L hz.1 + ∂reference n (k+1)) = entropy p q t (k+1)-entropy p q t k at hs + change Integrable (fun hz : History n (k+1) => relativeEntropyIntegrand p q t hz- + density q t hz*L hz.1) (reference n (k+1)) at hi + rw [he] at hi hs + rw [show reference n (k+1)=(reference n k).prod (GaussianStep.reference n) from rfl, + integral_prod _ hi] at hs + simp_rw [integral_const_mul,GaussianStep.integral_relativeEntropy _ _ ht] at hs + linarith + +def law (p : Prior n) (t : ℝ) (k : ℕ) : Measure (History n k) := + (reference n k).withDensity (fun h => ENNReal.ofReal (density p t h)) + +lemma law_probability (p : Prior n) {t : ℝ} (ht : 0≤t) (k : ℕ) : + IsProbabilityMeasure (law p t k) := by + constructor + rw [law,withDensity_apply _ MeasurableSet.univ,Measure.restrict_univ, + ←ofReal_integral_eq_lintegral_ofReal (integrable_density p t k) + (ae_of_all _ (fun h => (density_pos p t h).le)),integral_density p ht,ENNReal.ofReal_one] + +lemma integral_law (p : Prior n) (t : ℝ) {k : ℕ} (F : History n k → ℝ) : + (∫h,F h ∂law p t k) = ∫h,density p t h*F h ∂reference n k := by + rw [law,integral_withDensity_eq_integral_toReal_smul + ((continuous_density p t k).measurable.ennreal_ofReal) + (ae_of_all _ (fun _ => ENNReal.ofReal_lt_top))] + simp only [ENNReal.toReal_ofReal (density_pos p t _).le,smul_eq_mul] + +lemma integrable_law_iff (p : Prior n) (t : ℝ) {k : ℕ} (F : History n k → ℝ) : + Integrable F (law p t k) ↔ Integrable (fun h => density p t h*F h) (reference n k) := by + rw [law,integrable_withDensity_iff_integrable_smul' + ((continuous_density p t k).measurable.ennreal_ofReal) + (ae_of_all _ (fun _ => ENNReal.ofReal_lt_top))] + simp only [ENNReal.toReal_ofReal (density_pos p t _).le,smul_eq_mul] + +def eventProbability (p : Prior n) (t : ℝ) {k : ℕ} (E : Set (History n k)) : ℝ := + ∫h in E,density p t h ∂reference n k + +lemma eventProbability_nonneg (p : Prior n) (t : ℝ) {k : ℕ} (E : Set (History n k)) : + 0≤eventProbability p t E := integral_nonneg (fun h => (density_pos p t h).le) + +lemma eventProbability_eq (p : Prior n) (t : ℝ) {k : ℕ} (E : Set (History n k)) + (hE : MeasurableSet E) : ENNReal.ofReal (eventProbability p t E)=law p t k E := by + rw [eventProbability,law,withDensity_apply _ hE] + exact ofReal_integral_eq_lintegral_ofReal (integrable_density p t k).integrableOn + (ae_of_all _ (fun h => (density_pos p t h).le)) + +lemma scalar_entropy_fenchel {r : ℝ} (hr : 0(H.2.2.1 w hl hw).trans hW, + fun w hl hw=>(H.2.2.2 w hl hw).trans hC⟩ + +lemma started_replace_shapes {n M N : ℕ} {j K A₀ A c B B' W C W' C' : ℝ} + {J : Interaction n} (H : StartedMatrixEvent j K A₀ A c B W C M N J) + (hf : ∀h x l,l(ht.1 w hl hi hw).trans hW,fun w hl hi hw=>(ht.2 w hl hi hw).trans hC⟩ + +def PosteriorCovarianceProperty {n : ℕ} (j Aroot ε c r₀ D : ℝ) (g : Disorder n) : Prop := + ∀h:Fin n→ℝ,¬rootBad j Aroot ε c r₀ (coupling g) h→∀f:Observables n, + vectorNorm (centeredSpinCovariance (fieldGibbs (coupling g) h) f)≤ + D*sqrt ((∑x,fieldGibbs (coupling g) h x*(f x-∑y,fieldGibbs (coupling g) h y*f y)^2)+ + varianceEnergy (fieldGibbs (coupling g) h) f) + +theorem quenched_posterior_covariance {β Aroot ε c r₀ : ℝ} + (hβ : 0<β) (hβ1 : β<1) (hAroot : 1PosteriorCovarianceProperty (n := n) (β^2) Aroot ε c r₀ D g) := by + classical + let j:=β^2 + let K:=physicalNormBound j + let R:=2*log Aroot + have hj : 0≤j:=sq_nonneg β + have hK : 0≤K:=(physicalNormBound_pos j).le + have hR : 0StartedMatrixEvent j K Aroot (max Aroot (A k)) (c/2) + Bk Wk Ck (k+3) (2+2*(k+1)) (coupling g)) := by + intro k + exact disorder_started_matrix_event hβ hβ1 (by linarith) (by simpa only [sqrt_sq hβ.le] using hs) + (le_max_left _ _) ((hA k).trans (le_max_right _ _)) (half_pos hc) _ _ + choose Bk Wk Ck hBk hWk hCk hpk using hex + let W':=W+∑k:Fin r,Wk k + let C':=C+∑k:Fin r,Ck k + have hW' : W≤W':=le_add_of_nonneg_right (Finset.sum_nonneg (fun k _=>hWk k)) + have hC' : C≤C':=le_add_of_nonneg_right (Finset.sum_nonneg (fun k _=>(hCk k).le)) + have hwk (k:Fin r) : Wk k≤W':=by + have hsum:=Finset.single_le_sum (fun k _=>hWk k) (Finset.mem_univ k) + dsimp [W'] + linarith + have hck (k:Fin r) : Ck k≤C':=by + have hsum:=Finset.single_le_sum (fun k _=>(hCk k).le) (Finset.mem_univ k) + dsimp [C'] + linarith + let P : ∀n,Disorder n→Prop:=fun n g=> + RecipeMatrixEvent j K (residualCoefficientBudget j 2 (2*m) 0) B W C (2*m+1) (2*(2*m)) (coupling g) ∧ + ∀k:Fin r,StartedMatrixEvent j K Aroot (max Aroot (A k)) (c/2) (Bk k) (Wk k) (Ck k) + (k+3) (2+2*(k+1)) (coupling g) + have hP : Whp β P:=by + have hh:=whp_finset Finset.univ + (fun (k:Fin r) n g=>StartedMatrixEvent j K Aroot (max Aroot (A k)) (c/2) (Bk k) (Wk k) (Ck k) + (k+3) (2+2*(k+1)) (coupling g)) (fun k _=>hpk k) + simpa only [Finset.mem_univ,forall_true_left] using (show Whp β _ from hevent).and hh + let Dim (n:ℕ) : Prop:=∀kρ*sqrt (n:ℝ)) atTop atTop:= + (tendsto_sqrt_atTop.comp tendsto_natCast_atTop_atTop).const_mul_atTop hρ + have hh : ∀k:Fin r,∀ᶠ n:ℕ in atTop,4*(residualDerivativeBudget j K B k+residualDerivativeBudget j K B (k+1))≤ρ*sqrt (n:ℝ):= + fun k=>ht.eventually_ge_atTop _ + have hh':=Filter.eventually_all.mpr hh + filter_upwards [hh'] with n hn + exact fun k hk=>hn ⟨k,hk⟩ + let Ω:Type:={a:Σn,Disorder n × (Fin n→ℝ) // 0a.1.1) (fun a=>coupling a.1.2.1) (fun a=>a.1.2.2) + (fun a=>a.2.1) (fun a=>by ext i k;exact coupling_symm a.1.2.1 k i) + (fun a=>coupling_diag a.1.2.1) + (fun a k hk=>by + have ht:=(a.2.2.1.2 ⟨k,hk⟩).mono_budget (le_max_right Aroot (A k)) + have ht' : StartedMatrixEvent j K (exp (R/2)) (A k) (c/2) (Bk ⟨k,hk⟩) (Wk ⟨k,hk⟩) (Ck ⟨k,hk⟩) (k+3) (2+2*(k+1)) (coupling a.1.2.1) := by + simpa only [hAR] using ht + apply started_replace_shapes ht' _ (hwk ⟨k,hk⟩) (hck ⟨k,hk⟩) + intro h x l hl + exact a.2.2.1.1.2.1 h x l (by omega)) + (fun a=>recipe_increase_diagnostics a.2.2.1.1 hW' hC') + (fun a=>a.2.2.2.1) (fun a=>a.2.2.2.2) + refine ⟨D,hD,hP.mono ?_⟩ + filter_upwards [eventually_ge_atTop 1,hDim] with n hn hd + intro g hg h hb f + apply hDall ⟨⟨n,g,h⟩,?_⟩ f + exact ⟨show 0conditionalVariance p.mass x i*(SKGapCutoff.halfDiff i f x)^2)=_ + rw [avg_flip p i,avg_flip p i] + congr 1 + apply Finset.sum_congr rfl + intro x _ + rw [conditionalVariance_eq p x i hp,conditionalVariance_eq p (SKGap.flip i x) i hp, + halfDiff_sq,halfDiff_sq,SKGap.flip_flip,cond_flip] + unfold GaussianStep.cond + rw [add_comm (p (SKGap.flip i x)) (p x)] + field_simp [(add_pos (hp x) (hp (SKGap.flip i x))).ne'] + ring + +lemma fieldGibbs_prior (g : Disorder n) (h : Fin n→ℝ) : + SKGapCutoff.fieldGibbs (coupling g) h=(gibbsPrior g h).mass := + SKGapCutoff.fieldGibbs_edge g h + +lemma covariance_square_bound {j Aroot ε c r₀ D : ℝ} {g : Disorder n} + (hD : 0≤D) (H : PosteriorCovarianceProperty j Aroot ε c r₀ D g) + (h : Fin n→ℝ) (hb : ¬rootBad j Aroot ε c r₀ (coupling g) h) (f : Spin n→ℝ) : + (∑i,(∑x,gibbsPrior g h x*(f x-avg (gibbsPrior g h) f)*spinValue (x i))^2)≤ + D^2*(var (gibbsPrior g h) f+energy (gibbsPrior g h) f) := by + have hh:=H h hb f + rw [fieldGibbs_prior,varianceEnergy_eq _ (mass_pos g h)] at hh + change SKGapCutoff.Recipe.vectorNorm (centeredSpinCovariance (gibbsPrior g h).mass f) ≤ + D*sqrt (var (gibbsPrior g h) f+energy (gibbsPrior g h) f) at hh + have hs:=(sq_le_sq₀ (SKGapCutoff.Recipe.vectorNorm_nonneg _) + (mul_nonneg hD (Real.sqrt_nonneg _))).2 hh + rw [mul_pow,Real.sq_sqrt (add_nonneg (GaussianStep.var_nonneg _ _) (energy_nonneg _ _)), + SKGapCutoff.Recipe.vectorNorm_sq] at hs + exact hs + +lemma squareMean_eq (p : Prior n) (f : Spin n→ℝ) (hf : 0(f x)^2)) : + squareMean p.mass f=mean (squarePrior p f hf) := rfl + +lemma squareMean_one (p : Prior n) : squareMean p.mass (fun _=>1)=mean p := by + ext i + simp only [squareMean,squareMass,one_pow,mul_one,p.sum_one,div_one,mean] + rfl + +lemma energy_one (p : Prior n) (hp : ∀x,0

1)=0 := by + apply Finset.sum_eq_zero + intro i _ + apply Finset.sum_eq_zero + intro x _ + have hh : GaussianStep.cond p i (fun _=>1) x=1 := by + simp [GaussianStep.cond,div_self (add_pos (hp x) (hp (SKGap.flip i x))).ne'] + simp only [hh,sub_self,zero_pow (by decide : 2≠0),mul_zero] + +lemma stable_mean_difference {j Aroot ε c r₀ ρ C₀ C : ℝ} {g : Disorder n} + (hn : 0(f x)^2)) : + SKGapCutoff.Recipe.vectorNorm (mean (squarePrior (gibbsPrior g h) f hf)-mean (gibbsPrior g h))≤ + 2*C₀*ρ*sqrt (n:ℝ)+C*(2+energy (gibbsPrior g h) f/avg (gibbsPrior g h) (fun x=>(f x)^2)) := by + obtain ⟨r,hr,hu,hall⟩:=stableSquareMeanProperty_rootBad hAroot (coupling g) H h hb + rw [fieldGibbs_prior] at hall + have h1:=hall f hf + have h0:=hall (fun _=>1) (by simp only [one_pow,mul_one,(gibbsPrior g h).sum_one];norm_num) + rw [varianceEnergy_eq _ (mass_pos g h),squareMean_eq _ _ hf] at h1 + rw [varianceEnergy_eq _ (mass_pos g h),energy_one _ (mass_pos g h),squareMean_one] at h0 + have hs : 0(f x)^2)))*sqrt (n:ℝ)+ + (C₀*ρ+C/sqrt (n:ℝ)*(1+0/(∑x,gibbsPrior g h x*(1:ℝ)^2)))*sqrt (n:ℝ) := add_le_add h1' h0' + _=_ := by field_simp;ring + +lemma drift_square_of_stable_mean {j Aroot ε c r₀ ρ C₀ C : ℝ} {g : Disorder n} + (hn : 0(f x)^2)) : + (∑i,(mean (squarePrior (gibbsPrior g h) f hf) i-mean (gibbsPrior g h) i)^2)≤ + (4*C₀*ρ)*(n:ℝ)+(2*C)*sqrt (n:ℝ)*(2+energy (gibbsPrior g h) f/avg (gibbsPrior g h) (fun x=>(f x)^2)) := by + let v:=mean (squarePrior (gibbsPrior g h) f hf)-mean (gibbsPrior g h) + have hm:=stable_mean_difference hn hAroot H h hb f hf + have hu : SKGapCutoff.Recipe.vectorNorm v≤2*sqrt (n:ℝ) := by + apply nonneg_le_nonneg_of_sq_le_sq (by positivity) + simp only [←sq] + rw [SKGapCutoff.Recipe.vectorNorm_sq,mul_pow,sq_sqrt (Nat.cast_nonneg n)] + simpa only [v,Pi.sub_apply,show (2:ℝ)^2=4 by norm_num] using + GaussianHistory.mean_difference_square_le (gibbsPrior g h) (squarePrior (gibbsPrior g h) f hf) + have hh:=mul_le_mul hm hu (SKGapCutoff.Recipe.vectorNorm_nonneg v) ((SKGapCutoff.Recipe.vectorNorm_nonneg v).trans hm) + have he : (2*C₀*ρ*sqrt (n:ℝ)+C*(2+energy (gibbsPrior g h) f/avg (gibbsPrior g h) (fun x=>(f x)^2)))*(2*sqrt (n:ℝ))= + (4*C₀*ρ)*(n:ℝ)+(2*C)*sqrt (n:ℝ)*(2+energy (gibbsPrior g h) f/avg (gibbsPrior g h) (fun x=>(f x)^2)) := by + calc + _=(4*C₀*ρ)*(sqrt (n:ℝ))^2+(2*C)*sqrt (n:ℝ)*(2+energy (gibbsPrior g h) f/avg (gibbsPrior g h) (fun x=>(f x)^2)) := by ring + _=_ := by rw [sq_sqrt (Nat.cast_nonneg n)] + rw [←sq,SKGapCutoff.Recipe.vectorNorm_sq,he] at hh + exact hh + +end +end SKGap.FullMain + +namespace SKGap.FullMain +open MeasureTheory ProbabilityTheory Filter Real Set +open scoped Topology BigOperators ENNReal +open GaussianStep GaussianHistory ObservationBridge +noncomputable section +variable {n : ℕ} +local instance : MeasurableSpace (Matrix (Fin n) (Fin n) ℝ) := borel _ +local instance : BorelSpace (Matrix (Fin n) (Fin n) ℝ) := ⟨rfl⟩ + +lemma gaussianChannelLaw_step (g : Disorder n) (t : ℝ) : + gaussianChannelLaw g t=(GaussianStep.reference n).withDensity + (fun z=>ENNReal.ofReal (GaussianStep.density (gibbsPrior g 0) t z)) := by + have hd : gaussianChannelDensity g t=fun z=>GaussianStep.density (gibbsPrior g 0) t z := by + funext z + apply Finset.sum_congr rfl + intro x _ + change mass g 0 x*exp ((∑i,sqrt t*spinValue (x i)*z i)-(n:ℝ)*t/2)= + mass g 0 x*exp (sqrt t*(∑i,spinValue (x i)*z i)-t*(n:ℝ)/2) + congr 2 + simp only [Finset.mul_sum,←mul_assoc,mul_comm (n:ℝ) t] + change (GaussianStep.reference n).withDensity (fun z=>ENNReal.ofReal (gaussianChannelDensity g t z))=_ + rw [hd] + +lemma history_field_event (g : Disorder n) {t : ℝ} (ht : 0≤t) (k : ℕ) + (E : Set (Fin n→ℝ)) (hE : MeasurableSet E) : + eventProbability (gibbsPrior g 0) t ((GaussianHistory.field t) ⁻¹' E : Set (History n k))= + (gaussianChannelLaw g ((k:ℝ)*t)).real + ((fun z : Fin n→ℝ=>fun i=>sqrt ((k:ℝ)*t)*z i) ⁻¹' E) := by + have hh:=eventProbability_eq (gibbsPrior g 0) t + ((GaussianHistory.field t) ⁻¹' E : Set (History n k)) + (hE.preimage (continuous_field t k).measurable) + rw [←Measure.map_apply (continuous_field t k).measurable hE, + field_law _ ht k,←gaussianChannelLaw_step, + Measure.map_apply (by fun_prop) hE] at hh + simpa only [ENNReal.toReal_ofReal (eventProbability_nonneg _ _ _),Measure.real] using + congrArg ENNReal.toReal hh + +lemma measurable_rootFields (g : Disorder n) (j A ε c ρ : ℝ) : + MeasurableSet {h:Fin n→ℝ | rootBad j A ε c ρ (coupling g) h} := by + have hm : Measurable (fun h => (coupling g,h) : Field n → Matrix (Fin n) (Fin n) ℝ × Field n) := + measurable_const.prodMk measurable_id + change MeasurableSet ((fun h => (coupling g,h) : Field n → Matrix (Fin n) (Fin n) ℝ × Field n) ⁻¹' + {p : Matrix (Fin n) (Fin n) ℝ × Field n | rootBad j A ε c ρ p.1 p.2}) + exact (measurableSet_rootBad (n:=n) j A ε c ρ).preimage hm + +lemma history_root_probability (g : Disorder n) {t : ℝ} (ht : 0≤t) (k : ℕ) + (j A K ε c ρ : ℝ) (hop : operatorBound K (coupling g)) : + eventProbability (gibbsPrior g 0) t + {h:History n k | rootBad j A ε c ρ (coupling g) (GaussianHistory.field t h)}= + fixedTimeFailure n j A K ε c ρ ((k:ℝ)*t) g := by + let T:=(k:ℝ)*t + have hT : 0≤T:=mul_nonneg (Nat.cast_nonneg k) ht + let E:Set (Fin n→ℝ):={h | rootBad j A ε c ρ (coupling g) h} + have hE : MeasurableSet E:=measurable_rootFields g j A ε c ρ + change eventProbability (gibbsPrior g 0) t ((GaussianHistory.field t) ⁻¹' E : Set (History n k))=_ + rw [history_field_event g ht k E hE,Measure.real,gaussianChannel_event _ hT _ + (hE.preimage (by fun_prop))] + change (∑x,ENNReal.ofReal (mass g 0 x)*_).toReal=(fixedTimeFailureENN j A K ε c ρ T g).toReal + congr 1 + apply Finset.sum_congr rfl + intro x _ + congr 1 + unfold conditionalSpinFailure + have hGB : MeasurableSet ((Prod.mk g) ⁻¹' gibbsObservationBad j A K ε c ρ T x) := + (measurableSet_gibbsObservationBad j A K ε c ρ T x).preimage + (show Measurable (Prod.mk g : Field n→Disorder n × Field n) from measurable_const.prodMk measurable_id) + rw [←GaussianHistory.map_scaled_reference hT,Measure.map_apply (by fun_prop) hGB] + congr 1 + ext z + change rootBad j A ε c ρ (coupling g) (fun i=>sqrt T*(z i+sqrt T*spinValue (x i))) ↔ + operatorBound K (coupling g) ∧ rootBad j A ε c ρ (coupling g) (fun i=>T*spinValue (x i)+sqrt T*z i) + have he : (fun i=>sqrt T*(z i+sqrt T*spinValue (x i)))=(fun i=>T*spinValue (x i)+sqrt T*z i) := by + funext i + calc + _=(sqrt T)^2*spinValue (x i)+sqrt T*z i:=by ring + _=_:=by rw [sq_sqrt hT] + rw [he] + simp only [hop,true_and] + +lemma history_terminal_probability (g : Disorder n) {t : ℝ} (ht : 0≤t) (k : ℕ) : + eventProbability (gibbsPrior g 0) t + {h:History n k | ¬∀f:Spin n→ℝ, + variance g (GaussianHistory.field t h) f≤2*dirichlet g (GaussianHistory.field t h) f}= + (gaussianChannelLaw g ((k:ℝ)*t)).real + {z | ¬∀f:Spin n→ℝ,variance g (fun i=>sqrt ((k:ℝ)*t)*z i) f≤ + 2*dirichlet g (fun i=>sqrt ((k:ℝ)*t)*z i) f} := by + exact history_field_event g ht k _ (terminal_goodSet_closed g 2).measurableSet.compl + +end +end SKGap.FullMain + +end OAI diff --git a/lean/OAI/Probability/SKGap/Stability/ClosedOrdinaryBridge.lean b/lean/OAI/Probability/SKGap/Stability/ClosedOrdinaryBridge.lean new file mode 100644 index 0000000000000000000000000000000000000000..e774626431e7422f43b828cd68234981eed887b5 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Stability/ClosedOrdinaryBridge.lean @@ -0,0 +1,97 @@ +import Mathlib +import OAI.Probability.SKGap.Matrix.PrimaryWordControl +import OAI.Probability.SKGap.Localization.ClosedMarkedControl + +namespace OAI + +section + +noncomputable section +open scoped BigOperators +namespace SKGap.Noncrossing.ClosedMarked +open SKGapCutoff.Recipe Primary Primary.Tensor.Series +variable {n : ℕ} + +lemma ordinary_mass_bridge (j : ℝ) (t : SourceTree (Fin n→ℝ)) : + Marked.mass (GradedWords.ordinaryWords j t).1=MarkedPolynomial.mass (t.words j).1 ∧ + Marked.mass (GradedWords.ordinaryWords j t).2=MarkedPolynomial.mass (t.words j).2 := by + have happend (p q : GradedWords (Fin n)) : Marked.mass (p++q)=Marked.mass p+Marked.mass q := by simp [Marked.mass] + have hprepend (l : WordLetter (Fin n)) (p : GradedWords (Fin n)) : Marked.mass (GradedWords.prepend l p)=Marked.mass p := by + simp [Marked.mass,GradedWords.prepend,List.map_map,Function.comp_def] + have hbump (p : GradedWords (Fin n)) : Marked.mass (GradedWords.bump p)=Marked.mass p := by + simp [Marked.mass,GradedWords.bump,List.map_map,Function.comp_def] + have hscale (c : ℝ) (p : GradedWords (Fin n)) : Marked.mass (GradedWords.scale c p)=|c| *Marked.mass p := by + induction p with + | nil=>simp [Marked.mass,GradedWords.scale] + | cons t p ih=>simpa [Marked.mass,GradedWords.scale,mul_add,abs_mul] using congrArg (fun r=>|c*t.1|+r) ih + have hprefix (w : OrdinaryWord n) (p : WordPolynomial (ι:=Fin n)) : MarkedPolynomial.mass (prependWords w p)=MarkedPolynomial.mass p := by + simp [MarkedPolynomial.mass,prependWords,List.map_map,Function.comp_def] + have hscale' (c : ℝ) (p : WordPolynomial (ι:=Fin n)) : MarkedPolynomial.mass (scale c p)=|c| *MarkedPolynomial.mass p := by + induction p with + | nil=>simp [MarkedPolynomial.mass,scale] + | cons t p ih=>simpa [MarkedPolynomial.mass,scale,mul_add,abs_mul] using congrArg (fun r=>|c*t.1|+r) ih + have happend' (p q : WordPolynomial (ι:=Fin n)) : MarkedPolynomial.mass (p++q)=MarkedPolynomial.mass p+MarkedPolynomial.mass q := by simp [MarkedPolynomial.mass] + induction t with + | leaf c=>simp [GradedWords.ordinaryWords,GradedWords.scalar,SourceTree.words,Marked.mass,MarkedPolynomial.mass,GradedWords.bump,GradedWords.prepend] + | branch p t u ih1 ih2=> + simp only [GradedWords.ordinaryWords,SourceTree.words,GradedWords.branch,happend,hprepend,hbump,hscale,happend',hprefix,hscale',ih1.1,ih1.2,ih2.1,ih2.2,and_self] +end SKGap.Noncrossing.ClosedMarked + +end +end + +section + +noncomputable section +open scoped BigOperators +namespace SKGap.Noncrossing.ClosedMarked +open SKGapCutoff.Recipe Primary Primary.Tensor.Series +variable {n : ℕ} + +lemma ordinary_word_bridge (j : ℝ) (t : SourceTree (Fin n→ℝ)) : + ((GradedWords.ordinaryWords j t).1.map (fun s=>s.2.2))=((t.words j).1.map (fun s=>liftWord s.2)) ∧ + ((GradedWords.ordinaryWords j t).2.map (fun s=>s.2.2))=((t.words j).2.map (fun s=>liftWord s.2)) := by + have hprefix (l : WordLetter (Fin n)) (P : GradedWords (Fin n)) : + (GradedWords.prepend l P).map (fun s=>s.2.2)=(P.map (fun s=>s.2.2)).map (fun w=>l::w) := by + simp [GradedWords.prepend,List.map_map,Function.comp_def] + have hprefix' (l : Letter (Fin n→ℝ)) (P : WordPolynomial (ι:=Fin n)) : + (prependWords [l] P).map (fun s=>liftWord s.2)=(P.map (fun s=>liftWord s.2)).map (fun w=>l.toWord::w) := by + simp [prependWords,liftWord,List.map_map,Function.comp_def] + have hprefix'' (l m : Letter (Fin n→ℝ)) (P : WordPolynomial (ι:=Fin n)) : + (prependWords [l,m] P).map (fun s=>liftWord s.2)=(P.map (fun s=>liftWord s.2)).map (fun w=>l.toWord::m.toWord::w) := by + simp [prependWords,liftWord,List.map_map,Function.comp_def] + induction t with + | leaf c=>simp [GradedWords.ordinaryWords,GradedWords.scalar,GradedWords.bump,GradedWords.prepend,SourceTree.words,liftWord,Letter.toWord] + | branch p t u ih1 ih2=> + simp only [GradedWords.ordinaryWords,GradedWords.branch,SourceTree.words,List.map_append] + simp only [GradedWords.bump,GradedWords.scale,List.map_map,Function.comp_def] + change ((GradedWords.prepend (.diag p) (GradedWords.ordinaryWords j t).2).map (fun s=>s.2.2)++ + (GradedWords.ordinaryWords j u).1.map (fun s=>s.2.2)=_) ∧ _ + constructor + · rw [hprefix,ih1.2,ih2.1,hprefix'];rfl + · simp only [hprefix,ih1.1,ih1.2,ih2.2,hprefix'',scale,List.map_map,Function.comp_def] + rfl + +lemma ordinary_control_bridge (j : ℝ) (t : SourceTree (Fin n→ℝ)) {A : ℝ} {L : ℕ} + (h : PolynomialControl A L (t.words j).1 ∧ PolynomialControl A L (t.words j).2) : + GradedControl A L (GradedWords.ordinaryWords j t).1 ∧ GradedControl A L (GradedWords.ordinaryWords j t).2 := by + have hb:=ordinary_word_bridge j t + constructor + · intro s hs + have hh : s.2.2∈((GradedWords.ordinaryWords j t).1.map (fun s=>s.2.2)):=List.mem_map.mpr ⟨s,hs,rfl⟩ + rw [hb.1] at hh + obtain ⟨v,hv,he⟩:=List.mem_map.mp hh + rw [←he] + exact ⟨closedWordBounded_lift (h.1 v hv).1,by simpa [liftWord] using (h.1 v hv).2⟩ + · intro s hs + have hh : s.2.2∈((GradedWords.ordinaryWords j t).2.map (fun s=>s.2.2)):=List.mem_map.mpr ⟨s,hs,rfl⟩ + rw [hb.2] at hh + obtain ⟨v,hv,he⟩:=List.mem_map.mp hh + rw [←he] + exact ⟨closedWordBounded_lift (h.2 v hv).1,by simpa [liftWord] using (h.2 v hv).2⟩ +end SKGap.Noncrossing.ClosedMarked + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Stability/ConditionalMean.lean b/lean/OAI/Probability/SKGap/Stability/ConditionalMean.lean new file mode 100644 index 0000000000000000000000000000000000000000..263f2da89c716e6f954d5037a533e6ce4b0ef07c --- /dev/null +++ b/lean/OAI/Probability/SKGap/Stability/ConditionalMean.lean @@ -0,0 +1,425 @@ +import Mathlib +import OAI.Probability.SKGap.Terminal.GibbsExpectation + +namespace OAI + +section +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open scoped BigOperators +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open scoped BigOperators +open scoped BigOperators NNReal ENNReal +open MeasureTheory Metric Set +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators NNReal ENNReal Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Set +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators ENNReal NNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Matrix +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators ENNReal NNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal +open scoped BigOperators +namespace SKGapCutoff.Static + +noncomputable def conditionalMean {n : ℕ} (P : Spin n → ℝ) (x : Spin n) + (i : Fin n) : ℝ := + spin x i * ((P x - P (flip x i)) / (P x + P (flip x i))) + +noncomputable def lawDirichlet {n : ℕ} (P : Spin n → ℝ) (f : Spin n → ℝ) : ℝ := + (∑ i, ∑ x, (P x * P (flip x i) / (P x + P (flip x i))) * + (f x - f (flip x i)) ^ 2) / 2 + +noncomputable def lawDensityEnergy {n : ℕ} (P Q : Spin n → ℝ) : ℝ := + lawDirichlet P (fun x => Real.sqrt (Q x / P x)) + +lemma binary_root_energy (p r q s : ℝ) (hp : 0 < p) (hr : 0 < r) + (hq : 0 ≤ q) (hs : 0 ≤ s) : + p * r / (p+r) * (Real.sqrt (q/p) - Real.sqrt (s/r))^2 = + (Real.sqrt r * Real.sqrt q - Real.sqrt p * Real.sqrt s)^2 / (p+r) := by + rw [Real.sqrt_div hq, Real.sqrt_div hs] + have hp0 := Real.sqrt_pos.2 hp + have hr0 := Real.sqrt_pos.2 hr + have hp2 := Real.sq_sqrt hp.le + have hr2 := Real.sq_sqrt hr.le + field_simp + rw [hp2, hr2] + +lemma binary_conditional_mean_energy (p r q s : ℝ) (hp : 0 < p) (hr : 0 < r) + (hq : 0 ≤ q) (hs : 0 ≤ s) : + (q+s) * ((q-s)/(q+s) - (p-r)/(p+r))^2 ≤ + 4 * (Real.sqrt r * Real.sqrt q - Real.sqrt p * Real.sqrt s)^2 / (p+r) := by + by_cases hqs : q+s=0 + · have hq0 : q=0 := by linarith + have hs0 : s=0 := by linarith + simp [hq0, hs0] + have hqt : 0 < q+s := lt_of_le_of_ne (add_nonneg hq hs) (Ne.symm hqs) + have hpt : 0 < p+r := add_pos hp hr + have hp2 := Real.sq_sqrt hp.le + have hr2 := Real.sq_sqrt hr.le + have hq2 := Real.sq_sqrt hq + have hs2 := Real.sq_sqrt hs + let a := Real.sqrt r * Real.sqrt q - Real.sqrt p * Real.sqrt s + let b := Real.sqrt r * Real.sqrt q + Real.sqrt p * Real.sqrt s + have hab : a*b = r*q-p*s := by + dsimp [a,b] + nlinarith only [hp2,hr2,hq2,hs2] + have hb : b^2 ≤ (p+r)*(q+s) := by + have he : (p+r)*(q+s)-b^2 = + (Real.sqrt p * Real.sqrt q - Real.sqrt r * Real.sqrt s)^2 := by + dsimp [b] + nlinarith only [hp2,hr2,hq2,hs2] + nlinarith only [he, sq_nonneg (Real.sqrt p * Real.sqrt q - Real.sqrt r * Real.sqrt s)] + have hd : (q-s)/(q+s) - (p-r)/(p+r) = 2*(a*b)/((q+s)*(p+r)) := by + rw [hab] + field_simp + ring + rw [hd] + change (q+s)*(2*(a*b)/((q+s)*(p+r)))^2 ≤ 4*a^2/(p+r) + apply (le_div_iff₀ hpt).2 + have hd2 : (q+s)*(2*(a*b)/((q+s)*(p+r)))^2*(p+r) = + 4*a^2*b^2/((q+s)*(p+r)) := by field_simp; ring + rw [hd2] + apply (div_le_iff₀ (mul_pos hqt hpt)).2 + nlinarith only [mul_le_mul_of_nonneg_left hb (show 0 ≤ 4*a^2 by positivity)] + +@[simp] lemma conditionalMean_flip {n : ℕ} (P : Spin n → ℝ) + (x : Spin n) (i : Fin n) : conditionalMean P (flip x i) i = conditionalMean P x i := by + simp only [conditionalMean, flip_flip, spin_flip_self] + rw [add_comm (P (flip x i)), ← neg_sub (P x) (P (flip x i)), neg_div, neg_mul_neg] + +lemma lawDensityEnergy_eq {n : ℕ} (P Q : Spin n → ℝ) + (hP : ∀ x, 0 < P x) (hQ : ∀ x, 0 ≤ Q x) : + lawDensityEnergy P Q = (∑ i, ∑ x, + (Real.sqrt (P (flip x i)) * Real.sqrt (Q x) - + Real.sqrt (P x) * Real.sqrt (Q (flip x i)))^2 / (P x + P (flip x i))) / 2 := by + unfold lawDensityEnergy lawDirichlet + congr 1 + apply Finset.sum_congr rfl + intro i _ + apply Finset.sum_congr rfl + intro x _ + exact binary_root_energy _ _ _ _ (hP x) (hP _) (hQ x) (hQ _) + +theorem conditional_means_energy {n : ℕ} (P Q : Spin n → ℝ) + (hP : ∀ x, 0 < P x) (hQ : ∀ x, 0 ≤ Q x) : + (∑ x, Q x * ∑ i, (conditionalMean Q x i - conditionalMean P x i)^2) ≤ + 4 * lawDensityEnergy P Q := by + rw [lawDensityEnergy_eq P Q hP hQ] + simp_rw [Finset.mul_sum] + rw [Finset.sum_comm] + have hsym (i : Fin n) : + (∑ x, Q (flip x i) * (conditionalMean Q x i - conditionalMean P x i)^2) = + ∑ x, Q x * (conditionalMean Q x i - conditionalMean P x i)^2 := by + simpa only [conditionalMean_flip] using sum_flip i + (fun x => Q x * (conditionalMean Q x i - conditionalMean P x i)^2) + have hlocal (i : Fin n) (x : Spin n) : + (Q x + Q (flip x i)) * (conditionalMean Q x i - conditionalMean P x i)^2 ≤ + 4 * (Real.sqrt (P (flip x i)) * Real.sqrt (Q x) - + Real.sqrt (P x) * Real.sqrt (Q (flip x i)))^2 / (P x + P (flip x i)) := by + have he : (conditionalMean Q x i - conditionalMean P x i)^2 = + ((Q x-Q (flip x i))/(Q x+Q (flip x i)) - + (P x-P (flip x i))/(P x+P (flip x i)))^2 := by + simp only [conditionalMean, ← mul_sub, mul_pow, spin_sq, one_mul] + rw [he] + exact binary_conditional_mean_energy _ _ _ _ (hP x) (hP _) (hQ x) (hQ _) + have hh (i : Fin n) := Finset.sum_le_sum (fun x (_ : x ∈ Finset.univ) => hlocal i x) + simp only [add_mul, Finset.sum_add_distrib, hsym] at hh + have hsum := Finset.sum_le_sum (fun i (_ : i ∈ Finset.univ) => hh i) + simp only [Finset.sum_add_distrib, mul_div_assoc, ← Finset.mul_sum] at hsum ⊢ + linarith only [hsum] + +lemma conditionalMean_mul_mass {n : ℕ} (Q : Spin n → ℝ) + (hQ : ∀ x, 0 ≤ Q x) (x : Spin n) (i : Fin n) : + (Q x + Q (flip x i)) * conditionalMean Q x i = + spin x i * (Q x-Q (flip x i)) := by + unfold conditionalMean + by_cases h : Q x + Q (flip x i) = 0 + · have ha : Q x=0 := by have := hQ (flip x i); have := hQ x; linarith + have hb : Q (flip x i)=0 := by have := hQ x; have := hQ (flip x i); linarith + simp [ha,hb] + · field_simp + +lemma conditionalMean_abs_le {n : ℕ} (Q : Spin n → ℝ) + (hQ : ∀ x, 0 ≤ Q x) (x : Spin n) (i : Fin n) : + |conditionalMean Q x i| ≤ 1 := by + have hs : |spin x i| = 1 := by cases hx : x i <;> simp [spin,hx] + simp only [conditionalMean, abs_mul, hs, one_mul, abs_div] + rw [abs_of_nonneg (add_nonneg (hQ x) (hQ _))] + apply div_le_one_of_le₀ _ (add_nonneg (hQ x) (hQ _)) + exact abs_sub_le_iff.2 ⟨by linarith [hQ (flip x i)], by linarith [hQ x]⟩ + +lemma law_coordinate_mean {n : ℕ} (Q : Spin n → ℝ) (hQ : ∀ x, 0 ≤ Q x) + (i : Fin n) (F : Spin n → ℝ) (hF : ∀ x, F (flip x i)=F x) : + (∑ x, Q x * spin x i * F x) = ∑ x, Q x * conditionalMean Q x i * F x := by + have ha := sum_flip i (fun x => Q x * spin x i * F x) + have hb := sum_flip i (fun x => Q x * conditionalMean Q x i * F x) + simp only [spin_flip_self, conditionalMean_flip, hF] at ha hb + have he (x : Spin n) : + Q x * spin x i * F x + Q (flip x i) * -spin x i * F x = + Q x * conditionalMean Q x i * F x + + Q (flip x i) * conditionalMean Q x i * F x := by + have hm := conditionalMean_mul_mass Q hQ x i + have := congrArg (fun z => z * F x) hm + nlinarith only [this] + have hh := Finset.sum_congr (s₁ := Finset.univ) (s₂ := Finset.univ) rfl + (fun x _ => he x) + simp only [Finset.sum_add_distrib, ha, hb] at hh + linarith only [hh] + +lemma law_integration_by_parts {n : ℕ} (Q : Spin n → ℝ) (hQ : ∀ x, 0 ≤ Q x) + (i : Fin n) (F : Spin n → ℝ) : + (∑ x, Q x * (spin x i - conditionalMean Q x i) * F x) = + ∑ x, Q x * (1-spin x i*conditionalMean Q x i) * halfDiff i F x := by + have hh : ∀ x, (F (flip x i) - spin (flip x i) i * halfDiff i F (flip x i)) = + F x - spin x i * halfDiff i F x := by + intro x + rw [spin_flip_self, halfDiff_flip] + linarith only [flip_sub i F x] + have he := law_coordinate_mean Q hQ i + (fun x => F x-spin x i*halfDiff i F x) hh + have h1 (x : Spin n) : Q x * spin x i * (F x-spin x i*halfDiff i F x) = + Q x*spin x i*F x - Q x*halfDiff i F x := by + have hs := spin_sq x i + nlinarith only [congrArg (fun z : ℝ => Q x*halfDiff i F x*z) hs] + simp_rw [h1] at he + simp only [mul_sub, Finset.sum_sub_distrib] at he + have h2 (x : Spin n) : Q x * (spin x i - conditionalMean Q x i) * F x = + Q x * spin x i * F x - Q x * conditionalMean Q x i * F x := by ring + have h3 (x : Spin n) : Q x * (1-spin x i*conditionalMean Q x i) * halfDiff i F x = + Q x * halfDiff i F x - + Q x * conditionalMean Q x i * (spin x i * halfDiff i F x) := by ring + simp_rw [h2, h3, Finset.sum_sub_distrib] + linarith only [he] + +lemma law_integration_by_parts_variance {n : ℕ} (Q : Spin n → ℝ) + (hQ : ∀ x, 0 ≤ Q x) (i : Fin n) (F : Spin n → ℝ) : + (∑ x, Q x * (spin x i-conditionalMean Q x i) * F x) = + ∑ x, Q x*(1-(conditionalMean Q x i)^2)*halfDiff i F x := by + rw [law_integration_by_parts Q hQ] + have hh := law_coordinate_mean Q hQ i + (fun x => conditionalMean Q x i*halfDiff i F x) + (by intro x; rw [conditionalMean_flip,halfDiff_flip]) + simp only [mul_sub,sub_mul,mul_one,Finset.sum_sub_distrib,pow_two,← mul_assoc] at hh ⊢ + rw [hh] + +lemma gibbs_flipRate_fraction {n : ℕ} (J : Interaction n) + (hJ : ∀ i j, J i j = J j i) (hdiag : ∀ i, J i i = 0) + (x : Spin n) (i : Fin n) : + flipRate J x i = gibbs J (flip x i)/(gibbs J x+gibbs J (flip x i)) := by + have hf : flipRate J (flip x i) i = 1-flipRate J x i := by + simp only [flipRate, spin_flip_self, mean_flip J hdiag] + ring + have hh := gibbs_detailed_balance J hJ hdiag x i + rw [hf] at hh + apply (eq_div_iff (ne_of_gt (add_pos (gibbs_pos J x) (gibbs_pos J _)))).2 + nlinarith only [hh] + +lemma conditionalMean_gibbs {n : ℕ} (J : Interaction n) + (hJ : ∀ i j, J i j = J j i) (hdiag : ∀ i, J i i = 0) + (x : Spin n) (i : Fin n) : conditionalMean (gibbs J) x i = mean J x i := by + have hh := gibbs_flipRate_fraction J hJ hdiag x i + have hs := spin_sq x i + have hr : (gibbs J x-gibbs J (flip x i))/(gibbs J x+gibbs J (flip x i)) = + 1-2*flipRate J x i := by + rw [hh] + field_simp [ne_of_gt (add_pos (gibbs_pos J x) (gibbs_pos J (flip x i)))] + ring + rw [conditionalMean, hr, flipRate] + nlinarith only [congrArg (fun z : ℝ => mean J x i*z) hs] + +lemma lawDirichlet_gibbs {n : ℕ} (J : Interaction n) + (hJ : ∀ i j, J i j = J j i) (hdiag : ∀ i, J i i = 0) + (f : Spin n → ℝ) : lawDirichlet (gibbs J) f = dirichlet J f f := by + have he (i : Fin n) : + (∑ x, gibbs J x * flipRate J x i * (f x - f (flip x i))^2) = + 2 * (∑ x, gibbs J x * siteVariance J x i * halfDiff i f x * halfDiff i f x) := by + have hh := sum_flip i (fun x => gibbs J x * flipRate J x i * f x * (f x-f (flip x i))) + simp only [gibbs_detailed_balance J hJ hdiag, flip_flip] at hh + have hk (x : Spin n) : gibbs J x * flipRate J x i * (f x-f (flip x i))^2 = + gibbs J x * flipRate J x i * f x * (f x-f (flip x i)) + + gibbs J x * flipRate J x i * f (flip x i) * (f (flip x i)-f x) := by ring + simp_rw [hk] + rw [Finset.sum_add_distrib, hh] + have hd : (∑ x, gibbs J x * flipRate J x i * f x * (f x-f (flip x i))) = + ∑ x, gibbs J x * siteVariance J x i * halfDiff i f x * halfDiff i f x := by + convert gibbs_edge_dirichlet J hJ hdiag i f f using 1 + apply Finset.sum_congr rfl + intro x _ + ring + rw [hd] + ring + unfold lawDirichlet + simp_rw [mul_div_assoc, ← gibbs_flipRate_fraction J hJ hdiag] + simp_rw [he] + rw [← Finset.mul_sum] + have hc (z : ℝ) : 2*z/2=z := by ring + rw [hc] + unfold dirichlet gibbsExpectation + simp only [Finset.mul_sum] + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro i _ + apply Finset.sum_congr rfl + intro x _ + ring + +theorem gibbs_conditional_means_energy {n : ℕ} (J : Interaction n) + (hJ : ∀ i j, J i j = J j i) (hdiag : ∀ i, J i i = 0) + (Q : Spin n → ℝ) (hQ : ∀ x, 0 ≤ Q x) : + (∑ x, Q x * ∑ i, (conditionalMean Q x i - mean J x i)^2) ≤ + 4 * dirichlet J (fun x => Real.sqrt (Q x/gibbs J x)) + (fun x => Real.sqrt (Q x/gibbs J x)) := by + simpa only [conditionalMean_gibbs J hJ hdiag, lawDensityEnergy, + lawDirichlet_gibbs J hJ hdiag] using conditional_means_energy (gibbs J) Q (gibbs_pos J) hQ + +lemma lawDensityEnergy_nonneg {n : ℕ} (P Q : Spin n → ℝ) + (hP : ∀ x, 0 < P x) : 0 ≤ lawDensityEnergy P Q := by + unfold lawDensityEnergy lawDirichlet + apply div_nonneg _ (by norm_num) + exact Finset.sum_nonneg (fun i _ => Finset.sum_nonneg (fun x _ => + mul_nonneg (div_nonneg (mul_nonneg (hP x).le (hP _).le) + (add_nonneg (hP x).le (hP _).le)) (sq_nonneg _))) + +lemma lawDensityEnergy_le {n : ℕ} (P Q : Spin n → ℝ) + (hP : ∀ x, 0 < P x) (hQ : ∀ x, 0 ≤ Q x) : + lawDensityEnergy P Q ≤ (n:ℝ) * ∑ x, Q x := by + rw [lawDensityEnergy_eq P Q hP hQ] + have hlocal (i : Fin n) (x : Spin n) : + (Real.sqrt (P (flip x i))*Real.sqrt (Q x)- + Real.sqrt (P x)*Real.sqrt (Q (flip x i)))^2/(P x+P (flip x i)) ≤ Q x+Q (flip x i) := by + apply (div_le_iff₀ (add_pos (hP x) (hP _))).2 + have ha := Real.sq_sqrt (hP x).le + have hb := Real.sq_sqrt (hP (flip x i)).le + have hc := Real.sq_sqrt (hQ x) + have hd := Real.sq_sqrt (hQ (flip x i)) + have he : (Real.sqrt (P (flip x i))*Real.sqrt (Q x))^2 = P (flip x i)*Q x := by + rw [mul_pow, hb, hc] + have hf : (Real.sqrt (P x)*Real.sqrt (Q (flip x i)))^2 = P x*Q (flip x i) := by + rw [mul_pow, ha, hd] + nlinarith only [he, hf, + mul_nonneg (hP x).le (hQ x), mul_nonneg (hP (flip x i)).le (hQ (flip x i)), + mul_nonneg (mul_nonneg (Real.sqrt_nonneg (P (flip x i))) (Real.sqrt_nonneg (Q x))) + (mul_nonneg (Real.sqrt_nonneg (P x)) (Real.sqrt_nonneg (Q (flip x i))))] + calc + _ ≤ (∑ i : Fin n, ∑ x, (Q x+Q (flip x i)))/2 := by + exact div_le_div_of_nonneg_right + (Finset.sum_le_sum (fun i _ => Finset.sum_le_sum (fun x _ => hlocal i x))) + (by norm_num) + _ = _ := by simp only [Finset.sum_add_distrib, sum_flip, Finset.sum_const, + Finset.card_univ, Fintype.card_fin, nsmul_eq_mul]; ring + +lemma weighted_cauchy_sq {α : Type*} [Fintype α] (w f g : α → ℝ) + (hw : ∀ a, 0 ≤ w a) : + (∑ a, w a*f a*g a)^2 ≤ (∑ a, w a*f a^2)*(∑ a, w a*g a^2) := by + apply Finset.sum_sq_le_sum_mul_sum_of_sq_le_mul + Finset.univ (fun a _ => mul_nonneg (hw a) (sq_nonneg _)) + (fun a _ => mul_nonneg (hw a) (sq_nonneg _)) + intro a _ + exact le_of_eq (by ring) + +theorem weak_residual_base {n : ℕ} (P Q : Spin n → ℝ) + (hP : ∀ x, 0 < P x) (hQ : ∀ x, 0 ≤ Q x) (hQsum : ∑ x, Q x=1) + (U : Spin n → Fin n → ℝ) (A B : ℝ) (hB : 0 ≤ B) + (hA : ∀ x, ∑ i, |halfDiff i (fun y => U y i) x| ≤ A) + (hU : ∀ x, ∑ i, U x i^2 ≤ B^2) : + |∑ x, Q x * ∑ i, (spin x i-conditionalMean P x i)*U x i| ≤ + 2*A+2*B*Real.sqrt (lawDensityEnergy P Q) := by + let a := ∑ x, Q x * ∑ i, (1-spin x i*conditionalMean Q x i) * halfDiff i (fun y => U y i) x + let b := ∑ x, Q x * ∑ i, (conditionalMean Q x i-conditionalMean P x i)*U x i + have he : (∑ x, Q x * ∑ i, (spin x i-conditionalMean P x i)*U x i) = a+b := by + have hs (x : Spin n) (i : Fin n) : + (spin x i-conditionalMean P x i)*U x i = + (spin x i-conditionalMean Q x i)*U x i+ + (conditionalMean Q x i-conditionalMean P x i)*U x i := by ring + simp_rw [hs, Finset.sum_add_distrib, mul_add, Finset.sum_add_distrib] + congr 1 + dsimp [a] + simp_rw [Finset.mul_sum] + rw [Finset.sum_comm, Finset.sum_comm (f := fun x i => + Q x*((1-spin x i*conditionalMean Q x i)*halfDiff i (fun y => U y i) x))] + apply Finset.sum_congr rfl + intro i _ + simpa only [mul_assoc] using law_integration_by_parts Q hQ i (fun y => U y i) + have ha : |a| ≤ 2*A := by + have hs (x : Spin n) (i : Fin n) : |1-spin x i*conditionalMean Q x i| ≤ 2 := by + have hsp : |spin x i|=1 := by cases hx : x i <;> simp [spin,hx] + calc + _ ≤ |(1:ℝ)|+|spin x i*conditionalMean Q x i| := abs_sub _ _ + _ ≤ 2 := by rw [abs_one, abs_mul,hsp,one_mul]; linarith [conditionalMean_abs_le Q hQ x i] + calc + |a| ≤ ∑ x, |Q x * ∑ i, (1-spin x i*conditionalMean Q x i)*halfDiff i (fun y => U y i) x| := + Finset.abs_sum_le_sum_abs .. + _ = ∑ x, Q x * |∑ i, (1-spin x i*conditionalMean Q x i)*halfDiff i (fun y => U y i) x| := by + simp only [abs_mul, abs_of_nonneg (hQ _)] + _ ≤ ∑ x, Q x * (2*A) := by + apply Finset.sum_le_sum + intro x _ + apply mul_le_mul_of_nonneg_left _ (hQ x) + calc + _ ≤ ∑ i, |(1-spin x i*conditionalMean Q x i)*halfDiff i (fun y => U y i) x| := + Finset.abs_sum_le_sum_abs .. + _ ≤ ∑ i, 2*|halfDiff i (fun y => U y i) x| := by + apply Finset.sum_le_sum + intro i _ + rw [abs_mul] + exact mul_le_mul_of_nonneg_right (hs x i) (abs_nonneg _) + _ ≤ 2*A := by rw [← Finset.mul_sum]; exact mul_le_mul_of_nonneg_left (hA x) (by norm_num) + _ = 2*A := by rw [← Finset.sum_mul, hQsum,one_mul] + have hb : |b| ≤ 2*B*Real.sqrt (lawDensityEnergy P Q) := by + have hcs := weighted_cauchy_sq (fun a : Spin n × Fin n => Q a.1) + (fun a => conditionalMean Q a.1 a.2-conditionalMean P a.1 a.2) + (fun a => U a.1 a.2) (fun a => hQ a.1) + simp only [Fintype.sum_prod_type, mul_assoc, ← Finset.mul_sum] at hcs + have hUb : (∑ x, Q x*∑ i, U x i^2) ≤ B^2 := by + calc + _ ≤ ∑ x, Q x*B^2 := Finset.sum_le_sum (fun x _ => mul_le_mul_of_nonneg_left (hU x) (hQ x)) + _ = B^2 := by rw [← Finset.sum_mul,hQsum,one_mul] + have hc := conditional_means_energy P Q hP hQ + have hd := lawDensityEnergy_nonneg P Q hP + have hUI : 0 ≤ ∑ x, Q x*∑ i, U x i^2 := by + exact Finset.sum_nonneg (fun x _ => mul_nonneg (hQ x) + (Finset.sum_nonneg (fun i _ => sq_nonneg _))) + have hbound := mul_le_mul hc hUb hUI (show 0 ≤ 4*lawDensityEnergy P Q by positivity) + have he2 := Real.sq_sqrt hd + have hpos : 0 ≤ 2*B*Real.sqrt (lawDensityEnergy P Q) := by positivity + apply (sq_le_sq₀ (abs_nonneg b) hpos).1 + rw [sq_abs] + have hid : (2*B*Real.sqrt (lawDensityEnergy P Q))^2 = 4*lawDensityEnergy P Q*B^2 := by + rw [mul_pow,he2] + ring + rw [hid] + exact hcs.trans hbound + rw [he] + exact (abs_add_le a b).trans (add_le_add ha hb) + +end SKGapCutoff.Static + +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise NNReal ENNReal + +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Stability/ConditionalMeanScalar.lean b/lean/OAI/Probability/SKGap/Stability/ConditionalMeanScalar.lean new file mode 100644 index 0000000000000000000000000000000000000000..7c4fef7797231ffc55fac97195a97d0b841fa781 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Stability/ConditionalMeanScalar.lean @@ -0,0 +1,38 @@ +import Mathlib +import OAI.Probability.SKGap.Model + +namespace OAI + +section +noncomputable section +namespace SKGap +open Real +lemma conditional_perp_mean_scalar {N q s : ℝ} (hN : 0 < N) (hq : 0 < q) (hs : 0 < s) + (j a B w u : ℝ) : + (j/N*sqrt (N*q)/s)*(w+B*sqrt (N*q)*u-(N*(a+B*q)/sqrt (N*q))*u)= + j*sqrt (q/s)*(w/(sqrt N*sqrt s))-j*a/s*u := by + have hn := (sqrt_pos.mpr hN).ne' + have hq' := (sqrt_pos.mpr hq).ne' + have hs' := (sqrt_pos.mpr hs).ne' + rw [sqrt_mul hN.le,sqrt_div hq.le] + field_simp + ring_nf + simp only [sq_sqrt hN.le,sq_sqrt hq.le,sq_sqrt hs.le] + have hcube : sqrt N^3=N*sqrt N := by + linear_combination sqrt N*(sq_sqrt hN.le) + rw [hcube] + ring + +lemma conditional_parallel_mean_scalar {N q S : ℝ} (hN : 0 < N) (hq : 0 < q) + (j a B : ℝ) : + (2*(j/N)*sqrt (N*q)/S)*((N*(a+B*q))/sqrt (N*q))=2*j*(a+B*q)/S := by + have hc : sqrt (N*q) ≠ 0 := (sqrt_pos.mpr (mul_pos hN hq)).ne' + by_cases hS : S=0 + · simp [hS] + · field_simp + +end SKGap +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Stability/ConditionalStability.lean b/lean/OAI/Probability/SKGap/Stability/ConditionalStability.lean new file mode 100644 index 0000000000000000000000000000000000000000..0c4177125ed588b40868d75136c0d3beee2c3276 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Stability/ConditionalStability.lean @@ -0,0 +1,53 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.ConditionalWellDefined +import OAI.Probability.SKGap.Localization.ConditionalHessianLaw +import OAI.Probability.SKGap.Gaussian.GaussianTiltMass + +namespace OAI + +section +noncomputable section +namespace SKGap +open Matrix Real Set MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix.Norms.Frobenius ENNReal + +theorem conditional_field_stability {j A R t0 T : ℝ} + (hj : 0 < j) (hj1 : j < 1) (hA : 1 ≤ A) (hsub : sqrt j*A < 1) + (hR : 0 ≤ R) (ht0 : 0 < t0) : + ∃ m ν σ0 : ℝ, 0 < m ∧ 0 < ν ∧ 0 < σ0 ∧ + ∃ U : Set (ScalarTimeDomain R t0 T), IsOpen U ∧ scalarEqualitySet j R t0 T ⊆ U ∧ + ∀ R1 : ℝ, 1 ≤ R1 → ∃ ε c : ℝ, ∃ N : ℕ, 0 < ε ∧ 0 < c ∧ 0 < N ∧ + ∀ (n : ℕ) [NeZero n], N ≤ n → ∀ x ∈ U, ∀ y : Fin n → ℝ, + empiricalLaw y=(x.1 : ProbabilityMeasure ℝ) → + (∑ i,if R1 < |y i| then y i^2 else 0) ≤ ν*(n:ℝ) → + ∀ σ : ℝ, |σ| ≤ σ0 → + (conditionalGoeLaw (j/(n:ℝ)) ((x.2:ℝ)+σ^2) (magnetization y) + (empiricalObservation j x.2 σ y)).real + {W | ((fun i k=>W (i,k)),y) ∈ badFieldSet n j A ε m} ≤ exp (-c*(n:ℝ)) := by + obtain ⟨m,ν,σ0,hm,hν,hσ0,U,hU,hKU,hbound⟩ := + conditional_empirical_simultaneous (T := T) hj hj1 hA hsub hR ht0 + let V : Set (ScalarTimeDomain R t0 T) := {x | 0 < scalarQMoment (x.1:ProbabilityMeasure ℝ)} + have hV : IsOpen V := isOpen_lt continuous_const + (continuous_scalarQMoment.comp (continuous_subtype_val.comp continuous_fst)) + have hKV : scalarEqualitySet j R t0 T ⊆ V := by + intro x hx + change 0 < scalarQMoment (x.1:ProbabilityMeasure ℝ) + rw [hx,scalarQMoment_curve hj hj1 (ht0.le.trans x.2.2.1)] + exact (scalar_fixed_pos hj hj1 (ht0.trans_le x.2.2.1)).2 + refine ⟨m/2,ν,σ0,half_pos hm,hν,hσ0,U∩V,hU.inter hV,fun x hx=>⟨hKU hx,hKV hx⟩,?_⟩ + intro R1 hR1 + obtain ⟨ε,c,N,hε,hc,hN,hb⟩ := hbound R1 hR1 + obtain ⟨M,hM⟩ := absorb_finite_exponential_factor 103 (half_pos hc) + refine ⟨ε,c/2,max N M,hε,half_pos hc,lt_of_lt_of_le hN (le_max_left _ _),?_⟩ + intro n _ hn x hx y hP hy σ hσ + have hq : 0 < scalarQMoment (empiricalLaw y) := by rw [hP]; exact hx.2 + apply (conditional_bad_le_freshbad hj.le (ht0.trans_le x.2.2.1) (by linarith : m/2 < m) y hq).trans + apply (hb n ((le_max_left N M).trans hn) x hx.1 y hP hy σ hσ).trans + simpa only [Nat.cast_ofNat,show (n:ℝ)*(-c)= -c*(n:ℝ) from by ring, + show (n:ℝ)*(-c+c/2)= -(c/2)*(n:ℝ) from by ring] using + hM n ((le_max_right N M).trans hn) (-c) +end SKGap +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Stability/DiagonalStability.lean b/lean/OAI/Probability/SKGap/Stability/DiagonalStability.lean new file mode 100644 index 0000000000000000000000000000000000000000..cdab6edbf0e7e4b3393913ff71056df3a2c690d8 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Stability/DiagonalStability.lean @@ -0,0 +1,142 @@ +import Mathlib +import OAI.Probability.SKGap.Stability.RootDiagonalTransfer +import OAI.Probability.SKGap.Matrix.GOESubmatrix + +namespace OAI + +section + +noncomputable section +namespace SKGap.ObservationBridge +open Matrix Real Set MeasureTheory ProbabilityTheory Filter +open scoped BigOperators ENNReal Topology + +lemma absorb_linear_exponential {b : ℝ} (hb : 0 < b) : + ∃ N : ℕ, ∀ n ≥ N, + 2*(n:ℝ)*exp (-b*(n:ℝ)) ≤ exp (-(b/2)*(n:ℝ)) := by + obtain ⟨N,hN⟩ := exists_nat_ge (16/b^2) + refine ⟨N,fun n hn=>?_⟩ + have hnR : 16/b^2 ≤ (n:ℝ) := hN.trans (Nat.cast_le.mpr hn) + have hn0 : 0 ≤ (n:ℝ) := Nat.cast_nonneg _ + have hbn : 16 ≤ (n:ℝ)*b^2 := (div_le_iff₀ (sq_pos_of_pos hb)).mp hnR + have hmul := mul_le_mul_of_nonneg_right hbn hn0 + have he := Real.pow_div_factorial_le_exp ((b/2)*(n:ℝ)) (by positivity) 2 + norm_num only [Nat.factorial_succ,Nat.factorial_zero,Nat.cast_mul,Nat.cast_one,Nat.cast_ofNat] at he + have hhead : 2*(n:ℝ) ≤ exp ((b/2)*(n:ℝ)) := by nlinarith + calc + _ ≤ exp ((b/2)*(n:ℝ))*exp (-b*(n:ℝ)) := + mul_le_mul_of_nonneg_right hhead (exp_pos _).le + _ = _ := by rw [← exp_add]; congr 1; ring + +lemma shifted_goe_diagonal_tail {j δ : ℝ} (hj : 0 < j) (hδ : 0 < δ) + {n : ℕ} (hn : 0 < n) (hmean : j/(n:ℝ) ≤ δ/2) : + (gaussianCoordinates (MatrixCoordinates (Fin n))).real + {g | ∃ i, δ < |plantedInteraction j (goeMatrix (j/(n:ℝ)) g) i i|} ≤ + 2*(n:ℝ)*exp (-(δ^2/(32*j))*(n:ℝ)) := by + have hr : 0 < j/(n:ℝ) := div_pos hj (Nat.cast_pos.mpr hn) + have hs : {g : MatrixCoordinates (Fin n)→ℝ | ∃ i, + δ < |plantedInteraction j (goeMatrix (j/(n:ℝ)) g) i i|} ⊆ + {g | ∃ i, δ/2 < |goeMatrix (j/(n:ℝ)) g i i|} := by + rintro g ⟨i,hi⟩ + refine ⟨i,?_⟩ + have he : plantedInteraction j (goeMatrix (j/(n:ℝ)) g) i i = + goeMatrix (j/(n:ℝ)) g i i+j/(n:ℝ) := by + simp [plantedInteraction,Matrix.vecMulVec] + rw [he] at hi + have hh := abs_add_le (goeMatrix (j/(n:ℝ)) g i i) (j/(n:ℝ)) + rw [abs_of_pos hr] at hh + linarith + apply (measureReal_mono hs (measure_ne_top _ _)).trans + have hh := goe_diagonal_tail (ι:=Fin n) hr (half_pos hδ).le + have he : -(δ/2)^2/(8*(j/(n:ℝ))) = -(δ^2/(32*j))*(n:ℝ) := by + field_simp + ring + simpa only [Fintype.card_fin,he] using hh + +def erasedPlantedRootBad (n : ℕ) (j A K ε c ρ t : ℝ) : + Set ((MatrixCoordinates (Fin n)→ℝ) × (Fin n→ℝ)) := + {p | (∀ z : Field n, vectorNorm + (eraseDiagonal (plantedInteraction j (goeMatrix (j/(n:ℝ)) p.1))*ᵥz) ≤ K*vectorNorm z) ∧ + rootBad j A ε c ρ (eraseDiagonal (plantedInteraction j (goeMatrix (j/(n:ℝ)) p.1))) + (fun i=>t+p.2 i)} + +lemma erased_planted_probability {n : ℕ} {j A K ε c ρ δ a t : ℝ} + (hj : 0 < j) (hA : 0 ≤ A) (hδ : 0 < δ) (hn : 0 < n) + (hδρ : δ ≤ ρ/2) (hδc : A*δ ≤ c/2) (hmean : j/(n:ℝ) ≤ δ/2) + (hp : ((gaussianCoordinates (MatrixCoordinates (Fin n))).prod + (Measure.pi (fun _ : Fin n=>gaussianReal 0 t.toNNReal))).real + (plantedRootBad n j A K ε c ρ t) ≤ exp (-a*(n:ℝ))) : + ((gaussianCoordinates (MatrixCoordinates (Fin n))).prod + (Measure.pi (fun _ : Fin n=>gaussianReal 0 t.toNNReal))).real + (erasedPlantedRootBad n j A (K-δ) ε (c/2) (ρ/2) t) ≤ + exp (-a*(n:ℝ))+2*(n:ℝ)*exp (-(δ^2/(32*j))*(n:ℝ)) := by + let μ := gaussianCoordinates (MatrixCoordinates (Fin n)) + let ν := Measure.pi (fun _ : Fin n=>gaussianReal 0 t.toNNReal) + let D := {g : MatrixCoordinates (Fin n)→ℝ | ∃ i, + δ < |plantedInteraction j (goeMatrix (j/(n:ℝ)) g) i i|} + have hs : erasedPlantedRootBad n j A (K-δ) ε (c/2) (ρ/2) t ⊆ + plantedRootBad n j A K ε c ρ t ∪ (D ×ˢ (Set.univ : Set (Fin n→ℝ))) := by + intro p hp + by_cases hd : p.1∈D + · exact Or.inr ⟨hd,mem_univ _⟩ + · apply Or.inl + exact erased_planted_witness hA hδ.le hδρ hδc t p.1 p.2 + (fun i=>le_of_not_gt (fun hi=>hd ⟨i,hi⟩)) hp.1 hp.2 + have hD : (μ.prod ν).real (D ×ˢ (Set.univ : Set (Fin n→ℝ))) ≤ + 2*(n:ℝ)*exp (-(δ^2/(32*j))*(n:ℝ)) := by + rw [measureReal_prod_prod] + simp only [Measure.real,measure_univ,ENNReal.toReal_one,mul_one] + exact shifted_goe_diagonal_tail hj hδ hn hmean + exact (measureReal_mono hs (measure_ne_top _ _)).trans + ((measureReal_union_le _ _).trans (add_le_add hp hD)) + +theorem zero_diagonal_fixed_time_root_stability {j T : ℝ} + (hj : 0 < j) (hj1 : j < 1) (hT : 0 < T) : + ∃ A K ε c ρ a : ℝ, 1 < A ∧ 2*sqrt j < K ∧ sqrt j*A < 1 ∧ + 0 < ε ∧ 0 < c ∧ 0 < ρ ∧ 0 < a ∧ ∃ N : ℕ, 0 < N ∧ + ∀ n ≥ N, ∀ t∈Icc 0 T, + ((gaussianCoordinates (MatrixCoordinates (Fin n))).prod + (Measure.pi (fun _ : Fin n=>gaussianReal 0 t.toNNReal))).real + (erasedPlantedRootBad n j A K ε c ρ t) ≤ exp (-a*(n:ℝ)) := by + obtain ⟨A,K,ε,c,ρ,a,hA,hK,hsub,hε,hc,hρ,ha,N,hN,hp⟩ := + planted_fixed_time_root_stability hj hj1 hT + let δ := min ((K-2*sqrt j)/2) (min (ρ/2) (c/(2*A))) + have hA0 : 0 < A := zero_lt_one.trans hA + have hδ : 0 < δ := lt_min (by linarith) (lt_min (half_pos hρ) (by positivity)) + have hδK : δ ≤ (K-2*sqrt j)/2 := min_le_left _ _ + have hδρ : δ ≤ ρ/2 := (min_le_right _ _).trans (min_le_left _ _) + have hδc' : δ ≤ c/(2*A) := (min_le_right _ _).trans (min_le_right _ _) + have hδc : A*δ ≤ c/2 := by + have hh := (le_div_iff₀ (by positivity : 0 < 2*A)).mp hδc' + nlinarith + let b := δ^2/(32*j) + have hb : 0 < b := by dsimp [b]; positivity + obtain ⟨Nd,hNd⟩ := absorb_linear_exponential hb + obtain ⟨Nm,hNm⟩ := exists_nat_ge (2*j/δ) + obtain ⟨r,hr,Nr,hNr⟩ := two_exponential_tails ha (half_pos hb) + refine ⟨A,K-δ,ε,c/2,ρ/2,r,hA,by linarith,hsub,hε,half_pos hc,half_pos hρ,hr, + max N (max Nd (max Nm Nr)),hN.trans_le (le_max_left _ _),?_⟩ + intro n hn t ht + have hnN : N ≤ n := (le_max_left _ _).trans hn + have hnD : Nd ≤ n := (le_max_left _ _).trans ((le_max_right _ _).trans hn) + have hnM : Nm ≤ n := (le_max_left _ _).trans + ((le_max_right _ _).trans ((le_max_right _ _).trans hn)) + have hnR : Nr ≤ n := (le_max_right _ _).trans + ((le_max_right _ _).trans ((le_max_right _ _).trans hn)) + have hn0 : 0 < n := hN.trans_le hnN + have hmean : j/(n:ℝ) ≤ δ/2 := by + have hh := (div_le_iff₀ hδ).mp (hNm.trans (Nat.cast_le.mpr hnM)) + apply (div_le_iff₀ (Nat.cast_pos.mpr hn0)).mpr + nlinarith + have hh := erased_planted_probability hj hA0.le hδ hn0 hδρ hδc hmean (hp n hnN t ht) + apply hh.trans + apply (add_le_add_right (hNd n hnD) _).trans + exact (by nlinarith only [exp_pos (-a*(n:ℝ))] : + exp (-a*(n:ℝ))+exp (-(b/2)*(n:ℝ)) ≤ + 4*exp (-a*(n:ℝ))+exp (-(b/2)*(n:ℝ))).trans (hNr n hnR) +end SKGap.ObservationBridge + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Stability/FieldIntegralMeasure.lean b/lean/OAI/Probability/SKGap/Stability/FieldIntegralMeasure.lean new file mode 100644 index 0000000000000000000000000000000000000000..8d7334c1a1587631d1df0152089fd822999eed09 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Stability/FieldIntegralMeasure.lean @@ -0,0 +1,99 @@ +import Mathlib +import OAI.Probability.SKGap.Stability.FieldTonelli +import OAI.Probability.SKGap.Localization.ConditionalIntegralRate + +namespace OAI + +section +noncomputable section +namespace SKGap +open Matrix Real Set MeasureTheory ProbabilityTheory GaussianDensity +open scoped BigOperators Matrix.Norms.Frobenius ENNReal + +lemma measurable_fieldIntegral {n : ℕ} (j t σ : ℝ) + (E : Set (((Fin n×Fin n) → ℝ) × (Fin n → ℝ))) (hE : MeasurableSet E) : + Measurable (fun p : (MatrixCoordinates (Fin n) → ℝ) × (Fin n → ℝ)=> + fieldIntegral j σ (plantedInteraction j (goeMatrix (j/(n:ℝ)) p.1)) + (fun i=>t+p.2 i) {y | ((fun q=>goeMatrix (j/(n:ℝ)) p.1 q.1 q.2),y)∈E}) := by + let H : ((MatrixCoordinates (Fin n) → ℝ) × (Fin n → ℝ)) × (Fin n → ℝ) → ℝ≥0∞ := + fun p=>ENNReal.ofReal (fieldMollifier j σ (plantedInteraction j (goeMatrix (j/(n:ℝ)) p.1.1)) + (fun i=>t+p.1.2 i) p.2)* E.indicator (fun _=>1) ((fun q=>goeMatrix (j/(n:ℝ)) p.1.1 q.1 q.2),p.2) + have hsJ : Continuous (fun p : ((MatrixCoordinates (Fin n) → ℝ) × (Fin n → ℝ)) × (Fin n → ℝ) => + plantedInteraction j (goeMatrix (j/(n:ℝ)) p.1.1)) := + ((goeMatrix_pi_lipschitz (j/(n:ℝ))).continuous.comp (continuous_fst.comp continuous_fst)).add continuous_const + have htime : Continuous (fun p : ((MatrixCoordinates (Fin n) → ℝ) × (Fin n → ℝ)) × (Fin n → ℝ) => + (fun i=>t+p.1.2 i)) := by + apply continuous_pi + intro i + exact continuous_const.add ((continuous_apply i).comp (continuous_snd.comp continuous_fst)) + have hmap : Continuous (fun p : ((MatrixCoordinates (Fin n) → ℝ) × (Fin n → ℝ)) × (Fin n → ℝ) => + (plantedInteraction j (goeMatrix (j/(n:ℝ)) p.1.1),((fun i=>t+p.1.2 i),p.2))) := + hsJ.prodMk (htime.prodMk continuous_snd) + have hφ := ((continuous_fieldMollifier j σ).comp hmap).measurable.ennreal_ofReal + have hI : Measurable (fun p : ((MatrixCoordinates (Fin n) → ℝ) × (Fin n → ℝ)) × (Fin n → ℝ) => + E.indicator (fun _=>(1 : ℝ≥0∞)) ((fun q=>goeMatrix (j/(n:ℝ)) p.1.1 q.1 q.2),p.2)) := by + apply (measurable_const.indicator hE).comp + unfold goeMatrix + fun_prop + have hH : Measurable H := hφ.mul hI + have he (p : (MatrixCoordinates (Fin n) → ℝ) × (Fin n → ℝ)) : + fieldIntegral j σ (plantedInteraction j (goeMatrix (j/(n:ℝ)) p.1)) + (fun i=>t+p.2 i) {y | ((fun q=>goeMatrix (j/(n:ℝ)) p.1 q.1 q.2),y)∈E}= + ∫⁻ y,H (p,y) := by + have hs : MeasurableSet {y : Fin n → ℝ | ((fun q=>goeMatrix (j/(n:ℝ)) p.1 q.1 q.2),y)∈E} := hE.preimage (by fun_prop) + erw [fieldIntegral_indicator _ _ _ _ _ hs] + apply lintegral_congr + intro y + dsimp [H] + by_cases hy : ((fun q=>goeMatrix (j/(n:ℝ)) p.1 q.1 q.2),y)∈E <;> simp [hy] + simp_rw [he] + exact hH.lintegral_prod_right' + +lemma measurableSet_badField_section {n : ℕ} (j A ε m : ℝ) + (W : Matrix (Fin n) (Fin n) ℝ) : + MeasurableSet {y : Field n | (W,y)∈badFieldSet n j A ε m} := by + have hm : Measurable (fun z : Fin n → ℝ=>((fun q : Fin n × Fin n=>W q.1 q.2),z)) := + measurable_const.prodMk measurable_id + have hs := (measurableSet_badFieldFlat n j A ε m).preimage hm + convert hs using 1 + ext y + rfl + +lemma measurable_fieldIntegral_cylinder {n : ℕ} (j t σ : ℝ) + (E : Set (Field n)) (hE : MeasurableSet E) : + Measurable (fun p : (MatrixCoordinates (Fin n) → ℝ) × (Fin n → ℝ)=> + fieldIntegral j σ (plantedInteraction j (goeMatrix (j/(n:ℝ)) p.1)) + (fun i=>t+p.2 i) E) := by + simpa only [mem_prod,mem_univ,true_and,ofPred_mem_eq] using + measurable_fieldIntegral j t σ (Set.univ ×ˢ E) (MeasurableSet.univ.prod hE) + +lemma measureReal_union_detector {Ω : Type*} [MeasurableSpace Ω] + (μ : Measure Ω) [IsFiniteMeasure μ] (E D : Set Ω) (F : Ω → ℝ≥0∞) + (b p q : ℝ) (hbD : μ.real D ≤ p) + (hbF : μ.real {x | ENNReal.ofReal b ≤ F x} ≤ q) + (hdet : ∀ x ∈ E, x∉D → ENNReal.ofReal b ≤ F x) : μ.real E ≤ p+q := by + apply (measureReal_mono (s₂ := D ∪ {x | ENNReal.ofReal b ≤ F x}) ?_ (measure_ne_top _ _)).trans + · exact (measureReal_union_le _ _).trans (add_le_add hbD hbF) + · intro x hx + by_cases hd : x∈D + · exact Or.inl hd + · exact Or.inr (hdet x hx hd) + +lemma markov_exponential {Ω : Type*} [MeasurableSpace Ω] (μ : Measure Ω) + {F : Ω → ℝ≥0∞} (hF : Measurable F) {a b d : ℝ} + (hb : ∫⁻ x,F x ∂μ ≤ ENNReal.ofReal (exp (-a*d))) : + μ.real {x | ENNReal.ofReal (exp (-b*d)) ≤ F x} ≤ exp (-(a-b)*d) := by + have hm := meas_ge_le_lintegral_div (μ := μ) (ε := ENNReal.ofReal (exp (-b*d))) hF.aemeasurable + (ENNReal.ofReal_pos.mpr (exp_pos _)).ne' ENNReal.ofReal_ne_top + have he : ENNReal.ofReal (exp (-a*d))/ENNReal.ofReal (exp (-b*d))= + ENNReal.ofReal (exp (-(a-b)*d)) := by + rw [← ENNReal.ofReal_div_of_pos (exp_pos _),← exp_sub] + congr 2 + ring + have hx := hm.trans ((ENNReal.div_le_div_right hb _).trans_eq he) + exact (ENNReal.toReal_mono ENNReal.ofReal_ne_top hx).trans_eq (ENNReal.toReal_ofReal (exp_pos _).le) +end SKGap +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Stability/FieldIntegralReduction.lean b/lean/OAI/Probability/SKGap/Stability/FieldIntegralReduction.lean new file mode 100644 index 0000000000000000000000000000000000000000..16663d65856d9cf511107714f537c43e1f31ddbd --- /dev/null +++ b/lean/OAI/Probability/SKGap/Stability/FieldIntegralReduction.lean @@ -0,0 +1,212 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.CubeApprox +import OAI.Probability.SKGap.Localization.LocalVolumeChange +import OAI.Probability.SKGap.Matrix.ConditionalMiddleNorm +import OAI.Probability.SKGap.Gaussian.GaussianReductionPointwise + +namespace OAI + +section +noncomputable section +namespace SKGap +open Matrix Real Set MeasureTheory ProbabilityTheory GaussianDensity +open scoped BigOperators Matrix.Norms.Frobenius ENNReal +attribute [local fun_prop] continuous_radialDensity + +def fieldMollifier {n : ℕ} (j σ : ℝ) (J : Matrix (Fin n) (Fin n) ℝ) + (h y : Fin n → ℝ) : ℝ := + radialDensity σ (tapField j J h y)*exp ((n:ℝ)*j*(1-overlap y)^2/2) + +def fieldIntegral {n : ℕ} (j σ : ℝ) (J : Matrix (Fin n) (Fin n) ℝ) + (h : Fin n → ℝ) (E : Set (Fin n → ℝ)) : ℝ≥0∞ := + ∫⁻ y in E, ENNReal.ofReal (fieldMollifier j σ J h y) + +lemma continuous_fieldMollifier {n : ℕ} (j σ : ℝ) : + Continuous (fun p : Matrix (Fin n) (Fin n) ℝ × ((Fin n → ℝ) × (Fin n → ℝ))=> + fieldMollifier j σ p.1 p.2.1 p.2.2) := by + unfold fieldMollifier tapField onsager overlap magnetization + exact ((continuous_radialDensity σ).comp (by fun_prop)).mul (by fun_prop) + +def conditionalFieldWeight {n : ℕ} [NeZero n] (j t σ : ℝ) + (E : Set (((Fin n×Fin n) → ℝ) × (Fin n → ℝ))) (y : Fin n → ℝ) : ℝ≥0∞ := + conditionalGoeLaw (j/(n:ℝ)) (t+σ^2) (magnetization y) (empiricalObservation j t σ y) + {W | (W,y) ∈ E} + +lemma field_noise_convolution {n : ℕ} [NeZero n] {j t σ : ℝ} (ht : 0 ≤ t) (hσ : 0 < σ) + (y : Fin n → ℝ) (f : ((Fin n×Fin n) → ℝ) → ℝ≥0∞) (g : MatrixCoordinates (Fin n) → ℝ) : + (∫⁻ x, ENNReal.ofReal (fieldMollifier j σ + (plantedInteraction j (goeMatrix (j/(n:ℝ)) g)) (fun i=>t+x i) y)* + f (fun p=>goeMatrix (j/(n:ℝ)) g p.1 p.2) + ∂Measure.pi (fun _ : Fin n=>gaussianReal 0 t.toNNReal))= + ENNReal.ofReal (exp ((n:ℝ)*j*(1-overlap y)^2/2))* + (ENNReal.ofReal (radialDensity (sqrt (t+σ^2)) + (empiricalObservation j t σ y-goeMatrix (j/(n:ℝ)) g*ᵥmagnetization y))* + f (fun p=>goeMatrix (j/(n:ℝ)) g p.1 p.2)) := by + simp only [fieldMollifier,tapField_planted_observation j t σ, + ENNReal.ofReal_mul (radialDensity_pos hσ _).le] + rw [lintegral_mul_const _ (by fun_prop),lintegral_mul_const _ (by fun_prop),gaussian_radial_convolution ht hσ] + ring + +theorem field_reduction_fixed {n : ℕ} [NeZero n] {j t σ : ℝ} + (hj : 0 ≤ j) (ht : 0 ≤ t) (hσ : 0 < σ) + (E : Set (((Fin n×Fin n) → ℝ) × (Fin n → ℝ))) (hE : MeasurableSet E) (y : Fin n → ℝ) : + (∫⁻ g, ∫⁻ x, ENNReal.ofReal (fieldMollifier j σ + (plantedInteraction j (goeMatrix (j/(n:ℝ)) g)) (fun i=>t+x i) y)* + E.indicator (fun _=>1) ((fun p=>goeMatrix (j/(n:ℝ)) g p.1 p.2),y) + ∂Measure.pi (fun _ : Fin n=>gaussianReal 0 t.toNNReal) + ∂gaussianCoordinates (MatrixCoordinates (Fin n)))= + ENNReal.ofReal (sqrt (scalarS j (scalarEmpirical y t σ)/ + (scalarS j (scalarEmpirical y t σ)+j*scalarQMoment (empiricalLaw y)))*scalarIntegrand j t σ y)* + conditionalFieldWeight j t σ E y := by + let f : ((Fin n×Fin n) → ℝ) → ℝ≥0∞ := fun W=>E.indicator (fun _=>1) (W,y) + have hf : Measurable f := measurable_const.indicator (hE.preimage (by fun_prop)) + change (∫⁻ g, ∫⁻ x, ENNReal.ofReal (fieldMollifier j σ _ _ y)*f _ ∂_ ∂_)=_ + simp_rw [field_noise_convolution ht hσ y f] + have hgf : Measurable (fun g : MatrixCoordinates (Fin n) → ℝ => f (fun p=>goeMatrix (j/(n:ℝ)) g p.1 p.2)) := hf.comp (by unfold goeMatrix; fun_prop) + have hgr : Measurable (fun g : MatrixCoordinates (Fin n) → ℝ => ENNReal.ofReal + (radialDensity (sqrt (t+σ^2)) (empiricalObservation j t σ y-goeMatrix (j/(n:ℝ)) g*ᵥmagnetization y))) := by + apply Measurable.ennreal_ofReal + apply (continuous_radialDensity _).measurable.comp + unfold Matrix.mulVec dotProduct goeMatrix + fun_prop + erw [lintegral_const_mul _ (hgr.mul hgf),goe_pointwise_conditional_integral + (div_nonneg hj (Nat.cast_nonneg n)) (add_pos_of_nonneg_of_pos ht (sq_pos_of_pos hσ)) _ _ f hf] + have hfi : (∫⁻ W,f W ∂conditionalGoeLaw (j/(n:ℝ)) (t+σ^2) (magnetization y) + (empiricalObservation j t σ y))=conditionalFieldWeight j t σ E y := by + change (∫⁻ W, {W | (W,y)∈E}.indicator (fun _=>(1 : ℝ≥0∞)) W ∂_)=_ + have hset : MeasurableSet {W : (Fin n×Fin n) → ℝ | (W,y)∈E} := hE.preimage (by fun_prop) + rw [lintegral_indicator hset,lintegral_const] + simp [conditionalFieldWeight] + rw [hfi,← mul_assoc,← ENNReal.ofReal_mul (exp_pos _).le] + congr 1 + congr 1 + rw [mul_comm,scalar_density_cancellation hj ht hσ y] +end SKGap +end +end + +section +noncomputable section +namespace SKGap +open Matrix Real Set MeasureTheory ProbabilityTheory GaussianDensity +open scoped BigOperators ENNReal + +lemma fieldMollifier_eq_localAction {n : ℕ} (j σ : ℝ) (J : Matrix (Fin n) (Fin n) ℝ) + (h y : Field n) : fieldMollifier j σ J h y= + ((sqrt (2*Real.pi)*σ)⁻¹)^n*exp (localAction j σ J h y) := by + unfold fieldMollifier radialDensity localAction varianceAverage + rw [Fintype.card_fin,vectorNorm_sq,mul_assoc,← exp_add] + simp only [vectorSqNorm,dotProduct,pow_two] + +lemma fieldIntegral_eq_localVolume {n : ℕ} {σ : ℝ} (hσ : 0 < σ) (j : ℝ) + (J : Matrix (Fin n) (Fin n) ℝ) (h : Field n) (E : Set (Field n)) : + fieldIntegral j σ J h E=localVolume j σ J h E := by + unfold fieldIntegral localVolume + simp_rw [fieldMollifier_eq_localAction,ENNReal.ofReal_mul (by positivity : 0 ≤ ((sqrt (2*Real.pi)*σ)⁻¹)^n)] + exact lintegral_const_mul _ (Real.measurable_exp.comp (localAction_continuous j σ J h).measurable |>.ennreal_ofReal) +end SKGap +end +end + +section +noncomputable section +namespace SKGap +open Matrix Real Set MeasureTheory ProbabilityTheory GaussianDensity +open scoped BigOperators Matrix.Norms.Frobenius ENNReal + +lemma outer_add_rank_le_two {ι : Type*} [Fintype ι] [DecidableEq ι] + (u v w z : ι → ℝ) : (vecMulVec u v+vecMulVec w z).rank ≤ 2 := by + let Q : Matrix ι (Fin 2) ℝ := fun i k=>![u i,w i] k + let R : Matrix (Fin 2) ι ℝ := fun k i=>![v i,z i] k + have he : vecMulVec u v+vecMulVec w z=Q*R := by + ext i k + change u i*v k+w i*z k=∑ l : Fin 2,Q i l*R l k + simp [Q,R,Fin.sum_univ_two] + rw [he] + exact (rank_mul_le_left Q R).trans (by simpa using rank_le_card_width Q) + +lemma operator_outer_vector_le {n : ℕ} (u v : Field n) : + opNorm (vecMulVec u v) ≤ vectorNorm u*vectorNorm v := + operator_vecMulVec_le (WithLp.toLp 2 u) (WithLp.toLp 2 v) + +lemma vectorNorm_const_one (n : ℕ) : vectorNorm (fun _ : Fin n=>(1:ℝ))=sqrt (n:ℝ) := by + apply (sq_eq_sq₀ (vectorNorm_nonneg _) (sqrt_nonneg _)).mp + rw [vectorNorm_sq,sq_sqrt (Nat.cast_nonneg _)] + simp [vectorSqNorm] + +lemma spinVariance_norm_bound {n : ℕ} (y : Field n) : + vectorNorm (spinVariance y) ≤ sqrt (n:ℝ) := by + apply vectorNorm_le_of_sq_sum (sqrt_nonneg _) + rw [sq_sqrt (Nat.cast_nonneg _)] + calc + _ ≤ ∑ _i : Fin n,(1:ℝ) := Finset.sum_le_sum (fun i _=>by + have h0 := (spinVariance_pos y i).le + have h1 := spinVariance_le_one y i + nlinarith) + _ = _ := by simp + +lemma weightedMagnetization_norm_bound {n : ℕ} (y : Field n) : + vectorNorm (fun i=>magnetization y i*spinVariance y i) ≤ sqrt (n:ℝ) := by + have hh := vectorNorm_diag_le zero_le_one (x := magnetization y) + (a := spinVariance y) (fun i=>(abs_of_pos (spinVariance_pos y i)).trans_le (spinVariance_le_one y i)) + simpa only [one_mul,mul_comm] using hh.trans (by simpa only [one_mul] using magnetization_norm_bound y) + +def plantedJacobianPerturbation {n : ℕ} (j : ℝ) (y : Field n) : Matrix (Fin n) (Fin n) ℝ := + (-j/(n:ℝ)) • vecMulVec (fun _=>1) (spinVariance y)+ + (-2*j/(n:ℝ)) • vecMulVec (magnetization y) (fun i=>magnetization y i*spinVariance y i) + +lemma plantedJacobianPerturbation_rank {n : ℕ} (j : ℝ) (y : Field n) : + (plantedJacobianPerturbation j y).rank ≤ 2 := by + have he : plantedJacobianPerturbation j y= + vecMulVec (fun _=>-j/(n:ℝ)) (spinVariance y)+ + vecMulVec (fun i=>(-2*j/(n:ℝ))*magnetization y i) (fun i=>magnetization y i*spinVariance y i) := by + ext i k + simp [plantedJacobianPerturbation,vecMulVec_apply,mul_assoc] + rw [he] + exact outer_add_rank_le_two _ _ _ _ + +lemma plantedJacobianPerturbation_norm {n : ℕ} (hn : 0 < n) {j : ℝ} (hj : 0 ≤ j) (y : Field n) : + opNorm (plantedJacobianPerturbation j y) ≤ 3*j := by + have hn0 : (0:ℝ) < n := Nat.cast_pos.mpr hn + have h1 : opNorm (vecMulVec (fun _ : Fin n=>1) (spinVariance y)) ≤ (n:ℝ) := by + apply (operator_outer_vector_le _ _).trans + rw [vectorNorm_const_one] + exact (mul_le_mul_of_nonneg_left (spinVariance_norm_bound y) (sqrt_nonneg _)).trans_eq (mul_self_sqrt hn0.le) + have h2 : opNorm (vecMulVec (magnetization y) (fun i=>magnetization y i*spinVariance y i)) ≤ (n:ℝ) := by + apply (operator_outer_vector_le _ _).trans + exact (mul_le_mul (magnetization_norm_bound y) (weightedMagnetization_norm_bound y) + (vectorNorm_nonneg _) (sqrt_nonneg _)).trans_eq (mul_self_sqrt hn0.le) + have hh := real_opNorm_add ((-j/(n:ℝ)) • vecMulVec (fun _=>1) (spinVariance y)) + ((-2*j/(n:ℝ)) • vecMulVec (magnetization y) (fun i=>magnetization y i*spinVariance y i)) + change opNorm (plantedJacobianPerturbation j y) ≤ _ at hh + simp only [real_opNorm_smul,abs_div,abs_of_pos hn0,abs_neg,abs_of_nonneg hj] at hh + have hab : |-(2:ℝ)*j|=2*j := by rw [abs_mul,abs_neg,abs_of_nonneg (by norm_num : (0:ℝ) ≤ 2),abs_of_nonneg hj] + rw [hab] at hh + apply hh.trans + have ha := mul_le_mul_of_nonneg_left h1 (div_nonneg hj hn0.le) + have hb := mul_le_mul_of_nonneg_left h2 (div_nonneg (mul_nonneg (by norm_num : (0:ℝ) ≤ 2) hj) hn0.le) + have he1 : j/(n:ℝ)*(n:ℝ)=j := div_mul_cancel₀ j hn0.ne' + have he2 : 2*j/(n:ℝ)*(n:ℝ)=2*j := div_mul_cancel₀ (2*j) hn0.ne' + rw [he1] at ha + rw [he2] at hb + linarith + +lemma fieldJacobian_planted_formula {n : ℕ} (hn : 0 < n) (j : ℝ) + (W : Matrix (Fin n) (Fin n) ℝ) (y : Field n) : + fieldJacobian j (plantedInteraction j W) y= + 1+((j*coordAverage (spinVariance y)) • 1-W)*diagonal (spinVariance y)+ + plantedJacobianPerturbation j y := by + have hb : coordAverage (spinVariance y)=1-overlap y := by + simpa only [coordAverage,Fintype.card_fin,varianceAverage] using (varianceAverage_eq_average hn y).symm + ext i k + simp only [Matrix.add_apply] + erw [Matrix.mul_diagonal] + simp only [fieldJacobian,hessianCore,plantedInteraction,plantedJacobianPerturbation, + Matrix.add_apply,Matrix.sub_apply,Matrix.smul_apply,smul_eq_mul,vecMulVec_apply,hb,onsager, + Matrix.one_apply] + by_cases he : i=k <;> simp only [he,↓reduceIte] <;> ring +end SKGap +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Stability/FieldLogDet.lean b/lean/OAI/Probability/SKGap/Stability/FieldLogDet.lean new file mode 100644 index 0000000000000000000000000000000000000000..ceb1fec747519412389104d9d474af1ca93fb5ae --- /dev/null +++ b/lean/OAI/Probability/SKGap/Stability/FieldLogDet.lean @@ -0,0 +1,168 @@ +import Mathlib +import OAI.Probability.SKGap.Matrix.LogDetUniform +import OAI.Probability.SKGap.Stability.FieldIntegralReduction + +namespace OAI + +section +noncomputable section +namespace SKGap +open Matrix Real Set MeasureTheory ProbabilityTheory GaussianDensity +open scoped BigOperators Matrix.Norms.Frobenius ENNReal + +theorem field_logdet_uniform {j ε : ℝ} (hj : 0 < j) (hj1 : j < 1) (hε : 0 < ε) : + ∃ γ : ℝ,0 < γ ∧ ∃ N : ℕ,0 < N ∧ ∀ n : ℕ,N ≤ n → + (gaussianCoordinates (MatrixCoordinates (Fin n))).real + {g | ∃ y : Field n,(n:ℝ)*(j*varianceAverage y^2+ε) < + log ((fieldJacobian j (plantedInteraction j (goeMatrix (j/(n:ℝ)) g)) y)ᵀ* + fieldJacobian j (plantedInteraction j (goeMatrix (j/(n:ℝ)) g)) y+γ • 1).det} ≤ + 4*exp (-min 1 (1/(π^2*j))*(n:ℝ)) := by + obtain ⟨γ,hγ,hγbound⟩ := actual_simultaneous_logdet hj hj1 hε + obtain ⟨N,hN,hbound⟩ := hγbound γ hγ le_rfl 2 (3*j) + refine ⟨γ,hγ,N,hN,?_⟩ + intro n hn + have hn0 : 0 < n := hN.trans_le hn + have hnreal : (0:ℝ) < n := Nat.cast_pos.mpr hn0 + apply (measureReal_mono (s₂ := {g | ∃ a : Fin n → ℝ,(∀ i,0 ≤ a i) ∧ (∀ i,a i ≤ 1) ∧ + ∃ E : Matrix (Fin n) (Fin n) ℝ,E.rank ≤ 2 ∧ opNorm E ≤ 3*j ∧ + j*(coordAverage a)^2+ε < LogDet.regularizedLogDet γ + (1+((j*coordAverage a) • 1-goeMatrix (j/(n:ℝ)) g)*diagonal a+E)}) ?_ + (measure_ne_top _ _)).trans (hbound n hn) + rintro g ⟨y,hy⟩ + refine ⟨spinVariance y,fun i=>(spinVariance_pos y i).le,spinVariance_le_one y, + plantedJacobianPerturbation j y,plantedJacobianPerturbation_rank j y, + plantedJacobianPerturbation_norm hn0 hj.le y,?_⟩ + rw [← fieldJacobian_planted_formula hn0] + have hav : coordAverage (spinVariance y)=varianceAverage y := by + simpa only [coordAverage,Fintype.card_fin] using (varianceAverage_eq_average hn0 y).symm + rw [hav] + simpa only [LogDet.regularizedLogDet,LogDet.regularizedGram,Fintype.card_fin,lt_div_iff₀ hnreal,mul_comm] using hy +end SKGap +end +end + +section +noncomputable section +namespace SKGap +open Matrix Real Set +open scoped BigOperators + +lemma spinVariance_difference_norm {n : ℕ} (y d : Field n) : + vectorNorm (spinVariance (y+d)-spinVariance y) ≤ 2*vectorNorm d := by + apply vectorNorm_le_of_sq_sum (mul_nonneg (by norm_num : (0:ℝ) ≤ 2) (vectorNorm_nonneg _)) + rw [mul_pow,vectorNorm_sq,vectorSqNorm,Finset.mul_sum] + apply Finset.sum_le_sum + intro i _ + have hh : |spinVariance (y+d) i-spinVariance y i| ≤ 2*|d i| := by + simpa only [spinVariance,magnetization,Pi.add_apply,add_sub_cancel_left] using + scalar_variance_lipschitz_abs (y i+d i) (y i) + have ha := mul_self_le_mul_self (abs_nonneg _) hh + simpa only [sq_abs,← pow_two,mul_pow,Pi.sub_apply] using ha + +lemma dot_magnetization_sq_difference {n : ℕ} (y d v : Field n) : + |((∑ i,magnetization (y+d) i*v i)^2)-(∑ i,magnetization y i*v i)^2| ≤ + 2*sqrt (n:ℝ)*vectorNorm d*vectorSqNorm v := by + let a := ∑ i,magnetization (y+d) i*v i + let b := ∑ i,magnetization y i*v i + have ha : |a| ≤ sqrt (n:ℝ)*vectorNorm v := + (vector_dot_abs_le (magnetization (y+d)) v).trans + (mul_le_mul_of_nonneg_right (magnetization_norm_bound (y+d)) (vectorNorm_nonneg _)) + have hb : |b| ≤ sqrt (n:ℝ)*vectorNorm v := + (vector_dot_abs_le (magnetization y) v).trans + (mul_le_mul_of_nonneg_right (magnetization_norm_bound y) (vectorNorm_nonneg _)) + have hab : |a-b| ≤ vectorNorm d*vectorNorm v := by + have he : a-b=∑ i,(magnetization (y+d)-magnetization y) i*v i := by + simp only [a,b,Pi.sub_apply,sub_mul,Finset.sum_sub_distrib] + rw [he] + exact (vector_dot_abs_le _ _).trans + (mul_le_mul_of_nonneg_right (magnetization_difference_norm y d) (vectorNorm_nonneg _)) + have hsum : |a+b| ≤ 2*sqrt (n:ℝ)*vectorNorm v := (abs_add_le _ _).trans (by linarith) + change |a^2-b^2| ≤ _ + rw [sq_sub_sq,abs_mul] + apply (mul_le_mul hsum hab (abs_nonneg _) (mul_nonneg (mul_nonneg (by norm_num : (0:ℝ) ≤ 2) (sqrt_nonneg _)) (vectorNorm_nonneg _))).trans_eq + rw [← vectorNorm_sq] + ring + +lemma hessian_field_difference {n : ℕ} (hn : 0 < n) {j A : ℝ} (hj : 0 ≤ j) (_hA : 0 ≤ A) + (J : Matrix (Fin n) (Fin n) ℝ) (y d a x : Field n) + (ha0 : ∀ i,0 ≤ a i) (haA : ∀ i,a i ≤ A) : + |quadraticForm (fieldHessian j J (y+d) a) x-quadraticForm (fieldHessian j J y a) x| ≤ + (6*j*A/sqrt (n:ℝ))*vectorNorm d*vectorSqNorm x := by + let v : Field n := fun i=>sqrt (a i)*x i + have hn0 : (0:ℝ) < n := Nat.cast_pos.mpr hn + have hs0 : 0 < sqrt (n:ℝ) := sqrt_pos.mpr hn0 + have hv : vectorSqNorm v ≤ A*vectorSqNorm x := by + unfold vectorSqNorm v + rw [Finset.mul_sum] + exact Finset.sum_le_sum (fun i _=>by + rw [mul_pow,sq_sqrt (ha0 i)] + exact mul_le_mul_of_nonneg_right (haA i) (sq_nonneg _)) + have hb : |onsager j (y+d)-onsager j y| ≤ j*(2/sqrt (n:ℝ)*vectorNorm d) := by + unfold onsager + rw [← mul_sub,abs_mul,abs_of_nonneg hj] + exact mul_le_mul_of_nonneg_left (varianceAverage_difference hn y d) hj + have he : quadraticForm (fieldHessian j J (y+d) a) x-quadraticForm (fieldHessian j J y a) x= + (onsager j (y+d)-onsager j y)*vectorSqNorm v- + (2*j/(n:ℝ))*((∑ i,magnetization (y+d) i*v i)^2-(∑ i,magnetization y i*v i)^2) := by + rw [hessian_quadratic_formula,hessian_quadratic_formula] + dsimp [v] + ring + rw [he] + apply (abs_sub _ _).trans + rw [abs_mul,abs_of_nonneg (vectorSqNorm_nonneg v),abs_mul, + abs_of_nonneg (div_nonneg (mul_nonneg (by norm_num : (0:ℝ) ≤ 2) hj) hn0.le)] + have hq := dot_magnetization_sq_difference y d v + have hfirst := mul_le_mul_of_nonneg_right hb (vectorSqNorm_nonneg v) + have hsecond := mul_le_mul_of_nonneg_left hq (div_nonneg (mul_nonneg (by norm_num : (0:ℝ) ≤ 2) hj) hn0.le) + have hfactor : j*(2/sqrt (n:ℝ)*vectorNorm d)*vectorSqNorm v+ + (2*j/(n:ℝ))*(2*sqrt (n:ℝ)*vectorNorm d*vectorSqNorm v)= + (6*j/sqrt (n:ℝ))*vectorNorm d*vectorSqNorm v := by + field_simp + rw [sq_sqrt hn0.le] + ring + apply (add_le_add hfirst hsecond).trans + rw [hfactor] + calc + _ ≤ (6*j/sqrt (n:ℝ))*vectorNorm d*(A*vectorSqNorm x) := + mul_le_mul_of_nonneg_left hv (mul_nonneg (by positivity) (vectorNorm_nonneg _)) + _ = _ := by ring + +lemma badField_neighborhood {n : ℕ} (hn : 0 < n) {j A ε c r : ℝ} + (hj : 0 ≤ j) (hA : 0 ≤ A) (hε : 0 < ε) (_hr0 : 0 ≤ r) + (hrε : 2*r ≤ ε/2) (hrc : 6*j*A*r ≤ c/2) + (W : Matrix (Fin n) (Fin n) ℝ) (y d : Field n) + (hy : (W,y)∈badFieldSet n j A (ε/2) (c/2)) + (hd : vectorNorm d ≤ r*sqrt (n:ℝ)) : + (W,y+d)∈badFieldSet n j A ε c := by + obtain ⟨a,ha,hclose,x,hx,hquad⟩ := hy + have hs := sqrt_nonneg (n:ℝ) + have hn0 : (0:ℝ) < n := Nat.cast_pos.mpr hn + have hnorm : vectorNorm (a-spinVariance y) ≤ (ε/2)*sqrt (n:ℝ) := by + apply vectorNorm_le_of_sq_sum (by positivity) + simpa only [Pi.sub_apply,mul_pow,sq_sqrt hn0.le] using hclose + have hdist : vectorNorm (a-spinVariance (y+d)) ≤ ε*sqrt (n:ℝ) := by + have he : a-spinVariance (y+d)=(a-spinVariance y)-(spinVariance (y+d)-spinVariance y) := by abel + rw [he] + apply (vectorNorm_sub_le _ _).trans + have hm := (spinVariance_difference_norm y d).trans (mul_le_mul_of_nonneg_left hd (by norm_num)) + nlinarith [mul_le_mul_of_nonneg_right hrε hs] + refine ⟨a,ha,?_,x,hx,?_⟩ + · have hh := mul_self_le_mul_self (vectorNorm_nonneg (a-spinVariance (y+d))) hdist + simpa only [← pow_two,vectorNorm_sq,vectorSqNorm,Pi.sub_apply,mul_pow,sq_sqrt hn0.le] using hh + · have hv : vectorSqNorm x.ofLp=1 := by + rw [← vectorNorm_sq] + change ‖WithLp.toLp 2 x.ofLp‖^2=1 + simp only [WithLp.toLp_ofLp,hx,one_pow] + have hb := hessian_field_difference hn hj hA (plantedInteraction j W) y d a x.ofLp + (fun i=>(ha i).1) (fun i=>(ha i).2) + rw [hv,mul_one] at hb + have hc := (mul_le_mul_of_nonneg_left hd (by positivity : 0 ≤ 6*j*A/sqrt (n:ℝ))) + have he : (6*j*A/sqrt (n:ℝ))*(r*sqrt (n:ℝ))=6*j*A*r := by field_simp + rw [he] at hc + linarith [le_abs_self (quadraticForm (fieldHessian j (plantedInteraction j W) (y+d) a) x.ofLp- + quadraticForm (fieldHessian j (plantedInteraction j W) y a) x.ofLp)] +end SKGap +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Stability/FieldSquareSum.lean b/lean/OAI/Probability/SKGap/Stability/FieldSquareSum.lean new file mode 100644 index 0000000000000000000000000000000000000000..a110bd0715c84f5ea33a2287a774b52aa736a03c --- /dev/null +++ b/lean/OAI/Probability/SKGap/Stability/FieldSquareSum.lean @@ -0,0 +1,184 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.LinearObservable + +namespace OAI + +section +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open scoped BigOperators +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open scoped BigOperators +open scoped BigOperators NNReal ENNReal +open MeasureTheory Metric Set +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators NNReal ENNReal Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Set +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators ENNReal NNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Matrix +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators ENNReal NNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal +open scoped BigOperators +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise NNReal ENNReal +open scoped BigOperators +open Filter Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal Topology +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +namespace SKGapCutoff + +lemma field_square_sum_le {n : ℕ} (J : Interaction n) (x : Spin n) + {K : ℝ} (_hK : 0 ≤ K) + (hJ : ‖Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) J‖ ≤ K) : + ∑ i, field J x i^2 ≤ K^2*(n:ℝ) := by + let A := Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) J + let v : EuclideanSpace ℝ (Fin n) := (WithLp.equiv 2 _).symm (spin x) + have hv : ‖v‖^2 = (n:ℝ) := by + rw [EuclideanSpace.real_norm_sq_eq] + exact overlap_coeff_norm_sq x + have hh : ‖A v‖ ≤ K*‖v‖ := (A.le_opNorm v).trans + (mul_le_mul_of_nonneg_right hJ (norm_nonneg _)) + have hs := pow_le_pow_left₀ (norm_nonneg _) hh 2 + rw [mul_pow, hv, EuclideanSpace.real_norm_sq_eq] at hs + exact hs + +lemma one_sub_tanh_half (a : ℝ) : + (1-Real.tanh a)/2 = 1/(1+Real.exp (2*a)) := by + have hh := exp_two_mul_one_sub_tanh a + have he := Real.exp_pos (2*a) + apply (eq_div_iff (by positivity : (1+Real.exp (2*a)) ≠ 0)).mpr + nlinarith + +lemma one_add_tanh_half (a : ℝ) : + (1+Real.tanh a)/2 = 1/(1+Real.exp (-2*a)) := by + simpa only [Real.tanh_neg, sub_neg_eq_add, mul_neg, neg_mul] using one_sub_tanh_half (-a) + +lemma siteRefresh_diagonal_lower {n : ℕ} (J : Interaction n) (x : Spin n) (i : Fin n) : + 1/(1+Real.exp (2*|field J x i|)) ≤ + siteRefresh J i (fun z => if z=x then 1 else 0) x := by + have htrue : replace x i true = x ↔ x i = true := by + constructor + · intro h; simpa using (congrFun h i).symm + · intro h; simpa only [h] using replace_self x i + have hfalse : replace x i false = x ↔ x i = false := by + constructor + · intro h; simpa using (congrFun h i).symm + · intro h; simpa only [h] using replace_self x i + simp only [siteRefresh, htrue, hfalse, mean] + cases x i <;> simp only [ Bool.false_eq_true, Bool.true_eq_false, + ↓reduceIte, mul_zero, mul_one, zero_add, add_zero] + · rw [one_sub_tanh_half] + apply one_div_le_one_div_of_le (by positivity) + apply add_le_add le_rfl + apply Real.exp_le_exp.mpr + linarith [le_abs_self (field J x i)] + · rw [one_add_tanh_half] + apply one_div_le_one_div_of_le (by positivity) + apply add_le_add le_rfl + apply Real.exp_le_exp.mpr + linarith [neg_le_abs (field J x i)] + +lemma logistic_quadratic_lower {a L : ℝ} (hL : 0 < L) : + (1-a^2/L^2)/(1+Real.exp (2*L)) ≤ 1/(1+Real.exp (2*|a|)) := by + by_cases ha : |a| ≤ L + · calc + _ ≤ 1/(1+Real.exp (2*L)) := by + apply div_le_div_of_nonneg_right _ (by positivity) + have : 0 ≤ a^2/L^2 := by positivity + linarith + _ ≤ _ := by + apply one_div_le_one_div_of_le (by positivity) + apply add_le_add le_rfl + apply Real.exp_le_exp.mpr + linarith + · have ha2 : L^2 ≤ a^2 := by nlinarith [sq_abs a, abs_nonneg a, le_of_not_ge ha] + have hratio : 1 ≤ a^2/L^2 := (one_le_div (sq_pos_of_pos hL)).mpr ha2 + exact (div_nonpos_of_nonpos_of_nonneg (by linarith) (by positivity)).trans (by positivity) + +lemma attempted_holding_lower {n : ℕ} (hn : 0 < n) (J : Interaction n) + {K : ℝ} (hK : 0 < K) + (hJ : ‖Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) J‖ ≤ K) (x : Spin n) : + 1/(2*(1+Real.exp (2*(Real.sqrt 2*K)))) ≤ discreteKernel J 1 x x := by + have hnR : (0:ℝ) < n := Nat.cast_pos.mpr hn + have hL : 0 < Real.sqrt 2*K := mul_pos (Real.sqrt_pos.mpr (by norm_num)) hK + have hL2 : (Real.sqrt 2*K)^2 = 2*K^2 := by + rw [mul_pow, Real.sq_sqrt (by norm_num : (0:ℝ) ≤ 2)] + have hsum := field_square_sum_le J x hK.le hJ + have hs : (∑ i, (1-field J x i^2/(Real.sqrt 2*K)^2)/(1+Real.exp (2*(Real.sqrt 2*K)))) ≤ + ∑ i, siteRefresh J i (fun z => if z=x then 1 else 0) x := by + apply Finset.sum_le_sum + intro i _ + exact (logistic_quadratic_lower hL).trans (siteRefresh_diagonal_lower J x i) + simp only [← Finset.sum_div, Finset.sum_sub_distrib, Finset.sum_const, + Finset.card_univ, Fintype.card_fin, nsmul_eq_mul, mul_one, hL2] at hs + have hf : (∑ i, field J x i^2)/(2*K^2) ≤ (n:ℝ)/2 := by + apply (div_le_iff₀ (by positivity : 0 < 2*K^2)).mpr + nlinarith + change _ ≤ (attemptLM J ^ 1) (fun z => if z=x then 1 else 0) x + rw [pow_one, attempt_apply_of_pos hn] + apply (le_div_iff₀ hnR).mpr + calc + _ = ((n:ℝ)/2)/(1+Real.exp (2*(Real.sqrt 2*K))) := by field_simp + _ ≤ ((n:ℝ)-(∑ i, field J x i^2)/(2*K^2))/(1+Real.exp (2*(Real.sqrt 2*K))) := by + apply div_le_div_of_nonneg_right _ (by positivity) + linarith + _ ≤ _ := hs + +end SKGapCutoff + +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology + +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Stability/FieldTonelli.lean b/lean/OAI/Probability/SKGap/Stability/FieldTonelli.lean new file mode 100644 index 0000000000000000000000000000000000000000..165978d5b43fc008ad0ff0104d0e844fee5a1afc --- /dev/null +++ b/lean/OAI/Probability/SKGap/Stability/FieldTonelli.lean @@ -0,0 +1,76 @@ +import Mathlib +import OAI.Probability.SKGap.Stability.FieldIntegralReduction + +namespace OAI + +section +noncomputable section +namespace SKGap +open Matrix Real Set MeasureTheory ProbabilityTheory GaussianDensity +open scoped BigOperators Matrix.Norms.Frobenius ENNReal + +lemma fieldIntegral_indicator {n : ℕ} (j σ : ℝ) (J : Matrix (Fin n) (Fin n) ℝ) + (h : Fin n → ℝ) (E : Set (Fin n → ℝ)) (hE : MeasurableSet E) : + fieldIntegral j σ J h E=∫⁻ y, ENNReal.ofReal (fieldMollifier j σ J h y)*E.indicator (fun _=>1) y := by + rw [fieldIntegral,← lintegral_indicator hE] + apply lintegral_congr + intro y + by_cases hy : y∈E <;> simp [hy] + +theorem field_integral_gaussian_reduction {n : ℕ} [NeZero n] {j t σ : ℝ} + (hj : 0 ≤ j) (ht : 0 ≤ t) (hσ : 0 < σ) + (E : Set (((Fin n×Fin n) → ℝ) × (Fin n → ℝ))) (hE : MeasurableSet E) : + (∫⁻ g, ∫⁻ x, fieldIntegral j σ (plantedInteraction j (goeMatrix (j/(n:ℝ)) g)) + (fun i=>t+x i) {y | ((fun p=>goeMatrix (j/(n:ℝ)) g p.1 p.2),y)∈E} + ∂Measure.pi (fun _ : Fin n=>gaussianReal 0 t.toNNReal) + ∂gaussianCoordinates (MatrixCoordinates (Fin n)))= + ∫⁻ y, ENNReal.ofReal (sqrt (scalarS j (scalarEmpirical y t σ)/ + (scalarS j (scalarEmpirical y t σ)+j*scalarQMoment (empiricalLaw y)))*scalarIntegrand j t σ y)* + conditionalFieldWeight j t σ E y := by + let μ := gaussianCoordinates (MatrixCoordinates (Fin n)) + let ν := Measure.pi (fun _ : Fin n=>gaussianReal 0 t.toNNReal) + let H : ((MatrixCoordinates (Fin n) → ℝ) × (Fin n → ℝ)) × (Fin n → ℝ) → ℝ≥0∞ := + fun p=>ENNReal.ofReal (fieldMollifier j σ (plantedInteraction j (goeMatrix (j/(n:ℝ)) p.1.1)) + (fun i=>t+p.1.2 i) p.2)* E.indicator (fun _=>1) ((fun q=>goeMatrix (j/(n:ℝ)) p.1.1 q.1 q.2),p.2) + have hsJ : Continuous (fun p : ((MatrixCoordinates (Fin n) → ℝ) × (Fin n → ℝ)) × (Fin n → ℝ) => + plantedInteraction j (goeMatrix (j/(n:ℝ)) p.1.1)) := + ((goeMatrix_pi_lipschitz (j/(n:ℝ))).continuous.comp (continuous_fst.comp continuous_fst)).add continuous_const + have htime : Continuous (fun p : ((MatrixCoordinates (Fin n) → ℝ) × (Fin n → ℝ)) × (Fin n → ℝ) => + (fun i=>t+p.1.2 i)) := by + apply continuous_pi + intro i + exact continuous_const.add ((continuous_apply i).comp (continuous_snd.comp continuous_fst)) + have hmap : Continuous (fun p : ((MatrixCoordinates (Fin n) → ℝ) × (Fin n → ℝ)) × (Fin n → ℝ) => + (plantedInteraction j (goeMatrix (j/(n:ℝ)) p.1.1),((fun i=>t+p.1.2 i),p.2))) := + hsJ.prodMk (htime.prodMk continuous_snd) + have hφ := ((continuous_fieldMollifier j σ).comp hmap).measurable.ennreal_ofReal + have hI : Measurable (fun p : ((MatrixCoordinates (Fin n) → ℝ) × (Fin n → ℝ)) × (Fin n → ℝ) => + E.indicator (fun _=>(1 : ℝ≥0∞)) ((fun q=>goeMatrix (j/(n:ℝ)) p.1.1 q.1 q.2),p.2)) := by + apply (measurable_const.indicator hE).comp + unfold goeMatrix + fun_prop + have hH : Measurable H := hφ.mul hI + have he (g : MatrixCoordinates (Fin n) → ℝ) (x : Fin n → ℝ) : + fieldIntegral j σ (plantedInteraction j (goeMatrix (j/(n:ℝ)) g)) + (fun i=>t+x i) {y | ((fun p=>goeMatrix (j/(n:ℝ)) g p.1 p.2),y)∈E}= + ∫⁻ y,H ((g,x),y) := by + have hs : MeasurableSet {y : Fin n → ℝ | ((fun p=>goeMatrix (j/(n:ℝ)) g p.1 p.2),y)∈E} := hE.preimage (by fun_prop) + erw [fieldIntegral_indicator _ _ _ _ _ hs] + apply lintegral_congr + intro y + dsimp [H] + by_cases hy : ((fun p=>goeMatrix (j/(n:ℝ)) g p.1 p.2),y)∈E <;> simp [hy] + simp_rw [he] + change (∫⁻ g,∫⁻ x,∫⁻ y,H ((g,x),y) ∂volume ∂ν ∂μ)=_ + rw [← lintegral_prod _ hH.lintegral_prod_right'.aemeasurable, + lintegral_lintegral_swap hH.aemeasurable] + apply lintegral_congr + intro y + have hh : Measurable (fun p : (MatrixCoordinates (Fin n) → ℝ) × (Fin n → ℝ) => H (p,y)) := hH.comp (by fun_prop) + rw [lintegral_prod _ hh.aemeasurable] + exact field_reduction_fixed hj ht hσ E hE y +end SKGap +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Stability/FixedTimeAnnealed.lean b/lean/OAI/Probability/SKGap/Stability/FixedTimeAnnealed.lean new file mode 100644 index 0000000000000000000000000000000000000000..efff4c214381fa9683cfc9b176b4e9f10656a594 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Stability/FixedTimeAnnealed.lean @@ -0,0 +1,119 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.PlantedTilt +import OAI.Probability.SKGap.Localization.PlantedMarginalLaw + +namespace OAI + +section + +noncomputable section +namespace SKGap.ObservationBridge +open Matrix Real Set MeasureTheory ProbabilityTheory +open scoped BigOperators ENNReal NNReal +variable {n : ℕ} +local instance annealedMatrixMeasurable : MeasurableSpace (Matrix (Fin n) (Fin n) ℝ) := borel _ +local instance annealedMatrixBorel : BorelSpace (Matrix (Fin n) (Fin n) ℝ) := ⟨rfl⟩ + +def gibbsObservationBad (j A K ε c ρ t : ℝ) (s : Spin n) : Set (Disorder n × Field n) := + {p | (coupling p.1,(fun i=>t*spinValue (s i)+p.2 i))∈literalBadPair j A K ε c ρ} + +lemma measurableSet_gibbsObservationBad (j A K ε c ρ t : ℝ) (s : Spin n) : + MeasurableSet (gibbsObservationBad j A K ε c ρ t s) := by + have hmap : Continuous (fun p : Disorder n × Field n=> + (coupling p.1,(fun i=>t*spinValue (s i)+p.2 i)) : + Disorder n × Field n→Matrix (Fin n) (Fin n) ℝ × Field n) := + (continuous_coupling.comp continuous_fst).prodMk (by fun_prop) + have hmmap : Measurable (fun p : Disorder n × Field n=> + (coupling p.1,(fun i=>t*spinValue (s i)+p.2 i)) : + Disorder n × Field n→Matrix (Fin n) (Fin n) ℝ × Field n) := hmap.measurable + exact (measurableSet_literalBadPair j A K ε c ρ).preimage hmmap + +def conditionalSpinFailure (j A K ε c ρ t : ℝ) (s : Spin n) (J : Disorder n) : ℝ≥0∞ := + (Measure.pi (fun _ : Fin n=>gaussianReal 0 t.toNNReal)) + ((Prod.mk J) ⁻¹' gibbsObservationBad j A K ε c ρ t s) + +lemma measurable_conditionalSpinFailure (j A K ε c ρ t : ℝ) (s : Spin n) : + Measurable (conditionalSpinFailure j A K ε c ρ t s) := + measurable_measure_prodMk_left (measurableSet_gibbsObservationBad j A K ε c ρ t s) +lemma conditionalSpinFailure_le_one (j A K ε c ρ t : ℝ) (s : Spin n) (J : Disorder n) : + conditionalSpinFailure j A K ε c ρ t s J ≤ 1 := prob_le_one + +def fixedTimeFailureENN (j A K ε c ρ t : ℝ) (J : Disorder n) : ℝ≥0∞ := + ∑ s : Spin n, ENNReal.ofReal (mass J 0 s)*conditionalSpinFailure j A K ε c ρ t s J + +lemma measurable_fixedTimeFailureENN (j A K ε c ρ t : ℝ) : + Measurable (fixedTimeFailureENN (n:=n) j A K ε c ρ t) := by + apply Finset.measurable_sum + intro s _ + have hm : Measurable (fun J : Disorder n=>mass J 0 s) := by + simpa only [sqrt_one,one_mul] using scaled_spin_mass_measurable 1 s + exact hm.ennreal_ofReal.mul (measurable_conditionalSpinFailure j A K ε c ρ t s) + +lemma fixedTimeFailureENN_le_one (j A K ε c ρ t : ℝ) (J : Disorder n) : + fixedTimeFailureENN j A K ε c ρ t J ≤ 1 := by + calc + _ ≤ ∑ s : Spin n, ENNReal.ofReal (mass J 0 s)*1 := + Finset.sum_le_sum (fun s _=>mul_le_mul_right (conditionalSpinFailure_le_one j A K ε c ρ t s J) _) + _ = 1 := by + simp only [mul_one] + rw [← ENNReal.ofReal_sum_of_nonneg (fun s _=>mass_nonneg J 0 s),sum_mass,ENNReal.ofReal_one] + +lemma planted_spin_failure_integral (s : Spin n) (r j A K ε c ρ t : ℝ) : + (∫⁻ g : Disorder n,conditionalSpinFailure j A K ε c ρ t s (plantedEdges r s g) + ∂gaussianCoordinates (Edge n)) = + ((gaussianCoordinates (Edge n)).prod (Measure.pi (fun _ : Fin n=>gaussianReal 0 t.toNNReal))) + {p | (coupling (plusPlantedEdges r p.1),(fun i=>t+p.2 i))∈literalBadPair j A K ε c ρ} := by + let E := (Prod.map (plantedEdges r s) id) ⁻¹' gibbsObservationBad j A K ε c ρ t s + have hE : MeasurableSet E := (measurableSet_gibbsObservationBad j A K ε c ρ t s).preimage + ((show Measurable (plantedEdges r s) by unfold plantedEdges;fun_prop).prodMap measurable_id) + have he := Measure.prod_apply (μ:=gaussianCoordinates (Edge n)) + (ν:=Measure.pi (fun _ : Fin n=>gaussianReal 0 t.toNNReal)) hE + exact he.symm.trans (gauged_fixed_time_probability s r j A K ε c ρ t) + +theorem fixed_time_size_bias_identity (β A K ε c ρ t : ℝ) : + (∫⁻ J : Disorder n, + ENNReal.ofReal (partition J 0/(∫ J,partition J 0 ∂disorderLaw β n))* + fixedTimeFailureENN (β^2) A K ε c ρ t J ∂disorderLaw β n) = + ((gaussianCoordinates (MatrixCoordinates (Fin n))).prod + (Measure.pi (fun _ : Fin n=>gaussianReal 0 t.toNNReal))) + (erasedPlantedRootBad n (β^2) A K ε c ρ t) := by + rw [show fixedTimeFailureENN (n:=n) (β^2) A K ε c ρ t = + (fun J=>∑ s,ENNReal.ofReal (mass J 0 s)*conditionalSpinFailure (β^2) A K ε c ρ t s J) from rfl] + rw [planted_disorder_joint_tilt β _ (fun s=>measurable_conditionalSpinFailure (β^2) A K ε c ρ t s)] + have he (s : Spin n) : + (∫⁻ g : Disorder n,conditionalSpinFailure (β^2) A K ε c ρ t s + (fun e=>sqrt (β^2/(n:ℝ))*g e+β^2/(n:ℝ)*spinValue (s e.1.1)*spinValue (s e.1.2)) + ∂gaussianCoordinates (Edge n)) = + ((gaussianCoordinates (MatrixCoordinates (Fin n))).prod + (Measure.pi (fun _ : Fin n=>gaussianReal 0 t.toNNReal))) + (erasedPlantedRootBad n (β^2) A K ε c ρ t) := + (planted_spin_failure_integral s _ _ _ _ _ _ _ _).trans + (plus_planted_marginal_probability (sq_nonneg β) A K ε c ρ t) + simp_rw [he] + rw [Finset.sum_const,Finset.card_univ,nsmul_eq_mul,← mul_assoc] + have hc : (Fintype.card (Spin n):ℝ) ≠ 0 := by positivity + have hh : ENNReal.ofReal (1/(Fintype.card (Spin n):ℝ))*(Fintype.card (Spin n):ℝ≥0∞)=1 := by + rw [← ENNReal.ofReal_natCast,← ENNReal.ofReal_mul (by positivity : (0:ℝ)≤1/(Fintype.card (Spin n):ℝ))] + simp + rw [hh,one_mul] + +theorem annealed_fixed_time_root_stability {β T : ℝ} (hβ : 0<β) (hβ1 : β<1) (hT : 0by simpa only [spinMatrixAct_involutive] using htrans _ h,htrans _⟩ + +lemma literalBadPair_spin_iff (s : Spin n) (j A K ε c ρ : ℝ) + (J : Matrix (Fin n) (Fin n) ℝ) (h : Field n) : + (spinMatrixAct s J,spinAct s h)∈literalBadPair j A K ε c ρ ↔ + (J,h)∈literalBadPair j A K ε c ρ := by + change (operatorBound K (spinMatrixAct s J) ∧ rootBad j A ε c ρ (spinMatrixAct s J) (spinAct s h)) ↔ _ + rw [operatorBound_spin_iff] + refine and_congr_right (fun _=>⟨fun hh=>?_,spinAct_bad s j A ε c ρ J h⟩) + simpa only [spinMatrixAct_involutive,spinAct_involutive] using + spinAct_bad s j A ε c ρ (spinMatrixAct s J) (spinAct s h) hh + +lemma gaussianSign_variance_preserving {κ : Type*} [Fintype κ] + (q : κ→ℝ) (hq : ∀ i,q i^2=1) (v : ℝ≥0) : + MeasurePreserving (gaussianSignEquiv q hq) + (Measure.pi (fun _ : κ=>gaussianReal 0 v)) (Measure.pi (fun _ : κ=>gaussianReal 0 v)) := by + refine ⟨(gaussianSignEquiv q hq).measurable,?_⟩ + have he (i : κ) : (gaussianReal 0 v).map (fun x=>q i*x)=gaussianReal 0 v := by + rcases sq_eq_one_iff.mp (hq i) with h|h + · simp [h] + · simpa only [h,neg_one_mul,neg_zero] using (gaussianReal_map_neg (μ:=(0:ℝ)) (v:=v)) + change (Measure.pi (fun _ : κ=>gaussianReal 0 v)).map (fun g i=>q i*g i)=_ + rw [Measure.pi_map_pi (fun _=>by fun_prop)] + simp only [he] + +def edgeSpinSign (s : Spin n) (e : Edge n) : ℝ := spinValue (s e.1.1)*spinValue (s e.1.2) +lemma edgeSpinSign_sq (s : Spin n) (e : Edge n) : edgeSpinSign s e^2=1 := by + simp only [edgeSpinSign,mul_pow,spinValue_sq,one_mul] + +def plantedEdges (r : ℝ) (s : Spin n) (g : Disorder n) : Disorder n := + fun e=>sqrt r*g e+r*spinValue (s e.1.1)*spinValue (s e.1.2) +def plusPlantedEdges (r : ℝ) (g : Disorder n) : Disorder n := fun e=>sqrt r*g e+r + +lemma coupling_planted_gauge (s : Spin n) (r : ℝ) (g : Disorder n) : + spinMatrixAct s (coupling (plantedEdges r s g)) = + coupling (plusPlantedEdges r (gaussianSignEquiv (edgeSpinSign s) (edgeSpinSign_sq s) g)) := by + ext i k + unfold spinMatrixAct coupling + split_ifs with h h + · dsimp [plantedEdges,plusPlantedEdges,gaussianSignEquiv,edgeSpinSign] + calc + _ = sqrt r*(spinValue (s i)*spinValue (s k)*g ⟨(i,k),h⟩)+r*(spinValue (s i))^2*(spinValue (s k))^2 := by ring + _ = _ := by rw [spinValue_sq,spinValue_sq,mul_one,mul_one]; rfl + · dsimp [plantedEdges,plusPlantedEdges,gaussianSignEquiv,edgeSpinSign] + calc + _ = sqrt r*(spinValue (s k)*spinValue (s i)*g ⟨(k,i),h⟩)+r*(spinValue (s i))^2*(spinValue (s k))^2 := by ring + _ = _ := by rw [spinValue_sq,spinValue_sq,mul_one,mul_one]; rfl + · simp + +lemma spin_observation (s : Spin n) (t : ℝ) (b : Field n) : + spinAct s (fun i=>t*spinValue (s i)+b i)=(fun i=>t+spinAct s b i) := by + ext i + dsimp [spinAct] + calc + _ = t*(spinValue (s i))^2+spinValue (s i)*b i := by ring + _ = _ := by rw [spinValue_sq,mul_one] + +lemma continuous_coupling : Continuous (coupling (n:=n)) := by + apply continuous_pi + intro i + apply continuous_pi + intro k + unfold coupling + split_ifs <;> fun_prop + +theorem gauged_fixed_time_probability (s : Spin n) (r j A K ε c ρ t : ℝ) : + ((gaussianCoordinates (Edge n)).prod (Measure.pi (fun _ : Fin n=>gaussianReal 0 t.toNNReal))) + {p | (coupling (plantedEdges r s p.1),(fun i=>t*spinValue (s i)+p.2 i))∈literalBadPair j A K ε c ρ} = + ((gaussianCoordinates (Edge n)).prod (Measure.pi (fun _ : Fin n=>gaussianReal 0 t.toNNReal))) + {p | (coupling (plusPlantedEdges r p.1),(fun i=>t+p.2 i))∈literalBadPair j A K ε c ρ} := by + let V := gaussianSignEquiv (edgeSpinSign s) (edgeSpinSign_sq s) + let W := gaussianSignEquiv (fun i=>spinValue (s i)) (fun i=>spinValue_sq (s i)) + have hV := gaussianSign_variance_preserving (edgeSpinSign s) (edgeSpinSign_sq s) 1 + have hW := gaussianSign_variance_preserving (fun i=>spinValue (s i)) (fun i=>spinValue_sq (s i)) t.toNNReal + have hm := hV.prod hW + let E := {p : Disorder n × Field n | + (coupling (plusPlantedEdges r p.1),(fun i=>t+p.2 i))∈literalBadPair j A K ε c ρ} + have hmap : Continuous (fun p : Disorder n × Field n => + ((coupling (plusPlantedEdges r p.1)),(fun i=>t+p.2 i)) : + Disorder n × Field n → Matrix (Fin n) (Fin n) ℝ × Field n) := + (continuous_coupling.comp (by unfold plusPlantedEdges;fun_prop)).prodMk (by fun_prop) + have hmmap : Measurable (fun p : Disorder n × Field n => + ((coupling (plusPlantedEdges r p.1)),(fun i=>t+p.2 i)) : + Disorder n × Field n → Matrix (Fin n) (Fin n) ℝ × Field n) := hmap.measurable + have hE : MeasurableSet E := (measurableSet_literalBadPair j A K ε c ρ).preimage hmmap + have he : {p : Disorder n × Field n | + (coupling (plantedEdges r s p.1),(fun i=>t*spinValue (s i)+p.2 i))∈literalBadPair j A K ε c ρ} = + (Prod.map V W) ⁻¹' E := by + ext p + change _ ↔ (coupling (plusPlantedEdges r (V p.1)),fun i=>t+W p.2 i)∈literalBadPair j A K ε c ρ + have hh := literalBadPair_spin_iff s j A K ε c ρ + (coupling (plantedEdges r s p.1)) (fun i=>t*spinValue (s i)+p.2 i) + rw [coupling_planted_gauge,spin_observation] at hh + exact hh.symm + rw [he] + exact hm.measure_preimage hE.nullMeasurableSet +end SKGap.ObservationBridge + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Stability/GaugedField.lean b/lean/OAI/Probability/SKGap/Stability/GaugedField.lean new file mode 100644 index 0000000000000000000000000000000000000000..e8821048ba386fe7f0358fc4f270d6165be44960 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Stability/GaugedField.lean @@ -0,0 +1,246 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.SampledFlatCLM + +namespace OAI + +section +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open scoped BigOperators +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open scoped BigOperators +open scoped BigOperators NNReal ENNReal +open MeasureTheory Metric Set +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators NNReal ENNReal Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Set +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators ENNReal NNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Matrix +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators ENNReal NNReal +namespace SKGapCutoff.Regression + +noncomputable def gaugedField {n : ℕ} (x : Spin n) (g : GaussianCoordinates n) : Fin n → ℝ := + fun i => spin x i * field (sampledInteraction g) x i + +noncomputable def gaugeFieldCLM {n : ℕ} (x : Spin n) : GaussianCoordinates n →L[ℝ] (Fin n → ℝ) := + ContinuousLinearMap.pi fun i => ∑ j, (spin x i * spin x j) • + (ContinuousLinearMap.proj (i,j) : GaussianCoordinates n →L[ℝ] ℝ) + +lemma gaugeFieldCLM_sampled {n : ℕ} (x : Spin n) (g : GaussianCoordinates n) : + gaugeFieldCLM x (fun p => sampledInteraction g p.1 p.2) = gaugedField x g := by + ext i + simp [gaugeFieldCLM, gaugedField, field, Finset.mul_sum, mul_left_comm, mul_comm] + +lemma gaugedField_gaussian (β : ℝ) {n : ℕ} (hn : 0 < n) (x : Spin n) : + HasGaussianLaw (gaugedField x) (singleSpinPlantedLaw β x) := by + exact ((sampled_planted_gaussian β hn x).map_fun (gaugeFieldCLM x)).congr + (Eventually.of_forall (gaugeFieldCLM_sampled x)) + +lemma sum_off_diagonal_const {n : ℕ} (i : Fin n) (c : ℝ) : + (∑ j : Fin n, if i=j then 0 else c) = ((n:ℝ)-1)*c := by + have he (j : Fin n) : (if i=j then (0:ℝ) else c) = c - if j=i then c else 0 := by + by_cases h : i=j <;> simp [h, eq_comm] + simp_rw [he] + simp [Finset.sum_sub_distrib] + ring + +lemma gaugedField_mean (β : ℝ) {n : ℕ} (hn : 0 < n) (x : Spin n) (i : Fin n) : + (∫ g, gaugedField x g i ∂singleSpinPlantedLaw β x) = β^2*((n:ℝ)-1)/(n:ℝ) := by + unfold gaugedField field + rw [integral_const_mul, integral_finsetSum] + · simp_rw [integral_mul_const] + have hm (j : Fin n) := sampled_planted_mean β hn x (i,j) + simp only at hm + simp_rw [hm] + rw [Finset.mul_sum] + have he (j : Fin n) : spin x i * + ((if i=j then 0 else β^2/(n:ℝ)*spin x i*spin x j)*spin x j) = + if i=j then 0 else β^2/(n:ℝ) := by + by_cases h : i=j + · simp [h] + · simp only [h, ite_false] + have h1 := spin_sq x i + have h2 := spin_sq x j + nlinarith [congrArg (fun a : ℝ => β^2/(n:ℝ)*a) (show (spin x i*spin x j)^2=1 by simp [mul_pow])] + simp_rw [he] + rw [sum_off_diagonal_const] + ring + · intro j _ + exact (((sampled_planted_gaussian β hn x).eval (i,j)).integrable.mul_const _) + +lemma gauged_entry_covariance (β : ℝ) {n : ℕ} (hn : 0 < n) (x : Spin n) + (i j k l : Fin n) : + cov[fun g => spin x i*spin x j*sampledInteraction g i j, + fun g => spin x k*spin x l*sampledInteraction g k l; singleSpinPlantedLaw β x] = + if i=j ∨ k=l then 0 else β^2/(n:ℝ)* + ((if i=k ∧ j=l then 1 else 0)+(if i=l ∧ j=k then 1 else 0)) := by + rw [covariance_const_mul_left, covariance_const_mul_right, sampled_planted_covariance β hn x (i,j) (k,l)] + by_cases h : i=j ∨ k=l + · simp [h] + rw [ite_eq_right h] + by_cases h1 : i=k ∧ j=l + · rcases h1 with ⟨hik,hjl⟩ + subst k + subst l + have h2 : ¬ (i=j ∧ j=i) := fun h' => h (Or.inl h'.1) + rw [ite_eq_left ⟨rfl,rfl⟩, ite_eq_right h2, add_zero, mul_one] + calc + _ = (β^2/(n:ℝ))*(spin x i*spin x j)^2 := by ring + _ = _ := by simp [mul_pow] + by_cases h2 : i=l ∧ j=k + · rcases h2 with ⟨hil,hjk⟩ + subst l + subst k + rw [ite_eq_right h1, ite_eq_left ⟨rfl,rfl⟩, zero_add, mul_one] + calc + _ = (β^2/(n:ℝ))*(spin x i*spin x j)^2 := by ring + _ = _ := by simp [mul_pow] + · rw [ite_eq_right h1, ite_eq_right h2] + ring + +lemma sum_covariance_pattern {n : ℕ} (i k : Fin n) (c : ℝ) : + (∑ j : Fin n, ∑ l : Fin n, if i=j ∨ k=l then 0 else c* + ((if i=k ∧ j=l then (1:ℝ) else 0)+(if i=l ∧ j=k then 1 else 0))) = + if i=k then c*((n:ℝ)-1) else c := by + by_cases h : i=k + · subst k + have he (j l : Fin n) : + (if i=j ∨ i=l then 0 else c*((if i=i ∧ j=l then (1:ℝ) else 0)+ + (if i=l ∧ j=i then 1 else 0))) = if j=l then (if i=j then 0 else c) else 0 := by + by_cases hj : i=j <;> by_cases hl : i=l <;> by_cases hjl : j=l <;> simp [hj,hl,hjl] + calc + _ = ∑ j : Fin n, ∑ l : Fin n, if j=l then (if i=j then 0 else c) else 0 := by + apply Finset.sum_congr rfl + intro j _ + apply Finset.sum_congr rfl + intro l _ + exact he j l + _ = _ := by + simp only [Finset.sum_ite_eq, Finset.mem_univ, ite_true] + rw [sum_off_diagonal_const] + ring + · have he (j l : Fin n) : + (if i=j ∨ k=l then 0 else c*((if i=k ∧ j=l then (1:ℝ) else 0)+ + (if i=l ∧ j=k then 1 else 0))) = if j=k then (if l=i then c else 0) else 0 := by + by_cases hj : j=k <;> by_cases hl : l=i <;> simp_all [eq_comm] + simp_rw [he] + simp [h] + +lemma gaugedField_covariance (β : ℝ) {n : ℕ} (hn : 0 < n) (x : Spin n) (i k : Fin n) : + cov[fun g => gaugedField x g i, fun g => gaugedField x g k; singleSpinPlantedLaw β x] = + if i=k then β^2*((n:ℝ)-1)/(n:ℝ) else β^2/(n:ℝ) := by + have he (i : Fin n) (g : GaussianCoordinates n) : gaugedField x g i = + ∑ j, (spin x i*spin x j)*sampledInteraction g i j := by + simp [gaugedField, field, Finset.mul_sum, mul_left_comm, mul_comm] + let := singleSpinPlantedLaw_probability β hn x + simp_rw [he] + rw [covariance_fun_sum_fun_sum] + · simp_rw [gauged_entry_covariance β hn, sum_covariance_pattern] + split_ifs <;> ring + · exact fun j => ((sampled_planted_gaussian β hn x).eval (i,j)).memLp_two.const_mul _ + · exact fun l => ((sampled_planted_gaussian β hn x).eval (k,l)).memLp_two.const_mul _ + +noncomputable def sharedGaussianField {n : ℕ} (m a b : ℝ) + (g : Option (Fin n) → ℝ) : Fin n → ℝ := fun i => m + a*g (some i) + b*g none + +noncomputable def sharedGaussianFieldCLM (n : ℕ) (a b : ℝ) : + (Option (Fin n) → ℝ) →L[ℝ] (Fin n → ℝ) := + ContinuousLinearMap.pi fun i => a • + (ContinuousLinearMap.proj (some i) : (Option (Fin n) → ℝ) →L[ℝ] ℝ) + + b • ContinuousLinearMap.proj none + +lemma sharedGaussianField_gaussian (n : ℕ) (m a b : ℝ) : + HasGaussianLaw (sharedGaussianField (n := n) m a b) (standardArrayLaw (Option (Fin n))) := by + have hh := gaussian_add_constant (coordinates_gaussian.map_fun (sharedGaussianFieldCLM n a b)) + (fun _ : Fin n => m) + apply hh.congr + exact Eventually.of_forall fun g => by + ext i + simp [sharedGaussianFieldCLM, sharedGaussianField] + ring + +lemma sharedGaussianField_mean {n : ℕ} (m a b : ℝ) (i : Fin n) : + (∫ g, sharedGaussianField m a b g i ∂standardArrayLaw (Option (Fin n))) = m := by + have ha := (coordinate_hasLaw (some i)).hasGaussianLaw.integrable.const_mul a + have hb := (coordinate_hasLaw (none : Option (Fin n))).hasGaussianLaw.integrable.const_mul b + simp only [sharedGaussianField] + have hai : Integrable (fun g : Option (Fin n) → ℝ => m+a*g (some i)) + (standardArrayLaw (Option (Fin n))) := (integrable_const m).add ha + rw [integral_add hai hb, + integral_add (integrable_const m) ha, integral_const_mul, integral_const_mul, + coordinate_mean, coordinate_mean] + simp + +lemma sharedGaussianField_covariance {n : ℕ} (m a b : ℝ) (i k : Fin n) : + cov[fun g => sharedGaussianField m a b g i, fun g => sharedGaussianField m a b g k; + standardArrayLaw (Option (Fin n))] = (if i=k then a^2 else 0)+b^2 := by + have hm (i : Fin n) : MemLp (fun g : Option (Fin n) → ℝ => a*g (some i)) 2 + (standardArrayLaw (Option (Fin n))) := (coordinate_hasLaw (some i)).hasGaussianLaw.memLp_two.const_mul a + have hb : MemLp (fun g : Option (Fin n) → ℝ => b*g none) 2 + (standardArrayLaw (Option (Fin n))) := (coordinate_hasLaw none).hasGaussianLaw.memLp_two.const_mul b + have he (g : Option (Fin n) → ℝ) (i : Fin n) : sharedGaussianField m a b g i = + (a*g (some i)+b*g none)+m := by unfold sharedGaussianField; ring + have hs (j : Fin n) : Integrable (fun g : Option (Fin n) → ℝ => a*g (some j)+b*g none) + (standardArrayLaw (Option (Fin n))) := ((hm j).add hb).integrable (by norm_num) + simp_rw [he] + rw [covariance_add_const_left (hs i), + covariance_add_const_right (hs k)] + change cov[(fun g => a*g (some i))+(fun g => b*g none), + (fun g => a*g (some k))+(fun g => b*g none); standardArrayLaw (Option (Fin n))] = _ + rw [covariance_add_left (hm i) hb ((hm k).add hb), + covariance_add_right (hm i) (hm k) hb, + covariance_add_right hb (hm k) hb] + simp_rw [covariance_const_mul_left, covariance_const_mul_right, coordinate_covariance] + by_cases h : i=k <;> simp [h] <;> ring + +lemma planted_field_representation (β : ℝ) {n : ℕ} (hn : 2 ≤ n) (x : Spin n) : + (singleSpinPlantedLaw β x).map (gaugedField x) = + (standardArrayLaw (Option (Fin n))).map + (sharedGaussianField (β^2*((n:ℝ)-1)/(n:ℝ)) + (β*Real.sqrt (((n:ℝ)-2)/(n:ℝ))) (β/Real.sqrt (n:ℝ))) := by + have hn0 : 0 < n := by omega + have hnR : (0:ℝ) < n := Nat.cast_pos.mpr hn0 + have hn2 : (2:ℝ) ≤ n := by exact_mod_cast hn + apply gaussian_vector_law_ext (gaugedField_gaussian β hn0 x) (sharedGaussianField_gaussian _ _ _ _) + · intro i + rw [gaugedField_mean β hn0, sharedGaussianField_mean] + · intro i k + rw [gaugedField_covariance β hn0, sharedGaussianField_covariance] + have ha : (β*Real.sqrt (((n:ℝ)-2)/(n:ℝ)))^2 = β^2*((n:ℝ)-2)/(n:ℝ) := by + rw [mul_pow, Real.sq_sqrt (by positivity)] + ring + have hb : (β/Real.sqrt (n:ℝ))^2 = β^2/(n:ℝ) := by + rw [div_pow, Real.sq_sqrt hnR.le] + rw [ha,hb] + split_ifs <;> field_simp <;> ring + +end SKGapCutoff.Regression + +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal + +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Stability/HalfDiffField.lean b/lean/OAI/Probability/SKGap/Stability/HalfDiffField.lean new file mode 100644 index 0000000000000000000000000000000000000000..f645eddecdf3b29007dc34efa3f148501cd8b233 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Stability/HalfDiffField.lean @@ -0,0 +1,416 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.PreparationGrowth + +namespace OAI + +section +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open scoped BigOperators +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open scoped BigOperators +open scoped BigOperators NNReal ENNReal +open MeasureTheory Metric Set +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators NNReal ENNReal Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Set +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators ENNReal NNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Matrix +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators ENNReal NNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal +open scoped BigOperators +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise NNReal ENNReal +open scoped BigOperators +open Filter Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal Topology +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Set Matrix +open scoped BigOperators NNReal ENNReal Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open Filter MeasureTheory ProbabilityTheory +open scoped Topology NNReal ENNReal +open Filter MeasureTheory ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter +open scoped Topology NNReal ENNReal +open MeasureTheory Filter ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter +open scoped Topology +open MeasureTheory Filter ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter ProbabilityTheory ContinuousLinearMap +open scoped Topology NNReal ENNReal +open Filter MeasureTheory ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter +open scoped BigOperators Topology +open MeasureTheory Filter +open scoped BigOperators Topology +open MeasureTheory Filter +open scoped BigOperators Topology +open MeasureTheory Filter +open scoped BigOperators Topology +open MeasureTheory Filter +open scoped BigOperators Topology +open Filter Set Metric +open scoped Topology RealInnerProductSpace +open scoped BigOperators +open ContinuousLinearMap +open scoped BigOperators +open ContinuousLinearMap +namespace SKGapCutoff +open RandomMatrix + +lemma halfDiff_field {n : ℕ} (J : Interaction n) (x : Spin n) (i j : Fin n) : + halfDiff i (fun y => field J y j) x = J j i := by + simp only [field, halfDiff_sum, halfDiff_mul, halfDiff_const, halfDiff_spin, + add_zero, mul_ite, mul_one, mul_zero] + simp + +lemma halfDiff_field_add {n : ℕ} (J : Interaction n) (g : VectorFields n) + (x : Spin n) (i j : Fin n) : + halfDiff i (fun y => field J y j+g y j) x = J j i+halfDiff i (fun y => g y j) x := by + rw [← halfDiff_field J x i j] + simp only [halfDiff] + ring + +lemma refreshSemigroup_eq_preparationFlow {n : ℕ} (J : Interaction n) + (g : VectorFields n) (t : ℝ) : + refreshSemigroup (fun x i => Real.tanh (field J x i+g x i)) t = preparationFlow J g t := by + rw [refreshSemigroup, refreshGeneratorCLM_eq, smul_smul, mul_comm t] + rfl + +theorem preparation_poincare {n : ℕ} (J : Interaction n) + (γ : ℝ) (hγ : 0 < γ) (hg : HasGap J γ) + (g : VectorFields n) (C : ℝ) (hC : 0 ≤ C) + (hJC : ‖Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) J‖ ≤ C) + (hgc : ∀ x, ‖Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) + (fun j i => halfDiff i (fun y => g y j) x)‖ ≤ 1) + (f : Observables n) (t : ℝ) (ht : 0 ≤ t) : + gibbsExpectation J (preparationFlow J g t (fun y => f y^2)) - + (gibbsExpectation J (preparationFlow J g t f))^2 ≤ + (γ⁻¹*Real.exp (preparationGrowth (C+1)*t)+ + 4*((Real.exp (preparationGrowth (C+1)*t)-1)/preparationGrowth (C+1)))* + gibbsExpectation J (preparationFlow J g t (fun y => ∑ i, (halfDiff i f y)^2)) := by + have hHC (x : Spin n) : ‖Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) + (fun j i => halfDiff i (fun y => field J y j+g y j) x)‖ ≤ C+1 := by + have he : Matrix.of (fun j i => halfDiff i (fun y => field J y j+g y j) x) = + J+Matrix.of (fun j i => halfDiff i (fun y => g y j) x) := by + ext j i + exact halfDiff_field_add J g x i j + change ‖Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) + (Matrix.of (fun j i => halfDiff i (fun y => field J y j+g y j) x))‖ ≤ C+1 + rw [he, map_add] + exact (norm_add_le _ _).trans (add_le_add hJC (hgc x)) + have hh := preparation_poincare_field J γ hγ hg (fun x i => field J x i+g x i) + (C+1) (by linarith) hHC f t ht + simpa only [refreshSemigroup_eq_preparationFlow] using hh + +end SKGapCutoff + +open scoped Topology Interval +open MeasureTheory +namespace SKGapCutoff + +lemma interval_hasFDerivAt_of_continuous + {H E : Type*} [NormedAddCommGroup H] [NormedSpace ℝ H] [ProperSpace H] + [NormedAddCommGroup E] [NormedSpace ℝ E] [CompleteSpace E] + (F : H → ℝ → E) (F' : H → ℝ → H →L[ℝ] E) + (hF : Continuous (Function.uncurry F)) (hF' : Continuous (Function.uncurry F')) + (hd : ∀ x t, HasFDerivAt (fun y => F y t) (F' x t) x) + (a b : ℝ) (x : H) : + HasFDerivAt (fun y => ∫ t in a..b, F y t) (∫ t in a..b, F' x t) x := by + obtain ⟨C,hC⟩ := ((isCompact_closedBall x 1).prod isCompact_uIcc).exists_bound_of_continuousOn + hF'.continuousOn + apply intervalIntegral.hasFDerivAt_integral_of_dominated_of_fderiv_le + (s := Metric.closedBall x 1) (bound := fun _ => C) (Metric.closedBall_mem_nhds x (by norm_num)) + · filter_upwards [] with y + exact (hF.comp (continuous_const.prodMk continuous_id)).aestronglyMeasurable + · exact (hF.comp (continuous_const.prodMk continuous_id)).intervalIntegrable _ _ + · exact (hF'.comp (continuous_const.prodMk continuous_id)).aestronglyMeasurable + · filter_upwards [] with t ht y hy + exact hC (y,t) ⟨hy, Set.uIoc_subset_uIcc ht⟩ + · exact intervalIntegrable_const + · filter_upwards [] with t _ y _ + exact hd y t + +lemma algebra_exp_contDiff {A : Type*} [NormedRing A] [NormedAlgebra ℝ A] + [CompleteSpace A] : ContDiff ℝ ⊤ (NormedSpace.exp : A → A) := by + exact contDiff_iff_contDiffAt.mpr (fun x => (NormedSpace.exp_analytic (𝕂 := ℝ) x).contDiffAt) + +lemma algebra_duhamel {A : Type*} [NormedRing A] [NormedAlgebra ℝ A] + [CompleteSpace A] (X Y : A) (t : ℝ) : + NormedSpace.exp (t • Y)-NormedSpace.exp (t • X) = + ∫ s in 0..t, NormedSpace.exp (s • X)*(Y-X)*NormedSpace.exp ((t-s) • Y) := by + let : NormedAlgebra ℚ A := NormedAlgebra.restrictScalars ℚ ℝ A + have hc : Continuous (fun s : ℝ => NormedSpace.exp (s • X)*(Y-X)*NormedSpace.exp ((t-s) • Y)) := by + fun_prop + have hd (s : ℝ) : HasDerivAt + (fun u : ℝ => NormedSpace.exp (u • X)*NormedSpace.exp ((t-u) • Y)) + (-(NormedSpace.exp (s • X)*(Y-X)*NormedSpace.exp ((t-s) • Y))) s := by + have h1 := hasDerivAt_exp_smul_const X s + have h2 := (hasDerivAt_exp_smul_const' Y (t-s)).scomp s + ((hasDerivAt_id s).const_sub t) + convert! h1.mul h2 using 1 + simp only [one_smul, neg_smul] + noncomm_ring + have hi := intervalIntegral.integral_eq_sub_of_hasDerivAt (fun s _ => hd s) + (hc.neg.intervalIntegrable 0 t) + simp only [intervalIntegral.integral_neg, sub_self, zero_smul, NormedSpace.exp_zero, + mul_one, one_mul, sub_zero] at hi + simpa only [neg_sub, neg_neg] using (congrArg Neg.neg hi).symm + +lemma algebra_exp_smul_hasFDerivAt {A : Type*} [NormedRing A] [NormedAlgebra ℝ A] + [CompleteSpace A] [ProperSpace A] (X : A) (t : ℝ) : + HasFDerivAt (fun Y : A => NormedSpace.exp (t • Y)) + (∫ s in 0..t, ContinuousLinearMap.mulLeftRight ℝ A + (NormedSpace.exp (s • X)) (NormedSpace.exp ((t-s) • X))) X := by + let F : A → ℝ → A := fun Y s => + NormedSpace.exp (s • X)*(Y-X)*NormedSpace.exp ((t-s) • Y) + have ce : ContDiff ℝ ⊤ (NormedSpace.exp : A → A) := algebra_exp_contDiff + have hF : ContDiff ℝ ⊤ (Function.uncurry F) := by + exact ((ce.comp (contDiff_snd.smul_const X)).mul (contDiff_fst.sub contDiff_const)).mul + (ce.comp ((contDiff_const.sub contDiff_snd).smul contDiff_fst)) + have hd (Y : A) (s : ℝ) : DifferentiableAt ℝ (fun Z => F Z s) Y := by + exact (hF.comp (contDiff_id.prodMk contDiff_const)).differentiable (by simp) |>.differentiableAt + have hc' : Continuous (fun p : A × ℝ => fderiv ℝ (fun Y => F Y p.2) p.1) := by + have hFF : ContDiff ℝ ⊤ (fun p : (A × ℝ) × A => F p.2 p.1.2) := + hF.comp (contDiff_snd.prodMk contDiff_fst.snd) + exact Continuous.fderiv (f := fun p : A × ℝ => fun Y => F Y p.2) + (g := fun p => p.1) hFF continuous_fst le_top + have hint := interval_hasFDerivAt_of_continuous F + (fun Y s => fderiv ℝ (fun Z => F Z s) Y) hF.continuous hc' + (fun Y s => (hd Y s).hasFDerivAt) 0 t X + have he (s : ℝ) : fderiv ℝ (fun Y => F Y s) X = + ContinuousLinearMap.mulLeftRight ℝ A (NormedSpace.exp (s • X)) + (NormedSpace.exp ((t-s) • X)) := by + have hdR : DifferentiableAt ℝ (fun Y : A => NormedSpace.exp ((t-s) • Y)) X := + (ce.comp (contDiff_id.const_smul (t-s))).differentiable (by simp) |>.differentiableAt + have hh := (((hasFDerivAt_id X).sub_const X).mul' hdR.hasFDerivAt).const_mul + (NormedSpace.exp (s • X)) + have hfun : (fun Y => NormedSpace.exp (s • X)*((Y-X)*NormedSpace.exp ((t-s) • Y))) = + (fun Y => F Y s) := by funext Y; exact (mul_assoc _ _ _).symm + simp only [Pi.mul_apply, id_eq] at hh + rw [hfun] at hh + rw [hh.fderiv] + ext Z + simp [ContinuousLinearMap.mulLeftRight_apply, mul_assoc] + simp_rw [he] at hint + have hfinal := hint.add_const (NormedSpace.exp (t • X)) + convert! hfinal using 1 + funext Y + rw [← algebra_duhamel X Y t] + exact (sub_add_cancel _ _).symm + +lemma algebra_exp_curve_hasDerivAt {A : Type*} [NormedRing A] [NormedAlgebra ℝ A] + [CompleteSpace A] [ProperSpace A] {L : ℝ → A} {L' : A} {θ : ℝ} + (hL : HasDerivAt L L' θ) (t : ℝ) : + HasDerivAt (fun u => NormedSpace.exp (t • L u)) + (∫ s in 0..t, NormedSpace.exp (s • L θ)*L'*NormedSpace.exp ((t-s) • L θ)) θ := by + have hc : Continuous (fun s : ℝ => ContinuousLinearMap.mulLeftRight ℝ A + (NormedSpace.exp (s • L θ)) (NormedSpace.exp ((t-s) • L θ))) := by + have ce : Continuous (NormedSpace.exp : A → A) := algebra_exp_contDiff.continuous + exact ((ContinuousLinearMap.mulLeftRight ℝ A).continuous.comp + (ce.comp (continuous_id.smul continuous_const))).clm_apply + (ce.comp ((continuous_const.sub continuous_id).smul continuous_const)) + have hh := (algebra_exp_smul_hasFDerivAt (L θ) t).comp_hasDerivAt θ hL + rw [ContinuousLinearMap.intervalIntegral_apply (hc.intervalIntegrable _ _) L'] at hh + exact hh + +noncomputable def meanGeneratorCLM {n : ℕ} (m : VectorFields n) : + Observables n →L[ℝ] Observables n := refreshGeneratorCLM m-refreshGeneratorCLM 0 + +lemma meanGeneratorCLM_apply {n : ℕ} (m : VectorFields n) (f : Observables n) (x : Spin n) : + meanGeneratorCLM m f x = ∑ i, m x i*halfDiff i f x := by + change (∑ i, (m x i-spin x i)*halfDiff i f x)- + (∑ i, (0-spin x i)*halfDiff i f x) = _ + rw [← Finset.sum_sub_distrib] + apply Finset.sum_congr rfl + intro i _ + ring + +noncomputable def meanGeneratorMapLM (n : ℕ) : + VectorFields n →ₗ[ℝ] (Observables n →L[ℝ] Observables n) where + toFun := meanGeneratorCLM + map_add' p q := by + ext f x + simp [meanGeneratorCLM_apply, add_mul, Finset.sum_add_distrib] + map_smul' a p := by + ext f x + simp [meanGeneratorCLM_apply, mul_assoc, Finset.mul_sum] + +noncomputable def meanGeneratorMap (n : ℕ) : + VectorFields n →L[ℝ] (Observables n →L[ℝ] Observables n) := + (meanGeneratorMapLM n).toContinuousLinearMap + +lemma meanGeneratorMap_apply {n : ℕ} (m : VectorFields n) : + meanGeneratorMap n m = meanGeneratorCLM m := rfl + +lemma refreshGeneratorCLM_eq_mean {n : ℕ} (m : VectorFields n) : + refreshGeneratorCLM m = meanGeneratorMap n m + refreshGeneratorCLM 0 := by + simp [meanGeneratorMap_apply, meanGeneratorCLM] + +lemma preparation_mean_hasDerivAt {n : ℕ} (H v : VectorFields n) (θ : ℝ) : + HasDerivAt (fun u : ℝ => (fun x i => Real.tanh (H x i+u*v x i) : VectorFields n)) + (fun x i => scalarVariance (H x i+θ*v x i)*v x i) θ := by + apply hasDerivAt_pi.mpr + intro x + apply hasDerivAt_pi.mpr + intro i + convert! (tanh_hasDerivAt (H x i+θ*v x i)).comp θ + (((hasDerivAt_id θ).mul_const (v x i)).const_add (H x i)) using 1 + simp + +lemma preparation_generator_hasDerivAt {n : ℕ} (H v : VectorFields n) (θ : ℝ) : + HasDerivAt (fun u : ℝ => refreshGeneratorCLM (fun x i => Real.tanh (H x i+u*v x i))) + (meanGeneratorCLM (fun x i => scalarVariance (H x i+θ*v x i)*v x i)) θ := by + have hh := ((meanGeneratorMap n).hasFDerivAt.comp_hasDerivAt θ + (preparation_mean_hasDerivAt H v θ)).add_const (refreshGeneratorCLM 0) + simp only [meanGeneratorMap_apply] at hh + convert! hh using 1 + funext u + exact refreshGeneratorCLM_eq_mean _ + +lemma preparation_semigroup_hasDerivAt {n : ℕ} (H v : VectorFields n) (θ h : ℝ) : + HasDerivAt (fun u : ℝ => refreshSemigroup (fun x i => Real.tanh (H x i+u*v x i)) h) + (∫ s in 0..h, + refreshSemigroup (fun x i => Real.tanh (H x i+θ*v x i)) s * + meanGeneratorCLM (fun x i => scalarVariance (H x i+θ*v x i)*v x i) * + refreshSemigroup (fun x i => Real.tanh (H x i+θ*v x i)) (h-s)) θ := by + exact algebra_exp_curve_hasDerivAt (preparation_generator_hasDerivAt H v θ) h + +theorem preparation_expectation_hasDerivAt {n : ℕ} (J : Interaction n) + (g v : VectorFields n) (θ h : ℝ) (f : Observables n) : + HasDerivAt (fun u : ℝ => gibbsExpectation J + (preparationFlow J (fun x i => g x i+u*v x i) h f)) + (∫ s in 0..h, gibbsExpectation J + (preparationFlow J (fun x i => g x i+θ*v x i) s + (fun x => ∑ i, scalarVariance (field J x i+g x i+θ*v x i)*v x i* + halfDiff i (preparationFlow J (fun x i => g x i+θ*v x i) (h-s) f) x))) θ := by + let m : VectorFields n := fun x i => Real.tanh (field J x i+g x i+θ*v x i) + let B := meanGeneratorCLM (fun x i => scalarVariance (field J x i+g x i+θ*v x i)*v x i) + have hc : Continuous (fun s : ℝ => refreshSemigroup m s*B*refreshSemigroup m (h-s)) := by + exact ((refreshSemigroup_continuous m).mul continuous_const).mul + ((refreshSemigroup_continuous m).comp (continuous_const.sub continuous_id)) + have hd := (preparation_semigroup_hasDerivAt (fun x i => field J x i+g x i) v θ h).clm_apply + (hasDerivAt_const θ f) + have hh := (expectationCLM J).hasFDerivAt.comp_hasDerivAt θ hd + simp only [map_zero, add_zero] at hh + change HasDerivAt _ (expectationCLM J ((∫ s in 0..h, + refreshSemigroup m s*B*refreshSemigroup m (h-s)) f)) θ at hh + rw [ContinuousLinearMap.intervalIntegral_apply (hc.intervalIntegrable _ _) f, + ← (expectationCLM J).intervalIntegral_comp_comm + ((hc.clm_apply continuous_const).intervalIntegrable _ _)] at hh + have he (u k : ℝ) : refreshSemigroup + (fun x i => Real.tanh (field J x i+g x i+u*v x i)) k = + preparationFlow J (fun x i => g x i+u*v x i) k := by + convert! refreshSemigroup_eq_preparationFlow J (fun x i => g x i+u*v x i) k using 1 + congr 1 + funext x i + congr 1 + ring + simp only [mul_apply_eq_comp, m, B, he] at hh + have hB (q : Observables n) : + meanGeneratorCLM (fun x i => scalarVariance (field J x i+g x i+θ*v x i)*v x i) q = + fun x => ∑ i, scalarVariance (field J x i+g x i+θ*v x i)*v x i*halfDiff i q x := by + funext x + exact meanGeneratorCLM_apply _ q x + simp_rw [hB] at hh + exact hh + +end SKGapCutoff + +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Stability/ImplicitCoefficient.lean b/lean/OAI/Probability/SKGap/Stability/ImplicitCoefficient.lean new file mode 100644 index 0000000000000000000000000000000000000000..6f5ff7444fee75d328135e3791b4450076301cdc --- /dev/null +++ b/lean/OAI/Probability/SKGap/Stability/ImplicitCoefficient.lean @@ -0,0 +1,226 @@ +import Mathlib +import OAI.Probability.SKGap.Stability.StableFields +import OAI.Probability.SKGap.Localization.Operation +import OAI.Probability.SKGap.Localization.PhiCoefficient +import OAI.Probability.SKGap.Stability.ImplicitLinear + +namespace OAI + +section + +noncomputable section +open scoped BigOperators +namespace SKGapCutoff.Recipe +open SKGap.Stein Primary +variable {n : ℕ} + +lemma vectorNorm_const (c : ℝ) : vectorNorm (fun _ : Fin n=>c)=|c| *Real.sqrt n := by + apply (sq_eq_sq₀ (vectorNorm_nonneg _) (by positivity)).mp + rw [vectorNorm_sq,mul_pow,sq_abs,Real.sq_sqrt (Nat.cast_nonneg n)] + simp [mul_comm] + +lemma vectorNorm_neg (v : Fin n→ℝ) : vectorNorm (-v)=vectorNorm v := by + exact norm_neg (WithLp.toLp 2 v : EuclideanSpace ℝ (Fin n)) +lemma vectorNorm_sub (u v : Fin n→ℝ) : vectorNorm (u-v)≤vectorNorm u+vectorNorm v := by + simpa only [sub_eq_add_neg,vectorNorm_neg] using vectorNorm_add u (-v) +lemma vectorNorm_tanh (z : Fin n→ℝ) : vectorNorm (fun i=>Real.tanh (z i))≤Real.sqrt n := by + simpa only [vectorNorm_const,abs_one,one_mul] using + (vectorNorm_mono (u:=fun i=>Real.tanh (z i)) (v:=fun _=>1) + (fun i=>by simpa using (Real.abs_tanh_lt_one (z i)).le)) +lemma vectorNorm_tanh_diff (z r : Fin n→ℝ) : + vectorNorm (fun i=>Real.tanh (z i)-Real.tanh (r i))≤vectorNorm (z-r) := + vectorNorm_mono fun i=>tanh_lipschitz (r i) (z i) + +lemma abs_logSlope_le_two (z r a : ℝ) : |logSlope z r a|≤2 := by + rw [logSlope,abs_div,abs_of_pos (phi_pos z r a),div_le_iff₀ (phi_pos z r a)] + exact phiZ_relative_bound z r a + +lemma vectorNorm_logSlope (z r : Fin n→ℝ) (a : ℝ) : + vectorNorm (fun i=>logSlope (z i) (r i) a)≤2*Real.sqrt n := by + simpa only [vectorNorm_const,abs_of_pos (by norm_num : (0:ℝ)<2)] using + (vectorNorm_mono (u:=fun i=>logSlope (z i) (r i) a) (v:=fun _=>2) + (fun i=>by simpa using abs_logSlope_le_two (z i) (r i) a)) + +lemma vectorNorm_logSlope_near (z r : Fin n→ℝ) (a : ℝ) : + vectorNorm (fun i=>logSlope (z i) (r i) a+Real.tanh (r i))≤3*vectorNorm (z-r) := by + have h:=vectorNorm_mono (u:=fun i=>logSlope (z i) (r i) a+Real.tanh (r i)) + (v:=fun i=>3*(z i-r i)) (fun i=>by simpa only [abs_mul,abs_of_pos (by norm_num : (0:ℝ)<3)] using + (logSlope_near_diagonal (z i) (r i) a)) + apply h.trans_eq + convert! vectorNorm_smul 3 (z-r) using 1 + norm_num + +lemma phi_near_current (z r a : ℝ) {R : ℝ} (ha : |a|≤R) : + |phi z r a-scalarVariance z|≤ + (2*Real.exp (R/2)+2)*|z-r|+(Real.exp (R/2)/2)*|a| := by + have he:=Real.exp_le_exp.mpr (show |a|/2≤R/2 by linarith) + have h₁:=(phi_near_root z r a).trans (mul_le_mul_of_nonneg_right he (by positivity)) + have h₂:=scalarVariance_lipschitz r z + have h₃:=abs_sub_le (phi z r a) (scalarVariance r) (scalarVariance z) + rw [abs_sub_comm (scalarVariance r)] at h₃ + linarith + +lemma vectorNorm_phi_near_current (z r : Fin n→ℝ) (a : ℝ) {R : ℝ} (ha : |a|≤R) : + vectorNorm (fun i=>phi (z i) (r i) a-scalarVariance (z i))≤ + (2*Real.exp (R/2)+2)*vectorNorm (z-r)+(Real.exp (R/2)/2)*|a| *Real.sqrt n := by + let E:=Real.exp (R/2) + have he:0≤E := (Real.exp_pos _).le + have hmono:=vectorNorm_mono (u:=fun i=>phi (z i) (r i) a-scalarVariance (z i)) + (v:=fun i=>(2*E+2)*|z i-r i|+(E/2)*|a|) (fun i=>by + rw [abs_of_nonneg (show 0≤(2*E+2)*|z i-r i|+(E/2)*|a| from by positivity)] + exact phi_near_current _ _ _ ha) + apply hmono.trans + have ht:=vectorNorm_add ((2*E+2) • (fun i=>|z i-r i|)) (fun _=>(E/2)*|a|) + rw [vectorNorm_smul,abs_of_nonneg (by positivity : 0≤2*E+2), + vectorNorm_abs,vectorNorm_const,abs_of_nonneg (by positivity : 0≤(E/2)*|a|)] at ht + exact ht + +lemma normalized_mean_bound (u : Fin n→ℝ) (hn : 0u) (fun _=>false) hn + change (n:ℝ)*((∑i,u i)/(n:ℝ))^2≤(vectorNorm u)^2 at hh + apply (sq_le_sq₀ (abs_nonneg _) (div_nonneg (vectorNorm_nonneg _) hs.le)).mp + rw [sq_abs, div_pow, div_pow, Real.sq_sqrt hnR.le] + exact (le_div_iff₀ hnR).mpr (by simpa only [div_pow, mul_comm] using hh) + +theorem implicit_coefficient_bounds (z r : Fin n→ℝ) (a : ℝ) (hn : 0phi (z i) (r i) a + let ell:=fun i=>logSlope (z i) (r i) a + let q:=fun i=>Real.tanh (z i) + (∀i,0scalarVariance (z i)))≤(3*E+2)*ρ*Real.sqrt n ∧ + |(∑i,A i)/(n:ℝ)-(∑i,scalarVariance (z i))/(n:ℝ)|≤(3*E+2)*ρ ∧ + vectorNorm (ell+q)≤4*ρ*Real.sqrt n ∧ + vectorNorm ell≤2*Real.sqrt n ∧ vectorNorm q≤Real.sqrt n := by + dsimp only + have hnR : (0:ℝ)phi (z i) (r i) a-scalarVariance (z i))≤ + (3*Real.exp (R/2)+2)*ρ*Real.sqrt n := by + apply (vectorNorm_phi_near_current z r a ha).trans + have h₁:=mul_le_mul_of_nonneg_left hz (by positivity : 0≤2*Real.exp (R/2)+2) + have h₂:=mul_le_mul_of_nonneg_right (mul_le_mul_of_nonneg_left haρ + (by positivity : 0≤Real.exp (R/2)/2)) hs.le + nlinarith only [h₁,h₂,mul_nonneg he.le (mul_nonneg hρ hs.le)] + refine ⟨fun i=>⟨phi_pos _ _ _,(phi_le_exp ..).trans (Real.exp_le_exp.mpr (by linarith))⟩,hA,?_,?_, + vectorNorm_logSlope z r a,vectorNorm_tanh z⟩ + · rw [←sub_div,←Finset.sum_sub_distrib] + exact (normalized_mean_bound _ hn).trans ((div_le_div_of_nonneg_right hA hs.le).trans_eq (by field_simp)) + · have h₁:=vectorNorm_logSlope_near z r a + have h₂:=vectorNorm_tanh_diff z r + have h₃:=vectorNorm_add (fun i=>logSlope (z i) (r i) a+Real.tanh (r i)) + (fun i=>Real.tanh (z i)-Real.tanh (r i)) + have heq : (fun i=>logSlope (z i) (r i) a+Real.tanh (r i))+ + (fun i=>Real.tanh (z i)-Real.tanh (r i))= + (fun i=>logSlope (z i) (r i) a)+(fun i=>Real.tanh (z i)) := by ext i; dsimp; ring + rw [heq] at h₃ + nlinarith only [h₁,h₂,h₃,hz] + +end SKGapCutoff.Recipe + +end +end + +section + +noncomputable section +namespace SKGap.ImplicitSystem +open SKGap.ImplicitLinear +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] + +lemma eliminated_rhs_bound (A : E →L[ℝ] E) (j p : ℝ) (u m t : E) : + ‖A (u-(j*p) • (m+t))‖≤‖A‖*(‖u‖+|j| *|p| *(‖m‖+‖t‖)) := by + calc + _ ≤ ‖A‖*‖u-(j*p) • (m+t)‖ := A.le_opNorm _ + _ ≤ ‖A‖*(‖u‖+‖(j*p) • (m+t)‖) := mul_le_mul_of_nonneg_left (norm_sub_le _ _) (norm_nonneg _) + _ ≤ _ := by + simp only [norm_smul,Real.norm_eq_abs,abs_mul] + exact mul_le_mul_of_nonneg_left (add_le_add (le_refl _) + (mul_le_mul_of_nonneg_left (norm_add_le m t) (mul_nonneg (abs_nonneg _) (abs_nonneg _)))) (norm_nonneg _) + +lemma implicit_scalar_size (r p : ℝ) (ell w : E) : + |r*inner ℝ ell w+p|≤|r| *‖ell‖*‖w‖+|p| := by + calc + _ ≤ |r*inner ℝ ell w|+|p| := abs_add_le _ _ + _ ≤ _ := by + rw [abs_mul] + nlinarith only [mul_le_mul_of_nonneg_left (abs_real_inner_le_norm ell w) (abs_nonneg r)] + +lemma implicit_field_size (J : E →L[ℝ] E) (j χ c : ℝ) (w m : E) : + ‖J w-(j*χ) • w-(j*c) • m‖≤(‖J‖+|j*χ|)*‖w‖+|j| *|c| *‖m‖ := by + calc + _ ≤ ‖J w-(j*χ) • w‖+‖(j*c) • m‖ := norm_sub_le _ _ + _ ≤ ‖J w‖+‖(j*χ) • w‖+‖(j*c) • m‖ := add_le_add (norm_sub_le _ _) (le_refl _) + _ ≤ _ := by + simp only [norm_smul,Real.norm_eq_abs,abs_mul] + nlinarith only [J.le_opNorm w] + +variable [FiniteDimensional ℝ E] + +theorem implicit_size_bounds (j χ b r p : ℝ) (X J : E →L[ℝ] E) + (u m t ell q w y : E) (c : ℝ) {δ : ℝ} (hδ : 0<δ) + (hStable : ∀v,δ*‖v‖^2 ≤ inner ℝ v (stableMatrix j b r X J q v)) + (hSmall : |j| *|χ-b| *‖X‖^2+|j*r| *‖X‖^2* + (‖m+t-(2:ℝ) • q‖*‖ell‖+2*‖q‖*‖ell+q‖)≤δ/2) + (hEq : Equations j χ r p (X*X) J u m t ell w y c) : + let W := (1+‖X‖^2*(δ/2)⁻¹*‖L₂ j χ r J (m+t) ell‖)* + ‖X‖^2*(‖u‖+|j| *|p| *(‖m‖+‖t‖)) + ‖w‖≤W ∧ |c|≤|r| *‖ell‖*W+|p| ∧ + ‖y‖≤(‖J‖+|j*χ|)*W+|j| *(|r| *‖ell‖*W+|p|)*‖m‖ := by + dsimp only + let W := (1+‖X‖^2*(δ/2)⁻¹*‖L₂ j χ r J (m+t) ell‖)* + ‖X‖^2*(‖u‖+|j| *|p| *(‖m‖+‖t‖)) + have hPert := (normalized_difference_bound j χ b r X J (m+t) ell q).trans hSmall + obtain ⟨B,hMB,hBM,hB⟩ := unnormalized_inverse X (L₂ j χ r J (m+t) ell) + (stableMatrix j b r X J q) (by linarith : δ/2<δ) hStable hPert + have hw : (1+X*X*L₂ j χ r J (m+t) ell) w=(X*X) (u-(j*p) • (m+t)) := by + apply (eliminated_equation j χ r p (X*X) J u m t ell w).mp + rcases hEq with ⟨hw,hy,hc⟩ + refine ⟨?_,rfl,rfl⟩ + simpa only [←hc,←hy] using hw + have hform : w=B ((X*X) (u-(j*p) • (m+t))) := by + rw [←hw] + change w=(B*(1+X*X*L₂ j χ r J (m+t) ell)) w + rw [hBM]; rfl + have hBB : ‖B‖≤1+‖X‖^2*(δ/2)⁻¹*‖L₂ j χ r J (m+t) ell‖ := by + convert hB using 2 + congr 2 + ring + have hwB : ‖w‖≤W := by + calc + ‖w‖=‖B ((X*X) (u-(j*p) • (m+t)))‖ := congrArg norm hform + _ ≤ ‖B‖*‖(X*X) (u-(j*p) • (m+t))‖ := B.le_opNorm _ + _ ≤ ‖B‖*(‖X*X‖*(‖u‖+|j| *|p| *(‖m‖+‖t‖))) := + mul_le_mul_of_nonneg_left (eliminated_rhs_bound (X*X) j p u m t) (norm_nonneg _) + _ ≤ W := by + dsimp [W] + have hX : ‖X*X‖≤‖X‖^2 := by simpa only [pow_two] using norm_mul_le X X + have h0 : 0≤‖u‖+|j| *|p| *(‖m‖+‖t‖) := by positivity + have hK : 0≤1+‖X‖^2*(δ/2)⁻¹*‖L₂ j χ r J (m+t) ell‖ := by positivity + calc + _ ≤ (1+‖X‖^2*(δ/2)⁻¹*‖L₂ j χ r J (m+t) ell‖)* + (‖X‖^2*(‖u‖+|j| *|p| *(‖m‖+‖t‖))) := + mul_le_mul hBB (mul_le_mul_of_nonneg_right hX h0) (by positivity) hK + _ = _ := by ring + have hcB : |c|≤|r| *‖ell‖*W+|p| := by + rw [hEq.2.2] + exact (implicit_scalar_size r p ell w).trans + (add_le_add (mul_le_mul_of_nonneg_left hwB (mul_nonneg (abs_nonneg _) (norm_nonneg _))) (le_refl _)) + refine ⟨hwB,hcB,?_⟩ + rw [hEq.2.1] + apply (implicit_field_size J j χ c w m).trans + exact add_le_add (mul_le_mul_of_nonneg_left hwB (by positivity)) + (mul_le_mul_of_nonneg_right (mul_le_mul_of_nonneg_left hcB (abs_nonneg j)) (norm_nonneg m)) + +end SKGap.ImplicitSystem + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Stability/ImplicitComparison.lean b/lean/OAI/Probability/SKGap/Stability/ImplicitComparison.lean new file mode 100644 index 0000000000000000000000000000000000000000..5b4df150ccfa5f7a4b0647a18f92a8ffe31966d5 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Stability/ImplicitComparison.lean @@ -0,0 +1,103 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.ResidualRecipe +import OAI.Probability.SKGap.Localization.PhiResponse + +namespace OAI + +section + +noncomputable section +open scoped BigOperators +namespace SKGapCutoff.Recipe +open Matrix SKGap.Stein +variable {n : ℕ} + +lemma implicit_scalar_cancellation (m t v : Fin n→ℝ) (b b₀ q : ℝ) + (hb : (∑i,(m i)^2)=(n:ℝ)*(1-b)) (hq : (∑i,(t i)^2)=(n:ℝ)*q) : + (∑i,(m i-t i)*(v i+t i))+(n:ℝ)*(b-b₀)= + (n:ℝ)*(1-b₀-q)+(∑i,(v i-m i)*(m i-t i)) := by + have HH : (∑i,(m i-t i)*(v i+t i))-(∑i,(v i-m i)*(m i-t i))= + (∑i,(m i)^2)-(∑i,(t i)^2) := by + rw [←Finset.sum_sub_distrib,←Finset.sum_sub_distrib] + apply Finset.sum_congr rfl;intro i _;ring + rw [hb,hq] at HH + linarith + +theorem implicit_comparison (J : Interaction n) (hJ : J.IsSymm) + (z r h v w y w₀ d₀ : Fin n→ℝ) (j b b₀ q χ c : ℝ) + (hroot : ∀i,r i-h i-J.mulVec (fun k=>Real.tanh (r k)) i+j*(1-q)*Real.tanh (r i)=0) + (hb : (∑i,(Real.tanh (z i))^2)=(n:ℝ)*(1-b)) + (hq : (∑i,(Real.tanh (r i))^2)=(n:ℝ)*q) + (hw : ∀i,w i=w₀ i+phi (z i) (r i) (j*(1-b₀-q))*(y i-j*c*Real.tanh (r i))) + (hy : ∀i,y i=J.mulVec w i-j*χ*w i-j*c*v i) + (hc : (n:ℝ)*c=∑i,(d₀ i+phiZ (z i) (r i) (j*(1-b₀-q))*(y i-j*c*Real.tanh (r i)))) : + (∑i,(z i-h i-J.mulVec (fun k=>Real.tanh (z k)) i+j*b₀*Real.tanh (z i))*w i)-j*(b-b₀)*(n:ℝ)*c= + (∑i,((z i-r i-j*(1-b₀-q)*Real.tanh (z i))*w₀ i-j*(1-b₀-q)*d₀ i))+ + j*(1-q-χ)*(∑i,(Real.tanh (z i)-Real.tanh (r i))*w i)- + j*c*(∑i,(v i-Real.tanh (z i))*(Real.tanh (z i)-Real.tanh (r i))) := by + let m:=fun i=>Real.tanh (z i) + let t:=fun i=>Real.tanh (r i) + let p:=m-t + let a:=j*(1-b₀-q) + have hfield (i : Fin n) : z i-h i-J.mulVec m i+j*b₀*m i= + z i-r i-a*m i-J.mulVec p i+j*(1-q)*p i := by + have hr:=hroot i + dsimp only [p,m,t,a,Pi.sub_apply] + rw [Matrix.mulVec_sub] + simp only [Pi.sub_apply] + linarith + have hcoord (i : Fin n) : + (z i-r i-a*m i)*w i=(z i-r i-a*m i)*w₀ i-a*d₀ i+ + p i*(y i-j*c*t i)+a*(d₀ i+phiZ (z i) (r i) a*(y i-j*c*t i)) := by + have hh:=phi_stein (z i) (r i) a + rw [hw i] + dsimp only [p,m,t,a,Pi.sub_apply] at * + linear_combination (y i-j*c*Real.tanh (r i))*hh + have hsym : (∑i,J.mulVec p i*w i)=(∑i,p i*J.mulVec w i) := by + have hh:=dotProduct_transpose_mulVec J w p + rw [hJ] at hh + simpa only [dotProduct,mul_comm] using hh + have hscalar:=implicit_scalar_cancellation m t v b b₀ q hb hq + have hc' : (n:ℝ)*c=∑i,(d₀ i+phiZ (z i) (r i) a*(y i-j*c*t i)) := hc + have hcoords : (∑i,(z i-r i-a*m i)*w i)= + (∑i,((z i-r i-a*m i)*w₀ i-a*d₀ i))+ + (∑i,p i*(y i-j*c*t i))+a*((n:ℝ)*c) := by + simp_rw [hcoord] + rw [Finset.sum_add_distrib,Finset.sum_add_distrib,←Finset.mul_sum,hc'] + have hpy : (∑i,p i*(y i-j*c*t i))=(∑i,p i*J.mulVec w i)- + j*χ*(∑i,p i*w i)-j*c*(∑i,p i*(v i+t i)) := by + simp only [hy,Finset.mul_sum,←Finset.sum_sub_distrib] + apply Finset.sum_congr rfl;intro i _;ring + have hsum : (∑i,(z i-h i-J.mulVec m i+j*b₀*m i)*w i)= + (∑i,((z i-r i-a*m i)*w₀ i-a*d₀ i))+a*((n:ℝ)*c)+ + j*(1-q-χ)*(∑i,p i*w i)-j*c*(∑i,p i*(v i+t i)) := by + calc + _ = (∑i,(z i-r i-a*m i)*w i)-(∑i,J.mulVec p i*w i)+j*(1-q)*(∑i,p i*w i) := by + simp only [hfield,sub_mul,add_mul,Finset.sum_add_distrib,Finset.sum_sub_distrib,Finset.mul_sum] + congr 1;apply Finset.sum_congr rfl;intros;ring + _ = _ := by rw [hcoords,hpy,hsym];ring + change (∑i,(z i-h i-J.mulVec m i+j*b₀*m i)*w i)-j*(b-b₀)*(n:ℝ)*c=_ + rw [hsum] + dsimp only [a,p,m,t,Pi.sub_apply] at * + linear_combination -j*c*hscalar + +lemma implicit_phi_source (z r : Fin n→ℝ) (a : ℝ) (e : Fin n→ℝ) : + (∑i,((z i-r i-a*Real.tanh (z i))*(phi (z i) (r i) a*e i)-a*(phiZ (z i) (r i) a*e i)))= + ∑i,(Real.tanh (z i)-Real.tanh (r i))*e i := by + apply Finset.sum_congr rfl;intro i _ + linear_combination e i*phi_stein (z i) (r i) a + +lemma implicit_phiR_source (z r : Fin n→ℝ) (a : ℝ) : + (∑i,((z i-r i-a*Real.tanh (z i))*(phiR (z i) (r i) a/Real.sqrt (n:ℝ))- + a*(phiRZ (z i) (r i) a/Real.sqrt (n:ℝ))))= + (∑i,(phi (z i) (r i) a-scalarVariance (r i)))/Real.sqrt (n:ℝ) := by + rw [Finset.sum_div] + apply Finset.sum_congr rfl;intro i _ + linear_combination (phiR_stein (z i) (r i) a)/Real.sqrt (n:ℝ) + +end SKGapCutoff.Recipe + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Stability/ImplicitFlip.lean b/lean/OAI/Probability/SKGap/Stability/ImplicitFlip.lean new file mode 100644 index 0000000000000000000000000000000000000000..2319623c70074a296157e13c4c18f3561b4a3153 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Stability/ImplicitFlip.lean @@ -0,0 +1,196 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.FrobeniusSq +import OAI.Probability.SKGap.Stability.ImplicitLinear + +namespace OAI + +section + +noncomputable section +namespace SKGap.ImplicitSystem +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] + +lemma equations_balance (j χ r p : ℝ) (A J : E →L[ℝ] E) (u m t ell w y : E) (c : ℝ) + (h : Equations j χ r p A J u m t ell w y c) : + w=A (u+J w-(j*χ) • w-(j*c) • (m+t)) := by + rcases h with ⟨hw,hy,hc⟩ + calc + w=A (u+y-(j*c) • t) := hw + _=A (u+J w-(j*χ) • w-(j*c) • (m+t)) := by + rw [hy] + congr 1 + module + +theorem implicit_difference_equation (j χ χ' r p p' : ℝ) + (A A' J : E →L[ℝ] E) (u u' m m' t ell ell' w w' y y' : E) (c c' : ℝ) + (h : Equations j χ r p A J u m t ell w y c) + (h' : Equations j χ' r p' A' J u' m' t ell' w' y' c') : + (1+A'*L₂ j χ' r J (m'+t) ell') (w-w')= + (A-A') (u+J w-(j*χ) • w-(j*c) • (m+t))+ + A' (u-u')-(j*(χ-χ')) • A' w-(j*c) • A' (m-m')- + (j*(r*inner ℝ (ell-ell') w+(p-p'))) • A' (m'+t) := by + have hw:=equations_balance j χ r p A J u m t ell w y c h + have hw':=equations_balance j χ' r p' A' J u' m' t ell' w' y' c' h' + have hc:=h.2.2 + have hc':=h'.2.2 + simp only [L₂,add_apply,sub_apply,smul_apply,neg_apply,one_apply_eq_self, + mul_apply_eq_comp,rank_apply,map_add,map_sub,map_smul,map_neg,inner_sub_left] at hw hw' ⊢ + rw [hc] at hw ⊢ + rw [hc'] at hw' + linear_combination (norm := module) hw-hw' + +theorem implicit_scaled_difference (s j χ χ' r p p' : ℝ) + (A A' J : E →L[ℝ] E) (u u' m m' t ell ell' w w' y y' : E) (c c' : ℝ) + (h : Equations j χ r p A J u m t ell w y c) + (h' : Equations j χ' r p' A' J u' m' t ell' w' y' c') : + (1+A'*L₂ j χ' r J (m'+t) ell') (s • (w-w'))= + (s • (A-A')) (u+J w-(j*χ) • w-(j*c) • (m+t))+ + A' (s • (u-u'))-(j*(s*(χ-χ'))) • A' w-(j*c) • A' (s • (m-m'))- + (j*(r*inner ℝ (s • (ell-ell')) w+s*(p-p'))) • A' (m'+t) := by + have H:=congrArg (fun x:E=>s • x) + (implicit_difference_equation j χ χ' r p p' A A' J u u' m m' t ell ell' w w' y y' c c' h h') + simp only [map_smul,smul_apply,real_inner_smul_left] at H ⊢ + linear_combination (norm := module) H + +lemma implicit_scalar_difference (s r p p' : ℝ) (ell ell' w w' : E) : + s*(r*inner ℝ ell w+p-(r*inner ℝ ell' w'+p'))= + r*inner ℝ (s • (ell-ell')) w+s*(p-p')+ + r*inner ℝ ell' (s • (w-w')) := by + simp only [real_inner_smul_left,real_inner_smul_right,inner_sub_left,inner_sub_right] + ring + +end SKGap.ImplicitSystem + +end +end + +section + +noncomputable section +open scoped BigOperators Matrix.Norms.Frobenius +namespace SKGap.ImplicitSystem +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] +variable {ι : Type*} [Fintype ι] + +def columnNorm (V : ι→E) : ℝ := ‖(WithLp.toLp 2 V : PiLp 2 (fun _ : ι=>E))‖ +omit [InnerProductSpace ℝ E] in +lemma columnNorm_nonneg (V : ι→E) : 0≤columnNorm V := norm_nonneg _ +omit [InnerProductSpace ℝ E] in +lemma columnNorm_sq (V : ι→E) : columnNorm V^2=∑i,‖V i‖^2 := by + exact PiLp.norm_sq_eq_of_L2 (fun _ : ι=>E) (WithLp.toLp 2 V : PiLp 2 (fun _ : ι=>E)) +omit [InnerProductSpace ℝ E] in +lemma columnNorm_add (U V : ι→E) : columnNorm (U+V)≤columnNorm U+columnNorm V := + norm_add_le (WithLp.toLp 2 U : PiLp 2 (fun _ : ι=>E)) (WithLp.toLp 2 V) +omit [InnerProductSpace ℝ E] in +lemma columnNorm_neg (V : ι→E) : columnNorm (-V)=columnNorm V := norm_neg _ +omit [InnerProductSpace ℝ E] in +lemma columnNorm_sub (U V : ι→E) : columnNorm (U-V)≤columnNorm U+columnNorm V := by + simpa only [sub_eq_add_neg,columnNorm_neg] using columnNorm_add U (-V) +lemma columnNorm_smul (a : ℝ) (V : ι→E) : columnNorm (a • V)=|a| *columnNorm V := + norm_smul a (WithLp.toLp 2 V : PiLp 2 (fun _ : ι=>E)) +omit [InnerProductSpace ℝ E] in +lemma columnNorm_bound {U V : ι→E} {C : ℝ} (hC : 0≤C) + (h : ∀i,‖U i‖≤C*‖V i‖) : columnNorm U≤C*columnNorm V := by + apply nonneg_le_nonneg_of_sq_le_sq (mul_nonneg hC (columnNorm_nonneg _)) + simp only [←sq,columnNorm_sq,mul_pow,Finset.mul_sum] + exact Finset.sum_le_sum fun i _=>by simpa only [mul_pow] using pow_le_pow_left₀ (norm_nonneg (U i)) (h i) 2 +lemma columnNorm_operator (A : ι→E→L[ℝ]E) (V : ι→E) {C : ℝ} + (hC : 0≤C) (hA : ∀i,‖A i‖≤C) : + columnNorm (fun i=>A i (V i))≤C*columnNorm V := by + apply columnNorm_bound hC + intro i; exact ((A i).le_opNorm _).trans (mul_le_mul_of_nonneg_right (hA i) (norm_nonneg _)) +lemma columnNorm_vector_scalar (V : ι→E) (a : ι→ℝ) {C : ℝ} + (hC : 0≤C) (hV : ∀i,‖V i‖≤C) : + columnNorm (fun i=>a i • V i)≤C*columnNorm a := by + apply nonneg_le_nonneg_of_sq_le_sq (mul_nonneg hC (columnNorm_nonneg _)) + simp only [←sq,columnNorm_sq,norm_smul,Real.norm_eq_abs,mul_pow,Finset.mul_sum] + exact Finset.sum_le_sum fun i _=>by + have h:=pow_le_pow_left₀ (norm_nonneg (V i)) (hV i) 2 + nlinarith only [mul_le_mul_of_nonneg_left h (sq_nonneg |a i|)] + +omit [InnerProductSpace ℝ E] in +lemma columnNorm_add_sub_sub_sub (a b c d e : ι→E) : + columnNorm (a+b-c-d-e)≤columnNorm a+columnNorm b+columnNorm c+columnNorm d+columnNorm e := by + have h₁:=columnNorm_add a b + have h₂:=columnNorm_sub (a+b) c + have h₃:=columnNorm_sub (a+b-c) d + have h₄:=columnNorm_sub (a+b-c-d) e + linarith + +variable [FiniteDimensional ℝ E] + +lemma column_inverse_estimate (X L S : ι→E→L[ℝ]E) (U V : ι→E) + {δ X₀ L₀ : ℝ} (hδ : 0<δ) (hX₀ : 0≤X₀) (hL₀ : 0≤L₀) + (hX : ∀i,‖X i‖≤X₀) (hL : ∀i,‖L i‖≤L₀) + (hS : ∀i v,δ*‖v‖^2≤ inner ℝ v (S i v)) + (hPert : ∀i,‖(1+X i*L i*X i)-S i‖≤δ/2) + (hEq : ∀i,(1+X i*X i*L i) (U i)=V i) : + columnNorm U≤(1+X₀^2*(δ/2)⁻¹*L₀)*columnNorm V := by + apply columnNorm_bound (by positivity) + intro i + obtain ⟨B,hMB,hBM,hB⟩:=SKGap.ImplicitLinear.unnormalized_inverse (X i) (L i) (S i) + (by linarith : δ/2<δ) (hS i) (hPert i) + have he : U i=B (V i) := by + rw [←hEq i] + change U i=(B*(1+X i*X i*L i)) (U i) + rw [hBM]; rfl + rw [he] + apply (B.le_opNorm _).trans + apply mul_le_mul_of_nonneg_right _ (norm_nonneg _) + apply hB.trans + have hX2 : ‖X i‖^2≤X₀^2 := (sq_le_sq₀ (norm_nonneg _) hX₀).mpr (hX i) + have hinv : 0≤(δ-δ/2)⁻¹ := inv_nonneg.mpr (by linarith) + calc + _ ≤ 1+X₀^2*(δ-δ/2)⁻¹*L₀ := add_le_add le_rfl + (mul_le_mul (mul_le_mul_of_nonneg_right hX2 hinv) (hL i) (norm_nonneg _) (by positivity)) + _ = _ := by congr 2; ring + +theorem implicit_columns_bound (j χ r p : ℝ) (X J : E→L[ℝ]E) + (u m t ell w y : E) (c : ℝ) + (s χ' p' c' : ι→ℝ) (X' : ι→E→L[ℝ]E) (u' m' ell' w' y' q' : ι→E) (b' : ι→ℝ) + (h : Equations j χ r p (X*X) J u m t ell w y c) + (h' : ∀i,Equations j (χ' i) r (p' i) (X' i*X' i) J (u' i) (m' i) t (ell' i) (w' i) (y' i) (c' i)) + {δ X₀ L₀ : ℝ} (hδ : 0<δ) (hX₀ : 0≤X₀) (hL₀ : 0≤L₀) + (hX : ∀i,‖X' i‖≤X₀) (hL : ∀i,‖L₂ j (χ' i) r J (m' i+t) (ell' i)‖≤L₀) + (hS : ∀i v,δ*‖v‖^2≤ inner ℝ v (stableMatrix j (b' i) r (X' i) J (q' i) v)) + (hSmall : ∀i,|j| *|χ' i-b' i| *‖X' i‖^2+|j*r| *‖X' i‖^2* + (‖m' i+t-(2:ℝ) • q' i‖*‖ell' i‖+2*‖q' i‖*‖ell' i+q' i‖)≤δ/2) : + let A:=X*X + let A':=fun i=>X' i*X' i + let B:=u+J w-(j*χ) • w-(j*c) • (m+t) + let z:=fun i=>r*inner ℝ (s i • (ell-ell' i)) w+s i*(p-p' i) + columnNorm (fun i=>s i • (w-w' i))≤(1+X₀^2*(δ/2)⁻¹*L₀)* + (columnNorm (fun i=>(s i • (A-A' i)) B)+ + columnNorm (fun i=>A' i (s i • (u-u' i)))+ + columnNorm (fun i=>(j*(s i*(χ-χ' i))) • A' i w)+ + columnNorm (fun i=>(j*c) • A' i (s i • (m-m' i)))+ + columnNorm (fun i=>(j*z i) • A' i (m' i+t))) := by + dsimp only + let V:=fun i=>(s i • (X*X-X' i*X' i)) (u+J w-(j*χ) • w-(j*c) • (m+t))+ + (X' i*X' i) (s i • (u-u' i))-(j*(s i*(χ-χ' i))) • (X' i*X' i) w- + (j*c) • (X' i*X' i) (s i • (m-m' i))- + (j*(r*inner ℝ (s i • (ell-ell' i)) w+s i*(p-p' i))) • (X' i*X' i) (m' i+t) + have hlow:=column_inverse_estimate X' (fun i=>L₂ j (χ' i) r J (m' i+t) (ell' i)) + (fun i=>stableMatrix j (b' i) r (X' i) J (q' i)) (fun i=>s i • (w-w' i)) V + hδ hX₀ hL₀ hX hL hS + (fun i=>(normalized_difference_bound j (χ' i) (b' i) r (X' i) J (m' i+t) (ell' i) (q' i)).trans (hSmall i)) + (fun i=>implicit_scaled_difference (s i) j χ (χ' i) r p (p' i) (X*X) (X' i*X' i) J + u (u' i) m (m' i) t ell (ell' i) w (w' i) y (y' i) c (c' i) h (h' i)) + apply hlow.trans + apply mul_le_mul_of_nonneg_left _ (by positivity) + exact columnNorm_add_sub_sub_sub _ _ _ _ _ + +end SKGap.ImplicitSystem +namespace SKGapCutoff.Recipe +lemma columnNorm_matrix {dimension : ℕ} (D : Interaction dimension) : + SKGap.ImplicitSystem.columnNorm (fun k=>(WithLp.toLp 2 (fun i=>D i k) : EuclideanSpace ℝ (Fin dimension)))=‖D‖ := by + apply (sq_eq_sq₀ (SKGap.ImplicitSystem.columnNorm_nonneg _) (norm_nonneg _)).mp + rw [SKGap.ImplicitSystem.columnNorm_sq,SKGap.frobenius_sq] + simp only [EuclideanSpace.real_norm_sq_eq] + exact Finset.sum_comm +end SKGapCutoff.Recipe + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Stability/ImplicitFrobenius.lean b/lean/OAI/Probability/SKGap/Stability/ImplicitFrobenius.lean new file mode 100644 index 0000000000000000000000000000000000000000..48539389d4cb4cbfb9d8c84863e76a46dd31beca --- /dev/null +++ b/lean/OAI/Probability/SKGap/Stability/ImplicitFrobenius.lean @@ -0,0 +1,183 @@ +import Mathlib +import OAI.Probability.SKGap.Stability.ImplicitFlip + +namespace OAI + +section + +noncomputable section +open scoped BigOperators Matrix.Norms.Frobenius +namespace SKGap.ImplicitSystem +variable {E F : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] + [NormedAddCommGroup F] [InnerProductSpace ℝ F] +variable {ι : Type*} [Fintype ι] + +omit [InnerProductSpace ℝ E] [InnerProductSpace ℝ F] in +lemma columnNorm_compare (U : ι→E) (V : ι→F) {C : ℝ} (hC : 0≤C) + (h : ∀i,‖U i‖≤C*‖V i‖) : columnNorm U≤C*columnNorm V := by + apply nonneg_le_nonneg_of_sq_le_sq (mul_nonneg hC (columnNorm_nonneg _)) + simp only [←sq,columnNorm_sq,mul_pow,Finset.mul_sum] + exact Finset.sum_le_sum fun i _=>by + simpa only [mul_pow] using pow_le_pow_left₀ (norm_nonneg (U i)) (h i) 2 + +lemma columnNorm_inner_common (V : ι→E) (w : E) : + columnNorm (fun i=>inner ℝ (V i) w)≤‖w‖*columnNorm V := by + apply columnNorm_compare _ _ (norm_nonneg w) + intro i + simpa only [Real.norm_eq_abs,mul_comm] using abs_real_inner_le_norm (V i) w + +lemma columnNorm_inner_variable (V W : ι→E) {C : ℝ} + (hC : 0≤C) (hV : ∀i,‖V i‖≤C) : + columnNorm (fun i=>inner ℝ (V i) (W i))≤C*columnNorm W := by + apply columnNorm_compare _ _ hC + intro i + exact (abs_real_inner_le_norm _ _).trans (mul_le_mul_of_nonneg_right (hV i) (norm_nonneg _)) + +lemma normalized_coefficient_difference (D : ι→E) (dp : ι→ℝ) (w : E) + {r d R P : ℝ} (hr : 0≤r) (hd : 0r*inner ℝ (D i) w+dp i)≤R*‖w‖+P := by + have he : (fun i=>r*inner ℝ (D i) w+dp i)=r • (fun i=>inner ℝ (D i) w)+dp := rfl + rw [he] + have hc:=columnNorm_add (r • (fun i=>inner ℝ (D i) w)) dp + rw [columnNorm_smul,abs_of_nonneg hr] at hc + have hi:=(columnNorm_inner_common D w).trans + (mul_le_mul_of_nonneg_left hD (norm_nonneg w)) + calc + _ ≤ d*(r*(‖w‖*(R*d))+columnNorm dp) := mul_le_mul_of_nonneg_left + (hc.trans (add_le_add (mul_le_mul_of_nonneg_left hi hr) le_rfl)) hd.le + _ = R*‖w‖*(r*d^2)+d*columnNorm dp := by ring + _ = R*‖w‖+d*columnNorm dp := by rw [hscale]; ring + _ ≤ _ := add_le_add le_rfl hP + +lemma normalized_scalar_difference (D W L : ι→E) (dp : ι→ℝ) (w : E) + {r d R P Q : ℝ} (hr : 0≤r) (hd : 0r*inner ℝ (D i) w+dp i+r*inner ℝ (L i) (W i))≤ + R*‖w‖+P+Q*columnNorm W := by + have h₁:=normalized_coefficient_difference D dp w hr hd hscale hR hD hP + have h₂:=columnNorm_inner_variable L W (mul_nonneg hQ hd.le) hL + have he : (fun i=>r*inner ℝ (D i) w+dp i+r*inner ℝ (L i) (W i))= + (fun i=>r*inner ℝ (D i) w+dp i)+r • (fun i=>inner ℝ (L i) (W i)) := rfl + rw [he] + have hh:=columnNorm_add (fun i=>r*inner ℝ (D i) w+dp i) (r • (fun i=>inner ℝ (L i) (W i))) + rw [columnNorm_smul,abs_of_nonneg hr] at hh + calc + _ ≤ d*columnNorm (fun i=>r*inner ℝ (D i) w+dp i)+d*r*((Q*d)*columnNorm W) := by + nlinarith only [mul_le_mul_of_nonneg_left hh hd.le, + mul_le_mul_of_nonneg_left h₂ (mul_nonneg hd.le hr)] + _ = d*columnNorm (fun i=>r*inner ℝ (D i) w+dp i)+Q*columnNorm W*(r*d^2) := by ring + _ = d*columnNorm (fun i=>r*inner ℝ (D i) w+dp i)+Q*columnNorm W := by rw [hscale]; ring + _ ≤ _ := add_le_add h₁ le_rfl + +variable [FiniteDimensional ℝ E] + +theorem implicit_frobenius_estimate (j χ r p : ℝ) (X J : E→L[ℝ]E) + (u m t ell w y : E) (c : ℝ) + (s χ' p' c' : ι→ℝ) (X' : ι→E→L[ℝ]E) (u' m' ell' w' y' q' : ι→E) (b' : ι→ℝ) + (h : Equations j χ r p (X*X) J u m t ell w y c) + (h' : ∀i,Equations j (χ' i) r (p' i) (X' i*X' i) J (u' i) (m' i) t (ell' i) (w' i) (y' i) (c' i)) + {δ X₀ L₀ d RA U Rχ Rm Rell P C V : ℝ} + (hδ : 0<δ) (hX₀ : 0≤X₀) (hL₀ : 0≤L₀) (hd : 0(s i • (X*X-X' i*X' i)) B)≤RA*‖B‖) + (hDu : columnNorm (fun i=>s i • (u-u' i))≤U) + (hDχ : columnNorm (fun i=>s i*(χ-χ' i))≤Rχ) + (hDm : columnNorm (fun i=>s i • (m-m' i))≤Rm*d) + (hDell : columnNorm (fun i=>s i • (ell-ell' i))≤Rell*d) + (hDp : d*columnNorm (fun i=>s i*(p-p' i))≤P) + (hc : d*|c|≤C) (hv : ∀i,‖m' i+t‖≤V*d) : + columnNorm (fun i=>s i • (w-w' i))≤(1+X₀^2*(δ/2)⁻¹*L₀)* + (RA*‖u+J w-(j*χ) • w-(j*c) • (m+t)‖+X₀^2*U+ + |j| *X₀^2*‖w‖*Rχ+|j| *X₀^2*C*Rm+ + |j| *X₀^2*V*(Rell*‖w‖+P)) := by + let A':=fun i=>X' i*X' i + have hA : ∀i,‖A' i‖≤X₀^2 := fun i=>(norm_mul_le _ _).trans + (by simpa only [pow_two] using mul_le_mul (hX i) (hX i) (norm_nonneg _) hX₀) + let z:=fun i=>r*inner ℝ (s i • (ell-ell' i)) w+s i*(p-p' i) + have hz : d*columnNorm z≤Rell*‖w‖+P := + normalized_coefficient_difference _ _ w hr hd hscale hRell hDell hDp + have h₂ : columnNorm (fun i=>A' i (s i • (u-u' i)))≤X₀^2*U := + (columnNorm_operator A' _ (sq_nonneg _) hA).trans (mul_le_mul_of_nonneg_left hDu (sq_nonneg _)) + have h₃ : columnNorm (fun i=>(j*(s i*(χ-χ' i))) • A' i w)≤|j| *X₀^2*‖w‖*Rχ := by + have he : (fun i=>(j*(s i*(χ-χ' i))) • A' i w)= + j • (fun i=>(s i*(χ-χ' i)) • A' i w) := by ext i; simp [mul_smul] + rw [he,columnNorm_smul] + have hb : ∀i,‖A' i w‖≤X₀^2*‖w‖ := fun i=>((A' i).le_opNorm _).trans + (mul_le_mul_of_nonneg_right (hA i) (norm_nonneg _)) + have hh:=(columnNorm_vector_scalar _ _ (by positivity : 0≤X₀^2*‖w‖) hb).trans + (mul_le_mul_of_nonneg_left hDχ (by positivity)) + nlinarith only [mul_le_mul_of_nonneg_left hh (abs_nonneg j)] + have h₄ : columnNorm (fun i=>(j*c) • A' i (s i • (m-m' i)))≤|j| *X₀^2*C*Rm := by + change columnNorm ((j*c) • (fun i=>A' i (s i • (m-m' i))))≤_ + rw [columnNorm_smul,abs_mul] + have hh:=(columnNorm_operator A' _ (sq_nonneg _) hA).trans + (mul_le_mul_of_nonneg_left hDm (sq_nonneg _)) + calc + _ ≤ |j| *|c| *(X₀^2*(Rm*d)) := mul_le_mul_of_nonneg_left hh (by positivity) + _ = (|j| *X₀^2*Rm)*(d*|c|) := by ring + _ ≤ (|j| *X₀^2*Rm)*C := mul_le_mul_of_nonneg_left hc (by positivity) + _ = _ := by ring + have h₅ : columnNorm (fun i=>(j*z i) • A' i (m' i+t))≤|j| *X₀^2*V*(Rell*‖w‖+P) := by + have he : (fun i=>(j*z i) • A' i (m' i+t))=j • (fun i=>z i • A' i (m' i+t)) := by + ext i; simp [mul_smul] + rw [he,columnNorm_smul] + have hb : ∀i,‖A' i (m' i+t)‖≤X₀^2*(V*d) := fun i=>((A' i).le_opNorm _).trans + (mul_le_mul (hA i) (hv i) (norm_nonneg _) (sq_nonneg _)) + have hh:=columnNorm_vector_scalar (fun i=>A' i (m' i+t)) z (by positivity : 0≤X₀^2*(V*d)) hb + calc + _ ≤ |j| *((X₀^2*(V*d))*columnNorm z) := mul_le_mul_of_nonneg_left hh (abs_nonneg _) + _ = (|j| *X₀^2*V)*(d*columnNorm z) := by ring + _ ≤ _ := mul_le_mul_of_nonneg_left hz (by positivity) + have H:=implicit_columns_bound j χ r p X J u m t ell w y c s χ' p' c' X' u' m' ell' w' y' q' b' + h h' hδ hX₀ hL₀ hX hL hS hSmall + apply H.trans + apply mul_le_mul_of_nonneg_left _ (by positivity) + exact add_le_add (add_le_add (add_le_add (add_le_add (hDA _) h₂) h₃) h₄) h₅ + +end SKGap.ImplicitSystem +namespace SKGapCutoff.Recipe +open Matrix +variable {n : ℕ} +lemma frobenius_by_rows (D : Interaction n) {R : ℝ} (hR : 0≤R) + (hD : ∀i,∑k,(D i k)^2≤R^2) : ‖D‖≤R*Real.sqrt n := by + apply nonneg_le_nonneg_of_sq_le_sq (mul_nonneg hR (Real.sqrt_nonneg _)) + simp only [←sq,SKGap.frobenius_sq,mul_pow,Real.sq_sqrt (Nat.cast_nonneg n)] + calc + _ ≤ ∑_i:Fin n,R^2 := Finset.sum_le_sum fun i _=>hD i + _ = _ := by simp [mul_comm] + +lemma coefficient_diagonal_columns (a a' : Fin n→Fin n→ℝ) (s : Fin n→ℝ) + {R : ℝ} (hR : 0≤R) (ha : ∀i,∑k,(s k*(a k i-a' k i))^2≤R^2) + (B : EuclideanSpace ℝ (Fin n)) : + SKGap.ImplicitSystem.columnNorm (fun k=>(s k • + (toEuclideanCLM (𝕜:=ℝ) (diagonal (a k))-toEuclideanCLM (𝕜:=ℝ) (diagonal (a' k)))) B)≤R*‖B‖ := by + let D : Interaction n:=fun i k=>B i*(s k*(a k i-a' k i)) + have he : (fun k=>(s k • + (toEuclideanCLM (𝕜:=ℝ) (diagonal (a k))-toEuclideanCLM (𝕜:=ℝ) (diagonal (a' k)))) B)= + (fun k=>(WithLp.toLp 2 (fun i=>D i k) : EuclideanSpace ℝ (Fin n))) := by + ext k i + change s k*((toEuclideanCLM (𝕜:=ℝ) (diagonal (a k)) (WithLp.toLp 2 B.ofLp)) i- + (toEuclideanCLM (𝕜:=ℝ) (diagonal (a' k)) (WithLp.toLp 2 B.ofLp)) i)=D i k + simp only [toEuclideanCLM_toLp,WithLp.ofLp_toLp,mulVec_diagonal,D] + ring + rw [he,columnNorm_matrix] + apply nonneg_le_nonneg_of_sq_le_sq (mul_nonneg hR (norm_nonneg _)) + simp only [←sq,SKGap.frobenius_sq,mul_pow,EuclideanSpace.real_norm_sq_eq] + calc + _ = ∑i,(B i)^2*(∑k,(s k*(a k i-a' k i))^2) := by + simp only [D,mul_pow,Finset.mul_sum] + _ ≤ ∑i,(B i)^2*R^2 := Finset.sum_le_sum fun i _=>mul_le_mul_of_nonneg_left (ha i) (sq_nonneg _) + _ = _ := by rw [Finset.mul_sum]; apply Finset.sum_congr rfl; intro i _; ring +end SKGapCutoff.Recipe + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Stability/ImplicitLinear.lean b/lean/OAI/Probability/SKGap/Stability/ImplicitLinear.lean new file mode 100644 index 0000000000000000000000000000000000000000..a9931e837ae87c83a75eea8413390032ccf7ee66 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Stability/ImplicitLinear.lean @@ -0,0 +1,244 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.ResidualRecipe + +namespace OAI + +section + +noncomputable section +namespace SKGap.ImplicitLinear +local notation "⟪" x ", " y "⟫" => inner ℝ x y +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] + +lemma lower_norm_of_quadratic (M : E →L[ℝ] E) {c : ℝ} + (h : ∀v,c*‖v‖^2 ≤ ⟪v, M v⟫) (v : E) : c*‖v‖≤‖M v‖ := by + by_cases hv : ‖v‖=0 + · simp [hv] + have hn : 0<‖v‖ := lt_of_le_of_ne (norm_nonneg _) (Ne.symm hv) + have H:=(h v).trans (real_inner_le_norm v (M v)) + nlinarith + +lemma quadratic_perturbation (M S : E →L[ℝ] E) {c e : ℝ} + (hS : ∀v,c*‖v‖^2 ≤ ⟪v, S v⟫) (hMS : ‖M-S‖≤e) (v : E) : + (c-e)*‖v‖^2 ≤ ⟪v, M v⟫ := by + have hI:=abs_real_inner_le_norm v ((M-S) v) + have hO:=(M-S).le_opNorm v + have hm:=mul_le_mul_of_nonneg_right hMS (norm_nonneg v) + have hh:=mul_le_mul_of_nonneg_left (hO.trans hm) (norm_nonneg v) + have he : ⟪v, (M-S) v⟫=⟪v, M v⟫-⟪v, S v⟫ := by simp only [sub_apply,inner_sub_right] + rw [he] at hI + have H := (neg_abs_le (⟪v, M v⟫-⟪v, S v⟫)).trans (le_refl _) + nlinarith [hS v] + +lemma injective_of_lower_norm (M : E →L[ℝ] E) {c : ℝ} (hc : 0.trans_eq (by ring) + +end SKGap.ImplicitLinear + +namespace SKGap.ImplicitLinear +variable {R : Type*} [Ring R] + +lemma jacobson_left (X Y N : R) (hN : (1+Y*X)*N=1) : + (1+X*Y)*(1-X*N*Y)=1 := by + calc + _ = 1+X*(1-(1+Y*X)*N)*Y := by noncomm_ring + _ = 1 := by rw [hN]; simp + +lemma jacobson_right (X Y N : R) (hN : N*(1+Y*X)=1) : + (1-X*N*Y)*(1+X*Y)=1 := by + calc + _ = 1+X*(1-N*(1+Y*X))*Y := by noncomm_ring + _ = 1 := by rw [hN]; simp + +end SKGap.ImplicitLinear + +namespace SKGap.ImplicitLinear +local notation "⟪" x ", " y "⟫" => inner ℝ x y +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] + [FiniteDimensional ℝ E] + +theorem unnormalized_inverse (X L S : E →L[ℝ] E) {c e : ℝ} + (hce : ef w) hBM + simpa only [mul_apply_eq_comp,hw,one_apply_eq_self] using this.symm + +end SKGap.ImplicitLinear + +end +end + +section + +noncomputable section +namespace SKGap.ImplicitSystem +open SKGap.ImplicitLinear +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] + +def rank (u v : E) : E →L[ℝ] E := (innerSL ℝ v).smulRight u + +@[simp] lemma rank_apply (u v w : E) : rank u v w=inner ℝ v w • u := rfl + +lemma rank_add_right (u v w : E) : rank u (v+w)=rank u v+rank u w := by + ext x; simp only [rank_apply,inner_add_left,add_smul,add_apply] + +lemma rank_add_left (u v w : E) : rank (u+v) w=rank u w+rank v w := by + ext x; simp only [rank_apply,smul_add,add_apply] + +lemma rank_sub_left (u v w : E) : rank (u-v) w=rank u w-rank v w := by + ext x; simp only [rank_apply,smul_sub,sub_apply] + +lemma rank_smul_left (a : ℝ) (u v : E) : rank (a • u) v=a • rank u v := by + ext x; simp only [rank_apply,smul_apply]; module + +lemma rank_norm_le (u v : E) : ‖rank u v‖≤‖u‖*‖v‖ := by + apply ContinuousLinearMap.opNorm_le_bound _ (mul_nonneg (norm_nonneg _) (norm_nonneg _)) + intro x + simp only [rank_apply,norm_smul,Real.norm_eq_abs] + calc + _ ≤ (‖v‖*‖x‖)*‖u‖ := mul_le_mul_of_nonneg_right (abs_real_inner_le_norm v x) (norm_nonneg _) + _ = _ := by ring + +lemma rank_perturbation (v ell m : E) : + rank v ell+(2:ℝ) • rank m m=rank (v-(2:ℝ) • m) ell+(2:ℝ) • rank m (ell+m) := by + rw [rank_sub_left,rank_smul_left,rank_add_right,smul_add] + module + +lemma rank_perturbation_bound (v ell m : E) : + ‖rank v ell+(2:ℝ) • rank m m‖≤‖v-(2:ℝ) • m‖*‖ell‖+2*‖m‖*‖ell+m‖ := by + rw [rank_perturbation] + calc + _ ≤ ‖rank (v-(2:ℝ) • m) ell‖+‖(2:ℝ) • rank m (ell+m)‖ := norm_add_le _ _ + _ ≤ ‖v-(2:ℝ) • m‖*‖ell‖+2*(‖m‖*‖ell+m‖) := by + rw [norm_smul,Real.norm_eq_abs,abs_of_pos (by norm_num : (0:ℝ)<2)] + exact add_le_add (rank_norm_le _ _) (mul_le_mul_of_nonneg_left (rank_norm_le _ _) (by norm_num)) + _ = _ := by ring + +def L₂ (j χ r : ℝ) (J : E →L[ℝ] E) (v ell : E) : E →L[ℝ] E := + -J+(j*χ) • 1+(j*r) • rank v ell + +def stableMatrix (j b r : ℝ) (X J : E →L[ℝ] E) (m : E) : E →L[ℝ] E := + 1+(j*b) • (X*X)-X*J*X-(2*j*r) • (X*rank m m*X) + +lemma normalized_difference (j χ b r : ℝ) (X J : E →L[ℝ] E) (v ell m : E) : + (1+X*L₂ j χ r J v ell*X)-stableMatrix j b r X J m= + (j*(χ-b)) • (X*X)+(j*r) • (X*(rank v ell+(2:ℝ) • rank m m)*X) := by + simp only [L₂,stableMatrix,mul_add,add_mul,mul_neg,neg_mul,mul_smul_comm, + smul_mul_assoc,mul_one,smul_add,smul_smul] + module + +lemma normalized_difference_bound (j χ b r : ℝ) (X J : E →L[ℝ] E) (v ell m : E) : + ‖(1+X*L₂ j χ r J v ell*X)-stableMatrix j b r X J m‖≤ + |j| * |χ-b| * ‖X‖^2+|j*r| * ‖X‖^2*(‖v-(2:ℝ) • m‖*‖ell‖+2*‖m‖*‖ell+m‖) := by + rw [normalized_difference] + calc + _ ≤ ‖(j*(χ-b)) • (X*X)‖+‖(j*r) • (X*(rank v ell+(2:ℝ) • rank m m)*X)‖ := norm_add_le _ _ + _ ≤ |j| * |χ-b| * (‖X‖*‖X‖)+|j*r| * (‖X‖*(‖v-(2:ℝ) • m‖*‖ell‖+2*‖m‖*‖ell+m‖)*‖X‖) := by + simp only [norm_smul,Real.norm_eq_abs,abs_mul] + apply add_le_add + · exact mul_le_mul_of_nonneg_left (norm_mul_le X X) (mul_nonneg (abs_nonneg _) (abs_nonneg _)) + · apply mul_le_mul_of_nonneg_left _ (mul_nonneg (abs_nonneg _) (abs_nonneg _)) + exact (norm_mul_le _ _).trans (mul_le_mul_of_nonneg_right + ((norm_mul_le _ _).trans (mul_le_mul_of_nonneg_left (rank_perturbation_bound v ell m) (norm_nonneg _))) + (norm_nonneg _)) + _ = _ := by ring + +def Equations (j χ r p : ℝ) (A J : E →L[ℝ] E) (u m t ell w y : E) (c : ℝ) : Prop := + w=A (u+y-(j*c) • t) ∧ y=J w-(j*χ) • w-(j*c) • m ∧ c=r*inner ℝ ell w+p + +lemma eliminated_equation (j χ r p : ℝ) (A J : E →L[ℝ] E) (u m t ell w : E) : + Equations j χ r p A J u m t ell w + (J w-(j*χ) • w-(j*(r*inner ℝ ell w+p)) • m) (r*inner ℝ ell w+p) ↔ + (1+A*L₂ j χ r J (m+t) ell) w=A (u-(j*p) • (m+t)) := by + simp only [Equations,and_true,L₂,add_apply,smul_apply,neg_apply,one_apply_eq_self, + mul_apply_eq_comp,rank_apply,map_add,map_sub,map_smul,map_neg] + constructor <;> intro h <;> linear_combination (norm := module) h + +variable [FiniteDimensional ℝ E] + +theorem unique_implicit_solution (j χ b r p : ℝ) (X J : E →L[ℝ] E) + (u m t ell q : E) {δ : ℝ} (hδ : 0<δ) + (hStable : ∀v,δ*‖v‖^2 ≤ inner ℝ v (stableMatrix j b r X J q v)) + (hSmall : |j| * |χ-b| * ‖X‖^2+|j*r| * ‖X‖^2* + (‖m+t-(2:ℝ) • q‖*‖ell‖+2*‖q‖*‖ell+q‖)≤δ/2) : + ∃! z : E×E×ℝ,Equations j χ r p (X*X) J u m t ell z.1 z.2.1 z.2.2 := by + have hPert := (normalized_difference_bound j χ b r X J (m+t) ell q).trans hSmall + obtain ⟨B,hMB,hBM,hB⟩ := unnormalized_inverse X (L₂ j χ r J (m+t) ell) + (stableMatrix j b r X J q) (by linarith : δ/2<δ) hStable hPert + obtain ⟨w,hw,huniq⟩:=unique_solution_of_inverse (1+X*X*L₂ j χ r J (m+t) ell) B hMB hBM + ((X*X) (u-(j*p) • (m+t))) + let c:=r*inner ℝ ell w+p + let y:=J w-(j*χ) • w-(j*c) • m + have hEq : Equations j χ r p (X*X) J u m t ell w y c := by + apply (eliminated_equation j χ r p (X*X) J u m t ell w).mpr + simpa only [mul_assoc] using hw + refine ⟨(w,y,c),hEq,?_⟩ + rintro ⟨w',y',c'⟩ h' + rcases h' with ⟨hw',hy',hc'⟩ + have hwe : (1+(X*X)*L₂ j χ r J (m+t) ell) w'=(X*X) (u-(j*p) • (m+t)) := by + apply (eliminated_equation j χ r p (X*X) J u m t ell w').mp + refine ⟨?_,rfl,rfl⟩ + simpa only [←hc',←hy'] using hw' + have hww : w'=w := huniq w' (by simpa only [mul_assoc] using hwe) + have hcc : c'=c := by simpa only [hww] using hc' + have hyy : y'=y := by simpa only [hww,hcc] using hy' + simp only [hww,hyy,hcc] + +end SKGap.ImplicitSystem + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Stability/ImplicitNode.lean b/lean/OAI/Probability/SKGap/Stability/ImplicitNode.lean new file mode 100644 index 0000000000000000000000000000000000000000..735e3ba6cb62b5ecf49fd504449f2ea3649dadf1 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Stability/ImplicitNode.lean @@ -0,0 +1,95 @@ +import Mathlib +import OAI.Probability.SKGap.Stability.OrdinaryRecipe +import OAI.Probability.SKGap.Localization.RecipeError +import OAI.Probability.SKGap.Matrix.ClosedErrorTrace +import OAI.Probability.SKGap.Matrix.ClosedMatrix + +namespace OAI + +section + +noncomputable section +open scoped BigOperators Matrix.Norms.Frobenius +namespace SKGapCutoff.Recipe.OrdinaryData +open Primary Matrix SKGap SKGap.Noncrossing SKGap.Noncrossing.Primary +open SKGap.Noncrossing.Primary.Tensor.Series +variable {n : ℕ} {κ σ : Type*} [Fintype κ] [DecidableEq κ] [Fintype σ] +variable (D : OrdinaryData n Unit κ σ) + +def implicitPartial (y : VectorFields n) : VectorFields n := D.partialOf 1 () (fun _=>y) +def implicitCoefficient : VectorFields n := D.auxCoefficient 1 0 + +def implicitSourcePrimitive (t : SourceTree (Fin n→ℝ)) (y : VectorFields n) (x : Spin n) : Interaction n := + D.sourceAtoms 1 (fun _=>y) x+Matrix.diagonal (D.implicitPartial y x)* + (derivativeMatrix (D.H ()) x-t.fieldMatrix D.j D.J) +def implicitFieldPrimitive (t : SourceTree (Fin n→ℝ)) (w y : VectorFields n) (x : Spin n) : Interaction n := + -(D.j*siteMean (D.implicitPartial y) x) • + (derivativeMatrix (D.predecessor ()) x-t.sourceMatrix D.j D.J)- + D.j • (averageError (siteMean (D.implicitPartial y)) (D.predecessor ()) x+ + averageError (siteMean D.implicitCoefficient) w x) + +def implicitRetainedSource (t : SourceTree (Fin n→ℝ)) (y : VectorFields n) (x : Spin n) : Interaction n := + GradedWords.matrixValue D.j (D.implicitCoefficient x) D.J + (GradedWords.implicitSource D.j (D.implicitCoefficient x) (D.implicitPartial y x) t) +def implicitRetainedField (t : SourceTree (Fin n→ℝ)) (y : VectorFields n) (x : Spin n) : Interaction n := + GradedWords.matrixValue D.j (D.implicitCoefficient x) D.J + (GradedWords.implicitField D.j (D.implicitCoefficient x) (D.implicitPartial y x) t) + +lemma mean_implicit (F : VectorFields n) (x : Spin n) : Diagram.mean (F x)=siteMean F x := by + simp [Diagram.mean,siteMean] + +lemma implicit_source_derivative (t : SourceTree (Fin n→ℝ)) (w y : VectorFields n) + (hw : w=D.sourceOf 1 (fun _=>y)) (x : Spin n) : + derivativeMatrix w x=Matrix.diagonal (D.implicitCoefficient x)*derivativeMatrix y x+ + Matrix.diagonal (D.implicitPartial y x)*t.fieldMatrix D.j D.J+D.implicitSourcePrimitive t y x := by + rw [hw,D.sourceOf_derivative] + simp only [Fintype.sum_unique,implicitCoefficient,implicitPartial,implicitSourcePrimitive,mul_sub] + have hd : (default : Fin 1)=0 := Subsingleton.elim _ _ + rw [hd] + abel +lemma implicit_field_derivative (t : SourceTree (Fin n→ℝ)) (w y : VectorFields n) + (hw : w=D.sourceOf 1 (fun _=>y)) (hy : y=D.fieldOf 1 (fun _=>w) (fun _=>y)) (x : Spin n) : + derivativeMatrix y x=(D.J-(D.j*siteMean D.implicitCoefficient x) • 1)*derivativeMatrix w x- + (D.j*siteMean (D.implicitPartial y) x) • t.sourceMatrix D.j D.J+D.implicitFieldPrimitive t w y x := by + have H:=congrArg (fun Q:VectorFields n=>derivativeMatrix Q x) hy + rw [D.fieldOf_derivative,←hw] at H + simp only [Fintype.sum_unique] at H + rw [H] + simp only [implicitCoefficient,implicitPartial,implicitFieldPrimitive,neg_smul,smul_sub, + sub_mul,smul_mul_assoc,one_mul] + abel + +theorem implicit_error_solved (t : SourceTree (Fin n→ℝ)) (w y : VectorFields n) + (hw : w=D.sourceOf 1 (fun _=>y)) (hy : y=D.fieldOf 1 (fun _=>w) (fun _=>y)) (x : Spin n) + (hK : WordLetter.inverse.exactEval D.j (D.implicitCoefficient x) D.J* + (1-Matrix.diagonal (D.implicitCoefficient x)*(D.J-(D.j*siteMean D.implicitCoefficient x) • 1))=1) : + derivativeMatrix w x-D.implicitRetainedSource t y x= + WordLetter.inverse.exactEval D.j (D.implicitCoefficient x) D.J* + (D.implicitSourcePrimitive t y x+Matrix.diagonal (D.implicitCoefficient x)*D.implicitFieldPrimitive t w y x) ∧ + derivativeMatrix y x-D.implicitRetainedField t y x= + (D.J-(D.j*siteMean D.implicitCoefficient x) • 1)* + (derivativeMatrix w x-D.implicitRetainedSource t y x)+D.implicitFieldPrimitive t w y x := by + have hsource:=D.implicit_source_derivative t w y hw x + have hfield:=D.implicit_field_derivative t w y hw hy x + have hs : derivativeMatrix w x=Matrix.diagonal (D.implicitCoefficient x)*derivativeMatrix y x+ + (Matrix.diagonal (D.implicitPartial y x)*t.fieldMatrix D.j D.J+D.implicitSourcePrimitive t y x) := by rw [hsource];abel + have hf : derivativeMatrix y x=(D.J-(D.j*siteMean D.implicitCoefficient x) • 1)*derivativeMatrix w x+ + (-(D.j*siteMean (D.implicitPartial y) x) • t.sourceMatrix D.j D.J+D.implicitFieldPrimitive t w y x) := by + rw [hfield];simp only [neg_smul];abel + have H:=implicit_error_elimination _ _ _ _ _ _ _ _ hK hs hf + constructor + · rw [H,implicitRetainedSource,GradedWords.matrixValue_implicitSource,mean_implicit] + simp only [mul_add,mul_sub,neg_smul,mul_neg,mul_smul_comm] + abel + · rw [hfield,implicitRetainedField,GradedWords.matrixValue_implicitField,mean_implicit,mean_implicit] + change _-((D.J-(D.j*siteMean D.implicitCoefficient x) • 1)*D.implicitRetainedSource t y x- + (D.j*siteMean (D.implicitPartial y) x) • t.sourceMatrix D.j D.J)=_ + rw [mul_sub] + abel + +end SKGapCutoff.Recipe.OrdinaryData + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Stability/ImplicitPerturb.lean b/lean/OAI/Probability/SKGap/Stability/ImplicitPerturb.lean new file mode 100644 index 0000000000000000000000000000000000000000..555c6de3a7282cbf694c4d50311861d1b547ddb3 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Stability/ImplicitPerturb.lean @@ -0,0 +1,156 @@ +import Mathlib +import OAI.Probability.SKGap.Stability.ImplicitCoefficient + +namespace OAI + +section + +noncomputable section +open scoped BigOperators +namespace SKGapCutoff.Recipe +open SKGap.Stein Primary SKGap.ImplicitSystem +variable {n : ℕ} + +lemma vectorNorm_implicit_rank (z r m : Fin n→ℝ) {ρ : ℝ} + (hz : vectorNorm (z-r)≤ρ*Real.sqrt n) + (hm : vectorNorm (m-(fun i=>Real.tanh (r i)))≤ρ*Real.sqrt n) : + vectorNorm (m+(fun i=>Real.tanh (r i))-(2:ℝ) • (fun i=>Real.tanh (z i)))≤ + 3*ρ*Real.sqrt n := by + let q:=fun i=>Real.tanh (z i) + let t:=fun i=>Real.tanh (r i) + have ht:=vectorNorm_tanh_diff z r + have ht' : vectorNorm (t-q)≤ρ*Real.sqrt n := by + have he : t-q= -(q-t) := by ext i; dsimp; ring + rw [he,vectorNorm_neg] + exact ht.trans hz + have hh:=vectorNorm_add (m-t) ((2:ℝ) • (t-q)) + rw [vectorNorm_smul,abs_of_pos (by norm_num : (0:ℝ)<2)] at hh + have he : (m-t)+(2:ℝ) • (t-q)=m+t-(2:ℝ) • q := by ext i; dsimp; ring + rw [he] at hh + exact hh.trans (by nlinarith only [hm,ht']) + +theorem implicit_normalized_perturbation (z r m : Fin n→ℝ) (a j : ℝ) + (X : EuclideanSpace ℝ (Fin n) →L[ℝ] EuclideanSpace ℝ (Fin n)) + (hn : 0Real.tanh (r i)))≤ρ*Real.sqrt n) + (hX : ‖X‖^2≤Real.exp (R/2)) : + let χ:=(∑i,phi (z i) (r i) a)/(n:ℝ) + let b:=(∑i,scalarVariance (z i))/(n:ℝ) + let ell:EuclideanSpace ℝ (Fin n):=WithLp.toLp 2 (fun i=>logSlope (z i) (r i) a) + let q:EuclideanSpace ℝ (Fin n):=WithLp.toLp 2 (fun i=>Real.tanh (z i)) + let t:EuclideanSpace ℝ (Fin n):=WithLp.toLp 2 (fun i=>Real.tanh (r i)) + let M:EuclideanSpace ℝ (Fin n):=WithLp.toLp 2 m + |j| *|χ-b| *‖X‖^2+|j*(n:ℝ)⁻¹| *‖X‖^2* + (‖M+t-(2:ℝ) • q‖*‖ell‖+2*‖q‖*‖ell+q‖)≤ + |j| *Real.exp (R/2)*(3*Real.exp (R/2)+16)*ρ := by + dsimp only + obtain ⟨hA,hAv,hχ,hEllq,hEll,hq⟩:=implicit_coefficient_bounds z r a hn hρ ha haρ hz + have hnR : (0:ℝ)Real.tanh (r i))-(2:ℝ) • (fun i=>Real.tanh (z i)))* + vectorNorm (fun i=>logSlope (z i) (r i) a)+ + 2*vectorNorm (fun i=>Real.tanh (z i))* + vectorNorm ((fun i=>logSlope (z i) (r i) a)+(fun i=>Real.tanh (z i)))≤14*ρ*(n:ℝ) := by + have h₁:=mul_le_mul hv hEll (vectorNorm_nonneg _) (by positivity : 0≤3*ρ*Real.sqrt n) + have h₂:=mul_le_mul (mul_le_mul_of_nonneg_left hq (by norm_num : (0:ℝ)≤2)) hEllq + (vectorNorm_nonneg _) (by positivity : 0≤2*Real.sqrt n) + apply (add_le_add h₁ h₂).trans_eq + calc + _ = 14*ρ*(Real.sqrt n)^2 := by ring + _ = _ := by rw [Real.sq_sqrt hnR.le] + change |j| *|_| *‖X‖^2+|j*(n:ℝ)⁻¹| *‖X‖^2* + (vectorNorm _*vectorNorm _+2*vectorNorm _*vectorNorm _)≤_ + calc + _ ≤ |j| *((3*Real.exp (R/2)+2)*ρ)*Real.exp (R/2)+ + |j*(n:ℝ)⁻¹| *Real.exp (R/2)*(14*ρ*(n:ℝ)) := by + apply add_le_add + · exact mul_le_mul (mul_le_mul_of_nonneg_left hχ (abs_nonneg _)) hX (sq_nonneg _) (by positivity) + · exact mul_le_mul (mul_le_mul_of_nonneg_left hX (abs_nonneg _)) hbr + (add_nonneg (mul_nonneg (vectorNorm_nonneg _) (vectorNorm_nonneg _)) + (mul_nonneg (mul_nonneg (by norm_num) (vectorNorm_nonneg _)) (vectorNorm_nonneg _))) (by positivity) + _ = _ := by + rw [abs_mul,abs_inv,abs_of_pos hnR] + field_simp + ring + +lemma implicit_rho_threshold (j R δ ρ : ℝ) (hδ : 0<δ) + (hρ : ρ≤δ/(2*(|j| *Real.exp (R/2)*(3*Real.exp (R/2)+16)+1))) : + |j| *Real.exp (R/2)*(3*Real.exp (R/2)+16)*ρ≤δ/2 := by + let K:=|j| *Real.exp (R/2)*(3*Real.exp (R/2)+16) + have hK : 0≤K := by dsimp [K]; positivity + have hp : 0<2*(K+1) := by positivity + apply (mul_le_mul_of_nonneg_left hρ hK).trans + change K*(δ/(2*(K+1)))≤δ/2 + apply (le_div_iff₀ (by norm_num : (0:ℝ)<2)).mpr + rw [mul_assoc,div_mul_eq_mul_div,←mul_div_assoc] + apply (div_le_iff₀ hp).mpr + nlinarith + +end SKGapCutoff.Recipe + +end +end + +section + +noncomputable section +open scoped BigOperators +namespace SKGapCutoff.Recipe +open SKGap.Stein Primary SKGap.ImplicitSystem Matrix +variable {n : ℕ} +abbrev Euclid (n : ℕ) := EuclideanSpace ℝ (Fin n) + +def phiDiagonal (z r : Fin n→ℝ) (a : ℝ) : Euclid n→L[ℝ]Euclid n := + Matrix.toEuclideanCLM (𝕜:=ℝ) (diagonal (fun i=>phi (z i) (r i) a)) +def phiSqrt (z r : Fin n→ℝ) (a : ℝ) : Euclid n→L[ℝ]Euclid n := + Matrix.toEuclideanCLM (𝕜:=ℝ) (diagonal (fun i=>Real.sqrt (phi (z i) (r i) a))) + +lemma phiSqrt_square (z r : Fin n→ℝ) (a : ℝ) : + phiSqrt z r a*phiSqrt z r a=phiDiagonal z r a := by + rw [phiSqrt,phiDiagonal,←map_mul,diagonal_mul_diagonal] + congr 2 + ext i + exact Real.mul_self_sqrt (phi_pos _ _ _).le + +lemma phiSqrt_bound (z r : Fin n→ℝ) (a : ℝ) {R : ℝ} (ha : |a|≤R) : + ‖phiSqrt z r a‖^2≤Real.exp (R/2) := by + have he : 0≤Real.exp (R/2):=(Real.exp_pos _).le + have hh : ‖phiSqrt z r a‖≤Real.sqrt (Real.exp (R/2)) := by + apply SKGap.opNorm_diagonal_le (Real.sqrt_nonneg _) + intro i + rw [abs_of_nonneg (Real.sqrt_nonneg _)] + exact Real.sqrt_le_sqrt ((phi_le_exp ..).trans (Real.exp_le_exp.mpr (by linarith))) + exact (pow_le_pow_left₀ (norm_nonneg _) hh 2).trans_eq (Real.sq_sqrt he) + +theorem literal_implicit_exists_unique (z r m : Fin n→ℝ) (a j p : ℝ) + (J : Euclid n→L[ℝ]Euclid n) (u : Euclid n) (hn : 0Real.tanh (r i)))≤ρ*Real.sqrt n) + (hρsmall : ρ≤δ/(2*(|j| *Real.exp (R/2)*(3*Real.exp (R/2)+16)+1))) + (hStable : ∀v,δ*‖v‖^2 ≤ inner ℝ v + (stableMatrix j ((∑i,scalarVariance (z i))/(n:ℝ)) (n:ℝ)⁻¹ + (phiSqrt z r a) J (WithLp.toLp 2 (fun i=>Real.tanh (z i))) v)) : + ∃! sol : Euclid n×Euclid n×ℝ, + Equations j ((∑i,phi (z i) (r i) a)/(n:ℝ)) (n:ℝ)⁻¹ p + (phiDiagonal z r a) J u (WithLp.toLp 2 m) + (WithLp.toLp 2 (fun i=>Real.tanh (r i))) + (WithLp.toLp 2 (fun i=>logSlope (z i) (r i) a)) sol.1 sol.2.1 sol.2.2 := by + have hSmall:=(implicit_normalized_perturbation z r m a j (phiSqrt z r a) hn hρ ha haρ hz hm + (phiSqrt_bound z r a ha)).trans (implicit_rho_threshold j R δ ρ hδ hρsmall) + have H:=unique_implicit_solution j ((∑i,phi (z i) (r i) a)/(n:ℝ)) + ((∑i,scalarVariance (z i))/(n:ℝ)) (n:ℝ)⁻¹ p (phiSqrt z r a) J u + (WithLp.toLp 2 m) (WithLp.toLp 2 (fun i=>Real.tanh (r i))) + (WithLp.toLp 2 (fun i=>logSlope (z i) (r i) a)) + (WithLp.toLp 2 (fun i=>Real.tanh (z i))) hδ hStable hSmall + simpa only [phiSqrt_square] using H + +end SKGapCutoff.Recipe + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Stability/ImplicitTraceControl.lean b/lean/OAI/Probability/SKGap/Stability/ImplicitTraceControl.lean new file mode 100644 index 0000000000000000000000000000000000000000..c8e2b510874c79e8d1eb1cbbd8097d4543533f1a --- /dev/null +++ b/lean/OAI/Probability/SKGap/Stability/ImplicitTraceControl.lean @@ -0,0 +1,106 @@ +import Mathlib +import OAI.Probability.SKGap.Stability.StableFields +import OAI.Probability.SKGap.Localization.RecipeError +import OAI.Probability.SKGap.Stability.ImplicitNode + +namespace OAI + +section + +noncomputable section +open scoped BigOperators Matrix.Norms.Frobenius +namespace SKGapCutoff.Recipe.OrdinaryData +open Primary Matrix SKGap SKGap.Noncrossing SKGap.Noncrossing.Primary +variable {n : ℕ} {κ σ : Type*} [Fintype κ] [DecidableEq κ] [Fintype σ] +variable (D : OrdinaryData n Unit κ σ) + +lemma implicitSource_control (t : SourceTree (Fin n→ℝ)) (y : VectorFields n) (x : Spin n) + {C Q R L V Z B Cp E : ℝ} + (hC : 0≤C) (hQ : 0≤Q) (hR : 0≤R) (hL : 0≤L) (hV : 0≤V) + (hY : SmallBound y x B) (hp : SmallBound (D.implicitPartial y) x Cp) + (hE : ‖derivativeMatrix (D.H ()) x-t.fieldMatrix D.j D.J‖≤E) + (hs : ∀s,SegmentRegular D.H D.θ (D.seedFunction 1 s) (D.seedDerivative 1 s) x C) + (ha : SegmentRegular D.H D.θ (D.auxFunction 1 0) (D.auxDerivative 1 0) x C) + (ht : vectorNorm (parameterIncrement D.θ x)≤V) + (hQ4 : (∑i,∑k,(primaryIncrement D.H x i k)^4)≤Q^4) + (hQr : ∀i,(∑k,(primaryIncrement D.H x i k)^2)≤R^2) + (hQd : (∑i,(primaryIncrement D.H x i i)^2)≤L^2) + (hZ : (∑α,‖derivativeVector (D.θ α) x‖)+4*(Q^2+R*V+V^2)+2*(Q+L+V)≤Z) : + TraceControl (D.implicitSourcePrimitive t y x) + (((∑s,C*vectorNorm (D.seed s)*Z)+C*B*Z)+Cp*E) := by + have hc (s : VectorFields n) {S : ℝ} (hS : SmallBound s x S) + (F : Fin n→Args (ι:=Unit) (κ:=κ)→ℝ) + (F' : Fin n→Args (ι:=Unit) (κ:=κ)→Args (ι:=Unit) (κ:=κ)→L[ℝ]ℝ) + (hF : SegmentRegular D.H D.θ F F' x C) : TraceControl (sourceError D.H D.θ F F' s x) (C*S*Z) := + (sourceError_control D.H D.θ F F' s x hF hS.nonneg hV hQ hR hL hS.size hS.derivative ht hQ4 hQr hQd).mono + (mul_le_mul_of_nonneg_left hZ (mul_nonneg hC hS.nonneg)) + have hs' := TraceControl.sum (fun s=>hc (fun _=>D.seed s) (SmallBound.seed _ x) _ _ (hs s)) + have ha' := hc y hY _ _ ha + have hp' := (small_diagonal_control + (derivativeMatrix (D.H ()) x-t.fieldMatrix D.j D.J) (D.implicitPartial y x)).mono + (mul_le_mul hp.size hE (norm_nonneg _) hp.nonneg) + have H:=(hs'.add ha').add hp' + simpa only [implicitSourcePrimitive,sourceAtoms,Fin.sum_univ_one] using H + +lemma implicitField_control (t : SourceTree (Fin n→ℝ)) (w y : VectorFields n) (x : Spin n) (hn : 0y)) (hY : y=D.fieldOf 1 (fun _=>w) (fun _=>y)) (x : Spin n) + (ha0 : ∀i,0≤D.implicitCoefficient x i) + (hS : (1-SKGap.pathDiagonal (D.implicitCoefficient x) 1* + (D.J-(D.j*siteMean D.implicitCoefficient x) • 1)*SKGap.pathDiagonal (D.implicitCoefficient x) 1).PosDef) + {C F A M : ℝ} {L : ℕ} + (hs : TraceControl (D.implicitSourcePrimitive t y x) C) + (hf : TraceControl (D.implicitFieldPrimitive t w y x) F) + (ha : ∀i,|D.implicitCoefficient x i|≤A) + (hwords : ClosedWordTestBound D.j (D.implicitCoefficient x) D.J A M L) + (v : OrdinaryWord n) (hlen : v.length+3≤L) (hv : wordBounded A v) : + |trace (matrixWord D.J v*(derivativeMatrix w x-D.implicitRetainedSource t y x))|≤(C+F)*M ∧ + |trace (matrixWord D.J v*(derivativeMatrix y x-D.implicitRetainedField t y x))|≤ + ((1+|D.j*siteMean D.implicitCoefficient x|)*(C+F)+F)*M := by + obtain ⟨he,he'⟩:=D.implicit_error_solved t w y hW hY x (D.implicit_inverse_left x ha0 hS) + exact implicit_source_field_trace _ _ _ _ _ _ _ _ he he' hs hf ha hwords v hlen hv + +end SKGapCutoff.Recipe.OrdinaryData + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Stability/ImplicitUniform.lean b/lean/OAI/Probability/SKGap/Stability/ImplicitUniform.lean new file mode 100644 index 0000000000000000000000000000000000000000..64f166e6572e584fd165539e04b20858d26a63f1 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Stability/ImplicitUniform.lean @@ -0,0 +1,208 @@ +import Mathlib +import OAI.Probability.SKGap.Stability.ImplicitCoefficient +import OAI.Probability.SKGap.Stability.ImplicitFrobenius + +namespace OAI + +section + +noncomputable section +namespace SKGap.ImplicitSystem +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] + +lemma L₂_norm_le (j χ r : ℝ) (J : E→L[ℝ]E) (v ell : E) : + ‖L₂ j χ r J v ell‖≤‖J‖+|j| *|χ|+|j| *|r| *‖v‖*‖ell‖ := by + unfold L₂ + calc + _ ≤ ‖-J+(j*χ) • (1:E→L[ℝ]E)‖+‖(j*r) • rank v ell‖ := norm_add_le _ _ + _ ≤ (‖J‖+|j| *|χ|)+|j| *|r| *(‖v‖*‖ell‖) := by + apply add_le_add + · apply (norm_add_le _ _).trans + simp only [norm_neg,norm_smul,Real.norm_eq_abs,abs_mul] + exact add_le_add le_rfl (mul_le_of_le_one_right (by positivity) ContinuousLinearMap.norm_id_le) + · rw [norm_smul,Real.norm_eq_abs,abs_mul] + exact mul_le_mul_of_nonneg_left (rank_norm_le v ell) (by positivity) + _ = _ := by ring + +lemma L₂_normalized_bound (j χ r : ℝ) (J : E→L[ℝ]E) (v ell : E) + {d V Q A L : ℝ} (hr : 0≤r) (hd : 0≤d) (hscale : r*d^2=1) + (hV : 0≤V) (hQ : 0≤Q) (hv : ‖v‖≤V*d) (hell : ‖ell‖≤Q*d) + (hχ : |χ|≤A) (hJ : ‖J‖≤L) : + ‖L₂ j χ r J v ell‖≤L+|j| *A+|j| *V*Q := by + apply (L₂_norm_le j χ r J v ell).trans + rw [abs_of_nonneg hr] + have hmul:=mul_le_mul hv hell (norm_nonneg ell) (mul_nonneg hV hd) + calc + _ ≤ L+|j| *A+|j| *r*((V*d)*(Q*d)) := by + rw [mul_assoc (|j| *r)] + exact add_le_add (add_le_add hJ (mul_le_mul_of_nonneg_left hχ (abs_nonneg _))) + (mul_le_mul_of_nonneg_left hmul (by positivity)) + _ = L+|j| *A+|j| *V*Q*(r*d^2) := by ring + _ ≤ _ := by + simpa only [mul_one] using add_le_add (le_refl (L+|j| *A)) + (mul_le_mul_of_nonneg_left hscale.le (mul_nonneg (mul_nonneg (abs_nonneg j) hV) hQ)) + +variable [FiniteDimensional ℝ E] + +theorem implicit_uniform_size (j χ b r p : ℝ) (X J : E→L[ℝ]E) + (u m t ell q w y : E) (c : ℝ) + {δ d A L Q U P : ℝ} (hδ : 0<δ) (hd : 0.trans (mul_le_mul_of_nonneg_left hX hK)) + (by positivity) + (add_nonneg hU (mul_nonneg (mul_nonneg (by norm_num : (0:ℝ)≤2) (abs_nonneg j)) hP))) + have hc' : d*|c|≤Q*W+P := by + have hh:=implicit_scalar_size r p ell w + rw [←hEq.2.2,abs_of_nonneg hr] at hh + have hb:=mul_le_mul hell hw' (norm_nonneg w) (mul_nonneg hQ hd.le) + calc + _ ≤ d*(r*((Q*d)*W)+|p|) := mul_le_mul_of_nonneg_left + (hh.trans (add_le_add (by rw [mul_assoc]; exact mul_le_mul_of_nonneg_left hb hr) le_rfl)) hd.le + _ = Q*W*(r*d^2)+d*|p| := by ring + _ = Q*W+d*|p| := by rw [hscale]; ring + _ ≤ _ := add_le_add le_rfl hp + refine ⟨hw',hc',?_⟩ + rw [hEq.2.1] + apply (implicit_field_size J j χ c w m).trans + rw [abs_mul] + have h₁:=mul_le_mul (add_le_add hJ (mul_le_mul_of_nonneg_left hχ (abs_nonneg _))) hw' + (norm_nonneg w) (by positivity : 0≤L+|j| *A) + have h₂ : |j| *|c| *‖m‖≤|j| *(Q*W+P) := by + calc + _ ≤ |j| *|c| *d := mul_le_mul_of_nonneg_left hm (by positivity) + _ = |j| *(d*|c|) := by ring + _ ≤ _ := mul_le_mul_of_nonneg_left hc' (abs_nonneg _) + exact add_le_add h₁ h₂ +end SKGap.ImplicitSystem + +end +end + +section + +noncomputable section +open scoped BigOperators +namespace SKGap.ImplicitSystem +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] +variable {ι : Type*} [Fintype ι] + +lemma implicit_field_difference (s j χ χ' r p p' : ℝ) (A A' J : E→L[ℝ]E) + (u u' m m' t ell ell' w w' y y' : E) (c c' : ℝ) + (h : Equations j χ r p A J u m t ell w y c) + (h' : Equations j χ' r p' A' J u' m' t ell' w' y' c') : + s • (y-y')=J (s • (w-w'))-(j*χ') • (s • (w-w'))- + (j*(s*(χ-χ'))) • w-(j*c) • (s • (m-m'))-(j*(s*(c-c'))) • m' := by + rw [h.2.1,h'.2.1] + simp only [map_sub,map_smul] + module + +theorem implicit_scalar_columns (s : ι→ℝ) (r p : ℝ) (ell w : E) (c : ℝ) + (p' c' : ι→ℝ) (ell' w' : ι→E) + (hc : c=r*inner ℝ ell w+p) (hc' : ∀i,c' i=r*inner ℝ (ell' i) (w' i)+p' i) + {d R P Q : ℝ} (hr : 0≤r) (hd : 0s i • (ell-ell' i))≤R*d) + (hP : d*columnNorm (fun i=>s i*(p-p' i))≤P) + (hQ : 0≤Q) (hL : ∀i,‖ell' i‖≤Q*d) : + d*columnNorm (fun i=>s i*(c-c' i))≤R*‖w‖+P+Q*columnNorm (fun i=>s i • (w-w' i)) := by + have he : (fun i=>s i*(c-c' i))=(fun i=>r*inner ℝ (s i • (ell-ell' i)) w+s i*(p-p' i)+ + r*inner ℝ (ell' i) (s i • (w-w' i))) := by + funext i + rw [hc,hc' i] + exact implicit_scalar_difference (s i) r p (p' i) ell (ell' i) w (w' i) + rw [he] + exact normalized_scalar_difference _ _ _ _ w hr hd hscale hR hD hP hQ hL + +theorem implicit_field_columns (s : ι→ℝ) (j χ r p : ℝ) (A J : E→L[ℝ]E) + (u m t ell w y : E) (c : ℝ) (χ' p' c' : ι→ℝ) + (A' : ι→E→L[ℝ]E) (u' m' ell' w' y' : ι→E) + (h : Equations j χ r p A J u m t ell w y c) + (h' : ∀i,Equations j (χ' i) r (p' i) (A' i) J (u' i) (m' i) t (ell' i) (w' i) (y' i) (c' i)) + {L H d Rχ Rm C M Dc : ℝ} (hL : 0≤L) (hH : 0≤H) (hd : 0s i*(χ-χ' i))≤Rχ) + (hDm : columnNorm (fun i=>s i • (m-m' i))≤Rm*d) + (hc : d*|c|≤C) (hm : ∀i,‖m' i‖≤M*d) + (hdc : d*columnNorm (fun i=>s i*(c-c' i))≤Dc) : + columnNorm (fun i=>s i • (y-y' i))≤ + (L+|j| *H)*columnNorm (fun i=>s i • (w-w' i))+|j| *‖w‖*Rχ+|j| *C*Rm+|j| *M*Dc := by + let Dw:=fun i=>s i • (w-w' i) + let Dχ:=fun i=>s i*(χ-χ' i) + let Dm:=fun i=>s i • (m-m' i) + let Dc':=fun i=>s i*(c-c' i) + have ha : columnNorm (fun i=>J (Dw i))≤L*columnNorm Dw := + columnNorm_operator (fun _=>J) Dw hL (fun _=>hJ) + have hb : columnNorm (fun i=>(j*χ' i) • Dw i)≤(|j| *H)*columnNorm Dw := by + apply columnNorm_compare _ _ (by positivity) + intro i + rw [norm_smul,Real.norm_eq_abs,abs_mul] + exact mul_le_mul_of_nonneg_right (mul_le_mul_of_nonneg_left (hχ i) (abs_nonneg j)) (norm_nonneg _) + have he : columnNorm (fun i=>(j*Dχ i) • w)≤|j| *‖w‖*Rχ := by + have eq : (fun i=>(j*Dχ i) • w)=j • (fun i=>Dχ i • w) := by ext i; simp [mul_smul] + rw [eq,columnNorm_smul] + exact (mul_le_mul_of_nonneg_left (columnNorm_vector_scalar (fun _=>w) Dχ (norm_nonneg w) (fun _=>le_rfl)) (abs_nonneg j)).trans + (by + simpa only [mul_assoc,mul_comm,mul_left_comm] using mul_le_mul hDχ + (le_refl (|j| *‖w‖)) (mul_nonneg (abs_nonneg j) (norm_nonneg w)) hRχ) + have hf : columnNorm (fun i=>(j*c) • Dm i)≤|j| *C*Rm := by + change columnNorm ((j*c) • Dm)≤_ + rw [columnNorm_smul,abs_mul] + calc + _ ≤ |j| *|c| *(Rm*d) := mul_le_mul_of_nonneg_left hDm (by positivity) + _ = (|j| *Rm)*(d*|c|) := by ring + _ ≤ (|j| *Rm)*C := by + simpa only [mul_comm] using mul_le_mul hc (le_refl (|j| *Rm)) + (mul_nonneg (abs_nonneg j) hRm) hC + _ = _ := by ring + have hg : columnNorm (fun i=>(j*Dc' i) • m' i)≤|j| *M*Dc := by + have eq : (fun i=>(j*Dc' i) • m' i)=j • (fun i=>Dc' i • m' i) := by ext i; simp [mul_smul] + rw [eq,columnNorm_smul] + calc + _ ≤ |j| *((M*d)*columnNorm Dc') := mul_le_mul_of_nonneg_left + (columnNorm_vector_scalar m' Dc' (by positivity) hm) (abs_nonneg j) + _ = (|j| *M)*(d*columnNorm Dc') := by ring + _ ≤ _ := mul_le_mul_of_nonneg_left hdc (by positivity) + have eq : (fun i=>s i • (y-y' i))=(fun i=>J (Dw i))+(fun i=>-((j*χ' i) • Dw i))- + (fun i=>(j*Dχ i) • w)-(fun i=>(j*c) • Dm i)-(fun i=>(j*Dc' i) • m' i) := by + funext i + simpa only [Pi.add_apply,Pi.sub_apply,Pi.neg_apply,Dw,Dχ,Dm,Dc',sub_eq_add_neg] using + implicit_field_difference (s i) j χ (χ' i) r p (p' i) A (A' i) J u (u' i) m (m' i) t ell (ell' i) w (w' i) y (y' i) c (c' i) h (h' i) + rw [eq] + have ht:=columnNorm_add_sub_sub_sub (fun i=>J (Dw i)) (fun i=>-((j*χ' i) • Dw i)) + (fun i=>(j*Dχ i) • w) (fun i=>(j*c) • Dm i) (fun i=>(j*Dc' i) • m' i) + change columnNorm _≤_ at ht + have hn : columnNorm (fun i=>-((j*χ' i) • Dw i))=columnNorm (fun i=>(j*χ' i) • Dw i) := columnNorm_neg _ + rw [hn] at ht + exact ht.trans (by nlinarith only [ha,hb,he,hf,hg]) +end SKGap.ImplicitSystem + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Stability/ImplicitUniformControl.lean b/lean/OAI/Probability/SKGap/Stability/ImplicitUniformControl.lean new file mode 100644 index 0000000000000000000000000000000000000000..76b2800efae12e707706e31730260a5d134ed5d9 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Stability/ImplicitUniformControl.lean @@ -0,0 +1,188 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.CoefficientRow +import OAI.Probability.SKGap.Stability.ImplicitPerturb +import OAI.Probability.SKGap.Stability.ImplicitUniform + +namespace OAI + +section + +noncomputable section +namespace SKGap.ImplicitSystem +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] + [FiniteDimensional ℝ E] {ι : Type*} [Fintype ι] + +def uniformControlBudget (j δ B : ℝ) : ℝ := + let L:=B+|j| *B^2+2*|j| *B + let W:=(1+B^2*(δ/2)⁻¹*L)*B^2*(B+2*|j| *B) + let C:=B*W+B + let Y:=(B+|j| *B^2)*W+|j| *C + let F:=(1+B^2*(δ/2)⁻¹*L)*(B*(B+Y+|j| *C)+B^2*B+ + |j| *B^2*W*B+|j| *B^2*C*B+|j| *B^2*2*(B*W+B)) + let G:=B*W+B+B*F + let H:=(B+|j| *B^2)*F+|j| *W*B+|j| *C*B+|j| *G + W+C+Y+F+G+H + +lemma uniformControlBudget_nonneg {j δ B : ℝ} (hδ : 0<δ) (hB : 0≤B) : + 0≤uniformControlBudget j δ B := by unfold uniformControlBudget; positivity + +theorem implicit_uniform_control (j χ b r p : ℝ) (X J : E→L[ℝ]E) + (u m t ell q w y : E) (c : ℝ) + (s χ' p' c' b' : ι→ℝ) (X' : ι→E→L[ℝ]E) (u' m' ell' w' y' q' : ι→E) + {δ d B : ℝ} (hδ : 0<δ) (hd : 0(s i • (X*X-X' i*X' i)) V)≤B*‖V‖) + (hDu : columnNorm (fun i=>s i • (u-u' i))≤B) + (hDχ : columnNorm (fun i=>s i*(χ-χ' i))≤B) + (hDm : columnNorm (fun i=>s i • (m-m' i))≤B*d) + (hDell : columnNorm (fun i=>s i • (ell-ell' i))≤B*d) + (hDp : d*columnNorm (fun i=>s i*(p-p' i))≤B) : + ‖w‖+d*|c|+‖y‖+columnNorm (fun i=>s i • (w-w' i))+ + d*columnNorm (fun i=>s i*(c-c' i))+columnNorm (fun i=>s i • (y-y' i))≤ + uniformControlBudget j δ B := by + let L:=B+|j| *B^2+2*|j| *B + let W:=(1+B^2*(δ/2)⁻¹*L)*B^2*(B+2*|j| *B) + let C:=B*W+B + let Y:=(B+|j| *B^2)*W+|j| *C + let F:=(1+B^2*(δ/2)⁻¹*L)*(B*(B+Y+|j| *C)+B^2*B+ + |j| *B^2*W*B+|j| *B^2*C*B+|j| *B^2*2*(B*W+B)) + let G:=B*W+B+B*F + let H:=(B+|j| *B^2)*F+|j| *W*B+|j| *C*B+|j| *G + have hW0 : 0≤W := by dsimp [W,L]; positivity + have hC0 : 0≤C := by dsimp [C]; positivity + have hY0 : 0≤Y := by dsimp [Y]; positivity + have hL0 : 0≤L := by dsimp [L]; positivity + have hF0 : 0≤F := by dsimp [F]; positivity + obtain ⟨hw,hc,hy⟩:=implicit_uniform_size j χ b r p X J u m t ell q w y c + hδ hd hr hscale (sq_nonneg B) hB hB hB hB + (pow_le_pow_left₀ (norm_nonneg X) hX 2) hJ hχ hu hm ht hell hp hS hSmall h + change ‖w‖≤W at hw + change d*|c|≤C at hc + change ‖y‖≤Y at hy + have hl : ∀i,‖L₂ j (χ' i) r J (m' i+t) (ell' i)‖≤L := by + intro i + have hv : ‖m' i+t‖≤2*d := (norm_add_le _ _).trans (by linarith [hm' i]) + convert L₂_normalized_bound j (χ' i) r J (m' i+t) (ell' i) hr hd.le hscale + (by norm_num : (0:ℝ)≤2) hB hv (hell' i) (hχ' i) hJ using 1; dsimp [L]; ring + have hb : ‖u+J w-(j*χ) • w-(j*c) • (m+t)‖≤B+Y+|j| *C := by + have he : u+J w-(j*χ) • w-(j*c) • (m+t)=u+y-(j*c) • t := by + rw [h.2.1]; module + rw [he] + apply (norm_sub_le _ _).trans + have hct : ‖(j*c) • t‖≤|j| *C := by + rw [norm_smul,Real.norm_eq_abs,abs_mul] + calc + _ ≤ |j| *|c| *d := mul_le_mul_of_nonneg_left ht (by positivity) + _ = |j| *(d*|c|) := by ring + _ ≤ _ := mul_le_mul_of_nonneg_left hc (abs_nonneg j) + exact add_le_add ((norm_add_le _ _).trans (add_le_add hu hy)) hct + have hf:=implicit_frobenius_estimate j χ r p X J u m t ell w y c + s χ' p' c' X' u' m' ell' w' y' q' b' h h' hδ hB hL0 hd hr hscale + hB hB hB hB hB hB hC0 (by norm_num : (0:ℝ)≤2) hX' hl hS' hSmall' + hDA hDu hDχ hDm hDell hDp hc (fun i=>(norm_add_le _ _).trans (by linarith [hm' i])) + have hf' : columnNorm (fun i=>s i • (w-w' i))≤F := by + apply hf.trans + apply mul_le_mul_of_nonneg_left _ (by positivity) + exact add_le_add (add_le_add (add_le_add (add_le_add + (mul_le_mul_of_nonneg_left hb hB) le_rfl) + (mul_le_mul_of_nonneg_right (mul_le_mul_of_nonneg_left hw (by positivity)) hB)) le_rfl) + (mul_le_mul_of_nonneg_left (add_le_add (mul_le_mul_of_nonneg_left hw hB) le_rfl) (by positivity)) + have hg : d*columnNorm (fun i=>s i*(c-c' i))≤G := by + exact (implicit_scalar_columns s r p ell w c p' c' ell' w' h.2.2 (fun i=>(h' i).2.2) + hr hd hscale hB hDell hDp hB hell').trans (add_le_add + (add_le_add (mul_le_mul_of_nonneg_left hw hB) le_rfl) (mul_le_mul_of_nonneg_left hf' hB)) + have hh : columnNorm (fun i=>s i • (y-y' i))≤H := by + have hh:=implicit_field_columns s j χ r p (X*X) J u m t ell w y c χ' p' c' + (fun i=>X' i*X' i) u' m' ell' w' y' h h' hB (sq_nonneg B) hd hB hB hC0 + (by norm_num : (0:ℝ)≤1) hJ hχ' hDχ hDm hc (by simpa only [one_mul] using hm') hg + apply hh.trans + simp only [mul_one] + exact add_le_add (add_le_add (add_le_add (mul_le_mul_of_nonneg_left hf' (by positivity)) + (mul_le_mul_of_nonneg_right (mul_le_mul_of_nonneg_left hw (abs_nonneg j)) hB)) le_rfl) le_rfl + change _≤W+C+Y+F+G+H + exact add_le_add (add_le_add (add_le_add (add_le_add (add_le_add hw hc) hy) hf') hg) hh +end SKGap.ImplicitSystem + +end +end + +section + +noncomputable section +open scoped BigOperators Matrix.Norms.Frobenius +namespace SKGapCutoff.Recipe +open Primary SKGap.ImplicitSystem +variable {n : ℕ} + +lemma halfDiff_column (U : VectorFields n) (x : Spin n) (k : Fin n) : + ((spin x k/2) • ((WithLp.toLp 2 (U x) : Euclid n)-WithLp.toLp 2 (U (flip x k))))= + WithLp.toLp 2 (fun i=>derivativeMatrix U x i k) := by + ext i + change (spin x k/2)*(U x i-U (flip x k) i)=halfDiff k (fun y=>U y i) x + rw [halfDiff_as_flip]; ring + +lemma columnNorm_halfDiff (U : VectorFields n) (x : Spin n) : + columnNorm (fun k=>(spin x k/2) • + ((WithLp.toLp 2 (U x) : Euclid n)-WithLp.toLp 2 (U (flip x k))))=‖derivativeMatrix U x‖ := by + simp only [halfDiff_column] + exact columnNorm_matrix _ + +lemma columnNorm_scalar_halfDiff (f : Spin n→ℝ) (x : Spin n) : + columnNorm (fun k=>(spin x k/2)*(f x-f (flip x k)))=‖derivativeVector f x‖ := by + have he : (fun k=>(spin x k/2)*(f x-f (flip x k)))=fun k=>halfDiff k f x := by + ext k; rw [halfDiff_as_flip]; ring + rw [he] + rfl + +lemma diagonal_halfDiff_columns (a : VectorFields n) (x : Spin n) {R : ℝ} + (hR : 0≤R) (ha : ∀i,∑k,(derivativeMatrix a x i k)^2≤R^2) + (V : Euclid n) : + columnNorm (fun k=>((spin x k/2) • + (Matrix.toEuclideanCLM (𝕜:=ℝ) (Matrix.diagonal (a x))- + Matrix.toEuclideanCLM (𝕜:=ℝ) (Matrix.diagonal (a (flip x k))))) V)≤R*‖V‖ := by + apply coefficient_diagonal_columns (fun _=>a x) (fun k=>a (flip x k)) (fun k=>spin x k/2) hR + intro i + convert ha i using 1 + apply Finset.sum_congr rfl + intro k _ + congr 1 + rw [derivativeMatrix,halfDiff_as_flip] + ring + +lemma implicit_tuple_small (w y : VectorFields n) (c : Spin n→ℝ) (x : Spin n) + {d C : ℝ} (hd : 0≤d) (hC : 0≤C) + (h : vectorNorm (w x)+d*|c x|+vectorNorm (y x)+‖derivativeMatrix w x‖+ + d*‖derivativeVector c x‖+‖derivativeMatrix y x‖≤C) : + SmallBound w x C ∧ SmallBound y x C ∧ + |d*c x|≤C ∧ ‖derivativeVector (fun z=>d*c z) x‖≤C := by + have hw0:=vectorNorm_nonneg (w x) + have hy0:=vectorNorm_nonneg (y x) + have hc0:=mul_nonneg hd (abs_nonneg (c x)) + have hw1:=norm_nonneg (derivativeMatrix w x) + have hy1:=norm_nonneg (derivativeMatrix y x) + have hc1:=mul_nonneg hd (norm_nonneg (derivativeVector c x)) + refine ⟨⟨hC,by linarith,by linarith⟩,⟨hC,by linarith,by linarith⟩,?_,?_⟩ + · rw [abs_mul,abs_of_nonneg hd]; linarith + · have he : derivativeVector (fun z=>d*c z) x=d • derivativeVector c x := by + ext k + change halfDiff k (fun z=>d*c z) x=d*halfDiff k c x + simp [halfDiff]; ring + rw [he,norm_smul,Real.norm_eq_abs,abs_of_nonneg hd] + linarith +end SKGapCutoff.Recipe + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Stability/LawMean.lean b/lean/OAI/Probability/SKGap/Stability/LawMean.lean new file mode 100644 index 0000000000000000000000000000000000000000..17640b250ff110530e7de444141af85849051e4f --- /dev/null +++ b/lean/OAI/Probability/SKGap/Stability/LawMean.lean @@ -0,0 +1,436 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.PoissonWeight +import OAI.Probability.SKGap.Localization.DerivNonnegRightMin +import OAI.Probability.SKGap.Stability.HalfDiffField + +namespace OAI + +section +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open scoped BigOperators +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open scoped BigOperators +open scoped BigOperators NNReal ENNReal +open MeasureTheory Metric Set +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators NNReal ENNReal Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Set +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators ENNReal NNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Matrix +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators ENNReal NNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal +open scoped BigOperators +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise NNReal ENNReal +open scoped BigOperators +open Filter Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal Topology +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Set Matrix +open scoped BigOperators NNReal ENNReal Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open Filter MeasureTheory ProbabilityTheory +open scoped Topology NNReal ENNReal +open Filter MeasureTheory ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter +open scoped Topology NNReal ENNReal +open MeasureTheory Filter ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter +open scoped Topology +open MeasureTheory Filter ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter ProbabilityTheory ContinuousLinearMap +open scoped Topology NNReal ENNReal +open Filter MeasureTheory ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter +open scoped BigOperators Topology +open MeasureTheory Filter +open scoped BigOperators Topology +open MeasureTheory Filter +open scoped BigOperators Topology +open MeasureTheory Filter +open scoped BigOperators Topology +open MeasureTheory Filter +open scoped BigOperators Topology +open Filter Set Metric +open scoped Topology RealInnerProductSpace +open scoped BigOperators +open ContinuousLinearMap +open scoped BigOperators +open ContinuousLinearMap +open scoped Topology Interval +open MeasureTheory + +open MeasureTheory +open scoped BigOperators Topology Interval +namespace SKGapCutoff + +noncomputable def lawMean {n : ℕ} (p : Spin n → ℝ) (f : Observables n) : ℝ := + ∑ x, p x*f x + +noncomputable def lawVariance {n : ℕ} (p : Spin n → ℝ) (f : Observables n) : ℝ := + lawMean p (fun x => f x^2)-(lawMean p f)^2 + +noncomputable def pushLaw {n : ℕ} (T : Observables n →L[ℝ] Observables n) + (p : Spin n → ℝ) : Spin n → ℝ := + fun y => ∑ x, p x*T (fun z => if z=y then 1 else 0) x + +lemma lawMean_pushLaw {n : ℕ} (T : Observables n →L[ℝ] Observables n) + (p : Spin n → ℝ) (f : Observables n) : + lawMean (pushLaw T p) f = lawMean p (T f) := by + unfold lawMean pushLaw + simp_rw [Finset.sum_mul] + rw [Finset.sum_comm] + simp_rw [mul_assoc, ← Finset.mul_sum, kernel_apply] + +lemma lawMean_const {n : ℕ} (p : Spin n → ℝ) (hp : ∑ x, p x=1) (c : ℝ) : + lawMean p (fun _ => c) = c := by simp [lawMean, ← Finset.sum_mul, hp] + +lemma lawMean_mono {n : ℕ} (p : Spin n → ℝ) (hp : ∀ x, 0 ≤ p x) + {f g : Observables n} (hfg : ∀ x, f x≤g x) : lawMean p f ≤ lawMean p g := by + exact Finset.sum_le_sum (fun x _ => mul_le_mul_of_nonneg_left (hfg x) (hp x)) + +lemma lawMean_le_const {n : ℕ} (p : Spin n → ℝ) (hp : ∀ x, 0 ≤ p x) + (hs : ∑ x, p x=1) {f : Observables n} {b : ℝ} (hf : ∀ x, f x≤b) : + lawMean p f ≤ b := (lawMean_mono p hp hf).trans_eq (lawMean_const p hs b) + +lemma lawMean_add {n : ℕ} (p : Spin n → ℝ) (f g : Observables n) : + lawMean p (f+g) = lawMean p f+lawMean p g := by + simp [lawMean, mul_add, Finset.sum_add_distrib] + +lemma lawMean_sub {n : ℕ} (p : Spin n → ℝ) (f g : Observables n) : + lawMean p (f-g) = lawMean p f-lawMean p g := by + simp [lawMean, mul_sub, Finset.sum_sub_distrib] + +lemma lawMean_smul {n : ℕ} (p : Spin n → ℝ) (a : ℝ) (f : Observables n) : + lawMean p (a • f) = a*lawMean p f := by + simp [lawMean, mul_left_comm, Finset.mul_sum] + +lemma lawVariance_centered {n : ℕ} (p : Spin n → ℝ) (hs : ∑ x, p x=1) + (f : Observables n) : + ∑ x, p x*(f x-lawMean p f)^2 = lawVariance p f := by + have he (x : Spin n) : p x*(f x-lawMean p f)^2 = + p x*f x^2-2*lawMean p f*(p x*f x)+(lawMean p f)^2*p x := by ring + simp_rw [he] + rw [Finset.sum_add_distrib, Finset.sum_sub_distrib, ← Finset.mul_sum, + ← Finset.mul_sum, hs] + change lawMean p (fun x => f x^2)-2*lawMean p f*lawMean p f+(lawMean p f)^2*1 = _ + unfold lawVariance + ring + +lemma lawVariance_sub_const {n : ℕ} (p : Spin n → ℝ) (hs : ∑ x, p x=1) + (f : Observables n) (c : ℝ) : lawVariance p (fun x => f x-c) = lawVariance p f := by + rw [← lawVariance_centered p hs, ← lawVariance_centered p hs] + have hm : lawMean p (fun x => f x-c) = lawMean p f-c := by + exact (lawMean_sub p f (fun _ => c)).trans (by rw [lawMean_const p hs]) + rw [hm] + congr 1 + funext x + congr 2 + ring + +lemma pushLaw_sum {n : ℕ} (T : Observables n →L[ℝ] Observables n) + (p : Spin n → ℝ) (hs : ∑ x, p x=1) (hT : T (fun _ => 1) = fun _ => 1) : + ∑ x, pushLaw T p x=1 := by + have hh := lawMean_pushLaw T p (fun _ => 1) + simpa [lawMean, hT, hs] using hh + +lemma pushLaw_nonneg {n : ℕ} (T : Observables n →L[ℝ] Observables n) + (p : Spin n → ℝ) (hp : ∀ x, 0 ≤ p x) + (hT : ∀ f : Observables n, (∀ x, 0 ≤ f x) → ∀ x, 0 ≤ T f x) : + ∀ x, 0 ≤ pushLaw T p x := by + intro y + exact Finset.sum_nonneg (fun x _ => mul_nonneg (hp x) + (hT _ (fun z => by split_ifs <;> norm_num) x)) + +lemma evolvedLaw_variance_decomposition {n : ℕ} (J : Interaction n) (t : ℝ) + (p : Spin n → ℝ) (f : Observables n) : + lawVariance (pushLaw (semigroup J t) p) f = + lawMean p (fun x => semigroup J t (fun y => f y^2) x-(semigroup J t f x)^2)+ + lawVariance p (semigroup J t f) := by + unfold lawVariance + rw [lawMean_pushLaw, lawMean_pushLaw] + rw [show (fun x => semigroup J t (fun y => f y^2) x-(semigroup J t f x)^2) = + semigroup J t (fun y => f y^2)-(fun x => (semigroup J t f x)^2) from rfl, + lawMean_sub] + ring + +theorem trajectory_variance_from_gradient {n : ℕ} (J : Interaction n) (t C : ℝ) + (ht : 0 ≤ t) (hC : 0 ≤ C) (p : Spin n → ℝ) + (hp : ∀ x, 0 ≤ p x) (hs : ∑ x, p x=1) + (hP : ∀ f : Observables n, lawVariance p f ≤ + C*lawMean p (fun x => ∑ i, (halfDiff i f x)^2)) + (f : Observables n) (b : ℝ → ℝ) (hb : IntervalIntegrable b volume 0 t) + (hgrad : ∀ r ∈ Set.Icc (0:ℝ) t, ∀ x, + ∑ i, (halfDiff i (semigroup J r f) x)^2 ≤ b r) : + lawVariance (pushLaw (semigroup J t) p) f ≤ + 4*(∫ r in 0..t, b r)+C*b t := by + rw [evolvedLaw_variance_decomposition] + apply add_le_add + · exact lawMean_le_const p hp hs (semigroup_variance_le J f t ht b hb hgrad) + · exact (hP _).trans (mul_le_mul_of_nonneg_left + (lawMean_le_const p hp hs (hgrad t ⟨ht, le_rfl⟩)) hC) + +lemma pushed_totalVariation_le_worst {n : ℕ} (J : Interaction n) (t : ℝ) + (p : Spin n → ℝ) (hp : ∀ x, 0 ≤ p x) (hs : ∑ x, p x=1) : + totalVariation (pushLaw (semigroup J t) p) (gibbs J) ≤ worstContinuous J t := by + apply (totalVariation_mixture_le p hp hs (continuousKernel J t) (gibbs J)).trans + calc + _ ≤ ∑ x, p x*worstContinuous J t := by + apply Finset.sum_le_sum + intro x _ + apply mul_le_mul_of_nonneg_left _ (hp x) + exact Finset.le_sup' (fun x => totalVariation (continuousKernel J t x) (gibbs J)) + (Finset.mem_univ x) + _ = _ := by rw [← Finset.sum_mul, hs, one_mul] + +noncomputable def preparationLaw {n : ℕ} (J : Interaction n) + (g : VectorFields n) (h : ℝ) : Spin n → ℝ := + pushLaw (preparationFlow J g h) (gibbs J) + +lemma lawMean_preparationLaw {n : ℕ} (J : Interaction n) + (g : VectorFields n) (h : ℝ) (f : Observables n) : + lawMean (preparationLaw J g h) f = gibbsExpectation J (preparationFlow J g h f) := + lawMean_pushLaw _ _ _ + +lemma preparationLaw_nonneg {n : ℕ} (J : Interaction n) + (g : VectorFields n) (h : ℝ) (hh : 0 ≤ h) : ∀ x, 0 ≤ preparationLaw J g h x := by + apply pushLaw_nonneg _ _ (fun x => (gibbs_pos J x).le) + rw [← refreshSemigroup_eq_preparationFlow] + exact refreshSemigroup_nonneg _ (fun x i => (Real.abs_tanh_lt_one _).le) h hh + +lemma preparationLaw_sum {n : ℕ} (J : Interaction n) + (g : VectorFields n) (h : ℝ) : ∑ x, preparationLaw J g h x=1 := by + apply pushLaw_sum _ _ (gibbs_sum J) + rw [← refreshSemigroup_eq_preparationFlow, refreshSemigroup_const] + +lemma preparationLaw_poincare {n : ℕ} (J : Interaction n) + (γ : ℝ) (hγ : 0 < γ) (hg : HasGap J γ) + (g : VectorFields n) (C : ℝ) (hC : 0 ≤ C) + (hJC : ‖Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) J‖ ≤ C) + (hgc : ∀ x, ‖Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) + (fun j i => halfDiff i (fun y => g y j) x)‖ ≤ 1) + (f : Observables n) (h : ℝ) (hh : 0 ≤ h) : + lawVariance (preparationLaw J g h) f ≤ + (γ⁻¹*Real.exp (preparationGrowth (C+1)*h)+ + 4*((Real.exp (preparationGrowth (C+1)*h)-1)/preparationGrowth (C+1)))* + lawMean (preparationLaw J g h) (fun x => ∑ i, (halfDiff i f x)^2) := by + unfold lawVariance + simp_rw [lawMean_preparationLaw] + exact preparation_poincare J γ hγ hg g C hC hJC hgc f h hh + +open scoped RealInnerProductSpace + +noncomputable def lawBarycenter {E : Type*} [AddCommGroup E] [Module ℝ E] + {n : ℕ} (p : Spin n → ℝ) (F : Spin n → E) : E := ∑ x, p x • F x + +lemma lawMean_inner_sub {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] + {n : ℕ} (p : Spin n → ℝ) (hs : ∑ x, p x=1) (F : Spin n → E) (u c : E) : + lawMean p (fun x => ⟪u, F x-c⟫) = ⟪u, lawBarycenter p F-c⟫ := by + simp [lawMean, lawBarycenter, inner_sub_right, inner_sum, inner_smul_right, + mul_sub, Finset.sum_sub_distrib, ← Finset.sum_mul, hs] + +theorem worstContinuous_lower_from_prepared_image {E : Type*} + [NormedAddCommGroup E] [InnerProductSpace ℝ E] [FiniteDimensional ℝ E] + {n : ℕ} (J : Interaction n) (t : ℝ) (ht : 0 ≤ t) + (p : E → Spin n → ℝ) (hp : ∀ z x, 0 ≤ p z x) (hs : ∀ z, ∑ x, p z x=1) + (F : Spin n → E) (u : E) (hu : ‖u‖=1) (z₀ : E) (R a V : ℝ) + (hR : 0 < R) (ha : 0 < a) + (hcont : Continuous (fun z => lawBarycenter (pushLaw (semigroup J t) (p z)) F)) + (hbase : lawBarycenter (pushLaw (semigroup J t) (p z₀)) F = lawBarycenter (gibbs J) F) + (hder : ∀ z ∈ Metric.ball z₀ R, ∃ A : E →L[ℝ] E, + HasFDerivAt (fun z => lawBarycenter (pushLaw (semigroup J t) (p z)) F) A z ∧ + ∀ v : E, a*‖v‖ ≤ ‖A.adjoint v‖) + (hvar : ∀ z ∈ Metric.ball z₀ R, + lawVariance (pushLaw (semigroup J t) (p z)) (fun x => ⟪u, F x⟫) ≤ V) + (heqvar : lawVariance (gibbs J) (fun x => ⟪u, F x⟫) ≤ V) : + (a*R/2)^2*(1-worstContinuous J t) ≤ 8*V := by + let M : E → E := fun z => lawBarycenter (pushLaw (semigroup J t) (p z)) F + let c := lawBarycenter (gibbs J) F + let m := a*R/2 + change M z₀=c at hbase + have hm : 0 < m := by dsimp [m]; positivity + have hy : M z₀+m • u ∈ Metric.ball (M z₀) (a*R) := by + rw [Metric.mem_ball, dist_eq_norm, add_sub_cancel_left, norm_smul, hu, + Real.norm_eq_abs, abs_of_pos hm, mul_one] + dsimp [m] + nlinarith [mul_pos ha hR] + obtain ⟨z, hz, hMz⟩ := ball_subset_image_of_adjoint_lower M hcont z₀ hR ha hder hy + let q := pushLaw (semigroup J t) (p z) + have hq : ∀ x, 0 ≤ q x := pushLaw_nonneg _ _ (hp z) (semigroup_nonneg J t ht) + have hqs : ∑ x, q x=1 := pushLaw_sum _ _ (hs z) (semigroup_const J t 1) + let f : Observables n := fun x => ⟪u, F x-c⟫ + have hmean : lawMean q f=m := by + rw [lawMean_inner_sub q hqs F u c] + change ⟪u, M z-c⟫=m + rw [hMz, hbase, add_sub_cancel_left, inner_smul_right, real_inner_self_eq_norm_sq, hu] + simp + have hcenter : f = fun x => ⟪u, F x⟫-⟪u,c⟫ := funext (fun x => inner_sub_right _ _ _) + have hpvar : ∑ x, q x*(f x-m)^2 ≤ V := by + rw [← hmean, lawVariance_centered q hqs] + rw [hcenter] + rw [lawVariance_sub_const q hqs] + exact hvar z hz + have heqmean : lawMean (gibbs J) f=0 := by + rw [lawMean_inner_sub _ (gibbs_sum J)] + simp [c] + have hqvar : ∑ x, gibbs J x*f x^2 ≤ V := by + have hh := lawVariance_centered (gibbs J) (gibbs_sum J) f + rw [heqmean] at hh + simp only [sub_zero] at hh + rw [hh] + rw [hcenter] + rw [lawVariance_sub_const _ (gibbs_sum J)] + exact heqvar + have htv := totalVariation_lower_from_quadratic_test q (gibbs J) f hq (fun x => (gibbs_pos J x).le) + hqs (gibbs_sum J) m V hm hpvar hqvar + apply le_trans _ htv + exact mul_le_mul_of_nonneg_left (sub_le_sub_left + (pushed_totalVariation_le_worst J t (p z) (hp z) (hs z)) 1) (sq_nonneg m) + +lemma preparationFlow_zero {n : ℕ} (J : Interaction n) (h : ℝ) : + preparationFlow J 0 h = semigroup J h := by + rw [← refreshSemigroup_eq_preparationFlow] + have he : (fun x i => Real.tanh (field J x i+(0 : VectorFields n) x i)) = mean J := by + funext x i + simp [mean] + rw [he] + rfl + +lemma pushLaw_gibbs {n : ℕ} (J : Interaction n) + (hJ : ∀ i j, J i j = J j i) (hdiag : ∀ i, J i i=0) (t : ℝ) : + pushLaw (semigroup J t) (gibbs J) = gibbs J := by + funext y + change gibbsExpectation J (semigroup J t (fun z => if z=y then 1 else 0))=gibbs J y + rw [gibbsExpectation_semigroup J hJ hdiag] + simp [gibbsExpectation] + +lemma preparationLaw_zero {n : ℕ} (J : Interaction n) + (hJ : ∀ i j, J i j = J j i) (hdiag : ∀ i, J i i=0) (h : ℝ) : + preparationLaw J 0 h = gibbs J := by + rw [preparationLaw, preparationFlow_zero, pushLaw_gibbs J hJ hdiag] + +lemma polynomial_signal_error {n : ℕ} {d m c q V : ℝ} (hd : d ≤ 1) + (hc : 0 < c) (hm : c*Real.exp (q*Real.log (n:ℝ)) ≤ m) + (hsep : m^2*(1-d) ≤ 8*V) : + |d-1| ≤ (8*V/c^2)*dimensionDecay (2*q) n := by + have hspos : 0 < c*Real.exp (q*Real.log (n:ℝ)) := by positivity + have hmpos := hspos.trans_le hm + have hsq : (c*Real.exp (q*Real.log (n:ℝ)))^2 ≤ m^2 := sq_le_sq₀ hspos.le hmpos.le |>.mpr hm + have hbd := (mul_le_mul_of_nonneg_right hsq (sub_nonneg.mpr hd)).trans hsep + have hp : (c*Real.exp (q*Real.log (n:ℝ)))^2* + ((8*V/c^2)*dimensionDecay (2*q) n) = 8*V := by + have he : Real.exp (q*Real.log (n:ℝ))^2*dimensionDecay (2*q) n=1 := by + rw [← Real.exp_nat_mul, dimensionDecay, ← Real.exp_add] + convert Real.exp_zero using 1 + congr 1 + ring + calc + _ = 8*V*(Real.exp (q*Real.log (n:ℝ))^2*dimensionDecay (2*q) n) := by + field_simp + _ = _ := by rw [he, mul_one] + have hh := (mul_le_mul_iff_right₀ (sq_pos_of_pos hspos)).mp (hbd.trans_eq hp.symm) + rw [abs_of_nonpos (sub_nonpos.mpr hd)] + linarith + +end SKGapCutoff + +open MeasureTheory +open scoped BigOperators Topology Interval + +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Stability/LiteralStableControl.lean b/lean/OAI/Probability/SKGap/Stability/LiteralStableControl.lean new file mode 100644 index 0000000000000000000000000000000000000000..4fd89798eb601543b11a869b520cde279551845e --- /dev/null +++ b/lean/OAI/Probability/SKGap/Stability/LiteralStableControl.lean @@ -0,0 +1,169 @@ +import Mathlib +import OAI.Probability.SKGap.Stability.OrdinaryClosure +import OAI.Probability.SKGap.Stability.ImplicitUniformControl +import OAI.Probability.SKGap.Localization.LiteralSystemBridge + +namespace OAI + +section + +noncomputable section +open scoped BigOperators Matrix.Norms.Frobenius +namespace SKGapCutoff.Recipe +open SKGap.Stein Primary SKGap.ImplicitSystem Matrix +variable {n : ℕ} + +structure LiteralStableAt (J : Interaction n) (j : ℝ) + (z m : VectorFields n) (a : Spin n→ℝ) (r : Fin n→ℝ) + (R ρ δ : ℝ) (x : Spin n) : Prop where + a_bound : |a x|≤R + a_small : |a x|≤ρ + z_near : vectorNorm (z x-r)≤ρ*Real.sqrt n + m_near : vectorNorm (m x-(fun i=>Real.tanh (r i)))≤ρ*Real.sqrt n + m_bound : ∀i,|m x i|≤1 + stable : ∀v,δ*‖v‖^2≤ inner ℝ v + (stableMatrix j ((∑i,scalarVariance (z x i))/(n:ℝ)) (n:ℝ)⁻¹ + (phiSqrt (z x) r (a x)) (toEuclideanCLM (𝕜:=ℝ) J) + (WithLp.toLp 2 (fun i=>Real.tanh (z x i))) v) + +lemma LiteralStableAt.perturbation {J : Interaction n} {j : ℝ} + {z m : VectorFields n} {a : Spin n→ℝ} {r : Fin n→ℝ} + {R ρ δ : ℝ} {x : Spin n} (H : LiteralStableAt J j z m a r R ρ δ x) + (hn : 0phi (z v i) (r i) (a v)) x- + (∑i,scalarVariance (z x i))/(n:ℝ)| *‖phiSqrt (z x) r (a x)‖^2+ + |j*(n:ℝ)⁻¹| *‖phiSqrt (z x) r (a x)‖^2* + (‖(WithLp.toLp 2 (m x) : Euclid n)+WithLp.toLp 2 (fun i=>Real.tanh (r i))- + (2:ℝ) • WithLp.toLp 2 (fun i=>Real.tanh (z x i))‖* + ‖(WithLp.toLp 2 (fun i=>logSlope (z x i) (r i) (a x)) : Euclid n)‖+ + 2*‖(WithLp.toLp 2 (fun i=>Real.tanh (z x i)) : Euclid n)‖* + ‖(WithLp.toLp 2 (fun i=>logSlope (z x i) (r i) (a x)) : Euclid n)+ + WithLp.toLp 2 (fun i=>Real.tanh (z x i))‖)≤δ/2 := + (implicit_normalized_perturbation (z x) r (m x) (a x) j (phiSqrt (z x) r (a x)) + hn hρ H.a_bound H.a_small H.z_near H.m_near (phiSqrt_bound _ _ _ H.a_bound)).trans + (implicit_rho_threshold j R δ ρ hδ hsmall) + +lemma LiteralStableAt.m_size {J : Interaction n} {j : ℝ} + {z m : VectorFields n} {a : Spin n→ℝ} {r : Fin n→ℝ} + {R ρ δ : ℝ} {x : Spin n} (H : LiteralStableAt J j z m a r R ρ δ x) : + vectorNorm (m x)≤Real.sqrt n := by + have h:=vectorNorm_mono (u:=m x) (v:=fun _=>1) (fun i=>by simpa using H.m_bound i) + simpa only [vectorNorm_const,abs_one,one_mul] using h + +lemma frobenius_le_opNorm_sqrt (D : Interaction n) : ‖D‖≤SKGap.opNorm D*Real.sqrt n := + frobenius_by_rows D (norm_nonneg _) (fun i=>SKGap.SourceError.matrix_row_square_le D i) + +structure LiteralBudget (f : KernelExpr) (R T L B : ℝ) : Prop where + nonneg : 0≤B + two : 2≤B + root : Real.sqrt (Real.exp (R/2))≤B + square : Real.exp (R/2)≤B^2 + matrix : L≤B + primary : T≤B + source : ratioSmallBudget (.kernel f) T≤B + scalar : ratioSmallBudget ((RatioExpr.kernel f).d .z) T*kernelSmallBudget phiExpr R T≤B + phi_row : (phiExpr.dBudget R+phiExpr.ddBudget R)*T≤B + slope_row : ((RatioExpr.kernel phiExpr.dz).dBudget+(RatioExpr.kernel phiExpr.dz).ddBudget)*T≤B + +lemma literal_initial_control (J : Interaction n) (j : ℝ) (f : KernelExpr) + (z m w y : VectorFields n) (a c : Spin n→ℝ) (r e : Fin n→ℝ) (x : Spin n) + (hn : 0Real.sqrt n*c v) x‖≤uniformControlBudget j δ B := by + let A : VectorFields n:=fun v i=>phi (z v i) (r i) (a v) + let ell : VectorFields n:=fun v i=>logSlope (z v i) (r i) (a v) + have hnR : (0:ℝ)(Hf k).a_bound) hD + have ha' : CoefficientBound A x (Real.exp (R/2)) ((phiExpr.dBudget R+phiExpr.ddBudget R)*T) := by + convert! ha using 1 + · ext v i; exact (moment_base _ _ _).symm + · simp [phiExpr,KernelExpr.mass] + have hel:=initial_ratio_bound (.kernel phiExpr.dz) z a r x hT hD + have hel' : CoefficientBound ell x (RatioExpr.kernel phiExpr.dz).mass + (((RatioExpr.kernel phiExpr.dz).dBudget+(RatioExpr.kernel phiExpr.dz).ddBudget)*T) := by + convert! hel using 1 + ext v i; exact logSlope_ratio _ _ _ + have hu:=(initialU_small f z a r e x hT he hD).mono hB.source + have hp:=(initialP_small f z a r e x hT he H.a_bound (fun k=>(Hf k).a_bound) hD).mono hB.scalar + have hp':=scaledMean_norm hn _ x hp + have hX {v : Spin n} (HV : LiteralStableAt J j z m a r R ρ δ v) : ‖phiSqrt (z v) r (a v)‖≤B := by + apply (Real.le_sqrt (norm_nonneg _) (Real.exp_pos _).le).mpr (phiSqrt_bound _ _ _ HV.a_bound) |>.trans hB.root + have hχ {v : Spin n} (HV : LiteralStableAt J j z m a r R ρ δ v) : |siteMean A v|≤B^2 := by + apply (coefficient_mean_value A v (Real.exp_pos _).le (fun i=>?_) ).trans hB.square + rw [abs_of_pos (phi_pos _ _ _)] + exact (phi_le_exp ..).trans (Real.exp_le_exp.mpr (by linarith [HV.a_bound])) + have hell {v : Spin n} : ‖(WithLp.toLp 2 (ell v) : Euclid n)‖≤B*Real.sqrt n := + (vectorNorm_logSlope (z v) r (a v)).trans (mul_le_mul_of_nonneg_right hB.two hd.le) + have hDA (V : Euclid n) : columnNorm (fun k=>((spin x k/2) • + (phiSqrt (z x) r (a x)*phiSqrt (z x) r (a x)- + phiSqrt (z (flip x k)) r (a (flip x k))*phiSqrt (z (flip x k)) r (a (flip x k)))) V)≤B*‖V‖ := by + simp only [phiSqrt_square] + exact (diagonal_halfDiff_columns A x ha'.row_nonneg ha'.difference V).trans + (mul_le_mul_of_nonneg_right hB.phi_row (norm_nonneg _)) + have hDu : columnNorm (fun k=>(spin x k/2) • + ((WithLp.toLp 2 (initialU f z a r e x) : Euclid n)-WithLp.toLp 2 (initialU f z a r e (flip x k))))≤B := by + rw [columnNorm_halfDiff]; exact hu.derivative + have hDχ : columnNorm (fun k=>(spin x k/2)*(siteMean A x-siteMean A (flip x k)))≤B := by + rw [columnNorm_scalar_halfDiff] + exact (coefficient_mean_difference A x ha'.row_nonneg ha'.difference).trans hB.phi_row + have hDm' : columnNorm (fun k=>(spin x k/2) • + ((WithLp.toLp 2 (m x) : Euclid n)-WithLp.toLp 2 (m (flip x k))))≤B*Real.sqrt n := by + rw [columnNorm_halfDiff] + exact (frobenius_le_opNorm_sqrt _).trans (mul_le_mul_of_nonneg_right (hDm.trans hB.primary) hd.le) + have hDell : columnNorm (fun k=>(spin x k/2) • + ((WithLp.toLp 2 (ell x) : Euclid n)-WithLp.toLp 2 (ell (flip x k))))≤B*Real.sqrt n := by + rw [columnNorm_halfDiff] + exact (frobenius_by_rows _ hel'.row_nonneg hel'.difference).trans + (mul_le_mul_of_nonneg_right hB.slope_row hd.le) + have hDp : Real.sqrt n*columnNorm (fun k=>(spin x k/2)* + (siteMean (initialP f z a r e) x-siteMean (initialP f z a r e) (flip x k)))≤B := by + rw [columnNorm_scalar_halfDiff]; exact hp'.2 + have hEq : Equations j (siteMean A x) (n:ℝ)⁻¹ (siteMean (initialP f z a r e) x) + (phiSqrt (z x) r (a x)*phiSqrt (z x) r (a x)) (toEuclideanCLM (𝕜:=ℝ) J) + (WithLp.toLp 2 (initialU f z a r e x)) (WithLp.toLp 2 (m x)) + (WithLp.toLp 2 (fun i=>Real.tanh (r i))) (WithLp.toLp 2 (ell x)) + (WithLp.toLp 2 (w x)) (WithLp.toLp 2 (y x)) (c x) := by + rw [phiSqrt_square]; exact h + have hEqf k : Equations j (siteMean A (flip x k)) (n:ℝ)⁻¹ (siteMean (initialP f z a r e) (flip x k)) + (phiSqrt (z (flip x k)) r (a (flip x k))*phiSqrt (z (flip x k)) r (a (flip x k))) (toEuclideanCLM (𝕜:=ℝ) J) + (WithLp.toLp 2 (initialU f z a r e (flip x k))) (WithLp.toLp 2 (m (flip x k))) + (WithLp.toLp 2 (fun i=>Real.tanh (r i))) (WithLp.toLp 2 (ell (flip x k))) + (WithLp.toLp 2 (w (flip x k))) (WithLp.toLp 2 (y (flip x k))) (c (flip x k)) := by + rw [phiSqrt_square]; exact hf k + have ht:=implicit_uniform_control j (siteMean A x) ((∑i,scalarVariance (z x i))/(n:ℝ)) (n:ℝ)⁻¹ + (siteMean (initialP f z a r e) x) (phiSqrt (z x) r (a x)) (toEuclideanCLM (𝕜:=ℝ) J) + (WithLp.toLp 2 (initialU f z a r e x)) (WithLp.toLp 2 (m x)) + (WithLp.toLp 2 (fun i=>Real.tanh (r i))) (WithLp.toLp 2 (ell x)) + (WithLp.toLp 2 (fun i=>Real.tanh (z x i))) (WithLp.toLp 2 (w x)) (WithLp.toLp 2 (y x)) (c x) + (fun k=>spin x k/2) (fun k=>siteMean A (flip x k)) (fun k=>siteMean (initialP f z a r e) (flip x k)) + (fun k=>c (flip x k)) (fun k=>(∑i,scalarVariance (z (flip x k) i))/(n:ℝ)) + (fun k=>phiSqrt (z (flip x k)) r (a (flip x k))) + (fun k=>WithLp.toLp 2 (initialU f z a r e (flip x k))) (fun k=>WithLp.toLp 2 (m (flip x k))) + (fun k=>WithLp.toLp 2 (ell (flip x k))) (fun k=>WithLp.toLp 2 (w (flip x k))) + (fun k=>WithLp.toLp 2 (y (flip x k))) (fun k=>WithLp.toLp 2 (fun i=>Real.tanh (z (flip x k) i))) + hδ hd (inv_nonneg.mpr hnR.le) hscale hB.nonneg (hX H) (fun k=>hX (Hf k)) (hJ.trans hB.matrix) + (hχ H) (fun k=>hχ (Hf k)) hu.size H.m_size (fun k=>(Hf k).m_size) (vectorNorm_tanh r) + hell (fun _=>hell) hp'.1 H.stable (fun k=>(Hf k).stable) + (H.perturbation hn hδ hρ hsmall) (fun k=>(Hf k).perturbation hn hδ hρ hsmall) + hEq hEqf hDA hDu hDχ hDm' hDell hDp + rw [columnNorm_halfDiff,columnNorm_halfDiff,columnNorm_scalar_halfDiff] at ht + exact implicit_tuple_small w y c x hd.le (uniformControlBudget_nonneg hδ hB.nonneg) ht +end SKGapCutoff.Recipe + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Stability/LiteralStableEvent.lean b/lean/OAI/Probability/SKGap/Stability/LiteralStableEvent.lean new file mode 100644 index 0000000000000000000000000000000000000000..e2137d13c1fb43a6134137a1e110b9da771ccabb --- /dev/null +++ b/lean/OAI/Probability/SKGap/Stability/LiteralStableEvent.lean @@ -0,0 +1,181 @@ +import Mathlib +import OAI.Probability.SKGap.Stability.StableRootInverse +import OAI.Probability.SKGap.Entropy.WeightedMean +import OAI.Probability.SKGap.Localization.PhiHessianBridge +import OAI.Probability.SKGap.Stability.LiteralStableControl + +namespace OAI + +section + +noncomputable section +open scoped BigOperators Matrix +namespace SKGapCutoff.Recipe +open SKGap SKGap.Stein Primary SKGap.ImplicitSystem Matrix SKGap.ObservationBridge +variable {n : ℕ} + +lemma phi_hessian_stable (hn : 0Real.tanh (z i))) v) := by + obtain ⟨hb,hvar,hrest⟩:=implicit_coefficient_bounds z r a hn hρ ha haρ hz + have hdiag : (∑i,(phi (z i) (r i) a-SKGap.spinVariance z i)^2)≤ε^2*(n:ℝ) := by + have hv : vectorNorm (fun i=>phi (z i) (r i) a-SKGap.spinVariance z i)≤ε*Real.sqrt (n:ℝ) := by + apply (show vectorNorm (fun i=>phi (z i) (r i) a-SKGap.spinVariance z i)≤ + (3*Real.exp (R/2)+2)*ρ*Real.sqrt (n:ℝ) by + change SKGapCutoff.Recipe.vectorNorm ((fun i=>phi (z i) (r i) a)-(fun i=>scalarVariance (z i))) ≤ _ at hvar + exact hvar).trans + exact mul_le_mul_of_nonneg_right hsmall (Real.sqrt_nonneg _) + have hs:=pow_le_pow_left₀ (vectorNorm_nonneg _) hv 2 + simpa only [vectorNorm_sq,mul_pow,Real.sq_sqrt (Nat.cast_nonneg n)] using hs + have H:=stable_hessian_coercive hbad htap + (fun i=>⟨(hb i).1.le,(hb i).2.trans hAR⟩) hdiag + intro v + rw [literal_stableMatrix_quadratic hn] + have hvnorm : SKGap.vectorSqNorm v.ofLp=‖v‖^2 := by + simpa only [SKGap.vectorNorm,WithLp.toLp_ofLp] using (SKGap.vectorNorm_sq v.ofLp).symm + simpa only [hvnorm] using H v.ofLp + +lemma literalStableAt_of_stableField (hn : 0Real.tanh (r i)))≤ρ*Real.sqrt (n:ℝ)) + (hmb : ∀i,|m x i|≤1) : + LiteralStableAt J j z m a r R ρ c x := + ⟨ha,haρ,hz,hm,hmb,phi_hessian_stable hn hρ hε hAR hsmall J h (z x) r (a x) + hbad htap ha haρ hz⟩ + +end SKGapCutoff.Recipe + +end +end + +section + +noncomputable section +open scoped BigOperators Matrix +namespace SKGapCutoff.Recipe +open SKGap Primary Static SKGap.ObservationBridge SKGap.Stein +variable {n : ℕ} + +lemma square_average_difference (hn : 0j*(1-onsager j J h (k+1) v-SKGap.overlap r)) r R + ((1+2*j)*(1+(1+(K+3*j)/c)*(K+4*j))*ρ) c x := by + let C:=(1+(K+3*j)/c)*(K+4*j) + let D:=(1+2*j)*(1+C) + have hC : 0≤C:=by dsimp [C];positivity + have hD : 0≤D:=by dsimp [D];positivity + have hCD : C≤D:=by dsimp [D];nlinarith + have h1CD : 1+C≤D:=by dsimp [D];nlinarith + have h2CD : 2*j*(1+C)≤D:=by dsimp [D];nlinarith + have hs : 0y) x) + (hwf : ∀i,w (flip x i)=D.sourceOf 1 (fun _=>y) (flip x i)) : + derivativeMatrix w x=Matrix.diagonal (D.implicitCoefficient x)*derivativeMatrix y x+ + Matrix.diagonal (D.implicitPartial y x)*t.fieldMatrix D.j D.J+D.implicitSourcePrimitive t y x := by + rw [derivativeMatrix_congr_on_flips w _ x hw hwf,D.sourceOf_derivative] + simp only [Fintype.sum_unique,implicitCoefficient,implicitPartial,implicitSourcePrimitive,mul_sub] + have hd : (default : Fin 1)=0 := Subsingleton.elim _ _ + rw [hd] + abel + +lemma implicit_field_derivative_local (t : SourceTree (Fin n→ℝ)) (w y : VectorFields n) (x : Spin n) + (hw : w x=D.sourceOf 1 (fun _=>y) x) + (hwf : ∀i,w (flip x i)=D.sourceOf 1 (fun _=>y) (flip x i)) + (hy : y x=D.fieldOf 1 (fun _=>w) (fun _=>y) x) + (hyf : ∀i,y (flip x i)=D.fieldOf 1 (fun _=>w) (fun _=>y) (flip x i)) : + derivativeMatrix y x=(D.J-(D.j*siteMean D.implicitCoefficient x) • 1)*derivativeMatrix w x- + (D.j*siteMean (D.implicitPartial y) x) • t.sourceMatrix D.j D.J+D.implicitFieldPrimitive t w y x := by + have H:=derivativeMatrix_congr_on_flips y _ x hy hyf + have HW:=derivativeMatrix_congr_on_flips w _ x hw hwf + rw [D.fieldOf_derivative,←HW] at H + simp only [Fintype.sum_unique] at H + rw [H] + simp only [implicitCoefficient,implicitPartial,implicitFieldPrimitive,neg_smul,smul_sub, + sub_mul,smul_mul_assoc,one_mul] + abel +theorem implicit_error_solved_local (t : SourceTree (Fin n→ℝ)) (w y : VectorFields n) + (x : Spin n) + (hw : w x=D.sourceOf 1 (fun _=>y) x) + (hwf : ∀i,w (flip x i)=D.sourceOf 1 (fun _=>y) (flip x i)) + (hy : y x=D.fieldOf 1 (fun _=>w) (fun _=>y) x) + (hyf : ∀i,y (flip x i)=D.fieldOf 1 (fun _=>w) (fun _=>y) (flip x i)) + (hK : WordLetter.inverse.exactEval D.j (D.implicitCoefficient x) D.J* + (1-Matrix.diagonal (D.implicitCoefficient x)*(D.J-(D.j*siteMean D.implicitCoefficient x) • 1))=1) : + derivativeMatrix w x-D.implicitRetainedSource t y x= + WordLetter.inverse.exactEval D.j (D.implicitCoefficient x) D.J* + (D.implicitSourcePrimitive t y x+Matrix.diagonal (D.implicitCoefficient x)*D.implicitFieldPrimitive t w y x) ∧ + derivativeMatrix y x-D.implicitRetainedField t y x= + (D.J-(D.j*siteMean D.implicitCoefficient x) • 1)* + (derivativeMatrix w x-D.implicitRetainedSource t y x)+D.implicitFieldPrimitive t w y x := by + have hsource:=D.implicit_source_derivative_local t w y x hw hwf + have hfield:=D.implicit_field_derivative_local t w y x hw hwf hy hyf + have hs : derivativeMatrix w x=Matrix.diagonal (D.implicitCoefficient x)*derivativeMatrix y x+ + (Matrix.diagonal (D.implicitPartial y x)*t.fieldMatrix D.j D.J+D.implicitSourcePrimitive t y x) := by rw [hsource];abel + have hf : derivativeMatrix y x=(D.J-(D.j*siteMean D.implicitCoefficient x) • 1)*derivativeMatrix w x+ + (-(D.j*siteMean (D.implicitPartial y) x) • t.sourceMatrix D.j D.J+D.implicitFieldPrimitive t w y x) := by + rw [hfield];simp only [neg_smul];abel + have H:=implicit_error_elimination _ _ _ _ _ _ _ _ hK hs hf + constructor + · rw [H,implicitRetainedSource,GradedWords.matrixValue_implicitSource,mean_implicit] + simp only [mul_add,mul_sub,neg_smul,mul_neg,mul_smul_comm] + abel + · rw [hfield,implicitRetainedField,GradedWords.matrixValue_implicitField,mean_implicit,mean_implicit] + change _-((D.J-(D.j*siteMean D.implicitCoefficient x) • 1)*D.implicitRetainedSource t y x- + (D.j*siteMean (D.implicitPartial y) x) • t.sourceMatrix D.j D.J)=_ + rw [mul_sub] + abel + +end SKGapCutoff.Recipe.OrdinaryData + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Stability/LocalStartedImplicit.lean b/lean/OAI/Probability/SKGap/Stability/LocalStartedImplicit.lean new file mode 100644 index 0000000000000000000000000000000000000000..0dc9c01c654957aaecdb37b091c033be198e5295 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Stability/LocalStartedImplicit.lean @@ -0,0 +1,82 @@ +import Mathlib +import OAI.Probability.SKGap.Matrix.ClosedErrorTrace +import OAI.Probability.SKGap.Localization.StartedGraph +import OAI.Probability.SKGap.Stability.LocalImplicitNode +import OAI.Probability.SKGap.Stability.ImplicitTraceControl +import OAI.Probability.SKGap.Matrix.StartedNodeTrace + +namespace OAI + +section + +noncomputable section +open scoped BigOperators +namespace SKGapCutoff.Recipe.OrdinaryData +open Primary Matrix SKGap SKGap.Noncrossing SKGap.Noncrossing.Primary SKGap.Noncrossing.Primary.Tensor.Series +variable {n : ℕ} {ι κ σ κ₀ σ₀ : Type*} [Fintype ι] [DecidableEq ι] [Fintype κ] [DecidableEq κ] [Fintype σ] +variable [Fintype κ₀] [DecidableEq κ₀] [Fintype σ₀] +variable (D : OrdinaryData n ι κ σ) (I : OrdinaryData n Unit κ₀ σ₀) +variable (w y : VectorFields n) (T : ι→SourceTree (Fin n→ℝ)) (t : SourceTree (Fin n→ℝ)) + +lemma started_implicit_initial_errors_local (hj : D.j=I.j) (hJ : D.J=I.J) + (x : Spin n) + (hW : w x=I.sourceOf 1 (fun _=>y) x) + (hWf : ∀i,w (flip x i)=I.sourceOf 1 (fun _=>y) (flip x i)) + (hY : y x=I.fieldOf 1 (fun _=>w) (fun _=>y) x) + (hYf : ∀i,y (flip x i)=I.fieldOf 1 (fun _=>w) (fun _=>y) (flip x i)) + (ha : ∀i,0≤I.implicitCoefficient x i) + (hS : (1-SKGap.pathDiagonal (I.implicitCoefficient x) 1* + (I.J-(I.j*siteMean I.implicitCoefficient x) • 1)*SKGap.pathDiagonal (I.implicitCoefficient x) 1).PosDef) : + let t₀:=ClosedTree.implicit (I.implicitPartial y x) t + let a₀:=I.implicitCoefficient x + D.startedSourceError w y T t₀ a₀ x 0= + WordLetter.inverse.exactEval D.j a₀ D.J* + (I.implicitSourcePrimitive t y x+Matrix.diagonal a₀*I.implicitFieldPrimitive t w y x) ∧ + D.startedFieldError w y T t₀ a₀ x 0= + (D.J-(I.j*siteMean I.implicitCoefficient x) • 1)*D.startedSourceError w y T t₀ a₀ x 0+ + I.implicitFieldPrimitive t w y x := by + have H:=I.implicit_error_solved_local t w y x hW hWf hY hYf (I.implicit_inverse_left x ha hS) + dsimp only + simp only [startedSourceError_zero,startedFieldError_zero,hj,hJ,ClosedTree.sourceMatrix, + ClosedTree.fieldMatrix,ClosedTree.words] + exact H + +theorem implicit_started_error_words_local (hj : D.j=I.j) (hJ : D.J=I.J) + (x : Spin n) + (hW : w x=I.sourceOf 1 (fun _=>y) x) + (hWf : ∀i,w (flip x i)=I.sourceOf 1 (fun _=>y) (flip x i)) + (hY : y x=I.fieldOf 1 (fun _=>w) (fun _=>y) x) + (hYf : ∀i,y (flip x i)=I.fieldOf 1 (fun _=>w) (fun _=>y) (flip x i)) + (ha0 : ∀i,0≤I.implicitCoefficient x i) + (hS : (1-SKGap.pathDiagonal (I.implicitCoefficient x) 1* + (I.J-(I.j*siteMean I.implicitCoefficient x) • 1)*SKGap.pathDiagonal (I.implicitCoefficient x) 1).PosDef) + {C F A R M : ℝ} {Cs Cf : ℕ→ℝ} {N L : ℕ} + (hP : TraceControl (I.implicitSourcePrimitive t y x) C) + (hQ : TraceControl (I.implicitFieldPrimitive t w y x) F) + (hR : 0≤R) (hM : 0≤M) (ha : ∀i,|I.implicitCoefficient x i|≤A) + (hp : ∀a≤N,∀b i,|D.auxCoefficient a b x i|≤A) + (hr : ∀a≤N,∀b,|D.j*siteMean (D.auxCoefficient a b) x|≤R) + (hs : ∀a≤N,0if a=0 then C+F else Cs a + let Bf:=fun a=>if a=0 then |q| *(C+F)+F else Cf a + ∀a≤N, + (∀v:OrdinaryWord n,v.length+2*a+1≤L→wordBounded A v→ + |trace (matrixWord D.J v*D.startedSourceError w y T t₀ a₀ x a)|≤(errorBudget R Bs Bf a).1*M) ∧ + (∀v:OrdinaryWord n,v.length+2*a+2≤L→wordBounded A v→ + |trace (matrixWord D.J v*D.startedFieldError w y T t₀ a₀ x a)|≤(errorBudget R Bs Bf a).2*M) := by + obtain ⟨HE,HF⟩:=D.started_implicit_initial_errors_local I w y T t hj hJ x hW hWf hY hYf ha0 hS + exact D.started_derivative_error_words w y T _ _ x + (I.implicitSourcePrimitive t y x) (I.implicitFieldPrimitive t w y x) + (I.j*siteMean I.implicitCoefficient x) HE HF hP hQ hR hM ha hp hr hs hf hw + +end SKGapCutoff.Recipe.OrdinaryData + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Stability/LogDetMean.lean b/lean/OAI/Probability/SKGap/Stability/LogDetMean.lean new file mode 100644 index 0000000000000000000000000000000000000000..914d8b853686461778014a8bacc3fd75da116804 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Stability/LogDetMean.lean @@ -0,0 +1,94 @@ +import Mathlib +import OAI.Probability.SKGap.Brownian.LogDetPath + +namespace OAI + +section +noncomputable section +namespace SKGap +open Matrix MeasureTheory ProbabilityTheory Real Set +open RealComplex +open scoped BigOperators Matrix.Norms.Frobenius SchwartzMap +variable {ι : Type*} [Fintype ι] [DecidableEq ι] + +lemma trace_mul_diagonal_right (M : Matrix ι ι ℝ) (a : ι → ℝ) : + (M*diagonal a).trace=∑ i,M i i*a i := by + simp only [Matrix.trace,Matrix.diag,Matrix.mul_diagonal] + +lemma integral_trace_diagonal {Ω : Type*} [MeasurableSpace Ω] {μ : Measure Ω} + (F : Ω → Matrix ι ι ℝ) (a : ι → ℝ) (hF : ∀ i, Integrable (fun g => F g i i) μ) : + (∫ g, (F g*diagonal a).trace ∂μ)=∑ i,(∫ g, F g i i ∂μ)*a i := by + simp_rw [trace_mul_diagonal_right] + rw [integral_finsetSum Finset.univ (fun i _ => (hF i).mul_const (a i))] + simp only [integral_mul_const] + +omit [DecidableEq ι] in +lemma weighted_average_bias [Nonempty ι] {a t : ι → ℝ} {c δ : ℝ} + (hδ : 0 ≤ δ) (ha : ∀ i, 0 ≤ a i) (ha1 : ∀ i, a i ≤ 1) (ht : ∀ i, |t i-c| ≤ δ) : + |(∑ i,t i*a i)/(Fintype.card ι:ℝ)-c*((∑ i,a i)/(Fintype.card ι:ℝ))| ≤ δ := by + have hn : (0:ℝ) < Fintype.card ι := Nat.cast_pos.mpr Fintype.card_pos + have he : (∑ i,t i*a i)/(Fintype.card ι:ℝ)-c*((∑ i,a i)/(Fintype.card ι:ℝ))= + (∑ i,(t i-c)*a i)/(Fintype.card ι:ℝ) := by + simp_rw [sub_mul,Finset.sum_sub_distrib,← Finset.mul_sum] + ring + rw [he,abs_div,abs_of_pos hn] + apply (div_le_iff₀ hn).mpr + apply (Finset.abs_sum_le_sum_abs _ _).trans + have hh := Finset.sum_le_sum (s := Finset.univ) (fun i _ => + show |(t i-c)*a i| ≤ δ from by rw [abs_mul,abs_of_nonneg (ha i)]; exact (mul_le_mul (ht i) (ha1 i) (ha i) hδ).trans_eq (mul_one δ)) + simpa only [Finset.sum_const,Finset.card_univ,nsmul_eq_mul,mul_comm] using hh + +lemma logPathCutoffDerivative_mean_error [Nonempty ι] (f : 𝓢(ℝ,ℂ)) {R j C : ℝ} + (hR : 0 ≤ R) (hj : 0 ≤ j) (hC : 0 ≤ C) {a : ι → ℝ} + (ha : ∀ i, 0 ≤ a i) (ha1 : ∀ i, a i ≤ 1) {z : ℝ} (hz : z ∈ Icc (0:ℝ) 1) + (hK : ∀ i, |pathExpected f R hR j a z i-1| ≤ C/(Fintype.card ι:ℝ)) + (hWK : ∀ i, |(∫ g, (realProject R hR (goeMatrix (j/(Fintype.card ι:ℝ)) g)* + pathK f R hR j a z (goeMatrix (j/(Fintype.card ι:ℝ)) g)) i i + ∂Measure.pi (fun _ : MatrixCoordinates ι => gaussianReal 0 1))-z*((j/(Fintype.card ι:ℝ))*∑ b,a b)| ≤ C/(Fintype.card ι:ℝ)) : + |(∫ g, logPathCutoffDerivative f R hR j a (goeMatrix (j/(Fintype.card ι:ℝ)) g) z + ∂Measure.pi (fun _ : MatrixCoordinates ι => gaussianReal 0 1))- + z*j*((∑ i,a i)/(Fintype.card ι:ℝ))^2| ≤ (2*j+1)*C/(Fintype.card ι:ℝ) := by + let μ := Measure.pi (fun _ : MatrixCoordinates ι => gaussianReal 0 1) + let KG := fun g : MatrixCoordinates ι → ℝ => pathK f R hR j a z (goeMatrix (j/(Fintype.card ι:ℝ)) g) + let WG := fun g : MatrixCoordinates ι → ℝ => realProject R hR (goeMatrix (j/(Fintype.card ι:ℝ)) g)*KG g + have hn : (0:ℝ) < Fintype.card ι := Nat.cast_pos.mpr Fintype.card_pos + have hB := (path_constants_nonneg f hR hj (by norm_num : (0:ℝ)≤1)).1 + have hbnd := (pathK_bounds f hR hj (by norm_num : (0:ℝ)≤1) ha ha1 hz).1 + have hcontK : Continuous KG := (pathK_continuous f hR hj (by norm_num : (0:ℝ)≤1) ha ha1 hz).comp (goeMatrix_pi_lipschitz _).continuous + have hcontW : Continuous WG := ((realProject_lipschitz hR).continuous.comp (goeMatrix_pi_lipschitz _).continuous).mul hcontK + have hiK (i : ι) : Integrable (fun g => KG g i i) μ := + Integrable.mono' (integrable_const (pathBound f R j 1)) (hcontK.matrix_elem i i).aestronglyMeasurable + (ae_of_all _ (fun g => by simpa only [Real.norm_eq_abs] using (matrix_entry_le_opNorm _ i i).trans (hbnd _))) + have hiW (i : ι) : Integrable (fun g => WG g i i) μ := + Integrable.mono' (integrable_const (R*pathBound f R j 1)) (hcontW.matrix_elem i i).aestronglyMeasurable + (ae_of_all _ (fun g => by simpa only [Real.norm_eq_abs] using (matrix_entry_le_opNorm _ i i).trans (realProjectedProduct_opNorm hR _ hbnd _))) + have htK : Integrable (fun g => (KG g*diagonal a).trace) μ := by + simp_rw [trace_mul_diagonal_right] + exact integrable_finsetSum _ (fun i _ => (hiK i).mul_const (a i)) + have htW : Integrable (fun g => (WG g*diagonal a).trace) μ := by + simp_rw [trace_mul_diagonal_right] + exact integrable_finsetSum _ (fun i _ => (hiW i).mul_const (a i)) + have heK := weighted_average_bias (div_nonneg hC hn.le) ha ha1 (t := fun i => ∫ g, KG g i i ∂μ) hK + have heW := weighted_average_bias (div_nonneg hC hn.le) ha ha1 (t := fun i => ∫ g, WG g i i ∂μ) hWK + rw [← integral_trace_diagonal KG a hiK] at heK + rw [← integral_trace_diagonal WG a hiW] at heW + have hq := diagonal_mean_bounds hj ha ha1 + simp only [mul_one] at hq + have hcoef : |2*z*((j/(Fintype.card ι:ℝ))*∑ i,a i)| ≤ 2*j := by + rw [abs_of_nonneg (mul_nonneg (mul_nonneg (by norm_num) hz.1) hq.1)] + nlinarith [mul_le_mul hz.2 hq.2 hq.1 (by norm_num : (0:ℝ)≤1)] + change |(∫ g, (2*z*((j/(Fintype.card ι:ℝ))*∑ i,a i)*(KG g*diagonal a).trace-(WG g*diagonal a).trace)/(Fintype.card ι:ℝ) ∂μ)-_| ≤ _ + rw [integral_div,integral_sub (htK.const_mul _) htW,integral_const_mul] + have he : (2*z*((j/(Fintype.card ι:ℝ))*∑ i,a i)*(∫ g, (KG g*diagonal a).trace ∂μ)-(∫ g, (WG g*diagonal a).trace ∂μ))/(Fintype.card ι:ℝ)-z*j*((∑ i,a i)/(Fintype.card ι:ℝ))^2= + (2*z*((j/(Fintype.card ι:ℝ))*∑ i,a i))*((∫ g, (KG g*diagonal a).trace ∂μ)/(Fintype.card ι:ℝ)-1*((∑ i,a i)/(Fintype.card ι:ℝ)))- + ((∫ g, (WG g*diagonal a).trace ∂μ)/(Fintype.card ι:ℝ)-z*((j/(Fintype.card ι:ℝ))*∑ i,a i)*((∑ i,a i)/(Fintype.card ι:ℝ))) := by ring + rw [he] + apply (abs_sub _ _).trans + have hm := mul_le_mul hcoef heK (abs_nonneg _) (by positivity : 0 ≤ 2*j) + rw [← abs_mul] at hm + exact (add_le_add hm heW).trans_eq (by ring) +end SKGap +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Stability/LogDetUniformMean.lean b/lean/OAI/Probability/SKGap/Stability/LogDetUniformMean.lean new file mode 100644 index 0000000000000000000000000000000000000000..59d309999af53ae4048795a300424365be819223 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Stability/LogDetUniformMean.lean @@ -0,0 +1,47 @@ +import Mathlib +import OAI.Probability.SKGap.Matrix.LogDetExpected + +namespace OAI + +section +noncomputable section +namespace SKGap +open Matrix MeasureTheory ProbabilityTheory Real Set Filter +open RealComplex +open scoped BigOperators Matrix.Norms.Frobenius SchwartzMap Topology + +theorem actual_logdet_mean {j : ℝ} (hj : 0 < j) (hj1 : j < 1) : + ∃ B : ℝ, 0 ≤ B ∧ ∀ γ : ℝ, 0 < γ → ∃ C : ℝ, 0 ≤ C ∧ ∃ N : ℕ, 0 < N ∧ + ∀ n : ℕ, N ≤ n → ∀ a : Fin n → ℝ, (∀ i, 0 ≤ a i) → (∀ i, a i ≤ 1) → + (∫ g, LogDet.regularizedLogDet γ (logPath ((j/(n:ℝ))*∑ i,a i) a + (goeMatrix (j/(n:ℝ)) g) 1) + ∂Measure.pi (fun _ : MatrixCoordinates (Fin n) => gaussianReal 0 1)) ≤ + j*((∑ i,a i)/(n:ℝ))^2+γ*B^2+C/(n:ℝ) := by + have hs : sqrt j*1 < 1 := by nlinarith [sq_sqrt hj.le,sqrt_nonneg j] + obtain ⟨f,R,hR,lo,hi,C,N,hReq,hloeq,hhieq,hlo,hf,_hfr,hC,hN,hbias⟩ := + actual_projected_path_equivalents hj (by norm_num : (0:ℝ)<1) hs + have hB := (path_constants_nonneg f hR hj.le (by norm_num : (0:ℝ)≤1)).1 + refine ⟨pathBound f R j 1,hB,?_⟩ + intro γ hγ + have hr := pathRate_pos hj (by norm_num : (0:ℝ)<1) hs + refine ⟨logdetMeanError j R (pathBound f R j 1) C (pathRate j 1) γ, + logdetMeanError_nonneg hj.le hR hB hC.le hr hγ,?_⟩ + obtain ⟨N₁,hN₁⟩ := eventually_atTop.mp (path_size_eventually hs) + refine ⟨max N N₁,lt_of_lt_of_le hN (le_max_left _ _),?_⟩ + intro n hn a ha ha1 + have hnN := (le_max_left N N₁).trans hn + have hn0 := hN.trans_le hnN + let : Nonempty (Fin n) := Fin.pos_iff_nonempty.mp hn0 + have hb (z) (hz : z ∈ Icc (0:ℝ) 1) := hbias n hnN a ha ha1 z hz + have hp := logPathGood_exponential hj (by norm_num : (0:ℝ)<1) ha ha1 hs + (by simpa only [Fintype.card_fin] using hN₁ n ((le_max_right N N₁).trans hn)) + rw [← hReq,← hloeq,← hhieq] at hp + simpa only [Fintype.card_fin] using + logPath_regularized_expected f hR hlo hf hj.le hC.le hγ hr ha ha1 + (fun z hz i => by simpa only [Fintype.card_fin] using (hb z hz i).1) + (fun z hz i => by simpa only [Fintype.card_fin] using (hb z hz i).2) hp +end SKGap +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Stability/Ordinary.lean b/lean/OAI/Probability/SKGap/Stability/Ordinary.lean new file mode 100644 index 0000000000000000000000000000000000000000..9066043903c5135a31a88670bd87f34b1be81758 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Stability/Ordinary.lean @@ -0,0 +1,191 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.Map +import OAI.Probability.SKGap.Terminal.Map + +namespace OAI + +section +noncomputable section +noncomputable section +open scoped BigOperators +noncomputable section +noncomputable section +noncomputable section +open scoped BigOperators +noncomputable section +open scoped BigOperators +noncomputable section +open scoped BigOperators +noncomputable section +open scoped BigOperators +noncomputable section +open scoped BigOperators +noncomputable section +open scoped BigOperators +namespace SKGap.Noncrossing +open Diagram InverseDiagram +namespace WordSeries +variable {ι : Type*} [Fintype ι] + +def ordinary (j : ℝ) (F : List (Letter (ι→ℝ))) : ι→ℝ := expect j id F +def chain (j : ℝ) (a : ι→ℝ) (bs : List Bool) : List (Letter (ι→ℝ)) := + (expandBlocks bs).map (Letter.map (blockLabel j a)) +def inverseCoefficient (j : ℝ) (a : ι→ℝ) (P Q : List (Letter (ι→ℝ))) (n : ℕ) (i : ι) : ℝ := + ∑ bs : Blocks n, ordinary j (P++chain j a bs.val++Q) i + +@[simp] lemma chain_nil (j : ℝ) (a : ι→ℝ) : chain j a []=[] := rfl +@[simp] lemma chain_append (j : ℝ) (a : ι→ℝ) (p q : List Bool) : + chain j a (p++q)=chain j a p++chain j a q := by simp [chain] +@[simp] lemma chain_true (j : ℝ) (a : ι→ℝ) (p : List Bool) : + chain j a (true::p)=.diag a::.noise::chain j a p := rfl +@[simp] lemma chain_false (j : ℝ) (a : ι→ℝ) (p : List Bool) : + chain j a (false::p)=.diag (fun i => -(j*mean a)*a i)::chain j a p := rfl + +lemma blocks_zero (bs : Blocks 0) : bs.val=[] := by + have h := (mem_blockEnumerate bs.val 0).mpr bs.property + simpa [blockEnumerate] using h +instance blocksZeroUnique : Unique (Blocks 0) where + default := ⟨[],rfl⟩ + uniq bs := Subtype.ext (blocks_zero bs) + +@[simp] lemma inverseCoefficient_zero (j : ℝ) (a : ι→ℝ) + (P Q : List (Letter (ι→ℝ))) (i : ι) : + inverseCoefficient j a P Q 0 i=ordinary j (P++Q) i := by + simp [inverseCoefficient,blocks_zero] + +lemma inverseCoefficient_empty (j : ℝ) (a : ι→ℝ) (n : ℕ) (i : ι) : + inverseCoefficient j a [] [] n i=if n=0 then 1 else 0 := by + have he : inverseCoefficient j a [] [] n i=literalCoefficient j a n i := by + simp only [inverseCoefficient,List.nil_append,List.append_nil,ordinary,chain,expect_map, + Function.id_comp] + symm + change (∑ z : Σ bs : Blocks n, Paired (expandBlocks bs.val), _) = _ + rw [Fintype.sum_sigma] + rfl + rw [he,literalCoefficient_eq] + +lemma mean_inverseCoefficient (j : ℝ) (a : ι→ℝ) + (P Q : List (Letter (ι→ℝ))) (n : ℕ) : + mean (inverseCoefficient j a P Q n) = + ∑ bs : Blocks n, mean (ordinary j (P++chain j a bs.val++Q)) := by + simp only [mean,inverseCoefficient] + rw [Finset.sum_comm,Finset.sum_div] + +lemma sum_marked_chain {M : Type*} [AddCommMonoid M] (j : ℝ) (a : ι→ℝ) (n : ℕ) + (f : List (Letter (ι→ℝ))→List (Letter (ι→ℝ))→M) : + (∑ bs : Blocks (n+1), ∑ s : NoiseSplit (chain j a bs.val), f s.before s.after) = + ∑ k : Fin (n+1), ∑ p : Blocks k.val, ∑ q : Blocks (n-k.val), + f (chain j a p.val++[.diag a]) (chain j a q.val) := by + calc + _ = ∑ bs : Blocks (n+1), ∑ s : NoiseSplit (expandBlocks bs.val), + f (s.before.map (Letter.map (blockLabel j a))) + (s.after.map (Letter.map (blockLabel j a))) := by + apply Finset.sum_congr rfl + intro bs _ + symm + apply Fintype.sum_equiv (NoiseSplit.mapEquiv (blockLabel j a) (expandBlocks bs.val)) + intro s; rfl + _ = _ := by + simpa only [List.map_append,List.map_cons,List.map_nil,Letter.map,blockLabel,chain] using + sum_marked_blocks n (fun P Q => f (P.map (Letter.map (blockLabel j a))) + (Q.map (Letter.map (blockLabel j a)))) + +lemma inverse_partner_right (j : ℝ) (a : ι→ℝ) (P R T : List (Letter (ι→ℝ))) + (n : ℕ) (i : ι) : + (∑ bs : Blocks (n+1), ∑ s : NoiseSplit (chain j a bs.val), + j*mean (ordinary j (R++s.before))*ordinary j (P++s.after++T) i) = + ∑ k : Fin (n+1), j*mean (inverseCoefficient j a R [.diag a] k.val)* + inverseCoefficient j a P T (n-k.val) i := by + rw [sum_marked_chain j a n (fun P' Q' => + j*mean (ordinary j (R++P'))*ordinary j (P++Q'++T) i)] + apply Finset.sum_congr rfl + intro k _ + simp only [List.append_assoc] + simp_rw [← Finset.mul_sum] + rw [← Finset.sum_mul,← Finset.mul_sum,mean_inverseCoefficient] + simp only [inverseCoefficient,List.append_assoc] + +end WordSeries +end SKGap.Noncrossing + +noncomputable section +open scoped BigOperators +namespace SKGap.Noncrossing +namespace WordSeries +open Diagram InverseDiagram +variable {ι : Type*} [Fintype ι] + +lemma ordinary_cut_right (j : ℝ) (P R K T : List (Letter (ι→ℝ))) (i : ι) : + ordinary j ((P++(.noise::R))++K++T) i = + (∑ s : NoiseSplit P, j*mean (ordinary j s.after)*ordinary j (s.before++R++K++T) i) + + (∑ s : NoiseSplit R, j*mean (ordinary j s.before)*ordinary j (P++s.after++K++T) i) + + (∑ s : NoiseSplit K, j*mean (ordinary j (R++s.before))*ordinary j (P++s.after++T) i) + + (∑ s : NoiseSplit T, j*mean (ordinary j (R++K++s.before))*ordinary j (P++s.after) i) := by + have hh := expect_at j (id : (ι→ℝ)→ι→ℝ) P (R++(K++T)) i + rw [NoiseSplit.sum_append R (K++T) (fun U V => + j*mean (expect j id U)*expect j id (P++V) i)] at hh + rw [NoiseSplit.sum_append K T (fun U V => + j*mean (expect j id (R++U))*expect j id (P++V) i)] at hh + simpa only [ordinary,List.append_assoc,List.cons_append,add_assoc] using hh + +theorem inverseCoefficient_right (j : ℝ) (a : ι→ℝ) + (P R T : List (Letter (ι→ℝ))) (n : ℕ) (i : ι) : + inverseCoefficient j a (P++(.noise::R)) T (n+1) i = + (∑ s : NoiseSplit P, j*mean (ordinary j s.after)* + inverseCoefficient j a (s.before++R) T (n+1) i) + + (∑ s : NoiseSplit R, j*mean (ordinary j s.before)* + inverseCoefficient j a (P++s.after) T (n+1) i) + + (∑ k : Fin (n+1), j*mean (inverseCoefficient j a R [.diag a] k.val)* + inverseCoefficient j a P T (n-k.val) i) + + (∑ s : NoiseSplit T, j*mean (inverseCoefficient j a R s.before (n+1))* + ordinary j (P++s.after) i) := by + have hh : inverseCoefficient j a (P++(.noise::R)) T (n+1) i = + (∑ bs : Blocks (n+1), ∑ s : NoiseSplit P, j*mean (ordinary j s.after)* + ordinary j (s.before++R++chain j a bs.val++T) i) + + (∑ bs : Blocks (n+1), ∑ s : NoiseSplit R, j*mean (ordinary j s.before)* + ordinary j (P++s.after++chain j a bs.val++T) i) + + (∑ bs : Blocks (n+1), ∑ s : NoiseSplit (chain j a bs.val), + j*mean (ordinary j (R++s.before))*ordinary j (P++s.after++T) i) + + (∑ bs : Blocks (n+1), ∑ s : NoiseSplit T, j*mean (ordinary j (R++chain j a bs.val++s.before))* + ordinary j (P++s.after) i) := by + unfold inverseCoefficient + simp_rw [ordinary_cut_right,Finset.sum_add_distrib] + rw [hh,inverse_partner_right] + congr 2 + · congr 1 + · rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro s _ + rw [← Finset.mul_sum] + rfl + · rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro s _ + rw [← Finset.mul_sum] + rfl + · rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro s _ + rw [← Finset.sum_mul,← Finset.mul_sum,← mean_inverseCoefficient] + +end WordSeries +end SKGap.Noncrossing + +noncomputable section +open scoped BigOperators + +end +end +end +end +end +end +end +end +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Stability/OrdinaryClosure.lean b/lean/OAI/Probability/SKGap/Stability/OrdinaryClosure.lean new file mode 100644 index 0000000000000000000000000000000000000000..3d75b5016971e7449767a2cc7208f4f739a9ec26 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Stability/OrdinaryClosure.lean @@ -0,0 +1,215 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.RecipeError +import OAI.Probability.SKGap.Matrix.PrimitiveTrace +import OAI.Probability.SKGap.Localization.RecipeIncrement +import OAI.Probability.SKGap.Localization.RecipeBound +import OAI.Probability.SKGap.Matrix.RecipeTraceBudget +import OAI.Probability.SKGap.Matrix.RecipeNodeTrace + +namespace OAI + +section + +noncomputable section +open scoped BigOperators Matrix.Norms.Frobenius +namespace SKGapCutoff.Recipe +open Primary Matrix SKGap.Noncrossing SKGap.Noncrossing.Primary MarkedPolynomial + +structure LocalConstants where + A : ℝ + C : ℝ + P : ℝ + L : ℝ + E : ℝ + V : ℝ + S : ℝ + one_le_A : 1≤A + C_nonneg : 0≤C + C_le_A : C≤A + P_nonneg : 0≤P + L_nonneg : 0≤L + E_nonneg : 0≤E + V_nonneg : 0≤V + S_nonneg : 0≤S + +namespace LocalConstants +variable (c : LocalConstants) +def argument (d : ℕ) : ℝ := (d:ℝ)*c.P+c.V +def row (d : ℕ) : ℝ := c.C*c.argument d +def normBudget (j : ℝ) (d : ℕ) : ℕ→ℝ := recipeBudget (recipeCost c.A (c.row d) c.L c.P j d) c.S +def traceCost (d : ℕ) : ℝ := + c.V+4*((2*(d:ℝ)*c.P)^2+((d:ℝ)*c.P)*c.V+c.V^2)+2*(2*(d:ℝ)*c.P+(d:ℝ)*c.P+c.V) +def sourceCost (j : ℝ) (d s : ℕ) (a : ℕ) : ℝ := + (s:ℝ)*(c.C*c.S*c.traceCost d)+(∑b:Fin a,c.C*c.normBudget j d b*c.traceCost d)+ + (d:ℝ)*(c.normBudget j d a*c.E) +def fieldCost (j : ℝ) (d : ℕ) (a : ℕ) : ℝ := + (d:ℝ)*(|j| *(c.normBudget j d a*c.E))+ + |j| *((d:ℝ)*(c.normBudget j d a*(1+2*c.P))+(∑b:Fin a,3*c.normBudget j d b*c.row d)) +lemma A_nonneg : 0≤c.A := le_trans (by norm_num) c.one_le_A +lemma argument_nonneg (d : ℕ) : 0≤c.argument d := by unfold argument; positivity [c.P_nonneg,c.V_nonneg] +lemma row_nonneg (d : ℕ) : 0≤c.row d := mul_nonneg c.C_nonneg (c.argument_nonneg d) +lemma normBudget_nonneg (j : ℝ) (d a : ℕ) : 0≤c.normBudget j d a := + recipeBudget_nonneg (recipeCost_nonneg c.A_nonneg (c.row_nonneg d) c.L_nonneg c.P_nonneg) c.S_nonneg a +lemma traceCost_nonneg (d : ℕ) : 0≤c.traceCost d := by unfold traceCost; positivity [c.P_nonneg,c.V_nonneg] +end LocalConstants + +variable {n : ℕ} {ι κ σ : Type*} [Fintype ι] [DecidableEq ι] [Fintype κ] [DecidableEq κ] [Fintype σ] + +structure LocalOrdinaryInput (D : OrdinaryData n ι κ σ) (T : ι→SourceTree (Fin n→ℝ)) + (x : Spin n) (N : ℕ) (c : LocalConstants) : Prop where + dimension : 0(h.primaryShape l).1).trans_eq (by simp) +lemma seed_bound (a : ℕ) (ha : a≤N) (s : σ) : + CoefficientBound (D.seedCoefficient a s) x c.A (c.row (Fintype.card ι)) := + (h.seedRegular a ha s).coefficient_bound c.A_nonneg (c.argument_nonneg _) (h.seedValue a ha s) h.argument_bound +lemma aux_bound (a : ℕ) (ha : a≤N) (b : Fin a) : + CoefficientBound (D.auxCoefficient a b) x c.A (c.row (Fintype.card ι)) := + (h.auxRegular a ha b).coefficient_bound c.A_nonneg (c.argument_nonneg _) (h.auxValue a ha b) h.argument_bound +lemma seed_partial_bound (a : ℕ) (ha : a≤N) (l : ι) (s : σ) : + CoefficientBound (D.seedPartial a l s) x c.A (c.row (Fintype.card ι)) := + (h.seedRegular a ha s).partial_bound_coefficient (.inl l) c.A_nonneg (c.argument_nonneg _) c.C_le_A h.argument_bound +lemma aux_partial_bound (a : ℕ) (ha : a≤N) (l : ι) (b : Fin a) : + CoefficientBound (D.auxPartial a l b) x c.A (c.row (Fintype.card ι)) := + (h.auxRegular a ha b).partial_bound_coefficient (.inl l) c.A_nonneg (c.argument_nonneg _) c.C_le_A h.argument_bound + +lemma small (a : ℕ) (ha : a≤N) : + SmallBound (D.source a) x (c.normBudget D.j (Fintype.card ι) a) ∧ + SmallBound (D.auxiliary a) x (c.normBudget D.j (Fintype.card ι) a) ∧ + ∀l,SmallBound (D.sourcePartial a l) x (c.normBudget D.j (Fintype.card ι) a) := + D.evaluation_small N x h.dimension c.A_nonneg (c.row_nonneg _) c.L_nonneg c.P_nonneg c.S_nonneg + h.interaction h.seed h.primaryValue h.primaryDerivative h.seed_bound h.aux_bound h.seed_partial_bound h.aux_partial_bound a ha + +lemma source_control (a : ℕ) (ha : a≤N) : + TraceControl (D.nodeSourceError T x a) (c.sourceCost D.j (Fintype.card ι) (Fintype.card σ) a) := by + let d:=Fintype.card ι + let W:=c.normBudget D.j d + have hn (s : σ) : vectorNorm (D.seed s)≤c.S := + (Finset.single_le_sum (fun s _=>vectorNorm_nonneg (D.seed s)) (Finset.mem_univ s)).trans h.seed + have H:=D.nodeSource_control T x a c.C_nonneg + (show 0≤2*(d:ℝ)*c.P by positivity [c.P_nonneg]) + (show 0≤(d:ℝ)*c.P by positivity [c.P_nonneg]) + (show 0≤(d:ℝ)*c.P by positivity [c.P_nonneg]) c.V_nonneg + (fun b:Fin a=>(h.small b (b.isLt.le.trans ha)).2.1) (h.small a ha).2.2 h.primaryFieldError + (h.seedRegular a ha) (h.auxRegular a ha) + ((parameterIncrement_bound D.θ x).trans h.parameter) + (primaryIncrement_fourth D.H x c.P_nonneg h.primaryShape) + (primaryIncrement_row D.H x c.P_nonneg (fun l=>(h.primaryShape l).1)) + (primaryIncrement_diagonal D.H x c.P_nonneg (fun l=>(h.primaryShape l).2.1)) + (show _≤c.traceCost d from add_le_add (add_le_add h.parameter le_rfl) le_rfl) + apply H.mono + have hs : (∑s,c.C*vectorNorm (D.seed s)*c.traceCost d)≤(Fintype.card σ:ℝ)*(c.C*c.S*c.traceCost d) := + (Finset.sum_le_sum fun s _=>mul_le_mul_of_nonneg_right + (mul_le_mul_of_nonneg_left (hn s) c.C_nonneg) (c.traceCost_nonneg d)).trans_eq (by simp) + dsimp only [LocalConstants.sourceCost] + have hp : (∑_l:ι,c.normBudget D.j d a*c.E)=(d:ℝ)*(c.normBudget D.j d a*c.E) := by simp [d] + rw [hp] + exact add_le_add (add_le_add hs le_rfl) le_rfl + +lemma field_control (a : ℕ) (ha : a≤N) : + TraceControl (D.nodeFieldError T x a) (c.fieldCost D.j (Fintype.card ι) a) := by + have H:=D.nodeField_control T x a h.dimension c.P_nonneg (c.row_nonneg _) + (fun b:Fin a=>(h.small b (b.isLt.le.trans ha)).1) (h.small a ha).2.2 h.primarySourceError + h.primaryValue h.primaryDerivative (fun b=>(h.aux_bound a ha b).difference) + simpa only [LocalConstants.fieldCost,Finset.sum_const,Finset.card_univ,nsmul_eq_mul] using H + +lemma mean_bound (a : ℕ) (ha : a≤N) (b : Fin a) : |siteMean (D.auxCoefficient a b) x|≤c.A := + coefficient_mean_value (D.auxCoefficient a b) x c.A_nonneg (h.auxValue a ha b) + +end LocalOrdinaryInput + +namespace OrdinaryData +variable (D : OrdinaryData n ι κ σ) + +theorem ordinary_local_closure (T : ι→SourceTree (Fin n→ℝ)) (x : Spin n) (N : ℕ) + (c : LocalConstants) (h : LocalOrdinaryInput D T x N c) + {M B Q : ℝ} (hM : 0≤M) (hB : 0≤B) (hQ : 0≤Q) + (hm : ∀l,mass ((T l).words D.j).1≤Q ∧ mass ((T l).words D.j).2≤Q) + (hw : WordTestBound D.J c.A M (2*N+3)) + (hd : ∀a≤N,∀d:Fin n→ℝ,(∀i,|d i|≤1)→ + (∀t∈(D.markedRecipe T x a).1,SKGap.diagonalSeminorm (matrixWord D.J (t.2.diagnostic d)- + Matrix.diagonal (Diagram.prediction D.j (t.2.diagnostic d)))≤B) ∧ + (∀t∈(D.markedRecipe T x a).2,SKGap.diagonalSeminorm (matrixWord D.J (t.2.diagnostic d)- + Matrix.diagonal (Diagram.prediction D.j (t.2.diagnostic d)))≤B)) : + let W:=c.normBudget D.j (Fintype.card ι) + let R:=errorBudget (|D.j| *c.A) (c.sourceCost D.j (Fintype.card ι) (Fintype.card σ)) + (c.fieldCost D.j (Fintype.card ι)) + let V:=traceBudget ((Fintype.card ι:ℝ)*((2+|D.j|)*Q)) (2+|D.j| *c.A) W + ∀a≤N,SmallBound (D.source a) x (W a) ∧ SmallBound (D.auxiliary a) x (W a) ∧ + (∑i,|derivativeMatrix (D.source a) x i i|)≤V a*B+(R a).1*M ∧ + (∑i,|derivativeMatrix (D.auxiliary a) x i i|)≤V a*B+(R a).2*M := by + dsimp only + let W:=c.normBudget D.j (Fintype.card ι) + let R:=errorBudget (|D.j| *c.A) (c.sourceCost D.j (Fintype.card ι) (Fintype.card σ)) + (c.fieldCost D.j (Fintype.card ι)) + let V:=traceBudget ((Fintype.card ι:ℝ)*((2+|D.j|)*Q)) (2+|D.j| *c.A) W + have herr:=D.derivative_error_words T x (mul_nonneg (abs_nonneg _) c.A_nonneg) hM h.auxValue + (fun a ha b=>by rw [abs_mul]; exact mul_le_mul_of_nonneg_left (h.mean_bound a ha b) (abs_nonneg _)) + h.source_control h.field_control hw + have hmark:=D.markedRecipe_budget T x N W c.A_nonneg hQ (fun a ha l=>(h.small a ha).2.2 l |>.size) hm h.mean_bound + intro a ha + have hbounds := h.small a ha + have hretS : (∑i,|D.retainedSource T x a i i|)≤V a*B := by + apply (D.retainedSource_diagonal T x a h.dimension hB (fun d hd'=>(hd a ha d hd').1)).trans + apply mul_le_mul_of_nonneg_right _ hB + exact (le_add_of_nonneg_right (budget_nonneg _)).trans (hmark a ha) + have hretF : (∑i,|D.retainedField T x a i i|)≤V a*B := by + apply (D.retainedField_diagonal T x a h.dimension hB (fun d hd'=>(hd a ha d hd').2)).trans + apply mul_le_mul_of_nonneg_right _ hB + exact (le_add_of_nonneg_left (budget_nonneg _)).trans (hmark a ha) + have herrorS : (∑i,|D.sourceDerivativeError T x a i i|)≤(R a).1*M := by + apply diagonal_abs_sum_of_tests + intro d hd' + have H:=(herr a ha).1 [.diag d] (by simp; omega) (by + intro l hl; have he : l=Letter.diag d := List.mem_singleton.mp hl; subst l + exact fun i=>(hd' i).trans c.one_le_A) + simpa [matrixWord,matrixLetter] using H + have herrorF : (∑i,|D.fieldDerivativeError T x a i i|)≤(R a).2*M := by + apply diagonal_abs_sum_of_tests + intro d hd' + have H:=(herr a ha).2 [.diag d] (by simp; omega) (by + intro l hl; have he : l=Letter.diag d := List.mem_singleton.mp hl; subst l + exact fun i=>(hd' i).trans c.one_le_A) + simpa [matrixWord,matrixLetter] using H + refine ⟨hbounds.1,hbounds.2.1,?_,?_⟩ + · calc + _ = ∑i,|D.retainedSource T x a i i+D.sourceDerivativeError T x a i i| := by + simp only [sourceDerivativeError,Matrix.sub_apply]; congr 1; funext i; congr 1; ring + _ ≤ (∑i,|D.retainedSource T x a i i|)+(∑i,|D.sourceDerivativeError T x a i i|) := + (Finset.sum_le_sum fun i _=>abs_add_le _ _).trans_eq Finset.sum_add_distrib + _ ≤ _ := add_le_add hretS herrorS + · calc + _ = ∑i,|D.retainedField T x a i i+D.fieldDerivativeError T x a i i| := by + simp only [fieldDerivativeError,Matrix.sub_apply]; congr 1; funext i; congr 1; ring + _ ≤ (∑i,|D.retainedField T x a i i|)+(∑i,|D.fieldDerivativeError T x a i i|) := + (Finset.sum_le_sum fun i _=>abs_add_le _ _).trans_eq Finset.sum_add_distrib + _ ≤ _ := add_le_add hretF herrorF + +end OrdinaryData +end SKGapCutoff.Recipe + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Stability/OrdinaryCutLeft.lean b/lean/OAI/Probability/SKGap/Stability/OrdinaryCutLeft.lean new file mode 100644 index 0000000000000000000000000000000000000000..b7a74a8b2dce15d33d3b9656683b6be65dc4489e --- /dev/null +++ b/lean/OAI/Probability/SKGap/Stability/OrdinaryCutLeft.lean @@ -0,0 +1,125 @@ +import Mathlib +import OAI.Probability.SKGap.Stability.Ordinary + +namespace OAI + +section +noncomputable section +noncomputable section +open scoped BigOperators +noncomputable section +noncomputable section +noncomputable section +open scoped BigOperators +noncomputable section +open scoped BigOperators +noncomputable section +open scoped BigOperators +noncomputable section +open scoped BigOperators +noncomputable section +open scoped BigOperators +noncomputable section +open scoped BigOperators +noncomputable section +open scoped BigOperators +noncomputable section +open scoped BigOperators +namespace SKGap.Noncrossing +namespace WordSeries +open Diagram InverseDiagram +variable {ι : Type*} [Fintype ι] + +lemma ordinary_cut_left (j : ℝ) (P K R T : List (Letter (ι→ℝ))) (i : ι) : + ordinary j (P++K++R++(.noise::T)) i = + (∑ s : NoiseSplit P, j*mean (ordinary j (s.after++K++R))*ordinary j (s.before++T) i) + + (∑ s : NoiseSplit K, j*mean (ordinary j (s.after++R))*ordinary j (P++s.before++T) i) + + (∑ s : NoiseSplit R, j*mean (ordinary j s.after)*ordinary j (P++K++s.before++T) i) + + (∑ s : NoiseSplit T, j*mean (ordinary j s.before)*ordinary j (P++K++R++s.after) i) := by + have hh := expect_at j (id : (ι→ℝ)→ι→ℝ) (P++(K++R)) T i + rw [NoiseSplit.sum_append P (K++R) (fun U V => + j*mean (expect j id V)*expect j id (U++T) i)] at hh + rw [NoiseSplit.sum_append K R (fun U V => + j*mean (expect j id V)*expect j id ((P++U)++T) i)] at hh + simpa only [ordinary,List.append_assoc,add_assoc] using hh + +lemma inverse_partner_left (j : ℝ) (a : ι→ℝ) (P R T : List (Letter (ι→ℝ))) + (n : ℕ) (i : ι) : + (∑ bs : Blocks (n+1), ∑ s : NoiseSplit (chain j a bs.val), + j*mean (ordinary j (s.after++R))*ordinary j (P++s.before++T) i) = + ∑ k : Fin (n+1), j*mean (inverseCoefficient j a [] R (n-k.val))* + inverseCoefficient j a P (.diag a::T) k.val i := by + rw [sum_marked_chain j a n (fun U V => + j*mean (ordinary j (V++R))*ordinary j (P++U++T) i)] + apply Finset.sum_congr rfl + intro k _ + rw [Finset.sum_comm] + simp only [List.append_assoc,List.cons_append,List.nil_append] + simp_rw [← Finset.mul_sum] + rw [← Finset.sum_mul,← Finset.mul_sum,mean_inverseCoefficient] + simp only [inverseCoefficient,List.append_assoc,List.nil_append] + +theorem inverseCoefficient_left (j : ℝ) (a : ι→ℝ) + (P R T : List (Letter (ι→ℝ))) (n : ℕ) (i : ι) : + inverseCoefficient j a P (R++(.noise::T)) (n+1) i = + (∑ s : NoiseSplit P, j*mean (inverseCoefficient j a s.after R (n+1))* + ordinary j (s.before++T) i) + + (∑ k : Fin (n+1), j*mean (inverseCoefficient j a [] R (n-k.val))* + inverseCoefficient j a P (.diag a::T) k.val i) + + (∑ s : NoiseSplit R, j*mean (ordinary j s.after)* + inverseCoefficient j a P (s.before++T) (n+1) i) + + (∑ s : NoiseSplit T, j*mean (ordinary j s.before)* + inverseCoefficient j a P (R++s.after) (n+1) i) := by + have hh : inverseCoefficient j a P (R++(.noise::T)) (n+1) i = + (∑ bs : Blocks (n+1), ∑ s : NoiseSplit P, j*mean (ordinary j (s.after++chain j a bs.val++R))* + ordinary j (s.before++T) i) + + (∑ bs : Blocks (n+1), ∑ s : NoiseSplit (chain j a bs.val), + j*mean (ordinary j (s.after++R))*ordinary j (P++s.before++T) i) + + (∑ bs : Blocks (n+1), ∑ s : NoiseSplit R, j*mean (ordinary j s.after)* + ordinary j (P++chain j a bs.val++s.before++T) i) + + (∑ bs : Blocks (n+1), ∑ s : NoiseSplit T, j*mean (ordinary j s.before)* + ordinary j (P++chain j a bs.val++R++s.after) i) := by + unfold inverseCoefficient + have hcut (bs : Blocks (n+1)) := ordinary_cut_left j P (chain j a bs.val) R T i + have he := Finset.sum_congr rfl (fun bs (_ : bs∈(Finset.univ : Finset (Blocks (n+1)))) => hcut bs) + simpa only [List.append_assoc,Finset.sum_add_distrib] using he + rw [hh,inverse_partner_left] + congr 2 + · congr 2 + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro s _ + rw [← Finset.sum_mul,← Finset.mul_sum,← mean_inverseCoefficient] + · rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro s _ + rw [← Finset.mul_sum] + simp only [inverseCoefficient,List.append_assoc] + · rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro s _ + rw [← Finset.mul_sum] + simp only [inverseCoefficient,List.append_assoc] + +end WordSeries +end SKGap.Noncrossing + +noncomputable section +open scoped BigOperators + +end +end +end +end +end +end +end +end +end +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Stability/OrdinaryGraph.lean b/lean/OAI/Probability/SKGap/Stability/OrdinaryGraph.lean new file mode 100644 index 0000000000000000000000000000000000000000..16d90fdef9ee36308b68998e7b4bcdd28bc3ff41 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Stability/OrdinaryGraph.lean @@ -0,0 +1,111 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.GraphPrediction + +namespace OAI + +section + +noncomputable section +open scoped BigOperators +namespace SKGap.Noncrossing.Primary +open Diagram +variable {ι : Type*} [Fintype ι] [DecidableEq ι] + +inductive SourceTree (D : Type*) where + | leaf : ℝ → SourceTree D + | branch : D → SourceTree D → SourceTree D → SourceTree D + +namespace SourceTree +variable {D : Type*} + +def leafMass : SourceTree D→ℝ + | .leaf c => c + | .branch _ _ b => leafMass b + +def words (j : ℝ) : SourceTree (ι→ℝ)→WordPolynomial (ι:=ι)×WordPolynomial (ι:=ι) + | .leaf c => ([(c,[])],[(c,[.noise])]) + | .branch p a b => + (prependWords [.diag p] (words j a).2 ++ (words j b).1, + (prependWords [.noise,.diag p] (words j a).2 ++ + scale (-(j*Diagram.mean p)) (words j a).1) ++ (words j b).2) + +def sourceOperator (j : ℝ) (t : SourceTree (ι→ℝ)) := polynomialOperator j (t.words j).1 +def fieldOperator (j : ℝ) (t : SourceTree (ι→ℝ)) := polynomialOperator j (t.words j).2 + +section +omit [DecidableEq ι] + +lemma source_leaf (j c : ℝ) : sourceOperator (ι:=ι) j (.leaf c)=c • LinearMap.id := by + simp [sourceOperator,words,polynomialOperator,word] +lemma field_leaf (j c : ℝ) : fieldOperator (ι:=ι) j (.leaf c)=c • noise j := by + simp [fieldOperator,words,polynomialOperator,word,letter] +lemma source_branch (j : ℝ) (p : ι→ℝ) (a b : SourceTree (ι→ℝ)) : + sourceOperator j (.branch p a b)=(diagonal p).comp (fieldOperator j a)+sourceOperator j b := by + simp [sourceOperator,fieldOperator,words,polynomialOperator_append, + polynomialOperator_prefix,word,letter] +lemma field_branch (j : ℝ) (p : ι→ℝ) (a b : SourceTree (ι→ℝ)) : + fieldOperator j (.branch p a b)= + (noise j).comp ((diagonal p).comp (fieldOperator j a))- + (j*Diagram.mean p) • sourceOperator j a+fieldOperator j b := by + simp only [sourceOperator,fieldOperator,words,polynomialOperator_append, + polynomialOperator_prefix,polynomialOperator_scale,word,letter,LinearMap.comp_id, + LinearMap.comp_assoc] + ext v s + simp [LinearMap.sub_apply,LinearMap.smul_apply,sub_eq_add_neg] + +theorem field_vacuum (j : ℝ) (t : SourceTree (ι→ℝ)) : + fieldOperator j t vacuum=creation (sourceOperator j t vacuum) := by + induction t with + | leaf c => simp [field_leaf,source_leaf,noise,vacuum] + | branch p a b ia ib => + rw [field_branch,source_branch] + simp only [LinearMap.add_apply,LinearMap.sub_apply,LinearMap.comp_apply, + LinearMap.smul_apply,ia,ib,map_add,noise] + simp only [annihilation_diagonal_creation,smul_smul] + abel + +theorem field_prediction_zero (j : ℝ) (t : SourceTree (ι→ℝ)) (i : ι) : + polynomialPrediction j (t.words j).2 i=0 := by + rw [polynomialPrediction_eq_project] + change project (fieldOperator j t vacuum) i=0 + rw [field_vacuum,project_creation]; rfl + +theorem source_prediction (j : ℝ) (t : SourceTree (ι→ℝ)) (i : ι) : + polynomialPrediction j (t.words j).1 i=t.leafMass := by + rw [polynomialPrediction_eq_project] + change project (sourceOperator j t vacuum) i=t.leafMass + induction t with + | leaf c => simp [source_leaf,leafMass,vacuum,project,ket] + | branch p a b ia ib => + rw [source_branch] + simp only [LinearMap.add_apply,LinearMap.comp_apply,map_add,field_vacuum, + project_diagonal_creation,zero_add,leafMass] + exact ib + +end + +def sourceMatrix (j : ℝ) (J : Matrix ι ι ℝ) (t : SourceTree (ι→ℝ)) := + matrixPolynomial J (t.words j).1 +def fieldMatrix (j : ℝ) (J : Matrix ι ι ℝ) (t : SourceTree (ι→ℝ)) := + matrixPolynomial J (t.words j).2 +lemma sourceMatrix_leaf (j c : ℝ) (J : Matrix ι ι ℝ) : + sourceMatrix j J (.leaf c)=c • 1 := by simp [sourceMatrix,words,matrixPolynomial,matrixWord] +lemma fieldMatrix_leaf (j c : ℝ) (J : Matrix ι ι ℝ) : + fieldMatrix j J (.leaf c)=c • J := by + simp [fieldMatrix,words,matrixPolynomial,matrixWord,matrixLetter] +lemma sourceMatrix_branch (j : ℝ) (J : Matrix ι ι ℝ) (p : ι→ℝ) (a b : SourceTree (ι→ℝ)) : + sourceMatrix j J (.branch p a b)=Matrix.diagonal p*fieldMatrix j J a+sourceMatrix j J b := by + simp [sourceMatrix,fieldMatrix,words,matrixPolynomial_append,matrixPolynomial_prefix, + matrixWord,matrixLetter] +lemma fieldMatrix_branch (j : ℝ) (J : Matrix ι ι ℝ) (p : ι→ℝ) (a b : SourceTree (ι→ℝ)) : + fieldMatrix j J (.branch p a b)=J*(Matrix.diagonal p*fieldMatrix j J a)- + (j*Diagram.mean p) • sourceMatrix j J a+fieldMatrix j J b := by + simp [sourceMatrix,fieldMatrix,words,matrixPolynomial_append,matrixPolynomial_prefix, + matrixPolynomial_scale,matrixWord,matrixLetter,mul_assoc,sub_eq_add_neg,add_assoc] +end SourceTree +end SKGap.Noncrossing.Primary + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Stability/OrdinaryRecipe.lean b/lean/OAI/Probability/SKGap/Stability/OrdinaryRecipe.lean new file mode 100644 index 0000000000000000000000000000000000000000..b7b00e5b55f244a4f193a5ce7ad86b80ba160cfe --- /dev/null +++ b/lean/OAI/Probability/SKGap/Stability/OrdinaryRecipe.lean @@ -0,0 +1,123 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.CoefficientRow + +namespace OAI + +section + +noncomputable section +open scoped BigOperators Matrix.Norms.Frobenius +namespace SKGapCutoff.Recipe +open Primary Matrix +variable {n : ℕ} {ι κ σ : Type*} [Fintype ι] [DecidableEq ι] [Fintype κ] [DecidableEq κ] [Fintype σ] + +structure OrdinaryData (n : ℕ) (ι κ σ : Type*) [Fintype ι] [DecidableEq ι] [Fintype κ] [DecidableEq κ] where + J : Interaction n + j : ℝ + H : ι→VectorFields n + predecessor : ι→VectorFields n + θ : κ→Spin n→ℝ + seed : σ→Fin n→ℝ + seedFunction : ℕ→σ→Fin n→Args (ι:=ι) (κ:=κ)→ℝ + seedDerivative : ℕ→σ→Fin n→Args (ι:=ι) (κ:=κ)→Args (ι:=ι) (κ:=κ)→L[ℝ]ℝ + auxFunction : (a : ℕ)→Fin a→Fin n→Args (ι:=ι) (κ:=κ)→ℝ + auxDerivative : (a : ℕ)→Fin a→Fin n→Args (ι:=ι) (κ:=κ)→Args (ι:=ι) (κ:=κ)→L[ℝ]ℝ + +namespace OrdinaryData +variable (D : OrdinaryData n ι κ σ) + +def seedCoefficient (a : ℕ) (s : σ) : VectorFields n := coefficient D.H D.θ (D.seedFunction a s) +def auxCoefficient (a : ℕ) (b : Fin a) : VectorFields n := coefficient D.H D.θ (D.auxFunction a b) +def seedPartial (a : ℕ) (l : ι) (s : σ) : VectorFields n := localPartial D.H D.θ (D.seedDerivative a s) (.inl l) +def auxPartial (a : ℕ) (l : ι) (b : Fin a) : VectorFields n := localPartial D.H D.θ (D.auxDerivative a b) (.inl l) + +def sourceOf (a : ℕ) (Y : Fin a→VectorFields n) : VectorFields n := fun x i=> + (∑s,D.seedCoefficient a s x i*D.seed s i)+(∑b,D.auxCoefficient a b x i*Y b x i) + +def partialOf (a : ℕ) (l : ι) (Y : Fin a→VectorFields n) : VectorFields n := fun x i=> + (∑s,D.seedPartial a l s x i*D.seed s i)+(∑b,D.auxPartial a l b x i*Y b x i) + +def fieldOf (a : ℕ) (W Y : Fin a→VectorFields n) : VectorFields n := fun x i=> + D.J.mulVec (D.sourceOf a Y x) i- + D.j*(∑l,siteMean (D.partialOf a l Y) x*D.predecessor l x i)- + D.j*∑b,siteMean (D.auxCoefficient a b) x*W b x i + +def evaluate (D : OrdinaryData n ι κ σ) (a : ℕ) : VectorFields n × VectorFields n := + let prev := fun b : Fin a=>evaluate D b + (D.sourceOf a (fun b=>(prev b).2),D.fieldOf a (fun b=>(prev b).1) (fun b=>(prev b).2)) +termination_by a + +def source (a : ℕ) : VectorFields n := (D.evaluate a).1 +def auxiliary (a : ℕ) : VectorFields n := (D.evaluate a).2 +def sourcePartial (a : ℕ) (l : ι) : VectorFields n := D.partialOf a l (fun b=>D.auxiliary b) + +lemma source_eq (a : ℕ) : D.source a=D.sourceOf a (fun b=>D.auxiliary b) := by + rw [source,evaluate]; rfl +lemma auxiliary_eq (a : ℕ) : D.auxiliary a=D.fieldOf a (fun b=>D.source b) (fun b=>D.auxiliary b) := by + rw [auxiliary,evaluate]; rfl + +end OrdinaryData + +structure CoefficientBound (a : VectorFields n) (x : Spin n) (A R : ℝ) : Prop where + size_nonneg : 0≤A + row_nonneg : 0≤R + value : ∀i,|a x i|≤A + difference : ∀i,∑k,(derivativeMatrix a x i k)^2≤R^2 + +lemma CoefficientBound.small_product {a U : VectorFields n} {x : Spin n} {A R C : ℝ} + (ha : CoefficientBound a x A R) (hU : SmallBound U x C) : + SmallBound (fun x i=>a x i*U x i) x (C*(A+3*R)) := + hU.coefficient a ha.size_nonneg ha.row_nonneg ha.value ha.difference + +lemma CoefficientBound.mean_product {a U : VectorFields n} {x : Spin n} {A R C : ℝ} + (ha : CoefficientBound a x A R) (hU : SmallBound U x C) : + SmallBound (fun x i=>siteMean a x*U x i) x (C*(A+3*R)) := + hU.auxiliaryCorrection a ha.size_nonneg ha.row_nonneg ha.value ha.difference + +namespace OrdinaryData +variable (D : OrdinaryData n ι κ σ) + +lemma sourceOf_bound (a : ℕ) (Y : Fin a→VectorFields n) (x : Spin n) {A R : ℝ} (C : Fin a→ℝ) + (hY : ∀b,SmallBound (Y b) x (C b)) + (hs : ∀s,CoefficientBound (D.seedCoefficient a s) x A R) + (ha : ∀b,CoefficientBound (D.auxCoefficient a b) x A R) : + SmallBound (D.sourceOf a Y) x (((∑s,vectorNorm (D.seed s))+(∑b,C b))*(A+3*R)) := by + have H:=(SmallBound.sum fun s=>(hs s).small_product (SmallBound.seed (D.seed s) x)).add + (SmallBound.sum fun b=>(ha b).small_product (hY b)) + convert! H using 1 + simp only [←Finset.sum_mul,add_mul] + +lemma partialOf_bound (a : ℕ) (l : ι) (Y : Fin a→VectorFields n) (x : Spin n) {A R : ℝ} (C : Fin a→ℝ) + (hY : ∀b,SmallBound (Y b) x (C b)) + (hs : ∀s,CoefficientBound (D.seedPartial a l s) x A R) + (ha : ∀b,CoefficientBound (D.auxPartial a l b) x A R) : + SmallBound (D.partialOf a l Y) x (((∑s,vectorNorm (D.seed s))+(∑b,C b))*(A+3*R)) := by + have H:=(SmallBound.sum fun s=>(hs s).small_product (SmallBound.seed (D.seed s) x)).add + (SmallBound.sum fun b=>(ha b).small_product (hY b)) + convert! H using 1 + simp only [←Finset.sum_mul,add_mul] + +lemma fieldOf_bound (a : ℕ) (W Y : Fin a→VectorFields n) (x : Spin n) (hn : 0(hp l).primaryCorrection (D.predecessor l) hn hP (hm l) (hdm l)).smul D.j + have h2 := (SmallBound.sum fun b=>(ha b).mean_product (hW b)).smul D.j + have H:= (h0.sub h1).sub h2 + convert! H using 1 + simp only [Finset.sum_const,Finset.card_univ,nsmul_eq_mul,←Finset.sum_mul] + +end OrdinaryData +end SKGapCutoff.Recipe + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Stability/OrdinaryWordEvent.lean b/lean/OAI/Probability/SKGap/Stability/OrdinaryWordEvent.lean new file mode 100644 index 0000000000000000000000000000000000000000..c1c95e08d105721170a6f20d41b3cbd2614b6f76 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Stability/OrdinaryWordEvent.lean @@ -0,0 +1,93 @@ +import Mathlib +import OAI.Probability.SKGap.Matrix.WordDiag +import OAI.Probability.SKGap.Matrix.RecipeWordEvent + +namespace OAI + +section + +noncomputable section +open scoped BigOperators +namespace SKGapCutoff.Recipe +open SKGap SKGap.Noncrossing SKGap.Noncrossing.Primary MeasureTheory ProbabilityTheory Real Set +variable {n : ℕ} + +lemma wordBounded_lift (A : ℝ) (w : OrdinaryWord n) : + wordBounded A w ↔ ∀l∈liftWord w,l.bounded A := by + constructor + · intro h l hl + obtain ⟨a,ha,rfl⟩:=List.mem_map.mp hl + cases a <;> exact h _ ha + · intro h l hl + have hh:=h (Letter.toWord l) (List.mem_map.mpr ⟨l,hl,rfl⟩) + cases l <;> exact hh + +def WordSeminormBound (J : Interaction n) (j A C : ℝ) (L : ℕ) : Prop := + ∀(p : Bool) (w : OrdinaryWord n),w.length≤L→wordBounded A w→ + matrixWordSeminorm p (matrixWord J w-Matrix.diagonal (Diagram.prediction j w))≤C + +lemma wordSeminormBound_diagram {J : Interaction n} {j A C : ℝ} {L : ℕ} + (h : WordSeminormBound J j A C L) : WordDiagramBound J j A C L := h false + +lemma offDiagonalSeminorm_sub_diagonal (M : Interaction n) (a : Fin n→ℝ) : + SKGap.offDiagonalSeminorm (M-Matrix.diagonal a)=SKGap.offDiagonalSeminorm M := by + unfold SKGap.offDiagonalSeminorm + congr 1 + ext ⟨i,k⟩ + by_cases hik:i=k <;> simp [SKGap.offDiagonalVector,Matrix.diagonal_apply,hik] + +lemma matrixWord_opNorm (J : Interaction n) (hn : 0simpa [matrixWord] using (SKGap.opNorm_one_le (ι:=Fin n)) + | cons l w ih=> + have hl : SKGap.opNorm (matrixLetter J l)≤R := by + cases l with + | noise=>exact hJ + | diag a=>exact SKGap.opNorm_diagonal_le (by linarith) (hw (.diag a) (List.mem_cons_self)) + have hh:=ih (fun a ha=>hw a (List.mem_cons_of_mem _ ha)) + simp only [matrixWord,List.map_cons,List.prod_cons,List.length_cons,pow_succ] + exact (SKGap.opNorm_mul _ _).trans ((mul_le_mul hl hh (norm_nonneg _) (by linarith)).trans_eq (mul_comm _ _)) + +lemma wordSeminormBound_test {J : Interaction n} {j A C R : ℝ} {L : ℕ} + (h : WordSeminormBound J j A C L) (hn : 0gaussianReal 0 1)) + {g | ¬WordSeminormBound (removeDiagonal (goeMatrix (j/n) g)) j A C L}≤ + 2*((wordPatternSet L L).card*ENNReal.ofReal (3*exp (-(n:ℝ)))+ + ENNReal.ofReal (exp (-2*(n:ℝ)/(π^2*(sqrt (2*j))^2)))+ + (ENNReal.ofReal (2*exp (-(n:ℝ)/(π^2*j)))+ + ENNReal.ofReal (2*(n:ℝ)*exp (-1/(8*(j/n)))))) := by + have hs : sqrt j*(1:ℝ)<1 := by nlinarith [sq_sqrt hj.le,sqrt_nonneg j] + obtain ⟨C,N,hC,hN,hb⟩:=zeroDiag_exact_words_two_seminorms hj (by norm_num : (0:ℝ)<1) + hs hA hA (by norm_num : (0:ℝ)<1) L + refine ⟨C,N,hC,hN,fun n hn=>?_⟩ + apply (measure_mono ?_).trans (hb n hn) + intro g hg + simp only [WordSeminormBound,not_forall,not_le] at hg + obtain ⟨p,w,hw,hwb,hfail⟩:=hg + refine ⟨p,(fun _=>0),liftWord w,?_,?_,(wordBounded_lift A w).mp hwb,?_,?_,?_⟩ + · intro i; norm_num + · simpa [liftWord] using hw + · simp + · exact Or.inl (inverseCount_lift w) + · have he : wordPrediction j (fun _ : Fin n=>0) 1 (liftWord w)=Diagram.prediction j w:= + funext (wordPrediction_lift j _ _ _) + simpa only [exactWord_lift,he] using hfail + +end SKGapCutoff.Recipe + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Stability/PlantedFieldArray.lean b/lean/OAI/Probability/SKGap/Stability/PlantedFieldArray.lean new file mode 100644 index 0000000000000000000000000000000000000000..c573ffc1ffe3d288c2417b3b1f6718b754f1fdd4 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Stability/PlantedFieldArray.lean @@ -0,0 +1,460 @@ +import Mathlib +import OAI.Probability.SKGap.Entropy.ProdFst +import OAI.Probability.SKGap.Entropy.BoundGood +import OAI.Probability.SKGap.Terminal.GibbsEventProbabilityReal + +namespace OAI + +section +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open scoped BigOperators +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open scoped BigOperators +open scoped BigOperators NNReal ENNReal +open MeasureTheory Metric Set +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators NNReal ENNReal Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Set +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators ENNReal NNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Matrix +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators ENNReal NNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal +open scoped BigOperators +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise NNReal ENNReal +open scoped BigOperators +open Filter Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal Topology +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Set Matrix +open scoped BigOperators NNReal ENNReal Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open Filter MeasureTheory ProbabilityTheory +open scoped Topology NNReal ENNReal +open Filter MeasureTheory ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter +open scoped Topology NNReal ENNReal +open MeasureTheory Filter ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter +open scoped Topology +open MeasureTheory Filter ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter ProbabilityTheory ContinuousLinearMap +open scoped Topology NNReal ENNReal +open Filter MeasureTheory ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter +open scoped BigOperators Topology +open MeasureTheory Filter +open scoped BigOperators Topology +open MeasureTheory Filter +open scoped BigOperators Topology +open MeasureTheory Filter +open scoped BigOperators Topology +open MeasureTheory Filter +open scoped BigOperators Topology +open Filter Set Metric +open scoped Topology RealInnerProductSpace +open scoped BigOperators +open ContinuousLinearMap +open scoped BigOperators +open ContinuousLinearMap +open scoped Topology Interval +open MeasureTheory +open MeasureTheory +open scoped BigOperators Topology Interval +open MeasureTheory +open scoped BigOperators Topology Interval +open scoped Topology +open MeasureTheory +open scoped BigOperators Topology Interval +open scoped BigOperators Topology +open MeasureTheory +open scoped BigOperators Topology Interval RealInnerProductSpace +open MeasureTheory Filter +open scoped BigOperators Topology Interval +open MeasureTheory Filter +open scoped Topology +open MeasureTheory Filter +open scoped Topology +open MeasureTheory Filter +open scoped Topology +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped BigOperators ENNReal NNReal Topology Matrix.Norms.L2Operator +namespace SKGapCutoff.Regression + +noncomputable def plantedFieldArray (β : ℝ) (n : ℕ) (g : Option (Fin n) → ℝ) : Fin n → ℝ := + sharedGaussianField (β^2*((n:ℝ)-1)/(n:ℝ)) + (β*Real.sqrt (((n:ℝ)-2)/(n:ℝ))) (β/Real.sqrt (n:ℝ)) g + +lemma plantedFieldArray_measurable (β : ℝ) (n : ℕ) : Measurable (plantedFieldArray β n) := by + unfold plantedFieldArray sharedGaussianField + fun_prop + +lemma planted_field_event_eq (β : ℝ) {n : ℕ} (hn : 2≤n) (x : Spin n) + (E : Set (Fin n → ℝ)) (hE : MeasurableSet E) : + singleSpinPlantedLaw β x ((gaugedField x) ⁻¹' E) = + standardArrayLaw (Option (Fin n)) ((plantedFieldArray β n) ⁻¹' E) := by + have hh := congrArg (fun μ : Measure (Fin n → ℝ) => μ E) (planted_field_representation β hn x) + change (singleSpinPlantedLaw β x).map (gaugedField x) E = + (standardArrayLaw (Option (Fin n))).map (plantedFieldArray β n) E at hh + rw [Measure.map_apply (continuous_gaugedField x).measurable hE, + Measure.map_apply (plantedFieldArray_measurable β n) hE] at hh + exact hh + +lemma plantedField_common_convergence (β : ℝ) (hβ : 0<β) : + ExponentialConvergence (fun n => standardArrayLaw (Option (Fin n))) + (fun n g => (β/Real.sqrt (n:ℝ))*g none) 0 := by + intro ε hε + refine ⟨2,ε^2/(2*β^2),by norm_num,by positivity,?_⟩ + filter_upwards [eventually_gt_atTop 0] with n hn + have hnR : (0:ℝ) standardArrayLaw (Option (Fin n))) + (plantedFieldArray β) := by + let ρ := fun n => standardArrayLaw (Option (Fin n)) + have hi : ExponentialSquareTails ρ (fun _ g i => g (some i)) := by + exact iid_exponential_squareTails ρ _ (fun _ _ => measurable_pi_apply _) + (fun _ => coordinates_independent.precomp (Option.some_injective _)) + (gaussianReal 0 1) (fun _ _ => coordinate_hasLaw _) gaussian_integrable_exp_quarter_sq + have ha := hi.bounded_mul + (fun n _ _ => β*Real.sqrt (((n:ℝ)-2)/(n:ℝ))) |β| (abs_nonneg β) + (fun n _ _ => plantedField_scale_bound β n) + have hm := exponentialSquareTails_of_bounded ρ + (fun n _ _ => β^2*((n:ℝ)-1)/(n:ℝ)) (β^2) (fun n _ _ => plantedField_mean_bound β n) + have hb := hm.add ha + apply hb.l2_stability + have hz := (plantedField_common_convergence β hβ).continuous_map + (f := fun x : ℝ => x^2) (by fun_prop) + simp only [zero_pow (by norm_num : (2:ℕ)≠0)] at hz + intro ε hε + apply (hz ε hε).mono + filter_upwards [eventually_gt_atTop 0] with n hn + intro g hg + have he : (∑ i : Fin n, + (β^2*((n:ℝ)-1)/(n:ℝ)+β*Real.sqrt (((n:ℝ)-2)/(n:ℝ))*g (some i) - + plantedFieldArray β n g i)^2)/(n:ℝ) = ((β/Real.sqrt (n:ℝ))*g none)^2 := by + simp only [plantedFieldArray,sharedGaussianField,sub_add_cancel_left, + neg_sq,Finset.sum_const,Finset.card_univ,Fintype.card_fin,nsmul_eq_mul] + field_simp + change ε ≤ dist _ 0 at hg ⊢ + rwa [he] at hg + +noncomputable def plantedFieldLimitLaw (β : ℝ) : Measure ℝ := + (gaussianReal 0 1).map (fun z => β^2+β*z) + +instance plantedFieldLimitLaw_probability (β : ℝ) : IsProbabilityMeasure (plantedFieldLimitLaw β) := by + unfold plantedFieldLimitLaw + infer_instance + +lemma plantedFieldArray_empirical (β : ℝ) (hβ : 0<β) : + ExponentialEmpiricalConcentration (fun n => standardArrayLaw (Option (Fin n))) + (plantedFieldArray β) (plantedFieldLimitLaw β) := by + intro f K hf B hB ε hε + have hf' : LipschitzWith (K+1) f := hf.weaken (by simp) + obtain ⟨c,hc,ht⟩ := planted_field_average_exponential β hβ f (by positivity) hf' + (|B|+1) (by positivity) (fun z => (hB z).trans (by linarith [le_abs_self B])) ε hε + refine ⟨1,c,by norm_num,hc,?_⟩ + filter_upwards [ht,eventually_ge_atTop 2] with n hn hn2 + have hm : (∫ z, f z ∂plantedFieldLimitLaw β) = ∫ z, f (β^2+β*z) ∂gaussianReal 0 1 := by + exact integral_map (by fun_prop) hf.continuous.aestronglyMeasurable + rw [hm] + have hh := hn (fun _ => false) + have hE : MeasurableSet {v : Fin n → ℝ | ε ≤ |(∑ i, f (v i))/(n:ℝ) - + ∫ z, f (β^2+β*z) ∂gaussianReal 0 1|} := by + apply measurableSet_le measurable_const + exact (((Finset.measurable_sum _ (fun i _ => hf.continuous.measurable.comp + (measurable_pi_apply i))).div_const _).sub_const _).abs + rw [show singleSpinPlantedLaw β (fun _ : Fin n => false) {g | ε ≤ + |(∑ i, f (gaugedField (fun _ => false) g i))/(n:ℝ) - + ∫ z, f (β^2+β*z) ∂gaussianReal 0 1|} = _ from + planted_field_event_eq β hn2 (fun _ => false) _ hE] at hh + simpa only [one_mul,Set.preimage_ofPred_eq] using hh + +lemma plantedFieldLimitLaw_secondMoment (β : ℝ) : + Integrable (fun z : ℝ => z^2) (plantedFieldLimitLaw β) ∧ + (∫ z, z^2 ∂plantedFieldLimitLaw β)=β^2+β^4 := by + have hl : HasLaw (fun z : ℝ => β^2+β*z) (plantedFieldLimitLaw β) (gaussianReal 0 1) := + ⟨by fun_prop,rfl⟩ + have hi2 : MemLp (id : ℝ → ℝ) 2 (plantedFieldLimitLaw β) := by + apply (memLp_map_measure_iff (by fun_prop) (by fun_prop)).mpr + exact (memLp_const (β^2)).add + (((IsGaussian.hasGaussianLaw_id (μ := gaussianReal 0 1)).memLp_two).const_mul β) + have hi := hi2.integrable_sq + refine ⟨hi,?_⟩ + have hmean : (∫ z, z ∂plantedFieldLimitLaw β)=β^2 := by + rw [← hl.integral_eq] + have hm : Integrable (fun z : ℝ => β*z) (gaussianReal 0 1) := + (IsGaussian.hasGaussianLaw_id (μ := gaussianReal 0 1)).integrable.const_mul β + rw [integral_add (integrable_const _) hm,integral_const,integral_const_mul] + simp [integral_id_gaussianReal] + have hv : Var[id; plantedFieldLimitLaw β]=β^2 := by + rw [← hl.variance_eq,variance_const_add (by fun_prop),variance_const_mul] + simp + have hh := variance_eq_sub (X := id) hi2 + simp only [Pi.pow_apply,id_eq,hmean] at hh + rw [hv] at hh + nlinarith + +lemma plantedFieldArray_secondMoment (β : ℝ) (hβ : 0<β) : + ExponentialConvergence (fun n => standardArrayLaw (Option (Fin n))) + (fun n g => (∑ i, plantedFieldArray β n g i^2)/(n:ℝ)) (β^2+β^4) := by + have hh := (plantedFieldArray_empirical β hβ).secondMoment + (plantedFieldArray_squareTails β hβ) (plantedFieldLimitLaw_secondMoment β).1 + rwa [(plantedFieldLimitLaw_secondMoment β).2] at hh + +lemma ExponentiallyRare.without_prefactor {H : ℕ → Type*} [∀ n, MeasurableSpace (H n)] + {ρ : ∀ n, Measure (H n)} {A : ∀ n, Set (H n)} (hA : ExponentiallyRare ρ A) : + ∃ c : ℝ, 0 (n:ℝ)) atTop atTop) + filter_upwards [he,hnc.eventually (eventually_ge_atTop (2*Real.log C/c))] with n hn hsize + apply hn.trans + apply ENNReal.ofReal_le_ofReal + rw [show C*Real.exp (-c*n)=Real.exp (Real.log C-c*n) by + rw [Real.exp_sub,Real.exp_log hC,neg_mul,Real.exp_neg,div_eq_mul_inv] ] + apply Real.exp_le_exp.mpr + have hh := (div_le_iff₀ hc).mp hsize + nlinarith + +noncomputable def spinFieldSquareAverage {n : ℕ} (x : Spin n) + (g : GaussianCoordinates n) : ℝ := (∑ i, gaugedField x g i^2)/(n:ℝ) + +lemma continuous_spinFieldSquareAverage {n : ℕ} (x : Spin n) : + Continuous (spinFieldSquareAverage x) := by + change Continuous (fun g => (∑ i, gaugedField x g i^2)/(n:ℝ)) + exact (continuous_finsetSum _ (fun i _ => + ((continuous_apply i).comp (continuous_gaugedField x)).pow 2)).div_const _ + +lemma spinFieldSquareAverage_planted_exponential (β : ℝ) (hβ : 0<β) + (ε : ℝ) (hε : 0<ε) : ∃ c : ℝ, 0 (measurable_pi_apply i).pow_const 2)).div_const _).sub_const _).abs + have he := planted_field_event_eq β hn2 x _ hE + change singleSpinPlantedLaw β x {g | ε ≤ |spinFieldSquareAverage x g-(β^2+β^4)|} = _ at he + rw [he] + simpa only [Real.dist_eq,Set.preimage_ofPred_eq] using hn + +theorem quenched_spinFieldSquareAverage_exponential (β : ℝ) (hβ : 0<β) (hβ1 : β<1) + (ε : ℝ) (hε : 0<ε) : ∃ c : ℝ, 0 disorderLaw β n {g | + ENNReal.ofReal (Real.exp (-c*n)) ≤ gibbsEventProbability + (fun x : Spin n => {h | ε ≤ |spinFieldSquareAverage x h-(β^2+β^4)|}) g}) + atTop (nhds 0) := by + obtain ⟨c,hc,hs⟩ := spinFieldSquareAverage_planted_exponential β hβ ε hε + refine ⟨c/2,by positivity,?_⟩ + apply quenched_gibbs_events_exponential β (by nlinarith) c hc _ _ hs + intro n x + exact measurableSet_le measurable_const ((continuous_spinFieldSquareAverage x).measurable.sub_const _).abs + +lemma spinFieldSquareAverage_abs_le_opNorm_sq {n : ℕ} (hn : 0 spinFieldSquareAverage x g) + +theorem gibbsSpinFieldSquareAverage_limit (β : ℝ) (hβ : 0<β) (hβ1 : β<1) + (ε : ℝ) (hε : 0<ε) : + Tendsto (fun n => disorderLaw β n {g | ε ≤ |gibbsSpinFieldSquareAverage g-(β^2+β^4)|}) + atTop (nhds 0) := by + obtain ⟨c,hc,hevent⟩ := quenched_spinFieldSquareAverage_exponential β hβ hβ1 (ε/2) (by positivity) + let C := 2*(β^2+10) + let K := C^2+(β^2+β^4) + have hK : 0 ≤ K := by dsimp [K,C]; positivity + have hnorm := RandomMatrix.sampled_opNorm_tendsto β + have ht : Tendsto (fun n : ℕ => K*Real.exp (-c*n)) atTop (nhds 0) := by + have hh := Real.tendsto_exp_neg_atTop_nhds_zero.comp + ((tendsto_natCast_atTop_atTop : Tendsto (fun n : ℕ => (n:ℝ)) atTop atTop).const_mul_atTop hc) + simpa only [Function.comp_apply,neg_mul,mul_zero] using hh.const_mul K + have hsum := hnorm.add hevent + simp only [add_zero] at hsum + apply tendsto_of_tendsto_of_tendsto_of_le_of_le' tendsto_const_nhds hsum + (Eventually.of_forall (fun _ => bot_le)) + filter_upwards [eventually_gt_atTop 0,ht.eventually (gt_mem_nhds (by positivity : (0:ℝ)<ε/2))] + with n hn hsmall + apply (measure_mono (show {g | ε ≤ |gibbsSpinFieldSquareAverage g-(β^2+β^4)|} ⊆ + {g | C < ‖Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) (sampledInteraction g)‖} ∪ + {g | ENNReal.ofReal (Real.exp (-c*n)) ≤ + gibbsEventProbability (fun x : Spin n => {h | ε/2 ≤ |spinFieldSquareAverage x h-(β^2+β^4)|}) g} from ?_)).trans + (measure_union_le _ _) + intro g hg + by_cases ha : C < ‖Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) (sampledInteraction g)‖ + · exact Or.inl ha + by_cases hb : ENNReal.ofReal (Real.exp (-c*n)) ≤ + gibbsEventProbability (fun x : Spin n => {h | ε/2 ≤ |spinFieldSquareAverage x h-(β^2+β^4)|}) g + · exact Or.inr hb + exfalso + have hp : (gibbsEventProbability (fun x : Spin n => {h | ε/2 ≤ |spinFieldSquareAverage x h-(β^2+β^4)|}) g).toReal + ≤ Real.exp (-c*n) := by + have hh := ENNReal.toReal_mono (show ENNReal.ofReal (Real.exp (-c*n))≠⊤ from ENNReal.ofReal_ne_top) + (lt_of_not_ge hb).le + simpa only [ENNReal.toReal_ofReal (Real.exp_pos _).le] using hh + have hdev := gibbsExpectation_deviation_bound g + (fun x h => spinFieldSquareAverage x h) ((β^2+β^4)) (ε/2) K (by positivity) (fun x => by + calc + _ ≤ |spinFieldSquareAverage x g|+|(β^2+β^4)| := by simpa only [sub_zero,zero_sub,abs_neg] using abs_sub_le (spinFieldSquareAverage x g) (0:ℝ) ((β^2+β^4)) + _ ≤ C^2+(β^2+β^4) := by + rw [abs_of_nonneg (by positivity : 0≤β^2+β^4)] + exact add_le_add_left ((spinFieldSquareAverage_abs_le_opNorm_sq hn x g).trans + (pow_le_pow_left₀ (norm_nonneg _) (le_of_not_gt ha) 2)) _) + change ε ≤ |gibbsExpectation (sampledInteraction g) (fun x => spinFieldSquareAverage x g)-(β^2+β^4)| at hg + have he := mul_le_mul_of_nonneg_left hp hK + linarith + +end SKGapCutoff.Regression + +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped BigOperators ENNReal Matrix.Norms.L2Operator + +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Stability/PlantedFieldCenter.lean b/lean/OAI/Probability/SKGap/Stability/PlantedFieldCenter.lean new file mode 100644 index 0000000000000000000000000000000000000000..553a0af3a758f152175e6dbdc68b9633a3c0a1ab --- /dev/null +++ b/lean/OAI/Probability/SKGap/Stability/PlantedFieldCenter.lean @@ -0,0 +1,193 @@ +import Mathlib +import OAI.Probability.SKGap.Stability.GaugedField +import OAI.Probability.SKGap.Gaussian.SubgaussianAbsTail + +namespace OAI + +section +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open scoped BigOperators +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open scoped BigOperators +open scoped BigOperators NNReal ENNReal +open MeasureTheory Metric Set +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators NNReal ENNReal Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Set +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators ENNReal NNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Matrix +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators ENNReal NNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal +namespace SKGapCutoff.Regression + +lemma continuous_gaugedField {n : ℕ} (x : Spin n) : Continuous (gaugedField x) := by + rw [show gaugedField x = fun g => gaugeFieldCLM x (fun p => sampledInteraction g p.1 p.2) by + funext g; exact (gaugeFieldCLM_sampled x g).symm] + exact (gaugeFieldCLM x).continuous.comp (continuous_pi fun p => + (continuous_apply p.2).comp ((continuous_apply p.1).comp (continuous_sampledInteraction n))) + +noncomputable def plantedFieldCenter (β : ℝ) (n : ℕ) (f : ℝ → ℝ) : ℝ := + ∫ z, f (β^2*((n:ℝ)-1)/(n:ℝ) + β*Real.sqrt (((n:ℝ)-2)/(n:ℝ))*z) + ∂gaussianReal 0 1 + +lemma planted_field_average_tail (β : ℝ) {n : ℕ} (hn : 2 ≤ n) (x : Spin n) + (f : ℝ → ℝ) {K : ℝ≥0} (hf : LipschitzWith K f) + (B : ℝ) (hB : 0 ≤ B) (hbound : ∀ z, |f z| ≤ B) + (ε : ℝ) (hε : 0 ≤ ε) : + singleSpinPlantedLaw β x {g | + ε ≤ |(∑ i : Fin n, f (gaugedField x g i))/(n:ℝ) - plantedFieldCenter β n f|} ≤ + 2 * ENNReal.ofReal (Real.exp (-(ε^2*(n:ℝ))/(8*B^2))) + + 2 * ENNReal.ofReal (Real.exp (-(ε^2*(n:ℝ))/(8*(K:ℝ)^2*β^2))) := by + let E := {v : Fin n → ℝ | + ε ≤ |(∑ i, f (v i))/(n:ℝ) - plantedFieldCenter β n f|} + have hE : MeasurableSet E := by + apply measurableSet_le measurable_const + exact (((Finset.measurable_sum _ (fun i _ => + hf.continuous.measurable.comp (measurable_pi_apply i))).div_const _).sub_const _).abs + have hl := planted_field_representation β hn x + have hh := congrArg (fun μ : Measure (Fin n → ℝ) => μ E) hl + rw [Measure.map_apply (continuous_gaugedField x).measurable hE, + Measure.map_apply (by + unfold sharedGaussianField + exact Measurable.of_eval fun i => + (measurable_const.add (measurable_const.mul (measurable_pi_apply _))).add + (measurable_const.mul (measurable_pi_apply _))) hE] at hh + change singleSpinPlantedLaw β x ((gaugedField x) ⁻¹' E) ≤ _ + rw [hh] + have ht := iid_common_shift_average_tail (n := n) (by omega) + (β^2*((n:ℝ)-1)/(n:ℝ)) (β*Real.sqrt (((n:ℝ)-2)/(n:ℝ))) + (β/Real.sqrt (n:ℝ)) f hf B hB hbound ε hε + convert ht using 1 + congr 3 + have hnR : (0:ℝ) < n := Nat.cast_pos.mpr (by omega) + rw [div_pow, Real.sq_sqrt hnR.le] + field_simp + +lemma planted_field_center_limit (β : ℝ) (f : ℝ → ℝ) (hf : Continuous f) + (B : ℝ) (hbound : ∀ z, |f z| ≤ B) : + Tendsto (fun n => plantedFieldCenter β n f) atTop + (nhds (∫ z, f (β^2+β*z) ∂gaussianReal 0 1)) := by + have hn : Tendsto (fun n : ℕ => (n:ℝ)⁻¹) atTop (nhds 0) := + tendsto_inv_atTop_zero.comp tendsto_natCast_atTop_atTop + have hfrac (c : ℝ) : Tendsto (fun n : ℕ => ((n:ℝ)-c)/(n:ℝ)) atTop (nhds 1) := by + have ht := (tendsto_const_nhds (x := (1:ℝ))).sub (hn.const_mul c) + simp only [mul_zero, sub_zero] at ht + apply ht.congr' + filter_upwards [eventually_gt_atTop 0] with n hn + have hn0 : (n:ℝ) ≠ 0 := Nat.cast_ne_zero.mpr (Nat.ne_of_gt hn) + field_simp + apply tendsto_integral_of_dominated_convergence (fun _ => B) + · intro n + exact (hf.measurable.comp (measurable_const.add (measurable_const.mul measurable_id))).aestronglyMeasurable + · exact integrable_const B + · intro n + exact Eventually.of_forall (fun z => by simpa using hbound _) + · apply Eventually.of_forall + intro z + apply hf.continuousAt.tendsto.comp + have hm : Tendsto (fun n : ℕ => β^2*((n:ℝ)-1)/(n:ℝ)) atTop (nhds (β^2)) := by + simpa only [mul_one, mul_div_assoc] using (hfrac 1).const_mul (β^2) + have ha := (Real.continuous_sqrt.continuousAt.tendsto.comp (hfrac 2)).const_mul β + simp only [Real.sqrt_one, mul_one] at ha + exact hm.add (ha.mul_const z) + +lemma planted_field_average_exponential (β : ℝ) (hβ : 0 < β) + (f : ℝ → ℝ) {K : ℝ≥0} (hK : 0 < K) (hf : LipschitzWith K f) + (B : ℝ) (hB : 0 < B) (hbound : ∀ z, |f z| ≤ B) + (ε : ℝ) (hε : 0 < ε) : + ∃ c : ℝ, 0 < c ∧ ∀ᶠ n : ℕ in atTop, ∀ x : Spin n, + singleSpinPlantedLaw β x {g | + ε ≤ |(∑ i : Fin n, f (gaugedField x g i))/(n:ℝ) - + ∫ z, f (β^2+β*z) ∂gaussianReal 0 1|} ≤ + ENNReal.ofReal (Real.exp (-c*n)) := by + let a : ℝ := (ε/2)^2/(8*B^2) + let b : ℝ := (ε/2)^2/(8*(K:ℝ)^2*β^2) + let c : ℝ := min a b / 2 + have hKr : (0:ℝ) < K := NNReal.coe_pos.mpr hK + have ha : 0 < a := by dsimp [a]; positivity + have hb : 0 < b := by dsimp [b]; positivity + have hc : 0 < c := by dsimp [c]; positivity + refine ⟨c, hc, ?_⟩ + have hcenter := tendsto_iff_norm_sub_tendsto_zero.mp + (planted_field_center_limit β f hf.continuous B hbound) + have hcenter' := hcenter.eventually_le_const (show (0:ℝ) < ε/2 by positivity) + have hlarge : ∀ᶠ n : ℕ in atTop, Real.log 4 / c ≤ (n:ℝ) := + (tendsto_natCast_atTop_atTop : Tendsto (fun n : ℕ => (n:ℝ)) atTop atTop).eventually + (eventually_ge_atTop _) + filter_upwards [eventually_ge_atTop 2, hcenter', hlarge] with n hn hcen hnlarge + intro x + have hnR : (0:ℝ) ≤ n := Nat.cast_nonneg n + have hsub : {g : GaussianCoordinates n | + ε ≤ |(∑ i : Fin n, f (gaugedField x g i))/(n:ℝ) - + ∫ z, f (β^2+β*z) ∂gaussianReal 0 1|} ⊆ + {g | ε/2 ≤ |(∑ i : Fin n, f (gaugedField x g i))/(n:ℝ) - + plantedFieldCenter β n f|} := by + intro g hg + have ht := abs_add_le + ((∑ i : Fin n, f (gaugedField x g i))/(n:ℝ) - plantedFieldCenter β n f) + (plantedFieldCenter β n f - ∫ z, f (β^2+β*z) ∂gaussianReal 0 1) + simp only [sub_add_sub_cancel] at ht + simp only [Real.norm_eq_abs] at hcen + change ε ≤ _ at hg + change ε/2 ≤ _ + linarith + apply (measure_mono hsub).trans + apply (planted_field_average_tail β hn x f hf B hB.le hbound (ε/2) (by positivity)).trans + have hca : 2*c ≤ a := by dsimp [c]; linarith [min_le_left a b] + have hcb : 2*c ≤ b := by dsimp [c]; linarith [min_le_right a b] + have h1 : Real.exp (-((ε/2)^2*(n:ℝ))/(8*B^2)) ≤ Real.exp (-2*c*n) := by + apply Real.exp_le_exp.mpr + have he : -((ε/2)^2*(n:ℝ))/(8*B^2) = -a*n := by dsimp [a]; ring + rw [he] + nlinarith [mul_le_mul_of_nonneg_right hca hnR] + have h2 : Real.exp (-((ε/2)^2*(n:ℝ))/(8*(K:ℝ)^2*β^2)) ≤ Real.exp (-2*c*n) := by + apply Real.exp_le_exp.mpr + have he : -((ε/2)^2*(n:ℝ))/(8*(K:ℝ)^2*β^2) = -b*n := by dsimp [b]; ring + rw [he] + nlinarith [mul_le_mul_of_nonneg_right hcb hnR] + have htail : 4*Real.exp (-2*c*n) ≤ Real.exp (-c*n) := by + have hlog : Real.log 4 ≤ c*n := (div_le_iff₀ hc).mp hnlarge |>.trans_eq (mul_comm _ _) + calc + _ = Real.exp (Real.log 4 + (-2*c*n)) := by + rw [Real.exp_add, Real.exp_log (by norm_num : (0:ℝ) < 4)] + _ ≤ _ := Real.exp_le_exp.mpr (by linarith) + calc + _ ≤ 2*ENNReal.ofReal (Real.exp (-2*c*n)) + + 2*ENNReal.ofReal (Real.exp (-2*c*n)) := + add_le_add (mul_le_mul' le_rfl (ENNReal.ofReal_le_ofReal h1)) + (mul_le_mul' le_rfl (ENNReal.ofReal_le_ofReal h2)) + _ = ENNReal.ofReal (4*Real.exp (-2*c*n)) := by + rw [ENNReal.ofReal_mul (by norm_num : (0:ℝ) ≤ 4)] + norm_num + ring + _ ≤ _ := ENNReal.ofReal_le_ofReal htail + +end SKGapCutoff.Regression + +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Stability/PositiveRootStability.lean b/lean/OAI/Probability/SKGap/Stability/PositiveRootStability.lean new file mode 100644 index 0000000000000000000000000000000000000000..0686fc1572c3d2375d13f76b8d63dd16b5bf8018 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Stability/PositiveRootStability.lean @@ -0,0 +1,91 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.LocalVolumeFull +import OAI.Probability.SKGap.Stability.FieldLogDet +import OAI.Probability.SKGap.Stability.FieldIntegralMeasure +import OAI.Probability.SKGap.Entropy.BadIntegralEndpoints + +namespace OAI + +section +noncomputable section +namespace SKGap +open Matrix Real Set MeasureTheory ProbabilityTheory GaussianDensity +open scoped BigOperators Matrix.Norms.Frobenius ENNReal + +theorem positive_time_root_stability {j A K t₀ T : ℝ} (hj : 0 < j) (hj1 : j < 1) + (hA : 1 ≤ A) (hsub : sqrt j*A < 1) (hK : 0 ≤ K) + (ht₀ : 0 < t₀) (hT : t₀ ≤ T) : + ∃ ε c ρ a : ℝ,0 < ε ∧ 0 < c ∧ 0 < ρ ∧ 0 < a ∧ ∃ N : ℕ,0 < N ∧ + ∀ (n : ℕ),N ≤ n → ∀ t ∈ Icc t₀ T, + ((gaussianCoordinates (MatrixCoordinates (Fin n))).prod + (Measure.pi (fun _ : Fin n=>gaussianReal 0 t.toNNReal))).real + {p | (∀ z : Field n,vectorNorm (plantedInteraction j (goeMatrix (j/(n:ℝ)) p.1)*ᵥz) ≤ K*vectorNorm z) ∧ + ∃ y : Field n, vectorNorm (tapField j (plantedInteraction j (goeMatrix (j/(n:ℝ)) p.1)) + (fun i=>t+p.2 i) y) ≤ ρ*sqrt (n:ℝ) ∧ + (goeMatrix (j/(n:ℝ)) p.1,y)∈badFieldSet n j A ε c} ≤ + 4*exp (-min 1 (1/(π^2*j))*(n:ℝ))+exp (-a*(n:ℝ)) := by + obtain ⟨m,ε,σb,a,hm,hε,hσb,ha,Nb,hbad⟩ := positive_time_bad_integral hj hj1 hA hsub ht₀ hT + have hA0 : 0 < A := zero_lt_one.trans_le hA + let r := min (ε/4) (m/(12*j*A)) + have hr : 0 < r := lt_min (by positivity) (by positivity) + have hrε : 2*r ≤ ε/2 := by have hh := min_le_left (ε/4) (m/(12*j*A));dsimp [r];linarith + have hrm : 6*j*A*r ≤ m/2 := by + have hh := (le_div_iff₀ (by positivity : 0 < 12*j*A)).mp (min_le_right (ε/4) (m/(12*j*A))) + dsimp [r] + nlinarith only [hh] + obtain ⟨ε₁,hε₁,hvol⟩ := local_volume_uniform hj.le hK hr (half_pos ha) + obtain ⟨γ,hγ,Nd,hNd,hdet⟩ := field_logdet_uniform hj hj1 hε₁ + obtain ⟨σ₀,hσ₀,hσvol⟩ := hvol γ hγ + let σ := min (σ₀/2) σb + have hσ : 0 < σ := lt_min (by positivity) hσb + have hσless : σ < σ₀ := (min_le_left _ _).trans_lt (by linarith) + have hσle : σ ≤ σb := min_le_right _ _ + obtain ⟨ρ,hρ,Nv,hNv,hv⟩ := hσvol σ hσ hσless + refine ⟨ε/2,m/2,ρ,a/2,half_pos hε,half_pos hm,hρ,half_pos ha, + max Nb (max Nd Nv),hNd.trans_le ((le_max_left _ _).trans (le_max_right _ _)),?_⟩ + intro n hn t ht + have hnb : Nb ≤ n := (le_max_left _ _).trans hn + have hnd : Nd ≤ n := (le_max_left _ _).trans ((le_max_right _ _).trans hn) + have hnv : Nv ≤ n := (le_max_right _ _).trans ((le_max_right _ _).trans hn) + have hn0 : 0 < n := hNv.trans_le hnv + let : NeZero n := ⟨Nat.ne_of_gt hn0⟩ + let μ := gaussianCoordinates (MatrixCoordinates (Fin n)) + let ν := Measure.pi (fun _ : Fin n=>gaussianReal 0 t.toNNReal) + let D : Set (MatrixCoordinates (Fin n) → ℝ) := {g | ∃ y : Field n, + (n:ℝ)*(j*varianceAverage y^2+ε₁) < + log ((fieldJacobian j (plantedInteraction j (goeMatrix (j/(n:ℝ)) g)) y)ᵀ* + fieldJacobian j (plantedInteraction j (goeMatrix (j/(n:ℝ)) g)) y+γ • 1).det} + let I : ((MatrixCoordinates (Fin n) → ℝ) × (Fin n → ℝ)) → ℝ≥0∞ := fun p=> + fieldIntegral j σ (plantedInteraction j (goeMatrix (j/(n:ℝ)) p.1)) (fun i=>t+p.2 i) + {y | (goeMatrix (j/(n:ℝ)) p.1,y)∈badFieldSet n j A ε m} + have hI : Measurable I := measurable_fieldIntegral j t σ + (badFieldFlat n j A ε m) (measurableSet_badFieldFlat _ _ _ _ _) + have hInt : ∫⁻ p,I p ∂μ.prod ν ≤ ENNReal.ofReal (exp (-a*(n:ℝ))) := by + rw [lintegral_prod _ hI.aemeasurable] + exact hbad n hnb t ht σ ⟨hσ,hσle⟩ + have hMarkov := markov_exponential (μ.prod ν) hI (b := a/2) hInt + have hrate : a-a/2=a/2 := by ring + rw [hrate] at hMarkov + have hDP : (μ.prod ν).real (D ×ˢ (Set.univ : Set (Fin n → ℝ))) ≤ + 4*exp (-min 1 (1/(π^2*j))*(n:ℝ)) := by + rw [measureReal_prod_prod] + simp only [Measure.real,measure_univ,ENNReal.toReal_one,mul_one] + exact hdet n hnd + apply measureReal_union_detector (μ.prod ν) _ (D ×ˢ Set.univ) I + (exp (-(a/2)*(n:ℝ))) _ _ hDP hMarkov + rintro p ⟨hJ,y,hres,hy⟩ hp + have hp' : p.1∉D := fun hh=>hp ⟨hh,mem_univ _⟩ + dsimp [I] + rw [fieldIntegral_eq_localVolume hσ] + apply hv n hnv _ hJ _ y + {z | (goeMatrix (j/(n:ℝ)) p.1,z)∈badFieldSet n j A ε m} + · exact measurableSet_badField_section j A ε m _ + · intro d hd + exact badField_neighborhood hn0 hj.le hA0.le hε hr.le hrε hrm _ y d hy hd + · exact not_lt.mp (fun hh=>hp' ⟨y,hh⟩) + · exact hres +end SKGap +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Stability/QuenchedStableFields.lean b/lean/OAI/Probability/SKGap/Stability/QuenchedStableFields.lean new file mode 100644 index 0000000000000000000000000000000000000000..faab73721ff3ca30c501d317f2ca0fcedf0f2164 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Stability/QuenchedStableFields.lean @@ -0,0 +1,69 @@ +import Mathlib +import OAI.Probability.SKGap.Brownian.ObservationPathEstimate +import OAI.Probability.SKGap.Localization.OperatorQuenched + +namespace OAI + +section + +noncomputable section +namespace SKGap.ObservationBridge +open Matrix Real Set MeasureTheory ProbabilityTheory Filter +open scoped BigOperators ENNReal NNReal Topology +variable {Ω : Type*} [MeasurableSpace Ω] {n : ℕ} + +def rawPathFailure (P : Measure Ω) (B : ℝ≥0→Ω→ℝ) + (j A ε c ρ T : ℝ) (J : Disorder n) : ℝ := + ∑ σ : Spin n,mass J 0 σ*(Measure.pi (fun _ : Fin n=>P)).real + {ω | ∃ t : ℝ≥0,(t:ℝ)≤T ∧ rootBad j A ε c ρ (coupling J) (observationField B σ t ω)} + +lemma rawPathFailure_eq (P : Measure Ω) (B : ℝ≥0→Ω→ℝ) + (j A K ε c ρ T : ℝ) (J : Disorder n) (hJ : operatorBound K (coupling J)) : + rawPathFailure P B j A ε c ρ T J=pathFailure P B j A K ε c ρ T J := by + simp only [rawPathFailure,pathFailure,conditionalPathFailure,hJ,true_and] + +theorem quenched_stable_fields + {P : Measure Ω} {B : ℝ≥0→Ω→ℝ} + (hB : IsBrownianReal B P) {β T : ℝ} (hβ : 0<β) (hβ1 : β<1) (hT : 0(disorderLaw β n).real (G n)) atTop (𝓝 1) ∧ + ∀ n, ∀ J ∈ G n,operatorBound K (coupling J) ∧ + rawPathFailure P B (β^2) A ε c ρ T J ≤ exp (-a*(n:ℝ)) := by + obtain ⟨A,K,ε,c,ρ,a,hA,hK,hsub,hε,hc,hρ,ha,V,hVm,hVn,hVp,hVt⟩ := + quenched_observation_path_stability hB hβ hβ1 hT + let G : (n : ℕ)→Set (Disorder n) := fun n=> + {J | operatorBound K (coupling J) ∧ V n J ≤ exp (-a*(n:ℝ))} + have hnormMeas (n : ℕ) : MeasurableSet {J : Disorder n | operatorBound K (coupling J)} := by + exact ((isClosed_operatorBound K).preimage continuous_coupling).measurableSet + have hGm (n : ℕ) : MeasurableSet (G n) := + (hnormMeas n).inter (measurableSet_le (hVm n) measurable_const) + have hcompl (n : ℕ) : (G n)ᶜ = {J | ¬operatorBound K (coupling J)}∪ + {J | exp (-a*(n:ℝ))(disorderLaw β n).real (G n)ᶜ) atTop (𝓝 0) := by + apply squeeze_zero (fun n=>measureReal_nonneg) + (fun n=>?_) + (by simpa only [add_zero] using (quenched_operator_bound hβ hK).add hVt) + rw [hcompl] + exact measureReal_union_le _ _ + refine ⟨A,K,ε,c,ρ,a,hA,hK,hsub,hε,hc,hρ,ha,G,hGm,?_,?_⟩ + · have hh : Tendsto (fun n=>1-(disorderLaw β n).real (G n)ᶜ) atTop (𝓝 (1-0)) := + tendsto_const_nhds.sub hbad + have he (n : ℕ) : (disorderLaw β n).real (G n)=1-(disorderLaw β n).real (G n)ᶜ := by + rw [measureReal_compl (hGm n),probReal_univ] + ring + simpa only [sub_zero,←he] using hh + · intro n J hJ + refine ⟨hJ.1,?_⟩ + rw [rawPathFailure_eq P B (β^2) A K ε c ρ T J hJ.1] + exact (hVp n J).trans hJ.2 +end SKGap.ObservationBridge + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Stability/ResidualRoot.lean b/lean/OAI/Probability/SKGap/Stability/ResidualRoot.lean new file mode 100644 index 0000000000000000000000000000000000000000..d2344347891cdfeb11ee15f39db929c8b7edd3c2 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Stability/ResidualRoot.lean @@ -0,0 +1,140 @@ +import Mathlib +import OAI.Probability.SKGap.Stability.TapFieldE +import OAI.Probability.SKGap.Localization.SmoothSelection + +namespace OAI + +section + +noncomputable section +open scoped BigOperators +namespace SKGapCutoff.Recipe +open Primary Static Matrix +variable {n : ℕ} + +lemma primary_onsager_tap (hn : 0j*onsager j J h (k+1) x*(Primary.residual j J h k x i+Primary.residual j J h (k+1) x i))+ + (fun i=>j*(onsager j J h (k+2) x-onsager j J h (k+1) x)*mag j J h (k+2) x i) := by + ext i + simp only [SKGap.tapField,primary_onsager_tap hn,SKGap.magnetization,←mag_succ, + Pi.add_apply,Pi.sub_apply,Matrix.mulVec,dotProduct] + rw [fld_eq] + simp only [Nat.add_sub_cancel,Primary.residual,mul_sub,Finset.sum_sub_distrib] + ring + +lemma onsager_residual_difference (hn : 0mag j J h k x i+mag j J h (k+1) x i)≤2*Real.sqrt (n:ℝ) := by + exact (SKGap.vectorNorm_add_le _ _).trans + ((add_le_add (mag_vectorNorm j J h k x) (mag_vectorNorm j J h (k+1) x)).trans_eq (by ring)) + have hp := (SKGap.vector_dot_abs_le (Primary.residual j J h k x) + (fun i=>mag j J h k x i+mag j J h (k+1) x i)).trans + (mul_le_mul_of_nonneg_left hv (vectorNorm_nonneg _)) + rw [hd,abs_div,abs_of_pos hnR] + rw [div_mul_eq_mul_div] + apply (div_le_iff₀ hnR).mpr + convert mul_le_mul_of_nonneg_right hp (Real.sqrt_nonneg (n:ℝ)) using 1 + simp only [SKGap.vectorNorm,vectorNorm] + ring_nf + rw [Real.sq_sqrt hnR.le] + +lemma primary_tap_norm (hn : 0j*onsager j J h (k+1) x* + (Primary.residual j J h k x i+Primary.residual j J h (k+1) x i))≤ + j*(vectorNorm (Primary.residual j J h k x)+vectorNorm (Primary.residual j J h (k+1) x)) := by + rw [show vectorNorm (fun i=>j*onsager j J h (k+1) x* + (Primary.residual j J h k x i+Primary.residual j J h (k+1) x i))= + |j*onsager j J h (k+1) x| *vectorNorm (Primary.residual j J h k x+Primary.residual j J h (k+1) x) from SKGap.vectorNorm_smul .., + abs_of_nonneg (mul_nonneg hj hb.1)] + exact mul_le_mul (mul_le_of_le_one_right hj hb.2) (SKGap.vectorNorm_add_le _ _) (vectorNorm_nonneg _) hj + have hlast : vectorNorm (fun i=>j*(onsager j J h (k+2) x-onsager j J h (k+1) x)*mag j J h (k+2) x i)≤ + 2*j*vectorNorm (Primary.residual j J h (k+1) x) := by + rw [show vectorNorm (fun i=>j*(onsager j J h (k+2) x-onsager j J h (k+1) x)*mag j J h (k+2) x i)= + |j*(onsager j J h (k+2) x-onsager j J h (k+1) x)| *vectorNorm (mag j J h (k+2) x) from SKGap.vectorNorm_smul .., + abs_mul,abs_of_nonneg hj] + calc + _ ≤ j*|onsager j J h (k+2) x-onsager j J h (k+1) x| *Real.sqrt (n:ℝ) := + mul_le_mul_of_nonneg_left (mag_vectorNorm j J h (k+2) x) (by positivity) + _ ≤ j*(2*vectorNorm (Primary.residual j J h (k+1) x)) := by + rw [mul_assoc] + exact mul_le_mul_of_nonneg_left (onsager_residual_difference hn j J h (k+1) x) hj + _ = _ := by ring + rw [primary_tap_residual hn] + exact (SKGap.vectorNorm_add_le _ _).trans ((add_le_add + ((SKGap.vectorNorm_sub_le _ _).trans (add_le_add + ((vectorNorm_matrix_mul _ _).trans (mul_le_mul_of_nonneg_right hJ (vectorNorm_nonneg _))) + hterm)) hlast).trans_eq (by ring)) + +lemma magnetization_vector_lipschitz (y r : Fin n→ℝ) : + vectorNorm (SKGap.magnetization y-SKGap.magnetization r)≤vectorNorm (y-r) := by + apply (sq_le_sq₀ (vectorNorm_nonneg _) (vectorNorm_nonneg _)).mp + simp only [vectorNorm_sq,Pi.sub_apply,SKGap.magnetization] + exact Finset.sum_le_sum fun i _=>by + simpa only [sq_abs] using pow_le_pow_left₀ (abs_nonneg _) (tanh_lipschitz (r i) (y i)) 2 + +theorem selected_tap_root (hn : 0?_⟩ + obtain ⟨h0,h1⟩:=residualCutoff_support hn hρ J h k x hcut + have hnorm : vectorNorm (SKGap.tapField j J h (fld j J h (k+1) x))≤ + (K+4*j)*ρ*Real.sqrt (n:ℝ) := by + exact (primary_tap_norm hn hj hK J h k x hop).trans + ((add_le_add (mul_le_mul_of_nonneg_left h0 hj) + (mul_le_mul_of_nonneg_left h1 (by positivity))).trans_eq (by ring)) + have hnear : vectorNorm (SKGap.tapField j J h (fld j J h (k+1) x))(ha i).1) (fun i=>(ha i).2) hd + have hv : vectorSqNorm x.ofLp=1 := by + rw [← vectorNorm_sq] + change ‖x‖^2=1 + rw [hx];norm_num + rw [hv,mul_one] at hdiff + linarith only [le_abs_self (quadraticForm (fieldHessian j (J+diagonal d) y a) x.ofLp- + quadraticForm (fieldHessian j J y a) x.ofLp),hdiff,hq] + +lemma rootBad_mono {n : ℕ} {j A ε c c' ρ ρ' : ℝ} + (hc : c ≤ c') (hρ : ρ ≤ ρ') (J : Matrix (Fin n) (Fin n) ℝ) (h : Field n) : + rootBad j A ε c ρ J h → rootBad j A ε c' ρ' J h := by + rintro ⟨y,hy,a,ha,hd,x,hx,hq⟩ + exact ⟨y,hy.trans (mul_le_mul_of_nonneg_right hρ (sqrt_nonneg _)),a,ha,hd,x,hx,hq.trans hc⟩ + +def eraseDiagonal {n : ℕ} (J : Matrix (Fin n) (Fin n) ℝ) : Matrix (Fin n) (Fin n) ℝ := + J-diagonal (fun i=>J i i) + +lemma eraseDiagonal_add {n : ℕ} (J : Matrix (Fin n) (Fin n) ℝ) : + eraseDiagonal J+diagonal (fun i=>J i i)=J := sub_add_cancel _ _ + +lemma eraseDiagonal_diag {n : ℕ} (J : Matrix (Fin n) (Fin n) ℝ) (i : Fin n) : + eraseDiagonal J i i=0 := by simp [eraseDiagonal] + +lemma erased_planted_witness {n : ℕ} {j A K ε c ρ δ : ℝ} + (hA : 0 ≤ A) (hδ : 0 ≤ δ) (hδρ : δ ≤ ρ/2) (hδc : A*δ ≤ c/2) + (t : ℝ) (g : MatrixCoordinates (Fin n)→ℝ) (b : Field n) + (hd : ∀ i,|plantedInteraction j (goeMatrix (j/(n:ℝ)) g) i i| ≤ δ) + (hJ : ∀ z : Field n,vectorNorm ((eraseDiagonal (plantedInteraction j (goeMatrix (j/(n:ℝ)) g)))*ᵥz) ≤ + (K-δ)*vectorNorm z) + (hbad : rootBad j A ε (c/2) (ρ/2) + (eraseDiagonal (plantedInteraction j (goeMatrix (j/(n:ℝ)) g))) (fun i=>t+b i)) : + (g,b)∈plantedRootBad n j A K ε c ρ t := by + let J := plantedInteraction j (goeMatrix (j/(n:ℝ)) g) + have hjnorm := mulvec_add_diagonal_bound hδ (eraseDiagonal J) (fun i=>J i i) hJ hd + rw [eraseDiagonal_add] at hjnorm + have hjnorm' : ∀ z : Field n, vectorNorm (J*ᵥz) ≤ K*vectorNorm z := by + simpa only [sub_add_cancel] using hjnorm + have hh := rootBad_diagonal_transfer hA hδ (eraseDiagonal J) (fun i=>t+b i) (fun i=>J i i) hd hbad + rw [eraseDiagonal_add] at hh + obtain ⟨y,hy,a,ha,hdist,x,hx,hq⟩ := rootBad_mono (by linarith : c/2+A*δ ≤ c) + (by linarith : ρ/2+δ ≤ ρ) J (fun i=>t+b i) hh + exact ⟨hjnorm',y,hy,a,ha,hdist,x,hx,hq⟩ +end SKGap +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Stability/RootFieldTransfer.lean b/lean/OAI/Probability/SKGap/Stability/RootFieldTransfer.lean new file mode 100644 index 0000000000000000000000000000000000000000..6a98254a72057cced03163f0aa859703144eb595 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Stability/RootFieldTransfer.lean @@ -0,0 +1,41 @@ +import Mathlib +import OAI.Probability.SKGap.Stability.RootDiagonalTransfer + +namespace OAI + +section + +noncomputable section +namespace SKGap.ObservationBridge +open MeasureTheory ProbabilityTheory Matrix Real Set +open scoped BigOperators +variable {n : ℕ} + +lemma tapField_field_difference (j : ℝ) (J : Matrix (Fin n) (Fin n) ℝ) + (h h' y : Field n) : tapField j J h' y=tapField j J h y+(h-h') := by + ext i + simp only [tapField,Pi.add_apply,Pi.sub_apply] + ring + +lemma rootBad_field_transfer {j A ε c ρ κ : ℝ} + (J : Matrix (Fin n) (Fin n) ℝ) (h h' : Field n) + (hd : vectorNorm (h-h') ≤ κ*sqrt (n:ℝ)) : + rootBad j A ε c ρ J h → rootBad j A ε c (ρ+κ) J h' := by + rintro ⟨y,hy,a,ha,hdist,x,hx,hq⟩ + refine ⟨y,?_,a,ha,hdist,x,hx,hq⟩ + rw [tapField_field_difference] + exact (vectorNorm_add_le _ _).trans ((add_le_add hy hd).trans_eq (by ring)) + +theorem rootBad_mesh_transfer {ι τ : Type*} (mesh : ι→τ) (h : τ→Field n) + (j A ε c ρ κ : ℝ) (J : Matrix (Fin n) (Fin n) ℝ) + (hcover : ∀ t : τ, ∃ k : ι,vectorNorm (h t-h (mesh k)) ≤ κ*sqrt (n:ℝ)) : + (∃ t,rootBad j A ε c ρ J (h t)) → ∃ k,rootBad j A ε c (ρ+κ) J (h (mesh k)) := by + rintro ⟨t,ht⟩ + obtain ⟨k,hk⟩ := hcover t + exact ⟨k,rootBad_field_transfer J (h t) (h (mesh k)) hk ht⟩ +end SKGap.ObservationBridge + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Stability/RootGrid.lean b/lean/OAI/Probability/SKGap/Stability/RootGrid.lean new file mode 100644 index 0000000000000000000000000000000000000000..2d660fb5910258312c7eae10ef863d754ffc4284 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Stability/RootGrid.lean @@ -0,0 +1,67 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.FixedTimeQuenched +import OAI.Probability.SKGap.Localization.OperatorQuenched +import OAI.Probability.SKGap.Localization.GridSteps +import OAI.Probability.SKGap.Localization.QuenchedHelpers + +namespace OAI + +namespace SKGap.FullMain +open MeasureTheory ProbabilityTheory Filter Real Set ObservationBridge GaussianHistory +open scoped Topology BigOperators ENNReal +noncomputable section + +def gridFailure (n : ℕ) (j A K ε c ρ T : ℝ) (g : Disorder n) : ℝ := + ∑k∈Finset.range (gridSteps n+1),fixedTimeFailure n j A K ε c ρ ((k:ℝ)*gridStep T n) g + +lemma gridFailure_nonneg (n : ℕ) (j A K ε c ρ T : ℝ) (g : Disorder n) : + 0≤gridFailure n j A K ε c ρ T g := + Finset.sum_nonneg (fun step _=>fixedTimeFailure_nonneg n j A K ε c ρ ((step:ℝ)*gridStep T n) g) + +lemma weighted_gridFailure_integrable (β : ℝ) (n : ℕ) (A K ε c ρ T : ℝ) : + Integrable (fun g=>partitionSizeBias β n g*gridFailure n (β^2) A K ε c ρ T g) (disorderLaw β n) := by + simp only [gridFailure,Finset.mul_sum] + exact integrable_finsetSum _ (fun k _=>weighted_fixedTimeFailure_integrable _ _ _ _ _ _ _ _ _) + +lemma grid_time_mem {T : ℝ} (hT : 0≤T) {n k : ℕ} (hk : k≤gridSteps n) : + (k:ℝ)*gridStep T n∈Icc 0 T := by + have ht:=gridStep_nonneg hT n + refine ⟨mul_nonneg (Nat.cast_nonneg _) ht,?_⟩ + exact (mul_le_mul_of_nonneg_right (by exact_mod_cast hk) ht).trans_eq (grid_total T n) + +theorem quenched_grid_root_stability {β T : ℝ} (hβ : 0<β) (hβ1 : β<1) (hT : 0operatorBound K (coupling g) ∧ + gridFailure n (β^2) A K ε c ρ T g≤exp (-a*(n:ℝ))) := by + obtain ⟨A,K,ε,c,ρ,a,hA,hK,hs,hε,hc,hρ,ha,N,hN,hann⟩:= + annealed_fixed_time_root_stability hβ hβ1 hT + have hsum : ∀ᶠ n:ℕ in atTop, + (∫g,partitionSizeBias β n g*gridFailure n (β^2) A K ε c ρ T g ∂disorderLaw β n)≤ + exp (-(a/2)*(n:ℝ)) := by + filter_upwards [eventually_ge_atTop N,grid_exp_absorb ha] with n hn he + simp only [gridFailure,Finset.mul_sum] + rw [integral_finsetSum _ (fun k _=>weighted_fixedTimeFailure_integrable _ _ _ _ _ _ _ _ _)] + have he' : (∑_k∈Finset.range (gridSteps n+1),exp (-a*(n:ℝ)))≤exp (-(a/2)*(n:ℝ)) := by + simpa only [Finset.sum_const,Finset.card_range,nsmul_eq_mul,Nat.cast_add,Nat.cast_one] using he + apply le_trans (Finset.sum_le_sum (fun k hk=>?_)) he' + have hk' : k≤gridSteps n:=by have:=Finset.mem_range.mp hk;omega + exact weighted_fixedTimeFailure_integral_bound β n A K ε c ρ ((k:ℝ)*gridStep T n) _ + (exp_pos _).le (hann n hn _ (grid_time_mem hT.le hk')) + have hp : Whp β (fun n g=>gridFailure n (β^2) A K ε c ρ T g≤exp (-((a/2)/4)*(n:ℝ))) := by + apply (whp_iff_real _ _).mpr + simp only [not_le] + apply exponential_size_bias_transfer (C:=1) (disorderLaw β) (partitionSizeBias β) + (fun n=>gridFailure n (β^2) A K ε c ρ T) + (fun n g=>(partitionSizeBias_pos β n g).le) + (fun n g=>gridFailure_nonneg _ _ _ _ _ _ _ _ _) (fun n=>weighted_gridFailure_integrable _ _ _ _ _ _ _ _) + (half_pos ha) zero_le_one + · exact disorder_partition_lower_tail hβ hβ1 (by positivity) + · simpa only [one_mul] using hsum + have hop : Whp β (fun n g=>operatorBound K (coupling g)):= + (whp_iff_real _ _).mpr (quenched_operator_bound hβ hK) + exact ⟨A,K,ε,c,ρ,(a/2)/4,hA,hK,hs,hε,hc,hρ,by positivity,hop.and hp⟩ + +end +end SKGap.FullMain + +end OAI diff --git a/lean/OAI/Probability/SKGap/Stability/SmallRootStability.lean b/lean/OAI/Probability/SKGap/Stability/SmallRootStability.lean new file mode 100644 index 0000000000000000000000000000000000000000..161df38dbd7697964f83742d3502845ff6076932 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Stability/SmallRootStability.lean @@ -0,0 +1,87 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.LocalVolumeFull +import OAI.Probability.SKGap.Stability.FieldLogDet +import OAI.Probability.SKGap.Stability.FieldIntegralMeasure +import OAI.Probability.SKGap.Entropy.BadIntegralEndpoints +import OAI.Probability.SKGap.Localization.SmallOverlap + +namespace OAI + +section +noncomputable section +namespace SKGap +open Matrix Real Set MeasureTheory ProbabilityTheory GaussianDensity +open scoped BigOperators Matrix.Norms.Frobenius ENNReal + +theorem small_time_root_stability {j A K q₀ c : ℝ} (hj : 0 < j) (hj1 : j < 1) + (hA : 1 ≤ A) (hK : 0 ≤ K) (hKj : 0 ≤ K-j) (hq₀ : 0 < q₀) + (hmargin : c < 1-A*(K-j+6*j*q₀)) : + ∃ t₀ ρ a : ℝ,0 < t₀ ∧ 0 < ρ ∧ 0 < a ∧ ∃ N : ℕ,0 < N ∧ + ∀ (n : ℕ),N ≤ n → ∀ t ∈ Icc 0 t₀, ∀ ε : ℝ, + ((gaussianCoordinates (MatrixCoordinates (Fin n))).prod + (Measure.pi (fun _ : Fin n=>gaussianReal 0 t.toNNReal))).real + {p | (∀ z : Field n,vectorNorm (plantedInteraction j (goeMatrix (j/(n:ℝ)) p.1)*ᵥz) ≤ K*vectorNorm z) ∧ + ∃ y : Field n, vectorNorm (tapField j (plantedInteraction j (goeMatrix (j/(n:ℝ)) p.1)) + (fun i=>t+p.2 i) y) ≤ ρ*sqrt (n:ℝ) ∧ + (goeMatrix (j/(n:ℝ)) p.1,y)∈badFieldSet n j A ε c} ≤ + 4*exp (-min 1 (1/(π^2*j))*(n:ℝ))+exp (-a*(n:ℝ)) := by + obtain ⟨t₀,σb,a,ht₀,hσb,ha,Nb,hbad⟩ := smalltime_bad_integral hj hj1 hq₀ + let r := q₀/2 + have hr : 0 < r := half_pos hq₀ + have hrq : 2*r ≤ q₀ := by dsimp [r];linarith + obtain ⟨ε₁,hε₁,hvol⟩ := local_volume_uniform hj.le hK hr (half_pos ha) + obtain ⟨γ,hγ,Nd,hNd,hdet⟩ := field_logdet_uniform hj hj1 hε₁ + obtain ⟨σ₀,hσ₀,hσvol⟩ := hvol γ hγ + let σ := min (σ₀/2) σb + have hσ : 0 < σ := lt_min (by positivity) hσb + have hσless : σ < σ₀ := (min_le_left _ _).trans_lt (by linarith) + have hσle : σ ≤ σb := min_le_right _ _ + obtain ⟨ρ,hρ,Nv,hNv,hv⟩ := hσvol σ hσ hσless + refine ⟨t₀,ρ,a/2,ht₀,hρ,half_pos ha, + max Nb (max Nd Nv),hNd.trans_le ((le_max_left _ _).trans (le_max_right _ _)),?_⟩ + intro n hn t ht ε + have hnb : Nb ≤ n := (le_max_left _ _).trans hn + have hnd : Nd ≤ n := (le_max_left _ _).trans ((le_max_right _ _).trans hn) + have hnv : Nv ≤ n := (le_max_right _ _).trans ((le_max_right _ _).trans hn) + have hn0 : 0 < n := hNv.trans_le hnv + let : NeZero n := ⟨Nat.ne_of_gt hn0⟩ + let μ := gaussianCoordinates (MatrixCoordinates (Fin n)) + let ν := Measure.pi (fun _ : Fin n=>gaussianReal 0 t.toNNReal) + let D : Set (MatrixCoordinates (Fin n) → ℝ) := {g | ∃ y : Field n, + (n:ℝ)*(j*varianceAverage y^2+ε₁) < + log ((fieldJacobian j (plantedInteraction j (goeMatrix (j/(n:ℝ)) g)) y)ᵀ* + fieldJacobian j (plantedInteraction j (goeMatrix (j/(n:ℝ)) g)) y+γ • 1).det} + let I : ((MatrixCoordinates (Fin n) → ℝ) × (Fin n → ℝ)) → ℝ≥0∞ := fun p=> + fieldIntegral j σ (plantedInteraction j (goeMatrix (j/(n:ℝ)) p.1)) (fun i=>t+p.2 i) + {y | q₀ ≤ overlap y} + have hE : MeasurableSet {y : Field n | q₀ ≤ overlap y} := + (isClosed_le continuous_const (by unfold overlap magnetization;fun_prop)).measurableSet + have hI : Measurable I := measurable_fieldIntegral_cylinder j t σ _ hE + have hInt : ∫⁻ p,I p ∂μ.prod ν ≤ ENNReal.ofReal (exp (-a*(n:ℝ))) := by + rw [lintegral_prod _ hI.aemeasurable] + exact hbad n hnb t ht σ ⟨hσ,hσle⟩ + have hMarkov := markov_exponential (μ.prod ν) hI (b := a/2) hInt + have hrate : a-a/2=a/2 := by ring + rw [hrate] at hMarkov + have hDP : (μ.prod ν).real (D ×ˢ (Set.univ : Set (Fin n → ℝ))) ≤ + 4*exp (-min 1 (1/(π^2*j))*(n:ℝ)) := by + rw [measureReal_prod_prod] + simp only [Measure.real,measure_univ,ENNReal.toReal_one,mul_one] + exact hdet n hnd + apply measureReal_union_detector (μ.prod ν) _ (D ×ˢ Set.univ) I + (exp (-(a/2)*(n:ℝ))) _ _ hDP hMarkov + rintro p ⟨hJ,y,hres,hy⟩ hp + have hp' : p.1∉D := fun hh=>hp ⟨hh,mem_univ _⟩ + dsimp [I] + rw [fieldIntegral_eq_localVolume hσ] + apply hv n hnv _ hJ _ y {z | q₀ ≤ overlap z} hE + · intro d hd + exact overlap_neighborhood hn0 hrq y d + (badField_small_overlap_impossible hn0 hj.le (zero_le_one.trans hA) hKj hmargin _ y hJ hy) hd + · exact not_lt.mp (fun hh=>hp' ⟨y,hh⟩) + · exact hres +end SKGap +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Stability/StabilityMatrix.lean b/lean/OAI/Probability/SKGap/Stability/StabilityMatrix.lean new file mode 100644 index 0000000000000000000000000000000000000000..27e632470fa49c459ebb5581fd6941adc52d9f5b --- /dev/null +++ b/lean/OAI/Probability/SKGap/Stability/StabilityMatrix.lean @@ -0,0 +1,157 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.DiagonalSum +import OAI.Probability.SKGap.Matrix.MatrixQuad + +namespace OAI + +section +noncomputable section +open MeasureTheory ProbabilityTheory InformationTheory Real Set +open scoped NNReal ENNReal +open Filter +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius ENNReal NNReal +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius NNReal +noncomputable section +open MeasureTheory ProbabilityTheory Real Set Filter +open MeasureTheory.Measure +open scoped ENNReal NNReal MeasureTheory Topology +open MeasureTheory +noncomputable section +noncomputable section +open MeasureTheory Set NormedSpace +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius +noncomputable section +open Set Real +open scoped Topology +noncomputable section +open Matrix Set Filter +open scoped Topology Matrix.Norms.Frobenius +noncomputable section +open Matrix NormedSpace ContinuousLinearMap +open scoped Matrix.Norms.Frobenius +noncomputable section +open Matrix +noncomputable section +open MeasureTheory ProbabilityTheory Real Set +open scoped ENNReal NNReal +noncomputable section +open MeasureTheory ProbabilityTheory InformationTheory Real Set +open scoped NNReal ENNReal +noncomputable section +open scoped BigOperators +open MeasureTheory ProbabilityTheory +open Real +noncomputable section +open scoped BigOperators Topology +open Filter Real +namespace SKGap +section GOEPath +variable {ι : Type*} [Fintype ι] [DecidableEq ι] + +def stabilityMatrix (a : ι → ℝ) (z q : ℝ) (M : Matrix ι ι ℝ) : Matrix ι ι ℝ := + fun i k => (if i = k then 1 + z^2*q*a i else 0) - z*sqrt (a i)*M i k*sqrt (a k) + +lemma stabilityMatrix_quad (a : ι → ℝ) (ha : ∀ i, 0 ≤ a i) (z q : ℝ) + (M : Matrix ι ι ℝ) (p : EuclideanSpace ℝ ι) : + matrixQuad (stabilityMatrix a z q M) p = + ‖p‖^2 + z^2*q*‖diagonalSqrt a p‖^2 - z*matrixQuad M (diagonalSqrt a p) := by + rw [diagonalSqrt_norm_sq a ha, ← sum_coord_sq p] + simp only [matrixQuad, stabilityMatrix, mul_sub, sub_mul, Finset.sum_sub_distrib] + congr 1 + · simp only [mul_ite, ite_mul, mul_zero, zero_mul, Finset.mul_sum, ← Finset.sum_add_distrib] + apply Finset.sum_congr rfl + intro i _ + rw [Finset.sum_ite_eq] + simp only [Finset.mem_univ, ite_true] + ring + · simp only [Finset.mul_sum, diagonalSqrt] + apply Finset.sum_congr rfl + intro i _ + apply Finset.sum_congr rfl + intro k _ + ring + +omit [Fintype ι] in +lemma stabilityMatrix_symm {M : Matrix ι ι ℝ} (hM : M.IsHermitian) + (a : ι → ℝ) (z q : ℝ) : (stabilityMatrix a z q M).IsHermitian := by + ext i k + have hmk : M k i = M i k := by simpa using congrFun (congrFun hM i) k + simp only [Matrix.conjTranspose_apply, star_trivial, stabilityMatrix, hmk] + by_cases h : i = k + · subst k; rfl + · simp only [h, Ne.symm h, ↓reduceIte] + ring + +lemma diagonalProcess_coercive {r z q c : ℝ} {a : ι → ℝ} + (ha : ∀ i, 0 ≤ a i) {g : MatrixCoordinates ι → ℝ} + (hg : diagonalProcess r a z q g ≤ 1-c) (p : EuclideanSpace ℝ ι) : + c*‖p‖^2 ≤ matrixQuad (stabilityMatrix a z q (goeMatrix r g)) p := by + by_cases hp : p = 0 + · simp [hp, matrixQuad] + have hp0 : 0 < ‖p‖ := norm_pos_iff.mpr hp + let v : EuclideanSpace ℝ ι := ‖p‖⁻¹ • p + have hv : ‖v‖ = 1 := by + dsimp [v] + rw [norm_smul, Real.norm_eq_abs, abs_inv, abs_of_pos hp0, inv_mul_cancel₀ hp0.ne'] + let v' : UnitBall ι := ⟨v, by simp [Metric.mem_closedBall, hv]⟩ + have h := (gaussianAffine_le_gaussianSup (continuous_diagonalOffset a z q) + (continuous_diagonalCoeff (continuous_quadraticCoeff r) a z) g v').trans hg + rw [diagonal_affine_matrix] at h + have hs := stabilityMatrix_quad a ha z q (goeMatrix r g) v + change z*matrixQuad (goeMatrix r g) (diagonalSqrt a v) - + z^2*q*‖diagonalSqrt a v‖^2 ≤ 1-c at h + rw [hv, one_pow] at hs + have hc : c ≤ matrixQuad (stabilityMatrix a z q (goeMatrix r g)) v := by linarith + rw [show v = ‖p‖⁻¹ • p from rfl, matrixQuad_smul] at hc + have hc' : c ≤ matrixQuad (stabilityMatrix a z q (goeMatrix r g)) p / ‖p‖^2 := by + simpa only [inv_pow, div_eq_mul_inv, mul_comm] using hc + exact (le_div_iff₀ (sq_pos_of_pos hp0)).mp hc' + +variable [Nonempty ι] + +theorem goe_diagonal_matrix_path_tail {j A : ℝ} {a : ι → ℝ} + (hj : 0 < j) (hA0 : 0 < A) (ha : ∀ i, 0 ≤ a i) (hA : ∀ i, a i ≤ A) + (hsub : sqrt j*A < 1) + (herr : 2*sqrt A*sqrt (sqrt (2*j^2*A^2/(Fintype.card ι:ℝ))) ≤ + (1-sqrt j*A)^2/4) : + (gaussianCoordinates (MatrixCoordinates ι)).real + {g | ∃ z ∈ Icc (0:ℝ) 1, ∃ p : EuclideanSpace ℝ ι, + matrixQuad (stabilityMatrix a z ((j/(Fintype.card ι:ℝ))*∑ i, a i) + (goeMatrix (j/(Fintype.card ι:ℝ)) g)) p < (1-sqrt j*A)^2/2 * ‖p‖^2} ≤ + Real.exp (-((1-sqrt j*A)^2)^2 * (Fintype.card ι:ℝ) / (16*π^2*j*A^2)) := by + apply (measureReal_mono ?_).trans (scaled_diagonal_path_tail hj hA0 ha hA hsub herr) + rintro g ⟨z, hz, p, hp⟩ + refine ⟨z, hz, ?_⟩ + by_contra hh + have hc := diagonalProcess_coercive ha (le_of_not_gt hh) p + exact (not_lt_of_ge hc) hp + +end GOEPath +end SKGap + +end +end +end +end +end +end +end +end +end +end +end +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Stability/StableFields.lean b/lean/OAI/Probability/SKGap/Stability/StableFields.lean new file mode 100644 index 0000000000000000000000000000000000000000..0098884af281e464093e4000c3f70095849fb076 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Stability/StableFields.lean @@ -0,0 +1,486 @@ +import Mathlib +import OAI.Probability.SKGap.Model + +namespace OAI + +section + +noncomputable section +open scoped BigOperators +open Real Matrix +namespace SKGap + +abbrev Field (n : ℕ) := Fin n → ℝ + +def magnetization {n : ℕ} (y : Field n) : Field n := fun i => tanh (y i) +def overlap {n : ℕ} (y : Field n) : ℝ := (∑ i, magnetization y i ^ 2) / n +def onsager {n : ℕ} (j : ℝ) (y : Field n) : ℝ := j * (1 - overlap y) +def spinVariance {n : ℕ} (y : Field n) : Field n := fun i => 1 - magnetization y i ^ 2 + +def tapField {n : ℕ} (j : ℝ) (J : Matrix (Fin n) (Fin n) ℝ) + (h y : Field n) : Field n := fun i => + y i - h i + onsager j y * magnetization y i - ∑ k, J i k * magnetization y k + +def hessianCore {n : ℕ} (j : ℝ) (J : Matrix (Fin n) (Fin n) ℝ) + (y : Field n) : Matrix (Fin n) (Fin n) ℝ := fun i k => + onsager j y * (if i = k then 1 else 0) - J i k - + (2 * j / n) * magnetization y i * magnetization y k + +def fieldHessian {n : ℕ} (j : ℝ) (J : Matrix (Fin n) (Fin n) ℝ) + (y A : Field n) : Matrix (Fin n) (Fin n) ℝ := fun i k => + (if i = k then 1 else 0) + sqrt (A i) * hessianCore j J y i k * sqrt (A k) + +def vectorSqNorm {n : ℕ} (x : Field n) : ℝ := ∑ i, x i ^ 2 + +def quadraticForm {n : ℕ} (J : Matrix (Fin n) (Fin n) ℝ) (x : Field n) : ℝ := + ∑ i, ∑ k, x i * J i k * x k + +theorem overlap_nonneg {n : ℕ} (y : Field n) : 0 ≤ overlap y := + div_nonneg (Finset.sum_nonneg (fun _ _ => sq_nonneg _)) (Nat.cast_nonneg _) + +theorem overlap_lt_one {n : ℕ} (hn : 0 < n) (y : Field n) : overlap y < 1 := by + have hn' : (0 : ℝ) < n := by exact_mod_cast hn + apply (div_lt_iff₀ hn').mpr + simp only [one_mul] + calc + (∑ i, magnetization y i ^ 2) < ∑ _ : Fin n, (1 : ℝ) := by + apply Finset.sum_lt_sum_of_nonempty + · exact Finset.univ_nonempty_iff.mpr ⟨⟨0, hn⟩⟩ + · intro i _ + exact tanh_sq_lt_one (y i) + _ = n := by simp + +theorem spinVariance_pos {n : ℕ} (y : Field n) (i : Fin n) : + 0 < spinVariance y i := sub_pos.mpr (tanh_sq_lt_one _) + +theorem spinVariance_le_one {n : ℕ} (y : Field n) (i : Fin n) : + spinVariance y i ≤ 1 := sub_le_self _ (sq_nonneg _) + +theorem fieldHessian_symm {n : ℕ} {J : Matrix (Fin n) (Fin n) ℝ} + (hJ : J.IsSymm) (j : ℝ) (y A : Field n) : (fieldHessian j J y A).IsSymm := by + apply Matrix.IsSymm.ext + intro i k + simp only [fieldHessian, hessianCore, hJ.apply i k, eq_comm] + ring + +theorem tapField_sub_external {n : ℕ} (j : ℝ) (J : Matrix (Fin n) (Fin n) ℝ) + (h y : Field n) : tapField j J h y = tapField j J 0 y - h := by + ext i + simp only [tapField, Pi.zero_apply, Pi.sub_apply] + ring + +theorem vectorSqNorm_nonneg {n : ℕ} (x : Field n) : 0 ≤ vectorSqNorm x := + Finset.sum_nonneg (fun _ _ => sq_nonneg _) + +theorem vectorSqNorm_eq_zero {n : ℕ} {x : Field n} : vectorSqNorm x = 0 ↔ x = 0 := by + unfold vectorSqNorm + rw [Finset.sum_eq_zero_iff_of_nonneg (fun _ _ => sq_nonneg _)] + simp only [Finset.mem_univ, true_implies, sq_eq_zero_iff, funext_iff, Pi.zero_apply] + +theorem hessian_quadratic_formula {n : ℕ} (j : ℝ) + (J : Matrix (Fin n) (Fin n) ℝ) (y A x : Field n) : + quadraticForm (fieldHessian j J y A) x = vectorSqNorm x + + onsager j y * vectorSqNorm (fun i => sqrt (A i) * x i) - + quadraticForm J (fun i => sqrt (A i) * x i) - + (2 * j / n) * (∑ i, magnetization y i * (sqrt (A i) * x i)) ^ 2 := by + have hi (i : Fin n) : + (∑ k, x i * fieldHessian j J y A i k * x k) = x i ^ 2 + + onsager j y * (sqrt (A i) * x i) ^ 2 - + (∑ k, (sqrt (A i) * x i) * J i k * (sqrt (A k) * x k)) - + (2 * j / n) * (magnetization y i * (sqrt (A i) * x i)) * + (∑ k, magnetization y k * (sqrt (A k) * x k)) := by + calc + _ = ∑ k, ((if i = k then x i ^ 2 else 0) + + (if i = k then onsager j y * (sqrt (A i) * x i) ^ 2 else 0) - + (sqrt (A i) * x i) * J i k * (sqrt (A k) * x k) - + (2 * j / n) * (magnetization y i * (sqrt (A i) * x i)) * + (magnetization y k * (sqrt (A k) * x k))) := by + apply Finset.sum_congr rfl + intro k _ + by_cases hk : i = k + · subst k + simp only [fieldHessian, hessianCore, ↓reduceIte] + ring + · simp only [fieldHessian, hessianCore, ite_eq_right hk] + ring + _ = _ := by + simp only [Finset.sum_sub_distrib, Finset.sum_add_distrib, + Finset.sum_ite_eq, Finset.mem_univ, ite_true, ← Finset.mul_sum] + unfold quadraticForm + simp_rw [hi] + simp only [Finset.sum_sub_distrib, Finset.sum_add_distrib, ← Finset.mul_sum, + ← Finset.sum_mul, vectorSqNorm] + ring + +theorem hessian_lower_bound {n : ℕ} (hn : 0 < n) {j R a : ℝ} + (hj : 0 ≤ j) {J : Matrix (Fin n) (Fin n) ℝ} (y A : Field n) + (hA0 : ∀ i, 0 ≤ A i) (hAa : ∀ i, A i ≤ a) + (hJ : ∀ v : Field n, quadraticForm J v ≤ R * vectorSqNorm v) + (hcoef : 0 ≤ R - j + 3 * j * overlap y) (x : Field n) : + (1 - a * (R - j + 3 * j * overlap y)) * vectorSqNorm x ≤ + quadraticForm (fieldHessian j J y A) x := by + let v : Field n := fun i => sqrt (A i) * x i + have hn' : (0 : ℝ) < n := by exact_mod_cast hn + have hm : (∑ i, magnetization y i ^ 2) = n * overlap y := by + unfold overlap + field_simp + have hcs := Finset.sum_mul_sq_le_sq_mul_sq Finset.univ (magnetization y) v + rw [hm] at hcs + have hscale : 0 ≤ 2 * j / (n : ℝ) := by positivity + have hrank : (2 * j / n) * (∑ i, magnetization y i * v i) ^ 2 ≤ + 2 * j * overlap y * vectorSqNorm v := by + have he : (2 * j / n) * ((n : ℝ) * overlap y * vectorSqNorm v) = + 2 * j * overlap y * vectorSqNorm v := by field_simp + rw [← he] + exact mul_le_mul_of_nonneg_left hcs hscale + have hv : vectorSqNorm v ≤ a * vectorSqNorm x := by + rw [vectorSqNorm, vectorSqNorm, Finset.mul_sum] + apply Finset.sum_le_sum + intro i _ + dsimp [v] + rw [mul_pow, sq_sqrt (hA0 i)] + exact mul_le_mul_of_nonneg_right (hAa i) (sq_nonneg _) + rw [hessian_quadratic_formula] + change (1 - a * (R - j + 3 * j * overlap y)) * vectorSqNorm x ≤ + vectorSqNorm x + onsager j y * vectorSqNorm v - quadraticForm J v - + (2 * j / n) * (∑ i, magnetization y i * v i) ^ 2 + have hmul := mul_le_mul_of_nonneg_left hv hcoef + dsimp [onsager] + nlinarith [hJ v, hrank] + +def fieldJacobian {n : ℕ} (j : ℝ) (J : Matrix (Fin n) (Fin n) ℝ) + (y : Field n) : Matrix (Fin n) (Fin n) ℝ := fun i k => + (if i = k then 1 else 0) + hessianCore j J y i k * spinVariance y k + +theorem hasDerivAt_tanh (y : ℝ) : HasDerivAt tanh (1 - tanh y ^ 2) y := by + convert! (Real.hasDerivAt_sinh y).div (Real.hasDerivAt_cosh y) (cosh_pos y).ne' using 1 + · ext x + exact tanh_eq_sinh_div_cosh x + · rw [tanh_eq_sinh_div_cosh] + field_simp + +theorem magnetization_hasFDerivAt {n : ℕ} (y : Field n) (i : Fin n) : + HasFDerivAt (fun z : Field n => magnetization z i) + (spinVariance y i • (ContinuousLinearMap.proj i : Field n →L[ℝ] ℝ)) y := + (hasDerivAt_tanh (y i)).comp_hasFDerivAt y (hasFDerivAt_apply i y) + +def overlapDerivative {n : ℕ} (y : Field n) : Field n →L[ℝ] ℝ := + (2 / (n : ℝ)) • ∑ k, (magnetization y k * spinVariance y k) • ContinuousLinearMap.proj k + +theorem overlap_hasFDerivAt {n : ℕ} (y : Field n) : + HasFDerivAt overlap (overlapDerivative y) y := by + have hd := (HasFDerivAt.sum (u := Finset.univ) + (fun k _ => (magnetization_hasFDerivAt y k).pow 2)).const_mul (n : ℝ)⁻¹ + convert! hd using 1 + · ext z + simp only [overlap, Finset.sum_apply, div_eq_mul_inv] + ring + · ext v + simp only [overlapDerivative, _root_.smul_apply, + _root_.sum_apply, ContinuousLinearMap.proj_apply, + smul_eq_mul, Nat.cast_ofNat, Nat.reduceSub, pow_one, + nsmul_eq_mul] + simp_rw [mul_assoc] + rw [← Finset.mul_sum] + ring + +theorem onsager_hasFDerivAt {n : ℕ} (j : ℝ) (y : Field n) : + HasFDerivAt (onsager j) (-j • overlapDerivative y) y := by + convert! ((overlap_hasFDerivAt y).const_sub 1).const_mul j using 1 + ext v + simp only [_root_.smul_apply, smul_eq_mul, _root_.neg_apply] + ring + +theorem tapField_hasFDerivAt {n : ℕ} (j : ℝ) + (J : Matrix (Fin n) (Fin n) ℝ) (h y : Field n) : + HasFDerivAt (tapField j J h) + ((fieldJacobian j J y).mulVecLin.toContinuousLinearMap) y := by + rw [hasFDerivAt_pi'] + intro i + have hfirst := ((hasFDerivAt_apply i y).sub_const (h i)).add + ((onsager_hasFDerivAt j y).mul (magnetization_hasFDerivAt y i)) + have hlast := HasFDerivAt.sum (u := Finset.univ) + (fun k _ => (magnetization_hasFDerivAt y k).const_mul (J i k)) + convert! hfirst.sub hlast using 1 + · ext z + simp only [tapField, Pi.sub_apply, Pi.add_apply, Pi.mul_apply, Finset.sum_apply] + · ext v + simp only [ContinuousLinearMap.comp_apply, ContinuousLinearMap.proj_apply, + LinearMap.coe_toContinuousLinearMap', Matrix.mulVecLin_apply, Matrix.mulVec, + dotProduct, fieldJacobian, hessianCore, _root_.sub_apply, + _root_.add_apply, _root_.smul_apply, + _root_.sum_apply, smul_eq_mul, overlapDerivative] + have hdelta : (∑ k : Fin n, (if i = k then 1 else (0 : ℝ)) * v k) = v i := by + simp + have hdeltaV : (∑ k : Fin n, (if i = k then 1 else (0 : ℝ)) * + spinVariance y k * v k) = spinVariance y i * v i := by simp + calc + _ = (∑ k : Fin n, (if i = k then 1 else (0 : ℝ)) * v k) + + onsager j y * (∑ k : Fin n, (if i = k then 1 else (0 : ℝ)) * + spinVariance y k * v k) - + (∑ k, J i k * (spinVariance y k * v k)) - + (2 * j / n) * magnetization y i * + (∑ k, (magnetization y k * spinVariance y k) * v k) := by + simp only [Finset.mul_sum, ← Finset.sum_sub_distrib, ← Finset.sum_add_distrib] + apply Finset.sum_congr rfl + intro k _ + ring + _ = _ := by + rw [hdelta, hdeltaV] + ring + +theorem fieldHessian_variance_intertwine {n : ℕ} (j : ℝ) + (J : Matrix (Fin n) (Fin n) ℝ) (y : Field n) (i k : Fin n) : + fieldHessian j J y (spinVariance y) i k * sqrt (spinVariance y k) = + sqrt (spinVariance y i) * fieldJacobian j J y i k := by + have hk := sq_sqrt (spinVariance_pos y k).le + by_cases hik : i = k + · subst k + simp only [fieldHessian, fieldJacobian, ↓reduceIte] + nlinarith only [congrArg (fun z => sqrt (spinVariance y i) * hessianCore j J y i i * z) hk] + · simp only [fieldHessian, fieldJacobian, ite_eq_right hik, zero_add] + nlinarith only [congrArg (fun z => sqrt (spinVariance y i) * hessianCore j J y i k * z) hk] + +theorem fieldHessian_variance_mulVec {n : ℕ} (j : ℝ) + (J : Matrix (Fin n) (Fin n) ℝ) (y v : Field n) : + (fieldHessian j J y (spinVariance y)).mulVec + (fun k => sqrt (spinVariance y k) * v k) = + fun i => sqrt (spinVariance y i) * (fieldJacobian j J y).mulVec v i := by + ext i + simp only [Matrix.mulVec, dotProduct, Finset.mul_sum] + apply Finset.sum_congr rfl + intro k _ + rw [← mul_assoc, fieldHessian_variance_intertwine] + ring + +theorem quadraticForm_eq_dot_mulVec {n : ℕ} + (J : Matrix (Fin n) (Fin n) ℝ) (x : Field n) : + quadraticForm J x = ∑ i, x i * J.mulVec x i := by + simp only [quadraticForm, Matrix.mulVec, dotProduct, Finset.mul_sum, mul_assoc] + +theorem jacobian_injective_of_hessian_coercive {n : ℕ} {c j : ℝ} (hc : 0 < c) + (J : Matrix (Fin n) (Fin n) ℝ) (y : Field n) + (hH : ∀ x : Field n, c * vectorSqNorm x ≤ + quadraticForm (fieldHessian j J y (spinVariance y)) x) : + Function.Injective (fieldJacobian j J y).mulVec := by + apply (fieldJacobian j J y).mulVecLin.ker_eq_bot.mp + apply LinearMap.ker_eq_bot'.mpr + intro v hv + let w : Field n := fun k => sqrt (spinVariance y k) * v k + have hw : (fieldHessian j J y (spinVariance y)).mulVec w = 0 := by + rw [show w = (fun k => sqrt (spinVariance y k) * v k) from rfl, + fieldHessian_variance_mulVec] + ext i + have hi := congrFun hv i + change (fieldJacobian j J y).mulVec v i = 0 at hi + change sqrt (spinVariance y i) * (fieldJacobian j J y).mulVec v i = 0 + rw [hi, mul_zero] + have hquad : quadraticForm (fieldHessian j J y (spinVariance y)) w = 0 := by + rw [quadraticForm_eq_dot_mulVec, hw] + simp + have hn : vectorSqNorm w = 0 := by + have := hH w + rw [hquad] at this + nlinarith [vectorSqNorm_nonneg w] + have hw0 := vectorSqNorm_eq_zero.mp hn + ext i + have hi := congrFun hw0 i + have hs := sqrt_pos.mpr (spinVariance_pos y i) + dsimp [w] at hi + exact (mul_eq_zero.mp hi).resolve_left hs.ne' + +def vectorNorm {n : ℕ} (x : Field n) : ℝ := + ‖(WithLp.toLp 2 x : EuclideanSpace ℝ (Fin n))‖ + +theorem vectorNorm_nonneg {n : ℕ} (x : Field n) : 0 ≤ vectorNorm x := norm_nonneg _ + +theorem vectorNorm_sq {n : ℕ} (x : Field n) : vectorNorm x ^ 2 = vectorSqNorm x := by + exact EuclideanSpace.real_norm_sq_eq (WithLp.toLp 2 x) + +theorem vectorNorm_add_le {n : ℕ} (x z : Field n) : + vectorNorm (x + z) ≤ vectorNorm x + vectorNorm z := by + exact norm_add_le (WithLp.toLp 2 x : EuclideanSpace ℝ (Fin n)) (WithLp.toLp 2 z) + +theorem vectorNorm_sub_le {n : ℕ} (x z : Field n) : + vectorNorm (x - z) ≤ vectorNorm x + vectorNorm z := by + exact norm_sub_le (WithLp.toLp 2 x : EuclideanSpace ℝ (Fin n)) (WithLp.toLp 2 z) + +theorem vectorNorm_smul {n : ℕ} (a : ℝ) (x : Field n) : + vectorNorm (fun i => a * x i) = |a| * vectorNorm x := by + exact norm_smul a (WithLp.toLp 2 x : EuclideanSpace ℝ (Fin n)) + +theorem vector_dot_abs_le {n : ℕ} (x z : Field n) : + |∑ i, x i * z i| ≤ vectorNorm x * vectorNorm z := by + simpa only [vectorNorm, PiLp.inner_apply, RCLike.inner_apply, conj_trivial, + PiLp.toLp_apply, mul_comm] using + abs_real_inner_le_norm (WithLp.toLp 2 x : EuclideanSpace ℝ (Fin n)) (WithLp.toLp 2 z) + +theorem vectorNorm_diag_le {n : ℕ} {a : Field n} {M : ℝ} (hM : 0 ≤ M) + (ha : ∀ i, |a i| ≤ M) (x : Field n) : + vectorNorm (fun i => a i * x i) ≤ M * vectorNorm x := by + apply (sq_le_sq₀ (vectorNorm_nonneg _) (mul_nonneg hM (vectorNorm_nonneg _))).mp + rw [mul_pow, vectorNorm_sq, vectorNorm_sq] + unfold vectorSqNorm + rw [Finset.mul_sum] + apply Finset.sum_le_sum + intro i _ + rw [mul_pow] + have hi : a i ^ 2 ≤ M ^ 2 := by + simpa only [sq_abs] using (sq_le_sq₀ (abs_nonneg (a i)) hM).mpr (ha i) + exact mul_le_mul_of_nonneg_right hi (sq_nonneg (x i)) + +def sqrtVarianceMul {n : ℕ} (y v : Field n) : Field n := + fun i => sqrt (spinVariance y i) * v i + +theorem sqrtVarianceMul_norm_le {n : ℕ} (y v : Field n) : + vectorNorm (sqrtVarianceMul y v) ≤ vectorNorm v := by + change vectorNorm (fun i => sqrt (spinVariance y i) * v i) ≤ vectorNorm v + calc + _ ≤ 1 * vectorNorm v := vectorNorm_diag_le zero_le_one (fun i => by + rw [abs_of_nonneg (sqrt_nonneg _)] + exact sqrt_le_one.mpr (spinVariance_le_one y i)) v + _ = _ := one_mul _ + +theorem sqrtVarianceMul_twice {n : ℕ} (y v : Field n) : + sqrtVarianceMul y (sqrtVarianceMul y v) = fun i => spinVariance y i * v i := by + ext i + dsimp [sqrtVarianceMul] + rw [← mul_assoc, mul_self_sqrt (spinVariance_pos y i).le] + +theorem weighted_inverse_bound {n : ℕ} {c j : ℝ} (_hc : 0 < c) + (J : Matrix (Fin n) (Fin n) ℝ) (y v : Field n) + (hH : ∀ x : Field n, c * vectorSqNorm x ≤ + quadraticForm (fieldHessian j J y (spinVariance y)) x) : + c * vectorNorm (sqrtVarianceMul y v) ≤ + vectorNorm ((fieldJacobian j J y).mulVec v) := by + let w := sqrtVarianceMul y v + let z := (fieldJacobian j J y).mulVec v + have hi : (fieldHessian j J y (spinVariance y)).mulVec w = sqrtVarianceMul y z := + fieldHessian_variance_mulVec j J y v + have hq := hH w + rw [quadraticForm_eq_dot_mulVec, hi] at hq + have hdot := (le_abs_self (∑ i, w i * sqrtVarianceMul y z i)).trans + (vector_dot_abs_le w (sqrtVarianceMul y z)) + have hz := mul_le_mul_of_nonneg_left (sqrtVarianceMul_norm_le y z) (vectorNorm_nonneg w) + rw [← vectorNorm_sq] at hq + change c * vectorNorm w ≤ vectorNorm z + by_cases hw : vectorNorm w = 0 + · rw [hw, mul_zero] + exact vectorNorm_nonneg z + · have hw' : 0 < vectorNorm w := lt_of_le_of_ne (vectorNorm_nonneg w) (Ne.symm hw) + nlinarith [hq.trans (hdot.trans hz)] + +theorem hessianCore_mulVec {n : ℕ} (j : ℝ) + (J : Matrix (Fin n) (Fin n) ℝ) (y v : Field n) : + (hessianCore j J y).mulVec v = + (fun i => onsager j y * v i) - J.mulVec v - + (fun i => ((2 * j / n) * (∑ k, magnetization y k * v k)) * magnetization y i) := by + ext i + change (∑ k, hessianCore j J y i k * v k) = + onsager j y * v i - (∑ k, J i k * v k) - + ((2 * j / n) * (∑ k, magnetization y k * v k)) * magnetization y i + calc + _ = ∑ k, (onsager j y * ((if i = k then 1 else 0) * v k) - J i k * v k - + ((2 * j / n) * magnetization y i) * (magnetization y k * v k)) := by + apply Finset.sum_congr rfl + intro k _ + simp only [hessianCore] + ring + _ = _ := by + simp only [Finset.sum_sub_distrib, ← Finset.mul_sum] + simp + ring + +attribute [local irreducible] vectorNorm + +theorem hessianCore_norm_le {n : ℕ} (hn : 0 < n) {j K : ℝ} (hj : 0 ≤ j) + (J : Matrix (Fin n) (Fin n) ℝ) (y v : Field n) + (hJ : ∀ z : Field n, vectorNorm (J.mulVec z) ≤ K * vectorNorm z) : + vectorNorm ((hessianCore j J y).mulVec v) ≤ (K + 3 * j) * vectorNorm v := by + have hn' : (0 : ℝ) < n := by exact_mod_cast hn + have hq0 := overlap_nonneg y + have hq1 := (overlap_lt_one hn y).le + have hB0 : 0 ≤ onsager j y := mul_nonneg hj (sub_nonneg.mpr hq1) + have hB : onsager j y ≤ j := by + dsimp [onsager] + nlinarith + have hfirst : vectorNorm (fun i => onsager j y * v i) ≤ j * vectorNorm v := by + rw [vectorNorm_smul, abs_of_nonneg hB0] + exact mul_le_mul_of_nonneg_right hB (vectorNorm_nonneg v) + have hm : vectorNorm (magnetization y) ^ 2 = (n : ℝ) * overlap y := by + rw [vectorNorm_sq] + dsimp [vectorSqNorm, overlap] + field_simp + have hm_bound : vectorNorm (magnetization y) ^ 2 ≤ n := by nlinarith + have hs : 0 ≤ 2 * j / (n : ℝ) := by positivity + have hcs := vector_dot_abs_le (magnetization y) v + have hrank : vectorNorm (fun i => ((2 * j / n) * + (∑ k, magnetization y k * v k)) * magnetization y i) ≤ 2 * j * vectorNorm v := by + rw [vectorNorm_smul, abs_mul, abs_of_nonneg hs] + calc + _ ≤ ((2 * j / n) * (vectorNorm (magnetization y) * vectorNorm v)) * + vectorNorm (magnetization y) := + mul_le_mul_of_nonneg_right (mul_le_mul_of_nonneg_left hcs hs) + (vectorNorm_nonneg _) + _ = (2 * j / n) * vectorNorm (magnetization y) ^ 2 * vectorNorm v := by ring + _ ≤ (2 * j / n) * n * vectorNorm v := + mul_le_mul_of_nonneg_right (mul_le_mul_of_nonneg_left hm_bound hs) + (vectorNorm_nonneg _) + _ = _ := by field_simp + rw [hessianCore_mulVec] + calc + _ ≤ vectorNorm ((fun i => onsager j y * v i) - J.mulVec v) + + vectorNorm (fun i => ((2 * j / n) * (∑ k, magnetization y k * v k)) * + magnetization y i) := vectorNorm_sub_le _ _ + _ ≤ (vectorNorm (fun i => onsager j y * v i) + vectorNorm (J.mulVec v)) + + vectorNorm (fun i => ((2 * j / n) * (∑ k, magnetization y k * v k)) * + magnetization y i) := add_le_add (vectorNorm_sub_le _ _) le_rfl + _ ≤ (j * vectorNorm v + K * vectorNorm v) + 2 * j * vectorNorm v := + add_le_add (add_le_add hfirst (hJ v)) hrank + _ = _ := by ring + +theorem fieldJacobian_mulVec {n : ℕ} (j : ℝ) + (J : Matrix (Fin n) (Fin n) ℝ) (y v : Field n) : + (fieldJacobian j J y).mulVec v = v + + (hessianCore j J y).mulVec (fun i => spinVariance y i * v i) := by + ext i + simp only [Matrix.mulVec, dotProduct, fieldJacobian, add_mul, + Finset.sum_add_distrib, Pi.add_apply, mul_assoc] + simp + +theorem fieldJacobian_inverse_bound {n : ℕ} (hn : 0 < n) {c j K : ℝ} + (hc : 0 < c) (hj : 0 ≤ j) (hK : 0 ≤ K) + (J : Matrix (Fin n) (Fin n) ℝ) (y v : Field n) + (hJ : ∀ z : Field n, vectorNorm (J.mulVec z) ≤ K * vectorNorm z) + (hH : ∀ x : Field n, c * vectorSqNorm x ≤ + quadraticForm (fieldHessian j J y (spinVariance y)) x) : + vectorNorm v ≤ (1 + (K + 3 * j) / c) * + vectorNorm ((fieldJacobian j J y).mulVec v) := by + let z := (fieldJacobian j J y).mulVec v + let w : Field n := fun i => spinVariance y i * v i + have hw : vectorNorm w ≤ vectorNorm (sqrtVarianceMul y v) := by + simpa only [sqrtVarianceMul_twice] using sqrtVarianceMul_norm_le y (sqrtVarianceMul y v) + have hcv : c * vectorNorm w ≤ vectorNorm z := + (mul_le_mul_of_nonneg_left hw hc.le).trans (weighted_inverse_bound hc J y v hH) + have hv : vectorNorm w ≤ vectorNorm z / c := (le_div_iff₀ hc).mpr (by + simpa only [mul_comm] using hcv) + have he : v = z - (hessianCore j J y).mulVec w := by + have hid := fieldJacobian_mulVec j J y v + change z = v + (hessianCore j J y).mulVec w at hid + rw [hid, add_sub_cancel_right] + have hL := hessianCore_norm_le hn hj J y w hJ + have hD : 0 ≤ K + 3 * j := by positivity + calc + vectorNorm v ≤ vectorNorm z + vectorNorm ((hessianCore j J y).mulVec w) := by + conv_lhs => rw [he] + exact vectorNorm_sub_le _ _ + _ ≤ vectorNorm z + (K + 3 * j) * vectorNorm w := add_le_add le_rfl hL + _ ≤ vectorNorm z + (K + 3 * j) * (vectorNorm z / c) := + add_le_add le_rfl (mul_le_mul_of_nonneg_left hv hD) + _ = (1 + (K + 3 * j) / c) * vectorNorm z := by ring + +end SKGap +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Stability/StableLiteralComparison.lean b/lean/OAI/Probability/SKGap/Stability/StableLiteralComparison.lean new file mode 100644 index 0000000000000000000000000000000000000000..6f70a435433da7c15e98d22d02da028dac3d0dfc --- /dev/null +++ b/lean/OAI/Probability/SKGap/Stability/StableLiteralComparison.lean @@ -0,0 +1,142 @@ +import Mathlib +import OAI.Probability.SKGap.Terminal.StableLiteralTerminal +import OAI.Probability.SKGap.Localization.LocalFixedRecipe + +namespace OAI + +section + +noncomputable section +open scoped BigOperators Matrix.Norms.Frobenius +namespace SKGapCutoff.Recipe +open SKGap.Stein Primary Static +universe u +theorem stable_literal_comparison_targets {j K B R ρ δ : ℝ} + (hj : 0≤j) (hK : 0≤K) (hB : 0≤B) (hδ : 0<δ) (hρ : 0≤ρ) + (hsmall : ρ≤δ/(2*(|j| *Real.exp (R/2)*(3*Real.exp (R/2)+16)+1))) + (k : ℕ) (f : KernelExpr) : + ∃A≥1,∀W C : ℝ,0≤W→0≤C→∀(Ω : Type u) (n : Ω→ℕ) + (J : ∀b,Interaction (n b)) (h r e : ∀b,Fin (n b)→ℝ) + (E : ∀b,Set (Spin (n b))) (P : ∀b,Observables (n b)), + (∀b,0j*(1-onsager j (J b) (h b) (k+1) v-SKGap.overlap (r b))) (r b) R ρ δ x)→ + (∀b x,0≤P b x)→(∀b,∑x,P b x=1)→ + (∀b x i,conditionalMean (P b) x i=mag j (J b) (h b) 1 x i)→ + ∃w y : ∀b,VectorFields (n b),∃c : ∀b,Observables (n b), + (∀b x,x∈E b→LiteralEquations (J b) j f (fld j (J b) (h b) (k+1)) + (mag j (J b) (h b) (k+1)) (w b) (y b) + (fun v=>j*(1-onsager j (J b) (h b) (k+1) v-SKGap.overlap (r b))) (c b) (r b) (e b) x) ∧ + ((∀p≤k+1,LocalUniformWeak E P (fun b x=>∑i,residual j (J b) (h b) p x i*w b x i)) ∧ + LocalUniformWeak E P (fun b x=>∑i,residual j (J b) (h b) (k+1) x i*y b x i) ∧ + LocalUniformWeak E P (fun b x=>∑i,residual j (J b) (h b) (k+1) x i* + (Real.tanh (fld j (J b) (h b) (k+1) x i)/Real.sqrt (n b:ℝ))) ∧ + LocalUniformMultiplier E (fun b=>siteMean (fun x i=>phi (fld j (J b) (h b) (k+1) x i) (r b i) + (j*(1-onsager j (J b) (h b) (k+1) x-SKGap.overlap (r b))))) ∧ + LocalUniformMultiplier E (fun b x=>j*onsager j (J b) (h b) (k+1) x) ∧ + LocalUniformMultiplier E (fun b x=>Real.sqrt (n b:ℝ)*c b x)) ∧ + LocalUniformWeak E P (fun b x=>j*c b x*(∑i,residual j (J b) (h b) (k+1) x i* + (Real.tanh (fld j (J b) (h b) (k+1) x i)-Real.tanh (r b i)))) := by + let Cp:=localPrimaryBudget j K B (k+3) + let T:=(1+|j|)*Cp + have hCp : 0≤Cp:=localPrimaryBudget_nonneg hK hB _ + have hT : 0≤T:=by dsimp [T];positivity + obtain ⟨V,hV,S,hS,F,hF,Bc,hBc,Vc,hVc,hsol⟩:= + literal_complete_diagnostics j R ρ δ T K (2*Cp) Cp f hj hδ hρ hT + (mul_nonneg (by norm_num) hCp) hsmall + let A:=literalResidualBudget j f R Bc (k+1) + have hA : 1≤A:= + (show 1≤2+|literalCoefficientBudget f j R Bc| by linarith [abs_nonneg (literalCoefficientBudget f j R Bc)]).trans + (residualCoefficientBudget_ge j (by positivity) (k+1) 0) + refine ⟨A,hA,?_⟩ + intro W C hW hC Ω n J h r e E P hn hJ he hevent hstable hP hp hm + let a:=fun b v=>j*(1-onsager j (J b) (h b) (k+1) v-SKGap.overlap (r b)) + choose w y c heq hc hDc hdiag using fun b=>hsol (n b) (hn b) (J b) + (fld j (J b) (h b) (k+1)) (mag j (J b) (h b) (k+1)) (a b) (r b) (e b) + (hJ b) (hevent b).1 (he b) + have hs (b) (x : Spin (n b)) (hx : x∈flipNeighborhood (E b)) := + hstable b x (Or.inl hx) + have hsf (b) (x : Spin (n b)) (hx : x∈flipNeighborhood (E b)) (i : Fin (n b)) := + hstable b (flip x i) (Or.inr ⟨i,by simpa only [flip_flip] using hx⟩) + have hb (b) (x : Spin (n b)):=primary_literal_derivative_diagnostics (hn b) hK hB (J b) (h b) + (hevent b).1 k (fun v q hq=>(hevent b).2.1 (h b) v q hq) (r b) x + have heqE : ∀b x,x∈E b→LiteralEquations (J b) j f (fld j (J b) (h b) (k+1)) + (mag j (J b) (h b) (k+1)) (w b) (y b) (a b) (c b) (r b) (e b) x := by + intro b x hx;exact heq b x (hs b x (Or.inl hx)) + refine ⟨w,y,c,heqE,?_⟩ + apply literal_local_weak_comparison_targets j J h ⟨k+1,by omega⟩ f a c r e w y E hn he + hK hB hBc hT hVc hV hS hF hW hC + (fun b=>(hevent b).1) (fun b x q hq=>(hevent b).2.1 (h b) x q hq) + · intro b x hx;exact (hstable b x hx).a_bound + · intro b x hx;exact hc b x (hstable b x hx) + · intro b x hx + have hh:=(hb b x).1 + exact (le_add_of_nonneg_left (show 0≤SKGap.opNorm (derivativeMatrix (fld j (J b) (h b) (k+1)) x) from norm_nonneg _)).trans hh + · intro b x hx;exact hDc b x (hs b x hx) (hsf b x hx) (hb b x).1 (hb b x).2.1 + · exact heqE + · intro b x hx + exact (hdiag b x (primaryTree j (J b) (h b) x (k+1)) (hs b x hx) (hsf b x hx) + (hb b x).1 (hb b x).2.1 (primaryState_mag_bounded j (J b) (h b) (k+1) x) + (hb b x).2.2.1 (hb b x).2.2.2.1 (hb b x).2.2.2.2.1 (hb b x).2.2.2.2.2).monoCoefficient + (literalResidualBudget_exp j f R Bc (k+1)) + · exact hP + · exact hp + · exact hm + · exact hJ + · intro b x hx + exact (literal_closed_word_event (J b) j _ _ (a b) (r b) x (hn b) hj hδ hρ hsmall + (hs b x hx) (hevent b)).1 + · intro b x hx + exact (literal_closed_word_event (J b) j _ _ (a b) (r b) x (hn b) hj hδ hρ hsmall + (hs b x hx) (hevent b)).2 + +end SKGapCutoff.Recipe + +end +end + +section + +noncomputable section +open scoped BigOperators Matrix.Norms.Frobenius +namespace SKGapCutoff.Recipe +open Primary Static SKGap.Stein +universe u +theorem stable_literal_comparison_weak {j K B R ρ δ : ℝ} + (hj : 0≤j) (hK : 0≤K) (hB : 0≤B) (hδ : 0<δ) (hρ : 0≤ρ) + (hsmall : ρ≤δ/(2*(|j| *Real.exp (R/2)*(3*Real.exp (R/2)+16)+1))) + (k : ℕ) (f : KernelExpr) : + ∃A≥1,∀W C : ℝ,0≤W→0≤C→∀(Ω : Type u) (n : Ω→ℕ) + (J : ∀b,Interaction (n b)) (h r e : ∀b,Fin (n b)→ℝ) + (E : ∀b,Set (Spin (n b))) (P : ∀b,Observables (n b)), + (∀b,0j*(1-onsager j (J b) (h b) (k+1) v-SKGap.overlap (r b))) (r b) R ρ δ x)→ + (∀b x,0≤P b x)→(∀b,∑x,P b x=1)→ + (∀b x i,conditionalMean (P b) x i=mag j (J b) (h b) 1 x i)→ + ∃w y : ∀b,VectorFields (n b),∃c : ∀b,Observables (n b), + (∀b x,x∈E b→LiteralEquations (J b) j f (fld j (J b) (h b) (k+1)) + (mag j (J b) (h b) (k+1)) (w b) (y b) + (fun v=>j*(1-onsager j (J b) (h b) (k+1) v-SKGap.overlap (r b))) (c b) (r b) (e b) x) ∧ + LocalUniformWeak E P (fun b=>literalTerminal j (J b) (h b) k (w b) (c b)) ∧ + LocalUniformWeak E P (fun b x=>j*c b x*(∑i,residual j (J b) (h b) (k+1) x i* + (Real.tanh (fld j (J b) (h b) (k+1) x i)-Real.tanh (r b i)))) := by + obtain ⟨A,hA,hh⟩:=stable_literal_comparison_targets hj hK hB hδ hρ hsmall k f + refine ⟨A,hA,?_⟩ + intro W C hW hC Ω n J h r e E P hn hJ he hevent hstable hP hp hm + obtain ⟨w,y,c,heq,⟨hw,hy,hmag,hχ,ho,hc⟩,hrem⟩:=hh W C hW hC Ω n J h r e E P + hn hJ he hevent hstable hP hp hm + exact ⟨w,y,c,heq,literal_terminal_weak j J h r e k f + (fun b v=>j*(1-onsager j (J b) (h b) (k+1) v-SKGap.overlap (r b))) c w y E P hn hJ hP + heq hw hy hmag hχ ho hc,hrem⟩ + +end SKGapCutoff.Recipe + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Stability/StableLiteralWeak.lean b/lean/OAI/Probability/SKGap/Stability/StableLiteralWeak.lean new file mode 100644 index 0000000000000000000000000000000000000000..b6d526607b2057746a7949c6e553e9309264cd54 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Stability/StableLiteralWeak.lean @@ -0,0 +1,186 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.LiteralLocalWeak + +namespace OAI + +section + +noncomputable section +open scoped BigOperators Matrix.Norms.Frobenius +namespace SKGapCutoff.Recipe +open SKGap.Stein Primary Static +universe u + +lemma LiteralInitialDiagnostics.monoCoefficient {n : ℕ} + {D : OrdinaryData n Unit Bool Bool} {w y : VectorFields n} + {t : SKGap.Noncrossing.Primary.SourceTree (Fin n→ℝ)} {x : Spin n} {V S F A A' : ℝ} + (H : LiteralInitialDiagnostics D w y t x V S F A) (hA : A≤A') : + LiteralInitialDiagnostics D w y t x V S F A' := + {H with coefficient_bound:=fun i=>(H.coefficient_bound i).trans hA} + +lemma literalResidualBudget_exp (j : ℝ) (f : KernelExpr) (R B : ℝ) (p : ℕ) : + Real.exp (R/2)≤literalResidualBudget j f R B p := by + have h0:=le_abs_self (literalCoefficientBudget f j R B) + have hF : 0≤f.mass*Real.exp (R/2):=mul_nonneg f.mass_nonneg (Real.exp_pos _).le + have hJ : 0≤|j| *|B| *Real.exp (R/2):=by positivity + have hh : Real.exp (R/2)≤literalCoefficientBudget f j R B := by + simp only [literalCoefficientBudget,phiExpr,KernelExpr.mass] + nlinarith [abs_nonneg (initialRegularBudget f j R B)] + exact (show Real.exp (R/2)≤2+|literalCoefficientBudget f j R B| by linarith).trans + (residualCoefficientBudget_ge j (by positivity) p 0) + +theorem stable_literal_local_weak {j K B R ρ δ : ℝ} + (hj : 0≤j) (hK : 0≤K) (hB : 0≤B) (hδ : 0<δ) (hρ : 0≤ρ) + (hsmall : ρ≤δ/(2*(|j| *Real.exp (R/2)*(3*Real.exp (R/2)+16)+1))) + (k : ℕ) (f : KernelExpr) : + ∃A≥1,∀W C : ℝ,0≤W→0≤C→∀(Ω : Type u) (n : Ω→ℕ) + (J : ∀b,Interaction (n b)) (h r e : ∀b,Fin (n b)→ℝ) + (E : ∀b,Set (Spin (n b))) (P : ∀b,Observables (n b)), + (∀b,0j*(1-onsager j (J b) (h b) (k+1) v-SKGap.overlap (r b))) (r b) R ρ δ x)→ + (∀b x,0≤P b x)→(∀b,∑x,P b x=1)→ + (∀b x i,conditionalMean (P b) x i=mag j (J b) (h b) 1 x i)→ + ∃w y : ∀b,VectorFields (n b),∃c : ∀b,Observables (n b), + (∀b x,x∈E b→LiteralEquations (J b) j f (fld j (J b) (h b) (k+1)) + (mag j (J b) (h b) (k+1)) (w b) (y b) + (fun v=>j*(1-onsager j (J b) (h b) (k+1) v-SKGap.overlap (r b))) (c b) (r b) (e b) x) ∧ + LocalUniformWeak E P (fun b x=>∑i,residual j (J b) (h b) (k+1) x i*w b x i) := by + let Cp:=localPrimaryBudget j K B (k+3) + let T:=(1+|j|)*Cp + have hCp : 0≤Cp:=localPrimaryBudget_nonneg hK hB _ + have hT : 0≤T:=by dsimp [T];positivity + obtain ⟨V,hV,S,hS,F,hF,Bc,hBc,Vc,hVc,hsol⟩:= + literal_complete_diagnostics j R ρ δ T K (2*Cp) Cp f hj hδ hρ hT + (mul_nonneg (by norm_num) hCp) hsmall + let A:=literalResidualBudget j f R Bc (k+1) + have hA : 1≤A:= + (show 1≤2+|literalCoefficientBudget f j R Bc| by linarith [abs_nonneg (literalCoefficientBudget f j R Bc)]).trans + (residualCoefficientBudget_ge j (by positivity) (k+1) 0) + refine ⟨A,hA,?_⟩ + intro W C hW hC Ω n J h r e E P hn hJ he hevent hstable hP hp hm + let a:=fun b v=>j*(1-onsager j (J b) (h b) (k+1) v-SKGap.overlap (r b)) + choose w y c heq hc hDc hdiag using fun b=>hsol (n b) (hn b) (J b) + (fld j (J b) (h b) (k+1)) (mag j (J b) (h b) (k+1)) (a b) (r b) (e b) + (hJ b) (hevent b).1 (he b) + have hs (b) (x : Spin (n b)) (hx : x∈flipNeighborhood (E b)) := + hstable b x (Or.inl hx) + have hsf (b) (x : Spin (n b)) (hx : x∈flipNeighborhood (E b)) (i : Fin (n b)) := + hstable b (flip x i) (Or.inr ⟨i,by simpa only [flip_flip] using hx⟩) + have hb (b) (x : Spin (n b)):=primary_literal_derivative_diagnostics (hn b) hK hB (J b) (h b) + (hevent b).1 k (fun v q hq=>(hevent b).2.1 (h b) v q hq) (r b) x + have heqE : ∀b x,x∈E b→LiteralEquations (J b) j f (fld j (J b) (h b) (k+1)) + (mag j (J b) (h b) (k+1)) (w b) (y b) (a b) (c b) (r b) (e b) x := by + intro b x hx;exact heq b x (hs b x (Or.inl hx)) + refine ⟨w,y,c,heqE,?_⟩ + apply literal_local_weak_residual j J h ⟨k+1,by omega⟩ f a c r e w y E hn he + hK hB hBc hT hVc hV hS hF hW hC + (fun b=>(hevent b).1) (fun b x q hq=>(hevent b).2.1 (h b) x q hq) + · intro b x hx;exact (hstable b x hx).a_bound + · intro b x hx;exact hc b x (hstable b x hx) + · intro b x hx + have hh:=(hb b x).1 + exact (le_add_of_nonneg_left (show 0≤SKGap.opNorm (derivativeMatrix (fld j (J b) (h b) (k+1)) x) from norm_nonneg _)).trans hh + · intro b x hx;exact hDc b x (hs b x hx) (hsf b x hx) (hb b x).1 (hb b x).2.1 + · exact heqE + · intro b x hx + exact (hdiag b x (primaryTree j (J b) (h b) x (k+1)) (hs b x hx) (hsf b x hx) + (hb b x).1 (hb b x).2.1 (primaryState_mag_bounded j (J b) (h b) (k+1) x) + (hb b x).2.2.1 (hb b x).2.2.2.1 (hb b x).2.2.2.2.1 (hb b x).2.2.2.2.2).monoCoefficient + (literalResidualBudget_exp j f R Bc (k+1)) + · exact hP + · exact hp + · exact hm + · exact hJ + · intro b x hx + exact (literal_closed_word_event (J b) j _ _ (a b) (r b) x (hn b) hj hδ hρ hsmall + (hs b x hx) (hevent b)).1 + · intro b x hx + exact (literal_closed_word_event (J b) j _ _ (a b) (r b) x (hn b) hj hδ hρ hsmall + (hs b x hx) (hevent b)).2 + +end SKGapCutoff.Recipe + +end +end + +section + +noncomputable section +open scoped BigOperators Matrix.Norms.Frobenius +namespace SKGapCutoff.Recipe +open SKGap.Stein Primary Static +universe u + +theorem buffered_root_literal_weak {j K B Aroot ε c r₀ R ρ : ℝ} + (hj : 0≤j) (hK : 0≤K) (hB : 0≤B) (hA : 1≤Aroot) (hc : 0j*(1-onsager j (J b) (h b) (k+1) v-SKGap.overlap (r b))) + (c₀ b) (r b) (e b) x) ∧ + LocalUniformWeak (fun b=>{x | residualCutoff ρ j (J b) (h b) k x≠0}) P + (fun b x=>∑i,residual j (J b) (h b) (k+1) x i*w b x i) := by + let η:=(1+2*j)*(1+(1+(K+3*j)/c)*(K+4*j))*(2*ρ) + have hη : 0≤η:=by dsimp [η];positivity + obtain ⟨A,hA',hh⟩:=stable_literal_local_weak hj hK hB hc hη himplicit k f + refine ⟨A,hA',?_⟩ + intro W C hW hC Ω n J h e P hn hJ he hevent hbad hdim hP hp hm + have hact (b) (v : Fin (n b)→ℝ) : vectorNorm ((J b).mulVec v)≤K*vectorNorm v := + (vectorNorm_matrix_mul _ v).trans (mul_le_mul_of_nonneg_right (hevent b).1 (vectorNorm_nonneg v)) + choose r hr hu hs using fun b=>stable_primary_buffer (hn b) hj hK hA hc hr₀ + (mul_nonneg (by norm_num) hρ.le) hε hAR hbuffer hR hsmall (J b) (hJ b) (h b) (hact b) (hbad b) + let E:=fun b=>{x | residualCutoff ρ j (J b) (h b) k x≠0} + have hstable : ∀b x,x∈flipNeighborhood (flipNeighborhood (E b))→ + LiteralStableAt (J b) j (fld j (J b) (h b) (k+1)) (mag j (J b) (h b) (k+1)) + (fun v=>j*(1-onsager j (J b) (h b) (k+1) v-SKGap.overlap (r b))) (r b) R η c x := by + intro b x hx + let BB:=residualDerivativeBudget j K B k+residualDerivativeBudget j K B (k+1) + have hBB : 0≤BB:=add_nonneg (residualDerivativeBudget_nonneg hK hB _) + (residualDerivativeBudget_nonneg hK hB _) + have hD₀ (v : Spin (n b)) : SKGap.opNorm (derivativeMatrix (residual j (J b) (h b) k) v)≤BB := + (residual_derivative_bound (hn b) hK hB (J b) (h b) (hevent b).1 k + (fun v l hl=>(hevent b).2.1 (h b) v l (by omega)) v).trans + (le_add_of_nonneg_right (residualDerivativeBudget_nonneg hK hB _)) + have hD₁ (v : Spin (n b)) : SKGap.opNorm (derivativeMatrix (residual j (J b) (h b) (k+1)) v)≤BB := + (residual_derivative_bound (hn b) hK hB (J b) (h b) (hevent b).1 (k+1) + (fun v l hl=>(hevent b).2.1 (h b) v l (by omega)) v).trans + (le_add_of_nonneg_left (residualDerivativeBudget_nonneg hK hB _)) + have H0:=vector_neighborhood_twice_buffer (residual j (J b) (h b) k) (E b) hBB hD₀ (hdim b) + (fun v hv=>(residualCutoff_support (hn b) hρ (J b) (h b) k v hv).1) + have H1:=vector_neighborhood_twice_buffer (residual j (J b) (h b) (k+1)) (E b) hBB hD₁ (hdim b) + (fun v hv=>(residualCutoff_support (hn b) hρ (J b) (h b) k v hv).2) + rcases hx with hx|⟨i,hx⟩ + · exact hs b k x (H0 x hx).1 (H1 x hx).1 + · have h0:=(H0 (flip x i) hx).2 i + have h1:=(H1 (flip x i) hx).2 i + simp only [flip_flip] at h0 h1 + exact hs b k x h0 h1 + obtain ⟨w,y,c₀,heq,hw⟩:=hh W C hW hC Ω n J h r e E P hn hJ he hevent hstable hP hp hm + exact ⟨r,fun b=>⟨hr b,hu b⟩,w,y,c₀,heq,hw⟩ + +end SKGapCutoff.Recipe + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Stability/StableRootInverse.lean b/lean/OAI/Probability/SKGap/Stability/StableRootInverse.lean new file mode 100644 index 0000000000000000000000000000000000000000..177479aac587c135cfa74a1d1943ce31fac19e32 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Stability/StableRootInverse.lean @@ -0,0 +1,63 @@ +import Mathlib +import OAI.Probability.SKGap.Stability.GaugeStabilityLaw +import OAI.Probability.SKGap.Stability.TapFieldE + +namespace OAI + +section + +noncomputable section +namespace SKGap.ObservationBridge +open Matrix Real Set MeasureTheory ProbabilityTheory Filter +open scoped BigOperators ENNReal NNReal Topology + +lemma stable_hessian_coercive {n : ℕ} {j A ε c ρ : ℝ} + {J : Matrix (Fin n) (Fin n) ℝ} {h y a : Field n} + (hbad : ¬rootBad j A ε c ρ J h) + (hy : vectorNorm (tapField j J h y) ≤ ρ*sqrt (n:ℝ)) + (ha : ∀ i,a i∈Icc 0 A) (hd : (∑ i,(a i-spinVariance y i)^2)≤ε^2*(n:ℝ)) : + ∀ v : Field n,c*vectorSqNorm v ≤ quadraticForm (fieldHessian j J y a) v := by + intro v + let x : EuclideanSpace ℝ (Fin n) := WithLp.toLp 2 v + let H := fieldHessian j J y a + have hunit : ∀ z : EuclideanSpace ℝ (Fin n),‖z‖=1 → c < matrixQuad H z := by + intro z hz + exact lt_of_not_ge (fun hh=>hbad ⟨y,hy,a,ha,hd,z,hz,hh⟩) + by_cases hx : x=0 + · have hv : v=0 := congrArg WithLp.ofLp hx + simp [hv,vectorSqNorm,quadraticForm] + · have hx0 : 0<‖x‖ := norm_pos_iff.mpr hx + have hu : ‖(‖x‖⁻¹:ℝ) • x‖=1 := by + rw [norm_smul,Real.norm_eq_abs,abs_of_pos (inv_pos.mpr hx0),inv_mul_cancel₀ hx0.ne'] + have hh := (hunit (‖x‖⁻¹ • x) hu).le + rw [matrixQuad_smul] at hh + have hmul := mul_le_mul_of_nonneg_left hh (sq_nonneg ‖x‖) + have he : ‖x‖^2*((‖x‖⁻¹)^2*matrixQuad H x)=matrixQuad H x := by + field_simp + rw [he] at hmul + have hn : ‖x‖^2=vectorSqNorm v := vectorNorm_sq v + rw [hn,mul_comm] at hmul + exact hmul + +theorem stable_field_root_and_inverse {n : ℕ} (hn : 0 < n) + {j A K ε c ρ : ℝ} (hj : 0≤j) (hA : 1≤A) (hK : 0≤K) (hc : 0 x-ε • G x) s s) : + ∃! x : s, G x = 0 := by + let : CompactSpace s := isCompact_iff_compactSpace.mp hcompact + let : Nonempty s := hne.to_subtype + let : ConnectedSpace s := isConnected_iff_connectedSpace.mp (hconv.isConnected hne) + have hbound : ∃ M : ℝ, 0 ≤ M ∧ ∀ x ∈ s, ‖fderiv ℝ G x‖ ≤ M := by + obtain ⟨M, hM⟩ := hcompact.bddAbove_image + (hG.continuous_fderiv (by norm_num)).norm.continuousOn + refine ⟨max M 0, le_max_right _ _, fun x hx => ?_⟩ + exact (hM ⟨x, hx, rfl⟩).trans (le_max_left _ _) + obtain ⟨M, hM, hbound⟩ := hbound + obtain ⟨ε, hε, hε1, hεM, hεc, hεM2⟩ := exists_small_gradient_step hc hM + let L : ℝ≥0 := ⟨M, hM⟩ + have hLip : LipschitzOnWith L G s := + hconv.lipschitzOnWith_of_nnnorm_hasFDerivWithin_le + (fun x _ => (hG.differentiable (by norm_num) x).hasFDerivAt.hasFDerivWithinAt) + (fun x hx => by exact_mod_cast hbound x hx) + let T : s → s := fun x => ⟨x.val-ε • G x.val, hinvariant ε ⟨hε.le,hε1⟩ x.property⟩ + have hT : Continuous T := by + apply Continuous.subtype_mk + exact continuous_subtype_val.sub + (continuous_const.smul (hG.continuous.comp continuous_subtype_val)) + let ψ : s → ℝ := fun x => φ x.val + have hψ : Continuous ψ := + (continuous_iff_continuousAt.mpr fun x => (hgrad x).continuousAt).comp continuous_subtype_val + have hzero (x : s) : T x = x ↔ G x.val = 0 := by + rw [Subtype.ext_iff] + change x.val-ε • G x.val = x.val ↔ G x.val = 0 + simp only [sub_eq_self, smul_eq_zero, hε.ne', false_or] + have hstrict (x : s) (hx : T x ≠ x) : ψ (T x) < ψ x := by + exact gradient_step_strict_descent hconv (fun x _ => hgrad x) hLip hε hεM + x.property (T x).property (fun h => hx ((hzero x).mpr h)) + have hattract (p : s) (hp : T p = p) : + ∃ U : Set s, IsOpen U ∧ p ∈ U ∧ U ⊆ attractionBasin T p := by + let D := ContinuousLinearMap.id ℝ E - ε • fderiv ℝ G p.val + have hD : HasStrictFDerivAt (fun x : E => x-ε • G x) D p.val := + (hasStrictFDerivAt_id p.val).sub + ((hG.contDiffAt.hasStrictFDerivAt (by norm_num)).const_smul ε) + have hDn : ‖D‖ < 1 := gradient_step_derivative_norm_lt hc hM hε hεc hεM2 + (hcoercive p.val p.property ((hzero p).mp hp)) (hbound p.val p.property) + have hDnn : ‖D‖₊ < 1 := by exact_mod_cast hDn + obtain ⟨K, hDK, hK⟩ := exists_between hDnn + obtain ⟨U, hU, hULip⟩ := hD.exists_lipschitzOnWith_of_nnnorm_lt K hDK + have hpre : Subtype.val ⁻¹' U ∈ 𝓝 p := continuous_subtype_val.continuousAt.preimage_mem_nhds hU + have hpreLip : LipschitzOnWith K T (Subtype.val ⁻¹' U) := by + rw [lipschitzOnWith_iff_dist_le_mul] + intro x hx y hy + exact hULip.dist_le_mul x.val hx y.val hy + exact local_contraction_attracts hp hK hpre hpreLip + obtain ⟨p, hp, huniq⟩ := lyapunov_unique_fixed_point T hT ψ hψ hstrict hattract + exact ⟨p, (hzero p).mp hp, fun q hq => huniq q ((hzero q).mpr hq)⟩ + +end GradientRoots + +lemma weightedTapE_eq_zero_iff {n : ℕ} (j : ℝ) + (J : Matrix (Fin n) (Fin n) ℝ) (h : Field n) (y : EField n) : + weightedTapE j J h y = 0 ↔ tapField j J h (WithLp.ofLp y) = 0 := by + constructor + · intro hz + ext i + have he := congrArg (fun z : EField n => z i) hz + change spinVariance (WithLp.ofLp y) i * tapField j J h (WithLp.ofLp y) i = 0 at he + exact (mul_eq_zero.mp he).resolve_left (spinVariance_pos (WithLp.ofLp y) i).ne' + · intro hz + ext i + change spinVariance (WithLp.ofLp y) i * tapField j J h (WithLp.ofLp y) i = 0 + rw [hz, Pi.zero_apply, mul_zero] + +lemma weightedTapE_coercive_on_box {n : ℕ} (j : ℝ) + (J : Matrix (Fin n) (Fin n) ℝ) (h : Field n) {R c : ℝ} + (hR : 0 ≤ R) (hc : 0 ≤ c) (y : EField n) (hy : y ∈ fieldBoxE n R) + (hz : tapField j J h (WithLp.ofLp y) = 0) + (hH : ∀ x : Field n, c*vectorSqNorm x ≤ + quadraticForm (fieldHessian j J (WithLp.ofLp y) (spinVariance (WithLp.ofLp y))) x) + (v : EField n) : + (c / cosh R^2)*‖v‖^2 ≤ inner ℝ v (fderiv ℝ (weightedTapE j J h) y v) := by + rw [weightedTapE_derivative_energy j J h y v hz] + have hV := spinVariance_bound_on_box (WithLp.ofLp y) hR ((mem_fieldBoxE hR y).mp hy) + have hb : (1 / cosh R^2)*‖v‖^2 ≤ vectorSqNorm (sqrtVarianceMul (WithLp.ofLp y) (WithLp.ofLp v)) := by + rw [EuclideanSpace.real_norm_sq_eq] + simp only [vectorSqNorm, sqrtVarianceMul, Finset.mul_sum, mul_pow, + sq_sqrt (spinVariance_pos _ _).le] + apply Finset.sum_le_sum + intro i _ + exact mul_le_mul_of_nonneg_right (hV i) (sq_nonneg _) + have h := (mul_le_mul_of_nonneg_left hb hc).trans (hH _) + simpa only [mul_assoc, div_eq_mul_inv, one_mul] using h + +theorem tap_unique_zero {n : ℕ} (hn : 0 < n) {j c : ℝ} (hj : 0 ≤ j) (hc : 0 < c) + {J : Matrix (Fin n) (Fin n) ℝ} (hJ : J.IsSymm) (h : Field n) + (hH : ∀ y : Field n, tapField j J h y = 0 → ∀ x : Field n, + c*vectorSqNorm x ≤ quadraticForm (fieldHessian j J y (spinVariance y)) x) : + ∃! r : Field n, tapField j J h r = 0 := by + obtain ⟨R, hR, hbound⟩ := exists_tapBox_radius hn hj J h + have hco : ∀ y ∈ fieldBoxE n R, weightedTapE j J h y = 0 → ∀ v, + (c / cosh R^2)*‖v‖^2 ≤ inner ℝ v (fderiv ℝ (weightedTapE j J h) y v) := by + intro y hy hz v + have hz' := (weightedTapE_eq_zero_iff j J h y).mp hz + exact weightedTapE_coercive_on_box j J h hR.le hc.le y hy hz' (hH _ hz') v + have hmaps : ∀ ε ∈ Set.Icc (0:ℝ) 1, + Set.MapsTo (fun y => y-ε • weightedTapE j J h y) (fieldBoxE n R) (fieldBoxE n R) := by + intro ε hε y hy + rw [mem_fieldBoxE hR.le] at hy ⊢ + exact weightedTap_step_box j J h (WithLp.ofLp y) hε (hbound _) hy + obtain ⟨r, hr, huniq⟩ := gradient_unique_zero_on_compact + (isCompact_fieldBoxE n R) (nonempty_fieldBoxE n hR.le) (convex_fieldBoxE n R) + (tapPotentialE_hasFDerivAt j hJ h) (weightedTapE_contDiff j J h) + (show 0 < c / cosh R^2 by positivity) hco hmaps + refine ⟨WithLp.ofLp r.val, (weightedTapE_eq_zero_iff j J h r.val).mp hr, ?_⟩ + intro y hy + have hys : WithLp.toLp 2 y ∈ fieldBoxE n R := by + rw [mem_fieldBoxE hR.le] + intro i + have hb := hbound y i + simpa only [hy, Pi.zero_apply, sub_zero] using hb + have hye : weightedTapE j J h (WithLp.toLp 2 y) = 0 := + (weightedTapE_eq_zero_iff j J h (WithLp.toLp 2 y)).mpr hy + have he := congrArg (fun z : fieldBoxE n R => WithLp.ofLp z.val) + (huniq ⟨WithLp.toLp 2 y, hys⟩ hye) + exact he + +theorem inverseOnConvex_bound {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] + [FiniteDimensional ℝ E] [CompleteSpace E] {f : E → E} {U : Set E} + (hU : IsOpen U) (hconv : Convex ℝ U) (hf : ContDiff ℝ 1 f) + (hunique : ∀ z ∈ U, ∃! y, f y = z) {C : ℝ} (hC : 0 ≤ C) + (hbound : ∀ y, f y ∈ U → ∀ v, ‖v‖ ≤ C * ‖fderiv ℝ f y v‖) + {x y : E} (hx : f x ∈ U) (hy : f y ∈ U) : + ‖y-x‖ ≤ C * ‖f y-f x‖ := by + classical + let g : E → E := fun z => if hz : z ∈ U then (hunique z hz).choose else 0 + have hg (z : E) (hz : z ∈ U) : f (g z) = z := by + simp only [g, dite_eq_left hz] + exact (hunique z hz).choose_spec.1 + have hgf (z : E) (hz : f z ∈ U) : g (f z) = z := by + simp only [g, dite_eq_left hz] + exact ((hunique (f z) hz).choose_spec.2 z rfl).symm + have hinj (z : E) (hz : f z ∈ U) : Function.Injective (fderiv ℝ f z) := by + intro a b hab + apply sub_eq_zero.mp + apply norm_eq_zero.mp + have hh := hbound z hz (a-b) + rw [map_sub, hab, sub_self, norm_zero, mul_zero] at hh + exact le_antisymm hh (norm_nonneg _) + let D (z : E) : E →L[ℝ] E := fderiv ℝ f z + let e (z : E) (hz : f z ∈ U) : E ≃L[ℝ] E := + (LinearEquiv.ofInjectiveEndo (D z).toLinearMap (hinj z hz)).toContinuousLinearEquiv + have he (z : E) (hz : f z ∈ U) : (e z hz : E →L[ℝ] E) = D z := by + ext v + rfl + have hgder (z : E) (hz : z ∈ U) : + HasFDerivAt g ((e (g z) (by rw [hg z hz]; exact hz)).symm : E →L[ℝ] E) z := by + let p := g z + have hp : f p = z := hg z hz + have hpU : f p ∈ U := hp ▸ hz + have hder : HasStrictFDerivAt f (e p hpU : E →L[ℝ] E) p := by + rw [he p hpU] + exact hf.contDiffAt.hasStrictFDerivAt (by norm_num) + have hleft : ∀ᶠ w in 𝓝 p, g (f w) = w := by + filter_upwards [hf.continuous.continuousAt.preimage_mem_nhds (hU.mem_nhds hpU)] with w hw + exact hgf w hw + have H := (hder.to_local_left_inverse hleft).hasFDerivAt + simpa only [hp] using H + have hnorm (z : E) (hz : z ∈ U) : + ‖((e (g z) (by rw [hg z hz]; exact hz)).symm : E →L[ℝ] E)‖ ≤ C := by + apply ContinuousLinearMap.opNorm_le_bound _ hC + intro v + have hh := hbound (g z) (by rw [hg z hz]; exact hz) + ((e (g z) (by rw [hg z hz]; exact hz)).symm v) + change ‖_‖ ≤ C*‖D (g z) _‖ at hh + rw [← he (g z) (by rw [hg z hz]; exact hz)] at hh + simpa using hh + have hd : DifferentiableOn ℝ g U := fun z hz => (hgder z hz).differentiableAt.differentiableWithinAt + have hn : ∀ z ∈ U, ‖fderivWithin ℝ g U z‖ ≤ C := by + intro z hz + rw [(hgder z hz).hasFDerivWithinAt.fderivWithin (hU.uniqueDiffWithinAt hz)] + exact hnorm z hz + have H := hconv.norm_image_sub_le_of_norm_fderivWithin_le hd hn hx hy + simpa only [hgf x hx, hgf y hy] using H + +def tapFieldE {n : ℕ} (j : ℝ) (J : Matrix (Fin n) (Fin n) ℝ) + (h : Field n) (y : EField n) : EField n := + WithLp.toLp 2 (tapField j J h (WithLp.ofLp y)) + +lemma tapFieldE_contDiff {n : ℕ} {m : WithTop ℕ∞} (j : ℝ) + (J : Matrix (Fin n) (Fin n) ℝ) (h : Field n) : ContDiff ℝ m (tapFieldE j J h) := + (EuclideanSpace.equiv (ι := Fin n) (𝕜 := ℝ)).symm.contDiff.comp + ((tapField_contDiff j J h).comp + (EuclideanSpace.equiv (ι := Fin n) (𝕜 := ℝ)).contDiff) + +lemma norm_EField_eq {n : ℕ} (v : EField n) : ‖v‖ = vectorNorm (WithLp.ofLp v) := by + simp only [EuclideanSpace.norm_eq, vectorNorm, Real.norm_eq_abs, sq_abs] + +lemma tapFieldE_fderiv {n : ℕ} (j : ℝ) (J : Matrix (Fin n) (Fin n) ℝ) + (h : Field n) (y v : EField n) : + fderiv ℝ (tapFieldE j J h) y v = + WithLp.toLp 2 ((fieldJacobian j J (WithLp.ofLp y)).mulVec (WithLp.ofLp v)) := by + let e := EuclideanSpace.equiv (ι := Fin n) (𝕜 := ℝ) + have hd := e.symm.hasFDerivAt.comp y + ((tapField_hasFDerivAt j J h (WithLp.ofLp y)).comp y e.hasFDerivAt) + change HasFDerivAt (tapFieldE j J h) _ y at hd + rw [hd.fderiv] + rfl + +lemma vectorNorm_zero (n : ℕ) : vectorNorm (0 : Field n) = 0 := by + simp [vectorNorm] + +lemma tapField_shift {n : ℕ} (j : ℝ) (J : Matrix (Fin n) (Fin n) ℝ) + (h z y : Field n) : tapField j J (h+z) y = tapField j J h y-z := by + ext i + simp only [tapField, Pi.add_apply, Pi.sub_apply] + ring + +theorem tap_root_and_distance {n : ℕ} (hn : 0 < n) {j K c R : ℝ} + (hj : 0 ≤ j) (hK : 0 ≤ K) (hc : 0 < c) (hR : 0 < R) + {J : Matrix (Fin n) (Fin n) ℝ} (hJsymm : J.IsSymm) (h : Field n) + (hJ : ∀ z : Field n, vectorNorm (J.mulVec z) ≤ K*vectorNorm z) + (hH : ∀ y : Field n, vectorNorm (tapField j J h y) ≤ R → ∀ x : Field n, + c*vectorSqNorm x ≤ quadraticForm (fieldHessian j J y (spinVariance y)) x) : + ∃ r : Field n, tapField j J h r = 0 ∧ + (∀ y, tapField j J h y = 0 → y = r) ∧ + ∀ y, vectorNorm (tapField j J h y) < R → + vectorNorm (y-r) ≤ (1+(K+3*j)/c)*vectorNorm (tapField j J h y) := by + have hH0 : ∀ y : Field n, tapField j J h y = 0 → ∀ x : Field n, + c*vectorSqNorm x ≤ quadraticForm (fieldHessian j J y (spinVariance y)) x := by + intro y hy + apply hH y + simpa only [hy, vectorNorm_zero] using hR.le + obtain ⟨r, hr, huniq⟩ := tap_unique_zero hn hj hc hJsymm h hH0 + refine ⟨r, hr, huniq, ?_⟩ + intro y hy + let F := tapFieldE j J h + let U := Metric.ball (0 : EField n) R + have hmem (v : EField n) : F v ∈ U ↔ vectorNorm (tapField j J h (WithLp.ofLp v)) < R := by + simp only [U, Metric.mem_ball, dist_zero_right, F, norm_EField_eq, tapFieldE] + have hsurj : ∀ z ∈ U, ∃! v, F v = z := by + intro z hz + have hzn : vectorNorm (WithLp.ofLp z) < R := by + simpa only [U, Metric.mem_ball, dist_zero_right, norm_EField_eq] using hz + have hHz : ∀ v : Field n, tapField j J (h+WithLp.ofLp z) v = 0 → ∀ x : Field n, + c*vectorSqNorm x ≤ quadraticForm (fieldHessian j J v (spinVariance v)) x := by + intro v hv + rw [tapField_shift, sub_eq_zero] at hv + exact hH v (by rw [hv]; exact hzn.le) + obtain ⟨v, hv, huv⟩ := tap_unique_zero hn hj hc hJsymm (h+WithLp.ofLp z) hHz + have hv' : tapField j J h v = WithLp.ofLp z := by + simpa only [tapField_shift, sub_eq_zero] using hv + refine ⟨WithLp.toLp 2 v, ?_, ?_⟩ + · change WithLp.toLp 2 (tapField j J h v) = z + rw [hv', WithLp.toLp_ofLp] + · intro w hw + apply (WithLp.ofLp_injective 2) + apply huv + rw [tapField_shift, sub_eq_zero] + exact congrArg WithLp.ofLp hw + have hbound : ∀ v, F v ∈ U → ∀ w, ‖w‖ ≤ (1+(K+3*j)/c)*‖fderiv ℝ F v w‖ := by + intro v hv w + rw [tapFieldE_fderiv, norm_EField_eq, norm_EField_eq] + exact fieldJacobian_inverse_bound hn hc hj hK J (WithLp.ofLp v) (WithLp.ofLp w) + hJ (hH _ ((hmem v).mp hv).le) + have hrmem : F (WithLp.toLp 2 r) ∈ U := by + rw [hmem] + simpa only [WithLp.ofLp_toLp, hr, vectorNorm_zero] using hR + have hymem : F (WithLp.toLp 2 y) ∈ U := (hmem _).mpr hy + have H := inverseOnConvex_bound Metric.isOpen_ball (convex_ball _ _) (tapFieldE_contDiff j J h) + hsurj (show 0 ≤ 1+(K+3*j)/c by positivity) hbound hrmem hymem + simpa only [norm_EField_eq, WithLp.ofLp_sub, WithLp.ofLp_toLp, F, tapFieldE, hr, + sub_zero, WithLp.toLp_zero] using H + +end SKGap + +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Stability/UniformOrdinary.lean b/lean/OAI/Probability/SKGap/Stability/UniformOrdinary.lean new file mode 100644 index 0000000000000000000000000000000000000000..08da2b8359215093efd66969bee52c13920cab0f --- /dev/null +++ b/lean/OAI/Probability/SKGap/Stability/UniformOrdinary.lean @@ -0,0 +1,65 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.ResidualMultiplier +import OAI.Probability.SKGap.Matrix.RecipeWordEvent +import OAI.Probability.SKGap.Matrix.PrimaryWordControl + +namespace OAI + +section + +noncomputable section +open scoped BigOperators Matrix.Norms.Frobenius +namespace SKGapCutoff.Recipe +open Primary SKGap.Noncrossing SKGap.Noncrossing.Primary SKGap.Noncrossing.Primary.MarkedPolynomial Static +universe u +variable {Ω : Type u} {n : Ω→ℕ} +variable {ι κ σ : Type*} [Fintype ι] [DecidableEq ι] [Fintype κ] [DecidableEq κ] [Fintype σ] + +theorem uniform_ordinary_control (D : ∀a,OrdinaryData (n a) ι κ σ) + (T : ∀a,Spin (n a)→ι→SourceTree (Fin (n a)→ℝ)) + (N L : ℕ) (c : LocalConstants) (j : ℝ) (hj : ∀a,(D a).j=j) + (h : ∀a x,LocalOrdinaryInput (D a) (T a x) x N c) + {M B Q : ℝ} (hM : 0≤M) (hB : 0≤B) (hQ : 0≤Q) + (hm : ∀a x l,mass ((T a x l).words j).1≤Q ∧ mass ((T a x l).words j).2≤Q) + (hT : ∀a x l,PolynomialControl c.A L ((T a x l).words j).1 ∧ + PolynomialControl c.A L ((T a x l).words j).2) + (hw : ∀a,WordTestBound (D a).J c.A M (2*N+3)) + (hd : ∀a,WordDiagramBound (D a).J j c.A B (L+2*N+2)) : + ∃C : ℝ,0≤C ∧ ∀a x, + SmallBound ((D a).source N) x C ∧ + (∀l,SmallBound ((D a).sourcePartial N l) x C) ∧ + (∑i,|derivativeMatrix ((D a).source N) x i i|)≤C := by + let W:=c.normBudget j (Fintype.card ι) + let R:=errorBudget (|j| *c.A) (c.sourceCost j (Fintype.card ι) (Fintype.card σ)) + (c.fieldCost j (Fintype.card ι)) + let V:=traceBudget ((Fintype.card ι:ℝ)*((2+|j|)*Q)) (2+|j| *c.A) W + let C:=|W N|+|V N*B+(R N).1*M| + have hW : W N≤C := (le_abs_self _).trans (le_add_of_nonneg_right (abs_nonneg _)) + have hR : V N*B+(R N).1*M≤C := (le_abs_self _).trans (le_add_of_nonneg_left (abs_nonneg _)) + refine ⟨C,by dsimp [C]; positivity,fun a x=>?_⟩ + have hh:=(D a).ordinary_word_closure (T a x) x N L c (h a x) hM hB hQ + (by simpa only [hj a] using hm a x) (by simpa only [hj a,PolynomialControl] using hT a x) (hw a) + (by simpa only [hj a] using hd a) N le_rfl + rw [hj a] at hh + have hp:=(h a x).small N le_rfl + rw [hj a] at hp + exact ⟨hh.1.mono hW,fun l=>(hp.2.2 l).mono hW,hh.2.2.1.trans hR⟩ + +theorem uniform_auxiliary_mean (D : ∀a,OrdinaryData (n a) ι κ σ) + (T : ∀a,Spin (n a)→ι→SourceTree (Fin (n a)→ℝ)) (N : ℕ) (c : LocalConstants) + (h : ∀a x,LocalOrdinaryInput (D a) (T a x) x N c) (b : Fin N) : + UniformMultiplier (fun a=>siteMean ((D a).auxCoefficient N b)) := by + refine ⟨c.A,c.row (Fintype.card ι),c.A_nonneg,c.row_nonneg _, + fun a x=>(h a x).mean_bound N le_rfl b,fun a x=>?_⟩ + have hm:=coefficient_mean_difference ((D a).auxCoefficient N b) x (c.row_nonneg _) + ((h a x).aux_bound N le_rfl b).difference + have hs:=pow_le_pow_left₀ (norm_nonneg _) hm 2 + rw [EuclideanSpace.real_norm_sq_eq] at hs + exact hs + +end SKGapCutoff.Recipe + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Stability/WordDiagStable.lean b/lean/OAI/Probability/SKGap/Stability/WordDiagStable.lean new file mode 100644 index 0000000000000000000000000000000000000000..ac5848d1a8388bd902fbd96ca7a45de40184bbaf --- /dev/null +++ b/lean/OAI/Probability/SKGap/Stability/WordDiagStable.lean @@ -0,0 +1,71 @@ +import Mathlib +import OAI.Probability.SKGap.Stability.WordStableAgreement +import OAI.Probability.SKGap.Matrix.GOEDiagonalSquare + +namespace OAI + +section +noncomputable section +namespace SKGap +open Matrix Real Set MeasureTheory ProbabilityTheory Filter +open RealComplex +open scoped BigOperators Matrix.Norms.Frobenius SchwartzMap Topology + +theorem zeroDiag_exact_word_simultaneous_prediction {j A D c : ℝ} (hj : 0gaussianReal 0 1)) + {g | opNorm (removeDiagonal (goeMatrix (j/n) g))≤2*sqrt j+1+1 ∧ + ∃ (a : Fin n→ℝ) (F : List (WordLetter (Fin n))), + (∀ i,a i∈Icc 0 A) ∧ F.length≤L ∧ (∀ l∈F,l.bounded D) ∧ inverseCount F≤1 ∧ + c≤ComplexSpectral.lowerRayleigh (liftMatrix (stabilityMatrix a 1 + ((j/(n:ℝ))*∑ b,a b) (removeDiagonal (goeMatrix (j/n) g)))) ∧ + C< matrixWordSeminorm p + (exactWord j a F (removeDiagonal (goeMatrix (j/n) g))-Matrix.diagonal (wordPrediction j a 1 F))} ≤ + (wordPatternSet L L).card*ENNReal.ofReal (3*exp (-(n:ℝ)))+ + ENNReal.ofReal (exp (-2*(n:ℝ)/(π^2*(sqrt (2*j))^2))) := by + let R := 2*sqrt j+1+1 + let lo := min c ((1-sqrt j*A)^2/4) + let hi := 2+A*(R+j*A) + have hR : 0≤R := by dsimp [R];positivity + have hint := path_interval hj.le hA.le hs + have hlo : 0(ha i).1 + have haA : ∀ i,a i≤A := fun i=>(ha i).2 + have hq := diagonal_mean_bounds hj.le haq haA + simp only [Fintype.card_fin] at hq + have hb := stabilityMatrix_opNorm haq haA hA.le (show (1:ℝ)∈Icc 0 1 from ⟨zero_le_one,le_rfl⟩) hq.1 hMR + have hnrm : opNorm (stabilityMatrix a 1 ((j/(n:ℝ))*∑ b,a b) (removeDiagonal (goeMatrix (j/n) g)))≤hi := by + apply hb.trans + dsimp [hi,R] + nlinarith + have hu : -hi≤ComplexSpectral.lowerRayleigh (-liftMatrix (stabilityMatrix a 1 + ((j/(n:ℝ))*∑ b,a b) (removeDiagonal (goeMatrix (j/n) g)))) := + (neg_le_neg hnrm).trans (lowerRayleigh_neg_lift_ge _) + have hl : lo≤ComplexSpectral.lowerRayleigh (liftMatrix (stabilityMatrix a 1 + ((j/(n:ℝ))*∑ b,a b) (removeDiagonal (goeMatrix (j/n) g)))) := (min_le_left _ _).trans hstable + rw [stabilityMatrix_path_rep a haq zero_le_one] at hl hu + have he := actualWord_agrees f hlo hf hR j haq (removeDiagonal (goeMatrix (j/n) g)) + (by simp [removeDiagonal,Matrix.transpose_sub,goeMatrix_transpose]) hMR (by simpa only [Fintype.card_fin] using hl) + (by simpa only [Fintype.card_fin] using hu) F + rwa [he] +end SKGap +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Stability/WordMeanSeminorm.lean b/lean/OAI/Probability/SKGap/Stability/WordMeanSeminorm.lean new file mode 100644 index 0000000000000000000000000000000000000000..109c979c578d8dc2ac94aae7c1045ba25712edb1 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Stability/WordMeanSeminorm.lean @@ -0,0 +1,81 @@ +import Mathlib +import OAI.Probability.SKGap.Matrix.WordTemplateSurjective +import OAI.Probability.SKGap.Matrix.WordBaseBias + +namespace OAI + +section +noncomputable section +namespace SKGap +open Matrix Real Set MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix.Norms.Frobenius SchwartzMap +variable {ι : Type*} [Fintype ι] [DecidableEq ι] +local instance : Fact (1≤(4:ENNReal)) := ⟨by norm_num⟩ + +lemma actualWord_mean_diagonal (f : 𝓢(ℝ,ℂ)) {R : ℝ} (hR : 0≤R) (j : ℝ) + (a : ι→ℝ) (z : ℝ) (F : List (WordLetter ι)) : + matrixEntryMean (fun x : EuclideanSpace ℝ (MatrixCoordinates ι)=> + actualWord f R hR j a z F (goeMatrix (j/(Fintype.card ι:ℝ)) x))= + Matrix.diagonal (wordExpected f hR j a z F) := by + ext i k + by_cases h : i=k + · subst k + simp only [matrixEntryMean,Matrix.diagonal_apply_eq,wordExpected] + · rw [Matrix.diagonal_apply_ne _ h] + exact actualWord_offdiag_mean f hR j _ a z F i k h + +lemma offDiagonalSeminorm_sub_diagonal (M : Matrix ι ι ℝ) (d : ι→ℝ) : + offDiagonalSeminorm (M-Matrix.diagonal d)=offDiagonalSeminorm M := by + change ‖offDiagonalVector (M-Matrix.diagonal d)‖=‖offDiagonalVector M‖ + apply congrArg norm + ext p + simp only [offDiagonalVector,WithLp.ofLp_toLp,Matrix.sub_apply] + split_ifs with h + · rfl + · simp only [Matrix.diagonal_apply_ne _ h,sub_zero] + +lemma offDiagonalSeminorm_diagonal (d : ι→ℝ) : + offDiagonalSeminorm (Matrix.diagonal d)=0 := by + have he : offDiagonalVector (Matrix.diagonal d)=0 := by + ext p + simp only [offDiagonalVector,WithLp.ofLp_toLp,PiLp.zero_apply] + split_ifs with h + · rfl + · exact Matrix.diagonal_apply_ne _ h + change ‖offDiagonalVector (Matrix.diagonal d)‖=0 + rw [he,norm_zero] + +lemma diagonalSeminorm_diagonal_bound {n : ℕ} (hn : 1≤n) {C : ℝ} (hC : 0≤C) + {d : Fin n→ℝ} (hd : ∀ i,|d i|≤C/(n:ℝ)) : + diagonalSeminorm (Matrix.diagonal d)≤C := by + have hnr : (1:ℝ)≤n := by exact_mod_cast hn + have hn0 : (0:ℝ)hi i) + _ = C^2/(n:ℝ) := by simp only [Finset.sum_const,Finset.card_univ,Fintype.card_fin,nsmul_eq_mul];field_simp + _ ≤ C^2 := (div_le_self (sq_nonneg _) hnr) + +lemma actualWord_diagonal_prediction_decompose (f : 𝓢(ℝ,ℂ)) {R j : ℝ} (hR : 0≤R) + (a : ι→ℝ) (z : ℝ) (F : List (WordLetter ι)) (g : MatrixCoordinates ι→ℝ) : + actualWord f R hR j a z F (goeMatrix (j/(Fintype.card ι:ℝ)) g)- + Matrix.diagonal (wordPrediction j a z F)= + matrixCentered (fun x : EuclideanSpace ℝ (MatrixCoordinates ι)=>actualWord f R hR j a z F + (goeMatrix (j/(Fintype.card ι:ℝ)) x)) (WithLp.toLp 2 g)+ + Matrix.diagonal (fun i=>wordExpected f hR j a z F i-wordPrediction j a z F i) := by + rw [matrixCentered,actualWord_mean_diagonal] + ext i k + by_cases h : i=k + · subst k + simp only [Matrix.sub_apply,Matrix.add_apply,Matrix.diagonal_apply_eq] + ring + · simp only [Matrix.sub_apply,Matrix.add_apply,Matrix.diagonal_apply_ne _ h,sub_zero,add_zero] +end SKGap +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Stability/WordOrdinaryAgreement.lean b/lean/OAI/Probability/SKGap/Stability/WordOrdinaryAgreement.lean new file mode 100644 index 0000000000000000000000000000000000000000..a7d1f9c362435ff746bb1078330f32cdaba39021 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Stability/WordOrdinaryAgreement.lean @@ -0,0 +1,36 @@ +import Mathlib +import OAI.Probability.SKGap.Stability.WordStableAgreement +import OAI.Probability.SKGap.Matrix.MarkedWordIBP + +namespace OAI + +section +noncomputable section +namespace SKGap +open Matrix Real Set +open RealComplex +open scoped BigOperators Matrix.Norms.Frobenius SchwartzMap +variable {ι : Type*} [Fintype ι] [DecidableEq ι] + +lemma actualWord_agrees_no_inverse (f : 𝓢(ℝ,ℂ)) {R : ℝ} (hR : 0≤R) + (j : ℝ) (a : ι→ℝ) (M : Matrix ι ι ℝ) (hM : Mᵀ=M) (hMR : opNorm M≤R) + (F : List (WordLetter ι)) (hF : inverseCount F=0) : + actualWord f R hR j a 1 F M=exactWord j a F M := by + induction F with + | nil => rfl + | cons l F ih => + cases l with + | inverse => simp [inverseCount] at hF + | diag d => + have ht : inverseCount F=0 := by simpa [inverseCount] using hF + change diagonal d*actualWord f R hR j a 1 F M=diagonal d*exactWord j a F M + rw [ih ht] + | noise => + have ht : inverseCount F=0 := by simpa [inverseCount] using hF + change realProject R hR M*actualWord f R hR j a 1 F M=M*exactWord j a F M + rw [realProject_eq_self hR M hM hMR,ih ht] +end SKGap +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Stability/WordPredictionStability.lean b/lean/OAI/Probability/SKGap/Stability/WordPredictionStability.lean new file mode 100644 index 0000000000000000000000000000000000000000..662c1a618a8c58ae8e80870bf7439a657c6327e0 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Stability/WordPredictionStability.lean @@ -0,0 +1,127 @@ +import Mathlib +import OAI.Probability.SKGap.Matrix.WordLoop + +namespace OAI + +section +noncomputable section +namespace SKGap +open Real Matrix Set +open scoped BigOperators +variable {ι : Type*} [Fintype ι] [Nonempty ι] + +def wordAverage (e : List (WordLetter ι)→ι→ℝ) (F : List (WordLetter ι)) : ℝ := + (∑ k,e F k)/(Fintype.card ι:ℝ) +def wordRecursionValue (j : ℝ) (a : ι→ℝ) (z : ℝ) + (e : List (WordLetter ι)→ι→ℝ) (F : List (WordLetter ι)) (i : ι) : ℝ := + ((wordRecursionTerms a F).map (fun t=>(if t.inversePartner then z else 1)*j* + wordAverage e t.inner*e t.outer i)).sum + +lemma wordAverage_abs_le (e : List (WordLetter ι)→ι→ℝ) (F : List (WordLetter ι)) + {B : ℝ} (hB : ∀ i,|e F i|≤B) : |wordAverage e F|≤B := by + have hn : (0:ℝ)hB i) + _ = _ := by simp [mul_comm] + +lemma wordAverage_sub_abs_le (e p : List (WordLetter ι)→ι→ℝ) (F : List (WordLetter ι)) + {E : ℝ} (hE : ∀ i,|e F i-p F i|≤E) : |wordAverage e F-wordAverage p F|≤E := by + have hh := wordAverage_abs_le (fun G i=>e G i-p G i) F hE + simpa only [wordAverage,Finset.sum_sub_distrib,sub_div] using hh + +omit [Fintype ι] [Nonempty ι] in +lemma abs_list_difference_le (C : List ι) (p q : ι→ℝ) {E : ℝ} + (h : ∀ c∈C,|p c-q c|≤E) : |(C.map p).sum-(C.map q).sum|≤(C.length:ℝ)*E := by + induction C with + | nil => simp + | cons c C ih => + have hh := ih (fun c hc=>h c (List.mem_cons_of_mem _ hc)) + simp only [List.map_cons,List.sum_cons,List.length_cons,Nat.cast_add,Nat.cast_one] + calc + |(p c+(C.map p).sum)-(q c+(C.map q).sum)|= + |(p c-q c)+((C.map p).sum-(C.map q).sum)| := by congr 1;ring + _ ≤ |p c-q c|+|(C.map p).sum-(C.map q).sum| := abs_add_le _ _ + _ ≤ E+(C.length:ℝ)*E := add_le_add (h c List.mem_cons_self) hh + _ = _ := by ring + +omit [Nonempty ι] in +lemma wordPrediction_recursion (j : ℝ) (a : ι→ℝ) (z : ℝ) (F : List (WordLetter ι)) (i : ι) + (hO : ordinaryCount F≠0) : + wordPrediction j a z F i=wordRecursionValue j a z (wordPrediction j a z) F i := by + rw [wordPrediction,ite_eq_right hO] + simp only [wordRecursionValue,wordAverage] + apply congrArg List.sum + exact List.attach_map_val (l:=wordRecursionTerms a F) (f:=fun (t : WordRecursionTerm ι)=> + (if t.inversePartner then z else 1)*j*((∑ k,wordPrediction j a z t.inner k)/(Fintype.card ι:ℝ))*wordPrediction j a z t.outer i) + +omit [Nonempty ι] in +lemma wordPrediction_base (j : ℝ) (a : ι→ℝ) (z : ℝ) (F : List (WordLetter ι)) (i : ι) + (hO : ordinaryCount F=0) : wordPrediction j a z F i=wordDiagonal F i := by + rw [wordPrediction,ite_eq_left hO] + +omit [Fintype ι] [Nonempty ι] in +lemma scalar_product_prediction_error {u v p q B δ E : ℝ} + (hB : 0≤B) (hδ : 0≤δ) (hE : δ≤E) + (hu : |u|≤B) (hv : |v|≤B) (hup : |u-p|≤δ) (hvq : |v-q|≤δ) : + |u*v-p*q|≤(2*B+E)*δ := by + have he : u*v-p*q=u*(v-q)+(u-p)*q := by ring + have hq : |q|≤B+δ := by + calc + |q|=|v-(v-q)| := by congr 1;ring + _ ≤ |v|+|v-q| := abs_sub _ _ + _ ≤ B+δ := add_le_add hv hvq + rw [he] + calc + |u*(v-q)+(u-p)*q| ≤ |u*(v-q)|+|(u-p)*q| := abs_add_le _ _ + _ = |u| *|v-q|+|u-p| *|q| := by rw [abs_mul,abs_mul] + _ ≤ B*δ+δ*(B+δ) := add_le_add (mul_le_mul hu hvq (abs_nonneg _) hB) + (mul_le_mul hup hq (abs_nonneg _) hδ) + _ ≤ (2*B+E)*δ := by nlinarith [mul_nonneg hδ (sub_nonneg.mpr hE)] + +theorem wordRecursionValue_stability {j z n B E : ℝ} (hj : 0≤j) + (hz : z∈Icc (0:ℝ) 1) (hn : 1≤n) (hB : 0≤B) (hE : 0≤E) + (a : ι→ℝ) (F : List (WordLetter ι)) (p q : List (WordLetter ι)→ι→ℝ) + (hb : ∀ t∈wordRecursionTerms a F,∀ i,|p t.inner i|≤B ∧ |p t.outer i|≤B) + (he : ∀ t∈wordRecursionTerms a F,∀ i,|p t.inner i-q t.inner i|≤E/n ∧ + |p t.outer i-q t.outer i|≤E/n) (i : ι) : + |wordRecursionValue j a z p F i-wordRecursionValue j a z q F i|≤ + (F.length:ℝ)*j*(2*B+E)*E/n := by + have hn0 : 0(hb t ht k).1) + have hep := wordAverage_sub_abs_le p q t.inner (fun k=>(he t ht k).1) + have hh := scalar_product_prediction_error hB hd hdn hp (hb t ht i).2 hep (he t ht i).2 + have hcoef : |if t.inversePartner then z else 1|≤1 := by + split + · rw [abs_of_nonneg hz.1]; exact hz.2 + · simp + have hcj : |(if t.inversePartner then z else 1)*j|≤j := by + rw [abs_mul,abs_of_nonneg hj] + exact (mul_le_mul_of_nonneg_right hcoef hj).trans_eq (one_mul _) + calc + _=|(if t.inversePartner then z else 1)*j| * + |wordAverage p t.inner*p t.outer i-wordAverage q t.inner*q t.outer i| := by + rw [← abs_mul] + congr 1 + ring + _ ≤ j*((2*B+E)*(E/n)) := mul_le_mul hcj hh (abs_nonneg _) hj + _ = _ := by ring + have hh := abs_list_difference_le (wordRecursionTerms a F) _ _ hterm + have hcard : ((wordRecursionTerms a F).length:ℝ)≤F.length := by + exact_mod_cast wordRecursionTerms_card_bound a F + apply hh.trans + have hm := mul_le_mul_of_nonneg_right hcard (show 0≤j*(2*B+E)*E/n by positivity) + simpa only [mul_div_assoc,mul_assoc] using hm +end SKGap +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Stability/WordStableAgreement.lean b/lean/OAI/Probability/SKGap/Stability/WordStableAgreement.lean new file mode 100644 index 0000000000000000000000000000000000000000..4f6b5b6fc8f7098ba18e51669f66b44deed6b90e --- /dev/null +++ b/lean/OAI/Probability/SKGap/Stability/WordStableAgreement.lean @@ -0,0 +1,46 @@ +import Mathlib +import OAI.Probability.SKGap.Brownian.PathAgreement +import OAI.Probability.SKGap.Matrix.Word + +namespace OAI + +section +noncomputable section +namespace SKGap +open Matrix Real Set +open RealComplex +open scoped BigOperators Matrix.Norms.Frobenius SchwartzMap +variable {ι : Type*} [Fintype ι] [DecidableEq ι] + +def WordLetter.exactEval (j : ℝ) (a : ι→ℝ) : WordLetter ι→Matrix ι ι ℝ→Matrix ι ι ℝ + | .diag d,_ => diagonal d + | .noise,M => M + | .inverse,M => (1-diagonal a*(M-((j/(Fintype.card ι:ℝ))*∑ b,a b) • 1))⁻¹ + +def exactWord (j : ℝ) (a : ι→ℝ) (F : List (WordLetter ι)) (M : Matrix ι ι ℝ) : Matrix ι ι ℝ := + matrixFactorProduct (F.map (WordLetter.exactEval j a)) M + +theorem actualWord_agrees [Nonempty ι] (f : 𝓢(ℝ,ℂ)) {lo hi : ℝ} (hlo : 0 rfl + | noise => exact realProject_eq_self hR M hM hMR + | inverse => exact pathK_agrees f hlo hf hR j ha M hM hMR hl hu + induction F with + | nil => rfl + | cons l F ih => + change l.eval f R hR j a 1 M*actualWord f R hR j a 1 F M=l.exactEval j a M*exactWord j a F M + rw [he,ih] +end SKGap +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Stability/WordStablePrediction.lean b/lean/OAI/Probability/SKGap/Stability/WordStablePrediction.lean new file mode 100644 index 0000000000000000000000000000000000000000..4d276521622399d9e9c9b9952c77f1476591608a --- /dev/null +++ b/lean/OAI/Probability/SKGap/Stability/WordStablePrediction.lean @@ -0,0 +1,70 @@ +import Mathlib +import OAI.Probability.SKGap.Stability.WordStableAgreement +import OAI.Probability.SKGap.Matrix.WordBiasCutoff + +namespace OAI + +section +noncomputable section +namespace SKGap +open Matrix Real Set MeasureTheory ProbabilityTheory Filter +open RealComplex +open scoped BigOperators Matrix.Norms.Frobenius SchwartzMap Topology + +theorem exact_word_simultaneous_prediction {j A D c : ℝ} (hj : 0gaussianReal 0 1)) + {g | opNorm (goeMatrix (j/n) g)≤2*sqrt j+1+1 ∧ + ∃ (a : Fin n→ℝ) (F : List (WordLetter (Fin n))), + (∀ i,a i∈Icc 0 A) ∧ F.length≤L ∧ (∀ l∈F,l.bounded D) ∧ inverseCount F≤1 ∧ + c≤ComplexSpectral.lowerRayleigh (liftMatrix (stabilityMatrix a 1 + ((j/(n:ℝ))*∑ b,a b) (goeMatrix (j/n) g))) ∧ + C< matrixWordSeminorm p + (exactWord j a F (goeMatrix (j/n) g)-Matrix.diagonal (wordPrediction j a 1 F))} ≤ + (wordPatternSet L L).card*ENNReal.ofReal (3*exp (-(n:ℝ))) := by + let R := 2*sqrt j+1+1 + let lo := min c ((1-sqrt j*A)^2/4) + let hi := 2+A*(R+j*A) + have hR : 0≤R := by dsimp [R];positivity + have hint := path_interval hj.le hA.le hs + have hlo : 0(ha i).1 + have haA : ∀ i,a i≤A := fun i=>(ha i).2 + have hq := diagonal_mean_bounds hj.le haq haA + simp only [Fintype.card_fin] at hq + have hb := stabilityMatrix_opNorm haq haA hA.le (show (1:ℝ)∈Icc 0 1 from ⟨zero_le_one,le_rfl⟩) hq.1 hMR + have hnrm : opNorm (stabilityMatrix a 1 ((j/(n:ℝ))*∑ b,a b) (goeMatrix (j/n) g))≤hi := by + apply hb.trans + dsimp [hi,R] + nlinarith + have hu : -hi≤ComplexSpectral.lowerRayleigh (-liftMatrix (stabilityMatrix a 1 + ((j/(n:ℝ))*∑ b,a b) (goeMatrix (j/n) g))) := + (neg_le_neg hnrm).trans (lowerRayleigh_neg_lift_ge _) + have hl : lo≤ComplexSpectral.lowerRayleigh (liftMatrix (stabilityMatrix a 1 + ((j/(n:ℝ))*∑ b,a b) (goeMatrix (j/n) g))) := (min_le_left _ _).trans hstable + rw [stabilityMatrix_path_rep a haq zero_le_one] at hl hu + have he := actualWord_agrees f hlo hf hR j haq (goeMatrix (j/n) g) + (goeMatrix_transpose _ _) hMR (by simpa only [Fintype.card_fin] using hl) + (by simpa only [Fintype.card_fin] using hu) F + rwa [he] +end SKGap +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Terminal/ConsDiag.lean b/lean/OAI/Probability/SKGap/Terminal/ConsDiag.lean new file mode 100644 index 0000000000000000000000000000000000000000..bfc2f87f6c1015b400e459842918b950924edfc1 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Terminal/ConsDiag.lean @@ -0,0 +1,150 @@ +import Mathlib +import OAI.Probability.SKGap.Stability.Ordinary + +namespace OAI + +section +noncomputable section +noncomputable section +open scoped BigOperators +noncomputable section +noncomputable section +noncomputable section +open scoped BigOperators +noncomputable section +open scoped BigOperators +noncomputable section +open scoped BigOperators +noncomputable section +open scoped BigOperators +noncomputable section +open scoped BigOperators +noncomputable section +open scoped BigOperators +noncomputable section +open scoped BigOperators +noncomputable section +open scoped BigOperators +noncomputable section +open scoped BigOperators +namespace SKGap.Noncrossing +namespace Diagram +variable {D : Type*} + +def Paired.consDiag (a : D) (F : List (Letter D)) (d : Paired F) : Paired (.diag a::F) := + ⟨.diag a d.val,by simp [word,d.property]⟩ +lemma Paired.consDiag_bijective (a : D) (F : List (Letter D)) : + Function.Bijective (Paired.consDiag a F) := by + constructor + · intro d e h + apply Subtype.ext + exact (Diagram.diag.inj (congrArg Subtype.val h)).2 + · intro ⟨d,hd⟩ + cases d with + | nil => simp [word] at hd + | arch u v => simp [word] at hd + | diag b d => + change Letter.diag b::d.word=Letter.diag a::F at hd + obtain ⟨hab,hword⟩ := List.cons.inj hd + have hab := Letter.diag.inj hab + subst b + exact ⟨⟨d,hword⟩,rfl⟩ +def Paired.consDiagEquiv (a : D) (F : List (Letter D)) : Paired F ≃ Paired (.diag a::F) := + Equiv.ofBijective _ (Paired.consDiag_bijective a F) +def Paired.appendDiag (a : D) (F : List (Letter D)) (d : Paired F) : Paired (F++[.diag a]) := + ⟨d.val.append (.diag a .nil),by simp [append_word,d.property,word]⟩ +lemma Paired.appendDiag_bijective (a : D) (F : List (Letter D)) : + Function.Bijective (Paired.appendDiag a F) := by + constructor + · intro d e h + apply Subtype.ext + exact append_last_diag_injective a (congrArg Subtype.val h) + · intro ⟨d,hd⟩ + obtain ⟨e,he,hde⟩ := remove_last_diag d F a hd + exact ⟨⟨e,he⟩,Subtype.ext hde.symm⟩ +def Paired.appendDiagEquiv (a : D) (F : List (Letter D)) : Paired F ≃ Paired (F++[.diag a]) := + Equiv.ofBijective _ (Paired.appendDiag_bijective a F) +instance pairedNilUnique : Unique (Paired ([] : List (Letter D))) where + default := ⟨.nil,rfl⟩ + uniq d := by + apply Subtype.ext + have h := d.property + cases hd : d.val <;> simp_all [word] + +variable {ι : Type*} [Fintype ι] +@[simp] lemma expect_nil (j : ℝ) (v : D→ι→ℝ) (i : ι) : expect j v [] i=1 := by + rw [expect,Fintype.sum_unique] + rfl +@[simp] lemma expect_cons_diag (j : ℝ) (v : D→ι→ℝ) (a : D) (F : List (Letter D)) (i : ι) : + expect j v (.diag a::F) i=v a i*expect j v F i := by + unfold expect + rw [Finset.mul_sum] + symm + apply Fintype.sum_equiv (Paired.consDiagEquiv a F) + intro d + rfl +@[simp] lemma expect_append_diag (j : ℝ) (v : D→ι→ℝ) (a : D) (F : List (Letter D)) (i : ι) : + expect j v (F++[.diag a]) i=expect j v F i*v a i := by + unfold expect + rw [Finset.sum_mul] + symm + apply Fintype.sum_equiv (Paired.appendDiagEquiv a F) + intro d + simp [Paired.appendDiagEquiv,Paired.appendDiag,evaluate,map_append,map,value_append,value] +end Diagram +namespace WordSeries +open Diagram InverseDiagram +variable {ι : Type*} [Fintype ι] +@[simp] lemma ordinary_nil (j : ℝ) (i : ι) : ordinary j [] i=1 := expect_nil j id i +@[simp] lemma ordinary_cons_diag (j : ℝ) (d : ι→ℝ) (F : List (Letter (ι→ℝ))) (i : ι) : + ordinary j (.diag d::F) i=d i*ordinary j F i := expect_cons_diag j id d F i +@[simp] lemma ordinary_append_diag (j : ℝ) (d : ι→ℝ) (F : List (Letter (ι→ℝ))) (i : ι) : + ordinary j (F++[.diag d]) i=ordinary j F i*d i := expect_append_diag j id d F i + +lemma ordinary_diag_prefix (j : ℝ) (D : List (ι→ℝ)) (F : List (Letter (ι→ℝ))) (i : ι) : + ordinary j (D.map Letter.diag++F) i=(D.map (fun d=>d i)).prod*ordinary j F i := by + induction D with + | nil => simp + | cons d D ih => simp [ih,mul_assoc] +lemma ordinary_diag_suffix (j : ℝ) (D : List (ι→ℝ)) (F : List (Letter (ι→ℝ))) (i : ι) : + ordinary j (F++D.map Letter.diag) i=ordinary j F i*(D.map (fun d=>d i)).prod := by + induction D using List.reverseRecOn with + | nil => simp + | append_singleton D d ih => + simp only [List.map_append,List.map_singleton,List.prod_append,List.prod_singleton] + rw [← List.append_assoc,ordinary_append_diag,ih,mul_assoc] +lemma inverseCoefficient_diagonal (j : ℝ) (a : ι→ℝ) (P Q : List (ι→ℝ)) (n : ℕ) (i : ι) : + inverseCoefficient j a (P.map Letter.diag) (Q.map Letter.diag) n i= + if n=0 then (P.map (fun d=>d i)).prod*(Q.map (fun d=>d i)).prod else 0 := by + have he : inverseCoefficient j a (P.map Letter.diag) (Q.map Letter.diag) n i= + (P.map (fun d=>d i)).prod*inverseCoefficient j a [] [] n i*(Q.map (fun d=>d i)).prod := by + simp only [inverseCoefficient,List.nil_append,List.append_nil,Finset.mul_sum,Finset.sum_mul] + apply Finset.sum_congr rfl + intro bs _ + rw [List.append_assoc,ordinary_diag_prefix,ordinary_diag_suffix] + ring + rw [he,inverseCoefficient_empty] + split_ifs <;> ring +end WordSeries +end SKGap.Noncrossing + +noncomputable section +open scoped BigOperators + +end +end +end +end +end +end +end +end +end +end +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Terminal/FieldGibbs.lean b/lean/OAI/Probability/SKGap/Terminal/FieldGibbs.lean new file mode 100644 index 0000000000000000000000000000000000000000..6b6452f76bfc1dec8cea7bacdd42182898b69da1 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Terminal/FieldGibbs.lean @@ -0,0 +1,226 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.UniformSquareInduction +import OAI.Probability.SKGap.Localization.PrimaryFiniteControl +import OAI.Probability.SKGap.Matrix.FixedNormRecipeEvent + +namespace OAI + +section + +noncomputable section +open scoped BigOperators +namespace SKGapCutoff +variable {n : ℕ} + +def fieldEnergy (J : Interaction n) (h : Fin n→ℝ) (x : Spin n) : ℝ := + energy J x+∑i,h i*spin x i + +def fieldPartition (J : Interaction n) (h : Fin n→ℝ) : ℝ := ∑x,Real.exp (fieldEnergy J h x) +def fieldGibbs (J : Interaction n) (h : Fin n→ℝ) (x : Spin n) : ℝ := + Real.exp (fieldEnergy J h x)/fieldPartition J h + +lemma fieldPartition_pos (J : Interaction n) (h : Fin n→ℝ) : 0Real.exp_pos _) Finset.univ_nonempty +lemma fieldGibbs_pos (J : Interaction n) (h : Fin n→ℝ) (x : Spin n) : 0 simp only [spin,hi,Bool.false_eq_true,↓reduceIte,one_mul,neg_mul] at hb ⊢ <;> + linarith only [hb] + +lemma conditionalMean_primary (j : ℝ) (J : Interaction n) (hJ : J.IsSymm) + (hd : ∀i,J i i=0) (h : Fin n→ℝ) (x : Spin n) (i : Fin n) : + conditionalMean (fieldGibbs J h) x i=Primary.mag j J h 1 x i := by + rw [conditionalMean_fieldGibbs J (fun i k=>hJ.apply k i) hd] + rfl +end Static +end SKGapCutoff + +end +end + +section + +noncomputable section +open scoped BigOperators +namespace SKGapCutoff.Recipe +open Primary Static +universe u +variable {Ω : Type u} {n : Ω→ℕ} {M : ℕ} {j R B W C K : ℝ} +variable {J : ∀a,Interaction (n a)} {h : ∀a,Fin (n a)→ℝ} + +theorem gibbs_ordinary_residuals (p N : ℕ) (hK : 2≤K) (hM : pfieldGibbs (J a) (h a)) + (fun a x=>∑i,residual j (J a) (h a) p x i*(D a).source N x i) ∧ + UniformSquare (fun a=>fieldGibbs (J a) (h a)) + (fun a x=>∑i,residual j (J a) (h a) p x i*(D a).source N x i) := by + have hA : 1≤residualCoefficientBudget j K p 0 := + (by linarith : 1≤K).trans (residualCoefficientBudget_ge j (by linarith) p 0) + have hc:=primary_finite_control j R B hR hB J h M (N+2*p) hn + (fun a=>(hevent a).1) (fun a x l hl=>(hevent a).2.1 (h a) x l hl) + _ W C hA hW hC (fun a=>(hevent a).2.2.1) (fun a=>(hevent a).2.2.2) + have hp : ∀a x,0≤fieldGibbs (J a) (h a) x:=fun a x=>(fieldGibbs_pos _ _ _).le + have hm:=fun a=>conditionalMean_primary j (J a) (hJ a) (hdiag a) (h a) + exact ⟨uniform_ordinary_weak_residual p N hK hM hc hp (fun a=>sum_fieldGibbs _ _) hm hn hJ D H, + uniform_ordinary_square_residual p N hK hM hc hp (fun a=>sum_fieldGibbs _ _) hm hn hJ D H⟩ + +end SKGapCutoff.Recipe + +end +end + +section + +noncomputable section +open scoped BigOperators Matrix.Norms.Frobenius +namespace SKGapCutoff.Recipe +open Primary Matrix +variable {n : ℕ} + +def vectorPair (U V : VectorFields n) (x : Spin n) : ℝ := ∑i,U x i*V x i + +def normalizedPair (U V : VectorFields n) (x : Spin n) : ℝ := + vectorPair U V x/Real.sqrt (n:ℝ) + +lemma vectorPair_derivative (U V : VectorFields n) (x : Spin n) : + derivativeVector (vectorPair U V) x = + (Matrix.toEuclideanCLM (n:=Fin n) (𝕜:=ℝ) (derivativeMatrix U x)ᵀ) (WithLp.toLp 2 (V x))+ + (Matrix.toEuclideanCLM (n:=Fin n) (𝕜:=ℝ) (derivativeMatrix V x)ᵀ) (WithLp.toLp 2 (U x))- + WithLp.toLp 2 (fun k=>2*spin x k*∑i,derivativeMatrix U x i k*derivativeMatrix V x i k) := by + ext k + change halfDiff k (vectorPair U V) x = + (∑i,halfDiff k (fun y=>U y i) x*V x i)+ + (∑i,halfDiff k (fun y=>V y i) x*U x i)- + 2*spin x k*∑i,halfDiff k (fun y=>U y i) x*halfDiff k (fun y=>V y i) x + have hh : halfDiff k (vectorPair U V) x=∑i,halfDiff k (fun y=>U y i*V y i) x := by + simp only [halfDiff,vectorPair] + rw [← Finset.sum_sub_distrib,Finset.sum_div] + rw [hh,← Finset.sum_add_distrib,Finset.mul_sum,← Finset.sum_sub_distrib] + apply Finset.sum_congr rfl + intro i _ + rw [halfDiff_mul] + ring + +lemma vectorPair_abs (U V : VectorFields n) (x : Spin n) : + |vectorPair U V x| ≤ vectorNorm (U x)*vectorNorm (V x) := by + simpa [vectorPair,vectorNorm,EuclideanSpace.inner_eq_star_dotProduct,dotProduct,mul_comm] using + abs_real_inner_le_norm (WithLp.toLp 2 (U x) : EuclideanSpace ℝ (Fin n)) (WithLp.toLp 2 (V x)) + +lemma vectorPair_cross_bound (U V : VectorFields n) (x : Spin n) + {A B : ℝ} (hA : 0≤A) (hB : 0≤B) + (hu : SKGap.opNorm (derivativeMatrix U x)≤A) (hv : SKGap.opNorm (derivativeMatrix V x)≤B) : + vectorNorm (fun k=>2*spin x k*∑i,derivativeMatrix U x i k*derivativeMatrix V x i k) ≤ + 2*A*B*Real.sqrt (n:ℝ) := by + have hcol (M : Interaction n) {C : ℝ} (hC : 0≤C) (hM : SKGap.opNorm M≤C) (k : Fin n) : + vectorNorm (fun i=>M i k)≤C := by + apply nonneg_le_nonneg_of_sq_le_sq hC + simp only [← sq,vectorNorm_sq] + exact (RandomMatrix.matrix_column_sq_le M k).trans (pow_le_pow_left₀ (norm_nonneg _) hM 2) + have hdot (k : Fin n) : |∑i,derivativeMatrix U x i k*derivativeMatrix V x i k|≤A*B := by + exact (vectorPair_abs (fun _ i=>derivativeMatrix U x i k) + (fun _ i=>derivativeMatrix V x i k) x).trans + (mul_le_mul (hcol _ hA hu k) (hcol _ hB hv k) (vectorNorm_nonneg _) hA) + apply nonneg_le_nonneg_of_sq_le_sq (by positivity) + simp only [← sq,vectorNorm_sq] + calc + _ ≤ ∑ _k : Fin n,(2*A*B)^2 := by + apply Finset.sum_le_sum + intro k _ + have hb : |2*spin x k*∑i,derivativeMatrix U x i k*derivativeMatrix V x i k|≤2*A*B := by + simpa only [abs_mul,abs_of_nonneg (by norm_num : (0:ℝ)≤2),abs_spin_eq_one,mul_one,one_mul,mul_assoc] using + mul_le_mul_of_nonneg_left (hdot k) (by norm_num : (0:ℝ)≤2) + simpa only [sq_abs] using pow_le_pow_left₀ (abs_nonneg _) hb 2 + _ = _ := by simp [mul_pow,Real.sq_sqrt (Nat.cast_nonneg n)]; ring + +lemma vectorPair_derivative_bound (U V : VectorFields n) (x : Spin n) + {A B : ℝ} (hA : 0≤A) (hB : 0≤B) + (hu : SKGap.opNorm (derivativeMatrix U x)≤A) (hv : SKGap.opNorm (derivativeMatrix V x)≤B) : + ‖derivativeVector (vectorPair U V) x‖ ≤ + A*vectorNorm (V x)+B*vectorNorm (U x)+2*A*B*Real.sqrt (n:ℝ) := by + have hop (M : Interaction n) (u : Fin n→ℝ) {C : ℝ} (hM : SKGap.opNorm M≤C) : + ‖(Matrix.toEuclideanCLM (n:=Fin n) (𝕜:=ℝ) Mᵀ) (WithLp.toLp 2 u)‖≤C*vectorNorm u := by + apply (ContinuousLinearMap.le_opNorm _ _).trans + change SKGap.opNorm Mᵀ*vectorNorm u≤_ + rw [SKGap.opNorm_transpose] + exact mul_le_mul_of_nonneg_right hM (vectorNorm_nonneg u) + rw [vectorPair_derivative] + exact (norm_sub_le _ _).trans (add_le_add + ((norm_add_le _ _).trans (add_le_add (hop _ _ hu) (hop _ _ hv))) + (vectorPair_cross_bound U V x hA hB hu hv)) + +lemma normalizedPair_derivative (U V : VectorFields n) (x : Spin n) : + derivativeVector (normalizedPair U V) x = + (Real.sqrt (n:ℝ))⁻¹ • derivativeVector (vectorPair U V) x := by + ext k + simp only [derivativeVector,WithLp.ofLp_toLp,PiLp.smul_apply,smul_eq_mul,normalizedPair,halfDiff] + ring + +lemma normalizedPair_derivative_bound (hn : 0w x*(F k x)^2) + (fun k _=>mul_nonneg (hw x) (sq_nonneg _)) (Finset.mem_univ k)) + · simp only [zero_mul] + exact Finset.sum_nonneg (fun k _=>mul_nonneg (hw x) (sq_nonneg _)) + calc + _ = ∑x,(if ∃k,ε < |F k x| then w x else 0)*ε^2 := Finset.sum_mul .. + _ ≤ ∑x,∑k,w x*(F k x)^2 := Finset.sum_le_sum (fun x _=>hp x) + _ = ∑k,∑x,w x*(F k x)^2 := Finset.sum_comm + _ ≤ _ := Finset.sum_le_sum (fun k _=>hb k) + +lemma squared_sqrt_scale (w F : Spin n→ℝ) : + (∑x,w x*(F x/Real.sqrt (n:ℝ))^2)=(∑x,w x*(F x)^2)/(n:ℝ) := by + simp only [div_pow,Real.sq_sqrt (Nat.cast_nonneg n),mul_div_assoc,Finset.sum_div] + +lemma RecipeMatrixEvent.mono {j R A A' B W C : ℝ} {M N N' : ℕ} {J : Interaction n} + (he : RecipeMatrixEvent j R A B W C M N J) (hA : A'≤A) (hN : N'≤N) : + RecipeMatrixEvent j R A' B W C M N' J := by + refine ⟨he.1,he.2.1,?_,?_⟩ + · intro w hl hw; exact he.2.2.1 w (hl.trans (by omega)) (wordBounded_mono hw hA) + · intro w hl hw; exact he.2.2.2 w (hl.trans (by omega)) (wordBounded_mono hw hA) + +lemma residualCoefficientBudget_depth_mono (j : ℝ) {k d : ℕ} (hk : k≤d) : + residualCoefficientBudget j 2 k 0≤residualCoefficientBudget j 2 d 0 := by + simp only [residualCoefficientBudget,Nat.sub_zero] + apply mul_le_mul_of_nonneg_left _ (by norm_num) + exact pow_le_pow_right₀ (by linarith [steinCoefficientBudget_nonneg |j|]) hk + +universe u +variable {Ω : Type u} {N : Ω→ℕ} {j R B W C : ℝ} +variable {J : ∀a,Interaction (N a)} {h : ∀a,Fin (N a)→ℝ} + +theorem gibbs_pairing_tail (d : ℕ) {ε : ℝ} (hε : 0<ε) + (hR : 0≤R) (hB : 0≤B) (hW : 0≤W) (hC : 0≤C) + (hn : ∀a,0(hevent a).mono (residualCoefficientBudget_depth_mono j k.isLt.le) (by omega)) + choose C₁ C₂ hC₁ hC₂ hm using hm + refine ⟨(∑k,C₁ k)/ε^2,(∑k,C₂ k)/ε^2,div_nonneg (Finset.sum_nonneg (fun k _=>hC₁ k)) (sq_nonneg _), + div_nonneg (Finset.sum_nonneg (fun k _=>hC₂ k)) (sq_nonneg _),fun a=>⟨?_,?_⟩⟩ + · have ht := finite_pair_chebyshev (fun x=>fieldGibbs (J a) (h a) x) + (fun x=>(fieldGibbs_pos _ _ _).le) + (fun k:Fin d=>fun x=>primaryPair j (J a) (h a) k x/Real.sqrt (N a:ℝ)) hε + (fun k=>C₁ k/(N a:ℝ)) (fun k=>by + rw [squared_sqrt_scale] + exact div_le_div_of_nonneg_right (hm k a).1 (Nat.cast_nonneg _)) + simpa only [abs_div,abs_of_nonneg (Real.sqrt_nonneg _),←Finset.sum_div,div_right_comm] using ht + · intro f + have ht := finite_pair_chebyshev (fun x=>fieldGibbs (J a) (h a) x*(f x)^2) + (fun x=>mul_nonneg (fieldGibbs_pos _ _ _).le (sq_nonneg _)) + (fun k:Fin d=>fun x=>primaryPair j (J a) (h a) k x/Real.sqrt (N a:ℝ)) hε + (fun k=>C₂ k/Real.sqrt (N a:ℝ)*starSquared (fieldGibbs (J a) (h a)) f) + (fun k=>(hm k a).2 f) + convert ht using 1 + · simp only [abs_div,abs_of_nonneg (Real.sqrt_nonneg _)] + · rw [←Finset.sum_mul,←Finset.sum_div]; ring + +end SKGapCutoff.Recipe + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Terminal/FiniteSpinCalculus.lean b/lean/OAI/Probability/SKGap/Terminal/FiniteSpinCalculus.lean new file mode 100644 index 0000000000000000000000000000000000000000..99f03a0df4d97d0dab5e358d8340976c690bc025 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Terminal/FiniteSpinCalculus.lean @@ -0,0 +1,152 @@ +import Mathlib +import OAI.Probability.SKGap.Model + +namespace OAI + +noncomputable section +open scoped BigOperators +open MeasureTheory ProbabilityTheory Filter + +namespace SKGap + +section FiniteSpinCalculus + +variable {n : ℕ} + +@[simp] theorem spinValue_true : spinValue true = 1 := rfl +@[simp] theorem spinValue_false : spinValue false = -1 := rfl +@[simp] theorem spinValue_not (b : Bool) : spinValue (!b) = -spinValue b := by + cases b <;> norm_num [spinValue] +@[simp] theorem spinValue_sq (b : Bool) : spinValue b ^ 2 = 1 := by + cases b <;> norm_num [spinValue] + +@[simp] theorem coupling_diag (g : Disorder n) (i : Fin n) : coupling g i i = 0 := by + simp [coupling] + +theorem coupling_symm (g : Disorder n) (i k : Fin n) : coupling g i k = coupling g k i := by + rcases lt_trichotomy i k with hik | rfl | hki + · simp [coupling, hik, not_lt_of_gt hik] + · rfl + · simp [coupling, hki, not_lt_of_gt hki] + +@[simp] theorem flip_same (i : Fin n) (x : Spin n) : flip i x i = !(x i) := by + simp [flip] + +@[simp] theorem flip_other (i k : Fin n) (x : Spin n) (h : k ≠ i) : flip i x k = x k := by + simp [flip, h] + +@[simp] theorem flip_flip (i : Fin n) (x : Spin n) : flip i (flip i x) = x := by + ext k + by_cases h : k = i + · subst k; simp + · simp [flip_other, h] + +def flipEquiv (i : Fin n) : Spin n ≃ Spin n := + Function.Involutive.toPerm (flip i) (flip_flip i) + +theorem sum_flip (i : Fin n) (f : Spin n → ℝ) : ∑ x, f (flip i x) = ∑ x, f x := + (flipEquiv i).sum_comp f + +theorem weight_pos (g : Disorder n) (h : Fin n → ℝ) (x : Spin n) : + 0 < weight g h x := Real.exp_pos _ + +theorem partition_pos (g : Disorder n) (h : Fin n → ℝ) : 0 < partition g h := by + exact Finset.sum_pos (fun x _ => weight_pos g h x) Finset.univ_nonempty + +theorem mass_pos (g : Disorder n) (h : Fin n → ℝ) (x : Spin n) : + 0 < mass g h x := div_pos (weight_pos g h x) (partition_pos g h) + +theorem mass_nonneg (g : Disorder n) (h : Fin n → ℝ) (x : Spin n) : + 0 ≤ mass g h x := (mass_pos g h x).le + +@[simp] theorem sum_mass (g : Disorder n) (h : Fin n → ℝ) : ∑ x, mass g h x = 1 := by + simp only [mass, ← Finset.sum_div] + exact div_self (ne_of_gt (partition_pos g h)) + +@[simp] theorem expectation_const (g : Disorder n) (h : Fin n → ℝ) (c : ℝ) : + expectation g h (fun _ => c) = c := by + simp [expectation, ← Finset.sum_mul] + +theorem expectation_add (g : Disorder n) (h : Fin n → ℝ) (f k : Spin n → ℝ) : + expectation g h (fun x => f x + k x) = expectation g h f + expectation g h k := by + simp [expectation, mul_add, Finset.sum_add_distrib] + +theorem expectation_sub (g : Disorder n) (h : Fin n → ℝ) (f k : Spin n → ℝ) : + expectation g h (fun x => f x - k x) = expectation g h f - expectation g h k := by + simp [expectation, mul_sub, Finset.sum_sub_distrib] + +theorem expectation_mul_const (g : Disorder n) (h : Fin n → ℝ) (f : Spin n → ℝ) (c : ℝ) : + expectation g h (fun x => f x * c) = expectation g h f * c := by + simp only [expectation, Finset.sum_mul, mul_assoc] + +theorem expectation_const_mul (g : Disorder n) (h : Fin n → ℝ) (f : Spin n → ℝ) (c : ℝ) : + expectation g h (fun x => c * f x) = c * expectation g h f := by + simp only [mul_comm c, expectation_mul_const] + +theorem expectation_nonneg (g : Disorder n) (h : Fin n → ℝ) {f : Spin n → ℝ} + (hf : ∀ x, 0 ≤ f x) : 0 ≤ expectation g h f := + Finset.sum_nonneg (fun x _ => mul_nonneg (mass_nonneg g h x) (hf x)) + +theorem variance_nonneg (g : Disorder n) (h : Fin n → ℝ) (f : Spin n → ℝ) : + 0 ≤ variance g h f := expectation_nonneg g h (fun _ => sq_nonneg _) + +theorem dirichlet_nonneg (g : Disorder n) (h : Fin n → ℝ) (f : Spin n → ℝ) : + 0 ≤ dirichlet g h f := + Finset.sum_nonneg (fun _ _ => expectation_nonneg g h (fun _ => sq_nonneg _)) + +theorem variance_eq_zero_iff (g : Disorder n) (h : Fin n → ℝ) (f : Spin n → ℝ) : + variance g h f = 0 ↔ ∀ x, f x = expectation g h f := by + unfold variance expectation + rw [Finset.sum_eq_zero_iff_of_nonneg (fun x _ => + mul_nonneg (mass_nonneg g h x) (sq_nonneg _))] + simp only [Finset.mem_univ, true_implies, mul_eq_zero, ne_of_gt (mass_pos g h _), + false_or, sq_eq_zero_iff, sub_eq_zero] + +theorem variance_pos_of_ne (g : Disorder n) (h : Fin n → ℝ) {f : Spin n → ℝ} + {x y : Spin n} (hxy : f x ≠ f y) : 0 < variance g h f := by + refine lt_of_le_of_ne (variance_nonneg g h f) ?_ + intro heq + have hf := (variance_eq_zero_iff g h f).mp heq.symm + exact hxy ((hf x).trans (hf y).symm) + +theorem exists_positive_variance (g : Disorder n) (hn : 0 < n) : + ∃ f : Spin n → ℝ, 0 < variance g 0 f := by + let i : Fin n := ⟨0, hn⟩ + refine ⟨fun x => spinValue (x i), variance_pos_of_ne g 0 (x := fun _ => true) + (y := fun _ => false) ?_⟩ + norm_num + +theorem lower_bound_discreteGap (g : Disorder n) (hn : 0 < n) {C : ℝ} (hC : 0 < C) + (hP : ∀ f : Spin n → ℝ, variance g 0 f ≤ C * dirichlet g 0 f) : + 1 / (C * (n : ℝ)) ≤ discreteGap g := by + obtain ⟨f, hf⟩ := exists_positive_variance g hn + apply le_csInf + · exact ⟨_, f, hf, rfl⟩ + · rintro r ⟨f, hv, rfl⟩ + have hn' : 0 < (n : ℝ) := Nat.cast_pos.mpr hn + apply (div_le_div_iff₀ (mul_pos hC hn') (mul_pos hn' hv)).mpr + nlinarith [mul_le_mul_of_nonneg_left (hP f) hn'.le] + +instance disorderLaw_probability (β : ℝ) (n : ℕ) : IsProbabilityMeasure (disorderLaw β n) := by + unfold disorderLaw + infer_instance + +theorem gap_probability_of_poincare (β C : ℝ) (hC : 0 < C) + (hP : Tendsto (fun n : ℕ => disorderLaw β n (poincareEvent n C)) atTop (nhds 1)) : + Tendsto (fun n : ℕ => disorderLaw β n {g | 1 / (C * (n : ℝ)) ≤ discreteGap g}) + atTop (nhds 1) := by + apply tendsto_of_tendsto_of_tendsto_of_le_of_le' hP tendsto_const_nhds + · filter_upwards [eventually_gt_atTop (0 : ℕ)] with n hn + apply measure_mono + intro g hg + exact lower_bound_discreteGap g hn hC hg + · filter_upwards [] with n + exact (measure_mono (Set.subset_univ _)).trans_eq (measure_univ) + +end FiniteSpinCalculus + +end SKGap + +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Terminal/GibbsEventProbability.lean b/lean/OAI/Probability/SKGap/Terminal/GibbsEventProbability.lean new file mode 100644 index 0000000000000000000000000000000000000000..3ec1efd99994991c37fe02d957441fed38630fba --- /dev/null +++ b/lean/OAI/Probability/SKGap/Terminal/GibbsEventProbability.lean @@ -0,0 +1,96 @@ +import Mathlib +import OAI.Probability.SKGap.Terminal.GibbsLExpectation + +namespace OAI + +section +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open scoped BigOperators +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open scoped BigOperators +open scoped BigOperators NNReal ENNReal +open MeasureTheory Metric Set +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators NNReal ENNReal Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Set +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators ENNReal NNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Matrix +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators ENNReal NNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal +namespace SKGapCutoff + +noncomputable def gibbsEventProbability {n : ℕ} + (E : Spin n → Set (GaussianCoordinates n)) : GaussianCoordinates n → ℝ≥0∞ := + gibbsLExpectation (fun g x => (E x).indicator (fun _ => 1) g) + +lemma measurable_gibbsEventProbability {n : ℕ} (E : Spin n → Set (GaussianCoordinates n)) + (hE : ∀ x, MeasurableSet (E x)) : Measurable (gibbsEventProbability E) := + measurable_gibbsLExpectation _ (fun x => measurable_const.indicator (hE x)) + +lemma planted_gibbsEventProbability_bound (β : ℝ) {n : ℕ} (hn : 0 < n) + (E : Spin n → Set (GaussianCoordinates n)) (hE : ∀ x, MeasurableSet (E x)) + (a : ℝ≥0∞) (ha : ∀ x, singleSpinPlantedLaw β x (E x) ≤ a) : + (∫⁻ g, gibbsEventProbability E g ∂plantedDisorderLaw β n) ≤ a := by + rw [gibbsEventProbability, planted_gibbs_lintegral β hn _ + (fun x => measurable_const.indicator (hE x))] + have hI (x : Spin n) : + (∫⁻ g, (E x).indicator (fun _ => (1:ℝ≥0∞)) g ∂singleSpinPlantedLaw β x) = + singleSpinPlantedLaw β x (E x) := lintegral_indicator_one (hE x) + simp_rw [hI] + calc + _ ≤ ENNReal.ofReal (((2:ℝ)^n)⁻¹) * ∑ _x : Spin n, a := + mul_le_mul' le_rfl (Finset.sum_le_sum (fun x _ => ha x)) + _ = a := by + simp only [Finset.sum_const, Finset.card_univ, card_spin, nsmul_eq_mul, + Nat.cast_pow, Nat.cast_ofNat] + rw [← mul_assoc] + have he : ENNReal.ofReal (((2:ℝ)^n)⁻¹) * (2:ℝ≥0∞)^n = 1 := by + have hpow : ENNReal.ofReal ((2:ℝ)^n) = (2:ℝ≥0∞)^n := by + rw [ENNReal.ofReal_pow (by norm_num : (0:ℝ) ≤ 2)] + norm_num + rw [← hpow, ← ENNReal.ofReal_mul (by positivity)] + simp + rw [he, one_mul] + +lemma quenched_gibbs_events_exponential (β : ℝ) (hβ : β^2 < 1) + (c : ℝ) (hc : 0 < c) (E : (n : ℕ) → Spin n → Set (GaussianCoordinates n)) + (hE : ∀ n x, MeasurableSet (E n x)) + (hsmall : ∀ᶠ n : ℕ in atTop, ∀ x : Spin n, + singleSpinPlantedLaw β x (E n x) ≤ ENNReal.ofReal (Real.exp (-c*n))) : + Tendsto (fun n => disorderLaw β n {g | + ENNReal.ofReal (Real.exp (-(c/2)*n)) ≤ gibbsEventProbability (E n) g}) + atTop (nhds 0) := by + apply quenched_exponential_transfer β hβ c hc (fun n => gibbsEventProbability (E n)) + (fun n => measurable_gibbsEventProbability (E n) (hE n)) + filter_upwards [hsmall, eventually_gt_atTop 0] with n hs hn + exact planted_gibbsEventProbability_bound β hn (E n) (hE n) _ hs + +end SKGapCutoff + +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Terminal/GibbsEventProbabilityReal.lean b/lean/OAI/Probability/SKGap/Terminal/GibbsEventProbabilityReal.lean new file mode 100644 index 0000000000000000000000000000000000000000..a102486deddcbaa7f0f83b51083608c9c28cfbc3 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Terminal/GibbsEventProbabilityReal.lean @@ -0,0 +1,283 @@ +import Mathlib +import OAI.Probability.SKGap.Terminal.SpinCovarianceMeasure + +namespace OAI + +section +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open scoped BigOperators +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open scoped BigOperators +open scoped BigOperators NNReal ENNReal +open MeasureTheory Metric Set +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators NNReal ENNReal Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Set +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators ENNReal NNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Matrix +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators ENNReal NNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal +open scoped BigOperators +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise NNReal ENNReal +open scoped BigOperators +open Filter Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal Topology +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Set Matrix +open scoped BigOperators NNReal ENNReal Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open Filter MeasureTheory ProbabilityTheory +open scoped Topology NNReal ENNReal +open Filter MeasureTheory ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter +open scoped Topology NNReal ENNReal +open MeasureTheory Filter ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter +open scoped Topology +open MeasureTheory Filter ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter ProbabilityTheory ContinuousLinearMap +open scoped Topology NNReal ENNReal +open Filter MeasureTheory ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter +open scoped BigOperators Topology +open MeasureTheory Filter +open scoped BigOperators Topology +open MeasureTheory Filter +open scoped BigOperators Topology +open MeasureTheory Filter +open scoped BigOperators Topology +open MeasureTheory Filter +open scoped BigOperators Topology +open Filter Set Metric +open scoped Topology RealInnerProductSpace +open scoped BigOperators +open ContinuousLinearMap +open scoped BigOperators +open ContinuousLinearMap +open scoped Topology Interval +open MeasureTheory +open MeasureTheory +open scoped BigOperators Topology Interval +open MeasureTheory +open scoped BigOperators Topology Interval +open scoped Topology +open MeasureTheory +open scoped BigOperators Topology Interval +open scoped BigOperators Topology +open MeasureTheory +open scoped BigOperators Topology Interval RealInnerProductSpace +open MeasureTheory Filter +open scoped BigOperators Topology Interval +open MeasureTheory Filter +open scoped Topology +open MeasureTheory Filter +open scoped Topology +open MeasureTheory Filter +open scoped Topology +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Matrix.Norms.L2Operator +namespace SKGapCutoff + +lemma gibbsEventProbability_toReal {n : ℕ} + (E : Spin n → Set (GaussianCoordinates n)) (g : GaussianCoordinates n) : + (gibbsEventProbability E g).toReal = + gibbsExpectation (sampledInteraction g) (fun x => (E x).indicator (fun _ => 1) g) := by + classical + unfold gibbsEventProbability gibbsLExpectation gibbsExpectation + rw [ENNReal.toReal_sum] + · apply Finset.sum_congr rfl + intro x _ + by_cases hx : g ∈ E x + · simp [hx,ENNReal.toReal_ofReal (gibbs_pos _ _).le] + · simp [hx] + · intro x _ + by_cases hx : g ∈ E x <;> simp [hx] + +lemma gibbsExpectation_deviation_bound {n : ℕ} (g : GaussianCoordinates n) + (f : Spin n → GaussianCoordinates n → ℝ) (m δ K : ℝ) (hδ : 0≤δ) + (hK : ∀ x, |f x g-m|≤K) : + |gibbsExpectation (sampledInteraction g) (fun x => f x g)-m| ≤ + δ+K*(gibbsEventProbability (fun x => {h | δ ≤ |f x h-m|}) g).toReal := by + classical + rw [gibbsEventProbability_toReal] + simp only [Set.indicator_apply,Set.mem_ofPred_eq] + let J := sampledInteraction g + have he : gibbsExpectation J (fun x => f x g)-m = + ∑ x, gibbs J x*(f x g-m) := by + simp only [gibbsExpectation,mul_sub,Finset.sum_sub_distrib,← Finset.sum_mul,gibbs_sum,one_mul] + rw [he] + calc + _ ≤ ∑ x, |gibbs J x*(f x g-m)| := Finset.abs_sum_le_sum_abs _ _ + _ = ∑ x, gibbs J x*|f x g-m| := by simp [abs_mul,abs_of_pos (gibbs_pos J _)] + _ ≤ ∑ x, gibbs J x*(δ+K*(if δ ≤ |f x g-m| then 1 else 0)) := by + apply Finset.sum_le_sum + intro x _ + apply mul_le_mul_of_nonneg_left _ (gibbs_pos J x).le + split_ifs with hx + · simp only [mul_one]; linarith [hK x] + · simp only [mul_zero,add_zero]; exact (lt_of_not_ge hx).le + _ = δ+K*gibbsExpectation J (fun x => if g ∈ {h | δ≤|f x h-m|} then 1 else 0) := by + simp only [gibbsExpectation,mul_add,Finset.sum_add_distrib,← Finset.sum_mul,gibbs_sum, + one_mul,Set.mem_ofPred_eq,Finset.mul_sum] + congr 1 + apply Finset.sum_congr rfl + intro x _ + ring + +end SKGapCutoff + +namespace SKGapCutoff.Regression + +noncomputable def gibbsSpinEnergyAverage {n : ℕ} (g : GaussianCoordinates n) : ℝ := + gibbsExpectation (sampledInteraction g) (fun x => spinEnergyAverage x g) + +theorem gibbsSpinEnergyAverage_limit (β : ℝ) (hβ : 0<β) (hβ1 : β<1) + (ε : ℝ) (hε : 0<ε) : + Tendsto (fun n => disorderLaw β n {g | ε ≤ |gibbsSpinEnergyAverage g-β^2|}) + atTop (nhds 0) := by + obtain ⟨c,hc,hevent⟩ := quenched_spinEnergyAverage_exponential β hβ hβ1 (ε/2) (by positivity) + let C := 2*(β^2+10) + let K := C+β^2 + have hK : 0 ≤ K := by dsimp [K,C]; positivity + have hnorm := RandomMatrix.sampled_opNorm_tendsto β + have ht : Tendsto (fun n : ℕ => K*Real.exp (-c*n)) atTop (nhds 0) := by + have hh := Real.tendsto_exp_neg_atTop_nhds_zero.comp + ((tendsto_natCast_atTop_atTop : Tendsto (fun n : ℕ => (n:ℝ)) atTop atTop).const_mul_atTop hc) + simpa only [Function.comp_apply,neg_mul,mul_zero] using hh.const_mul K + have hsum := hnorm.add hevent + simp only [add_zero] at hsum + apply tendsto_of_tendsto_of_tendsto_of_le_of_le' tendsto_const_nhds hsum + (Eventually.of_forall (fun _ => bot_le)) + filter_upwards [eventually_gt_atTop 0,ht.eventually (gt_mem_nhds (by positivity : (0:ℝ)<ε/2))] + with n hn hsmall + apply (measure_mono (show {g | ε ≤ |gibbsSpinEnergyAverage g-β^2|} ⊆ + {g | C < ‖Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) (sampledInteraction g)‖} ∪ + {g | ENNReal.ofReal (Real.exp (-c*n)) ≤ + gibbsEventProbability (fun x : Spin n => {h | ε/2 ≤ |spinEnergyAverage x h-β^2|}) g} from ?_)).trans + (measure_union_le _ _) + intro g hg + by_cases ha : C < ‖Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) (sampledInteraction g)‖ + · exact Or.inl ha + by_cases hb : ENNReal.ofReal (Real.exp (-c*n)) ≤ + gibbsEventProbability (fun x : Spin n => {h | ε/2 ≤ |spinEnergyAverage x h-β^2|}) g + · exact Or.inr hb + exfalso + have hp : (gibbsEventProbability (fun x : Spin n => {h | ε/2 ≤ |spinEnergyAverage x h-β^2|}) g).toReal + ≤ Real.exp (-c*n) := by + have hh := ENNReal.toReal_mono (show ENNReal.ofReal (Real.exp (-c*n))≠⊤ from ENNReal.ofReal_ne_top) + (lt_of_not_ge hb).le + simpa only [ENNReal.toReal_ofReal (Real.exp_pos _).le] using hh + have hdev := gibbsExpectation_deviation_bound g + (fun x h => spinEnergyAverage x h) (β^2) (ε/2) K (by positivity) (fun x => by + calc + _ ≤ |spinEnergyAverage x g|+|β^2| := by simpa only [sub_zero,zero_sub,abs_neg] using abs_sub_le (spinEnergyAverage x g) (0:ℝ) (β^2) + _ ≤ C+β^2 := by + rw [abs_of_nonneg (sq_nonneg β)] + exact add_le_add_left ((spinEnergyAverage_abs_le_opNorm hn x g).trans (le_of_not_gt ha)) _) + change ε ≤ |gibbsExpectation (sampledInteraction g) (fun x => spinEnergyAverage x g)-β^2| at hg + have he := mul_le_mul_of_nonneg_left hp hK + linarith + +end SKGapCutoff.Regression + +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped BigOperators ENNReal NNReal Topology Matrix.Norms.L2Operator + +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Terminal/GibbsExpectation.lean b/lean/OAI/Probability/SKGap/Terminal/GibbsExpectation.lean new file mode 100644 index 0000000000000000000000000000000000000000..83705747335944f9ca5db83a92e4598a371fed00 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Terminal/GibbsExpectation.lean @@ -0,0 +1,223 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.Character + +namespace OAI + +section +open scoped BigOperators +namespace SKGapCutoff +open Filter Topology +noncomputable def gibbsExpectation {n : ℕ} (J : Interaction n) (f : Observables n) : ℝ := + ∑ x, gibbs J x * f x +noncomputable def gibbsVariance {n : ℕ} (J : Interaction n) (f : Observables n) : ℝ := + gibbsExpectation J (fun x => (f x - gibbsExpectation J f) ^ 2) +noncomputable def siteVariance {n : ℕ} (J : Interaction n) (x : Spin n) (i : Fin n) : ℝ := + 1 - mean J x i ^ 2 +noncomputable def dirichlet {n : ℕ} (J : Interaction n) (f g : Observables n) : ℝ := + gibbsExpectation J (fun x => ∑ i, siteVariance J x i * halfDiff i f x * halfDiff i g x) +def HasGap {n : ℕ} (J : Interaction n) (γ : ℝ) : Prop := + ∀ f : Observables n, γ * gibbsVariance J f ≤ dirichlet J f f + +def QuenchedGap (β : ℝ) : Prop := + ∃ γ : ℝ, 0 < γ ∧ Tendsto (fun n => (disorderLaw β n) + {g | HasGap (sampledInteraction g) γ}) atTop (nhds 1) + +def flip {n : ℕ} (x : Spin n) (i : Fin n) : Spin n := replace x i (!x i) + +@[simp] lemma flip_flip {n : ℕ} (x : Spin n) (i : Fin n) : flip (flip x i) i = x := by + simp [flip] + +@[simp] lemma spin_flip_self {n : ℕ} (x : Spin n) (i : Fin n) : + spin (flip x i) i = -spin x i := by + cases h : x i <;> simp [flip, spin, h] + +lemma spin_flip {n : ℕ} (x : Spin n) (i j : Fin n) : + spin (flip x i) j = spin x j - if j = i then 2 * spin x i else 0 := by + by_cases h : j = i + · subst j; simp; ring + · simp [flip, spin_replace_of_ne x h, h] + +lemma field_flip {n : ℕ} (J : Interaction n) (hdiag : ∀ i, J i i = 0) + (x : Spin n) (i : Fin n) : field J (flip x i) i = field J x i := by + simp only [field, spin_flip, mul_sub, Finset.sum_sub_distrib] + simp [mul_ite, hdiag] + +@[simp] lemma mean_flip {n : ℕ} (J : Interaction n) (hdiag : ∀ i, J i i = 0) + (x : Spin n) (i : Fin n) : mean J (flip x i) i = mean J x i := by + simp only [mean, field_flip J hdiag] + +lemma energy_flip {n : ℕ} (J : Interaction n) (hJ : ∀ i j, J i j = J j i) + (hdiag : ∀ i, J i i = 0) (x : Spin n) (i : Fin n) : + energy J (flip x i) = energy J x - 2 * spin x i * field J x i := by + have hr : ∑ j, spin x j * J j i = field J x i := by + simp only [field, hJ, mul_comm] + unfold energy + simp only [spin_flip, sub_mul, mul_sub, Finset.sum_sub_distrib] + simp only [mul_ite, ite_mul, mul_zero, zero_mul, Finset.sum_ite_irrel, Finset.sum_const_zero, Finset.sum_ite_eq', Finset.mem_univ, + ↓reduceIte, hdiag] + simp only [← Finset.sum_mul, hr] + simp only [mul_assoc, ← Finset.mul_sum, field] + ring + +noncomputable def flipRate {n : ℕ} (J : Interaction n) (x : Spin n) (i : Fin n) : ℝ := + (1 - spin x i * mean J x i) / 2 + +lemma generator_flip {n : ℕ} (J : Interaction n) (f : Observables n) (x : Spin n) : + generator J f x = ∑ i, flipRate J x i * (f (flip x i) - f x) := by + apply Finset.sum_congr rfl + intro i _ + have hx := replace_self x i + cases hi : x i <;> simp only [hi] at hx + · simp only [spin, hi, Bool.false_eq_true, ↓reduceIte, flipRate, flip, Bool.not_false, + halfDiff] + rw [hx]; ring + · simp only [spin, hi, ↓reduceIte, flipRate, flip, Bool.not_true, halfDiff] + rw [hx]; ring + +lemma exp_two_mul_one_sub_tanh (a : ℝ) : + Real.exp (2 * a) * (1 - Real.tanh a) = 1 + Real.tanh a := by + rw [Real.tanh_eq, show 2 * a = a + a by ring, Real.exp_add, Real.exp_neg] + have he := Real.exp_pos a + field_simp + nlinarith + +lemma exp_neg_two_mul_one_add_tanh (a : ℝ) : + Real.exp (-2 * a) * (1 + Real.tanh a) = 1 - Real.tanh a := by + simpa only [mul_neg, neg_mul, Real.tanh_neg, sub_neg_eq_add, sub_eq_add_neg, neg_neg] using + exp_two_mul_one_sub_tanh (-a) + +lemma gibbs_detailed_balance {n : ℕ} (J : Interaction n) + (hJ : ∀ i j, J i j = J j i) (hdiag : ∀ i, J i i = 0) + (x : Spin n) (i : Fin n) : + gibbs J (flip x i) * flipRate J (flip x i) i = gibbs J x * flipRate J x i := by + simp only [gibbs, energy_flip J hJ hdiag, flipRate, spin_flip_self, + Real.exp_sub, mean, field_flip J hdiag] + cases hi : x i + · simp only [spin, hi, Bool.false_eq_true, ↓reduceIte, neg_neg, neg_mul, mul_one, + one_mul, mul_neg, Real.exp_neg] + have h := exp_two_mul_one_sub_tanh (field J x i) + field_simp [ne_of_gt (partition_pos J)] + nlinarith only [h] + · simp only [spin, hi, ↓reduceIte, mul_one, one_mul, neg_mul, sub_neg_eq_add] + have h := exp_two_mul_one_sub_tanh (field J x i) + field_simp [ne_of_gt (partition_pos J)] + nlinarith only [h] + +def flipEquiv (n : ℕ) (i : Fin n) : Spin n ≃ Spin n where + toFun x := flip x i + invFun x := flip x i + left_inv x := flip_flip x i + right_inv x := flip_flip x i + +lemma sum_flip {n : ℕ} (i : Fin n) (f : Observables n) : + ∑ x, f (flip x i) = ∑ x, f x := (flipEquiv n i).sum_comp f + +@[simp] lemma halfDiff_flip {n : ℕ} (i : Fin n) (f : Observables n) (x : Spin n) : + halfDiff i f (flip x i) = halfDiff i f x := by simp [flip] + +lemma flip_sub {n : ℕ} (i : Fin n) (f : Observables n) (x : Spin n) : + f (flip x i) - f x = -2 * spin x i * halfDiff i f x := by + have hx := replace_self x i + cases hi : x i <;> simp only [hi] at hx + · simp only [flip, hi, Bool.not_false, spin, Bool.false_eq_true, ↓reduceIte, halfDiff] + rw [hx]; ring + · simp only [flip, hi, Bool.not_true, spin, ↓reduceIte, halfDiff] + rw [hx]; ring + +lemma gibbs_flip_integral {n : ℕ} (J : Interaction n) + (hJ : ∀ i j, J i j = J j i) (hdiag : ∀ i, J i i = 0) + (i : Fin n) (f : Observables n) : + ∑ x, gibbs J x * flipRate J x i * f (flip x i) = + ∑ x, gibbs J x * flipRate J x i * f x := by + calc + _ = ∑ x, gibbs J (flip x i) * flipRate J (flip x i) i * f (flip x i) := by + simp_rw [gibbs_detailed_balance J hJ hdiag] + _ = _ := sum_flip i (fun x => gibbs J x * flipRate J x i * f x) + +lemma gibbs_generator_zero {n : ℕ} (J : Interaction n) + (hJ : ∀ i j, J i j = J j i) (hdiag : ∀ i, J i i = 0) + (f : Observables n) : gibbsExpectation J (generator J f) = 0 := by + simp only [gibbsExpectation, generator_flip, Finset.mul_sum] + rw [Finset.sum_comm] + apply Finset.sum_eq_zero + intro i _ + simp only [mul_sub, Finset.sum_sub_distrib] + simp only [← mul_assoc, gibbs_flip_integral J hJ hdiag, sub_self] + +lemma gibbs_coordinate_mean {n : ℕ} (J : Interaction n) + (hJ : ∀ i j, J i j = J j i) (hdiag : ∀ i, J i i = 0) + (i : Fin n) (h : Observables n) (hinv : ∀ x, h (flip x i) = h x) : + (∑ x, gibbs J x * spin x i * h x) = ∑ x, gibbs J x * mean J x i * h x := by + have he := gibbs_flip_integral J hJ hdiag i (fun x => spin x i * h x) + simp only [spin_flip_self, hinv] at he + have hz : ∑ x, gibbs J x * flipRate J x i * spin x i * h x = 0 := by + simp only [mul_neg, neg_mul, ← mul_assoc, Finset.sum_neg_distrib] at he + linarith + have hp (x : Spin n) : gibbs J x * flipRate J x i * spin x i * h x = + (gibbs J x * spin x i * h x - gibbs J x * mean J x i * h x) / 2 := by + unfold flipRate + have hs := spin_sq x i + nlinarith only [congrArg (fun a : ℝ => gibbs J x * mean J x i * h x * a) hs] + simp_rw [hp] at hz + rw [← Finset.sum_div, Finset.sum_sub_distrib] at hz + linarith + +lemma gibbs_edge_dirichlet {n : ℕ} (J : Interaction n) + (hJ : ∀ i j, J i j = J j i) (hdiag : ∀ i, J i i = 0) + (i : Fin n) (f g : Observables n) : + (∑ x, gibbs J x * f x * (flipRate J x i * (g x - g (flip x i)))) = + ∑ x, gibbs J x * siteVariance J x i * halfDiff i f x * halfDiff i g x := by + let c (x : Spin n) := gibbs J x * flipRate J x i + have hc (x : Spin n) : c (flip x i) = c x := gibbs_detailed_balance J hJ hdiag x i + have he := sum_flip i (fun x => c x * f x * (g x - g (flip x i))) + simp only [hc, flip_flip] at he + have hpair : (∑ x, c x * f x * (g x - g (flip x i))) = + (∑ x, c x * (f (flip x i) - f x) * (g (flip x i) - g x)) / 2 := by + have hp (x : Spin n) : c x * (f (flip x i) - f x) * (g (flip x i) - g x) = + c x * f (flip x i) * (g (flip x i) - g x) + c x * f x * (g x - g (flip x i)) := by ring + simp_rw [hp] + rw [Finset.sum_add_distrib, he] + ring + have hdf (x : Spin n) : c x * (f (flip x i) - f x) * (g (flip x i) - g x) = + 4 * c x * halfDiff i f x * halfDiff i g x := by + rw [flip_sub, flip_sub] + have hs := spin_sq x i + nlinarith only [congrArg (fun a : ℝ => c x * halfDiff i f x * halfDiff i g x * a) hs] + have hmean := gibbs_coordinate_mean J hJ hdiag i + (fun x => mean J x i * halfDiff i f x * halfDiff i g x) + (by intro x; rw [mean_flip J hdiag, halfDiff_flip, halfDiff_flip]) + have hp (x : Spin n) : (4 * c x * halfDiff i f x * halfDiff i g x) / 2 = + gibbs J x * siteVariance J x i * halfDiff i f x * halfDiff i g x + + gibbs J x * mean J x i * (mean J x i * halfDiff i f x * halfDiff i g x) - + gibbs J x * spin x i * (mean J x i * halfDiff i f x * halfDiff i g x) := by + dsimp [c, siteVariance, flipRate] + ring + calc + _ = (∑ x, c x * f x * (g x - g (flip x i))) := by + apply Finset.sum_congr rfl; intro x _; dsimp [c]; ring + _ = _ := hpair + _ = _ := by + simp_rw [hdf] + rw [Finset.sum_div] + simp_rw [hp] + rw [Finset.sum_sub_distrib, Finset.sum_add_distrib, hmean] + ring + +theorem gibbs_dirichlet {n : ℕ} (J : Interaction n) + (hJ : ∀ i j, J i j = J j i) (hdiag : ∀ i, J i i = 0) + (f g : Observables n) : + gibbsExpectation J (fun x => f x * -generator J g x) = dirichlet J f g := by + simp only [gibbsExpectation, generator_flip, dirichlet, Finset.mul_sum, + ← Finset.sum_neg_distrib] + rw [Finset.sum_comm, Finset.sum_comm (f := fun x i => + gibbs J x * (siteVariance J x i * halfDiff i f x * halfDiff i g x))] + apply Finset.sum_congr rfl + intro i _ + convert gibbs_edge_dirichlet J hJ hdiag i f g using 1 <;> + apply Finset.sum_congr rfl <;> intro x _ <;> ring + +end SKGapCutoff + +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Terminal/GibbsExpectationMono.lean b/lean/OAI/Probability/SKGap/Terminal/GibbsExpectationMono.lean new file mode 100644 index 0000000000000000000000000000000000000000..2085f0af49c9e536dfd5b35e8f209110b9096805 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Terminal/GibbsExpectationMono.lean @@ -0,0 +1,119 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.Centered + +namespace OAI + +section +open scoped BigOperators +namespace SKGapCutoff + +lemma gibbsExpectation_mono {n : ℕ} (J : Interaction n) (f g : Observables n) + (hfg : ∀ x, f x ≤ g x) : gibbsExpectation J f ≤ gibbsExpectation J g := by + exact Finset.sum_le_sum fun x _ => mul_le_mul_of_nonneg_left (hfg x) (le_of_lt (gibbs_pos J x)) + +lemma spin_variance {n : ℕ} (J : Interaction n) (i : Fin n) : + gibbsVariance J (fun x => spin x i) = 1 := by + rw [gibbsVariance, gibbs_spin_centered] + simp only [sub_zero, spin_sq] + exact gibbsExpectation_const J 1 + +theorem finite_gap_le_one {n : ℕ} (hn : 0 < n) (J : Interaction n) + {γ : ℝ} (hγ : HasGap J γ) : γ ≤ 1 := by + let i : Fin n := ⟨0, hn⟩ + have hh := hγ (fun x => spin x i) + rw [spin_variance, mul_one] at hh + have hd : dirichlet J (fun x => spin x i) (fun x => spin x i) = + gibbsExpectation J (fun x => siteVariance J x i) := by + simp [dirichlet, halfDiff_spin] + rw [hd] at hh + exact hh.trans ((gibbsExpectation_mono J _ (fun _ => 1) + (fun x => siteVariance_le_one J x i)).trans_eq (gibbsExpectation_const J 1)) + +lemma spectral_bilinear_dirichlet {n : ℕ} (J : Interaction n) + (hJ : ∀ i j, J i j = J j i) (hdiag : ∀ i, J i i = 0) (f g : Observables n) : + dirichlet J f g = ∑ a, spinEigenvalues J hJ hdiag a * + ((spinEigenbasis J hJ hdiag).repr (gibbsEuclideanEquiv J f) a) * + ((spinEigenbasis J hJ hdiag).repr (gibbsEuclideanEquiv J g) a) := by + rw [← gibbs_dirichlet J hJ hdiag] + change stationaryInner J f (-generator J g) = _ + rw [← spectral_parseval J hJ hdiag] + simp_rw [spectral_generator_coordinates] + apply Finset.sum_congr rfl + intro a _ + ring + +lemma spectral_gradient_correlation {n : ℕ} (J : Interaction n) + (hJ : ∀ i j, J i j = J j i) (hdiag : ∀ i, J i i = 0) + (t : ℝ) (f g : Observables n) : + weightedInner J (gradientCLM n f) (gradientSemigroup J t (gradientCLM n g)) = + ∑ a, spinEigenvalues J hJ hdiag a * Real.exp (-spinEigenvalues J hJ hdiag a * t) * + ((spinEigenbasis J hJ hdiag).repr (gibbsEuclideanEquiv J f) a) * + ((spinEigenbasis J hJ hdiag).repr (gibbsEuclideanEquiv J g) a) := by + change weightedInner J (fun x i => halfDiff i f x) + (gradientSemigroup J t (fun x i => halfDiff i g x)) = _ + simp_rw [weightedInner, ← halfDiff_semigroup] + change dirichlet J f (semigroup J t g) = _ + rw [spectral_bilinear_dirichlet J hJ hdiag] + simp_rw [spectral_semigroup_coordinates] + apply Finset.sum_congr rfl + intro a _ + ring + +theorem exact_gradient_semigroup_positive {n : ℕ} (J : Interaction n) + (hJ : ∀ i j, J i j = J j i) (hdiag : ∀ i, J i i = 0) + (t : ℝ) (f : Observables n) : + 0 ≤ weightedInner J (gradientCLM n f) (gradientSemigroup J t (gradientCLM n f)) := by + rw [spectral_gradient_correlation J hJ hdiag] + apply Finset.sum_nonneg + intro a _ + rw [mul_assoc] + exact mul_nonneg (mul_nonneg (spinEigenvalues_nonneg J hJ hdiag a) + (le_of_lt (Real.exp_pos _))) (mul_self_nonneg _) + +lemma exact_gradient_semigroup_symmetric {n : ℕ} (J : Interaction n) + (hJ : ∀ i j, J i j = J j i) (hdiag : ∀ i, J i i = 0) + (t : ℝ) (f g : Observables n) : + weightedInner J (gradientCLM n f) (gradientSemigroup J t (gradientCLM n g)) = + weightedInner J (gradientCLM n g) (gradientSemigroup J t (gradientCLM n f)) := by + rw [spectral_gradient_correlation J hJ hdiag, spectral_gradient_correlation J hJ hdiag] + apply Finset.sum_congr rfl + intro a _ + ring + +theorem exact_gradient_semigroup_gap {n : ℕ} (J : Interaction n) + (hJ : ∀ i j, J i j = J j i) (hdiag : ∀ i, J i i = 0) + {γ : ℝ} (hγ : HasGap J γ) (t : ℝ) (ht : 0 ≤ t) (f : Observables n) : + weightedInner J (gradientSemigroup J t (gradientCLM n f)) + (gradientSemigroup J t (gradientCLM n f)) ≤ + Real.exp (-2 * γ * t) * weightedInner J (gradientCLM n f) (gradientCLM n f) := by + have hg : gradientSemigroup J t (gradientCLM n f) = gradientCLM n (semigroup J t f) := by + ext x i + exact (halfDiff_semigroup J t f x i).symm + rw [hg] + change dirichlet J (semigroup J t f) (semigroup J t f) ≤ Real.exp (-2 * γ * t) * dirichlet J f f + rw [spectral_dirichlet J hJ hdiag, spectral_dirichlet J hJ hdiag, Finset.mul_sum] + simp_rw [spectral_semigroup_coordinates] + apply Finset.sum_le_sum + intro a _ + by_cases ha : spinEigenvalues J hJ hdiag a = 0 + · simp only [ha, zero_mul, mul_zero, le_refl] + · have hp := lt_of_le_of_ne (spinEigenvalues_nonneg J hJ hdiag a) (Ne.symm ha) + have hle := gap_le_positive_eigenvalue J hJ hdiag hγ a hp + have he : Real.exp (-spinEigenvalues J hJ hdiag a * t) ^ 2 ≤ Real.exp (-2 * γ * t) := by + rw [← Real.exp_nat_mul] + apply Real.exp_le_exp.mpr + norm_num only [Nat.cast_ofNat] + nlinarith only [mul_nonneg (sub_nonneg.mpr hle) ht] + have hm := mul_le_mul_of_nonneg_right he + (mul_nonneg (le_of_lt hp) + (sq_nonneg ((spinEigenbasis J hJ hdiag).repr (gibbsEuclideanEquiv J f) a))) + convert hm using 1 + ring + +end SKGapCutoff + +open scoped BigOperators + +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Terminal/GibbsLExpectation.lean b/lean/OAI/Probability/SKGap/Terminal/GibbsLExpectation.lean new file mode 100644 index 0000000000000000000000000000000000000000..93545db952dc9fbf35270bc75e93596253a659ec --- /dev/null +++ b/lean/OAI/Probability/SKGap/Terminal/GibbsLExpectation.lean @@ -0,0 +1,173 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.LogPartitionDeviationProbability +import OAI.Probability.SKGap.Terminal.SingleSpinPlantedLaw + +namespace OAI + +section +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open scoped BigOperators +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open scoped BigOperators +open scoped BigOperators NNReal ENNReal +open MeasureTheory Metric Set +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators NNReal ENNReal Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Set +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators ENNReal NNReal +namespace SKGapCutoff + +noncomputable def gibbsLExpectation {n : ℕ} + (q : GaussianCoordinates n → Spin n → ℝ≥0∞) (g : GaussianCoordinates n) : ℝ≥0∞ := + ∑ x, ENNReal.ofReal (gibbs (sampledInteraction g) x) * q g x + +lemma measurable_gibbsLExpectation {n : ℕ} + (q : GaussianCoordinates n → Spin n → ℝ≥0∞) (hq : ∀ x, Measurable (fun g => q g x)) : + Measurable (gibbsLExpectation q) := by + apply Finset.measurable_sum + intro x _ + exact (((continuous_gibbs x).comp (continuous_sampledInteraction n)).measurable.ennreal_ofReal).mul (hq x) + +lemma planted_gibbs_density (β : ℝ) {n : ℕ} (hn : 0 < n) + (g : GaussianCoordinates n) (x : Spin n) : + (partition (sampledInteraction g) / + (∫ h, partition (sampledInteraction h) ∂disorderLaw β n)) * gibbs (sampledInteraction g) x = + ((2 : ℝ)^n)⁻¹ * Real.exp (energy (sampledInteraction g) x - β^2*((n:ℝ)-1)/4) := by + rw [integral_partition_sampled β hn, gibbs, Real.exp_sub] + field_simp [ne_of_gt (partition_pos (sampledInteraction g))] + +lemma planted_gibbs_lintegral (β : ℝ) {n : ℕ} (hn : 0 < n) + (q : GaussianCoordinates n → Spin n → ℝ≥0∞) (hq : ∀ x, Measurable (fun g => q g x)) : + (∫⁻ g, gibbsLExpectation q g ∂plantedDisorderLaw β n) = + ENNReal.ofReal (((2:ℝ)^n)⁻¹) * + ∑ x : Spin n, ∫⁻ g, q g x ∂singleSpinPlantedLaw β x := by + have hm := (continuous_partition n).comp (continuous_sampledInteraction n) + unfold plantedDisorderLaw + have hr : Measurable (fun g : GaussianCoordinates n => ENNReal.ofReal + (partition (sampledInteraction g) / + (∫ h, partition (sampledInteraction h) ∂disorderLaw β n))) := by + exact (hm.measurable.div_const _).ennreal_ofReal + rw [lintegral_withDensity_eq_lintegral_mul _ hr (measurable_gibbsLExpectation q hq)] + change (∫⁻ g, _ * (∑ x, ENNReal.ofReal (gibbs (sampledInteraction g) x) * q g x) ∂disorderLaw β n) = _ + simp only [Finset.mul_sum, ← mul_assoc] + have hp (g : GaussianCoordinates n) (x : Spin n) : + ENNReal.ofReal (partition (sampledInteraction g) / + (∫ h, partition (sampledInteraction h) ∂disorderLaw β n)) * + ENNReal.ofReal (gibbs (sampledInteraction g) x) = + ENNReal.ofReal (((2:ℝ)^n)⁻¹) * + ENNReal.ofReal (Real.exp (energy (sampledInteraction g) x - β^2*((n:ℝ)-1)/4)) := by + rw [← ENNReal.ofReal_mul (by + exact div_nonneg (partition_pos _).le (by rw [integral_partition_sampled β hn]; positivity)), + planted_gibbs_density β hn, ENNReal.ofReal_mul (by positivity)] + have hE (x : Spin n) : Measurable (fun g : GaussianCoordinates n => + ENNReal.ofReal (Real.exp (energy (sampledInteraction g) x - β^2*((n:ℝ)-1)/4))) := + ((((continuous_energy x).comp (continuous_sampledInteraction n)).measurable.sub_const _).exp).ennreal_ofReal + simp_rw [hp, mul_assoc] + have hterm (x : Spin n) : Measurable (fun g : GaussianCoordinates n => + ENNReal.ofReal (((2:ℝ)^n)⁻¹) * + (ENNReal.ofReal (Real.exp (energy (sampledInteraction g) x - β^2*((n:ℝ)-1)/4)) * q g x)) := + measurable_const.mul ((hE x).mul (hq x)) + rw [lintegral_finsetSum Finset.univ (fun x _ => hterm x)] + apply Finset.sum_congr rfl + intro x _ + have hf : Measurable (fun g : GaussianCoordinates n => + ENNReal.ofReal (Real.exp (energy (sampledInteraction g) x - β^2*((n:ℝ)-1)/4)) * q g x) := + (hE x).mul (hq x) + rw [lintegral_const_mul _ hf] + congr 1 + rw [singleSpinPlantedLaw, lintegral_withDensity_eq_lintegral_mul _ (hE x) (hq x)] + rfl + +lemma planted_failure_probability_bound (β : ℝ) {n : ℕ} (hn : 0 < n) + (a s : ℝ) (f : GaussianCoordinates n → ℝ≥0∞) (hf : Measurable f) : + disorderLaw β n {g | ENNReal.ofReal (Real.exp (-s)) ≤ f g} ≤ + disorderLaw β n {g | a/(n:ℝ) < |(Real.log (partition (sampledInteraction g)) - + Real.log (∫ h, partition (sampledInteraction h) ∂disorderLaw β n))/(n:ℝ)|} + + ENNReal.ofReal (Real.exp (a+s)) * ∫⁻ g, f g ∂plantedDisorderLaw β n := by + let m := ∫ h, partition (sampledInteraction h) ∂disorderLaw β n + let E := {g : GaussianCoordinates n | Real.log m - a ≤ Real.log (partition (sampledInteraction g))} + have hsub : {g | ENNReal.ofReal (Real.exp (-s)) ≤ f g} ⊆ + Eᶜ ∪ {g | Real.log m - a ≤ Real.log (partition (sampledInteraction g)) ∧ + ENNReal.ofReal (Real.exp (-s)) ≤ f g} := by + intro g hg + by_cases h : g ∈ E + · exact Or.inr ⟨h,hg⟩ + · exact Or.inl h + apply (measure_mono hsub).trans + apply (measure_union_le _ _).trans + apply add_le_add _ (planted_law_transfer β hn a s f hf) + apply measure_mono + intro g hg + have hnR : (0:ℝ) < n := Nat.cast_pos.mpr hn + have hh : Real.log (partition (sampledInteraction g)) < Real.log m - a := lt_of_not_ge hg + change a/(n:ℝ) < |(Real.log (partition (sampledInteraction g)) - Real.log m)/(n:ℝ)| + rw [abs_div, abs_of_pos hnR] + apply (div_lt_div_iff_of_pos_right hnR).mpr + linarith [neg_le_abs (Real.log (partition (sampledInteraction g)) - Real.log m)] + +lemma quenched_exponential_transfer (β : ℝ) (hβ : β^2 < 1) + (c : ℝ) (hc : 0 < c) (f : (n : ℕ) → GaussianCoordinates n → ℝ≥0∞) + (hf : ∀ n, Measurable (f n)) + (hsmall : ∀ᶠ n : ℕ in atTop, (∫⁻ g, f n g ∂plantedDisorderLaw β n) ≤ + ENNReal.ofReal (Real.exp (-c*n))) : + Tendsto (fun n => disorderLaw β n {g | ENNReal.ofReal (Real.exp (-(c/2)*n)) ≤ f n g}) + atTop (nhds 0) := by + have hlog := log_partition_annealed_difference_limit β hβ (c/4) (by positivity) + simp only [sub_zero] at hlog + have he : Tendsto (fun n : ℕ => Real.exp (-(c/4)*n)) atTop (nhds 0) := by + have hh := Real.tendsto_exp_neg_atTop_nhds_zero.comp + ((tendsto_natCast_atTop_atTop : Tendsto (fun n : ℕ => (n:ℝ)) atTop atTop).const_mul_atTop + (show 0 < c/4 by positivity)) + simpa only [Function.comp_def, neg_mul] using hh + have he' := ENNReal.continuous_ofReal.continuousAt.tendsto.comp he + simp only [ENNReal.ofReal_zero] at he' + have hb := hlog.add he' + simp only [zero_add] at hb + apply tendsto_of_tendsto_of_tendsto_of_le_of_le' tendsto_const_nhds hb + (Eventually.of_forall (fun _ => bot_le)) + filter_upwards [eventually_gt_atTop 0, hsmall] with n hn hs + have hh := planted_failure_probability_bound β hn (c*n/4) (c*n/2) (f n) (hf n) + have hn0 : (n:ℝ) ≠ 0 := Nat.cast_ne_zero.mpr (Nat.ne_of_gt hn) + have hfrac : (c*(n:ℝ)/4)/(n:ℝ) = c/4 := by field_simp + rw [hfrac] at hh + have hleft : -(c*(n:ℝ)/2) = -(c/2)*n := by ring + rw [hleft] at hh + apply hh.trans + apply add_le_add le_rfl + calc + _ ≤ ENNReal.ofReal (Real.exp (c*n/4+c*n/2)) * + ENNReal.ofReal (Real.exp (-c*n)) := mul_le_mul' le_rfl hs + _ = _ := by + rw [← ENNReal.ofReal_mul (Real.exp_pos _).le, ← Real.exp_add] + congr 2 + ring + +end SKGapCutoff + +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Matrix + +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Terminal/Map.lean b/lean/OAI/Probability/SKGap/Terminal/Map.lean new file mode 100644 index 0000000000000000000000000000000000000000..b202e8e55b6627ec8d81ec6eacdc39dd1726a625 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Terminal/Map.lean @@ -0,0 +1,142 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.Append +import OAI.Probability.SKGap.Localization.NoiseSplit + +namespace OAI + +section +noncomputable section +noncomputable section +open scoped BigOperators +noncomputable section +noncomputable section +noncomputable section +open scoped BigOperators +noncomputable section +open scoped BigOperators +noncomputable section +open scoped BigOperators +noncomputable section +open scoped BigOperators +noncomputable section +open scoped BigOperators +namespace SKGap.Noncrossing +namespace Diagram +variable {D E : Type*} + +@[simp] lemma map_size (f : D→E) (d : Diagram D) : (d.map f).size=d.size := by + induction d <;> simp_all [map,size] +lemma map_map {G : Type*} (f : D→E) (g : E→G) (d : Diagram D) : + (d.map f).map g=d.map (g∘f) := by induction d <;> simp_all [map] + +lemma fiber_map_injective (f : D→E) (d e : Diagram D) + (hw : d.word=e.word) (he : d.map f=e.map f) : d=e := by + induction d generalizing e with + | nil => cases e <;> simp_all [word,map] + | diag a d ih => + cases e with + | nil => simp [word] at hw + | arch u v => simp [word] at hw + | diag b e => + simp only [word,List.cons.injEq,Letter.diag.injEq] at hw + simp only [map,Diagram.diag.injEq] at he + obtain ⟨rfl,hw⟩ := hw + exact congrArg (Diagram.diag a) (ih e hw he.2) + | arch d r hd hr => + cases e with + | nil => simp [word] at hw + | diag b e => simp [word] at hw + | arch u v => + simp only [map,Diagram.arch.injEq] at he + have hlen : d.word.length=u.word.length := by + simpa only [word_length,map_size] using congrArg Diagram.size he.1 + simp only [word,List.cons.injEq,true_and] at hw + have hw' := List.append_inj hw hlen + have hu := hd u hw'.1 he.1 + have hv := hr v (List.cons.inj hw'.2).2 he.2 + subst u; subst v; rfl + +lemma exists_map_of_word (f : D→E) (d : Diagram E) (F : List (Letter D)) + (hw : F.map (Letter.map f)=d.word) : + ∃ e : Diagram D, e.word=F ∧ e.map f=d := by + induction d generalizing F with + | nil => + have hF : F=[] := List.map_eq_nil_iff.mp hw + subst F + exact ⟨.nil,rfl,rfl⟩ + | diag a d ih => + cases F with + | nil => simp [word] at hw + | cons l F => + cases l with + | noise => simp [Letter.map,word] at hw + | diag b => + simp only [List.map_cons,Letter.map,word,List.cons.injEq,Letter.diag.injEq] at hw + obtain ⟨e,he,hef⟩ := ih F hw.2 + exact ⟨.diag b e,by simp [word,he],by simp [map,hef,hw.1]⟩ + | arch d e hd he => + cases F with + | nil => simp [word] at hw + | cons l F => + cases l with + | diag b => simp [Letter.map,word] at hw + | noise => + simp only [List.map_cons,Letter.map,word,List.cons.injEq,true_and] at hw + obtain ⟨P,Q,hF,hP,hQ⟩ := List.map_eq_append_iff.mp hw + cases Q with + | nil => simp at hQ + | cons l Q => + cases l with + | diag b => simp [Letter.map] at hQ + | noise => + simp only [List.map_cons,Letter.map,List.cons.injEq,true_and] at hQ + obtain ⟨u,hu,huf⟩ := hd P hP + obtain ⟨v,hv,hvf⟩ := he Q hQ + exact ⟨.arch u v,by simp [word,hu,hv,hF],by simp [map,huf,hvf]⟩ + +def Paired.map (f : D→E) (F : List (Letter D)) (d : Paired F) : + Paired (F.map (Letter.map f)) := ⟨d.val.map f,by rw [map_word,d.property]⟩ +lemma Paired.map_bijective (f : D→E) (F : List (Letter D)) : + Function.Bijective (Paired.map f F) := by + constructor + · intro d e h + apply Subtype.ext + exact fiber_map_injective f d.val e.val (d.property.trans e.property.symm) + (congrArg (fun z => z.val) h) + · intro d + obtain ⟨e,he,hef⟩ := exists_map_of_word f d.val F d.property.symm + exact ⟨⟨e,he⟩,Subtype.ext hef⟩ +def Paired.mapEquiv (f : D→E) (F : List (Letter D)) : + Paired F ≃ Paired (F.map (Letter.map f)) := + Equiv.ofBijective (Paired.map f F) (Paired.map_bijective f F) + +variable {ι : Type*} [Fintype ι] +lemma evaluate_map (j : ℝ) (v : E→ι→ℝ) (f : D→E) (d : Diagram D) : + evaluate j v (d.map f)=evaluate j (v∘f) d := by simp [evaluate,map_map] + +lemma expect_map (j : ℝ) (v : E→ι→ℝ) (f : D→E) (F : List (Letter D)) (i : ι) : + expect j v (F.map (Letter.map f)) i=expect j (v∘f) F i := by + symm + apply Fintype.sum_equiv (Paired.mapEquiv f F) + intro d + exact congrFun (evaluate_map j v f d.val).symm i + +end Diagram +end SKGap.Noncrossing + +noncomputable section +open scoped BigOperators + +end +end +end +end +end +end +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Terminal/PairBoltzmann.lean b/lean/OAI/Probability/SKGap/Terminal/PairBoltzmann.lean new file mode 100644 index 0000000000000000000000000000000000000000..51cae6c9e9072ed5376f22a28a2ff1da34cb9615 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Terminal/PairBoltzmann.lean @@ -0,0 +1,239 @@ +import Mathlib +import OAI.Probability.SKGap.Terminal.TerminalMatrixTransfer +import OAI.Probability.SKGap.Terminal.PairCrossLower + +namespace OAI + +section +noncomputable section +namespace SKGap +open Real +open scoped BigOperators + +lemma exp_spin (t : ℝ) (x : Bool) : + exp (t*spinValue x)=cosh t*(1+tanh t*spinValue x) := by + have h : cosh t ≠ 0 := (cosh_pos t).ne' + cases x + · simp only [spinValue_false,mul_neg_one,tanh_eq_sinh_div_cosh] + rw [← cosh_sub_sinh] + field_simp + ring + · simp only [spinValue_true,mul_one,tanh_eq_sinh_div_cosh] + rw [← cosh_add_sinh] + field_simp + +lemma exp_spin_product (t : ℝ) (x y : Bool) : + exp (t*spinValue x*spinValue y)=cosh t*(1+tanh t*spinValue x*spinValue y) := by + cases y + · simp only [spinValue_false,mul_neg_one] + have he := exp_spin t (!x) + simpa only [spinValue_not,mul_neg,neg_mul] using he + · simpa only [spinValue_true,mul_one] using exp_spin t x + +def pairBoltzmannWeight (α γ J : ℝ) (x y : Bool) : ℝ := + exp (α*spinValue x+γ*spinValue y+J*spinValue x*spinValue y) +def pairBoltzmannMean (α γ J : ℝ) (F : Bool→Bool→ℝ) : ℝ := + (∑ x,∑ y,pairBoltzmannWeight α γ J x y*F x y)/(∑ x,∑ y,pairBoltzmannWeight α γ J x y) + +lemma pairBoltzmannWeight_factor (α γ J : ℝ) (x y : Bool) : + pairBoltzmannWeight α γ J x y=cosh α*cosh γ*cosh J* + ((1+tanh α*spinValue x)*(1+tanh γ*spinValue y)*(1+tanh J*spinValue x*spinValue y)) := by + unfold pairBoltzmannWeight + rw [exp_add,exp_add,exp_spin,exp_spin,exp_spin_product] + ring + +lemma pairBoltzmann_partition (α γ J : ℝ) : + (∑ x,∑ y,pairBoltzmannWeight α γ J x y)= + 4*cosh α*cosh γ*cosh J*(1+tanh J*tanh α*tanh γ) := by + simp only [pairBoltzmannWeight_factor,Fintype.sum_bool,spinValue_false,spinValue_true] + ring + +lemma pairBoltzmannMean_eq (α γ J : ℝ) (F : Bool→Bool→ℝ) : + pairBoltzmannMean α γ J F=pairInterMean (tanh α) (tanh γ) (tanh J) F := by + unfold pairBoltzmannMean pairInterMean pairMean + rw [pairBoltzmann_partition] + simp_rw [pairBoltzmannWeight_factor] + rw [Finset.sum_div] + apply Finset.sum_congr rfl + intro x _ + rw [Finset.sum_div] + apply Finset.sum_congr rfl + intro y _ + unfold pairBaseMass pairDensity + have h₁ := (cosh_pos α).ne' + have h₂ := (cosh_pos γ).ne' + have h₃ := (cosh_pos J).ne' + field_simp [h₁,h₂,h₃] + +lemma pair_gradients_representation (F : Bool→Bool→ℝ) (a b : ℝ) : + ∃ p s r : ℝ, + (∀ y,(F true y-F false y)/2=pairGrad₁ b p r y) ∧ + (∀ x,(F x true-F x false)/2=pairGrad₂ a s r x) := by + let r := (F true true-F true false-F false true+F false false)/4 + let p := (F true true+F true false-F false true-F false false)/4+b*r + let s := (F true true-F true false+F false true-F false false)/4+a*r + refine ⟨p,s,r,?_,?_⟩ + · intro y;cases y <;> simp only [pairGrad₁,spinValue_false,spinValue_true] <;> dsimp [p,r] <;> ring + · intro x;cases x <;> simp only [pairGrad₂,spinValue_false,spinValue_true] <;> dsimp [s,r] <;> ring + +lemma tanh_add_real (a b : ℝ) : tanh (a+b)=(tanh a+tanh b)/(1+tanh a*tanh b) := by + have h₁ := (cosh_pos a).ne' + have h₂ := (cosh_pos b).ne' + have h₃ : cosh a*cosh b+sinh a*sinh b ≠ 0 := by + rw [← cosh_add] + exact (cosh_pos (a+b)).ne' + simp only [tanh_eq_sinh_div_cosh,sinh_add,cosh_add] + field_simp [h₁,h₂,h₃] + +lemma tanh_pair_residual (α J : ℝ) (x y : Bool) : + spinValue x-tanh (α+J*spinValue y)=pairResidual (tanh α) (tanh J) x y := by + have hh : tanh (J*spinValue y)=tanh J*spinValue y := by + cases y <;> simp only [spinValue_false,spinValue_true,mul_one,mul_neg_one,tanh_neg] + rw [tanh_add_real,hh] + unfold pairResidual + have hd : 1+tanh α*(tanh J*spinValue y) ≠ 0 := by + have ht : |tanh α*(tanh J*spinValue y)| < 1 := by + rw [abs_mul,abs_mul,pairSign_abs,mul_one] + exact (mul_le_mul_of_nonneg_left (abs_tanh_lt_one J).le (abs_nonneg (tanh α))).trans_lt (by simpa using abs_tanh_lt_one α) + linarith only [(abs_lt.mp ht).1] + have hd' : 1+tanh J*tanh α*spinValue y ≠ 0 := by + convert hd using 1; ring + simp only [← mul_assoc] at hd hd' ⊢ + field_simp [hd,hd'] + cases x <;> simp only [spinValue_false,spinValue_true] <;> ring + +lemma tanh_pair_variance (α J : ℝ) (y : Bool) : + 1-tanh (α+J*spinValue y)^2=pairVariance (tanh α) (tanh J) y := by + have hh : tanh (J*spinValue y)=tanh J*spinValue y := by + cases y <;> simp only [spinValue_false,spinValue_true,mul_one,mul_neg_one,tanh_neg] + rw [tanh_add_real,hh] + unfold pairVariance + have hd : 1+tanh α*(tanh J*spinValue y) ≠ 0 := by + have ht : |tanh α*(tanh J*spinValue y)| < 1 := by + rw [abs_mul,abs_mul,pairSign_abs,mul_one] + exact (mul_le_mul_of_nonneg_left (abs_tanh_lt_one J).le (abs_nonneg (tanh α))).trans_lt (by simpa using abs_tanh_lt_one α) + linarith only [(abs_lt.mp ht).1] + have hd' : 1+tanh J*tanh α*spinValue y ≠ 0 := by + convert hd using 1; ring + simp only [← mul_assoc] at hd hd' ⊢ + field_simp [hd,hd'] + cases y <;> simp only [spinValue_false,spinValue_true] <;> ring + +lemma pairBoltzmann_signed_bound (α γ J : ℝ) (F : Bool→Bool→ℝ) + (hJ : |tanh J| ≤ 1/1000) : + let g₁ := fun y=>(F true y-F false y)/2; + let g₂ := fun x=>(F x true-F x false)/2; + let v₁ := fun y=>1-tanh (α+J*spinValue y)^2; + let v₂ := fun x=>1-tanh (γ+J*spinValue x)^2; + -tanh J*pairBoltzmannMean α γ J (fun x y=>v₁ y*g₁ y*(v₂ x*g₂ x))- + 400000*(tanh J)^2*pairBoltzmannMean α γ J (fun x y=>|v₁ y*g₁ y*(v₂ x*g₂ x)|)- + 400000*(tanh J)^4*pairBoltzmannMean α γ J (fun x y=>v₁ y*(g₁ y)^2+v₂ x*(g₂ x)^2) ≤ + pairBoltzmannMean α γ J (fun x y=>(spinValue x-tanh (α+J*spinValue y))*g₁ y* + ((spinValue y-tanh (γ+J*spinValue x))*g₂ x)) := by + dsimp only + obtain ⟨p,s,r,hg₁,hg₂⟩ := pair_gradients_representation F (tanh α) (tanh γ) + simp_rw [pairBoltzmannMean_eq,tanh_pair_residual,tanh_pair_variance,hg₁,hg₂] + exact pair_signed_bound (abs_tanh_lt_one α).le (abs_tanh_lt_one γ).le hJ +end SKGap + +end +end + +section +noncomputable section +namespace SKGap +open Real +open scoped BigOperators +variable {n : ℕ} + +lemma update_true_false (i : Fin n) (x : Spin n) : + (Function.update x i true=x ∧ Function.update x i false=flip i x) ∨ + (Function.update x i true=flip i x ∧ Function.update x i false=x) := by + cases hx : x i + · right + constructor + · simp [flip,hx] + · simpa only [hx] using Function.update_eq_self i x + · left + constructor + · simpa only [hx] using Function.update_eq_self i x + · simp [flip,hx] + +lemma conditionalExpectation_updates (g : Disorder n) (h : Fin n→ℝ) (i : Fin n) + (f : Spin n→ℝ) (x : Spin n) : + conditionalExpectation g h i f x= + (∑ b : Bool,weight g h (Function.update x i b)*f (Function.update x i b))/ + (∑ b : Bool,weight g h (Function.update x i b)) := by + simp only [Fintype.sum_bool] + rcases update_true_false i x with ⟨ht,hf⟩|⟨ht,hf⟩ <;> rw [ht,hf] + · rfl + · unfold conditionalExpectation + rw [add_comm (weight g h (flip i x)*f (flip i x)),add_comm (weight g h (flip i x))] + +lemma weight_update_factor (g : Disorder n) (h : Fin n→ℝ) (i : Fin n) (x : Spin n) (b : Bool) : + weight g h (Function.update x i b)=exp (hamiltonian g h x-spinValue (x i)*localField g h i x)* + exp (localField g h i x*spinValue b) := by + unfold weight + rw [hamiltonian_update,← exp_add] + congr 1;ring + +lemma conditionalExpectation_local (g : Disorder n) (h : Fin n→ℝ) (i : Fin n) + (f : Spin n→ℝ) (x : Spin n) : + conditionalExpectation g h i f x= + (f (Function.update x i true)+f (Function.update x i false))/2+ + tanh (localField g h i x)*spinGradient i f x := by + rw [conditionalExpectation_updates] + simp_rw [weight_update_factor,exp_spin] + simp only [Fintype.sum_bool,spinValue_true,spinValue_false,mul_one,mul_neg_one] + unfold spinGradient + have h₁ := (exp_pos (hamiltonian g h x-spinValue (x i)*localField g h i x)).ne' + have h₂ := (cosh_pos (localField g h i x)).ne' + have he : exp (hamiltonian g h x-spinValue (x i)*localField g h i x)* + (cosh (localField g h i x)*(1+tanh (localField g h i x)))+ + exp (hamiltonian g h x-spinValue (x i)*localField g h i x)* + (cosh (localField g h i x)*(1+-tanh (localField g h i x)))= + 2*exp (hamiltonian g h x-spinValue (x i)*localField g h i x)*cosh (localField g h i x) := by ring + rw [he] + field_simp [h₁,h₂] + ring + +lemma spin_affine (i : Fin n) (f : Spin n→ℝ) (x : Spin n) : + f x=(f (Function.update x i true)+f (Function.update x i false))/2+ + spinValue (x i)*spinGradient i f x := by + unfold spinGradient + cases hx : x i + · have hf : Function.update x i false=x := by simpa only [hx] using Function.update_eq_self i x + rw [spinValue_false,hf];ring + · have ht : Function.update x i true=x := by simpa only [hx] using Function.update_eq_self i x + rw [spinValue_true,ht];ring + +lemma conditionalDifference_local (g : Disorder n) (h : Fin n→ℝ) (i : Fin n) + (f : Spin n→ℝ) (x : Spin n) : + f x-conditionalExpectation g h i f x= + (spinValue (x i)-tanh (localField g h i x))*spinGradient i f x := by + rw [conditionalExpectation_local] + have he := spin_affine i f x + linarith only [he] + +lemma spinGradient_update (i : Fin n) (f : Spin n→ℝ) (x : Spin n) (b : Bool) : + spinGradient i f (Function.update x i b)=spinGradient i f x := by + simp only [spinGradient,Function.update_idem] + +lemma conditionalSiteEnergy_local (g : Disorder n) (h : Fin n→ℝ) (i : Fin n) + (f : Spin n→ℝ) : + expectation g h (fun x=>(f x-conditionalExpectation g h i f x)^2)= + expectation g h (fun x=>(1-tanh (localField g h i x)^2)*spinGradient i f x^2) := by + rw [← expectation_conditionalExpectation g h i] + congr 1 + funext x + rw [conditionalExpectation_local] + simp_rw [conditionalDifference_local,localField_update_self,spinGradient_update] + simp only [Function.update_self,spinValue_true,spinValue_false,spinGradient] + simp_rw [Function.update_idem,localField_update_self] + ring +end SKGap + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Terminal/PairConditioning.lean b/lean/OAI/Probability/SKGap/Terminal/PairConditioning.lean new file mode 100644 index 0000000000000000000000000000000000000000..af122423036f956d1fa43315a6fc44fde4d0f026 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Terminal/PairConditioning.lean @@ -0,0 +1,152 @@ +import Mathlib +import OAI.Probability.SKGap.Terminal.PairBoltzmann + +namespace OAI + +section +noncomputable section +namespace SKGap +open Real +open scoped BigOperators +variable {n : ℕ} + +def pairUpdate (i j : Fin n) (x : Spin n) (a b : Bool) : Spin n := + Function.update (Function.update x i a) j b + +lemma pairUpdate_overwrite (i j : Fin n) (hij : i ≠ j) (x : Spin n) (a b c d : Bool) : + pairUpdate i j (pairUpdate i j x a b) c d=pairUpdate i j x c d := by + funext k + by_cases hj : k=j + · subst k;simp [pairUpdate] + · by_cases hi : k=i + · subst k;simp [pairUpdate,hij] + · simp [pairUpdate,hj,hi] + +lemma pairUpdate_left (i j : Fin n) (hij : i ≠ j) (x : Spin n) (a b : Bool) : + pairUpdate i j x a b i=a := by simp [pairUpdate,hij] +lemma pairUpdate_right (i j : Fin n) (x : Spin n) (a b : Bool) : + pairUpdate i j x a b j=b := by simp [pairUpdate] + +lemma sum_spin_update (i : Fin n) (F : Spin n→ℝ) : + (∑ x,∑ b : Bool,F (Function.update x i b))=2*∑ x,F x := by + have he (x : Spin n) : (∑ b : Bool,F (Function.update x i b))=F x+F (flip i x) := by + simp only [Fintype.sum_bool] + rcases update_true_false i x with ⟨ht,hf⟩|⟨ht,hf⟩ <;> rw [ht,hf]; ring + simp_rw [he] + rw [Finset.sum_add_distrib,sum_flip] + ring + +lemma sum_pairUpdate (i j : Fin n) (F : Spin n→ℝ) : + (∑ x,∑ a : Bool,∑ b : Bool,F (pairUpdate i j x a b))=4*∑ x,F x := by + unfold pairUpdate + rw [sum_spin_update i (fun x=>∑ b : Bool,F (Function.update x j b)),sum_spin_update] + ring + +def pairConditionalMean (g : Disorder n) (h : Fin n→ℝ) (i j : Fin n) + (F : Spin n→ℝ) (x : Spin n) : ℝ := + (∑ a : Bool,∑ b : Bool,weight g h (pairUpdate i j x a b)*F (pairUpdate i j x a b))/ + (∑ a : Bool,∑ b : Bool,weight g h (pairUpdate i j x a b)) + +lemma pairConditionalMean_update (g : Disorder n) (h : Fin n→ℝ) (i j : Fin n) (hij : i ≠ j) + (F : Spin n→ℝ) (x : Spin n) (a b : Bool) : + pairConditionalMean g h i j F (pairUpdate i j x a b)=pairConditionalMean g h i j F x := by + simp only [pairConditionalMean,pairUpdate_overwrite i j hij] + +lemma pairConditional_partition_pos (g : Disorder n) (h : Fin n→ℝ) (i j : Fin n) (x : Spin n) : + 0 < ∑ a : Bool,∑ b : Bool,weight g h (pairUpdate i j x a b) := by + simp only [Fintype.sum_bool] + exact add_pos (add_pos (weight_pos _ _ _) (weight_pos _ _ _)) + (add_pos (weight_pos _ _ _) (weight_pos _ _ _)) + +lemma expectation_pairConditionalMean (g : Disorder n) (h : Fin n→ℝ) (i j : Fin n) (hij : i ≠ j) + (F : Spin n→ℝ) : expectation g h (pairConditionalMean g h i j F)=expectation g h F := by + have h₁ := sum_pairUpdate i j (fun x=>mass g h x*pairConditionalMean g h i j F x) + have h₂ := sum_pairUpdate i j (fun x=>mass g h x*F x) + have he : (∑ x,∑ a : Bool,∑ b : Bool,mass g h (pairUpdate i j x a b)* + pairConditionalMean g h i j F (pairUpdate i j x a b))= + ∑ x,∑ a : Bool,∑ b : Bool,mass g h (pairUpdate i j x a b)*F (pairUpdate i j x a b) := by + apply Finset.sum_congr rfl + intro x _ + simp_rw [pairConditionalMean_update g h i j hij,mass,div_mul_eq_mul_div] + simp only [← Finset.sum_div,← Finset.sum_mul] + unfold pairConditionalMean + rw [mul_div_cancel₀ _ (pairConditional_partition_pos g h i j x).ne'] + unfold expectation + linarith only [h₁,h₂,he] + +lemma pairUpdate_hamiltonian (g : Disorder n) (h : Fin n→ℝ) (i j : Fin n) (hij : i ≠ j) + (x : Spin n) (a b : Bool) : + let α := localField g h i x-coupling g i j*spinValue (x j); + let γ := localField g h j x-coupling g i j*spinValue (x i); + hamiltonian g h (pairUpdate i j x a b)= + (hamiltonian g h x-α*spinValue (x i)-γ*spinValue (x j)- + coupling g i j*spinValue (x i)*spinValue (x j))+ + (α*spinValue a+γ*spinValue b+coupling g i j*spinValue a*spinValue b) := by + dsimp only + unfold pairUpdate + rw [hamiltonian_update,hamiltonian_update,localField_update, + Function.update_of_ne (Ne.symm hij),coupling_symm g j i] + ring + +lemma pairUpdate_localField₁ (g : Disorder n) (h : Fin n→ℝ) (i j : Fin n) + (x : Spin n) (a b : Bool) : + localField g h i (pairUpdate i j x a b)= + (localField g h i x-coupling g i j*spinValue (x j))+coupling g i j*spinValue b := by + unfold pairUpdate + rw [localField_update,localField_update_self] + by_cases hij : i=j + · subst j;simp + · rw [Function.update_of_ne (Ne.symm hij)] + ring + +lemma pairUpdate_localField₂ (g : Disorder n) (h : Fin n→ℝ) (i j : Fin n) + (x : Spin n) (a b : Bool) : + localField g h j (pairUpdate i j x a b)= + (localField g h j x-coupling g i j*spinValue (x i))+coupling g i j*spinValue a := by + unfold pairUpdate + rw [localField_update_self,localField_update,coupling_symm g j i] + ring + +lemma pairUpdate_gradient₁ (i j : Fin n) (hij : i ≠ j) (F : Spin n→ℝ) + (x : Spin n) (a b : Bool) : + spinGradient i F (pairUpdate i j x a b)= + (F (pairUpdate i j x true b)-F (pairUpdate i j x false b))/2 := by + have he (c : Bool) : Function.update (pairUpdate i j x a b) i c=pairUpdate i j x c b := by + funext k + by_cases hi : k=i + · subst k;simp [pairUpdate,hij] + · by_cases hj : k=j + · subst k;simp [pairUpdate,hij.symm] + · simp [pairUpdate,hj,hi] + simp only [spinGradient,he] +lemma pairUpdate_gradient₂ (i j : Fin n) (F : Spin n→ℝ) + (x : Spin n) (a b : Bool) : + spinGradient j F (pairUpdate i j x a b)= + (F (pairUpdate i j x a true)-F (pairUpdate i j x a false))/2 := by + simp only [spinGradient,pairUpdate,Function.update_idem] + +lemma pairConditionalMean_boltzmann (g : Disorder n) (h : Fin n→ℝ) (i j : Fin n) (hij : i ≠ j) + (F : Spin n→ℝ) (x : Spin n) : + pairConditionalMean g h i j F x= + pairBoltzmannMean (localField g h i x-coupling g i j*spinValue (x j)) + (localField g h j x-coupling g i j*spinValue (x i)) (coupling g i j) + (fun a b=>F (pairUpdate i j x a b)) := by + let α := localField g h i x-coupling g i j*spinValue (x j) + let γ := localField g h j x-coupling g i j*spinValue (x i) + let C := exp (hamiltonian g h x-α*spinValue (x i)-γ*spinValue (x j)- + coupling g i j*spinValue (x i)*spinValue (x j)) + have hC : C ≠ 0 := (exp_pos _).ne' + have hw (a b : Bool) : weight g h (pairUpdate i j x a b)=C*pairBoltzmannWeight α γ (coupling g i j) a b := by + unfold weight + rw [pairUpdate_hamiltonian g h i j hij,exp_add] + rfl + unfold pairConditionalMean + simp_rw [hw,mul_assoc,← Finset.mul_sum] + rw [mul_div_mul_left _ _ hC] + rfl +end SKGap + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Terminal/PairCrossIdentity.lean b/lean/OAI/Probability/SKGap/Terminal/PairCrossIdentity.lean new file mode 100644 index 0000000000000000000000000000000000000000..177f2143d7c1a7eae458ad4543c657eae29e5fa4 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Terminal/PairCrossIdentity.lean @@ -0,0 +1,271 @@ +import Mathlib +import OAI.Probability.SKGap.Terminal.SpinLocalField +import OAI.Probability.SKGap.Terminal.PairRationalBounds + +namespace OAI + +section +noncomputable section +namespace SKGap +open Real +open scoped BigOperators + +def pairDensity (a b u : ℝ) (x y : Bool) : ℝ := + (1+u*spinValue x*spinValue y)/(1+u*a*b) +def pairInterMean (a b u : ℝ) (F : Bool→Bool→ℝ) : ℝ := + pairMean a b (fun x y=>pairDensity a b u x y*F x y) +def pairResidual (a u : ℝ) (x y : Bool) : ℝ := + (spinValue x-a)*(1-u*spinValue x*spinValue y)/(1+u*a*spinValue y) +def pairVariance (a u : ℝ) (y : Bool) : ℝ := + (1-a^2)*(1-u^2)/(1+u*a*spinValue y)^2 + +def pairGrad₁ (b p r : ℝ) (y : Bool) : ℝ := p+r*(spinValue y-b) +def pairGrad₂ (a s r : ℝ) (x : Bool) : ℝ := s+r*(spinValue x-a) + +lemma pairSign_abs (x : Bool) : |spinValue x|=1 := by cases x <;> norm_num [spinValue] +lemma pairSign_sq (x : Bool) : spinValue x^2=1 := by cases x <;> norm_num [spinValue] + +lemma pairDenominator_pos {u a b : ℝ} (hu : |u| ≤ 1/4) (ha : |a| ≤ 1) (hb : |b| ≤ 1) : + 0 < 1+u*a*b := by + have hh := (pair_factor_control hu (abs_mul_le_one_pair ha hb)).1 + rw [← mul_assoc] at hh + linarith only [hh] + +lemma reciprocal_affine (c d v : ℝ) (y : Bool) (hv : |v| < 1) : + (c+d*spinValue y)/(1+v*spinValue y)= + (c-v*d)/(1-v^2)+spinValue y*((d-v*c)/(1-v^2)) := by + have hv' := abs_lt.mp hv + have h₁ : 1+v ≠ 0 := by linarith only [hv'.1] + have h₂ : 1-v ≠ 0 := by linarith only [hv'.2] + have h₃ : 1-v^2 ≠ 0 := by + have he : 1-v^2=(1+v)*(1-v) := by ring + rw [he];exact mul_ne_zero h₁ h₂ + cases y <;> simp only [spinValue,Bool.false_eq_true,ite_false,ite_true,mul_one,mul_neg_one,← sub_eq_add_neg] + · field_simp [h₂,h₃] + ring + · field_simp [h₁,h₃] + ring + +lemma pair_gradient_reciprocal {a b u p r : ℝ} (ha : |a| ≤ 1) (hu : |u| ≤ 1/4) (y : Bool) : + pairGrad₁ b p r y/(1+u*a*spinValue y)= + (p-(b+u*a)*r)/(1-u^2*a^2)+ + spinValue y*((r*(1+u*a*b)-u*a*p)/(1-u^2*a^2)) := by + have hv : |u*a| < 1 := by + rw [abs_mul] + have hh := mul_le_mul_of_nonneg_left ha (abs_nonneg u) + nlinarith only [hu,hh] + have he := reciprocal_affine (p-r*b) r (u*a) y hv + have hg : pairGrad₁ b p r y =p-r*b+r*spinValue y := by unfold pairGrad₁;ring + rw [hg,he] + congr 1 + · congr 1 <;> ring + · congr 1 + congr 1 <;> ring + +lemma pair_cross_coefficient_identity {a b u p s r : ℝ} + (ha : |a| ≤ 1) (hb : |b| ≤ 1) (hu : |u| ≤ 1/4) : + (1-u^2)/(1+u*a*b)* + (((r*(1+u*a*b)-u*a*p)/(1-u^2*a^2))* + ((r*(1+u*a*b)-u*b*s)/(1-u^2*b^2))- + u*((p-(b+u*a)*r)/(1-u^2*a^2))*((s-(a+u*b)*r)/(1-u^2*b^2)))= + pairCrossPolynomial a b u p s r := by + have hd₀ := (pairDenominator_pos hu ha hb).ne' + have hd₁ : 1-u^2*a^2 ≠ 0 := by + have h₁ := pairDenominator_pos hu ha (by norm_num : |(1:ℝ)| ≤ 1) + have h₂ := pairDenominator_pos hu ha (by norm_num : |(-1:ℝ)| ≤ 1) + have he : 1-u^2*a^2=(1+u*a*1)*(1+u*a*(-1)) := by ring + rw [he];exact mul_ne_zero h₁.ne' h₂.ne' + have hd₂ : 1-u^2*b^2 ≠ 0 := by + have h₁ := pairDenominator_pos hu hb (by norm_num : |(1:ℝ)| ≤ 1) + have h₂ := pairDenominator_pos hu hb (by norm_num : |(-1:ℝ)| ≤ 1) + have he : 1-u^2*b^2=(1+u*b*1)*(1+u*b*(-1)) := by ring + rw [he];exact mul_ne_zero h₁.ne' h₂.ne' + unfold pairCrossPolynomial pairK pairR + field_simp [hd₀,hd₁,hd₂] + ring + +lemma pair_cross_pointwise (a b u p s r : ℝ) (x y : Bool) : + pairDensity a b u x y*(pairResidual a u x y*pairGrad₁ b p r y* + (pairResidual b u y x*pairGrad₂ a s r x))= + ((1-u^2)/(1+u*a*b))*((spinValue x-a)*(spinValue y-b)* + (1-u*spinValue x*spinValue y)*(pairGrad₁ b p r y/(1+u*a*spinValue y))* + (pairGrad₂ a s r x/(1+u*b*spinValue x))) := by + unfold pairDensity pairResidual + have he : (1+u*spinValue x*spinValue y)*(1-u*spinValue x*spinValue y)* + (1-u*spinValue y*spinValue x)=(1-u^2)*(1-u*spinValue x*spinValue y) := by + cases x <;> cases y <;> simp only [spinValue,Bool.false_eq_true,ite_false,ite_true] <;> ring + calc + _ = ((1+u*spinValue x*spinValue y)*(1-u*spinValue x*spinValue y)*(1-u*spinValue y*spinValue x))* + ((spinValue x-a)*(spinValue y-b)*pairGrad₁ b p r y*pairGrad₂ a s r x)/ + ((1+u*a*b)*(1+u*a*spinValue y)*(1+u*b*spinValue x)) := by + simp only [div_eq_mul_inv,mul_inv_rev] + ring + _ = _ := by + rw [he] + simp only [div_eq_mul_inv,mul_inv_rev] + ring + +lemma pair_cross_exact {a b u p s r : ℝ} + (ha : |a| ≤ 1) (hb : |b| ≤ 1) (hu : |u| ≤ 1/4) : + pairInterMean a b u (fun x y=>pairResidual a u x y*pairGrad₁ b p r y* + (pairResidual b u y x*pairGrad₂ a s r x))= + (1-a^2)*(1-b^2)*pairCrossPolynomial a b u p s r := by + unfold pairInterMean + simp_rw [pair_cross_pointwise] + rw [pairMean_mul] + have hh (x y : Bool) : + (spinValue x-a)*(spinValue y-b)*(1-u*spinValue x*spinValue y)* + (pairGrad₁ b p r y/(1+u*a*spinValue y))* + (pairGrad₂ a s r x/(1+u*b*spinValue x))= + (spinValue x-a)*(spinValue y-b)*(1-u*spinValue x*spinValue y)* + ((p-(b+u*a)*r)/(1-u^2*a^2)+spinValue y*((r*(1+u*a*b)-u*a*p)/(1-u^2*a^2)))* + ((s-(a+u*b)*r)/(1-u^2*b^2)+spinValue x*((r*(1+u*b*a)-u*b*s)/(1-u^2*b^2))) := by + rw [pair_gradient_reciprocal ha hu] + change _ * (pairGrad₁ a s r x / _) = _ + rw [pair_gradient_reciprocal hb hu] + simp_rw [hh] + rw [pair_polynomial_cross_mean] + have he : 1+u*b*a=1+u*a*b := by ring + rw [he] + calc + _ = (1-a^2)*(1-b^2)*((1-u^2)/(1+u*a*b)* + (((r*(1+u*a*b)-u*a*p)/(1-u^2*a^2))* + ((r*(1+u*a*b)-u*b*s)/(1-u^2*b^2))- + u*((p-(b+u*a)*r)/(1-u^2*a^2))*((s-(a+u*b)*r)/(1-u^2*b^2)))) := by ring + _ = _ := by rw [pair_cross_coefficient_identity ha hb hu] +end SKGap + +end +end + +section +noncomputable section +namespace SKGap +open Real + +lemma pair_variance_nonneg {a u : ℝ} (ha : |a| ≤ 1) (hu : |u| ≤ 1/4) (y : Bool) : + 0 ≤ pairVariance a u y := by + have ha2 : a^2 ≤ 1 := by nlinarith only [sq_abs a,abs_nonneg a,ha] + have hh := (pair_square_factor_control hu).1 + exact div_nonneg (mul_nonneg (sub_nonneg.mpr ha2) (by linarith only [hh])) (sq_nonneg _) + +lemma pair_density_nonneg {a b u : ℝ} (ha : |a| ≤ 1) (hb : |b| ≤ 1) + (hu : |u| ≤ 1/4) (x y : Bool) : 0 ≤ pairDensity a b u x y := by + exact div_nonneg (pairDenominator_pos hu (pairSign_abs x).le (pairSign_abs y).le).le + (pairDenominator_pos hu ha hb).le + +lemma pair_variance_product (a b u : ℝ) (x y : Bool) : + pairDensity a b u x y*(pairVariance a u y*pairVariance b u x)= + (1-a^2)*(1-b^2)*pairRationalWeight a b u (spinValue x) (spinValue y) := by + unfold pairDensity pairVariance pairRationalWeight + simp only [div_eq_mul_inv,mul_inv_rev] + ring + +lemma pair_weighted_product (a b u p s r : ℝ) : + pairInterMean a b u (fun x y=>pairVariance a u y*pairGrad₁ b p r y* + (pairVariance b u x*pairGrad₂ a s r x))= + (1-a^2)*(1-b^2)*pairMean a b (fun x y=>pairRationalWeight a b u (spinValue x) (spinValue y)* + (pairGrad₁ b p r y*pairGrad₂ a s r x)) := by + unfold pairInterMean + rw [← pairMean_mul] + congr 1 + funext x y + calc + _ = (pairDensity a b u x y*(pairVariance a u y*pairVariance b u x))* + (pairGrad₁ b p r y*pairGrad₂ a s r x) := by ring + _ = _ := by rw [pair_variance_product];ring + +lemma pair_abs_weighted_product {a b u p s r : ℝ} + (ha : |a| ≤ 1) (hb : |b| ≤ 1) (hu : |u| ≤ 1/4) : + pairInterMean a b u (fun x y=>|pairVariance a u y*pairGrad₁ b p r y* + (pairVariance b u x*pairGrad₂ a s r x)|)= + (1-a^2)*(1-b^2)*pairMean a b (fun x y=>pairRationalWeight a b u (spinValue x) (spinValue y)* + |pairGrad₁ b p r y*pairGrad₂ a s r x|) := by + unfold pairInterMean + rw [← pairMean_mul] + congr 1 + funext x y + have h₁ := pair_variance_nonneg ha hu y + have h₂ := pair_variance_nonneg hb hu x + simp only [abs_mul,abs_of_nonneg h₁,abs_of_nonneg h₂] + calc + _ = (pairDensity a b u x y*(pairVariance a u y*pairVariance b u x))* + (|pairGrad₁ b p r y| * |pairGrad₂ a s r x|) := by ring + _ = _ := by rw [pair_variance_product];ring + +lemma pair_weighted_error {a b u p s r : ℝ} + (ha : |a| ≤ 1) (hb : |b| ≤ 1) (hu : |u| ≤ 1/4) : + |pairMean a b (fun x y=>pairRationalWeight a b u (spinValue x) (spinValue y)* + (pairGrad₁ b p r y*pairGrad₂ a s r x))-p*s| ≤ + 1216*|u| * pairMean a b (fun x y=>|pairGrad₁ b p r y*pairGrad₂ a s r x|) := by + have he : p*s=pairMean a b (fun x y=>pairGrad₁ b p r y*pairGrad₂ a s r x) := + (pair_gradient_mean a b p s r).symm + rw [he,← pairMean_sub] + apply (abs_pairMean_le ha hb _).trans + rw [← pairMean_mul] + apply pairMean_mono ha hb + intro x y + have hh := (pairRationalWeight_bounds ha hb hu (pairSign_abs x).le (pairSign_abs y).le).2.2 + have ht : pairRationalWeight a b u (spinValue x) (spinValue y)* + (pairGrad₁ b p r y*pairGrad₂ a s r x)-(pairGrad₁ b p r y*pairGrad₂ a s r x)= + (pairRationalWeight a b u (spinValue x) (spinValue y)-1)* + (pairGrad₁ b p r y*pairGrad₂ a s r x) := by ring + rw [ht,abs_mul] + exact mul_le_mul_of_nonneg_right hh (abs_nonneg _) + +lemma pair_abs_cost_lower {a b u p s r : ℝ} + (ha : |a| ≤ 1) (hb : |b| ≤ 1) (hu : |u| ≤ 1/4) : + (1-a^2)*(1-b^2)*pairMean a b (fun x y=>|pairGrad₁ b p r y*pairGrad₂ a s r x|)/256 ≤ + pairInterMean a b u (fun x y=>|pairVariance a u y*pairGrad₁ b p r y* + (pairVariance b u x*pairGrad₂ a s r x)|) := by + rw [pair_abs_weighted_product ha hb hu] + have ha2 : a^2 ≤ 1 := by nlinarith only [sq_abs a,abs_nonneg a,ha] + have hb2 : b^2 ≤ 1 := by nlinarith only [sq_abs b,abs_nonneg b,hb] + have hAB : 0 ≤ (1-a^2)*(1-b^2) := mul_nonneg (sub_nonneg.mpr ha2) (sub_nonneg.mpr hb2) + have he : (1-a^2)*(1-b^2)*pairMean a b (fun x y=>|pairGrad₁ b p r y*pairGrad₂ a s r x|)/256= + (1-a^2)*(1-b^2)*((1/256)*pairMean a b (fun x y=>|pairGrad₁ b p r y*pairGrad₂ a s r x|)) := by ring + rw [he] + apply mul_le_mul_of_nonneg_left _ hAB + rw [← pairMean_mul] + apply pairMean_mono ha hb + intro x y + exact mul_le_mul_of_nonneg_right + (pairRationalWeight_bounds ha hb hu (pairSign_abs x).le (pairSign_abs y).le).1 (abs_nonneg _) + +lemma pair_density_variance_lower {a b u : ℝ} + (ha : |a| ≤ 1) (hb : |b| ≤ 1) (hu : |u| ≤ 1/4) (x y : Bool) : + (1-a^2)/32 ≤ pairDensity a b u x y*pairVariance a u y := by + have hn : 1/2 ≤ 1+u*spinValue x*spinValue y := by + simpa only [mul_assoc] using (pair_factor_control hu (abs_mul_le_one_pair (pairSign_abs x).le (pairSign_abs y).le)).1 + have hs := (pair_square_factor_control hu).1 + have hd₀ := pair_factor_control hu (abs_mul_le_one_pair ha hb) + have hd₁ := pair_factor_control hu (abs_mul_le_one_pair ha (pairSign_abs y).le) + have hd02 : 1+u*a*b ≤ 2 := by simpa only [mul_assoc] using hd₀.2.1 + have hd12 : 1+u*a*spinValue y ≤ 2 := by simpa only [mul_assoc] using hd₁.2.1 + have hd10 : 0 ≤ 1+u*a*spinValue y := (pairDenominator_pos hu ha (pairSign_abs y).le).le + have hd00 := pairDenominator_pos hu ha hb + have hdd : 0 < (1+u*a*b)*(1+u*a*spinValue y)^2 := mul_pos hd00 (sq_pos_of_pos (pairDenominator_pos hu ha (pairSign_abs y).le)) + have hd : (1+u*a*b)*(1+u*a*spinValue y)^2 ≤ 8 := by + have hh : (1+u*a*spinValue y)^2 ≤ 4 := by nlinarith only [hd12,hd10] + nlinarith only [mul_le_mul hd02 hh (sq_nonneg (1+u*a*spinValue y)) (by norm_num : (0:ℝ) ≤ 2)] + have ha2 : a^2 ≤ 1 := by nlinarith only [sq_abs a,abs_nonneg a,ha] + have hA := sub_nonneg.mpr ha2 + have hn' : 1/4 ≤ (1+u*spinValue x*spinValue y)*(1-u^2) := by + nlinarith only [mul_le_mul hn hs (by norm_num : (0:ℝ) ≤ 1/2) (by linarith only [hn] : 0 ≤ 1+u*spinValue x*spinValue y)] + have he : pairDensity a b u x y*pairVariance a u y= + ((1-a^2)*((1+u*spinValue x*spinValue y)*(1-u^2)))/ + ((1+u*a*b)*(1+u*a*spinValue y)^2) := by + unfold pairDensity pairVariance + simp only [div_eq_mul_inv,mul_inv_rev] + ring + rw [he] + apply (le_div_iff₀ hdd).mpr + have h₁ := mul_le_mul_of_nonneg_left hd (div_nonneg hA (by norm_num : (0:ℝ) ≤ 32)) + have h₂ := mul_le_mul_of_nonneg_left hn' hA + nlinarith only [h₁,h₂] +end SKGap + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Terminal/PairCrossLower.lean b/lean/OAI/Probability/SKGap/Terminal/PairCrossLower.lean new file mode 100644 index 0000000000000000000000000000000000000000..4403279cc1e88f715149dcbb433c1b2a916b3f5d --- /dev/null +++ b/lean/OAI/Probability/SKGap/Terminal/PairCrossLower.lean @@ -0,0 +1,206 @@ +import Mathlib +import OAI.Probability.SKGap.Terminal.PairCrossIdentity + +namespace OAI + +section +noncomputable section +namespace SKGap +open Real + +lemma abs_pair_ps_coefficient {a b u : ℝ} + (ha : |a| ≤ 1) (hb : |b| ≤ 1) (hu : |u| ≤ 1/1000) : + |pairK a b u*(-u+u^2*a*b)+u| ≤ 66*u^2 := by + have hk := pairK_bounds ha hb hu + have hk0 : 0 ≤ pairK a b u := by linarith only [hk.2.1] + have he : pairK a b u*(-u+u^2*a*b)+u= + -(pairK a b u-1)*u+pairK a b u*u^2*(a*b) := by ring + rw [he] + apply (abs_add_le _ _).trans + rw [abs_mul,abs_neg,abs_mul,abs_mul,abs_of_nonneg hk0,abs_of_nonneg (sq_nonneg u)] + have h₁ := mul_le_mul_of_nonneg_right hk.1 (abs_nonneg u) + have h₂ := mul_le_mul (mul_le_mul_of_nonneg_right hk.2.2 (sq_nonneg u)) + (abs_mul_le_one_pair ha hb) (abs_nonneg (a*b)) (by positivity : (0:ℝ) ≤ 2*u^2) + nlinarith only [h₁,h₂,sq_abs u] + +lemma abs_pair_mixed_coefficient {a b u : ℝ} + (ha : |a| ≤ 1) (hb : |b| ≤ 1) (hu : |u| ≤ 1/1000) : + |pairK a b u*u^2*b*(1-a^2)| ≤ 2*u^2 ∧ + |pairK a b u*u^2*a*(1-b^2)| ≤ 2*u^2 := by + have hk := pairK_bounds ha hb hu + have hk0 : 0 ≤ pairK a b u := by linarith only [hk.2.1] + have ha2 : a^2 ≤ 1 := by nlinarith only [sq_abs a,abs_nonneg a,ha] + have hb2 : b^2 ≤ 1 := by nlinarith only [sq_abs b,abs_nonneg b,hb] + have hA : |1-a^2| ≤ 1 := by rw [abs_of_nonneg (sub_nonneg.mpr ha2)];linarith [sq_nonneg a] + have hB : |1-b^2| ≤ 1 := by rw [abs_of_nonneg (sub_nonneg.mpr hb2)];linarith [sq_nonneg b] + have hh (x y : ℝ) (hxy : |x*y| ≤ 1) : |pairK a b u*u^2*x*y| ≤ 2*u^2 := by + rw [mul_assoc (pairK a b u*u^2),abs_mul,abs_mul,abs_of_nonneg hk0,abs_of_nonneg (sq_nonneg u)] + exact (mul_le_mul (mul_le_mul_of_nonneg_right hk.2.2 (sq_nonneg u)) hxy + (abs_nonneg _) (by positivity)).trans_eq (mul_one _) + exact ⟨hh b (1-a^2) (abs_mul_le_one_pair hb hA),hh a (1-b^2) (abs_mul_le_one_pair ha hB)⟩ + +lemma mul_lower_from_abs {c x B : ℝ} (hc : |c| ≤ B) : -B*|x| ≤ c*x := by + have hh := neg_abs_le (c*x) + rw [abs_mul] at hh + have hm := mul_le_mul_of_nonneg_right hc (abs_nonneg x) + linarith only [hh,hm] + +lemma pairCrossPolynomial_lower {a b u p s r : ℝ} + (ha : |a| ≤ 1) (hb : |b| ≤ 1) (hu : |u| ≤ 1/1000) : + r^2/2-66*u^2*|p*s|-2*u^2*|r*p|-2*u^2*|r*s| ≤ + pairCrossPolynomial a b u p s r+u*(p*s) := by + have hps := mul_lower_from_abs (x:=p*s) (abs_pair_ps_coefficient ha hb hu) + have hrp := mul_lower_from_abs (x:=r*p) (abs_pair_mixed_coefficient ha hb hu).1 + have hrs := mul_lower_from_abs (x:=r*s) (abs_pair_mixed_coefficient ha hb hu).2 + have hr := mul_le_mul_of_nonneg_right (pairKR_lower ha hb hu) (sq_nonneg r) + unfold pairCrossPolynomial + nlinarith only [hps,hrp,hrs,hr] + +lemma pair_young_cost (u r p : ℝ) : + 2*u^2*|r*p| ≤ r^2/4+4*u^4*p^2 := by + rw [abs_mul] + have he : (|r|/2-2*u^2*|p|)^2=r^2/4-2*u^2*|r| * |p|+4*u^4*p^2 := by + ring_nf + rw [sq_abs r,sq_abs p] + ring + nlinarith only [sq_nonneg (|r|/2-2*u^2*|p|),he] + +lemma pair_signed_cross_lower {a b u p s r z q : ℝ} + (ha : |a| ≤ 1) (hb : |b| ≤ 1) (hu : |u| ≤ 1/1000) + (hq : |p*s| ≤ q) (hz : |z-p*s| ≤ 1216*|u| * q) : + -1282*u^2*q-4*u^4*(p^2+s^2) ≤ pairCrossPolynomial a b u p s r+u*z := by + have h₁ := pairCrossPolynomial_lower (p:=p) (s:=s) (r:=r) ha hb hu + have h₂ := pair_young_cost u r p + have h₃ := pair_young_cost u r s + have h₄ := mul_le_mul_of_nonneg_left hq (show 0 ≤ 66*u^2 by positivity) + have hz' : -1216*u^2*q ≤ u*(z-p*s) := by + have hh := neg_abs_le (u*(z-p*s)) + rw [abs_mul] at hh + have hm := mul_le_mul_of_nonneg_left hz (abs_nonneg u) + have he : |u| * (1216*|u| * q)=1216*u^2*q := by + ring_nf + rw [sq_abs u] + ring + rw [he] at hm + linarith only [hh,hm] + nlinarith only [h₁,h₂,h₃,h₄,hz'] +end SKGap + +end +end + +section +noncomputable section +namespace SKGap +open Real + +lemma pair_energy_lower {a b u p r : ℝ} + (ha : |a| ≤ 1) (hb : |b| ≤ 1) (hu : |u| ≤ 1/4) : + (1-a^2)*(1-b^2)*p^2/32 ≤ + pairInterMean a b u (fun _x y=>pairVariance a u y*(pairGrad₁ b p r y)^2) := by + have ha2 : a^2 ≤ 1 := by nlinarith only [sq_abs a,abs_nonneg a,ha] + have hb2 : b^2 ≤ 1 := by nlinarith only [sq_abs b,abs_nonneg b,hb] + have hA := sub_nonneg.mpr ha2 + have hB := sub_nonneg.mpr hb2 + have he := pairMean_mono ha hb (fun x y=>mul_le_mul_of_nonneg_right + (pair_density_variance_lower ha hb hu x y) (sq_nonneg (pairGrad₁ b p r y))) + simp only [pairMean_mul] at he + have h₁ : pairMean a b (fun _ y=>(pairGrad₁ b p r y)^2)=p^2+(1-b^2)*r^2 := + pair_gradient_square a b p r + rw [h₁] at he + have h₂ : pairMean a b (fun x y=>pairDensity a b u x y*pairVariance a u y*(pairGrad₁ b p r y)^2)= + pairInterMean a b u (fun _x y=>pairVariance a u y*(pairGrad₁ b p r y)^2) := by + unfold pairInterMean + congr 1 + funext x y + ring + rw [h₂] at he + have h₃ : (1-a^2)*(1-b^2)*p^2 ≤ (1-a^2)*p^2 := by + have hh := mul_le_mul_of_nonneg_right (show 1-b^2 ≤ 1 by linarith [sq_nonneg b]) + (mul_nonneg hA (sq_nonneg p)) + nlinarith only [hh] + have h₄ : 0 ≤ (1-a^2)*(1-b^2)*r^2 := mul_nonneg (mul_nonneg hA hB) (sq_nonneg r) + nlinarith only [he,h₃,h₄] + +lemma pairInterMean_swap (a b u : ℝ) (F : Bool→Bool→ℝ) : + pairInterMean a b u F=pairInterMean b a u (fun x y=>F y x) := by + unfold pairInterMean + rw [pairMean_swap] + congr 1 + funext x y + unfold pairDensity + have he : (1+u*spinValue y*spinValue x)/(1+u*a*b)= + (1+u*spinValue x*spinValue y)/(1+u*b*a) := by congr 1 <;> ring + rw [he] + +lemma pair_second_energy_lower {a b u s r : ℝ} + (ha : |a| ≤ 1) (hb : |b| ≤ 1) (hu : |u| ≤ 1/4) : + (1-a^2)*(1-b^2)*s^2/32 ≤ + pairInterMean a b u (fun x _y=>pairVariance b u x*(pairGrad₂ a s r x)^2) := by + rw [pairInterMean_swap] + simpa only [mul_comm (1-a^2) (1-b^2),pairGrad₁,pairGrad₂] using + (pair_energy_lower (p:=s) (r:=r) hb ha hu) + +lemma pairInterMean_add (a b u : ℝ) (F G : Bool→Bool→ℝ) : + pairInterMean a b u (fun x y=>F x y+G x y)=pairInterMean a b u F+pairInterMean a b u G := by + unfold pairInterMean + simp_rw [mul_add] + exact pairMean_add a b _ _ + +lemma pairInterMean_nonneg {a b u : ℝ} + (ha : |a| ≤ 1) (hb : |b| ≤ 1) (hu : |u| ≤ 1/4) + {F : Bool→Bool→ℝ} (hF : ∀ x y,0 ≤ F x y) : 0 ≤ pairInterMean a b u F := by + have hh := pairMean_mono ha hb (fun x y=>mul_nonneg (pair_density_nonneg ha hb hu x y) (hF x y)) + have he : pairMean a b (fun _ _=>(0:ℝ))=0 := by simp [pairMean] + rwa [he] at hh + +lemma pair_signed_bound {a b u p s r : ℝ} + (ha : |a| ≤ 1) (hb : |b| ≤ 1) (hu : |u| ≤ 1/1000) : + -u*pairInterMean a b u (fun x y=>pairVariance a u y*pairGrad₁ b p r y* + (pairVariance b u x*pairGrad₂ a s r x))- + 400000*u^2*pairInterMean a b u (fun x y=>|pairVariance a u y*pairGrad₁ b p r y* + (pairVariance b u x*pairGrad₂ a s r x)|)- + 400000*u^4*pairInterMean a b u (fun x y=>pairVariance a u y*(pairGrad₁ b p r y)^2+ + pairVariance b u x*(pairGrad₂ a s r x)^2) ≤ + pairInterMean a b u (fun x y=>pairResidual a u x y*pairGrad₁ b p r y* + (pairResidual b u y x*pairGrad₂ a s r x)) := by + have hu' : |u| ≤ 1/4 := by linarith only [hu] + let q := pairMean a b (fun x y=>|pairGrad₁ b p r y*pairGrad₂ a s r x|) + let z := pairMean a b (fun x y=>pairRationalWeight a b u (spinValue x) (spinValue y)* + (pairGrad₁ b p r y*pairGrad₂ a s r x)) + have hq : |p*s| ≤ q := by + have hh := abs_pairMean_le ha hb (fun x y=>pairGrad₁ b p r y*pairGrad₂ a s r x) + change |pairMean a b (fun x y=>(p+r*(spinValue y-b))*(s+r*(spinValue x-a)))| ≤ q at hh + rwa [pair_gradient_mean] at hh + have hl := pair_signed_cross_lower (r:=r) ha hb hu hq (pair_weighted_error ha hb hu') + have ha2 : a^2 ≤ 1 := by nlinarith only [sq_abs a,abs_nonneg a,ha] + have hb2 : b^2 ≤ 1 := by nlinarith only [sq_abs b,abs_nonneg b,hb] + have hAB : 0 ≤ (1-a^2)*(1-b^2) := mul_nonneg (sub_nonneg.mpr ha2) (sub_nonneg.mpr hb2) + have hl' := mul_le_mul_of_nonneg_left hl hAB + have hc := pair_abs_cost_lower (p:=p) (s:=s) (r:=r) ha hb hu' + have h₁ := pair_energy_lower (p:=p) (r:=r) ha hb hu' + have h₂ := pair_second_energy_lower (s:=s) (r:=r) ha hb hu' + have hc' := mul_le_mul_of_nonneg_left hc (show 0 ≤ 1282*256*u^2 by positivity) + have he' := mul_le_mul_of_nonneg_left (add_le_add h₁ h₂) (show 0 ≤ 128*u^4 by positivity) + have habs : 0 ≤ pairInterMean a b u (fun x y=>|pairVariance a u y*pairGrad₁ b p r y* + (pairVariance b u x*pairGrad₂ a s r x)|) := pairInterMean_nonneg ha hb hu' (fun _ _=>abs_nonneg _) + have hener : 0 ≤ pairInterMean a b u (fun x y=>pairVariance a u y*(pairGrad₁ b p r y)^2+ + pairVariance b u x*(pairGrad₂ a s r x)^2) := pairInterMean_nonneg ha hb hu' + (fun x y=>add_nonneg (mul_nonneg (pair_variance_nonneg ha hu' y) (sq_nonneg _)) + (mul_nonneg (pair_variance_nonneg hb hu' x) (sq_nonneg _))) + have hc'' := mul_nonneg (sq_nonneg u) habs + have he'' := mul_nonneg (show 0 ≤ u^4 by positivity) hener + rw [pairInterMean_add] at he'' ⊢ + rw [pair_cross_exact ha hb hu',pair_weighted_product] + change -u*((1-a^2)*(1-b^2)*z)-_ -_ ≤ _ + change -1282*u^2*q-4*u^4*(p^2+s^2) ≤ pairCrossPolynomial a b u p s r+u*z at hl + change (1-a^2)*(1-b^2)*(-1282*u^2*q-4*u^4*(p^2+s^2)) ≤ + (1-a^2)*(1-b^2)*(pairCrossPolynomial a b u p s r+u*z) at hl' + change 1282*256*u^2*((1-a^2)*(1-b^2)*q/256) ≤ _ at hc' + nlinarith only [hl',hc',he',hc'',he''] +end SKGap + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Terminal/PairGibbsBound.lean b/lean/OAI/Probability/SKGap/Terminal/PairGibbsBound.lean new file mode 100644 index 0000000000000000000000000000000000000000..e3d3fba42054c0023a6d25967e715c02f533529f --- /dev/null +++ b/lean/OAI/Probability/SKGap/Terminal/PairGibbsBound.lean @@ -0,0 +1,161 @@ +import Mathlib +import OAI.Probability.SKGap.Terminal.PairConditioning + +namespace OAI + +section +noncomputable section +namespace SKGap +open Real +open scoped BigOperators +variable {n : ℕ} + +def siteVariance (g : Disorder n) (h : Fin n→ℝ) (i : Fin n) (x : Spin n) : ℝ := + 1-tanh (localField g h i x)^2 + +def weightedGradient (g : Disorder n) (h : Fin n→ℝ) (i : Fin n) (f : Spin n→ℝ) (x : Spin n) : ℝ := + siteVariance g h i x*spinGradient i f x + +lemma pairConditional_signed_bound (g : Disorder n) (h : Fin n→ℝ) (i j : Fin n) (hij : i ≠ j) + (f : Spin n→ℝ) (x : Spin n) (hc : |tanh (coupling g i j)| ≤ 1/1000) : + -tanh (coupling g i j)*pairConditionalMean g h i j + (fun x=>weightedGradient g h i f x*weightedGradient g h j f x) x- + 400000*tanh (coupling g i j)^2*pairConditionalMean g h i j + (fun x=>|weightedGradient g h i f x*weightedGradient g h j f x|) x- + 400000*tanh (coupling g i j)^4*pairConditionalMean g h i j + (fun x=>siteVariance g h i x*spinGradient i f x^2+siteVariance g h j x*spinGradient j f x^2) x ≤ + pairConditionalMean g h i j (fun x=>(f x-conditionalExpectation g h i f x)* + (f x-conditionalExpectation g h j f x)) x := by + simp_rw [pairConditionalMean_boltzmann g h i j hij,weightedGradient,siteVariance, + conditionalDifference_local,pairUpdate_localField₁,pairUpdate_localField₂, + pairUpdate_gradient₁ i j hij,pairUpdate_gradient₂,pairUpdate_left i j hij,pairUpdate_right] + exact pairBoltzmann_signed_bound + (localField g h i x-coupling g i j*spinValue (x j)) + (localField g h j x-coupling g i j*spinValue (x i)) + (coupling g i j) (fun a b=>f (pairUpdate i j x a b)) hc + +lemma expectation_mono (g : Disorder n) (h : Fin n→ℝ) {F G : Spin n→ℝ} + (hFG : ∀ x,F x ≤ G x) : expectation g h F ≤ expectation g h G := by + apply Finset.sum_le_sum + intro x _ + exact mul_le_mul_of_nonneg_left (hFG x) (mass_nonneg g h x) + +lemma gibbs_pair_signed_bound (g : Disorder n) (h : Fin n→ℝ) (i j : Fin n) (hij : i ≠ j) + (f : Spin n→ℝ) (hc : |tanh (coupling g i j)| ≤ 1/1000) : + -tanh (coupling g i j)*expectation g h + (fun x=>weightedGradient g h i f x*weightedGradient g h j f x)- + 400000*tanh (coupling g i j)^2*expectation g h + (fun x=>|weightedGradient g h i f x*weightedGradient g h j f x|)- + 400000*tanh (coupling g i j)^4*(expectation g h + (fun x=>siteVariance g h i x*spinGradient i f x^2)+expectation g h + (fun x=>siteVariance g h j x*spinGradient j f x^2)) ≤ + expectation g h (fun x=>(f x-conditionalExpectation g h i f x)* + (f x-conditionalExpectation g h j f x)) := by + have hh := expectation_mono g h (fun x=>pairConditional_signed_bound g h i j hij f x hc) + simpa only [expectation_sub,expectation_const_mul,expectation_pairConditionalMean g h i j hij, + expectation_add] using hh +end SKGap + +end +end + +section +noncomputable section +namespace SKGap +open Real +open scoped BigOperators +variable {n : ℕ} + +lemma siteVariance_pos (g : Disorder n) (h : Fin n→ℝ) (i : Fin n) (x : Spin n) : + 0 < siteVariance g h i x := by + unfold siteVariance + have ht := abs_tanh_lt_one (localField g h i x) + have hs := (sq_lt_sq₀ (abs_nonneg _) (by norm_num : (0:ℝ) ≤ 1)).mpr ht + simp only [sq_abs,one_pow] at hs + linarith only [hs] +lemma siteVariance_le_one (g : Disorder n) (h : Fin n→ℝ) (i : Fin n) (x : Spin n) : + siteVariance g h i x ≤ 1 := sub_le_self _ (sq_nonneg _) + +lemma dirichlet_weighted (g : Disorder n) (h : Fin n→ℝ) (f : Spin n→ℝ) : + dirichlet g h f=∑ i,expectation g h (fun x=>siteVariance g h i x*spinGradient i f x^2) := by + unfold dirichlet siteVariance + simp_rw [conditionalSiteEnergy_local] + +lemma symmetric_fourth_cost {ι : Type*} [Fintype ι] (U : ι→ι→ℝ) (D : ι→ℝ) {R : ℝ} + (hU : ∀ i j,U i j=U j i) (hD : ∀ i,0 ≤ D i) + (hR : ∀ i,∑ j,U i j^4 ≤ R) : + (∑ i,∑ j,U i j^4*(D i+D j)) ≤ 2*R*(∑ i,D i) := by + simp_rw [mul_add,Finset.sum_add_distrib] + have h₁ : (∑ i,∑ j,U i j^4*D i) ≤ R*∑ i,D i := by + rw [Finset.mul_sum] + apply Finset.sum_le_sum + intro i _ + rw [← Finset.sum_mul] + exact mul_le_mul_of_nonneg_right (hR i) (hD i) + have h₂ : (∑ i,∑ j,U i j^4*D j)=(∑ i,∑ j,U i j^4*D i) := by + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro i _ + apply Finset.sum_congr rfl + intro j _ + rw [hU j i] + rw [h₂] + linarith only [h₁] + +lemma heatBathGenerator_square (g : Disorder n) (h : Fin n→ℝ) (f : Spin n→ℝ) : + expectation g h (fun x=>heatBathGenerator g h f x^2)= + ∑ i,∑ j,expectation g h (fun x=>(f x-conditionalExpectation g h i f x)* + (f x-conditionalExpectation g h j f x)) := by + simp only [heatBathGenerator,sq,Finset.sum_mul,Finset.mul_sum,expectation_sum] + rw [Finset.sum_comm] + +theorem gibbs_signed_curvature (g : Disorder n) (h : Fin n→ℝ) (f : Spin n→ℝ) {R : ℝ} + (hc : ∀ i j,|tanh (coupling g i j)| ≤ 1/1000) + (hR : ∀ i,∑ j,tanh (coupling g i j)^4 ≤ R) : + (1-800000*R)*dirichlet g h f- + expectation g h (fun x=>∑ i,∑ j,tanh (coupling g i j)* + weightedGradient g h i f x*weightedGradient g h j f x)- + 400000*expectation g h (fun x=>∑ i,∑ j,tanh (coupling g i j)^2* + |weightedGradient g h i f x*weightedGradient g h j f x|) ≤ + expectation g h (fun x=>heatBathGenerator g h f x^2) := by + let U := fun i j=>tanh (coupling g i j) + let D := fun i=>expectation g h (fun x=>siteVariance g h i x*spinGradient i f x^2) + let A := fun i j=>expectation g h (fun x=>weightedGradient g h i f x*weightedGradient g h j f x) + let B := fun i j=>expectation g h (fun x=>|weightedGradient g h i f x*weightedGradient g h j f x|) + let X := fun i j=>expectation g h (fun x=>(f x-conditionalExpectation g h i f x)* + (f x-conditionalExpectation g h j f x)) + have hpair (i j : Fin n) : (if i=j then D i else 0)-U i j*A i j- + 400000*U i j^2*B i j-400000*U i j^4*(D i+D j) ≤ X i j := by + by_cases hij : i=j + · subst j + have hX : X i i=D i := by + dsimp [X,D,siteVariance] + simp only [← sq,conditionalSiteEnergy_local] + simp only [U,coupling_diag,tanh_zero,zero_mul,mul_zero,zero_pow (by omega : (2:ℕ) ≠ 0), + zero_pow (by omega : (4:ℕ) ≠ 0),sub_zero,ite_true,hX,le_refl] + · simpa only [ite_eq_right hij,zero_sub,neg_mul,U,A,B,D,X] using gibbs_pair_signed_bound g h i j hij f (hc i j) + have hsum := Finset.sum_le_sum (fun i (_ : i ∈ Finset.univ)=> + Finset.sum_le_sum (fun j (_ : j ∈ Finset.univ)=>hpair i j)) + have hcost := symmetric_fourth_cost U D (fun i j=>congrArg tanh (coupling_symm g i j)) + (fun i=>expectation_nonneg g h (fun x=>mul_nonneg (siteVariance_pos g h i x).le (sq_nonneg _))) hR + have hD : (∑ i,D i)=dirichlet g h f := (dirichlet_weighted g h f).symm + have hX : (∑ i,∑ j,X i j)=expectation g h (fun x=>heatBathGenerator g h f x^2) := + (heatBathGenerator_square g h f).symm + have hA : expectation g h (fun x=>∑ i,∑ j,tanh (coupling g i j)* + weightedGradient g h i f x*weightedGradient g h j f x)=∑ i,∑ j,U i j*A i j := by + simp only [expectation_sum,mul_assoc,expectation_const_mul,U,A] + have hB : expectation g h (fun x=>∑ i,∑ j,tanh (coupling g i j)^2* + |weightedGradient g h i f x*weightedGradient g h j f x|)=∑ i,∑ j,U i j^2*B i j := by + simp only [expectation_sum,expectation_const_mul,U,B] + simp only [Finset.sum_sub_distrib,Finset.sum_ite_eq,Finset.mem_univ,ite_true] at hsum + simp only [← Finset.mul_sum,mul_assoc] at hsum + rw [hD,hX] at hsum + rw [hD] at hcost + rw [hA,hB] + nlinarith only [hsum,hcost] +end SKGap + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Terminal/PairInteraction.lean b/lean/OAI/Probability/SKGap/Terminal/PairInteraction.lean new file mode 100644 index 0000000000000000000000000000000000000000..f94dd59ae690ef7054d502a1279bbd7d7945a9f7 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Terminal/PairInteraction.lean @@ -0,0 +1,94 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.Magnetization +import OAI.Probability.SKGap.Localization.Invert + +namespace OAI + +section +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +namespace SKGapCutoff + +lemma gap_le_eigenrate {n : ℕ} (J : Interaction n) + (hJ : ∀ i j, J i j = J j i) (hdiag : ∀ i, J i i = 0) + {γ rate : ℝ} (hγ : HasGap J γ) (f : Observables n) + (hc : gibbsExpectation J f = 0) + (he : ∀ x, generator J f x = -rate * f x) + (x : Spin n) (hx : f x ≠ 0) : γ ≤ rate := by + have hv : 0 < gibbsVariance J f := by + rw [gibbsVariance, hc] + simp only [sub_zero, gibbsExpectation] + exact Finset.sum_pos' (fun y _ => mul_nonneg (le_of_lt (gibbs_pos J y)) (sq_nonneg _)) + ⟨x, Finset.mem_univ _, mul_pos (gibbs_pos J x) (sq_pos_of_ne_zero hx)⟩ + have hd : dirichlet J f f = rate * gibbsVariance J f := by + rw [← gibbs_dirichlet J hJ hdiag, gibbsVariance, hc] + simp only [he, sub_zero, neg_mul, neg_neg] + have hm (y : Spin n) : f y * (rate * f y) = rate * (f y) ^ 2 := by ring + simp_rw [hm] + exact gibbsExpectation_mul_const J rate (fun y => f y ^ 2) + have h := hγ f + rw [hd] at h + exact le_of_mul_le_mul_right h hv + +def pairInteraction (a : ℝ) : Interaction 2 := fun i j => if i = j then 0 else a + +lemma pairInteraction_symm (a : ℝ) : ∀ i j, pairInteraction a i j = pairInteraction a j i := by + intro i j + simp only [pairInteraction, eq_comm] + +lemma pairInteraction_diag (a : ℝ) : ∀ i, pairInteraction a i i = 0 := by + intro i + simp [pairInteraction] + +lemma tanh_mul_spin {n : ℕ} (a : ℝ) (x : Spin n) (i : Fin n) : + Real.tanh (a * spin x i) = Real.tanh a * spin x i := by + cases h : x i <;> simp [spin, h, Real.tanh_neg] + +lemma pair_field_zero (a : ℝ) (x : Spin 2) : field (pairInteraction a) x 0 = a * spin x 1 := by + simp [field, Fin.sum_univ_two, pairInteraction] + +lemma pair_field_one (a : ℝ) (x : Spin 2) : field (pairInteraction a) x 1 = a * spin x 0 := by + simp [field, Fin.sum_univ_two, pairInteraction] + +lemma pair_magnetization_eigen (a : ℝ) (x : Spin 2) : + generator (pairInteraction a) magnetization x = -(1 - Real.tanh a) * magnetization x := by + simp only [generator, halfDiff_magnetization, mul_one, Fin.sum_univ_two, + mean, pair_field_zero, pair_field_one, tanh_mul_spin, magnetization] + ring + +lemma magnetization_centered {n : ℕ} (J : Interaction n) : + gibbsExpectation J magnetization = 0 := by + change gibbsExpectation J (fun x => ∑ i, spin x i) = 0 + rw [gibbsExpectation_sum] + simp only [gibbs_spin_centered, Finset.sum_const_zero] + +lemma pair_gap_upper (a : ℝ) {γ : ℝ} (hγ : HasGap (pairInteraction a) γ) : + γ ≤ 1 - Real.tanh a := by + apply gap_le_eigenrate (pairInteraction a) (pairInteraction_symm a) (pairInteraction_diag a) + hγ magnetization (magnetization_centered _) (pair_magnetization_eigen a) (plusSpin 2) + norm_num + +theorem no_all_interaction_gap : ¬ ∃ γ : ℝ, 0 < γ ∧ + ∀ J : Interaction 2, (∀ i j, J i j = J j i) → (∀ i, J i i = 0) → HasGap J γ := by + rintro ⟨γ, hγ, h⟩ + let δ := min γ 1 / 2 + have hδ : 0 < δ := half_pos (lt_min hγ (by norm_num)) + have hδγ : δ < γ := by + dsimp only [δ] + have hm := min_le_left γ 1 + linarith + have hδ1 : δ ≤ 1 / 2 := div_le_div_of_nonneg_right (min_le_right γ 1) (by norm_num) + have hr : 1 - δ ∈ Set.Ioo (-1 : ℝ) 1 := by constructor <;> linarith + have hg := pair_gap_upper (Real.artanh (1 - δ)) + (h _ (pairInteraction_symm _) (pairInteraction_diag _)) + rw [Real.tanh_artanh hr] at hg + linarith + +end SKGapCutoff + +open scoped BigOperators + +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Terminal/PairRationalBounds.lean b/lean/OAI/Probability/SKGap/Terminal/PairRationalBounds.lean new file mode 100644 index 0000000000000000000000000000000000000000..7788feefbe51f8fc83fed1d92a0e8597970478db --- /dev/null +++ b/lean/OAI/Probability/SKGap/Terminal/PairRationalBounds.lean @@ -0,0 +1,251 @@ +import Mathlib +import OAI.Probability.SKGap.Model + +namespace OAI + +section +noncomputable section +namespace SKGap +open Real +open scoped BigOperators + +lemma list_prod_perturb (l : List ℝ) {t : ℝ} (ht : 0 ≤ t) (ht1 : t ≤ 1) + (h : ∀ x∈l,|x-1| ≤ t) : + |l.prod| ≤ 2^l.length ∧ |l.prod-1| ≤ (2^l.length-1)*t := by + induction l with + | nil => simp + | cons x l ih => + have hx := h x (by simp) + have hl := ih (fun y hy=>h y (by simp [hy])) + have hx2 : |x| ≤ 2 := by + have hh := abs_add_le (x-1) 1 + simp only [sub_add_cancel,abs_one] at hh + linarith + have he : x*l.prod-1=(x-1)*l.prod+(l.prod-1) := by ring + simp only [List.prod_cons,List.length_cons,pow_succ] + constructor + · rw [abs_mul] + exact (mul_le_mul hx2 hl.1 (abs_nonneg _) (by norm_num)).trans_eq (by ring) + · rw [he] + calc + _ ≤ |x-1| * |l.prod|+|l.prod-1| := by simpa only [abs_mul] using abs_add_le ((x-1)*l.prod) (l.prod-1) + _ ≤ t*2^l.length+(2^l.length-1)*t := add_le_add + (mul_le_mul hx hl.1 (abs_nonneg _) ht) hl.2 + _ = _ := by ring + +lemma list_prod_between (l : List ℝ) (h : ∀ x∈l,(1/2:ℝ) ≤ x ∧ x ≤ 2) : + (1/2:ℝ)^l.length ≤ l.prod ∧ l.prod ≤ (2:ℝ)^l.length := by + induction l with + | nil => simp + | cons x l ih => + have hx := h x (by simp) + have hl := ih (fun y hy=>h y (by simp [hy])) + have hl0 : 0 ≤ l.prod := (by positivity : (0:ℝ) ≤ (1/2:ℝ)^l.length).trans hl.1 + simp only [List.prod_cons,List.length_cons,pow_succ] + constructor + · exact (by ring : (1/2:ℝ)^l.length*(1/2)=(1/2)*(1/2)^l.length).le.trans + (mul_le_mul hx.1 hl.1 (by positivity) (by linarith)) + · exact (mul_le_mul hx.2 hl.2 hl0 (by norm_num)).trans_eq (by ring) + +lemma pair_factor_control {u z : ℝ} (hu : |u| ≤ 1/4) (hz : |z| ≤ 1) : + (1/2:ℝ) ≤ 1+u*z ∧ 1+u*z ≤ 2 ∧ |(1+u*z)-1| ≤ |u| := by + have hh : |u*z| ≤ |u| := by rw [abs_mul];exact (mul_le_mul_of_nonneg_left hz (abs_nonneg u)).trans_eq (mul_one _) + have hb := abs_le.mp hh + constructor + · linarith + constructor + · linarith + simpa only [add_sub_cancel_left] using hh + +lemma pair_square_factor_control {u : ℝ} (hu : |u| ≤ 1/4) : + (1/2:ℝ) ≤ 1-u^2 ∧ 1-u^2 ≤ 2 ∧ |(1-u^2)-1| ≤ |u| := by + have hs : u^2 ≤ |u| := by nlinarith [sq_abs u,abs_nonneg u] + have h0 := sq_nonneg u + constructor + · linarith + constructor + · linarith + rw [sub_sub_cancel_left,abs_neg,abs_of_nonneg h0] + exact hs + +def pairRationalWeight (a b u x y : ℝ) : ℝ := + (1-u^2)^2*(1+u*x*y)/((1+u*a*b)*(1+u*a*y)^2*(1+u*b*x)^2) + +lemma pairRationalWeight_bounds {a b u x y : ℝ} + (ha : |a| ≤ 1) (hb : |b| ≤ 1) (hu : |u| ≤ 1/4) + (hx : |x| ≤ 1) (hy : |y| ≤ 1) : + 1/256 ≤ pairRationalWeight a b u x y ∧ + pairRationalWeight a b u x y ≤ 256 ∧ + |pairRationalWeight a b u x y-1| ≤ 1216*|u| := by + have hab : |a*b| ≤ 1 := by simpa only [one_mul,abs_mul] using mul_le_mul ha hb (abs_nonneg b) (by norm_num : (0:ℝ) ≤ 1) + have hay : |a*y| ≤ 1 := by simpa only [one_mul,abs_mul] using mul_le_mul ha hy (abs_nonneg y) (by norm_num : (0:ℝ) ≤ 1) + have hbx : |b*x| ≤ 1 := by simpa only [one_mul,abs_mul] using mul_le_mul hb hx (abs_nonneg x) (by norm_num : (0:ℝ) ≤ 1) + have hxy : |x*y| ≤ 1 := by simpa only [one_mul,abs_mul] using mul_le_mul hx hy (abs_nonneg y) (by norm_num : (0:ℝ) ≤ 1) + have h₀ := pair_square_factor_control hu + have h₁ := pair_factor_control hu hab + have h₂ := pair_factor_control hu hay + have h₃ := pair_factor_control hu hbx + have h₄ := pair_factor_control hu hxy + let ln : List ℝ := [1-u^2,1-u^2,1+u*(x*y)] + let ld : List ℝ := [1+u*(a*b),1+u*(a*y),1+u*(a*y),1+u*(b*x),1+u*(b*x)] + have hn : ∀ z∈ln, (1/2:ℝ) ≤ z ∧ z ≤ 2 := by + intro z hz + simp only [ln,List.mem_cons,List.not_mem_nil,or_false] at hz + rcases hz with rfl|rfl|rfl <;> exact ⟨by grind,by grind⟩ + have hd : ∀ z∈ld, (1/2:ℝ) ≤ z ∧ z ≤ 2 := by + intro z hz + simp only [ld,List.mem_cons,List.not_mem_nil,or_false] at hz + rcases hz with rfl|rfl|rfl|rfl|rfl <;> exact ⟨by grind,by grind⟩ + have hn' : ∀ z∈ln, |z-1| ≤ |u| := by + intro z hz + simp only [ln,List.mem_cons,List.not_mem_nil,or_false] at hz + rcases hz with rfl|rfl|rfl <;> grind + have hd' : ∀ z∈ld, |z-1| ≤ |u| := by + intro z hz + simp only [ld,List.mem_cons,List.not_mem_nil,or_false] at hz + rcases hz with rfl|rfl|rfl|rfl|rfl <;> grind + have hnb := list_prod_between ln hn + have hdb := list_prod_between ld hd + have hnp := (list_prod_perturb ln (abs_nonneg u) (by linarith) hn').2 + have hdp := (list_prod_perturb ld (abs_nonneg u) (by linarith) hd').2 + have hnl : ln.length=3 := rfl + have hdl : ld.length=5 := rfl + rw [hnl] at hnb hnp + rw [hdl] at hdb hdp + norm_num only at hnb hdb hnp hdp + have hd0 : 0 < ld.prod := by linarith [hdb.1] + have he : pairRationalWeight a b u x y=ln.prod/ld.prod := by + unfold pairRationalWeight ln ld + simp only [List.prod_cons,List.prod_nil,mul_one] + congr 1 <;> ring + rw [he] + constructor + · apply (le_div_iff₀ hd0).mpr + nlinarith [hnb.1,hdb.2] + constructor + · apply (div_le_iff₀ hd0).mpr + nlinarith [hnb.2,hdb.1] + rw [div_sub_one (ne_of_gt hd0),abs_div,abs_of_pos hd0] + apply (div_le_iff₀ hd0).mpr + have hh : |ln.prod-ld.prod| ≤ 38*|u| := by + have hh := abs_sub_le (ln.prod-1) 0 (ld.prod-1) + simp only [sub_zero,zero_sub,abs_neg] at hh + simpa only [sub_sub_sub_cancel_right] using (hh.trans (add_le_add hnp hdp)).trans_eq (by ring) + have hm := mul_le_mul_of_nonneg_left hdb.1 (show 0 ≤ 1216*|u| by positivity) + nlinarith only [hh,hm] +end SKGap + +end +end + +section +noncomputable section +namespace SKGap +open Real + +def pairK (a b u : ℝ) : ℝ := + (1-u^2)/((1+u*a*b)*(1-u^2*a^2)*(1-u^2*b^2)) +def pairR (a b u : ℝ) : ℝ := + 1+u*a*b+u^2*(a^2*b^2-a^2-b^2)-u^3*a*b + +def pairCrossPolynomial (a b u p s r : ℝ) : ℝ := + pairK a b u*((-u+u^2*a*b)*p*s+u^2*b*(1-a^2)*r*p+ + u^2*a*(1-b^2)*r*s+pairR a b u*r^2) + +lemma abs_mul_le_one_pair {x y : ℝ} (hx : |x| ≤ 1) (hy : |y| ≤ 1) : |x*y| ≤ 1 := by + rw [abs_mul] + exact (mul_le_mul hx hy (abs_nonneg _) (by norm_num)).trans_eq (by ring) + +lemma pairK_bounds {a b u : ℝ} (ha : |a| ≤ 1) (hb : |b| ≤ 1) (hu : |u| ≤ 1/1000) : + |pairK a b u-1| ≤ 64*|u| ∧ 9/10 ≤ pairK a b u ∧ pairK a b u ≤ 2 := by + have hu4 : |u| ≤ 1/4 := by linarith only [hu] + have hua : |u| ≤ 1 := by linarith only [hu] + have ha2 : |a^2| ≤ 1 := by simpa only [pow_two] using abs_mul_le_one_pair ha ha + have hb2 : |b^2| ≤ 1 := by simpa only [pow_two] using abs_mul_le_one_pair hb hb + have h₁ := pair_factor_control hu4 (abs_mul_le_one_pair ha hb) + have h₂ := pair_factor_control hu4 (show |-u*a^2| ≤ 1 by simpa only [abs_neg,abs_mul] using abs_mul_le_one_pair hua ha2) + have h₃ := pair_factor_control hu4 (show |-u*b^2| ≤ 1 by simpa only [abs_neg,abs_mul] using abs_mul_le_one_pair hua hb2) + have he₂ : 1+u*(-u*a^2)=1-u^2*a^2 := by ring + have he₃ : 1+u*(-u*b^2)=1-u^2*b^2 := by ring + rw [he₂] at h₂ + rw [he₃] at h₃ + let l : List ℝ := [1+u*(a*b),1-u^2*a^2,1-u^2*b^2] + have hl : ∀ z∈l,(1/2:ℝ) ≤ z ∧ z ≤ 2 := by + intro z hz + simp only [l,List.mem_cons,List.not_mem_nil,or_false] at hz + rcases hz with rfl|rfl|rfl <;> grind + have hl' : ∀ z∈l,|z-1| ≤ |u| := by + intro z hz + simp only [l,List.mem_cons,List.not_mem_nil,or_false] at hz + rcases hz with rfl|rfl|rfl <;> grind + have hlen : l.length=3 := rfl + have hbounds := list_prod_between l hl + have hperturb := (list_prod_perturb l (abs_nonneg u) hua hl').2 + rw [hlen] at hbounds hperturb + norm_num only at hbounds hperturb + have hd : 0 < l.prod := by linarith only [hbounds.1] + have he : pairK a b u=(1-u^2)/l.prod := by + unfold pairK l + simp only [List.prod_cons,List.prod_nil,mul_one] + congr 1; ring + have hs : u^2 ≤ |u| := by nlinarith only [sq_abs u,abs_nonneg u,hu] + have hp : |pairK a b u-1| ≤ 64*|u| := by + rw [he,div_sub_one hd.ne',abs_div,abs_of_pos hd] + apply (div_le_iff₀ hd).mpr + have hh : |1-u^2-l.prod| ≤ 8*|u| := by + have hh := abs_add_le (-u^2) (1-l.prod) + rw [abs_neg,abs_of_nonneg (sq_nonneg u),abs_sub_comm] at hh + have he' : 1-u^2-l.prod= -u^2+(1-l.prod) := by ring + rw [he'] + linarith only [hh,hs,hperturb] + have hm := mul_le_mul_of_nonneg_left hbounds.1 (show 0 ≤ 64*|u| by positivity) + nlinarith only [hh,hm] + refine ⟨hp,?_,?_⟩ <;> have hh := abs_le.mp hp <;> linarith only [hu,hh.1,hh.2] + +lemma pairR_bounds {a b u : ℝ} (ha : |a| ≤ 1) (hb : |b| ≤ 1) (hu : |u| ≤ 1/1000) : + |pairR a b u-1| ≤ 5*|u| ∧ 9/10 ≤ pairR a b u := by + have hua : |u| ≤ 1 := by linarith only [hu] + have ha2 : |a^2| ≤ 1 := by simpa only [pow_two] using abs_mul_le_one_pair ha ha + have hb2 : |b^2| ≤ 1 := by simpa only [pow_two] using abs_mul_le_one_pair hb hb + have hab := abs_mul_le_one_pair ha hb + have hab2 := abs_mul_le_one_pair ha2 hb2 + have hz : |a^2*b^2-a^2-b^2| ≤ 3 := by + have h₁ := abs_sub_le (a^2*b^2) 0 (a^2) + have h₂ := abs_sub_le (a^2*b^2-a^2) 0 (b^2) + simp only [sub_zero,zero_sub,abs_neg] at h₁ h₂ + linarith only [h₁,h₂,ha2,hb2,hab2] + have hs : u^2 ≤ |u| := by nlinarith only [sq_abs u,abs_nonneg u,hu] + have hu3 : |u^3| ≤ |u| := by + rw [pow_succ,abs_mul,abs_of_nonneg (sq_nonneg u)] + have h' := mul_le_mul_of_nonneg_right hs (abs_nonneg u) + nlinarith only [h',sq_abs u,hs] + have h₁ : |u*a*b| ≤ |u| := by + rw [mul_assoc,abs_mul] + exact (mul_le_mul_of_nonneg_left hab (abs_nonneg u)).trans_eq (mul_one _) + have h₂ : |u^2*(a^2*b^2-a^2-b^2)| ≤ 3*|u| := by + rw [abs_mul,abs_of_nonneg (sq_nonneg u)] + have hh := mul_le_mul_of_nonneg_left hz (sq_nonneg u) + nlinarith only [hh,hs] + have h₃ : |u^3*a*b| ≤ |u| := by + rw [mul_assoc,abs_mul] + exact (mul_le_mul hu3 hab (abs_nonneg _) (abs_nonneg u)).trans_eq (mul_one _) + have hp : |pairR a b u-1| ≤ 5*|u| := by + have hh := abs_add_le (u*a*b) (u^2*(a^2*b^2-a^2-b^2)) + have hh' := abs_sub_le (u*a*b+u^2*(a^2*b^2-a^2-b^2)) 0 (u^3*a*b) + simp only [sub_zero,zero_sub,abs_neg] at hh' + have he : pairR a b u-1=u*a*b+u^2*(a^2*b^2-a^2-b^2)-u^3*a*b := by unfold pairR;ring + rw [he] + linarith only [hh,hh',h₁,h₂,h₃] + exact ⟨hp,by have hh := (abs_le.mp hp).1;linarith only [hh,hu]⟩ + +lemma pairKR_lower {a b u : ℝ} (ha : |a| ≤ 1) (hb : |b| ≤ 1) (hu : |u| ≤ 1/1000) : + 1/2 ≤ pairK a b u*pairR a b u := by + have h₁ := (pairK_bounds ha hb hu).2.1 + have h₂ := (pairR_bounds ha hb hu).2 + nlinarith [mul_nonneg (sub_nonneg.mpr h₁) (sub_nonneg.mpr h₂)] +end SKGap + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Terminal/PairSpinFrequency.lean b/lean/OAI/Probability/SKGap/Terminal/PairSpinFrequency.lean new file mode 100644 index 0000000000000000000000000000000000000000..bdfce0faab4a19e1a0e30167cfc184ccf2420f42 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Terminal/PairSpinFrequency.lean @@ -0,0 +1,210 @@ +import Mathlib +import OAI.Probability.SKGap.Matrix.DoublePlantLogNorm + +namespace OAI + +section +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open scoped BigOperators +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open scoped BigOperators +open scoped BigOperators NNReal ENNReal +open MeasureTheory Metric Set +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators NNReal ENNReal Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Set +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators ENNReal NNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Matrix +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators ENNReal NNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal +open scoped BigOperators +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise NNReal ENNReal +open scoped BigOperators +open Filter Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal Topology +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +namespace SKGapCutoff + +lemma replicaOverlap_comm {n : ℕ} (x y : Spin n) : replicaOverlap x y = replicaOverlap y x := by + simp only [replicaOverlap, mul_comm] + +lemma doublePlantWeight_comm {n : ℕ} (β : ℝ) (x y : Spin n) : + doublePlantWeight β x y = doublePlantWeight β y x := by + simp only [doublePlantWeight, doublePlantLogNorm, replicaOverlap_comm x y] + +lemma doublePlantWeight_marginal (β : ℝ) {n : ℕ} (hn : 0 < n) (x : Spin n) : + ∑ y : Spin n, doublePlantWeight β x y = 1/(2:ℝ)^n := by + have hs := sum_replicaOverlap x (fun z => Real.exp (β^2*z^2/(2*n))) + let S := ∑ y : Spin n, Real.exp (β^2*magnetization y^2/(2*n)) + have hS : 0 < S := Finset.sum_pos (fun _ _ => Real.exp_pos _) Finset.univ_nonempty + simp_rw [doublePlantWeight_eq_overlap_tilt β hn] + rw [← Finset.sum_div, hs] + simp_rw [sum_replicaOverlap _ (fun z => Real.exp (β^2*z^2/(2*n)))] + simp only [Finset.sum_const, Finset.card_univ, nsmul_eq_mul] + change S/((Fintype.card (Spin n):ℝ)*S) = _ + rw [card_spin, Nat.cast_pow, Nat.cast_ofNat] + field_simp + +lemma doublePlantWeight_right_marginal (β : ℝ) {n : ℕ} (hn : 0 < n) (y : Spin n) : + ∑ x : Spin n, doublePlantWeight β x y = 1/(2:ℝ)^n := by + simp_rw [doublePlantWeight_comm β _ y] + exact doublePlantWeight_marginal β hn y + +lemma doublePlantWeight_magnetization_tail (β q ε : ℝ) (hq0 : 0 < q) (hq1 : q < 1) + (hε : 0 < ε) {n : ℕ} (hn : 0 < n) : + (∑ x : Spin n, ∑ y : Spin n, if ε*n < |magnetization x| then + doublePlantWeight β x y else 0) ≤ + Real.exp (-(q*ε^2*n/2))*(Real.sqrt (1-q))⁻¹ := by + have he (x : Spin n) : (∑ y : Spin n, if ε*n < |magnetization x| then + doublePlantWeight β x y else 0) = + (if ε*n < |magnetization x| then (1:ℝ) else 0)/(2:ℝ)^n := by + split_ifs <;> simp [doublePlantWeight_marginal β hn] + simp_rw [he] + rw [← Finset.sum_div] + simpa only [zero_pow (by norm_num : (2:ℕ) ≠ 0), zero_mul, zero_div, + Real.exp_zero, sub_zero] using sign_square_tail_le 0 q ε (by simpa using hq0) hq1 hε hn + +lemma doublePlantWeight_right_magnetization_tail (β q ε : ℝ) (hq0 : 0 < q) (hq1 : q < 1) + (hε : 0 < ε) {n : ℕ} (hn : 0 < n) : + (∑ x : Spin n, ∑ y : Spin n, if ε*n < |magnetization y| then + doublePlantWeight β x y else 0) ≤ + Real.exp (-(q*ε^2*n/2))*(Real.sqrt (1-q))⁻¹ := by + rw [Finset.sum_comm] + simp_rw [doublePlantWeight_comm β] + exact doublePlantWeight_magnetization_tail β q ε hq0 hq1 hε hn + +noncomputable def pairSpinFrequency {n : ℕ} (x y : Spin n) (a b : Bool) : ℝ := + (∑ i : Fin n, if x i=a ∧ y i=b then (1:ℝ) else 0)/(n:ℝ) + +lemma pairSpinFrequency_expansion {n : ℕ} (hn : 0 < n) (x y : Spin n) (a b : Bool) : + pairSpinFrequency x y a b - 1/4 = + ((if a then 1 else -1)*magnetization x + + (if b then 1 else -1)*magnetization y + + (if a then 1 else -1)*(if b then 1 else -1)*replicaOverlap x y)/(4*n) := by + have hh (i : Fin n) : (if x i=a ∧ y i=b then (1:ℝ) else 0) = + (1+(if a then 1 else -1)*spin x i+(if b then 1 else -1)*spin y i+ + (if a then 1 else -1)*(if b then 1 else -1)*spin x i*spin y i)/4 := by + cases a <;> cases b <;> cases hx : x i <;> cases hy : y i <;> norm_num [spin, hx, hy] + have hs : (∑ i : Fin n, if x i=a ∧ y i=b then (1:ℝ) else 0) = + ((n:ℝ)+(if a then 1 else -1)*magnetization x + + (if b then 1 else -1)*magnetization y + + (if a then 1 else -1)*(if b then 1 else -1)*replicaOverlap x y)/4 := by + simp_rw [hh] + rw [← Finset.sum_div] + congr 1 + simp only [Finset.sum_add_distrib, Finset.sum_const, Finset.card_univ, + Fintype.card_fin, nsmul_eq_mul, mul_one, ← Finset.mul_sum, mul_assoc, + magnetization, replicaOverlap] + rw [pairSpinFrequency, hs] + have hn0 : (n:ℝ) ≠ 0 := Nat.cast_ne_zero.mpr (Nat.ne_of_gt hn) + field_simp + ring + +lemma pairSpinFrequency_deviation {n : ℕ} (hn : 0 < n) (x y : Spin n) (a b : Bool) : + |pairSpinFrequency x y a b-1/4| ≤ + (|magnetization x|+|magnetization y|+|replicaOverlap x y|)/(4*n) := by + rw [pairSpinFrequency_expansion hn, abs_div, abs_of_pos (by positivity : (0:ℝ)<4*n)] + apply div_le_div_of_nonneg_right _ (by positivity) + have hh := (abs_add_le + ((if a then 1 else -1)*magnetization x+(if b then 1 else -1)*magnetization y) + ((if a then 1 else -1)*(if b then 1 else -1)*replicaOverlap x y)).trans + (add_le_add (abs_add_le _ _) le_rfl) + cases a <;> cases b <;> simpa only [Bool.false_eq_true, ↓reduceIte, mul_one, one_mul, neg_mul, + neg_neg, abs_neg] using hh + +theorem doublePlantWeight_pair_frequency_tail (β q ε : ℝ) + (hβq : β^2 < q) (hq1 : q < 1) (hε : 0 < ε) {n : ℕ} (hn : 0 < n) (a b : Bool) : + (∑ x : Spin n, ∑ y : Spin n, if ε < |pairSpinFrequency x y a b-1/4| then + doublePlantWeight β x y else 0) ≤ + 3*Real.exp (-((q-β^2)*ε^2*n/2))*(Real.sqrt (1-q))⁻¹ := by + let c := Real.exp (-((q-β^2)*ε^2*n/2))*(Real.sqrt (1-q))⁻¹ + have hq0 : 0 < q := (sq_nonneg β).trans_lt hβq + have hpoint (x y : Spin n) : + (if ε < |pairSpinFrequency x y a b-1/4| then doublePlantWeight β x y else 0) ≤ + (if ε*n < |magnetization x| then doublePlantWeight β x y else 0) + + (if ε*n < |magnetization y| then doublePlantWeight β x y else 0) + + (if ε*n < |replicaOverlap x y| then doublePlantWeight β x y else 0) := by + have hp := (doublePlantWeight_pos β hn x y).le + have hd := pairSpinFrequency_deviation hn x y a b + have hN : (0:ℝ)<4*n := by positivity + have he : ε < |pairSpinFrequency x y a b-1/4| → + ε*n < |magnetization x| ∨ ε*n < |magnetization y| ∨ ε*n < |replicaOverlap x y| := by + intro hh + by_contra h + push Not at h + have hx := (le_div_iff₀ hN).mp hd + nlinarith [h.1,h.2.1,h.2.2] + split_ifs with h h1 h2 h3 <;> simp_all <;> linarith + have hb : Real.exp (-(q*ε^2*n/2))*(Real.sqrt (1-q))⁻¹ ≤ c := by + apply mul_le_mul_of_nonneg_right _ (by positivity) + apply Real.exp_le_exp.mpr + nlinarith [mul_nonneg (mul_nonneg (sq_nonneg β) (sq_nonneg ε)) (Nat.cast_nonneg (α := ℝ) n)] + have hx := (doublePlantWeight_magnetization_tail β q ε hq0 hq1 hε hn).trans hb + have hy := (doublePlantWeight_right_magnetization_tail β q ε hq0 hq1 hε hn).trans hb + have hr := doublePlantWeight_overlap_tail β q ε hβq hq1 hε hn + have hs := Finset.sum_le_sum (s := Finset.univ) (fun x _ => + Finset.sum_le_sum (s := Finset.univ) (fun y _ => hpoint x y)) + simp only [Finset.sum_add_distrib] at hs + calc + _ ≤ _ := hs + _ ≤ c+c+c := add_le_add (add_le_add hx hy) hr + _ = _ := by dsimp [c]; ring + +end SKGapCutoff + +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators + +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Terminal/PairingPairingAddError.lean b/lean/OAI/Probability/SKGap/Terminal/PairingPairingAddError.lean new file mode 100644 index 0000000000000000000000000000000000000000..acec603a69d1beb20c56540980a04184aec37619 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Terminal/PairingPairingAddError.lean @@ -0,0 +1,262 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.SumPoissonMass +import OAI.Probability.SKGap.Gaussian.GaussianPDFMoment +import OAI.Probability.SKGap.Localization.IntegrableMulBounded + +namespace OAI + +section +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open scoped BigOperators +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open scoped BigOperators +open scoped BigOperators NNReal ENNReal +open MeasureTheory Metric Set +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators NNReal ENNReal Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Set +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators ENNReal NNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Matrix +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators ENNReal NNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal +open scoped BigOperators +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise NNReal ENNReal +open scoped BigOperators +open Filter Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal Topology +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Set Matrix +open scoped BigOperators NNReal ENNReal Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open Filter MeasureTheory ProbabilityTheory +open scoped Topology NNReal ENNReal +open Filter MeasureTheory ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter +open scoped Topology NNReal ENNReal +open MeasureTheory Filter ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter +open scoped Topology +open MeasureTheory Filter ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter ProbabilityTheory +open scoped Topology NNReal ENNReal +namespace SKGapCutoff.Clock + +lemma pairing_le_pairing_add_error {f g u : ℝ → ℝ} {B : ℝ} + (hf : Integrable f) (hg : Integrable g) (hu : AEStronglyMeasurable u) + (hb : ∀ x, |u x| ≤ B) : + |∫ x : ℝ, f x*u x| ≤ |∫ x : ℝ, g x*u x|+B*(∫ x : ℝ, |f x-g x|) := by + have hh := pairing_sub_abs_le hf hg hu hb + have htri := norm_le_norm_sub_add (∫ x : ℝ, f x*u x) (∫ x : ℝ, g x*u x) + simp only [Real.norm_eq_abs] at htri + linarith + +lemma pairing_finite_error_bound {ρ : ℝ → ℝ} {φ : ℝ → ℝ → ℝ} + {u : ℝ → ℝ} {B : ℝ} (hρ : Integrable ρ) (hφ : ∀ y, Integrable (φ y)) + (hu : AEStronglyMeasurable u) (hb : ∀ x, |u x| ≤ B) + (s : Finset ℝ) (c : ℝ → ℝ) : + |∫ x : ℝ, ρ x*u x| ≤ B*(∫ x : ℝ, |ρ x-∑ y ∈ s, c y*φ y x|)+ + ∑ y ∈ s, |c y| * |∫ x : ℝ, φ y x*u x| := by + let F : ℝ → ℝ := fun x => ∑ y ∈ s, c y*φ y x + have hF : Integrable F := integrable_finsetSum _ (fun y _ => (hφ y).const_mul (c y)) + have hh := pairing_le_pairing_add_error hρ hF hu hb + have he : (∫ x : ℝ, F x*u x) = ∑ y ∈ s, c y*(∫ x : ℝ, φ y x*u x) := by + unfold F + simp_rw [Finset.sum_mul,mul_assoc] + rw [integral_finsetSum s (fun y _ => (integrable_mul_bounded (hφ y) hu hb).const_mul (c y))] + simp only [integral_const_mul] + rw [he] at hh + have hs := Finset.abs_sum_le_sum_abs (fun y => c y*(∫ x : ℝ, φ y x*u x)) s + simp only [abs_mul] at hs + linarith + +theorem clock_finite_error_bound {q B : ℝ} (hq : 0 < q) (hq1 : q < 1) (hB : 0 ≤ B) + {M : ℕ} (hM : 0 < M) (a : ℕ → ℝ) (ha : ∀ j, |a j| ≤ B) + (s : Finset ℝ) (c : ℝ → ℝ) : + |∑' j, binomialMass q M j*a j| ≤ + B*(∫ x : ℝ, |histogram q M (binomialMass q M) x- + gaussianPDFReal 0 ⟨q*(1-q),mul_nonneg hq.le (by linarith)⟩ x|)+ + B*(∫ x : ℝ, |gaussianPDFReal 0 ⟨q*(1-q),mul_nonneg hq.le (by linarith)⟩ x- + ∑ y ∈ s, c y*gaussianPDFReal (-y) ⟨q,hq.le⟩ x|)+ + ∑ y ∈ s, |c y| * (|∑' j, poissonMass (q*M+(-y)*Real.sqrt M) j*a j|+ + B*(∫ x : ℝ, |histogram q M (poissonMass (q*M+(-y)*Real.sqrt M)) x- + gaussianPDFReal (-y) ⟨q,hq.le⟩ x|)) := by + let u : ℝ → ℝ := testHistogram q M a + have hu : AEStronglyMeasurable u := (measurable_testHistogram q M a).aestronglyMeasurable + have hub : ∀ x, |u x| ≤ B := testHistogram_bound hB ha q M + let ψ := gaussianPDFReal 0 ⟨q*(1-q),mul_nonneg hq.le (by linarith)⟩ + let φ : ℝ → ℝ → ℝ := fun y => gaussianPDFReal (-y) ⟨q,hq.le⟩ + have hψ : Integrable ψ := integrable_gaussianPDFReal _ _ + have hφ (y) : Integrable (φ y) := integrable_gaussianPDFReal _ _ + have hbin := pairing_le_pairing_add_error + (integrable_histogram (hasSum_binomialMass q M) q hM) hψ hu hub + rw [integral_histogram_test (hasSum_binomialMass q M).summable ha q hM] at hbin + have hfin := pairing_finite_error_bound hψ hφ hu hub s c + have hpoi (y : ℝ) : |∫ x : ℝ, φ y x*u x| ≤ + |∑' j, poissonMass (q*M+(-y)*Real.sqrt M) j*a j|+ + B*(∫ x : ℝ, |histogram q M (poissonMass (q*M+(-y)*Real.sqrt M)) x-φ y x|) := by + have hp := pairing_le_pairing_add_error (hφ y) + (integrable_histogram (hasSum_poissonMass (q*M+(-y)*Real.sqrt M)) q hM) hu hub + rw [integral_histogram_test (hasSum_poissonMass _).summable ha q hM] at hp + simpa only [abs_sub_comm] using hp + have hs := Finset.sum_le_sum (fun y (_ : y ∈ s) => + mul_le_mul_of_nonneg_left (hpoi y) (abs_nonneg (c y))) + linarith + +theorem finite_clock_certificate {q B ε : ℝ} (hq : 0 < q) (hq1 : q < 1) + (hB : 0 < B) (hε : 0 < ε) : + ∃ (s : Finset ℝ) (δ : ℝ), 0 < δ ∧ ∃ N : ℕ, ∀ M : ℕ, N ≤ M → + ∀ a : ℕ → ℝ, (∀ j, |a j| ≤ B) → + (∀ y ∈ s, |∑' j, poissonMass (q*M+(-y)*Real.sqrt M) j*a j| < δ) → + |∑' j, binomialMass q M j*a j| < ε := by + let v : ℝ≥0 := ⟨q,hq.le⟩ + let w : ℝ≥0 := ⟨q*(1-q),mul_nonneg hq.le (by linarith)⟩ + have hv : 0 < v := hq + have hw : 0 < w := mul_pos hq (by linarith) + have hwv : w ≤ v := by change q*(1-q) ≤ q; nlinarith [sq_nonneg q] + have htol : 0 < ε/(4*B) := by positivity + obtain ⟨s,c,happrox⟩ := finite_gaussianPDF_approximation hv hw hwv htol + let A : ℝ := (∑ y ∈ s, |c y|)+1 + have hS : 0 ≤ ∑ y ∈ s, |c y| := Finset.sum_nonneg (fun _ _ => abs_nonneg _) + have hA : 0 < A := by dsimp [A]; linarith + let δ := ε/(4*A*(B+1)) + have hδ : 0 < δ := by dsimp [δ]; positivity + have hδeq : 4*A*(B+1)*δ = ε := by + dsimp [δ]; field_simp + have hBin : ∀ᶠ M in atTop, + (∫ x : ℝ, |histogram q M (binomialMass q M) x-gaussianPDFReal 0 w x|) < ε/(4*B) := + (binomial_density_L1 hq hq1).eventually (gt_mem_nhds htol) + have hPoi : ∀ᶠ M in atTop, ∀ y ∈ s, + (∫ x : ℝ, |histogram q M (poissonMass (q*M+(-y)*Real.sqrt M)) x- + gaussianPDFReal (-y) v x|) < δ := by + apply s.eventually_all.mpr + intro y _ + exact (poisson_density_L1 hq (-y)).eventually (gt_mem_nhds hδ) + obtain ⟨N,hN⟩ := eventually_atTop.mp (hBin.and (hPoi.and (eventually_gt_atTop 0))) + refine ⟨s,δ,hδ,N,?_⟩ + intro M hM a ha hp + obtain ⟨hb,hpL,hM0⟩ := hN M hM + have hbound := clock_finite_error_bound hq hq1 hB.le hM0 a ha s c + have hb' : B*(∫ x : ℝ, |histogram q M (binomialMass q M) x- + gaussianPDFReal 0 w x|) < ε/4 := by + have := (lt_div_iff₀ (by positivity : 0 < 4*B)).mp hb + linarith + have ha' : B*(∫ x : ℝ, |gaussianPDFReal 0 w x- + ∑ y ∈ s, c y*gaussianPDFReal (-y) v x|) < ε/4 := by + have := (lt_div_iff₀ (by positivity : 0 < 4*B)).mp happrox + linarith + have hs : (∑ y ∈ s, |c y| * (|∑' j, + poissonMass (q*M+(-y)*Real.sqrt M) j*a j|+ + B*(∫ x : ℝ, |histogram q M (poissonMass (q*M+(-y)*Real.sqrt M)) x- + gaussianPDFReal (-y) v x|))) ≤ (∑ y ∈ s, |c y|)*((B+1)*δ) := by + rw [Finset.sum_mul] + apply Finset.sum_le_sum + intro y hy + apply mul_le_mul_of_nonneg_left _ (abs_nonneg _) + have := hp y hy + have := mul_lt_mul_of_pos_left (hpL y hy) hB + nlinarith + have hs' : (∑ y ∈ s, |c y|)*((B+1)*δ) ≤ ε/4 := by + have hx : (∑ y ∈ s, |c y|) ≤ A := by dsimp [A]; linarith + have := mul_le_mul_of_nonneg_right hx (show 0 ≤ (B+1)*δ by positivity) + nlinarith [hδeq] + change |∑' j, binomialMass q M j*a j| ≤ _ at hbound + linarith + +end SKGapCutoff.Clock + +open MeasureTheory Filter ProbabilityTheory +open scoped Topology NNReal ENNReal + +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Terminal/PowExponentialPair.lean b/lean/OAI/Probability/SKGap/Terminal/PowExponentialPair.lean new file mode 100644 index 0000000000000000000000000000000000000000..408321546de5a4ce7c690be0d73b3690c146c397 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Terminal/PowExponentialPair.lean @@ -0,0 +1,107 @@ +import Mathlib +import OAI.Probability.SKGap.Gaussian.StdGaussianMgfLipschitz + +namespace OAI + +section +noncomputable section +open MeasureTheory ProbabilityTheory InformationTheory Real Set +open scoped NNReal ENNReal +open Filter +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius ENNReal NNReal +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius NNReal +noncomputable section +open MeasureTheory ProbabilityTheory Real Set Filter +open MeasureTheory.Measure +open scoped ENNReal NNReal MeasureTheory Topology +namespace SKGap +open MeasureTheory ProbabilityTheory Real +open scoped Topology +section SubgaussianMoments +variable {Ω : Type*} [MeasurableSpace Ω] {μ : Measure Ω} {X : Ω → ℝ} {c : ℝ≥0} + +lemma pow_le_exponential_pair (x : ℝ) {r : ℝ} (hr : 0 < r) (k : ℕ) : + |x|^k ≤ ((k.factorial : ℝ)/r^k) * (exp (r*x)+exp (-r*x)) := by + have hk : 0 < (k.factorial : ℝ) := by exact_mod_cast k.factorial_pos + have hh := Real.pow_div_factorial_le_exp (r*|x|) (mul_nonneg hr.le (abs_nonneg x)) k + have he : exp (r*|x|) ≤ exp (r*x)+exp (-r*x) := by + rcases le_total 0 x with hx | hx + · rw [abs_of_nonneg hx]; exact le_add_of_nonneg_right (exp_nonneg _) + · rw [abs_of_nonpos hx]; have hid : r * -x = -r*x := by ring + rw [hid]; exact le_add_of_nonneg_left (exp_nonneg _) + have hg := hh.trans he + rw [div_le_iff₀ hk,mul_pow] at hg + rw [div_mul_eq_mul_div] + apply (le_div_iff₀ (pow_pos hr k)).mpr + convert hg using 1 <;> ring + +lemma subgaussian_abs_moment {r : ℝ} (hr : 0 < r) (hX : HasSubgaussianMGF X c μ) (k : ℕ) : + (∫ x, |X x|^k ∂μ) ≤ + 2*((k.factorial : ℝ)/r^k)*exp ((c : ℝ)*r^2/2) := by + let C := (k.factorial : ℝ)/r^k + have hC : 0 ≤ C := by dsimp [C]; positivity + have he : Integrable (fun x => C*(exp (r*X x)+exp (-r*X x))) μ := + ((hX.integrable_exp_mul r).add (hX.integrable_exp_mul (-r))).const_mul C + have hp (x : Ω) : |X x|^k ≤ C*(exp (r*X x)+exp (-r*X x)) := pow_le_exponential_pair (X x) hr k + have hi : Integrable (fun x => |X x|^k) μ := by + apply he.mono' (hX.integrable.aestronglyMeasurable.norm.pow k) + filter_upwards [] with x + simpa only [Pi.pow_apply,Real.norm_eq_abs,abs_pow,abs_abs] using hp x + calc + _ ≤ ∫ x, C*(exp (r*X x)+exp (-r*X x)) ∂μ := integral_mono hi he hp + _ = C*(mgf X μ r+mgf X μ (-r)) := by + rw [integral_const_mul,integral_add (hX.integrable_exp_mul r) (hX.integrable_exp_mul (-r))] + rfl + _ ≤ C*(exp ((c:ℝ)*r^2/2)+exp ((c:ℝ)*r^2/2)) := by + apply mul_le_mul_of_nonneg_left _ hC + simpa only [neg_sq] using add_le_add (hX.mgf_le r) (hX.mgf_le (-r)) + _ = _ := by dsimp only [C]; ring +end SubgaussianMoments + +section GaussianMoments +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] + [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] + +lemma stdGaussian_subgaussian_lipschitz {f : E → ℝ} {L : ℝ≥0} (hf : LipschitzWith L f) : + HasSubgaussianMGF (fun x => f x-∫ y, f y ∂stdGaussian E) + ⟨π^2*(L:ℝ)^2/4,by positivity⟩ (stdGaussian E) where + integrable_exp_mul r := by + apply gaussian_integrable_exp_lipschitz (L := L) _ r + apply LipschitzWith.of_dist_le_mul + intro x y + simpa only [Real.dist_eq,sub_sub_sub_cancel_right] using hf.dist_le_mul x y + mgf_le r := by + have hh := stdGaussian_mgf_lipschitz_le hf r + change (∫ x, exp (r*(f x-∫ y, f y ∂stdGaussian E)) ∂stdGaussian E) ≤ _ + apply hh.trans_eq + change exp (π^2*r^2*(L:ℝ)^2/8) = exp ((π^2*(L:ℝ)^2/4)*r^2/2) + congr 1 + ring + +lemma stdGaussian_abs_centered_moment {f : E → ℝ} {L : ℝ≥0} (hf : LipschitzWith L f) + (hL : 0 < L) (k : ℕ) : + (∫ x, |f x-∫ y, f y ∂stdGaussian E|^k ∂stdGaussian E) ≤ + (2*(k.factorial : ℝ)*exp (π^2/8))*(L:ℝ)^k := by + have hLr : 0 < (L:ℝ) := hL + have hh := subgaussian_abs_moment (inv_pos.mpr hLr) (stdGaussian_subgaussian_lipschitz hf) k + convert hh using 1 + have he : π^2*(L:ℝ)^2/4*((L:ℝ)⁻¹)^2/2 = π^2/8 := by field_simp [ne_of_gt hLr]; ring + change 2*(k.factorial : ℝ)*exp (π^2/8)*(L:ℝ)^k = + 2*((k.factorial:ℝ)/(L:ℝ)⁻¹^k)*exp ((π^2*(L:ℝ)^2/4)*(L:ℝ)⁻¹^2/2) + rw [he,inv_pow,div_inv_eq_mul] + ring +end GaussianMoments +end SKGap + +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Terminal/ResidualPairMoments.lean b/lean/OAI/Probability/SKGap/Terminal/ResidualPairMoments.lean new file mode 100644 index 0000000000000000000000000000000000000000..5aa5d5e2ad3d36a6fe8f9e8ec823086e39802f8c --- /dev/null +++ b/lean/OAI/Probability/SKGap/Terminal/ResidualPairMoments.lean @@ -0,0 +1,195 @@ +import Mathlib +import OAI.Probability.SKGap.Terminal.FieldGibbs + +namespace OAI + +section + +noncomputable section +open scoped BigOperators Matrix.Norms.Frobenius +namespace SKGapCutoff.Static +open Primary Recipe +variable {n : ℕ} + +lemma varianceEnergy_gradient_bound (P : Observables n) (hP : ∀x,0≤P x) + (hp : ∑x,P x=1) (f : Observables n) {L : ℝ} + (hd : ∀x,∑i,(halfDiff i f x)^2≤L^2) : varianceEnergy P f≤L^2 := by + calc + _ ≤ ∑x,P x*L^2 := by + apply Finset.sum_le_sum; intro x _ + apply mul_le_mul_of_nonneg_left _ (hP x) + exact (Finset.sum_le_sum (fun i _=>mul_le_of_le_one_left (sq_nonneg _) (conditionalVariance_le_one P x i))).trans (hd x) + _ = _ := by rw [←Finset.sum_mul,hp,one_mul] + +lemma weak_selftest (P F : Observables n) (hP : ∀x,0≤P x) (hp : ∑x,P x=1) + {C L : ℝ} (hC : 0≤C) + (hw : ∀G,|∑x,P x*G x*F x|≤C*starNorm P G) + (hd : ∀x,∑i,(halfDiff i F x)^2≤L^2) : + (∑x,P x*(F x)^2)≤C^2+L^2 := by + let X:=∑x,P x*(F x)^2 + have hX : 0≤X:=Finset.sum_nonneg (fun x _=>mul_nonneg (hP x) (sq_nonneg _)) + have he:=varianceEnergy_gradient_bound P hP hp F hd + have hb : X≤C*Real.sqrt (X+L^2) := by + apply le_trans _ (mul_le_mul_of_nonneg_left (Real.sqrt_le_sqrt (show X+varianceEnergy P F≤X+L^2 by linarith)) hC) + have hh : (∑x,P x*F x*F x)=X := by + apply Finset.sum_congr rfl; intro x _; ring + have hh' := hw F + rw [hh,abs_of_nonneg hX] at hh' + exact hh' + have hy:=Real.sq_sqrt (add_nonneg hX (sq_nonneg L)) + change X≤_ + nlinarith [sq_nonneg (C-Real.sqrt (X+L^2))] + +lemma square_selftest (hn : 0by + simpa only [sq_abs,mag] using pow_le_pow_left₀ (abs_nonneg _) (primaryState_mag_bounded j J h k x i) 2) + _ = _ := by simp + +lemma residual_vectorNorm (j : ℝ) (J : Interaction n) (h : Fin n→ℝ) (k : ℕ) (x : Spin n) : + vectorNorm (residual j J h k x)≤2*Real.sqrt (n:ℝ) := by + have he : vectorNorm (residual j J h k x)≤vectorNorm (mag j J h k x)+vectorNorm (mag j J h (k+1) x) := + norm_sub_le (WithLp.toLp 2 (mag j J h k x) : EuclideanSpace ℝ (Fin n)) (WithLp.toLp 2 (mag j J h (k+1) x)) + exact he.trans ((add_le_add (mag_vectorNorm j J h k x) (mag_vectorNorm j J h (k+1) x)).trans_eq (by ring)) + +lemma primaryPair_size (hn : 0hformal x t (ht.trans hl))).2.2.1 + intro x + change ‖derivativeVector (primaryPair j J h k) x‖≤(A+B')+B'*2+2*(A+B')*B' + apply (normalizedPair_derivative_bound (Cu:=2) (Cv:=1) hn _ _ x (add_nonneg hA hB') hB' ?_ + (hm _ le_rfl x) (residual_vectorNorm j J h k x) (by simpa using mag_vectorNorm j J h (k+1) x)).trans_eq (by ring) + rw [show derivativeMatrix (residual j J h k) x= + derivativeMatrix (mag j J h k) x-derivativeMatrix (mag j J h (k+1)) x from derivativeMatrix_sub _ _ x] + simp only [opNorm_eq,map_sub] + exact (norm_sub_le _ _).trans (add_le_add (hm _ (by omega) x) (hm _ le_rfl x)) + +end SKGapCutoff.Recipe + +end +end + +section + +noncomputable section +open scoped BigOperators +namespace SKGapCutoff.Recipe +open Primary Static +universe u +variable {Ω : Type u} {n : Ω→ℕ} {M : ℕ} {j R B W C : ℝ} +variable {J : ∀a,Interaction (n a)} {h : ∀a,Fin (n a)→ℝ} + +lemma primaryPair_difference_sq {n : ℕ} (hn : 0primaryPair j J h k y/Real.sqrt (n:ℝ)) x)^2)≤(primaryPairBudget j R B k)^2 := by + have ht (i : Fin n) : halfDiff i (fun y=>primaryPair j J h k y/Real.sqrt (n:ℝ)) x= + halfDiff i (primaryPair j J h k) x/Real.sqrt (n:ℝ) := by unfold halfDiff; ring + simp only [ht,div_pow,←Finset.sum_div,Real.sq_sqrt (Nat.cast_nonneg n)] + exact (div_le_div_of_nonneg_right (primaryPair_difference_sq hn hR hB J h hJ k hformal x) + (Nat.cast_nonneg n)).trans (div_le_self (sq_nonneg _) (by exact_mod_cast hn)) + +theorem gibbs_primary_pair_moments (k : ℕ) (hk : k+1(emptyRecipe j (J a) (h a) M).normalizedPrimary q + have hD : FamilyRecipe j J h D 0 k 2:= + (emptyRecipe_family j J h M).normalizedPrimary hn q k le_rfl + have hcon (a : Ω) (x : Spin (n a)) : + (∑i,residual j (J a) (h a) k x i*(D a).source 0 x i)=primaryPair j (J a) (h a) k x := by + rw [show (D a).source 0=fun y i=>mag j (J a) (h a) (k+1) y i/Real.sqrt (n a:ℝ) from + OrdinaryData.normalizedPrimary_magnetization _ q j (J a) (h a) k rfl] + simp only [primaryPair,normalizedPair,vectorPair,mul_div_assoc,Finset.sum_div] + obtain ⟨hw,hs⟩:=gibbs_ordinary_residuals k 0 (by norm_num : (2:ℝ)≤2) (by omega) + hR hB hW hC hn hJ hdiag (by simpa using hevent) D hD + have hw':=hw.congr hcon + have hs':=hs.congr hcon + obtain ⟨C₁,hC₁,hw'⟩:=hw' + let L:=primaryPairBudget j R B k + have hL : 0≤L:=primaryPairBudget_nonneg hR hB k + obtain ⟨C₂,hC₂,hs'⟩:=hs' 2 L (by norm_num) hL + refine ⟨C₁^2+L^2,C₂,by positivity,hC₂,fun a=>⟨?_,?_⟩⟩ + · exact weak_selftest _ _ (fun x=>(fieldGibbs_pos _ _ x).le) (sum_fieldGibbs _ _) hC₁ (hw' a) + (primaryPair_difference_sq (hn a) hR hB (J a) (h a) (hevent a).1 k + (fun x l hl=>(hevent a).2.1 (h a) x l (by omega))) + · intro f + apply square_selftest (hn a) _ _ (fun x=>(fieldGibbs_pos _ _ x).le) ?_ f + intro g + apply hs' a g _ + · intro x + rw [abs_div,abs_of_pos (Real.sqrt_pos.mpr (Nat.cast_pos.mpr (hn a)))] + exact (div_le_iff₀ (Real.sqrt_pos.mpr (Nat.cast_pos.mpr (hn a)))).mpr + (primaryPair_size (hn a) j (J a) (h a) k x) + · exact primaryPair_scaled_difference (hn a) hR hB (J a) (h a) (hevent a).1 k + (fun x l hl=>(hevent a).2.1 (h a) x l (by omega)) + +end SKGapCutoff.Recipe + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Terminal/SingleSpinPlantedLaw.lean b/lean/OAI/Probability/SKGap/Terminal/SingleSpinPlantedLaw.lean new file mode 100644 index 0000000000000000000000000000000000000000..7c36f89f2af5a1f7688b2fd65be4fefed54387f4 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Terminal/SingleSpinPlantedLaw.lean @@ -0,0 +1,219 @@ +import Mathlib +import OAI.Probability.SKGap.Brownian.ContinuousEnergy +import OAI.Probability.SKGap.Localization.UpperCoefficient + +namespace OAI + +section +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators NNReal ENNReal +namespace SKGapCutoff + +lemma gaussianPDFReal_tilt (v : ℝ≥0) (hv : v ≠ 0) (a x : ℝ) : + gaussianPDFReal ((v : ℝ) * a) v x = + gaussianPDFReal 0 v x * Real.exp (a*x - (v : ℝ)*a^2/2) := by + have hvR : (v : ℝ) ≠ 0 := by exact_mod_cast hv + unfold gaussianPDFReal + conv_rhs => rw [mul_assoc, ← Real.exp_add] + congr 2 + field_simp + ring + +lemma gaussianReal_exponential_tilt (v : ℝ≥0) (a : ℝ) : + (gaussianReal 0 v).withDensity + (fun x => ENNReal.ofReal (Real.exp (a*x - (v : ℝ)*a^2/2))) = + gaussianReal ((v : ℝ)*a) v := by + by_cases hv : v = 0 + · subst v + simp [dirac_withDensity] + rw [gaussianReal_of_var_ne_zero _ hv, gaussianReal_of_var_ne_zero _ hv] + rw [← withDensity_mul _ (measurable_gaussianPDF 0 v) (by fun_prop)] + congr 1 + funext x + simp only [Pi.mul_apply, gaussianPDF, gaussianPDFReal_tilt v hv a x, + ENNReal.ofReal_mul (gaussianPDFReal_nonneg 0 v x)] + +lemma pi_withDensity_ofReal_prod {ι : Type*} [Fintype ι] + {E : Type*} [MeasurableSpace E] (μ : ι → Measure E) [∀ i, SigmaFinite (μ i)] + (f : ι → E → ℝ) (hf : ∀ i, Integrable (f i) (μ i)) + (hf0 : ∀ i x, 0 ≤ f i x) : + Measure.pi (fun i => (μ i).withDensity (fun x => ENNReal.ofReal (f i x))) = + (Measure.pi μ).withDensity (fun x => ENNReal.ofReal (∏ i, f i (x i))) := by + apply Measure.pi_eq + intro s hs + rw [withDensity_apply _ (MeasurableSet.univ_pi hs), Measure.restrict_pi_pi] + rw [← ofReal_integral_eq_lintegral_ofReal + (Integrable.fintype_prod (fun i => (hf i).restrict)) + (Filter.Eventually.of_forall (fun x => Finset.prod_nonneg (fun i _ => hf0 i (x i))))] + rw [integral_fintype_prod_eq_prod] + rw [ENNReal.ofReal_prod_of_nonneg (fun i _ => integral_nonneg (hf0 i))] + apply Finset.prod_congr rfl + intro i _ + rw [withDensity_apply _ (hs i)] + exact ofReal_integral_eq_lintegral_ofReal (hf i |>.restrict) + (Filter.Eventually.of_forall (hf0 i)) + +lemma gaussianPi_exponential_tilt {ι : Type*} [Fintype ι] + (v : ℝ≥0) (a : ι → ℝ) : + (Measure.pi (fun _ : ι => gaussianReal 0 v)).withDensity + (fun g => ENNReal.ofReal + (Real.exp ((∑ i, a i * g i) - (v : ℝ)*(∑ i, a i ^ 2)/2))) = + Measure.pi (fun i => gaussianReal ((v : ℝ)*a i) v) := by + have hp (g : ι → ℝ) : Real.exp ((∑ i, a i * g i) - (v : ℝ)*(∑ i, a i ^ 2)/2) = + ∏ i, Real.exp (a i*g i - (v : ℝ)*(a i)^2/2) := by + rw [← Real.exp_sum] + congr 1 + simp [Finset.sum_sub_distrib, Finset.mul_sum, Finset.sum_div] + simp_rw [← gaussianReal_exponential_tilt v, hp] + symm + apply pi_withDensity_ofReal_prod + · intro i + simp_rw [Real.exp_sub, div_eq_mul_inv] + exact (integrable_exp_mul_gaussianReal (μ := 0) (v := v) (a i)).mul_const _ + · intro i x; positivity + +noncomputable def singleSpinPlantedLaw (β : ℝ) {n : ℕ} (x : Spin n) : + Measure (GaussianCoordinates n) := + (disorderLaw β n).withDensity (fun g => ENNReal.ofReal + (Real.exp (energy (sampledInteraction g) x - β^2*((n : ℝ)-1)/4))) + +lemma singleSpinPlantedLaw_eq_gaussianPi (β : ℝ) {n : ℕ} (hn : 0 < n) (x : Spin n) : + singleSpinPlantedLaw β x = Measure.pi (fun p : Fin n × Fin n => + gaussianReal (β^2/n * upperCoefficient x p) (Real.toNNReal (β^2/n))) := by + unfold singleSpinPlantedLaw disorderLaw + have hv : (Real.toNNReal (β^2/(n : ℝ)) : ℝ) = β^2/n := + Real.coe_toNNReal _ (div_nonneg (sq_nonneg _) (Nat.cast_nonneg _)) + have hnR : (n : ℝ) ≠ 0 := by exact_mod_cast (Nat.ne_of_gt hn) + have hc : (Real.toNNReal (β^2/(n : ℝ)) : ℝ) * (∑ p, upperCoefficient x p ^ 2)/2 = + β^2*((n : ℝ)-1)/4 := by + rw [hv, sum_upperCoefficient_sq] + field_simp + ring + simp_rw [energy_sampled, ← hc] + rw [gaussianPi_exponential_tilt] + simp only [hv] + +lemma singleSpinPlantedLaw_probability (β : ℝ) {n : ℕ} (hn : 0 < n) (x : Spin n) : + IsProbabilityMeasure (singleSpinPlantedLaw β x) := by + rw [singleSpinPlantedLaw_eq_gaussianPi β hn] + infer_instance + +noncomputable def plantedDisorderLaw (β : ℝ) (n : ℕ) : Measure (GaussianCoordinates n) := + (disorderLaw β n).withDensity (fun g => ENNReal.ofReal + (partition (sampledInteraction g) / (∫ h, partition (sampledInteraction h) ∂disorderLaw β n))) + +lemma plantedDisorderLaw_probability (β : ℝ) {n : ℕ} (hn : 0 < n) : + IsProbabilityMeasure (plantedDisorderLaw β n) := by + have hZ : Integrable (fun g : GaussianCoordinates n => partition (sampledInteraction g)) + (disorderLaw β n) := by + unfold partition + exact integrable_finsetSum _ (fun x _ => integrable_exp_energy_sampled β x) + have hm : 0 < ∫ g, partition (sampledInteraction g) ∂disorderLaw β n := by + rw [integral_partition_sampled β hn] + positivity + constructor + rw [plantedDisorderLaw, withDensity_apply _ MeasurableSet.univ, Measure.restrict_univ] + rw [← ofReal_integral_eq_lintegral_ofReal (hZ.div_const _) + (Filter.Eventually.of_forall (fun g => div_nonneg (le_of_lt (partition_pos _)) (le_of_lt hm)))] + rw [integral_div, div_self (ne_of_gt hm), ENNReal.ofReal_one] + +lemma planted_density_sum (β : ℝ) {n : ℕ} (hn : 0 < n) (g : GaussianCoordinates n) : + partition (sampledInteraction g) / (∫ h, partition (sampledInteraction h) ∂disorderLaw β n) = + ∑ x : Spin n, ((2 : ℝ)^n)⁻¹ * + Real.exp (energy (sampledInteraction g) x - β^2*((n : ℝ)-1)/4) := by + rw [integral_partition_sampled β hn] + unfold partition + simp_rw [Real.exp_sub, ← Finset.mul_sum, ← Finset.sum_div] + ring + +lemma plantedDisorderLaw_mixture (β : ℝ) {n : ℕ} (hn : 0 < n) : + plantedDisorderLaw β n = ENNReal.ofReal (((2 : ℝ)^n)⁻¹) • + Measure.sum (fun x : Spin n => singleSpinPlantedLaw β x) := by + ext s hs + rw [plantedDisorderLaw, withDensity_apply _ hs, Measure.smul_apply, + Measure.sum_apply _ hs, tsum_fintype] + simp_rw [singleSpinPlantedLaw, withDensity_apply _ hs] + rw [← lintegral_finsetSum (s := Finset.univ) (fun x _ => by simp_rw [energy_sampled]; fun_prop)] + rw [smul_eq_mul, ← lintegral_const_mul _ (by simp_rw [energy_sampled]; fun_prop)] + apply lintegral_congr + intro g + rw [planted_density_sum β hn] + rw [ENNReal.ofReal_sum_of_nonneg (fun x _ => by positivity)] + simp_rw [ENNReal.ofReal_mul (by positivity : 0 ≤ ((2 : ℝ)^n)⁻¹)] + rw [Finset.mul_sum] + +lemma lower_density_markov {E : Type*} [MeasurableSpace E] (μ : Measure E) + (r f : E → ℝ≥0∞) (hr : Measurable r) (hf : Measurable f) + (A : Set E) (hA : MeasurableSet A) (c t : ℝ≥0∞) + (hc : ∀ x ∈ A, c ≤ r x) (ht : ∀ x ∈ A, t ≤ f x) : + (c*t) * μ A ≤ ∫⁻ x, f x ∂(μ.withDensity r) := by + rw [lintegral_withDensity_eq_lintegral_mul μ hr hf] + calc + (c*t) * μ A = ∫⁻ _ in A, c*t ∂μ := by simp + _ ≤ ∫⁻ x in A, r x * f x ∂μ := + setLIntegral_mono' hA (fun x hx => mul_le_mul' (hc x hx) (ht x hx)) + _ ≤ ∫⁻ x, r x * f x ∂μ := lintegral_mono' Measure.restrict_le_self le_rfl + +lemma lower_density_markov_div {E : Type*} [MeasurableSpace E] (μ : Measure E) + (r f : E → ℝ≥0∞) (hr : Measurable r) (hf : Measurable f) + (A : Set E) (hA : MeasurableSet A) (c t : ℝ≥0∞) + (hc0 : c ≠ 0) (hcT : c ≠ ⊤) (ht0 : t ≠ 0) (htT : t ≠ ⊤) + (hc : ∀ x ∈ A, c ≤ r x) (ht : ∀ x ∈ A, t ≤ f x) : + μ A ≤ (∫⁻ x, f x ∂(μ.withDensity r)) / (c*t) := by + apply (ENNReal.le_div_iff_mul_le (Or.inl (mul_ne_zero hc0 ht0)) + (Or.inl (ENNReal.mul_ne_top hcT htT))).mpr + simpa only [mul_comm] using lower_density_markov μ r f hr hf A hA c t hc ht + +lemma planted_law_transfer (β : ℝ) {n : ℕ} (hn : 0 < n) + (a s : ℝ) (f : GaussianCoordinates n → ℝ≥0∞) (hf : Measurable f) : + (disorderLaw β n) {g | Real.log (∫ h, partition (sampledInteraction h) ∂disorderLaw β n) - a ≤ + Real.log (partition (sampledInteraction g)) ∧ ENNReal.ofReal (Real.exp (-s)) ≤ f g} ≤ + ENNReal.ofReal (Real.exp (a+s)) * ∫⁻ g, f g ∂plantedDisorderLaw β n := by + let m := ∫ h, partition (sampledInteraction h) ∂disorderLaw β n + let r := fun g : GaussianCoordinates n => ENNReal.ofReal (partition (sampledInteraction g) / m) + let A := {g : GaussianCoordinates n | Real.log m - a ≤ + Real.log (partition (sampledInteraction g)) ∧ ENNReal.ofReal (Real.exp (-s)) ≤ f g} + have hm : 0 < m := by dsimp [m]; rw [integral_partition_sampled β hn]; positivity + have hZ := (continuous_partition n).comp (continuous_sampledInteraction n) + have hr : Measurable r := by dsimp [r]; exact (hZ.measurable.div_const m).ennreal_ofReal + have hA : MeasurableSet A := + (measurableSet_le measurable_const hZ.measurable.log).inter + (measurableSet_le measurable_const hf) + have hd : ∀ g ∈ A, ENNReal.ofReal (Real.exp (-a)) ≤ r g := by + intro g hg + apply ENNReal.ofReal_le_ofReal + have he : -a ≤ Real.log (partition (sampledInteraction g) / m) := by + rw [Real.log_div (partition_pos _).ne' hm.ne'] + linarith [hg.1] + have hexp := Real.exp_le_exp.mpr he + rwa [Real.exp_log (div_pos (partition_pos _) hm)] at hexp + have h := lower_density_markov_div (disorderLaw β n) r f hr hf A hA + (ENNReal.ofReal (Real.exp (-a))) (ENNReal.ofReal (Real.exp (-s))) + (by positivity) ENNReal.ofReal_ne_top (by positivity) ENNReal.ofReal_ne_top hd + (fun g hg => hg.2) + have he : (ENNReal.ofReal (Real.exp (-a)) * ENNReal.ofReal (Real.exp (-s)))⁻¹ = + ENNReal.ofReal (Real.exp (a+s)) := by + rw [← ENNReal.ofReal_mul (Real.exp_pos _).le, ← Real.exp_add, + ← ENNReal.ofReal_inv_of_pos (Real.exp_pos _), ← Real.exp_neg] + congr 2 + ring + rw [div_eq_mul_inv, he, mul_comm] at h + exact h + +end SKGapCutoff + +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal + +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Terminal/SmallFieldCount.lean b/lean/OAI/Probability/SKGap/Terminal/SmallFieldCount.lean new file mode 100644 index 0000000000000000000000000000000000000000..37d459cfcce315b242bd5370db55d2926e1551e4 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Terminal/SmallFieldCount.lean @@ -0,0 +1,279 @@ +import Mathlib +import OAI.Probability.SKGap.Terminal.TerminalMatrixTransfer +import OAI.Probability.SKGap.Terminal.SpinLocalField + +namespace OAI + +section +noncomputable section +namespace SKGap +open Matrix Real +open scoped BigOperators Matrix.Norms.L2Operator +variable {n : ℕ} + +lemma cardinal_small_sum {ι : Type*} [Fintype ι] [DecidableEq ι] + (h z : ι→ℝ) {t a b : ℝ} (ht : 0 < t) + (hh : ((Finset.univ.filter (fun i=>|h i| < 2*t)).card:ℝ) ≤ a) + (hz : (∑ i,z i^2) ≤ t^2*b) : + ((Finset.univ.filter (fun i=>|h i+z i| < t)).card:ℝ) ≤ a+b := by + let S := Finset.univ.filter (fun i=>|h i+z i| < t) + let B := Finset.univ.filter (fun i=>|h i| < 2*t) + let L := Finset.univ.filter (fun i=>t < |z i|) + have hsub : S ⊆ B ∪ L := by + intro i hi + have hfield : |h i+z i| < t := (Finset.mem_filter.mp hi).2 + by_cases hb : |h i| < 2*t + · exact Finset.mem_union_left _ (Finset.mem_filter.mpr ⟨Finset.mem_univ _,hb⟩) + · apply Finset.mem_union_right + apply Finset.mem_filter.mpr + refine ⟨Finset.mem_univ _,?_⟩ + have he : h i=(h i+z i)+(-z i) := by ring + have habs := abs_add_le (h i+z i) (-z i) + rw [← he,abs_neg] at habs + linarith only [hfield,le_of_not_gt hb,habs] + have hL : t^2*(L.card:ℝ) ≤ ∑ i,z i^2 := by + calc + _ = ∑ _i ∈ L,t^2 := by simp [mul_comm] + _ ≤ ∑ i ∈ L,z i^2 := by + apply Finset.sum_le_sum + intro i hi + have hh := ((Finset.mem_filter.mp hi).2 : t < |z i|) + have hs := (sq_le_sq₀ ht.le (abs_nonneg (z i))).mpr hh.le + simpa only [sq_abs] using hs + _ ≤ ∑ i,z i^2 := Finset.sum_le_univ_sum_of_nonneg (fun i=>sq_nonneg (z i)) + have hcard := (Finset.card_le_card hsub).trans (Finset.card_union_le B L) + have hcard' : (S.card:ℝ) ≤ (B.card:ℝ)+(L.card:ℝ) := by exact_mod_cast hcard + have hLb : (L.card:ℝ) ≤ b := by + exact (mul_le_mul_iff_right₀ (sq_pos_of_pos ht)).mp (hL.trans hz) + exact hcard'.trans (add_le_add hh hLb) + +lemma coupling_spin_norm_square (g : Disorder n) {M : ℝ} (hM : 0 ≤ M) + (hJ : ‖Matrix.of (coupling g)‖ ≤ M) (x : Spin n) : + (∑ i,(∑ j,coupling g i j*spinValue (x j))^2) ≤ M^2*(n:ℝ) := by + let v : EuclideanSpace ℝ (Fin n) := WithLp.toLp 2 (fun i=>spinValue (x i)) + let w := Matrix.toEuclideanCLM (𝕜 := ℝ) (n := Fin n) (Matrix.of (coupling g)) v + have hv : ‖v‖^2=(n:ℝ) := by + rw [EuclideanSpace.real_norm_sq_eq] + change (∑ i,spinValue (x i)^2)=(n:ℝ) + simp + have hw : ‖w‖ ≤ M*‖v‖ := (ContinuousLinearMap.le_opNorm _ _).trans + (mul_le_mul_of_nonneg_right (by simpa only [Matrix.l2_opNorm_toEuclideanCLM] using hJ) (norm_nonneg v)) + have hw2 := (sq_le_sq₀ (norm_nonneg w) (mul_nonneg hM (norm_nonneg v))).mpr hw + rw [mul_pow,hv,EuclideanSpace.real_norm_sq_eq] at hw2 + exact hw2 + +lemma all_configurations_small_fields (g : Disorder n) (h : Fin n→ℝ) {M t α : ℝ} + (hM : 0 ≤ M) (ht : 0 < t) (hJ : ‖Matrix.of (coupling g)‖ ≤ M) + (hB : ((Finset.univ.filter (fun i=>|h i| < 2*t)).card:ℝ) ≤ α*(n:ℝ)/2) + (hsmall : M^2 ≤ t^2*α/2) : + ∀ x : Spin n,((Finset.univ.filter (fun i=>|localField g h i x| < t)).card:ℝ) ≤ α*(n:ℝ) := by + intro x + have hnorm := coupling_spin_norm_square g hM hJ x + have hnorm' : (∑ i,(∑ j,coupling g i j*spinValue (x j))^2) ≤ t^2*(α*(n:ℝ)/2) := by + apply hnorm.trans + have hh := mul_le_mul_of_nonneg_right hsmall (Nat.cast_nonneg n) + nlinarith only [hh] + have hc := cardinal_small_sum h (fun i=>∑ j,coupling g i j*spinValue (x j)) ht hB hnorm' + have he : α*(n:ℝ)/2+α*(n:ℝ)/2=α*(n:ℝ) := by ring + rw [he] at hc + exact hc +end SKGap + +end +end + +section +noncomputable section +namespace SKGap +open scoped RealInnerProductSpace + +lemma positive_form_cauchy {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] + (H : E →ₗ[ℝ] E) (hH : H.IsSymmetric) (hpos : ∀ v,0 ≤ ⟪v,H v⟫) (u v : E) : + ⟪u,H v⟫^2 ≤ ⟪u,H u⟫*⟪v,H v⟫ := by + have hh : ∀ t : ℝ,0 ≤ ⟪v,H v⟫*(t*t)+(2*⟪u,H v⟫)*t+⟪u,H u⟫ := by + intro t + have hp := hpos (u+t • v) + simp only [map_add,map_smul,inner_add_left,inner_add_right,real_inner_smul_left, + real_inner_smul_right] at hp + have he : ⟪v,H u⟫=⟪u,H v⟫ := (real_inner_comm (H u) v).trans (hH u v) + rw [he] at hp + nlinarith only [hp] + have hd := discrim_le_zero hh + unfold discrim at hd + nlinarith only [hd] + +lemma curvature_poincare_on_kernel_orthogonal {E : Type*} + [NormedAddCommGroup E] [InnerProductSpace ℝ E] [FiniteDimensional ℝ E] + (H : E →ₗ[ℝ] E) (hH : H.IsSymmetric) (hpos : ∀ v,0 ≤ ⟪v,H v⟫) + {ρ : ℝ} (hρ : 0 < ρ) (hcurv : ∀ v,ρ*⟪v,H v⟫ ≤ ⟪H v,H v⟫) + (f : E) (hf : f ∈ (LinearMap.ker H)ᗮ) : + ρ*⟪f,f⟫ ≤ ⟪f,H f⟫ := by + have hrange : f ∈ LinearMap.range H := by + rwa [← hH.orthogonal_range,Submodule.orthogonal_orthogonal] at hf + obtain ⟨g,rfl⟩ := hrange + have hc := positive_form_cauchy H hH hpos (H g) g + have hg := hcurv g + have hp := hpos (H g) + have hn : 0 ≤ ⟪H g,H g⟫ := real_inner_self_nonneg + have hh : ρ*⟪H g,H g⟫^2 ≤ ⟪H g,H (H g)⟫*⟪H g,H g⟫ := by + calc + _ ≤ ρ*(⟪H g,H (H g)⟫*⟪g,H g⟫) := mul_le_mul_of_nonneg_left hc hρ.le + _ = ⟪H g,H (H g)⟫*(ρ*⟪g,H g⟫) := by ring + _ ≤ _ := mul_le_mul_of_nonneg_left hg hp + by_cases hz : ⟪H g,H g⟫=0 + · rw [hz,mul_zero];exact hp + · have hpos' : 0 < ⟪H g,H g⟫ := lt_of_le_of_ne hn (Ne.symm hz) + nlinarith only [hh,hpos'] +end SKGap + +end +end + +section +noncomputable section +namespace SKGap +open Real +open scoped BigOperators RealInnerProductSpace +variable {n : ℕ} + +lemma conditionalExpectation_add (g : Disorder n) (h : Fin n→ℝ) (i : Fin n) + (f k : Spin n→ℝ) (x : Spin n) : + conditionalExpectation g h i (f+k) x=conditionalExpectation g h i f x+conditionalExpectation g h i k x := by + unfold conditionalExpectation + simp only [Pi.add_apply] + ring +lemma conditionalExpectation_smul (g : Disorder n) (h : Fin n→ℝ) (i : Fin n) + (c : ℝ) (f : Spin n→ℝ) (x : Spin n) : + conditionalExpectation g h i (c • f) x=c*conditionalExpectation g h i f x := by + unfold conditionalExpectation + simp only [Pi.smul_apply,smul_eq_mul] + ring + +def heatBathLinear (g : Disorder n) (h : Fin n→ℝ) : (Spin n→ℝ) →ₗ[ℝ] (Spin n→ℝ) where + toFun := heatBathGenerator g h + map_add' f k := by + funext x + simp only [heatBathGenerator,conditionalExpectation_add,Pi.add_apply] + rw [← Finset.sum_add_distrib] + apply Finset.sum_congr rfl + intro i _;ring + map_smul' c f := by + funext x + simp only [heatBathGenerator,conditionalExpectation_smul,Pi.smul_apply,smul_eq_mul, + RingHom.id_apply] + rw [Finset.mul_sum] + apply Finset.sum_congr rfl + intro i _;ring + +def gibbsScale (g : Disorder n) (h : Fin n→ℝ) : (Spin n→ℝ) ≃ₗ[ℝ] EuclideanSpace ℝ (Spin n) where + toFun f := WithLp.toLp 2 (fun x=>sqrt (mass g h x)*f x) + invFun v := fun x=>v x/sqrt (mass g h x) + left_inv f := by + funext x + change sqrt (mass g h x)*f x/sqrt (mass g h x)=f x + exact mul_div_cancel_left₀ (f x) (sqrt_pos.mpr (mass_pos g h x)).ne' + right_inv v := by + ext x + exact mul_div_cancel₀ (v x) (sqrt_pos.mpr (mass_pos g h x)).ne' + map_add' f k := by ext x;simp [mul_add] + map_smul' c f := by ext x;simp [mul_left_comm] + +lemma gibbsScale_inner (g : Disorder n) (h : Fin n→ℝ) (f k : Spin n→ℝ) : + ⟪gibbsScale g h f,gibbsScale g h k⟫=expectation g h (fun x=>f x*k x) := by + simp only [EuclideanSpace.inner_eq_star_dotProduct,star_trivial] + unfold dotProduct expectation + apply Finset.sum_congr rfl + intro x _ + change sqrt (mass g h x)*k x*(sqrt (mass g h x)*f x)=mass g h x*(f x*k x) + calc + _ = sqrt (mass g h x)^2*(f x*k x) := by ring + _ = _ := by rw [sq_sqrt (mass_nonneg g h x)] + +lemma heatBathLinear_const (g : Disorder n) (h : Fin n→ℝ) (c : ℝ) : + heatBathLinear g h (fun _=>c)=0 := by + funext x + simp only [heatBathLinear,heatBathGenerator,LinearMap.coe_mk,AddHom.coe_mk, + conditionalExpectation_const,sub_self,Finset.sum_const_zero,Pi.zero_apply] + +lemma heatBathLinear_kernel (g : Disorder n) (h : Fin n→ℝ) (f : Spin n→ℝ) : + heatBathLinear g h f=0 ↔ ∀ x y,f x=f y := by + constructor + · intro hf + apply (dirichlet_eq_zero_iff g h f).mp + rw [← heatBathGenerator_form] + change expectation g h (fun x=>f x*(heatBathLinear g h f) x)=0 + rw [hf] + simp only [Pi.zero_apply,mul_zero,expectation_const] + · intro hf + have he : f=(fun _=>f (fun _=>false)) := funext (fun x=>hf x (fun _=>false)) + rw [he,heatBathLinear_const] + +lemma heatBath_curvature_poincare (g : Disorder n) (h : Fin n→ℝ) + {ρ : ℝ} (hρ : 0 < ρ) + (hc : ∀ f : Spin n→ℝ,ρ*dirichlet g h f ≤ + expectation g h (fun x=>heatBathGenerator g h f x^2)) (f : Spin n→ℝ) : + ρ*variance g h f ≤ dirichlet g h f := by + let S := gibbsScale g h + let H : EuclideanSpace ℝ (Spin n) →ₗ[ℝ] EuclideanSpace ℝ (Spin n) := + S.toLinearMap ∘ₗ heatBathLinear g h ∘ₗ S.symm.toLinearMap + have hHS (k : Spin n→ℝ) : H (S k)=S (heatBathLinear g h k) := by simp [H] + have hH : H.IsSymmetric := by + intro u v + obtain ⟨u,rfl⟩ := S.surjective u + obtain ⟨v,rfl⟩ := S.surjective v + rw [hHS,hHS] + exact (gibbsScale_inner g h _ _).trans ((heatBathGenerator_adjoint g h u v).trans + (gibbsScale_inner g h _ _).symm) + have hform (k : Spin n→ℝ) : ⟪S k,H (S k)⟫=dirichlet g h k := by + rw [hHS,gibbsScale_inner] + exact heatBathGenerator_form g h k + have hpos : ∀ v,0 ≤ ⟪v,H v⟫ := by + intro v + obtain ⟨k,rfl⟩ := S.surjective v + rw [hform] + exact dirichlet_nonneg g h k + have hcurv : ∀ v,ρ*⟪v,H v⟫ ≤ ⟪H v,H v⟫ := by + intro v + obtain ⟨k,rfl⟩ := S.surjective v + rw [hform,hHS,gibbsScale_inner] + simpa only [sq,heatBathLinear,LinearMap.coe_mk,AddHom.coe_mk] using hc k + let f₀ := f-(fun _=>expectation g h f) + have hm : expectation g h f₀=0 := by + change expectation g h (fun x=>f x-expectation g h f)=0 + rw [expectation_sub,expectation_const,sub_self] + have hker : S f₀ ∈ (LinearMap.ker H)ᗮ := by + rw [Submodule.mem_orthogonal] + intro v hv + obtain ⟨k,rfl⟩ := S.surjective v + have hk : heatBathLinear g h k=0 := by + have hh := LinearMap.mem_ker.mp hv + rw [hHS] at hh + exact S.injective (by simpa using hh) + have hk' := (heatBathLinear_kernel g h k).mp hk + have he : k=(fun _=>k (fun _=>false)) := funext (fun x=>hk' x (fun _=>false)) + rw [gibbsScale_inner,he,expectation_const_mul,hm,mul_zero] + have hh := curvature_poincare_on_kernel_orthogonal H hH hpos hρ hcurv (S f₀) hker + rw [gibbsScale_inner,hform] at hh + have hd : dirichlet g h f₀=dirichlet g h f := by + rw [← heatBathGenerator_form,← heatBathGenerator_form] + have he : heatBathLinear g h f₀=heatBathLinear g h f := by + simp only [f₀,map_sub,heatBathLinear_const,sub_zero] + change expectation g h (fun x=>f₀ x*(heatBathLinear g h f₀) x)=_ + rw [he] + have hz : expectation g h (heatBathLinear g h f)=0 := by + change expectation g h (fun x=>∑ i,(f x-conditionalExpectation g h i f x))=0 + rw [expectation_sum] + apply Finset.sum_eq_zero + intro i _ + rw [expectation_sub,expectation_conditionalExpectation,sub_self] + simp only [f₀,Pi.sub_apply,sub_mul] + rw [expectation_sub,expectation_const_mul,hz,mul_zero,sub_zero] + rfl + rw [hd] at hh + simpa only [variance,f₀,Pi.sub_apply,sq] using hh +end SKGap + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Terminal/Spin.lean b/lean/OAI/Probability/SKGap/Terminal/Spin.lean new file mode 100644 index 0000000000000000000000000000000000000000..66501bfcf02a473cf6326b0125ca7686442964f9 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Terminal/Spin.lean @@ -0,0 +1,405 @@ +import Mathlib +import OAI.Probability.SKGap.Model + +namespace OAI + +section + +open scoped BigOperators + +namespace SKGapCutoff + +abbrev Spin (n : ℕ) := Fin n → Bool +abbrev Interaction (n : ℕ) := Matrix (Fin n) (Fin n) ℝ + +def spin {n : ℕ} (x : Spin n) (i : Fin n) : ℝ := if x i then 1 else -1 + +def replace {n : ℕ} (x : Spin n) (i : Fin n) (b : Bool) : Spin n := + Function.update x i b + +noncomputable def halfDiff {n : ℕ} (i : Fin n) (f : Spin n → ℝ) + (x : Spin n) : ℝ := (f (replace x i true) - f (replace x i false)) / 2 + +noncomputable def field {n : ℕ} (J : Interaction n) (x : Spin n) (i : Fin n) : ℝ := + ∑ j, J i j * spin x j + +noncomputable def mean {n : ℕ} (J : Interaction n) (x : Spin n) (i : Fin n) : ℝ := + Real.tanh (field J x i) + +noncomputable def generator {n : ℕ} (J : Interaction n) (f : Spin n → ℝ) + (x : Spin n) : ℝ := ∑ j, (mean J x j - spin x j) * halfDiff j f x + +noncomputable def gradientGenerator {n : ℕ} (J : Interaction n) + (p : Spin n → Fin n → ℝ) (x : Spin n) (i : Fin n) : ℝ := + generator J (fun y => p y i) x - p x i - + 2 * spin x i * ∑ j, halfDiff i (fun y => mean J y j) x * + halfDiff j (fun y => p y i) x + + ∑ j, halfDiff i (fun y => mean J y j) x * p x j + +@[simp] theorem replace_same {n : ℕ} (x : Spin n) (i : Fin n) (b : Bool) : + replace x i b i = b := by + simp [replace] + +@[simp] theorem replace_replace {n : ℕ} (x : Spin n) (i : Fin n) (a b : Bool) : + replace (replace x i a) i b = replace x i b := by + simp [replace, Function.update_idem] + +@[simp] theorem replace_self {n : ℕ} (x : Spin n) (i : Fin n) : + replace x i (x i) = x := by + simp [replace] + +theorem replace_comm {n : ℕ} (x : Spin n) {i j : Fin n} (h : i ≠ j) + (a b : Bool) : replace (replace x i a) j b = replace (replace x j b) i a := by + exact Function.update_comm h a b x + +@[simp] theorem halfDiff_replace {n : ℕ} (i : Fin n) (f : Spin n → ℝ) + (x : Spin n) (b : Bool) : halfDiff i f (replace x i b) = halfDiff i f x := by + simp [halfDiff] + +@[simp] theorem halfDiff_self {n : ℕ} (i : Fin n) (f : Spin n → ℝ) + (x : Spin n) : halfDiff i (halfDiff i f) x = 0 := by + simp [halfDiff] + +theorem halfDiff_mul {n : ℕ} (i : Fin n) (f g : Spin n → ℝ) (x : Spin n) : + halfDiff i (fun y => f y * g y) x = + f x * halfDiff i g x + g x * halfDiff i f x - + 2 * spin x i * halfDiff i f x * halfDiff i g x := by + have hx : replace x i (x i) = x := replace_self x i + cases h : x i <;> simp only [h] at hx + · simp only [halfDiff, spin, h, Bool.false_eq_true, ↓reduceIte] + rw [hx] + ring + · simp only [halfDiff, spin, h, ↓reduceIte] + rw [hx] + ring + +theorem halfDiff_comm {n : ℕ} (i j : Fin n) (f : Spin n → ℝ) (x : Spin n) : + halfDiff i (halfDiff j f) x = halfDiff j (halfDiff i f) x := by + by_cases h : i = j + · subst j + rfl + · simp only [halfDiff] + rw [replace_comm x h true true, replace_comm x h true false, + replace_comm x h false true, replace_comm x h false false] + ring + +@[simp] theorem halfDiff_const {n : ℕ} (i : Fin n) (c : ℝ) (x : Spin n) : + halfDiff i (fun _ => c) x = 0 := by + simp [halfDiff] + +theorem halfDiff_sub {n : ℕ} (i : Fin n) (f g : Spin n → ℝ) (x : Spin n) : + halfDiff i (fun y => f y - g y) x = halfDiff i f x - halfDiff i g x := by + simp only [halfDiff] + ring + +theorem halfDiff_sum {n : ℕ} {α : Type*} [Fintype α] (i : Fin n) + (f : α → Spin n → ℝ) (x : Spin n) : + halfDiff i (fun y => ∑ a, f a y) x = ∑ a, halfDiff i (f a) x := by + simp only [halfDiff, sub_div, Finset.sum_sub_distrib, Finset.sum_div] + +@[simp] theorem halfDiff_spin {n : ℕ} (i j : Fin n) (x : Spin n) : + halfDiff i (fun y => spin y j) x = if i = j then 1 else 0 := by + by_cases h : i = j + · subst j + norm_num [halfDiff, spin] + · simp [halfDiff, spin, replace, Function.update_of_ne (Ne.symm h), h] + +theorem halfDiff_generator {n : ℕ} (J : Interaction n) (f : Spin n → ℝ) + (x : Spin n) (i : Fin n) : + halfDiff i (generator J f) x = + gradientGenerator J (fun y j => halfDiff j f y) x i := by + change halfDiff i (fun y => generator J f y) x = _ + unfold gradientGenerator + simp only [generator, halfDiff_sum, halfDiff_mul, halfDiff_sub, halfDiff_spin] + simp_rw [halfDiff_comm i] + simp only [mul_sub, sub_mul, Finset.sum_add_distrib, Finset.sum_sub_distrib] + simp only [mul_ite, mul_one, mul_zero, ite_mul, zero_mul, + Fintype.sum_ite_eq, halfDiff_self, sub_zero] + rw [Finset.mul_sum] + simp only [mul_assoc] + simp_rw [mul_comm (halfDiff _ f x)] + ring + +abbrev Observables (n : ℕ) := Spin n → ℝ +abbrev VectorFields (n : ℕ) := Spin n → Fin n → ℝ + +noncomputable def gradientLM (n : ℕ) : Observables n →ₗ[ℝ] VectorFields n where + toFun f x i := halfDiff i f x + map_add' f g := by + funext x i + simp only [halfDiff, Pi.add_apply] + ring + map_smul' a f := by + funext x i + simp only [halfDiff, Pi.smul_apply, smul_eq_mul, RingHom.id_apply] + ring + +noncomputable def generatorLM {n : ℕ} (J : Interaction n) : + Observables n →ₗ[ℝ] Observables n where + toFun := generator J + map_add' f g := by + funext x + simp only [generator] + change (∑ j, (mean J x j - spin x j) * + (gradientLM n (f + g) x j)) = _ + simp [map_add, gradientLM, generator, mul_add, Finset.sum_add_distrib] + map_smul' a f := by + funext x + simp only [generator] + change (∑ j, (mean J x j - spin x j) * + (gradientLM n (a • f) x j)) = _ + simp [map_smul, gradientLM, generator, mul_left_comm, Finset.mul_sum] + +noncomputable def gradientGeneratorLM {n : ℕ} (J : Interaction n) : + VectorFields n →ₗ[ℝ] VectorFields n where + toFun := gradientGenerator J + map_add' p q := by + funext x i + simp only [gradientGenerator, Pi.add_apply] + have h1 : (fun y => p y i + q y i) = + (fun y => p y i) + (fun y => q y i) := rfl + rw [h1] + change (generatorLM J ((fun y => p y i) + (fun y => q y i))) x - _ - + 2 * spin x i * (∑ j, halfDiff i (fun y => mean J y j) x * + gradientLM n ((fun y => p y i) + (fun y => q y i)) x j) + _ = _ + simp only [map_add, Pi.add_apply, mul_add, Finset.sum_add_distrib] + change generator J (fun y => p y i) x + generator J (fun y => q y i) x - _ - _ + _ = _ + simp only [gradientLM, LinearMap.coe_mk, AddHom.coe_mk] + ring + map_smul' a p := by + funext x i + simp only [gradientGenerator, Pi.smul_apply, smul_eq_mul, RingHom.id_apply] + have h1 : (fun y => a * p y i) = a • (fun y => p y i) := rfl + rw [h1] + change (generatorLM J (a • (fun y => p y i))) x - _ - + 2 * spin x i * (∑ j, halfDiff i (fun y => mean J y j) x * + gradientLM n (a • (fun y => p y i)) x j) + _ = _ + simp only [map_smul, Pi.smul_apply, smul_eq_mul] + simp only [gradientLM, generatorLM, LinearMap.coe_mk, AddHom.coe_mk] + simp_rw [mul_left_comm _ a, ← Finset.mul_sum] + ring + +noncomputable def gradientCLM (n : ℕ) : Observables n →L[ℝ] VectorFields n := + (gradientLM n).toContinuousLinearMap + +noncomputable def generatorCLM {n : ℕ} (J : Interaction n) : + Observables n →L[ℝ] Observables n := (generatorLM J).toContinuousLinearMap + +noncomputable def gradientGeneratorCLM {n : ℕ} (J : Interaction n) : + VectorFields n →L[ℝ] VectorFields n := + (gradientGeneratorLM J).toContinuousLinearMap + +noncomputable def semigroup {n : ℕ} (J : Interaction n) (t : ℝ) : + Observables n →L[ℝ] Observables n := NormedSpace.exp (t • generatorCLM J) + +noncomputable def gradientSemigroup {n : ℕ} (J : Interaction n) (t : ℝ) : + VectorFields n →L[ℝ] VectorFields n := + NormedSpace.exp (t • gradientGeneratorCLM J) + +theorem exp_intertwine {E F : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] + [CompleteSpace E] [NormedAddCommGroup F] [NormedSpace ℝ F] [CompleteSpace F] + (A : E →L[ℝ] E) (B : F →L[ℝ] F) (T : E →L[ℝ] F) + (h : ∀ x, T (A x) = B (T x)) (x : E) : + T (NormedSpace.exp A x) = NormedSpace.exp B (T x) := by + have hp (k : ℕ) (y : E) : T ((A ^ k) y) = (B ^ k) (T y) := by + induction k generalizing y with + | zero => simp + | succ k ih => + simp only [pow_succ', mul_apply_eq_comp, h, ih] + have hA : HasSum (fun k : ℕ => ((k.factorial : ℝ)⁻¹) • ((A ^ k) x)) + (NormedSpace.exp A x) := by + simpa only [NormedSpace.expSeries_apply_eq, ContinuousLinearMap.apply_apply, + smul_apply] using + (ContinuousLinearMap.apply ℝ E x).hasSum + (NormedSpace.expSeries_hasSum_exp (𝕂 := ℝ) A) + have hB : HasSum (fun k : ℕ => ((k.factorial : ℝ)⁻¹) • ((B ^ k) (T x))) + (NormedSpace.exp B (T x)) := by + simpa only [NormedSpace.expSeries_apply_eq, ContinuousLinearMap.apply_apply, + smul_apply] using + (ContinuousLinearMap.apply ℝ F (T x)).hasSum + (NormedSpace.expSeries_hasSum_exp (𝕂 := ℝ) B) + apply HasSum.unique _ hB + simpa only [map_smul, hp] using T.hasSum hA + +theorem halfDiff_semigroup {n : ℕ} (J : Interaction n) (t : ℝ) + (f : Observables n) (x : Spin n) (i : Fin n) : + halfDiff i (semigroup J t f) x = + gradientSemigroup J t (fun y j => halfDiff j f y) x i := by + have h (g : Observables n) : + gradientCLM n ((t • generatorCLM J) g) = + (t • gradientGeneratorCLM J) (gradientCLM n g) := by + rw [smul_apply, map_smul, smul_apply] + congr 1 + funext y j + exact halfDiff_generator J g y j + exact congrFun (congrFun + (exp_intertwine (t • generatorCLM J) (t • gradientGeneratorCLM J) + (gradientCLM n) h f) x) i + +noncomputable def energy {n : ℕ} (J : Interaction n) (x : Spin n) : ℝ := + (∑ i, ∑ j, spin x i * J i j * spin x j) / 2 + +noncomputable def partition {n : ℕ} (J : Interaction n) : ℝ := + ∑ x : Spin n, Real.exp (energy J x) + +noncomputable def gibbs {n : ℕ} (J : Interaction n) (x : Spin n) : ℝ := + Real.exp (energy J x) / partition J + +noncomputable def attemptLM {n : ℕ} (J : Interaction n) : + Observables n →L[ℝ] Observables n := + 1 + (n : ℝ)⁻¹ • generatorCLM J + +noncomputable def continuousKernel {n : ℕ} (J : Interaction n) (t : ℝ) + (x y : Spin n) : ℝ := semigroup J t (fun z => if z = y then 1 else 0) x + +noncomputable def discreteKernel {n : ℕ} (J : Interaction n) (k : ℕ) + (x y : Spin n) : ℝ := (attemptLM J ^ k) (fun z => if z = y then 1 else 0) x + +noncomputable def totalVariation {n : ℕ} (p q : Spin n → ℝ) : ℝ := + (∑ y, |p y - q y|) / 2 + +noncomputable def worstContinuous {n : ℕ} (J : Interaction n) (t : ℝ) : ℝ := + Finset.univ.sup' Finset.univ_nonempty + (fun x => totalVariation (continuousKernel J t x) (gibbs J)) + +noncomputable def worstDiscrete {n : ℕ} (J : Interaction n) (k : ℕ) : ℝ := + Finset.univ.sup' Finset.univ_nonempty + (fun x => totalVariation (discreteKernel J k x) (gibbs J)) + +abbrev GaussianCoordinates (n : ℕ) := (Fin n × Fin n) → ℝ + +noncomputable def disorderLaw (β : ℝ) (n : ℕ) : + MeasureTheory.Measure (GaussianCoordinates n) := + MeasureTheory.Measure.pi (fun _ => + ProbabilityTheory.gaussianReal 0 (Real.toNNReal (β ^ 2 / (n : ℝ)))) + +def sampledInteraction {n : ℕ} (g : GaussianCoordinates n) : Interaction n := + fun i j => if i = j then 0 else g (min i j, max i j) + +noncomputable def cutoffTime (rate : ℝ) (n : ℕ) : ℝ := Real.log (n : ℝ) / (2 * rate) + +def DisorderLimit (β : ℝ) (F : (n : ℕ) → Interaction n → ℝ) (a : ℝ) : Prop := + ∀ δ : ℝ, 0 < δ → + Filter.Tendsto (fun n => (disorderLaw β n) + {g | δ < |F n (sampledInteraction g) - a|}) + Filter.atTop (nhds 0) + +def CutoffAtRate (β rate : ℝ) : Prop := + ∀ ε : ℝ, 0 < ε → ε < 1 → + DisorderLimit β (fun n J => worstContinuous J ((1 - ε) * cutoffTime rate n)) 1 ∧ + DisorderLimit β (fun n J => worstContinuous J ((1 + ε) * cutoffTime rate n)) 0 ∧ + DisorderLimit β (fun n J => worstDiscrete J + ⌊(1 - ε) * (n : ℝ) * cutoffTime rate n⌋₊) 1 ∧ + DisorderLimit β (fun n J => worstDiscrete J + ⌈(1 + ε) * (n : ℝ) * cutoffTime rate n⌉₊) 0 + +@[simp] theorem sampledInteraction_diag {n : ℕ} (g : GaussianCoordinates n) (i : Fin n) : + sampledInteraction g i i = 0 := by simp [sampledInteraction] + +theorem sampledInteraction_symm {n : ℕ} (g : GaussianCoordinates n) (i j : Fin n) : + sampledInteraction g i j = sampledInteraction g j i := by + by_cases h : i = j + · subst j; rfl + · simp [sampledInteraction, h, Ne.symm h, min_comm, max_comm] + +theorem partition_pos {n : ℕ} (J : Interaction n) : 0 < partition J := by + exact Finset.sum_pos (fun _ _ => Real.exp_pos _) Finset.univ_nonempty + +theorem gibbs_pos {n : ℕ} (J : Interaction n) (x : Spin n) : 0 < gibbs J x := + div_pos (Real.exp_pos _) (partition_pos J) + +theorem gibbs_sum {n : ℕ} (J : Interaction n) : ∑ x : Spin n, gibbs J x = 1 := by + simp only [gibbs, ← Finset.sum_div] + exact div_self (ne_of_gt (partition_pos J)) + +noncomputable def siteRefresh {n : ℕ} (J : Interaction n) (i : Fin n) + (f : Observables n) (x : Spin n) : ℝ := + ((1 + mean J x i) / 2) * f (replace x i true) + + ((1 - mean J x i) / 2) * f (replace x i false) + +theorem generator_siteRefresh {n : ℕ} (J : Interaction n) (f : Observables n) + (x : Spin n) : generator J f x = ∑ i, (siteRefresh J i f x - f x) := by + apply Finset.sum_congr rfl + intro i _ + have hx : replace x i (x i) = x := replace_self x i + cases hi : x i <;> simp only [hi] at hx + · simp only [halfDiff, spin, hi, Bool.false_eq_true, ↓reduceIte, siteRefresh] + rw [hx] + ring + · simp only [halfDiff, spin, hi, ↓reduceIte, siteRefresh] + rw [hx] + ring + +theorem attempt_apply_of_pos {n : ℕ} (hn : 0 < n) (J : Interaction n) + (f : Observables n) (x : Spin n) : + attemptLM J f x = (∑ i, siteRefresh J i f x) / (n : ℝ) := by + have hn' : (n : ℝ) ≠ 0 := by exact_mod_cast ne_of_gt hn + change f x + (n : ℝ)⁻¹ * generator J f x = _ + rw [generator_siteRefresh, Finset.sum_sub_distrib] + simp only [Finset.sum_const, Finset.card_univ, Fintype.card_fin, nsmul_eq_mul] + field_simp + ring + +@[simp] theorem generator_const {n : ℕ} (J : Interaction n) (a : ℝ) (x : Spin n) : + generator J (fun _ => a) x = 0 := by + simp [generator] + +@[simp] theorem siteRefresh_const {n : ℕ} (J : Interaction n) (i : Fin n) + (a : ℝ) (x : Spin n) : siteRefresh J i (fun _ => a) x = a := by + unfold siteRefresh + ring + +@[simp] theorem attempt_const {n : ℕ} (J : Interaction n) (a : ℝ) : + attemptLM J (fun _ => a) = fun _ => a := by + funext x + change a + (n : ℝ)⁻¹ * generator J (fun _ => a) x = a + simp + +@[simp] theorem attempt_pow_const {n : ℕ} (J : Interaction n) (k : ℕ) (a : ℝ) : + (attemptLM J ^ k) (fun _ => a) = fun _ => a := by + induction k with + | zero => simp + | succ k ih => simp only [pow_succ', mul_apply_eq_comp, ih, attempt_const] + +theorem siteRefresh_nonneg {n : ℕ} (J : Interaction n) (i : Fin n) + (f : Observables n) (hf : ∀ x, 0 ≤ f x) (x : Spin n) : + 0 ≤ siteRefresh J i f x := by + have hm1 : -1 ≤ mean J x i := le_of_lt (Real.neg_one_lt_tanh _) + have hm2 : mean J x i ≤ 1 := le_of_lt (Real.tanh_lt_one _) + exact add_nonneg (mul_nonneg (by linarith) (hf _)) + (mul_nonneg (by linarith) (hf _)) + +theorem attempt_nonneg {n : ℕ} (J : Interaction n) (f : Observables n) + (hf : ∀ x, 0 ≤ f x) (x : Spin n) : 0 ≤ attemptLM J f x := by + by_cases hn : n = 0 + · subst n + simpa [attemptLM] using hf x + · rw [attempt_apply_of_pos (Nat.pos_of_ne_zero hn)] + exact div_nonneg (Finset.sum_nonneg (fun _ _ => siteRefresh_nonneg J _ f hf x)) + (Nat.cast_nonneg n) + +theorem attempt_pow_nonneg {n : ℕ} (J : Interaction n) (k : ℕ) (f : Observables n) + (hf : ∀ x, 0 ≤ f x) (x : Spin n) : 0 ≤ (attemptLM J ^ k) f x := by + induction k generalizing x with + | zero => simpa using hf x + | succ k ih => + simp only [pow_succ', mul_apply_eq_comp] + exact attempt_nonneg J _ ih x + +theorem discreteKernel_nonneg {n : ℕ} (J : Interaction n) (k : ℕ) + (x y : Spin n) : 0 ≤ discreteKernel J k x y := by + exact attempt_pow_nonneg J k _ (fun _ => by split_ifs <;> norm_num) x + +theorem discreteKernel_sum {n : ℕ} (J : Interaction n) (k : ℕ) (x : Spin n) : + ∑ y, discreteKernel J k x y = 1 := by + have eq_one : (∑ y : Spin n, fun z => if z = y then (1 : ℝ) else 0) = + fun _ : Spin n => (1 : ℝ) := by + funext z + simp + unfold discreteKernel + rw [← Finset.sum_apply, ← map_sum, eq_one, attempt_pow_const] + +end SKGapCutoff +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Terminal/SpinChebyshev.lean b/lean/OAI/Probability/SKGap/Terminal/SpinChebyshev.lean new file mode 100644 index 0000000000000000000000000000000000000000..9dcac7e02120e2229db0ec757020311a40ac071a --- /dev/null +++ b/lean/OAI/Probability/SKGap/Terminal/SpinChebyshev.lean @@ -0,0 +1,500 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.ResidualRecipe +import OAI.Probability.SKGap.Localization.SemicircleDensity + +namespace OAI + +section +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open scoped BigOperators +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open scoped BigOperators +open scoped BigOperators NNReal ENNReal +open MeasureTheory Metric Set +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators NNReal ENNReal Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Set +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators ENNReal NNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Matrix +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators ENNReal NNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal +open scoped BigOperators +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise NNReal ENNReal +open scoped BigOperators +open Filter Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal Topology +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Set Matrix +open scoped BigOperators NNReal ENNReal Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open Filter MeasureTheory ProbabilityTheory +open scoped Topology NNReal ENNReal +open Filter MeasureTheory ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter +open scoped Topology NNReal ENNReal +open MeasureTheory Filter ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter +open scoped Topology +open MeasureTheory Filter ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter ProbabilityTheory ContinuousLinearMap +open scoped Topology NNReal ENNReal +open Filter MeasureTheory ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter +open scoped BigOperators Topology +open MeasureTheory Filter +open scoped BigOperators Topology +open MeasureTheory Filter +open scoped BigOperators Topology +open MeasureTheory Filter +open scoped BigOperators Topology +open MeasureTheory Filter +open scoped BigOperators Topology +open Filter Set Metric +open scoped Topology RealInnerProductSpace +open scoped BigOperators +open ContinuousLinearMap +open scoped BigOperators +open ContinuousLinearMap +open scoped Topology Interval +open MeasureTheory +open MeasureTheory +open scoped BigOperators Topology Interval +open MeasureTheory +open scoped BigOperators Topology Interval +open scoped Topology +open MeasureTheory +open scoped BigOperators Topology Interval +open scoped BigOperators Topology +open MeasureTheory +open scoped BigOperators Topology Interval RealInnerProductSpace +open MeasureTheory Filter +open scoped BigOperators Topology Interval +open MeasureTheory Filter +open scoped Topology +open MeasureTheory Filter +open scoped Topology +namespace SKGapCutoff + +noncomputable def spinChebyshev (k : ℕ) : Polynomial ℝ := + Polynomial.Chebyshev.S ℝ (k:ℤ) + +lemma spinChebyshev_zero : spinChebyshev 0=1 := by simp [spinChebyshev] +lemma spinChebyshev_one : spinChebyshev 1=Polynomial.X := by simp [spinChebyshev] +lemma spinChebyshev_recurrence (k : ℕ) : + spinChebyshev (k+2)=Polynomial.X*spinChebyshev (k+1)-spinChebyshev k := by + simp [spinChebyshev, Polynomial.Chebyshev.S_add_two] + +lemma spinChebyshev_cos (k : ℕ) (θ : ℝ) : + (spinChebyshev k).eval (2*Real.cos θ)*Real.sin θ=Real.sin (((k:ℝ)+1)*θ) := by + have he := congrArg (fun p : Polynomial ℝ => p.eval (Real.cos θ)) + (Polynomial.Chebyshev.S_comp_two_mul_X ℝ (k:ℤ)) + simp only [Polynomial.eval_comp,Polynomial.eval_mul,Polynomial.eval_ofNat, + Polynomial.eval_X] at he + rw [spinChebyshev,he,Polynomial.Chebyshev.U_real_cos] + simp + +lemma abs_sin_nat_mul_le (k : ℕ) (θ : ℝ) : + |Real.sin ((k:ℝ)*θ)| ≤ (k:ℝ)*|Real.sin θ| := by + induction k with + | zero => simp + | succ k ih => + simp only [Nat.cast_add,Nat.cast_one,add_mul,one_mul,Real.sin_add] + calc + _ ≤ |Real.sin ((k:ℝ)*θ)*Real.cos θ|+|Real.cos ((k:ℝ)*θ)*Real.sin θ| := abs_add_le _ _ + _ ≤ |Real.sin ((k:ℝ)*θ)|+|Real.sin θ| := by + rw [abs_mul,abs_mul] + calc + _ ≤ |Real.sin ((k:ℝ)*θ)| * 1+1 * |Real.sin θ| := + add_le_add (mul_le_mul_of_nonneg_left (Real.abs_cos_le_one θ) (abs_nonneg _)) + (mul_le_mul_of_nonneg_right (Real.abs_cos_le_one _) (abs_nonneg _)) + _ = _ := by ring + _ ≤ (k:ℝ)*|Real.sin θ|+|Real.sin θ| := by gcongr + +lemma spinChebyshev_abs_le (k : ℕ) {u : ℝ} (hu : u ∈ Set.Icc (-2:ℝ) 2) : + |(spinChebyshev k).eval u| ≤ (k:ℝ)+1 := by + have hi : Set.Ioo (-2:ℝ) 2 ⊆ {v : ℝ | |(spinChebyshev k).eval v| ≤ (k:ℝ)+1} := by + intro v hv + have hlo : -1 < v/2 := by linarith [hv.1] + have hhi : v/2 < 1 := by linarith [hv.2] + have hs : 0 < Real.sin (Real.arccos (v/2)) := + Real.sin_pos_of_pos_of_lt_pi (Real.arccos_pos.mpr hhi) (Real.arccos_lt_pi.mpr hlo) + have he := spinChebyshev_cos k (Real.arccos (v/2)) + rw [Real.cos_arccos hlo.le hhi.le] at he + have hc : 2*(v/2)=v := by ring + rw [hc] at he + have hh := abs_sin_nat_mul_le (k+1) (Real.arccos (v/2)) + simp only [Nat.cast_add,Nat.cast_one,← he,abs_mul,abs_of_pos hs] at hh + exact le_of_mul_le_mul_right hh hs + have hc := closure_mono hi + rw [closure_Ioo (by norm_num : (-2:ℝ) ≠ 2)] at hc + have hclosed : IsClosed {v : ℝ | |(spinChebyshev k).eval v| ≤ (k:ℝ)+1} := + isClosed_le (spinChebyshev k).continuous.abs continuous_const + rw [hclosed.closure_eq] at hc + exact hc hu + +lemma spinChebyshev_series_majorant {β : ℝ} (hβ : |β|<1) : + Summable (fun k : ℕ => ((k:ℝ)+1)*|β|^k) := by + have hh : ‖|β|‖<1 := by simpa using hβ + have hs := (hasSum_coe_mul_geometric_of_norm_lt_one hh).summable.add + (summable_geometric_of_norm_lt_one hh) + simpa only [add_mul,one_mul] using hs + +lemma spinChebyshev_term_bound (β : ℝ) (k : ℕ) {u : ℝ} + (hu : u ∈ Set.Icc (-2:ℝ) 2) : + ‖β^k*(spinChebyshev k).eval u‖ ≤ ((k:ℝ)+1)*|β|^k := by + rw [Real.norm_eq_abs,abs_mul,abs_pow,mul_comm] + exact mul_le_mul_of_nonneg_right (spinChebyshev_abs_le k hu) (pow_nonneg (abs_nonneg β) _) + +lemma spinChebyshev_series_summable {β u : ℝ} (hβ : |β|<1) + (hu : u ∈ Set.Icc (-2:ℝ) 2) : + Summable (fun k : ℕ => β^k*(spinChebyshev k).eval u) := by + exact Summable.of_norm_bounded (spinChebyshev_series_majorant hβ) + (fun k => spinChebyshev_term_bound β k hu) + +lemma spinChebyshev_series_uniform {β : ℝ} (hβ : |β|<1) : + TendstoUniformlyOn + (fun N u => ∑ k ∈ Finset.range N, β^k*(spinChebyshev k).eval u) + (fun u => ∑' k : ℕ, β^k*(spinChebyshev k).eval u) + atTop (Set.Icc (-2:ℝ) 2) := by + exact tendstoUniformlyOn_tsum_nat (spinChebyshev_series_majorant hβ) + (fun k _ hu => spinChebyshev_term_bound β k hu) + +lemma spinChebyshev_generating_series {β u : ℝ} (hβ : |β|<1) + (hu : u ∈ Set.Icc (-2:ℝ) 2) : + (∑' k : ℕ, β^k*(spinChebyshev k).eval u) = (1-β*u+β^2)⁻¹ := by + let f : ℕ → ℝ := fun k => β^k*(spinChebyshev k).eval u + have hs : Summable f := spinChebyshev_series_summable hβ hu + have hs1 : Summable (fun k => f (k+1)) := (summable_nat_add_iff 1).mpr hs + have hrec (k : ℕ) : f (k+2)=β*u*f (k+1)-β^2*f k := by + simp only [f,spinChebyshev_recurrence,Polynomial.eval_sub,Polynomial.eval_mul, + Polynomial.eval_X,pow_add,pow_one] + ring + have ht : (∑' k, f (k+2))=β*u*(∑' k, f (k+1))-β^2*(∑' k, f k) := by + simp_rw [hrec] + rw [(hs1.mul_left (β*u)).tsum_sub (hs.mul_left (β^2)),tsum_mul_left,tsum_mul_left] + have h0 := hs.sum_add_tsum_nat_add 1 + have h2 := hs.sum_add_tsum_nat_add 2 + have hf0 : f 0=1 := by simp [f,spinChebyshev_zero] + have hf1 : f 1=β*u := by simp [f,spinChebyshev_one] + simp only [Finset.sum_range_succ,Finset.sum_range_zero,hf0,hf1,zero_add] at h0 h2 + have hm : (1-β*u+β^2)*(∑' k, f k)=1 := by + linear_combination -h2 + ht + (β*u)*h0 + have hn : 1-β*u+β^2 ≠ 0 := by + intro hz + rw [hz,zero_mul] at hm + norm_num at hm + apply (mul_left_cancel₀ hn) + change (1-β*u+β^2)*(∑' k, f k)=(1-β*u+β^2)*(1-β*u+β^2)⁻¹ + rw [hm,mul_inv_cancel₀ hn] + +lemma semicircle_integral (f : ℝ → ℝ) : + (∫ u, f u ∂semicircleMeasure)=∫ u in (-2:ℝ)..2, semicircleDensity u*f u := by + have hn (u : ℝ) : 0 ≤ semicircleDensity u := + div_nonneg (Real.sqrt_nonneg _) (mul_pos (by norm_num) Real.pi_pos).le + rw [semicircleMeasure,integral_withDensity_eq_integral_toReal_smul] + · simp only [ENNReal.toReal_ofReal (hn _),smul_eq_mul] + rw [← setIntegral_eq_integral_of_forall_compl_eq_zero + (s := Set.Icc (-2:ℝ) 2) (fun u hu => by rw [semicircleDensity_eq_zero_outside u hu,zero_mul])] + rw [integral_Icc_eq_integral_Ioc,intervalIntegral.integral_of_le (by norm_num : (-2:ℝ) ≤ 2)] + · exact ENNReal.measurable_ofReal.comp semicircleDensity_continuous.measurable + · exact Eventually.of_forall (fun _ => ENNReal.ofReal_lt_top) + +lemma semicircleDensity_two_cos {θ : ℝ} (hθ : θ ∈ Set.Icc 0 Real.pi) : + semicircleDensity (2*Real.cos θ)=Real.sin θ/Real.pi := by + have he : 4-(2*Real.cos θ)^2=(2*Real.sin θ)^2 := by + nlinarith only [Real.sin_sq_add_cos_sq θ] + rw [semicircleDensity,he,Real.sqrt_sq (mul_nonneg (by norm_num) + (Real.sin_nonneg_of_nonneg_of_le_pi hθ.1 hθ.2))] + ring + +lemma semicircle_integral_angular {f : ℝ → ℝ} (hf : Continuous f) : + (∫ u, f u ∂semicircleMeasure)= + (2/Real.pi)*∫ θ in 0..Real.pi, f (2*Real.cos θ)*(Real.sin θ)^2 := by + have hh := intervalIntegral.integral_comp_mul_deriv + (a := 0) (b := Real.pi) (f := fun θ => 2*Real.cos θ) + (f' := fun θ => -2*Real.sin θ) + (g := fun u => semicircleDensity u*f u) + (fun θ _ => by simpa only [mul_neg,neg_mul] using (Real.hasDerivAt_cos θ).const_mul 2) + (by fun_prop) (semicircleDensity_continuous.mul hf) + have he : (∫ θ in 0..Real.pi, + (fun u => semicircleDensity u*f u) (2*Real.cos θ)*(-2*Real.sin θ))= + (-2/Real.pi)*(∫ θ in 0..Real.pi, f (2*Real.cos θ)*(Real.sin θ)^2) := by + rw [← intervalIntegral.integral_const_mul] + apply intervalIntegral.integral_congr + intro θ hθ + rw [Set.uIcc_of_le Real.pi_pos.le] at hθ + change semicircleDensity (2*Real.cos θ)*f (2*Real.cos θ)*(-2*Real.sin θ)=_ + rw [semicircleDensity_two_cos hθ] + ring + change (∫ θ in 0..Real.pi, + (fun u => semicircleDensity u*f u) (2*Real.cos θ)*(-2*Real.sin θ))=_ at hh + rw [he] at hh + simp only [Real.cos_zero,Real.cos_pi,mul_one,mul_neg_one] at hh + rw [intervalIntegral.integral_symm (a := (-2:ℝ)) (b := 2)] at hh + rw [semicircle_integral] + linear_combination hh + +lemma integral_cos_integer_frequency (z : ℤ) (hz : z ≠ 0) : + (∫ θ in 0..Real.pi, Real.cos ((z:ℝ)*θ))=0 := by + have hh := Polynomial.Chebyshev.integral_eval_T_real_measureT_of_ne_zero hz + rw [Polynomial.Chebyshev.integral_measureT_eq_integral_cos] at hh + simpa only [Polynomial.Chebyshev.T_real_cos] using hh + +lemma integral_sin_nat_frequencies (k l : ℕ) : + (∫ θ in 0..Real.pi, Real.sin (((k:ℝ)+1)*θ)*Real.sin (((l:ℝ)+1)*θ))= + if k=l then Real.pi/2 else 0 := by + have he (θ : ℝ) : + Real.sin (((k:ℝ)+1)*θ)*Real.sin (((l:ℝ)+1)*θ)= + (Real.cos (((k:ℝ)-(l:ℝ))*θ)-Real.cos (((k:ℝ)+(l:ℝ)+2)*θ))/2 := by + have hh := Real.two_mul_sin_mul_sin (((k:ℝ)+1)*θ) (((l:ℝ)+1)*θ) + have hs : ((k:ℝ)+1)*θ-((l:ℝ)+1)*θ=((k:ℝ)-(l:ℝ))*θ := by ring + have ha : ((k:ℝ)+1)*θ+((l:ℝ)+1)*θ=((k:ℝ)+(l:ℝ)+2)*θ := by ring + rw [hs,ha] at hh + linear_combination hh / 2 + have h1 : (∫ θ in 0..Real.pi, Real.cos (((k:ℝ)-(l:ℝ))*θ))= + if k=l then Real.pi else 0 := by + by_cases h : k=l + · subst l + simp + · rw [ite_eq_right h] + have hz : (k:ℤ)-(l:ℤ) ≠ 0 := sub_ne_zero.mpr (by exact_mod_cast h) + simpa only [Int.cast_sub,Int.cast_natCast] using integral_cos_integer_frequency _ hz + have h2 : (∫ θ in 0..Real.pi, Real.cos (((k:ℝ)+(l:ℝ)+2)*θ))=0 := by + have hz : (k:ℤ)+(l:ℤ)+2 ≠ 0 := by omega + simpa only [Int.cast_add,Int.cast_natCast,Int.cast_ofNat] using integral_cos_integer_frequency _ hz + simp_rw [he] + rw [intervalIntegral.integral_div,intervalIntegral.integral_sub + (by apply Continuous.intervalIntegrable; fun_prop) + (by apply Continuous.intervalIntegrable; fun_prop),h1,h2,sub_zero] + split_ifs <;> simp + +theorem spinChebyshev_orthonormal (k l : ℕ) : + (∫ u, (spinChebyshev k).eval u*(spinChebyshev l).eval u ∂semicircleMeasure)= + if k=l then 1 else 0 := by + rw [semicircle_integral_angular (f := fun u => (spinChebyshev k).eval u*(spinChebyshev l).eval u) + (by fun_prop)] + have he (θ : ℝ) : + ((spinChebyshev k).eval (2*Real.cos θ)*(spinChebyshev l).eval (2*Real.cos θ))* + (Real.sin θ)^2 = + Real.sin (((k:ℝ)+1)*θ)*Real.sin (((l:ℝ)+1)*θ) := by + rw [← spinChebyshev_cos,← spinChebyshev_cos] + ring + simp_rw [he] + rw [integral_sin_nat_frequencies] + split_ifs + · field_simp + · simp + +lemma semicircle_ae_mem : ∀ᵐ u ∂semicircleMeasure, u ∈ Set.Icc (-2:ℝ) 2 := by + apply (ae_withDensity_iff (ENNReal.measurable_ofReal.comp semicircleDensity_continuous.measurable)).mpr + exact Eventually.of_forall (fun u hu => by + by_contra h + exact hu (by change ENNReal.ofReal (semicircleDensity u) = 0 + rw [semicircleDensity_eq_zero_outside u h,ENNReal.ofReal_zero])) + +theorem spinCovariance_density_moment {β : ℝ} (hβ : |β|<1) (m : ℕ) : + (∫ u, (spinChebyshev m).eval u/(1-β*u+β^2) ∂semicircleMeasure)=β^m := by + let F : ℕ → ℝ → ℝ := fun k u => + (spinChebyshev m).eval u*(β^k*(spinChebyshev k).eval u) + have hm (k : ℕ) : AEStronglyMeasurable (F k) semicircleMeasure := by + apply Continuous.aestronglyMeasurable + dsimp [F] + fun_prop + have hb (k : ℕ) : ∀ᵐ u ∂semicircleMeasure, + ‖F k u‖ ≤ ((m:ℝ)+1)*(((k:ℝ)+1)*|β|^k) := by + filter_upwards [semicircle_ae_mem] with u hu + dsimp [F] + rw [abs_mul] + exact mul_le_mul (spinChebyshev_abs_le m hu) (spinChebyshev_term_bound β k hu) + (abs_nonneg _) (by positivity) + have hs := (spinChebyshev_series_majorant hβ).mul_left ((m:ℝ)+1) + have hl : ∀ᵐ u ∂semicircleMeasure, + HasSum (fun k => F k u) ((spinChebyshev m).eval u/(1-β*u+β^2)) := by + filter_upwards [semicircle_ae_mem] with u hu + have hh := (spinChebyshev_series_summable hβ hu).hasSum.mul_left ((spinChebyshev m).eval u) + rw [spinChebyshev_generating_series hβ hu] at hh + exact hh + have hh := hasSum_integral_of_dominated_convergence + (μ := semicircleMeasure) (F := F) + (fun k _ => ((m:ℝ)+1)*(((k:ℝ)+1)*|β|^k)) hm hb + (Eventually.of_forall fun _ => hs) (integrable_const _) hl + have hi (k : ℕ) : (∫ u, F k u ∂semicircleMeasure)=if m=k then β^k else 0 := by + have he (u : ℝ) : F k u=β^k*((spinChebyshev m).eval u*(spinChebyshev k).eval u) := by + dsimp [F] + ring + simp_rw [he] + rw [integral_const_mul,spinChebyshev_orthonormal] + split_ifs <;> simp + rw [← hh.tsum_eq] + simp_rw [hi] + simp + +lemma spinChebyshev_degree (k : ℕ) : (spinChebyshev k).degree=k := by + induction k using Nat.twoStepInduction with + | zero => simp [spinChebyshev_zero] + | one => simp [spinChebyshev_one] + | more k ih₀ ih₁ => + have hd : (Polynomial.X*spinChebyshev (k+1)).degree=↑(k+2) := by + rw [mul_comm,Polynomial.degree_mul_X,ih₁] + norm_cast + rw [spinChebyshev_recurrence,Polynomial.degree_sub_eq_left_of_degree_lt] + · exact hd + · rw [ih₀,hd] + norm_cast + omega + +lemma spinChebyshev_leadingCoeff (k : ℕ) : (spinChebyshev k).leadingCoeff=1 := by + induction k using Nat.twoStepInduction with + | zero => simp [spinChebyshev_zero] + | one => simp [spinChebyshev_one] + | more k _ ih => + rw [spinChebyshev_recurrence,Polynomial.leadingCoeff_sub_of_degree_lt] + · rw [Polynomial.leadingCoeff_mul,Polynomial.leadingCoeff_X,ih,one_mul] + · rw [mul_comm,Polynomial.degree_mul_X,spinChebyshev_degree,spinChebyshev_degree] + norm_cast + omega + +lemma spinChebyshev_span : Submodule.span ℝ (Set.range spinChebyshev)=⊤ := by + let S : Polynomial.Sequence ℝ := ⟨spinChebyshev,spinChebyshev_degree⟩ + exact S.span (fun k => by + change IsUnit (spinChebyshev k).leadingCoeff + rw [spinChebyshev_leadingCoeff] + exact isUnit_one) + +lemma integrable_of_continuousOn_semicircle_support {μ : Measure ℝ} [IsFiniteMeasure μ] + (hμ : ∀ᵐ u ∂μ, u ∈ Set.Icc (-2:ℝ) 2) {f : ℝ → ℝ} + (hf : ContinuousOn f (Set.Icc (-2:ℝ) 2)) : Integrable f μ := by + have hi := hf.integrableOn_compact (μ := μ) isCompact_Icc + rwa [IntegrableOn,Measure.restrict_eq_self_of_ae_mem hμ] at hi + +lemma integrable_spinCovariance_polynomial {β : ℝ} (hβ0 : 0 ≤ β) (hβ1 : β<1) + (p : Polynomial ℝ) : Integrable (fun u => p.eval u/(1-β*u+β^2)) semicircleMeasure := by + apply integrable_of_continuousOn_semicircle_support semicircle_ae_mem + apply p.continuous.continuousOn.div (by fun_prop) + exact fun u hu => ne_of_gt (spinCovariance_denominator_pos hβ0 hβ1 hu) + +theorem spinCovariance_polynomial_of_moments {β : ℝ} (hβ0 : 0 ≤ β) (hβ1 : β<1) + {μ : Measure ℝ} [IsFiniteMeasure μ] + (hμ : ∀ᵐ u ∂μ, u ∈ Set.Icc (-2:ℝ) 2) + (hm : ∀ k : ℕ, (∫ u, (spinChebyshev k).eval u ∂μ)=β^k) (p : Polynomial ℝ) : + (∫ u, p.eval u ∂μ)=(∫ u, p.eval u/(1-β*u+β^2) ∂semicircleMeasure) := by + have hp : p ∈ Submodule.span ℝ (Set.range spinChebyshev) := by rw [spinChebyshev_span]; trivial + have hi (p : Polynomial ℝ) : Integrable (fun u => p.eval u) μ := + integrable_of_continuousOn_semicircle_support hμ p.continuous.continuousOn + induction hp using Submodule.span_induction with + | mem p hp => + obtain ⟨k,rfl⟩ := hp + rw [hm,spinCovariance_density_moment (by rwa [abs_of_nonneg hβ0])] + | zero => simp + | add p q _ _ hp hq => + simp only [Polynomial.eval_add,add_div] + rw [integral_add (hi p) (hi q), + integral_add (integrable_spinCovariance_polynomial hβ0 hβ1 p) + (integrable_spinCovariance_polynomial hβ0 hβ1 q),hp,hq] + | smul c p _ hp => + simp only [Polynomial.eval_smul,smul_eq_mul,mul_div_assoc, + integral_const_mul,hp] + +end SKGapCutoff + +open MeasureTheory Filter +open scoped Topology + +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Terminal/SpinCovarianceMeasure.lean b/lean/OAI/Probability/SKGap/Terminal/SpinCovarianceMeasure.lean new file mode 100644 index 0000000000000000000000000000000000000000..61516bd28c3c6dfeb2e17df00e9c9e2e636d0547 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Terminal/SpinCovarianceMeasure.lean @@ -0,0 +1,450 @@ +import Mathlib +import OAI.Probability.SKGap.Stability.PlantedFieldCenter +import OAI.Probability.SKGap.Terminal.GibbsEventProbability +import OAI.Probability.SKGap.Terminal.SpinChebyshev + +namespace OAI + +section +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open scoped BigOperators +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open scoped BigOperators +open scoped BigOperators NNReal ENNReal +open MeasureTheory Metric Set +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators NNReal ENNReal Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Set +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators ENNReal NNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Matrix +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators ENNReal NNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal +open scoped BigOperators +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise NNReal ENNReal +open scoped BigOperators +open Filter Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal Topology +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Set Matrix +open scoped BigOperators NNReal ENNReal Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open Filter MeasureTheory ProbabilityTheory +open scoped Topology NNReal ENNReal +open Filter MeasureTheory ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter +open scoped Topology NNReal ENNReal +open MeasureTheory Filter ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter +open scoped Topology +open MeasureTheory Filter ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter ProbabilityTheory ContinuousLinearMap +open scoped Topology NNReal ENNReal +open Filter MeasureTheory ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter +open scoped BigOperators Topology +open MeasureTheory Filter +open scoped BigOperators Topology +open MeasureTheory Filter +open scoped BigOperators Topology +open MeasureTheory Filter +open scoped BigOperators Topology +open MeasureTheory Filter +open scoped BigOperators Topology +open Filter Set Metric +open scoped Topology RealInnerProductSpace +open scoped BigOperators +open ContinuousLinearMap +open scoped BigOperators +open ContinuousLinearMap +open scoped Topology Interval +open MeasureTheory +open MeasureTheory +open scoped BigOperators Topology Interval +open MeasureTheory +open scoped BigOperators Topology Interval +open scoped Topology +open MeasureTheory +open scoped BigOperators Topology Interval +open scoped BigOperators Topology +open MeasureTheory +open scoped BigOperators Topology Interval RealInnerProductSpace +open MeasureTheory Filter +open scoped BigOperators Topology Interval +open MeasureTheory Filter +open scoped Topology +open MeasureTheory Filter +open scoped Topology +open MeasureTheory Filter +open scoped Topology +namespace SKGapCutoff + +lemma polynomial_approximation_semicircle_support {f : ℝ → ℝ} (hf : Continuous f) + {ε : ℝ} (hε : 0 < ε) : ∃ p : Polynomial ℝ, + ∀ u ∈ Set.Icc (-2:ℝ) 2, |f u-p.eval u|<ε := by + let K := Set.Icc (-2:ℝ) 2 + let F : C(K,ℝ) := ⟨fun u => f u.1,hf.comp continuous_subtype_val⟩ + have hF : F ∈ closure (polynomialFunctions K : Set C(K,ℝ)) := by + rw [← Subalgebra.topologicalClosure_coe,polynomialFunctions.topologicalClosure] + trivial + obtain ⟨g,hg,hfg⟩ := Metric.mem_closure_iff.mp hF ε hε + rw [polynomialFunctions_coe] at hg + obtain ⟨p,rfl⟩ := hg + refine ⟨p,fun u hu => ?_⟩ + have hh := ContinuousMap.dist_apply_le_dist + (f := F) (g := Polynomial.toContinuousMapOnAlgHom K p) ⟨u,hu⟩ + exact lt_of_le_of_lt (by simpa [F,Real.dist_eq] using hh) hfg + +lemma semicircle_support_measure_ext {μ ν : Measure ℝ} + [IsProbabilityMeasure μ] [IsProbabilityMeasure ν] + (hμ : ∀ᵐ u ∂μ, u ∈ Set.Icc (-2:ℝ) 2) + (hν : ∀ᵐ u ∂ν, u ∈ Set.Icc (-2:ℝ) 2) + (hp : ∀ p : Polynomial ℝ, (∫ u, p.eval u ∂μ)=(∫ u, p.eval u ∂ν)) : μ=ν := by + apply Measure.ext_of_integral_eq_on_compactlySupported + intro f + apply sub_eq_zero.mp + apply abs_eq_zero.mp + apply le_antisymm _ (abs_nonneg _) + apply le_of_forall_pos_le_add + intro ε hε + obtain ⟨p,hpapprox⟩ := polynomial_approximation_semicircle_support f.continuous + (half_pos hε) + have hb {ρ : Measure ℝ} [IsProbabilityMeasure ρ] + (hρ : ∀ᵐ u ∂ρ, u ∈ Set.Icc (-2:ℝ) 2) : + |(∫ u, f u ∂ρ)-(∫ u, p.eval u ∂ρ)| ≤ ε/2 := by + have hfi : Integrable (fun u => f u) ρ := by + apply integrable_of_continuousOn_semicircle_support hρ + exact f.continuous.continuousOn + rw [← integral_sub hfi + (integrable_of_continuousOn_semicircle_support hρ p.continuous.continuousOn)] + have hh := norm_integral_le_of_norm_le_const (μ := ρ) (C := ε/2) + (f := fun u => f u-p.eval u) + (by filter_upwards [hρ] with u hu; exact (hpapprox u hu).le) + simpa only [Real.norm_eq_abs,measureReal_def,measure_univ,ENNReal.toReal_one,mul_one] using hh + calc + _ = |((∫ u, f u ∂μ)-(∫ u, p.eval u ∂μ))- + ((∫ u, f u ∂ν)-(∫ u, p.eval u ∂ν))| := by rw [hp]; congr 1; ring + _ ≤ |(∫ u, f u ∂μ)-(∫ u, p.eval u ∂μ)|+ + |(∫ u, f u ∂ν)-(∫ u, p.eval u ∂ν)| := by simpa using abs_sub_le _ (0:ℝ) _ + _ ≤ ε/2+ε/2 := add_le_add (hb hμ) (hb hν) + _ = 0+ε := by ring + +noncomputable def spinCovarianceMeasure (β : ℝ) : Measure ℝ := + semicircleMeasure.withDensity (fun u => ENNReal.ofReal ((1-β*u+β^2)⁻¹)) + +lemma spinCovarianceMeasure_ae_mem (β : ℝ) : + ∀ᵐ u ∂spinCovarianceMeasure β, u ∈ Set.Icc (-2:ℝ) 2 := + (withDensity_absolutelyContinuous _ _).ae_le semicircle_ae_mem + +lemma spinCovarianceMeasure_integral {β : ℝ} (hβ0 : 0 ≤ β) (hβ1 : β<1) + (f : ℝ → ℝ) : (∫ u, f u ∂spinCovarianceMeasure β)= + ∫ u, f u/(1-β*u+β^2) ∂semicircleMeasure := by + rw [spinCovarianceMeasure,integral_withDensity_eq_integral_toReal_smul] + · apply integral_congr_ae + filter_upwards [semicircle_ae_mem] with u hu + rw [ENNReal.toReal_ofReal (inv_nonneg.mpr + (spinCovariance_denominator_pos hβ0 hβ1 hu).le),smul_eq_mul,div_eq_mul_inv,mul_comm] + · fun_prop + · exact Eventually.of_forall (fun _ => ENNReal.ofReal_lt_top) + +lemma spinCovarianceMeasure_probability {β : ℝ} (hβ0 : 0 ≤ β) (hβ1 : β<1) : + IsProbabilityMeasure (spinCovarianceMeasure β) where + measure_univ := by + have hi : Integrable (fun u => (1-β*u+β^2)⁻¹) semicircleMeasure := by + simpa only [Polynomial.eval_one,one_div] using + integrable_spinCovariance_polynomial hβ0 hβ1 1 + have he : (∫ u, (1-β*u+β^2)⁻¹ ∂semicircleMeasure)=1 := by + simpa only [spinChebyshev_zero,Polynomial.eval_one,one_div,pow_zero] using + spinCovariance_density_moment (β := β) (by rwa [abs_of_nonneg hβ0]) 0 + rw [spinCovarianceMeasure,withDensity_apply _ MeasurableSet.univ,Measure.restrict_univ, + ← ofReal_integral_eq_lintegral_ofReal hi,he] + · norm_num + · filter_upwards [semicircle_ae_mem] with u hu + exact inv_nonneg.mpr (spinCovariance_denominator_pos hβ0 hβ1 hu).le + +theorem spinCovarianceMeasure_eq_of_moments {β : ℝ} (hβ0 : 0 ≤ β) (hβ1 : β<1) + {μ : Measure ℝ} [IsProbabilityMeasure μ] + (hμ : ∀ᵐ u ∂μ, u ∈ Set.Icc (-2:ℝ) 2) + (hm : ∀ k : ℕ, (∫ u, (spinChebyshev k).eval u ∂μ)=β^k) : + μ=spinCovarianceMeasure β := by + let := spinCovarianceMeasure_probability hβ0 hβ1 + apply semicircle_support_measure_ext hμ (spinCovarianceMeasure_ae_mem β) + intro p + rw [spinCovarianceMeasure_integral hβ0 hβ1] + exact spinCovariance_polynomial_of_moments hβ0 hβ1 hμ hm p + +end SKGapCutoff + +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Matrix.Norms.L2Operator + +namespace SKGapCutoff.Regression + +noncomputable def spinEnergyAverage {n : ℕ} (x : Spin n) + (g : GaussianCoordinates n) : ℝ := (∑ i, gaugedField x g i)/(n:ℝ) + +lemma spinEnergyAverage_gaussian (β : ℝ) {n : ℕ} (hn : 0 < n) (x : Spin n) : + HasGaussianLaw (spinEnergyAverage x) (singleSpinPlantedLaw β x) := by + have h := (gaugedField_gaussian β hn x).fun_sum.fun_smul ((n:ℝ)⁻¹) + change HasGaussianLaw (fun g => (∑ i, gaugedField x g i)/(n:ℝ)) _ + simpa only [smul_eq_mul,div_eq_mul_inv,mul_comm] using h + +lemma spinEnergyAverage_mean (β : ℝ) {n : ℕ} (hn : 0 < n) (x : Spin n) : + (∫ g, spinEnergyAverage x g ∂singleSpinPlantedLaw β x)=β^2*((n:ℝ)-1)/(n:ℝ) := by + change (∫ g, (∑ i, gaugedField x g i)/(n:ℝ) ∂singleSpinPlantedLaw β x)=_ + rw [integral_div,integral_finsetSum] + · simp_rw [gaugedField_mean β hn] + simp only [Finset.sum_const,Finset.card_univ,Fintype.card_fin,nsmul_eq_mul] + field_simp + · exact fun i _ => ((gaugedField_gaussian β hn x).eval i).integrable + +lemma spinEnergyAverage_variance (β : ℝ) {n : ℕ} (hn : 0 < n) (x : Spin n) : + Var[spinEnergyAverage x; singleSpinPlantedLaw β x] = 2*β^2*((n:ℝ)-1)/(n:ℝ)^2 := by + let := singleSpinPlantedLaw_probability β hn x + have hsum : Var[fun g => ∑ i, gaugedField x g i; singleSpinPlantedLaw β x] = + 2*β^2*((n:ℝ)-1) := by + rw [variance_fun_sum (fun i => ((gaugedField_gaussian β hn x).eval i).memLp_two)] + simp_rw [gaugedField_covariance β hn] + have he (i : Fin n) : (∑ j : Fin n, + if i=j then β^2*((n:ℝ)-1)/(n:ℝ) else β^2/(n:ℝ)) = + 2*β^2*((n:ℝ)-1)/(n:ℝ) := by + have hterm (j : Fin n) : + (if i=j then β^2*((n:ℝ)-1)/(n:ℝ) else β^2/(n:ℝ)) = + β^2/(n:ℝ)+(if i=j then β^2*((n:ℝ)-2)/(n:ℝ) else 0) := by + split_ifs <;> ring + simp_rw [hterm] + rw [Finset.sum_add_distrib] + simp only [Finset.sum_const,Finset.card_univ,Fintype.card_fin,nsmul_eq_mul, + Finset.sum_ite_eq,Finset.mem_univ,ite_true] + have hnR : (n:ℝ)≠0 := Nat.cast_ne_zero.mpr hn.ne' + field_simp + ring + simp_rw [he] + simp only [Finset.sum_const,Finset.card_univ,Fintype.card_fin,nsmul_eq_mul] + have hnR : (n:ℝ)≠0 := Nat.cast_ne_zero.mpr hn.ne' + field_simp + have he : spinEnergyAverage x = fun g => (n:ℝ)⁻¹*(∑ i, gaugedField x g i) := by + funext g; simp [spinEnergyAverage,div_eq_mul_inv,mul_comm] + rw [he,variance_const_mul,hsum] + ring + +lemma hasSubgaussianMGF_mono_parameter {Ω : Type*} [MeasurableSpace Ω] + {μ : Measure Ω} {X : Ω → ℝ} {c d : ℝ≥0} + (hX : HasSubgaussianMGF X c μ) (hcd : c ≤ d) : HasSubgaussianMGF X d μ where + integrable_exp_mul := hX.integrable_exp_mul + mgf_le t := (hX.mgf_le t).trans (Real.exp_le_exp.mpr (by + exact div_le_div_of_nonneg_right (mul_le_mul_of_nonneg_right hcd (sq_nonneg t)) (by norm_num))) + +lemma spinEnergyAverage_centered_subgaussian (β : ℝ) {n : ℕ} (hn : 0 < n) + (x : Spin n) : HasSubgaussianMGF + (fun g => spinEnergyAverage x g-β^2*((n:ℝ)-1)/(n:ℝ)) + (Real.toNNReal (2*β^2/(n:ℝ))) (singleSpinPlantedLaw β x) := by + let := singleSpinPlantedLaw_probability β hn x + have hg := spinEnergyAverage_gaussian β hn x + have hl : HasLaw (spinEnergyAverage x) + (gaussianReal (β^2*((n:ℝ)-1)/(n:ℝ)) (Real.toNNReal (2*β^2*((n:ℝ)-1)/(n:ℝ)^2))) + (singleSpinPlantedLaw β x) := by + refine ⟨hg.aemeasurable,?_⟩ + rw [hg.map_eq_gaussianReal,spinEnergyAverage_mean β hn,spinEnergyAverage_variance β hn] + have hlz : HasLaw (fun g => spinEnergyAverage x g-β^2*((n:ℝ)-1)/(n:ℝ)) + (gaussianReal 0 (Real.toNNReal (2*β^2*((n:ℝ)-1)/(n:ℝ)^2))) + (singleSpinPlantedLaw β x) := by + convert! gaussianReal_sub_const hl (β^2*((n:ℝ)-1)/(n:ℝ)) using 2 + ring + have hz := gaussian_hasSubgaussianMGF hlz + apply hasSubgaussianMGF_mono_parameter hz + apply Real.toNNReal_mono + have hnR : (0:ℝ) (n:ℝ)) atTop atTop) + filter_upwards [eventually_gt_atTop 0, hnc.eventually (eventually_ge_atTop (2*β^2/ε)), + hnc.eventually (eventually_ge_atTop (Real.log 2/c))] with n hn hsize hlog + intro x + have hnR : (0:ℝ) (∑ i, gaugedField x g i)/(n:ℝ)) + exact (continuous_finsetSum _ (fun i _ => + (continuous_apply i).comp (continuous_gaugedField x))).div_const _ + +theorem quenched_spinEnergyAverage_exponential (β : ℝ) (hβ : 0<β) (hβ1 : β<1) + (ε : ℝ) (hε : 0<ε) : ∃ c : ℝ, 0 disorderLaw β n {g | + ENNReal.ofReal (Real.exp (-c*n)) ≤ + gibbsEventProbability (fun x : Spin n => {h | ε ≤ |spinEnergyAverage x h-β^2|}) g}) + atTop (nhds 0) := by + obtain ⟨c,hc,hs⟩ := spinEnergyAverage_planted_exponential β hβ ε hε + refine ⟨c/2,by positivity,?_⟩ + apply quenched_gibbs_events_exponential β (by nlinarith) c hc _ _ hs + intro n x + exact measurableSet_le measurable_const ((continuous_spinEnergyAverage x).measurable.sub_const _).abs + +lemma spinEnergyAverage_abs_le_opNorm {n : ℕ} (hn : 0 2*(n:ℝ)-2*linearObservable (spin x) y := + funext (spinDifferenceEnergy_eq x) + rw [he, halfDiff_sub, halfDiff_const] + have hh : halfDiff i (fun y => 2*linearObservable (spin x) y) y = 2*spin x i := by + rw [show (fun y => 2*linearObservable (spin x) y) = + (2:ℝ) • linearObservable (spin x) from rfl] + change (gradientLM n ((2:ℝ) • linearObservable (spin x))) y i = _ + rw [map_smul] + simp [gradientLM, halfDiff_linearObservable] + rw [hh] + ring + +lemma refreshGenerator_spinDifferenceEnergy_le {n : ℕ} (m : VectorFields n) + (hm : ∀ y i, |m y i|≤1) (x y : Spin n) : + refreshGenerator m (spinDifferenceEnergy x) y ≤ 4*(n:ℝ) := by + unfold refreshGenerator + simp_rw [halfDiff_spinDifferenceEnergy] + calc + _ ≤ ∑ i : Fin n, (4:ℝ) := by + apply Finset.sum_le_sum + intro i _ + have hh := abs_le.mp (hm y i) + cases hx : x i <;> cases hy : y i <;> + simp only [spin, hx, hy, Bool.false_eq_true, ↓reduceIte] <;> linarith + _ = _ := by simp; ring + +lemma refreshSemigroup_sub_initial_le {n : ℕ} (m : VectorFields n) + (hm : ∀ y i, |m y i|≤1) (f : Observables n) (B t : ℝ) (ht : 0≤t) + (hB : ∀ y, refreshGenerator m f y ≤ B) (x : Spin n) : + refreshSemigroup m t f x-f x ≤ B*t := by + have hc : Continuous (fun s : ℝ => refreshSemigroup m s (refreshGenerator m f) x) := + (continuous_apply x).comp ((refreshSemigroup_continuous m).clm_apply continuous_const) + have hd (s : ℝ) := hasDerivAt_pi.mp (refreshSemigroup_apply_hasDerivAt m f s) x + have he := intervalIntegral.integral_eq_sub_of_hasDerivAt (fun s _ => hd s) + (hc.intervalIntegrable 0 t) + simp only [refreshSemigroup_zero, one_apply_eq_self] at he + rw [← he] + calc + _ ≤ ∫ s in 0..t, B := by + apply intervalIntegral.integral_mono_on ht (hc.intervalIntegrable _ _) intervalIntegrable_const + intro s hs + exact (refreshSemigroup_mono m hm s hs.1 hB x).trans_eq (by simp) + _ = _ := by simp [mul_comm] + +lemma refreshSemigroup_spinDifferenceEnergy {n : ℕ} (m : VectorFields n) + (hm : ∀ y i, |m y i|≤1) (t : ℝ) (ht : 0≤t) (x : Spin n) : + refreshSemigroup m t (spinDifferenceEnergy x) x ≤ 4*(n:ℝ)*t := by + have hh := refreshSemigroup_sub_initial_le m hm (spinDifferenceEnergy x) + (4*(n:ℝ)) t ht (refreshGenerator_spinDifferenceEnergy_le m hm x) x + simpa [spinDifferenceEnergy] using hh + +noncomputable def spinEuclidean {n : ℕ} (x : Spin n) : EuclideanSpace ℝ (Fin n) := + WithLp.toLp 2 (spin x) + +lemma spinEuclidean_sub_norm_sq {n : ℕ} (x y : Spin n) : + ‖spinEuclidean y-spinEuclidean x‖^2 = spinDifferenceEnergy x y := by + rw [EuclideanSpace.real_norm_sq_eq] + rfl + +theorem refresh_lipschitz_recipe_short_time {n : ℕ} {E : Type*} + [NormedAddCommGroup E] (F : EuclideanSpace ℝ (Fin n) → E) {K : NNReal} + (hF : LipschitzWith K F) (m : VectorFields n) (hm : ∀ y i, |m y i|≤1) + (t : ℝ) (ht : 0≤t) (x : Spin n) : + refreshSemigroup m t (fun y => ‖F (spinEuclidean y)-F (spinEuclidean x)‖^2) x ≤ + 4*(n:ℝ)*(K:ℝ)^2*t := by + have hb (y : Spin n) : ‖F (spinEuclidean y)-F (spinEuclidean x)‖^2 ≤ + (K:ℝ)^2*spinDifferenceEnergy x y := by + have hh := hF.norm_sub_le (spinEuclidean y) (spinEuclidean x) + have hh' := pow_le_pow_left₀ (norm_nonneg _) hh 2 + simpa only [mul_pow, spinEuclidean_sub_norm_sq] using hh' + apply (refreshSemigroup_mono m hm t ht hb x).trans + have he : refreshSemigroup m t (fun y => (K:ℝ)^2*spinDifferenceEnergy x y) x = + (K:ℝ)^2*refreshSemigroup m t (spinDifferenceEnergy x) x := by + exact congrFun (map_smul (refreshSemigroup m t) ((K:ℝ)^2) (spinDifferenceEnergy x)) x + rw [he] + have hh := mul_le_mul_of_nonneg_left (refreshSemigroup_spinDifferenceEnergy m hm t ht x) + (sq_nonneg (K:ℝ)) + nlinarith only [hh] + +end SKGapCutoff + +open scoped Topology + +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Terminal/SpinDifferenceEnergyReplace.lean b/lean/OAI/Probability/SKGap/Terminal/SpinDifferenceEnergyReplace.lean new file mode 100644 index 0000000000000000000000000000000000000000..f35dc79060b89e8db620e3c97d34a690686b7e36 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Terminal/SpinDifferenceEnergyReplace.lean @@ -0,0 +1,316 @@ +import Mathlib +import OAI.Probability.SKGap.Matrix.NormalizedInfluence +import OAI.Probability.SKGap.Entropy.BoundGood +import OAI.Probability.SKGap.Terminal.SpinDifferenceEnergy +import OAI.Probability.SKGap.Localization.ComponentRefresh + +namespace OAI + +section +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open scoped BigOperators +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open scoped BigOperators +open scoped BigOperators NNReal ENNReal +open MeasureTheory Metric Set +open scoped BigOperators NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators NNReal ENNReal Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Set +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators ENNReal NNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Matrix +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators ENNReal NNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal +open scoped BigOperators +open MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix Matrix.Norms.Elementwise NNReal ENNReal +open scoped BigOperators +open Filter Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal Topology +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter +open scoped ENNReal NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Set Matrix +open scoped BigOperators NNReal ENNReal Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open MeasureTheory ProbabilityTheory Filter Matrix +open scoped NNReal ENNReal BigOperators Topology Matrix Matrix.Norms.Elementwise +open Filter MeasureTheory ProbabilityTheory +open scoped Topology NNReal ENNReal +open Filter MeasureTheory ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter +open scoped Topology NNReal ENNReal +open MeasureTheory Filter ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter +open scoped Topology +open MeasureTheory Filter ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter ProbabilityTheory ContinuousLinearMap +open scoped Topology NNReal ENNReal +open Filter MeasureTheory ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter +open scoped BigOperators Topology +open MeasureTheory Filter +open scoped BigOperators Topology +open MeasureTheory Filter +open scoped BigOperators Topology +open MeasureTheory Filter +open scoped BigOperators Topology +open MeasureTheory Filter +open scoped BigOperators Topology +open Filter Set Metric +open scoped Topology RealInnerProductSpace +open scoped BigOperators +open ContinuousLinearMap +open scoped BigOperators +open ContinuousLinearMap +open scoped Topology Interval +open MeasureTheory +open MeasureTheory +open scoped BigOperators Topology Interval +open MeasureTheory +open scoped BigOperators Topology Interval +open scoped Topology +open MeasureTheory +open scoped BigOperators Topology Interval +open scoped BigOperators Topology +namespace SKGapCutoff + +lemma spinDifferenceEnergy_replace {n : ℕ} (x : Spin n) (j : Fin n) : + spinDifferenceEnergy (replace x j false) (replace x j true) = 4 := by + unfold spinDifferenceEnergy + rw [Finset.sum_eq_single j] + · norm_num [spin, replace] + · intro i _ hij + simp [spin, replace, Function.update_of_ne hij] + · simp + +lemma lipschitz_vector_derivativeSquare {n : ℕ} + (F : EuclideanSpace ℝ (Fin n) → EuclideanSpace ℝ (Fin n)) {K : NNReal} + (hF : LipschitzWith K F) (x : Spin n) : + vectorDerivativeSquare (fun y i => F (spinEuclidean y) i) x ≤ (n:ℝ)*(K:ℝ)^2 := by + have hh (j : Fin n) : (∑ i, (halfDiff j (fun y => F (spinEuclidean y) i) x)^2) ≤ (K:ℝ)^2 := by + have hl := pow_le_pow_left₀ (norm_nonneg _) + (hF.norm_sub_le (spinEuclidean (replace x j true)) (spinEuclidean (replace x j false))) 2 + rw [mul_pow, spinEuclidean_sub_norm_sq, spinDifferenceEnergy_replace, + EuclideanSpace.real_norm_sq_eq] at hl + have he : (∑ i, (halfDiff j (fun y => F (spinEuclidean y) i) x)^2) = + (∑ i, (F (spinEuclidean (replace x j true)) i-F (spinEuclidean (replace x j false)) i)^2)/4 := by + simp only [halfDiff, div_pow, ← Finset.sum_div] + norm_num + rw [he] + change (∑ i, (F (spinEuclidean (replace x j true)) i-F (spinEuclidean (replace x j false)) i)^2) ≤ _ at hl + linarith + unfold vectorDerivativeSquare + rw [Finset.sum_comm] + calc + _ ≤ ∑ _j : Fin n, (K:ℝ)^2 := Finset.sum_le_sum (fun j _ => hh j) + _ = _ := by simp + +theorem refreshGradient_lipschitz_short_time {n : ℕ} + (F : EuclideanSpace ℝ (Fin n) → EuclideanSpace ℝ (Fin n)) {K : NNReal} + (hF : LipschitzWith K F) (m : VectorFields n) (hm : ∀ x i, |m x i|≤1) + (C U M D t : ℝ) (hC : 0≤C) (hU : 0≤U) (hD : 0≤D) (ht : 0≤t) + (hrough : ∀ q : VectorFields n, ∀ u : ℝ, 0≤u → ∀ x, + vectorSquare (refreshGradientSemigroup m u q) x ≤ + Real.exp (C*u)*refreshSemigroup m u (vectorSquare q) x) + (hbound : ∀ x, ‖F (spinEuclidean x)‖^2 ≤ U) + (hrow : ∀ x i, ∑ j, refreshInfluence m x i j^2 ≤ D) + (hop : ∀ x (q : Fin n → ℝ), ∑ i, (∑ j, refreshInfluence m x i j*q j)^2 ≤ + M^2*∑ i, q i^2) (x : Spin n) : + vectorSquare (refreshGradientSemigroup m t (fun y i => F (spinEuclidean y) i)- + (fun y i => F (spinEuclidean y) i)) x ≤ + 2*t^2*Real.exp (2*C*t)*(3*(1+M^2)*U+12*D*(n:ℝ)*(K:ℝ)^2)+ + 8*(n:ℝ)*(K:ℝ)^2*t := by + have hb : ∀ x, vectorSquare (fun y i => F (spinEuclidean y) i) x ≤ U := by + intro x + simpa only [vectorSquare, ← EuclideanSpace.real_norm_sq_eq] using hbound x + have hh := refreshGradient_short_time m (fun y i => F (spinEuclidean y) i) hm + C U ((n:ℝ)*(K:ℝ)^2) M D t hC hU (by positivity) hD ht hrough hb + (lipschitz_vector_derivativeSquare F hF) hrow hop x + have ho := refresh_lipschitz_recipe_short_time F hF m hm t ht x + simp only [EuclideanSpace.real_norm_sq_eq, PiLp.sub_apply] at ho + nlinarith only [hh,ho] + +lemma refreshInfluence_field_opNorm {n : ℕ} (H : VectorFields n) (C : ℝ) (hC : 0≤C) + (hHC : ∀ x, ‖Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) + (fun j i => halfDiff i (fun y => H y j) x)‖ ≤ C) (x : Spin n) : + ‖Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) + (refreshInfluence (fun y k => Real.tanh (H y k)) x)‖ ≤ C+4*C^2 := by + let K : Interaction n := fun j i => halfDiff i (fun y => H y j) x + let A : Interaction n := refreshInfluence (fun y k => Real.tanh (H y k)) x + let V : Interaction n := Matrix.diagonal (fun j => scalarVariance (H x j)) + let E := A-K.transpose*V + have he (i j : Fin n) : |E i j| ≤ 4*(K j i)^2 := by + simp only [E,A,K,V,Matrix.sub_apply,Matrix.mul_diagonal] + exact refreshInfluence_error_le H x i j + have hk : ‖Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) K‖ ≤ C := hHC x + have hkt : ‖Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) K.transpose‖ ≤ C := by + have hs : K.transpose = star K := rfl + have hn : ‖Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) K.transpose‖ = + ‖Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) K‖ := by + rw [hs,map_star] + exact ContinuousLinearMap.adjoint.norm_map _ + rw [hn] + exact hk + have hv : ‖Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) V‖ ≤ 1 := by + apply matrix_diagonal_opNorm_le _ 1 (by norm_num) + intro j + rw [abs_of_pos (scalarVariance_pos _)] + exact scalarVariance_le_one _ + have herr : ‖Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) E‖ ≤ 4*C^2 := by + apply matrix_opNorm_le_schur E _ (by positivity) + · intro i + calc + _ ≤ ∑ j, 4*(K j i)^2 := Finset.sum_le_sum (fun j _ => he i j) + _ = 4*∑ j, (K j i)^2 := (Finset.mul_sum _ _ _).symm + _ ≤ _ := mul_le_mul_of_nonneg_left + ((RandomMatrix.matrix_column_sq_le K i).trans (pow_le_pow_left₀ (norm_nonneg _) hk 2)) (by norm_num) + · intro j + calc + _ ≤ ∑ i, 4*(K j i)^2 := Finset.sum_le_sum (fun i _ => he i j) + _ = 4*∑ i, (K j i)^2 := (Finset.mul_sum _ _ _).symm + _ ≤ _ := mul_le_mul_of_nonneg_left + ((matrix_row_sq_le K j).trans (pow_le_pow_left₀ (norm_nonneg _) hk 2)) (by norm_num) + have hbase : ‖Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) (K.transpose*V)‖ ≤ C := by + rw [map_mul] + exact (norm_mul_le _ _).trans ((mul_le_mul hkt hv (norm_nonneg _) hC).trans_eq (mul_one C)) + have ha : A = K.transpose*V+E := by dsimp only [E]; abel + change ‖Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) A‖ ≤ _ + rw [ha,map_add] + exact (norm_add_le _ _).trans (add_le_add hbase herr) + +lemma refreshVector_field_bound {n : ℕ} (H : VectorFields n) (C : ℝ) (hC : 0≤C) + (hHC : ∀ x, ‖Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) + (fun j i => halfDiff i (fun y => H y j) x)‖ ≤ C) + (p : VectorFields n) (t : ℝ) (ht : 0≤t) (x : Spin n) : + vectorSquare (refreshGradientSemigroup (fun y k => Real.tanh (H y k)) t p) x ≤ + Real.exp (preparationGrowth C*t)*refreshSemigroup (fun y k => Real.tanh (H y k)) t + (vectorSquare p) x := by + apply (refreshRough_of_field_opNorm H C hC hHC p t ht x).trans + apply mul_le_mul_of_nonneg_right + · apply Real.exp_le_exp.mpr + apply mul_le_mul_of_nonneg_right _ ht + unfold preparationGrowth + linarith + · exact refreshSemigroup_nonneg _ (fun y k => (Real.abs_tanh_lt_one _).le) t ht _ + (fun y => Finset.sum_nonneg (fun i _ => sq_nonneg _)) x + +theorem field_recipe_short_time {n : ℕ} + (F : EuclideanSpace ℝ (Fin n) → EuclideanSpace ℝ (Fin n)) {K : NNReal} + (hF : LipschitzWith K F) (H : VectorFields n) (C U t : ℝ) + (hC : 0≤C) (hU : 0≤U) (ht : 0≤t) + (hHC : ∀ x, ‖Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) + (fun j i => halfDiff i (fun y => H y j) x)‖ ≤ C) + (hbound : ∀ x, ‖F (spinEuclidean x)‖^2 ≤ U) (x : Spin n) : + vectorSquare (refreshGradientSemigroup (fun y k => Real.tanh (H y k)) t + (fun y i => F (spinEuclidean y) i)-(fun y i => F (spinEuclidean y) i)) x ≤ + 2*t^2*Real.exp (2*preparationGrowth C*t)* + (3*(1+(C+4*C^2)^2)*U+12*(C+4*C^2)^2*(n:ℝ)*(K:ℝ)^2)+ + 8*(n:ℝ)*(K:ℝ)^2*t := by + apply refreshGradient_lipschitz_short_time F hF _ (fun y k => (Real.abs_tanh_lt_one _).le) + (preparationGrowth C) U (C+4*C^2) ((C+4*C^2)^2) t + (preparationGrowth_pos C hC).le hU (sq_nonneg _) ht + (refreshVector_field_bound H C hC hHC) hbound + · intro y i + exact (matrix_row_sq_le _ i).trans + (pow_le_pow_left₀ (norm_nonneg _) (refreshInfluence_field_opNorm H C hC hHC y) 2) + · intro y q + exact Regression.matrix_mulVec_sq_bound _ q (refreshInfluence_field_opNorm H C hC hHC y) + +end SKGapCutoff + +open MeasureTheory +open scoped BigOperators Topology Interval RealInnerProductSpace + +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Terminal/SpinEnergy.lean b/lean/OAI/Probability/SKGap/Terminal/SpinEnergy.lean new file mode 100644 index 0000000000000000000000000000000000000000..22c30a9a100e6d86a11e7015dd7dac2ad1fbeb98 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Terminal/SpinEnergy.lean @@ -0,0 +1,91 @@ +import Mathlib +import OAI.Probability.SKGap.Terminal.FiniteSpinCalculus + +namespace OAI + +section +noncomputable section +namespace SKGap +open Matrix Real +open scoped BigOperators + +lemma sum_edges {n : ℕ} (f : Fin n → Fin n → ℝ) : + (∑ e : Edge n,f e.1.1 e.1.2)=∑ i,∑ k,if i < k then f i k else 0 := by + have he := Finset.sum_subtype (F:=inferInstance) (p:=fun p : Fin n×Fin n=>p.1 < p.2) (Finset.univ.filter (fun p : Fin n×Fin n=>p.1 < p.2)) + (by simp) (fun p=>f p.1 p.2) + simpa only [Finset.sum_filter,Fintype.sum_prod_type] using he.symm + +lemma edge_energy_formula {n : ℕ} (g : Disorder n) (x : Spin n) : + hamiltonian g 0 x=∑ e : Edge n,g e*spinValue (x e.1.1)*spinValue (x e.1.2) := by + let f : Fin n → Fin n → ℝ := fun i k=>spinValue (x i)*coupling g i k*spinValue (x k) + have hsymm : ∀ i k,f i k=f k i := by intro i k; dsimp [f];rw [coupling_symm g i k];ring + have hz : ∀ i,f i i=0 := by intro i;simp [f] + have hf : (∑ i,∑ k,f i k)=2*∑ i,∑ k,if i < k then f i k else 0 := by + have hh : ∀ i k,f i k=(if i < k then f i k else 0)+(if k < i then f k i else 0) := by + intro i k + rcases lt_trichotomy i k with h|rfl|h + · simp [h,not_lt_of_gt h] + · simp [hz] + · simp only [ite_eq_right (not_lt_of_gt h),ite_eq_left h,zero_add];exact hsymm i k + conv_lhs => arg 2; ext i; arg 2; ext k; rw [hh i k] + simp only [Finset.sum_add_distrib] + rw [Finset.sum_comm (f:=fun i k=>if k < i then f k i else 0)] + ring + have he : (∑ e : Edge n,g e*spinValue (x e.1.1)*spinValue (x e.1.2))= + ∑ i,∑ k,if i < k then f i k else 0 := by + rw [← sum_edges f] + apply Finset.sum_congr rfl + intro e _ + simp only [f,coupling,dite_eq_left e.2] + ring + rw [he] + change 1/2*(∑ i,∑ k,f i k)+ (∑ i,(0:Fin n→ℝ) i*spinValue (x i))=_ + simp only [Pi.zero_apply,zero_mul,Finset.sum_const_zero,add_zero] + rw [hf];ring + +lemma edge_symmetric_sum {n : ℕ} (u : Fin n → ℝ) : + 2*(∑ e : Edge n,u e.1.1*u e.1.2)=(∑ i,u i)^2-∑ i,u i^2 := by + rw [sum_edges (fun i k=>u i*u k)] + have hh : ∀ i k,u i*u k=(if i < k then u i*u k else 0)+ + (if k < i then u k*u i else 0)+(if i=k then u i^2 else 0) := by + intro i k + rcases lt_trichotomy i k with h|rfl|h + · simp [h,not_lt_of_gt h,ne_of_lt h] + · simp [sq] + · simp [h,not_lt_of_gt h,ne_of_gt h,mul_comm] + have hs : (∑ i,u i)^2=2*(∑ i,∑ k,if i < k then u i*u k else 0)+∑ i,u i^2 := by + rw [sq,Finset.sum_mul_sum] + conv_lhs => arg 2; ext i; arg 2; ext k; rw [hh i k] + simp only [Finset.sum_add_distrib] + rw [Finset.sum_comm (f:=fun i k=>if k < i then u k*u i else 0)] + simp only [Finset.sum_ite_eq,Finset.mem_univ,ite_true] + ring + linarith only [hs] + +def spinMul {n : ℕ} (x y : Spin n) : Spin n := fun i => !(xor (x i) (y i)) + +lemma spinValue_mul {n : ℕ} (x y : Spin n) (i : Fin n) : + spinValue (spinMul x y i)=spinValue (x i)*spinValue (y i) := by + cases hx : x i <;> cases hy : y i <;> simp [spinMul,hx,hy,spinValue] + +lemma spinMul_involutive {n : ℕ} (x : Spin n) : Function.Involutive (spinMul x) := by + intro y;ext i + cases hx : x i <;> cases hy : y i <;> simp [spinMul,hx,hy] + +lemma sum_spinMul {n : ℕ} (x : Spin n) (f : Spin n→ℝ) : + (∑ y,f (spinMul x y))=∑ y,f y := + Equiv.sum_comp (Function.Involutive.toPerm (spinMul x) (spinMul_involutive x)) f + +lemma spin_exponential_sum {n : ℕ} (a : ℝ) : + (∑ x : Spin n,exp (a*∑ i,spinValue (x i)))=(2*cosh a)^n := by + simp_rw [Finset.mul_sum,exp_sum] + rw [← Fintype.prod_sum (fun (_ : Fin n) (b : Bool)=>exp (a*spinValue b))] + simp only [Fintype.sum_bool,spinValue_false,spinValue_true,mul_one,mul_neg_one, + Finset.prod_const,Finset.card_univ,Fintype.card_fin,cosh_eq] + congr 1;ring + +end SKGap +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Terminal/SpinGaussianBound.lean b/lean/OAI/Probability/SKGap/Terminal/SpinGaussianBound.lean new file mode 100644 index 0000000000000000000000000000000000000000..7d26bf10983a1019402bf665d8eda742d8f2bd2d --- /dev/null +++ b/lean/OAI/Probability/SKGap/Terminal/SpinGaussianBound.lean @@ -0,0 +1,67 @@ +import Mathlib +import OAI.Probability.SKGap.Terminal.SpinEnergy + +namespace OAI + +section +noncomputable section +namespace SKGap +open MeasureTheory ProbabilityTheory Real +open scoped BigOperators + +lemma gaussian_quadratic_integrable_sharp {j : ℝ} (hj : j < 1) : + Integrable (fun g : ℝ=>exp (j*g^2/2)) (gaussianReal 0 1) := by + rw [gaussianReal_of_var_ne_zero 0 (one_ne_zero),integrable_withDensity_iff + (measurable_gaussianPDF 0 1) (ae_of_all _ (fun y=>by simp [gaussianPDF]))] + simp only [gaussianPDF,ENNReal.toReal_ofReal (gaussianPDFReal_nonneg _ _ _)] + have hi := (integrable_exp_neg_mul_sq (show 0 < (1-j)/2 by linarith)).const_mul (1/sqrt (2*Real.pi)) + have he : (fun g : ℝ=>exp (j*g^2/2)*gaussianPDFReal 0 1 g)= + (fun g : ℝ=>(1/sqrt (2*Real.pi))*exp (-((1-j)/2)*g^2)) := by + funext g + simp only [gaussianPDFReal,NNReal.coe_one,sub_zero,mul_one] + rw [mul_left_comm,← exp_add] + congr 2 <;> ring + rw [he] + exact hi + +lemma gaussian_spin_exponential_integrable (a : ℝ) {n : ℕ} (x : Spin n) : + Integrable (fun g : ℝ=>exp (a*g*∑ i,spinValue (x i))) (gaussianReal 0 1) := by + convert (integrable_exp_mul_gaussianReal (μ:=0) (v:=1) (a*∑ i,spinValue (x i))) using 1 + ext g;congr 1;ring + +lemma spin_gaussian_linearization {r : ℝ} (hr : 0 ≤ r) {n : ℕ} (x : Spin n) : + exp (r/2*(∑ i,spinValue (x i))^2)= + ∫ g : ℝ,exp (sqrt r*g*∑ i,spinValue (x i)) ∂gaussianReal 0 1 := by + have he := mgf_gaussianReal (μ:=0) (v:=1) (X:=fun g : ℝ=>g) (p:=gaussianReal 0 1) (by simp) + (sqrt r*∑ i,spinValue (x i)) + simp only [mgf,zero_mul,NNReal.coe_one,one_mul,zero_add,mul_pow,sq_sqrt hr] at he + calc + _ = exp (r*(∑ i,spinValue (x i))^2/2) := by congr 1;ring + _ = ∫ g : ℝ,exp ((sqrt r*∑ i,spinValue (x i))*g) ∂gaussianReal 0 1 := he.symm + _ = _ := by congr 1;ext g;congr 1;ring + +lemma spin_quadratic_sum_bound {n : ℕ} {j r : ℝ} (hj : j < 1) (hr : 0 ≤ r) + (hnr : (n:ℝ)*r ≤ j) : + (∑ x : Spin n,exp (r/2*(∑ i,spinValue (x i))^2)) ≤ + (2:ℝ)^n*(∫ g : ℝ,exp (j*g^2/2) ∂gaussianReal 0 1) := by + simp_rw [spin_gaussian_linearization hr] + rw [← integral_finsetSum _ (fun x _=>gaussian_spin_exponential_integrable (sqrt r) x), + ← integral_const_mul] + apply integral_mono + (integrable_finsetSum _ (fun x _=>gaussian_spin_exponential_integrable (sqrt r) x)) + ((gaussian_quadratic_integrable_sharp hj).const_mul _) + intro g + dsimp only [] + rw [spin_exponential_sum (sqrt r*g),mul_pow] + apply mul_le_mul_of_nonneg_left ?_ (by positivity) + calc + (cosh (sqrt r*g))^n ≤ (exp ((sqrt r*g)^2/2))^n := + pow_le_pow_left₀ (cosh_pos _).le (cosh_le_exp_half_sq _) _ + _ = exp ((n:ℝ)*r*g^2/2) := by rw [← exp_nat_mul,mul_pow,sq_sqrt hr];congr 1;ring + _ ≤ exp (j*g^2/2) := exp_le_exp.mpr (by nlinarith [mul_le_mul_of_nonneg_right hnr (sq_nonneg g)]) + +end SKGap +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Terminal/SpinLocalField.lean b/lean/OAI/Probability/SKGap/Terminal/SpinLocalField.lean new file mode 100644 index 0000000000000000000000000000000000000000..ad986fcc917ce14c1ad93cb456a7ebbc5ad9811e --- /dev/null +++ b/lean/OAI/Probability/SKGap/Terminal/SpinLocalField.lean @@ -0,0 +1,190 @@ +import Mathlib +import OAI.Probability.SKGap.Terminal.FiniteSpinCalculus + +namespace OAI + +section +noncomputable section +namespace SKGap +open Matrix Real +open scoped BigOperators +variable {n : ℕ} + +def localField (g : Disorder n) (h : Fin n→ℝ) (i : Fin n) (x : Spin n) : ℝ := + h i+∑ k,coupling g i k*spinValue (x k) +def spinGradient (i : Fin n) (f : Spin n→ℝ) (x : Spin n) : ℝ := + (f (Function.update x i true)-f (Function.update x i false))/2 + +def realSpinEnergy (g : Disorder n) (h v : Fin n→ℝ) : ℝ := + (1/2)*(v ⬝ᵥ (Matrix.of (coupling g) *ᵥ v))+h ⬝ᵥ v + +lemma realSpinEnergy_eq (g : Disorder n) (h : Fin n→ℝ) (x : Spin n) : + realSpinEnergy g h (fun i=>spinValue (x i))=hamiltonian g h x := by + unfold realSpinEnergy hamiltonian + congr 1 + congr 1 + simp only [Matrix.mulVec, Matrix.of_apply, dotProduct] + apply Finset.sum_congr rfl + intro i _ + rw [Finset.mul_sum] + apply Finset.sum_congr rfl + intro k _;ring + +lemma dot_coupling_single (g : Disorder n) (v : Fin n→ℝ) (i : Fin n) (a : ℝ) : + v ⬝ᵥ (Matrix.of (coupling g) *ᵥ Pi.single i a)=a*(Matrix.of (coupling g) *ᵥ v) i := by + rw [Matrix.mulVec_single] + simp only [Matrix.mulVec, Matrix.of_apply, dotProduct] + simp only [Pi.smul_apply,op_smul_eq_mul,Matrix.col_apply,Matrix.of_apply] + rw [Finset.mul_sum] + apply Finset.sum_congr rfl + intro k _ + rw [coupling_symm g k i] + ring + +lemma realSpinEnergy_update (g : Disorder n) (h v : Fin n→ℝ) (i : Fin n) (a : ℝ) : + realSpinEnergy g h (Function.update v i a)=realSpinEnergy g h v+ + (a-v i)*(h i+(Matrix.of (coupling g) *ᵥ v) i) := by + have he : Function.update v i a=v+Pi.single i (a-v i) := by + funext k + by_cases hk : k=i + · subst k;simp + · simp [hk] + rw [he] + unfold realSpinEnergy + rw [Matrix.mulVec_add,dotProduct_add,add_dotProduct,add_dotProduct,dotProduct_add, + dot_coupling_single,single_dotProduct,single_dotProduct,dotProduct_single,Matrix.mulVec_single] + simp only [Pi.smul_apply,op_smul_eq_mul,Matrix.col_apply,Matrix.of_apply,coupling_diag,zero_mul] + ring + +lemma spinValue_update (x : Spin n) (i : Fin n) (b : Bool) : + (fun k=>spinValue (Function.update x i b k))=Function.update (fun k=>spinValue (x k)) i (spinValue b) := by + funext k + by_cases hk : k=i + · subst k;simp + · simp [Function.update_of_ne hk] + +lemma hamiltonian_update (g : Disorder n) (h : Fin n→ℝ) (i : Fin n) (x : Spin n) (b : Bool) : + hamiltonian g h (Function.update x i b)=hamiltonian g h x+ + (spinValue b-spinValue (x i))*localField g h i x := by + rw [← realSpinEnergy_eq,spinValue_update,realSpinEnergy_update,realSpinEnergy_eq] + rfl + +lemma localField_update_self (g : Disorder n) (h : Fin n→ℝ) (i : Fin n) (x : Spin n) (b : Bool) : + localField g h i (Function.update x i b)=localField g h i x := by + unfold localField + congr 1 + apply Finset.sum_congr rfl + intro k _ + by_cases hk : k=i + · subst k;simp + · simp [Function.update_of_ne hk] + +lemma localField_update (g : Disorder n) (h : Fin n→ℝ) (i j : Fin n) (x : Spin n) (b : Bool) : + localField g h i (Function.update x j b)=localField g h i x+ + coupling g i j*(spinValue b-spinValue (x j)) := by + unfold localField + have he : (fun k=>spinValue (Function.update x j b k))= + (fun k=>spinValue (x k))+Pi.single j (spinValue b-spinValue (x j)) := by + funext k + by_cases hk : k=j + · subst k;simp + · simp [Function.update_of_ne hk,Pi.single_eq_of_ne hk] + change h i+(coupling g i ⬝ᵥ (fun k=>spinValue (Function.update x j b k)))=_ + rw [he,dotProduct_add,dotProduct_single] + exact (add_assoc _ _ _).symm +end SKGap + +end +end + +section +noncomputable section +namespace SKGap +open Real +open scoped BigOperators + +def pairBaseMass (a b : ℝ) (x y : Bool) : ℝ := + (1+a*spinValue x)*(1+b*spinValue y)/4 + +def pairMean (a b : ℝ) (F : Bool→Bool→ℝ) : ℝ := + ∑ x,∑ y,pairBaseMass a b x y*F x y + +lemma pairMean_explicit (a b : ℝ) (F : Bool→Bool→ℝ) : + pairMean a b F=((1-a)*(1-b)*F false false+(1-a)*(1+b)*F false true+ + (1+a)*(1-b)*F true false+(1+a)*(1+b)*F true true)/4 := by + simp only [pairMean,Fintype.sum_bool,pairBaseMass,spinValue,Bool.false_eq_true, + ite_false,ite_true,mul_neg_one,mul_one] + ring + +lemma pairBaseMass_nonneg {a b : ℝ} (ha : |a| ≤ 1) (hb : |b| ≤ 1) (x y : Bool) : + 0 ≤ pairBaseMass a b x y := by + have h₁ := abs_le.mp ha + have h₂ := abs_le.mp hb + unfold pairBaseMass + cases x <;> cases y <;> simp only [spinValue,Bool.false_eq_true,ite_false,ite_true,mul_one,mul_neg_one] <;> + exact div_nonneg (mul_nonneg (by linarith only [h₁.1,h₁.2]) (by linarith only [h₂.1,h₂.2])) (by norm_num) + +lemma pairMean_mono {a b : ℝ} (ha : |a| ≤ 1) (hb : |b| ≤ 1) + {F G : Bool→Bool→ℝ} (h : ∀ x y,F x y ≤ G x y) : pairMean a b F ≤ pairMean a b G := by + apply Finset.sum_le_sum + intro x _ + apply Finset.sum_le_sum + intro y _ + exact mul_le_mul_of_nonneg_left (h x y) (pairBaseMass_nonneg ha hb x y) + +lemma pairMean_add (a b : ℝ) (F G : Bool→Bool→ℝ) : + pairMean a b (fun x y=>F x y+G x y)=pairMean a b F+pairMean a b G := by + simp only [pairMean,mul_add,Finset.sum_add_distrib] +lemma pairMean_sub (a b : ℝ) (F G : Bool→Bool→ℝ) : + pairMean a b (fun x y=>F x y-G x y)=pairMean a b F-pairMean a b G := by + simp only [pairMean,mul_sub,Finset.sum_sub_distrib] +lemma pairMean_mul (a b c : ℝ) (F : Bool→Bool→ℝ) : + pairMean a b (fun x y=>c*F x y)=c*pairMean a b F := by + simp only [pairMean,Finset.mul_sum,mul_left_comm] + +lemma abs_pairMean_le {a b : ℝ} (ha : |a| ≤ 1) (hb : |b| ≤ 1) + (F : Bool→Bool→ℝ) : |pairMean a b F| ≤ pairMean a b (fun x y=>|F x y|) := by + unfold pairMean + apply (Finset.abs_sum_le_sum_abs _ _).trans + apply Finset.sum_le_sum + intro x _ + apply (Finset.abs_sum_le_sum_abs _ _).trans_eq + apply Finset.sum_congr rfl + intro y _ + rw [abs_mul,abs_of_nonneg (pairBaseMass_nonneg ha hb x y)] + +lemma pair_gradient_mean (a b p s r : ℝ) : + pairMean a b (fun x y=>(p+r*(spinValue y-b))*(s+r*(spinValue x-a)))=p*s := by + rw [pairMean_explicit] + simp only [spinValue,Bool.false_eq_true,ite_false,ite_true] + ring + +lemma pair_gradient_square (a b p r : ℝ) : + pairMean a b (fun _ y=>(p+r*(spinValue y-b))^2)=p^2+(1-b^2)*r^2 := by + rw [pairMean_explicit] + simp only [spinValue,Bool.false_eq_true,ite_false,ite_true] + ring + +lemma pairMean_swap (a b : ℝ) (F : Bool→Bool→ℝ) : + pairMean a b F=pairMean b a (fun x y=>F y x) := by + rw [pairMean_explicit,pairMean_explicit] + ring + +lemma pair_second_gradient_square (a b s r : ℝ) : + pairMean a b (fun x _=>(s+r*(spinValue x-a))^2)=s^2+(1-a^2)*r^2 := by + rw [pairMean_swap] + exact pair_gradient_square b a s r + +lemma pair_polynomial_cross_mean (a b u c₁ d₁ c₂ d₂ : ℝ) : + pairMean a b (fun x y=>(spinValue x-a)*(spinValue y-b)*(1-u*spinValue x*spinValue y)* + (c₁+spinValue y*d₁)*(c₂+spinValue x*d₂))= + (1-a^2)*(1-b^2)*(d₁*d₂-u*c₁*c₂) := by + rw [pairMean_explicit] + simp only [spinValue,Bool.false_eq_true,ite_false,ite_true] + ring +end SKGap + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Terminal/SpinSpectralMassBelow.lean b/lean/OAI/Probability/SKGap/Terminal/SpinSpectralMassBelow.lean new file mode 100644 index 0000000000000000000000000000000000000000..eceb7bacf2a857e3d3a3c29993554bcc3ce8c0e1 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Terminal/SpinSpectralMassBelow.lean @@ -0,0 +1,91 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.LinearObservable + +namespace OAI + +section +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +open scoped BigOperators +namespace SKGapCutoff +open MeasureTheory + +noncomputable def spinSpectralMassBelow {n : ℕ} (J : Interaction n) + (hJ : ∀ i j, J i j = J j i) (hdiag : ∀ i, J i i = 0) (L : ℝ) : ℝ := + ∑ a, if spinEigenvalues J hJ hdiag a ≤ L then spinSpectralMass J hJ hdiag a else 0 + +lemma spinSpectralMassBelow_nonneg {n : ℕ} (J : Interaction n) + (hJ : ∀ i j, J i j = J j i) (hdiag : ∀ i, J i i = 0) (L : ℝ) : + 0 ≤ spinSpectralMassBelow J hJ hdiag L := by + apply Finset.sum_nonneg + intro a _ + split_ifs + · exact spinSpectralMass_nonneg J hJ hdiag a + · rfl + +lemma spinSpectralMeasure_Iic {n : ℕ} (J : Interaction n) + (hJ : ∀ i j, J i j = J j i) (hdiag : ∀ i, J i i = 0) (L : ℝ) : + spinSpectralMeasure J hJ hdiag (Set.Iic L) = + ENNReal.ofReal (spinSpectralMassBelow J hJ hdiag L) := by + simp only [spinSpectralMeasure, Measure.finsetSum_apply, Measure.smul_apply, + spinSpectralMassBelow] + rw [ENNReal.ofReal_sum_of_nonneg] + · apply Finset.sum_congr rfl + intro a _ + split_ifs with h + · simp only [Measure.dirac_apply' _ measurableSet_Iic, Set.mem_Iic, h, + Set.indicator_of_mem, smul_eq_mul, Pi.one_apply, mul_one] + · simp [h] + · intro a _ + split_ifs + · exact spinSpectralMass_nonneg J hJ hdiag a + · rfl + +lemma spinCorrelation_eq_spectralSum {n : ℕ} (J : Interaction n) + (hJ : ∀ i j, J i j = J j i) (hdiag : ∀ i, J i i = 0) (t : ℝ) : + spinCorrelation J t = ∑ a, spinSpectralMass J hJ hdiag a * + Real.exp (-spinEigenvalues J hJ hdiag a * t) := by + rw [← spinSpectralMeasure_integral J hJ hdiag (fun u => Real.exp (-u*t)), + spinSpectralMeasure_correlation] + rfl + +lemma spinCorrelation_lower_of_mass {n : ℕ} (J : Interaction n) + (hJ : ∀ i j, J i j = J j i) (hdiag : ∀ i, J i i = 0) + (L t : ℝ) (ht : 0 ≤ t) : + spinSpectralMassBelow J hJ hdiag L * Real.exp (-L * t) ≤ spinCorrelation J t := by + rw [spinCorrelation_eq_spectralSum J hJ hdiag, spinSpectralMassBelow, Finset.sum_mul] + apply Finset.sum_le_sum + intro a _ + split_ifs with h + · apply mul_le_mul_of_nonneg_left _ (spinSpectralMass_nonneg J hJ hdiag a) + exact Real.exp_le_exp.mpr (mul_le_mul_of_nonneg_right (neg_le_neg h) ht) + · simp only [zero_mul] + exact mul_nonneg (spinSpectralMass_nonneg J hJ hdiag a) (Real.exp_pos _).le + +theorem worstContinuous_lower_from_spectralMass {n : ℕ} (hn : 0 < n) + (J : Interaction n) (hJ : ∀ i j, J i j = J j i) (hdiag : ∀ i, J i i = 0) + {γ V c L t : ℝ} (ht : 0 ≤ t) (hγ : 0 < γ) (hgap : HasGap J γ) + (hV : 1 ≤ γ * V) (hc : 0 < c) (hmass : c ≤ spinSpectralMassBelow J hJ hdiag L) + (hvar : ∀ x, semigroup J t (fun y => overlap x y ^ 2) x - + (semigroup J t (overlap x) x) ^ 2 ≤ (n : ℝ) * V) : + (n : ℝ) * c ^ 2 * Real.exp (-2 * L * t) * (1 - worstContinuous J t) ≤ 8 * V := by + have he : c * Real.exp (-L * t) ≤ spinCorrelation J t := + (mul_le_mul_of_nonneg_right hmass (Real.exp_pos _).le).trans + (spinCorrelation_lower_of_mass J hJ hdiag L t ht) + have hl := worstContinuous_lower_from_spin hn J ht hγ hgap hV + (mul_pos hc (Real.exp_pos _)) he hvar + have hexp : Real.exp (-L * t) ^ 2 = Real.exp (-2 * L * t) := by + rw [← Real.exp_nat_mul] + congr 1 + norm_num + ring + rw [mul_pow, hexp] at hl + simpa only [mul_assoc] using hl + +end SKGapCutoff + +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Terminal/StableLiteralTerminal.lean b/lean/OAI/Probability/SKGap/Terminal/StableLiteralTerminal.lean new file mode 100644 index 0000000000000000000000000000000000000000..498e41f853e4d3571194e2073ed1cbc447dd98fd --- /dev/null +++ b/lean/OAI/Probability/SKGap/Terminal/StableLiteralTerminal.lean @@ -0,0 +1,159 @@ +import Mathlib +import OAI.Probability.SKGap.Terminal.TerminalIdentity +import OAI.Probability.SKGap.Stability.StableLiteralWeak +import OAI.Probability.SKGap.Gaussian.LiteralWeakTail + +namespace OAI + +section + +noncomputable section +open scoped BigOperators Matrix.Norms.Frobenius +namespace SKGapCutoff.Recipe +open SKGap.Stein Primary Static +universe u +theorem stable_literal_terminal_targets {j K B R ρ δ : ℝ} + (hj : 0≤j) (hK : 0≤K) (hB : 0≤B) (hδ : 0<δ) (hρ : 0≤ρ) + (hsmall : ρ≤δ/(2*(|j| *Real.exp (R/2)*(3*Real.exp (R/2)+16)+1))) + (k : ℕ) (f : KernelExpr) : + ∃A≥1,∀W C : ℝ,0≤W→0≤C→∀(Ω : Type u) (n : Ω→ℕ) + (J : ∀b,Interaction (n b)) (h r e : ∀b,Fin (n b)→ℝ) + (E : ∀b,Set (Spin (n b))) (P : ∀b,Observables (n b)), + (∀b,0j*(1-onsager j (J b) (h b) (k+1) v-SKGap.overlap (r b))) (r b) R ρ δ x)→ + (∀b x,0≤P b x)→(∀b,∑x,P b x=1)→ + (∀b x i,conditionalMean (P b) x i=mag j (J b) (h b) 1 x i)→ + ∃w y : ∀b,VectorFields (n b),∃c : ∀b,Observables (n b), + (∀b x,x∈E b→LiteralEquations (J b) j f (fld j (J b) (h b) (k+1)) + (mag j (J b) (h b) (k+1)) (w b) (y b) + (fun v=>j*(1-onsager j (J b) (h b) (k+1) v-SKGap.overlap (r b))) (c b) (r b) (e b) x) ∧ + (∀p≤k+1,LocalUniformWeak E P (fun b x=>∑i,residual j (J b) (h b) p x i*w b x i)) ∧ + LocalUniformWeak E P (fun b x=>∑i,residual j (J b) (h b) (k+1) x i*y b x i) ∧ + LocalUniformWeak E P (fun b x=>∑i,residual j (J b) (h b) (k+1) x i* + (Real.tanh (fld j (J b) (h b) (k+1) x i)/Real.sqrt (n b:ℝ))) ∧ + LocalUniformMultiplier E (fun b=>siteMean (fun x i=>phi (fld j (J b) (h b) (k+1) x i) (r b i) + (j*(1-onsager j (J b) (h b) (k+1) x-SKGap.overlap (r b))))) ∧ + LocalUniformMultiplier E (fun b x=>j*onsager j (J b) (h b) (k+1) x) ∧ + LocalUniformMultiplier E (fun b x=>Real.sqrt (n b:ℝ)*c b x) := by + let Cp:=localPrimaryBudget j K B (k+3) + let T:=(1+|j|)*Cp + have hCp : 0≤Cp:=localPrimaryBudget_nonneg hK hB _ + have hT : 0≤T:=by dsimp [T];positivity + obtain ⟨V,hV,S,hS,F,hF,Bc,hBc,Vc,hVc,hsol⟩:= + literal_complete_diagnostics j R ρ δ T K (2*Cp) Cp f hj hδ hρ hT + (mul_nonneg (by norm_num) hCp) hsmall + let A:=literalResidualBudget j f R Bc (k+1) + have hA : 1≤A:= + (show 1≤2+|literalCoefficientBudget f j R Bc| by linarith [abs_nonneg (literalCoefficientBudget f j R Bc)]).trans + (residualCoefficientBudget_ge j (by positivity) (k+1) 0) + refine ⟨A,hA,?_⟩ + intro W C hW hC Ω n J h r e E P hn hJ he hevent hstable hP hp hm + let a:=fun b v=>j*(1-onsager j (J b) (h b) (k+1) v-SKGap.overlap (r b)) + choose w y c heq hc hDc hdiag using fun b=>hsol (n b) (hn b) (J b) + (fld j (J b) (h b) (k+1)) (mag j (J b) (h b) (k+1)) (a b) (r b) (e b) + (hJ b) (hevent b).1 (he b) + have hs (b) (x : Spin (n b)) (hx : x∈flipNeighborhood (E b)) := + hstable b x (Or.inl hx) + have hsf (b) (x : Spin (n b)) (hx : x∈flipNeighborhood (E b)) (i : Fin (n b)) := + hstable b (flip x i) (Or.inr ⟨i,by simpa only [flip_flip] using hx⟩) + have hb (b) (x : Spin (n b)):=primary_literal_derivative_diagnostics (hn b) hK hB (J b) (h b) + (hevent b).1 k (fun v q hq=>(hevent b).2.1 (h b) v q hq) (r b) x + have heqE : ∀b x,x∈E b→LiteralEquations (J b) j f (fld j (J b) (h b) (k+1)) + (mag j (J b) (h b) (k+1)) (w b) (y b) (a b) (c b) (r b) (e b) x := by + intro b x hx;exact heq b x (hs b x (Or.inl hx)) + refine ⟨w,y,c,heqE,?_⟩ + apply literal_local_weak_terminal_targets j J h ⟨k+1,by omega⟩ f a c r e w y E hn he + hK hB hBc hT hVc hV hS hF hW hC + (fun b=>(hevent b).1) (fun b x q hq=>(hevent b).2.1 (h b) x q hq) + · intro b x hx;exact (hstable b x hx).a_bound + · intro b x hx;exact hc b x (hstable b x hx) + · intro b x hx + have hh:=(hb b x).1 + exact (le_add_of_nonneg_left (show 0≤SKGap.opNorm (derivativeMatrix (fld j (J b) (h b) (k+1)) x) from norm_nonneg _)).trans hh + · intro b x hx;exact hDc b x (hs b x hx) (hsf b x hx) (hb b x).1 (hb b x).2.1 + · exact heqE + · intro b x hx + exact (hdiag b x (primaryTree j (J b) (h b) x (k+1)) (hs b x hx) (hsf b x hx) + (hb b x).1 (hb b x).2.1 (primaryState_mag_bounded j (J b) (h b) (k+1) x) + (hb b x).2.2.1 (hb b x).2.2.2.1 (hb b x).2.2.2.2.1 (hb b x).2.2.2.2.2).monoCoefficient + (literalResidualBudget_exp j f R Bc (k+1)) + · exact hP + · exact hp + · exact hm + · exact hJ + · intro b x hx + exact (literal_closed_word_event (J b) j _ _ (a b) (r b) x (hn b) hj hδ hρ hsmall + (hs b x hx) (hevent b)).1 + · intro b x hx + exact (literal_closed_word_event (J b) j _ _ (a b) (r b) x (hn b) hj hδ hρ hsmall + (hs b x hx) (hevent b)).2 + +end SKGapCutoff.Recipe + +end +end + +section + +noncomputable section +open scoped BigOperators Matrix.Norms.Frobenius +namespace SKGapCutoff.Recipe +open Primary Static SKGap.Stein +universe u +variable {Ω : Type u} {n : Ω→ℕ} + + def literalTerminal {n : ℕ} (j : ℝ) (J : Interaction n) (h : Fin n→ℝ) (k : ℕ) + (w : VectorFields n) (c : Observables n) : Observables n := fun x=> + (∑i,(fld j J h (k+1) x i-h i-J.mulVec (mag j J h (k+2) x) i+ + j*onsager j J h (k+1) x*mag j J h (k+2) x i)*w x i)- + j*(onsager j J h (k+2) x-onsager j J h (k+1) x)*(n:ℝ)*c x + + theorem literal_terminal_weak (j : ℝ) (J : ∀b,Interaction (n b)) + (h r e : ∀b,Fin (n b)→ℝ) (k : ℕ) (f : KernelExpr) + (a c : ∀b,Observables (n b)) (w y : ∀b,VectorFields (n b)) + (E : ∀b,Set (Spin (n b))) (P : ∀b,Observables (n b)) + (hn : ∀b,0∑i,residual j (J b) (h b) p x i*w b x i)) + (hy : LocalUniformWeak E P (fun b x=>∑i,residual j (J b) (h b) (k+1) x i*y b x i)) + (hm : LocalUniformWeak E P (fun b x=>∑i,residual j (J b) (h b) (k+1) x i* + (Real.tanh (fld j (J b) (h b) (k+1) x i)/Real.sqrt (n b:ℝ)))) + (hχ : LocalUniformMultiplier E (fun b=>siteMean (fun x i=>phi (fld j (J b) (h b) (k+1) x i) (r b i) (a b x)))) + (ho : LocalUniformMultiplier E (fun b x=>j*onsager j (J b) (h b) (k+1) x)) + (hc : LocalUniformMultiplier E (fun b x=>Real.sqrt (n b:ℝ)*c b x)) : + LocalUniformWeak E P (fun b=>literalTerminal j (J b) (h b) k (w b) (c b)) := by + have hc' := (hm.mul hP hc).smul hP j + have hh:=(((hy.add (((hw (k+1) le_rfl).mul hP hχ).smul hP j)).sub + ((hw (k+1) le_rfl).mul hP ho)).sub ((hw k (by omega)).mul hP ho)).sub hc' + apply hh.congr_on + intro b x hx + have he:=(literalEquations_recipe (J b) j (Real.sqrt (n b:ℝ)) f + (fld j (J b) (h b) (k+1)) (mag j (J b) (h b) (k+1)) (w b) (y b) + (a b) (c b) (r b) (e b) (Real.sqrt_pos.mpr (Nat.cast_pos.mpr (hn b))).ne' x).mp (heq b x hx) + have hf:=he.2.1.trans (literalInitial_field (J b) j (Real.sqrt (n b:ℝ)) f + (fld j (J b) (h b) (k+1)) (mag j (J b) (h b) (k+1)) (w b) (y b) + (a b) (c b) (r b) (e b) x he.1 he.2.2) + have ht:=terminal_residual_identity (hn b) j (J b) (hJ b) (h b) k x (w b x) (y b x) + (siteMean (fun v i=>phi (fld j (J b) (h b) (k+1) v i) (r b i) (a b v)) x) (c b x) + (fun i=>congrFun hf i) + change _=literalTerminal j (J b) (h b) k (w b) (c b) x + unfold literalTerminal + rw [ht] + have hnorm : (Real.sqrt (n b:ℝ)*c b x)* + (∑i,residual j (J b) (h b) (k+1) x i*(Real.tanh (fld j (J b) (h b) (k+1) x i)/Real.sqrt (n b:ℝ)))= + c b x*(∑i,residual j (J b) (h b) (k+1) x i*mag j (J b) (h b) (k+2) x i) := by + exact normalized_pair_cancel (hn b) (residual j (J b) (h b) (k+1)) + (fun v i=>Real.tanh (fld j (J b) (h b) (k+1) v i)) (c b) x + rw [hnorm] + ring + +end SKGapCutoff.Recipe + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Terminal/TerminalChannel.lean b/lean/OAI/Probability/SKGap/Terminal/TerminalChannel.lean new file mode 100644 index 0000000000000000000000000000000000000000..177020b362958fdc3a85a4454eb73947e938bf10 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Terminal/TerminalChannel.lean @@ -0,0 +1,132 @@ +import Mathlib +import OAI.Probability.SKGap.Terminal.TerminalProbability +import OAI.Probability.SKGap.Terminal.TerminalHighProbability +import OAI.Probability.SKGap.Posterior.ChannelTranslation + +namespace OAI + +section +noncomputable section +namespace SKGap +open MeasureTheory ProbabilityTheory Real Set +open scoped BigOperators ENNReal +variable {n : ℕ} + +lemma channel_field_shift {T : ℝ} (hT : 0 ≤ T) (x : Spin n) (z : Fin n→ℝ) : + (fun i=>sqrt T*(z i+sqrt T*spinValue (x i)))=observationField T x z := by + funext i + simp only [observationField] + calc + _ = sqrt T*z i+(sqrt T)^2*spinValue (x i) := by ring + _ = _ := by rw [sq_sqrt hT];ring + +lemma gaussianChannel_terminal_bad (g : Disorder n) {T c : ℝ} (hT : 0 ≤ T) + (hh : ∀ x : Spin n,(channelReference n).real {z | ¬∀ f : Spin n→ℝ, + variance g (observationField T x z) f ≤ 2*dirichlet g (observationField T x z) f} ≤ exp (-c*(n:ℝ))) : + (gaussianChannelLaw g T).real {z | ¬∀ f : Spin n→ℝ, + variance g (fun i=>sqrt T*z i) f ≤ 2*dirichlet g (fun i=>sqrt T*z i) f} ≤ exp (-c*(n:ℝ)) := by + let B : Set (Fin n→ℝ) := {z | ¬∀ f : Spin n→ℝ, + variance g (fun i=>sqrt T*z i) f ≤ 2*dirichlet g (fun i=>sqrt T*z i) f} + have hB : MeasurableSet B := + ((terminal_goodSet_closed g 2).measurableSet.compl).preimage (by fun_prop) + have he := gaussianChannel_event g hT B hB + have hx (x : Spin n) : channelReference n + ((fun z : Fin n→ℝ=>fun i=>z i+sqrt T*spinValue (x i)) ⁻¹' B) ≤ ENNReal.ofReal (exp (-c*(n:ℝ))) := by + have hb : ((fun z : Fin n→ℝ=>fun i=>z i+sqrt T*spinValue (x i)) ⁻¹' B)= + {z | ¬∀ f : Spin n→ℝ,variance g (observationField T x z) f ≤ + 2*dirichlet g (observationField T x z) f} := by + ext z + simp only [Set.mem_preimage,B,Set.mem_ofPred_eq,channel_field_shift hT] + rw [hb] + exact (ENNReal.toReal_le_toReal (measure_ne_top _ _) ENNReal.ofReal_ne_top).mp + (by simpa only [measureReal_def,ENNReal.toReal_ofReal (exp_pos _).le] using hh x) + have hs : (∑ x : Spin n,ENNReal.ofReal (mass g 0 x))=1 := by + rw [← ENNReal.ofReal_sum_of_nonneg (fun x _=>mass_nonneg g 0 x),sum_mass] + exact ENNReal.ofReal_one + have hb : gaussianChannelLaw g T B ≤ ENNReal.ofReal (exp (-c*(n:ℝ))) := by + rw [he] + calc + _ ≤ ∑ x,ENNReal.ofReal (mass g 0 x)*ENNReal.ofReal (exp (-c*(n:ℝ))) := + Finset.sum_le_sum (fun x _=>by gcongr;exact hx x) + _ = _ := by rw [← Finset.sum_mul,hs,one_mul] + have hr := ENNReal.toReal_mono ENNReal.ofReal_ne_top hb + simpa only [measureReal_def,ENNReal.toReal_ofReal (exp_pos _).le] using hr +end SKGap + +end +end + +section +noncomputable section +namespace SKGap +open MeasureTheory ProbabilityTheory Real Set Filter +open scoped BigOperators Topology Matrix.Norms.L2Operator +variable {n : ℕ} + +lemma terminalMatrixBound_nonneg {j : ℝ} (hj : 0 ≤ j) : 0 ≤ terminalMatrixBound j := by + unfold terminalMatrixBound terminalRowBound + have hlog : 0 ≤ log (2:ℝ) := log_nonneg (by norm_num) + positivity + +lemma terminal_endpoint_from_data {M α ε T : ℝ} (hM : 0 ≤ M) (hT : 0 < T) (hε : 0 ≤ ε) + (hsmall : M^2 ≤ (T/4)^2*α/2) + (hnum : 400001*(ε+M*(2*sqrt (1/cosh (T/4)^2)+1/cosh (T/4)^2)) ≤ 1/4) + (hp : exp (-T/8)*(exp 1-1) ≤ α/4) + (hn₁ : terminalEntryScale n ≤ 1/1000) (hn₂ : 800000*(M*terminalEntryScale n^2) ≤ 1/4) + (g : Disorder n) (hg : terminalMatrixData M α ε g) : + (gaussianChannelLaw g T).real {z | ¬∀ f : Spin n→ℝ, + variance g (fun i=>sqrt T*z i) f ≤ 2*dirichlet g (fun i=>sqrt T*z i) f} ≤ exp (-(α/4)*(n:ℝ)) := by + apply gaussianChannel_terminal_bad g hT.le + intro x + have hc (i k : Fin n) : |tanh (coupling g i k)| ≤ 1/1000 := + (abs_tanh_le_abs _).trans ((hg.1 i k).trans hn₁) + have hh := terminal_probability_fixedSpin g hM hT hε hg.2.1 hg.2.2.1 hg.2.2.2.1 hc hg.2.2.2.2.1 + (terminalMatrixData_forms g hg) hsmall (by linarith only [hnum,hn₂]) hp x + convert hh using 1 + congr 1 + ring + +lemma terminal_numeric_eventually (M : ℝ) : ∀ᶠ n : ℕ in atTop, + terminalEntryScale n ≤ 1/1000 ∧ 800000*(M*terminalEntryScale n^2) ≤ 1/4 := by + have ht := (terminalEntryScale_tendsto.pow 2).const_mul M |>.const_mul 800000 + simp only [zero_pow (by decide : (2:ℕ) ≠ 0),mul_zero] at ht + exact (terminalEntryScale_tendsto.eventually (ge_mem_nhds (by norm_num : (0:ℝ) < 1/1000))).and + (ht.eventually (ge_mem_nhds (by norm_num : (0:ℝ) < 1/4))) + +theorem terminal_gap_high_probability {β : ℝ} (hβ : 0 < β) : + ∃ T a : ℝ,0 < T ∧ 0 < a ∧ ∃ Ω : (n : ℕ)→Set (Disorder n), + (∀ n,MeasurableSet (Ω n)) ∧ + Tendsto (fun n=>(disorderLaw β n).real (Ω n)) atTop (𝓝 1) ∧ + ∀ (n : ℕ) (g : Disorder n),g ∈ Ω n → + (gaussianChannelLaw g T).real {z | ¬∀ f : Spin n→ℝ, + variance g (fun i=>sqrt T*z i) f ≤ 2*dirichlet g (fun i=>sqrt T*z i) f} ≤ exp (-a*(n:ℝ)) := by + let ε : ℝ := 1/(16*400001) + have hε : 0 < ε := by norm_num [ε] + obtain ⟨α,l,hα,hαhalf,hl,hedge,h₅,h₆⟩ := sparse_parameters (sq_pos_of_pos hβ) hε + let M := terminalMatrixBound (β^2) + have hM : 0 ≤ M := terminalMatrixBound_nonneg (sq_nonneg β) + obtain ⟨T,hT,hsmall,hnum,hp⟩ := terminalTime_exists hM hα (show 400001*ε < 1/4 by norm_num [ε]) + obtain ⟨N,hN⟩ := eventually_atTop.mp (terminal_numeric_eventually M) + let Ω : (n : ℕ)→Set (Disorder n) := fun n=>if N ≤ n then {g | terminalMatrixData M α ε g} else ∅ + have hΩ (n : ℕ) : MeasurableSet (Ω n) := by + dsimp [Ω] + split_ifs + · exact terminalMatrixData_measurable M α ε + · exact MeasurableSet.empty + refine ⟨T,α/4,hT,(by positivity),Ω,hΩ,?_,?_⟩ + · apply Tendsto.congr' _ (terminalMatrixData_actual_whp hβ hα.le hε hl hedge h₅ h₆) + filter_upwards [eventually_ge_atTop N] with n hn + simp only [Ω,ite_eq_left hn] + rfl + · intro n g hg + have hn : N ≤ n := by + by_contra hn + simp only [Ω,ite_eq_right hn,Set.mem_empty_iff_false] at hg + have hd : terminalMatrixData M α ε g := by simpa only [Ω,ite_eq_left hn,Set.mem_ofPred_eq] using hg + exact terminal_endpoint_from_data hM hT hε.le hsmall hnum hp (hN n hn).1 (hN n hn).2 g hd +end SKGap + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Terminal/TerminalDeterministic.lean b/lean/OAI/Probability/SKGap/Terminal/TerminalDeterministic.lean new file mode 100644 index 0000000000000000000000000000000000000000..6489c8042a35707a53a462a697a36ba3b582bb59 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Terminal/TerminalDeterministic.lean @@ -0,0 +1,100 @@ +import Mathlib +import OAI.Probability.SKGap.Terminal.PairGibbsBound +import OAI.Probability.SKGap.Entropy.SparseWeightedForm +import OAI.Probability.SKGap.Terminal.SmallFieldCount + +namespace OAI + +section +noncomputable section +namespace SKGap +open Matrix Real +open scoped BigOperators RealInnerProductSpace Matrix.Norms.L2Operator +variable {n : ℕ} + +lemma one_sub_tanh_sq (x : ℝ) : 1-tanh x^2=1/cosh x^2 := by + rw [tanh_eq_sinh_div_cosh] + have hc := (cosh_pos x).ne' + have he := cosh_sq_sub_sinh_sq x + field_simp + nlinarith only [he] + +lemma variance_tanh_le_cosh {t x : ℝ} (ht : 0 ≤ t) (hx : t ≤ |x|) : + 1-tanh x^2 ≤ 1/cosh t^2 := by + rw [one_sub_tanh_sq] + have hcosh : cosh t ≤ cosh x := cosh_le_cosh.mpr (by simpa only [abs_of_nonneg ht] using hx) + have hs := (sq_le_sq₀ (cosh_pos t).le (cosh_pos x).le).mpr hcosh + exact one_div_le_one_div_of_le (sq_pos_of_pos (cosh_pos t)) hs + +def terminalU (g : Disorder n) : Matrix (Fin n) (Fin n) ℝ := Matrix.of (fun i j=>tanh (coupling g i j)) +def terminalQ (g : Disorder n) : Matrix (Fin n) (Fin n) ℝ := Matrix.of (fun i j=>tanh (coupling g i j)^2) + +theorem terminal_deterministic (g : Disorder n) (h : Fin n→ℝ) {M t α ε R : ℝ} + (hM : 0 ≤ M) (ht : 0 < t) (hε : 0 ≤ ε) + (hJ : ‖Matrix.of (coupling g)‖ ≤ M) + (hU : ‖terminalU g‖ ≤ M) (hQ : ‖terminalQ g‖ ≤ M) + (hc : ∀ i j,|tanh (coupling g i j)| ≤ 1/1000) + (hR : ∀ i,∑ j,tanh (coupling g i j)^4 ≤ R) + (hsparse : ∀ S : Finset (Fin n),(S.card:ℝ) ≤ α*(n:ℝ) → + ∀ w : EuclideanSpace ℝ (Fin n),(∀ i,i ∉ S → w i=0) → + |⟪w,Matrix.toEuclideanCLM (𝕜 := ℝ) (n := Fin n) (terminalU g) w⟫| ≤ ε*‖w‖^2 ∧ + |⟪w,Matrix.toEuclideanCLM (𝕜 := ℝ) (n := Fin n) (terminalQ g) w⟫| ≤ ε*‖w‖^2) + (hB : ((Finset.univ.filter (fun i=>|h i| < 2*t)).card:ℝ) ≤ α*(n:ℝ)/2) + (hsmall : M^2 ≤ t^2*α/2) + (hnum : 800000*R+400001*(ε+M*(2*sqrt (1/cosh t^2)+1/cosh t^2)) ≤ 1/2) : + ∀ f : Spin n→ℝ,variance g h f ≤ 2*dirichlet g h f := by + have hη : (0:ℝ) ≤ 1/cosh t^2 := by positivity + have hS := all_configurations_small_fields g h hM ht hJ hB hsmall + let k := ε+M*(2*sqrt (1/cosh t^2)+1/cosh t^2) + have hcurv (f : Spin n→ℝ) : (1/2:ℝ)*dirichlet g h f ≤ + expectation g h (fun x=>heatBathGenerator g h f x^2) := by + let q := fun x=>∑ i,siteVariance g h i x*spinGradient i f x^2 + have hq : expectation g h q=dirichlet g h f := by + dsimp [q] + rw [expectation_sum,dirichlet_weighted] + have hform (x : Spin n) : + (∑ i,∑ j,tanh (coupling g i j)*weightedGradient g h i f x*weightedGradient g h j f x) ≤ k*q x ∧ + (∑ i,∑ j,tanh (coupling g i j)^2*|weightedGradient g h i f x*weightedGradient g h j f x|) ≤ k*q x := by + let S := Finset.univ.filter (fun i=>|localField g h i x| < t) + have hv (i : Fin n) : 0 ≤ siteVariance g h i x := (siteVariance_pos g h i x).le + have hvsmall (i : Fin n) (hi : i ∉ S) : siteVariance g h i x ≤ 1/cosh t^2 := by + apply variance_tanh_le_cosh ht.le + have hi' : ¬|localField g h i x| < t := by simpa only [S,Finset.mem_filter,Finset.mem_univ,true_and] using hi + exact le_of_not_gt hi' + have hboundU := weighted_sparse_form (terminalU g) S (fun i=>siteVariance g h i x) + (fun i=>spinGradient i f x) hη hε hM hv (fun i=>siteVariance_le_one g h i x) hvsmall hU + (fun w hw=>(hsparse S (hS x) w hw).1) + have hboundQ := weighted_sparse_form (terminalQ g) S (fun i=>siteVariance g h i x) + (fun i=>|spinGradient i f x|) hη hε hM hv (fun i=>siteVariance_le_one g h i x) hvsmall hQ + (fun w hw=>(hsparse S (hS x) w hw).2) + constructor + · exact (le_abs_self _).trans hboundU + · simp only [sq_abs] at hboundQ + have he : (∑ i,∑ j,tanh (coupling g i j)^2*|weightedGradient g h i f x*weightedGradient g h j f x|)= + ∑ i,∑ j,terminalQ g i j*(siteVariance g h i x*|spinGradient i f x|)* + (siteVariance g h j x*|spinGradient j f x|) := by + apply Finset.sum_congr rfl + intro i _ + apply Finset.sum_congr rfl + intro j _ + simp only [terminalQ,Matrix.of_apply,weightedGradient,abs_mul,abs_of_nonneg (hv i),abs_of_nonneg (hv j)] + ring + rw [he] + exact (le_abs_self _).trans hboundQ + have hu := expectation_mono g h (fun x=>(hform x).1) + have hq' := expectation_mono g h (fun x=>(hform x).2) + rw [expectation_const_mul,hq] at hu hq' + have hl := gibbs_signed_curvature g h f hc hR + have hd := dirichlet_nonneg g h f + have hn : 800000*R+400001*k ≤ 1/2 := hnum + have hh := mul_le_mul_of_nonneg_right hn hd + nlinarith only [hu,hq',hl,hh] + intro f + have hp := heatBath_curvature_poincare g h (by norm_num : (0:ℝ) < 1/2) hcurv f + linarith only [hp] +end SKGap + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Terminal/TerminalHighProbability.lean b/lean/OAI/Probability/SKGap/Terminal/TerminalHighProbability.lean new file mode 100644 index 0000000000000000000000000000000000000000..c3e20226a032f57ad08ef1c008f617034fd97a4e --- /dev/null +++ b/lean/OAI/Probability/SKGap/Terminal/TerminalHighProbability.lean @@ -0,0 +1,105 @@ +import Mathlib +import OAI.Probability.SKGap.Terminal.TerminalMatrixMeasurable + +namespace OAI + +section +noncomputable section +namespace SKGap +open MeasureTheory ProbabilityTheory Real Set Filter +open scoped Topology + +lemma terminalMatrixData_small_eventually {j ε : ℝ} (hε : 0 < ε) : + ∀ᶠ n : ℕ in atTop,terminalEntryScale n ≤ 1 ∧ + terminalEntryScale n*(1+terminalRowBound j/3) ≤ 2*ε/3 := by + have ht := terminalEntryScale_tendsto + have ht' := ht.mul_const (1+terminalRowBound j/3) + exact (ht.eventually (ge_mem_nhds (by norm_num : (0:ℝ) < 1))).and + (by simpa only [zero_mul] using ht'.eventually (ge_mem_nhds (by simpa only [zero_mul] using (show (0:ℝ) < 2*ε/3 by positivity) : (0:ℝ)*(1+terminalRowBound j/3) < 2*ε/3))) + +lemma terminalMatrixData_actual_bad {β α ε l : ℝ} (hβ : 0 < β) (hα : 0 ≤ α) + (hε : 0 < ε) (hl : 0 ≤ l) (hedge : 2*sqrt (β^2*α) ≤ ε/6) : + ∀ᶠ n : ℕ in atTop,(disorderLaw β n).real {g | ¬ terminalMatrixData (terminalMatrixBound (β^2)) α ε g} ≤ + terminalRawTail (β^2) α ε n l := by + have hn : ∀ᶠ n : ℕ in atTop,1 ≤ n := eventually_ge_atTop 1 + filter_upwards [terminalMatrixData_small_eventually (j:=β^2) hε,hn] with n hn hnpos + let : NeZero n := ⟨by omega⟩ + have hm := (terminalMatrixData_measurable (n:=n) (terminalMatrixBound (β^2)) α ε).compl + change MeasurableSet {g : Disorder n | ¬terminalMatrixData (terminalMatrixBound (β^2)) α ε g} at hm + rw [← (goe_actual_disorder_hasLaw β n).measureReal_eq hm] + apply (measureReal_mono (μ:=gaussianCoordinates (MatrixCoordinates (Fin n))) ?_ (measure_ne_top _ _)).trans + (terminalRaw_bad_bound (sq_pos_of_pos hβ) hα hε hl hedge) + intro g hg hr + exact hg (terminalMatrixData_of_raw (sq_pos_of_pos hβ) hε.le hn.1 hn.2 g hr) + +lemma terminalMatrixData_actual_whp {β α ε l : ℝ} (hβ : 0 < β) (hα : 0 ≤ α) + (hε : 0 < ε) (hl : 0 ≤ l) (hedge : 2*sqrt (β^2*α) ≤ ε/6) + (h₅ : 0 < ε^2/(36*π^2*(β^2))-(l*α+log (1+exp (-l)))) + (h₆ : 0 < ε/(4*(β^2))-(l*α+log (1+exp (-l))+α*log 2)) : + Tendsto (fun n : ℕ=>(disorderLaw β n).real {g | terminalMatrixData (terminalMatrixBound (β^2)) α ε g}) atTop (𝓝 1) := by + have hb : Tendsto (fun n : ℕ=>(disorderLaw β n).real {g | ¬terminalMatrixData (terminalMatrixBound (β^2)) α ε g}) atTop (𝓝 0) := + squeeze_zero' (Eventually.of_forall (fun _=>measureReal_nonneg)) + (terminalMatrixData_actual_bad hβ hα hε hl hedge) (terminalRawTail_tendsto (sq_pos_of_pos hβ) h₅ h₆) + have he (n : ℕ) : (disorderLaw β n).real {g | terminalMatrixData (terminalMatrixBound (β^2)) α ε g}= + 1-(disorderLaw β n).real {g | ¬terminalMatrixData (terminalMatrixBound (β^2)) α ε g} := by + have hm := terminalMatrixData_measurable (n:=n) (terminalMatrixBound (β^2)) α ε + have h := measureReal_compl hm (μ:=disorderLaw β n) + simp only [probReal_univ] at h + change (disorderLaw β n).real {g | ¬terminalMatrixData (terminalMatrixBound (β^2)) α ε g}=1- _ at h + linarith only [h] + simp_rw [he] + simpa only [sub_zero] using tendsto_const_nhds.sub hb +end SKGap + +end +end + +section +noncomputable section +namespace SKGap +open Filter Real +open scoped Topology + +lemma tendsto_cosh_real_atTop : Tendsto cosh atTop atTop := by + have he : Tendsto (fun x : ℝ=>exp x/2) atTop atTop := by + simpa only [div_eq_mul_inv,mul_comm,one_mul,id_eq] using tendsto_exp_atTop.const_mul_atTop (by norm_num : (0:ℝ) < 1/2) + apply tendsto_atTop_mono _ he + intro x + rw [cosh_eq] + have hp := exp_pos (-x) + linarith only [hp] + +lemma terminalTime_exists {M α ε : ℝ} (_hM : 0 ≤ M) (hα : 0 < α) + (hε : 400001*ε < 1/4) : + ∃ T : ℝ,0 < T ∧ M^2 ≤ (T/4)^2*α/2 ∧ + 400001*(ε+M*(2*sqrt (1/cosh (T/4)^2)+1/cosh (T/4)^2)) ≤ 1/4 ∧ + exp (-T/8)*(exp 1-1) ≤ α/4 := by + have hT4 : Tendsto (fun T : ℝ=>T/4) atTop atTop := by + simpa only [div_eq_mul_inv,mul_comm,one_mul,id_eq] using tendsto_id.const_mul_atTop (by norm_num : (0:ℝ) < 1/4) + have hs : Tendsto (fun T : ℝ=>1/cosh (T/4)^2) atTop (𝓝 0) := by + have h := tendsto_inv_atTop_zero.comp (tendsto_cosh_real_atTop.comp hT4) + simpa only [Function.comp_apply,one_div,inv_pow,zero_pow (by decide : (2:ℕ) ≠ 0)] using h.pow 2 + have hsroot := hs.sqrt + have hsfull : Tendsto (fun T : ℝ=>400001*(ε+M*(2*sqrt (1/cosh (T/4)^2)+1/cosh (T/4)^2))) atTop (𝓝 (400001*ε)) := by + simpa only [sqrt_zero,mul_zero,add_zero] using (((hsroot.const_mul 2).add hs).const_mul M |>.const_add ε |>.const_mul 400001) + have he : Tendsto (fun T : ℝ=>exp (-T/8)*(exp 1-1)) atTop (𝓝 0) := by + have hT8 : Tendsto (fun T : ℝ=>T/8) atTop atTop := by + simpa only [div_eq_mul_inv,mul_comm,one_mul,id_eq] using tendsto_id.const_mul_atTop (by norm_num : (0:ℝ) < 1/8) + simpa only [Function.comp_apply,neg_div,zero_mul] using (tendsto_exp_neg_atTop_nhds_zero.comp hT8).mul_const (exp 1-1) + have ht : ∀ᶠ T : ℝ in atTop,4*sqrt (2*M^2/α)+1 ≤ T := eventually_ge_atTop _ + obtain ⟨T,⟨htT,htnum⟩,htp⟩ := (ht.and (hsfull.eventually (ge_mem_nhds hε))).and + (he.eventually (ge_mem_nhds (by positivity : (0:ℝ) < α/4))) |>.exists + refine ⟨T,?_,?_,htnum,htp⟩ + · have hr := sqrt_nonneg (2*M^2/α) + linarith only [htT,hr] + · have hr := sqrt_nonneg (2*M^2/α) + have hsquare := sq_sqrt (by positivity : 0 ≤ 2*M^2/α) + have hbound : 2*M^2/α ≤ (T/4)^2 := by nlinarith only [hr,hsquare,htT] + have hmul := (div_le_iff₀ hα).mp hbound + nlinarith only [hmul] +end SKGap + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Terminal/TerminalIdentity.lean b/lean/OAI/Probability/SKGap/Terminal/TerminalIdentity.lean new file mode 100644 index 0000000000000000000000000000000000000000..aed0d801d8c91c604ffe3e8a0172c8e586654415 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Terminal/TerminalIdentity.lean @@ -0,0 +1,64 @@ +import Mathlib +import OAI.Probability.SKGap.Localization.ResidualInduction + +namespace OAI + +section + +noncomputable section +open scoped BigOperators +namespace SKGapCutoff.Primary +open Matrix +variable {n : ℕ} + +lemma terminal_field_identity (j : ℝ) (J : Interaction n) (h : Fin n→ℝ) + (k : ℕ) (x : Spin n) (i : Fin n) : + fld j J h (k+1) x i-h i-J.mulVec (mag j J h (k+2) x) i+ + j*onsager j J h (k+1) x*mag j J h (k+2) x i = + J.mulVec (residual j J h (k+1) x) i- + j*onsager j J h (k+1) x*(residual j J h k x i+residual j J h (k+1) x i) := by + rw [fld_eq] + simp only [Nat.add_sub_cancel,residual,Matrix.mulVec,dotProduct,mul_sub,Finset.sum_sub_distrib] + ring + +theorem terminal_residual_identity (hn : 0coupling g i k) := by + unfold coupling + split_ifs <;> fun_prop + +lemma continuous_coupling_matrix : Continuous (fun g : Disorder n=>Matrix.of (coupling g)) := by + apply continuous_pi + intro i + apply continuous_pi + exact continuous_coupling_entry i + +lemma continuous_tanh_real : Continuous tanh := + continuous_iff_continuousAt.mpr (fun x=>(hasDerivAt_tanh x).continuousAt) + +lemma continuous_terminalU : Continuous (terminalU (n:=n)) := by + apply continuous_pi + intro i + apply continuous_pi + intro k + exact continuous_tanh_real.comp (continuous_coupling_entry i k) + +lemma continuous_terminalQ : Continuous (terminalQ (n:=n)) := by + apply continuous_pi + intro i + apply continuous_pi + intro k + exact (continuous_tanh_real.comp (continuous_coupling_entry i k)).pow 2 + +lemma continuous_principalOperatorNorm (S : Finset (Fin n)) : + Continuous (fun M : Matrix (Fin n) (Fin n) ℝ=>principalOperatorNorm M S) := by + unfold principalOperatorNorm + exact (continuous_matrixOperator.comp (by unfold Matrix.submatrix;fun_prop)).norm + +lemma terminalMatrixData_measurable (M α ε : ℝ) : + MeasurableSet {g : Disorder n | terminalMatrixData M α ε g} := by + classical + unfold terminalMatrixData + simp only [ofPred_and,ofPred_forall] + apply MeasurableSet.inter + (MeasurableSet.iInter (fun i=>MeasurableSet.iInter (fun k=>measurableSet_le (continuous_coupling_entry i k).abs.measurable measurable_const))) + apply MeasurableSet.inter (measurableSet_le continuous_coupling_matrix.norm.measurable measurable_const) + apply MeasurableSet.inter (measurableSet_le continuous_terminalU.norm.measurable measurable_const) + apply MeasurableSet.inter (measurableSet_le continuous_terminalQ.norm.measurable measurable_const) + apply MeasurableSet.inter + · apply MeasurableSet.iInter + intro i + apply measurableSet_le _ measurable_const + exact (continuous_finsetSum _ (fun k _=>(continuous_tanh_real.comp (continuous_coupling_entry i k)).pow 4)).measurable + · apply MeasurableSet.iInter + intro S + apply MeasurableSet.iInter + intro _ + exact (measurableSet_le ((continuous_principalOperatorNorm S).comp continuous_terminalU).measurable measurable_const).inter + (measurableSet_le ((continuous_principalOperatorNorm S).comp continuous_terminalQ).measurable measurable_const) +end SKGap + +end +end + +section +noncomputable section +namespace SKGap +open Filter Real +open scoped Topology + +lemma nat_pow_exp_div_tendsto {c : ℝ} (hc : 0 < c) (k : ℕ) : + Tendsto (fun n : ℕ=>(n:ℝ)^k*exp (-(n:ℝ)/c)) atTop (𝓝 0) := by + convert nat_pow_exp_neg_tendsto (inv_pos.mpr hc) k using 1 + ext n + congr 2 + ring + +lemma nat_pow_exp_sqrt_div_tendsto {c : ℝ} (hc : 0 < c) (k : ℕ) : + Tendsto (fun n : ℕ=>(n:ℝ)^k*exp (-sqrt (n:ℝ)/c)) atTop (𝓝 0) := by + convert nat_pow_exp_sqrt_tendsto (inv_pos.mpr hc) k using 1 + ext n + congr 2 + ring + +lemma terminalRawTail_tendsto {j α ε l : ℝ} (hj : 0 < j) + (h₅ : 0 < ε^2/(36*π^2*j)-(l*α+log (1+exp (-l)))) + (h₆ : 0 < ε/(4*j)-(l*α+log (1+exp (-l))+α*log 2)) : + Tendsto (fun n : ℕ=>terminalRawTail j α ε n l) atTop (𝓝 0) := by + have ht1 := (nat_pow_exp_div_tendsto (by positivity : 0 < π^2*j) 0).const_mul 2 + have ht2 := (nat_pow_exp_sqrt_div_tendsto (by positivity : 0 < 8*j) 1).const_mul 2 + have ht3 := (nat_pow_exp_sqrt_div_tendsto (by positivity : 0 < 4*j) 2).const_mul 2 + have ht4 := nat_pow_exp_neg_tendsto (by norm_num : (0:ℝ) < 1) 1 + have ht5 := (nat_pow_exp_neg_tendsto h₅ 0).const_mul 2 + have ht6 := nat_pow_exp_neg_tendsto h₆ 1 + have hh := ((((ht1.add ht2).add ht3).add ht4).add ht5).add ht6 + simpa only [terminalRawTail,pow_zero,pow_one,one_mul,mul_zero,add_zero,neg_mul,mul_assoc,mul_comm,mul_left_comm,mul_neg,mul_neg_one,zero_mul,mul_one] using hh +end SKGap + +end +end + +section +noncomputable section +namespace SKGap +open Filter Real +open scoped Topology + +lemma sparse_parameters {j ε : ℝ} (hj : 0 < j) (hε : 0 < ε) : + ∃ α l : ℝ,0 < α ∧ α < 1/2 ∧ 0 ≤ l ∧ 2*sqrt (j*α) ≤ ε/6 ∧ + 0 < ε^2/(36*π^2*j)-(l*α+log (1+exp (-l))) ∧ + 0 < ε/(4*j)-(l*α+log (1+exp (-l))+α*log 2) := by + let δ := min (ε^2/(72*π^2*j)) (ε/(8*j)) + have hδ : 0 < δ := lt_min (by positivity) (by positivity) + have ht : Tendsto (fun l : ℝ=>log (1+exp (-l))) atTop (𝓝 0) := by + have hplus : Tendsto (fun l : ℝ=>1+exp (-l)) atTop (𝓝 1) := by + simpa using (tendsto_const_nhds.add tendsto_exp_neg_atTop_nhds_zero : Tendsto (fun l : ℝ=>1+exp (-l)) atTop (𝓝 (1+0))) + have h := (continuousAt_log (by norm_num : (1:ℝ) ≠ 0)).tendsto.comp hplus + simpa only [Function.comp_def, log_one] using h + obtain ⟨l,hl,hlδ⟩ := ((eventually_ge_atTop (0:ℝ)).and (ht.eventually (gt_mem_nhds (by linarith only [hδ] : (0:ℝ) < δ/2)))).exists + let α := min (1/4:ℝ) (min (ε^2/(144*j)) (δ/(2*(l+log 2+1)))) + have hlog : (0:ℝ) ≤ log 2 := log_nonneg (by norm_num) + have hden : 0 < 2*(l+log 2+1) := by linarith only [hl,hlog] + have hα : 0 < α := lt_min (by norm_num) (lt_min (by positivity) (div_pos hδ hden)) + have hαmax : α ≤ 1/4 := min_le_left _ _ + have hαedge : α ≤ ε^2/(144*j) := (min_le_right _ _).trans (min_le_left _ _) + have hαrate : α ≤ δ/(2*(l+log 2+1)) := (min_le_right _ _).trans (min_le_right _ _) + have hprod : α*(l+log 2+1) ≤ δ/2 := by + have h := (le_div_iff₀ hden).mp hαrate + nlinarith only [h] + have hedge : 2*sqrt (j*α) ≤ ε/6 := by + have hm := (le_div_iff₀ (by positivity : 0 < 144*j)).mp hαedge + have hs := sq_sqrt (mul_nonneg hj.le hα.le) + nlinarith only [hm,hs,sqrt_nonneg (j*α),hε] + refine ⟨α,l,hα,(by linarith only [hαmax]),hl,hedge,?_,?_⟩ + · have hδ1 : δ ≤ ε^2/(72*π^2*j) := min_le_left _ _ + have ha := mul_nonneg hα.le hlog + have he : ε^2/(36*π^2*j)=2*(ε^2/(72*π^2*j)) := by ring + rw [he] + nlinarith only [hδ1,hδ,hprod,hlδ,ha,hα] + · have hδ2 : δ ≤ ε/(8*j) := min_le_right _ _ + have he : ε/(4*j)=2*(ε/(8*j)) := by ring + rw [he] + nlinarith only [hδ2,hδ,hprod,hlδ,hα] +end SKGap + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Terminal/TerminalMatrixTransfer.lean b/lean/OAI/Probability/SKGap/Terminal/TerminalMatrixTransfer.lean new file mode 100644 index 0000000000000000000000000000000000000000..175885a6671018bdeb7962cf991c8c1ad11dd938 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Terminal/TerminalMatrixTransfer.lean @@ -0,0 +1,256 @@ +import Mathlib +import OAI.Probability.SKGap.Matrix.GOESparse +import OAI.Probability.SKGap.Matrix.TanhMatrixBounds + +namespace OAI + +section +noncomputable section +namespace SKGap +open Matrix Real +open scoped BigOperators RealInnerProductSpace Matrix.Norms.L2Operator +variable {n : ℕ} + +lemma coupling_symmetric (g : Disorder n) (i k : Fin n) : coupling g i k=coupling g k i := by + by_cases h : i=k + · subst k;rfl + · rcases lt_or_gt_of_ne h with h | h <;> simp [coupling,h,not_lt_of_gt h] + +lemma coupling_norm_from_goe (r d M : ℝ) (g : MatrixCoordinates (Fin n)→ℝ) + (hd : 0 ≤ d) (hg : ‖matrixOperator (goeMatrix r g)‖ ≤ M) + (hdiag : ∀ i,|goeMatrix r g i i| ≤ d) : + ‖Matrix.of (coupling (goeDisorder r g))‖ ≤ M+d := by + rw [coupling_goeDisorder] + apply (norm_sub_le _ _).trans + apply add_le_add _ (diagonal_norm_le hd _ hdiag) + rwa [matrixOperator_eq_toEuclideanCLM,Matrix.l2_opNorm_toEuclideanCLM] at hg + +lemma coupling_principal_norm_from_goe (r d ε : ℝ) (g : MatrixCoordinates (Fin n)→ℝ) + (S : Finset (Fin n)) (hd : 0 ≤ d) + (hg : principalOperatorNorm (goeMatrix r g) S ≤ ε) + (hdiag : ∀ i,|goeMatrix r g i i| ≤ d) : + ‖(Matrix.of (coupling (goeDisorder r g))).submatrix (fun i : S=>i.1) (fun i : S=>i.1)‖ ≤ ε+d := by + rw [coupling_goeDisorder] + have he : (goeMatrix r g-Matrix.diagonal (fun i=>goeMatrix r g i i)).submatrix + (fun i : S=>i.1) (fun i : S=>i.1)= + (goeMatrix r g).submatrix (fun i : S=>i.1) (fun i : S=>i.1)- + Matrix.diagonal (fun i : S=>goeMatrix r g i.1 i.1) := by + ext i k + simp only [submatrix_apply,Matrix.sub_apply] + congr 1 + simp only [Matrix.diagonal_apply,Subtype.val_inj] + rw [he] + apply (norm_sub_le _ _).trans + have hb : ‖Matrix.diagonal (fun i : S=>goeMatrix r g i.1 i.1)‖ ≤ d := + diagonal_norm_le (ι:=S) hd _ (fun i=>hdiag i.1) + apply add_le_add _ hb + simpa only [principalOperatorNorm,matrixOperator_eq_toEuclideanCLM,Matrix.l2_opNorm_toEuclideanCLM] using hg + +lemma row_square_restrict (A : Matrix (Fin n) (Fin n) ℝ) (S : Finset (Fin n)) + {R : ℝ} (hr : ∀ i,∑ k,A i k^2 ≤ R) (i : S) : + (∑ k : S,A i.1 k.1^2) ≤ R := by + rw [Finset.sum_coe_sort S (fun k=>A i.1 k^2)] + exact (Finset.sum_le_sum_of_subset_of_nonneg (Finset.subset_univ S) + (fun k _ _=>sq_nonneg (A i.1 k))).trans (hr i.1) + +lemma tanh_principal_norm (g : Disorder n) (S : Finset (Fin n)) {d R ε : ℝ} + (hd : 0 ≤ d) (hR : 0 ≤ R) + (hma : ∀ i k,|coupling g i k| ≤ d) (hrow : ∀ i,∑ k,coupling g i k^2 ≤ R) + (hJ : ‖(Matrix.of (coupling g)).submatrix (fun i : S=>i.1) (fun i : S=>i.1)‖ ≤ ε) : + ‖Matrix.of (fun i k : S=>tanh (coupling g i.1 k.1))‖ ≤ ε+d*R/3 := by + let A : Matrix S S ℝ := (Matrix.of (coupling g)).submatrix (fun i : S=>i.1) (fun i : S=>i.1) + have hh := tanh_matrix_remainder_norm A (fun i k=>coupling_symmetric g i.1 k.1) + hR hd (fun i k=>hma i.1 k.1) (row_square_restrict _ S hrow) + have he : Matrix.of (fun i k : S=>tanh (coupling g i.1 k.1))= + A+(Matrix.of (fun i k=>tanh (A i k))-A) := by ext i k;simp [A] + rw [he] + exact (norm_add_le _ _).trans (add_le_add hJ hh) + +lemma tanh_square_principal_norm (g : Disorder n) (S : Finset (Fin n)) {ε : ℝ} + (hε : 0 ≤ ε) (hrows : ∀ i,∑ k∈S,coupling g i k^2 ≤ ε) : + ‖Matrix.of (fun i k : S=>tanh (coupling g i.1 k.1)^2)‖ ≤ ε := by + apply tanh_matrix_Q_norm (Matrix.of (fun i k : S=>coupling g i.1 k.1)) + (fun i k=>coupling_symmetric g i.1 k.1) hε + intro i + change (∑ k : S,coupling g i.1 k.1^2) ≤ ε + rw [Finset.sum_coe_sort S (fun k=>coupling g i.1 k^2)] + exact hrows i.1 +end SKGap + +end +end + +section +noncomputable section +namespace SKGap +open Real +open scoped BigOperators +variable {n : ℕ} + +lemma conditionalExpectation_flip (g : Disorder n) (h : Fin n→ℝ) (i : Fin n) + (f : Spin n→ℝ) (x : Spin n) : + conditionalExpectation g h i f (flip i x)=conditionalExpectation g h i f x := by + simp only [conditionalExpectation,flip_flip] + rw [add_comm (weight g h (flip i x)*f (flip i x)),add_comm (weight g h (flip i x))] + +lemma conditionalExpectation_idem (g : Disorder n) (h : Fin n→ℝ) (i : Fin n) + (f : Spin n→ℝ) (x : Spin n) : + conditionalExpectation g h i (conditionalExpectation g h i f) x=conditionalExpectation g h i f x := by + unfold conditionalExpectation at * + rw [flip_flip] + have hd : weight g h x+weight g h (flip i x) ≠ 0 := (add_pos (weight_pos _ _ _) (weight_pos _ _ _)).ne' + have hd' : weight g h (flip i x)+weight g h x ≠ 0 := by simpa only [add_comm] using hd + field_simp [hd,hd'] + ring + +lemma expectation_flip_average (g : Disorder n) (h : Fin n→ℝ) (i : Fin n) + (F : Spin n→ℝ) : + expectation g h F=(1/2)*∑ x,(mass g h x*F x+mass g h (flip i x)*F (flip i x)) := by + rw [Finset.sum_add_distrib,sum_flip i (fun x=>mass g h x*F x)] + unfold expectation + ring + +lemma conditionalExpectation_adjoint (g : Disorder n) (h : Fin n→ℝ) (i : Fin n) + (f k : Spin n→ℝ) : + expectation g h (fun x=>conditionalExpectation g h i f x*k x)= + expectation g h (fun x=>f x*conditionalExpectation g h i k x) := by + rw [expectation_flip_average g h i,expectation_flip_average g h i] + congr 1 + apply Finset.sum_congr rfl + intro x _ + rw [conditionalExpectation_flip,conditionalExpectation_flip] + unfold mass conditionalExpectation + have hd : weight g h x+weight g h (flip i x) ≠ 0 := (add_pos (weight_pos _ _ _) (weight_pos _ _ _)).ne' + have hZ := (partition_pos g h).ne' + field_simp [hd,hZ] + +lemma conditionalExpectation_mul_invariant (g : Disorder n) (h : Fin n→ℝ) (i : Fin n) + (f k : Spin n→ℝ) (hk : ∀ x,k (flip i x)=k x) (x : Spin n) : + conditionalExpectation g h i (fun x=>f x*k x) x=conditionalExpectation g h i f x*k x := by + unfold conditionalExpectation + dsimp only + rw [hk] + ring + +lemma conditionalExpectation_const (g : Disorder n) (h : Fin n→ℝ) (i : Fin n) + (c : ℝ) (x : Spin n) : conditionalExpectation g h i (fun _=>c) x=c := by + unfold conditionalExpectation + have hd : weight g h x+weight g h (flip i x) ≠ 0 := (add_pos (weight_pos _ _ _) (weight_pos _ _ _)).ne' + field_simp [hd] + +lemma expectation_conditionalExpectation (g : Disorder n) (h : Fin n→ℝ) (i : Fin n) + (f : Spin n→ℝ) : expectation g h (conditionalExpectation g h i f)=expectation g h f := by + have he := conditionalExpectation_adjoint g h i f (fun _=>1) + simpa only [conditionalExpectation_const,mul_one] using he + +lemma expectation_projection_square (g : Disorder n) (h : Fin n→ℝ) (i : Fin n) + (f : Spin n→ℝ) : + expectation g h (fun x=>(f x-conditionalExpectation g h i f x)^2)= + expectation g h (fun x=>f x*(f x-conditionalExpectation g h i f x)) := by + have he := conditionalExpectation_adjoint g h i f (conditionalExpectation g h i f) + simp only [conditionalExpectation_idem] at he + have hp (x : Spin n) : (f x-conditionalExpectation g h i f x)^2= + f x*(f x-conditionalExpectation g h i f x)+ + (conditionalExpectation g h i f x*conditionalExpectation g h i f x- + f x*conditionalExpectation g h i f x) := by ring + simp_rw [hp] + rw [expectation_add,expectation_sub,he] + ring + +def heatBathGenerator (g : Disorder n) (h : Fin n→ℝ) (f : Spin n→ℝ) (x : Spin n) : ℝ := + ∑ i,(f x-conditionalExpectation g h i f x) + +lemma expectation_sum (g : Disorder n) (h : Fin n→ℝ) {ι : Type*} [Fintype ι] + (F : ι→Spin n→ℝ) : expectation g h (fun x=>∑ i,F i x)=∑ i,expectation g h (F i) := by + unfold expectation + simp_rw [Finset.mul_sum] + rw [Finset.sum_comm] + +lemma heatBathGenerator_form (g : Disorder n) (h : Fin n→ℝ) (f : Spin n→ℝ) : + expectation g h (fun x=>f x*heatBathGenerator g h f x)=dirichlet g h f := by + unfold heatBathGenerator dirichlet + simp_rw [Finset.mul_sum] + rw [expectation_sum] + apply Finset.sum_congr rfl + intro i _ + exact (expectation_projection_square g h i f).symm + +lemma heatBathGenerator_adjoint (g : Disorder n) (h : Fin n→ℝ) (f k : Spin n→ℝ) : + expectation g h (fun x=>heatBathGenerator g h f x*k x)= + expectation g h (fun x=>f x*heatBathGenerator g h k x) := by + unfold heatBathGenerator + simp_rw [Finset.sum_mul,Finset.mul_sum] + rw [expectation_sum,expectation_sum] + apply Finset.sum_congr rfl + intro i _ + simp_rw [sub_mul,mul_sub] + rw [expectation_sub,expectation_sub,conditionalExpectation_adjoint] + +lemma conditionalDifference_zero_iff (g : Disorder n) (h : Fin n→ℝ) (i : Fin n) + (f : Spin n→ℝ) (x : Spin n) : f x-conditionalExpectation g h i f x=0 ↔ f x=f (flip i x) := by + have hd : weight g h x+weight g h (flip i x) ≠ 0 := (add_pos (weight_pos _ _ _) (weight_pos _ _ _)).ne' + have hw := (weight_pos g h (flip i x)).ne' + unfold conditionalExpectation + rw [sub_eq_zero,eq_div_iff hd] + constructor + · intro hh + have he : weight g h (flip i x)*(f x-f (flip i x))=0 := by nlinarith only [hh] + exact sub_eq_zero.mp ((mul_eq_zero.mp he).resolve_left hw) + · intro hh + rw [hh] + ring + +lemma flip_invariant_constant (f : Spin n→ℝ) (hf : ∀ i x,f (flip i x)=f x) : + ∀ x y,f x=f y := by + classical + intro x y + have hs : ∀ S : Finset (Fin n),f (fun i=>if i∈S then y i else x i)=f x := by + intro S + induction S using Finset.induction_on with + | empty => simp + | @insert i S hi ih => + let z : Spin n := fun k=>if k∈S then y k else x k + have he : (fun k=>if k∈insert i S then y k else x k)=Function.update z i (y i) := by + funext k + by_cases hk : k=i + · subst k;simp + · simp [z,hk] + rw [he] + have hz : f (Function.update z i (y i))=f z := by + by_cases hiy : y i=z i + · rw [hiy,Function.update_eq_self] + · have hnot : y i= !(z i) := by + cases hy : y i <;> cases hz : z i <;> simp_all + rw [hnot] + exact hf i z + exact hz.trans ih + simpa using (hs Finset.univ).symm + +lemma dirichlet_eq_zero_iff (g : Disorder n) (h : Fin n→ℝ) (f : Spin n→ℝ) : + dirichlet g h f=0 ↔ ∀ x y,f x=f y := by + constructor + · intro hh + have hi : ∀ i,expectation g h (fun x=>(f x-conditionalExpectation g h i f x)^2)=0 := by + intro i + exact (Finset.sum_eq_zero_iff_of_nonneg (fun j _=>expectation_nonneg g h (fun _=>sq_nonneg _))).mp hh i (Finset.mem_univ _) + have hf : ∀ i x,f (flip i x)=f x := by + intro i x + have hx : mass g h x*(f x-conditionalExpectation g h i f x)^2=0 := + (Finset.sum_eq_zero_iff_of_nonneg (fun y _=>mul_nonneg (mass_nonneg g h y) (sq_nonneg _))).mp + (hi i) x (Finset.mem_univ _) + have hd := (mul_eq_zero.mp hx).resolve_left (mass_pos g h x).ne' + exact ((conditionalDifference_zero_iff g h i f x).mp (sq_eq_zero_iff.mp hd)).symm + exact flip_invariant_constant f hf + · intro hf + unfold dirichlet + apply Finset.sum_eq_zero + intro i _ + have he : ∀ x,f x-conditionalExpectation g h i f x=0 := fun x=>(conditionalDifference_zero_iff g h i f x).mpr (hf x (flip i x)) + simp only [he,zero_pow (by omega : (2:ℕ) ≠ 0)] + simp [expectation] +end SKGap + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Terminal/TerminalProbability.lean b/lean/OAI/Probability/SKGap/Terminal/TerminalProbability.lean new file mode 100644 index 0000000000000000000000000000000000000000..a1e749c067915acb95f32e201c0db681423bbb90 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Terminal/TerminalProbability.lean @@ -0,0 +1,107 @@ +import Mathlib +import OAI.Probability.SKGap.Terminal.TerminalDeterministic +import OAI.Probability.SKGap.Brownian.GibbsContinuity +import OAI.Probability.SKGap.Localization.RareCoordinate +import OAI.Probability.SKGap.Posterior.GaussianChannel + +namespace OAI + +section +noncomputable section +namespace SKGap +open MeasureTheory ProbabilityTheory Real Set Matrix +open scoped BigOperators ENNReal RealInnerProductSpace Matrix.Norms.L2Operator +variable {n : ℕ} + +def observationField (T : ℝ) (x : Spin n) (z : Fin n→ℝ) : Fin n→ℝ := + fun i=>T*spinValue (x i)+sqrt T*z i + +lemma spinValue_sign (b : Bool) : spinValue b=1 ∨ spinValue b= -1 := by + cases b <;> simp + +lemma rareCount_field (T : ℝ) (x : Spin n) (z : Fin n→ℝ) : + rareCount (fun i=>{u : ℝ | |T*spinValue (x i)+sqrt T*u| < T/2}) z= + ((Finset.univ.filter (fun i=>|observationField T x z i| < T/2)).card:ℝ) := by + classical + simp only [rareCount,observationField,Set.mem_ofPred_eq] + simp only [Finset.sum_boole] + rfl + +lemma observation_smallField_tail {T α : ℝ} (hT : 0 < T) + (hp : exp (-T/8)*(exp 1-1) ≤ α/4) (x : Spin n) : + (channelReference n).real {z | α*(n:ℝ)/2 < + ((Finset.univ.filter (fun i=>|observationField T x z i| < T/2)).card:ℝ)} ≤ + exp (-α*(n:ℝ)/4) := by + classical + have hh := rareCount_tail (fun _ : Fin n=>gaussianReal 0 1) + (fun i=>{u : ℝ | |T*spinValue (x i)+sqrt T*u| < T/2}) + (fun _=>isOpen_lt (by fun_prop) continuous_const |>.measurableSet) + (a:=α*(n:ℝ)/2) (fun i=>gaussian_observation_small hT (spinValue_sign (x i))) + simp only [rareCount_field,Fintype.card_fin] at hh + apply hh.trans + apply exp_le_exp.mpr + have hm := mul_le_mul_of_nonneg_left hp (Nat.cast_nonneg n : (0:ℝ) ≤ n) + nlinarith only [hm] + +theorem terminal_probability_fixedSpin (g : Disorder n) {M T α ε R : ℝ} + (hM : 0 ≤ M) (hT : 0 < T) (hε : 0 ≤ ε) + (hJ : ‖Matrix.of (coupling g)‖ ≤ M) + (hU : ‖terminalU g‖ ≤ M) (hQ : ‖terminalQ g‖ ≤ M) + (hc : ∀ i j,|tanh (coupling g i j)| ≤ 1/1000) + (hR : ∀ i,∑ j,tanh (coupling g i j)^4 ≤ R) + (hsparse : ∀ S : Finset (Fin n),(S.card:ℝ) ≤ α*(n:ℝ) → + ∀ w : EuclideanSpace ℝ (Fin n),(∀ i,i ∉ S → w i=0) → + |⟪w,Matrix.toEuclideanCLM (𝕜 := ℝ) (n := Fin n) (terminalU g) w⟫| ≤ ε*‖w‖^2 ∧ + |⟪w,Matrix.toEuclideanCLM (𝕜 := ℝ) (n := Fin n) (terminalQ g) w⟫| ≤ ε*‖w‖^2) + (hsmall : M^2 ≤ (T/4)^2*α/2) + (hnum : 800000*R+400001*(ε+M*(2*sqrt (1/cosh (T/4)^2)+1/cosh (T/4)^2)) ≤ 1/2) + (hp : exp (-T/8)*(exp 1-1) ≤ α/4) (x : Spin n) : + (channelReference n).real {z | ¬∀ f : Spin n→ℝ, + variance g (observationField T x z) f ≤ 2*dirichlet g (observationField T x z) f} ≤ + exp (-α*(n:ℝ)/4) := by + apply (measureReal_mono (μ:=channelReference n) ?_ (measure_ne_top _ _)).trans + (observation_smallField_tail hT hp x) + intro z hz + by_contra hn + change ¬α*(n:ℝ)/2 < ((Finset.univ.filter (fun i=>|observationField T x z i| < T/2)).card:ℝ) at hn + have hb := le_of_not_gt hn + apply hz + apply terminal_deterministic g (observationField T x z) hM (by positivity : 0 < T/4) hε hJ hU hQ hc hR hsparse + ?_ hsmall hnum + simpa only [show 2*(T/4)=T/2 by ring] using hb + +lemma terminal_bad_measurable (g : Disorder n) (T : ℝ) : + MeasurableSet {p : Spin n × (Fin n→ℝ) | ¬∀ f : Spin n→ℝ, + variance g (observationField T p.1 p.2) f ≤ 2*dirichlet g (observationField T p.1 p.2) f} := by + apply ((terminal_goodSet_closed g 2).measurableSet.compl).preimage + unfold observationField + apply Measurable.of_eval + intro i + exact (measurable_const.mul ((measurable_of_finite (spinValue)).comp ((measurable_pi_apply i).comp measurable_fst))).add + (measurable_const.mul ((measurable_pi_apply i).comp measurable_snd)) + +lemma terminal_probability_anyLaw (g : Disorder n) {T c : ℝ} + (hh : ∀ x : Spin n,(channelReference n).real {z | ¬∀ f : Spin n→ℝ, + variance g (observationField T x z) f ≤ 2*dirichlet g (observationField T x z) f} ≤ exp (-c*(n:ℝ))) + (μ : Measure (Spin n)) [IsProbabilityMeasure μ] : + (μ.prod (channelReference n)).real {p | ¬∀ f : Spin n→ℝ, + variance g (observationField T p.1 p.2) f ≤ 2*dirichlet g (observationField T p.1 p.2) f} ≤ exp (-c*(n:ℝ)) := by + have hb (x : Spin n) : channelReference n {z | ¬∀ f : Spin n→ℝ, + variance g (observationField T x z) f ≤ 2*dirichlet g (observationField T x z) f} ≤ ENNReal.ofReal (exp (-c*(n:ℝ))) := by + exact (ENNReal.toReal_le_toReal (measure_ne_top _ _) ENNReal.ofReal_ne_top).mp + (by simpa only [measureReal_def,ENNReal.toReal_ofReal (exp_pos _).le] using hh x) + have he := Measure.prod_apply (μ:=μ) (ν:=channelReference n) (terminal_bad_measurable g T) + have hh' : μ.prod (channelReference n) {p | ¬∀ f : Spin n→ℝ, + variance g (observationField T p.1 p.2) f ≤ 2*dirichlet g (observationField T p.1 p.2) f} ≤ ENNReal.ofReal (exp (-c*(n:ℝ))) := by + rw [he] + calc + _ ≤ ∫⁻ _x,ENNReal.ofReal (exp (-c*(n:ℝ))) ∂μ := lintegral_mono hb + _ = _ := by simp + have hr := ENNReal.toReal_mono ENNReal.ofReal_ne_top hh' + simpa only [measureReal_def,ENNReal.toReal_ofReal (exp_pos _).le] using hr +end SKGap + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKGap/Terminal/TerminalRates.lean b/lean/OAI/Probability/SKGap/Terminal/TerminalRates.lean new file mode 100644 index 0000000000000000000000000000000000000000..d0e0244aebd64ce955b6a17a8a3c72a82b8519b6 --- /dev/null +++ b/lean/OAI/Probability/SKGap/Terminal/TerminalRates.lean @@ -0,0 +1,226 @@ +import Mathlib +import OAI.Probability.SKGap.Terminal.TerminalDeterministic +import OAI.Probability.SKGap.Matrix.GOEGlobalEvents + +namespace OAI + +section +noncomputable section +namespace SKGap +open Filter Real +open scoped Topology + +lemma nat_pow_exp_neg_tendsto {a : ℝ} (ha : 0 < a) (k : ℕ) : + Tendsto (fun n : ℕ=>(n:ℝ)^k*exp (-a*(n:ℝ))) atTop (𝓝 0) := by + have ht : Tendsto (fun n : ℕ=>a*(n:ℝ)) atTop atTop := + tendsto_natCast_atTop_atTop.const_mul_atTop ha + have h := ((tendsto_pow_mul_exp_neg_atTop_nhds_zero k).comp ht).div_const (a^k) + simp only [zero_div] at h + convert h using 1 + ext n + simp only [Function.comp_apply,mul_pow,neg_mul] + field_simp + +lemma nat_pow_exp_sqrt_tendsto {a : ℝ} (ha : 0 < a) (k : ℕ) : + Tendsto (fun n : ℕ=>(n:ℝ)^k*exp (-a*sqrt (n:ℝ))) atTop (𝓝 0) := by + have ht : Tendsto (fun n : ℕ=>a*sqrt (n:ℝ)) atTop atTop := + (tendsto_sqrt_atTop.comp tendsto_natCast_atTop_atTop).const_mul_atTop ha + have h := ((tendsto_pow_mul_exp_neg_atTop_nhds_zero (2*k)).comp ht).div_const (a^(2*k)) + simp only [zero_div] at h + convert h using 1 + ext n + simp only [Function.comp_apply,mul_pow,neg_mul,pow_mul,sq_sqrt (Nat.cast_nonneg n)] + field_simp + +def terminalEntryScale (n : ℕ) : ℝ := 1/sqrt (sqrt (n:ℝ)) + +lemma terminalEntryScale_nonneg (n : ℕ) : 0 ≤ terminalEntryScale n := by unfold terminalEntryScale;positivity + +lemma terminalEntryScale_tendsto : Tendsto terminalEntryScale atTop (𝓝 0) := by + change Tendsto (fun n : ℕ=>1/sqrt (sqrt (n:ℝ))) atTop (𝓝 0) + simpa only [one_div,Function.comp_def] using + tendsto_inv_atTop_zero.comp (tendsto_sqrt_atTop.comp (tendsto_sqrt_atTop.comp (tendsto_natCast_atTop_atTop (R:=ℝ)))) + +lemma terminalEntryScale_sq (n : ℕ) : terminalEntryScale n^2=1/sqrt (n:ℝ) := by + unfold terminalEntryScale + rw [div_pow,one_pow,sq_sqrt (sqrt_nonneg _)] + +lemma terminalEntryScale_rate {n : ℕ} (hn : 0 < n) : (n:ℝ)*terminalEntryScale n^2=sqrt (n:ℝ) := by + rw [terminalEntryScale_sq,mul_one_div] + apply (div_eq_iff (sqrt_pos.mpr (Nat.cast_pos.mpr hn)).ne').mpr + nlinarith only [sq_sqrt (Nat.cast_nonneg n)] +end SKGap + +end +end + +section +noncomputable section +namespace SKGap +open MeasureTheory ProbabilityTheory Matrix Real Set Filter +open scoped BigOperators Topology + +variable (j α ε : ℝ) (n : ℕ) +def terminalRowBound : ℝ := 4*j*(log 2+1) + +def terminalRawGood (g : MatrixCoordinates (Fin n)→ℝ) : Prop := + ‖matrixOperator (goeMatrix (j/(n:ℝ)) g)‖ ≤ 2*sqrt j+1 ∧ + (∀ i,|goeMatrix (j/(n:ℝ)) g i i| ≤ terminalEntryScale n) ∧ + (∀ i k,|coupling (goeDisorder (j/(n:ℝ)) g) i k| ≤ terminalEntryScale n) ∧ + (∀ i,∑ k,coupling (goeDisorder (j/(n:ℝ)) g) i k^2 ≤ terminalRowBound j) ∧ + (∀ S : Finset (Fin n),(S.card:ℝ) ≤ α*(n:ℝ) → + principalOperatorNorm (goeMatrix (j/(n:ℝ)) g) S ≤ ε/3) ∧ + (∀ (i : Fin n) (S : Finset (Fin n)),(S.card:ℝ) ≤ α*(n:ℝ) → + ∑ k∈S,coupling (goeDisorder (j/(n:ℝ)) g) i k^2 ≤ ε) + +variable (l : ℝ) +def terminalRawTail : ℝ := + 2*exp (-(n:ℝ)/(π^2*j))+ + 2*(n:ℝ)*exp (-sqrt (n:ℝ)/(8*j))+ + 2*(n:ℝ)^2*exp (-sqrt (n:ℝ)/(4*j))+ + (n:ℝ)*exp (-(n:ℝ))+ + 2*exp (-(n:ℝ)*(ε^2/(36*π^2*j)-(l*α+log (1+exp (-l)))))+ + (n:ℝ)*exp (-(n:ℝ)*(ε/(4*j)-(l*α+log (1+exp (-l))+α*log 2))) + +variable {j α ε n l} +lemma terminalRaw_bad_bound [NeZero n] (hj : 0 < j) (hα : 0 ≤ α) (hε : 0 < ε) + (hl : 0 ≤ l) (hedge : 2*sqrt (j*α) ≤ ε/6) : + (gaussianCoordinates (MatrixCoordinates (Fin n))).real {g | ¬terminalRawGood j α ε n g} ≤ + terminalRawTail j α ε n l := by + have hn : (0:ℝ) < n := by exact_mod_cast NeZero.pos n + let μ := gaussianCoordinates (MatrixCoordinates (Fin n)) + let E₁ := {g : MatrixCoordinates (Fin n)→ℝ | 2*sqrt j+1 < ‖matrixOperator (goeMatrix (j/(n:ℝ)) g)‖} + let E₂ := {g : MatrixCoordinates (Fin n)→ℝ | ∃ i,terminalEntryScale n < |goeMatrix (j/(n:ℝ)) g i i|} + let E₃ := {g : MatrixCoordinates (Fin n)→ℝ | ∃ i k,terminalEntryScale n < |coupling (goeDisorder (j/(n:ℝ)) g) i k|} + let E₄ := {g : MatrixCoordinates (Fin n)→ℝ | ∃ i,terminalRowBound j < ∑ k,coupling (goeDisorder (j/(n:ℝ)) g) i k^2} + let E₅ := {g : MatrixCoordinates (Fin n)→ℝ | ∃ S : Finset (Fin n),(S.card:ℝ) ≤ α*(n:ℝ) ∧ ε/3 < principalOperatorNorm (goeMatrix (j/(n:ℝ)) g) S} + let E₆ := {g : MatrixCoordinates (Fin n)→ℝ | ∃ i,∃ S : Finset (Fin n),(S.card:ℝ) ≤ α*(n:ℝ) ∧ ε < ∑ k∈S,coupling (goeDisorder (j/(n:ℝ)) g) i k^2} + have he : {g | ¬terminalRawGood j α ε n g}=((((E₁ ∪ E₂) ∪ E₃) ∪ E₄) ∪ E₅) ∪ E₆ := by + ext g + simp only [terminalRawGood,E₁,E₂,E₃,E₄,E₅,E₆,Set.mem_union,Set.mem_ofPred_eq,not_and_or,not_forall,not_le,exists_prop,or_assoc] + have h₁ : μ.real E₁ ≤ 2*exp (-(n:ℝ)/(π^2*j)) := by + convert goe_norm_tail (ι:=Fin n) hj (by norm_num : (0:ℝ) ≤ 1) using 1 <;> simp [μ,E₁] + have h₂ : μ.real E₂ ≤ 2*(n:ℝ)*exp (-sqrt (n:ℝ)/(8*j)) := by + apply (goe_diagonal_tail (ι:=Fin n) (div_pos hj hn) (terminalEntryScale_nonneg n)).trans_eq + simp only [Fintype.card_fin] + congr 2 + have hr := terminalEntryScale_rate (NeZero.pos n) + field_simp + nlinarith only [hr] + have h₃ : μ.real E₃ ≤ 2*(n:ℝ)^2*exp (-sqrt (n:ℝ)/(4*j)) := by + apply (coupling_goe_max_entry_tail hj (terminalEntryScale_nonneg n)).trans_eq + congr 2 + rw [neg_mul,terminalEntryScale_rate (NeZero.pos n)] + have h₄ : μ.real E₄ ≤ (n:ℝ)*exp (-(n:ℝ)) := by + apply (coupling_goe_all_rows_tail (t:=terminalRowBound j) hj).trans_eq + have heq : terminalRowBound j/(4*j)-log 2=1 := by unfold terminalRowBound;field_simp;ring + rw [heq,mul_one] + have h₅ : μ.real E₅ ≤ 2*exp (-(n:ℝ)*(ε^2/(36*π^2*j)-(l*α+log (1+exp (-l))))) := by + have hd : 2*sqrt (j*α) ≤ (ε/3)/2 := by linarith only [hedge] + convert goe_sparse_union_tail (ι:=Fin n) hj hα (by positivity : 0 < ε/3) hl hd using 1 + · simp only [Fintype.card_fin] + rfl + · simp only [Fintype.card_fin] + congr 2 + ring + have h₆ : μ.real E₆ ≤ (n:ℝ)*exp (-(n:ℝ)*(ε/(4*j)-(l*α+log (1+exp (-l))+α*log 2))) := + coupling_goe_sparse_rows_tail hj hα hl + rw [he] + have hu : μ.real (((((E₁ ∪ E₂) ∪ E₃) ∪ E₄) ∪ E₅) ∪ E₆) ≤ + ((((μ.real E₁+μ.real E₂)+μ.real E₃)+μ.real E₄)+μ.real E₅)+μ.real E₆ := by + calc + _ ≤ μ.real ((((E₁ ∪ E₂) ∪ E₃) ∪ E₄) ∪ E₅)+μ.real E₆ := measureReal_union_le _ _ + _ ≤ (μ.real (((E₁ ∪ E₂) ∪ E₃) ∪ E₄)+μ.real E₅)+μ.real E₆ := by gcongr;exact measureReal_union_le _ _ + _ ≤ ((μ.real ((E₁ ∪ E₂) ∪ E₃)+μ.real E₄)+μ.real E₅)+μ.real E₆ := by gcongr;exact measureReal_union_le _ _ + _ ≤ (((μ.real (E₁ ∪ E₂)+μ.real E₃)+μ.real E₄)+μ.real E₅)+μ.real E₆ := by gcongr;exact measureReal_union_le _ _ + _ ≤ _ := by gcongr;exact measureReal_union_le _ _ + exact hu.trans (add_le_add (add_le_add (add_le_add (add_le_add (add_le_add h₁ h₂) h₃) h₄) h₅) h₆) +end SKGap + +end +end + +section +noncomputable section +namespace SKGap +open Matrix Real MeasureTheory +open scoped BigOperators RealInnerProductSpace Matrix.Norms.L2Operator +variable {n : ℕ} + +def terminalMatrixBound (j : ℝ) : ℝ := 2*sqrt j+2+terminalRowBound j + +def terminalMatrixData (M α ε : ℝ) (g : Disorder n) : Prop := + (∀ i k,|coupling g i k| ≤ terminalEntryScale n) ∧ + ‖Matrix.of (coupling g)‖ ≤ M ∧ ‖terminalU g‖ ≤ M ∧ ‖terminalQ g‖ ≤ M ∧ + (∀ i,∑ k,tanh (coupling g i k)^4 ≤ M*terminalEntryScale n^2) ∧ + (∀ S : Finset (Fin n),(S.card:ℝ) ≤ α*(n:ℝ) → + principalOperatorNorm (terminalU g) S ≤ ε ∧ principalOperatorNorm (terminalQ g) S ≤ ε) + +lemma terminalMatrixData_of_raw {j α ε : ℝ} (hj : 0 < j) (hε : 0 ≤ ε) + (hn1 : terminalEntryScale n ≤ 1) + (hns : terminalEntryScale n*(1+terminalRowBound j/3) ≤ 2*ε/3) + (g : MatrixCoordinates (Fin n)→ℝ) (hg : terminalRawGood j α ε n g) : + terminalMatrixData (terminalMatrixBound j) α ε (goeDisorder (j/(n:ℝ)) g) := by + let J := goeDisorder (j/(n:ℝ)) g + have hR : 0 ≤ terminalRowBound j := by + unfold terminalRowBound + have hh : (0:ℝ) ≤ log 2 := log_nonneg (by norm_num) + positivity + have hd := terminalEntryScale_nonneg n + obtain ⟨hG,hdiag,hma,hrow,hsp,hrowS⟩ := hg + have hJ := coupling_norm_from_goe (j/(n:ℝ)) (terminalEntryScale n) (2*sqrt j+1) g hd hG hdiag + have hJM : ‖Matrix.of (coupling J)‖ ≤ terminalMatrixBound j := by + unfold terminalMatrixBound + change ‖Matrix.of (coupling J)‖ ≤ _ at hJ + linarith only [hJ,hn1,hR] + refine ⟨hma,hJM,?_,?_,?_,?_⟩ + · have hrem := tanh_matrix_remainder_norm (Matrix.of (coupling J)) (coupling_symmetric J) + hR hd hma hrow + have he : terminalU J=Matrix.of (coupling J)+(terminalU J-Matrix.of (coupling J)) := by abel + rw [he] + apply (norm_add_le _ _).trans + have hm := mul_le_mul_of_nonneg_right hn1 hR + change ‖terminalU J-Matrix.of (coupling J)‖ ≤ _ at hrem + change ‖Matrix.of (coupling J)‖ ≤ _ at hJ + unfold terminalMatrixBound + nlinarith only [hJ,hrem,hn1,hR,hm] + · apply (tanh_matrix_Q_norm (Matrix.of (coupling J)) (coupling_symmetric J) hR hrow).trans + unfold terminalMatrixBound + have hsq := sqrt_nonneg j + linarith only [hsq] + · intro i + apply (tanh_matrix_fourth_row (Matrix.of (coupling J)) hma hrow i).trans + have hb : terminalRowBound j ≤ terminalMatrixBound j := by + unfold terminalMatrixBound + have hsq := sqrt_nonneg j + linarith only [hsq] + calc + _ ≤ terminalEntryScale n^2*terminalMatrixBound j := mul_le_mul_of_nonneg_left hb (sq_nonneg _) + _ = _ := mul_comm _ _ + · intro S hS + have hJs := coupling_principal_norm_from_goe (j/(n:ℝ)) (terminalEntryScale n) (ε/3) g S hd (hsp S hS) hdiag + have hUs := tanh_principal_norm J S hd hR hma hrow hJs + have hQs := tanh_square_principal_norm J S hε (fun i=>hrowS i S hS) + constructor + · change ‖matrixOperator ((terminalU J).submatrix (fun i : S=>i.1) (fun i : S=>i.1))‖ ≤ ε + rw [matrixOperator_eq_toEuclideanCLM,Matrix.l2_opNorm_toEuclideanCLM] + change ‖Matrix.of (fun i k : S=>tanh (coupling J i.1 k.1))‖ ≤ ε + nlinarith only [hUs,hns] + · change ‖matrixOperator ((terminalQ J).submatrix (fun i : S=>i.1) (fun i : S=>i.1))‖ ≤ ε + rw [matrixOperator_eq_toEuclideanCLM,Matrix.l2_opNorm_toEuclideanCLM] + exact hQs + +lemma terminalMatrixData_forms {M α ε : ℝ} (g : Disorder n) (hg : terminalMatrixData M α ε g) : + ∀ S : Finset (Fin n),(S.card:ℝ) ≤ α*(n:ℝ) → + ∀ w : EuclideanSpace ℝ (Fin n),(∀ i,i ∉ S → w i=0) → + |⟪w,Matrix.toEuclideanCLM (𝕜 := ℝ) (n := Fin n) (terminalU g) w⟫| ≤ ε*‖w‖^2 ∧ + |⟪w,Matrix.toEuclideanCLM (𝕜 := ℝ) (n := Fin n) (terminalQ g) w⟫| ≤ ε*‖w‖^2 := by + intro S hS w hw + exact ⟨supported_quad_le_principal _ _ (hg.2.2.2.2.2 S hS).1 w hw, + supported_quad_le_principal _ _ (hg.2.2.2.2.2 S hS).2 w hw⟩ +end SKGap + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Calculus/Curvature.lean b/lean/OAI/Probability/SKRatio/Calculus/Curvature.lean new file mode 100644 index 0000000000000000000000000000000000000000..6efef489a39a7d64d1d01e28527df3f3f739321b --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Calculus/Curvature.lean @@ -0,0 +1,277 @@ +import Mathlib +import OAI.Probability.SKRatio.Calculus.RowControl +import OAI.Probability.SKRatio.Calculus.HeatBathLinearKernel + +namespace OAI + +section +noncomputable section +open scoped BigOperators RealInnerProductSpace +namespace SKRatio.Fields +open Real Matrix Calculus +attribute [local instance] Classical.propDecidable +variable {n : ℕ} + +lemma symmetric_row_cost {ι : Type*} [Fintype ι] + (U : ι → ι → ℝ) (D : ι → ℝ) {R : ℝ} + (hU : ∀ i j, U i j = U j i) (hD : ∀ i, 0 ≤ D i) + (hR : ∀ i, ∑ j, U i j ≤ R) : + (∑ i, ∑ j, U i j*(D i+D j)) ≤ 2*R*(∑ i, D i) := by + simp_rw [mul_add,Finset.sum_add_distrib] + have h₁ : (∑ i, ∑ j, U i j*D i) ≤ R*∑ i, D i := by + rw [Finset.mul_sum] + apply Finset.sum_le_sum + intro i _ + rw [← Finset.sum_mul] + exact mul_le_mul_of_nonneg_right (hR i) (hD i) + have h₂ : (∑ i, ∑ j, U i j*D j) = ∑ i, ∑ j, U i j*D i := by + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro i _ + apply Finset.sum_congr rfl + intro j _ + rw [hU j i] + rw [h₂] + linarith only [h₁] + +lemma symmetric_row_quadratic {ι : Type*} [Fintype ι] + (U : ι → ι → ℝ) (z : ι → ℝ) {R : ℝ} + (hU : ∀ i j, U i j = U j i) (habs : ∀ i j, 0 ≤ U i j) + (hR : ∀ i, ∑ j, U i j ≤ R) : + (∑ i, ∑ j, U i j*z i*z j) ≤ R*(∑ i, z i^2) := by + have hc := symmetric_row_cost U (fun i => z i^2) hU (fun _ => sq_nonneg _) hR + have hpt (i j : ι) : 2*(U i j*z i*z j) ≤ U i j*(z i^2+z j^2) := by + have hh := mul_nonneg (habs i j) (sq_nonneg (z i-z j)) + nlinarith only [hh] + have hh := Finset.sum_le_sum (fun i (_ : i ∈ Finset.univ) => + Finset.sum_le_sum (fun j (_ : j ∈ Finset.univ) => hpt i j)) + simp only [← Finset.mul_sum] at hh + linarith only [hh,hc] + +lemma quadratic_le_euclideanOpNorm (T : Interaction n) (z : Fin n → ℝ) : + (∑ i, ∑ j, T i j*z i*z j) ≤ euclideanOpNorm T * ∑ i, z i^2 := by + let Z : EuclideanSpace ℝ (Fin n) := WithLp.toLp 2 z + have hid : (∑ i, ∑ j, T i j*z i*z j) = + ⟪Z,Matrix.toEuclideanCLM (𝕜 := ℝ) (n := Fin n) T Z⟫ := by + rw [Matrix.inner_toEuclideanCLM (T : Matrix (Fin n) (Fin n) ℝ) Z Z] + simp only [dotProduct,Matrix.mulVec,Z,Finset.mul_sum] + apply Finset.sum_congr rfl + intro i _ + apply Finset.sum_congr rfl + intro j _; ring + rw [hid] + calc + _ ≤ ‖Z‖ * ‖Matrix.toEuclideanCLM (𝕜 := ℝ) (n := Fin n) T Z‖ := real_inner_le_norm _ _ + _ ≤ ‖Z‖ * (euclideanOpNorm T * ‖Z‖) := + mul_le_mul_of_nonneg_left (ContinuousLinearMap.le_opNorm _ _) (norm_nonneg _) + _ = euclideanOpNorm T * ∑ i, z i^2 := by + rw [show ‖Z‖*(euclideanOpNorm T*‖Z‖) = euclideanOpNorm T*‖Z‖^2 by ring, + EuclideanSpace.real_norm_sq_eq] + +theorem gibbs_cubic_curvature (g : Disorder n) (h : Fin n → ℝ) (f : Spin n → ℝ) {R : ℝ} + (hc : ∀ i j, |tanh (coupling g i j)| ≤ 1/1000) + (hR : ∀ i, ∑ j, |tanh (coupling g i j)|^3 ≤ R) : + (1-3840000*R)*dirichlet g h f - expectation g h (fun x => + ∑ i, ∑ j, (tanh (coupling g i j)+2*tanh (coupling g i j)^2* + tanh (localField g h i x)*tanh (localField g h j x))* + siteVariance g h i x*siteVariance g h j x*spinGradient i f x*spinGradient j f x) ≤ + expectation g h (fun x => heatBathGenerator g h f x^2) := by + let U := fun i j => tanh (coupling g i j) + let D := fun i => expectation g h (fun x => siteVariance g h i x * spinGradient i f x^2) + let A := fun i j => expectation g h (fun x => + (U i j+2*(U i j)^2*tanh (localField g h i x)*tanh (localField g h j x))* + siteVariance g h i x*siteVariance g h j x*spinGradient i f x*spinGradient j f x) + let X := fun i j => expectation g h (fun x => (f x-conditionalExpectation g h i f x)* + (f x-conditionalExpectation g h j f x)) + have hpair (i j : Fin n) : + (if i=j then D i else 0)-A i j-1920000*|U i j|^3*(D i+D j) ≤ X i j := by + by_cases hij : i=j + · subst j + have hX : X i i=D i := by + dsimp [X,D,siteVariance] + simp only [← sq,conditionalSiteEnergy_local] + have hA : A i i=0 := by + simp [A,U,coupling_diag] + simp [U,coupling_diag,hA,hX] + · simpa only [ite_eq_right hij,zero_sub,U,A,D,X] using gibbs_pair_cubic_bound g h i j hij f (hc i j) + have hsum := Finset.sum_le_sum (fun i (_ : i ∈ Finset.univ) => + Finset.sum_le_sum (fun j (_ : j ∈ Finset.univ) => hpair i j)) + have hcost := symmetric_row_cost (fun i j => |U i j|^3) D + (fun i j => by dsimp [U];rw [coupling_symm g i j]) + (fun i => expectation_nonneg g h (fun x => mul_nonneg (siteVariance_pos g h i x).le (sq_nonneg _))) hR + have hD : (∑ i, D i) = dirichlet g h f := (dirichlet_weighted g h f).symm + have hX : (∑ i, ∑ j, X i j) = expectation g h (fun x => heatBathGenerator g h f x^2) := + (heatBathGenerator_square g h f).symm + simp only [Finset.sum_sub_distrib,Finset.sum_ite_eq,Finset.mem_univ,ite_true] at hsum + have hcoef : (∑ i, ∑ j, 1920000*|U i j|^3*(D i+D j)) = + 1920000*(∑ i, ∑ j, |U i j|^3*(D i+D j)) := by simp only [mul_assoc,← Finset.mul_sum] + rw [hcoef,hD,hX] at hsum + rw [hD] at hcost + simp only [expectation_sum] + change _- (∑ i, ∑ j, A i j) ≤ _ + nlinarith only [hsum,hcost] + +lemma signed_forms_le (g : Disorder n) (h : Fin n → ℝ) (f : Spin n → ℝ) + (x : Spin n) {M B : ℝ} (hM : 0 ≤ M) + (hT : euclideanOpNorm (fun i j => tanh (coupling g i j)) ≤ M) + (hB : ∀ i, ∑ j, tanh (coupling g i j)^2 ≤ B) (hBM : 2*B ≤ M) : + (∑ i, ∑ j, (tanh (coupling g i j)+2*tanh (coupling g i j)^2* + tanh (localField g h i x)*tanh (localField g h j x))* + siteVariance g h i x*siteVariance g h j x*spinGradient i f x*spinGradient j f x) ≤ + M*∑ i, siteVariance g h i x*spinGradient i f x^2 := by + let T := fun i j => tanh (coupling g i j) + let z := fun i => siteVariance g h i x*spinGradient i f x + let z' := fun i => tanh (localField g h i x)*z i + have h₁ := (quadratic_le_euclideanOpNorm T z).trans + (mul_le_mul_of_nonneg_right hT (Finset.sum_nonneg (fun _ _ => sq_nonneg _))) + have h₂ := symmetric_row_quadratic (fun i j => T i j^2) z' + (fun i j => by dsimp [T]; rw [coupling_symm g i j]) (fun _ _ => sq_nonneg _) hB + have hs : (∑ i, z i^2)+(∑ i, z' i^2) ≤ + ∑ i, siteVariance g h i x*spinGradient i f x^2 := by + rw [← Finset.sum_add_distrib] + apply Finset.sum_le_sum + intro i _ + have hh := mul_nonneg (mul_nonneg (siteVariance_pos g h i x).le + (sq_nonneg (tanh (localField g h i x)^2))) (sq_nonneg (spinGradient i f x)) + dsimp [z,z',siteVariance] at hh ⊢ + nlinarith only [hh] + have he : (∑ i, ∑ j, (tanh (coupling g i j)+2*tanh (coupling g i j)^2* + tanh (localField g h i x)*tanh (localField g h j x))* + siteVariance g h i x*siteVariance g h j x*spinGradient i f x*spinGradient j f x) = + (∑ i, ∑ j, T i j*z i*z j)+2*(∑ i, ∑ j, T i j^2*z' i*z' j) := by + simp only [Finset.mul_sum,← Finset.sum_add_distrib] + apply Finset.sum_congr rfl + intro i _ + apply Finset.sum_congr rfl + intro j _ + dsimp [z,z',T]; ring + rw [he] + have hm := mul_le_mul_of_nonneg_left hs hM + have hb := mul_le_mul_of_nonneg_right hBM + (Finset.sum_nonneg (s := Finset.univ) (fun i _ => sq_nonneg (z' i))) + nlinarith only [h₁,h₂,hm,hb] + +theorem all_fields_poincare (g : Disorder n) {M B R ρ : ℝ} + (hM : 0 ≤ M) (hρ : 0 < ρ) (hmargin : ρ ≤ 1-M-3840000*R) + (hc : ∀ i j, |tanh (coupling g i j)| ≤ 1/1000) + (hR : ∀ i, ∑ j, |tanh (coupling g i j)|^3 ≤ R) + (hT : euclideanOpNorm (fun i j => tanh (coupling g i j)) ≤ M) + (hB : ∀ i, ∑ j, tanh (coupling g i j)^2 ≤ B) (hBM : 2*B ≤ M) + (h : Fin n → ℝ) (f : Spin n → ℝ) : ρ*variance g h f ≤ dirichlet g h f := by + apply heatBath_curvature_poincare g h hρ + intro F + have hh := gibbs_cubic_curvature g h F hc hR + have hb := expectation_mono g h (fun x => signed_forms_le g h F x hM hT hB hBM) + conv_rhs at hb => rw [expectation_const_mul,expectation_sum,← dirichlet_weighted] + have hm := mul_le_mul_of_nonneg_right hmargin (dirichlet_nonneg g h F) + nlinarith only [hh,hb,hm] + +lemma symmetric_abs_row_quad (T : Interaction n) (hs : ∀ i j, T i j=T j i) + {R : ℝ} (hR : ∀ i, ∑ j, |T i j| ≤ R) (z : Fin n → ℝ) : + |∑ i, ∑ j, T i j*z i*z j| ≤ R*∑ i, z i^2 := by + calc + _ ≤ ∑ i, ∑ j, |T i j*z i*z j| := (Finset.abs_sum_le_sum_abs _ _).trans + (Finset.sum_le_sum (fun _ _ => Finset.abs_sum_le_sum_abs _ _)) + _ = ∑ i, ∑ j, |T i j| *|z i| *|z j| := by simp only [abs_mul] + _ ≤ R*∑ i, |z i|^2 := symmetric_row_quadratic _ _ + (fun i j => by rw [hs i j]) (fun _ _ => abs_nonneg _) hR + _ = _ := by simp only [sq_abs] + +lemma euclideanOpNorm_le_abs_row (T : Interaction n) (hs : ∀ i j, T i j=T j i) + {R : ℝ} (hR0 : 0 ≤ R) (hR : ∀ i, ∑ j, |T i j| ≤ R) : euclideanOpNorm T ≤ R := by + let A := Matrix.toEuclideanCLM (𝕜 := ℝ) (n := Fin n) T + have hsa : A.IsSymmetric := Matrix.isSymmetric_toEuclideanLin_iff.mpr (by + change (T : Matrix (Fin n) (Fin n) ℝ)ᴴ = T + ext i j + change T j i=T i j + exact hs j i) + change ‖A‖ ≤ R + rw [ContinuousLinearMap.norm_eq_iSup_rayleighQuotient (T := A) hsa] + apply ciSup_le + intro z + by_cases hz : z=0 + · simp [hz,ContinuousLinearMap.rayleighQuotient,hR0] + have hn : 0 < ‖z‖^2 := sq_pos_of_pos (norm_pos_iff.mpr hz) + have hh := symmetric_abs_row_quad T hs hR (fun i => z i) + have he : ⟪A z,z⟫ = ∑ i, ∑ j, T i j*z i*z j := by + rw [real_inner_comm] + change ⟪z, Matrix.toEuclideanCLM (𝕜 := ℝ) (n := Fin n) T z⟫ = _ + rw [Matrix.inner_toEuclideanCLM (T : Matrix (Fin n) (Fin n) ℝ) z z] + simp only [dotProduct,Matrix.mulVec,Finset.mul_sum] + apply Finset.sum_congr rfl + intro i _ + apply Finset.sum_congr rfl + intro j _; ring + simpa only [ContinuousLinearMap.rayleighQuotient,ContinuousLinearMap.reApplyInnerSelf_apply, + RCLike.re_to_real,he,abs_div,abs_pow,abs_norm,div_le_iff₀ hn] using + (show |∑ i, ∑ j, T i j*z i*z j| ≤ R*‖z‖^2 by simpa only [EuclideanSpace.real_norm_sq_eq] using hh) + +lemma cubic_row_bound (T : Interaction n) {δ B : ℝ} (hδ : 0 ≤ δ) + (he : ∀ i j, |T i j| ≤ δ) (hB : ∀ i, ∑ j, T i j^2 ≤ B) (i : Fin n) : + (∑ j, |T i j|^3) ≤ δ*B := by + calc + _ = ∑ j, |T i j| *T i j^2 := by + apply Finset.sum_congr rfl + intro j _ + rw [pow_succ,sq_abs];ring + _ ≤ ∑ j, δ*T i j^2 := Finset.sum_le_sum (fun j _ => + mul_le_mul_of_nonneg_right (he i j) (sq_nonneg _)) + _ = δ*∑ j, T i j^2 := (Finset.mul_sum _ _ _).symm + _ ≤ _ := mul_le_mul_of_nonneg_left (hB i) hδ + +lemma tanh_euclideanOpNorm (T : Interaction n) (hs : ∀ i j, T i j=T j i) + {δ B : ℝ} (hδ : 0 ≤ δ) (hB0 : 0 ≤ B) + (he : ∀ i j, |T i j| ≤ δ) (hB : ∀ i, ∑ j, T i j^2 ≤ B) : + euclideanOpNorm (fun i j => tanh (T i j)) ≤ euclideanOpNorm T+δ*B/3 := by + have hr : euclideanOpNorm (fun i j => tanh (T i j)-T i j) ≤ δ*B/3 := by + apply euclideanOpNorm_le_abs_row _ (fun i j => by rw [hs i j]) (by positivity) + intro i + calc + _ ≤ ∑ j, |T i j|^3/3 := Finset.sum_le_sum (fun j _ => tanh_cubic_error _) + _ = (∑ j, |T i j|^3)/3 := (Finset.sum_div _ _ _).symm + _ ≤ _ := div_le_div_of_nonneg_right (cubic_row_bound T hδ he hB i) (by norm_num) + have hh := norm_add_le (Matrix.toEuclideanCLM (𝕜 := ℝ) (n := Fin n) T) + (Matrix.toEuclideanCLM (𝕜 := ℝ) (n := Fin n) (fun i j => tanh (T i j)-T i j)) + have hi : Matrix.toEuclideanCLM (𝕜 := ℝ) (n := Fin n) (fun i j => tanh (T i j)) = + Matrix.toEuclideanCLM (𝕜 := ℝ) (n := Fin n) T+ + Matrix.toEuclideanCLM (𝕜 := ℝ) (n := Fin n) (fun i j => tanh (T i j)-T i j) := by + ext z i + change (∑ j, tanh (T i j)*z j) = (∑ j, T i j*z j)+(∑ j, (tanh (T i j)-T i j)*z j) + rw [← Finset.sum_add_distrib] + apply Finset.sum_congr rfl + intro j _;ring + change ‖Matrix.toEuclideanCLM (𝕜 := ℝ) (n := Fin n) (fun i j => tanh (T i j))‖ ≤ _ + rw [hi] + exact hh.trans (add_le_add le_rfl hr) + +lemma tanh_square_row (T : Interaction n) {B : ℝ} (hB : ∀ i, ∑ j, T i j^2 ≤ B) + (i : Fin n) : (∑ j, tanh (T i j)^2) ≤ B := by + apply le_trans _ (hB i) + apply Finset.sum_le_sum + intro j _ + simpa only [sq_abs] using pow_le_pow_left₀ (abs_nonneg _) (abs_tanh_le_abs (T i j)) 2 + +theorem poincare_of_matrix_bounds (g : Disorder n) {K B δ ρ : ℝ} + (hK : 0 ≤ K) (hB : 0 ≤ B) (hδ : 0 ≤ δ) (hδsmall : δ ≤ 1/1000) + (hρ : 0 < ρ) (hmargin : ρ ≤ 1-(K+δ*B/3)-3840000*(δ*B)) + (hBK : 2*B ≤ K) (hnorm : euclideanOpNorm (coupling g) ≤ K) + (he : ∀ i j, |coupling g i j| ≤ δ) (hrow : ∀ i, ∑ j, coupling g i j^2 ≤ B) + (h : Fin n → ℝ) (f : Spin n → ℝ) : ρ*variance g h f ≤ dirichlet g h f := by + apply all_fields_poincare g (M := K+δ*B/3) (B := B) (R := δ*B) + (by positivity) hρ hmargin + · intro i j + exact ((abs_tanh_le_abs _).trans (he i j)).trans hδsmall + · intro i + apply le_trans _ (cubic_row_bound _ hδ he hrow i) + exact Finset.sum_le_sum (fun j _ => pow_le_pow_left₀ (abs_nonneg _) (abs_tanh_le_abs _) 3) + · exact (tanh_euclideanOpNorm _ (coupling_symm g) hδ hB he hrow).trans + (add_le_add hnorm le_rfl) + · exact tanh_square_row _ hrow + · linarith only [hBK,mul_nonneg hδ hB] + +end SKRatio.Fields + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Calculus/Energy.lean b/lean/OAI/Probability/SKRatio/Calculus/Energy.lean new file mode 100644 index 0000000000000000000000000000000000000000..a961f01136a58f54b567c3b8dc3c13377da608c0 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Calculus/Energy.lean @@ -0,0 +1,193 @@ +import Mathlib +import OAI.Probability.SKRatio.Calculus.GibbsMeanCLM + +namespace OAI + +section +noncomputable section +open scoped BigOperators Topology Matrix +open ContinuousLinearMap MeasureTheory Filter +namespace SKRatio.Calculus + +lemma energy_early_late_averaging (G : ℝ → ℝ) (hcontinuous : Continuous G) + {t s a R : ℝ} (ht : 0 ≤ t) (hs : 0 < s) (ha : 0 ≤ a) + (hnonneg : ∀ u ∈ Set.Icc (0:ℝ) (t+s), 0 ≤ G u) + (hbudget : (∫ u in (0:ℝ)..(t+s), G u) ≤ 1/2) + (hcompare : ∀ u ∈ Set.Icc (0:ℝ) t, + ∀ z ∈ Set.Icc (t+s/2) (t+s), G u ≤ a*G z+R) : + (∫ u in (0:ℝ)..t, G u) ≤ t*(a/s+R) := by + have hsplit := intervalIntegral.integral_add_adjacent_intervals (μ := volume) + (hcontinuous.intervalIntegrable 0 (t+s/2)) + (hcontinuous.intervalIntegrable (t+s/2) (t+s)) + have hfirst : 0 ≤ ∫ u in (0:ℝ)..(t+s/2), G u := by + apply intervalIntegral.integral_nonneg (by linarith) + intro u hu + exact hnonneg u ⟨hu.1, by linarith [hu.2]⟩ + have hlate : (∫ u in (t+s/2)..(t+s), G u) ≤ 1/2 := by + linarith only [hsplit, hfirst, hbudget] + have hearly (u : ℝ) (hu : u ∈ Set.Icc (0:ℝ) t) : G u ≤ a/s+R := by + have hi := intervalIntegral.integral_mono_on (μ := volume) (by linarith : t+s/2 ≤ t+s) + (continuous_const.intervalIntegrable (t+s/2) (t+s)) + ((hcontinuous.const_mul a |>.add_const R).intervalIntegrable (t+s/2) (t+s)) + (hcompare u hu) + rw [intervalIntegral.integral_const, + intervalIntegral.integral_add ((hcontinuous.const_mul a).intervalIntegrable _ _) + (continuous_const.intervalIntegrable _ _), + intervalIntegral.integral_const_mul, intervalIntegral.integral_const] at hi + simp only [smul_eq_mul] at hi + have hlate' := mul_le_mul_of_nonneg_left hlate ha + have heq : s*(a/s)=a := by field_simp + nlinarith only [hi, hlate', heq, hs] + calc + _ ≤ ∫ _u in (0:ℝ)..t, (a/s+R) := + intervalIntegral.integral_mono_on ht (hcontinuous.intervalIntegrable _ _) + (continuous_const.intervalIntegrable _ _) hearly + _ = _ := by rw [intervalIntegral.integral_const]; simp + +theorem transient_variance_of_energy_comparison {n : ℕ} (J : Interaction n) + (f : Observables n) (hf : ∀ y, |f y| ≤ 1) (x : Spin n) + {t s a R : ℝ} (ht : 0 ≤ t) (hs : 0 < s) (ha : 0 ≤ a) + (hcompare : ∀ u ∈ Set.Icc (0:ℝ) t, + ∀ z ∈ Set.Icc (t+s/2) (t+s), + backwardEnergy J f x (t+s) u ≤ a*backwardEnergy J f x (t+s) z+R) : + FiniteLaw.variance (continuousKernel J t x) (semigroup J s f) ≤ + 2*t*(a/s+R) := by + have H := energy_early_late_averaging (backwardEnergy J f x (t+s)) + (backwardEnergy_continuous J f x (t+s)) ht hs ha + (fun u hu => backwardEnergy_nonneg J f x (t+s) u hu.1) + (backward_energy_budget J f hf x (by linarith)) hcompare + have hv := backward_variance_budget J f x (t+s) t + rw [show t+s-t = s by ring] at hv + rw [hv] + linarith only [H] + +def stationaryEnergy {n : ℕ} (g : Disorder n) (f : Observables n) : ℝ := + FiniteLaw.mean (mass g 0) (weightedGradient (coupling g) f) + +lemma stationaryEnergy_nonneg {n : ℕ} (g : Disorder n) (f : Observables n) : + 0 ≤ stationaryEnergy g f := by + exact Finset.sum_nonneg (fun x _ => + mul_nonneg (mass_nonneg g 0 x) (weightedGradient_nonneg _ f x)) + +lemma stationaryEnergy_eq {n : ℕ} (g : Disorder n) (f : Observables n) : + stationaryEnergy g f = + -FiniteLaw.mean (mass g 0) (fun x => f x*generator (coupling g) f x) := by + have hg : generator (coupling g) (fun x => f x^2) = + (2:ℝ) • ((fun x => f x*generator (coupling g) f x) + + weightedGradient (coupling g) f) := by + funext x + change generator (coupling g) (fun y => f y^2) x = + 2*(f x*generator (coupling g) f x + weightedGradient (coupling g) f x) + have h := variance_density (coupling g) f x + linarith only [h] + have h := congrArg (gibbsMeanCLM g) hg + rw [gibbsMean_generator, map_smul, map_add] at h + simp only [gibbsMeanCLM_apply, smul_eq_mul] at h + unfold stationaryEnergy + linarith only [h] + +lemma equilibrium_variance_hasDerivAt {n : ℕ} (g : Disorder n) (f : Observables n) + (t : ℝ) : + HasDerivAt (fun r => FiniteLaw.variance (mass g 0) (semigroup (coupling g) r f)) + (-2*stationaryEnergy g (semigroup (coupling g) t f)) t := by + have hsq : HasDerivAt (fun r : ℝ => fun x : Spin n => (semigroup (coupling g) r f x)^2) + (fun x => 2*semigroup (coupling g) t f x* + generator (coupling g) (semigroup (coupling g) t f) x) t := by + apply hasDerivAt_pi.mpr + intro x + have h := (hasDerivAt_pi.mp (semigroup_apply_hasDerivAt' (coupling g) f t) x).fun_pow 2 + convert h using 1 + simp only [Nat.cast_ofNat, Nat.reduceSub, pow_one] + have hm := (gibbsMeanCLM g).hasFDerivAt.comp_hasDerivAt t hsq + have hm' := hm.sub_const ((FiniteLaw.mean (mass g 0) f)^2) + have heq : (fun r => FiniteLaw.variance (mass g 0) (semigroup (coupling g) r f)) = + (fun r => gibbsMeanCLM g (fun x => (semigroup (coupling g) r f x)^2) - + (FiniteLaw.mean (mass g 0) f)^2) := by + funext r + rw [FiniteLaw.variance_eq _ _ (sum_mass g 0), gibbsMean_semigroup, gibbsMeanCLM_apply] + rw [heq] + apply hm'.congr_deriv + rw [stationaryEnergy_eq] + simp only [gibbsMeanCLM_apply, FiniteLaw.mean, mul_neg, neg_mul, neg_neg, Finset.mul_sum, Finset.sum_neg_distrib] + apply Finset.sum_congr rfl + intro x _ + ring + +theorem equilibrium_variance_decay {n : ℕ} (g : Disorder n) {γ : ℝ} + (hgap : ∀ f : Observables n, + γ*FiniteLaw.variance (mass g 0) f ≤ stationaryEnergy g f) + (f : Observables n) {s : ℝ} (hs : 0 ≤ s) : + FiniteLaw.variance (mass g 0) (semigroup (coupling g) s f) ≤ + Real.exp (-2*γ*s)*FiniteLaw.variance (mass g 0) f := by + let V (r : ℝ) := FiniteLaw.variance (mass g 0) (semigroup (coupling g) r f) + let E (r : ℝ) := stationaryEnergy g (semigroup (coupling g) r f) + let H (r : ℝ) := Real.exp (2*γ*r)*V r + have hderiv (r : ℝ) : HasDerivAt H (Real.exp (2*γ*r)*(2*γ*V r-2*E r)) r := by + have h := (((hasDerivAt_id r).const_mul (2*γ)).exp).mul + (equilibrium_variance_hasDerivAt g f r) + convert h using 1 <;> first | rfl | (dsimp [V, E]; ring) + have hanti : Antitone H := antitone_of_deriv_nonpos + (fun r => (hderiv r).differentiableAt) (fun r => by + rw [(hderiv r).deriv] + exact mul_nonpos_of_nonneg_of_nonpos (Real.exp_nonneg _) (by + have h := hgap (semigroup (coupling g) r f) + change γ*V r ≤ E r at h + linarith only [h])) + have h := hanti hs + have hzero : H 0 = FiniteLaw.variance (mass g 0) f := by + simp [H, V] + rw [hzero] at h + have hscaled := mul_le_mul_of_nonneg_left h (Real.exp_nonneg (-2*γ*s)) + calc + V s = Real.exp (-2*γ*s)*H s := by + dsimp [H] + rw [← mul_assoc, ← Real.exp_add, show -2*γ*s+2*γ*s=0 by ring, Real.exp_zero, one_mul] + _ ≤ _ := hscaled + +lemma equilibrium_variance_le_one {n : ℕ} (g : Disorder n) (f : Observables n) + (hf : ∀ x, |f x| ≤ 1) : FiniteLaw.variance (mass g 0) f ≤ 1 := by + have hle : FiniteLaw.mean (mass g 0) (fun x => f x^2) ≤ 1 := by + calc + _ ≤ ∑ x : Spin n, mass g 0 x*1 := + Finset.sum_le_sum (fun x _ => mul_le_mul_of_nonneg_left + ((sq_le_one_iff_abs_le_one _).mpr (hf x)) (mass_nonneg g 0 x)) + _ = _ := by simp [sum_mass] + rw [FiniteLaw.variance_eq _ _ (sum_mass g 0)] + linarith only [hle, sq_nonneg (FiniteLaw.mean (mass g 0) f)] + +theorem equilibrium_smoothing {n : ℕ} (g : Disorder n) {γ : ℝ} + (hgap : ∀ f : Observables n, + γ*FiniteLaw.variance (mass g 0) f ≤ stationaryEnergy g f) + (f : Observables n) (hf : ∀ x, |f x| ≤ 1) {s : ℝ} (hs : 0 ≤ s) : + FiniteLaw.variance (mass g 0) (semigroup (coupling g) s f) ≤ Real.exp (-2*γ*s) := by + exact (equilibrium_variance_decay g hgap f hs).trans + ((mul_le_mul_of_nonneg_left (equilibrium_variance_le_one g f hf) + (Real.exp_nonneg _)).trans_eq (mul_one _)) + +theorem smoothing_of_energy_comparison {n : ℕ} (g : Disorder n) + {t s a R γ ε : ℝ} (ht : 0 ≤ t) (hs : 0 < s) (ha : 0 ≤ a) (hε : 0 < ε) + (hoverlap : continuousDistance g t ≤ 1-ε) + (hgap : ∀ f : Observables n, + γ*FiniteLaw.variance (mass g 0) f ≤ stationaryEnergy g f) + (hcompare : ∀ (f : Observables n), (∀ y, |f y| ≤ 1) → + ∀ (x : Spin n), ∀ u ∈ Set.Icc (0:ℝ) t, + ∀ z ∈ Set.Icc (t+s/2) (t+s), + backwardEnergy (coupling g) f x (t+s) u ≤ + a*backwardEnergy (coupling g) f x (t+s) z+R) : + continuousDistance g (t+s) ≤ + (Real.sqrt (2*t*(a/s+R))+Real.exp (-γ*s))/(2*Real.sqrt ε) := by + have h := continuousDistance_smoothing g ht hε hoverlap + (fun x f hf => transient_variance_of_energy_comparison (coupling g) + f hf x ht hs ha (hcompare f hf x)) + (fun f hf => equilibrium_smoothing g hgap f hf hs.le) + have heq : Real.sqrt (Real.exp (-2*γ*s)) = Real.exp (-γ*s) := by + rw [show -2*γ*s = (2:ℕ)*(-γ*s) by push_cast; ring, + Real.exp_nat_mul, Real.sqrt_sq (Real.exp_nonneg _)] + rwa [heq] at h + +end SKRatio.Calculus + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Calculus/Expectation.lean b/lean/OAI/Probability/SKRatio/Calculus/Expectation.lean new file mode 100644 index 0000000000000000000000000000000000000000..9dd55ca6b8bec44dcb1c93169922180f9a171f71 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Calculus/Expectation.lean @@ -0,0 +1,428 @@ +import Mathlib +import OAI.Probability.SKRatio.Calculus.TwoSpin + +namespace OAI + +section +noncomputable section +open scoped BigOperators RealInnerProductSpace +namespace SKRatio.Fields +open Real Matrix TwoSpin +attribute [local instance] Classical.propDecidable +variable {n : ℕ} + +@[simp] lemma spinValue_true : spinValue true = 1 := rfl +@[simp] lemma spinValue_false : spinValue false = -1 := rfl +@[simp] lemma spinValue_not (b : Bool) : spinValue (!b) = -spinValue b := by + cases b <;> norm_num [spinValue] + +lemma abs_tanh_lt_one (a : ℝ) : |tanh a| < 1 := + abs_lt.mpr ⟨Real.neg_one_lt_tanh a, Real.tanh_lt_one a⟩ + +lemma sum_flip (i : Fin n) (F : Spin n → ℝ) : ∑ x, F (flip i x) = ∑ x, F x := + Equiv.sum_comp (Function.Involutive.toPerm (flip i) (flip_flip i)) F + +def expectation {n : ℕ} (g : Disorder n) (h : Fin n → ℝ) (f : Spin n → ℝ) : ℝ := + ∑ x, mass g h x * f x + +def variance {n : ℕ} (g : Disorder n) (h : Fin n → ℝ) (f : Spin n → ℝ) : ℝ := + expectation g h (fun x => (f x - expectation g h f) ^ 2) + +def conditionalExpectation {n : ℕ} (g : Disorder n) (h : Fin n → ℝ) + (i : Fin n) (f : Spin n → ℝ) (x : Spin n) : ℝ := + (weight g h x * f x + weight g h (flip i x) * f (flip i x)) / + (weight g h x + weight g h (flip i x)) + +def dirichlet {n : ℕ} (g : Disorder n) (h : Fin n → ℝ) (f : Spin n → ℝ) : ℝ := + ∑ i, expectation g h (fun x => (f x - conditionalExpectation g h i f x) ^ 2) + +@[simp] theorem expectation_const (g : Disorder n) (h : Fin n → ℝ) (c : ℝ) : + expectation g h (fun _ => c) = c := by + simp [expectation, ← Finset.sum_mul] + +theorem expectation_add (g : Disorder n) (h : Fin n → ℝ) (f k : Spin n → ℝ) : + expectation g h (fun x => f x + k x) = expectation g h f + expectation g h k := by + simp [expectation, mul_add, Finset.sum_add_distrib] + +theorem expectation_sub (g : Disorder n) (h : Fin n → ℝ) (f k : Spin n → ℝ) : + expectation g h (fun x => f x - k x) = expectation g h f - expectation g h k := by + simp [expectation, mul_sub, Finset.sum_sub_distrib] + +theorem expectation_mul_const (g : Disorder n) (h : Fin n → ℝ) (f : Spin n → ℝ) (c : ℝ) : + expectation g h (fun x => f x * c) = expectation g h f * c := by + simp only [expectation, Finset.sum_mul, mul_assoc] + +theorem expectation_const_mul (g : Disorder n) (h : Fin n → ℝ) (f : Spin n → ℝ) (c : ℝ) : + expectation g h (fun x => c * f x) = c * expectation g h f := by + simp only [mul_comm c, expectation_mul_const] + +theorem expectation_nonneg (g : Disorder n) (h : Fin n → ℝ) {f : Spin n → ℝ} + (hf : ∀ x, 0 ≤ f x) : 0 ≤ expectation g h f := + Finset.sum_nonneg (fun x _ => mul_nonneg (mass_nonneg g h x) (hf x)) + +theorem variance_nonneg (g : Disorder n) (h : Fin n → ℝ) (f : Spin n → ℝ) : + 0 ≤ variance g h f := expectation_nonneg g h (fun _ => sq_nonneg _) + +theorem dirichlet_nonneg (g : Disorder n) (h : Fin n → ℝ) (f : Spin n → ℝ) : + 0 ≤ dirichlet g h f := + Finset.sum_nonneg (fun _ _ => expectation_nonneg g h (fun _ => sq_nonneg _)) + +lemma conditionalExpectation_flip (g : Disorder n) (h : Fin n→ℝ) (i : Fin n) + (f : Spin n→ℝ) (x : Spin n) : + conditionalExpectation g h i f (flip i x)=conditionalExpectation g h i f x := by + simp only [conditionalExpectation,flip_flip] + rw [add_comm (weight g h (flip i x)*f (flip i x)),add_comm (weight g h (flip i x))] + +lemma conditionalExpectation_idem (g : Disorder n) (h : Fin n→ℝ) (i : Fin n) + (f : Spin n→ℝ) (x : Spin n) : + conditionalExpectation g h i (conditionalExpectation g h i f) x=conditionalExpectation g h i f x := by + unfold conditionalExpectation at * + rw [flip_flip] + have hd : weight g h x+weight g h (flip i x) ≠ 0 := (add_pos (weight_pos _ _ _) (weight_pos _ _ _)).ne' + have hd' : weight g h (flip i x)+weight g h x ≠ 0 := by simpa only [add_comm] using hd + field_simp [hd,hd'] + ring + +lemma expectation_flip_average (g : Disorder n) (h : Fin n→ℝ) (i : Fin n) + (F : Spin n→ℝ) : + expectation g h F=(1/2)*∑ x,(mass g h x*F x+mass g h (flip i x)*F (flip i x)) := by + rw [Finset.sum_add_distrib,sum_flip i (fun x=>mass g h x*F x)] + unfold expectation + ring + +lemma conditionalExpectation_adjoint (g : Disorder n) (h : Fin n→ℝ) (i : Fin n) + (f k : Spin n→ℝ) : + expectation g h (fun x=>conditionalExpectation g h i f x*k x)= + expectation g h (fun x=>f x*conditionalExpectation g h i k x) := by + rw [expectation_flip_average g h i,expectation_flip_average g h i] + congr 1 + apply Finset.sum_congr rfl + intro x _ + rw [conditionalExpectation_flip,conditionalExpectation_flip] + unfold mass conditionalExpectation + have hd : weight g h x+weight g h (flip i x) ≠ 0 := (add_pos (weight_pos _ _ _) (weight_pos _ _ _)).ne' + have hZ := (partition_pos g h).ne' + field_simp [hd,hZ] + +lemma conditionalExpectation_mul_invariant (g : Disorder n) (h : Fin n→ℝ) (i : Fin n) + (f k : Spin n→ℝ) (hk : ∀ x,k (flip i x)=k x) (x : Spin n) : + conditionalExpectation g h i (fun x=>f x*k x) x=conditionalExpectation g h i f x*k x := by + unfold conditionalExpectation + dsimp only + rw [hk] + ring + +lemma conditionalExpectation_const (g : Disorder n) (h : Fin n→ℝ) (i : Fin n) + (c : ℝ) (x : Spin n) : conditionalExpectation g h i (fun _=>c) x=c := by + unfold conditionalExpectation + have hd : weight g h x+weight g h (flip i x) ≠ 0 := (add_pos (weight_pos _ _ _) (weight_pos _ _ _)).ne' + field_simp [hd] + +lemma expectation_conditionalExpectation (g : Disorder n) (h : Fin n→ℝ) (i : Fin n) + (f : Spin n→ℝ) : expectation g h (conditionalExpectation g h i f)=expectation g h f := by + have he := conditionalExpectation_adjoint g h i f (fun _=>1) + simpa only [conditionalExpectation_const,mul_one] using he + +lemma expectation_projection_square (g : Disorder n) (h : Fin n→ℝ) (i : Fin n) + (f : Spin n→ℝ) : + expectation g h (fun x=>(f x-conditionalExpectation g h i f x)^2)= + expectation g h (fun x=>f x*(f x-conditionalExpectation g h i f x)) := by + have he := conditionalExpectation_adjoint g h i f (conditionalExpectation g h i f) + simp only [conditionalExpectation_idem] at he + have hp (x : Spin n) : (f x-conditionalExpectation g h i f x)^2= + f x*(f x-conditionalExpectation g h i f x)+ + (conditionalExpectation g h i f x*conditionalExpectation g h i f x- + f x*conditionalExpectation g h i f x) := by ring + simp_rw [hp] + rw [expectation_add,expectation_sub,he] + ring + +def heatBathGenerator (g : Disorder n) (h : Fin n→ℝ) (f : Spin n→ℝ) (x : Spin n) : ℝ := + ∑ i,(f x-conditionalExpectation g h i f x) + +lemma expectation_sum (g : Disorder n) (h : Fin n→ℝ) {ι : Type*} [Fintype ι] + (F : ι→Spin n→ℝ) : expectation g h (fun x=>∑ i,F i x)=∑ i,expectation g h (F i) := by + unfold expectation + simp_rw [Finset.mul_sum] + rw [Finset.sum_comm] + +lemma heatBathGenerator_form (g : Disorder n) (h : Fin n→ℝ) (f : Spin n→ℝ) : + expectation g h (fun x=>f x*heatBathGenerator g h f x)=dirichlet g h f := by + unfold heatBathGenerator dirichlet + simp_rw [Finset.mul_sum] + rw [expectation_sum] + apply Finset.sum_congr rfl + intro i _ + exact (expectation_projection_square g h i f).symm + +lemma heatBathGenerator_adjoint (g : Disorder n) (h : Fin n→ℝ) (f k : Spin n→ℝ) : + expectation g h (fun x=>heatBathGenerator g h f x*k x)= + expectation g h (fun x=>f x*heatBathGenerator g h k x) := by + unfold heatBathGenerator + simp_rw [Finset.sum_mul,Finset.mul_sum] + rw [expectation_sum,expectation_sum] + apply Finset.sum_congr rfl + intro i _ + simp_rw [sub_mul,mul_sub] + rw [expectation_sub,expectation_sub,conditionalExpectation_adjoint] + +lemma conditionalDifference_zero_iff (g : Disorder n) (h : Fin n→ℝ) (i : Fin n) + (f : Spin n→ℝ) (x : Spin n) : f x-conditionalExpectation g h i f x=0 ↔ f x=f (flip i x) := by + have hd : weight g h x+weight g h (flip i x) ≠ 0 := (add_pos (weight_pos _ _ _) (weight_pos _ _ _)).ne' + have hw := (weight_pos g h (flip i x)).ne' + unfold conditionalExpectation + rw [sub_eq_zero,eq_div_iff hd] + constructor + · intro hh + have he : weight g h (flip i x)*(f x-f (flip i x))=0 := by nlinarith only [hh] + exact sub_eq_zero.mp ((mul_eq_zero.mp he).resolve_left hw) + · intro hh + rw [hh] + ring + +lemma flip_invariant_constant (f : Spin n→ℝ) (hf : ∀ i x,f (flip i x)=f x) : + ∀ x y,f x=f y := by + classical + intro x y + have hs : ∀ S : Finset (Fin n),f (fun i=>if i∈S then y i else x i)=f x := by + intro S + induction S using Finset.induction_on with + | empty => simp + | @insert i S hi ih => + let z : Spin n := fun k=>if k∈S then y k else x k + have he : (fun k=>if k∈insert i S then y k else x k)=Function.update z i (y i) := by + funext k + by_cases hk : k=i + · subst k;simp + · simp [z,hk] + rw [he] + have hz : f (Function.update z i (y i))=f z := by + by_cases hiy : y i=z i + · rw [hiy,Function.update_eq_self] + · have hnot : y i= !(z i) := by + cases hy : y i <;> cases hz : z i <;> simp_all + rw [hnot] + exact hf i z + exact hz.trans ih + simpa using (hs Finset.univ).symm + +lemma dirichlet_eq_zero_iff (g : Disorder n) (h : Fin n→ℝ) (f : Spin n→ℝ) : + dirichlet g h f=0 ↔ ∀ x y,f x=f y := by + constructor + · intro hh + have hi : ∀ i,expectation g h (fun x=>(f x-conditionalExpectation g h i f x)^2)=0 := by + intro i + exact (Finset.sum_eq_zero_iff_of_nonneg (fun j _=>expectation_nonneg g h (fun _=>sq_nonneg _))).mp hh i (Finset.mem_univ _) + have hf : ∀ i x,f (flip i x)=f x := by + intro i x + have hx : mass g h x*(f x-conditionalExpectation g h i f x)^2=0 := + (Finset.sum_eq_zero_iff_of_nonneg (fun y _=>mul_nonneg (mass_nonneg g h y) (sq_nonneg _))).mp + (hi i) x (Finset.mem_univ _) + have hd := (mul_eq_zero.mp hx).resolve_left (mass_pos g h x).ne' + exact ((conditionalDifference_zero_iff g h i f x).mp (sq_eq_zero_iff.mp hd)).symm + exact flip_invariant_constant f hf + · intro hf + unfold dirichlet + apply Finset.sum_eq_zero + intro i _ + have he : ∀ x,f x-conditionalExpectation g h i f x=0 := fun x=>(conditionalDifference_zero_iff g h i f x).mpr (hf x (flip i x)) + simp only [he,zero_pow (by omega : (2:ℕ) ≠ 0)] + simp [expectation] + +def localField (g : Disorder n) (h : Fin n→ℝ) (i : Fin n) (x : Spin n) : ℝ := + h i+∑ k,coupling g i k*spinValue (x k) +def spinGradient (i : Fin n) (f : Spin n→ℝ) (x : Spin n) : ℝ := + (f (Function.update x i true)-f (Function.update x i false))/2 + +def realSpinEnergy (g : Disorder n) (h v : Fin n→ℝ) : ℝ := + (1/2)*(v ⬝ᵥ (Matrix.of (coupling g) *ᵥ v))+h ⬝ᵥ v + +lemma realSpinEnergy_eq (g : Disorder n) (h : Fin n→ℝ) (x : Spin n) : + realSpinEnergy g h (fun i=>spinValue (x i))=hamiltonian g h x := by + unfold realSpinEnergy hamiltonian + congr 1 + congr 1 + simp only [Matrix.mulVec, Matrix.of_apply, dotProduct] + apply Finset.sum_congr rfl + intro i _ + rw [Finset.mul_sum] + apply Finset.sum_congr rfl + intro k _;ring + +lemma dot_coupling_single (g : Disorder n) (v : Fin n→ℝ) (i : Fin n) (a : ℝ) : + v ⬝ᵥ (Matrix.of (coupling g) *ᵥ Pi.single i a)=a*(Matrix.of (coupling g) *ᵥ v) i := by + rw [Matrix.mulVec_single] + simp only [Matrix.mulVec, Matrix.of_apply, dotProduct] + simp only [Pi.smul_apply,op_smul_eq_mul,Matrix.col_apply,Matrix.of_apply] + rw [Finset.mul_sum] + apply Finset.sum_congr rfl + intro k _ + rw [coupling_symm g k i] + ring + +lemma realSpinEnergy_update (g : Disorder n) (h v : Fin n→ℝ) (i : Fin n) (a : ℝ) : + realSpinEnergy g h (Function.update v i a)=realSpinEnergy g h v+ + (a-v i)*(h i+(Matrix.of (coupling g) *ᵥ v) i) := by + have he : Function.update v i a=v+Pi.single i (a-v i) := by + funext k + by_cases hk : k=i + · subst k;simp + · simp [hk] + rw [he] + unfold realSpinEnergy + rw [Matrix.mulVec_add,dotProduct_add,add_dotProduct,add_dotProduct,dotProduct_add, + dot_coupling_single,single_dotProduct,single_dotProduct,dotProduct_single,Matrix.mulVec_single] + simp only [Pi.smul_apply,op_smul_eq_mul,Matrix.col_apply,Matrix.of_apply,coupling_diag,zero_mul] + ring + +lemma spinValue_update (x : Spin n) (i : Fin n) (b : Bool) : + (fun k=>spinValue (Function.update x i b k))=Function.update (fun k=>spinValue (x k)) i (spinValue b) := by + funext k + by_cases hk : k=i + · subst k;simp + · simp [Function.update_of_ne hk] + +lemma hamiltonian_update (g : Disorder n) (h : Fin n→ℝ) (i : Fin n) (x : Spin n) (b : Bool) : + hamiltonian g h (Function.update x i b)=hamiltonian g h x+ + (spinValue b-spinValue (x i))*localField g h i x := by + rw [← realSpinEnergy_eq,spinValue_update,realSpinEnergy_update,realSpinEnergy_eq] + rfl + +lemma localField_update_self (g : Disorder n) (h : Fin n→ℝ) (i : Fin n) (x : Spin n) (b : Bool) : + localField g h i (Function.update x i b)=localField g h i x := by + unfold localField + congr 1 + apply Finset.sum_congr rfl + intro k _ + by_cases hk : k=i + · subst k;simp + · simp [Function.update_of_ne hk] + +lemma localField_update (g : Disorder n) (h : Fin n→ℝ) (i j : Fin n) (x : Spin n) (b : Bool) : + localField g h i (Function.update x j b)=localField g h i x+ + coupling g i j*(spinValue b-spinValue (x j)) := by + unfold localField + have he : (fun k=>spinValue (Function.update x j b k))= + (fun k=>spinValue (x k))+Pi.single j (spinValue b-spinValue (x j)) := by + funext k + by_cases hk : k=j + · subst k;simp + · simp [Function.update_of_ne hk,Pi.single_eq_of_ne hk] + change h i+(coupling g i ⬝ᵥ (fun k=>spinValue (Function.update x j b k)))=_ + rw [he,dotProduct_add,dotProduct_single] + exact (add_assoc _ _ _).symm + +lemma exp_spin (t : ℝ) (x : Bool) : + exp (t*spinValue x)=cosh t*(1+tanh t*spinValue x) := by + have h : cosh t ≠ 0 := (cosh_pos t).ne' + cases x + · simp only [spinValue_false,mul_neg_one,tanh_eq_sinh_div_cosh] + rw [← cosh_sub_sinh] + field_simp + ring + · simp only [spinValue_true,mul_one,tanh_eq_sinh_div_cosh] + rw [← cosh_add_sinh] + field_simp + +lemma exp_spin_product (t : ℝ) (x y : Bool) : + exp (t*spinValue x*spinValue y)=cosh t*(1+tanh t*spinValue x*spinValue y) := by + cases y + · simp only [spinValue_false,mul_neg_one] + have he := exp_spin t (!x) + simpa only [spinValue_not,mul_neg,neg_mul] using he + · simpa only [spinValue_true,mul_one] using exp_spin t x + +def pairBoltzmannWeight (α γ J : ℝ) (x y : Bool) : ℝ := + exp (α*spinValue x+γ*spinValue y+J*spinValue x*spinValue y) +def pairBoltzmannMean (α γ J : ℝ) (F : Bool→Bool→ℝ) : ℝ := + (∑ x,∑ y,pairBoltzmannWeight α γ J x y*F x y)/(∑ x,∑ y,pairBoltzmannWeight α γ J x y) + +lemma pairBoltzmannWeight_factor (α γ J : ℝ) (x y : Bool) : + pairBoltzmannWeight α γ J x y=cosh α*cosh γ*cosh J* + ((1+tanh α*spinValue x)*(1+tanh γ*spinValue y)*(1+tanh J*spinValue x*spinValue y)) := by + unfold pairBoltzmannWeight + rw [exp_add,exp_add,exp_spin,exp_spin,exp_spin_product] + ring + +lemma pairBoltzmann_partition (α γ J : ℝ) : + (∑ x,∑ y,pairBoltzmannWeight α γ J x y)= + 4*cosh α*cosh γ*cosh J*(1+tanh J*tanh α*tanh γ) := by + simp only [pairBoltzmannWeight_factor,Fintype.sum_bool,spinValue_false,spinValue_true] + ring + +lemma pairBoltzmannMean_eq (α γ J : ℝ) (F : Bool→Bool→ℝ) : + pairBoltzmannMean α γ J F=pairInterMean (tanh α) (tanh γ) (tanh J) F := by + unfold pairBoltzmannMean pairInterMean pairMean + rw [pairBoltzmann_partition] + simp_rw [pairBoltzmannWeight_factor] + rw [Finset.sum_div] + apply Finset.sum_congr rfl + intro x _ + rw [Finset.sum_div] + apply Finset.sum_congr rfl + intro y _ + unfold pairBaseMass pairDensity + have h₁ := (cosh_pos α).ne' + have h₂ := (cosh_pos γ).ne' + have h₃ := (cosh_pos J).ne' + field_simp [h₁,h₂,h₃] + +lemma pair_gradients_representation (F : Bool→Bool→ℝ) (a b : ℝ) : + ∃ p s r : ℝ, + (∀ y,(F true y-F false y)/2=pairGrad₁ b p r y) ∧ + (∀ x,(F x true-F x false)/2=pairGrad₂ a s r x) := by + let r := (F true true-F true false-F false true+F false false)/4 + let p := (F true true+F true false-F false true-F false false)/4+b*r + let s := (F true true-F true false+F false true-F false false)/4+a*r + refine ⟨p,s,r,?_,?_⟩ + · intro y;cases y <;> simp only [pairGrad₁,spinValue_false,spinValue_true] <;> dsimp [p,r] <;> ring + · intro x;cases x <;> simp only [pairGrad₂,spinValue_false,spinValue_true] <;> dsimp [s,r] <;> ring + +lemma tanh_add_real (a b : ℝ) : tanh (a+b)=(tanh a+tanh b)/(1+tanh a*tanh b) := by + have h₁ := (cosh_pos a).ne' + have h₂ := (cosh_pos b).ne' + have h₃ : cosh a*cosh b+sinh a*sinh b ≠ 0 := by + rw [← cosh_add] + exact (cosh_pos (a+b)).ne' + simp only [tanh_eq_sinh_div_cosh,sinh_add,cosh_add] + field_simp [h₁,h₂,h₃] + +lemma tanh_pair_residual (α J : ℝ) (x y : Bool) : + spinValue x-tanh (α+J*spinValue y)=pairResidual (tanh α) (tanh J) x y := by + have hh : tanh (J*spinValue y)=tanh J*spinValue y := by + cases y <;> simp only [spinValue_false,spinValue_true,mul_one,mul_neg_one,tanh_neg] + rw [tanh_add_real,hh] + unfold pairResidual + have hd : 1+tanh α*(tanh J*spinValue y) ≠ 0 := by + have ht : |tanh α*(tanh J*spinValue y)| < 1 := by + rw [abs_mul,abs_mul,pairSign_abs,mul_one] + exact (mul_le_mul_of_nonneg_left (abs_tanh_lt_one J).le (abs_nonneg (tanh α))).trans_lt (by simpa using abs_tanh_lt_one α) + linarith only [(abs_lt.mp ht).1] + have hd' : 1+tanh J*tanh α*spinValue y ≠ 0 := by + convert hd using 1; ring + simp only [← mul_assoc] at hd hd' ⊢ + field_simp [hd,hd'] + cases x <;> simp only [spinValue_false,spinValue_true] <;> ring + +lemma tanh_pair_variance (α J : ℝ) (y : Bool) : + 1-tanh (α+J*spinValue y)^2=pairVariance (tanh α) (tanh J) y := by + have hh : tanh (J*spinValue y)=tanh J*spinValue y := by + cases y <;> simp only [spinValue_false,spinValue_true,mul_one,mul_neg_one,tanh_neg] + rw [tanh_add_real,hh] + unfold pairVariance + have hd : 1+tanh α*(tanh J*spinValue y) ≠ 0 := by + have ht : |tanh α*(tanh J*spinValue y)| < 1 := by + rw [abs_mul,abs_mul,pairSign_abs,mul_one] + exact (mul_le_mul_of_nonneg_left (abs_tanh_lt_one J).le (abs_nonneg (tanh α))).trans_lt (by simpa using abs_tanh_lt_one α) + linarith only [(abs_lt.mp ht).1] + have hd' : 1+tanh J*tanh α*spinValue y ≠ 0 := by + convert hd using 1; ring + simp only [← mul_assoc] at hd hd' ⊢ + field_simp [hd,hd'] + cases y <;> simp only [spinValue_false,spinValue_true] <;> ring + +end SKRatio.Fields +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Calculus/FieldTails.lean b/lean/OAI/Probability/SKRatio/Calculus/FieldTails.lean new file mode 100644 index 0000000000000000000000000000000000000000..8b1d4e34888616630f90cda07033d018cbac973d --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Calculus/FieldTails.lean @@ -0,0 +1,234 @@ +import Mathlib +import OAI.Probability.SKRatio.Dynamics.PositiveLag + +namespace OAI + +section +noncomputable section +open scoped BigOperators Topology Matrix +open MeasureTheory Filter +namespace SKRatio.Calculus +attribute [local instance] Classical.propDecidable + +def reversal {n : ℕ} (x : Spin n) : Spin n := fun i => !(x i) + +@[simp] lemma reversal_reversal {n : ℕ} (x : Spin n) : reversal (reversal x) = x := by + funext i + simp [reversal] + +@[simp] lemma spin_reversal {n : ℕ} (x : Spin n) (i : Fin n) : + spin (reversal x) i = -spin x i := by + cases h : x i <;> simp [spin, reversal, h] + +@[simp] lemma mass_reversal {n : ℕ} (g : Disorder n) (x : Spin n) : + mass g 0 (reversal x) = mass g 0 x := by + have hv (i : Fin n) : spinValue (reversal x i) = -spinValue (x i) := + spin_reversal x i + simp [mass, weight, hamiltonian, hv] + +@[simp] lemma field_reversal {n : ℕ} (J : Interaction n) (x : Spin n) (i : Fin n) : + field J (reversal x) i = -field J x i := by + simp [field, spin_reversal, Finset.sum_neg_distrib] + +lemma gibbsMean_field_zero {n : ℕ} (g : Disorder n) (i : Fin n) : + FiniteLaw.mean (mass g 0) (fun x => field (coupling g) x i) = 0 := by + let e : Spin n ≃ Spin n := Function.Involutive.toPerm reversal (fun x => reversal_reversal x) + have he := Equiv.sum_comp e (fun x => mass g 0 x * field (coupling g) x i) + change (∑ x, mass g 0 (reversal x) * field (coupling g) (reversal x) i) = _ at he + simp only [mass_reversal, field_reversal, mul_neg, Finset.sum_neg_distrib] at he + unfold FiniteLaw.mean + linarith only [he] + +lemma halfDiff_field {n : ℕ} (J : Interaction n) (i j : Fin n) (x : Spin n) : + halfDiff j (fun y => field J y i) x = J i j := by + unfold field + rw [halfDiff_sum] + have hlin (l : Fin n) : halfDiff j (fun y => J i l * spin y l) x = + J i l * halfDiff j (fun y => spin y l) x := by unfold halfDiff; ring + simp only [hlin, halfDiff_spin, mul_ite, mul_one, mul_zero, Fintype.sum_ite_eq] + +lemma unweightedGradient_field {n : ℕ} (J : Interaction n) (i : Fin n) (x : Spin n) : + unweightedGradient (fun y => field J y i) x = ∑ j, J i j ^ 2 := by + simp [unweightedGradient, halfDiff_field] + +lemma stationary_field_variance_le {n : ℕ} (g : Disorder n) {γ R : ℝ} + (hγ : 0 < γ) (hrow : ∀ i, ∑ j, coupling g i j ^ 2 ≤ R) + (hgap : ∀ f : Observables n, + γ*FiniteLaw.variance (mass g 0) f ≤ stationaryEnergy g f) (i : Fin n) : + FiniteLaw.variance (mass g 0) (fun y => field (coupling g) y i) ≤ 2*R/γ := by + apply (le_div_iff₀ hγ).mpr + have h := hgap (fun y => field (coupling g) y i) + have hE : stationaryEnergy g (fun y => field (coupling g) y i) ≤ 2*R := by + unfold stationaryEnergy FiniteLaw.mean + calc + _ ≤ ∑ x, mass g 0 x * (2*R) := by + apply Finset.sum_le_sum + intro x _ + apply mul_le_mul_of_nonneg_left _ (mass_nonneg g 0 x) + have hh := weightedGradient_le (coupling g) (fun y => field (coupling g) y i) x + rw [unweightedGradient_field] at hh + exact hh.trans (mul_le_mul_of_nonneg_left (hrow i) (by norm_num)) + _ = _ := by rw [← Finset.sum_mul, sum_mass, one_mul] + linarith only [h, hE] + +lemma field_mean_of_overlap {n : ℕ} (g : Disorder n) {t ε V W : ℝ} + (ht : 0 ≤ t) (hε : 0 < ε) (hoverlap : continuousDistance g t ≤ 1-ε) + (hvar : ∀ x i, FiniteLaw.variance (continuousKernel (coupling g) t x) + (fun y => field (coupling g) y i) ≤ V) + (hstat : ∀ i, FiniteLaw.variance (mass g 0) (fun y => field (coupling g) y i) ≤ W) + (x : Spin n) (i : Fin n) : + |semigroup (coupling g) t (fun y => field (coupling g) y i) x| ≤ + (Real.sqrt V+Real.sqrt W)/Real.sqrt ε := by + have h := FiniteLaw.common_mass_means (continuousKernel (coupling g) t x) (mass g 0) + (fun y => field (coupling g) y i) + (continuousKernel_nonneg _ t ht x) (mass_nonneg g 0) + (continuousKernel_sum _ t x) (sum_mass g 0) hε + ((tv_le_continuousDistance g t x).trans hoverlap) + rw [gibbsMean_field_zero, sub_zero] at h + rw [← semigroup_eq_kernel] at h + exact h.trans (div_le_div_of_nonneg_right + (add_le_add (Real.sqrt_le_sqrt (hvar x i)) (Real.sqrt_le_sqrt (hstat i))) + (Real.sqrt_nonneg _)) + +lemma exp_abs_le_sum (z : ℝ) : Real.exp |z| ≤ Real.exp z + Real.exp (-z) := by + rcases le_total 0 z with hz | hz + · rw [abs_of_nonneg hz] + linarith [Real.exp_pos (-z)] + · rw [abs_of_nonpos hz] + linarith [Real.exp_pos z] + +lemma indicator_max_le_exp {n : ℕ} (u c : Fin n → ℝ) {θ H m : ℝ} + (hθ : 0 ≤ θ) (hc : ∀ i, |c i| ≤ m) : + (if ∃ i, H < |u i| then (1:ℝ) else 0) ≤ + Real.exp (-θ*(H-m)) * ∑ i, (Real.exp (θ*(u i-c i)) + Real.exp (-θ*(u i-c i))) := by + classical + by_cases hu : ∃ i, H < |u i| + · simp only [hu, ↓reduceIte] + obtain ⟨i, hi⟩ := hu + have htri : H-m ≤ |u i-c i| := by + have hh : |u i| ≤ |u i-c i|+|c i| := by + simpa only [sub_add_cancel] using abs_add_le (u i-c i) (c i) + linarith [hc i] + have hs : Real.exp (θ*|u i-c i|) ≤ + ∑ j, (Real.exp (θ*(u j-c j)) + Real.exp (-θ*(u j-c j))) := by + have hh := exp_abs_le_sum (θ*(u i-c i)) + rw [abs_mul, abs_of_nonneg hθ] at hh + have hh' : Real.exp (θ*|u i-c i|) ≤ + Real.exp (θ*(u i-c i))+Real.exp (-θ*(u i-c i)) := by + simpa only [neg_mul] using hh + exact hh'.trans (Finset.single_le_sum (f := fun j => + Real.exp (θ*(u j-c j))+Real.exp (-θ*(u j-c j))) + (fun j _ => by positivity) (Finset.mem_univ i)) + calc + 1 ≤ Real.exp (-θ*(H-m))*Real.exp (θ*|u i-c i|) := by + rw [← Real.exp_add, Real.one_le_exp_iff] + have hh := mul_le_mul_of_nonneg_left htri hθ + linarith + _ ≤ _ := mul_le_mul_of_nonneg_left hs (Real.exp_pos _).le + · simp only [hu, ↓reduceIte] + positivity + +lemma semigroup_max_tail {n : ℕ} (J : Interaction n) (f : Fin n → Observables n) + {t θ H m C : ℝ} (ht : 0 ≤ t) (hθ : 0 ≤ θ) (x : Spin n) + (hmean : ∀ i, |semigroup J t (f i) x| ≤ m) + (hmgf : ∀ i, ∀ σ ∈ ({-1,1}:Set ℝ), + semigroup J t (fun y => Real.exp (σ*θ*(f i y-semigroup J t (f i) x))) x ≤ C) : + semigroup J t (fun y => if ∃ i, H < |f i y| then (1:ℝ) else 0) x ≤ + 2*(n:ℝ)*C*Real.exp (-θ*(H-m)) := by + classical + have hh := semigroup_mono J ht _ _ (fun y => + indicator_max_le_exp (fun i => f i y) (fun i => semigroup J t (f i) x) (H := H) hθ hmean) x + have he : (fun y => Real.exp (-θ*(H-m))*∑ i, + (Real.exp (θ*(f i y-semigroup J t (f i) x)) + + Real.exp (-θ*(f i y-semigroup J t (f i) x)))) = + Real.exp (-θ*(H-m)) • ∑ i : Fin n, + ((fun y => Real.exp (θ*(f i y-semigroup J t (f i) x))) + + (fun y => Real.exp (-θ*(f i y-semigroup J t (f i) x)))) := by + funext y + simp only [Pi.smul_apply, smul_eq_mul, Finset.sum_apply, Pi.add_apply] + rw [he, map_smul, map_sum] at hh + simp only [Pi.smul_apply, smul_eq_mul, Finset.sum_apply, map_add, Pi.add_apply] at hh + have hib : ∀ i : Fin n, + semigroup J t (fun y => Real.exp (θ*(f i y-semigroup J t (f i) x))) x + + semigroup J t (fun y => Real.exp (-θ*(f i y-semigroup J t (f i) x))) x ≤ 2*C := by + intro i + have hpos := hmgf i 1 (by simp) + have hneg := hmgf i (-1) (by simp) + simp only [one_mul, neg_one_mul] at hpos hneg + linarith + calc + _ ≤ _ := hh + _ ≤ Real.exp (-θ*(H-m))*∑ _i : Fin n, 2*C := + mul_le_mul_of_nonneg_left (Finset.sum_le_sum (fun i _ => hib i)) (Real.exp_pos _).le + _ = _ := by simp; ring + +theorem uniform_field_tails_of_moments + (G : ∀ n : ℕ, Set (Disorder n)) {V W : ℝ} + (hstat : ∀ᶠ n : ℕ in atTop, ∀ g ∈ G n, ∀ i, + FiniteLaw.variance (mass g 0) (fun y => field (coupling g) y i) ≤ W) + (hvar : ∀ D : ℝ, 0 < D → ∀ᶠ n : ℕ in atTop, ∀ g ∈ G n, + ∀ t ∈ Set.Icc (0:ℝ) (D*Real.log n), ∀ x i, + FiniteLaw.variance (continuousKernel (coupling g) t x) + (fun y => field (coupling g) y i) ≤ V) + (hmgf : ∀ D θ : ℝ, 0 < D → 0 < θ → ∃ M : ℝ, + ∀ᶠ n : ℕ in atTop, ∀ g ∈ G n, ∀ t ∈ Set.Icc (0:ℝ) (D*Real.log n), + ∀ x i, ∀ σ ∈ ({-1,1}:Set ℝ), semigroup (coupling g) t + (fun y => Real.exp (σ*θ*(field (coupling g) y i- + semigroup (coupling g) t (fun z => field (coupling g) z i) x))) x ≤ M) : + ∀ ε δ D m : ℝ, 0 < ε → 0 < δ → 0 < D → 0 < m → + ∀ᶠ n : ℕ in atTop, ∀ g ∈ G n, ∀ t ∈ Set.Icc (0:ℝ) (D*Real.log n), + continuousDistance g t ≤ 1-ε → ∀ x, semigroup (coupling g) t + (fun y => if ∃ i, δ*Real.log n < |field (coupling g) y i| then 1 else 0) x ≤ + dimensionDecay m n := by + intro ε δ D m hε hδ hD hm + let θ := (m+2)/δ + have hθ : 0 < θ := div_pos (by linarith only [hm]) hδ + have hθδ : θ*δ = m+2 := div_mul_cancel₀ _ (ne_of_gt hδ) + let B := (Real.sqrt V+Real.sqrt W)/Real.sqrt ε + obtain ⟨M,hM⟩ := hmgf D θ hD hθ + have herr := (dimensionDecay_tendsto_zero (by norm_num : (0:ℝ)<1)).const_mul + (2*M*Real.exp (θ*B)) + simp only [mul_zero] at herr + have herr' : ∀ᶠ n : ℕ in atTop, + (2*M*Real.exp (θ*B))*dimensionDecay 1 n ≤ 1 := by + filter_upwards [herr.eventually (gt_mem_nhds (by norm_num : (0:ℝ)<1))] with n hn + simpa only [mul_zero] using hn.le + filter_upwards [hstat,hvar D hD,hM,herr',eventually_gt_atTop 0] + with n hnstat hnvar hnmgf hnerr hn + intro g hg t ht ho x + have hmean := field_mean_of_overlap g ht.1 hε ho (hnvar g hg t ht) (hnstat g hg) x + have h := semigroup_max_tail (coupling g) (fun i y => field (coupling g) y i) + (H := δ*Real.log n) ht.1 hθ.le x hmean (hnmgf g hg t ht x) + have he : 2*(n:ℝ)*M*Real.exp (-θ*(δ*Real.log n-B)) = + ((2*M*Real.exp (θ*B))*dimensionDecay 1 n)*dimensionDecay m n := by + have he' : Real.exp (-θ*(δ*Real.log n-B)) = + Real.exp (θ*B)*dimensionDecay (m+2) n := by + unfold dimensionDecay + rw [← Real.exp_add] + congr 1 + calc + _ = θ*B-(θ*δ)*Real.log n := by ring + _ = _ := by rw [hθδ]; ring + rw [he'] + calc + _ = (2*M*Real.exp (θ*B))*((n:ℝ)*dimensionDecay (m+2) n) := by ring + _ = (2*M*Real.exp (θ*B))*dimensionDecay (m+2-1) n := by + rw [nat_mul_dimensionDecay hn] + _ = (2*M*Real.exp (θ*B))*(dimensionDecay 1 n*dimensionDecay m n) := by + congr 1 + unfold dimensionDecay + rw [← Real.exp_add] + congr 1 + ring + _ = _ := by ring + change _ ≤ 2*(n:ℝ)*M*Real.exp (-θ*(δ*Real.log n-B)) at h + rw [he] at h + exact h.trans (by simpa only [one_mul] using + (mul_le_mul_of_nonneg_right hnerr (dimensionDecay_pos m n).le)) + +end SKRatio.Calculus + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Calculus/GibbsMeanCLM.lean b/lean/OAI/Probability/SKRatio/Calculus/GibbsMeanCLM.lean new file mode 100644 index 0000000000000000000000000000000000000000..3237cfefbb1dae996fe01ad25636b6394dcd53ad --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Calculus/GibbsMeanCLM.lean @@ -0,0 +1,258 @@ +import Mathlib +import OAI.Probability.SKRatio.FiniteChain.MeanMulVec +import OAI.Probability.SKRatio.Calculus.SignedVector + +namespace OAI + +section +noncomputable section +open scoped BigOperators Topology Matrix +open ContinuousLinearMap +namespace SKRatio.Calculus +open Real Set + +def gibbsMeanCLM {n : ℕ} (g : Disorder n) : Observables n →L[ℝ] ℝ := + (∑ x : Spin n, mass g 0 x • ContinuousLinearMap.proj x) + +@[simp] lemma gibbsMeanCLM_apply {n : ℕ} (g : Disorder n) (f : Observables n) : + gibbsMeanCLM g f = FiniteLaw.mean (mass g 0) f := by + simp [gibbsMeanCLM, FiniteLaw.mean] + +lemma gibbsMean_generator {n : ℕ} (g : Disorder n) (f : Observables n) : + gibbsMeanCLM g (generator (coupling g) f) = 0 := by + have heq : generator (coupling g) f = (n:ℝ) • (transition g *ᵥ f - f) := by + funext x + exact generator_eq_transition g f x + rw [heq, map_smul, map_sub] + simp only [gibbsMeanCLM_apply, FiniteLaw.mean_mulVec, transition_stationary, sub_self, + smul_zero] + +lemma functional_exp_invariant {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] + [CompleteSpace E] (A : E →L[ℝ] E) (T : E →L[ℝ] ℝ) + (h : ∀ f, T (A f) = 0) (f : E) : T (NormedSpace.exp A f) = T f := by + have hp (k : ℕ) : T ((A^(k+1)) f) = 0 := by + rw [pow_succ', mul_apply_eq_comp, h] + have hs := T.hasSum (exp_apply_hasSum A f) + have eqs : (fun k : ℕ => T ((k.factorial:ℝ)⁻¹ • ((A^k) f))) = + fun k => if k = 0 then T f else 0 := by + funext k + cases k with + | zero => simp + | succ k => simp only [map_smul, hp, smul_zero, Nat.succ_ne_zero, ↓reduceIte] + rw [eqs] at hs + exact hs.unique (hasSum_ite_eq 0 (T f)) + +theorem gibbsMean_semigroup {n : ℕ} (g : Disorder n) (t : ℝ) + (f : Observables n) : + FiniteLaw.mean (mass g 0) (semigroup (coupling g) t f) = + FiniteLaw.mean (mass g 0) f := by + simpa only [gibbsMeanCLM_apply, semigroup] using + functional_exp_invariant (t • generatorCLM (coupling g)) (gibbsMeanCLM g) + (fun f => by + rw [smul_apply, map_smul] + change t • gibbsMeanCLM g (generator (coupling g) f) = 0 + rw [gibbsMean_generator, smul_zero]) f + +theorem continuousKernel_stationary {n : ℕ} (g : Disorder n) (t : ℝ) : + mass g 0 ᵥ* continuousKernel (coupling g) t = mass g 0 := by + funext y + have h := gibbsMean_semigroup g t (fun z => if z = y then (1:ℝ) else 0) + simpa only [FiniteLaw.mean, Matrix.vecMul, continuousKernel, dotProduct, + mul_ite, mul_one, mul_zero, Fintype.sum_ite_eq'] using h + +def continuousDistance {n : ℕ} (g : Disorder n) (t : ℝ) : ℝ := + Finset.univ.sup' Finset.univ_nonempty + (fun x : Spin n => totalVariation (continuousKernel (coupling g) t x) (mass g 0)) + +lemma continuousKernel_stochastic {n : ℕ} (J : Interaction n) {t : ℝ} (ht : 0 ≤ t) : + continuousKernel J t ∈ Matrix.rowStochastic ℝ (Spin n) := by + exact Matrix.mem_rowStochastic_iff_sum.mpr + ⟨continuousKernel_nonneg J t ht, continuousKernel_sum J t⟩ + +lemma tv_le_continuousDistance {n : ℕ} (g : Disorder n) (t : ℝ) (x : Spin n) : + totalVariation (continuousKernel (coupling g) t x) (mass g 0) ≤ + continuousDistance g t := by + unfold continuousDistance + exact Finset.le_sup' (fun z : Spin n => + totalVariation (continuousKernel (coupling g) t z) (mass g 0)) (Finset.mem_univ x) + +lemma continuousDistance_nonneg {n : ℕ} (g : Disorder n) (t : ℝ) : + 0 ≤ continuousDistance g t := + (totalVariation_nonneg _ _).trans (tv_le_continuousDistance g t (fun _ => true)) + +lemma continuousDistance_le_one {n : ℕ} (g : Disorder n) {t : ℝ} (ht : 0 ≤ t) : + continuousDistance g t ≤ 1 := by + apply Finset.sup'_le + intro x _ + exact totalVariation_le_one _ _ (continuousKernel_nonneg _ t ht x) (mass_nonneg g 0) + (continuousKernel_sum _ t x) (sum_mass g 0) + +lemma continuousDistance_antitone {n : ℕ} (g : Disorder n) {s t : ℝ} + (_hs : 0 ≤ s) (hst : s ≤ t) : continuousDistance g t ≤ continuousDistance g s := by + apply Finset.sup'_le + intro x _ + have htime : t = s + (t-s) := by ring + have hsum : (∑ y, continuousKernel (coupling g) s x y) = ∑ y, mass g 0 y := by + rw [continuousKernel_sum, sum_mass] + calc + _ = totalVariation (continuousKernel (coupling g) s x ᵥ* + continuousKernel (coupling g) (t-s)) + (mass g 0 ᵥ* continuousKernel (coupling g) (t-s)) := by + rw [continuousKernel_stationary] + conv_lhs => rw [htime, continuousKernel_add, Matrix.mul_apply_eq_vecMul] + _ ≤ totalVariation (continuousKernel (coupling g) s x) (mass g 0) := + totalVariation_contract _ (continuousKernel_stochastic _ (sub_nonneg.mpr hst)) _ _ hsum + _ ≤ _ := tv_le_continuousDistance g s x + +theorem continuousDistance_smoothing {n : ℕ} (g : Disorder n) {t s : ℝ} + (ht : 0 ≤ t) {ε V W : ℝ} (hε : 0 < ε) + (hoverlap : continuousDistance g t ≤ 1-ε) + (htransient : ∀ (x : Spin n) (f : Observables n), (∀ y, |f y| ≤ 1) → + FiniteLaw.variance (continuousKernel (coupling g) t x) + (semigroup (coupling g) s f) ≤ V) + (hequilibrium : ∀ f : Observables n, (∀ y, |f y| ≤ 1) → + FiniteLaw.variance (mass g 0) (semigroup (coupling g) s f) ≤ W) : + continuousDistance g (t+s) ≤ (Real.sqrt V+Real.sqrt W)/(2*Real.sqrt ε) := by + apply Finset.sup'_le + intro x _ + apply FiniteLaw.totalVariation_le_of_tests + intro f hf + have hc := FiniteLaw.common_mass_means (continuousKernel (coupling g) t x) (mass g 0) + (semigroup (coupling g) s f) (continuousKernel_nonneg _ t ht x) (mass_nonneg g 0) + (continuousKernel_sum _ t x) (sum_mass g 0) hε + ((tv_le_continuousDistance g t x).trans hoverlap) + rw [gibbsMean_semigroup, ← semigroup_eq_kernel, ← mul_apply_eq_comp, + ← semigroup_add, semigroup_eq_kernel] at hc + calc + _ ≤ (Real.sqrt (FiniteLaw.variance (continuousKernel (coupling g) t x) + (semigroup (coupling g) s f))+ + Real.sqrt (FiniteLaw.variance (mass g 0) (semigroup (coupling g) s f))) / + Real.sqrt ε := hc + _ ≤ (Real.sqrt V+Real.sqrt W) / Real.sqrt ε := by + apply div_le_div_of_nonneg_right _ (Real.sqrt_nonneg _) + exact add_le_add (Real.sqrt_le_sqrt (htransient x f hf)) + (Real.sqrt_le_sqrt (hequilibrium f hf)) + _ = _ := by ring + +lemma gradientWeight_le_two {n : ℕ} (J : Interaction n) (x : Spin n) (i : Fin n) : + gradientWeight J x i ≤ 2 := by + have hl : -1 < mean J x i := Real.neg_one_lt_tanh _ + have hu : mean J x i < 1 := Real.tanh_lt_one _ + unfold gradientWeight spin + cases x i <;> simp only [Bool.false_eq_true, ↓reduceIte] <;> linarith + +lemma weightedGradient_nonneg {n : ℕ} (J : Interaction n) (f : Observables n) (x : Spin n) : + 0 ≤ weightedGradient J f x := by + exact Finset.sum_nonneg (fun i _ => mul_nonneg (gradientWeight_pos J x i).le (sq_nonneg _)) + +lemma weightedGradient_le {n : ℕ} (J : Interaction n) (f : Observables n) (x : Spin n) : + weightedGradient J f x ≤ 2*unweightedGradient f x := by + rw [unweightedGradient, Finset.mul_sum] + exact Finset.sum_le_sum (fun i _ => + mul_le_mul_of_nonneg_right (gradientWeight_le_two J x i) (sq_nonneg _)) + +lemma halfDiff_abs_le {n : ℕ} (f : Observables n) {B : ℝ} + (hf : ∀ x, |f x| ≤ B) (x : Spin n) (i : Fin n) : |halfDiff i f x| ≤ B := by + unfold halfDiff + rw [abs_div, abs_of_pos (by norm_num : (0:ℝ) < 2)] + have h := (abs_sub (f (replace x i true)) (f (replace x i false))).trans + (add_le_add (hf _) (hf _)) + linarith only [h] + +lemma unweightedGradient_le_dim {n : ℕ} (f : Observables n) (hf : ∀ x, |f x| ≤ 1) + (x : Spin n) : unweightedGradient f x ≤ n := by + calc + _ ≤ ∑ _i : Fin n, (1:ℝ) := by + apply Finset.sum_le_sum + intro i _ + exact (sq_le_one_iff_abs_le_one _).mpr (halfDiff_abs_le f hf x i) + _ = _ := by simp + +lemma continuous_halfDiff {n : ℕ} (i : Fin n) (F : ℝ → Observables n) + (hF : Continuous F) (x : Spin n) : Continuous (fun t => halfDiff i (F t) x) := by + exact (((continuous_apply _).comp hF).sub ((continuous_apply _).comp hF)).div_const 2 + +lemma continuous_weightedGradient {n : ℕ} (J : Interaction n) (F : ℝ → Observables n) + (hF : Continuous F) : Continuous (fun t => weightedGradient J (F t)) := by + apply continuous_pi + intro x + exact continuous_finsetSum _ (fun i _ => + ((continuous_halfDiff i F hF x).pow 2).const_mul (gradientWeight J x i)) + +def backwardEnergy {n : ℕ} (J : Interaction n) (f : Observables n) + (x : Spin n) (T u : ℝ) : ℝ := + semigroup J u (weightedGradient J (semigroup J (T-u) f)) x + +lemma backwardEnergy_continuous {n : ℕ} (J : Interaction n) (f : Observables n) + (x : Spin n) (T : ℝ) : Continuous (backwardEnergy J f x T) := by + exact (continuous_apply x).comp ((semigroup_continuous J).clm_apply + (continuous_weightedGradient J _ (((semigroup_continuous J).comp + (continuous_const.sub continuous_id)).clm_apply continuous_const))) + +lemma backwardEnergy_nonneg {n : ℕ} (J : Interaction n) (f : Observables n) + (x : Spin n) (T u : ℝ) (hu : 0 ≤ u) : 0 ≤ backwardEnergy J f x T u := by + exact semigroup_nonneg J u hu _ (weightedGradient_nonneg J _) x + +lemma backward_second_moment_hasDerivAt {n : ℕ} (J : Interaction n) (f : Observables n) + (x : Spin n) (T u : ℝ) : + HasDerivAt (fun r : ℝ => semigroup J r (fun y => (semigroup J (T-r) f y)^2) x) + (2*backwardEnergy J f x T u) u := by + let F : ℝ → Observables n := fun r => semigroup J (T-r) f + have hF : HasDerivAt F (-generator J (F u)) u := by + simpa only [Function.comp_def, sub_zero, zero_sub, neg_smul, one_smul] using + (semigroup_apply_hasDerivAt' J f (T-u)).scomp u + ((hasDerivAt_const u T).sub (hasDerivAt_id u)) + have hsq : HasDerivAt (fun r : ℝ => (fun y => (F r y)^2)) + (fun y => -2*F u y*generator J (F u) y) u := by + apply hasDerivAt_pi.mpr + intro y + convert (hasDerivAt_pi.mp hF y).fun_pow 2 using 1 + simp only [Pi.neg_apply, Nat.cast_ofNat, Nat.reduceSub, pow_one] + ring + have H := (semigroup_hasDerivAt J u).clm_apply hsq + have heq : (semigroup J u*generatorCLM J) (fun y => F u y^2) + + semigroup J u (fun y => -2*F u y*generator J (F u) y) = + (2:ℝ) • semigroup J u (weightedGradient J (F u)) := by + rw [mul_apply_eq_comp, ← map_add, ← map_smul] + congr 1 + funext y + change generator J (fun y => F u y^2) y + (-2*F u y*generator J (F u) y) = + 2*weightedGradient J (F u) y + have h := variance_density J (F u) y + linarith only [h] + rw [heq] at H + exact hasDerivAt_pi.mp H x + +theorem backward_variance_budget {n : ℕ} (J : Interaction n) (f : Observables n) + (x : Spin n) (T r : ℝ) : + FiniteLaw.variance (continuousKernel J r x) (semigroup J (T-r) f) = + 2*∫ u in (0:ℝ)..r, backwardEnergy J f x T u := by + have hi := intervalIntegral.integral_eq_sub_of_hasDerivAt + (fun u _ => backward_second_moment_hasDerivAt J f x T u) + ((backwardEnergy_continuous J f x T).const_mul 2 |>.intervalIntegrable 0 r) + rw [intervalIntegral.integral_const_mul] at hi + rw [FiniteLaw.variance_eq _ _ (continuousKernel_sum J r x), + ← semigroup_eq_kernel, ← semigroup_eq_kernel, + ← mul_apply_eq_comp, ← semigroup_add] + have heq : r+(T-r) = T := by ring + rw [heq] + simpa only [semigroup_zero, one_apply_eq_self, sub_zero] using hi.symm + +theorem backward_energy_budget {n : ℕ} (J : Interaction n) (f : Observables n) + (hf : ∀ y, |f y| ≤ 1) (x : Spin n) {T : ℝ} (hT : 0 ≤ T) : + (∫ u in (0:ℝ)..T, backwardEnergy J f x T u) ≤ 1/2 := by + have hi := backward_variance_budget J f x T T + simp only [sub_self, semigroup_zero, one_apply_eq_self] at hi + rw [FiniteLaw.variance_eq _ _ (continuousKernel_sum J T x), ← semigroup_eq_kernel, + ← semigroup_eq_kernel] at hi + have hsquares : ∀ y, f y^2 ≤ (1:ℝ) := fun y => (sq_le_one_iff_abs_le_one _).mpr (hf y) + have hm := semigroup_mono J hT (fun y => f y^2) (fun _ => 1) hsquares x + rw [semigroup_const] at hm + linarith [sq_nonneg (semigroup J T f x)] + +end SKRatio.Calculus + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Calculus/GradientMoments.lean b/lean/OAI/Probability/SKRatio/Calculus/GradientMoments.lean new file mode 100644 index 0000000000000000000000000000000000000000..38701a395206b7c1d11818410a9189789e23f71c --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Calculus/GradientMoments.lean @@ -0,0 +1,223 @@ +import Mathlib +import OAI.Probability.SKRatio.Calculus.FieldTails + +namespace OAI + +section +noncomputable section +open scoped BigOperators Topology Matrix +open MeasureTheory Filter +namespace SKRatio.Calculus +attribute [local instance] Classical.propDecidable + +lemma integral_exp_decay_le {κ d : ℝ} (hκ : 0 < κ) : + (∫ r in (0:ℝ)..d, Real.exp (-κ*r)) ≤ 1/κ := by + have hd (r : ℝ) : HasDerivAt (fun r : ℝ => -Real.exp (-κ*r)/κ) + (Real.exp (-κ*r)) r := by + have h := (((hasDerivAt_id r).const_mul (-κ)).exp.neg).div_const κ + apply h.congr_deriv + simp only [mul_one, id_eq] + field_simp + have hi : IntervalIntegrable (fun r : ℝ => Real.exp (-κ*r)) volume 0 d := + (by fun_prop : Continuous (fun r : ℝ => Real.exp (-κ*r))).intervalIntegrable 0 d + rw [intervalIntegral.integral_eq_sub_of_hasDerivAt (fun r _ => hd r) hi] + simp only [mul_zero, Real.exp_zero, neg_div] + have hp := div_nonneg (Real.exp_nonneg (-κ*d)) hκ.le + linarith + +lemma gradient_envelope_bounds {κ C E R d : ℝ} + (hκ : 0 < κ) (hC : 0 ≤ C) (hR : 0 ≤ R) (hd : 0 ≤ d) + (hE : E ≤ 1) (hdE : d*E ≤ 1) : + (∀ r ∈ Set.Icc (0:ℝ) d, R*(C*Real.exp (-κ*r)+E) ≤ R*(C+1)) ∧ + (∫ r in (0:ℝ)..d, R*(C*Real.exp (-κ*r)+E)) ≤ R*(C/κ+1) := by + refine ⟨?_,?_⟩ + · intro r hr + apply mul_le_mul_of_nonneg_left _ hR + have he : Real.exp (-κ*r) ≤ 1 := Real.exp_le_one_iff.mpr (by nlinarith only [hκ,hr.1]) + have hc := mul_le_mul_of_nonneg_left he hC + linarith + · have hi : IntervalIntegrable (fun r : ℝ => C*Real.exp (-κ*r)) volume 0 d := + (intervalIntegrable_iff_integrableOn_Icc_of_le hd).mpr + (by fun_prop : Continuous (fun r : ℝ => C*Real.exp (-κ*r))).integrableOn_Icc + rw [intervalIntegral.integral_const_mul, intervalIntegral.integral_add hi intervalIntegrable_const, + intervalIntegral.integral_const_mul, intervalIntegral.integral_const] + simp only [sub_zero, smul_eq_mul] + apply mul_le_mul_of_nonneg_left _ hR + have hu := mul_le_mul_of_nonneg_left (integral_exp_decay_le (d := d) hκ) hC + simpa only [mul_one_div] using add_le_add hu hdE + +lemma moments_of_gradient_envelope {n : ℕ} (J : Interaction n) (f : Observables n) + {κ C E R d : ℝ} (hκ : 0 < κ) (hC : 0 ≤ C) (hR : 0 ≤ R) (hd : 0 ≤ d) + (hE : E ≤ 1) (hdE : d*E ≤ 1) + (henv : ∀ r ∈ Set.Icc (0:ℝ) d, ∀ x, + unweightedGradient (semigroup J r f) x ≤ R*(C*Real.exp (-κ*r)+E)) : + (∀ x, FiniteLaw.variance (continuousKernel J d x) f ≤ 4*(R*(C/κ+1))) ∧ + (∀ θ x, semigroup J d (fun y => Real.exp (θ*(f y-semigroup J d f x))) x ≤ + Real.exp (2*θ^2*Real.exp (2*|θ| *Real.sqrt (R*(C+1)))*(R*(C/κ+1)))) := by + have hb : IntervalIntegrable (fun r : ℝ => R*(C*Real.exp (-κ*r)+E)) volume 0 d := + (by fun_prop : Continuous (fun r : ℝ => R*(C*Real.exp (-κ*r)+E))).intervalIntegrable 0 d + have ⟨hB,hI⟩ := gradient_envelope_bounds hκ hC hR hd hE hdE + constructor + · intro x + rw [FiniteLaw.variance_eq _ _ (continuousKernel_sum J d x), ← semigroup_eq_kernel, + ← semigroup_eq_kernel] + exact (semigroup_variance_le J f d hd _ hb henv x).trans + (mul_le_mul_of_nonneg_left hI (by norm_num)) + · intro θ x + exact (semigroup_jump_mgf J f d hd _ (R*(C+1)) θ hb hB henv x).trans + (Real.exp_le_exp.mpr (mul_le_mul_of_nonneg_left hI (by positivity))) + +lemma gradient_envelope_of_small_set {n : ℕ} (J : Interaction n) + (f : Observables n) (bad : Set (Spin n)) {κ A d₀ T q R : ℝ} + (hκ : 0 ≤ κ) (hA : 0 ≤ A) (hd₀ : 0 ≤ d₀) (hq : 0 ≤ q) (hR : 0 ≤ R) + (hinit : ∀ y, unweightedGradient f y ≤ R) + (hdrift : ∀ r ∈ Set.Icc (0:ℝ) T, ∀ y, + deriv (fun v => unweightedGradient (semigroup J v f) y) r - + generator J (unweightedGradient (semigroup J r f)) y ≤ + (-κ + if y ∈ bad then A else 0)*unweightedGradient (semigroup J r f) y) + (havoid : ∀ u ∈ Set.Icc d₀ T, ∀ x, + semigroup J u (fun y => if y ∈ bad then 1 else 0) x ≤ q) + (r : ℝ) (hr : r ∈ Set.Icc (0:ℝ) T) (x : Spin n) : + unweightedGradient (semigroup J r f) x ≤ + R*(Real.exp (A*d₀)*Real.exp (-κ*r)+A*Real.exp (A*d₀)*T*Real.exp (A*T)*q) := by + have h := gradient_propagation_small_set J f bad hκ hA hd₀ hr.1 le_rfl hr.2 hq hR + (fun v hv => hdrift v ⟨hv.1,hv.2.trans hr.2⟩) havoid + (by simpa only [sub_self,semigroup_zero,one_apply_eq_self] using hinit) x + simp only [sub_self,semigroup_zero,one_apply_eq_self] at h + calc + _ ≤ _ := h + _ ≤ Real.exp (A*d₀)*Real.exp (-κ*r)*R + + A*Real.exp (A*d₀)*T*Real.exp (A*T)*q*R := + add_le_add (mul_le_mul_of_nonneg_left + (semigroup_le_const J r hr.1 hinit x) (by positivity)) le_rfl + _ = _ := by ring + +theorem uniform_gradient_moments_of_small_set + (G : ∀ n : ℕ, Set (Disorder n)) + (bad : ∀ n, Disorder n → Set (Spin n)) {κ A d₀ : ℝ} + (hκ : 0 < κ) (hA : 0 ≤ A) (hd₀ : 0 ≤ d₀) + (hdrift : ∀ D : ℝ, 0 < D → ∀ᶠ n : ℕ in atTop, ∀ g ∈ G n, + ∀ (f : Observables n), ∀ r ∈ Set.Icc (0:ℝ) (D*Real.log n), ∀ y, + deriv (fun v => unweightedGradient (semigroup (coupling g) v f) y) r - + generator (coupling g) (unweightedGradient (semigroup (coupling g) r f)) y ≤ + (-κ + if y ∈ bad n g then A else 0)* + unweightedGradient (semigroup (coupling g) r f) y) + (havoid : ∀ D m : ℝ, 0 < D → 0 < m → + ∀ᶠ n : ℕ in atTop, ∀ g ∈ G n, ∀ u ∈ Set.Icc d₀ (D*Real.log n), ∀ x, + semigroup (coupling g) u (fun y => if y ∈ bad n g then 1 else 0) x ≤ dimensionDecay m n) + {D R : ℝ} (hD : 0 < D) (hR : 0 ≤ R) : + ∀ᶠ n : ℕ in atTop, ∀ g ∈ G n, ∀ f : Observables n, + (∀ y, unweightedGradient f y ≤ R) → ∀ d ∈ Set.Icc (0:ℝ) (D*Real.log n), + (∀ x, FiniteLaw.variance (continuousKernel (coupling g) d x) f ≤ + 4*(R*(Real.exp (A*d₀)/κ+1))) ∧ + (∀ θ x, semigroup (coupling g) d (fun y => Real.exp + (θ*(f y-semigroup (coupling g) d f x))) x ≤ + Real.exp (2*θ^2*Real.exp (2*|θ| *Real.sqrt (R*(Real.exp (A*d₀)+1)))* + (R*(Real.exp (A*d₀)/κ+1)))) := by + let C := Real.exp (A*d₀) + let E (n : ℕ) := A*C*D*(Real.log n)*dimensionDecay 4 n + have hEn : Tendsto E atTop (𝓝 0) := by + have h := (log_pow_mul_dimensionDecay_tendsto_zero 1 (by norm_num : (0:ℝ)<4)).const_mul (A*C*D) + simpa only [pow_one, mul_zero, mul_assoc, E] using h + have hTEn : Tendsto (fun n : ℕ => (D*Real.log n)*E n) atTop (𝓝 0) := by + have h := (log_pow_mul_dimensionDecay_tendsto_zero 2 (by norm_num : (0:ℝ)<4)).const_mul (A*C*D^2) + simp only [mul_zero] at h + convert h using 1 + funext n + dsimp only [E] + ring + have hm : 0 < A*D+4 := by positivity + filter_upwards [hdrift D hD,havoid D (A*D+4) hD hm, + hEn.eventually (gt_mem_nhds (by norm_num : (0:ℝ)<1)), + hTEn.eventually (gt_mem_nhds (by norm_num : (0:ℝ)<1)),eventually_ge_atTop 1] + with n hndrift hnavoid hnE hnTE hn + intro g hg f hf d hd + have hlog : 0 ≤ Real.log n := Real.log_nonneg (by exact_mod_cast hn) + have hE0 : 0 ≤ E n := by dsimp [E,C,dimensionDecay]; positivity + have herror : A*Real.exp (A*d₀)*(D*Real.log n)*Real.exp (A*(D*Real.log n))* + dimensionDecay (A*D+4) n = E n := by + have hprod : Real.exp (A*(D*Real.log n))*dimensionDecay (A*D+4) n = dimensionDecay 4 n := by + unfold dimensionDecay + rw [← Real.exp_add] + congr 1 + ring + rw [mul_assoc (A*Real.exp (A*d₀)*(D*Real.log n)),hprod] + dsimp only [E,C] + ring + apply moments_of_gradient_envelope (coupling g) f hκ (Real.exp_nonneg _) hR hd.1 hnE.le + ((mul_le_mul_of_nonneg_right hd.2 hE0).trans hnTE.le) + intro r hr x + have h := gradient_envelope_of_small_set (coupling g) f (bad n g) + hκ.le hA hd₀ (dimensionDecay_pos (A*D+4) n).le hR hf + (hndrift g hg f) (hnavoid g hg) r ⟨hr.1,hr.2.trans hd.2⟩ x + rwa [herror] at h + +lemma row_squares_le_opNorm {n : ℕ} (J : Interaction n) + (hsymm : ∀ i j, J i j = J j i) {K : ℝ} + (hK : 0 ≤ K) + (hop : ‖Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) J‖ ≤ K) (i : Fin n) : + ∑ j, J i j ^ 2 ≤ K^2 := by + let e : EuclideanSpace ℝ (Fin n) := EuclideanSpace.single i 1 + have he : ‖e‖ = 1 := by simp [e] + have h := (Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) J).le_opNorm e + rw [he,mul_one] at h + have hsq := sq_le_sq₀ (norm_nonneg _) hK |>.mpr (h.trans hop) + rw [EuclideanSpace.real_norm_sq_eq] at hsq + have happly (j : Fin n) : + (Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) J e).ofLp j = J i j := by + change (∑ coordinate, J j coordinate * e.ofLp coordinate) = J i j + simp only [e, EuclideanSpace.single, PiLp.single_apply, + mul_ite, mul_one, mul_zero] + simp [hsymm j i] + simpa only [happly] using hsq + +theorem uniform_field_tails_of_small_set + (G : ∀ n : ℕ, Set (Disorder n)) + (bad : ∀ n, Disorder n → Set (Spin n)) {κ A d₀ γ R : ℝ} + (hκ : 0 < κ) (hA : 0 ≤ A) (hd₀ : 0 ≤ d₀) (hγ : 0 < γ) (hR : 0 ≤ R) + (hrow : ∀ᶠ n : ℕ in atTop, ∀ g ∈ G n, ∀ i, ∑ j, coupling g i j ^ 2 ≤ R) + (hgap : ∀ᶠ n : ℕ in atTop, ∀ g ∈ G n, ∀ f : Observables n, + γ*FiniteLaw.variance (mass g 0) f ≤ stationaryEnergy g f) + (hdrift : ∀ D : ℝ, 0 < D → ∀ᶠ n : ℕ in atTop, ∀ g ∈ G n, + ∀ (f : Observables n), ∀ r ∈ Set.Icc (0:ℝ) (D*Real.log n), ∀ y, + deriv (fun v => unweightedGradient (semigroup (coupling g) v f) y) r - + generator (coupling g) (unweightedGradient (semigroup (coupling g) r f)) y ≤ + (-κ + if y ∈ bad n g then A else 0)* + unweightedGradient (semigroup (coupling g) r f) y) + (havoid : ∀ D m : ℝ, 0 < D → 0 < m → + ∀ᶠ n : ℕ in atTop, ∀ g ∈ G n, ∀ u ∈ Set.Icc d₀ (D*Real.log n), ∀ x, + semigroup (coupling g) u (fun y => if y ∈ bad n g then 1 else 0) x ≤ dimensionDecay m n) : + ∀ ε δ D m : ℝ, 0 < ε → 0 < δ → 0 < D → 0 < m → + ∀ᶠ n : ℕ in atTop, ∀ g ∈ G n, ∀ t ∈ Set.Icc (0:ℝ) (D*Real.log n), + continuousDistance g t ≤ 1-ε → ∀ x, semigroup (coupling g) t + (fun y => if ∃ i, δ*Real.log n < |field (coupling g) y i| then 1 else 0) x ≤ + dimensionDecay m n := by + have hmom {D : ℝ} (hD : 0 < D) := + uniform_gradient_moments_of_small_set G bad hκ hA hd₀ hdrift havoid hD hR + apply uniform_field_tails_of_moments (V := 4*(R*(Real.exp (A*d₀)/κ+1))) + (W := 2*R/γ) G + · filter_upwards [hrow,hgap] with n hnrow hngap + intro g hg i + exact stationary_field_variance_le g hγ (hnrow g hg) (hngap g hg) i + · intro D hD + filter_upwards [hrow,hmom hD] with n hnrow hnmom + intro g hg t ht x i + exact (hnmom g hg (fun y => field (coupling g) y i) + (fun y => by rw [unweightedGradient_field]; exact hnrow g hg i) t ht).1 x + · intro D θ hD hθ + refine ⟨Real.exp (2*θ^2*Real.exp (2*θ*Real.sqrt (R*(Real.exp (A*d₀)+1)))* + (R*(Real.exp (A*d₀)/κ+1))),?_⟩ + filter_upwards [hrow,hmom hD] with n hnrow hnmom + intro g hg t ht x i σ hσ + have h := (hnmom g hg (fun y => field (coupling g) y i) + (fun y => by rw [unweightedGradient_field]; exact hnrow g hg i) t ht).2 (σ*θ) x + rcases hσ with hσ | hσ <;> rcases hσ with rfl + · simpa only [neg_one_mul, neg_sq, abs_neg, abs_of_pos hθ] using h + · simpa only [one_mul, abs_of_pos hθ] using h + +end SKRatio.Calculus + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Calculus/HeatBathLinearKernel.lean b/lean/OAI/Probability/SKRatio/Calculus/HeatBathLinearKernel.lean new file mode 100644 index 0000000000000000000000000000000000000000..3111818359f19969ebbbf6ca02067d280d6aebc9 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Calculus/HeatBathLinearKernel.lean @@ -0,0 +1,96 @@ +import Mathlib +import OAI.Probability.SKRatio.Calculus.PairUpdate + +namespace OAI + +section +noncomputable section +open scoped BigOperators RealInnerProductSpace +namespace SKRatio.Fields +open Real Matrix TwoSpin +attribute [local instance] Classical.propDecidable +variable {n : ℕ} + +lemma heatBathLinear_kernel (g : Disorder n) (h : Fin n→ℝ) (f : Spin n→ℝ) : + heatBathLinear g h f=0 ↔ ∀ x y,f x=f y := by + constructor + · intro hf + apply (dirichlet_eq_zero_iff g h f).mp + rw [← heatBathGenerator_form] + change expectation g h (fun x=>f x*(heatBathLinear g h f) x)=0 + rw [hf] + simp only [Pi.zero_apply,mul_zero,expectation_const] + · intro hf + have he : f=(fun _=>f (fun _=>false)) := funext (fun x=>hf x (fun _=>false)) + rw [he,heatBathLinear_const] + +lemma heatBath_curvature_poincare (g : Disorder n) (h : Fin n→ℝ) + {ρ : ℝ} (hρ : 0 < ρ) + (hc : ∀ f : Spin n→ℝ,ρ*dirichlet g h f ≤ + expectation g h (fun x=>heatBathGenerator g h f x^2)) (f : Spin n→ℝ) : + ρ*variance g h f ≤ dirichlet g h f := by + let S := gibbsScale g h + let H : EuclideanSpace ℝ (Spin n) →ₗ[ℝ] EuclideanSpace ℝ (Spin n) := + S.toLinearMap ∘ₗ heatBathLinear g h ∘ₗ S.symm.toLinearMap + have hHS (k : Spin n→ℝ) : H (S k)=S (heatBathLinear g h k) := by simp [H] + have hH : H.IsSymmetric := by + intro u v + obtain ⟨u,rfl⟩ := S.surjective u + obtain ⟨v,rfl⟩ := S.surjective v + rw [hHS,hHS] + exact (gibbsScale_inner g h _ _).trans ((heatBathGenerator_adjoint g h u v).trans + (gibbsScale_inner g h _ _).symm) + have hform (k : Spin n→ℝ) : ⟪S k,H (S k)⟫=dirichlet g h k := by + rw [hHS,gibbsScale_inner] + exact heatBathGenerator_form g h k + have hpos : ∀ v,0 ≤ ⟪v,H v⟫ := by + intro v + obtain ⟨k,rfl⟩ := S.surjective v + rw [hform] + exact dirichlet_nonneg g h k + have hcurv : ∀ v,ρ*⟪v,H v⟫ ≤ ⟪H v,H v⟫ := by + intro v + obtain ⟨k,rfl⟩ := S.surjective v + rw [hform,hHS,gibbsScale_inner] + simpa only [sq,heatBathLinear,LinearMap.coe_mk,AddHom.coe_mk] using hc k + let f₀ := f-(fun _=>expectation g h f) + have hm : expectation g h f₀=0 := by + change expectation g h (fun x=>f x-expectation g h f)=0 + rw [expectation_sub,expectation_const,sub_self] + have hker : S f₀ ∈ (LinearMap.ker H)ᗮ := by + rw [Submodule.mem_orthogonal] + intro v hv + obtain ⟨k,rfl⟩ := S.surjective v + have hk : heatBathLinear g h k=0 := by + have hh := LinearMap.mem_ker.mp hv + rw [hHS] at hh + exact S.injective (by simpa using hh) + have hk' := (heatBathLinear_kernel g h k).mp hk + have he : k=(fun _=>k (fun _=>false)) := funext (fun x=>hk' x (fun _=>false)) + rw [gibbsScale_inner,he,expectation_const_mul,hm,mul_zero] + have hh := curvature_poincare_on_kernel_orthogonal H hH hpos hρ hcurv (S f₀) hker + rw [gibbsScale_inner,hform] at hh + have hd : dirichlet g h f₀=dirichlet g h f := by + rw [← heatBathGenerator_form,← heatBathGenerator_form] + have he : heatBathLinear g h f₀=heatBathLinear g h f := by + simp only [f₀,map_sub,heatBathLinear_const,sub_zero] + change expectation g h (fun x=>f₀ x*(heatBathLinear g h f₀) x)=_ + rw [he] + have hz : expectation g h (heatBathLinear g h f)=0 := by + change expectation g h (fun x=>∑ i,(f x-conditionalExpectation g h i f x))=0 + rw [expectation_sum] + apply Finset.sum_eq_zero + intro i _ + rw [expectation_sub,expectation_conditionalExpectation,sub_self] + simp only [f₀,Pi.sub_apply,sub_mul] + rw [expectation_sub,expectation_const_mul,hz,mul_zero,sub_zero] + rfl + rw [hd] at hh + simpa only [variance,f₀,Pi.sub_apply,sq] using hh + +end SKRatio.Fields + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Calculus/Interaction.lean b/lean/OAI/Probability/SKRatio/Calculus/Interaction.lean new file mode 100644 index 0000000000000000000000000000000000000000..31c106673dfc6bd2a863d9a3f179adf242b1ca1c --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Calculus/Interaction.lean @@ -0,0 +1,412 @@ +import Mathlib +import OAI.Probability.SKRatio.FiniteChain.Spin + +namespace OAI + +section +noncomputable section +open scoped BigOperators Topology Matrix +open ContinuousLinearMap +namespace SKRatio.Calculus +abbrev Interaction (n : ℕ) := Fin n → Fin n → ℝ + +def spin {n : ℕ} (x : Spin n) (i : Fin n) : ℝ := if x i then 1 else -1 + +def replace {n : ℕ} (x : Spin n) (i : Fin n) (b : Bool) : Spin n := + Function.update x i b + +noncomputable def halfDiff {n : ℕ} (i : Fin n) (f : Spin n → ℝ) + (x : Spin n) : ℝ := (f (replace x i true) - f (replace x i false)) / 2 + +noncomputable def field {n : ℕ} (J : Interaction n) (x : Spin n) (i : Fin n) : ℝ := + ∑ j, J i j * spin x j + +noncomputable def mean {n : ℕ} (J : Interaction n) (x : Spin n) (i : Fin n) : ℝ := + Real.tanh (field J x i) + +noncomputable def generator {n : ℕ} (J : Interaction n) (f : Spin n → ℝ) + (x : Spin n) : ℝ := ∑ j, (mean J x j - spin x j) * halfDiff j f x + +noncomputable def gradientGenerator {n : ℕ} (J : Interaction n) + (p : Spin n → Fin n → ℝ) (x : Spin n) (i : Fin n) : ℝ := + generator J (fun y => p y i) x - p x i - + 2 * spin x i * ∑ j, halfDiff i (fun y => mean J y j) x * + halfDiff j (fun y => p y i) x + + ∑ j, halfDiff i (fun y => mean J y j) x * p x j + +@[simp] theorem replace_same {n : ℕ} (x : Spin n) (i : Fin n) (b : Bool) : + replace x i b i = b := by + simp [replace] + +@[simp] theorem replace_replace {n : ℕ} (x : Spin n) (i : Fin n) (a b : Bool) : + replace (replace x i a) i b = replace x i b := by + simp [replace, Function.update_idem] + +@[simp] theorem replace_self {n : ℕ} (x : Spin n) (i : Fin n) : + replace x i (x i) = x := by + simp [replace] + +theorem replace_comm {n : ℕ} (x : Spin n) {i j : Fin n} (h : i ≠ j) + (a b : Bool) : replace (replace x i a) j b = replace (replace x j b) i a := by + exact Function.update_comm h a b x + +@[simp] theorem halfDiff_replace {n : ℕ} (i : Fin n) (f : Spin n → ℝ) + (x : Spin n) (b : Bool) : halfDiff i f (replace x i b) = halfDiff i f x := by + simp [halfDiff] + +@[simp] theorem halfDiff_self {n : ℕ} (i : Fin n) (f : Spin n → ℝ) + (x : Spin n) : halfDiff i (halfDiff i f) x = 0 := by + simp [halfDiff] + +theorem halfDiff_mul {n : ℕ} (i : Fin n) (f g : Spin n → ℝ) (x : Spin n) : + halfDiff i (fun y => f y * g y) x = + f x * halfDiff i g x + g x * halfDiff i f x - + 2 * spin x i * halfDiff i f x * halfDiff i g x := by + have hx : replace x i (x i) = x := replace_self x i + cases h : x i <;> simp only [h] at hx + · simp only [halfDiff, spin, h, Bool.false_eq_true, ↓reduceIte] + rw [hx] + ring + · simp only [halfDiff, spin, h, ↓reduceIte] + rw [hx] + ring + +theorem halfDiff_comm {n : ℕ} (i j : Fin n) (f : Spin n → ℝ) (x : Spin n) : + halfDiff i (halfDiff j f) x = halfDiff j (halfDiff i f) x := by + by_cases h : i = j + · subst j + rfl + · simp only [halfDiff] + rw [replace_comm x h true true, replace_comm x h true false, + replace_comm x h false true, replace_comm x h false false] + ring + +@[simp] theorem halfDiff_const {n : ℕ} (i : Fin n) (c : ℝ) (x : Spin n) : + halfDiff i (fun _ => c) x = 0 := by + simp [halfDiff] + +theorem halfDiff_sub {n : ℕ} (i : Fin n) (f g : Spin n → ℝ) (x : Spin n) : + halfDiff i (fun y => f y - g y) x = halfDiff i f x - halfDiff i g x := by + simp only [halfDiff] + ring + +theorem halfDiff_sum {n : ℕ} {α : Type*} [Fintype α] (i : Fin n) + (f : α → Spin n → ℝ) (x : Spin n) : + halfDiff i (fun y => ∑ a, f a y) x = ∑ a, halfDiff i (f a) x := by + simp only [halfDiff, sub_div, Finset.sum_sub_distrib, Finset.sum_div] + +@[simp] theorem halfDiff_spin {n : ℕ} (i j : Fin n) (x : Spin n) : + halfDiff i (fun y => spin y j) x = if i = j then 1 else 0 := by + by_cases h : i = j + · subst j + norm_num [halfDiff, spin] + · simp [halfDiff, spin, replace, Function.update_of_ne (Ne.symm h), h] + +theorem halfDiff_generator {n : ℕ} (J : Interaction n) (f : Spin n → ℝ) + (x : Spin n) (i : Fin n) : + halfDiff i (generator J f) x = + gradientGenerator J (fun y j => halfDiff j f y) x i := by + change halfDiff i (fun y => generator J f y) x = _ + unfold gradientGenerator + simp only [generator, halfDiff_sum, halfDiff_mul, halfDiff_sub, halfDiff_spin] + simp_rw [halfDiff_comm i] + simp only [mul_sub, sub_mul, Finset.sum_add_distrib, Finset.sum_sub_distrib] + simp only [mul_ite, mul_one, mul_zero, ite_mul, zero_mul, + Fintype.sum_ite_eq, halfDiff_self, sub_zero] + rw [Finset.mul_sum] + simp only [mul_assoc] + simp_rw [mul_comm (halfDiff _ f x)] + ring + +abbrev Observables (n : ℕ) := Spin n → ℝ +abbrev VectorFields (n : ℕ) := Spin n → Fin n → ℝ + +noncomputable def gradientLM (n : ℕ) : Observables n →ₗ[ℝ] VectorFields n where + toFun f x i := halfDiff i f x + map_add' f g := by + funext x i + simp only [halfDiff, Pi.add_apply] + ring + map_smul' a f := by + funext x i + simp only [halfDiff, Pi.smul_apply, smul_eq_mul, RingHom.id_apply] + ring + +noncomputable def generatorLM {n : ℕ} (J : Interaction n) : + Observables n →ₗ[ℝ] Observables n where + toFun := generator J + map_add' f g := by + funext x + simp only [generator] + change (∑ j, (mean J x j - spin x j) * + (gradientLM n (f + g) x j)) = _ + simp [map_add, gradientLM, generator, mul_add, Finset.sum_add_distrib] + map_smul' a f := by + funext x + simp only [generator] + change (∑ j, (mean J x j - spin x j) * + (gradientLM n (a • f) x j)) = _ + simp [map_smul, gradientLM, generator, mul_left_comm, Finset.mul_sum] + +noncomputable def generatorCLM {n : ℕ} (J : Interaction n) : + Observables n →L[ℝ] Observables n := (generatorLM J).toContinuousLinearMap + +noncomputable def semigroup {n : ℕ} (J : Interaction n) (t : ℝ) : + Observables n →L[ℝ] Observables n := NormedSpace.exp (t • generatorCLM J) + +@[simp] lemma spin_sq {n : ℕ} (x : Spin n) (i : Fin n) : spin x i ^ 2 = 1 := by + cases h : x i <;> simp [spin, h] + +lemma generator_mul {n : ℕ} (J : Interaction n) (f g : Observables n) (x : Spin n) : + generator J (fun y => f y * g y) x = + f x * generator J g x + g x * generator J f x + + 2 * ∑ i, (1 - mean J x i * spin x i) * halfDiff i f x * halfDiff i g x := by + simp only [generator, halfDiff_mul, Finset.mul_sum, ← Finset.sum_add_distrib] + apply Finset.sum_congr rfl + intro i _ + have hx := spin_sq x i + linear_combination 2 * halfDiff i f x * halfDiff i g x * hx + +lemma semigroup_hasDerivAt {n : ℕ} (J : Interaction n) (t : ℝ) : + HasDerivAt (fun s : ℝ => semigroup J s) + (semigroup J t * generatorCLM J) t := + hasDerivAt_exp_smul_const (generatorCLM J) t + +lemma semigroup_hasDerivAt' {n : ℕ} (J : Interaction n) (t : ℝ) : + HasDerivAt (fun s : ℝ => semigroup J s) + (generatorCLM J * semigroup J t) t := + hasDerivAt_exp_smul_const' (generatorCLM J) t + +lemma semigroup_apply_hasDerivAt {n : ℕ} (J : Interaction n) (f : Observables n) (t : ℝ) : + HasDerivAt (fun s : ℝ => semigroup J s f) (semigroup J t (generator J f)) t := by + simpa only [mul_apply_eq_comp, map_zero, add_zero, generatorCLM, generatorLM, + LinearMap.coe_toContinuousLinearMap', LinearMap.coe_mk, AddHom.coe_mk] using + (semigroup_hasDerivAt J t).clm_apply (hasDerivAt_const t f) + +lemma semigroup_apply_hasDerivAt' {n : ℕ} (J : Interaction n) (f : Observables n) (t : ℝ) : + HasDerivAt (fun s : ℝ => semigroup J s f) (generator J (semigroup J t f)) t := by + simpa only [mul_apply_eq_comp, map_zero, add_zero, generatorCLM, generatorLM, + LinearMap.coe_toContinuousLinearMap', LinearMap.coe_mk, AddHom.coe_mk] using + (semigroup_hasDerivAt' J t).clm_apply (hasDerivAt_const t f) + +lemma semigroup_continuous {n : ℕ} (J : Interaction n) : + Continuous (fun s : ℝ => semigroup J s) := by + have hd : Differentiable ℝ (fun s : ℝ => semigroup J s) := + fun t => (semigroup_hasDerivAt J t).differentiableAt + exact hd.continuous + +@[simp] lemma semigroup_zero {n : ℕ} (J : Interaction n) : semigroup J 0 = 1 := by + simp [semigroup] + +noncomputable def jumpEnergy {n : ℕ} (J : Interaction n) (f : Observables n) (x : Spin n) : ℝ := + 2 * ∑ i, (1 - mean J x i * spin x i) * (halfDiff i f x) ^ 2 + +lemma generator_square {n : ℕ} (J : Interaction n) (f : Observables n) : + generator J (fun x => f x ^ 2) = + fun x => 2 * f x * generator J f x + jumpEnergy J f x := by + funext x + simpa only [pow_two, mul_assoc, ← two_mul, jumpEnergy] using generator_mul J f f x + +lemma spin_flip_self {n : ℕ} (x : Spin n) (i : Fin n) : + spin (flip i x) i = -spin x i := by + cases h : x i <;> simp [SKRatio.flip, spin, h] + +lemma spin_flip {n : ℕ} (x : Spin n) (i j : Fin n) : + spin (flip i x) j = spin x j - if j = i then 2 * spin x i else 0 := by + by_cases h : j = i + · subst j; rw [spin_flip_self]; simp; ring + · simp [flip, spin, h] + +lemma field_flip {n : ℕ} (J : Interaction n) (hdiag : ∀ i, J i i = 0) + (x : Spin n) (i : Fin n) : field J (flip i x) i = field J x i := by + simp only [field, spin_flip, mul_sub, Finset.sum_sub_distrib] + simp [mul_ite, hdiag] + +lemma hamiltonian_flip {n : ℕ} (g : Disorder n) (x : Spin n) (i : Fin n) : + hamiltonian g 0 (flip i x) = hamiltonian g 0 x - + 2 * spin x i * field (coupling g) x i := by + have hr : ∑ j, spin x j * coupling g j i = field (coupling g) x i := by + simp only [field, coupling_symm, mul_comm] + have he (y : Spin n) : hamiltonian g 0 y = + (∑ j, ∑ k, spin y j * coupling g j k * spin y k) / 2 := by + simp only [hamiltonian, Pi.zero_apply, zero_mul, Finset.sum_const_zero, add_zero] + simp only [spinValue, spin] + ring + rw [he, he] + simp only [spin_flip, sub_mul, mul_sub, Finset.sum_sub_distrib] + simp only [mul_ite, ite_mul, mul_zero, zero_mul, Finset.sum_ite_irrel, + Finset.sum_const_zero, Finset.sum_ite_eq', Finset.mem_univ, + ↓reduceIte, coupling_diag] + simp only [← Finset.sum_mul, hr] + simp only [mul_assoc, ← Finset.mul_sum, field] + ring + +lemma mass_flip {n : ℕ} (g : Disorder n) (x : Spin n) (i : Fin n) : + mass g 0 (flip i x) = mass g 0 x * Real.exp (-2 * spin x i * field (coupling g) x i) := by + unfold mass weight + rw [hamiltonian_flip, Real.exp_sub, neg_mul, neg_mul, Real.exp_neg] + ring + +lemma exp_two_mul_one_sub_tanh (a : ℝ) : + Real.exp (2 * a) * (1 - Real.tanh a) = 1 + Real.tanh a := by + rw [Real.tanh_eq, show 2 * a = a + a by ring, Real.exp_add, Real.exp_neg] + have he := Real.exp_pos a + field_simp + nlinarith + +lemma exp_neg_two_mul_one_add_tanh (a : ℝ) : + Real.exp (-2 * a) * (1 + Real.tanh a) = 1 - Real.tanh a := by + simpa only [mul_neg, neg_mul, Real.tanh_neg, sub_neg_eq_add, sub_eq_add_neg, neg_neg] using + exp_two_mul_one_sub_tanh (-a) + +def flipRate {n : ℕ} (J : Interaction n) (x : Spin n) (i : Fin n) : ℝ := + (1 - spin x i * mean J x i) / 2 + +lemma mass_flip_ratio {n : ℕ} (g : Disorder n) (x : Spin n) (i : Fin n) : + mass g 0 (flip i x) / (mass g 0 x + mass g 0 (flip i x)) = + flipRate (coupling g) x i := by + have hx := mass_pos g 0 x + rw [mass_flip] + have he := Real.exp_pos (-2 * spin x i * field (coupling g) x i) + have hden : mass g 0 x + mass g 0 x * Real.exp (-2 * spin x i * field (coupling g) x i) ≠ 0 := by + positivity + apply (div_eq_iff hden).mpr + cases hi : x i + · have h := exp_two_mul_one_sub_tanh (field (coupling g) x i) + simp only [flipRate, mean, spin, hi, Bool.false_eq_true, ↓reduceIte, mul_neg, + mul_one, sub_neg_eq_add, neg_mul, neg_neg] + linear_combination (mass g 0 x / 2) * h + · have h := exp_neg_two_mul_one_add_tanh (field (coupling g) x i) + simp only [flipRate, mean, spin, hi, ↓reduceIte, mul_one, one_mul] + linear_combination (mass g 0 x / 2) * h + +lemma siteKernel_apply {n : ℕ} (g : Disorder n) (i : Fin n) (f : Observables n) (x : Spin n) : + ∑ y, siteKernel g i x y * f y = + f x + flipRate (coupling g) x i * (f (flip i x) - f x) := by + have hd : mass g 0 x + mass g 0 (flip i x) ≠ 0 := + (add_pos (mass_pos g 0 x) (mass_pos g 0 (flip i x))).ne' + have hs : mass g 0 x / (mass g 0 x + mass g 0 (flip i x)) + + mass g 0 (flip i x) / (mass g 0 x + mass g 0 (flip i x)) = 1 := by + rw [← add_div, div_self hd] + simp only [siteKernel, add_mul, Finset.sum_add_distrib, ite_mul, zero_mul, + Finset.sum_ite_eq', Finset.mem_univ, ite_true] + rw [← mass_flip_ratio] + linear_combination f x * hs + +lemma generator_flip {n : ℕ} (J : Interaction n) (f : Observables n) (x : Spin n) : + generator J f x = ∑ i, flipRate J x i * (f (flip i x) - f x) := by + apply Finset.sum_congr rfl + intro i _ + have hx := replace_self x i + cases hi : x i <;> simp only [hi] at hx + · simp only [spin, hi, Bool.false_eq_true, ↓reduceIte, flipRate, flip, Bool.not_false, + halfDiff] + rw [hx] + simp only [replace] + ring + · simp only [spin, hi, ↓reduceIte, flipRate, flip, Bool.not_true, halfDiff] + rw [hx] + simp only [replace] + ring + +theorem generator_eq_transition {n : ℕ} (g : Disorder n) (f : Observables n) (x : Spin n) : + generator (coupling g) f x = (n : ℝ) * ((∑ y, transition g x y * f y) - f x) := by + by_cases hn : n = 0 + · subst n; simp [generator] + have hn' : (n : ℝ) ≠ 0 := Nat.cast_ne_zero.mpr hn + have hP : transition g = fun x y => (∑ i, siteKernel g i x y) / (n : ℝ) := by + simp only [transition, hn, ↓reduceIte] + rfl + rw [hP] + simp only [div_mul_eq_mul_div, ← Finset.sum_div] + rw [mul_sub, mul_div_cancel₀ _ hn'] + simp_rw [Finset.sum_mul] + rw [Finset.sum_comm] + simp_rw [siteKernel_apply] + rw [Finset.sum_add_distrib] + simp only [Finset.sum_const, Finset.card_univ, Fintype.card_fin, nsmul_eq_mul] + rw [generator_flip] + ring + +def unweightedGradient {n : ℕ} (f : Observables n) (x : Spin n) : ℝ := + ∑ i, (halfDiff i f x) ^ 2 + +def gradientWeight {n : ℕ} (J : Interaction n) (x : Spin n) (i : Fin n) : ℝ := + 1 - spin x i * mean J x i + +def weightedGradient {n : ℕ} (J : Interaction n) (f : Observables n) (x : Spin n) : ℝ := + ∑ i, gradientWeight J x i * (halfDiff i f x)^2 + +lemma variance_density {n : ℕ} (J : Interaction n) (f : Observables n) (x : Spin n) : + generator J (fun y => f y ^ 2) x - 2 * f x * generator J f x = + 2 * weightedGradient J f x := by + rw [generator_square] + simp only [jumpEnergy, weightedGradient, gradientWeight, mul_comm (mean J x _)] + ring + +lemma halfDiff_flow_hasDerivAt {n : ℕ} (J : Interaction n) (f : Observables n) + (i : Fin n) (x : Spin n) (t : ℝ) : + HasDerivAt (fun s : ℝ => halfDiff i (semigroup J s f) x) + (halfDiff i (generator J (semigroup J t f)) x) t := by + have h := semigroup_apply_hasDerivAt' J f t + exact ((hasDerivAt_pi.mp h (replace x i true)).sub + (hasDerivAt_pi.mp h (replace x i false))).div_const 2 + +lemma unweightedGradient_hasDerivAt {n : ℕ} (J : Interaction n) (f : Observables n) + (x : Spin n) (t : ℝ) : + HasDerivAt (fun s : ℝ => unweightedGradient (semigroup J s f) x) + (∑ i, 2 * halfDiff i (semigroup J t f) x * + halfDiff i (generator J (semigroup J t f)) x) t := by + have hs := HasDerivAt.fun_sum (u := Finset.univ) + (fun i _ => (halfDiff_flow_hasDerivAt J f i x t).pow 2) + simpa only [unweightedGradient, Nat.cast_ofNat, Nat.reduceSub, pow_one, Pi.pow_apply] using hs + +lemma generator_unweightedGradient {n : ℕ} (J : Interaction n) (f : Observables n) + (x : Spin n) : + generator J (unweightedGradient f) x = + ∑ i, generator J (fun y => halfDiff i f y ^ 2) x := by + have hu : unweightedGradient f = ∑ i, (fun y => halfDiff i f y ^ 2) := by + funext y; simp only [unweightedGradient, Finset.sum_apply] + rw [hu] + change generatorLM J (∑ i, (fun y => halfDiff i f y ^ 2)) x = _ + simp only [map_sum, Finset.sum_apply] + rfl + +lemma unweightedGradient_commutator {n : ℕ} (J : Interaction n) (f : Observables n) + (x : Spin n) : + (1 / 2 : ℝ) * ((∑ i, 2 * halfDiff i f x * halfDiff i (generator J f) x) - + generator J (unweightedGradient f) x) = + -unweightedGradient f x + + (∑ i, ∑ j, halfDiff i f x * halfDiff i (fun y => mean J y j) x * + (halfDiff j f x - 2 * spin x i * halfDiff i (halfDiff j f) x)) - + (∑ i, ∑ j, gradientWeight J x j * (halfDiff i (halfDiff j f) x)^2) := by + rw [generator_unweightedGradient, ← Finset.sum_sub_distrib, Finset.mul_sum] + have hloc (i : Fin n) : + (1 / 2 : ℝ) * (2 * halfDiff i f x * halfDiff i (generator J f) x - + generator J (fun y => halfDiff i f y ^ 2) x) = + -(halfDiff i f x)^2 + + (∑ j, halfDiff i f x * halfDiff i (fun y => mean J y j) x * + (halfDiff j f x - 2 * spin x i * halfDiff i (halfDiff j f) x)) - + ∑ j, gradientWeight J x j * (halfDiff i (halfDiff j f) x)^2 := by + have hsum : (∑ j, halfDiff i f x * halfDiff i (fun y => mean J y j) x * + (halfDiff j f x - 2 * spin x i * halfDiff i (halfDiff j f) x)) = + halfDiff i f x * (∑ j, halfDiff i (fun y => mean J y j) x * halfDiff j f x) - + 2 * halfDiff i f x * spin x i * + (∑ j, halfDiff i (fun y => mean J y j) x * halfDiff i (halfDiff j f) x) := by + simp only [Finset.mul_sum, ← Finset.sum_sub_distrib] + apply Finset.sum_congr rfl + intro j _ + ring + rw [hsum, halfDiff_generator, generator_square] + simp only [gradientGenerator, jumpEnergy, gradientWeight] + simp_rw [halfDiff_comm _ i, mul_comm (mean J x _)] + ring + simp_rw [hloc] + simp only [Finset.sum_sub_distrib, Finset.sum_add_distrib, Finset.sum_neg_distrib, + unweightedGradient] + +end SKRatio.Calculus +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Calculus/PairUpdate.lean b/lean/OAI/Probability/SKRatio/Calculus/PairUpdate.lean new file mode 100644 index 0000000000000000000000000000000000000000..a4750005822c507ef89caebbeb5cc2b3a1d35332 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Calculus/PairUpdate.lean @@ -0,0 +1,435 @@ +import Mathlib +import OAI.Probability.SKRatio.Calculus.Expectation + +namespace OAI + +section +noncomputable section +open scoped BigOperators RealInnerProductSpace +namespace SKRatio.Fields +open Real Matrix TwoSpin +attribute [local instance] Classical.propDecidable +variable {n : ℕ} + +lemma tanh_pair_mean (α J : ℝ) (y : Bool) : + tanh (α+J*spinValue y)=TwoSpin.pairConditionalMean (tanh α) (tanh J) y := by + have hh : tanh (J*spinValue y)=tanh J*spinValue y := by + cases y <;> simp only [spinValue_false,spinValue_true,mul_one,mul_neg_one,tanh_neg] + rw [tanh_add_real,hh] + simp only [TwoSpin.pairConditionalMean,mul_comm,mul_assoc] + +lemma pairBoltzmann_cubic_bound (α γ J : ℝ) (F : Bool → Bool → ℝ) + (hJ : |tanh J| ≤ 1/1000) : + let g₁ := fun y => (F true y-F false y)/2; + let g₂ := fun x => (F x true-F x false)/2; + let m₁ := fun y => tanh (α+J*spinValue y); + let m₂ := fun x => tanh (γ+J*spinValue x); + let v₁ := fun y => 1-m₁ y^2; + let v₂ := fun x => 1-m₂ x^2; + -pairBoltzmannMean α γ J (fun x y => + (tanh J+2*(tanh J)^2*m₁ y*m₂ x)*v₁ y*v₂ x*g₁ y*g₂ x) - + 1920000*|tanh J|^3*pairBoltzmannMean α γ J (fun x y => + v₁ y*(g₁ y)^2+v₂ x*(g₂ x)^2) ≤ + pairBoltzmannMean α γ J (fun x y => + (spinValue x-m₁ y)*g₁ y*((spinValue y-m₂ x)*g₂ x)) := by + dsimp only + obtain ⟨p,s,r,hg₁,hg₂⟩ := pair_gradients_representation F (tanh α) (tanh γ) + simp_rw [pairBoltzmannMean_eq,tanh_pair_residual,tanh_pair_variance, + tanh_pair_mean,hg₁,hg₂] + exact pair_cubic_signed_bound (abs_tanh_lt_one α).le (abs_tanh_lt_one γ).le hJ + +lemma update_true_false (i : Fin n) (x : Spin n) : + (Function.update x i true=x ∧ Function.update x i false=flip i x) ∨ + (Function.update x i true=flip i x ∧ Function.update x i false=x) := by + cases hx : x i + · right + constructor + · simp [flip,hx] + · simpa only [hx] using Function.update_eq_self i x + · left + constructor + · simpa only [hx] using Function.update_eq_self i x + · simp [flip,hx] + +lemma conditionalExpectation_updates (g : Disorder n) (h : Fin n→ℝ) (i : Fin n) + (f : Spin n→ℝ) (x : Spin n) : + conditionalExpectation g h i f x= + (∑ b : Bool,weight g h (Function.update x i b)*f (Function.update x i b))/ + (∑ b : Bool,weight g h (Function.update x i b)) := by + simp only [Fintype.sum_bool] + rcases update_true_false i x with ⟨ht,hf⟩|⟨ht,hf⟩ <;> rw [ht,hf] + · rfl + · unfold conditionalExpectation + rw [add_comm (weight g h (flip i x)*f (flip i x)),add_comm (weight g h (flip i x))] + +lemma weight_update_factor (g : Disorder n) (h : Fin n→ℝ) (i : Fin n) (x : Spin n) (b : Bool) : + weight g h (Function.update x i b)=exp (hamiltonian g h x-spinValue (x i)*localField g h i x)* + exp (localField g h i x*spinValue b) := by + unfold weight + rw [hamiltonian_update,← exp_add] + congr 1;ring + +lemma conditionalExpectation_local (g : Disorder n) (h : Fin n→ℝ) (i : Fin n) + (f : Spin n→ℝ) (x : Spin n) : + conditionalExpectation g h i f x= + (f (Function.update x i true)+f (Function.update x i false))/2+ + tanh (localField g h i x)*spinGradient i f x := by + rw [conditionalExpectation_updates] + simp_rw [weight_update_factor,exp_spin] + simp only [Fintype.sum_bool,spinValue_true,spinValue_false,mul_one,mul_neg_one] + unfold spinGradient + have h₁ := (exp_pos (hamiltonian g h x-spinValue (x i)*localField g h i x)).ne' + have h₂ := (cosh_pos (localField g h i x)).ne' + have he : exp (hamiltonian g h x-spinValue (x i)*localField g h i x)* + (cosh (localField g h i x)*(1+tanh (localField g h i x)))+ + exp (hamiltonian g h x-spinValue (x i)*localField g h i x)* + (cosh (localField g h i x)*(1+-tanh (localField g h i x)))= + 2*exp (hamiltonian g h x-spinValue (x i)*localField g h i x)*cosh (localField g h i x) := by ring + rw [he] + field_simp [h₁,h₂] + ring + +lemma spin_affine (i : Fin n) (f : Spin n→ℝ) (x : Spin n) : + f x=(f (Function.update x i true)+f (Function.update x i false))/2+ + spinValue (x i)*spinGradient i f x := by + unfold spinGradient + cases hx : x i + · have hf : Function.update x i false=x := by simpa only [hx] using Function.update_eq_self i x + rw [spinValue_false,hf];ring + · have ht : Function.update x i true=x := by simpa only [hx] using Function.update_eq_self i x + rw [spinValue_true,ht];ring + +lemma conditionalDifference_local (g : Disorder n) (h : Fin n→ℝ) (i : Fin n) + (f : Spin n→ℝ) (x : Spin n) : + f x-conditionalExpectation g h i f x= + (spinValue (x i)-tanh (localField g h i x))*spinGradient i f x := by + rw [conditionalExpectation_local] + have he := spin_affine i f x + linarith only [he] + +lemma spinGradient_update (i : Fin n) (f : Spin n→ℝ) (x : Spin n) (b : Bool) : + spinGradient i f (Function.update x i b)=spinGradient i f x := by + simp only [spinGradient,Function.update_idem] + +lemma conditionalSiteEnergy_local (g : Disorder n) (h : Fin n→ℝ) (i : Fin n) + (f : Spin n→ℝ) : + expectation g h (fun x=>(f x-conditionalExpectation g h i f x)^2)= + expectation g h (fun x=>(1-tanh (localField g h i x)^2)*spinGradient i f x^2) := by + rw [← expectation_conditionalExpectation g h i] + congr 1 + funext x + rw [conditionalExpectation_local] + simp_rw [conditionalDifference_local,localField_update_self,spinGradient_update] + simp only [Function.update_self,spinValue_true,spinValue_false,spinGradient] + simp_rw [Function.update_idem,localField_update_self] + ring + +def pairUpdate (i j : Fin n) (x : Spin n) (a b : Bool) : Spin n := + Function.update (Function.update x i a) j b + +lemma pairUpdate_overwrite (i j : Fin n) (hij : i ≠ j) (x : Spin n) (a b c d : Bool) : + pairUpdate i j (pairUpdate i j x a b) c d=pairUpdate i j x c d := by + funext k + by_cases hj : k=j + · subst k;simp [pairUpdate] + · by_cases hi : k=i + · subst k;simp [pairUpdate,hij] + · simp [pairUpdate,hj,hi] + +lemma pairUpdate_left (i j : Fin n) (hij : i ≠ j) (x : Spin n) (a b : Bool) : + pairUpdate i j x a b i=a := by simp [pairUpdate,hij] +lemma pairUpdate_right (i j : Fin n) (x : Spin n) (a b : Bool) : + pairUpdate i j x a b j=b := by simp [pairUpdate] + +lemma sum_spin_update (i : Fin n) (F : Spin n→ℝ) : + (∑ x,∑ b : Bool,F (Function.update x i b))=2*∑ x,F x := by + have he (x : Spin n) : (∑ b : Bool,F (Function.update x i b))=F x+F (flip i x) := by + simp only [Fintype.sum_bool] + rcases update_true_false i x with ⟨ht,hf⟩|⟨ht,hf⟩ <;> rw [ht,hf]; ring + simp_rw [he] + rw [Finset.sum_add_distrib,sum_flip] + ring + +lemma sum_pairUpdate (i j : Fin n) (F : Spin n→ℝ) : + (∑ x,∑ a : Bool,∑ b : Bool,F (pairUpdate i j x a b))=4*∑ x,F x := by + unfold pairUpdate + rw [sum_spin_update i (fun x=>∑ b : Bool,F (Function.update x j b)),sum_spin_update] + ring + +def pairConditionalMean (g : Disorder n) (h : Fin n→ℝ) (i j : Fin n) + (F : Spin n→ℝ) (x : Spin n) : ℝ := + (∑ a : Bool,∑ b : Bool,weight g h (pairUpdate i j x a b)*F (pairUpdate i j x a b))/ + (∑ a : Bool,∑ b : Bool,weight g h (pairUpdate i j x a b)) + +lemma pairConditionalMean_update (g : Disorder n) (h : Fin n→ℝ) (i j : Fin n) (hij : i ≠ j) + (F : Spin n→ℝ) (x : Spin n) (a b : Bool) : + pairConditionalMean g h i j F (pairUpdate i j x a b)=pairConditionalMean g h i j F x := by + simp only [pairConditionalMean,pairUpdate_overwrite i j hij] + +lemma pairConditional_partition_pos (g : Disorder n) (h : Fin n→ℝ) (i j : Fin n) (x : Spin n) : + 0 < ∑ a : Bool,∑ b : Bool,weight g h (pairUpdate i j x a b) := by + simp only [Fintype.sum_bool] + exact add_pos (add_pos (weight_pos _ _ _) (weight_pos _ _ _)) + (add_pos (weight_pos _ _ _) (weight_pos _ _ _)) + +lemma expectation_pairConditionalMean (g : Disorder n) (h : Fin n→ℝ) (i j : Fin n) (hij : i ≠ j) + (F : Spin n→ℝ) : expectation g h (pairConditionalMean g h i j F)=expectation g h F := by + have h₁ := sum_pairUpdate i j (fun x=>mass g h x*pairConditionalMean g h i j F x) + have h₂ := sum_pairUpdate i j (fun x=>mass g h x*F x) + have he : (∑ x,∑ a : Bool,∑ b : Bool,mass g h (pairUpdate i j x a b)* + pairConditionalMean g h i j F (pairUpdate i j x a b))= + ∑ x,∑ a : Bool,∑ b : Bool,mass g h (pairUpdate i j x a b)*F (pairUpdate i j x a b) := by + apply Finset.sum_congr rfl + intro x _ + simp_rw [pairConditionalMean_update g h i j hij,mass,div_mul_eq_mul_div] + simp only [← Finset.sum_div,← Finset.sum_mul] + unfold pairConditionalMean + rw [mul_div_cancel₀ _ (pairConditional_partition_pos g h i j x).ne'] + unfold expectation + linarith only [h₁,h₂,he] + +lemma pairUpdate_hamiltonian (g : Disorder n) (h : Fin n→ℝ) (i j : Fin n) (hij : i ≠ j) + (x : Spin n) (a b : Bool) : + let α := localField g h i x-coupling g i j*spinValue (x j); + let γ := localField g h j x-coupling g i j*spinValue (x i); + hamiltonian g h (pairUpdate i j x a b)= + (hamiltonian g h x-α*spinValue (x i)-γ*spinValue (x j)- + coupling g i j*spinValue (x i)*spinValue (x j))+ + (α*spinValue a+γ*spinValue b+coupling g i j*spinValue a*spinValue b) := by + dsimp only + unfold pairUpdate + rw [hamiltonian_update,hamiltonian_update,localField_update, + Function.update_of_ne (Ne.symm hij),coupling_symm g j i] + ring + +lemma pairUpdate_localField₁ (g : Disorder n) (h : Fin n→ℝ) (i j : Fin n) + (x : Spin n) (a b : Bool) : + localField g h i (pairUpdate i j x a b)= + (localField g h i x-coupling g i j*spinValue (x j))+coupling g i j*spinValue b := by + unfold pairUpdate + rw [localField_update,localField_update_self] + by_cases hij : i=j + · subst j;simp + · rw [Function.update_of_ne (Ne.symm hij)] + ring + +lemma pairUpdate_localField₂ (g : Disorder n) (h : Fin n→ℝ) (i j : Fin n) + (x : Spin n) (a b : Bool) : + localField g h j (pairUpdate i j x a b)= + (localField g h j x-coupling g i j*spinValue (x i))+coupling g i j*spinValue a := by + unfold pairUpdate + rw [localField_update_self,localField_update,coupling_symm g j i] + ring + +lemma pairUpdate_gradient₁ (i j : Fin n) (hij : i ≠ j) (F : Spin n→ℝ) + (x : Spin n) (a b : Bool) : + spinGradient i F (pairUpdate i j x a b)= + (F (pairUpdate i j x true b)-F (pairUpdate i j x false b))/2 := by + have he (c : Bool) : Function.update (pairUpdate i j x a b) i c=pairUpdate i j x c b := by + funext k + by_cases hi : k=i + · subst k;simp [pairUpdate,hij] + · by_cases hj : k=j + · subst k;simp [pairUpdate,hij.symm] + · simp [pairUpdate,hj,hi] + simp only [spinGradient,he] +lemma pairUpdate_gradient₂ (i j : Fin n) (F : Spin n→ℝ) + (x : Spin n) (a b : Bool) : + spinGradient j F (pairUpdate i j x a b)= + (F (pairUpdate i j x a true)-F (pairUpdate i j x a false))/2 := by + simp only [spinGradient,pairUpdate,Function.update_idem] + +lemma pairConditionalMean_boltzmann (g : Disorder n) (h : Fin n→ℝ) (i j : Fin n) (hij : i ≠ j) + (F : Spin n→ℝ) (x : Spin n) : + pairConditionalMean g h i j F x= + pairBoltzmannMean (localField g h i x-coupling g i j*spinValue (x j)) + (localField g h j x-coupling g i j*spinValue (x i)) (coupling g i j) + (fun a b=>F (pairUpdate i j x a b)) := by + let α := localField g h i x-coupling g i j*spinValue (x j) + let γ := localField g h j x-coupling g i j*spinValue (x i) + let C := exp (hamiltonian g h x-α*spinValue (x i)-γ*spinValue (x j)- + coupling g i j*spinValue (x i)*spinValue (x j)) + have hC : C ≠ 0 := (exp_pos _).ne' + have hw (a b : Bool) : weight g h (pairUpdate i j x a b)=C*pairBoltzmannWeight α γ (coupling g i j) a b := by + unfold weight + rw [pairUpdate_hamiltonian g h i j hij,exp_add] + rfl + unfold pairConditionalMean + simp_rw [hw,mul_assoc,← Finset.mul_sum] + rw [mul_div_mul_left _ _ hC] + rfl + +def siteVariance (g : Disorder n) (h : Fin n→ℝ) (i : Fin n) (x : Spin n) : ℝ := + 1-tanh (localField g h i x)^2 + +def weightedGradient (g : Disorder n) (h : Fin n→ℝ) (i : Fin n) (f : Spin n→ℝ) (x : Spin n) : ℝ := + siteVariance g h i x*spinGradient i f x + +lemma expectation_mono (g : Disorder n) (h : Fin n→ℝ) {F G : Spin n→ℝ} + (hFG : ∀ x,F x ≤ G x) : expectation g h F ≤ expectation g h G := by + apply Finset.sum_le_sum + intro x _ + exact mul_le_mul_of_nonneg_left (hFG x) (mass_nonneg g h x) + +lemma pairConditional_cubic_bound (g : Disorder n) (h : Fin n → ℝ) + (i j : Fin n) (hij : i ≠ j) (f : Spin n → ℝ) (x : Spin n) + (hc : |tanh (coupling g i j)| ≤ 1/1000) : + -pairConditionalMean g h i j (fun y => + (tanh (coupling g i j)+2*(tanh (coupling g i j))^2* + tanh (localField g h i y)*tanh (localField g h j y))* + siteVariance g h i y*siteVariance g h j y*spinGradient i f y*spinGradient j f y) x - + 1920000*|tanh (coupling g i j)|^3*pairConditionalMean g h i j + (fun y => siteVariance g h i y*spinGradient i f y^2+ + siteVariance g h j y*spinGradient j f y^2) x ≤ + pairConditionalMean g h i j (fun y => (f y-conditionalExpectation g h i f y)* + (f y-conditionalExpectation g h j f y)) x := by + simp_rw [pairConditionalMean_boltzmann g h i j hij,siteVariance, + conditionalDifference_local,pairUpdate_localField₁,pairUpdate_localField₂, + pairUpdate_gradient₁ i j hij,pairUpdate_gradient₂,pairUpdate_left i j hij,pairUpdate_right] + exact pairBoltzmann_cubic_bound + (localField g h i x-coupling g i j*spinValue (x j)) + (localField g h j x-coupling g i j*spinValue (x i)) + (coupling g i j) (fun a b => f (pairUpdate i j x a b)) hc + +lemma gibbs_pair_cubic_bound (g : Disorder n) (h : Fin n → ℝ) + (i j : Fin n) (hij : i ≠ j) (f : Spin n → ℝ) + (hc : |tanh (coupling g i j)| ≤ 1/1000) : + -expectation g h (fun y => + (tanh (coupling g i j)+2*(tanh (coupling g i j))^2* + tanh (localField g h i y)*tanh (localField g h j y))* + siteVariance g h i y*siteVariance g h j y*spinGradient i f y*spinGradient j f y) - + 1920000*|tanh (coupling g i j)|^3*(expectation g h + (fun y => siteVariance g h i y*spinGradient i f y^2)+expectation g h + (fun y => siteVariance g h j y*spinGradient j f y^2)) ≤ + expectation g h (fun y => (f y-conditionalExpectation g h i f y)* + (f y-conditionalExpectation g h j f y)) := by + have hh := expectation_mono g h (fun x => pairConditional_cubic_bound g h i j hij f x hc) + have eneg (F : Spin n → ℝ) : expectation g h (fun x => -F x) = -expectation g h F := by + simp [expectation] + simpa only [expectation_sub,expectation_const_mul,expectation_pairConditionalMean g h i j hij, + expectation_add,eneg] using hh + +lemma siteVariance_pos (g : Disorder n) (h : Fin n→ℝ) (i : Fin n) (x : Spin n) : + 0 < siteVariance g h i x := by + unfold siteVariance + have ht := abs_tanh_lt_one (localField g h i x) + have hs := (sq_lt_sq₀ (abs_nonneg _) (by norm_num : (0:ℝ) ≤ 1)).mpr ht + simp only [sq_abs,one_pow] at hs + linarith only [hs] +lemma siteVariance_le_one (g : Disorder n) (h : Fin n→ℝ) (i : Fin n) (x : Spin n) : + siteVariance g h i x ≤ 1 := sub_le_self _ (sq_nonneg _) + +lemma dirichlet_weighted (g : Disorder n) (h : Fin n→ℝ) (f : Spin n→ℝ) : + dirichlet g h f=∑ i,expectation g h (fun x=>siteVariance g h i x*spinGradient i f x^2) := by + unfold dirichlet siteVariance + simp_rw [conditionalSiteEnergy_local] + +lemma heatBathGenerator_square (g : Disorder n) (h : Fin n→ℝ) (f : Spin n→ℝ) : + expectation g h (fun x=>heatBathGenerator g h f x^2)= + ∑ i,∑ j,expectation g h (fun x=>(f x-conditionalExpectation g h i f x)* + (f x-conditionalExpectation g h j f x)) := by + simp only [heatBathGenerator,sq,Finset.sum_mul,Finset.mul_sum,expectation_sum] + rw [Finset.sum_comm] + +lemma positive_form_cauchy {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] + (H : E →ₗ[ℝ] E) (hH : H.IsSymmetric) (hpos : ∀ v,0 ≤ ⟪v,H v⟫) (u v : E) : + ⟪u,H v⟫^2 ≤ ⟪u,H u⟫*⟪v,H v⟫ := by + have hh : ∀ t : ℝ,0 ≤ ⟪v,H v⟫*(t*t)+(2*⟪u,H v⟫)*t+⟪u,H u⟫ := by + intro t + have hp := hpos (u+t • v) + simp only [map_add,map_smul,inner_add_left,inner_add_right,real_inner_smul_left, + real_inner_smul_right] at hp + have he : ⟪v,H u⟫=⟪u,H v⟫ := (real_inner_comm (H u) v).trans (hH u v) + rw [he] at hp + nlinarith only [hp] + have hd := discrim_le_zero hh + unfold discrim at hd + nlinarith only [hd] + +lemma curvature_poincare_on_kernel_orthogonal {E : Type*} + [NormedAddCommGroup E] [InnerProductSpace ℝ E] [FiniteDimensional ℝ E] + (H : E →ₗ[ℝ] E) (hH : H.IsSymmetric) (hpos : ∀ v,0 ≤ ⟪v,H v⟫) + {ρ : ℝ} (hρ : 0 < ρ) (hcurv : ∀ v,ρ*⟪v,H v⟫ ≤ ⟪H v,H v⟫) + (f : E) (hf : f ∈ (LinearMap.ker H)ᗮ) : + ρ*⟪f,f⟫ ≤ ⟪f,H f⟫ := by + have hrange : f ∈ LinearMap.range H := by + rwa [← hH.orthogonal_range,Submodule.orthogonal_orthogonal] at hf + obtain ⟨g,rfl⟩ := hrange + have hc := positive_form_cauchy H hH hpos (H g) g + have hg := hcurv g + have hp := hpos (H g) + have hn : 0 ≤ ⟪H g,H g⟫ := real_inner_self_nonneg + have hh : ρ*⟪H g,H g⟫^2 ≤ ⟪H g,H (H g)⟫*⟪H g,H g⟫ := by + calc + _ ≤ ρ*(⟪H g,H (H g)⟫*⟪g,H g⟫) := mul_le_mul_of_nonneg_left hc hρ.le + _ = ⟪H g,H (H g)⟫*(ρ*⟪g,H g⟫) := by ring + _ ≤ _ := mul_le_mul_of_nonneg_left hg hp + by_cases hz : ⟪H g,H g⟫=0 + · rw [hz,mul_zero];exact hp + · have hpos' : 0 < ⟪H g,H g⟫ := lt_of_le_of_ne hn (Ne.symm hz) + nlinarith only [hh,hpos'] + +lemma conditionalExpectation_add (g : Disorder n) (h : Fin n→ℝ) (i : Fin n) + (f k : Spin n→ℝ) (x : Spin n) : + conditionalExpectation g h i (f+k) x=conditionalExpectation g h i f x+conditionalExpectation g h i k x := by + unfold conditionalExpectation + simp only [Pi.add_apply] + ring +lemma conditionalExpectation_smul (g : Disorder n) (h : Fin n→ℝ) (i : Fin n) + (c : ℝ) (f : Spin n→ℝ) (x : Spin n) : + conditionalExpectation g h i (c • f) x=c*conditionalExpectation g h i f x := by + unfold conditionalExpectation + simp only [Pi.smul_apply,smul_eq_mul] + ring + +def heatBathLinear (g : Disorder n) (h : Fin n→ℝ) : (Spin n→ℝ) →ₗ[ℝ] (Spin n→ℝ) where + toFun := heatBathGenerator g h + map_add' f k := by + funext x + simp only [heatBathGenerator,conditionalExpectation_add,Pi.add_apply] + rw [← Finset.sum_add_distrib] + apply Finset.sum_congr rfl + intro i _;ring + map_smul' c f := by + funext x + simp only [heatBathGenerator,conditionalExpectation_smul,Pi.smul_apply,smul_eq_mul, + RingHom.id_apply] + rw [Finset.mul_sum] + apply Finset.sum_congr rfl + intro i _;ring + +def gibbsScale (g : Disorder n) (h : Fin n→ℝ) : (Spin n→ℝ) ≃ₗ[ℝ] EuclideanSpace ℝ (Spin n) where + toFun f := WithLp.toLp 2 (fun x=>sqrt (mass g h x)*f x) + invFun v := fun x=>v x/sqrt (mass g h x) + left_inv f := by + funext x + change sqrt (mass g h x)*f x/sqrt (mass g h x)=f x + exact mul_div_cancel_left₀ (f x) (sqrt_pos.mpr (mass_pos g h x)).ne' + right_inv v := by + ext x + exact mul_div_cancel₀ (v x) (sqrt_pos.mpr (mass_pos g h x)).ne' + map_add' f k := by ext x;simp [mul_add] + map_smul' c f := by ext x;simp [mul_left_comm] + +lemma gibbsScale_inner (g : Disorder n) (h : Fin n→ℝ) (f k : Spin n→ℝ) : + ⟪gibbsScale g h f,gibbsScale g h k⟫=expectation g h (fun x=>f x*k x) := by + simp only [EuclideanSpace.inner_eq_star_dotProduct,star_trivial] + unfold dotProduct expectation + apply Finset.sum_congr rfl + intro x _ + change sqrt (mass g h x)*k x*(sqrt (mass g h x)*f x)=mass g h x*(f x*k x) + calc + _ = sqrt (mass g h x)^2*(f x*k x) := by ring + _ = _ := by rw [sq_sqrt (mass_nonneg g h x)] + +lemma heatBathLinear_const (g : Disorder n) (h : Fin n→ℝ) (c : ℝ) : + heatBathLinear g h (fun _=>c)=0 := by + funext x + simp only [heatBathLinear,heatBathGenerator,LinearMap.coe_mk,AddHom.coe_mk, + conditionalExpectation_const,sub_self,Finset.sum_const_zero,Pi.zero_apply] + +end SKRatio.Fields +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Calculus/PlusSpin.lean b/lean/OAI/Probability/SKRatio/Calculus/PlusSpin.lean new file mode 100644 index 0000000000000000000000000000000000000000..9106a285dd1ed6c1b3da7d5625b21cc34aee6ea5 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Calculus/PlusSpin.lean @@ -0,0 +1,419 @@ +import Mathlib +import OAI.Probability.SKRatio.Calculus.Interaction + +namespace OAI + +section +noncomputable section +open scoped BigOperators Topology Matrix +open ContinuousLinearMap +namespace SKRatio.Calculus + +lemma field_replace_self {n : ℕ} (J : Interaction n) (hdiag : ∀ i, J i i = 0) + (x : Spin n) (i : Fin n) (b : Bool) : + field J (replace x i b) i = field J x i := by + apply Finset.sum_congr rfl + intro j _ + by_cases hi : j = i + · subst j; simp [hdiag] + · simp [spin, replace, hi] + +@[simp] lemma halfDiff_mean_self {n : ℕ} (J : Interaction n) (hdiag : ∀ i, J i i = 0) + (x : Spin n) (i : Fin n) : halfDiff i (fun y => mean J y i) x = 0 := by + simp only [halfDiff, mean, field_replace_self J hdiag, sub_self, zero_div] + +def plusSpin (n : ℕ) : Spin n := fun _ => true + +theorem pointwise_gradient_identity {n : ℕ} (J : Interaction n) + (hdiag : ∀ i, J i i = 0) (f : Observables n) (t : ℝ) : + (1 / 2 : ℝ) * (deriv (fun s => unweightedGradient (semigroup J s f) (plusSpin n)) t - + generator J (unweightedGradient (semigroup J t f)) (plusSpin n)) = + -unweightedGradient (semigroup J t f) (plusSpin n) + + (∑ i, ∑ j ∈ Finset.univ.erase i, + halfDiff i (semigroup J t f) (plusSpin n) * + halfDiff i (fun y => mean J y j) (plusSpin n) * + (halfDiff j (semigroup J t f) (plusSpin n) - + 2 * halfDiff i (halfDiff j (semigroup J t f)) (plusSpin n))) - + (∑ i, ∑ j ∈ Finset.univ.erase i, + gradientWeight J (plusSpin n) j * + (halfDiff i (halfDiff j (semigroup J t f)) (plusSpin n))^2) := by + rw [(unweightedGradient_hasDerivAt J f (plusSpin n) t).deriv, + unweightedGradient_commutator] + simp only [spin, plusSpin, ↓reduceIte, mul_one] + congr 1 + · congr 1 + apply Finset.sum_congr rfl + intro i _ + rw [Finset.sum_erase_eq_sub (Finset.mem_univ i), halfDiff_mean_self J hdiag, + mul_zero, zero_mul, sub_zero] + · apply Finset.sum_congr rfl + intro i _ + rw [Finset.sum_erase_eq_sub (Finset.mem_univ i), halfDiff_self] + simp + +open Real Set + +lemma hasDerivAt_tanh (y : ℝ) : HasDerivAt tanh (1 - tanh y ^ 2) y := by + convert! (Real.hasDerivAt_sinh y).div (Real.hasDerivAt_cosh y) (cosh_pos y).ne' using 1 + · ext x + exact tanh_eq_sinh_div_cosh x + · rw [tanh_eq_sinh_div_cosh] + field_simp + +lemma tanh_lipschitz_abs (x y : ℝ) : |tanh x-tanh y| ≤ |x-y| := by + have hh := Convex.norm_image_sub_le_of_norm_hasDerivWithin_le + (fun z (_ : z ∈ (univ : Set ℝ)) => (hasDerivAt_tanh z).hasDerivWithinAt) + (C := 1) (fun z _ => by + rw [Real.norm_eq_abs,abs_of_nonneg (sub_nonneg.mpr (tanh_sq_lt_one z).le)] + linarith [sq_nonneg (tanh z)]) convex_univ (mem_univ y) (mem_univ x) + simpa only [Real.norm_eq_abs,one_mul] using hh + +lemma abs_tanh_le_abs (x : ℝ) : |tanh x| ≤ |x| := by + simpa only [tanh_zero,sub_zero] using tanh_lipschitz_abs x 0 + +lemma tanh_cubic_error (x : ℝ) : |tanh x-x| ≤ |x|^3/3 := by + let f : ℝ→ℝ := fun y=>y^3/3-y+tanh y + have hd (y : ℝ) : HasDerivAt f (y^2-tanh y^2) y := by + dsimp [f] + convert! ((((hasDerivAt_id y).pow 3).div_const 3).sub (hasDerivAt_id y)).add (hasDerivAt_tanh y) using 1; simp only [id_eq]; ring + have hm : Monotone f := monotone_of_deriv_nonneg (fun y=>(hd y).differentiableAt) (fun y=>by + rw [(hd y).deriv] + have hs := (sq_le_sq₀ (abs_nonneg _) (abs_nonneg _)).mpr (abs_tanh_le_abs y) + simpa only [sq_abs,sub_nonneg] using hs) + have hp (y : ℝ) (hy : 0 ≤ y) : |tanh y-y| ≤ |y|^3/3 := by + have h := hm hy + have ht : tanh y ≤ y := (le_abs_self _).trans ((abs_tanh_le_abs y).trans_eq (abs_of_nonneg hy)) + rw [abs_of_nonpos (sub_nonpos.mpr ht),abs_of_nonneg hy] + simp only [f,tanh_zero,zero_pow (by decide : (3:ℕ) ≠ 0),zero_div,sub_zero,zero_add] at h + linarith only [h] + rcases le_or_gt 0 x with hx | hx + · exact hp x hx + · have h := hp (-x) (by linarith) + simpa only [tanh_neg,neg_sub_neg,abs_sub_comm,abs_neg] using h + +def scalarVariance (h : ℝ) : ℝ := 1 - Real.tanh h ^ 2 + +lemma scalarVariance_pos (h : ℝ) : 0 < scalarVariance h := + sub_pos.mpr (Real.tanh_sq_lt_one h) + +lemma scalarVariance_eq (h : ℝ) : scalarVariance h = 1 / Real.cosh h ^ 2 := by + have hc := Real.cosh_sq_sub_sinh_sq h + unfold scalarVariance + rw [Real.tanh_eq_sinh_div_cosh] + field_simp + nlinarith + +lemma tanh_difference_eq (x y : ℝ) : Real.tanh y - Real.tanh x = + Real.sinh (y-x) / (Real.cosh y * Real.cosh x) := by + rw [Real.tanh_eq_sinh_div_cosh, Real.tanh_eq_sinh_div_cosh, Real.sinh_sub] + field_simp + +lemma normalized_tanh_difference (h d : ℝ) : + (Real.tanh h - Real.tanh (h-d)) / scalarVariance h = + Real.tanh d / (1 - Real.tanh h * Real.tanh d) := by + have hc : Real.cosh (h-d) ≠ 0 := (Real.cosh_pos _).ne' + have hh : Real.cosh h ≠ 0 := (Real.cosh_pos _).ne' + have hd : Real.cosh d ≠ 0 := (Real.cosh_pos _).ne' + have hm : Real.cosh h * Real.cosh d - Real.sinh h * Real.sinh d ≠ 0 := by + simpa only [Real.cosh_sub] using hc + rw [tanh_difference_eq, show h-(h-d)=d by ring, scalarVariance_eq] + simp only [Real.tanh_eq_sinh_div_cosh] + rw [Real.cosh_sub] + field_simp + +def q (z m : ℝ) : ℝ := Real.tanh (2*z) / (2*(1-m*Real.tanh (2*z))) + +lemma tanh_difference_variance (h z : ℝ) : + (Real.tanh h - Real.tanh (h-2*z)) / 2 = scalarVariance h * q z (Real.tanh h) := by + have H := normalized_tanh_difference h (2*z) + apply (div_eq_iff (scalarVariance_pos h).ne').mp at H + rw [H] + unfold q + simp only [div_eq_mul_inv, mul_inv_rev] + ring + +lemma q_denominator {z m : ℝ} (hz : |z| ≤ 1/10) (hm : |m| ≤ 1) : + 4/5 ≤ 1-m*Real.tanh (2*z) := by + have hT : |Real.tanh (2*z)| ≤ 2*|z| := by + simpa only [abs_mul, abs_of_nonneg (by norm_num : (0:ℝ) ≤ 2)] using abs_tanh_le_abs (2*z) + have hmul := mul_le_mul hm hT (abs_nonneg _) (by norm_num : (0:ℝ) ≤ 1) + rw [one_mul, ← abs_mul] at hmul + linarith [le_abs_self (m*Real.tanh (2*z))] + +lemma q_linear_bound {z m : ℝ} (hz : |z| ≤ 1/10) (hm : |m| ≤ 1) : + |q z m| ≤ (5/4)*|z| := by + have hden := q_denominator hz hm + have hpos : 0 < 1-m*Real.tanh (2*z) := by linarith + have hT : |Real.tanh (2*z)| ≤ 2*|z| := by + simpa only [abs_mul, abs_of_nonneg (by norm_num : (0:ℝ) ≤ 2)] using abs_tanh_le_abs (2*z) + rw [q, abs_div, abs_of_pos (mul_pos (by norm_num) hpos), div_le_iff₀ (by positivity)] + nlinarith [mul_le_mul_of_nonneg_right hden (abs_nonneg z)] + +lemma q_expansion {z m : ℝ} (hz : |z| ≤ 1/10) (hm : |m| ≤ 1) : + q z m = Real.tanh (2*z)/2 + m*Real.tanh (2*z)^2/2 + + m^2*Real.tanh (2*z)^3/(2*(1-m*Real.tanh (2*z))) := by + have hden := q_denominator hz hm + have hne : 1-m*Real.tanh (2*z) ≠ 0 := by linarith + have hD : 2*(1-m*Real.tanh (2*z)) ≠ 0 := mul_ne_zero (by norm_num) hne + apply mul_right_cancel₀ hD + simp only [q, add_mul, div_mul_cancel₀ _ hD] + ring + +lemma q_cubic_bound {z m : ℝ} (hz : |z| ≤ 1/10) (hm : |m| ≤ 1) : + |q z m - z - 2*m*z^2| ≤ 7*|z|^3 := by + let T := Real.tanh (2*z) + have hT : |T| ≤ 2*|z| := by + simpa only [T, abs_mul, abs_of_nonneg (by norm_num : (0:ℝ) ≤ 2)] using abs_tanh_le_abs (2*z) + have hc : |T-2*z| ≤ (8/3)*|z|^3 := by + calc + _ ≤ |2*z|^3/3 := tanh_cubic_error _ + _ = _ := by rw [abs_mul, abs_of_nonneg (by norm_num : (0:ℝ) ≤ 2)]; ring + have hden : 4/5 ≤ 1-m*T := q_denominator hz hm + have hpos : 0 < 1-m*T := by linarith + have h1 : |T/2-z| ≤ (4/3)*|z|^3 := by + rw [show T/2-z = (T-2*z)/2 by ring, abs_div, abs_of_nonneg (by norm_num : (0:ℝ) ≤ 2)] + linarith only [hc] + have hsum : |T+2*z| ≤ 4*|z| := by + calc + _ ≤ |T| + |2*z| := abs_add_le _ _ + _ ≤ _ := by rw [abs_mul, abs_of_nonneg (by norm_num : (0:ℝ) ≤ 2)]; linarith only [hT] + have h2 : |m*T^2/2-2*m*z^2| ≤ (16/3)*|z|^4 := by + rw [show m*T^2/2-2*m*z^2 = m/2*((T-2*z)*(T+2*z)) by ring, + abs_mul, abs_div, abs_of_nonneg (by norm_num : (0:ℝ) ≤ 2), abs_mul] + calc + _ ≤ (1/2)*(((8/3)*|z|^3)*(4*|z|)) := + mul_le_mul (by linarith only [hm]) (mul_le_mul hc hsum (abs_nonneg _) (by positivity)) + (by positivity) (by norm_num) + _ = _ := by ring + have h3 : |m^2*T^3/(2*(1-m*T))| ≤ 5*|z|^3 := by + rw [abs_div, abs_mul, abs_pow, abs_pow, abs_of_pos (by positivity : 0 < 2*(1-m*T)), + div_le_iff₀ (by positivity)] + have hm2 : |m|^2 ≤ 1 := by nlinarith only [hm, abs_nonneg m] + have hT3 : |T|^3 ≤ 8*|z|^3 := by + calc + _ ≤ (2*|z|)^3 := pow_le_pow_left₀ (abs_nonneg _) hT 3 + _ = _ := by ring + have hprod := mul_le_mul hm2 hT3 (by positivity : 0 ≤ |T|^3) (by norm_num : (0:ℝ) ≤ 1) + nlinarith only [hprod, mul_le_mul_of_nonneg_right hden (pow_nonneg (abs_nonneg z) 3)] + have hrem : q z m - z - 2*m*z^2 = (T/2-z) + (m*T^2/2-2*m*z^2) + + m^2*T^3/(2*(1-m*T)) := by + rw [q_expansion hz hm] + dsimp [T]; ring + rw [hrem] + calc + _ ≤ (|T/2-z| + |m*T^2/2-2*m*z^2|) + |m^2*T^3/(2*(1-m*T))| := + (abs_add_le _ _).trans (add_le_add (abs_add_le _ _) le_rfl) + _ ≤ (4/3)*|z|^3 + (16/3)*|z|^4 + 5*|z|^3 := + add_le_add (add_le_add h1 h2) h3 + _ ≤ 7*|z|^3 := by + have h := mul_le_mul_of_nonneg_right hz (pow_nonneg (abs_nonneg z) 3) + nlinarith only [h, pow_nonneg (abs_nonneg z) 3] + +lemma q_quadratic_bound {z m : ℝ} (hz : |z| ≤ 1/10) (hm : |m| ≤ 1) : + |q z m - z| ≤ (27/10)*z^2 := by + have hc := q_cubic_bound hz hm + have hmz : |2*m*z^2| ≤ 2*|z|^2 := by + simp only [abs_mul, abs_of_nonneg (by norm_num : (0:ℝ) ≤ 2), abs_pow] + nlinarith only [mul_le_mul_of_nonneg_right hm (sq_nonneg |z|)] + calc + _ = |(q z m-z-2*m*z^2)+2*m*z^2| := by congr 1; ring + _ ≤ |q z m-z-2*m*z^2|+|2*m*z^2| := abs_add_le _ _ + _ ≤ 7*|z|^3+2*|z|^2 := add_le_add hc hmz + _ ≤ (27/10)*z^2 := by + have h := mul_le_mul_of_nonneg_right hz (sq_nonneg |z|) + nlinarith only [h, sq_abs z] + +lemma field_flip_coordinate {n : ℕ} (J : Interaction n) (x : Spin n) (i j : Fin n) : + field J (flip i x) j = field J x j - 2 * J j i * spin x i := by + simp only [field, spin_flip, mul_sub, Finset.sum_sub_distrib, mul_ite, mul_zero, + Finset.sum_ite_eq', Finset.mem_univ, ↓reduceIte] + ring + +def conditionalVariance {n : ℕ} (J : Interaction n) (x : Spin n) (i : Fin n) : ℝ := + 1 - mean J x i ^ 2 + +lemma conditionalVariance_pos {n : ℕ} (J : Interaction n) (x : Spin n) (i : Fin n) : + 0 < conditionalVariance J x i := scalarVariance_pos _ + +lemma conditionalVariance_le_one {n : ℕ} (J : Interaction n) (x : Spin n) (i : Fin n) : + conditionalVariance J x i ≤ 1 := by + unfold conditionalVariance + linarith [sq_nonneg (mean J x i)] + +lemma mean_abs_le_one {n : ℕ} (J : Interaction n) (x : Spin n) (i : Fin n) : + |mean J x i| ≤ 1 := (abs_lt.mpr ⟨Real.neg_one_lt_tanh _, Real.tanh_lt_one _⟩).le + +lemma gradientWeight_pos {n : ℕ} (J : Interaction n) (x : Spin n) (i : Fin n) : + 0 < gradientWeight J x i := by + cases hi : x i + · have h := Real.neg_one_lt_tanh (field J x i) + simp only [gradientWeight, spin, hi, Bool.false_eq_true, ↓reduceIte, neg_mul, + one_mul, sub_neg_eq_add, mean] + linarith + · simpa only [gradientWeight, spin, hi, ↓reduceIte, one_mul, mean] using + sub_pos.mpr (Real.tanh_lt_one (field J x i)) + +@[simp] lemma mean_weight_plus {n : ℕ} (J : Interaction n) (i : Fin n) : + gradientWeight J (plusSpin n) i = 1 - mean J (plusSpin n) i := by + simp [gradientWeight, spin, plusSpin] + +lemma halfDiff_mean_plus {n : ℕ} (J : Interaction n) (hsymm : ∀ i j, J i j = J j i) + (i j : Fin n) : + halfDiff i (fun y => mean J y j) (plusSpin n) = + conditionalVariance J (plusSpin n) j * q (J i j) (mean J (plusSpin n) j) := by + have hplus : replace (plusSpin n) i true = plusSpin n := replace_self _ _ + have hminus : replace (plusSpin n) i false = flip i (plusSpin n) := rfl + simp only [halfDiff, hplus, hminus, mean, field_flip_coordinate, spin, plusSpin, + ↓reduceIte, mul_one, ← hsymm i j] + exact tanh_difference_variance _ _ + +lemma variance_over_weight {m : ℝ} (hm : -1 ≤ m) (hm' : m < 1) : + (1 - m^2)^2 / (1-m) ≤ 32/27 := by + have hpos : 0 < 1-m := sub_pos.mpr hm' + have hid : (1-m^2)^2 / (1-m) = (1-m)*(1+m)^2 := by + apply (div_eq_iff hpos.ne').mpr + ring + rw [hid] + have hp : 0 ≤ m + 5/3 := by linarith only [hm] + nlinarith only [mul_nonneg (sq_nonneg (m-1/3)) hp] + +lemma pair_denominator_control {vi vj wi wj pi pj : ℝ} + (hwi : 0 < wi) (hwj : 0 < wj) : + (vj * |pi| + vi * |pj|)^2 / (wi + wj) ≤ + (vj^2 / wj) * pi^2 + (vi^2 / wi) * pj^2 := by + have H := Finset.sq_sum_div_le_sum_sq_div (R := ℝ) Finset.univ + ![vj * |pi|, vi * |pj|] (g := ![wj, wi]) (by + intro i _ + fin_cases i + · exact hwj + · exact hwi) + simpa only [Fin.sum_univ_two, Matrix.cons_val_zero, Matrix.cons_val_one, + mul_pow, sq_abs, div_eq_mul_inv, mul_assoc, mul_left_comm, mul_comm, add_comm] using H + +lemma scalar_pair_denominator_control {mi mj pi pj : ℝ} + (hmi : -1 ≤ mi) (hmi' : mi < 1) (hmj : -1 ≤ mj) (hmj' : mj < 1) : + ((1-mj^2)*|pi| + (1-mi^2)*|pj|)^2 / ((1-mi) + (1-mj)) ≤ + (32/27)*(pi^2 + pj^2) := by + calc + _ ≤ ((1-mj^2)^2/(1-mj))*pi^2 + ((1-mi^2)^2/(1-mi))*pj^2 := + pair_denominator_control (sub_pos.mpr hmi') (sub_pos.mpr hmj') + _ ≤ (32/27)*pi^2 + (32/27)*pj^2 := + add_le_add (mul_le_mul_of_nonneg_right (variance_over_weight hmj hmj') (sq_nonneg _)) + (mul_le_mul_of_nonneg_right (variance_over_weight hmi hmi') (sq_nonneg _)) + _ = _ := by ring + +lemma complete_pair_square (A r w : ℝ) (hw : 0 < w) : + -2*A*r - w*r^2 ≤ A^2/w := by + rw [le_div_iff₀ hw] + nlinarith only [sq_nonneg (A+w*r)] + +lemma weighted_pair_abs_le {vi vj qi qj pi pj B : ℝ} + (hvi : 0 ≤ vi) (hvj : 0 ≤ vj) (hqi : |qi| ≤ B) (hqj : |qj| ≤ B) : + |vj*qj*pi + vi*qi*pj| ≤ B * (vj*|pi| + vi*|pj|) := by + calc + _ ≤ |vj*qj*pi| + |vi*qi*pj| := abs_add_le _ _ + _ = vj*|qj| *|pi| + vi*|qi| *|pj| := by + simp only [abs_mul, abs_of_nonneg hvi, abs_of_nonneg hvj] + _ ≤ vj*B*|pi| + vi*B*|pj| := add_le_add + (mul_le_mul_of_nonneg_right (mul_le_mul_of_nonneg_left hqj hvj) (abs_nonneg pi)) + (mul_le_mul_of_nonneg_right (mul_le_mul_of_nonneg_left hqi hvi) (abs_nonneg pj)) + _ = _ := by ring + +lemma pair_q_error {z mi mj vi vj pi pj : ℝ} + (hz : |z| ≤ 1/10) (hmi : |mi| ≤ 1) (hmj : |mj| ≤ 1) + (hvi : 0 ≤ vi) (hvj : 0 ≤ vj) : + |(vj*q z mj*pi + vi*q z mi*pj)^2 - (z*(vj*pi+vi*pj))^2| ≤ + 7*|z|^3*(vj*|pi|+vi*|pj|)^2 := by + let A := vj*q z mj*pi + vi*q z mi*pj + let B := z*(vj*pi+vi*pj) + let S := vj*|pi|+vi*|pj| + have hS : 0 ≤ S := by dsimp [S]; positivity + have hdiff : |A-B| ≤ (27/10)*z^2*S := by + have hid : A-B = vj*(q z mj-z)*pi + vi*(q z mi-z)*pj := by dsimp [A, B]; ring + rw [hid] + exact weighted_pair_abs_le hvi hvj (q_quadratic_bound hz hmi) (q_quadratic_bound hz hmj) + have hA : |A| ≤ (5/4)*|z| *S := + weighted_pair_abs_le hvi hvj (q_linear_bound hz hmi) (q_linear_bound hz hmj) + have hB : |B| ≤ |z| *S := by + have hid : B = vj*z*pi + vi*z*pj := by dsimp [B]; ring + rw [hid] + exact weighted_pair_abs_le hvi hvj le_rfl le_rfl + have hsum : |A+B| ≤ (9/4)*|z| *S := by + calc + _ ≤ |A| + |B| := abs_add_le _ _ + _ ≤ (5/4)*|z| *S + |z| *S := add_le_add hA hB + _ = _ := by ring + change |A^2-B^2| ≤ 7*|z|^3*S^2 + rw [show A^2-B^2 = (A-B)*(A+B) by ring, abs_mul] + calc + _ ≤ ((27/10)*z^2*S)*((9/4)*|z| *S) := + mul_le_mul hdiff hsum (abs_nonneg _) (by positivity) + _ = (243/40)*|z|^3*S^2 := by rw [← sq_abs z]; ring + _ ≤ 7*|z|^3*S^2 := by nlinarith only [mul_nonneg (pow_nonneg (abs_nonneg z) 3) (sq_nonneg S)] + +lemma pair_square_replacement {z mi mj pi pj : ℝ} + (hz : |z| ≤ 1/10) (hmi : -1 ≤ mi) (hmi' : mi < 1) + (hmj : -1 ≤ mj) (hmj' : mj < 1) : + ((1-mj^2)*q z mj*pi + (1-mi^2)*q z mi*pj)^2 / ((1-mi)+(1-mj)) ≤ + z^2*((1-mj^2)*pi+(1-mi^2)*pj)^2 / ((1-mi)+(1-mj)) + + (224/27)*|z|^3*(pi^2+pj^2) := by + have hmiabs : |mi| ≤ 1 := abs_le.mpr ⟨hmi, hmi'.le⟩ + have hmjabs : |mj| ≤ 1 := abs_le.mpr ⟨hmj, hmj'.le⟩ + have hvi : 0 ≤ 1-mi^2 := by nlinarith only [sq_le_sq₀ (abs_nonneg mi) (by norm_num : (0:ℝ) ≤ 1) |>.2 hmiabs, sq_abs mi] + have hvj : 0 ≤ 1-mj^2 := by nlinarith only [sq_le_sq₀ (abs_nonneg mj) (by norm_num : (0:ℝ) ≤ 1) |>.2 hmjabs, sq_abs mj] + have herr := pair_q_error hz hmiabs hmjabs hvi hvj (pi := pi) (pj := pj) + have hd : 0 < (1-mi)+(1-mj) := add_pos (sub_pos.mpr hmi') (sub_pos.mpr hmj') + have hraw : ((1-mj^2)*q z mj*pi + (1-mi^2)*q z mi*pj)^2 ≤ + z^2*((1-mj^2)*pi+(1-mi^2)*pj)^2 + 7*|z|^3*((1-mj^2)*|pi|+(1-mi^2)*|pj|)^2 := by + have h := (le_abs_self _).trans herr + rw [mul_pow] at h + linarith only [h] + calc + _ ≤ (z^2*((1-mj^2)*pi+(1-mi^2)*pj)^2 + 7*|z|^3*((1-mj^2)*|pi|+(1-mi^2)*|pj|)^2) / + ((1-mi)+(1-mj)) := div_le_div_of_nonneg_right hraw hd.le + _ = z^2*((1-mj^2)*pi+(1-mi^2)*pj)^2 / ((1-mi)+(1-mj)) + + (7*|z|^3)*(((1-mj^2)*|pi|+(1-mi^2)*|pj|)^2/((1-mi)+(1-mj))) := by ring + _ ≤ z^2*((1-mj^2)*pi+(1-mi^2)*pj)^2 / ((1-mi)+(1-mj)) + + (7*|z|^3)*((32/27)*(pi^2+pj^2)) := add_le_add le_rfl + (mul_le_mul_of_nonneg_left (scalar_pair_denominator_control hmi hmi' hmj hmj') (by positivity)) + _ = _ := by ring + +def pairSum {n : ℕ} (F : Fin n → Fin n → ℝ) : ℝ := + ∑ i, ∑ j ∈ Finset.univ.filter (fun j => i < j), F i j + +lemma sum_transpose_triangle {n : ℕ} (F : Fin n → Fin n → ℝ) : + (∑ i, ∑ j ∈ Finset.univ.filter (fun j => j < i), F i j) = + pairSum (fun i j => F j i) := by + simp only [pairSum, Finset.sum_filter] + rw [Finset.sum_comm] + +lemma sum_offdiag_pairs {n : ℕ} (F : Fin n → Fin n → ℝ) : + (∑ i, ∑ j ∈ Finset.univ.erase i, F i j) = pairSum (fun i j => F i j + F j i) := by + have hsplit (i : Fin n) : + (∑ j ∈ Finset.univ.erase i, F i j) = + (∑ j ∈ Finset.univ.filter (fun j => i < j), F i j) + + ∑ j ∈ Finset.univ.filter (fun j => j < i), F i j := by + have heq : Finset.univ.erase i = (Finset.univ.filter (fun j => i < j)) ∪ + (Finset.univ.filter (fun j => j < i)) := by + ext j + simp only [Finset.mem_erase, Finset.mem_univ, and_true, Finset.mem_union, + Finset.mem_filter, true_and] + omega + have hdis : Disjoint (Finset.univ.filter (fun j => i < j)) + (Finset.univ.filter (fun j => j < i)) := by + simp only [Finset.disjoint_left, Finset.mem_filter, Finset.mem_univ, true_and] + intro j hj hj'; exact (lt_asymm hj hj') + rw [heq, Finset.sum_union hdis] + simp_rw [hsplit] + rw [Finset.sum_add_distrib, sum_transpose_triangle] + simp only [pairSum, Finset.sum_add_distrib] + +lemma pairSum_add {n : ℕ} (F G : Fin n → Fin n → ℝ) : + pairSum (fun i j => F i j + G i j) = pairSum F + pairSum G := by + simp only [pairSum, Finset.sum_add_distrib] + +end SKRatio.Calculus +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Calculus/RowControl.lean b/lean/OAI/Probability/SKRatio/Calculus/RowControl.lean new file mode 100644 index 0000000000000000000000000000000000000000..a2491bf3d9e399dfc4e6c37f51ee805d72c3b634 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Calculus/RowControl.lean @@ -0,0 +1,437 @@ +import Mathlib +import OAI.Probability.SKRatio.Calculus.PlusSpin + +namespace OAI + +section +noncomputable section +open scoped BigOperators Topology Matrix +open ContinuousLinearMap +namespace SKRatio.Calculus +open Real Set + +lemma pairSum_sub {n : ℕ} (F G : Fin n → Fin n → ℝ) : + pairSum (fun i j => F i j - G i j) = pairSum F - pairSum G := by + simp only [pairSum, Finset.sum_sub_distrib] + +lemma pairSum_mul {n : ℕ} (a : ℝ) (F : Fin n → Fin n → ℝ) : + pairSum (fun i j => a * F i j) = a * pairSum F := by + simp only [pairSum, Finset.mul_sum] + +lemma pairSum_le {n : ℕ} {F G : Fin n → Fin n → ℝ} + (h : ∀ i j, i < j → F i j ≤ G i j) : pairSum F ≤ pairSum G := by + apply Finset.sum_le_sum + intro i _ + apply Finset.sum_le_sum + intro j hj + exact h i j (Finset.mem_filter.mp hj).2 + +def rowControl {n : ℕ} (J : Interaction n) (k : ℕ) : ℝ := + (Finset.univ.sup (fun i => ∑ j, ‖J i j‖₊ ^ k) : NNReal) + +lemma rowControl_nonneg {n : ℕ} (J : Interaction n) (k : ℕ) : 0 ≤ rowControl J k := + NNReal.coe_nonneg _ + +lemma row_le_rowControl {n : ℕ} (J : Interaction n) (k : ℕ) (i : Fin n) : + (∑ j, |J i j|^k) ≤ rowControl J k := by + have h := Finset.le_sup (f := fun i => ∑ j, ‖J i j‖₊^k) (Finset.mem_univ i) + simpa only [rowControl, NNReal.coe_sum, NNReal.coe_pow, coe_nnnorm, Real.norm_eq_abs] using + (NNReal.coe_le_coe.mpr h) + +abbrev R2 {n : ℕ} (J : Interaction n) : ℝ := rowControl J 2 +abbrev R3 {n : ℕ} (J : Interaction n) : ℝ := rowControl J 3 + +lemma pair_row_bound {n : ℕ} (J : Interaction n) (hsymm : ∀ i j, J i j = J j i) + (p : Fin n → ℝ) (k : ℕ) : + pairSum (fun i j => |J i j|^k * (p i^2+p j^2)) ≤ rowControl J k * ∑ i, p i^2 := by + have hid : pairSum (fun i j => |J i j|^k * (p i^2+p j^2)) = + ∑ i, ∑ j ∈ Finset.univ.erase i, |J i j|^k * p i^2 := by + rw [sum_offdiag_pairs] + unfold pairSum + apply Finset.sum_congr rfl + intro i _ + apply Finset.sum_congr rfl + intro j _ + dsimp only + rw [← hsymm i j] + ring + rw [hid, Finset.mul_sum] + apply Finset.sum_le_sum + intro i _ + rw [← Finset.sum_mul] + apply mul_le_mul_of_nonneg_right _ (sq_nonneg _) + exact (Finset.sum_le_sum_of_subset_of_nonneg (Finset.erase_subset _ _) + (fun _ _ _ => pow_nonneg (abs_nonneg _) k)).trans (row_le_rowControl J k i) + +lemma offdiag_abs_row_bound {n : ℕ} (J : Interaction n) (hsymm : ∀ i j, J i j = J j i) + (p : Fin n → ℝ) (k : ℕ) : + (∑ i, ∑ j ∈ Finset.univ.erase i, |J i j|^k * |p i| * |p j|) ≤ + rowControl J k * ∑ i, p i^2 := by + rw [sum_offdiag_pairs] + refine le_trans (pairSum_le (fun i j _ => ?_)) (pair_row_bound J hsymm p k) + rw [← hsymm i j] + have h : 2*|p i| * |p j| ≤ p i^2+p j^2 := by + nlinarith only [sq_nonneg (|p i|-|p j|), sq_abs (p i), sq_abs (p j)] + have hm := mul_le_mul_of_nonneg_left h (pow_nonneg (abs_nonneg (J i j)) k) + nlinarith only [hm] + +lemma eliminate_second_differences {n : ℕ} (p w : Fin n → ℝ) + (a r : Fin n → Fin n → ℝ) (hw : ∀ i, 0 < w i) (hr : ∀ i j, r i j = r j i) : + (∑ i, ∑ j ∈ Finset.univ.erase i, p i*a i j*(p j-2*r i j)) - + (∑ i, ∑ j ∈ Finset.univ.erase i, w j*(r i j)^2) ≤ + (∑ i, ∑ j ∈ Finset.univ.erase i, p i*a i j*p j) + + pairSum (fun i j => (a i j*p i+a j i*p j)^2/(w i+w j)) := by + rw [sum_offdiag_pairs, sum_offdiag_pairs, sum_offdiag_pairs, ← pairSum_sub, ← pairSum_add] + apply pairSum_le + intro i j _ + rw [← hr i j] + have h := complete_pair_square (a i j*p i+a j i*p j) (r i j) (w i+w j) + (add_pos (hw i) (hw j)) + linarith only [h] + +def gradientForm {n : ℕ} (J : Interaction n) (p : Fin n → ℝ) : ℝ := + (∑ i, ∑ j ∈ Finset.univ.erase i, + J i j * p i * conditionalVariance J (plusSpin n) j * p j) + + 2 * (∑ i, ∑ j ∈ Finset.univ.erase i, + J i j^2 * p i * mean J (plusSpin n) j * conditionalVariance J (plusSpin n) j * p j) + + pairSum (fun i j => + J i j^2 * (conditionalVariance J (plusSpin n) j * p i + + conditionalVariance J (plusSpin n) i * p j)^2 / + (gradientWeight J (plusSpin n) i + gradientWeight J (plusSpin n) j)) + +lemma field_difference_error {n : ℕ} (J : Interaction n) (hsymm : ∀ i j, J i j = J j i) + (hsmall : ∀ i j, |J i j| ≤ 1/10) (i j : Fin n) : + |halfDiff i (fun y => mean J y j) (plusSpin n) - + J i j * conditionalVariance J (plusSpin n) j - + 2*(J i j)^2 * mean J (plusSpin n) j * conditionalVariance J (plusSpin n) j| ≤ + 7*|J i j|^3 := by + let v := conditionalVariance J (plusSpin n) j + let m := mean J (plusSpin n) j + have hv : 0 ≤ v := (conditionalVariance_pos J (plusSpin n) j).le + have hv1 : v ≤ 1 := conditionalVariance_le_one J (plusSpin n) j + rw [halfDiff_mean_plus J hsymm] + change |v*q (J i j) m - J i j*v - 2*(J i j)^2*m*v| ≤ _ + rw [show v*q (J i j) m - J i j*v - 2*(J i j)^2*m*v = + v*(q (J i j) m - J i j - 2*m*(J i j)^2) by ring, abs_mul, abs_of_nonneg hv] + calc + _ ≤ v*(7*|J i j|^3) := mul_le_mul_of_nonneg_left + (q_cubic_bound (hsmall i j) (mean_abs_le_one J (plusSpin n) j)) hv + _ ≤ 7*|J i j|^3 := by nlinarith only [mul_le_mul_of_nonneg_right hv1 (by positivity : 0 ≤ 7*|J i j|^3)] + +lemma linear_field_replacement {n : ℕ} (J : Interaction n) (hsymm : ∀ i j, J i j = J j i) + (hsmall : ∀ i j, |J i j| ≤ 1/10) (p : Fin n → ℝ) : + (∑ i, ∑ j ∈ Finset.univ.erase i, + p i * halfDiff i (fun y => mean J y j) (plusSpin n) * p j) ≤ + (∑ i, ∑ j ∈ Finset.univ.erase i, + J i j * p i * conditionalVariance J (plusSpin n) j * p j) + + 2 * (∑ i, ∑ j ∈ Finset.univ.erase i, + J i j^2 * p i * mean J (plusSpin n) j * conditionalVariance J (plusSpin n) j * p j) + + 7*R3 J*(∑ i, p i^2) := by + have hpoint (i j : Fin n) : p i * halfDiff i (fun y => mean J y j) (plusSpin n) * p j ≤ + J i j * p i * conditionalVariance J (plusSpin n) j * p j + + 2 * (J i j^2 * p i * mean J (plusSpin n) j * conditionalVariance J (plusSpin n) j * p j) + + 7*|J i j|^3 * |p i| * |p j| := by + let e := halfDiff i (fun y => mean J y j) (plusSpin n) - + J i j * conditionalVariance J (plusSpin n) j - + 2*(J i j)^2 * mean J (plusSpin n) j * conditionalVariance J (plusSpin n) j + have he : |e| ≤ 7*|J i j|^3 := field_difference_error J hsymm hsmall i j + have hprod : p i*e*p j ≤ 7*|J i j|^3 * |p i| * |p j| := by + calc + _ ≤ |p i*e*p j| := le_abs_self _ + _ = |e| * |p i| * |p j| := by simp only [abs_mul]; ring + _ ≤ _ := mul_le_mul_of_nonneg_right + (mul_le_mul_of_nonneg_right he (abs_nonneg _)) (abs_nonneg _) + dsimp only [e] at hprod + linarith only [hprod] + have hsum := Finset.sum_le_sum (fun i (_ : i ∈ (Finset.univ : Finset (Fin n))) => + Finset.sum_le_sum (fun j (_ : j ∈ Finset.univ.erase i) => hpoint i j)) + simp only [Finset.sum_add_distrib, ← Finset.mul_sum, mul_assoc] at hsum + have hrow := mul_le_mul_of_nonneg_left (offdiag_abs_row_bound J hsymm p 3) + (by norm_num : (0:ℝ) ≤ 7) + simp only [← Finset.mul_sum, mul_assoc] at hrow ⊢ + linarith only [hsum, hrow] + +lemma completed_squares_replacement {n : ℕ} (J : Interaction n) (hsymm : ∀ i j, J i j = J j i) + (hsmall : ∀ i j, |J i j| ≤ 1/10) (p : Fin n → ℝ) : + pairSum (fun i j => + (halfDiff i (fun y => mean J y j) (plusSpin n)*p i + + halfDiff j (fun y => mean J y i) (plusSpin n)*p j)^2 / + (gradientWeight J (plusSpin n) i+gradientWeight J (plusSpin n) j)) ≤ + pairSum (fun i j => + J i j^2 * (conditionalVariance J (plusSpin n) j * p i + + conditionalVariance J (plusSpin n) i * p j)^2 / + (gradientWeight J (plusSpin n) i + gradientWeight J (plusSpin n) j)) + + (224/27)*R3 J*(∑ i, p i^2) := by + calc + _ ≤ pairSum (fun i j => + J i j^2 * (conditionalVariance J (plusSpin n) j * p i + + conditionalVariance J (plusSpin n) i * p j)^2 / + (gradientWeight J (plusSpin n) i + gradientWeight J (plusSpin n) j) + + (224/27)*|J i j|^3*(p i^2+p j^2)) := by + apply pairSum_le + intro i j _ + rw [halfDiff_mean_plus J hsymm, halfDiff_mean_plus J hsymm, ← hsymm i j] + simp only [mean_weight_plus, conditionalVariance] + exact pair_square_replacement (hsmall i j) + (Real.neg_one_lt_tanh _).le (Real.tanh_lt_one _) + (Real.neg_one_lt_tanh _).le (Real.tanh_lt_one _) + _ = _ + (224/27) * pairSum (fun i j => |J i j|^3*(p i^2+p j^2)) := by + rw [pairSum_add] + congr 1 + simp only [mul_assoc, pairSum_mul] + _ ≤ _ := by + have h := mul_le_mul_of_nonneg_left (pair_row_bound J hsymm p 3) + (by norm_num : (0:ℝ) ≤ 224/27) + simp only [mul_assoc] + exact add_le_add le_rfl h + +theorem pointwise_gradient_bound_plus {n : ℕ} (J : Interaction n) + (hsymm : ∀ i j, J i j = J j i) (hdiag : ∀ i, J i i = 0) + (hsmall : ∀ i j, |J i j| ≤ 1/10) (f : Observables n) (t : ℝ) : + (1/2:ℝ) * (deriv (fun s => unweightedGradient (semigroup J s f) (plusSpin n)) t - + generator J (unweightedGradient (semigroup J t f)) (plusSpin n)) ≤ + -unweightedGradient (semigroup J t f) (plusSpin n) + + gradientForm J (fun i => halfDiff i (semigroup J t f) (plusSpin n)) + + 16*R3 J*unweightedGradient (semigroup J t f) (plusSpin n) := by + rw [pointwise_gradient_identity J hdiag] + let p := fun i => halfDiff i (semigroup J t f) (plusSpin n) + let a := fun i j => halfDiff i (fun y => mean J y j) (plusSpin n) + let r := fun i j => halfDiff i (halfDiff j (semigroup J t f)) (plusSpin n) + have hc := eliminate_second_differences p (gradientWeight J (plusSpin n)) a r + (gradientWeight_pos J (plusSpin n)) (fun i j => halfDiff_comm i j _ _) + have hl := linear_field_replacement J hsymm hsmall p + have hs := completed_squares_replacement J hsymm hsmall p + have hU : 0 ≤ unweightedGradient (semigroup J t f) (plusSpin n) := + Finset.sum_nonneg (fun i _ => sq_nonneg _) + have hR := rowControl_nonneg J 3 + have hbudget := mul_nonneg hR hU + dsimp only [p, a, r] at hc hl hs + unfold gradientForm unweightedGradient at * + linarith only [hc, hl, hs, hbudget] + +def signProduct {n : ℕ} (x y : Spin n) : Spin n := + fun i => if x i then y i else !(y i) + +@[simp] lemma signProduct_plus {n : ℕ} (x : Spin n) : signProduct x (plusSpin n) = x := by + funext i + cases hi : x i <;> simp [signProduct, plusSpin, hi] + +@[simp] lemma plus_signProduct {n : ℕ} (x : Spin n) : signProduct (plusSpin n) x = x := by + funext i + simp [signProduct, plusSpin] + +lemma signProduct_involutive {n : ℕ} (x : Spin n) : Function.Involutive (signProduct x) := by + intro y + funext i + cases h : x i <;> simp [signProduct, h] + +lemma spin_signProduct {n : ℕ} (x y : Spin n) (i : Fin n) : + spin (signProduct x y) i = spin x i * spin y i := by + cases hx : x i <;> cases hy : y i <;> simp [signProduct, spin, hx, hy] + +@[simp] lemma abs_spin {n : ℕ} (x : Spin n) (i : Fin n) : |spin x i| = 1 := by + cases hx : x i <;> simp [spin, hx] + +lemma signProduct_replace {n : ℕ} (x y : Spin n) (i : Fin n) (b : Bool) : + signProduct x (replace y i b) = replace (signProduct x y) i (if x i then b else !b) := by + funext j + by_cases hj : j = i + · subst j; simp [replace, signProduct] + · simp [replace, signProduct, hj] + +def signConjugate {n : ℕ} (x : Spin n) (J : Interaction n) : Interaction n := + fun i j => spin x i * J i j * spin x j + +def signPullback {n : ℕ} (x : Spin n) (f : Observables n) : Observables n := + fun y => f (signProduct x y) + +lemma halfDiff_signPullback {n : ℕ} (x y : Spin n) (f : Observables n) (i : Fin n) : + halfDiff i (signPullback x f) y = spin x i * halfDiff i f (signProduct x y) := by + simp only [halfDiff, signPullback, signProduct_replace] + cases hi : x i <;> simp only [hi, ↓reduceIte, Bool.not_true, Bool.not_false, spin, + Bool.false_eq_true, neg_mul, one_mul] + · ring + +lemma field_signConjugate {n : ℕ} (J : Interaction n) (x y : Spin n) (i : Fin n) : + field (signConjugate x J) y i = spin x i * field J (signProduct x y) i := by + simp only [field, signConjugate, spin_signProduct, Finset.mul_sum] + apply Finset.sum_congr rfl + intro j _ + ring + +lemma mean_signConjugate {n : ℕ} (J : Interaction n) (x y : Spin n) (i : Fin n) : + mean (signConjugate x J) y i = spin x i * mean J (signProduct x y) i := by + simp only [mean, field_signConjugate] + cases hi : x i <;> simp only [spin, hi, Bool.false_eq_true, ↓reduceIte, + neg_mul, one_mul, Real.tanh_neg] + +lemma generator_signConjugate {n : ℕ} (J : Interaction n) (x : Spin n) (f : Observables n) : + generator (signConjugate x J) (signPullback x f) = signPullback x (generator J f) := by + funext y + simp only [generator, halfDiff_signPullback, mean_signConjugate, signPullback] + apply Finset.sum_congr rfl + intro i _ + rw [spin_signProduct] + linear_combination mean J (signProduct x y) i * halfDiff i f (signProduct x y) * spin_sq x i + +lemma unweightedGradient_signPullback {n : ℕ} (x : Spin n) (f : Observables n) : + unweightedGradient (signPullback x f) = signPullback x (unweightedGradient f) := by + funext y + simp only [unweightedGradient, halfDiff_signPullback, mul_pow, spin_sq, one_mul, signPullback] + +lemma gradient_drift_signPullback {n : ℕ} (J : Interaction n) (x y : Spin n) (f : Observables n) : + (∑ i, 2 * halfDiff i (signPullback x f) y * + halfDiff i (generator (signConjugate x J) (signPullback x f)) y) = + ∑ i, 2 * halfDiff i f (signProduct x y) * halfDiff i (generator J f) (signProduct x y) := by + rw [generator_signConjugate] + simp only [halfDiff_signPullback] + apply Finset.sum_congr rfl + intro i _ + linear_combination 2 * halfDiff i f (signProduct x y) * halfDiff i (generator J f) (signProduct x y) * spin_sq x i + +lemma signConjugate_symm {n : ℕ} (J : Interaction n) (hsymm : ∀ i j, J i j = J j i) + (x : Spin n) : ∀ i j, signConjugate x J i j = signConjugate x J j i := by + intro i j + simp only [signConjugate, ← hsymm i j] + ring + +lemma signConjugate_diag {n : ℕ} (J : Interaction n) (hdiag : ∀ i, J i i = 0) + (x : Spin n) : ∀ i, signConjugate x J i i = 0 := by + intro i; simp [signConjugate, hdiag] + +@[simp] lemma abs_signConjugate {n : ℕ} (J : Interaction n) (x : Spin n) (i j : Fin n) : + |signConjugate x J i j| = |J i j| := by + simp [signConjugate, abs_mul] + +lemma rowControl_signConjugate {n : ℕ} (J : Interaction n) (x : Spin n) (k : ℕ) : + rowControl (signConjugate x J) k = rowControl J k := by + have hn (i j : Fin n) : ‖signConjugate x J i j‖₊ = ‖J i j‖₊ := by + apply NNReal.coe_injective + simp only [coe_nnnorm, Real.norm_eq_abs, abs_signConjugate] + simp only [rowControl, hn] + +lemma instantaneous_gradient_bound_plus {n : ℕ} (J : Interaction n) + (hsymm : ∀ i j, J i j = J j i) (hdiag : ∀ i, J i i = 0) + (hsmall : ∀ i j, |J i j| ≤ 1/10) (f : Observables n) : + (1/2:ℝ) * ((∑ i, 2 * halfDiff i f (plusSpin n) * + halfDiff i (generator J f) (plusSpin n)) - generator J (unweightedGradient f) (plusSpin n)) ≤ + -unweightedGradient f (plusSpin n) + gradientForm J (fun i => halfDiff i f (plusSpin n)) + + 16*R3 J*unweightedGradient f (plusSpin n) := by + have h := pointwise_gradient_bound_plus J hsymm hdiag hsmall f 0 + rw [(unweightedGradient_hasDerivAt J f (plusSpin n) 0).deriv] at h + simpa only [semigroup_zero, one_apply_eq_self] using h + +theorem pointwise_gradient_local_bound {n : ℕ} (J : Interaction n) + (hsymm : ∀ i j, J i j = J j i) (hdiag : ∀ i, J i i = 0) + (hsmall : ∀ i j, |J i j| ≤ 1/10) (f : Observables n) (t : ℝ) (x : Spin n) : + (1/2:ℝ) * (deriv (fun s => unweightedGradient (semigroup J s f) x) t - + generator J (unweightedGradient (semigroup J t f)) x) ≤ + -unweightedGradient (semigroup J t f) x + + gradientForm (signConjugate x J) (fun i => spin x i * halfDiff i (semigroup J t f) x) + + 16*R3 J*unweightedGradient (semigroup J t f) x := by + have h := instantaneous_gradient_bound_plus (signConjugate x J) (signConjugate_symm J hsymm x) + (signConjugate_diag J hdiag x) (by simpa only [abs_signConjugate] using hsmall) + (signPullback x (semigroup J t f)) + rw [gradient_drift_signPullback, unweightedGradient_signPullback, + generator_signConjugate] at h + simp only [halfDiff_signPullback, signPullback, signProduct_plus, R3, + rowControl_signConjugate] at h + rw [(unweightedGradient_hasDerivAt J f x t).deriv] + exact h + +def euclideanOpNorm {n : ℕ} (J : Interaction n) : ℝ := ‖Matrix.toEuclideanCLM (𝕜 := ℝ) (n := Fin n) J‖ + +lemma euclideanOpNorm_nonneg {n : ℕ} (J : Interaction n) : 0 ≤ euclideanOpNorm J := + norm_nonneg _ + +lemma euclideanNorm_variance_le {n : ℕ} (J : Interaction n) (x : Spin n) + (p : Fin n → ℝ) : + ‖WithLp.toLp 2 (fun i => conditionalVariance J x i * p i)‖ ≤ + ‖(WithLp.toLp 2 p : EuclideanSpace ℝ (Fin n))‖ := by + apply (sq_le_sq₀ (norm_nonneg _) (norm_nonneg _)).mp + simp only [EuclideanSpace.real_norm_sq_eq] + apply Finset.sum_le_sum + intro i _ + have hv := (conditionalVariance_pos J x i).le + have hv1 := conditionalVariance_le_one J x i + have hv2 : (conditionalVariance J x i)^2 ≤ 1 := by nlinarith only [hv, hv1] + nlinarith only [mul_le_mul_of_nonneg_right hv2 (sq_nonneg (p i))] + +lemma gradientForm_linear_bound {n : ℕ} (J : Interaction n) (hdiag : ∀ i, J i i = 0) + (p : Fin n → ℝ) : + (∑ i, ∑ j ∈ Finset.univ.erase i, + J i j * p i * conditionalVariance J (plusSpin n) j * p j) ≤ + euclideanOpNorm J * ∑ i, p i^2 := by + let P : EuclideanSpace ℝ (Fin n) := WithLp.toLp 2 p + let Q : EuclideanSpace ℝ (Fin n) := + WithLp.toLp 2 (fun j => conditionalVariance J (plusSpin n) j * p j) + have hid : (∑ i, ∑ j ∈ Finset.univ.erase i, + J i j * p i * conditionalVariance J (plusSpin n) j * p j) = + inner ℝ P (Matrix.toEuclideanCLM (𝕜 := ℝ) (n := Fin n) J Q) := by + rw [Matrix.inner_toEuclideanCLM (J : Matrix (Fin n) (Fin n) ℝ) P Q] + simp only [dotProduct, Matrix.mulVec, P, Q, Finset.mul_sum] + apply Finset.sum_congr rfl + intro i _ + rw [← Finset.sum_erase_add _ _ (Finset.mem_univ i)] + simp only [hdiag, zero_mul, mul_zero, add_zero] + apply Finset.sum_congr rfl + intro j _ + ring + rw [hid] + calc + _ ≤ ‖P‖ * ‖Matrix.toEuclideanCLM (𝕜 := ℝ) (n := Fin n) J Q‖ := real_inner_le_norm _ _ + _ ≤ ‖P‖ * (euclideanOpNorm J * ‖Q‖) := + mul_le_mul_of_nonneg_left ((Matrix.toEuclideanCLM (𝕜 := ℝ) (n := Fin n) J).le_opNorm _) (norm_nonneg _) + _ ≤ ‖P‖ * (euclideanOpNorm J * ‖P‖) := + mul_le_mul_of_nonneg_left + (mul_le_mul_of_nonneg_left (euclideanNorm_variance_le J (plusSpin n) p) + (euclideanOpNorm_nonneg J)) (norm_nonneg _) + _ = euclideanOpNorm J * ∑ i, p i^2 := by + rw [show ‖P‖ * (euclideanOpNorm J * ‖P‖) = euclideanOpNorm J * ‖P‖^2 by ring, + EuclideanSpace.real_norm_sq_eq] + +lemma abs_mean_variance_bound {m : ℝ} (hm : |m| ≤ 1) : + |m*(1-m^2)| ≤ 2/(3*Real.sqrt 3) := by + have hs : 0 < Real.sqrt 3 := Real.sqrt_pos.2 (by norm_num) + have hs2 : (Real.sqrt 3)^2 = 3 := Real.sq_sqrt (by norm_num) + have hmv : 0 ≤ 1-m^2 := by nlinarith only [sq_abs m, abs_nonneg m, hm] + rw [abs_mul, abs_of_nonneg hmv, le_div_iff₀ (by positivity : 0 < 3*Real.sqrt 3)] + have h : 0 ≤ (Real.sqrt 3 * |m| - 1)^2 * (Real.sqrt 3 * |m| + 2) := + mul_nonneg (sq_nonneg _) (by positivity) + have hc : (Real.sqrt 3 * |m|)^3 = 3*m^2*(Real.sqrt 3*|m|) := by + rw [pow_succ, mul_pow, hs2, sq_abs] + nlinarith only [h, hc] + +lemma mean_variance_bound {n : ℕ} (J : Interaction n) (x : Spin n) (j : Fin n) : + |mean J x j * conditionalVariance J x j| ≤ 2/(3*Real.sqrt 3) := + abs_mean_variance_bound (mean_abs_le_one J x j) + +lemma gradientForm_quadratic_bound {n : ℕ} (J : Interaction n) + (hsymm : ∀ i j, J i j = J j i) (p : Fin n → ℝ) : + 2*(∑ i, ∑ j ∈ Finset.univ.erase i, + J i j^2 * p i * mean J (plusSpin n) j * conditionalVariance J (plusSpin n) j * p j) ≤ + (4/(3*Real.sqrt 3))* R2 J * ∑ i, p i^2 := by + have hpoint (i j : Fin n) : + J i j^2 * p i * mean J (plusSpin n) j * conditionalVariance J (plusSpin n) j * p j ≤ + (2/(3*Real.sqrt 3)) * (|J i j|^2*|p i| *|p j|) := by + calc + _ ≤ |J i j^2 * p i * mean J (plusSpin n) j * conditionalVariance J (plusSpin n) j * p j| := + le_abs_self _ + _ = |mean J (plusSpin n) j*conditionalVariance J (plusSpin n) j| * + (|J i j|^2*|p i| *|p j|) := by simp only [abs_mul, abs_pow]; ring + _ ≤ _ := mul_le_mul_of_nonneg_right (mean_variance_bound J (plusSpin n) j) (by positivity) + have hsum := Finset.sum_le_sum (fun i (_ : i ∈ (Finset.univ : Finset (Fin n))) => + Finset.sum_le_sum (fun j (_ : j ∈ Finset.univ.erase i) => hpoint i j)) + simp only [← Finset.mul_sum] at hsum + have hrow := mul_le_mul_of_nonneg_left (offdiag_abs_row_bound J hsymm p 2) + (by positivity : 0 ≤ 2/(3*Real.sqrt 3)) + calc + _ ≤ 2*((2/(3*Real.sqrt 3))* (R2 J * ∑ i, p i^2)) := + mul_le_mul_of_nonneg_left (hsum.trans hrow) (by norm_num) + _ = _ := by ring + +end SKRatio.Calculus +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Calculus/SignedVector.lean b/lean/OAI/Probability/SKRatio/Calculus/SignedVector.lean new file mode 100644 index 0000000000000000000000000000000000000000..33f4fa0b28ee132e931feff92088c7dbea584530 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Calculus/SignedVector.lean @@ -0,0 +1,417 @@ +import Mathlib +import OAI.Probability.SKRatio.FiniteChain.Mean +import OAI.Probability.SKRatio.Calculus.RowControl + +namespace OAI + +section +noncomputable section +open scoped BigOperators Topology Matrix +open ContinuousLinearMap +namespace SKRatio.Calculus +open Real Set + +lemma gradientForm_pairs_bound {n : ℕ} (J : Interaction n) + (hsymm : ∀ i j, J i j = J j i) (p : Fin n → ℝ) : + pairSum (fun i j => + J i j^2 * (conditionalVariance J (plusSpin n) j * p i + + conditionalVariance J (plusSpin n) i * p j)^2 / + (gradientWeight J (plusSpin n) i + gradientWeight J (plusSpin n) j)) ≤ + (32/27)*R2 J * ∑ i, p i^2 := by + have hpoint (i j : Fin n) : + (conditionalVariance J (plusSpin n) j * p i + + conditionalVariance J (plusSpin n) i * p j)^2 / + (gradientWeight J (plusSpin n) i + gradientWeight J (plusSpin n) j) ≤ + (32/27)*(p i^2+p j^2) := by + have habs : |conditionalVariance J (plusSpin n) j * p i + + conditionalVariance J (plusSpin n) i * p j| ≤ + conditionalVariance J (plusSpin n) j * |p i| + + conditionalVariance J (plusSpin n) i * |p j| := by + simpa only [abs_mul, abs_of_pos (conditionalVariance_pos J (plusSpin n) j), + abs_of_pos (conditionalVariance_pos J (plusSpin n) i)] using abs_add_le + (conditionalVariance J (plusSpin n) j * p i) (conditionalVariance J (plusSpin n) i * p j) + have hsquare := pow_le_pow_left₀ (abs_nonneg _) habs 2 + rw [sq_abs] at hsquare + refine (div_le_div_of_nonneg_right hsquare + (add_pos (gradientWeight_pos J (plusSpin n) i) (gradientWeight_pos J (plusSpin n) j)).le).trans ?_ + simpa only [conditionalVariance, mean_weight_plus, mean] using + (scalar_pair_denominator_control + (Real.neg_one_lt_tanh (field J (plusSpin n) i)).le + (Real.tanh_lt_one (field J (plusSpin n) i)) + (Real.neg_one_lt_tanh (field J (plusSpin n) j)).le + (Real.tanh_lt_one (field J (plusSpin n) j)) (pi := p i) (pj := p j)) + have hp := pairSum_le (fun i j (_ : i < j) => + mul_le_mul_of_nonneg_left (hpoint i j) (sq_nonneg (J i j))) + simp only [← mul_assoc] at hp + have hr := mul_le_mul_of_nonneg_left (pair_row_bound J hsymm p 2) + (by norm_num : (0:ℝ) ≤ 32/27) + have hid : pairSum (fun i j => J i j^2 * (32/27) * (p i^2+p j^2)) = + (32/27)*pairSum (fun i j => |J i j|^2 * (p i^2+p j^2)) := by + rw [← pairSum_mul] + unfold pairSum + simp only [sq_abs] + congr 1 + ext i + congr 1 + ext j + ring + rw [hid] at hp + simpa only [mul_div_assoc, mul_assoc] using hp.trans hr + +theorem rough_gradient_bound {n : ℕ} (J : Interaction n) + (hsymm : ∀ i j, J i j = J j i) (hdiag : ∀ i, J i i = 0) (p : Fin n → ℝ) : + gradientForm J p ≤ (euclideanOpNorm J + + (4/(3*Real.sqrt 3)+32/27)*R2 J) * ∑ i, p i^2 := by + have h₁ := gradientForm_linear_bound J hdiag p + have h₂ := gradientForm_quadratic_bound J hsymm p + have h₃ := gradientForm_pairs_bound J hsymm p + unfold gradientForm + linarith only [h₁, h₂, h₃] + +def signedVector {n : ℕ} (x : Spin n) (p : EuclideanSpace ℝ (Fin n)) : + EuclideanSpace ℝ (Fin n) := WithLp.toLp 2 (fun i => spin x i * p.ofLp i) + +@[simp] lemma norm_signedVector {n : ℕ} (x : Spin n) (p : EuclideanSpace ℝ (Fin n)) : + ‖signedVector x p‖ = ‖p‖ := by + apply (sq_eq_sq₀ (norm_nonneg _) (norm_nonneg _)).mp + simp only [EuclideanSpace.real_norm_sq_eq, signedVector, mul_pow, spin_sq, one_mul] + +lemma signConjugate_action {n : ℕ} (J : Interaction n) (x : Spin n) + (p : EuclideanSpace ℝ (Fin n)) : + Matrix.toEuclideanCLM (𝕜 := ℝ) (n := Fin n) (signConjugate x J) p = + signedVector x (Matrix.toEuclideanCLM (𝕜 := ℝ) (n := Fin n) J (signedVector x p)) := by + apply WithLp.ofLp_injective + funext i + change (∑ j, signConjugate x J i j * p.ofLp j) = + spin x i * (∑ j, J i j * (spin x j * p.ofLp j)) + simp only [signConjugate, Finset.mul_sum] + apply Finset.sum_congr rfl + intro j _ + ring + +lemma euclideanOpNorm_signConjugate_le {n : ℕ} (J : Interaction n) (x : Spin n) : + euclideanOpNorm (signConjugate x J) ≤ euclideanOpNorm J := by + apply ContinuousLinearMap.opNorm_le_bound _ (euclideanOpNorm_nonneg J) + intro p + rw [signConjugate_action, norm_signedVector] + simpa only [norm_signedVector, euclideanOpNorm] using + (Matrix.toEuclideanCLM (𝕜 := ℝ) (n := Fin n) J).le_opNorm (signedVector x p) + +@[simp] lemma signConjugate_twice {n : ℕ} (J : Interaction n) (x : Spin n) : + signConjugate x (signConjugate x J) = J := by + funext i j + simp only [signConjugate] + calc + _ = (spin x i)^2 * (spin x j)^2 * J i j := by ring + _ = J i j := by simp only [spin_sq, one_mul] + +@[simp] lemma euclideanOpNorm_signConjugate {n : ℕ} (J : Interaction n) (x : Spin n) : + euclideanOpNorm (signConjugate x J) = euclideanOpNorm J := by + exact le_antisymm (euclideanOpNorm_signConjugate_le J x) + (by simpa only [signConjugate_twice] using euclideanOpNorm_signConjugate_le (signConjugate x J) x) + +theorem gradient_global_bound {n : ℕ} (J : Interaction n) + (hsymm : ∀ i j, J i j = J j i) (hdiag : ∀ i, J i i = 0) + (hsmall : ∀ i j, |J i j| ≤ 1/10) (f : Observables n) (t : ℝ) (x : Spin n) : + deriv (fun s => unweightedGradient (semigroup J s f) x) t - + generator J (unweightedGradient (semigroup J t f)) x ≤ + 2*(-1+euclideanOpNorm J+(4/(3*Real.sqrt 3)+32/27)*R2 J+16*R3 J) * + unweightedGradient (semigroup J t f) x := by + have hlocal := pointwise_gradient_local_bound J hsymm hdiag hsmall f t x + have hform := rough_gradient_bound (signConjugate x J) (signConjugate_symm J hsymm x) + (signConjugate_diag J hdiag x) (fun i => spin x i * halfDiff i (semigroup J t f) x) + simp only [euclideanOpNorm_signConjugate, R2, rowControl_signConjugate, mul_pow, spin_sq, one_mul] at hform + change gradientForm _ _ ≤ _ * unweightedGradient (semigroup J t f) x at hform + linarith only [hlocal, hform] + +lemma rough_coefficient_lt_two : 4/(3*Real.sqrt 3)+32/27 < (2:ℝ) := by + have hs : 0 < Real.sqrt 3 := Real.sqrt_pos.2 (by norm_num) + have hs2 : (Real.sqrt 3)^2 = 3 := Real.sq_sqrt (by norm_num) + have hslo : (18/11:ℝ) < Real.sqrt 3 := by nlinarith only [hs2, hs] + have h : 4/(3*Real.sqrt 3) < (22/27:ℝ) := + (div_lt_iff₀ (by positivity : 0 < 3*Real.sqrt 3)).mpr (by linarith only [hslo]) + linarith only [h] + +theorem gradient_dissipation_small_norm {n : ℕ} (J : Interaction n) + (hsymm : ∀ i j, J i j = J j i) (hdiag : ∀ i, J i i = 0) + (hsmall : ∀ i j, |J i j| ≤ 1/10) + (hop : euclideanOpNorm J ≤ 7/10+1/10000) + (hr2 : R2 J ≤ 49/400+1/10000) (hr3 : R3 J ≤ 1/10000) + (f : Observables n) (t : ℝ) (x : Spin n) : + deriv (fun s => unweightedGradient (semigroup J s f) x) t - + generator J (unweightedGradient (semigroup J t f)) x ≤ + -(1/10:ℝ) * unweightedGradient (semigroup J t f) x := by + have h := gradient_global_bound J hsymm hdiag hsmall f t x + have hc : 2*(-1+euclideanOpNorm J+(4/(3*Real.sqrt 3)+32/27)*R2 J+16*R3 J) ≤ -(1/10:ℝ) := by + have hm := mul_le_mul_of_nonneg_right rough_coefficient_lt_two.le (rowControl_nonneg J 2) + linarith only [hm, hop, hr2, hr3] + exact h.trans (mul_le_mul_of_nonneg_right hc + (Finset.sum_nonneg (fun i _ => sq_nonneg (halfDiff i (semigroup J t f) x)))) + +noncomputable def attemptLM {n : ℕ} (J : Interaction n) : + Observables n →L[ℝ] Observables n := + 1 + (n : ℝ)⁻¹ • generatorCLM J + +noncomputable def continuousKernel {n : ℕ} (J : Interaction n) (t : ℝ) : + Matrix (Spin n) (Spin n) ℝ := fun x y => + semigroup J t (fun z => if z = y then 1 else 0) x + +noncomputable def siteRefresh {n : ℕ} (J : Interaction n) (i : Fin n) + (f : Observables n) (x : Spin n) : ℝ := + ((1 + mean J x i) / 2) * f (replace x i true) + + ((1 - mean J x i) / 2) * f (replace x i false) + +theorem generator_siteRefresh {n : ℕ} (J : Interaction n) (f : Observables n) + (x : Spin n) : generator J f x = ∑ i, (siteRefresh J i f x - f x) := by + apply Finset.sum_congr rfl + intro i _ + have hx : replace x i (x i) = x := replace_self x i + cases hi : x i <;> simp only [hi] at hx + · simp only [halfDiff, spin, hi, Bool.false_eq_true, ↓reduceIte, siteRefresh] + rw [hx] + ring + · simp only [halfDiff, spin, hi, ↓reduceIte, siteRefresh] + rw [hx] + ring + +theorem attempt_apply_of_pos {n : ℕ} (hn : 0 < n) (J : Interaction n) + (f : Observables n) (x : Spin n) : + attemptLM J f x = (∑ i, siteRefresh J i f x) / (n : ℝ) := by + have hn' : (n : ℝ) ≠ 0 := by exact_mod_cast ne_of_gt hn + change f x + (n : ℝ)⁻¹ * generator J f x = _ + rw [generator_siteRefresh, Finset.sum_sub_distrib] + simp only [Finset.sum_const, Finset.card_univ, Fintype.card_fin, nsmul_eq_mul] + field_simp + ring + +@[simp] theorem generator_const {n : ℕ} (J : Interaction n) (a : ℝ) (x : Spin n) : + generator J (fun _ => a) x = 0 := by + simp [generator] + +@[simp] theorem siteRefresh_const {n : ℕ} (J : Interaction n) (i : Fin n) + (a : ℝ) (x : Spin n) : siteRefresh J i (fun _ => a) x = a := by + unfold siteRefresh + ring + +@[simp] theorem attempt_const {n : ℕ} (J : Interaction n) (a : ℝ) : + attemptLM J (fun _ => a) = fun _ => a := by + funext x + change a + (n : ℝ)⁻¹ * generator J (fun _ => a) x = a + simp + +@[simp] theorem attempt_pow_const {n : ℕ} (J : Interaction n) (k : ℕ) (a : ℝ) : + (attemptLM J ^ k) (fun _ => a) = fun _ => a := by + induction k with + | zero => simp + | succ k ih => simp only [pow_succ', mul_apply_eq_comp, ih, attempt_const] + +theorem siteRefresh_nonneg {n : ℕ} (J : Interaction n) (i : Fin n) + (f : Observables n) (hf : ∀ x, 0 ≤ f x) (x : Spin n) : + 0 ≤ siteRefresh J i f x := by + have hm1 : -1 ≤ mean J x i := le_of_lt (Real.neg_one_lt_tanh _) + have hm2 : mean J x i ≤ 1 := le_of_lt (Real.tanh_lt_one _) + exact add_nonneg (mul_nonneg (by linarith) (hf _)) + (mul_nonneg (by linarith) (hf _)) + +theorem attempt_nonneg {n : ℕ} (J : Interaction n) (f : Observables n) + (hf : ∀ x, 0 ≤ f x) (x : Spin n) : 0 ≤ attemptLM J f x := by + by_cases hn : n = 0 + · subst n + simpa [attemptLM] using hf x + · rw [attempt_apply_of_pos (Nat.pos_of_ne_zero hn)] + exact div_nonneg (Finset.sum_nonneg (fun _ _ => siteRefresh_nonneg J _ f hf x)) + (Nat.cast_nonneg n) + +theorem attempt_pow_nonneg {n : ℕ} (J : Interaction n) (k : ℕ) (f : Observables n) + (hf : ∀ x, 0 ≤ f x) (x : Spin n) : 0 ≤ (attemptLM J ^ k) f x := by + induction k generalizing x with + | zero => simpa using hf x + | succ k ih => + simp only [pow_succ', mul_apply_eq_comp] + exact attempt_nonneg J _ ih x + +theorem exp_apply_hasSum {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] + [CompleteSpace E] (A : E →L[ℝ] E) (f : E) : + HasSum (fun k : ℕ => (k.factorial : ℝ)⁻¹ • ((A ^ k) f)) + (NormedSpace.exp A f) := by + simpa only [NormedSpace.expSeries_apply_eq, ContinuousLinearMap.apply_apply, + smul_apply] using + (ContinuousLinearMap.apply ℝ E f).hasSum + (NormedSpace.expSeries_hasSum_exp (𝕂 := ℝ) A) + +theorem exp_apply_of_apply_eq_zero {E : Type*} [NormedAddCommGroup E] + [NormedSpace ℝ E] [CompleteSpace E] (A : E →L[ℝ] E) (f : E) + (h : A f = 0) : NormedSpace.exp A f = f := by + have hp (k : ℕ) : (A ^ (k + 1)) f = 0 := by + induction k with + | zero => simpa using h + | succ k ih => rw [pow_succ', mul_apply_eq_comp, ih, map_zero] + have hs : HasSum (fun k : ℕ => (k.factorial : ℝ)⁻¹ • ((A ^ k) f)) f := by + convert hasSum_ite_eq 0 f using 1 + funext k + cases k with + | zero => simp + | succ k => simp [hp] + exact (exp_apply_hasSum A f).unique hs + +@[simp] theorem semigroup_const {n : ℕ} (J : Interaction n) (t a : ℝ) : + semigroup J t (fun _ => a) = fun _ => a := by + apply exp_apply_of_apply_eq_zero + funext x + change t * generator J (fun _ => a) x = 0 + simp + +theorem exp_smul_identity {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] + [CompleteSpace E] (a : ℝ) : + NormedSpace.exp (a • (1 : E →L[ℝ] E)) = Real.exp a • (1 : E →L[ℝ] E) := by + simpa only [Algebra.algebraMap_eq_smul_one, ← Real.exp_eq_exp_ℝ] using + (NormedSpace.algebraMap_exp_comm (𝔸 := E →L[ℝ] E) a).symm + +theorem semigroup_uniformization {n : ℕ} (hn : 0 < n) (J : Interaction n) (t : ℝ) : + semigroup J t = Real.exp (-(n : ℝ) * t) • + NormedSpace.exp (((n : ℝ) * t) • attemptLM J) := by + have hn' : (n : ℝ) ≠ 0 := by exact_mod_cast ne_of_gt hn + have heq : t • generatorCLM J = + (-(n : ℝ) * t) • (1 : Observables n →L[ℝ] Observables n) + + ((n : ℝ) * t) • attemptLM J := by + unfold attemptLM + simp only [smul_add, smul_smul] + have hc : ((n : ℝ) * t) * (n : ℝ)⁻¹ = t := by field_simp + rw [hc] + module + let : NormedAlgebra ℚ (Observables n →L[ℝ] Observables n) := + NormedAlgebra.restrictScalars ℚ ℝ _ + unfold semigroup + rw [heq, NormedSpace.exp_add_of_commute + (((Commute.one_left (attemptLM J)).smul_left _).smul_right _), + exp_smul_identity, smul_mul_assoc, one_mul] + +theorem semigroup_nonneg {n : ℕ} (J : Interaction n) (t : ℝ) (ht : 0 ≤ t) + (f : Observables n) (hf : ∀ x, 0 ≤ f x) (x : Spin n) : + 0 ≤ semigroup J t f x := by + by_cases hn : n = 0 + · subst n + have hL : generatorCLM J = 0 := by + ext f x + simp [generatorCLM, generatorLM, generator] + simp only [semigroup, hL, smul_zero, NormedSpace.exp_zero, + one_apply_eq_self] + exact hf x + · rw [semigroup_uniformization (Nat.pos_of_ne_zero hn)] + simp only [smul_apply, Pi.smul_apply, smul_eq_mul] + apply mul_nonneg (le_of_lt (Real.exp_pos _)) + have hs := Pi.hasSum.mp (exp_apply_hasSum (((n : ℝ) * t) • attemptLM J) f) x + apply HasSum.nonneg _ hs + intro k + simp only [smul_pow, smul_apply, Pi.smul_apply, smul_eq_mul] + exact mul_nonneg (inv_nonneg.mpr (Nat.cast_nonneg _)) + (mul_nonneg (pow_nonneg (mul_nonneg (Nat.cast_nonneg _) ht) _) + (attempt_pow_nonneg J k f hf x)) + +theorem continuousKernel_nonneg {n : ℕ} (J : Interaction n) (t : ℝ) (ht : 0 ≤ t) + (x y : Spin n) : 0 ≤ continuousKernel J t x y := by + exact semigroup_nonneg J t ht _ (fun _ => by split_ifs <;> norm_num) x + +theorem continuousKernel_sum {n : ℕ} (J : Interaction n) (t : ℝ) (x : Spin n) : + ∑ y, continuousKernel J t x y = 1 := by + have eq_one : (∑ y : Spin n, fun z => if z = y then (1 : ℝ) else 0) = + fun _ : Spin n => (1 : ℝ) := by + funext z + simp + unfold continuousKernel + rw [← Finset.sum_apply, ← map_sum, eq_one, semigroup_const] + +theorem attempt_eq_transition {n : ℕ} (g : Disorder n) (f : Observables n) : + attemptLM (coupling g) f = transition g *ᵥ f := by + funext x + by_cases hn : n = 0 + · subst n + simp [attemptLM, transition] + have hn' : (n : ℝ) ≠ 0 := Nat.cast_ne_zero.mpr hn + change f x + (n : ℝ)⁻¹ * generator (coupling g) f x = _ + rw [generator_eq_transition] + simp only [← mul_assoc, inv_mul_cancel₀ hn', one_mul] + change f x + ((transition g *ᵥ f) x - f x) = (transition g *ᵥ f) x + ring + +theorem attempt_pow_eq_transition_pow {n : ℕ} (g : Disorder n) (k : ℕ) + (f : Observables n) : (attemptLM (coupling g)^k) f = transition g^k *ᵥ f := by + induction k with + | zero => simp + | succ k ih => + rw [pow_succ', pow_succ', mul_apply_eq_comp, ih, attempt_eq_transition, + Matrix.mulVec_mulVec] + +theorem semigroup_add {n : ℕ} (J : Interaction n) (s t : ℝ) : + semigroup J (s+t) = semigroup J s * semigroup J t := by + let : NormedAlgebra ℚ (Observables n →L[ℝ] Observables n) := + NormedAlgebra.restrictScalars ℚ ℝ _ + unfold semigroup + rw [add_smul, NormedSpace.exp_add_of_commute + (((Commute.refl (generatorCLM J)).smul_left _).smul_right _)] + +theorem semigroup_mono {n : ℕ} (J : Interaction n) {t : ℝ} (ht : 0 ≤ t) + (f h : Observables n) (hfh : ∀ x, f x ≤ h x) (x : Spin n) : + semigroup J t f x ≤ semigroup J t h x := by + have hn := semigroup_nonneg J t ht (h-f) (fun x => sub_nonneg.mpr (hfh x)) x + simpa only [map_sub, Pi.sub_apply, sub_nonneg] using hn + +theorem semigroup_abs_le {n : ℕ} (J : Interaction n) {t : ℝ} (ht : 0 ≤ t) + (f : Observables n) {B : ℝ} (hf : ∀ x, |f x| ≤ B) (x : Spin n) : + |semigroup J t f x| ≤ B := by + have hu := semigroup_mono J ht f (fun _ => B) (fun x => (abs_le.mp (hf x)).2) x + have hl := semigroup_mono J ht (fun _ => -B) f (fun x => (abs_le.mp (hf x)).1) x + simp only [semigroup_const] at hu hl + exact abs_le.mpr ⟨hl,hu⟩ + +theorem observable_basis {n : ℕ} (f : Observables n) : + f = ∑ y : Spin n, f y • (fun z => if z = y then (1:ℝ) else 0) := by + funext x + simp + +theorem semigroup_eq_kernel {n : ℕ} (J : Interaction n) (t : ℝ) + (f : Observables n) (x : Spin n) : + semigroup J t f x = FiniteLaw.mean (continuousKernel J t x) f := by + conv_lhs => rw [observable_basis f] + simp only [map_sum, map_smul, Finset.sum_apply, Pi.smul_apply, smul_eq_mul, + FiniteLaw.mean, continuousKernel] + exact Finset.sum_congr rfl (fun _ _ => mul_comm _ _) + +theorem kernel_eq_mulVec {n : ℕ} (J : Interaction n) (t : ℝ) + (f : Observables n) : semigroup J t f = continuousKernel J t *ᵥ f := by + funext x + exact semigroup_eq_kernel J t f x + +theorem continuousKernel_add {n : ℕ} (J : Interaction n) (s t : ℝ) : + continuousKernel J (s+t) = + (continuousKernel J s : Matrix (Spin n) (Spin n) ℝ) * continuousKernel J t := by + funext x y + unfold continuousKernel + rw [semigroup_add, mul_apply_eq_comp, semigroup_eq_kernel] + rfl + +theorem continuousKernel_poisson_hasSum {n : ℕ} (hn : 0 < n) (g : Disorder n) + (t : ℝ) (x y : Spin n) : + HasSum (fun k : ℕ => Real.exp (-(n:ℝ)*t) * ((n:ℝ)*t)^k / + (k.factorial:ℝ) * (transition g^k) x y) + (continuousKernel (coupling g) t x y) := by + have hs := (Pi.hasSum.mp (exp_apply_hasSum (((n:ℝ)*t) • attemptLM (coupling g)) + (fun z => if z = y then (1:ℝ) else 0)) x).mul_left (Real.exp (-(n:ℝ)*t)) + simp only [smul_pow, smul_apply, Pi.smul_apply, smul_eq_mul, + attempt_pow_eq_transition_pow, Matrix.mulVec, dotProduct, + mul_ite, mul_one, mul_zero, Fintype.sum_ite_eq'] at hs + rw [continuousKernel, semigroup_uniformization hn] + have heq : (fun k : ℕ => Real.exp (-(n:ℝ)*t) * ((n:ℝ)*t)^k / + (k.factorial:ℝ) * (transition g^k) x y) = + (fun k : ℕ => Real.exp (-(n:ℝ)*t) * ((k.factorial:ℝ)⁻¹ * + (((n:ℝ)*t)^k * (transition g^k) x y))) := by + funext k + ring + rw [heq] + exact hs + +end SKRatio.Calculus +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Calculus/SmallTemperature.lean b/lean/OAI/Probability/SKRatio/Calculus/SmallTemperature.lean new file mode 100644 index 0000000000000000000000000000000000000000..a4e763720d4f0266257ef83a21c57d78d0387421 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Calculus/SmallTemperature.lean @@ -0,0 +1,100 @@ +import Mathlib +import OAI.Probability.SKRatio.Gaussian.GaussianEvents +import OAI.Probability.SKRatio.Variational.UniformDrift + +namespace OAI + +section +noncomputable section +open scoped BigOperators Topology Matrix +open MeasureTheory Filter +namespace SKRatio.Calculus +attribute [local instance] Classical.propDecidable + +lemma rowControl_le {n : ℕ} (J : Interaction n) (k : ℕ) {B : ℝ} + (hB : 0 ≤ B) (h : ∀ i, ∑ j, |J i j|^k ≤ B) : rowControl J k ≤ B := by + change ((Finset.univ.sup (fun i => ∑ j, ‖J i j‖₊^k) : NNReal) : ℝ) ≤ B + apply (NNReal.coe_le_coe (r₂ := ⟨B,hB⟩)).mpr + apply Finset.sup_le + intro i _ + have hh : ((∑ j, ‖J i j‖₊^k : NNReal) : ℝ) ≤ B := by + simpa only [NNReal.coe_sum,NNReal.coe_pow,coe_nnnorm,Real.norm_eq_abs] using h i + exact hh + +lemma R3_le_entry_times_row {n : ℕ} (J : Interaction n) {δ B : ℝ} + (hδ : 0 ≤ δ) (hB : 0 ≤ B) + (he : ∀ i j, |J i j| ≤ δ) (hrow : ∀ i, ∑ j, J i j^2 ≤ B) : + R3 J ≤ δ*B := by + apply rowControl_le J 3 (mul_nonneg hδ hB) + intro i + calc + _ ≤ ∑ j, δ*(J i j)^2 := by + apply Finset.sum_le_sum + intro j _ + calc + _ = |J i j| *(J i j)^2 := by rw [pow_succ,sq_abs];ring + _ ≤ _ := mul_le_mul_of_nonneg_right (he i j) (sq_nonneg _) + _ = δ*(∑ j, J i j^2) := (Finset.mul_sum ..).symm + _ ≤ _ := mul_le_mul_of_nonneg_left (hrow i) hδ + +theorem uniform_gradient_small_temperature {β δ : ℝ} + (hβ : 0 ≤ β) (hβsmall : β ≤ 7/20) (hδ : 0 ≤ δ) (hδsmall : δ ≤ 1/10000) + {n : ℕ} (g : Disorder n) (hg : g ∈ Gaussian.matrixGood β δ n) + (f : Observables n) (r : ℝ) (y : Spin n) : + deriv (fun v => unweightedGradient (semigroup (coupling g) v f) y) r - + generator (coupling g) (unweightedGradient (semigroup (coupling g) r f)) y ≤ + -(1/10:ℝ)*unweightedGradient (semigroup (coupling g) r f) y := by + have hb2 : β^2 ≤ 49/400 := by + nlinarith [mul_nonneg hβ (sub_nonneg.mpr hβsmall)] + have hrow (i : Fin n) : ∑ j, coupling g i j^2 ≤ 1 := (hg.2.2 i).trans (by linarith) + apply gradient_dissipation_small_norm (coupling g) (coupling_symm g) (coupling_diag g) + · intro i j + exact (hg.2.1 i j).trans (by linarith) + · exact hg.1.trans (by linarith) + · apply rowControl_le _ 2 (by norm_num) + intro i + simpa only [sq_abs] using (hg.2.2 i).trans (by linarith : β^2+δ ≤ 49/400+1/10000) + · exact (R3_le_entry_times_row (coupling g) hδ (by norm_num : (0:ℝ) ≤ 1) + hg.2.1 hrow).trans (by simpa only [mul_one] using hδsmall) + +end SKRatio.Calculus + +namespace SKRatio +open Calculus + +theorem ratio_cutoff_small_temperature (β ε η : ℝ) + (hβ0 : 0 ≤ β) (hβsmall : β ≤ 7/20) + (hε0 : 0 < ε) (hεhalf : ε < 1/2) (hη : 0 < η) : + Tendsto + (fun n : ℕ => disorderLaw β n + {g : Disorder n | 1+η < + (mixingTime g ε : ℝ)/(mixingTime g (1-ε) : ℝ)}) + atTop (𝓝 0) ∧ + (∀ᶠ n : ℕ in atTop, ∀ g : Disorder n, 0 < mixingTime g (1-ε)) := by + obtain ⟨δ,γ,hd,hγ,hgap⟩ := Fields.exists_uniform_gap_tolerance hβ0 (by linarith : β < 1/2) + let d := min δ (1/10000:ℝ) + have hdp : 0 < d := lt_min hd (by norm_num) + have hdδ : d ≤ δ := min_le_left _ _ + have hds : d ≤ 1/10000 := min_le_right _ _ + let G := Gaussian.matrixGood β d + have hnorm : ∀ n, ∀ g ∈ G n, euclideanOpNorm (coupling g) ≤ 1 := by + intro n g hg + exact hg.1.trans (by linarith) + have hgp (n : ℕ) (g : Disorder n) (hg : g ∈ G n) (f : Observables n) : + γ*FiniteLaw.variance (mass g 0) f ≤ stationaryEnergy g f := by + have h := (hgap n g (hg.1.trans (by linarith)) + (fun i j => (hg.2.1 i j).trans hdδ) + (fun i => (hg.2.2 i).trans (by linarith)) 1 ⟨by norm_num,le_rfl⟩ 0).1 f + simpa only [one_smul,Fields.variance_eq_finiteLaw,Fields.dirichlet_zero_eq_stationaryEnergy] using h + apply ratio_cutoff_of_uniform_gradient β ε η hε0 (by linarith) hη G + (by norm_num : (0:ℝ) < 1/10) hγ (by norm_num : (0:ℝ) < 1) + (Gaussian.matrixGood_probability hβ0 hdp) hnorm hgp + intro n g hg f r y + exact uniform_gradient_small_temperature hβ0 hβsmall hdp.le hds g hg f r y + +end SKRatio + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Calculus/SpectralLower.lean b/lean/OAI/Probability/SKRatio/Calculus/SpectralLower.lean new file mode 100644 index 0000000000000000000000000000000000000000..e8626e3400f49c8ed0278c6a1ebd8a114afbacb9 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Calculus/SpectralLower.lean @@ -0,0 +1,547 @@ +import Mathlib +import OAI.Probability.SKRatio.Dynamics.Median +import OAI.Probability.SKRatio.Calculus.GradientMoments + +namespace OAI + +section +noncomputable section +open scoped BigOperators Topology Matrix +open ContinuousLinearMap MeasureTheory Filter + +namespace SKRatio.Calculus +attribute [local instance] Classical.propDecidable + +lemma transition_balance {n : ℕ} (g : Disorder n) (x y : Spin n) : + mass g 0 x * transition g x y = mass g 0 y * transition g y x := by + by_cases hn : n = 0 + · simp only [transition, hn, ↓reduceIte, Matrix.one_apply] + by_cases h : x = y + · subst y + simp + · simp [h, Ne.symm h] + · simp only [transition, hn, ↓reduceIte, mul_div, Finset.mul_sum] + simp_rw [siteKernel_balance g _ x y] + +def stationaryInner {n : ℕ} (g : Disorder n) (f h : Observables n) : ℝ := + FiniteLaw.mean (mass g 0) (fun x => f x*h x) + +def stationaryPairingCLM {n : ℕ} (g : Disorder n) (f : Observables n) : + Observables n →L[ℝ] ℝ := + (show Observables n →ₗ[ℝ] ℝ from + { toFun := stationaryInner g f + map_add' a b := by + simp [stationaryInner, FiniteLaw.mean, mul_add, Finset.sum_add_distrib] + map_smul' c a := by + simp [stationaryInner, FiniteLaw.mean, mul_left_comm, ← Finset.mul_sum] + }).toContinuousLinearMap + +@[simp] lemma stationaryPairingCLM_apply {n : ℕ} (g : Disorder n) (f h : Observables n) : + stationaryPairingCLM g f h = stationaryInner g f h := rfl + +lemma stationaryInner_symm {n : ℕ} (g : Disorder n) (f h : Observables n) : + stationaryInner g f h = stationaryInner g h f := by + simp only [stationaryInner, mul_comm (f _) (h _)] + +lemma generator_symmetric {n : ℕ} (g : Disorder n) (f h : Observables n) : + stationaryInner g f (generator (coupling g) h) = + stationaryInner g (generator (coupling g) f) h := by + have hpair : (∑ x, ∑ y, mass g 0 x * transition g x y * f x * h y) = + ∑ y, ∑ x, mass g 0 y * transition g y x * f x * h y := by + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro y _ + apply Finset.sum_congr rfl + intro x _ + rw [transition_balance] + unfold stationaryInner FiniteLaw.mean + simp only [generator_eq_transition, mul_sub, sub_mul, Finset.sum_sub_distrib, + Finset.mul_sum, Finset.sum_mul] + have he (x : Spin n) (y : Spin n) : + mass g 0 x * (f x * ((n:ℝ)*(transition g x y*h y))) = + (n:ℝ)*(mass g 0 x*transition g x y*f x*h y) := by ring + have he' (y : Spin n) (x : Spin n) : + mass g 0 y * (((n:ℝ)*(transition g y x*f x))*h y) = + (n:ℝ)*(mass g 0 y*transition g y x*f x*h y) := by ring + simp_rw [he,he',← Finset.mul_sum,hpair] + congr 1 + apply Finset.sum_congr rfl + intro x _ + ring + +lemma stationaryInner_pow_symm {n : ℕ} (g : Disorder n) + (A : Observables n →L[ℝ] Observables n) + (hA : ∀ f h, stationaryInner g f (A h) = stationaryInner g (A f) h) + (k : ℕ) (f h : Observables n) : + stationaryInner g f ((A^k) h) = stationaryInner g ((A^k) f) h := by + induction k generalizing f h with + | zero => simp + | succ k ih => + calc + _ = stationaryInner g (A f) ((A^k) h) := by + rw [pow_succ', mul_apply_eq_comp, hA] + _ = stationaryInner g ((A^k) (A f)) h := ih (A f) h + _ = _ := by rw [pow_succ, mul_apply_eq_comp] + +lemma stationaryInner_exp_symm {n : ℕ} (g : Disorder n) + (A : Observables n →L[ℝ] Observables n) + (hA : ∀ f h, stationaryInner g f (A h) = stationaryInner g (A f) h) + (f h : Observables n) : + stationaryInner g f (NormedSpace.exp A h) = stationaryInner g (NormedSpace.exp A f) h := by + have hf : HasSum (fun k : ℕ => ((k.factorial:ℝ)⁻¹)*stationaryInner g f ((A^k) h)) + (stationaryInner g f (NormedSpace.exp A h)) := by + simpa only [map_smul,smul_eq_mul,stationaryPairingCLM_apply] using + (stationaryPairingCLM g f).hasSum (exp_apply_hasSum A h) + have hh : HasSum (fun k : ℕ => ((k.factorial:ℝ)⁻¹)*stationaryInner g h ((A^k) f)) + (stationaryInner g h (NormedSpace.exp A f)) := by + simpa only [map_smul,smul_eq_mul,stationaryPairingCLM_apply] using + (stationaryPairingCLM g h).hasSum (exp_apply_hasSum A f) + have hp (k : ℕ) : stationaryInner g f ((A^k) h) = stationaryInner g h ((A^k) f) := by + rw [stationaryInner_pow_symm g A hA,stationaryInner_symm] + simp_rw [hp] at hf + rw [← stationaryInner_symm g h] + exact hf.unique hh + +lemma semigroup_symmetric {n : ℕ} (g : Disorder n) (t : ℝ) (f h : Observables n) : + stationaryInner g f (semigroup (coupling g) t h) = + stationaryInner g (semigroup (coupling g) t f) h := by + apply stationaryInner_exp_symm + intro a b + have he := congrArg (fun z : ℝ => t*z) (generator_symmetric g a b) + change (∑ x, mass g 0 x*(a x*(t*generator (coupling g) b x))) = + ∑ x, mass g 0 x*((t*generator (coupling g) a x)*b x) + convert he using 1 <;> simp only [stationaryInner,FiniteLaw.mean,Finset.mul_sum] <;> + apply Finset.sum_congr rfl <;> intro x _ <;> ring + +lemma exp_apply_of_eigenvector {E : Type*} [NormedAddCommGroup E] + [NormedSpace ℝ E] [CompleteSpace E] (A : E →L[ℝ] E) (f : E) (a : ℝ) + (h : A f = a • f) : NormedSpace.exp A f = Real.exp a • f := by + have hp (k : ℕ) : (A^k) f = a^k • f := by + induction k with + | zero => simp + | succ k ih => + rw [pow_succ',mul_apply_eq_comp,ih,map_smul,h,smul_smul,pow_succ] + have hs : HasSum (fun k : ℕ => (k.factorial:ℝ)⁻¹*a^k) (Real.exp a) := by + simpa only [smul_eq_mul,Real.exp_eq_exp_ℝ] using + (NormedSpace.exp_series_hasSum_exp' (𝕂 := ℝ) a) + apply (exp_apply_hasSum A f).unique + simpa only [hp,smul_smul] using hs.smul_const f + +def gibbsEuclideanEquiv {n : ℕ} (g : Disorder n) : + Observables n ≃ₗ[ℝ] EuclideanSpace ℝ (Spin n) where + toFun f := WithLp.toLp 2 (fun x => Real.sqrt (mass g 0 x)*f x) + invFun u x := u x/Real.sqrt (mass g 0 x) + left_inv f := by + funext x + exact mul_div_cancel_left₀ (f x) (ne_of_gt (Real.sqrt_pos.2 (mass_pos g 0 x))) + right_inv u := by + ext x + exact mul_div_cancel₀ (u x) (ne_of_gt (Real.sqrt_pos.2 (mass_pos g 0 x))) + map_add' f h := by ext x; simp [mul_add] + map_smul' a f := by ext x; simp [mul_left_comm] + +@[simp] lemma gibbsEuclideanEquiv_apply {n : ℕ} (g : Disorder n) (f : Observables n) (x : Spin n) : + gibbsEuclideanEquiv g f x = Real.sqrt (mass g 0 x)*f x := rfl + +lemma gibbsEuclideanEquiv_inner {n : ℕ} (g : Disorder n) (f h : Observables n) : + inner (𝕜 := ℝ) (gibbsEuclideanEquiv g f) (gibbsEuclideanEquiv g h) = stationaryInner g f h := by + rw [PiLp.inner_apply] + unfold stationaryInner FiniteLaw.mean + apply Finset.sum_congr rfl + intro x _ + simp only [gibbsEuclideanEquiv_apply,RCLike.inner_apply,conj_trivial] + nlinarith only [congrArg (fun a : ℝ => a*f x*h x) (Real.sq_sqrt (mass_nonneg g 0 x))] + +def negativeGeneratorEuclidean {n : ℕ} (g : Disorder n) : + EuclideanSpace ℝ (Spin n) →ₗ[ℝ] EuclideanSpace ℝ (Spin n) := + (gibbsEuclideanEquiv g).toLinearMap.comp + ((-generatorLM (coupling g)).comp (gibbsEuclideanEquiv g).symm.toLinearMap) + +lemma negativeGeneratorEuclidean_lift {n : ℕ} (g : Disorder n) (f : Observables n) : + negativeGeneratorEuclidean g (gibbsEuclideanEquiv g f) = + gibbsEuclideanEquiv g (-generator (coupling g) f) := by + simp [negativeGeneratorEuclidean,generatorLM] + +lemma negativeGeneratorEuclidean_symmetric {n : ℕ} (g : Disorder n) : + (negativeGeneratorEuclidean g).IsSymmetric := by + intro u v + obtain ⟨f,rfl⟩ := (gibbsEuclideanEquiv g).surjective u + obtain ⟨h,rfl⟩ := (gibbsEuclideanEquiv g).surjective v + rw [negativeGeneratorEuclidean_lift,negativeGeneratorEuclidean_lift, + gibbsEuclideanEquiv_inner,gibbsEuclideanEquiv_inner] + have he := generator_symmetric g f h + simp only [stationaryInner,FiniteLaw.mean] at he ⊢ + simpa only [Pi.neg_apply,neg_mul,mul_neg,Finset.sum_neg_distrib] using congrArg Neg.neg he.symm + +def spinEigenvalues {n : ℕ} (g : Disorder n) : Fin (Fintype.card (Spin n)) → ℝ := + (negativeGeneratorEuclidean_symmetric g).eigenvalues finrank_euclideanSpace + +def spinEigenbasis {n : ℕ} (g : Disorder n) : + OrthonormalBasis (Fin (Fintype.card (Spin n))) ℝ (EuclideanSpace ℝ (Spin n)) := + (negativeGeneratorEuclidean_symmetric g).eigenvectorBasis finrank_euclideanSpace + +def spectralCoefficient {n : ℕ} (g : Disorder n) (f : Observables n) + (a : Fin (Fintype.card (Spin n))) : ℝ := + (spinEigenbasis g).repr (gibbsEuclideanEquiv g f) a + +lemma spectral_parseval {n : ℕ} (g : Disorder n) (f h : Observables n) : + (∑ a, spectralCoefficient g f a*spectralCoefficient g h a) = stationaryInner g f h := by + have he := (spinEigenbasis g).repr.inner_map_map (gibbsEuclideanEquiv g f) (gibbsEuclideanEquiv g h) + rw [PiLp.inner_apply,gibbsEuclideanEquiv_inner] at he + simpa only [spectralCoefficient,RCLike.inner_apply,conj_trivial,mul_comm] using he + +lemma spectral_generator_coordinates {n : ℕ} (g : Disorder n) (f : Observables n) + (a : Fin (Fintype.card (Spin n))) : + spectralCoefficient g (-generator (coupling g) f) a = spinEigenvalues g a*spectralCoefficient g f a := by + unfold spectralCoefficient + rw [← negativeGeneratorEuclidean_lift] + exact (negativeGeneratorEuclidean_symmetric g).eigenvectorBasis_apply_self_apply + finrank_euclideanSpace (gibbsEuclideanEquiv g f) a + +def scalarEigenfunction {n : ℕ} (g : Disorder n) (a : Fin (Fintype.card (Spin n))) : Observables n := + (gibbsEuclideanEquiv g).symm (spinEigenbasis g a) + +@[simp] lemma lift_scalarEigenfunction {n : ℕ} (g : Disorder n) (a : Fin (Fintype.card (Spin n))) : + gibbsEuclideanEquiv g (scalarEigenfunction g a) = spinEigenbasis g a := + (gibbsEuclideanEquiv g).apply_symm_apply _ + +lemma generator_scalarEigenfunction {n : ℕ} (g : Disorder n) (a : Fin (Fintype.card (Spin n))) : + generator (coupling g) (scalarEigenfunction g a) = -spinEigenvalues g a • scalarEigenfunction g a := by + have he : negativeGeneratorEuclidean g (spinEigenbasis g a) = spinEigenvalues g a • spinEigenbasis g a := + (negativeGeneratorEuclidean_symmetric g).apply_eigenvectorBasis finrank_euclideanSpace a + have hf : -generator (coupling g) (scalarEigenfunction g a) = spinEigenvalues g a • scalarEigenfunction g a := by + apply (gibbsEuclideanEquiv g).injective + rw [← negativeGeneratorEuclidean_lift,map_smul,lift_scalarEigenfunction] + exact he + simpa only [neg_neg,neg_smul] using congrArg Neg.neg hf + +lemma semigroup_scalarEigenfunction {n : ℕ} (g : Disorder n) (a : Fin (Fintype.card (Spin n))) (t : ℝ) : + semigroup (coupling g) t (scalarEigenfunction g a) = + Real.exp (-spinEigenvalues g a*t) • scalarEigenfunction g a := by + apply exp_apply_of_eigenvector + rw [smul_apply] + change t • generator (coupling g) (scalarEigenfunction g a) = _ + rw [generator_scalarEigenfunction,smul_smul,mul_comm] + +lemma spectral_coordinates_inner {n : ℕ} (g : Disorder n) (f : Observables n) + (a : Fin (Fintype.card (Spin n))) : + spectralCoefficient g f a = stationaryInner g (scalarEigenfunction g a) f := by + rw [spectralCoefficient,OrthonormalBasis.repr_apply_apply,← lift_scalarEigenfunction g a, + gibbsEuclideanEquiv_inner] + +lemma spectral_semigroup_coordinates {n : ℕ} (g : Disorder n) (f : Observables n) (t : ℝ) + (a : Fin (Fintype.card (Spin n))) : + spectralCoefficient g (semigroup (coupling g) t f) a = + Real.exp (-spinEigenvalues g a*t)*spectralCoefficient g f a := by + rw [spectral_coordinates_inner,spectral_coordinates_inner,semigroup_symmetric,semigroup_scalarEigenfunction] + simp only [stationaryInner,FiniteLaw.mean,Pi.smul_apply,smul_eq_mul,Finset.mul_sum] + apply Finset.sum_congr rfl + intro x _ + ring + +lemma stationary_correlation_lower {n : ℕ} (g : Disorder n) (f : Observables n) + (hnorm : stationaryInner g f f = 1) (t : ℝ) : + Real.exp (-t*stationaryEnergy g f) ≤ stationaryInner g f (semigroup (coupling g) t f) := by + have hsum : (∑ a, spectralCoefficient g f a^2) = 1 := by + simpa only [pow_two,hnorm] using spectral_parseval g f f + have hE : (∑ a, spectralCoefficient g f a^2*spinEigenvalues g a) = stationaryEnergy g f := by + have he := spectral_parseval g f (-generator (coupling g) f) + simp only [spectral_generator_coordinates] at he + rw [stationaryEnergy_eq] + change _ = -(∑ x, mass g 0 x * (f x * generator (coupling g) f x)) + have hinner : stationaryInner g f (-generator (coupling g) f) = + -(∑ x, mass g 0 x * (f x * generator (coupling g) f x)) := by + simp [stationaryInner,FiniteLaw.mean] + rw [← hinner,← he] + apply Finset.sum_congr rfl + intro a _ + ring + have he := convexOn_exp.map_sum_le (s := Set.univ) (p := fun a => -t*spinEigenvalues g a) + (fun a (_ : a ∈ Finset.univ) => sq_nonneg (spectralCoefficient g f a)) hsum (fun _ _ => Set.mem_univ _) + simp only [smul_eq_mul] at he + have hl : (∑ a, spectralCoefficient g f a^2*(-t*spinEigenvalues g a)) = -t*stationaryEnergy g f := by + rw [← hE,Finset.mul_sum] + apply Finset.sum_congr rfl + intro a _ + ring + rw [hl] at he + rw [← spectral_parseval] + simp_rw [spectral_semigroup_coordinates] + calc + _ ≤ ∑ a, spectralCoefficient g f a ^ 2 * Real.exp (-t * spinEigenvalues g a) := he + _ = _ := by + apply Finset.sum_congr rfl + intro a _ + rw [show -spinEigenvalues g a * t = -t * spinEigenvalues g a by ring] + ring + +lemma gibbsMean_siteKernel {n : ℕ} (g : Disorder n) (i : Fin n) (f : Observables n) : + FiniteLaw.mean (mass g 0) (fun x => ∑ y, siteKernel g i x y * f y) = + FiniteLaw.mean (mass g 0) f := by + unfold FiniteLaw.mean + simp only [Finset.mul_sum, ← mul_assoc] + rw [Finset.sum_comm] + simp_rw [← Finset.sum_mul, siteKernel_stationary] + +lemma gibbsMean_spin_times_mean {n : ℕ} (g : Disorder n) (i : Fin n) : + FiniteLaw.mean (mass g 0) (fun x => spin x i * mean (coupling g) x i) = + FiniteLaw.mean (mass g 0) (fun x => mean (coupling g) x i ^ 2) := by + have hpoint (x : Spin n) : (∑ y, siteKernel g i x y * + (spin y i * mean (coupling g) y i)) = mean (coupling g) x i ^ 2 := by + rw [siteKernel_apply, spin_flip_self] + have hm : mean (coupling g) (flip i x) i = mean (coupling g) x i := by + simp only [mean, field_flip _ (coupling_diag g)] + rw [hm, flipRate] + nlinarith only [congrArg (fun a : ℝ => a * mean (coupling g) x i ^ 2) (spin_sq x i)] + rw [← gibbsMean_siteKernel g i, show + (fun x => ∑ y, siteKernel g i x y * (spin y i * mean (coupling g) y i)) = + (fun x => mean (coupling g) x i ^ 2) by funext x; exact hpoint x] + +lemma stationary_weight_le_one {n : ℕ} (g : Disorder n) (i : Fin n) : + FiniteLaw.mean (mass g 0) (fun x => gradientWeight (coupling g) x i) ≤ 1 := by + have he : FiniteLaw.mean (mass g 0) (fun x => gradientWeight (coupling g) x i) = + 1 - FiniteLaw.mean (mass g 0) (fun x => mean (coupling g) x i ^ 2) := by + simp only [gradientWeight, FiniteLaw.mean, mul_sub, mul_one, Finset.sum_sub_distrib, + sum_mass] + congr 1 + exact gibbsMean_spin_times_mean g i + rw [he] + have hn : 0 ≤ FiniteLaw.mean (mass g 0) (fun x => mean (coupling g) x i ^ 2) := + Finset.sum_nonneg (fun x _ => mul_nonneg (mass_nonneg g 0 x) (sq_nonneg _)) + linarith only [hn] + +lemma stationaryEnergy_spin_le_one {n : ℕ} (g : Disorder n) (i : Fin n) : + stationaryEnergy g (fun x => spin x i) ≤ 1 := by + have hw (x : Spin n) : weightedGradient (coupling g) (fun y => spin y i) x = + gradientWeight (coupling g) x i := by + simp only [weightedGradient, halfDiff_spin, ite_pow, one_pow, ne_eq, + OfNat.ofNat_ne_zero, not_false_eq_true, zero_pow, mul_ite, mul_one, mul_zero, + Fintype.sum_ite_eq'] + unfold stationaryEnergy FiniteLaw.mean + simp_rw [hw] + exact stationary_weight_le_one g i + +lemma spin_correlation_lower {n : ℕ} (g : Disorder n) (i : Fin n) {t : ℝ} (ht : 0 ≤ t) : + Real.exp (-t) ≤ stationaryInner g (fun x => spin x i) + (semigroup (coupling g) t (fun x => spin x i)) := by + have hnorm : stationaryInner g (fun x => spin x i) (fun x => spin x i) = 1 := by + simp [stationaryInner, FiniteLaw.mean, ← pow_two, spin_sq, sum_mass] + have hh := stationary_correlation_lower g (fun x => spin x i) hnorm t + have hE := mul_le_mul_of_nonneg_left (stationaryEnergy_spin_le_one g i) ht + exact (Real.exp_le_exp.mpr (by linarith only [hE])).trans hh + +def linearObservable {n : ℕ} (a : Fin n → ℝ) : Observables n := fun x => ∑ i, a i * spin x i + +lemma halfDiff_linearObservable {n : ℕ} (a : Fin n → ℝ) (i : Fin n) (x : Spin n) : + halfDiff i (linearObservable a) x = a i := by + unfold linearObservable + rw [halfDiff_sum] + have he (j : Fin n) : halfDiff i (fun y => a j * spin y j) x = a j * halfDiff i (fun y => spin y j) x := by + unfold halfDiff + ring + simp only [he, halfDiff_spin, mul_ite, mul_one, mul_zero, Fintype.sum_ite_eq] + +lemma unweightedGradient_linearObservable {n : ℕ} (a : Fin n → ℝ) (x : Spin n) : + unweightedGradient (linearObservable a) x = ∑ i, a i ^ 2 := by + simp only [unweightedGradient, halfDiff_linearObservable] + +lemma gibbsMean_linearObservable_zero {n : ℕ} (g : Disorder n) (a : Fin n → ℝ) : + FiniteLaw.mean (mass g 0) (linearObservable a) = 0 := by + let e : Spin n ≃ Spin n := Function.Involutive.toPerm reversal (fun x => reversal_reversal x) + have he := Equiv.sum_comp e (fun x => mass g 0 x * linearObservable a x) + change (∑ x, mass g 0 (reversal x) * linearObservable a (reversal x)) = _ at he + have hr (x : Spin n) : linearObservable a (reversal x) = -linearObservable a x := by + simp [linearObservable, spin_reversal, Finset.sum_neg_distrib] + simp only [mass_reversal, hr, mul_neg, Finset.sum_neg_distrib] at he + unfold FiniteLaw.mean + linarith only [he] + +lemma stationaryEnergy_linearObservable_le {n : ℕ} (g : Disorder n) (a : Fin n → ℝ) : + stationaryEnergy g (linearObservable a) ≤ ∑ i, a i ^ 2 := by + unfold stationaryEnergy FiniteLaw.mean weightedGradient + simp only [halfDiff_linearObservable, Finset.mul_sum] + rw [Finset.sum_comm] + apply Finset.sum_le_sum + intro i _ + have h := mul_le_mul_of_nonneg_right (stationary_weight_le_one g i) (sq_nonneg (a i)) + simpa only [FiniteLaw.mean, one_mul, Finset.sum_mul, mul_assoc] using h + +lemma stationary_linearObservable_variance_le {n : ℕ} (g : Disorder n) {γ : ℝ} + (hγ : 0 < γ) + (hgap : ∀ f : Observables n, γ * FiniteLaw.variance (mass g 0) f ≤ stationaryEnergy g f) + (a : Fin n → ℝ) : + FiniteLaw.variance (mass g 0) (linearObservable a) ≤ (∑ i, a i ^ 2) / γ := by + apply (le_div_iff₀ hγ).mpr + simpa only [mul_comm γ] using (hgap (linearObservable a)).trans (stationaryEnergy_linearObservable_le g a) + +lemma semigroup_linearObservable {n : ℕ} (J : Interaction n) (a : Fin n → ℝ) (t : ℝ) (x : Spin n) : + semigroup J t (linearObservable a) x = ∑ i, a i * semigroup J t (fun y => spin y i) x := by + have he : linearObservable a = ∑ i, a i • (fun y : Spin n => spin y i) := by + ext y + simp [linearObservable] + rw [he, map_sum] + simp only [map_smul, Finset.sum_apply, Pi.smul_apply, smul_eq_mul] + +lemma exists_distinguishing_linear {n : ℕ} (hn : 0 < n) (g : Disorder n) {t : ℝ} (ht : 0 ≤ t) : + ∃ x : Spin n, ∃ a : Fin n → ℝ, (∑ i, a i ^ 2) = 1 ∧ + Real.sqrt n * Real.exp (-t) ≤ semigroup (coupling g) t (linearObservable a) x := by + let F (x : Spin n) := ∑ i, spin x i * semigroup (coupling g) t (fun y => spin y i) x + have hsum : (n : ℝ) * Real.exp (-t) ≤ FiniteLaw.mean (mass g 0) F := by + have h := Finset.sum_le_sum (s := Finset.univ) (fun i _ => spin_correlation_lower g i ht) + simp only [Finset.sum_const, Finset.card_univ, Fintype.card_fin, nsmul_eq_mul, + stationaryInner, FiniteLaw.mean] at h + unfold FiniteLaw.mean + dsimp only [F] + simp only [Finset.mul_sum] + rw [Finset.sum_comm] + exact h + obtain ⟨x, _, hmax⟩ := Finset.exists_max_image Finset.univ F Finset.univ_nonempty + have hx : (n : ℝ) * Real.exp (-t) ≤ F x := by + calc + _ ≤ _ := hsum + _ ≤ ∑ y, mass g 0 y * F x := Finset.sum_le_sum (fun y _ => + mul_le_mul_of_nonneg_left (hmax y (Finset.mem_univ y)) (mass_nonneg g 0 y)) + _ = _ := by rw [← Finset.sum_mul, sum_mass, one_mul] + let a (i : Fin n) := spin x i / Real.sqrt n + have hnp : (0 : ℝ) < n := Nat.cast_pos.mpr hn + have hsqrt : 0 < Real.sqrt n := Real.sqrt_pos.2 hnp + refine ⟨x, a, ?_, ?_⟩ + · simp only [a, div_pow, spin_sq, Real.sq_sqrt hnp.le, Finset.sum_const, + Finset.card_univ, Fintype.card_fin, nsmul_eq_mul] + field_simp + · rw [semigroup_linearObservable] + have he : (∑ i, a i * semigroup (coupling g) t (fun y => spin y i) x) = F x / Real.sqrt n := by + simp only [a, F, Finset.sum_div, div_mul_eq_mul_div] + rw [he] + apply (le_div_iff₀ hsqrt).mpr + have heq : Real.sqrt n * Real.exp (-t) * Real.sqrt n = (n : ℝ) * Real.exp (-t) := by + nlinarith only [congrArg (fun z : ℝ => z * Real.exp (-t)) (Real.sq_sqrt hnp.le)] + rwa [heq] + +lemma continuousDistance_lower_of_linear_variances {n : ℕ} (hn : 0 < n) + (g : Disorder n) {t V W : ℝ} (ht : 0 ≤ t) + (htrans : ∀ (a : Fin n → ℝ), (∑ i, a i ^ 2) = 1 → ∀ x, + FiniteLaw.variance (continuousKernel (coupling g) t x) (linearObservable a) ≤ V) + (hstat : ∀ (a : Fin n → ℝ), (∑ i, a i ^ 2) = 1 → + FiniteLaw.variance (mass g 0) (linearObservable a) ≤ W) : + 1 - 2*(V+W)*Real.exp (2*t)/n ≤ continuousDistance g t := by + obtain ⟨x,a,ha,hm⟩ := exists_distinguishing_linear hn g ht + let m := semigroup (coupling g) t (linearObservable a) x + let d := totalVariation (continuousKernel (coupling g) t x) (mass g 0) + have hcommon := FiniteLaw.common_mass_square (continuousKernel (coupling g) t x) + (mass g 0) (linearObservable a) (continuousKernel_nonneg _ t ht x) + (mass_nonneg g 0) (continuousKernel_sum _ t x) (sum_mass g 0) + rw [gibbsMean_linearObservable_zero, sub_zero, ← semigroup_eq_kernel] at hcommon + have hm0 : 0 ≤ m := by + dsimp [m] + exact (mul_nonneg (Real.sqrt_nonneg _) (Real.exp_nonneg _)).trans hm + have hsq : (n : ℝ)*Real.exp (-2*t) ≤ m^2 := by + have h := (sq_le_sq₀ (by positivity : 0 ≤ Real.sqrt n * Real.exp (-t)) hm0).mpr hm + have he : (Real.exp (-t))^2 = Real.exp (-2*t) := by + rw [← Real.exp_nat_mul] + congr 1 + push_cast + ring + simpa only [mul_pow, Real.sq_sqrt (Nat.cast_nonneg n), he] using h + have hbound : (1-continuousDistance g t)*((n : ℝ)*Real.exp (-2*t)) ≤ 2*(V+W) := by + calc + _ ≤ (1-continuousDistance g t)*m^2 := mul_le_mul_of_nonneg_left hsq + (sub_nonneg.mpr (continuousDistance_le_one g ht)) + _ ≤ (1-d)*m^2 := mul_le_mul_of_nonneg_right + (sub_le_sub_left (tv_le_continuousDistance g t x) 1) (sq_nonneg m) + _ ≤ 2*FiniteLaw.variance (continuousKernel (coupling g) t x) (linearObservable a) + + 2*FiniteLaw.variance (mass g 0) (linearObservable a) := hcommon + _ ≤ 2*(V+W) := by linarith only [htrans a ha x, hstat a ha] + have hnp : (0 : ℝ) < n := Nat.cast_pos.mpr hn + have heq : ((n : ℝ)*Real.exp (-2*t)) * (Real.exp (2*t)/n) = 1 := by + rw [mul_div_assoc', mul_assoc (n : ℝ), ← Real.exp_add, + show -2*t+2*t=0 by ring, Real.exp_zero, mul_one, div_self hnp.ne'] + have hmultiply := mul_le_mul_of_nonneg_right hbound + (div_nonneg (Real.exp_nonneg (2*t)) hnp.le) + rw [mul_assoc, heq, mul_one] at hmultiply + rw [← mul_div_assoc] at hmultiply + linarith only [hmultiply] + +lemma exp_quarter_log_div {n : ℕ} (hn : 0 < n) : + Real.exp (2*(Real.log n/4))/(n : ℝ) = dimensionDecay (1/2) n := by + have hn' : (0 : ℝ) < n := Nat.cast_pos.mpr hn + have he : (n : ℝ) = Real.exp (Real.log n) := (Real.exp_log hn').symm + conv_lhs => rhs; rw [he] + rw [← Real.exp_sub] + unfold dimensionDecay + congr 1 + ring + +theorem uniform_strong_lower_of_small_set + (G : ∀ n : ℕ, Set (Disorder n)) + (bad : ∀ n, Disorder n → Set (Spin n)) {κ A d₀ γ : ℝ} + (hκ : 0 < κ) (hA : 0 ≤ A) (hd₀ : 0 ≤ d₀) (hγ : 0 < γ) + (hgap : ∀ᶠ n : ℕ in atTop, ∀ g ∈ G n, ∀ f : Observables n, + γ*FiniteLaw.variance (mass g 0) f ≤ stationaryEnergy g f) + (hdrift : ∀ D : ℝ, 0 < D → ∀ᶠ n : ℕ in atTop, ∀ g ∈ G n, + ∀ (f : Observables n), ∀ r ∈ Set.Icc (0:ℝ) (D*Real.log n), ∀ y, + deriv (fun v => unweightedGradient (semigroup (coupling g) v f) y) r - + generator (coupling g) (unweightedGradient (semigroup (coupling g) r f)) y ≤ + (-κ + if y ∈ bad n g then A else 0)* + unweightedGradient (semigroup (coupling g) r f) y) + (havoid : ∀ D m : ℝ, 0 < D → 0 < m → + ∀ᶠ n : ℕ in atTop, ∀ g ∈ G n, ∀ u ∈ Set.Icc d₀ (D*Real.log n), ∀ x, + semigroup (coupling g) u (fun y => if y ∈ bad n g then 1 else 0) x ≤ dimensionDecay m n) : + ∀ᶠ n : ℕ in atTop, ∀ g ∈ G n, + 1-2*(4*(Real.exp (A*d₀)/κ+1)+1/γ)*dimensionDecay (1/2) n ≤ + continuousDistance g (Real.log n/4) := by + have hmom := uniform_gradient_moments_of_small_set G bad hκ hA hd₀ hdrift havoid + (D := 1) (R := 1) (by norm_num) (by norm_num) + filter_upwards [hgap, hmom, eventually_ge_atTop 1] with n hngap hnmom hn + intro g hg + have hn' : 0 < n := hn + have hlog : 0 ≤ Real.log n := Real.log_nonneg (by exact_mod_cast hn) + have htime : Real.log n/4 ∈ Set.Icc (0 : ℝ) (1*Real.log n) := by + constructor <;> linarith only [hlog] + have htrans (a : Fin n → ℝ) (ha : (∑ i, a i ^ 2) = 1) (x : Spin n) : + FiniteLaw.variance (continuousKernel (coupling g) (Real.log n/4) x) + (linearObservable a) ≤ 4*(Real.exp (A*d₀)/κ+1) := by + simpa only [one_mul] using (hnmom g hg (linearObservable a) + (fun y => by rw [unweightedGradient_linearObservable,ha]) (Real.log n/4) htime).1 x + have hstat (a : Fin n → ℝ) (ha : (∑ i, a i ^ 2) = 1) : + FiniteLaw.variance (mass g 0) (linearObservable a) ≤ 1/γ := by + simpa only [ha] using stationary_linearObservable_variance_le g hγ (hngap g hg) a + have h := continuousDistance_lower_of_linear_variances hn' g htime.1 htrans hstat + rw [mul_div_assoc, exp_quarter_log_div hn'] at h + exact h + +theorem uniform_median_lower_of_small_set + (G : ∀ n : ℕ, Set (Disorder n)) + (bad : ∀ n, Disorder n → Set (Spin n)) {κ A d₀ γ : ℝ} + (hκ : 0 < κ) (hA : 0 ≤ A) (hd₀ : 0 ≤ d₀) (hγ : 0 < γ) + (hgap : ∀ᶠ n : ℕ in atTop, ∀ g ∈ G n, ∀ f : Observables n, + γ*FiniteLaw.variance (mass g 0) f ≤ stationaryEnergy g f) + (hdrift : ∀ D : ℝ, 0 < D → ∀ᶠ n : ℕ in atTop, ∀ g ∈ G n, + ∀ (f : Observables n), ∀ r ∈ Set.Icc (0:ℝ) (D*Real.log n), ∀ y, + deriv (fun v => unweightedGradient (semigroup (coupling g) v f) y) r - + generator (coupling g) (unweightedGradient (semigroup (coupling g) r f)) y ≤ + (-κ + if y ∈ bad n g then A else 0)* + unweightedGradient (semigroup (coupling g) r f) y) + (havoid : ∀ D m : ℝ, 0 < D → 0 < m → + ∀ᶠ n : ℕ in atTop, ∀ g ∈ G n, ∀ u ∈ Set.Icc d₀ (D*Real.log n), ∀ x, + semigroup (coupling g) u (fun y => if y ∈ bad n g then 1 else 0) x ≤ dimensionDecay m n) : + ∀ᶠ n : ℕ in atTop, ∀ g ∈ G n, Real.log n/4 ≤ medianTime g := by + have hlower := uniform_strong_lower_of_small_set G bad hκ hA hd₀ hγ hgap hdrift havoid + have hdecay := (dimensionDecay_tendsto_zero (by norm_num : (0 : ℝ)<1/2)).const_mul + (2*(4*(Real.exp (A*d₀)/κ+1)+1/γ)) + simp only [mul_zero] at hdecay + filter_upwards [hlower, hdecay.eventually (gt_mem_nhds (by norm_num : (0 : ℝ)<1/2)), + eventually_ge_atTop 1] with n hnlow hdec hn + intro g hg + have ht : 0 ≤ Real.log n/4 := div_nonneg + (Real.log_nonneg (by exact_mod_cast hn)) (by norm_num) + have hdist : 1/2 < continuousDistance g (Real.log n/4) := by + linarith only [hnlow g hg,hdec] + exact le_of_lt (lt_of_not_ge (fun h => not_lt_of_ge ((medianTime_le_iff g ht).mp h) hdist)) + +end SKRatio.Calculus + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Calculus/TwoSpin.lean b/lean/OAI/Probability/SKRatio/Calculus/TwoSpin.lean new file mode 100644 index 0000000000000000000000000000000000000000..4481af4521d7a8023bb93485ee51ef8e0e2632f2 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Calculus/TwoSpin.lean @@ -0,0 +1,682 @@ +import Mathlib +import OAI.Probability.SKRatio.FiniteChain.Spin + +namespace OAI + +section +noncomputable section +open scoped BigOperators +namespace SKRatio.TwoSpin + +private def polynomialSum (l : List (ℤ × ℕ × ℕ × ℕ)) (a b t : ℝ) : ℝ := + (l.map fun c => (c.1 : ℝ)*a^c.2.1*b^c.2.2.1*t^c.2.2.2).sum + +private lemma polynomialSum_bound (l : List (ℤ × ℕ × ℕ × ℕ)) {a b t : ℝ} + (ha : |a| ≤ 1) (hb : |b| ≤ 1) (ht : |t| ≤ 1) : + |polynomialSum l a b t| ≤ (l.map fun c => |(c.1 : ℝ)|).sum := by + have hm (c : ℤ × ℕ × ℕ × ℕ) : + |(c.1 : ℝ)*a^c.2.1*b^c.2.2.1*t^c.2.2.2| ≤ |(c.1 : ℝ)| := by + simp only [abs_mul, abs_pow] + have ha' : |a|^c.2.1 ≤ 1 := pow_le_one₀ (abs_nonneg _) ha + have hb' : |b|^c.2.2.1 ≤ 1 := pow_le_one₀ (abs_nonneg _) hb + have ht' : |t|^c.2.2.2 ≤ 1 := pow_le_one₀ (abs_nonneg _) ht + calc + _ ≤ |(c.1 : ℝ)| * 1*1*1 := by gcongr + _ = _ := by ring + induction l with + | nil => simp [polynomialSum] + | cons c l ih => + simp only [polynomialSum, List.map_cons, List.sum_cons] at ih ⊢ + exact (abs_add_le _ _).trans (add_le_add (hm c) ih) + +private lemma affine_factor {a t : ℝ} (ha : |a| ≤ 1) (ht : |t| ≤ 1/4) : + (1/2:ℝ) ≤ 1+a*t := by + have h : |a*t| ≤ 1/4 := by + rw [abs_mul] + calc |a| * |t| ≤ 1*(1/4) := by gcongr + _ = _ := by ring + linarith [(abs_le.mp h).1] + +private def rationalCoefficient (a b t : ℝ) : ℝ := + (1-t)/((1+a*t)*(1+b*t)) + + (t+2*t^2*((a+t)/(1+a*t))*((b+t)/(1+b*t)))* + ((1-t^2)*(1+a)*(1+b)*(1+t))/((1+a*t)^2*(1+b*t)^2) + +private def leadingCoefficient (a b t : ℝ) : ℝ := + 1+a*b*t+(1-a^2-b^2+2*a^2*b^2)*t^2 + +private def remainder0 : List (ℤ × ℕ × ℕ × ℕ) := + [(-1, 0, 0, 0), + (-1, 0, 1, 0), + (2, 0, 2, 0), + (2, 0, 3, 0), + (-1, 1, 0, 0), + (4, 1, 1, 0), + (2, 1, 2, 0), + (-3, 1, 3, 0), + (2, 2, 0, 0), + (2, 2, 1, 0), + (-6, 2, 2, 0), + (-6, 2, 3, 0), + (2, 3, 0, 0), + (-3, 3, 1, 0), + (-6, 3, 2, 0)] + +private def remainder1 : List (ℤ × ℕ × ℕ × ℕ) := + [(1, 0, 0, 1), + (2, 0, 1, 1), + (-2, 0, 2, 1), + (3, 0, 4, 1), + (2, 1, 0, 1), + (-7, 1, 1, 1), + (-2, 1, 2, 1), + (6, 1, 3, 1), + (-1, 1, 4, 1), + (-2, 2, 0, 1), + (-2, 2, 1, 1), + (-3, 2, 2, 1), + (-9, 2, 3, 1), + (-6, 2, 4, 1), + (6, 3, 1, 1), + (-9, 3, 2, 1), + (-18, 3, 3, 1), + (3, 4, 0, 1), + (-1, 4, 1, 1), + (-6, 4, 2, 1)] + +private def remainder2 : List (ℤ × ℕ × ℕ × ℕ) := + [(2, 0, 0, 2), + (-1, 0, 1, 2), + (-3, 0, 2, 2), + (-1, 0, 3, 2), + (1, 0, 5, 2), + (-1, 1, 0, 2), + (-7, 1, 1, 2), + (-15, 1, 2, 2), + (9, 1, 4, 2), + (-3, 2, 0, 2), + (-15, 2, 1, 2), + (-4, 2, 2, 2), + (7, 2, 3, 2), + (-3, 2, 4, 2), + (-2, 2, 5, 2), + (-1, 3, 0, 2), + (7, 3, 2, 2), + (-9, 3, 3, 2), + (-18, 3, 4, 2), + (9, 4, 1, 2), + (-3, 4, 2, 2), + (-18, 4, 3, 2), + (1, 5, 0, 2), + (-2, 5, 2, 2)] + +private def remainder3 : List (ℤ × ℕ × ℕ × ℕ) := + [(-2, 0, 0, 3), + (-4, 0, 1, 3), + (-2, 0, 2, 3), + (-4, 1, 0, 3), + (-7, 1, 1, 3), + (-3, 1, 2, 3), + (-3, 1, 3, 3), + (3, 1, 5, 3), + (-2, 2, 0, 3), + (-3, 2, 1, 3), + (-10, 2, 2, 3), + (9, 2, 4, 3), + (-3, 3, 1, 3), + (5, 3, 3, 3), + (-3, 3, 4, 3), + (-6, 3, 5, 3), + (9, 4, 2, 3), + (-3, 4, 3, 3), + (-18, 4, 4, 3), + (3, 5, 1, 3), + (-6, 5, 3, 3)] + +private def remainder4 : List (ℤ × ℕ × ℕ × ℕ) := + [(-2, 0, 0, 4), + (-2, 0, 1, 4), + (-2, 1, 0, 4), + (-2, 1, 1, 4), + (-3, 2, 3, 4), + (3, 2, 5, 4), + (-3, 3, 2, 4), + (3, 3, 4, 4), + (3, 4, 3, 4), + (-1, 4, 4, 4), + (-6, 4, 5, 4), + (3, 5, 2, 4), + (-6, 5, 4, 4)] + +private def remainder5 : List (ℤ × ℕ × ℕ × ℕ) := + [(-1, 3, 3, 5), + (1, 3, 5, 5), + (1, 5, 3, 5), + (-2, 5, 5, 5)] + +private def remainder (a b t : ℝ) : ℝ := + polynomialSum remainder0 a b t + + polynomialSum remainder1 a b t + + polynomialSum remainder2 a b t + + polynomialSum remainder3 a b t + + polynomialSum remainder4 a b t + + polynomialSum remainder5 a b t + +private lemma remainder_bound {a b t : ℝ} (ha : |a| ≤ 1) + (hb : |b| ≤ 1) (ht : |t| ≤ 1) : |remainder a b t| ≤ 428 := by + have h0 : |polynomialSum remainder0 a b t| ≤ 43 := by + have h := polynomialSum_bound remainder0 ha hb ht + norm_num [remainder0] at h ⊢ + exact h + have h1 : |polynomialSum remainder1 a b t| ≤ 91 := by + have h := polynomialSum_bound remainder1 ha hb ht + norm_num [remainder1] at h ⊢ + exact h + have h2 : |polynomialSum remainder2 a b t| ≤ 142 := by + have h := polynomialSum_bound remainder2 ha hb ht + norm_num [remainder2] at h ⊢ + exact h + have h3 : |polynomialSum remainder3 a b t| ≤ 108 := by + have h := polynomialSum_bound remainder3 ha hb ht + norm_num [remainder3] at h ⊢ + exact h + have h4 : |polynomialSum remainder4 a b t| ≤ 39 := by + have h := polynomialSum_bound remainder4 ha hb ht + norm_num [remainder4] at h ⊢ + exact h + have h5 : |polynomialSum remainder5 a b t| ≤ 5 := by + have h := polynomialSum_bound remainder5 ha hb ht + norm_num [remainder5] at h ⊢ + exact h + have h01 := (abs_add_le _ _).trans (add_le_add h0 h1) + have h02 := (abs_add_le _ _).trans (add_le_add h01 h2) + have h03 := (abs_add_le _ _).trans (add_le_add h02 h3) + have h04 := (abs_add_le _ _).trans (add_le_add h03 h4) + have h05 := (abs_add_le _ _).trans (add_le_add h04 h5) + norm_num at h05 + exact h05 + +private lemma numerator_certificate (a b t : ℝ) : + (1-t)*(1+a*t)^2*(1+b*t)^2 + + (t*(1+a*t)*(1+b*t)+2*t^2*(a+t)*(b+t))* + ((1-t^2)*(1+a)*(1+b)*(1+t)) - + leadingCoefficient a b t*((1+a*t)^3*(1+b*t)^3) = + t^3*remainder a b t := by + simp only [remainder, leadingCoefficient, polynomialSum, + remainder0,remainder1,remainder2,remainder3,remainder4,remainder5, + List.map_cons, List.map_nil, List.sum_cons, List.sum_nil, + Int.cast_ofNat, Int.cast_neg] + ring + +private lemma rational_remainder {a b t : ℝ} (ha : |a| ≤ 1) + (hb : |b| ≤ 1) (ht : |t| ≤ 1/4) : + rationalCoefficient a b t - leadingCoefficient a b t = + t^3*remainder a b t/((1+a*t)^3*(1+b*t)^3) := by + have hA : 1+a*t ≠ 0 := ne_of_gt (lt_of_lt_of_le (by norm_num) (affine_factor ha ht)) + have hB : 1+b*t ≠ 0 := ne_of_gt (lt_of_lt_of_le (by norm_num) (affine_factor hb ht)) + have hc := numerator_certificate a b t + have hA' : 1+t*a ≠ 0 := by simpa [mul_comm] using hA + have hB' : 1+t*b ≠ 0 := by simpa [mul_comm] using hB + unfold rationalCoefficient + field_simp [hA, hB, hA', hB'] + linear_combination hc + +private lemma rational_remainder_bound {a b t : ℝ} (ha : |a| ≤ 1) + (hb : |b| ≤ 1) (ht : |t| ≤ 1/4) : + |rationalCoefficient a b t - leadingCoefficient a b t| ≤ 30000*|t|^3 := by + have hA := affine_factor ha ht + have hB := affine_factor hb ht + have hAp : 0 < 1+a*t := lt_of_lt_of_le (by norm_num) hA + have hBp : 0 < 1+b*t := lt_of_lt_of_le (by norm_num) hB + have hd : (1/64:ℝ) ≤ (1+a*t)^3*(1+b*t)^3 := by + calc (1/64:ℝ) = (1/2:ℝ)^3*(1/2:ℝ)^3 := by norm_num + _ ≤ (1+a*t)^3*(1+b*t)^3 := by gcongr + have hdp : 0 < (1+a*t)^3*(1+b*t)^3 := mul_pos (pow_pos hAp 3) (pow_pos hBp 3) + rw [rational_remainder ha hb ht, abs_div, abs_mul, abs_pow, + abs_of_pos hdp, div_le_iff₀ hdp] + have hr := remainder_bound ha hb (ht.trans (by norm_num)) + calc + |t|^3*|remainder a b t| ≤ |t|^3*428 := by gcongr + _ ≤ 30000*|t|^3*(1/64) := by nlinarith [pow_nonneg (abs_nonneg t) 3] + _ ≤ 30000*|t|^3*((1+a*t)^3*(1+b*t)^3) := by gcongr + +def pairBaseMass (a b : ℝ) (x y : Bool) : ℝ := + (1+a*spinValue x)*(1+b*spinValue y)/4 + +def pairMean (a b : ℝ) (F : Bool→Bool→ℝ) : ℝ := + ∑ x,∑ y,pairBaseMass a b x y*F x y + +lemma pairMean_explicit (a b : ℝ) (F : Bool→Bool→ℝ) : + pairMean a b F=((1-a)*(1-b)*F false false+(1-a)*(1+b)*F false true+ + (1+a)*(1-b)*F true false+(1+a)*(1+b)*F true true)/4 := by + simp only [pairMean,Fintype.sum_bool,pairBaseMass,spinValue,Bool.false_eq_true, + ite_false,ite_true,mul_neg_one,mul_one] + ring + +lemma pairBaseMass_nonneg {a b : ℝ} (ha : |a| ≤ 1) (hb : |b| ≤ 1) (x y : Bool) : + 0 ≤ pairBaseMass a b x y := by + have h₁ := abs_le.mp ha + have h₂ := abs_le.mp hb + unfold pairBaseMass + cases x <;> cases y <;> simp only [spinValue,Bool.false_eq_true,ite_false,ite_true,mul_one,mul_neg_one] <;> + exact div_nonneg (mul_nonneg (by linarith only [h₁.1,h₁.2]) (by linarith only [h₂.1,h₂.2])) (by norm_num) + +lemma pairMean_mono {a b : ℝ} (ha : |a| ≤ 1) (hb : |b| ≤ 1) + {F G : Bool→Bool→ℝ} (h : ∀ x y,F x y ≤ G x y) : pairMean a b F ≤ pairMean a b G := by + apply Finset.sum_le_sum + intro x _ + apply Finset.sum_le_sum + intro y _ + exact mul_le_mul_of_nonneg_left (h x y) (pairBaseMass_nonneg ha hb x y) + +lemma pairMean_add (a b : ℝ) (F G : Bool→Bool→ℝ) : + pairMean a b (fun x y=>F x y+G x y)=pairMean a b F+pairMean a b G := by + simp only [pairMean,mul_add,Finset.sum_add_distrib] + +lemma pairMean_sub (a b : ℝ) (F G : Bool→Bool→ℝ) : + pairMean a b (fun x y=>F x y-G x y)=pairMean a b F-pairMean a b G := by + simp only [pairMean,mul_sub,Finset.sum_sub_distrib] + +lemma pairMean_mul (a b c : ℝ) (F : Bool→Bool→ℝ) : + pairMean a b (fun x y=>c*F x y)=c*pairMean a b F := by + simp only [pairMean,Finset.mul_sum,mul_left_comm] + +lemma abs_pairMean_le {a b : ℝ} (ha : |a| ≤ 1) (hb : |b| ≤ 1) + (F : Bool→Bool→ℝ) : |pairMean a b F| ≤ pairMean a b (fun x y=>|F x y|) := by + unfold pairMean + apply (Finset.abs_sum_le_sum_abs _ _).trans + apply Finset.sum_le_sum + intro x _ + apply (Finset.abs_sum_le_sum_abs _ _).trans_eq + apply Finset.sum_congr rfl + intro y _ + rw [abs_mul,abs_of_nonneg (pairBaseMass_nonneg ha hb x y)] + +lemma pair_gradient_mean (a b p s r : ℝ) : + pairMean a b (fun x y=>(p+r*(spinValue y-b))*(s+r*(spinValue x-a)))=p*s := by + rw [pairMean_explicit] + simp only [spinValue,Bool.false_eq_true,ite_false,ite_true] + ring + +lemma pair_gradient_square (a b p r : ℝ) : + pairMean a b (fun _ y=>(p+r*(spinValue y-b))^2)=p^2+(1-b^2)*r^2 := by + rw [pairMean_explicit] + simp only [spinValue,Bool.false_eq_true,ite_false,ite_true] + ring + +lemma pairMean_swap (a b : ℝ) (F : Bool→Bool→ℝ) : + pairMean a b F=pairMean b a (fun x y=>F y x) := by + rw [pairMean_explicit,pairMean_explicit] + ring + +lemma pair_second_gradient_square (a b s r : ℝ) : + pairMean a b (fun x _=>(s+r*(spinValue x-a))^2)=s^2+(1-a^2)*r^2 := by + rw [pairMean_swap] + exact pair_gradient_square b a s r + +lemma pair_factor_control {u z : ℝ} (hu : |u| ≤ 1/4) (hz : |z| ≤ 1) : + (1/2:ℝ) ≤ 1+u*z ∧ 1+u*z ≤ 2 ∧ |(1+u*z)-1| ≤ |u| := by + have hh : |u*z| ≤ |u| := by rw [abs_mul];exact (mul_le_mul_of_nonneg_left hz (abs_nonneg u)).trans_eq (mul_one _) + have hb := abs_le.mp hh + constructor + · linarith + constructor + · linarith + simpa only [add_sub_cancel_left] using hh + +lemma pair_square_factor_control {u : ℝ} (hu : |u| ≤ 1/4) : + (1/2:ℝ) ≤ 1-u^2 ∧ 1-u^2 ≤ 2 ∧ |(1-u^2)-1| ≤ |u| := by + have hs : u^2 ≤ |u| := by nlinarith [sq_abs u,abs_nonneg u] + have h0 := sq_nonneg u + constructor + · linarith + constructor + · linarith + rw [sub_sub_cancel_left,abs_neg,abs_of_nonneg h0] + exact hs + +lemma abs_mul_le_one_pair {x y : ℝ} (hx : |x| ≤ 1) (hy : |y| ≤ 1) : |x*y| ≤ 1 := by + rw [abs_mul] + exact (mul_le_mul hx hy (abs_nonneg _) (by norm_num)).trans_eq (by ring) + +def pairDensity (a b u : ℝ) (x y : Bool) : ℝ := + (1+u*spinValue x*spinValue y)/(1+u*a*b) + +def pairInterMean (a b u : ℝ) (F : Bool→Bool→ℝ) : ℝ := + pairMean a b (fun x y=>pairDensity a b u x y*F x y) + +def pairResidual (a u : ℝ) (x y : Bool) : ℝ := + (spinValue x-a)*(1-u*spinValue x*spinValue y)/(1+u*a*spinValue y) + +def pairVariance (a u : ℝ) (y : Bool) : ℝ := + (1-a^2)*(1-u^2)/(1+u*a*spinValue y)^2 + +def pairGrad₁ (b p r : ℝ) (y : Bool) : ℝ := p+r*(spinValue y-b) + +def pairGrad₂ (a s r : ℝ) (x : Bool) : ℝ := s+r*(spinValue x-a) + +lemma pairSign_abs (x : Bool) : |spinValue x|=1 := by cases x <;> norm_num [spinValue] + +lemma pairSign_sq (x : Bool) : spinValue x^2=1 := by cases x <;> norm_num [spinValue] + +lemma pairDenominator_pos {u a b : ℝ} (hu : |u| ≤ 1/4) (ha : |a| ≤ 1) (hb : |b| ≤ 1) : + 0 < 1+u*a*b := by + have hh := (pair_factor_control hu (abs_mul_le_one_pair ha hb)).1 + rw [← mul_assoc] at hh + linarith only [hh] + +lemma pair_variance_nonneg {a u : ℝ} (ha : |a| ≤ 1) (hu : |u| ≤ 1/4) (y : Bool) : + 0 ≤ pairVariance a u y := by + have ha2 : a^2 ≤ 1 := by nlinarith only [sq_abs a,abs_nonneg a,ha] + have hh := (pair_square_factor_control hu).1 + exact div_nonneg (mul_nonneg (sub_nonneg.mpr ha2) (by linarith only [hh])) (sq_nonneg _) + +lemma pair_density_nonneg {a b u : ℝ} (ha : |a| ≤ 1) (hb : |b| ≤ 1) + (hu : |u| ≤ 1/4) (x y : Bool) : 0 ≤ pairDensity a b u x y := by + exact div_nonneg (pairDenominator_pos hu (pairSign_abs x).le (pairSign_abs y).le).le + (pairDenominator_pos hu ha hb).le + +lemma pair_density_variance_lower {a b u : ℝ} + (ha : |a| ≤ 1) (hb : |b| ≤ 1) (hu : |u| ≤ 1/4) (x y : Bool) : + (1-a^2)/32 ≤ pairDensity a b u x y*pairVariance a u y := by + have hn : 1/2 ≤ 1+u*spinValue x*spinValue y := by + simpa only [mul_assoc] using (pair_factor_control hu (abs_mul_le_one_pair (pairSign_abs x).le (pairSign_abs y).le)).1 + have hs := (pair_square_factor_control hu).1 + have hd₀ := pair_factor_control hu (abs_mul_le_one_pair ha hb) + have hd₁ := pair_factor_control hu (abs_mul_le_one_pair ha (pairSign_abs y).le) + have hd02 : 1+u*a*b ≤ 2 := by simpa only [mul_assoc] using hd₀.2.1 + have hd12 : 1+u*a*spinValue y ≤ 2 := by simpa only [mul_assoc] using hd₁.2.1 + have hd10 : 0 ≤ 1+u*a*spinValue y := (pairDenominator_pos hu ha (pairSign_abs y).le).le + have hd00 := pairDenominator_pos hu ha hb + have hdd : 0 < (1+u*a*b)*(1+u*a*spinValue y)^2 := mul_pos hd00 (sq_pos_of_pos (pairDenominator_pos hu ha (pairSign_abs y).le)) + have hd : (1+u*a*b)*(1+u*a*spinValue y)^2 ≤ 8 := by + have hh : (1+u*a*spinValue y)^2 ≤ 4 := by nlinarith only [hd12,hd10] + nlinarith only [mul_le_mul hd02 hh (sq_nonneg (1+u*a*spinValue y)) (by norm_num : (0:ℝ) ≤ 2)] + have ha2 : a^2 ≤ 1 := by nlinarith only [sq_abs a,abs_nonneg a,ha] + have hA := sub_nonneg.mpr ha2 + have hn' : 1/4 ≤ (1+u*spinValue x*spinValue y)*(1-u^2) := by + nlinarith only [mul_le_mul hn hs (by norm_num : (0:ℝ) ≤ 1/2) (by linarith only [hn] : 0 ≤ 1+u*spinValue x*spinValue y)] + have he : pairDensity a b u x y*pairVariance a u y= + ((1-a^2)*((1+u*spinValue x*spinValue y)*(1-u^2)))/ + ((1+u*a*b)*(1+u*a*spinValue y)^2) := by + unfold pairDensity pairVariance + simp only [div_eq_mul_inv,mul_inv_rev] + ring + rw [he] + apply (le_div_iff₀ hdd).mpr + have h₁ := mul_le_mul_of_nonneg_left hd (div_nonneg hA (by norm_num : (0:ℝ) ≤ 32)) + have h₂ := mul_le_mul_of_nonneg_left hn' hA + nlinarith only [h₁,h₂] + +lemma pair_energy_lower {a b u p r : ℝ} + (ha : |a| ≤ 1) (hb : |b| ≤ 1) (hu : |u| ≤ 1/4) : + (1-a^2)*(1-b^2)*p^2/32 ≤ + pairInterMean a b u (fun _x y=>pairVariance a u y*(pairGrad₁ b p r y)^2) := by + have ha2 : a^2 ≤ 1 := by nlinarith only [sq_abs a,abs_nonneg a,ha] + have hb2 : b^2 ≤ 1 := by nlinarith only [sq_abs b,abs_nonneg b,hb] + have hA := sub_nonneg.mpr ha2 + have hB := sub_nonneg.mpr hb2 + have he := pairMean_mono ha hb (fun x y=>mul_le_mul_of_nonneg_right + (pair_density_variance_lower ha hb hu x y) (sq_nonneg (pairGrad₁ b p r y))) + simp only [pairMean_mul] at he + have h₁ : pairMean a b (fun _ y=>(pairGrad₁ b p r y)^2)=p^2+(1-b^2)*r^2 := + pair_gradient_square a b p r + rw [h₁] at he + have h₂ : pairMean a b (fun x y=>pairDensity a b u x y*pairVariance a u y*(pairGrad₁ b p r y)^2)= + pairInterMean a b u (fun _x y=>pairVariance a u y*(pairGrad₁ b p r y)^2) := by + unfold pairInterMean + congr 1 + funext x y + ring + rw [h₂] at he + have h₃ : (1-a^2)*(1-b^2)*p^2 ≤ (1-a^2)*p^2 := by + have hh := mul_le_mul_of_nonneg_right (show 1-b^2 ≤ 1 by linarith [sq_nonneg b]) + (mul_nonneg hA (sq_nonneg p)) + nlinarith only [hh] + have h₄ : 0 ≤ (1-a^2)*(1-b^2)*r^2 := mul_nonneg (mul_nonneg hA hB) (sq_nonneg r) + nlinarith only [he,h₃,h₄] + +lemma pairInterMean_swap (a b u : ℝ) (F : Bool→Bool→ℝ) : + pairInterMean a b u F=pairInterMean b a u (fun x y=>F y x) := by + unfold pairInterMean + rw [pairMean_swap] + congr 1 + funext x y + unfold pairDensity + have he : (1+u*spinValue y*spinValue x)/(1+u*a*b)= + (1+u*spinValue x*spinValue y)/(1+u*b*a) := by congr 1 <;> ring + rw [he] + +lemma pair_second_energy_lower {a b u s r : ℝ} + (ha : |a| ≤ 1) (hb : |b| ≤ 1) (hu : |u| ≤ 1/4) : + (1-a^2)*(1-b^2)*s^2/32 ≤ + pairInterMean a b u (fun x _y=>pairVariance b u x*(pairGrad₂ a s r x)^2) := by + rw [pairInterMean_swap] + simpa only [mul_comm (1-a^2) (1-b^2),pairGrad₁,pairGrad₂] using + (pair_energy_lower (p:=s) (r:=r) hb ha hu) + +lemma pairInterMean_add (a b u : ℝ) (F G : Bool→Bool→ℝ) : + pairInterMean a b u (fun x y=>F x y+G x y)=pairInterMean a b u F+pairInterMean a b u G := by + unfold pairInterMean + simp_rw [mul_add] + exact pairMean_add a b _ _ + +lemma pairInterMean_nonneg {a b u : ℝ} + (ha : |a| ≤ 1) (hb : |b| ≤ 1) (hu : |u| ≤ 1/4) + {F : Bool→Bool→ℝ} (hF : ∀ x y,0 ≤ F x y) : 0 ≤ pairInterMean a b u F := by + have hh := pairMean_mono ha hb (fun x y=>mul_nonneg (pair_density_nonneg ha hb hu x y) (hF x y)) + have he : pairMean a b (fun _ _=>(0:ℝ))=0 := by simp [pairMean] + rwa [he] at hh + +def pairConditionalMean (a t : ℝ) (y : Bool) : ℝ := + (a+t*spinValue y)/(1+t*a*spinValue y) + +private def signedCoefficient (a b t : ℝ) (x y : Bool) : ℝ := + (spinValue x*spinValue y-t)/((1+t*a*spinValue y)*(1+t*b*spinValue x)) + + (t+2*t^2*pairConditionalMean a t y*pairConditionalMean b t x)* + ((1-t^2)*(1+a*spinValue x)*(1+b*spinValue y)*(1+t*spinValue x*spinValue y))/ + ((1+t*a*spinValue y)^2*(1+t*b*spinValue x)^2) + +private lemma signedCoefficient_eq (a b t : ℝ) (x y : Bool) : + signedCoefficient a b t x y = spinValue x*spinValue y * + rationalCoefficient (a*spinValue x) (b*spinValue y) (t*spinValue x*spinValue y) := by + unfold signedCoefficient rationalCoefficient pairConditionalMean + cases x <;> cases y <;> norm_num [spinValue] <;> ring + +private lemma leading_signs (a b t : ℝ) (x y : Bool) : + leadingCoefficient (a*spinValue x) (b*spinValue y) (t*spinValue x*spinValue y) = + leadingCoefficient a b t := by + cases x <;> cases y <;> norm_num [spinValue,leadingCoefficient] + +private lemma signedCoefficient_remainder {a b t : ℝ} (ha : |a| ≤ 1) + (hb : |b| ≤ 1) (ht : |t| ≤ 1/4) (x y : Bool) : + |signedCoefficient a b t x y-spinValue x*spinValue y*leadingCoefficient a b t| ≤ + 30000*|t|^3 := by + have h := rational_remainder_bound + (a := a*spinValue x) (b := b*spinValue y) (t := t*spinValue x*spinValue y) + (by simpa only [abs_mul,pairSign_abs,mul_one] using ha) + (by simpa only [abs_mul,pairSign_abs,mul_one] using hb) + (by simpa only [abs_mul,pairSign_abs,mul_one] using ht) + rw [leading_signs] at h + simpa only [signedCoefficient_eq,← mul_sub,abs_mul,pairSign_abs,one_mul,mul_one] using h + +private lemma pairMean_const (a b c : ℝ) : pairMean a b (fun _ _ => c)=c := by + rw [pairMean_explicit] + ring + +private lemma uniform_cross_gradient (a b p q r : ℝ) : + pairMean 0 0 (fun x y => spinValue x*spinValue y*pairGrad₁ b p r y*pairGrad₂ a q r x)=r^2 := by + rw [pairMean_explicit] + simp only [pairGrad₁,pairGrad₂,spinValue,Bool.false_eq_true,ite_false,ite_true] + ring + +private lemma abs_pairGrad_product {a b : ℝ} (ha : |a| ≤ 1) (hb : |b| ≤ 1) + (p q r : ℝ) (x y : Bool) : + |pairGrad₁ b p r y*pairGrad₂ a q r x| ≤ p^2+q^2+8*r^2 := by + have hya : |spinValue y-b| ≤ 2 := by + calc _ ≤ |spinValue y|+|b| := abs_sub _ _ + _ ≤ 2 := by rw [pairSign_abs];linarith + have hxb : |spinValue x-a| ≤ 2 := by + calc _ ≤ |spinValue x|+|a| := abs_sub _ _ + _ ≤ 2 := by rw [pairSign_abs];linarith + have hx2 : (spinValue x-a)^2 ≤ 4 := by + nlinarith only [hxb,abs_nonneg (spinValue x-a),sq_abs (spinValue x-a)] + have hy2 : (spinValue y-b)^2 ≤ 4 := by + nlinarith only [hya,abs_nonneg (spinValue y-b),sq_abs (spinValue y-b)] + have h₁ : (pairGrad₁ b p r y)^2 ≤ 2*p^2+8*r^2 := by + have h := mul_le_mul_of_nonneg_left hy2 (sq_nonneg r) + dsimp [pairGrad₁] + nlinarith only [sq_nonneg (p-r*(spinValue y-b)),h] + have h₂ : (pairGrad₂ a q r x)^2 ≤ 2*q^2+8*r^2 := by + have h := mul_le_mul_of_nonneg_left hx2 (sq_nonneg r) + dsimp [pairGrad₂] + nlinarith only [sq_nonneg (q-r*(spinValue x-a)),h] + have h := sq_nonneg (|pairGrad₁ b p r y|-|pairGrad₂ a q r x|) + rw [abs_mul] + nlinarith only [h,h₁,h₂,sq_abs (pairGrad₁ b p r y),sq_abs (pairGrad₂ a q r x)] + +private lemma leading_lower {a b t : ℝ} (ha : |a| ≤ 1) (hb : |b| ≤ 1) : + 1-|t| ≤ leadingCoefficient a b t := by + have ha2 : a^2 ≤ 1 := by nlinarith [sq_abs a,abs_nonneg a] + have hb2 : b^2 ≤ 1 := by nlinarith [sq_abs b,abs_nonneg b] + have hq : 0 ≤ 1-a^2-b^2+2*a^2*b^2 := by + nlinarith only [mul_nonneg (sub_nonneg.mpr ha2) (sub_nonneg.mpr hb2), + mul_nonneg (sq_nonneg a) (sq_nonneg b)] + have ht : |a*b*t| ≤ |t| := by + rw [abs_mul] + exact (mul_le_mul_of_nonneg_right (abs_mul_le_one_pair ha hb) (abs_nonneg t)).trans_eq (one_mul _) + have hs := mul_nonneg hq (sq_nonneg t) + dsimp [leadingCoefficient] + linarith only [(abs_le.mp ht).1,hs] + +private lemma signed_mean_lower {a b t : ℝ} (ha : |a| ≤ 1) + (hb : |b| ≤ 1) (ht : |t| ≤ 1/1000) (p q r : ℝ) : + -30000*|t|^3*(p^2+q^2) ≤ + pairMean 0 0 (fun x y => pairGrad₁ b p r y*pairGrad₂ a q r x*signedCoefficient a b t x y) := by + have ht4 : |t| ≤ 1/4 := ht.trans (by norm_num) + have hpoint (x y : Bool) : + -30000*|t|^3*(p^2+q^2+8*r^2) ≤ + pairGrad₁ b p r y*pairGrad₂ a q r x* + (signedCoefficient a b t x y-spinValue x*spinValue y*leadingCoefficient a b t) := by + have h := mul_le_mul (abs_pairGrad_product ha hb p q r x y) + (signedCoefficient_remainder ha hb ht4 x y) (abs_nonneg _) + (by positivity : 0 ≤ p^2+q^2+8*r^2) + have hh := neg_abs_le (pairGrad₁ b p r y*pairGrad₂ a q r x* + (signedCoefficient a b t x y-spinValue x*spinValue y*leadingCoefficient a b t)) + rw [abs_mul] at hh + nlinarith only [h,hh] + have he := pairMean_mono (a := 0) (b := 0) (by norm_num) (by norm_num) hpoint + rw [pairMean_const] at he + have hlead : pairMean 0 0 (fun x y => pairGrad₁ b p r y*pairGrad₂ a q r x* + (spinValue x*spinValue y*leadingCoefficient a b t)) = leadingCoefficient a b t*r^2 := by + calc + _ = pairMean 0 0 (fun x y => leadingCoefficient a b t* + (spinValue x*spinValue y*pairGrad₁ b p r y*pairGrad₂ a q r x)) := by + congr 1;funext x y;ring + _ = _ := by rw [pairMean_mul,uniform_cross_gradient] + simp_rw [mul_sub] at he + rw [pairMean_sub,hlead] at he + have ht3 : |t|^3 ≤ 1/1000000000 := by + calc _ ≤ (1/1000:ℝ)^3 := by gcongr + _ = _ := by norm_num + have hco : 0 ≤ leadingCoefficient a b t-240000*|t|^3 := by + linarith only [leading_lower (t := t) ha hb,ht,ht3] + nlinarith only [he,mul_nonneg hco (sq_nonneg r)] + +private def pairPrefactor (a b t : ℝ) : ℝ := + (1-a^2)*(1-b^2)*(1-t^2)/(1+t*a*b) + +private lemma residual_factorization (a b t : ℝ) (x y : Bool) : + pairBaseMass a b x y*pairDensity a b t x y*pairResidual a t x y*pairResidual b t y x = + pairPrefactor a b t / 4 * + ((spinValue x*spinValue y-t)/((1+t*a*spinValue y)*(1+t*b*spinValue x))) := by + unfold pairBaseMass pairDensity pairResidual pairPrefactor + simp only [div_eq_mul_inv,mul_inv_rev] + cases x <;> cases y <;> norm_num [spinValue] <;> ring + +private lemma variance_factorization (a b t : ℝ) (x y : Bool) : + pairBaseMass a b x y*pairDensity a b t x y*pairVariance a t y*pairVariance b t x = + pairPrefactor a b t / 4 * + ((1-t^2)*(1+a*spinValue x)*(1+b*spinValue y)*(1+t*spinValue x*spinValue y)/ + ((1+t*a*spinValue y)^2*(1+t*b*spinValue x)^2)) := by + unfold pairBaseMass pairDensity pairVariance pairPrefactor + simp only [div_eq_mul_inv,mul_inv_rev] + ring + +private lemma signed_factorization (a b t p q r : ℝ) : + pairInterMean a b t (fun x y => pairResidual a t x y*pairGrad₁ b p r y* + (pairResidual b t y x*pairGrad₂ a q r x)) + + pairInterMean a b t (fun x y => + (t+2*t^2*pairConditionalMean a t y*pairConditionalMean b t x)* + pairVariance a t y*pairVariance b t x*pairGrad₁ b p r y*pairGrad₂ a q r x) = + pairPrefactor a b t * pairMean 0 0 (fun x y => + pairGrad₁ b p r y*pairGrad₂ a q r x*signedCoefficient a b t x y) := by + unfold pairInterMean pairMean + simp only [Finset.mul_sum,← Finset.sum_add_distrib] + apply Finset.sum_congr rfl + intro x _ + apply Finset.sum_congr rfl + intro y _ + have h₁ := residual_factorization a b t x y + have h₂ := variance_factorization a b t x y + calc + _ = (pairBaseMass a b x y*pairDensity a b t x y*pairResidual a t x y*pairResidual b t y x)* + (pairGrad₁ b p r y*pairGrad₂ a q r x) + + (pairBaseMass a b x y*pairDensity a b t x y*pairVariance a t y*pairVariance b t x)* + ((t+2*t^2*pairConditionalMean a t y*pairConditionalMean b t x)* + pairGrad₁ b p r y*pairGrad₂ a q r x) := by ring + _ = _ := by + rw [h₁,h₂] + simp only [pairBaseMass,zero_mul,add_zero,one_mul] + unfold signedCoefficient + ring + +private lemma pairPrefactor_bounds {a b t : ℝ} (ha : |a| ≤ 1) + (hb : |b| ≤ 1) (ht : |t| ≤ 1/4) : + 0 ≤ pairPrefactor a b t ∧ pairPrefactor a b t ≤ 2*(1-a^2)*(1-b^2) := by + have ha2 : a^2 ≤ 1 := by nlinarith [sq_abs a,abs_nonneg a] + have hb2 : b^2 ≤ 1 := by nlinarith [sq_abs b,abs_nonneg b] + have hAB : 0 ≤ (1-a^2)*(1-b^2) := mul_nonneg (sub_nonneg.mpr ha2) (sub_nonneg.mpr hb2) + have hS := (pair_square_factor_control ht).1 + have hZ : (1/2:ℝ) ≤ 1+t*a*b := by + simpa only [mul_assoc] using (pair_factor_control ht (abs_mul_le_one_pair ha hb)).1 + have hZp : 0 < 1+t*a*b := by linarith + constructor + · exact div_nonneg (mul_nonneg hAB (by linarith : 0 ≤ 1-t^2)) hZp.le + · unfold pairPrefactor + apply (div_le_iff₀ hZp).mpr + have h := mul_le_mul_of_nonneg_left hZ hAB + have hh := mul_nonneg hAB (sq_nonneg t) + nlinarith only [h,hh] + +theorem pair_cubic_signed_bound {a b t p q r : ℝ} + (ha : |a| ≤ 1) (hb : |b| ≤ 1) (ht : |t| ≤ 1/1000) : + -pairInterMean a b t (fun x y => + (t+2*t^2*pairConditionalMean a t y*pairConditionalMean b t x)* + pairVariance a t y*pairVariance b t x*pairGrad₁ b p r y*pairGrad₂ a q r x) - + 1920000*|t|^3*pairInterMean a b t (fun x y => + pairVariance a t y*(pairGrad₁ b p r y)^2 + + pairVariance b t x*(pairGrad₂ a q r x)^2) ≤ + pairInterMean a b t (fun x y => pairResidual a t x y*pairGrad₁ b p r y* + (pairResidual b t y x*pairGrad₂ a q r x)) := by + have ht4 : |t| ≤ 1/4 := ht.trans (by norm_num) + have hp := pairPrefactor_bounds ha hb ht4 + have hQ := mul_le_mul_of_nonneg_left (signed_mean_lower ha hb ht p q r) hp.1 + rw [← signed_factorization] at hQ + have he₁ := pair_energy_lower (p := p) (r := r) ha hb ht4 + have he₂ := pair_second_energy_lower (s := q) (r := r) ha hb ht4 + have hcost : pairPrefactor a b t*(p^2+q^2) ≤ 64*pairInterMean a b t (fun x y => + pairVariance a t y*(pairGrad₁ b p r y)^2+ + pairVariance b t x*(pairGrad₂ a q r x)^2) := by + rw [pairInterMean_add] + have h := mul_le_mul_of_nonneg_right hp.2 (add_nonneg (sq_nonneg p) (sq_nonneg q)) + nlinarith only [h,he₁,he₂] + have h := mul_le_mul_of_nonneg_left hcost (show 0 ≤ 30000*|t|^3 by positivity) + nlinarith only [hQ,h] + +end SKRatio.TwoSpin + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Certificates/CertifiedBatches.lean b/lean/OAI/Probability/SKRatio/Certificates/CertifiedBatches.lean new file mode 100644 index 0000000000000000000000000000000000000000..24b2420502c57141e4ab4f3fc8c213b0d1db6640 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Certificates/CertifiedBatches.lean @@ -0,0 +1,63 @@ +import Mathlib +import OAI.Probability.SKRatio.Certificates.CertifiedQuadrature +import OAI.Probability.SKRatio.Certificates.CertifiedGaussian + +namespace OAI + +noncomputable section +open Real Set MeasureTheory +namespace SKRatio.Certificate + +def sumBoxes (B : ℕ → Box) : ℕ → Box + | 0 => Box.rat 0 + | n+1 => Box.add (sumBoxes B n) (B n) + +lemma integral_batches (e : Expr) (a h : ℚ) (k m : ℕ) (B : ℕ → Box) + (hc : ∀ i < m, e.check (a+i*(k*h)) h k (B i) = true) : + IntervalIntegrable e.val volume a (a+m*(k*h):ℚ) ∧ + (∫ x in (a:ℝ)..(a+m*(k*h):ℚ), e.val x) ∈ sumBoxes B m := by + induction m with + | zero => + simp only [sumBoxes,Nat.cast_zero,zero_mul,add_zero,IntervalIntegrable.refl,intervalIntegral.integral_same] + exact ⟨trivial,by simpa only [Rat.cast_zero] using Box.mem_rat 0⟩ + | succ m hm => + have ht := hm (fun i hi => hc i (lt_trans hi (Nat.lt_succ_self m))) + have hn := e.check_sound (hc m (Nat.lt_succ_self m)) + have he : a+(m:ℚ)*(k*h)+k*h = a+(m+1:ℕ)*(k*h) := by push_cast; ring + rw [he] at hn + refine ⟨ht.1.trans hn.1,?_⟩ + rw [←intervalIntegral.integral_add_adjacent_intervals ht.1 hn.1] + exact Box.mem_add ht.2 hn.2 + +def normalizerBox : Box := ⟨39894227/100000000,39894229/100000000⟩ +lemma normalizer_mem : gaussianNormalizer ∈ normalizerBox := by + change ((39894227/100000000:ℚ):ℝ) ≤ gaussianNormalizer ∧ gaussianNormalizer ≤ ((39894229/100000000:ℚ):ℝ) + norm_num only [Rat.cast_div,Rat.cast_ofNat] + exact normalizer_bounds + +def normalizedBox (B : Box) : Box := Box.mul normalizerBox (B.widen (1/1000000)) + +def batchCheck (B : ℕ → Box) (m : ℕ) (A : Box) : Bool := + A.contains (normalizedBox (sumBoxes B m)) + +lemma gaussian_certificate {e : Expr} {β : ℝ} {f : ℝ → ℝ} {B : ℕ → Box} {A : Box} + {h : ℚ} {k : ℕ} (hh : (k:ℚ)*h=1/2) + (hfun : ∀ x, e.val x = f (β^2+β*x)*gaussianWeight x) + (hf : Measurable f) (hb : ∀ x, |f (β^2+β*x)| ≤ 32*(1+x^2)) + (hc : ∀ i : ℕ, i < 40 → e.check (-10+(i:ℚ)*(k*h)) h k (B i) = true) + (hsum : batchCheck B 40 A = true) : (∫ h, f h ∂Scalar.fieldLaw β) ∈ A := by + have ht := integral_batches e (-10) h k 40 B hc + rw [hh] at ht + norm_num only [show (-10:ℚ)+40*(1/2) = 10 by norm_num] at ht + have htail := gaussian_truncation (f := fun x => f (β^2+β*x)) + (hf.comp (by fun_prop)).aestronglyMeasurable hb + have hI : (∫ x in (-10:ℝ)..10, f (β^2+β*x)*gaussianWeight x) ∈ sumBoxes B 40 := by + simpa only [hfun,Rat.cast_neg,Rat.cast_ofNat] using ht.2 + have hfull := Box.mem_widen (y := ∫ x, f (β^2+β*x)*gaussianWeight x) (r := 1/1000000) hI (by simpa only [Rat.cast_div,Rat.cast_one,Rat.cast_ofNat,abs_sub_comm] using htail) + rw [affine_gaussian_integral β hf] + exact Box.mem_of_contains hsum (Box.mem_mul normalizer_mem hfull) +end SKRatio.Certificate + +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Certificates/CertifiedCoefficient.lean b/lean/OAI/Probability/SKRatio/Certificates/CertifiedCoefficient.lean new file mode 100644 index 0000000000000000000000000000000000000000..851ac44b6bcb3d8bd4c1c6a30b706acb7acf4c2b --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Certificates/CertifiedCoefficient.lean @@ -0,0 +1,112 @@ +import Mathlib +import OAI.Probability.SKRatio.Variational.ScalarVariance +import OAI.Probability.SKRatio.Certificates.CertifiedFunctionBounds + +namespace OAI + +noncomputable section +open scoped Topology ENNReal NNReal +open Real MeasureTheory ProbabilityTheory +namespace SKRatio.Certificate +open Scalar + +lemma memLp_approxF (β A C : ℝ) : MemLp (approxF β A C) 2 (fieldLaw β) := by + convert! (((((memLp_field_v β).add ((memLp_field β).const_mul A)).add + (memLp_mv.const_mul (2*β^2))).add (memLp_v.const_mul + (1/2-β^2*A/(64/100-(19/100)*A)))).add + (memLp_m.const_mul (12/100:ℝ))).add (memLp_g.const_mul (3*β^2*C)) using 1 + ext h + dsimp [approxF] + ring + +lemma sd_le_of_center {μ : Measure ℝ} [IsProbabilityMeasure μ] {f : ℝ → ℝ} + (hf : MemLp f 2 μ) {c B : ℝ} (hB : 0 ≤ B) + (hc : (∫ x, (f x-c)^2 ∂μ) ≤ B^2) : sd μ f ≤ B := by + have ht := (sd_min_center hf c).trans hc + nlinarith only [ht,sd_nonneg (μ := μ) f,hB] + +lemma sd_unit {μ : Measure ℝ} [IsProbabilityMeasure μ] {f : ℝ → ℝ} + (hf : MemLp f 2 μ) (hb : ∀ h, |f h| ≤ 1) : sd μ f ≤ 1 := by + apply sd_le_of_center hf (c := 0) (by norm_num) + simp only [sub_zero,one_pow] + have ht := integral_mono hf.integrable_sq (integrable_const (μ := μ) (1:ℝ)) + (fun h => by nlinarith [hb h,sq_abs (f h),abs_nonneg (f h)]) + simpa only [integral_const,probReal_univ,smul_eq_mul,one_mul] using ht + +lemma sd_field (β : ℝ) : sd (fieldLaw β) (fun h : ℝ => h) = |β| := by + have hh := variance_id_gaussianReal (μ := β^2) (v := variance β) + rw [variance_eq_integral measurable_id.aemeasurable] at hh + change ∫ h, (h-(∫ t, t ∂fieldLaw β))^2 ∂fieldLaw β = _ at hh + rw [variance_coe] at hh + unfold sd l2Norm centered + rw [hh,sqrt_sq_eq_abs] + +lemma ratio_coefficient_error {A B : ℝ} (hA : 0 ≤ A) (hA1 : A ≤ 1) + (hB : 0 ≤ B) (hB1 : B ≤ 1) : + |A/(64/100-(19/100)*A)-B/(64/100-(19/100)*B)| ≤ 4*|A-B| := by + have hDA : 45/100 ≤ 64/100-(19/100)*A := by linarith + have hDB : 45/100 ≤ 64/100-(19/100)*B := by linarith + have hDA0 : 0 < 64/100-(19/100)*A := by linarith + have hDB0 : 0 < 64/100-(19/100)*B := by linarith + have he : A/(64/100-(19/100)*A)-B/(64/100-(19/100)*B) = + (64/100)*(A-B)/((64/100-(19/100)*A)*(64/100-(19/100)*B)) := by + rw [div_sub_div A B hDA0.ne' hDB0.ne'] + congr 1 + ring + rw [he,abs_div,abs_mul,abs_of_pos (by norm_num : (0:ℝ) < 64/100), + abs_of_pos (mul_pos hDA0 hDB0)] + apply (div_le_iff₀ (mul_pos hDA0 hDB0)).mpr + have hp : (104/625:ℝ) ≤ + (64/100-(19/100)*A)*(64/100-(19/100)*B) := by + nlinarith only [hA1,hB1,mul_nonneg hA hB] + have hh := mul_le_mul_of_nonneg_right hp (abs_nonneg (A-B)) + nlinarith only [hh,abs_nonneg (A-B)] + +lemma approxF_error {β A C : ℝ} (hβ : 0 ≤ β) (hb : β ≤ 1/2) + (hA : 0 ≤ A) (hA1 : A ≤ 1) : + sd (fieldLaw β) (F β) ≤ sd (fieldLaw β) (approxF β A C)+ + 2*|a β-A|+|G β-C| := by + let ca := a β-A + let cv := β^2*(A/(64/100-(19/100)*A)-a β/l β) + let cg := 3*β^2*(G β-C) + have he (h : ℝ) : F β h-approxF β A C h = ca*h+cv*v h+cg*g h := by + dsimp [F,approxF,ca,cv,cg] + ring + have hi : MemLp (fun h : ℝ => ca*h) 2 (fieldLaw β) := (memLp_field β).const_mul ca + have hiv : MemLp (fun h => cv*v h) 2 (fieldLaw β) := memLp_v.const_mul cv + have hig : MemLp (fun h => cg*g h) 2 (fieldLaw β) := memLp_g.const_mul cg + have h1 := sd_add hi hiv + have h2 := sd_add (hi.add hiv) hig + have hdiff := (le_abs_self _).trans (abs_sd_sub_le (memLp_F β) (memLp_approxF β A C)) + simp_rw [he] at hdiff + have hid : sd (fieldLaw β) (fun h : ℝ => ca*h) = |ca| *β := by + change sd (fieldLaw β) (fun h => ca*(fun t : ℝ => t) h) = _ + rw [sd_const_mul,sd_field,abs_of_nonneg hβ] + simp only [Pi.add_def,sd_const_mul,hid] at h1 h2 + have hcv : |cv| ≤ |a β-A| := by + have hh := ratio_coefficient_error (a_nonneg β) (a_le_one β) hA hA1 + rw [←l_eq,abs_sub_comm] at hh + dsimp [cv] + rw [abs_mul,abs_of_nonneg (sq_nonneg β)] + have hp := mul_le_mul_of_nonneg_left hh (sq_nonneg β) + have hβ2 : β^2 ≤ (1/4:ℝ) := by nlinarith + have hh' := mul_le_mul_of_nonneg_right hβ2 (abs_nonneg (a β-A)) + nlinarith only [hp,hh'] + have hcg : |cg| ≤ |G β-C| := by + dsimp [cg] + rw [abs_mul,abs_of_nonneg (by positivity : 0 ≤ 3*β^2)] + have hβ2 : 3*β^2 ≤ 1 := by nlinarith + nlinarith only [mul_le_mul_of_nonneg_right hβ2 (abs_nonneg (G β-C))] + have hva := sd_unit (μ := fieldLaw β) memLp_v abs_v_le + have hga := sd_unit (μ := fieldLaw β) memLp_g abs_g_le_one + have hpv := mul_le_mul hcv hva (sd_nonneg (μ := fieldLaw β) v) (abs_nonneg (a β-A)) + have hpg := mul_le_mul hcg hga (sd_nonneg (μ := fieldLaw β) g) (abs_nonneg (G β-C)) + have hpa := mul_le_mul_of_nonneg_left hb (abs_nonneg ca) + dsimp [ca] at h1 h2 hpa + nlinarith only [hdiff,h1,h2,hpv,hpg,hpa,abs_nonneg (a β-A)] + +end SKRatio.Certificate + +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Certificates/CertifiedConstants.lean b/lean/OAI/Probability/SKRatio/Certificates/CertifiedConstants.lean new file mode 100644 index 0000000000000000000000000000000000000000..71313ad7a7491fdc1f24584b9e485fb59c14c222 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Certificates/CertifiedConstants.lean @@ -0,0 +1,95 @@ +import Mathlib +import OAI.Probability.SKRatio.Certificates.CertifiedInterpolation + +namespace OAI + +noncomputable section +open Real MeasureTheory +namespace SKRatio.Certificate +open Scalar + +lemma sqrt_densityFactor_bound {j z t : ℝ} (hj : 0 < j) (hz : 0 ≤ z) (ht : 0 ≤ t) + (hexp : (z^2-j^2)/2 < 1) + (harith : z/j/(1-(z^2-j^2)/2) ≤ t^2) : sqrt (densityFactor j z) ≤ t := by + have hpos : 0 < 1-(z^2-j^2)/2 := by linarith only [hexp] + have he : exp ((z^2-j^2)/2) ≤ 1/(1-(z^2-j^2)/2) := by + have hh := one_div_le_one_div_of_le hpos (show 1-(z^2-j^2)/2 ≤ exp (-((z^2-j^2)/2)) by + linarith only [add_one_le_exp (-((z^2-j^2)/2))]) + simpa only [exp_neg,one_div,inv_inv] using hh + apply (sqrt_le_iff).mpr + refine ⟨ht,?_⟩ + have hm := mul_le_mul_of_nonneg_left he (div_nonneg hz hj.le) + unfold densityFactor + exact hm.trans (by simpa only [mul_one_div] using harith) + +def X0 : Enclosures where + av := ⟨2777/3125,22291/25000⟩ + gv := ⟨110463/200000,111063/200000⟩ + mv := ⟨9979/125000,5177/62500⟩ + rv := ⟨0,33/2000⟩ + vs := ⟨0,13/100⟩ + gs := ⟨0,43/500⟩ + ms := ⟨0,239/1000⟩ + fs := ⟨0,333/500⟩ + +def X1 : Enclosures where + av := ⟨214787/250000,215537/250000⟩ + gv := ⟨544267/1000000,547267/1000000⟩ + mv := ⟨94251/1000000,97251/1000000⟩ + rv := ⟨0,1/50⟩ + vs := ⟨0,157/1000⟩ + gs := ⟨0,19/200⟩ + ms := ⟨0,249/1000⟩ + fs := ⟨0,737/1000⟩ + +def X2 : Enclosures where + av := ⟨207709/250000,208459/250000⟩ + gv := ⟨26771/50000,26921/50000⟩ + mv := ⟨21177/200000,21777/200000⟩ + rv := ⟨0,47/2000⟩ + vs := ⟨0,181/1000⟩ + gs := ⟨0,103/1000⟩ + ms := ⟨0,127/500⟩ + fs := ⟨0,397/500⟩ + +def X3 : Enclosures where + av := ⟨405599/500000,407099/500000⟩ + gv := ⟨132171/250000,132921/250000⟩ + mv := ⟨7051/62500,14477/125000⟩ + rv := ⟨0,13/500⟩ + vs := ⟨0,49/250⟩ + gs := ⟨0,109/1000⟩ + ms := ⟨0,32/125⟩ + fs := ⟨0,207/250⟩ + +def X4 : Enclosures where + av := ⟨397223/500000,398723/500000⟩ + gv := ⟨522571/1000000,525571/1000000⟩ + mv := ⟨118053/1000000,121053/1000000⟩ + rv := ⟨0,7/250⟩ + vs := ⟨0,209/1000⟩ + gs := ⟨0,23/200⟩ + ms := ⟨0,257/1000⟩ + fs := ⟨0,171/200⟩ + +lemma density0 : sqrt (densityFactor (7/20) (2/5)) ≤ 27/25 := by + apply sqrt_densityFactor_bound <;> norm_num +lemma check0 : interpolationCheck (7/20) (2/5) (27/25) X0 X1 = true := by decide +kernel + +lemma density1 : sqrt (densityFactor (2/5) (89/200)) ≤ 1067/1000 := by + apply sqrt_densityFactor_bound <;> norm_num +lemma check1 : interpolationCheck (2/5) (89/200) (1067/1000) X1 X2 = true := by decide +kernel + +lemma density2 : sqrt (densityFactor (89/200) (19/40)) ≤ 521/500 := by + apply sqrt_densityFactor_bound <;> norm_num +lemma check2 : interpolationCheck (89/200) (19/40) (521/500) X2 X3 = true := by decide +kernel + +lemma density3 : sqrt (densityFactor (19/40) (1/2)) ≤ 517/500 := by + apply sqrt_densityFactor_bound <;> norm_num +lemma check3 : interpolationCheck (19/40) (1/2) (517/500) X3 X4 = true := by decide +kernel + +end SKRatio.Certificate + +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Certificates/CertifiedEndpointAssembly.lean b/lean/OAI/Probability/SKRatio/Certificates/CertifiedEndpointAssembly.lean new file mode 100644 index 0000000000000000000000000000000000000000..572ee3853418b327a243df8baeb9d8625c461e16 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Certificates/CertifiedEndpointAssembly.lean @@ -0,0 +1,61 @@ +import Mathlib +import OAI.Probability.SKRatio.Variational.ScalarEnvelope +import OAI.Probability.SKRatio.Certificates.CertifiedFunctions + +namespace OAI + +noncomputable section +open Real MeasureTheory +namespace SKRatio.Certificate +open Scalar + +lemma endpointK_zero_integral (β A C M Q : ℝ) : endpointK 0 = + ∫ h, scalarFunction β A C M Q 8 h ∂fieldLaw (1/2) := by + unfold endpointK + norm_num only [zero_pow (by decide : (2:ℕ) ≠ 0),sub_zero] + rw [←integral_const_mul] + apply integral_congr_ae + exact ae_of_all _ (fun h => by norm_num [scalarFunction]; ring) + +lemma endpointK_one_integral (β A C M Q : ℝ) : endpointK 1 = + ∫ h, scalarFunction β A C M Q 9 h ∂fieldLaw (1/2) := by + unfold endpointK + norm_num only [one_pow,sub_self,zero_add] + rw [←integral_const_mul] + apply integral_congr_ae + exact ae_of_all _ (fun h => by norm_num [scalarFunction]; ring) + +lemma endpointD_zero_integral (β A C M Q : ℝ) : endpointD 0 = + ∫ h, scalarFunction β A C M Q 10 h ∂fieldLaw (1/2) := by + unfold endpointD + simp only [sub_zero] + rw [←integral_const_mul] + apply integral_congr_ae + exact ae_of_all _ (fun h => by norm_num [scalarFunction]; ring) + +lemma endpointD_prime_integral (β A C M Q : ℝ) : endpointDPrime = + ∫ h, scalarFunction β A C M Q 11 h ∂fieldLaw (1/2) := by + unfold endpointDPrime + rw [←integral_const_mul] + apply integral_congr_ae + exact ae_of_all _ (fun h => by norm_num [scalarFunction]; ring) + +lemma endpointD_one_integral (β A C M Q : ℝ) : endpointD 1 = + ∫ h, scalarFunction β A C M Q 12 h ∂fieldLaw (1/2) := by + unfold endpointD + norm_num only [show (2:ℝ)-1=1 by norm_num] + rw [←integral_const_mul] + apply integral_congr_ae + apply ae_of_all + intro h + have hd : 1-m h ≠ 0 := by linarith only [(m_bounds h).2] + norm_num only [scalarFunction] + rw [v_factor,w] + field_simp + ring + +end SKRatio.Certificate + +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Certificates/CertifiedEndpoints.lean b/lean/OAI/Probability/SKRatio/Certificates/CertifiedEndpoints.lean new file mode 100644 index 0000000000000000000000000000000000000000..eda8cbc291720a5fcf098e40eb953806e7415bf9 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Certificates/CertifiedEndpoints.lean @@ -0,0 +1,56 @@ +import Mathlib +import OAI.Probability.SKRatio.Certificates.CertifiedEndpointAssembly +import OAI.Probability.SKRatio.Certificates.ScalarDataJ4K8 +import OAI.Probability.SKRatio.Certificates.ScalarDataJ4K9 +import OAI.Probability.SKRatio.Certificates.ScalarDataJ4K10 +import OAI.Probability.SKRatio.Certificates.ScalarDataJ4K11 +import OAI.Probability.SKRatio.Certificates.ScalarDataJ4K12 + +namespace OAI + +noncomputable section +open Real MeasureTheory +namespace SKRatio.Certificate +open Scalar + +lemma endpointK_zero_bound : endpointK 0 ≤ 4280/10000 := by + rw [endpointK_zero_integral (1/2) (397973/500000) (524071/1000000) + (119553/1000000) (702377/1000000)] + convert! Data.J4K8.integral_bound.2 using 1; norm_num + +lemma endpointK_one_bound : endpointK 1 ≤ 902/10000 := by + rw [endpointK_one_integral (1/2) (397973/500000) (524071/1000000) + (119553/1000000) (702377/1000000)] + convert! Data.J4K9.integral_bound.2 using 1; norm_num + +lemma endpointD_zero_bound : endpointD 0 ≤ 929/10000 := by + rw [endpointD_zero_integral (1/2) (397973/500000) (524071/1000000) + (119553/1000000) (702377/1000000)] + convert! Data.J4K10.integral_bound.2 using 1; norm_num + +lemma endpointD_one_bound : endpointD 1 ≤ 2292/10000 := by + rw [endpointD_one_integral (1/2) (397973/500000) (524071/1000000) + (119553/1000000) (702377/1000000)] + convert! Data.J4K12.integral_bound.2 using 1; norm_num + +lemma endpointD_prime_lower : 520/10000 ≤ endpointDPrime := by + rw [endpointD_prime_integral (1/2) (397973/500000) (524071/1000000) + (119553/1000000) (702377/1000000)] + convert! Data.J4K11.integral_bound.1 using 1; norm_num + +lemma endpointD_prime_upper : endpointDPrime ≤ 526/10000 := by + rw [endpointD_prime_integral (1/2) (397973/500000) (524071/1000000) + (119553/1000000) (702377/1000000)] + convert! Data.J4K11.integral_bound.2 using 1; norm_num + +theorem diagonal_envelope {β : ℝ} (hβ : 0 < β) (hβh : β ≤ 1/2) (h : ℝ) : + multiplier h+diagonal (fieldLaw β) β h+cost (fieldLaw β) β h ≤ 9789/10000 := + envelope_of_endpoint_data endpointK_zero_bound endpointK_one_bound + endpointD_zero_bound endpointD_one_bound endpointD_prime_lower endpointD_prime_upper + hβ hβh h + +end SKRatio.Certificate + +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Certificates/CertifiedFunctionBounds.lean b/lean/OAI/Probability/SKRatio/Certificates/CertifiedFunctionBounds.lean new file mode 100644 index 0000000000000000000000000000000000000000..e5989297ec954868d10a3bcaeaa30da91fdf39fc --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Certificates/CertifiedFunctionBounds.lean @@ -0,0 +1,143 @@ +import Mathlib +import OAI.Probability.SKRatio.Certificates.CertifiedFunctions + +namespace OAI + +noncomputable section +open scoped Topology ENNReal NNReal +open Real MeasureTheory ProbabilityTheory +namespace SKRatio.Certificate +open Scalar + +lemma abs_v_le (h : ℝ) : |v h| ≤ 1 := by rw [abs_of_pos (v_pos h)]; exact v_le_one h +lemma abs_m_le (h : ℝ) : |m h| ≤ 1 := (abs_lt.mpr (m_bounds h)).le +lemma abs_mv_le (h : ℝ) : |m h*v h| ≤ 1 := by + rw [abs_mul] + nlinarith [mul_le_mul (abs_m_le h) (abs_v_le h) (abs_nonneg (v h)) (by norm_num : (0:ℝ) ≤ 1)] + +lemma approx_coefficient_bound {β A : ℝ} (hβ : 0 ≤ β) (hb : β ≤ 1/2) + (hA : 0 ≤ A) (hA1 : A ≤ 1) : |1/2-β^2*A/(64/100-(19/100)*A)| ≤ 1 := by + have hd : 0 < 64/100-(19/100)*A := by linarith + have hp : 0 ≤ β^2*A/(64/100-(19/100)*A) := by positivity + have hu : β^2*A/(64/100-(19/100)*A) ≤ 3/2 := by + apply (div_le_iff₀ hd).mpr + have hh : β^2 ≤ (1/4:ℝ) := by nlinarith + have hh' := mul_le_mul_of_nonneg_right hh hA + nlinarith + exact abs_le.mpr ⟨by linarith,by linarith⟩ + +lemma approxF_bound {β A C Q : ℝ} (hβ : 0 ≤ β) (hb : β ≤ 1/2) + (hA : 0 ≤ A) (hA1 : A ≤ 1) (hC : 0 ≤ C) (hC1 : C ≤ 1) + (hQ : 0 ≤ Q) (hQ1 : Q ≤ 1) (x : ℝ) : + |approxF β A C (β^2+β*x)-Q| ≤ |x|+4 := by + let h := β^2+β*x + have hh : |h| ≤ 1/4+|x|/2 := by + have ht := abs_add_le (β^2) (β*x) + rw [abs_of_nonneg (sq_nonneg β),abs_mul,abs_of_nonneg hβ] at ht + have hm := mul_le_mul_of_nonneg_right hb (abs_nonneg x) + dsimp [h] + nlinarith + have hp : |(v h+A)*h| ≤ 2*|h| := by + rw [abs_mul,abs_of_nonneg (by positivity [v_pos h] : 0 ≤ v h+A)] + exact mul_le_mul_of_nonneg_right (by linarith [v_le_one h]) (abs_nonneg h) + have h2 : |2*β^2*(m h*v h)| ≤ 1/2 := by + rw [abs_mul,abs_of_nonneg (by positivity : 0 ≤ 2*β^2)] + have ht := mul_le_mul_of_nonneg_left (abs_mv_le h) (by positivity : 0 ≤ 2*β^2) + nlinarith + have h3 : |(1/2-β^2*A/(64/100-(19/100)*A))*v h| ≤ 1 := by + rw [abs_mul] + simpa using mul_le_mul (approx_coefficient_bound hβ hb hA hA1) (abs_v_le h) + (abs_nonneg _) (by norm_num : (0:ℝ) ≤ 1) + have h4 : |(12/100:ℝ)*m h| ≤ 12/100 := by + rw [abs_mul,abs_of_pos (by norm_num : (0:ℝ) < 12/100)] + nlinarith [abs_m_le h] + have h5 : |3*β^2*C*g h| ≤ 3/4 := by + rw [abs_mul,abs_of_nonneg (by positivity : 0 ≤ 3*β^2*C)] + have ht := mul_le_mul_of_nonneg_left (abs_g_le_one h) (by positivity : 0 ≤ 3*β^2*C) + have hh' := mul_le_mul_of_nonneg_left hC1 (by positivity : 0 ≤ 3*β^2) + nlinarith + have hsum : |approxF β A C h-Q| ≤ 2*|h|+237/100+Q := by + unfold approxF + calc + _ ≤ |(v h+A)*h+2*β^2*(m h*v h)+(1/2-β^2*A/(64/100-(19/100)*A))*v h+ + (12/100)*m h+3*β^2*C*g h|+|Q| := abs_sub _ _ + _ ≤ ((((|(v h+A)*h|+|2*β^2*(m h*v h)|)+|(1/2-β^2*A/(64/100-(19/100)*A))*v h|)+ + |(12/100)*m h|)+|3*β^2*C*g h|)+|Q| := by + gcongr + exact (abs_add_le _ _).trans (add_le_add + ((abs_add_le _ _).trans (add_le_add + ((abs_add_le _ _).trans (add_le_add (abs_add_le _ _) le_rfl)) le_rfl)) le_rfl) + _ ≤ _ := by rw [abs_of_nonneg hQ]; linarith only [hp,h2,h3,h4,h5] + change |approxF β A C h-Q| ≤ _ + linarith only [hsum,hh,hQ1] + +lemma bounded_center_square {u c : ℝ} (hu : |u| ≤ 1) (hc : 0 ≤ c) (hc1 : c ≤ 1) : + |(u-c)^2| ≤ 4 := by + rw [abs_of_nonneg (sq_nonneg _)] + have h := abs_sub u c + rw [abs_of_nonneg hc] at h + have hh : |u-c| ≤ 2 := by linarith + simpa only [sq_abs,show (2:ℝ)^2=4 by norm_num] using (sq_le_sq₀ (abs_nonneg (u-c)) (by norm_num : (0:ℝ) ≤ 2)).mpr hh + +lemma scalarFunction_bound {β A C M Q : ℝ} (hβ : 0 ≤ β) (hb : β ≤ 1/2) + (hA : 0 ≤ A) (hA1 : A ≤ 1) (hC : 0 ≤ C) (hC1 : C ≤ 1) + (hM : 0 ≤ M) (hM1 : M ≤ 1) (hQ : 0 ≤ Q) (hQ1 : Q ≤ 1) + (k : ℕ) (x : ℝ) : |scalarFunction β A C M Q k (β^2+β*x)| ≤ 32*(1+x^2) := by + let h := β^2+β*x + have ht : (4:ℝ) ≤ 32*(1+x^2) := by nlinarith [sq_nonneg x] + have hv := v_le_one h + have hv0 := (v_pos h).le + have hL := multiplier_pos h + have hL0 := multiplier_strict_pos h + have hm := m_bounds h + have hd : 0 < 2-m h := by linarith + have hd1 : 1 ≤ 2-m h := by linarith + have hv2 : v h^2 ≤ 1 := by nlinarith + have hs : |(approxF β A C h-Q)^2| ≤ 32*(1+x^2) := by + have hh := approxF_bound hβ hb hA hA1 hC hC1 hQ hQ1 x + rw [abs_of_nonneg (sq_nonneg _)] + have hs := (sq_le_sq₀ (abs_nonneg _) (by positivity : 0 ≤ |x|+4)).mpr hh + rw [sq_abs] at hs + nlinarith [sq_nonneg (|x|-1),sq_abs x] + unfold scalarFunction + split + · exact (abs_v_le h).trans ((by norm_num : (1:ℝ) ≤ 4).trans ht) + · exact (abs_g_le_one h).trans ((by norm_num : (1:ℝ) ≤ 4).trans ht) + · exact (abs_mv_le h).trans ((by norm_num : (1:ℝ) ≤ 4).trans ht) + · rw [abs_of_nonneg (rho_nonneg h)] + exact (rho_le_one h).trans ((by norm_num : (1:ℝ) ≤ 4).trans ht) + · exact (bounded_center_square (abs_v_le h) hA hA1).trans ht + · exact (bounded_center_square (abs_g_le_one h) hC hC1).trans ht + · exact (bounded_center_square (abs_mv_le h) hM hM1).trans ht + · exact hs + · apply le_trans _ ht + rw [abs_of_nonneg (by positivity : 0 ≤ (1+v h)^2/multiplier h/16)] + apply (div_le_iff₀ (by norm_num : (0:ℝ) < 16)).mpr + apply (div_le_iff₀ hL0).mpr + nlinarith + · apply le_trans _ ht + rw [abs_of_nonneg (by positivity : 0 ≤ v h^2/multiplier h/16)] + apply (div_le_iff₀ (by norm_num : (0:ℝ) < 16)).mpr + apply (div_le_iff₀ hL0).mpr + nlinarith + · apply le_trans _ ht + rw [abs_of_nonneg (by positivity : 0 ≤ v h^2/(2-m h)/4)] + apply (div_le_iff₀ (by norm_num : (0:ℝ) < 4)).mpr + apply (div_le_iff₀ hd).mpr + nlinarith + · apply le_trans _ ht + rw [abs_of_nonneg (by positivity : 0 ≤ v h^2/(2-m h)^2/4)] + apply (div_le_iff₀ (by norm_num : (0:ℝ) < 4)).mpr + apply (div_le_iff₀ (sq_pos_of_pos hd)).mpr + nlinarith + · apply le_trans _ ht + have hm' : 0 ≤ 1+m h := by linarith + rw [abs_of_nonneg (by positivity : 0 ≤ v h*(1+m h)/4)] + have ht' := mul_le_mul hv (show 1+m h ≤ 2 by linarith) hm' (by norm_num : (0:ℝ) ≤ 1) + nlinarith + +end SKRatio.Certificate + +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Certificates/CertifiedFunctions.lean b/lean/OAI/Probability/SKRatio/Certificates/CertifiedFunctions.lean new file mode 100644 index 0000000000000000000000000000000000000000..894c213a0f1d89eada8ea0196934c0c3d0382336 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Certificates/CertifiedFunctions.lean @@ -0,0 +1,126 @@ +import Mathlib +import OAI.Probability.SKRatio.Variational.ScalarCoherent +import OAI.Probability.SKRatio.Certificates.CertifiedJet +import OAI.Probability.SKRatio.Certificates.CertifiedGaussian + +namespace OAI + +noncomputable section +open Real MeasureTheory ProbabilityTheory +namespace SKRatio.Certificate +open Scalar + +namespace Expr +instance : Add Expr := ⟨Expr.add⟩ +instance : Neg Expr := ⟨Expr.neg⟩ +instance : Sub Expr := ⟨fun a b => Expr.add a (Expr.neg b)⟩ +instance : Mul Expr := ⟨Expr.mul⟩ +instance : Div Expr := ⟨fun a b => Expr.mul a (Expr.inv b)⟩ +instance (n : ℕ) : OfNat Expr n := ⟨Expr.rat n⟩ +@[simp] lemma val_add (a b : Expr) (x : ℝ) : (a+b).val x = a.val x+b.val x := rfl +@[simp] lemma val_sub (a b : Expr) (x : ℝ) : (a-b).val x = a.val x-b.val x := rfl +@[simp] lemma val_mul (a b : Expr) (x : ℝ) : (a*b).val x = a.val x*b.val x := rfl +@[simp] lemma val_div (a b : Expr) (x : ℝ) : (a/b).val x = a.val x/b.val x := rfl +@[simp] lemma val_ofNat (n : ℕ) (x : ℝ) : (ofNat(n) : Expr).val x = n := by + change ((n:ℚ):ℝ) = n + norm_cast +end Expr + +def approxF (β A C h : ℝ) : ℝ := (v h+A)*h+2*β^2*(m h*v h)+ + (1/2-β^2*A/(64/100-(19/100)*A))*v h+(12/100)*m h+3*β^2*C*g h + +def scalarFunction (β A C M Q : ℝ) (k : ℕ) (h : ℝ) : ℝ := match k with + | 0 => v h + | 1 => g h + | 2 => m h*v h + | 3 => rho h + | 4 => (v h-A)^2 + | 5 => (g h-C)^2 + | 6 => (m h*v h-M)^2 + | 7 => (approxF β A C h-Q)^2 + | 8 => (1+v h)^2/multiplier h/16 + | 9 => v h^2/multiplier h/16 + | 10 => v h^2/(2-m h)/4 + | 11 => v h^2/(2-m h)^2/4 + | _ => v h*(1+m h)/4 + +def scalarExpr (β A C M Q : ℚ) (k : ℕ) (h : Expr) : Expr := + let m := Expr.tanh h + let v := 1-Expr.sq m + let g := v/(Expr.rat (7/4)-m) + let L := Expr.rat (45/100)+Expr.rat (1/4)*Expr.sq m-Expr.rat (6/100)*m + let F := (v+Expr.rat A)*h+Expr.rat (2*β^2)*(m*v)+ + Expr.rat (1/2-β^2*A/(64/100-(19/100)*A))*v+ + Expr.rat (12/100)*m+Expr.rat (3*β^2*C)*g + match k with + | 0 => v + | 1 => g + | 2 => m*v + | 3 => Expr.rat (1/2)*((1+m)*v)-Expr.rat (3/2)*Expr.sq g + | 4 => Expr.sq (v-Expr.rat A) + | 5 => Expr.sq (g-Expr.rat C) + | 6 => Expr.sq (m*v-Expr.rat M) + | 7 => Expr.sq (F-Expr.rat Q) + | 8 => Expr.rat (1/16)*(Expr.sq (1+v)/L) + | 9 => Expr.rat (1/16)*(Expr.sq v/L) + | 10 => Expr.rat (1/4)*(Expr.sq v/(2-m)) + | 11 => Expr.rat (1/4)*(Expr.sq v/Expr.sq (2-m)) + | _ => Expr.rat (1/4)*(v*(1+m)) + +def integrandExpr (β A C M Q : ℚ) (k : ℕ) : Expr := + (scalarExpr β A C M Q k (Expr.rat (β^2)+Expr.rat β*Expr.var))* + (Expr.exp (Expr.rat (-1/2)*Expr.sq Expr.var)) + +lemma scalarExpr_val (β A C M Q : ℚ) (k : ℕ) (h : Expr) (x : ℝ) : + (scalarExpr β A C M Q k h).val x = scalarFunction β A C M Q k (h.val x) := by + have hg : (7/4:ℝ)-Real.tanh (h.val x) = w (h.val x)+3/4 := by unfold w m; ring + unfold scalarExpr scalarFunction + split <;> simp only [Expr.val_sub,Expr.val_div, + Expr.val,Rat.cast_sub,Rat.cast_mul,Rat.cast_div,Rat.cast_pow, + Rat.cast_ofNat,Rat.cast_one,hg] <;> + dsimp [v,m,g,rho,multiplier,approxF] <;> ring + +lemma integrandExpr_val (β A C M Q : ℚ) (k : ℕ) (x : ℝ) : + (integrandExpr β A C M Q k).val x = + scalarFunction β A C M Q k ((β:ℝ)^2+β*x)*gaussianWeight x := by + unfold integrandExpr + rw [Expr.val_mul,scalarExpr_val] + simp only [Expr.val,Rat.cast_pow,Rat.cast_neg, + Rat.cast_div,Rat.cast_one,Rat.cast_ofNat,gaussianWeight] + congr 2 + ring + +lemma continuous_approxF (β A C : ℝ) : Continuous (approxF β A C) := by + unfold approxF + exact (((((continuous_v.add continuous_const).mul continuous_id).add + (continuous_const.mul (continuous_m.mul continuous_v))).add + (continuous_const.mul continuous_v)).add (continuous_const.mul continuous_m)).add + (continuous_const.mul continuous_g) + +lemma continuous_scalarFunction (β A C M Q : ℝ) (k : ℕ) : + Continuous (scalarFunction β A C M Q k) := by + unfold scalarFunction + split + · exact continuous_v + · exact continuous_g + · exact continuous_m.mul continuous_v + · exact continuous_rho + · exact (continuous_v.sub continuous_const).pow 2 + · exact (continuous_g.sub continuous_const).pow 2 + · exact ((continuous_m.mul continuous_v).sub continuous_const).pow 2 + · exact ((continuous_approxF β A C).sub continuous_const).pow 2 + · exact (((continuous_const.add continuous_v).pow 2).div continuous_multiplier + (fun h => (multiplier_strict_pos h).ne')).div_const 16 + · exact ((continuous_v.pow 2).div continuous_multiplier + (fun h => (multiplier_strict_pos h).ne')).div_const 16 + · exact ((continuous_v.pow 2).div (continuous_const.sub continuous_m) + (fun h => by change 2-m h ≠ 0; linarith [(m_bounds h).2])).div_const 4 + · exact ((continuous_v.pow 2).div ((continuous_const.sub continuous_m).pow 2) + (fun h => pow_ne_zero _ (by change 2-m h ≠ 0; linarith [(m_bounds h).2]))).div_const 4 + · exact (continuous_v.mul (continuous_const.add continuous_m)).div_const 4 + +end SKRatio.Certificate + +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Certificates/CertifiedGaussian.lean b/lean/OAI/Probability/SKRatio/Certificates/CertifiedGaussian.lean new file mode 100644 index 0000000000000000000000000000000000000000..faf3677034c2c261e62ef5b415fc734bceb4f611 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Certificates/CertifiedGaussian.lean @@ -0,0 +1,156 @@ +import Mathlib +import OAI.Probability.SKRatio.Variational.ScalarMoments + +namespace OAI + +noncomputable section +open scoped Topology ENNReal NNReal +open Real Set MeasureTheory ProbabilityTheory +namespace SKRatio.Certificate + +def gaussianWeight (x : ℝ) : ℝ := exp (-x^2/2) +def gaussianNormalizer : ℝ := (sqrt (2*Real.pi))⁻¹ + +lemma gaussian_weight_factor (x : ℝ) : + gaussianWeight x = exp ((-(1/4:ℝ)*x^2))*exp ((-(1/4:ℝ)*x^2)) := by + unfold gaussianWeight + rw [←exp_add] + congr 1 + ring + +lemma polynomial_weight_bound (x : ℝ) : + (1+x^2)*exp ((-(1/4:ℝ)*x^2)) ≤ 4 := by + have h := add_one_le_exp ((1/4:ℝ)*x^2) + have h' : 1+x^2 ≤ 4*exp ((1/4:ℝ)*x^2) := by linarith + have hm := mul_le_mul_of_nonneg_right h' (exp_pos ((-(1/4:ℝ)*x^2))).le + have hh : rexp ((1/4:ℝ)*x^2)*rexp (-(1/4:ℝ)*x^2) = 1 := by + rw [←exp_add,show (1/4:ℝ)*x^2+(-(1/4:ℝ)*x^2)=0 by ring,exp_zero] + simpa only [mul_assoc,hh,mul_one] using hm + +lemma polynomial_tail_bound {x : ℝ} (hx : 10 ≤ |x|) : + (1+x^2)*exp ((-(1/4:ℝ)*x^2)) ≤ 101*exp (-25) := by + have h := add_one_le_exp ((x^2-100)/4) + have hx2 : 100 ≤ x^2 := by nlinarith [sq_abs x] + have h' : 1+x^2 ≤ 101*exp ((x^2-100)/4) := by nlinarith only [h,hx2] + have hm := mul_le_mul_of_nonneg_right h' (exp_pos ((-(1/4:ℝ)*x^2))).le + rw [mul_assoc,←exp_add,show (x^2-100)/4+(-(1/4:ℝ)*x^2) = -25 by ring] at hm + exact hm + +lemma gaussian_tail_constant : 12928*exp (-25:ℝ) ≤ 1/1000000 := by + have he : (27/10:ℝ) ≤ exp 1 := by linarith [exp_one_gt_d9] + have hp := pow_le_pow_left₀ (by norm_num : (0:ℝ) ≤ 27/10) he 25 + have hh : 12928000000 ≤ exp (25:ℝ) := by + rw [show exp (25:ℝ) = (exp (1:ℝ))^25 by simp] + norm_num at hp ⊢ + linarith only [hp] + rw [exp_neg] + have he25 := exp_pos (25:ℝ) + apply (mul_le_mul_iff_of_pos_right he25).mp + field_simp + linarith only [hh] + +lemma integrable_weighted {f : ℝ → ℝ} (hf : AEStronglyMeasurable f volume) + (hb : ∀ x, |f x| ≤ 32*(1+x^2)) : + Integrable (fun x => f x*gaussianWeight x) volume := by + have hbase := (integrable_exp_neg_mul_sq (by norm_num : (0:ℝ) < 1/4)).const_mul (128:ℝ) + apply hbase.mono' (hf.mul (by unfold gaussianWeight; fun_prop)) + apply ae_of_all + intro x + change |f x*gaussianWeight x| ≤ _ + rw [abs_mul,abs_of_pos (show 0 < gaussianWeight x from exp_pos _)] + calc + |f x| *gaussianWeight x ≤ (32*(1+x^2))*gaussianWeight x := + mul_le_mul_of_nonneg_right (hb x) (exp_pos _).le + _ = 32*((1+x^2)*exp ((-(1/4:ℝ)*x^2)))*exp ((-(1/4:ℝ)*x^2)) := by + rw [gaussian_weight_factor] + ring + _ ≤ 128*exp ((-(1/4:ℝ)*x^2)) := by + have hp := mul_le_mul_of_nonneg_right (polynomial_weight_bound x) (exp_pos ((-(1/4:ℝ)*x^2))).le + nlinarith only [hp] + +lemma gaussian_truncation {f : ℝ → ℝ} (hf : AEStronglyMeasurable f volume) + (hb : ∀ x, |f x| ≤ 32*(1+x^2)) : + |(∫ x, f x*gaussianWeight x)-(∫ x in (-10:ℝ)..10, f x*gaussianWeight x)| ≤ 1/1000000 := by + have hi := integrable_weighted hf hb + let s : Set ℝ := Icc (-10) 10 + have hs : MeasurableSet s := measurableSet_Icc + have hi' := ((integrable_exp_neg_mul_sq (by norm_num : (0:ℝ) < 1/4)).const_mul + (3232*exp (-25:ℝ))).integrableOn (s := sᶜ) + have hm : ∀ᵐ x ∂volume.restrict sᶜ, + |f x*gaussianWeight x| ≤ (3232*exp (-25:ℝ))*exp ((-(1/4:ℝ)*x^2)) := by + rw [ae_restrict_iff' hs.compl] + apply ae_of_all + intro x hx + have hxabs : 10 ≤ |x| := by + by_contra h + have ha := abs_lt.mp (lt_of_not_ge h) + exact hx ⟨ha.1.le,ha.2.le⟩ + rw [abs_mul,abs_of_pos (show 0 < gaussianWeight x from exp_pos _)] + calc + |f x| *gaussianWeight x ≤ (32*(1+x^2))*gaussianWeight x := + mul_le_mul_of_nonneg_right (hb x) (exp_pos _).le + _ = 32*((1+x^2)*exp ((-(1/4:ℝ)*x^2)))*exp ((-(1/4:ℝ)*x^2)) := by + rw [gaussian_weight_factor]; ring + _ ≤ (3232*exp (-25:ℝ))*exp ((-(1/4:ℝ)*x^2)) := by + have hp := mul_le_mul_of_nonneg_right (polynomial_tail_bound hxabs) (exp_pos ((-(1/4:ℝ)*x^2))).le + nlinarith only [hp] + have hnorm := (norm_integral_le_integral_norm (f := fun x => f x*gaussianWeight x) + (μ := volume.restrict sᶜ)).trans (integral_mono_ae hi.integrableOn.norm hi' (by + filter_upwards [hm] with x hx + simpa only [Real.norm_eq_abs] using hx)) + have hfull : (∫ x in sᶜ, (3232*exp (-25:ℝ))*exp ((-(1/4:ℝ)*x^2))) ≤ + ∫ x, (3232*exp (-25:ℝ))*exp ((-(1/4:ℝ)*x^2)) := by + apply integral_mono_measure Measure.restrict_le_self (ae_of_all _ (fun x => by positivity)) + exact (integrable_exp_neg_mul_sq (by norm_num : (0:ℝ) < 1/4)).const_mul _ + have hsqrt : sqrt (Real.pi/(1/4:ℝ)) ≤ 4 := by + apply (sqrt_le_iff).mpr + exact ⟨by norm_num,by nlinarith [pi_lt_four]⟩ + simp only [integral_const_mul,integral_gaussian] at hfull + have hlast : (3232*exp (-25:ℝ))*sqrt (Real.pi/(1/4:ℝ)) ≤ 12928*exp (-25:ℝ) := by + nlinarith only [mul_le_mul_of_nonneg_left hsqrt (by positivity : 0 ≤ 3232*exp (-25:ℝ))] + rw [Real.norm_eq_abs,setIntegral_compl hs hi] at hnorm + have he : (∫ x in s, f x*gaussianWeight x) = ∫ x in (-10:ℝ)..10, f x*gaussianWeight x := by + rw [intervalIntegral.integral_of_le (by norm_num : (-10:ℝ) ≤ 10)] + exact integral_Icc_eq_integral_Ioc + rw [he] at hnorm + rw [integral_const_mul] at hnorm + exact hnorm.trans (hfull.trans (hlast.trans gaussian_tail_constant)) + +lemma normalizer_bounds : (39894227/100000000:ℝ) ≤ gaussianNormalizer ∧ + gaussianNormalizer ≤ 39894229/100000000 := by + have hpi0 := pi_pos + have hpiL := pi_gt_d20 + have hpiU := pi_lt_d20 + have hp : 0 < sqrt (2*Real.pi) := sqrt_pos.2 (by positivity) + have hs : sqrt (2*Real.pi)^2 = 2*Real.pi := sq_sqrt (by positivity) + unfold gaussianNormalizer + constructor + · rw [inv_eq_one_div,le_div_iff₀ hp] + nlinarith only [hs,hpiL,hpiU,hp] + · rw [inv_eq_one_div,div_le_iff₀ hp] + nlinarith only [hs,hpiL,hpiU,hp] + +lemma affine_gaussian_integral (β : ℝ) {f : ℝ → ℝ} (hf : Measurable f) : + (∫ h, f h ∂Scalar.fieldLaw β) = + gaussianNormalizer*(∫ x, f (β^2+β*x)*gaussianWeight x) := by + have hl : HasLaw (fun x : ℝ => β^2+β*x) (Scalar.fieldLaw β) (gaussianReal 0 1) := by + have h := gaussianReal_const_add (gaussianReal_const_mul (HasLaw.id (μ := gaussianReal 0 1)) β) (β^2) + convert! h using 1 + simp [Scalar.fieldLaw,Scalar.variance] + congr 1 + exact Real.toNNReal_of_nonneg (sq_nonneg β) + rw [←hl.integral_comp hf.aestronglyMeasurable, + integral_gaussianReal_eq_integral_smul (by norm_num : (1:ℝ≥0) ≠ 0)] + simp only [gaussianPDFReal,NNReal.coe_one,mul_one,sub_zero,smul_eq_mul] + rw [←integral_const_mul] + apply integral_congr_ae + apply ae_of_all + intro x + dsimp [gaussianNormalizer,gaussianWeight] + ring + +end SKRatio.Certificate + +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Certificates/CertifiedInterpolation.lean b/lean/OAI/Probability/SKRatio/Certificates/CertifiedInterpolation.lean new file mode 100644 index 0000000000000000000000000000000000000000..067c5ee00c3e7d7603aef4137b11c68a62538021 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Certificates/CertifiedInterpolation.lean @@ -0,0 +1,167 @@ +import Mathlib +import OAI.Probability.SKRatio.Certificates.CertifiedInterval +import OAI.Probability.SKRatio.Variational.ScalarInterpolation + +namespace OAI + +noncomputable section +open scoped Topology ENNReal NNReal +open Real MeasureTheory ProbabilityTheory +namespace SKRatio.Certificate +open Scalar + +namespace Box + +def posInv (A : Box) : Box := round (1/A.hi) (1/A.lo) +def divPos (A B : Box) : Box := mul A (posInv B) +lemma mem_divPos {A B : Box} {x y : ℝ} (hx : x ∈ A) (hy : y ∈ B) + (hB : 0 < B.lo) : x/y ∈ divPos A B := by + have hi : inv B=some (posInv B) := by simp only [inv,posInv,ite_eq_left hB] + exact mem_mul hx (mem_inv hy hi).1 + +lemma lower {A : Box} {q : ℚ} {x : ℝ} (h : q ≤ A.lo) (hx : x ∈ A) : (q:ℝ) ≤ x := + (by exact_mod_cast h : (q:ℝ) ≤ A.lo).trans hx.1 +lemma upper {A : Box} {q : ℚ} {x : ℝ} (h : A.hi ≤ q) (hx : x ∈ A) : x ≤ (q:ℝ) := + hx.2.trans (by exact_mod_cast h) +end Box + +structure Enclosures where + av : Box + gv : Box + mv : Box + rv : Box + vs : Box + gs : Box + ms : Box + fs : Box + +structure Valid (β : ℝ) (X : Enclosures) : Prop where + mem_a : a β ∈ X.av + mem_G : G β ∈ X.gv + mem_M : (∫ h, m h*v h ∂fieldLaw β) ∈ X.mv + mem_R : R β ∈ X.rv + mem_v : sd (fieldLaw β) v ∈ X.vs + mem_g : sd (fieldLaw β) g ∈ X.gs + mem_mv : sd (fieldLaw β) (fun h => m h*v h) ∈ X.ms + mem_F : sd (fieldLaw β) (F β) ∈ X.fs + +def lBox (A : Box) : Box := Box.sub (Box.rat (64/100)) (Box.mul (Box.rat (19/100)) A) +lemma mem_lBox {β : ℝ} {A : Box} (ha : a β ∈ A) : l β ∈ lBox A := by + rw [l_eq] + simpa only [lBox,Rat.cast_div,Rat.cast_ofNat] using + Box.mem_sub (Box.mem_rat (64/100)) (Box.mem_mul (Box.mem_rat (19/100)) ha) + +def coefficientBox (X Y : Enclosures) : Box := + Box.sub (Box.sub (Box.divPos (Box.sq Y.av) (lBox Y.av)) Y.av) + (Box.mul (Box.rat (3/2)) (Box.sq X.gv)) + +def slackBox₀ (j z : ℚ) (X Y : Enclosures) : Box := + Box.sub (Box.add (Box.add (lBox X.av) (Box.rat (18/1000))) + (Box.mul (Box.rat (j^2)) (coefficientBox X Y))) (Box.mul (Box.rat (z^2)) Y.rv) + +def slackBox₁ (j z : ℚ) (X Y : Enclosures) : Box := + Box.sub (Box.add (Box.sub (Box.rat (4644/10000)) (Box.mul (Box.rat (z/2)) Y.vs)) + (Box.mul (Box.rat (j^2)) X.mv)) + (Box.mul (Box.rat (z^2)) (Box.add (Box.mul (Box.rat (3/2)) (Box.sq Y.gs)) Y.rv)) + +def crossBox (j z t : ℚ) (X Y : Enclosures) : Box := + let aTerm := Box.mul (Box.sub X.av Y.av) (Box.rat z) + let mTerm := Box.mul (Box.rat (2*(z^2-j^2))) Y.ms + let vTerm := Box.mul (Box.sub (Box.divPos (Box.mul (Box.rat (z^2)) X.av) (lBox X.av)) + (Box.divPos (Box.mul (Box.rat (j^2)) Y.av) (lBox Y.av))) Y.vs + let gTerm := Box.mul (Box.mul (Box.rat 3) + (Box.sub (Box.mul (Box.rat (z^2)) X.gv) (Box.mul (Box.rat (j^2)) Y.gv))) Y.gs + Box.mul ⟨0,t⟩ (Box.add (Box.add (Box.add (Box.add Y.fs aTerm) mTerm) vTerm) gTerm) + +lemma coefficient_mem {j z : ℝ} {X Y : Enclosures} (hx : Valid j X) (hy : Valid z Y) + (hY : 0 < (lBox Y.av).lo) : a z^2/l z-a z-(3/2)*G j^2 ∈ coefficientBox X Y := by + simpa only [coefficientBox,Rat.cast_div,Rat.cast_ofNat] using Box.mem_sub + (Box.mem_sub (Box.mem_divPos (Box.mem_sq hy.mem_a) (mem_lBox hy.mem_a) hY) hy.mem_a) + (Box.mem_mul (Box.mem_rat (3/2)) (Box.mem_sq hx.mem_G)) + +lemma slack₀_mem {j z : ℚ} {X Y : Enclosures} (hx : Valid j X) (hy : Valid z Y) + (hY : 0 < (lBox Y.av).lo) : slackBound₀ j z ∈ slackBox₀ j z X Y := by + have hh := Box.mem_sub + (Box.mem_add (Box.mem_add (mem_lBox hx.mem_a) (Box.mem_rat (18/1000))) + (Box.mem_mul (Box.mem_rat (j^2)) (coefficient_mem hx hy hY))) + (Box.mem_mul (Box.mem_rat (z^2)) hy.mem_R) + rw [Rat.cast_pow,Rat.cast_pow] at hh + simpa only [slackBound₀,slackBox₀,Rat.cast_div,Rat.cast_ofNat] using hh + +lemma slack₁_mem {j z : ℚ} {X Y : Enclosures} (hx : Valid j X) (hy : Valid z Y) : + slackBound₁ j z ∈ slackBox₁ j z X Y := by + have hh := Box.mem_sub + (Box.mem_add (Box.mem_sub (Box.mem_rat (4644/10000)) + (Box.mem_mul (Box.mem_rat (z/2)) hy.mem_v)) + (Box.mem_mul (Box.mem_rat (j^2)) hx.mem_M)) + (Box.mem_mul (Box.mem_rat (z^2)) + (Box.mem_add (Box.mem_mul (Box.mem_rat (3/2)) (Box.mem_sq hy.mem_g)) hy.mem_R)) + simp only [Rat.cast_div,Rat.cast_ofNat,Rat.cast_pow] at hh + convert! hh using 1 + unfold slackBound₁ + ring + +lemma cross_mem {j z t : ℚ} {X Y : Enclosures} (hx : Valid j X) (hy : Valid z Y) + (hX : 0 < (lBox X.av).lo) (hY : 0 < (lBox Y.av).lo) + (ht : sqrt (densityFactor j z) ≤ (t:ℝ)) : crossBound j z ∈ crossBox j z t X Y := by + have ht' : sqrt (densityFactor j z) ∈ (⟨0,t⟩ : Box) := by + exact ⟨by simpa only [Rat.cast_zero] using sqrt_nonneg _,ht⟩ + have hh := Box.mem_mul ht' (Box.mem_add (Box.mem_add (Box.mem_add + (Box.mem_add hy.mem_F (Box.mem_mul (Box.mem_sub hx.mem_a hy.mem_a) (Box.mem_rat z))) + (Box.mem_mul (Box.mem_rat (2*(z^2-j^2))) hy.mem_mv)) + (Box.mem_mul (Box.mem_sub + (Box.mem_divPos (Box.mem_mul (Box.mem_rat (z^2)) hx.mem_a) (mem_lBox hx.mem_a) hX) + (Box.mem_divPos (Box.mem_mul (Box.mem_rat (j^2)) hy.mem_a) (mem_lBox hy.mem_a) hY)) hy.mem_v)) + (Box.mem_mul (Box.mem_mul (Box.mem_rat 3) + (Box.mem_sub (Box.mem_mul (Box.mem_rat (z^2)) hx.mem_G) + (Box.mem_mul (Box.mem_rat (j^2)) hy.mem_G))) hy.mem_g)) + repeat rw [Rat.cast_mul] at hh + repeat rw [Rat.cast_sub] at hh + repeat rw [Rat.cast_pow] at hh + simpa only [crossBound,crossBox,Rat.cast_div,Rat.cast_ofNat] using hh + +def interpolationCheck (j z t : ℚ) (X Y : Enclosures) : Bool := decide ( + 0 < (lBox X.av).lo ∧ 0 < (lBox Y.av).lo ∧ + (lBox Y.av).hi ≤ 2*Y.av.lo ∧ 0 ≤ (coefficientBox X Y).lo ∧ + 511/1000 ≤ (slackBox₀ j z X Y).lo ∧ 425/1000 ≤ (slackBox₁ j z X Y).lo ∧ + (crossBox j z t X Y).hi ≤ 925/1000) + +lemma interpolation_check_sound {j z t : ℚ} {X Y : Enclosures} + (hx : Valid j X) (hy : Valid z Y) + (ht : sqrt (densityFactor j z) ≤ (t:ℝ)) + (hc : interpolationCheck j z t X Y = true) : + l z ≤ 2*a z ∧ 0 ≤ a z^2/l z-a z-(3/2)*G j^2 ∧ + 511/1000 ≤ slackBound₀ j z ∧ 425/1000 ≤ slackBound₁ j z ∧ crossBound j z ≤ 925/1000 := by + rcases of_decide_eq_true hc with ⟨hX,hY,hreg,hcoeff,hS₀,hS₁,hC⟩ + have hreg' : ((lBox Y.av).hi:ℝ) ≤ 2*(Y.av.lo:ℝ) := by exact_mod_cast hreg + have hreg'' : l (z:ℝ) ≤ 2*a z := by + linarith only [(mem_lBox hy.mem_a).2,hy.mem_a.1,hreg'] + refine ⟨hreg'',?_,?_,?_,?_⟩ + · simpa only [Rat.cast_zero] using Box.lower hcoeff (coefficient_mem hx hy hY) + · simpa only [Rat.cast_div,Rat.cast_ofNat] using Box.lower hS₀ (slack₀_mem hx hy hY) + · simpa only [Rat.cast_div,Rat.cast_ofNat] using Box.lower hS₁ (slack₁_mem hx hy) + · simpa only [Rat.cast_div,Rat.cast_ofNat] using Box.upper hC (cross_mem hx hy hX hY ht) + +lemma certified_slacks {j z t : ℚ} {X Y : Enclosures} {β : ℝ} + (hj : 0 < (j:ℝ)) (hjβ : (j:ℝ) ≤ β) (hβz : β ≤ (z:ℝ)) (hz : (z:ℝ) ≤ 1) + (hx : Valid j X) (hy : Valid z Y) (ht : sqrt (densityFactor j z) ≤ (t:ℝ)) + (hc : interpolationCheck j z t X Y = true) : + 511/1000 ≤ U₀ β ∧ 425/1000 ≤ U₁ β ∧ sd (fieldLaw β) (F β) ≤ 925/1000 := by + obtain ⟨hreg,hcoeff,hS₀,hS₁,hC⟩ := interpolation_check_sound hx hy ht hc + exact ⟨hS₀.trans (U₀_interval hj hjβ hβz hz hreg hcoeff), + hS₁.trans (U₁_interval hj hjβ hβz hz),(sd_F_interval hj hjβ hβz).trans hC⟩ + +lemma discriminant_of_slacks {β : ℝ} (h0 : 511/1000 ≤ U₀ β) + (h1 : 425/1000 ≤ U₁ β) (hs : sd (fieldLaw β) (F β) ≤ 925/1000) : + 0 < U₀ β ∧ sd (fieldLaw β) (F β)^2 ≤ 4*U₀ β*U₁ β := by + have h0p : 0 < U₀ β := by linarith + have hp := mul_le_mul h0 h1 (by norm_num : (0:ℝ) ≤ 425/1000) h0p.le + have hsq := (sq_le_sq₀ (sd_nonneg (μ := fieldLaw β) (F β)) + (by norm_num : (0:ℝ) ≤ 925/1000)).mpr hs + exact ⟨h0p,by nlinarith only [hp,hsq]⟩ + +end SKRatio.Certificate + +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Certificates/CertifiedInterval.lean b/lean/OAI/Probability/SKRatio/Certificates/CertifiedInterval.lean new file mode 100644 index 0000000000000000000000000000000000000000..84e38c70c9499acdf23fee36d4f6ce7670eed7ba --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Certificates/CertifiedInterval.lean @@ -0,0 +1,167 @@ +import Mathlib +import OAI.Probability.SKRatio.Certificates.FixedExp + +namespace OAI + +noncomputable section +open Real +namespace SKRatio.Certificate + +@[reducible] def scale : ℚ := 10000000000000000000000 + +def down (q : ℚ) : ℚ := (⌊q*scale⌋ : ℚ)/scale +def up (q : ℚ) : ℚ := (⌈q*scale⌉ : ℚ)/scale + +lemma down_le (q : ℚ) : (down q : ℝ) ≤ q := by + have h : (down q : ℚ) ≤ q := by + unfold down + exact (div_le_iff₀ (by norm_num : (0:ℚ) < scale)).mpr (Int.floor_le _) + exact_mod_cast h + +lemma le_up (q : ℚ) : (q : ℝ) ≤ up q := by + have h : q ≤ up q := by + unfold up + exact (le_div_iff₀ (by norm_num : (0:ℚ) < scale)).mpr (Int.le_ceil _) + exact_mod_cast h + +structure Box where + lo : ℚ + hi : ℚ + deriving DecidableEq, Repr + +namespace Box + +def Mem (A : Box) (x : ℝ) : Prop := (A.lo:ℝ) ≤ x ∧ x ≤ A.hi +instance : Membership ℝ Box := ⟨fun A x => A.Mem x⟩ + +def rat (q : ℚ) : Box := ⟨q,q⟩ +def round (a b : ℚ) : Box := ⟨down a,up b⟩ +def add (A B : Box) : Box := ⟨A.lo+B.lo,A.hi+B.hi⟩ +def neg (A : Box) : Box := ⟨-A.hi,-A.lo⟩ +def sub (A B : Box) : Box := add A (neg B) +def mul (A B : Box) : Box := round + (min (min (A.lo*B.lo) (A.lo*B.hi)) (min (A.hi*B.lo) (A.hi*B.hi))) + (max (max (A.lo*B.lo) (A.lo*B.hi)) (max (A.hi*B.lo) (A.hi*B.hi))) +def inv (A : Box) : Option Box := if 0 < A.lo then some (round (1/A.hi) (1/A.lo)) else none + +def sq (A : Box) : Box := round + (if 0 ≤ A.lo then A.lo^2 else if A.hi ≤ 0 then A.hi^2 else 0) + (max (A.lo^2) (A.hi^2)) + +def squareIter : ℕ → Box → Box + | 0,A => A + | k+1,A => squareIter k (sq A) + +def exp (A : Box) : Option Box := + if A.hi < 1073741824 then + let B := Fixed.expBounds A.lo A.hi + some ⟨(B.lo:ℚ)/(Fixed.S:ℚ),(B.hi:ℚ)/(Fixed.S:ℚ)⟩ + else none + +lemma mem_rat (q : ℚ) : (q:ℝ) ∈ rat q := ⟨le_rfl,le_rfl⟩ +lemma mem_round {x : ℝ} {a b : ℚ} (hx : (a:ℝ) ≤ x ∧ x ≤ b) : x ∈ round a b := + ⟨(down_le a).trans hx.1,hx.2.trans (le_up b)⟩ +lemma mem_add {A B : Box} {x y : ℝ} (hx : x ∈ A) (hy : y ∈ B) : x+y ∈ add A B := by + change _ ∧ _ + simp only [add,Rat.cast_add] + exact ⟨add_le_add hx.1 hy.1,add_le_add hx.2 hy.2⟩ +lemma mem_neg {A : Box} {x : ℝ} (hx : x ∈ A) : -x ∈ neg A := by + change _ ∧ _ + simp only [neg,Rat.cast_neg] + exact ⟨neg_le_neg hx.2,neg_le_neg hx.1⟩ +lemma mem_sub {A B : Box} {x y : ℝ} (hx : x ∈ A) (hy : y ∈ B) : x-y ∈ sub A B := by + exact mem_add hx (mem_neg hy) + +lemma four_products {a b c d x y : ℝ} (hx : a ≤ x ∧ x ≤ b) (hy : c ≤ y ∧ y ≤ d) : + min (min (a*c) (a*d)) (min (b*c) (b*d)) ≤ x*y ∧ + x*y ≤ max (max (a*c) (a*d)) (max (b*c) (b*d)) := by + have hlo : min (min (a*c) (a*d)) (min (b*c) (b*d)) ≤ a*c ∧ + min (min (a*c) (a*d)) (min (b*c) (b*d)) ≤ a*d ∧ + min (min (a*c) (a*d)) (min (b*c) (b*d)) ≤ b*c ∧ + min (min (a*c) (a*d)) (min (b*c) (b*d)) ≤ b*d := by + simp only [min_le_iff,le_refl,or_true,true_or,and_self] + have hhi : a*c ≤ max (max (a*c) (a*d)) (max (b*c) (b*d)) ∧ + a*d ≤ max (max (a*c) (a*d)) (max (b*c) (b*d)) ∧ + b*c ≤ max (max (a*c) (a*d)) (max (b*c) (b*d)) ∧ + b*d ≤ max (max (a*c) (a*d)) (max (b*c) (b*d)) := by + simp only [le_max_iff,le_refl,or_true,true_or,and_self] + have lower {L : ℝ} (h : L ≤ a*c ∧ L ≤ a*d ∧ L ≤ b*c ∧ L ≤ b*d) : L ≤ x*y := by + rcases le_total 0 y with hp | hn + · have ha : L ≤ a*y := by + rcases le_total 0 a with hap | han + · exact h.1.trans (mul_le_mul_of_nonneg_left hy.1 hap) + · exact h.2.1.trans (mul_le_mul_of_nonpos_left hy.2 han) + exact ha.trans (mul_le_mul_of_nonneg_right hx.1 hp) + · have hb : L ≤ b*y := by + rcases le_total 0 b with hbp | hbn + · exact h.2.2.1.trans (mul_le_mul_of_nonneg_left hy.1 hbp) + · exact h.2.2.2.trans (mul_le_mul_of_nonpos_left hy.2 hbn) + exact hb.trans (mul_le_mul_of_nonpos_right hx.2 hn) + have upper {U : ℝ} (h : a*c ≤ U ∧ a*d ≤ U ∧ b*c ≤ U ∧ b*d ≤ U) : x*y ≤ U := by + rcases le_total 0 y with hp | hn + · have hb : b*y ≤ U := by + rcases le_total 0 b with hbp | hbn + · exact (mul_le_mul_of_nonneg_left hy.2 hbp).trans h.2.2.2 + · exact (mul_le_mul_of_nonpos_left hy.1 hbn).trans h.2.2.1 + exact (mul_le_mul_of_nonneg_right hx.2 hp).trans hb + · have ha : a*y ≤ U := by + rcases le_total 0 a with hap | han + · exact (mul_le_mul_of_nonneg_left hy.2 hap).trans h.2.1 + · exact (mul_le_mul_of_nonpos_left hy.1 han).trans h.1 + exact (mul_le_mul_of_nonpos_right hx.1 hn).trans ha + exact ⟨lower hlo,upper hhi⟩ + +lemma mem_mul {A B : Box} {x y : ℝ} (hx : x ∈ A) (hy : y ∈ B) : x*y ∈ mul A B := by + apply mem_round + simp only [Rat.cast_min,Rat.cast_max,Rat.cast_mul] + exact four_products hx hy + +lemma mem_inv {A B : Box} {x : ℝ} (hx : x ∈ A) (he : inv A=some B) : x⁻¹ ∈ B ∧ x ≠ 0 := by + unfold inv at he + split_ifs at he with hp + · cases he + have hp' : 0 < (A.lo:ℝ) := by exact_mod_cast hp + have hx' : 0 < x := hp'.trans_le hx.1 + have hh : 0 < (A.hi:ℝ) := hx'.trans_le hx.2 + refine ⟨mem_round ?_,hx'.ne'⟩ + simp only [one_div,Rat.cast_inv] + exact ⟨inv_anti₀ hx' hx.2,inv_anti₀ hp' hx.1⟩ + +lemma mem_sq {A : Box} {x : ℝ} (hx : x ∈ A) : x^2 ∈ sq A := by + apply mem_round + constructor + · split_ifs with hp hn + · rw [Rat.cast_pow] + exact (sq_le_sq₀ (by exact_mod_cast hp) (by exact (show (0:ℝ) ≤ A.lo from by exact_mod_cast hp).trans hx.1)).mpr hx.1 + · rw [Rat.cast_pow] + have hn' : (A.hi:ℝ) ≤ 0 := by exact_mod_cast hn + nlinarith [hx.2] + · simpa using sq_nonneg x + · simp only [Rat.cast_max,Rat.cast_pow] + rcases le_total 0 x with hp | hn + · exact (show x^2 ≤ (A.hi:ℝ)^2 from (sq_le_sq₀ hp (hp.trans hx.2)).mpr hx.2).trans (le_max_right _ _) + · have ha : (A.lo:ℝ) ≤ 0 := hx.1.trans hn + exact (show x^2 ≤ (A.lo:ℝ)^2 by nlinarith [hx.1]).trans (le_max_left _ _) + +lemma mem_squareIter {A : Box} {x : ℝ} (hx : x ∈ A) (k : ℕ) : x^(2^k) ∈ squareIter k A := by + induction k generalizing A x with + | zero => simpa [squareIter] using hx + | succ k hk => + have h := hk (mem_sq hx) + simpa only [squareIter,←pow_mul,show (2:ℕ)^(k+1) = 2*2^k by rw [pow_succ,Nat.mul_comm]] using h + +lemma mem_exp {A B : Box} {x : ℝ} (hx : x ∈ A) (he : exp A=some B) : Real.exp x ∈ B := by + unfold exp at he + split_ifs at he with hh + cases he + have hb := Fixed.mem_expBounds hx hh + change _ ∧ _ + simp only [Rat.cast_div,Rat.cast_intCast] + exact hb + +end Box +end SKRatio.Certificate + +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Certificates/CertifiedJet.lean b/lean/OAI/Probability/SKRatio/Certificates/CertifiedJet.lean new file mode 100644 index 0000000000000000000000000000000000000000..bdc4fe6f9ef89387576ca934a4f9b8af7c970848 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Certificates/CertifiedJet.lean @@ -0,0 +1,253 @@ +import Mathlib +import OAI.Probability.SKRatio.Calculus.PlusSpin +import OAI.Probability.SKRatio.Certificates.CertifiedInterval + +namespace OAI + +noncomputable section +open Real +namespace SKRatio.Certificate + +structure Jet where + val : Box + der : Box + sec : Box + deriving DecidableEq, Repr + +namespace Jet +open Box + +def rat (q : ℚ) : Jet := ⟨Box.rat q,Box.rat 0,Box.rat 0⟩ +def var (B : Box) : Jet := ⟨B,Box.rat 1,Box.rat 0⟩ +def add (A B : Jet) : Jet := ⟨Box.add A.val B.val,Box.add A.der B.der,Box.add A.sec B.sec⟩ +def neg (A : Jet) : Jet := ⟨Box.neg A.val,Box.neg A.der,Box.neg A.sec⟩ +def mul (A B : Jet) : Jet := + ⟨Box.mul A.val B.val, + Box.add (Box.mul A.der B.val) (Box.mul A.val B.der), + Box.add (Box.add (Box.mul A.sec B.val) (Box.mul (Box.rat 2) (Box.mul A.der B.der))) (Box.mul A.val B.sec)⟩ +def sq (A : Jet) : Jet := ⟨Box.sq A.val,Box.mul (Box.rat 2) (Box.mul A.val A.der), + Box.mul (Box.rat 2) (Box.add (Box.sq A.der) (Box.mul A.val A.sec))⟩ +def inv (A : Jet) : Option Jet := do + let B ← Box.inv A.val + return ⟨B,Box.neg (Box.mul A.der (Box.sq B)), + Box.sub (Box.mul (Box.rat 2) (Box.mul (Box.sq A.der) (Box.mul B (Box.sq B)))) (Box.mul A.sec (Box.sq B))⟩ +def exp (A : Jet) : Option Jet := do + let B ← Box.exp A.val + return ⟨B,Box.mul B A.der,Box.mul B (Box.add A.sec (Box.sq A.der))⟩ + +def tanhBox (A : Box) : Option Box := do + let E ← Box.exp (Box.mul (Box.rat 2) A) + let D ← Box.inv (Box.add E (Box.rat 1)) + return Box.mul (Box.sub E (Box.rat 1)) D + +def tanh (A : Jet) : Option Jet := do + let B ← tanhBox A.val + let V := Box.sub (Box.rat 1) (Box.sq B) + return ⟨B,Box.mul V A.der,Box.sub (Box.mul V A.sec) + (Box.mul (Box.rat 2) (Box.mul B (Box.mul V (Box.sq A.der))))⟩ + +lemma tanh_formula (x : ℝ) : Real.tanh x = (Real.exp (2*x)-1)*(Real.exp (2*x)+1)⁻¹ := by + have h := Calculus.exp_two_mul_one_sub_tanh x + have hd : Real.exp (2*x)+1 ≠ 0 := by positivity + apply (mul_right_cancel₀ hd) + field_simp + linarith only [h] + +lemma mem_tanhBox {A B : Box} {x : ℝ} (hx : x ∈ A) (he : tanhBox A=some B) : Real.tanh x ∈ B := by + simp only [tanhBox,bind, pure, Option.bind_eq_some_iff,Option.some.injEq] at he + obtain ⟨E,hE,D,hD,rfl⟩ := he + have he' := Box.mem_exp (Box.mem_mul (Box.mem_rat 2) hx) hE + norm_num only [Rat.cast_ofNat] at he' + have hd' := Box.mem_inv (Box.mem_add he' (Box.mem_rat 1)) hD + rw [tanh_formula] + exact Box.mem_mul (Box.mem_sub he' (by exact_mod_cast Box.mem_rat 1)) (by simpa only [Rat.cast_one] using hd'.1) +end Jet + +inductive Expr where + | rat : ℚ → Expr + | var : Expr + | add : Expr → Expr → Expr + | neg : Expr → Expr + | mul : Expr → Expr → Expr + | sq : Expr → Expr + | inv : Expr → Expr + | exp : Expr → Expr + | tanh : Expr → Expr + deriving DecidableEq, Repr + +namespace Expr + +def val (e : Expr) (x : ℝ) : ℝ := match e with + | rat q => q + | var => x + | add a b => a.val x+b.val x + | neg a => -a.val x + | mul a b => a.val x*b.val x + | sq a => (a.val x)^2 + | inv a => (a.val x)⁻¹ + | exp a => Real.exp (a.val x) + | tanh a => Real.tanh (a.val x) + +def der (e : Expr) (x : ℝ) : ℝ := match e with + | rat _ => 0 + | var => 1 + | add a b => a.der x+b.der x + | neg a => -a.der x + | mul a b => a.der x*b.val x+a.val x*b.der x + | sq a => 2*a.val x*a.der x + | inv a => -a.der x*((a.val x)⁻¹)^2 + | exp a => Real.exp (a.val x)*a.der x + | tanh a => (1-(Real.tanh (a.val x))^2)*a.der x + +def sec (e : Expr) (x : ℝ) : ℝ := match e with + | rat _ => 0 + | var => 0 + | add a b => a.sec x+b.sec x + | neg a => -a.sec x + | mul a b => a.sec x*b.val x+2*a.der x*b.der x+a.val x*b.sec x + | sq a => 2*(a.der x^2+a.val x*a.sec x) + | inv a => 2*a.der x^2*((a.val x)⁻¹)^3-a.sec x*((a.val x)⁻¹)^2 + | exp a => Real.exp (a.val x)*(a.sec x+a.der x^2) + | tanh a => (1-(Real.tanh (a.val x))^2)*a.sec x- + 2*Real.tanh (a.val x)*(1-(Real.tanh (a.val x))^2)*a.der x^2 + +def compute (e : Expr) (B : Box) : Option Jet := match e with + | rat q => some (Jet.rat q) + | var => some (Jet.var B) + | add a b => do let A ← a.compute B; let C ← b.compute B; return Jet.add A C + | neg a => do let A ← a.compute B; return Jet.neg A + | mul a b => do let A ← a.compute B; let C ← b.compute B; return Jet.mul A C + | sq a => do let A ← a.compute B; return Jet.sq A + | inv a => do let A ← a.compute B; Jet.inv A + | exp a => do let A ← a.compute B; Jet.exp A + | tanh a => do let A ← a.compute B; Jet.tanh A + +def Regular (e : Expr) (x : ℝ) : Prop := match e with + | rat _ | var => True + | add a b | mul a b => a.Regular x ∧ b.Regular x + | neg a | sq a | exp a | tanh a => a.Regular x + | inv a => a.Regular x ∧ a.val x ≠ 0 + +lemma derivatives (e : Expr) (x : ℝ) (h : e.Regular x) : + HasDerivAt e.val (e.der x) x ∧ HasDerivAt e.der (e.sec x) x := by + induction e with + | rat q => exact ⟨hasDerivAt_const _ _,hasDerivAt_const _ _⟩ + | var => exact ⟨hasDerivAt_id _,hasDerivAt_const _ _⟩ + | add a b ha hb => + exact ⟨(ha h.1).1.add (hb h.2).1,(ha h.1).2.add (hb h.2).2⟩ + | neg a ha => exact ⟨(ha h).1.neg,(ha h).2.neg⟩ + | mul a b ha hb => + obtain ⟨ha,ha'⟩ := ha h.1 + obtain ⟨hb,hb'⟩ := hb h.2 + refine ⟨ha.mul hb,?_⟩ + convert! (ha'.mul hb).add (ha.mul hb') using 1 + dsimp [der,sec] + ring + | sq a ha => + obtain ⟨ha,ha'⟩ := ha h + refine ⟨?_,?_⟩ + · convert! ha.pow 2 using 1 + dsimp [der,val] + ring + · convert! ((ha.const_mul 2).mul ha') using 1 + dsimp [der,sec] + ring + | inv a ha => + obtain ⟨ha,ha'⟩ := ha h.1 + have hi := ha.inv h.2 + refine ⟨?_,?_⟩ + · convert! hi using 1 + dsimp [val,der] + field_simp + · convert! ha'.neg.mul (hi.pow 2) using 1 + dsimp [der,sec] + field_simp + ring + | exp a ha => + obtain ⟨ha,ha'⟩ := ha h + refine ⟨ha.exp,?_⟩ + convert! ha.exp.mul ha' using 1 + dsimp [der,sec] + ring + | tanh a ha => + obtain ⟨ha,ha'⟩ := ha h + have hm := (Calculus.hasDerivAt_tanh (a.val x)).comp x ha + refine ⟨hm,?_⟩ + convert! ((hasDerivAt_const x (1:ℝ)).sub (hm.pow 2)).mul ha' using 1 + dsimp [der,sec] + ring + +lemma compute_sound (e : Expr) {B : Box} {J : Jet} (hc : e.compute B=some J) + {x : ℝ} (hx : x ∈ B) : + e.val x ∈ J.val ∧ e.der x ∈ J.der ∧ e.sec x ∈ J.sec ∧ e.Regular x := by + induction e generalizing J with + | rat q => + simp only [compute,Option.some.injEq] at hc + cases hc + exact ⟨Box.mem_rat q,by simpa only [Jet.rat,Jet.var,der,sec,Rat.cast_zero] using Box.mem_rat 0,by simpa only [Jet.rat,Jet.var,der,sec,Rat.cast_zero] using Box.mem_rat 0,trivial⟩ + | var => + simp only [compute,Option.some.injEq] at hc + cases hc + exact ⟨hx,by simpa only [Jet.rat,Jet.var,der,sec,Rat.cast_one] using Box.mem_rat 1,by simpa only [Jet.rat,Jet.var,der,sec,Rat.cast_zero] using Box.mem_rat 0,trivial⟩ + | add a b ha hb => + simp only [compute,bind, pure, Option.bind_eq_some_iff,Option.some.injEq] at hc + obtain ⟨A,hA,C,hC,rfl⟩ := hc + obtain ⟨ha0,ha1,ha2,har⟩ := ha hA + obtain ⟨hb0,hb1,hb2,hbr⟩ := hb hC + exact ⟨Box.mem_add ha0 hb0,Box.mem_add ha1 hb1,Box.mem_add ha2 hb2,har,hbr⟩ + | neg a ha => + simp only [compute,bind, pure, Option.bind_eq_some_iff,Option.some.injEq] at hc + obtain ⟨A,hA,rfl⟩ := hc + obtain ⟨ha0,ha1,ha2,har⟩ := ha hA + exact ⟨Box.mem_neg ha0,Box.mem_neg ha1,Box.mem_neg ha2,har⟩ + | mul a b ha hb => + simp only [compute,bind, pure, Option.bind_eq_some_iff,Option.some.injEq] at hc + obtain ⟨A,hA,C,hC,rfl⟩ := hc + obtain ⟨ha0,ha1,ha2,har⟩ := ha hA + obtain ⟨hb0,hb1,hb2,hbr⟩ := hb hC + refine ⟨Box.mem_mul ha0 hb0,Box.mem_add (Box.mem_mul ha1 hb0) (Box.mem_mul ha0 hb1),?_,har,hbr⟩ + simpa only [sec,der,Jet.mul,Jet.sq,Rat.cast_ofNat,mul_assoc] using Box.mem_add + (Box.mem_add (Box.mem_mul ha2 hb0) (Box.mem_mul (Box.mem_rat 2) (Box.mem_mul ha1 hb1))) (Box.mem_mul ha0 hb2) + | sq a ha => + simp only [compute,bind, pure, Option.bind_eq_some_iff,Option.some.injEq] at hc + obtain ⟨A,hA,rfl⟩ := hc + obtain ⟨ha0,ha1,ha2,har⟩ := ha hA + refine ⟨Box.mem_sq ha0,?_,?_,har⟩ + · simpa only [sec,der,Jet.mul,Jet.sq,Rat.cast_ofNat,mul_assoc] using Box.mem_mul (Box.mem_rat 2) (Box.mem_mul ha0 ha1) + · exact Box.mem_mul (by simpa using Box.mem_rat 2) (Box.mem_add (Box.mem_sq ha1) (Box.mem_mul ha0 ha2)) + | inv a ha => + simp only [compute,bind, pure, Option.bind_eq_some_iff,Jet.inv,Option.some.injEq] at hc + obtain ⟨A,hA,C,hC,rfl⟩ := hc + obtain ⟨ha0,ha1,ha2,har⟩ := ha hA + obtain ⟨hi,hn⟩ := Box.mem_inv ha0 hC + refine ⟨hi,?_,?_,har,hn⟩ + · simpa only [der,neg_mul] using Box.mem_neg (Box.mem_mul ha1 (Box.mem_sq hi)) + · have h := Box.mem_sub (Box.mem_mul (Box.mem_rat 2) (Box.mem_mul (Box.mem_sq ha1) + (Box.mem_mul hi (Box.mem_sq hi)))) (Box.mem_mul ha2 (Box.mem_sq hi)) + convert! h using 1 + dsimp [sec,Jet.inv] + ring + | exp a ha => + simp only [compute,bind, pure, Option.bind_eq_some_iff,Jet.exp,Option.some.injEq] at hc + obtain ⟨A,hA,C,hC,rfl⟩ := hc + obtain ⟨ha0,ha1,ha2,har⟩ := ha hA + have he := Box.mem_exp ha0 hC + exact ⟨he,Box.mem_mul he ha1,Box.mem_mul he (Box.mem_add ha2 (Box.mem_sq ha1)),har⟩ + | tanh a ha => + simp only [compute,bind, pure, Option.bind_eq_some_iff,Jet.tanh,Option.some.injEq] at hc + obtain ⟨A,hA,C,hC,rfl⟩ := hc + obtain ⟨ha0,ha1,ha2,har⟩ := ha hA + have hm := Jet.mem_tanhBox ha0 hC + have hv := Box.mem_sub (Box.mem_rat 1) (Box.mem_sq hm) + norm_num only [Rat.cast_one] at hv + refine ⟨hm,Box.mem_mul hv ha1,?_,har⟩ + have h := Box.mem_sub (Box.mem_mul hv ha2) (Box.mem_mul (Box.mem_rat 2) + (Box.mem_mul hm (Box.mem_mul hv (Box.mem_sq ha1)))) + simpa only [sec,der,Jet.mul,Jet.sq,Rat.cast_ofNat,mul_assoc] using h + +end Expr +end SKRatio.Certificate + +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Certificates/CertifiedMomentAssembly.lean b/lean/OAI/Probability/SKRatio/Certificates/CertifiedMomentAssembly.lean new file mode 100644 index 0000000000000000000000000000000000000000..1e5bcfd65db2e5dfc2c39ddb69658977189a85a6 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Certificates/CertifiedMomentAssembly.lean @@ -0,0 +1,51 @@ +import Mathlib +import OAI.Probability.SKRatio.Certificates.CertifiedCoefficient + +namespace OAI + +noncomputable section +open Real MeasureTheory +namespace SKRatio.Certificate +open Scalar + +lemma abs_sub_center {x : ℝ} {A e : ℚ} (hx : x ∈ (⟨A-e,A+e⟩ : Box)) : + |x-(A:ℝ)| ≤ (e:ℝ) := by + change ((A-e:ℚ):ℝ) ≤ x ∧ x ≤ ((A+e:ℚ):ℝ) at hx + rw [Rat.cast_sub,Rat.cast_add] at hx + exact abs_le.mpr ⟨by linarith only [hx.1],by linarith only [hx.2]⟩ + +lemma mem_sd_center {μ : Measure ℝ} [IsProbabilityMeasure μ] {f : ℝ → ℝ} + (hf : MemLp f 2 μ) {c B : ℚ} (hB : 0 ≤ B) + (hc : (∫ h, (f h-(c:ℝ))^2 ∂μ) ∈ (⟨0,B^2⟩ : Box)) : + sd μ f ∈ (⟨0,B⟩ : Box) := by + have hi := hc.2 + change (∫ h, (f h-(c:ℝ))^2 ∂μ) ≤ ((B^2:ℚ):ℝ) at hi + rw [Rat.cast_pow] at hi + exact ⟨by simpa only [Rat.cast_zero] using sd_nonneg (μ := μ) f, + sd_le_of_center hf (by exact_mod_cast hB) hi⟩ + +lemma mem_F_of_center {β : ℝ} {A C Q sa sf : ℚ} + (hβ : 0 ≤ β) (hβh : β ≤ 1/2) (hA : 0 ≤ A) (hA1 : A ≤ 1) + (ha : a β ∈ (⟨A-3/2000,A+3/2000⟩ : Box)) + (hg : G β ∈ (⟨C-3/2000,C+3/2000⟩ : Box)) + (hsa : 0 ≤ sa) + (hc : (∫ h, (approxF β A C h-(Q:ℝ))^2 ∂fieldLaw β) ∈ (⟨0,sa^2⟩ : Box)) + (harith : sa+9/2000 ≤ sf) : sd (fieldLaw β) (F β) ∈ (⟨0,sf⟩ : Box) := by + have hbound := approxF_error hβ hβh (A := (A:ℝ)) (C := (C:ℝ)) + (by exact_mod_cast hA) (by exact_mod_cast hA1) + have hsd := (mem_sd_center (memLp_approxF β A C) hsa hc).2 + change sd (fieldLaw β) (approxF β A C) ≤ (sa:ℝ) at hsd + have heA := abs_sub_center ha + have heG := abs_sub_center hg + have ha' : (sa:ℝ)+9/2000 ≤ (sf:ℝ) := by + have hh : ((sa+9/2000:ℚ):ℝ) ≤ (sf:ℝ) := Rat.cast_le.mpr harith + simpa only [Rat.cast_add,Rat.cast_div,Rat.cast_ofNat] using hh + norm_num only [Rat.cast_div,Rat.cast_ofNat] at heA heG + exact ⟨by simpa only [Rat.cast_zero] using sd_nonneg (μ := fieldLaw β) (F β), + by linarith only [hbound,hsd,heA,heG,ha']⟩ + +end SKRatio.Certificate + +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Certificates/CertifiedMomentsJ0.lean b/lean/OAI/Probability/SKRatio/Certificates/CertifiedMomentsJ0.lean new file mode 100644 index 0000000000000000000000000000000000000000..8acc3c5be348567a94f9d9b788c09401e61bba33 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Certificates/CertifiedMomentsJ0.lean @@ -0,0 +1,47 @@ +import Mathlib +import OAI.Probability.SKRatio.Certificates.CertifiedConstants +import OAI.Probability.SKRatio.Certificates.CertifiedMomentAssembly +import OAI.Probability.SKRatio.Certificates.ScalarDataJ0K0 +import OAI.Probability.SKRatio.Certificates.ScalarDataJ0K1 +import OAI.Probability.SKRatio.Certificates.ScalarDataJ0K2 +import OAI.Probability.SKRatio.Certificates.ScalarDataJ0K3 +import OAI.Probability.SKRatio.Certificates.ScalarDataJ0K4 +import OAI.Probability.SKRatio.Certificates.ScalarDataJ0K5 +import OAI.Probability.SKRatio.Certificates.ScalarDataJ0K6 +import OAI.Probability.SKRatio.Certificates.ScalarDataJ0K7 + +namespace OAI + +noncomputable section +open Real MeasureTheory +namespace SKRatio.Certificate +open Scalar + +theorem valid0 : Valid (7/20) X0 := by + refine ⟨?_,?_,?_,?_,?_,?_,?_,?_⟩ + · exact Data.J0K0.integral_bound + · exact Data.J0K1.integral_bound + · exact Data.J0K2.integral_bound + · exact Data.J0K3.integral_bound + · apply mem_sd_center memLp_v (c := (44507/50000)) (by norm_num : (0:ℚ) ≤ 13/100) + convert! Data.J0K4.integral_bound using 1 <;> norm_num [scalarFunction] + · apply mem_sd_center memLp_g (c := (110763/200000)) (by norm_num : (0:ℚ) ≤ 43/500) + convert! Data.J0K5.integral_bound using 1 <;> norm_num [scalarFunction] + · apply mem_sd_center memLp_mv (c := (20333/250000)) (by norm_num : (0:ℚ) ≤ 239/1000) + convert! Data.J0K6.integral_bound using 1 <;> norm_num [scalarFunction] + · apply mem_F_of_center (A := (44507/50000)) (C := (110763/200000)) (Q := (14573/25000)) + (sa := (661/1000)) (sf := (333/500)) (by norm_num) (by norm_num) + (by norm_num) (by norm_num) + · convert! Data.J0K0.integral_bound using 1 + norm_num [scalarFunction,a] + · convert! Data.J0K1.integral_bound using 1 + norm_num [scalarFunction,G] + · norm_num + · convert! Data.J0K7.integral_bound using 1 <;> norm_num [scalarFunction] + · norm_num + +end SKRatio.Certificate + +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Certificates/CertifiedMomentsJ1.lean b/lean/OAI/Probability/SKRatio/Certificates/CertifiedMomentsJ1.lean new file mode 100644 index 0000000000000000000000000000000000000000..26eaaf8f2ec07b3c5272cc5f62db6d7b9e42ce8f --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Certificates/CertifiedMomentsJ1.lean @@ -0,0 +1,47 @@ +import Mathlib +import OAI.Probability.SKRatio.Certificates.CertifiedConstants +import OAI.Probability.SKRatio.Certificates.CertifiedMomentAssembly +import OAI.Probability.SKRatio.Certificates.ScalarDataJ1K0 +import OAI.Probability.SKRatio.Certificates.ScalarDataJ1K1 +import OAI.Probability.SKRatio.Certificates.ScalarDataJ1K2 +import OAI.Probability.SKRatio.Certificates.ScalarDataJ1K3 +import OAI.Probability.SKRatio.Certificates.ScalarDataJ1K4 +import OAI.Probability.SKRatio.Certificates.ScalarDataJ1K5 +import OAI.Probability.SKRatio.Certificates.ScalarDataJ1K6 +import OAI.Probability.SKRatio.Certificates.ScalarDataJ1K7 + +namespace OAI + +noncomputable section +open Real MeasureTheory +namespace SKRatio.Certificate +open Scalar + +theorem valid1 : Valid (2/5) X1 := by + refine ⟨?_,?_,?_,?_,?_,?_,?_,?_⟩ + · exact Data.J1K0.integral_bound + · exact Data.J1K1.integral_bound + · exact Data.J1K2.integral_bound + · exact Data.J1K3.integral_bound + · apply mem_sd_center memLp_v (c := (107581/125000)) (by norm_num : (0:ℚ) ≤ 157/1000) + convert! Data.J1K4.integral_bound using 1 <;> norm_num [scalarFunction] + · apply mem_sd_center memLp_g (c := (545767/1000000)) (by norm_num : (0:ℚ) ≤ 19/200) + convert! Data.J1K5.integral_bound using 1 <;> norm_num [scalarFunction] + · apply mem_sd_center memLp_mv (c := (95751/1000000)) (by norm_num : (0:ℚ) ≤ 249/1000) + convert! Data.J1K6.integral_bound using 1 <;> norm_num [scalarFunction] + · apply mem_F_of_center (A := (107581/125000)) (C := (545767/1000000)) (Q := (616697/1000000)) + (sa := (183/250)) (sf := (737/1000)) (by norm_num) (by norm_num) + (by norm_num) (by norm_num) + · convert! Data.J1K0.integral_bound using 1 + norm_num [scalarFunction,a] + · convert! Data.J1K1.integral_bound using 1 + norm_num [scalarFunction,G] + · norm_num + · convert! Data.J1K7.integral_bound using 1 <;> norm_num [scalarFunction] + · norm_num + +end SKRatio.Certificate + +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Certificates/CertifiedMomentsJ2.lean b/lean/OAI/Probability/SKRatio/Certificates/CertifiedMomentsJ2.lean new file mode 100644 index 0000000000000000000000000000000000000000..5b64828f44ccd933f5d06445c83db2cab3da8ff1 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Certificates/CertifiedMomentsJ2.lean @@ -0,0 +1,45 @@ +import Mathlib +import OAI.Probability.SKRatio.Certificates.CertifiedConstants +import OAI.Probability.SKRatio.Certificates.CertifiedMomentAssembly +import OAI.Probability.SKRatio.Certificates.ScalarDataJ2K0 +import OAI.Probability.SKRatio.Certificates.ScalarDataJ2K1 +import OAI.Probability.SKRatio.Certificates.ScalarDataJ2K2 +import OAI.Probability.SKRatio.Certificates.ScalarDataJ2K3 +import OAI.Probability.SKRatio.Certificates.ScalarDataJ2K4 +import OAI.Probability.SKRatio.Certificates.ScalarDataJ2K5 +import OAI.Probability.SKRatio.Certificates.ScalarDataJ2K6 +import OAI.Probability.SKRatio.Certificates.ScalarDataJ2K7 + +namespace OAI + +noncomputable section +open Real MeasureTheory +namespace SKRatio.Certificate +open Scalar + +theorem valid2 : Valid (89/200) X2 := by + refine ⟨?_,?_,?_,?_,?_,?_,?_,?_⟩ + · exact Data.J2K0.integral_bound + · exact Data.J2K1.integral_bound + · exact Data.J2K2.integral_bound + · exact Data.J2K3.integral_bound + · apply mem_sd_center memLp_v (c := (52021/62500)) (by norm_num : (0:ℚ) ≤ 181/1000) + convert! Data.J2K4.integral_bound using 1 <;> norm_num [scalarFunction] + · apply mem_sd_center memLp_g (c := (13423/25000)) (by norm_num : (0:ℚ) ≤ 103/1000) + convert! Data.J2K5.integral_bound using 1 <;> norm_num [scalarFunction] + · apply mem_sd_center memLp_mv (c := (21477/200000)) (by norm_num : (0:ℚ) ≤ 127/500) + convert! Data.J2K6.integral_bound using 1 <;> norm_num [scalarFunction] + · apply mem_F_of_center (A := (52021/62500)) (C := (13423/25000)) (Q := (81561/125000)) + (sa := (789/1000)) (sf := (397/500)) (by norm_num) (by norm_num) + (by norm_num) (by norm_num) + · convert! Data.J2K0.integral_bound using 1; norm_num [scalarFunction,a] + · convert! Data.J2K1.integral_bound using 1; norm_num [scalarFunction,G] + · norm_num + · convert! Data.J2K7.integral_bound using 1 <;> norm_num [scalarFunction] + · norm_num + +end SKRatio.Certificate + +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Certificates/CertifiedMomentsJ3.lean b/lean/OAI/Probability/SKRatio/Certificates/CertifiedMomentsJ3.lean new file mode 100644 index 0000000000000000000000000000000000000000..681291069f52a8f77d469d25141f4ddf5a54189d --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Certificates/CertifiedMomentsJ3.lean @@ -0,0 +1,47 @@ +import Mathlib +import OAI.Probability.SKRatio.Certificates.CertifiedConstants +import OAI.Probability.SKRatio.Certificates.CertifiedMomentAssembly +import OAI.Probability.SKRatio.Certificates.ScalarDataJ3K0 +import OAI.Probability.SKRatio.Certificates.ScalarDataJ3K1 +import OAI.Probability.SKRatio.Certificates.ScalarDataJ3K2 +import OAI.Probability.SKRatio.Certificates.ScalarDataJ3K3 +import OAI.Probability.SKRatio.Certificates.ScalarDataJ3K4 +import OAI.Probability.SKRatio.Certificates.ScalarDataJ3K5 +import OAI.Probability.SKRatio.Certificates.ScalarDataJ3K6 +import OAI.Probability.SKRatio.Certificates.ScalarDataJ3K7 + +namespace OAI + +noncomputable section +open Real MeasureTheory +namespace SKRatio.Certificate +open Scalar + +theorem valid3 : Valid (19/40) X3 := by + refine ⟨?_,?_,?_,?_,?_,?_,?_,?_⟩ + · exact Data.J3K0.integral_bound + · exact Data.J3K1.integral_bound + · exact Data.J3K2.integral_bound + · exact Data.J3K3.integral_bound + · apply mem_sd_center memLp_v (c := (406349/500000)) (by norm_num : (0:ℚ) ≤ 49/250) + convert! Data.J3K4.integral_bound using 1 <;> norm_num [scalarFunction] + · apply mem_sd_center memLp_g (c := (66273/125000)) (by norm_num : (0:ℚ) ≤ 109/1000) + convert! Data.J3K5.integral_bound using 1 <;> norm_num [scalarFunction] + · apply mem_sd_center memLp_mv (c := (28579/250000)) (by norm_num : (0:ℚ) ≤ 32/125) + convert! Data.J3K6.integral_bound using 1 <;> norm_num [scalarFunction] + · apply mem_F_of_center (A := (406349/500000)) (C := (66273/125000)) (Q := (135787/200000)) + (sa := (823/1000)) (sf := (207/250)) (by norm_num) (by norm_num) + (by norm_num) (by norm_num) + · convert! Data.J3K0.integral_bound using 1 + norm_num [scalarFunction,a] + · convert! Data.J3K1.integral_bound using 1 + norm_num [scalarFunction,G] + · norm_num + · convert! Data.J3K7.integral_bound using 1 <;> norm_num [scalarFunction] + · norm_num + +end SKRatio.Certificate + +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Certificates/CertifiedMomentsJ4.lean b/lean/OAI/Probability/SKRatio/Certificates/CertifiedMomentsJ4.lean new file mode 100644 index 0000000000000000000000000000000000000000..534e1eb890ff1fb116c7eda8589ae01d10a77131 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Certificates/CertifiedMomentsJ4.lean @@ -0,0 +1,47 @@ +import Mathlib +import OAI.Probability.SKRatio.Certificates.CertifiedConstants +import OAI.Probability.SKRatio.Certificates.CertifiedMomentAssembly +import OAI.Probability.SKRatio.Certificates.ScalarDataJ4K0 +import OAI.Probability.SKRatio.Certificates.ScalarDataJ4K1 +import OAI.Probability.SKRatio.Certificates.ScalarDataJ4K2 +import OAI.Probability.SKRatio.Certificates.ScalarDataJ4K3 +import OAI.Probability.SKRatio.Certificates.ScalarDataJ4K4 +import OAI.Probability.SKRatio.Certificates.ScalarDataJ4K5 +import OAI.Probability.SKRatio.Certificates.ScalarDataJ4K6 +import OAI.Probability.SKRatio.Certificates.ScalarDataJ4K7 + +namespace OAI + +noncomputable section +open Real MeasureTheory +namespace SKRatio.Certificate +open Scalar + +theorem valid4 : Valid (1/2) X4 := by + refine ⟨?_,?_,?_,?_,?_,?_,?_,?_⟩ + · exact Data.J4K0.integral_bound + · exact Data.J4K1.integral_bound + · exact Data.J4K2.integral_bound + · exact Data.J4K3.integral_bound + · apply mem_sd_center memLp_v (c := (397973/500000)) (by norm_num : (0:ℚ) ≤ 209/1000) + convert! Data.J4K4.integral_bound using 1 <;> norm_num [scalarFunction] + · apply mem_sd_center memLp_g (c := (524071/1000000)) (by norm_num : (0:ℚ) ≤ 23/200) + convert! Data.J4K5.integral_bound using 1 <;> norm_num [scalarFunction] + · apply mem_sd_center memLp_mv (c := (119553/1000000)) (by norm_num : (0:ℚ) ≤ 257/1000) + convert! Data.J4K6.integral_bound using 1 <;> norm_num [scalarFunction] + · apply mem_F_of_center (A := (397973/500000)) (C := (524071/1000000)) (Q := (702377/1000000)) + (sa := (17/20)) (sf := (171/200)) (by norm_num) (by norm_num) + (by norm_num) (by norm_num) + · convert! Data.J4K0.integral_bound using 1 + norm_num [scalarFunction,a] + · convert! Data.J4K1.integral_bound using 1 + norm_num [scalarFunction,G] + · norm_num + · convert! Data.J4K7.integral_bound using 1 <;> norm_num [scalarFunction] + · norm_num + +end SKRatio.Certificate + +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Certificates/CertifiedQuadrature.lean b/lean/OAI/Probability/SKRatio/Certificates/CertifiedQuadrature.lean new file mode 100644 index 0000000000000000000000000000000000000000..b89793a3da387e4b21621b32e6b48ab299354991 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Certificates/CertifiedQuadrature.lean @@ -0,0 +1,141 @@ +import Mathlib +import OAI.Probability.SKRatio.Certificates.CertifiedJet + +namespace OAI + +noncomputable section +open Real Set MeasureTheory +namespace SKRatio.Certificate + +namespace Box + +def absUpper (A : Box) : ℚ := max |A.lo| |A.hi| +def widen (A : Box) (r : ℚ) : Box := ⟨A.lo-r,A.hi+r⟩ + +def contains (A B : Box) : Bool := decide (A.lo ≤ B.lo ∧ B.hi ≤ A.hi) + +lemma mem_of_contains {A B : Box} {x : ℝ} (h : contains A B=true) (hx : x ∈ B) : x ∈ A := by + have h' : A.lo ≤ B.lo ∧ B.hi ≤ A.hi := of_decide_eq_true h + have hl : (A.lo:ℝ) ≤ B.lo := by exact_mod_cast h'.1 + have hu : (B.hi:ℝ) ≤ A.hi := by exact_mod_cast h'.2 + exact ⟨hl.trans hx.1,hx.2.trans hu⟩ + +lemma absUpper_nonneg (A : Box) : (0:ℝ) ≤ A.absUpper := by + exact_mod_cast (abs_nonneg A.lo).trans (le_max_left |A.lo| |A.hi|) + +lemma abs_le_absUpper {A : Box} {x : ℝ} (hx : x ∈ A) : |x| ≤ A.absUpper := by + have hl : |(A.lo:ℝ)| ≤ (A.absUpper:ℝ) := by simp [absUpper] + have hu : |(A.hi:ℝ)| ≤ (A.absUpper:ℝ) := by simp [absUpper] + exact abs_le.mpr ⟨by linarith [hx.1,(abs_le.mp hl).1],by linarith [hx.2,(abs_le.mp hu).2]⟩ + +lemma mem_widen {A : Box} {x y : ℝ} {r : ℚ} (hx : x ∈ A) (hy : |x-y| ≤ (r:ℝ)) : y ∈ widen A r := by + change (A.lo-r:ℚ) ≤ y ∧ y ≤ (A.hi+r:ℚ) + push_cast + obtain ⟨hy0,hy1⟩ := abs_le.mp hy + exact ⟨by linarith [hx.1],by linarith [hx.2]⟩ +end Box + +lemma trapezoid_bound {f f' f'' : ℝ → ℝ} {a b M : ℝ} (hab : a < b) + (hf : ∀ x ∈ Icc a b, HasDerivAt f (f' x) x) + (hf' : ∀ x ∈ Icc a b, HasDerivAt f' (f'' x) x) + (hM : 0 ≤ M) (hb : ∀ x ∈ Icc a b, |f'' x| ≤ M) : + |(b-a)/2*(f a+f b)-(∫ x in a..b, f x)| ≤ (b-a)^3*M/12 := by + have hud := uniqueDiffOn_Icc hab + have hd : EqOn (derivWithin f (Icc a b)) f' (Icc a b) := fun x hx => + (hf x hx).hasDerivWithinAt.derivWithin (hud x hx) + have hdd : DifferentiableOn ℝ (derivWithin f (Icc a b)) (Icc a b) := + (show DifferentiableOn ℝ f' (Icc a b) from + fun x hx => (hf' x hx).differentiableAt.differentiableWithinAt).congr hd + have h2 : ∀ x, |iteratedDerivWithin 2 f (Icc a b) x| ≤ M := by + intro x + rw [iteratedDerivWithin_succ',iteratedDerivWithin_succ',iteratedDerivWithin_zero] + by_cases hx : x ∈ Icc a b + · rw [derivWithin_congr hd (hd hx), (hf' x hx).hasDerivWithinAt.derivWithin (hud x hx)] + exact hb x hx + · rw [derivWithin_zero_of_notMem_closure (by simpa using hx), abs_zero] + exact hM + have h := trapezoidal_error_le (f := f) (a := a) (b := b) + (by rw [uIcc_of_lt hab]; exact fun x hx => (hf x hx).differentiableAt.differentiableWithinAt) + (by rwa [uIcc_of_lt hab]) (ζ := M) (by rwa [uIcc_of_lt hab]) (N := 1) (by decide) + simpa [trapezoidal_error,trapezoidal_integral_one,abs_of_pos (sub_pos.mpr hab)] using h + +namespace Expr + +def cell (e : Expr) (a b : ℚ) : Option Box := do + if ¬a (hf x hx).continuousAt.continuousWithinAt).intervalIntegrable_of_Icc hab'.le,?_⟩ + have ht := Box.mem_mul (Box.mem_rat ((b-a)/2)) (Box.mem_add hA.1 hB.1) + apply Box.mem_widen ht + push_cast + exact trapezoid_bound hab' hf hf' (Box.absUpper_nonneg J.sec) + (fun x hx => Box.abs_le_absUpper (hI x hx).2.2.1) + +def quad (e : Expr) (h : ℚ) : ℕ → ℚ → Option Box + | 0,_ => some (Box.rat 0) + | n+1,a => do + let A ← e.cell a (a+h) + let B ← e.quad h n (a+h) + return Box.add A B + +lemma quad_sound (e : Expr) {h a : ℚ} {n : ℕ} {A : Box} + (hc : e.quad h n a=some A) : + IntervalIntegrable e.val volume a (a+n*h:ℚ) ∧ + (∫ x in (a:ℝ)..(a+n*h:ℚ), e.val x) ∈ A := by + induction n generalizing A a with + | zero => + simp only [quad,Option.some.injEq] at hc + cases hc + simp only [Nat.cast_zero,zero_mul,add_zero,IntervalIntegrable.refl,intervalIntegral.integral_same] + exact ⟨trivial,by simpa only [Rat.cast_zero] using Box.mem_rat 0⟩ + | succ n hn => + simp only [quad,bind,pure,Option.bind_eq_some_iff,Option.some.injEq] at hc + obtain ⟨B,hB,C,hC,rfl⟩ := hc + obtain ⟨hi,hm⟩ := e.cell_sound hB + obtain ⟨hi',hm'⟩ := hn hC + have hh : a+h+(n:ℚ)*h = a+(n+1:ℕ)*h := by push_cast; ring + rw [hh] at hi' hm' + refine ⟨hi.trans hi',?_⟩ + rw [←intervalIntegral.integral_add_adjacent_intervals hi hi'] + exact Box.mem_add hm hm' + +def check (e : Expr) (a h : ℚ) (n : ℕ) (A : Box) : Bool := + match e.quad h n a with + | none => false + | some B => A.contains B + +lemma check_sound (e : Expr) {a h : ℚ} {n : ℕ} {A : Box} + (hc : e.check a h n A=true) : + IntervalIntegrable e.val volume a (a+n*h:ℚ) ∧ + (∫ x in (a:ℝ)..(a+n*h:ℚ), e.val x) ∈ A := by + unfold check at hc + split at hc + · contradiction + · rename_i B hB + obtain ⟨hi,hm⟩ := e.quad_sound hB + exact ⟨hi,Box.mem_of_contains hc hm⟩ + +end Expr +end SKRatio.Certificate + +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Certificates/FinalScalar.lean b/lean/OAI/Probability/SKRatio/Certificates/FinalScalar.lean new file mode 100644 index 0000000000000000000000000000000000000000..9d250575ec16ed422f45111c92a537479cf977df --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Certificates/FinalScalar.lean @@ -0,0 +1,74 @@ +import Mathlib +import OAI.Probability.SKRatio.Certificates.CertifiedMomentsJ0 +import OAI.Probability.SKRatio.Certificates.CertifiedMomentsJ1 +import OAI.Probability.SKRatio.Certificates.CertifiedMomentsJ2 +import OAI.Probability.SKRatio.Certificates.CertifiedMomentsJ3 +import OAI.Probability.SKRatio.Certificates.CertifiedMomentsJ4 +import OAI.Probability.SKRatio.Certificates.CertifiedEndpoints + +namespace OAI + +noncomputable section +open Real MeasureTheory +namespace SKRatio.Certificate +open Scalar + +lemma uniform_slacks {β : ℝ} (hβ : 7/20 ≤ β) (hβh : β ≤ 1/2) : + 511/1000 ≤ U₀ β ∧ 425/1000 ≤ U₁ β ∧ + sd (fieldLaw β) (F β) ≤ 925/1000 := by + by_cases h1 : β ≤ 2/5 + · apply certified_slacks (j := 7/20) (z := 2/5) (t := 27/25) (X := X0) (Y := X1) + · norm_num + · simpa only [Rat.cast_div,Rat.cast_ofNat] using hβ + · simpa only [Rat.cast_div,Rat.cast_ofNat] using h1 + · norm_num + · simpa only [Rat.cast_div,Rat.cast_ofNat] using valid0 + · simpa only [Rat.cast_div,Rat.cast_ofNat] using valid1 + · simpa only [Rat.cast_div,Rat.cast_ofNat] using density0 + · exact check0 + by_cases h2 : β ≤ 89/200 + · apply certified_slacks (j := 2/5) (z := 89/200) (t := 1067/1000) (X := X1) (Y := X2) + · norm_num + · simp only [Rat.cast_div,Rat.cast_ofNat]; linarith + · simpa only [Rat.cast_div,Rat.cast_ofNat] using h2 + · norm_num + · simpa only [Rat.cast_div,Rat.cast_ofNat] using valid1 + · simpa only [Rat.cast_div,Rat.cast_ofNat] using valid2 + · simpa only [Rat.cast_div,Rat.cast_ofNat] using density1 + · exact check1 + by_cases h3 : β ≤ 19/40 + · apply certified_slacks (j := 89/200) (z := 19/40) (t := 521/500) (X := X2) (Y := X3) + · norm_num + · simp only [Rat.cast_div,Rat.cast_ofNat]; linarith + · simpa only [Rat.cast_div,Rat.cast_ofNat] using h3 + · norm_num + · simpa only [Rat.cast_div,Rat.cast_ofNat] using valid2 + · simpa only [Rat.cast_div,Rat.cast_ofNat] using valid3 + · simpa only [Rat.cast_div,Rat.cast_ofNat] using density2 + · exact check2 + · apply certified_slacks (j := 19/40) (z := 1/2) (t := 517/500) (X := X3) (Y := X4) + · norm_num + · simp only [Rat.cast_div,Rat.cast_ofNat]; linarith + · simpa only [Rat.cast_div,Rat.cast_ofNat,Rat.cast_one] using hβh + · norm_num + · simpa only [Rat.cast_div,Rat.cast_ofNat] using valid3 + · simpa only [Rat.cast_div,Rat.cast_ofNat,Rat.cast_one] using valid4 + · simpa only [Rat.cast_div,Rat.cast_ofNat,Rat.cast_one] using density3 + · exact check3 + +theorem variational_bound {β : ℝ} (hβ : 7/20 ≤ β) (hβh : β ≤ 1/2) + {b r : ℝ → ℝ} (hb : MemLp b 2 (fieldLaw β)) (hr : MemLp r 2 (fieldLaw β)) + (hnorm : (∫ h, b h^2+r h^2 ∂fieldLaw β) = 1) : + variational β b r ≤ 9969/10000 := by + obtain ⟨h0,h1,hs⟩ := uniform_slacks hβ hβh + obtain ⟨hU,hdisc⟩ := discriminant_of_slacks h0 h1 hs + have he := variational_bound_of_two_estimates β (9789/10000) (18/1000) + (by norm_num) (diagonal_envelope (by linarith) hβh) + (fun b hb => coherent_bound_of_slacks (by linarith) hU hdisc hb) hb hr hnorm + convert! he using 1; norm_num + +end SKRatio.Certificate + +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Certificates/FixedExp.lean b/lean/OAI/Probability/SKRatio/Certificates/FixedExp.lean new file mode 100644 index 0000000000000000000000000000000000000000..dbd14f2f02beb3f6f7de8c19a919f77247ab4f59 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Certificates/FixedExp.lean @@ -0,0 +1,90 @@ +import Mathlib + +namespace OAI + +noncomputable section +open Real +namespace SKRatio.Certificate.Fixed + +def S : ℤ := 1000000000000000000000000 +structure I where + lo : ℤ + hi : ℤ + deriving DecidableEq, Repr + +def Mem (A : I) (x : ℝ) : Prop := (A.lo:ℝ)/(S:ℝ) ≤ x ∧ x ≤ (A.hi:ℝ)/(S:ℝ) +def round (a b : ℚ) : I := ⟨⌊a*(S:ℚ)⌋,⌈b*(S:ℚ)⌉⟩ +def sq (A : I) : I := ⟨(max 0 A.lo)^2/S,(A.hi^2+S)/S⟩ +def iter : ℕ → I → I + | 0,A => A + | n+1,A => iter n (sq A) +def expBounds (a b : ℚ) : I := + iter 30 (round (1+a/1073741824) (1/(1-b/1073741824))) + +lemma S_pos : (0:ℝ) < S := by norm_num [S] +lemma mem_round {a b : ℚ} {x : ℝ} (hx : (a:ℝ) ≤ x ∧ x ≤ b) : Mem (round a b) x := by + have hl : (⌊a*(S:ℚ)⌋:ℚ) ≤ a*(S:ℚ) := Int.floor_le _ + have hu : b*(S:ℚ) ≤ (⌈b*(S:ℚ)⌉:ℚ) := Int.le_ceil _ + have hl' : (⌊a*(S:ℚ)⌋:ℝ) ≤ (a:ℝ)*(S:ℝ) := by exact_mod_cast hl + have hu' : (b:ℝ)*(S:ℝ) ≤ (⌈b*(S:ℚ)⌉:ℝ) := by exact_mod_cast hu + exact ⟨((div_le_iff₀ S_pos).mpr hl').trans hx.1,hx.2.trans ((le_div_iff₀ S_pos).mpr hu')⟩ + +lemma mem_sq {A : I} {x : ℝ} (hx : Mem A x) (hp : 0 ≤ x) : Mem (sq A) (x^2) := by + have hl0 : (0:ℝ) ≤ (max 0 A.lo : ℤ)/(S:ℝ) := div_nonneg (by positivity) S_pos.le + have hl : ((max 0 A.lo : ℤ):ℝ)/(S:ℝ) ≤ x := by + rw [Int.cast_max,Int.cast_zero,←max_div_div_right S_pos.le] + exact max_le (by simpa using hp) hx.1 + have hu0 : (0:ℝ) ≤ (A.hi:ℝ)/(S:ℝ) := hp.trans hx.2 + have hl2 := (sq_le_sq₀ hl0 hp).mpr hl + have hu2 := (sq_le_sq₀ hp hu0).mpr hx.2 + have hL : ((max 0 A.lo)^2/S)*S ≤ (max 0 A.lo)^2 := Int.ediv_mul_le _ (by norm_num [S]) + have hU : A.hi^2 ≤ ((A.hi^2+S)/S)*S := by + have hh := Int.lt_ediv_mul (A.hi^2+S) (by norm_num [S] : (0:ℤ) < S) + linarith only [hh] + have hL' : ((max 0 A.lo)^2/S:ℤ)*(S:ℝ) ≤ ((max 0 A.lo:ℤ):ℝ)^2 := by exact_mod_cast hL + have hU' : (A.hi:ℝ)^2 ≤ ((A.hi^2+S)/S:ℤ)*(S:ℝ) := by exact_mod_cast hU + refine ⟨?_,?_⟩ + · change (((max 0 A.lo)^2/S:ℤ):ℝ)/(S:ℝ) ≤ x^2 + apply le_trans _ hl2 + rw [div_pow,div_le_div_iff₀ S_pos (sq_pos_of_pos S_pos)] + nlinarith only [mul_le_mul_of_nonneg_right hL' S_pos.le] + · change x^2 ≤ (((A.hi^2+S)/S:ℤ):ℝ)/(S:ℝ) + apply le_trans hu2 + rw [div_pow,div_le_div_iff₀ (sq_pos_of_pos S_pos) S_pos] + nlinarith only [mul_le_mul_of_nonneg_right hU' S_pos.le] + +lemma mem_iter {A : I} {x : ℝ} (hx : Mem A x) (hp : 0 ≤ x) (n : ℕ) : + Mem (iter n A) (x^(2^n)) := by + induction n generalizing A x with + | zero => simpa only [iter,pow_zero,pow_one] using hx + | succ n hn => + have h := hn (mem_sq hx hp) (sq_nonneg x) + simpa only [iter,←pow_mul,show (2:ℕ)^(n+1) = 2*2^n by rw [pow_succ,Nat.mul_comm]] using h + +lemma mem_expBounds {a b : ℚ} {x : ℝ} (hx : (a:ℝ) ≤ x ∧ x ≤ b) + (hb : b < 1073741824) : Mem (expBounds a b) (exp x) := by + have hhi : (b:ℝ) < 1073741824 := by exact_mod_cast hb + have hr : Mem (round (1+a/1073741824) (1/(1-b/1073741824))) (exp (x/1073741824)) := by + apply mem_round + push_cast + constructor + · have ht := add_one_le_exp (x/1073741824) + linarith only [hx.1,ht] + · have hden : 0 < 1-(b:ℝ)/1073741824 := by linarith + have hz : 1-(b:ℝ)/1073741824 ≤ exp (-(x/1073741824)) := by + have ht := add_one_le_exp (-(x/1073741824)) + linarith only [hx.2,ht] + have h := one_div_le_one_div_of_le hden hz + simpa only [exp_neg,one_div,inv_inv] using h + have he : exp (x/1073741824)^(2^30) = exp x := by + rw [←exp_nat_mul] + congr 1 + norm_num + ring + rw [←he] + exact mem_iter hr (exp_pos _).le 30 +end SKRatio.Certificate.Fixed + +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Certificates/ScalarDataJ0K0.lean b/lean/OAI/Probability/SKRatio/Certificates/ScalarDataJ0K0.lean new file mode 100644 index 0000000000000000000000000000000000000000..52429bebd6e1f6f807618dd84ecf83345d4840f4 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Certificates/ScalarDataJ0K0.lean @@ -0,0 +1,154 @@ +import Mathlib +import OAI.Probability.SKRatio.Certificates.CertifiedBatches +import OAI.Probability.SKRatio.Certificates.CertifiedFunctionBounds + +namespace OAI + +noncomputable section +open Real MeasureTheory +namespace SKRatio.Certificate.Data.J0K0 + +def expression : Expr := integrandExpr (7/20) (44507/50000) (110763/200000) (20333/250000) (14573/25000) 0 +def blocks : ℕ → Box + | 0 => ⟨-1/1000000,1/1000000⟩ + | 1 => ⟨-1/1000000,1/1000000⟩ + | 2 => ⟨-1/1000000,1/1000000⟩ + | 3 => ⟨-1/1000000,1/1000000⟩ + | 4 => ⟨-1/1000000,1/1000000⟩ + | 5 => ⟨-1/1000000,1/1000000⟩ + | 6 => ⟨-1/1000000,1/1000000⟩ + | 7 => ⟨-1/1000000,1/1000000⟩ + | 8 => ⟨-1/1000000,1/1000000⟩ + | 9 => ⟨-1/1000000,1/1000000⟩ + | 10 => ⟨1/1000000,1/500000⟩ + | 11 => ⟨1/62500,19/1000000⟩ + | 12 => ⟨81/500000,169/1000000⟩ + | 13 => ⟨297/250000,61/50000⟩ + | 14 => ⟨3309/500000,6739/1000000⟩ + | 15 => ⟨13957/500000,7057/250000⟩ + | 16 => ⟨88509/1000000,89029/1000000⟩ + | 17 => ⟨209517/1000000,26239/125000⟩ + | 18 => ⟨367737/1000000,23009/62500⟩ + | 19 => ⟨477123/1000000,478093/1000000⟩ + | 20 => ⟨457861/1000000,57341/125000⟩ + | 21 => ⟨325663/1000000,325973/1000000⟩ + | 22 => ⟨34441/200000,34543/200000⟩ + | 23 => ⟨68157/1000000,17169/250000⟩ + | 24 => ⟨4069/200000,5159/250000⟩ + | 25 => ⟨4611/1000000,4721/1000000⟩ + | 26 => ⟨399/500000,207/250000⟩ + | 27 => ⟨21/200000,113/1000000⟩ + | 28 => ⟨1/100000,3/250000⟩ + | 29 => ⟨0,1/500000⟩ + | 30 => ⟨-1/1000000,1/1000000⟩ + | 31 => ⟨-1/1000000,1/1000000⟩ + | 32 => ⟨-1/1000000,1/1000000⟩ + | 33 => ⟨-1/1000000,1/1000000⟩ + | 34 => ⟨-1/1000000,1/1000000⟩ + | 35 => ⟨-1/1000000,1/1000000⟩ + | 36 => ⟨-1/1000000,1/1000000⟩ + | 37 => ⟨-1/1000000,1/1000000⟩ + | 38 => ⟨-1/1000000,1/1000000⟩ + | 39 => ⟨-1/1000000,1/1000000⟩ + | _ => Box.rat 0 + +lemma check_0 : expression.check (-10+(0:ℚ)*(5*(1/10))) (1/10) 5 (blocks 0) = true := by decide +kernel +lemma check_1 : expression.check (-10+(1:ℚ)*(5*(1/10))) (1/10) 5 (blocks 1) = true := by decide +kernel +lemma check_2 : expression.check (-10+(2:ℚ)*(5*(1/10))) (1/10) 5 (blocks 2) = true := by decide +kernel +lemma check_3 : expression.check (-10+(3:ℚ)*(5*(1/10))) (1/10) 5 (blocks 3) = true := by decide +kernel +lemma check_4 : expression.check (-10+(4:ℚ)*(5*(1/10))) (1/10) 5 (blocks 4) = true := by decide +kernel +lemma check_5 : expression.check (-10+(5:ℚ)*(5*(1/10))) (1/10) 5 (blocks 5) = true := by decide +kernel +lemma check_6 : expression.check (-10+(6:ℚ)*(5*(1/10))) (1/10) 5 (blocks 6) = true := by decide +kernel +lemma check_7 : expression.check (-10+(7:ℚ)*(5*(1/10))) (1/10) 5 (blocks 7) = true := by decide +kernel +lemma check_8 : expression.check (-10+(8:ℚ)*(5*(1/10))) (1/10) 5 (blocks 8) = true := by decide +kernel +lemma check_9 : expression.check (-10+(9:ℚ)*(5*(1/10))) (1/10) 5 (blocks 9) = true := by decide +kernel +lemma check_10 : expression.check (-10+(10:ℚ)*(5*(1/10))) (1/10) 5 (blocks 10) = true := by decide +kernel +lemma check_11 : expression.check (-10+(11:ℚ)*(5*(1/10))) (1/10) 5 (blocks 11) = true := by decide +kernel +lemma check_12 : expression.check (-10+(12:ℚ)*(5*(1/10))) (1/10) 5 (blocks 12) = true := by decide +kernel +lemma check_13 : expression.check (-10+(13:ℚ)*(5*(1/10))) (1/10) 5 (blocks 13) = true := by decide +kernel +lemma check_14 : expression.check (-10+(14:ℚ)*(5*(1/10))) (1/10) 5 (blocks 14) = true := by decide +kernel +lemma check_15 : expression.check (-10+(15:ℚ)*(5*(1/10))) (1/10) 5 (blocks 15) = true := by decide +kernel +lemma check_16 : expression.check (-10+(16:ℚ)*(5*(1/10))) (1/10) 5 (blocks 16) = true := by decide +kernel +lemma check_17 : expression.check (-10+(17:ℚ)*(5*(1/10))) (1/10) 5 (blocks 17) = true := by decide +kernel +lemma check_18 : expression.check (-10+(18:ℚ)*(5*(1/10))) (1/10) 5 (blocks 18) = true := by decide +kernel +lemma check_19 : expression.check (-10+(19:ℚ)*(5*(1/10))) (1/10) 5 (blocks 19) = true := by decide +kernel +lemma check_20 : expression.check (-10+(20:ℚ)*(5*(1/10))) (1/10) 5 (blocks 20) = true := by decide +kernel +lemma check_21 : expression.check (-10+(21:ℚ)*(5*(1/10))) (1/10) 5 (blocks 21) = true := by decide +kernel +lemma check_22 : expression.check (-10+(22:ℚ)*(5*(1/10))) (1/10) 5 (blocks 22) = true := by decide +kernel +lemma check_23 : expression.check (-10+(23:ℚ)*(5*(1/10))) (1/10) 5 (blocks 23) = true := by decide +kernel +lemma check_24 : expression.check (-10+(24:ℚ)*(5*(1/10))) (1/10) 5 (blocks 24) = true := by decide +kernel +lemma check_25 : expression.check (-10+(25:ℚ)*(5*(1/10))) (1/10) 5 (blocks 25) = true := by decide +kernel +lemma check_26 : expression.check (-10+(26:ℚ)*(5*(1/10))) (1/10) 5 (blocks 26) = true := by decide +kernel +lemma check_27 : expression.check (-10+(27:ℚ)*(5*(1/10))) (1/10) 5 (blocks 27) = true := by decide +kernel +lemma check_28 : expression.check (-10+(28:ℚ)*(5*(1/10))) (1/10) 5 (blocks 28) = true := by decide +kernel +lemma check_29 : expression.check (-10+(29:ℚ)*(5*(1/10))) (1/10) 5 (blocks 29) = true := by decide +kernel +lemma check_30 : expression.check (-10+(30:ℚ)*(5*(1/10))) (1/10) 5 (blocks 30) = true := by decide +kernel +lemma check_31 : expression.check (-10+(31:ℚ)*(5*(1/10))) (1/10) 5 (blocks 31) = true := by decide +kernel +lemma check_32 : expression.check (-10+(32:ℚ)*(5*(1/10))) (1/10) 5 (blocks 32) = true := by decide +kernel +lemma check_33 : expression.check (-10+(33:ℚ)*(5*(1/10))) (1/10) 5 (blocks 33) = true := by decide +kernel +lemma check_34 : expression.check (-10+(34:ℚ)*(5*(1/10))) (1/10) 5 (blocks 34) = true := by decide +kernel +lemma check_35 : expression.check (-10+(35:ℚ)*(5*(1/10))) (1/10) 5 (blocks 35) = true := by decide +kernel +lemma check_36 : expression.check (-10+(36:ℚ)*(5*(1/10))) (1/10) 5 (blocks 36) = true := by decide +kernel +lemma check_37 : expression.check (-10+(37:ℚ)*(5*(1/10))) (1/10) 5 (blocks 37) = true := by decide +kernel +lemma check_38 : expression.check (-10+(38:ℚ)*(5*(1/10))) (1/10) 5 (blocks 38) = true := by decide +kernel +lemma check_39 : expression.check (-10+(39:ℚ)*(5*(1/10))) (1/10) 5 (blocks 39) = true := by decide +kernel + +lemma checks (i : ℕ) (hi : i < 40) : + expression.check (-10+(i:ℚ)*(5*(1/10))) (1/10) 5 (blocks i) = true := by + interval_cases i + · exact check_0 + · exact check_1 + · exact check_2 + · exact check_3 + · exact check_4 + · exact check_5 + · exact check_6 + · exact check_7 + · exact check_8 + · exact check_9 + · exact check_10 + · exact check_11 + · exact check_12 + · exact check_13 + · exact check_14 + · exact check_15 + · exact check_16 + · exact check_17 + · exact check_18 + · exact check_19 + · exact check_20 + · exact check_21 + · exact check_22 + · exact check_23 + · exact check_24 + · exact check_25 + · exact check_26 + · exact check_27 + · exact check_28 + · exact check_29 + · exact check_30 + · exact check_31 + · exact check_32 + · exact check_33 + · exact check_34 + · exact check_35 + · exact check_36 + · exact check_37 + · exact check_38 + · exact check_39 + +theorem integral_bound : + (∫ h, scalarFunction (7/20) (44507/50000) (110763/200000) (20333/250000) (14573/25000) 0 h ∂Scalar.fieldLaw (7/20)) ∈ (⟨2777/3125,22291/25000⟩ : Box) := by + apply gaussian_certificate (e := expression) (B := blocks) (h := (1/10)) (k := 5) (by norm_num) + · simpa only [expression,Rat.cast_div,Rat.cast_ofNat,Rat.cast_one,Rat.cast_zero] using integrandExpr_val (7/20) (44507/50000) (110763/200000) (20333/250000) (14573/25000) 0 + · exact (continuous_scalarFunction _ _ _ _ _ _).measurable + · intro x + apply scalarFunction_bound <;> norm_num + · exact checks + · decide +kernel + +end SKRatio.Certificate.Data.J0K0 + +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Certificates/ScalarDataJ0K1.lean b/lean/OAI/Probability/SKRatio/Certificates/ScalarDataJ0K1.lean new file mode 100644 index 0000000000000000000000000000000000000000..fe2fda577cabbb19a065da9d16dd28d57f030a03 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Certificates/ScalarDataJ0K1.lean @@ -0,0 +1,154 @@ +import Mathlib +import OAI.Probability.SKRatio.Certificates.CertifiedBatches +import OAI.Probability.SKRatio.Certificates.CertifiedFunctionBounds + +namespace OAI + +noncomputable section +open Real MeasureTheory +namespace SKRatio.Certificate.Data.J0K1 + +def expression : Expr := integrandExpr (7/20) (44507/50000) (110763/200000) (20333/250000) (14573/25000) 1 +def blocks : ℕ → Box + | 0 => ⟨-1/1000000,1/1000000⟩ + | 1 => ⟨-1/1000000,1/1000000⟩ + | 2 => ⟨-1/1000000,1/1000000⟩ + | 3 => ⟨-1/1000000,1/1000000⟩ + | 4 => ⟨-1/1000000,1/1000000⟩ + | 5 => ⟨-1/1000000,1/1000000⟩ + | 6 => ⟨-1/1000000,1/1000000⟩ + | 7 => ⟨-1/1000000,1/1000000⟩ + | 8 => ⟨-1/1000000,1/1000000⟩ + | 9 => ⟨-1/1000000,1/1000000⟩ + | 10 => ⟨0,1/1000000⟩ + | 11 => ⟨3/500000,1/125000⟩ + | 12 => ⟨63/1000000,33/500000⟩ + | 13 => ⟨237/500000,61/125000⟩ + | 14 => ⟨2731/1000000,557/200000⟩ + | 15 => ⟨12041/1000000,381/31250⟩ + | 16 => ⟨20197/500000,40677/1000000⟩ + | 17 => ⟨102507/1000000,102801/1000000⟩ + | 18 => ⟨48883/250000,195703/1000000⟩ + | 19 => ⟨69689/250000,279267/1000000⟩ + | 20 => ⟨74083/250000,296971/1000000⟩ + | 21 => ⟨117189/500000,117363/500000⟩ + | 22 => ⟨137699/1000000,34501/250000⟩ + | 23 => ⟨15027/250000,30263/500000⟩ + | 24 => ⟨9789/500000,19853/1000000⟩ + | 25 => ⟨4779/1000000,153/31250⟩ + | 26 => ⟨439/500000,457/500000⟩ + | 27 => ⟨61/500000,13/100000⟩ + | 28 => ⟨3/250000,3/200000⟩ + | 29 => ⟨0,1/500000⟩ + | 30 => ⟨-1/1000000,1/1000000⟩ + | 31 => ⟨-1/1000000,1/1000000⟩ + | 32 => ⟨-1/1000000,1/1000000⟩ + | 33 => ⟨-1/1000000,1/1000000⟩ + | 34 => ⟨-1/1000000,1/1000000⟩ + | 35 => ⟨-1/1000000,1/1000000⟩ + | 36 => ⟨-1/1000000,1/1000000⟩ + | 37 => ⟨-1/1000000,1/1000000⟩ + | 38 => ⟨-1/1000000,1/1000000⟩ + | 39 => ⟨-1/1000000,1/1000000⟩ + | _ => Box.rat 0 + +lemma check_0 : expression.check (-10+(0:ℚ)*(5*(1/10))) (1/10) 5 (blocks 0) = true := by decide +kernel +lemma check_1 : expression.check (-10+(1:ℚ)*(5*(1/10))) (1/10) 5 (blocks 1) = true := by decide +kernel +lemma check_2 : expression.check (-10+(2:ℚ)*(5*(1/10))) (1/10) 5 (blocks 2) = true := by decide +kernel +lemma check_3 : expression.check (-10+(3:ℚ)*(5*(1/10))) (1/10) 5 (blocks 3) = true := by decide +kernel +lemma check_4 : expression.check (-10+(4:ℚ)*(5*(1/10))) (1/10) 5 (blocks 4) = true := by decide +kernel +lemma check_5 : expression.check (-10+(5:ℚ)*(5*(1/10))) (1/10) 5 (blocks 5) = true := by decide +kernel +lemma check_6 : expression.check (-10+(6:ℚ)*(5*(1/10))) (1/10) 5 (blocks 6) = true := by decide +kernel +lemma check_7 : expression.check (-10+(7:ℚ)*(5*(1/10))) (1/10) 5 (blocks 7) = true := by decide +kernel +lemma check_8 : expression.check (-10+(8:ℚ)*(5*(1/10))) (1/10) 5 (blocks 8) = true := by decide +kernel +lemma check_9 : expression.check (-10+(9:ℚ)*(5*(1/10))) (1/10) 5 (blocks 9) = true := by decide +kernel +lemma check_10 : expression.check (-10+(10:ℚ)*(5*(1/10))) (1/10) 5 (blocks 10) = true := by decide +kernel +lemma check_11 : expression.check (-10+(11:ℚ)*(5*(1/10))) (1/10) 5 (blocks 11) = true := by decide +kernel +lemma check_12 : expression.check (-10+(12:ℚ)*(5*(1/10))) (1/10) 5 (blocks 12) = true := by decide +kernel +lemma check_13 : expression.check (-10+(13:ℚ)*(5*(1/10))) (1/10) 5 (blocks 13) = true := by decide +kernel +lemma check_14 : expression.check (-10+(14:ℚ)*(5*(1/10))) (1/10) 5 (blocks 14) = true := by decide +kernel +lemma check_15 : expression.check (-10+(15:ℚ)*(5*(1/10))) (1/10) 5 (blocks 15) = true := by decide +kernel +lemma check_16 : expression.check (-10+(16:ℚ)*(5*(1/10))) (1/10) 5 (blocks 16) = true := by decide +kernel +lemma check_17 : expression.check (-10+(17:ℚ)*(5*(1/10))) (1/10) 5 (blocks 17) = true := by decide +kernel +lemma check_18 : expression.check (-10+(18:ℚ)*(5*(1/10))) (1/10) 5 (blocks 18) = true := by decide +kernel +lemma check_19 : expression.check (-10+(19:ℚ)*(5*(1/10))) (1/10) 5 (blocks 19) = true := by decide +kernel +lemma check_20 : expression.check (-10+(20:ℚ)*(5*(1/10))) (1/10) 5 (blocks 20) = true := by decide +kernel +lemma check_21 : expression.check (-10+(21:ℚ)*(5*(1/10))) (1/10) 5 (blocks 21) = true := by decide +kernel +lemma check_22 : expression.check (-10+(22:ℚ)*(5*(1/10))) (1/10) 5 (blocks 22) = true := by decide +kernel +lemma check_23 : expression.check (-10+(23:ℚ)*(5*(1/10))) (1/10) 5 (blocks 23) = true := by decide +kernel +lemma check_24 : expression.check (-10+(24:ℚ)*(5*(1/10))) (1/10) 5 (blocks 24) = true := by decide +kernel +lemma check_25 : expression.check (-10+(25:ℚ)*(5*(1/10))) (1/10) 5 (blocks 25) = true := by decide +kernel +lemma check_26 : expression.check (-10+(26:ℚ)*(5*(1/10))) (1/10) 5 (blocks 26) = true := by decide +kernel +lemma check_27 : expression.check (-10+(27:ℚ)*(5*(1/10))) (1/10) 5 (blocks 27) = true := by decide +kernel +lemma check_28 : expression.check (-10+(28:ℚ)*(5*(1/10))) (1/10) 5 (blocks 28) = true := by decide +kernel +lemma check_29 : expression.check (-10+(29:ℚ)*(5*(1/10))) (1/10) 5 (blocks 29) = true := by decide +kernel +lemma check_30 : expression.check (-10+(30:ℚ)*(5*(1/10))) (1/10) 5 (blocks 30) = true := by decide +kernel +lemma check_31 : expression.check (-10+(31:ℚ)*(5*(1/10))) (1/10) 5 (blocks 31) = true := by decide +kernel +lemma check_32 : expression.check (-10+(32:ℚ)*(5*(1/10))) (1/10) 5 (blocks 32) = true := by decide +kernel +lemma check_33 : expression.check (-10+(33:ℚ)*(5*(1/10))) (1/10) 5 (blocks 33) = true := by decide +kernel +lemma check_34 : expression.check (-10+(34:ℚ)*(5*(1/10))) (1/10) 5 (blocks 34) = true := by decide +kernel +lemma check_35 : expression.check (-10+(35:ℚ)*(5*(1/10))) (1/10) 5 (blocks 35) = true := by decide +kernel +lemma check_36 : expression.check (-10+(36:ℚ)*(5*(1/10))) (1/10) 5 (blocks 36) = true := by decide +kernel +lemma check_37 : expression.check (-10+(37:ℚ)*(5*(1/10))) (1/10) 5 (blocks 37) = true := by decide +kernel +lemma check_38 : expression.check (-10+(38:ℚ)*(5*(1/10))) (1/10) 5 (blocks 38) = true := by decide +kernel +lemma check_39 : expression.check (-10+(39:ℚ)*(5*(1/10))) (1/10) 5 (blocks 39) = true := by decide +kernel + +lemma checks (i : ℕ) (hi : i < 40) : + expression.check (-10+(i:ℚ)*(5*(1/10))) (1/10) 5 (blocks i) = true := by + interval_cases i + · exact check_0 + · exact check_1 + · exact check_2 + · exact check_3 + · exact check_4 + · exact check_5 + · exact check_6 + · exact check_7 + · exact check_8 + · exact check_9 + · exact check_10 + · exact check_11 + · exact check_12 + · exact check_13 + · exact check_14 + · exact check_15 + · exact check_16 + · exact check_17 + · exact check_18 + · exact check_19 + · exact check_20 + · exact check_21 + · exact check_22 + · exact check_23 + · exact check_24 + · exact check_25 + · exact check_26 + · exact check_27 + · exact check_28 + · exact check_29 + · exact check_30 + · exact check_31 + · exact check_32 + · exact check_33 + · exact check_34 + · exact check_35 + · exact check_36 + · exact check_37 + · exact check_38 + · exact check_39 + +theorem integral_bound : + (∫ h, scalarFunction (7/20) (44507/50000) (110763/200000) (20333/250000) (14573/25000) 1 h ∂Scalar.fieldLaw (7/20)) ∈ (⟨110463/200000,111063/200000⟩ : Box) := by + apply gaussian_certificate (e := expression) (B := blocks) (h := (1/10)) (k := 5) (by norm_num) + · simpa only [expression,Rat.cast_div,Rat.cast_ofNat,Rat.cast_one,Rat.cast_zero] using integrandExpr_val (7/20) (44507/50000) (110763/200000) (20333/250000) (14573/25000) 1 + · exact (continuous_scalarFunction _ _ _ _ _ _).measurable + · intro x + apply scalarFunction_bound <;> norm_num + · exact checks + · decide +kernel + +end SKRatio.Certificate.Data.J0K1 + +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Certificates/ScalarDataJ0K2.lean b/lean/OAI/Probability/SKRatio/Certificates/ScalarDataJ0K2.lean new file mode 100644 index 0000000000000000000000000000000000000000..55f1e0720579642986deb6c86e3532f4938ce438 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Certificates/ScalarDataJ0K2.lean @@ -0,0 +1,154 @@ +import Mathlib +import OAI.Probability.SKRatio.Certificates.CertifiedBatches +import OAI.Probability.SKRatio.Certificates.CertifiedFunctionBounds + +namespace OAI + +noncomputable section +open Real MeasureTheory +namespace SKRatio.Certificate.Data.J0K2 + +def expression : Expr := integrandExpr (7/20) (44507/50000) (110763/200000) (20333/250000) (14573/25000) 2 +def blocks : ℕ → Box + | 0 => ⟨-1/1000000,1/1000000⟩ + | 1 => ⟨-1/1000000,1/1000000⟩ + | 2 => ⟨-1/1000000,1/1000000⟩ + | 3 => ⟨-1/1000000,1/1000000⟩ + | 4 => ⟨-1/1000000,1/1000000⟩ + | 5 => ⟨-1/1000000,1/1000000⟩ + | 6 => ⟨-1/1000000,1/1000000⟩ + | 7 => ⟨-1/1000000,1/1000000⟩ + | 8 => ⟨-1/1000000,1/1000000⟩ + | 9 => ⟨-1/1000000,1/1000000⟩ + | 10 => ⟨-1/500000,-1/1000000⟩ + | 11 => ⟨-1/62500,-7/500000⟩ + | 12 => ⟨-139/1000000,-133/1000000⟩ + | 13 => ⟨-921/1000000,-449/500000⟩ + | 14 => ⟨-4521/1000000,-4453/1000000⟩ + | 15 => ⟨-999/62500,-7931/500000⟩ + | 16 => ⟨-39167/1000000,-7813/200000⟩ + | 17 => ⟨-61811/1000000,-30749/500000⟩ + | 18 => ⟨-4891/100000,-48441/1000000⟩ + | 19 => ⟨8697/500000,17603/1000000⟩ + | 20 => ⟨2907/31250,93501/1000000⟩ + | 21 => ⟨23371/200000,23473/200000⟩ + | 22 => ⟨4287/50000,85947/1000000⟩ + | 23 => ⟨20971/500000,42191/1000000⟩ + | 24 => ⟨3613/250000,14649/1000000⟩ + | 25 => ⟨3619/1000000,3707/1000000⟩ + | 26 => ⟨671/1000000,349/500000⟩ + | 27 => ⟨93/1000000,1/10000⟩ + | 28 => ⟨9/1000000,11/1000000⟩ + | 29 => ⟨0,1/500000⟩ + | 30 => ⟨-1/1000000,1/1000000⟩ + | 31 => ⟨-1/1000000,1/1000000⟩ + | 32 => ⟨-1/1000000,1/1000000⟩ + | 33 => ⟨-1/1000000,1/1000000⟩ + | 34 => ⟨-1/1000000,1/1000000⟩ + | 35 => ⟨-1/1000000,1/1000000⟩ + | 36 => ⟨-1/1000000,1/1000000⟩ + | 37 => ⟨-1/1000000,1/1000000⟩ + | 38 => ⟨-1/1000000,1/1000000⟩ + | 39 => ⟨-1/1000000,1/1000000⟩ + | _ => Box.rat 0 + +lemma check_0 : expression.check (-10+(0:ℚ)*(5*(1/10))) (1/10) 5 (blocks 0) = true := by decide +kernel +lemma check_1 : expression.check (-10+(1:ℚ)*(5*(1/10))) (1/10) 5 (blocks 1) = true := by decide +kernel +lemma check_2 : expression.check (-10+(2:ℚ)*(5*(1/10))) (1/10) 5 (blocks 2) = true := by decide +kernel +lemma check_3 : expression.check (-10+(3:ℚ)*(5*(1/10))) (1/10) 5 (blocks 3) = true := by decide +kernel +lemma check_4 : expression.check (-10+(4:ℚ)*(5*(1/10))) (1/10) 5 (blocks 4) = true := by decide +kernel +lemma check_5 : expression.check (-10+(5:ℚ)*(5*(1/10))) (1/10) 5 (blocks 5) = true := by decide +kernel +lemma check_6 : expression.check (-10+(6:ℚ)*(5*(1/10))) (1/10) 5 (blocks 6) = true := by decide +kernel +lemma check_7 : expression.check (-10+(7:ℚ)*(5*(1/10))) (1/10) 5 (blocks 7) = true := by decide +kernel +lemma check_8 : expression.check (-10+(8:ℚ)*(5*(1/10))) (1/10) 5 (blocks 8) = true := by decide +kernel +lemma check_9 : expression.check (-10+(9:ℚ)*(5*(1/10))) (1/10) 5 (blocks 9) = true := by decide +kernel +lemma check_10 : expression.check (-10+(10:ℚ)*(5*(1/10))) (1/10) 5 (blocks 10) = true := by decide +kernel +lemma check_11 : expression.check (-10+(11:ℚ)*(5*(1/10))) (1/10) 5 (blocks 11) = true := by decide +kernel +lemma check_12 : expression.check (-10+(12:ℚ)*(5*(1/10))) (1/10) 5 (blocks 12) = true := by decide +kernel +lemma check_13 : expression.check (-10+(13:ℚ)*(5*(1/10))) (1/10) 5 (blocks 13) = true := by decide +kernel +lemma check_14 : expression.check (-10+(14:ℚ)*(5*(1/10))) (1/10) 5 (blocks 14) = true := by decide +kernel +lemma check_15 : expression.check (-10+(15:ℚ)*(5*(1/10))) (1/10) 5 (blocks 15) = true := by decide +kernel +lemma check_16 : expression.check (-10+(16:ℚ)*(5*(1/10))) (1/10) 5 (blocks 16) = true := by decide +kernel +lemma check_17 : expression.check (-10+(17:ℚ)*(5*(1/10))) (1/10) 5 (blocks 17) = true := by decide +kernel +lemma check_18 : expression.check (-10+(18:ℚ)*(5*(1/10))) (1/10) 5 (blocks 18) = true := by decide +kernel +lemma check_19 : expression.check (-10+(19:ℚ)*(5*(1/10))) (1/10) 5 (blocks 19) = true := by decide +kernel +lemma check_20 : expression.check (-10+(20:ℚ)*(5*(1/10))) (1/10) 5 (blocks 20) = true := by decide +kernel +lemma check_21 : expression.check (-10+(21:ℚ)*(5*(1/10))) (1/10) 5 (blocks 21) = true := by decide +kernel +lemma check_22 : expression.check (-10+(22:ℚ)*(5*(1/10))) (1/10) 5 (blocks 22) = true := by decide +kernel +lemma check_23 : expression.check (-10+(23:ℚ)*(5*(1/10))) (1/10) 5 (blocks 23) = true := by decide +kernel +lemma check_24 : expression.check (-10+(24:ℚ)*(5*(1/10))) (1/10) 5 (blocks 24) = true := by decide +kernel +lemma check_25 : expression.check (-10+(25:ℚ)*(5*(1/10))) (1/10) 5 (blocks 25) = true := by decide +kernel +lemma check_26 : expression.check (-10+(26:ℚ)*(5*(1/10))) (1/10) 5 (blocks 26) = true := by decide +kernel +lemma check_27 : expression.check (-10+(27:ℚ)*(5*(1/10))) (1/10) 5 (blocks 27) = true := by decide +kernel +lemma check_28 : expression.check (-10+(28:ℚ)*(5*(1/10))) (1/10) 5 (blocks 28) = true := by decide +kernel +lemma check_29 : expression.check (-10+(29:ℚ)*(5*(1/10))) (1/10) 5 (blocks 29) = true := by decide +kernel +lemma check_30 : expression.check (-10+(30:ℚ)*(5*(1/10))) (1/10) 5 (blocks 30) = true := by decide +kernel +lemma check_31 : expression.check (-10+(31:ℚ)*(5*(1/10))) (1/10) 5 (blocks 31) = true := by decide +kernel +lemma check_32 : expression.check (-10+(32:ℚ)*(5*(1/10))) (1/10) 5 (blocks 32) = true := by decide +kernel +lemma check_33 : expression.check (-10+(33:ℚ)*(5*(1/10))) (1/10) 5 (blocks 33) = true := by decide +kernel +lemma check_34 : expression.check (-10+(34:ℚ)*(5*(1/10))) (1/10) 5 (blocks 34) = true := by decide +kernel +lemma check_35 : expression.check (-10+(35:ℚ)*(5*(1/10))) (1/10) 5 (blocks 35) = true := by decide +kernel +lemma check_36 : expression.check (-10+(36:ℚ)*(5*(1/10))) (1/10) 5 (blocks 36) = true := by decide +kernel +lemma check_37 : expression.check (-10+(37:ℚ)*(5*(1/10))) (1/10) 5 (blocks 37) = true := by decide +kernel +lemma check_38 : expression.check (-10+(38:ℚ)*(5*(1/10))) (1/10) 5 (blocks 38) = true := by decide +kernel +lemma check_39 : expression.check (-10+(39:ℚ)*(5*(1/10))) (1/10) 5 (blocks 39) = true := by decide +kernel + +lemma checks (i : ℕ) (hi : i < 40) : + expression.check (-10+(i:ℚ)*(5*(1/10))) (1/10) 5 (blocks i) = true := by + interval_cases i + · exact check_0 + · exact check_1 + · exact check_2 + · exact check_3 + · exact check_4 + · exact check_5 + · exact check_6 + · exact check_7 + · exact check_8 + · exact check_9 + · exact check_10 + · exact check_11 + · exact check_12 + · exact check_13 + · exact check_14 + · exact check_15 + · exact check_16 + · exact check_17 + · exact check_18 + · exact check_19 + · exact check_20 + · exact check_21 + · exact check_22 + · exact check_23 + · exact check_24 + · exact check_25 + · exact check_26 + · exact check_27 + · exact check_28 + · exact check_29 + · exact check_30 + · exact check_31 + · exact check_32 + · exact check_33 + · exact check_34 + · exact check_35 + · exact check_36 + · exact check_37 + · exact check_38 + · exact check_39 + +theorem integral_bound : + (∫ h, scalarFunction (7/20) (44507/50000) (110763/200000) (20333/250000) (14573/25000) 2 h ∂Scalar.fieldLaw (7/20)) ∈ (⟨9979/125000,5177/62500⟩ : Box) := by + apply gaussian_certificate (e := expression) (B := blocks) (h := (1/10)) (k := 5) (by norm_num) + · simpa only [expression,Rat.cast_div,Rat.cast_ofNat,Rat.cast_one,Rat.cast_zero] using integrandExpr_val (7/20) (44507/50000) (110763/200000) (20333/250000) (14573/25000) 2 + · exact (continuous_scalarFunction _ _ _ _ _ _).measurable + · intro x + apply scalarFunction_bound <;> norm_num + · exact checks + · decide +kernel + +end SKRatio.Certificate.Data.J0K2 + +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Certificates/ScalarDataJ0K3.lean b/lean/OAI/Probability/SKRatio/Certificates/ScalarDataJ0K3.lean new file mode 100644 index 0000000000000000000000000000000000000000..4ae18ef262888073c93ee368448410f9e16c6660 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Certificates/ScalarDataJ0K3.lean @@ -0,0 +1,154 @@ +import Mathlib +import OAI.Probability.SKRatio.Certificates.CertifiedBatches +import OAI.Probability.SKRatio.Certificates.CertifiedFunctionBounds + +namespace OAI + +noncomputable section +open Real MeasureTheory +namespace SKRatio.Certificate.Data.J0K3 + +def expression : Expr := integrandExpr (7/20) (44507/50000) (110763/200000) (20333/250000) (14573/25000) 3 +def blocks : ℕ → Box + | 0 => ⟨-1/1000000,1/1000000⟩ + | 1 => ⟨-1/1000000,1/1000000⟩ + | 2 => ⟨-1/1000000,1/1000000⟩ + | 3 => ⟨-1/1000000,1/1000000⟩ + | 4 => ⟨-1/1000000,1/1000000⟩ + | 5 => ⟨-1/1000000,1/1000000⟩ + | 6 => ⟨-1/1000000,1/1000000⟩ + | 7 => ⟨-1/1000000,1/1000000⟩ + | 8 => ⟨-1/1000000,1/1000000⟩ + | 9 => ⟨-1/1000000,1/1000000⟩ + | 10 => ⟨-1/1000000,1/1000000⟩ + | 11 => ⟨-1/1000000,1/1000000⟩ + | 12 => ⟨1/500000,3/1000000⟩ + | 13 => ⟨11/500000,1/40000⟩ + | 14 => ⟨77/500000,81/500000⟩ + | 15 => ⟨371/500000,763/1000000⟩ + | 16 => ⟨1217/500000,2473/1000000⟩ + | 17 => ⟨5177/1000000,2617/500000⟩ + | 18 => ⟨3247/500000,1317/200000⟩ + | 19 => ⟨961/250000,1961/500000⟩ + | 20 => ⟨399/1000000,569/1000000⟩ + | 21 => ⟨321/200000,1847/1000000⟩ + | 22 => ⟨647/125000,1101/200000⟩ + | 23 => ⟨71/12500,3003/500000⟩ + | 24 => ⟨1687/500000,3567/1000000⟩ + | 25 => ⟨39/31250,83/62500⟩ + | 26 => ⟨307/1000000,333/1000000⟩ + | 27 => ⟨13/250000,59/1000000⟩ + | 28 => ⟨3/500000,1/125000⟩ + | 29 => ⟨0,1/1000000⟩ + | 30 => ⟨-1/1000000,1/1000000⟩ + | 31 => ⟨-1/1000000,1/1000000⟩ + | 32 => ⟨-1/1000000,1/1000000⟩ + | 33 => ⟨-1/1000000,1/1000000⟩ + | 34 => ⟨-1/1000000,1/1000000⟩ + | 35 => ⟨-1/1000000,1/1000000⟩ + | 36 => ⟨-1/1000000,1/1000000⟩ + | 37 => ⟨-1/1000000,1/1000000⟩ + | 38 => ⟨-1/1000000,1/1000000⟩ + | 39 => ⟨-1/1000000,1/1000000⟩ + | _ => Box.rat 0 + +lemma check_0 : expression.check (-10+(0:ℚ)*(5*(1/10))) (1/10) 5 (blocks 0) = true := by decide +kernel +lemma check_1 : expression.check (-10+(1:ℚ)*(5*(1/10))) (1/10) 5 (blocks 1) = true := by decide +kernel +lemma check_2 : expression.check (-10+(2:ℚ)*(5*(1/10))) (1/10) 5 (blocks 2) = true := by decide +kernel +lemma check_3 : expression.check (-10+(3:ℚ)*(5*(1/10))) (1/10) 5 (blocks 3) = true := by decide +kernel +lemma check_4 : expression.check (-10+(4:ℚ)*(5*(1/10))) (1/10) 5 (blocks 4) = true := by decide +kernel +lemma check_5 : expression.check (-10+(5:ℚ)*(5*(1/10))) (1/10) 5 (blocks 5) = true := by decide +kernel +lemma check_6 : expression.check (-10+(6:ℚ)*(5*(1/10))) (1/10) 5 (blocks 6) = true := by decide +kernel +lemma check_7 : expression.check (-10+(7:ℚ)*(5*(1/10))) (1/10) 5 (blocks 7) = true := by decide +kernel +lemma check_8 : expression.check (-10+(8:ℚ)*(5*(1/10))) (1/10) 5 (blocks 8) = true := by decide +kernel +lemma check_9 : expression.check (-10+(9:ℚ)*(5*(1/10))) (1/10) 5 (blocks 9) = true := by decide +kernel +lemma check_10 : expression.check (-10+(10:ℚ)*(5*(1/10))) (1/10) 5 (blocks 10) = true := by decide +kernel +lemma check_11 : expression.check (-10+(11:ℚ)*(5*(1/10))) (1/10) 5 (blocks 11) = true := by decide +kernel +lemma check_12 : expression.check (-10+(12:ℚ)*(5*(1/10))) (1/10) 5 (blocks 12) = true := by decide +kernel +lemma check_13 : expression.check (-10+(13:ℚ)*(5*(1/10))) (1/10) 5 (blocks 13) = true := by decide +kernel +lemma check_14 : expression.check (-10+(14:ℚ)*(5*(1/10))) (1/10) 5 (blocks 14) = true := by decide +kernel +lemma check_15 : expression.check (-10+(15:ℚ)*(5*(1/10))) (1/10) 5 (blocks 15) = true := by decide +kernel +lemma check_16 : expression.check (-10+(16:ℚ)*(5*(1/10))) (1/10) 5 (blocks 16) = true := by decide +kernel +lemma check_17 : expression.check (-10+(17:ℚ)*(5*(1/10))) (1/10) 5 (blocks 17) = true := by decide +kernel +lemma check_18 : expression.check (-10+(18:ℚ)*(5*(1/10))) (1/10) 5 (blocks 18) = true := by decide +kernel +lemma check_19 : expression.check (-10+(19:ℚ)*(5*(1/10))) (1/10) 5 (blocks 19) = true := by decide +kernel +lemma check_20 : expression.check (-10+(20:ℚ)*(5*(1/10))) (1/10) 5 (blocks 20) = true := by decide +kernel +lemma check_21 : expression.check (-10+(21:ℚ)*(5*(1/10))) (1/10) 5 (blocks 21) = true := by decide +kernel +lemma check_22 : expression.check (-10+(22:ℚ)*(5*(1/10))) (1/10) 5 (blocks 22) = true := by decide +kernel +lemma check_23 : expression.check (-10+(23:ℚ)*(5*(1/10))) (1/10) 5 (blocks 23) = true := by decide +kernel +lemma check_24 : expression.check (-10+(24:ℚ)*(5*(1/10))) (1/10) 5 (blocks 24) = true := by decide +kernel +lemma check_25 : expression.check (-10+(25:ℚ)*(5*(1/10))) (1/10) 5 (blocks 25) = true := by decide +kernel +lemma check_26 : expression.check (-10+(26:ℚ)*(5*(1/10))) (1/10) 5 (blocks 26) = true := by decide +kernel +lemma check_27 : expression.check (-10+(27:ℚ)*(5*(1/10))) (1/10) 5 (blocks 27) = true := by decide +kernel +lemma check_28 : expression.check (-10+(28:ℚ)*(5*(1/10))) (1/10) 5 (blocks 28) = true := by decide +kernel +lemma check_29 : expression.check (-10+(29:ℚ)*(5*(1/10))) (1/10) 5 (blocks 29) = true := by decide +kernel +lemma check_30 : expression.check (-10+(30:ℚ)*(5*(1/10))) (1/10) 5 (blocks 30) = true := by decide +kernel +lemma check_31 : expression.check (-10+(31:ℚ)*(5*(1/10))) (1/10) 5 (blocks 31) = true := by decide +kernel +lemma check_32 : expression.check (-10+(32:ℚ)*(5*(1/10))) (1/10) 5 (blocks 32) = true := by decide +kernel +lemma check_33 : expression.check (-10+(33:ℚ)*(5*(1/10))) (1/10) 5 (blocks 33) = true := by decide +kernel +lemma check_34 : expression.check (-10+(34:ℚ)*(5*(1/10))) (1/10) 5 (blocks 34) = true := by decide +kernel +lemma check_35 : expression.check (-10+(35:ℚ)*(5*(1/10))) (1/10) 5 (blocks 35) = true := by decide +kernel +lemma check_36 : expression.check (-10+(36:ℚ)*(5*(1/10))) (1/10) 5 (blocks 36) = true := by decide +kernel +lemma check_37 : expression.check (-10+(37:ℚ)*(5*(1/10))) (1/10) 5 (blocks 37) = true := by decide +kernel +lemma check_38 : expression.check (-10+(38:ℚ)*(5*(1/10))) (1/10) 5 (blocks 38) = true := by decide +kernel +lemma check_39 : expression.check (-10+(39:ℚ)*(5*(1/10))) (1/10) 5 (blocks 39) = true := by decide +kernel + +lemma checks (i : ℕ) (hi : i < 40) : + expression.check (-10+(i:ℚ)*(5*(1/10))) (1/10) 5 (blocks i) = true := by + interval_cases i + · exact check_0 + · exact check_1 + · exact check_2 + · exact check_3 + · exact check_4 + · exact check_5 + · exact check_6 + · exact check_7 + · exact check_8 + · exact check_9 + · exact check_10 + · exact check_11 + · exact check_12 + · exact check_13 + · exact check_14 + · exact check_15 + · exact check_16 + · exact check_17 + · exact check_18 + · exact check_19 + · exact check_20 + · exact check_21 + · exact check_22 + · exact check_23 + · exact check_24 + · exact check_25 + · exact check_26 + · exact check_27 + · exact check_28 + · exact check_29 + · exact check_30 + · exact check_31 + · exact check_32 + · exact check_33 + · exact check_34 + · exact check_35 + · exact check_36 + · exact check_37 + · exact check_38 + · exact check_39 + +theorem integral_bound : + (∫ h, scalarFunction (7/20) (44507/50000) (110763/200000) (20333/250000) (14573/25000) 3 h ∂Scalar.fieldLaw (7/20)) ∈ (⟨0,33/2000⟩ : Box) := by + apply gaussian_certificate (e := expression) (B := blocks) (h := (1/10)) (k := 5) (by norm_num) + · simpa only [expression,Rat.cast_div,Rat.cast_ofNat,Rat.cast_one,Rat.cast_zero] using integrandExpr_val (7/20) (44507/50000) (110763/200000) (20333/250000) (14573/25000) 3 + · exact (continuous_scalarFunction _ _ _ _ _ _).measurable + · intro x + apply scalarFunction_bound <;> norm_num + · exact checks + · decide +kernel + +end SKRatio.Certificate.Data.J0K3 + +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Certificates/ScalarDataJ0K4.lean b/lean/OAI/Probability/SKRatio/Certificates/ScalarDataJ0K4.lean new file mode 100644 index 0000000000000000000000000000000000000000..599b030b10bf17e1f80b706b3b9ede46798738db --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Certificates/ScalarDataJ0K4.lean @@ -0,0 +1,154 @@ +import Mathlib +import OAI.Probability.SKRatio.Certificates.CertifiedBatches +import OAI.Probability.SKRatio.Certificates.CertifiedFunctionBounds + +namespace OAI + +noncomputable section +open Real MeasureTheory +namespace SKRatio.Certificate.Data.J0K4 + +def expression : Expr := integrandExpr (7/20) (44507/50000) (110763/200000) (20333/250000) (14573/25000) 4 +def blocks : ℕ → Box + | 0 => ⟨-1/1000000,1/1000000⟩ + | 1 => ⟨-1/1000000,1/1000000⟩ + | 2 => ⟨-1/1000000,1/1000000⟩ + | 3 => ⟨-1/1000000,1/1000000⟩ + | 4 => ⟨-1/1000000,1/1000000⟩ + | 5 => ⟨-1/1000000,1/1000000⟩ + | 6 => ⟨-1/1000000,1/1000000⟩ + | 7 => ⟨-1/1000000,1/1000000⟩ + | 8 => ⟨-1/1000000,1/1000000⟩ + | 9 => ⟨0,1/1000000⟩ + | 10 => ⟨3/1000000,1/200000⟩ + | 11 => ⟨29/1000000,31/1000000⟩ + | 12 => ⟨1/6250,33/200000⟩ + | 13 => ⟨151/250000,613/1000000⟩ + | 14 => ⟨293/200000,739/500000⟩ + | 15 => ⟨1977/1000000,401/200000⟩ + | 16 => ⟨197/200000,101/100000⟩ + | 17 => ⟨257/1000000,3/10000⟩ + | 18 => ⟨3073/1000000,3101/1000000⟩ + | 19 => ⟨5351/1000000,1351/250000⟩ + | 20 => ⟨7/3125,571/250000⟩ + | 21 => ⟨551/1000000,319/500000⟩ + | 22 => ⟨4907/1000000,2497/500000⟩ + | 23 => ⟨2067/250000,8393/1000000⟩ + | 24 => ⟨1317/200000,833/125000⟩ + | 25 => ⟨79/25000,3209/1000000⟩ + | 26 => ⟨1011/1000000,1037/1000000⟩ + | 27 => ⟨57/250000,119/500000⟩ + | 28 => ⟨37/1000000,1/25000⟩ + | 29 => ⟨1/250000,3/500000⟩ + | 30 => ⟨0,1/1000000⟩ + | 31 => ⟨-1/1000000,1/1000000⟩ + | 32 => ⟨-1/1000000,1/1000000⟩ + | 33 => ⟨-1/1000000,1/1000000⟩ + | 34 => ⟨-1/1000000,1/1000000⟩ + | 35 => ⟨-1/1000000,1/1000000⟩ + | 36 => ⟨-1/1000000,1/1000000⟩ + | 37 => ⟨-1/1000000,1/1000000⟩ + | 38 => ⟨-1/1000000,1/1000000⟩ + | 39 => ⟨-1/1000000,1/1000000⟩ + | _ => Box.rat 0 + +lemma check_0 : expression.check (-10+(0:ℚ)*(5*(1/10))) (1/10) 5 (blocks 0) = true := by decide +kernel +lemma check_1 : expression.check (-10+(1:ℚ)*(5*(1/10))) (1/10) 5 (blocks 1) = true := by decide +kernel +lemma check_2 : expression.check (-10+(2:ℚ)*(5*(1/10))) (1/10) 5 (blocks 2) = true := by decide +kernel +lemma check_3 : expression.check (-10+(3:ℚ)*(5*(1/10))) (1/10) 5 (blocks 3) = true := by decide +kernel +lemma check_4 : expression.check (-10+(4:ℚ)*(5*(1/10))) (1/10) 5 (blocks 4) = true := by decide +kernel +lemma check_5 : expression.check (-10+(5:ℚ)*(5*(1/10))) (1/10) 5 (blocks 5) = true := by decide +kernel +lemma check_6 : expression.check (-10+(6:ℚ)*(5*(1/10))) (1/10) 5 (blocks 6) = true := by decide +kernel +lemma check_7 : expression.check (-10+(7:ℚ)*(5*(1/10))) (1/10) 5 (blocks 7) = true := by decide +kernel +lemma check_8 : expression.check (-10+(8:ℚ)*(5*(1/10))) (1/10) 5 (blocks 8) = true := by decide +kernel +lemma check_9 : expression.check (-10+(9:ℚ)*(5*(1/10))) (1/10) 5 (blocks 9) = true := by decide +kernel +lemma check_10 : expression.check (-10+(10:ℚ)*(5*(1/10))) (1/10) 5 (blocks 10) = true := by decide +kernel +lemma check_11 : expression.check (-10+(11:ℚ)*(5*(1/10))) (1/10) 5 (blocks 11) = true := by decide +kernel +lemma check_12 : expression.check (-10+(12:ℚ)*(5*(1/10))) (1/10) 5 (blocks 12) = true := by decide +kernel +lemma check_13 : expression.check (-10+(13:ℚ)*(5*(1/10))) (1/10) 5 (blocks 13) = true := by decide +kernel +lemma check_14 : expression.check (-10+(14:ℚ)*(5*(1/10))) (1/10) 5 (blocks 14) = true := by decide +kernel +lemma check_15 : expression.check (-10+(15:ℚ)*(5*(1/10))) (1/10) 5 (blocks 15) = true := by decide +kernel +lemma check_16 : expression.check (-10+(16:ℚ)*(5*(1/10))) (1/10) 5 (blocks 16) = true := by decide +kernel +lemma check_17 : expression.check (-10+(17:ℚ)*(5*(1/10))) (1/10) 5 (blocks 17) = true := by decide +kernel +lemma check_18 : expression.check (-10+(18:ℚ)*(5*(1/10))) (1/10) 5 (blocks 18) = true := by decide +kernel +lemma check_19 : expression.check (-10+(19:ℚ)*(5*(1/10))) (1/10) 5 (blocks 19) = true := by decide +kernel +lemma check_20 : expression.check (-10+(20:ℚ)*(5*(1/10))) (1/10) 5 (blocks 20) = true := by decide +kernel +lemma check_21 : expression.check (-10+(21:ℚ)*(5*(1/10))) (1/10) 5 (blocks 21) = true := by decide +kernel +lemma check_22 : expression.check (-10+(22:ℚ)*(5*(1/10))) (1/10) 5 (blocks 22) = true := by decide +kernel +lemma check_23 : expression.check (-10+(23:ℚ)*(5*(1/10))) (1/10) 5 (blocks 23) = true := by decide +kernel +lemma check_24 : expression.check (-10+(24:ℚ)*(5*(1/10))) (1/10) 5 (blocks 24) = true := by decide +kernel +lemma check_25 : expression.check (-10+(25:ℚ)*(5*(1/10))) (1/10) 5 (blocks 25) = true := by decide +kernel +lemma check_26 : expression.check (-10+(26:ℚ)*(5*(1/10))) (1/10) 5 (blocks 26) = true := by decide +kernel +lemma check_27 : expression.check (-10+(27:ℚ)*(5*(1/10))) (1/10) 5 (blocks 27) = true := by decide +kernel +lemma check_28 : expression.check (-10+(28:ℚ)*(5*(1/10))) (1/10) 5 (blocks 28) = true := by decide +kernel +lemma check_29 : expression.check (-10+(29:ℚ)*(5*(1/10))) (1/10) 5 (blocks 29) = true := by decide +kernel +lemma check_30 : expression.check (-10+(30:ℚ)*(5*(1/10))) (1/10) 5 (blocks 30) = true := by decide +kernel +lemma check_31 : expression.check (-10+(31:ℚ)*(5*(1/10))) (1/10) 5 (blocks 31) = true := by decide +kernel +lemma check_32 : expression.check (-10+(32:ℚ)*(5*(1/10))) (1/10) 5 (blocks 32) = true := by decide +kernel +lemma check_33 : expression.check (-10+(33:ℚ)*(5*(1/10))) (1/10) 5 (blocks 33) = true := by decide +kernel +lemma check_34 : expression.check (-10+(34:ℚ)*(5*(1/10))) (1/10) 5 (blocks 34) = true := by decide +kernel +lemma check_35 : expression.check (-10+(35:ℚ)*(5*(1/10))) (1/10) 5 (blocks 35) = true := by decide +kernel +lemma check_36 : expression.check (-10+(36:ℚ)*(5*(1/10))) (1/10) 5 (blocks 36) = true := by decide +kernel +lemma check_37 : expression.check (-10+(37:ℚ)*(5*(1/10))) (1/10) 5 (blocks 37) = true := by decide +kernel +lemma check_38 : expression.check (-10+(38:ℚ)*(5*(1/10))) (1/10) 5 (blocks 38) = true := by decide +kernel +lemma check_39 : expression.check (-10+(39:ℚ)*(5*(1/10))) (1/10) 5 (blocks 39) = true := by decide +kernel + +lemma checks (i : ℕ) (hi : i < 40) : + expression.check (-10+(i:ℚ)*(5*(1/10))) (1/10) 5 (blocks i) = true := by + interval_cases i + · exact check_0 + · exact check_1 + · exact check_2 + · exact check_3 + · exact check_4 + · exact check_5 + · exact check_6 + · exact check_7 + · exact check_8 + · exact check_9 + · exact check_10 + · exact check_11 + · exact check_12 + · exact check_13 + · exact check_14 + · exact check_15 + · exact check_16 + · exact check_17 + · exact check_18 + · exact check_19 + · exact check_20 + · exact check_21 + · exact check_22 + · exact check_23 + · exact check_24 + · exact check_25 + · exact check_26 + · exact check_27 + · exact check_28 + · exact check_29 + · exact check_30 + · exact check_31 + · exact check_32 + · exact check_33 + · exact check_34 + · exact check_35 + · exact check_36 + · exact check_37 + · exact check_38 + · exact check_39 + +theorem integral_bound : + (∫ h, scalarFunction (7/20) (44507/50000) (110763/200000) (20333/250000) (14573/25000) 4 h ∂Scalar.fieldLaw (7/20)) ∈ (⟨0,169/10000⟩ : Box) := by + apply gaussian_certificate (e := expression) (B := blocks) (h := (1/10)) (k := 5) (by norm_num) + · simpa only [expression,Rat.cast_div,Rat.cast_ofNat,Rat.cast_one,Rat.cast_zero] using integrandExpr_val (7/20) (44507/50000) (110763/200000) (20333/250000) (14573/25000) 4 + · exact (continuous_scalarFunction _ _ _ _ _ _).measurable + · intro x + apply scalarFunction_bound <;> norm_num + · exact checks + · decide +kernel + +end SKRatio.Certificate.Data.J0K4 + +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Certificates/ScalarDataJ0K5.lean b/lean/OAI/Probability/SKRatio/Certificates/ScalarDataJ0K5.lean new file mode 100644 index 0000000000000000000000000000000000000000..fb7efd32b4af7d400a3868c8adb4950e83166d7e --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Certificates/ScalarDataJ0K5.lean @@ -0,0 +1,154 @@ +import Mathlib +import OAI.Probability.SKRatio.Certificates.CertifiedBatches +import OAI.Probability.SKRatio.Certificates.CertifiedFunctionBounds + +namespace OAI + +noncomputable section +open Real MeasureTheory +namespace SKRatio.Certificate.Data.J0K5 + +def expression : Expr := integrandExpr (7/20) (44507/50000) (110763/200000) (20333/250000) (14573/25000) 5 +def blocks : ℕ → Box + | 0 => ⟨-1/1000000,1/1000000⟩ + | 1 => ⟨-1/1000000,1/1000000⟩ + | 2 => ⟨-1/1000000,1/1000000⟩ + | 3 => ⟨-1/1000000,1/1000000⟩ + | 4 => ⟨-1/1000000,1/1000000⟩ + | 5 => ⟨-1/1000000,1/1000000⟩ + | 6 => ⟨-1/1000000,1/1000000⟩ + | 7 => ⟨-1/1000000,1/1000000⟩ + | 8 => ⟨-1/1000000,1/1000000⟩ + | 9 => ⟨-1/1000000,1/1000000⟩ + | 10 => ⟨1/1000000,3/1000000⟩ + | 11 => ⟨7/500000,1/62500⟩ + | 12 => ⟨91/1000000,19/200000⟩ + | 13 => ⟨103/250000,419/1000000⟩ + | 14 => ⟨33/25000,333/250000⟩ + | 15 => ⟨2877/1000000,723/250000⟩ + | 16 => ⟨491/125000,99/25000⟩ + | 17 => ⟨703/250000,2837/1000000⟩ + | 18 => ⟨113/200000,593/1000000⟩ + | 19 => ⟨3/6250,251/500000⟩ + | 20 => ⟨101/50000,41/20000⟩ + | 21 => ⟨1867/1000000,19/10000⟩ + | 22 => ⟨59/125000,261/500000⟩ + | 23 => ⟨27/1000000,73/1000000⟩ + | 24 => ⟨27/100000,19/62500⟩ + | 25 => ⟨19/62500,163/500000⟩ + | 26 => ⟨77/500000,41/250000⟩ + | 27 => ⟨23/500000,1/20000⟩ + | 28 => ⟨9/1000000,11/1000000⟩ + | 29 => ⟨1/1000000,1/500000⟩ + | 30 => ⟨-1/1000000,1/1000000⟩ + | 31 => ⟨-1/1000000,1/1000000⟩ + | 32 => ⟨-1/1000000,1/1000000⟩ + | 33 => ⟨-1/1000000,1/1000000⟩ + | 34 => ⟨-1/1000000,1/1000000⟩ + | 35 => ⟨-1/1000000,1/1000000⟩ + | 36 => ⟨-1/1000000,1/1000000⟩ + | 37 => ⟨-1/1000000,1/1000000⟩ + | 38 => ⟨-1/1000000,1/1000000⟩ + | 39 => ⟨-1/1000000,1/1000000⟩ + | _ => Box.rat 0 + +lemma check_0 : expression.check (-10+(0:ℚ)*(5*(1/10))) (1/10) 5 (blocks 0) = true := by decide +kernel +lemma check_1 : expression.check (-10+(1:ℚ)*(5*(1/10))) (1/10) 5 (blocks 1) = true := by decide +kernel +lemma check_2 : expression.check (-10+(2:ℚ)*(5*(1/10))) (1/10) 5 (blocks 2) = true := by decide +kernel +lemma check_3 : expression.check (-10+(3:ℚ)*(5*(1/10))) (1/10) 5 (blocks 3) = true := by decide +kernel +lemma check_4 : expression.check (-10+(4:ℚ)*(5*(1/10))) (1/10) 5 (blocks 4) = true := by decide +kernel +lemma check_5 : expression.check (-10+(5:ℚ)*(5*(1/10))) (1/10) 5 (blocks 5) = true := by decide +kernel +lemma check_6 : expression.check (-10+(6:ℚ)*(5*(1/10))) (1/10) 5 (blocks 6) = true := by decide +kernel +lemma check_7 : expression.check (-10+(7:ℚ)*(5*(1/10))) (1/10) 5 (blocks 7) = true := by decide +kernel +lemma check_8 : expression.check (-10+(8:ℚ)*(5*(1/10))) (1/10) 5 (blocks 8) = true := by decide +kernel +lemma check_9 : expression.check (-10+(9:ℚ)*(5*(1/10))) (1/10) 5 (blocks 9) = true := by decide +kernel +lemma check_10 : expression.check (-10+(10:ℚ)*(5*(1/10))) (1/10) 5 (blocks 10) = true := by decide +kernel +lemma check_11 : expression.check (-10+(11:ℚ)*(5*(1/10))) (1/10) 5 (blocks 11) = true := by decide +kernel +lemma check_12 : expression.check (-10+(12:ℚ)*(5*(1/10))) (1/10) 5 (blocks 12) = true := by decide +kernel +lemma check_13 : expression.check (-10+(13:ℚ)*(5*(1/10))) (1/10) 5 (blocks 13) = true := by decide +kernel +lemma check_14 : expression.check (-10+(14:ℚ)*(5*(1/10))) (1/10) 5 (blocks 14) = true := by decide +kernel +lemma check_15 : expression.check (-10+(15:ℚ)*(5*(1/10))) (1/10) 5 (blocks 15) = true := by decide +kernel +lemma check_16 : expression.check (-10+(16:ℚ)*(5*(1/10))) (1/10) 5 (blocks 16) = true := by decide +kernel +lemma check_17 : expression.check (-10+(17:ℚ)*(5*(1/10))) (1/10) 5 (blocks 17) = true := by decide +kernel +lemma check_18 : expression.check (-10+(18:ℚ)*(5*(1/10))) (1/10) 5 (blocks 18) = true := by decide +kernel +lemma check_19 : expression.check (-10+(19:ℚ)*(5*(1/10))) (1/10) 5 (blocks 19) = true := by decide +kernel +lemma check_20 : expression.check (-10+(20:ℚ)*(5*(1/10))) (1/10) 5 (blocks 20) = true := by decide +kernel +lemma check_21 : expression.check (-10+(21:ℚ)*(5*(1/10))) (1/10) 5 (blocks 21) = true := by decide +kernel +lemma check_22 : expression.check (-10+(22:ℚ)*(5*(1/10))) (1/10) 5 (blocks 22) = true := by decide +kernel +lemma check_23 : expression.check (-10+(23:ℚ)*(5*(1/10))) (1/10) 5 (blocks 23) = true := by decide +kernel +lemma check_24 : expression.check (-10+(24:ℚ)*(5*(1/10))) (1/10) 5 (blocks 24) = true := by decide +kernel +lemma check_25 : expression.check (-10+(25:ℚ)*(5*(1/10))) (1/10) 5 (blocks 25) = true := by decide +kernel +lemma check_26 : expression.check (-10+(26:ℚ)*(5*(1/10))) (1/10) 5 (blocks 26) = true := by decide +kernel +lemma check_27 : expression.check (-10+(27:ℚ)*(5*(1/10))) (1/10) 5 (blocks 27) = true := by decide +kernel +lemma check_28 : expression.check (-10+(28:ℚ)*(5*(1/10))) (1/10) 5 (blocks 28) = true := by decide +kernel +lemma check_29 : expression.check (-10+(29:ℚ)*(5*(1/10))) (1/10) 5 (blocks 29) = true := by decide +kernel +lemma check_30 : expression.check (-10+(30:ℚ)*(5*(1/10))) (1/10) 5 (blocks 30) = true := by decide +kernel +lemma check_31 : expression.check (-10+(31:ℚ)*(5*(1/10))) (1/10) 5 (blocks 31) = true := by decide +kernel +lemma check_32 : expression.check (-10+(32:ℚ)*(5*(1/10))) (1/10) 5 (blocks 32) = true := by decide +kernel +lemma check_33 : expression.check (-10+(33:ℚ)*(5*(1/10))) (1/10) 5 (blocks 33) = true := by decide +kernel +lemma check_34 : expression.check (-10+(34:ℚ)*(5*(1/10))) (1/10) 5 (blocks 34) = true := by decide +kernel +lemma check_35 : expression.check (-10+(35:ℚ)*(5*(1/10))) (1/10) 5 (blocks 35) = true := by decide +kernel +lemma check_36 : expression.check (-10+(36:ℚ)*(5*(1/10))) (1/10) 5 (blocks 36) = true := by decide +kernel +lemma check_37 : expression.check (-10+(37:ℚ)*(5*(1/10))) (1/10) 5 (blocks 37) = true := by decide +kernel +lemma check_38 : expression.check (-10+(38:ℚ)*(5*(1/10))) (1/10) 5 (blocks 38) = true := by decide +kernel +lemma check_39 : expression.check (-10+(39:ℚ)*(5*(1/10))) (1/10) 5 (blocks 39) = true := by decide +kernel + +lemma checks (i : ℕ) (hi : i < 40) : + expression.check (-10+(i:ℚ)*(5*(1/10))) (1/10) 5 (blocks i) = true := by + interval_cases i + · exact check_0 + · exact check_1 + · exact check_2 + · exact check_3 + · exact check_4 + · exact check_5 + · exact check_6 + · exact check_7 + · exact check_8 + · exact check_9 + · exact check_10 + · exact check_11 + · exact check_12 + · exact check_13 + · exact check_14 + · exact check_15 + · exact check_16 + · exact check_17 + · exact check_18 + · exact check_19 + · exact check_20 + · exact check_21 + · exact check_22 + · exact check_23 + · exact check_24 + · exact check_25 + · exact check_26 + · exact check_27 + · exact check_28 + · exact check_29 + · exact check_30 + · exact check_31 + · exact check_32 + · exact check_33 + · exact check_34 + · exact check_35 + · exact check_36 + · exact check_37 + · exact check_38 + · exact check_39 + +theorem integral_bound : + (∫ h, scalarFunction (7/20) (44507/50000) (110763/200000) (20333/250000) (14573/25000) 5 h ∂Scalar.fieldLaw (7/20)) ∈ (⟨0,1849/250000⟩ : Box) := by + apply gaussian_certificate (e := expression) (B := blocks) (h := (1/10)) (k := 5) (by norm_num) + · simpa only [expression,Rat.cast_div,Rat.cast_ofNat,Rat.cast_one,Rat.cast_zero] using integrandExpr_val (7/20) (44507/50000) (110763/200000) (20333/250000) (14573/25000) 5 + · exact (continuous_scalarFunction _ _ _ _ _ _).measurable + · intro x + apply scalarFunction_bound <;> norm_num + · exact checks + · decide +kernel + +end SKRatio.Certificate.Data.J0K5 + +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Certificates/ScalarDataJ0K6.lean b/lean/OAI/Probability/SKRatio/Certificates/ScalarDataJ0K6.lean new file mode 100644 index 0000000000000000000000000000000000000000..24735e229c114d9ee81c55131355cb761e563e74 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Certificates/ScalarDataJ0K6.lean @@ -0,0 +1,154 @@ +import Mathlib +import OAI.Probability.SKRatio.Certificates.CertifiedBatches +import OAI.Probability.SKRatio.Certificates.CertifiedFunctionBounds + +namespace OAI + +noncomputable section +open Real MeasureTheory +namespace SKRatio.Certificate.Data.J0K6 + +def expression : Expr := integrandExpr (7/20) (44507/50000) (110763/200000) (20333/250000) (14573/25000) 6 +def blocks : ℕ → Box + | 0 => ⟨-1/1000000,1/1000000⟩ + | 1 => ⟨-1/1000000,1/1000000⟩ + | 2 => ⟨-1/1000000,1/1000000⟩ + | 3 => ⟨-1/1000000,1/1000000⟩ + | 4 => ⟨-1/1000000,1/1000000⟩ + | 5 => ⟨-1/1000000,1/1000000⟩ + | 6 => ⟨-1/1000000,1/1000000⟩ + | 7 => ⟨-1/1000000,1/1000000⟩ + | 8 => ⟨-1/1000000,1/1000000⟩ + | 9 => ⟨-1/1000000,1/1000000⟩ + | 10 => ⟨0,1/1000000⟩ + | 11 => ⟨1/200000,7/1000000⟩ + | 12 => ⟨3/50000,1/15625⟩ + | 13 => ⟨227/500000,467/1000000⟩ + | 14 => ⟨609/250000,1239/500000⟩ + | 15 => ⟨4463/500000,2249/250000⟩ + | 16 => ⟨5229/250000,20997/1000000⟩ + | 17 => ⟨14113/500000,28427/1000000⟩ + | 18 => ⟨3503/200000,17633/1000000⟩ + | 19 => ⟨2147/1000000,583/250000⟩ + | 20 => ⟨3491/500000,111/15625⟩ + | 21 => ⟨629/31250,10167/500000⟩ + | 22 => ⟨19501/1000000,19649/1000000⟩ + | 23 => ⟨9837/1000000,9943/1000000⟩ + | 24 => ⟨2963/1000000,381/125000⟩ + | 25 => ⟨567/1000000,601/1000000⟩ + | 26 => ⟨69/1000000,79/1000000⟩ + | 27 => ⟨1/200000,7/1000000⟩ + | 28 => ⟨0,1/1000000⟩ + | 29 => ⟨-1/1000000,1/1000000⟩ + | 30 => ⟨-1/1000000,1/1000000⟩ + | 31 => ⟨-1/1000000,1/1000000⟩ + | 32 => ⟨-1/1000000,1/1000000⟩ + | 33 => ⟨-1/1000000,1/1000000⟩ + | 34 => ⟨-1/1000000,1/1000000⟩ + | 35 => ⟨-1/1000000,1/1000000⟩ + | 36 => ⟨-1/1000000,1/1000000⟩ + | 37 => ⟨-1/1000000,1/1000000⟩ + | 38 => ⟨-1/1000000,1/1000000⟩ + | 39 => ⟨-1/1000000,1/1000000⟩ + | _ => Box.rat 0 + +lemma check_0 : expression.check (-10+(0:ℚ)*(5*(1/10))) (1/10) 5 (blocks 0) = true := by decide +kernel +lemma check_1 : expression.check (-10+(1:ℚ)*(5*(1/10))) (1/10) 5 (blocks 1) = true := by decide +kernel +lemma check_2 : expression.check (-10+(2:ℚ)*(5*(1/10))) (1/10) 5 (blocks 2) = true := by decide +kernel +lemma check_3 : expression.check (-10+(3:ℚ)*(5*(1/10))) (1/10) 5 (blocks 3) = true := by decide +kernel +lemma check_4 : expression.check (-10+(4:ℚ)*(5*(1/10))) (1/10) 5 (blocks 4) = true := by decide +kernel +lemma check_5 : expression.check (-10+(5:ℚ)*(5*(1/10))) (1/10) 5 (blocks 5) = true := by decide +kernel +lemma check_6 : expression.check (-10+(6:ℚ)*(5*(1/10))) (1/10) 5 (blocks 6) = true := by decide +kernel +lemma check_7 : expression.check (-10+(7:ℚ)*(5*(1/10))) (1/10) 5 (blocks 7) = true := by decide +kernel +lemma check_8 : expression.check (-10+(8:ℚ)*(5*(1/10))) (1/10) 5 (blocks 8) = true := by decide +kernel +lemma check_9 : expression.check (-10+(9:ℚ)*(5*(1/10))) (1/10) 5 (blocks 9) = true := by decide +kernel +lemma check_10 : expression.check (-10+(10:ℚ)*(5*(1/10))) (1/10) 5 (blocks 10) = true := by decide +kernel +lemma check_11 : expression.check (-10+(11:ℚ)*(5*(1/10))) (1/10) 5 (blocks 11) = true := by decide +kernel +lemma check_12 : expression.check (-10+(12:ℚ)*(5*(1/10))) (1/10) 5 (blocks 12) = true := by decide +kernel +lemma check_13 : expression.check (-10+(13:ℚ)*(5*(1/10))) (1/10) 5 (blocks 13) = true := by decide +kernel +lemma check_14 : expression.check (-10+(14:ℚ)*(5*(1/10))) (1/10) 5 (blocks 14) = true := by decide +kernel +lemma check_15 : expression.check (-10+(15:ℚ)*(5*(1/10))) (1/10) 5 (blocks 15) = true := by decide +kernel +lemma check_16 : expression.check (-10+(16:ℚ)*(5*(1/10))) (1/10) 5 (blocks 16) = true := by decide +kernel +lemma check_17 : expression.check (-10+(17:ℚ)*(5*(1/10))) (1/10) 5 (blocks 17) = true := by decide +kernel +lemma check_18 : expression.check (-10+(18:ℚ)*(5*(1/10))) (1/10) 5 (blocks 18) = true := by decide +kernel +lemma check_19 : expression.check (-10+(19:ℚ)*(5*(1/10))) (1/10) 5 (blocks 19) = true := by decide +kernel +lemma check_20 : expression.check (-10+(20:ℚ)*(5*(1/10))) (1/10) 5 (blocks 20) = true := by decide +kernel +lemma check_21 : expression.check (-10+(21:ℚ)*(5*(1/10))) (1/10) 5 (blocks 21) = true := by decide +kernel +lemma check_22 : expression.check (-10+(22:ℚ)*(5*(1/10))) (1/10) 5 (blocks 22) = true := by decide +kernel +lemma check_23 : expression.check (-10+(23:ℚ)*(5*(1/10))) (1/10) 5 (blocks 23) = true := by decide +kernel +lemma check_24 : expression.check (-10+(24:ℚ)*(5*(1/10))) (1/10) 5 (blocks 24) = true := by decide +kernel +lemma check_25 : expression.check (-10+(25:ℚ)*(5*(1/10))) (1/10) 5 (blocks 25) = true := by decide +kernel +lemma check_26 : expression.check (-10+(26:ℚ)*(5*(1/10))) (1/10) 5 (blocks 26) = true := by decide +kernel +lemma check_27 : expression.check (-10+(27:ℚ)*(5*(1/10))) (1/10) 5 (blocks 27) = true := by decide +kernel +lemma check_28 : expression.check (-10+(28:ℚ)*(5*(1/10))) (1/10) 5 (blocks 28) = true := by decide +kernel +lemma check_29 : expression.check (-10+(29:ℚ)*(5*(1/10))) (1/10) 5 (blocks 29) = true := by decide +kernel +lemma check_30 : expression.check (-10+(30:ℚ)*(5*(1/10))) (1/10) 5 (blocks 30) = true := by decide +kernel +lemma check_31 : expression.check (-10+(31:ℚ)*(5*(1/10))) (1/10) 5 (blocks 31) = true := by decide +kernel +lemma check_32 : expression.check (-10+(32:ℚ)*(5*(1/10))) (1/10) 5 (blocks 32) = true := by decide +kernel +lemma check_33 : expression.check (-10+(33:ℚ)*(5*(1/10))) (1/10) 5 (blocks 33) = true := by decide +kernel +lemma check_34 : expression.check (-10+(34:ℚ)*(5*(1/10))) (1/10) 5 (blocks 34) = true := by decide +kernel +lemma check_35 : expression.check (-10+(35:ℚ)*(5*(1/10))) (1/10) 5 (blocks 35) = true := by decide +kernel +lemma check_36 : expression.check (-10+(36:ℚ)*(5*(1/10))) (1/10) 5 (blocks 36) = true := by decide +kernel +lemma check_37 : expression.check (-10+(37:ℚ)*(5*(1/10))) (1/10) 5 (blocks 37) = true := by decide +kernel +lemma check_38 : expression.check (-10+(38:ℚ)*(5*(1/10))) (1/10) 5 (blocks 38) = true := by decide +kernel +lemma check_39 : expression.check (-10+(39:ℚ)*(5*(1/10))) (1/10) 5 (blocks 39) = true := by decide +kernel + +lemma checks (i : ℕ) (hi : i < 40) : + expression.check (-10+(i:ℚ)*(5*(1/10))) (1/10) 5 (blocks i) = true := by + interval_cases i + · exact check_0 + · exact check_1 + · exact check_2 + · exact check_3 + · exact check_4 + · exact check_5 + · exact check_6 + · exact check_7 + · exact check_8 + · exact check_9 + · exact check_10 + · exact check_11 + · exact check_12 + · exact check_13 + · exact check_14 + · exact check_15 + · exact check_16 + · exact check_17 + · exact check_18 + · exact check_19 + · exact check_20 + · exact check_21 + · exact check_22 + · exact check_23 + · exact check_24 + · exact check_25 + · exact check_26 + · exact check_27 + · exact check_28 + · exact check_29 + · exact check_30 + · exact check_31 + · exact check_32 + · exact check_33 + · exact check_34 + · exact check_35 + · exact check_36 + · exact check_37 + · exact check_38 + · exact check_39 + +theorem integral_bound : + (∫ h, scalarFunction (7/20) (44507/50000) (110763/200000) (20333/250000) (14573/25000) 6 h ∂Scalar.fieldLaw (7/20)) ∈ (⟨0,57121/1000000⟩ : Box) := by + apply gaussian_certificate (e := expression) (B := blocks) (h := (1/10)) (k := 5) (by norm_num) + · simpa only [expression,Rat.cast_div,Rat.cast_ofNat,Rat.cast_one,Rat.cast_zero] using integrandExpr_val (7/20) (44507/50000) (110763/200000) (20333/250000) (14573/25000) 6 + · exact (continuous_scalarFunction _ _ _ _ _ _).measurable + · intro x + apply scalarFunction_bound <;> norm_num + · exact checks + · decide +kernel + +end SKRatio.Certificate.Data.J0K6 + +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Certificates/ScalarDataJ0K7.lean b/lean/OAI/Probability/SKRatio/Certificates/ScalarDataJ0K7.lean new file mode 100644 index 0000000000000000000000000000000000000000..25ba8e1e18cb672d71c38779806670c50ba4003d --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Certificates/ScalarDataJ0K7.lean @@ -0,0 +1,154 @@ +import Mathlib +import OAI.Probability.SKRatio.Certificates.CertifiedBatches +import OAI.Probability.SKRatio.Certificates.CertifiedFunctionBounds + +namespace OAI + +noncomputable section +open Real MeasureTheory +namespace SKRatio.Certificate.Data.J0K7 + +def expression : Expr := integrandExpr (7/20) (44507/50000) (110763/200000) (20333/250000) (14573/25000) 7 +def blocks : ℕ → Box + | 0 => ⟨-1/1000000,1/1000000⟩ + | 1 => ⟨-1/1000000,1/1000000⟩ + | 2 => ⟨-1/1000000,1/1000000⟩ + | 3 => ⟨-1/1000000,1/1000000⟩ + | 4 => ⟨-1/1000000,1/1000000⟩ + | 5 => ⟨-1/1000000,1/1000000⟩ + | 6 => ⟨-1/1000000,1/1000000⟩ + | 7 => ⟨-1/1000000,1/1000000⟩ + | 8 => ⟨0,1/1000000⟩ + | 9 => ⟨3/1000000,1/200000⟩ + | 10 => ⟨1/25000,43/1000000⟩ + | 11 => ⟨331/1000000,343/1000000⟩ + | 12 => ⟨2103/1000000,539/250000⟩ + | 13 => ⟨159/15625,10349/1000000⟩ + | 14 => ⟨36733/1000000,18551/500000⟩ + | 15 => ⟨95661/1000000,9607/100000⟩ + | 16 => ⟨169931/1000000,85339/500000⟩ + | 17 => ⟨187633/1000000,18879/100000⟩ + | 18 => ⟨103601/1000000,104181/1000000⟩ + | 19 => ⟨2517/200000,13583/1000000⟩ + | 20 => ⟨2251/62500,36649/1000000⟩ + | 21 => ⟨15061/125000,1517/12500⟩ + | 22 => ⟨144411/1000000,29073/200000⟩ + | 23 => ⟨99259/1000000,4989/50000⟩ + | 24 => ⟨45617/1000000,23043/500000⟩ + | 25 => ⟨15183/1000000,7737/500000⟩ + | 26 => ⟨767/200000,247/62500⟩ + | 27 => ⟨377/500000,197/250000⟩ + | 28 => ⟨117/1000000,1/8000⟩ + | 29 => ⟨7/500000,1/62500⟩ + | 30 => ⟨1/1000000,1/500000⟩ + | 31 => ⟨-1/1000000,1/1000000⟩ + | 32 => ⟨-1/1000000,1/1000000⟩ + | 33 => ⟨-1/1000000,1/1000000⟩ + | 34 => ⟨-1/1000000,1/1000000⟩ + | 35 => ⟨-1/1000000,1/1000000⟩ + | 36 => ⟨-1/1000000,1/1000000⟩ + | 37 => ⟨-1/1000000,1/1000000⟩ + | 38 => ⟨-1/1000000,1/1000000⟩ + | 39 => ⟨-1/1000000,1/1000000⟩ + | _ => Box.rat 0 + +lemma check_0 : expression.check (-10+(0:ℚ)*(5*(1/10))) (1/10) 5 (blocks 0) = true := by decide +kernel +lemma check_1 : expression.check (-10+(1:ℚ)*(5*(1/10))) (1/10) 5 (blocks 1) = true := by decide +kernel +lemma check_2 : expression.check (-10+(2:ℚ)*(5*(1/10))) (1/10) 5 (blocks 2) = true := by decide +kernel +lemma check_3 : expression.check (-10+(3:ℚ)*(5*(1/10))) (1/10) 5 (blocks 3) = true := by decide +kernel +lemma check_4 : expression.check (-10+(4:ℚ)*(5*(1/10))) (1/10) 5 (blocks 4) = true := by decide +kernel +lemma check_5 : expression.check (-10+(5:ℚ)*(5*(1/10))) (1/10) 5 (blocks 5) = true := by decide +kernel +lemma check_6 : expression.check (-10+(6:ℚ)*(5*(1/10))) (1/10) 5 (blocks 6) = true := by decide +kernel +lemma check_7 : expression.check (-10+(7:ℚ)*(5*(1/10))) (1/10) 5 (blocks 7) = true := by decide +kernel +lemma check_8 : expression.check (-10+(8:ℚ)*(5*(1/10))) (1/10) 5 (blocks 8) = true := by decide +kernel +lemma check_9 : expression.check (-10+(9:ℚ)*(5*(1/10))) (1/10) 5 (blocks 9) = true := by decide +kernel +lemma check_10 : expression.check (-10+(10:ℚ)*(5*(1/10))) (1/10) 5 (blocks 10) = true := by decide +kernel +lemma check_11 : expression.check (-10+(11:ℚ)*(5*(1/10))) (1/10) 5 (blocks 11) = true := by decide +kernel +lemma check_12 : expression.check (-10+(12:ℚ)*(5*(1/10))) (1/10) 5 (blocks 12) = true := by decide +kernel +lemma check_13 : expression.check (-10+(13:ℚ)*(5*(1/10))) (1/10) 5 (blocks 13) = true := by decide +kernel +lemma check_14 : expression.check (-10+(14:ℚ)*(5*(1/10))) (1/10) 5 (blocks 14) = true := by decide +kernel +lemma check_15 : expression.check (-10+(15:ℚ)*(5*(1/10))) (1/10) 5 (blocks 15) = true := by decide +kernel +lemma check_16 : expression.check (-10+(16:ℚ)*(5*(1/10))) (1/10) 5 (blocks 16) = true := by decide +kernel +lemma check_17 : expression.check (-10+(17:ℚ)*(5*(1/10))) (1/10) 5 (blocks 17) = true := by decide +kernel +lemma check_18 : expression.check (-10+(18:ℚ)*(5*(1/10))) (1/10) 5 (blocks 18) = true := by decide +kernel +lemma check_19 : expression.check (-10+(19:ℚ)*(5*(1/10))) (1/10) 5 (blocks 19) = true := by decide +kernel +lemma check_20 : expression.check (-10+(20:ℚ)*(5*(1/10))) (1/10) 5 (blocks 20) = true := by decide +kernel +lemma check_21 : expression.check (-10+(21:ℚ)*(5*(1/10))) (1/10) 5 (blocks 21) = true := by decide +kernel +lemma check_22 : expression.check (-10+(22:ℚ)*(5*(1/10))) (1/10) 5 (blocks 22) = true := by decide +kernel +lemma check_23 : expression.check (-10+(23:ℚ)*(5*(1/10))) (1/10) 5 (blocks 23) = true := by decide +kernel +lemma check_24 : expression.check (-10+(24:ℚ)*(5*(1/10))) (1/10) 5 (blocks 24) = true := by decide +kernel +lemma check_25 : expression.check (-10+(25:ℚ)*(5*(1/10))) (1/10) 5 (blocks 25) = true := by decide +kernel +lemma check_26 : expression.check (-10+(26:ℚ)*(5*(1/10))) (1/10) 5 (blocks 26) = true := by decide +kernel +lemma check_27 : expression.check (-10+(27:ℚ)*(5*(1/10))) (1/10) 5 (blocks 27) = true := by decide +kernel +lemma check_28 : expression.check (-10+(28:ℚ)*(5*(1/10))) (1/10) 5 (blocks 28) = true := by decide +kernel +lemma check_29 : expression.check (-10+(29:ℚ)*(5*(1/10))) (1/10) 5 (blocks 29) = true := by decide +kernel +lemma check_30 : expression.check (-10+(30:ℚ)*(5*(1/10))) (1/10) 5 (blocks 30) = true := by decide +kernel +lemma check_31 : expression.check (-10+(31:ℚ)*(5*(1/10))) (1/10) 5 (blocks 31) = true := by decide +kernel +lemma check_32 : expression.check (-10+(32:ℚ)*(5*(1/10))) (1/10) 5 (blocks 32) = true := by decide +kernel +lemma check_33 : expression.check (-10+(33:ℚ)*(5*(1/10))) (1/10) 5 (blocks 33) = true := by decide +kernel +lemma check_34 : expression.check (-10+(34:ℚ)*(5*(1/10))) (1/10) 5 (blocks 34) = true := by decide +kernel +lemma check_35 : expression.check (-10+(35:ℚ)*(5*(1/10))) (1/10) 5 (blocks 35) = true := by decide +kernel +lemma check_36 : expression.check (-10+(36:ℚ)*(5*(1/10))) (1/10) 5 (blocks 36) = true := by decide +kernel +lemma check_37 : expression.check (-10+(37:ℚ)*(5*(1/10))) (1/10) 5 (blocks 37) = true := by decide +kernel +lemma check_38 : expression.check (-10+(38:ℚ)*(5*(1/10))) (1/10) 5 (blocks 38) = true := by decide +kernel +lemma check_39 : expression.check (-10+(39:ℚ)*(5*(1/10))) (1/10) 5 (blocks 39) = true := by decide +kernel + +lemma checks (i : ℕ) (hi : i < 40) : + expression.check (-10+(i:ℚ)*(5*(1/10))) (1/10) 5 (blocks i) = true := by + interval_cases i + · exact check_0 + · exact check_1 + · exact check_2 + · exact check_3 + · exact check_4 + · exact check_5 + · exact check_6 + · exact check_7 + · exact check_8 + · exact check_9 + · exact check_10 + · exact check_11 + · exact check_12 + · exact check_13 + · exact check_14 + · exact check_15 + · exact check_16 + · exact check_17 + · exact check_18 + · exact check_19 + · exact check_20 + · exact check_21 + · exact check_22 + · exact check_23 + · exact check_24 + · exact check_25 + · exact check_26 + · exact check_27 + · exact check_28 + · exact check_29 + · exact check_30 + · exact check_31 + · exact check_32 + · exact check_33 + · exact check_34 + · exact check_35 + · exact check_36 + · exact check_37 + · exact check_38 + · exact check_39 + +theorem integral_bound : + (∫ h, scalarFunction (7/20) (44507/50000) (110763/200000) (20333/250000) (14573/25000) 7 h ∂Scalar.fieldLaw (7/20)) ∈ (⟨0,436921/1000000⟩ : Box) := by + apply gaussian_certificate (e := expression) (B := blocks) (h := (1/10)) (k := 5) (by norm_num) + · simpa only [expression,Rat.cast_div,Rat.cast_ofNat,Rat.cast_one,Rat.cast_zero] using integrandExpr_val (7/20) (44507/50000) (110763/200000) (20333/250000) (14573/25000) 7 + · exact (continuous_scalarFunction _ _ _ _ _ _).measurable + · intro x + apply scalarFunction_bound <;> norm_num + · exact checks + · decide +kernel + +end SKRatio.Certificate.Data.J0K7 + +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Certificates/ScalarDataJ1K0.lean b/lean/OAI/Probability/SKRatio/Certificates/ScalarDataJ1K0.lean new file mode 100644 index 0000000000000000000000000000000000000000..eaef08a8ec7af1a683e96bee88c84aa0cfcb2f00 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Certificates/ScalarDataJ1K0.lean @@ -0,0 +1,154 @@ +import Mathlib +import OAI.Probability.SKRatio.Certificates.CertifiedBatches +import OAI.Probability.SKRatio.Certificates.CertifiedFunctionBounds + +namespace OAI + +noncomputable section +open Real MeasureTheory +namespace SKRatio.Certificate.Data.J1K0 + +def expression : Expr := integrandExpr (2/5) (107581/125000) (545767/1000000) (95751/1000000) (616697/1000000) 0 +def blocks : ℕ → Box + | 0 => ⟨-1/1000000,1/1000000⟩ + | 1 => ⟨-1/1000000,1/1000000⟩ + | 2 => ⟨-1/1000000,1/1000000⟩ + | 3 => ⟨-1/1000000,1/1000000⟩ + | 4 => ⟨-1/1000000,1/1000000⟩ + | 5 => ⟨-1/1000000,1/1000000⟩ + | 6 => ⟨-1/1000000,1/1000000⟩ + | 7 => ⟨-1/1000000,1/1000000⟩ + | 8 => ⟨-1/1000000,1/1000000⟩ + | 9 => ⟨-1/1000000,1/1000000⟩ + | 10 => ⟨0,1/500000⟩ + | 11 => ⟨3/250000,7/500000⟩ + | 12 => ⟨127/1000000,133/1000000⟩ + | 13 => ⟨983/1000000,1011/1000000⟩ + | 14 => ⟨5779/1000000,5893/1000000⟩ + | 15 => ⟨2561/100000,6481/250000⟩ + | 16 => ⟨84641/1000000,42591/500000⟩ + | 17 => ⟨20639/100000,41363/200000⟩ + | 18 => ⟨45939/125000,367957/1000000⟩ + | 19 => ⟨237757/500000,9531/20000⟩ + | 20 => ⟨223663/500000,112051/250000⟩ + | 21 => ⟨307183/1000000,30751/100000⟩ + | 22 => ⟨154943/1000000,155529/1000000⟩ + | 23 => ⟨58037/1000000,58573/1000000⟩ + | 24 => ⟨16321/1000000,16603/1000000⟩ + | 25 => ⟨3477/1000000,3579/1000000⟩ + | 26 => ⟨113/200000,37/62500⟩ + | 27 => ⟨7/100000,19/250000⟩ + | 28 => ⟨3/500000,1/125000⟩ + | 29 => ⟨0,1/1000000⟩ + | 30 => ⟨-1/1000000,1/1000000⟩ + | 31 => ⟨-1/1000000,1/1000000⟩ + | 32 => ⟨-1/1000000,1/1000000⟩ + | 33 => ⟨-1/1000000,1/1000000⟩ + | 34 => ⟨-1/1000000,1/1000000⟩ + | 35 => ⟨-1/1000000,1/1000000⟩ + | 36 => ⟨-1/1000000,1/1000000⟩ + | 37 => ⟨-1/1000000,1/1000000⟩ + | 38 => ⟨-1/1000000,1/1000000⟩ + | 39 => ⟨-1/1000000,1/1000000⟩ + | _ => Box.rat 0 + +lemma check_0 : expression.check (-10+(0:ℚ)*(5*(1/10))) (1/10) 5 (blocks 0) = true := by decide +kernel +lemma check_1 : expression.check (-10+(1:ℚ)*(5*(1/10))) (1/10) 5 (blocks 1) = true := by decide +kernel +lemma check_2 : expression.check (-10+(2:ℚ)*(5*(1/10))) (1/10) 5 (blocks 2) = true := by decide +kernel +lemma check_3 : expression.check (-10+(3:ℚ)*(5*(1/10))) (1/10) 5 (blocks 3) = true := by decide +kernel +lemma check_4 : expression.check (-10+(4:ℚ)*(5*(1/10))) (1/10) 5 (blocks 4) = true := by decide +kernel +lemma check_5 : expression.check (-10+(5:ℚ)*(5*(1/10))) (1/10) 5 (blocks 5) = true := by decide +kernel +lemma check_6 : expression.check (-10+(6:ℚ)*(5*(1/10))) (1/10) 5 (blocks 6) = true := by decide +kernel +lemma check_7 : expression.check (-10+(7:ℚ)*(5*(1/10))) (1/10) 5 (blocks 7) = true := by decide +kernel +lemma check_8 : expression.check (-10+(8:ℚ)*(5*(1/10))) (1/10) 5 (blocks 8) = true := by decide +kernel +lemma check_9 : expression.check (-10+(9:ℚ)*(5*(1/10))) (1/10) 5 (blocks 9) = true := by decide +kernel +lemma check_10 : expression.check (-10+(10:ℚ)*(5*(1/10))) (1/10) 5 (blocks 10) = true := by decide +kernel +lemma check_11 : expression.check (-10+(11:ℚ)*(5*(1/10))) (1/10) 5 (blocks 11) = true := by decide +kernel +lemma check_12 : expression.check (-10+(12:ℚ)*(5*(1/10))) (1/10) 5 (blocks 12) = true := by decide +kernel +lemma check_13 : expression.check (-10+(13:ℚ)*(5*(1/10))) (1/10) 5 (blocks 13) = true := by decide +kernel +lemma check_14 : expression.check (-10+(14:ℚ)*(5*(1/10))) (1/10) 5 (blocks 14) = true := by decide +kernel +lemma check_15 : expression.check (-10+(15:ℚ)*(5*(1/10))) (1/10) 5 (blocks 15) = true := by decide +kernel +lemma check_16 : expression.check (-10+(16:ℚ)*(5*(1/10))) (1/10) 5 (blocks 16) = true := by decide +kernel +lemma check_17 : expression.check (-10+(17:ℚ)*(5*(1/10))) (1/10) 5 (blocks 17) = true := by decide +kernel +lemma check_18 : expression.check (-10+(18:ℚ)*(5*(1/10))) (1/10) 5 (blocks 18) = true := by decide +kernel +lemma check_19 : expression.check (-10+(19:ℚ)*(5*(1/10))) (1/10) 5 (blocks 19) = true := by decide +kernel +lemma check_20 : expression.check (-10+(20:ℚ)*(5*(1/10))) (1/10) 5 (blocks 20) = true := by decide +kernel +lemma check_21 : expression.check (-10+(21:ℚ)*(5*(1/10))) (1/10) 5 (blocks 21) = true := by decide +kernel +lemma check_22 : expression.check (-10+(22:ℚ)*(5*(1/10))) (1/10) 5 (blocks 22) = true := by decide +kernel +lemma check_23 : expression.check (-10+(23:ℚ)*(5*(1/10))) (1/10) 5 (blocks 23) = true := by decide +kernel +lemma check_24 : expression.check (-10+(24:ℚ)*(5*(1/10))) (1/10) 5 (blocks 24) = true := by decide +kernel +lemma check_25 : expression.check (-10+(25:ℚ)*(5*(1/10))) (1/10) 5 (blocks 25) = true := by decide +kernel +lemma check_26 : expression.check (-10+(26:ℚ)*(5*(1/10))) (1/10) 5 (blocks 26) = true := by decide +kernel +lemma check_27 : expression.check (-10+(27:ℚ)*(5*(1/10))) (1/10) 5 (blocks 27) = true := by decide +kernel +lemma check_28 : expression.check (-10+(28:ℚ)*(5*(1/10))) (1/10) 5 (blocks 28) = true := by decide +kernel +lemma check_29 : expression.check (-10+(29:ℚ)*(5*(1/10))) (1/10) 5 (blocks 29) = true := by decide +kernel +lemma check_30 : expression.check (-10+(30:ℚ)*(5*(1/10))) (1/10) 5 (blocks 30) = true := by decide +kernel +lemma check_31 : expression.check (-10+(31:ℚ)*(5*(1/10))) (1/10) 5 (blocks 31) = true := by decide +kernel +lemma check_32 : expression.check (-10+(32:ℚ)*(5*(1/10))) (1/10) 5 (blocks 32) = true := by decide +kernel +lemma check_33 : expression.check (-10+(33:ℚ)*(5*(1/10))) (1/10) 5 (blocks 33) = true := by decide +kernel +lemma check_34 : expression.check (-10+(34:ℚ)*(5*(1/10))) (1/10) 5 (blocks 34) = true := by decide +kernel +lemma check_35 : expression.check (-10+(35:ℚ)*(5*(1/10))) (1/10) 5 (blocks 35) = true := by decide +kernel +lemma check_36 : expression.check (-10+(36:ℚ)*(5*(1/10))) (1/10) 5 (blocks 36) = true := by decide +kernel +lemma check_37 : expression.check (-10+(37:ℚ)*(5*(1/10))) (1/10) 5 (blocks 37) = true := by decide +kernel +lemma check_38 : expression.check (-10+(38:ℚ)*(5*(1/10))) (1/10) 5 (blocks 38) = true := by decide +kernel +lemma check_39 : expression.check (-10+(39:ℚ)*(5*(1/10))) (1/10) 5 (blocks 39) = true := by decide +kernel + +lemma checks (i : ℕ) (hi : i < 40) : + expression.check (-10+(i:ℚ)*(5*(1/10))) (1/10) 5 (blocks i) = true := by + interval_cases i + · exact check_0 + · exact check_1 + · exact check_2 + · exact check_3 + · exact check_4 + · exact check_5 + · exact check_6 + · exact check_7 + · exact check_8 + · exact check_9 + · exact check_10 + · exact check_11 + · exact check_12 + · exact check_13 + · exact check_14 + · exact check_15 + · exact check_16 + · exact check_17 + · exact check_18 + · exact check_19 + · exact check_20 + · exact check_21 + · exact check_22 + · exact check_23 + · exact check_24 + · exact check_25 + · exact check_26 + · exact check_27 + · exact check_28 + · exact check_29 + · exact check_30 + · exact check_31 + · exact check_32 + · exact check_33 + · exact check_34 + · exact check_35 + · exact check_36 + · exact check_37 + · exact check_38 + · exact check_39 + +theorem integral_bound : + (∫ h, scalarFunction (2/5) (107581/125000) (545767/1000000) (95751/1000000) (616697/1000000) 0 h ∂Scalar.fieldLaw (2/5)) ∈ (⟨214787/250000,215537/250000⟩ : Box) := by + apply gaussian_certificate (e := expression) (B := blocks) (h := (1/10)) (k := 5) (by norm_num) + · simpa only [expression,Rat.cast_div,Rat.cast_ofNat,Rat.cast_one,Rat.cast_zero] using integrandExpr_val (2/5) (107581/125000) (545767/1000000) (95751/1000000) (616697/1000000) 0 + · exact (continuous_scalarFunction _ _ _ _ _ _).measurable + · intro x + apply scalarFunction_bound <;> norm_num + · exact checks + · decide +kernel + +end SKRatio.Certificate.Data.J1K0 + +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Certificates/ScalarDataJ1K1.lean b/lean/OAI/Probability/SKRatio/Certificates/ScalarDataJ1K1.lean new file mode 100644 index 0000000000000000000000000000000000000000..63af84142d257e0a7fb48beedc97ddf32eea0a5a --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Certificates/ScalarDataJ1K1.lean @@ -0,0 +1,154 @@ +import Mathlib +import OAI.Probability.SKRatio.Certificates.CertifiedBatches +import OAI.Probability.SKRatio.Certificates.CertifiedFunctionBounds + +namespace OAI + +noncomputable section +open Real MeasureTheory +namespace SKRatio.Certificate.Data.J1K1 + +def expression : Expr := integrandExpr (2/5) (107581/125000) (545767/1000000) (95751/1000000) (616697/1000000) 1 +def blocks : ℕ → Box + | 0 => ⟨-1/1000000,1/1000000⟩ + | 1 => ⟨-1/1000000,1/1000000⟩ + | 2 => ⟨-1/1000000,1/1000000⟩ + | 3 => ⟨-1/1000000,1/1000000⟩ + | 4 => ⟨-1/1000000,1/1000000⟩ + | 5 => ⟨-1/1000000,1/1000000⟩ + | 6 => ⟨-1/1000000,1/1000000⟩ + | 7 => ⟨-1/1000000,1/1000000⟩ + | 8 => ⟨-1/1000000,1/1000000⟩ + | 9 => ⟨-1/1000000,1/1000000⟩ + | 10 => ⟨0,1/1000000⟩ + | 11 => ⟨1/250000,3/500000⟩ + | 12 => ⟨3/62500,51/1000000⟩ + | 13 => ⟨6/15625,397/1000000⟩ + | 14 => ⟨2337/1000000,2387/1000000⟩ + | 15 => ⟨677/62500,10979/1000000⟩ + | 16 => ⟨37989/1000000,19141/500000⟩ + | 17 => ⟨3999/40000,12537/125000⟩ + | 18 => ⟨195577/1000000,195763/1000000⟩ + | 19 => ⟨281997/1000000,282549/1000000⟩ + | 20 => ⟨149257/500000,74803/250000⟩ + | 21 => ⟨231371/1000000,46351/200000⟩ + | 22 => ⟨3279/25000,26313/200000⟩ + | 23 => ⟨2181/40000,55011/1000000⟩ + | 24 => ⟨16743/1000000,8521/500000⟩ + | 25 => ⟨3827/1000000,3947/1000000⟩ + | 26 => ⟨41/62500,691/1000000⟩ + | 27 => ⟨21/250000,93/1000000⟩ + | 28 => ⟨1/125000,1/100000⟩ + | 29 => ⟨0,1/1000000⟩ + | 30 => ⟨-1/1000000,1/1000000⟩ + | 31 => ⟨-1/1000000,1/1000000⟩ + | 32 => ⟨-1/1000000,1/1000000⟩ + | 33 => ⟨-1/1000000,1/1000000⟩ + | 34 => ⟨-1/1000000,1/1000000⟩ + | 35 => ⟨-1/1000000,1/1000000⟩ + | 36 => ⟨-1/1000000,1/1000000⟩ + | 37 => ⟨-1/1000000,1/1000000⟩ + | 38 => ⟨-1/1000000,1/1000000⟩ + | 39 => ⟨-1/1000000,1/1000000⟩ + | _ => Box.rat 0 + +lemma check_0 : expression.check (-10+(0:ℚ)*(5*(1/10))) (1/10) 5 (blocks 0) = true := by decide +kernel +lemma check_1 : expression.check (-10+(1:ℚ)*(5*(1/10))) (1/10) 5 (blocks 1) = true := by decide +kernel +lemma check_2 : expression.check (-10+(2:ℚ)*(5*(1/10))) (1/10) 5 (blocks 2) = true := by decide +kernel +lemma check_3 : expression.check (-10+(3:ℚ)*(5*(1/10))) (1/10) 5 (blocks 3) = true := by decide +kernel +lemma check_4 : expression.check (-10+(4:ℚ)*(5*(1/10))) (1/10) 5 (blocks 4) = true := by decide +kernel +lemma check_5 : expression.check (-10+(5:ℚ)*(5*(1/10))) (1/10) 5 (blocks 5) = true := by decide +kernel +lemma check_6 : expression.check (-10+(6:ℚ)*(5*(1/10))) (1/10) 5 (blocks 6) = true := by decide +kernel +lemma check_7 : expression.check (-10+(7:ℚ)*(5*(1/10))) (1/10) 5 (blocks 7) = true := by decide +kernel +lemma check_8 : expression.check (-10+(8:ℚ)*(5*(1/10))) (1/10) 5 (blocks 8) = true := by decide +kernel +lemma check_9 : expression.check (-10+(9:ℚ)*(5*(1/10))) (1/10) 5 (blocks 9) = true := by decide +kernel +lemma check_10 : expression.check (-10+(10:ℚ)*(5*(1/10))) (1/10) 5 (blocks 10) = true := by decide +kernel +lemma check_11 : expression.check (-10+(11:ℚ)*(5*(1/10))) (1/10) 5 (blocks 11) = true := by decide +kernel +lemma check_12 : expression.check (-10+(12:ℚ)*(5*(1/10))) (1/10) 5 (blocks 12) = true := by decide +kernel +lemma check_13 : expression.check (-10+(13:ℚ)*(5*(1/10))) (1/10) 5 (blocks 13) = true := by decide +kernel +lemma check_14 : expression.check (-10+(14:ℚ)*(5*(1/10))) (1/10) 5 (blocks 14) = true := by decide +kernel +lemma check_15 : expression.check (-10+(15:ℚ)*(5*(1/10))) (1/10) 5 (blocks 15) = true := by decide +kernel +lemma check_16 : expression.check (-10+(16:ℚ)*(5*(1/10))) (1/10) 5 (blocks 16) = true := by decide +kernel +lemma check_17 : expression.check (-10+(17:ℚ)*(5*(1/10))) (1/10) 5 (blocks 17) = true := by decide +kernel +lemma check_18 : expression.check (-10+(18:ℚ)*(5*(1/10))) (1/10) 5 (blocks 18) = true := by decide +kernel +lemma check_19 : expression.check (-10+(19:ℚ)*(5*(1/10))) (1/10) 5 (blocks 19) = true := by decide +kernel +lemma check_20 : expression.check (-10+(20:ℚ)*(5*(1/10))) (1/10) 5 (blocks 20) = true := by decide +kernel +lemma check_21 : expression.check (-10+(21:ℚ)*(5*(1/10))) (1/10) 5 (blocks 21) = true := by decide +kernel +lemma check_22 : expression.check (-10+(22:ℚ)*(5*(1/10))) (1/10) 5 (blocks 22) = true := by decide +kernel +lemma check_23 : expression.check (-10+(23:ℚ)*(5*(1/10))) (1/10) 5 (blocks 23) = true := by decide +kernel +lemma check_24 : expression.check (-10+(24:ℚ)*(5*(1/10))) (1/10) 5 (blocks 24) = true := by decide +kernel +lemma check_25 : expression.check (-10+(25:ℚ)*(5*(1/10))) (1/10) 5 (blocks 25) = true := by decide +kernel +lemma check_26 : expression.check (-10+(26:ℚ)*(5*(1/10))) (1/10) 5 (blocks 26) = true := by decide +kernel +lemma check_27 : expression.check (-10+(27:ℚ)*(5*(1/10))) (1/10) 5 (blocks 27) = true := by decide +kernel +lemma check_28 : expression.check (-10+(28:ℚ)*(5*(1/10))) (1/10) 5 (blocks 28) = true := by decide +kernel +lemma check_29 : expression.check (-10+(29:ℚ)*(5*(1/10))) (1/10) 5 (blocks 29) = true := by decide +kernel +lemma check_30 : expression.check (-10+(30:ℚ)*(5*(1/10))) (1/10) 5 (blocks 30) = true := by decide +kernel +lemma check_31 : expression.check (-10+(31:ℚ)*(5*(1/10))) (1/10) 5 (blocks 31) = true := by decide +kernel +lemma check_32 : expression.check (-10+(32:ℚ)*(5*(1/10))) (1/10) 5 (blocks 32) = true := by decide +kernel +lemma check_33 : expression.check (-10+(33:ℚ)*(5*(1/10))) (1/10) 5 (blocks 33) = true := by decide +kernel +lemma check_34 : expression.check (-10+(34:ℚ)*(5*(1/10))) (1/10) 5 (blocks 34) = true := by decide +kernel +lemma check_35 : expression.check (-10+(35:ℚ)*(5*(1/10))) (1/10) 5 (blocks 35) = true := by decide +kernel +lemma check_36 : expression.check (-10+(36:ℚ)*(5*(1/10))) (1/10) 5 (blocks 36) = true := by decide +kernel +lemma check_37 : expression.check (-10+(37:ℚ)*(5*(1/10))) (1/10) 5 (blocks 37) = true := by decide +kernel +lemma check_38 : expression.check (-10+(38:ℚ)*(5*(1/10))) (1/10) 5 (blocks 38) = true := by decide +kernel +lemma check_39 : expression.check (-10+(39:ℚ)*(5*(1/10))) (1/10) 5 (blocks 39) = true := by decide +kernel + +lemma checks (i : ℕ) (hi : i < 40) : + expression.check (-10+(i:ℚ)*(5*(1/10))) (1/10) 5 (blocks i) = true := by + interval_cases i + · exact check_0 + · exact check_1 + · exact check_2 + · exact check_3 + · exact check_4 + · exact check_5 + · exact check_6 + · exact check_7 + · exact check_8 + · exact check_9 + · exact check_10 + · exact check_11 + · exact check_12 + · exact check_13 + · exact check_14 + · exact check_15 + · exact check_16 + · exact check_17 + · exact check_18 + · exact check_19 + · exact check_20 + · exact check_21 + · exact check_22 + · exact check_23 + · exact check_24 + · exact check_25 + · exact check_26 + · exact check_27 + · exact check_28 + · exact check_29 + · exact check_30 + · exact check_31 + · exact check_32 + · exact check_33 + · exact check_34 + · exact check_35 + · exact check_36 + · exact check_37 + · exact check_38 + · exact check_39 + +theorem integral_bound : + (∫ h, scalarFunction (2/5) (107581/125000) (545767/1000000) (95751/1000000) (616697/1000000) 1 h ∂Scalar.fieldLaw (2/5)) ∈ (⟨544267/1000000,547267/1000000⟩ : Box) := by + apply gaussian_certificate (e := expression) (B := blocks) (h := (1/10)) (k := 5) (by norm_num) + · simpa only [expression,Rat.cast_div,Rat.cast_ofNat,Rat.cast_one,Rat.cast_zero] using integrandExpr_val (2/5) (107581/125000) (545767/1000000) (95751/1000000) (616697/1000000) 1 + · exact (continuous_scalarFunction _ _ _ _ _ _).measurable + · intro x + apply scalarFunction_bound <;> norm_num + · exact checks + · decide +kernel + +end SKRatio.Certificate.Data.J1K1 + +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Certificates/ScalarDataJ1K2.lean b/lean/OAI/Probability/SKRatio/Certificates/ScalarDataJ1K2.lean new file mode 100644 index 0000000000000000000000000000000000000000..3662ce758b101b3893745c79075ab55415f95df8 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Certificates/ScalarDataJ1K2.lean @@ -0,0 +1,154 @@ +import Mathlib +import OAI.Probability.SKRatio.Certificates.CertifiedBatches +import OAI.Probability.SKRatio.Certificates.CertifiedFunctionBounds + +namespace OAI + +noncomputable section +open Real MeasureTheory +namespace SKRatio.Certificate.Data.J1K2 + +def expression : Expr := integrandExpr (2/5) (107581/125000) (545767/1000000) (95751/1000000) (616697/1000000) 2 +def blocks : ℕ → Box + | 0 => ⟨-1/1000000,1/1000000⟩ + | 1 => ⟨-1/1000000,1/1000000⟩ + | 2 => ⟨-1/1000000,1/1000000⟩ + | 3 => ⟨-1/1000000,1/1000000⟩ + | 4 => ⟨-1/1000000,1/1000000⟩ + | 5 => ⟨-1/1000000,1/1000000⟩ + | 6 => ⟨-1/1000000,1/1000000⟩ + | 7 => ⟨-1/1000000,1/1000000⟩ + | 8 => ⟨-1/1000000,1/1000000⟩ + | 9 => ⟨-1/1000000,1/1000000⟩ + | 10 => ⟨-1/500000,0⟩ + | 11 => ⟨-13/1000000,-11/1000000⟩ + | 12 => ⟨-57/500000,-109/1000000⟩ + | 13 => ⟨-811/1000000,-789/1000000⟩ + | 14 => ⟨-2121/500000,-4171/1000000⟩ + | 15 => ⟨-15871/1000000,-1967/125000⟩ + | 16 => ⟨-40599/1000000,-40483/1000000⟩ + | 17 => ⟨-16293/250000,-32403/500000⟩ + | 18 => ⟨-48501/1000000,-47957/1000000⟩ + | 19 => ⟨911/31250,147/5000⟩ + | 20 => ⟨6969/62500,112111/1000000⟩ + | 21 => ⟨32273/250000,129669/1000000⟩ + | 22 => ⟨43943/500000,17627/200000⟩ + | 23 => ⟨159/4000,10019/250000⟩ + | 24 => ⟨6323/500000,12869/1000000⟩ + | 25 => ⟨117/40000,3017/1000000⟩ + | 26 => ⟨251/500000,529/1000000⟩ + | 27 => ⟨1/15625,71/1000000⟩ + | 28 => ⟨3/500000,1/125000⟩ + | 29 => ⟨0,1/1000000⟩ + | 30 => ⟨-1/1000000,1/1000000⟩ + | 31 => ⟨-1/1000000,1/1000000⟩ + | 32 => ⟨-1/1000000,1/1000000⟩ + | 33 => ⟨-1/1000000,1/1000000⟩ + | 34 => ⟨-1/1000000,1/1000000⟩ + | 35 => ⟨-1/1000000,1/1000000⟩ + | 36 => ⟨-1/1000000,1/1000000⟩ + | 37 => ⟨-1/1000000,1/1000000⟩ + | 38 => ⟨-1/1000000,1/1000000⟩ + | 39 => ⟨-1/1000000,1/1000000⟩ + | _ => Box.rat 0 + +lemma check_0 : expression.check (-10+(0:ℚ)*(5*(1/10))) (1/10) 5 (blocks 0) = true := by decide +kernel +lemma check_1 : expression.check (-10+(1:ℚ)*(5*(1/10))) (1/10) 5 (blocks 1) = true := by decide +kernel +lemma check_2 : expression.check (-10+(2:ℚ)*(5*(1/10))) (1/10) 5 (blocks 2) = true := by decide +kernel +lemma check_3 : expression.check (-10+(3:ℚ)*(5*(1/10))) (1/10) 5 (blocks 3) = true := by decide +kernel +lemma check_4 : expression.check (-10+(4:ℚ)*(5*(1/10))) (1/10) 5 (blocks 4) = true := by decide +kernel +lemma check_5 : expression.check (-10+(5:ℚ)*(5*(1/10))) (1/10) 5 (blocks 5) = true := by decide +kernel +lemma check_6 : expression.check (-10+(6:ℚ)*(5*(1/10))) (1/10) 5 (blocks 6) = true := by decide +kernel +lemma check_7 : expression.check (-10+(7:ℚ)*(5*(1/10))) (1/10) 5 (blocks 7) = true := by decide +kernel +lemma check_8 : expression.check (-10+(8:ℚ)*(5*(1/10))) (1/10) 5 (blocks 8) = true := by decide +kernel +lemma check_9 : expression.check (-10+(9:ℚ)*(5*(1/10))) (1/10) 5 (blocks 9) = true := by decide +kernel +lemma check_10 : expression.check (-10+(10:ℚ)*(5*(1/10))) (1/10) 5 (blocks 10) = true := by decide +kernel +lemma check_11 : expression.check (-10+(11:ℚ)*(5*(1/10))) (1/10) 5 (blocks 11) = true := by decide +kernel +lemma check_12 : expression.check (-10+(12:ℚ)*(5*(1/10))) (1/10) 5 (blocks 12) = true := by decide +kernel +lemma check_13 : expression.check (-10+(13:ℚ)*(5*(1/10))) (1/10) 5 (blocks 13) = true := by decide +kernel +lemma check_14 : expression.check (-10+(14:ℚ)*(5*(1/10))) (1/10) 5 (blocks 14) = true := by decide +kernel +lemma check_15 : expression.check (-10+(15:ℚ)*(5*(1/10))) (1/10) 5 (blocks 15) = true := by decide +kernel +lemma check_16 : expression.check (-10+(16:ℚ)*(5*(1/10))) (1/10) 5 (blocks 16) = true := by decide +kernel +lemma check_17 : expression.check (-10+(17:ℚ)*(5*(1/10))) (1/10) 5 (blocks 17) = true := by decide +kernel +lemma check_18 : expression.check (-10+(18:ℚ)*(5*(1/10))) (1/10) 5 (blocks 18) = true := by decide +kernel +lemma check_19 : expression.check (-10+(19:ℚ)*(5*(1/10))) (1/10) 5 (blocks 19) = true := by decide +kernel +lemma check_20 : expression.check (-10+(20:ℚ)*(5*(1/10))) (1/10) 5 (blocks 20) = true := by decide +kernel +lemma check_21 : expression.check (-10+(21:ℚ)*(5*(1/10))) (1/10) 5 (blocks 21) = true := by decide +kernel +lemma check_22 : expression.check (-10+(22:ℚ)*(5*(1/10))) (1/10) 5 (blocks 22) = true := by decide +kernel +lemma check_23 : expression.check (-10+(23:ℚ)*(5*(1/10))) (1/10) 5 (blocks 23) = true := by decide +kernel +lemma check_24 : expression.check (-10+(24:ℚ)*(5*(1/10))) (1/10) 5 (blocks 24) = true := by decide +kernel +lemma check_25 : expression.check (-10+(25:ℚ)*(5*(1/10))) (1/10) 5 (blocks 25) = true := by decide +kernel +lemma check_26 : expression.check (-10+(26:ℚ)*(5*(1/10))) (1/10) 5 (blocks 26) = true := by decide +kernel +lemma check_27 : expression.check (-10+(27:ℚ)*(5*(1/10))) (1/10) 5 (blocks 27) = true := by decide +kernel +lemma check_28 : expression.check (-10+(28:ℚ)*(5*(1/10))) (1/10) 5 (blocks 28) = true := by decide +kernel +lemma check_29 : expression.check (-10+(29:ℚ)*(5*(1/10))) (1/10) 5 (blocks 29) = true := by decide +kernel +lemma check_30 : expression.check (-10+(30:ℚ)*(5*(1/10))) (1/10) 5 (blocks 30) = true := by decide +kernel +lemma check_31 : expression.check (-10+(31:ℚ)*(5*(1/10))) (1/10) 5 (blocks 31) = true := by decide +kernel +lemma check_32 : expression.check (-10+(32:ℚ)*(5*(1/10))) (1/10) 5 (blocks 32) = true := by decide +kernel +lemma check_33 : expression.check (-10+(33:ℚ)*(5*(1/10))) (1/10) 5 (blocks 33) = true := by decide +kernel +lemma check_34 : expression.check (-10+(34:ℚ)*(5*(1/10))) (1/10) 5 (blocks 34) = true := by decide +kernel +lemma check_35 : expression.check (-10+(35:ℚ)*(5*(1/10))) (1/10) 5 (blocks 35) = true := by decide +kernel +lemma check_36 : expression.check (-10+(36:ℚ)*(5*(1/10))) (1/10) 5 (blocks 36) = true := by decide +kernel +lemma check_37 : expression.check (-10+(37:ℚ)*(5*(1/10))) (1/10) 5 (blocks 37) = true := by decide +kernel +lemma check_38 : expression.check (-10+(38:ℚ)*(5*(1/10))) (1/10) 5 (blocks 38) = true := by decide +kernel +lemma check_39 : expression.check (-10+(39:ℚ)*(5*(1/10))) (1/10) 5 (blocks 39) = true := by decide +kernel + +lemma checks (i : ℕ) (hi : i < 40) : + expression.check (-10+(i:ℚ)*(5*(1/10))) (1/10) 5 (blocks i) = true := by + interval_cases i + · exact check_0 + · exact check_1 + · exact check_2 + · exact check_3 + · exact check_4 + · exact check_5 + · exact check_6 + · exact check_7 + · exact check_8 + · exact check_9 + · exact check_10 + · exact check_11 + · exact check_12 + · exact check_13 + · exact check_14 + · exact check_15 + · exact check_16 + · exact check_17 + · exact check_18 + · exact check_19 + · exact check_20 + · exact check_21 + · exact check_22 + · exact check_23 + · exact check_24 + · exact check_25 + · exact check_26 + · exact check_27 + · exact check_28 + · exact check_29 + · exact check_30 + · exact check_31 + · exact check_32 + · exact check_33 + · exact check_34 + · exact check_35 + · exact check_36 + · exact check_37 + · exact check_38 + · exact check_39 + +theorem integral_bound : + (∫ h, scalarFunction (2/5) (107581/125000) (545767/1000000) (95751/1000000) (616697/1000000) 2 h ∂Scalar.fieldLaw (2/5)) ∈ (⟨94251/1000000,97251/1000000⟩ : Box) := by + apply gaussian_certificate (e := expression) (B := blocks) (h := (1/10)) (k := 5) (by norm_num) + · simpa only [expression,Rat.cast_div,Rat.cast_ofNat,Rat.cast_one,Rat.cast_zero] using integrandExpr_val (2/5) (107581/125000) (545767/1000000) (95751/1000000) (616697/1000000) 2 + · exact (continuous_scalarFunction _ _ _ _ _ _).measurable + · intro x + apply scalarFunction_bound <;> norm_num + · exact checks + · decide +kernel + +end SKRatio.Certificate.Data.J1K2 + +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Certificates/ScalarDataJ1K3.lean b/lean/OAI/Probability/SKRatio/Certificates/ScalarDataJ1K3.lean new file mode 100644 index 0000000000000000000000000000000000000000..3e36b1c60b631fd689b56e09076549a0473b5cb3 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Certificates/ScalarDataJ1K3.lean @@ -0,0 +1,154 @@ +import Mathlib +import OAI.Probability.SKRatio.Certificates.CertifiedBatches +import OAI.Probability.SKRatio.Certificates.CertifiedFunctionBounds + +namespace OAI + +noncomputable section +open Real MeasureTheory +namespace SKRatio.Certificate.Data.J1K3 + +def expression : Expr := integrandExpr (2/5) (107581/125000) (545767/1000000) (95751/1000000) (616697/1000000) 3 +def blocks : ℕ → Box + | 0 => ⟨-1/1000000,1/1000000⟩ + | 1 => ⟨-1/1000000,1/1000000⟩ + | 2 => ⟨-1/1000000,1/1000000⟩ + | 3 => ⟨-1/1000000,1/1000000⟩ + | 4 => ⟨-1/1000000,1/1000000⟩ + | 5 => ⟨-1/1000000,1/1000000⟩ + | 6 => ⟨-1/1000000,1/1000000⟩ + | 7 => ⟨-1/1000000,1/1000000⟩ + | 8 => ⟨-1/1000000,1/1000000⟩ + | 9 => ⟨-1/1000000,1/1000000⟩ + | 10 => ⟨-1/1000000,1/1000000⟩ + | 11 => ⟨-1/1000000,1/1000000⟩ + | 12 => ⟨1/1000000,1/500000⟩ + | 13 => ⟨3/200000,9/500000⟩ + | 14 => ⟨61/500000,129/1000000⟩ + | 15 => ⟨13/20000,673/1000000⟩ + | 16 => ⟨1163/500000,2373/1000000⟩ + | 17 => ⟨5209/1000000,2641/500000⟩ + | 18 => ⟨6441/1000000,3279/500000⟩ + | 19 => ⟨159/50000,3293/1000000⟩ + | 20 => ⟨129/500000,131/250000⟩ + | 21 => ⟨791/200000,2177/500000⟩ + | 22 => ⟨221/25000,4693/500000⟩ + | 23 => ⟨101/12500,8569/1000000⟩ + | 24 => ⟨4141/1000000,4407/1000000⟩ + | 25 => ⟨669/500000,1437/1000000⟩ + | 26 => ⟨29/100000,319/1000000⟩ + | 27 => ⟨43/1000000,51/1000000⟩ + | 28 => ⟨1/250000,3/500000⟩ + | 29 => ⟨0,1/1000000⟩ + | 30 => ⟨-1/1000000,1/1000000⟩ + | 31 => ⟨-1/1000000,1/1000000⟩ + | 32 => ⟨-1/1000000,1/1000000⟩ + | 33 => ⟨-1/1000000,1/1000000⟩ + | 34 => ⟨-1/1000000,1/1000000⟩ + | 35 => ⟨-1/1000000,1/1000000⟩ + | 36 => ⟨-1/1000000,1/1000000⟩ + | 37 => ⟨-1/1000000,1/1000000⟩ + | 38 => ⟨-1/1000000,1/1000000⟩ + | 39 => ⟨-1/1000000,1/1000000⟩ + | _ => Box.rat 0 + +lemma check_0 : expression.check (-10+(0:ℚ)*(5*(1/10))) (1/10) 5 (blocks 0) = true := by decide +kernel +lemma check_1 : expression.check (-10+(1:ℚ)*(5*(1/10))) (1/10) 5 (blocks 1) = true := by decide +kernel +lemma check_2 : expression.check (-10+(2:ℚ)*(5*(1/10))) (1/10) 5 (blocks 2) = true := by decide +kernel +lemma check_3 : expression.check (-10+(3:ℚ)*(5*(1/10))) (1/10) 5 (blocks 3) = true := by decide +kernel +lemma check_4 : expression.check (-10+(4:ℚ)*(5*(1/10))) (1/10) 5 (blocks 4) = true := by decide +kernel +lemma check_5 : expression.check (-10+(5:ℚ)*(5*(1/10))) (1/10) 5 (blocks 5) = true := by decide +kernel +lemma check_6 : expression.check (-10+(6:ℚ)*(5*(1/10))) (1/10) 5 (blocks 6) = true := by decide +kernel +lemma check_7 : expression.check (-10+(7:ℚ)*(5*(1/10))) (1/10) 5 (blocks 7) = true := by decide +kernel +lemma check_8 : expression.check (-10+(8:ℚ)*(5*(1/10))) (1/10) 5 (blocks 8) = true := by decide +kernel +lemma check_9 : expression.check (-10+(9:ℚ)*(5*(1/10))) (1/10) 5 (blocks 9) = true := by decide +kernel +lemma check_10 : expression.check (-10+(10:ℚ)*(5*(1/10))) (1/10) 5 (blocks 10) = true := by decide +kernel +lemma check_11 : expression.check (-10+(11:ℚ)*(5*(1/10))) (1/10) 5 (blocks 11) = true := by decide +kernel +lemma check_12 : expression.check (-10+(12:ℚ)*(5*(1/10))) (1/10) 5 (blocks 12) = true := by decide +kernel +lemma check_13 : expression.check (-10+(13:ℚ)*(5*(1/10))) (1/10) 5 (blocks 13) = true := by decide +kernel +lemma check_14 : expression.check (-10+(14:ℚ)*(5*(1/10))) (1/10) 5 (blocks 14) = true := by decide +kernel +lemma check_15 : expression.check (-10+(15:ℚ)*(5*(1/10))) (1/10) 5 (blocks 15) = true := by decide +kernel +lemma check_16 : expression.check (-10+(16:ℚ)*(5*(1/10))) (1/10) 5 (blocks 16) = true := by decide +kernel +lemma check_17 : expression.check (-10+(17:ℚ)*(5*(1/10))) (1/10) 5 (blocks 17) = true := by decide +kernel +lemma check_18 : expression.check (-10+(18:ℚ)*(5*(1/10))) (1/10) 5 (blocks 18) = true := by decide +kernel +lemma check_19 : expression.check (-10+(19:ℚ)*(5*(1/10))) (1/10) 5 (blocks 19) = true := by decide +kernel +lemma check_20 : expression.check (-10+(20:ℚ)*(5*(1/10))) (1/10) 5 (blocks 20) = true := by decide +kernel +lemma check_21 : expression.check (-10+(21:ℚ)*(5*(1/10))) (1/10) 5 (blocks 21) = true := by decide +kernel +lemma check_22 : expression.check (-10+(22:ℚ)*(5*(1/10))) (1/10) 5 (blocks 22) = true := by decide +kernel +lemma check_23 : expression.check (-10+(23:ℚ)*(5*(1/10))) (1/10) 5 (blocks 23) = true := by decide +kernel +lemma check_24 : expression.check (-10+(24:ℚ)*(5*(1/10))) (1/10) 5 (blocks 24) = true := by decide +kernel +lemma check_25 : expression.check (-10+(25:ℚ)*(5*(1/10))) (1/10) 5 (blocks 25) = true := by decide +kernel +lemma check_26 : expression.check (-10+(26:ℚ)*(5*(1/10))) (1/10) 5 (blocks 26) = true := by decide +kernel +lemma check_27 : expression.check (-10+(27:ℚ)*(5*(1/10))) (1/10) 5 (blocks 27) = true := by decide +kernel +lemma check_28 : expression.check (-10+(28:ℚ)*(5*(1/10))) (1/10) 5 (blocks 28) = true := by decide +kernel +lemma check_29 : expression.check (-10+(29:ℚ)*(5*(1/10))) (1/10) 5 (blocks 29) = true := by decide +kernel +lemma check_30 : expression.check (-10+(30:ℚ)*(5*(1/10))) (1/10) 5 (blocks 30) = true := by decide +kernel +lemma check_31 : expression.check (-10+(31:ℚ)*(5*(1/10))) (1/10) 5 (blocks 31) = true := by decide +kernel +lemma check_32 : expression.check (-10+(32:ℚ)*(5*(1/10))) (1/10) 5 (blocks 32) = true := by decide +kernel +lemma check_33 : expression.check (-10+(33:ℚ)*(5*(1/10))) (1/10) 5 (blocks 33) = true := by decide +kernel +lemma check_34 : expression.check (-10+(34:ℚ)*(5*(1/10))) (1/10) 5 (blocks 34) = true := by decide +kernel +lemma check_35 : expression.check (-10+(35:ℚ)*(5*(1/10))) (1/10) 5 (blocks 35) = true := by decide +kernel +lemma check_36 : expression.check (-10+(36:ℚ)*(5*(1/10))) (1/10) 5 (blocks 36) = true := by decide +kernel +lemma check_37 : expression.check (-10+(37:ℚ)*(5*(1/10))) (1/10) 5 (blocks 37) = true := by decide +kernel +lemma check_38 : expression.check (-10+(38:ℚ)*(5*(1/10))) (1/10) 5 (blocks 38) = true := by decide +kernel +lemma check_39 : expression.check (-10+(39:ℚ)*(5*(1/10))) (1/10) 5 (blocks 39) = true := by decide +kernel + +lemma checks (i : ℕ) (hi : i < 40) : + expression.check (-10+(i:ℚ)*(5*(1/10))) (1/10) 5 (blocks i) = true := by + interval_cases i + · exact check_0 + · exact check_1 + · exact check_2 + · exact check_3 + · exact check_4 + · exact check_5 + · exact check_6 + · exact check_7 + · exact check_8 + · exact check_9 + · exact check_10 + · exact check_11 + · exact check_12 + · exact check_13 + · exact check_14 + · exact check_15 + · exact check_16 + · exact check_17 + · exact check_18 + · exact check_19 + · exact check_20 + · exact check_21 + · exact check_22 + · exact check_23 + · exact check_24 + · exact check_25 + · exact check_26 + · exact check_27 + · exact check_28 + · exact check_29 + · exact check_30 + · exact check_31 + · exact check_32 + · exact check_33 + · exact check_34 + · exact check_35 + · exact check_36 + · exact check_37 + · exact check_38 + · exact check_39 + +theorem integral_bound : + (∫ h, scalarFunction (2/5) (107581/125000) (545767/1000000) (95751/1000000) (616697/1000000) 3 h ∂Scalar.fieldLaw (2/5)) ∈ (⟨0,1/50⟩ : Box) := by + apply gaussian_certificate (e := expression) (B := blocks) (h := (1/10)) (k := 5) (by norm_num) + · simpa only [expression,Rat.cast_div,Rat.cast_ofNat,Rat.cast_one,Rat.cast_zero] using integrandExpr_val (2/5) (107581/125000) (545767/1000000) (95751/1000000) (616697/1000000) 3 + · exact (continuous_scalarFunction _ _ _ _ _ _).measurable + · intro x + apply scalarFunction_bound <;> norm_num + · exact checks + · decide +kernel + +end SKRatio.Certificate.Data.J1K3 + +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Certificates/ScalarDataJ1K4.lean b/lean/OAI/Probability/SKRatio/Certificates/ScalarDataJ1K4.lean new file mode 100644 index 0000000000000000000000000000000000000000..b2375aff99f2621955dd3acbf944e78fe18a58ad --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Certificates/ScalarDataJ1K4.lean @@ -0,0 +1,154 @@ +import Mathlib +import OAI.Probability.SKRatio.Certificates.CertifiedBatches +import OAI.Probability.SKRatio.Certificates.CertifiedFunctionBounds + +namespace OAI + +noncomputable section +open Real MeasureTheory +namespace SKRatio.Certificate.Data.J1K4 + +def expression : Expr := integrandExpr (2/5) (107581/125000) (545767/1000000) (95751/1000000) (616697/1000000) 4 +def blocks : ℕ → Box + | 0 => ⟨-1/1000000,1/1000000⟩ + | 1 => ⟨-1/1000000,1/1000000⟩ + | 2 => ⟨-1/1000000,1/1000000⟩ + | 3 => ⟨-1/1000000,1/1000000⟩ + | 4 => ⟨-1/1000000,1/1000000⟩ + | 5 => ⟨-1/1000000,1/1000000⟩ + | 6 => ⟨-1/1000000,1/1000000⟩ + | 7 => ⟨-1/1000000,1/1000000⟩ + | 8 => ⟨-1/1000000,1/1000000⟩ + | 9 => ⟨0,1/1000000⟩ + | 10 => ⟨1/250000,1/200000⟩ + | 11 => ⟨1/31250,7/200000⟩ + | 12 => ⟨23/125000,19/100000⟩ + | 13 => ⟨181/250000,367/500000⟩ + | 14 => ⟨1817/1000000,1833/1000000⟩ + | 15 => ⟨2481/1000000,1259/500000⟩ + | 16 => ⟨287/250000,591/500000⟩ + | 17 => ⟨537/1000000,151/250000⟩ + | 18 => ⟨1337/250000,1079/200000⟩ + | 19 => ⟨8343/1000000,8429/1000000⟩ + | 20 => ⟨29/10000,149/50000⟩ + | 21 => ⟨621/500000,691/500000⟩ + | 22 => ⟨8421/1000000,4289/500000⟩ + | 23 => ⟨3101/250000,6301/500000⟩ + | 24 => ⟨8983/1000000,9099/1000000⟩ + | 25 => ⟨997/250000,4059/1000000⟩ + | 26 => ⟨1197/1000000,1231/1000000⟩ + | 27 => ⟨4/15625,67/250000⟩ + | 28 => ⟨1/25000,43/1000000⟩ + | 29 => ⟨1/250000,3/500000⟩ + | 30 => ⟨0,1/1000000⟩ + | 31 => ⟨-1/1000000,1/1000000⟩ + | 32 => ⟨-1/1000000,1/1000000⟩ + | 33 => ⟨-1/1000000,1/1000000⟩ + | 34 => ⟨-1/1000000,1/1000000⟩ + | 35 => ⟨-1/1000000,1/1000000⟩ + | 36 => ⟨-1/1000000,1/1000000⟩ + | 37 => ⟨-1/1000000,1/1000000⟩ + | 38 => ⟨-1/1000000,1/1000000⟩ + | 39 => ⟨-1/1000000,1/1000000⟩ + | _ => Box.rat 0 + +lemma check_0 : expression.check (-10+(0:ℚ)*(5*(1/10))) (1/10) 5 (blocks 0) = true := by decide +kernel +lemma check_1 : expression.check (-10+(1:ℚ)*(5*(1/10))) (1/10) 5 (blocks 1) = true := by decide +kernel +lemma check_2 : expression.check (-10+(2:ℚ)*(5*(1/10))) (1/10) 5 (blocks 2) = true := by decide +kernel +lemma check_3 : expression.check (-10+(3:ℚ)*(5*(1/10))) (1/10) 5 (blocks 3) = true := by decide +kernel +lemma check_4 : expression.check (-10+(4:ℚ)*(5*(1/10))) (1/10) 5 (blocks 4) = true := by decide +kernel +lemma check_5 : expression.check (-10+(5:ℚ)*(5*(1/10))) (1/10) 5 (blocks 5) = true := by decide +kernel +lemma check_6 : expression.check (-10+(6:ℚ)*(5*(1/10))) (1/10) 5 (blocks 6) = true := by decide +kernel +lemma check_7 : expression.check (-10+(7:ℚ)*(5*(1/10))) (1/10) 5 (blocks 7) = true := by decide +kernel +lemma check_8 : expression.check (-10+(8:ℚ)*(5*(1/10))) (1/10) 5 (blocks 8) = true := by decide +kernel +lemma check_9 : expression.check (-10+(9:ℚ)*(5*(1/10))) (1/10) 5 (blocks 9) = true := by decide +kernel +lemma check_10 : expression.check (-10+(10:ℚ)*(5*(1/10))) (1/10) 5 (blocks 10) = true := by decide +kernel +lemma check_11 : expression.check (-10+(11:ℚ)*(5*(1/10))) (1/10) 5 (blocks 11) = true := by decide +kernel +lemma check_12 : expression.check (-10+(12:ℚ)*(5*(1/10))) (1/10) 5 (blocks 12) = true := by decide +kernel +lemma check_13 : expression.check (-10+(13:ℚ)*(5*(1/10))) (1/10) 5 (blocks 13) = true := by decide +kernel +lemma check_14 : expression.check (-10+(14:ℚ)*(5*(1/10))) (1/10) 5 (blocks 14) = true := by decide +kernel +lemma check_15 : expression.check (-10+(15:ℚ)*(5*(1/10))) (1/10) 5 (blocks 15) = true := by decide +kernel +lemma check_16 : expression.check (-10+(16:ℚ)*(5*(1/10))) (1/10) 5 (blocks 16) = true := by decide +kernel +lemma check_17 : expression.check (-10+(17:ℚ)*(5*(1/10))) (1/10) 5 (blocks 17) = true := by decide +kernel +lemma check_18 : expression.check (-10+(18:ℚ)*(5*(1/10))) (1/10) 5 (blocks 18) = true := by decide +kernel +lemma check_19 : expression.check (-10+(19:ℚ)*(5*(1/10))) (1/10) 5 (blocks 19) = true := by decide +kernel +lemma check_20 : expression.check (-10+(20:ℚ)*(5*(1/10))) (1/10) 5 (blocks 20) = true := by decide +kernel +lemma check_21 : expression.check (-10+(21:ℚ)*(5*(1/10))) (1/10) 5 (blocks 21) = true := by decide +kernel +lemma check_22 : expression.check (-10+(22:ℚ)*(5*(1/10))) (1/10) 5 (blocks 22) = true := by decide +kernel +lemma check_23 : expression.check (-10+(23:ℚ)*(5*(1/10))) (1/10) 5 (blocks 23) = true := by decide +kernel +lemma check_24 : expression.check (-10+(24:ℚ)*(5*(1/10))) (1/10) 5 (blocks 24) = true := by decide +kernel +lemma check_25 : expression.check (-10+(25:ℚ)*(5*(1/10))) (1/10) 5 (blocks 25) = true := by decide +kernel +lemma check_26 : expression.check (-10+(26:ℚ)*(5*(1/10))) (1/10) 5 (blocks 26) = true := by decide +kernel +lemma check_27 : expression.check (-10+(27:ℚ)*(5*(1/10))) (1/10) 5 (blocks 27) = true := by decide +kernel +lemma check_28 : expression.check (-10+(28:ℚ)*(5*(1/10))) (1/10) 5 (blocks 28) = true := by decide +kernel +lemma check_29 : expression.check (-10+(29:ℚ)*(5*(1/10))) (1/10) 5 (blocks 29) = true := by decide +kernel +lemma check_30 : expression.check (-10+(30:ℚ)*(5*(1/10))) (1/10) 5 (blocks 30) = true := by decide +kernel +lemma check_31 : expression.check (-10+(31:ℚ)*(5*(1/10))) (1/10) 5 (blocks 31) = true := by decide +kernel +lemma check_32 : expression.check (-10+(32:ℚ)*(5*(1/10))) (1/10) 5 (blocks 32) = true := by decide +kernel +lemma check_33 : expression.check (-10+(33:ℚ)*(5*(1/10))) (1/10) 5 (blocks 33) = true := by decide +kernel +lemma check_34 : expression.check (-10+(34:ℚ)*(5*(1/10))) (1/10) 5 (blocks 34) = true := by decide +kernel +lemma check_35 : expression.check (-10+(35:ℚ)*(5*(1/10))) (1/10) 5 (blocks 35) = true := by decide +kernel +lemma check_36 : expression.check (-10+(36:ℚ)*(5*(1/10))) (1/10) 5 (blocks 36) = true := by decide +kernel +lemma check_37 : expression.check (-10+(37:ℚ)*(5*(1/10))) (1/10) 5 (blocks 37) = true := by decide +kernel +lemma check_38 : expression.check (-10+(38:ℚ)*(5*(1/10))) (1/10) 5 (blocks 38) = true := by decide +kernel +lemma check_39 : expression.check (-10+(39:ℚ)*(5*(1/10))) (1/10) 5 (blocks 39) = true := by decide +kernel + +lemma checks (i : ℕ) (hi : i < 40) : + expression.check (-10+(i:ℚ)*(5*(1/10))) (1/10) 5 (blocks i) = true := by + interval_cases i + · exact check_0 + · exact check_1 + · exact check_2 + · exact check_3 + · exact check_4 + · exact check_5 + · exact check_6 + · exact check_7 + · exact check_8 + · exact check_9 + · exact check_10 + · exact check_11 + · exact check_12 + · exact check_13 + · exact check_14 + · exact check_15 + · exact check_16 + · exact check_17 + · exact check_18 + · exact check_19 + · exact check_20 + · exact check_21 + · exact check_22 + · exact check_23 + · exact check_24 + · exact check_25 + · exact check_26 + · exact check_27 + · exact check_28 + · exact check_29 + · exact check_30 + · exact check_31 + · exact check_32 + · exact check_33 + · exact check_34 + · exact check_35 + · exact check_36 + · exact check_37 + · exact check_38 + · exact check_39 + +theorem integral_bound : + (∫ h, scalarFunction (2/5) (107581/125000) (545767/1000000) (95751/1000000) (616697/1000000) 4 h ∂Scalar.fieldLaw (2/5)) ∈ (⟨0,24649/1000000⟩ : Box) := by + apply gaussian_certificate (e := expression) (B := blocks) (h := (1/10)) (k := 5) (by norm_num) + · simpa only [expression,Rat.cast_div,Rat.cast_ofNat,Rat.cast_one,Rat.cast_zero] using integrandExpr_val (2/5) (107581/125000) (545767/1000000) (95751/1000000) (616697/1000000) 4 + · exact (continuous_scalarFunction _ _ _ _ _ _).measurable + · intro x + apply scalarFunction_bound <;> norm_num + · exact checks + · decide +kernel + +end SKRatio.Certificate.Data.J1K4 + +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Certificates/ScalarDataJ1K5.lean b/lean/OAI/Probability/SKRatio/Certificates/ScalarDataJ1K5.lean new file mode 100644 index 0000000000000000000000000000000000000000..d11423d77280a6da3f8ec4316160880c4119ec3b --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Certificates/ScalarDataJ1K5.lean @@ -0,0 +1,154 @@ +import Mathlib +import OAI.Probability.SKRatio.Certificates.CertifiedBatches +import OAI.Probability.SKRatio.Certificates.CertifiedFunctionBounds + +namespace OAI + +noncomputable section +open Real MeasureTheory +namespace SKRatio.Certificate.Data.J1K5 + +def expression : Expr := integrandExpr (2/5) (107581/125000) (545767/1000000) (95751/1000000) (616697/1000000) 5 +def blocks : ℕ → Box + | 0 => ⟨-1/1000000,1/1000000⟩ + | 1 => ⟨-1/1000000,1/1000000⟩ + | 2 => ⟨-1/1000000,1/1000000⟩ + | 3 => ⟨-1/1000000,1/1000000⟩ + | 4 => ⟨-1/1000000,1/1000000⟩ + | 5 => ⟨-1/1000000,1/1000000⟩ + | 6 => ⟨-1/1000000,1/1000000⟩ + | 7 => ⟨-1/1000000,1/1000000⟩ + | 8 => ⟨-1/1000000,1/1000000⟩ + | 9 => ⟨-1/1000000,1/1000000⟩ + | 10 => ⟨1/1000000,3/1000000⟩ + | 11 => ⟨3/200000,17/1000000⟩ + | 12 => ⟨1/10000,13/125000⟩ + | 13 => ⟨93/200000,473/1000000⟩ + | 14 => ⟨761/500000,307/200000⟩ + | 15 => ⟨3357/1000000,27/8000⟩ + | 16 => ⟨181/40000,913/200000⟩ + | 17 => ⟨749/250000,3027/1000000⟩ + | 18 => ⟨217/500000,473/1000000⟩ + | 19 => ⟨249/250000,16/15625⟩ + | 20 => ⟨1431/500000,91/31250⟩ + | 21 => ⟨471/250000,1941/1000000⟩ + | 22 => ⟨177/1000000,11/40000⟩ + | 23 => ⟨157/500000,399/1000000⟩ + | 24 => ⟨403/500000,877/1000000⟩ + | 25 => ⟨627/1000000,133/200000⟩ + | 26 => ⟨13/50000,11/40000⟩ + | 27 => ⟨67/1000000,37/500000⟩ + | 28 => ⟨3/250000,7/500000⟩ + | 29 => ⟨1/1000000,1/500000⟩ + | 30 => ⟨-1/1000000,1/1000000⟩ + | 31 => ⟨-1/1000000,1/1000000⟩ + | 32 => ⟨-1/1000000,1/1000000⟩ + | 33 => ⟨-1/1000000,1/1000000⟩ + | 34 => ⟨-1/1000000,1/1000000⟩ + | 35 => ⟨-1/1000000,1/1000000⟩ + | 36 => ⟨-1/1000000,1/1000000⟩ + | 37 => ⟨-1/1000000,1/1000000⟩ + | 38 => ⟨-1/1000000,1/1000000⟩ + | 39 => ⟨-1/1000000,1/1000000⟩ + | _ => Box.rat 0 + +lemma check_0 : expression.check (-10+(0:ℚ)*(5*(1/10))) (1/10) 5 (blocks 0) = true := by decide +kernel +lemma check_1 : expression.check (-10+(1:ℚ)*(5*(1/10))) (1/10) 5 (blocks 1) = true := by decide +kernel +lemma check_2 : expression.check (-10+(2:ℚ)*(5*(1/10))) (1/10) 5 (blocks 2) = true := by decide +kernel +lemma check_3 : expression.check (-10+(3:ℚ)*(5*(1/10))) (1/10) 5 (blocks 3) = true := by decide +kernel +lemma check_4 : expression.check (-10+(4:ℚ)*(5*(1/10))) (1/10) 5 (blocks 4) = true := by decide +kernel +lemma check_5 : expression.check (-10+(5:ℚ)*(5*(1/10))) (1/10) 5 (blocks 5) = true := by decide +kernel +lemma check_6 : expression.check (-10+(6:ℚ)*(5*(1/10))) (1/10) 5 (blocks 6) = true := by decide +kernel +lemma check_7 : expression.check (-10+(7:ℚ)*(5*(1/10))) (1/10) 5 (blocks 7) = true := by decide +kernel +lemma check_8 : expression.check (-10+(8:ℚ)*(5*(1/10))) (1/10) 5 (blocks 8) = true := by decide +kernel +lemma check_9 : expression.check (-10+(9:ℚ)*(5*(1/10))) (1/10) 5 (blocks 9) = true := by decide +kernel +lemma check_10 : expression.check (-10+(10:ℚ)*(5*(1/10))) (1/10) 5 (blocks 10) = true := by decide +kernel +lemma check_11 : expression.check (-10+(11:ℚ)*(5*(1/10))) (1/10) 5 (blocks 11) = true := by decide +kernel +lemma check_12 : expression.check (-10+(12:ℚ)*(5*(1/10))) (1/10) 5 (blocks 12) = true := by decide +kernel +lemma check_13 : expression.check (-10+(13:ℚ)*(5*(1/10))) (1/10) 5 (blocks 13) = true := by decide +kernel +lemma check_14 : expression.check (-10+(14:ℚ)*(5*(1/10))) (1/10) 5 (blocks 14) = true := by decide +kernel +lemma check_15 : expression.check (-10+(15:ℚ)*(5*(1/10))) (1/10) 5 (blocks 15) = true := by decide +kernel +lemma check_16 : expression.check (-10+(16:ℚ)*(5*(1/10))) (1/10) 5 (blocks 16) = true := by decide +kernel +lemma check_17 : expression.check (-10+(17:ℚ)*(5*(1/10))) (1/10) 5 (blocks 17) = true := by decide +kernel +lemma check_18 : expression.check (-10+(18:ℚ)*(5*(1/10))) (1/10) 5 (blocks 18) = true := by decide +kernel +lemma check_19 : expression.check (-10+(19:ℚ)*(5*(1/10))) (1/10) 5 (blocks 19) = true := by decide +kernel +lemma check_20 : expression.check (-10+(20:ℚ)*(5*(1/10))) (1/10) 5 (blocks 20) = true := by decide +kernel +lemma check_21 : expression.check (-10+(21:ℚ)*(5*(1/10))) (1/10) 5 (blocks 21) = true := by decide +kernel +lemma check_22 : expression.check (-10+(22:ℚ)*(5*(1/10))) (1/10) 5 (blocks 22) = true := by decide +kernel +lemma check_23 : expression.check (-10+(23:ℚ)*(5*(1/10))) (1/10) 5 (blocks 23) = true := by decide +kernel +lemma check_24 : expression.check (-10+(24:ℚ)*(5*(1/10))) (1/10) 5 (blocks 24) = true := by decide +kernel +lemma check_25 : expression.check (-10+(25:ℚ)*(5*(1/10))) (1/10) 5 (blocks 25) = true := by decide +kernel +lemma check_26 : expression.check (-10+(26:ℚ)*(5*(1/10))) (1/10) 5 (blocks 26) = true := by decide +kernel +lemma check_27 : expression.check (-10+(27:ℚ)*(5*(1/10))) (1/10) 5 (blocks 27) = true := by decide +kernel +lemma check_28 : expression.check (-10+(28:ℚ)*(5*(1/10))) (1/10) 5 (blocks 28) = true := by decide +kernel +lemma check_29 : expression.check (-10+(29:ℚ)*(5*(1/10))) (1/10) 5 (blocks 29) = true := by decide +kernel +lemma check_30 : expression.check (-10+(30:ℚ)*(5*(1/10))) (1/10) 5 (blocks 30) = true := by decide +kernel +lemma check_31 : expression.check (-10+(31:ℚ)*(5*(1/10))) (1/10) 5 (blocks 31) = true := by decide +kernel +lemma check_32 : expression.check (-10+(32:ℚ)*(5*(1/10))) (1/10) 5 (blocks 32) = true := by decide +kernel +lemma check_33 : expression.check (-10+(33:ℚ)*(5*(1/10))) (1/10) 5 (blocks 33) = true := by decide +kernel +lemma check_34 : expression.check (-10+(34:ℚ)*(5*(1/10))) (1/10) 5 (blocks 34) = true := by decide +kernel +lemma check_35 : expression.check (-10+(35:ℚ)*(5*(1/10))) (1/10) 5 (blocks 35) = true := by decide +kernel +lemma check_36 : expression.check (-10+(36:ℚ)*(5*(1/10))) (1/10) 5 (blocks 36) = true := by decide +kernel +lemma check_37 : expression.check (-10+(37:ℚ)*(5*(1/10))) (1/10) 5 (blocks 37) = true := by decide +kernel +lemma check_38 : expression.check (-10+(38:ℚ)*(5*(1/10))) (1/10) 5 (blocks 38) = true := by decide +kernel +lemma check_39 : expression.check (-10+(39:ℚ)*(5*(1/10))) (1/10) 5 (blocks 39) = true := by decide +kernel + +lemma checks (i : ℕ) (hi : i < 40) : + expression.check (-10+(i:ℚ)*(5*(1/10))) (1/10) 5 (blocks i) = true := by + interval_cases i + · exact check_0 + · exact check_1 + · exact check_2 + · exact check_3 + · exact check_4 + · exact check_5 + · exact check_6 + · exact check_7 + · exact check_8 + · exact check_9 + · exact check_10 + · exact check_11 + · exact check_12 + · exact check_13 + · exact check_14 + · exact check_15 + · exact check_16 + · exact check_17 + · exact check_18 + · exact check_19 + · exact check_20 + · exact check_21 + · exact check_22 + · exact check_23 + · exact check_24 + · exact check_25 + · exact check_26 + · exact check_27 + · exact check_28 + · exact check_29 + · exact check_30 + · exact check_31 + · exact check_32 + · exact check_33 + · exact check_34 + · exact check_35 + · exact check_36 + · exact check_37 + · exact check_38 + · exact check_39 + +theorem integral_bound : + (∫ h, scalarFunction (2/5) (107581/125000) (545767/1000000) (95751/1000000) (616697/1000000) 5 h ∂Scalar.fieldLaw (2/5)) ∈ (⟨0,361/40000⟩ : Box) := by + apply gaussian_certificate (e := expression) (B := blocks) (h := (1/10)) (k := 5) (by norm_num) + · simpa only [expression,Rat.cast_div,Rat.cast_ofNat,Rat.cast_one,Rat.cast_zero] using integrandExpr_val (2/5) (107581/125000) (545767/1000000) (95751/1000000) (616697/1000000) 5 + · exact (continuous_scalarFunction _ _ _ _ _ _).measurable + · intro x + apply scalarFunction_bound <;> norm_num + · exact checks + · decide +kernel + +end SKRatio.Certificate.Data.J1K5 + +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Certificates/ScalarDataJ1K6.lean b/lean/OAI/Probability/SKRatio/Certificates/ScalarDataJ1K6.lean new file mode 100644 index 0000000000000000000000000000000000000000..ca0e0aedea90fef1af353beafb3499c5dd40539b --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Certificates/ScalarDataJ1K6.lean @@ -0,0 +1,154 @@ +import Mathlib +import OAI.Probability.SKRatio.Certificates.CertifiedBatches +import OAI.Probability.SKRatio.Certificates.CertifiedFunctionBounds + +namespace OAI + +noncomputable section +open Real MeasureTheory +namespace SKRatio.Certificate.Data.J1K6 + +def expression : Expr := integrandExpr (2/5) (107581/125000) (545767/1000000) (95751/1000000) (616697/1000000) 6 +def blocks : ℕ → Box + | 0 => ⟨-1/1000000,1/1000000⟩ + | 1 => ⟨-1/1000000,1/1000000⟩ + | 2 => ⟨-1/1000000,1/1000000⟩ + | 3 => ⟨-1/1000000,1/1000000⟩ + | 4 => ⟨-1/1000000,1/1000000⟩ + | 5 => ⟨-1/1000000,1/1000000⟩ + | 6 => ⟨-1/1000000,1/1000000⟩ + | 7 => ⟨-1/1000000,1/1000000⟩ + | 8 => ⟨-1/1000000,1/1000000⟩ + | 9 => ⟨-1/1000000,1/1000000⟩ + | 10 => ⟨0,1/1000000⟩ + | 11 => ⟨1/250000,3/500000⟩ + | 12 => ⟨49/1000000,13/250000⟩ + | 13 => ⟨1/2500,413/1000000⟩ + | 14 => ⟨2343/1000000,2389/1000000⟩ + | 15 => ⟨937/100000,9457/1000000⟩ + | 16 => ⟨23607/1000000,4741/200000⟩ + | 17 => ⟨33071/1000000,3333/100000⟩ + | 18 => ⟨19919/1000000,803/40000⟩ + | 19 => ⟨1041/500000,2327/1000000⟩ + | 20 => ⟨4969/500000,10101/1000000⟩ + | 21 => ⟨5821/250000,11783/500000⟩ + | 22 => ⟨18807/1000000,1897/100000⟩ + | 23 => ⟨7711/1000000,7873/1000000⟩ + | 24 => ⟨227/125000,383/200000⟩ + | 25 => ⟨251/1000000,57/200000⟩ + | 26 => ⟨9/500000,13/500000⟩ + | 27 => ⟨0,1/500000⟩ + | 28 => ⟨-1/1000000,1/1000000⟩ + | 29 => ⟨-1/1000000,1/1000000⟩ + | 30 => ⟨-1/1000000,1/1000000⟩ + | 31 => ⟨-1/1000000,1/1000000⟩ + | 32 => ⟨-1/1000000,1/1000000⟩ + | 33 => ⟨-1/1000000,1/1000000⟩ + | 34 => ⟨-1/1000000,1/1000000⟩ + | 35 => ⟨-1/1000000,1/1000000⟩ + | 36 => ⟨-1/1000000,1/1000000⟩ + | 37 => ⟨-1/1000000,1/1000000⟩ + | 38 => ⟨-1/1000000,1/1000000⟩ + | 39 => ⟨-1/1000000,1/1000000⟩ + | _ => Box.rat 0 + +lemma check_0 : expression.check (-10+(0:ℚ)*(5*(1/10))) (1/10) 5 (blocks 0) = true := by decide +kernel +lemma check_1 : expression.check (-10+(1:ℚ)*(5*(1/10))) (1/10) 5 (blocks 1) = true := by decide +kernel +lemma check_2 : expression.check (-10+(2:ℚ)*(5*(1/10))) (1/10) 5 (blocks 2) = true := by decide +kernel +lemma check_3 : expression.check (-10+(3:ℚ)*(5*(1/10))) (1/10) 5 (blocks 3) = true := by decide +kernel +lemma check_4 : expression.check (-10+(4:ℚ)*(5*(1/10))) (1/10) 5 (blocks 4) = true := by decide +kernel +lemma check_5 : expression.check (-10+(5:ℚ)*(5*(1/10))) (1/10) 5 (blocks 5) = true := by decide +kernel +lemma check_6 : expression.check (-10+(6:ℚ)*(5*(1/10))) (1/10) 5 (blocks 6) = true := by decide +kernel +lemma check_7 : expression.check (-10+(7:ℚ)*(5*(1/10))) (1/10) 5 (blocks 7) = true := by decide +kernel +lemma check_8 : expression.check (-10+(8:ℚ)*(5*(1/10))) (1/10) 5 (blocks 8) = true := by decide +kernel +lemma check_9 : expression.check (-10+(9:ℚ)*(5*(1/10))) (1/10) 5 (blocks 9) = true := by decide +kernel +lemma check_10 : expression.check (-10+(10:ℚ)*(5*(1/10))) (1/10) 5 (blocks 10) = true := by decide +kernel +lemma check_11 : expression.check (-10+(11:ℚ)*(5*(1/10))) (1/10) 5 (blocks 11) = true := by decide +kernel +lemma check_12 : expression.check (-10+(12:ℚ)*(5*(1/10))) (1/10) 5 (blocks 12) = true := by decide +kernel +lemma check_13 : expression.check (-10+(13:ℚ)*(5*(1/10))) (1/10) 5 (blocks 13) = true := by decide +kernel +lemma check_14 : expression.check (-10+(14:ℚ)*(5*(1/10))) (1/10) 5 (blocks 14) = true := by decide +kernel +lemma check_15 : expression.check (-10+(15:ℚ)*(5*(1/10))) (1/10) 5 (blocks 15) = true := by decide +kernel +lemma check_16 : expression.check (-10+(16:ℚ)*(5*(1/10))) (1/10) 5 (blocks 16) = true := by decide +kernel +lemma check_17 : expression.check (-10+(17:ℚ)*(5*(1/10))) (1/10) 5 (blocks 17) = true := by decide +kernel +lemma check_18 : expression.check (-10+(18:ℚ)*(5*(1/10))) (1/10) 5 (blocks 18) = true := by decide +kernel +lemma check_19 : expression.check (-10+(19:ℚ)*(5*(1/10))) (1/10) 5 (blocks 19) = true := by decide +kernel +lemma check_20 : expression.check (-10+(20:ℚ)*(5*(1/10))) (1/10) 5 (blocks 20) = true := by decide +kernel +lemma check_21 : expression.check (-10+(21:ℚ)*(5*(1/10))) (1/10) 5 (blocks 21) = true := by decide +kernel +lemma check_22 : expression.check (-10+(22:ℚ)*(5*(1/10))) (1/10) 5 (blocks 22) = true := by decide +kernel +lemma check_23 : expression.check (-10+(23:ℚ)*(5*(1/10))) (1/10) 5 (blocks 23) = true := by decide +kernel +lemma check_24 : expression.check (-10+(24:ℚ)*(5*(1/10))) (1/10) 5 (blocks 24) = true := by decide +kernel +lemma check_25 : expression.check (-10+(25:ℚ)*(5*(1/10))) (1/10) 5 (blocks 25) = true := by decide +kernel +lemma check_26 : expression.check (-10+(26:ℚ)*(5*(1/10))) (1/10) 5 (blocks 26) = true := by decide +kernel +lemma check_27 : expression.check (-10+(27:ℚ)*(5*(1/10))) (1/10) 5 (blocks 27) = true := by decide +kernel +lemma check_28 : expression.check (-10+(28:ℚ)*(5*(1/10))) (1/10) 5 (blocks 28) = true := by decide +kernel +lemma check_29 : expression.check (-10+(29:ℚ)*(5*(1/10))) (1/10) 5 (blocks 29) = true := by decide +kernel +lemma check_30 : expression.check (-10+(30:ℚ)*(5*(1/10))) (1/10) 5 (blocks 30) = true := by decide +kernel +lemma check_31 : expression.check (-10+(31:ℚ)*(5*(1/10))) (1/10) 5 (blocks 31) = true := by decide +kernel +lemma check_32 : expression.check (-10+(32:ℚ)*(5*(1/10))) (1/10) 5 (blocks 32) = true := by decide +kernel +lemma check_33 : expression.check (-10+(33:ℚ)*(5*(1/10))) (1/10) 5 (blocks 33) = true := by decide +kernel +lemma check_34 : expression.check (-10+(34:ℚ)*(5*(1/10))) (1/10) 5 (blocks 34) = true := by decide +kernel +lemma check_35 : expression.check (-10+(35:ℚ)*(5*(1/10))) (1/10) 5 (blocks 35) = true := by decide +kernel +lemma check_36 : expression.check (-10+(36:ℚ)*(5*(1/10))) (1/10) 5 (blocks 36) = true := by decide +kernel +lemma check_37 : expression.check (-10+(37:ℚ)*(5*(1/10))) (1/10) 5 (blocks 37) = true := by decide +kernel +lemma check_38 : expression.check (-10+(38:ℚ)*(5*(1/10))) (1/10) 5 (blocks 38) = true := by decide +kernel +lemma check_39 : expression.check (-10+(39:ℚ)*(5*(1/10))) (1/10) 5 (blocks 39) = true := by decide +kernel + +lemma checks (i : ℕ) (hi : i < 40) : + expression.check (-10+(i:ℚ)*(5*(1/10))) (1/10) 5 (blocks i) = true := by + interval_cases i + · exact check_0 + · exact check_1 + · exact check_2 + · exact check_3 + · exact check_4 + · exact check_5 + · exact check_6 + · exact check_7 + · exact check_8 + · exact check_9 + · exact check_10 + · exact check_11 + · exact check_12 + · exact check_13 + · exact check_14 + · exact check_15 + · exact check_16 + · exact check_17 + · exact check_18 + · exact check_19 + · exact check_20 + · exact check_21 + · exact check_22 + · exact check_23 + · exact check_24 + · exact check_25 + · exact check_26 + · exact check_27 + · exact check_28 + · exact check_29 + · exact check_30 + · exact check_31 + · exact check_32 + · exact check_33 + · exact check_34 + · exact check_35 + · exact check_36 + · exact check_37 + · exact check_38 + · exact check_39 + +theorem integral_bound : + (∫ h, scalarFunction (2/5) (107581/125000) (545767/1000000) (95751/1000000) (616697/1000000) 6 h ∂Scalar.fieldLaw (2/5)) ∈ (⟨0,62001/1000000⟩ : Box) := by + apply gaussian_certificate (e := expression) (B := blocks) (h := (1/10)) (k := 5) (by norm_num) + · simpa only [expression,Rat.cast_div,Rat.cast_ofNat,Rat.cast_one,Rat.cast_zero] using integrandExpr_val (2/5) (107581/125000) (545767/1000000) (95751/1000000) (616697/1000000) 6 + · exact (continuous_scalarFunction _ _ _ _ _ _).measurable + · intro x + apply scalarFunction_bound <;> norm_num + · exact checks + · decide +kernel + +end SKRatio.Certificate.Data.J1K6 + +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Certificates/ScalarDataJ1K7.lean b/lean/OAI/Probability/SKRatio/Certificates/ScalarDataJ1K7.lean new file mode 100644 index 0000000000000000000000000000000000000000..ce3ed005bc6a0cac89e8ce08cdc95a813880aa6f --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Certificates/ScalarDataJ1K7.lean @@ -0,0 +1,154 @@ +import Mathlib +import OAI.Probability.SKRatio.Certificates.CertifiedBatches +import OAI.Probability.SKRatio.Certificates.CertifiedFunctionBounds + +namespace OAI + +noncomputable section +open Real MeasureTheory +namespace SKRatio.Certificate.Data.J1K7 + +def expression : Expr := integrandExpr (2/5) (107581/125000) (545767/1000000) (95751/1000000) (616697/1000000) 7 +def blocks : ℕ → Box + | 0 => ⟨-1/1000000,1/1000000⟩ + | 1 => ⟨-1/1000000,1/1000000⟩ + | 2 => ⟨-1/1000000,1/1000000⟩ + | 3 => ⟨-1/1000000,1/1000000⟩ + | 4 => ⟨-1/1000000,1/1000000⟩ + | 5 => ⟨-1/1000000,1/1000000⟩ + | 6 => ⟨-1/1000000,1/1000000⟩ + | 7 => ⟨-1/1000000,1/1000000⟩ + | 8 => ⟨0,1/1000000⟩ + | 9 => ⟨1/250000,1/200000⟩ + | 10 => ⟨11/250000,3/62500⟩ + | 11 => ⟨369/1000000,383/1000000⟩ + | 12 => ⟨473/200000,1213/500000⟩ + | 13 => ⟨11663/1000000,5933/500000⟩ + | 14 => ⟨1733/40000,43781/1000000⟩ + | 15 => ⟨116837/1000000,58691/500000⟩ + | 16 => ⟨21459/100000,107769/500000⟩ + | 17 => ⟨241471/1000000,60761/250000⟩ + | 18 => ⟨131229/1000000,66019/500000⟩ + | 19 => ⟨2887/200000,7907/500000⟩ + | 20 => ⟨51879/1000000,10543/200000⟩ + | 21 => ⟨77211/500000,31151/200000⟩ + | 22 => ⟨42457/250000,34217/200000⟩ + | 23 => ⟨108519/1000000,109261/1000000⟩ + | 24 => ⟨23631/500000,9589/200000⟩ + | 25 => ⟨7649/500000,3921/250000⟩ + | 26 => ⟨1927/500000,4001/1000000⟩ + | 27 => ⟨771/1000000,813/1000000⟩ + | 28 => ⟨61/500000,33/250000⟩ + | 29 => ⟨3/200000,9/500000⟩ + | 30 => ⟨1/1000000,1/500000⟩ + | 31 => ⟨-1/1000000,1/1000000⟩ + | 32 => ⟨-1/1000000,1/1000000⟩ + | 33 => ⟨-1/1000000,1/1000000⟩ + | 34 => ⟨-1/1000000,1/1000000⟩ + | 35 => ⟨-1/1000000,1/1000000⟩ + | 36 => ⟨-1/1000000,1/1000000⟩ + | 37 => ⟨-1/1000000,1/1000000⟩ + | 38 => ⟨-1/1000000,1/1000000⟩ + | 39 => ⟨-1/1000000,1/1000000⟩ + | _ => Box.rat 0 + +lemma check_0 : expression.check (-10+(0:ℚ)*(5*(1/10))) (1/10) 5 (blocks 0) = true := by decide +kernel +lemma check_1 : expression.check (-10+(1:ℚ)*(5*(1/10))) (1/10) 5 (blocks 1) = true := by decide +kernel +lemma check_2 : expression.check (-10+(2:ℚ)*(5*(1/10))) (1/10) 5 (blocks 2) = true := by decide +kernel +lemma check_3 : expression.check (-10+(3:ℚ)*(5*(1/10))) (1/10) 5 (blocks 3) = true := by decide +kernel +lemma check_4 : expression.check (-10+(4:ℚ)*(5*(1/10))) (1/10) 5 (blocks 4) = true := by decide +kernel +lemma check_5 : expression.check (-10+(5:ℚ)*(5*(1/10))) (1/10) 5 (blocks 5) = true := by decide +kernel +lemma check_6 : expression.check (-10+(6:ℚ)*(5*(1/10))) (1/10) 5 (blocks 6) = true := by decide +kernel +lemma check_7 : expression.check (-10+(7:ℚ)*(5*(1/10))) (1/10) 5 (blocks 7) = true := by decide +kernel +lemma check_8 : expression.check (-10+(8:ℚ)*(5*(1/10))) (1/10) 5 (blocks 8) = true := by decide +kernel +lemma check_9 : expression.check (-10+(9:ℚ)*(5*(1/10))) (1/10) 5 (blocks 9) = true := by decide +kernel +lemma check_10 : expression.check (-10+(10:ℚ)*(5*(1/10))) (1/10) 5 (blocks 10) = true := by decide +kernel +lemma check_11 : expression.check (-10+(11:ℚ)*(5*(1/10))) (1/10) 5 (blocks 11) = true := by decide +kernel +lemma check_12 : expression.check (-10+(12:ℚ)*(5*(1/10))) (1/10) 5 (blocks 12) = true := by decide +kernel +lemma check_13 : expression.check (-10+(13:ℚ)*(5*(1/10))) (1/10) 5 (blocks 13) = true := by decide +kernel +lemma check_14 : expression.check (-10+(14:ℚ)*(5*(1/10))) (1/10) 5 (blocks 14) = true := by decide +kernel +lemma check_15 : expression.check (-10+(15:ℚ)*(5*(1/10))) (1/10) 5 (blocks 15) = true := by decide +kernel +lemma check_16 : expression.check (-10+(16:ℚ)*(5*(1/10))) (1/10) 5 (blocks 16) = true := by decide +kernel +lemma check_17 : expression.check (-10+(17:ℚ)*(5*(1/10))) (1/10) 5 (blocks 17) = true := by decide +kernel +lemma check_18 : expression.check (-10+(18:ℚ)*(5*(1/10))) (1/10) 5 (blocks 18) = true := by decide +kernel +lemma check_19 : expression.check (-10+(19:ℚ)*(5*(1/10))) (1/10) 5 (blocks 19) = true := by decide +kernel +lemma check_20 : expression.check (-10+(20:ℚ)*(5*(1/10))) (1/10) 5 (blocks 20) = true := by decide +kernel +lemma check_21 : expression.check (-10+(21:ℚ)*(5*(1/10))) (1/10) 5 (blocks 21) = true := by decide +kernel +lemma check_22 : expression.check (-10+(22:ℚ)*(5*(1/10))) (1/10) 5 (blocks 22) = true := by decide +kernel +lemma check_23 : expression.check (-10+(23:ℚ)*(5*(1/10))) (1/10) 5 (blocks 23) = true := by decide +kernel +lemma check_24 : expression.check (-10+(24:ℚ)*(5*(1/10))) (1/10) 5 (blocks 24) = true := by decide +kernel +lemma check_25 : expression.check (-10+(25:ℚ)*(5*(1/10))) (1/10) 5 (blocks 25) = true := by decide +kernel +lemma check_26 : expression.check (-10+(26:ℚ)*(5*(1/10))) (1/10) 5 (blocks 26) = true := by decide +kernel +lemma check_27 : expression.check (-10+(27:ℚ)*(5*(1/10))) (1/10) 5 (blocks 27) = true := by decide +kernel +lemma check_28 : expression.check (-10+(28:ℚ)*(5*(1/10))) (1/10) 5 (blocks 28) = true := by decide +kernel +lemma check_29 : expression.check (-10+(29:ℚ)*(5*(1/10))) (1/10) 5 (blocks 29) = true := by decide +kernel +lemma check_30 : expression.check (-10+(30:ℚ)*(5*(1/10))) (1/10) 5 (blocks 30) = true := by decide +kernel +lemma check_31 : expression.check (-10+(31:ℚ)*(5*(1/10))) (1/10) 5 (blocks 31) = true := by decide +kernel +lemma check_32 : expression.check (-10+(32:ℚ)*(5*(1/10))) (1/10) 5 (blocks 32) = true := by decide +kernel +lemma check_33 : expression.check (-10+(33:ℚ)*(5*(1/10))) (1/10) 5 (blocks 33) = true := by decide +kernel +lemma check_34 : expression.check (-10+(34:ℚ)*(5*(1/10))) (1/10) 5 (blocks 34) = true := by decide +kernel +lemma check_35 : expression.check (-10+(35:ℚ)*(5*(1/10))) (1/10) 5 (blocks 35) = true := by decide +kernel +lemma check_36 : expression.check (-10+(36:ℚ)*(5*(1/10))) (1/10) 5 (blocks 36) = true := by decide +kernel +lemma check_37 : expression.check (-10+(37:ℚ)*(5*(1/10))) (1/10) 5 (blocks 37) = true := by decide +kernel +lemma check_38 : expression.check (-10+(38:ℚ)*(5*(1/10))) (1/10) 5 (blocks 38) = true := by decide +kernel +lemma check_39 : expression.check (-10+(39:ℚ)*(5*(1/10))) (1/10) 5 (blocks 39) = true := by decide +kernel + +lemma checks (i : ℕ) (hi : i < 40) : + expression.check (-10+(i:ℚ)*(5*(1/10))) (1/10) 5 (blocks i) = true := by + interval_cases i + · exact check_0 + · exact check_1 + · exact check_2 + · exact check_3 + · exact check_4 + · exact check_5 + · exact check_6 + · exact check_7 + · exact check_8 + · exact check_9 + · exact check_10 + · exact check_11 + · exact check_12 + · exact check_13 + · exact check_14 + · exact check_15 + · exact check_16 + · exact check_17 + · exact check_18 + · exact check_19 + · exact check_20 + · exact check_21 + · exact check_22 + · exact check_23 + · exact check_24 + · exact check_25 + · exact check_26 + · exact check_27 + · exact check_28 + · exact check_29 + · exact check_30 + · exact check_31 + · exact check_32 + · exact check_33 + · exact check_34 + · exact check_35 + · exact check_36 + · exact check_37 + · exact check_38 + · exact check_39 + +theorem integral_bound : + (∫ h, scalarFunction (2/5) (107581/125000) (545767/1000000) (95751/1000000) (616697/1000000) 7 h ∂Scalar.fieldLaw (2/5)) ∈ (⟨0,33489/62500⟩ : Box) := by + apply gaussian_certificate (e := expression) (B := blocks) (h := (1/10)) (k := 5) (by norm_num) + · simpa only [expression,Rat.cast_div,Rat.cast_ofNat,Rat.cast_one,Rat.cast_zero] using integrandExpr_val (2/5) (107581/125000) (545767/1000000) (95751/1000000) (616697/1000000) 7 + · exact (continuous_scalarFunction _ _ _ _ _ _).measurable + · intro x + apply scalarFunction_bound <;> norm_num + · exact checks + · decide +kernel + +end SKRatio.Certificate.Data.J1K7 + +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Certificates/ScalarDataJ2K0.lean b/lean/OAI/Probability/SKRatio/Certificates/ScalarDataJ2K0.lean new file mode 100644 index 0000000000000000000000000000000000000000..c61abe94fb24e59ee6e76ac9ba5bfe2ced634471 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Certificates/ScalarDataJ2K0.lean @@ -0,0 +1,154 @@ +import Mathlib +import OAI.Probability.SKRatio.Certificates.CertifiedBatches +import OAI.Probability.SKRatio.Certificates.CertifiedFunctionBounds + +namespace OAI + +noncomputable section +open Real MeasureTheory +namespace SKRatio.Certificate.Data.J2K0 + +def expression : Expr := integrandExpr (89/200) (52021/62500) (13423/25000) (21477/200000) (81561/125000) 0 +def blocks : ℕ → Box + | 0 => ⟨-1/1000000,1/1000000⟩ + | 1 => ⟨-1/1000000,1/1000000⟩ + | 2 => ⟨-1/1000000,1/1000000⟩ + | 3 => ⟨-1/1000000,1/1000000⟩ + | 4 => ⟨-1/1000000,1/1000000⟩ + | 5 => ⟨-1/1000000,1/1000000⟩ + | 6 => ⟨-1/1000000,1/1000000⟩ + | 7 => ⟨-1/1000000,1/1000000⟩ + | 8 => ⟨-1/1000000,1/1000000⟩ + | 9 => ⟨-1/1000000,1/1000000⟩ + | 10 => ⟨0,1/1000000⟩ + | 11 => ⟨9/1000000,11/1000000⟩ + | 12 => ⟨101/1000000,107/1000000⟩ + | 13 => ⟨827/1000000,853/1000000⟩ + | 14 => ⟨511/100000,2609/500000⟩ + | 15 => ⟨4741/200000,24017/1000000⟩ + | 16 => ⟨4071/50000,81981/1000000⟩ + | 17 => ⟨102009/500000,20447/100000⟩ + | 18 => ⟨14707/40000,184081/500000⟩ + | 19 => ⟨473169/1000000,237137/500000⟩ + | 20 => ⟨217631/500000,21807/50000⟩ + | 21 => ⟨57617/200000,288453/1000000⟩ + | 22 => ⟨138603/1000000,69631/500000⟩ + | 23 => ⟨4923/100000,49781/1000000⟩ + | 24 => ⟨3273/250000,13367/1000000⟩ + | 25 => ⟨527/200000,683/250000⟩ + | 26 => ⟨101/250000,43/100000⟩ + | 27 => ⟨47/1000000,53/1000000⟩ + | 28 => ⟨1/250000,3/500000⟩ + | 29 => ⟨0,1/1000000⟩ + | 30 => ⟨-1/1000000,1/1000000⟩ + | 31 => ⟨-1/1000000,1/1000000⟩ + | 32 => ⟨-1/1000000,1/1000000⟩ + | 33 => ⟨-1/1000000,1/1000000⟩ + | 34 => ⟨-1/1000000,1/1000000⟩ + | 35 => ⟨-1/1000000,1/1000000⟩ + | 36 => ⟨-1/1000000,1/1000000⟩ + | 37 => ⟨-1/1000000,1/1000000⟩ + | 38 => ⟨-1/1000000,1/1000000⟩ + | 39 => ⟨-1/1000000,1/1000000⟩ + | _ => Box.rat 0 + +lemma check_0 : expression.check (-10+(0:ℚ)*(5*(1/10))) (1/10) 5 (blocks 0) = true := by decide +kernel +lemma check_1 : expression.check (-10+(1:ℚ)*(5*(1/10))) (1/10) 5 (blocks 1) = true := by decide +kernel +lemma check_2 : expression.check (-10+(2:ℚ)*(5*(1/10))) (1/10) 5 (blocks 2) = true := by decide +kernel +lemma check_3 : expression.check (-10+(3:ℚ)*(5*(1/10))) (1/10) 5 (blocks 3) = true := by decide +kernel +lemma check_4 : expression.check (-10+(4:ℚ)*(5*(1/10))) (1/10) 5 (blocks 4) = true := by decide +kernel +lemma check_5 : expression.check (-10+(5:ℚ)*(5*(1/10))) (1/10) 5 (blocks 5) = true := by decide +kernel +lemma check_6 : expression.check (-10+(6:ℚ)*(5*(1/10))) (1/10) 5 (blocks 6) = true := by decide +kernel +lemma check_7 : expression.check (-10+(7:ℚ)*(5*(1/10))) (1/10) 5 (blocks 7) = true := by decide +kernel +lemma check_8 : expression.check (-10+(8:ℚ)*(5*(1/10))) (1/10) 5 (blocks 8) = true := by decide +kernel +lemma check_9 : expression.check (-10+(9:ℚ)*(5*(1/10))) (1/10) 5 (blocks 9) = true := by decide +kernel +lemma check_10 : expression.check (-10+(10:ℚ)*(5*(1/10))) (1/10) 5 (blocks 10) = true := by decide +kernel +lemma check_11 : expression.check (-10+(11:ℚ)*(5*(1/10))) (1/10) 5 (blocks 11) = true := by decide +kernel +lemma check_12 : expression.check (-10+(12:ℚ)*(5*(1/10))) (1/10) 5 (blocks 12) = true := by decide +kernel +lemma check_13 : expression.check (-10+(13:ℚ)*(5*(1/10))) (1/10) 5 (blocks 13) = true := by decide +kernel +lemma check_14 : expression.check (-10+(14:ℚ)*(5*(1/10))) (1/10) 5 (blocks 14) = true := by decide +kernel +lemma check_15 : expression.check (-10+(15:ℚ)*(5*(1/10))) (1/10) 5 (blocks 15) = true := by decide +kernel +lemma check_16 : expression.check (-10+(16:ℚ)*(5*(1/10))) (1/10) 5 (blocks 16) = true := by decide +kernel +lemma check_17 : expression.check (-10+(17:ℚ)*(5*(1/10))) (1/10) 5 (blocks 17) = true := by decide +kernel +lemma check_18 : expression.check (-10+(18:ℚ)*(5*(1/10))) (1/10) 5 (blocks 18) = true := by decide +kernel +lemma check_19 : expression.check (-10+(19:ℚ)*(5*(1/10))) (1/10) 5 (blocks 19) = true := by decide +kernel +lemma check_20 : expression.check (-10+(20:ℚ)*(5*(1/10))) (1/10) 5 (blocks 20) = true := by decide +kernel +lemma check_21 : expression.check (-10+(21:ℚ)*(5*(1/10))) (1/10) 5 (blocks 21) = true := by decide +kernel +lemma check_22 : expression.check (-10+(22:ℚ)*(5*(1/10))) (1/10) 5 (blocks 22) = true := by decide +kernel +lemma check_23 : expression.check (-10+(23:ℚ)*(5*(1/10))) (1/10) 5 (blocks 23) = true := by decide +kernel +lemma check_24 : expression.check (-10+(24:ℚ)*(5*(1/10))) (1/10) 5 (blocks 24) = true := by decide +kernel +lemma check_25 : expression.check (-10+(25:ℚ)*(5*(1/10))) (1/10) 5 (blocks 25) = true := by decide +kernel +lemma check_26 : expression.check (-10+(26:ℚ)*(5*(1/10))) (1/10) 5 (blocks 26) = true := by decide +kernel +lemma check_27 : expression.check (-10+(27:ℚ)*(5*(1/10))) (1/10) 5 (blocks 27) = true := by decide +kernel +lemma check_28 : expression.check (-10+(28:ℚ)*(5*(1/10))) (1/10) 5 (blocks 28) = true := by decide +kernel +lemma check_29 : expression.check (-10+(29:ℚ)*(5*(1/10))) (1/10) 5 (blocks 29) = true := by decide +kernel +lemma check_30 : expression.check (-10+(30:ℚ)*(5*(1/10))) (1/10) 5 (blocks 30) = true := by decide +kernel +lemma check_31 : expression.check (-10+(31:ℚ)*(5*(1/10))) (1/10) 5 (blocks 31) = true := by decide +kernel +lemma check_32 : expression.check (-10+(32:ℚ)*(5*(1/10))) (1/10) 5 (blocks 32) = true := by decide +kernel +lemma check_33 : expression.check (-10+(33:ℚ)*(5*(1/10))) (1/10) 5 (blocks 33) = true := by decide +kernel +lemma check_34 : expression.check (-10+(34:ℚ)*(5*(1/10))) (1/10) 5 (blocks 34) = true := by decide +kernel +lemma check_35 : expression.check (-10+(35:ℚ)*(5*(1/10))) (1/10) 5 (blocks 35) = true := by decide +kernel +lemma check_36 : expression.check (-10+(36:ℚ)*(5*(1/10))) (1/10) 5 (blocks 36) = true := by decide +kernel +lemma check_37 : expression.check (-10+(37:ℚ)*(5*(1/10))) (1/10) 5 (blocks 37) = true := by decide +kernel +lemma check_38 : expression.check (-10+(38:ℚ)*(5*(1/10))) (1/10) 5 (blocks 38) = true := by decide +kernel +lemma check_39 : expression.check (-10+(39:ℚ)*(5*(1/10))) (1/10) 5 (blocks 39) = true := by decide +kernel + +lemma checks (i : ℕ) (hi : i < 40) : + expression.check (-10+(i:ℚ)*(5*(1/10))) (1/10) 5 (blocks i) = true := by + interval_cases i + · exact check_0 + · exact check_1 + · exact check_2 + · exact check_3 + · exact check_4 + · exact check_5 + · exact check_6 + · exact check_7 + · exact check_8 + · exact check_9 + · exact check_10 + · exact check_11 + · exact check_12 + · exact check_13 + · exact check_14 + · exact check_15 + · exact check_16 + · exact check_17 + · exact check_18 + · exact check_19 + · exact check_20 + · exact check_21 + · exact check_22 + · exact check_23 + · exact check_24 + · exact check_25 + · exact check_26 + · exact check_27 + · exact check_28 + · exact check_29 + · exact check_30 + · exact check_31 + · exact check_32 + · exact check_33 + · exact check_34 + · exact check_35 + · exact check_36 + · exact check_37 + · exact check_38 + · exact check_39 + +theorem integral_bound : + (∫ h, scalarFunction (89/200) (52021/62500) (13423/25000) (21477/200000) (81561/125000) 0 h ∂Scalar.fieldLaw (89/200)) ∈ (⟨207709/250000,208459/250000⟩ : Box) := by + apply gaussian_certificate (e := expression) (B := blocks) (h := (1/10)) (k := 5) (by norm_num) + · simpa only [expression,Rat.cast_div,Rat.cast_ofNat,Rat.cast_one,Rat.cast_zero] using integrandExpr_val (89/200) (52021/62500) (13423/25000) (21477/200000) (81561/125000) 0 + · exact (continuous_scalarFunction _ _ _ _ _ _).measurable + · intro x + apply scalarFunction_bound <;> norm_num + · exact checks + · decide +kernel + +end SKRatio.Certificate.Data.J2K0 + +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Certificates/ScalarDataJ2K1.lean b/lean/OAI/Probability/SKRatio/Certificates/ScalarDataJ2K1.lean new file mode 100644 index 0000000000000000000000000000000000000000..502734430420bbeb041e5aebef5300ba9a74d414 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Certificates/ScalarDataJ2K1.lean @@ -0,0 +1,154 @@ +import Mathlib +import OAI.Probability.SKRatio.Certificates.CertifiedBatches +import OAI.Probability.SKRatio.Certificates.CertifiedFunctionBounds + +namespace OAI + +noncomputable section +open Real MeasureTheory +namespace SKRatio.Certificate.Data.J2K1 + +def expression : Expr := integrandExpr (89/200) (52021/62500) (13423/25000) (21477/200000) (81561/125000) 1 +def blocks : ℕ → Box + | 0 => ⟨-1/1000000,1/1000000⟩ + | 1 => ⟨-1/1000000,1/1000000⟩ + | 2 => ⟨-1/1000000,1/1000000⟩ + | 3 => ⟨-1/1000000,1/1000000⟩ + | 4 => ⟨-1/1000000,1/1000000⟩ + | 5 => ⟨-1/1000000,1/1000000⟩ + | 6 => ⟨-1/1000000,1/1000000⟩ + | 7 => ⟨-1/1000000,1/1000000⟩ + | 8 => ⟨-1/1000000,1/1000000⟩ + | 9 => ⟨-1/1000000,1/1000000⟩ + | 10 => ⟨0,1/1000000⟩ + | 11 => ⟨3/1000000,1/250000⟩ + | 12 => ⟨19/500000,41/1000000⟩ + | 13 => ⟨319/1000000,33/100000⟩ + | 14 => ⟨2037/1000000,2083/1000000⟩ + | 15 => ⟨2469/250000,10021/1000000⟩ + | 16 => ⟨18041/500000,1137/31250⟩ + | 17 => ⟨24537/250000,19699/200000⟩ + | 18 => ⟨196257/1000000,196459/1000000⟩ + | 19 => ⟨285153/1000000,142877/500000⟩ + | 20 => ⟨29937/100000,300131/1000000⟩ + | 21 => ⟨56613/250000,226887/1000000⟩ + | 22 => ⟨24687/200000,123957/1000000⟩ + | 23 => ⟨24387/500000,4933/100000⟩ + | 24 => ⟨3531/250000,2889/200000⟩ + | 25 => ⟨303/100000,631/200000⟩ + | 26 => ⟨243/500000,261/500000⟩ + | 27 => ⟨29/500000,67/1000000⟩ + | 28 => ⟨1/200000,7/1000000⟩ + | 29 => ⟨0,1/1000000⟩ + | 30 => ⟨-1/1000000,1/1000000⟩ + | 31 => ⟨-1/1000000,1/1000000⟩ + | 32 => ⟨-1/1000000,1/1000000⟩ + | 33 => ⟨-1/1000000,1/1000000⟩ + | 34 => ⟨-1/1000000,1/1000000⟩ + | 35 => ⟨-1/1000000,1/1000000⟩ + | 36 => ⟨-1/1000000,1/1000000⟩ + | 37 => ⟨-1/1000000,1/1000000⟩ + | 38 => ⟨-1/1000000,1/1000000⟩ + | 39 => ⟨-1/1000000,1/1000000⟩ + | _ => Box.rat 0 + +lemma check_0 : expression.check (-10+(0:ℚ)*(5*(1/10))) (1/10) 5 (blocks 0) = true := by decide +kernel +lemma check_1 : expression.check (-10+(1:ℚ)*(5*(1/10))) (1/10) 5 (blocks 1) = true := by decide +kernel +lemma check_2 : expression.check (-10+(2:ℚ)*(5*(1/10))) (1/10) 5 (blocks 2) = true := by decide +kernel +lemma check_3 : expression.check (-10+(3:ℚ)*(5*(1/10))) (1/10) 5 (blocks 3) = true := by decide +kernel +lemma check_4 : expression.check (-10+(4:ℚ)*(5*(1/10))) (1/10) 5 (blocks 4) = true := by decide +kernel +lemma check_5 : expression.check (-10+(5:ℚ)*(5*(1/10))) (1/10) 5 (blocks 5) = true := by decide +kernel +lemma check_6 : expression.check (-10+(6:ℚ)*(5*(1/10))) (1/10) 5 (blocks 6) = true := by decide +kernel +lemma check_7 : expression.check (-10+(7:ℚ)*(5*(1/10))) (1/10) 5 (blocks 7) = true := by decide +kernel +lemma check_8 : expression.check (-10+(8:ℚ)*(5*(1/10))) (1/10) 5 (blocks 8) = true := by decide +kernel +lemma check_9 : expression.check (-10+(9:ℚ)*(5*(1/10))) (1/10) 5 (blocks 9) = true := by decide +kernel +lemma check_10 : expression.check (-10+(10:ℚ)*(5*(1/10))) (1/10) 5 (blocks 10) = true := by decide +kernel +lemma check_11 : expression.check (-10+(11:ℚ)*(5*(1/10))) (1/10) 5 (blocks 11) = true := by decide +kernel +lemma check_12 : expression.check (-10+(12:ℚ)*(5*(1/10))) (1/10) 5 (blocks 12) = true := by decide +kernel +lemma check_13 : expression.check (-10+(13:ℚ)*(5*(1/10))) (1/10) 5 (blocks 13) = true := by decide +kernel +lemma check_14 : expression.check (-10+(14:ℚ)*(5*(1/10))) (1/10) 5 (blocks 14) = true := by decide +kernel +lemma check_15 : expression.check (-10+(15:ℚ)*(5*(1/10))) (1/10) 5 (blocks 15) = true := by decide +kernel +lemma check_16 : expression.check (-10+(16:ℚ)*(5*(1/10))) (1/10) 5 (blocks 16) = true := by decide +kernel +lemma check_17 : expression.check (-10+(17:ℚ)*(5*(1/10))) (1/10) 5 (blocks 17) = true := by decide +kernel +lemma check_18 : expression.check (-10+(18:ℚ)*(5*(1/10))) (1/10) 5 (blocks 18) = true := by decide +kernel +lemma check_19 : expression.check (-10+(19:ℚ)*(5*(1/10))) (1/10) 5 (blocks 19) = true := by decide +kernel +lemma check_20 : expression.check (-10+(20:ℚ)*(5*(1/10))) (1/10) 5 (blocks 20) = true := by decide +kernel +lemma check_21 : expression.check (-10+(21:ℚ)*(5*(1/10))) (1/10) 5 (blocks 21) = true := by decide +kernel +lemma check_22 : expression.check (-10+(22:ℚ)*(5*(1/10))) (1/10) 5 (blocks 22) = true := by decide +kernel +lemma check_23 : expression.check (-10+(23:ℚ)*(5*(1/10))) (1/10) 5 (blocks 23) = true := by decide +kernel +lemma check_24 : expression.check (-10+(24:ℚ)*(5*(1/10))) (1/10) 5 (blocks 24) = true := by decide +kernel +lemma check_25 : expression.check (-10+(25:ℚ)*(5*(1/10))) (1/10) 5 (blocks 25) = true := by decide +kernel +lemma check_26 : expression.check (-10+(26:ℚ)*(5*(1/10))) (1/10) 5 (blocks 26) = true := by decide +kernel +lemma check_27 : expression.check (-10+(27:ℚ)*(5*(1/10))) (1/10) 5 (blocks 27) = true := by decide +kernel +lemma check_28 : expression.check (-10+(28:ℚ)*(5*(1/10))) (1/10) 5 (blocks 28) = true := by decide +kernel +lemma check_29 : expression.check (-10+(29:ℚ)*(5*(1/10))) (1/10) 5 (blocks 29) = true := by decide +kernel +lemma check_30 : expression.check (-10+(30:ℚ)*(5*(1/10))) (1/10) 5 (blocks 30) = true := by decide +kernel +lemma check_31 : expression.check (-10+(31:ℚ)*(5*(1/10))) (1/10) 5 (blocks 31) = true := by decide +kernel +lemma check_32 : expression.check (-10+(32:ℚ)*(5*(1/10))) (1/10) 5 (blocks 32) = true := by decide +kernel +lemma check_33 : expression.check (-10+(33:ℚ)*(5*(1/10))) (1/10) 5 (blocks 33) = true := by decide +kernel +lemma check_34 : expression.check (-10+(34:ℚ)*(5*(1/10))) (1/10) 5 (blocks 34) = true := by decide +kernel +lemma check_35 : expression.check (-10+(35:ℚ)*(5*(1/10))) (1/10) 5 (blocks 35) = true := by decide +kernel +lemma check_36 : expression.check (-10+(36:ℚ)*(5*(1/10))) (1/10) 5 (blocks 36) = true := by decide +kernel +lemma check_37 : expression.check (-10+(37:ℚ)*(5*(1/10))) (1/10) 5 (blocks 37) = true := by decide +kernel +lemma check_38 : expression.check (-10+(38:ℚ)*(5*(1/10))) (1/10) 5 (blocks 38) = true := by decide +kernel +lemma check_39 : expression.check (-10+(39:ℚ)*(5*(1/10))) (1/10) 5 (blocks 39) = true := by decide +kernel + +lemma checks (i : ℕ) (hi : i < 40) : + expression.check (-10+(i:ℚ)*(5*(1/10))) (1/10) 5 (blocks i) = true := by + interval_cases i + · exact check_0 + · exact check_1 + · exact check_2 + · exact check_3 + · exact check_4 + · exact check_5 + · exact check_6 + · exact check_7 + · exact check_8 + · exact check_9 + · exact check_10 + · exact check_11 + · exact check_12 + · exact check_13 + · exact check_14 + · exact check_15 + · exact check_16 + · exact check_17 + · exact check_18 + · exact check_19 + · exact check_20 + · exact check_21 + · exact check_22 + · exact check_23 + · exact check_24 + · exact check_25 + · exact check_26 + · exact check_27 + · exact check_28 + · exact check_29 + · exact check_30 + · exact check_31 + · exact check_32 + · exact check_33 + · exact check_34 + · exact check_35 + · exact check_36 + · exact check_37 + · exact check_38 + · exact check_39 + +theorem integral_bound : + (∫ h, scalarFunction (89/200) (52021/62500) (13423/25000) (21477/200000) (81561/125000) 1 h ∂Scalar.fieldLaw (89/200)) ∈ (⟨26771/50000,26921/50000⟩ : Box) := by + apply gaussian_certificate (e := expression) (B := blocks) (h := (1/10)) (k := 5) (by norm_num) + · simpa only [expression,Rat.cast_div,Rat.cast_ofNat,Rat.cast_one,Rat.cast_zero] using integrandExpr_val (89/200) (52021/62500) (13423/25000) (21477/200000) (81561/125000) 1 + · exact (continuous_scalarFunction _ _ _ _ _ _).measurable + · intro x + apply scalarFunction_bound <;> norm_num + · exact checks + · decide +kernel + +end SKRatio.Certificate.Data.J2K1 + +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Certificates/ScalarDataJ2K2.lean b/lean/OAI/Probability/SKRatio/Certificates/ScalarDataJ2K2.lean new file mode 100644 index 0000000000000000000000000000000000000000..ab1824e9a10a02cd7d313183e38341ac057f002d --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Certificates/ScalarDataJ2K2.lean @@ -0,0 +1,154 @@ +import Mathlib +import OAI.Probability.SKRatio.Certificates.CertifiedBatches +import OAI.Probability.SKRatio.Certificates.CertifiedFunctionBounds + +namespace OAI + +noncomputable section +open Real MeasureTheory +namespace SKRatio.Certificate.Data.J2K2 + +def expression : Expr := integrandExpr (89/200) (52021/62500) (13423/25000) (21477/200000) (81561/125000) 2 +def blocks : ℕ → Box + | 0 => ⟨-1/1000000,1/1000000⟩ + | 1 => ⟨-1/1000000,1/1000000⟩ + | 2 => ⟨-1/1000000,1/1000000⟩ + | 3 => ⟨-1/1000000,1/1000000⟩ + | 4 => ⟨-1/1000000,1/1000000⟩ + | 5 => ⟨-1/1000000,1/1000000⟩ + | 6 => ⟨-1/1000000,1/1000000⟩ + | 7 => ⟨-1/1000000,1/1000000⟩ + | 8 => ⟨-1/1000000,1/1000000⟩ + | 9 => ⟨-1/1000000,1/1000000⟩ + | 10 => ⟨-1/1000000,0⟩ + | 11 => ⟨-1/100000,-1/125000⟩ + | 12 => ⟨-19/200000,-9/100000⟩ + | 13 => ⟨-89/125000,-173/250000⟩ + | 14 => ⟨-3947/1000000,-969/250000⟩ + | 15 => ⟨-3889/250000,-1541/100000⟩ + | 16 => ⟨-41393/1000000,-8253/200000⟩ + | 17 => ⟨-33693/500000,-8371/125000⟩ + | 18 => ⟨-46641/1000000,-46029/1000000⟩ + | 19 => ⟨10371/250000,41771/1000000⟩ + | 20 => ⟨12771/100000,2007/15625⟩ + | 21 => ⟨136969/1000000,68799/500000⟩ + | 22 => ⟨86737/1000000,43527/500000⟩ + | 23 => ⟨36433/1000000,3683/100000⟩ + | 24 => ⟨10773/1000000,2203/200000⟩ + | 25 => ⟨29/12500,1207/500000⟩ + | 26 => ⟨371/1000000,199/500000⟩ + | 27 => ⟨11/250000,51/1000000⟩ + | 28 => ⟨3/1000000,3/500000⟩ + | 29 => ⟨0,1/1000000⟩ + | 30 => ⟨-1/1000000,1/1000000⟩ + | 31 => ⟨-1/1000000,1/1000000⟩ + | 32 => ⟨-1/1000000,1/1000000⟩ + | 33 => ⟨-1/1000000,1/1000000⟩ + | 34 => ⟨-1/1000000,1/1000000⟩ + | 35 => ⟨-1/1000000,1/1000000⟩ + | 36 => ⟨-1/1000000,1/1000000⟩ + | 37 => ⟨-1/1000000,1/1000000⟩ + | 38 => ⟨-1/1000000,1/1000000⟩ + | 39 => ⟨-1/1000000,1/1000000⟩ + | _ => Box.rat 0 + +lemma check_0 : expression.check (-10+(0:ℚ)*(5*(1/10))) (1/10) 5 (blocks 0) = true := by decide +kernel +lemma check_1 : expression.check (-10+(1:ℚ)*(5*(1/10))) (1/10) 5 (blocks 1) = true := by decide +kernel +lemma check_2 : expression.check (-10+(2:ℚ)*(5*(1/10))) (1/10) 5 (blocks 2) = true := by decide +kernel +lemma check_3 : expression.check (-10+(3:ℚ)*(5*(1/10))) (1/10) 5 (blocks 3) = true := by decide +kernel +lemma check_4 : expression.check (-10+(4:ℚ)*(5*(1/10))) (1/10) 5 (blocks 4) = true := by decide +kernel +lemma check_5 : expression.check (-10+(5:ℚ)*(5*(1/10))) (1/10) 5 (blocks 5) = true := by decide +kernel +lemma check_6 : expression.check (-10+(6:ℚ)*(5*(1/10))) (1/10) 5 (blocks 6) = true := by decide +kernel +lemma check_7 : expression.check (-10+(7:ℚ)*(5*(1/10))) (1/10) 5 (blocks 7) = true := by decide +kernel +lemma check_8 : expression.check (-10+(8:ℚ)*(5*(1/10))) (1/10) 5 (blocks 8) = true := by decide +kernel +lemma check_9 : expression.check (-10+(9:ℚ)*(5*(1/10))) (1/10) 5 (blocks 9) = true := by decide +kernel +lemma check_10 : expression.check (-10+(10:ℚ)*(5*(1/10))) (1/10) 5 (blocks 10) = true := by decide +kernel +lemma check_11 : expression.check (-10+(11:ℚ)*(5*(1/10))) (1/10) 5 (blocks 11) = true := by decide +kernel +lemma check_12 : expression.check (-10+(12:ℚ)*(5*(1/10))) (1/10) 5 (blocks 12) = true := by decide +kernel +lemma check_13 : expression.check (-10+(13:ℚ)*(5*(1/10))) (1/10) 5 (blocks 13) = true := by decide +kernel +lemma check_14 : expression.check (-10+(14:ℚ)*(5*(1/10))) (1/10) 5 (blocks 14) = true := by decide +kernel +lemma check_15 : expression.check (-10+(15:ℚ)*(5*(1/10))) (1/10) 5 (blocks 15) = true := by decide +kernel +lemma check_16 : expression.check (-10+(16:ℚ)*(5*(1/10))) (1/10) 5 (blocks 16) = true := by decide +kernel +lemma check_17 : expression.check (-10+(17:ℚ)*(5*(1/10))) (1/10) 5 (blocks 17) = true := by decide +kernel +lemma check_18 : expression.check (-10+(18:ℚ)*(5*(1/10))) (1/10) 5 (blocks 18) = true := by decide +kernel +lemma check_19 : expression.check (-10+(19:ℚ)*(5*(1/10))) (1/10) 5 (blocks 19) = true := by decide +kernel +lemma check_20 : expression.check (-10+(20:ℚ)*(5*(1/10))) (1/10) 5 (blocks 20) = true := by decide +kernel +lemma check_21 : expression.check (-10+(21:ℚ)*(5*(1/10))) (1/10) 5 (blocks 21) = true := by decide +kernel +lemma check_22 : expression.check (-10+(22:ℚ)*(5*(1/10))) (1/10) 5 (blocks 22) = true := by decide +kernel +lemma check_23 : expression.check (-10+(23:ℚ)*(5*(1/10))) (1/10) 5 (blocks 23) = true := by decide +kernel +lemma check_24 : expression.check (-10+(24:ℚ)*(5*(1/10))) (1/10) 5 (blocks 24) = true := by decide +kernel +lemma check_25 : expression.check (-10+(25:ℚ)*(5*(1/10))) (1/10) 5 (blocks 25) = true := by decide +kernel +lemma check_26 : expression.check (-10+(26:ℚ)*(5*(1/10))) (1/10) 5 (blocks 26) = true := by decide +kernel +lemma check_27 : expression.check (-10+(27:ℚ)*(5*(1/10))) (1/10) 5 (blocks 27) = true := by decide +kernel +lemma check_28 : expression.check (-10+(28:ℚ)*(5*(1/10))) (1/10) 5 (blocks 28) = true := by decide +kernel +lemma check_29 : expression.check (-10+(29:ℚ)*(5*(1/10))) (1/10) 5 (blocks 29) = true := by decide +kernel +lemma check_30 : expression.check (-10+(30:ℚ)*(5*(1/10))) (1/10) 5 (blocks 30) = true := by decide +kernel +lemma check_31 : expression.check (-10+(31:ℚ)*(5*(1/10))) (1/10) 5 (blocks 31) = true := by decide +kernel +lemma check_32 : expression.check (-10+(32:ℚ)*(5*(1/10))) (1/10) 5 (blocks 32) = true := by decide +kernel +lemma check_33 : expression.check (-10+(33:ℚ)*(5*(1/10))) (1/10) 5 (blocks 33) = true := by decide +kernel +lemma check_34 : expression.check (-10+(34:ℚ)*(5*(1/10))) (1/10) 5 (blocks 34) = true := by decide +kernel +lemma check_35 : expression.check (-10+(35:ℚ)*(5*(1/10))) (1/10) 5 (blocks 35) = true := by decide +kernel +lemma check_36 : expression.check (-10+(36:ℚ)*(5*(1/10))) (1/10) 5 (blocks 36) = true := by decide +kernel +lemma check_37 : expression.check (-10+(37:ℚ)*(5*(1/10))) (1/10) 5 (blocks 37) = true := by decide +kernel +lemma check_38 : expression.check (-10+(38:ℚ)*(5*(1/10))) (1/10) 5 (blocks 38) = true := by decide +kernel +lemma check_39 : expression.check (-10+(39:ℚ)*(5*(1/10))) (1/10) 5 (blocks 39) = true := by decide +kernel + +lemma checks (i : ℕ) (hi : i < 40) : + expression.check (-10+(i:ℚ)*(5*(1/10))) (1/10) 5 (blocks i) = true := by + interval_cases i + · exact check_0 + · exact check_1 + · exact check_2 + · exact check_3 + · exact check_4 + · exact check_5 + · exact check_6 + · exact check_7 + · exact check_8 + · exact check_9 + · exact check_10 + · exact check_11 + · exact check_12 + · exact check_13 + · exact check_14 + · exact check_15 + · exact check_16 + · exact check_17 + · exact check_18 + · exact check_19 + · exact check_20 + · exact check_21 + · exact check_22 + · exact check_23 + · exact check_24 + · exact check_25 + · exact check_26 + · exact check_27 + · exact check_28 + · exact check_29 + · exact check_30 + · exact check_31 + · exact check_32 + · exact check_33 + · exact check_34 + · exact check_35 + · exact check_36 + · exact check_37 + · exact check_38 + · exact check_39 + +theorem integral_bound : + (∫ h, scalarFunction (89/200) (52021/62500) (13423/25000) (21477/200000) (81561/125000) 2 h ∂Scalar.fieldLaw (89/200)) ∈ (⟨21177/200000,21777/200000⟩ : Box) := by + apply gaussian_certificate (e := expression) (B := blocks) (h := (1/10)) (k := 5) (by norm_num) + · simpa only [expression,Rat.cast_div,Rat.cast_ofNat,Rat.cast_one,Rat.cast_zero] using integrandExpr_val (89/200) (52021/62500) (13423/25000) (21477/200000) (81561/125000) 2 + · exact (continuous_scalarFunction _ _ _ _ _ _).measurable + · intro x + apply scalarFunction_bound <;> norm_num + · exact checks + · decide +kernel + +end SKRatio.Certificate.Data.J2K2 + +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Certificates/ScalarDataJ2K3.lean b/lean/OAI/Probability/SKRatio/Certificates/ScalarDataJ2K3.lean new file mode 100644 index 0000000000000000000000000000000000000000..6d7aeec07095b007a478256d2cf6f92f61ed68be --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Certificates/ScalarDataJ2K3.lean @@ -0,0 +1,154 @@ +import Mathlib +import OAI.Probability.SKRatio.Certificates.CertifiedBatches +import OAI.Probability.SKRatio.Certificates.CertifiedFunctionBounds + +namespace OAI + +noncomputable section +open Real MeasureTheory +namespace SKRatio.Certificate.Data.J2K3 + +def expression : Expr := integrandExpr (89/200) (52021/62500) (13423/25000) (21477/200000) (81561/125000) 3 +def blocks : ℕ → Box + | 0 => ⟨-1/1000000,1/1000000⟩ + | 1 => ⟨-1/1000000,1/1000000⟩ + | 2 => ⟨-1/1000000,1/1000000⟩ + | 3 => ⟨-1/1000000,1/1000000⟩ + | 4 => ⟨-1/1000000,1/1000000⟩ + | 5 => ⟨-1/1000000,1/1000000⟩ + | 6 => ⟨-1/1000000,1/1000000⟩ + | 7 => ⟨-1/1000000,1/1000000⟩ + | 8 => ⟨-1/1000000,1/1000000⟩ + | 9 => ⟨-1/1000000,1/1000000⟩ + | 10 => ⟨-1/1000000,1/1000000⟩ + | 11 => ⟨-1/1000000,1/1000000⟩ + | 12 => ⟨0,1/500000⟩ + | 13 => ⟨11/1000000,13/1000000⟩ + | 14 => ⟨97/1000000,13/125000⟩ + | 15 => ⟨573/1000000,597/1000000⟩ + | 16 => ⟨2221/1000000,91/40000⟩ + | 17 => ⟨521/100000,5299/1000000⟩ + | 18 => ⟨1579/250000,6459/1000000⟩ + | 19 => ⟨2523/1000000,671/250000⟩ + | 20 => ⟨647/1000000,519/500000⟩ + | 21 => ⟨357/50000,1939/250000⟩ + | 22 => ⟨2527/200000,269/20000⟩ + | 23 => ⟨4979/500000,5311/500000⟩ + | 24 => ⟨4483/1000000,241/50000⟩ + | 25 => ⟨1283/1000000,351/250000⟩ + | 26 => ⟨247/1000000,141/500000⟩ + | 27 => ⟨33/1000000,21/500000⟩ + | 28 => ⟨1/500000,1/200000⟩ + | 29 => ⟨0,1/1000000⟩ + | 30 => ⟨-1/1000000,1/1000000⟩ + | 31 => ⟨-1/1000000,1/1000000⟩ + | 32 => ⟨-1/1000000,1/1000000⟩ + | 33 => ⟨-1/1000000,1/1000000⟩ + | 34 => ⟨-1/1000000,1/1000000⟩ + | 35 => ⟨-1/1000000,1/1000000⟩ + | 36 => ⟨-1/1000000,1/1000000⟩ + | 37 => ⟨-1/1000000,1/1000000⟩ + | 38 => ⟨-1/1000000,1/1000000⟩ + | 39 => ⟨-1/1000000,1/1000000⟩ + | _ => Box.rat 0 + +lemma check_0 : expression.check (-10+(0:ℚ)*(5*(1/10))) (1/10) 5 (blocks 0) = true := by decide +kernel +lemma check_1 : expression.check (-10+(1:ℚ)*(5*(1/10))) (1/10) 5 (blocks 1) = true := by decide +kernel +lemma check_2 : expression.check (-10+(2:ℚ)*(5*(1/10))) (1/10) 5 (blocks 2) = true := by decide +kernel +lemma check_3 : expression.check (-10+(3:ℚ)*(5*(1/10))) (1/10) 5 (blocks 3) = true := by decide +kernel +lemma check_4 : expression.check (-10+(4:ℚ)*(5*(1/10))) (1/10) 5 (blocks 4) = true := by decide +kernel +lemma check_5 : expression.check (-10+(5:ℚ)*(5*(1/10))) (1/10) 5 (blocks 5) = true := by decide +kernel +lemma check_6 : expression.check (-10+(6:ℚ)*(5*(1/10))) (1/10) 5 (blocks 6) = true := by decide +kernel +lemma check_7 : expression.check (-10+(7:ℚ)*(5*(1/10))) (1/10) 5 (blocks 7) = true := by decide +kernel +lemma check_8 : expression.check (-10+(8:ℚ)*(5*(1/10))) (1/10) 5 (blocks 8) = true := by decide +kernel +lemma check_9 : expression.check (-10+(9:ℚ)*(5*(1/10))) (1/10) 5 (blocks 9) = true := by decide +kernel +lemma check_10 : expression.check (-10+(10:ℚ)*(5*(1/10))) (1/10) 5 (blocks 10) = true := by decide +kernel +lemma check_11 : expression.check (-10+(11:ℚ)*(5*(1/10))) (1/10) 5 (blocks 11) = true := by decide +kernel +lemma check_12 : expression.check (-10+(12:ℚ)*(5*(1/10))) (1/10) 5 (blocks 12) = true := by decide +kernel +lemma check_13 : expression.check (-10+(13:ℚ)*(5*(1/10))) (1/10) 5 (blocks 13) = true := by decide +kernel +lemma check_14 : expression.check (-10+(14:ℚ)*(5*(1/10))) (1/10) 5 (blocks 14) = true := by decide +kernel +lemma check_15 : expression.check (-10+(15:ℚ)*(5*(1/10))) (1/10) 5 (blocks 15) = true := by decide +kernel +lemma check_16 : expression.check (-10+(16:ℚ)*(5*(1/10))) (1/10) 5 (blocks 16) = true := by decide +kernel +lemma check_17 : expression.check (-10+(17:ℚ)*(5*(1/10))) (1/10) 5 (blocks 17) = true := by decide +kernel +lemma check_18 : expression.check (-10+(18:ℚ)*(5*(1/10))) (1/10) 5 (blocks 18) = true := by decide +kernel +lemma check_19 : expression.check (-10+(19:ℚ)*(5*(1/10))) (1/10) 5 (blocks 19) = true := by decide +kernel +lemma check_20 : expression.check (-10+(20:ℚ)*(5*(1/10))) (1/10) 5 (blocks 20) = true := by decide +kernel +lemma check_21 : expression.check (-10+(21:ℚ)*(5*(1/10))) (1/10) 5 (blocks 21) = true := by decide +kernel +lemma check_22 : expression.check (-10+(22:ℚ)*(5*(1/10))) (1/10) 5 (blocks 22) = true := by decide +kernel +lemma check_23 : expression.check (-10+(23:ℚ)*(5*(1/10))) (1/10) 5 (blocks 23) = true := by decide +kernel +lemma check_24 : expression.check (-10+(24:ℚ)*(5*(1/10))) (1/10) 5 (blocks 24) = true := by decide +kernel +lemma check_25 : expression.check (-10+(25:ℚ)*(5*(1/10))) (1/10) 5 (blocks 25) = true := by decide +kernel +lemma check_26 : expression.check (-10+(26:ℚ)*(5*(1/10))) (1/10) 5 (blocks 26) = true := by decide +kernel +lemma check_27 : expression.check (-10+(27:ℚ)*(5*(1/10))) (1/10) 5 (blocks 27) = true := by decide +kernel +lemma check_28 : expression.check (-10+(28:ℚ)*(5*(1/10))) (1/10) 5 (blocks 28) = true := by decide +kernel +lemma check_29 : expression.check (-10+(29:ℚ)*(5*(1/10))) (1/10) 5 (blocks 29) = true := by decide +kernel +lemma check_30 : expression.check (-10+(30:ℚ)*(5*(1/10))) (1/10) 5 (blocks 30) = true := by decide +kernel +lemma check_31 : expression.check (-10+(31:ℚ)*(5*(1/10))) (1/10) 5 (blocks 31) = true := by decide +kernel +lemma check_32 : expression.check (-10+(32:ℚ)*(5*(1/10))) (1/10) 5 (blocks 32) = true := by decide +kernel +lemma check_33 : expression.check (-10+(33:ℚ)*(5*(1/10))) (1/10) 5 (blocks 33) = true := by decide +kernel +lemma check_34 : expression.check (-10+(34:ℚ)*(5*(1/10))) (1/10) 5 (blocks 34) = true := by decide +kernel +lemma check_35 : expression.check (-10+(35:ℚ)*(5*(1/10))) (1/10) 5 (blocks 35) = true := by decide +kernel +lemma check_36 : expression.check (-10+(36:ℚ)*(5*(1/10))) (1/10) 5 (blocks 36) = true := by decide +kernel +lemma check_37 : expression.check (-10+(37:ℚ)*(5*(1/10))) (1/10) 5 (blocks 37) = true := by decide +kernel +lemma check_38 : expression.check (-10+(38:ℚ)*(5*(1/10))) (1/10) 5 (blocks 38) = true := by decide +kernel +lemma check_39 : expression.check (-10+(39:ℚ)*(5*(1/10))) (1/10) 5 (blocks 39) = true := by decide +kernel + +lemma checks (i : ℕ) (hi : i < 40) : + expression.check (-10+(i:ℚ)*(5*(1/10))) (1/10) 5 (blocks i) = true := by + interval_cases i + · exact check_0 + · exact check_1 + · exact check_2 + · exact check_3 + · exact check_4 + · exact check_5 + · exact check_6 + · exact check_7 + · exact check_8 + · exact check_9 + · exact check_10 + · exact check_11 + · exact check_12 + · exact check_13 + · exact check_14 + · exact check_15 + · exact check_16 + · exact check_17 + · exact check_18 + · exact check_19 + · exact check_20 + · exact check_21 + · exact check_22 + · exact check_23 + · exact check_24 + · exact check_25 + · exact check_26 + · exact check_27 + · exact check_28 + · exact check_29 + · exact check_30 + · exact check_31 + · exact check_32 + · exact check_33 + · exact check_34 + · exact check_35 + · exact check_36 + · exact check_37 + · exact check_38 + · exact check_39 + +theorem integral_bound : + (∫ h, scalarFunction (89/200) (52021/62500) (13423/25000) (21477/200000) (81561/125000) 3 h ∂Scalar.fieldLaw (89/200)) ∈ (⟨0,47/2000⟩ : Box) := by + apply gaussian_certificate (e := expression) (B := blocks) (h := (1/10)) (k := 5) (by norm_num) + · simpa only [expression,Rat.cast_div,Rat.cast_ofNat,Rat.cast_one,Rat.cast_zero] using integrandExpr_val (89/200) (52021/62500) (13423/25000) (21477/200000) (81561/125000) 3 + · exact (continuous_scalarFunction _ _ _ _ _ _).measurable + · intro x + apply scalarFunction_bound <;> norm_num + · exact checks + · decide +kernel + +end SKRatio.Certificate.Data.J2K3 + +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Certificates/ScalarDataJ2K4.lean b/lean/OAI/Probability/SKRatio/Certificates/ScalarDataJ2K4.lean new file mode 100644 index 0000000000000000000000000000000000000000..955152df1d16c44e2c4add4ef2792e1d16691738 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Certificates/ScalarDataJ2K4.lean @@ -0,0 +1,154 @@ +import Mathlib +import OAI.Probability.SKRatio.Certificates.CertifiedBatches +import OAI.Probability.SKRatio.Certificates.CertifiedFunctionBounds + +namespace OAI + +noncomputable section +open Real MeasureTheory +namespace SKRatio.Certificate.Data.J2K4 + +def expression : Expr := integrandExpr (89/200) (52021/62500) (13423/25000) (21477/200000) (81561/125000) 4 +def blocks : ℕ → Box + | 0 => ⟨-1/1000000,1/1000000⟩ + | 1 => ⟨-1/1000000,1/1000000⟩ + | 2 => ⟨-1/1000000,1/1000000⟩ + | 3 => ⟨-1/1000000,1/1000000⟩ + | 4 => ⟨-1/1000000,1/1000000⟩ + | 5 => ⟨-1/1000000,1/1000000⟩ + | 6 => ⟨-1/1000000,1/1000000⟩ + | 7 => ⟨-1/1000000,1/1000000⟩ + | 8 => ⟨-1/1000000,1/1000000⟩ + | 9 => ⟨0,1/1000000⟩ + | 10 => ⟨1/250000,1/200000⟩ + | 11 => ⟨17/500000,9/250000⟩ + | 12 => ⟨99/500000,51/250000⟩ + | 13 => ⟨201/250000,163/200000⟩ + | 14 => ⟨83/40000,2093/1000000⟩ + | 15 => ⟨2857/1000000,2901/1000000⟩ + | 16 => ⟨1217/1000000,63/50000⟩ + | 17 => ⟨247/250000,1081/1000000⟩ + | 18 => ⟨2057/250000,4149/500000⟩ + | 19 => ⟨2901/250000,733/62500⟩ + | 20 => ⟨3337/1000000,867/250000⟩ + | 21 => ⟨2367/1000000,1283/500000⟩ + | 22 => ⟨1567/125000,3197/250000⟩ + | 23 => ⟨8221/500000,16721/1000000⟩ + | 24 => ⟨10971/1000000,2781/250000⟩ + | 25 => ⟨913/200000,2329/500000⟩ + | 26 => ⟨1303/1000000,21/15625⟩ + | 27 => ⟨67/250000,281/1000000⟩ + | 28 => ⟨1/25000,11/250000⟩ + | 29 => ⟨1/250000,3/500000⟩ + | 30 => ⟨0,1/1000000⟩ + | 31 => ⟨-1/1000000,1/1000000⟩ + | 32 => ⟨-1/1000000,1/1000000⟩ + | 33 => ⟨-1/1000000,1/1000000⟩ + | 34 => ⟨-1/1000000,1/1000000⟩ + | 35 => ⟨-1/1000000,1/1000000⟩ + | 36 => ⟨-1/1000000,1/1000000⟩ + | 37 => ⟨-1/1000000,1/1000000⟩ + | 38 => ⟨-1/1000000,1/1000000⟩ + | 39 => ⟨-1/1000000,1/1000000⟩ + | _ => Box.rat 0 + +lemma check_0 : expression.check (-10+(0:ℚ)*(5*(1/10))) (1/10) 5 (blocks 0) = true := by decide +kernel +lemma check_1 : expression.check (-10+(1:ℚ)*(5*(1/10))) (1/10) 5 (blocks 1) = true := by decide +kernel +lemma check_2 : expression.check (-10+(2:ℚ)*(5*(1/10))) (1/10) 5 (blocks 2) = true := by decide +kernel +lemma check_3 : expression.check (-10+(3:ℚ)*(5*(1/10))) (1/10) 5 (blocks 3) = true := by decide +kernel +lemma check_4 : expression.check (-10+(4:ℚ)*(5*(1/10))) (1/10) 5 (blocks 4) = true := by decide +kernel +lemma check_5 : expression.check (-10+(5:ℚ)*(5*(1/10))) (1/10) 5 (blocks 5) = true := by decide +kernel +lemma check_6 : expression.check (-10+(6:ℚ)*(5*(1/10))) (1/10) 5 (blocks 6) = true := by decide +kernel +lemma check_7 : expression.check (-10+(7:ℚ)*(5*(1/10))) (1/10) 5 (blocks 7) = true := by decide +kernel +lemma check_8 : expression.check (-10+(8:ℚ)*(5*(1/10))) (1/10) 5 (blocks 8) = true := by decide +kernel +lemma check_9 : expression.check (-10+(9:ℚ)*(5*(1/10))) (1/10) 5 (blocks 9) = true := by decide +kernel +lemma check_10 : expression.check (-10+(10:ℚ)*(5*(1/10))) (1/10) 5 (blocks 10) = true := by decide +kernel +lemma check_11 : expression.check (-10+(11:ℚ)*(5*(1/10))) (1/10) 5 (blocks 11) = true := by decide +kernel +lemma check_12 : expression.check (-10+(12:ℚ)*(5*(1/10))) (1/10) 5 (blocks 12) = true := by decide +kernel +lemma check_13 : expression.check (-10+(13:ℚ)*(5*(1/10))) (1/10) 5 (blocks 13) = true := by decide +kernel +lemma check_14 : expression.check (-10+(14:ℚ)*(5*(1/10))) (1/10) 5 (blocks 14) = true := by decide +kernel +lemma check_15 : expression.check (-10+(15:ℚ)*(5*(1/10))) (1/10) 5 (blocks 15) = true := by decide +kernel +lemma check_16 : expression.check (-10+(16:ℚ)*(5*(1/10))) (1/10) 5 (blocks 16) = true := by decide +kernel +lemma check_17 : expression.check (-10+(17:ℚ)*(5*(1/10))) (1/10) 5 (blocks 17) = true := by decide +kernel +lemma check_18 : expression.check (-10+(18:ℚ)*(5*(1/10))) (1/10) 5 (blocks 18) = true := by decide +kernel +lemma check_19 : expression.check (-10+(19:ℚ)*(5*(1/10))) (1/10) 5 (blocks 19) = true := by decide +kernel +lemma check_20 : expression.check (-10+(20:ℚ)*(5*(1/10))) (1/10) 5 (blocks 20) = true := by decide +kernel +lemma check_21 : expression.check (-10+(21:ℚ)*(5*(1/10))) (1/10) 5 (blocks 21) = true := by decide +kernel +lemma check_22 : expression.check (-10+(22:ℚ)*(5*(1/10))) (1/10) 5 (blocks 22) = true := by decide +kernel +lemma check_23 : expression.check (-10+(23:ℚ)*(5*(1/10))) (1/10) 5 (blocks 23) = true := by decide +kernel +lemma check_24 : expression.check (-10+(24:ℚ)*(5*(1/10))) (1/10) 5 (blocks 24) = true := by decide +kernel +lemma check_25 : expression.check (-10+(25:ℚ)*(5*(1/10))) (1/10) 5 (blocks 25) = true := by decide +kernel +lemma check_26 : expression.check (-10+(26:ℚ)*(5*(1/10))) (1/10) 5 (blocks 26) = true := by decide +kernel +lemma check_27 : expression.check (-10+(27:ℚ)*(5*(1/10))) (1/10) 5 (blocks 27) = true := by decide +kernel +lemma check_28 : expression.check (-10+(28:ℚ)*(5*(1/10))) (1/10) 5 (blocks 28) = true := by decide +kernel +lemma check_29 : expression.check (-10+(29:ℚ)*(5*(1/10))) (1/10) 5 (blocks 29) = true := by decide +kernel +lemma check_30 : expression.check (-10+(30:ℚ)*(5*(1/10))) (1/10) 5 (blocks 30) = true := by decide +kernel +lemma check_31 : expression.check (-10+(31:ℚ)*(5*(1/10))) (1/10) 5 (blocks 31) = true := by decide +kernel +lemma check_32 : expression.check (-10+(32:ℚ)*(5*(1/10))) (1/10) 5 (blocks 32) = true := by decide +kernel +lemma check_33 : expression.check (-10+(33:ℚ)*(5*(1/10))) (1/10) 5 (blocks 33) = true := by decide +kernel +lemma check_34 : expression.check (-10+(34:ℚ)*(5*(1/10))) (1/10) 5 (blocks 34) = true := by decide +kernel +lemma check_35 : expression.check (-10+(35:ℚ)*(5*(1/10))) (1/10) 5 (blocks 35) = true := by decide +kernel +lemma check_36 : expression.check (-10+(36:ℚ)*(5*(1/10))) (1/10) 5 (blocks 36) = true := by decide +kernel +lemma check_37 : expression.check (-10+(37:ℚ)*(5*(1/10))) (1/10) 5 (blocks 37) = true := by decide +kernel +lemma check_38 : expression.check (-10+(38:ℚ)*(5*(1/10))) (1/10) 5 (blocks 38) = true := by decide +kernel +lemma check_39 : expression.check (-10+(39:ℚ)*(5*(1/10))) (1/10) 5 (blocks 39) = true := by decide +kernel + +lemma checks (i : ℕ) (hi : i < 40) : + expression.check (-10+(i:ℚ)*(5*(1/10))) (1/10) 5 (blocks i) = true := by + interval_cases i + · exact check_0 + · exact check_1 + · exact check_2 + · exact check_3 + · exact check_4 + · exact check_5 + · exact check_6 + · exact check_7 + · exact check_8 + · exact check_9 + · exact check_10 + · exact check_11 + · exact check_12 + · exact check_13 + · exact check_14 + · exact check_15 + · exact check_16 + · exact check_17 + · exact check_18 + · exact check_19 + · exact check_20 + · exact check_21 + · exact check_22 + · exact check_23 + · exact check_24 + · exact check_25 + · exact check_26 + · exact check_27 + · exact check_28 + · exact check_29 + · exact check_30 + · exact check_31 + · exact check_32 + · exact check_33 + · exact check_34 + · exact check_35 + · exact check_36 + · exact check_37 + · exact check_38 + · exact check_39 + +theorem integral_bound : + (∫ h, scalarFunction (89/200) (52021/62500) (13423/25000) (21477/200000) (81561/125000) 4 h ∂Scalar.fieldLaw (89/200)) ∈ (⟨0,32761/1000000⟩ : Box) := by + apply gaussian_certificate (e := expression) (B := blocks) (h := (1/10)) (k := 5) (by norm_num) + · simpa only [expression,Rat.cast_div,Rat.cast_ofNat,Rat.cast_one,Rat.cast_zero] using integrandExpr_val (89/200) (52021/62500) (13423/25000) (21477/200000) (81561/125000) 4 + · exact (continuous_scalarFunction _ _ _ _ _ _).measurable + · intro x + apply scalarFunction_bound <;> norm_num + · exact checks + · decide +kernel + +end SKRatio.Certificate.Data.J2K4 + +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Certificates/ScalarDataJ2K5.lean b/lean/OAI/Probability/SKRatio/Certificates/ScalarDataJ2K5.lean new file mode 100644 index 0000000000000000000000000000000000000000..16f6911dcb49f9daada57c59e117e9973fe062ec --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Certificates/ScalarDataJ2K5.lean @@ -0,0 +1,154 @@ +import Mathlib +import OAI.Probability.SKRatio.Certificates.CertifiedBatches +import OAI.Probability.SKRatio.Certificates.CertifiedFunctionBounds + +namespace OAI + +noncomputable section +open Real MeasureTheory +namespace SKRatio.Certificate.Data.J2K5 + +def expression : Expr := integrandExpr (89/200) (52021/62500) (13423/25000) (21477/200000) (81561/125000) 5 +def blocks : ℕ → Box + | 0 => ⟨-1/1000000,1/1000000⟩ + | 1 => ⟨-1/1000000,1/1000000⟩ + | 2 => ⟨-1/1000000,1/1000000⟩ + | 3 => ⟨-1/1000000,1/1000000⟩ + | 4 => ⟨-1/1000000,1/1000000⟩ + | 5 => ⟨-1/1000000,1/1000000⟩ + | 6 => ⟨-1/1000000,1/1000000⟩ + | 7 => ⟨-1/1000000,1/1000000⟩ + | 8 => ⟨-1/1000000,1/1000000⟩ + | 9 => ⟨-1/1000000,1/1000000⟩ + | 10 => ⟨1/1000000,3/1000000⟩ + | 11 => ⟨1/62500,9/500000⟩ + | 12 => ⟨53/500000,11/100000⟩ + | 13 => ⟨249/500000,507/1000000⟩ + | 14 => ⟨1661/1000000,419/250000⟩ + | 15 => ⟨37/10000,93/25000⟩ + | 16 => ⟨983/200000,2481/500000⟩ + | 17 => ⟨1493/500000,1511/500000⟩ + | 18 => ⟨161/500000,373/1000000⟩ + | 19 => ⟨873/500000,1783/1000000⟩ + | 20 => ⟨3691/1000000,1883/500000⟩ + | 21 => ⟨53/31250,899/500000⟩ + | 22 => ⟨69/1000000,117/500000⟩ + | 23 => ⟨993/1000000,57/50000⟩ + | 24 => ⟨767/500000,1649/1000000⟩ + | 25 => ⟨97/100000,41/40000⟩ + | 26 => ⟨351/1000000,47/125000⟩ + | 27 => ⟨83/1000000,23/250000⟩ + | 28 => ⟨13/1000000,1/62500⟩ + | 29 => ⟨1/1000000,3/1000000⟩ + | 30 => ⟨-1/1000000,1/1000000⟩ + | 31 => ⟨-1/1000000,1/1000000⟩ + | 32 => ⟨-1/1000000,1/1000000⟩ + | 33 => ⟨-1/1000000,1/1000000⟩ + | 34 => ⟨-1/1000000,1/1000000⟩ + | 35 => ⟨-1/1000000,1/1000000⟩ + | 36 => ⟨-1/1000000,1/1000000⟩ + | 37 => ⟨-1/1000000,1/1000000⟩ + | 38 => ⟨-1/1000000,1/1000000⟩ + | 39 => ⟨-1/1000000,1/1000000⟩ + | _ => Box.rat 0 + +lemma check_0 : expression.check (-10+(0:ℚ)*(5*(1/10))) (1/10) 5 (blocks 0) = true := by decide +kernel +lemma check_1 : expression.check (-10+(1:ℚ)*(5*(1/10))) (1/10) 5 (blocks 1) = true := by decide +kernel +lemma check_2 : expression.check (-10+(2:ℚ)*(5*(1/10))) (1/10) 5 (blocks 2) = true := by decide +kernel +lemma check_3 : expression.check (-10+(3:ℚ)*(5*(1/10))) (1/10) 5 (blocks 3) = true := by decide +kernel +lemma check_4 : expression.check (-10+(4:ℚ)*(5*(1/10))) (1/10) 5 (blocks 4) = true := by decide +kernel +lemma check_5 : expression.check (-10+(5:ℚ)*(5*(1/10))) (1/10) 5 (blocks 5) = true := by decide +kernel +lemma check_6 : expression.check (-10+(6:ℚ)*(5*(1/10))) (1/10) 5 (blocks 6) = true := by decide +kernel +lemma check_7 : expression.check (-10+(7:ℚ)*(5*(1/10))) (1/10) 5 (blocks 7) = true := by decide +kernel +lemma check_8 : expression.check (-10+(8:ℚ)*(5*(1/10))) (1/10) 5 (blocks 8) = true := by decide +kernel +lemma check_9 : expression.check (-10+(9:ℚ)*(5*(1/10))) (1/10) 5 (blocks 9) = true := by decide +kernel +lemma check_10 : expression.check (-10+(10:ℚ)*(5*(1/10))) (1/10) 5 (blocks 10) = true := by decide +kernel +lemma check_11 : expression.check (-10+(11:ℚ)*(5*(1/10))) (1/10) 5 (blocks 11) = true := by decide +kernel +lemma check_12 : expression.check (-10+(12:ℚ)*(5*(1/10))) (1/10) 5 (blocks 12) = true := by decide +kernel +lemma check_13 : expression.check (-10+(13:ℚ)*(5*(1/10))) (1/10) 5 (blocks 13) = true := by decide +kernel +lemma check_14 : expression.check (-10+(14:ℚ)*(5*(1/10))) (1/10) 5 (blocks 14) = true := by decide +kernel +lemma check_15 : expression.check (-10+(15:ℚ)*(5*(1/10))) (1/10) 5 (blocks 15) = true := by decide +kernel +lemma check_16 : expression.check (-10+(16:ℚ)*(5*(1/10))) (1/10) 5 (blocks 16) = true := by decide +kernel +lemma check_17 : expression.check (-10+(17:ℚ)*(5*(1/10))) (1/10) 5 (blocks 17) = true := by decide +kernel +lemma check_18 : expression.check (-10+(18:ℚ)*(5*(1/10))) (1/10) 5 (blocks 18) = true := by decide +kernel +lemma check_19 : expression.check (-10+(19:ℚ)*(5*(1/10))) (1/10) 5 (blocks 19) = true := by decide +kernel +lemma check_20 : expression.check (-10+(20:ℚ)*(5*(1/10))) (1/10) 5 (blocks 20) = true := by decide +kernel +lemma check_21 : expression.check (-10+(21:ℚ)*(5*(1/10))) (1/10) 5 (blocks 21) = true := by decide +kernel +lemma check_22 : expression.check (-10+(22:ℚ)*(5*(1/10))) (1/10) 5 (blocks 22) = true := by decide +kernel +lemma check_23 : expression.check (-10+(23:ℚ)*(5*(1/10))) (1/10) 5 (blocks 23) = true := by decide +kernel +lemma check_24 : expression.check (-10+(24:ℚ)*(5*(1/10))) (1/10) 5 (blocks 24) = true := by decide +kernel +lemma check_25 : expression.check (-10+(25:ℚ)*(5*(1/10))) (1/10) 5 (blocks 25) = true := by decide +kernel +lemma check_26 : expression.check (-10+(26:ℚ)*(5*(1/10))) (1/10) 5 (blocks 26) = true := by decide +kernel +lemma check_27 : expression.check (-10+(27:ℚ)*(5*(1/10))) (1/10) 5 (blocks 27) = true := by decide +kernel +lemma check_28 : expression.check (-10+(28:ℚ)*(5*(1/10))) (1/10) 5 (blocks 28) = true := by decide +kernel +lemma check_29 : expression.check (-10+(29:ℚ)*(5*(1/10))) (1/10) 5 (blocks 29) = true := by decide +kernel +lemma check_30 : expression.check (-10+(30:ℚ)*(5*(1/10))) (1/10) 5 (blocks 30) = true := by decide +kernel +lemma check_31 : expression.check (-10+(31:ℚ)*(5*(1/10))) (1/10) 5 (blocks 31) = true := by decide +kernel +lemma check_32 : expression.check (-10+(32:ℚ)*(5*(1/10))) (1/10) 5 (blocks 32) = true := by decide +kernel +lemma check_33 : expression.check (-10+(33:ℚ)*(5*(1/10))) (1/10) 5 (blocks 33) = true := by decide +kernel +lemma check_34 : expression.check (-10+(34:ℚ)*(5*(1/10))) (1/10) 5 (blocks 34) = true := by decide +kernel +lemma check_35 : expression.check (-10+(35:ℚ)*(5*(1/10))) (1/10) 5 (blocks 35) = true := by decide +kernel +lemma check_36 : expression.check (-10+(36:ℚ)*(5*(1/10))) (1/10) 5 (blocks 36) = true := by decide +kernel +lemma check_37 : expression.check (-10+(37:ℚ)*(5*(1/10))) (1/10) 5 (blocks 37) = true := by decide +kernel +lemma check_38 : expression.check (-10+(38:ℚ)*(5*(1/10))) (1/10) 5 (blocks 38) = true := by decide +kernel +lemma check_39 : expression.check (-10+(39:ℚ)*(5*(1/10))) (1/10) 5 (blocks 39) = true := by decide +kernel + +lemma checks (i : ℕ) (hi : i < 40) : + expression.check (-10+(i:ℚ)*(5*(1/10))) (1/10) 5 (blocks i) = true := by + interval_cases i + · exact check_0 + · exact check_1 + · exact check_2 + · exact check_3 + · exact check_4 + · exact check_5 + · exact check_6 + · exact check_7 + · exact check_8 + · exact check_9 + · exact check_10 + · exact check_11 + · exact check_12 + · exact check_13 + · exact check_14 + · exact check_15 + · exact check_16 + · exact check_17 + · exact check_18 + · exact check_19 + · exact check_20 + · exact check_21 + · exact check_22 + · exact check_23 + · exact check_24 + · exact check_25 + · exact check_26 + · exact check_27 + · exact check_28 + · exact check_29 + · exact check_30 + · exact check_31 + · exact check_32 + · exact check_33 + · exact check_34 + · exact check_35 + · exact check_36 + · exact check_37 + · exact check_38 + · exact check_39 + +theorem integral_bound : + (∫ h, scalarFunction (89/200) (52021/62500) (13423/25000) (21477/200000) (81561/125000) 5 h ∂Scalar.fieldLaw (89/200)) ∈ (⟨0,10609/1000000⟩ : Box) := by + apply gaussian_certificate (e := expression) (B := blocks) (h := (1/10)) (k := 5) (by norm_num) + · simpa only [expression,Rat.cast_div,Rat.cast_ofNat,Rat.cast_one,Rat.cast_zero] using integrandExpr_val (89/200) (52021/62500) (13423/25000) (21477/200000) (81561/125000) 5 + · exact (continuous_scalarFunction _ _ _ _ _ _).measurable + · intro x + apply scalarFunction_bound <;> norm_num + · exact checks + · decide +kernel + +end SKRatio.Certificate.Data.J2K5 + +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Certificates/ScalarDataJ2K6.lean b/lean/OAI/Probability/SKRatio/Certificates/ScalarDataJ2K6.lean new file mode 100644 index 0000000000000000000000000000000000000000..fdd530f31bab8a71873ca5f4216940014c2852bc --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Certificates/ScalarDataJ2K6.lean @@ -0,0 +1,154 @@ +import Mathlib +import OAI.Probability.SKRatio.Certificates.CertifiedBatches +import OAI.Probability.SKRatio.Certificates.CertifiedFunctionBounds + +namespace OAI + +noncomputable section +open Real MeasureTheory +namespace SKRatio.Certificate.Data.J2K6 + +def expression : Expr := integrandExpr (89/200) (52021/62500) (13423/25000) (21477/200000) (81561/125000) 6 +def blocks : ℕ → Box + | 0 => ⟨-1/1000000,1/1000000⟩ + | 1 => ⟨-1/1000000,1/1000000⟩ + | 2 => ⟨-1/1000000,1/1000000⟩ + | 3 => ⟨-1/1000000,1/1000000⟩ + | 4 => ⟨-1/1000000,1/1000000⟩ + | 5 => ⟨-1/1000000,1/1000000⟩ + | 6 => ⟨-1/1000000,1/1000000⟩ + | 7 => ⟨-1/1000000,1/1000000⟩ + | 8 => ⟨-1/1000000,1/1000000⟩ + | 9 => ⟨-1/1000000,1/1000000⟩ + | 10 => ⟨0,1/1000000⟩ + | 11 => ⟨3/1000000,1/200000⟩ + | 12 => ⟨41/1000000,11/250000⟩ + | 13 => ⟨353/1000000,183/500000⟩ + | 14 => ⟨553/250000,113/50000⟩ + | 15 => ⟨4761/500000,77/8000⟩ + | 16 => ⟨25549/1000000,12831/500000⟩ + | 17 => ⟨4607/125000,9293/250000⟩ + | 18 => ⟨10651/500000,2687/125000⟩ + | 19 => ⟨399/200000,2297/1000000⟩ + | 20 => ⟨13057/1000000,531/40000⟩ + | 21 => ⟨3119/125000,12647/500000⟩ + | 22 => ⟨16689/1000000,3379/200000⟩ + | 23 => ⟨2737/500000,5687/1000000⟩ + | 24 => ⟨959/1000000,213/200000⟩ + | 25 => ⟨79/1000000,11/100000⟩ + | 26 => ⟨-1/1000000,7/1000000⟩ + | 27 => ⟨-1/1000000,1/1000000⟩ + | 28 => ⟨-1/1000000,1/1000000⟩ + | 29 => ⟨-1/1000000,1/1000000⟩ + | 30 => ⟨-1/1000000,1/1000000⟩ + | 31 => ⟨-1/1000000,1/1000000⟩ + | 32 => ⟨-1/1000000,1/1000000⟩ + | 33 => ⟨-1/1000000,1/1000000⟩ + | 34 => ⟨-1/1000000,1/1000000⟩ + | 35 => ⟨-1/1000000,1/1000000⟩ + | 36 => ⟨-1/1000000,1/1000000⟩ + | 37 => ⟨-1/1000000,1/1000000⟩ + | 38 => ⟨-1/1000000,1/1000000⟩ + | 39 => ⟨-1/1000000,1/1000000⟩ + | _ => Box.rat 0 + +lemma check_0 : expression.check (-10+(0:ℚ)*(5*(1/10))) (1/10) 5 (blocks 0) = true := by decide +kernel +lemma check_1 : expression.check (-10+(1:ℚ)*(5*(1/10))) (1/10) 5 (blocks 1) = true := by decide +kernel +lemma check_2 : expression.check (-10+(2:ℚ)*(5*(1/10))) (1/10) 5 (blocks 2) = true := by decide +kernel +lemma check_3 : expression.check (-10+(3:ℚ)*(5*(1/10))) (1/10) 5 (blocks 3) = true := by decide +kernel +lemma check_4 : expression.check (-10+(4:ℚ)*(5*(1/10))) (1/10) 5 (blocks 4) = true := by decide +kernel +lemma check_5 : expression.check (-10+(5:ℚ)*(5*(1/10))) (1/10) 5 (blocks 5) = true := by decide +kernel +lemma check_6 : expression.check (-10+(6:ℚ)*(5*(1/10))) (1/10) 5 (blocks 6) = true := by decide +kernel +lemma check_7 : expression.check (-10+(7:ℚ)*(5*(1/10))) (1/10) 5 (blocks 7) = true := by decide +kernel +lemma check_8 : expression.check (-10+(8:ℚ)*(5*(1/10))) (1/10) 5 (blocks 8) = true := by decide +kernel +lemma check_9 : expression.check (-10+(9:ℚ)*(5*(1/10))) (1/10) 5 (blocks 9) = true := by decide +kernel +lemma check_10 : expression.check (-10+(10:ℚ)*(5*(1/10))) (1/10) 5 (blocks 10) = true := by decide +kernel +lemma check_11 : expression.check (-10+(11:ℚ)*(5*(1/10))) (1/10) 5 (blocks 11) = true := by decide +kernel +lemma check_12 : expression.check (-10+(12:ℚ)*(5*(1/10))) (1/10) 5 (blocks 12) = true := by decide +kernel +lemma check_13 : expression.check (-10+(13:ℚ)*(5*(1/10))) (1/10) 5 (blocks 13) = true := by decide +kernel +lemma check_14 : expression.check (-10+(14:ℚ)*(5*(1/10))) (1/10) 5 (blocks 14) = true := by decide +kernel +lemma check_15 : expression.check (-10+(15:ℚ)*(5*(1/10))) (1/10) 5 (blocks 15) = true := by decide +kernel +lemma check_16 : expression.check (-10+(16:ℚ)*(5*(1/10))) (1/10) 5 (blocks 16) = true := by decide +kernel +lemma check_17 : expression.check (-10+(17:ℚ)*(5*(1/10))) (1/10) 5 (blocks 17) = true := by decide +kernel +lemma check_18 : expression.check (-10+(18:ℚ)*(5*(1/10))) (1/10) 5 (blocks 18) = true := by decide +kernel +lemma check_19 : expression.check (-10+(19:ℚ)*(5*(1/10))) (1/10) 5 (blocks 19) = true := by decide +kernel +lemma check_20 : expression.check (-10+(20:ℚ)*(5*(1/10))) (1/10) 5 (blocks 20) = true := by decide +kernel +lemma check_21 : expression.check (-10+(21:ℚ)*(5*(1/10))) (1/10) 5 (blocks 21) = true := by decide +kernel +lemma check_22 : expression.check (-10+(22:ℚ)*(5*(1/10))) (1/10) 5 (blocks 22) = true := by decide +kernel +lemma check_23 : expression.check (-10+(23:ℚ)*(5*(1/10))) (1/10) 5 (blocks 23) = true := by decide +kernel +lemma check_24 : expression.check (-10+(24:ℚ)*(5*(1/10))) (1/10) 5 (blocks 24) = true := by decide +kernel +lemma check_25 : expression.check (-10+(25:ℚ)*(5*(1/10))) (1/10) 5 (blocks 25) = true := by decide +kernel +lemma check_26 : expression.check (-10+(26:ℚ)*(5*(1/10))) (1/10) 5 (blocks 26) = true := by decide +kernel +lemma check_27 : expression.check (-10+(27:ℚ)*(5*(1/10))) (1/10) 5 (blocks 27) = true := by decide +kernel +lemma check_28 : expression.check (-10+(28:ℚ)*(5*(1/10))) (1/10) 5 (blocks 28) = true := by decide +kernel +lemma check_29 : expression.check (-10+(29:ℚ)*(5*(1/10))) (1/10) 5 (blocks 29) = true := by decide +kernel +lemma check_30 : expression.check (-10+(30:ℚ)*(5*(1/10))) (1/10) 5 (blocks 30) = true := by decide +kernel +lemma check_31 : expression.check (-10+(31:ℚ)*(5*(1/10))) (1/10) 5 (blocks 31) = true := by decide +kernel +lemma check_32 : expression.check (-10+(32:ℚ)*(5*(1/10))) (1/10) 5 (blocks 32) = true := by decide +kernel +lemma check_33 : expression.check (-10+(33:ℚ)*(5*(1/10))) (1/10) 5 (blocks 33) = true := by decide +kernel +lemma check_34 : expression.check (-10+(34:ℚ)*(5*(1/10))) (1/10) 5 (blocks 34) = true := by decide +kernel +lemma check_35 : expression.check (-10+(35:ℚ)*(5*(1/10))) (1/10) 5 (blocks 35) = true := by decide +kernel +lemma check_36 : expression.check (-10+(36:ℚ)*(5*(1/10))) (1/10) 5 (blocks 36) = true := by decide +kernel +lemma check_37 : expression.check (-10+(37:ℚ)*(5*(1/10))) (1/10) 5 (blocks 37) = true := by decide +kernel +lemma check_38 : expression.check (-10+(38:ℚ)*(5*(1/10))) (1/10) 5 (blocks 38) = true := by decide +kernel +lemma check_39 : expression.check (-10+(39:ℚ)*(5*(1/10))) (1/10) 5 (blocks 39) = true := by decide +kernel + +lemma checks (i : ℕ) (hi : i < 40) : + expression.check (-10+(i:ℚ)*(5*(1/10))) (1/10) 5 (blocks i) = true := by + interval_cases i + · exact check_0 + · exact check_1 + · exact check_2 + · exact check_3 + · exact check_4 + · exact check_5 + · exact check_6 + · exact check_7 + · exact check_8 + · exact check_9 + · exact check_10 + · exact check_11 + · exact check_12 + · exact check_13 + · exact check_14 + · exact check_15 + · exact check_16 + · exact check_17 + · exact check_18 + · exact check_19 + · exact check_20 + · exact check_21 + · exact check_22 + · exact check_23 + · exact check_24 + · exact check_25 + · exact check_26 + · exact check_27 + · exact check_28 + · exact check_29 + · exact check_30 + · exact check_31 + · exact check_32 + · exact check_33 + · exact check_34 + · exact check_35 + · exact check_36 + · exact check_37 + · exact check_38 + · exact check_39 + +theorem integral_bound : + (∫ h, scalarFunction (89/200) (52021/62500) (13423/25000) (21477/200000) (81561/125000) 6 h ∂Scalar.fieldLaw (89/200)) ∈ (⟨0,16129/250000⟩ : Box) := by + apply gaussian_certificate (e := expression) (B := blocks) (h := (1/10)) (k := 5) (by norm_num) + · simpa only [expression,Rat.cast_div,Rat.cast_ofNat,Rat.cast_one,Rat.cast_zero] using integrandExpr_val (89/200) (52021/62500) (13423/25000) (21477/200000) (81561/125000) 6 + · exact (continuous_scalarFunction _ _ _ _ _ _).measurable + · intro x + apply scalarFunction_bound <;> norm_num + · exact checks + · decide +kernel + +end SKRatio.Certificate.Data.J2K6 + +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Certificates/ScalarDataJ2K7.lean b/lean/OAI/Probability/SKRatio/Certificates/ScalarDataJ2K7.lean new file mode 100644 index 0000000000000000000000000000000000000000..1c24fa3b19dd342476999daeae143596f7453722 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Certificates/ScalarDataJ2K7.lean @@ -0,0 +1,154 @@ +import Mathlib +import OAI.Probability.SKRatio.Certificates.CertifiedBatches +import OAI.Probability.SKRatio.Certificates.CertifiedFunctionBounds + +namespace OAI + +noncomputable section +open Real MeasureTheory +namespace SKRatio.Certificate.Data.J2K7 + +def expression : Expr := integrandExpr (89/200) (52021/62500) (13423/25000) (21477/200000) (81561/125000) 7 +def blocks : ℕ → Box + | 0 => ⟨-1/1000000,1/1000000⟩ + | 1 => ⟨-1/1000000,1/1000000⟩ + | 2 => ⟨-1/1000000,1/1000000⟩ + | 3 => ⟨-1/1000000,1/1000000⟩ + | 4 => ⟨-1/1000000,1/1000000⟩ + | 5 => ⟨-1/1000000,1/1000000⟩ + | 6 => ⟨-1/1000000,1/1000000⟩ + | 7 => ⟨-1/1000000,1/1000000⟩ + | 8 => ⟨0,1/1000000⟩ + | 9 => ⟨1/250000,3/500000⟩ + | 10 => ⟨3/62500,13/250000⟩ + | 11 => ⟨399/1000000,207/500000⟩ + | 12 => ⟨2569/1000000,527/200000⟩ + | 13 => ⟨1283/100000,6529/500000⟩ + | 14 => ⟨12191/250000,493/10000⟩ + | 15 => ⟨67813/500000,13631/100000⟩ + | 16 => ⟨16061/62500,6453/25000⟩ + | 17 => ⟨7353/25000,296147/1000000⟩ + | 18 => ⟨19569/125000,9851/62500⟩ + | 19 => ⟨1947/125000,543/31250⟩ + | 20 => ⟨70169/1000000,1781/25000⟩ + | 21 => ⟨11569/62500,186983/1000000⟩ + | 22 => ⟨186533/1000000,188099/1000000⟩ + | 23 => ⟨22261/200000,112401/1000000⟩ + | 24 => ⟨5811/125000,23713/500000⟩ + | 25 => ⟨3717/250000,7679/500000⟩ + | 26 => ⟨3791/1000000,3973/1000000⟩ + | 27 => ⟨389/500000,83/100000⟩ + | 28 => ⟨127/1000000,7/50000⟩ + | 29 => ⟨1/62500,19/1000000⟩ + | 30 => ⟨1/1000000,3/1000000⟩ + | 31 => ⟨-1/1000000,1/1000000⟩ + | 32 => ⟨-1/1000000,1/1000000⟩ + | 33 => ⟨-1/1000000,1/1000000⟩ + | 34 => ⟨-1/1000000,1/1000000⟩ + | 35 => ⟨-1/1000000,1/1000000⟩ + | 36 => ⟨-1/1000000,1/1000000⟩ + | 37 => ⟨-1/1000000,1/1000000⟩ + | 38 => ⟨-1/1000000,1/1000000⟩ + | 39 => ⟨-1/1000000,1/1000000⟩ + | _ => Box.rat 0 + +lemma check_0 : expression.check (-10+(0:ℚ)*(5*(1/10))) (1/10) 5 (blocks 0) = true := by decide +kernel +lemma check_1 : expression.check (-10+(1:ℚ)*(5*(1/10))) (1/10) 5 (blocks 1) = true := by decide +kernel +lemma check_2 : expression.check (-10+(2:ℚ)*(5*(1/10))) (1/10) 5 (blocks 2) = true := by decide +kernel +lemma check_3 : expression.check (-10+(3:ℚ)*(5*(1/10))) (1/10) 5 (blocks 3) = true := by decide +kernel +lemma check_4 : expression.check (-10+(4:ℚ)*(5*(1/10))) (1/10) 5 (blocks 4) = true := by decide +kernel +lemma check_5 : expression.check (-10+(5:ℚ)*(5*(1/10))) (1/10) 5 (blocks 5) = true := by decide +kernel +lemma check_6 : expression.check (-10+(6:ℚ)*(5*(1/10))) (1/10) 5 (blocks 6) = true := by decide +kernel +lemma check_7 : expression.check (-10+(7:ℚ)*(5*(1/10))) (1/10) 5 (blocks 7) = true := by decide +kernel +lemma check_8 : expression.check (-10+(8:ℚ)*(5*(1/10))) (1/10) 5 (blocks 8) = true := by decide +kernel +lemma check_9 : expression.check (-10+(9:ℚ)*(5*(1/10))) (1/10) 5 (blocks 9) = true := by decide +kernel +lemma check_10 : expression.check (-10+(10:ℚ)*(5*(1/10))) (1/10) 5 (blocks 10) = true := by decide +kernel +lemma check_11 : expression.check (-10+(11:ℚ)*(5*(1/10))) (1/10) 5 (blocks 11) = true := by decide +kernel +lemma check_12 : expression.check (-10+(12:ℚ)*(5*(1/10))) (1/10) 5 (blocks 12) = true := by decide +kernel +lemma check_13 : expression.check (-10+(13:ℚ)*(5*(1/10))) (1/10) 5 (blocks 13) = true := by decide +kernel +lemma check_14 : expression.check (-10+(14:ℚ)*(5*(1/10))) (1/10) 5 (blocks 14) = true := by decide +kernel +lemma check_15 : expression.check (-10+(15:ℚ)*(5*(1/10))) (1/10) 5 (blocks 15) = true := by decide +kernel +lemma check_16 : expression.check (-10+(16:ℚ)*(5*(1/10))) (1/10) 5 (blocks 16) = true := by decide +kernel +lemma check_17 : expression.check (-10+(17:ℚ)*(5*(1/10))) (1/10) 5 (blocks 17) = true := by decide +kernel +lemma check_18 : expression.check (-10+(18:ℚ)*(5*(1/10))) (1/10) 5 (blocks 18) = true := by decide +kernel +lemma check_19 : expression.check (-10+(19:ℚ)*(5*(1/10))) (1/10) 5 (blocks 19) = true := by decide +kernel +lemma check_20 : expression.check (-10+(20:ℚ)*(5*(1/10))) (1/10) 5 (blocks 20) = true := by decide +kernel +lemma check_21 : expression.check (-10+(21:ℚ)*(5*(1/10))) (1/10) 5 (blocks 21) = true := by decide +kernel +lemma check_22 : expression.check (-10+(22:ℚ)*(5*(1/10))) (1/10) 5 (blocks 22) = true := by decide +kernel +lemma check_23 : expression.check (-10+(23:ℚ)*(5*(1/10))) (1/10) 5 (blocks 23) = true := by decide +kernel +lemma check_24 : expression.check (-10+(24:ℚ)*(5*(1/10))) (1/10) 5 (blocks 24) = true := by decide +kernel +lemma check_25 : expression.check (-10+(25:ℚ)*(5*(1/10))) (1/10) 5 (blocks 25) = true := by decide +kernel +lemma check_26 : expression.check (-10+(26:ℚ)*(5*(1/10))) (1/10) 5 (blocks 26) = true := by decide +kernel +lemma check_27 : expression.check (-10+(27:ℚ)*(5*(1/10))) (1/10) 5 (blocks 27) = true := by decide +kernel +lemma check_28 : expression.check (-10+(28:ℚ)*(5*(1/10))) (1/10) 5 (blocks 28) = true := by decide +kernel +lemma check_29 : expression.check (-10+(29:ℚ)*(5*(1/10))) (1/10) 5 (blocks 29) = true := by decide +kernel +lemma check_30 : expression.check (-10+(30:ℚ)*(5*(1/10))) (1/10) 5 (blocks 30) = true := by decide +kernel +lemma check_31 : expression.check (-10+(31:ℚ)*(5*(1/10))) (1/10) 5 (blocks 31) = true := by decide +kernel +lemma check_32 : expression.check (-10+(32:ℚ)*(5*(1/10))) (1/10) 5 (blocks 32) = true := by decide +kernel +lemma check_33 : expression.check (-10+(33:ℚ)*(5*(1/10))) (1/10) 5 (blocks 33) = true := by decide +kernel +lemma check_34 : expression.check (-10+(34:ℚ)*(5*(1/10))) (1/10) 5 (blocks 34) = true := by decide +kernel +lemma check_35 : expression.check (-10+(35:ℚ)*(5*(1/10))) (1/10) 5 (blocks 35) = true := by decide +kernel +lemma check_36 : expression.check (-10+(36:ℚ)*(5*(1/10))) (1/10) 5 (blocks 36) = true := by decide +kernel +lemma check_37 : expression.check (-10+(37:ℚ)*(5*(1/10))) (1/10) 5 (blocks 37) = true := by decide +kernel +lemma check_38 : expression.check (-10+(38:ℚ)*(5*(1/10))) (1/10) 5 (blocks 38) = true := by decide +kernel +lemma check_39 : expression.check (-10+(39:ℚ)*(5*(1/10))) (1/10) 5 (blocks 39) = true := by decide +kernel + +lemma checks (i : ℕ) (hi : i < 40) : + expression.check (-10+(i:ℚ)*(5*(1/10))) (1/10) 5 (blocks i) = true := by + interval_cases i + · exact check_0 + · exact check_1 + · exact check_2 + · exact check_3 + · exact check_4 + · exact check_5 + · exact check_6 + · exact check_7 + · exact check_8 + · exact check_9 + · exact check_10 + · exact check_11 + · exact check_12 + · exact check_13 + · exact check_14 + · exact check_15 + · exact check_16 + · exact check_17 + · exact check_18 + · exact check_19 + · exact check_20 + · exact check_21 + · exact check_22 + · exact check_23 + · exact check_24 + · exact check_25 + · exact check_26 + · exact check_27 + · exact check_28 + · exact check_29 + · exact check_30 + · exact check_31 + · exact check_32 + · exact check_33 + · exact check_34 + · exact check_35 + · exact check_36 + · exact check_37 + · exact check_38 + · exact check_39 + +theorem integral_bound : + (∫ h, scalarFunction (89/200) (52021/62500) (13423/25000) (21477/200000) (81561/125000) 7 h ∂Scalar.fieldLaw (89/200)) ∈ (⟨0,622521/1000000⟩ : Box) := by + apply gaussian_certificate (e := expression) (B := blocks) (h := (1/10)) (k := 5) (by norm_num) + · simpa only [expression,Rat.cast_div,Rat.cast_ofNat,Rat.cast_one,Rat.cast_zero] using integrandExpr_val (89/200) (52021/62500) (13423/25000) (21477/200000) (81561/125000) 7 + · exact (continuous_scalarFunction _ _ _ _ _ _).measurable + · intro x + apply scalarFunction_bound <;> norm_num + · exact checks + · decide +kernel + +end SKRatio.Certificate.Data.J2K7 + +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Certificates/ScalarDataJ3K0.lean b/lean/OAI/Probability/SKRatio/Certificates/ScalarDataJ3K0.lean new file mode 100644 index 0000000000000000000000000000000000000000..7f31eb4270eb126bbca89f5cd363caff8626fa2d --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Certificates/ScalarDataJ3K0.lean @@ -0,0 +1,154 @@ +import Mathlib +import OAI.Probability.SKRatio.Certificates.CertifiedBatches +import OAI.Probability.SKRatio.Certificates.CertifiedFunctionBounds + +namespace OAI + +noncomputable section +open Real MeasureTheory +namespace SKRatio.Certificate.Data.J3K0 + +def expression : Expr := integrandExpr (19/40) (406349/500000) (66273/125000) (28579/250000) (135787/200000) 0 +def blocks : ℕ → Box + | 0 => ⟨-1/1000000,1/1000000⟩ + | 1 => ⟨-1/1000000,1/1000000⟩ + | 2 => ⟨-1/1000000,1/1000000⟩ + | 3 => ⟨-1/1000000,1/1000000⟩ + | 4 => ⟨-1/1000000,1/1000000⟩ + | 5 => ⟨-1/1000000,1/1000000⟩ + | 6 => ⟨-1/1000000,1/1000000⟩ + | 7 => ⟨-1/1000000,1/1000000⟩ + | 8 => ⟨-1/1000000,1/1000000⟩ + | 9 => ⟨-1/1000000,1/1000000⟩ + | 10 => ⟨0,1/1000000⟩ + | 11 => ⟨7/1000000,9/1000000⟩ + | 12 => ⟨87/1000000,23/250000⟩ + | 13 => ⟨737/1000000,761/1000000⟩ + | 14 => ⟨471/100000,4813/1000000⟩ + | 15 => ⟨2253/100000,11421/500000⟩ + | 16 => ⟨79433/1000000,8001/100000⟩ + | 17 => ⟨202701/1000000,203171/1000000⟩ + | 18 => ⟨183977/500000,14739/40000⟩ + | 19 => ⟨235497/500000,472147/1000000⟩ + | 20 => ⟨85153/200000,213319/500000⟩ + | 21 => ⟨274223/1000000,274629/1000000⟩ + | 22 => ⟨127561/1000000,12827/100000⟩ + | 23 => ⟨43669/1000000,44229/1000000⟩ + | 24 => ⟨559/50000,11453/1000000⟩ + | 25 => ⟨433/200000,2261/1000000⟩ + | 26 => ⟨319/1000000,69/200000⟩ + | 27 => ⟨7/200000,21/500000⟩ + | 28 => ⟨1/500000,1/200000⟩ + | 29 => ⟨-1/1000000,1/1000000⟩ + | 30 => ⟨-1/1000000,1/1000000⟩ + | 31 => ⟨-1/1000000,1/1000000⟩ + | 32 => ⟨-1/1000000,1/1000000⟩ + | 33 => ⟨-1/1000000,1/1000000⟩ + | 34 => ⟨-1/1000000,1/1000000⟩ + | 35 => ⟨-1/1000000,1/1000000⟩ + | 36 => ⟨-1/1000000,1/1000000⟩ + | 37 => ⟨-1/1000000,1/1000000⟩ + | 38 => ⟨-1/1000000,1/1000000⟩ + | 39 => ⟨-1/1000000,1/1000000⟩ + | _ => Box.rat 0 + +lemma check_0 : expression.check (-10+(0:ℚ)*(5*(1/10))) (1/10) 5 (blocks 0) = true := by decide +kernel +lemma check_1 : expression.check (-10+(1:ℚ)*(5*(1/10))) (1/10) 5 (blocks 1) = true := by decide +kernel +lemma check_2 : expression.check (-10+(2:ℚ)*(5*(1/10))) (1/10) 5 (blocks 2) = true := by decide +kernel +lemma check_3 : expression.check (-10+(3:ℚ)*(5*(1/10))) (1/10) 5 (blocks 3) = true := by decide +kernel +lemma check_4 : expression.check (-10+(4:ℚ)*(5*(1/10))) (1/10) 5 (blocks 4) = true := by decide +kernel +lemma check_5 : expression.check (-10+(5:ℚ)*(5*(1/10))) (1/10) 5 (blocks 5) = true := by decide +kernel +lemma check_6 : expression.check (-10+(6:ℚ)*(5*(1/10))) (1/10) 5 (blocks 6) = true := by decide +kernel +lemma check_7 : expression.check (-10+(7:ℚ)*(5*(1/10))) (1/10) 5 (blocks 7) = true := by decide +kernel +lemma check_8 : expression.check (-10+(8:ℚ)*(5*(1/10))) (1/10) 5 (blocks 8) = true := by decide +kernel +lemma check_9 : expression.check (-10+(9:ℚ)*(5*(1/10))) (1/10) 5 (blocks 9) = true := by decide +kernel +lemma check_10 : expression.check (-10+(10:ℚ)*(5*(1/10))) (1/10) 5 (blocks 10) = true := by decide +kernel +lemma check_11 : expression.check (-10+(11:ℚ)*(5*(1/10))) (1/10) 5 (blocks 11) = true := by decide +kernel +lemma check_12 : expression.check (-10+(12:ℚ)*(5*(1/10))) (1/10) 5 (blocks 12) = true := by decide +kernel +lemma check_13 : expression.check (-10+(13:ℚ)*(5*(1/10))) (1/10) 5 (blocks 13) = true := by decide +kernel +lemma check_14 : expression.check (-10+(14:ℚ)*(5*(1/10))) (1/10) 5 (blocks 14) = true := by decide +kernel +lemma check_15 : expression.check (-10+(15:ℚ)*(5*(1/10))) (1/10) 5 (blocks 15) = true := by decide +kernel +lemma check_16 : expression.check (-10+(16:ℚ)*(5*(1/10))) (1/10) 5 (blocks 16) = true := by decide +kernel +lemma check_17 : expression.check (-10+(17:ℚ)*(5*(1/10))) (1/10) 5 (blocks 17) = true := by decide +kernel +lemma check_18 : expression.check (-10+(18:ℚ)*(5*(1/10))) (1/10) 5 (blocks 18) = true := by decide +kernel +lemma check_19 : expression.check (-10+(19:ℚ)*(5*(1/10))) (1/10) 5 (blocks 19) = true := by decide +kernel +lemma check_20 : expression.check (-10+(20:ℚ)*(5*(1/10))) (1/10) 5 (blocks 20) = true := by decide +kernel +lemma check_21 : expression.check (-10+(21:ℚ)*(5*(1/10))) (1/10) 5 (blocks 21) = true := by decide +kernel +lemma check_22 : expression.check (-10+(22:ℚ)*(5*(1/10))) (1/10) 5 (blocks 22) = true := by decide +kernel +lemma check_23 : expression.check (-10+(23:ℚ)*(5*(1/10))) (1/10) 5 (blocks 23) = true := by decide +kernel +lemma check_24 : expression.check (-10+(24:ℚ)*(5*(1/10))) (1/10) 5 (blocks 24) = true := by decide +kernel +lemma check_25 : expression.check (-10+(25:ℚ)*(5*(1/10))) (1/10) 5 (blocks 25) = true := by decide +kernel +lemma check_26 : expression.check (-10+(26:ℚ)*(5*(1/10))) (1/10) 5 (blocks 26) = true := by decide +kernel +lemma check_27 : expression.check (-10+(27:ℚ)*(5*(1/10))) (1/10) 5 (blocks 27) = true := by decide +kernel +lemma check_28 : expression.check (-10+(28:ℚ)*(5*(1/10))) (1/10) 5 (blocks 28) = true := by decide +kernel +lemma check_29 : expression.check (-10+(29:ℚ)*(5*(1/10))) (1/10) 5 (blocks 29) = true := by decide +kernel +lemma check_30 : expression.check (-10+(30:ℚ)*(5*(1/10))) (1/10) 5 (blocks 30) = true := by decide +kernel +lemma check_31 : expression.check (-10+(31:ℚ)*(5*(1/10))) (1/10) 5 (blocks 31) = true := by decide +kernel +lemma check_32 : expression.check (-10+(32:ℚ)*(5*(1/10))) (1/10) 5 (blocks 32) = true := by decide +kernel +lemma check_33 : expression.check (-10+(33:ℚ)*(5*(1/10))) (1/10) 5 (blocks 33) = true := by decide +kernel +lemma check_34 : expression.check (-10+(34:ℚ)*(5*(1/10))) (1/10) 5 (blocks 34) = true := by decide +kernel +lemma check_35 : expression.check (-10+(35:ℚ)*(5*(1/10))) (1/10) 5 (blocks 35) = true := by decide +kernel +lemma check_36 : expression.check (-10+(36:ℚ)*(5*(1/10))) (1/10) 5 (blocks 36) = true := by decide +kernel +lemma check_37 : expression.check (-10+(37:ℚ)*(5*(1/10))) (1/10) 5 (blocks 37) = true := by decide +kernel +lemma check_38 : expression.check (-10+(38:ℚ)*(5*(1/10))) (1/10) 5 (blocks 38) = true := by decide +kernel +lemma check_39 : expression.check (-10+(39:ℚ)*(5*(1/10))) (1/10) 5 (blocks 39) = true := by decide +kernel + +lemma checks (i : ℕ) (hi : i < 40) : + expression.check (-10+(i:ℚ)*(5*(1/10))) (1/10) 5 (blocks i) = true := by + interval_cases i + · exact check_0 + · exact check_1 + · exact check_2 + · exact check_3 + · exact check_4 + · exact check_5 + · exact check_6 + · exact check_7 + · exact check_8 + · exact check_9 + · exact check_10 + · exact check_11 + · exact check_12 + · exact check_13 + · exact check_14 + · exact check_15 + · exact check_16 + · exact check_17 + · exact check_18 + · exact check_19 + · exact check_20 + · exact check_21 + · exact check_22 + · exact check_23 + · exact check_24 + · exact check_25 + · exact check_26 + · exact check_27 + · exact check_28 + · exact check_29 + · exact check_30 + · exact check_31 + · exact check_32 + · exact check_33 + · exact check_34 + · exact check_35 + · exact check_36 + · exact check_37 + · exact check_38 + · exact check_39 + +theorem integral_bound : + (∫ h, scalarFunction (19/40) (406349/500000) (66273/125000) (28579/250000) (135787/200000) 0 h ∂Scalar.fieldLaw (19/40)) ∈ (⟨405599/500000,407099/500000⟩ : Box) := by + apply gaussian_certificate (e := expression) (B := blocks) (h := (1/10)) (k := 5) (by norm_num) + · simpa only [expression,Rat.cast_div,Rat.cast_ofNat,Rat.cast_one,Rat.cast_zero] using integrandExpr_val (19/40) (406349/500000) (66273/125000) (28579/250000) (135787/200000) 0 + · exact (continuous_scalarFunction _ _ _ _ _ _).measurable + · intro x + apply scalarFunction_bound <;> norm_num + · exact checks + · decide +kernel + +end SKRatio.Certificate.Data.J3K0 + +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Certificates/ScalarDataJ3K1.lean b/lean/OAI/Probability/SKRatio/Certificates/ScalarDataJ3K1.lean new file mode 100644 index 0000000000000000000000000000000000000000..7dee97877383cb4aa053e29764b29a6ec5edc8e2 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Certificates/ScalarDataJ3K1.lean @@ -0,0 +1,154 @@ +import Mathlib +import OAI.Probability.SKRatio.Certificates.CertifiedBatches +import OAI.Probability.SKRatio.Certificates.CertifiedFunctionBounds + +namespace OAI + +noncomputable section +open Real MeasureTheory +namespace SKRatio.Certificate.Data.J3K1 + +def expression : Expr := integrandExpr (19/40) (406349/500000) (66273/125000) (28579/250000) (135787/200000) 1 +def blocks : ℕ → Box + | 0 => ⟨-1/1000000,1/1000000⟩ + | 1 => ⟨-1/1000000,1/1000000⟩ + | 2 => ⟨-1/1000000,1/1000000⟩ + | 3 => ⟨-1/1000000,1/1000000⟩ + | 4 => ⟨-1/1000000,1/1000000⟩ + | 5 => ⟨-1/1000000,1/1000000⟩ + | 6 => ⟨-1/1000000,1/1000000⟩ + | 7 => ⟨-1/1000000,1/1000000⟩ + | 8 => ⟨-1/1000000,1/1000000⟩ + | 9 => ⟨-1/1000000,1/1000000⟩ + | 10 => ⟨0,1/1000000⟩ + | 11 => ⟨1/500000,1/250000⟩ + | 12 => ⟨1/31250,7/200000⟩ + | 13 => ⟨141/500000,293/1000000⟩ + | 14 => ⟨1861/1000000,381/200000⟩ + | 15 => ⟨4653/500000,9449/1000000⟩ + | 16 => ⟨34943/1000000,8813/250000⟩ + | 17 => ⟨97171/1000000,19507/200000⟩ + | 18 => ⟨197039/1000000,197253/1000000⟩ + | 19 => ⟨287301/1000000,143971/500000⟩ + | 20 => ⟨37399/125000,300001/1000000⟩ + | 21 => ⟨221923/1000000,111203/500000⟩ + | 22 => ⟨5871/50000,59017/500000⟩ + | 23 => ⟨5589/125000,22659/500000⟩ + | 24 => ⟨12423/1000000,12759/1000000⟩ + | 25 => ⟨319/125000,2679/1000000⟩ + | 26 => ⟨391/1000000,427/1000000⟩ + | 27 => ⟨11/250000,53/1000000⟩ + | 28 => ⟨3/1000000,3/500000⟩ + | 29 => ⟨0,1/1000000⟩ + | 30 => ⟨-1/1000000,1/1000000⟩ + | 31 => ⟨-1/1000000,1/1000000⟩ + | 32 => ⟨-1/1000000,1/1000000⟩ + | 33 => ⟨-1/1000000,1/1000000⟩ + | 34 => ⟨-1/1000000,1/1000000⟩ + | 35 => ⟨-1/1000000,1/1000000⟩ + | 36 => ⟨-1/1000000,1/1000000⟩ + | 37 => ⟨-1/1000000,1/1000000⟩ + | 38 => ⟨-1/1000000,1/1000000⟩ + | 39 => ⟨-1/1000000,1/1000000⟩ + | _ => Box.rat 0 + +lemma check_0 : expression.check (-10+(0:ℚ)*(5*(1/10))) (1/10) 5 (blocks 0) = true := by decide +kernel +lemma check_1 : expression.check (-10+(1:ℚ)*(5*(1/10))) (1/10) 5 (blocks 1) = true := by decide +kernel +lemma check_2 : expression.check (-10+(2:ℚ)*(5*(1/10))) (1/10) 5 (blocks 2) = true := by decide +kernel +lemma check_3 : expression.check (-10+(3:ℚ)*(5*(1/10))) (1/10) 5 (blocks 3) = true := by decide +kernel +lemma check_4 : expression.check (-10+(4:ℚ)*(5*(1/10))) (1/10) 5 (blocks 4) = true := by decide +kernel +lemma check_5 : expression.check (-10+(5:ℚ)*(5*(1/10))) (1/10) 5 (blocks 5) = true := by decide +kernel +lemma check_6 : expression.check (-10+(6:ℚ)*(5*(1/10))) (1/10) 5 (blocks 6) = true := by decide +kernel +lemma check_7 : expression.check (-10+(7:ℚ)*(5*(1/10))) (1/10) 5 (blocks 7) = true := by decide +kernel +lemma check_8 : expression.check (-10+(8:ℚ)*(5*(1/10))) (1/10) 5 (blocks 8) = true := by decide +kernel +lemma check_9 : expression.check (-10+(9:ℚ)*(5*(1/10))) (1/10) 5 (blocks 9) = true := by decide +kernel +lemma check_10 : expression.check (-10+(10:ℚ)*(5*(1/10))) (1/10) 5 (blocks 10) = true := by decide +kernel +lemma check_11 : expression.check (-10+(11:ℚ)*(5*(1/10))) (1/10) 5 (blocks 11) = true := by decide +kernel +lemma check_12 : expression.check (-10+(12:ℚ)*(5*(1/10))) (1/10) 5 (blocks 12) = true := by decide +kernel +lemma check_13 : expression.check (-10+(13:ℚ)*(5*(1/10))) (1/10) 5 (blocks 13) = true := by decide +kernel +lemma check_14 : expression.check (-10+(14:ℚ)*(5*(1/10))) (1/10) 5 (blocks 14) = true := by decide +kernel +lemma check_15 : expression.check (-10+(15:ℚ)*(5*(1/10))) (1/10) 5 (blocks 15) = true := by decide +kernel +lemma check_16 : expression.check (-10+(16:ℚ)*(5*(1/10))) (1/10) 5 (blocks 16) = true := by decide +kernel +lemma check_17 : expression.check (-10+(17:ℚ)*(5*(1/10))) (1/10) 5 (blocks 17) = true := by decide +kernel +lemma check_18 : expression.check (-10+(18:ℚ)*(5*(1/10))) (1/10) 5 (blocks 18) = true := by decide +kernel +lemma check_19 : expression.check (-10+(19:ℚ)*(5*(1/10))) (1/10) 5 (blocks 19) = true := by decide +kernel +lemma check_20 : expression.check (-10+(20:ℚ)*(5*(1/10))) (1/10) 5 (blocks 20) = true := by decide +kernel +lemma check_21 : expression.check (-10+(21:ℚ)*(5*(1/10))) (1/10) 5 (blocks 21) = true := by decide +kernel +lemma check_22 : expression.check (-10+(22:ℚ)*(5*(1/10))) (1/10) 5 (blocks 22) = true := by decide +kernel +lemma check_23 : expression.check (-10+(23:ℚ)*(5*(1/10))) (1/10) 5 (blocks 23) = true := by decide +kernel +lemma check_24 : expression.check (-10+(24:ℚ)*(5*(1/10))) (1/10) 5 (blocks 24) = true := by decide +kernel +lemma check_25 : expression.check (-10+(25:ℚ)*(5*(1/10))) (1/10) 5 (blocks 25) = true := by decide +kernel +lemma check_26 : expression.check (-10+(26:ℚ)*(5*(1/10))) (1/10) 5 (blocks 26) = true := by decide +kernel +lemma check_27 : expression.check (-10+(27:ℚ)*(5*(1/10))) (1/10) 5 (blocks 27) = true := by decide +kernel +lemma check_28 : expression.check (-10+(28:ℚ)*(5*(1/10))) (1/10) 5 (blocks 28) = true := by decide +kernel +lemma check_29 : expression.check (-10+(29:ℚ)*(5*(1/10))) (1/10) 5 (blocks 29) = true := by decide +kernel +lemma check_30 : expression.check (-10+(30:ℚ)*(5*(1/10))) (1/10) 5 (blocks 30) = true := by decide +kernel +lemma check_31 : expression.check (-10+(31:ℚ)*(5*(1/10))) (1/10) 5 (blocks 31) = true := by decide +kernel +lemma check_32 : expression.check (-10+(32:ℚ)*(5*(1/10))) (1/10) 5 (blocks 32) = true := by decide +kernel +lemma check_33 : expression.check (-10+(33:ℚ)*(5*(1/10))) (1/10) 5 (blocks 33) = true := by decide +kernel +lemma check_34 : expression.check (-10+(34:ℚ)*(5*(1/10))) (1/10) 5 (blocks 34) = true := by decide +kernel +lemma check_35 : expression.check (-10+(35:ℚ)*(5*(1/10))) (1/10) 5 (blocks 35) = true := by decide +kernel +lemma check_36 : expression.check (-10+(36:ℚ)*(5*(1/10))) (1/10) 5 (blocks 36) = true := by decide +kernel +lemma check_37 : expression.check (-10+(37:ℚ)*(5*(1/10))) (1/10) 5 (blocks 37) = true := by decide +kernel +lemma check_38 : expression.check (-10+(38:ℚ)*(5*(1/10))) (1/10) 5 (blocks 38) = true := by decide +kernel +lemma check_39 : expression.check (-10+(39:ℚ)*(5*(1/10))) (1/10) 5 (blocks 39) = true := by decide +kernel + +lemma checks (i : ℕ) (hi : i < 40) : + expression.check (-10+(i:ℚ)*(5*(1/10))) (1/10) 5 (blocks i) = true := by + interval_cases i + · exact check_0 + · exact check_1 + · exact check_2 + · exact check_3 + · exact check_4 + · exact check_5 + · exact check_6 + · exact check_7 + · exact check_8 + · exact check_9 + · exact check_10 + · exact check_11 + · exact check_12 + · exact check_13 + · exact check_14 + · exact check_15 + · exact check_16 + · exact check_17 + · exact check_18 + · exact check_19 + · exact check_20 + · exact check_21 + · exact check_22 + · exact check_23 + · exact check_24 + · exact check_25 + · exact check_26 + · exact check_27 + · exact check_28 + · exact check_29 + · exact check_30 + · exact check_31 + · exact check_32 + · exact check_33 + · exact check_34 + · exact check_35 + · exact check_36 + · exact check_37 + · exact check_38 + · exact check_39 + +theorem integral_bound : + (∫ h, scalarFunction (19/40) (406349/500000) (66273/125000) (28579/250000) (135787/200000) 1 h ∂Scalar.fieldLaw (19/40)) ∈ (⟨132171/250000,132921/250000⟩ : Box) := by + apply gaussian_certificate (e := expression) (B := blocks) (h := (1/10)) (k := 5) (by norm_num) + · simpa only [expression,Rat.cast_div,Rat.cast_ofNat,Rat.cast_one,Rat.cast_zero] using integrandExpr_val (19/40) (406349/500000) (66273/125000) (28579/250000) (135787/200000) 1 + · exact (continuous_scalarFunction _ _ _ _ _ _).measurable + · intro x + apply scalarFunction_bound <;> norm_num + · exact checks + · decide +kernel + +end SKRatio.Certificate.Data.J3K1 + +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Certificates/ScalarDataJ3K2.lean b/lean/OAI/Probability/SKRatio/Certificates/ScalarDataJ3K2.lean new file mode 100644 index 0000000000000000000000000000000000000000..8fd969c64fe1e9b585ab17fb883723276a89d881 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Certificates/ScalarDataJ3K2.lean @@ -0,0 +1,154 @@ +import Mathlib +import OAI.Probability.SKRatio.Certificates.CertifiedBatches +import OAI.Probability.SKRatio.Certificates.CertifiedFunctionBounds + +namespace OAI + +noncomputable section +open Real MeasureTheory +namespace SKRatio.Certificate.Data.J3K2 + +def expression : Expr := integrandExpr (19/40) (406349/500000) (66273/125000) (28579/250000) (135787/200000) 2 +def blocks : ℕ → Box + | 0 => ⟨-1/1000000,1/1000000⟩ + | 1 => ⟨-1/1000000,1/1000000⟩ + | 2 => ⟨-1/1000000,1/1000000⟩ + | 3 => ⟨-1/1000000,1/1000000⟩ + | 4 => ⟨-1/1000000,1/1000000⟩ + | 5 => ⟨-1/1000000,1/1000000⟩ + | 6 => ⟨-1/1000000,1/1000000⟩ + | 7 => ⟨-1/1000000,1/1000000⟩ + | 8 => ⟨-1/1000000,1/1000000⟩ + | 9 => ⟨-1/1000000,1/1000000⟩ + | 10 => ⟨-1/1000000,0⟩ + | 11 => ⟨-9/1000000,-7/1000000⟩ + | 12 => ⟨-83/1000000,-79/1000000⟩ + | 13 => ⟨-13/20000,-631/1000000⟩ + | 14 => ⟨-3743/1000000,-459/125000⟩ + | 15 => ⟨-1909/125000,-15119/1000000⟩ + | 16 => ⟨-41723/1000000,-8317/200000⟩ + | 17 => ⟨-34241/500000,-68027/1000000⟩ + | 18 => ⟨-44613/1000000,-10989/250000⟩ + | 19 => ⟨12631/250000,25429/500000⟩ + | 20 => ⟨68973/500000,138777/1000000⟩ + | 21 => ⟨140351/1000000,8813/62500⟩ + | 22 => ⟨42251/500000,21221/250000⟩ + | 23 => ⟨33749/1000000,34191/1000000⟩ + | 24 => ⟨4751/500000,1951/200000⟩ + | 25 => ⟨61/31250,2047/1000000⟩ + | 26 => ⟨149/500000,13/40000⟩ + | 27 => ⟨17/500000,1/25000⟩ + | 28 => ⟨1/500000,1/200000⟩ + | 29 => ⟨-1/1000000,1/1000000⟩ + | 30 => ⟨-1/1000000,1/1000000⟩ + | 31 => ⟨-1/1000000,1/1000000⟩ + | 32 => ⟨-1/1000000,1/1000000⟩ + | 33 => ⟨-1/1000000,1/1000000⟩ + | 34 => ⟨-1/1000000,1/1000000⟩ + | 35 => ⟨-1/1000000,1/1000000⟩ + | 36 => ⟨-1/1000000,1/1000000⟩ + | 37 => ⟨-1/1000000,1/1000000⟩ + | 38 => ⟨-1/1000000,1/1000000⟩ + | 39 => ⟨-1/1000000,1/1000000⟩ + | _ => Box.rat 0 + +lemma check_0 : expression.check (-10+(0:ℚ)*(5*(1/10))) (1/10) 5 (blocks 0) = true := by decide +kernel +lemma check_1 : expression.check (-10+(1:ℚ)*(5*(1/10))) (1/10) 5 (blocks 1) = true := by decide +kernel +lemma check_2 : expression.check (-10+(2:ℚ)*(5*(1/10))) (1/10) 5 (blocks 2) = true := by decide +kernel +lemma check_3 : expression.check (-10+(3:ℚ)*(5*(1/10))) (1/10) 5 (blocks 3) = true := by decide +kernel +lemma check_4 : expression.check (-10+(4:ℚ)*(5*(1/10))) (1/10) 5 (blocks 4) = true := by decide +kernel +lemma check_5 : expression.check (-10+(5:ℚ)*(5*(1/10))) (1/10) 5 (blocks 5) = true := by decide +kernel +lemma check_6 : expression.check (-10+(6:ℚ)*(5*(1/10))) (1/10) 5 (blocks 6) = true := by decide +kernel +lemma check_7 : expression.check (-10+(7:ℚ)*(5*(1/10))) (1/10) 5 (blocks 7) = true := by decide +kernel +lemma check_8 : expression.check (-10+(8:ℚ)*(5*(1/10))) (1/10) 5 (blocks 8) = true := by decide +kernel +lemma check_9 : expression.check (-10+(9:ℚ)*(5*(1/10))) (1/10) 5 (blocks 9) = true := by decide +kernel +lemma check_10 : expression.check (-10+(10:ℚ)*(5*(1/10))) (1/10) 5 (blocks 10) = true := by decide +kernel +lemma check_11 : expression.check (-10+(11:ℚ)*(5*(1/10))) (1/10) 5 (blocks 11) = true := by decide +kernel +lemma check_12 : expression.check (-10+(12:ℚ)*(5*(1/10))) (1/10) 5 (blocks 12) = true := by decide +kernel +lemma check_13 : expression.check (-10+(13:ℚ)*(5*(1/10))) (1/10) 5 (blocks 13) = true := by decide +kernel +lemma check_14 : expression.check (-10+(14:ℚ)*(5*(1/10))) (1/10) 5 (blocks 14) = true := by decide +kernel +lemma check_15 : expression.check (-10+(15:ℚ)*(5*(1/10))) (1/10) 5 (blocks 15) = true := by decide +kernel +lemma check_16 : expression.check (-10+(16:ℚ)*(5*(1/10))) (1/10) 5 (blocks 16) = true := by decide +kernel +lemma check_17 : expression.check (-10+(17:ℚ)*(5*(1/10))) (1/10) 5 (blocks 17) = true := by decide +kernel +lemma check_18 : expression.check (-10+(18:ℚ)*(5*(1/10))) (1/10) 5 (blocks 18) = true := by decide +kernel +lemma check_19 : expression.check (-10+(19:ℚ)*(5*(1/10))) (1/10) 5 (blocks 19) = true := by decide +kernel +lemma check_20 : expression.check (-10+(20:ℚ)*(5*(1/10))) (1/10) 5 (blocks 20) = true := by decide +kernel +lemma check_21 : expression.check (-10+(21:ℚ)*(5*(1/10))) (1/10) 5 (blocks 21) = true := by decide +kernel +lemma check_22 : expression.check (-10+(22:ℚ)*(5*(1/10))) (1/10) 5 (blocks 22) = true := by decide +kernel +lemma check_23 : expression.check (-10+(23:ℚ)*(5*(1/10))) (1/10) 5 (blocks 23) = true := by decide +kernel +lemma check_24 : expression.check (-10+(24:ℚ)*(5*(1/10))) (1/10) 5 (blocks 24) = true := by decide +kernel +lemma check_25 : expression.check (-10+(25:ℚ)*(5*(1/10))) (1/10) 5 (blocks 25) = true := by decide +kernel +lemma check_26 : expression.check (-10+(26:ℚ)*(5*(1/10))) (1/10) 5 (blocks 26) = true := by decide +kernel +lemma check_27 : expression.check (-10+(27:ℚ)*(5*(1/10))) (1/10) 5 (blocks 27) = true := by decide +kernel +lemma check_28 : expression.check (-10+(28:ℚ)*(5*(1/10))) (1/10) 5 (blocks 28) = true := by decide +kernel +lemma check_29 : expression.check (-10+(29:ℚ)*(5*(1/10))) (1/10) 5 (blocks 29) = true := by decide +kernel +lemma check_30 : expression.check (-10+(30:ℚ)*(5*(1/10))) (1/10) 5 (blocks 30) = true := by decide +kernel +lemma check_31 : expression.check (-10+(31:ℚ)*(5*(1/10))) (1/10) 5 (blocks 31) = true := by decide +kernel +lemma check_32 : expression.check (-10+(32:ℚ)*(5*(1/10))) (1/10) 5 (blocks 32) = true := by decide +kernel +lemma check_33 : expression.check (-10+(33:ℚ)*(5*(1/10))) (1/10) 5 (blocks 33) = true := by decide +kernel +lemma check_34 : expression.check (-10+(34:ℚ)*(5*(1/10))) (1/10) 5 (blocks 34) = true := by decide +kernel +lemma check_35 : expression.check (-10+(35:ℚ)*(5*(1/10))) (1/10) 5 (blocks 35) = true := by decide +kernel +lemma check_36 : expression.check (-10+(36:ℚ)*(5*(1/10))) (1/10) 5 (blocks 36) = true := by decide +kernel +lemma check_37 : expression.check (-10+(37:ℚ)*(5*(1/10))) (1/10) 5 (blocks 37) = true := by decide +kernel +lemma check_38 : expression.check (-10+(38:ℚ)*(5*(1/10))) (1/10) 5 (blocks 38) = true := by decide +kernel +lemma check_39 : expression.check (-10+(39:ℚ)*(5*(1/10))) (1/10) 5 (blocks 39) = true := by decide +kernel + +lemma checks (i : ℕ) (hi : i < 40) : + expression.check (-10+(i:ℚ)*(5*(1/10))) (1/10) 5 (blocks i) = true := by + interval_cases i + · exact check_0 + · exact check_1 + · exact check_2 + · exact check_3 + · exact check_4 + · exact check_5 + · exact check_6 + · exact check_7 + · exact check_8 + · exact check_9 + · exact check_10 + · exact check_11 + · exact check_12 + · exact check_13 + · exact check_14 + · exact check_15 + · exact check_16 + · exact check_17 + · exact check_18 + · exact check_19 + · exact check_20 + · exact check_21 + · exact check_22 + · exact check_23 + · exact check_24 + · exact check_25 + · exact check_26 + · exact check_27 + · exact check_28 + · exact check_29 + · exact check_30 + · exact check_31 + · exact check_32 + · exact check_33 + · exact check_34 + · exact check_35 + · exact check_36 + · exact check_37 + · exact check_38 + · exact check_39 + +theorem integral_bound : + (∫ h, scalarFunction (19/40) (406349/500000) (66273/125000) (28579/250000) (135787/200000) 2 h ∂Scalar.fieldLaw (19/40)) ∈ (⟨7051/62500,14477/125000⟩ : Box) := by + apply gaussian_certificate (e := expression) (B := blocks) (h := (1/10)) (k := 5) (by norm_num) + · simpa only [expression,Rat.cast_div,Rat.cast_ofNat,Rat.cast_one,Rat.cast_zero] using integrandExpr_val (19/40) (406349/500000) (66273/125000) (28579/250000) (135787/200000) 2 + · exact (continuous_scalarFunction _ _ _ _ _ _).measurable + · intro x + apply scalarFunction_bound <;> norm_num + · exact checks + · decide +kernel + +end SKRatio.Certificate.Data.J3K2 + +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Certificates/ScalarDataJ3K3.lean b/lean/OAI/Probability/SKRatio/Certificates/ScalarDataJ3K3.lean new file mode 100644 index 0000000000000000000000000000000000000000..5df1aad7413a8b5cef6506b637036be89eb39bda --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Certificates/ScalarDataJ3K3.lean @@ -0,0 +1,154 @@ +import Mathlib +import OAI.Probability.SKRatio.Certificates.CertifiedBatches +import OAI.Probability.SKRatio.Certificates.CertifiedFunctionBounds + +namespace OAI + +noncomputable section +open Real MeasureTheory +namespace SKRatio.Certificate.Data.J3K3 + +def expression : Expr := integrandExpr (19/40) (406349/500000) (66273/125000) (28579/250000) (135787/200000) 3 +def blocks : ℕ → Box + | 0 => ⟨-1/1000000,1/1000000⟩ + | 1 => ⟨-1/1000000,1/1000000⟩ + | 2 => ⟨-1/1000000,1/1000000⟩ + | 3 => ⟨-1/1000000,1/1000000⟩ + | 4 => ⟨-1/1000000,1/1000000⟩ + | 5 => ⟨-1/1000000,1/1000000⟩ + | 6 => ⟨-1/1000000,1/1000000⟩ + | 7 => ⟨-1/1000000,1/1000000⟩ + | 8 => ⟨-1/1000000,1/1000000⟩ + | 9 => ⟨-1/1000000,1/1000000⟩ + | 10 => ⟨-1/1000000,1/1000000⟩ + | 11 => ⟨-1/1000000,1/1000000⟩ + | 12 => ⟨0,1/500000⟩ + | 13 => ⟨9/1000000,11/1000000⟩ + | 14 => ⟨21/250000,9/100000⟩ + | 15 => ⟨263/500000,11/20000⟩ + | 16 => ⟨2151/1000000,221/100000⟩ + | 17 => ⟨13/2500,5303/1000000⟩ + | 18 => ⟨6191/1000000,6353/1000000⟩ + | 19 => ⟨519/250000,57/25000⟩ + | 20 => ⟨159/125000,1771/1000000⟩ + | 21 => ⟨9813/1000000,1063/100000⟩ + | 22 => ⟨15223/1000000,813/50000⟩ + | 23 => ⟨10911/1000000,1463/125000⟩ + | 24 => ⟨451/100000,153/31250⟩ + | 25 => ⟨119/100000,83/62500⟩ + | 26 => ⟨211/1000000,63/250000⟩ + | 27 => ⟨13/500000,9/250000⟩ + | 28 => ⟨1/500000,1/250000⟩ + | 29 => ⟨-1/1000000,1/1000000⟩ + | 30 => ⟨-1/1000000,1/1000000⟩ + | 31 => ⟨-1/1000000,1/1000000⟩ + | 32 => ⟨-1/1000000,1/1000000⟩ + | 33 => ⟨-1/1000000,1/1000000⟩ + | 34 => ⟨-1/1000000,1/1000000⟩ + | 35 => ⟨-1/1000000,1/1000000⟩ + | 36 => ⟨-1/1000000,1/1000000⟩ + | 37 => ⟨-1/1000000,1/1000000⟩ + | 38 => ⟨-1/1000000,1/1000000⟩ + | 39 => ⟨-1/1000000,1/1000000⟩ + | _ => Box.rat 0 + +lemma check_0 : expression.check (-10+(0:ℚ)*(5*(1/10))) (1/10) 5 (blocks 0) = true := by decide +kernel +lemma check_1 : expression.check (-10+(1:ℚ)*(5*(1/10))) (1/10) 5 (blocks 1) = true := by decide +kernel +lemma check_2 : expression.check (-10+(2:ℚ)*(5*(1/10))) (1/10) 5 (blocks 2) = true := by decide +kernel +lemma check_3 : expression.check (-10+(3:ℚ)*(5*(1/10))) (1/10) 5 (blocks 3) = true := by decide +kernel +lemma check_4 : expression.check (-10+(4:ℚ)*(5*(1/10))) (1/10) 5 (blocks 4) = true := by decide +kernel +lemma check_5 : expression.check (-10+(5:ℚ)*(5*(1/10))) (1/10) 5 (blocks 5) = true := by decide +kernel +lemma check_6 : expression.check (-10+(6:ℚ)*(5*(1/10))) (1/10) 5 (blocks 6) = true := by decide +kernel +lemma check_7 : expression.check (-10+(7:ℚ)*(5*(1/10))) (1/10) 5 (blocks 7) = true := by decide +kernel +lemma check_8 : expression.check (-10+(8:ℚ)*(5*(1/10))) (1/10) 5 (blocks 8) = true := by decide +kernel +lemma check_9 : expression.check (-10+(9:ℚ)*(5*(1/10))) (1/10) 5 (blocks 9) = true := by decide +kernel +lemma check_10 : expression.check (-10+(10:ℚ)*(5*(1/10))) (1/10) 5 (blocks 10) = true := by decide +kernel +lemma check_11 : expression.check (-10+(11:ℚ)*(5*(1/10))) (1/10) 5 (blocks 11) = true := by decide +kernel +lemma check_12 : expression.check (-10+(12:ℚ)*(5*(1/10))) (1/10) 5 (blocks 12) = true := by decide +kernel +lemma check_13 : expression.check (-10+(13:ℚ)*(5*(1/10))) (1/10) 5 (blocks 13) = true := by decide +kernel +lemma check_14 : expression.check (-10+(14:ℚ)*(5*(1/10))) (1/10) 5 (blocks 14) = true := by decide +kernel +lemma check_15 : expression.check (-10+(15:ℚ)*(5*(1/10))) (1/10) 5 (blocks 15) = true := by decide +kernel +lemma check_16 : expression.check (-10+(16:ℚ)*(5*(1/10))) (1/10) 5 (blocks 16) = true := by decide +kernel +lemma check_17 : expression.check (-10+(17:ℚ)*(5*(1/10))) (1/10) 5 (blocks 17) = true := by decide +kernel +lemma check_18 : expression.check (-10+(18:ℚ)*(5*(1/10))) (1/10) 5 (blocks 18) = true := by decide +kernel +lemma check_19 : expression.check (-10+(19:ℚ)*(5*(1/10))) (1/10) 5 (blocks 19) = true := by decide +kernel +lemma check_20 : expression.check (-10+(20:ℚ)*(5*(1/10))) (1/10) 5 (blocks 20) = true := by decide +kernel +lemma check_21 : expression.check (-10+(21:ℚ)*(5*(1/10))) (1/10) 5 (blocks 21) = true := by decide +kernel +lemma check_22 : expression.check (-10+(22:ℚ)*(5*(1/10))) (1/10) 5 (blocks 22) = true := by decide +kernel +lemma check_23 : expression.check (-10+(23:ℚ)*(5*(1/10))) (1/10) 5 (blocks 23) = true := by decide +kernel +lemma check_24 : expression.check (-10+(24:ℚ)*(5*(1/10))) (1/10) 5 (blocks 24) = true := by decide +kernel +lemma check_25 : expression.check (-10+(25:ℚ)*(5*(1/10))) (1/10) 5 (blocks 25) = true := by decide +kernel +lemma check_26 : expression.check (-10+(26:ℚ)*(5*(1/10))) (1/10) 5 (blocks 26) = true := by decide +kernel +lemma check_27 : expression.check (-10+(27:ℚ)*(5*(1/10))) (1/10) 5 (blocks 27) = true := by decide +kernel +lemma check_28 : expression.check (-10+(28:ℚ)*(5*(1/10))) (1/10) 5 (blocks 28) = true := by decide +kernel +lemma check_29 : expression.check (-10+(29:ℚ)*(5*(1/10))) (1/10) 5 (blocks 29) = true := by decide +kernel +lemma check_30 : expression.check (-10+(30:ℚ)*(5*(1/10))) (1/10) 5 (blocks 30) = true := by decide +kernel +lemma check_31 : expression.check (-10+(31:ℚ)*(5*(1/10))) (1/10) 5 (blocks 31) = true := by decide +kernel +lemma check_32 : expression.check (-10+(32:ℚ)*(5*(1/10))) (1/10) 5 (blocks 32) = true := by decide +kernel +lemma check_33 : expression.check (-10+(33:ℚ)*(5*(1/10))) (1/10) 5 (blocks 33) = true := by decide +kernel +lemma check_34 : expression.check (-10+(34:ℚ)*(5*(1/10))) (1/10) 5 (blocks 34) = true := by decide +kernel +lemma check_35 : expression.check (-10+(35:ℚ)*(5*(1/10))) (1/10) 5 (blocks 35) = true := by decide +kernel +lemma check_36 : expression.check (-10+(36:ℚ)*(5*(1/10))) (1/10) 5 (blocks 36) = true := by decide +kernel +lemma check_37 : expression.check (-10+(37:ℚ)*(5*(1/10))) (1/10) 5 (blocks 37) = true := by decide +kernel +lemma check_38 : expression.check (-10+(38:ℚ)*(5*(1/10))) (1/10) 5 (blocks 38) = true := by decide +kernel +lemma check_39 : expression.check (-10+(39:ℚ)*(5*(1/10))) (1/10) 5 (blocks 39) = true := by decide +kernel + +lemma checks (i : ℕ) (hi : i < 40) : + expression.check (-10+(i:ℚ)*(5*(1/10))) (1/10) 5 (blocks i) = true := by + interval_cases i + · exact check_0 + · exact check_1 + · exact check_2 + · exact check_3 + · exact check_4 + · exact check_5 + · exact check_6 + · exact check_7 + · exact check_8 + · exact check_9 + · exact check_10 + · exact check_11 + · exact check_12 + · exact check_13 + · exact check_14 + · exact check_15 + · exact check_16 + · exact check_17 + · exact check_18 + · exact check_19 + · exact check_20 + · exact check_21 + · exact check_22 + · exact check_23 + · exact check_24 + · exact check_25 + · exact check_26 + · exact check_27 + · exact check_28 + · exact check_29 + · exact check_30 + · exact check_31 + · exact check_32 + · exact check_33 + · exact check_34 + · exact check_35 + · exact check_36 + · exact check_37 + · exact check_38 + · exact check_39 + +theorem integral_bound : + (∫ h, scalarFunction (19/40) (406349/500000) (66273/125000) (28579/250000) (135787/200000) 3 h ∂Scalar.fieldLaw (19/40)) ∈ (⟨0,13/500⟩ : Box) := by + apply gaussian_certificate (e := expression) (B := blocks) (h := (1/10)) (k := 5) (by norm_num) + · simpa only [expression,Rat.cast_div,Rat.cast_ofNat,Rat.cast_one,Rat.cast_zero] using integrandExpr_val (19/40) (406349/500000) (66273/125000) (28579/250000) (135787/200000) 3 + · exact (continuous_scalarFunction _ _ _ _ _ _).measurable + · intro x + apply scalarFunction_bound <;> norm_num + · exact checks + · decide +kernel + +end SKRatio.Certificate.Data.J3K3 + +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Certificates/ScalarDataJ3K4.lean b/lean/OAI/Probability/SKRatio/Certificates/ScalarDataJ3K4.lean new file mode 100644 index 0000000000000000000000000000000000000000..2f68d00c824439e2e092ebf78f0e9281da4e3271 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Certificates/ScalarDataJ3K4.lean @@ -0,0 +1,154 @@ +import Mathlib +import OAI.Probability.SKRatio.Certificates.CertifiedBatches +import OAI.Probability.SKRatio.Certificates.CertifiedFunctionBounds + +namespace OAI + +noncomputable section +open Real MeasureTheory +namespace SKRatio.Certificate.Data.J3K4 + +def expression : Expr := integrandExpr (19/40) (406349/500000) (66273/125000) (28579/250000) (135787/200000) 4 +def blocks : ℕ → Box + | 0 => ⟨-1/1000000,1/1000000⟩ + | 1 => ⟨-1/1000000,1/1000000⟩ + | 2 => ⟨-1/1000000,1/1000000⟩ + | 3 => ⟨-1/1000000,1/1000000⟩ + | 4 => ⟨-1/1000000,1/1000000⟩ + | 5 => ⟨-1/1000000,1/1000000⟩ + | 6 => ⟨-1/1000000,1/1000000⟩ + | 7 => ⟨-1/1000000,1/1000000⟩ + | 8 => ⟨-1/1000000,1/1000000⟩ + | 9 => ⟨0,1/1000000⟩ + | 10 => ⟨1/250000,1/200000⟩ + | 11 => ⟨17/500000,9/250000⟩ + | 12 => ⟨51/250000,209/1000000⟩ + | 13 => ⟨841/1000000,853/1000000⟩ + | 14 => ⟨2211/1000000,223/100000⟩ + | 15 => ⟨763/250000,3101/1000000⟩ + | 16 => ⟨1219/1000000,127/100000⟩ + | 17 => ⟨287/200000,31/20000⟩ + | 18 => ⟨10643/1000000,2683/250000⟩ + | 19 => ⟨2801/200000,7079/500000⟩ + | 20 => ⟨701/200000,23/6250⟩ + | 21 => ⟨3467/1000000,371/100000⟩ + | 22 => ⟨7849/500000,8017/500000⟩ + | 23 => ⟨4779/250000,19453/1000000⟩ + | 24 => ⟨12109/1000000,192/15625⟩ + | 25 => ⟨4843/1000000,99/20000⟩ + | 26 => ⟨67/50000,347/250000⟩ + | 27 => ⟨269/1000000,71/250000⟩ + | 28 => ⟨1/25000,11/250000⟩ + | 29 => ⟨1/250000,3/500000⟩ + | 30 => ⟨0,1/1000000⟩ + | 31 => ⟨-1/1000000,1/1000000⟩ + | 32 => ⟨-1/1000000,1/1000000⟩ + | 33 => ⟨-1/1000000,1/1000000⟩ + | 34 => ⟨-1/1000000,1/1000000⟩ + | 35 => ⟨-1/1000000,1/1000000⟩ + | 36 => ⟨-1/1000000,1/1000000⟩ + | 37 => ⟨-1/1000000,1/1000000⟩ + | 38 => ⟨-1/1000000,1/1000000⟩ + | 39 => ⟨-1/1000000,1/1000000⟩ + | _ => Box.rat 0 + +lemma check_0 : expression.check (-10+(0:ℚ)*(5*(1/10))) (1/10) 5 (blocks 0) = true := by decide +kernel +lemma check_1 : expression.check (-10+(1:ℚ)*(5*(1/10))) (1/10) 5 (blocks 1) = true := by decide +kernel +lemma check_2 : expression.check (-10+(2:ℚ)*(5*(1/10))) (1/10) 5 (blocks 2) = true := by decide +kernel +lemma check_3 : expression.check (-10+(3:ℚ)*(5*(1/10))) (1/10) 5 (blocks 3) = true := by decide +kernel +lemma check_4 : expression.check (-10+(4:ℚ)*(5*(1/10))) (1/10) 5 (blocks 4) = true := by decide +kernel +lemma check_5 : expression.check (-10+(5:ℚ)*(5*(1/10))) (1/10) 5 (blocks 5) = true := by decide +kernel +lemma check_6 : expression.check (-10+(6:ℚ)*(5*(1/10))) (1/10) 5 (blocks 6) = true := by decide +kernel +lemma check_7 : expression.check (-10+(7:ℚ)*(5*(1/10))) (1/10) 5 (blocks 7) = true := by decide +kernel +lemma check_8 : expression.check (-10+(8:ℚ)*(5*(1/10))) (1/10) 5 (blocks 8) = true := by decide +kernel +lemma check_9 : expression.check (-10+(9:ℚ)*(5*(1/10))) (1/10) 5 (blocks 9) = true := by decide +kernel +lemma check_10 : expression.check (-10+(10:ℚ)*(5*(1/10))) (1/10) 5 (blocks 10) = true := by decide +kernel +lemma check_11 : expression.check (-10+(11:ℚ)*(5*(1/10))) (1/10) 5 (blocks 11) = true := by decide +kernel +lemma check_12 : expression.check (-10+(12:ℚ)*(5*(1/10))) (1/10) 5 (blocks 12) = true := by decide +kernel +lemma check_13 : expression.check (-10+(13:ℚ)*(5*(1/10))) (1/10) 5 (blocks 13) = true := by decide +kernel +lemma check_14 : expression.check (-10+(14:ℚ)*(5*(1/10))) (1/10) 5 (blocks 14) = true := by decide +kernel +lemma check_15 : expression.check (-10+(15:ℚ)*(5*(1/10))) (1/10) 5 (blocks 15) = true := by decide +kernel +lemma check_16 : expression.check (-10+(16:ℚ)*(5*(1/10))) (1/10) 5 (blocks 16) = true := by decide +kernel +lemma check_17 : expression.check (-10+(17:ℚ)*(5*(1/10))) (1/10) 5 (blocks 17) = true := by decide +kernel +lemma check_18 : expression.check (-10+(18:ℚ)*(5*(1/10))) (1/10) 5 (blocks 18) = true := by decide +kernel +lemma check_19 : expression.check (-10+(19:ℚ)*(5*(1/10))) (1/10) 5 (blocks 19) = true := by decide +kernel +lemma check_20 : expression.check (-10+(20:ℚ)*(5*(1/10))) (1/10) 5 (blocks 20) = true := by decide +kernel +lemma check_21 : expression.check (-10+(21:ℚ)*(5*(1/10))) (1/10) 5 (blocks 21) = true := by decide +kernel +lemma check_22 : expression.check (-10+(22:ℚ)*(5*(1/10))) (1/10) 5 (blocks 22) = true := by decide +kernel +lemma check_23 : expression.check (-10+(23:ℚ)*(5*(1/10))) (1/10) 5 (blocks 23) = true := by decide +kernel +lemma check_24 : expression.check (-10+(24:ℚ)*(5*(1/10))) (1/10) 5 (blocks 24) = true := by decide +kernel +lemma check_25 : expression.check (-10+(25:ℚ)*(5*(1/10))) (1/10) 5 (blocks 25) = true := by decide +kernel +lemma check_26 : expression.check (-10+(26:ℚ)*(5*(1/10))) (1/10) 5 (blocks 26) = true := by decide +kernel +lemma check_27 : expression.check (-10+(27:ℚ)*(5*(1/10))) (1/10) 5 (blocks 27) = true := by decide +kernel +lemma check_28 : expression.check (-10+(28:ℚ)*(5*(1/10))) (1/10) 5 (blocks 28) = true := by decide +kernel +lemma check_29 : expression.check (-10+(29:ℚ)*(5*(1/10))) (1/10) 5 (blocks 29) = true := by decide +kernel +lemma check_30 : expression.check (-10+(30:ℚ)*(5*(1/10))) (1/10) 5 (blocks 30) = true := by decide +kernel +lemma check_31 : expression.check (-10+(31:ℚ)*(5*(1/10))) (1/10) 5 (blocks 31) = true := by decide +kernel +lemma check_32 : expression.check (-10+(32:ℚ)*(5*(1/10))) (1/10) 5 (blocks 32) = true := by decide +kernel +lemma check_33 : expression.check (-10+(33:ℚ)*(5*(1/10))) (1/10) 5 (blocks 33) = true := by decide +kernel +lemma check_34 : expression.check (-10+(34:ℚ)*(5*(1/10))) (1/10) 5 (blocks 34) = true := by decide +kernel +lemma check_35 : expression.check (-10+(35:ℚ)*(5*(1/10))) (1/10) 5 (blocks 35) = true := by decide +kernel +lemma check_36 : expression.check (-10+(36:ℚ)*(5*(1/10))) (1/10) 5 (blocks 36) = true := by decide +kernel +lemma check_37 : expression.check (-10+(37:ℚ)*(5*(1/10))) (1/10) 5 (blocks 37) = true := by decide +kernel +lemma check_38 : expression.check (-10+(38:ℚ)*(5*(1/10))) (1/10) 5 (blocks 38) = true := by decide +kernel +lemma check_39 : expression.check (-10+(39:ℚ)*(5*(1/10))) (1/10) 5 (blocks 39) = true := by decide +kernel + +lemma checks (i : ℕ) (hi : i < 40) : + expression.check (-10+(i:ℚ)*(5*(1/10))) (1/10) 5 (blocks i) = true := by + interval_cases i + · exact check_0 + · exact check_1 + · exact check_2 + · exact check_3 + · exact check_4 + · exact check_5 + · exact check_6 + · exact check_7 + · exact check_8 + · exact check_9 + · exact check_10 + · exact check_11 + · exact check_12 + · exact check_13 + · exact check_14 + · exact check_15 + · exact check_16 + · exact check_17 + · exact check_18 + · exact check_19 + · exact check_20 + · exact check_21 + · exact check_22 + · exact check_23 + · exact check_24 + · exact check_25 + · exact check_26 + · exact check_27 + · exact check_28 + · exact check_29 + · exact check_30 + · exact check_31 + · exact check_32 + · exact check_33 + · exact check_34 + · exact check_35 + · exact check_36 + · exact check_37 + · exact check_38 + · exact check_39 + +theorem integral_bound : + (∫ h, scalarFunction (19/40) (406349/500000) (66273/125000) (28579/250000) (135787/200000) 4 h ∂Scalar.fieldLaw (19/40)) ∈ (⟨0,2401/62500⟩ : Box) := by + apply gaussian_certificate (e := expression) (B := blocks) (h := (1/10)) (k := 5) (by norm_num) + · simpa only [expression,Rat.cast_div,Rat.cast_ofNat,Rat.cast_one,Rat.cast_zero] using integrandExpr_val (19/40) (406349/500000) (66273/125000) (28579/250000) (135787/200000) 4 + · exact (continuous_scalarFunction _ _ _ _ _ _).measurable + · intro x + apply scalarFunction_bound <;> norm_num + · exact checks + · decide +kernel + +end SKRatio.Certificate.Data.J3K4 + +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Certificates/ScalarDataJ3K5.lean b/lean/OAI/Probability/SKRatio/Certificates/ScalarDataJ3K5.lean new file mode 100644 index 0000000000000000000000000000000000000000..d36f5df20faa3f8eb141bd32c1c01ed69558a667 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Certificates/ScalarDataJ3K5.lean @@ -0,0 +1,154 @@ +import Mathlib +import OAI.Probability.SKRatio.Certificates.CertifiedBatches +import OAI.Probability.SKRatio.Certificates.CertifiedFunctionBounds + +namespace OAI + +noncomputable section +open Real MeasureTheory +namespace SKRatio.Certificate.Data.J3K5 + +def expression : Expr := integrandExpr (19/40) (406349/500000) (66273/125000) (28579/250000) (135787/200000) 5 +def blocks : ℕ → Box + | 0 => ⟨-1/1000000,1/1000000⟩ + | 1 => ⟨-1/1000000,1/1000000⟩ + | 2 => ⟨-1/1000000,1/1000000⟩ + | 3 => ⟨-1/1000000,1/1000000⟩ + | 4 => ⟨-1/1000000,1/1000000⟩ + | 5 => ⟨-1/1000000,1/1000000⟩ + | 6 => ⟨-1/1000000,1/1000000⟩ + | 7 => ⟨-1/1000000,1/1000000⟩ + | 8 => ⟨-1/1000000,1/1000000⟩ + | 9 => ⟨-1/1000000,1/1000000⟩ + | 10 => ⟨1/1000000,3/1000000⟩ + | 11 => ⟨1/62500,9/500000⟩ + | 12 => ⟨27/250000,7/62500⟩ + | 13 => ⟨513/1000000,523/1000000⟩ + | 14 => ⟨1731/1000000,873/500000⟩ + | 15 => ⟨969/250000,1949/500000⟩ + | 16 => ⟨5087/1000000,2569/500000⟩ + | 17 => ⟨2887/1000000,183/62500⟩ + | 18 => ⟨287/1000000,347/1000000⟩ + | 19 => ⟨2429/1000000,99/40000⟩ + | 20 => ⟨1061/250000,217/50000⟩ + | 21 => ⟨1471/1000000,811/500000⟩ + | 22 => ⟨173/1000000,199/500000⟩ + | 23 => ⟨423/250000,949/500000⟩ + | 24 => ⟨33/15625,1131/500000⟩ + | 25 => ⟨599/500000,127/100000⟩ + | 26 => ⟨403/1000000,109/250000⟩ + | 27 => ⟨91/1000000,51/500000⟩ + | 28 => ⟨7/500000,17/1000000⟩ + | 29 => ⟨1/1000000,3/1000000⟩ + | 30 => ⟨-1/1000000,1/1000000⟩ + | 31 => ⟨-1/1000000,1/1000000⟩ + | 32 => ⟨-1/1000000,1/1000000⟩ + | 33 => ⟨-1/1000000,1/1000000⟩ + | 34 => ⟨-1/1000000,1/1000000⟩ + | 35 => ⟨-1/1000000,1/1000000⟩ + | 36 => ⟨-1/1000000,1/1000000⟩ + | 37 => ⟨-1/1000000,1/1000000⟩ + | 38 => ⟨-1/1000000,1/1000000⟩ + | 39 => ⟨-1/1000000,1/1000000⟩ + | _ => Box.rat 0 + +lemma check_0 : expression.check (-10+(0:ℚ)*(5*(1/10))) (1/10) 5 (blocks 0) = true := by decide +kernel +lemma check_1 : expression.check (-10+(1:ℚ)*(5*(1/10))) (1/10) 5 (blocks 1) = true := by decide +kernel +lemma check_2 : expression.check (-10+(2:ℚ)*(5*(1/10))) (1/10) 5 (blocks 2) = true := by decide +kernel +lemma check_3 : expression.check (-10+(3:ℚ)*(5*(1/10))) (1/10) 5 (blocks 3) = true := by decide +kernel +lemma check_4 : expression.check (-10+(4:ℚ)*(5*(1/10))) (1/10) 5 (blocks 4) = true := by decide +kernel +lemma check_5 : expression.check (-10+(5:ℚ)*(5*(1/10))) (1/10) 5 (blocks 5) = true := by decide +kernel +lemma check_6 : expression.check (-10+(6:ℚ)*(5*(1/10))) (1/10) 5 (blocks 6) = true := by decide +kernel +lemma check_7 : expression.check (-10+(7:ℚ)*(5*(1/10))) (1/10) 5 (blocks 7) = true := by decide +kernel +lemma check_8 : expression.check (-10+(8:ℚ)*(5*(1/10))) (1/10) 5 (blocks 8) = true := by decide +kernel +lemma check_9 : expression.check (-10+(9:ℚ)*(5*(1/10))) (1/10) 5 (blocks 9) = true := by decide +kernel +lemma check_10 : expression.check (-10+(10:ℚ)*(5*(1/10))) (1/10) 5 (blocks 10) = true := by decide +kernel +lemma check_11 : expression.check (-10+(11:ℚ)*(5*(1/10))) (1/10) 5 (blocks 11) = true := by decide +kernel +lemma check_12 : expression.check (-10+(12:ℚ)*(5*(1/10))) (1/10) 5 (blocks 12) = true := by decide +kernel +lemma check_13 : expression.check (-10+(13:ℚ)*(5*(1/10))) (1/10) 5 (blocks 13) = true := by decide +kernel +lemma check_14 : expression.check (-10+(14:ℚ)*(5*(1/10))) (1/10) 5 (blocks 14) = true := by decide +kernel +lemma check_15 : expression.check (-10+(15:ℚ)*(5*(1/10))) (1/10) 5 (blocks 15) = true := by decide +kernel +lemma check_16 : expression.check (-10+(16:ℚ)*(5*(1/10))) (1/10) 5 (blocks 16) = true := by decide +kernel +lemma check_17 : expression.check (-10+(17:ℚ)*(5*(1/10))) (1/10) 5 (blocks 17) = true := by decide +kernel +lemma check_18 : expression.check (-10+(18:ℚ)*(5*(1/10))) (1/10) 5 (blocks 18) = true := by decide +kernel +lemma check_19 : expression.check (-10+(19:ℚ)*(5*(1/10))) (1/10) 5 (blocks 19) = true := by decide +kernel +lemma check_20 : expression.check (-10+(20:ℚ)*(5*(1/10))) (1/10) 5 (blocks 20) = true := by decide +kernel +lemma check_21 : expression.check (-10+(21:ℚ)*(5*(1/10))) (1/10) 5 (blocks 21) = true := by decide +kernel +lemma check_22 : expression.check (-10+(22:ℚ)*(5*(1/10))) (1/10) 5 (blocks 22) = true := by decide +kernel +lemma check_23 : expression.check (-10+(23:ℚ)*(5*(1/10))) (1/10) 5 (blocks 23) = true := by decide +kernel +lemma check_24 : expression.check (-10+(24:ℚ)*(5*(1/10))) (1/10) 5 (blocks 24) = true := by decide +kernel +lemma check_25 : expression.check (-10+(25:ℚ)*(5*(1/10))) (1/10) 5 (blocks 25) = true := by decide +kernel +lemma check_26 : expression.check (-10+(26:ℚ)*(5*(1/10))) (1/10) 5 (blocks 26) = true := by decide +kernel +lemma check_27 : expression.check (-10+(27:ℚ)*(5*(1/10))) (1/10) 5 (blocks 27) = true := by decide +kernel +lemma check_28 : expression.check (-10+(28:ℚ)*(5*(1/10))) (1/10) 5 (blocks 28) = true := by decide +kernel +lemma check_29 : expression.check (-10+(29:ℚ)*(5*(1/10))) (1/10) 5 (blocks 29) = true := by decide +kernel +lemma check_30 : expression.check (-10+(30:ℚ)*(5*(1/10))) (1/10) 5 (blocks 30) = true := by decide +kernel +lemma check_31 : expression.check (-10+(31:ℚ)*(5*(1/10))) (1/10) 5 (blocks 31) = true := by decide +kernel +lemma check_32 : expression.check (-10+(32:ℚ)*(5*(1/10))) (1/10) 5 (blocks 32) = true := by decide +kernel +lemma check_33 : expression.check (-10+(33:ℚ)*(5*(1/10))) (1/10) 5 (blocks 33) = true := by decide +kernel +lemma check_34 : expression.check (-10+(34:ℚ)*(5*(1/10))) (1/10) 5 (blocks 34) = true := by decide +kernel +lemma check_35 : expression.check (-10+(35:ℚ)*(5*(1/10))) (1/10) 5 (blocks 35) = true := by decide +kernel +lemma check_36 : expression.check (-10+(36:ℚ)*(5*(1/10))) (1/10) 5 (blocks 36) = true := by decide +kernel +lemma check_37 : expression.check (-10+(37:ℚ)*(5*(1/10))) (1/10) 5 (blocks 37) = true := by decide +kernel +lemma check_38 : expression.check (-10+(38:ℚ)*(5*(1/10))) (1/10) 5 (blocks 38) = true := by decide +kernel +lemma check_39 : expression.check (-10+(39:ℚ)*(5*(1/10))) (1/10) 5 (blocks 39) = true := by decide +kernel + +lemma checks (i : ℕ) (hi : i < 40) : + expression.check (-10+(i:ℚ)*(5*(1/10))) (1/10) 5 (blocks i) = true := by + interval_cases i + · exact check_0 + · exact check_1 + · exact check_2 + · exact check_3 + · exact check_4 + · exact check_5 + · exact check_6 + · exact check_7 + · exact check_8 + · exact check_9 + · exact check_10 + · exact check_11 + · exact check_12 + · exact check_13 + · exact check_14 + · exact check_15 + · exact check_16 + · exact check_17 + · exact check_18 + · exact check_19 + · exact check_20 + · exact check_21 + · exact check_22 + · exact check_23 + · exact check_24 + · exact check_25 + · exact check_26 + · exact check_27 + · exact check_28 + · exact check_29 + · exact check_30 + · exact check_31 + · exact check_32 + · exact check_33 + · exact check_34 + · exact check_35 + · exact check_36 + · exact check_37 + · exact check_38 + · exact check_39 + +theorem integral_bound : + (∫ h, scalarFunction (19/40) (406349/500000) (66273/125000) (28579/250000) (135787/200000) 5 h ∂Scalar.fieldLaw (19/40)) ∈ (⟨0,11881/1000000⟩ : Box) := by + apply gaussian_certificate (e := expression) (B := blocks) (h := (1/10)) (k := 5) (by norm_num) + · simpa only [expression,Rat.cast_div,Rat.cast_ofNat,Rat.cast_one,Rat.cast_zero] using integrandExpr_val (19/40) (406349/500000) (66273/125000) (28579/250000) (135787/200000) 5 + · exact (continuous_scalarFunction _ _ _ _ _ _).measurable + · intro x + apply scalarFunction_bound <;> norm_num + · exact checks + · decide +kernel + +end SKRatio.Certificate.Data.J3K5 + +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Certificates/ScalarDataJ3K6.lean b/lean/OAI/Probability/SKRatio/Certificates/ScalarDataJ3K6.lean new file mode 100644 index 0000000000000000000000000000000000000000..d7db22bf76403ab8f66243a980737a088b8372d3 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Certificates/ScalarDataJ3K6.lean @@ -0,0 +1,154 @@ +import Mathlib +import OAI.Probability.SKRatio.Certificates.CertifiedBatches +import OAI.Probability.SKRatio.Certificates.CertifiedFunctionBounds + +namespace OAI + +noncomputable section +open Real MeasureTheory +namespace SKRatio.Certificate.Data.J3K6 + +def expression : Expr := integrandExpr (19/40) (406349/500000) (66273/125000) (28579/250000) (135787/200000) 6 +def blocks : ℕ → Box + | 0 => ⟨-1/1000000,1/1000000⟩ + | 1 => ⟨-1/1000000,1/1000000⟩ + | 2 => ⟨-1/1000000,1/1000000⟩ + | 3 => ⟨-1/1000000,1/1000000⟩ + | 4 => ⟨-1/1000000,1/1000000⟩ + | 5 => ⟨-1/1000000,1/1000000⟩ + | 6 => ⟨-1/1000000,1/1000000⟩ + | 7 => ⟨-1/1000000,1/1000000⟩ + | 8 => ⟨-1/1000000,1/1000000⟩ + | 9 => ⟨-1/1000000,1/1000000⟩ + | 10 => ⟨0,1/1000000⟩ + | 11 => ⟨3/1000000,1/250000⟩ + | 12 => ⟨37/1000000,1/25000⟩ + | 13 => ⟨81/250000,21/62500⟩ + | 14 => ⟨33/15625,2161/1000000⟩ + | 15 => ⟨9521/1000000,4817/500000⟩ + | 16 => ⟨26601/1000000,6681/250000⟩ + | 17 => ⟨1561/40000,39381/1000000⟩ + | 18 => ⟨2719/125000,10987/500000⟩ + | 19 => ⟨501/250000,469/200000⟩ + | 20 => ⟨15287/1000000,243/15625⟩ + | 21 => ⟨25297/1000000,25671/1000000⟩ + | 22 => ⟨14701/1000000,14957/1000000⟩ + | 23 => ⟨1011/250000,67/15625⟩ + | 24 => ⟨537/1000000,129/200000⟩ + | 25 => ⟨9/500000,49/1000000⟩ + | 26 => ⟨-3/1000000,1/250000⟩ + | 27 => ⟨-1/1000000,1/500000⟩ + | 28 => ⟨-1/1000000,1/1000000⟩ + | 29 => ⟨-1/1000000,1/1000000⟩ + | 30 => ⟨-1/1000000,1/1000000⟩ + | 31 => ⟨-1/1000000,1/1000000⟩ + | 32 => ⟨-1/1000000,1/1000000⟩ + | 33 => ⟨-1/1000000,1/1000000⟩ + | 34 => ⟨-1/1000000,1/1000000⟩ + | 35 => ⟨-1/1000000,1/1000000⟩ + | 36 => ⟨-1/1000000,1/1000000⟩ + | 37 => ⟨-1/1000000,1/1000000⟩ + | 38 => ⟨-1/1000000,1/1000000⟩ + | 39 => ⟨-1/1000000,1/1000000⟩ + | _ => Box.rat 0 + +lemma check_0 : expression.check (-10+(0:ℚ)*(5*(1/10))) (1/10) 5 (blocks 0) = true := by decide +kernel +lemma check_1 : expression.check (-10+(1:ℚ)*(5*(1/10))) (1/10) 5 (blocks 1) = true := by decide +kernel +lemma check_2 : expression.check (-10+(2:ℚ)*(5*(1/10))) (1/10) 5 (blocks 2) = true := by decide +kernel +lemma check_3 : expression.check (-10+(3:ℚ)*(5*(1/10))) (1/10) 5 (blocks 3) = true := by decide +kernel +lemma check_4 : expression.check (-10+(4:ℚ)*(5*(1/10))) (1/10) 5 (blocks 4) = true := by decide +kernel +lemma check_5 : expression.check (-10+(5:ℚ)*(5*(1/10))) (1/10) 5 (blocks 5) = true := by decide +kernel +lemma check_6 : expression.check (-10+(6:ℚ)*(5*(1/10))) (1/10) 5 (blocks 6) = true := by decide +kernel +lemma check_7 : expression.check (-10+(7:ℚ)*(5*(1/10))) (1/10) 5 (blocks 7) = true := by decide +kernel +lemma check_8 : expression.check (-10+(8:ℚ)*(5*(1/10))) (1/10) 5 (blocks 8) = true := by decide +kernel +lemma check_9 : expression.check (-10+(9:ℚ)*(5*(1/10))) (1/10) 5 (blocks 9) = true := by decide +kernel +lemma check_10 : expression.check (-10+(10:ℚ)*(5*(1/10))) (1/10) 5 (blocks 10) = true := by decide +kernel +lemma check_11 : expression.check (-10+(11:ℚ)*(5*(1/10))) (1/10) 5 (blocks 11) = true := by decide +kernel +lemma check_12 : expression.check (-10+(12:ℚ)*(5*(1/10))) (1/10) 5 (blocks 12) = true := by decide +kernel +lemma check_13 : expression.check (-10+(13:ℚ)*(5*(1/10))) (1/10) 5 (blocks 13) = true := by decide +kernel +lemma check_14 : expression.check (-10+(14:ℚ)*(5*(1/10))) (1/10) 5 (blocks 14) = true := by decide +kernel +lemma check_15 : expression.check (-10+(15:ℚ)*(5*(1/10))) (1/10) 5 (blocks 15) = true := by decide +kernel +lemma check_16 : expression.check (-10+(16:ℚ)*(5*(1/10))) (1/10) 5 (blocks 16) = true := by decide +kernel +lemma check_17 : expression.check (-10+(17:ℚ)*(5*(1/10))) (1/10) 5 (blocks 17) = true := by decide +kernel +lemma check_18 : expression.check (-10+(18:ℚ)*(5*(1/10))) (1/10) 5 (blocks 18) = true := by decide +kernel +lemma check_19 : expression.check (-10+(19:ℚ)*(5*(1/10))) (1/10) 5 (blocks 19) = true := by decide +kernel +lemma check_20 : expression.check (-10+(20:ℚ)*(5*(1/10))) (1/10) 5 (blocks 20) = true := by decide +kernel +lemma check_21 : expression.check (-10+(21:ℚ)*(5*(1/10))) (1/10) 5 (blocks 21) = true := by decide +kernel +lemma check_22 : expression.check (-10+(22:ℚ)*(5*(1/10))) (1/10) 5 (blocks 22) = true := by decide +kernel +lemma check_23 : expression.check (-10+(23:ℚ)*(5*(1/10))) (1/10) 5 (blocks 23) = true := by decide +kernel +lemma check_24 : expression.check (-10+(24:ℚ)*(5*(1/10))) (1/10) 5 (blocks 24) = true := by decide +kernel +lemma check_25 : expression.check (-10+(25:ℚ)*(5*(1/10))) (1/10) 5 (blocks 25) = true := by decide +kernel +lemma check_26 : expression.check (-10+(26:ℚ)*(5*(1/10))) (1/10) 5 (blocks 26) = true := by decide +kernel +lemma check_27 : expression.check (-10+(27:ℚ)*(5*(1/10))) (1/10) 5 (blocks 27) = true := by decide +kernel +lemma check_28 : expression.check (-10+(28:ℚ)*(5*(1/10))) (1/10) 5 (blocks 28) = true := by decide +kernel +lemma check_29 : expression.check (-10+(29:ℚ)*(5*(1/10))) (1/10) 5 (blocks 29) = true := by decide +kernel +lemma check_30 : expression.check (-10+(30:ℚ)*(5*(1/10))) (1/10) 5 (blocks 30) = true := by decide +kernel +lemma check_31 : expression.check (-10+(31:ℚ)*(5*(1/10))) (1/10) 5 (blocks 31) = true := by decide +kernel +lemma check_32 : expression.check (-10+(32:ℚ)*(5*(1/10))) (1/10) 5 (blocks 32) = true := by decide +kernel +lemma check_33 : expression.check (-10+(33:ℚ)*(5*(1/10))) (1/10) 5 (blocks 33) = true := by decide +kernel +lemma check_34 : expression.check (-10+(34:ℚ)*(5*(1/10))) (1/10) 5 (blocks 34) = true := by decide +kernel +lemma check_35 : expression.check (-10+(35:ℚ)*(5*(1/10))) (1/10) 5 (blocks 35) = true := by decide +kernel +lemma check_36 : expression.check (-10+(36:ℚ)*(5*(1/10))) (1/10) 5 (blocks 36) = true := by decide +kernel +lemma check_37 : expression.check (-10+(37:ℚ)*(5*(1/10))) (1/10) 5 (blocks 37) = true := by decide +kernel +lemma check_38 : expression.check (-10+(38:ℚ)*(5*(1/10))) (1/10) 5 (blocks 38) = true := by decide +kernel +lemma check_39 : expression.check (-10+(39:ℚ)*(5*(1/10))) (1/10) 5 (blocks 39) = true := by decide +kernel + +lemma checks (i : ℕ) (hi : i < 40) : + expression.check (-10+(i:ℚ)*(5*(1/10))) (1/10) 5 (blocks i) = true := by + interval_cases i + · exact check_0 + · exact check_1 + · exact check_2 + · exact check_3 + · exact check_4 + · exact check_5 + · exact check_6 + · exact check_7 + · exact check_8 + · exact check_9 + · exact check_10 + · exact check_11 + · exact check_12 + · exact check_13 + · exact check_14 + · exact check_15 + · exact check_16 + · exact check_17 + · exact check_18 + · exact check_19 + · exact check_20 + · exact check_21 + · exact check_22 + · exact check_23 + · exact check_24 + · exact check_25 + · exact check_26 + · exact check_27 + · exact check_28 + · exact check_29 + · exact check_30 + · exact check_31 + · exact check_32 + · exact check_33 + · exact check_34 + · exact check_35 + · exact check_36 + · exact check_37 + · exact check_38 + · exact check_39 + +theorem integral_bound : + (∫ h, scalarFunction (19/40) (406349/500000) (66273/125000) (28579/250000) (135787/200000) 6 h ∂Scalar.fieldLaw (19/40)) ∈ (⟨0,1024/15625⟩ : Box) := by + apply gaussian_certificate (e := expression) (B := blocks) (h := (1/10)) (k := 5) (by norm_num) + · simpa only [expression,Rat.cast_div,Rat.cast_ofNat,Rat.cast_one,Rat.cast_zero] using integrandExpr_val (19/40) (406349/500000) (66273/125000) (28579/250000) (135787/200000) 6 + · exact (continuous_scalarFunction _ _ _ _ _ _).measurable + · intro x + apply scalarFunction_bound <;> norm_num + · exact checks + · decide +kernel + +end SKRatio.Certificate.Data.J3K6 + +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Certificates/ScalarDataJ3K7.lean b/lean/OAI/Probability/SKRatio/Certificates/ScalarDataJ3K7.lean new file mode 100644 index 0000000000000000000000000000000000000000..140cbb4ef5780647faaa67b4e02ebfb0c8323ac7 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Certificates/ScalarDataJ3K7.lean @@ -0,0 +1,154 @@ +import Mathlib +import OAI.Probability.SKRatio.Certificates.CertifiedBatches +import OAI.Probability.SKRatio.Certificates.CertifiedFunctionBounds + +namespace OAI + +noncomputable section +open Real MeasureTheory +namespace SKRatio.Certificate.Data.J3K7 + +def expression : Expr := integrandExpr (19/40) (406349/500000) (66273/125000) (28579/250000) (135787/200000) 7 +def blocks : ℕ → Box + | 0 => ⟨-1/1000000,1/1000000⟩ + | 1 => ⟨-1/1000000,1/1000000⟩ + | 2 => ⟨-1/1000000,1/1000000⟩ + | 3 => ⟨-1/1000000,1/1000000⟩ + | 4 => ⟨-1/1000000,1/1000000⟩ + | 5 => ⟨-1/1000000,1/1000000⟩ + | 6 => ⟨-1/1000000,1/1000000⟩ + | 7 => ⟨-1/1000000,1/1000000⟩ + | 8 => ⟨0,1/1000000⟩ + | 9 => ⟨1/250000,3/500000⟩ + | 10 => ⟨1/20000,27/500000⟩ + | 11 => ⟨209/500000,433/1000000⟩ + | 12 => ⟨2691/1000000,2761/1000000⟩ + | 13 => ⟨541/40000,13767/1000000⟩ + | 14 => ⟨52109/1000000,52697/1000000⟩ + | 15 => ⟨147861/1000000,18581/125000⟩ + | 16 => ⟨8941/31250,287393/1000000⟩ + | 17 => ⟨16551/50000,1667/5000⟩ + | 18 => ⟨21621/125000,21779/125000⟩ + | 19 => ⟨3217/200000,1821/100000⟩ + | 20 => ⟨10581/125000,85953/1000000⟩ + | 21 => ⟨20437/100000,206681/1000000⟩ + | 22 => ⟨96671/500000,9757/50000⟩ + | 23 => ⟨110183/1000000,111621/1000000⟩ + | 24 => ⟨44983/1000000,11531/250000⟩ + | 25 => ⟨7191/500000,3739/250000⟩ + | 26 => ⟨3721/1000000,1967/500000⟩ + | 27 => ⟨39/50000,21/25000⟩ + | 28 => ⟨13/100000,9/62500⟩ + | 29 => ⟨17/1000000,1/50000⟩ + | 30 => ⟨1/1000000,3/1000000⟩ + | 31 => ⟨-1/1000000,1/1000000⟩ + | 32 => ⟨-1/1000000,1/1000000⟩ + | 33 => ⟨-1/1000000,1/1000000⟩ + | 34 => ⟨-1/1000000,1/1000000⟩ + | 35 => ⟨-1/1000000,1/1000000⟩ + | 36 => ⟨-1/1000000,1/1000000⟩ + | 37 => ⟨-1/1000000,1/1000000⟩ + | 38 => ⟨-1/1000000,1/1000000⟩ + | 39 => ⟨-1/1000000,1/1000000⟩ + | _ => Box.rat 0 + +lemma check_0 : expression.check (-10+(0:ℚ)*(5*(1/10))) (1/10) 5 (blocks 0) = true := by decide +kernel +lemma check_1 : expression.check (-10+(1:ℚ)*(5*(1/10))) (1/10) 5 (blocks 1) = true := by decide +kernel +lemma check_2 : expression.check (-10+(2:ℚ)*(5*(1/10))) (1/10) 5 (blocks 2) = true := by decide +kernel +lemma check_3 : expression.check (-10+(3:ℚ)*(5*(1/10))) (1/10) 5 (blocks 3) = true := by decide +kernel +lemma check_4 : expression.check (-10+(4:ℚ)*(5*(1/10))) (1/10) 5 (blocks 4) = true := by decide +kernel +lemma check_5 : expression.check (-10+(5:ℚ)*(5*(1/10))) (1/10) 5 (blocks 5) = true := by decide +kernel +lemma check_6 : expression.check (-10+(6:ℚ)*(5*(1/10))) (1/10) 5 (blocks 6) = true := by decide +kernel +lemma check_7 : expression.check (-10+(7:ℚ)*(5*(1/10))) (1/10) 5 (blocks 7) = true := by decide +kernel +lemma check_8 : expression.check (-10+(8:ℚ)*(5*(1/10))) (1/10) 5 (blocks 8) = true := by decide +kernel +lemma check_9 : expression.check (-10+(9:ℚ)*(5*(1/10))) (1/10) 5 (blocks 9) = true := by decide +kernel +lemma check_10 : expression.check (-10+(10:ℚ)*(5*(1/10))) (1/10) 5 (blocks 10) = true := by decide +kernel +lemma check_11 : expression.check (-10+(11:ℚ)*(5*(1/10))) (1/10) 5 (blocks 11) = true := by decide +kernel +lemma check_12 : expression.check (-10+(12:ℚ)*(5*(1/10))) (1/10) 5 (blocks 12) = true := by decide +kernel +lemma check_13 : expression.check (-10+(13:ℚ)*(5*(1/10))) (1/10) 5 (blocks 13) = true := by decide +kernel +lemma check_14 : expression.check (-10+(14:ℚ)*(5*(1/10))) (1/10) 5 (blocks 14) = true := by decide +kernel +lemma check_15 : expression.check (-10+(15:ℚ)*(5*(1/10))) (1/10) 5 (blocks 15) = true := by decide +kernel +lemma check_16 : expression.check (-10+(16:ℚ)*(5*(1/10))) (1/10) 5 (blocks 16) = true := by decide +kernel +lemma check_17 : expression.check (-10+(17:ℚ)*(5*(1/10))) (1/10) 5 (blocks 17) = true := by decide +kernel +lemma check_18 : expression.check (-10+(18:ℚ)*(5*(1/10))) (1/10) 5 (blocks 18) = true := by decide +kernel +lemma check_19 : expression.check (-10+(19:ℚ)*(5*(1/10))) (1/10) 5 (blocks 19) = true := by decide +kernel +lemma check_20 : expression.check (-10+(20:ℚ)*(5*(1/10))) (1/10) 5 (blocks 20) = true := by decide +kernel +lemma check_21 : expression.check (-10+(21:ℚ)*(5*(1/10))) (1/10) 5 (blocks 21) = true := by decide +kernel +lemma check_22 : expression.check (-10+(22:ℚ)*(5*(1/10))) (1/10) 5 (blocks 22) = true := by decide +kernel +lemma check_23 : expression.check (-10+(23:ℚ)*(5*(1/10))) (1/10) 5 (blocks 23) = true := by decide +kernel +lemma check_24 : expression.check (-10+(24:ℚ)*(5*(1/10))) (1/10) 5 (blocks 24) = true := by decide +kernel +lemma check_25 : expression.check (-10+(25:ℚ)*(5*(1/10))) (1/10) 5 (blocks 25) = true := by decide +kernel +lemma check_26 : expression.check (-10+(26:ℚ)*(5*(1/10))) (1/10) 5 (blocks 26) = true := by decide +kernel +lemma check_27 : expression.check (-10+(27:ℚ)*(5*(1/10))) (1/10) 5 (blocks 27) = true := by decide +kernel +lemma check_28 : expression.check (-10+(28:ℚ)*(5*(1/10))) (1/10) 5 (blocks 28) = true := by decide +kernel +lemma check_29 : expression.check (-10+(29:ℚ)*(5*(1/10))) (1/10) 5 (blocks 29) = true := by decide +kernel +lemma check_30 : expression.check (-10+(30:ℚ)*(5*(1/10))) (1/10) 5 (blocks 30) = true := by decide +kernel +lemma check_31 : expression.check (-10+(31:ℚ)*(5*(1/10))) (1/10) 5 (blocks 31) = true := by decide +kernel +lemma check_32 : expression.check (-10+(32:ℚ)*(5*(1/10))) (1/10) 5 (blocks 32) = true := by decide +kernel +lemma check_33 : expression.check (-10+(33:ℚ)*(5*(1/10))) (1/10) 5 (blocks 33) = true := by decide +kernel +lemma check_34 : expression.check (-10+(34:ℚ)*(5*(1/10))) (1/10) 5 (blocks 34) = true := by decide +kernel +lemma check_35 : expression.check (-10+(35:ℚ)*(5*(1/10))) (1/10) 5 (blocks 35) = true := by decide +kernel +lemma check_36 : expression.check (-10+(36:ℚ)*(5*(1/10))) (1/10) 5 (blocks 36) = true := by decide +kernel +lemma check_37 : expression.check (-10+(37:ℚ)*(5*(1/10))) (1/10) 5 (blocks 37) = true := by decide +kernel +lemma check_38 : expression.check (-10+(38:ℚ)*(5*(1/10))) (1/10) 5 (blocks 38) = true := by decide +kernel +lemma check_39 : expression.check (-10+(39:ℚ)*(5*(1/10))) (1/10) 5 (blocks 39) = true := by decide +kernel + +lemma checks (i : ℕ) (hi : i < 40) : + expression.check (-10+(i:ℚ)*(5*(1/10))) (1/10) 5 (blocks i) = true := by + interval_cases i + · exact check_0 + · exact check_1 + · exact check_2 + · exact check_3 + · exact check_4 + · exact check_5 + · exact check_6 + · exact check_7 + · exact check_8 + · exact check_9 + · exact check_10 + · exact check_11 + · exact check_12 + · exact check_13 + · exact check_14 + · exact check_15 + · exact check_16 + · exact check_17 + · exact check_18 + · exact check_19 + · exact check_20 + · exact check_21 + · exact check_22 + · exact check_23 + · exact check_24 + · exact check_25 + · exact check_26 + · exact check_27 + · exact check_28 + · exact check_29 + · exact check_30 + · exact check_31 + · exact check_32 + · exact check_33 + · exact check_34 + · exact check_35 + · exact check_36 + · exact check_37 + · exact check_38 + · exact check_39 + +theorem integral_bound : + (∫ h, scalarFunction (19/40) (406349/500000) (66273/125000) (28579/250000) (135787/200000) 7 h ∂Scalar.fieldLaw (19/40)) ∈ (⟨0,677329/1000000⟩ : Box) := by + apply gaussian_certificate (e := expression) (B := blocks) (h := (1/10)) (k := 5) (by norm_num) + · simpa only [expression,Rat.cast_div,Rat.cast_ofNat,Rat.cast_one,Rat.cast_zero] using integrandExpr_val (19/40) (406349/500000) (66273/125000) (28579/250000) (135787/200000) 7 + · exact (continuous_scalarFunction _ _ _ _ _ _).measurable + · intro x + apply scalarFunction_bound <;> norm_num + · exact checks + · decide +kernel + +end SKRatio.Certificate.Data.J3K7 + +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Certificates/ScalarDataJ4K0.lean b/lean/OAI/Probability/SKRatio/Certificates/ScalarDataJ4K0.lean new file mode 100644 index 0000000000000000000000000000000000000000..9df0779704d032a94fc3b8f20bb9a4540e7636b4 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Certificates/ScalarDataJ4K0.lean @@ -0,0 +1,154 @@ +import Mathlib +import OAI.Probability.SKRatio.Certificates.CertifiedBatches +import OAI.Probability.SKRatio.Certificates.CertifiedFunctionBounds + +namespace OAI + +noncomputable section +open Real MeasureTheory +namespace SKRatio.Certificate.Data.J4K0 + +def expression : Expr := integrandExpr (1/2) (397973/500000) (524071/1000000) (119553/1000000) (702377/1000000) 0 +def blocks : ℕ → Box + | 0 => ⟨-1/1000000,1/1000000⟩ + | 1 => ⟨-1/1000000,1/1000000⟩ + | 2 => ⟨-1/1000000,1/1000000⟩ + | 3 => ⟨-1/1000000,1/1000000⟩ + | 4 => ⟨-1/1000000,1/1000000⟩ + | 5 => ⟨-1/1000000,1/1000000⟩ + | 6 => ⟨-1/1000000,1/1000000⟩ + | 7 => ⟨-1/1000000,1/1000000⟩ + | 8 => ⟨-1/1000000,1/1000000⟩ + | 9 => ⟨-1/1000000,1/1000000⟩ + | 10 => ⟨0,1/1000000⟩ + | 11 => ⟨3/500000,1/125000⟩ + | 12 => ⟨77/1000000,41/500000⟩ + | 13 => ⟨67/100000,693/1000000⟩ + | 14 => ⟨4403/1000000,4503/1000000⟩ + | 15 => ⟨5403/250000,21923/1000000⟩ + | 16 => ⟨19471/250000,78473/1000000⟩ + | 17 => ⟨100889/500000,202261/1000000⟩ + | 18 => ⟨23017/62500,14753/40000⟩ + | 19 => ⟨117183/250000,234963/500000⟩ + | 20 => ⟨83387/200000,417801/1000000⟩ + | 21 => ⟨32761/125000,131267/500000⟩ + | 22 => ⟨118399/1000000,2383/20000⟩ + | 23 => ⟨39281/1000000,39849/1000000⟩ + | 24 => ⟨9741/1000000,2503/250000⟩ + | 25 => ⟨1827/1000000,1921/1000000⟩ + | 26 => ⟨13/50000,143/500000⟩ + | 27 => ⟨7/250000,17/500000⟩ + | 28 => ⟨1/500000,1/250000⟩ + | 29 => ⟨-1/1000000,1/1000000⟩ + | 30 => ⟨-1/1000000,1/1000000⟩ + | 31 => ⟨-1/1000000,1/1000000⟩ + | 32 => ⟨-1/1000000,1/1000000⟩ + | 33 => ⟨-1/1000000,1/1000000⟩ + | 34 => ⟨-1/1000000,1/1000000⟩ + | 35 => ⟨-1/1000000,1/1000000⟩ + | 36 => ⟨-1/1000000,1/1000000⟩ + | 37 => ⟨-1/1000000,1/1000000⟩ + | 38 => ⟨-1/1000000,1/1000000⟩ + | 39 => ⟨-1/1000000,1/1000000⟩ + | _ => Box.rat 0 + +lemma check_0 : expression.check (-10+(0:ℚ)*(5*(1/10))) (1/10) 5 (blocks 0) = true := by decide +kernel +lemma check_1 : expression.check (-10+(1:ℚ)*(5*(1/10))) (1/10) 5 (blocks 1) = true := by decide +kernel +lemma check_2 : expression.check (-10+(2:ℚ)*(5*(1/10))) (1/10) 5 (blocks 2) = true := by decide +kernel +lemma check_3 : expression.check (-10+(3:ℚ)*(5*(1/10))) (1/10) 5 (blocks 3) = true := by decide +kernel +lemma check_4 : expression.check (-10+(4:ℚ)*(5*(1/10))) (1/10) 5 (blocks 4) = true := by decide +kernel +lemma check_5 : expression.check (-10+(5:ℚ)*(5*(1/10))) (1/10) 5 (blocks 5) = true := by decide +kernel +lemma check_6 : expression.check (-10+(6:ℚ)*(5*(1/10))) (1/10) 5 (blocks 6) = true := by decide +kernel +lemma check_7 : expression.check (-10+(7:ℚ)*(5*(1/10))) (1/10) 5 (blocks 7) = true := by decide +kernel +lemma check_8 : expression.check (-10+(8:ℚ)*(5*(1/10))) (1/10) 5 (blocks 8) = true := by decide +kernel +lemma check_9 : expression.check (-10+(9:ℚ)*(5*(1/10))) (1/10) 5 (blocks 9) = true := by decide +kernel +lemma check_10 : expression.check (-10+(10:ℚ)*(5*(1/10))) (1/10) 5 (blocks 10) = true := by decide +kernel +lemma check_11 : expression.check (-10+(11:ℚ)*(5*(1/10))) (1/10) 5 (blocks 11) = true := by decide +kernel +lemma check_12 : expression.check (-10+(12:ℚ)*(5*(1/10))) (1/10) 5 (blocks 12) = true := by decide +kernel +lemma check_13 : expression.check (-10+(13:ℚ)*(5*(1/10))) (1/10) 5 (blocks 13) = true := by decide +kernel +lemma check_14 : expression.check (-10+(14:ℚ)*(5*(1/10))) (1/10) 5 (blocks 14) = true := by decide +kernel +lemma check_15 : expression.check (-10+(15:ℚ)*(5*(1/10))) (1/10) 5 (blocks 15) = true := by decide +kernel +lemma check_16 : expression.check (-10+(16:ℚ)*(5*(1/10))) (1/10) 5 (blocks 16) = true := by decide +kernel +lemma check_17 : expression.check (-10+(17:ℚ)*(5*(1/10))) (1/10) 5 (blocks 17) = true := by decide +kernel +lemma check_18 : expression.check (-10+(18:ℚ)*(5*(1/10))) (1/10) 5 (blocks 18) = true := by decide +kernel +lemma check_19 : expression.check (-10+(19:ℚ)*(5*(1/10))) (1/10) 5 (blocks 19) = true := by decide +kernel +lemma check_20 : expression.check (-10+(20:ℚ)*(5*(1/10))) (1/10) 5 (blocks 20) = true := by decide +kernel +lemma check_21 : expression.check (-10+(21:ℚ)*(5*(1/10))) (1/10) 5 (blocks 21) = true := by decide +kernel +lemma check_22 : expression.check (-10+(22:ℚ)*(5*(1/10))) (1/10) 5 (blocks 22) = true := by decide +kernel +lemma check_23 : expression.check (-10+(23:ℚ)*(5*(1/10))) (1/10) 5 (blocks 23) = true := by decide +kernel +lemma check_24 : expression.check (-10+(24:ℚ)*(5*(1/10))) (1/10) 5 (blocks 24) = true := by decide +kernel +lemma check_25 : expression.check (-10+(25:ℚ)*(5*(1/10))) (1/10) 5 (blocks 25) = true := by decide +kernel +lemma check_26 : expression.check (-10+(26:ℚ)*(5*(1/10))) (1/10) 5 (blocks 26) = true := by decide +kernel +lemma check_27 : expression.check (-10+(27:ℚ)*(5*(1/10))) (1/10) 5 (blocks 27) = true := by decide +kernel +lemma check_28 : expression.check (-10+(28:ℚ)*(5*(1/10))) (1/10) 5 (blocks 28) = true := by decide +kernel +lemma check_29 : expression.check (-10+(29:ℚ)*(5*(1/10))) (1/10) 5 (blocks 29) = true := by decide +kernel +lemma check_30 : expression.check (-10+(30:ℚ)*(5*(1/10))) (1/10) 5 (blocks 30) = true := by decide +kernel +lemma check_31 : expression.check (-10+(31:ℚ)*(5*(1/10))) (1/10) 5 (blocks 31) = true := by decide +kernel +lemma check_32 : expression.check (-10+(32:ℚ)*(5*(1/10))) (1/10) 5 (blocks 32) = true := by decide +kernel +lemma check_33 : expression.check (-10+(33:ℚ)*(5*(1/10))) (1/10) 5 (blocks 33) = true := by decide +kernel +lemma check_34 : expression.check (-10+(34:ℚ)*(5*(1/10))) (1/10) 5 (blocks 34) = true := by decide +kernel +lemma check_35 : expression.check (-10+(35:ℚ)*(5*(1/10))) (1/10) 5 (blocks 35) = true := by decide +kernel +lemma check_36 : expression.check (-10+(36:ℚ)*(5*(1/10))) (1/10) 5 (blocks 36) = true := by decide +kernel +lemma check_37 : expression.check (-10+(37:ℚ)*(5*(1/10))) (1/10) 5 (blocks 37) = true := by decide +kernel +lemma check_38 : expression.check (-10+(38:ℚ)*(5*(1/10))) (1/10) 5 (blocks 38) = true := by decide +kernel +lemma check_39 : expression.check (-10+(39:ℚ)*(5*(1/10))) (1/10) 5 (blocks 39) = true := by decide +kernel + +lemma checks (i : ℕ) (hi : i < 40) : + expression.check (-10+(i:ℚ)*(5*(1/10))) (1/10) 5 (blocks i) = true := by + interval_cases i + · exact check_0 + · exact check_1 + · exact check_2 + · exact check_3 + · exact check_4 + · exact check_5 + · exact check_6 + · exact check_7 + · exact check_8 + · exact check_9 + · exact check_10 + · exact check_11 + · exact check_12 + · exact check_13 + · exact check_14 + · exact check_15 + · exact check_16 + · exact check_17 + · exact check_18 + · exact check_19 + · exact check_20 + · exact check_21 + · exact check_22 + · exact check_23 + · exact check_24 + · exact check_25 + · exact check_26 + · exact check_27 + · exact check_28 + · exact check_29 + · exact check_30 + · exact check_31 + · exact check_32 + · exact check_33 + · exact check_34 + · exact check_35 + · exact check_36 + · exact check_37 + · exact check_38 + · exact check_39 + +theorem integral_bound : + (∫ h, scalarFunction (1/2) (397973/500000) (524071/1000000) (119553/1000000) (702377/1000000) 0 h ∂Scalar.fieldLaw (1/2)) ∈ (⟨397223/500000,398723/500000⟩ : Box) := by + apply gaussian_certificate (e := expression) (B := blocks) (h := (1/10)) (k := 5) (by norm_num) + · simpa only [expression,Rat.cast_div,Rat.cast_ofNat,Rat.cast_one,Rat.cast_zero] using integrandExpr_val (1/2) (397973/500000) (524071/1000000) (119553/1000000) (702377/1000000) 0 + · exact (continuous_scalarFunction _ _ _ _ _ _).measurable + · intro x + apply scalarFunction_bound <;> norm_num + · exact checks + · decide +kernel + +end SKRatio.Certificate.Data.J4K0 + +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Certificates/ScalarDataJ4K1.lean b/lean/OAI/Probability/SKRatio/Certificates/ScalarDataJ4K1.lean new file mode 100644 index 0000000000000000000000000000000000000000..49f0e4b34fc7c29cf00e1fb8d26077bca232c97e --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Certificates/ScalarDataJ4K1.lean @@ -0,0 +1,154 @@ +import Mathlib +import OAI.Probability.SKRatio.Certificates.CertifiedBatches +import OAI.Probability.SKRatio.Certificates.CertifiedFunctionBounds + +namespace OAI + +noncomputable section +open Real MeasureTheory +namespace SKRatio.Certificate.Data.J4K1 + +def expression : Expr := integrandExpr (1/2) (397973/500000) (524071/1000000) (119553/1000000) (702377/1000000) 1 +def blocks : ℕ → Box + | 0 => ⟨-1/1000000,1/1000000⟩ + | 1 => ⟨-1/1000000,1/1000000⟩ + | 2 => ⟨-1/1000000,1/1000000⟩ + | 3 => ⟨-1/1000000,1/1000000⟩ + | 4 => ⟨-1/1000000,1/1000000⟩ + | 5 => ⟨-1/1000000,1/1000000⟩ + | 6 => ⟨-1/1000000,1/1000000⟩ + | 7 => ⟨-1/1000000,1/1000000⟩ + | 8 => ⟨-1/1000000,1/1000000⟩ + | 9 => ⟨-1/1000000,1/1000000⟩ + | 10 => ⟨-1/1000000,1/1000000⟩ + | 11 => ⟨1/500000,3/1000000⟩ + | 12 => ⟨7/250000,31/1000000⟩ + | 13 => ⟨51/200000,53/200000⟩ + | 14 => ⟨1729/1000000,1771/1000000⟩ + | 15 => ⟨2217/250000,901/100000⟩ + | 16 => ⟨34073/1000000,8597/250000⟩ + | 17 => ⟨96503/1000000,48441/500000⟩ + | 18 => ⟨39577/200000,198111/1000000⟩ + | 19 => ⟨28907/100000,1159/4000⟩ + | 20 => ⟨298503/1000000,149679/500000⟩ + | 21 => ⟨217367/1000000,108949/500000⟩ + | 22 => ⟨27989/250000,56327/500000⟩ + | 23 => ⟨10317/250000,10479/250000⟩ + | 24 => ⟨5533/500000,5707/500000⟩ + | 25 => ⟨2189/1000000,2321/1000000⟩ + | 26 => ⟨161/500000,9/25000⟩ + | 27 => ⟨7/200000,11/250000⟩ + | 28 => ⟨1/500000,1/200000⟩ + | 29 => ⟨-1/1000000,1/1000000⟩ + | 30 => ⟨-1/1000000,1/1000000⟩ + | 31 => ⟨-1/1000000,1/1000000⟩ + | 32 => ⟨-1/1000000,1/1000000⟩ + | 33 => ⟨-1/1000000,1/1000000⟩ + | 34 => ⟨-1/1000000,1/1000000⟩ + | 35 => ⟨-1/1000000,1/1000000⟩ + | 36 => ⟨-1/1000000,1/1000000⟩ + | 37 => ⟨-1/1000000,1/1000000⟩ + | 38 => ⟨-1/1000000,1/1000000⟩ + | 39 => ⟨-1/1000000,1/1000000⟩ + | _ => Box.rat 0 + +lemma check_0 : expression.check (-10+(0:ℚ)*(5*(1/10))) (1/10) 5 (blocks 0) = true := by decide +kernel +lemma check_1 : expression.check (-10+(1:ℚ)*(5*(1/10))) (1/10) 5 (blocks 1) = true := by decide +kernel +lemma check_2 : expression.check (-10+(2:ℚ)*(5*(1/10))) (1/10) 5 (blocks 2) = true := by decide +kernel +lemma check_3 : expression.check (-10+(3:ℚ)*(5*(1/10))) (1/10) 5 (blocks 3) = true := by decide +kernel +lemma check_4 : expression.check (-10+(4:ℚ)*(5*(1/10))) (1/10) 5 (blocks 4) = true := by decide +kernel +lemma check_5 : expression.check (-10+(5:ℚ)*(5*(1/10))) (1/10) 5 (blocks 5) = true := by decide +kernel +lemma check_6 : expression.check (-10+(6:ℚ)*(5*(1/10))) (1/10) 5 (blocks 6) = true := by decide +kernel +lemma check_7 : expression.check (-10+(7:ℚ)*(5*(1/10))) (1/10) 5 (blocks 7) = true := by decide +kernel +lemma check_8 : expression.check (-10+(8:ℚ)*(5*(1/10))) (1/10) 5 (blocks 8) = true := by decide +kernel +lemma check_9 : expression.check (-10+(9:ℚ)*(5*(1/10))) (1/10) 5 (blocks 9) = true := by decide +kernel +lemma check_10 : expression.check (-10+(10:ℚ)*(5*(1/10))) (1/10) 5 (blocks 10) = true := by decide +kernel +lemma check_11 : expression.check (-10+(11:ℚ)*(5*(1/10))) (1/10) 5 (blocks 11) = true := by decide +kernel +lemma check_12 : expression.check (-10+(12:ℚ)*(5*(1/10))) (1/10) 5 (blocks 12) = true := by decide +kernel +lemma check_13 : expression.check (-10+(13:ℚ)*(5*(1/10))) (1/10) 5 (blocks 13) = true := by decide +kernel +lemma check_14 : expression.check (-10+(14:ℚ)*(5*(1/10))) (1/10) 5 (blocks 14) = true := by decide +kernel +lemma check_15 : expression.check (-10+(15:ℚ)*(5*(1/10))) (1/10) 5 (blocks 15) = true := by decide +kernel +lemma check_16 : expression.check (-10+(16:ℚ)*(5*(1/10))) (1/10) 5 (blocks 16) = true := by decide +kernel +lemma check_17 : expression.check (-10+(17:ℚ)*(5*(1/10))) (1/10) 5 (blocks 17) = true := by decide +kernel +lemma check_18 : expression.check (-10+(18:ℚ)*(5*(1/10))) (1/10) 5 (blocks 18) = true := by decide +kernel +lemma check_19 : expression.check (-10+(19:ℚ)*(5*(1/10))) (1/10) 5 (blocks 19) = true := by decide +kernel +lemma check_20 : expression.check (-10+(20:ℚ)*(5*(1/10))) (1/10) 5 (blocks 20) = true := by decide +kernel +lemma check_21 : expression.check (-10+(21:ℚ)*(5*(1/10))) (1/10) 5 (blocks 21) = true := by decide +kernel +lemma check_22 : expression.check (-10+(22:ℚ)*(5*(1/10))) (1/10) 5 (blocks 22) = true := by decide +kernel +lemma check_23 : expression.check (-10+(23:ℚ)*(5*(1/10))) (1/10) 5 (blocks 23) = true := by decide +kernel +lemma check_24 : expression.check (-10+(24:ℚ)*(5*(1/10))) (1/10) 5 (blocks 24) = true := by decide +kernel +lemma check_25 : expression.check (-10+(25:ℚ)*(5*(1/10))) (1/10) 5 (blocks 25) = true := by decide +kernel +lemma check_26 : expression.check (-10+(26:ℚ)*(5*(1/10))) (1/10) 5 (blocks 26) = true := by decide +kernel +lemma check_27 : expression.check (-10+(27:ℚ)*(5*(1/10))) (1/10) 5 (blocks 27) = true := by decide +kernel +lemma check_28 : expression.check (-10+(28:ℚ)*(5*(1/10))) (1/10) 5 (blocks 28) = true := by decide +kernel +lemma check_29 : expression.check (-10+(29:ℚ)*(5*(1/10))) (1/10) 5 (blocks 29) = true := by decide +kernel +lemma check_30 : expression.check (-10+(30:ℚ)*(5*(1/10))) (1/10) 5 (blocks 30) = true := by decide +kernel +lemma check_31 : expression.check (-10+(31:ℚ)*(5*(1/10))) (1/10) 5 (blocks 31) = true := by decide +kernel +lemma check_32 : expression.check (-10+(32:ℚ)*(5*(1/10))) (1/10) 5 (blocks 32) = true := by decide +kernel +lemma check_33 : expression.check (-10+(33:ℚ)*(5*(1/10))) (1/10) 5 (blocks 33) = true := by decide +kernel +lemma check_34 : expression.check (-10+(34:ℚ)*(5*(1/10))) (1/10) 5 (blocks 34) = true := by decide +kernel +lemma check_35 : expression.check (-10+(35:ℚ)*(5*(1/10))) (1/10) 5 (blocks 35) = true := by decide +kernel +lemma check_36 : expression.check (-10+(36:ℚ)*(5*(1/10))) (1/10) 5 (blocks 36) = true := by decide +kernel +lemma check_37 : expression.check (-10+(37:ℚ)*(5*(1/10))) (1/10) 5 (blocks 37) = true := by decide +kernel +lemma check_38 : expression.check (-10+(38:ℚ)*(5*(1/10))) (1/10) 5 (blocks 38) = true := by decide +kernel +lemma check_39 : expression.check (-10+(39:ℚ)*(5*(1/10))) (1/10) 5 (blocks 39) = true := by decide +kernel + +lemma checks (i : ℕ) (hi : i < 40) : + expression.check (-10+(i:ℚ)*(5*(1/10))) (1/10) 5 (blocks i) = true := by + interval_cases i + · exact check_0 + · exact check_1 + · exact check_2 + · exact check_3 + · exact check_4 + · exact check_5 + · exact check_6 + · exact check_7 + · exact check_8 + · exact check_9 + · exact check_10 + · exact check_11 + · exact check_12 + · exact check_13 + · exact check_14 + · exact check_15 + · exact check_16 + · exact check_17 + · exact check_18 + · exact check_19 + · exact check_20 + · exact check_21 + · exact check_22 + · exact check_23 + · exact check_24 + · exact check_25 + · exact check_26 + · exact check_27 + · exact check_28 + · exact check_29 + · exact check_30 + · exact check_31 + · exact check_32 + · exact check_33 + · exact check_34 + · exact check_35 + · exact check_36 + · exact check_37 + · exact check_38 + · exact check_39 + +theorem integral_bound : + (∫ h, scalarFunction (1/2) (397973/500000) (524071/1000000) (119553/1000000) (702377/1000000) 1 h ∂Scalar.fieldLaw (1/2)) ∈ (⟨522571/1000000,525571/1000000⟩ : Box) := by + apply gaussian_certificate (e := expression) (B := blocks) (h := (1/10)) (k := 5) (by norm_num) + · simpa only [expression,Rat.cast_div,Rat.cast_ofNat,Rat.cast_one,Rat.cast_zero] using integrandExpr_val (1/2) (397973/500000) (524071/1000000) (119553/1000000) (702377/1000000) 1 + · exact (continuous_scalarFunction _ _ _ _ _ _).measurable + · intro x + apply scalarFunction_bound <;> norm_num + · exact checks + · decide +kernel + +end SKRatio.Certificate.Data.J4K1 + +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Certificates/ScalarDataJ4K10.lean b/lean/OAI/Probability/SKRatio/Certificates/ScalarDataJ4K10.lean new file mode 100644 index 0000000000000000000000000000000000000000..21b33e701fcbf377fcaeef036baee97db0e5ef69 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Certificates/ScalarDataJ4K10.lean @@ -0,0 +1,154 @@ +import Mathlib +import OAI.Probability.SKRatio.Certificates.CertifiedBatches +import OAI.Probability.SKRatio.Certificates.CertifiedFunctionBounds + +namespace OAI + +noncomputable section +open Real MeasureTheory +namespace SKRatio.Certificate.Data.J4K10 + +def expression : Expr := integrandExpr (1/2) (397973/500000) (524071/1000000) (119553/1000000) (702377/1000000) 10 +def blocks : ℕ → Box + | 0 => ⟨-1/1000000,1/1000000⟩ + | 1 => ⟨-1/1000000,1/1000000⟩ + | 2 => ⟨-1/1000000,1/1000000⟩ + | 3 => ⟨-1/1000000,1/1000000⟩ + | 4 => ⟨-1/1000000,1/1000000⟩ + | 5 => ⟨-1/1000000,1/1000000⟩ + | 6 => ⟨-1/1000000,1/1000000⟩ + | 7 => ⟨-1/1000000,1/1000000⟩ + | 8 => ⟨-1/1000000,1/1000000⟩ + | 9 => ⟨-1/1000000,1/1000000⟩ + | 10 => ⟨-1/1000000,1/1000000⟩ + | 11 => ⟨-1/1000000,1/1000000⟩ + | 12 => ⟨0,1/500000⟩ + | 13 => ⟨7/500000,3/200000⟩ + | 14 => ⟨9/62500,147/1000000⟩ + | 15 => ⟨1061/1000000,267/250000⟩ + | 16 => ⟨5461/1000000,137/25000⟩ + | 17 => ⟨2371/125000,18993/1000000⟩ + | 18 => ⟨2143/50000,42877/1000000⟩ + | 19 => ⟨61359/1000000,6141/100000⟩ + | 20 => ⟨3451/62500,55257/1000000⟩ + | 21 => ⟨6311/200000,31581/1000000⟩ + | 22 => ⟨2937/250000,11783/1000000⟩ + | 23 => ⟨369/125000,743/250000⟩ + | 24 => ⟨259/500000,263/500000⟩ + | 25 => ⟨13/200000,17/250000⟩ + | 26 => ⟨1/200000,7/1000000⟩ + | 27 => ⟨0,1/1000000⟩ + | 28 => ⟨-1/1000000,1/1000000⟩ + | 29 => ⟨-1/1000000,1/1000000⟩ + | 30 => ⟨-1/1000000,1/1000000⟩ + | 31 => ⟨-1/1000000,1/1000000⟩ + | 32 => ⟨-1/1000000,1/1000000⟩ + | 33 => ⟨-1/1000000,1/1000000⟩ + | 34 => ⟨-1/1000000,1/1000000⟩ + | 35 => ⟨-1/1000000,1/1000000⟩ + | 36 => ⟨-1/1000000,1/1000000⟩ + | 37 => ⟨-1/1000000,1/1000000⟩ + | 38 => ⟨-1/1000000,1/1000000⟩ + | 39 => ⟨-1/1000000,1/1000000⟩ + | _ => Box.rat 0 + +lemma check_0 : expression.check (-10+(0:ℚ)*(10*(1/20))) (1/20) 10 (blocks 0) = true := by decide +kernel +lemma check_1 : expression.check (-10+(1:ℚ)*(10*(1/20))) (1/20) 10 (blocks 1) = true := by decide +kernel +lemma check_2 : expression.check (-10+(2:ℚ)*(10*(1/20))) (1/20) 10 (blocks 2) = true := by decide +kernel +lemma check_3 : expression.check (-10+(3:ℚ)*(10*(1/20))) (1/20) 10 (blocks 3) = true := by decide +kernel +lemma check_4 : expression.check (-10+(4:ℚ)*(10*(1/20))) (1/20) 10 (blocks 4) = true := by decide +kernel +lemma check_5 : expression.check (-10+(5:ℚ)*(10*(1/20))) (1/20) 10 (blocks 5) = true := by decide +kernel +lemma check_6 : expression.check (-10+(6:ℚ)*(10*(1/20))) (1/20) 10 (blocks 6) = true := by decide +kernel +lemma check_7 : expression.check (-10+(7:ℚ)*(10*(1/20))) (1/20) 10 (blocks 7) = true := by decide +kernel +lemma check_8 : expression.check (-10+(8:ℚ)*(10*(1/20))) (1/20) 10 (blocks 8) = true := by decide +kernel +lemma check_9 : expression.check (-10+(9:ℚ)*(10*(1/20))) (1/20) 10 (blocks 9) = true := by decide +kernel +lemma check_10 : expression.check (-10+(10:ℚ)*(10*(1/20))) (1/20) 10 (blocks 10) = true := by decide +kernel +lemma check_11 : expression.check (-10+(11:ℚ)*(10*(1/20))) (1/20) 10 (blocks 11) = true := by decide +kernel +lemma check_12 : expression.check (-10+(12:ℚ)*(10*(1/20))) (1/20) 10 (blocks 12) = true := by decide +kernel +lemma check_13 : expression.check (-10+(13:ℚ)*(10*(1/20))) (1/20) 10 (blocks 13) = true := by decide +kernel +lemma check_14 : expression.check (-10+(14:ℚ)*(10*(1/20))) (1/20) 10 (blocks 14) = true := by decide +kernel +lemma check_15 : expression.check (-10+(15:ℚ)*(10*(1/20))) (1/20) 10 (blocks 15) = true := by decide +kernel +lemma check_16 : expression.check (-10+(16:ℚ)*(10*(1/20))) (1/20) 10 (blocks 16) = true := by decide +kernel +lemma check_17 : expression.check (-10+(17:ℚ)*(10*(1/20))) (1/20) 10 (blocks 17) = true := by decide +kernel +lemma check_18 : expression.check (-10+(18:ℚ)*(10*(1/20))) (1/20) 10 (blocks 18) = true := by decide +kernel +lemma check_19 : expression.check (-10+(19:ℚ)*(10*(1/20))) (1/20) 10 (blocks 19) = true := by decide +kernel +lemma check_20 : expression.check (-10+(20:ℚ)*(10*(1/20))) (1/20) 10 (blocks 20) = true := by decide +kernel +lemma check_21 : expression.check (-10+(21:ℚ)*(10*(1/20))) (1/20) 10 (blocks 21) = true := by decide +kernel +lemma check_22 : expression.check (-10+(22:ℚ)*(10*(1/20))) (1/20) 10 (blocks 22) = true := by decide +kernel +lemma check_23 : expression.check (-10+(23:ℚ)*(10*(1/20))) (1/20) 10 (blocks 23) = true := by decide +kernel +lemma check_24 : expression.check (-10+(24:ℚ)*(10*(1/20))) (1/20) 10 (blocks 24) = true := by decide +kernel +lemma check_25 : expression.check (-10+(25:ℚ)*(10*(1/20))) (1/20) 10 (blocks 25) = true := by decide +kernel +lemma check_26 : expression.check (-10+(26:ℚ)*(10*(1/20))) (1/20) 10 (blocks 26) = true := by decide +kernel +lemma check_27 : expression.check (-10+(27:ℚ)*(10*(1/20))) (1/20) 10 (blocks 27) = true := by decide +kernel +lemma check_28 : expression.check (-10+(28:ℚ)*(10*(1/20))) (1/20) 10 (blocks 28) = true := by decide +kernel +lemma check_29 : expression.check (-10+(29:ℚ)*(10*(1/20))) (1/20) 10 (blocks 29) = true := by decide +kernel +lemma check_30 : expression.check (-10+(30:ℚ)*(10*(1/20))) (1/20) 10 (blocks 30) = true := by decide +kernel +lemma check_31 : expression.check (-10+(31:ℚ)*(10*(1/20))) (1/20) 10 (blocks 31) = true := by decide +kernel +lemma check_32 : expression.check (-10+(32:ℚ)*(10*(1/20))) (1/20) 10 (blocks 32) = true := by decide +kernel +lemma check_33 : expression.check (-10+(33:ℚ)*(10*(1/20))) (1/20) 10 (blocks 33) = true := by decide +kernel +lemma check_34 : expression.check (-10+(34:ℚ)*(10*(1/20))) (1/20) 10 (blocks 34) = true := by decide +kernel +lemma check_35 : expression.check (-10+(35:ℚ)*(10*(1/20))) (1/20) 10 (blocks 35) = true := by decide +kernel +lemma check_36 : expression.check (-10+(36:ℚ)*(10*(1/20))) (1/20) 10 (blocks 36) = true := by decide +kernel +lemma check_37 : expression.check (-10+(37:ℚ)*(10*(1/20))) (1/20) 10 (blocks 37) = true := by decide +kernel +lemma check_38 : expression.check (-10+(38:ℚ)*(10*(1/20))) (1/20) 10 (blocks 38) = true := by decide +kernel +lemma check_39 : expression.check (-10+(39:ℚ)*(10*(1/20))) (1/20) 10 (blocks 39) = true := by decide +kernel + +lemma checks (i : ℕ) (hi : i < 40) : + expression.check (-10+(i:ℚ)*(10*(1/20))) (1/20) 10 (blocks i) = true := by + interval_cases i + · exact check_0 + · exact check_1 + · exact check_2 + · exact check_3 + · exact check_4 + · exact check_5 + · exact check_6 + · exact check_7 + · exact check_8 + · exact check_9 + · exact check_10 + · exact check_11 + · exact check_12 + · exact check_13 + · exact check_14 + · exact check_15 + · exact check_16 + · exact check_17 + · exact check_18 + · exact check_19 + · exact check_20 + · exact check_21 + · exact check_22 + · exact check_23 + · exact check_24 + · exact check_25 + · exact check_26 + · exact check_27 + · exact check_28 + · exact check_29 + · exact check_30 + · exact check_31 + · exact check_32 + · exact check_33 + · exact check_34 + · exact check_35 + · exact check_36 + · exact check_37 + · exact check_38 + · exact check_39 + +theorem integral_bound : + (∫ h, scalarFunction (1/2) (397973/500000) (524071/1000000) (119553/1000000) (702377/1000000) 10 h ∂Scalar.fieldLaw (1/2)) ∈ (⟨0,929/10000⟩ : Box) := by + apply gaussian_certificate (e := expression) (B := blocks) (h := (1/20)) (k := 10) (by norm_num) + · simpa only [expression,Rat.cast_div,Rat.cast_ofNat,Rat.cast_one,Rat.cast_zero] using integrandExpr_val (1/2) (397973/500000) (524071/1000000) (119553/1000000) (702377/1000000) 10 + · exact (continuous_scalarFunction _ _ _ _ _ _).measurable + · intro x + apply scalarFunction_bound <;> norm_num + · exact checks + · decide +kernel + +end SKRatio.Certificate.Data.J4K10 + +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Certificates/ScalarDataJ4K11.lean b/lean/OAI/Probability/SKRatio/Certificates/ScalarDataJ4K11.lean new file mode 100644 index 0000000000000000000000000000000000000000..1bf71a0fce8e34ea7766a6a295940c55d4e9c3eb --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Certificates/ScalarDataJ4K11.lean @@ -0,0 +1,154 @@ +import Mathlib +import OAI.Probability.SKRatio.Certificates.CertifiedBatches +import OAI.Probability.SKRatio.Certificates.CertifiedFunctionBounds + +namespace OAI + +noncomputable section +open Real MeasureTheory +namespace SKRatio.Certificate.Data.J4K11 + +def expression : Expr := integrandExpr (1/2) (397973/500000) (524071/1000000) (119553/1000000) (702377/1000000) 11 +def blocks : ℕ → Box + | 0 => ⟨-1/1000000,1/1000000⟩ + | 1 => ⟨-1/1000000,1/1000000⟩ + | 2 => ⟨-1/1000000,1/1000000⟩ + | 3 => ⟨-1/1000000,1/1000000⟩ + | 4 => ⟨-1/1000000,1/1000000⟩ + | 5 => ⟨-1/1000000,1/1000000⟩ + | 6 => ⟨-1/1000000,1/1000000⟩ + | 7 => ⟨-1/1000000,1/1000000⟩ + | 8 => ⟨-1/1000000,1/1000000⟩ + | 9 => ⟨-1/1000000,1/1000000⟩ + | 10 => ⟨-1/1000000,1/1000000⟩ + | 11 => ⟨-1/1000000,1/1000000⟩ + | 12 => ⟨0,1/1000000⟩ + | 13 => ⟨1/250000,3/500000⟩ + | 14 => ⟨51/1000000,53/1000000⟩ + | 15 => ⟨79/200000,399/1000000⟩ + | 16 => ⟨2157/1000000,1083/500000⟩ + | 17 => ⟨4059/500000,8133/1000000⟩ + | 18 => ⟨20323/1000000,20333/1000000⟩ + | 19 => ⟨32797/1000000,32823/1000000⟩ + | 20 => ⟨8379/250000,671/20000⟩ + | 21 => ⟨21651/1000000,2709/125000⟩ + | 22 => ⟨897/100000,2249/250000⟩ + | 23 => ⟨2453/1000000,247/100000⟩ + | 24 => ⟨459/1000000,233/500000⟩ + | 25 => ⟨3/50000,63/1000000⟩ + | 26 => ⟨1/200000,7/1000000⟩ + | 27 => ⟨0,1/1000000⟩ + | 28 => ⟨-1/1000000,1/1000000⟩ + | 29 => ⟨-1/1000000,1/1000000⟩ + | 30 => ⟨-1/1000000,1/1000000⟩ + | 31 => ⟨-1/1000000,1/1000000⟩ + | 32 => ⟨-1/1000000,1/1000000⟩ + | 33 => ⟨-1/1000000,1/1000000⟩ + | 34 => ⟨-1/1000000,1/1000000⟩ + | 35 => ⟨-1/1000000,1/1000000⟩ + | 36 => ⟨-1/1000000,1/1000000⟩ + | 37 => ⟨-1/1000000,1/1000000⟩ + | 38 => ⟨-1/1000000,1/1000000⟩ + | 39 => ⟨-1/1000000,1/1000000⟩ + | _ => Box.rat 0 + +lemma check_0 : expression.check (-10+(0:ℚ)*(10*(1/20))) (1/20) 10 (blocks 0) = true := by decide +kernel +lemma check_1 : expression.check (-10+(1:ℚ)*(10*(1/20))) (1/20) 10 (blocks 1) = true := by decide +kernel +lemma check_2 : expression.check (-10+(2:ℚ)*(10*(1/20))) (1/20) 10 (blocks 2) = true := by decide +kernel +lemma check_3 : expression.check (-10+(3:ℚ)*(10*(1/20))) (1/20) 10 (blocks 3) = true := by decide +kernel +lemma check_4 : expression.check (-10+(4:ℚ)*(10*(1/20))) (1/20) 10 (blocks 4) = true := by decide +kernel +lemma check_5 : expression.check (-10+(5:ℚ)*(10*(1/20))) (1/20) 10 (blocks 5) = true := by decide +kernel +lemma check_6 : expression.check (-10+(6:ℚ)*(10*(1/20))) (1/20) 10 (blocks 6) = true := by decide +kernel +lemma check_7 : expression.check (-10+(7:ℚ)*(10*(1/20))) (1/20) 10 (blocks 7) = true := by decide +kernel +lemma check_8 : expression.check (-10+(8:ℚ)*(10*(1/20))) (1/20) 10 (blocks 8) = true := by decide +kernel +lemma check_9 : expression.check (-10+(9:ℚ)*(10*(1/20))) (1/20) 10 (blocks 9) = true := by decide +kernel +lemma check_10 : expression.check (-10+(10:ℚ)*(10*(1/20))) (1/20) 10 (blocks 10) = true := by decide +kernel +lemma check_11 : expression.check (-10+(11:ℚ)*(10*(1/20))) (1/20) 10 (blocks 11) = true := by decide +kernel +lemma check_12 : expression.check (-10+(12:ℚ)*(10*(1/20))) (1/20) 10 (blocks 12) = true := by decide +kernel +lemma check_13 : expression.check (-10+(13:ℚ)*(10*(1/20))) (1/20) 10 (blocks 13) = true := by decide +kernel +lemma check_14 : expression.check (-10+(14:ℚ)*(10*(1/20))) (1/20) 10 (blocks 14) = true := by decide +kernel +lemma check_15 : expression.check (-10+(15:ℚ)*(10*(1/20))) (1/20) 10 (blocks 15) = true := by decide +kernel +lemma check_16 : expression.check (-10+(16:ℚ)*(10*(1/20))) (1/20) 10 (blocks 16) = true := by decide +kernel +lemma check_17 : expression.check (-10+(17:ℚ)*(10*(1/20))) (1/20) 10 (blocks 17) = true := by decide +kernel +lemma check_18 : expression.check (-10+(18:ℚ)*(10*(1/20))) (1/20) 10 (blocks 18) = true := by decide +kernel +lemma check_19 : expression.check (-10+(19:ℚ)*(10*(1/20))) (1/20) 10 (blocks 19) = true := by decide +kernel +lemma check_20 : expression.check (-10+(20:ℚ)*(10*(1/20))) (1/20) 10 (blocks 20) = true := by decide +kernel +lemma check_21 : expression.check (-10+(21:ℚ)*(10*(1/20))) (1/20) 10 (blocks 21) = true := by decide +kernel +lemma check_22 : expression.check (-10+(22:ℚ)*(10*(1/20))) (1/20) 10 (blocks 22) = true := by decide +kernel +lemma check_23 : expression.check (-10+(23:ℚ)*(10*(1/20))) (1/20) 10 (blocks 23) = true := by decide +kernel +lemma check_24 : expression.check (-10+(24:ℚ)*(10*(1/20))) (1/20) 10 (blocks 24) = true := by decide +kernel +lemma check_25 : expression.check (-10+(25:ℚ)*(10*(1/20))) (1/20) 10 (blocks 25) = true := by decide +kernel +lemma check_26 : expression.check (-10+(26:ℚ)*(10*(1/20))) (1/20) 10 (blocks 26) = true := by decide +kernel +lemma check_27 : expression.check (-10+(27:ℚ)*(10*(1/20))) (1/20) 10 (blocks 27) = true := by decide +kernel +lemma check_28 : expression.check (-10+(28:ℚ)*(10*(1/20))) (1/20) 10 (blocks 28) = true := by decide +kernel +lemma check_29 : expression.check (-10+(29:ℚ)*(10*(1/20))) (1/20) 10 (blocks 29) = true := by decide +kernel +lemma check_30 : expression.check (-10+(30:ℚ)*(10*(1/20))) (1/20) 10 (blocks 30) = true := by decide +kernel +lemma check_31 : expression.check (-10+(31:ℚ)*(10*(1/20))) (1/20) 10 (blocks 31) = true := by decide +kernel +lemma check_32 : expression.check (-10+(32:ℚ)*(10*(1/20))) (1/20) 10 (blocks 32) = true := by decide +kernel +lemma check_33 : expression.check (-10+(33:ℚ)*(10*(1/20))) (1/20) 10 (blocks 33) = true := by decide +kernel +lemma check_34 : expression.check (-10+(34:ℚ)*(10*(1/20))) (1/20) 10 (blocks 34) = true := by decide +kernel +lemma check_35 : expression.check (-10+(35:ℚ)*(10*(1/20))) (1/20) 10 (blocks 35) = true := by decide +kernel +lemma check_36 : expression.check (-10+(36:ℚ)*(10*(1/20))) (1/20) 10 (blocks 36) = true := by decide +kernel +lemma check_37 : expression.check (-10+(37:ℚ)*(10*(1/20))) (1/20) 10 (blocks 37) = true := by decide +kernel +lemma check_38 : expression.check (-10+(38:ℚ)*(10*(1/20))) (1/20) 10 (blocks 38) = true := by decide +kernel +lemma check_39 : expression.check (-10+(39:ℚ)*(10*(1/20))) (1/20) 10 (blocks 39) = true := by decide +kernel + +lemma checks (i : ℕ) (hi : i < 40) : + expression.check (-10+(i:ℚ)*(10*(1/20))) (1/20) 10 (blocks i) = true := by + interval_cases i + · exact check_0 + · exact check_1 + · exact check_2 + · exact check_3 + · exact check_4 + · exact check_5 + · exact check_6 + · exact check_7 + · exact check_8 + · exact check_9 + · exact check_10 + · exact check_11 + · exact check_12 + · exact check_13 + · exact check_14 + · exact check_15 + · exact check_16 + · exact check_17 + · exact check_18 + · exact check_19 + · exact check_20 + · exact check_21 + · exact check_22 + · exact check_23 + · exact check_24 + · exact check_25 + · exact check_26 + · exact check_27 + · exact check_28 + · exact check_29 + · exact check_30 + · exact check_31 + · exact check_32 + · exact check_33 + · exact check_34 + · exact check_35 + · exact check_36 + · exact check_37 + · exact check_38 + · exact check_39 + +theorem integral_bound : + (∫ h, scalarFunction (1/2) (397973/500000) (524071/1000000) (119553/1000000) (702377/1000000) 11 h ∂Scalar.fieldLaw (1/2)) ∈ (⟨13/250,263/5000⟩ : Box) := by + apply gaussian_certificate (e := expression) (B := blocks) (h := (1/20)) (k := 10) (by norm_num) + · simpa only [expression,Rat.cast_div,Rat.cast_ofNat,Rat.cast_one,Rat.cast_zero] using integrandExpr_val (1/2) (397973/500000) (524071/1000000) (119553/1000000) (702377/1000000) 11 + · exact (continuous_scalarFunction _ _ _ _ _ _).measurable + · intro x + apply scalarFunction_bound <;> norm_num + · exact checks + · decide +kernel + +end SKRatio.Certificate.Data.J4K11 + +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Certificates/ScalarDataJ4K12.lean b/lean/OAI/Probability/SKRatio/Certificates/ScalarDataJ4K12.lean new file mode 100644 index 0000000000000000000000000000000000000000..7947d1840ac97207773d7e67569e82d584e820bd --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Certificates/ScalarDataJ4K12.lean @@ -0,0 +1,154 @@ +import Mathlib +import OAI.Probability.SKRatio.Certificates.CertifiedBatches +import OAI.Probability.SKRatio.Certificates.CertifiedFunctionBounds + +namespace OAI + +noncomputable section +open Real MeasureTheory +namespace SKRatio.Certificate.Data.J4K12 + +def expression : Expr := integrandExpr (1/2) (397973/500000) (524071/1000000) (119553/1000000) (702377/1000000) 12 +def blocks : ℕ → Box + | 0 => ⟨-1/1000000,1/1000000⟩ + | 1 => ⟨-1/1000000,1/1000000⟩ + | 2 => ⟨-1/1000000,1/1000000⟩ + | 3 => ⟨-1/1000000,1/1000000⟩ + | 4 => ⟨-1/1000000,1/1000000⟩ + | 5 => ⟨-1/1000000,1/1000000⟩ + | 6 => ⟨-1/1000000,1/1000000⟩ + | 7 => ⟨-1/1000000,1/1000000⟩ + | 8 => ⟨-1/1000000,1/1000000⟩ + | 9 => ⟨-1/1000000,1/1000000⟩ + | 10 => ⟨-1/1000000,1/1000000⟩ + | 11 => ⟨-1/1000000,1/1000000⟩ + | 12 => ⟨1/1000000,1/500000⟩ + | 13 => ⟨21/1000000,23/1000000⟩ + | 14 => ⟨9/40000,57/250000⟩ + | 15 => ⟨423/250000,1703/1000000⟩ + | 16 => ⟨903/100000,4531/500000⟩ + | 17 => ⟨4147/125000,8307/250000⟩ + | 18 => ⟨20397/250000,5101/62500⟩ + | 19 => ⟨132077/1000000,413/3125⟩ + | 20 => ⟨35257/250000,17641/125000⟩ + | 21 => ⟨50579/500000,50599/500000⟩ + | 22 => ⟨12533/250000,50187/1000000⟩ + | 23 => ⟨1771/100000,111/6250⟩ + | 24 => ⟨917/200000,461/100000⟩ + | 25 => ⟨111/125000,897/1000000⟩ + | 26 => ⟨13/100000,133/1000000⟩ + | 27 => ⟨7/500000,1/62500⟩ + | 28 => ⟨1/1000000,1/500000⟩ + | 29 => ⟨-1/1000000,1/1000000⟩ + | 30 => ⟨-1/1000000,1/1000000⟩ + | 31 => ⟨-1/1000000,1/1000000⟩ + | 32 => ⟨-1/1000000,1/1000000⟩ + | 33 => ⟨-1/1000000,1/1000000⟩ + | 34 => ⟨-1/1000000,1/1000000⟩ + | 35 => ⟨-1/1000000,1/1000000⟩ + | 36 => ⟨-1/1000000,1/1000000⟩ + | 37 => ⟨-1/1000000,1/1000000⟩ + | 38 => ⟨-1/1000000,1/1000000⟩ + | 39 => ⟨-1/1000000,1/1000000⟩ + | _ => Box.rat 0 + +lemma check_0 : expression.check (-10+(0:ℚ)*(10*(1/20))) (1/20) 10 (blocks 0) = true := by decide +kernel +lemma check_1 : expression.check (-10+(1:ℚ)*(10*(1/20))) (1/20) 10 (blocks 1) = true := by decide +kernel +lemma check_2 : expression.check (-10+(2:ℚ)*(10*(1/20))) (1/20) 10 (blocks 2) = true := by decide +kernel +lemma check_3 : expression.check (-10+(3:ℚ)*(10*(1/20))) (1/20) 10 (blocks 3) = true := by decide +kernel +lemma check_4 : expression.check (-10+(4:ℚ)*(10*(1/20))) (1/20) 10 (blocks 4) = true := by decide +kernel +lemma check_5 : expression.check (-10+(5:ℚ)*(10*(1/20))) (1/20) 10 (blocks 5) = true := by decide +kernel +lemma check_6 : expression.check (-10+(6:ℚ)*(10*(1/20))) (1/20) 10 (blocks 6) = true := by decide +kernel +lemma check_7 : expression.check (-10+(7:ℚ)*(10*(1/20))) (1/20) 10 (blocks 7) = true := by decide +kernel +lemma check_8 : expression.check (-10+(8:ℚ)*(10*(1/20))) (1/20) 10 (blocks 8) = true := by decide +kernel +lemma check_9 : expression.check (-10+(9:ℚ)*(10*(1/20))) (1/20) 10 (blocks 9) = true := by decide +kernel +lemma check_10 : expression.check (-10+(10:ℚ)*(10*(1/20))) (1/20) 10 (blocks 10) = true := by decide +kernel +lemma check_11 : expression.check (-10+(11:ℚ)*(10*(1/20))) (1/20) 10 (blocks 11) = true := by decide +kernel +lemma check_12 : expression.check (-10+(12:ℚ)*(10*(1/20))) (1/20) 10 (blocks 12) = true := by decide +kernel +lemma check_13 : expression.check (-10+(13:ℚ)*(10*(1/20))) (1/20) 10 (blocks 13) = true := by decide +kernel +lemma check_14 : expression.check (-10+(14:ℚ)*(10*(1/20))) (1/20) 10 (blocks 14) = true := by decide +kernel +lemma check_15 : expression.check (-10+(15:ℚ)*(10*(1/20))) (1/20) 10 (blocks 15) = true := by decide +kernel +lemma check_16 : expression.check (-10+(16:ℚ)*(10*(1/20))) (1/20) 10 (blocks 16) = true := by decide +kernel +lemma check_17 : expression.check (-10+(17:ℚ)*(10*(1/20))) (1/20) 10 (blocks 17) = true := by decide +kernel +lemma check_18 : expression.check (-10+(18:ℚ)*(10*(1/20))) (1/20) 10 (blocks 18) = true := by decide +kernel +lemma check_19 : expression.check (-10+(19:ℚ)*(10*(1/20))) (1/20) 10 (blocks 19) = true := by decide +kernel +lemma check_20 : expression.check (-10+(20:ℚ)*(10*(1/20))) (1/20) 10 (blocks 20) = true := by decide +kernel +lemma check_21 : expression.check (-10+(21:ℚ)*(10*(1/20))) (1/20) 10 (blocks 21) = true := by decide +kernel +lemma check_22 : expression.check (-10+(22:ℚ)*(10*(1/20))) (1/20) 10 (blocks 22) = true := by decide +kernel +lemma check_23 : expression.check (-10+(23:ℚ)*(10*(1/20))) (1/20) 10 (blocks 23) = true := by decide +kernel +lemma check_24 : expression.check (-10+(24:ℚ)*(10*(1/20))) (1/20) 10 (blocks 24) = true := by decide +kernel +lemma check_25 : expression.check (-10+(25:ℚ)*(10*(1/20))) (1/20) 10 (blocks 25) = true := by decide +kernel +lemma check_26 : expression.check (-10+(26:ℚ)*(10*(1/20))) (1/20) 10 (blocks 26) = true := by decide +kernel +lemma check_27 : expression.check (-10+(27:ℚ)*(10*(1/20))) (1/20) 10 (blocks 27) = true := by decide +kernel +lemma check_28 : expression.check (-10+(28:ℚ)*(10*(1/20))) (1/20) 10 (blocks 28) = true := by decide +kernel +lemma check_29 : expression.check (-10+(29:ℚ)*(10*(1/20))) (1/20) 10 (blocks 29) = true := by decide +kernel +lemma check_30 : expression.check (-10+(30:ℚ)*(10*(1/20))) (1/20) 10 (blocks 30) = true := by decide +kernel +lemma check_31 : expression.check (-10+(31:ℚ)*(10*(1/20))) (1/20) 10 (blocks 31) = true := by decide +kernel +lemma check_32 : expression.check (-10+(32:ℚ)*(10*(1/20))) (1/20) 10 (blocks 32) = true := by decide +kernel +lemma check_33 : expression.check (-10+(33:ℚ)*(10*(1/20))) (1/20) 10 (blocks 33) = true := by decide +kernel +lemma check_34 : expression.check (-10+(34:ℚ)*(10*(1/20))) (1/20) 10 (blocks 34) = true := by decide +kernel +lemma check_35 : expression.check (-10+(35:ℚ)*(10*(1/20))) (1/20) 10 (blocks 35) = true := by decide +kernel +lemma check_36 : expression.check (-10+(36:ℚ)*(10*(1/20))) (1/20) 10 (blocks 36) = true := by decide +kernel +lemma check_37 : expression.check (-10+(37:ℚ)*(10*(1/20))) (1/20) 10 (blocks 37) = true := by decide +kernel +lemma check_38 : expression.check (-10+(38:ℚ)*(10*(1/20))) (1/20) 10 (blocks 38) = true := by decide +kernel +lemma check_39 : expression.check (-10+(39:ℚ)*(10*(1/20))) (1/20) 10 (blocks 39) = true := by decide +kernel + +lemma checks (i : ℕ) (hi : i < 40) : + expression.check (-10+(i:ℚ)*(10*(1/20))) (1/20) 10 (blocks i) = true := by + interval_cases i + · exact check_0 + · exact check_1 + · exact check_2 + · exact check_3 + · exact check_4 + · exact check_5 + · exact check_6 + · exact check_7 + · exact check_8 + · exact check_9 + · exact check_10 + · exact check_11 + · exact check_12 + · exact check_13 + · exact check_14 + · exact check_15 + · exact check_16 + · exact check_17 + · exact check_18 + · exact check_19 + · exact check_20 + · exact check_21 + · exact check_22 + · exact check_23 + · exact check_24 + · exact check_25 + · exact check_26 + · exact check_27 + · exact check_28 + · exact check_29 + · exact check_30 + · exact check_31 + · exact check_32 + · exact check_33 + · exact check_34 + · exact check_35 + · exact check_36 + · exact check_37 + · exact check_38 + · exact check_39 + +theorem integral_bound : + (∫ h, scalarFunction (1/2) (397973/500000) (524071/1000000) (119553/1000000) (702377/1000000) 12 h ∂Scalar.fieldLaw (1/2)) ∈ (⟨0,573/2500⟩ : Box) := by + apply gaussian_certificate (e := expression) (B := blocks) (h := (1/20)) (k := 10) (by norm_num) + · simpa only [expression,Rat.cast_div,Rat.cast_ofNat,Rat.cast_one,Rat.cast_zero] using integrandExpr_val (1/2) (397973/500000) (524071/1000000) (119553/1000000) (702377/1000000) 12 + · exact (continuous_scalarFunction _ _ _ _ _ _).measurable + · intro x + apply scalarFunction_bound <;> norm_num + · exact checks + · decide +kernel + +end SKRatio.Certificate.Data.J4K12 + +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Certificates/ScalarDataJ4K2.lean b/lean/OAI/Probability/SKRatio/Certificates/ScalarDataJ4K2.lean new file mode 100644 index 0000000000000000000000000000000000000000..b16574755246fa041bb99800b0c33fc42ba689ce --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Certificates/ScalarDataJ4K2.lean @@ -0,0 +1,154 @@ +import Mathlib +import OAI.Probability.SKRatio.Certificates.CertifiedBatches +import OAI.Probability.SKRatio.Certificates.CertifiedFunctionBounds + +namespace OAI + +noncomputable section +open Real MeasureTheory +namespace SKRatio.Certificate.Data.J4K2 + +def expression : Expr := integrandExpr (1/2) (397973/500000) (524071/1000000) (119553/1000000) (702377/1000000) 2 +def blocks : ℕ → Box + | 0 => ⟨-1/1000000,1/1000000⟩ + | 1 => ⟨-1/1000000,1/1000000⟩ + | 2 => ⟨-1/1000000,1/1000000⟩ + | 3 => ⟨-1/1000000,1/1000000⟩ + | 4 => ⟨-1/1000000,1/1000000⟩ + | 5 => ⟨-1/1000000,1/1000000⟩ + | 6 => ⟨-1/1000000,1/1000000⟩ + | 7 => ⟨-1/1000000,1/1000000⟩ + | 8 => ⟨-1/1000000,1/1000000⟩ + | 9 => ⟨-1/1000000,1/1000000⟩ + | 10 => ⟨-1/1000000,0⟩ + | 11 => ⟨-1/125000,-3/500000⟩ + | 12 => ⟨-3/40000,-71/1000000⟩ + | 13 => ⟨-301/500000,-583/1000000⟩ + | 14 => ⟨-3573/1000000,-1751/500000⟩ + | 15 => ⟨-7503/500000,-14847/1000000⟩ + | 16 => ⟨-41901/1000000,-8351/200000⟩ + | 17 => ⟨-13837/200000,-68697/1000000⟩ + | 18 => ⟨-21219/500000,-8349/200000⟩ + | 19 => ⟨29251/500000,58877/1000000⟩ + | 20 => ⟨4561/31250,146863/1000000⟩ + | 21 => ⟨28393/200000,142643/1000000⟩ + | 22 => ⟨40929/500000,82303/1000000⟩ + | 23 => ⟨6267/200000,15907/500000⟩ + | 24 => ⟨1059/125000,8733/1000000⟩ + | 25 => ⟨1673/1000000,1771/1000000⟩ + | 26 => ⟨49/200000,273/1000000⟩ + | 27 => ⟨13/500000,33/1000000⟩ + | 28 => ⟨1/1000000,1/250000⟩ + | 29 => ⟨-1/1000000,1/1000000⟩ + | 30 => ⟨-1/1000000,1/1000000⟩ + | 31 => ⟨-1/1000000,1/1000000⟩ + | 32 => ⟨-1/1000000,1/1000000⟩ + | 33 => ⟨-1/1000000,1/1000000⟩ + | 34 => ⟨-1/1000000,1/1000000⟩ + | 35 => ⟨-1/1000000,1/1000000⟩ + | 36 => ⟨-1/1000000,1/1000000⟩ + | 37 => ⟨-1/1000000,1/1000000⟩ + | 38 => ⟨-1/1000000,1/1000000⟩ + | 39 => ⟨-1/1000000,1/1000000⟩ + | _ => Box.rat 0 + +lemma check_0 : expression.check (-10+(0:ℚ)*(5*(1/10))) (1/10) 5 (blocks 0) = true := by decide +kernel +lemma check_1 : expression.check (-10+(1:ℚ)*(5*(1/10))) (1/10) 5 (blocks 1) = true := by decide +kernel +lemma check_2 : expression.check (-10+(2:ℚ)*(5*(1/10))) (1/10) 5 (blocks 2) = true := by decide +kernel +lemma check_3 : expression.check (-10+(3:ℚ)*(5*(1/10))) (1/10) 5 (blocks 3) = true := by decide +kernel +lemma check_4 : expression.check (-10+(4:ℚ)*(5*(1/10))) (1/10) 5 (blocks 4) = true := by decide +kernel +lemma check_5 : expression.check (-10+(5:ℚ)*(5*(1/10))) (1/10) 5 (blocks 5) = true := by decide +kernel +lemma check_6 : expression.check (-10+(6:ℚ)*(5*(1/10))) (1/10) 5 (blocks 6) = true := by decide +kernel +lemma check_7 : expression.check (-10+(7:ℚ)*(5*(1/10))) (1/10) 5 (blocks 7) = true := by decide +kernel +lemma check_8 : expression.check (-10+(8:ℚ)*(5*(1/10))) (1/10) 5 (blocks 8) = true := by decide +kernel +lemma check_9 : expression.check (-10+(9:ℚ)*(5*(1/10))) (1/10) 5 (blocks 9) = true := by decide +kernel +lemma check_10 : expression.check (-10+(10:ℚ)*(5*(1/10))) (1/10) 5 (blocks 10) = true := by decide +kernel +lemma check_11 : expression.check (-10+(11:ℚ)*(5*(1/10))) (1/10) 5 (blocks 11) = true := by decide +kernel +lemma check_12 : expression.check (-10+(12:ℚ)*(5*(1/10))) (1/10) 5 (blocks 12) = true := by decide +kernel +lemma check_13 : expression.check (-10+(13:ℚ)*(5*(1/10))) (1/10) 5 (blocks 13) = true := by decide +kernel +lemma check_14 : expression.check (-10+(14:ℚ)*(5*(1/10))) (1/10) 5 (blocks 14) = true := by decide +kernel +lemma check_15 : expression.check (-10+(15:ℚ)*(5*(1/10))) (1/10) 5 (blocks 15) = true := by decide +kernel +lemma check_16 : expression.check (-10+(16:ℚ)*(5*(1/10))) (1/10) 5 (blocks 16) = true := by decide +kernel +lemma check_17 : expression.check (-10+(17:ℚ)*(5*(1/10))) (1/10) 5 (blocks 17) = true := by decide +kernel +lemma check_18 : expression.check (-10+(18:ℚ)*(5*(1/10))) (1/10) 5 (blocks 18) = true := by decide +kernel +lemma check_19 : expression.check (-10+(19:ℚ)*(5*(1/10))) (1/10) 5 (blocks 19) = true := by decide +kernel +lemma check_20 : expression.check (-10+(20:ℚ)*(5*(1/10))) (1/10) 5 (blocks 20) = true := by decide +kernel +lemma check_21 : expression.check (-10+(21:ℚ)*(5*(1/10))) (1/10) 5 (blocks 21) = true := by decide +kernel +lemma check_22 : expression.check (-10+(22:ℚ)*(5*(1/10))) (1/10) 5 (blocks 22) = true := by decide +kernel +lemma check_23 : expression.check (-10+(23:ℚ)*(5*(1/10))) (1/10) 5 (blocks 23) = true := by decide +kernel +lemma check_24 : expression.check (-10+(24:ℚ)*(5*(1/10))) (1/10) 5 (blocks 24) = true := by decide +kernel +lemma check_25 : expression.check (-10+(25:ℚ)*(5*(1/10))) (1/10) 5 (blocks 25) = true := by decide +kernel +lemma check_26 : expression.check (-10+(26:ℚ)*(5*(1/10))) (1/10) 5 (blocks 26) = true := by decide +kernel +lemma check_27 : expression.check (-10+(27:ℚ)*(5*(1/10))) (1/10) 5 (blocks 27) = true := by decide +kernel +lemma check_28 : expression.check (-10+(28:ℚ)*(5*(1/10))) (1/10) 5 (blocks 28) = true := by decide +kernel +lemma check_29 : expression.check (-10+(29:ℚ)*(5*(1/10))) (1/10) 5 (blocks 29) = true := by decide +kernel +lemma check_30 : expression.check (-10+(30:ℚ)*(5*(1/10))) (1/10) 5 (blocks 30) = true := by decide +kernel +lemma check_31 : expression.check (-10+(31:ℚ)*(5*(1/10))) (1/10) 5 (blocks 31) = true := by decide +kernel +lemma check_32 : expression.check (-10+(32:ℚ)*(5*(1/10))) (1/10) 5 (blocks 32) = true := by decide +kernel +lemma check_33 : expression.check (-10+(33:ℚ)*(5*(1/10))) (1/10) 5 (blocks 33) = true := by decide +kernel +lemma check_34 : expression.check (-10+(34:ℚ)*(5*(1/10))) (1/10) 5 (blocks 34) = true := by decide +kernel +lemma check_35 : expression.check (-10+(35:ℚ)*(5*(1/10))) (1/10) 5 (blocks 35) = true := by decide +kernel +lemma check_36 : expression.check (-10+(36:ℚ)*(5*(1/10))) (1/10) 5 (blocks 36) = true := by decide +kernel +lemma check_37 : expression.check (-10+(37:ℚ)*(5*(1/10))) (1/10) 5 (blocks 37) = true := by decide +kernel +lemma check_38 : expression.check (-10+(38:ℚ)*(5*(1/10))) (1/10) 5 (blocks 38) = true := by decide +kernel +lemma check_39 : expression.check (-10+(39:ℚ)*(5*(1/10))) (1/10) 5 (blocks 39) = true := by decide +kernel + +lemma checks (i : ℕ) (hi : i < 40) : + expression.check (-10+(i:ℚ)*(5*(1/10))) (1/10) 5 (blocks i) = true := by + interval_cases i + · exact check_0 + · exact check_1 + · exact check_2 + · exact check_3 + · exact check_4 + · exact check_5 + · exact check_6 + · exact check_7 + · exact check_8 + · exact check_9 + · exact check_10 + · exact check_11 + · exact check_12 + · exact check_13 + · exact check_14 + · exact check_15 + · exact check_16 + · exact check_17 + · exact check_18 + · exact check_19 + · exact check_20 + · exact check_21 + · exact check_22 + · exact check_23 + · exact check_24 + · exact check_25 + · exact check_26 + · exact check_27 + · exact check_28 + · exact check_29 + · exact check_30 + · exact check_31 + · exact check_32 + · exact check_33 + · exact check_34 + · exact check_35 + · exact check_36 + · exact check_37 + · exact check_38 + · exact check_39 + +theorem integral_bound : + (∫ h, scalarFunction (1/2) (397973/500000) (524071/1000000) (119553/1000000) (702377/1000000) 2 h ∂Scalar.fieldLaw (1/2)) ∈ (⟨118053/1000000,121053/1000000⟩ : Box) := by + apply gaussian_certificate (e := expression) (B := blocks) (h := (1/10)) (k := 5) (by norm_num) + · simpa only [expression,Rat.cast_div,Rat.cast_ofNat,Rat.cast_one,Rat.cast_zero] using integrandExpr_val (1/2) (397973/500000) (524071/1000000) (119553/1000000) (702377/1000000) 2 + · exact (continuous_scalarFunction _ _ _ _ _ _).measurable + · intro x + apply scalarFunction_bound <;> norm_num + · exact checks + · decide +kernel + +end SKRatio.Certificate.Data.J4K2 + +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Certificates/ScalarDataJ4K3.lean b/lean/OAI/Probability/SKRatio/Certificates/ScalarDataJ4K3.lean new file mode 100644 index 0000000000000000000000000000000000000000..bc088cf6122b140159e246aff41fbef92cace872 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Certificates/ScalarDataJ4K3.lean @@ -0,0 +1,154 @@ +import Mathlib +import OAI.Probability.SKRatio.Certificates.CertifiedBatches +import OAI.Probability.SKRatio.Certificates.CertifiedFunctionBounds + +namespace OAI + +noncomputable section +open Real MeasureTheory +namespace SKRatio.Certificate.Data.J4K3 + +def expression : Expr := integrandExpr (1/2) (397973/500000) (524071/1000000) (119553/1000000) (702377/1000000) 3 +def blocks : ℕ → Box + | 0 => ⟨-1/1000000,1/1000000⟩ + | 1 => ⟨-1/1000000,1/1000000⟩ + | 2 => ⟨-1/1000000,1/1000000⟩ + | 3 => ⟨-1/1000000,1/1000000⟩ + | 4 => ⟨-1/1000000,1/1000000⟩ + | 5 => ⟨-1/1000000,1/1000000⟩ + | 6 => ⟨-1/1000000,1/1000000⟩ + | 7 => ⟨-1/1000000,1/1000000⟩ + | 8 => ⟨-1/1000000,1/1000000⟩ + | 9 => ⟨-1/1000000,1/1000000⟩ + | 10 => ⟨-1/1000000,1/1000000⟩ + | 11 => ⟨-1/1000000,1/1000000⟩ + | 12 => ⟨0,1/1000000⟩ + | 13 => ⟨7/1000000,9/1000000⟩ + | 14 => ⟨37/500000,1/12500⟩ + | 15 => ⟨49/100000,257/500000⟩ + | 16 => ⟨1047/500000,2157/1000000⟩ + | 17 => ⟨1297/250000,2651/500000⟩ + | 18 => ⟨303/50000,6239/1000000⟩ + | 19 => ⟨107/62500,981/500000⟩ + | 20 => ⟨103/50000,667/250000⟩ + | 21 => ⟨12339/1000000,13363/1000000⟩ + | 22 => ⟨17301/1000000,9273/500000⟩ + | 23 => ⟨717/62500,12377/1000000⟩ + | 24 => ⟨4419/1000000,4847/1000000⟩ + | 25 => ⟨1089/1000000,311/250000⟩ + | 26 => ⟨9/50000,113/500000⟩ + | 27 => ⟨1/50000,31/1000000⟩ + | 28 => ⟨1/1000000,1/250000⟩ + | 29 => ⟨-1/1000000,1/1000000⟩ + | 30 => ⟨-1/1000000,1/1000000⟩ + | 31 => ⟨-1/1000000,1/1000000⟩ + | 32 => ⟨-1/1000000,1/1000000⟩ + | 33 => ⟨-1/1000000,1/1000000⟩ + | 34 => ⟨-1/1000000,1/1000000⟩ + | 35 => ⟨-1/1000000,1/1000000⟩ + | 36 => ⟨-1/1000000,1/1000000⟩ + | 37 => ⟨-1/1000000,1/1000000⟩ + | 38 => ⟨-1/1000000,1/1000000⟩ + | 39 => ⟨-1/1000000,1/1000000⟩ + | _ => Box.rat 0 + +lemma check_0 : expression.check (-10+(0:ℚ)*(5*(1/10))) (1/10) 5 (blocks 0) = true := by decide +kernel +lemma check_1 : expression.check (-10+(1:ℚ)*(5*(1/10))) (1/10) 5 (blocks 1) = true := by decide +kernel +lemma check_2 : expression.check (-10+(2:ℚ)*(5*(1/10))) (1/10) 5 (blocks 2) = true := by decide +kernel +lemma check_3 : expression.check (-10+(3:ℚ)*(5*(1/10))) (1/10) 5 (blocks 3) = true := by decide +kernel +lemma check_4 : expression.check (-10+(4:ℚ)*(5*(1/10))) (1/10) 5 (blocks 4) = true := by decide +kernel +lemma check_5 : expression.check (-10+(5:ℚ)*(5*(1/10))) (1/10) 5 (blocks 5) = true := by decide +kernel +lemma check_6 : expression.check (-10+(6:ℚ)*(5*(1/10))) (1/10) 5 (blocks 6) = true := by decide +kernel +lemma check_7 : expression.check (-10+(7:ℚ)*(5*(1/10))) (1/10) 5 (blocks 7) = true := by decide +kernel +lemma check_8 : expression.check (-10+(8:ℚ)*(5*(1/10))) (1/10) 5 (blocks 8) = true := by decide +kernel +lemma check_9 : expression.check (-10+(9:ℚ)*(5*(1/10))) (1/10) 5 (blocks 9) = true := by decide +kernel +lemma check_10 : expression.check (-10+(10:ℚ)*(5*(1/10))) (1/10) 5 (blocks 10) = true := by decide +kernel +lemma check_11 : expression.check (-10+(11:ℚ)*(5*(1/10))) (1/10) 5 (blocks 11) = true := by decide +kernel +lemma check_12 : expression.check (-10+(12:ℚ)*(5*(1/10))) (1/10) 5 (blocks 12) = true := by decide +kernel +lemma check_13 : expression.check (-10+(13:ℚ)*(5*(1/10))) (1/10) 5 (blocks 13) = true := by decide +kernel +lemma check_14 : expression.check (-10+(14:ℚ)*(5*(1/10))) (1/10) 5 (blocks 14) = true := by decide +kernel +lemma check_15 : expression.check (-10+(15:ℚ)*(5*(1/10))) (1/10) 5 (blocks 15) = true := by decide +kernel +lemma check_16 : expression.check (-10+(16:ℚ)*(5*(1/10))) (1/10) 5 (blocks 16) = true := by decide +kernel +lemma check_17 : expression.check (-10+(17:ℚ)*(5*(1/10))) (1/10) 5 (blocks 17) = true := by decide +kernel +lemma check_18 : expression.check (-10+(18:ℚ)*(5*(1/10))) (1/10) 5 (blocks 18) = true := by decide +kernel +lemma check_19 : expression.check (-10+(19:ℚ)*(5*(1/10))) (1/10) 5 (blocks 19) = true := by decide +kernel +lemma check_20 : expression.check (-10+(20:ℚ)*(5*(1/10))) (1/10) 5 (blocks 20) = true := by decide +kernel +lemma check_21 : expression.check (-10+(21:ℚ)*(5*(1/10))) (1/10) 5 (blocks 21) = true := by decide +kernel +lemma check_22 : expression.check (-10+(22:ℚ)*(5*(1/10))) (1/10) 5 (blocks 22) = true := by decide +kernel +lemma check_23 : expression.check (-10+(23:ℚ)*(5*(1/10))) (1/10) 5 (blocks 23) = true := by decide +kernel +lemma check_24 : expression.check (-10+(24:ℚ)*(5*(1/10))) (1/10) 5 (blocks 24) = true := by decide +kernel +lemma check_25 : expression.check (-10+(25:ℚ)*(5*(1/10))) (1/10) 5 (blocks 25) = true := by decide +kernel +lemma check_26 : expression.check (-10+(26:ℚ)*(5*(1/10))) (1/10) 5 (blocks 26) = true := by decide +kernel +lemma check_27 : expression.check (-10+(27:ℚ)*(5*(1/10))) (1/10) 5 (blocks 27) = true := by decide +kernel +lemma check_28 : expression.check (-10+(28:ℚ)*(5*(1/10))) (1/10) 5 (blocks 28) = true := by decide +kernel +lemma check_29 : expression.check (-10+(29:ℚ)*(5*(1/10))) (1/10) 5 (blocks 29) = true := by decide +kernel +lemma check_30 : expression.check (-10+(30:ℚ)*(5*(1/10))) (1/10) 5 (blocks 30) = true := by decide +kernel +lemma check_31 : expression.check (-10+(31:ℚ)*(5*(1/10))) (1/10) 5 (blocks 31) = true := by decide +kernel +lemma check_32 : expression.check (-10+(32:ℚ)*(5*(1/10))) (1/10) 5 (blocks 32) = true := by decide +kernel +lemma check_33 : expression.check (-10+(33:ℚ)*(5*(1/10))) (1/10) 5 (blocks 33) = true := by decide +kernel +lemma check_34 : expression.check (-10+(34:ℚ)*(5*(1/10))) (1/10) 5 (blocks 34) = true := by decide +kernel +lemma check_35 : expression.check (-10+(35:ℚ)*(5*(1/10))) (1/10) 5 (blocks 35) = true := by decide +kernel +lemma check_36 : expression.check (-10+(36:ℚ)*(5*(1/10))) (1/10) 5 (blocks 36) = true := by decide +kernel +lemma check_37 : expression.check (-10+(37:ℚ)*(5*(1/10))) (1/10) 5 (blocks 37) = true := by decide +kernel +lemma check_38 : expression.check (-10+(38:ℚ)*(5*(1/10))) (1/10) 5 (blocks 38) = true := by decide +kernel +lemma check_39 : expression.check (-10+(39:ℚ)*(5*(1/10))) (1/10) 5 (blocks 39) = true := by decide +kernel + +lemma checks (i : ℕ) (hi : i < 40) : + expression.check (-10+(i:ℚ)*(5*(1/10))) (1/10) 5 (blocks i) = true := by + interval_cases i + · exact check_0 + · exact check_1 + · exact check_2 + · exact check_3 + · exact check_4 + · exact check_5 + · exact check_6 + · exact check_7 + · exact check_8 + · exact check_9 + · exact check_10 + · exact check_11 + · exact check_12 + · exact check_13 + · exact check_14 + · exact check_15 + · exact check_16 + · exact check_17 + · exact check_18 + · exact check_19 + · exact check_20 + · exact check_21 + · exact check_22 + · exact check_23 + · exact check_24 + · exact check_25 + · exact check_26 + · exact check_27 + · exact check_28 + · exact check_29 + · exact check_30 + · exact check_31 + · exact check_32 + · exact check_33 + · exact check_34 + · exact check_35 + · exact check_36 + · exact check_37 + · exact check_38 + · exact check_39 + +theorem integral_bound : + (∫ h, scalarFunction (1/2) (397973/500000) (524071/1000000) (119553/1000000) (702377/1000000) 3 h ∂Scalar.fieldLaw (1/2)) ∈ (⟨0,7/250⟩ : Box) := by + apply gaussian_certificate (e := expression) (B := blocks) (h := (1/10)) (k := 5) (by norm_num) + · simpa only [expression,Rat.cast_div,Rat.cast_ofNat,Rat.cast_one,Rat.cast_zero] using integrandExpr_val (1/2) (397973/500000) (524071/1000000) (119553/1000000) (702377/1000000) 3 + · exact (continuous_scalarFunction _ _ _ _ _ _).measurable + · intro x + apply scalarFunction_bound <;> norm_num + · exact checks + · decide +kernel + +end SKRatio.Certificate.Data.J4K3 + +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Certificates/ScalarDataJ4K4.lean b/lean/OAI/Probability/SKRatio/Certificates/ScalarDataJ4K4.lean new file mode 100644 index 0000000000000000000000000000000000000000..a1c34fce730969918a0d9a5d34783c51f9d2b9ae --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Certificates/ScalarDataJ4K4.lean @@ -0,0 +1,154 @@ +import Mathlib +import OAI.Probability.SKRatio.Certificates.CertifiedBatches +import OAI.Probability.SKRatio.Certificates.CertifiedFunctionBounds + +namespace OAI + +noncomputable section +open Real MeasureTheory +namespace SKRatio.Certificate.Data.J4K4 + +def expression : Expr := integrandExpr (1/2) (397973/500000) (524071/1000000) (119553/1000000) (702377/1000000) 4 +def blocks : ℕ → Box + | 0 => ⟨-1/1000000,1/1000000⟩ + | 1 => ⟨-1/1000000,1/1000000⟩ + | 2 => ⟨-1/1000000,1/1000000⟩ + | 3 => ⟨-1/1000000,1/1000000⟩ + | 4 => ⟨-1/1000000,1/1000000⟩ + | 5 => ⟨-1/1000000,1/1000000⟩ + | 6 => ⟨-1/1000000,1/1000000⟩ + | 7 => ⟨-1/1000000,1/1000000⟩ + | 8 => ⟨-1/1000000,1/1000000⟩ + | 9 => ⟨0,1/1000000⟩ + | 10 => ⟨3/1000000,1/200000⟩ + | 11 => ⟨17/500000,9/250000⟩ + | 12 => ⟨103/500000,53/250000⟩ + | 13 => ⟨863/1000000,219/250000⟩ + | 14 => ⟨2299/1000000,2319/1000000⟩ + | 15 => ⟨397/125000,3229/1000000⟩ + | 16 => ⟨239/200000,1253/1000000⟩ + | 17 => ⟨1921/1000000,1027/500000⟩ + | 18 => ⟨811/62500,3271/250000⟩ + | 19 => ⟨16093/1000000,1017/62500⟩ + | 20 => ⟨889/250000,3781/1000000⟩ + | 21 => ⟨4629/1000000,4919/1000000⟩ + | 22 => ⟨18521/1000000,9469/500000⟩ + | 23 => ⟨10621/500000,2163/100000⟩ + | 24 => ⟨12909/1000000,1639/125000⟩ + | 25 => ⟨1251/250000,641/125000⟩ + | 26 => ⟨677/500000,703/500000⟩ + | 27 => ⟨67/250000,283/1000000⟩ + | 28 => ⟨39/1000000,43/1000000⟩ + | 29 => ⟨1/250000,3/500000⟩ + | 30 => ⟨0,1/1000000⟩ + | 31 => ⟨-1/1000000,1/1000000⟩ + | 32 => ⟨-1/1000000,1/1000000⟩ + | 33 => ⟨-1/1000000,1/1000000⟩ + | 34 => ⟨-1/1000000,1/1000000⟩ + | 35 => ⟨-1/1000000,1/1000000⟩ + | 36 => ⟨-1/1000000,1/1000000⟩ + | 37 => ⟨-1/1000000,1/1000000⟩ + | 38 => ⟨-1/1000000,1/1000000⟩ + | 39 => ⟨-1/1000000,1/1000000⟩ + | _ => Box.rat 0 + +lemma check_0 : expression.check (-10+(0:ℚ)*(5*(1/10))) (1/10) 5 (blocks 0) = true := by decide +kernel +lemma check_1 : expression.check (-10+(1:ℚ)*(5*(1/10))) (1/10) 5 (blocks 1) = true := by decide +kernel +lemma check_2 : expression.check (-10+(2:ℚ)*(5*(1/10))) (1/10) 5 (blocks 2) = true := by decide +kernel +lemma check_3 : expression.check (-10+(3:ℚ)*(5*(1/10))) (1/10) 5 (blocks 3) = true := by decide +kernel +lemma check_4 : expression.check (-10+(4:ℚ)*(5*(1/10))) (1/10) 5 (blocks 4) = true := by decide +kernel +lemma check_5 : expression.check (-10+(5:ℚ)*(5*(1/10))) (1/10) 5 (blocks 5) = true := by decide +kernel +lemma check_6 : expression.check (-10+(6:ℚ)*(5*(1/10))) (1/10) 5 (blocks 6) = true := by decide +kernel +lemma check_7 : expression.check (-10+(7:ℚ)*(5*(1/10))) (1/10) 5 (blocks 7) = true := by decide +kernel +lemma check_8 : expression.check (-10+(8:ℚ)*(5*(1/10))) (1/10) 5 (blocks 8) = true := by decide +kernel +lemma check_9 : expression.check (-10+(9:ℚ)*(5*(1/10))) (1/10) 5 (blocks 9) = true := by decide +kernel +lemma check_10 : expression.check (-10+(10:ℚ)*(5*(1/10))) (1/10) 5 (blocks 10) = true := by decide +kernel +lemma check_11 : expression.check (-10+(11:ℚ)*(5*(1/10))) (1/10) 5 (blocks 11) = true := by decide +kernel +lemma check_12 : expression.check (-10+(12:ℚ)*(5*(1/10))) (1/10) 5 (blocks 12) = true := by decide +kernel +lemma check_13 : expression.check (-10+(13:ℚ)*(5*(1/10))) (1/10) 5 (blocks 13) = true := by decide +kernel +lemma check_14 : expression.check (-10+(14:ℚ)*(5*(1/10))) (1/10) 5 (blocks 14) = true := by decide +kernel +lemma check_15 : expression.check (-10+(15:ℚ)*(5*(1/10))) (1/10) 5 (blocks 15) = true := by decide +kernel +lemma check_16 : expression.check (-10+(16:ℚ)*(5*(1/10))) (1/10) 5 (blocks 16) = true := by decide +kernel +lemma check_17 : expression.check (-10+(17:ℚ)*(5*(1/10))) (1/10) 5 (blocks 17) = true := by decide +kernel +lemma check_18 : expression.check (-10+(18:ℚ)*(5*(1/10))) (1/10) 5 (blocks 18) = true := by decide +kernel +lemma check_19 : expression.check (-10+(19:ℚ)*(5*(1/10))) (1/10) 5 (blocks 19) = true := by decide +kernel +lemma check_20 : expression.check (-10+(20:ℚ)*(5*(1/10))) (1/10) 5 (blocks 20) = true := by decide +kernel +lemma check_21 : expression.check (-10+(21:ℚ)*(5*(1/10))) (1/10) 5 (blocks 21) = true := by decide +kernel +lemma check_22 : expression.check (-10+(22:ℚ)*(5*(1/10))) (1/10) 5 (blocks 22) = true := by decide +kernel +lemma check_23 : expression.check (-10+(23:ℚ)*(5*(1/10))) (1/10) 5 (blocks 23) = true := by decide +kernel +lemma check_24 : expression.check (-10+(24:ℚ)*(5*(1/10))) (1/10) 5 (blocks 24) = true := by decide +kernel +lemma check_25 : expression.check (-10+(25:ℚ)*(5*(1/10))) (1/10) 5 (blocks 25) = true := by decide +kernel +lemma check_26 : expression.check (-10+(26:ℚ)*(5*(1/10))) (1/10) 5 (blocks 26) = true := by decide +kernel +lemma check_27 : expression.check (-10+(27:ℚ)*(5*(1/10))) (1/10) 5 (blocks 27) = true := by decide +kernel +lemma check_28 : expression.check (-10+(28:ℚ)*(5*(1/10))) (1/10) 5 (blocks 28) = true := by decide +kernel +lemma check_29 : expression.check (-10+(29:ℚ)*(5*(1/10))) (1/10) 5 (blocks 29) = true := by decide +kernel +lemma check_30 : expression.check (-10+(30:ℚ)*(5*(1/10))) (1/10) 5 (blocks 30) = true := by decide +kernel +lemma check_31 : expression.check (-10+(31:ℚ)*(5*(1/10))) (1/10) 5 (blocks 31) = true := by decide +kernel +lemma check_32 : expression.check (-10+(32:ℚ)*(5*(1/10))) (1/10) 5 (blocks 32) = true := by decide +kernel +lemma check_33 : expression.check (-10+(33:ℚ)*(5*(1/10))) (1/10) 5 (blocks 33) = true := by decide +kernel +lemma check_34 : expression.check (-10+(34:ℚ)*(5*(1/10))) (1/10) 5 (blocks 34) = true := by decide +kernel +lemma check_35 : expression.check (-10+(35:ℚ)*(5*(1/10))) (1/10) 5 (blocks 35) = true := by decide +kernel +lemma check_36 : expression.check (-10+(36:ℚ)*(5*(1/10))) (1/10) 5 (blocks 36) = true := by decide +kernel +lemma check_37 : expression.check (-10+(37:ℚ)*(5*(1/10))) (1/10) 5 (blocks 37) = true := by decide +kernel +lemma check_38 : expression.check (-10+(38:ℚ)*(5*(1/10))) (1/10) 5 (blocks 38) = true := by decide +kernel +lemma check_39 : expression.check (-10+(39:ℚ)*(5*(1/10))) (1/10) 5 (blocks 39) = true := by decide +kernel + +lemma checks (i : ℕ) (hi : i < 40) : + expression.check (-10+(i:ℚ)*(5*(1/10))) (1/10) 5 (blocks i) = true := by + interval_cases i + · exact check_0 + · exact check_1 + · exact check_2 + · exact check_3 + · exact check_4 + · exact check_5 + · exact check_6 + · exact check_7 + · exact check_8 + · exact check_9 + · exact check_10 + · exact check_11 + · exact check_12 + · exact check_13 + · exact check_14 + · exact check_15 + · exact check_16 + · exact check_17 + · exact check_18 + · exact check_19 + · exact check_20 + · exact check_21 + · exact check_22 + · exact check_23 + · exact check_24 + · exact check_25 + · exact check_26 + · exact check_27 + · exact check_28 + · exact check_29 + · exact check_30 + · exact check_31 + · exact check_32 + · exact check_33 + · exact check_34 + · exact check_35 + · exact check_36 + · exact check_37 + · exact check_38 + · exact check_39 + +theorem integral_bound : + (∫ h, scalarFunction (1/2) (397973/500000) (524071/1000000) (119553/1000000) (702377/1000000) 4 h ∂Scalar.fieldLaw (1/2)) ∈ (⟨0,43681/1000000⟩ : Box) := by + apply gaussian_certificate (e := expression) (B := blocks) (h := (1/10)) (k := 5) (by norm_num) + · simpa only [expression,Rat.cast_div,Rat.cast_ofNat,Rat.cast_one,Rat.cast_zero] using integrandExpr_val (1/2) (397973/500000) (524071/1000000) (119553/1000000) (702377/1000000) 4 + · exact (continuous_scalarFunction _ _ _ _ _ _).measurable + · intro x + apply scalarFunction_bound <;> norm_num + · exact checks + · decide +kernel + +end SKRatio.Certificate.Data.J4K4 + +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Certificates/ScalarDataJ4K5.lean b/lean/OAI/Probability/SKRatio/Certificates/ScalarDataJ4K5.lean new file mode 100644 index 0000000000000000000000000000000000000000..3b273dc6457908f79d60f1aefc0f858f6dd9ca3a --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Certificates/ScalarDataJ4K5.lean @@ -0,0 +1,154 @@ +import Mathlib +import OAI.Probability.SKRatio.Certificates.CertifiedBatches +import OAI.Probability.SKRatio.Certificates.CertifiedFunctionBounds + +namespace OAI + +noncomputable section +open Real MeasureTheory +namespace SKRatio.Certificate.Data.J4K5 + +def expression : Expr := integrandExpr (1/2) (397973/500000) (524071/1000000) (119553/1000000) (702377/1000000) 5 +def blocks : ℕ → Box + | 0 => ⟨-1/1000000,1/1000000⟩ + | 1 => ⟨-1/1000000,1/1000000⟩ + | 2 => ⟨-1/1000000,1/1000000⟩ + | 3 => ⟨-1/1000000,1/1000000⟩ + | 4 => ⟨-1/1000000,1/1000000⟩ + | 5 => ⟨-1/1000000,1/1000000⟩ + | 6 => ⟨-1/1000000,1/1000000⟩ + | 7 => ⟨-1/1000000,1/1000000⟩ + | 8 => ⟨-1/1000000,1/1000000⟩ + | 9 => ⟨-1/1000000,1/1000000⟩ + | 10 => ⟨1/1000000,3/1000000⟩ + | 11 => ⟨1/62500,9/500000⟩ + | 12 => ⟨27/250000,7/62500⟩ + | 13 => ⟨261/500000,531/1000000⟩ + | 14 => ⟨71/40000,1791/1000000⟩ + | 15 => ⟨3989/1000000,1003/250000⟩ + | 16 => ⟨207/40000,523/100000⟩ + | 17 => ⟨2753/1000000,2797/1000000⟩ + | 18 => ⟨19/62500,93/250000⟩ + | 19 => ⟨39/12500,3177/1000000⟩ + | 20 => ⟨117/25000,4797/1000000⟩ + | 21 => ⟨619/500000,723/500000⟩ + | 22 => ⟨51/125000,347/500000⟩ + | 23 => ⟨151/62500,2683/1000000⟩ + | 24 => ⟨41/15625,701/250000⟩ + | 25 => ⟨687/500000,733/500000⟩ + | 26 => ⟨439/1000000,3/6250⟩ + | 27 => ⟨19/200000,27/250000⟩ + | 28 => ⟨7/500000,9/500000⟩ + | 29 => ⟨1/1000000,3/1000000⟩ + | 30 => ⟨-1/1000000,1/1000000⟩ + | 31 => ⟨-1/1000000,1/1000000⟩ + | 32 => ⟨-1/1000000,1/1000000⟩ + | 33 => ⟨-1/1000000,1/1000000⟩ + | 34 => ⟨-1/1000000,1/1000000⟩ + | 35 => ⟨-1/1000000,1/1000000⟩ + | 36 => ⟨-1/1000000,1/1000000⟩ + | 37 => ⟨-1/1000000,1/1000000⟩ + | 38 => ⟨-1/1000000,1/1000000⟩ + | 39 => ⟨-1/1000000,1/1000000⟩ + | _ => Box.rat 0 + +lemma check_0 : expression.check (-10+(0:ℚ)*(5*(1/10))) (1/10) 5 (blocks 0) = true := by decide +kernel +lemma check_1 : expression.check (-10+(1:ℚ)*(5*(1/10))) (1/10) 5 (blocks 1) = true := by decide +kernel +lemma check_2 : expression.check (-10+(2:ℚ)*(5*(1/10))) (1/10) 5 (blocks 2) = true := by decide +kernel +lemma check_3 : expression.check (-10+(3:ℚ)*(5*(1/10))) (1/10) 5 (blocks 3) = true := by decide +kernel +lemma check_4 : expression.check (-10+(4:ℚ)*(5*(1/10))) (1/10) 5 (blocks 4) = true := by decide +kernel +lemma check_5 : expression.check (-10+(5:ℚ)*(5*(1/10))) (1/10) 5 (blocks 5) = true := by decide +kernel +lemma check_6 : expression.check (-10+(6:ℚ)*(5*(1/10))) (1/10) 5 (blocks 6) = true := by decide +kernel +lemma check_7 : expression.check (-10+(7:ℚ)*(5*(1/10))) (1/10) 5 (blocks 7) = true := by decide +kernel +lemma check_8 : expression.check (-10+(8:ℚ)*(5*(1/10))) (1/10) 5 (blocks 8) = true := by decide +kernel +lemma check_9 : expression.check (-10+(9:ℚ)*(5*(1/10))) (1/10) 5 (blocks 9) = true := by decide +kernel +lemma check_10 : expression.check (-10+(10:ℚ)*(5*(1/10))) (1/10) 5 (blocks 10) = true := by decide +kernel +lemma check_11 : expression.check (-10+(11:ℚ)*(5*(1/10))) (1/10) 5 (blocks 11) = true := by decide +kernel +lemma check_12 : expression.check (-10+(12:ℚ)*(5*(1/10))) (1/10) 5 (blocks 12) = true := by decide +kernel +lemma check_13 : expression.check (-10+(13:ℚ)*(5*(1/10))) (1/10) 5 (blocks 13) = true := by decide +kernel +lemma check_14 : expression.check (-10+(14:ℚ)*(5*(1/10))) (1/10) 5 (blocks 14) = true := by decide +kernel +lemma check_15 : expression.check (-10+(15:ℚ)*(5*(1/10))) (1/10) 5 (blocks 15) = true := by decide +kernel +lemma check_16 : expression.check (-10+(16:ℚ)*(5*(1/10))) (1/10) 5 (blocks 16) = true := by decide +kernel +lemma check_17 : expression.check (-10+(17:ℚ)*(5*(1/10))) (1/10) 5 (blocks 17) = true := by decide +kernel +lemma check_18 : expression.check (-10+(18:ℚ)*(5*(1/10))) (1/10) 5 (blocks 18) = true := by decide +kernel +lemma check_19 : expression.check (-10+(19:ℚ)*(5*(1/10))) (1/10) 5 (blocks 19) = true := by decide +kernel +lemma check_20 : expression.check (-10+(20:ℚ)*(5*(1/10))) (1/10) 5 (blocks 20) = true := by decide +kernel +lemma check_21 : expression.check (-10+(21:ℚ)*(5*(1/10))) (1/10) 5 (blocks 21) = true := by decide +kernel +lemma check_22 : expression.check (-10+(22:ℚ)*(5*(1/10))) (1/10) 5 (blocks 22) = true := by decide +kernel +lemma check_23 : expression.check (-10+(23:ℚ)*(5*(1/10))) (1/10) 5 (blocks 23) = true := by decide +kernel +lemma check_24 : expression.check (-10+(24:ℚ)*(5*(1/10))) (1/10) 5 (blocks 24) = true := by decide +kernel +lemma check_25 : expression.check (-10+(25:ℚ)*(5*(1/10))) (1/10) 5 (blocks 25) = true := by decide +kernel +lemma check_26 : expression.check (-10+(26:ℚ)*(5*(1/10))) (1/10) 5 (blocks 26) = true := by decide +kernel +lemma check_27 : expression.check (-10+(27:ℚ)*(5*(1/10))) (1/10) 5 (blocks 27) = true := by decide +kernel +lemma check_28 : expression.check (-10+(28:ℚ)*(5*(1/10))) (1/10) 5 (blocks 28) = true := by decide +kernel +lemma check_29 : expression.check (-10+(29:ℚ)*(5*(1/10))) (1/10) 5 (blocks 29) = true := by decide +kernel +lemma check_30 : expression.check (-10+(30:ℚ)*(5*(1/10))) (1/10) 5 (blocks 30) = true := by decide +kernel +lemma check_31 : expression.check (-10+(31:ℚ)*(5*(1/10))) (1/10) 5 (blocks 31) = true := by decide +kernel +lemma check_32 : expression.check (-10+(32:ℚ)*(5*(1/10))) (1/10) 5 (blocks 32) = true := by decide +kernel +lemma check_33 : expression.check (-10+(33:ℚ)*(5*(1/10))) (1/10) 5 (blocks 33) = true := by decide +kernel +lemma check_34 : expression.check (-10+(34:ℚ)*(5*(1/10))) (1/10) 5 (blocks 34) = true := by decide +kernel +lemma check_35 : expression.check (-10+(35:ℚ)*(5*(1/10))) (1/10) 5 (blocks 35) = true := by decide +kernel +lemma check_36 : expression.check (-10+(36:ℚ)*(5*(1/10))) (1/10) 5 (blocks 36) = true := by decide +kernel +lemma check_37 : expression.check (-10+(37:ℚ)*(5*(1/10))) (1/10) 5 (blocks 37) = true := by decide +kernel +lemma check_38 : expression.check (-10+(38:ℚ)*(5*(1/10))) (1/10) 5 (blocks 38) = true := by decide +kernel +lemma check_39 : expression.check (-10+(39:ℚ)*(5*(1/10))) (1/10) 5 (blocks 39) = true := by decide +kernel + +lemma checks (i : ℕ) (hi : i < 40) : + expression.check (-10+(i:ℚ)*(5*(1/10))) (1/10) 5 (blocks i) = true := by + interval_cases i + · exact check_0 + · exact check_1 + · exact check_2 + · exact check_3 + · exact check_4 + · exact check_5 + · exact check_6 + · exact check_7 + · exact check_8 + · exact check_9 + · exact check_10 + · exact check_11 + · exact check_12 + · exact check_13 + · exact check_14 + · exact check_15 + · exact check_16 + · exact check_17 + · exact check_18 + · exact check_19 + · exact check_20 + · exact check_21 + · exact check_22 + · exact check_23 + · exact check_24 + · exact check_25 + · exact check_26 + · exact check_27 + · exact check_28 + · exact check_29 + · exact check_30 + · exact check_31 + · exact check_32 + · exact check_33 + · exact check_34 + · exact check_35 + · exact check_36 + · exact check_37 + · exact check_38 + · exact check_39 + +theorem integral_bound : + (∫ h, scalarFunction (1/2) (397973/500000) (524071/1000000) (119553/1000000) (702377/1000000) 5 h ∂Scalar.fieldLaw (1/2)) ∈ (⟨0,529/40000⟩ : Box) := by + apply gaussian_certificate (e := expression) (B := blocks) (h := (1/10)) (k := 5) (by norm_num) + · simpa only [expression,Rat.cast_div,Rat.cast_ofNat,Rat.cast_one,Rat.cast_zero] using integrandExpr_val (1/2) (397973/500000) (524071/1000000) (119553/1000000) (702377/1000000) 5 + · exact (continuous_scalarFunction _ _ _ _ _ _).measurable + · intro x + apply scalarFunction_bound <;> norm_num + · exact checks + · decide +kernel + +end SKRatio.Certificate.Data.J4K5 + +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Certificates/ScalarDataJ4K6.lean b/lean/OAI/Probability/SKRatio/Certificates/ScalarDataJ4K6.lean new file mode 100644 index 0000000000000000000000000000000000000000..74826a0b35758bf5c40814be9b1037ddc9a089d9 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Certificates/ScalarDataJ4K6.lean @@ -0,0 +1,154 @@ +import Mathlib +import OAI.Probability.SKRatio.Certificates.CertifiedBatches +import OAI.Probability.SKRatio.Certificates.CertifiedFunctionBounds + +namespace OAI + +noncomputable section +open Real MeasureTheory +namespace SKRatio.Certificate.Data.J4K6 + +def expression : Expr := integrandExpr (1/2) (397973/500000) (524071/1000000) (119553/1000000) (702377/1000000) 6 +def blocks : ℕ → Box + | 0 => ⟨-1/1000000,1/1000000⟩ + | 1 => ⟨-1/1000000,1/1000000⟩ + | 2 => ⟨-1/1000000,1/1000000⟩ + | 3 => ⟨-1/1000000,1/1000000⟩ + | 4 => ⟨-1/1000000,1/1000000⟩ + | 5 => ⟨-1/1000000,1/1000000⟩ + | 6 => ⟨-1/1000000,1/1000000⟩ + | 7 => ⟨-1/1000000,1/1000000⟩ + | 8 => ⟨-1/1000000,1/1000000⟩ + | 9 => ⟨-1/1000000,1/1000000⟩ + | 10 => ⟨0,1/1000000⟩ + | 11 => ⟨1/500000,1/250000⟩ + | 12 => ⟨17/500000,37/1000000⟩ + | 13 => ⟨151/500000,313/1000000⟩ + | 14 => ⟨81/40000,1037/500000⟩ + | 15 => ⟨148/15625,1199/125000⟩ + | 16 => ⟨13669/500000,27471/1000000⟩ + | 17 => ⟨40599/1000000,4099/100000⟩ + | 18 => ⟨10913/500000,2207/100000⟩ + | 19 => ⟨2103/1000000,619/250000⟩ + | 20 => ⟨1073/62500,3497/200000⟩ + | 21 => ⟨25081/1000000,25477/1000000⟩ + | 22 => ⟨1283/100000,13143/1000000⟩ + | 23 => ⟨119/40000,1621/500000⟩ + | 24 => ⟨141/500000,391/1000000⟩ + | 25 => ⟨-7/1000000,3/125000⟩ + | 26 => ⟨-1/500000,7/1000000⟩ + | 27 => ⟨0,1/250000⟩ + | 28 => ⟨0,1/1000000⟩ + | 29 => ⟨-1/1000000,1/1000000⟩ + | 30 => ⟨-1/1000000,1/1000000⟩ + | 31 => ⟨-1/1000000,1/1000000⟩ + | 32 => ⟨-1/1000000,1/1000000⟩ + | 33 => ⟨-1/1000000,1/1000000⟩ + | 34 => ⟨-1/1000000,1/1000000⟩ + | 35 => ⟨-1/1000000,1/1000000⟩ + | 36 => ⟨-1/1000000,1/1000000⟩ + | 37 => ⟨-1/1000000,1/1000000⟩ + | 38 => ⟨-1/1000000,1/1000000⟩ + | 39 => ⟨-1/1000000,1/1000000⟩ + | _ => Box.rat 0 + +lemma check_0 : expression.check (-10+(0:ℚ)*(5*(1/10))) (1/10) 5 (blocks 0) = true := by decide +kernel +lemma check_1 : expression.check (-10+(1:ℚ)*(5*(1/10))) (1/10) 5 (blocks 1) = true := by decide +kernel +lemma check_2 : expression.check (-10+(2:ℚ)*(5*(1/10))) (1/10) 5 (blocks 2) = true := by decide +kernel +lemma check_3 : expression.check (-10+(3:ℚ)*(5*(1/10))) (1/10) 5 (blocks 3) = true := by decide +kernel +lemma check_4 : expression.check (-10+(4:ℚ)*(5*(1/10))) (1/10) 5 (blocks 4) = true := by decide +kernel +lemma check_5 : expression.check (-10+(5:ℚ)*(5*(1/10))) (1/10) 5 (blocks 5) = true := by decide +kernel +lemma check_6 : expression.check (-10+(6:ℚ)*(5*(1/10))) (1/10) 5 (blocks 6) = true := by decide +kernel +lemma check_7 : expression.check (-10+(7:ℚ)*(5*(1/10))) (1/10) 5 (blocks 7) = true := by decide +kernel +lemma check_8 : expression.check (-10+(8:ℚ)*(5*(1/10))) (1/10) 5 (blocks 8) = true := by decide +kernel +lemma check_9 : expression.check (-10+(9:ℚ)*(5*(1/10))) (1/10) 5 (blocks 9) = true := by decide +kernel +lemma check_10 : expression.check (-10+(10:ℚ)*(5*(1/10))) (1/10) 5 (blocks 10) = true := by decide +kernel +lemma check_11 : expression.check (-10+(11:ℚ)*(5*(1/10))) (1/10) 5 (blocks 11) = true := by decide +kernel +lemma check_12 : expression.check (-10+(12:ℚ)*(5*(1/10))) (1/10) 5 (blocks 12) = true := by decide +kernel +lemma check_13 : expression.check (-10+(13:ℚ)*(5*(1/10))) (1/10) 5 (blocks 13) = true := by decide +kernel +lemma check_14 : expression.check (-10+(14:ℚ)*(5*(1/10))) (1/10) 5 (blocks 14) = true := by decide +kernel +lemma check_15 : expression.check (-10+(15:ℚ)*(5*(1/10))) (1/10) 5 (blocks 15) = true := by decide +kernel +lemma check_16 : expression.check (-10+(16:ℚ)*(5*(1/10))) (1/10) 5 (blocks 16) = true := by decide +kernel +lemma check_17 : expression.check (-10+(17:ℚ)*(5*(1/10))) (1/10) 5 (blocks 17) = true := by decide +kernel +lemma check_18 : expression.check (-10+(18:ℚ)*(5*(1/10))) (1/10) 5 (blocks 18) = true := by decide +kernel +lemma check_19 : expression.check (-10+(19:ℚ)*(5*(1/10))) (1/10) 5 (blocks 19) = true := by decide +kernel +lemma check_20 : expression.check (-10+(20:ℚ)*(5*(1/10))) (1/10) 5 (blocks 20) = true := by decide +kernel +lemma check_21 : expression.check (-10+(21:ℚ)*(5*(1/10))) (1/10) 5 (blocks 21) = true := by decide +kernel +lemma check_22 : expression.check (-10+(22:ℚ)*(5*(1/10))) (1/10) 5 (blocks 22) = true := by decide +kernel +lemma check_23 : expression.check (-10+(23:ℚ)*(5*(1/10))) (1/10) 5 (blocks 23) = true := by decide +kernel +lemma check_24 : expression.check (-10+(24:ℚ)*(5*(1/10))) (1/10) 5 (blocks 24) = true := by decide +kernel +lemma check_25 : expression.check (-10+(25:ℚ)*(5*(1/10))) (1/10) 5 (blocks 25) = true := by decide +kernel +lemma check_26 : expression.check (-10+(26:ℚ)*(5*(1/10))) (1/10) 5 (blocks 26) = true := by decide +kernel +lemma check_27 : expression.check (-10+(27:ℚ)*(5*(1/10))) (1/10) 5 (blocks 27) = true := by decide +kernel +lemma check_28 : expression.check (-10+(28:ℚ)*(5*(1/10))) (1/10) 5 (blocks 28) = true := by decide +kernel +lemma check_29 : expression.check (-10+(29:ℚ)*(5*(1/10))) (1/10) 5 (blocks 29) = true := by decide +kernel +lemma check_30 : expression.check (-10+(30:ℚ)*(5*(1/10))) (1/10) 5 (blocks 30) = true := by decide +kernel +lemma check_31 : expression.check (-10+(31:ℚ)*(5*(1/10))) (1/10) 5 (blocks 31) = true := by decide +kernel +lemma check_32 : expression.check (-10+(32:ℚ)*(5*(1/10))) (1/10) 5 (blocks 32) = true := by decide +kernel +lemma check_33 : expression.check (-10+(33:ℚ)*(5*(1/10))) (1/10) 5 (blocks 33) = true := by decide +kernel +lemma check_34 : expression.check (-10+(34:ℚ)*(5*(1/10))) (1/10) 5 (blocks 34) = true := by decide +kernel +lemma check_35 : expression.check (-10+(35:ℚ)*(5*(1/10))) (1/10) 5 (blocks 35) = true := by decide +kernel +lemma check_36 : expression.check (-10+(36:ℚ)*(5*(1/10))) (1/10) 5 (blocks 36) = true := by decide +kernel +lemma check_37 : expression.check (-10+(37:ℚ)*(5*(1/10))) (1/10) 5 (blocks 37) = true := by decide +kernel +lemma check_38 : expression.check (-10+(38:ℚ)*(5*(1/10))) (1/10) 5 (blocks 38) = true := by decide +kernel +lemma check_39 : expression.check (-10+(39:ℚ)*(5*(1/10))) (1/10) 5 (blocks 39) = true := by decide +kernel + +lemma checks (i : ℕ) (hi : i < 40) : + expression.check (-10+(i:ℚ)*(5*(1/10))) (1/10) 5 (blocks i) = true := by + interval_cases i + · exact check_0 + · exact check_1 + · exact check_2 + · exact check_3 + · exact check_4 + · exact check_5 + · exact check_6 + · exact check_7 + · exact check_8 + · exact check_9 + · exact check_10 + · exact check_11 + · exact check_12 + · exact check_13 + · exact check_14 + · exact check_15 + · exact check_16 + · exact check_17 + · exact check_18 + · exact check_19 + · exact check_20 + · exact check_21 + · exact check_22 + · exact check_23 + · exact check_24 + · exact check_25 + · exact check_26 + · exact check_27 + · exact check_28 + · exact check_29 + · exact check_30 + · exact check_31 + · exact check_32 + · exact check_33 + · exact check_34 + · exact check_35 + · exact check_36 + · exact check_37 + · exact check_38 + · exact check_39 + +theorem integral_bound : + (∫ h, scalarFunction (1/2) (397973/500000) (524071/1000000) (119553/1000000) (702377/1000000) 6 h ∂Scalar.fieldLaw (1/2)) ∈ (⟨0,66049/1000000⟩ : Box) := by + apply gaussian_certificate (e := expression) (B := blocks) (h := (1/10)) (k := 5) (by norm_num) + · simpa only [expression,Rat.cast_div,Rat.cast_ofNat,Rat.cast_one,Rat.cast_zero] using integrandExpr_val (1/2) (397973/500000) (524071/1000000) (119553/1000000) (702377/1000000) 6 + · exact (continuous_scalarFunction _ _ _ _ _ _).measurable + · intro x + apply scalarFunction_bound <;> norm_num + · exact checks + · decide +kernel + +end SKRatio.Certificate.Data.J4K6 + +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Certificates/ScalarDataJ4K7.lean b/lean/OAI/Probability/SKRatio/Certificates/ScalarDataJ4K7.lean new file mode 100644 index 0000000000000000000000000000000000000000..810fabfce6d4dd82eededd756167ef7992cc5c10 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Certificates/ScalarDataJ4K7.lean @@ -0,0 +1,154 @@ +import Mathlib +import OAI.Probability.SKRatio.Certificates.CertifiedBatches +import OAI.Probability.SKRatio.Certificates.CertifiedFunctionBounds + +namespace OAI + +noncomputable section +open Real MeasureTheory +namespace SKRatio.Certificate.Data.J4K7 + +def expression : Expr := integrandExpr (1/2) (397973/500000) (524071/1000000) (119553/1000000) (702377/1000000) 7 +def blocks : ℕ → Box + | 0 => ⟨-1/1000000,1/1000000⟩ + | 1 => ⟨-1/1000000,1/1000000⟩ + | 2 => ⟨-1/1000000,1/1000000⟩ + | 3 => ⟨-1/1000000,1/1000000⟩ + | 4 => ⟨-1/1000000,1/1000000⟩ + | 5 => ⟨-1/1000000,1/1000000⟩ + | 6 => ⟨-1/1000000,1/1000000⟩ + | 7 => ⟨-1/1000000,1/1000000⟩ + | 8 => ⟨0,1/1000000⟩ + | 9 => ⟨1/250000,3/500000⟩ + | 10 => ⟨13/250000,7/125000⟩ + | 11 => ⟨433/1000000,7/15625⟩ + | 12 => ⟨557/200000,2857/1000000⟩ + | 13 => ⟨1757/125000,1431/100000⟩ + | 14 => ⟨27361/500000,55353/1000000⟩ + | 15 => ⟨78913/500000,79351/500000⟩ + | 16 => ⟨310803/1000000,312203/1000000⟩ + | 17 => ⟨36263/100000,365337/1000000⟩ + | 18 => ⟨5811/31250,187399/1000000⟩ + | 19 => ⟨16431/1000000,18853/1000000⟩ + | 20 => ⟨49069/500000,19933/200000⟩ + | 21 => ⟨218973/1000000,2771/12500⟩ + | 22 => ⟨196003/1000000,198021/1000000⟩ + | 23 => ⟨107543/1000000,109349/1000000⟩ + | 24 => ⟨43249/1000000,22291/500000⟩ + | 25 => ⟨1389/100000,14549/1000000⟩ + | 26 => ⟨913/250000,779/200000⟩ + | 27 => ⟨39/50000,849/1000000⟩ + | 28 => ⟨133/1000000,37/250000⟩ + | 29 => ⟨17/1000000,21/1000000⟩ + | 30 => ⟨1/1000000,3/1000000⟩ + | 31 => ⟨-1/1000000,1/1000000⟩ + | 32 => ⟨-1/1000000,1/1000000⟩ + | 33 => ⟨-1/1000000,1/1000000⟩ + | 34 => ⟨-1/1000000,1/1000000⟩ + | 35 => ⟨-1/1000000,1/1000000⟩ + | 36 => ⟨-1/1000000,1/1000000⟩ + | 37 => ⟨-1/1000000,1/1000000⟩ + | 38 => ⟨-1/1000000,1/1000000⟩ + | 39 => ⟨-1/1000000,1/1000000⟩ + | _ => Box.rat 0 + +lemma check_0 : expression.check (-10+(0:ℚ)*(5*(1/10))) (1/10) 5 (blocks 0) = true := by decide +kernel +lemma check_1 : expression.check (-10+(1:ℚ)*(5*(1/10))) (1/10) 5 (blocks 1) = true := by decide +kernel +lemma check_2 : expression.check (-10+(2:ℚ)*(5*(1/10))) (1/10) 5 (blocks 2) = true := by decide +kernel +lemma check_3 : expression.check (-10+(3:ℚ)*(5*(1/10))) (1/10) 5 (blocks 3) = true := by decide +kernel +lemma check_4 : expression.check (-10+(4:ℚ)*(5*(1/10))) (1/10) 5 (blocks 4) = true := by decide +kernel +lemma check_5 : expression.check (-10+(5:ℚ)*(5*(1/10))) (1/10) 5 (blocks 5) = true := by decide +kernel +lemma check_6 : expression.check (-10+(6:ℚ)*(5*(1/10))) (1/10) 5 (blocks 6) = true := by decide +kernel +lemma check_7 : expression.check (-10+(7:ℚ)*(5*(1/10))) (1/10) 5 (blocks 7) = true := by decide +kernel +lemma check_8 : expression.check (-10+(8:ℚ)*(5*(1/10))) (1/10) 5 (blocks 8) = true := by decide +kernel +lemma check_9 : expression.check (-10+(9:ℚ)*(5*(1/10))) (1/10) 5 (blocks 9) = true := by decide +kernel +lemma check_10 : expression.check (-10+(10:ℚ)*(5*(1/10))) (1/10) 5 (blocks 10) = true := by decide +kernel +lemma check_11 : expression.check (-10+(11:ℚ)*(5*(1/10))) (1/10) 5 (blocks 11) = true := by decide +kernel +lemma check_12 : expression.check (-10+(12:ℚ)*(5*(1/10))) (1/10) 5 (blocks 12) = true := by decide +kernel +lemma check_13 : expression.check (-10+(13:ℚ)*(5*(1/10))) (1/10) 5 (blocks 13) = true := by decide +kernel +lemma check_14 : expression.check (-10+(14:ℚ)*(5*(1/10))) (1/10) 5 (blocks 14) = true := by decide +kernel +lemma check_15 : expression.check (-10+(15:ℚ)*(5*(1/10))) (1/10) 5 (blocks 15) = true := by decide +kernel +lemma check_16 : expression.check (-10+(16:ℚ)*(5*(1/10))) (1/10) 5 (blocks 16) = true := by decide +kernel +lemma check_17 : expression.check (-10+(17:ℚ)*(5*(1/10))) (1/10) 5 (blocks 17) = true := by decide +kernel +lemma check_18 : expression.check (-10+(18:ℚ)*(5*(1/10))) (1/10) 5 (blocks 18) = true := by decide +kernel +lemma check_19 : expression.check (-10+(19:ℚ)*(5*(1/10))) (1/10) 5 (blocks 19) = true := by decide +kernel +lemma check_20 : expression.check (-10+(20:ℚ)*(5*(1/10))) (1/10) 5 (blocks 20) = true := by decide +kernel +lemma check_21 : expression.check (-10+(21:ℚ)*(5*(1/10))) (1/10) 5 (blocks 21) = true := by decide +kernel +lemma check_22 : expression.check (-10+(22:ℚ)*(5*(1/10))) (1/10) 5 (blocks 22) = true := by decide +kernel +lemma check_23 : expression.check (-10+(23:ℚ)*(5*(1/10))) (1/10) 5 (blocks 23) = true := by decide +kernel +lemma check_24 : expression.check (-10+(24:ℚ)*(5*(1/10))) (1/10) 5 (blocks 24) = true := by decide +kernel +lemma check_25 : expression.check (-10+(25:ℚ)*(5*(1/10))) (1/10) 5 (blocks 25) = true := by decide +kernel +lemma check_26 : expression.check (-10+(26:ℚ)*(5*(1/10))) (1/10) 5 (blocks 26) = true := by decide +kernel +lemma check_27 : expression.check (-10+(27:ℚ)*(5*(1/10))) (1/10) 5 (blocks 27) = true := by decide +kernel +lemma check_28 : expression.check (-10+(28:ℚ)*(5*(1/10))) (1/10) 5 (blocks 28) = true := by decide +kernel +lemma check_29 : expression.check (-10+(29:ℚ)*(5*(1/10))) (1/10) 5 (blocks 29) = true := by decide +kernel +lemma check_30 : expression.check (-10+(30:ℚ)*(5*(1/10))) (1/10) 5 (blocks 30) = true := by decide +kernel +lemma check_31 : expression.check (-10+(31:ℚ)*(5*(1/10))) (1/10) 5 (blocks 31) = true := by decide +kernel +lemma check_32 : expression.check (-10+(32:ℚ)*(5*(1/10))) (1/10) 5 (blocks 32) = true := by decide +kernel +lemma check_33 : expression.check (-10+(33:ℚ)*(5*(1/10))) (1/10) 5 (blocks 33) = true := by decide +kernel +lemma check_34 : expression.check (-10+(34:ℚ)*(5*(1/10))) (1/10) 5 (blocks 34) = true := by decide +kernel +lemma check_35 : expression.check (-10+(35:ℚ)*(5*(1/10))) (1/10) 5 (blocks 35) = true := by decide +kernel +lemma check_36 : expression.check (-10+(36:ℚ)*(5*(1/10))) (1/10) 5 (blocks 36) = true := by decide +kernel +lemma check_37 : expression.check (-10+(37:ℚ)*(5*(1/10))) (1/10) 5 (blocks 37) = true := by decide +kernel +lemma check_38 : expression.check (-10+(38:ℚ)*(5*(1/10))) (1/10) 5 (blocks 38) = true := by decide +kernel +lemma check_39 : expression.check (-10+(39:ℚ)*(5*(1/10))) (1/10) 5 (blocks 39) = true := by decide +kernel + +lemma checks (i : ℕ) (hi : i < 40) : + expression.check (-10+(i:ℚ)*(5*(1/10))) (1/10) 5 (blocks i) = true := by + interval_cases i + · exact check_0 + · exact check_1 + · exact check_2 + · exact check_3 + · exact check_4 + · exact check_5 + · exact check_6 + · exact check_7 + · exact check_8 + · exact check_9 + · exact check_10 + · exact check_11 + · exact check_12 + · exact check_13 + · exact check_14 + · exact check_15 + · exact check_16 + · exact check_17 + · exact check_18 + · exact check_19 + · exact check_20 + · exact check_21 + · exact check_22 + · exact check_23 + · exact check_24 + · exact check_25 + · exact check_26 + · exact check_27 + · exact check_28 + · exact check_29 + · exact check_30 + · exact check_31 + · exact check_32 + · exact check_33 + · exact check_34 + · exact check_35 + · exact check_36 + · exact check_37 + · exact check_38 + · exact check_39 + +theorem integral_bound : + (∫ h, scalarFunction (1/2) (397973/500000) (524071/1000000) (119553/1000000) (702377/1000000) 7 h ∂Scalar.fieldLaw (1/2)) ∈ (⟨0,289/400⟩ : Box) := by + apply gaussian_certificate (e := expression) (B := blocks) (h := (1/10)) (k := 5) (by norm_num) + · simpa only [expression,Rat.cast_div,Rat.cast_ofNat,Rat.cast_one,Rat.cast_zero] using integrandExpr_val (1/2) (397973/500000) (524071/1000000) (119553/1000000) (702377/1000000) 7 + · exact (continuous_scalarFunction _ _ _ _ _ _).measurable + · intro x + apply scalarFunction_bound <;> norm_num + · exact checks + · decide +kernel + +end SKRatio.Certificate.Data.J4K7 + +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Certificates/ScalarDataJ4K8.lean b/lean/OAI/Probability/SKRatio/Certificates/ScalarDataJ4K8.lean new file mode 100644 index 0000000000000000000000000000000000000000..206419264cbd0a60e6a082e37e0b2e5e6134ea8f --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Certificates/ScalarDataJ4K8.lean @@ -0,0 +1,154 @@ +import Mathlib +import OAI.Probability.SKRatio.Certificates.CertifiedBatches +import OAI.Probability.SKRatio.Certificates.CertifiedFunctionBounds + +namespace OAI + +noncomputable section +open Real MeasureTheory +namespace SKRatio.Certificate.Data.J4K8 + +def expression : Expr := integrandExpr (1/2) (397973/500000) (524071/1000000) (119553/1000000) (702377/1000000) 8 +def blocks : ℕ → Box + | 0 => ⟨-1/1000000,1/1000000⟩ + | 1 => ⟨-1/1000000,1/1000000⟩ + | 2 => ⟨-1/1000000,1/1000000⟩ + | 3 => ⟨-1/1000000,1/1000000⟩ + | 4 => ⟨-1/1000000,1/1000000⟩ + | 5 => ⟨-1/1000000,1/1000000⟩ + | 6 => ⟨-1/1000000,1/1000000⟩ + | 7 => ⟨-1/1000000,1/1000000⟩ + | 8 => ⟨-1/1000000,1/1000000⟩ + | 9 => ⟨-1/1000000,1/1000000⟩ + | 10 => ⟨0,1/1000000⟩ + | 11 => ⟨7/1000000,1/125000⟩ + | 12 => ⟨29/500000,3/50000⟩ + | 13 => ⟨389/1000000,49/125000⟩ + | 14 => ⟨2153/1000000,541/250000⟩ + | 15 => ⟨9853/1000000,309/31250⟩ + | 16 => ⟨29/800,18163/500000⟩ + | 17 => ⟨20263/200000,25349/250000⟩ + | 18 => ⟨19983/100000,199907/1000000⟩ + | 19 => ⟨262289/1000000,3281/12500⟩ + | 20 => ⟨227819/1000000,113967/500000⟩ + | 21 => ⟨68903/500000,13787/100000⟩ + | 22 => ⟨1563/25000,62609/1000000⟩ + | 23 => ⟨4523/200000,1417/62500⟩ + | 24 => ⟨6737/1000000,6763/1000000⟩ + | 25 => ⟨333/200000,67/40000⟩ + | 26 => ⟨339/1000000,343/1000000⟩ + | 27 => ⟨7/125000,29/500000⟩ + | 28 => ⟨7/1000000,1/125000⟩ + | 29 => ⟨0,1/500000⟩ + | 30 => ⟨-1/1000000,1/1000000⟩ + | 31 => ⟨-1/1000000,1/1000000⟩ + | 32 => ⟨-1/1000000,1/1000000⟩ + | 33 => ⟨-1/1000000,1/1000000⟩ + | 34 => ⟨-1/1000000,1/1000000⟩ + | 35 => ⟨-1/1000000,1/1000000⟩ + | 36 => ⟨-1/1000000,1/1000000⟩ + | 37 => ⟨-1/1000000,1/1000000⟩ + | 38 => ⟨-1/1000000,1/1000000⟩ + | 39 => ⟨-1/1000000,1/1000000⟩ + | _ => Box.rat 0 + +lemma check_0 : expression.check (-10+(0:ℚ)*(10*(1/20))) (1/20) 10 (blocks 0) = true := by decide +kernel +lemma check_1 : expression.check (-10+(1:ℚ)*(10*(1/20))) (1/20) 10 (blocks 1) = true := by decide +kernel +lemma check_2 : expression.check (-10+(2:ℚ)*(10*(1/20))) (1/20) 10 (blocks 2) = true := by decide +kernel +lemma check_3 : expression.check (-10+(3:ℚ)*(10*(1/20))) (1/20) 10 (blocks 3) = true := by decide +kernel +lemma check_4 : expression.check (-10+(4:ℚ)*(10*(1/20))) (1/20) 10 (blocks 4) = true := by decide +kernel +lemma check_5 : expression.check (-10+(5:ℚ)*(10*(1/20))) (1/20) 10 (blocks 5) = true := by decide +kernel +lemma check_6 : expression.check (-10+(6:ℚ)*(10*(1/20))) (1/20) 10 (blocks 6) = true := by decide +kernel +lemma check_7 : expression.check (-10+(7:ℚ)*(10*(1/20))) (1/20) 10 (blocks 7) = true := by decide +kernel +lemma check_8 : expression.check (-10+(8:ℚ)*(10*(1/20))) (1/20) 10 (blocks 8) = true := by decide +kernel +lemma check_9 : expression.check (-10+(9:ℚ)*(10*(1/20))) (1/20) 10 (blocks 9) = true := by decide +kernel +lemma check_10 : expression.check (-10+(10:ℚ)*(10*(1/20))) (1/20) 10 (blocks 10) = true := by decide +kernel +lemma check_11 : expression.check (-10+(11:ℚ)*(10*(1/20))) (1/20) 10 (blocks 11) = true := by decide +kernel +lemma check_12 : expression.check (-10+(12:ℚ)*(10*(1/20))) (1/20) 10 (blocks 12) = true := by decide +kernel +lemma check_13 : expression.check (-10+(13:ℚ)*(10*(1/20))) (1/20) 10 (blocks 13) = true := by decide +kernel +lemma check_14 : expression.check (-10+(14:ℚ)*(10*(1/20))) (1/20) 10 (blocks 14) = true := by decide +kernel +lemma check_15 : expression.check (-10+(15:ℚ)*(10*(1/20))) (1/20) 10 (blocks 15) = true := by decide +kernel +lemma check_16 : expression.check (-10+(16:ℚ)*(10*(1/20))) (1/20) 10 (blocks 16) = true := by decide +kernel +lemma check_17 : expression.check (-10+(17:ℚ)*(10*(1/20))) (1/20) 10 (blocks 17) = true := by decide +kernel +lemma check_18 : expression.check (-10+(18:ℚ)*(10*(1/20))) (1/20) 10 (blocks 18) = true := by decide +kernel +lemma check_19 : expression.check (-10+(19:ℚ)*(10*(1/20))) (1/20) 10 (blocks 19) = true := by decide +kernel +lemma check_20 : expression.check (-10+(20:ℚ)*(10*(1/20))) (1/20) 10 (blocks 20) = true := by decide +kernel +lemma check_21 : expression.check (-10+(21:ℚ)*(10*(1/20))) (1/20) 10 (blocks 21) = true := by decide +kernel +lemma check_22 : expression.check (-10+(22:ℚ)*(10*(1/20))) (1/20) 10 (blocks 22) = true := by decide +kernel +lemma check_23 : expression.check (-10+(23:ℚ)*(10*(1/20))) (1/20) 10 (blocks 23) = true := by decide +kernel +lemma check_24 : expression.check (-10+(24:ℚ)*(10*(1/20))) (1/20) 10 (blocks 24) = true := by decide +kernel +lemma check_25 : expression.check (-10+(25:ℚ)*(10*(1/20))) (1/20) 10 (blocks 25) = true := by decide +kernel +lemma check_26 : expression.check (-10+(26:ℚ)*(10*(1/20))) (1/20) 10 (blocks 26) = true := by decide +kernel +lemma check_27 : expression.check (-10+(27:ℚ)*(10*(1/20))) (1/20) 10 (blocks 27) = true := by decide +kernel +lemma check_28 : expression.check (-10+(28:ℚ)*(10*(1/20))) (1/20) 10 (blocks 28) = true := by decide +kernel +lemma check_29 : expression.check (-10+(29:ℚ)*(10*(1/20))) (1/20) 10 (blocks 29) = true := by decide +kernel +lemma check_30 : expression.check (-10+(30:ℚ)*(10*(1/20))) (1/20) 10 (blocks 30) = true := by decide +kernel +lemma check_31 : expression.check (-10+(31:ℚ)*(10*(1/20))) (1/20) 10 (blocks 31) = true := by decide +kernel +lemma check_32 : expression.check (-10+(32:ℚ)*(10*(1/20))) (1/20) 10 (blocks 32) = true := by decide +kernel +lemma check_33 : expression.check (-10+(33:ℚ)*(10*(1/20))) (1/20) 10 (blocks 33) = true := by decide +kernel +lemma check_34 : expression.check (-10+(34:ℚ)*(10*(1/20))) (1/20) 10 (blocks 34) = true := by decide +kernel +lemma check_35 : expression.check (-10+(35:ℚ)*(10*(1/20))) (1/20) 10 (blocks 35) = true := by decide +kernel +lemma check_36 : expression.check (-10+(36:ℚ)*(10*(1/20))) (1/20) 10 (blocks 36) = true := by decide +kernel +lemma check_37 : expression.check (-10+(37:ℚ)*(10*(1/20))) (1/20) 10 (blocks 37) = true := by decide +kernel +lemma check_38 : expression.check (-10+(38:ℚ)*(10*(1/20))) (1/20) 10 (blocks 38) = true := by decide +kernel +lemma check_39 : expression.check (-10+(39:ℚ)*(10*(1/20))) (1/20) 10 (blocks 39) = true := by decide +kernel + +lemma checks (i : ℕ) (hi : i < 40) : + expression.check (-10+(i:ℚ)*(10*(1/20))) (1/20) 10 (blocks i) = true := by + interval_cases i + · exact check_0 + · exact check_1 + · exact check_2 + · exact check_3 + · exact check_4 + · exact check_5 + · exact check_6 + · exact check_7 + · exact check_8 + · exact check_9 + · exact check_10 + · exact check_11 + · exact check_12 + · exact check_13 + · exact check_14 + · exact check_15 + · exact check_16 + · exact check_17 + · exact check_18 + · exact check_19 + · exact check_20 + · exact check_21 + · exact check_22 + · exact check_23 + · exact check_24 + · exact check_25 + · exact check_26 + · exact check_27 + · exact check_28 + · exact check_29 + · exact check_30 + · exact check_31 + · exact check_32 + · exact check_33 + · exact check_34 + · exact check_35 + · exact check_36 + · exact check_37 + · exact check_38 + · exact check_39 + +theorem integral_bound : + (∫ h, scalarFunction (1/2) (397973/500000) (524071/1000000) (119553/1000000) (702377/1000000) 8 h ∂Scalar.fieldLaw (1/2)) ∈ (⟨0,107/250⟩ : Box) := by + apply gaussian_certificate (e := expression) (B := blocks) (h := (1/20)) (k := 10) (by norm_num) + · simpa only [expression,Rat.cast_div,Rat.cast_ofNat,Rat.cast_one,Rat.cast_zero] using integrandExpr_val (1/2) (397973/500000) (524071/1000000) (119553/1000000) (702377/1000000) 8 + · exact (continuous_scalarFunction _ _ _ _ _ _).measurable + · intro x + apply scalarFunction_bound <;> norm_num + · exact checks + · decide +kernel + +end SKRatio.Certificate.Data.J4K8 + +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Certificates/ScalarDataJ4K9.lean b/lean/OAI/Probability/SKRatio/Certificates/ScalarDataJ4K9.lean new file mode 100644 index 0000000000000000000000000000000000000000..e499b29e93b359ac2645874e3b75761d9b596fcc --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Certificates/ScalarDataJ4K9.lean @@ -0,0 +1,154 @@ +import Mathlib +import OAI.Probability.SKRatio.Certificates.CertifiedBatches +import OAI.Probability.SKRatio.Certificates.CertifiedFunctionBounds + +namespace OAI + +noncomputable section +open Real MeasureTheory +namespace SKRatio.Certificate.Data.J4K9 + +def expression : Expr := integrandExpr (1/2) (397973/500000) (524071/1000000) (119553/1000000) (702377/1000000) 9 +def blocks : ℕ → Box + | 0 => ⟨-1/1000000,1/1000000⟩ + | 1 => ⟨-1/1000000,1/1000000⟩ + | 2 => ⟨-1/1000000,1/1000000⟩ + | 3 => ⟨-1/1000000,1/1000000⟩ + | 4 => ⟨-1/1000000,1/1000000⟩ + | 5 => ⟨-1/1000000,1/1000000⟩ + | 6 => ⟨-1/1000000,1/1000000⟩ + | 7 => ⟨-1/1000000,1/1000000⟩ + | 8 => ⟨-1/1000000,1/1000000⟩ + | 9 => ⟨-1/1000000,1/1000000⟩ + | 10 => ⟨-1/1000000,1/1000000⟩ + | 11 => ⟨-1/1000000,1/1000000⟩ + | 12 => ⟨0,1/500000⟩ + | 13 => ⟨7/500000,1/62500⟩ + | 14 => ⟨77/500000,39/250000⟩ + | 15 => ⟨1171/1000000,1179/1000000⟩ + | 16 => ⟨1/160,98/15625⟩ + | 17 => ⟨4437/200000,22213/1000000⟩ + | 18 => ⟨49053/1000000,1227/25000⟩ + | 19 => ⟨64197/1000000,64259/1000000⟩ + | 20 => ⟨24739/500000,49507/1000000⟩ + | 21 => ⟨2931/125000,587/25000⟩ + | 22 => ⟨7299/1000000,3663/500000⟩ + | 23 => ⟨1583/1000000,399/250000⟩ + | 24 => ⟨249/1000000,127/500000⟩ + | 25 => ⟨29/1000000,31/1000000⟩ + | 26 => ⟨1/500000,3/1000000⟩ + | 27 => ⟨-1/1000000,1/1000000⟩ + | 28 => ⟨-1/1000000,1/1000000⟩ + | 29 => ⟨-1/1000000,1/1000000⟩ + | 30 => ⟨-1/1000000,1/1000000⟩ + | 31 => ⟨-1/1000000,1/1000000⟩ + | 32 => ⟨-1/1000000,1/1000000⟩ + | 33 => ⟨-1/1000000,1/1000000⟩ + | 34 => ⟨-1/1000000,1/1000000⟩ + | 35 => ⟨-1/1000000,1/1000000⟩ + | 36 => ⟨-1/1000000,1/1000000⟩ + | 37 => ⟨-1/1000000,1/1000000⟩ + | 38 => ⟨-1/1000000,1/1000000⟩ + | 39 => ⟨-1/1000000,1/1000000⟩ + | _ => Box.rat 0 + +lemma check_0 : expression.check (-10+(0:ℚ)*(10*(1/20))) (1/20) 10 (blocks 0) = true := by decide +kernel +lemma check_1 : expression.check (-10+(1:ℚ)*(10*(1/20))) (1/20) 10 (blocks 1) = true := by decide +kernel +lemma check_2 : expression.check (-10+(2:ℚ)*(10*(1/20))) (1/20) 10 (blocks 2) = true := by decide +kernel +lemma check_3 : expression.check (-10+(3:ℚ)*(10*(1/20))) (1/20) 10 (blocks 3) = true := by decide +kernel +lemma check_4 : expression.check (-10+(4:ℚ)*(10*(1/20))) (1/20) 10 (blocks 4) = true := by decide +kernel +lemma check_5 : expression.check (-10+(5:ℚ)*(10*(1/20))) (1/20) 10 (blocks 5) = true := by decide +kernel +lemma check_6 : expression.check (-10+(6:ℚ)*(10*(1/20))) (1/20) 10 (blocks 6) = true := by decide +kernel +lemma check_7 : expression.check (-10+(7:ℚ)*(10*(1/20))) (1/20) 10 (blocks 7) = true := by decide +kernel +lemma check_8 : expression.check (-10+(8:ℚ)*(10*(1/20))) (1/20) 10 (blocks 8) = true := by decide +kernel +lemma check_9 : expression.check (-10+(9:ℚ)*(10*(1/20))) (1/20) 10 (blocks 9) = true := by decide +kernel +lemma check_10 : expression.check (-10+(10:ℚ)*(10*(1/20))) (1/20) 10 (blocks 10) = true := by decide +kernel +lemma check_11 : expression.check (-10+(11:ℚ)*(10*(1/20))) (1/20) 10 (blocks 11) = true := by decide +kernel +lemma check_12 : expression.check (-10+(12:ℚ)*(10*(1/20))) (1/20) 10 (blocks 12) = true := by decide +kernel +lemma check_13 : expression.check (-10+(13:ℚ)*(10*(1/20))) (1/20) 10 (blocks 13) = true := by decide +kernel +lemma check_14 : expression.check (-10+(14:ℚ)*(10*(1/20))) (1/20) 10 (blocks 14) = true := by decide +kernel +lemma check_15 : expression.check (-10+(15:ℚ)*(10*(1/20))) (1/20) 10 (blocks 15) = true := by decide +kernel +lemma check_16 : expression.check (-10+(16:ℚ)*(10*(1/20))) (1/20) 10 (blocks 16) = true := by decide +kernel +lemma check_17 : expression.check (-10+(17:ℚ)*(10*(1/20))) (1/20) 10 (blocks 17) = true := by decide +kernel +lemma check_18 : expression.check (-10+(18:ℚ)*(10*(1/20))) (1/20) 10 (blocks 18) = true := by decide +kernel +lemma check_19 : expression.check (-10+(19:ℚ)*(10*(1/20))) (1/20) 10 (blocks 19) = true := by decide +kernel +lemma check_20 : expression.check (-10+(20:ℚ)*(10*(1/20))) (1/20) 10 (blocks 20) = true := by decide +kernel +lemma check_21 : expression.check (-10+(21:ℚ)*(10*(1/20))) (1/20) 10 (blocks 21) = true := by decide +kernel +lemma check_22 : expression.check (-10+(22:ℚ)*(10*(1/20))) (1/20) 10 (blocks 22) = true := by decide +kernel +lemma check_23 : expression.check (-10+(23:ℚ)*(10*(1/20))) (1/20) 10 (blocks 23) = true := by decide +kernel +lemma check_24 : expression.check (-10+(24:ℚ)*(10*(1/20))) (1/20) 10 (blocks 24) = true := by decide +kernel +lemma check_25 : expression.check (-10+(25:ℚ)*(10*(1/20))) (1/20) 10 (blocks 25) = true := by decide +kernel +lemma check_26 : expression.check (-10+(26:ℚ)*(10*(1/20))) (1/20) 10 (blocks 26) = true := by decide +kernel +lemma check_27 : expression.check (-10+(27:ℚ)*(10*(1/20))) (1/20) 10 (blocks 27) = true := by decide +kernel +lemma check_28 : expression.check (-10+(28:ℚ)*(10*(1/20))) (1/20) 10 (blocks 28) = true := by decide +kernel +lemma check_29 : expression.check (-10+(29:ℚ)*(10*(1/20))) (1/20) 10 (blocks 29) = true := by decide +kernel +lemma check_30 : expression.check (-10+(30:ℚ)*(10*(1/20))) (1/20) 10 (blocks 30) = true := by decide +kernel +lemma check_31 : expression.check (-10+(31:ℚ)*(10*(1/20))) (1/20) 10 (blocks 31) = true := by decide +kernel +lemma check_32 : expression.check (-10+(32:ℚ)*(10*(1/20))) (1/20) 10 (blocks 32) = true := by decide +kernel +lemma check_33 : expression.check (-10+(33:ℚ)*(10*(1/20))) (1/20) 10 (blocks 33) = true := by decide +kernel +lemma check_34 : expression.check (-10+(34:ℚ)*(10*(1/20))) (1/20) 10 (blocks 34) = true := by decide +kernel +lemma check_35 : expression.check (-10+(35:ℚ)*(10*(1/20))) (1/20) 10 (blocks 35) = true := by decide +kernel +lemma check_36 : expression.check (-10+(36:ℚ)*(10*(1/20))) (1/20) 10 (blocks 36) = true := by decide +kernel +lemma check_37 : expression.check (-10+(37:ℚ)*(10*(1/20))) (1/20) 10 (blocks 37) = true := by decide +kernel +lemma check_38 : expression.check (-10+(38:ℚ)*(10*(1/20))) (1/20) 10 (blocks 38) = true := by decide +kernel +lemma check_39 : expression.check (-10+(39:ℚ)*(10*(1/20))) (1/20) 10 (blocks 39) = true := by decide +kernel + +lemma checks (i : ℕ) (hi : i < 40) : + expression.check (-10+(i:ℚ)*(10*(1/20))) (1/20) 10 (blocks i) = true := by + interval_cases i + · exact check_0 + · exact check_1 + · exact check_2 + · exact check_3 + · exact check_4 + · exact check_5 + · exact check_6 + · exact check_7 + · exact check_8 + · exact check_9 + · exact check_10 + · exact check_11 + · exact check_12 + · exact check_13 + · exact check_14 + · exact check_15 + · exact check_16 + · exact check_17 + · exact check_18 + · exact check_19 + · exact check_20 + · exact check_21 + · exact check_22 + · exact check_23 + · exact check_24 + · exact check_25 + · exact check_26 + · exact check_27 + · exact check_28 + · exact check_29 + · exact check_30 + · exact check_31 + · exact check_32 + · exact check_33 + · exact check_34 + · exact check_35 + · exact check_36 + · exact check_37 + · exact check_38 + · exact check_39 + +theorem integral_bound : + (∫ h, scalarFunction (1/2) (397973/500000) (524071/1000000) (119553/1000000) (702377/1000000) 9 h ∂Scalar.fieldLaw (1/2)) ∈ (⟨0,451/5000⟩ : Box) := by + apply gaussian_certificate (e := expression) (B := blocks) (h := (1/20)) (k := 10) (by norm_num) + · simpa only [expression,Rat.cast_div,Rat.cast_ofNat,Rat.cast_one,Rat.cast_zero] using integrandExpr_val (1/2) (397973/500000) (524071/1000000) (119553/1000000) (702377/1000000) 9 + · exact (continuous_scalarFunction _ _ _ _ _ _).measurable + · intro x + apply scalarFunction_bound <;> norm_num + · exact checks + · decide +kernel + +end SKRatio.Certificate.Data.J4K9 + +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Dynamics/Assembly.lean b/lean/OAI/Probability/SKRatio/Dynamics/Assembly.lean new file mode 100644 index 0000000000000000000000000000000000000000..8a441c87632a44bc5dddc0607b7214fd16bbd362 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Dynamics/Assembly.lean @@ -0,0 +1,104 @@ +import Mathlib +import OAI.Probability.SKRatio.FiniteChain.RatioProbabilityUniformBounds +import OAI.Probability.SKRatio.Dynamics.ClockLower +import OAI.Probability.SKRatio.Dynamics.ClockTransfer + +namespace OAI + +section +noncomputable section +open scoped BigOperators Topology Matrix +open MeasureTheory Filter +namespace SKRatio.Calculus + +lemma uniform_holding_of_norm + (G : ∀ n : ℕ, Set (Disorder n)) {K : ℝ} (hK : 0 < K) + (hnorm : ∀ n, ∀ g ∈ G n, + ‖Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) (coupling g)‖ ≤ K) : + ∃ q : ℝ, 0 < q ∧ q < 1 ∧ + ∀ n, 0 < n → ∀ g ∈ G n, ∀ x, 1-q ≤ transition g x x := by + let a : ℝ := 1/(2*(1+Real.exp (2*(Real.sqrt 2*K)))) + have ha : 0 < a := by dsimp [a]; positivity + have ha1 : a < 1 := by + apply (div_lt_one (by positivity)).mpr + linarith [Real.exp_pos (2*(Real.sqrt 2*K))] + refine ⟨1-a,by linarith,by linarith,?_⟩ + intro n hn g hg x + have h := attempted_holding_lower hn (coupling g) hK (hnorm n g hg) x + rw [attemptKernel_eq_transition] at h + simpa only [sub_sub_cancel] using h + +theorem uniform_discrete_cutoff_of_positive_lag + (G : ∀ n : ℕ, Set (Disorder n)) {c C K : ℝ} (hc : 0 < c) (hK : 0 < K) + (hnorm : ∀ n, ∀ g ∈ G n, + ‖Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) (coupling g)‖ ≤ K) + (hscale : ∀ᶠ n : ℕ in atTop, ∀ g ∈ G n, + c*Real.log n ≤ medianTime g ∧ medianTime g ≤ C*Real.log n) + (hlag : ∀ ε α D δ : ℝ, 0 < ε → 0 < α → 0 < δ → + ∀ᶠ n : ℕ in atTop, ∀ g ∈ G n, ∀ t : ℝ, + 0 ≤ t → t+α*Real.log n ≤ D*Real.log n → + continuousDistance g t ≤ 1-ε → continuousDistance g (t+α*Real.log n) ≤ δ) + {b δ : ℝ} (hb : 0 < b) (hb1 : b < 1) (hδ : 0 < δ) : + ∀ᶠ n : ℕ in atTop, ∀ g ∈ G n, + 1-δ < discreteDistance g ⌊(1-b)*(n:ℝ)*medianTime g⌋₊ ∧ + discreteDistance g ⌈(1+b)*(n:ℝ)*medianTime g⌉₊ ≤ δ := by + have hdiv := median_attempts_diverge_of_log_lower G hc + (hscale.mono (fun _ hn g hg => (hn g hg).1)) + have hb2 : 0 < b/2 := by positivity + have hb21 : b/2 < 1 := by linarith + have hcont (e : ℝ) (he : 0 < e) := + uniform_continuous_cutoff_of_positive_lag G hc hscale hlag hb2 hb21 he + obtain ⟨q,hq,hq1,hhold⟩ := uniform_holding_of_norm G hK hnorm + have hup := uniform_discrete_upper_of_holding G hb hq hq1 hdiv hhold + (fun e he => (hcont e he).mono (fun _ hn g hg => (hn g hg).2)) δ hδ + have hlo := uniform_discrete_lower_from_continuous G hb hb1 hdiv + (fun e he => (hcont e he).mono (fun _ hn g hg => (hn g hg).1)) δ hδ + filter_upwards [hlo,hup] with n hnlo hnup + intro g hg + exact ⟨hnlo g hg,hnup g hg⟩ + +theorem ratio_cutoff_of_positive_lag (β ε η : ℝ) + (hε : 0 < ε) (hε1 : ε < 1) (hη : 0 < η) + (G : ∀ n : ℕ, Set (Disorder n)) {c C K : ℝ} (hc : 0 < c) (hK : 0 < K) + (hnorm : ∀ n, ∀ g ∈ G n, + ‖Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) (coupling g)‖ ≤ K) + (hG : Tendsto (fun n => disorderLaw β n (G n)ᶜ) atTop (𝓝 0)) + (hscale : ∀ᶠ n : ℕ in atTop, ∀ g ∈ G n, + c*Real.log n ≤ medianTime g ∧ medianTime g ≤ C*Real.log n) + (hlag : ∀ ε α D δ : ℝ, 0 < ε → 0 < α → 0 < δ → + ∀ᶠ n : ℕ in atTop, ∀ g ∈ G n, ∀ t : ℝ, + 0 ≤ t → t+α*Real.log n ≤ D*Real.log n → + continuousDistance g t ≤ 1-ε → continuousDistance g (t+α*Real.log n) ≤ δ) : + Tendsto + (fun n : ℕ => disorderLaw β n + {g : Disorder n | 1+η < + (mixingTime g ε : ℝ)/(mixingTime g (1-ε) : ℝ)}) + atTop (𝓝 0) ∧ + (∀ᶠ n : ℕ in atTop, ∀ g : Disorder n, 0 < mixingTime g (1-ε)) := by + refine ⟨?_,denominator_eventually_positive ε hε hε1⟩ + let b : ℝ := η/(2*(2+η)) + have hden : 0 < 2*(2+η) := by positivity + have hb : 0 < b := div_pos hη hden + have hb1 : b < 1 := (div_lt_one hden).mpr (by linarith) + have hbid : b*(2+η) = η/2 := by dsimp only [b]; field_simp + have hbase : (1+b)/(1-b) < 1+η := by + apply (div_lt_iff₀ (sub_pos.mpr hb1)).mpr + nlinarith only [hbid,hη] + have hdiv := median_attempts_diverge_of_log_lower G hc + (hscale.mono (fun _ hn g hg => (hn g hg).1)) + have hd := uniform_discrete_cutoff_of_positive_lag G hc hK hnorm hscale hlag hb hb1 hε + apply ratio_probability_zero_of_uniform_bounds (disorderLaw β) G + (fun n g => (n:ℝ)*medianTime g) hε hε1 hb hb1 hbase hG hdiv + · filter_upwards [hd] with n hn + intro g hg + simpa only [mul_assoc] using (hn g hg).1 + · filter_upwards [hd] with n hn + intro g hg + simpa only [mul_assoc] using (hn g hg).2 + +end SKRatio.Calculus + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Dynamics/ClockBridge.lean b/lean/OAI/Probability/SKRatio/Dynamics/ClockBridge.lean new file mode 100644 index 0000000000000000000000000000000000000000..aa1446e045a136d5061cb5ba190b3a659cd2e78c --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Dynamics/ClockBridge.lean @@ -0,0 +1,336 @@ +import Mathlib +import OAI.Probability.SKRatio.Calculus.GibbsMeanCLM +import OAI.Probability.SKRatio.Dynamics.SumPoissonMass + +namespace OAI + +section +noncomputable section +open scoped BigOperators Topology Matrix +open ContinuousLinearMap MeasureTheory Filter ProbabilityTheory SKRatioClock +namespace SKRatio.Calculus + +lemma kernel_apply {n : ℕ} (K : Observables n →L[ℝ] Observables n) + (f : Observables n) (x : Spin n) : + (∑ y, K (fun z => if z = y then 1 else 0) x*f y) = K f x := by + conv_rhs => rw [observable_basis f] + simp only [map_sum, map_smul, Finset.sum_apply, Pi.smul_apply, smul_eq_mul] + exact Finset.sum_congr rfl (fun _ _ => mul_comm _ _) + +def attemptKernel {n : ℕ} (J : Interaction n) : Matrix (Spin n) (Spin n) ℝ := + fun x y => attemptLM J (fun z => if z = y then 1 else 0) x + +lemma attemptKernel_nonneg {n : ℕ} (J : Interaction n) (x y : Spin n) : + 0 ≤ attemptKernel J x y := by + classical + exact attempt_nonneg J _ (fun z => by split_ifs <;> norm_num) x + +lemma attemptKernel_eq_transition {n : ℕ} (g : Disorder n) : + attemptKernel (coupling g) = transition g := by + classical + funext x y + simp [attemptKernel, attempt_eq_transition, Matrix.mulVec, dotProduct] + +noncomputable def residualAttempt {n : ℕ} (J : Interaction n) (q : ℝ) : + Observables n →L[ℝ] Observables n := + q⁻¹ • (attemptLM J-(1-q) • 1) + +lemma residualAttempt_apply {n : ℕ} (J : Interaction n) (q : ℝ) + (f : Observables n) (x : Spin n) : + residualAttempt J q f x = (attemptLM J f x-(1-q)*f x)/q := by + simp [residualAttempt,div_eq_mul_inv,mul_comm] + +lemma attempt_eq_lazy_residual {n : ℕ} (J : Interaction n) {q : ℝ} (hq : q ≠ 0) : + attemptLM J = q • residualAttempt J q+(1-q) • 1 := by + simp only [residualAttempt,smul_smul,mul_inv_cancel₀ hq,one_smul,sub_add_cancel] + +lemma residualAttempt_const {n : ℕ} (J : Interaction n) {q : ℝ} (hq : q ≠ 0) + (c : ℝ) : residualAttempt J q (fun _ => c) = fun _ => c := by + ext x + rw [residualAttempt_apply,attempt_const] + field_simp + ring + +lemma residualAttempt_pow_const {n : ℕ} (J : Interaction n) {q : ℝ} (hq : q ≠ 0) + (k : ℕ) (c : ℝ) : (residualAttempt J q ^ k) (fun _ => c) = fun _ => c := by + induction k with + | zero => simp + | succ k ih => rw [pow_succ',mul_apply_eq_comp,ih,residualAttempt_const J hq] + +lemma residualAttempt_nonneg {n : ℕ} (J : Interaction n) {q : ℝ} (hq : 0 < q) + (hhold : ∀ x, 1-q ≤ attemptKernel J x x) + (f : Observables n) (hf : ∀ x, 0 ≤ f x) (x : Spin n) : + 0 ≤ residualAttempt J q f x := by + rw [← kernel_apply (residualAttempt J q) f x] + apply Finset.sum_nonneg + intro y _ + apply mul_nonneg _ (hf y) + rw [residualAttempt_apply] + apply div_nonneg _ hq.le + by_cases hxy : x=y + · subst y + simpa [attemptKernel] using sub_nonneg.mpr (hhold x) + · simpa only [hxy,↓reduceIte,mul_zero,sub_zero,attemptKernel] using + attemptKernel_nonneg J x y + +lemma residualAttempt_pow_nonneg {n : ℕ} (J : Interaction n) {q : ℝ} (hq : 0 < q) + (hhold : ∀ x, 1-q ≤ attemptKernel J x x) + (k : ℕ) (f : Observables n) (hf : ∀ x, 0 ≤ f x) (x : Spin n) : + 0 ≤ (residualAttempt J q ^ k) f x := by + induction k generalizing x with + | zero => exact hf x + | succ k ih => + rw [pow_succ',mul_apply_eq_comp] + exact residualAttempt_nonneg J hq hhold _ (fun x => ih x) x + +lemma residualAttempt_pow_abs_le {n : ℕ} (J : Interaction n) {q : ℝ} (hq : 0 < q) + (hhold : ∀ x, 1-q ≤ attemptKernel J x x) + (k : ℕ) (f : Observables n) (hf : ∀ x, |f x| ≤ 1) (x : Spin n) : + |(residualAttempt J q ^ k) f x| ≤ 1 := by + have hup := residualAttempt_pow_nonneg J hq hhold k (fun y => 1-f y) + (fun y => by have := (abs_le.mp (hf y)).2; linarith) x + have hlo := residualAttempt_pow_nonneg J hq hhold k (fun y => f y+1) + (fun y => by have := (abs_le.mp (hf y)).1; linarith) x + change 0 ≤ (residualAttempt J q ^ k) ((fun _ => 1)-f) x at hup + change 0 ≤ (residualAttempt J q ^ k) (f+(fun _ => 1)) x at hlo + rw [map_sub,residualAttempt_pow_const J hq.ne'] at hup + rw [map_add,residualAttempt_pow_const J hq.ne'] at hlo + simp only [Pi.add_apply,Pi.sub_apply] at hlo hup + exact abs_le.mpr ⟨by linarith,by linarith⟩ + +lemma residual_semigroup_uniformization {n : ℕ} (hn : 0 < n) + (J : Interaction n) {q : ℝ} (hq : q ≠ 0) (t : ℝ) : + semigroup J t = Real.exp (-(q*n*t)) • + NormedSpace.exp ((q*n*t) • residualAttempt J q) := by + have hn' : (n : ℝ) ≠ 0 := by exact_mod_cast hn.ne' + have heq : t • generatorCLM J = + (-(q*n*t)) • (1 : Observables n →L[ℝ] Observables n) + + (q*n*t) • residualAttempt J q := by + unfold residualAttempt attemptLM + simp only [smul_smul,smul_sub,smul_add] + have hc : q*n*t*q⁻¹ = (n:ℝ)*t := by field_simp + have hc' : q*n*t*(q⁻¹*(n:ℝ)⁻¹) = t := by field_simp + have hc'' : q*n*t*(q⁻¹*(1-q)) = (n:ℝ)*t*(1-q) := by field_simp + rw [hc,hc',hc''] + module + let : NormedAlgebra ℚ (Observables n →L[ℝ] Observables n) := + NormedAlgebra.restrictScalars ℚ ℝ _ + unfold semigroup + rw [heq,NormedSpace.exp_add_of_commute + (((Commute.one_left (residualAttempt J q)).smul_left _).smul_right _), + exp_smul_identity,smul_mul_assoc,one_mul] + +lemma residual_poisson_hasSum {n : ℕ} (hn : 0 < n) + (J : Interaction n) {q : ℝ} (hq : q ≠ 0) (t : ℝ) + (f : Observables n) (x : Spin n) : + HasSum (fun j => Clock.poissonMass (q*n*t) j*(residualAttempt J q ^ j) f x) + (semigroup J t f x) := by + have hs := (Pi.hasSum.mp (exp_apply_hasSum ((q*n*t) • residualAttempt J q) f) x).mul_left + (Real.exp (-(q*n*t))) + convert! hs using 1 + · funext j + simp only [smul_pow,_root_.smul_apply,Pi.smul_apply,smul_eq_mul,Clock.poissonMass] + ring + · rw [residual_semigroup_uniformization hn J hq] + rfl + +lemma natCastCLM_apply {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] + (k : ℕ) (f : E) : (k : E →L[ℝ] E) f = (k:ℝ) • f := by + induction k with + | zero => simp + | succ k ih => simp [Nat.cast_succ,ih,add_smul] + +lemma residual_binomial_sum {n : ℕ} (J : Interaction n) {q : ℝ} (hq : q ≠ 0) + (M : ℕ) (f : Observables n) (x : Spin n) : + (∑ j ∈ Finset.range (M+1), Clock.binomialMass q M j* + (residualAttempt J q ^ j) f x) = (attemptLM J ^ M) f x := by + rw [attempt_eq_lazy_residual J hq] + rw [(((Commute.one_right (residualAttempt J q)).smul_left q).smul_right (1-q)).add_pow] + simp only [_root_.sum_apply,smul_pow,one_pow,smul_mul_assoc,mul_smul_comm,mul_one, + Clock.binomialMass,mul_apply_eq_comp,_root_.smul_apply,Finset.sum_apply,Pi.smul_apply,smul_eq_mul] + apply Finset.sum_congr rfl + intro j _ + simp only [natCastCLM_apply,map_smul,Pi.smul_apply,smul_eq_mul] + ring + +lemma residual_binomial_hasSum {n : ℕ} (J : Interaction n) {q : ℝ} (hq : q ≠ 0) + (M : ℕ) (f : Observables n) (x : Spin n) : + HasSum (fun j => Clock.binomialMass q M j*(residualAttempt J q ^ j) f x) + ((attemptLM J ^ M) f x) := by + rw [← residual_binomial_sum J hq M f x] + apply hasSum_sum_of_ne_finset_zero + intro j hj + have hj' : M < j := by simp only [Finset.mem_range,not_lt] at hj; omega + simp [Clock.binomialMass,Nat.choose_eq_zero_of_lt hj'] + +lemma gibbsMean_abs_le_one {n : ℕ} (g : Disorder n) (f : Observables n) + (hf : ∀ x, |f x| ≤ 1) : |FiniteLaw.mean (mass g 0) f| ≤ 1 := by + unfold FiniteLaw.mean + calc + _ ≤ ∑ x, |mass g 0 x*f x| := Finset.abs_sum_le_sum_abs _ _ + _ ≤ ∑ x, mass g 0 x := by + apply Finset.sum_le_sum + intro x _ + rw [abs_mul,abs_of_nonneg (mass_nonneg g 0 x)] + exact mul_le_of_le_one_right (mass_nonneg g 0 x) (hf x) + _ = _ := sum_mass g 0 + +lemma residual_test_bound {n : ℕ} (g : Disorder n) {q : ℝ} (hq : 0 < q) + (hhold : ∀ x, 1-q ≤ transition g x x) + (f : Observables n) (hf : ∀ x, |f x| ≤ 1) (x : Spin n) (j : ℕ) : + |(residualAttempt (coupling g) q ^ j) f x-FiniteLaw.mean (mass g 0) f| ≤ 2 := by + have h := abs_sub ((residualAttempt (coupling g) q ^ j) f x) + (FiniteLaw.mean (mass g 0) f) + have hhold' : ∀ x, 1-q ≤ attemptKernel (coupling g) x x := by + rwa [attemptKernel_eq_transition] + linarith [residualAttempt_pow_abs_le (coupling g) hq hhold' j f hf x, + gibbsMean_abs_le_one g f hf] + +lemma residual_poisson_test {n : ℕ} (hn : 0 < n) + (g : Disorder n) {q : ℝ} (hq : q ≠ 0) (m : ℝ) + (f : Observables n) (x : Spin n) : + (∑' j, Clock.poissonMass m j*((residualAttempt (coupling g) q ^ j) f x- + FiniteLaw.mean (mass g 0) f)) = + semigroup (coupling g) (m/(q*n)) f x-FiniteLaw.mean (mass g 0) f := by + have hn' : (n : ℝ) ≠ 0 := by exact_mod_cast hn.ne' + have he : q*n*(m/(q*n)) = m := by field_simp + have hs := residual_poisson_hasSum hn (coupling g) hq (m/(q*n)) f x + rw [he] at hs + have hh := hs.sub ((Clock.hasSum_poissonMass m).mul_right (FiniteLaw.mean (mass g 0) f)) + simpa only [one_mul,← mul_sub] using hh.tsum_eq + +lemma residual_binomial_test {n : ℕ} (g : Disorder n) {q : ℝ} (hq : q ≠ 0) + (M : ℕ) (f : Observables n) (x : Spin n) : + (∑' j, Clock.binomialMass q M j*((residualAttempt (coupling g) q ^ j) f x- + FiniteLaw.mean (mass g 0) f)) = + ((transition g ^ M) *ᵥ f) x-FiniteLaw.mean (mass g 0) f := by + have hs := residual_binomial_hasSum (coupling g) hq M f x + have hh := hs.sub ((Clock.hasSum_binomialMass q M).mul_right (FiniteLaw.mean (mass g 0) f)) + simpa only [one_mul,← mul_sub, attempt_pow_eq_transition_pow] using hh.tsum_eq + +lemma totalVariation_test_bound {n : ℕ} (p r f : Spin n → ℝ) + (hf : ∀ y, |f y| ≤ 1) : + |FiniteLaw.mean p f-FiniteLaw.mean r f| ≤ 2*totalVariation p r := by + unfold FiniteLaw.mean + rw [← Finset.sum_sub_distrib] + simp_rw [← sub_mul] + calc + _ ≤ ∑ y, |(p y-r y)*f y| := Finset.abs_sum_le_sum_abs _ _ + _ ≤ ∑ y, |p y-r y| := by + apply Finset.sum_le_sum + intro y _ + rw [abs_mul] + exact mul_le_of_le_one_right (abs_nonneg _) (hf y) + _ = _ := by dsimp [totalVariation]; ring + +lemma continuous_test_bound {n : ℕ} (g : Disorder n) (t : ℝ) + (f : Observables n) (hf : ∀ y, |f y| ≤ 1) (x : Spin n) : + |semigroup (coupling g) t f x-FiniteLaw.mean (mass g 0) f| ≤ + 2*continuousDistance g t := by + rw [semigroup_eq_kernel] + apply (totalVariation_test_bound (continuousKernel (coupling g) t x) (mass g 0) f hf).trans + exact mul_le_mul_of_nonneg_left (tv_le_continuousDistance g t x) (by norm_num) + +lemma field_square_sum_le {n : ℕ} (J : Interaction n) (x : Spin n) + {K : ℝ} (_hK : 0 ≤ K) + (hJ : ‖Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) J‖ ≤ K) : + ∑ i, field J x i^2 ≤ K^2*(n:ℝ) := by + let A := Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) J + let v : EuclideanSpace ℝ (Fin n) := (WithLp.equiv 2 _).symm (spin x) + have hv : ‖v‖^2 = (n:ℝ) := by + rw [EuclideanSpace.real_norm_sq_eq] + simp [v, spin_sq] + have hh : ‖A v‖ ≤ K*‖v‖ := (A.le_opNorm v).trans + (mul_le_mul_of_nonneg_right hJ (norm_nonneg _)) + have hs := pow_le_pow_left₀ (norm_nonneg _) hh 2 + rw [mul_pow, hv, EuclideanSpace.real_norm_sq_eq] at hs + exact hs + +lemma one_sub_tanh_half (a : ℝ) : + (1-Real.tanh a)/2 = 1/(1+Real.exp (2*a)) := by + have hh := exp_two_mul_one_sub_tanh a + have he := Real.exp_pos (2*a) + apply (eq_div_iff (by positivity : (1+Real.exp (2*a)) ≠ 0)).mpr + nlinarith + +lemma one_add_tanh_half (a : ℝ) : + (1+Real.tanh a)/2 = 1/(1+Real.exp (-2*a)) := by + simpa only [Real.tanh_neg, sub_neg_eq_add, mul_neg, neg_mul] using one_sub_tanh_half (-a) + +lemma siteRefresh_diagonal_lower {n : ℕ} (J : Interaction n) (x : Spin n) (i : Fin n) : + 1/(1+Real.exp (2*|field J x i|)) ≤ + siteRefresh J i (fun z => if z=x then 1 else 0) x := by + have htrue : replace x i true = x ↔ x i = true := by + constructor + · intro h; simpa using (congrFun h i).symm + · intro h; simpa only [h] using replace_self x i + have hfalse : replace x i false = x ↔ x i = false := by + constructor + · intro h; simpa using (congrFun h i).symm + · intro h; simpa only [h] using replace_self x i + simp only [siteRefresh, htrue, hfalse, mean] + cases x i <;> simp only [ Bool.false_eq_true, Bool.true_eq_false, + ↓reduceIte, mul_zero, mul_one, zero_add, add_zero] + · rw [one_sub_tanh_half] + apply one_div_le_one_div_of_le (by positivity) + apply add_le_add le_rfl + apply Real.exp_le_exp.mpr + linarith [le_abs_self (field J x i)] + · rw [one_add_tanh_half] + apply one_div_le_one_div_of_le (by positivity) + apply add_le_add le_rfl + apply Real.exp_le_exp.mpr + linarith [neg_le_abs (field J x i)] + +lemma logistic_quadratic_lower {a L : ℝ} (hL : 0 < L) : + (1-a^2/L^2)/(1+Real.exp (2*L)) ≤ 1/(1+Real.exp (2*|a|)) := by + by_cases ha : |a| ≤ L + · calc + _ ≤ 1/(1+Real.exp (2*L)) := by + apply div_le_div_of_nonneg_right _ (by positivity) + have : 0 ≤ a^2/L^2 := by positivity + linarith + _ ≤ _ := by + apply one_div_le_one_div_of_le (by positivity) + apply add_le_add le_rfl + apply Real.exp_le_exp.mpr + linarith + · have ha2 : L^2 ≤ a^2 := by nlinarith [sq_abs a, abs_nonneg a, le_of_not_ge ha] + have hratio : 1 ≤ a^2/L^2 := (one_le_div (sq_pos_of_pos hL)).mpr ha2 + exact (div_nonpos_of_nonpos_of_nonneg (by linarith) (by positivity)).trans (by positivity) + +lemma attempted_holding_lower {n : ℕ} (hn : 0 < n) (J : Interaction n) + {K : ℝ} (hK : 0 < K) + (hJ : ‖Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) J‖ ≤ K) (x : Spin n) : + 1/(2*(1+Real.exp (2*(Real.sqrt 2*K)))) ≤ attemptKernel J x x := by + have hnR : (0:ℝ) < n := Nat.cast_pos.mpr hn + have hL : 0 < Real.sqrt 2*K := mul_pos (Real.sqrt_pos.mpr (by norm_num)) hK + have hL2 : (Real.sqrt 2*K)^2 = 2*K^2 := by + rw [mul_pow, Real.sq_sqrt (by norm_num : (0:ℝ) ≤ 2)] + have hsum := field_square_sum_le J x hK.le hJ + have hs : (∑ i, (1-field J x i^2/(Real.sqrt 2*K)^2)/(1+Real.exp (2*(Real.sqrt 2*K)))) ≤ + ∑ i, siteRefresh J i (fun z => if z=x then 1 else 0) x := by + apply Finset.sum_le_sum + intro i _ + exact (logistic_quadratic_lower hL).trans (siteRefresh_diagonal_lower J x i) + simp only [← Finset.sum_div, Finset.sum_sub_distrib, Finset.sum_const, + Finset.card_univ, Fintype.card_fin, nsmul_eq_mul, mul_one, hL2] at hs + have hf : (∑ i, field J x i^2)/(2*K^2) ≤ (n:ℝ)/2 := by + apply (div_le_iff₀ (by positivity : 0 < 2*K^2)).mpr + nlinarith + change _ ≤ attemptLM J (fun z => if z=x then 1 else 0) x + rw [attempt_apply_of_pos hn] + apply (le_div_iff₀ hnR).mpr + calc + _ = ((n:ℝ)/2)/(1+Real.exp (2*(Real.sqrt 2*K))) := by field_simp + _ ≤ ((n:ℝ)-(∑ i, field J x i^2)/(2*K^2))/(1+Real.exp (2*(Real.sqrt 2*K))) := by + apply div_le_div_of_nonneg_right _ (by positivity) + linarith + _ ≤ _ := hs + +end SKRatio.Calculus + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Dynamics/ClockLower.lean b/lean/OAI/Probability/SKRatio/Dynamics/ClockLower.lean new file mode 100644 index 0000000000000000000000000000000000000000..a46206af23e06610cd9a6c8dd9aa28350c98b6d0 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Dynamics/ClockLower.lean @@ -0,0 +1,241 @@ +import Mathlib +import OAI.Probability.SKRatio.Dynamics.Median +import OAI.Probability.SKRatio.Dynamics.LogQuadratic + +namespace OAI + +section +noncomputable section +open scoped BigOperators Topology Matrix NNReal ENNReal +open MeasureTheory Filter ProbabilityTheory SKRatioClock +namespace SKRatio.Calculus + +lemma poissonMass_nonneg {r : ℝ} (hr : 0 ≤ r) (j : ℕ) : + 0 ≤ Clock.poissonMass r j := by unfold Clock.poissonMass; positivity + +lemma poissonMass_exp_hasSum (r s : ℝ) : + HasSum (fun j => Clock.poissonMass r j*Real.exp (s*(j:ℝ))) + (Real.exp (r*(Real.exp s-1))) := by + have h := (NormedSpace.expSeries_div_hasSum_exp (r*Real.exp s)).mul_left (Real.exp (-r)) + convert! h using 1 + · funext j + rw [mul_pow, ← Real.exp_nat_mul] + unfold Clock.poissonMass + ring_nf + · rw [← Real.exp_eq_exp_ℝ, ← Real.exp_add] + congr 1 + ring + +lemma poisson_head_le {r s : ℝ} (hr : 0 ≤ r) (hs : 0 ≤ s) (k : ℕ) : + (∑ j ∈ Finset.range k, Clock.poissonMass r j) ≤ + Real.exp (s*(k:ℝ)+r*(Real.exp (-s)-1)) := by + have hsum := (poissonMass_exp_hasSum r (-s)).mul_left (Real.exp (s*k)) + have hle : (∑ j ∈ Finset.range k, Clock.poissonMass r j) ≤ + ∑ j ∈ Finset.range k, Real.exp (s*k)*(Clock.poissonMass r j*Real.exp (-s*j)) := by + apply Finset.sum_le_sum + intro j hj + have hj' : (j:ℝ) ≤ k := by exact_mod_cast (Finset.mem_range.mp hj).le + calc + _ ≤ Clock.poissonMass r j * Real.exp (s*((k:ℝ)-j)) := by + exact le_mul_of_one_le_right (poissonMass_nonneg hr j) + ((Real.one_le_exp_iff).mpr (mul_nonneg hs (sub_nonneg.mpr hj'))) + _ = _ := by + calc + _ = Clock.poissonMass r j * (Real.exp (s*k)*Real.exp (-s*j)) := by + rw [← Real.exp_add]; congr 2; ring + _ = _ := by ring + apply hle.trans + have ht := Summable.sum_le_tsum (Finset.range k) (fun j _ => by + exact mul_nonneg (Real.exp_pos _).le + (mul_nonneg (poissonMass_nonneg hr j) (Real.exp_pos _).le)) hsum.summable + rw [hsum.tsum_eq] at ht + simpa only [Real.exp_add] using ht + +lemma exists_poisson_head_exponent {a : ℝ} (ha1 : a < 1) : + ∃ s c : ℝ, 0 < s ∧ 0 < c ∧ s*a+Real.exp (-s)-1 = -c := by + let s := (1-a)/2 + have hs : 0 < s := by dsimp [s]; linarith + have he : Real.exp (-s) ≤ (1+s)⁻¹ := by + rw [Real.exp_neg] + simp only [← one_div] + apply one_div_le_one_div_of_le (by linarith : 0 < 1+s) + linarith [Real.add_one_le_exp s] + have ha' : a*(1+s) < 1 := by + have hm := mul_le_mul_of_nonneg_right ha1.le hs.le + dsimp [s] at * + nlinarith + have hh : s*a+(1+s)⁻¹-1 < 0 := by + have hpos : 0 < 1+s := by linarith + have hid : (s*a+(1+s)⁻¹-1)*(1+s) = s*(a*(1+s)-1) := by + field_simp + ring + have hp := mul_neg_of_pos_of_neg hs (sub_neg.mpr ha') + rw [← hid] at hp + nlinarith + refine ⟨s, -(s*a+Real.exp (-s)-1),hs,?_,by ring⟩ + linarith + +lemma continuousKernel_poisson_integral {n : ℕ} (hn : 0 < n) + (g : Disorder n) (t : ℝ) (ht : 0 ≤ t) (x y : Spin n) : + continuousKernel (coupling g) t x y = ∫ j, (transition g ^ j) x y + ∂poissonMeasure (⟨(n:ℝ)*t, mul_nonneg (Nat.cast_nonneg n) ht⟩ : ℝ≥0) := by + erw [integral_poissonMeasure] + change continuousKernel (coupling g) t x y = + ∑' j, Real.exp (-((n:ℝ)*t))*((n:ℝ)*t)^j/(j.factorial:ℝ)*(transition g ^ j) x y + simpa only [neg_mul] using + (continuousKernel_poisson_hasSum hn g t x y).tsum_eq.symm + +lemma integrable_discreteKernel_poisson {n : ℕ} (g : Disorder n) + (r : ℝ≥0) (x y : Spin n) : + Integrable (fun j => (transition g ^ j) x y) (poissonMeasure r) := by + apply Integrable.mono' (integrable_const (1 : ℝ)) (.of_discrete) (ae_of_all _ ?_) + intro j + rw [Real.norm_eq_abs, abs_of_nonneg ((transition_pow_stochastic g j).1 x y)] + exact (Finset.single_le_sum (fun z _ => (transition_pow_stochastic g j).1 x z) + (Finset.mem_univ y)).trans_eq + (Matrix.sum_row_of_mem_rowStochastic (transition_pow_stochastic g j) x) + +lemma totalVariation_integral_le {n : ℕ} {Ω : Type*} [MeasurableSpace Ω] + (μ : Measure Ω) [IsProbabilityMeasure μ] (p : Ω → Spin n → ℝ) + (q : Spin n → ℝ) (hi : ∀ y, Integrable (fun j => p j y) μ) : + totalVariation (fun y => ∫ j, p j y ∂μ) q ≤ ∫ j, totalVariation (p j) q ∂μ := by + unfold totalVariation + rw [integral_const_mul, integral_finsetSum] + swap + · intro y _ + exact ((hi y).sub (integrable_const (q y))).abs + gcongr with y + have he : (∫ j, p j y ∂μ)-q y = ∫ j, (p j y-q y) ∂μ := by + rw [integral_sub (hi y) (integrable_const _)] + simp + rw [he] + exact abs_integral_le_integral_abs + +lemma integrable_totalVariation_poisson {n : ℕ} (g : Disorder n) + (r : ℝ≥0) (x : Spin n) : + Integrable (fun j => totalVariation ((transition g ^ j) x) (mass g 0)) + (poissonMeasure r) := by + unfold totalVariation + apply Integrable.const_mul + apply integrable_finsetSum + intro y _ + exact ((integrable_discreteKernel_poisson g r x y).sub (integrable_const _)).abs + +lemma poisson_head_integral (r : ℝ≥0) (k : ℕ) : + (∫ j : ℕ, (if j < k then (1:ℝ) else 0) ∂poissonMeasure r) = + ∑ j ∈ Finset.range k, Clock.poissonMass r j := by + erw [integral_poissonMeasure] + simp only [smul_eq_mul, mul_ite, mul_one, mul_zero] + rw [tsum_eq_sum (s := Finset.range k) (fun j hj => by + simp only [Finset.mem_range, not_lt] at hj + simp only [not_lt.mpr hj, ite_false])] + apply Finset.sum_congr rfl + intro j hj + rw [ite_eq_left (Finset.mem_range.mp hj)] + rfl + +lemma continuous_le_poisson_head_add_discrete {n : ℕ} (hn : 0 < n) + (g : Disorder n) (t : ℝ) (ht : 0 ≤ t) (k : ℕ) : + continuousDistance g t ≤ (∑ j ∈ Finset.range k, Clock.poissonMass ((n:ℝ)*t) j) + + discreteDistance g k := by + let r : ℝ≥0 := ⟨(n:ℝ)*t,mul_nonneg (Nat.cast_nonneg n) ht⟩ + apply Finset.sup'_le + intro x _ + change totalVariation (continuousKernel (coupling g) t x) (mass g 0) ≤ _ + have he : continuousKernel (coupling g) t x = + fun y => ∫ j, (transition g ^ j) x y ∂poissonMeasure r := by + funext y + exact continuousKernel_poisson_integral hn g t ht x y + rw [he] + apply (totalVariation_integral_le _ _ _ (integrable_discreteKernel_poisson g r x)).trans + have hbi : Integrable (fun j : ℕ => if j < k then (1:ℝ) else 0) (poissonMeasure r) := by + apply Integrable.mono' (integrable_const (1:ℝ)) (.of_discrete) + exact ae_of_all _ (fun j => by split_ifs <;> norm_num) + calc + _ ≤ ∫ j : ℕ, (if j < k then (1:ℝ) else 0)+discreteDistance g k ∂poissonMeasure r := by + apply integral_mono (integrable_totalVariation_poisson g r x) + (hbi.add (integrable_const _)) + intro j + change totalVariation ((transition g ^ j) x) (mass g 0) ≤ + (if j < k then (1:ℝ) else 0)+discreteDistance g k + by_cases hj : j < k + · simp only [ite_eq_left hj] + have hb := (tv_le_discreteDistance g j x).trans (discreteDistance_le_one g j) + linarith [discreteDistance_nonneg g k] + · simp only [ite_eq_right hj, zero_add] + exact (tv_le_discreteDistance g j x).trans + (discreteDistance_antitone g (not_lt.mp hj)) + _ = _ := by + rw [integral_add hbi (integrable_const _), poisson_head_integral] + have hu : (poissonMeasure r).real Set.univ = 1 := by + simp [Measure.real, measure_univ] + simp only [integral_const, smul_eq_mul, hu, one_mul] + rfl + +lemma uniform_lower_clock_error + (G : ∀ n : ℕ, Set (Disorder n)) {b : ℝ} (hb : 0 < b) (hb1 : b < 1) + (hdiv : ∀ R : ℝ, ∀ᶠ n : ℕ in atTop, ∀ g ∈ G n, R ≤ (n:ℝ)*medianTime g) : + ∀ ε : ℝ, 0 < ε → ∀ᶠ n : ℕ in atTop, ∀ g ∈ G n, + (∑ j ∈ Finset.range ⌊(1-b)*(n:ℝ)*medianTime g⌋₊, + Clock.poissonMass ((n:ℝ)*((1-b/2)*medianTime g)) j) < ε := by + let a : ℝ := (1-b)/(1-b/2) + have hmid : 0 < 1-b/2 := by linarith + have ha1 : a < 1 := by + apply (div_lt_one hmid).mpr + linarith + obtain ⟨s,c,hs,hc,he⟩ := exists_poisson_head_exponent ha1 + intro ε hε + have hlim : Tendsto (fun z : ℝ => Real.exp (-c*((1-b/2)*z))) atTop (𝓝 0) := by + simpa only [Function.comp_def,neg_mul,id_eq] using + Real.tendsto_exp_neg_atTop_nhds_zero.comp + ((tendsto_id.const_mul_atTop hmid).const_mul_atTop hc) + obtain ⟨R,hR⟩ := eventually_atTop.mp (hlim.eventually (gt_mem_nhds hε)) + filter_upwards [hdiv R] with n hn + intro g hg + have ht := (medianTime_mem g).1 + have hr : 0 ≤ (n:ℝ)*((1-b/2)*medianTime g) := by positivity + have hkr : (⌊(1-b)*(n:ℝ)*medianTime g⌋₊:ℝ) ≤ + a*((n:ℝ)*((1-b/2)*medianTime g)) := by + apply (Nat.floor_le (mul_nonneg + (mul_nonneg (by linarith) (Nat.cast_nonneg _)) ht)).trans + apply le_of_eq + dsimp [a] + have hne : 2-b ≠ 0 := by linarith + field_simp [hne] + have hhead := poisson_head_le hr hs.le ⌊(1-b)*(n:ℝ)*medianTime g⌋₊ + have hexp : Real.exp (s*(⌊(1-b)*(n:ℝ)*medianTime g⌋₊:ℝ)+ + ((n:ℝ)*((1-b/2)*medianTime g))*(Real.exp (-s)-1)) ≤ + Real.exp (-c*((1-b/2)*((n:ℝ)*medianTime g))) := by + apply Real.exp_le_exp.mpr + calc + _ ≤ s*(a*((n:ℝ)*((1-b/2)*medianTime g)))+ + ((n:ℝ)*((1-b/2)*medianTime g))*(Real.exp (-s)-1) := by + gcongr + _ = (s*a+Real.exp (-s)-1)*((n:ℝ)*((1-b/2)*medianTime g)) := by ring + _ = _ := by rw [he]; ring + exact (hhead.trans hexp).trans_lt (hR _ (hn g hg)) + +theorem uniform_discrete_lower_from_continuous + (G : ∀ n : ℕ, Set (Disorder n)) {b : ℝ} (hb : 0 < b) (hb1 : b < 1) + (hdiv : ∀ R : ℝ, ∀ᶠ n : ℕ in atTop, ∀ g ∈ G n, R ≤ (n:ℝ)*medianTime g) + (hcont : ∀ δ : ℝ, 0 < δ → ∀ᶠ n : ℕ in atTop, ∀ g ∈ G n, + 1-δ < continuousDistance g ((1-b/2)*medianTime g)) : + ∀ δ : ℝ, 0 < δ → ∀ᶠ n : ℕ in atTop, ∀ g ∈ G n, + 1-δ < discreteDistance g ⌊(1-b)*(n:ℝ)*medianTime g⌋₊ := by + intro δ hδ + filter_upwards [hcont (δ/2) (by positivity), + uniform_lower_clock_error G hb hb1 hdiv (δ/2) (by positivity), + eventually_gt_atTop 0] with n hn he hn0 + intro g hg + have h := continuous_le_poisson_head_add_discrete hn0 g ((1-b/2)*medianTime g) + (mul_nonneg (by linarith) (medianTime_mem g).1) ⌊(1-b)*(n:ℝ)*medianTime g⌋₊ + have hc := hn g hg + have he' := he g hg + linarith + +end SKRatio.Calculus + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Dynamics/ClockTransfer.lean b/lean/OAI/Probability/SKRatio/Dynamics/ClockTransfer.lean new file mode 100644 index 0000000000000000000000000000000000000000..76fb92a44729775f869370fb047e376452ef53d7 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Dynamics/ClockTransfer.lean @@ -0,0 +1,170 @@ +import Mathlib +import OAI.Probability.SKRatio.Dynamics.Median +import OAI.Probability.SKRatio.Dynamics.PoissonBinomial +import OAI.Probability.SKRatio.Dynamics.ClockBridge + +namespace OAI + +section +noncomputable section +open scoped BigOperators Topology Matrix +open ContinuousLinearMap MeasureTheory Filter ProbabilityTheory SKRatioClock +namespace SKRatio.Calculus + +lemma median_attempts_diverge_of_log_lower + (G : ∀ n : ℕ, Set (Disorder n)) {c : ℝ} (hc : 0 < c) + (hscale : ∀ᶠ n : ℕ in atTop, ∀ g ∈ G n, c*Real.log n ≤ medianTime g) : + ∀ R : ℝ, ∀ᶠ n : ℕ in atTop, ∀ g ∈ G n, R ≤ (n:ℝ)*medianTime g := by + have hlog : Tendsto (fun n : ℕ => Real.log (n:ℝ)) atTop atTop := + Real.tendsto_log_atTop.comp tendsto_natCast_atTop_atTop + have hlim : Tendsto (fun n : ℕ => (n:ℝ)*(c*Real.log n)) atTop atTop := + tendsto_natCast_atTop_atTop.atTop_mul_atTop₀ (hlog.const_mul_atTop hc) + intro R + filter_upwards [hscale,hlim.eventually_ge_atTop R] with n hn hR + intro g hg + exact hR.trans (mul_le_mul_of_nonneg_left (hn g hg) (Nat.cast_nonneg n)) + +lemma upper_median_clock_diverges + (G : ∀ n : ℕ, Set (Disorder n)) {b : ℝ} (hb : 0 < b) + (hdiv : ∀ R : ℝ, ∀ᶠ n : ℕ in atTop, ∀ g ∈ G n, R ≤ (n:ℝ)*medianTime g) : + ∀ K : ℕ, ∀ᶠ n : ℕ in atTop, ∀ g ∈ G n, + K ≤ ⌈(1+b)*(n:ℝ)*medianTime g⌉₊ := by + intro K + have hp : 0 < 1+b := by linarith + filter_upwards [hdiv ((K:ℝ)/(1+b))] with n hn + intro g hg + have hx := (div_le_iff₀ hp).mp (hn g hg) + have hy : (K:ℝ) ≤ (⌈(1+b)*(n:ℝ)*medianTime g⌉₊:ℝ) := by + apply le_trans _ (Nat.le_ceil _) + nlinarith only [hx] + exact_mod_cast hy + +lemma upper_clock_shifted_time {n : ℕ} (hn : 0 < n) (t : ℝ) + {b q y : ℝ} (hb : 0 < b) (hq : 0 < q) + (hy : |y| ≤ (q*b/(2*(1+b)))*Real.sqrt (⌈(1+b)*(n:ℝ)*t⌉₊:ℝ)) : + (1+b/2)*t ≤ + (q*(⌈(1+b)*(n:ℝ)*t⌉₊:ℝ)+y*Real.sqrt (⌈(1+b)*(n:ℝ)*t⌉₊:ℝ))/(q*n) := by + let M : ℕ := ⌈(1+b)*(n:ℝ)*t⌉₊ + let c := q*b/(2*(1+b)) + have hc : 0 < c := by dsimp [c]; positivity + have hcq : c < q := by + dsimp [c] + apply (div_lt_iff₀ (by positivity : 0 < 2*(1+b))).mpr + nlinarith + have hn' : (0:ℝ) < n := Nat.cast_pos.mpr hn + have hM : (1+b)*(n:ℝ)*t ≤ (M:ℝ) := Nat.le_ceil _ + have hsq : Real.sqrt (M:ℝ)^2 = (M:ℝ) := Real.sq_sqrt (Nat.cast_nonneg _) + have herr : -c*(M:ℝ) ≤ y*Real.sqrt (M:ℝ) := by + have hh := mul_le_mul_of_nonneg_right hy (Real.sqrt_nonneg (M:ℝ)) + have hy' := mul_le_mul_of_nonneg_right (neg_abs_le y) (Real.sqrt_nonneg (M:ℝ)) + change |y| * Real.sqrt (M:ℝ) ≤ c*Real.sqrt (M:ℝ)*Real.sqrt (M:ℝ) at hh + nlinarith + apply (le_div_iff₀ (mul_pos hq hn')).mpr + have hmain := mul_le_mul_of_nonneg_left hM (sub_pos.mpr hcq).le + have hid : (q-c)*(1+b) = q*(1+b/2) := by + dsimp [c] + field_simp + ring + change _ ≤ q*(M:ℝ)+y*Real.sqrt (M:ℝ) + calc + _ = (q-c)*((1+b)*(n:ℝ)*t) := by + calc + _ = ((q-c)*(1+b))*(n:ℝ)*t := by rw [hid]; ring + _ = _ := by ring + _ ≤ (q-c)*(M:ℝ) := hmain + _ ≤ _ := by nlinarith + +lemma uniform_upper_clock_shift + (G : ∀ n : ℕ, Set (Disorder n)) {b q : ℝ} (hb : 0 < b) (hq : 0 < q) + (hdiv : ∀ R : ℝ, ∀ᶠ n : ℕ in atTop, ∀ g ∈ G n, R ≤ (n:ℝ)*medianTime g) + (y : ℝ) : + ∀ᶠ n : ℕ in atTop, ∀ g ∈ G n, + (1+b/2)*medianTime g ≤ + (q*(⌈(1+b)*(n:ℝ)*medianTime g⌉₊:ℝ)+ + y*Real.sqrt (⌈(1+b)*(n:ℝ)*medianTime g⌉₊:ℝ))/(q*n) := by + have hc : 0 < q*b/(2*(1+b)) := by positivity + have hs := (Real.tendsto_sqrt_atTop.comp + (tendsto_natCast_atTop_atTop : Tendsto (fun n : ℕ => (n:ℝ)) atTop atTop)).const_mul_atTop hc + obtain ⟨N,hN⟩ := eventually_atTop.mp (hs.eventually_ge_atTop |y|) + filter_upwards [upper_median_clock_diverges G hb hdiv N,eventually_gt_atTop 0] with n hn hn0 + intro g hg + exact upper_clock_shifted_time hn0 (medianTime g) hb hq (hN _ (hn g hg)) + +theorem uniform_discrete_upper_of_holding + (G : ∀ n : ℕ, Set (Disorder n)) {b q : ℝ} + (hb : 0 < b) (hq : 0 < q) (hq1 : q < 1) + (hdiv : ∀ R : ℝ, ∀ᶠ n : ℕ in atTop, ∀ g ∈ G n, R ≤ (n:ℝ)*medianTime g) + (hhold : ∀ n, 0 < n → ∀ g ∈ G n, ∀ x, 1-q ≤ transition g x x) + (hcont : ∀ δ : ℝ, 0 < δ → ∀ᶠ n : ℕ in atTop, ∀ g ∈ G n, + continuousDistance g ((1+b/2)*medianTime g) ≤ δ) : + ∀ δ : ℝ, 0 < δ → ∀ᶠ n : ℕ in atTop, ∀ g ∈ G n, + discreteDistance g ⌈(1+b)*(n:ℝ)*medianTime g⌉₊ ≤ δ := by + classical + let ι : ℕ → Type := fun n => Option + ({g : Disorder n // g ∈ G n ∧ 0 < n} × Spin n × + {f : Observables n // ∀ x, |f x| ≤ 1}) + let M : (n : ℕ) → ι n → ℕ := fun n i => match i with + | none => n+1 + | some j => ⌈(1+b)*(n:ℝ)*medianTime j.1.val⌉₊ + let a : (n : ℕ) → ι n → ℕ → ℝ := fun _ i k => match i with + | none => 0 + | some j => (residualAttempt (coupling j.1.val) q ^ k) j.2.2.val j.2.1- + FiniteLaw.mean (mass j.1.val 0) j.2.2.val + have hM : ∀ K : ℕ, ∀ᶠ n in atTop, ∀ i : ι n, K ≤ M n i := by + intro K + filter_upwards [upper_median_clock_diverges G hb hdiv K,eventually_ge_atTop K] with n hn hnK + intro i + cases i with + | none => exact hnK.trans (Nat.le_succ n) + | some j => exact hn j.1.val j.1.property.1 + have hab : ∀ n (i : ι n) k, |a n i k| ≤ 2 := by + intro n i k + cases i with + | none => norm_num [a] + | some j => + exact residual_test_bound j.1.val hq + (hhold n j.1.property.2 j.1.val j.1.property.1) j.2.2.val j.2.2.property j.2.1 k + have hp : ∀ y ε : ℝ, 0 < ε → ∀ᶠ n in atTop, ∀ i : ι n, + |∑' j, Clock.poissonMass (q*M n i+y*Real.sqrt (M n i)) j*a n i j| < ε := by + intro y ε hε + filter_upwards [uniform_upper_clock_shift G hb hq hdiv y,hcont (ε/4) (by positivity)] with n hn hcn + intro i + cases i with + | none => simpa only [a,mul_zero,tsum_zero,abs_zero] using hε + | some j => + change |∑' k, Clock.poissonMass + (q*(⌈(1+b)*(n:ℝ)*medianTime j.1.val⌉₊:ℝ)+ + y*Real.sqrt (⌈(1+b)*(n:ℝ)*medianTime j.1.val⌉₊:ℝ)) k* + ((residualAttempt (coupling j.1.val) q ^ k) j.2.2.val j.2.1- + FiniteLaw.mean (mass j.1.val 0) j.2.2.val)| < ε + rw [residual_poisson_test j.1.property.2 j.1.val hq.ne'] + have htime := hn j.1.val j.1.property.1 + have ht : 0 ≤ (1+b/2)*medianTime j.1.val := + mul_nonneg (by linarith) (medianTime_mem j.1.val).1 + have hbd := (continuous_test_bound j.1.val _ j.2.2.val j.2.2.property j.2.1).trans + (mul_le_mul_of_nonneg_left (continuousDistance_antitone j.1.val ht htime) (by norm_num)) + have hc := hcn j.1.val j.1.property.1 + linarith + have hbin := Clock.poisson_to_binomial_uniform_clocks hq hq1 M hM a hab hp + intro δ hδ + filter_upwards [hbin δ hδ,eventually_gt_atTop 0] with n hn hn0 + intro g hg + apply Finset.sup'_le + intro x _ + apply FiniteLaw.totalVariation_le_of_tests + intro f hf + let i : ι n := some (⟨g,hg,hn0⟩,x,⟨f,hf⟩) + have hbd := hn i + change |∑' k, Clock.binomialMass q ⌈(1+b)*(n:ℝ)*medianTime g⌉₊ k* + ((residualAttempt (coupling g) q ^ k) f x-FiniteLaw.mean (mass g 0) f)| < δ at hbd + rw [residual_binomial_test g hq.ne'] at hbd + change |((transition g ^ ⌈(1+b)*(n:ℝ)*medianTime g⌉₊) *ᵥ f) x- + FiniteLaw.mean (mass g 0) f| ≤ 2*δ + linarith + +end SKRatio.Calculus + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Dynamics/Concentration.lean b/lean/OAI/Probability/SKRatio/Dynamics/Concentration.lean new file mode 100644 index 0000000000000000000000000000000000000000..aaf71f4246dc0d3907c8b7fa8ed5b7686d65c604 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Dynamics/Concentration.lean @@ -0,0 +1,375 @@ +import Mathlib +import OAI.Probability.SKRatio.Calculus.SignedVector + +namespace OAI + +section +noncomputable section +open scoped BigOperators Topology Matrix +open ContinuousLinearMap MeasureTheory Filter +namespace SKRatio.Calculus + +lemma flip_sub {n : ℕ} (f : Observables n) (x : Spin n) (i : Fin n) : + f (flip i x)-f x = -2*spin x i*halfDiff i f x := by + have hx := replace_self x i + cases hi : x i <;> simp only [hi] at hx + · simp only [spin, hi, Bool.false_eq_true, ↓reduceIte, flip, Bool.not_false, halfDiff] + rw [hx] + simp only [replace] + ring + · simp only [spin, hi, ↓reduceIte, flip, Bool.not_true, halfDiff] + rw [hx] + simp only [replace] + ring + +lemma backward_flow_hasDerivAt {n : ℕ} (J : Interaction n) (f : Observables n) (d s : ℝ) : + HasDerivAt (fun r : ℝ => semigroup J (d - r) f) + (fun x => -generator J (semigroup J (d - s) f) x) s := by + have h := (semigroup_apply_hasDerivAt' J f (d - s)).scomp s + ((hasDerivAt_id s).const_sub d) + simpa only [id_eq, neg_smul, one_smul, Pi.neg_def, Function.comp_def] using h + +lemma backward_square_hasDerivAt {n : ℕ} (J : Interaction n) (f : Observables n) (d s : ℝ) : + HasDerivAt (fun r : ℝ => fun x : Spin n => (semigroup J (d - r) f x) ^ 2) + (fun x => -2 * semigroup J (d - s) f x * generator J (semigroup J (d - s) f) x) s := by + apply hasDerivAt_pi.mpr + intro x + have h := (hasDerivAt_pi.mp (backward_flow_hasDerivAt J f d s) x).pow 2 + have he : (2 : ℝ) * semigroup J (d - s) f x * + -generator J (semigroup J (d - s) f) x = + -2 * semigroup J (d - s) f x * generator J (semigroup J (d - s) f) x := by ring + convert h using 1 + try rfl + simpa only [Nat.cast_ofNat, Nat.reduceSub, pow_one] using he.symm + +lemma interpolated_square_hasDerivAt {n : ℕ} (J : Interaction n) (f : Observables n) (d s : ℝ) : + HasDerivAt (fun r : ℝ => semigroup J r + (fun x => (semigroup J (d - r) f x) ^ 2)) + (semigroup J s (jumpEnergy J (semigroup J (d - s) f))) s := by + have h := (semigroup_hasDerivAt J s).clm_apply (backward_square_hasDerivAt J f d s) + apply h.congr_deriv + simp only [mul_apply_eq_comp] + change semigroup J s (generator J (fun x => semigroup J (d - s) f x ^ 2)) + + semigroup J s (fun x => -2 * semigroup J (d - s) f x * + generator J (semigroup J (d - s) f) x) = _ + rw [← map_add] + congr 1 + funext x + rw [generator_square] + simp only [Pi.add_apply] + ring + +lemma jumpEnergy_continuous {n : ℕ} (J : Interaction n) : + Continuous (jumpEnergy J) := by + unfold jumpEnergy halfDiff + fun_prop + +lemma interpolated_energy_continuous {n : ℕ} (J : Interaction n) (f : Observables n) + (d : ℝ) (x : Spin n) : + Continuous (fun s : ℝ => semigroup J s (jumpEnergy J (semigroup J (d - s) f)) x) := by + have hc : Continuous (fun s : ℝ => semigroup J (d - s) f) := + ((semigroup_continuous J).comp (continuous_const.sub continuous_id)).clm_apply continuous_const + exact continuous_apply x |>.comp ((semigroup_continuous J).clm_apply + ((jumpEnergy_continuous J).comp hc)) + +lemma semigroup_variance_integral {n : ℕ} (J : Interaction n) (f : Observables n) + (d : ℝ) (x : Spin n) : + semigroup J d (fun y => f y ^ 2) x - (semigroup J d f x) ^ 2 = + ∫ s in (0 : ℝ)..d, semigroup J s (jumpEnergy J (semigroup J (d - s) f)) x := by + have hd (s : ℝ) := hasDerivAt_pi.mp (interpolated_square_hasDerivAt J f d s) x + have hi := (interpolated_energy_continuous J f d x).intervalIntegrable + (μ := MeasureTheory.volume) 0 d + have he := intervalIntegral.integral_eq_sub_of_hasDerivAt (fun s _ => hd s) hi + simpa only [sub_self, sub_zero, semigroup_zero, one_apply_eq_self] using he.symm + +lemma jumpWeight_bounds {n : ℕ} (J : Interaction n) (x : Spin n) (i : Fin n) : + 0 ≤ 1 - mean J x i * spin x i ∧ 1 - mean J x i * spin x i ≤ 2 := by + have hl := Real.neg_one_lt_tanh (field J x i) + have hu := Real.tanh_lt_one (field J x i) + cases hs : x i <;> simp only [spin, hs, Bool.false_eq_true, ↓reduceIte, mul_one, + mul_neg, sub_neg_eq_add, mean] <;> constructor <;> linarith + +lemma jumpEnergy_nonneg {n : ℕ} (J : Interaction n) (f : Observables n) (x : Spin n) : + 0 ≤ jumpEnergy J f x := by + unfold jumpEnergy + exact mul_nonneg (by norm_num) (Finset.sum_nonneg + (fun i _ => mul_nonneg (jumpWeight_bounds J x i).1 (sq_nonneg _))) + +lemma jumpEnergy_le_gradient {n : ℕ} (J : Interaction n) (f : Observables n) (x : Spin n) : + jumpEnergy J f x ≤ 4 * ∑ i, (halfDiff i f x) ^ 2 := by + unfold jumpEnergy + calc + _ ≤ 2 * ∑ i, 2 * (halfDiff i f x) ^ 2 := by + apply mul_le_mul_of_nonneg_left (Finset.sum_le_sum _) (by norm_num) + intro i _ + exact mul_le_mul_of_nonneg_right (jumpWeight_bounds J x i).2 (sq_nonneg _) + _ = _ := by rw [← Finset.mul_sum]; ring + +lemma semigroup_le_const {n : ℕ} (J : Interaction n) (t : ℝ) (ht : 0 ≤ t) + {f : Observables n} {C : ℝ} (hf : ∀ x, f x ≤ C) (x : Spin n) : + semigroup J t f x ≤ C := by + simpa only [semigroup_const] using semigroup_mono J ht _ _ hf x + +theorem semigroup_variance_le {n : ℕ} (J : Interaction n) (f : Observables n) + (d : ℝ) (hd : 0 ≤ d) (b : ℝ → ℝ) + (hb : IntervalIntegrable b MeasureTheory.volume 0 d) + (hbound : ∀ r ∈ Set.Icc (0 : ℝ) d, ∀ x, ∑ i, (halfDiff i (semigroup J r f) x) ^ 2 ≤ b r) + (x : Spin n) : + semigroup J d (fun y => f y ^ 2) x - (semigroup J d f x) ^ 2 ≤ + 4 * ∫ r in (0 : ℝ)..d, b r := by + rw [semigroup_variance_integral] + have hbr : IntervalIntegrable (fun s => b (d - s)) MeasureTheory.volume 0 d := by + simpa only [sub_self, sub_zero] using (hb.comp_sub_left d).symm + calc + _ ≤ ∫ s in (0 : ℝ)..d, 4 * b (d - s) := by + apply intervalIntegral.integral_mono_on hd + ((interpolated_energy_continuous J f d x).intervalIntegrable 0 d) + (hbr.const_mul 4) + intro s hs + apply semigroup_le_const J s hs.1 + intro y + exact (jumpEnergy_le_gradient J (semigroup J (d - s) f) y).trans + (mul_le_mul_of_nonneg_left (hbound (d - s) ⟨sub_nonneg.mpr hs.2, by linarith [hs.1]⟩ y) + (by norm_num)) + _ = _ := by + rw [intervalIntegral.integral_const_mul, intervalIntegral.integral_comp_sub_left] + simp only [sub_self, sub_zero] + +lemma real_exp_remainder_le (z : ℝ) : + Real.exp z - 1 - z ≤ z ^ 2 * Real.exp |z| / 2 := by + by_cases hz : z = 0 + · simp [hz] + have hn : (0 : ℝ) ≠ z := Ne.symm hz + obtain ⟨u, hu, he⟩ := taylor_mean_remainder_lagrange_iteratedDeriv + (n := 1) (f := Real.exp) hn Real.contDiff_exp.contDiffOn + have hd : derivWithin Real.exp (Set.uIcc 0 z) 0 = 1 := by + simpa using (Real.hasDerivAt_exp 0).hasDerivWithinAt.derivWithin + ((uniqueDiffOn_uIcc hn) 0 (Set.left_mem_uIcc)) + have hi : iteratedDeriv 2 Real.exp = Real.exp := by + simpa using iteratedDeriv_exp_const_mul 2 (1 : ℝ) + simp [taylorWithinEval_succ, iteratedDerivWithin_one, hd, hi] at he + have hu' : u ≤ |z| := by + calc + u ≤ max 0 z := le_of_lt hu.2 + _ ≤ |z| := max_le (abs_nonneg _) (le_abs_self _) + calc + Real.exp z - 1 - z = Real.exp u * z ^ 2 / 2 := by linarith [he] + _ ≤ z ^ 2 * Real.exp |z| / 2 := by + have h := mul_le_mul_of_nonneg_right (Real.exp_le_exp.mpr hu') (sq_nonneg z) + nlinarith + +noncomputable def expDrift {n : ℕ} (J : Interaction n) (θ : ℝ) + (f : Observables n) (x : Spin n) : ℝ := + generator J (fun y => Real.exp (θ * f y)) x - + θ * Real.exp (θ * f x) * generator J f x + +lemma expDrift_eq_sum {n : ℕ} (J : Interaction n) (θ : ℝ) (f : Observables n) (x : Spin n) : + expDrift J θ f x = Real.exp (θ * f x) * ∑ i, flipRate J x i * + (Real.exp (θ * (f (flip i x) - f x)) - 1 - θ * (f (flip i x) - f x)) := by + have he (i : Fin n) : Real.exp (θ * f (flip i x)) = + Real.exp (θ * f x) * Real.exp (θ * (f (flip i x) - f x)) := by + rw [← Real.exp_add] + congr 1 + ring + simp only [expDrift, generator_flip, he, Finset.mul_sum, ← Finset.sum_sub_distrib] + apply Finset.sum_congr rfl + intro i _ + ring + +lemma flipRate_nonneg {n : ℕ} (J : Interaction n) (x : Spin n) (i : Fin n) : + 0 ≤ flipRate J x i := by + unfold flipRate + exact div_nonneg (by simpa only [mul_comm] using (jumpWeight_bounds J x i).1) (by norm_num) + +lemma jumpEnergy_eq_jump_square {n : ℕ} (J : Interaction n) (f : Observables n) (x : Spin n) : + jumpEnergy J f x = ∑ i, flipRate J x i * (f (flip i x) - f x) ^ 2 := by + simp only [jumpEnergy, Finset.mul_sum] + apply Finset.sum_congr rfl + intro i _ + rw [flip_sub] + simp only [mul_pow, spin_sq, mul_one, flipRate] + ring + +lemma abs_flip_sub_le {n : ℕ} (f : Observables n) (x : Spin n) (B : ℝ) + (hB : ∑ j, (halfDiff j f x) ^ 2 ≤ B) (i : Fin n) : + |f (flip i x) - f x| ≤ 2 * Real.sqrt B := by + have hi : (halfDiff i f x) ^ 2 ≤ B := + (Finset.single_le_sum (fun j _ => sq_nonneg (halfDiff j f x)) (Finset.mem_univ i)).trans hB + have hs : |spin x i| = 1 := by cases hx : x i <;> simp [spin, hx] + rw [flip_sub, abs_mul, abs_mul, hs] + norm_num + exact Real.abs_le_sqrt hi + +lemma expDrift_le {n : ℕ} (J : Interaction n) (θ : ℝ) (f : Observables n) (x : Spin n) + (B b : ℝ) (hB : ∑ i, (halfDiff i f x) ^ 2 ≤ B) + (hb : ∑ i, (halfDiff i f x) ^ 2 ≤ b) : + expDrift J θ f x ≤ (2 * θ ^ 2 * Real.exp (2 * |θ| * Real.sqrt B) * b) * + Real.exp (θ * f x) := by + let R := Real.exp (2 * |θ| * Real.sqrt B) + have hR : 0 ≤ θ ^ 2 * R / 2 := by positivity + have hrem (i : Fin n) : + Real.exp (θ * (f (flip i x) - f x)) - 1 - θ * (f (flip i x) - f x) ≤ + θ ^ 2 * R / 2 * (f (flip i x) - f x) ^ 2 := by + have ha : |θ * (f (flip i x) - f x)| ≤ 2 * |θ| * Real.sqrt B := by + rw [abs_mul] + calc + _ ≤ |θ| * (2 * Real.sqrt B) := + mul_le_mul_of_nonneg_left (abs_flip_sub_le f x B hB i) (abs_nonneg θ) + _ = _ := by ring + calc + _ ≤ (θ * (f (flip i x) - f x)) ^ 2 * + Real.exp |θ * (f (flip i x) - f x)| / 2 := real_exp_remainder_le _ + _ ≤ (θ * (f (flip i x) - f x)) ^ 2 * R / 2 := by + apply div_le_div_of_nonneg_right _ (by norm_num) + exact mul_le_mul_of_nonneg_left (Real.exp_le_exp.mpr ha) (sq_nonneg _) + _ = _ := by ring + rw [expDrift_eq_sum] + calc + _ ≤ Real.exp (θ * f x) * ∑ i, flipRate J x i * + (θ ^ 2 * R / 2 * (f (flip i x) - f x) ^ 2) := by + apply mul_le_mul_of_nonneg_left (Finset.sum_le_sum _) (Real.exp_pos _).le + intro i _ + exact mul_le_mul_of_nonneg_left (hrem i) (flipRate_nonneg J x i) + _ = Real.exp (θ * f x) * (θ ^ 2 * R / 2) * jumpEnergy J f x := by + rw [jumpEnergy_eq_jump_square] + simp only [Finset.mul_sum] + apply Finset.sum_congr rfl + intro i _ + ring + _ ≤ Real.exp (θ * f x) * (θ ^ 2 * R / 2) * (4 * b) := by + apply mul_le_mul_of_nonneg_left _ (mul_nonneg (Real.exp_pos _).le hR) + exact (jumpEnergy_le_gradient J f x).trans (mul_le_mul_of_nonneg_left hb (by norm_num)) + _ = _ := by dsimp [R]; ring + +lemma backward_exp_hasDerivAt {n : ℕ} (J : Interaction n) (f : Observables n) + (θ d s : ℝ) : + HasDerivAt (fun r : ℝ => fun x : Spin n => Real.exp (θ * semigroup J (d - r) f x)) + (fun x => -θ * Real.exp (θ * semigroup J (d - s) f x) * + generator J (semigroup J (d - s) f) x) s := by + apply hasDerivAt_pi.mpr + intro x + have h := ((hasDerivAt_pi.mp (backward_flow_hasDerivAt J f d s) x).const_mul θ).exp + convert h using 1 + try rfl + ring + +lemma interpolated_exp_hasDerivAt {n : ℕ} (J : Interaction n) (f : Observables n) + (θ d s : ℝ) : + HasDerivAt (fun r : ℝ => semigroup J r + (fun x => Real.exp (θ * semigroup J (d - r) f x))) + (semigroup J s (expDrift J θ (semigroup J (d - s) f))) s := by + have h := (semigroup_hasDerivAt J s).clm_apply (backward_exp_hasDerivAt J f θ d s) + apply h.congr_deriv + simp only [mul_apply_eq_comp] + change semigroup J s (generator J (fun x => Real.exp (θ * semigroup J (d - s) f x))) + + semigroup J s (fun x => -θ * Real.exp (θ * semigroup J (d - s) f x) * + generator J (semigroup J (d - s) f) x) = _ + rw [← map_add] + congr 1 + funext x + simp only [Pi.add_apply, expDrift] + ring + +lemma semigroup_pos {n : ℕ} (J : Interaction n) (t : ℝ) (ht : 0 ≤ t) + {f : Observables n} (hf : ∀ x, 0 < f x) (x : Spin n) : 0 < semigroup J t f x := by + obtain ⟨y, _, hy⟩ := Finset.exists_min_image (Finset.univ : Finset (Spin n)) f + Finset.univ_nonempty + have h := semigroup_mono J ht _ _ (fun z => hy z (Finset.mem_univ z)) x + exact (hf y).trans_le (by simpa only [semigroup_const] using h) + +lemma expDrift_continuous {n : ℕ} (J : Interaction n) (θ : ℝ) : + Continuous (expDrift J θ) := by + unfold expDrift generator halfDiff + fun_prop + +lemma interpolated_exp_continuous {n : ℕ} (J : Interaction n) (f : Observables n) + (θ d : ℝ) (x : Spin n) : + Continuous (fun s : ℝ => semigroup J s + (fun y => Real.exp (θ * semigroup J (d - s) f y)) x) := by + exact continuous_apply x |>.comp + ((show Differentiable ℝ (fun s : ℝ => semigroup J s + (fun y => Real.exp (θ * semigroup J (d - s) f y))) from + fun s => (interpolated_exp_hasDerivAt J f θ d s).differentiableAt).continuous) + +lemma interpolated_expDrift_continuous {n : ℕ} (J : Interaction n) (f : Observables n) + (θ d : ℝ) (x : Spin n) : + Continuous (fun s : ℝ => semigroup J s (expDrift J θ (semigroup J (d - s) f)) x) := by + have hc : Continuous (fun s : ℝ => semigroup J (d - s) f) := + ((semigroup_continuous J).comp (continuous_const.sub continuous_id)).clm_apply continuous_const + exact continuous_apply x |>.comp ((semigroup_continuous J).clm_apply + ((expDrift_continuous J θ).comp hc)) + +theorem semigroup_jump_mgf {n : ℕ} (J : Interaction n) (f : Observables n) + (d : ℝ) (hd : 0 ≤ d) (b : ℝ → ℝ) (B θ : ℝ) + (hb : IntervalIntegrable b MeasureTheory.volume 0 d) + (hB : ∀ r ∈ Set.Icc (0 : ℝ) d, b r ≤ B) + (hbound : ∀ r ∈ Set.Icc (0 : ℝ) d, ∀ x, ∑ i, (halfDiff i (semigroup J r f) x) ^ 2 ≤ b r) + (x : Spin n) : + semigroup J d (fun y => Real.exp (θ * (f y - semigroup J d f x))) x ≤ + Real.exp (2 * θ ^ 2 * Real.exp (2 * |θ| * Real.sqrt B) * ∫ r in (0 : ℝ)..d, b r) := by + let F (s : ℝ) := semigroup J s (fun y => Real.exp (θ * semigroup J (d - s) f y)) x + let F' (s : ℝ) := semigroup J s (expDrift J θ (semigroup J (d - s) f)) x + let K := 2 * θ ^ 2 * Real.exp (2 * |θ| * Real.sqrt B) + have hFpos (s : ℝ) (hs : 0 ≤ s) : 0 < F s := + semigroup_pos J s hs (fun y => Real.exp_pos _) x + have hFderiv (s : ℝ) : HasDerivAt F (F' s) s := + hasDerivAt_pi.mp (interpolated_exp_hasDerivAt J f θ d s) x + have hlog (s : ℝ) (hs : s ∈ Set.Icc (0 : ℝ) d) : + HasDerivAt (fun r => Real.log (F r)) (F' s / F s) s := + (hFderiv s).log (hFpos s hs.1).ne' + have hcont : ContinuousOn (fun s => F' s / F s) (Set.uIcc (0 : ℝ) d) := by + apply (interpolated_expDrift_continuous J f θ d x).continuousOn.div + (interpolated_exp_continuous J f θ d x).continuousOn + intro s hs + have hs' : s ∈ Set.Icc (0 : ℝ) d := by simpa only [Set.uIcc_of_le hd] using hs + exact (hFpos s hs'.1).ne' + have hI : Real.log (F d) - Real.log (F 0) = + ∫ s in (0 : ℝ)..d, F' s / F s := by + symm + apply intervalIntegral.integral_eq_sub_of_hasDerivAt _ hcont.intervalIntegrable + intro s hs + exact hlog s (by simpa only [Set.uIcc_of_le hd] using hs) + have hbr : IntervalIntegrable (fun s => b (d - s)) MeasureTheory.volume 0 d := by + simpa only [sub_self, sub_zero] using (hb.comp_sub_left d).symm + have hle : Real.log (F d) - Real.log (F 0) ≤ K * ∫ r in (0 : ℝ)..d, b r := by + rw [hI] + calc + _ ≤ ∫ s in (0 : ℝ)..d, K * b (d - s) := by + apply intervalIntegral.integral_mono_on hd hcont.intervalIntegrable (hbr.const_mul K) + intro s hs + apply (div_le_iff₀ (hFpos s hs.1)).mpr + have hr : d - s ∈ Set.Icc (0 : ℝ) d := ⟨sub_nonneg.mpr hs.2, by linarith [hs.1]⟩ + have hp := semigroup_mono J hs.1 _ _ + (fun y => expDrift_le J θ (semigroup J (d - s) f) y B (b (d - s)) + ((hbound (d - s) hr y).trans (hB (d - s) hr)) (hbound (d - s) hr y)) x + change F' s ≤ semigroup J s ((K * b (d - s)) • + (fun y => Real.exp (θ * semigroup J (d - s) f y))) x at hp + simpa only [map_smul, Pi.smul_apply, smul_eq_mul] using hp + _ = _ := by + rw [intervalIntegral.integral_const_mul, intervalIntegral.integral_comp_sub_left] + simp only [sub_self, sub_zero] + have hF0 : F 0 = Real.exp (θ * semigroup J d f x) := by + dsimp [F] + rw [sub_zero, semigroup_zero, one_apply_eq_self] + have hFd : F d = semigroup J d (fun y => Real.exp (θ * f y)) x := by + simp only [F, sub_self, semigroup_zero, one_apply_eq_self] + rw [hF0, Real.log_exp] at hle + have hle' := (Real.log_le_iff_le_exp (hFpos d hd)).mp (sub_le_iff_le_add.mp hle) + have hfactor : (fun y => Real.exp (θ * (f y - semigroup J d f x))) = + Real.exp (-(θ * semigroup J d f x)) • (fun y => Real.exp (θ * f y)) := by + funext y + simp only [Pi.smul_apply, smul_eq_mul, mul_sub, Real.exp_sub, Real.exp_neg] + ring + rw [hfactor, map_smul, Pi.smul_apply, smul_eq_mul] + calc + _ ≤ Real.exp (-(θ * semigroup J d f x)) * + Real.exp (K * (∫ r in (0 : ℝ)..d, b r) + θ * semigroup J d f x) := + mul_le_mul_of_nonneg_left (by rwa [hFd] at hle') (Real.exp_pos _).le + _ = _ := by rw [← Real.exp_add]; congr 1; dsimp [K]; ring + +end SKRatio.Calculus + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Dynamics/GaussMoment.lean b/lean/OAI/Probability/SKRatio/Dynamics/GaussMoment.lean new file mode 100644 index 0000000000000000000000000000000000000000..d35d27f9a0ce8099b4c4167830ab15dbd5906b4f --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Dynamics/GaussMoment.lean @@ -0,0 +1,406 @@ +import Mathlib + +namespace OAI + +section +noncomputable section +open scoped BigOperators +open Filter MeasureTheory ProbabilityTheory +open scoped Topology NNReal ENNReal +open Filter MeasureTheory ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter +open scoped Topology NNReal ENNReal +namespace SKRatioClock.Clock + +noncomputable def gaussMoment (a : ℝ) (k : ℕ) (x : ℝ) : ℝ := + x^k*Real.exp (-a*x^2) + +lemma integrable_gaussMoment {a : ℝ} (ha : 0 < a) (k : ℕ) : + Integrable (gaussMoment a k) := by + have hk : (-1:ℝ) < (k:ℝ) := by have := (Nat.cast_nonneg k : (0:ℝ)≤k); linarith + have hh := integrable_rpow_mul_exp_neg_mul_sq ha hk + convert! hh using 1 + ext x + exact (Real.rpow_natCast x k).symm |> congrArg (fun t => t*Real.exp (-a*x^2)) + +lemma hasDerivAt_gaussMoment (a : ℝ) (k : ℕ) (x : ℝ) : + HasDerivAt (gaussMoment a k) + ((k:ℝ)*gaussMoment a (k-1) x-2*a*gaussMoment a (k+1) x) x := by + have he := ((((hasDerivAt_id x).pow 2).const_mul (-a)).exp) + convert! ((hasDerivAt_id x).pow k).mul he using 1 + simp only [gaussMoment,pow_succ,Pi.pow_apply,id_eq,Nat.cast_ofNat,mul_one,pow_zero] + ring + +lemma integrable_abs_add_one_pow_gauss {a : ℝ} (ha : 0 < a) (k : ℕ) : + Integrable (fun x : ℝ => (|x|+1)^k*Real.exp (-a*x^2)) := by + have hi (j : ℕ) : Integrable (fun x : ℝ => |x|^j*Real.exp (-a*x^2)) := by + simpa only [gaussMoment,Real.norm_eq_abs,abs_mul,abs_pow, + abs_of_nonneg (Real.exp_nonneg _)] using (integrable_gaussMoment ha j).norm + have hh := integrable_finsetSum (Finset.range (k+1)) + (fun j _ => (hi j).mul_const (k.choose j:ℝ)) + convert! hh using 1 + ext x + rw [add_pow,Finset.sum_mul] + apply Finset.sum_congr rfl + intro j hj + simp only [one_pow,mul_one] + ring + +noncomputable def momentEnvelope (a : ℝ) (k : ℕ) (x : ℝ) : ℝ := + ((k:ℝ)*(|x|+1)^(k-1)+2*a*(|x|+1)^(k+1))*Real.exp a*Real.exp (-(a/2)*x^2) + +lemma integrable_momentEnvelope {a : ℝ} (ha : 0 < a) (k : ℕ) : + Integrable (momentEnvelope a k) := by + have hhalf : 0 < a/2 := by positivity + have hh := (((integrable_abs_add_one_pow_gauss hhalf (k-1)).const_mul (k:ℝ)).add + ((integrable_abs_add_one_pow_gauss hhalf (k+1)).const_mul (2*a))).const_mul (Real.exp a) + convert! hh using 1 + ext x + simp only [momentEnvelope,Pi.add_apply] + ring + +lemma gaussMoment_deriv_bound {a : ℝ} (ha : 0 < a) (k : ℕ) (x z : ℝ) + (hz : z ∈ Set.Icc (x-1) (x+1)) : + |(k:ℝ)*gaussMoment a (k-1) z-2*a*gaussMoment a (k+1) z| ≤ + momentEnvelope a k x := by + have hdist : |z-x| ≤ 1 := abs_le.mpr ⟨by linarith [hz.1],by linarith [hz.2]⟩ + have hzabs : |z| ≤ |x|+1 := by + calc + |z| = |(z-x)+x| := by rw [sub_add_cancel] + _ ≤ |z-x|+|x| := abs_add_le _ _ + _ ≤ |x|+1 := by linarith + have hsq : (z-x)^2 ≤ 1 := by + have hh := mul_self_le_mul_self (abs_nonneg (z-x)) hdist + nlinarith [sq_abs (z-x)] + have hquad : x^2/2-1 ≤ z^2 := by nlinarith [sq_nonneg (x-2*z)] + have he : Real.exp (-a*z^2) ≤ Real.exp a*Real.exp (-(a/2)*x^2) := by + rw [← Real.exp_add] + apply Real.exp_le_exp.mpr + nlinarith [mul_nonneg ha.le (sub_nonneg.mpr hquad)] + have h1 := pow_le_pow_left₀ (abs_nonneg z) hzabs (k-1) + have h2 := pow_le_pow_left₀ (abs_nonneg z) hzabs (k+1) + calc + _ ≤ |(k:ℝ)*gaussMoment a (k-1) z|+|2*a*gaussMoment a (k+1) z| := by + simpa only [Real.norm_eq_abs] using norm_sub_le + ((k:ℝ)*gaussMoment a (k-1) z) (2*a*gaussMoment a (k+1) z) + _ = ((k:ℝ)*|z|^(k-1)+2*a*|z|^(k+1))*Real.exp (-a*z^2) := by + norm_num only [gaussMoment,abs_mul,abs_pow,abs_of_nonneg (Nat.cast_nonneg k : (0:ℝ)≤k), + abs_of_nonneg ha.le,abs_of_nonneg (Real.exp_nonneg _)] + ring + _ ≤ ((k:ℝ)*(|x|+1)^(k-1)+2*a*(|x|+1)^(k+1))* + (Real.exp a*Real.exp (-(a/2)*x^2)) := by + apply mul_le_mul _ he (Real.exp_nonneg _) (by positivity) + exact add_le_add (mul_le_mul_of_nonneg_left h1 (Nat.cast_nonneg _)) + (mul_le_mul_of_nonneg_left h2 (by positivity)) + _ = _ := by dsimp [momentEnvelope]; ring + +noncomputable def diffMoment (a : ℝ) (k : ℕ) (h x : ℝ) : ℝ := + (gaussMoment a k (x+h)-gaussMoment a k x)/h + +lemma diffMoment_bound {a : ℝ} (ha : 0 < a) (k : ℕ) {h : ℝ} + (hh : 0 < h) (hh1 : h ≤ 1) (x : ℝ) : + |diffMoment a k h x| ≤ momentEnvelope a k x := by + have hmv := Convex.norm_image_sub_le_of_norm_hasDerivWithin_le + (s := Set.Icc (x-1) (x+1)) + (f := gaussMoment a k) + (f' := fun z => (k:ℝ)*gaussMoment a (k-1) z-2*a*gaussMoment a (k+1) z) + (fun z _ => (hasDerivAt_gaussMoment a k z).hasDerivWithinAt) + (fun z hz => by simpa only [Real.norm_eq_abs] using gaussMoment_deriv_bound ha k x z hz) + (convex_Icc _ _) (show x ∈ Set.Icc (x-1) (x+1) from ⟨by linarith,by linarith⟩) + (show x+h ∈ Set.Icc (x-1) (x+1) from ⟨by linarith,by linarith⟩) + rw [Real.norm_eq_abs,Real.norm_eq_abs,add_sub_cancel_left,abs_of_pos hh] at hmv + unfold diffMoment + rw [abs_div,abs_of_pos hh] + exact (div_le_iff₀ hh).mpr hmv + +lemma integrable_diffMoment {a : ℝ} (ha : 0 < a) (k : ℕ) (h : ℝ) : + Integrable (diffMoment a k h) := + (((integrable_gaussMoment ha k).comp_add_right h).sub + (integrable_gaussMoment ha k)).div_const h + +lemma gaussMoment_derivative_L1 {a : ℝ} (ha : 0 < a) (k : ℕ) : + Tendsto (fun n : ℕ => ∫ x : ℝ, + |diffMoment a k (1/((n:ℝ)+1)) x- + ((k:ℝ)*gaussMoment a (k-1) x-2*a*gaussMoment a (k+1) x)|) + atTop (𝓝 0) := by + let dg : ℝ → ℝ := fun x => (k:ℝ)*gaussMoment a (k-1) x-2*a*gaussMoment a (k+1) x + have hdg : Integrable dg := ((integrable_gaussMoment ha (k-1)).const_mul (k:ℝ)).sub + ((integrable_gaussMoment ha (k+1)).const_mul (2*a)) + have hstep : Tendsto (fun n : ℕ => 1/((n:ℝ)+1)) atTop (𝓝[≠] (0:ℝ)) := by + refine tendsto_nhdsWithin_iff.mpr ⟨tendsto_one_div_add_atTop_nhds_zero_nat, ?_⟩ + exact Filter.Eventually.of_forall (fun n => by + simp only [Set.mem_compl_iff,Set.mem_singleton_iff] + exact ne_of_gt (by positivity)) + have hp (x : ℝ) : Tendsto (fun n : ℕ => diffMoment a k (1/((n:ℝ)+1)) x) + atTop (𝓝 (dg x)) := by + have hh := (hasDerivAt_gaussMoment a k x).tendsto_slope_zero.comp hstep + simpa only [Function.comp_def,smul_eq_mul,div_eq_mul_inv,mul_comm,diffMoment,dg] using hh + have ht := tendsto_integral_of_dominated_convergence + (fun x => momentEnvelope a k x+|dg x|) + (F := fun n : ℕ => fun x => |diffMoment a k (1/((n:ℝ)+1)) x-dg x|) + (f := fun _ => (0:ℝ)) + (fun n => ((integrable_diffMoment ha k _).sub hdg).abs.aestronglyMeasurable) + ((integrable_momentEnvelope ha k).add hdg.abs) + (fun n => Filter.Eventually.of_forall (fun x => by + rw [Real.norm_eq_abs,abs_abs] + have htri : |diffMoment a k (1/((n:ℝ)+1)) x-dg x| ≤ + |diffMoment a k (1/((n:ℝ)+1)) x|+|dg x| := by + simpa only [Real.norm_eq_abs] using + norm_sub_le (diffMoment a k (1/((n:ℝ)+1)) x) (dg x) + exact htri.trans (add_le_add (diffMoment_bound ha k (h := 1/((n:ℝ)+1)) (by positivity) + (by have := (Nat.cast_nonneg n : (0:ℝ)≤n); apply (div_le_one (by positivity)).mpr; linarith) x) le_rfl))) + (Filter.Eventually.of_forall (fun x => by simpa using ((hp x).sub_const (dg x)).abs)) + simpa only [integral_zero] using ht + +noncomputable def momentL1 (a : ℝ) (ha : 0 < a) (k : ℕ) (y : ℝ) : Lp ℝ 1 (volume : Measure ℝ) := + Integrable.toL1 (fun x : ℝ => gaussMoment a k (x+y)) + ((integrable_gaussMoment ha k).comp_add_right y) + +lemma norm_toL1_real {f : ℝ → ℝ} (hf : Integrable f) : + ‖hf.toL1 f‖ = ∫ x : ℝ, |f x| := by + rw [Integrable.norm_toL1_eq_lintegral_enorm, + ← integral_norm_eq_lintegral_enorm hf.aestronglyMeasurable] + simp only [Real.norm_eq_abs] + +lemma momentL1_derivative {a : ℝ} (ha : 0 < a) (k : ℕ) (y : ℝ) : + Tendsto (fun n : ℕ => ((1/((n:ℝ)+1))⁻¹) • + (momentL1 a ha k (y+1/((n:ℝ)+1))-momentL1 a ha k y)) atTop + (𝓝 ((k:ℝ) • momentL1 a ha (k-1) y-(2*a) • momentL1 a ha (k+1) y)) := by + apply tendsto_iff_norm_sub_tendsto_zero.mpr + have he (n : ℕ) : + ‖((1/((n:ℝ)+1))⁻¹) • (momentL1 a ha k (y+1/((n:ℝ)+1))- + momentL1 a ha k y)-((k:ℝ) • momentL1 a ha (k-1) y- + (2*a) • momentL1 a ha (k+1) y)‖ = + ∫ x : ℝ, |diffMoment a k (1/((n:ℝ)+1)) x- + ((k:ℝ)*gaussMoment a (k-1) x-2*a*gaussMoment a (k+1) x)| := by + let h : ℝ := 1/((n:ℝ)+1) + let f : ℝ → ℝ := fun x => h⁻¹ * (gaussMoment a k (x+(y+h))- + gaussMoment a k (x+y))- + ((k:ℝ)*gaussMoment a (k-1) (x+y)-(2*a)*gaussMoment a (k+1) (x+y)) + have hf : Integrable f := + ((((integrable_gaussMoment ha k).comp_add_right (y+h)).sub + ((integrable_gaussMoment ha k).comp_add_right y)).const_mul h⁻¹).sub + ((((integrable_gaussMoment ha (k-1)).comp_add_right y).const_mul (k:ℝ)).sub + (((integrable_gaussMoment ha (k+1)).comp_add_right y).const_mul (2*a))) + change ‖hf.toL1 f‖ = _ + rw [norm_toL1_real] + have hfun : (fun x => |f x|) = fun x => |diffMoment a k h (x+y)- + ((k:ℝ)*gaussMoment a (k-1) (x+y)-2*a*gaussMoment a (k+1) (x+y))| := by + funext x + simp only [f,diffMoment,add_assoc,div_eq_mul_inv,mul_comm] + rw [hfun] + exact integral_add_right_eq_self (fun x => |diffMoment a k h x- + ((k:ℝ)*gaussMoment a (k-1) x-2*a*gaussMoment a (k+1) x)|) y + simp_rw [he] + exact gaussMoment_derivative_L1 ha k + +lemma momentL1_mem_of_gaussian {a : ℝ} (ha : 0 < a) + (S : Submodule ℝ (Lp ℝ 1 (volume : Measure ℝ))) (hS : IsClosed (S : Set (Lp ℝ 1 (volume : Measure ℝ)))) + (hbase : ∀ y, momentL1 a ha 0 y ∈ S) : + ∀ k y, momentL1 a ha k y ∈ S := by + intro k + induction k using Nat.strong_induction_on with + | h k ih => + intro y + cases k with + | zero => exact hbase y + | succ k => + have hder : (k:ℝ) • momentL1 a ha (k-1) y- + (2*a) • momentL1 a ha (k+1) y ∈ S := + hS.mem_of_tendsto (momentL1_derivative ha k y) + (Filter.Eventually.of_forall (fun n => S.smul_mem _ + (S.sub_mem (ih k (by omega) _) (ih k (by omega) _)))) + have hlow : (k:ℝ) • momentL1 a ha (k-1) y ∈ S := + S.smul_mem _ (ih (k-1) (by omega) y) + have hhigh := S.sub_mem hlow hder + rw [sub_sub_cancel] at hhigh + have hn : (2*a) ≠ 0 := ne_of_gt (by positivity) + have hh := S.smul_mem (2*a)⁻¹ hhigh + simpa only [smul_smul,inv_mul_cancel₀ hn,one_smul] using hh + +noncomputable def gaussianTaylor (a c : ℝ) (N : ℕ) (x : ℝ) : ℝ := + ∑ k ∈ Finset.range N, ((-c)^k/(Nat.factorial k : ℝ))*gaussMoment a (2*k) x + +lemma gaussianTaylor_eq (a c : ℝ) (N : ℕ) (x : ℝ) : + gaussianTaylor a c N x = + (∑ k ∈ Finset.range N, (-c*x^2)^k/(Nat.factorial k : ℝ))*Real.exp (-a*x^2) := by + unfold gaussianTaylor gaussMoment + rw [Finset.sum_mul] + apply Finset.sum_congr rfl + intro k _ + rw [mul_pow,← pow_mul] + ring + +lemma gaussianTaylor_bound (a : ℝ) {c : ℝ} (hc : 0 ≤ c) (N : ℕ) (x : ℝ) : + |gaussianTaylor a c N x| ≤ Real.exp (-(a-c)*x^2) := by + rw [gaussianTaylor_eq,abs_mul,abs_of_pos (Real.exp_pos _)] + have habs : |∑ k ∈ Finset.range N, (-c*x^2)^k/(Nat.factorial k : ℝ)| ≤ + ∑ k ∈ Finset.range N, (c*x^2)^k/(Nat.factorial k : ℝ) := by + calc + _ ≤ ∑ k ∈ Finset.range N, |(-c*x^2)^k/(Nat.factorial k : ℝ)| := + Finset.abs_sum_le_sum_abs _ _ + _ = _ := by + apply Finset.sum_congr rfl + intro k _ + rw [abs_div,abs_pow,abs_mul,abs_neg,abs_of_nonneg hc, + abs_of_nonneg (sq_nonneg x),abs_of_nonneg (Nat.cast_nonneg _)] + calc + _ ≤ Real.exp (c*x^2)*Real.exp (-a*x^2) := + mul_le_mul_of_nonneg_right (habs.trans (Real.sum_le_exp_of_nonneg (by positivity) N)) + (Real.exp_nonneg _) + _ = _ := by rw [← Real.exp_add]; congr 1; ring + +lemma integrable_gaussianTaylor {a : ℝ} (ha : 0 < a) (c : ℝ) (N : ℕ) : + Integrable (gaussianTaylor a c N) := + integrable_finsetSum _ (fun k _ => (integrable_gaussMoment ha (2*k)).const_mul _) + +lemma gaussianTaylor_tendsto (a c x : ℝ) : + Tendsto (fun N : ℕ => gaussianTaylor a c N x) atTop (𝓝 (gaussMoment (a+c) 0 x)) := by + have ht := (NormedSpace.expSeries_div_hasSum_exp (-c*x^2)).tendsto_sum_nat.mul_const + (Real.exp (-a*x^2)) + simpa only [gaussianTaylor_eq,← Real.exp_eq_exp_ℝ,← Real.exp_add,gaussMoment,pow_zero,one_mul, + show -c*x^2+-a*x^2=-(a+c)*x^2 by ring] using ht + +lemma gaussianTaylor_L1 {a c : ℝ} (ha : 0 < a) (hc : 0 ≤ c) (hca : c < a) : + Tendsto (fun N : ℕ => ∫ x : ℝ, + |gaussianTaylor a c N x-gaussMoment (a+c) 0 x|) atTop (𝓝 0) := by + have hp : 0 < a+c := by linarith + have hm : 0 < a-c := by linarith + have hh := tendsto_integral_of_dominated_convergence + (fun x => Real.exp (-(a-c)*x^2)+Real.exp (-(a+c)*x^2)) + (F := fun N : ℕ => fun x => |gaussianTaylor a c N x-gaussMoment (a+c) 0 x|) + (f := fun _ => (0:ℝ)) + (fun N => ((integrable_gaussianTaylor ha c N).sub (integrable_gaussMoment hp 0)).abs.aestronglyMeasurable) + (by simpa only [Pi.add_def,gaussMoment,pow_zero,one_mul] using + (integrable_gaussMoment hm 0).add (integrable_gaussMoment hp 0)) + (fun N => Filter.Eventually.of_forall (fun x => by + rw [Real.norm_eq_abs,abs_abs] + have htri := norm_sub_le (gaussianTaylor a c N x) (gaussMoment (a+c) 0 x) + simp only [Real.norm_eq_abs,gaussMoment,pow_zero,one_mul,abs_of_pos (Real.exp_pos _)] at htri + simpa only [gaussMoment,pow_zero,one_mul] using + htri.trans (add_le_add (gaussianTaylor_bound a hc N x) le_rfl))) + (Filter.Eventually.of_forall (fun x => by + simpa using ((gaussianTaylor_tendsto a c x).sub_const (gaussMoment (a+c) 0 x)).abs)) + simpa only [integral_zero] using hh + +lemma toL1_finsetSum {ι : Type*} (s : Finset ι) (f : ι → ℝ → ℝ) + (hf : ∀ i, Integrable (f i)) : + (integrable_finsetSum s (fun i _ => hf i)).toL1 (fun x => ∑ i ∈ s, f i x) = + ∑ i ∈ s, (hf i).toL1 (f i) := by + classical + induction s using Finset.induction_on with + | empty => + simp only [Finset.sum_empty] + exact Integrable.toL1_zero _ + | @insert i s hi ih => + simp only [Finset.sum_insert hi] + change (((hf i).add (integrable_finsetSum s (fun j _ => hf j))).toL1 + (f i+(fun x => ∑ j ∈ s, f j x))) = _ + rw [Integrable.toL1_add _ _ (hf i) + (integrable_finsetSum s (fun j _ => hf j)),ih] + +lemma toL1_tendsto_of_integral_abs_sub {f : ℕ → ℝ → ℝ} {g : ℝ → ℝ} + (hf : ∀ n, Integrable (f n)) (hg : Integrable g) + (ht : Tendsto (fun n => ∫ x : ℝ, |f n x-g x|) atTop (𝓝 0)) : + Tendsto (fun n => (hf n).toL1 (f n)) atTop (𝓝 (hg.toL1 g)) := by + apply tendsto_iff_norm_sub_tendsto_zero.mpr + have he (n : ℕ) : ‖(hf n).toL1 (f n)-hg.toL1 g‖ = ∫ x : ℝ, |f n x-g x| := by + change ‖((hf n).sub hg).toL1 (f n-g)‖ = _ + exact norm_toL1_real _ + simpa only [he] using ht + +lemma gaussian_increment_mem {a c : ℝ} (ha : 0 < a) (hc : 0 ≤ c) (hca : c < a) + (S : Submodule ℝ (Lp ℝ 1 (volume : Measure ℝ))) + (hS : IsClosed (S : Set (Lp ℝ 1 (volume : Measure ℝ)))) + (hbase : ∀ y, momentL1 a ha 0 y ∈ S) : + ∀ y, momentL1 (a+c) (by linarith) 0 y ∈ S := by + intro y + have hm := momentL1_mem_of_gaussian ha S hS hbase + let fp : ℕ → ℝ → ℝ := fun N x => gaussianTaylor a c N (x+y) + have hfp (N : ℕ) : Integrable (fp N) := (integrable_gaussianTaylor ha c N).comp_add_right y + have hin (N : ℕ) : (hfp N).toL1 (fp N) ∈ S := by + have he : (hfp N).toL1 (fp N) = + ∑ k ∈ Finset.range N, ((-c)^k/(Nat.factorial k:ℝ)) • momentL1 a ha (2*k) y := by + exact toL1_finsetSum (Finset.range N) + (fun k x => ((-c)^k/(Nat.factorial k:ℝ))*gaussMoment a (2*k) (x+y)) + (fun k => ((integrable_gaussMoment ha (2*k)).comp_add_right y).const_mul _) + rw [he] + exact S.sum_mem (fun k _ => S.smul_mem _ (hm _ y)) + have ht : Tendsto (fun N => ∫ x : ℝ, + |fp N x-gaussMoment (a+c) 0 (x+y)|) atTop (𝓝 0) := by + have he (N : ℕ) : (∫ x : ℝ, |fp N x-gaussMoment (a+c) 0 (x+y)|) = + ∫ x : ℝ, |gaussianTaylor a c N x-gaussMoment (a+c) 0 x| := + integral_add_right_eq_self (fun x => |gaussianTaylor a c N x-gaussMoment (a+c) 0 x|) y + simpa only [he] using gaussianTaylor_L1 ha hc hca + exact hS.mem_of_tendsto (toL1_tendsto_of_integral_abs_sub hfp + ((integrable_gaussMoment (by linarith : 0 < a+c) 0).comp_add_right y) ht) + (Filter.Eventually.of_forall hin) + +lemma gaussian_wider_precision_mem {a b : ℝ} (ha : 0 < a) (hab : a ≤ b) + (S : Submodule ℝ (Lp ℝ 1 (volume : Measure ℝ))) + (hS : IsClosed (S : Set (Lp ℝ 1 (volume : Measure ℝ)))) + (hbase : ∀ y, momentL1 a ha 0 y ∈ S) : + ∀ y, momentL1 b (ha.trans_le hab) 0 y ∈ S := by + obtain ⟨N,hN⟩ := exists_nat_gt ((b-a)/a+1) + have hN0 : (0:ℝ) < N := by + have : 0 ≤ (b-a)/a := div_nonneg (sub_nonneg.mpr hab) ha.le + linarith + let c : ℝ := (b-a)/N + have hc : 0 ≤ c := div_nonneg (sub_nonneg.mpr hab) hN0.le + have hca : c < a := by + apply (div_lt_iff₀ hN0).mpr + have : (b-a)/a < (N:ℝ) := by linarith + have := (div_lt_iff₀ ha).mp this + linarith + have hall (n : ℕ) : ∀ y, momentL1 (a+(n:ℝ)*c) (by positivity) 0 y ∈ S := by + induction n with + | zero => simpa only [Nat.cast_zero,zero_mul,add_zero] using hbase + | succ n ih => + have hh := gaussian_increment_mem (show 0 < a+(n:ℝ)*c by positivity) hc + (show c < a+(n:ℝ)*c by have := mul_nonneg (Nat.cast_nonneg n) hc; linarith) S hS ih + have he : a+(↑(n+1):ℝ)*c=(a+(n:ℝ)*c)+c := by push_cast; ring + simpa only [he] using hh + have he : a+(N:ℝ)*c = b := by dsimp [c]; field_simp [ne_of_gt hN0]; ring + simpa only [he] using hall N + +lemma gaussian_mem_closed_span {a b : ℝ} (ha : 0 < a) (hab : a ≤ b) (y : ℝ) : + momentL1 b (ha.trans_le hab) 0 y ∈ + (Submodule.span ℝ (Set.range (momentL1 a ha 0))).topologicalClosure := by + apply gaussian_wider_precision_mem ha hab _ + (Submodule.isClosed_topologicalClosure _) (fun z => ?_) y + exact Submodule.le_topologicalClosure _ (Submodule.subset_span ⟨z,rfl⟩) + +theorem finite_gaussian_approximation {a b ε : ℝ} (ha : 0 < a) (hab : a ≤ b) + (hε : 0 < ε) : + ∃ (s : Finset ℝ) (c : ℝ → ℝ), + (∫ x : ℝ, |gaussMoment b 0 x- + ∑ y ∈ s, c y*gaussMoment a 0 (x+y)|) < ε := by + classical + have hm := gaussian_mem_closed_span ha hab 0 + change momentL1 b (ha.trans_le hab) 0 0 ∈ + closure (↑(Submodule.span ℝ (Set.range (momentL1 a ha 0))) : Set _) at hm + obtain ⟨w,hw,hclose⟩ := Metric.mem_closure_iff.mp hm ε hε + obtain ⟨c,rfl⟩ := Finsupp.mem_span_range_iff_exists_finsupp.mp hw + refine ⟨c.support,c,?_⟩ + let f : ℝ → ℝ := fun x => ∑ y ∈ c.support, c y*gaussMoment a 0 (x+y) + have hf : Integrable f := integrable_finsetSum _ (fun y _ => + ((integrable_gaussMoment ha 0).comp_add_right y).const_mul (c y)) + have hfL : hf.toL1 f = c.sum (fun y z => z • momentL1 a ha 0 y) := + toL1_finsetSum c.support (fun y x => c y*gaussMoment a 0 (x+y)) + (fun y => ((integrable_gaussMoment ha 0).comp_add_right y).const_mul (c y)) + rw [dist_eq_norm,← hfL] at hclose + change ‖((((integrable_gaussMoment (ha.trans_le hab) 0).comp_add_right 0).sub hf).toL1 + (fun x => gaussMoment b 0 (x+0)-f x))‖ < ε at hclose + rw [norm_toL1_real] at hclose + simpa only [add_zero] using hclose + +end SKRatioClock.Clock + +open MeasureTheory Filter ProbabilityTheory +open scoped Topology NNReal ENNReal + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Dynamics/GaussianPDFMoment.lean b/lean/OAI/Probability/SKRatio/Dynamics/GaussianPDFMoment.lean new file mode 100644 index 0000000000000000000000000000000000000000..d998ec0a6faebe975aef21563a128e999fe7cc34 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Dynamics/GaussianPDFMoment.lean @@ -0,0 +1,68 @@ +import Mathlib +import OAI.Probability.SKRatio.Dynamics.GaussMoment + +namespace OAI + +section +noncomputable section +open scoped BigOperators +open Filter MeasureTheory ProbabilityTheory +open scoped Topology NNReal ENNReal +open Filter MeasureTheory ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter +open scoped Topology NNReal ENNReal +open MeasureTheory Filter ProbabilityTheory +open scoped Topology NNReal ENNReal +namespace SKRatioClock.Clock + +lemma gaussianPDF_moment (v : ℝ≥0) (y x : ℝ) : + gaussianPDFReal y v x = (Real.sqrt (2*Real.pi*v))⁻¹ * + gaussMoment (1/(2*(v:ℝ))) 0 (x-y) := by + unfold gaussianPDFReal gaussMoment + simp only [pow_zero,one_mul] + congr 2 + ring + +theorem finite_gaussianPDF_approximation {v w : ℝ≥0} (hv : 0 < v) (hw : 0 < w) + (hwv : w ≤ v) {ε : ℝ} (hε : 0 < ε) : + ∃ (s : Finset ℝ) (c : ℝ → ℝ), + (∫ x : ℝ, |gaussianPDFReal 0 w x- + ∑ y ∈ s, c y*gaussianPDFReal (-y) v x|) < ε := by + have hvR : (0:ℝ) < v := hv + have hwR : (0:ℝ) < w := hw + let kv : ℝ := (Real.sqrt (2*Real.pi*v))⁻¹ + let kw : ℝ := (Real.sqrt (2*Real.pi*w))⁻¹ + have hkv : 0 < kv := by dsimp [kv]; positivity + have hkw : 0 < kw := by dsimp [kw]; positivity + have hra : 0 < 1/(2*(v:ℝ)) := by positivity + have hrab : 1/(2*(v:ℝ)) ≤ 1/(2*(w:ℝ)) := by + apply one_div_le_one_div_of_le (by positivity) + exact mul_le_mul_of_nonneg_left (show (w:ℝ) ≤ v from hwv) (by norm_num) + obtain ⟨s,c,hc⟩ := finite_gaussian_approximation hra hrab (show 0 < ε/kw by positivity) + refine ⟨s,fun y => kw*c y/kv,?_⟩ + have he (x : ℝ) : |gaussianPDFReal 0 w x- + ∑ y ∈ s, (kw*c y/kv)*gaussianPDFReal (-y) v x| = + kw*|gaussMoment (1/(2*(w:ℝ))) 0 x- + ∑ y ∈ s, c y*gaussMoment (1/(2*(v:ℝ))) 0 (x+y)| := by + simp only [gaussianPDF_moment,sub_zero,sub_neg_eq_add] + change |kw*gaussMoment (1/(2*(w:ℝ))) 0 x- + ∑ y ∈ s, (kw*c y/kv)*(kv*gaussMoment (1/(2*(v:ℝ))) 0 (x+y))| = _ + have hterm (y : ℝ) : (kw*c y/kv)*(kv*gaussMoment (1/(2*(v:ℝ))) 0 (x+y)) = + kw*(c y*gaussMoment (1/(2*(v:ℝ))) 0 (x+y)) := by field_simp + simp_rw [hterm] + rw [← Finset.mul_sum,← mul_sub,abs_mul,abs_of_pos hkw] + simp_rw [he] + rw [integral_const_mul] + have hh := mul_lt_mul_of_pos_left hc hkw + rwa [mul_div_cancel₀ _ hkw.ne'] at hh + +end SKRatioClock.Clock + +open MeasureTheory Filter +open scoped Topology + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Dynamics/IntegrableMulBounded.lean b/lean/OAI/Probability/SKRatio/Dynamics/IntegrableMulBounded.lean new file mode 100644 index 0000000000000000000000000000000000000000..25410159200a26d66852f713fe70b97b83975076 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Dynamics/IntegrableMulBounded.lean @@ -0,0 +1,99 @@ +import Mathlib + +namespace OAI + +section +noncomputable section +open scoped BigOperators +open Filter MeasureTheory ProbabilityTheory +open scoped Topology NNReal ENNReal +open Filter MeasureTheory ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter +open scoped Topology NNReal ENNReal +open MeasureTheory Filter ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter +open scoped Topology +namespace SKRatioClock.Clock + +lemma integrable_mul_bounded {f u : ℝ → ℝ} {B : ℝ} (hf : Integrable f) + (hu : AEStronglyMeasurable u) (hb : ∀ x, |u x| ≤ B) : Integrable (fun x => f x*u x) := by + apply (hf.abs.mul_const B).mono' (hf.aestronglyMeasurable.mul hu) + exact Filter.Eventually.of_forall (fun x => by + simpa only [Real.norm_eq_abs,Pi.mul_apply,abs_mul] using mul_le_mul_of_nonneg_left (hb x) (abs_nonneg (f x))) + +lemma pairing_abs_le {f u : ℝ → ℝ} {B : ℝ} (hf : Integrable f) + (hu : AEStronglyMeasurable u) (hb : ∀ x, |u x| ≤ B) : + |∫ x : ℝ, f x*u x| ≤ B*(∫ x : ℝ, |f x|) := by + calc + _ ≤ ∫ x : ℝ, |f x*u x| := abs_integral_le_integral_abs + _ ≤ ∫ x : ℝ, |f x| * B := integral_mono (integrable_mul_bounded hf hu hb).abs + (hf.abs.mul_const B) (fun x => by rw [abs_mul]; exact mul_le_mul_of_nonneg_left (hb x) (abs_nonneg _)) + _ = _ := by rw [integral_mul_const]; ring + +lemma pairing_sub_abs_le {f g u : ℝ → ℝ} {B : ℝ} + (hf : Integrable f) (hg : Integrable g) (hu : AEStronglyMeasurable u) + (hb : ∀ x, |u x| ≤ B) : + |(∫ x : ℝ, f x*u x)-(∫ x : ℝ, g x*u x)| ≤ B*(∫ x : ℝ, |f x-g x|) := by + rw [← integral_sub (integrable_mul_bounded hf hu hb) (integrable_mul_bounded hg hu hb)] + simpa only [Pi.sub_apply,sub_mul] using pairing_abs_le (hf.sub hg) hu hb + +lemma pairing_of_L1_limit {f : ℕ → ℝ → ℝ} {g : ℝ → ℝ} {u : ℕ → ℝ → ℝ} {B : ℝ} + (hf : ∀ᶠ n in atTop, Integrable (f n)) (hg : Integrable g) + (hu : ∀ n, AEStronglyMeasurable (u n)) (hb : ∀ n x, |u n x| ≤ B) + (ht : Tendsto (fun n => ∫ x : ℝ, |f n x-g x|) atTop (𝓝 0)) : + Tendsto (fun n => (∫ x : ℝ, f n x*u n x)-(∫ x : ℝ, g x*u n x)) atTop (𝓝 0) := by + apply squeeze_zero_norm' _ (by simpa using ht.const_mul B) + filter_upwards [hf] with n hn + simpa only [Real.norm_eq_abs] using pairing_sub_abs_le hn hg (hu n) (hb n) + +theorem pairing_of_finite_approximation {ρ : ℝ → ℝ} {φ : ℝ → ℝ → ℝ} + {u : ℕ → ℝ → ℝ} {B : ℝ} + (hρ : Integrable ρ) (hφ : ∀ y, Integrable (φ y)) (hB : 0 < B) + (hu : ∀ n, AEStronglyMeasurable (u n)) (hb : ∀ n x, |u n x| ≤ B) + (ha : ∀ ε : ℝ, 0 < ε → ∃ (s : Finset ℝ) (c : ℝ → ℝ), + (∫ x : ℝ, |ρ x-∑ y ∈ s, c y*φ y x|) < ε) + (ht : ∀ y, Tendsto (fun n => ∫ x : ℝ, φ y x*u n x) atTop (𝓝 0)) : + Tendsto (fun n => ∫ x : ℝ, ρ x*u n x) atTop (𝓝 0) := by + classical + apply Metric.tendsto_atTop.mpr + intro ε hε + obtain ⟨s,c,happrox⟩ := ha (ε/(2*B)) (by positivity) + let F : ℝ → ℝ := fun x => ∑ y ∈ s, c y*φ y x + have hF : Integrable F := integrable_finsetSum s (fun y _ => (hφ y).const_mul (c y)) + have hsum (n : ℕ) : (∫ x : ℝ, F x*u n x) = ∑ y ∈ s, c y*(∫ x : ℝ, φ y x*u n x) := by + unfold F + simp_rw [Finset.sum_mul,mul_assoc] + rw [integral_finsetSum s (fun y _ => (integrable_mul_bounded (hφ y) (hu n) (hb n)).const_mul (c y))] + apply Finset.sum_congr rfl + intro y _ + simp only [integral_const_mul] + have hconv : Tendsto (fun n => ∫ x : ℝ, F x*u n x) atTop (𝓝 0) := by + simp_rw [hsum] + have hh := tendsto_finsetSum s (fun y _ => (ht y).const_mul (c y)) + simpa using hh + obtain ⟨N,hN⟩ := Metric.tendsto_atTop.mp hconv (ε/2) (by positivity) + refine ⟨N,fun n hn => ?_⟩ + have hclose := pairing_sub_abs_le hρ hF (hu n) (hb n) + have hh := hN n hn + simp only [Real.dist_eq,sub_zero] at hh ⊢ + have he : B*(∫ x : ℝ, |ρ x-F x|) < ε/2 := by + have := mul_lt_mul_of_pos_left happrox hB + have he : B*(ε/(2*B))=ε/2 := by field_simp + rwa [he] at this + have htri : |∫ x : ℝ, ρ x*u n x| ≤ + |(∫ x : ℝ, ρ x*u n x)-(∫ x : ℝ, F x*u n x)|+|∫ x : ℝ, F x*u n x| := by + simpa only [Real.norm_eq_abs] using norm_le_norm_sub_add + (∫ x : ℝ, ρ x*u n x) (∫ x : ℝ, F x*u n x) + linarith + +end SKRatioClock.Clock + +open MeasureTheory Filter ProbabilityTheory +open scoped Topology NNReal ENNReal + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Dynamics/LogQuadratic.lean b/lean/OAI/Probability/SKRatio/Dynamics/LogQuadratic.lean new file mode 100644 index 0000000000000000000000000000000000000000..ec76f6933bf58efc9df9a565fe14eca1d6b4a8ad --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Dynamics/LogQuadratic.lean @@ -0,0 +1,401 @@ +import Mathlib + +namespace OAI + +section +noncomputable section +open scoped BigOperators + +open Filter MeasureTheory ProbabilityTheory +open scoped Topology NNReal ENNReal + +namespace SKRatioClock.Clock + +noncomputable def logQuadratic : ℝ → ℝ := + Function.update (fun x => (Real.log (1+x)-x)/x^2) 0 (-(1/2:ℝ)) + +lemma logQuadratic_mul_sq (x : ℝ) : + logQuadratic x*x^2 = Real.log (1+x)-x := by + classical + by_cases hx : x=0 + · subst x + simp [logQuadratic] + · simp only [logQuadratic, Function.update_of_ne hx] + exact div_mul_cancel₀ _ (pow_ne_zero 2 hx) + +lemma continuousAt_logQuadratic : ContinuousAt logQuadratic 0 := by + classical + apply continuousAt_update_same.mpr + have hdom : ∀ᶠ x : ℝ in 𝓝[≠] 0, 0 < 1+x := by + filter_upwards [(eventually_gt_nhds (by norm_num : (-1:ℝ)<0)).filter_mono nhdsWithin_le_nhds] + with x hx + linarith + have hne : ∀ᶠ x : ℝ in 𝓝[≠] 0, x ≠ 0 := self_mem_nhdsWithin + apply HasDerivAt.lhopital_zero_nhdsNE + (f' := fun x => 1/(1+x)-1) (g' := fun x => 2*x) + · filter_upwards [hdom] with x hx + exact ((hasDerivAt_id x).const_add 1 |>.log hx.ne').sub (hasDerivAt_id x) + · exact Filter.Eventually.of_forall fun x => by + convert! (hasDerivAt_id x).mul (hasDerivAt_id x) using 1 + · ext t + simp [pow_two] + · simp [two_mul] + · filter_upwards [hne] with x hx + exact mul_ne_zero (by norm_num) hx + · have h : Tendsto (fun x : ℝ => Real.log (1+x)-x) (𝓝 0) (𝓝 0) := by + have hc : ContinuousAt (fun x : ℝ => Real.log (1+x)-x) 0 := by + apply ContinuousAt.sub + · apply ContinuousAt.log + · fun_prop + · norm_num + · fun_prop + simpa using hc.tendsto + exact h.mono_left nhdsWithin_le_nhds + · have hc : ContinuousAt (fun x : ℝ => x^2) 0 := by fun_prop + simpa using hc.tendsto.mono_left nhdsWithin_le_nhds + · have ht : Tendsto (fun x : ℝ => -1/(2*(1+x))) (𝓝[≠] 0) (𝓝 (-(1/2:ℝ))) := by + have hc : ContinuousAt (fun x : ℝ => -1/(2*(1+x))) 0 := by + apply ContinuousAt.div <;> first | fun_prop | norm_num + convert hc.tendsto.mono_left nhdsWithin_le_nhds using 1; norm_num + apply ht.congr' + filter_upwards [hne,hdom] with x hx hd + field_simp + ring + +noncomputable def poissonMass (m : ℝ) (k : ℕ) : ℝ := + Real.exp (-m)*m^k/(k.factorial:ℝ) + +lemma poissonMass_stirling {m : ℝ} (hm : 0 < m) {k : ℕ} (hk : 0 < k) : + Real.sqrt k*poissonMass m k = + Real.exp ((k:ℝ)*(Real.log (m/k)-(m-k)/k))/ + (Real.sqrt 2*Stirling.stirlingSeq k) := by + have hk0 : (k:ℝ) ≠ 0 := by exact_mod_cast hk.ne' + have hkp : (0:ℝ) (m n-(k n:ℝ))/Real.sqrt (k n)) atTop (𝓝 z)) : + Tendsto (fun n => Real.sqrt (k n)*poissonMass (m n) (k n)) atTop + (𝓝 (Real.exp (-(z^2)/2)/(Real.sqrt 2*Real.sqrt Real.pi))) := by + have hkn : Tendsto (fun n => (k n:ℝ)) atTop atTop := + tendsto_natCast_atTop_atTop.comp hk + have hks : Tendsto (fun n => Real.sqrt (k n:ℝ)) atTop atTop := + Real.tendsto_sqrt_atTop.comp hkn + have hkpos : ∀ᶠ n in atTop, 0 < k n := hk.eventually (eventually_gt_atTop 0) + have hh : Tendsto (fun n => (m n-(k n:ℝ))/(k n:ℝ)) atTop (𝓝 0) := by + apply (hd.div_atTop hks).congr' + filter_upwards [hkpos] with n hn + have hn0 : (0:ℝ)≤k n := Nat.cast_nonneg _ + rw [div_div, Real.mul_self_sqrt hn0] + have hq : Tendsto (fun n => logQuadratic ((m n-(k n:ℝ))/(k n:ℝ))) atTop + (𝓝 (-(1/2:ℝ))) := by + have h := continuousAt_logQuadratic.tendsto.comp hh + simpa [Function.comp_def,logQuadratic] using h + have hprod := hq.mul (hd.pow 2) + have he : Tendsto (fun n => (k n:ℝ)*(Real.log (m n/k n)-(m n-k n)/k n)) + atTop (𝓝 (-(z^2)/2)) := by + have ht : (-(1/2:ℝ))*z^2 = -(z^2)/2 := by ring + rw [ht] at hprod + apply hprod.congr' + filter_upwards [hkpos] with n hn + have hn0 : (k n:ℝ) ≠ 0 := by exact_mod_cast hn.ne' + have hsn : Real.sqrt (k n:ℝ)^2 = k n := Real.sq_sqrt (Nat.cast_nonneg _) + have hlog : 1+(m n-(k n:ℝ))/(k n:ℝ) = m n/k n := by field_simp; ring + have h := logQuadratic_mul_sq ((m n-(k n:ℝ))/(k n:ℝ)) + rw [hlog] at h + rw [div_pow,hsn] + calc + _ = (k n:ℝ)*(logQuadratic ((m n-(k n:ℝ))/(k n:ℝ))* + ((m n-(k n:ℝ))/(k n:ℝ))^2) := by field_simp + _ = _ := by rw [h] + have hdnom : Tendsto (fun n => Real.sqrt 2*Stirling.stirlingSeq (k n)) atTop + (𝓝 (Real.sqrt 2*Real.sqrt Real.pi)) := + tendsto_const_nhds.mul (Stirling.tendsto_stirlingSeq_sqrt_pi.comp hk) + have heexp := Real.continuous_exp.continuousAt.tendsto.comp he + apply (heexp.div hdnom (by positivity)).congr' + filter_upwards [hm,hkpos] with n hn hnk + exact (poissonMass_stirling hn hnk).symm + +noncomputable def centralIndex (q x : ℝ) (M : ℕ) : ℕ := + ⌊q*(M:ℝ)+x*Real.sqrt M⌋₊ + +lemma center_ratio_tendsto (q x : ℝ) : + Tendsto (fun n : ℕ => (q*n+x*Real.sqrt n)/(n:ℝ)) atTop (𝓝 q) := by + have hs := Real.tendsto_sqrt_atTop.comp (tendsto_natCast_atTop_atTop (R := ℝ)) + have h : Tendsto (fun n : ℕ => q+x/Real.sqrt n) atTop (𝓝 q) := by + simpa using (tendsto_const_nhds.add (tendsto_const_nhds.div_atTop hs)) + apply h.congr' + filter_upwards [eventually_gt_atTop 0] with n hn + have hn0 : (n:ℝ) ≠ 0 := by exact_mod_cast hn.ne' + have hsn : Real.sqrt (n:ℝ) ≠ 0 := by positivity + have hsq := Real.sq_sqrt (Nat.cast_nonneg n) + field_simp + nlinarith [congrArg (fun t => x*t) hsq] + +lemma center_tendsto_atTop {q : ℝ} (hq : 0 < q) (x : ℝ) : + Tendsto (fun n : ℕ => q*n+x*Real.sqrt n) atTop atTop := by + have h := (center_ratio_tendsto q x).pos_mul_atTop hq + (tendsto_natCast_atTop_atTop (R := ℝ)) + apply h.congr' + filter_upwards [eventually_gt_atTop 0] with n hn + exact div_mul_cancel₀ _ (by exact_mod_cast hn.ne') + +lemma centralIndex_atTop {q : ℝ} (hq : 0 < q) (x : ℝ) : + Tendsto (centralIndex q x) atTop atTop := + tendsto_nat_floor_atTop.comp (center_tendsto_atTop hq x) + +lemma centralIndex_deviation {q : ℝ} (hq : 0 < q) (x : ℝ) : + Tendsto (fun n => ((centralIndex q x n:ℝ)-q*n)/Real.sqrt n) atTop (𝓝 x) := by + have hs := Real.tendsto_sqrt_atTop.comp (tendsto_natCast_atTop_atTop (R := ℝ)) + have hzero : Tendsto (fun n : ℕ => 1/Real.sqrt n) atTop (𝓝 0) := + tendsto_const_nhds.div_atTop hs + have hneg : Tendsto (fun n : ℕ => -(1/Real.sqrt n)) atTop (𝓝 0) := by + simpa using hzero.neg + have he : Tendsto (fun n => ((centralIndex q x n:ℝ)- + (q*n+x*Real.sqrt n))/Real.sqrt n) atTop (𝓝 0) := by + apply hneg.squeeze' tendsto_const_nhds + · filter_upwards [(center_tendsto_atTop hq x).eventually (eventually_ge_atTop 0), + eventually_gt_atTop 0] with n hn hn0 + have hspos : 0 < Real.sqrt (n:ℝ) := by positivity + have hh := Nat.lt_floor_add_one (q*n+x*Real.sqrt n) + change -(1/Real.sqrt (n:ℝ)) ≤ _ + rw [← neg_div] + apply div_le_div_of_nonneg_right _ hspos.le + dsimp [centralIndex] + linarith + · filter_upwards [(center_tendsto_atTop hq x).eventually (eventually_ge_atTop 0)] + with n hn + apply div_nonpos_of_nonpos_of_nonneg _ (Real.sqrt_nonneg _) + exact sub_nonpos.mpr (Nat.floor_le hn) + have htt : Tendsto (fun n => (((centralIndex q x n:ℝ)- + (q*n+x*Real.sqrt n))/Real.sqrt n)+x) atTop (𝓝 x) := by + simpa using he.add_const x + apply htt.congr' + filter_upwards [eventually_gt_atTop 0] with n hn + have hsn : Real.sqrt (n:ℝ) ≠ 0 := by positivity + field_simp + ring + +lemma centralIndex_ratio {q : ℝ} (hq : 0 < q) (x : ℝ) : + Tendsto (fun n => (centralIndex q x n:ℝ)/(n:ℝ)) atTop (𝓝 q) := by + have hs := Real.tendsto_sqrt_atTop.comp (tendsto_natCast_atTop_atTop (R := ℝ)) + have ht : Tendsto (fun n => q+(((centralIndex q x n:ℝ)-q*n)/Real.sqrt n)/Real.sqrt n) + atTop (𝓝 q) := by + simpa using tendsto_const_nhds.add ((centralIndex_deviation hq x).div_atTop hs) + apply ht.congr' + filter_upwards [eventually_gt_atTop 0] with n hn + have hn0 : (n:ℝ) ≠ 0 := by exact_mod_cast hn.ne' + rw [div_div, Real.mul_self_sqrt (Nat.cast_nonneg _)] + field_simp + ring + +theorem poisson_scaled_local {q : ℝ} (hq : 0 < q) (x y : ℝ) + (k : ℕ → ℕ) (hk : Tendsto k atTop atTop) + (hkr : Tendsto (fun n => (k n:ℝ)/(n:ℝ)) atTop (𝓝 q)) + (hkd : Tendsto (fun n => ((k n:ℝ)-q*n)/Real.sqrt n) atTop (𝓝 x)) : + Tendsto (fun n : ℕ => Real.sqrt (n:ℝ)* + poissonMass (q*n+y*Real.sqrt n) (k n)) atTop + (𝓝 (Real.exp (-((y-x)/Real.sqrt q)^2/2)/ + (Real.sqrt q*(Real.sqrt 2*Real.sqrt Real.pi)))) := by + have hratio : Tendsto (fun n => Real.sqrt (k n:ℝ)/Real.sqrt n) + atTop (𝓝 (Real.sqrt q)) := by + have hh := Real.continuous_sqrt.continuousAt.tendsto.comp hkr + simpa only [Function.comp_def,Real.sqrt_div (Nat.cast_nonneg _)] using hh + have hstd : Tendsto (fun n : ℕ => ((q*n+y*Real.sqrt n)-(k n:ℝ))/ + Real.sqrt (k n)) atTop (𝓝 ((y-x)/Real.sqrt q)) := by + have hh := ((tendsto_const_nhds (x := y)).sub hkd).div hratio + ((Real.sqrt_pos.2 hq).ne') + apply hh.congr' + filter_upwards [eventually_gt_atTop 0, hk.eventually (eventually_gt_atTop 0)] + with n hn hk0 + have hsn : Real.sqrt (n:ℝ) ≠ 0 := by positivity + have hsk : Real.sqrt (k n:ℝ) ≠ 0 := by positivity + change (y-((k n:ℝ)-q*n)/Real.sqrt n)/ + (Real.sqrt (k n:ℝ)/Real.sqrt n) = _ + field_simp + ring + have hp := poisson_local_limit hk + ((center_tendsto_atTop hq y).eventually (eventually_gt_atTop 0)) hstd + have ht := hp.div hratio ((Real.sqrt_pos.2 hq).ne') + have heconst : (Real.exp (-((y-x)/Real.sqrt q)^2/2)/ + (Real.sqrt 2*Real.sqrt Real.pi))/Real.sqrt q = + Real.exp (-((y-x)/Real.sqrt q)^2/2)/ + (Real.sqrt q*(Real.sqrt 2*Real.sqrt Real.pi)) := by ring + rw [heconst] at ht + apply ht.congr' + filter_upwards [hk.eventually (eventually_gt_atTop 0)] with n hn + have hsk : Real.sqrt (k n:ℝ) ≠ 0 := by positivity + change (Real.sqrt (k n:ℝ)*poissonMass _ _)/ + (Real.sqrt (k n:ℝ)/Real.sqrt n) = _ + field_simp + +theorem poisson_histogram_pointwise {q : ℝ} (hq : 0 < q) (x y : ℝ) : + Tendsto (fun n : ℕ => Real.sqrt (n:ℝ)* + poissonMass (q*n+y*Real.sqrt n) (centralIndex q x n)) atTop + (𝓝 (Real.exp (-((y-x)/Real.sqrt q)^2/2)/ + (Real.sqrt q*(Real.sqrt 2*Real.sqrt Real.pi)))) := + poisson_scaled_local hq x y (centralIndex q x) (centralIndex_atTop hq x) + (centralIndex_ratio hq x) (centralIndex_deviation hq x) + +noncomputable def binomialMass (q : ℝ) (M k : ℕ) : ℝ := + (M.choose k:ℝ)*q^k*(1-q)^(M-k) + +lemma binomialMass_poisson {q : ℝ} {M k : ℕ} (hk : k ≤ M) (hM : 0 < M) : + binomialMass q M k = + poissonMass (q*M) k*poissonMass ((1-q)*M) (M-k)/poissonMass M M := by + have hM0 : (M:ℝ) ≠ 0 := by exact_mod_cast hM.ne' + unfold binomialMass poissonMass + rw [Nat.cast_choose ℝ hk] + have he : Real.exp (-(q*(M:ℝ)))*Real.exp (-((1-q)*M)) = Real.exp (-(M:ℝ)) := by + rw [← Real.exp_add] + congr 1 + ring + have hp : (M:ℝ)^k*(M:ℝ)^(M-k) = (M:ℝ)^M := by + rw [← pow_add, Nat.add_sub_of_le hk] + simp only [mul_pow] + have hf1 : (k.factorial:ℝ) ≠ 0 := by positivity + have hf2 : ((M-k).factorial:ℝ) ≠ 0 := by positivity + have hf3 : (M.factorial:ℝ) ≠ 0 := by positivity + have he0 : Real.exp (-(M:ℝ)) ≠ 0 := Real.exp_ne_zero _ + field_simp + calc + _ = (M:ℝ)^M * Real.exp (-(M:ℝ)) *q^k*(1-q)^(M-k) := by ring + _ = _ := by rw [← hp, ← he]; ring + +lemma gaussian_formula {q : ℝ} (hq : 0 < q) (x y : ℝ) : + Real.exp (-((y-x)/Real.sqrt q)^2/2)/ + (Real.sqrt q*(Real.sqrt 2*Real.sqrt Real.pi)) = + gaussianPDFReal y ⟨q,hq.le⟩ x := by + change _ = (Real.sqrt (2*Real.pi*q))⁻¹ * Real.exp (-(x-y)^2/(2*q)) + rw [Real.sqrt_mul (mul_nonneg (by norm_num) Real.pi_pos.le), + Real.sqrt_mul (by norm_num : (0:ℝ)≤2)] + have he : -((y-x)/Real.sqrt q)^2/2 = -(x-y)^2/(2*q) := by + rw [div_pow, Real.sq_sqrt hq.le] + ring + rw [he] + ring + +lemma index_atTop_of_ratio {k : ℕ → ℕ} {q : ℝ} (hq : 0 < q) + (hkr : Tendsto (fun n => (k n:ℝ)/(n:ℝ)) atTop (𝓝 q)) : Tendsto k atTop atTop := by + apply (tendsto_natCast_atTop_iff (R := ℝ)).mp + apply (hkr.pos_mul_atTop hq (tendsto_natCast_atTop_atTop (R := ℝ))).congr' + filter_upwards [eventually_gt_atTop 0] with n hn + exact div_mul_cancel₀ _ (by exact_mod_cast hn.ne') + +lemma centralIndex_le {q : ℝ} (hql : 0 < q) (hqu : q < 1) (x : ℝ) : + ∀ᶠ n in atTop, centralIndex q x n ≤ n := by + filter_upwards [(centralIndex_ratio hql x).eventually (eventually_lt_nhds hqu), + eventually_gt_atTop 0] with n hn hn0 + have hnpos : (0:ℝ) < n := by exact_mod_cast hn0 + have hh := (div_lt_iff₀ hnpos).mp hn + have hh' : (centralIndex q x n:ℝ) < n := by simpa using hh + exact le_of_lt (by exact_mod_cast hh') + +lemma complementIndex_ratio {q : ℝ} (hql : 0 < q) (hqu : q < 1) (x : ℝ) : + Tendsto (fun n => ((n-centralIndex q x n:ℕ):ℝ)/(n:ℝ)) atTop (𝓝 (1-q)) := by + apply ((tendsto_const_nhds (x := (1:ℝ))).sub (centralIndex_ratio hql x)).congr' + filter_upwards [centralIndex_le hql hqu x,eventually_gt_atTop 0] with n hn hn0 + rw [Nat.cast_sub hn] + have hne : (n:ℝ) ≠ 0 := by exact_mod_cast hn0.ne' + field_simp + +lemma complementIndex_deviation {q : ℝ} (hql : 0 < q) (hqu : q < 1) (x : ℝ) : + Tendsto (fun n => (((n-centralIndex q x n:ℕ):ℝ)-(1-q)*n)/Real.sqrt n) + atTop (𝓝 (-x)) := by + apply (centralIndex_deviation hql x).neg.congr' + filter_upwards [centralIndex_le hql hqu x] with n hn + rw [Nat.cast_sub hn] + ring + +lemma gaussian_product_quotient {q : ℝ} (hql : 0 < q) (hqu : q < 1) (x : ℝ) : + gaussianPDFReal 0 ⟨q,hql.le⟩ x * + gaussianPDFReal 0 ⟨1-q,by linarith⟩ (-x) / + gaussianPDFReal 0 1 0 = + gaussianPDFReal 0 ⟨q*(1-q),mul_nonneg hql.le (by linarith)⟩ x := by + have hg1 : gaussianPDFReal 0 1 0 = 1/(Real.sqrt 2*Real.sqrt Real.pi) := by + norm_num [gaussianPDFReal, Real.sqrt_mul (by norm_num : (0:ℝ)≤2)] + rw [← gaussian_formula hql x 0, ← gaussian_formula (by linarith : 0 < 1-q) (-x) 0, + hg1, ← gaussian_formula (mul_pos hql (by linarith : 0 < 1-q)) x 0] + simp only [zero_sub, neg_div, neg_sq, neg_neg] + have hq0 : q ≠ 0 := hql.ne' + have hr0 : 1-q ≠ 0 := by linarith + have he : -(x/Real.sqrt q)^2/2 + -(x/Real.sqrt (1-q))^2/2 = + -(x/Real.sqrt (q*(1-q)))^2/2 := by + simp only [div_pow, Real.sq_sqrt hql.le, Real.sq_sqrt (show 0≤1-q by linarith), + Real.sq_sqrt (mul_nonneg hql.le (show 0≤1-q by linarith))] + field_simp + ring + rw [mul_div_assoc, div_div, div_mul_div_comm] + rw [← Real.exp_add] + simp only [← neg_div] + rw [he, Real.sqrt_mul hql.le] + have hs : Real.sqrt q ≠ 0 := by positivity + have hr : Real.sqrt (1-q) ≠ 0 := by positivity + have h2 : Real.sqrt (2:ℝ) ≠ 0 := by positivity + have hpi : Real.sqrt Real.pi ≠ 0 := by positivity + field_simp + +theorem binomial_histogram_pointwise {q : ℝ} (hql : 0 < q) (hqu : q < 1) (x : ℝ) : + Tendsto (fun n : ℕ => Real.sqrt (n:ℝ)*binomialMass q n (centralIndex q x n)) atTop + (𝓝 (gaussianPDFReal 0 ⟨q*(1-q),mul_nonneg hql.le (by linarith)⟩ x)) := by + have ha := poisson_scaled_local hql x 0 (centralIndex q x) (centralIndex_atTop hql x) + (centralIndex_ratio hql x) (centralIndex_deviation hql x) + have hb := poisson_scaled_local (by linarith : 0 < 1-q) (-x) 0 + (fun n => n-centralIndex q x n) + (index_atTop_of_ratio (by linarith) (complementIndex_ratio hql hqu x)) + (complementIndex_ratio hql hqu x) (complementIndex_deviation hql hqu x) + have hc := poisson_scaled_local (by norm_num : (0:ℝ)<1) 0 0 (fun n => n) tendsto_id + (by + apply tendsto_const_nhds.congr' + filter_upwards [eventually_gt_atTop 0] with n hn + exact (div_self (by exact_mod_cast hn.ne' : (n:ℝ) ≠ 0)).symm) + (by simp) + rw [gaussian_formula hql x 0] at ha + rw [gaussian_formula (by linarith : 0 < 1-q) (-x) 0] at hb + rw [gaussian_formula (by norm_num : (0:ℝ)<1) 0 0] at hc + have hc1 : (⟨(1:ℝ),by norm_num⟩ : ℝ≥0) = 1 := by rfl + rw [hc1] at hc + have hh := (ha.mul hb).div hc (gaussianPDFReal_pos 0 1 0 (by norm_num)).ne' + have heq : gaussianPDFReal 0 ⟨q,hql.le⟩ x * + gaussianPDFReal 0 ⟨1-q,by linarith⟩ (-x) / gaussianPDFReal 0 1 0 = + gaussianPDFReal 0 ⟨q*(1-q),mul_nonneg hql.le (by linarith)⟩ x := + gaussian_product_quotient hql hqu x + have hh' : Tendsto (fun n : ℕ => + (Real.sqrt (n:ℝ)*poissonMass (q*n+0*Real.sqrt n) (centralIndex q x n))* + (Real.sqrt (n:ℝ)*poissonMass ((1-q)*n+0*Real.sqrt n) (n-centralIndex q x n))/ + (Real.sqrt (n:ℝ)*poissonMass (1*n+0*Real.sqrt n) n)) atTop + (𝓝 (gaussianPDFReal 0 ⟨q,hql.le⟩ x * + gaussianPDFReal 0 ⟨1-q,by linarith⟩ (-x) / gaussianPDFReal 0 1 0)) := hh + rw [heq] at hh' + apply hh'.congr' + filter_upwards [centralIndex_le hql hqu x,eventually_gt_atTop 0] with n hn hn0 + simp only [zero_mul,add_zero,one_mul] + rw [binomialMass_poisson hn hn0] + have hs : Real.sqrt (n:ℝ) ≠ 0 := by positivity + field_simp + +end SKRatioClock.Clock + +open Filter MeasureTheory ProbabilityTheory +open scoped Topology NNReal ENNReal + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Dynamics/Median.lean b/lean/OAI/Probability/SKRatio/Dynamics/Median.lean new file mode 100644 index 0000000000000000000000000000000000000000..0830acd550fb019432171317499f061ad796258c --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Dynamics/Median.lean @@ -0,0 +1,205 @@ +import Mathlib +import OAI.Probability.SKRatio.FiniteChain.DiscreteDistanceNonneg +import OAI.Probability.SKRatio.Calculus.GibbsMeanCLM + +namespace OAI + +section +noncomputable section +open scoped BigOperators Topology Matrix +open ContinuousLinearMap MeasureTheory Filter +namespace SKRatio.Calculus + +@[simp] lemma continuousKernel_zero {n : ℕ} (J : Interaction n) : + continuousKernel J 0 = (1 : Matrix (Spin n) (Spin n) ℝ) := by + funext x y + simp [continuousKernel, Matrix.one_apply] + +@[simp] lemma continuousDistance_zero {n : ℕ} (g : Disorder n) : + continuousDistance g 0 = discreteDistance g 0 := by + simp [continuousDistance, discreteDistance] + +lemma continuousKernel_continuous_time {n : ℕ} (J : Interaction n) (x y : Spin n) : + Continuous (fun t : ℝ => continuousKernel J t x y) := by + unfold continuousKernel + exact (continuous_apply x).comp ((semigroup_continuous J).clm_apply continuous_const) + +lemma continuousDistance_continuous_time {n : ℕ} (g : Disorder n) : + Continuous (continuousDistance g) := by + have h : Continuous (Finset.univ.sup' Finset.univ_nonempty + (fun (x : Spin n) (t : ℝ) => + totalVariation (continuousKernel (coupling g) t x) (mass g 0))) := by + apply Continuous.finset_sup' + intro x _ + unfold totalVariation + apply continuous_const.mul + exact continuous_finsetSum _ (fun y _ => + ((continuousKernel_continuous_time _ x y).sub continuous_const).abs) + exact h.congr (fun t => Finset.sup'_apply _ _ t) + +lemma continuousKernel_pos {n : ℕ} (g : Disorder n) {t : ℝ} (ht : 0 < t) + (x y : Spin n) : 0 < continuousKernel (coupling g) t x y := by + by_cases hn : n = 0 + · subst n + have h := continuousKernel_sum (coupling g) t x + rw [Fintype.sum_subsingleton _ y] at h + linarith only [h] + · have hn' : 0 < n := Nat.pos_of_ne_zero hn + have hs := continuousKernel_poisson_hasSum hn' g t x y + have hpos : 0 < Real.exp (-(n:ℝ)*t) * ((n:ℝ)*t)^n / + (n.factorial:ℝ) * (transition g^n) x y := by + exact mul_pos (div_pos (mul_pos (Real.exp_pos _) (pow_pos + (mul_pos (Nat.cast_pos.mpr hn') ht) _)) (Nat.cast_pos.mpr (Nat.factorial_pos _))) + (transition_n_pos g x y) + exact hpos.trans_le (hs.tsum_eq ▸ hs.summable.le_tsum n (fun k _ => by + exact mul_nonneg (div_nonneg (mul_nonneg (Real.exp_nonneg _) + (pow_nonneg (mul_nonneg (Nat.cast_nonneg _) ht.le) _)) (Nat.cast_nonneg _)) + ((transition_pow_stochastic g k).1 x y))) + +lemma continuousKernel_nat {n : ℕ} (J : Interaction n) (k : ℕ) : + continuousKernel J (k : ℝ) = (continuousKernel J 1)^k := by + induction k with + | zero => simp + | succ k ih => + rw [Nat.cast_add, Nat.cast_one, continuousKernel_add, ih, pow_succ] + +lemma exists_continuous_geometric_bound {n : ℕ} (g : Disorder n) : + ∃ r : ℝ, 0 ≤ r ∧ r < 1 ∧ ∀ k : ℕ, continuousDistance g k ≤ r^k := by + obtain ⟨r, hr0, hr1, hr⟩ := exists_geometric_block_bound + (continuousKernel (coupling g) 1) (continuousKernel_stochastic _ (by norm_num)) + (mass g 0) (mass_nonneg g 0) (sum_mass g 0) 1 + (by simpa only [pow_one] using continuousKernel_pos g (by norm_num : (0:ℝ)<1)) + (by simpa only [pow_one] using continuousKernel_stationary g 1) + refine ⟨r, hr0, hr1, fun k => ?_⟩ + unfold continuousDistance + rw [continuousKernel_nat] + apply Finset.sup'_le + intro x _ + simpa only [one_mul] using hr k x + +lemma exists_continuous_mixing_time {n : ℕ} (g : Disorder n) {ε : ℝ} (hε : 0 < ε) : + ∃ t : ℝ, 0 ≤ t ∧ continuousDistance g t ≤ ε := by + obtain ⟨r, hr0, hr1, hbound⟩ := exists_continuous_geometric_bound g + obtain ⟨k, hk⟩ := ((tendsto_pow_atTop_nhds_zero_of_lt_one hr0 hr1).eventually + (gt_mem_nhds hε)).exists + exact ⟨k, Nat.cast_nonneg _, (hbound k).trans hk.le⟩ + +def medianTime {n : ℕ} (g : Disorder n) : ℝ := + sInf {t : ℝ | 0 ≤ t ∧ continuousDistance g t ≤ 1/2} + +lemma medianTime_mem {n : ℕ} (g : Disorder n) : + 0 ≤ medianTime g ∧ continuousDistance g (medianTime g) ≤ 1/2 := by + apply IsClosed.csInf_mem + ((isClosed_le continuous_const continuous_id).inter + (isClosed_le (continuousDistance_continuous_time g) continuous_const)) + (exists_continuous_mixing_time g (by norm_num)) + ⟨0, fun _ ht => ht.1⟩ + +lemma medianTime_le_iff {n : ℕ} (g : Disorder n) {t : ℝ} (ht : 0 ≤ t) : + medianTime g ≤ t ↔ continuousDistance g t ≤ 1/2 := by + constructor + · intro h + exact (continuousDistance_antitone g (medianTime_mem g).1 h).trans (medianTime_mem g).2 + · intro h + exact csInf_le ⟨0, fun _ h => h.1⟩ ⟨ht, h⟩ + +lemma before_median {n : ℕ} (g : Disorder n) {t : ℝ} (ht : 0 ≤ t) + (hbefore : t < medianTime g) : 1/2 < continuousDistance g t := by + exact lt_of_not_ge (fun h => not_le_of_gt hbefore ((medianTime_le_iff g ht).mpr h)) + +lemma medianTime_pos {n : ℕ} (g : Disorder n) (hn : 2 ≤ n) : 0 < medianTime g := by + have hid : 1/2 < continuousDistance g 0 := by + rw [continuousDistance_zero] + have hpow : (1/2:ℝ)^n ≤ (1/2:ℝ)^2 := + pow_le_pow_of_le_one (by norm_num) (by norm_num) hn + have h := discreteDistance_zero_lower g + norm_num at hpow + linarith only [hpow, h] + exact lt_of_not_ge (fun h => not_le_of_gt hid + ((medianTime_le_iff g (le_refl 0)).mp h)) + +lemma continuousDistance_median {n : ℕ} (g : Disorder n) (hn : 2 ≤ n) : + continuousDistance g (medianTime g) = 1/2 := by + apply le_antisymm (medianTime_mem g).2 + by_contra h + have hlt : continuousDistance g (medianTime g) < 1/2 := lt_of_not_ge h + have hopen : IsOpen {t : ℝ | continuousDistance g t < 1/2} := + isOpen_lt (continuousDistance_continuous_time g) continuous_const + obtain ⟨l, u, hmu, hsub⟩ := mem_nhds_iff_exists_Ioo_subset.mp (hopen.mem_nhds hlt) + have hm : max 0 l < medianTime g := max_lt (medianTime_pos g hn) hmu.1 + obtain ⟨y, hy₀, hym⟩ := exists_between hm + have hy : 0 ≤ y := (le_max_left 0 l).trans hy₀.le + have hylt : continuousDistance g y < 1/2 := + hsub ⟨(le_max_right 0 l).trans_lt hy₀, hym.trans hmu.2⟩ + exact not_lt_of_gt (before_median g hy hym) hylt + +lemma median_cutoff_sides_of_lag {n : ℕ} (g : Disorder n) + {c C b δ : ℝ} (hc : 0 < c) (hb : 0 < b) (hb' : b < 1) + (hδ : δ < 1/2) (hn : 1 < n) + (hscale : c * Real.log n ≤ medianTime g ∧ medianTime g ≤ C * Real.log n) + (hlag : ∀ t : ℝ, 0 ≤ t → + t + (b*c/2)*Real.log n ≤ ((1+b)*C)*Real.log n → + continuousDistance g t ≤ 1-δ → + continuousDistance g (t+(b*c/2)*Real.log n) ≤ δ) : + 1-δ < continuousDistance g ((1-b)*medianTime g) ∧ + continuousDistance g ((1+b)*medianTime g) ≤ δ := by + let s : ℝ := (b*c/2)*Real.log n + have hlog : 0 < Real.log n := Real.log_pos (by exact_mod_cast hn) + have hs : 0 < s := by dsimp [s]; positivity + have hm : 0 ≤ medianTime g := (medianTime_mem g).1 + have hsmed : s ≤ b*medianTime g/2 := by + have h := mul_le_mul_of_nonneg_left hscale.1 (div_nonneg hb.le (by norm_num : (0:ℝ)≤2)) + dsimp [s] + nlinarith only [h] + have hshift : medianTime g+s ≤ (1+b)*medianTime g := by nlinarith only [hsmed, hs] + have hhor : medianTime g+s ≤ ((1+b)*C)*Real.log n := by + calc + _ ≤ (1+b)*medianTime g := hshift + _ ≤ (1+b)*(C*Real.log n) := + mul_le_mul_of_nonneg_left hscale.2 (by linarith) + _ = _ := by ring + have hlo : 0 ≤ (1-b)*medianTime g := mul_nonneg (by linarith) hm + have hlobefore : (1-b)*medianTime g+s < medianTime g := by + nlinarith only [hsmed, hs] + constructor + · by_contra h + have ht := hlag ((1-b)*medianTime g) hlo + ((le_of_lt hlobefore).trans ((le_add_of_nonneg_right hs.le).trans hhor)) + (le_of_not_gt h) + have hbefore := before_median g (add_nonneg hlo hs.le) hlobefore + exact not_lt_of_ge (ht.trans hδ.le) hbefore + · have hcmed : continuousDistance g (medianTime g) ≤ 1-δ := by + linarith only [(medianTime_mem g).2, hδ] + exact (continuousDistance_antitone g (add_nonneg hm hs.le) hshift).trans + (hlag (medianTime g) hm hhor hcmed) + +lemma uniform_continuous_cutoff_of_positive_lag + (G : ∀ n : ℕ, Set (Disorder n)) {c C : ℝ} (hc : 0 < c) + (hscale : ∀ᶠ n : ℕ in atTop, ∀ g ∈ G n, + c*Real.log n ≤ medianTime g ∧ medianTime g ≤ C*Real.log n) + (hlag : ∀ ε α D δ : ℝ, 0 < ε → 0 < α → 0 < δ → + ∀ᶠ n : ℕ in atTop, ∀ g ∈ G n, ∀ t : ℝ, + 0 ≤ t → t+α*Real.log n ≤ D*Real.log n → + continuousDistance g t ≤ 1-ε → continuousDistance g (t+α*Real.log n) ≤ δ) + {b : ℝ} (hb : 0 < b) (hb' : b < 1) {δ : ℝ} (hδ : 0 < δ) : + ∀ᶠ n : ℕ in atTop, ∀ g ∈ G n, + 1-δ < continuousDistance g ((1-b)*medianTime g) ∧ + continuousDistance g ((1+b)*medianTime g) ≤ δ := by + let e : ℝ := min δ (1/4) + have he : 0 < e := lt_min hδ (by norm_num) + have heδ : e ≤ δ := min_le_left _ _ + have hehalf : e < 1/2 := (min_le_right _ _).trans_lt (by norm_num) + have ha : 0 < b*c/2 := by positivity + filter_upwards [hscale, hlag e (b*c/2) ((1+b)*C) e he ha he, + eventually_gt_atTop 1] with n hnscale hnlag hn + intro g hg + obtain ⟨hl, hu⟩ := median_cutoff_sides_of_lag g hc hb hb' hehalf hn + (hnscale g hg) (hnlag g hg) + exact ⟨(by linarith only [heδ, hl]), hu.trans heδ⟩ + +end SKRatio.Calculus + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Dynamics/PoissonBinomial.lean b/lean/OAI/Probability/SKRatio/Dynamics/PoissonBinomial.lean new file mode 100644 index 0000000000000000000000000000000000000000..a039713d5cb7ae4aa64d9c8fe9dcb0a60c1a2621 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Dynamics/PoissonBinomial.lean @@ -0,0 +1,155 @@ +import Mathlib +import OAI.Probability.SKRatio.Dynamics.SumPoissonMass +import OAI.Probability.SKRatio.Dynamics.GaussianPDFMoment +import OAI.Probability.SKRatio.Dynamics.IntegrableMulBounded +import OAI.Probability.SKRatio.Dynamics.TestHistogram + +namespace OAI + +section +noncomputable section +open scoped BigOperators +open Filter MeasureTheory ProbabilityTheory +open scoped Topology NNReal ENNReal +open Filter MeasureTheory ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter +open scoped Topology NNReal ENNReal +open MeasureTheory Filter ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter +open scoped Topology +open MeasureTheory Filter ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter ProbabilityTheory +open scoped Topology NNReal ENNReal +namespace SKRatioClock.Clock + +theorem poisson_to_binomial {q B : ℝ} (hq : 0 < q) (hq1 : q < 1) (hB : 0 < B) + (M : ℕ → ℕ) (hM : Tendsto M atTop atTop) (a : ℕ → ℕ → ℝ) + (hab : ∀ n j, |a n j| ≤ B) + (hp : ∀ y : ℝ, Tendsto (fun n => ∑' j, + poissonMass (q*M n+y*Real.sqrt (M n)) j*a n j) atTop (𝓝 0)) : + Tendsto (fun n => ∑' j, binomialMass q (M n) j*a n j) atTop (𝓝 0) := by + let u : ℕ → ℝ → ℝ := fun n => testHistogram q (M n) (a n) + have hu (n : ℕ) : AEStronglyMeasurable (u n) := + (measurable_testHistogram q (M n) (a n)).aestronglyMeasurable + have hub (n : ℕ) (x : ℝ) : |u n x| ≤ B := testHistogram_bound hB.le (hab n) q (M n) x + have hMn : ∀ᶠ n in atTop, 0 < M n := hM.eventually (eventually_gt_atTop 0) + have hPi (y : ℝ) : ∀ᶠ n in atTop, + Integrable (histogram q (M n) (poissonMass (q*M n+y*Real.sqrt (M n)))) := by + filter_upwards [hMn] with n hn + exact integrable_histogram (hasSum_poissonMass _) q hn + have hdiff (y : ℝ) := pairing_of_L1_limit (hPi y) + (integrable_gaussianPDFReal y ⟨q,hq.le⟩) hu hub ((poisson_density_L1 hq y).comp hM) + have hP (y : ℝ) : Tendsto (fun n => ∫ x : ℝ, + histogram q (M n) (poissonMass (q*M n+y*Real.sqrt (M n))) x*u n x) + atTop (𝓝 0) := by + apply (hp y).congr' + filter_upwards [hMn] with n hn + exact (integral_histogram_test (hasSum_poissonMass _).summable (hab n) q hn).symm + have hG (y : ℝ) : Tendsto (fun n => ∫ x : ℝ, gaussianPDFReal y ⟨q,hq.le⟩ x*u n x) + atTop (𝓝 0) := by + have hh := (hP y).sub (hdiff y) + simpa only [sub_sub_cancel,sub_zero] using hh + let v : ℝ≥0 := ⟨q,hq.le⟩ + let w : ℝ≥0 := ⟨q*(1-q),mul_nonneg hq.le (by linarith)⟩ + have hv : 0 < v := hq + have hw : 0 < w := mul_pos hq (by linarith) + have hwv : w ≤ v := by + change q*(1-q) ≤ q + nlinarith [sq_nonneg q] + have hGb : Tendsto (fun n => ∫ x : ℝ, gaussianPDFReal 0 w x*u n x) + atTop (𝓝 0) := + pairing_of_finite_approximation (integrable_gaussianPDFReal 0 w) + (fun y => integrable_gaussianPDFReal (-y) v) hB hu hub + (fun ε hε => finite_gaussianPDF_approximation hv hw hwv hε) (fun y => hG (-y)) + have hBi : ∀ᶠ n in atTop, Integrable (histogram q (M n) (binomialMass q (M n))) := by + filter_upwards [hMn] with n hn + exact integrable_histogram (hasSum_binomialMass q _) q hn + have hBd := pairing_of_L1_limit hBi (integrable_gaussianPDFReal 0 w) hu hub + ((binomial_density_L1 hq hq1).comp hM) + have hBin : Tendsto (fun n => ∫ x : ℝ, + histogram q (M n) (binomialMass q (M n)) x*u n x) atTop (𝓝 0) := by + have hh := hBd.add hGb + simpa only [sub_add_cancel,zero_add] using hh + apply hBin.congr' + filter_upwards [hMn] with n hn + exact integral_histogram_test (hasSum_binomialMass q _).summable (hab n) q hn + +lemma uniform_zero_of_selections {ι : ℕ → Type*} [∀ n, Nonempty (ι n)] + (f : (n : ℕ) → ι n → ℝ) + (hf : ∀ i : (n : ℕ) → ι n, Tendsto (fun n => f n (i n)) atTop (𝓝 0)) : + ∀ ε : ℝ, 0 < ε → ∀ᶠ n in atTop, ∀ i : ι n, |f n i| < ε := by + classical + intro ε hε + let i : (n : ℕ) → ι n := fun n => + if h : ∃ i : ι n, ε ≤ |f n i| then Classical.choose h else Classical.choice (inferInstance : Nonempty (ι n)) + have hh : ∀ᶠ n in atTop, |f n (i n)| < ε := by + have he := (hf i).eventually (Metric.ball_mem_nhds 0 hε) + simpa only [Metric.mem_ball,Real.dist_eq,sub_zero] using he + filter_upwards [hh] with n hn + intro j + by_contra h + have hbad : ∃ j : ι n, ε ≤ |f n j| := ⟨j,le_of_not_gt h⟩ + have hlarge : ε ≤ |f n (i n)| := by simpa only [i,dite_eq_left hbad] using Classical.choose_spec hbad + exact (not_le.mpr hn) hlarge + +theorem poisson_to_binomial_uniform {q B : ℝ} (hq : 0 < q) (hq1 : q < 1) (hB : 0 < B) + (M : ℕ → ℕ) (hM : Tendsto M atTop atTop) + {ι : ℕ → Type*} [∀ n, Nonempty (ι n)] + (a : (n : ℕ) → ι n → ℕ → ℝ) (hab : ∀ n i j, |a n i j| ≤ B) + (hp : ∀ y ε : ℝ, 0 < ε → ∀ᶠ n in atTop, ∀ i : ι n, + |∑' j, poissonMass (q*M n+y*Real.sqrt (M n)) j*a n i j| < ε) : + ∀ ε : ℝ, 0 < ε → ∀ᶠ n in atTop, ∀ i : ι n, + |∑' j, binomialMass q (M n) j*a n i j| < ε := by + apply uniform_zero_of_selections + intro i + apply poisson_to_binomial hq hq1 hB M hM (fun n => a n (i n)) + (fun n j => hab n (i n) j) + intro y + apply Metric.tendsto_atTop.mpr + intro ε hε + obtain ⟨N,hN⟩ := eventually_atTop.mp (hp y ε hε) + refine ⟨N,fun n hn => ?_⟩ + simpa only [Real.dist_eq,sub_zero] using hN n hn (i n) + +theorem poisson_to_binomial_bounded {q B : ℝ} (hq : 0 < q) (hq1 : q < 1) + (M : ℕ → ℕ) (hM : Tendsto M atTop atTop) (a : ℕ → ℕ → ℝ) + (hab : ∀ n j, |a n j| ≤ B) + (hp : ∀ y : ℝ, Tendsto (fun n => ∑' j, + poissonMass (q*M n+y*Real.sqrt (M n)) j*a n j) atTop (𝓝 0)) : + Tendsto (fun n => ∑' j, binomialMass q (M n) j*a n j) atTop (𝓝 0) := by + apply poisson_to_binomial hq hq1 (show 0 < |B|+1 by positivity) M hM a + (fun n j => (hab n j).trans ((le_abs_self B).trans (by linarith))) hp + +theorem poisson_to_binomial_uniform_clocks {q B : ℝ} (hq : 0 < q) (hq1 : q < 1) + {ι : ℕ → Type*} [∀ n, Nonempty (ι n)] (M : (n : ℕ) → ι n → ℕ) + (hM : ∀ K : ℕ, ∀ᶠ n in atTop, ∀ i : ι n, K ≤ M n i) + (a : (n : ℕ) → ι n → ℕ → ℝ) (hab : ∀ n i j, |a n i j| ≤ B) + (hp : ∀ y ε : ℝ, 0 < ε → ∀ᶠ n in atTop, ∀ i : ι n, + |∑' j, poissonMass (q*M n i+y*Real.sqrt (M n i)) j*a n i j| < ε) : + ∀ ε : ℝ, 0 < ε → ∀ᶠ n in atTop, ∀ i : ι n, + |∑' j, binomialMass q (M n i) j*a n i j| < ε := by + apply uniform_zero_of_selections + intro i + have hMi : Tendsto (fun n => M n (i n)) atTop atTop := by + apply Filter.tendsto_atTop.mpr + intro K + filter_upwards [hM K] with n hn + exact hn (i n) + apply poisson_to_binomial_bounded hq hq1 (fun n => M n (i n)) hMi (fun n => a n (i n)) + (fun n j => hab n (i n) j) + intro y + apply Metric.tendsto_atTop.mpr + intro ε hε + obtain ⟨N,hN⟩ := eventually_atTop.mp (hp y ε hε) + refine ⟨N,fun n hn => ?_⟩ + simpa only [Real.dist_eq,sub_zero] using hN n hn (i n) + +end SKRatioClock.Clock + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Dynamics/PositiveLag.lean b/lean/OAI/Probability/SKRatio/Dynamics/PositiveLag.lean new file mode 100644 index 0000000000000000000000000000000000000000..c8f3ed46b93fab327e31b4ee0327c157529b46cb --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Dynamics/PositiveLag.lean @@ -0,0 +1,201 @@ +import Mathlib +import OAI.Probability.SKRatio.Dynamics.Propagation + +namespace OAI + +section +noncomputable section +open scoped BigOperators Topology Matrix +open MeasureTheory Filter +namespace SKRatio.Calculus +attribute [local instance] Classical.propDecidable + +def dimensionDecay (a : ℝ) (n : ℕ) : ℝ := Real.exp (-a * Real.log n) + +lemma dimensionDecay_pos (a : ℝ) (n : ℕ) : 0 < dimensionDecay a n := + Real.exp_pos _ + +lemma dimensionDecay_tendsto_zero {a : ℝ} (ha : 0 < a) : + Tendsto (dimensionDecay a) atTop (𝓝 0) := by + have h := (tendsto_rpow_mul_exp_neg_mul_atTop_nhds_zero 0 a ha).comp + (Real.tendsto_log_atTop.comp tendsto_natCast_atTop_atTop) + unfold dimensionDecay + simpa only [Function.comp_def, Real.rpow_zero, one_mul] using h + +lemma log_pow_mul_dimensionDecay_tendsto_zero (k : ℕ) {a : ℝ} (ha : 0 < a) : + Tendsto (fun n : ℕ => (Real.log n)^k * dimensionDecay a n) atTop (𝓝 0) := by + have h := (tendsto_rpow_mul_exp_neg_mul_atTop_nhds_zero (k : ℝ) a ha).comp + (Real.tendsto_log_atTop.comp tendsto_natCast_atTop_atTop) + simpa only [Function.comp_def, Real.rpow_natCast, dimensionDecay] using h + +lemma nat_mul_dimensionDecay {n : ℕ} (hn : 0 < n) (a : ℝ) : + (n : ℝ) * dimensionDecay a n = dimensionDecay (a - 1) n := by + have hn' : 0 < (n : ℝ) := Nat.cast_pos.mpr hn + calc + _ = Real.exp (Real.log n) * Real.exp (-a * Real.log n) := by + rw [Real.exp_log hn']; rfl + _ = _ := by rw [← Real.exp_add]; congr 1; ring + +def logarithmicVarianceBound (κ A d₀ D α : ℝ) (n : ℕ) : ℝ := + (4*D*Real.exp (A*d₀)/α) * dimensionDecay (κ*α/4) n + + (4*A*D^2*Real.exp (A*d₀)) * ((Real.log n)^2 * dimensionDecay 3 n) + + (4*D*Real.exp (A*d₀)) * (Real.log n * dimensionDecay 3 n) + +lemma logarithmicVarianceBound_nonneg {κ A d₀ D α : ℝ} {n : ℕ} + (hA : 0 ≤ A) (hD : 0 ≤ D) (hα : 0 ≤ α) (hn : 1 ≤ n) : + 0 ≤ logarithmicVarianceBound κ A d₀ D α n := by + have hlog : 0 ≤ Real.log n := Real.log_nonneg (by exact_mod_cast hn) + unfold logarithmicVarianceBound dimensionDecay + positivity + +lemma logarithmicVarianceBound_tendsto_zero {κ α : ℝ} + (hκ : 0 < κ) (hα : 0 < α) (A d₀ D : ℝ) : + Tendsto (logarithmicVarianceBound κ A d₀ D α) atTop (𝓝 0) := by + have h1 := (dimensionDecay_tendsto_zero + (a := κ*α/4) (by positivity)).const_mul (4*D*Real.exp (A*d₀)/α) + have h2 := (log_pow_mul_dimensionDecay_tendsto_zero 2 (by norm_num : (0:ℝ)<3)).const_mul + (4*A*D^2*Real.exp (A*d₀)) + have h3 := (log_pow_mul_dimensionDecay_tendsto_zero 1 (by norm_num : (0:ℝ)<3)).const_mul + (4*D*Real.exp (A*d₀)) + unfold logarithmicVarianceBound + simpa only [zero_mul, mul_zero, add_zero, pow_one] using + (h1.add h2).add h3 + +def logarithmicSmoothingBound (κ A d₀ D α γ ε : ℝ) (n : ℕ) : ℝ := + (Real.sqrt (logarithmicVarianceBound κ A d₀ D α n) + + dimensionDecay (γ*α) n) / (2*Real.sqrt ε) + +lemma logarithmicSmoothingBound_tendsto_zero {κ α γ : ℝ} + (hκ : 0 < κ) (hα : 0 < α) (hγ : 0 < γ) (A d₀ D ε : ℝ) : + Tendsto (logarithmicSmoothingBound κ A d₀ D α γ ε) atTop (𝓝 0) := by + have h := (((logarithmicVarianceBound_tendsto_zero hκ hα A d₀ D).sqrt).add + (dimensionDecay_tendsto_zero (a := γ*α) (by positivity))).div_const (2*Real.sqrt ε) + unfold logarithmicSmoothingBound + simpa only [Real.sqrt_zero, zero_add, zero_div] using h + +lemma logarithmic_smoothing_of_small_set_gradient {n : ℕ} (hn : 1 < n) + (g : Disorder n) (bad : Set (Spin n)) {κ A d₀ D α γ ε t : ℝ} + (hκ : 0 ≤ κ) (hA : 0 ≤ A) (hd₀ : 0 ≤ d₀) (hD : 0 ≤ D) + (hα : 0 < α) (hε : 0 < ε) (ht : 0 ≤ t) + (horizon : t+α*Real.log n ≤ D*Real.log n) + (hoverlap : continuousDistance g t ≤ 1-ε) + (hgap : ∀ f : Observables n, + γ*FiniteLaw.variance (mass g 0) f ≤ stationaryEnergy g f) + (hdrift : ∀ (f : Observables n), ∀ r ∈ Set.Icc (0:ℝ) (D*Real.log n), ∀ y, + deriv (fun v => unweightedGradient (semigroup (coupling g) v f) y) r - + generator (coupling g) (unweightedGradient (semigroup (coupling g) r f)) y ≤ + (-κ + if y ∈ bad then A else 0)* + unweightedGradient (semigroup (coupling g) r f) y) + (havoid : ∀ u ∈ Set.Icc d₀ (D*Real.log n), ∀ x, + semigroup (coupling g) u (fun y => if y ∈ bad then 1 else 0) x ≤ + dimensionDecay (A*D+4) n) + (hfields : ∀ z ∈ Set.Icc t (t+α*Real.log n), ∀ x, semigroup (coupling g) z + (fun y => if ∃ i, (κ*α/8)*Real.log n < |field (coupling g) y i| then 1 else 0) x ≤ + dimensionDecay 4 n) : + continuousDistance g (t+α*Real.log n) ≤ + logarithmicSmoothingBound κ A d₀ D α γ ε n := by + have hlog : 0 < Real.log n := Real.log_pos (by exact_mod_cast hn) + have hs : 0 < α*Real.log n := mul_pos hα hlog + have hsne : α*Real.log n ≠ 0 := ne_of_gt hs + have h := smoothing_of_small_set_gradient g bad + hκ hA hd₀ ht hs horizon (dimensionDecay_pos (A*D+4) n).le + (dimensionDecay_pos 4 n).le hε hoverlap hgap hdrift havoid hfields + dsimp only at h + apply h.trans + apply div_le_div_of_nonneg_right _ (by positivity : 0 ≤ 2*Real.sqrt ε) + have hexpγ : Real.exp (-γ*(α*Real.log n)) = dimensionDecay (γ*α) n := by + unfold dimensionDecay; congr 1; ring + change Real.sqrt _ + Real.exp (-γ*(α*Real.log n)) ≤ + Real.sqrt (logarithmicVarianceBound κ A d₀ D α n) + dimensionDecay (γ*α) n + rw [hexpγ] + apply add_le_add _ le_rfl + apply Real.sqrt_le_sqrt + have htD : t ≤ D*Real.log n := by linarith only [horizon, hs] + have haexp : Real.exp (-κ*(α*Real.log n/2))*Real.exp (2*((κ*α/8)*Real.log n)) = + dimensionDecay (κ*α/4) n := by + rw [← Real.exp_add]; unfold dimensionDecay; congr 1; ring + have hqexp : Real.exp (A*(D*Real.log n))*dimensionDecay (A*D+4) n = + dimensionDecay 4 n := by + unfold dimensionDecay; rw [← Real.exp_add]; congr 1; ring + have hN : (n:ℝ)*dimensionDecay 4 n = dimensionDecay 3 n := by + simpa only [show (4:ℝ)-1=3 by norm_num] using nat_mul_dimensionDecay (by omega : 0 unweightedGradient (semigroup (coupling g) v f) y) r - + generator (coupling g) (unweightedGradient (semigroup (coupling g) r f)) y ≤ + (-κ + if y ∈ bad n g then A else 0)* + unweightedGradient (semigroup (coupling g) r f) y) + (havoid : ∀ D m : ℝ, 0 < D → 0 < m → + ∀ᶠ n : ℕ in atTop, ∀ g ∈ G n, ∀ u ∈ Set.Icc d₀ (D*Real.log n), ∀ x, + semigroup (coupling g) u (fun y => if y ∈ bad n g then 1 else 0) x ≤ dimensionDecay m n) + (hfields : ∀ ε δ D m : ℝ, 0 < ε → 0 < δ → 0 < D → 0 < m → + ∀ᶠ n : ℕ in atTop, ∀ g ∈ G n, ∀ z ∈ Set.Icc (0:ℝ) (D*Real.log n), + continuousDistance g z ≤ 1-ε → ∀ x, semigroup (coupling g) z + (fun y => if ∃ i, δ*Real.log n < |field (coupling g) y i| then 1 else 0) x ≤ + dimensionDecay m n) : + ∀ ε α D δ : ℝ, 0 < ε → 0 < α → 0 < δ → + ∀ᶠ n : ℕ in atTop, ∀ g ∈ G n, ∀ t : ℝ, + 0 ≤ t → t+α*Real.log n ≤ D*Real.log n → + continuousDistance g t ≤ 1-ε → continuousDistance g (t+α*Real.log n) ≤ δ := by + intro ε α D δ hε hα hδ + let D' := max 1 D + have hD : 0 < D' := lt_of_lt_of_le (by norm_num) (le_max_left 1 D) + have hm : 0 < A*D'+4 := by positivity + have hthreshold : 0 < κ*α/8 := by positivity + have hlim := logarithmicSmoothingBound_tendsto_zero hκ hα hγ A d₀ D' ε + filter_upwards [hgap, hdrift D' hD, havoid D' (A*D'+4) hD hm, + hfields ε (κ*α/8) D' 4 hε hthreshold hD (by norm_num), + hlim.eventually (gt_mem_nhds hδ), eventually_gt_atTop 1] + with n hngap hndrift hnavoid hnfields hnbound hn + intro g hg t ht hhor ho + have hlog : 0 < Real.log n := Real.log_pos (by exact_mod_cast hn) + have hhor' : t+α*Real.log n ≤ D'*Real.log n := + hhor.trans (mul_le_mul_of_nonneg_right (le_max_right 1 D) hlog.le) + apply (logarithmic_smoothing_of_small_set_gradient hn g (bad n g) + hκ.le hA hd₀ hD.le hα hε ht hhor' ho (hngap g hg) + (hndrift g hg) (hnavoid g hg) ?_).trans hnbound.le + intro z hz + apply hnfields g hg z ⟨ht.trans hz.1, hz.2.trans hhor'⟩ + exact (continuousDistance_antitone g ht hz.1).trans ho + +end SKRatio.Calculus + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Dynamics/Propagation.lean b/lean/OAI/Probability/SKRatio/Dynamics/Propagation.lean new file mode 100644 index 0000000000000000000000000000000000000000..545f27609631e843813a593d59565ce77e33ce80 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Dynamics/Propagation.lean @@ -0,0 +1,427 @@ +import Mathlib +import OAI.Probability.SKRatio.Calculus.Energy +import OAI.Probability.SKRatio.Dynamics.Concentration + +namespace OAI + +section +noncomputable section +open scoped BigOperators Topology Matrix +open ContinuousLinearMap MeasureTheory Filter +namespace SKRatio.Calculus +attribute [local instance] Classical.propDecidable + +lemma backward_observable_hasDerivAt {n : ℕ} (J : Interaction n) + (F F' : ℝ → Observables n) (hF : ∀ r, HasDerivAt F (F' r) r) + (d a u : ℝ) (x : Spin n) : + HasDerivAt (fun v : ℝ => Real.exp (a*v)*semigroup J v (F (d-v)) x) + (Real.exp (a*u)*semigroup J u + (fun y => a*F (d-u) y + generator J (F (d-u)) y - F' (d-u) y) x) u := by + have hb : HasDerivAt (fun v : ℝ => F (d-v)) (-F' (d-u)) u := by + simpa only [Function.comp_def, sub_zero, zero_sub, neg_smul, one_smul] using + (hF (d-u)).scomp u ((hasDerivAt_const u d).sub (hasDerivAt_id u)) + have h := (((hasDerivAt_id u).const_mul a).exp).mul + (hasDerivAt_pi.mp ((semigroup_hasDerivAt J u).clm_apply hb) x) + apply h.congr_deriv + simp only [mul_apply_eq_comp, Pi.add_apply, map_neg, Pi.neg_apply, id_eq, mul_one] + have hv : (fun y => a*F (d-u) y + generator J (F (d-u)) y - F' (d-u) y) = + a • F (d-u) + generator J (F (d-u)) - F' (d-u) := rfl + rw [hv, map_sub, map_add, map_smul] + change (Real.exp (a*u)*a)*semigroup J u (F (d-u)) x + + Real.exp (a*u)*(semigroup J u (generator J (F (d-u))) x - + semigroup J u (F' (d-u)) x) = + Real.exp (a*u)*(a*semigroup J u (F (d-u)) x + + semigroup J u (generator J (F (d-u))) x - semigroup J u (F' (d-u)) x) + ring + +lemma semigroup_subsolution_comparison {n : ℕ} (J : Interaction n) + (F F' : ℝ → Observables n) (hF : ∀ r, HasDerivAt F (F' r) r) + {d s a : ℝ} (hs : 0 ≤ s) + (hineq : ∀ r ∈ Set.Icc (d-s) d, ∀ y, + F' r y - generator J (F r) y ≤ a*F r y) (x : Spin n) : + F d x ≤ Real.exp (a*s)*semigroup J s (F (d-s)) x := by + let H (u : ℝ) := Real.exp (a*u)*semigroup J u (F (d-u)) x + have hD (u : ℝ) := backward_observable_hasDerivAt J F F' hF d a u x + have hmono : MonotoneOn H (Set.Icc 0 s) := by + apply monotoneOn_of_deriv_nonneg (convex_Icc _ _) + (fun u _ => (hD u).continuousAt.continuousWithinAt) + (fun u _ => (hD u).differentiableAt.differentiableWithinAt) + intro u hu + have hui : u ∈ Set.Icc (0:ℝ) s := interior_subset hu + rw [(hD u).deriv] + exact mul_nonneg (Real.exp_nonneg _) (semigroup_nonneg J u hui.1 _ (fun y => by + have h := hineq (d-u) ⟨by linarith only [hui.2], by linarith only [hui.1]⟩ y + linarith only [h]) x) + have h := hmono ⟨le_rfl, hs⟩ ⟨hs, le_rfl⟩ hs + simpa [H] using h + +lemma gradient_flow_hasDerivAt {n : ℕ} (J : Interaction n) (f : Observables n) + (r : ℝ) : + HasDerivAt (fun t => unweightedGradient (semigroup J t f)) + (fun x => deriv (fun t => unweightedGradient (semigroup J t f) x) r) r := by + apply hasDerivAt_pi.mpr + intro x + exact (unweightedGradient_hasDerivAt J f x r).differentiableAt.hasDerivAt + +lemma gradient_comparison_of_drift {n : ℕ} (J : Interaction n) (f : Observables n) + {d s a : ℝ} (hs : 0 ≤ s) + (hineq : ∀ r ∈ Set.Icc (d-s) d, ∀ y, + deriv (fun t => unweightedGradient (semigroup J t f) y) r - + generator J (unweightedGradient (semigroup J r f)) y ≤ + a*unweightedGradient (semigroup J r f) y) (x : Spin n) : + unweightedGradient (semigroup J d f) x ≤ + Real.exp (a*s)*semigroup J s (unweightedGradient (semigroup J (d-s) f)) x := + semigroup_subsolution_comparison J _ _ (gradient_flow_hasDerivAt J f) hs hineq x + +lemma gradient_envelope_of_drift {n : ℕ} (J : Interaction n) (f : Observables n) + {d a B : ℝ} (hd : 0 ≤ d) + (hineq : ∀ r ∈ Set.Icc (0:ℝ) d, ∀ y, + deriv (fun t => unweightedGradient (semigroup J t f) y) r - + generator J (unweightedGradient (semigroup J r f)) y ≤ + a*unweightedGradient (semigroup J r f) y) + (hB : ∀y, unweightedGradient f y ≤ B) (x : Spin n) : + unweightedGradient (semigroup J d f) x ≤ Real.exp (a*d)*B := by + have h := gradient_comparison_of_drift J f (d := d) (s := d) hd + (by simpa only [sub_self] using hineq) x + simp only [sub_self, semigroup_zero] at h + exact h.trans (mul_le_mul_of_nonneg_left (semigroup_le_const J d hd hB x) (Real.exp_nonneg _)) + +lemma semigroup_subsolution_small_set {n : ℕ} (J : Interaction n) + (F F' : ℝ → Observables n) (hF : ∀ r, HasDerivAt F (F' r) r) + (bad : Set (Spin n)) {κ A d₀ T d s q B : ℝ} + (hκ : 0 ≤ κ) (hA : 0 ≤ A) (hd₀ : 0 ≤ d₀) (hs : 0 ≤ s) + (hsd : s ≤ d) (hdT : d ≤ T) (hq : 0 ≤ q) (hB : 0 ≤ B) + (hpos : ∀ r ∈ Set.Icc (0:ℝ) d, ∀ y, 0 ≤ F r y) + (hineq : ∀ r ∈ Set.Icc (0:ℝ) d, ∀ y, + F' r y - generator J (F r) y ≤ (-κ + if y ∈ bad then A else 0)*F r y) + (havoid : ∀ u ∈ Set.Icc d₀ T, ∀ x, + semigroup J u (fun y => if y ∈ bad then 1 else 0) x ≤ q) + (hend : ∀y, F (d-s) y ≤ B) (x : Spin n) : + F d x ≤ Real.exp (A*d₀)*Real.exp (-κ*s)*semigroup J s (F (d-s)) x + + A*Real.exp (A*d₀)*T*Real.exp (A*T)*q*B := by + classical + have hT : 0 ≤ T := hs.trans (hsd.trans hdT) + have hor (r : ℝ) (hr : r ∈ Set.Icc (0:ℝ) d) (y : Spin n) : + F' r y - generator J (F r) y ≤ (A-κ)*F r y := by + refine (hineq r hr y).trans ?_ + apply mul_le_mul_of_nonneg_right _ (hpos r hr y) + split_ifs <;> linarith only [hA] + have hbase (v : ℝ) (hv : 0 ≤ v) (hvd : v ≤ d) : + F d x ≤ Real.exp ((A-κ)*v)*semigroup J v (F (d-v)) x := by + apply semigroup_subsolution_comparison J F F' hF hv + intro r hr y + exact hor r ⟨by linarith only [hr.1, hvd], hr.2⟩ y + have hspos : 0 ≤ semigroup J s (F (d-s)) x := + semigroup_nonneg J s hs _ (hpos (d-s) ⟨sub_nonneg.mpr hsd, by linarith only [hs]⟩) x + have herr : 0 ≤ A*Real.exp (A*d₀)*T*Real.exp (A*T)*q*B := by positivity + by_cases hlong : d₀ ≤ s + · let H (u : ℝ) := Real.exp (-κ*u)*semigroup J u (F (d-u)) x + let M : ℝ := A*Real.exp (A*T)*q*B + have hM : 0 ≤ M := by dsimp [M]; positivity + have henv (u : ℝ) (hu : u ∈ Set.Icc d₀ s) (y : Spin n) : + F (d-u) y ≤ Real.exp (A*T)*B := by + have hu0 : 0 ≤ u := hd₀.trans hu.1 + have hus : 0 ≤ s-u := sub_nonneg.mpr hu.2 + have hcmp := semigroup_subsolution_comparison J F F' hF + (d := d-u) (s := s-u) (a := A-κ) hus (by + intro r hr z + apply hor r ⟨by linarith only [hr.1, hsd], by linarith only [hr.2, hu0]⟩ z) y + rw [show d-u-(s-u) = d-s by ring] at hcmp + have hconst := semigroup_le_const J (s-u) hus hend y + have hexp : Real.exp ((A-κ)*(s-u)) ≤ Real.exp (A*T) := by + apply Real.exp_le_exp.mpr + nlinarith only [hus, hκ, hA, hs, hsd, hdT, hu0] + exact hcmp.trans ((mul_le_mul_of_nonneg_left hconst (Real.exp_nonneg _)).trans + (mul_le_mul_of_nonneg_right hexp hB)) + have hD (u : ℝ) := backward_observable_hasDerivAt J F F' hF d (-κ) u x + have hderivLower (u : ℝ) (hu : u ∈ Set.Icc d₀ s) : + -M ≤ deriv H u := by + have hu0 : 0 ≤ u := hd₀.trans hu.1 + have hru : d-u ∈ Set.Icc (0:ℝ) d := + ⟨by linarith only [hu.2, hsd], by linarith only [hu0]⟩ + let bF : Observables n := fun y => if y ∈ bad then F (d-u) y else 0 + have hdual (y : Spin n) : + -A*bF y ≤ -κ*F (d-u) y + generator J (F (d-u)) y - F' (d-u) y := by + have h := hineq (d-u) hru y + dsimp [bF] + split_ifs at * <;> linarith only [h] + have hmon := semigroup_mono J hu0 _ _ hdual x + have heq : (fun y => -A*bF y) = (-A) • bF := rfl + rw [heq, map_smul] at hmon + change -A*semigroup J u bF x ≤ _ at hmon + have hbF : 0 ≤ semigroup J u bF x := + semigroup_nonneg J u hu0 _ (fun y => by + dsimp [bF]; split_ifs <;> first | exact hpos (d-u) hru y | rfl) x + have hcF (y : Spin n) : bF y ≤ + (Real.exp (A*T)*B)*(if y ∈ bad then 1 else 0) := by + dsimp [bF] + split_ifs <;> simp only [mul_one, mul_zero] + · exact henv u hu y + · rfl + have hcbound := semigroup_mono J hu0 _ _ hcF x + have hceq : (fun y => Real.exp (A*T)*B*(if y ∈ bad then 1 else 0)) = + (Real.exp (A*T)*B) • (fun y => if y ∈ bad then 1 else 0) := rfl + rw [hceq, map_smul] at hcbound + have hcbound' : semigroup J u bF x ≤ Real.exp (A*T)*B*q := by + apply hcbound.trans + exact mul_le_mul_of_nonneg_left + (havoid u ⟨hu.1, hu.2.trans (hsd.trans hdT)⟩ x) (by positivity) + have he : Real.exp (-κ*u) ≤ 1 := Real.exp_le_one_iff.mpr (by nlinarith only [hκ, hu0]) + have hprod : Real.exp (-κ*u)*A*semigroup J u bF x ≤ M := by + dsimp [M] + calc + _ ≤ 1*A*(Real.exp (A*T)*B*q) := + mul_le_mul (mul_le_mul_of_nonneg_right he hA) hcbound' hbF (by positivity) + _ = _ := by ring + have hbound := mul_le_mul_of_nonneg_left hmon (Real.exp_nonneg (-κ*u)) + rw [(hD u).deriv] + dsimp [H] at * + linarith only [hprod, hbound] + have hmono : MonotoneOn (fun u => H u+M*u) (Set.Icc d₀ s) := by + have hf (u : ℝ) : HasDerivAt (fun u => H u+M*u) (deriv H u+M) u := by + have hdH : HasDerivAt H (deriv H u) u := (hD u).differentiableAt.hasDerivAt + simpa only [Pi.add_apply, id_eq, mul_one] using hdH.fun_add ((hasDerivAt_id u).const_mul M) + apply monotoneOn_of_deriv_nonneg (convex_Icc _ _) + (fun u _ => (hf u).continuousAt.continuousWithinAt) + (fun u _ => (hf u).differentiableAt.differentiableWithinAt) + intro u hu + rw [(hf u).deriv] + linarith only [hderivLower u (interior_subset hu)] + have hhs := hmono ⟨le_rfl, hlong⟩ ⟨hlong, le_rfl⟩ hlong + have hH : H d₀ ≤ H s+M*T := by + have h := mul_le_mul_of_nonneg_left (show s-d₀ ≤ T by linarith only [hsd, hdT, hd₀]) hM + nlinarith only [hhs, h] + have hstart := hbase d₀ hd₀ (hlong.trans hsd) + have heq : Real.exp ((A-κ)*d₀)*semigroup J d₀ (F (d-d₀)) x = + Real.exp (A*d₀)*H d₀ := by + dsimp [H] + rw [← mul_assoc, ← Real.exp_add] + congr 2 + ring + rw [heq] at hstart + calc + _ ≤ Real.exp (A*d₀)*(H s+M*T) := + hstart.trans (mul_le_mul_of_nonneg_left hH (Real.exp_nonneg _)) + _ = _ := by dsimp [H, M]; ring + · have hshort : s ≤ d₀ := (lt_of_not_ge hlong).le + have he : Real.exp ((A-κ)*s) ≤ Real.exp (A*d₀)*Real.exp (-κ*s) := by + rw [← Real.exp_add, Real.exp_le_exp] + nlinarith only [hA, hshort] + exact (hbase s hs hsd).trans ((mul_le_mul_of_nonneg_right he hspos).trans + (le_add_of_nonneg_right herr)) + +lemma unweightedGradient_nonneg {n : ℕ} (f : Observables n) (x : Spin n) : + 0 ≤ unweightedGradient f x := + Finset.sum_nonneg (fun _ _ => sq_nonneg _) + +theorem gradient_propagation_small_set {n : ℕ} (J : Interaction n) + (f : Observables n) (bad : Set (Spin n)) {κ A d₀ T d s q B : ℝ} + (hκ : 0 ≤ κ) (hA : 0 ≤ A) (hd₀ : 0 ≤ d₀) (hs : 0 ≤ s) + (hsd : s ≤ d) (hdT : d ≤ T) (hq : 0 ≤ q) (hB : 0 ≤ B) + (hineq : ∀ r ∈ Set.Icc (0:ℝ) d, ∀ y, + deriv (fun t => unweightedGradient (semigroup J t f) y) r - + generator J (unweightedGradient (semigroup J r f)) y ≤ + (-κ + if y ∈ bad then A else 0)*unweightedGradient (semigroup J r f) y) + (havoid : ∀ u ∈ Set.Icc d₀ T, ∀ x, + semigroup J u (fun y => if y ∈ bad then 1 else 0) x ≤ q) + (hend : ∀y, unweightedGradient (semigroup J (d-s) f) y ≤ B) (x : Spin n) : + unweightedGradient (semigroup J d f) x ≤ + Real.exp (A*d₀)*Real.exp (-κ*s)* + semigroup J s (unweightedGradient (semigroup J (d-s) f)) x + + A*Real.exp (A*d₀)*T*Real.exp (A*T)*q*B := by + exact semigroup_subsolution_small_set J _ _ (gradient_flow_hasDerivAt J f) bad + hκ hA hd₀ hs hsd hdT hq hB + (fun r _ y => unweightedGradient_nonneg _ y) hineq havoid hend x + +lemma tanh_mono : Monotone Real.tanh := + monotone_of_deriv_nonneg (fun r => (hasDerivAt_tanh r).differentiableAt) + (fun r => by rw [(hasDerivAt_tanh r).deriv]; exact (scalarVariance_pos r).le) + +lemma gradientWeight_exp_lower {n : ℕ} (J : Interaction n) (x : Spin n) (i : Fin n) : + Real.exp (-2*|field J x i|) ≤ gradientWeight J x i := by + let a := |field J x i| + have hat : 0 ≤ Real.tanh a := by + simpa only [Real.tanh_zero] using tanh_mono (abs_nonneg (field J x i)) + have hl : Real.exp (-2*a) ≤ 1-Real.tanh a := by + have h := exp_two_mul_one_sub_tanh a + have hm := mul_le_mul_of_nonneg_left (show 1 ≤ 1+Real.tanh a by linarith only [hat]) + (Real.exp_nonneg (-2*a)) + calc + Real.exp (-2*a) = Real.exp (-2*a)*1 := (mul_one _).symm + _ ≤ Real.exp (-2*a)*(Real.exp (2*a)*(1-Real.tanh a)) := by rwa [h] + _ = 1-Real.tanh a := by + rw [← mul_assoc, ← Real.exp_add, show -2*a+2*a=0 by ring, Real.exp_zero, one_mul] + have hspin : spin x i*Real.tanh (field J x i) ≤ Real.tanh a := by + unfold spin + cases x i <;> simp only [Bool.false_eq_true, ↓reduceIte, one_mul, neg_one_mul] + · rw [← Real.tanh_neg] + exact tanh_mono (neg_le_abs (field J x i)) + · exact tanh_mono (le_abs_self (field J x i)) + exact hl.trans (sub_le_sub_left hspin 1) + +lemma unweightedGradient_le_exp_weighted {n : ℕ} (J : Interaction n) + (f : Observables n) (x : Spin n) {H : ℝ} + (hfields : ∀ i, |field J x i| ≤ H) : + unweightedGradient f x ≤ Real.exp (2*H)*weightedGradient J f x := by + have hw (i : Fin n) : 1 ≤ Real.exp (2*H)*gradientWeight J x i := by + have h := mul_le_mul_of_nonneg_left (gradientWeight_exp_lower J x i) + (Real.exp_nonneg (2*H)) + have he : 1 ≤ Real.exp (2*H)*Real.exp (-2*|field J x i|) := by + rw [← Real.exp_add, Real.one_le_exp_iff] + linarith only [hfields i] + exact he.trans h + unfold unweightedGradient weightedGradient + rw [Finset.mul_sum] + apply Finset.sum_le_sum + intro i _ + simpa only [one_mul, mul_assoc] using + mul_le_mul_of_nonneg_right (hw i) (sq_nonneg (halfDiff i f x)) + +lemma field_gradient_expectation {n : ℕ} (J : Interaction n) (f : Observables n) + (hf : ∀ y, |f y| ≤ 1) {z H τ : ℝ} (hz : 0 ≤ z) + (htail : ∀ x, semigroup J z + (fun y => if ∃ i, H < |field J y i| then 1 else 0) x ≤ τ) (x : Spin n) : + semigroup J z (unweightedGradient f) x ≤ + Real.exp (2*H)*semigroup J z (weightedGradient J f) x + (n:ℝ)*τ := by + classical + have hp (y : Spin n) : unweightedGradient f y ≤ + Real.exp (2*H)*weightedGradient J f y + + (n:ℝ)*(if ∃ i, H < |field J y i| then 1 else 0) := by + split_ifs with h + · have hb := unweightedGradient_le_dim f hf y + have hw := mul_nonneg (Real.exp_nonneg (2*H)) (weightedGradient_nonneg J f y) + linarith only [hb, hw] + · have hb := unweightedGradient_le_exp_weighted J f y + (fun i => le_of_not_gt (fun hi => h ⟨i,hi⟩)) + simpa only [mul_zero, add_zero] using hb + have h := semigroup_mono J hz _ _ hp x + have heq : + (fun y => Real.exp (2*H)*weightedGradient J f y + + (n:ℝ)*(if ∃ i, H < |field J y i| then 1 else 0)) = + Real.exp (2*H) • weightedGradient J f + + (n:ℝ) • (fun y => if ∃ i, H < |field J y i| then 1 else 0) := rfl + rw [heq, map_add, map_smul, map_smul] at h + change semigroup J z (unweightedGradient f) x ≤ + Real.exp (2*H)*semigroup J z (weightedGradient J f) x + + (n:ℝ)*semigroup J z (fun y => if ∃ i, H < |field J y i| then 1 else 0) x at h + exact h.trans (add_le_add le_rfl (mul_le_mul_of_nonneg_left (htail x) (Nat.cast_nonneg n))) + +lemma backward_gradient_propagation {n : ℕ} (J : Interaction n) (f : Observables n) + {D u z C κ r : ℝ} (hu : 0 ≤ u) + (hprop : ∀ y, unweightedGradient (semigroup J (D-u) f) y ≤ + C*Real.exp (-κ*(z-u))* + semigroup J (z-u) (unweightedGradient (semigroup J (D-z) f)) y + (n:ℝ)*r) + (x : Spin n) : + semigroup J u (unweightedGradient (semigroup J (D-u) f)) x ≤ + C*Real.exp (-κ*(z-u))* + semigroup J z (unweightedGradient (semigroup J (D-z) f)) x + (n:ℝ)*r := by + have h := semigroup_mono J hu _ _ hprop x + have heq : + (fun y => C*Real.exp (-κ*(z-u))* + semigroup J (z-u) (unweightedGradient (semigroup J (D-z) f)) y + (n:ℝ)*r) = + (C*Real.exp (-κ*(z-u))) • + semigroup J (z-u) (unweightedGradient (semigroup J (D-z) f)) + + (fun _ => (n:ℝ)*r) := rfl + rw [heq, map_add, map_smul, semigroup_const] at h + have hsem : semigroup J u (semigroup J (z-u) + (unweightedGradient (semigroup J (D-z) f))) = + semigroup J z (unweightedGradient (semigroup J (D-z) f)) := by + rw [← mul_apply_eq_comp, + ← semigroup_add, add_sub_cancel] + change semigroup J u (unweightedGradient (semigroup J (D-u) f)) x ≤ + C*Real.exp (-κ*(z-u))* + semigroup J u (semigroup J (z-u) (unweightedGradient (semigroup J (D-z) f))) x + + (n:ℝ)*r at h + rwa [hsem] at h + +lemma energy_comparison_from_gradient {n : ℕ} (J : Interaction n) (f : Observables n) + (hf : ∀ y, |f y| ≤ 1) {D u z v C κ r H τ : ℝ} + (hu : 0 ≤ u) (hz : 0 ≤ z) (hzD : z ≤ D) (hv : 0 ≤ v) (hvzu : v ≤ z-u) + (hC : 0 ≤ C) (hκ : 0 ≤ κ) (hτ : 0 ≤ τ) + (hprop : ∀ y, unweightedGradient (semigroup J (D-u) f) y ≤ + C*Real.exp (-κ*(z-u))* + semigroup J (z-u) (unweightedGradient (semigroup J (D-z) f)) y + (n:ℝ)*r) + (htail : ∀ x, semigroup J z + (fun y => if ∃ i, H < |field J y i| then 1 else 0) x ≤ τ) (x : Spin n) : + backwardEnergy J f x D u ≤ + (2*C*Real.exp (-κ*v)*Real.exp (2*H))*backwardEnergy J f x D z + + (2*(n:ℝ)*r + 2*C*(n:ℝ)*τ) := by + have hU := backward_gradient_propagation J f hu hprop x + have hlate := field_gradient_expectation J (semigroup J (D-z) f) + (semigroup_abs_le J (sub_nonneg.mpr hzD) f hf) hz htail x + have hΓ : backwardEnergy J f x D u ≤ + 2*semigroup J u (unweightedGradient (semigroup J (D-u) f)) x := by + have h := semigroup_mono J hu _ _ + (weightedGradient_le J (semigroup J (D-u) f)) x + have heq : (fun y => 2*unweightedGradient (semigroup J (D-u) f) y) = + (2:ℝ) • unweightedGradient (semigroup J (D-u) f) := rfl + rw [heq, map_smul] at h + exact h + have hpoint := (mul_le_mul_of_nonneg_left hlate + (show 0 ≤ C*Real.exp (-κ*(z-u)) by positivity)) + have hexp : Real.exp (-κ*(z-u)) ≤ Real.exp (-κ*v) := by + apply Real.exp_le_exp.mpr + nlinarith only [hκ, hvzu] + have heone : Real.exp (-κ*(z-u)) ≤ 1 := by + apply Real.exp_le_one_iff.mpr + nlinarith only [hκ, hvzu, hv] + have hcoeff := mul_le_mul_of_nonneg_right hexp + (show 0 ≤ 2*C*Real.exp (2*H)*backwardEnergy J f x D z by + exact mul_nonneg (by positivity) (backwardEnergy_nonneg J f x D z hz)) + have herror := mul_le_mul_of_nonneg_right heone + (show 0 ≤ 2*C*(n:ℝ)*τ by positivity) + change semigroup J z (unweightedGradient (semigroup J (D-z) f)) x ≤ + Real.exp (2*H)*backwardEnergy J f x D z + (n:ℝ)*τ at hlate + change C*Real.exp (-κ*(z-u))* + semigroup J z (unweightedGradient (semigroup J (D-z) f)) x ≤ + C*Real.exp (-κ*(z-u))*(Real.exp (2*H)*backwardEnergy J f x D z+(n:ℝ)*τ) at hpoint + nlinarith only [hU, hΓ, hpoint, hcoeff, herror] + +theorem smoothing_of_small_set_gradient {n : ℕ} (g : Disorder n) + (bad : Set (Spin n)) {κ A d₀ T t s q H τ γ ε : ℝ} + (hκ : 0 ≤ κ) (hA : 0 ≤ A) (hd₀ : 0 ≤ d₀) (ht : 0 ≤ t) (hs : 0 < s) + (hT : t+s ≤ T) (hq : 0 ≤ q) (hτ : 0 ≤ τ) (hε : 0 < ε) + (hoverlap : continuousDistance g t ≤ 1-ε) + (hgap : ∀ f : Observables n, + γ*FiniteLaw.variance (mass g 0) f ≤ stationaryEnergy g f) + (hdrift : ∀ (f : Observables n), ∀ r ∈ Set.Icc (0:ℝ) T, ∀ y, + deriv (fun v => unweightedGradient (semigroup (coupling g) v f) y) r - + generator (coupling g) (unweightedGradient (semigroup (coupling g) r f)) y ≤ + (-κ + if y ∈ bad then A else 0)* + unweightedGradient (semigroup (coupling g) r f) y) + (havoid : ∀ u ∈ Set.Icc d₀ T, ∀ x, + semigroup (coupling g) u (fun y => if y ∈ bad then 1 else 0) x ≤ q) + (hfields : ∀ z ∈ Set.Icc t (t+s), ∀ x, semigroup (coupling g) z + (fun y => if ∃ i, H < |field (coupling g) y i| then 1 else 0) x ≤ τ) : + let C := Real.exp (A*d₀) + let r := A*C*T*Real.exp (A*T)*q + let a := 2*C*Real.exp (-κ*(s/2))*Real.exp (2*H) + let R := 2*(n:ℝ)*r+2*C*(n:ℝ)*τ + continuousDistance g (t+s) ≤ + (Real.sqrt (2*t*(a/s+R))+Real.exp (-γ*s))/(2*Real.sqrt ε) := by + dsimp only + apply smoothing_of_energy_comparison g ht hs (by positivity) hε hoverlap hgap + intro f hf x u hu z hz + apply energy_comparison_from_gradient (coupling g) f hf hu.1 + (by linarith only [hz.1, ht, hs]) hz.2 (by linarith only [hs]) + (by linarith only [hz.1, hu.2]) (Real.exp_nonneg _) hκ hτ _ + (hfields z ⟨by linarith only [hz.1, hs], hz.2⟩) x + intro y + have hd : t+s-u ≤ T := by linarith only [hT, hu.1] + have h := gradient_propagation_small_set (coupling g) f bad + (d := t+s-u) (s := z-u) (B := n) hκ hA hd₀ + (by linarith only [hz.1, hu.2, hs]) + (by linarith only [hz.2]) hd hq (Nat.cast_nonneg n) + (fun r hr y => hdrift f r ⟨hr.1, hr.2.trans hd⟩ y) havoid + (fun y => unweightedGradient_le_dim _ + (semigroup_abs_le (coupling g) (by linarith only [hz.2]) f hf) y) y + rw [show t+s-u-(z-u) = t+s-z by ring] at h + convert h using 1 + ring + +end SKRatio.Calculus + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Dynamics/StepMass.lean b/lean/OAI/Probability/SKRatio/Dynamics/StepMass.lean new file mode 100644 index 0000000000000000000000000000000000000000..dd4aa84116fca2cad744873b4ac0eea60ca32951 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Dynamics/StepMass.lean @@ -0,0 +1,186 @@ +import Mathlib + +namespace OAI + +section +noncomputable section +open scoped BigOperators +open Filter MeasureTheory ProbabilityTheory +open scoped Topology NNReal ENNReal +open Filter MeasureTheory ProbabilityTheory +open scoped Topology NNReal ENNReal +namespace SKRatioClock.Clock + +theorem scheffe_density {α : Type*} [MeasurableSpace α] {μ : Measure α} + {f : ℕ → α → ℝ} {g : α → ℝ} + (hf : ∀ n, Integrable (f n) μ) (hg : Integrable g μ) + (hf0 : ∀ n, ∀ᵐ x ∂μ, 0 ≤ f n x) (hg0 : ∀ᵐ x ∂μ, 0 ≤ g x) + (hlim : ∀ᵐ x ∂μ, Tendsto (fun n => f n x) atTop (𝓝 (g x))) + (hmass : Tendsto (fun n => ∫ x, f n x ∂μ) atTop (𝓝 (∫ x, g x ∂μ))) : + Tendsto (fun n => ∫ x, |f n x-g x| ∂μ) atTop (𝓝 0) := by + have hmin : Tendsto (fun n => ∫ x, min (f n x) (g x) ∂μ) + atTop (𝓝 (∫ x, g x ∂μ)) := by + apply tendsto_integral_of_dominated_convergence g + · intro n + exact (hf n).aestronglyMeasurable.inf hg.aestronglyMeasurable + · exact hg + · intro n + filter_upwards [hf0 n,hg0] with x hx hy + rw [Real.norm_eq_abs, abs_of_nonneg (le_min hx hy)] + exact min_le_right _ _ + · filter_upwards [hlim] with x hx + simpa using hx.min (tendsto_const_nhds (x := g x)) + have ht := (hmass.add (tendsto_const_nhds (x := ∫ x, g x ∂μ))).sub + (hmin.const_mul 2) + have hz : (∫ x, g x ∂μ)+(∫ x, g x ∂μ)-2*(∫ x, g x ∂μ)=0 := by ring + rw [hz] at ht + apply ht.congr + intro n + rw [← integral_add (hf n) hg, ← integral_const_mul] + have hi : Integrable (fun x => f n x+g x) μ := (hf n).add hg + have hj : Integrable (fun x => 2*min (f n x) (g x)) μ := ((hf n).inf hg).const_mul 2 + rw [← integral_sub hi hj] + congr 1 + ext x + rcases le_total (f n x) (g x) with h|h + · rw [min_eq_left h,abs_of_nonpos (sub_nonpos.mpr h)] + ring + · rw [min_eq_right h,abs_of_nonneg (sub_nonneg.mpr h)] + ring + +theorem scheffe_density_filter {ι : Type*} {l : Filter ι} [l.IsCountablyGenerated] + {α : Type*} [MeasurableSpace α] {μ : Measure α} + {f : ι → α → ℝ} {g : α → ℝ} + (hf : ∀ᶠ n in l, Integrable (f n) μ) (hg : Integrable g μ) + (hf0 : ∀ᶠ n in l, ∀ᵐ x ∂μ, 0 ≤ f n x) (hg0 : ∀ᵐ x ∂μ, 0 ≤ g x) + (hlim : ∀ᵐ x ∂μ, Tendsto (fun n => f n x) l (𝓝 (g x))) + (hmass : Tendsto (fun n => ∫ x, f n x ∂μ) l (𝓝 (∫ x, g x ∂μ))) : + Tendsto (fun n => ∫ x, |f n x-g x| ∂μ) l (𝓝 0) := by + have hmin : Tendsto (fun n => ∫ x, min (f n x) (g x) ∂μ) + l (𝓝 (∫ x, g x ∂μ)) := by + apply tendsto_integral_filter_of_dominated_convergence g + · filter_upwards [hf] with n hn + exact hn.aestronglyMeasurable.inf hg.aestronglyMeasurable + · filter_upwards [hf0] with n hn + filter_upwards [hn,hg0] with x hx hy + rw [Real.norm_eq_abs, abs_of_nonneg (le_min hx hy)] + exact min_le_right _ _ + · exact hg + · filter_upwards [hlim] with x hx + simpa using hx.min (tendsto_const_nhds (x := g x)) + have ht := (hmass.add (tendsto_const_nhds (x := ∫ x, g x ∂μ))).sub + (hmin.const_mul 2) + have hz : (∫ x, g x ∂μ)+(∫ x, g x ∂μ)-2*(∫ x, g x ∂μ)=0 := by ring + rw [hz] at ht + apply ht.congr' + filter_upwards [hf] with n hn + rw [← integral_add hn hg, ← integral_const_mul] + have hi : Integrable (fun x => f n x+g x) μ := hn.add hg + have hj : Integrable (fun x => 2*min (f n x) (g x)) μ := (hn.inf hg).const_mul 2 + rw [← integral_sub hi hj] + congr 1 + ext x + rcases le_total (f n x) (g x) with h|h + · rw [min_eq_left h,abs_of_nonpos (sub_nonpos.mpr h)] + ring + · rw [min_eq_right h,abs_of_nonneg (sub_nonneg.mpr h)] + ring + +noncomputable def stepMass (p : ℕ → ℝ) (x : ℝ) : ℝ := + ∑' j : ℕ, (Set.Ico (j:ℝ) (j+1)).indicator (fun _ => p j) x + +lemma stepMass_of_nonneg (p : ℕ → ℝ) {x : ℝ} (hx : 0 ≤ x) : + stepMass p x = p ⌊x⌋₊ := by + unfold stepMass + rw [tsum_eq_single ⌊x⌋₊] + · exact Set.indicator_of_mem (show x ∈ Set.Ico (⌊x⌋₊:ℝ) (⌊x⌋₊+1) from + ⟨Nat.floor_le hx,Nat.lt_floor_add_one x⟩) _ + · intro j hj + apply Set.indicator_of_notMem + intro h + exact hj ((Nat.floor_eq_iff hx).mpr h).symm + +lemma stepMass_of_neg (p : ℕ → ℝ) {x : ℝ} (hx : x < 0) : stepMass p x = 0 := by + unfold stepMass + suffices hh : (fun j : ℕ => (Set.Ico (j:ℝ) (j+1)).indicator (fun _ => p j) x) = 0 by + rw [hh] + change (∑' _ : ℕ, (0:ℝ)) = 0 + exact tsum_zero + ext j + apply Set.indicator_of_notMem + intro h + exact (not_le.mpr hx) ((Nat.cast_nonneg j).trans h.1) + +lemma stepMass_nonneg {p : ℕ → ℝ} (hp : ∀ j, 0 ≤ p j) (x : ℝ) : 0 ≤ stepMass p x := by + by_cases hx : 0 ≤ x + · rw [stepMass_of_nonneg p hx] + exact hp _ + · rw [stepMass_of_neg p (lt_of_not_ge hx)] + +lemma integral_step_interval (p : ℕ → ℝ) (j : ℕ) : + ∫ x : ℝ, (Set.Ico (j:ℝ) (j+1)).indicator (fun _ => p j) x = p j := by + rw [integral_indicator measurableSet_Ico,integral_const] + simp [Measure.real,Real.volume_Ico] + +lemma integrable_step_interval (p : ℕ → ℝ) (j : ℕ) : + Integrable ((Set.Ico (j:ℝ) (j+1)).indicator (fun _ => p j)) := + (integrableOn_const (μ := volume) (C := p j) (by simp [Real.volume_Ico])).integrable_indicator + measurableSet_Ico + +lemma integral_step_interval_norm (p : ℕ → ℝ) (j : ℕ) : + ∫ x : ℝ, ‖(Set.Ico (j:ℝ) (j+1)).indicator (fun _ => p j) x‖ = |p j| := by + rw [← integral_step_interval (fun j => |p j|) j] + congr 1 + ext x + by_cases hx : x ∈ Set.Ico (j:ℝ) (j+1) + · simp [Set.indicator_of_mem hx] + · simp [Set.indicator_of_notMem hx] + +lemma integral_stepMass {p : ℕ → ℝ} (hp : Summable p) : + ∫ x, stepMass p x = ∑' j, p j := by + unfold stepMass + rw [← integral_tsum_of_summable_integral_norm (integrable_step_interval p)] + · simp only [integral_step_interval] + · simpa only [integral_step_interval_norm] using hp.abs + +lemma integrable_stepMass {p : ℕ → ℝ} (hp : HasSum p 1) : Integrable (stepMass p) := by + apply Integrable.of_integral_ne_zero + rw [integral_stepMass hp.summable,hp.tsum_eq] + norm_num + +noncomputable def histogram (q : ℝ) (n : ℕ) (p : ℕ → ℝ) (x : ℝ) : ℝ := + Real.sqrt n*stepMass p (q*n+x*Real.sqrt n) + +lemma integrable_histogram {p : ℕ → ℝ} (hp : HasSum p 1) (q : ℝ) {n : ℕ} + (hn : 0 < n) : Integrable (histogram q n p) := by + have hs : Real.sqrt (n:ℝ) ≠ 0 := by positivity + have hi := ((integrable_stepMass hp).comp_add_right (q*n)).comp_mul_right' hs + convert! hi.const_mul (Real.sqrt (n:ℝ)) using 1 + ext x + simp only [histogram,add_comm] + +lemma integral_histogram {p : ℕ → ℝ} (hp : HasSum p 1) (q : ℝ) {n : ℕ} + (hn : 0 < n) : ∫ x, histogram q n p x = 1 := by + have hs : Real.sqrt (n:ℝ) ≠ 0 := by positivity + unfold histogram + rw [integral_const_mul] + have hh : (fun x : ℝ => stepMass p (q*n+x*Real.sqrt n)) = + (fun x : ℝ => (fun t => stepMass p (t+q*n)) (Real.sqrt n*x)) := by + ext x + congr 1 + ring + rw [hh,Measure.integral_comp_mul_left (fun t : ℝ => stepMass p (t+q*n)) + (Real.sqrt (n:ℝ)),integral_add_right_eq_self, + integral_stepMass hp.summable,hp.tsum_eq,smul_eq_mul,mul_one, + abs_of_nonneg (inv_nonneg.mpr (Real.sqrt_nonneg _)),mul_inv_cancel₀ hs] + +lemma histogram_nonneg {p : ℕ → ℝ} (hp : ∀ j, 0 ≤ p j) (q : ℝ) (n : ℕ) (x : ℝ) : + 0 ≤ histogram q n p x := + mul_nonneg (Real.sqrt_nonneg _) (stepMass_nonneg hp _) + +end SKRatioClock.Clock + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Dynamics/SumPoissonMass.lean b/lean/OAI/Probability/SKRatio/Dynamics/SumPoissonMass.lean new file mode 100644 index 0000000000000000000000000000000000000000..f2d1753e5b54de06520ce9f83b8cf185072ff348 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Dynamics/SumPoissonMass.lean @@ -0,0 +1,111 @@ +import Mathlib +import OAI.Probability.SKRatio.Dynamics.LogQuadratic +import OAI.Probability.SKRatio.Dynamics.StepMass + +namespace OAI + +section +noncomputable section +open scoped BigOperators +open Filter MeasureTheory ProbabilityTheory +open scoped Topology NNReal ENNReal +open Filter MeasureTheory ProbabilityTheory +open scoped Topology NNReal ENNReal +namespace SKRatioClock.Clock + +lemma hasSum_poissonMass (m : ℝ) : HasSum (poissonMass m) 1 := by + convert! (NormedSpace.expSeries_div_hasSum_exp m).mul_left (Real.exp (-m)) using 1 + · ext n + simp only [poissonMass,mul_div_assoc] + · simp [← Real.exp_eq_exp_ℝ, ← Real.exp_add] + +lemma hasSum_binomialMass (q : ℝ) (n : ℕ) : HasSum (binomialMass q n) 1 := by + have hh : HasSum (binomialMass q n) + (∑ k ∈ Finset.range (n+1), binomialMass q n k) := + hasSum_sum_of_ne_finset_zero (s := Finset.range (n+1)) + (f := binomialMass q n) (by + intro k hk + have hnk : n < k := by simpa only [Finset.mem_range,not_lt,Nat.add_one_le_iff] using hk + simp only [binomialMass,Nat.choose_eq_zero_of_lt hnk,Nat.cast_zero,zero_mul]) + convert! hh using 1 + have hb := add_pow q (1-q) n + have hq : q+(1-q)=1 := by ring + rw [hq,one_pow] at hb + rw [hb] + apply Finset.sum_congr rfl + intro i hi + simp only [binomialMass] + ring + +lemma poisson_density_pointwise {q : ℝ} (hq : 0 < q) (y x : ℝ) : + Tendsto (fun n : ℕ => histogram q n (poissonMass (q*n+y*Real.sqrt n)) x) + atTop (𝓝 (gaussianPDFReal y ⟨q,hq.le⟩ x)) := by + have hh := poisson_histogram_pointwise hq x y + rw [gaussian_formula hq x y] at hh + apply hh.congr' + filter_upwards [(center_tendsto_atTop hq x).eventually (eventually_ge_atTop 0)] with n hn + simp only [histogram,stepMass_of_nonneg _ hn,centralIndex] + +lemma binomial_density_pointwise {q : ℝ} (hql : 0 < q) (hqu : q < 1) (x : ℝ) : + Tendsto (fun n : ℕ => histogram q n (binomialMass q n) x) + atTop (𝓝 (gaussianPDFReal 0 ⟨q*(1-q),mul_nonneg hql.le (by linarith)⟩ x)) := by + apply (binomial_histogram_pointwise hql hqu x).congr' + filter_upwards [(center_tendsto_atTop hql x).eventually (eventually_ge_atTop 0)] with n hn + simp only [histogram,stepMass_of_nonneg _ hn,centralIndex] + +theorem poisson_density_L1 {q : ℝ} (hq : 0 < q) (y : ℝ) : + Tendsto (fun n : ℕ => ∫ x : ℝ, + |histogram q n (poissonMass (q*n+y*Real.sqrt n)) x- + gaussianPDFReal y ⟨q,hq.le⟩ x|) atTop (𝓝 0) := by + apply scheffe_density_filter + · filter_upwards [eventually_gt_atTop 0] with n hn + exact integrable_histogram (hasSum_poissonMass _) q hn + · exact integrable_gaussianPDFReal _ _ + · filter_upwards [(center_tendsto_atTop hq y).eventually (eventually_ge_atTop 0)] with n hn + exact Filter.Eventually.of_forall (histogram_nonneg (fun j => by + unfold poissonMass + positivity) q n) + · exact Filter.Eventually.of_forall (gaussianPDFReal_nonneg _ _) + · exact Filter.Eventually.of_forall (poisson_density_pointwise hq y) + · have hv : (⟨q,hq.le⟩ : ℝ≥0) ≠ 0 := by + intro h + have hh := congrArg (fun r : ℝ≥0 => (r:ℝ)) h + exact hq.ne' hh + rw [integral_gaussianPDFReal_eq_one _ hv] + apply tendsto_const_nhds.congr' + filter_upwards [eventually_gt_atTop 0] with n hn + exact (integral_histogram (hasSum_poissonMass _) q hn).symm + +theorem binomial_density_L1 {q : ℝ} (hql : 0 < q) (hqu : q < 1) : + Tendsto (fun n : ℕ => ∫ x : ℝ, + |histogram q n (binomialMass q n) x- + gaussianPDFReal 0 ⟨q*(1-q),mul_nonneg hql.le (by linarith)⟩ x|) atTop (𝓝 0) := by + apply scheffe_density_filter + · filter_upwards [eventually_gt_atTop 0] with n hn + exact integrable_histogram (hasSum_binomialMass q n) q hn + · exact integrable_gaussianPDFReal _ _ + · apply Filter.Eventually.of_forall + intro n + exact Filter.Eventually.of_forall (histogram_nonneg (fun j => by + unfold binomialMass + positivity) q n) + · exact Filter.Eventually.of_forall (gaussianPDFReal_nonneg _ _) + · exact Filter.Eventually.of_forall (binomial_density_pointwise hql hqu) + · have hv : (⟨q*(1-q),mul_nonneg hql.le (by linarith)⟩ : ℝ≥0) ≠ 0 := by + intro h + have hh := congrArg (fun r : ℝ≥0 => (r:ℝ)) h + exact (mul_pos hql (by linarith : 0 < 1-q)).ne' hh + rw [integral_gaussianPDFReal_eq_one _ hv] + apply tendsto_const_nhds.congr' + filter_upwards [eventually_gt_atTop 0] with n hn + exact (integral_histogram (hasSum_binomialMass q n) q hn).symm + +end SKRatioClock.Clock + +open MeasureTheory Filter +open scoped Topology NNReal ENNReal + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Dynamics/TestHistogram.lean b/lean/OAI/Probability/SKRatio/Dynamics/TestHistogram.lean new file mode 100644 index 0000000000000000000000000000000000000000..6546d897ca6ee23e571e39fb76cc559b5d323015 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Dynamics/TestHistogram.lean @@ -0,0 +1,91 @@ +import Mathlib +import OAI.Probability.SKRatio.Dynamics.StepMass + +namespace OAI + +section +noncomputable section +open scoped BigOperators +open Filter MeasureTheory ProbabilityTheory +open scoped Topology NNReal ENNReal +open Filter MeasureTheory ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter +open scoped Topology NNReal ENNReal +open MeasureTheory Filter ProbabilityTheory +open scoped Topology NNReal ENNReal +open MeasureTheory Filter +open scoped Topology +open MeasureTheory Filter ProbabilityTheory +open scoped Topology NNReal ENNReal +namespace SKRatioClock.Clock + +lemma measurable_stepMass (p : ℕ → ℝ) : Measurable (stepMass p) := by + unfold stepMass + exact Measurable.tsum (fun _ => measurable_const.indicator measurableSet_Ico) + +lemma stepMass_abs_le {a : ℕ → ℝ} {B : ℝ} (hB : 0 ≤ B) (ha : ∀ j, |a j| ≤ B) + (x : ℝ) : |stepMass a x| ≤ B := by + by_cases hx : 0 ≤ x + · rw [stepMass_of_nonneg _ hx] + exact ha _ + · rw [stepMass_of_neg _ (lt_of_not_ge hx),abs_zero] + exact hB + +lemma stepMass_mul (p a : ℕ → ℝ) (x : ℝ) : + stepMass p x*stepMass a x=stepMass (fun j => p j*a j) x := by + by_cases hx : 0 ≤ x + · simp only [stepMass_of_nonneg _ hx] + · simp only [stepMass_of_neg _ (lt_of_not_ge hx),mul_zero] + +lemma summable_mul_bounded {p a : ℕ → ℝ} {B : ℝ} (hp : Summable p) + (ha : ∀ j, |a j| ≤ B) : Summable (fun j => p j*a j) := by + apply Summable.of_norm_bounded (hp.abs.mul_right B) + intro j + simpa only [Real.norm_eq_abs,abs_mul] using mul_le_mul_of_nonneg_left (ha j) (abs_nonneg (p j)) + +lemma integral_histogram_summable {p : ℕ → ℝ} (hp : Summable p) (q : ℝ) {n : ℕ} + (hn : 0 < n) : ∫ x : ℝ, histogram q n p x = ∑' j, p j := by + have hs : Real.sqrt (n:ℝ) ≠ 0 := by positivity + unfold histogram + rw [integral_const_mul] + have hh : (fun x : ℝ => stepMass p (q*n+x*Real.sqrt n)) = + (fun x : ℝ => (fun t => stepMass p (t+q*n)) (Real.sqrt n*x)) := by + ext x + congr 1 + ring + rw [hh,Measure.integral_comp_mul_left (fun t : ℝ => stepMass p (t+q*n)) + (Real.sqrt (n:ℝ)),integral_add_right_eq_self,integral_stepMass hp,smul_eq_mul, + abs_of_nonneg (inv_nonneg.mpr (Real.sqrt_nonneg _)),← mul_assoc,mul_inv_cancel₀ hs,one_mul] + +noncomputable def testHistogram (q : ℝ) (n : ℕ) (a : ℕ → ℝ) (x : ℝ) : ℝ := + stepMass a (q*n+x*Real.sqrt n) + +lemma measurable_testHistogram (q : ℝ) (n : ℕ) (a : ℕ → ℝ) : + Measurable (testHistogram q n a) := by + apply (measurable_stepMass a).comp + fun_prop + +lemma testHistogram_bound {a : ℕ → ℝ} {B : ℝ} (hB : 0 ≤ B) (ha : ∀ j, |a j| ≤ B) + (q : ℝ) (n : ℕ) (x : ℝ) : |testHistogram q n a x| ≤ B := + stepMass_abs_le hB ha _ + +lemma integral_histogram_test {p a : ℕ → ℝ} {B : ℝ} (hp : Summable p) + (ha : ∀ j, |a j| ≤ B) (q : ℝ) {n : ℕ} (hn : 0 < n) : + (∫ x : ℝ, histogram q n p x*testHistogram q n a x) = ∑' j, p j*a j := by + have he (x : ℝ) : histogram q n p x*testHistogram q n a x = + histogram q n (fun j => p j*a j) x := by + unfold histogram testHistogram + rw [mul_assoc,stepMass_mul] + simp_rw [he] + exact integral_histogram_summable (summable_mul_bounded hp ha) q hn + +end SKRatioClock.Clock + +open MeasureTheory Filter ProbabilityTheory +open scoped Topology NNReal ENNReal + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Entropy/AnnealedTransfer.lean b/lean/OAI/Probability/SKRatio/Entropy/AnnealedTransfer.lean new file mode 100644 index 0000000000000000000000000000000000000000..2eb2087a7ab9c22d47e3fcc9f52a83a81c58d203 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Entropy/AnnealedTransfer.lean @@ -0,0 +1,139 @@ +import Mathlib +import OAI.Probability.SKRatio.Gaussian.GaussianEvents +import OAI.Probability.SKRatio.Entropy.LogPartition + +namespace OAI + +section +noncomputable section +open scoped BigOperators Topology ENNReal NNReal +open MeasureTheory ProbabilityTheory Real Filter +namespace SKRatio.Planted +open Calculus +attribute [local instance] Classical.propDecidable +variable {n : ℕ} + +def badMass (B : Set (Disorder n)) (g : Disorder n) : ℝ := + FiniteLaw.mean (mass g 0) (fun x => if gauge x g ∈ B then 1 else 0) + +lemma badMass_eq_div (B : Set (Disorder n)) (g : Disorder n) : + badMass B g = badWeight B g / partition g 0 := by + unfold badMass FiniteLaw.mean badWeight + rw [Finset.sum_div] + apply Finset.sum_congr rfl + intro x _ + by_cases hx : gauge x g ∈ B <;> simp [hx,mass] + +lemma badMass_nonneg (B : Set (Disorder n)) (g : Disorder n) : 0 ≤ badMass B g := by + rw [badMass_eq_div] + exact div_nonneg (badWeight_nonneg B g) (partition_pos g 0).le + +lemma badWeight_measurable {B : Set (Disorder n)} (hB : MeasurableSet B) : + Measurable (badWeight B) := by + apply Finset.measurable_sum + intro x _ + exact (continuous_weight 0 x).measurable.indicator + (hB.preimage (gauge_continuous x).measurable) + +lemma badMass_measurable {B : Set (Disorder n)} (hB : MeasurableSet B) : + Measurable (badMass B) := by + change Measurable (fun g => badMass B g) + simp_rw [badMass_eq_div] + exact (badWeight_measurable hB).div (continuous_partition 0).measurable + +lemma badWeight_probability {β κ : ℝ} {B : Set (Disorder n)} + (hB : MeasurableSet B) + (hp : law β n B ≤ ENNReal.ofReal (exp (-κ*n))) : + disorderLaw β n {g | ((2:ℝ)^n*exp (normalizingExponent β n))* + exp (-(3*κ/4)*n) < badWeight B g} ≤ ENNReal.ofReal (exp (-(κ/4)*n)) := by + let M := (2:ℝ)^n*exp (normalizingExponent β n) + have hM : 0 < M := by dsimp [M]; positivity + have hthreshold : 0 < M*exp (-(3*κ/4)*n) := mul_pos hM (exp_pos _) + have hpR : (law β n).real B ≤ exp (-κ*n) := by + have ht := ENNReal.toReal_mono (ENNReal.ofReal_ne_top) hp + change (law β n B).toReal ≤ _ + simpa only [ENNReal.toReal_ofReal (exp_pos _).le] using ht + have hi := mul_meas_ge_le_integral_of_nonneg + (μ := disorderLaw β n) (f := badWeight B) + (Eventually.of_forall (badWeight_nonneg B)) (badWeight_integrable β hB) + (M*exp (-(3*κ/4)*n)) + have hs : {g : Disorder n | M*exp (-(3*κ/4)*n) < badWeight B g} ⊆ + {g | M*exp (-(3*κ/4)*n) ≤ badWeight B g} := by + intro g hg + exact (show M*exp (-(3*κ/4)*n) < badWeight B g from hg).le + have hl := mul_le_mul_of_nonneg_left (measureReal_mono (μ := disorderLaw β n) hs) + hthreshold.le + rw [integral_badWeight β hB] at hi + change _ ≤ M*(law β n).real B at hi + have hb := hl.trans (hi.trans (mul_le_mul_of_nonneg_left hpR hM.le)) + have he : M*exp (-κ*n)/(M*exp (-(3*κ/4)*n)) = exp (-(κ/4)*n) := by + rw [mul_div_mul_left _ _ hM.ne',←exp_sub] + congr 1 + ring + have hreal : (disorderLaw β n).real + {g | M*exp (-(3*κ/4)*n) < badWeight B g} ≤ exp (-(κ/4)*n) := by + rw [←he] + apply (le_div_iff₀ hthreshold).mpr + simpa only [mul_comm] using hb + rw [←ENNReal.ofReal_toReal (measure_ne_top _ _)] + exact ENNReal.ofReal_le_ofReal hreal + +lemma badMass_event_subset (β κ : ℝ) (B : Set (Disorder n)) : + {g : Disorder n | exp (-(κ/2)*n) < badMass B g} ⊆ + {g | partition g 0 < ((2:ℝ)^n*exp (normalizingExponent β n))*exp (-(κ/4)*n)} ∪ + {g | ((2:ℝ)^n*exp (normalizingExponent β n))*exp (-(3*κ/4)*n) < badWeight B g} := by + intro g hg + by_contra h + simp only [Set.mem_union,Set.mem_ofPred_eq,not_or,not_lt] at h + have he : (((2:ℝ)^n*exp (normalizingExponent β n))*exp (-(κ/4)*n))* + exp (-(κ/2)*n) = ((2:ℝ)^n*exp (normalizingExponent β n))*exp (-(3*κ/4)*n) := by + rw [mul_assoc,←exp_add] + congr 2 + ring + have hh := mul_le_mul_of_nonneg_right h.1 (exp_pos (-(κ/2)*n)).le + rw [he] at hh + have hb : badMass B g ≤ exp (-(κ/2)*n) := by + rw [badMass_eq_div] + apply (div_le_iff₀ (partition_pos g 0)).mpr + simpa only [mul_comm] using h.2.trans hh + exact not_le_of_gt hg hb + +theorem annealed_transfer {β κ : ℝ} (hβ : β^2 ≤ 1/2) (hκ : 0 < κ) + (B : ∀ n : ℕ, Set (Disorder n)) (hB : ∀ n, MeasurableSet (B n)) + (hp : ∀ᶠ n : ℕ in atTop, law β n (B n) ≤ ENNReal.ofReal (exp (-κ*n))) : + Tendsto (fun n : ℕ => disorderLaw β n + {g | exp (-(κ/2)*n) < badMass (B n) g}) atTop (𝓝 0) := by + have hpart := partition_lower_high_probability hβ (show 0 < κ/4 by positivity) + have he : Tendsto (fun n : ℕ => ENNReal.ofReal (exp (-(κ/4)*n))) atTop (𝓝 0) := by + have hr := Gaussian.nat_pow_exp_neg_tendsto (show 0 < κ/4 by positivity) 0 + simp only [pow_zero,one_mul] at hr + simpa only [Function.comp_def,ENNReal.ofReal_zero] using + ENNReal.continuous_ofReal.continuousAt.tendsto.comp hr + apply tendsto_of_tendsto_of_tendsto_of_le_of_le' + tendsto_const_nhds (by simpa only [add_zero] using hpart.add he) + (Eventually.of_forall fun n => (show (0:ℝ≥0∞) ≤ disorderLaw β n + {g | exp (-(κ/2)*n) < badMass (B n) g} from bot_le)) + filter_upwards [hp] with n hn + exact (measure_mono (badMass_event_subset β κ (B n))).trans + ((measure_union_le _ _).trans (add_le_add le_rfl (badWeight_probability (hB n) hn))) + +theorem annealed_transfer_events {β κ : ℝ} (hβ : β^2 ≤ 1/2) (hκ : 0 < κ) + (B : ∀ n : ℕ, Set (Disorder n)) (hB : ∀ n, MeasurableSet (B n)) + (hp : ∀ᶠ n : ℕ in atTop, law β n (B n) ≤ ENNReal.ofReal (exp (-κ*n))) : + ∃ G : ∀ n : ℕ, Set (Disorder n), + (∀ n, MeasurableSet (G n)) ∧ + Tendsto (fun n => disorderLaw β n (G n)ᶜ) atTop (𝓝 0) ∧ + ∀ n, ∀ g ∈ G n, badMass (B n) g ≤ exp (-(κ/2)*n) := by + refine ⟨fun n => {g | badMass (B n) g ≤ exp (-(κ/2)*n)},?_,?_,?_⟩ + · intro n + exact measurableSet_le (badMass_measurable (hB n)) measurable_const + · simpa only [Set.compl_ofPred,not_le] using annealed_transfer hβ hκ B hB hp + · intro n g hg + exact hg + +end SKRatio.Planted + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Entropy/BadAvoidance.lean b/lean/OAI/Probability/SKRatio/Entropy/BadAvoidance.lean new file mode 100644 index 0000000000000000000000000000000000000000..c4beb649212272cfc2bc0bf773d0f932d2a03832 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Entropy/BadAvoidance.lean @@ -0,0 +1,195 @@ +import Mathlib +import OAI.Probability.SKRatio.Entropy.Entropy +import OAI.Probability.SKRatio.Gaussian.HammingGeometry + +namespace OAI + +section +noncomputable section +open scoped BigOperators Topology Matrix +open MeasureTheory Filter ContinuousLinearMap +namespace SKRatio.Calculus +attribute [local instance] Classical.propDecidable + +lemma semigroup_small_set_of_mgf {n : ℕ} (J : Interaction n) (B : Set (Spin n)) + (f : Observables n) {d C a : ℝ} (hd : 0 ≤ d) + (hf : ∀ y ∈ B, f y = 0) + (hmean : ∀ x, a ≤ semigroup J d f x) + (hmgf : ∀ x, semigroup J d (fun y => Real.exp (-(f y-semigroup J d f x))) x ≤ + Real.exp C) (x : Spin n) : + semigroup J d (fun y => if y ∈ B then 1 else 0) x ≤ Real.exp (C-a) := by + have hp (y : Spin n) : Real.exp a*(if y ∈ B then 1 else 0) ≤ + Real.exp (-(f y-semigroup J d f x)) := by + by_cases hy : y ∈ B + · simp only [hy,↓reduceIte,mul_one,hf y hy,zero_sub,neg_neg] + exact Real.exp_le_exp.mpr (hmean x) + · simp only [hy,↓reduceIte,mul_zero] + exact Real.exp_nonneg _ + have h := semigroup_mono J hd _ _ hp x + change semigroup J d (Real.exp a • (fun y => if y ∈ B then 1 else 0)) x ≤ _ at h + rw [map_smul] at h + change Real.exp a*semigroup J d (fun y => if y ∈ B then 1 else 0) x ≤ _ at h + have hm := mul_le_mul_of_nonneg_left (h.trans (hmgf x)) (Real.exp_nonneg (-a)) + simpa only [← mul_assoc,← Real.exp_add,neg_add_cancel,Real.exp_zero,one_mul, + show -a+C=C-a by ring] using hm + +lemma bad_avoidance_burnin {n : ℕ} (hn : 0 < n) (g : Disorder n) + (B : Set (Spin n)) {d A κ δ : ℝ} (hd : 0 ≤ d) (hA : 0 ≤ A) + (hκ : 0 < κ) (hδ : 0 ≤ δ) + (hsmall : FiniteLaw.mean (mass g 0) + (fun y => if y ∈ hammingNeighborhood B δ then 1 else 0) ≤ Real.exp (-(κ/2*n))) + (hentropy : ∀ x, transitionEntropy g x d ≤ κ*n/8) + (hsize : Real.log 2 ≤ κ*n/8) + (hdrift : ∀ f : Observables n, ∀ r ∈ Set.Icc (0:ℝ) d, ∀ y, + deriv (fun v => unweightedGradient (semigroup (coupling g) v f) y) r - + generator (coupling g) (unweightedGradient (semigroup (coupling g) r f)) y ≤ + A*unweightedGradient (semigroup (coupling g) r f) y) (x : Spin n) : + let Q := Real.exp (A*d)/4 + semigroup (coupling g) d (fun y => if y ∈ B then 1 else 0) x ≤ + Real.exp (2*Real.exp (2*Real.sqrt Q)*(d*Q)-δ*Real.sqrt n/2) := by + dsimp only + by_cases hB : B.Nonempty + · have hhalf (x : Spin n) : FiniteLaw.mean (continuousKernel (coupling g) d x) + (fun y => if y ∈ hammingNeighborhood B δ then 1 else 0) ≤ 1/2 := by + have h := FiniteLaw.event_entropy_bound (continuousKernel (coupling g) d x) (mass g 0) + (hammingNeighborhood B δ) (continuousKernel_nonneg (coupling g) d hd x) + (mass_pos g 0) (continuousKernel_sum _ d x) (sum_mass g 0) hsmall + change (κ/2*n)*FiniteLaw.mean _ _ ≤ transitionEntropy g x d+Real.log 2 at h + have hkn : 0 < κ*(n:ℝ) := mul_pos hκ (Nat.cast_pos.mpr hn) + nlinarith only [h,hentropy x,hsize,hkn] + have hmean (x : Spin n) : δ*Real.sqrt n/2 ≤ + semigroup (coupling g) d (distanceObservable B) x := by + rw [semigroup_eq_kernel] + exact distanceObservable_mean_lower hn B hB _ + (continuousKernel_nonneg _ d hd x) (continuousKernel_sum _ d x) hδ (hhalf x) + have henv (r : ℝ) (hr : r ∈ Set.Icc (0:ℝ) d) (y : Spin n) : + unweightedGradient (semigroup (coupling g) r (distanceObservable B)) y ≤ + Real.exp (A*d)/4 := by + calc + _ ≤ Real.exp (A*r)*(1/4) := gradient_envelope_of_drift (coupling g) _ hr.1 + (fun v hv => hdrift _ v ⟨hv.1,hv.2.trans hr.2⟩) (unweightedGradient_distanceObservable hn B hB) y + _ ≤ _ := by + simpa only [mul_one_div] using mul_le_mul_of_nonneg_right + (Real.exp_le_exp.mpr (mul_le_mul_of_nonneg_left hr.2 hA)) (by norm_num : (0:ℝ)≤1/4) + apply semigroup_small_set_of_mgf (coupling g) B (distanceObservable B) hd + (distanceObservable_zero B) hmean _ x + intro z + have h := semigroup_jump_mgf (coupling g) (distanceObservable B) d hd + (fun _ => Real.exp (A*d)/4) (Real.exp (A*d)/4) (-1) intervalIntegrable_const + (fun _ _ => le_rfl) henv z + simpa only [neg_one_mul,neg_sq,one_pow,mul_one,abs_neg,abs_one, + intervalIntegral.integral_const,sub_zero,smul_eq_mul] using h + · have he : B = ∅ := Set.not_nonempty_iff_eq_empty.mp hB + simpa only [he,Set.mem_empty_iff_false,↓reduceIte,semigroup_const] using + (Real.exp_nonneg (2*Real.exp (2*Real.sqrt (Real.exp (A*d)/4))*(d*(Real.exp (A*d)/4))- + δ*Real.sqrt n/2)) + +lemma semigroup_event_bound_later {n : ℕ} (J : Interaction n) (B : Set (Spin n)) + {d q : ℝ} (hB : ∀ x, semigroup J d (fun y => if y ∈ B then 1 else 0) x ≤ q) + {u : ℝ} (hu : d ≤ u) (x : Spin n) : + semigroup J u (fun y => if y ∈ B then 1 else 0) x ≤ q := by + have h := semigroup_le_const J (u-d) (sub_nonneg.mpr hu) hB x + rwa [← mul_apply_eq_comp,← semigroup_add,sub_add_cancel] at h + +lemma stretched_exp_le_dimensionDecay {c m : ℝ} (hc : 0 < c) (hm : 0 < m) : + ∀ᶠ n : ℕ in atTop, Real.exp (-c*Real.sqrt n) ≤ dimensionDecay m n := by + have hlim : Tendsto (fun n : ℕ => Real.log n/Real.sqrt n) atTop (𝓝 0) := by + have h := (isLittleO_log_rpow_atTop (r := (1/2:ℝ)) (by norm_num)).tendsto_div_nhds_zero.comp + (tendsto_natCast_atTop_atTop (R := ℝ)) + simpa only [Function.comp_def,← Real.sqrt_eq_rpow] using h + filter_upwards [hlim.eventually (gt_mem_nhds (div_pos hc hm)),eventually_gt_atTop 0] + with n hn hn0 + have hs := Real.sqrt_pos.mpr (Nat.cast_pos.mpr hn0 : 0 < (n:ℝ)) + have h := (div_lt_iff₀ hs).mp hn + apply Real.exp_le_exp.mpr + have hh := mul_lt_mul_of_pos_left h hm + have hcan : m*(c/m*Real.sqrt n) = c*Real.sqrt n := by field_simp + rw [hcan] at hh + linarith only [hh] + +theorem uniform_bad_avoidance + (G : ∀ n : ℕ, Set (Disorder n)) + (bad : ∀ n, Disorder n → Set (Spin n)) {κ A χ K : ℝ} + (hκ : 0 < κ) (hA : 0 ≤ A) (hχ : 0 < χ) (hK : 0 ≤ K) + (hnorm : ∀ n, ∀ g ∈ G n, euclideanOpNorm (coupling g) ≤ K) + (hmlsi : ∀ n, ∀ g ∈ G n, ∀ F : Observables n, + (∀ y, 0 < F y) → FiniteLaw.mean (mass g 0) F = 1 → + χ*FiniteLaw.entropy (mass g 0) F ≤ + -stationaryInner g (generator (coupling g) F) (fun y => Real.log (F y))) + (hsmall : ∀ n, ∀ g ∈ G n, FiniteLaw.mean (mass g 0) + (fun y => if y ∈ bad n g then 1 else 0) ≤ Real.exp (-κ*n)) + (hdrift : ∀ n, ∀ g ∈ G n, ∀ f : Observables n, ∀ r : ℝ, 0 ≤ r → ∀ y, + deriv (fun v => unweightedGradient (semigroup (coupling g) v f) y) r - + generator (coupling g) (unweightedGradient (semigroup (coupling g) r f)) y ≤ + (-κ + if y ∈ bad n g then A else 0)* + unweightedGradient (semigroup (coupling g) r f) y) : + ∃ d c : ℝ, 0 < d ∧ 0 < c ∧ ∀ᶠ n : ℕ in atTop, ∀ g ∈ G n, + ∀ u : ℝ, d ≤ u → ∀ x, semigroup (coupling g) u + (fun y => if y ∈ bad n g then 1 else 0) x ≤ Real.exp (-c*Real.sqrt n) := by + obtain ⟨δ,ρ,hδ,hδhalf,hρ,hδρ⟩ := exists_small_hamming_radius (K := K) hκ + have he : Tendsto (fun t : ℝ => Real.exp (-χ*t)*(Real.log 2+K)) atTop (𝓝 0) := by + have h := (tendsto_rpow_mul_exp_neg_mul_atTop_nhds_zero 0 χ hχ).mul_const (Real.log 2+K) + simpa only [Real.rpow_zero,one_mul,zero_mul] using h + obtain ⟨d,hd,hE⟩ := ((eventually_gt_atTop (0:ℝ)).and + (he.eventually (gt_mem_nhds (by positivity : (0:ℝ)<κ/8)))).exists + let Q := Real.exp (A*d)/4 + let C := 2*Real.exp (2*Real.sqrt Q)*(d*Q) + have hsize : ∀ᶠ n : ℕ in atTop, Real.log 2 ≤ κ*(n:ℝ)/8 := by + have h := (tendsto_natCast_atTop_atTop (R := ℝ)).const_mul_atTop (by positivity : (0:ℝ)<κ/8) + simpa only [div_mul_eq_mul_div] using h.eventually_ge_atTop (Real.log 2) + have hC : ∀ᶠ n : ℕ in atTop, C ≤ δ*Real.sqrt n/4 := by + have h := (Real.tendsto_sqrt_atTop.comp (tendsto_natCast_atTop_atTop (R := ℝ))).const_mul_atTop + (by positivity : (0:ℝ)<δ/4) + simpa only [Function.comp_def,div_mul_eq_mul_div] using h.eventually_ge_atTop C + refine ⟨d,δ/4,hd,by positivity,?_⟩ + filter_upwards [hsize,hC,eventually_gt_atTop 0] with n hnsize hnC hn + intro g hg u hu x + apply semigroup_event_bound_later (coupling g) (bad n g) (d := d) (q := Real.exp (-(δ/4)*Real.sqrt n)) _ hu x + intro z + have hneigh : FiniteLaw.mean (mass g 0) + (fun y => if y ∈ hammingNeighborhood (bad n g) δ then 1 else 0) ≤ Real.exp (-(κ/2*n)) := by + apply (gibbs_hamming_neighborhood g (bad n g) hK hδ.le hρ (hnorm n g hg) (hsmall n g hg)).trans + apply Real.exp_le_exp.mpr + have hcoeff : -κ+2*K*Real.sqrt δ+ρ*δ+Real.log (1+Real.exp (-ρ)) ≤ -(κ/2) := by + linarith only [hδρ] + simpa only [neg_mul] using mul_le_mul_of_nonneg_right hcoeff (Nat.cast_nonneg n) + have hent (y : Spin n) : transitionEntropy g y d ≤ κ*n/8 := by + calc + _ ≤ Real.exp (-χ*d)*Real.log (1/mass g 0 y) := transitionEntropy_decay g (hmlsi n g hg) y hd.le + _ ≤ Real.exp (-χ*d)*((n:ℝ)*(Real.log 2+K)) := mul_le_mul_of_nonneg_left + ((log_inverse_mass_le g y).trans (mul_le_mul_of_nonneg_left + (add_le_add le_rfl (hnorm n g hg)) (Nat.cast_nonneg n))) (Real.exp_nonneg _) + _ = (Real.exp (-χ*d)*(Real.log 2+K))*(n:ℝ) := by ring + _ ≤ _ := by simpa only [div_mul_eq_mul_div] using + mul_le_mul_of_nonneg_right hE.le (Nat.cast_nonneg n) + have hrough (f : Observables n) (r : ℝ) (hr : r ∈ Set.Icc (0:ℝ) d) (y : Spin n) : + deriv (fun v => unweightedGradient (semigroup (coupling g) v f) y) r - + generator (coupling g) (unweightedGradient (semigroup (coupling g) r f)) y ≤ + A*unweightedGradient (semigroup (coupling g) r f) y := by + apply (hdrift n g hg f r hr.1 y).trans + apply mul_le_mul_of_nonneg_right _ (unweightedGradient_nonneg _ _) + split_ifs <;> linarith only [hκ,hA] + have h := bad_avoidance_burnin hn g (bad n g) hd.le hA hκ hδ.le hneigh hent hnsize hrough z + apply h.trans (Real.exp_le_exp.mpr ?_) + change C-δ*Real.sqrt n/2 ≤ _ + linarith only [hnC] + +theorem superpolynomial_bad_avoidance + (G : ∀ n : ℕ, Set (Disorder n)) + (bad : ∀ n, Disorder n → Set (Spin n)) {d c : ℝ} (hc : 0 < c) + (havoid : ∀ᶠ n : ℕ in atTop, ∀ g ∈ G n, ∀ u : ℝ, d ≤ u → ∀ x, + semigroup (coupling g) u (fun y => if y ∈ bad n g then 1 else 0) x ≤ Real.exp (-c*Real.sqrt n)) : + ∀ D m : ℝ, 0 < D → 0 < m → ∀ᶠ n : ℕ in atTop, ∀ g ∈ G n, + ∀ u ∈ Set.Icc d (D*Real.log n), ∀ x, semigroup (coupling g) u + (fun y => if y ∈ bad n g then 1 else 0) x ≤ dimensionDecay m n := by + intro D m _ hm + filter_upwards [havoid,stretched_exp_le_dimensionDecay hc hm] with n hn hnexp + intro g hg u hu x + exact (hn g hg u hu.1 x).trans hnexp + +end SKRatio.Calculus + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Entropy/Entropy.lean b/lean/OAI/Probability/SKRatio/Entropy/Entropy.lean new file mode 100644 index 0000000000000000000000000000000000000000..76e87cc6ef21186511d27d932cff0cb6e303a304 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Entropy/Entropy.lean @@ -0,0 +1,393 @@ +import Mathlib +import OAI.Probability.SKRatio.Calculus.SpectralLower + +namespace OAI + +section +noncomputable section +open scoped BigOperators Topology Matrix +open MeasureTheory Filter ContinuousLinearMap +namespace SKRatio.FiniteLaw +variable {α : Type*} [Fintype α] +attribute [local instance] Classical.propDecidable + +def entropy (q f : α → ℝ) : ℝ := + mean q (fun x => f x * Real.log (f x)) - mean q f * Real.log (mean q f) + +def relativeEntropy (p q : α → ℝ) : ℝ := ∑ x, p x * Real.log (p x / q x) + +lemma mul_log_div (p q : ℝ) (hq : q ≠ 0) : + p * Real.log (p/q) = p * Real.log p - p * Real.log q := by + by_cases hp : p = 0 + · simp [hp] + · rw [Real.log_div hp hq, mul_sub] + +lemma relativeEntropy_nonneg (p q : α → ℝ) (hp : ∀ x, 0 ≤ p x) + (hq : ∀ x, 0 < q x) (hp1 : ∑ x, p x = 1) (hq1 : ∑ x, q x = 1) : + 0 ≤ relativeEntropy p q := by + have h (x : α) : p x-q x ≤ p x*Real.log (p x/q x) := by + have hl := mul_le_mul_of_nonneg_left + (Real.self_sub_one_le_mul_log (div_nonneg (hp x) (hq x).le)) (hq x).le + calc + p x-q x = q x*(p x/q x-1) := by field_simp [ne_of_gt (hq x)] + _ ≤ q x*(p x/q x*Real.log (p x/q x)) := hl + _ = p x*Real.log (p x/q x) := by field_simp [ne_of_gt (hq x)] + have hs := Finset.sum_le_sum (s := Finset.univ) (fun x _ => h x) + simpa only [Finset.sum_sub_distrib,hp1,hq1,sub_self,relativeEntropy] using hs + +lemma entropy_density (p q : α → ℝ) (hq : ∀ x, q x ≠ 0) + (hp1 : ∑ x, p x = 1) : + entropy q (fun x => p x/q x) = relativeEntropy p q := by + have hm : mean q (fun x => p x/q x) = 1 := by + simpa only [mean,mul_div_cancel₀ _ (hq _)] using hp1 + rw [entropy,hm,Real.log_one,mul_zero,sub_zero] + unfold mean relativeEntropy + exact Finset.sum_congr rfl (fun x _ => by field_simp [hq x]) + +lemma relativeEntropy_continuous (q : α → ℝ) (hq : ∀ x, q x ≠ 0) : + Continuous (fun p : α → ℝ => relativeEntropy p q) := by + simp only [relativeEntropy,mul_log_div _ _ (hq _)] + exact continuous_finsetSum _ (fun x _ => + (Real.continuous_mul_log.comp (continuous_apply x)).sub ((continuous_apply x).mul continuous_const)) + +lemma entropy_variational (p q a : α → ℝ) (hp : ∀ x, 0 ≤ p x) + (hq : ∀ x, 0 < q x) (hp1 : ∑ x, p x = 1) (hq1 : ∑ x, q x = 1) : + mean p a ≤ relativeEntropy p q + Real.log (mean q (fun x => Real.exp (a x))) := by + have : Nonempty α := by + by_contra h + have : IsEmpty α := not_nonempty_iff.mp h + simp at hq1 + let Z := mean q (fun x => Real.exp (a x)) + have hZ : 0 < Z := Finset.sum_pos (fun x _ => mul_pos (hq x) (Real.exp_pos _)) Finset.univ_nonempty + let r (x : α) := q x*Real.exp (a x)/Z + have hr (x : α) : 0 < r x := div_pos (mul_pos (hq x) (Real.exp_pos _)) hZ + have hr1 : ∑ x, r x = 1 := by + rw [show (∑ x, r x) = Z/Z by simp only [r,Z,mean,Finset.sum_div]] + exact div_self (ne_of_gt hZ) + have h := relativeEntropy_nonneg p r hp hr hp1 hr1 + have he (x : α) : p x*Real.log (p x/r x) = + p x*Real.log (p x/q x) - p x*a x + p x*Real.log Z := by + rw [mul_log_div _ _ (ne_of_gt (hr x)),mul_log_div _ _ (ne_of_gt (hq x))] + rw [show Real.log (r x) = Real.log (q x) + a x - Real.log Z by + dsimp only [r] + rw [Real.log_div (ne_of_gt (mul_pos (hq x) (Real.exp_pos _))) (ne_of_gt hZ), + Real.log_mul (ne_of_gt (hq x)) (Real.exp_ne_zero _),Real.log_exp]] + ring + simp only [relativeEntropy,he,Finset.sum_add_distrib,Finset.sum_sub_distrib, + ← Finset.sum_mul,hp1,one_mul] at h + dsimp only [mean,relativeEntropy,Z] at * + linarith only [h] + +lemma event_entropy_bound (p q : α → ℝ) (B : Set α) (hp : ∀ x, 0 ≤ p x) + (hq : ∀ x, 0 < q x) (hp1 : ∑ x, p x = 1) (hq1 : ∑ x, q x = 1) + {a : ℝ} (hsmall : mean q (fun x => if x ∈ B then 1 else 0) ≤ Real.exp (-a)) : + a*mean p (fun x => if x ∈ B then 1 else 0) ≤ relativeEntropy p q+Real.log 2 := by + classical + have h := entropy_variational p q (fun x => if x ∈ B then a else 0) hp hq hp1 hq1 + have hm : mean q (fun x => Real.exp (if x ∈ B then a else 0)) ≤ 2 := by + calc + _ ≤ ∑ x, (q x + Real.exp a*(q x*(if x ∈ B then 1 else 0))) := by + apply Finset.sum_le_sum + intro x _ + by_cases hx : x ∈ B <;> simp only [hx,↓reduceIte,Real.exp_zero,mul_one,mul_zero] + · nlinarith only [hq x] + · simp + _ = 1+Real.exp a*mean q (fun x => if x ∈ B then 1 else 0) := by + simp only [Finset.sum_add_distrib,← Finset.mul_sum,hq1,mean] + _ ≤ 1+Real.exp a*Real.exp (-a) := + add_le_add le_rfl (mul_le_mul_of_nonneg_left hsmall (Real.exp_nonneg _)) + _ = 2 := by rw [← Real.exp_add,add_neg_cancel,Real.exp_zero]; norm_num + have hmpos : 0 < mean q (fun x => Real.exp (if x ∈ B then a else 0)) := by + have : Nonempty α := by + by_contra h + have : IsEmpty α := not_nonempty_iff.mp h + simp at hp1 + exact Finset.sum_pos (fun x _ => mul_pos (hq x) (Real.exp_pos _)) Finset.univ_nonempty + have hlog := Real.log_le_log hmpos hm + have he : mean p (fun x => if x ∈ B then a else 0) = + a*mean p (fun x => if x ∈ B then 1 else 0) := by + simp only [mean,Finset.mul_sum] + apply Finset.sum_congr rfl + intro x _ + split_ifs <;> ring + rw [he] at h + linarith only [h,hlog] + +lemma hellinger_pointwise {p q : ℝ} (hp : 0 ≤ p) (hq : 0 < q) : + 2*p-2*Real.sqrt p*Real.sqrt q ≤ p*Real.log (p/q) := by + rcases eq_or_lt_of_le hp with hp0 | hp0 + · simp [← hp0] + have hp' := Real.sqrt_pos.mpr hp0 + have hq' := Real.sqrt_pos.mpr hq + have hlog := Real.log_le_sub_one_of_pos (div_pos hq' hp') + have h := mul_le_mul_of_nonneg_left hlog (by positivity : 0 ≤ 2*p) + have he : Real.log (Real.sqrt q/Real.sqrt p) = -(Real.log (p/q))/2 := by + rw [Real.log_div (ne_of_gt hq') (ne_of_gt hp'),Real.log_sqrt hq.le,Real.log_sqrt hp, + Real.log_div (ne_of_gt hp0) (ne_of_gt hq)] + ring + rw [he] at h + have hr : p*(Real.sqrt q/Real.sqrt p) = Real.sqrt p*Real.sqrt q := by + nth_rw 1 [← Real.sq_sqrt hp] + field_simp + nlinarith only [h,hr] + +lemma hellinger_le_entropy (p q : α → ℝ) (hp : ∀ x, 0 ≤ p x) + (hq : ∀ x, 0 < q x) (hp1 : ∑ x, p x = 1) (hq1 : ∑ x, q x = 1) : + (∑ x, (Real.sqrt (p x)-Real.sqrt (q x))^2) ≤ relativeEntropy p q := by + have h := Finset.sum_le_sum (s := Finset.univ) + (fun x _ => hellinger_pointwise (hp x) (hq x)) + have he (x : α) : (Real.sqrt (p x)-Real.sqrt (q x))^2 = + p x+q x-2*Real.sqrt (p x)*Real.sqrt (q x) := by + nlinarith only [Real.sq_sqrt (hp x),Real.sq_sqrt (hq x).le] + simp only [he,Finset.sum_sub_distrib,Finset.sum_add_distrib,hp1,hq1] + simpa only [Finset.sum_sub_distrib,← Finset.mul_sum,hp1,relativeEntropy, + mul_one,show (1:ℝ)+1=2 by norm_num] using h + +lemma totalVariation_square_le_entropy (p q : α → ℝ) (hp : ∀ x, 0 ≤ p x) + (hq : ∀ x, 0 < q x) (hp1 : ∑ x, p x = 1) (hq1 : ∑ x, q x = 1) : + totalVariation p q ^ 2 ≤ relativeEntropy p q := by + have hcs := Finset.sum_mul_sq_le_sq_mul_sq Finset.univ + (fun x => |Real.sqrt (p x)-Real.sqrt (q x)|) + (fun x => Real.sqrt (p x)+Real.sqrt (q x)) + have he (x : α) : |Real.sqrt (p x)-Real.sqrt (q x)| * + (Real.sqrt (p x)+Real.sqrt (q x)) = |p x-q x| := by + rw [← abs_of_nonneg (add_nonneg (Real.sqrt_nonneg _) (Real.sqrt_nonneg _)),← abs_mul] + congr 1 + nlinarith only [Real.sq_sqrt (hp x),Real.sq_sqrt (hq x).le] + have hrest : ∑ x, (Real.sqrt (p x)+Real.sqrt (q x))^2 ≤ 4 := by + calc + _ ≤ ∑ x, (2*p x+2*q x) := by + apply Finset.sum_le_sum + intro x _ + nlinarith only [sq_nonneg (Real.sqrt (p x)-Real.sqrt (q x)), + Real.sq_sqrt (hp x),Real.sq_sqrt (hq x).le] + _ = 4 := by simp only [Finset.sum_add_distrib,← Finset.mul_sum,hp1,hq1]; norm_num + simp only [he,sq_abs] at hcs + have hb := mul_le_mul_of_nonneg_left hrest (Finset.sum_nonneg (s := Finset.univ) (fun x _ => sq_nonneg + (Real.sqrt (p x)-Real.sqrt (q x)))) + have hh := hellinger_le_entropy p q hp hq hp1 hq1 + unfold totalVariation + nlinarith only [hcs,hb,hh] + +end SKRatio.FiniteLaw + +namespace SKRatio.Calculus +attribute [local instance] Classical.propDecidable + +lemma continuousKernel_balance {n : ℕ} (g : Disorder n) (t : ℝ) (x y : Spin n) : + mass g 0 x*continuousKernel (coupling g) t x y = + mass g 0 y*continuousKernel (coupling g) t y x := by + have hs := semigroup_symmetric g t (fun z => if z = x then 1 else 0) + (fun z => if z = y then 1 else 0) + simpa only [stationaryInner,FiniteLaw.mean,ite_mul,one_mul,zero_mul,mul_ite, + mul_one,mul_zero,Finset.sum_ite_eq',Finset.mem_univ,↓reduceIte,continuousKernel] + using hs + +def transitionDensity {n : ℕ} (g : Disorder n) (t : ℝ) (x : Spin n) : Observables n := + fun y => continuousKernel (coupling g) t x y/mass g 0 y + +lemma transitionDensity_eq_semigroup {n : ℕ} (g : Disorder n) (t : ℝ) (x : Spin n) : + transitionDensity g t x = semigroup (coupling g) t + (fun y => if y = x then (mass g 0 x)⁻¹ else 0) := by + funext y + rw [semigroup_eq_kernel] + simp only [FiniteLaw.mean,mul_ite,mul_zero,Finset.sum_ite_eq',Finset.mem_univ,↓reduceIte] + dsimp only [transitionDensity] + field_simp [ne_of_gt (mass_pos g 0 x),ne_of_gt (mass_pos g 0 y)] + nlinarith only [continuousKernel_balance g t x y] + +lemma transitionDensity_pos {n : ℕ} (g : Disorder n) {t : ℝ} (ht : 0 < t) (x y : Spin n) : + 0 < transitionDensity g t x y := div_pos (continuousKernel_pos g ht x y) (mass_pos g 0 y) + +lemma transitionDensity_mean {n : ℕ} (g : Disorder n) (t : ℝ) (x : Spin n) : + FiniteLaw.mean (mass g 0) (transitionDensity g t x) = 1 := by + simp only [FiniteLaw.mean,transitionDensity,mul_div_cancel₀ _ (ne_of_gt (mass_pos g 0 _)), + continuousKernel_sum] + +lemma transitionDensity_hasDerivAt {n : ℕ} (g : Disorder n) (x : Spin n) (t : ℝ) : + HasDerivAt (fun t => transitionDensity g t x) + (generator (coupling g) (transitionDensity g t x)) t := by + simp_rw [transitionDensity_eq_semigroup] + exact semigroup_apply_hasDerivAt' _ _ _ + +def transitionEntropy {n : ℕ} (g : Disorder n) (x : Spin n) (t : ℝ) : ℝ := + FiniteLaw.relativeEntropy (continuousKernel (coupling g) t x) (mass g 0) + +lemma transitionEntropy_eq {n : ℕ} (g : Disorder n) (x : Spin n) (t : ℝ) : + transitionEntropy g x t = + FiniteLaw.mean (mass g 0) (fun y => transitionDensity g t x y * + Real.log (transitionDensity g t x y)) := by + rw [transitionEntropy,← FiniteLaw.entropy_density _ _ (fun y => ne_of_gt (mass_pos g 0 y)) + (continuousKernel_sum _ t x)] + change FiniteLaw.entropy (mass g 0) (transitionDensity g t x) = _ + simp only [FiniteLaw.entropy,transitionDensity_mean,Real.log_one,mul_zero,sub_zero] + +lemma transitionEntropy_continuous {n : ℕ} (g : Disorder n) (x : Spin n) : + Continuous (transitionEntropy g x) := by + exact (FiniteLaw.relativeEntropy_continuous (mass g 0) (fun y => ne_of_gt (mass_pos g 0 y))).comp + (continuous_pi (continuousKernel_continuous_time (coupling g) x)) + +lemma transitionEntropy_zero {n : ℕ} (g : Disorder n) (x : Spin n) : + transitionEntropy g x 0 = Real.log (1/mass g 0 x) := by + simp [transitionEntropy,FiniteLaw.relativeEntropy,Matrix.one_apply,ite_mul,ite_div] + +lemma transitionEntropy_hasDerivAt {n : ℕ} (g : Disorder n) (x : Spin n) + {t : ℝ} (ht : 0 < t) : + HasDerivAt (transitionEntropy g x) + (stationaryInner g (generator (coupling g) (transitionDensity g t x)) + (fun y => Real.log (transitionDensity g t x y))) t := by + have hd (y : Spin n) := hasDerivAt_pi.mp (transitionDensity_hasDerivAt g x t) y + have hp (y : Spin n) := (Real.hasDerivAt_mul_log + (ne_of_gt (transitionDensity_pos g ht x y))).comp t (hd y) + have hm := (gibbsMeanCLM g).hasFDerivAt.comp_hasDerivAt t (hasDerivAt_pi.mpr hp) + have he : (fun t => gibbsMeanCLM g (fun y => transitionDensity g t x y* + Real.log (transitionDensity g t x y))) = transitionEntropy g x := by + funext t + rw [gibbsMeanCLM_apply,transitionEntropy_eq] + change HasDerivAt (fun r => gibbsMeanCLM g + (fun y => transitionDensity g r x y*Real.log (transitionDensity g r x y))) _ t at hm + rw [he] at hm + apply hm.congr_deriv + have hz := gibbsMean_generator g (transitionDensity g t x) + simp only [gibbsMeanCLM_apply,FiniteLaw.mean] at hz ⊢ + simp only [stationaryInner,FiniteLaw.mean,add_mul,one_mul,mul_add,Finset.sum_add_distrib,hz, + add_zero] + exact Finset.sum_congr rfl (fun y _ => by ring) + +theorem transitionEntropy_decay {n : ℕ} (g : Disorder n) {χ : ℝ} + (hmlsi : ∀ F : Observables n, (∀ y, 0 < F y) → FiniteLaw.mean (mass g 0) F = 1 → + χ*FiniteLaw.entropy (mass g 0) F ≤ + -stationaryInner g (generator (coupling g) F) (fun y => Real.log (F y))) + (x : Spin n) {t : ℝ} (ht : 0 ≤ t) : + transitionEntropy g x t ≤ Real.exp (-χ*t)*Real.log (1/mass g 0 x) := by + let H (r : ℝ) := Real.exp (χ*r)*transitionEntropy g x r + have hd (r : ℝ) (hr : 0 < r) : HasDerivAt H + (Real.exp (χ*r)*(χ*transitionEntropy g x r+ + stationaryInner g (generator (coupling g) (transitionDensity g r x)) + (fun y => Real.log (transitionDensity g r x y)))) r := by + have h := (((hasDerivAt_id r).const_mul χ).exp).mul (transitionEntropy_hasDerivAt g x hr) + convert! h using 1 + first | rfl | (simp only [id_eq]; ring) + have hc : Continuous H := (Real.continuous_exp.comp (continuous_const.mul continuous_id)).mul + (transitionEntropy_continuous g x) + have hanti : AntitoneOn H (Set.Ici 0) := by + apply antitoneOn_of_deriv_nonpos (convex_Ici _) hc.continuousOn + · intro r hr + rw [interior_Ici,Set.mem_Ioi] at hr + exact (hd r hr).differentiableAt.differentiableWithinAt + · intro r hr + rw [interior_Ici,Set.mem_Ioi] at hr + rw [(hd r hr).deriv] + apply mul_nonpos_of_nonneg_of_nonpos (Real.exp_nonneg _) + have h := hmlsi (transitionDensity g r x) (transitionDensity_pos g hr x) + (transitionDensity_mean g r x) + rw [FiniteLaw.entropy,transitionDensity_mean,Real.log_one,mul_zero,sub_zero, + ← transitionEntropy_eq] at h + linarith only [h] + have h := hanti (by simp) ht ht + have hzero : H 0 = Real.log (1/mass g 0 x) := by simp [H,transitionEntropy_zero] + rw [hzero] at h + have hm := mul_le_mul_of_nonneg_left h (Real.exp_nonneg (-χ*t)) + calc + _ = Real.exp (-χ*t)*H t := by + dsimp only [H] + rw [← mul_assoc,← Real.exp_add,show -χ*t+χ*t=0 by ring,Real.exp_zero,one_mul] + _ ≤ _ := hm + +lemma abs_hamiltonian_le_norm {n : ℕ} (g : Disorder n) (x : Spin n) : + |hamiltonian g 0 x| ≤ euclideanOpNorm (coupling g)*(n:ℝ)/2 := by + let X : EuclideanSpace ℝ (Fin n) := WithLp.toLp 2 (fun i => spinValue (x i)) + have hid : hamiltonian g 0 x = (1/2:ℝ)*inner ℝ X + (Matrix.toEuclideanCLM (𝕜 := ℝ) (n := Fin n) (coupling g) X) := by + rw [Matrix.inner_toEuclideanCLM (coupling g : Matrix (Fin n) (Fin n) ℝ) X X] + simp only [hamiltonian,Pi.zero_apply,zero_mul,Finset.sum_const_zero,add_zero,dotProduct, + Matrix.mulVec,Finset.mul_sum,X,mul_assoc] + have hX : ‖X‖^2 = (n:ℝ) := by + simp [X,EuclideanSpace.real_norm_sq_eq,Independent.spinValue_sq] + rw [hid,abs_mul,abs_of_nonneg (by norm_num : (0:ℝ)≤1/2)] + calc + _ ≤ (1/2:ℝ)*(‖X‖*‖Matrix.toEuclideanCLM (𝕜 := ℝ) (n := Fin n) (coupling g) X‖) := + mul_le_mul_of_nonneg_left (abs_real_inner_le_norm _ _) (by norm_num) + _ ≤ (1/2:ℝ)*(‖X‖*(euclideanOpNorm (coupling g)*‖X‖)) := + mul_le_mul_of_nonneg_left (mul_le_mul_of_nonneg_left + ((Matrix.toEuclideanCLM (𝕜 := ℝ) (n := Fin n) (coupling g)).le_opNorm X) + (norm_nonneg X)) (by norm_num) + _ = _ := by rw [← hX]; ring + +lemma log_inverse_mass_le {n : ℕ} (g : Disorder n) (x : Spin n) : + Real.log (1/mass g 0 x) ≤ (n:ℝ)*(Real.log 2+euclideanOpNorm (coupling g)) := by + let b := euclideanOpNorm (coupling g)*(n:ℝ)/2 + have he (y : Spin n) : |hamiltonian g 0 y| ≤ b := abs_hamiltonian_le_norm g y + have hp : partition g 0 ≤ (2:ℝ)^n*Real.exp b := by + calc + _ ≤ ∑ y : Spin n, Real.exp b := Finset.sum_le_sum + (fun y _ => Real.exp_le_exp.mpr ((le_abs_self _).trans (he y))) + _ = _ := by simp [Spin] + have hlog := Real.log_le_log (partition_pos g 0) hp + rw [Real.log_mul (by positivity : (2:ℝ)^n ≠ 0) (Real.exp_ne_zero _), + Real.log_pow,Real.log_exp] at hlog + have hinv : Real.log (1/mass g 0 x) = Real.log (partition g 0)-hamiltonian g 0 x := by + rw [mass,weight,one_div_div,Real.log_div (ne_of_gt (partition_pos g 0)) (Real.exp_ne_zero _), + Real.log_exp] + rw [hinv] + have hl := (abs_le.mp (he x)).1 + dsimp only [b] at hlog hl + linarith only [hlog,hl] + +lemma continuousDistance_square_le_entropy {n : ℕ} (g : Disorder n) {t H : ℝ} + (ht : 0 ≤ t) (hH : ∀ x, transitionEntropy g x t ≤ H) : + continuousDistance g t ^ 2 ≤ H := by + obtain ⟨x, -, hx⟩ := Finset.exists_mem_eq_sup' Finset.univ_nonempty + (fun x : Spin n => totalVariation (continuousKernel (coupling g) t x) (mass g 0)) + change (Finset.univ.sup' _ _)^2 ≤ _ + rw [hx] + exact (FiniteLaw.totalVariation_square_le_entropy _ _ (continuousKernel_nonneg _ t ht x) + (mass_pos g 0) (continuousKernel_sum _ t x) (sum_mass g 0)).trans (hH x) + +lemma continuousDistance_square_decay {n : ℕ} (g : Disorder n) {χ : ℝ} + (hmlsi : ∀ F : Observables n, (∀ y, 0 < F y) → FiniteLaw.mean (mass g 0) F = 1 → + χ*FiniteLaw.entropy (mass g 0) F ≤ + -stationaryInner g (generator (coupling g) F) (fun y => Real.log (F y))) + {t : ℝ} (ht : 0 ≤ t) : + continuousDistance g t ^ 2 ≤ + Real.exp (-χ*t)*(n:ℝ)*(Real.log 2+euclideanOpNorm (coupling g)) := by + apply continuousDistance_square_le_entropy g ht + intro x + exact (transitionEntropy_decay g hmlsi x ht).trans + (by + simpa only [mul_assoc] using mul_le_mul_of_nonneg_left + (log_inverse_mass_le g x) (Real.exp_nonneg (-χ*t))) + +theorem uniform_median_upper_of_mlsi + (G : ∀ n : ℕ, Set (Disorder n)) {χ K : ℝ} (hχ : 0 < χ) + (hnorm : ∀ n, ∀ g ∈ G n, euclideanOpNorm (coupling g) ≤ K) + (hmlsi : ∀ n, ∀ g ∈ G n, ∀ F : Observables n, + (∀ y, 0 < F y) → FiniteLaw.mean (mass g 0) F = 1 → + χ*FiniteLaw.entropy (mass g 0) F ≤ + -stationaryInner g (generator (coupling g) F) (fun y => Real.log (F y))) : + ∀ᶠ n : ℕ in atTop, ∀ g ∈ G n, medianTime g ≤ (2/χ)*Real.log n := by + have hvan := (dimensionDecay_tendsto_zero (by norm_num : (0:ℝ)<1)).mul_const (Real.log 2+K) + simp only [zero_mul] at hvan + filter_upwards [hvan.eventually (gt_mem_nhds (by norm_num : (0:ℝ)<1/4)), + eventually_ge_atTop 1] with n hnsmall hn + intro g hg + have htime : 0 ≤ (2/χ)*Real.log n := mul_nonneg (by positivity) + (Real.log_nonneg (by exact_mod_cast hn)) + apply (medianTime_le_iff g htime).mpr + have h := continuousDistance_square_decay g (hmlsi n g hg) htime + have hcoeff : Real.exp (-χ*((2/χ)*Real.log n))*(n:ℝ) = dimensionDecay 1 n := by + have hed : -χ*((2/χ)*Real.log n) = -2*Real.log n := by field_simp + rw [hed,mul_comm,← dimensionDecay,nat_mul_dimensionDecay (by omega)] + norm_num + rw [hcoeff] at h + have hkn := mul_le_mul_of_nonneg_left (add_le_add_left (hnorm n g hg) (Real.log 2)) + (dimensionDecay_pos 1 n).le + have hnD := continuousDistance_nonneg g ((2/χ)*Real.log n) + nlinarith only [h,hkn,hnsmall,hnD] + +end SKRatio.Calculus + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Entropy/FiniteEntropy.lean b/lean/OAI/Probability/SKRatio/Entropy/FiniteEntropy.lean new file mode 100644 index 0000000000000000000000000000000000000000..11a99369d9874b5449c74a1d2e9f1d1d3fdf562e --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Entropy/FiniteEntropy.lean @@ -0,0 +1,154 @@ +import Mathlib +import OAI.Probability.SKRatio.FiniteChain.EntropicCovariance + +namespace OAI + +section +noncomputable section +open scoped BigOperators +open Real +namespace SKRatio.Observation +variable {α : Type*} [Fintype α] + +def logRemainder (u a : ℝ) : ℝ := u*log (u/a)-u+a + +lemma logRemainder_nonneg {u a : ℝ} (hu : 0 < u) (ha : 0 < a) : + 0 ≤ logRemainder u a := by + have h := mul_le_mul_of_nonneg_left + (self_sub_one_le_mul_log (div_nonneg hu.le ha.le)) ha.le + have he : a*(u/a*log (u/a))-(a*(u/a-1)) = logRemainder u a := by + unfold logRemainder + field_simp [ha.ne'] + ring + rw [← he] + linarith only [h] + +lemma logRemainder_eq {u a : ℝ} (hu : u ≠ 0) (ha : a ≠ 0) : + logRemainder u a = u*log u-u*log a-u+a := by + rw [logRemainder,log_div hu ha] + ring + +lemma ent_nonneg (p : Prior α) {f : α → ℝ} (hf : ∀ x, 0 < f x) : 0 ≤ ent p f := by + have hj := convexOn_mul_log.map_sum_le (t := Finset.univ) (w := p.mass) (p := f) + (fun x _ => p.nonneg x) p.sum_one (fun x _ => (hf x).le) + change avg p f*log (avg p f) ≤ avg p (fun x => f x*log (f x)) at hj + unfold ent FiniteLaw.entropy + exact sub_nonneg.mpr hj + +lemma avg_sum (p : Prior α) {ι : Type*} [Fintype ι] (f : ι → α → ℝ) : + avg p (fun x => ∑ i, f i x) = ∑ i, avg p (f i) := by + simp only [avg,FiniteLaw.mean,Finset.mul_sum] + rw [Finset.sum_comm] + +lemma avg_logRemainder (p : Prior α) (f : α → ℝ) (hf : ∀ x, 0 < f x) {a : ℝ} (ha : 0 logRemainder (f x) a) = ent p f+logRemainder (avg p f) a := by + simp_rw [logRemainder_eq (hf _).ne' ha.ne'] + rw [avg_add,avg_sub,avg_sub,avg_mul_const,avg_const, + logRemainder_eq (avg_pos p hf).ne' ha.ne'] + unfold ent FiniteLaw.entropy + change _ = avg p (fun x => f x*log (f x))-avg p f*log (avg p f)+_ + ring + +lemma ent_minimizes (p : Prior α) (f : α → ℝ) (hf : ∀ x, 0 logRemainder (f x) a) := by + rw [avg_logRemainder p f hf ha] + exact le_add_of_nonneg_right (logRemainder_nonneg (avg_pos p hf) ha) + +lemma ent_eq_remainder (p : Prior α) (f : α → ℝ) (hf : ∀ x, 0 < f x) : + ent p f = avg p (fun x => logRemainder (f x) (avg p f)) := by + rw [avg_logRemainder p f hf (avg_pos p hf)] + simp only [logRemainder,div_self (avg_pos p hf).ne',log_one,mul_zero,zero_sub,neg_add_cancel,add_zero] + +lemma prior_le_one (p : Prior α) (x : α) : p x ≤ 1 := by + rw [← p.sum_one] + exact Finset.single_le_sum (fun y _ => p.nonneg y) (Finset.mem_univ x) + +lemma ent_bound (p : Prior α) (f : α → ℝ) (hf : ∀ x, 0 < f x) : + ent p f ≤ ∑ x, logRemainder (f x) 1 := by + apply (ent_minimizes p f hf zero_lt_one).trans + exact Finset.sum_le_sum (fun x _ => mul_le_of_le_one_left + (logRemainder_nonneg (hf x) zero_lt_one) (prior_le_one p x)) + +lemma continuous_entropy_masses (f : α → ℝ) : + Continuous (fun p : α → ℝ => FiniteLaw.entropy p f) := by + have hs : Continuous (fun p : α → ℝ => FiniteLaw.mean p f) := + continuous_finsetSum _ (fun x _ => (continuous_apply x : Continuous (fun p : α → ℝ => p x)).mul_const (f x)) + exact (continuous_finsetSum _ (fun x _ => (continuous_apply x : Continuous (fun p : α → ℝ => p x)).mul_const (f x*log (f x)))).sub + (continuous_mul_log.comp hs) + +lemma avg_ent_eq_remainder (p : Prior α) (f : α → ℝ) (hf : ∀ x, 0 f x*log (f x/avg p f)) := by + have he (x : α) : f x*log (f x/avg p f) = f x*log (f x)-f x*log (avg p f) := by + rw [log_div (hf x).ne' (avg_pos p hf).ne',mul_sub] + simp_rw [he] + rw [avg_sub,avg_mul_const] + rfl + +lemma avg_log_le_log_avg (p : Prior α) (f : α → ℝ) (hf : ∀ x, 0 log (f x)) ≤ log (avg p f) := by + have hj := strictConcaveOn_log_Ioi.concaveOn.le_map_sum (t := Finset.univ) + (w := p.mass) (p := f) (fun x _ => p.nonneg x) p.sum_one (fun x _ => hf x) + exact hj + +lemma ent_le_cov_log (p : Prior α) (f : α → ℝ) (hf : ∀ x, 0 < f x) : + ent p f ≤ avg p (fun x => f x*log (f x))-avg p f*avg p (fun x => log (f x)) := by + have h := mul_le_mul_of_nonneg_left (avg_log_le_log_avg p f hf) (avg_pos p hf).le + unfold ent FiniteLaw.entropy + change avg p (fun x => f x*log (f x))-avg p f*log (avg p f) ≤ _ + linarith only [h] + +lemma logSum (p : Prior α) (a b : α → ℝ) (ha : ∀ x,0 a x*log (a x/b x)) := by + let q := reweight p b hb + have he : avg q (fun x => a x/b x) = avg p a/avg p b := by + rw [avg_reweight] + congr 1 + congr 1 + funext x + field_simp [(hb x).ne'] + have hj := convexOn_mul_log.map_sum_le (t := Finset.univ) (w := q.mass) + (p := fun x => a x/b x) (fun x _ => q.nonneg x) q.sum_one + (fun x _ => (div_pos (ha x) (hb x)).le) + change avg q (fun x => a x/b x)*log (avg q (fun x => a x/b x)) ≤ + avg q (fun x => (a x/b x)*log (a x/b x)) at hj + rw [he,avg_reweight] at hj + have he₂ : (fun x => b x*(a x/b x*log (a x/b x))) = + fun x => a x*log (a x/b x) := by + funext x + field_simp [(hb x).ne'] + rw [he₂] at hj + have h := mul_le_mul_of_nonneg_right hj (avg_pos p hb).le + convert! h using 1 <;> field_simp [(avg_pos p hb).ne'] + +theorem entropy_average_le {ι : Type*} [Fintype ι] (p : Prior α) (q : Prior ι) + (f : ι → α → ℝ) (hf : ∀ i x, 0 avg q (fun i => f i x)) ≤ avg q (fun i => ent p (f i)) := by + have hswap (F : ι → α → ℝ) : avg p (fun x => avg q (fun i => F i x)) = + avg q (fun i => avg p (F i)) := by + simp only [avg,FiniteLaw.mean,Finset.mul_sum] + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro i _ + apply Finset.sum_congr rfl + intro x _ + ring + rw [avg_ent_eq_remainder p _ (fun x => avg_pos q (fun i => hf i x))] + rw [hswap f] + calc + _ ≤ avg p (fun x => avg q (fun i => f i x*log (f i x/avg p (f i)))) := by + apply avg_mono p + intro x + exact logSum q (fun i => f i x) (fun i => avg p (f i)) (fun i => hf i x) + (fun i => avg_pos p (hf i)) + _ = avg q (fun i => ent p (f i)) := by + rw [hswap] + congr 1 + funext i + exact (avg_ent_eq_remainder p (f i) (hf i)).symm + +end SKRatio.Observation + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Entropy/GaussianChannel.lean b/lean/OAI/Probability/SKRatio/Entropy/GaussianChannel.lean new file mode 100644 index 0000000000000000000000000000000000000000..7bdeadee95a606dccefd54a1b8cf9c4db2c650f5 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Entropy/GaussianChannel.lean @@ -0,0 +1,587 @@ +import Mathlib +import OAI.Probability.SKRatio.FiniteChain.EntropicCovariance + +namespace OAI + +section +noncomputable section +open scoped BigOperators ENNReal NNReal +open MeasureTheory ProbabilityTheory Real Set Filter +namespace SKRatio.Observation.Channel +variable {α : Type*} [Fintype α] {d : ℕ} + +def reference (d : ℕ) : Measure (Fin d → ℝ) := + Measure.pi (fun _ => gaussianReal 0 1) + +instance reference_probability (d : ℕ) : IsProbabilityMeasure (reference d) := + inferInstanceAs (IsProbabilityMeasure (Measure.pi _)) + +lemma integrable_exp_linear (a : Fin d → ℝ) : + Integrable (fun z => exp (∑ i, a i*z i)) (reference d) := by + simp_rw [exp_sum] + exact Integrable.fintype_prod (fun i => integrable_exp_mul_gaussianReal (μ := 0) (v := 1) (a i)) + +lemma integral_exp_linear (a : Fin d → ℝ) : + (∫ z, exp (∑ i, a i*z i) ∂reference d) = exp ((∑ i, a i^2)/2) := by + simp_rw [exp_sum] + rw [reference, integral_fintype_prod_eq_prod (fun i (z : ℝ) => exp (a i*z))] + have hi (i : Fin d) : (∫ z : ℝ, exp (a i*z) ∂gaussianReal 0 1) = exp (a i^2/2) := by + simpa only [mgf,zero_mul,NNReal.coe_one,one_mul,zero_add,id_eq] using + mgf_gaussianReal (μ := 0) (v := 1) (X := id) (p := gaussianReal 0 1) (by simp) (a i) + simp_rw [hi] + rw [← exp_sum,Finset.sum_div] + +variable (v : α → Fin d → ℝ) + +def normSq (x : α) : ℝ := ∑ i, v x i^2 + +def mean (p : Prior α) (i : Fin d) : ℝ := avg p (fun x => v x i) + +def secondMoment (p : Prior α) : ℝ := avg p (normSq v) + +def likelihood (t : ℝ) (x : α) (z : Fin d → ℝ) : ℝ := + exp (sqrt t*(∑ i, v x i*z i)-t*normSq v x/2) + +def density (p : Prior α) (t : ℝ) (z : Fin d → ℝ) : ℝ := + ∑ x, p x*likelihood v t x z + +omit [Fintype α] in +lemma likelihood_pos (t : ℝ) (x : α) (z : Fin d → ℝ) : + 0 < likelihood v t x z := exp_pos _ + +omit [Fintype α] in +lemma integrable_likelihood (t : ℝ) (x : α) : + Integrable (likelihood v t x) (reference d) := by + have he : likelihood v t x = fun z => exp (∑ i, (sqrt t*v x i)*z i) * + exp (-(t*normSq v x/2)) := by + funext z + simp only [likelihood,exp_sub,exp_neg,← Finset.mul_sum,mul_assoc,div_eq_mul_inv] + rw [he] + exact (integrable_exp_linear _).mul_const _ + +omit [Fintype α] in +lemma integral_likelihood {t : ℝ} (ht : 0 ≤ t) (x : α) : + (∫ z, likelihood v t x z ∂reference d) = 1 := by + have he : likelihood v t x = fun z => exp (∑ i, (sqrt t*v x i)*z i) * + exp (-(t*normSq v x/2)) := by + funext z + simp only [likelihood,exp_sub,exp_neg,← Finset.mul_sum,mul_assoc,div_eq_mul_inv] + rw [he,integral_mul_const,integral_exp_linear,← exp_add] + simp only [mul_pow,sq_sqrt ht,← Finset.mul_sum,normSq] + simp + +lemma density_jensen (p : Prior α) (t : ℝ) (z : Fin d → ℝ) : + exp (sqrt t*(∑ i, mean v p i*z i)-t*secondMoment v p/2) ≤ density v p t z := by + have he : (∑ x, p x*(sqrt t*(∑ i, v x i*z i)-t*normSq v x/2)) = + sqrt t*(∑ i, mean v p i*z i)-t*secondMoment v p/2 := by + simp only [mul_sub,Finset.sum_sub_distrib,mean,secondMoment,avg,FiniteLaw.mean] + congr 1 + · simp only [Finset.mul_sum,Finset.sum_mul] + rw [Finset.sum_comm] + exact Finset.sum_congr rfl (fun i _ => Finset.sum_congr rfl (fun x _ => by ring)) + · simp only [Finset.mul_sum,Finset.sum_div] + exact Finset.sum_congr rfl (fun x _ => by ring) + have hj := convexOn_exp.map_sum_le (t := Finset.univ) (w := p.mass) + (p := fun x => sqrt t*(∑ i, v x i*z i)-t*normSq v x/2) + (fun x _ => p.nonneg x) p.sum_one (fun _ _ => Set.mem_univ _) + simpa only [smul_eq_mul,he,density,likelihood] using hj + +lemma density_pos (p : Prior α) (t : ℝ) (z : Fin d → ℝ) : + 0 < density v p t z := (exp_pos _).trans_le (density_jensen v p t z) + +lemma integrable_density (p : Prior α) (t : ℝ) : + Integrable (density v p t) (reference d) := + integrable_finsetSum _ (fun x _ => (integrable_likelihood v t x).const_mul (p x)) + +lemma integral_density (p : Prior α) {t : ℝ} (ht : 0 ≤ t) : + (∫ z, density v p t z ∂reference d) = 1 := by + unfold density + rw [integral_finsetSum _ (fun x _ => (integrable_likelihood v t x).const_mul (p x))] + simp_rw [integral_const_mul,integral_likelihood v ht,mul_one] + exact p.sum_one + +def interaction (p : Prior α) (x y : α) : ℝ := + ((∑ i, (v x i+v y i-mean v p i)^2)-normSq v x-normSq v y+secondMoment v p)/2 + +lemma interaction_sum (p : Prior α) (x y : α) : + interaction v p x y = ∑ i, (v x i*v y i-v x i*mean v p i-v y i*mean v p i+ + (mean v p i)^2/2+avg p (fun z => v z i^2)/2) := by + have he : secondMoment v p = ∑ i, avg p (fun z => v z i^2) := by + simp only [secondMoment,avg,FiniteLaw.mean,normSq,Finset.mul_sum] + exact Finset.sum_comm + rw [interaction,normSq,normSq,he,← Finset.sum_sub_distrib,← Finset.sum_sub_distrib, + ← Finset.sum_add_distrib,Finset.sum_div] + exact Finset.sum_congr rfl (fun i _ => by ring) + +omit v in +lemma signed_sum_left (a u : α → ℝ) (ha : ∑ x, a x = 0) : + (∑ x, ∑ y, a x*a y*u x) = 0 := by + apply Finset.sum_eq_zero + intro x _ + calc + _ = (a x*u x)*∑ y, a y := by + rw [Finset.mul_sum] + exact Finset.sum_congr rfl (fun y _ => by ring) + _ = 0 := by rw [ha,mul_zero] + +omit v in +lemma signed_sum_right (a u : α → ℝ) (ha : ∑ x, a x = 0) : + (∑ x, ∑ y, a x*a y*u y) = 0 := by + rw [Finset.sum_comm] + convert signed_sum_left a u ha using 1 + exact Finset.sum_congr rfl (fun x _ => Finset.sum_congr rfl (fun y _ => by ring)) + +omit v in +lemma signed_sum_product (a u : α → ℝ) : + (∑ x, ∑ y, a x*a y*(u x*u y)) = (∑ x, a x*u x)^2 := by + rw [pow_two,Finset.sum_mul_sum] + exact Finset.sum_congr rfl (fun x _ => Finset.sum_congr rfl (fun y _ => by ring)) + +lemma signed_interaction (p : Prior α) (a : α → ℝ) (ha : ∑ x, a x = 0) : + (∑ x, ∑ y, a x*a y*interaction v p x y) = ∑ i, (∑ x, a x*v x i)^2 := by + simp_rw [interaction_sum,Finset.mul_sum] + calc + _ = ∑ x, ∑ i, ∑ y, a x*a y*(v x i*v y i-v x i*mean v p i-v y i*mean v p i+ + (mean v p i)^2/2+avg p (fun z => v z i^2)/2) := by + exact Finset.sum_congr rfl (fun x _ => Finset.sum_comm) + _ = ∑ i, ∑ x, ∑ y, a x*a y*(v x i*v y i-v x i*mean v p i-v y i*mean v p i+ + (mean v p i)^2/2+avg p (fun z => v z i^2)/2) := Finset.sum_comm + _ = _ := by + apply Finset.sum_congr rfl + intro i _ + simp only [mul_add,mul_sub,Finset.sum_add_distrib,Finset.sum_sub_distrib] + rw [signed_sum_product a (fun x => v x i), + signed_sum_left a (fun x => v x i*mean v p i) ha, + signed_sum_right a (fun x => v x i*mean v p i) ha, + signed_sum_left a (fun _ => (mean v p i)^2/2) ha, + signed_sum_left a (fun _ => avg p (fun z => v z i^2)/2) ha] + ring + +lemma interaction_remainder_bound (p : Prior α) {K t : ℝ} (hK : 0 ≤ K) (ht : 0 ≤ t) + (hbound : ∀ x y, |interaction v p x y| ≤ K) (hKt : K*t ≤ 1) (x y : α) : + |exp (t*interaction v p x y)-1-t*interaction v p x y| ≤ K^2*t^2 := by + have htb : |t*interaction v p x y| ≤ K*t := by + rw [abs_mul,abs_of_nonneg ht,mul_comm K] + exact mul_le_mul_of_nonneg_left (hbound x y) ht + apply (abs_exp_sub_one_sub_id_le (htb.trans hKt)).trans + have hs := (sq_le_sq₀ (abs_nonneg (t*interaction v p x y)) (mul_nonneg hK ht)).mpr htb + simpa only [sq_abs,mul_pow] using hs + +def pairShift (p : Prior α) (x y : α) : ℝ := + (normSq v x+normSq v y-secondMoment v p)/2 + +def pairKernel (p : Prior α) (t : ℝ) (x y : α) (z : Fin d → ℝ) : ℝ := + exp ((∑ i, (sqrt t*(v x i+v y i-mean v p i))*z i)-t*pairShift v p x y) + +lemma integrable_pairKernel (p : Prior α) (t : ℝ) (x y : α) : + Integrable (pairKernel v p t x y) (reference d) := by + have he : pairKernel v p t x y = fun z => + exp (∑ i, (sqrt t*(v x i+v y i-mean v p i))*z i)*exp (-(t*pairShift v p x y)) := by + funext z; simp [pairKernel,exp_sub,exp_neg,div_eq_mul_inv] + rw [he] + exact (integrable_exp_linear _).mul_const _ + +lemma integral_pairKernel (p : Prior α) {t : ℝ} (ht : 0 ≤ t) (x y : α) : + (∫ z, pairKernel v p t x y z ∂reference d) = exp (t*interaction v p x y) := by + have he : pairKernel v p t x y = fun z => + exp (∑ i, (sqrt t*(v x i+v y i-mean v p i))*z i)*exp (-(t*pairShift v p x y)) := by + funext z; simp [pairKernel,exp_sub,exp_neg,div_eq_mul_inv] + rw [he,integral_mul_const,integral_exp_linear,← exp_add] + congr 1 + simp only [mul_pow,sq_sqrt ht,← Finset.mul_sum,interaction,pairShift] + ring + +lemma likelihood_pair (p : Prior α) (t : ℝ) (x y : α) (z : Fin d → ℝ) : + likelihood v t x z * likelihood v t y z * + exp (-(sqrt t * (∑ i, mean v p i * z i) - t*secondMoment v p/2)) = pairKernel v p t x y z := by + unfold likelihood pairKernel pairShift + rw [← exp_add, ← exp_add] + congr 1 + simp only [add_mul, sub_mul, mul_add, mul_sub, Finset.mul_sum, Finset.sum_add_distrib, + Finset.sum_sub_distrib, mul_assoc] + ring + +def majorant (p : Prior α) (a : α → ℝ) (t : ℝ) (z : Fin d → ℝ) : ℝ := + (∑ x, a x*likelihood v t x z)^2 * exp (-(sqrt t * (∑ i, mean v p i * z i) - t*secondMoment v p/2)) + +lemma majorant_eq_sum (p : Prior α) (a : α → ℝ) (t : ℝ) (z : Fin d → ℝ) : + majorant v p a t z = ∑ x, ∑ y, (a x*a y)*pairKernel v p t x y z := by + unfold majorant + rw [pow_two, Finset.sum_mul_sum] + simp only [Finset.sum_mul] + apply Finset.sum_congr rfl + intro x _ + apply Finset.sum_congr rfl + intro y _ + calc + _ = (a x*a y)*(likelihood v t x z*likelihood v t y z* + exp (-(sqrt t * (∑ i, mean v p i * z i) - t*secondMoment v p/2))) := by ring + _ = _ := by rw [likelihood_pair] + +lemma majorant_nonneg (p : Prior α) (a : α → ℝ) (t : ℝ) (z : Fin d → ℝ) : + 0 ≤ majorant v p a t z := mul_nonneg (sq_nonneg _) (exp_pos _).le + +lemma integrable_majorant (p : Prior α) (a : α → ℝ) (t : ℝ) : + Integrable (majorant v p a t) (reference d) := by + simp_rw [show majorant v p a t = fun z => ∑ x, ∑ y, (a x*a y)*pairKernel v p t x y z from + funext (majorant_eq_sum v p a t)] + exact integrable_finsetSum _ (fun x _ => integrable_finsetSum _ (fun y _ => + (integrable_pairKernel v p t x y).const_mul _)) + +lemma integral_majorant (p : Prior α) (a : α → ℝ) {t : ℝ} (ht : 0 ≤ t) : + (∫ z, majorant v p a t z ∂reference d) = ∑ x, ∑ y, (a x*a y)*exp (t*interaction v p x y) := by + simp_rw [majorant_eq_sum] + rw [integral_finsetSum _ (fun x _ => integrable_finsetSum _ (fun y _ => + (integrable_pairKernel v p t x y).const_mul _))] + apply Finset.sum_congr rfl + intro x _ + rw [integral_finsetSum _ (fun y _ => (integrable_pairKernel v p t x y).const_mul _)] + simp_rw [integral_const_mul, integral_pairKernel v p ht] + +lemma interaction_exp_sum_bound (p : Prior α) (a : α → ℝ) + (ha : ∑ x, a x = 0) {K t : ℝ} (ht : 0 ≤ t) (hK : 0 ≤ K) (hbound : ∀ x y, |interaction v p x y| ≤ K) (hKt : K*t ≤ 1) : + (∑ x, ∑ y, a x*a y*exp (t*interaction v p x y)) ≤ + t*(∑ i, (∑ x, a x*v x i)^2) + + K^2*t^2*(∑ x, |a x|)^2 := by + calc + _ ≤ ∑ x, ∑ y, ((a x*a y + t*(a x*a y*interaction v p x y)) + + (K^2*t^2)*(|a x| * |a y|)) := by + apply Finset.sum_le_sum + intro x _ + apply Finset.sum_le_sum + intro y _ + have hr := interaction_remainder_bound v p hK ht hbound hKt x y + have hb : a x*a y*(exp (t*interaction v p x y)-1-t*interaction v p x y) ≤ + |a x| * |a y| * (K^2*t^2) := by + calc + _ ≤ |a x*a y*(exp (t*interaction v p x y)-1-t*interaction v p x y)| := le_abs_self _ + _ = |a x| * |a y| * |exp (t*interaction v p x y)-1-t*interaction v p x y| := by simp [abs_mul] + _ ≤ _ := mul_le_mul_of_nonneg_left hr (mul_nonneg (abs_nonneg _) (abs_nonneg _)) + nlinarith only [hb] + _ = _ := by + simp only [Finset.sum_add_distrib, ← Finset.mul_sum] + rw [ha, signed_interaction v p a ha] + simp only [mul_zero, Finset.sum_const_zero, zero_add, ← Finset.sum_mul] + ring + +def quadraticIntegrand (p : Prior α) (a : α → ℝ) (t : ℝ) (z : Fin d → ℝ) : ℝ := + (∑ x, a x*likelihood v t x z)^2 / density v p t z + +lemma quadraticIntegrand_nonneg (p : Prior α) (a : α → ℝ) (t : ℝ) (z : Fin d → ℝ) : + 0 ≤ quadraticIntegrand v p a t z := div_nonneg (sq_nonneg _) (density_pos v p t z).le + +lemma quadraticIntegrand_le_majorant (p : Prior α) (a : α → ℝ) (t : ℝ) (z : Fin d → ℝ) : + quadraticIntegrand v p a t z ≤ majorant v p a t z := by + unfold quadraticIntegrand + calc + _ ≤ (∑ x, a x*likelihood v t x z)^2 / + exp (sqrt t * (∑ i, mean v p i*z i) - t*secondMoment v p/2) := + div_le_div_of_nonneg_left (sq_nonneg _) (exp_pos _) (density_jensen v p t z) + _ = _ := by simp only [majorant, div_eq_mul_inv, exp_neg] + +omit [Fintype α] in +lemma continuous_likelihood (t : ℝ) (x : α) : Continuous (likelihood v t x) := by + unfold likelihood + fun_prop + +lemma continuous_density (p : Prior α) (t : ℝ) : Continuous (density v p t) := by + unfold density + exact continuous_finsetSum _ (fun x _ => (continuous_likelihood v t x).const_mul _) + +lemma continuous_quadraticIntegrand (p : Prior α) (a : α → ℝ) (t : ℝ) : + Continuous (quadraticIntegrand v p a t) := by + apply Continuous.div + ((continuous_finsetSum _ (fun x _ => (continuous_likelihood v t x).const_mul (a x))).pow 2) + (continuous_density v p t) + intro z + exact (density_pos v p t z).ne' + +lemma integrable_quadraticIntegrand (p : Prior α) (a : α → ℝ) (t : ℝ) : + Integrable (quadraticIntegrand v p a t) (reference d) := by + apply (integrable_majorant v p a t).mono' (continuous_quadraticIntegrand v p a t).aestronglyMeasurable + filter_upwards [] with z + rw [Real.norm_eq_abs, abs_of_nonneg (quadraticIntegrand_nonneg v p a t z)] + exact quadraticIntegrand_le_majorant v p a t z + +theorem quadratic_bound (p : Prior α) (a : α → ℝ) (ha : ∑ x, a x = 0) + {K t : ℝ} (ht : 0 ≤ t) (hK : 0 ≤ K) (hbound : ∀ x y, |interaction v p x y| ≤ K) (hKt : K*t ≤ 1) : + (∫ z, quadraticIntegrand v p a t z ∂reference d) ≤ + t*(∑ i, (∑ x, a x*v x i)^2) + + K^2*t^2*(∑ x, |a x|)^2 := by + calc + _ ≤ ∫ z, majorant v p a t z ∂reference d := + integral_mono (integrable_quadraticIntegrand v p a t) (integrable_majorant v p a t) + (quadraticIntegrand_le_majorant v p a t) + _ = _ := integral_majorant v p a ht + _ ≤ _ := interaction_exp_sum_bound v p a ha ht hK hbound hKt + +def posterior (p : Prior α) (t : ℝ) (z : Fin d → ℝ) : Prior α where + mass x := p x * likelihood v t x z / density v p t z + nonneg x := div_nonneg (mul_nonneg (p.nonneg x) (likelihood_pos v t x z).le) + (density_pos v p t z).le + sum_one := by + rw [← Finset.sum_div] + exact div_self (density_pos v p t z).ne' + +lemma posterior_avg_weight (p : Prior α) (t : ℝ) (z : Fin d → ℝ) (f : α → ℝ) : + density v p t z * avg (posterior v p t z) f = ∑ x, (p x*f x)*likelihood v t x z := by + unfold avg FiniteLaw.mean posterior + rw [Finset.mul_sum] + apply Finset.sum_congr rfl + intro x _ + dsimp + field_simp [(density_pos v p t z).ne'] + +lemma integrable_posterior_avg_weight (p : Prior α) (t : ℝ) (f : α → ℝ) : + Integrable (fun z => density v p t z * avg (posterior v p t z) f) (reference d) := by + simp_rw [posterior_avg_weight] + exact integrable_finsetSum _ (fun x _ => (integrable_likelihood v t x).const_mul _) + +lemma integral_posterior_avg_weight (p : Prior α) {t : ℝ} (ht : 0 ≤ t) (f : α → ℝ) : + (∫ z, density v p t z * avg (posterior v p t z) f ∂reference d) = avg p f := by + simp_rw [posterior_avg_weight] + rw [integral_finsetSum _ (fun x _ => (integrable_likelihood v t x).const_mul _)] + simp_rw [integral_const_mul, integral_likelihood v ht, mul_one] + rfl + +lemma scalar_entropy_nonneg {r : ℝ} (hr : 0 < r) : 0 ≤ r*log r-r+1 := by + have h := mul_le_mul_of_nonneg_left (one_sub_inv_le_log_of_pos hr) hr.le + have hi : r*r⁻¹ = 1 := mul_inv_cancel₀ hr.ne' + nlinarith + +lemma scalar_entropy_le_square {r : ℝ} (hr : 0 < r) : r*log r-r+1 ≤ (r-1)^2 := by + have h := mul_le_mul_of_nonneg_left (log_le_sub_one_of_pos hr) hr.le + nlinarith + +def divergenceIntegrand (p q : Prior α) (t : ℝ) (z : Fin d → ℝ) : ℝ := + density v q t z * log (density v q t z/density v p t z) - density v q t z + density v p t z + +lemma divergenceIntegrand_eq (p q : Prior α) (t : ℝ) (z : Fin d → ℝ) : + divergenceIntegrand v p q t z = density v p t z * + ((density v q t z/density v p t z)*log (density v q t z/density v p t z)- + density v q t z/density v p t z+1) := by + unfold divergenceIntegrand + field_simp [(density_pos v p t z).ne'] + +lemma divergenceIntegrand_nonneg (p q : Prior α) (t : ℝ) (z : Fin d → ℝ) : + 0 ≤ divergenceIntegrand v p q t z := by + rw [divergenceIntegrand_eq] + exact mul_nonneg (density_pos v p t z).le + (scalar_entropy_nonneg (div_pos (density_pos v q t z) (density_pos v p t z))) + +lemma density_sub (p q : Prior α) (t : ℝ) (z : Fin d → ℝ) : + (∑ x, (q x-p x)*likelihood v t x z) = density v q t z-density v p t z := by + simp only [sub_mul, Finset.sum_sub_distrib, density] + +lemma divergenceIntegrand_le_quadratic (p q : Prior α) (t : ℝ) (z : Fin d → ℝ) : + divergenceIntegrand v p q t z ≤ quadraticIntegrand v p (fun x => q x-p x) t z := by + rw [divergenceIntegrand_eq, quadraticIntegrand, density_sub] + calc + _ ≤ density v p t z*(density v q t z/density v p t z-1)^2 := + mul_le_mul_of_nonneg_left + (scalar_entropy_le_square (div_pos (density_pos v q t z) (density_pos v p t z))) + (density_pos v p t z).le + _ = _ := by field_simp [(density_pos v p t z).ne'] + +lemma continuous_divergenceIntegrand (p q : Prior α) (t : ℝ) : + Continuous (divergenceIntegrand v p q t) := by + have hd := (continuous_density v q t).div (continuous_density v p t) + (fun z => (density_pos v p t z).ne') + exact (((continuous_density v q t).mul (hd.log (fun z => + (div_pos (density_pos v q t z) (density_pos v p t z)).ne'))).sub + (continuous_density v q t)).add (continuous_density v p t) + +lemma integrable_divergenceIntegrand (p q : Prior α) (t : ℝ) : + Integrable (divergenceIntegrand v p q t) (reference d) := by + apply (integrable_quadraticIntegrand v p (fun x => q x-p x) t).mono' + (continuous_divergenceIntegrand v p q t).aestronglyMeasurable + filter_upwards [] with z + rw [Real.norm_eq_abs, abs_of_nonneg (divergenceIntegrand_nonneg v p q t z)] + exact divergenceIntegrand_le_quadratic v p q t z + +lemma prior_sub_l1 (p q : Prior α) : (∑ x, |q x-p x|) ≤ 2 := by + calc + _ ≤ ∑ x, (q x+p x) := Finset.sum_le_sum (fun x _ => by + simpa only [abs_of_nonneg (q.nonneg x), abs_of_nonneg (p.nonneg x)] using abs_sub (q x) (p x)) + _ = 2 := by rw [Finset.sum_add_distrib, q.sum_one, p.sum_one]; norm_num + +lemma prior_sub_sum (p q : Prior α) : (∑ x, (q x-p x)) = 0 := by + rw [Finset.sum_sub_distrib, q.sum_one, p.sum_one, sub_self] + +theorem entropy_step_bound (p q : Prior α) {K t : ℝ} (ht : 0 ≤ t) + (hK : 0 ≤ K) (hbound : ∀ x y, |interaction v p x y| ≤ K) (hKt : K*t ≤ 1) : + (∫ z, divergenceIntegrand v p q t z ∂reference d) ≤ + t*(∑ i, (mean v q i-mean v p i)^2)+4*K^2*t^2 := by + have hmean : (∑ i, (∑ x, (q x-p x)*v x i)^2) = + ∑ i, (mean v q i-mean v p i)^2 := by + simp only [sub_mul, Finset.sum_sub_distrib, mean, avg, FiniteLaw.mean] + have he : (∑ x, |q x-p x|)^2 ≤ 4 := by + have hl : 0 ≤ ∑ x, |q x-p x| := Finset.sum_nonneg (fun _ _ => abs_nonneg _) + nlinarith [prior_sub_l1 p q] + calc + _ ≤ ∫ z, quadraticIntegrand v p (fun x => q x-p x) t z ∂reference d := + integral_mono (integrable_divergenceIntegrand v p q t) (integrable_quadraticIntegrand v p _ t) + (divergenceIntegrand_le_quadratic v p q t) + _ ≤ t*(∑ i, (mean v q i-mean v p i)^2)+K^2*t^2*(∑ x, |q x-p x|)^2 := by + simpa only [hmean] using quadratic_bound v p (fun x => q x-p x) (prior_sub_sum p q) ht hK hbound hKt + _ ≤ _ := by nlinarith [mul_le_mul_of_nonneg_left he (show 0 ≤ K^2*t^2 by positivity)] + +lemma integrable_relativeEntropy (p q : Prior α) (t : ℝ) : + Integrable (fun z => density v q t z*log (density v q t z/density v p t z)) (reference d) := by + have he : (fun z => density v q t z*log (density v q t z/density v p t z)) = + fun z => divergenceIntegrand v p q t z+density v q t z-density v p t z := by + funext z + unfold divergenceIntegrand + ring + rw [he] + exact ((integrable_divergenceIntegrand v p q t).add (integrable_density v q t)).sub + (integrable_density v p t) + +lemma integral_relativeEntropy (p q : Prior α) {t : ℝ} (ht : 0 ≤ t) : + (∫ z, density v q t z*log (density v q t z/density v p t z) ∂reference d) = + ∫ z, divergenceIntegrand v p q t z ∂reference d := by + have hi := integral_add + ((integrable_relativeEntropy v p q t).sub (integrable_density v q t)) (integrable_density v p t) + have hj := integral_sub (integrable_relativeEntropy v p q t) (integrable_density v q t) + simp only [Pi.sub_apply] at hi hj + rw [hj, integral_density v q ht, integral_density v p ht] at hi + change (∫ z, divergenceIntegrand v p q t z ∂reference d) = _ at hi + linarith + +lemma mean_abs_le (p : Prior α) {B : ℝ} (hB : ∀ x i, |v x i| ≤ B) (i : Fin d) : + |mean v p i| ≤ B := by + calc + _ ≤ ∑ x, |p x*v x i| := Finset.abs_sum_le_sum_abs _ _ + _ ≤ ∑ x, p x*B := Finset.sum_le_sum (fun x _ => by + rw [abs_mul,abs_of_nonneg (p.nonneg x)] + exact mul_le_mul_of_nonneg_left (hB x i) (p.nonneg x)) + _ = B := by rw [← Finset.sum_mul,p.sum_one,one_mul] + +omit [Fintype α] in +lemma normSq_nonneg (x : α) : 0 ≤ normSq v x := Finset.sum_nonneg (fun _ _ => sq_nonneg _) + +omit [Fintype α] in +lemma normSq_le {B : ℝ} (hB0 : 0 ≤ B) (hB : ∀ x i, |v x i| ≤ B) (x : α) : + normSq v x ≤ d*B^2 := by + calc + _ ≤ ∑ _i : Fin d, B^2 := Finset.sum_le_sum (fun i _ => by + simpa only [sq_abs] using (sq_le_sq₀ (abs_nonneg _) hB0).mpr (hB x i)) + _ = _ := by simp + +lemma interaction_abs_le (p : Prior α) {B : ℝ} (hB0 : 0 ≤ B) + (hB : ∀ x i, |v x i| ≤ B) (x y : α) : + |interaction v p x y| ≤ 5*d*B^2 := by + have hmean (i : Fin d) := mean_abs_le v p hB i + have hsec : 0 ≤ secondMoment v p := avg_nonneg p (normSq_nonneg v) + have hsecb : secondMoment v p ≤ d*B^2 := by + exact (avg_mono p (normSq_le v hB0 hB)).trans_eq (avg_const p _) + have hs0 : 0 ≤ ∑ i, (v x i+v y i-mean v p i)^2 := + Finset.sum_nonneg (fun _ _ => sq_nonneg _) + have hsum : (∑ i, (v x i+v y i-mean v p i)^2) ≤ 9*d*B^2 := by + calc + _ ≤ ∑ _i : Fin d, (3*B)^2 := by + apply Finset.sum_le_sum + intro i _ + have hh : |v x i+v y i-mean v p i| ≤ 3*B := by + have hh := (abs_sub (v x i+v y i) (mean v p i)).trans + (add_le_add (abs_add_le (v x i) (v y i)) le_rfl) + linarith [hB x i,hB y i,hmean i] + simpa only [sq_abs] using (sq_le_sq₀ (abs_nonneg _) (by positivity)).mpr hh + _ = _ := by simp;ring + rw [abs_le] + unfold interaction + constructor <;> nlinarith [normSq_nonneg v x,normSq_nonneg v y, + normSq_le v hB0 hB x,normSq_le v hB0 hB y, + mul_nonneg (Nat.cast_nonneg (α := ℝ) d) (sq_nonneg B)] + +theorem exists_interaction_bound : ∃ K : ℝ, 0 ≤ K ∧ + ∀ p : Prior α, ∀ x y, |interaction v p x y| ≤ K := by + let B := ∑ x, ∑ i, |v x i| + have hB0 : 0 ≤ B := Finset.sum_nonneg (fun _ _ => Finset.sum_nonneg (fun _ _ => abs_nonneg _)) + have hB (x : α) (i : Fin d) : |v x i| ≤ B := by + exact (Finset.single_le_sum (f := fun j => |v x j|) + (fun _ _ => abs_nonneg _) (Finset.mem_univ i)).trans + (Finset.single_le_sum (f := fun y => ∑ j, |v y j|) + (fun _ _ => Finset.sum_nonneg (fun _ _ => abs_nonneg _)) (Finset.mem_univ x)) + exact ⟨5*d*B^2,by positivity,fun p x y => interaction_abs_le v p hB0 hB x y⟩ + +lemma reweight_density (p : Prior α) (f : α → ℝ) (hf : ∀ x, 0 < f x) + (t : ℝ) (z : Fin d → ℝ) : + density v (reweight p f hf) t z = + density v p t z*avg (posterior v p t z) f/avg p f := by + rw [posterior_avg_weight] + unfold density reweight + dsimp + rw [Finset.sum_div] + exact Finset.sum_congr rfl (fun x _ => by ring) + +lemma posterior_avg_eq_density_ratio (p : Prior α) (f : α → ℝ) (hf : ∀ x, 0 < f x) + (t : ℝ) (z : Fin d → ℝ) : + avg (posterior v p t z) f = avg p f*(density v (reweight p f hf) t z/density v p t z) := by + rw [reweight_density] + field_simp [(avg_pos p hf).ne',(density_pos v p t z).ne'] + +lemma posterior_entropy_identity (p : Prior α) (f : α → ℝ) (hf : ∀ x, 0 < f x) + (t : ℝ) (z : Fin d → ℝ) : + density v p t z*ent (posterior v p t z) f = + density v p t z*avg (posterior v p t z) (fun x => f x*log (f x)) - + avg p f*(density v (reweight p f hf) t z*log (density v (reweight p f hf) t z/density v p t z)) - + log (avg p f)*(density v p t z*avg (posterior v p t z) f) := by + change density v p t z*(avg (posterior v p t z) (fun x => f x*log (f x))- + avg (posterior v p t z) f*log (avg (posterior v p t z) f)) = _ + rw [posterior_avg_eq_density_ratio v p f hf,log_mul (avg_pos p hf).ne' + (div_pos (density_pos v (reweight p f hf) t z) (density_pos v p t z)).ne'] + field_simp [(density_pos v p t z).ne'] + ring + +lemma integrable_posterior_entropy_weight (p : Prior α) (f : α → ℝ) (hf : ∀ x, 0 < f x) (t : ℝ) : + Integrable (fun z => density v p t z*ent (posterior v p t z) f) (reference d) := by + simp_rw [posterior_entropy_identity v p f hf] + exact ((integrable_posterior_avg_weight v p t _).sub + ((integrable_relativeEntropy v p (reweight p f hf) t).const_mul _)).sub + ((integrable_posterior_avg_weight v p t f).const_mul _) + +lemma integral_posterior_entropy (p : Prior α) (f : α → ℝ) (hf : ∀ x, 0 < f x) + {t : ℝ} (ht : 0 ≤ t) : + (∫ z, density v p t z*ent (posterior v p t z) f ∂reference d) = + ent p f-avg p f*(∫ z, divergenceIntegrand v p (reweight p f hf) t z ∂reference d) := by + simp_rw [posterior_entropy_identity v p f hf] + have h₁ := integrable_posterior_avg_weight v p t (fun x => f x*log (f x)) + have h₂ := (integrable_relativeEntropy v p (reweight p f hf) t).const_mul (avg p f) + have h₃ := (integrable_posterior_avg_weight v p t f).const_mul (log (avg p f)) + have h₄ := integral_sub (h₁.sub h₂) h₃ + have h₅ := integral_sub h₁ h₂ + simp only [Pi.sub_apply] at h₄ h₅ + rw [h₄,h₅,integral_const_mul,integral_const_mul, + integral_posterior_avg_weight v p ht,integral_posterior_avg_weight v p ht, + integral_relativeEntropy v p (reweight p f hf) ht] + unfold ent FiniteLaw.entropy avg + ring + +theorem entropy_retention (p : Prior α) (f : α → ℝ) (hf : ∀ x, 0 < f x) + (hp : ∀ x, 0 < p x) {C K t : ℝ} (hC : 0 < C) (ht : 0 ≤ t) + (hK : 0 ≤ K) (hbound : ∀ x y, |interaction v p x y| ≤ K) (hKt : K*t ≤ 1) + (hvar : ∀ a : Fin d → ℝ, ∀ s : ℝ, + var (tilt p (linear v a) s) (linear v a) ≤ C*(∑ i, a i^2)) : + (1-2*C*t)*ent p f-4*K^2*t^2*avg p f ≤ + ∫ z, density v p t z*ent (posterior v p t z) f ∂reference d := by + have h := entropy_step_bound v p (reweight p f hf) ht hK hbound hKt + have hd := vector_mean_displacement_sq p (reweight p f hf) v hp hC hvar + rw [relativeEntropy_reweight p f hf hp] at hd + change (∑ i, (mean v (reweight p f hf) i-mean v p i)^2) ≤ _ at hd + have he := mul_le_mul_of_nonneg_left hd ht + have hh := mul_le_mul_of_nonneg_left + (h.trans (add_le_add he le_rfl)) (avg_pos p hf).le + rw [integral_posterior_entropy v p f hf ht] + have heq : avg p f*(t*(2*C*(ent p f/avg p f))+4*K^2*t^2) = + 2*C*t*ent p f+4*K^2*t^2*avg p f := by + field_simp [(avg_pos p hf).ne'] + rw [heq] at hh + nlinarith only [hh] + +end SKRatio.Observation.Channel + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Entropy/GaussianHistory.lean b/lean/OAI/Probability/SKRatio/Entropy/GaussianHistory.lean new file mode 100644 index 0000000000000000000000000000000000000000..7b607af08a409d90223549d112af68ba364618ef --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Entropy/GaussianHistory.lean @@ -0,0 +1,329 @@ +import Mathlib +import OAI.Probability.SKRatio.Entropy.GaussianChannel +import OAI.Probability.SKRatio.Entropy.FiniteEntropy + +namespace OAI + +section +noncomputable section +open scoped BigOperators ENNReal NNReal Topology +open MeasureTheory ProbabilityTheory Real Set Filter +namespace SKRatio.Observation + +abbrev History (d : ℕ) : ℕ → Type + | 0 => Unit + | k+1 => History d k × (Fin d → ℝ) + +namespace History +variable {α : Type*} {d : ℕ} + +@[reducible] instance historyMeasurable (d : ℕ) : (k : ℕ) → MeasurableSpace (History d k) + | 0 => inferInstanceAs (MeasurableSpace Unit) + | k+1 => by + change MeasurableSpace (History d k × (Fin d → ℝ)) + letI := historyMeasurable d k + infer_instance + +@[reducible] instance historyTopology (d : ℕ) : (k : ℕ) → TopologicalSpace (History d k) + | 0 => inferInstanceAs (TopologicalSpace Unit) + | k+1 => by + change TopologicalSpace (History d k × (Fin d → ℝ)) + letI := historyTopology d k + infer_instance + +instance historySecondCountable (d : ℕ) : (k : ℕ) → SecondCountableTopology (History d k) + | 0 => inferInstanceAs (SecondCountableTopology Unit) + | k+1 => by + change SecondCountableTopology (History d k × (Fin d → ℝ)) + let := historySecondCountable d k + infer_instance + +instance historyBorel (d : ℕ) : (k : ℕ) → BorelSpace (History d k) + | 0 => inferInstanceAs (BorelSpace Unit) + | k+1 => by + change BorelSpace (History d k × (Fin d → ℝ)) + let := historyBorel d k + infer_instance + +def reference (d : ℕ) : (k : ℕ) → Measure (History d k) + | 0 => Measure.dirac () + | k+1 => (reference d k).prod (Channel.reference d) + +instance reference_probability (d : ℕ) : (k : ℕ) → IsProbabilityMeasure (reference d k) + | 0 => inferInstanceAs (IsProbabilityMeasure (Measure.dirac ())) + | k+1 => by + change IsProbabilityMeasure ((reference d k).prod (Channel.reference d)) + let := reference_probability d k + infer_instance + +variable (v : α → Fin d → ℝ) + +def likelihood (t : ℝ) (x : α) : {k : ℕ} → History d k → ℝ + | 0, _ => 1 + | _+1, h => likelihood t x h.1 * Channel.likelihood v t x h.2 + +lemma likelihood_pos (t : ℝ) (x : α) : ∀ {k : ℕ} (h : History d k), + 0 < likelihood v t x h + | 0, _ => zero_lt_one + | _+1, h => mul_pos (likelihood_pos t x h.1) (Channel.likelihood_pos v t x h.2) + +lemma continuous_likelihood (t : ℝ) (x : α) : ∀ k, + Continuous (likelihood v t x (k := k)) + | 0 => continuous_const + | k+1 => (continuous_likelihood t x k).comp continuous_fst |>.mul + ((Channel.continuous_likelihood v t x).comp continuous_snd) + +lemma integrable_likelihood (t : ℝ) (x : α) : ∀ k, + Integrable (likelihood v t x (k := k)) (reference d k) + | 0 => by + change Integrable (fun _ : Unit => (1:ℝ)) (Measure.dirac ()) + exact integrable_const 1 + | k+1 => (integrable_likelihood t x k).mul_prod (Channel.integrable_likelihood v t x) + +lemma integral_likelihood {t : ℝ} (ht : 0 ≤ t) (x : α) : ∀ k, + (∫ h : History d k, likelihood v t x h ∂reference d k) = 1 + | 0 => by + change (∫ _ : Unit, (1:ℝ) ∂Measure.dirac ()) = 1 + rw [integral_dirac] + | k+1 => by + change (∫ h, likelihood v t x h.1 * Channel.likelihood v t x h.2 + ∂(reference d k).prod (Channel.reference d)) = 1 + rw [integral_prod_mul, integral_likelihood ht x k, Channel.integral_likelihood v ht, mul_one] + +variable [Fintype α] + +def density (p : Prior α) (t : ℝ) {k : ℕ} (h : History d k) : ℝ := + ∑ x, p x*likelihood v t x h + +lemma density_pos (p : Prior α) (t : ℝ) {k : ℕ} (h : History d k) : + 0 < density v p t h := by + have he : ∃ x, 0 < p x := by + by_contra hn + push Not at hn + have hz : ∑ x, p x = 0 := Finset.sum_eq_zero (fun x _ => le_antisymm (hn x) (p.nonneg x)) + linarith [p.sum_one] + obtain ⟨x,hx⟩ := he + exact Finset.sum_pos' (fun y _ => mul_nonneg (p.nonneg y) (likelihood_pos v t y h).le) + ⟨x, Finset.mem_univ _, mul_pos hx (likelihood_pos v t x h)⟩ + +lemma continuous_density (p : Prior α) (t : ℝ) (k : ℕ) : Continuous (density v p t (k := k)) := + continuous_finsetSum _ (fun x _ => (continuous_likelihood v t x k).const_mul (p x)) + +lemma integrable_density (p : Prior α) (t : ℝ) (k : ℕ) : + Integrable (density v p t (k := k)) (reference d k) := + integrable_finsetSum _ (fun x _ => (integrable_likelihood v t x k).const_mul (p x)) + +lemma integral_density (p : Prior α) {t : ℝ} (ht : 0 ≤ t) (k : ℕ) : + (∫ h : History d k, density v p t h ∂reference d k) = 1 := by + unfold density + rw [integral_finsetSum _ (fun x _ => (integrable_likelihood v t x k).const_mul (p x))] + simp_rw [integral_const_mul, integral_likelihood v ht, mul_one] + exact p.sum_one + +def posterior (p : Prior α) (t : ℝ) {k : ℕ} (h : History d k) : Prior α where + mass x := p x*likelihood v t x h/density v p t h + nonneg x := div_nonneg (mul_nonneg (p.nonneg x) (likelihood_pos v t x h).le) (density_pos v p t h).le + sum_one := by rw [← Finset.sum_div]; exact div_self (density_pos v p t h).ne' + +lemma density_zero (p : Prior α) (t : ℝ) (h : History d 0) : density v p t h=1 := by + simp only [density, likelihood, mul_one, p.sum_one] + +lemma posterior_zero (p : Prior α) (t : ℝ) (h : History d 0) : posterior v p t h=p := by + apply Prior.ext + funext x + change p x*1/density v p t h=p x + rw [density_zero v, mul_one, div_one] + +lemma density_succ (p : Prior α) (t : ℝ) {k : ℕ} (h : History d k) (z : Fin d → ℝ) : + density v p t (k := k+1) (h,z) = density v p t h*Channel.density v (posterior v p t h) t z := by + change (∑ x, p x*(likelihood v t x h*Channel.likelihood v t x z)) = + density v p t h*(∑ x, (p x*likelihood v t x h/density v p t h)*Channel.likelihood v t x z) + rw [Finset.mul_sum] + apply Finset.sum_congr rfl + intro x _ + field_simp [(density_pos v p t h).ne'] + +lemma posterior_succ (p : Prior α) (t : ℝ) {k : ℕ} (h : History d k) (z : Fin d → ℝ) : + posterior v p t (k := k+1) (h,z) = Channel.posterior v (posterior v p t h) t z := by + apply Prior.ext + funext x + change p x*(likelihood v t x h*Channel.likelihood v t x z)/density v p t (k := k+1) (h,z) = + (p x*likelihood v t x h/density v p t h)*Channel.likelihood v t x z / + Channel.density v (posterior v p t h) t z + rw [density_succ v] + field_simp [(density_pos v p t h).ne', (Channel.density_pos v (posterior v p t h) t z).ne'] + +lemma posterior_avg_weight (p : Prior α) (t : ℝ) {k : ℕ} (h : History d k) (f : α → ℝ) : + density v p t h*avg (posterior v p t h) f=∑ x, p x*likelihood v t x h*f x := by + simp only [avg,FiniteLaw.mean, posterior, Finset.mul_sum] + apply Finset.sum_congr rfl + intro x _ + field_simp [(density_pos v p t h).ne'] + +lemma integrable_posterior_avg_weight (p : Prior α) (t : ℝ) (f : α → ℝ) (k : ℕ) : + Integrable (fun h : History d k => density v p t h*avg (posterior v p t h) f) (reference d k) := by + simp_rw [posterior_avg_weight v] + exact integrable_finsetSum _ (fun x _ => ((integrable_likelihood v t x k).const_mul (p x)).mul_const (f x)) + +lemma integral_posterior_avg_weight (p : Prior α) {t : ℝ} (ht : 0 ≤ t) (f : α → ℝ) (k : ℕ) : + (∫ h : History d k, density v p t h*avg (posterior v p t h) f ∂reference d k)=avg p f := by + simp_rw [posterior_avg_weight v] + rw [integral_finsetSum _ (fun x _ => ((integrable_likelihood v t x k).const_mul (p x)).mul_const (f x))] + simp_rw [integral_mul_const, integral_const_mul, integral_likelihood v ht, mul_one] + rfl + +lemma posterior_mass_pos (p : Prior α) (hp : ∀ x,0 < p x) (t : ℝ) + {k : ℕ} (h : History d k) (x : α) : 0 < posterior v p t h x := + div_pos (mul_pos (hp x) (likelihood_pos v t x h)) (density_pos v p t h) + +lemma continuous_posterior_mass (p : Prior α) (t : ℝ) (k : ℕ) (x : α) : + Continuous (fun h : History d k => posterior v p t h x) := + ((continuous_likelihood v t x k).const_mul (p x)).div (continuous_density v p t k) + (fun h => (density_pos v p t h).ne') + +lemma continuous_posterior_entropy (p : Prior α) (f : α → ℝ) (t : ℝ) (k : ℕ) : + Continuous (fun h : History d k => ent (posterior v p t h) f) := + (continuous_entropy_masses f).comp (continuous_pi (continuous_posterior_mass v p t k)) + +lemma integrable_posterior_entropy_weight (p : Prior α) (f : α → ℝ) (hf : ∀ x,0 density v p t h*ent (posterior v p t h) f) (reference d k) := by + apply ((integrable_density v p t k).mul_const (∑ x,logRemainder (f x) 1)).mono' + ((continuous_density v p t k).mul (continuous_posterior_entropy v p f t k)).aestronglyMeasurable + filter_upwards [] with h + change |density v p t h*ent (posterior v p t h) f| ≤ _ + rw [abs_of_nonneg (mul_nonneg (density_pos v p t h).le (ent_nonneg _ hf))] + exact mul_le_mul_of_nonneg_left (ent_bound _ f hf) (density_pos v p t h).le + +def remainingEntropy (p : Prior α) (f : α → ℝ) (t : ℝ) (k : ℕ) : ℝ := + ∫ h : History d k, density v p t h*ent (posterior v p t h) f ∂reference d k + +lemma remainingEntropy_zero (p : Prior α) (f : α → ℝ) (t : ℝ) : + remainingEntropy v p f t 0=ent p f := by + unfold remainingEntropy + simp only [density_zero,posterior_zero,one_mul] + change (∫ _ : Unit, ent p f ∂Measure.dirac ()) = ent p f + rw [integral_dirac] + +lemma remainingEntropy_succ (p : Prior α) (f : α → ℝ) (hf : ∀ x,0 by + have hh := mul_le_mul_of_nonneg_left + (Channel.entropy_retention v (posterior v p t h) f hf (posterior_mass_pos v p hp t h) + hC ht hK (hbound _) hKt (hvar h)) (density_pos v p t h).le + convert! hh using 1 + dsimp + ring) + simp only [Pi.sub_apply] at hh + rw [integral_sub ((integrable_posterior_entropy_weight v p f hf t k).const_mul (1-2*C*t)) + ((integrable_posterior_avg_weight v p t f k).const_mul (4*K^2*t^2)), + integral_const_mul,integral_const_mul,integral_posterior_avg_weight v p ht] at hh + rw [remainingEntropy_succ v p f hf t k] + exact hh + +lemma affine_lower (u : ℕ → ℝ) {r b : ℝ} (hr : 0≤r) (hr1 : r≤1) (hb : 0≤b) + (N : ℕ) (hstep : ∀ k simp + | succ N ih => + have hi := mul_le_mul_of_nonneg_left (ih (fun k hk => hstep k (hk.trans (Nat.lt_succ_self N)))) hr + have hs := hstep N (Nat.lt_succ_self N) + have hb' := mul_le_mul_of_nonneg_right hr1 (show 0≤(N:ℝ)*b by positivity) + rw [Nat.cast_add,Nat.cast_one,pow_succ] + nlinarith + +lemma exp_neg_two_le {x : ℝ} (hx : 0≤x) (hx1 : x≤1/2) : exp (-2*x)≤1-x := by + have hpos : 0<1-x := by linarith + have hi : (1-x)⁻¹≤1+2*x := by + rw [inv_eq_one_div,div_le_iff₀ hpos] + nlinarith + have hl := Real.one_sub_inv_le_log_of_pos hpos + have hh : -2*x≤log (1-x) := by linarith + simpa only [Real.exp_log hpos] using Real.exp_le_exp.mpr hh + +lemma pow_one_sub_lower {x : ℝ} (hx : 0≤x) (hx1 : x≤1/2) (N : ℕ) : + exp (-2*(N:ℝ)*x)≤(1-x)^N := by + have hh := pow_le_pow_left₀ (exp_pos (-2*x)).le (exp_neg_two_le hx hx1) N + rw [←Real.exp_nat_mul] at hh + convert! hh using 1 + congr 1 + ring + +lemma entropy_retention_mesh (p : Prior α) (hp : ∀ x,0

entropy_recurrence v p hp f hf hC ht hK hbound hk k (hvar k hkn)) + rw [remainingEntropy_zero] at hs + have he : (N:ℝ)*(4*K^2*((N:ℝ)⁻¹)^2*avg p f)=4*K^2/(N:ℝ)*avg p f := by + field_simp [hn.ne'] + have hh := pow_one_sub_lower (mul_nonneg (by positivity : 0≤2*C) ht) hc N + have hee : -2*(N:ℝ)*(2*C*(N:ℝ)⁻¹) = -4*C := by field_simp [hn.ne'];ring + rw [hee] at hh + rw [he] at hs + exact (sub_le_sub_right (mul_le_mul_of_nonneg_right hh (ent_nonneg p hf)) _).trans hs + +theorem entropy_of_observation_estimates (p : Prior α) (hp : ∀ x,0

(N:ℝ)⁻¹) atTop (𝓝 0) := + tendsto_inv_atTop_zero.comp tendsto_natCast_atTop_atTop + have hlim : Tendsto (fun N : ℕ => E+4*K^2/(N:ℝ)*avg p f) atTop (𝓝 E) := by + simpa only [div_eq_mul_inv,mul_zero,zero_mul,add_zero] using + tendsto_const_nhds.add ((tendsto_const_nhds.mul hinv).mul_const (avg p f)) + apply ge_of_tendsto hlim + filter_upwards [eventually_gt_atTop 0, + (tendsto_natCast_atTop_atTop (R := ℝ)).eventually (eventually_ge_atTop (4*C)), + (tendsto_natCast_atTop_atTop (R := ℝ)).eventually (eventually_ge_atTop K)] with N hn hc hk + have hh := (entropy_retention_mesh v p hp f hf hC hK hbound hn hc hk (hvar N hn)).trans + (hterminal N hn) + linarith only [hh] + +end History +end SKRatio.Observation + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Entropy/GibbsObservation.lean b/lean/OAI/Probability/SKRatio/Entropy/GibbsObservation.lean new file mode 100644 index 0000000000000000000000000000000000000000..4e67fdcb1a394982e0882d01c546f2b65daa2444 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Entropy/GibbsObservation.lean @@ -0,0 +1,283 @@ +import Mathlib +import OAI.Probability.SKRatio.Entropy.GaussianHistory +import OAI.Probability.SKRatio.Entropy.ProductEntropy + +namespace OAI + +section +noncomputable section +open scoped BigOperators Matrix MatrixOrder Topology +open MeasureTheory Real Matrix +namespace SKRatio.Observation +open Calculus Fields +attribute [local instance] Classical.propDecidable +variable {n : ℕ} + +lemma abs_quadratic_le_opNorm (J : Interaction n) (z : Fin n → ℝ) : + |z ⬝ᵥ Matrix.mulVec J z| ≤ euclideanOpNorm J*(∑ i,z i^2) := by + let Z : EuclideanSpace ℝ (Fin n) := WithLp.toLp 2 z + have hi : z ⬝ᵥ Matrix.mulVec J z = inner ℝ Z (Matrix.toEuclideanCLM (𝕜 := ℝ) J Z) := + (Matrix.inner_toEuclideanCLM J Z Z).symm + rw [hi] + calc + _ ≤ ‖Z‖*‖Matrix.toEuclideanCLM (𝕜 := ℝ) J Z‖ := abs_real_inner_le_norm _ _ + _ ≤ ‖Z‖*(euclideanOpNorm J*‖Z‖) := + mul_le_mul_of_nonneg_left ((Matrix.toEuclideanCLM (𝕜 := ℝ) J).le_opNorm _) (norm_nonneg _) + _ = _ := by + rw [show ‖Z‖*(euclideanOpNorm J*‖Z‖)=euclideanOpNorm J*‖Z‖^2 by ring, + EuclideanSpace.real_norm_sq_eq] + +def shiftedCoupling (g : Disorder n) : Matrix (Fin n) (Fin n) ℝ := Matrix.of (coupling g) + (2:ℝ) • 1 + +lemma shiftedCoupling_quad (g : Disorder n) (z : Fin n → ℝ) : + z ⬝ᵥ (shiftedCoupling g).mulVec z = z ⬝ᵥ Matrix.mulVec (coupling g) z + 2*∑ i,z i^2 := by + simp only [shiftedCoupling,Matrix.add_mulVec,Matrix.smul_mulVec,Matrix.one_mulVec, + dotProduct,Pi.add_apply,Pi.smul_apply,smul_eq_mul,mul_add,Finset.sum_add_distrib, + pow_two,←mul_assoc] + congr 1 + rw [Finset.mul_sum] + apply Finset.sum_congr rfl + intro i _ + ring + +lemma shiftedCoupling_nonneg (g : Disorder n) (hg : euclideanOpNorm (coupling g) ≤ 2) : + 0 ≤ shiftedCoupling g := by + apply Matrix.PosSemidef.nonneg + rw [Matrix.posSemidef_iff_dotProduct_mulVec] + constructor + · apply Matrix.isHermitian_iff_isSymm.mpr + apply Matrix.IsSymm.add + · ext i j + exact coupling_symm g j i + · exact Matrix.isSymm_one.smul _ + · intro z + simp only [star_trivial] + rw [shiftedCoupling_quad] + have hh := (abs_quadratic_le_opNorm (coupling g) z).trans + (mul_le_mul_of_nonneg_right hg (Finset.sum_nonneg (fun _ _ => sq_nonneg _))) + linarith only [neg_abs_le (z ⬝ᵥ Matrix.mulVec (coupling g) z),hh] + +def observationMatrix (g : Disorder n) : Matrix (Fin n) (Fin n) ℝ := CFC.sqrt (shiftedCoupling g) + +lemma observationMatrix_symm (g : Disorder n) : (observationMatrix g).IsSymm := + Matrix.isHermitian_iff_isSymm.mp (Matrix.nonneg_iff_posSemidef.mp (CFC.sqrt_nonneg _)).1 + +lemma observationMatrix_square (g : Disorder n) (hg : euclideanOpNorm (coupling g)≤2) : + observationMatrix g * observationMatrix g = shiftedCoupling g := by + simpa only [observationMatrix,pow_two] using CFC.sq_sqrt (shiftedCoupling g) (shiftedCoupling_nonneg g hg) + +lemma symmetric_mulVec_dot (A : Matrix (Fin n) (Fin n) ℝ) (hA : A.IsSymm) + (z y : Fin n → ℝ) : A.mulVec z ⬝ᵥ y = z ⬝ᵥ A.mulVec y := by + rw [Matrix.dotProduct_mulVec] + have he : Matrix.vecMul z A = A.mulVec z := by + ext i + simp only [Matrix.vecMul,Matrix.mulVec,dotProduct] + apply Finset.sum_congr rfl + intro j _ + rw [show A j i = A i j from congrFun (congrFun hA i) j] + ring + rw [he] + +lemma observationMatrix_normSq (g : Disorder n) (hg : euclideanOpNorm (coupling g)≤2) + (z : Fin n → ℝ) : + (∑ i, ((observationMatrix g).mulVec z i)^2) = + z ⬝ᵥ Matrix.mulVec (coupling g) z+2*∑ i,z i^2 := by + have he : (∑ i, ((observationMatrix g).mulVec z i)^2) = + (observationMatrix g).mulVec z ⬝ᵥ (observationMatrix g).mulVec z := by + simp only [dotProduct,pow_two] + rw [he,symmetric_mulVec_dot _ (observationMatrix_symm g),Matrix.mulVec_mulVec, + observationMatrix_square g hg,shiftedCoupling_quad] + +lemma observationMatrix_normSq_le (g : Disorder n) (hg : euclideanOpNorm (coupling g)≤2) + (z : Fin n → ℝ) : (∑ i, ((observationMatrix g).mulVec z i)^2) ≤ 4*∑ i,z i^2 := by + rw [observationMatrix_normSq g hg] + have hh := (le_abs_self (z ⬝ᵥ Matrix.mulVec (coupling g) z)).trans + ((abs_quadratic_le_opNorm (coupling g) z).trans + (mul_le_mul_of_nonneg_right hg (Finset.sum_nonneg (fun _ _ => sq_nonneg _)))) + linarith only [hh] + +def gibbsFeature (g : Disorder n) (x : Spin n) : Fin n → ℝ := + (observationMatrix g).mulVec (fun i => spinValue (x i)) + +lemma gibbsFeature_normSq (g : Disorder n) (hg : euclideanOpNorm (coupling g)≤2) (x : Spin n) : + Channel.normSq (gibbsFeature g) x = 2*hamiltonian g 0 x+2*n := by + unfold Channel.normSq gibbsFeature + rw [observationMatrix_normSq g hg] + have hs (i : Fin n) : spinValue (x i)^2 = 1 := by cases x i <;> norm_num [spinValue] + simp only [hs,Finset.sum_const,Finset.card_univ,Fintype.card_fin,nsmul_eq_mul,mul_one, + hamiltonian,Pi.zero_apply,zero_mul,dotProduct, + Matrix.mulVec,Finset.mul_sum] + have he : (∑ i,∑ j,spinValue (x i)*(coupling g i j*spinValue (x j))) = + (∑ i,∑ j,spinValue (x i)*coupling g i j*spinValue (x j)) := by + simp only [mul_assoc] + rw [he] + simp only [←Finset.mul_sum] + ring + +lemma gibbsFeature_linear (g : Disorder n) (a : Fin n → ℝ) : + linear (gibbsFeature g) a = Fields.linearObservable ((observationMatrix g).mulVec a) := by + funext x + change a ⬝ᵥ (observationMatrix g).mulVec (fun i => spinValue (x i)) = + (observationMatrix g).mulVec a ⬝ᵥ (fun i => spinValue (x i)) + exact (symmetric_mulVec_dot _ (observationMatrix_symm g) _ _).symm + +lemma hamiltonian_scale (g : Disorder n) (h : Fin n → ℝ) (s : ℝ) (x : Spin n) : + hamiltonian (s • g) h x = s*hamiltonian g 0 x+Fields.linearObservable h x := by + simp only [hamiltonian,Fields.coupling_smul,Pi.zero_apply,zero_mul,Finset.sum_const_zero, + add_zero,Fields.linearObservable,mul_left_comm (spinValue (x _)) s,mul_assoc, + ←Finset.mul_sum] + ring + +lemma channel_weight_identity (g : Disorder n) (hg : euclideanOpNorm (coupling g)≤2) + (s t : ℝ) (h z : Fin n → ℝ) (x : Spin n) : + weight (s • g) h x*Channel.likelihood (gibbsFeature g) t x z = + exp (-t*n)*weight ((s-t) • g) (h+sqrt t • (observationMatrix g).mulVec z) x := by + simp only [weight,Channel.likelihood,←exp_add,gibbsFeature_normSq g hg,hamiltonian_scale] + congr 1 + have he : (∑ i,gibbsFeature g x i*z i)= + Fields.linearObservable ((observationMatrix g).mulVec z) x := by + simpa only [linear,mul_comm] using congrFun (gibbsFeature_linear g z) x + rw [he] + simp only [Fields.linearObservable,Pi.add_apply,Pi.smul_apply,smul_eq_mul,add_mul, + Finset.sum_add_distrib,mul_assoc,←Finset.mul_sum] + ring + +lemma channel_posterior_gibbs (g : Disorder n) (hg : euclideanOpNorm (coupling g)≤2) + (s t : ℝ) (h z : Fin n → ℝ) : + Channel.posterior (gibbsFeature g) (gibbsPrior (s • g) h) t z = + gibbsPrior ((s-t) • g) (h+sqrt t • (observationMatrix g).mulVec z) := by + let h' := h+sqrt t • (observationMatrix g).mulVec z + have hn (x : Spin n) : gibbsPrior (s • g) h x*Channel.likelihood (gibbsFeature g) t x z = + (exp (-t*n)/partition (s • g) h)*weight ((s-t) • g) h' x := by + change weight (s • g) h x/partition (s • g) h*Channel.likelihood (gibbsFeature g) t x z = _ + rw [div_mul_eq_mul_div,channel_weight_identity g hg] + ring + have hd : Channel.density (gibbsFeature g) (gibbsPrior (s • g) h) t z = + (exp (-t*n)/partition (s • g) h)*partition ((s-t) • g) h' := by + simp only [Channel.density,hn,←Finset.mul_sum,partition] + apply Prior.ext + funext x + change (gibbsPrior (s • g) h x*Channel.likelihood (gibbsFeature g) t x z)/ + Channel.density (gibbsFeature g) (gibbsPrior (s • g) h) t z = + weight ((s-t) • g) h' x/partition ((s-t) • g) h' + rw [hn,hd] + field_simp [(exp_pos (-t*n)).ne',(partition_pos (s • g) h).ne', + (partition_pos ((s-t) • g) h').ne'] + +def observedField (g : Disorder n) (t : ℝ) (h₀ : Fin n → ℝ) : + {k : ℕ} → History n k → Fin n → ℝ + | 0,_ => h₀ + | _+1,h => observedField g t h₀ h.1+sqrt t • (observationMatrix g).mulVec h.2 + +lemma history_posterior_gibbs (g : Disorder n) (hg : euclideanOpNorm (coupling g)≤2) + (t : ℝ) (h₀ : Fin n → ℝ) : ∀ {k : ℕ} (h : History n k), + History.posterior (gibbsFeature g) (gibbsPrior g h₀) t h = + gibbsPrior ((1-(k:ℝ)*t) • g) (observedField g t h₀ h) + | 0,h => by simp only [History.posterior_zero,Nat.cast_zero,zero_mul,sub_zero,one_smul, + observedField] + | k+1,h => by + rw [History.posterior_succ,history_posterior_gibbs g hg t h₀ h.1, + channel_posterior_gibbs g hg] + simp only [observedField,Nat.cast_add,Nat.cast_one] + congr 2 + ring + +def fieldPrior (h : ℝ) : Prior Bool where + mass b := exp (h*spinValue b)/(exp h+exp (-h)) + nonneg b := div_nonneg (exp_pos _).le (add_pos (exp_pos _) (exp_pos _)).le + sum_one := by + simp only [Fintype.sum_bool,spinValue_true,spinValue_false,mul_one,mul_neg_one,←add_div] + exact div_self (add_pos (exp_pos _) (exp_pos _)).ne' + +lemma fieldPrior_pos (h : ℝ) (b : Bool) : 0 fieldPrior (h i)) := by + have hw (x : Spin n) : weight ((0:ℝ) • g) h x = ∏ i,exp (h i*spinValue (x i)) := by + simp only [weight,hamiltonian_scale,zero_mul,zero_add,Fields.linearObservable,exp_sum] + have hz : partition ((0:ℝ) • g) h = ∏ i,(exp (h i)+exp (-h i)) := by + simp only [partition,hw] + change (∑ x : Fin n → Bool, ∏ i,exp (h i*spinValue (x i))) = _ + rw [←Fintype.prod_sum (fun (i : Fin n) (b : Bool) => exp (h i*spinValue b))] + simp only [Fintype.sum_bool,spinValue_true,spinValue_false,mul_one,mul_neg_one] + apply Prior.ext + funext x + simp only [gibbsPrior,mass,hw,hz,productPrior,fieldPrior,Finset.prod_div_distrib] + +lemma history_endpoint_product (g : Disorder n) (hg : euclideanOpNorm (coupling g)≤2) + (h₀ : Fin n → ℝ) {N : ℕ} (hN : 0 fieldPrior (observedField g (N:ℝ)⁻¹ h₀ h i)) := by + rw [history_posterior_gibbs g hg, mul_inv_cancel₀ (Nat.cast_ne_zero.mpr hN.ne'), + sub_self,zero_scale_product] + +lemma history_endpoint_entropy (g : Disorder n) (hg : euclideanOpNorm (coupling g)≤2) + (h₀ : Fin n → ℝ) (f : Spin n → ℝ) (hf : ∀ x,0 f x*heatBathGenerator g h₀ (fun y => log (f y)) x) := by + let R := fun x => ∑ i,logRemainder (f x) (conditionalExpectation g h₀ i f x) + have hpoint (h : History n N) : + ent (History.posterior (gibbsFeature g) (gibbsPrior g h₀) (N:ℝ)⁻¹ h) f ≤ + avg (History.posterior (gibbsFeature g) (gibbsPrior g h₀) (N:ℝ)⁻¹ h) R := by + rw [history_endpoint_product g hg h₀ hN] + exact product_entropy_le_remainders _ f hf (fun i => conditionalExpectation g h₀ i f) + (fun i x => conditionalExpectation_pos g h₀ i f hf x) + (fun i x => conditionalExpectation_flip g h₀ i f x) + have hi := integral_mono + (History.integrable_posterior_entropy_weight (gibbsFeature g) (gibbsPrior g h₀) f hf (N:ℝ)⁻¹ N) + (History.integrable_posterior_avg_weight (gibbsFeature g) (gibbsPrior g h₀) (N:ℝ)⁻¹ R N) + (fun h => mul_le_mul_of_nonneg_left (hpoint h) (History.density_pos _ _ _ h).le) + rw [History.integral_posterior_avg_weight _ _ (inv_nonneg.mpr (Nat.cast_nonneg N))] at hi + exact hi.trans (remainders_le_energy g h₀ f hf) + +theorem entropy_of_scaled_covariance (g : Disorder n) (hg : euclideanOpNorm (coupling g)≤2) + {ρ : ℝ} (hρ : 0<ρ) + (hcov : ∀ s ∈ Set.Icc (0:ℝ) 1, ∀ h a : Fin n → ℝ, + Fields.variance (s • g) h (Fields.linearObservable a) ≤ ρ⁻¹*(∑ i,a i^2)) + (h₀ : Fin n → ℝ) (f : Spin n → ℝ) (hf : ∀ x,0 f x*heatBathGenerator g h₀ (fun y => log (f y)) x) := by + have he := History.entropy_of_observation_estimates + (E := expectation g h₀ (fun x => f x*heatBathGenerator g h₀ (fun y => log (f y)) x)) + (gibbsFeature g) (gibbsPrior g h₀) + (mass_pos g h₀) f hf (div_pos (by norm_num : (0:ℝ)<4) hρ) + have hvar (N : ℕ) (hN : 0 history_endpoint_entropy g hg h₀ f hf hN) + convert! hh using 1 + ring_nf + +theorem zero_field_mlsi (g : Disorder n) (hg : euclideanOpNorm (coupling g)≤2) + {ρ : ℝ} (hρ : 0<ρ) + (hcov : ∀ s ∈ Set.Icc (0:ℝ) 1, ∀ h a : Fin n → ℝ, + Fields.variance (s • g) h (Fields.linearObservable a) ≤ ρ⁻¹*(∑ i,a i^2)) + (f : Observables n) (hf : ∀ x,0 log (f y)) := by + have hh := entropy_of_scaled_covariance g hg hρ hcov 0 f hf + rw [←heatBathGenerator_adjoint] at hh + simpa only [heatBathGenerator_zero_field,expectation,neg_mul,Finset.sum_neg_distrib, + ent,gibbsPrior,stationaryInner,FiniteLaw.mean,mul_neg,Finset.sum_neg_distrib] using hh + +end SKRatio.Observation + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Entropy/LogPartition.lean b/lean/OAI/Probability/SKRatio/Entropy/LogPartition.lean new file mode 100644 index 0000000000000000000000000000000000000000..ca34fc3b8327fd32d58b3138a9c1c606c660873d --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Entropy/LogPartition.lean @@ -0,0 +1,305 @@ +import Mathlib +import OAI.Probability.SKRatio.Matrices.GaussianProductIntegral +import OAI.Probability.SKRatio.Entropy.Partition + +namespace OAI + +section +noncomputable section +open scoped BigOperators Topology ENNReal NNReal +open MeasureTheory ProbabilityTheory Real Filter +namespace SKRatio.Planted +open Calculus +attribute [local instance] Classical.propDecidable +variable {n : ℕ} + +def standardSample (β : ℝ) (n : ℕ) (z : Edge n → ℝ) : Disorder n := + fun e => sqrt (β^2/n)*z e + +lemma standardSample_continuous (β : ℝ) (n : ℕ) : Continuous (standardSample β n) := by + apply continuous_pi + intro e + exact (continuous_apply e).const_mul _ + +lemma standardSample_preserving (β : ℝ) (n : ℕ) : + MeasurePreserving (standardSample β n) (Measure.pi (fun _ : Edge n => gaussianReal 0 1)) + (disorderLaw β n) := by + refine ⟨(standardSample_continuous β n).measurable,?_⟩ + change Measure.map (fun (z : Edge n → ℝ) (e : Edge n) => sqrt (β^2/n)*z e) _ = _ + rw [Measure.pi_map_pi (fun _ => by fun_prop)] + unfold disorderLaw + congr 1 + funext e + rw [gaussianReal_map_const_mul] + congr 1 + · simp + · apply NNReal.coe_injective + simp only [NNReal.coe_mk,mul_one, + sq_sqrt (div_nonneg (sq_nonneg _) (Nat.cast_nonneg _)), + Real.coe_toNNReal _ (div_nonneg (sq_nonneg _) (Nat.cast_nonneg _))] + +lemma hamiltonian_difference_le (g h : Disorder n) (x : Spin n) : + |hamiltonian g 0 x-hamiltonian h 0 x| ≤ ∑ e,|g e-h e| := by + rw [hamiltonian_edges,hamiltonian_edges,←Finset.sum_sub_distrib] + calc + _ ≤ ∑ e,|spinValue (x e.1.1)*g e*spinValue (x e.1.2)- + spinValue (x e.1.1)*h e*spinValue (x e.1.2)| := Finset.abs_sum_le_sum_abs _ _ + _ = _ := by + apply Finset.sum_congr rfl + intro e _ + rw [←sub_mul,←mul_sub,abs_mul,abs_mul] + cases x e.1.1 <;> cases x e.1.2 <;> simp [spinValue] + +lemma log_partition_difference_le (g h : Disorder n) : + |log (partition g 0)-log (partition h 0)| ≤ ∑ e,|g e-h e| := by + have hh (g h : Disorder n) : log (partition g 0) ≤ (∑ e,|g e-h e|)+log (partition h 0) := by + have hp : partition g 0 ≤ exp (∑ e,|g e-h e|)*partition h 0 := by + unfold partition weight + rw [Finset.mul_sum] + apply Finset.sum_le_sum + intro x _ + rw [←exp_add] + apply exp_le_exp.mpr + have ht := (le_abs_self _).trans (hamiltonian_difference_le g h x) + linarith + have ht := log_le_log (partition_pos _ _) hp + rw [log_mul (exp_ne_zero _) (partition_pos _ _).ne',log_exp] at ht + exact ht + have hgh := hh g h + have hhg := hh h g + simp_rw [abs_sub_comm (h _) (g _)] at hhg + exact abs_le.mpr ⟨by linarith,by linarith⟩ + +lemma edge_card_bound (n : ℕ) : (Fintype.card (Edge n):ℝ) ≤ (n:ℝ)^2 := by + have h := Fintype.card_subtype_le (fun p : Fin n × Fin n => p.1 < p.2) + simp only [Fintype.card_prod,Fintype.card_fin] at h + exact_mod_cast (show Fintype.card (Edge n) ≤ n^2 from by simpa only [pow_two] using h) + +lemma standard_lipschitz_bound (β : ℝ) (n : ℕ) : + sqrt (β^2/n)*sqrt (Fintype.card (Edge n)) ≤ (|β|+1)*sqrt ((n:ℝ)+1) := by + by_cases hn : n=0 + · subst n + simpa using (by positivity : (0:ℝ) ≤ |β|+1) + have hnR : 0 < (n:ℝ) := Nat.cast_pos.mpr (Nat.pos_of_ne_zero hn) + have ha : 0 ≤ sqrt (β^2/n)*sqrt (Fintype.card (Edge n)) := by positivity + have hb : 0 ≤ (|β|+1)*sqrt ((n:ℝ)+1) := by positivity + apply (sq_le_sq₀ ha hb).mp + rw [mul_pow,mul_pow,sq_sqrt (div_nonneg (sq_nonneg _) hnR.le),sq_sqrt (Nat.cast_nonneg _), + sq_sqrt (by positivity : (0:ℝ) ≤ (n:ℝ)+1)] + have h := mul_le_mul_of_nonneg_left (edge_card_bound n) + (div_nonneg (sq_nonneg β) hnR.le) + have he : β^2/(n:ℝ)*(n:ℝ)^2 = β^2*n := by field_simp + rw [he] at h + nlinarith [sq_abs β,abs_nonneg β,show (0:ℝ) ≤ n from hnR.le, + mul_nonneg (abs_nonneg β) hnR.le] + +lemma log_partition_standard_lipschitz (β : ℝ) (n : ℕ) : + LipschitzWith ⟨(|β|+1)*sqrt ((n:ℝ)+1),by positivity⟩ + (fun z : EuclideanSpace ℝ (Edge n) => log (partition (standardSample β n z.ofLp) 0)) := by + apply LipschitzWith.of_dist_le_mul + intro z y + rw [Real.dist_eq] + calc + _ ≤ ∑ e, |standardSample β n z.ofLp e-standardSample β n y.ofLp e| := + log_partition_difference_le _ _ + _ = sqrt (β^2/n) * ∑ e, |z e-y e| := by + simp only [standardSample,←mul_sub,abs_mul,abs_of_nonneg (sqrt_nonneg _),Finset.mul_sum] + _ ≤ sqrt (β^2/n) * (sqrt (Fintype.card (Edge n))*dist z y) := by + apply mul_le_mul_of_nonneg_left _ (sqrt_nonneg _) + have hs := Real.sum_mul_le_sqrt_mul_sqrt Finset.univ (fun _ : Edge n => (1:ℝ)) + (fun e => |z e-y e|) + simpa only [one_mul,one_pow,Finset.sum_const,Finset.card_univ,nsmul_eq_mul,mul_one, + sq_abs,EuclideanSpace.dist_eq,Real.dist_eq] using hs + _ ≤ ((|β|+1)*sqrt ((n:ℝ)+1))*dist z y := by + rw [←mul_assoc] + exact mul_le_mul_of_nonneg_right (standard_lipschitz_bound β n) dist_nonneg + +lemma log_partition_integrable (β : ℝ) (n : ℕ) : + Integrable (fun g : Disorder n => log (partition g 0)) (disorderLaw β n) := by + have hi := SKRatioGaussian.gaussianProduct_integrable_lipschitz (log_partition_standard_lipschitz β n) + have hp := standardSample_preserving β n + exact (hp.integrable_comp (by + exact ((continuous_partition 0).log (fun g => (partition_pos g 0).ne')).aestronglyMeasurable)).mp hi + +lemma log_partition_centered_L1 (β : ℝ) (n : ℕ) : + (∫ g : Disorder n, |log (partition g 0)- + ∫ h : Disorder n, log (partition h 0) ∂disorderLaw β n| ∂disorderLaw β n) ≤ + (2*exp (π^2/8))*(|β|+1)*sqrt ((n:ℝ)+1) := by + have hp := standardSample_preserving β n + have hh := SKRatioGaussian.gaussianProduct_centered_L1 (log_partition_standard_lipschitz β n) + (show (0:ℝ≥0) < ⟨(|β|+1)*sqrt ((n:ℝ)+1),by positivity⟩ from by + change (0:ℝ)<(|β|+1)*sqrt ((n:ℝ)+1); positivity) + have hl : Continuous (fun g : Disorder n => log (partition g 0)) := + (continuous_partition 0).log (fun g => (partition_pos g 0).ne') + have he := (integral_map (μ := Measure.pi (fun _ : Edge n => gaussianReal 0 1)) hp.measurable.aemeasurable hl.aestronglyMeasurable).symm + rw [hp.map_eq] at he + change (∫ g : Disorder n, log (partition (standardSample β n g) 0) + ∂Measure.pi (fun _ => gaussianReal 0 1)) = _ at he + change (∫ g : Disorder n, |log (partition (standardSample β n g) 0)- + ∫ h : Disorder n, log (partition (standardSample β n h) 0) ∂Measure.pi (fun _ => gaussianReal 0 1)| + ∂Measure.pi (fun _ => gaussianReal 0 1)) ≤ _ at hh + rw [he] at hh + have he' := (integral_map (μ := Measure.pi (fun _ : Edge n => gaussianReal 0 1)) hp.measurable.aemeasurable + ((hl.sub (continuous_const (y := ∫ h : Disorder n,log (partition h 0) ∂disorderLaw β n))).abs.aestronglyMeasurable)).symm + rw [hp.map_eq] at he' + simp only [Pi.sub_apply] at he' + rw [he'] at hh + change _ ≤ (2*exp (π^2/8))*((|β|+1)*sqrt ((n:ℝ)+1)) at hh + simpa only [mul_assoc] using hh + +lemma log_partition_mean_upper (β : ℝ) (n : ℕ) : + (∫ g : Disorder n, log (partition g 0) ∂disorderLaw β n) ≤ + log ((2:ℝ)^n*exp (normalizingExponent β n)) := by + let M := (2:ℝ)^n*exp (normalizingExponent β n) + have hM : 0 < M := by dsimp [M]; positivity + have hi := integral_mono (log_partition_integrable β n) + (((integrable_const (log M)).add ((partition_integrable β n).div_const M)).sub (integrable_const 1)) + (fun g => show log (partition g 0) ≤ log M+partition g 0/M-1 from by + have hh := log_le_sub_one_of_pos (div_pos (partition_pos g 0) hM) + rw [log_div (partition_pos _ _).ne' hM.ne'] at hh + linarith) + simp only [Pi.sub_apply,Pi.add_apply] at hi + rw [integral_sub (f := fun g => log M+partition g 0/M) + ((integrable_const _).add ((partition_integrable β n).div_const _)) (integrable_const _), + integral_add (integrable_const _) ((partition_integrable β n).div_const _), + integral_const,integral_const,probReal_univ,one_smul,integral_div,integral_partition] at hi + change _ ≤ log M at ⊢ + simp only [smul_eq_mul,one_mul] at hi + change _ ≤ log M+M/M-1 at hi + simpa only [div_self hM.ne',add_sub_cancel_right] using hi + +lemma log_partition_mean_lower {β : ℝ} (hβ : β^2 ≤ 1/2) (n : ℕ) : + log ((2:ℝ)^n*exp (normalizingExponent β n))-log 2- + 8*((2*exp (π^2/8))*(|β|+1)*sqrt ((n:ℝ)+1)) ≤ + ∫ g : Disorder n, log (partition g 0) ∂disorderLaw β n := by + let M := (2:ℝ)^n*exp (normalizingExponent β n) + let m := ∫ g : Disorder n,log (partition g 0) ∂disorderLaw β n + let L := (2*exp (π^2/8))*(|β|+1)*sqrt ((n:ℝ)+1) + have hM : 0 < M := by dsimp [M]; positivity + have hL : 0 ≤ L := by dsimp [L]; positivity + have he : {g : Disorder n | M/2 ≤ partition g 0} = + {g : Disorder n | log M-log 2 ≤ log (partition g 0)} := by + ext g + rw [←log_div hM.ne' (by norm_num)] + exact (log_le_log_iff (by positivity) (partition_pos g 0)).symm + have hprob := partition_lower_positive_probability hβ n + change (1/8:ℝ) ≤ (disorderLaw β n).real {g | M/2 ≤ partition g 0} at hprob + rw [he] at hprob + change log M-log 2-8*L ≤ m + by_cases ha : log M-log 2 ≤ m + · linarith + have hc : 0 < log M-log 2-m := by linarith + have hi : Integrable (fun g : Disorder n => |log (partition g 0)-m|) (disorderLaw β n) := + ((log_partition_integrable β n).sub (integrable_const m)).abs + have hs := mul_meas_ge_le_integral_of_nonneg + (μ := disorderLaw β n) (f := fun g => |log (partition g 0)-m|) + (Eventually.of_forall (fun g => abs_nonneg _)) hi (log M-log 2-m) + have hsub : {g : Disorder n | log M-log 2 ≤ log (partition g 0)} ⊆ + {g : Disorder n | log M-log 2-m ≤ |log (partition g 0)-m|} := by + intro g hg + exact (sub_le_sub_right hg m).trans (le_abs_self _) + have hp := hprob.trans (measureReal_mono (μ := disorderLaw β n) hsub) + have hmul := mul_le_mul_of_nonneg_left hp hc.le + have hb := log_partition_centered_L1 β n + change (∫ g,|log (partition g 0)-m| ∂disorderLaw β n) ≤ L at hb + linarith + +lemma log_partition_annealed_L1 {β : ℝ} (hβ : β^2 ≤ 1/2) (n : ℕ) : + (∫ g : Disorder n, |log (partition g 0)- + log ((2:ℝ)^n*exp (normalizingExponent β n))| ∂disorderLaw β n) ≤ + 9*((2*exp (π^2/8))*(|β|+1)*sqrt ((n:ℝ)+1))+log 2 := by + let a := log ((2:ℝ)^n*exp (normalizingExponent β n)) + let m := ∫ g : Disorder n,log (partition g 0) ∂disorderLaw β n + let L := (2*exp (π^2/8))*(|β|+1)*sqrt ((n:ℝ)+1) + have hu : m ≤ a := log_partition_mean_upper β n + have hl : a-log 2-8*L ≤ m := log_partition_mean_lower hβ n + have hi : Integrable (fun g : Disorder n => |log (partition g 0)-m|) (disorderLaw β n) := + ((log_partition_integrable β n).sub (integrable_const m)).abs + have hineq := integral_mono + (((log_partition_integrable β n).sub (integrable_const a)).abs) + (hi.add (integrable_const (a-m))) (fun g => show + |log (partition g 0)-a| ≤ |log (partition g 0)-m|+(a-m) from by + have hh := abs_sub_le (log (partition g 0)) m a + rw [abs_of_nonpos (sub_nonpos.mpr hu)] at hh + linarith) + simp only [Pi.add_apply,Pi.sub_apply] at hineq + rw [integral_add hi (integrable_const _),integral_const,probReal_univ,one_smul] at hineq + have hb : (∫ g,|log (partition g 0)-m| ∂disorderLaw β n) ≤ L := log_partition_centered_L1 β n + change (∫ g : Disorder n, |log (partition g 0)-a| ∂disorderLaw β n) ≤ 9*L+log 2 + linarith + +lemma partition_lower_probability {β κ : ℝ} (hβ : β^2 ≤ 1/2) (hκ : 0 < κ) + {n : ℕ} (hn : 0 < n) : + disorderLaw β n {g : Disorder n | partition g 0 < + ((2:ℝ)^n*exp (normalizingExponent β n))*exp (-κ*n)} ≤ + ENNReal.ofReal ((9*((2*exp (π^2/8))*(|β|+1)*sqrt ((n:ℝ)+1))+log 2)/(κ*n)) := by + let M := (2:ℝ)^n*exp (normalizingExponent β n) + have hM : 0 < M := by dsimp [M]; positivity + let U := 9*((2*exp (π^2/8))*(|β|+1)*sqrt ((n:ℝ)+1))+log 2 + let f : Disorder n → ℝ := fun g => |log (partition g 0)-log M| + have hnR : 0 < (n:ℝ) := Nat.cast_pos.mpr hn + have hkn : 0 < κ*n := mul_pos hκ hnR + have hi : Integrable f (disorderLaw β n) := + ((log_partition_integrable β n).sub (integrable_const (log M))).abs + have hs := mul_meas_ge_le_integral_of_nonneg (μ := disorderLaw β n) + (f := f) (Eventually.of_forall (fun g => abs_nonneg _)) hi (κ*n) + have hsub : {g : Disorder n | partition g 0 < M*exp (-κ*n)} ⊆ + {g : Disorder n | κ*n ≤ f g} := by + intro g hg + have hh := log_lt_log (partition_pos g 0) hg + rw [log_mul hM.ne' (exp_ne_zero _),log_exp] at hh + dsimp [f] + have ht := neg_le_abs (log (partition g 0)-log M) + linarith + have hh := mul_le_mul_of_nonneg_left (measureReal_mono (μ := disorderLaw β n) hsub) hkn.le + have hb := log_partition_annealed_L1 hβ n + change (∫ g,f g ∂disorderLaw β n) ≤ U at hb + have hreal : (disorderLaw β n).real {g : Disorder n | partition g 0 < M*exp (-κ*n)} ≤ + U/(κ*n) := by + apply (le_div_iff₀ hkn).mpr + rw [mul_comm] + exact hh.trans (hs.trans hb) + rw [←ENNReal.ofReal_toReal (measure_ne_top _ _)] + exact ENNReal.ofReal_le_ofReal hreal + +lemma sqrt_nat_add_div_tendsto : + Tendsto (fun n : ℕ => sqrt ((n:ℝ)+1)/(n:ℝ)) atTop (𝓝 0) := by + have hi : Tendsto (fun n : ℕ => (n:ℝ)⁻¹) atTop (𝓝 0) := + tendsto_inv_atTop_zero.comp tendsto_natCast_atTop_atTop + have hs := (hi.add (hi.pow 2)).sqrt + have he : ∀ᶠ n : ℕ in atTop, + sqrt ((n:ℝ)+1)/(n:ℝ) = sqrt ((n:ℝ)⁻¹+((n:ℝ)⁻¹)^2) := by + filter_upwards [eventually_ge_atTop 1] with n hn + have hnR : 0 < (n:ℝ) := Nat.cast_pos.mpr (by omega) + rw [show (n:ℝ)⁻¹+((n:ℝ)⁻¹)^2 = ((n:ℝ)+1)/(n:ℝ)^2 by field_simp, + sqrt_div (by positivity),sqrt_sq hnR.le] + simpa only [zero_pow (by norm_num : (2:ℕ)≠0),zero_add,sqrt_zero] using + hs.congr' (he.mono (fun _ h => h.symm)) + +lemma partition_lower_high_probability {β κ : ℝ} (hβ : β^2 ≤ 1/2) (hκ : 0 < κ) : + Tendsto (fun n : ℕ => disorderLaw β n {g : Disorder n | partition g 0 < + ((2:ℝ)^n*exp (normalizingExponent β n))*exp (-κ*n)}) atTop (𝓝 0) := by + let C := 9*((2*exp (π^2/8))*(|β|+1)) + have hi : Tendsto (fun n : ℕ => (n:ℝ)⁻¹) atTop (𝓝 0) := + tendsto_inv_atTop_zero.comp tendsto_natCast_atTop_atTop + have hreal : Tendsto (fun n : ℕ => + (9*((2*exp (π^2/8))*(|β|+1)*sqrt ((n:ℝ)+1))+log 2)/(κ*n)) atTop (𝓝 0) := by + have ht := (sqrt_nat_add_div_tendsto.const_mul (C/κ)).add (hi.const_mul (log 2/κ)) + have he (n : ℕ) : (C/κ)*(sqrt ((n:ℝ)+1)/(n:ℝ))+(log 2/κ)*(n:ℝ)⁻¹ = + (9*((2*exp (π^2/8))*(|β|+1)*sqrt ((n:ℝ)+1))+log 2)/(κ*n) := by + dsimp [C] + ring + simpa only [he,mul_zero,add_zero] using ht + have he := ENNReal.continuous_ofReal.continuousAt.tendsto.comp hreal + simp only [Function.comp_def,ENNReal.ofReal_zero] at he + apply tendsto_of_tendsto_of_tendsto_of_le_of_le' tendsto_const_nhds he + (Eventually.of_forall (fun _ => bot_le)) + filter_upwards [eventually_ge_atTop 1] with n hn + exact partition_lower_probability hβ hκ (by omega) + +end SKRatio.Planted + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Entropy/Partition.lean b/lean/OAI/Probability/SKRatio/Entropy/Partition.lean new file mode 100644 index 0000000000000000000000000000000000000000..442d7bccd9fb8a418574cd333d836a649edb74a9 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Entropy/Partition.lean @@ -0,0 +1,232 @@ +import Mathlib +import OAI.Probability.SKRatio.FiniteChain.DiscreteDistanceNonneg +import OAI.Probability.SKRatio.Matrices.GaussianTails +import OAI.Probability.SKRatio.Gaussian.Planted + +namespace OAI + +section +noncomputable section +open scoped BigOperators Topology ENNReal NNReal +open MeasureTheory ProbabilityTheory Real Filter +namespace SKRatio.Planted +open Calculus +attribute [local instance] Classical.propDecidable +variable {n : ℕ} + +lemma sum_edges_spin (x : Spin n) : + 2*∑ e : Edge n, spin x e.1.1*spin x e.1.2 = (∑ i,spin x i)^2-n := by + have h (i j : Fin n) : spin x i*coupling (fun _ : Edge n => 1) i j*spin x j = + spin x i*spin x j - if i=j then 1 else 0 := by + by_cases hij : i=j + · subst j + simp only [coupling_diag,mul_zero,zero_mul,↓reduceIte] + nlinarith [spin_sq x i] + · simp only [coupling] + split_ifs <;> simp_all only [mul_one,sub_zero] + omega + have hs := hamiltonian_edges (fun _ : Edge n => 1) x + have hss : (∑ i,spin x i)^2 = ∑ i : Fin n, ∑ j : Fin n, spin x i*spin x j := by + rw [pow_two,Finset.sum_mul_sum] + simp only [hamiltonian,Pi.zero_apply,zero_mul,Finset.sum_const_zero,add_zero] at hs + change (1/2:ℝ)*(∑ i,∑ j,spin x i*coupling (fun _ : Edge n => 1) i j*spin x j) = + ∑ e : Edge n,spin x e.1.1*1*spin x e.1.2 at hs + simp only [h,Finset.sum_sub_distrib,Finset.sum_ite_eq,Finset.mem_univ,↓reduceIte, + Finset.sum_const,Finset.card_univ,Fintype.card_fin,nsmul_eq_mul,mul_one] at hs + rw [hss] + linarith + +lemma weight_pair_linear (g : Disorder n) (x y : Spin n) : + weight g 0 x*weight g 0 y = exp (∑ e : Edge n, + (spin x e.1.1*spin x e.1.2+spin y e.1.1*spin y e.1.2)*g e) := by + rw [weight_linear,weight_linear,←exp_add,←Finset.sum_add_distrib] + congr 1 + apply Finset.sum_congr rfl + intro e _ + change _ = (spinValue (x e.1.1)*spinValue (x e.1.2)+ + spinValue (y e.1.1)*spinValue (y e.1.2))*g e + ring + +lemma weight_pair_integrable (β : ℝ) (x y : Spin n) : + Integrable (fun g => weight g 0 x*weight g 0 y) (disorderLaw β n) := by + simp_rw [weight_pair_linear] + exact integrable_exp_linear _ _ _ + +lemma integral_weight_pair (β : ℝ) (x y : Spin n) : + (∫ g, weight g 0 x*weight g 0 y ∂disorderLaw β n) = + exp (2*normalizingExponent β n + (β^2/n)* + ∑ e : Edge n, spin (signProduct x y) e.1.1*spin (signProduct x y) e.1.2) := by + simp_rw [weight_pair_linear] + rw [disorderLaw,integral_exp_linear] + congr 1 + have hv : (Real.toNNReal (β^2/(n:ℝ)) : ℝ) = β^2/n := + Real.coe_toNNReal _ (div_nonneg (sq_nonneg _) (Nat.cast_nonneg _)) + have he (e : Edge n) : (spin x e.1.1*spin x e.1.2+spin y e.1.1*spin y e.1.2)^2 = + 2+2*(spin (signProduct x y) e.1.1*spin (signProduct x y) e.1.2) := by + rw [add_sq,mul_pow,mul_pow,spin_sq,spin_sq,spin_sq,spin_sq,spin_signProduct,spin_signProduct] + ring + simp only [mul_zero,zero_add,hv,he, + show ∀ a b : ℝ, a*(2+2*b)/2 = a+a*b from by intros; ring, + Finset.sum_add_distrib,Finset.sum_const,Finset.card_univ,nsmul_eq_mul,←Finset.mul_sum, + normalizingExponent] + ring + +lemma partition_square_integrable (β : ℝ) (n : ℕ) : + Integrable (fun g : Disorder n => (partition g 0)^2) (disorderLaw β n) := by + have he (g : Disorder n) : partition g 0^2 = + ∑ x : Spin n, ∑ y : Spin n,weight g 0 x*weight g 0 y := by + rw [pow_two,partition,Finset.sum_mul_sum] + simp_rw [he] + exact integrable_finsetSum _ (fun x _ => integrable_finsetSum _ (fun y _ => weight_pair_integrable β x y)) + +lemma sign_sum_exp (t : ℝ) (n : ℕ) : + (∑ x : Spin n, exp (t*∑ i,spin x i)) = (2*cosh t)^n := by + simp_rw [Finset.mul_sum,exp_sum] + have he : (∑ x : Spin n, ∏ i, exp (t*spin x i)) = + ∏ _i : Fin n, ∑ b : Bool, exp (t*spinValue b) := by + simpa only [spin,spinValue] using + (Fintype.prod_sum (fun (_ : Fin n) (b : Bool) => exp (t*spinValue b))).symm + rw [he] + have hB : (∑ b : Bool, exp (t*spinValue b)) = 2*cosh t := by + simp [spinValue,cosh_eq] + ring + simp only [hB,Finset.prod_const,Finset.card_univ,Fintype.card_fin] + +lemma sign_square_exp_bound {β : ℝ} (hβ : β^2 ≤ 1/2) (n : ℕ) : + (∑ x : Spin n, exp ((β^2/(2*n))*(∑ i,spin x i)^2)) ≤ 2*(2:ℝ)^n := by + by_cases hn : n=0 + · subst n + norm_num [Spin] + have hnR : 0 < (n:ℝ) := Nat.cast_pos.mpr (Nat.pos_of_ne_zero hn) + let a := β/sqrt n + have ha : a^2 = β^2/n := by + dsimp [a] + rw [div_pow,sq_sqrt hnR.le] + have he (x : Spin n) : exp ((β^2/(2*n))*(∑ i,spin x i)^2) = + ∫ z : ℝ, exp ((a*∑ i,spin x i)*z) ∂gaussianReal 0 1 := by + have hm := mgf_gaussianReal (μ := 0) (v := 1) (X := id) (p := gaussianReal 0 1) + (by simp) (a*∑ i,spin x i) + simp only [mgf,id_eq,NNReal.coe_one,one_mul] at hm + rw [hm,mul_pow,ha] + congr 1 + ring + simp_rw [he] + rw [←integral_finsetSum _ (fun x _ => integrable_exp_mul_gaussianReal (a*∑ i,spin x i))] + have he' (z : ℝ) : (∑ x : Spin n, exp ((a*∑ i,spin x i)*z)) = (2*cosh (a*z))^n := by + have hh (x : Spin n) : (a*∑ i,spin x i)*z = (a*z)*∑ i,spin x i := by ring + simp_rw [hh] + exact sign_sum_exp _ _ + simp_rw [he'] + have hb (z : ℝ) : (2*cosh (a*z))^n ≤ (2:ℝ)^n*exp (z^2/4) := by + rw [mul_pow] + apply mul_le_mul_of_nonneg_left _ (by positivity) + calc + cosh (a*z)^n ≤ exp ((a*z)^2/2)^n := pow_le_pow_left₀ (cosh_pos _).le (cosh_le_exp_half_sq _) n + _ = exp (β^2*z^2/2) := by + rw [←exp_nat_mul,mul_pow,ha] + congr 1 + field_simp + _ ≤ exp (z^2/4) := exp_le_exp.mpr (by nlinarith [mul_le_mul_of_nonneg_right hβ (sq_nonneg z)]) + have hi : Integrable (fun z : ℝ => (2*cosh (a*z))^n) (gaussianReal 0 1) := by + have hh := integrable_finsetSum Finset.univ + (fun (x : Spin n) _ => integrable_exp_mul_gaussianReal (μ := 0) (v := 1) (a*∑ i,spin x i)) + simpa only [he'] using hh + calc + _ ≤ ∫ z : ℝ, (2:ℝ)^n*exp (z^2/4) ∂gaussianReal 0 1 := + integral_mono hi (SKRatioGaussian.gaussian_square_exp_integrable.const_mul _) hb + _ ≤ (2:ℝ)^n*2 := by + rw [integral_const_mul] + exact mul_le_mul_of_nonneg_left SKRatioGaussian.gaussian_square_exp_integral (by positivity) + _ = _ := mul_comm _ _ + +lemma partition_second_moment {β : ℝ} (hβ : β^2 ≤ 1/2) (n : ℕ) : + (∫ g : Disorder n, (partition g 0)^2 ∂disorderLaw β n) ≤ + 2*((2:ℝ)^n*exp (normalizingExponent β n))^2 := by + have he (g : Disorder n) : partition g 0^2 = + ∑ x : Spin n, ∑ y : Spin n,weight g 0 x*weight g 0 y := by + rw [pow_two,partition,Finset.sum_mul_sum] + simp_rw [he] + rw [integral_finsetSum _ (fun x _ => integrable_finsetSum _ (fun y _ => weight_pair_integrable β x y))] + simp_rw [integral_finsetSum _ (fun y _ => weight_pair_integrable β _ y),integral_weight_pair] + let f : Spin n → ℝ := fun z => exp (2*normalizingExponent β n +(β^2/n)* + ∑ e : Edge n,spin z e.1.1*spin z e.1.2) + have heq (x : Spin n) : (∑ y : Spin n,f (signProduct x y)) = ∑ z : Spin n,f z := + Equiv.sum_comp ((signProduct_involutive x).toPerm) f + change (∑ x : Spin n, ∑ y : Spin n,f (signProduct x y)) ≤ _ + simp only [heq,Finset.sum_const,Finset.card_univ,nsmul_eq_mul, + Fintype.card_fun,Fintype.card_bool,Fintype.card_fin,Nat.cast_pow,Nat.cast_ofNat] + have hb (z : Spin n) : f z ≤ exp (2*normalizingExponent β n)* + exp ((β^2/(2*n))*(∑ i,spin z i)^2) := by + dsimp [f] + rw [←exp_add] + apply exp_le_exp.mpr + have hv := div_nonneg (sq_nonneg β) (Nat.cast_nonneg n : (0:ℝ) ≤ n) + have hsum := sum_edges_spin z + have hle : ∑ e : Edge n,spin z e.1.1*spin z e.1.2 ≤ (∑ i,spin z i)^2/2 := by + linarith [show (0:ℝ) ≤ n from Nat.cast_nonneg n] + have hh := mul_le_mul_of_nonneg_left hle hv + have hid : (β^2/n)*((∑ i,spin z i)^2/2) = (β^2/(2*n))*(∑ i,spin z i)^2 := by ring + rw [hid] at hh + linarith + calc + _ ≤ (2:ℝ)^n * (exp (2*normalizingExponent β n)* + ∑ z : Spin n, exp ((β^2/(2*n))*(∑ i,spin z i)^2)) := by + apply mul_le_mul_of_nonneg_left _ (by positivity) + rw [Finset.mul_sum] + exact Finset.sum_le_sum (fun z _ => hb z) + _ ≤ (2:ℝ)^n*(exp (2*normalizingExponent β n)*(2*(2:ℝ)^n)) := + mul_le_mul_of_nonneg_left (mul_le_mul_of_nonneg_left (sign_square_exp_bound hβ n) + (exp_pos _).le) (by positivity) + _ = _ := by + rw [show (2:ℝ)*normalizingExponent β n = normalizingExponent β n+normalizingExponent β n by ring, + exp_add] + ring + +lemma partition_lower_positive_probability {β : ℝ} (hβ : β^2 ≤ 1/2) (n : ℕ) : + (1/8:ℝ) ≤ (disorderLaw β n).real + {g : Disorder n | ((2:ℝ)^n*exp (normalizingExponent β n))/2 ≤ partition g 0} := by + let M := (2:ℝ)^n*exp (normalizingExponent β n) + have hM : 0 < M := by dsimp [M]; positivity + let A := {g : Disorder n | M/2 ≤ partition g 0} + have hA : MeasurableSet A := measurableSet_le measurable_const (continuous_partition 0).measurable + let I : Disorder n → ℝ := A.indicator 1 + have hI : Integrable I (disorderLaw β n) := (integrable_const (1:ℝ)).indicator hA + have hi : (∫ g, I g ∂disorderLaw β n) = (disorderLaw β n).real A := integral_indicator_one hA + have hp (g : Disorder n) : partition g 0 ≤ M/2+(partition g 0)^2/(8*M)+2*M*I g := by + by_cases hg : g ∈ A + · have he : I g=1 := Set.indicator_of_mem hg 1 + rw [he,mul_one] + have hsq := sq_nonneg (partition g 0-4*M) + have hb : partition g 0-2*M ≤ partition g 0^2/(8*M) := by + apply (le_div_iff₀ (show 0 < 8*M by positivity)).mpr + nlinarith only [hsq] + linarith only [hb,hM] + · have he : I g=0 := Set.indicator_of_notMem hg 1 + rw [he,mul_zero,add_zero] + have hz : partition g 0 < M/2 := lt_of_not_ge hg + exact hz.le.trans (le_add_of_nonneg_right (div_nonneg (sq_nonneg _) (by positivity))) + have hineq := integral_mono (partition_integrable β n) + (((integrable_const (M/2)).add ((partition_square_integrable β n).div_const (8*M))).add + (hI.const_mul (2*M))) hp + simp only [Pi.add_apply] at hineq + have hsum : Integrable (fun g : Disorder n => M/2+partition g 0^2/(8*M)) + (disorderLaw β n) := (integrable_const _).add ((partition_square_integrable β n).div_const _) + rw [integral_add hsum (hI.const_mul (2*M)), + integral_add (integrable_const (M/2)) ((partition_square_integrable β n).div_const (8*M)), + integral_const,probReal_univ,smul_eq_mul,one_mul,integral_div,integral_const_mul,hi, + integral_partition] at hineq + have hs := partition_second_moment hβ n + change _ ≤ 2*M^2 at hs + change M ≤ M/2+_+2*M*(disorderLaw β n).real A at hineq + have hdiv : (∫ g : Disorder n, partition g 0^2 ∂disorderLaw β n)/(8*M) ≤ M/4 := by + apply (div_le_iff₀ (show 0 < 8*M by positivity)).mpr + nlinarith only [hs] + change (1/8:ℝ) ≤ (disorderLaw β n).real A + nlinarith only [hineq,hdiv,hM] + +end SKRatio.Planted + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Entropy/ProductEntropy.lean b/lean/OAI/Probability/SKRatio/Entropy/ProductEntropy.lean new file mode 100644 index 0000000000000000000000000000000000000000..0401664972c95435da915e0a36048e2af25d3450 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Entropy/ProductEntropy.lean @@ -0,0 +1,240 @@ +import Mathlib +import OAI.Probability.SKRatio.Entropy.FiniteEntropy + +namespace OAI + +section +noncomputable section +open scoped BigOperators +open Real +namespace SKRatio.Observation +attribute [local instance] Classical.propDecidable + +variable {n : ℕ} + +def productPrior (q : Fin n → Prior Bool) : Prior (Spin n) where + mass x := ∏ i, q i (x i) + nonneg x := Finset.prod_nonneg (fun i _ => (q i).nonneg (x i)) + sum_one := by + rw [← Fintype.prod_sum] + simp only [Prior.sum_one,Finset.prod_const_one] + +lemma productPrior_pos (q : Fin n → Prior Bool) (hq : ∀ i b,0 hq i (x i)) + +lemma sum_cons (F : Spin (n+1) → ℝ) : + ∑ x, F x = ∑ b : Bool, ∑ y : Spin n, F (Fin.cons b y) := by + rw [← Equiv.sum_comp (Fin.consEquiv (fun _ : Fin (n+1) => Bool)),Fintype.sum_prod_type] + rfl + +lemma avg_product_succ (q : Fin (n+1) → Prior Bool) (f : Spin (n+1) → ℝ) : + avg (productPrior q) f = avg (q 0) (fun b => + avg (productPrior (fun i => q i.succ)) (fun y => f (Fin.cons b y))) := by + unfold avg FiniteLaw.mean + rw [sum_cons] + simp only [productPrior,Fin.prod_univ_succ,Fin.cons_zero,Fin.cons_succ,Finset.mul_sum,mul_assoc] + +lemma avg_swap {α β : Type*} [Fintype α] [Fintype β] (p : Prior α) (q : Prior β) + (F : α → β → ℝ) : + avg p (fun a => avg q (F a)) = avg q (fun b => avg p (fun a => F a b)) := by + simp only [avg,FiniteLaw.mean,Finset.mul_sum] + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro b _ + apply Finset.sum_congr rfl + intro a _ + ring + +lemma entropy_product_chain (q : Fin (n+1) → Prior Bool) (f : Spin (n+1) → ℝ) : + ent (productPrior q) f = + avg (q 0) (fun b => ent (productPrior (fun i => q i.succ)) (fun y => f (Fin.cons b y))) + + ent (q 0) (fun b => avg (productPrior (fun i => q i.succ)) (fun y => f (Fin.cons b y))) := by + change avg (productPrior q) (fun x => f x*log (f x))- + avg (productPrior q) f*log (avg (productPrior q) f) = _ + rw [avg_product_succ,avg_product_succ] + change _ = avg (q 0) (fun b => + avg (productPrior (fun i => q i.succ)) (fun y => f (Fin.cons b y)*log (f (Fin.cons b y)))- + avg (productPrior (fun i => q i.succ)) (fun y => f (Fin.cons b y))* + log (avg (productPrior (fun i => q i.succ)) (fun y => f (Fin.cons b y)))) + _ + rw [avg_sub] + unfold ent FiniteLaw.entropy + change _ = _ + (avg (q 0) (fun b => + avg (productPrior (fun i => q i.succ)) (fun y => f (Fin.cons b y))* + log (avg (productPrior (fun i => q i.succ)) (fun y => f (Fin.cons b y)))) - _) + unfold avg + ring + +lemma update_cons_succ (b : Bool) (y : Spin n) (i : Fin n) (z : Bool) : + Function.update (Fin.cons b y : Spin (n+1)) i.succ z = + (Fin.cons b (Function.update y i z) : Spin (n+1)) := by + funext j + refine Fin.cases ?_ (fun k => ?_) j + · simp [Function.update_of_ne (Fin.succ_ne_zero i).symm] + · by_cases hk : k=i + · subst k;simp + · simp [hk] + +def productSiteEntropy (q : Fin n → Prior Bool) (f : Spin n → ℝ) (i : Fin n) : ℝ := + avg (productPrior q) (fun x => ent (q i) (fun b => f (Function.update x i b))) + +lemma productSiteEntropy_zero (q : Fin (n+1) → Prior Bool) (f : Spin (n+1) → ℝ) : + productSiteEntropy q f 0 = + avg (productPrior (fun i => q i.succ)) (fun y => ent (q 0) (fun b => f (Fin.cons b y))) := by + unfold productSiteEntropy + rw [avg_product_succ] + simp only [Fin.update_cons_zero] + exact avg_const _ _ + +lemma productSiteEntropy_succ (q : Fin (n+1) → Prior Bool) (f : Spin (n+1) → ℝ) (i : Fin n) : + productSiteEntropy q f i.succ = avg (q 0) (fun b => + productSiteEntropy (fun j => q j.succ) (fun y => f (Fin.cons b y)) i) := by + unfold productSiteEntropy + rw [avg_product_succ] + simp only [update_cons_succ] + +theorem product_entropy_tensorization : ∀ (n : ℕ) (q : Fin n → Prior Bool) + (f : Spin n → ℝ), (∀ x,0 + intro q f hf + let x₀ : Spin 0 := fun i => Fin.elim0 i + have he : f = fun _ => f x₀ := funext (fun x => congrArg f (Subsingleton.elim x x₀)) + rw [he] + change avg (productPrior q) (fun _ => f x₀*log (f x₀))- + avg (productPrior q) (fun _ => f x₀)*log (avg (productPrior q) (fun _ => f x₀)) ≤ _ + simp only [avg_const,sub_self,Fin.sum_univ_zero,le_refl] + | succ n ih => + intro q f hf + rw [entropy_product_chain,Fin.sum_univ_succ,productSiteEntropy_zero] + simp_rw [productSiteEntropy_succ] + have h₁ := avg_mono (q 0) (fun b => ih (fun i => q i.succ) (fun y => f (Fin.cons b y)) + (fun y => hf _)) + rw [avg_sum] at h₁ + have h₂ := entropy_average_le (q 0) (productPrior (fun i => q i.succ)) + (fun y b => f (Fin.cons b y)) (fun y b => hf _) + linarith only [h₁,h₂] + +end SKRatio.Observation + +namespace SKRatio.Observation +attribute [local instance] Classical.propDecidable +variable {n : ℕ} + +lemma invariant_update (i : Fin n) (c : Spin n → ℝ) + (hc : ∀ x,c (flip i x)=c x) (x : Spin n) (b : Bool) : + c (Function.update x i b) = c x := by + by_cases hb : b=x i + · rw [hb,Function.update_eq_self] + · have hb' : b= !(x i) := by cases b <;> cases hx : x i <;> simp_all + rw [hb'] + exact hc x + +lemma avg_product_resample : ∀ (n : ℕ) (q : Fin n → Prior Bool) + (F : Spin n → ℝ) (i : Fin n), + avg (productPrior q) (fun x => avg (q i) (fun b => F (Function.update x i b))) = + avg (productPrior q) F := by + intro n + induction n with + | zero => intro q F i;exact Fin.elim0 i + | succ n ih => + intro q F i + refine Fin.cases ?_ (fun j => ?_) i + · rw [avg_product_succ,avg_product_succ] + simp only [Fin.update_cons_zero] + rw [avg_const,avg_swap] + · rw [avg_product_succ,avg_product_succ] + simp only [update_cons_succ] + congr 1 + funext b + exact ih (fun i => q i.succ) (fun y => F (Fin.cons b y)) j + +theorem product_entropy_le_remainders (q : Fin n → Prior Bool) + (f : Spin n → ℝ) (hf : ∀ x,0 ∑ i,logRemainder (f x) (c i x)) := by + rw [avg_sum] + apply (product_entropy_tensorization n q f hf).trans + apply Finset.sum_le_sum + intro i _ + have hh : productSiteEntropy q f i ≤ avg (productPrior q) (fun x => + avg (q i) (fun b => logRemainder (f (Function.update x i b)) (c i x))) := + avg_mono _ (fun x => ent_minimizes (q i) _ (fun b => hf _) (hc i x)) + have he : (fun x => avg (q i) (fun b => logRemainder (f (Function.update x i b)) (c i x))) = + fun x => avg (q i) (fun b => logRemainder (f (Function.update x i b)) (c i (Function.update x i b))) := by + funext x + congr 1 + funext b + rw [invariant_update i (c i) (hinv i)] + rw [he,avg_product_resample n q (fun x => logRemainder (f x) (c i x)) i] at hh + exact hh + +end SKRatio.Observation + +namespace SKRatio.Fields +open Observation +attribute [local instance] Classical.propDecidable +variable {n : ℕ} + +def sitePrior (g : Disorder n) (h : Fin n → ℝ) (i : Fin n) (x : Spin n) : Prior Bool where + mass b := (if b then weight g h x else weight g h (flip i x)) / + (weight g h x+weight g h (flip i x)) + nonneg b := div_nonneg (by split <;> exact (weight_pos _ _ _).le) + (add_pos (weight_pos _ _ _) (weight_pos _ _ _)).le + sum_one := by simp only [Fintype.sum_bool,Bool.false_eq_true,↓reduceIte,←add_div]; + rw [add_comm,div_self (add_pos (weight_pos _ _ _) (weight_pos _ _ _)).ne'] + +lemma sitePrior_avg (g : Disorder n) (h : Fin n → ℝ) (i : Fin n) (x : Spin n) + (f : Spin n → ℝ) : + avg (sitePrior g h i x) (fun b => f (if b then x else flip i x)) = + conditionalExpectation g h i f x := by + simp only [avg,FiniteLaw.mean,sitePrior,Fintype.sum_bool,Bool.false_eq_true,↓reduceIte, + conditionalExpectation] + ring + +lemma conditionalExpectation_pos (g : Disorder n) (h : Fin n → ℝ) (i : Fin n) + (f : Spin n → ℝ) (hf : ∀ x,0 hf _) + +lemma conditionalExpectation_log_le (g : Disorder n) (h : Fin n → ℝ) (i : Fin n) + (f : Spin n → ℝ) (hf : ∀ x,0 log (f y)) x ≤ log (conditionalExpectation g h i f x) := by + rw [←sitePrior_avg g h i x (fun y => log (f y)),←sitePrior_avg g h i x f] + exact avg_log_le_log_avg (sitePrior g h i x) + (fun b => f (if b then x else flip i x)) (fun b => hf _) + +lemma single_remainder_le_energy (g : Disorder n) (h : Fin n → ℝ) (i : Fin n) + (f : Spin n → ℝ) (hf : ∀ x,0 logRemainder (f x) (conditionalExpectation g h i f x)) ≤ + expectation g h (fun x => f x*(log (f x)-conditionalExpectation g h i (fun y => log (f y)) x)) := by + have he (x : Spin n) := logRemainder_eq (hf x).ne' (conditionalExpectation_pos g h i f hf x).ne' + simp_rw [he] + rw [expectation_add,expectation_sub,expectation_conditionalExpectation] + have hc : expectation g h (fun x => f x*log (f x)-f x*log (conditionalExpectation g h i f x)) ≤ + expectation g h (fun x => f x*(log (f x)-conditionalExpectation g h i (fun y => log (f y)) x)) := by + apply SKRatio.Fields.expectation_mono + intro x + have hj := mul_le_mul_of_nonneg_left (conditionalExpectation_log_le g h i f hf x) (hf x).le + linarith only [hj] + linarith only [hc] + +theorem remainders_le_energy (g : Disorder n) (h : Fin n → ℝ) + (f : Spin n → ℝ) (hf : ∀ x,0 ∑ i,logRemainder (f x) (conditionalExpectation g h i f x)) ≤ + expectation g h (fun x => f x*heatBathGenerator g h (fun y => log (f y)) x) := by + unfold heatBathGenerator + simp only [Finset.mul_sum] + rw [expectation_sum,expectation_sum] + exact Finset.sum_le_sum (fun i _ => single_remainder_le_energy g h i f hf) + +end SKRatio.Fields + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/FiniteChain/CutoffScale.lean b/lean/OAI/Probability/SKRatio/FiniteChain/CutoffScale.lean new file mode 100644 index 0000000000000000000000000000000000000000..2bd61912636413431676bc9d894dedc87505df19 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/FiniteChain/CutoffScale.lean @@ -0,0 +1,215 @@ +import Mathlib +import OAI.Probability.SKRatio.FiniteChain.DiscreteDistanceNonneg +import OAI.Probability.SKRatio.FiniteChain.Mean + +namespace OAI + +section +noncomputable section +open scoped BigOperators Topology Matrix +open MeasureTheory ProbabilityTheory Filter +noncomputable section +open scoped BigOperators Topology Matrix +open MeasureTheory ProbabilityTheory Filter +namespace SKRatio +namespace Independent +variable {n : ℕ} + +theorem distance_lower (hn : 2 ≤ n) (k : ℕ) {ε : ℝ} + (hbound : 4 < ε * n * ((1 - 1 / (n : ℝ)) ^ k) ^ 2) : + 1 - ε < discreteDistance (0 : Disorder n) k := by + have hnpos : 0 < n := lt_of_lt_of_le (by decide : 0 < 2) hn + have hnR : (0 : ℝ) < n := Nat.cast_pos.mpr hnpos + have h := FiniteLaw.common_mass_square + ((transition (0 : Disorder n) ^ k) (fun _ => true)) (mass 0 0) magnetization + ((transition_pow_stochastic _ k).1 _) (mass_nonneg _ _) + (Matrix.sum_row_of_mem_rowStochastic (transition_pow_stochastic _ k) _) (sum_mass _ _) + rw [row_mean_magnetization hnpos, equilibrium_mean_magnetization, sub_zero, + equilibrium_variance_magnetization] at h + have hvar := row_variance_magnetization hn k + have htv := tv_le_discreteDistance (0 : Disorder n) k (fun _ => true) + by_contra hfail + have hdist := le_of_not_gt hfail + have hb := mul_lt_mul_of_pos_right hbound hnR + have hpoint := mul_le_mul_of_nonneg_right + (show ε ≤ 1 - totalVariation ((transition (0 : Disorder n) ^ k) (fun _ => true)) + (mass 0 0) from by linarith only [htv, hdist]) + (sq_nonneg ((n : ℝ) * (1 - 1 / (n : ℝ)) ^ k)) + nlinarith only [h, hvar, hb, hpoint] + +def cutoffScale (n : ℕ) : ℝ := (n : ℝ) * Real.log n / 2 + +theorem cutoffScale_pos (hn : 2 ≤ n) : 0 < cutoffScale n := by + have h : (1 : ℝ) < n := by exact_mod_cast (lt_of_lt_of_le (by decide : 1 < 2) hn) + exact div_pos (mul_pos (by linarith) (Real.log_pos h)) (by norm_num) + +theorem cutoffScale_tendsto : Tendsto cutoffScale atTop atTop := by + have hl : Tendsto (fun n : ℕ => (1 / 2 : ℝ) * Real.log n) atTop atTop := + (Real.tendsto_log_atTop.comp tendsto_natCast_atTop_atTop).const_mul_atTop (by norm_num) + apply tendsto_atTop_mono' atTop _ hl + filter_upwards [eventually_ge_atTop 2] with n hn + have hnR : (2 : ℝ) ≤ n := by exact_mod_cast hn + have hlog : 0 ≤ Real.log (n : ℝ) := Real.log_nonneg (by linarith) + dsimp only [cutoffScale] + nlinarith + +theorem upper_exponent (hn : 2 ≤ n) (b : ℝ) : + (n : ℝ) * Real.exp (-2 * (⌈(1 + b) * cutoffScale n⌉₊ : ℝ) / n) ≤ + Real.exp (-(b * Real.log n)) := by + have hnR : (0 : ℝ) < n := by exact_mod_cast (lt_of_lt_of_le (by decide : 0 < 2) hn) + have hk := Nat.le_ceil ((1 + b) * cutoffScale n) + have hexp : Real.log (n : ℝ) + -2 * (⌈(1 + b) * cutoffScale n⌉₊ : ℝ) / n ≤ + -(b * Real.log n) := by + rw [show Real.log (n : ℝ) + -2 * (⌈(1 + b) * cutoffScale n⌉₊ : ℝ) / n = + ((n : ℝ) * Real.log n - 2 * (⌈(1 + b) * cutoffScale n⌉₊ : ℝ)) / n from by field_simp; ring, + div_le_iff₀ hnR] + dsimp only [cutoffScale] at hk ⊢ + nlinarith only [hk] + calc + _ = Real.exp (Real.log (n : ℝ) + -2 * (⌈(1 + b) * cutoffScale n⌉₊ : ℝ) / n) := by + rw [Real.exp_add, Real.exp_log hnR] + _ ≤ _ := Real.exp_le_exp.mpr hexp + +theorem one_spin_exp_lower (hn : 2 ≤ n) (k : ℕ) : + Real.exp (-2 * (k : ℝ) / ((n : ℝ) - 1)) ≤ ((1 - 1 / (n : ℝ)) ^ k) ^ 2 := by + have hnR : (2 : ℝ) ≤ n := by exact_mod_cast hn + have hnpos : (0 : ℝ) < n := by linarith + have hrpos : 0 < 1 - 1 / (n : ℝ) := by + exact sub_pos.mpr ((div_lt_one hnpos).mpr (by linarith)) + have hlog : -1 / ((n : ℝ) - 1) ≤ Real.log (1 - 1 / (n : ℝ)) := by + have hn1 : (n : ℝ) - 1 ≠ 0 := by linarith + convert Real.one_sub_inv_le_log_of_pos hrpos using 1 + field_simp [hn1] + ring + have hbase : Real.exp (-1 / ((n : ℝ) - 1)) ≤ 1 - 1 / (n : ℝ) := by + calc + _ ≤ Real.exp (Real.log (1 - 1 / (n : ℝ))) := Real.exp_le_exp.mpr hlog + _ = _ := Real.exp_log hrpos + have hpow := pow_le_pow_left₀ (Real.exp_nonneg _) hbase (2 * k) + rw [← Real.exp_nat_mul] at hpow + have hexp : (2 * k : ℕ) * (-1 / ((n : ℝ) - 1)) = -2 * (k : ℝ) / ((n : ℝ) - 1) := by + push_cast + ring + simpa only [hexp, ← pow_mul, mul_comm k 2] using hpow + +theorem lower_exponent (hn : 2 ≤ n) {b : ℝ} (hb0 : 0 < b) (hb1 : b < 1) + (hnb : 2 ≤ b * n) : + Real.exp ((b / 2) * Real.log n) ≤ + (n : ℝ) * ((1 - 1 / (n : ℝ)) ^ ⌊(1 - b) * cutoffScale n⌋₊) ^ 2 := by + have hnR : (2 : ℝ) ≤ n := by exact_mod_cast hn + have hnpos : (0 : ℝ) < n := by linarith + have hn1 : 0 < (n : ℝ) - 1 := by linarith + have hlog : 0 ≤ Real.log (n : ℝ) := Real.log_nonneg (by linarith) + have hk := Nat.floor_le (show 0 ≤ (1 - b) * cutoffScale n from + mul_nonneg (sub_pos.mpr hb1).le (cutoffScale_pos hn).le) + have hmargin : (1 - b) * (n : ℝ) ≤ (1 - b / 2) * ((n : ℝ) - 1) := by + nlinarith only [hnb, hb0] + have hbound := mul_le_mul_of_nonneg_right hmargin hlog + have hexp : (b / 2) * Real.log (n : ℝ) ≤ + Real.log n + -2 * (⌊(1 - b) * cutoffScale n⌋₊ : ℝ) / ((n : ℝ) - 1) := by + rw [show Real.log (n : ℝ) + -2 * (⌊(1 - b) * cutoffScale n⌋₊ : ℝ) / ((n : ℝ) - 1) = + (((n : ℝ) - 1) * Real.log n - 2 * (⌊(1 - b) * cutoffScale n⌋₊ : ℝ)) / + ((n : ℝ) - 1) from by field_simp; ring, + le_div_iff₀ hn1] + dsimp only [cutoffScale] at hk ⊢ + nlinarith only [hk, hbound] + calc + _ ≤ Real.exp (Real.log (n : ℝ) + + -2 * (⌊(1 - b) * cutoffScale n⌋₊ : ℝ) / ((n : ℝ) - 1)) := + Real.exp_le_exp.mpr hexp + _ = (n : ℝ) * Real.exp (-2 * (⌊(1 - b) * cutoffScale n⌋₊ : ℝ) / ((n : ℝ) - 1)) := by + rw [Real.exp_add, Real.exp_log hnpos] + _ ≤ _ := mul_le_mul_of_nonneg_left (one_spin_exp_lower hn _) hnpos.le + +theorem distance_upper_eventually {b ε : ℝ} (hb : 0 < b) (hε : 0 < ε) : + ∀ᶠ n : ℕ in atTop, discreteDistance (0 : Disorder n) ⌈(1 + b) * cutoffScale n⌉₊ ≤ ε := by + have hlog : Tendsto (fun n : ℕ => b * Real.log n) atTop atTop := + (Real.tendsto_log_atTop.comp tendsto_natCast_atTop_atTop).const_mul_atTop hb + have hsmall : Tendsto (fun n : ℕ => Real.exp (Real.exp (-(b * Real.log n))) - 1) + atTop (𝓝 0) := by + have hexp := Real.tendsto_exp_neg_atTop_nhds_zero.comp hlog + simpa only [Real.exp_zero, sub_self, Function.comp_def] using + (Real.continuous_exp.continuousAt.tendsto.comp hexp).sub_const 1 + have htarget : 0 < 4 * ε ^ 2 := by positivity + filter_upwards [eventually_ge_atTop 2, hsmall.eventually (gt_mem_nhds htarget)] with n hn he + apply distance_upper (lt_of_lt_of_le (by decide : 0 < 2) hn) _ hε.le + exact (sub_le_sub_right (Real.exp_le_exp.mpr (upper_exponent hn b)) 1).trans he.le + +theorem distance_lower_eventually {b ε : ℝ} (hb0 : 0 < b) (hb1 : b < 1) (hε : 0 < ε) : + ∀ᶠ n : ℕ in atTop, 1 - ε < discreteDistance (0 : Disorder n) ⌊(1 - b) * cutoffScale n⌋₊ := by + have hlog : Tendsto (fun n : ℕ => (b / 2) * Real.log n) atTop atTop := + (Real.tendsto_log_atTop.comp tendsto_natCast_atTop_atTop).const_mul_atTop (by positivity) + have hlarge : Tendsto (fun n : ℕ => ε * Real.exp ((b / 2) * Real.log n)) atTop atTop := + (Real.tendsto_exp_atTop.comp hlog).const_mul_atTop hε + have hnb : Tendsto (fun n : ℕ => b * n) atTop atTop := + tendsto_natCast_atTop_atTop.const_mul_atTop hb0 + filter_upwards [eventually_ge_atTop 2, hnb.eventually_ge_atTop 2, + hlarge.eventually_gt_atTop 4] with n hn hb he + apply distance_lower hn + exact he.trans_le (by + simpa only [mul_assoc] using + mul_le_mul_of_nonneg_left (lower_exponent hn hb0 hb1 hb) hε.le) + +theorem mixing_ratio_eventually {ε η : ℝ} (hε0 : 0 < ε) (hε1 : ε < 1) (hη : 0 < η) : + ∀ᶠ n : ℕ in atTop, + (mixingTime (0 : Disorder n) ε : ℝ) / (mixingTime (0 : Disorder n) (1 - ε) : ℝ) ≤ + 1 + η := by + let b : ℝ := η / (2 * (2 + η)) + have hden : 0 < 2 * (2 + η) := by positivity + have hb0 : 0 < b := div_pos hη hden + have hb1 : b < 1 := (div_lt_one hden).mpr (by linarith) + have hbid : b * (2 + η) = η / 2 := by + dsimp only [b] + field_simp + have hbase : (1 + b) / (1 - b) < 1 + η := by + apply (div_lt_iff₀ (sub_pos.mpr hb1)).mpr + nlinarith only [hbid, hη] + have hrem : Tendsto (fun n => 1 / ((1 - b) * cutoffScale n)) atTop (𝓝 0) := by + simpa only [one_div, Function.comp_def] using + tendsto_inv_atTop_zero.comp (cutoffScale_tendsto.const_mul_atTop (sub_pos.mpr hb1)) + have hevent := hrem.eventually (gt_mem_nhds (sub_pos.mpr hbase)) + filter_upwards [distance_lower_eventually hb0 hb1 hε0, distance_upper_eventually hb0 hε0, + eventually_ge_atTop 2, hevent] with n hl hu hn hr + have hratio := mixing_ratio_bound (0 : Disorder n) hε0 hε1 hb0 hb1 (cutoffScale_pos hn) hl hu + linarith only [hr, hratio] + +end Independent + +theorem disorderLaw_zero_ae (n : ℕ) : ∀ᵐ g : Disorder n ∂disorderLaw 0 n, g = 0 := by + have hs : disorderLaw 0 n ({0} : Set (Disorder n)) = 1 := by + simp [disorderLaw, Measure.pi_singleton] + rw [ae_iff] + change disorderLaw 0 n ({0}ᶜ : Set (Disorder n)) = 0 + rw [measure_compl (measurableSet_singleton 0) (measure_ne_top _ _), measure_univ, hs, tsub_self] + +theorem ratio_cutoff_zero (ε η : ℝ) (hε0 : 0 < ε) (hεhalf : ε < 1 / 2) (hη : 0 < η) : + Tendsto + (fun n : ℕ => disorderLaw 0 n + {g : Disorder n | 1 + η < + (mixingTime g ε : ℝ) / (mixingTime g (1 - ε) : ℝ)}) + atTop (𝓝 0) ∧ + (∀ᶠ n : ℕ in atTop, ∀ g : Disorder n, 0 < mixingTime g (1 - ε)) := by + have hε1 : ε < 1 := by linarith + refine ⟨?_, denominator_eventually_positive ε hε0 hε1⟩ + apply Tendsto.congr' _ tendsto_const_nhds + filter_upwards [Independent.mixing_ratio_eventually hε0 hε1 hη] with n hn + symm + have hempty : ∀ᵐ g : Disorder n ∂disorderLaw 0 n, + ¬ (1 + η < (mixingTime g ε : ℝ) / (mixingTime g (1 - ε) : ℝ)) := by + filter_upwards [disorderLaw_zero_ae n] with g hg + subst g + exact not_lt_of_ge hn + simpa only [not_not] using ae_iff.mp hempty + +end SKRatio + +noncomputable section +open scoped BigOperators Topology +open MeasureTheory ProbabilityTheory Filter + +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/FiniteChain/DiscreteDistanceNonneg.lean b/lean/OAI/Probability/SKRatio/FiniteChain/DiscreteDistanceNonneg.lean new file mode 100644 index 0000000000000000000000000000000000000000..78c3b8186ba3f3d7f67cb2f3b2f69dea63b41f2b --- /dev/null +++ b/lean/OAI/Probability/SKRatio/FiniteChain/DiscreteDistanceNonneg.lean @@ -0,0 +1,230 @@ +import Mathlib +import OAI.Probability.SKRatio.FiniteChain.Spin + +namespace OAI + +section +noncomputable section +open scoped BigOperators Topology Matrix +open MeasureTheory ProbabilityTheory Filter +namespace SKRatio +section MixingTime +variable {n : ℕ} + +theorem discreteDistance_nonneg (g : Disorder n) (k : ℕ) : + 0 ≤ discreteDistance g k := + (totalVariation_nonneg _ _).trans (tv_le_discreteDistance g k (fun _ => true)) + +theorem discreteDistance_le_one (g : Disorder n) (k : ℕ) : + discreteDistance g k ≤ 1 := by + apply Finset.sup'_le + intro x _ + have hP := transition_pow_stochastic g k + exact totalVariation_le_one _ _ (hP.1 x) (mass_nonneg g 0) + (Matrix.sum_row_of_mem_rowStochastic hP x) (sum_mass g 0) + +theorem discreteDistance_antitone (g : Disorder n) : Antitone (discreteDistance g) := by + apply antitone_nat_of_succ_le + intro k + apply Finset.sup'_le + intro x _ + have hsum : (∑ y, (transition g ^ k) x y) = ∑ y, mass g 0 y := by + rw [Matrix.sum_row_of_mem_rowStochastic (transition_pow_stochastic g k), sum_mass] + calc + totalVariation ((transition g ^ (k + 1)) x) (mass g 0) = + totalVariation ((transition g ^ k) x ᵥ* transition g) (mass g 0 ᵥ* transition g) := by + rw [pow_succ, Matrix.mul_apply_eq_vecMul, transition_stationary] + _ ≤ totalVariation ((transition g ^ k) x) (mass g 0) := + totalVariation_contract _ (transition_stochastic g) _ _ hsum + _ ≤ discreteDistance g k := tv_le_discreteDistance g k x + +theorem exists_geometric_bound (g : Disorder n) : + ∃ r : ℝ, 0 ≤ r ∧ r < 1 ∧ ∀ k : ℕ, discreteDistance g (n * k) ≤ r ^ k := by + obtain ⟨r, hr0, hr1, hbound⟩ := exists_geometric_block_bound + (transition g) (transition_stochastic g) (mass g 0) (mass_nonneg g 0) (sum_mass g 0) + n (transition_n_pos g) (transition_pow_stationary g n) + refine ⟨r, hr0, hr1, fun k => Finset.sup'_le _ _ (fun x _ => hbound k x)⟩ + +theorem exists_mixing_time (g : Disorder n) {ε : ℝ} (hε : 0 < ε) : + ∃ k : ℕ, discreteDistance g k ≤ ε := by + obtain ⟨r, hr0, hr1, hbound⟩ := exists_geometric_bound g + have H := (tendsto_pow_atTop_nhds_zero_of_lt_one hr0 hr1).eventually (gt_mem_nhds hε) + obtain ⟨k, hk⟩ := H.exists + exact ⟨n * k, (hbound k).trans hk.le⟩ + +theorem mixingTime_spec (g : Disorder n) {ε : ℝ} (hε : 0 < ε) : + discreteDistance g (mixingTime g ε) ≤ ε := + Nat.sInf_mem (exists_mixing_time g hε) + +theorem mixingTime_le_of_distance_le (g : Disorder n) {ε : ℝ} {k : ℕ} + (hk : discreteDistance g k ≤ ε) : mixingTime g ε ≤ k := Nat.sInf_le hk + +theorem mixingTime_le_iff (g : Disorder n) {ε : ℝ} (hε : 0 < ε) (k : ℕ) : + mixingTime g ε ≤ k ↔ discreteDistance g k ≤ ε := by + constructor + · intro h + exact (discreteDistance_antitone g h).trans (mixingTime_spec g hε) + · exact mixingTime_le_of_distance_le g + +theorem lt_mixingTime_of_lt_distance (g : Disorder n) {ε : ℝ} (hε : 0 < ε) + {k : ℕ} (hk : ε < discreteDistance g k) : k < mixingTime g ε := by + exact lt_of_not_ge (fun h => not_le_of_gt hk ((mixingTime_le_iff g hε k).mp h)) + +theorem discreteDistance_zero_lower (g : Disorder n) : + 1 - (1 / 2 : ℝ) ^ n ≤ discreteDistance g 0 := by + have hpoint (x : Spin n) : 1 - mass g 0 x ≤ discreteDistance g 0 := by + have h := tv_le_discreteDistance g 0 x + simpa only [pow_zero, totalVariation_dirac _ (mass_nonneg g 0) (sum_mass g 0)] using h + have hsum : (Fintype.card (Spin n) : ℝ) * (1 - discreteDistance g 0) ≤ 1 := by + calc + (Fintype.card (Spin n) : ℝ) * (1 - discreteDistance g 0) = + ∑ _x : Spin n, (1 - discreteDistance g 0) := by + simp only [Finset.sum_const, Finset.card_univ, nsmul_eq_mul] + _ ≤ ∑ x, mass g 0 x := Finset.sum_le_sum (fun x _ => by linarith [hpoint x]) + _ = 1 := sum_mass g 0 + have hcard : Fintype.card (Spin n) = 2 ^ n := by simp [Spin] + have hcpos : (0 : ℝ) < Fintype.card (Spin n) := Nat.cast_pos.mpr Fintype.card_pos + have h : 1 - discreteDistance g 0 ≤ (1 : ℝ) / Fintype.card (Spin n) := + (le_div_iff₀ hcpos).mpr (by simpa only [mul_comm] using hsum) + have hid : (1 : ℝ) / Fintype.card (Spin n) = (1 / 2 : ℝ) ^ n := by + rw [hcard, Nat.cast_pow, Nat.cast_ofNat, one_div_pow] + rw [hid] at h + linarith + +theorem denominator_eventually_positive (ε : ℝ) (hε0 : 0 < ε) (hε1 : ε < 1) : + ∀ᶠ n : ℕ in atTop, ∀ g : Disorder n, 0 < mixingTime g (1 - ε) := by + have H := (tendsto_pow_atTop_nhds_zero_of_lt_one + (by norm_num : (0 : ℝ) ≤ 1 / 2) (by norm_num : (1 / 2 : ℝ) < 1)).eventually + (gt_mem_nhds hε0) + filter_upwards [H] with n hn + intro g + apply lt_mixingTime_of_lt_distance g (sub_pos.mpr hε1) + linarith [discreteDistance_zero_lower g] + +theorem mixing_ratio_bound (g : Disorder n) {ε b T : ℝ} + (hε0 : 0 < ε) (hε1 : ε < 1) (hb0 : 0 < b) (hb1 : b < 1) (hT : 0 < T) + (hlower : 1 - ε < discreteDistance g ⌊(1 - b) * T⌋₊) + (hupper : discreteDistance g ⌈(1 + b) * T⌉₊ ≤ ε) : + (mixingTime g ε : ℝ) / (mixingTime g (1 - ε) : ℝ) ≤ + (1 + b) / (1 - b) + 1 / ((1 - b) * T) := by + have hlo := lt_mixingTime_of_lt_distance g (sub_pos.mpr hε1) hlower + have hup := (mixingTime_le_iff g hε0 _).mpr hupper + have htlo : (1 - b) * T < (mixingTime g (1 - ε) : ℝ) := by + have hcast : (⌊(1 - b) * T⌋₊ : ℝ) + 1 ≤ (mixingTime g (1 - ε) : ℝ) := by + exact_mod_cast hlo + exact (Nat.lt_floor_add_one _).trans_le hcast + have hthi : (mixingTime g ε : ℝ) ≤ (1 + b) * T + 1 := by + have hcast : (mixingTime g ε : ℝ) ≤ (⌈(1 + b) * T⌉₊ : ℝ) := by + exact_mod_cast hup + exact hcast.trans (Nat.ceil_lt_add_one (by positivity)).le + have htpos : 0 < (1 - b) * T := mul_pos (sub_pos.mpr hb1) hT + have hden : 0 < (mixingTime g (1 - ε) : ℝ) := htpos.trans htlo + calc + (mixingTime g ε : ℝ) / (mixingTime g (1 - ε) : ℝ) ≤ + ((1 + b) * T + 1) / (mixingTime g (1 - ε) : ℝ) := + div_le_div_of_nonneg_right hthi hden.le + _ ≤ ((1 + b) * T + 1) / ((1 - b) * T) := + div_le_div_of_nonneg_left (by positivity) htpos htlo.le + _ = (1 + b) / (1 - b) + 1 / ((1 - b) * T) := by + field_simp + +end MixingTime + +section Measurability +variable {n : ℕ} + +@[fun_prop] theorem continuous_coupling (i j : Fin n) : + Continuous (fun g : Disorder n => coupling g i j) := by + unfold coupling + split_ifs <;> fun_prop + +@[fun_prop] theorem continuous_hamiltonian (h : Fin n → ℝ) (x : Spin n) : + Continuous (fun g : Disorder n => hamiltonian g h x) := by + unfold hamiltonian + fun_prop + +@[fun_prop] theorem continuous_weight (h : Fin n → ℝ) (x : Spin n) : + Continuous (fun g : Disorder n => weight g h x) := by + unfold weight + fun_prop + +@[fun_prop] theorem continuous_partition (h : Fin n → ℝ) : + Continuous (fun g : Disorder n => partition g h) := by + unfold partition + fun_prop + +@[fun_prop] theorem continuous_mass (h : Fin n → ℝ) (x : Spin n) : + Continuous (fun g : Disorder n => mass g h x) := by + exact (continuous_weight h x).div (continuous_partition h) + (fun g => (partition_pos g h).ne') + +@[fun_prop] theorem continuous_siteKernel (i : Fin n) (x y : Spin n) : + Continuous (fun g : Disorder n => siteKernel g i x y) := by + have hd : ∀ g : Disorder n, mass g 0 x + mass g 0 (flip i x) ≠ 0 := + fun g => (add_pos (mass_pos g 0 x) (mass_pos g 0 (flip i x))).ne' + have hx := (continuous_mass 0 x).div + ((continuous_mass 0 x).add (continuous_mass 0 (flip i x))) hd + have hf := (continuous_mass 0 (flip i x)).div + ((continuous_mass 0 x).add (continuous_mass 0 (flip i x))) hd + unfold siteKernel + split_ifs <;> fun_prop + +@[fun_prop] theorem continuous_transition (x y : Spin n) : + Continuous (fun g : Disorder n => transition g x y) := by + by_cases hn : n = 0 + · simp only [transition, hn, ↓reduceIte] + fun_prop + · simp only [transition, hn, ↓reduceIte] + fun_prop + +@[fun_prop] theorem continuous_transition_pow (k : ℕ) (x y : Spin n) : + Continuous (fun g : Disorder n => (transition g ^ k) x y) := by + induction k generalizing x y with + | zero => simp only [pow_zero]; fun_prop + | succ k ih => + simp only [pow_succ, Matrix.mul_apply] + fun_prop + +@[fun_prop] theorem continuous_discreteDistance (k : ℕ) : + Continuous (fun g : Disorder n => discreteDistance g k) := by + have h : Continuous (Finset.univ.sup' Finset.univ_nonempty + (fun (x : Spin n) (g : Disorder n) => + totalVariation ((transition g ^ k) x) (mass g 0))) := by + apply Continuous.finset_sup' + intro x _ + unfold totalVariation + fun_prop + exact h.congr (fun g => Finset.sup'_apply _ _ g) + +@[fun_prop] theorem measurable_mixingTime {ε : ℝ} (hε : 0 < ε) : + Measurable (fun g : Disorder n => mixingTime g ε) := by + apply measurable_of_Iic + intro k + have heq : (fun g : Disorder n => mixingTime g ε) ⁻¹' Set.Iic k = + {g : Disorder n | discreteDistance g k ≤ ε} := by + ext g + exact mixingTime_le_iff g hε k + rw [heq] + exact measurableSet_le (continuous_discreteDistance k).measurable measurable_const + +theorem measurableSet_ratio_event {ε : ℝ} (hε0 : 0 < ε) (hε1 : ε < 1) (η : ℝ) : + MeasurableSet {g : Disorder n | 1 + η < + (mixingTime g ε : ℝ) / (mixingTime g (1 - ε) : ℝ)} := by + have hm1 := measurable_mixingTime (n := n) hε0 + have hm2 := measurable_mixingTime (n := n) (sub_pos.mpr hε1) + apply measurableSet_lt measurable_const + fun_prop + +end Measurability + +end SKRatio + +noncomputable section +open scoped BigOperators Topology Matrix +open MeasureTheory ProbabilityTheory Filter + +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/FiniteChain/EntropicCovariance.lean b/lean/OAI/Probability/SKRatio/FiniteChain/EntropicCovariance.lean new file mode 100644 index 0000000000000000000000000000000000000000..9c2cd1944611f912ba0d29d1956061fb9a992373 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/FiniteChain/EntropicCovariance.lean @@ -0,0 +1,324 @@ +import Mathlib +import OAI.Probability.SKRatio.Variational.UniformGap +import OAI.Probability.SKRatio.Entropy.Entropy + +namespace OAI + +section +noncomputable section +open scoped BigOperators Topology +open MeasureTheory Filter Real +namespace SKRatio.Observation +attribute [local instance] Classical.propDecidable +variable {α : Type*} [Fintype α] + +structure Prior (α : Type*) [Fintype α] where + mass : α → ℝ + nonneg : ∀ x, 0 ≤ mass x + sum_one : ∑ x, mass x = 1 + +instance : CoeFun (Prior α) (fun _ => α → ℝ) := ⟨Prior.mass⟩ + +@[ext] lemma Prior.ext {p q : Prior α} (h : p.mass = q.mass) : p = q := by + cases p; cases q; congr + +def avg (p : Prior α) (f : α → ℝ) : ℝ := FiniteLaw.mean p f + +def var (p : Prior α) (f : α → ℝ) : ℝ := FiniteLaw.variance p f + +def ent (p : Prior α) (f : α → ℝ) : ℝ := FiniteLaw.entropy p f + +lemma avg_const (p : Prior α) (c : ℝ) : avg p (fun _ => c) = c := by + simp only [avg,FiniteLaw.mean,← Finset.sum_mul,p.sum_one,one_mul] + +lemma avg_nonneg (p : Prior α) {f : α → ℝ} (hf : ∀ x, 0 ≤ f x) : 0 ≤ avg p f := + Finset.sum_nonneg (fun x _ => mul_nonneg (p.nonneg x) (hf x)) + +lemma avg_pos (p : Prior α) {f : α → ℝ} (hf : ∀ x, 0 < f x) : 0 < avg p f := by + have h : 0 < ∑ x, p x := by rw [p.sum_one];norm_num + obtain ⟨x,hx,hpx⟩ := (Finset.sum_pos_iff_of_nonneg (fun x _ => p.nonneg x)).mp h + exact Finset.sum_pos' (fun y _ => mul_nonneg (p.nonneg y) (hf y).le) + ⟨x,hx,mul_pos hpx (hf x)⟩ + +lemma avg_mono (p : Prior α) {f g : α → ℝ} (h : ∀ x, f x ≤ g x) : avg p f ≤ avg p g := + Finset.sum_le_sum (fun x _ => mul_le_mul_of_nonneg_left (h x) (p.nonneg x)) + +lemma avg_add (p : Prior α) (f g : α → ℝ) : avg p (fun x => f x+g x) = avg p f+avg p g := by + simp only [avg,FiniteLaw.mean,mul_add,Finset.sum_add_distrib] + +lemma avg_sub (p : Prior α) (f g : α → ℝ) : avg p (fun x => f x-g x) = avg p f-avg p g := by + simp only [avg,FiniteLaw.mean,mul_sub,Finset.sum_sub_distrib] + +lemma avg_const_mul (p : Prior α) (c : ℝ) (f : α → ℝ) : avg p (fun x => c*f x) = c*avg p f := by + simp only [avg,FiniteLaw.mean,Finset.mul_sum,mul_left_comm] + +lemma avg_mul_const (p : Prior α) (f : α → ℝ) (c : ℝ) : avg p (fun x => f x*c) = avg p f*c := by + simp only [avg,FiniteLaw.mean,Finset.sum_mul,mul_assoc] + +lemma var_eq (p : Prior α) (v : α → ℝ) : var p v = avg p (fun x => v x^2)-(avg p v)^2 := + FiniteLaw.variance_eq p v p.sum_one + +def tiltZ (p : Prior α) (v : α → ℝ) (s : ℝ) : ℝ := avg p (fun x => exp (s*v x)) + +lemma tiltZ_pos (p : Prior α) (v : α → ℝ) (s : ℝ) : 0 < tiltZ p v s := + avg_pos p (fun _ => exp_pos _) + +def tilt (p : Prior α) (v : α → ℝ) (s : ℝ) : Prior α where + mass x := p x*exp (s*v x)/tiltZ p v s + nonneg x := div_nonneg (mul_nonneg (p.nonneg x) (exp_nonneg _)) (tiltZ_pos p v s).le + sum_one := by + rw [← Finset.sum_div] + exact div_self (tiltZ_pos p v s).ne' + +@[simp] lemma tilt_apply (p : Prior α) (v : α → ℝ) (s : ℝ) (x : α) : + tilt p v s x = p x*exp (s*v x)/tiltZ p v s := rfl + +@[simp] lemma tiltZ_zero (p : Prior α) (v : α → ℝ) : tiltZ p v 0 = 1 := by + simp only [tiltZ,zero_mul,exp_zero,avg_const] + +@[simp] lemma tilt_zero (p : Prior α) (v : α → ℝ) : tilt p v 0 = p := by + ext x + simp only [tilt_apply,zero_mul,exp_zero,tiltZ_zero,mul_one,div_one] + +lemma avg_tilt (p : Prior α) (v f : α → ℝ) (s : ℝ) : + avg (tilt p v s) f = avg p (fun x => exp (s*v x)*f x)/tiltZ p v s := by + simp only [avg,FiniteLaw.mean,tilt_apply,Finset.sum_div] + apply Finset.sum_congr rfl + intro x _ + ring + +lemma hasDerivAt_tiltZ (p : Prior α) (v : α → ℝ) (s : ℝ) : + HasDerivAt (tiltZ p v) (avg p (fun x => exp (s*v x)*v x)) s := by + unfold tiltZ avg FiniteLaw.mean + apply HasDerivAt.fun_sum + intro x _ + simpa only [id_eq,one_mul] using + (((hasDerivAt_id s).mul_const (v x)).exp).const_mul (p x) + +lemma hasDerivAt_tiltNumerator (p : Prior α) (v : α → ℝ) (s : ℝ) : + HasDerivAt (fun r => avg p (fun x => exp (r*v x)*v x)) + (avg p (fun x => exp (s*v x)*(v x)^2)) s := by + unfold avg FiniteLaw.mean + apply HasDerivAt.fun_sum + intro x _ + convert! (((((hasDerivAt_id s).mul_const (v x)).exp).mul_const (v x)).const_mul (p x)) using 1 + simp only [id_eq,one_mul] + ring + +lemma hasDerivAt_logTiltZ (p : Prior α) (v : α → ℝ) (s : ℝ) : + HasDerivAt (fun r => log (tiltZ p v r)) (avg (tilt p v s) v) s := by + rw [avg_tilt] + exact (hasDerivAt_tiltZ p v s).log (tiltZ_pos p v s).ne' + +lemma hasDerivAt_tiltedMean (p : Prior α) (v : α → ℝ) (s : ℝ) : + HasDerivAt (fun r => avg (tilt p v r) v) (var (tilt p v s) v) s := by + simp_rw [avg_tilt] + convert! (hasDerivAt_tiltNumerator p v s).div (hasDerivAt_tiltZ p v s) + (tiltZ_pos p v s).ne' using 1 + rw [var_eq,avg_tilt,avg_tilt] + field_simp [(tiltZ_pos p v s).ne'] + +lemma quadratic_upper_of_derivatives (F G Q : ℝ → ℝ) {C : ℝ} + (hF : ∀ r, HasDerivAt F (G r) r) (hG : ∀ r, HasDerivAt G (Q r) r) + (hQ : ∀ r, Q r ≤ C) (s : ℝ) : + F s ≤ F 0 + s*G 0 + C*s^2/2 := by + let A := fun r => F r-C*r^2/2 + let B := fun r => G r-C*r + have hA (r : ℝ) : HasDerivAt A (B r) r := by + convert! (hF r).sub ((((hasDerivAt_id r).pow 2).const_mul C).div_const 2) using 1 + dsimp [A,B] + ring + have hB (r : ℝ) : HasDerivAt B (Q r-C) r := by + dsimp only [B] + convert! (hG r).sub ((hasDerivAt_id r).const_mul C) using 1 + simp only [mul_one] + have hanti : Antitone B := antitone_of_deriv_nonpos + (fun r => (hB r).differentiableAt) (fun r => by rw [(hB r).deriv];linarith [hQ r]) + have hderiv : deriv A = B := funext (fun r => (hA r).deriv) + have hconc : ConcaveOn ℝ Set.univ A := Antitone.concaveOn_univ_of_deriv + (fun r => (hA r).differentiableAt) (hderiv ▸ hanti) + rcases lt_trichotomy 0 s with hs | rfl | hs + · have h := hconc.slope_le_deriv (Set.mem_univ 0) (Set.mem_univ s) hs + (hA 0).differentiableAt + rw [(hA 0).deriv] at h + simp only [slope,sub_zero,vsub_eq_sub,smul_eq_mul] at h + have hh : A s-A 0 ≤ B 0*s := by + have he : s⁻¹*(A s-A 0) = (A s-A 0)/s := by ring + rw [he,div_le_iff₀ hs] at h + exact h + dsimp [A,B] at hh + nlinarith only [hh] + · ring_nf + exact le_rfl + · have h := hconc.deriv_le_slope (Set.mem_univ s) (Set.mem_univ 0) hs + (hA 0).differentiableAt + rw [(hA 0).deriv] at h + simp only [slope,zero_sub,vsub_eq_sub,smul_eq_mul] at h + have hh : B 0*(-s) ≤ A 0-A s := by + have he : (-s)⁻¹*(A 0-A s) = (A 0-A s)/(-s) := by ring + rw [he,le_div_iff₀ (neg_pos.mpr hs)] at h + exact h + dsimp [A,B] at hh + nlinarith only [hh] + +theorem logTiltZ_le (p : Prior α) (v : α → ℝ) {C : ℝ} + (hC : ∀ s, var (tilt p v s) v ≤ C) (s : ℝ) : + log (tiltZ p v s) ≤ s*avg p v+C*s^2/2 := by + have h := quadratic_upper_of_derivatives + (fun r => log (tiltZ p v r)) (fun r => avg (tilt p v r) v) + (fun r => var (tilt p v r) v) (hasDerivAt_logTiltZ p v) + (hasDerivAt_tiltedMean p v) hC s + simpa only [tiltZ_zero,log_one,tilt_zero,zero_add] using h + +theorem mean_displacement_sq (p q : Prior α) (v : α → ℝ) {C : ℝ} + (hp : ∀ x, 0 < p x) (hC : 0 < C) (hvar : ∀ s, var (tilt p v s) v ≤ C) : + (avg q v-avg p v)^2 ≤ 2*C*FiniteLaw.relativeEntropy q p := by + let d := avg q v-avg p v + have he := FiniteLaw.entropy_variational q p (fun x => (d/C)*v x) + q.nonneg hp q.sum_one p.sum_one + have hm := logTiltZ_le p v hvar (d/C) + change avg q (fun x => (d/C)*v x) ≤ FiniteLaw.relativeEntropy q p+ + log (tiltZ p v (d/C)) at he + rw [avg_const_mul] at he + have hh : (d/C)*d ≤ FiniteLaw.relativeEntropy q p+C*(d/C)^2/2 := by + dsimp [d] at * + nlinarith only [he,hm] + have heq : (d/C)*d-C*(d/C)^2/2 = d^2/(2*C) := by field_simp;ring + have hb : d^2/(2*C) ≤ FiniteLaw.relativeEntropy q p := by linarith only [hh,heq] + rw [div_le_iff₀ (by positivity : 0 < 2*C)] at hb + simpa only [mul_comm (FiniteLaw.relativeEntropy q p)] using hb + +variable {ι : Type*} [Fintype ι] + +def linear (v : α → ι → ℝ) (a : ι → ℝ) (x : α) : ℝ := ∑ i, a i*v x i + +lemma avg_linear (p : Prior α) (v : α → ι → ℝ) (a : ι → ℝ) : + avg p (linear v a) = ∑ i, a i*avg p (fun x => v x i) := by + simp only [avg,FiniteLaw.mean,linear,Finset.mul_sum] + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro i _ + exact Finset.sum_congr rfl (fun x _ => by ring) + +theorem vector_mean_displacement_sq (p q : Prior α) (v : α → ι → ℝ) {C : ℝ} + (hp : ∀ x, 0 < p x) (hC : 0 < C) + (hvar : ∀ a : ι → ℝ, ∀ s : ℝ, + var (tilt p (linear v a) s) (linear v a) ≤ C*(∑ i, a i^2)) : + (∑ i, (avg q (fun x => v x i)-avg p (fun x => v x i))^2) ≤ + 2*C*FiniteLaw.relativeEntropy q p := by + let a := fun i => avg q (fun x => v x i)-avg p (fun x => v x i) + let R := ∑ i, a i^2 + have hR : 0 ≤ R := Finset.sum_nonneg (fun _ _ => sq_nonneg _) + have hE := FiniteLaw.relativeEntropy_nonneg q p q.nonneg hp q.sum_one p.sum_one + rcases eq_or_lt_of_le hR with hz | hz + · change R ≤ _ + rw [← hz] + exact mul_nonneg (by positivity) hE + have hh := mean_displacement_sq p q (linear v a) hp (mul_pos hC hz) (hvar a) + have he : avg q (linear v a)-avg p (linear v a) = R := by + simp only [avg_linear,← Finset.sum_sub_distrib] + apply Finset.sum_congr rfl + intro i _ + dsimp [a] + ring + rw [he] at hh + change R ≤ _ + nlinarith only [hh,hz] + +def reweight (p : Prior α) (f : α → ℝ) (hf : ∀ x, 0 < f x) : Prior α where + mass x := p x*f x/avg p f + nonneg x := div_nonneg (mul_nonneg (p.nonneg x) (hf x).le) (avg_pos p hf).le + sum_one := by rw [← Finset.sum_div];exact div_self (avg_pos p hf).ne' + +lemma avg_reweight (p : Prior α) (f v : α → ℝ) (hf : ∀ x, 0 < f x) : + avg (reweight p f hf) v = avg p (fun x => f x*v x)/avg p f := by + simp only [avg,FiniteLaw.mean,reweight,Finset.sum_div] + exact Finset.sum_congr rfl (fun x _ => by ring) + +lemma relativeEntropy_reweight (p : Prior α) (f : α → ℝ) (hf : ∀ x, 0 < f x) + (hp : ∀ x, 0 < p x) : + FiniteLaw.relativeEntropy (reweight p f hf) p = ent p f/avg p f := by + have he (x : α) : p x*f x/avg p f/p x = f x/avg p f := by + field_simp [(avg_pos p hf).ne',(hp x).ne'] + simp only [FiniteLaw.relativeEntropy,reweight,he, + log_div (hf _).ne' (avg_pos p hf).ne',mul_sub,Finset.sum_sub_distrib] + have ha : (∑ x, p x*f x/avg p f*log (f x)) = + avg p (fun x => f x*log (f x))/avg p f := by + simp only [avg,FiniteLaw.mean,Finset.sum_div] + exact Finset.sum_congr rfl (fun x _ => by ring) + rw [ha,← Finset.sum_mul,← Finset.sum_div] + change _-avg p f/avg p f*log (avg p f)=_ + rw [div_self (avg_pos p hf).ne',one_mul] + unfold ent FiniteLaw.entropy + change _ = (avg p (fun x => f x*log (f x))-avg p f*log (avg p f))/avg p f + field_simp [(avg_pos p hf).ne'] + +theorem covariance_entropy (p : Prior α) (v : α → ι → ℝ) (f : α → ℝ) {C : ℝ} + (hp : ∀ x, 0 < p x) (hf : ∀ x, 0 < f x) (hC : 0 < C) + (hvar : ∀ a : ι → ℝ, ∀ s : ℝ, + var (tilt p (linear v a) s) (linear v a) ≤ C*(∑ i, a i^2)) : + (∑ i, (avg p (fun x => v x i*f x)-avg p (fun x => v x i)*avg p f)^2) ≤ + 2*C*avg p f*ent p f := by + have h := vector_mean_displacement_sq p (reweight p f hf) v hp hC hvar + rw [relativeEntropy_reweight p f hf hp] at h + simp_rw [avg_reweight] at h + have he (i : ι) : + avg p (fun x => f x*v x i)/avg p f-avg p (fun x => v x i) = + (avg p (fun x => v x i*f x)-avg p (fun x => v x i)*avg p f)/avg p f := by + rw [show (fun x => f x*v x i) = (fun x => v x i*f x) by funext x;ring] + field_simp [(avg_pos p hf).ne'] + simp_rw [he,div_pow] at h + rw [← Finset.sum_div] at h + have hm := (div_le_iff₀ (sq_pos_of_pos (avg_pos p hf))).mp h + convert! hm using 1 + rw [pow_two] + calc + _ = 2*C*((ent p f/avg p f)*avg p f)*avg p f := by + rw [div_mul_cancel₀ _ (avg_pos p hf).ne'] + ring + _ = _ := by ring + +def gibbsPrior {n : ℕ} (g : Disorder n) (h : Fin n → ℝ) : Prior (Spin n) := + ⟨mass g h,mass_nonneg g h,sum_mass g h⟩ + +lemma weight_field_tilt {n : ℕ} (g : Disorder n) (h a : Fin n → ℝ) (s : ℝ) (x : Spin n) : + weight g (h+s • a) x = weight g h x*exp (s*Fields.linearObservable a x) := by + rw [weight,weight,← exp_add] + congr 1 + simp only [hamiltonian,Pi.add_apply,Pi.smul_apply,smul_eq_mul,add_mul, + Finset.sum_add_distrib,Fields.linearObservable,Finset.mul_sum,mul_assoc] + ring + +lemma tilt_gibbs_linear {n : ℕ} (g : Disorder n) (h a : Fin n → ℝ) (s : ℝ) : + tilt (gibbsPrior g h) (Fields.linearObservable a) s = gibbsPrior g (h+s • a) := by + have hz : tiltZ (gibbsPrior g h) (Fields.linearObservable a) s = + partition g (h+s • a)/partition g h := by + simp only [tiltZ,avg,FiniteLaw.mean,gibbsPrior,mass,partition,weight_field_tilt, + Finset.sum_div] + exact Finset.sum_congr rfl (fun x _ => by ring) + apply Prior.ext + funext x + rw [tilt_apply,hz] + simp only [gibbsPrior,mass,weight_field_tilt] + field_simp [(partition_pos g h).ne',(partition_pos g (h+s • a)).ne'] + +theorem spin_covariance_entropy {n : ℕ} (g : Disorder n) (h : Fin n → ℝ) + (f : Spin n → ℝ) {C : ℝ} (hf : ∀ x, 0 < f x) (hC : 0 < C) + (hvar : ∀ θ a : Fin n → ℝ, + Fields.variance g θ (Fields.linearObservable a) ≤ C*∑ i, a i^2) : + (∑ i, (avg (gibbsPrior g h) (fun x => spinValue (x i)*f x)- + avg (gibbsPrior g h) (fun x => spinValue (x i))*avg (gibbsPrior g h) f)^2) ≤ + 2*C*avg (gibbsPrior g h) f*ent (gibbsPrior g h) f := by + apply covariance_entropy (gibbsPrior g h) (fun x i => spinValue (x i)) f + (mass_pos g h) hf hC + intro a s + change var (tilt (gibbsPrior g h) (Fields.linearObservable a) s) (Fields.linearObservable a) ≤ _ + rw [tilt_gibbs_linear] + exact hvar (h+s • a) a + +end SKRatio.Observation + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/FiniteChain/FieldSize.lean b/lean/OAI/Probability/SKRatio/FiniteChain/FieldSize.lean new file mode 100644 index 0000000000000000000000000000000000000000..ab0e86148713f8361df91aa86695290d81c2f0b8 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/FiniteChain/FieldSize.lean @@ -0,0 +1,78 @@ +import Mathlib +import OAI.Probability.SKRatio.Gaussian.PlantedEmpirical +import OAI.Probability.SKRatio.Quantization.BinStability + +namespace OAI + +noncomputable section +open scoped BigOperators NNReal ENNReal Topology +open MeasureTheory ProbabilityTheory Filter Real +namespace SKRatio.Planted +open SKRatioClock.Regression Bins +attribute [local instance] Classical.propDecidable +variable {n : ℕ} + +lemma augmentedAverage_gaussian (β : ℝ) : + HasGaussianLaw (fun g : (Fin n × Fin n) → ℝ => + (∑ i, augmentedField β g i)/(n:ℝ)) (standardArrayLaw (Fin n × Fin n)) := by + simpa only [smul_apply,ContinuousLinearMap.id_apply, + smul_eq_mul,inv_mul_eq_div] using + (augmentedField_gaussian (n := n) β).fun_sum.map_fun + ((n:ℝ)⁻¹ • ContinuousLinearMap.id ℝ ℝ) + +lemma augmentedAverage_hasLaw (hn : 0 (∑ i, augmentedField β g i)/(n:ℝ)) + (gaussianReal (β^2) (Real.toNNReal (2*β^2/(n:ℝ)))) + (standardArrayLaw (Fin n × Fin n)) := by + have hg := augmentedAverage_gaussian (n := n) β + have hLp (i : Fin n) := ((augmentedField_gaussian β).eval i).memLp_two + have hmean : (∫ g, (∑ i, augmentedField β g i)/(n:ℝ) + ∂standardArrayLaw (Fin n × Fin n))=β^2 := by + rw [integral_div,integral_finsetSum _ (fun i _ => ((augmentedField_gaussian β).eval i).integrable)] + simp only [augmentedField_mean hn,Finset.sum_const,Finset.card_univ,Fintype.card_fin,nsmul_eq_mul] + field_simp + have hvar : Var[(fun g => (∑ i, augmentedField β g i)/(n:ℝ)); + standardArrayLaw (Fin n × Fin n)] = 2*β^2/(n:ℝ) := by + rw [←covariance_self hg.aemeasurable,covariance_fun_div_left,covariance_fun_div_right, + covariance_fun_sum_fun_sum hLp hLp] + simp only [augmentedField_covariance hn,Finset.sum_add_distrib,Finset.sum_ite_eq, + Finset.mem_univ,ite_true,Finset.sum_const,Finset.card_univ,Fintype.card_fin,nsmul_eq_mul] + field_simp + ring + exact ⟨hg.aemeasurable,by rw [hg.map_eq_gaussianReal,hmean,hvar]⟩ + +theorem augmentedField_firstMoment (β : ℝ) (hβ : 0<β) : + ExponentialConvergence (fun n => standardArrayLaw (Fin n × Fin n)) + (fun n g => (∑ i, augmentedField β g i)/(n:ℝ)) (β^2) := by + intro ε hε + refine ⟨2,ε^2/(4*β^2),by norm_num,by positivity,?_⟩ + filter_upwards [eventually_gt_atTop 0] with n hn + have hnR : (0:ℝ) + (∑ i, augmentedField β g i)/(n:ℝ)-β^2) + (gaussianReal 0 (Real.toNNReal (2*β^2/(n:ℝ)))) + (standardArrayLaw (Fin n × Fin n)) := by + have h := gaussianReal_add_const (augmentedAverage_hasLaw hn β) (-(β^2 : ℝ)) + rw [add_neg_cancel] at h + simpa only [sub_eq_add_neg] using h + have ht := subgaussian_abs_tail (gaussian_hasSubgaussianMGF hc) ε hε.le + rw [Real.coe_toNNReal _ (by positivity : 0≤2*β^2/(n:ℝ))] at ht + have he : -ε^2/(2*(2*β^2/(n:ℝ)))=-(ε^2/(4*β^2))*(n:ℝ) := by field_simp; ring + rw [he,←ENNReal.ofReal_ofNat 2,←ENNReal.ofReal_mul (by norm_num)] at ht + exact ht + +lemma siteNorm_eq_sqrt (H : Fin n → ℝ) : + siteNorm H = sqrt ((∑ i, H i^2)/(n:ℝ)) := by + rw [←siteNorm_sq,sqrt_sq (siteNorm_nonneg H)] + +lemma augmentedField_siteNorm (β : ℝ) (hβ : 0<β) : + ExponentialConvergence (fun n => standardArrayLaw (Fin n × Fin n)) + (fun _ g => siteNorm (augmentedField β g)) (sqrt (β^2+β^4)) := by + simpa only [siteNorm_eq_sqrt] using + (augmentedField_secondMoment β hβ).continuous_map continuous_sqrt.continuousAt + +end SKRatio.Planted + +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/FiniteChain/Mean.lean b/lean/OAI/Probability/SKRatio/FiniteChain/Mean.lean new file mode 100644 index 0000000000000000000000000000000000000000..9f6890198a921625fc46c1fe41d081565af38f06 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/FiniteChain/Mean.lean @@ -0,0 +1,430 @@ +import Mathlib +import OAI.Probability.SKRatio.FiniteChain.Spin + +namespace OAI + +section +noncomputable section +open scoped BigOperators Topology Matrix +open MeasureTheory ProbabilityTheory Filter +noncomputable section +open scoped BigOperators Topology Matrix +open MeasureTheory ProbabilityTheory Filter +namespace SKRatio +namespace FiniteLaw +variable {α : Type*} [Fintype α] + +def mean (p : α → ℝ) (f : α → ℝ) : ℝ := ∑ x, p x * f x + +def variance (p : α → ℝ) (f : α → ℝ) : ℝ := + ∑ x, p x * (f x - mean p f) ^ 2 + +theorem variance_eq (p f : α → ℝ) (hp1 : ∑ x, p x = 1) : + variance p f = mean p (fun x => f x ^ 2) - mean p f ^ 2 := by + have h (x : α) : p x * (f x - mean p f) ^ 2 = + p x * f x ^ 2 - 2 * mean p f * (p x * f x) + mean p f ^ 2 * p x := by ring + simp only [variance, h, Finset.sum_add_distrib, Finset.sum_sub_distrib, + ← Finset.mul_sum, hp1, mul_one] + simp only [mean] + ring + +theorem common_mass (p q : α → ℝ) (hp1 : ∑ x, p x = 1) (hq1 : ∑ x, q x = 1) : + ∑ x, min (p x) (q x) = 1 - totalVariation p q := by + have h (x : α) : min (p x) (q x) = (p x + q x - |p x - q x|) / 2 := by + rcases le_total (p x) (q x) with h | h + · rw [min_eq_left h, abs_of_nonpos (sub_nonpos.mpr h)]; ring + · rw [min_eq_right h, abs_of_nonneg (sub_nonneg.mpr h)]; ring + simp only [h, ← Finset.sum_div, Finset.sum_sub_distrib, Finset.sum_add_distrib, hp1, hq1, + totalVariation] + ring + +theorem common_mass_square (p q f : α → ℝ) (hp : ∀ x, 0 ≤ p x) (hq : ∀ x, 0 ≤ q x) + (hp1 : ∑ x, p x = 1) (hq1 : ∑ x, q x = 1) : + (1 - totalVariation p q) * (mean p f - mean q f) ^ 2 ≤ + 2 * variance p f + 2 * variance q f := by + rw [← common_mass p q hp1 hq1, Finset.sum_mul] + calc + _ ≤ ∑ x, (2 * (p x * (f x - mean p f) ^ 2) + + 2 * (q x * (f x - mean q f) ^ 2)) := by + apply Finset.sum_le_sum + intro x _ + have hpoint : (mean p f - mean q f) ^ 2 ≤ + 2 * (f x - mean p f) ^ 2 + 2 * (f x - mean q f) ^ 2 := by nlinarith [sq_nonneg (2 * f x - mean p f - mean q f)] + have hmul := mul_le_mul_of_nonneg_left hpoint (le_min (hp x) (hq x)) + have hpbound := mul_le_mul_of_nonneg_right (min_le_left (p x) (q x)) (sq_nonneg (f x - mean p f)) + have hqbound := mul_le_mul_of_nonneg_right (min_le_right (p x) (q x)) (sq_nonneg (f x - mean q f)) + nlinarith only [hmul, hpbound, hqbound] + _ = _ := by simp only [Finset.sum_add_distrib, ← Finset.mul_sum, variance] + +theorem totalVariation_square (p q : α → ℝ) : + 4 * totalVariation p q ^ 2 ≤ (Fintype.card α : ℝ) * ∑ x, (p x - q x) ^ 2 := by + have h := Finset.sum_mul_sq_le_sq_mul_sq Finset.univ + (fun x : α => (1 : ℝ)) (fun x => |p x - q x|) + simp only [one_mul, one_pow, Finset.sum_const, Finset.card_univ, nsmul_eq_mul, mul_one, + sq_abs] at h + unfold totalVariation + nlinarith only [h] + +end FiniteLaw +namespace Independent +variable {n : ℕ} + +@[simp] theorem spinValue_sq (b : Bool) : spinValue b ^ 2 = 1 := by + cases b <;> norm_num [spinValue] + +@[simp] theorem spinValue_not (b : Bool) : spinValue (!b) = -spinValue b := by + cases b <;> norm_num [spinValue] + +@[simp] theorem coupling_zero (i j : Fin n) : coupling (0 : Disorder n) i j = 0 := by + simp [coupling] + +@[simp] theorem mass_zero (x : Spin n) : mass (0 : Disorder n) 0 x = 1 / (2 : ℝ) ^ n := by + simp [mass, weight, hamiltonian, partition, Spin] + +@[simp] theorem siteKernel_zero (i : Fin n) (x y : Spin n) : + siteKernel (0 : Disorder n) i x y = + (if y = x then 1 / 2 else 0) + (if y = flip i x then 1 / 2 else 0) := by + have h : (1 / (2 : ℝ) ^ n) / (1 / (2 : ℝ) ^ n + 1 / (2 : ℝ) ^ n) = 1 / 2 := by + field_simp + norm_num + simp only [siteKernel, mass_zero, h] + +def character (S : Finset (Fin n)) (x : Spin n) : ℝ := ∏ i ∈ S, spinValue (x i) + +@[simp] theorem character_empty (x : Spin n) : character ∅ x = 1 := by simp [character] + +@[simp] theorem character_sq (S : Finset (Fin n)) (x : Spin n) : character S x ^ 2 = 1 := by + simp only [character, ← Finset.prod_pow, spinValue_sq, Finset.prod_const_one] + +@[simp] theorem character_plus (S : Finset (Fin n)) : character S (fun _ => true) = 1 := by + simp [character, spinValue] + +@[simp] theorem character_flip (S : Finset (Fin n)) (i : Fin n) (x : Spin n) : + character S (flip i x) = if i ∈ S then -character S x else character S x := by + by_cases hi : i ∈ S + · simp only [ite_eq_left hi, character] + rw [← Finset.mul_prod_erase S _ hi, ← Finset.mul_prod_erase S (fun j => spinValue (x j)) hi] + simp only [flip_same, spinValue_not, neg_mul] + congr 2 + apply Finset.prod_congr rfl + intro j hj + rw [flip_other i j x (Finset.mem_erase.mp hj).1] + · simp only [ite_eq_right hi, character] + apply Finset.prod_congr rfl + intro j hj + rw [flip_other i j x (fun h => hi (h ▸ hj))] + +theorem character_complete (x y : Spin n) : + ∑ S : Finset (Fin n), character S x * character S y = + if x = y then (2 : ℝ) ^ n else 0 := by + have hxyp : ∑ S : Finset (Fin n), character S x * character S y = + ∏ i, (spinValue (x i) * spinValue (y i) + 1) := by + simp only [Fintype.prod_add, Finset.prod_const_one, mul_one, character, + Finset.prod_mul_distrib] + rw [hxyp] + by_cases hxy : x = y + · subst y + simp only [← sq, spinValue_sq] + norm_num + · simp only [ite_eq_right hxy] + obtain ⟨i, hi⟩ := Function.ne_iff.mp hxy + apply Finset.prod_eq_zero (Finset.mem_univ i) + cases hx : x i <;> cases hy : y i <;> simp_all [spinValue] + +def eigenvalue (S : Finset (Fin n)) : ℝ := 1 - (S.card : ℝ) / n + +theorem siteKernel_character (i : Fin n) (x : Spin n) (S : Finset (Fin n)) : + ∑ y, siteKernel (0 : Disorder n) i x y * character S y = + if i ∈ S then 0 else character S x := by + simp only [siteKernel_zero, add_mul, Finset.sum_add_distrib, ite_mul, + zero_mul, Finset.sum_ite_eq', Finset.mem_univ, ↓reduceIte, character_flip] + split_ifs <;> ring + +theorem transition_character (hn : 0 < n) (x : Spin n) (S : Finset (Fin n)) : + ∑ y, transition (0 : Disorder n) x y * character S y = eigenvalue S * character S x := by + simp only [transition, Nat.ne_of_gt hn, ↓reduceIte, div_mul_eq_mul_div, + ← Finset.sum_div, Finset.sum_mul] + rw [Finset.sum_comm] + simp only [siteKernel_character] + have hmem : ∑ i : Fin n, (if i ∈ S then 0 else character S x) = + (n : ℝ) * character S x - (S.card : ℝ) * character S x := by + have hf (i : Fin n) : (if i ∈ S then 0 else character S x) = + character S x - (if i ∈ S then character S x else 0) := by split_ifs <;> ring + simp only [hf, Finset.sum_sub_distrib, Finset.sum_ite_mem, Finset.univ_inter, + Finset.sum_const, Finset.card_univ, Fintype.card_fin, nsmul_eq_mul] + rw [hmem] + dsimp [eigenvalue] + field_simp + +theorem power_character (hn : 0 < n) (k : ℕ) (x : Spin n) (S : Finset (Fin n)) : + ∑ y, (transition (0 : Disorder n) ^ k) x y * character S y = + eigenvalue S ^ k * character S x := by + induction k generalizing x with + | zero => simp [Matrix.one_apply] + | succ k ih => + simp only [pow_succ, Matrix.mul_apply, Finset.sum_mul] + rw [Finset.sum_comm] + have he (z : Spin n) : ∑ y, (transition (0 : Disorder n) ^ k) x z * + transition 0 z y * character S y = + (transition (0 : Disorder n) ^ k) x z * (eigenvalue S * character S z) := by + simp only [mul_assoc, ← Finset.mul_sum, transition_character hn] + simp only [he] + rw [show (∑ z, (transition (0 : Disorder n) ^ k) x z * + (eigenvalue S * character S z)) = eigenvalue S * + ∑ z, (transition (0 : Disorder n) ^ k) x z * character S z from by + rw [Finset.mul_sum]; congr 1; funext z; ring] + rw [ih] + ring + +theorem return_probability (hn : 0 < n) (k : ℕ) (x : Spin n) : + (2 : ℝ) ^ n * (transition (0 : Disorder n) ^ k) x x = + ∑ S : Finset (Fin n), eigenvalue S ^ k := by + have H := congrArg (fun f : Finset (Fin n) → ℝ => ∑ S, f S * character S x) + (funext (power_character hn k x)) + simp only [Finset.sum_mul] at H + rw [Finset.sum_comm] at H + have hinn (y : Spin n) : ∑ S : Finset (Fin n), + (transition (0 : Disorder n) ^ k) x y * character S y * character S x = + (transition (0 : Disorder n) ^ k) x y * (if y = x then (2 : ℝ) ^ n else 0) := by + simp only [mul_assoc, ← Finset.mul_sum, character_complete] + simp only [hinn, mul_ite, mul_zero, Finset.sum_ite_eq', Finset.mem_univ, ↓reduceIte] at H + have hright (S : Finset (Fin n)) : eigenvalue S ^ k * character S x * character S x = + eigenvalue S ^ k := by rw [mul_assoc, ← sq, character_sq, mul_one] + simp only [hright] at H + simpa only [mul_comm] using H + +theorem transition_isSymm : (transition (0 : Disorder n)).IsSymm := by + have hsite (i : Fin n) (x y : Spin n) : siteKernel 0 i x y = siteKernel 0 i y x := by + have hb := siteKernel_balance (0 : Disorder n) i x y + simp only [mass_zero] at hb + exact mul_left_cancel₀ (one_div_ne_zero (pow_ne_zero n (by norm_num))) hb + change (transition (0 : Disorder n))ᵀ = transition 0 + by_cases hn : n = 0 + · simp [transition, hn] + · apply Matrix.ext + intro x y + change transition 0 y x = transition 0 x y + simp only [transition, hn, ↓reduceIte] + congr 1 + exact Finset.sum_congr rfl (fun i _ => hsite i y x) + +theorem eigenvalue_nonneg (hn : 0 < n) (S : Finset (Fin n)) : 0 ≤ eigenvalue S := by + have hc : (S.card : ℝ) ≤ n := by + exact_mod_cast (show S.card ≤ n from (Finset.card_le_univ _).trans_eq (Fintype.card_fin n)) + exact sub_nonneg.mpr ((div_le_one (Nat.cast_pos.mpr hn)).mpr hc) + +theorem eigenvalue_exp_bound (hn : 0 < n) (k : ℕ) (S : Finset (Fin n)) : + eigenvalue S ^ (2 * k) ≤ Real.exp (-2 * k / n) ^ S.card := by + have h := pow_le_pow_left₀ (eigenvalue_nonneg hn S) + (Real.one_sub_le_exp_neg ((S.card : ℝ) / n)) (2 * k) + apply h.trans_eq + rw [← Real.exp_nat_mul, ← Real.exp_nat_mul] + congr 1 + push_cast + ring + +theorem sum_eigenvalue_bound (hn : 0 < n) (k : ℕ) : + (∑ S : Finset (Fin n), eigenvalue S ^ (2 * k)) ≤ + Real.exp ((n : ℝ) * Real.exp (-2 * k / n)) := by + calc + _ ≤ ∑ S : Finset (Fin n), Real.exp (-2 * k / n) ^ S.card := + Finset.sum_le_sum (fun S _ => eigenvalue_exp_bound hn k S) + _ = (Real.exp (-2 * k / n) + 1) ^ n := by + have h := Fintype.prod_add (fun _ : Fin n => Real.exp (-2 * k / n)) (fun _ => (1 : ℝ)) + simpa using h.symm + _ ≤ Real.exp (Real.exp (-2 * k / n)) ^ n := + pow_le_pow_left₀ (by positivity) (Real.add_one_le_exp _) n + _ = _ := (Real.exp_nat_mul _ _).symm + +theorem row_square (hn : 0 < n) (k : ℕ) (x : Spin n) : + (2 : ℝ) ^ n * ∑ y, ((transition (0 : Disorder n) ^ k) x y) ^ 2 = + ∑ S : Finset (Fin n), eigenvalue S ^ (2 * k) := by + have hret := return_probability hn (2 * k) x + have h : (transition (0 : Disorder n) ^ (2 * k)) x x = + ∑ y, ((transition (0 : Disorder n) ^ k) x y) ^ 2 := by + rw [two_mul, pow_add, Matrix.mul_apply] + apply Finset.sum_congr rfl + intro y _ + rw [(transition_isSymm.pow k).apply x y, sq] + rwa [h] at hret + +theorem row_centered_square (hn : 0 < n) (k : ℕ) (x : Spin n) : + (2 : ℝ) ^ n * ∑ y, ((transition (0 : Disorder n) ^ k) x y - mass 0 0 y) ^ 2 = + (∑ S : Finset (Fin n), eigenvalue S ^ (2 * k)) - 1 := by + have hsum := Matrix.sum_row_of_mem_rowStochastic (transition_pow_stochastic (0 : Disorder n) k) x + have hcard : (Fintype.card (Spin n) : ℝ) = (2 : ℝ) ^ n := by simp [Spin] + calc + _ = (2 : ℝ) ^ n * ∑ y, ((transition (0 : Disorder n) ^ k) x y) ^ 2 - 1 := by + simp only [mass_zero, sub_sq, Finset.sum_add_distrib, Finset.sum_sub_distrib, + ← Finset.sum_mul, ← Finset.mul_sum, hsum, Finset.sum_const, Finset.card_univ, + nsmul_eq_mul, hcard] + field_simp + ring + _ = _ := by rw [row_square hn k x] + +theorem row_tv_square_upper (hn : 0 < n) (k : ℕ) (x : Spin n) : + 4 * totalVariation ((transition (0 : Disorder n) ^ k) x) (mass 0 0) ^ 2 ≤ + Real.exp ((n : ℝ) * Real.exp (-2 * k / n)) - 1 := by + have hc := FiniteLaw.totalVariation_square ((transition (0 : Disorder n) ^ k) x) (mass 0 0) + have hcard : (Fintype.card (Spin n) : ℝ) = (2 : ℝ) ^ n := by simp [Spin] + rw [hcard, row_centered_square hn k x] at hc + exact hc.trans (sub_le_sub_right (sum_eigenvalue_bound hn k) 1) + +theorem distance_upper (hn : 0 < n) (k : ℕ) {ε : ℝ} (hε : 0 ≤ ε) + (hbound : Real.exp ((n : ℝ) * Real.exp (-2 * k / n)) - 1 ≤ 4 * ε ^ 2) : + discreteDistance (0 : Disorder n) k ≤ ε := by + apply Finset.sup'_le + intro x _ + have htv := row_tv_square_upper hn k x + nlinarith only [htv, hbound, hε, + totalVariation_nonneg ((transition (0 : Disorder n) ^ k) x) (mass 0 0)] + +def flipEquiv (i : Fin n) : Spin n ≃ Spin n where + toFun := flip i + invFun := flip i + left_inv := flip_flip i + right_inv := flip_flip i + +theorem mean_character (S : Finset (Fin n)) (hS : S.Nonempty) : + FiniteLaw.mean (mass (0 : Disorder n) 0) (character S) = 0 := by + obtain ⟨i, hi⟩ := hS + have hs := Equiv.sum_comp (flipEquiv i) (character S) + change (∑ x : Spin n, character S (flip i x)) = ∑ x : Spin n, character S x at hs + simp only [character_flip, ite_eq_left hi, Finset.sum_neg_distrib] at hs + have hz : (∑ x : Spin n, character S x) = 0 := by linarith + simp only [FiniteLaw.mean, mass_zero, ← Finset.mul_sum, hz, mul_zero] + +@[simp] theorem character_singleton (i : Fin n) (x : Spin n) : + character {i} x = spinValue (x i) := by simp [character] + +theorem character_pair (i j : Fin n) (hij : i ≠ j) (x : Spin n) : + character {i, j} x = spinValue (x i) * spinValue (x j) := by + simp [character, hij] + +def magnetization (x : Spin n) : ℝ := ∑ i, spinValue (x i) + +theorem row_mean_spin (hn : 0 < n) (k : ℕ) (i : Fin n) : + FiniteLaw.mean ((transition (0 : Disorder n) ^ k) (fun _ => true)) + (fun x => spinValue (x i)) = (1 - 1 / (n : ℝ)) ^ k := by + simpa [FiniteLaw.mean, eigenvalue] using power_character hn k (fun _ => true) {i} + +theorem row_mean_pair (hn : 0 < n) (k : ℕ) (i j : Fin n) (hij : i ≠ j) : + FiniteLaw.mean ((transition (0 : Disorder n) ^ k) (fun _ => true)) + (fun x => spinValue (x i) * spinValue (x j)) = (1 - 2 / (n : ℝ)) ^ k := by + simpa [FiniteLaw.mean, character_pair i j hij, eigenvalue, hij, spinValue] using + power_character hn k (fun _ => true) {i, j} + +theorem equilibrium_mean_spin (i : Fin n) : + FiniteLaw.mean (mass (0 : Disorder n) 0) (fun x => spinValue (x i)) = 0 := by + simpa only [FiniteLaw.mean, character_singleton] using mean_character {i} (Finset.singleton_nonempty i) + +theorem equilibrium_mean_pair (i j : Fin n) (hij : i ≠ j) : + FiniteLaw.mean (mass (0 : Disorder n) 0) + (fun x => spinValue (x i) * spinValue (x j)) = 0 := by + simpa only [FiniteLaw.mean, character_pair i j hij] using mean_character {i, j} (by simp) + +theorem row_mean_magnetization (hn : 0 < n) (k : ℕ) : + FiniteLaw.mean ((transition (0 : Disorder n) ^ k) (fun _ => true)) magnetization = + (n : ℝ) * (1 - 1 / (n : ℝ)) ^ k := by + simp only [FiniteLaw.mean, magnetization, Finset.mul_sum] + rw [Finset.sum_comm] + change (∑ i : Fin n, FiniteLaw.mean ((transition (0 : Disorder n) ^ k) (fun _ => true)) + (fun x => spinValue (x i))) = _ + simp only [row_mean_spin hn, Finset.sum_const, Finset.card_univ, + Fintype.card_fin, nsmul_eq_mul] + +theorem equilibrium_mean_magnetization : + FiniteLaw.mean (mass (0 : Disorder n) 0) magnetization = 0 := by + simp only [FiniteLaw.mean, magnetization, Finset.mul_sum] + rw [Finset.sum_comm] + change (∑ i : Fin n, FiniteLaw.mean (mass (0 : Disorder n) 0) + (fun x => spinValue (x i))) = _ + simp only [equilibrium_mean_spin, Finset.sum_const_zero] + +theorem eigenvalue_two_le_square (hn : 2 ≤ n) (k : ℕ) : + (1 - 2 / (n : ℝ)) ^ k ≤ ((1 - 1 / (n : ℝ)) ^ k) ^ 2 := by + have hnR : (2 : ℝ) ≤ n := by exact_mod_cast hn + have hnpos : (0 : ℝ) < n := by linarith + have h0 : 0 ≤ 1 - 2 / (n : ℝ) := by + exact sub_nonneg.mpr ((div_le_one hnpos).mpr hnR) + have hb : 1 - 2 / (n : ℝ) ≤ (1 - 1 / (n : ℝ)) ^ 2 := by + rw [show (2 : ℝ) / n = 2 * (1 / (n : ℝ)) from by ring] + nlinarith [sq_nonneg (1 / (n : ℝ))] + simpa only [← pow_mul, mul_comm 2 k] using pow_le_pow_left₀ h0 hb k + +theorem row_variance_magnetization (hn : 2 ≤ n) (k : ℕ) : + FiniteLaw.variance ((transition (0 : Disorder n) ^ k) (fun _ => true)) magnetization ≤ n := by + have hnpos : 0 < n := lt_of_lt_of_le (by decide : 0 < 2) hn + let p := (transition (0 : Disorder n) ^ k) (fun _ => true) + let r := (1 - 1 / (n : ℝ)) ^ k + have hp1 : ∑ x, p x = 1 := + Matrix.sum_row_of_mem_rowStochastic (transition_pow_stochastic (0 : Disorder n) k) _ + have hpij (i j : Fin n) : + FiniteLaw.mean p (fun x => spinValue (x i) * spinValue (x j)) ≤ + (if j = i then 1 else 0) + r ^ 2 := by + by_cases hij : i = j + · subst j + simp only [← sq, spinValue_sq, FiniteLaw.mean, mul_one, hp1, ↓reduceIte] + linarith [sq_nonneg r] + · rw [ite_eq_right (Ne.symm hij)] + exact (row_mean_pair hnpos k i j hij).le.trans (by + simpa only [zero_add] using eigenvalue_two_le_square hn k) + have hexpand : FiniteLaw.mean p (fun x => magnetization x ^ 2) = + ∑ i, ∑ j, FiniteLaw.mean p (fun x => spinValue (x i) * spinValue (x j)) := by + simp only [FiniteLaw.mean, magnetization, sq, Finset.sum_mul, Finset.mul_sum] + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro i _ + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro j _ + apply Finset.sum_congr rfl + intro x _ + ring + have hsecond : FiniteLaw.mean p (fun x => magnetization x ^ 2) ≤ n + n ^ 2 * r ^ 2 := by + rw [hexpand] + calc + _ ≤ ∑ i : Fin n, ∑ j : Fin n, ((if j = i then (1 : ℝ) else 0) + r ^ 2) := + Finset.sum_le_sum (fun i _ => Finset.sum_le_sum (fun j _ => hpij i j)) + _ = _ := by + simp only [Finset.sum_add_distrib, Finset.sum_ite_eq', Finset.mem_univ, ↓reduceIte, + Finset.sum_const, Finset.card_univ, Fintype.card_fin, nsmul_eq_mul, mul_one] + ring + rw [FiniteLaw.variance_eq p _ hp1, row_mean_magnetization hnpos] + dsimp only [r] at hsecond + nlinarith only [hsecond] + +theorem equilibrium_variance_magnetization : + FiniteLaw.variance (mass (0 : Disorder n) 0) magnetization = n := by + have hpij (i j : Fin n) : + FiniteLaw.mean (mass (0 : Disorder n) 0) + (fun x => spinValue (x i) * spinValue (x j)) = if j = i then 1 else 0 := by + by_cases hij : i = j + · subst j + simp only [← sq, spinValue_sq, FiniteLaw.mean, mul_one, sum_mass, ↓reduceIte] + · rw [ite_eq_right (Ne.symm hij)] + exact equilibrium_mean_pair i j hij + have hexpand : FiniteLaw.mean (mass (0 : Disorder n) 0) (fun x => magnetization x ^ 2) = + ∑ i, ∑ j, FiniteLaw.mean (mass (0 : Disorder n) 0) + (fun x => spinValue (x i) * spinValue (x j)) := by + simp only [FiniteLaw.mean, magnetization, sq, Finset.sum_mul, Finset.mul_sum] + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro i _ + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro j _ + apply Finset.sum_congr rfl + intro x _ + ring + rw [FiniteLaw.variance_eq _ _ (sum_mass _ _), equilibrium_mean_magnetization, hexpand] + simp only [hpij, Finset.sum_ite_eq', Finset.mem_univ, ↓reduceIte, Finset.sum_const, + Finset.card_univ, Fintype.card_fin, nsmul_eq_mul, mul_one, zero_pow (by decide : 2 ≠ 0), sub_zero] + +end Independent +end SKRatio +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/FiniteChain/MeanMulVec.lean b/lean/OAI/Probability/SKRatio/FiniteChain/MeanMulVec.lean new file mode 100644 index 0000000000000000000000000000000000000000..43bb1078e6150f50c86d451ccc6a32d44698cb23 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/FiniteChain/MeanMulVec.lean @@ -0,0 +1,70 @@ +import Mathlib +import OAI.Probability.SKRatio.FiniteChain.VarianceNonneg + +namespace OAI + +section +noncomputable section +open scoped BigOperators Topology Matrix +open MeasureTheory ProbabilityTheory Filter +noncomputable section +open scoped BigOperators Topology Matrix +open MeasureTheory ProbabilityTheory Filter +noncomputable section +open scoped BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +noncomputable section +open scoped BigOperators Topology Matrix +open MeasureTheory ProbabilityTheory Filter +namespace SKRatio +namespace FiniteLaw +variable {α : Type*} [Fintype α] + +theorem mean_mulVec (p : α → ℝ) (A : Matrix α α ℝ) (f : α → ℝ) : + mean p (A *ᵥ f) = mean (p ᵥ* A) f := by + simp only [mean, Matrix.mulVec, Matrix.vecMul, dotProduct, Finset.mul_sum, Finset.sum_mul] + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro y _ + apply Finset.sum_congr rfl + intro x _ + ring + +end FiniteLaw + +theorem discreteDistance_smoothing {n : ℕ} (g : Disorder n) (k s : ℕ) + {ε V W : ℝ} (hε : 0 < ε) (hoverlap : discreteDistance g k ≤ 1 - ε) + (htransient : ∀ (x : Spin n) (f : Spin n → ℝ), (∀ y, |f y| ≤ 1) → + FiniteLaw.variance ((transition g ^ k) x) ((transition g ^ s) *ᵥ f) ≤ V) + (hequilibrium : ∀ f : Spin n → ℝ, (∀ y, |f y| ≤ 1) → + FiniteLaw.variance (mass g 0) ((transition g ^ s) *ᵥ f) ≤ W) : + discreteDistance g (k + s) ≤ (Real.sqrt V + Real.sqrt W) / (2 * Real.sqrt ε) := by + apply Finset.sup'_le + intro x _ + apply FiniteLaw.totalVariation_le_of_tests + intro f hf + have hP := transition_pow_stochastic g k + have hc := FiniteLaw.common_mass_means ((transition g ^ k) x) (mass g 0) + ((transition g ^ s) *ᵥ f) (hP.1 x) (mass_nonneg g 0) + (Matrix.sum_row_of_mem_rowStochastic hP x) (sum_mass g 0) hε + ((tv_le_discreteDistance g k x).trans hoverlap) + rw [FiniteLaw.mean_mulVec, FiniteLaw.mean_mulVec, transition_pow_stationary] at hc + rw [pow_add, Matrix.mul_apply_eq_vecMul] + calc + _ ≤ (Real.sqrt (FiniteLaw.variance ((transition g ^ k) x) ((transition g ^ s) *ᵥ f)) + + Real.sqrt (FiniteLaw.variance (mass g 0) ((transition g ^ s) *ᵥ f))) / Real.sqrt ε := hc + _ ≤ (Real.sqrt V + Real.sqrt W) / Real.sqrt ε := by + apply div_le_div_of_nonneg_right _ (Real.sqrt_nonneg _) + exact add_le_add (Real.sqrt_le_sqrt (htransient x f hf)) + (Real.sqrt_le_sqrt (hequilibrium f hf)) + _ = _ := by ring + +end SKRatio + +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/FiniteChain/RatioProbabilityUniformBounds.lean b/lean/OAI/Probability/SKRatio/FiniteChain/RatioProbabilityUniformBounds.lean new file mode 100644 index 0000000000000000000000000000000000000000..b37ced65be0fd01bc10cfcdc9fb2046aa39ee8a8 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/FiniteChain/RatioProbabilityUniformBounds.lean @@ -0,0 +1,65 @@ +import Mathlib +import OAI.Probability.SKRatio.FiniteChain.DiscreteDistanceNonneg + +namespace OAI + +section +noncomputable section +open scoped BigOperators Topology Matrix +open MeasureTheory ProbabilityTheory Filter +noncomputable section +open scoped BigOperators Topology Matrix +open MeasureTheory ProbabilityTheory Filter +noncomputable section +open scoped BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +namespace SKRatio + +theorem ratio_probability_zero_of_uniform_bounds + (law : (n : ℕ) → Measure (Disorder n)) + (G : (n : ℕ) → Set (Disorder n)) (T : (n : ℕ) → Disorder n → ℝ) + {ε η b : ℝ} (hε0 : 0 < ε) (hε1 : ε < 1) (hb0 : 0 < b) (hb1 : b < 1) + (hbase : (1 + b) / (1 - b) < 1 + η) + (hG : Tendsto (fun n => law n (G n)ᶜ) atTop (𝓝 0)) + (hscale : ∀ A : ℝ, ∀ᶠ n : ℕ in atTop, ∀ g ∈ G n, A ≤ T n g) + (hlower : ∀ᶠ n : ℕ in atTop, ∀ g ∈ G n, + 1 - ε < discreteDistance g ⌊(1 - b) * T n g⌋₊) + (hupper : ∀ᶠ n : ℕ in atTop, ∀ g ∈ G n, + discreteDistance g ⌈(1 + b) * T n g⌉₊ ≤ ε) : + Tendsto (fun n => law n + {g : Disorder n | 1 + η < (mixingTime g ε : ℝ) / (mixingTime g (1 - ε) : ℝ)}) + atTop (𝓝 0) := by + have hrem : Tendsto (fun t : ℝ => 1 / ((1 - b) * t)) atTop (𝓝 0) := by + simpa only [one_div, Function.comp_def, id_eq] using + tendsto_inv_atTop_zero.comp (tendsto_id.const_mul_atTop (sub_pos.mpr hb1)) + have htail : ∀ᶠ t : ℝ in atTop, + 0 < t ∧ (1 + b) / (1 - b) + 1 / ((1 - b) * t) ≤ 1 + η := by + filter_upwards [eventually_gt_atTop 0, hrem.eventually (gt_mem_nhds (sub_pos.mpr hbase))] + with t ht hr + exact ⟨ht, by linarith only [hr]⟩ + obtain ⟨A, hA⟩ := eventually_atTop.mp htail + have hsub : ∀ᶠ n : ℕ in atTop, + {g : Disorder n | 1 + η < (mixingTime g ε : ℝ) / (mixingTime g (1 - ε) : ℝ)} ⊆ + (G n)ᶜ := by + filter_upwards [hscale A, hlower, hupper] with n hs hl hu + intro g hg hgG + obtain ⟨hT, htail⟩ := hA (T n g) (hs g hgG) + have hratio := mixing_ratio_bound g hε0 hε1 hb0 hb1 hT (hl g hgG) (hu g hgG) + exact not_lt_of_ge (hratio.trans htail) hg + apply tendsto_of_tendsto_of_tendsto_of_le_of_le' tendsto_const_nhds hG + · exact Eventually.of_forall (fun n => by positivity) + · exact hsub.mono (fun n hn => measure_mono hn) + +end SKRatio + +noncomputable section +open scoped BigOperators Topology Matrix +open MeasureTheory ProbabilityTheory Filter + +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/FiniteChain/ResidualBounds.lean b/lean/OAI/Probability/SKRatio/FiniteChain/ResidualBounds.lean new file mode 100644 index 0000000000000000000000000000000000000000..87bfdc2fb1b88a6d4dac52874a2545bc66c4b1c5 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/FiniteChain/ResidualBounds.lean @@ -0,0 +1,90 @@ +import Mathlib +import OAI.Probability.SKRatio.Quantization.BinStability +import OAI.Probability.SKRatio.Variational.ScalarHilbert + +namespace OAI + +noncomputable section +open scoped BigOperators Matrix +open MeasureTheory ProbabilityTheory Filter Real +namespace SKRatio.Planted +open Bins Scalar SKRatioClock.Regression MatrixNet Calculus +attribute [local instance] Classical.propDecidable +variable {n : ℕ} + +lemma fieldProjection_opNorm_le_one (hn : 0 β^2/(n:ℝ)) ≤ β^2 := by + apply matrix_opNorm_le_schur _ _ (sq_nonneg β) + all_goals + intro i + have hn : 0 β^2/(n:ℝ)) := by + ext i j + have hc := congrFun (congrFun (coupling_augmentedDisorder β g) i) j + change coupling (augmentedDisorder β g) i j = augmented β g i j- + Matrix.diagonal (augmentedDiagonal β g) i j at hc + change β*goe g i j = coupling (augmentedDisorder β g) i j+ + Matrix.diagonal (augmentedDiagonal β g) i j-β^2/(n:ℝ) + rw [hc] + change β*goe g i j = (β*goe g i j+β^2/(n:ℝ)-_)+_-β^2/(n:ℝ) + ring + unfold euclideanOpNorm + rw [he,map_sub,map_add] + apply (norm_sub_le _ _).trans + exact (add_le_add (norm_add_le _ _) le_rfl).trans + (add_le_add (add_le_add le_rfl (matrix_diagonal_opNorm_le _ D hD hd)) (fullMean_opNorm_le β)) + +theorem residual_norm_rare {β : ℝ} (hβ : 0<β) : + ExponentiallyRare (fun n => standardArrayLaw (Fin n × Fin n)) + (fun n => {g | 2*β+2*β^2+2 < + euclideanOpNorm (fieldProjection n*(β • goe g)*fieldProjection n)}) := by + apply ((augmented_norm_rare hβ (by norm_num : (0:ℝ)<1)).union + (augmented_diagonal_rare β (by norm_num : (0:ℝ)<1))).mono + filter_upwards [eventually_gt_atTop 0] with n hn + intro g hg + by_contra h + have hnot := not_or.mp h + have hnorm : euclideanOpNorm (coupling (augmentedDisorder β g)) ≤ 2*β+β^2+1 := not_lt.mp hnot.1 + have hdiag : ∀ i : Fin n, |augmentedDiagonal β g i| ≤ 1 := by + intro i + exact not_lt.mp (fun hi => hnot.2 ⟨i,hi⟩) + have hr := (projected_opNorm_le hn (β • goe g)).trans + (centered_augmented_opNorm_le β g (by norm_num) hdiag) + change 2*β+2*β^2+2 < _ at hg + linarith only [hg,hr,hnorm] + +end SKRatio.Planted + +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/FiniteChain/Spin.lean b/lean/OAI/Probability/SKRatio/FiniteChain/Spin.lean new file mode 100644 index 0000000000000000000000000000000000000000..04d0c5f711ca7bb59adb5a1fa316144f9bb4caa5 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/FiniteChain/Spin.lean @@ -0,0 +1,399 @@ +import Mathlib + +namespace OAI + +section +noncomputable section +open scoped BigOperators Topology Matrix +open MeasureTheory ProbabilityTheory Filter + +namespace SKRatio + +abbrev Spin (n : ℕ) := Fin n → Bool +abbrev Edge (n : ℕ) := {p : Fin n × Fin n // p.1 < p.2} +abbrev Disorder (n : ℕ) := Edge n → ℝ + +def spinValue (b : Bool) : ℝ := if b then 1 else -1 + +def coupling {n : ℕ} (g : Disorder n) (i j : Fin n) : ℝ := + if h : i < j then g ⟨(i, j), h⟩ else + if h : j < i then g ⟨(j, i), h⟩ else 0 + +def hamiltonian {n : ℕ} (g : Disorder n) (h : Fin n → ℝ) (x : Spin n) : ℝ := + (1 / 2 : ℝ) * ∑ i, ∑ j, spinValue (x i) * coupling g i j * spinValue (x j) + + ∑ i, h i * spinValue (x i) + +def weight {n : ℕ} (g : Disorder n) (h : Fin n → ℝ) (x : Spin n) : ℝ := + Real.exp (hamiltonian g h x) + +def partition {n : ℕ} (g : Disorder n) (h : Fin n → ℝ) : ℝ := + ∑ x, weight g h x + +def mass {n : ℕ} (g : Disorder n) (h : Fin n → ℝ) (x : Spin n) : ℝ := + weight g h x / partition g h + +def flip {n : ℕ} (i : Fin n) (x : Spin n) : Spin n := + Function.update x i (!(x i)) + +def disorderLaw (β : ℝ) (n : ℕ) : Measure (Disorder n) := + Measure.pi (fun _ : Edge n => gaussianReal 0 (Real.toNNReal (β ^ 2 / n))) + +def siteKernel {n : ℕ} (g : Disorder n) (i : Fin n) : + Matrix (Spin n) (Spin n) ℝ := fun x y => + (if y = x then mass g 0 x / (mass g 0 x + mass g 0 (flip i x)) else 0) + + (if y = flip i x then + mass g 0 (flip i x) / (mass g 0 x + mass g 0 (flip i x)) else 0) + +def transition {n : ℕ} (g : Disorder n) : Matrix (Spin n) (Spin n) ℝ := + if n = 0 then 1 else fun x y => (∑ i, siteKernel g i x y) / (n : ℝ) + +def totalVariation {α : Type*} [Fintype α] (p q : α → ℝ) : ℝ := + (1 / 2 : ℝ) * ∑ y, |p y - q y| + +def discreteDistance {n : ℕ} (g : Disorder n) (k : ℕ) : ℝ := + Finset.univ.sup' Finset.univ_nonempty + (fun x : Spin n => totalVariation ((transition g ^ k) x) (mass g 0)) + +def mixingTime {n : ℕ} (g : Disorder n) (ε : ℝ) : ℕ := + sInf {k : ℕ | discreteDistance g k ≤ ε} + +section ElementaryGibbs +variable {n : ℕ} + +@[simp] theorem coupling_diag (g : Disorder n) (i : Fin n) : coupling g i i = 0 := by + simp [coupling] + +theorem coupling_symm (g : Disorder n) (i j : Fin n) : coupling g i j = coupling g j i := by + rcases lt_trichotomy i j with hij | rfl | hji + · simp [coupling, hij, not_lt_of_gt hij] + · rfl + · simp [coupling, hji, not_lt_of_gt hji] + +@[simp] theorem flip_same (i : Fin n) (x : Spin n) : flip i x i = !(x i) := by + simp [flip] + +@[simp] theorem flip_other (i j : Fin n) (x : Spin n) (h : j ≠ i) : flip i x j = x j := by + simp [flip, h] + +@[simp] theorem flip_flip (i : Fin n) (x : Spin n) : flip i (flip i x) = x := by + ext j + by_cases h : j = i + · subst j; simp + · simp [flip_other, h] + +@[simp] theorem flip_ne (i : Fin n) (x : Spin n) : flip i x ≠ x := by + intro h + have hi := congrFun h i + simp at hi + +theorem weight_pos (g : Disorder n) (h : Fin n → ℝ) (x : Spin n) : + 0 < weight g h x := Real.exp_pos _ + +theorem partition_pos (g : Disorder n) (h : Fin n → ℝ) : 0 < partition g h := by + exact Finset.sum_pos (fun x _ => weight_pos g h x) Finset.univ_nonempty + +theorem mass_pos (g : Disorder n) (h : Fin n → ℝ) (x : Spin n) : + 0 < mass g h x := div_pos (weight_pos g h x) (partition_pos g h) + +theorem mass_nonneg (g : Disorder n) (h : Fin n → ℝ) (x : Spin n) : + 0 ≤ mass g h x := (mass_pos g h x).le + +@[simp] theorem sum_mass (g : Disorder n) (h : Fin n → ℝ) : ∑ x, mass g h x = 1 := by + simp only [mass, ← Finset.sum_div] + exact div_self (ne_of_gt (partition_pos g h)) + +theorem mass_le_one (g : Disorder n) (h : Fin n → ℝ) (x : Spin n) : + mass g h x ≤ 1 := by + calc + mass g h x ≤ ∑ y, mass g h y := + Finset.single_le_sum (fun y _ => mass_nonneg g h y) (Finset.mem_univ x) + _ = 1 := sum_mass g h + +instance disorderLaw_probability (β : ℝ) (n : ℕ) : IsProbabilityMeasure (disorderLaw β n) := by + unfold disorderLaw + infer_instance + +end ElementaryGibbs + +section HeatBath +variable {n : ℕ} + +theorem siteKernel_nonneg (g : Disorder n) (i : Fin n) (x y : Spin n) : + 0 ≤ siteKernel g i x y := by + unfold siteKernel + have hx := mass_nonneg g 0 x + have hf := mass_nonneg g 0 (flip i x) + positivity + +@[simp] theorem sum_siteKernel (g : Disorder n) (i : Fin n) (x : Spin n) : + ∑ y, siteKernel g i x y = 1 := by + have hd : mass g 0 x + mass g 0 (flip i x) ≠ 0 := + ne_of_gt (add_pos (mass_pos g 0 x) (mass_pos g 0 (flip i x))) + simp only [siteKernel, Finset.sum_add_distrib, Finset.sum_ite_eq', Finset.mem_univ, + ite_true] + rw [← add_div, div_self hd] + +theorem siteKernel_balance (g : Disorder n) (i : Fin n) (x y : Spin n) : + mass g 0 x * siteKernel g i x y = mass g 0 y * siteKernel g i y x := by + by_cases hxy : y = x + · subst y; rfl + by_cases hflip : y = flip i x + · subst y + simp only [siteKernel, flip_ne, Ne.symm (flip_ne i x), ↓reduceIte, flip_flip, + zero_add] + rw [add_comm (mass g 0 (flip i x)) (mass g 0 x)] + ring + · have hyx : x ≠ y := Ne.symm hxy + have hflip' : x ≠ flip i y := by + intro h + apply hflip + rw [h, flip_flip] + simp [siteKernel, hxy, hflip, hyx, hflip'] + +theorem siteKernel_stationary (g : Disorder n) (i : Fin n) (y : Spin n) : + ∑ x, mass g 0 x * siteKernel g i x y = mass g 0 y := by + simp_rw [siteKernel_balance g i _ y] + rw [← Finset.mul_sum, sum_siteKernel, mul_one] + +theorem transition_stochastic (g : Disorder n) : + transition g ∈ Matrix.rowStochastic ℝ (Spin n) := by + by_cases hn : n = 0 + · simp only [transition, hn, ↓reduceIte] + exact (Matrix.rowStochastic ℝ (Spin n)).one_mem + · rw [Matrix.mem_rowStochastic_iff_sum] + simp only [transition, hn, ↓reduceIte] + constructor + · intro x y + exact div_nonneg (Finset.sum_nonneg (fun i _ => siteKernel_nonneg g i x y)) + (Nat.cast_nonneg n) + · intro x + rw [← Finset.sum_div, Finset.sum_comm] + simp [Nat.cast_ne_zero.mpr hn] + +theorem transition_nonneg (g : Disorder n) (x y : Spin n) : + 0 ≤ transition g x y := (transition_stochastic g).1 x y + +theorem transition_stationary (g : Disorder n) : + (mass g 0) ᵥ* transition g = mass g 0 := by + by_cases hn : n = 0 + · simp [transition, hn] + · ext y + simp only [Matrix.vecMul, dotProduct, transition, hn, ↓reduceIte, + mul_div, ← Finset.sum_div, Finset.mul_sum] + rw [Finset.sum_comm] + simp [siteKernel_stationary, Nat.cast_ne_zero.mpr hn] + +theorem transition_pow_stochastic (g : Disorder n) (k : ℕ) : + transition g ^ k ∈ Matrix.rowStochastic ℝ (Spin n) := + (Matrix.rowStochastic ℝ (Spin n)).pow_mem (transition_stochastic g) k + +theorem transition_pow_stationary (g : Disorder n) (k : ℕ) : + (mass g 0) ᵥ* (transition g ^ k) = mass g 0 := by + induction k with + | zero => simp + | succ k ih => rw [pow_succ, ← Matrix.vecMul_vecMul, ih, transition_stationary] + +theorem siteKernel_update_pos (g : Disorder n) (i : Fin n) (x : Spin n) (b : Bool) : + 0 < siteKernel g i x (Function.update x i b) := by + by_cases hb : b = x i + · subst b + simp only [Function.update_eq_self, siteKernel, Ne.symm (flip_ne i x), + ↓reduceIte, add_zero] + exact div_pos (mass_pos g 0 x) (add_pos (mass_pos g 0 x) (mass_pos g 0 (flip i x))) + · have hb' : b = !(x i) := by cases b <;> cases h : x i <;> simp_all + subst b + change 0 < siteKernel g i x (flip i x) + simp only [siteKernel, flip_ne, ↓reduceIte, zero_add] + exact div_pos (mass_pos g 0 (flip i x)) + (add_pos (mass_pos g 0 x) (mass_pos g 0 (flip i x))) + +theorem transition_update_pos (g : Disorder n) (i : Fin n) (x : Spin n) (b : Bool) : + 0 < transition g x (Function.update x i b) := by + have hn : n ≠ 0 := ne_of_gt (Nat.zero_lt_of_lt i.isLt) + simp only [transition, hn, ↓reduceIte] + apply div_pos _ (Nat.cast_pos.mpr (Nat.pos_of_ne_zero hn)) + exact (siteKernel_update_pos g i x b).trans_le + (Finset.single_le_sum (fun j _ => siteKernel_nonneg g j x _) (Finset.mem_univ i)) + +def updatePath (x y : Spin n) (k : ℕ) : Spin n := + fun i => if (i : ℕ) < k then y i else x i + +@[simp] theorem updatePath_zero (x y : Spin n) : updatePath x y 0 = x := by + ext i; simp [updatePath] + +@[simp] theorem updatePath_end (x y : Spin n) : updatePath x y n = y := by + ext i; simp [updatePath] + +theorem updatePath_succ (x y : Spin n) (k : ℕ) (hk : k < n) : + updatePath x y (k + 1) = + Function.update (updatePath x y k) ⟨k, hk⟩ (y ⟨k, hk⟩) := by + ext i + by_cases hi : i = ⟨k, hk⟩ + · subst i + simp [updatePath] + · have hval : (i : ℕ) ≠ k := fun h => hi (Fin.ext h) + have hlt : (i : ℕ) < k + 1 ↔ (i : ℕ) < k := by omega + simp [Function.update_of_ne hi, updatePath, hlt] + +theorem transition_n_pos (g : Disorder n) (x y : Spin n) : + 0 < (transition g ^ n) x y := by + have path_pos (k : ℕ) (hk : k ≤ n) : + 0 < (transition g ^ k) x (updatePath x y k) := by + induction k with + | zero => simp + | succ k ih => + have hkn : k < n := by omega + have hprev := ih (by omega) + rw [pow_succ, Matrix.mul_apply] + have hlast : 0 < transition g (updatePath x y k) (updatePath x y (k + 1)) := by + rw [updatePath_succ x y k hkn] + exact transition_update_pos g ⟨k, hkn⟩ _ _ + exact (mul_pos hprev hlast).trans_le + (Finset.single_le_sum + (fun z _ => mul_nonneg ((transition_pow_stochastic g k).1 x z) + (transition_nonneg g z _)) (Finset.mem_univ _)) + simpa using path_pos n le_rfl + +end HeatBath + +section FiniteTV +variable {α : Type*} [Fintype α] + +theorem totalVariation_nonneg (p q : α → ℝ) : 0 ≤ totalVariation p q := by + unfold totalVariation + positivity + +theorem totalVariation_le_one (p q : α → ℝ) + (hp : ∀ x, 0 ≤ p x) (hq : ∀ x, 0 ≤ q x) + (hp1 : ∑ x, p x = 1) (hq1 : ∑ x, q x = 1) : + totalVariation p q ≤ 1 := by + calc + totalVariation p q ≤ (1 / 2 : ℝ) * ∑ x, (p x + q x) := by + apply mul_le_mul_of_nonneg_left (Finset.sum_le_sum (fun x _ => ?_)) (by norm_num) + simpa [abs_of_nonneg (hp x), abs_of_nonneg (hq x)] using abs_sub (p x) (q x) + _ = 1 := by rw [Finset.sum_add_distrib, hp1, hq1]; norm_num + +variable [DecidableEq α] + +theorem totalVariation_dirac (q : α → ℝ) (hq : ∀ x, 0 ≤ q x) + (hq1 : ∑ x, q x = 1) (x : α) : + totalVariation ((1 : Matrix α α ℝ) x) q = 1 - q x := by + have hqx : q x ≤ 1 := by + rw [← hq1] + exact Finset.single_le_sum (fun y _ => hq y) (Finset.mem_univ x) + have summand (y : α) : + |(1 : Matrix α α ℝ) x y - q y| = q y + if y = x then 1 - 2 * q x else 0 := by + by_cases h : y = x + · subst y + simp only [Matrix.one_apply_eq, ↓reduceIte, abs_of_nonneg (sub_nonneg.mpr hqx)] + ring + · simp [Matrix.one_apply_ne (Ne.symm h), h, abs_of_nonneg (hq y)] + simp only [totalVariation, summand, Finset.sum_add_distrib, hq1, + Finset.sum_ite_eq', Finset.mem_univ, ↓reduceIte] + ring + +theorem totalVariation_minorization (A : Matrix α α ℝ) + (hA : A ∈ Matrix.rowStochastic ℝ α) (p q : α → ℝ) + (hpq : ∑ x, p x = ∑ x, q x) (c : ℝ) (hc : ∀ x y, c ≤ A x y) : + totalVariation (p ᵥ* A) (q ᵥ* A) ≤ + (1 - (Fintype.card α : ℝ) * c) * totalVariation p q := by + have hdiff (y : α) : (p ᵥ* A) y - (q ᵥ* A) y = + ∑ x, (p x - q x) * (A x y - c) := by + simp only [Matrix.vecMul, dotProduct, mul_sub, sub_mul, Finset.sum_sub_distrib, + ← Finset.sum_mul, hpq] + ring + have hrow (x : α) : ∑ y, (A x y - c) = 1 - (Fintype.card α : ℝ) * c := by + simp only [Finset.sum_sub_distrib, Matrix.sum_row_of_mem_rowStochastic hA, + Finset.sum_const, Finset.card_univ, nsmul_eq_mul] + have habs (y : α) : |(p ᵥ* A) y - (q ᵥ* A) y| ≤ + ∑ x, |p x - q x| * (A x y - c) := by + rw [hdiff] + calc + |∑ x, (p x - q x) * (A x y - c)| ≤ ∑ x, |(p x - q x) * (A x y - c)| := + Finset.abs_sum_le_sum_abs _ _ + _ = _ := Finset.sum_congr rfl (fun x _ => by + rw [abs_mul, abs_of_nonneg (sub_nonneg.mpr (hc x y))]) + calc + totalVariation (p ᵥ* A) (q ᵥ* A) ≤ + (1 / 2 : ℝ) * ∑ y, ∑ x, |p x - q x| * (A x y - c) := by + exact mul_le_mul_of_nonneg_left (Finset.sum_le_sum (fun y _ => habs y)) (by norm_num) + _ = (1 / 2 : ℝ) * ∑ x, + |p x - q x| * (1 - (Fintype.card α : ℝ) * c) := by + rw [Finset.sum_comm] + simp only [← Finset.mul_sum, hrow] + _ = (1 - (Fintype.card α : ℝ) * c) * totalVariation p q := by + rw [← Finset.sum_mul] + unfold totalVariation + ring + +theorem totalVariation_contract (A : Matrix α α ℝ) + (hA : A ∈ Matrix.rowStochastic ℝ α) (p q : α → ℝ) + (hpq : ∑ x, p x = ∑ x, q x) : + totalVariation (p ᵥ* A) (q ᵥ* A) ≤ totalVariation p q := by + simpa using totalVariation_minorization A hA p q hpq 0 hA.1 + +theorem exists_geometric_block_bound [Nonempty α] (A : Matrix α α ℝ) + (hA : A ∈ Matrix.rowStochastic ℝ α) (π : α → ℝ) + (hπ : ∀ x, 0 ≤ π x) (hπ1 : ∑ x, π x = 1) + (m : ℕ) (hm : ∀ x y, 0 < (A ^ m) x y) (hstation : π ᵥ* (A ^ m) = π) : + ∃ r : ℝ, 0 ≤ r ∧ r < 1 ∧ + ∀ k : ℕ, ∀ x, totalVariation ((A ^ (m * k)) x) π ≤ r ^ k := by + classical + let c : ℝ := Finset.univ.inf' Finset.univ_nonempty + (fun xy : α × α => (A ^ m) xy.1 xy.2) + have hc : 0 < c := (Finset.lt_inf'_iff _).mpr (fun xy _ => hm xy.1 xy.2) + have hcA (x y : α) : c ≤ (A ^ m) x y := + Finset.inf'_le _ (Finset.mem_univ (x, y)) + have hAm := (Matrix.rowStochastic ℝ α).pow_mem hA m + let r : ℝ := 1 - (Fintype.card α : ℝ) * c + have hr0 : 0 ≤ r := by + have H : (Fintype.card α : ℝ) * c ≤ 1 := by + calc + (Fintype.card α : ℝ) * c = ∑ _y : α, c := by simp + _ ≤ ∑ y, (A ^ m) (Classical.arbitrary α) y := Finset.sum_le_sum (fun y _ => hcA _ y) + _ = 1 := Matrix.sum_row_of_mem_rowStochastic hAm _ + exact sub_nonneg.mpr H + have hr1 : r < 1 := by + have hcard : (0 : ℝ) < Fintype.card α := Nat.cast_pos.mpr Fintype.card_pos + dsimp [r] + linarith [mul_pos hcard hc] + refine ⟨r, hr0, hr1, ?_⟩ + intro k + induction k with + | zero => + intro x + simp only [Nat.mul_zero, pow_zero] + have hI := (Matrix.rowStochastic ℝ α).one_mem + exact totalVariation_le_one _ _ (hI.1 x) hπ + (Matrix.sum_row_of_mem_rowStochastic hI x) hπ1 + | succ k ih => + intro x + rw [Nat.mul_succ, pow_add, Matrix.mul_apply_eq_vecMul] + have hAk := (Matrix.rowStochastic ℝ α).pow_mem hA (m * k) + have hequal : (∑ y, (A ^ (m * k)) x y) = ∑ y, π y := by + rw [Matrix.sum_row_of_mem_rowStochastic hAk, hπ1] + calc + totalVariation ((A ^ (m * k)) x ᵥ* (A ^ m)) π = + totalVariation ((A ^ (m * k)) x ᵥ* (A ^ m)) (π ᵥ* (A ^ m)) := by rw [hstation] + _ ≤ r * totalVariation ((A ^ (m * k)) x) π := + totalVariation_minorization (A ^ m) hAm _ _ hequal c hcA + _ ≤ r * r ^ k := mul_le_mul_of_nonneg_left (ih x) hr0 + _ = r ^ (k + 1) := by rw [pow_succ, mul_comm] + +end FiniteTV + +section MixingTime +variable {n : ℕ} + +theorem tv_le_discreteDistance (g : Disorder n) (k : ℕ) (x : Spin n) : + totalVariation ((transition g ^ k) x) (mass g 0) ≤ discreteDistance g k := by + unfold discreteDistance + exact Finset.le_sup' (fun z : Spin n => totalVariation ((transition g ^ k) z) (mass g 0)) + (Finset.mem_univ x) + +end MixingTime +end SKRatio +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/FiniteChain/StaticReduction.lean b/lean/OAI/Probability/SKRatio/FiniteChain/StaticReduction.lean new file mode 100644 index 0000000000000000000000000000000000000000..65a4a4f11bcb60ae6c0dae31e25ec4eaf43ca9ec --- /dev/null +++ b/lean/OAI/Probability/SKRatio/FiniteChain/StaticReduction.lean @@ -0,0 +1,77 @@ +import Mathlib +import OAI.Probability.SKRatio.Dynamics.Assembly +import OAI.Probability.SKRatio.Entropy.BadAvoidance + +namespace OAI + +section +noncomputable section +open scoped BigOperators Topology Matrix +open MeasureTheory Filter +namespace SKRatio.Calculus +attribute [local instance] Classical.propDecidable + +theorem ratio_cutoff_of_static_inputs (β ε η : ℝ) + (hε : 0 < ε) (hε1 : ε < 1) (hη : 0 < η) + (G : ∀ n : ℕ, Set (Disorder n)) + (bad : ∀ n, Disorder n → Set (Spin n)) {κ A χ γ K : ℝ} + (hκ : 0 < κ) (hA : 0 ≤ A) (hχ : 0 < χ) (hγ : 0 < γ) (hK : 0 < K) + (hG : Tendsto (fun n => disorderLaw β n (G n)ᶜ) atTop (𝓝 0)) + (hnorm : ∀ n, ∀ g ∈ G n, euclideanOpNorm (coupling g) ≤ K) + (hgap : ∀ n, ∀ g ∈ G n, ∀ f : Observables n, + γ*FiniteLaw.variance (mass g 0) f ≤ stationaryEnergy g f) + (hmlsi : ∀ n, ∀ g ∈ G n, ∀ F : Observables n, + (∀ y, 0 < F y) → FiniteLaw.mean (mass g 0) F = 1 → + χ*FiniteLaw.entropy (mass g 0) F ≤ + -stationaryInner g (generator (coupling g) F) (fun y => Real.log (F y))) + (hsmall : ∀ n, ∀ g ∈ G n, FiniteLaw.mean (mass g 0) + (fun y => if y ∈ bad n g then 1 else 0) ≤ Real.exp (-κ*n)) + (hgradient : ∀ n, ∀ g ∈ G n, ∀ f : Observables n, ∀ y, + (∑ i, 2*halfDiff i f y*halfDiff i (generator (coupling g) f) y) - + generator (coupling g) (unweightedGradient f) y ≤ + (-κ + if y ∈ bad n g then A else 0)*unweightedGradient f y) : + Tendsto + (fun n : ℕ => disorderLaw β n + {g : Disorder n | 1+η < + (mixingTime g ε : ℝ)/(mixingTime g (1-ε) : ℝ)}) + atTop (𝓝 0) ∧ + (∀ᶠ n : ℕ in atTop, ∀ g : Disorder n, 0 < mixingTime g (1-ε)) := by + have hdrift (n : ℕ) (g : Disorder n) (hg : g ∈ G n) (f : Observables n) + (r : ℝ) (_hr : 0 ≤ r) (y : Spin n) : + deriv (fun v => unweightedGradient (semigroup (coupling g) v f) y) r - + generator (coupling g) (unweightedGradient (semigroup (coupling g) r f)) y ≤ + (-κ + if y ∈ bad n g then A else 0)* + unweightedGradient (semigroup (coupling g) r f) y := by + rw [(unweightedGradient_hasDerivAt (coupling g) f y r).deriv] + exact hgradient n g hg (semigroup (coupling g) r f) y + obtain ⟨d,c,hd,hc,havoid⟩ := uniform_bad_avoidance G bad hκ hA hχ hK.le hnorm hmlsi hsmall hdrift + have hav := superpolynomial_bad_avoidance G bad hc havoid + have hgp : ∀ᶠ n : ℕ in atTop, ∀ g ∈ G n, ∀ f : Observables n, + γ*FiniteLaw.variance (mass g 0) f ≤ stationaryEnergy g f := Eventually.of_forall hgap + have hgd (D : ℝ) (_hD : 0 < D) : ∀ᶠ n : ℕ in atTop, ∀ g ∈ G n, + ∀ f : Observables n, ∀ r ∈ Set.Icc (0:ℝ) (D*Real.log n), ∀ y, + deriv (fun v => unweightedGradient (semigroup (coupling g) v f) y) r - + generator (coupling g) (unweightedGradient (semigroup (coupling g) r f)) y ≤ + (-κ + if y ∈ bad n g then A else 0)* + unweightedGradient (semigroup (coupling g) r f) y := + Eventually.of_forall (fun n g hg f r hr => hdrift n g hg f r hr.1) + have hrow : ∀ᶠ n : ℕ in atTop, ∀ g ∈ G n, ∀ i, ∑ j, coupling g i j ^ 2 ≤ K^2 := by + apply Eventually.of_forall + intro n g hg i + exact row_squares_le_opNorm (coupling g) (coupling_symm g) hK.le (hnorm n g hg) i + have hfields := uniform_field_tails_of_small_set G bad hκ hA hd.le hγ (sq_nonneg K) hrow hgp hgd hav + have hlag := uniform_positive_lag_of_small_set_gradient G bad hκ hA hd.le hγ hgp hgd hav hfields + have hlo := uniform_median_lower_of_small_set G bad hκ hA hd.le hγ hgp hgd hav + have hup := uniform_median_upper_of_mlsi G hχ hnorm hmlsi + apply ratio_cutoff_of_positive_lag β ε η hε hε1 hη G (c := 1/4) (C := 2/χ) + (by norm_num) hK hnorm hG _ hlag + filter_upwards [hlo,hup] with n hnlo hnup + intro g hg + exact ⟨by simpa only [one_div_mul_eq_div] using hnlo g hg,hnup g hg⟩ + +end SKRatio.Calculus + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/FiniteChain/VarianceNonneg.lean b/lean/OAI/Probability/SKRatio/FiniteChain/VarianceNonneg.lean new file mode 100644 index 0000000000000000000000000000000000000000..a9e742774fc9622adf36f68106da59de4240d77c --- /dev/null +++ b/lean/OAI/Probability/SKRatio/FiniteChain/VarianceNonneg.lean @@ -0,0 +1,115 @@ +import Mathlib +import OAI.Probability.SKRatio.FiniteChain.Mean + +namespace OAI + +section +noncomputable section +open scoped BigOperators Topology Matrix +open MeasureTheory ProbabilityTheory Filter +noncomputable section +open scoped BigOperators Topology Matrix +open MeasureTheory ProbabilityTheory Filter +noncomputable section +open scoped BigOperators Topology +open MeasureTheory ProbabilityTheory Filter +noncomputable section +open scoped BigOperators Topology Matrix +open MeasureTheory ProbabilityTheory Filter +namespace SKRatio.FiniteLaw +variable {α : Type*} [Fintype α] + +theorem variance_nonneg (p f : α → ℝ) (hp : ∀ x, 0 ≤ p x) : + 0 ≤ variance p f := by + exact Finset.sum_nonneg (fun x _ => mul_nonneg (hp x) (sq_nonneg _)) + +theorem submass_centered_mean (p ρ f : α → ℝ) + (hρ : ∀ x, 0 ≤ ρ x) (hρp : ∀ x, ρ x ≤ p x) : + |mean ρ (fun x => f x - mean p f)| ≤ + Real.sqrt (∑ x, ρ x) * Real.sqrt (variance p f) := by + have hcs := Real.sum_mul_le_sqrt_mul_sqrt Finset.univ + (fun x => Real.sqrt (ρ x)) (fun x => Real.sqrt (ρ x) * |f x - mean p f|) + simp only [mul_pow, Real.sq_sqrt (hρ _), sq_abs, + ← mul_assoc, Real.mul_self_sqrt (hρ _)] at hcs + calc + |mean ρ (fun x => f x - mean p f)| ≤ ∑ x, |ρ x * (f x - mean p f)| := + Finset.abs_sum_le_sum_abs _ _ + _ = ∑ x, ρ x * |f x - mean p f| := by + apply Finset.sum_congr rfl + intro x _ + rw [abs_mul, abs_of_nonneg (hρ x)] + _ ≤ Real.sqrt (∑ x, ρ x) * Real.sqrt (∑ x, ρ x * (f x - mean p f) ^ 2) := hcs + _ ≤ Real.sqrt (∑ x, ρ x) * Real.sqrt (variance p f) := by + apply mul_le_mul_of_nonneg_left _ (Real.sqrt_nonneg _) + apply Real.sqrt_le_sqrt + exact Finset.sum_le_sum (fun x _ => mul_le_mul_of_nonneg_right (hρp x) (sq_nonneg _)) + +theorem common_mass_means (p q f : α → ℝ) (hp : ∀ x, 0 ≤ p x) (hq : ∀ x, 0 ≤ q x) + (hp1 : ∑ x, p x = 1) (hq1 : ∑ x, q x = 1) + {ε : ℝ} (hε : 0 < ε) (hTV : totalVariation p q ≤ 1 - ε) : + |mean p f - mean q f| ≤ + (Real.sqrt (variance p f) + Real.sqrt (variance q f)) / Real.sqrt ε := by + let ρ := fun x => min (p x) (q x) + let c : ℝ := ∑ x, ρ x + have hρ : ∀ x, 0 ≤ ρ x := fun x => le_min (hp x) (hq x) + have hpmean := submass_centered_mean p ρ f hρ (fun x => min_le_left _ _) + have hqmean := submass_centered_mean q ρ f hρ (fun x => min_le_right _ _) + have heq : c * (mean p f - mean q f) = + mean ρ (fun x => f x - mean q f) - mean ρ (fun x => f x - mean p f) := by + simp only [mean, mul_sub, Finset.sum_sub_distrib, ← Finset.sum_mul, c] + ring + have hc : ε ≤ c := by + dsimp only [c, ρ] + rw [common_mass p q hp1 hq1] + linarith only [hTV] + have hc0 : 0 < c := hε.trans_le hc + have htriangle : c * |mean p f - mean q f| ≤ + Real.sqrt c * (Real.sqrt (variance p f) + Real.sqrt (variance q f)) := by + calc + c * |mean p f - mean q f| = |c * (mean p f - mean q f)| := by + rw [abs_mul, abs_of_pos hc0] + _ ≤ |mean ρ (fun x => f x - mean q f)| + |mean ρ (fun x => f x - mean p f)| := by + rw [heq] + exact abs_sub _ _ + _ ≤ Real.sqrt c * Real.sqrt (variance q f) + Real.sqrt c * Real.sqrt (variance p f) := + add_le_add hqmean hpmean + _ = _ := by ring + have hb : Real.sqrt c * |mean p f - mean q f| ≤ + Real.sqrt (variance p f) + Real.sqrt (variance q f) := by + apply (mul_le_mul_iff_right₀ (Real.sqrt_pos.mpr hc0)).mp + simpa only [← mul_assoc, Real.mul_self_sqrt hc0.le] using htriangle + apply (le_div_iff₀ (Real.sqrt_pos.mpr hε)).mpr + calc + |mean p f - mean q f| * Real.sqrt ε ≤ |mean p f - mean q f| * Real.sqrt c := + mul_le_mul_of_nonneg_left (Real.sqrt_le_sqrt hc) (abs_nonneg _) + _ ≤ _ := by simpa only [mul_comm] using hb + +theorem totalVariation_le_of_tests (p q : α → ℝ) {B : ℝ} + (h : ∀ f : α → ℝ, (∀ x, |f x| ≤ 1) → |mean p f - mean q f| ≤ 2 * B) : + totalVariation p q ≤ B := by + let f : α → ℝ := fun x => if 0 ≤ p x - q x then 1 else -1 + have hf : ∀ x, |f x| ≤ 1 := by + intro x + dsimp only [f] + split_ifs <;> norm_num + have hprod (x : α) : (p x - q x) * f x = |p x - q x| := by + dsimp only [f] + split_ifs with h + · rw [mul_one, abs_of_nonneg h] + · rw [mul_neg_one, abs_of_neg (lt_of_not_ge h)] + have hid : mean p f - mean q f = 2 * totalVariation p q := by + simp only [mean, ← Finset.sum_sub_distrib, ← sub_mul, hprod, totalVariation] + ring + have hbound := h f hf + rw [hid, abs_of_nonneg (mul_nonneg (by norm_num) (totalVariation_nonneg p q))] at hbound + linarith only [hbound] + +end SKRatio.FiniteLaw + +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/FiniteChain/WeightedKernelOperator.lean b/lean/OAI/Probability/SKRatio/FiniteChain/WeightedKernelOperator.lean new file mode 100644 index 0000000000000000000000000000000000000000..6f6f82e38b973d8d39e599d9bdb4caa6ee94487a --- /dev/null +++ b/lean/OAI/Probability/SKRatio/FiniteChain/WeightedKernelOperator.lean @@ -0,0 +1,42 @@ +import Mathlib +import OAI.Probability.SKRatio.Matrices.WeightedSquares +import OAI.Probability.SKRatio.Matrices.CompactMatrixMasks + +namespace OAI + +section +noncomputable section +open scoped BigOperators NNReal ENNReal Topology +open MeasureTheory ProbabilityTheory Filter Set Real +namespace SKRatio.Planted +open SKRatioClock.Regression MatrixNet + +theorem weighted_square_operator_rare {X : Type*} [PseudoMetricSpace X] [CompactSpace X] + (β : ℝ) (G : X × X → ℝ) (hG : Continuous G) {u : ℝ} (hu : 0 {g | ∃ x : Fin n → X, + u < ‖Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) + (Matrix.of fun i j => squareError β g i j*G (x i,x j))‖}) := by + obtain ⟨C,hC,hrow⟩ := square_rows_bounded β + obtain ⟨δ,hδ,hmask⟩ := continuous_kernel_insertion G hG + (show 0≤C+β^2 by positivity) hu + apply (hrow.union (squareError_rare β hδ)).mono + refine Filter.Eventually.of_forall ?_ + rintro n g ⟨x,hx⟩ + by_contra hn + have hr : ∀ i, ∑ j, |squareError β g i j| ≤ C+β^2 := by + intro i + exact (squareError_absolute_row β g i).trans (add_le_add_left + (le_of_not_gt (fun hi => hn (Or.inl ⟨i,hi⟩))) _) + have hc : ∀ j, ∑ i, |squareError β g i j| ≤ C+β^2 := by + intro j + simpa only [squareError_symmetric β g] using hr j + have hd : ‖Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) (squareError β g)‖ ≤ δ := + le_of_not_gt (fun h => hn (Or.inr h)) + exact (not_lt_of_ge (hmask (squareError β g) hr hc hd x)) hx + +end SKRatio.Planted + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Gaussian/EmpiricalIntervals.lean b/lean/OAI/Probability/SKRatio/Gaussian/EmpiricalIntervals.lean new file mode 100644 index 0000000000000000000000000000000000000000..7cf698160526d10d8142e42e35ac5ef5ed140e06 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Gaussian/EmpiricalIntervals.lean @@ -0,0 +1,197 @@ +import Mathlib +import OAI.Probability.SKRatio.Gaussian.ExponentialEvents + +namespace OAI + +noncomputable section +open scoped BigOperators NNReal ENNReal Topology +open MeasureTheory ProbabilityTheory Filter Real Set +namespace SKRatioClock.Regression +attribute [local instance] Classical.propDecidable + +def cdfRamp (a b x : ℝ) : ℝ := max 0 (min 1 ((b-x)/(b-a))) + +lemma cdfRamp_bounds (a b x : ℝ) : 0≤cdfRamp a b x ∧ cdfRamp a b x≤1 := by + unfold cdfRamp + exact ⟨le_max_left ..,max_le (by norm_num) (min_le_left ..)⟩ + +lemma cdfRamp_lipschitz {a b : ℝ} (hab : a (b-x)/(b-a)) := by + apply LipschitzWith.of_dist_le_mul + intro x y + change dist ((b-x)/(b-a)) ((b-y)/(b-a)) ≤ (b-a)⁻¹*dist x y + simp only [Real.dist_eq] + rw [←sub_div,show b-x-(b-y)=-(x-y) by ring,abs_div,abs_neg, + abs_of_pos (sub_pos.mpr hab)] + exact le_of_eq (by ring) + unfold cdfRamp + simpa only [max_self] using + (LipschitzWith.const' 0 (K:=K)).max + ((LipschitzWith.const' 1 (K:=K)).min hlin) + +lemma cdfRamp_sandwich {a b : ℝ} (hab : a (1:ℝ)) x≤cdfRamp a b x ∧ + cdfRamp a b x≤(Set.Iic b).indicator (fun _ : ℝ => (1:ℝ)) x := by + constructor + · by_cases hx : x≤a + · rw [indicator_of_mem (show x∈Set.Iic a from hx)] + unfold cdfRamp + have hh : 1≤(b-x)/(b-a) := (le_div_iff₀ (sub_pos.mpr hab)).mpr (by linarith) + rw [min_eq_left hh,max_eq_right (by norm_num : (0:ℝ)≤1)] + · rw [indicator_of_notMem (show x∉Set.Iic a from hx)] + exact (cdfRamp_bounds ..).1 + · by_cases hx : x≤b + · rw [indicator_of_mem (show x∈Set.Iic b from hx)] + exact (cdfRamp_bounds ..).2 + · rw [indicator_of_notMem (show x∉Set.Iic b from hx)] + have hh : (b-x)/(b-a)≤0 := div_nonpos_of_nonpos_of_nonneg (by linarith) (by linarith) + unfold cdfRamp + rw [min_eq_right (hh.trans (by norm_num)),max_eq_left hh] + +lemma integrable_cdfRamp {μ : Measure ℝ} [IsFiniteMeasure μ] {a b : ℝ} (hab : a by rw [Real.norm_eq_abs,abs_of_nonneg (cdfRamp_bounds ..).1]; exact (cdfRamp_bounds ..).2)) + +lemma integral_cdfRamp_bounds {μ : Measure ℝ} [IsFiniteMeasure μ] {a b : ℝ} (hab : a (cdfRamp_sandwich hab x).1) + have h2 := integral_mono (integrable_cdfRamp (μ:=μ) hab) + ((integrable_const (1:ℝ)).indicator measurableSet_Iic) (fun x => (cdfRamp_sandwich hab x).2) + simpa only [integral_indicator measurableSet_Iic,integral_const,smul_eq_mul,mul_one,measureReal_restrict_apply_univ] using And.intro h1 h2 + +lemma continuous_measureReal_Iic (μ : Measure ℝ) [IsFiniteMeasure μ] [NullSingletonClass μ] : + Continuous (fun t : ℝ => μ.real (Set.Iic t)) := by + apply continuous_iff_continuousAt.mpr + intro t + have h := ((integrable_const (1:ℝ) : Integrable (fun _ : ℝ => (1:ℝ)) μ).integrableOn).continuousOn_Iic_primitive_Iic (a₀:=t+1) + have ht := h.continuousAt (Iic_mem_nhds (by linarith : t (∑ i, (Set.Iic t).indicator (fun _ : ℝ => (1:ℝ)) (X n ω i))/(n:ℝ)) + (μ.real (Set.Iic t)) := by + intro ε hε + obtain ⟨δ,hδ,hnear⟩ := Metric.continuousAt_iff.mp ((continuous_measureReal_Iic μ).continuousAt (x:=t)) (ε/4) (by positivity) + let d := δ/2 + have hd : 0 by rw [abs_of_nonneg (cdfRamp_bounds ..).1]; exact (cdfRamp_bounds ..).2) + have hU := hX.average (cdfRamp t (t+d)) (cdfRamp_lipschitz (by linarith : t by rw [abs_of_nonneg (cdfRamp_bounds ..).1]; exact (cdfRamp_bounds ..).2) + apply ((hL (ε/2) (by positivity)).union (hU (ε/2) (by positivity))).mono + filter_upwards [eventually_gt_atTop 0] with n hn + intro ω hbad + by_contra hh + have heL : |(∑ i, cdfRamp (t-d) t (X n ω i))/(n:ℝ)-∫ x, cdfRamp (t-d) t x ∂μ|<ε/2 := by + apply lt_of_not_ge + intro he + exact hh (Or.inl he) + have heU : |(∑ i, cdfRamp t (t+d) (X n ω i))/(n:ℝ)-∫ x, cdfRamp t (t+d) x ∂μ|<ε/2 := by + apply lt_of_not_ge + intro he + exact hh (Or.inr he) + have hsumL : (∑ i, cdfRamp (t-d) t (X n ω i))/(n:ℝ)≤ + (∑ i, (Set.Iic t).indicator (fun _ : ℝ => (1:ℝ)) (X n ω i))/(n:ℝ) := + div_le_div_of_nonneg_right (Finset.sum_le_sum (fun i _ => (cdfRamp_sandwich (by linarith : t-d (1:ℝ)) (X n ω i))/(n:ℝ)≤ + (∑ i, cdfRamp t (t+d) (X n ω i))/(n:ℝ) := + div_le_div_of_nonneg_right (Finset.sum_le_sum (fun i _ => (cdfRamp_sandwich (by linarith : t (1:ℝ)) (X n ω i))/(n:ℝ) - μ.real (Set.Iic t)| at hbad + rw [Real.dist_eq] at hlo hhi + rcases abs_cases ((∑ i, (Set.Iic t).indicator (fun _ : ℝ => (1:ℝ)) (X n ω i))/(n:ℝ) - μ.real (Set.Iic t)) with ⟨he,_⟩ | ⟨he,_⟩ + · rw [he] at hbad + linarith only [hε,hbad,hsumU,hibU,(abs_lt.mp heU).2,(abs_lt.mp hhi).2] + · rw [he] at hbad + linarith only [hε,hbad,hsumL,hibL,(abs_lt.mp heL).1,(abs_lt.mp hlo).1] + +lemma ExponentialConvergence.congr_eventually + {Ω : ℕ → Type*} [∀ n, MeasurableSpace (Ω n)] {ρ : ∀ n, Measure (Ω n)} + {E : Type*} [PseudoMetricSpace E] {X Y : ∀ n, Ω n → E} {x : E} + (hX : ExponentialConvergence ρ X x) (he : ∀ᶠ n in atTop, X n=Y n) : + ExponentialConvergence ρ Y x := by + intro ε hε + apply (hX ε hε).mono + filter_upwards [he] with n hn + rw [hn] + +lemma exponentialConvergence_const + {Ω : ℕ → Type*} [∀ n, MeasurableSpace (Ω n)] (ρ : ∀ n, Measure (Ω n)) + {E : Type*} [PseudoMetricSpace E] (x : E) : + ExponentialConvergence ρ (fun _ _ => x) x := by + intro ε hε + apply (exponentiallyRare_empty ρ).mono + filter_upwards [] with n + simp only [dist_self,not_le.mpr hε,Set.ofPred_false,Set.Subset.rfl] + +lemma indicator_Ioc_sub {a b : ℝ} (hab : a≤b) (x : ℝ) : + (Set.Ioc a b).indicator (fun _ : ℝ => (1:ℝ)) x= + (Set.Iic b).indicator (fun _ : ℝ => (1:ℝ)) x- + (Set.Iic a).indicator (fun _ : ℝ => (1:ℝ)) x := by + by_cases hxa : x≤a + · have hxb := hxa.trans hab + simp [Set.indicator,Set.mem_Ioc,Set.mem_Iic,hxa,hxb,not_lt_of_ge hxa] + · by_cases hxb : x≤b <;> + simp [Set.indicator,Set.mem_Ioc,Set.mem_Iic,hxa,hxb,lt_of_not_ge hxa] + +lemma ExponentialEmpiricalConcentration.Ioc + {Ω : ℕ → Type*} [∀ n, MeasurableSpace (Ω n)] + {ρ : ∀ n, Measure (Ω n)} {X : ∀ n, Ω n → Fin n → ℝ} + {μ : Measure ℝ} [IsFiniteMeasure μ] [NullSingletonClass μ] + (hX : ExponentialEmpiricalConcentration ρ X μ) {a b : ℝ} (hab : a≤b) : + ExponentialConvergence ρ + (fun n ω => (∑ i, (Set.Ioc a b).indicator (fun _ : ℝ => (1:ℝ)) (X n ω i))/(n:ℝ)) + (μ.real (Set.Ioc a b)) := by + have hm : μ.real (Set.Ioc a b)=μ.real (Set.Iic b)-μ.real (Set.Iic a) := by + rw [←integral_indicator_one measurableSet_Ioc] + change (∫ x, (Set.Ioc a b).indicator (fun _ : ℝ => (1:ℝ)) x ∂μ)=_ + simp_rw [indicator_Ioc_sub hab] + rw [integral_sub ((integrable_const (1:ℝ)).indicator measurableSet_Iic) + ((integrable_const (1:ℝ)).indicator measurableSet_Iic)] + simp only [integral_indicator measurableSet_Iic,integral_const, + smul_eq_mul,mul_one,measureReal_restrict_apply_univ] + rw [hm] + convert! ((hX.Iic b).prod (hX.Iic a)).continuous_map (f:=fun q : ℝ×ℝ => q.1-q.2) (by fun_prop) using 1 + funext n ω + simp only [indicator_Ioc_sub hab,Finset.sum_sub_distrib,sub_div] + +lemma ExponentialEmpiricalConcentration.Ioi + {Ω : ℕ → Type*} [∀ n, MeasurableSpace (Ω n)] + {ρ : ∀ n, Measure (Ω n)} {X : ∀ n, Ω n → Fin n → ℝ} + {μ : Measure ℝ} [IsProbabilityMeasure μ] [NullSingletonClass μ] + (hX : ExponentialEmpiricalConcentration ρ X μ) (a : ℝ) : + ExponentialConvergence ρ + (fun n ω => (∑ i, (Set.Ioi a).indicator (fun _ : ℝ => (1:ℝ)) (X n ω i))/(n:ℝ)) + (μ.real (Set.Ioi a)) := by + have hm : μ.real (Set.Ioi a)=1-μ.real (Set.Iic a) := by + rw [←Set.compl_Iic,measureReal_compl measurableSet_Iic,probReal_univ] + rw [hm] + apply ((hX.Iic a).continuous_map (f:=fun x : ℝ => 1-x) (by fun_prop)).congr_eventually + filter_upwards [eventually_gt_atTop 0] with n hn + funext ω + have hi (x : ℝ) : (Set.Ioi a).indicator (fun _ : ℝ => (1:ℝ)) x= + 1-(Set.Iic a).indicator (fun _ : ℝ => (1:ℝ)) x := by + by_cases hx : x≤a + · simp [Set.indicator,hx,not_lt_of_ge hx] + · simp [Set.indicator,hx,lt_of_not_ge hx] + simp only [hi,Finset.sum_sub_distrib,sub_div,Finset.sum_const,Finset.card_univ,Fintype.card_fin,nsmul_eq_mul, + mul_one,div_self (show (n:ℝ)≠0 from Nat.cast_ne_zero.mpr hn.ne')] + +end SKRatioClock.Regression + +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Gaussian/ExponentialBounds.lean b/lean/OAI/Probability/SKRatio/Gaussian/ExponentialBounds.lean new file mode 100644 index 0000000000000000000000000000000000000000..9b71454cb0ced7a6f8eb608563e7f22a9c269050 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Gaussian/ExponentialBounds.lean @@ -0,0 +1,88 @@ +import Mathlib +import OAI.Probability.SKRatio.Gaussian.ExponentialEvents + +namespace OAI + +section +noncomputable section +open scoped BigOperators NNReal ENNReal Topology +open MeasureTheory ProbabilityTheory Filter Set Real +namespace SKRatioClock.Regression + +lemma eventually_polynomial_exp_le {a : ℝ} (ha : 0 (a/2)*(n:ℝ)) atTop atTop := + tendsto_natCast_atTop_atTop.const_mul_atTop (by positivity) + have h := ((tendsto_pow_mul_exp_neg_atTop_nhds_zero k).comp ht).div_const ((a/2)^k) + simp only [zero_div] at h + have hlim : Tendsto (fun n : ℕ => (n:ℝ)^k*exp (-(a/2)*n)) atTop (𝓝 0) := by + convert h using 1 + funext n + simp only [Function.comp_apply,mul_pow,neg_mul] + field_simp + filter_upwards [hlim.eventually (gt_mem_nhds (by norm_num : (0:ℝ)<1))] with n hn + calc + _ = ((n:ℝ)^k*exp (-(a/2)*n))*exp (-(a/2)*n) := by + rw [mul_assoc,←exp_add] + congr 2 + ring + _ ≤ 1*exp (-(a/2)*n) := mul_le_mul_of_nonneg_right hn.le (by positivity) + _ = _ := one_mul _ + +lemma eventually_geom_exp_quadratic_le {a b c : ℝ} (ha : 0 (n:ℝ)) atTop atTop) + filter_upwards [hn.eventually (eventually_ge_atTop ((log b+c)/a))] with n hn + rw [show b^n = exp ((n:ℝ)*log b) by rw [exp_nat_mul,exp_log hb],←exp_add] + apply exp_le_exp.mpr + have hh := mul_le_mul_of_nonneg_right ((div_le_iff₀ ha).mp hn) (Nat.cast_nonneg (α := ℝ) n) + nlinarith only [hh] + +lemma exponentiallyRare_of_polynomial {H : ℕ → Type*} [∀ n, MeasurableSpace (H n)] + (ρ : ∀ n, Measure (H n)) (A : ∀ n, Set (H n)) + {C c : ℝ} (hC : 0 ⋃ i, A n i) := by + apply exponentiallyRare_of_polynomial ρ _ (mul_pos hD hC) hc k + filter_upwards [hcard,hbound] with n hcard hb + calc + _ ≤ ∑ i, ρ n (A n i) := measure_iUnion_fintype_le (ρ n) _ + _ ≤ ∑ _i : I n, ENNReal.ofReal (C*exp (-c*n)) := Finset.sum_le_sum (fun i _ => hb i) + _ = ENNReal.ofReal ((Fintype.card (I n):ℝ)*(C*exp (-c*n))) := by + simp [ENNReal.ofReal_natCast] + _ ≤ ENNReal.ofReal ((D*C)*(n:ℝ)^k*exp (-c*n)) := by + apply ENNReal.ofReal_le_ofReal + calc + _ ≤ (D*(n:ℝ)^k)*(C*exp (-c*n)) := mul_le_mul_of_nonneg_right hcard (by positivity) + _ = _ := by ring + +end SKRatioClock.Regression + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Gaussian/ExponentialEvents.lean b/lean/OAI/Probability/SKRatio/Gaussian/ExponentialEvents.lean new file mode 100644 index 0000000000000000000000000000000000000000..9aa419b086d8358c1e0d0965055e529706a2f982 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Gaussian/ExponentialEvents.lean @@ -0,0 +1,175 @@ +import Mathlib + +namespace OAI + +section +noncomputable section +open scoped BigOperators NNReal ENNReal Topology +open MeasureTheory ProbabilityTheory Filter +namespace SKRatioClock.Regression + +def ExponentialEmpiricalConcentration {H : ℕ → Type*} [∀ n, MeasurableSpace (H n)] + {E : Type*} [PseudoMetricSpace E] [MeasurableSpace E] + (ρ : ∀ n, Measure (H n)) (X : ∀ n, H n → Fin n → E) (ν : Measure E) : Prop := + ∀ (f : E → ℝ) (K : ℝ≥0), LipschitzWith K f → ∀ B : ℝ, + (∀ x, |f x| ≤ B) → ∀ ε : ℝ, 0 < ε → + ∃ C c : ℝ, 0 < C ∧ 0 < c ∧ ∀ᶠ n in atTop, + ρ n {h | ε ≤ |(∑ i, f (X n h i))/(n:ℝ) - ∫ x, f x ∂ν|} ≤ + ENNReal.ofReal (C * Real.exp (-c*(n:ℝ))) + +def ExponentiallyRare {H : ℕ → Type*} [∀ n, MeasurableSpace (H n)] + (ρ : ∀ n, Measure (H n)) (A : ∀ n, Set (H n)) : Prop := + ∃ C c : ℝ, 0 < C ∧ 0 < c ∧ ∀ᶠ n in atTop, + ρ n (A n) ≤ ENNReal.ofReal (C * Real.exp (-c*(n:ℝ))) + +lemma ExponentiallyRare.mono {H : ℕ → Type*} [∀ n, MeasurableSpace (H n)] + {ρ : ∀ n, Measure (H n)} {A B : ∀ n, Set (H n)} + (hB : ExponentiallyRare ρ B) (hAB : ∀ᶠ n in atTop, A n ⊆ B n) : + ExponentiallyRare ρ A := by + obtain ⟨C,c,hC,hc,he⟩ := hB + refine ⟨C,c,hC,hc,?_⟩ + filter_upwards [he,hAB] with n hn hABn + exact (measure_mono hABn).trans hn + +lemma ExponentiallyRare.union {H : ℕ → Type*} [∀ n, MeasurableSpace (H n)] + {ρ : ∀ n, Measure (H n)} {A B : ∀ n, Set (H n)} + (hA : ExponentiallyRare ρ A) (hB : ExponentiallyRare ρ B) : + ExponentiallyRare ρ (fun n => A n ∪ B n) := by + obtain ⟨C,c,hC,hc,he⟩ := hA + obtain ⟨D,d,hD,hd,hf⟩ := hB + refine ⟨C+D,min c d,add_pos hC hD,lt_min hc hd,?_⟩ + filter_upwards [he,hf] with n hn hm + refine (measure_union_le _ _).trans ((add_le_add hn hm).trans ?_) + have hc' : Real.exp (-c*(n:ℝ)) ≤ Real.exp (-min c d*(n:ℝ)) := + Real.exp_le_exp.mpr (by + have := min_le_left c d + nlinarith [Nat.cast_nonneg (α := ℝ) n]) + have hd' : Real.exp (-d*(n:ℝ)) ≤ Real.exp (-min c d*(n:ℝ)) := + Real.exp_le_exp.mpr (by + have := min_le_right c d + nlinarith [Nat.cast_nonneg (α := ℝ) n]) + rw [add_mul, ENNReal.ofReal_add (by positivity) (by positivity)] + exact add_le_add (ENNReal.ofReal_le_ofReal (mul_le_mul_of_nonneg_left hc' hC.le)) + (ENNReal.ofReal_le_ofReal (mul_le_mul_of_nonneg_left hd' hD.le)) + +lemma exponentiallyRare_empty {H : ℕ → Type*} [∀ n, MeasurableSpace (H n)] + (ρ : ∀ n, Measure (H n)) : ExponentiallyRare ρ (fun _ => ∅) := by + refine ⟨1,1,by norm_num,by norm_num,Filter.Eventually.of_forall ?_⟩ + intro n + simp only [measure_empty, zero_le] + +lemma ExponentiallyRare.iUnion_finite {H : ℕ → Type*} [∀ n, MeasurableSpace (H n)] + {ρ : ∀ n, Measure (H n)} {ι : Type*} [Finite ι] + {A : ι → ∀ n, Set (H n)} (hA : ∀ i, ExponentiallyRare ρ (A i)) : + ExponentiallyRare ρ (fun n => ⋃ i, A i n) := by + classical + cases nonempty_fintype ι + have hs (s : Finset ι) : ExponentiallyRare ρ (fun n => ⋃ i ∈ s, A i n) := by + induction s using Finset.induction_on with + | empty => simpa using exponentiallyRare_empty ρ + | @insert i s hi ih => + have heq : (fun n => ⋃ j ∈ insert i s, A j n) = + (fun n => A i n ∪ ⋃ j ∈ s, A j n) := by + funext n + ext h + simp only [Set.mem_iUnion, Finset.mem_insert, Set.mem_union] + aesop + rw [heq] + exact (hA i).union ih + simpa using hs Finset.univ + +def ExponentialConvergence {H : ℕ → Type*} [∀ n, MeasurableSpace (H n)] + (ρ : ∀ n, Measure (H n)) {E : Type*} [PseudoMetricSpace E] + (X : ∀ n, H n → E) (x : E) : Prop := + ∀ ε : ℝ, 0 < ε → ExponentiallyRare ρ (fun n => {h | ε ≤ dist (X n h) x}) + +lemma ExponentialConvergence.continuous_map + {H : ℕ → Type*} [∀ n, MeasurableSpace (H n)] {ρ : ∀ n, Measure (H n)} + {E F : Type*} [PseudoMetricSpace E] [PseudoMetricSpace F] + {X : ∀ n, H n → E} {x : E} (hX : ExponentialConvergence ρ X x) + {f : E → F} (hf : ContinuousAt f x) : + ExponentialConvergence ρ (fun n h => f (X n h)) (f x) := by + intro ε hε + obtain ⟨δ,hδ,hδe⟩ := Metric.continuousAt_iff.mp hf ε hε + apply (hX δ hδ).mono + refine Filter.Eventually.of_forall ?_ + intro n h hh + by_contra hnot + have hnear : dist (X n h) x < δ := lt_of_not_ge hnot + exact (not_lt_of_ge hh) (hδe hnear) + +lemma ExponentialConvergence.prod + {H : ℕ → Type*} [∀ n, MeasurableSpace (H n)] {ρ : ∀ n, Measure (H n)} + {E F : Type*} [PseudoMetricSpace E] [PseudoMetricSpace F] + {X : ∀ n, H n → E} {Y : ∀ n, H n → F} {x : E} {y : F} + (hX : ExponentialConvergence ρ X x) (hY : ExponentialConvergence ρ Y y) : + ExponentialConvergence ρ (fun n h => (X n h,Y n h)) (x,y) := by + intro ε hε + apply ((hX ε hε).union (hY ε hε)).mono + exact Filter.Eventually.of_forall (fun n h hh => by + simpa only [Prod.dist_eq, le_max_iff, Set.mem_union, Set.mem_ofPred_eq] using hh) + +lemma ExponentialConvergence.pi_finite + {H : ℕ → Type*} [∀ n, MeasurableSpace (H n)] {ρ : ∀ n, Measure (H n)} + {ι : Type*} [Fintype ι] {E : ι → Type*} [∀ i, PseudoMetricSpace (E i)] + {X : ∀ n, H n → ∀ i, E i} {x : ∀ i, E i} + (hX : ∀ i, ExponentialConvergence ρ (fun n h => X n h i) (x i)) : + ExponentialConvergence ρ X x := by + intro ε hε + apply (ExponentiallyRare.iUnion_finite (fun i => hX i ε hε)).mono + refine Filter.Eventually.of_forall ?_ + intro n h hh + by_contra hn + have hall : ∀ i, dist (X n h i) (x i) < ε := by + intro i + apply lt_of_not_ge + intro hi + exact hn (Set.mem_iUnion.mpr ⟨i,hi⟩) + exact (not_lt_of_ge hh) ((dist_pi_lt_iff hε).mpr hall) + +lemma ExponentialEmpiricalConcentration.average + {E : Type*} [PseudoMetricSpace E] [MeasurableSpace E] + {H : ℕ → Type*} [∀ n, MeasurableSpace (H n)] + {ρ : ∀ n, Measure (H n)} {X : ∀ n, H n → Fin n → E} {ν : Measure E} + (hX : ExponentialEmpiricalConcentration ρ X ν) + (f : E → ℝ) {K : ℝ≥0} (hf : LipschitzWith K f) + (B : ℝ) (hB : ∀ x, |f x| ≤ B) : + ExponentialConvergence ρ (fun n h => (∑ i, f (X n h i))/(n:ℝ)) (∫ x, f x ∂ν) := by + intro ε hε + simpa only [ExponentiallyRare, Real.dist_eq] using hX f K hf B hB ε hε + +lemma ExponentialEmpiricalConcentration.map + {E F : Type*} [PseudoMetricSpace E] [MeasurableSpace E] [BorelSpace E] + [PseudoMetricSpace F] [MeasurableSpace F] [BorelSpace F] + {H : ℕ → Type*} [∀ n, MeasurableSpace (H n)] + {ρ : ∀ n, Measure (H n)} {X : ∀ n, H n → Fin n → E} {ν : Measure E} + (hX : ExponentialEmpiricalConcentration ρ X ν) + (g : E → F) {L : ℝ≥0} (hg : LipschitzWith L g) : + ExponentialEmpiricalConcentration ρ (fun n h i => g (X n h i)) (ν.map g) := by + intro f K hf B hB ε hε + have hh := hX (f ∘ g) (K*L) (hf.comp hg) B (fun x => hB (g x)) ε hε + have hm : ∫ y, f y ∂ν.map g = ∫ x, f (g x) ∂ν := + integral_map hg.continuous.measurable.aemeasurable hf.continuous.measurable.aestronglyMeasurable + simpa only [Function.comp_apply, hm] using hh + +lemma ExponentiallyRare.without_prefactor {H : ℕ → Type*} [∀ n, MeasurableSpace (H n)] + {ρ : ∀ n, Measure (H n)} {A : ∀ n, Set (H n)} (hA : ExponentiallyRare ρ A) : + ∃ c : ℝ, 0 (n:ℝ)) atTop atTop) + filter_upwards [he,hnc.eventually (eventually_ge_atTop (2*Real.log C/c))] with n hn hsize + apply hn.trans + apply ENNReal.ofReal_le_ofReal + rw [show C*Real.exp (-c*n)=Real.exp (Real.log C-c*n) by + rw [Real.exp_sub,Real.exp_log hC,neg_mul,Real.exp_neg,div_eq_mul_inv] ] + apply Real.exp_le_exp.mpr + have hh := (div_le_iff₀ hc).mp hsize + nlinarith + +end SKRatioClock.Regression + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Gaussian/ExponentialProducts.lean b/lean/OAI/Probability/SKRatio/Gaussian/ExponentialProducts.lean new file mode 100644 index 0000000000000000000000000000000000000000..e388aff42a52c168442aaae7dea2e9a783af4a5c --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Gaussian/ExponentialProducts.lean @@ -0,0 +1,54 @@ +import Mathlib +import OAI.Probability.SKRatio.Gaussian.ExponentialEvents + +namespace OAI + +section +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +namespace SKRatioClock.Regression + +lemma ExponentiallyRare.prod_snd {H K : ℕ → Type*} + [∀ n, MeasurableSpace (H n)] [∀ n, MeasurableSpace (K n)] + {ρ : ∀ n, Measure (H n)} (μ : ∀ n, Measure (K n)) + [∀ n, SFinite (ρ n)] [∀ n, IsProbabilityMeasure (μ n)] + {A : ∀ n, Set (H n)} (hA : ExponentiallyRare ρ A) : + ExponentiallyRare (fun n => (μ n).prod (ρ n)) (fun n => Prod.snd ⁻¹' A n) := by + obtain ⟨C,c,hC,hc,he⟩ := hA + refine ⟨C,c,hC,hc,?_⟩ + filter_upwards [he] with n hn + have heq : (Prod.snd ⁻¹' A n : Set (K n × H n)) = univ ×ˢ A n := by ext; simp + rw [heq,Measure.prod_prod,measure_univ,one_mul] + exact hn + +lemma ExponentiallyRare.prod_fst {H K : ℕ → Type*} + [∀ n, MeasurableSpace (H n)] [∀ n, MeasurableSpace (K n)] + {ρ : ∀ n, Measure (H n)} (μ : ∀ n, Measure (K n)) + [∀ n, IsProbabilityMeasure (μ n)] + {A : ∀ n, Set (H n)} (hA : ExponentiallyRare ρ A) : + ExponentiallyRare (fun n => (ρ n).prod (μ n)) (fun n => Prod.fst ⁻¹' A n) := by + obtain ⟨C,c,hC,hc,he⟩ := hA + refine ⟨C,c,hC,hc,?_⟩ + filter_upwards [he] with n hn + have heq : (Prod.fst ⁻¹' A n : Set (H n × K n)) = A n ×ˢ univ := by ext; simp + rw [heq,Measure.prod_prod,measure_univ,mul_one] + exact hn + +lemma ExponentiallyRare.preimage_hasLaw {H K : ℕ → Type*} + [∀ n, MeasurableSpace (H n)] [∀ n, MeasurableSpace (K n)] + {ρ : ∀ n, Measure (H n)} {μ : ∀ n, Measure (K n)} + {A : ∀ n, Set (H n)} (hA : ExponentiallyRare ρ A) + (f : ∀ n, K n → H n) (hf : ∀ n, HasLaw (f n) (ρ n) (μ n)) : + ExponentiallyRare μ (fun n => f n ⁻¹' A n) := by + obtain ⟨C,c,hC,hc,he⟩ := hA + refine ⟨C,c,hC,hc,?_⟩ + filter_upwards [he] with n hn + exact ((Measure.le_map_apply (hf n).aemeasurable (A n)).trans_eq + (congrArg (fun m : Measure (H n) => m (A n)) (hf n).map_eq)).trans hn + +end SKRatioClock.Regression + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Gaussian/GaussianEmpirical.lean b/lean/OAI/Probability/SKRatio/Gaussian/GaussianEmpirical.lean new file mode 100644 index 0000000000000000000000000000000000000000..f001bf6a0d691a27531f20b3984bb8d7afb6ee4d --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Gaussian/GaussianEmpirical.lean @@ -0,0 +1,169 @@ +import Mathlib +import OAI.Probability.SKRatio.Matrices.GOERegression + +namespace OAI + +section +noncomputable section +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal +namespace SKRatioClock.Regression + +lemma subgaussian_abs_tail {Ω : Type*} [MeasurableSpace Ω] {μ : Measure Ω} + [IsFiniteMeasure μ] {X : Ω → ℝ} {c : ℝ≥0} (hX : HasSubgaussianMGF X c μ) + (ε : ℝ) (hε : 0 ≤ ε) : + μ {ω | ε ≤ |X ω|} ≤ 2 * ENNReal.ofReal (Real.exp (-ε^2/(2*(c:ℝ)))) := by + have hu := ENNReal.ofReal_le_ofReal (hX.measure_ge_le hε) + have hl := ENNReal.ofReal_le_ofReal (hX.neg.measure_ge_le hε) + simp only [Measure.real, ENNReal.ofReal_toReal (measure_ne_top _ _)] at hu hl + have hs : {ω | ε ≤ |X ω|} ⊆ {ω | ε ≤ X ω} ∪ {ω | ε ≤ -X ω} := by + intro ω h + simpa only [Set.mem_union, Set.mem_ofPred_eq, le_abs] using h + calc + _ ≤ _ := measure_mono hs + _ ≤ _ := measure_union_le _ _ + _ ≤ _ := add_le_add hu hl + _ = _ := (two_mul _).symm + +lemma iid_bounded_average_tail_of_hasLaw {Ω : Type*} [MeasurableSpace Ω] + {μ : Measure Ω} [IsProbabilityMeasure μ] {n : ℕ} (hn : 0 < n) + (X : Fin n → Ω → ℝ) (hXi : iIndepFun X μ) + (hX : ∀ i, HasLaw (X i) (gaussianReal 0 1) μ) (f : ℝ → ℝ) + (hf : Measurable f) (B : ℝ) (hB : 0 ≤ B) (hbound : ∀ z, |f z| ≤ B) + (ε : ℝ) (hε : 0 ≤ ε) : + μ {g | + ε ≤ |(∑ i : Fin n, f (X i g))/(n:ℝ) - ∫ z, f z ∂gaussianReal 0 1|} ≤ + 2 * ENNReal.ofReal (Real.exp (-(ε^2*(n:ℝ))/(2*B^2))) := by + let m := ∫ z, f z ∂gaussianReal 0 1 + have hi : iIndepFun (fun i (g : Ω) => f (X i g) - m) μ := + hXi.comp (fun _ z => f z-m) (fun _ => hf.sub_const m) + have hm (i : Fin n) : + (∫ g : Ω, f (X i g) ∂μ) = m := by + exact (hX i).integral_comp hf.aestronglyMeasurable + have hsub (i : Fin n) : HasSubgaussianMGF (fun g : Ω => f (X i g)-m) + ((‖B-(-B)‖₊/2)^2) μ := by + have hb : ∀ᵐ g : Ω ∂μ, f (X i g) ∈ Set.Icc (-B) B := + Eventually.of_forall (fun g => abs_le.mp (hbound (X i g))) + simpa only [hm] using hasSubgaussianMGF_of_mem_Icc + (show AEMeasurable (fun g : Ω => f (X i g)) μ from + hf.comp_aemeasurable (hX i).aemeasurable) hb + have hh := subgaussian_abs_tail + (HasSubgaussianMGF.sum_of_iIndepFun hi (s := Finset.univ) (fun i _ => hsub i)) + (ε*n) (by positivity) + have he (g : Ω) : + (ε*(n:ℝ) ≤ |∑ i : Fin n, (f (X i g)-m)|) ↔ + ε ≤ |(∑ i : Fin n, f (X i g))/(n:ℝ)-m| := by + have hnR : (0:ℝ) < n := Nat.cast_pos.mpr hn + rw [Finset.sum_sub_distrib, Finset.sum_const, Finset.card_univ, Fintype.card_fin, + nsmul_eq_mul] + have heq : (∑ i : Fin n, f (X i g))-(n:ℝ)*m = + (n:ℝ)*((∑ i : Fin n, f (X i g))/(n:ℝ)-m) := by field_simp + rw [heq, abs_mul, abs_of_pos hnR] + rw [mul_comm ε (n:ℝ), mul_le_mul_iff_right₀ hnR] + simp only [he] at hh + convert hh using 1 + congr 3 + simp only [Finset.sum_const, Finset.card_univ, Fintype.card_fin, nsmul_eq_mul, + NNReal.coe_mul, NNReal.coe_natCast, NNReal.coe_pow, NNReal.coe_div, NNReal.coe_ofNat, + coe_nnnorm, Real.norm_eq_abs] + rw [abs_of_nonneg (by linarith : 0 ≤ B-(-B))] + have hn0 : (n:ℝ) ≠ 0 := Nat.cast_ne_zero.mpr (Nat.ne_of_gt hn) + by_cases hB0 : B=0 + · simp [hB0] + · field_simp + ring + +lemma iid_bounded_average_tail {n : ℕ} (hn : 0 < n) (f : ℝ → ℝ) + (hf : Measurable f) (B : ℝ) (hB : 0 ≤ B) (hbound : ∀ z, |f z| ≤ B) + (ε : ℝ) (hε : 0 ≤ ε) : + standardArrayLaw (Fin n) {g | + ε ≤ |(∑ i : Fin n, f (g i))/(n:ℝ) - ∫ z, f z ∂gaussianReal 0 1|} ≤ + 2 * ENNReal.ofReal (Real.exp (-(ε^2*(n:ℝ))/(2*B^2))) := by + exact iid_bounded_average_tail_of_hasLaw (μ := standardArrayLaw (Fin n)) hn + (fun (i : Fin n) (g : Fin n → ℝ) => g i) + coordinates_independent coordinate_hasLaw f hf B hB hbound ε hε + +lemma gaussian_hasSubgaussianMGF {Ω : Type*} [MeasurableSpace Ω] + {μ : Measure Ω} [IsProbabilityMeasure μ] {X : Ω → ℝ} {v : ℝ≥0} + (hX : HasLaw X (gaussianReal 0 v) μ) : HasSubgaussianMGF X v μ where + integrable_exp_mul t := by + rw [← mgf_pos_iff, mgf_gaussianReal hX] + exact Real.exp_pos _ + mgf_le t := by + rw [mgf_gaussianReal hX] + simp + +lemma average_common_shift_bound {n : ℕ} (hn : 0 < n) {f : ℝ → ℝ} {K : ℝ≥0} + (hf : LipschitzWith K f) (v : Fin n → ℝ) (r : ℝ) : + |(∑ i, f (v i+r))/(n:ℝ) - (∑ i, f (v i))/(n:ℝ)| ≤ (K:ℝ)*|r| := by + have hnR : (0:ℝ) < n := Nat.cast_pos.mpr hn + rw [← sub_div, ← Finset.sum_sub_distrib, abs_div, abs_of_pos hnR] + apply (div_le_iff₀ hnR).mpr + apply (Finset.abs_sum_le_sum_abs _ _).trans + calc + _ ≤ ∑ _i : Fin n, (K:ℝ)*|r| := by + apply Finset.sum_le_sum + intro i _ + simpa only [Real.dist_eq, add_sub_cancel_left] using hf.dist_le_mul (v i+r) (v i) + _ = _ := by simp [mul_comm] + +lemma iid_common_shift_average_tail {n : ℕ} (hn : 0 < n) (m a b : ℝ) + (f : ℝ → ℝ) {K : ℝ≥0} (hf : LipschitzWith K f) + (B : ℝ) (hB : 0 ≤ B) (hbound : ∀ z, |f z| ≤ B) + (ε : ℝ) (hε : 0 ≤ ε) : + standardArrayLaw (Option (Fin n)) {g | + ε ≤ |(∑ i : Fin n, f (m+a*g (some i)+b*g none))/(n:ℝ) - + ∫ z, f (m+a*z) ∂gaussianReal 0 1|} ≤ + 2 * ENNReal.ofReal (Real.exp (-(ε^2*(n:ℝ))/(8*B^2))) + + 2 * ENNReal.ofReal (Real.exp (-ε^2/(8*(K:ℝ)^2*b^2))) := by + let M := ∫ z, f (m+a*z) ∂gaussianReal 0 1 + let A (g : Option (Fin n) → ℝ) := (∑ i : Fin n, f (m+a*g (some i)))/(n:ℝ) + have hi : iIndepFun (fun i : Fin n => fun g : Option (Fin n) → ℝ => g (some i)) + (standardArrayLaw (Option (Fin n))) := coordinates_independent.precomp (Option.some_injective (Fin n)) + have ht := iid_bounded_average_tail_of_hasLaw (μ := standardArrayLaw (Option (Fin n))) hn + (fun (i : Fin n) (g : Option (Fin n) → ℝ) => g (some i)) hi + (fun i => coordinate_hasLaw (some i)) (fun z => f (m+a*z)) + (hf.continuous.measurable.comp (measurable_const.add (measurable_const.mul measurable_id))) + B hB (fun z => hbound _) (ε/2) (by positivity) + have hz := subgaussian_abs_tail + ((gaussian_hasSubgaussianMGF (coordinate_hasLaw (none : Option (Fin n)))).const_mul ((K:ℝ)*b)) + (ε/2) (by positivity) + have hsub : {g | ε ≤ |(∑ i : Fin n, f (m+a*g (some i)+b*g none))/(n:ℝ)-M|} ⊆ + {g | ε/2 ≤ |A g-M|} ∪ {g | ε/2 ≤ |(K:ℝ)*b*g none|} := by + intro g hg + by_cases ha : ε/2 ≤ |A g-M| + · exact Or.inl ha + apply Or.inr + have hd := average_common_shift_bound hn hf (fun i => m+a*g (some i)) (b*g none) + have htri := abs_add_le + ((∑ i : Fin n, f (m+a*g (some i)+b*g none))/(n:ℝ) - A g) (A g-M) + have hrad : (K:ℝ)*|b*g none| = |(K:ℝ)*b*g none| := by + simp [abs_mul, abs_of_nonneg K.coe_nonneg, mul_assoc] + rw [hrad] at hd + simp only [sub_add_sub_cancel] at htri + change ε ≤ _ at hg + change |(∑ i : Fin n, f (m+a*g (some i)+b*g none))/(n:ℝ) - A g| ≤ _ at hd + have : |A g-M| < ε/2 := lt_of_not_ge ha + change ε/2 ≤ |(K:ℝ)*b*g none| + linarith + apply (measure_mono hsub).trans + apply (measure_union_le _ _).trans + have h1 : standardArrayLaw (Option (Fin n)) {g | ε/2 ≤ |A g-M|} ≤ + 2 * ENNReal.ofReal (Real.exp (-(ε^2*(n:ℝ))/(8*B^2))) := by + convert ht using 1 + congr 3 + ring + have h2 : standardArrayLaw (Option (Fin n)) {g | ε/2 ≤ |(K:ℝ)*b*g none|} ≤ + 2 * ENNReal.ofReal (Real.exp (-ε^2/(8*(K:ℝ)^2*b^2))) := by + convert hz using 1 + congr 3 + change -ε^2 / (8 * (K:ℝ)^2 * b^2) = -(ε / 2)^2 / (2 * ((((K:ℝ)*b)^2) * 1)) + ring + exact add_le_add h1 h2 + +end SKRatioClock.Regression + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Gaussian/GaussianEvents.lean b/lean/OAI/Probability/SKRatio/Gaussian/GaussianEvents.lean new file mode 100644 index 0000000000000000000000000000000000000000..71cfd1505c6b3b09ea90501e6fbdb3e5a5400892 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Gaussian/GaussianEvents.lean @@ -0,0 +1,202 @@ +import Mathlib +import OAI.Probability.SKRatio.FiniteChain.CutoffScale +import OAI.Probability.SKRatio.Matrices.GoeMatrixQuadCoeff +import OAI.Probability.SKRatio.Matrices.GaussianRows +import OAI.Probability.SKRatio.Variational.UniformGap + +namespace OAI + +section +noncomputable section +open scoped BigOperators Topology ENNReal +open MeasureTheory ProbabilityTheory Real Filter +namespace SKRatio.Gaussian +open Calculus +variable {n : ℕ} + +lemma coupling_bridge (g : Disorder n) : coupling g = SKRatioGaussian.coupling g := by + funext i j + unfold coupling SKRatioGaussian.coupling + split_ifs <;> rfl + +lemma continuous_operator_norm : Continuous (fun g : Disorder n => euclideanOpNorm (coupling g)) := by + exact continuous_norm.comp + (((Matrix.toEuclideanCLM (𝕜 := ℝ) (n := Fin n)).toAlgEquiv.toLinearEquiv.toLinearMap.continuous_of_finiteDimensional).comp + (continuous_pi (fun i => continuous_pi (fun k => continuous_coupling i k)))) + +def matrixGood (β δ : ℝ) (n : ℕ) : Set (Disorder n) := + {g | euclideanOpNorm (coupling g) ≤ 2*β+δ ∧ + (∀ i k, |coupling g i k| ≤ δ) ∧ + (∀ i, ∑ k, coupling g i k^2 ≤ β^2+δ)} + +lemma matrixGood_measurable (β δ : ℝ) (n : ℕ) : MeasurableSet (matrixGood β δ n) := by + unfold matrixGood + apply (measurableSet_le continuous_operator_norm.measurable measurable_const).inter + apply MeasurableSet.inter + · change MeasurableSet {g : Disorder n | ∀ i k, |coupling g i k| ≤ δ} + simp only [Set.ofPred_forall] + exact MeasurableSet.iInter fun i => MeasurableSet.iInter fun k => + measurableSet_le (continuous_coupling i k).abs.measurable measurable_const + · change MeasurableSet {g : Disorder n | ∀ i, ∑ k, coupling g i k ^ 2 ≤ β^2+δ} + simp only [Set.ofPred_forall] + exact MeasurableSet.iInter fun i => measurableSet_le (by fun_prop) measurable_const + +lemma deleted_diagonal_norm_bound (r d R : ℝ) (hd : 0 ≤ d) + (g : SKRatioGaussian.MatrixCoordinates (Fin n) → ℝ) + (hR : ‖SKRatioGaussian.matrixOperator (SKRatioGaussian.goeMatrix r g)‖ ≤ R) + (hdiag : ∀ i, |SKRatioGaussian.goeMatrix r g i i| ≤ d) : + euclideanOpNorm (coupling (SKRatioGaussian.goeDisorder r g)) ≤ R+d := by + change ‖Matrix.toEuclideanCLM (𝕜 := ℝ) (n := Fin n) (Matrix.of (SKRatioGaussian.coupling (SKRatioGaussian.goeDisorder r g)))‖ ≤ _ + rw [SKRatioGaussian.coupling_goeDisorder,map_sub] + have hh : ‖Matrix.toEuclideanCLM (𝕜 := ℝ) (n := Fin n) (Matrix.diagonal (fun i => SKRatioGaussian.goeMatrix r g i i))‖ ≤ d := by + rw [Matrix.l2_opNorm_toEuclideanCLM] + exact SKRatioGaussian.diagonal_norm_le hd _ hdiag + exact (norm_sub_le _ _).trans (add_le_add hR hh) + +lemma disorder_goe_hasLaw (β : ℝ) (n : ℕ) : + HasLaw (SKRatioGaussian.goeDisorder (n := n) (β^2/(n:ℝ))) (disorderLaw β n) + (SKRatioGaussian.gaussianCoordinates (SKRatioGaussian.MatrixCoordinates (Fin n))) := + SKRatioGaussian.goe_actual_disorder_hasLaw β n + +lemma coupling_norm_tail {β δ : ℝ} (hβ : 0 < β) (hδ : 0 ≤ δ) (hn : 0 < n) : + (disorderLaw β n).real {g | 2*β+δ < euclideanOpNorm (coupling g)} ≤ + 2*exp (-((δ/2)^2/(Real.pi^2*β^2))*(n:ℝ)) + + 2*(n:ℝ)*exp (-((δ/2)^2/(8*β^2))*(n:ℝ)) := by + let : NeZero n := ⟨hn.ne'⟩ + have hnr : (0:ℝ) < n := Nat.cast_pos.mpr hn + have hm : MeasurableSet {g : Disorder n | 2*β+δ < euclideanOpNorm (coupling g)} := + measurableSet_lt measurable_const continuous_operator_norm.measurable + rw [←(disorder_goe_hasLaw β n).measureReal_eq hm] + let r := β^2/(n:ℝ) + let E₁ := {g : SKRatioGaussian.MatrixCoordinates (Fin n) → ℝ | + 2*β+δ/2 < ‖SKRatioGaussian.matrixOperator (SKRatioGaussian.goeMatrix r g)‖} + let E₂ := {g : SKRatioGaussian.MatrixCoordinates (Fin n) → ℝ | ∃ i, δ/2 < |SKRatioGaussian.goeMatrix r g i i|} + have hs : {g : SKRatioGaussian.MatrixCoordinates (Fin n) → ℝ | + 2*β+δ < euclideanOpNorm (coupling (SKRatioGaussian.goeDisorder r g))} ⊆ E₁ ∪ E₂ := by + intro g hg + by_contra hh + have hh₁ : ¬g ∈ E₁ := fun h => hh (Or.inl h) + have hh₂ : ¬g ∈ E₂ := fun h => hh (Or.inr h) + have hb := deleted_diagonal_norm_bound r (δ/2) (2*β+δ/2) (by positivity) g + (not_lt.mp hh₁) (fun i => not_lt.mp (fun hi => hh₂ ⟨i,hi⟩)) + change 2*β+δ < _ at hg + linarith + have h₁ : (SKRatioGaussian.gaussianCoordinates (SKRatioGaussian.MatrixCoordinates (Fin n))).real E₁ ≤ + 2*exp (-((δ/2)^2/(Real.pi^2*β^2))*(n:ℝ)) := by + have ht := SKRatioGaussian.goe_norm_tail (ι := Fin n) (sq_pos_of_pos hβ) (by positivity : 0 ≤ δ/2) + simpa only [Fintype.card_fin,sqrt_sq hβ.le,show -(δ/2)^2*(n:ℝ)/(Real.pi^2*β^2) = + -((δ/2)^2/(Real.pi^2*β^2))*(n:ℝ) by ring] using ht + have h₂ : (SKRatioGaussian.gaussianCoordinates (SKRatioGaussian.MatrixCoordinates (Fin n))).real E₂ ≤ + 2*(n:ℝ)*exp (-((δ/2)^2/(8*β^2))*(n:ℝ)) := by + have ht := SKRatioGaussian.goe_diagonal_tail (ι := Fin n) (div_pos (sq_pos_of_pos hβ) hnr) + (by positivity : 0 ≤ δ/2) + have he : -(δ/2)^2/(8*(β^2/(n:ℝ))) = -((δ/2)^2/(8*β^2))*(n:ℝ) := by field_simp + simpa only [Fintype.card_fin,he] using ht + exact (measureReal_mono hs).trans ((measureReal_union_le E₁ E₂).trans (add_le_add h₁ h₂)) + +lemma coupling_entries_tail {β δ : ℝ} (hβ : 0 < β) (hδ : 0 ≤ δ) (hn : 0 < n) : + (disorderLaw β n).real {g | ∃ i k, δ < |coupling g i k|} ≤ + 2*(n:ℝ)^2*exp (-(δ^2/(4*β^2))*(n:ℝ)) := by + let : NeZero n := ⟨hn.ne'⟩ + have hm : MeasurableSet {g : Disorder n | ∃ i k, δ < |coupling g i k|} := + by + simp only [Set.ofPred_exists] + exact MeasurableSet.iUnion fun i => MeasurableSet.iUnion fun k => + measurableSet_lt measurable_const (continuous_coupling i k).abs.measurable + rw [←(disorder_goe_hasLaw β n).measureReal_eq hm] + simp only [coupling_bridge] + convert SKRatioGaussian.coupling_goe_max_entry_tail (n := n) (sq_pos_of_pos hβ) hδ using 1 + congr 2 + ring + +lemma coupling_rows_tail {β δ : ℝ} (hβ : 0 < β) (hδ : 0 ≤ δ) (hn : 0 < n) : + (disorderLaw β n).real {g | ∃ i, β^2+δ < ∑ k, coupling g i k^2} ≤ + (n:ℝ)*exp (-(2*(sqrt (β^2+δ)-β)^2/(Real.pi^2*β^2))*(n:ℝ)) := by + have hm : MeasurableSet {g : Disorder n | ∃ i, β^2+δ < ∑ k, coupling g i k^2} := + by + simp only [Set.ofPred_exists] + exact MeasurableSet.iUnion fun i => measurableSet_lt measurable_const (by fun_prop) + rw [←(disorder_goe_hasLaw β n).measureReal_eq hm] + simpa only [coupling_bridge,sqrt_sq hβ.le] using SKRatioGaussian.coupling_goe_all_rows_tight_tail hn (sq_pos_of_pos hβ) hδ + +lemma nat_pow_exp_neg_tendsto {a : ℝ} (ha : 0 < a) (k : ℕ) : + Tendsto (fun n : ℕ => (n:ℝ)^k*exp (-a*(n:ℝ))) atTop (𝓝 0) := by + have ht : Tendsto (fun n : ℕ => a*(n:ℝ)) atTop atTop := + tendsto_natCast_atTop_atTop.const_mul_atTop ha + have h := ((tendsto_pow_mul_exp_neg_atTop_nhds_zero k).comp ht).div_const (a^k) + simp only [zero_div] at h + convert h using 1 + ext n + simp only [Function.comp_apply,mul_pow,neg_mul] + field_simp + +lemma matrixGood_compl_bound {β δ : ℝ} (hβ : 0 < β) (hδ : 0 ≤ δ) (hn : 0 < n) : + (disorderLaw β n).real (matrixGood β δ n)ᶜ ≤ + (2*exp (-((δ/2)^2/(Real.pi^2*β^2))*(n:ℝ)) + + 2*(n:ℝ)*exp (-((δ/2)^2/(8*β^2))*(n:ℝ))) + + (2*(n:ℝ)^2*exp (-(δ^2/(4*β^2))*(n:ℝ)) + + (n:ℝ)*exp (-(2*(sqrt (β^2+δ)-β)^2/(Real.pi^2*β^2))*(n:ℝ))) := by + let E₁ := {g : Disorder n | 2*β+δ < euclideanOpNorm (coupling g)} + let E₂ := {g : Disorder n | ∃ i k, δ < |coupling g i k|} + let E₃ := {g : Disorder n | ∃ i, β^2+δ < ∑ k, coupling g i k^2} + have he : (matrixGood β δ n)ᶜ = E₁ ∪ (E₂ ∪ E₃) := by + ext g + simp only [matrixGood,Set.mem_compl_iff,Set.mem_ofPred_eq,not_and_or,not_forall,not_le, + Set.mem_union,E₁,E₂,E₃] + rw [he] + apply (measureReal_union_le E₁ (E₂ ∪ E₃)).trans + apply add_le_add (coupling_norm_tail hβ hδ hn) + exact (measureReal_union_le E₂ E₃).trans + (add_le_add (coupling_entries_tail hβ hδ hn) (coupling_rows_tail hβ hδ hn)) + +theorem matrixGood_probability {β δ : ℝ} (hβ : 0 ≤ β) (hδ : 0 < δ) : + Tendsto (fun n : ℕ => disorderLaw β n (matrixGood β δ n)ᶜ) atTop (𝓝 0) := by + rcases hβ.eq_or_lt with he | hpos + · subst β + have hz (n : ℕ) : disorderLaw 0 n (matrixGood 0 δ n)ᶜ = 0 := by + apply measure_eq_zero_iff_ae_notMem.mpr + filter_upwards [disorderLaw_zero_ae n] with g hg + subst g + simp only [Set.mem_compl_iff,not_not] + unfold matrixGood + have hc : coupling (0 : Disorder n) = 0 := by ext i k; simp [coupling] + have he : Matrix.toEuclideanCLM (𝕜 := ℝ) (n := Fin n) (0 : Interaction n) = 0 := by + exact map_zero (Matrix.toEuclideanCLM (𝕜 := ℝ) (n := Fin n)).toAlgEquiv + simp [hc,euclideanOpNorm,he,hδ.le] + simpa only [hz] using (tendsto_const_nhds : Tendsto (fun _ : ℕ => (0:ℝ≥0∞)) atTop (𝓝 0)) + apply (ENNReal.tendsto_toReal_iff (fun n => measure_ne_top _ _) ENNReal.zero_ne_top).mp + have ha : 0 < (δ/2)^2/(Real.pi^2*β^2) := by positivity + have hb : 0 < (δ/2)^2/(8*β^2) := by positivity + have hc : 0 < δ^2/(4*β^2) := by positivity + have hs : 0 < sqrt (β^2+δ)-β := by + have := sqrt_lt_sqrt (sq_nonneg β) (show β^2 < β^2+δ by linarith) + rw [sqrt_sq hpos.le] at this + linarith + have hd : 0 < 2*(sqrt (β^2+δ)-β)^2/(Real.pi^2*β^2) := by positivity + have ht := ((nat_pow_exp_neg_tendsto ha 0).const_mul 2 |>.add + ((nat_pow_exp_neg_tendsto hb 1).const_mul 2)).add + (((nat_pow_exp_neg_tendsto hc 2).const_mul 2).add (nat_pow_exp_neg_tendsto hd 1)) + simp only [pow_zero,one_mul,pow_one,mul_zero,zero_add,←mul_assoc] at ht + apply squeeze_zero' (Eventually.of_forall (fun n => measureReal_nonneg)) + ?_ ht + filter_upwards [eventually_gt_atTop (0:ℕ)] with n hn + exact matrixGood_compl_bound hpos hδ.le hn + +theorem uniform_gap_high_probability {β : ℝ} (hβ : 0 ≤ β) (hβhalf : β < 1/2) : + ∃ δ ρ : ℝ, 0 < δ ∧ 0 < ρ ∧ + Tendsto (fun n : ℕ => disorderLaw β n (matrixGood β δ n)ᶜ) atTop (𝓝 0) ∧ + ∀ n : ℕ, ∀ g ∈ matrixGood β δ n, + ∀ s ∈ Set.Icc (0:ℝ) 1, ∀ h : Fin n → ℝ, + (∀ f, ρ*Fields.variance (s • g) h f ≤ Fields.dirichlet (s • g) h f) ∧ + (∀ a, Fields.variance (s • g) h (Fields.linearObservable a) ≤ + ρ⁻¹*(∑ i, a i^2)) := by + obtain ⟨δ,ρ,hd,hr,hgap⟩ := Fields.exists_uniform_gap_tolerance hβ hβhalf + exact ⟨δ,ρ,hd,hr,matrixGood_probability hβ hd, + fun n g hg => hgap n g hg.1 hg.2.1 hg.2.2⟩ + +end SKRatio.Gaussian + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Gaussian/GaussianFunctional.lean b/lean/OAI/Probability/SKRatio/Gaussian/GaussianFunctional.lean new file mode 100644 index 0000000000000000000000000000000000000000..9f4695230c29fcecc3926cc42dd3ef9849081710 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Gaussian/GaussianFunctional.lean @@ -0,0 +1,92 @@ +import Mathlib +import OAI.Probability.SKRatio.Gaussian.GaussianEvents +import OAI.Probability.SKRatio.Entropy.GibbsObservation +import OAI.Probability.SKRatio.FiniteChain.StaticReduction + +namespace OAI + +section +noncomputable section +open scoped BigOperators Topology +open MeasureTheory ProbabilityTheory Real Filter +namespace SKRatio.Gaussian +attribute [local instance] Classical.propDecidable +open Calculus + +theorem functional_inequalities_high_probability {β : ℝ} + (hβ : 0 ≤ β) (hβhalf : β < 1/2) : + ∃ δ ρ χ : ℝ, 0 < δ ∧ 0 < ρ ∧ 0 < χ ∧ + Tendsto (fun n : ℕ => disorderLaw β n (matrixGood β δ n)ᶜ) atTop (𝓝 0) ∧ + ∀ n : ℕ, ∀ g ∈ matrixGood β δ n, + euclideanOpNorm (coupling g) ≤ 2 ∧ + (∀ f : Observables n, ρ*FiniteLaw.variance (mass g 0) f ≤ stationaryEnergy g f) ∧ + (∀ f : Observables n, (∀ x, 0 < f x) → + χ*FiniteLaw.entropy (mass g 0) f ≤ + -stationaryInner g (generator (coupling g) f) (fun x => log (f x))) := by + obtain ⟨δ,ρ,hd,hr,hgap⟩ := Fields.exists_uniform_gap_tolerance hβ hβhalf + let d := min δ 1 + have hdp : 0 < d := lt_min hd zero_lt_one + have hdδ : d ≤ δ := min_le_left _ _ + have hd1 : d ≤ 1 := min_le_right _ _ + refine ⟨d,ρ,exp (-16/ρ),hdp,hr,exp_pos _,matrixGood_probability hβ hdp,?_⟩ + intro n g hg + have hnorm : euclideanOpNorm (coupling g) ≤ 2 := hg.1.trans (by linarith) + have hboth := hgap n g (hg.1.trans (by linarith)) + (fun i j => (hg.2.1 i j).trans hdδ) (fun i => (hg.2.2 i).trans (by linarith)) + refine ⟨hnorm,?_,?_⟩ + · intro f + have hh := (hboth 1 ⟨by norm_num,le_rfl⟩ 0).1 f + simpa only [one_smul,Fields.variance_eq_finiteLaw, + Fields.dirichlet_zero_eq_stationaryEnergy] using hh + · intro f hf + exact Observation.zero_field_mlsi g hnorm hr (fun s hs h => (hboth s hs h).2) f hf + +theorem ratio_cutoff_of_typical_gradient (β ε η : ℝ) + (hβ : 0 ≤ β) (hβhalf : β < 1/2) + (hε : 0 < ε) (hεhalf : ε < 1/2) (hη : 0 < η) + (G : ∀ n : ℕ, Set (Disorder n)) (bad : ∀ n, Disorder n → Set (Spin n)) + {κ A : ℝ} (hκ : 0 < κ) (hA : 0 ≤ A) + (hG : Tendsto (fun n => disorderLaw β n (G n)ᶜ) atTop (𝓝 0)) + (hsmall : ∀ n, ∀ g ∈ G n, FiniteLaw.mean (mass g 0) + (fun y => if y ∈ bad n g then 1 else 0) ≤ exp (-κ*n)) + (hgradient : ∀ n, ∀ g ∈ G n, ∀ f : Observables n, ∀ y, + (∑ i, 2*halfDiff i f y*halfDiff i (generator (coupling g) f) y) - + generator (coupling g) (unweightedGradient f) y ≤ + (-κ + if y ∈ bad n g then A else 0)*unweightedGradient f y) : + Tendsto + (fun n : ℕ => disorderLaw β n + {g : Disorder n | 1+η < + (mixingTime g ε : ℝ)/(mixingTime g (1-ε) : ℝ)}) + atTop (𝓝 0) ∧ + (∀ᶠ n : ℕ in atTop, ∀ g : Disorder n, 0 < mixingTime g (1-ε)) := by + classical + obtain ⟨δ,ρ,χ,hd,hr,hχ,hprob,hfun⟩ := functional_inequalities_high_probability hβ hβhalf + let F := fun n => G n ∩ matrixGood β δ n + have hF : Tendsto (fun n => disorderLaw β n (F n)ᶜ) atTop (𝓝 0) := by + have hb (n : ℕ) : disorderLaw β n (F n)ᶜ ≤ + disorderLaw β n (G n)ᶜ + disorderLaw β n (matrixGood β δ n)ᶜ := by + dsimp [F] + rw [Set.compl_inter] + exact measure_union_le _ _ + exact tendsto_of_tendsto_of_tendsto_of_le_of_le tendsto_const_nhds + (by simpa only [add_zero] using hG.add hprob) + (fun n => bot_le) hb + apply ratio_cutoff_of_static_inputs β ε η hε (by linarith) hη F bad hκ hA hχ hr + (by norm_num : (0:ℝ)<2) hF + · intro n g hg + exact (hfun n g hg.2).1 + · intro n g hg + exact (hfun n g hg.2).2.1 + · intro n g hg f hf _ + exact (hfun n g hg.2).2.2 f hf + · intro n g hg + exact hsmall n g hg.1 + · intro n g hg + exact hgradient n g hg.1 + +end SKRatio.Gaussian + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Gaussian/HammingGeometry.lean b/lean/OAI/Probability/SKRatio/Gaussian/HammingGeometry.lean new file mode 100644 index 0000000000000000000000000000000000000000..3b5da360e9006463f5cdfabffcb9594c124284de --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Gaussian/HammingGeometry.lean @@ -0,0 +1,331 @@ +import Mathlib +import OAI.Probability.SKRatio.FiniteChain.Mean +import OAI.Probability.SKRatio.Calculus.RowControl + +namespace OAI + +section +noncomputable section +open scoped BigOperators Topology Matrix +open MeasureTheory Filter +namespace SKRatio.Calculus +attribute [local instance] Classical.propDecidable + +lemma hammingDist_real_sum {n : ℕ} (x y : Spin n) : + (hammingDist x y : ℝ) = ∑ i, if x i = y i then 0 else 1 := by + simp only [hammingDist,Finset.card_filter,Nat.cast_sum,Nat.cast_ite,Nat.cast_one,Nat.cast_zero, + ite_not] + +lemma hamming_exp_sum {n : ℕ} (ρ : ℝ) (y : Spin n) : + (∑ x : Spin n, Real.exp (-ρ*(hammingDist x y:ℝ))) = (1+Real.exp (-ρ))^n := by + have he (x : Spin n) : Real.exp (-ρ*(hammingDist x y:ℝ)) = + ∏ i, (if x i = y i then (1:ℝ) else Real.exp (-ρ)) := by + rw [hammingDist_real_sum,Finset.mul_sum,Real.exp_sum] + apply Finset.prod_congr rfl + intro i _ + split_ifs <;> simp + simp_rw [he] + rw [← Fintype.prod_sum (fun (i : Fin n) (b : Bool) => if b = y i then (1:ℝ) else Real.exp (-ρ))] + have hb (i : Fin n) : (∑ b : Bool, if b = y i then (1:ℝ) else Real.exp (-ρ)) = + 1+Real.exp (-ρ) := by + cases y i <;> simp [add_comm] + simp only [hb,Finset.prod_const,Finset.card_univ,Fintype.card_fin] + +def spinVector {n : ℕ} (x : Spin n) : EuclideanSpace ℝ (Fin n) := + WithLp.toLp 2 (fun i => spinValue (x i)) + +lemma spinVector_norm_sq {n : ℕ} (x : Spin n) : ‖spinVector x‖^2 = (n:ℝ) := by + simp [spinVector,EuclideanSpace.real_norm_sq_eq,Independent.spinValue_sq] + +lemma spinVector_sub_norm_sq {n : ℕ} (x y : Spin n) : + ‖spinVector x-spinVector y‖^2 = 4*(hammingDist x y:ℝ) := by + rw [EuclideanSpace.real_norm_sq_eq,hammingDist_real_sum,Finset.mul_sum] + apply Finset.sum_congr rfl + intro i _ + change (spinValue (x i)-spinValue (y i))^2 = _ + cases hx : x i <;> cases hy : y i <;> norm_num [spinValue] + +lemma hamiltonian_eq_inner {n : ℕ} (g : Disorder n) (x : Spin n) : + hamiltonian g 0 x = (1/2:ℝ)*inner ℝ (spinVector x) + (Matrix.toEuclideanCLM (𝕜 := ℝ) (n := Fin n) (coupling g) (spinVector x)) := by + rw [Matrix.inner_toEuclideanCLM (coupling g : Matrix (Fin n) (Fin n) ℝ) (spinVector x) (spinVector x)] + simp only [hamiltonian,Pi.zero_apply,zero_mul,Finset.sum_const_zero,add_zero,dotProduct, + Matrix.mulVec,Finset.mul_sum,spinVector,mul_assoc] + +lemma abs_hamiltonian_sub_hamming {n : ℕ} (g : Disorder n) (x y : Spin n) : + |hamiltonian g 0 x-hamiltonian g 0 y| ≤ + 2*euclideanOpNorm (coupling g)*Real.sqrt n*Real.sqrt (hammingDist x y) := by + let T := Matrix.toEuclideanCLM (𝕜 := ℝ) (n := Fin n) (coupling g) + have hid : hamiltonian g 0 x-hamiltonian g 0 y = (1/2:ℝ)*( + inner ℝ (spinVector x) (T (spinVector x-spinVector y))+ + inner ℝ (spinVector x-spinVector y) (T (spinVector y))) := by + rw [hamiltonian_eq_inner,hamiltonian_eq_inner,map_sub,inner_sub_right,inner_sub_left] + dsimp only [T] + ring + have hnorm (z : Spin n) : ‖spinVector z‖ = Real.sqrt n := by + rw [← spinVector_norm_sq z,Real.sqrt_sq (norm_nonneg _)] + have hdiff : ‖spinVector x-spinVector y‖ = 2*Real.sqrt (hammingDist x y) := by + rw [← Real.sqrt_sq (norm_nonneg (spinVector x-spinVector y)),spinVector_sub_norm_sq, + Real.sqrt_mul (by norm_num : (0:ℝ)≤4)] + norm_num + rw [hid,abs_mul,abs_of_nonneg (by norm_num : (0:ℝ)≤1/2)] + calc + _ ≤ (1/2:ℝ)*(|inner ℝ (spinVector x) (T (spinVector x-spinVector y))|+ + |inner ℝ (spinVector x-spinVector y) (T (spinVector y))|) := + mul_le_mul_of_nonneg_left (abs_add_le _ _) (by norm_num) + _ ≤ (1/2:ℝ)*(‖spinVector x‖*(euclideanOpNorm (coupling g)*‖spinVector x-spinVector y‖)+ + ‖spinVector x-spinVector y‖*(euclideanOpNorm (coupling g)*‖spinVector y‖)) := by + apply mul_le_mul_of_nonneg_left _ (by norm_num) + apply add_le_add + · exact (abs_real_inner_le_norm _ _).trans (mul_le_mul_of_nonneg_left + (T.le_opNorm _) (norm_nonneg _)) + · exact (abs_real_inner_le_norm _ _).trans (mul_le_mul_of_nonneg_left + (T.le_opNorm _) (norm_nonneg _)) + _ = _ := by rw [hnorm,hnorm,hdiff]; ring + +lemma mass_le_of_hamming {n : ℕ} (g : Disorder n) {K δ : ℝ} + (hK : 0 ≤ K) (hδ : 0 ≤ δ) (hnorm : euclideanOpNorm (coupling g) ≤ K) + (x y : Spin n) (hxy : (hammingDist x y:ℝ) ≤ δ*n) : + mass g 0 x ≤ Real.exp (2*K*Real.sqrt δ*n)*mass g 0 y := by + have he := abs_hamiltonian_sub_hamming g x y + have hgeom : |hamiltonian g 0 x-hamiltonian g 0 y| ≤ 2*K*Real.sqrt δ*n := by + calc + _ ≤ 2*euclideanOpNorm (coupling g)*Real.sqrt n*Real.sqrt (hammingDist x y) := he + _ ≤ 2*K*Real.sqrt n*Real.sqrt (δ*n) := by + apply mul_le_mul + · exact mul_le_mul_of_nonneg_right (mul_le_mul_of_nonneg_left hnorm (by norm_num)) + (Real.sqrt_nonneg _) + · exact Real.sqrt_le_sqrt hxy + · exact Real.sqrt_nonneg _ + · positivity + _ = (2*K*Real.sqrt δ)*(Real.sqrt n)^2 := by rw [Real.sqrt_mul hδ]; ring + _ = _ := by rw [Real.sq_sqrt (Nat.cast_nonneg n)] + have hh : hamiltonian g 0 x ≤ 2*K*Real.sqrt δ*n+hamiltonian g 0 y := by + have h := (le_abs_self _).trans hgeom + linarith only [h] + unfold mass weight + rw [← mul_div_assoc,← Real.exp_add] + exact div_le_div_of_nonneg_right (Real.exp_le_exp.mpr hh) (partition_pos g 0).le + +lemma hamming_ball_exp_bound {n : ℕ} (y : Spin n) {δ ρ : ℝ} (hρ : 0 ≤ ρ) : + (∑ x : Spin n, if (hammingDist x y:ℝ) ≤ δ*n then (1:ℝ) else 0) ≤ + Real.exp ((ρ*δ+Real.log (1+Real.exp (-ρ)))*n) := by + have hle (x : Spin n) : (if (hammingDist x y:ℝ) ≤ δ*n then (1:ℝ) else 0) ≤ + Real.exp (ρ*δ*n)*Real.exp (-ρ*(hammingDist x y:ℝ)) := by + rw [← Real.exp_add] + split_ifs with hx + · apply Real.one_le_exp_iff.mpr + nlinarith only [mul_le_mul_of_nonneg_left hx hρ] + · exact Real.exp_nonneg _ + calc + _ ≤ _ := Finset.sum_le_sum (fun x _ => hle x) + _ = Real.exp (ρ*δ*n)*(1+Real.exp (-ρ))^n := by rw [← Finset.mul_sum,hamming_exp_sum] + _ = _ := by + rw [show (1+Real.exp (-ρ))^n = Real.exp (Real.log (1+Real.exp (-ρ))*(n:ℝ)) by + rw [mul_comm,Real.exp_nat_mul,Real.exp_log (by positivity)],← Real.exp_add] + congr 1 + ring + +def hammingNeighborhood {n : ℕ} (B : Set (Spin n)) (δ : ℝ) : Set (Spin n) := + {x | ∃ y ∈ B, (hammingDist x y:ℝ) ≤ δ*n} + +lemma gibbs_hamming_neighborhood {n : ℕ} (g : Disorder n) (B : Set (Spin n)) + {K κ δ ρ : ℝ} (hK : 0 ≤ K) (hδ : 0 ≤ δ) (hρ : 0 ≤ ρ) + (hnorm : euclideanOpNorm (coupling g) ≤ K) + (hsmall : FiniteLaw.mean (mass g 0) (fun x => if x ∈ B then 1 else 0) ≤ Real.exp (-κ*n)) : + FiniteLaw.mean (mass g 0) (fun x => if x ∈ hammingNeighborhood B δ then 1 else 0) ≤ + Real.exp ((-κ+2*K*Real.sqrt δ+ρ*δ+Real.log (1+Real.exp (-ρ)))*n) := by + let a := Real.exp (2*K*Real.sqrt δ*n) + let b := Real.exp ((ρ*δ+Real.log (1+Real.exp (-ρ)))*n) + have hpoint (x : Spin n) : mass g 0 x*(if x ∈ hammingNeighborhood B δ then 1 else 0) ≤ + ∑ y : Spin n, if y ∈ B then a*mass g 0 y*(if (hammingDist x y:ℝ) ≤ δ*n then 1 else 0) else 0 := by + by_cases hx : x ∈ hammingNeighborhood B δ + · simp only [hx,↓reduceIte,mul_one] + obtain ⟨y,hy,hxy⟩ := hx + apply (mass_le_of_hamming g hK hδ hnorm x y hxy).trans + apply le_trans _ (Finset.single_le_sum (fun z _ => by + have := mass_nonneg g 0 z + dsimp only [a]; positivity) (Finset.mem_univ y)) + simp [hy,hxy,a] + · simp only [hx,↓reduceIte,mul_zero] + exact Finset.sum_nonneg (fun y _ => by have := mass_nonneg g 0 y; dsimp only [a]; positivity) + calc + _ ≤ ∑ x : Spin n, ∑ y : Spin n, + if y ∈ B then a*mass g 0 y*(if (hammingDist x y:ℝ) ≤ δ*n then 1 else 0) else 0 := + Finset.sum_le_sum (fun x _ => hpoint x) + _ = ∑ y : Spin n, if y ∈ B then a*mass g 0 y* + (∑ x : Spin n, if (hammingDist x y:ℝ) ≤ δ*n then 1 else 0) else 0 := by + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro y _ + by_cases hy : y ∈ B <;> simp only [hy,↓reduceIte,Finset.mul_sum,Finset.sum_const_zero] + _ ≤ ∑ y : Spin n, a*b*(mass g 0 y*(if y ∈ B then 1 else 0)) := by + apply Finset.sum_le_sum + intro y _ + by_cases hy : y ∈ B + · simp only [hy,↓reduceIte,mul_one] + calc + _ ≤ a*mass g 0 y*b := mul_le_mul_of_nonneg_left (hamming_ball_exp_bound y hρ) + (mul_nonneg (Real.exp_nonneg _) (mass_nonneg g 0 y)) + _ = _ := by ring + · simp [hy] + _ = a*b*FiniteLaw.mean (mass g 0) (fun y => if y ∈ B then 1 else 0) := by + simp only [FiniteLaw.mean,Finset.mul_sum] + _ ≤ a*b*Real.exp (-κ*n) := mul_le_mul_of_nonneg_left hsmall (by dsimp only [a,b]; positivity) + _ = _ := by dsimp only [a,b]; rw [← Real.exp_add,← Real.exp_add]; congr 1; ring + +lemma exists_small_hamming_radius {κ K : ℝ} (hκ : 0 < κ) : + ∃ δ ρ : ℝ, 0 < δ ∧ δ < 1/2 ∧ 0 ≤ ρ ∧ + 2*K*Real.sqrt δ+ρ*δ+Real.log (1+Real.exp (-ρ)) < κ/2 := by + have he : Tendsto (fun ρ : ℝ => Real.exp (-ρ)) atTop (𝓝 0) := + Real.tendsto_exp_atBot.comp tendsto_neg_atTop_atBot + have hl : Tendsto (fun ρ : ℝ => Real.log (1+Real.exp (-ρ))) atTop (𝓝 0) := by + have h := ((tendsto_const_nhds.add he).log (by norm_num : (1:ℝ)+0≠0)) + simpa only [add_zero,Real.log_one] using h + obtain ⟨ρ,hρ,hrsmall⟩ := ((eventually_ge_atTop (0:ℝ)).and + (hl.eventually (gt_mem_nhds (by linarith : (0:ℝ)<κ/2)))).exists + let f (δ : ℝ) := 2*K*Real.sqrt δ+ρ*δ+Real.log (1+Real.exp (-ρ)) + have hf : Continuous f := by fun_prop + have hfs : f 0 < κ/2 := by simpa [f] using hrsmall + obtain ⟨e,he0,hee⟩ := Metric.eventually_nhds_iff.mp + (hf.continuousAt.tendsto.eventually (gt_mem_nhds hfs)) + let δ := min e (1/2) / 2 + have hd : 0 < δ := by dsimp only [δ]; positivity + have hde : δ < e := by dsimp only [δ]; linarith only [min_le_left e (1/2),he0] + have hdhalf : δ < 1/2 := by dsimp only [δ]; linarith only [min_le_right e (1/2)] + refine ⟨δ,ρ,hd,hdhalf,hρ,?_⟩ + exact hee (by simpa only [Real.dist_eq,sub_zero,abs_of_pos hd] using hde) + +def hammingTo {n : ℕ} (B : Set (Spin n)) (x : Spin n) : ℕ := + if h : B.Nonempty then B.toFinset.inf' (Set.toFinset_nonempty.mpr h) (hammingDist x) else 0 + +lemma hammingTo_attained {n : ℕ} (B : Set (Spin n)) (hB : B.Nonempty) (x : Spin n) : + ∃ y ∈ B, hammingTo B x = hammingDist x y := by + obtain ⟨y,hy,he⟩ := Finset.exists_mem_eq_inf' (Set.toFinset_nonempty.mpr hB) (hammingDist x) + exact ⟨y,Set.mem_toFinset.mp hy,by simpa only [hammingTo,dite_eq_left hB] using he⟩ + +lemma hammingTo_le {n : ℕ} (B : Set (Spin n)) (x y : Spin n) (hy : y ∈ B) : + hammingTo B x ≤ hammingDist x y := by + have hB : B.Nonempty := ⟨y,hy⟩ + simp only [hammingTo,dite_eq_left hB] + exact Finset.inf'_le _ (Set.mem_toFinset.mpr hy) + +lemma hammingTo_zero_of_mem {n : ℕ} (B : Set (Spin n)) (x : Spin n) (hx : x ∈ B) : + hammingTo B x = 0 := by + have h := hammingTo_le B x x hx + simpa only [hammingDist_self,Nat.le_zero] using h + +lemma hammingTo_triangle {n : ℕ} (B : Set (Spin n)) (hB : B.Nonempty) (x z : Spin n) : + hammingTo B x ≤ hammingDist x z+hammingTo B z := by + obtain ⟨y,hy,he⟩ := hammingTo_attained B hB z + rw [he] + exact (hammingTo_le B x y hy).trans (hammingDist_triangle x z y) + +lemma hammingTo_le_radius_iff {n : ℕ} (B : Set (Spin n)) (hB : B.Nonempty) + (x : Spin n) (δ : ℝ) : + (hammingTo B x:ℝ) ≤ δ*n ↔ x ∈ hammingNeighborhood B δ := by + constructor + · intro hx + obtain ⟨y,hy,he⟩ := hammingTo_attained B hB x + exact ⟨y,hy,by simpa only [he] using hx⟩ + · rintro ⟨y,hy,hxy⟩ + have hcast : (hammingTo B x:ℝ) ≤ (hammingDist x y:ℝ) := by + exact_mod_cast hammingTo_le B x y hy + exact hcast.trans hxy + +lemma hammingDist_replace_le_one {n : ℕ} (x : Spin n) (i : Fin n) : + hammingDist (replace x i true) (replace x i false) ≤ 1 := by + unfold hammingDist + apply Finset.card_le_one.mpr + intro a ha b hb + have h (a : Fin n) (ha : a ∈ Finset.univ.filter + (fun a => replace x i true a ≠ replace x i false a)) : a = i := by + by_contra hne + exact (Finset.mem_filter.mp ha).2 (by simp [replace,Function.update_of_ne hne]) + exact (h a ha).trans (h b hb).symm + +def distanceObservable {n : ℕ} (B : Set (Spin n)) : Observables n := + fun x => (hammingTo B x:ℝ)/Real.sqrt n + +lemma distanceObservable_nonneg {n : ℕ} (B : Set (Spin n)) (x : Spin n) : + 0 ≤ distanceObservable B x := by unfold distanceObservable; positivity + +lemma distanceObservable_zero {n : ℕ} (B : Set (Spin n)) (x : Spin n) (hx : x ∈ B) : + distanceObservable B x = 0 := by simp [distanceObservable,hammingTo_zero_of_mem B x hx] + +lemma unweightedGradient_distanceObservable {n : ℕ} (hn : 0 < n) + (B : Set (Spin n)) (hB : B.Nonempty) (x : Spin n) : + unweightedGradient (distanceObservable B) x ≤ 1/4 := by + have hsq : (Real.sqrt n)^2 = (n:ℝ) := Real.sq_sqrt (Nat.cast_nonneg n) + have hspos : 0 < Real.sqrt n := Real.sqrt_pos.mpr (Nat.cast_pos.mpr hn) + have hdiff (i : Fin n) : |(hammingTo B (replace x i true):ℝ)-hammingTo B (replace x i false)| ≤ 1 := by + apply abs_le.mpr + have h1 := hammingTo_triangle B hB (replace x i true) (replace x i false) + have h2 := hammingTo_triangle B hB (replace x i false) (replace x i true) + rw [hammingDist_comm (replace x i false)] at h2 + have hd := hammingDist_replace_le_one x i + have h1r : (hammingTo B (replace x i true):ℝ) ≤ + (hammingDist (replace x i true) (replace x i false):ℝ)+hammingTo B (replace x i false) := by + exact_mod_cast h1 + have h2r : (hammingTo B (replace x i false):ℝ) ≤ + (hammingDist (replace x i true) (replace x i false):ℝ)+hammingTo B (replace x i true) := by + exact_mod_cast h2 + have hdr : (hammingDist (replace x i true) (replace x i false):ℝ) ≤ 1 := by + exact_mod_cast hd + constructor <;> linarith only [h1r,h2r,hdr] + calc + _ ≤ ∑ _i : Fin n, (1/(2*Real.sqrt n))^2 := by + apply Finset.sum_le_sum + intro i _ + have h := (sq_le_sq₀ (abs_nonneg _) (by norm_num)).mpr (hdiff i) + rw [sq_abs] at h + unfold halfDiff distanceObservable + have he : (((hammingTo B (replace x i true):ℝ)/Real.sqrt n- + (hammingTo B (replace x i false):ℝ)/Real.sqrt n)/2)^2 = + (((hammingTo B (replace x i true):ℝ)-(hammingTo B (replace x i false):ℝ))^2)* + (1/(2*Real.sqrt n))^2 := by ring + rw [he] + simpa only [one_mul,one_pow] using mul_le_mul_of_nonneg_right h (sq_nonneg (1/(2*Real.sqrt n))) + _ = _ := by + simp only [Finset.sum_const,Finset.card_univ,Fintype.card_fin,nsmul_eq_mul] + field_simp + nlinarith only [hsq] + +lemma distanceObservable_mean_lower {n : ℕ} (hn : 0 < n) (B : Set (Spin n)) + (hB : B.Nonempty) (p : Spin n → ℝ) (hp : ∀ y, 0 ≤ p y) (hp1 : ∑ y, p y = 1) + {δ : ℝ} (hδ : 0 ≤ δ) + (hhalf : FiniteLaw.mean p (fun y => if y ∈ hammingNeighborhood B δ then 1 else 0) ≤ 1/2) : + δ*Real.sqrt n/2 ≤ FiniteLaw.mean p (distanceObservable B) := by + have hspos : 0 < Real.sqrt n := Real.sqrt_pos.mpr (Nat.cast_pos.mpr hn) + have hdist (y : Spin n) : δ*Real.sqrt n*(1-(if y ∈ hammingNeighborhood B δ then 1 else 0)) ≤ + distanceObservable B y := by + by_cases hy : y ∈ hammingNeighborhood B δ + · simp only [hy,↓reduceIte,sub_self,mul_zero] + exact distanceObservable_nonneg B y + · have hgt := lt_of_not_ge (mt (hammingTo_le_radius_iff B hB y δ).mp hy) + simp only [hy,↓reduceIte,sub_zero,mul_one] + rw [distanceObservable,le_div_iff₀ hspos] + calc + _ = δ*(n:ℝ) := by rw [mul_assoc,← pow_two,Real.sq_sqrt (Nat.cast_nonneg n)] + _ ≤ _ := hgt.le + have hs := Finset.sum_le_sum (s := Finset.univ) + (fun y _ => mul_le_mul_of_nonneg_left (hdist y) (hp y)) + have hsum : (∑ y, p y*(δ*Real.sqrt n*(1-(if y ∈ hammingNeighborhood B δ then 1 else 0)))) = + δ*Real.sqrt n*(1-FiniteLaw.mean p (fun y => if y ∈ hammingNeighborhood B δ then 1 else 0)) := by + simp only [FiniteLaw.mean,Finset.mul_sum,mul_sub,mul_one,Finset.sum_sub_distrib] + rw [show (∑ y, p y*(δ*Real.sqrt n)) = δ*Real.sqrt n by rw [← Finset.sum_mul,hp1,one_mul]] + congr 1 + apply Finset.sum_congr rfl + intro y _ + ring + rw [hsum] at hs + have hm := mul_le_mul_of_nonneg_left hhalf (mul_nonneg hδ (Real.sqrt_nonneg n)) + dsimp only [FiniteLaw.mean] at * + linarith only [hs,hm] + +end SKRatio.Calculus + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Gaussian/Planted.lean b/lean/OAI/Probability/SKRatio/Gaussian/Planted.lean new file mode 100644 index 0000000000000000000000000000000000000000..2e32d1f7775278d2e5695931af3b7d1d5a4d5346 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Gaussian/Planted.lean @@ -0,0 +1,316 @@ +import Mathlib +import OAI.Probability.SKRatio.Calculus.RowControl + +namespace OAI + +noncomputable section +open scoped BigOperators Topology ENNReal NNReal +open MeasureTheory ProbabilityTheory Real Filter +namespace SKRatio.Planted +open Calculus +attribute [local instance] Classical.propDecidable +variable {n : ℕ} + +def gauge (x : Spin n) (g : Disorder n) : Disorder n := + fun e => spinValue (x e.1.1)*g e*spinValue (x e.1.2) + +lemma coupling_gauge (x : Spin n) (g : Disorder n) : + coupling (gauge x g) = signConjugate x (coupling g) := by + funext i j + change coupling (gauge x g) i j = spinValue (x i)*coupling g i j*spinValue (x j) + simp only [coupling, gauge] + split_ifs <;> ring + +lemma gauge_twice (x : Spin n) (g : Disorder n) : gauge x (gauge x g) = g := by + funext e + unfold gauge + have h₁ := spin_sq x e.1.1 + have h₂ := spin_sq x e.1.2 + change spinValue (x e.1.1)^2 = 1 at h₁ + change spinValue (x e.1.2)^2 = 1 at h₂ + calc + _ = (spinValue (x e.1.1))^2*(spinValue (x e.1.2))^2*g e := by ring + _ = _ := by rw [h₁,h₂,one_mul,one_mul] + +lemma gauge_continuous (x : Spin n) : Continuous (gauge x) := by + apply continuous_pi + intro e + exact (continuous_apply e |>.const_mul _).mul_const _ + +lemma hamiltonian_gauge (x y : Spin n) (g : Disorder n) : + hamiltonian (gauge x g) 0 y = hamiltonian g 0 (signProduct x y) := by + simp only [hamiltonian,coupling_gauge,Pi.zero_apply,zero_mul,Finset.sum_const_zero,add_zero] + congr 1 + apply Finset.sum_congr rfl + intro i _ + apply Finset.sum_congr rfl + intro j _ + change spin y i*(spin x i*coupling g i j*spin x j)*spin y j = + spin (signProduct x y) i*coupling g i j*spin (signProduct x y) j + rw [spin_signProduct,spin_signProduct] + ring + +lemma hamiltonian_edges (g : Disorder n) (x : Spin n) : + hamiltonian g 0 x = ∑ e : Edge n, spinValue (x e.1.1)*g e*spinValue (x e.1.2) := by + let f : Fin n × Fin n → ℝ := fun p => + if h : p.1 < p.2 then spinValue (x p.1)*g ⟨p,h⟩*spinValue (x p.2) else 0 + have hh (i j : Fin n) : spinValue (x i)*coupling g i j*spinValue (x j) = f (i,j)+f (j,i) := by + dsimp [f,coupling] + split_ifs with h₁ h₂ h₂ <;> try omega + all_goals ring + have hs : ∑ p, f p = ∑ e : Edge n, spinValue (x e.1.1)*g e*spinValue (x e.1.2) := by + apply Finset.sum_congr_set (s := {p : Fin n × Fin n | p.1 < p.2}) + · intro p hp + simp [f,show p.1 < p.2 from hp] + · intro p hp + simp [f,show ¬p.1 < p.2 from hp] + have he : (∑ i : Fin n, ∑ j : Fin n, f (j,i)) = ∑ i : Fin n, ∑ j : Fin n, f (i,j) := + Finset.sum_comm + simp only [hamiltonian,Pi.zero_apply,zero_mul,Finset.sum_const_zero,add_zero,hh, + Finset.sum_add_distrib] + rw [he,←Fintype.sum_prod_type,hs] + ring + +lemma gaussianReal_tilt (μ : ℝ) (v : ℝ≥0) (a : ℝ) : + (gaussianReal μ v).withDensity + (fun z => ENNReal.ofReal (exp (a*z-(a*μ+(v:ℝ)*a^2/2)))) = + gaussianReal (μ+(v:ℝ)*a) v := by + by_cases hv : v=0 + · subst v + simp [dirac_withDensity] + have hvr : (v:ℝ) ≠ 0 := by exact_mod_cast hv + rw [gaussianReal_of_var_ne_zero _ hv,gaussianReal_of_var_ne_zero _ hv, + ←withDensity_mul volume (measurable_gaussianPDF _ _) (by fun_prop)] + congr 1 + funext z + simp only [Pi.mul_apply,gaussianPDF_def,←ENNReal.ofReal_mul (gaussianPDFReal_nonneg _ _ _)] + congr 1 + simp only [gaussianPDFReal_def,mul_assoc,←exp_add] + congr 2 + field_simp + ring + +lemma lintegral_fin_nat_prod_eq_prod {k : ℕ} {E : Fin k → Type*} + {mE : ∀ i, MeasurableSpace (E i)} {μ : (i : Fin k) → Measure (E i)} + [∀ i, SigmaFinite (μ i)] (f : (i : Fin k) → E i → ℝ≥0∞) + (hf : ∀ i, Measurable (f i)) : + (∫⁻ x : (i : Fin k) → E i, ∏ i, f i (x i) ∂Measure.pi μ) = + ∏ i, ∫⁻ x, f i x ∂μ i := by + classical + induction k with + | zero => simp + | succ k ih => + calc + _ = ∫⁻ x : E 0 × ((i : Fin k) → E i.succ), + f 0 x.1 * ∏ i : Fin k, f i.succ (x.2 i) + ∂((μ 0).prod (Measure.pi (fun i => μ i.succ))) := by + let e : E 0 × ((i : Fin k) → E i.succ) ≃ᵐ ((i : Fin (k+1)) → E i) := + (MeasurableEquiv.piFinSuccAbove E 0).symm + have he : MeasurePreserving e + ((μ 0).prod (Measure.pi (fun i => μ i.succ))) (Measure.pi μ) := + (measurePreserving_piFinSuccAbove μ 0).symm + rw [← he.lintegral_comp_emb e.measurableEmbedding] + congr 1 + funext x + change (∏ i, f i (Fin.insertNthEquiv E 0 x i)) = _ + rw [Fin.insertNthEquiv_zero] + change (∏ i, f i (Fin.cons x.1 x.2 i)) = _ + rw [Fin.prod_univ_succ] + rfl + _ = (∫⁻ x, f 0 x ∂μ 0) * ∏ i : Fin k, ∫⁻ x, f i.succ x ∂μ i.succ := by + rw [lintegral_prod_mul (hf 0).aemeasurable + (g := fun x : (i : Fin k) → E i.succ => ∏ i, f i.succ (x i)) + ((Finset.measurable_prod _ (fun i _ => (hf _).comp (measurable_pi_apply i))).aemeasurable)] + rw [ih _ (fun i => hf _)] + _ = _ := by rw [Fin.prod_univ_succ] + +lemma lintegral_fintype_prod_eq_prod {ι : Type*} [Fintype ι] {E : ι → Type*} + {mE : ∀ i, MeasurableSpace (E i)} {μ : (i : ι) → Measure (E i)} + [∀ i, SigmaFinite (μ i)] (f : (i : ι) → E i → ℝ≥0∞) + (hf : ∀ i, Measurable (f i)) : + (∫⁻ x : (i : ι) → E i, ∏ i, f i (x i) ∂Measure.pi μ) = + ∏ i, ∫⁻ x, f i x ∂μ i := by + classical + let e := (Fintype.equivFin ι).symm + rw [← (measurePreserving_piCongrLeft _ e).lintegral_comp_emb + (MeasurableEquiv.measurableEmbedding _)] + simp_rw [← e.prod_comp,MeasurableEquiv.coe_piCongrLeft,Equiv.piCongrLeft_apply_apply] + exact lintegral_fin_nat_prod_eq_prod _ (fun i => hf _) + +lemma product_tilt {ι : Type*} [Fintype ι] (μ : ι → ℝ) (v : ι → ℝ≥0) (a : ι → ℝ) : + (Measure.pi (fun i => gaussianReal (μ i) (v i))).withDensity + (fun z : ι → ℝ => ENNReal.ofReal (exp (∑ i : ι, (a i*z i-(a i*μ i+(v i:ℝ)*(a i)^2/2))))) = + Measure.pi (fun i => gaussianReal (μ i+(v i:ℝ)*a i) (v i)) := by + symm + apply Measure.pi_eq + intro s hs + rw [withDensity_apply _ (MeasurableSet.univ_pi hs)] + rw [Measure.restrict_pi_pi] + simp only [exp_sum,ENNReal.ofReal_prod_of_nonneg (fun _ _ => (exp_pos _).le)] + rw [lintegral_fintype_prod_eq_prod + (fun i (z : ℝ) => ENNReal.ofReal (exp (a i*z-(a i*μ i+(v i:ℝ)*(a i)^2/2)))) + (by intro i; fun_prop)] + apply Finset.prod_congr rfl + intro i _ + rw [←gaussianReal_tilt (μ i) (v i) (a i),withDensity_apply _ (hs i)] + +def law (β : ℝ) (n : ℕ) : Measure (Disorder n) := + Measure.pi (fun _ : Edge n => gaussianReal (β^2/(n:ℝ)) (Real.toNNReal (β^2/n))) + +instance law_probability (β : ℝ) (n : ℕ) : IsProbabilityMeasure (law β n) := + inferInstanceAs (IsProbabilityMeasure (Measure.pi _)) + +def normalizingExponent (β : ℝ) (n : ℕ) : ℝ := + (Fintype.card (Edge n) : ℝ)*(β^2/n)/2 + +lemma law_density (β : ℝ) (n : ℕ) : + (disorderLaw β n).withDensity + (fun g => ENNReal.ofReal (exp (hamiltonian g 0 (plusSpin n)-normalizingExponent β n))) = + law β n := by + have hv : (Real.toNNReal (β^2/(n:ℝ)) : ℝ) = β^2/n := + Real.coe_toNNReal _ (div_nonneg (sq_nonneg _) (Nat.cast_nonneg _)) + have ht := product_tilt (ι := Edge n) (fun _ => 0) (fun _ => Real.toNNReal (β^2/n)) (fun _ => 1) + simpa only [law,disorderLaw,hamiltonian_edges,plusSpin,spinValue,↓reduceIte, + one_mul,mul_one,one_pow,zero_mul,zero_add,hv,Finset.sum_sub_distrib, + Finset.sum_const,Finset.card_univ,nsmul_eq_mul,normalizingExponent,mul_div_assoc] using ht + +lemma gauge_preserving (β : ℝ) (x : Spin n) : + MeasurePreserving (gauge x) (disorderLaw β n) (disorderLaw β n) := by + refine ⟨(gauge_continuous x).measurable,?_⟩ + unfold disorderLaw gauge + rw [Measure.pi_map_pi (f := fun (e : Edge n) (z : ℝ) => spinValue (x e.1.1)*z*spinValue (x e.1.2)) + (by intro e; fun_prop)] + congr 1 + funext e + cases x e.1.1 <;> cases x e.1.2 <;> + simp [spinValue,gaussianReal_map_neg] + +lemma integrable_exp_linear {ι : Type*} [Fintype ι] + (μ : ι → ℝ) (v : ι → ℝ≥0) (a : ι → ℝ) : + Integrable (fun z : ι → ℝ => exp (∑ i, a i*z i)) + (Measure.pi (fun i => gaussianReal (μ i) (v i))) := by + simp_rw [exp_sum] + exact Integrable.fintype_prod (fun i => integrable_exp_mul_gaussianReal (a i)) + +lemma integral_exp_linear {ι : Type*} [Fintype ι] + (μ : ι → ℝ) (v : ι → ℝ≥0) (a : ι → ℝ) : + (∫ z : ι → ℝ, exp (∑ i, a i*z i) ∂Measure.pi (fun i => gaussianReal (μ i) (v i))) = + exp (∑ i, (a i*μ i+(v i:ℝ)*(a i)^2/2)) := by + simp_rw [exp_sum] + rw [integral_fintype_prod_eq_prod (fun i (z : ℝ) => exp (a i*z))] + apply Finset.prod_congr rfl + intro i _ + simpa only [mgf,id_eq,mul_comm (μ i) (a i)] using + mgf_gaussianReal (μ := μ i) (v := v i) (X := id) (p := gaussianReal (μ i) (v i)) + (by simp) (a i) + +lemma weight_linear (g : Disorder n) (x : Spin n) : + weight g 0 x = exp (∑ e : Edge n, (spinValue (x e.1.1)*spinValue (x e.1.2))*g e) := by + rw [weight,hamiltonian_edges] + congr 1 + apply Finset.sum_congr rfl + intro e _ + ring + +lemma weight_integrable (β : ℝ) (x : Spin n) : + Integrable (fun g => weight g 0 x) (disorderLaw β n) := by + simp_rw [weight_linear] + exact integrable_exp_linear _ _ _ + +lemma integral_weight (β : ℝ) (x : Spin n) : + (∫ g, weight g 0 x ∂disorderLaw β n) = exp (normalizingExponent β n) := by + simp_rw [weight_linear] + rw [disorderLaw,integral_exp_linear] + have hs (e : Edge n) : (spinValue (x e.1.1)*spinValue (x e.1.2))^2 = 1 := by + change (spin x e.1.1*spin x e.1.2)^2 = 1 + rw [mul_pow,spin_sq,spin_sq,mul_one] + simp only [mul_zero,zero_add,hs,mul_one,Real.coe_toNNReal _ + (div_nonneg (sq_nonneg _) (Nat.cast_nonneg _)),Finset.sum_const, + Finset.card_univ,nsmul_eq_mul,normalizingExponent,mul_div_assoc] + +lemma partition_integrable (β : ℝ) (n : ℕ) : + Integrable (fun g : Disorder n => partition g 0) (disorderLaw β n) := + integrable_finsetSum _ (fun x _ => weight_integrable β x) + +lemma integral_partition (β : ℝ) (n : ℕ) : + (∫ g : Disorder n, partition g 0 ∂disorderLaw β n) = + (2:ℝ)^n*exp (normalizingExponent β n) := by + change (∫ g, ∑ x : Spin n, weight g 0 x ∂disorderLaw β n) = _ + rw [integral_finsetSum _ (fun x _ => weight_integrable β x)] + simp only [integral_weight,Finset.sum_const,Finset.card_univ,nsmul_eq_mul, + Fintype.card_fun,Fintype.card_bool,Fintype.card_fin,Nat.cast_pow,Nat.cast_ofNat] + +def badWeight (B : Set (Disorder n)) (g : Disorder n) : ℝ := + ∑ x : Spin n, if gauge x g ∈ B then weight g 0 x else 0 + +lemma badWeight_nonneg (B : Set (Disorder n)) (g : Disorder n) : 0 ≤ badWeight B g := by + apply Finset.sum_nonneg + intro x _ + split_ifs + · exact (weight_pos g 0 x).le + · rfl + +lemma badWeight_le_partition (B : Set (Disorder n)) (g : Disorder n) : + badWeight B g ≤ partition g 0 := by + apply Finset.sum_le_sum + intro x _ + split_ifs + · rfl + · exact (weight_pos g 0 x).le + +lemma badWeight_integrable (β : ℝ) {B : Set (Disorder n)} (hB : MeasurableSet B) : + Integrable (badWeight B) (disorderLaw β n) := by + apply integrable_finsetSum + intro x _ + exact (weight_integrable β x).indicator (hB.preimage (gauge_continuous x).measurable) + +lemma integral_planted_weight (β : ℝ) {B : Set (Disorder n)} (hB : MeasurableSet B) : + (∫ g, if g ∈ B then weight g 0 (plusSpin n) else 0 ∂disorderLaw β n) = + exp (normalizingExponent β n)*(law β n).real B := by + have hn := law_density β n + have he := congrArg (fun μ : Measure (Disorder n) => μ B) hn + rw [withDensity_apply _ hB] at he + have hi : Integrable (fun g : Disorder n => exp (hamiltonian g 0 (plusSpin n)- + normalizingExponent β n)) (disorderLaw β n) := by + simp only [exp_sub] + exact (weight_integrable β (plusSpin n)).div_const _ + have he' := congrArg ENNReal.toReal he + rw [← integral_eq_lintegral_of_nonneg_ae (Filter.Eventually.of_forall (fun g => (exp_pos _).le)) + (hi.restrict).aestronglyMeasurable] at he' + simp only [exp_sub,integral_div] at he' + change (∫ g, B.indicator (fun g => weight g 0 (plusSpin n)) g ∂disorderLaw β n) = _ + rw [integral_indicator hB] + exact (div_eq_iff (exp_ne_zero _)).mp he' |>.trans (mul_comm _ _) + +lemma integral_badWeight (β : ℝ) {B : Set (Disorder n)} (hB : MeasurableSet B) : + (∫ g, badWeight B g ∂disorderLaw β n) = + ((2:ℝ)^n*exp (normalizingExponent β n))*(law β n).real B := by + unfold badWeight + rw [integral_finsetSum _ (fun x _ => show + Integrable (fun g => if gauge x g ∈ B then weight g 0 x else 0) (disorderLaw β n) from by + change Integrable ((gauge x ⁻¹' B).indicator (fun g => weight g 0 x)) (disorderLaw β n) + exact (weight_integrable β x).indicator (hB.preimage (gauge_continuous x).measurable))] + have he (x : Spin n) : + (∫ g, if gauge x g ∈ B then weight g 0 x else 0 ∂disorderLaw β n) = + exp (normalizingExponent β n)*(law β n).real B := by + have hw (g : Disorder n) : weight (gauge x g) 0 (plusSpin n) = weight g 0 x := by + rw [weight,hamiltonian_gauge,signProduct_plus,←weight] + rw [←integral_planted_weight β hB] + let e : Disorder n ≃ᵐ Disorder n := + { toFun := gauge x + invFun := gauge x + left_inv := gauge_twice x + right_inv := gauge_twice x + measurable_toFun := (gauge_continuous x).measurable + measurable_invFun := (gauge_continuous x).measurable } + have hh := (gauge_preserving β x).integral_comp e.measurableEmbedding + (fun g => if g ∈ B then weight g 0 (plusSpin n) else 0) + simpa only [hw] using hh + simp only [he,Finset.sum_const,Finset.card_univ,nsmul_eq_mul, + Fintype.card_fun,Fintype.card_bool,Fintype.card_fin,Nat.cast_pow,Nat.cast_ofNat,mul_assoc] + +end SKRatio.Planted + +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Gaussian/PlantedCriterion.lean b/lean/OAI/Probability/SKRatio/Gaussian/PlantedCriterion.lean new file mode 100644 index 0000000000000000000000000000000000000000..5ec98b498d27c46ba98eacd53b3e0abeec9db82a --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Gaussian/PlantedCriterion.lean @@ -0,0 +1,226 @@ +import Mathlib +import OAI.Probability.SKRatio.Calculus.SmallTemperature +import OAI.Probability.SKRatio.Gaussian.GaussianFunctional +import OAI.Probability.SKRatio.Entropy.AnnealedTransfer + +namespace OAI + +section +noncomputable section +open scoped BigOperators Topology +open MeasureTheory ProbabilityTheory Real Filter +namespace SKRatio.Planted +open Calculus +attribute [local instance] Classical.propDecidable +variable {n : ℕ} + +lemma continuous_field (x : Spin n) (i : Fin n) : + Continuous (fun g : Disorder n => field (coupling g) x i) := by + unfold field + exact continuous_finsetSum _ (fun j _ => (continuous_coupling i j).mul_const _) + +lemma continuous_mean (x : Spin n) (i : Fin n) : + Continuous (fun g : Disorder n => mean (coupling g) x i) := + (continuous_iff_continuousAt.mpr (fun y => (hasDerivAt_tanh y).continuousAt)).comp + (continuous_field x i) + +lemma continuous_conditionalVariance (x : Spin n) (i : Fin n) : + Continuous (fun g : Disorder n => conditionalVariance (coupling g) x i) := by + unfold conditionalVariance + exact continuous_const.sub ((continuous_mean x i).pow 2) + +lemma continuous_gradientWeight (x : Spin n) (i : Fin n) : + Continuous (fun g : Disorder n => gradientWeight (coupling g) x i) := by + unfold gradientWeight + exact continuous_const.sub ((continuous_mean x i).const_mul _) + +lemma continuous_gradientForm (p : Fin n → ℝ) : + Continuous (fun g : Disorder n => gradientForm (coupling g) p) := by + unfold gradientForm pairSum + apply Continuous.add + · apply Continuous.add + · exact continuous_finsetSum _ (fun i _ => continuous_finsetSum _ (fun j _ => + (((continuous_coupling i j).mul_const _).mul + (continuous_conditionalVariance _ j)).mul_const _)) + · apply Continuous.const_mul + exact continuous_finsetSum _ (fun i _ => continuous_finsetSum _ (fun j _ => + (((((continuous_coupling i j).pow 2).mul_const _).mul + (continuous_mean _ j)).mul (continuous_conditionalVariance _ j)).mul_const _)) + · apply continuous_finsetSum + intro i _ + apply continuous_finsetSum + intro j _ + apply Continuous.div + · exact ((continuous_coupling i j).pow 2).mul + ((((continuous_conditionalVariance _ j).mul_const _).add + ((continuous_conditionalVariance _ i).mul_const _)).pow 2) + · exact (continuous_gradientWeight _ i).add (continuous_gradientWeight _ j) + · intro g + exact (add_pos (gradientWeight_pos _ _ _) (gradientWeight_pos _ _ _)).ne' + +def formBad (ρ : ℝ) (n : ℕ) : Set (Disorder n) := + {g | ∃ p : Fin n → ℝ, (1-ρ)*(∑ i, p i^2) < gradientForm (coupling g) p} + +lemma formBad_measurable (ρ : ℝ) (n : ℕ) : MeasurableSet (formBad ρ n) := by + have he : formBad ρ n = ⋃ p : Fin n → ℝ, + {g | (1-ρ)*(∑ i, p i^2) < gradientForm (coupling g) p} := by + ext g + simp [formBad] + rw [he] + exact (isOpen_iUnion (fun p => isOpen_lt continuous_const (continuous_gradientForm p))).measurableSet + +lemma gradientForm_smul (J : Interaction n) (p : Fin n → ℝ) (a : ℝ) : + gradientForm J (fun i => a*p i) = a^2*gradientForm J p := by + unfold gradientForm pairSum + simp only [mul_add,Finset.mul_sum,mul_div_assoc] + congr 1 + · congr 1 + · apply Finset.sum_congr rfl + intro i _ + apply Finset.sum_congr rfl + intro j _ + ring + · apply Finset.sum_congr rfl + intro i _ + apply Finset.sum_congr rfl + intro j _ + ring + · apply Finset.sum_congr rfl + intro i _ + apply Finset.sum_congr rfl + intro j _ + ring + +lemma gradientForm_zero (J : Interaction n) : gradientForm J 0 = 0 := by + simp [gradientForm,pairSum] + +lemma formBad_iff_unit (ρ : ℝ) (g : Disorder n) : + g ∈ formBad ρ n ↔ ∃ p : Fin n → ℝ, (∑ i, p i^2) = 1 ∧ + 1-ρ < gradientForm (coupling g) p := by + constructor + · rintro ⟨p,hp⟩ + have hnorm0 : 0 ≤ ∑ i, p i^2 := Finset.sum_nonneg (fun _ _ => sq_nonneg _) + have hnorm : 0 < ∑ i, p i^2 := by + by_contra h + have hz : ∑ i, p i^2 = 0 := le_antisymm (not_lt.mp h) hnorm0 + have hp0 : p = 0 := by + funext i + have hi : p i^2 ≤ 0 := by + rw [←hz] + exact Finset.single_le_sum (fun j _ => sq_nonneg (p j)) (Finset.mem_univ i) + have : p i = 0 := by nlinarith [sq_nonneg (p i)] + exact this + rw [hp0,gradientForm_zero] at hp + simp at hp + let a := (sqrt (∑ i, p i^2))⁻¹ + have ha : 0 < a := inv_pos.mpr (sqrt_pos.mpr hnorm) + have ha2 : a^2*(∑ i, p i^2) = 1 := by + dsimp [a] + rw [inv_pow,sq_sqrt hnorm0,inv_mul_cancel₀ hnorm.ne'] + refine ⟨fun i => a*p i,?_,?_⟩ + · simp only [mul_pow,←Finset.mul_sum] + exact ha2 + · rw [gradientForm_smul] + have ht := mul_lt_mul_of_pos_left hp (sq_pos_of_pos ha) + have he : a^2*((1-ρ)*(∑ i, p i^2)) = (1-ρ)*(a^2*(∑ i, p i^2)) := by ring + rw [he,ha2,mul_one] at ht + exact ht + · rintro ⟨p,hp,h⟩ + exact ⟨p,by simpa only [hp,mul_one] using h⟩ + +lemma gradient_drift_of_form_good {ρ : ℝ} (g : Disorder n) + (hsmall : ∀ i j, |coupling g i j| ≤ 1/10) + (hR : 16*R3 (coupling g) ≤ ρ/2) (f : Observables n) (x : Spin n) + (hx : gauge x g ∉ formBad ρ n) : + (∑ i, 2*halfDiff i f x*halfDiff i (generator (coupling g) f) x) - + generator (coupling g) (unweightedGradient f) x ≤ -ρ*unweightedGradient f x := by + have hlocal := pointwise_gradient_local_bound (coupling g) (coupling_symm g) + (coupling_diag g) hsmall f 0 x + rw [(unweightedGradient_hasDerivAt (coupling g) f x 0).deriv] at hlocal + simp only [semigroup_zero,one_apply_eq_self] at hlocal + have hf : gradientForm (coupling (gauge x g)) (fun i => spin x i*halfDiff i f x) ≤ + (1-ρ)*(∑ i, (spin x i*halfDiff i f x)^2) := by + by_contra h + exact hx ⟨_,not_le.mp h⟩ + simp only [coupling_gauge,mul_pow,spin_sq,one_mul] at hf + change gradientForm _ _ ≤ (1-ρ)*unweightedGradient f x at hf + have hU : 0 ≤ unweightedGradient f x := unweightedGradient_nonneg f x + have hRU := mul_le_mul_of_nonneg_right hR hU + linarith only [hlocal,hf,hRU] + +lemma gradient_drift_rough (g : Disorder n) + (hsmall : ∀ i j, |coupling g i j| ≤ 1/10) + (hnorm : euclideanOpNorm (coupling g) ≤ 2) + (hR2 : R2 (coupling g) ≤ 1) (hR3 : 16*R3 (coupling g) ≤ 1) + (f : Observables n) (x : Spin n) : + (∑ i, 2*halfDiff i f x*halfDiff i (generator (coupling g) f) x) - + generator (coupling g) (unweightedGradient f) x ≤ 8*unweightedGradient f x := by + have hr := gradient_global_bound (coupling g) (coupling_symm g) (coupling_diag g) hsmall f 0 x + rw [(unweightedGradient_hasDerivAt (coupling g) f x 0).deriv] at hr + simp only [semigroup_zero,one_apply_eq_self] at hr + have hc : 2*(-1+euclideanOpNorm (coupling g)+(4/(3*sqrt 3)+32/27)*R2 (coupling g)+ + 16*R3 (coupling g)) ≤ 8 := by + have hh := mul_le_mul_of_nonneg_right rough_coefficient_lt_two.le + (rowControl_nonneg (coupling g) 2) + linarith + exact hr.trans (mul_le_mul_of_nonneg_right hc (unweightedGradient_nonneg f x)) + +theorem ratio_cutoff_of_planted_form (β ε η : ℝ) + (hβ : 0 ≤ β) (hβhalf : β < 1/2) + (hε : 0 < ε) (hεhalf : ε < 1/2) (hη : 0 < η) + {ρ κ : ℝ} (hρ : 0 < ρ) (hκ : 0 < κ) + (hplant : ∀ᶠ n : ℕ in atTop, + law β n (formBad ρ n) ≤ ENNReal.ofReal (exp (-κ*n))) : + Tendsto (fun n : ℕ => disorderLaw β n + {g : Disorder n | 1+η < + (mixingTime g ε : ℝ)/(mixingTime g (1-ε) : ℝ)}) atTop (𝓝 0) ∧ + (∀ᶠ n : ℕ in atTop, ∀ g : Disorder n, 0 < mixingTime g (1-ε)) := by + have hb2 : β^2 ≤ 1/4 := by nlinarith + obtain ⟨H,hHm,hHp,hHs⟩ := annealed_transfer_events + (show β^2 ≤ 1/2 by linarith) hκ (formBad ρ) (formBad_measurable ρ) hplant + let δ := min (1/100:ℝ) (ρ/32) + have hd : 0 < δ := lt_min (by norm_num) (by positivity) + have hd1 : δ ≤ 1/100 := min_le_left _ _ + have hdρ : δ ≤ ρ/32 := min_le_right _ _ + let c := min ρ (κ/2) + have hc : 0 < c := lt_min hρ (by positivity) + have hcρ : c ≤ ρ := min_le_left _ _ + have hcκ : c ≤ κ/2 := min_le_right _ _ + let G : ∀ n : ℕ, Set (Disorder n) := fun n => H n ∩ Gaussian.matrixGood β δ n + let bad : ∀ n : ℕ, Disorder n → Set (Spin n) := fun n g => {x | gauge x g ∈ formBad ρ n} + have hGp : Tendsto (fun n => disorderLaw β n (G n)ᶜ) atTop (𝓝 0) := by + have hb (n : ℕ) : disorderLaw β n (G n)ᶜ ≤ disorderLaw β n (H n)ᶜ + + disorderLaw β n (Gaussian.matrixGood β δ n)ᶜ := by + simp only [G,Set.compl_inter] + exact measure_union_le _ _ + exact tendsto_of_tendsto_of_tendsto_of_le_of_le tendsto_const_nhds + (by simpa only [add_zero] using hHp.add (Gaussian.matrixGood_probability hβ hd)) + (fun _ => bot_le) hb + apply Gaussian.ratio_cutoff_of_typical_gradient β ε η hβ hβhalf hε hεhalf hη G bad hc + (by linarith : 0 ≤ 8+c) hGp + · intro n g hg + change badMass (formBad ρ n) g ≤ exp (-c*n) + exact (hHs n g hg.1).trans (exp_le_exp.mpr (by nlinarith [show (0:ℝ) ≤ n from Nat.cast_nonneg n])) + · intro n g hg f x + have hnorm : euclideanOpNorm (coupling g) ≤ 2 := hg.2.1.trans (by linarith) + have hrow (i : Fin n) : ∑ j, coupling g i j^2 ≤ 1 := (hg.2.2.2 i).trans (by linarith) + have hR2 : R2 (coupling g) ≤ 1 := rowControl_le _ 2 zero_le_one + (by intro i; simpa only [sq_abs] using hrow i) + have hR3 : R3 (coupling g) ≤ δ := by + simpa only [mul_one] using R3_le_entry_times_row (coupling g) hd.le zero_le_one hg.2.2.1 hrow + have hsmall : ∀ i j, |coupling g i j| ≤ 1/10 := fun i j => (hg.2.2.1 i j).trans (by linarith) + by_cases hx : x ∈ bad n g + · rw [ite_eq_left hx] + have hr := gradient_drift_rough g hsmall hnorm hR2 (by linarith) f x + convert hr using 1 + ring + · rw [ite_eq_right hx,add_zero] + exact (gradient_drift_of_form_good g hsmall (by linarith) f x hx).trans + (mul_le_mul_of_nonneg_right (neg_le_neg hcρ) (unweightedGradient_nonneg f x)) + +end SKRatio.Planted + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Gaussian/PlantedEmpirical.lean b/lean/OAI/Probability/SKRatio/Gaussian/PlantedEmpirical.lean new file mode 100644 index 0000000000000000000000000000000000000000..6a4400641586d8946708c89b5e4c16937f074362 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Gaussian/PlantedEmpirical.lean @@ -0,0 +1,194 @@ +import Mathlib +import OAI.Probability.SKRatio.Gaussian.GaussianEmpirical +import OAI.Probability.SKRatio.Matrices.PlantedGOE +import OAI.Probability.SKRatio.Matrices.GaussianSquareTails +import OAI.Probability.SKRatio.Variational.ScalarMoments + +namespace OAI + +section +noncomputable section +open scoped BigOperators NNReal ENNReal Topology +open MeasureTheory ProbabilityTheory Filter Real +namespace SKRatio.Planted +open SKRatioClock.Regression + +def modelField (β : ℝ) (n : ℕ) : (Option (Fin n) → ℝ) → Fin n → ℝ := + sharedGaussianField (β^2) β (β/sqrt n) + +lemma modelField_measurable (β : ℝ) (n : ℕ) : Measurable (modelField β n) := by + unfold modelField sharedGaussianField + fun_prop + +lemma fieldLaw_eq_affine_map (β : ℝ) : Scalar.fieldLaw β = + (gaussianReal 0 1).map (fun z : ℝ => β^2+β*z) := by + have hid : (fun z : ℝ => β^2+β*z) = (fun z : ℝ => β^2+z) ∘ (fun z : ℝ => β*z) := rfl + rw [hid,←Measure.map_map (by fun_prop) (by fun_prop),gaussianReal_map_const_mul, + gaussianReal_map_const_add] + simp only [mul_zero,zero_add,mul_one,Scalar.fieldLaw] + congr 1 + apply NNReal.eq + simp only [Scalar.variance_coe,NNReal.coe_mk] + +lemma fieldLaw_secondMoment (β : ℝ) : + (∫ h, h^2 ∂Scalar.fieldLaw β) = β^2+β^4 := by + have hv := variance_eq_sub (Scalar.memLp_field β) + change _ = (∫ h, h^2 ∂Scalar.fieldLaw β)-(∫ h, h ∂Scalar.fieldLaw β)^2 at hv + have hm : (∫ h, h ∂Scalar.fieldLaw β) = β^2 := integral_id_gaussianReal + have hvar : Var[(fun h : ℝ => h); Scalar.fieldLaw β] = β^2 := by + change Var[id; gaussianReal (β^2) (Scalar.variance β)] = β^2 + rw [variance_id_gaussianReal,Scalar.variance_coe] + rw [hm,hvar] at hv + nlinarith only [hv] + +lemma common_field_convergence (β : ℝ) (hβ : 0 < β) : + ExponentialConvergence (fun n => standardArrayLaw (Option (Fin n))) + (fun n g => (β/sqrt (n:ℝ))*g none) 0 := by + intro ε hε + refine ⟨2,ε^2/(2*β^2),by norm_num,by positivity,?_⟩ + filter_upwards [eventually_gt_atTop 0] with n hn + have hnR : (0:ℝ) standardArrayLaw (Option (Fin n))) (modelField β) := by + let ρ := fun n => standardArrayLaw (Option (Fin n)) + have hi : ExponentialSquareTails ρ (fun _ g i => g (some i)) := by + exact iid_exponential_squareTails ρ _ (fun _ _ => measurable_pi_apply _) + (fun _ => coordinates_independent.precomp (Option.some_injective _)) + (gaussianReal 0 1) (fun _ _ => coordinate_hasLaw _) gaussian_integrable_exp_quarter_sq + have ha := hi.bounded_mul (fun _ _ _ => β) |β| (abs_nonneg β) (fun _ _ _ => le_rfl) + have hm := exponentialSquareTails_of_bounded ρ (fun _ _ _ => β^2) (β^2) + (fun _ _ _ => by rw [abs_of_nonneg (sq_nonneg β)]) + apply (hm.add ha).l2_stability + have hz := (common_field_convergence β hβ).continuous_map + (f := fun x : ℝ => x^2) (by fun_prop) + simp only [zero_pow (by norm_num : (2:ℕ)≠0)] at hz + intro ε hε + apply (hz ε hε).mono + filter_upwards [eventually_gt_atTop 0] with n hn + intro g hg + have he : (∑ i : Fin n, (β^2+β*g (some i)-modelField β n g i)^2)/(n:ℝ) = + ((β/sqrt (n:ℝ))*g none)^2 := by + simp only [modelField,sharedGaussianField,sub_add_cancel_left,neg_sq, + Finset.sum_const,Finset.card_univ,Fintype.card_fin,nsmul_eq_mul] + field_simp + change ε ≤ dist _ 0 at hg ⊢ + rwa [he] at hg + +lemma modelField_empirical (β : ℝ) (hβ : 0 < β) : + ExponentialEmpiricalConcentration (fun n => standardArrayLaw (Option (Fin n))) + (modelField β) (Scalar.fieldLaw β) := by + intro f K hf B hB ε hε + let L : ℝ≥0 := K+1 + let D : ℝ := |B|+1 + have hL : (0:ℝ) < L := by dsimp [L]; positivity + have hD : 0 < D := by dsimp [D]; positivity + have hf' : LipschitzWith L f := hf.weaken (by simp [L]) + have hB' (z : ℝ) : |f z| ≤ D := (hB z).trans (by dsimp [D]; linarith [le_abs_self B]) + let c := min (ε^2/(8*D^2)) (ε^2/(8*(L:ℝ)^2*β^2)) + have hc : 0 < c := lt_min (by positivity) (by positivity) + refine ⟨4,c,by norm_num,hc,?_⟩ + filter_upwards [eventually_gt_atTop 0] with n hn + have hnR : (0:ℝ) < n := Nat.cast_pos.mpr hn + have ht := iid_common_shift_average_tail hn (β^2) β (β/sqrt n) + f hf' D hD.le hB' ε hε.le + have hm : (∫ z, f z ∂Scalar.fieldLaw β) = ∫ z, f (β^2+β*z) ∂gaussianReal 0 1 := by + rw [fieldLaw_eq_affine_map] + exact integral_map (by fun_prop) hf.continuous.aestronglyMeasurable + rw [hm] + change standardArrayLaw (Option (Fin n)) {g | ε ≤ + |(∑ i : Fin n, f (β^2+β*g (some i)+(β/sqrt n)*g none))/(n:ℝ) - + ∫ z, f (β^2+β*z) ∂gaussianReal 0 1|} ≤ _ + have he1 : -(ε^2*(n:ℝ))/(8*D^2) ≤ -c*n := by + have hh := mul_le_mul_of_nonneg_right (min_le_left (ε^2/(8*D^2)) (ε^2/(8*(L:ℝ)^2*β^2))) hnR.le + have he : -(ε^2*(n:ℝ))/(8*D^2) = -(ε^2/(8*D^2))*n := by ring + rw [he] + dsimp [c] + linarith only [hh] + have he2 : -ε^2/(8*(L:ℝ)^2*(β/sqrt (n:ℝ))^2) ≤ -c*n := by + have hh := mul_le_mul_of_nonneg_right (min_le_right (ε^2/(8*D^2)) (ε^2/(8*(L:ℝ)^2*β^2))) hnR.le + have he : -ε^2/(8*(L:ℝ)^2*(β/sqrt (n:ℝ))^2) = -(ε^2/(8*(L:ℝ)^2*β^2))*n := by + rw [div_pow,sq_sqrt hnR.le] + field_simp + rw [he] + dsimp [c] + linarith only [hh] + apply ht.trans + calc + _ ≤ 2*ENNReal.ofReal (exp (-c*n))+2*ENNReal.ofReal (exp (-c*n)) := by + gcongr + _ = ENNReal.ofReal (4*exp (-c*n)) := by + rw [←add_mul] + norm_num only [show (2:ENNReal)+2=4 by norm_num] + rw [ENNReal.ofReal_mul (by norm_num : (0:ℝ) ≤ 4)] + norm_num + +lemma augmentedField_event_eq {n : ℕ} (hn : 0 < n) (β : ℝ) + (E : Set (Fin n → ℝ)) (hE : MeasurableSet E) : + standardArrayLaw (Fin n × Fin n) ((augmentedField β) ⁻¹' E) = + standardArrayLaw (Option (Fin n)) ((modelField β n) ⁻¹' E) := by + have he := congrArg (fun μ : Measure (Fin n → ℝ) => μ E) (augmentedField_law hn β) + change ((standardArrayLaw (Fin n × Fin n)).map (augmentedField β)) E = + ((standardArrayLaw (Option (Fin n))).map (modelField β n)) E at he + rw [Measure.map_apply_of_aemeasurable (augmentedField_gaussian β).aemeasurable hE, + Measure.map_apply (modelField_measurable β n) hE] at he + exact he + +theorem augmentedField_empirical (β : ℝ) (hβ : 0 < β) : + ExponentialEmpiricalConcentration (fun n => standardArrayLaw (Fin n × Fin n)) + (fun _ => augmentedField β) (Scalar.fieldLaw β) := by + intro f K hf B hB ε hε + obtain ⟨C,c,hC,hc,he⟩ := modelField_empirical β hβ f K hf B hB ε hε + refine ⟨C,c,hC,hc,?_⟩ + filter_upwards [he,eventually_gt_atTop 0] with n hn hn0 + have hE : MeasurableSet {v : Fin n → ℝ | ε ≤ + |(∑ i, f (v i))/(n:ℝ) - ∫ z, f z ∂Scalar.fieldLaw β|} := by + apply measurableSet_le measurable_const + exact (((Finset.measurable_sum _ (fun i _ => hf.continuous.measurable.comp + (measurable_pi_apply i))).div_const _).sub_const _).abs + exact (augmentedField_event_eq hn0 β _ hE).le.trans hn + +theorem augmentedField_squareTails (β : ℝ) (hβ : 0 < β) : + ExponentialSquareTails (fun n => standardArrayLaw (Fin n × Fin n)) + (fun _ => augmentedField β) := by + intro ε hε + obtain ⟨R,hR,C,c,hC,hc,he⟩ := modelField_squareTails β hβ ε hε + refine ⟨R,hR,C,c,hC,hc,?_⟩ + filter_upwards [he,eventually_gt_atTop 0] with n hn hn0 + have hE : MeasurableSet {v : Fin n → ℝ | ε ≤ (∑ i, squareTail R (v i))/(n:ℝ)} := by + exact measurableSet_le measurable_const ((Finset.measurable_sum _ + (fun i _ => (measurable_squareTail R).comp (measurable_pi_apply i))).div_const _) + exact (augmentedField_event_eq hn0 β _ hE).le.trans hn + +theorem augmentedField_secondMoment (β : ℝ) (hβ : 0 < β) : + ExponentialConvergence (fun n => standardArrayLaw (Fin n × Fin n)) + (fun n g => (∑ i, augmentedField β g i^2)/(n:ℝ)) (β^2+β^4) := by + have he := (augmentedField_empirical β hβ).secondMoment + (augmentedField_squareTails β hβ) (Scalar.memLp_field β).integrable_sq + rwa [fieldLaw_secondMoment] at he + +end SKRatio.Planted + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Gaussian/PlantedEntries.lean b/lean/OAI/Probability/SKRatio/Gaussian/PlantedEntries.lean new file mode 100644 index 0000000000000000000000000000000000000000..a0b758ac0334025fc2425b792b6e8355f3166bf2 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Gaussian/PlantedEntries.lean @@ -0,0 +1,82 @@ +import Mathlib +import OAI.Probability.SKRatio.Matrices.PlantedSquares + +namespace OAI + +section +noncomputable section +open scoped BigOperators NNReal ENNReal Topology +open MeasureTheory ProbabilityTheory Filter Set Real +namespace SKRatio.Planted +open SKRatioClock.Regression MatrixNet +attribute [local instance] Classical.propDecidable + +lemma affine_coordinates_max_rare (β : ℝ) {u : ℝ} (hu : 0 standardArrayLaw (I n)) + (fun n => {z | ∃ i, u < |β/sqrt n*z i+β^2/(n:ℝ)|}) := by + by_cases hβ : β=0 + · apply (exponentiallyRare_empty (fun n => standardArrayLaw (I n))).mono + refine Eventually.of_forall ?_ + intro n z hz + obtain ⟨i,hi⟩ := hz + simp [hβ] at hi + linarith + have hβ2 : 0<β^2 := sq_pos_of_ne_zero hβ + have hc : 0 standardArrayLaw (I n)) + (fun n i => {z | u < |β/sqrt n*z i+β^2/(n:ℝ)|}) hc + (by norm_num : (0:ℝ)<2) hD k hcard he + apply hr.mono + exact Eventually.of_forall (fun n z hz => mem_iUnion.mpr hz) + +lemma affine_max_entry_rare (β : ℝ) {u : ℝ} (hu : 0 standardArrayLaw (Edge n)) + (fun n => {z | ∃ e : Edge n, u < |affineDisorder β z e|}) := by + apply affine_coordinates_max_rare β hu (Edge) (D := 1) (by norm_num) 2 + refine Eventually.of_forall ?_ + intro n + have hc := Fintype.card_subtype_le (fun e : Fin n × Fin n => e.1 disorderLaw β n + {g : Disorder n | 1 + η < + (mixingTime g ε : ℝ) / (mixingTime g (1 - ε) : ℝ)}) + atTop (𝓝 0) ∧ + (∀ᶠ n : ℕ in atTop, ∀ g : Disorder n, 0 < mixingTime g (1 - ε)) := by + by_cases hsmall : β ≤ 7/20 + · exact ratio_cutoff_small_temperature β ε η hβ0 hsmall hε0 hεhalf hη + · exact Planted.ratio_cutoff_of_scalar β ε η (9969/10000) + (by linarith) hβhalf hε0 hεhalf hη (by norm_num) + (fun _ _ hb hr hn => Certificate.variational_bound + (by linarith) hβhalf.le hb hr hn) + +end SKRatio + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Matrices/AbsMulEntryBound.lean b/lean/OAI/Probability/SKRatio/Matrices/AbsMulEntryBound.lean new file mode 100644 index 0000000000000000000000000000000000000000..4c421ae8a78e6a3facbdad7755989ec25cacd7eb --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Matrices/AbsMulEntryBound.lean @@ -0,0 +1,157 @@ +import Mathlib +import OAI.Probability.SKRatio.Matrices.GaussianCoordinateMemLp +import OAI.Probability.SKRatio.Matrices.IntegralAbsSet + +namespace OAI + +section +section +noncomputable section +open MeasureTheory ProbabilityTheory InformationTheory Real Set +open scoped NNReal ENNReal +open Filter +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius ENNReal NNReal +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius NNReal +noncomputable section +open MeasureTheory ProbabilityTheory Real Set Filter +open MeasureTheory.Measure +open scoped ENNReal NNReal MeasureTheory Topology +open MeasureTheory +noncomputable section +noncomputable section +open MeasureTheory Set NormedSpace +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius +noncomputable section +open Set Real +open scoped Topology +noncomputable section +open Matrix Set Filter +open scoped Topology Matrix.Norms.Frobenius +noncomputable section +open Matrix NormedSpace ContinuousLinearMap +open scoped Matrix.Norms.Frobenius +noncomputable section +open Matrix +noncomputable section +open MeasureTheory ProbabilityTheory Real Set +open scoped ENNReal NNReal +namespace SKRatioGaussian +open Matrix MeasureTheory ProbabilityTheory Real +open scoped BigOperators Matrix.Norms.Frobenius NNReal ENNReal +variable {ι : Type*} [Fintype ι] [DecidableEq ι] + +omit [DecidableEq ι] in +lemma abs_mul_entry_bound (M K : Matrix ι ι ℝ) (C : ℝ) (hK : ∀ a b, |K a b| ≤ C) (i : ι) : + |(M*K) i i| ≤ C*∑ b, |M i b| := by + rw [Matrix.mul_apply] + apply (Finset.abs_sum_le_sum_abs _ _).trans + rw [Finset.mul_sum] + apply Finset.sum_le_sum + intro b _ + rw [abs_mul,mul_comm C] + exact mul_le_mul_of_nonneg_left (hK b i) (abs_nonneg _) + +omit [DecidableEq ι] in + +theorem goe_diagonal_inverse_loop {r : ℝ} (hr : 0 ≤ r) (a c : ι → ℝ) (i : ι) + {K : (MatrixCoordinates ι → ℝ) → Matrix ι ι ℝ} {C : ℝ} + {s : Set (MatrixCoordinates ι → ℝ)} (hK : Continuous K) + (hC : ∀ g a b, |K g a b| ≤ C) (hs : MeasurableSet s) + (he : ∀ g ∈ s, K g i i = 1+a i*((goeMatrix r g*K g) i i-c i*K g i i)) : + let μ := Measure.pi (fun _ : MatrixCoordinates ι => gaussianReal 0 1) + |(∫ g, K g i i ∂μ)- + (1+a i*((∫ g, (goeMatrix r g*K g) i i ∂μ)-c i*(∫ g, K g i i ∂μ)))| ≤ + (C+1+|a i*c i| *C)*μ.real sᶜ+ + (|a i| *C)*(Fintype.card ι:ℝ)*sqrt (2*r)*sqrt (μ.real sᶜ) := by + intro μ + have hC0 : 0 ≤ C := (abs_nonneg _).trans (hC 0 i i) + have hKi (a b : ι) : Integrable (fun g => K g a b) μ := + Integrable.mono' (integrable_const C) (hK.matrix_elem a b).aestronglyMeasurable + (ae_of_all _ (fun g => by simpa only [Real.norm_eq_abs] using hC g a b)) + have hW (b : ι) : Integrable (fun g => goeMatrix r g i b) μ := + (goeEntry_memLp r i b).integrable (by norm_num) + have hWK (b : ι) : Integrable (fun g => goeMatrix r g i b*K g b i) μ := by + simpa only [mul_comm] using (hW b).bdd_mul (hK.matrix_elem b i).aestronglyMeasurable + (ae_of_all _ (fun g => by simpa only [Real.norm_eq_abs] using hC g b i)) + have hWI : Integrable (fun g => (goeMatrix r g*K g) i i) μ := + integrable_finsetSum _ (fun b _ => hWK b) + let A := C+1+|a i*c i| *C + let B := |a i| *C + let H := fun g => A+B*∑ b, |goeMatrix r g i b| + have hHA : Integrable (fun g => ∑ b, |goeMatrix r g i b|) μ := + integrable_finsetSum _ (fun b _ => (hW b).norm) + have hHI : Integrable H μ := (integrable_const A).add (hHA.const_mul B) + have hGI : Integrable (fun g => 1+a i*((goeMatrix r g*K g) i i-c i*K g i i)) μ := + (integrable_const 1).add ((hWI.sub ((hKi i i).const_mul _)).const_mul _) + have hb (g : MatrixCoordinates ι → ℝ) : + ‖K g i i-(1+a i*((goeMatrix r g*K g) i i-c i*K g i i))‖ ≤ H g := by + rw [Real.norm_eq_abs] + have hid : K g i i-(1+a i*((goeMatrix r g*K g) i i-c i*K g i i)) = + (K g i i-1)+(a i*c i)*K g i i+(-a i)*(goeMatrix r g*K g) i i := by ring + rw [hid] + apply (abs_add_le _ _).trans + apply (add_le_add (abs_add_le _ _) le_rfl).trans + have hk1 : |K g i i-1| ≤ C+1 := (abs_sub _ _).trans (by simpa using add_le_add_right (hC g i i) 1) + have hk2 : |(a i*c i)*K g i i| ≤ |a i*c i| *C := by + rw [abs_mul]; exact mul_le_mul_of_nonneg_left (hC g i i) (abs_nonneg _) + have hk3 : |(-a i)*(goeMatrix r g*K g) i i| ≤ |a i| *(C*∑ b, |goeMatrix r g i b|) := by + rw [abs_mul,abs_neg] + exact mul_le_mul_of_nonneg_left (abs_mul_entry_bound _ _ C (hC g) i) (abs_nonneg _) + exact (add_le_add (add_le_add hk1 hk2) hk3).trans_eq (by dsimp [H,A,B]; ring) + have hraw := integral_exceptional_equal_bound hs.compl (hKi i i) hGI hHI + (fun g hg => he g (by simpa using hg)) (fun g _ => hb g) + have hbad (b : ι) : (∫ g in sᶜ, |goeMatrix r g i b| ∂μ) ≤ + sqrt (2*r)*sqrt (μ.real sᶜ) := by + apply (integral_abs_on_set_le (goeEntry_memLp r i b) hs.compl).trans + exact mul_le_mul_of_nonneg_right (sqrt_le_sqrt (goeEntry_integral_sq_le hr i b)) (sqrt_nonneg _) + have hHr : (∫ g in sᶜ, H g ∂μ) ≤ A*μ.real sᶜ+B*(Fintype.card ι:ℝ)*sqrt (2*r)*sqrt (μ.real sᶜ) := by + rw [show H = fun g => A+B*∑ b, |goeMatrix r g i b| from rfl, + integral_add (integrable_const A) ((hHA.const_mul B).mono_measure Measure.restrict_le_self), + integral_const,integral_const_mul] + have hWa (b : ι) : Integrable (fun g => |goeMatrix r g i b|) (μ.restrict sᶜ) := by + simpa only [Real.norm_eq_abs] using (hW b).norm.mono_measure Measure.restrict_le_self + rw [integral_finsetSum _ (fun b _ => hWa b)] + simp only [measureReal_restrict_apply_univ,smul_eq_mul] + calc + _ ≤ μ.real sᶜ*A+B*(∑ _b : ι, sqrt (2*r)*sqrt (μ.real sᶜ)) := + add_le_add le_rfl (mul_le_mul_of_nonneg_left (Finset.sum_le_sum (fun b _ => hbad b)) + (mul_nonneg (abs_nonneg _) hC0)) + _ = _ := by simp only [Finset.sum_const,Finset.card_univ,nsmul_eq_mul]; ring + have heI : (∫ g, 1+a i*((goeMatrix r g*K g) i i-c i*K g i i) ∂μ) = + 1+a i*((∫ g, (goeMatrix r g*K g) i i ∂μ)-c i*(∫ g, K g i i ∂μ)) := by + have ht := integral_add (integrable_const (1:ℝ)) + ((hWI.sub ((hKi i i).const_mul (c i))).const_mul (a i)) + change (∫ g, 1+a i*((goeMatrix r g*K g) i i-c i*K g i i) ∂μ) = _ at ht + rw [ht,integral_const_mul] + simp only [Pi.sub_apply] + rw [integral_sub hWI ((hKi i i).const_mul (c i)),integral_const_mul] + simp + rw [heI] at hraw + exact hraw.trans hHr + +end SKRatioGaussian + +end +end +end +end +end +end +end +end +end +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Matrices/AugmentedBounds.lean b/lean/OAI/Probability/SKRatio/Matrices/AugmentedBounds.lean new file mode 100644 index 0000000000000000000000000000000000000000..7741ffd6ce97bda1e5b61863397aaf1d2f760f15 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Matrices/AugmentedBounds.lean @@ -0,0 +1,162 @@ +import Mathlib +import OAI.Probability.SKRatio.Matrices.AugmentedSquares + +namespace OAI + +noncomputable section +open scoped BigOperators NNReal ENNReal Topology +open MeasureTheory ProbabilityTheory Filter Set Real +namespace SKRatio.Planted +open SKRatioClock.Regression MatrixNet Calculus +attribute [local instance] Classical.propDecidable +variable {n : ℕ} + +lemma shiftedDisorder_hasLaw (β : ℝ) : + HasLaw (fun g : Disorder n => fun e => g e+β^2/(n:ℝ)) (law β n) (disorderLaw β n) := by + have hi : iIndepFun (fun e (g : Disorder n) => g e) (disorderLaw β n) := + iIndepFun_pi (fun _ => measurable_id.aemeasurable) + have hl (e : Edge n) : HasLaw (fun g : Disorder n => g e) + (gaussianReal 0 (Real.toNNReal (β^2/(n:ℝ)))) (disorderLaw β n) := + (measurePreserving_eval (fun _ : Edge n => gaussianReal 0 (Real.toNNReal (β^2/(n:ℝ)))) e).hasLaw + apply iIndepFun.hasLaw_pi _ (hi.comp (fun _ x => x+β^2/(n:ℝ)) (fun _ => by fun_prop)) + intro e + simpa only [zero_add,Function.comp_def] using gaussianReal_add_const (hl e) (β^2/(n:ℝ)) + +lemma coupling_shift (β : ℝ) (g : Disorder n) : + Matrix.of (coupling (fun e => g e+β^2/(n:ℝ))) = + Matrix.of (coupling g)+Matrix.of (coupling (fun _ => β^2/(n:ℝ))) := by + ext i j + simp only [Matrix.of_apply,Matrix.add_apply,coupling] + split_ifs <;> ring + +lemma meanMatrix_opNorm_bound (β : ℝ) : + euclideanOpNorm (coupling (fun _ : Edge n => β^2/(n:ℝ))) ≤ β^2 := by + have hentry (i j : Fin n) : |coupling (fun _ : Edge n => β^2/(n:ℝ)) i j| ≤ β^2/(n:ℝ) := by + unfold coupling + split_ifs <;> simp [abs_of_nonneg (div_nonneg (sq_nonneg β) (Nat.cast_nonneg n)), + div_nonneg (sq_nonneg β) (Nat.cast_nonneg n)] + have hr (i : Fin n) : ∑ j, |coupling (fun _ : Edge n => β^2/(n:ℝ)) i j| ≤ β^2 := by + have hn : (n:ℝ) ≠ 0 := Nat.cast_ne_zero.mpr (ne_of_gt (Nat.zero_lt_of_lt i.isLt)) + calc + _ ≤ ∑ _j : Fin n, β^2/(n:ℝ) := Finset.sum_le_sum (fun j _ => hentry i j) + _ = β^2 := by simp [mul_div_cancel₀ _ hn] + exact matrix_opNorm_le_schur _ _ (sq_nonneg β) hr (fun j => by + simpa only [coupling_symm] using hr j) + +lemma shifted_opNorm_bound (β : ℝ) (g : Disorder n) : + euclideanOpNorm (coupling (fun e => g e+β^2/(n:ℝ))) ≤ + euclideanOpNorm (coupling g)+β^2 := by + change ‖Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) (Matrix.of (coupling (fun e => g e+β^2/(n:ℝ))))‖ ≤ _ + rw [coupling_shift,map_add] + apply (norm_add_le _ _).trans + apply add_le_add le_rfl + exact meanMatrix_opNorm_bound β + +lemma original_norm_rare {β δ : ℝ} (hβ : 0<β) (hδ : 0<δ) : + ExponentiallyRare (disorderLaw β) (fun n => {g : Disorder n | 2*β+δ {g : Disorder n | 2*β+β^2+δ standardArrayLaw (Fin n × Fin n)) + (fun n => {g | 2*β+β^2+δ β*goe g i i) + (gaussianReal 0 (Real.toNNReal (2*β^2/(n:ℝ)))) (standardArrayLaw (Fin n × Fin n)) := by + have hg : HasGaussianLaw (fun g : (Fin n × Fin n) → ℝ => β*goe g i i) + (standardArrayLaw (Fin n × Fin n)) := by + simpa only [ContinuousLinearMap.smulRight_apply,ContinuousLinearMap.id_apply, + smul_eq_mul,mul_comm] using (((goe_gaussian n).eval i |>.eval i).map_fun + ((ContinuousLinearMap.id ℝ ℝ).smulRight β)) + refine ⟨hg.aemeasurable,?_⟩ + rw [hg.map_eq_gaussianReal,integral_const_mul,goe_entry_mean,mul_zero, + ←covariance_self hg.aemeasurable,covariance_const_mul_left,covariance_const_mul_right, + goe_entry_covariance hn] + congr 2 + simp only [and_self,ite_true] + ring + +lemma augmented_diagonal_rare (β : ℝ) {u : ℝ} (hu : 0 standardArrayLaw (Fin n × Fin n)) + (fun n => {g | ∃ i : Fin n, u< |augmentedDiagonal β g i|}) := by + by_cases hb : β=0 + · apply (exponentiallyRare_empty (fun n => standardArrayLaw (Fin n × Fin n))).mono + refine Eventually.of_forall ?_ + intro n g hg + obtain ⟨i,hi⟩ := hg + simp [augmentedDiagonal,augmented,hb,hu.not_gt] at hi + have hb2 : 0<β^2 := sq_pos_of_ne_zero hb + have hc : 0 standardArrayLaw (Fin n × Fin n)) + (fun n i => {g | u< |augmentedDiagonal β g i|}) hc (by norm_num : (0:ℝ)<2) + (D := 1) (by norm_num) 1 (Eventually.of_forall (fun n => by simp)) hbound + apply hh.mono + exact Eventually.of_forall (fun n g hg => mem_iUnion.mpr hg) + +end SKRatio.Planted + +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Matrices/AugmentedSquares.lean b/lean/OAI/Probability/SKRatio/Matrices/AugmentedSquares.lean new file mode 100644 index 0000000000000000000000000000000000000000..7c47d4293e1a01f67f5e686e7bd58997fad60382 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Matrices/AugmentedSquares.lean @@ -0,0 +1,143 @@ +import Mathlib +import OAI.Probability.SKRatio.Matrices.PlantedGOE +import OAI.Probability.SKRatio.Matrices.WeightedDiagonalSquares + +namespace OAI + +section +noncomputable section +open scoped BigOperators NNReal ENNReal Topology +open MeasureTheory ProbabilityTheory Filter Set Real +namespace SKRatio.Planted +open SKRatioClock.Regression MatrixNet +attribute [local instance] Classical.propDecidable +variable {n : ℕ} + +lemma continuous_affineDisorder (β : ℝ) : Continuous (affineDisorder (n := n) β) := by + unfold affineDisorder + fun_prop + +lemma diagonal_affine_hasLaw (hn : 0 (p.1,affineDisorder β p.2)) + (μ.prod (law β n)) (μ.prod (standardArrayLaw (Edge n))) := by + refine ⟨(continuous_fst.prodMk ((continuous_affineDisorder β).comp continuous_snd)).aemeasurable,?_⟩ + change Measure.map (Prod.map id (affineDisorder β)) _ = _ + rw [←Measure.map_prod_map μ _ measurable_id (continuous_affineDisorder β).measurable, + Measure.map_id,(affineDisorder_hasLaw hn β).map_eq] + +def diagonalSquareError {X : Type*} (β : ℝ) (G : X × X → ℝ) (b : ℝ → X) + (p : (Fin n → ℝ) × Disorder n) (i : Fin n) : ℝ := + ∑ e : incidentEdges i, (p.2 e^2-β^2/(n:ℝ))* + G (b (diagonalField p.1 p.2 i),b (diagonalField p.1 p.2 (otherEnd i e))) + +lemma continuous_diagonalSquareError {X : Type*} [TopologicalSpace X] + (β : ℝ) {G : X × X → ℝ} (hG : Continuous G) {b : ℝ → X} (hb : Continuous b) + (i : Fin n) : Continuous (fun p => diagonalSquareError β G b p i) := by + apply continuous_finsetSum + intro e _ + apply Continuous.mul (by fun_prop) + exact hG.comp ((hb.comp (continuous_diagonalField i)).prodMk + (hb.comp (continuous_diagonalField (otherEnd i e)))) + +lemma diagonal_square_event_measurable {X : Type*} [TopologicalSpace X] + (β : ℝ) {G : X × X → ℝ} (hG : Continuous G) {b : ℝ → X} (hb : Continuous b) + (u : ℝ) : MeasurableSet {p : (Fin n → ℝ) × Disorder n | + ∃ i, u < |diagonalSquareError β G b p i|} := by + simp only [ofPred_exists] + exact MeasurableSet.iUnion (fun i => isOpen_lt continuous_const + (continuous_diagonalSquareError β hG hb i).abs |>.measurableSet) + +theorem planted_weighted_diagonal_rare {X : Type} [PseudoMetricSpace X] [CompactSpace X] + (G : X × X → ℝ) (hG : Continuous G) (b : ℝ → X) {K : ℝ≥0} (hb : LipschitzWith K b) + (β : ℝ) (μ : ∀ n, Measure (Fin n → ℝ)) [∀ n, IsProbabilityMeasure (μ n)] + {u : ℝ} (hu : 0 (μ n).prod (law β n)) + (fun n => {p | ∃ i : Fin n, u < |diagonalSquareError β G b p i|}) := by + obtain ⟨C,c,hC,hc,ht⟩ := continuous_weighted_diagonal_rare G hG b hb β μ hu + refine ⟨C,c,hC,hc,?_⟩ + filter_upwards [ht,eventually_gt_atTop 0] with n hn hn0 + rw [←(diagonal_affine_hasLaw hn0 β (μ n)).measure_eq + (diagonal_square_event_measurable β hG hb.continuous u)] + refine (measure_mono ?_).trans hn + rintro p ⟨i,hi⟩ + exact ⟨i,b (diagonalField p.1 (affineDisorder β p.2) i),hi⟩ + +def augmentedDiagonal (β : ℝ) (g : (Fin n × Fin n) → ℝ) : Fin n → ℝ := + fun i => augmented β g i i + +lemma augmentedPair_gaussian (β : ℝ) : + HasGaussianLaw (fun g : (Fin n × Fin n) → ℝ => + (augmentedDiagonal β g,augmentedDisorder β g)) (standardArrayLaw (Fin n × Fin n)) := by + let L : ((Fin n × Fin n) → ℝ) →L[ℝ] ((Fin n → ℝ) × Disorder n) := + (β • ContinuousLinearMap.pi (fun i : Fin n => (entryCLM i i).comp (goeCLM n))).prod + (β • ContinuousLinearMap.pi (fun e : Edge n => (entryCLM e.1.1 e.1.2).comp (goeCLM n))) + let c := ((fun _ : Fin n => β^2/(n:ℝ)),(fun _ : Edge n => β^2/(n:ℝ))) + have hL := coordinates_gaussian.map_fun L + have h : HasGaussianLaw (fun g => L g+c) (standardArrayLaw (Fin n × Fin n)) := by + have := hL.isGaussian_map + refine ⟨by fun_prop, ?_⟩ + change IsGaussian ((standardArrayLaw (Fin n × Fin n)).map ((fun x => x+c) ∘ L)) + rw [← AEMeasurable.map_map_of_aemeasurable + (by fun_prop : AEMeasurable (fun x => x+c) ((standardArrayLaw (Fin n × Fin n)).map L)) hL.aemeasurable] + infer_instance + apply h.congr + exact Eventually.of_forall (fun g => by + ext x <;> simp [L,c,entryCLM_apply,goeCLM_apply,augmented,augmentedDiagonal,augmentedDisorder]) + +lemma augmentedDiagonal_independent (hn : 0 augmented β g i i,fun g => augmented β g e.1.1 e.1.2; + standardArrayLaw (Fin n × Fin n)] = 0 + rw [augmented_covariance hn] + have h1 : ¬(i=e.1.1 ∧ i=e.1.2) := by rintro ⟨rfl,h⟩; exact (ne_of_lt e.2) h + have h2 : ¬(i=e.1.2 ∧ i=e.1.1) := by rintro ⟨h,rfl⟩; exact (ne_of_lt e.2) h + simp only [ite_eq_right h1,ite_eq_right h2,add_zero,mul_zero] + +def diagonalLaw (β : ℝ) (n : ℕ) : Measure (Fin n → ℝ) := + (standardArrayLaw (Fin n × Fin n)).map (augmentedDiagonal β) + +lemma continuous_augmentedDiagonal (β : ℝ) : Continuous (augmentedDiagonal (n := n) β) := by + unfold augmentedDiagonal augmented goe + fun_prop + +instance diagonalLaw_probability (β : ℝ) : IsProbabilityMeasure (diagonalLaw β n) := + (Measure.isProbabilityMeasure_map_iff (continuous_augmentedDiagonal β).aemeasurable).2 + inferInstance + +lemma augmentedPair_hasLaw (hn : 0 (augmentedDiagonal β g,augmentedDisorder β g)) + ((diagonalLaw β n).prod (law β n)) (standardArrayLaw (Fin n × Fin n)) := + (augmentedDiagonal_independent hn β).hasLaw_prod + ⟨(continuous_augmentedDiagonal β).aemeasurable,rfl⟩ (augmentedDisorder_hasLaw hn β) + +lemma diagonalField_augmented (β : ℝ) (g : (Fin n × Fin n) → ℝ) (i : Fin n) : + diagonalField (augmentedDiagonal β g) (augmentedDisorder β g) i = augmentedField β g i := by + have h := coupling_augmentedDisorder β g + change augmented β g i i+∑ j, coupling (augmentedDisorder β g) i j = _ + simp_rw [show coupling (augmentedDisorder β g) = fun i j => + augmented β g i j - Matrix.diagonal (fun k => augmented β g k k) i j from h] + simp [Finset.sum_sub_distrib,Matrix.diagonal_apply,augmentedField] + +theorem augmented_weighted_diagonal_rare {X : Type} [PseudoMetricSpace X] [CompactSpace X] + (G : X × X → ℝ) (hG : Continuous G) (b : ℝ → X) {K : ℝ≥0} (hb : LipschitzWith K b) + (β : ℝ) {u : ℝ} (hu : 0 standardArrayLaw (Fin n × Fin n)) + (fun n => {g | ∃ i : Fin n, u < |∑ e : incidentEdges i, + (augmentedDisorder β g e^2-β^2/(n:ℝ))* + G (b (augmentedField β g i),b (augmentedField β g (otherEnd i e)))|}) := by + obtain ⟨C,c,hC,hc,ht⟩ := planted_weighted_diagonal_rare G hG b hb β (diagonalLaw β) hu + refine ⟨C,c,hC,hc,?_⟩ + filter_upwards [ht,eventually_gt_atTop 0] with n hn hn0 + have hl := (augmentedPair_hasLaw hn0 β).measure_eq + (diagonal_square_event_measurable β hG hb.continuous u) + simpa only [diagonalSquareError,diagonalField_augmented] using hl.le.trans hn + +end SKRatio.Planted + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Matrices/BrownianUnitLaw.lean b/lean/OAI/Probability/SKRatio/Matrices/BrownianUnitLaw.lean new file mode 100644 index 0000000000000000000000000000000000000000..6f024f7ace63f4229514fe14808d48a17d665de5 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Matrices/BrownianUnitLaw.lean @@ -0,0 +1,113 @@ +import Mathlib +import OAI.Probability.SKRatio.Matrices.PathEvaluations +import OAI.Probability.SKRatio.Matrices.PathEnergy + +namespace OAI + +section +section +noncomputable section +namespace SKRatioGaussian.PathBridge +open MeasureTheory ProbabilityTheory Real Set TopologicalSpace +open scoped BigOperators ENNReal NNReal Topology + +def brownianUnitLaw {Ω : Type*} [MeasurableSpace Ω] (P : Measure Ω) + (B : ℝ≥0→Ω→ℝ) : Measure UnitPath := + P.map (continuousPathVersion (unitBrownianProcess B)) + +lemma brownianUnitLaw_probability {Ω : Type*} [MeasurableSpace Ω] + {P : Measure Ω} {B : ℝ≥0→Ω→ℝ} (hB : IsBrownianReal B P) : + IsProbabilityMeasure (brownianUnitLaw P B) := by + let : IsProbabilityMeasure P := hB.isGaussianProcess.isProbabilityMeasure + exact (Measure.isProbabilityMeasure_map_iff + (aemeasurable_continuousPathVersion (brownian_unit_gaussian hB).aemeasurable + (brownian_unit_continuous hB))).2 inferInstance + +theorem brownianUnitLaw_eq {Ω Ω' : Type*} [MeasurableSpace Ω] [MeasurableSpace Ω'] + {P : Measure Ω} {Q : Measure Ω'} {B : ℝ≥0→Ω→ℝ} {C : ℝ≥0→Ω'→ℝ} + (hB : IsBrownianReal B P) (hC : IsBrownianReal C Q) : + brownianUnitLaw P B=brownianUnitLaw Q C := by + classical + let : IsProbabilityMeasure P := hB.isGaussianProcess.isProbabilityMeasure + let : IsProbabilityMeasure Q := hC.isGaussianProcess.isProbabilityMeasure + have hmB := aemeasurable_continuousPathVersion (brownian_unit_gaussian hB).aemeasurable + (brownian_unit_continuous hB) + have hmC := aemeasurable_continuousPathVersion (brownian_unit_gaussian hC).aemeasurable + (brownian_unit_continuous hC) + apply measurableEmbedding_pathEvaluations.map_injective + unfold brownianUnitLaw + rw [AEMeasurable.map_map_of_aemeasurable measurableEmbedding_pathEvaluations.measurable.aemeasurable hmB, + AEMeasurable.map_map_of_aemeasurable measurableEmbedding_pathEvaluations.measurable.aemeasurable hmC] + have hpB := isProjectiveLimit_map + (measurableEmbedding_pathEvaluations.measurable.comp_aemeasurable hmB) + have hpC := isProjectiveLimit_map + (measurableEmbedding_pathEvaluations.measurable.comp_aemeasurable hmC) + suffices heq : ∀ s : Finset ℕ, + P.map (fun ω=>s.restrict (pathEvaluations (continuousPathVersion (unitBrownianProcess B) ω)))= + Q.map (fun ω=>s.restrict (pathEvaluations (continuousPathVersion (unitBrownianProcess C) ω))) by + simp only [Function.comp_apply] at hpB hpC + simp_rw [heq] at hpB + exact hpB.unique hpC + intro s + let d : ℕ→ℝ≥0 := fun k=>⟨(denseSeq UnitInterval k).1,(denseSeq UnitInterval k).2.1⟩ + let I := s.image d + let e : (I→ℝ)→s→ℝ := fun v i=>v ⟨d i,Finset.mem_image.mpr ⟨i,i.2,rfl⟩⟩ + have he : Measurable e := by fun_prop + have hb := congrArg (Measure.map e) (hB.hasLaw I).map_eq + have hc := congrArg (Measure.map e) (hC.hasLaw I).map_eq + rw [AEMeasurable.map_map_of_aemeasurable he.aemeasurable (hB.hasLaw I).aemeasurable] at hb + rw [AEMeasurable.map_map_of_aemeasurable he.aemeasurable (hC.hasLaw I).aemeasurable] at hc + calc + _ = P.map (e ∘ (fun ω=>I.restrict (B · ω))) := by + apply Measure.map_congr + have hall : ∀ᵐ ω ∂P, ∀ k : s, + continuousPathVersion (unitBrownianProcess B) ω (denseSeq UnitInterval k) = + unitBrownianProcess B (denseSeq UnitInterval k) ω := + ae_all_iff.mpr (fun k=>continuousPathVersion_eval (brownian_unit_continuous hB) _) + filter_upwards [hall] with ω hω + ext k + change continuousPathVersion (unitBrownianProcess B) ω (denseSeq UnitInterval k) = B (d k) ω + exact hω k + _ = Q.map (e ∘ (fun ω=>I.restrict (C · ω))) := hb.trans hc.symm + _ = _ := by + apply Measure.map_congr + have hall : ∀ᵐ ω ∂Q, ∀ k : s, + continuousPathVersion (unitBrownianProcess C) ω (denseSeq UnitInterval k) = + unitBrownianProcess C (denseSeq UnitInterval k) ω := + ae_all_iff.mpr (fun k=>continuousPathVersion_eval (brownian_unit_continuous hC) _) + filter_upwards [hall] with ω hω + ext k + change C (d k) ω = continuousPathVersion (unitBrownianProcess C) ω (denseSeq UnitInterval k) + exact (hω k).symm + +theorem brownian_normalized_increment_tail {Ω : Type*} [MeasurableSpace Ω] + {P : Measure Ω} {B : ℝ≥0→Ω→ℝ} (hB : IsBrownianReal B P) : + ∃ H : ℝ, 0brownianUnitLaw P + (fun t ω=>(sqrt δ)⁻¹*(B (s+δ*t) ω-B s ω)))).real + {f | H*(n:ℝ) ≤ pathEnergy n f} ≤ exp (-(n:ℝ)) := by + let := brownianUnitLaw_probability hB + obtain ⟨H,hH,hTail⟩ := pathEnergy_dimension_tail (brownianUnitLaw P B) + (gaussian_continuousPathVersion (brownian_unit_gaussian hB) (brownian_unit_continuous hB)) + (fun t=>by + rw [brownianUnitLaw,mean_continuousPathVersion (brownian_unit_gaussian hB).aemeasurable + (brownian_unit_continuous hB)] + exact hB.integral_eval _) + refine ⟨H,hH,fun s δ hδ n=>?_⟩ + have hb := (hB.shift s).smul hδ + have he := brownianUnitLaw_eq hb hB + simpa only [he] using hTail n +end SKRatioGaussian.PathBridge + +end +end + +section + +noncomputable section + +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Matrices/ClosedConvexNonempty.lean b/lean/OAI/Probability/SKRatio/Matrices/ClosedConvexNonempty.lean new file mode 100644 index 0000000000000000000000000000000000000000..0580e490a95ea40df9a380075a77979e30ec10bc --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Matrices/ClosedConvexNonempty.lean @@ -0,0 +1,123 @@ +import Mathlib + +namespace OAI + +section +section +noncomputable section +open MeasureTheory ProbabilityTheory InformationTheory Real Set +open scoped NNReal ENNReal +open Filter +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius ENNReal NNReal +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius NNReal +noncomputable section +open MeasureTheory ProbabilityTheory Real Set Filter +open MeasureTheory.Measure +open scoped ENNReal NNReal MeasureTheory Topology +open MeasureTheory +noncomputable section +noncomputable section +open MeasureTheory Set NormedSpace +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius +noncomputable section +open Set Real +open scoped Topology +namespace SKRatioGaussian +section Projection +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] + +structure ClosedConvexNonempty (K : Set E) : Prop where + nonempty : K.Nonempty + complete : IsComplete K + convex : Convex ℝ K + +noncomputable def convexProject {K : Set E} (hK : ClosedConvexNonempty K) (x : E) : E := + Classical.choose (exists_norm_eq_iInf_of_complete_convex hK.nonempty hK.complete hK.convex x) + +lemma convexProject_mem {K : Set E} (hK : ClosedConvexNonempty K) (x : E) : + convexProject hK x ∈ K := + (Classical.choose_spec (exists_norm_eq_iInf_of_complete_convex hK.nonempty hK.complete hK.convex x)).1 + +lemma convexProject_minimal {K : Set E} (hK : ClosedConvexNonempty K) (x : E) : + ‖x-convexProject hK x‖ = ⨅ y : K, ‖x-y‖ := + (Classical.choose_spec (exists_norm_eq_iInf_of_complete_convex hK.nonempty hK.complete hK.convex x)).2 + +lemma convexProject_inner {K : Set E} (hK : ClosedConvexNonempty K) (x : E) + {y : E} (hy : y ∈ K) : + inner ℝ (x-convexProject hK x) (y-convexProject hK x) ≤ 0 := by + exact ((norm_eq_iInf_iff_real_inner_le_zero hK.convex (convexProject_mem hK x)).mp + (convexProject_minimal hK x)) y hy + +lemma convexProject_lipschitz {K : Set E} (hK : ClosedConvexNonempty K) : + LipschitzWith 1 (convexProject hK) := by + apply LipschitzWith.of_dist_le_mul + intro x y + simp only [NNReal.coe_one,one_mul,dist_eq_norm] + let p := convexProject hK x + let q := convexProject hK y + have hx := convexProject_inner hK x (convexProject_mem hK y) + have hy := convexProject_inner hK y (convexProject_mem hK x) + change inner ℝ (x-p) (q-p) ≤ 0 at hx + change inner ℝ (y-q) (p-q) ≤ 0 at hy + have hi : ‖p-q‖^2 ≤ inner ℝ (p-q) (x-y) := by + rw [← real_inner_self_eq_norm_sq] + simp only [inner_sub_left,inner_sub_right,real_inner_comm] at * + nlinarith + have hb := real_inner_le_norm (p-q) (x-y) + nlinarith [norm_nonneg (p-q),norm_nonneg (x-y)] + +lemma convexProject_eq_self {K : Set E} (hK : ClosedConvexNonempty K) {x : E} + (hx : x ∈ K) : convexProject hK x = x := by + have hh := convexProject_inner hK x hx + rw [real_inner_self_eq_norm_sq] at hh + have hz : ‖x-convexProject hK x‖ = 0 := by nlinarith [norm_nonneg (x-convexProject hK x)] + exact (sub_eq_zero.mp (norm_eq_zero.mp hz)).symm + +lemma convexProject_unique {K : Set E} (hK : ClosedConvexNonempty K) {x p : E} + (hp : p ∈ K) (hmin : ∀ y ∈ K, inner ℝ (x-p) (y-p) ≤ 0) : + p = convexProject hK x := by + let q := convexProject hK x + have h₁ := hmin q (convexProject_mem hK x) + have h₂ := convexProject_inner hK x hp + change inner ℝ (x-q) (p-q) ≤ 0 at h₂ + have hh : ‖p-q‖^2 ≤ 0 := by + rw [← real_inner_self_eq_norm_sq] + simp only [inner_sub_right,inner_sub_left,real_inner_comm] at * + nlinarith + have hz : ‖p-q‖ = 0 := by nlinarith [norm_nonneg (p-q)] + exact sub_eq_zero.mp (norm_eq_zero.mp hz) + +lemma convexProject_equivariant {K : Set E} (hK : ClosedConvexNonempty K) + (U : E ≃ₗᵢ[ℝ] E) (hU : ∀ x, U x ∈ K ↔ x ∈ K) (x : E) : + convexProject hK (U x) = U (convexProject hK x) := by + apply Eq.symm + apply convexProject_unique hK ((hU _).mpr (convexProject_mem hK x)) + intro y hy + have hy' : U.symm y ∈ K := (hU _).mp (by simpa using hy) + have hh := convexProject_inner hK x hy' + rw [← U.inner_map_map] at hh + simpa only [map_sub,LinearIsometryEquiv.apply_symm_apply] using hh + +end Projection +end SKRatioGaussian + +end +end +end +end +end +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Matrices/CompactMatrixMasks.lean b/lean/OAI/Probability/SKRatio/Matrices/CompactMatrixMasks.lean new file mode 100644 index 0000000000000000000000000000000000000000..72be7082fb457a5c0a4832d81399ceed342af2c4 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Matrices/CompactMatrixMasks.lean @@ -0,0 +1,182 @@ +import Mathlib +import OAI.Probability.SKRatio.Matrices.RandomMatrixNet + +namespace OAI + +noncomputable section +open scoped BigOperators Topology +open Set Metric +namespace SKRatio.MatrixNet +attribute [local instance] Classical.propDecidable + +lemma masked_matrix_norm_le {n : ℕ} (A : Matrix (Fin n) (Fin n) ℝ) + (s t : Fin n → Prop) : + ‖Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) + (fun i j => if s i ∧ t j then A i j else 0)‖ ≤ + ‖Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) A‖ := by + let D (s : Fin n → Prop) : Matrix (Fin n) (Fin n) ℝ := + Matrix.diagonal (fun i => if s i then 1 else 0) + have hde (s : Fin n → Prop) : + ‖Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) (D s)‖ ≤ 1 := by + apply matrix_diagonal_opNorm_le _ 1 zero_le_one + intro i + split_ifs <;> norm_num + have he : (fun i j => if s i ∧ t j then A i j else 0) = D s*A*D t := by + ext i j + simp only [D,Matrix.diagonal_mul,Matrix.mul_diagonal] + split_ifs <;> simp_all + rw [he,map_mul,map_mul] + calc + _ ≤ (‖Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) (D s)‖* + ‖Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) A‖)* + ‖Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) (D t)‖ := + (norm_mul_le _ _).trans (mul_le_mul_of_nonneg_right (norm_mul_le _ _) (norm_nonneg _)) + _ ≤ (1*‖Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) A‖)*1 := + mul_le_mul (mul_le_mul_of_nonneg_right (hde s) (norm_nonneg _)) (hde t) + (norm_nonneg _) (by positivity) + _ = _ := by ring + +lemma bin_kernel_decomposition {n : ℕ} {κ : Type*} [Fintype κ] [DecidableEq κ] + (A : Matrix (Fin n) (Fin n) ℝ) (b : Fin n → κ) (G : κ → κ → ℝ) : + Matrix.of (fun i j => A i j*G (b i) (b j)) = + ∑ a : κ, ∑ c : κ, G a c • Matrix.of (fun i j => if b i=a ∧ b j=c then A i j else 0) := by + apply Matrix.ext + intro i j + simp only [Matrix.sum_apply,Matrix.of_apply,Matrix.smul_apply,smul_eq_mul] + simp only [mul_ite,mul_zero, ite_and, + Finset.sum_ite_irrel,Finset.sum_const_zero,Finset.sum_ite_eq, + Finset.mem_univ,ite_true] + ring + +lemma euclideanCLM_smul {n : ℕ} (a : ℝ) (A : Matrix (Fin n) (Fin n) ℝ) : + Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) (a • A) = + a • Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) A := by + exact map_smul (Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ)) a A + +lemma masked_smul_norm_le {n : ℕ} (a : ℝ) (A : Matrix (Fin n) (Fin n) ℝ) + (s t : Fin n → Prop) : + ‖Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) + (a • Matrix.of (fun i j => if s i ∧ t j then A i j else 0))‖ ≤ + |a| * ‖Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) A‖ := by + rw [euclideanCLM_smul,norm_smul,Real.norm_eq_abs] + exact mul_le_mul_of_nonneg_left (masked_matrix_norm_le A s t) (abs_nonneg a) + +lemma bin_kernel_norm_le {n : ℕ} {κ : Type*} [Fintype κ] [DecidableEq κ] + (A : Matrix (Fin n) (Fin n) ℝ) (b : Fin n → κ) (G : κ → κ → ℝ) : + ‖Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) (Matrix.of (fun i j => A i j*G (b i) (b j)))‖ ≤ + (∑ a : κ, ∑ c : κ, |G a c|) * ‖Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) A‖ := by + let T := Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) + let P (a c : κ) : Matrix (Fin n) (Fin n) ℝ := + G a c • Matrix.of (fun i j => if b i=a ∧ b j=c then A i j else 0) + have hmap : T (∑ a, ∑ c, P a c) = ∑ a, ∑ c, T (P a c) := by + rw [map_sum] + exact Finset.sum_congr rfl (fun a _ => map_sum T _ _) + have hnormsum : ‖∑ a, ∑ c, T (P a c)‖ ≤ ∑ a, ∑ c, ‖T (P a c)‖ := + (norm_sum_le _ _).trans (Finset.sum_le_sum (fun a _ => norm_sum_le _ _)) + have hbnd : ∑ a, ∑ c, ‖T (P a c)‖ ≤ ∑ a, ∑ c, |G a c| *‖T A‖ := by + dsimp only [T,P] + apply Finset.sum_le_sum + intro a _ + apply Finset.sum_le_sum + intro c _ + convert masked_smul_norm_le (G a c) A (fun i => b i=a) (fun j => b j=c) using 1 + try rfl + apply congrArg (fun M : Matrix (Fin n) (Fin n) ℝ => + ‖Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) M‖) + apply Matrix.ext + intro i j + simp only [Matrix.smul_apply,Matrix.of_apply,smul_eq_mul] + split_ifs <;> rfl + rw [bin_kernel_decomposition A b G] + change ‖T (∑ a, ∑ c, P a c)‖ ≤ _ + rw [hmap] + apply (hnormsum.trans hbnd).trans_eq + simp only [T, Finset.sum_mul] + +lemma kernel_error_norm_le {n : ℕ} (A : Matrix (Fin n) (Fin n) ℝ) + (G G' : Fin n → Fin n → ℝ) {a C : ℝ} (ha : 0≤a) (hC : 0≤C) + (hr : ∀ i, ∑ j, |A i j| ≤ C) (hc : ∀ j, ∑ i, |A i j| ≤ C) + (he : ∀ i j, |G i j-G' i j| ≤ a) : + ‖Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) (fun i j => A i j*(G i j-G' i j))‖ ≤ a*C := by + apply matrix_opNorm_le_schur _ (a*C) (mul_nonneg ha hC) + · intro i + calc + _ ≤ ∑ j, a*|A i j| := Finset.sum_le_sum (fun j _ => by + rw [abs_mul,mul_comm] + exact mul_le_mul_of_nonneg_right (he i j) (abs_nonneg _)) + _ = a*(∑ j, |A i j|) := (Finset.mul_sum ..).symm + _ ≤ _ := mul_le_mul_of_nonneg_left (hr i) ha + · intro j + calc + _ ≤ ∑ i, a*|A i j| := Finset.sum_le_sum (fun i _ => by + rw [abs_mul,mul_comm] + exact mul_le_mul_of_nonneg_right (he i j) (abs_nonneg _)) + _ = a*(∑ i, |A i j|) := (Finset.mul_sum ..).symm + _ ≤ _ := mul_le_mul_of_nonneg_left (hc j) ha + +lemma compact_kernel_approximation {X : Type*} [PseudoMetricSpace X] [CompactSpace X] + (G : X × X → ℝ) (hG : Continuous G) {a : ℝ} (ha : 0 A i j*G (x i,x j))‖ ≤ u := by + classical + let a := u/(2*(C+1)) + have ha : 0 Finset.sum_nonneg (fun _ _ => abs_nonneg _)) + let δ := u/(2*(B+1)) + have hd : 0<δ := by dsimp [δ]; positivity + refine ⟨δ,hd,?_⟩ + intro n A hr hc hsmall x + have hbin := bin_kernel_norm_le A (fun i => b (x i)) (fun k l => G (k,l)) + have herr := kernel_error_norm_le A (fun i j => G (x i,x j)) + (fun i j => G (b (x i),b (x j))) ha.le hC hr hc (fun i j => hb (x i) (x j)) + have hdecomp : Matrix.of (fun i j => A i j*G (x i,x j)) = + Matrix.of (fun i j => A i j*G (b (x i),b (x j))) + + Matrix.of (fun i j => A i j*(G (x i,x j)-G (b (x i),b (x j)))) := by + apply Matrix.ext + intro i j + change A i j*G (x i,x j) = A i j*G (b (x i),b (x j)) + A i j*(G (x i,x j)-G (b (x i),b (x j))) + ring + have hBδ : B*δ ≤ u/2 := by + dsimp [δ] + rw [←mul_div_assoc] + apply (div_le_iff₀ (by positivity : (0:ℝ)<2*(B+1))).mpr + nlinarith + have haC : a*C ≤ u/2 := by + dsimp [a] + rw [div_mul_eq_mul_div] + apply (div_le_iff₀ (by positivity : (0:ℝ)<2*(C+1))).mpr + nlinarith + calc + _ ≤ B*‖Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) A‖+a*C := by + change ‖Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) (Matrix.of (fun i j => A i j*G (x i,x j)))‖ ≤ _ + rw [hdecomp,map_add] + exact (norm_add_le _ _).trans (add_le_add hbin herr) + _ ≤ B*δ+a*C := add_le_add_left (mul_le_mul_of_nonneg_left hsmall hB) _ + _ ≤ u := by linarith only [hBδ,haC] + +end SKRatio.MatrixNet + +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Matrices/ConditionalAffineSquares.lean b/lean/OAI/Probability/SKRatio/Matrices/ConditionalAffineSquares.lean new file mode 100644 index 0000000000000000000000000000000000000000..96c5e1cdf00b3f3025e883394fb9f8e0107098b7 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Matrices/ConditionalAffineSquares.lean @@ -0,0 +1,153 @@ +import Mathlib +import OAI.Probability.SKRatio.Matrices.ConditionalGaussianSquares + +namespace OAI + +section +noncomputable section +open scoped BigOperators NNReal ENNReal Topology +open MeasureTheory ProbabilityTheory Filter Set Real +namespace SKRatio.MatrixNet +open SKRatioClock.Regression +attribute [local instance] Classical.propDecidable + +lemma weighted_square_conditioned_product_tail {A u : ℝ} (hA : 0≤A) (hu : 0 a p.1 p.2 i)) → + (∀ ω y i, |a ω y i|≤A) → ∀ {n : ℕ}, 0 p.2 j) i * (p.2 i^2-1))/(n:ℝ)|} ≤ + ENNReal.ofReal (3*exp (-c*n)) := by + obtain ⟨c,hc,ht⟩ := weighted_square_conditioned_tail hA hu + refine ⟨c,hc,?_⟩ + intro Ω _ μ _ ι _ s a hm ha n hn hs + have hE : MeasurableSet {p : Ω × (ι → ℝ) | u ≤ |(∑ i : s, + a p.1 (fun j => p.2 j) i * (p.2 i^2-1))/(n:ℝ)|} := by + apply measurableSet_le measurable_const + apply Measurable.abs + apply Measurable.div_const + apply Finset.measurable_sum + intro i _ + have hr : Measurable (fun p : Ω × (ι → ℝ) => (p.1, fun j : {i // i∉s} => p.2 j)) := by + fun_prop + exact ((hm i).comp hr).mul + (((measurable_pi_apply (i : ι)).comp measurable_snd).pow_const 2 |>.sub measurable_const) + rw [Measure.prod_apply hE] + calc + _ ≤ ∫⁻ _ω : Ω, ENNReal.ofReal (3*exp (-c*n)) ∂μ := by + apply lintegral_mono + intro ω + exact ht s (a ω) (fun i => (hm i).comp (measurable_const.prodMk measurable_id)) (ha ω) hn hs + _ = _ := by simp + +lemma average_abs_le_square_add_one {ι : Type*} [Fintype ι] (z : ι → ℝ) + {n : ℕ} (hn : Fintype.card ι≤n) : + (∑ i, |z i|)/(n:ℝ) ≤ (∑ i, z i^2)/(n:ℝ)+1 := by + by_cases hn0 : n=0 + · simp [hn0] + have hsum : ∑ i, |z i| ≤ (∑ i, z i^2)+(n:ℝ) := by + calc + _ ≤ ∑ i, (z i^2+1) := Finset.sum_le_sum (fun i _ => by + nlinarith [sq_nonneg (|z i|-1),sq_abs (z i),abs_nonneg (z i)]) + _ = (∑ i, z i^2)+(Fintype.card ι:ℝ) := by simp [Finset.sum_add_distrib] + _ ≤ _ := add_le_add_right (by exact_mod_cast hn : (Fintype.card ι:ℝ) ≤ n) _ + have h := div_le_div_of_nonneg_right hsum (Nat.cast_nonneg n : (0:ℝ)≤n) + simpa [add_div,hn0] using h + +lemma weighted_affine_square_error {ι : Type*} [Fintype ι] + (β : ℝ) (a z : ι → ℝ) {A C : ℝ} (hA : 0≤A) + (ha : ∀ i, |a i|≤A) {n : ℕ} (hn : 0 a p.1 p.2 i)) → + (∀ ω y i, |a ω y i|≤A) → + (μ.prod (standardArrayLaw ι)) {p | + u < |∑ i : s, a p.1 (fun j => p.2 j) i * + ((β/sqrt n*p.2 i+β^2/(n:ℝ))^2-β^2/n)| ∧ + (∑ i : s, p.2 i^2)/(n:ℝ) ≤ C} ≤ + ENNReal.ofReal (3*exp (-c*n)) := by + let d := u/(2*(β^2+1)) + have hd : 0 A*(|2*β^3/sqrt n| *(C+1)+β^4/n)) atTop (𝓝 0) := by + have hn := (tendsto_natCast_atTop_atTop : Tendsto (fun n : ℕ => (n:ℝ)) atTop atTop) + have h₁ := ((tendsto_const_nhds (x := 2*β^3)).div_atTop (tendsto_sqrt_atTop.comp hn)).abs.mul_const (C+1) + have h₂ := (tendsto_const_nhds (x := β^4)).div_atTop hn + simpa only [abs_zero,zero_mul,zero_add,mul_zero,Function.comp_def] using (h₁.add h₂).const_mul A + refine ⟨c,hc,?_⟩ + filter_upwards [eventually_gt_atTop 0,hconv.eventually (gt_mem_nhds (half_pos hu))] with n hn hb + intro Ω _ μ _ ι _ s a hs hm ha + apply (measure_mono (t := {p : Ω × (ι → ℝ) | d ≤ |(∑ i : s, + a p.1 (fun j => p.2 j) i*(p.2 i^2-1))/(n:ℝ)|}) ?_).trans (ht μ s a hm ha hn hs) + rintro p ⟨hp,hrow⟩ + change d ≤ _ + apply le_of_not_gt + intro hsmall + have hh := weighted_affine_square_error β (a p.1 (fun j => p.2 j)) (fun i : s => p.2 i) + hA (ha _ _) hn (by simpa using hs) hrow + have hs' : β^2*|(∑ i : s, a p.1 (fun j => p.2 j) i*(p.2 i^2-1))/(n:ℝ)| ≤ u/2 := by + apply (mul_le_mul_of_nonneg_left hsmall.le (sq_nonneg β)).trans + dsimp only [d] + rw [←mul_div_assoc] + apply (div_le_iff₀ (by positivity : (0:ℝ)<2*(β^2+1))).mpr + nlinarith + have htri := abs_sub_le (∑ i : s, a p.1 (fun j => p.2 j) i * + ((β/sqrt n*p.2 i+β^2/(n:ℝ))^2-β^2/n)) + (β^2*((∑ i : s, a p.1 (fun j => p.2 j) i*(p.2 i^2-1))/(n:ℝ))) 0 + simp only [sub_zero,abs_mul,abs_of_nonneg (sq_nonneg β)] at htri + linarith only [hp,hh,hb,hs',htri] + +end SKRatio.MatrixNet + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Matrices/ConditionalGaussianSquares.lean b/lean/OAI/Probability/SKRatio/Matrices/ConditionalGaussianSquares.lean new file mode 100644 index 0000000000000000000000000000000000000000..dbe49942161345211f008ef9e5ea903e9892185a --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Matrices/ConditionalGaussianSquares.lean @@ -0,0 +1,82 @@ +import Mathlib +import OAI.Probability.SKRatio.Matrices.WeightedGaussianSquares + +namespace OAI + +section +noncomputable section +open scoped BigOperators ENNReal NNReal Topology +open MeasureTheory ProbabilityTheory Filter Set Real +namespace SKRatio.MatrixNet +open SKRatioClock.Regression +attribute [local instance] Classical.propDecidable + +lemma weighted_square_product_tail {A u c : ℝ} + (ht : ∀ {ι : Type} [Fintype ι] (s : Finset ι) (a : ι → ℝ), + (∀ i∈s, |a i|≤A) → ∀ {n : ℕ}, 0 a ω i)) (ha : ∀ ω i, i∈s → |a ω i|≤A) + {n : ℕ} (hn : 0 ((hma i).comp measurable_fst).mul + (((measurable_pi_apply i).comp measurable_snd).pow_const 2 |>.sub measurable_const)) + rw [Measure.prod_apply hE] + calc + _ ≤ ∫⁻ _ω : Ω, ENNReal.ofReal (3*exp (-c*n)) ∂μ := + lintegral_mono (fun ω => ht s (a ω) (ha ω) hn hc) + _ = _ := by simp + +theorem weighted_square_conditioned_tail {A u : ℝ} (hA : 0≤A) (hu : 0 a y i)) → (∀ y i, |a y i|≤A) → + ∀ {n : ℕ}, 0 z j) i * (z i^2-1))/(n:ℝ)|} ≤ + ENNReal.ofReal (3*exp (-c*n)) := by + classical + obtain ⟨c,hc,ht⟩ := weighted_standard_square_tail hA hu + refine ⟨c,hc,?_⟩ + intro ι _ s a hm ha n hn hs + let E : Set (({i // i∉s} → ℝ) × (s → ℝ)) := + {p | u ≤ |(∑ i : s, a p.1 i*(p.2 i^2-1))/(n:ℝ)|} + have hE : MeasurableSet E := by + apply measurableSet_le measurable_const + apply Measurable.abs + apply Measurable.div_const + exact Finset.measurable_sum _ (fun i _ => ((hm i).comp measurable_fst).mul + (((measurable_pi_apply i).comp measurable_snd).pow_const 2 |>.sub measurable_const)) + have hp := measurePreserving_piEquivPiSubtypeProd + (fun _ : ι => gaussianReal 0 1) (fun i => i∈s) + have hp' := Measure.measurePreserving_swap.comp hp + have he : {z : ι → ℝ | u ≤ |(∑ i : s, a (fun j => z j) i*(z i^2-1))/(n:ℝ)|} = + (fun z => ((fun j : {i // i∉s} => z j), (fun j : s => z j))) ⁻¹' E := rfl + rw [he] + have hmap : MeasurePreserving (fun z : ι → ℝ => + ((fun j : {i // i∉s} => z j), (fun j : s => z j))) + (standardArrayLaw ι) ((standardArrayLaw {i // i∉s}).prod (standardArrayLaw s)) := by + convert! hp' using 1 + dsimp only [standardArrayLaw] + congr 1 + congr 1 + exact Subsingleton.elim _ _ + + rw [hmap.measure_preimage hE.nullMeasurableSet] + exact weighted_square_product_tail ht (standardArrayLaw {i // i∉s}) + Finset.univ a hm (fun y i _ => ha y i) hn (by simpa using hs) + +end SKRatio.MatrixNet + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Matrices/CoordinateDeriv.lean b/lean/OAI/Probability/SKRatio/Matrices/CoordinateDeriv.lean new file mode 100644 index 0000000000000000000000000000000000000000..85d0d8de33e57694465b330abf75184f1b4f8858 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Matrices/CoordinateDeriv.lean @@ -0,0 +1,96 @@ +import Mathlib +import OAI.Probability.SKRatio.Matrices.TendstoGaussianPDFRealTop + +namespace OAI + +section +section +noncomputable section +open MeasureTheory ProbabilityTheory InformationTheory Real Set +open scoped NNReal ENNReal +open Filter +open scoped Topology +namespace SKRatioGaussian + +def coordinateDeriv {n : ℕ} (i : Fin (n+1)) (f : (Fin (n+1) → ℝ) → ℝ) + (x : Fin (n+1) → ℝ) : ℝ := + deriv (fun z => f (i.insertNth z (i.removeNth x))) (x i) + +lemma lipschitz_insertNth {n : ℕ} (i : Fin (n+1)) (u : Fin n → ℝ) : + LipschitzWith 1 (fun z : ℝ => i.insertNth (α := fun _ => ℝ) z u) := by + apply LipschitzWith.of_dist_le_mul + intro x y + simp only [NNReal.coe_one,one_mul] + apply (dist_pi_le_iff dist_nonneg).2 + refine i.forall_iff_succAbove.mpr ⟨?_,?_⟩ + · simp only [Fin.insertNth_apply_same,le_refl] + · intro k + simp only [Fin.insertNth_apply_succAbove,dist_self] + exact dist_nonneg + +lemma continuous_insertNth_uncurry {n : ℕ} (i : Fin (n+1)) : + Continuous (fun p : (Fin n → ℝ) × ℝ => i.insertNth (α := fun _ => ℝ) p.2 p.1) := by + apply continuous_pi + refine i.forall_iff_succAbove.mpr ⟨?_,?_⟩ + · simpa only [Fin.insertNth_apply_same] using (continuous_snd : Continuous (fun p : (Fin n → ℝ) × ℝ => p.2)) + · intro k + simpa only [Fin.insertNth_apply_succAbove,Function.comp_def] using (continuous_apply k).comp continuous_fst + +lemma measurable_coordinateDeriv {n : ℕ} (i : Fin (n+1)) {f : (Fin (n+1) → ℝ) → ℝ} + (hf : Continuous f) : Measurable (coordinateDeriv i f) := by + have h := measurable_deriv_with_param (f := fun u z => f (i.insertNth z u)) + (hf.comp (continuous_insertNth_uncurry i)) + have hc : Continuous (fun x : Fin (n+1) → ℝ => (i.removeNth x,x i)) := by + apply Continuous.prodMk + · apply continuous_pi + intro k + exact continuous_apply (i.succAbove k) + · exact continuous_apply i + exact h.comp hc.measurable + +lemma norm_coordinateDeriv_le {n : ℕ} (i : Fin (n+1)) {f : (Fin (n+1) → ℝ) → ℝ} + {L : ℝ≥0} (hf : LipschitzWith L f) (x : Fin (n+1) → ℝ) : + ‖coordinateDeriv i f x‖ ≤ L := by + have hl := hf.comp (lipschitz_insertNth i (i.removeNth x)) + simpa only [mul_one,coordinateDeriv,Function.comp_def] using norm_deriv_le_of_lipschitz hl (x₀ := x i) + +theorem gaussianProduct_lipschitz_IBP {n : ℕ} (i : Fin (n+1)) + {f : (Fin (n+1) → ℝ) → ℝ} {L : ℝ≥0} {C : ℝ} + (hf : LipschitzWith L f) (hC : ∀ x, ‖f x‖ ≤ C) : + (∫ x, x i * f x ∂standardGaussianProduct (n+1)) = + ∫ x, coordinateDeriv i f x ∂standardGaussianProduct (n+1) := by + let e := MeasurableEquiv.piFinSuccAbove (fun _ : Fin (n+1) => ℝ) i + have hp : MeasurePreserving e.symm + ((gaussianReal 0 1).prod (standardGaussianProduct n)) + (standardGaussianProduct (n+1)) := + (measurePreserving_piFinSuccAbove (fun _ => gaussianReal 0 1) i).symm + have hi : Integrable (fun x : Fin (n+1) → ℝ => x i * f x) + (standardGaussianProduct (n+1)) := by + simpa only [mul_comm,standardGaussianProduct] using + (integrable_eval (i := i) IsGaussian.integrable_id).bdd_mul + hf.continuous.aestronglyMeasurable (ae_of_all _ hC) + have hi' : Integrable (coordinateDeriv i f) (standardGaussianProduct (n+1)) := + Integrable.of_bound (measurable_coordinateDeriv i hf.continuous).aestronglyMeasurable (L:ℝ) + (ae_of_all _ (norm_coordinateDeriv_le i hf)) + have hsplit (g : (Fin (n+1) → ℝ) → ℝ) (hg : Integrable g (standardGaussianProduct (n+1))) : + (∫ x, g x ∂standardGaussianProduct (n+1)) = + ∫ u, ∫ z, g (i.insertNth (α := fun _ => ℝ) z u) ∂gaussianReal 0 1 ∂standardGaussianProduct n := by + have hi2 : Integrable (fun x => g (e.symm x)) + ((gaussianReal 0 1).prod (standardGaussianProduct n)) := hp.integrable_comp_of_integrable hg + rw [← hp.integral_comp' g,integral_prod _ hi2,integral_integral_swap hi2] + rfl + rw [hsplit _ hi,hsplit _ hi'] + apply integral_congr_ae + filter_upwards [] with u + simp only [coordinateDeriv,Fin.insertNth_apply_same,Fin.removeNth_insertNth] + simpa only [sub_zero,NNReal.coe_one,one_mul,Function.comp_def] using + gaussian_lipschitz_IBP (d := 0) (s := 1) (by norm_num) + (hf.comp (lipschitz_insertNth i u)) (fun z => hC (i.insertNth (α := fun _ => ℝ) z u)) + +end SKRatioGaussian + +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Matrices/DetMultilinear.lean b/lean/OAI/Probability/SKRatio/Matrices/DetMultilinear.lean new file mode 100644 index 0000000000000000000000000000000000000000..80ecfc14afde59987a7a068d0161598bce505bca --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Matrices/DetMultilinear.lean @@ -0,0 +1,79 @@ +import Mathlib + +namespace OAI + +section +section +noncomputable section +namespace SKRatioGaussian.LogDet +open Matrix +open scoped BigOperators +variable {ι : Type*} [Fintype ι] [DecidableEq ι] + +private def detMultilinear : ContinuousMultilinearMap ℝ (fun _ : ι => ι → ℝ) ℝ := + { (Matrix.detRowAlternating : (ι → ℝ) [⋀^ι]→ₗ[ℝ] ℝ).toMultilinearMap with + cont := by change Continuous (fun M : Matrix ι ι ℝ => M.det); fun_prop } + +lemma hasDerivAt_det_update {Q : ℝ → Matrix ι ι ℝ} {Q' : Matrix ι ι ℝ} {t : ℝ} + (hQ : ∀ i k, HasDerivAt (fun x => Q x i k) (Q' i k) t) : + HasDerivAt (fun x => (Q x).det) (∑ i, ((Q t).updateRow i (Q' i)).det) t := by + have hrow (i : ι) : HasDerivAt (fun x => Q x i) (Q' i) t := hasDerivAt_pi.mpr (hQ i) + have h := (HasFDerivAt.multilinear_comp (f := detMultilinear (ι := ι)) + (fun i => (hrow i).hasFDerivAt)).hasDerivAt + convert h using 1 <;> try rfl + simp only [_root_.sum_apply,ContinuousLinearMap.comp_apply, + ContinuousLinearMap.toSpanSingleton_apply,one_smul, + ContinuousMultilinearMap.toContinuousLinearMap_apply] + rfl + +lemma det_updateRow_trace (M H : Matrix ι ι ℝ) : + (∑ i, (M.updateRow i (H i)).det)= (H*M.adjugate).trace := by + simp only [Matrix.trace,Matrix.diag,Matrix.mul_apply] + apply Finset.sum_congr rfl + intro i _ + rw [← Matrix.cramer_transpose_apply,Matrix.cramer_eq_adjugate_mulVec, + ← Matrix.adjugate_transpose] + simp only [Matrix.mulVec,Matrix.transpose_apply,dotProduct] + apply Finset.sum_congr rfl + intro k _ + ring + +lemma hasDerivAt_det_adjugate {Q : ℝ → Matrix ι ι ℝ} {Q' : Matrix ι ι ℝ} {t : ℝ} + (hQ : ∀ i k, HasDerivAt (fun x => Q x i k) (Q' i k) t) : + HasDerivAt (fun x => (Q x).det) (Q'*(Q t).adjugate).trace t := by + simpa only [det_updateRow_trace] using hasDerivAt_det_update hQ + +lemma adjugate_eq_det_smul_inv (M : Matrix ι ι ℝ) (hM : IsUnit M) : + M.adjugate=M.det • M⁻¹ := by + have hd : M.det ≠ 0 := (Matrix.isUnit_iff_isUnit_det M).mp hM |>.ne_zero + rw [Matrix.inv_def,Ring.inverse_eq_inv,smul_smul,mul_inv_cancel₀ hd,one_smul] + +lemma hasDerivAt_det {Q : ℝ → Matrix ι ι ℝ} {Q' : Matrix ι ι ℝ} {t : ℝ} + (hQ : ∀ i k, HasDerivAt (fun x => Q x i k) (Q' i k) t) (hunit : IsUnit (Q t)) : + HasDerivAt (fun x => (Q x).det) ((Q t).det*(Q'*(Q t)⁻¹).trace) t := by + have h := hasDerivAt_det_adjugate hQ + rw [adjugate_eq_det_smul_inv _ hunit,Matrix.mul_smul,Matrix.trace_smul,smul_eq_mul] at h + exact h + +lemma hasDerivAt_logdet {Q : ℝ → Matrix ι ι ℝ} {Q' : Matrix ι ι ℝ} {t : ℝ} + (hQ : ∀ i k, HasDerivAt (fun x => Q x i k) (Q' i k) t) (hunit : IsUnit (Q t)) : + HasDerivAt (fun x => Real.log (Q x).det) (Q'*(Q t)⁻¹).trace t := by + have hd : (Q t).det ≠ 0 := (Matrix.isUnit_iff_isUnit_det _).mp hunit |>.ne_zero + have h := (hasDerivAt_det hQ hunit).log hd + convert h using 1 + field_simp +end SKRatioGaussian.LogDet +end +end + +section + +noncomputable section +open MeasureTheory ProbabilityTheory InformationTheory Real Set +open scoped NNReal ENNReal + +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Matrices/DiagonalSqrt.lean b/lean/OAI/Probability/SKRatio/Matrices/DiagonalSqrt.lean new file mode 100644 index 0000000000000000000000000000000000000000..83754b9d454b30caa2163c3088490bb5d9479cfd --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Matrices/DiagonalSqrt.lean @@ -0,0 +1,143 @@ +import Mathlib +import OAI.Probability.SKRatio.Matrices.QuadraticCoeff + +namespace OAI + +section +section +noncomputable section +open MeasureTheory ProbabilityTheory InformationTheory Real Set +open scoped NNReal ENNReal +open Filter +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius ENNReal NNReal +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius NNReal +noncomputable section +open MeasureTheory ProbabilityTheory Real Set Filter +open MeasureTheory.Measure +open scoped ENNReal NNReal MeasureTheory Topology +open MeasureTheory +noncomputable section +noncomputable section +open MeasureTheory Set NormedSpace +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius +noncomputable section +open Set Real +open scoped Topology +noncomputable section +open Matrix Set Filter +open scoped Topology Matrix.Norms.Frobenius +noncomputable section +open Matrix NormedSpace ContinuousLinearMap +open scoped Matrix.Norms.Frobenius +noncomputable section +open Matrix +noncomputable section +open MeasureTheory ProbabilityTheory Real Set +open scoped ENNReal NNReal +noncomputable section +open MeasureTheory ProbabilityTheory InformationTheory Real Set +open scoped NNReal ENNReal +noncomputable section +open scoped BigOperators +open MeasureTheory ProbabilityTheory +namespace SKRatioGaussian +section DiagonalGeometry +variable {ι : Type*} [Fintype ι] + +def diagonalSqrt (a : ι → ℝ) (p : EuclideanSpace ℝ ι) : EuclideanSpace ℝ ι := + WithLp.toLp 2 (fun i => Real.sqrt (a i) * p i) + +lemma diagonalSqrt_norm_sq (a : ι → ℝ) (ha : ∀ i, 0 ≤ a i) (p : EuclideanSpace ℝ ι) : + ‖diagonalSqrt a p‖^2 = ∑ i, a i * (p i)^2 := by + rw [EuclideanSpace.norm_sq_eq] + apply Finset.sum_congr rfl + intro i _ + simp only [diagonalSqrt, WithLp.ofLp_toLp, Real.norm_eq_abs, sq_abs, mul_pow, + Real.sq_sqrt (ha i)] + +lemma diagonalSqrt_norm_sq_le {a : ι → ℝ} {A : ℝ} + (ha : ∀ i, 0 ≤ a i) (hA : ∀ i, a i ≤ A) (p : EuclideanSpace ℝ ι) : + ‖diagonalSqrt a p‖^2 ≤ A * ‖p‖^2 := by + rw [diagonalSqrt_norm_sq a ha, ← sum_coord_sq, Finset.mul_sum] + exact Finset.sum_le_sum (fun i _ => mul_le_mul_of_nonneg_right (hA i) (sq_nonneg _)) + +lemma diagonalSqrt_norm_le_sqrt {a : ι → ℝ} {A : ℝ} + (ha : ∀ i, 0 ≤ a i) (hA0 : 0 ≤ A) (hA : ∀ i, a i ≤ A) + {p : EuclideanSpace ℝ ι} (hp : ‖p‖ ≤ 1) : + ‖diagonalSqrt a p‖ ≤ Real.sqrt A := by + have h := diagonalSqrt_norm_sq_le ha hA p + have hp2 : ‖p‖^2 ≤ 1 := by nlinarith [norm_nonneg p] + have hh := mul_le_mul_of_nonneg_left hp2 hA0 + have hs := Real.sq_sqrt hA0 + have hs0 := Real.sqrt_nonneg A + nlinarith [norm_nonneg (diagonalSqrt a p)] + +omit [Fintype ι] in +lemma continuous_diagonalSqrt (a : ι → ℝ) : Continuous (diagonalSqrt a) := by + apply (PiLp.continuous_toLp 2 (fun _ : ι => ℝ)).comp + exact continuous_pi (fun i => continuous_const.mul (PiLp.continuous_apply 2 (fun _ => ℝ) i)) + +lemma diagonal_sum_mul_le_norm (a : ι → ℝ) (p g : EuclideanSpace ℝ ι) : + (∑ i, diagonalSqrt a p i * g i) ≤ ‖p‖ * ‖diagonalSqrt a g‖ := by + have he : (∑ i, diagonalSqrt a p i * g i) = inner ℝ p (diagonalSqrt a g) := by + rw [PiLp.inner_apply] + apply Finset.sum_congr rfl + intro i _ + simp only [diagonalSqrt, WithLp.ofLp_toLp, RCLike.inner_apply, conj_trivial] + ring + rw [he] + exact real_inner_le_norm _ _ + +lemma quadraticCoeff_norm {r : ℝ} (hr : 0 ≤ r) (w : EuclideanSpace ℝ ι) : + ‖WithLp.toLp 2 (quadraticCoeff r w)‖ = Real.sqrt (2*r) * ‖w‖^2 := by + have hsum : (∑ k, (quadraticCoeff r w k)^2) = 2*r*‖w‖^4 := by + have h := quadraticCoeff_increment r hr w 0 + have h0 : quadraticCoeff r (0 : EuclideanSpace ℝ ι) = 0 := by + funext k + cases k <;> simp [quadraticCoeff] + simpa only [h0, Pi.zero_apply, sub_zero, norm_zero, zero_pow (by norm_num : (4 : ℕ) ≠ 0), + WithLp.ofLp_zero, zero_mul, mul_zero, Finset.sum_const_zero, zero_pow (by norm_num : (2 : ℕ) ≠ 0), + add_zero] using h + have he : ‖WithLp.toLp 2 (quadraticCoeff r w)‖^2 = + (Real.sqrt (2*r) * ‖w‖^2)^2 := by + rw [← sum_coord_sq, hsum, mul_pow, Real.sq_sqrt (by positivity)] + ring + have hnon : 0 ≤ Real.sqrt (2*r) * ‖w‖^2 := by positivity + nlinarith [norm_nonneg (WithLp.toLp 2 (quadraticCoeff r w))] + +end DiagonalGeometry + +lemma quadratic_margin {d b : ℝ} (_hd : 0 ≤ d) (hdb : d ≤ b) (hb : b ≤ 1) : + 2*d-d^2 ≤ 1-(1-b)^2 := by + nlinarith [mul_nonneg (sub_nonneg.mpr hdb) (show 0 ≤ 2-b-d by linarith)] + +end SKRatioGaussian + +open Real + +end +end +end +end +end +end +end +end +end +end +end +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Matrices/DiagonalSum.lean b/lean/OAI/Probability/SKRatio/Matrices/DiagonalSum.lean new file mode 100644 index 0000000000000000000000000000000000000000..1ae14352547b880e98acc32b05d6d6aadc535c54 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Matrices/DiagonalSum.lean @@ -0,0 +1,146 @@ +import Mathlib + +namespace OAI + +section +section +noncomputable section +open MeasureTheory ProbabilityTheory InformationTheory Real Set +open scoped NNReal ENNReal +open Filter +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius ENNReal NNReal +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius NNReal +noncomputable section +open MeasureTheory ProbabilityTheory Real Set Filter +open MeasureTheory.Measure +open scoped ENNReal NNReal MeasureTheory Topology +open MeasureTheory +noncomputable section +noncomputable section +open MeasureTheory Set NormedSpace +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius +noncomputable section +open Set Real +open scoped Topology +noncomputable section +open Matrix Set Filter +open scoped Topology Matrix.Norms.Frobenius +noncomputable section +open Matrix NormedSpace ContinuousLinearMap +open scoped Matrix.Norms.Frobenius +noncomputable section +open Matrix +noncomputable section +open MeasureTheory ProbabilityTheory Real Set +open scoped ENNReal NNReal +noncomputable section +open MeasureTheory ProbabilityTheory InformationTheory Real Set +open scoped NNReal ENNReal +noncomputable section +open scoped BigOperators +open MeasureTheory ProbabilityTheory +open Real +noncomputable section +open scoped BigOperators Topology +open Filter Real +namespace SKRatioGaussian +section MatrixScale +variable {ι : Type*} [Fintype ι] + +lemma diagonal_sum_le {a : ι → ℝ} {A : ℝ} (hA : ∀ i, a i ≤ A) : + (∑ i, a i) ≤ (Fintype.card ι : ℝ) * A := by + simpa only [Finset.sum_const, Finset.card_univ, nsmul_eq_mul] using + Finset.sum_le_sum (fun i (_ : i ∈ Finset.univ) => hA i) + +lemma diagonal_sq_sum_le {a : ι → ℝ} {A : ℝ} + (ha : ∀ i, 0 ≤ a i) (hA : ∀ i, a i ≤ A) : + (∑ i, (a i)^2) ≤ (Fintype.card ι : ℝ) * A^2 := + diagonal_sum_le (fun i => by nlinarith [ha i, hA i]) + +lemma scaled_mean_bound [Nonempty ι] {j A : ℝ} {a : ι → ℝ} + (hj : 0 ≤ j) (hA : ∀ i, a i ≤ A) : + (j / (Fintype.card ι : ℝ)) * (∑ i, a i) ≤ j*A := by + have hn : 0 < (Fintype.card ι : ℝ) := by exact_mod_cast Fintype.card_pos + have h := mul_le_mul_of_nonneg_left (diagonal_sum_le hA) (div_nonneg hj hn.le) + calc + _ ≤ _ := h + _ = _ := by field_simp + +lemma scaled_variance_bound [Nonempty ι] {j A : ℝ} {a : ι → ℝ} + (ha : ∀ i, 0 ≤ a i) (hA : ∀ i, a i ≤ A) : + 2*(j / (Fintype.card ι : ℝ))^2 * (∑ i, (a i)^2) ≤ + 2*j^2*A^2 / (Fintype.card ι : ℝ) := by + have hn : 0 < (Fintype.card ι : ℝ) := by exact_mod_cast Fintype.card_pos + have h := mul_le_mul_of_nonneg_left (diagonal_sq_sum_le ha hA) + (show 0 ≤ 2*(j / (Fintype.card ι : ℝ))^2 by positivity) + calc + _ ≤ _ := h + _ = _ := by field_simp + +lemma scaled_sqrt_mean_bound [Nonempty ι] {j A : ℝ} {a : ι → ℝ} + (hj : 0 ≤ j) (ha : ∀ i, 0 ≤ a i) (hA : ∀ i, a i ≤ A) (hA0 : 0 ≤ A) : + sqrt ((j / (Fintype.card ι : ℝ)) * (∑ i, a i)) * sqrt A ≤ sqrt j * A := by + have hn : 0 ≤ (Fintype.card ι : ℝ) := by positivity + have hq : 0 ≤ (j / (Fintype.card ι : ℝ)) * ∑ i, a i := + mul_nonneg (div_nonneg hj hn) (Finset.sum_nonneg (fun i _ => ha i)) + rw [← sqrt_mul hq] + calc + _ ≤ sqrt (j * A^2) := sqrt_le_sqrt (by + have h := mul_le_mul_of_nonneg_right (scaled_mean_bound hj hA) hA0 + nlinarith only [h]) + _ = sqrt j * A := by rw [sqrt_mul hj, sqrt_sq hA0] + +lemma subcritical_endpoint_margin {b : ℝ} (hb0 : 0 ≤ b) (hb1 : b ≤ 1) : + b^2 ≤ 1 - (1-b)^2/2 := by + nlinarith [mul_nonneg (sub_nonneg.mpr hb1) (show 0 ≤ 3*b+1 by positivity)] + +lemma scaled_qA_bound [Nonempty ι] {j A : ℝ} {a : ι → ℝ} + (hj : 0 ≤ j) (hA : ∀ i, a i ≤ A) (hA0 : 0 ≤ A) + (hsub : sqrt j * A ≤ 1) : + ((j / (Fintype.card ι : ℝ)) * (∑ i, a i))*A ≤ + 1-(1-sqrt j*A)^2/2 := by + have h := mul_le_mul_of_nonneg_right (scaled_mean_bound hj hA) hA0 + have hm := subcritical_endpoint_margin (show 0 ≤ sqrt j*A by positivity) hsub + have he : (sqrt j*A)^2 = j*A^2 := by rw [mul_pow, sq_sqrt hj] + rw [he] at hm + nlinarith only [h, hm] + +end MatrixScale + +lemma diagonal_error_tendsto (j A : ℝ) : + Tendsto (fun n : ℕ => 2*sqrt A * sqrt (sqrt (2*j^2*A^2/(n:ℝ)))) atTop (𝓝 0) := by + have hd : Tendsto (fun n : ℕ => 2*j^2*A^2/(n:ℝ)) atTop (𝓝 0) := + tendsto_const_div_atTop_nhds_zero_nat (2*j^2*A^2) + simpa only [sqrt_zero, mul_zero, Function.comp_def] using + (tendsto_const_nhds.mul (Real.continuous_sqrt.continuousAt.tendsto.comp + (Real.continuous_sqrt.continuousAt.tendsto.comp hd))) + +end SKRatioGaussian + +end +end +end +end +end +end +end +end +end +end +end +end +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Matrices/DiagonalTMemLp.lean b/lean/OAI/Probability/SKRatio/Matrices/DiagonalTMemLp.lean new file mode 100644 index 0000000000000000000000000000000000000000..8cb03bf450913d81d06491002536efd567114c3b --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Matrices/DiagonalTMemLp.lean @@ -0,0 +1,181 @@ +import Mathlib +import OAI.Probability.SKRatio.Matrices.UnitBall +import OAI.Probability.SKRatio.Matrices.GaussianProductUpperTailLipschitz + +namespace OAI + +section +section +noncomputable section +open MeasureTheory ProbabilityTheory InformationTheory Real Set +open scoped NNReal ENNReal +open Filter +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius ENNReal NNReal +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius NNReal +noncomputable section +open MeasureTheory ProbabilityTheory Real Set Filter +open MeasureTheory.Measure +open scoped ENNReal NNReal MeasureTheory Topology +open MeasureTheory +noncomputable section +noncomputable section +open MeasureTheory Set NormedSpace +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius +noncomputable section +open Set Real +open scoped Topology +noncomputable section +open Matrix Set Filter +open scoped Topology Matrix.Norms.Frobenius +noncomputable section +open Matrix NormedSpace ContinuousLinearMap +open scoped Matrix.Norms.Frobenius +noncomputable section +open Matrix +noncomputable section +open MeasureTheory ProbabilityTheory Real Set +open scoped ENNReal NNReal +noncomputable section +open MeasureTheory ProbabilityTheory InformationTheory Real Set +open scoped NNReal ENNReal +noncomputable section +open scoped BigOperators +open MeasureTheory ProbabilityTheory +open Real +noncomputable section +open scoped BigOperators Topology +open Filter Real +namespace SKRatioGaussian +section GOEProbability +variable {ι : Type*} [Fintype ι] [Nonempty ι] + +omit [Nonempty ι] in +lemma diagonalT_memLp {r : ℝ} (hr : 0 ≤ r) {a : ι → ℝ} (ha : ∀ i, 0 ≤ a i) : + MemLp (diagonalT r a) 2 (gaussianCoordinates (MatrixCoordinates ι)) := by + apply memLp_sqrt_of_nonneg ((gaussianQuadratic_memLp (diagonalWeights r a)).integrable + (by norm_num)) + intro g + apply Finset.sum_nonneg + intro k _ + apply mul_nonneg _ (sq_nonneg _) + cases k <;> simp only [diagonalWeights] + · exact le_rfl + · exact mul_nonneg hr (ha _) + +omit [Nonempty ι] in +lemma diagonalT_mean_le {r : ℝ} (hr : 0 ≤ r) {a : ι → ℝ} (ha : ∀ i, 0 ≤ a i) : + (∫ g, diagonalT r a g ∂gaussianCoordinates (MatrixCoordinates ι)) ≤ + sqrt (r * ∑ i, a i) := by + have he (g : MatrixCoordinates ι → ℝ) : (diagonalT r a g)^2 = + gaussianQuadratic (diagonalWeights r a) g := by + apply sq_sqrt + apply Finset.sum_nonneg + intro k _ + apply mul_nonneg _ (sq_nonneg _) + cases k <;> simp only [diagonalWeights] + · exact le_rfl + · exact mul_nonneg hr (ha _) + have h := integral_abs_le_sqrt_sq (diagonalT_memLp hr ha) + simp_rw [he, abs_of_nonneg (show 0 ≤ diagonalT r a _ from sqrt_nonneg _)] at h + have hm : (∫ g, gaussianQuadratic (diagonalWeights r a) g + ∂gaussianCoordinates (MatrixCoordinates ι)) = r * ∑ i, a i := by + simpa only [gaussianCoordinates, diagonalWeights_sum] using gaussianQuadratic_mean (diagonalWeights r a) + rwa [hm] at h + +theorem goe_expected_top {j : ℝ} (hj : 0 ≤ j) : + (∫ g, diagonalProcess (j/(Fintype.card ι:ℝ)) (fun _ : ι => 1) 1 0 g + ∂gaussianCoordinates (MatrixCoordinates ι)) ≤ 2*sqrt j := by + let r := j/(Fintype.card ι:ℝ) + let a : ι → ℝ := fun _ => 1 + have hr : 0 ≤ r := div_nonneg hj (by positivity) + have ha : ∀ i, 0 ≤ a i := by intro; norm_num [a] + have hc := gaussian_quadraticSup_comparison (continuous_diagonalOffset a 1 0) + ((continuous_diagonalSqrt a).comp continuous_subtype_val) hr 1 + change (∫ g, diagonalProcess r a 1 0 g ∂gaussianCoordinates (MatrixCoordinates ι)) ≤ + (∫ g, diagonalLinearProcess r a 1 0 g ∂gaussianCoordinates (MatrixCoordinates ι)) at hc + have hb (g) : diagonalLinearProcess r a 1 0 g ≤ 2*diagonalT r a g := by + have h := diagonalLinearProcess_le (A := 1) (b := 0) hr ha + (by intro; exact le_rfl) zero_le_one (by norm_num : (0:ℝ) ≤ 1) le_rfl + le_rfl (by norm_num) zero_le_one g + simpa only [sub_zero, one_pow, sub_self, sqrt_zero, sqrt_one, mul_one, + abs_of_nonneg (show 0 ≤ diagonalT r a g from sqrt_nonneg _), zero_add] using h + have hi := diagonalT_integrable hr ha + calc + _ ≤ ∫ g, diagonalLinearProcess r a 1 0 g + ∂gaussianCoordinates (MatrixCoordinates ι) := hc + _ ≤ ∫ g, 2*diagonalT r a g ∂gaussianCoordinates (MatrixCoordinates ι) := + integral_mono (integrable_diagonalLinearProcess r a 1 0) (hi.const_mul 2) hb + _ = 2 * ∫ g, diagonalT r a g ∂gaussianCoordinates (MatrixCoordinates ι) := + integral_const_mul _ _ + _ ≤ 2*sqrt (r * ∑ i, a i) := mul_le_mul_of_nonneg_left (diagonalT_mean_le hr ha) (by norm_num) + _ = 2*sqrt j := by + have hn : (Fintype.card ι:ℝ) ≠ 0 := by exact_mod_cast Fintype.card_ne_zero + simp [a, r, hn] + +lemma gaussianCoordinates_preserving_neg {κ : Type*} [Fintype κ] : + MeasurePreserving (fun g : κ → ℝ => -g) (gaussianCoordinates κ) + (gaussianCoordinates κ) := by + apply measurePreserving_pi (f := fun _ => fun x : ℝ => -x) + (fun _ => gaussianReal 0 1) (fun _ => gaussianReal 0 1) + intro i + exact ⟨by fun_prop, by simpa using (gaussianReal_map_neg (μ := 0) (v := 1))⟩ + +theorem goe_top_tail {j ε : ℝ} (hj : 0 < j) (hε : 0 ≤ ε) : + (gaussianCoordinates (MatrixCoordinates ι)).real + {g | 2*sqrt j+ε < diagonalProcess (j/(Fintype.card ι:ℝ)) (fun _ : ι => 1) 1 0 g} ≤ + Real.exp (-ε^2*(Fintype.card ι:ℝ)/(π^2*j)) := by + let r := j/(Fintype.card ι:ℝ) + let P := diagonalProcess r (fun _ : ι => 1) 1 0 + have hn : 0 < (Fintype.card ι:ℝ) := by exact_mod_cast Fintype.card_pos + have hr : 0 < r := div_pos hj hn + have hL := diagonalProcess_lipschitz (a := fun _ : ι => 1) hr.le (fun _ => zero_le_one) + (fun _ => le_rfl) zero_le_one (by norm_num : (0:ℝ) ≤ 1) 0 + have hLp : 0 < Real.toNNReal (1*sqrt (2*r)*1) := by + rw [Real.toNNReal_pos]; positivity + have ht := gaussianProduct_upper_tail_lipschitz hL hLp hε + have hm := goe_expected_top (ι := ι) hj.le + have hs : {g | 2*sqrt j+ε < P g} ⊆ + {g | ε ≤ P g - ∫ g, P g ∂gaussianCoordinates (MatrixCoordinates ι)} := by + intro g hg + change ε ≤ P g - ∫ g, P g ∂gaussianCoordinates (MatrixCoordinates ι) + change _ < P g at hg + change (∫ g, P g ∂gaussianCoordinates (MatrixCoordinates ι)) ≤ 2*sqrt j at hm + linarith + exact (measureReal_mono hs).trans (ht.trans_eq (by + congr 1 + rw [Real.coe_toNNReal _ (by positivity)] + simp only [one_mul, mul_one] + rw [sq_sqrt (by positivity)] + dsimp [r] + field_simp)) + +end GOEProbability +end SKRatioGaussian + +end +end +end +end +end +end +end +end +end +end +end +end +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Matrices/EntryLM.lean b/lean/OAI/Probability/SKRatio/Matrices/EntryLM.lean new file mode 100644 index 0000000000000000000000000000000000000000..144048a8f9f974dd5fa5c5852684f7d3da4ff043 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Matrices/EntryLM.lean @@ -0,0 +1,151 @@ +import Mathlib +import OAI.Probability.SKRatio.Matrices.Imaginary + +namespace OAI + +section +section +noncomputable section +open MeasureTheory ProbabilityTheory InformationTheory Real Set +open scoped NNReal ENNReal +open Filter +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius ENNReal NNReal +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius NNReal +noncomputable section +open MeasureTheory ProbabilityTheory Real Set Filter +open MeasureTheory.Measure +open scoped ENNReal NNReal MeasureTheory Topology +open MeasureTheory +noncomputable section +noncomputable section +open MeasureTheory Set NormedSpace +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius +namespace SKRatioGaussian.ComplexMatrix +open MeasureTheory Set NormedSpace +open scoped Topology FourierTransform SchwartzMap +variable {ι : Type*} [Fintype ι] [DecidableEq ι] + +local instance : ContinuousENorm (Matrix ι ι ℂ) := + @SeminormedAddGroup.toContinuousENorm _ Matrix.frobeniusSeminormedAddCommGroup.toSeminormedAddGroup +local instance : TopologicalSpace.PseudoMetrizableSpace (Matrix ι ι ℂ) := + inferInstanceAs (TopologicalSpace.PseudoMetrizableSpace (ι → ι → ℂ)) + +def entryLM (i j : ι) : Matrix ι ι ℂ →ₗ[ℂ] ℂ where + toFun := fun M => M i j + map_add' := by intros; rfl + map_smul' := by intros; rfl + +def entryCLM (i j : ι) : Matrix ι ι ℂ →L[ℂ] ℂ := (entryLM i j).toContinuousLinearMap + +lemma integral_entry {F : ℝ → Matrix ι ι ℂ} (hF : Integrable F) (i j : ι) : + (∫ t : ℝ, F t) i j = ∫ t : ℝ, F t i j := by + exact ((entryCLM i j).integral_comp_comm hF).symm + +def conjugate (U : unitary (Matrix ι ι ℂ)) : Matrix ι ι ℂ ≃⋆ₐ[ℂ] Matrix ι ι ℂ := + Unitary.conjStarAlgAut ℂ _ U + +def conjugateCLM (U : unitary (Matrix ι ι ℂ)) : Matrix ι ι ℂ →L[ℂ] Matrix ι ι ℂ := + (conjugate U).toAlgEquiv.toLinearMap.toContinuousLinearMap + +lemma conjugate_exp (U : unitary (Matrix ι ι ℂ)) (M : Matrix ι ι ℂ) : + conjugate U (exp M) = exp (conjugate U M) := by + exact NormedSpace.map_exp (conjugate U).toRingHom (conjugateCLM U).continuous M + +lemma conjugate_imaginary (U : unitary (Matrix ι ι ℂ)) (t : ℝ) (M : Matrix ι ι ℂ) : + conjugate U (imaginary t M) = imaginary t (conjugate U M) := by + exact (conjugate U).map_smul' _ _ + +lemma kernelMatrix_conjugate {g : ℝ → ℂ} (hg : Integrable g) (U : unitary (Matrix ι ι ℂ)) + (M : Matrix ι ι ℂ) (hM : Mᴴ = M) : + kernelMatrix g (conjugate U M) = conjugate U (kernelMatrix g M) := by + have hi := (conjugateCLM U).integral_comp_comm (kernel_integrable hg M hM) + change _ = (conjugateCLM U) (∫ t : ℝ, g t • exp (imaginary t M)) + calc + _ = ∫ t : ℝ, (conjugateCLM U) (g t • exp (imaginary t M)) := by + apply integral_congr_ae + filter_upwards [] with t + change g t • exp (imaginary t (conjugate U M)) = conjugate U (g t • exp (imaginary t M)) + rw [map_smul,conjugate_exp,conjugate_imaginary] + _ = _ := hi + +lemma kernelMatrix_diagonal {g : ℝ → ℂ} (hg : Integrable g) (x : ι → ℝ) : + kernelMatrix g (diagonal (fun i => (x i : ℂ))) = + diagonal (fun i => ∫ t : ℝ, g t * Complex.exp ((t : ℂ)*Complex.I*(x i : ℂ))) := by + have hD : (diagonal (fun i => (x i : ℂ)))ᴴ = diagonal (fun i => (x i : ℂ)) := by + simp [Matrix.diagonal_conjTranspose] + ext i j + rw [kernelMatrix,integral_entry (kernel_integrable hg _ hD)] + have hexp (t : ℝ) : exp (imaginary t (diagonal (fun i => (x i : ℂ)))) = + diagonal (fun i => Complex.exp ((t : ℂ)*Complex.I*(x i : ℂ))) := by + rw [imaginary,← diagonal_smul,Matrix.exp_diagonal] + congr 1 + ext i + rw [Pi.coe_exp,← Complex.exp_eq_exp_ℂ] + rfl + simp_rw [hexp,Matrix.smul_apply,smul_eq_mul] + by_cases hij : i = j + · subst j; simp + · simp [hij] + +noncomputable def schwartzMatrix (f : 𝓢(ℝ, ℂ)) (M : Matrix ι ι ℂ) : Matrix ι ι ℂ := + kernelMatrix ((𝓕 f : 𝓢(ℝ,ℂ)) : ℝ → ℂ) ((2*Real.pi : ℝ) • M) + +lemma fourier_scalar_inverse (f : 𝓢(ℝ, ℂ)) (x : ℝ) : + (∫ t : ℝ, (𝓕 f) t * Complex.exp ((t : ℂ)*Complex.I*((2*Real.pi*x : ℝ) : ℂ))) = f x := by + have hh := congrArg (fun g : 𝓢(ℝ,ℂ) => g x) (show (𝓕⁻ (𝓕 f : 𝓢(ℝ,ℂ)) : 𝓢(ℝ,ℂ)) = f from FourierTransform.fourierInv_fourier_eq f) + rw [SchwartzMap.fourierInv_coe,Real.fourierInv_eq'] at hh + rw [← hh] + apply integral_congr_ae + filter_upwards [] with t + simp only [smul_eq_mul,Real.inner_apply] + conv_lhs => rw [mul_comm] + congr 1 + congr 1 + push_cast + ring + +lemma schwartzMatrix_diagonal (f : 𝓢(ℝ,ℂ)) (x : ι → ℝ) : + schwartzMatrix f (diagonal (fun i => (x i : ℂ))) = diagonal (fun i => f (x i)) := by + rw [schwartzMatrix,← diagonal_smul] + have heq : (2*Real.pi : ℝ) • (fun i => (x i : ℂ)) = fun i => ((2*Real.pi*x i : ℝ) : ℂ) := by + ext i; simp + rw [heq,kernelMatrix_diagonal (𝓕 f).integrable] + congr 1 + ext i + exact fourier_scalar_inverse f (x i) + +lemma schwartzMatrix_conjugate (f : 𝓢(ℝ,ℂ)) (U : unitary (Matrix ι ι ℂ)) + (M : Matrix ι ι ℂ) (hM : Mᴴ = M) : + schwartzMatrix f (conjugate U M) = conjugate U (schwartzMatrix f M) := by + have heq : (2*Real.pi : ℝ) • conjugate U M = conjugate U ((2*Real.pi : ℝ) • M) := by + simp [conjugate,Unitary.conjStarAlgAut_apply] + rw [schwartzMatrix,heq] + exact kernelMatrix_conjugate (𝓕 f).integrable U _ (by simp [hM]) + +lemma schwartzMatrix_spectral (f : 𝓢(ℝ,ℂ)) (M : Matrix ι ι ℂ) (hM : M.IsHermitian) : + schwartzMatrix f M = conjugate hM.eigenvectorUnitary (diagonal (fun i => f (hM.eigenvalues i))) := by + conv_lhs => rw [hM.spectral_theorem] + change schwartzMatrix f (conjugate hM.eigenvectorUnitary (diagonal (fun i => (hM.eigenvalues i : ℂ)))) = _ + rw [schwartzMatrix_conjugate f _ _ (by simp [Matrix.diagonal_conjTranspose]),schwartzMatrix_diagonal] + +end SKRatioGaussian.ComplexMatrix + +end +end +end +end +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Matrices/ExpDuhamel.lean b/lean/OAI/Probability/SKRatio/Matrices/ExpDuhamel.lean new file mode 100644 index 0000000000000000000000000000000000000000..377b1b54d9a44e615b2c05a2a90bda6db22b9514 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Matrices/ExpDuhamel.lean @@ -0,0 +1,88 @@ +import Mathlib + +namespace OAI + +section +section +noncomputable section +open MeasureTheory ProbabilityTheory InformationTheory Real Set +open scoped NNReal ENNReal +open Filter +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius ENNReal NNReal +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius NNReal +noncomputable section +open MeasureTheory ProbabilityTheory Real Set Filter +open MeasureTheory.Measure +open scoped ENNReal NNReal MeasureTheory Topology +open MeasureTheory +noncomputable section +noncomputable section +open MeasureTheory Set NormedSpace +open scoped Topology +namespace SKRatioGaussian +section Algebra +variable {A : Type*} [NormedRing A] [NormedAlgebra ℝ A] [NormedAlgebra ℚ A] [CompleteSpace A] + +lemma exp_duhamel (a b : A) : + exp a - exp b = ∫ u : ℝ in (0 : ℝ)..1, exp ((1-u) • a) * (a-b) * exp (u • b) := by + have hd (u : ℝ) : HasDerivAt (fun u : ℝ => exp ((1-u) • a) * exp (u • b)) + (-(exp ((1-u) • a) * (a-b) * exp (u • b))) u := by + have h₁ := (hasDerivAt_exp_smul_const a (1-u)).scomp u ((hasDerivAt_const u (1:ℝ)).sub (hasDerivAt_id u)) + have h₂ := hasDerivAt_exp_smul_const' b u + convert h₁.mul h₂ using 1 <;> (try simp only [zero_sub, neg_smul, one_smul]) <;> noncomm_ring + have hc : Continuous (fun u : ℝ => -(exp ((1-u) • a) * (a-b) * exp (u • b))) := by fun_prop + have hh := intervalIntegral.integral_eq_sub_of_hasDerivAt (fun u _ => hd u) + (hc.intervalIntegrable 0 1) + simpa only [intervalIntegral.integral_neg, sub_self, zero_smul, NormedSpace.exp_zero, one_mul, + sub_zero, one_smul, mul_one, neg_neg, neg_sub] using congrArg Neg.neg hh.symm + +end Algebra + +section CStar +variable {A : Type*} [NormedRing A] [NormedAlgebra ℝ A] [NormedAlgebra ℚ A] [CompleteSpace A] + [StarRing A] [ContinuousStar A] [CStarRing A] + +omit [CStarRing A] in +lemma exp_skew_unitary (a : A) (ha : star a = -a) (t : ℝ) + [StarModule ℝ A] : exp (t • a) ∈ unitary A := by + apply exp_mem_unitary_of_mem_skewAdjoint + change star (t • a) = -(t • a) + simp [ha] + +lemma exp_skew_difference [StarModule ℝ A] (a b : A) + (ha : star a = -a) (hb : star b = -b) : ‖exp a - exp b‖ ≤ ‖a-b‖ := by + rw [exp_duhamel] + have hc : Continuous (fun u : ℝ => exp ((1-u) • a) * (a-b) * exp (u • b)) := by fun_prop + have hh : ∀ u : ℝ, ‖exp ((1-u) • a) * (a-b) * exp (u • b)‖ = ‖a-b‖ := by + intro u + rw [CStarRing.norm_mul_coe_unitary _ ⟨_,exp_skew_unitary b hb u⟩, + CStarRing.norm_coe_unitary_mul ⟨_,exp_skew_unitary a ha (1-u)⟩] + calc + ‖∫ u : ℝ in (0 : ℝ)..1, exp ((1-u) • a) * (a-b) * exp (u • b)‖ ≤ + ∫ u : ℝ in (0 : ℝ)..1, ‖exp ((1-u) • a) * (a-b) * exp (u • b)‖ := + intervalIntegral.norm_integral_le_integral_norm (by norm_num) + _ = ‖a-b‖ := by simp only [hh]; simp + +end CStar +end SKRatioGaussian + +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius + +end +end +end +end +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Matrices/ExpSum.lean b/lean/OAI/Probability/SKRatio/Matrices/ExpSum.lean new file mode 100644 index 0000000000000000000000000000000000000000..2fb76e8a7cadd0e3e6ebedd2ca488b7f5386111c --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Matrices/ExpSum.lean @@ -0,0 +1,502 @@ +import Mathlib +import OAI.Probability.SKRatio.Matrices.StandardGaussianProduct + +namespace OAI + +section +section +noncomputable section +open MeasureTheory ProbabilityTheory InformationTheory Real Set +open scoped NNReal ENNReal +open Filter +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius ENNReal NNReal +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius NNReal +noncomputable section +open MeasureTheory ProbabilityTheory Real Set Filter +open MeasureTheory.Measure +open scoped ENNReal NNReal MeasureTheory Topology +open MeasureTheory +noncomputable section +noncomputable section +open MeasureTheory Set NormedSpace +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius +noncomputable section +open Set Real +open scoped Topology +noncomputable section +open Matrix Set Filter +open scoped Topology Matrix.Norms.Frobenius +noncomputable section +open Matrix NormedSpace ContinuousLinearMap +open scoped Matrix.Norms.Frobenius +noncomputable section +open Matrix +noncomputable section +open MeasureTheory ProbabilityTheory Real Set +open scoped ENNReal NNReal +noncomputable section +open MeasureTheory ProbabilityTheory InformationTheory Real Set +open scoped NNReal ENNReal +namespace SKRatioGaussian + +instance (n : ℕ) : IsProbabilityMeasure (standardGaussianProduct n) := by + unfold standardGaussianProduct + infer_instance + +variable {ι : Type*} [Fintype ι] [Nonempty ι] + +def expSum (κ : ℝ) (x : ι → ℝ) : ℝ := ∑ i, Real.exp (κ * x i) +def softWeight (κ : ℝ) (x : ι → ℝ) (i : ι) : ℝ := Real.exp (κ * x i) / expSum κ x +def smoothMax (κ : ℝ) (x : ι → ℝ) : ℝ := log (expSum κ x) / κ + +theorem expSum_pos (κ : ℝ) (x : ι → ℝ) : 0 < expSum κ x := by + exact Finset.sum_pos (fun i _ => exp_pos _) Finset.univ_nonempty + +theorem softWeight_pos (κ : ℝ) (x : ι → ℝ) (i : ι) : 0 < softWeight κ x i := + div_pos (exp_pos _) (expSum_pos κ x) + +theorem sum_softWeight (κ : ℝ) (x : ι → ℝ) : ∑ i, softWeight κ x i = 1 := by + simp only [softWeight, ← Finset.sum_div] + exact div_self (expSum_pos κ x).ne' + +theorem softWeight_le_one (κ : ℝ) (x : ι → ℝ) (i : ι) : softWeight κ x i ≤ 1 := by + rw [← sum_softWeight κ x] + exact Finset.single_le_sum (fun j _ => (softWeight_pos κ x j).le) (Finset.mem_univ i) + +theorem continuous_softWeight (κ : ℝ) (i : ι) : Continuous (fun x : ι → ℝ => softWeight κ x i) := by + apply Continuous.div + · exact continuous_exp.comp (continuous_const.mul (continuous_apply i)) + · exact continuous_finsetSum _ (fun j _ => continuous_exp.comp (continuous_const.mul (continuous_apply j))) + · exact fun x => (expSum_pos κ x).ne' + +theorem continuous_smoothMax (κ : ℝ) : Continuous (smoothMax κ : (ι → ℝ) → ℝ) := by + apply Continuous.div_const + exact (continuous_finsetSum _ (fun j _ => continuous_exp.comp (continuous_const.mul (continuous_apply j)))).log + (fun x => (expSum_pos κ x).ne') + +omit [Nonempty ι] in +theorem hasDerivAt_expSum {κ t : ℝ} {f : ι → ℝ → ℝ} {df : ι → ℝ} + (hf : ∀ i, HasDerivAt (f i) (df i) t) : + HasDerivAt (fun s => expSum κ (fun i => f i s)) + (∑ i, Real.exp (κ * f i t) * (κ * df i)) t := by + convert! HasDerivAt.fun_sum (fun i _ => ((hf i).const_mul κ).exp) using 1 + +theorem hasDerivAt_smoothMax {κ t : ℝ} (hκ : κ ≠ 0) {f : ι → ℝ → ℝ} {df : ι → ℝ} + (hf : ∀ i, HasDerivAt (f i) (df i) t) : + HasDerivAt (fun s => smoothMax κ (fun i => f i s)) + (∑ i, softWeight κ (fun j => f j t) i * df i) t := by + convert! ((hasDerivAt_expSum hf).log (expSum_pos κ (fun j => f j t)).ne').div_const κ using 1 + simp only [softWeight] + have hs : (∑ i, Real.exp (κ * f i t) * (κ * df i)) = + κ * ∑ i, Real.exp (κ * f i t) * df i := by + rw [Finset.mul_sum] + apply Finset.sum_congr rfl + intro i _ + ring + rw [hs] + simp_rw [div_mul_eq_mul_div, ← Finset.sum_div] + field_simp [hκ, (expSum_pos κ (fun j => f j t)).ne'] + +theorem hasDerivAt_softWeight {κ t : ℝ} {f : ι → ℝ → ℝ} {df : ι → ℝ} + (hf : ∀ i, HasDerivAt (f i) (df i) t) (i : ι) : + HasDerivAt (fun s => softWeight κ (fun j => f j s) i) + (κ * softWeight κ (fun j => f j t) i * + (df i - ∑ j, softWeight κ (fun k => f k t) j * df j)) t := by + convert! (((hf i).const_mul κ).exp).div (hasDerivAt_expSum hf) + (expSum_pos κ (fun j => f j t)).ne' using 1 + simp only [softWeight] + have hs : (∑ j, Real.exp (κ * f j t) * (κ * df j)) = + κ * ∑ j, Real.exp (κ * f j t) * df j := by + rw [Finset.mul_sum] + apply Finset.sum_congr rfl + intro j _ + ring + rw [hs] + simp_rw [div_mul_eq_mul_div, ← Finset.sum_div] + field_simp [(expSum_pos κ (fun j => f j t)).ne'] + +theorem weighted_abs_le (κ : ℝ) (x v : ι → ℝ) : + |∑ i, softWeight κ x i * v i| ≤ ∑ i, |v i| := by + calc + _ ≤ ∑ i, |softWeight κ x i * v i| := Finset.abs_sum_le_sum_abs _ _ + _ ≤ ∑ i, |v i| := by + apply Finset.sum_le_sum + intro i _ + rw [abs_mul, abs_of_pos (softWeight_pos κ x i)] + exact mul_le_of_le_one_left (abs_nonneg _) (softWeight_le_one κ x i) + +omit [Nonempty ι] in +theorem smoothMax_ge {κ : ℝ} (hκ : 0 < κ) (x : ι → ℝ) (i : ι) : + x i ≤ smoothMax κ x := by + rw [smoothMax, le_div_iff₀ hκ] + calc + x i * κ = log (Real.exp (κ * x i)) := by rw [log_exp]; ring + _ ≤ log (expSum κ x) := log_le_log (exp_pos _) <| + Finset.single_le_sum (fun j _ => (exp_pos (κ * x j)).le) (Finset.mem_univ i) + +theorem smoothMax_le {κ : ℝ} (hκ : 0 < κ) (x : ι → ℝ) {b : ℝ} + (hb : ∀ i, x i ≤ b) : smoothMax κ x ≤ b + log (Fintype.card ι) / κ := by + have hn : (0 : ℝ) < Fintype.card ι := Nat.cast_pos.mpr Fintype.card_pos + rw [smoothMax, div_le_iff₀ hκ] + calc + log (expSum κ x) ≤ log ((Fintype.card ι : ℝ) * Real.exp (κ * b)) := by + apply log_le_log (expSum_pos _ _) + calc + _ ≤ ∑ _ : ι, Real.exp (κ * b) := Finset.sum_le_sum (fun i _ => exp_le_exp.mpr (mul_le_mul_of_nonneg_left (hb i) hκ.le)) + _ = _ := by simp + _ = _ := by rw [log_mul hn.ne' (exp_pos _).ne', log_exp]; field_simp; ring + +variable {ι : Type*} [Fintype ι] [Nonempty ι] + +def affineProcess {n : ℕ} (m : ι → ℝ) (a : ι → Fin n → ℝ) (z : Fin n → ℝ) (i : ι) : ℝ := + m i + ∑ k, a i k * z k + +omit [Fintype ι] [Nonempty ι] in +theorem continuous_affineProcess {n : ℕ} (m : ι → ℝ) (a : ι → Fin n → ℝ) : + Continuous (affineProcess m a) := by + apply continuous_pi + intro i + exact continuous_const.add (continuous_finsetSum _ (fun k _ => continuous_const.mul (continuous_apply k))) + +omit [Fintype ι] [Nonempty ι] in +theorem affineProcess_coordinate_hasDerivAt {n : ℕ} (m : ι → ℝ) + (a : ι → Fin (n + 1) → ℝ) (i : ι) (k : Fin (n + 1)) (u : Fin n → ℝ) (z : ℝ) : + HasDerivAt (fun z => affineProcess m a (k.insertNth z u) i) (a i k) z := by + have he (z : ℝ) : affineProcess m a (k.insertNth z u) i = + a i k * z + (m i + ∑ l, a i (k.succAbove l) * u l) := by + rw [affineProcess, Fin.sum_univ_succAbove _ k] + simp only [Fin.insertNth_apply_same, Fin.insertNth_apply_succAbove] + ring + simp_rw [he] + convert! ((hasDerivAt_id z).const_mul (a i k)).add_const (m i + ∑ l, a i (k.succAbove l) * u l) using 1 + simp + +theorem affine_softWeight_coordinate_IBP {n : ℕ} (κ : ℝ) (m : ι → ℝ) + (a : ι → Fin (n + 1) → ℝ) (i : ι) (k : Fin (n + 1)) : + (∫ z, z k * softWeight κ (affineProcess m a z) i ∂standardGaussianProduct (n + 1)) = + ∫ z, κ * softWeight κ (affineProcess m a z) i * + (a i k - ∑ j, softWeight κ (affineProcess m a z) j * a j k) + ∂standardGaussianProduct (n + 1) := by + apply gaussianProduct_coordinate_IBP (C := 1) (D := |κ| * (|a i k| + ∑ j, |a j k|)) k + · exact (continuous_softWeight κ i).comp (continuous_affineProcess m a) + · exact (continuous_const.mul ((continuous_softWeight κ i).comp (continuous_affineProcess m a))).mul + (continuous_const.sub (continuous_finsetSum _ (fun j _ => + ((continuous_softWeight κ j).comp (continuous_affineProcess m a)).mul continuous_const))) + · intro z + rw [Real.norm_eq_abs, abs_of_pos (softWeight_pos _ _ _)] + exact softWeight_le_one _ _ _ + · intro z + rw [norm_mul, norm_mul, Real.norm_eq_abs κ, + Real.norm_eq_abs (softWeight _ _ _), abs_of_pos (softWeight_pos _ _ _), Real.norm_eq_abs] + apply mul_le_mul + · exact mul_le_of_le_one_right (abs_nonneg κ) (softWeight_le_one _ _ _) + · exact (abs_sub _ _).trans (add_le_add_right (weighted_abs_le κ _ (fun j => a j k)) _) + · positivity + · positivity + · intro u z + exact hasDerivAt_softWeight (fun j => affineProcess_coordinate_hasDerivAt m a j k u z) i + +omit [Nonempty ι] in +theorem weighted_covariance_identity (p u v : ι → ℝ) (hp : ∑ i, p i = 1) : + (∑ i, p i * u i * v i) - (∑ i, p i * u i) * (∑ i, p i * v i) = + (1 / 2 : ℝ) * ∑ i, ∑ j, p i * p j * (u i - u j) * (v i - v j) := by + have he (i j : ι) : p i * p j * (u i - u j) * (v i - v j) = + (p i * u i * v i) * p j + p i * (p j * u j * v j) - + (p i * u i) * (p j * v j) - (p i * v i) * (p j * u j) := by ring + simp_rw [he, Finset.sum_sub_distrib, Finset.sum_add_distrib, + ← Finset.mul_sum, ← Finset.sum_mul] + rw [hp] + ring + +theorem smoothMax_norm_le {κ : ℝ} (hκ : 0 < κ) (x : ι → ℝ) : + ‖smoothMax κ x‖ ≤ ∑ i, |x i| + log (Fintype.card ι) / κ := by + have hn : (1 : ℝ) ≤ Fintype.card ι := by exact_mod_cast Fintype.card_pos + have hlog : 0 ≤ log (Fintype.card ι) / κ := div_nonneg (log_nonneg hn) hκ.le + have hb (i : ι) : |x i| ≤ ∑ j, |x j| := + Finset.single_le_sum (fun j _ => abs_nonneg (x j)) (Finset.mem_univ i) + rw [Real.norm_eq_abs] + apply abs_le.mpr + constructor + · let i : ι := Classical.choice inferInstance + have hlo := smoothMax_ge hκ x i + have ha := (abs_le.mp (hb i)).1 + linarith + · exact smoothMax_le hκ x (fun i => (le_abs_self _).trans (hb i)) + +def interpolatedCoeff {n : ℕ} (a b : ι → Fin n → ℝ) (t : ℝ) (i : ι) (k : Fin n) : ℝ := + sin t * a i k + cos t * b i k + +def interpolatedCoeffDeriv {n : ℕ} (a b : ι → Fin n → ℝ) (t : ℝ) (i : ι) (k : Fin n) : ℝ := + cos t * a i k - sin t * b i k + +def processBound {n : ℕ} (a b : ι → Fin n → ℝ) (z : Fin n → ℝ) : ℝ := + ∑ i, ∑ k, (|a i k| + |b i k|) * |z k| + +omit [Fintype ι] [Nonempty ι] in +theorem interpolatedCoeff_abs_le {n : ℕ} (a b : ι → Fin n → ℝ) (t : ℝ) (i : ι) (k : Fin n) : + |interpolatedCoeff a b t i k| ≤ |a i k| + |b i k| := by + calc + _ ≤ |sin t * a i k| + |cos t * b i k| := abs_add_le _ _ + _ ≤ 1 * |a i k| + 1 * |b i k| := by + simp only [abs_mul] + gcongr + · exact abs_sin_le_one t + · exact abs_cos_le_one t + _ = _ := by ring + +omit [Fintype ι] [Nonempty ι] in +theorem interpolatedCoeffDeriv_abs_le {n : ℕ} (a b : ι → Fin n → ℝ) (t : ℝ) (i : ι) (k : Fin n) : + |interpolatedCoeffDeriv a b t i k| ≤ |a i k| + |b i k| := by + calc + _ ≤ |cos t * a i k| + |sin t * b i k| := abs_sub _ _ + _ ≤ 1 * |a i k| + 1 * |b i k| := by + simp only [abs_mul] + gcongr + · exact abs_cos_le_one t + · exact abs_sin_le_one t + _ = _ := by ring + +omit [Nonempty ι] in +theorem integrable_processBound {n : ℕ} (a b : ι → Fin n → ℝ) : + Integrable (processBound a b) (standardGaussianProduct n) := by + apply integrable_finsetSum + intro i _ + apply integrable_finsetSum + intro k _ + exact ((integrable_eval (i := k) IsGaussian.integrable_id).norm).const_mul _ + +omit [Fintype ι] [Nonempty ι] in +theorem interpolated_affine_hasDerivAt {n : ℕ} (m : ι → ℝ) (a b : ι → Fin n → ℝ) + (z : Fin n → ℝ) (t : ℝ) (i : ι) : + HasDerivAt (fun t => affineProcess m (interpolatedCoeff a b t) z i) + (∑ k, interpolatedCoeffDeriv a b t i k * z k) t := by + convert! (HasDerivAt.fun_sum (fun k _ => + (((Real.hasDerivAt_sin t).mul_const (a i k)).add + ((Real.hasDerivAt_cos t).mul_const (b i k))).mul_const (z k))).const_add (m i) using 1 + apply Finset.sum_congr rfl + intro k _ + dsimp [interpolatedCoeffDeriv] + ring + +def interpolationDerivative {n : ℕ} (κ : ℝ) (m : ι → ℝ) (a b : ι → Fin n → ℝ) + (t : ℝ) (z : Fin n → ℝ) : ℝ := + ∑ i, softWeight κ (affineProcess m (interpolatedCoeff a b t) z) i * + ∑ k, interpolatedCoeffDeriv a b t i k * z k + +theorem interpolationDerivative_norm_le {n : ℕ} (κ : ℝ) (m : ι → ℝ) + (a b : ι → Fin n → ℝ) (t : ℝ) (z : Fin n → ℝ) : + ‖interpolationDerivative κ m a b t z‖ ≤ processBound a b z := by + rw [Real.norm_eq_abs] + calc + _ ≤ ∑ i, |∑ k, interpolatedCoeffDeriv a b t i k * z k| := weighted_abs_le _ _ _ + _ ≤ ∑ i, ∑ k, (|a i k| + |b i k|) * |z k| := by + apply Finset.sum_le_sum + intro i _ + apply (Finset.abs_sum_le_sum_abs _ _).trans + apply Finset.sum_le_sum + intro k _ + rw [abs_mul] + exact mul_le_mul_of_nonneg_right (interpolatedCoeffDeriv_abs_le a b t i k) (abs_nonneg _) + +theorem interpolated_smoothMax_norm_le {n : ℕ} {κ : ℝ} (hκ : 0 < κ) (m : ι → ℝ) + (a b : ι → Fin n → ℝ) (t : ℝ) (z : Fin n → ℝ) : + ‖smoothMax κ (affineProcess m (interpolatedCoeff a b t) z)‖ ≤ + (∑ i, |m i|) + processBound a b z + log (Fintype.card ι) / κ := by + apply (smoothMax_norm_le hκ _).trans + gcongr + rw [processBound, ← Finset.sum_add_distrib] + apply Finset.sum_le_sum + intro i _ + apply (abs_add_le _ _).trans + gcongr + apply (Finset.abs_sum_le_sum_abs _ _).trans + apply Finset.sum_le_sum + intro k _ + rw [abs_mul] + exact mul_le_mul_of_nonneg_right (interpolatedCoeff_abs_le a b t i k) (abs_nonneg _) + +theorem interpolation_hasDerivAt {n : ℕ} {κ : ℝ} (hκ : 0 < κ) + (m : ι → ℝ) (a b : ι → Fin n → ℝ) (t : ℝ) : + HasDerivAt (fun t => ∫ z, smoothMax κ (affineProcess m (interpolatedCoeff a b t) z) + ∂standardGaussianProduct n) + (∫ z, interpolationDerivative κ m a b t z ∂standardGaussianProduct n) t := by + have hp (t : ℝ) (i : ι) : + Continuous (fun z => softWeight κ (affineProcess m (interpolatedCoeff a b t) z) i) := + (continuous_softWeight κ i).comp (continuous_affineProcess m _) + have hf (t : ℝ) : Continuous (fun z => smoothMax κ (affineProcess m (interpolatedCoeff a b t) z)) := + (continuous_smoothMax κ).comp (continuous_affineProcess m _) + have hdf (t : ℝ) : Continuous (interpolationDerivative κ m a b t) := by + apply continuous_finsetSum + intro i _ + exact (hp t i).mul (continuous_finsetSum _ (fun k _ => continuous_const.mul (continuous_apply k))) + have hb : Integrable (fun z => (∑ i, |m i|) + processBound a b z + log (Fintype.card ι) / κ) + (standardGaussianProduct n) := + ((integrable_const _).add (integrable_processBound a b)).add (integrable_const _) + exact (hasDerivAt_integral_of_dominated_loc_of_deriv_le + (μ := standardGaussianProduct n) (s := univ) (x₀ := t) + (F := fun t z => smoothMax κ (affineProcess m (interpolatedCoeff a b t) z)) + (F' := fun t z => interpolationDerivative κ m a b t z) + (bound := processBound a b) + Filter.univ_mem (Filter.Eventually.of_forall (fun t => (hf t).aestronglyMeasurable)) + (hb.mono' (hf t).aestronglyMeasurable (ae_of_all _ (interpolated_smoothMax_norm_le hκ m a b t))) + (hdf t).aestronglyMeasurable + (ae_of_all _ (fun z t _ => interpolationDerivative_norm_le κ m a b t z)) + (integrable_processBound a b) + (ae_of_all _ (fun z t _ => hasDerivAt_smoothMax hκ.ne' + (fun i => interpolated_affine_hasDerivAt m a b z t i)))).2 + +theorem integrable_affine_weight {n : ℕ} (κ : ℝ) (m : ι → ℝ) (a : ι → Fin n → ℝ) (i : ι) : + Integrable (fun z => softWeight κ (affineProcess m a z) i) (standardGaussianProduct n) := by + apply Integrable.of_bound ((continuous_softWeight κ i).comp (continuous_affineProcess m a)).aestronglyMeasurable 1 + exact ae_of_all _ (fun z => by + simp only [Function.comp_def] + rw [Real.norm_eq_abs, abs_of_pos (softWeight_pos _ _ _)] + exact softWeight_le_one _ _ _) + +theorem integrable_coordinate_weight {n : ℕ} (κ : ℝ) (m : ι → ℝ) + (a : ι → Fin n → ℝ) (i : ι) (k : Fin n) : + Integrable (fun z => z k * softWeight κ (affineProcess m a z) i) (standardGaussianProduct n) := by + apply Integrable.mul_bdd (integrable_eval (i := k) IsGaussian.integrable_id) + ((continuous_softWeight κ i).comp (continuous_affineProcess m a)).aestronglyMeasurable + exact ae_of_all _ (fun z => by + simp only [Function.comp_def] + rw [Real.norm_eq_abs, abs_of_pos (softWeight_pos _ _ _)] + exact softWeight_le_one _ _ _) + +theorem integrable_weight_covariance {n : ℕ} (κ : ℝ) (m : ι → ℝ) + (a : ι → Fin n → ℝ) (i : ι) (k : Fin n) : + Integrable (fun z => κ * softWeight κ (affineProcess m a z) i * + (a i k - ∑ j, softWeight κ (affineProcess m a z) j * a j k)) + (standardGaussianProduct n) := by + have hi : Integrable (fun z => a i k - ∑ j, softWeight κ (affineProcess m a z) j * a j k) + (standardGaussianProduct n) := by + apply (integrable_const _).sub + exact integrable_finsetSum _ (fun j _ => (integrable_affine_weight κ m a j).mul_const _) + have hm := hi.bdd_mul ((continuous_softWeight κ i).comp (continuous_affineProcess m a)).aestronglyMeasurable + (ae_of_all _ (fun z => by + simp only [Function.comp_def] + rw [Real.norm_eq_abs, abs_of_pos (softWeight_pos κ (affineProcess m a z) i)] + exact softWeight_le_one _ _ _)) + convert! hm.const_mul κ using 1 + ext z + simp only [Function.comp_def] + ring + +omit [Nonempty ι] in +theorem weighted_matrix_covariance_identity {n : ℕ} (p : ι → ℝ) (a d : ι → Fin n → ℝ) + (hp : ∑ i, p i = 1) : + (∑ i, ∑ k, d i k * p i * (a i k - ∑ j, p j * a j k)) = + (1 / 2 : ℝ) * ∑ i, ∑ j, p i * p j * ∑ k, (d i k - d j k) * (a i k - a j k) := by + have hk (k : Fin n) : + (∑ i, d i k * p i * (a i k - ∑ j, p j * a j k)) = + (1/2:ℝ) * ∑ i, ∑ j, p i * p j * (d i k - d j k) * (a i k - a j k) := by + rw [← weighted_covariance_identity p (fun i => d i k) (fun i => a i k) hp] + simp_rw [mul_sub, Finset.sum_sub_distrib, ← Finset.sum_mul] + congr 1 + · apply Finset.sum_congr rfl + intro i _ + ring + · congr 1 + apply Finset.sum_congr rfl + intro i _ + ring + rw [Finset.sum_comm] + simp_rw [hk, ← Finset.mul_sum] + congr 1 + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro i _ + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro j _ + rw [Finset.mul_sum] + apply Finset.sum_congr rfl + intro k _ + ring + +theorem gaussian_linear_weight_IBP {n : ℕ} (κ : ℝ) (m : ι → ℝ) + (a d : ι → Fin (n + 1) → ℝ) : + (∫ z, ∑ i, softWeight κ (affineProcess m a z) i * ∑ k, d i k * z k + ∂standardGaussianProduct (n + 1)) = + (κ / 2) * ∫ z, ∑ i, ∑ j, + softWeight κ (affineProcess m a z) i * softWeight κ (affineProcess m a z) j * + ∑ k, (d i k - d j k) * (a i k - a j k) + ∂standardGaussianProduct (n + 1) := by + let p := fun z i => softWeight κ (affineProcess m a z) i + have hi (i : ι) (k : Fin (n + 1)) : Integrable (fun z => d i k * (z k * p z i)) + (standardGaussianProduct (n + 1)) := (integrable_coordinate_weight κ m a i k).const_mul _ + have hr (i : ι) (k : Fin (n + 1)) : Integrable (fun z => d i k * + (κ * p z i * (a i k - ∑ j, p z j * a j k))) (standardGaussianProduct (n + 1)) := + (integrable_weight_covariance κ m a i k).const_mul _ + calc + _ = ∫ z, ∑ i, ∑ k, d i k * (z k * p z i) ∂standardGaussianProduct (n + 1) := by + apply integral_congr_ae + filter_upwards [] with z + apply Finset.sum_congr rfl + intro i _ + rw [Finset.mul_sum] + apply Finset.sum_congr rfl + intro k _ + dsimp [p] + ring + _ = ∑ i, ∑ k, d i k * ∫ z, z k * p z i ∂standardGaussianProduct (n + 1) := by + rw [integral_finsetSum _ (fun i _ => integrable_finsetSum _ (fun k _ => hi i k))] + apply Finset.sum_congr rfl + intro i _ + rw [integral_finsetSum _ (fun k _ => hi i k)] + simp only [integral_const_mul] + _ = ∑ i, ∑ k, d i k * ∫ z, κ * p z i * (a i k - ∑ j, p z j * a j k) + ∂standardGaussianProduct (n + 1) := by + apply Finset.sum_congr rfl + intro i _ + apply Finset.sum_congr rfl + intro k _ + rw [affine_softWeight_coordinate_IBP] + _ = ∫ z, ∑ i, ∑ k, d i k * (κ * p z i * (a i k - ∑ j, p z j * a j k)) + ∂standardGaussianProduct (n + 1) := by + rw [integral_finsetSum _ (fun i _ => integrable_finsetSum _ (fun k _ => hr i k))] + apply Finset.sum_congr rfl + intro i _ + rw [integral_finsetSum _ (fun k _ => hr i k)] + simp only [integral_const_mul] + _ = _ := by + rw [← integral_const_mul] + apply integral_congr_ae + filter_upwards [] with z + have he := weighted_matrix_covariance_identity (p z) a d (sum_softWeight κ _) + calc + _ = κ * ∑ i, ∑ k, d i k * p z i * (a i k - ∑ j, p z j * a j k) := by + simp only [Finset.mul_sum] + apply Finset.sum_congr rfl + intro i _ + apply Finset.sum_congr rfl + intro k _ + ring + _ = _ := by rw [he]; dsimp [p]; ring + +end SKRatioGaussian +end +end +end +end +end +end +end +end +end +end +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Matrices/FiniteCoordinateDeriv.lean b/lean/OAI/Probability/SKRatio/Matrices/FiniteCoordinateDeriv.lean new file mode 100644 index 0000000000000000000000000000000000000000..cea78ae029c07aaf23d78d0c52fdfa0b0242881f --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Matrices/FiniteCoordinateDeriv.lean @@ -0,0 +1,96 @@ +import Mathlib +import OAI.Probability.SKRatio.Matrices.CoordinateDeriv + +namespace OAI + +section +section +noncomputable section +open MeasureTheory ProbabilityTheory InformationTheory Real Set +open scoped NNReal ENNReal +open Filter +open scoped Topology +namespace SKRatioGaussian +variable {κ : Type*} [Fintype κ] [DecidableEq κ] + +def finiteCoordinateDeriv (i : κ) (f : (κ → ℝ) → ℝ) (x : κ → ℝ) : ℝ := + deriv (fun z => f (Function.update x i z)) (x i) + +lemma lipschitz_coordinate_update (i : κ) (x : κ → ℝ) : + LipschitzWith 1 (fun z : ℝ => Function.update x i z) := by + apply LipschitzWith.of_dist_le_mul + intro z w + simp only [NNReal.coe_one,one_mul] + apply (dist_pi_le_iff dist_nonneg).2 + intro k + by_cases h : k = i + · subst k; simp + · simp only [Function.update_of_ne h,dist_self]; exact dist_nonneg + +lemma measurable_finiteCoordinateDeriv (i : κ) {f : (κ → ℝ) → ℝ} + (hf : Continuous f) : Measurable (finiteCoordinateDeriv i f) := by + have h := measurable_deriv_with_param (f := fun x z => f (Function.update x i z)) + (hf.comp (continuous_update i)) + exact h.comp ((continuous_id.prodMk (continuous_apply i)).measurable) + +lemma norm_finiteCoordinateDeriv_le (i : κ) {f : (κ → ℝ) → ℝ} + {L : ℝ≥0} (hf : LipschitzWith L f) (x : κ → ℝ) : + ‖finiteCoordinateDeriv i f x‖ ≤ L := by + simpa only [finiteCoordinateDeriv,Function.comp_def,mul_one] using + norm_deriv_le_of_lipschitz (hf.comp (lipschitz_coordinate_update i x)) (x₀ := x i) + +lemma gaussianFinite_lipschitz_IBP_equiv {n : ℕ} (e : Fin (n+1) ≃ κ) (i : κ) + {f : (κ → ℝ) → ℝ} {L : ℝ≥0} {C : ℝ} + (hf : LipschitzWith L f) (hC : ∀ x, ‖f x‖ ≤ C) : + (∫ x, x i*f x ∂Measure.pi (fun _ : κ => gaussianReal 0 1)) = + ∫ x, finiteCoordinateDeriv i f x ∂Measure.pi (fun _ : κ => gaussianReal 0 1) := by + let E := MeasurableEquiv.piCongrLeft (fun _ : κ => ℝ) e + have he (x : Fin (n+1) → ℝ) (k : κ) : E x k = x (e.symm k) := by + simp [E,MeasurableEquiv.coe_piCongrLeft,Equiv.piCongrLeft_apply] + have hl : LipschitzWith 1 E := by + apply LipschitzWith.of_dist_le_mul + intro x y + simp only [NNReal.coe_one,one_mul] + apply (dist_pi_le_iff dist_nonneg).2 + intro k + simpa only [he] using dist_le_pi_dist x y (e.symm k) + have hp := measurePreserving_piCongrLeft (fun _ : κ => gaussianReal 0 1) e + have hh := gaussianProduct_lipschitz_IBP (e.symm i) + (by simpa only [mul_one,Function.comp_def] using hf.comp hl) (fun x => hC (E x)) + have hu (x : Fin (n+1) → ℝ) (z : ℝ) : + E ((e.symm i).insertNth z ((e.symm i).removeNth x)) = + Function.update (E x) i z := by + rw [Fin.insertNth_removeNth] + ext k + simp only [he] + by_cases h : k = i + · subst k; simp + · simp [he,Function.update_of_ne h,show e.symm k ≠ e.symm i from fun h' => h (e.symm.injective h')] + have hd (x : Fin (n+1) → ℝ) : + coordinateDeriv (e.symm i) (f ∘ E) x = finiteCoordinateDeriv i f (E x) := by + simp only [coordinateDeriv,finiteCoordinateDeriv,Function.comp_def,hu,he] + rw [← hp.integral_comp' (fun x => x i*f x), + ← hp.integral_comp' (finiteCoordinateDeriv i f)] + change (∫ x, E x i*f (E x) ∂standardGaussianProduct (n+1)) = + ∫ x, finiteCoordinateDeriv i f (E x) ∂standardGaussianProduct (n+1) + simpa only [← hd,he,Function.comp_def] using hh + +theorem gaussianFinite_lipschitz_IBP (i : κ) + {f : (κ → ℝ) → ℝ} {L : ℝ≥0} {C : ℝ} + (hf : LipschitzWith L f) (hC : ∀ x, ‖f x‖ ≤ C) : + (∫ x, x i*f x ∂Measure.pi (fun _ : κ => gaussianReal 0 1)) = + ∫ x, finiteCoordinateDeriv i f x ∂Measure.pi (fun _ : κ => gaussianReal 0 1) := by + have hn : Fintype.card κ ≠ 0 := by + let : Nonempty κ := ⟨i⟩ + exact Fintype.card_ne_zero + obtain ⟨n,hn⟩ := Nat.exists_eq_succ_of_ne_zero hn + let e : κ ≃ Fin (n+1) := (Fintype.equivFin κ).trans (Equiv.cast (congrArg Fin hn)) + exact gaussianFinite_lipschitz_IBP_equiv e.symm i hf hC + +end SKRatioGaussian + +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Matrices/FiniteMax.lean b/lean/OAI/Probability/SKRatio/Matrices/FiniteMax.lean new file mode 100644 index 0000000000000000000000000000000000000000..bd34df4b73699e7d201468bc8d4ca5824cd3d6e6 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Matrices/FiniteMax.lean @@ -0,0 +1,387 @@ +import Mathlib +import OAI.Probability.SKRatio.Matrices.ExpSum + +namespace OAI + +section +section +noncomputable section +open MeasureTheory ProbabilityTheory InformationTheory Real Set +open scoped NNReal ENNReal +open Filter +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius ENNReal NNReal +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius NNReal +noncomputable section +open MeasureTheory ProbabilityTheory Real Set Filter +open MeasureTheory.Measure +open scoped ENNReal NNReal MeasureTheory Topology +open MeasureTheory +noncomputable section +noncomputable section +open MeasureTheory Set NormedSpace +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius +noncomputable section +open Set Real +open scoped Topology +noncomputable section +open Matrix Set Filter +open scoped Topology Matrix.Norms.Frobenius +noncomputable section +open Matrix NormedSpace ContinuousLinearMap +open scoped Matrix.Norms.Frobenius +noncomputable section +open Matrix +noncomputable section +open MeasureTheory ProbabilityTheory Real Set +open scoped ENNReal NNReal +noncomputable section +open MeasureTheory ProbabilityTheory InformationTheory Real Set +open scoped NNReal ENNReal +namespace SKRatioGaussian +variable {ι : Type*} [Fintype ι] [Nonempty ι] +variable {ι : Type*} [Fintype ι] [Nonempty ι] +omit [Fintype ι] [Nonempty ι] in +theorem interpolation_increment_identity {n : ℕ} (a b : ι → Fin n → ℝ) (i j : ι) (t : ℝ) + (horth : ∑ k, (a i k - a j k) * (b i k - b j k) = 0) : + (∑ k, (interpolatedCoeffDeriv a b t i k - interpolatedCoeffDeriv a b t j k) * + (interpolatedCoeff a b t i k - interpolatedCoeff a b t j k)) = + sin t * cos t * ((∑ k, (a i k - a j k) ^ 2) - ∑ k, (b i k - b j k) ^ 2) := by + have he (k : Fin n) : + (interpolatedCoeffDeriv a b t i k - interpolatedCoeffDeriv a b t j k) * + (interpolatedCoeff a b t i k - interpolatedCoeff a b t j k) = + sin t * cos t * (a i k - a j k)^2 - sin t * cos t * (b i k - b j k)^2 + + (cos t ^ 2 - sin t ^ 2) * ((a i k - a j k) * (b i k - b j k)) := by + dsimp [interpolatedCoeff, interpolatedCoeffDeriv] + ring + simp_rw [he, Finset.sum_add_distrib, Finset.sum_sub_distrib, ← Finset.mul_sum] + rw [horth] + ring + +theorem interpolation_derivative_nonneg {n : ℕ} {κ : ℝ} (hκ : 0 ≤ κ) + (m : ι → ℝ) (a b : ι → Fin (n + 1) → ℝ) + (horth : ∀ i j, ∑ k, (a i k - a j k) * (b i k - b j k) = 0) + (hinc : ∀ i j, (∑ k, (b i k - b j k)^2) ≤ ∑ k, (a i k - a j k)^2) + {t : ℝ} (ht : t ∈ Icc 0 (π / 2)) : + 0 ≤ ∫ z, interpolationDerivative κ m a b t z ∂standardGaussianProduct (n + 1) := by + have hs : 0 ≤ sin t := sin_nonneg_of_nonneg_of_le_pi ht.1 (by linarith [pi_pos, ht.2]) + have hc : 0 ≤ cos t := cos_nonneg_of_mem_Icc ⟨by linarith [pi_pos, ht.1], ht.2⟩ + rw [show (fun z => interpolationDerivative κ m a b t z) = + (fun z => ∑ i, softWeight κ (affineProcess m (interpolatedCoeff a b t) z) i * + ∑ k, interpolatedCoeffDeriv a b t i k * z k) from rfl, + gaussian_linear_weight_IBP] + apply mul_nonneg (div_nonneg hκ (by norm_num)) + apply integral_nonneg + intro z + apply Finset.sum_nonneg + intro i _ + apply Finset.sum_nonneg + intro j _ + apply mul_nonneg (mul_nonneg (softWeight_pos _ _ _).le (softWeight_pos _ _ _).le) + rw [interpolation_increment_identity a b i j t (horth i j)] + exact mul_nonneg (mul_nonneg hs hc) (sub_nonneg.mpr (hinc i j)) + +theorem gaussian_smoothMax_comparison {n : ℕ} {κ : ℝ} (hκ : 0 < κ) + (m : ι → ℝ) (a b : ι → Fin (n + 1) → ℝ) + (horth : ∀ i j, ∑ k, (a i k - a j k) * (b i k - b j k) = 0) + (hinc : ∀ i j, (∑ k, (b i k - b j k)^2) ≤ ∑ k, (a i k - a j k)^2) : + (∫ z, smoothMax κ (affineProcess m b z) ∂standardGaussianProduct (n + 1)) ≤ + ∫ z, smoothMax κ (affineProcess m a z) ∂standardGaussianProduct (n + 1) := by + let f := fun t => ∫ z, smoothMax κ (affineProcess m (interpolatedCoeff a b t) z) + ∂standardGaussianProduct (n + 1) + have hmono : MonotoneOn f (Icc 0 (π / 2)) := by + apply monotoneOn_of_hasDerivWithinAt_nonneg (convex_Icc _ _) + (continuous_iff_continuousAt.mpr (fun t => (interpolation_hasDerivAt hκ m a b t).continuousAt)).continuousOn + (fun t _ => (interpolation_hasDerivAt hκ m a b t).hasDerivWithinAt) + intro t ht + exact interpolation_derivative_nonneg hκ.le m a b horth hinc (interior_subset ht) + have hle := hmono (show (0:ℝ) ∈ Icc 0 (π/2) from ⟨le_refl _, by positivity⟩) + (show π/2 ∈ Icc (0:ℝ) (π/2) from ⟨by positivity, le_refl _⟩) (by positivity) + have h0 : interpolatedCoeff a b 0 = b := by + funext i k + simp [interpolatedCoeff] + have h1 : interpolatedCoeff a b (π/2) = a := by + funext i k + simp [interpolatedCoeff] + simpa only [f, h0, h1] using hle + +def finiteMax (x : ι → ℝ) : ℝ := Finset.univ.sup' Finset.univ_nonempty x + +theorem le_finiteMax (x : ι → ℝ) (i : ι) : x i ≤ finiteMax x := + Finset.le_sup' x (Finset.mem_univ i) + +theorem finiteMax_le {x : ι → ℝ} {b : ℝ} (hb : ∀ i, x i ≤ b) : finiteMax x ≤ b := + Finset.sup'_le _ _ (fun i _ => hb i) + +theorem continuous_finiteMax : Continuous (finiteMax : (ι → ℝ) → ℝ) := + Continuous.finset_sup'_apply Finset.univ_nonempty (fun i _ => continuous_apply i) + +theorem finiteMax_norm_le (x : ι → ℝ) : ‖finiteMax x‖ ≤ ∑ i, |x i| := by + obtain ⟨i, _, hi⟩ := Finset.exists_mem_eq_sup' Finset.univ_nonempty x + change ‖Finset.univ.sup' Finset.univ_nonempty x‖ ≤ _ + rw [hi, Real.norm_eq_abs] + exact Finset.single_le_sum (fun j _ => abs_nonneg (x j)) (Finset.mem_univ i) + +omit [Fintype ι] [Nonempty ι] in +theorem integrable_affineProcess {n : ℕ} (m : ι → ℝ) (a : ι → Fin n → ℝ) (i : ι) : + Integrable (fun z => affineProcess m a z i) (standardGaussianProduct n) := by + apply (integrable_const _).add + exact integrable_finsetSum _ (fun k _ => (integrable_eval (i := k) IsGaussian.integrable_id).const_mul _) + +theorem integrable_finiteMax_affine {n : ℕ} (m : ι → ℝ) (a : ι → Fin n → ℝ) : + Integrable (fun z => finiteMax (affineProcess m a z)) (standardGaussianProduct n) := by + apply (integrable_finsetSum _ (fun i _ => (integrable_affineProcess m a i).norm)).mono' + (continuous_finiteMax.comp (continuous_affineProcess m a)).aestronglyMeasurable + exact ae_of_all _ (fun z => finiteMax_norm_le _) + +theorem integrable_smoothMax_affine {n : ℕ} {κ : ℝ} (hκ : 0 < κ) (m : ι → ℝ) (a : ι → Fin n → ℝ) : + Integrable (fun z => smoothMax κ (affineProcess m a z)) (standardGaussianProduct n) := by + apply ((integrable_finsetSum _ (fun i _ => (integrable_affineProcess m a i).norm)).add + (integrable_const (log (Fintype.card ι) / κ))).mono' + ((continuous_smoothMax κ).comp (continuous_affineProcess m a)).aestronglyMeasurable + exact ae_of_all _ (fun z => smoothMax_norm_le hκ _) + +theorem gaussian_finiteMax_comparison {n : ℕ} + (m : ι → ℝ) (a b : ι → Fin (n + 1) → ℝ) + (horth : ∀ i j, ∑ k, (a i k - a j k) * (b i k - b j k) = 0) + (hinc : ∀ i j, (∑ k, (b i k - b j k)^2) ≤ ∑ k, (a i k - a j k)^2) : + (∫ z, finiteMax (affineProcess m b z) ∂standardGaussianProduct (n + 1)) ≤ + ∫ z, finiteMax (affineProcess m a z) ∂standardGaussianProduct (n + 1) := by + apply le_of_forall_pos_le_add + intro ε hε + have hlog : 0 ≤ log (Fintype.card ι) := log_nonneg (by exact_mod_cast Fintype.card_pos) + let κ := (log (Fintype.card ι) + 1) / ε + have hκ : 0 < κ := div_pos (by linarith) hε + have herr : log (Fintype.card ι) / κ ≤ ε := by + apply (div_le_iff₀ hκ).mpr + dsimp [κ] + rw [mul_div_cancel₀ _ hε.ne'] + linarith + calc + _ ≤ ∫ z, smoothMax κ (affineProcess m b z) ∂standardGaussianProduct (n + 1) := by + apply integral_mono (integrable_finiteMax_affine m b) (integrable_smoothMax_affine hκ m b) + intro z + exact finiteMax_le (fun i => smoothMax_ge hκ _ i) + _ ≤ ∫ z, smoothMax κ (affineProcess m a z) ∂standardGaussianProduct (n + 1) := + gaussian_smoothMax_comparison hκ m a b horth hinc + _ ≤ (∫ z, finiteMax (affineProcess m a z) ∂standardGaussianProduct (n + 1)) + ε := by + calc + _ ≤ ∫ z, finiteMax (affineProcess m a z) + log (Fintype.card ι) / κ + ∂standardGaussianProduct (n + 1) := by + apply integral_mono (integrable_smoothMax_affine hκ m a) + ((integrable_finiteMax_affine m a).add (integrable_const _)) + intro z + exact smoothMax_le hκ _ (fun i => le_finiteMax _ i) + _ = (∫ z, finiteMax (affineProcess m a z) ∂standardGaussianProduct (n + 1)) + + log (Fintype.card ι) / κ := by + rw [integral_add (integrable_finiteMax_affine m a) (integrable_const _)] + simp + _ ≤ _ := add_le_add (le_refl _) herr + +section CompactIndex +variable {I : Type*} [TopologicalSpace I] [CompactSpace I] [Nonempty I] + +def supProcess {n : ℕ} (m : I → ℝ) (a : I → Fin n → ℝ) (z : Fin n → ℝ) : ℝ := + sSup (Set.range (affineProcess m a z)) + +omit [CompactSpace I] [Nonempty I] in +theorem continuous_affine_index {n : ℕ} {m : I → ℝ} {a : I → Fin n → ℝ} + (hm : Continuous m) (ha : Continuous a) (z : Fin n → ℝ) : + Continuous (affineProcess m a z) := by + exact hm.add (continuous_finsetSum _ (fun k _ => ((continuous_apply k).comp ha).mul continuous_const)) + +theorem supProcess_attained {n : ℕ} {m : I → ℝ} {a : I → Fin n → ℝ} + (hm : Continuous m) (ha : Continuous a) (z : Fin n → ℝ) : + ∃ i, supProcess m a z = affineProcess m a z i ∧ + ∀ j, affineProcess m a z j ≤ affineProcess m a z i := by + obtain ⟨i, _, he, hi⟩ := isCompact_univ.exists_sSup_image_eq_and_ge + Set.univ_nonempty (continuous_affine_index hm ha z).continuousOn + exact ⟨i, by simpa [supProcess] using he, fun j => hi j (Set.mem_univ _)⟩ + +theorem affine_le_supProcess {n : ℕ} {m : I → ℝ} {a : I → Fin n → ℝ} + (hm : Continuous m) (ha : Continuous a) (z : Fin n → ℝ) (i : I) : + affineProcess m a z i ≤ supProcess m a z := by + obtain ⟨j, he, hj⟩ := supProcess_attained hm ha z + rw [he] + exact hj i + +theorem supProcess_le {n : ℕ} {m : I → ℝ} {a : I → Fin n → ℝ} + (hm : Continuous m) (ha : Continuous a) (z : Fin n → ℝ) {c : ℝ} + (hc : ∀ i, affineProcess m a z i ≤ c) : supProcess m a z ≤ c := by + obtain ⟨i, he, _⟩ := supProcess_attained hm ha z + rw [he] + exact hc i + +omit [Nonempty I] in +theorem continuous_supProcess {n : ℕ} {m : I → ℝ} {a : I → Fin n → ℝ} + (hm : Continuous m) (ha : Continuous a) : Continuous (supProcess m a) := by + have hc : Continuous (fun p : (Fin n → ℝ) × I => affineProcess m a p.1 p.2) := by + exact (hm.comp continuous_snd).add (continuous_finsetSum _ (fun k _ => + (((continuous_apply k).comp ha).comp continuous_snd).mul + ((continuous_apply k).comp continuous_fst))) + change Continuous (fun z => sSup (Set.range (affineProcess m a z))) + simpa only [Set.image_univ] using isCompact_univ.continuous_sSup hc + +omit [TopologicalSpace I] [CompactSpace I] [Nonempty I] in + theorem affineProcess_abs_le {n : ℕ} {m : I → ℝ} {a : I → Fin n → ℝ} + {M A : ℝ} (hm : ∀ i, |m i| ≤ M) (ha : ∀ i k, |a i k| ≤ A) + (z : Fin n → ℝ) (i : I) : + |affineProcess m a z i| ≤ M + A * ∑ k, |z k| := by + calc + _ ≤ |m i| + |∑ k, a i k * z k| := abs_add_le _ _ + _ ≤ M + ∑ k, |a i k * z k| := add_le_add (hm i) (Finset.abs_sum_le_sum_abs _ _) + _ ≤ M + ∑ k, A * |z k| := by + gcongr with k + rw [abs_mul] + exact mul_le_mul_of_nonneg_right (ha i k) (abs_nonneg _) + _ = _ := by rw [Finset.mul_sum] + +theorem integrable_supProcess {n : ℕ} {m : I → ℝ} {a : I → Fin n → ℝ} + (hm : Continuous m) (ha : Continuous a) : + Integrable (supProcess m a) (standardGaussianProduct n) := by + obtain ⟨M, hM⟩ := isCompact_univ.exists_bound_of_continuousOn hm.continuousOn + obtain ⟨A, hA⟩ := isCompact_univ.exists_bound_of_continuousOn ha.continuousOn + have hMb : ∀ i, |m i| ≤ M := fun i => by simpa only [Real.norm_eq_abs] using hM i (Set.mem_univ _) + have hAb : ∀ i k, |a i k| ≤ A := by + intro i k + have hk : |a i k| ≤ ‖a i‖ := by simpa only [Real.norm_eq_abs] using norm_le_pi_norm (a i) k + exact hk.trans (hA i (Set.mem_univ _)) + apply ((integrable_const M).add ((integrable_finsetSum _ (fun k _ => + ((integrable_eval (i := k) IsGaussian.integrable_id).norm))).const_mul A)).mono' + (continuous_supProcess hm ha).aestronglyMeasurable + apply Filter.Eventually.of_forall + intro z + obtain ⟨i, he, _⟩ := supProcess_attained hm ha z + rw [he, Real.norm_eq_abs] + exact affineProcess_abs_le hMb hAb z i + +theorem exists_finite_affine_net {n : ℕ} {m : I → ℝ} {a : I → Fin n → ℝ} + (hm : Continuous m) (ha : Continuous a) {ε : ℝ} (hε : 0 < ε) : + ∃ t : Finset I, t.Nonempty ∧ ∀ j, ∃ i ∈ t, + |m j - m i| ≤ ε ∧ ∀ k, |a j k - a i k| ≤ ε := by + let U : I → Set I := fun i => m ⁻¹' Metric.ball (m i) ε ∩ a ⁻¹' Metric.ball (a i) ε + have ho (i : I) : IsOpen (U i) := + (Metric.isOpen_ball.preimage hm).inter (Metric.isOpen_ball.preimage ha) + have hu : Set.univ ⊆ ⋃ i, U i := by + intro j _ + apply Set.mem_iUnion.mpr + exact ⟨j, by simp [U, hε]⟩ + obtain ⟨t, ht⟩ := isCompact_univ.elim_finite_subcover U ho hu + have hcover (j : I) : ∃ i ∈ t, j ∈ U i := by + obtain ⟨i, hi⟩ := Set.mem_iUnion.mp (ht (Set.mem_univ j)) + obtain ⟨hit, hji⟩ := Set.mem_iUnion.mp hi + exact ⟨i, hit, hji⟩ + have hne : t.Nonempty := by + obtain ⟨i, hi, _⟩ := hcover (Classical.choice inferInstance) + exact ⟨i, hi⟩ + refine ⟨t, hne, fun j => ?_⟩ + obtain ⟨i, hi, hj⟩ := hcover j + refine ⟨i, hi, ?_, fun k => ?_⟩ + · have hd : dist (m j) (m i) < ε := hj.1 + simpa only [Real.dist_eq] using hd.le + · have hb : dist (a j) (a i) < ε := hj.2 + have hk := (dist_le_pi_dist (a j) (a i) k).trans_lt hb + simpa only [Real.dist_eq] using hk.le + +omit [TopologicalSpace I] [CompactSpace I] [Nonempty I] in + theorem affineProcess_difference_abs_le {n : ℕ} (m : I → ℝ) (a : I → Fin n → ℝ) + {ε : ℝ} {i j : I} (hm : |m i - m j| ≤ ε) + (ha : ∀ k, |a i k - a j k| ≤ ε) (z : Fin n → ℝ) : + |affineProcess m a z i - affineProcess m a z j| ≤ ε * (1 + ∑ k, |z k|) := by + have he : affineProcess m a z i - affineProcess m a z j = + (m i - m j) + ∑ k, (a i k - a j k) * z k := by + simp only [affineProcess, sub_mul, Finset.sum_sub_distrib] + ring + rw [he] + calc + _ ≤ |m i - m j| + |∑ k, (a i k - a j k) * z k| := abs_add_le _ _ + _ ≤ ε + ∑ k, |(a i k - a j k) * z k| := + add_le_add hm (Finset.abs_sum_le_sum_abs _ _) + _ ≤ ε + ∑ k, ε * |z k| := by + gcongr with k + rw [abs_mul] + exact mul_le_mul_of_nonneg_right (ha k) (abs_nonneg _) + _ = _ := by rw [← Finset.mul_sum]; ring + +theorem gaussian_supProcess_comparison {n : ℕ} + {m : I → ℝ} {a b : I → Fin (n + 1) → ℝ} + (hm : Continuous m) (ha : Continuous a) (hb : Continuous b) + (horth : ∀ i j, ∑ k, (a i k - a j k) * (b i k - b j k) = 0) + (hinc : ∀ i j, (∑ k, (b i k - b j k)^2) ≤ ∑ k, (a i k - a j k)^2) : + (∫ z, supProcess m b z ∂standardGaussianProduct (n + 1)) ≤ + ∫ z, supProcess m a z ∂standardGaussianProduct (n + 1) := by + let μ := standardGaussianProduct (n + 1) + let Z : (Fin (n + 1) → ℝ) → ℝ := fun z => 1 + ∑ k, |z k| + have hZI : Integrable Z μ := (integrable_const 1).add + (integrable_finsetSum _ (fun k _ => by + have hi : Integrable (fun z : Fin (n + 1) → ℝ => z k) μ := + integrable_eval (i := k) IsGaussian.integrable_id + simpa only [Real.norm_eq_abs] using hi.norm)) + have hZ : 0 ≤ ∫ z, Z z ∂μ := integral_nonneg (fun z => by dsimp [Z]; positivity) + apply le_of_forall_pos_le_add + intro ε hε + let δ : ℝ := ε / ((∫ z, Z z ∂μ) + 1) + have hδ : 0 < δ := div_pos hε (by linarith) + have hδε : δ * (∫ z, Z z ∂μ) ≤ ε := by + dsimp [δ] + rw [div_mul_eq_mul_div] + apply (div_le_iff₀ (by linarith : 0 < (∫ z, Z z ∂μ) + 1)).mpr + nlinarith + obtain ⟨t, ht, hnet⟩ := exists_finite_affine_net hm hb hδ + have : Nonempty t := ht.to_subtype + let mf : t → ℝ := fun i => m i + let af : t → Fin (n + 1) → ℝ := fun i => a i + let bf : t → Fin (n + 1) → ℝ := fun i => b i + have hfinite := gaussian_finiteMax_comparison mf af bf + (fun i j => horth i j) (fun i j => hinc i j) + calc + _ ≤ ∫ z, finiteMax (affineProcess mf bf z) + δ * Z z ∂μ := by + apply integral_mono (integrable_supProcess hm hb) + ((integrable_finiteMax_affine mf bf).add (hZI.const_mul δ)) + intro z + apply supProcess_le hm hb + intro j + obtain ⟨i, hi, hmj, hbj⟩ := hnet j + have hd := (le_abs_self _).trans (affineProcess_difference_abs_le m b hmj hbj z) + have hmax := le_finiteMax (affineProcess mf bf z) (⟨i, hi⟩ : t) + change affineProcess m b z i ≤ _ at hmax + change affineProcess m b z j ≤ finiteMax (affineProcess mf bf z) + δ * (1 + ∑ k, |z k|) + linarith + _ = (∫ z, finiteMax (affineProcess mf bf z) ∂μ) + δ * ∫ z, Z z ∂μ := by + rw [integral_add (integrable_finiteMax_affine mf bf) (hZI.const_mul δ), integral_const_mul] + _ ≤ (∫ z, finiteMax (affineProcess mf af z) ∂μ) + ε := add_le_add hfinite hδε + _ ≤ (∫ z, supProcess m a z ∂μ) + ε := by + refine add_le_add ?_ le_rfl + apply integral_mono (integrable_finiteMax_affine mf af) (integrable_supProcess hm ha) + intro z + apply finiteMax_le + intro i + exact affine_le_supProcess hm ha z i + +end CompactIndex +end SKRatioGaussian + +end +end +end +end +end +end +end +end +end +end +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Matrices/FiniteTimeMesh.lean b/lean/OAI/Probability/SKRatio/Matrices/FiniteTimeMesh.lean new file mode 100644 index 0000000000000000000000000000000000000000..9a4a8ddf6d64093e079183b357e0b40ba0fa2490 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Matrices/FiniteTimeMesh.lean @@ -0,0 +1,72 @@ +import Mathlib + +namespace OAI + +section +section +noncomputable section +namespace SKRatioGaussian.PathBridge +open Real Set +open scoped BigOperators NNReal + +theorem finite_time_mesh {T δ₀ : ℝ} (hT : 0 positivity + +def diagonalChange (D D' : Matrix ι ι ℂ) : ℝ := + (opNorm D+opNorm D')*opNorm (D-D') +def shiftChange (R : ℝ) (B B' D D' : Matrix ι ι ℂ) : ℝ := + opNorm (B-B')+diagonalChange D D'*R +def gBound (f : 𝓢(ℝ,ℂ)) (D : Matrix ι ι ℂ) : ℝ := + opNorm D^2*fourierMoment f 0 +def gLip (f : 𝓢(ℝ,ℂ)) (D : Matrix ι ι ℂ) : ℝ := + fl1 f*opNorm D^4 +def gChange (f : 𝓢(ℝ,ℂ)) (R : ℝ) (B B' D D' : Matrix ι ι ℂ) : ℝ := + diagonalChange D D'*fourierMoment f 0+opNorm D'^2*fl1 f*shiftChange R B B' D D' +def gMixed (f : 𝓢(ℝ,ℂ)) (R : ℝ) (B B' D D' : Matrix ι ι ℂ) : ℝ := + diagonalChange D D'*fl1 f*opNorm D^2+ + opNorm D'^2*(fl1 f*diagonalChange D D'+fl2 f*(2*shiftChange R B B' D D')*opNorm D'^2) + +lemma diagonalChange_nonneg (D D' : Matrix ι ι ℂ) : 0 ≤ diagonalChange D D' := by + unfold diagonalChange + positivity [opNorm_nonneg D,opNorm_nonneg D',opNorm_nonneg (D-D')] +lemma shiftChange_nonneg {R : ℝ} (hR : 0 ≤ R) (B B' D D' : Matrix ι ι ℂ) : + 0 ≤ shiftChange R B B' D D' := by + unfold shiftChange + positivity [opNorm_nonneg (B-B'),diagonalChange_nonneg D D'] +lemma g_constants_nonneg (f : 𝓢(ℝ,ℂ)) {R : ℝ} (hR : 0 ≤ R) + (B B' D D' : Matrix ι ι ℂ) : + 0 ≤ gBound f D ∧ 0 ≤ gLip f D ∧ 0 ≤ gChange f R B B' D D' ∧ 0 ≤ gMixed f R B B' D D' := by + have h₀ := fourierMoment_nonneg f 0 + have h₁ := (fl_nonneg f).1 + have h₂ := (fl_nonneg f).2 + have hd := diagonalChange_nonneg D D' + have hs := shiftChange_nonneg hR B B' D D' + unfold gBound gLip gChange gMixed + exact ⟨by positivity,by positivity,by positivity,by positivity⟩ + +lemma truncatedG_parameter (f : 𝓢(ℝ,ℂ)) {R : ℝ} (hR : 0 ≤ R) + (B B' D D' M : Matrix ι ι ℂ) + (hB : Bᴴ = B) (hB' : B'ᴴ = B') (hD : Dᴴ = D) (hD' : D'ᴴ = D') : + opNorm (truncatedG f R hR B D M-truncatedG f R hR B' D' M) ≤ + gChange f R B B' D D' := by + let P := matrixProject R hR M + let F := schwartzMatrix f (sandShift B D P) + let F' := schwartzMatrix f (sandShift B' D' P) + have hP := matrixProject_bound R hR M + have hF : opNorm F ≤ fourierMoment f 0 := by + simpa only [F,fourierMoment,pow_zero,mul_one] using + schwartzMatrix_opNorm f _ (sandShift_hermitian _ _ _ hB hD hP.1) + have hs : opNorm (sandShift B D P-sandShift B' D' P) ≤ shiftChange R B B' D D' := by + apply (sandShift_parameter B B' D D' P).trans + unfold shiftChange diagonalChange + exact add_le_add_right (mul_le_mul_of_nonneg_left hP.2 (diagonalChange_nonneg D D')) _ + have hL : opNorm (F-F') ≤ fl1 f*shiftChange R B B' D D' := + (schwartzMatrix_opNorm_lipschitz f _ _ (sandShift_hermitian _ _ _ hB hD hP.1) + (sandShift_hermitian _ _ _ hB' hD' hP.1)).trans + (mul_le_mul_of_nonneg_left hs (fl_nonneg f).1) + have he : truncatedG f R hR B D M-truncatedG f R hR B' D' M = + (D*F*D-D'*F*D')+D'*(F-F')*D' := by dsimp [truncatedG,F,F',P]; noncomm_ring + rw [he] + calc + _ ≤ opNorm (D*F*D-D'*F*D')+opNorm (D'*(F-F')*D') := opNorm_add _ _ + _ ≤ diagonalChange D D'*opNorm F+opNorm D'^2*opNorm (F-F') := + add_le_add (sandwich_difference_opNorm _ _ _) (sandwich_opNorm _ _) + _ ≤ diagonalChange D D'*fourierMoment f 0+opNorm D'^2*(fl1 f*shiftChange R B B' D D') := + add_le_add (mul_le_mul_of_nonneg_left hF (diagonalChange_nonneg _ _)) + (mul_le_mul_of_nonneg_left hL (sq_nonneg _)) + _ = _ := by unfold gChange; ring + +lemma truncatedG_four_point (f : 𝓢(ℝ,ℂ)) {R : ℝ} (hR : 0 ≤ R) + (B B' D D' M N : Matrix ι ι ℂ) + (hB : Bᴴ = B) (hB' : B'ᴴ = B') (hD : Dᴴ = D) (hD' : D'ᴴ = D') : + ‖(truncatedG f R hR B D M-truncatedG f R hR B D N)- + (truncatedG f R hR B' D' M-truncatedG f R hR B' D' N)‖ ≤ + gMixed f R B B' D D'*‖M-N‖ := by + let P := matrixProject R hR M + let Q := matrixProject R hR N + let F := schwartzMatrix f (sandShift B D P)-schwartzMatrix f (sandShift B D Q) + let F' := schwartzMatrix f (sandShift B' D' P)-schwartzMatrix f (sandShift B' D' Q) + have hP := matrixProject_bound R hR M + have hQ := matrixProject_bound R hR N + have hPQ : ‖P-Q‖ ≤ ‖M-N‖ := matrixProject_sub_norm _ _ _ _ + have hF : ‖F‖ ≤ fl1 f*opNorm D^2*‖M-N‖ := + (schwartzMatrix_sandShift_lipschitz f B D P Q hB hD hP.1 hQ.1).trans + (mul_le_mul_of_nonneg_left hPQ (mul_nonneg (fl_nonneg f).1 (sq_nonneg _))) + have hFF : ‖F-F'‖ ≤ + (fl1 f*diagonalChange D D'+fl2 f*(2*shiftChange R B B' D D')*opNorm D'^2)*‖M-N‖ := by + apply (schwartzMatrix_sandShift_four_point f B B' D D' P Q hB hB' hD hD' hP.1 hQ.1).trans + simp only [mul_assoc (2*Real.pi*fourierMoment f 1) (opNorm D+opNorm D')] + change (fl1 f*diagonalChange D D'+fl2 f* + (2*opNorm (B-B')+diagonalChange D D'*(opNorm P+opNorm Q))*opNorm D'^2)*‖P-Q‖ ≤ _ + have hd := diagonalChange_nonneg D D' + have hs := shiftChange_nonneg hR B B' D D' + have hc : 2*opNorm (B-B')+diagonalChange D D'*(opNorm P+opNorm Q) ≤ + 2*shiftChange R B B' D D' := by + calc + _ ≤ 2*opNorm (B-B')+diagonalChange D D'*(R+R) := + add_le_add_right (mul_le_mul_of_nonneg_left (add_le_add hP.2 hQ.2) hd) _ + _ = _ := by unfold shiftChange; ring + have hc' := mul_le_mul_of_nonneg_right + (mul_le_mul_of_nonneg_left hc (fl_nonneg f).2) (sq_nonneg (opNorm D')) + have hcoef := add_le_add_right hc' (fl1 f*diagonalChange D D') + have hn : 0 ≤ fl1 f*diagonalChange D D'+fl2 f*(2*shiftChange R B B' D D')*opNorm D'^2 := + add_nonneg (mul_nonneg (fl_nonneg f).1 hd) + (mul_nonneg (mul_nonneg (fl_nonneg f).2 (mul_nonneg (by norm_num) hs)) (sq_nonneg _)) + exact mul_le_mul hcoef hPQ (norm_nonneg _) hn + have he : (truncatedG f R hR B D M-truncatedG f R hR B D N)- + (truncatedG f R hR B' D' M-truncatedG f R hR B' D' N) = + (D*F*D-D'*F*D')+D'*(F-F')*D' := by dsimp [truncatedG,F,F',P,Q]; noncomm_ring + rw [he] + calc + _ ≤ ‖D*F*D-D'*F*D'‖+‖D'*(F-F')*D'‖ := norm_add_le _ _ + _ ≤ diagonalChange D D'*‖F‖+opNorm D'^2*‖F-F'‖ := + add_le_add (sandwich_difference_frobenius _ _ _) (sandwich_frobenius _ _) + _ ≤ diagonalChange D D'*(fl1 f*opNorm D^2*‖M-N‖)+opNorm D'^2* + ((fl1 f*diagonalChange D D'+fl2 f*(2*shiftChange R B B' D D')*opNorm D'^2)*‖M-N‖) := + add_le_add (mul_le_mul_of_nonneg_left hF (diagonalChange_nonneg _ _)) + (mul_le_mul_of_nonneg_left hFF (sq_nonneg _)) + _ = _ := by unfold gMixed; ring + +noncomputable def truncatedK (f : 𝓢(ℝ,ℂ)) (R : ℝ) (hR : 0 ≤ R) + (B D C M : Matrix ι ι ℂ) : Matrix ι ι ℂ := + 1+truncatedG f R hR B D M*(matrixProject R hR M-C) + +def kBound (f : 𝓢(ℝ,ℂ)) (R : ℝ) (D C : Matrix ι ι ℂ) : ℝ := + 1+gBound f D*(R+opNorm C) +def kLip (f : 𝓢(ℝ,ℂ)) (R : ℝ) (D C : Matrix ι ι ℂ) : ℝ := + gLip f D*(R+opNorm C)+gBound f D +def kMixed (f : 𝓢(ℝ,ℂ)) (R : ℝ) (B B' D D' C C' : Matrix ι ι ℂ) : ℝ := + gMixed f R B B' D D'*(R+opNorm C)+gLip f D'*opNorm (C-C')+gChange f R B B' D D' + +lemma projected_sub_bound {R : ℝ} (hR : 0 ≤ R) (M C : Matrix ι ι ℂ) : + opNorm (matrixProject R hR M-C) ≤ R+opNorm C := + (opNorm_sub _ _).trans (add_le_add_left (matrixProject_bound R hR M).2 _) + +lemma truncatedK_opNorm (f : 𝓢(ℝ,ℂ)) {R : ℝ} (hR : 0 ≤ R) + (B D C M : Matrix ι ι ℂ) (hB : Bᴴ = B) (hD : Dᴴ = D) : + opNorm (truncatedK f R hR B D C M) ≤ kBound f R D C := by + apply (opNorm_add _ _).trans + apply add_le_add opNorm_one_le + exact (opNorm_mul _ _).trans + (mul_le_mul (truncatedG_opNorm _ _ _ _ _ _ hB hD) (projected_sub_bound hR M C) + (opNorm_nonneg _) (g_constants_nonneg f hR B B D D).1) + +lemma truncatedK_sub_norm (f : 𝓢(ℝ,ℂ)) {R : ℝ} (hR : 0 ≤ R) + (B D C M N : Matrix ι ι ℂ) (hB : Bᴴ = B) (hD : Dᴴ = D) : + ‖truncatedK f R hR B D C M-truncatedK f R hR B D C N‖ ≤ + kLip f R D C*‖M-N‖ := by + let G := truncatedG f R hR B D + let P : Matrix ι ι ℂ → Matrix ι ι ℂ := matrixProject R hR + have he : truncatedK f R hR B D C M-truncatedK f R hR B D C N = + (G M-G N)*(P M-C)+G N*(P M-P N) := by dsimp [truncatedK,G,P]; noncomm_ring + rw [he] + calc + _ ≤ ‖(G M-G N)*(P M-C)‖+‖G N*(P M-P N)‖ := norm_add_le _ _ + _ ≤ ‖G M-G N‖*opNorm (P M-C)+opNorm (G N)*‖P M-P N‖ := + add_le_add (frobenius_mul_le_opNorm_right _ _) (frobenius_mul_le_opNorm _ _) + _ ≤ (gLip f D*‖M-N‖)*(R+opNorm C)+gBound f D*‖M-N‖ := by + apply add_le_add + · exact mul_le_mul (truncatedG_sub_norm _ _ _ _ _ _ _ hB hD) (projected_sub_bound hR M C) + (opNorm_nonneg _) (mul_nonneg (g_constants_nonneg f hR B B D D).2.1 (norm_nonneg _)) + · exact mul_le_mul (truncatedG_opNorm _ _ _ _ _ _ hB hD) (matrixProject_sub_norm _ _ _ _) + (norm_nonneg _) (g_constants_nonneg f hR B B D D).1 + _ = _ := by unfold kLip; ring + +lemma truncatedK_four_point (f : 𝓢(ℝ,ℂ)) {R : ℝ} (hR : 0 ≤ R) + (B B' D D' C C' M N : Matrix ι ι ℂ) + (hB : Bᴴ = B) (hB' : B'ᴴ = B') (hD : Dᴴ = D) (hD' : D'ᴴ = D') : + ‖(truncatedK f R hR B D C M-truncatedK f R hR B D C N)- + (truncatedK f R hR B' D' C' M-truncatedK f R hR B' D' C' N)‖ ≤ + kMixed f R B B' D D' C C'*‖M-N‖ := by + let G := truncatedG f R hR B D + let G' := truncatedG f R hR B' D' + let P : Matrix ι ι ℂ → Matrix ι ι ℂ := matrixProject R hR + have he : (truncatedK f R hR B D C M-truncatedK f R hR B D C N)- + (truncatedK f R hR B' D' C' M-truncatedK f R hR B' D' C' N) = + (G M*(P M-C)-G N*(P N-C))-(G' M*(P M-C')-G' N*(P N-C')) := by + dsimp [truncatedK,G,G',P]; abel + rw [he] + have h₁ : (P M-C)-(P M-C') = -(C-C') := by abel + have h₂ : (P M-C)-(P N-C) = P M-P N := by abel + have h₃ : ((P M-C)-(P N-C))-((P M-C')-(P N-C')) = 0 := by abel + have hh := product_four_point (G M) (G N) (G' M) (G' N) (P M-C) (P N-C) (P M-C') (P N-C') + rw [h₃,h₁,h₂,opNorm_neg,norm_zero,mul_zero,add_zero] at hh + apply hh.trans + calc + _ ≤ (gMixed f R B B' D D'*‖M-N‖)*(R+opNorm C)+ + (gLip f D'*‖M-N‖)*opNorm (C-C')+gChange f R B B' D D'*‖M-N‖ := by + apply add_le_add + · apply add_le_add + · exact mul_le_mul (truncatedG_four_point f hR B B' D D' M N hB hB' hD hD') + (projected_sub_bound hR M C) (opNorm_nonneg _) + (mul_nonneg (g_constants_nonneg f hR B B' D D').2.2.2 (norm_nonneg _)) + · exact mul_le_mul_of_nonneg_right (truncatedG_sub_norm _ _ _ _ _ _ _ hB' hD') (opNorm_nonneg _) + · exact mul_le_mul (truncatedG_parameter f hR B B' D D' N hB hB' hD hD') + (matrixProject_sub_norm _ _ _ _) (norm_nonneg _) + (g_constants_nonneg f hR B B' D D').2.2.1 + _ = _ := by unfold kMixed; ring + +end SKRatioGaussian.ComplexMatrix + +noncomputable section +open Matrix Set Filter +open scoped Topology Matrix.Norms.Frobenius + +end +end +end +end +end +end +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Matrices/FourierMoment.lean b/lean/OAI/Probability/SKRatio/Matrices/FourierMoment.lean new file mode 100644 index 0000000000000000000000000000000000000000..7d6ff49013f299ad44e9baddb12d979dbecba66f --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Matrices/FourierMoment.lean @@ -0,0 +1,89 @@ +import Mathlib +import OAI.Probability.SKRatio.Matrices.EntryLM + +namespace OAI + +section +section +noncomputable section +open MeasureTheory ProbabilityTheory InformationTheory Real Set +open scoped NNReal ENNReal +open Filter +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius ENNReal NNReal +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius NNReal +noncomputable section +open MeasureTheory ProbabilityTheory Real Set Filter +open MeasureTheory.Measure +open scoped ENNReal NNReal MeasureTheory Topology +open MeasureTheory +noncomputable section +noncomputable section +open MeasureTheory Set NormedSpace +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius +namespace SKRatioGaussian.ComplexMatrix +open MeasureTheory NormedSpace +open scoped FourierTransform SchwartzMap +variable {ι : Type*} [Fintype ι] [DecidableEq ι] + +noncomputable def fourierMoment (f : 𝓢(ℝ,ℂ)) (k : ℕ) : ℝ := + ∫ t : ℝ, ‖(𝓕 f) t‖*|t|^k + +lemma fourierMoment_nonneg (f : 𝓢(ℝ,ℂ)) (k : ℕ) : 0 ≤ fourierMoment f k := by + apply integral_nonneg + intro t + positivity + +lemma fourierMoment_integrable (f : 𝓢(ℝ,ℂ)) (k : ℕ) : + Integrable (fun t : ℝ => ‖(𝓕 f) t‖*|t|^k) := by + simpa only [Real.norm_eq_abs,mul_comm] using (𝓕 f).integrable_pow_mul volume k + +lemma opNorm_rsmul (r : ℝ) (M : Matrix ι ι ℂ) : opNorm (r • M) = |r| * opNorm M := by + change opNorm ((r:ℂ) • M) = _ + rw [opNorm_csmul,Complex.norm_real,Real.norm_eq_abs] + +lemma schwartzMatrix_lipschitz (f : 𝓢(ℝ,ℂ)) (M N : Matrix ι ι ℂ) + (hM : Mᴴ = M) (hN : Nᴴ = N) : + ‖schwartzMatrix f M-schwartzMatrix f N‖ ≤ + (2*Real.pi*fourierMoment f 1)*‖M-N‖ := by + have hf₁ : Integrable (fun t : ℝ => ‖(𝓕 f) t‖*|t|) := by + simpa only [pow_one] using fourierMoment_integrable f 1 + have hh := kernelMatrix_lipschitz (𝓕 f).integrable hf₁ + ((2*Real.pi:ℝ) • M) ((2*Real.pi:ℝ) • N) (by simp [hM]) (by simp [hN]) + rw [← smul_sub,norm_smul,Real.norm_eq_abs,abs_of_pos (by positivity : 0 < (2*Real.pi:ℝ))] at hh + exact hh.trans_eq (by simp only [fourierMoment,pow_one]; ring) + +lemma schwartzMatrix_four_point (f : 𝓢(ℝ,ℂ)) (a b c d : Matrix ι ι ℂ) + (ha : aᴴ = a) (hb : bᴴ = b) (hc : cᴴ = c) (hd : dᴴ = d) : + ‖(schwartzMatrix f a-schwartzMatrix f b)-(schwartzMatrix f c-schwartzMatrix f d)‖ ≤ + (2*Real.pi*fourierMoment f 1)*‖(a-b)-(c-d)‖ + + ((2*Real.pi)^2*fourierMoment f 2)*(opNorm (a-c)+opNorm (b-d))*‖c-d‖ := by + have hf₁ : Integrable (fun t : ℝ => ‖(𝓕 f) t‖*|t|) := by + simpa only [pow_one] using fourierMoment_integrable f 1 + have hh := kernelMatrix_four_point (𝓕 f).integrable hf₁ (fourierMoment_integrable f 2) + ((2*Real.pi:ℝ) • a) ((2*Real.pi:ℝ) • b) ((2*Real.pi:ℝ) • c) ((2*Real.pi:ℝ) • d) + (by simp [ha]) (by simp [hb]) (by simp [hc]) (by simp [hd]) + simp only [← smul_sub,norm_smul,opNorm_rsmul,Real.norm_eq_abs, + abs_of_pos (by positivity : 0 < (2*Real.pi:ℝ))] at hh + exact hh.trans_eq (by simp only [fourierMoment,pow_one]; ring) + +end SKRatioGaussian.ComplexMatrix + +end +end +end +end +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Matrices/FrobeniusSq.lean b/lean/OAI/Probability/SKRatio/Matrices/FrobeniusSq.lean new file mode 100644 index 0000000000000000000000000000000000000000..a854acec6a1b8327df50c7e3077512b042ac607f --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Matrices/FrobeniusSq.lean @@ -0,0 +1,84 @@ +import Mathlib +import OAI.Probability.SKRatio.Matrices.OpNorm + +namespace OAI + +section +section +noncomputable section +open MeasureTheory ProbabilityTheory InformationTheory Real Set +open scoped NNReal ENNReal +open Filter +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius ENNReal NNReal +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius NNReal +namespace SKRatioGaussian +variable {ι : Type*} [Fintype ι] [DecidableEq ι] + +lemma frobenius_sq (M : Matrix ι ι ℝ) : ‖M‖^2 = ∑ i,∑ k, (M i k)^2 := by + rw [Matrix.frobenius_norm_def] + simp only [Real.rpow_two, Real.norm_eq_abs,sq_abs] + rw [← Real.sqrt_eq_rpow,Real.sq_sqrt] + positivity + +lemma frobenius_col_sq (M : Matrix ι ι ℝ) : ‖M‖^2 = ∑ k, ‖colVec M k‖^2 := by + rw [frobenius_sq,Finset.sum_comm] + apply Finset.sum_congr rfl + intro k _ + rw [EuclideanSpace.norm_sq_eq] + simp [colVec,Real.norm_eq_abs,sq_abs] + +lemma colVec_mul (M N : Matrix ι ι ℝ) (k : ι) : + colVec (M*N) k = M.toEuclideanLin.toContinuousLinearMap (colVec N k) := by + ext i + rfl + +lemma frobenius_mul_le_opNorm (M N : Matrix ι ι ℝ) : ‖M*N‖ ≤ opNorm M * ‖N‖ := by + have hp : 0 ≤ opNorm M := norm_nonneg _ + apply nonneg_le_nonneg_of_sq_le_sq (mul_nonneg hp (norm_nonneg N)) + simp only [← sq] + rw [frobenius_col_sq,mul_pow,frobenius_col_sq,Finset.mul_sum] + apply Finset.sum_le_sum + intro k _ + rw [colVec_mul] + have hh := M.toEuclideanLin.toContinuousLinearMap.le_opNorm (colVec N k) + change ‖M.toEuclideanLin.toContinuousLinearMap (colVec N k)‖ ≤ opNorm M * ‖colVec N k‖ at hh + nlinarith only [hh, norm_nonneg (M.toEuclideanLin.toContinuousLinearMap (colVec N k)), + mul_nonneg hp (norm_nonneg (colVec N k))] + +lemma opNorm_transpose (M : Matrix ι ι ℝ) : opNorm Mᵀ = opNorm M := by + change ‖Mᵀ.toEuclideanLin.toContinuousLinearMap‖ = ‖M.toEuclideanLin.toContinuousLinearMap‖ + have he : Mᵀ.toEuclideanLin.toContinuousLinearMap = + ContinuousLinearMap.adjoint M.toEuclideanLin.toContinuousLinearMap := by + apply ContinuousLinearMap.ext + intro x + apply ext_inner_left ℝ + intro y + rw [ContinuousLinearMap.adjoint_inner_right] + change (∑ i, (∑ k, M k i*x k)*y i) = ∑ i, x i * (∑ k, M i k*y k) + simp only [Finset.sum_mul,Finset.mul_sum] + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro i _ + apply Finset.sum_congr rfl + intro k _ + ring + rw [he,ContinuousLinearMap.adjoint.norm_map] + +lemma frobenius_mul_le_opNorm_right (M N : Matrix ι ι ℝ) : ‖M*N‖ ≤ ‖M‖ * opNorm N := by + rw [← Matrix.frobenius_norm_transpose (M*N),Matrix.transpose_mul] + exact (frobenius_mul_le_opNorm Nᵀ Mᵀ).trans_eq (by rw [opNorm_transpose,Matrix.frobenius_norm_transpose,mul_comm]) + +end SKRatioGaussian + +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Matrices/GOERegression.lean b/lean/OAI/Probability/SKRatio/Matrices/GOERegression.lean new file mode 100644 index 0000000000000000000000000000000000000000..c03cdf81ac4aca817e10e8ba88317894e548c00e --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Matrices/GOERegression.lean @@ -0,0 +1,446 @@ +import Mathlib +import OAI.Probability.SKRatio.FiniteChain.Mean + +namespace OAI + +section +noncomputable section +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal ENNReal Matrix Matrix.Norms.Elementwise + +namespace SKRatioClock.Regression + +local instance matrixMeasurable {n m : ℕ} : MeasurableSpace (Matrix (Fin n) (Fin m) ℝ) := + inferInstanceAs (MeasurableSpace (Fin n → Fin m → ℝ)) + +local instance matrixBorel {n m : ℕ} : BorelSpace (Matrix (Fin n) (Fin m) ℝ) := + inferInstanceAs (BorelSpace (Fin n → Fin m → ℝ)) + +noncomputable def standardArrayLaw (ι : Type*) [Fintype ι] : Measure (ι → ℝ) := + Measure.pi (fun _ => gaussianReal 0 1) + +instance {ι : Type*} [Fintype ι] : IsProbabilityMeasure (standardArrayLaw ι) := by + unfold standardArrayLaw + infer_instance + +lemma coordinate_hasLaw {ι : Type*} [Fintype ι] (i : ι) : + HasLaw (fun g : ι → ℝ => g i) (gaussianReal 0 1) (standardArrayLaw ι) := + (measurePreserving_eval (fun _ : ι => gaussianReal 0 1) i).hasLaw + +lemma coordinates_independent {ι : Type*} [Fintype ι] : + iIndepFun (fun i (g : ι → ℝ) => g i) (standardArrayLaw ι) := + iIndepFun_pi (fun _ => measurable_id.aemeasurable) + +lemma coordinates_gaussian {ι : Type*} [Fintype ι] : + HasGaussianLaw (fun g : ι → ℝ => g) (standardArrayLaw ι) := + coordinates_independent.hasGaussianLaw (fun i => (coordinate_hasLaw i).hasGaussianLaw) + +lemma coordinate_covariance {ι : Type*} [Fintype ι] [DecidableEq ι] (i j : ι) : + cov[fun g : ι → ℝ => g i, fun g => g j; standardArrayLaw ι] = if i = j then 1 else 0 := by + by_cases h : i = j + · subst j + rw [covariance_self (coordinate_hasLaw i).aemeasurable, + (coordinate_hasLaw i).variance_eq, variance_id_gaussianReal] + simp + · rw [ite_eq_right h] + exact (coordinates_independent.indepFun h).covariance_eq_zero + ((coordinate_hasLaw i).hasGaussianLaw.memLp_two) + ((coordinate_hasLaw j).hasGaussianLaw.memLp_two) + +noncomputable def linearTest {ι : Type*} [Fintype ι] (a : ι → ℝ) : (ι → ℝ) →L[ℝ] ℝ := + ∑ i, a i • ContinuousLinearMap.proj i + +@[simp] lemma linearTest_apply {ι : Type*} [Fintype ι] (a g : ι → ℝ) : + linearTest a g = ∑ i, a i * g i := by simp [linearTest] + +lemma linearTest_covariance {ι : Type*} [Fintype ι] [DecidableEq ι] (a b : ι → ℝ) : + cov[fun g : ι → ℝ => ∑ i, a i * g i, + fun g => ∑ i, b i * g i; standardArrayLaw ι] = ∑ i, a i * b i := by + rw [covariance_fun_sum_fun_sum] + · simp_rw [covariance_const_mul_left, covariance_const_mul_right, coordinate_covariance] + simp + · exact fun i => ((coordinate_hasLaw i).hasGaussianLaw.memLp_two).const_mul _ + · exact fun i => ((coordinate_hasLaw i).hasGaussianLaw.memLp_two).const_mul _ + +noncomputable def goe {n : ℕ} (g : (Fin n × Fin n) → ℝ) : Matrix (Fin n) (Fin n) ℝ := + fun i j => (g (i,j) + g (j,i)) / Real.sqrt (2*n) + +lemma goe_symmetric {n : ℕ} (g : (Fin n × Fin n) → ℝ) : (goe g)ᵀ = goe g := by + ext i j + simp [goe, add_comm] + +noncomputable def goeCLM (n : ℕ) : ((Fin n × Fin n) → ℝ) →L[ℝ] Matrix (Fin n) (Fin n) ℝ := + ContinuousLinearMap.pi fun i => ContinuousLinearMap.pi fun j => + (Real.sqrt (2*n))⁻¹ • ((ContinuousLinearMap.proj (i,j) : ((Fin n × Fin n) → ℝ) →L[ℝ] ℝ) + ContinuousLinearMap.proj (j,i)) + +@[simp] lemma goeCLM_apply (n : ℕ) (g : (Fin n × Fin n) → ℝ) : goeCLM n g = goe g := by + ext i j + change (Real.sqrt (2*n))⁻¹ * (g (i,j) + g (j,i)) = + (g (i,j) + g (j,i)) / Real.sqrt (2*n) + rw [div_eq_mul_inv, mul_comm] + +lemma goe_gaussian (n : ℕ) : + HasGaussianLaw (fun g : (Fin n × Fin n) → ℝ => goe g) + (standardArrayLaw (Fin n × Fin n)) := by + have h := coordinates_gaussian.map_fun + (show ((Fin n × Fin n) → ℝ) →L[ℝ] (Fin n → Fin n → ℝ) from goeCLM n) + exact h.congr (Filter.Eventually.of_forall (goeCLM_apply n)) + +lemma goe_entry_memLp {n : ℕ} (i j : Fin n) : + MemLp (fun g : (Fin n × Fin n) → ℝ => goe g i j) 2 (standardArrayLaw (Fin n × Fin n)) := + ((goe_gaussian n).eval i |>.eval j).memLp_two + +lemma goe_entry_covariance {n : ℕ} (hn : 0 < n) (i j k l : Fin n) : + cov[fun g : (Fin n × Fin n) → ℝ => goe g i j, fun g => goe g k l; + standardArrayLaw (Fin n × Fin n)] = + ((if i = k ∧ j = l then 1 else 0) + (if i = l ∧ j = k then 1 else 0)) / n := by + have hLp (a : Fin n × Fin n) := (coordinate_hasLaw a).hasGaussianLaw.memLp_two + simp only [goe, covariance_fun_div_left, covariance_fun_div_right] + change cov[(fun g => g (i,j)) + (fun g => g (j,i)), + (fun g => g (k,l)) + (fun g => g (l,k)); standardArrayLaw (Fin n × Fin n)] / + Real.sqrt (2*n) / Real.sqrt (2*n) = _ + rw [covariance_add_left (hLp _) (hLp _) ((hLp _).add (hLp _)), + covariance_add_right (hLp _) (hLp _) (hLp _), + covariance_add_right (hLp _) (hLp _) (hLp _)] + simp only [coordinate_covariance, Prod.mk.injEq] + have hnR : (0 : ℝ) < n := by exact_mod_cast hn + have hs : Real.sqrt (2*n) ^ 2 = 2*n := Real.sq_sqrt (by positivity) + have hs0 : Real.sqrt (2*(n : ℝ)) ≠ 0 := (Real.sqrt_pos.2 (by positivity)).ne' + rw [div_div, ← pow_two] + rw [hs] + have ha : (j = k ∧ i = l) ↔ (i = l ∧ j = k) := and_comm + have hb : (j = l ∧ i = k) ↔ (i = k ∧ j = l) := and_comm + simp only [ha, hb] + ring + +noncomputable def sandwichCLM {a n b : ℕ} + (A : Matrix (Fin a) (Fin n) ℝ) (B : Matrix (Fin n) (Fin b) ℝ) : + Matrix (Fin n) (Fin n) ℝ →L[ℝ] Matrix (Fin a) (Fin b) ℝ := + LinearMap.toContinuousLinearMap { + toFun := fun G => A * G * B + map_add' := by intro G H; simp [Matrix.mul_add, Matrix.add_mul] + map_smul' := by intro c G; simp [Matrix.mul_smul, Matrix.smul_mul] } + +@[simp] lemma sandwichCLM_apply {a n b : ℕ} + (A : Matrix (Fin a) (Fin n) ℝ) (B : Matrix (Fin n) (Fin b) ℝ) + (G : Matrix (Fin n) (Fin n) ℝ) : sandwichCLM A B G = A * G * B := rfl + +def residualProjection {n r : ℕ} (U : Matrix (Fin n) (Fin r) ℝ) : Matrix (Fin n) (Fin n) ℝ := + 1 - U * Uᵀ + +lemma residualProjection_symmetric {n r : ℕ} (U : Matrix (Fin n) (Fin r) ℝ) : + (residualProjection U)ᵀ = residualProjection U := by + simp [residualProjection] + +lemma residualProjection_mul {n r : ℕ} (U : Matrix (Fin n) (Fin r) ℝ) (hU : Uᵀ * U = 1) : + residualProjection U * U = 0 := by + simp [residualProjection, Matrix.sub_mul, Matrix.mul_assoc, hU] + +lemma mul_residualProjection {n r : ℕ} (U : Matrix (Fin n) (Fin r) ℝ) (hU : Uᵀ * U = 1) : + Uᵀ * residualProjection U = 0 := by + simp [residualProjection, Matrix.mul_sub, ← Matrix.mul_assoc, hU] + +lemma regression_decomposition {n r : ℕ} (G : Matrix (Fin n) (Fin n) ℝ) + (U : Matrix (Fin n) (Fin r) ℝ) (hG : Gᵀ = G) : + G = (G*U)*Uᵀ + U*(G*U)ᵀ - U*(Uᵀ*(G*U))*Uᵀ + + residualProjection U * G * residualProjection U := by + simp only [Matrix.transpose_mul, hG, residualProjection] + simp only [Matrix.sub_mul, Matrix.mul_sub, Matrix.one_mul, Matrix.mul_one] + simp only [Matrix.mul_assoc] + abel + +lemma goe_entry_sandwich_covariance {n a b : ℕ} (hn : 0 < n) + (C : Matrix (Fin a) (Fin n) ℝ) (D : Matrix (Fin n) (Fin b) ℝ) + (i j : Fin n) (k : Fin a) (l : Fin b) : + cov[fun g : (Fin n × Fin n) → ℝ => goe g i j, + fun g => (C * goe g * D) k l; standardArrayLaw (Fin n × Fin n)] = + (C k i * D j l + C k j * D i l) / n := by + have hterm (p q : Fin n) : MemLp (fun g : (Fin n × Fin n) → ℝ => + C k q * goe g q p * D p l) 2 (standardArrayLaw (Fin n × Fin n)) := + ((goe_entry_memLp q p).const_mul _).mul_const _ + have hsum (p : Fin n) := memLp_finsetSum Finset.univ (fun q _ => hterm p q) + have he (g : (Fin n × Fin n) → ℝ) : (C * goe g * D) k l = + ∑ p, ∑ q, C k q * goe g q p * D p l := by + simp [Matrix.mul_apply, Finset.sum_mul] + simp_rw [he] + rw [covariance_fun_sum_right hsum (goe_entry_memLp i j)] + simp_rw [covariance_fun_sum_right (fun q => hterm _ q) (goe_entry_memLp i j), + covariance_mul_const_right, covariance_const_mul_right, goe_entry_covariance hn] + simp only [ite_and, add_div, mul_add, add_mul, Finset.sum_add_distrib, + ite_div, mul_ite, ite_mul, zero_div, mul_zero, zero_mul] + simp + ring + +lemma goe_sandwich_covariance {n a b c d : ℕ} (hn : 0 < n) + (A : Matrix (Fin a) (Fin n) ℝ) (B : Matrix (Fin n) (Fin b) ℝ) + (C : Matrix (Fin c) (Fin n) ℝ) (D : Matrix (Fin n) (Fin d) ℝ) + (i : Fin a) (j : Fin b) (k : Fin c) (l : Fin d) : + cov[fun g : (Fin n × Fin n) → ℝ => (A * goe g * B) i j, + fun g => (C * goe g * D) k l; standardArrayLaw (Fin n × Fin n)] = + ((Bᵀ * D) j l * (A * Cᵀ) i k + (C * B) k j * (A * D) i l) / n := by + have hterm (p q : Fin n) : MemLp (fun g : (Fin n × Fin n) → ℝ => + A i q * goe g q p * B p j) 2 (standardArrayLaw (Fin n × Fin n)) := + ((goe_entry_memLp q p).const_mul _).mul_const _ + have hsum (p : Fin n) := memLp_finsetSum Finset.univ (fun q _ => hterm p q) + have hCD : MemLp (fun g : (Fin n × Fin n) → ℝ => (C * goe g * D) k l) + 2 (standardArrayLaw (Fin n × Fin n)) := by + simp only [Matrix.mul_apply, Finset.sum_mul] + exact memLp_finsetSum _ (fun p _ => memLp_finsetSum _ + (fun q _ => ((goe_entry_memLp q p).const_mul _).mul_const _)) + have he (g : (Fin n × Fin n) → ℝ) : (A * goe g * B) i j = + ∑ p, ∑ q, A i q * goe g q p * B p j := by + simp [Matrix.mul_apply, Finset.sum_mul] + simp_rw [he] + rw [covariance_fun_sum_left hsum hCD] + simp_rw [covariance_fun_sum_left (fun q => hterm _ q) hCD, + covariance_mul_const_left, covariance_const_mul_left, goe_entry_sandwich_covariance hn] + simp only [Matrix.mul_apply, Matrix.transpose_apply, Finset.sum_mul, Finset.mul_sum, + ← Finset.sum_add_distrib] + rw [Finset.sum_comm] + simp only [← mul_div_assoc, div_mul_eq_mul_div, ← Finset.sum_div] + apply congrArg (fun x : ℝ => x / n) + apply Finset.sum_congr rfl + intro p _ + apply Finset.sum_congr rfl + intro q _ + ring + +lemma residual_answer_covariance {n r : ℕ} (hn : 0 < n) + (U : Matrix (Fin n) (Fin r) ℝ) (hU : Uᵀ * U = 1) + (i j k : Fin n) (l : Fin r) : + cov[fun g : (Fin n × Fin n) → ℝ => + (residualProjection U * goe g * residualProjection U) i j, + fun g => (goe g * U) k l; standardArrayLaw (Fin n × Fin n)] = 0 := by + have h := goe_sandwich_covariance hn (residualProjection U) (residualProjection U) + (1 : Matrix (Fin n) (Fin n) ℝ) U i j k l + simpa [residualProjection_symmetric, residualProjection_mul U hU] using h + +noncomputable def entryCLM {n m : ℕ} (i : Fin n) (j : Fin m) : + Matrix (Fin n) (Fin m) ℝ →L[ℝ] ℝ := + (ContinuousLinearMap.proj j : (Fin m → ℝ) →L[ℝ] ℝ).comp + (ContinuousLinearMap.proj i : (Fin n → Fin m → ℝ) →L[ℝ] (Fin m → ℝ)) + +@[simp] lemma entryCLM_apply {n m : ℕ} (i : Fin n) (j : Fin m) + (G : Matrix (Fin n) (Fin m) ℝ) : entryCLM i j G = G i j := rfl + +noncomputable def regressionCLM {n r : ℕ} (U : Matrix (Fin n) (Fin r) ℝ) : + ((Fin n × Fin n) → ℝ) →L[ℝ] + (((Fin n × Fin n) → ℝ) × ((Fin n × Fin r) → ℝ)) := + (ContinuousLinearMap.pi (fun p : Fin n × Fin n => + ((entryCLM p.1 p.2).comp (sandwichCLM (residualProjection U) (residualProjection U))).comp + (goeCLM n))).prod + (ContinuousLinearMap.pi (fun p : Fin n × Fin r => + ((entryCLM p.1 p.2).comp (sandwichCLM (1 : Matrix (Fin n) (Fin n) ℝ) U)).comp + (goeCLM n))) + +lemma regressionCLM_apply {n r : ℕ} (U : Matrix (Fin n) (Fin r) ℝ) + (g : (Fin n × Fin n) → ℝ) : + regressionCLM U g = + (fun p : Fin n × Fin n => (residualProjection U * goe g * residualProjection U) p.1 p.2, + fun p : Fin n × Fin r => (goe g * U) p.1 p.2) := by + change (fun p : Fin n × Fin n => + (residualProjection U * (goeCLM n) g * residualProjection U) p.1 p.2, + fun p : Fin n × Fin r => ((1 : Matrix (Fin n) (Fin n) ℝ) * (goeCLM n) g * U) p.1 p.2) = _ + rw [goeCLM_apply, Matrix.one_mul] + +lemma residual_answer_independent {n r : ℕ} (hn : 0 < n) + (U : Matrix (Fin n) (Fin r) ℝ) (hU : Uᵀ * U = 1) : + IndepFun (fun g : (Fin n × Fin n) → ℝ => fun p : Fin n × Fin n => + (residualProjection U * goe g * residualProjection U) p.1 p.2) + (fun g => fun p : Fin n × Fin r => (goe g * U) p.1 p.2) + (standardArrayLaw (Fin n × Fin n)) := by + have hXY := (coordinates_gaussian.map_fun (regressionCLM U)).congr + (Filter.Eventually.of_forall (regressionCLM_apply U)) + exact hXY.indepFun_of_covariance_eval (fun p q => + residual_answer_covariance hn U hU p.1 p.2 q.1 q.2) + +def revealedCompletion {n r : ℕ} (U Y : Matrix (Fin n) (Fin r) ℝ) : + Matrix (Fin n) (Fin n) ℝ := + Y * Uᵀ + U * Yᵀ - U * (Uᵀ * Y) * Uᵀ + +lemma revealedCompletion_answer {n r : ℕ} (U Y : Matrix (Fin n) (Fin r) ℝ) + (hU : Uᵀ * U = 1) (hY : Uᵀ * Y = Yᵀ * U) : + revealedCompletion U Y * U = Y := by + simp only [revealedCompletion, Matrix.sub_mul, Matrix.add_mul] + rw [Matrix.mul_assoc Y, hU, Matrix.mul_one, Matrix.mul_assoc U Yᵀ, + Matrix.mul_assoc (U * (Uᵀ * Y)), hU, Matrix.mul_one, hY] + abel + +lemma revealedCompletion_symmetric {n r : ℕ} (U Y : Matrix (Fin n) (Fin r) ℝ) + (hY : Uᵀ * Y = Yᵀ * U) : + (revealedCompletion U Y)ᵀ = revealedCompletion U Y := by + simp only [revealedCompletion, Matrix.transpose_sub, Matrix.transpose_add, + Matrix.transpose_mul, Matrix.transpose_transpose] + rw [← hY] + simp only [Matrix.mul_assoc] + abel + +lemma revealedCompletion_residual {n r : ℕ} (U Y : Matrix (Fin n) (Fin r) ℝ) + (hU : Uᵀ * U = 1) : + residualProjection U * revealedCompletion U Y * residualProjection U = 0 := by + simp only [revealedCompletion, Matrix.mul_sub, Matrix.mul_add, Matrix.sub_mul, + Matrix.add_mul] + rw [Matrix.mul_assoc (residualProjection U) (Y * Uᵀ) (residualProjection U)] + rw [Matrix.mul_assoc Y Uᵀ (residualProjection U), mul_residualProjection U hU, + Matrix.mul_zero, Matrix.mul_zero] + simp only [← Matrix.mul_assoc, residualProjection_mul U hU, Matrix.zero_mul, + add_zero, sub_zero] + +lemma revealedCompletion_unique {n r : ℕ} (G : Matrix (Fin n) (Fin n) ℝ) + (U Y : Matrix (Fin n) (Fin r) ℝ) (hG : Gᵀ = G) (hY : G*U = Y) + (hR : residualProjection U * G * residualProjection U = 0) : + G = revealedCompletion U Y := by + simpa only [hY, hR, add_zero, revealedCompletion] using regression_decomposition G U hG + +lemma regression_factorization {n r : ℕ} (hn : 0 < n) + (U : Matrix (Fin n) (Fin r) ℝ) (hU : Uᵀ * U = 1) : + (standardArrayLaw (Fin n × Fin n)).map (fun g => + (fun p : Fin n × Fin n => (residualProjection U * goe g * residualProjection U) p.1 p.2, + fun p : Fin n × Fin r => (goe g * U) p.1 p.2)) = + ((standardArrayLaw (Fin n × Fin n)).map (fun g => fun p : Fin n × Fin n => + (residualProjection U * goe g * residualProjection U) p.1 p.2)).prod + ((standardArrayLaw (Fin n × Fin n)).map (fun g => fun p : Fin n × Fin r => + (goe g * U) p.1 p.2)) := by + have hXY := (coordinates_gaussian.map_fun (regressionCLM U)).congr + (Filter.Eventually.of_forall (regressionCLM_apply U)) + exact (residual_answer_independent hn U hU).map_prod_eq_prod_map_map + hXY.fst.aemeasurable hXY.snd.aemeasurable + +lemma coordinate_mean {ι : Type*} [Fintype ι] (i : ι) : + (∫ g : ι → ℝ, g i ∂standardArrayLaw ι) = 0 := by + rw [(coordinate_hasLaw i).integral_eq, integral_id_gaussianReal] + +lemma goe_entry_mean {n : ℕ} (i j : Fin n) : + (∫ g : (Fin n × Fin n) → ℝ, goe g i j ∂standardArrayLaw (Fin n × Fin n)) = 0 := by + simp only [goe, integral_div] + rw [integral_add (coordinate_hasLaw (i,j)).hasGaussianLaw.integrable + (coordinate_hasLaw (j,i)).hasGaussianLaw.integrable] + simp only [coordinate_mean, add_zero, zero_div] + +lemma sandwich_entry_mean {n r s : ℕ} + (A : Matrix (Fin r) (Fin n) ℝ) (B : Matrix (Fin n) (Fin s) ℝ) + (i : Fin r) (j : Fin s) : + (∫ g : (Fin n × Fin n) → ℝ, (A * goe g * B) i j + ∂standardArrayLaw (Fin n × Fin n)) = 0 := by + have hterm (k l : Fin n) : Integrable (fun g : (Fin n × Fin n) → ℝ => + A i l * goe g l k * B k j) (standardArrayLaw (Fin n × Fin n)) := + ((goe_entry_memLp l k).integrable (by norm_num)).const_mul _ |>.mul_const _ + have he (g : (Fin n × Fin n) → ℝ) : (A * goe g * B) i j = + ∑ k, ∑ l, A i l * goe g l k * B k j := by + simp [Matrix.mul_apply, Finset.sum_mul] + simp_rw [he] + rw [integral_finsetSum Finset.univ (fun k _ => integrable_finsetSum Finset.univ (fun l _ => hterm k l))] + have inner (k : Fin n) : (∫ g : (Fin n × Fin n) → ℝ, + ∑ l, A i l * goe g l k * B k j ∂standardArrayLaw (Fin n × Fin n)) = 0 := by + rw [integral_finsetSum Finset.univ (fun l _ => hterm k l)] + simp only [integral_mul_const, integral_const_mul, goe_entry_mean, mul_zero, + zero_mul, Finset.sum_const_zero] + simp only [inner, Finset.sum_const_zero] + +def queryColumn {n : ℕ} (q : Fin n → ℝ) : Matrix (Fin n) (Fin 1) ℝ := fun i _ => q i + +def queryComplement {n : ℕ} (P : Matrix (Fin n) (Fin n) ℝ) (q : Fin n → ℝ) := + P - queryColumn q * (queryColumn q)ᵀ + +lemma queryColumn_unit {n : ℕ} (q : Fin n → ℝ) (hq : ∑ i, q i ^ 2 = 1) : + (queryColumn q)ᵀ * queryColumn q = 1 := by + ext i j + have hi : i = 0 := Subsingleton.elim _ _ + have hj : j = 0 := Subsingleton.elim _ _ + subst i; subst j + simpa [Matrix.mul_apply, queryColumn, pow_two] using hq + +lemma gaussian_add_constant {ι Ω : Type*} [Fintype ι] [MeasurableSpace Ω] + {μ : Measure Ω} {X : Ω → ι → ℝ} (hX : HasGaussianLaw X μ) (c : ι → ℝ) : + HasGaussianLaw (fun ω => X ω + c) μ := by + have := hX.isGaussian_map + refine ⟨hX.aemeasurable.add_const c, ?_⟩ + change IsGaussian (μ.map ((fun x : ι → ℝ => x+c) ∘ X)) + rw [← AEMeasurable.map_map_of_aemeasurable + (by fun_prop : AEMeasurable (fun x : ι → ℝ => x+c) (μ.map X)) hX.aemeasurable] + infer_instance + +lemma piGaussian_coordinates {ι : Type*} [Fintype ι] (m : ι → ℝ) (v : ℝ≥0) : + HasGaussianLaw (fun g : ι → ℝ => g) (Measure.pi (fun i => gaussianReal (m i) v)) := + (iIndepFun_pi (fun _ => measurable_id.aemeasurable)).hasGaussianLaw + (fun i => (measurePreserving_eval (fun j => gaussianReal (m j) v) i).hasLaw.hasGaussianLaw) + +lemma piGaussian_coordinate_mean {ι : Type*} [Fintype ι] (m : ι → ℝ) (v : ℝ≥0) (i : ι) : + (∫ g : ι → ℝ, g i ∂Measure.pi (fun j => gaussianReal (m j) v)) = m i := by + rw [(measurePreserving_eval (fun j => gaussianReal (m j) v) i).hasLaw.integral_eq] + exact integral_id_gaussianReal + +lemma piGaussian_coordinate_covariance {ι : Type*} [Fintype ι] [DecidableEq ι] + (m : ι → ℝ) (v : ℝ≥0) (i j : ι) : + cov[fun g : ι → ℝ => g i, fun g => g j; Measure.pi (fun k => gaussianReal (m k) v)] = + if i = j then (v:ℝ) else 0 := by + by_cases h : i=j + · subst j + rw [covariance_self (measurePreserving_eval (fun k => gaussianReal (m k) v) i).aemeasurable, + (measurePreserving_eval (fun k => gaussianReal (m k) v) i).hasLaw.variance_eq, + variance_id_gaussianReal] + simp + · rw [ite_eq_right h] + exact ((iIndepFun_pi (fun _ => measurable_id.aemeasurable)).indepFun h).covariance_eq_zero + (((piGaussian_coordinates m v).eval i).memLp_two) + (((piGaussian_coordinates m v).eval j).memLp_two) + +noncomputable def sharedGaussianField {n : ℕ} (m a b : ℝ) + (g : Option (Fin n) → ℝ) : Fin n → ℝ := fun i => m + a*g (some i) + b*g none + +noncomputable def sharedGaussianFieldCLM (n : ℕ) (a b : ℝ) : + (Option (Fin n) → ℝ) →L[ℝ] (Fin n → ℝ) := + ContinuousLinearMap.pi fun i => a • + (ContinuousLinearMap.proj (some i) : (Option (Fin n) → ℝ) →L[ℝ] ℝ) + + b • ContinuousLinearMap.proj none + +lemma sharedGaussianField_gaussian (n : ℕ) (m a b : ℝ) : + HasGaussianLaw (sharedGaussianField (n := n) m a b) (standardArrayLaw (Option (Fin n))) := by + have hh := gaussian_add_constant (coordinates_gaussian.map_fun (sharedGaussianFieldCLM n a b)) + (fun _ : Fin n => m) + apply hh.congr + exact Eventually.of_forall fun g => by + ext i + simp [sharedGaussianFieldCLM, sharedGaussianField] + ring + +lemma sharedGaussianField_mean {n : ℕ} (m a b : ℝ) (i : Fin n) : + (∫ g, sharedGaussianField m a b g i ∂standardArrayLaw (Option (Fin n))) = m := by + have ha := (coordinate_hasLaw (some i)).hasGaussianLaw.integrable.const_mul a + have hb := (coordinate_hasLaw (none : Option (Fin n))).hasGaussianLaw.integrable.const_mul b + simp only [sharedGaussianField] + have hai : Integrable (fun g : Option (Fin n) → ℝ => m+a*g (some i)) + (standardArrayLaw (Option (Fin n))) := (integrable_const m).add ha + rw [integral_add hai hb, + integral_add (integrable_const m) ha, integral_const_mul, integral_const_mul, + coordinate_mean, coordinate_mean] + simp + +lemma sharedGaussianField_covariance {n : ℕ} (m a b : ℝ) (i k : Fin n) : + cov[fun g => sharedGaussianField m a b g i, fun g => sharedGaussianField m a b g k; + standardArrayLaw (Option (Fin n))] = (if i=k then a^2 else 0)+b^2 := by + have hm (i : Fin n) : MemLp (fun g : Option (Fin n) → ℝ => a*g (some i)) 2 + (standardArrayLaw (Option (Fin n))) := (coordinate_hasLaw (some i)).hasGaussianLaw.memLp_two.const_mul a + have hb : MemLp (fun g : Option (Fin n) → ℝ => b*g none) 2 + (standardArrayLaw (Option (Fin n))) := (coordinate_hasLaw none).hasGaussianLaw.memLp_two.const_mul b + have he (g : Option (Fin n) → ℝ) (i : Fin n) : sharedGaussianField m a b g i = + (a*g (some i)+b*g none)+m := by unfold sharedGaussianField; ring + have hs (j : Fin n) : Integrable (fun g : Option (Fin n) → ℝ => a*g (some j)+b*g none) + (standardArrayLaw (Option (Fin n))) := ((hm j).add hb).integrable (by norm_num) + simp_rw [he] + rw [covariance_add_const_left (hs i), + covariance_add_const_right (hs k)] + change cov[(fun g => a*g (some i))+(fun g => b*g none), + (fun g => a*g (some k))+(fun g => b*g none); standardArrayLaw (Option (Fin n))] = _ + rw [covariance_add_left (hm i) hb ((hm k).add hb), + covariance_add_right (hm i) (hm k) hb, + covariance_add_right hb (hm k) hb] + simp_rw [covariance_const_mul_left, covariance_const_mul_right, coordinate_covariance] + by_cases h : i=k <;> simp [h] <;> ring + +end SKRatioClock.Regression + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Matrices/GaussianAffineGaussianSup.lean b/lean/OAI/Probability/SKRatio/Matrices/GaussianAffineGaussianSup.lean new file mode 100644 index 0000000000000000000000000000000000000000..1806499212f6d089111e772d212028b705cb07df --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Matrices/GaussianAffineGaussianSup.lean @@ -0,0 +1,115 @@ +import Mathlib +import OAI.Probability.SKRatio.Matrices.GaussianCoordinates + +namespace OAI + +section +section +noncomputable section +open MeasureTheory ProbabilityTheory InformationTheory Real Set +open scoped NNReal ENNReal +open Filter +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius ENNReal NNReal +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius NNReal +noncomputable section +open MeasureTheory ProbabilityTheory Real Set Filter +open MeasureTheory.Measure +open scoped ENNReal NNReal MeasureTheory Topology +open MeasureTheory +noncomputable section +noncomputable section +open MeasureTheory Set NormedSpace +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius +noncomputable section +open Set Real +open scoped Topology +noncomputable section +open Matrix Set Filter +open scoped Topology Matrix.Norms.Frobenius +noncomputable section +open Matrix NormedSpace ContinuousLinearMap +open scoped Matrix.Norms.Frobenius +noncomputable section +open Matrix +noncomputable section +open MeasureTheory ProbabilityTheory Real Set +open scoped ENNReal NNReal +noncomputable section +open MeasureTheory ProbabilityTheory InformationTheory Real Set +open scoped NNReal ENNReal +noncomputable section +open scoped BigOperators +open MeasureTheory ProbabilityTheory +namespace SKRatioGaussian +section SupLipschitz +variable {I κ : Type*} [TopologicalSpace I] [CompactSpace I] [Nonempty I] [Fintype κ] + +lemma gaussianAffine_le_gaussianSup {m : I → ℝ} {a : I → κ → ℝ} + (hm : Continuous m) (ha : Continuous a) (x : κ → ℝ) (i : I) : + gaussianAffine m a x i ≤ gaussianSup m a x := by + obtain ⟨j, hj, hmax⟩ := gaussianSup_attained hm ha x + rw [hj] + exact hmax i + +lemma gaussianSup_sub_le {m : I → ℝ} {a : I → κ → ℝ} + (hm : Continuous m) (ha : Continuous a) {L : ℝ} + (hL : ∀ i, ‖WithLp.toLp 2 (a i)‖ ≤ L) (x y : EuclideanSpace ℝ κ) : + gaussianSup m a x.ofLp - gaussianSup m a y.ofLp ≤ L * ‖x-y‖ := by + obtain ⟨i, hi, _⟩ := gaussianSup_attained hm ha x.ofLp + calc + _ ≤ gaussianAffine m a x.ofLp i - gaussianAffine m a y.ofLp i := by + rw [hi] + exact sub_le_sub_left (gaussianAffine_le_gaussianSup hm ha y.ofLp i) _ + _ = inner ℝ (WithLp.toLp 2 (a i)) (x-y) := by + simp only [gaussianAffine, PiLp.inner_apply, WithLp.ofLp_sub, + Pi.sub_apply, RCLike.inner_apply, conj_trivial] + rw [add_sub_add_left_eq_sub, ← Finset.sum_sub_distrib] + apply Finset.sum_congr rfl + intro k _ + ring + _ ≤ ‖WithLp.toLp 2 (a i)‖ * ‖x-y‖ := real_inner_le_norm _ _ + _ ≤ L * ‖x-y‖ := mul_le_mul_of_nonneg_right (hL i) (norm_nonneg _) + +theorem gaussianSup_lipschitz {m : I → ℝ} {a : I → κ → ℝ} + (hm : Continuous m) (ha : Continuous a) {L : ℝ≥0} + (hL : ∀ i, ‖WithLp.toLp 2 (a i)‖ ≤ (L : ℝ)) : + LipschitzWith L (fun x : EuclideanSpace ℝ κ => gaussianSup m a x.ofLp) := by + apply LipschitzWith.of_dist_le_mul + intro x y + rw [Real.dist_eq, dist_eq_norm] + apply abs_le.mpr + constructor + · have h := gaussianSup_sub_le hm ha hL y x + rw [norm_sub_rev] at h + linarith + · exact gaussianSup_sub_le hm ha hL x y + +end SupLipschitz +end SKRatioGaussian + +end +end +end +end +end +end +end +end +end +end +end +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Matrices/GaussianCoordinateMemLp.lean b/lean/OAI/Probability/SKRatio/Matrices/GaussianCoordinateMemLp.lean new file mode 100644 index 0000000000000000000000000000000000000000..7d83cc35d64f31eb7839ca8b13a22f9e1cd4bcdb --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Matrices/GaussianCoordinateMemLp.lean @@ -0,0 +1,111 @@ +import Mathlib +import OAI.Probability.SKRatio.Matrices.MatrixCoordinates + +namespace OAI + +section +section +noncomputable section +open MeasureTheory ProbabilityTheory InformationTheory Real Set +open scoped NNReal ENNReal +open Filter +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius ENNReal NNReal +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius NNReal +noncomputable section +open MeasureTheory ProbabilityTheory Real Set Filter +open MeasureTheory.Measure +open scoped ENNReal NNReal MeasureTheory Topology +open MeasureTheory +noncomputable section +noncomputable section +open MeasureTheory Set NormedSpace +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius +noncomputable section +open Set Real +open scoped Topology +noncomputable section +open Matrix Set Filter +open scoped Topology Matrix.Norms.Frobenius +noncomputable section +open Matrix NormedSpace ContinuousLinearMap +open scoped Matrix.Norms.Frobenius +noncomputable section +open Matrix +namespace SKRatioGaussian +open MeasureTheory ProbabilityTheory Real +open scoped ENNReal NNReal +variable {ι : Type*} [Fintype ι] + +lemma gaussianCoordinate_memLp (a : MatrixCoordinates ι) : + MemLp (fun g : MatrixCoordinates ι → ℝ => g a) 2 + (Measure.pi (fun _ => gaussianReal 0 1)) := by + exact (IsGaussian.memLp_id (gaussianReal 0 1) 2 (by norm_num)).comp_measurePreserving + (measurePreserving_eval (fun _ : MatrixCoordinates ι => gaussianReal 0 1) a) + +lemma gaussianCoordinate_integral_sq (a : MatrixCoordinates ι) : + (∫ g : MatrixCoordinates ι → ℝ, (g a)^2 ∂Measure.pi (fun _ => gaussianReal 0 1)) = 1 := by + rw [integral_comp_eval (μ := fun _ : MatrixCoordinates ι => gaussianReal 0 1) (i := a) (by fun_prop : AEStronglyMeasurable (fun x : ℝ => x^2) (gaussianReal 0 1))] + have hh := variance_fun_id_gaussianReal (μ := 0) (v := 1) + rw [variance_eq_integral (by fun_prop),integral_id_gaussianReal] at hh + simpa only [sub_zero,NNReal.coe_one] using hh + +lemma goeEntry_memLp (r : ℝ) (i b : ι) : + MemLp (fun g => goeMatrix r g i b) 2 + (Measure.pi (fun _ : MatrixCoordinates ι => gaussianReal 0 1)) := by + exact ((gaussianCoordinate_memLp (.inl (i,b))).add + (gaussianCoordinate_memLp (.inl (b,i)))).const_mul _ + +lemma goeEntry_integral_sq_le {r : ℝ} (hr : 0 ≤ r) (i b : ι) : + (∫ g, (goeMatrix r g i b)^2 + ∂Measure.pi (fun _ : MatrixCoordinates ι => gaussianReal 0 1)) ≤ 2*r := by + let μ := Measure.pi (fun _ : MatrixCoordinates ι => gaussianReal 0 1) + have h1 := (gaussianCoordinate_memLp (.inl (i,b))).integrable_sq + have h2 := (gaussianCoordinate_memLp (.inl (b,i))).integrable_sq + have hb (g : MatrixCoordinates ι → ℝ) : (goeMatrix r g i b)^2 ≤ + r*((g (.inl (i,b)))^2+(g (.inl (b,i)))^2) := by + have hx : (g (.inl (i,b))+g (.inl (b,i)))^2 ≤ + 2*((g (.inl (i,b)))^2+(g (.inl (b,i)))^2) := by + nlinarith only [sq_nonneg (g (.inl (i,b))-g (.inl (b,i)))] + simp only [goeMatrix,mul_pow] + calc + _ ≤ (sqrt (2*r)/2)^2*(2*((g (.inl (i,b)))^2+(g (.inl (b,i)))^2)) := + mul_le_mul_of_nonneg_left hx (sq_nonneg _) + _ = _ := by rw [div_pow,sq_sqrt (by positivity)]; ring + calc + _ ≤ ∫ g, r*((g (.inl (i,b)))^2+(g (.inl (b,i)))^2) ∂μ := + integral_mono (goeEntry_memLp r i b).integrable_sq ((h1.add h2).const_mul r) hb + _ = 2*r := by + rw [integral_const_mul,integral_add h1 h2,gaussianCoordinate_integral_sq, + gaussianCoordinate_integral_sq] + ring + +end SKRatioGaussian + +noncomputable section +open MeasureTheory ProbabilityTheory Real Set +open scoped ENNReal NNReal + +end +end +end +end +end +end +end +end +end +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Matrices/GaussianCoordinates.lean b/lean/OAI/Probability/SKRatio/Matrices/GaussianCoordinates.lean new file mode 100644 index 0000000000000000000000000000000000000000..b76b5df445b209034083ecc99facf21454206a01 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Matrices/GaussianCoordinates.lean @@ -0,0 +1,189 @@ +import Mathlib +import OAI.Probability.SKRatio.Matrices.FiniteMax + +namespace OAI + +section +section +noncomputable section +open MeasureTheory ProbabilityTheory InformationTheory Real Set +open scoped NNReal ENNReal +open Filter +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius ENNReal NNReal +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius NNReal +noncomputable section +open MeasureTheory ProbabilityTheory Real Set Filter +open MeasureTheory.Measure +open scoped ENNReal NNReal MeasureTheory Topology +open MeasureTheory +noncomputable section +noncomputable section +open MeasureTheory Set NormedSpace +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius +noncomputable section +open Set Real +open scoped Topology +noncomputable section +open Matrix Set Filter +open scoped Topology Matrix.Norms.Frobenius +noncomputable section +open Matrix NormedSpace ContinuousLinearMap +open scoped Matrix.Norms.Frobenius +noncomputable section +open Matrix +noncomputable section +open MeasureTheory ProbabilityTheory Real Set +open scoped ENNReal NNReal +noncomputable section +open MeasureTheory ProbabilityTheory InformationTheory Real Set +open scoped NNReal ENNReal +namespace SKRatioGaussian +section ArbitraryCoordinates +variable {I κ : Type*} [TopologicalSpace I] [CompactSpace I] [Nonempty I] + [Fintype κ] + +def gaussianCoordinates (κ : Type*) [Fintype κ] : Measure (κ → ℝ) := + Measure.pi (fun _ => gaussianReal 0 1) + +instance : IsProbabilityMeasure (gaussianCoordinates κ) := by + unfold gaussianCoordinates + infer_instance + +def gaussianAffine (m : I → ℝ) (a : I → κ → ℝ) (z : κ → ℝ) (i : I) : ℝ := + m i + ∑ k, a i k * z k + +def gaussianSup (m : I → ℝ) (a : I → κ → ℝ) (z : κ → ℝ) : ℝ := + sSup (Set.range (gaussianAffine m a z)) + +omit [CompactSpace I] [Nonempty I] in + theorem continuous_gaussianAffine {m : I → ℝ} {a : I → κ → ℝ} + (hm : Continuous m) (ha : Continuous a) (z : κ → ℝ) : + Continuous (gaussianAffine m a z) := + hm.add (continuous_finsetSum _ (fun k _ => + ((continuous_apply k).comp ha).mul continuous_const)) + +theorem gaussianSup_attained {m : I → ℝ} {a : I → κ → ℝ} + (hm : Continuous m) (ha : Continuous a) (z : κ → ℝ) : + ∃ i, gaussianSup m a z = gaussianAffine m a z i ∧ + ∀ j, gaussianAffine m a z j ≤ gaussianAffine m a z i := by + obtain ⟨i, _, he, hi⟩ := isCompact_univ.exists_sSup_image_eq_and_ge + Set.univ_nonempty (continuous_gaussianAffine hm ha z).continuousOn + exact ⟨i, by simpa [gaussianSup] using he, fun j => hi j (Set.mem_univ _)⟩ + +theorem gaussianSup_le {m : I → ℝ} {a : I → κ → ℝ} + (hm : Continuous m) (ha : Continuous a) (z : κ → ℝ) {c : ℝ} + (hc : ∀ i, gaussianAffine m a z i ≤ c) : gaussianSup m a z ≤ c := by + obtain ⟨i, he, _⟩ := gaussianSup_attained hm ha z + rw [he] + exact hc i + +omit [Nonempty I] in + theorem continuous_gaussianSup {m : I → ℝ} {a : I → κ → ℝ} + (hm : Continuous m) (ha : Continuous a) : Continuous (gaussianSup m a) := by + have hc : Continuous (fun p : (κ → ℝ) × I => gaussianAffine m a p.1 p.2) := by + exact (hm.comp continuous_snd).add (continuous_finsetSum _ (fun k _ => + (((continuous_apply k).comp ha).comp continuous_snd).mul + ((continuous_apply k).comp continuous_fst))) + change Continuous (fun z => sSup (Set.range (gaussianAffine m a z))) + simpa only [Set.image_univ] using isCompact_univ.continuous_sSup hc + +theorem integrable_gaussianSup {m : I → ℝ} {a : I → κ → ℝ} + (hm : Continuous m) (ha : Continuous a) : + Integrable (gaussianSup m a) (gaussianCoordinates κ) := by + obtain ⟨M, hM⟩ := isCompact_univ.exists_bound_of_continuousOn hm.continuousOn + obtain ⟨A, hA⟩ := isCompact_univ.exists_bound_of_continuousOn ha.continuousOn + have hMb : ∀ i, |m i| ≤ M := fun i => by + simpa only [Real.norm_eq_abs] using hM i (Set.mem_univ _) + have hAb : ∀ i k, |a i k| ≤ A := by + intro i k + have hk : |a i k| ≤ ‖a i‖ := by + simpa only [Real.norm_eq_abs] using norm_le_pi_norm (a i) k + exact hk.trans (hA i (Set.mem_univ _)) + apply ((integrable_const M).add ((integrable_finsetSum (Finset.univ : Finset κ) (fun k _ => + ((integrable_eval (i := k) IsGaussian.integrable_id).norm))).const_mul A)).mono' + (continuous_gaussianSup hm ha).aestronglyMeasurable + apply Filter.Eventually.of_forall + intro z + obtain ⟨i, he, _⟩ := gaussianSup_attained hm ha z + rw [he, Real.norm_eq_abs] + change |gaussianAffine m a z i| ≤ M + A * ∑ k, |z k| + calc + _ ≤ |m i| + |∑ k, a i k * z k| := abs_add_le _ _ + _ ≤ M + ∑ k, |a i k * z k| := + add_le_add (hMb i) (Finset.abs_sum_le_sum_abs _ _) + _ ≤ M + ∑ k, A * |z k| := by + gcongr with k + rw [abs_mul] + exact mul_le_mul_of_nonneg_right (hAb i k) (abs_nonneg _) + _ = _ := by rw [Finset.mul_sum] + +theorem gaussianSup_comparison [Nonempty κ] {m : I → ℝ} {a b : I → κ → ℝ} + (hm : Continuous m) (ha : Continuous a) (hb : Continuous b) + (horth : ∀ i j, ∑ k, (a i k - a j k) * (b i k - b j k) = 0) + (hinc : ∀ i j, (∑ k, (b i k - b j k)^2) ≤ ∑ k, (a i k - a j k)^2) : + (∫ z, gaussianSup m b z ∂gaussianCoordinates κ) ≤ + ∫ z, gaussianSup m a z ∂gaussianCoordinates κ := by + obtain ⟨n, hn⟩ := Nat.exists_eq_succ_of_ne_zero (Fintype.card_ne_zero (α := κ)) + let e : Fin (n + 1) ≃ κ := (finCongr hn.symm).trans (Fintype.equivFin κ).symm + let E := MeasurableEquiv.piCongrLeft (fun _ : κ => ℝ) e + let a' : I → Fin (n + 1) → ℝ := fun i k => a i (e k) + let b' : I → Fin (n + 1) → ℝ := fun i k => b i (e k) + have ha' : Continuous a' := continuous_pi (fun k => (continuous_apply (e k)).comp ha) + have hb' : Continuous b' := continuous_pi (fun k => (continuous_apply (e k)).comp hb) + have he (f : κ → ℝ) : ∑ k : Fin (n + 1), f (e k) = ∑ k : κ, f k := e.sum_comp f + have horth' (i j : I) : ∑ k, (a' i k - a' j k) * (b' i k - b' j k) = 0 := by + dsimp [a', b'] + rw [he (fun k => (a i k - a j k) * (b i k - b j k))] + exact horth i j + have hinc' (i j : I) : (∑ k, (b' i k - b' j k)^2) ≤ ∑ k, (a' i k - a' j k)^2 := by + dsimp [a', b'] + rw [he (fun k => (b i k - b j k)^2), he (fun k => (a i k - a j k)^2)] + exact hinc i j + have hpres : MeasurePreserving E (standardGaussianProduct (n + 1)) (gaussianCoordinates κ) := + measurePreserving_piCongrLeft (fun _ => gaussianReal 0 1) e + have hpoint (c : I → κ → ℝ) (z : Fin (n + 1) → ℝ) : + gaussianSup m c (E z) = supProcess m (fun i k => c i (e k)) z := by + unfold gaussianSup supProcess + congr 1 + congr 1 + funext i + dsimp [gaussianAffine, affineProcess] + rw [← he (fun k => c i k * E z k)] + simp [E, MeasurableEquiv.piCongrLeft, Equiv.piCongrLeft] + rw [← hpres.integral_comp' (gaussianSup m b), ← hpres.integral_comp' (gaussianSup m a)] + simp_rw [hpoint] + exact gaussian_supProcess_comparison hm ha' hb' horth' hinc' + +end ArbitraryCoordinates +end SKRatioGaussian + +noncomputable section +open scoped BigOperators +open MeasureTheory ProbabilityTheory + +end +end +end +end +end +end +end +end +end +end +end +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Matrices/GaussianFiniteIBPError.lean b/lean/OAI/Probability/SKRatio/Matrices/GaussianFiniteIBPError.lean new file mode 100644 index 0000000000000000000000000000000000000000..65f6585dd5b1047631feb9c4d6e413f8f245c4af --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Matrices/GaussianFiniteIBPError.lean @@ -0,0 +1,52 @@ +import Mathlib +import OAI.Probability.SKRatio.Matrices.FiniteCoordinateDeriv + +namespace OAI + +section +section +noncomputable section +open MeasureTheory ProbabilityTheory InformationTheory Real Set +open scoped NNReal ENNReal +open Filter +open scoped Topology +namespace SKRatioGaussian +variable {κ : Type*} [Fintype κ] [DecidableEq κ] + +theorem gaussianFinite_IBP_error (i : κ) + {f d : (κ → ℝ) → ℝ} {L : ℝ≥0} {C D : ℝ} {s : Set (κ → ℝ)} + (hf : LipschitzWith L f) (hC : ∀ x, ‖f x‖ ≤ C) + (hd : Measurable d) (hD : ∀ x, ‖d x‖ ≤ D) (hs : MeasurableSet s) + (hder : ∀ x ∈ s, HasDerivAt (fun z => f (Function.update x i z)) (d x) (x i)) : + |(∫ x, x i*f x ∂Measure.pi (fun _ : κ => gaussianReal 0 1))- + ∫ x, d x ∂Measure.pi (fun _ : κ => gaussianReal 0 1)| ≤ + ((L:ℝ)+D)*(Measure.pi (fun _ : κ => gaussianReal 0 1)).real sᶜ := by + let μ := Measure.pi (fun _ : κ => gaussianReal 0 1) + have hi : Integrable (finiteCoordinateDeriv i f) μ := + Integrable.of_bound (measurable_finiteCoordinateDeriv i hf.continuous).aestronglyMeasurable + (L:ℝ) (ae_of_all _ (norm_finiteCoordinateDeriv_le i hf)) + have hid : Integrable d μ := Integrable.of_bound hd.aestronglyMeasurable D (ae_of_all _ hD) + rw [gaussianFinite_lipschitz_IBP i hf hC,← integral_sub hi hid] + have he : (fun x => finiteCoordinateDeriv i f x-d x) = + sᶜ.indicator (fun x => finiteCoordinateDeriv i f x-d x) := by + funext x + by_cases hx : x ∈ s + · simp only [Set.indicator_of_notMem (show x ∉ sᶜ by simpa using hx),finiteCoordinateDeriv] + rw [(hder x hx).deriv,sub_self] + · rw [Set.indicator_of_mem hx] + rw [he,integral_indicator hs.compl] + exact norm_setIntegral_le_of_norm_le_const (measure_lt_top μ sᶜ) (fun x _ => + (norm_sub_le _ _).trans (add_le_add (norm_finiteCoordinateDeriv_le i hf x) (hD x))) + +end SKRatioGaussian + +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius ENNReal NNReal + +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Matrices/GaussianProductIntegral.lean b/lean/OAI/Probability/SKRatio/Matrices/GaussianProductIntegral.lean new file mode 100644 index 0000000000000000000000000000000000000000..56986b0c5689304252fb9d4e4d4c40072f5c79c0 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Matrices/GaussianProductIntegral.lean @@ -0,0 +1,75 @@ +import Mathlib +import OAI.Probability.SKRatio.Matrices.PowExponentialPair + +namespace OAI + +section +section +noncomputable section +open MeasureTheory ProbabilityTheory InformationTheory Real Set +open scoped NNReal ENNReal +open Filter +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius ENNReal NNReal +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius NNReal +noncomputable section +open MeasureTheory ProbabilityTheory Real Set Filter +open MeasureTheory.Measure +open scoped ENNReal NNReal MeasureTheory Topology +namespace SKRatioGaussian +open MeasureTheory ProbabilityTheory Real +open scoped Topology +section ProductMoments +variable {κ : Type*} [Fintype κ] + +lemma gaussianProduct_integral (F : EuclideanSpace ℝ κ → ℝ) (hF : Continuous F) : + (∫ g : κ → ℝ, F (WithLp.toLp 2 g) ∂Measure.pi (fun _ => gaussianReal 0 1)) = + ∫ x, F x ∂stdGaussian (EuclideanSpace ℝ κ) := by + rw [← map_pi_eq_stdGaussian] + exact (integral_map (by fun_prop) hF.aestronglyMeasurable).symm + +lemma gaussianProduct_integrable_lipschitz {F : EuclideanSpace ℝ κ → ℝ} + {L : ℝ≥0} (hF : LipschitzWith L F) : + Integrable (fun g : κ → ℝ => F (WithLp.toLp 2 g)) + (Measure.pi (fun _ => gaussianReal 0 1)) := by + have hi := gaussian_integrable_lipschitz (μ := stdGaussian (EuclideanSpace ℝ κ)) hF + rw [← map_pi_eq_stdGaussian] at hi + exact hi.comp_measurable (by fun_prop) + +lemma gaussianProduct_abs_centered_moment {F : EuclideanSpace ℝ κ → ℝ} + {L : ℝ≥0} (hF : LipschitzWith L F) (hL : 0 < L) (k : ℕ) : + (∫ g : κ → ℝ, |F (WithLp.toLp 2 g)- + ∫ h : κ → ℝ, F (WithLp.toLp 2 h) ∂Measure.pi (fun _ => gaussianReal 0 1)|^k + ∂Measure.pi (fun _ => gaussianReal 0 1)) ≤ + (2*(k.factorial : ℝ)*exp (π^2/8))*(L:ℝ)^k := by + rw [gaussianProduct_integral F hF.continuous] + rw [gaussianProduct_integral (fun x => |F x-∫ y, F y ∂stdGaussian _|^k) ((hF.continuous.sub continuous_const).abs.pow k)] + exact stdGaussian_abs_centered_moment hF hL k + +lemma gaussianProduct_centered_L1 {F : EuclideanSpace ℝ κ → ℝ} + {L : ℝ≥0} (hF : LipschitzWith L F) (hL : 0 < L) : + (∫ g : κ → ℝ, |F (WithLp.toLp 2 g)- + ∫ h : κ → ℝ, F (WithLp.toLp 2 h) ∂Measure.pi (fun _ => gaussianReal 0 1)| + ∂Measure.pi (fun _ => gaussianReal 0 1)) ≤ + (2*exp (π^2/8))*(L:ℝ) := by + simpa using gaussianProduct_abs_centered_moment hF hL 1 + +end ProductMoments +end SKRatioGaussian + +open MeasureTheory +noncomputable section + +end +end +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Matrices/GaussianProductUpperTailLipschitz.lean b/lean/OAI/Probability/SKRatio/Matrices/GaussianProductUpperTailLipschitz.lean new file mode 100644 index 0000000000000000000000000000000000000000..a9366eb407af76020cd988908870cd82449ec3e0 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Matrices/GaussianProductUpperTailLipschitz.lean @@ -0,0 +1,105 @@ +import Mathlib +import OAI.Probability.SKRatio.Matrices.StdGaussianMgfLipschitz + +namespace OAI + +section +section +noncomputable section +open MeasureTheory ProbabilityTheory InformationTheory Real Set +open scoped NNReal ENNReal +open Filter +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius ENNReal NNReal +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius NNReal +noncomputable section +open MeasureTheory ProbabilityTheory Real Set Filter +open MeasureTheory.Measure +open scoped ENNReal NNReal MeasureTheory Topology +open MeasureTheory +noncomputable section +noncomputable section +open MeasureTheory Set NormedSpace +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius +noncomputable section +open Set Real +open scoped Topology +noncomputable section +open Matrix Set Filter +open scoped Topology Matrix.Norms.Frobenius +noncomputable section +open Matrix NormedSpace ContinuousLinearMap +open scoped Matrix.Norms.Frobenius +noncomputable section +open Matrix +noncomputable section +open MeasureTheory ProbabilityTheory Real Set +open scoped ENNReal NNReal +noncomputable section +open MeasureTheory ProbabilityTheory InformationTheory Real Set +open scoped NNReal ENNReal +noncomputable section +open scoped BigOperators +open MeasureTheory ProbabilityTheory +open Real +namespace SKRatioGaussian +section ProductGaussianConcentration +variable {κ : Type*} [Fintype κ] + +theorem gaussianProduct_upper_tail_lipschitz {f : (κ → ℝ) → ℝ} {L : ℝ≥0} + (hf : LipschitzWith L (fun x : EuclideanSpace ℝ κ => f x.ofLp)) + (hL : 0 < L) {u : ℝ} (hu : 0 ≤ u) : + (Measure.pi (fun _ : κ => gaussianReal 0 1)).real + {x | u ≤ f x - ∫ y, f y ∂Measure.pi (fun _ : κ => gaussianReal 0 1)} ≤ + Real.exp (-2*u^2/(π^2*(L:ℝ)^2)) := by + let e : (κ → ℝ) ≃ᵐ EuclideanSpace ℝ κ := MeasurableEquiv.toLp 2 _ + have hp : MeasurePreserving e (Measure.pi (fun _ : κ => gaussianReal 0 1)) + (stdGaussian (EuclideanSpace ℝ κ)) := + ⟨e.measurable, map_pi_eq_stdGaussian⟩ + have hi := hp.integral_comp' (fun x : EuclideanSpace ℝ κ => f x.ofLp) + change (∫ x, f x ∂Measure.pi (fun _ : κ => gaussianReal 0 1)) = _ at hi + have h := stdGaussian_upper_tail_lipschitz hf hL hu + rw [← hi] at h + have hs : MeasurableSet {x : EuclideanSpace ℝ κ | + u ≤ f x.ofLp - ∫ y, f y ∂Measure.pi (fun _ : κ => gaussianReal 0 1)} := + measurableSet_le measurable_const (hf.continuous.measurable.sub_const _) + have he := hp.measure_preimage hs.nullMeasurableSet + have her := congrArg ENNReal.toReal he + change (Measure.pi (fun _ : κ => gaussianReal 0 1)).real + {x | u ≤ f x - ∫ y, f y ∂Measure.pi (fun _ : κ => gaussianReal 0 1)} = _ at her + rw [her] + exact h + +end ProductGaussianConcentration +end SKRatioGaussian + +noncomputable section +open scoped BigOperators Topology +open Filter Real + +end +end +end +end +end +end +end +end +end +end +end +end +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Matrices/GaussianQuadratic.lean b/lean/OAI/Probability/SKRatio/Matrices/GaussianQuadratic.lean new file mode 100644 index 0000000000000000000000000000000000000000..f17946d03ac93cec132a011ee5d4e00463891aec --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Matrices/GaussianQuadratic.lean @@ -0,0 +1,203 @@ +import Mathlib +import OAI.Probability.SKRatio.Matrices.StandardGaussianProduct + +namespace OAI + +section +section +noncomputable section +open MeasureTheory ProbabilityTheory InformationTheory Real Set +open scoped NNReal ENNReal +open Filter +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius ENNReal NNReal +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius NNReal +noncomputable section +open MeasureTheory ProbabilityTheory Real Set Filter +open MeasureTheory.Measure +open scoped ENNReal NNReal MeasureTheory Topology +open MeasureTheory +noncomputable section +noncomputable section +open MeasureTheory Set NormedSpace +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius +noncomputable section +open Set Real +open scoped Topology +noncomputable section +open Matrix Set Filter +open scoped Topology Matrix.Norms.Frobenius +noncomputable section +open Matrix NormedSpace ContinuousLinearMap +open scoped Matrix.Norms.Frobenius +noncomputable section +open Matrix +noncomputable section +open MeasureTheory ProbabilityTheory Real Set +open scoped ENNReal NNReal +noncomputable section +open MeasureTheory ProbabilityTheory InformationTheory Real Set +open scoped NNReal ENNReal +noncomputable section +open scoped BigOperators +open MeasureTheory ProbabilityTheory +open Real +namespace SKRatioGaussian +open scoped BigOperators + +lemma gaussian_integrable_pow (k : ℕ) : + Integrable (fun x : ℝ => x^k) (gaussianReal 0 1) := by + apply (integrable_norm_iff (by fun_prop)).mp + simpa only [id_eq, norm_pow] using + (IsGaussian.memLp_id (gaussianReal 0 1) (k : ℝ≥0∞) (by simp)).integrable_norm_pow' + +lemma gaussian_memLp_sq : MemLp (fun x : ℝ => x^2) 2 (gaussianReal 0 1) := by + apply (memLp_two_iff_integrable_sq (by fun_prop)).mpr + simpa only [← pow_mul] using gaussian_integrable_pow 4 + +lemma gaussian_integral_sq : (∫ x : ℝ, x^2 ∂gaussianReal 0 1) = 1 := by + have h := variance_fun_id_gaussianReal (μ := 0) (v := 1) + rw [variance_eq_integral (by fun_prop), integral_id_gaussianReal] at h + simpa only [sub_zero, NNReal.coe_one] using h + +lemma gaussian_integral_fourth : (∫ x : ℝ, x^4 ∂gaussianReal 0 1) = 3 := by + have hd (x : ℝ) : HasDerivAt (fun x : ℝ => x^3) (3*x^2) x := by + convert! (hasDerivAt_id x).pow 3 using 1; norm_num [Pi.pow_apply, id_eq] + have hi : Integrable (fun x : ℝ => (x - 0)*x^3) (gaussianReal 0 1) := by + simpa only [sub_zero, ← pow_succ'] using gaussian_integrable_pow 4 + have h := gaussian_integration_by_parts (by norm_num : (1 : ℝ≥0) ≠ 0) + hd (gaussian_integrable_pow 3) ((gaussian_integrable_pow 2).const_mul 3) hi + simpa only [sub_zero, ← pow_succ', integral_const_mul, gaussian_integral_sq, + NNReal.coe_one, one_mul, mul_one] using h + +lemma gaussian_variance_sq : Var[fun x : ℝ => x^2; gaussianReal 0 1] = 2 := by + rw [variance_eq_sub gaussian_memLp_sq] + simp only [Pi.pow_apply, ← pow_mul, gaussian_integral_fourth, gaussian_integral_sq] + norm_num + +section Quadratic +variable {ι : Type*} [Fintype ι] + +def gaussianQuadratic (a : ι → ℝ) (x : ι → ℝ) : ℝ := ∑ i, a i * (x i)^2 + +lemma gaussianQuadratic_memLp (a : ι → ℝ) : + MemLp (gaussianQuadratic a) 2 (Measure.pi (fun _ : ι => gaussianReal 0 1)) := by + apply memLp_finsetSum + intro i _ + exact ((gaussian_memLp_sq.const_mul (a i)).comp_measurePreserving + (measurePreserving_eval (fun _ : ι => gaussianReal 0 1) i)) + +lemma gaussianQuadratic_mean (a : ι → ℝ) : + (∫ x, gaussianQuadratic a x ∂Measure.pi (fun _ : ι => gaussianReal 0 1)) = ∑ i, a i := by + unfold gaussianQuadratic + have hi (i : ι) : Integrable (fun x : ι → ℝ => a i * (x i)^2) + (Measure.pi (fun _ : ι => gaussianReal 0 1)) := + ((gaussian_memLp_sq.const_mul (a i)).comp_measurePreserving + (measurePreserving_eval (fun _ : ι => gaussianReal 0 1) i)).integrable (by norm_num) + rw [integral_finsetSum _ (fun i _ => hi i)] + apply Finset.sum_congr rfl + intro i _ + rw [integral_const_mul] + have he : (∫ x : ι → ℝ, (x i)^2 ∂Measure.pi (fun _ : ι => gaussianReal 0 1)) = + ∫ y : ℝ, y^2 ∂gaussianReal 0 1 := + integral_comp_eval (μ := fun _ : ι => gaussianReal 0 1) (i := i) + (f := fun y : ℝ => y^2) (by fun_prop) + rw [he, gaussian_integral_sq, mul_one] + +lemma gaussianQuadratic_variance (a : ι → ℝ) : + Var[gaussianQuadratic a; Measure.pi (fun _ : ι => gaussianReal 0 1)] = + 2 * ∑ i, (a i)^2 := by + have h : Var[gaussianQuadratic a; Measure.pi (fun _ : ι => gaussianReal 0 1)] = + ∑ i, Var[fun x : ℝ => a i * x^2; gaussianReal 0 1] := by + convert variance_sum_pi (fun i : ι => gaussian_memLp_sq.const_mul (a i)) using 1 + congr 1 + funext x + simp only [gaussianQuadratic, Finset.sum_apply] + rw [h] + simp only [variance_const_mul, gaussian_variance_sq, ← Finset.sum_mul] + ring + +end Quadratic + +lemma sqrt_sub_sq_le_abs_sub {x y : ℝ} (hx : 0 ≤ x) (hy : 0 ≤ y) : + (sqrt x - sqrt y)^2 ≤ |x-y| := by + have hx2 := sq_sqrt hx + have hy2 := sq_sqrt hy + rcases le_total x y with h | h + · rw [abs_of_nonpos (sub_nonpos.mpr h)] + have hh := sqrt_le_sqrt h + nlinarith [mul_nonneg (sqrt_nonneg x) (sub_nonneg.mpr hh)] + · rw [abs_of_nonneg (sub_nonneg.mpr h)] + have hh := sqrt_le_sqrt h + nlinarith [mul_nonneg (sqrt_nonneg y) (sub_nonneg.mpr hh)] + +section Fluctuation +variable {Ω : Type*} [MeasurableSpace Ω] {μ : Measure Ω} [IsProbabilityMeasure μ] + +omit [IsProbabilityMeasure μ] in +lemma memLp_sqrt_of_nonneg {f : Ω → ℝ} (hf : Integrable f μ) + (hpos : ∀ x, 0 ≤ f x) : MemLp (fun x => sqrt (f x)) 2 μ := by + apply (memLp_two_iff_integrable_sq + (Real.continuous_sqrt.comp_aestronglyMeasurable hf.aestronglyMeasurable)).mpr + exact hf.congr (Filter.Eventually.of_forall (fun x => (sq_sqrt (hpos x)).symm)) + +lemma integral_abs_le_sqrt_sq {f : Ω → ℝ} (hf : MemLp f 2 μ) : + (∫ x, |f x| ∂μ) ≤ sqrt (∫ x, (f x)^2 ∂μ) := by + have h0 := ProbabilityTheory.variance_nonneg (fun x => ‖f x‖) μ + rw [variance_eq_sub hf.norm] at h0 + have hsq : (∫ x, |f x| ∂μ)^2 ≤ ∫ x, (f x)^2 ∂μ := by + simpa only [Real.norm_eq_abs, Pi.pow_apply, sq_abs, sub_nonneg] using h0 + have hi : 0 ≤ ∫ x, (f x)^2 ∂μ := integral_nonneg (fun x => sq_nonneg _) + have hh := sq_sqrt hi + have hp := sqrt_nonneg (∫ x, (f x)^2 ∂μ) + nlinarith [sq_nonneg ((∫ x, |f x| ∂μ) - sqrt (∫ x, (f x)^2 ∂μ))] + +theorem integral_sqrt_fluctuation {f : Ω → ℝ} (hf : MemLp f 2 μ) + (hpos : ∀ x, 0 ≤ f x) : + (∫ x, |sqrt (f x) - sqrt (∫ y, f y ∂μ)| ∂μ) ≤ sqrt (sqrt (Var[f; μ])) := by + let m := ∫ y, f y ∂μ + have hm : 0 ≤ m := integral_nonneg hpos + have hg : MemLp (fun x => f x - m) 2 μ := hf.sub (memLp_const m) + have hroot : MemLp (fun x => sqrt (f x) - sqrt m) 2 μ := by + apply (memLp_two_iff_integrable_sq ((Real.continuous_sqrt.comp_aestronglyMeasurable hf.aestronglyMeasurable).sub aestronglyMeasurable_const)).mpr + apply hg.integrable (by norm_num) |>.norm |>.mono' + (((Real.continuous_sqrt.comp_aestronglyMeasurable hf.aestronglyMeasurable).sub aestronglyMeasurable_const).pow 2) + filter_upwards [] with x + change |(sqrt (f x) - sqrt m)^2| ≤ |f x - m| + rw [abs_of_nonneg (sq_nonneg (sqrt (f x) - sqrt m))] + exact sqrt_sub_sq_le_abs_sub (hpos x) hm + have hdiff : (∫ x, (sqrt (f x) - sqrt m)^2 ∂μ) ≤ ∫ x, |f x-m| ∂μ := by + apply integral_mono hroot.integrable_sq (hg.integrable (by norm_num)).norm + exact fun x => sqrt_sub_sq_le_abs_sub (hpos x) hm + have hc := integral_abs_le_sqrt_sq hg + rw [← variance_eq_integral hf.aemeasurable] at hc + exact (integral_abs_le_sqrt_sq hroot).trans (sqrt_le_sqrt (hdiff.trans hc)) + +end Fluctuation +end SKRatioGaussian + +end +end +end +end +end +end +end +end +end +end +end +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Matrices/GaussianQuadraticSupComparison.lean b/lean/OAI/Probability/SKRatio/Matrices/GaussianQuadraticSupComparison.lean new file mode 100644 index 0000000000000000000000000000000000000000..2d1f83d86b6fc010b52c805c741fe19bb285e58c --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Matrices/GaussianQuadraticSupComparison.lean @@ -0,0 +1,102 @@ +import Mathlib +import OAI.Probability.SKRatio.Matrices.GaussianCoordinates +import OAI.Probability.SKRatio.Matrices.QuadraticCoeff + +namespace OAI + +section +section +noncomputable section +open MeasureTheory ProbabilityTheory InformationTheory Real Set +open scoped NNReal ENNReal +open Filter +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius ENNReal NNReal +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius NNReal +noncomputable section +open MeasureTheory ProbabilityTheory Real Set Filter +open MeasureTheory.Measure +open scoped ENNReal NNReal MeasureTheory Topology +open MeasureTheory +noncomputable section +noncomputable section +open MeasureTheory Set NormedSpace +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius +noncomputable section +open Set Real +open scoped Topology +noncomputable section +open Matrix Set Filter +open scoped Topology Matrix.Norms.Frobenius +noncomputable section +open Matrix NormedSpace ContinuousLinearMap +open scoped Matrix.Norms.Frobenius +noncomputable section +open Matrix +noncomputable section +open MeasureTheory ProbabilityTheory Real Set +open scoped ENNReal NNReal +noncomputable section +open MeasureTheory ProbabilityTheory InformationTheory Real Set +open scoped NNReal ENNReal +noncomputable section +open scoped BigOperators +open MeasureTheory ProbabilityTheory +namespace SKRatioGaussian +section QuadraticComparison +variable {I ι : Type*} [TopologicalSpace I] [CompactSpace I] [Nonempty I] + [Fintype ι] [Nonempty ι] + +theorem gaussian_quadraticSup_comparison {m : I → ℝ} + {w : I → EuclideanSpace ℝ ι} (hm : Continuous m) (hw : Continuous w) + {r : ℝ} (hr : 0 ≤ r) (z : ℝ) : + (∫ g, gaussianSup m (fun i k => z * quadraticCoeff r (w i) k) g + ∂gaussianCoordinates (MatrixCoordinates ι)) ≤ + ∫ g, gaussianSup m (fun i k => z * linearCoeff r (w i) k) g + ∂gaussianCoordinates (MatrixCoordinates ι) := by + have hc {q : EuclideanSpace ℝ ι → MatrixCoordinates ι → ℝ} (hq : Continuous q) : + Continuous (fun i k => z * q (w i) k) := by + apply continuous_pi + intro k + exact continuous_const.mul ((continuous_apply k).comp (hq.comp hw)) + apply gaussianSup_comparison hm (hc (continuous_linearCoeff r)) + (hc (continuous_quadraticCoeff r)) + · intro i j + simp_rw [← mul_sub] + simp_rw [show ∀ k, (z * (linearCoeff r (w i) k - linearCoeff r (w j) k)) * + (z * (quadraticCoeff r (w i) k - quadraticCoeff r (w j) k)) = + z^2 * ((linearCoeff r (w i) k - linearCoeff r (w j) k) * + (quadraticCoeff r (w i) k - quadraticCoeff r (w j) k)) by intros; ring] + rw [← Finset.mul_sum, quadratic_linear_orthogonal, mul_zero] + · intro i j + simp_rw [← mul_sub, mul_pow, ← Finset.mul_sum] + exact mul_le_mul_of_nonneg_left (quadratic_linear_increment_le r hr (w i) (w j)) + (sq_nonneg z) +end QuadraticComparison +end SKRatioGaussian + +end +end +end +end +end +end +end +end +end +end +end +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Matrices/GaussianRows.lean b/lean/OAI/Probability/SKRatio/Matrices/GaussianRows.lean new file mode 100644 index 0000000000000000000000000000000000000000..5588982a9ed06cb2f90dbc7cc225953483dd6b6c --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Matrices/GaussianRows.lean @@ -0,0 +1,145 @@ +import Mathlib +import OAI.Probability.SKRatio.Matrices.GaussianQuadratic +import OAI.Probability.SKRatio.Matrices.GaussianProductUpperTailLipschitz +import OAI.Probability.SKRatio.Matrices.GaussianTails + +namespace OAI + +section +noncomputable section +open MeasureTheory ProbabilityTheory Real Filter +open scoped BigOperators Topology +namespace SKRatioGaussian +variable {κ : Type*} [Fintype κ] + +lemma gaussian_coordinates_norm_mean : + (∫ x : κ → ℝ, ‖WithLp.toLp 2 x‖ ∂gaussianCoordinates κ) ≤ + sqrt (Fintype.card κ) := by + have hsq (x : κ → ℝ) : ‖WithLp.toLp 2 x‖^2 = gaussianQuadratic (fun _ => 1) x := by + simp only [EuclideanSpace.norm_sq_eq, Real.norm_eq_abs, sq_abs, + gaussianQuadratic, one_mul] + have hnorm (x : κ → ℝ) : ‖WithLp.toLp 2 x‖ = sqrt (gaussianQuadratic (fun _ => 1) x) := by + rw [←hsq, sqrt_sq (norm_nonneg _)] + have hi : MemLp (fun x : κ → ℝ => ‖WithLp.toLp 2 x‖) 2 (gaussianCoordinates κ) := by + simp_rw [hnorm] + exact memLp_sqrt_of_nonneg ((gaussianQuadratic_memLp (fun _ : κ => 1)).integrable (by norm_num)) + (fun x => Finset.sum_nonneg (fun i _ => by positivity)) + have hb := integral_abs_le_sqrt_sq hi + simp only [abs_of_nonneg (norm_nonneg _),hsq,gaussianCoordinates,gaussianQuadratic_mean, + Finset.sum_const,Finset.card_univ,nsmul_eq_mul,mul_one] at hb + exact hb + +lemma scaled_gaussian_radius_tail {r b R : ℝ} (hr : 0 < r) + (hb : sqrt r * sqrt (Fintype.card κ) ≤ b) (hR : b ≤ R) : + (Measure.pi (fun _ : κ => gaussianReal 0 (Real.toNNReal r))).real + {v | R < ‖WithLp.toLp 2 v‖} ≤ + exp (-2*(R-b)^2/(Real.pi^2*r)) := by + let f : (κ → ℝ) → ℝ := fun x => sqrt r * ‖WithLp.toLp 2 x‖ + have hi : Integrable (fun x : κ → ℝ => ‖WithLp.toLp 2 x‖) (gaussianCoordinates κ) := by + have hsq (x : κ → ℝ) : ‖WithLp.toLp 2 x‖ = sqrt (gaussianQuadratic (fun _ => 1) x) := by + simp only [EuclideanSpace.norm_eq, Real.norm_eq_abs,sq_abs, + gaussianQuadratic,one_mul] + simp_rw [hsq] + exact (memLp_sqrt_of_nonneg ((gaussianQuadratic_memLp (fun _ : κ => 1)).integrable (by norm_num)) + (fun x => Finset.sum_nonneg (fun i _ => by positivity))).integrable (by norm_num) + have hm : (∫ x, f x ∂gaussianCoordinates κ) ≤ b := by + change (∫ x : κ → ℝ, sqrt r * ‖WithLp.toLp 2 x‖ ∂gaussianCoordinates κ) ≤ b + rw [integral_const_mul] + exact (mul_le_mul_of_nonneg_left gaussian_coordinates_norm_mean (sqrt_nonneg r)).trans hb + have hl : LipschitzWith (Real.toNNReal (sqrt r)) + (fun x : EuclideanSpace ℝ κ => f x.ofLp) := by + apply LipschitzWith.of_dist_le_mul + intro x y + change dist (sqrt r * ‖x‖) (sqrt r * ‖y‖) ≤ _ + rw [Real.dist_eq, ←mul_sub, abs_mul,abs_of_nonneg (sqrt_nonneg r), + Real.coe_toNNReal _ (sqrt_nonneg r)] + exact mul_le_mul_of_nonneg_left (abs_norm_sub_norm_le x y) (sqrt_nonneg r) + have ht := gaussianProduct_upper_tail_lipschitz hl + (Real.toNNReal_pos.mpr (sqrt_pos.mpr hr)) (sub_nonneg.mpr hR) + rw [Real.coe_toNNReal _ (sqrt_nonneg r),sq_sqrt hr.le] at ht + have he : MeasurableSet {v : κ → ℝ | R < ‖WithLp.toLp 2 v‖} := by + apply measurableSet_lt measurable_const + exact (continuous_norm.comp (PiLp.continuous_toLp 2 (fun _ : κ => ℝ))).measurable + rw [←(gaussian_scaled_coordinates_hasLaw (κ := κ) hr.le).measureReal_eq he] + apply (measureReal_mono (s₂ := {x : κ → ℝ | R-b ≤ f x - ∫ y, f y ∂gaussianCoordinates κ}) ?_).trans ht + intro x hx + have heq : WithLp.toLp 2 (fun i => sqrt r * x i) = + sqrt r • (WithLp.toLp 2 x : EuclideanSpace ℝ κ) := rfl + change R < ‖WithLp.toLp 2 (fun i => sqrt r * x i)‖ at hx + rw [heq,norm_smul,Real.norm_eq_abs,abs_of_nonneg (sqrt_nonneg r)] at hx + change R-b ≤ f x - ∫ y, f y ∂gaussianCoordinates κ + dsimp [f] at * + linarith + +variable {n : ℕ} + +lemma coupling_goe_row_tight_tail {j δ : ℝ} (hj : 0 < j) (hδ : 0 ≤ δ) + (i : Fin n) : + (gaussianCoordinates (MatrixCoordinates (Fin n))).real + {g | j+δ < ∑ k, coupling (goeDisorder (j/(n:ℝ)) g) i k^2} ≤ + exp (-(2*(sqrt (j+δ)-sqrt j)^2/(Real.pi^2*j))*(n:ℝ)) := by + classical + have hn : (0:ℝ) < n := Nat.cast_pos.mpr (Nat.pos_of_ne_zero (fun hn => by simpa [hn] using i.isLt)) + let S : Finset (Fin n) := Finset.univ.erase i + let e : S ↪ Fin n := ⟨Subtype.val,Subtype.val_injective⟩ + have havoid (k : S) : e k ≠ i := Finset.ne_of_mem_erase k.2 + have hsum (g : MatrixCoordinates (Fin n) → ℝ) : + (∑ k, coupling (goeDisorder (j/(n:ℝ)) g) i k^2) = + ∑ k : S, goeMatrix (j/(n:ℝ)) g i k^2 := + coupling_goe_row_square_sum (j/(n:ℝ)) g i Finset.univ + simp_rw [hsum] + have hm : MeasurableSet {v : S → ℝ | j+δ < ∑ k, v k^2} := by measurability + have hl := (goe_row_hasLaw (div_nonneg hj.le hn.le) i e havoid).measureReal_eq hm + change (gaussianCoordinates (MatrixCoordinates (Fin n))).real + {g | j+δ < ∑ k : S, goeMatrix (j/(n:ℝ)) g i k^2} = + (Measure.pi (fun _ : S => gaussianReal 0 (Real.toNNReal (j/(n:ℝ))))).real + {v | j+δ < ∑ k, v k^2} at hl + rw [hl] + have heq : {v : S → ℝ | j+δ < ∑ k, v k^2} = + {v : S → ℝ | sqrt (j+δ) < ‖WithLp.toLp 2 v‖} := by + ext v + have hnrm : ‖WithLp.toLp 2 v‖^2 = ∑ k, v k^2 := by + simp only [EuclideanSpace.norm_sq_eq,Real.norm_eq_abs,sq_abs] + simp only [Set.mem_ofPred_eq] + calc + j+δ < ∑ k, v k^2 ↔ sqrt (j+δ)^2 < ‖WithLp.toLp 2 v‖^2 := by + rw [hnrm,sq_sqrt (by positivity : 0 ≤ j+δ)] + _ ↔ _ := sq_lt_sq₀ (sqrt_nonneg (j+δ)) + (norm_nonneg (WithLp.toLp 2 v : EuclideanSpace ℝ S)) + rw [heq] + have hcard : (Fintype.card S : ℝ) ≤ n := by + rw [Fintype.card_coe] + exact_mod_cast ((Finset.card_erase_le (s := Finset.univ) (a := i)).trans + (by simp)) + have hb : sqrt (j/(n:ℝ))*sqrt (Fintype.card S) ≤ sqrt j := by + rw [←sqrt_mul (by positivity : 0 ≤ j/(n:ℝ))] + apply sqrt_le_sqrt + calc + _ ≤ (j/(n:ℝ))*(n:ℝ) := mul_le_mul_of_nonneg_left hcard (by positivity) + _ = j := div_mul_cancel₀ j hn.ne' + have ht := scaled_gaussian_radius_tail (κ := S) (div_pos hj hn) hb + (sqrt_le_sqrt (by linarith : j ≤ j+δ)) + apply ht.trans_eq + congr 1 + field_simp + +lemma coupling_goe_all_rows_tight_tail {n : ℕ} (_hn : 0 < n) {j δ : ℝ} + (hj : 0 < j) (hδ : 0 ≤ δ) : + (gaussianCoordinates (MatrixCoordinates (Fin n))).real + {g | ∃ i, j+δ < ∑ k, coupling (goeDisorder (j/(n:ℝ)) g) i k^2} ≤ + (n:ℝ)*exp (-(2*(sqrt (j+δ)-sqrt j)^2/(Real.pi^2*j))*(n:ℝ)) := by + have he : {g : MatrixCoordinates (Fin n) → ℝ | ∃ i, + j+δ < ∑ k, coupling (goeDisorder (j/(n:ℝ)) g) i k^2} = + ⋃ i : Fin n, {g | j+δ < ∑ k, coupling (goeDisorder (j/(n:ℝ)) g) i k^2} := by + ext g; simp + rw [he] + apply (measureReal_iUnion_fintype_le _).trans + apply (Finset.sum_le_sum (fun i _ => coupling_goe_row_tight_tail hj hδ i)).trans_eq + simp + +end SKRatioGaussian + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Matrices/GaussianSquareMatrix.lean b/lean/OAI/Probability/SKRatio/Matrices/GaussianSquareMatrix.lean new file mode 100644 index 0000000000000000000000000000000000000000..13af56862ac34b14713e38ba18bf34a07834545e --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Matrices/GaussianSquareMatrix.lean @@ -0,0 +1,356 @@ +import Mathlib +import OAI.Probability.SKRatio.Matrices.RandomMatrixBounded +import OAI.Probability.SKRatio.Gaussian.ExponentialBounds +import OAI.Probability.SKRatio.Matrices.GaussianSquareTails + +namespace OAI + +section +noncomputable section +open scoped BigOperators NNReal ENNReal Topology +open MeasureTheory ProbabilityTheory Filter Set Real +namespace SKRatio.MatrixNet +open SKRatioClock.Regression +attribute [local instance] Classical.propDecidable + +lemma independent_sum_upper_tail {Ω ι : Type*} [MeasurableSpace Ω] + {μ : Measure Ω} [IsProbabilityMeasure μ] (X : ι → Ω → ℝ) + (hXi : iIndepFun X μ) (hXm : ∀ i, Measurable (X i)) + (s : Finset ι) {t M : ℝ} (ht : 0 exp (t*X i ω)) μ) + (hmgf : ∀ i ∈ s, cgf (X i) μ t ≤ M) (hM : 0≤M) + {n : ℕ} (hn : 0 log (∫ z, exp (squareTail R z/4) ∂gaussianReal 0 1)) + atTop (𝓝 0) := by + simpa only [Function.comp_def,log_one] using (continuousAt_log (by norm_num : (1:ℝ)≠0)).tendsto.comp + (tendsto_squareTail_mgf gaussian_integrable_exp_quarter_sq) + have hsq : Integrable (fun z : ℝ => z^2) (gaussianReal 0 1) := by + simpa only [id_eq] using (IsGaussian.memLp_two_id (μ := gaussianReal 0 1)).integrable_sq + have hm : Tendsto (fun R : ℕ => ∫ z, squareTail R z ∂gaussianReal 0 1) atTop (𝓝 0) := by + have hb := tendsto_integral_of_dominated_convergence (fun z : ℝ => z^2) + (μ := gaussianReal 0 1) + (F := fun R : ℕ => squareTail R) (f := fun _ => (0:ℝ)) + (fun R => (measurable_squareTail R).aestronglyMeasurable) hsq + have h := hb (fun R => ae_of_all _ (fun z => by + rw [Real.norm_eq_abs,abs_of_nonneg (squareTail_nonneg _ _)] + exact squareTail_le _ _)) (ae_of_all _ (fun z => by + apply tendsto_const_nhds.congr' + filter_upwards [eventually_ge_atTop ⌈|z|⌉₊] with R hR + have hz : |z| ≤ (R:ℝ) := (Nat.le_ceil _).trans (by exact_mod_cast hR) + simp [squareTail,not_lt.mpr hz])) + simpa using h + obtain ⟨R,hR,hmg,hmean⟩ := ((eventually_ge_atTop 1).and + ((ht.eventually (gt_mem_nhds (by positivity : (0:ℝ) squareTail R (z i)) (standardArrayLaw ι) (1/4) = M := by + unfold cgf mgf M + congr 1 + have hh := (coordinate_hasLaw i).integral_comp (f := fun z : ℝ => exp (squareTail R z/4)) (((measurable_squareTail R).div_const 4).exp.aestronglyMeasurable) + simpa only [one_div_mul_eq_div, Function.comp_def] using hh + have hi (i : ι) : Integrable (fun z : ι → ℝ => exp ((1/4)*squareTail R (z i))) (standardArrayLaw ι) := by + have hh := integrable_exp_squareTail gaussian_integrable_exp_quarter_sq (R:ℝ) + rw [←(coordinate_hasLaw i).map_eq] at hh + have h := (integrable_map_measure (((measurable_squareTail R).div_const 4).exp.aestronglyMeasurable) (coordinate_hasLaw i).aemeasurable).mp hh + simpa only [one_div_mul_eq_div, Function.comp_def] using h + have hb := independent_sum_upper_tail (fun i (z : ι → ℝ) => squareTail R (z i)) + (coordinates_independent.comp (fun _ => squareTail R) (fun _ => measurable_squareTail R)) + (fun i => (measurable_squareTail R).comp (measurable_pi_apply i)) s + (by norm_num : (0:ℝ)<1/4) (fun i _ => hi i) (fun i _ => le_of_eq (hc i)) hM hn hs a + simpa only [one_div_mul_eq_div,neg_mul] using hb + +def incidentEdges {n : ℕ} (i : Fin n) : Finset (Edge n) := + Finset.univ.filter (fun e => e.1.1 = i ∨ e.1.2 = i) + +lemma incidentEdges_card_le {n : ℕ} (i : Fin n) : (incidentEdges i).card ≤ n := by + let other (e : Edge n) : Fin n := if e.1.1 = i then e.1.2 else e.1.1 + have h := Finset.card_le_card_of_injOn other + (t := (Finset.univ : Finset (Fin n))) (s := incidentEdges i) + (fun _ _ => Finset.mem_univ _) (by + intro e he f hf hef + have he' : e.1.1 = i ∨ e.1.2 = i := (Finset.mem_filter.mp he).2 + have hf' : f.1.1 = i ∨ f.1.2 = i := (Finset.mem_filter.mp hf).2 + have ehe := e.2 + have ehf := f.2 + apply Subtype.ext + apply Prod.ext + all_goals dsimp [other] at hef; split_ifs at hef <;> rcases he' with he' | he' <;> + rcases hf' with hf' | hf' <;> simp_all <;> omega) + simpa using h + +lemma sum_coupling_row {n : ℕ} (g : Disorder n) (i : Fin n) : + ∑ j, coupling g i j = ∑ e ∈ incidentEdges i, g e := by + have he := coupling_bilinear (fun j => if j=i then 1 else 0) (fun _ => 1) g + simp only [mul_one,ite_mul,one_mul,zero_mul,Finset.sum_ite_irrel,Finset.sum_const_zero,Finset.sum_ite_eq',Finset.mem_univ,ite_true] at he + rw [he,incidentEdges,Finset.sum_filter] + apply Finset.sum_congr rfl + intro e _ + have hh : e.1.1 ≠ e.1.2 := ne_of_lt e.2 + by_cases h1 : e.1.1=i <;> by_cases h2 : e.1.2=i <;> simp_all + +lemma abs_coupling {n : ℕ} (g : Disorder n) (i j : Fin n) : + |coupling g i j| = coupling (fun e => |g e|) i j := by + unfold coupling + split_ifs <;> simp + +lemma coupling_nonneg {n : ℕ} {g : Disorder n} (hg : ∀ e, 0 ≤ g e) (i j : Fin n) : + 0 ≤ coupling g i j := by + unfold coupling + split_ifs <;> first | exact hg _ | exact le_refl 0 + +lemma coupling_add {n : ℕ} (g h : Disorder n) : + coupling (g+h) = coupling g + coupling h := by + funext i j + change coupling (g+h) i j = coupling g i j + coupling h i j + unfold coupling + split_ifs <;> simp_all + +lemma coupling_sub {n : ℕ} (g h : Disorder n) : + coupling (g-h) = coupling g - coupling h := by + funext i j + change coupling (g-h) i j = coupling g i j - coupling h i j + unfold coupling + split_ifs <;> simp_all + +lemma coupling_const_mul {n : ℕ} (c : ℝ) (g : Disorder n) : + coupling (fun e => c*g e) = c • coupling g := by + funext i j + change coupling (fun e => c*g e) i j = c*coupling g i j + unfold coupling + split_ifs <;> simp_all + +lemma coupling_const_norm_le {n : ℕ} (c : ℝ) : + ‖Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) (coupling (fun _ => c))‖ ≤ n*|c| := by + apply matrix_opNorm_le_schur _ (n*|c|) (by positivity) + all_goals + intro i + calc + _ ≤ ∑ _j : Fin n, |c| := Finset.sum_le_sum (fun j _ => by + unfold coupling; split_ifs <;> simp [abs_nonneg]) + _ = _ := by simp + +lemma integrable_standard_square : Integrable (fun z : ℝ => z^2) (gaussianReal 0 1) := by + simpa only [id_eq] using (IsGaussian.memLp_two_id (μ := gaussianReal 0 1)).integrable_sq + +lemma standard_square_integral : ∫ z : ℝ, z^2 ∂gaussianReal 0 1 = 1 := by + have h := variance_fun_id_gaussianReal (μ := 0) (v := 1) + rw [variance_eq_integral measurable_id'.aemeasurable] at h + simpa only [integral_id_gaussianReal,sub_zero,NNReal.coe_one] using h + +def clippedSquare (R z : ℝ) : ℝ := min (z^2) (R^2) + +lemma continuous_clippedSquare (R : ℝ) : Continuous (clippedSquare R) := by + unfold clippedSquare; fun_prop + +lemma clippedSquare_nonneg (R z : ℝ) : 0 ≤ clippedSquare R z := le_min (sq_nonneg _) (sq_nonneg _) + +lemma clippedSquare_le (R z : ℝ) : clippedSquare R z ≤ R^2 := min_le_right _ _ + +lemma square_sub_clip_nonneg (R z : ℝ) : 0 ≤ z^2-clippedSquare R z := + sub_nonneg.mpr (min_le_left _ _) + +lemma square_sub_clip_le {R : ℝ} (hR : 0 ≤ R) (z : ℝ) : + z^2-clippedSquare R z ≤ squareTail R z := by + by_cases hz : R < |z| + · simp only [squareTail,hz,ite_true] + linarith [clippedSquare_nonneg R z] + · have h : z^2 ≤ R^2 := by + simpa only [sq_abs] using (sq_le_sq₀ (abs_nonneg z) hR).2 (le_of_not_gt hz) + simp only [clippedSquare,min_eq_left h,sub_self,squareTail,hz,ite_false,le_refl] + +lemma clippedSquare_integrable (R : ℝ) : Integrable (clippedSquare R) (gaussianReal 0 1) := by + apply Integrable.of_bound (continuous_clippedSquare R).aestronglyMeasurable (R^2) + exact ae_of_all _ (fun z => by + rw [Real.norm_eq_abs,abs_of_nonneg (clippedSquare_nonneg _ _)]; exact clippedSquare_le _ _) + +lemma clippedSquare_mean_bounds (R : ℝ) : + 0 ≤ ∫ z, clippedSquare R z ∂gaussianReal 0 1 ∧ + (∫ z, clippedSquare R z ∂gaussianReal 0 1) ≤ R^2 := by + constructor + · exact integral_nonneg (clippedSquare_nonneg R) + · simpa using integral_mono (clippedSquare_integrable R) (integrable_const (R^2)) + (clippedSquare_le R) + +lemma clippedSquare_mean_error {R : ℝ} (hR : 0 ≤ R) : + |(∫ z, clippedSquare R z ∂gaussianReal 0 1)-1| ≤ + ∫ z, squareTail R z ∂gaussianReal 0 1 := by + have hi : Integrable (squareTail R) (gaussianReal 0 1) := + integrable_standard_square.mono' (measurable_squareTail R).aestronglyMeasurable + (ae_of_all _ (fun z => by + rw [Real.norm_eq_abs,abs_of_nonneg (squareTail_nonneg _ _)]; exact squareTail_le _ _)) + have hm : (∫ z, clippedSquare R z ∂gaussianReal 0 1) ≤ 1 := by + rw [← standard_square_integral] + exact integral_mono (clippedSquare_integrable R) integrable_standard_square (fun _ => min_le_left _ _) + have h := integral_mono (integrable_standard_square.sub (clippedSquare_integrable R)) hi + (square_sub_clip_le hR) + simp only [Pi.sub_apply] at h + rw [integral_sub integrable_standard_square (clippedSquare_integrable R),standard_square_integral] at h + rw [abs_of_nonpos (sub_nonpos.mpr hm)] + linarith only [h] + +lemma centered_clip_subgaussian {ι : Type*} [Fintype ι] {R : ℝ} (hR : 0 < R) (i : ι) : + HasSubgaussianMGF + (fun z : ι → ℝ => clippedSquare R (z i)-(∫ x, clippedSquare R x ∂gaussianReal 0 1)) + ((Real.toNNReal (R^2))^2) (standardArrayLaw ι) := by + apply bounded_zero_subgaussian _ + (((continuous_clippedSquare R).measurable.comp (measurable_pi_apply i)).sub measurable_const).aemeasurable + · exact ae_of_all _ (fun z => by + simp only [Pi.sub_apply,Function.comp_def] + rw [Real.coe_toNNReal _ (sq_pos_of_pos hR).le,abs_le] + have h := clippedSquare_mean_bounds R + constructor <;> linarith [clippedSquare_le R (z i),clippedSquare_nonneg R (z i)]) + · have hc := (coordinate_hasLaw i).integral_comp + (f := fun x : ℝ => clippedSquare R x-(∫ y, clippedSquare R y ∂gaussianReal 0 1)) + (((continuous_clippedSquare R).sub continuous_const).aestronglyMeasurable) + simp only [Function.comp_def] at hc + simp only [Pi.sub_apply,Function.comp_def] + rw [hc,integral_sub (clippedSquare_integrable R) (integrable_const _)] + simp + +lemma clipped_square_matrix_rare {R u : ℝ} (hR : 0 < R) (hu : 0 < u) : + ExponentiallyRare (fun n => standardArrayLaw (Edge n)) + (fun n => {z | u < ‖Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) + (coupling (fun e => (clippedSquare R (z e)-(∫ x, clippedSquare R x ∂gaussianReal 0 1))/n))‖}) := by + apply exponentiallyRare_of_geom_quadratic _ _ (C := 2) (b := 81) (a := (u/2)^2/(4*(R^2)^2)) + (by norm_num) (by positivity) (by norm_num) + filter_upwards [eventually_gt_atTop 0] with n hn + have hb := bounded_matrix_opNorm_tail hn + (fun e (z : Edge n → ℝ) => clippedSquare R (z e)-(∫ x, clippedSquare R x ∂gaussianReal 0 1)) + (coordinates_independent.comp + (fun _ x => clippedSquare R x-(∫ y, clippedSquare R y ∂gaussianReal 0 1)) + (fun _ => ((continuous_clippedSquare R).sub continuous_const).measurable)) + (show 0 < Real.toNNReal (R^2) from Real.toNNReal_pos.mpr (by positivity)) + (centered_clip_subgaussian hR) (u := u/2) (by positivity) + rw [show 2*(u/2) = u by ring,Real.coe_toNNReal _ (sq_nonneg _)] at hb + convert hb using 1 + congr 2 + ring_nf + +lemma square_remainder_norm_le {n : ℕ} (hn : 0 (z e^2-clippedSquare R (z e))/n))‖ ≤ a := by + have hnR : (0:ℝ) (z e^2-clippedSquare R (z e))/n + have hg : ∀ e, 0≤g e := fun e => div_nonneg (square_sub_clip_nonneg _ _) hnR.le + have hr (i : Fin n) : ∑ j, |coupling g i j| ≤ a := by + simp_rw [abs_of_nonneg (coupling_nonneg hg _ _)] + rw [sum_coupling_row] + change (∑ e ∈ incidentEdges i, (z e^2-clippedSquare R (z e))/(n:ℝ)) ≤ a + rw [←Finset.sum_div] + exact (div_le_div_of_nonneg_right (Finset.sum_le_sum (fun e _ => square_sub_clip_le hR _)) hnR.le).trans (hrow i) + exact matrix_opNorm_le_schur (coupling g) a ha hr (fun j => by + simpa only [coupling_symm] using hr j) + +lemma coupling_norm_add_three {n : ℕ} (A B D : Disorder n) : + ‖Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) (coupling (A+B+D))‖ ≤ + (‖Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) (coupling A)‖ + + ‖Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) (coupling B)‖) + + ‖Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) (coupling D)‖ := by + rw [coupling_add,coupling_add] + change ‖Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) + ((Matrix.of (coupling A)+Matrix.of (coupling B))+Matrix.of (coupling D))‖ ≤ _ + rw [map_add,map_add] + exact (norm_add_le _ _).trans (add_le_add_left (norm_add_le _ _) _) + +lemma centered_square_mean_norm_le {n : ℕ} (hn : 0 ((∫ x, clippedSquare R x ∂gaussianReal 0 1)-1)/n))‖ ≤ + ∫ x, squareTail R x ∂gaussianReal 0 1 := by + let m := ∫ x, clippedSquare R x ∂gaussianReal 0 1 + have hh := coupling_const_norm_le (n := n) ((m-1)/n) + have hnR : (n:ℝ)≠0 := Nat.cast_ne_zero.mpr hn.ne' + have hm : (n:ℝ)*|(m-1)/n| = |m-1| := by + rw [abs_div,show |(n:ℝ)|=(n:ℝ) from abs_of_nonneg (Nat.cast_nonneg n)] + field_simp + rw [hm] at hh + exact hh.trans (clippedSquare_mean_error hR) + +lemma centered_square_norm_le {n : ℕ} (hn : 0 (z e^2-1)/n))‖ ≤ + ‖Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) + (coupling (fun e => (clippedSquare R (z e)-(∫ x, clippedSquare R x ∂gaussianReal 0 1))/n))‖ + + (∫ x, squareTail R x ∂gaussianReal 0 1) + a := by + let m := ∫ x, clippedSquare R x ∂gaussianReal 0 1 + let A : Disorder n := fun e => (clippedSquare R (z e)-m)/n + let B : Disorder n := fun _ => (m-1)/n + let D : Disorder n := fun e => (z e^2-clippedSquare R (z e))/n + have he : (fun e => (z e^2-1)/(n:ℝ)) = A+B+D := by + funext e + dsimp only [A,B,D,Pi.add_apply] + ring + have hB := centered_square_mean_norm_le hn hR + have hD := square_remainder_norm_le hn z hR ha hrow + rw [he] + exact (coupling_norm_add_three A B D).trans (add_le_add (add_le_add_right hB _) hD) + +theorem centered_gaussian_square_matrix_rare {u : ℝ} (hu : 0 standardArrayLaw (Edge n)) + (fun n => {z | u < ‖Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) + (coupling (fun e => (z e^2-1)/n))‖}) := by + obtain ⟨R,c,hR,hc,hmean,hb⟩ := gaussian_squareTail_row_bound (a := u/3) (by positivity) + have htail : ExponentiallyRare (fun n => standardArrayLaw (Edge n)) + (fun n => ⋃ i : Fin n, {z | u/3 ≤ (∑ e ∈ incidentEdges i, squareTail R (z e))/(n:ℝ)}) := by + apply exponentiallyRare_iUnion_polynomial _ _ hc (hC := zero_lt_one) (hD := zero_lt_one) 1 + · apply Eventually.of_forall + intro n + simp + · filter_upwards [eventually_gt_atTop 0] with n hn + intro i + simpa only [one_mul] using hb (incidentEdges i) hn (incidentEdges_card_le i) + apply ((clipped_square_matrix_rare hR (show 0 (clippedSquare R (z e)-(∫ x, clippedSquare R x ∂gaussianReal 0 1))/n))‖ ≤ u/3 := + le_of_not_gt (fun h => hnot (Or.inl h)) + have hrows : ∀ i, (∑ e ∈ incidentEdges i, squareTail R (z e))/(n:ℝ) ≤ u/3 := by + intro i + exact (not_le.mp (fun hi => hnot (Or.inr (mem_iUnion.mpr ⟨i,hi⟩)))).le + have hh := centered_square_norm_le hn z hR.le (by positivity : 0≤u/3) hrows + change u < _ at hz + linarith + +end SKRatio.MatrixNet + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Matrices/GaussianSquareTails.lean b/lean/OAI/Probability/SKRatio/Matrices/GaussianSquareTails.lean new file mode 100644 index 0000000000000000000000000000000000000000..5e1389a8a1ae467d353321102ec0de4e0fcd1c3a --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Matrices/GaussianSquareTails.lean @@ -0,0 +1,452 @@ +import Mathlib +import OAI.Probability.SKRatio.Matrices.GOERegression +import OAI.Probability.SKRatio.Gaussian.ExponentialEvents + +namespace OAI + +section +noncomputable section +open scoped BigOperators NNReal ENNReal Topology +open MeasureTheory ProbabilityTheory Filter +namespace SKRatioClock.Regression + +lemma integrable_bounded_lipschitz {F : Type*} [PseudoMetricSpace F] + [MeasurableSpace F] [BorelSpace F] (μ : Measure F) [IsProbabilityMeasure μ] + {f : F → ℝ} {K : ℝ≥0} (hf : LipschitzWith K f) + (B : ℝ) (hB : ∀ x, |f x| ≤ B) : Integrable f μ := by + apply Integrable.of_bound hf.continuous.measurable.aestronglyMeasurable B + exact Filter.Eventually.of_forall (by simpa only [Real.norm_eq_abs] using hB) + +lemma bounded_product_lipschitz {E : Type*} [PseudoMetricSpace E] + {f g : E → ℝ} {K L B D : ℝ≥0} + (hf : LipschitzWith K f) (hg : LipschitzWith L g) + (hb : ∀ x, |f x| ≤ B) (hd : ∀ x, |g x| ≤ D) : + LipschitzWith (K*D+L*B) (fun x => f x*g x) := by + apply LipschitzWith.of_dist_le_mul + intro x y + rw [Real.dist_eq] + have hid : f x*g x-f y*g y = (f x-f y)*g x + f y*(g x-g y) := by ring + rw [hid] + calc + |(f x-f y)*g x+f y*(g x-g y)| ≤ |(f x-f y)*g x|+|f y*(g x-g y)| := abs_add_le _ _ + _ = |f x-f y| * |g x|+|f y| * |g x-g y| := by rw [abs_mul, abs_mul] + _ ≤ ((K:ℝ)*dist x y)*(D:ℝ)+(B:ℝ)*((L:ℝ)*dist x y) := by + gcongr + · exact hf.dist_le_mul x y + · exact hd x + · exact hb y + · exact hg.dist_le_mul x y + _ = ((K*D+L*B:ℝ≥0):ℝ)*dist x y := by push_cast; ring +lemma gaussian_integrable_exp_quarter_sq : + Integrable (fun x : ℝ => Real.exp (x^2/4)) (gaussianReal 0 1) := by + rw [gaussianReal_of_var_ne_zero _ (by norm_num : (1:ℝ≥0) ≠ 0)] + rw [integrable_withDensity_iff_integrable_smul' + (measurable_gaussianPDF _ _) (ae_of_all _ (fun _ => gaussianPDF_lt_top))] + have h := (integrable_exp_neg_mul_sq (by norm_num : (0:ℝ)<1/4)).const_mul + ((Real.sqrt (2*Real.pi))⁻¹) + apply h.congr + filter_upwards [] with x + symm + simp only [toReal_gaussianPDF, + smul_eq_mul, gaussianPDFReal, NNReal.coe_one, sub_zero, mul_one, one_div] + rw [mul_assoc, ← Real.exp_add] + congr 2 + ring + +lemma iid_upper_deviation_of_log_mgf {Ω : Type*} [MeasurableSpace Ω] + {μ : Measure Ω} [IsProbabilityMeasure μ] {n : ℕ} (hn : 0 < n) + (X : Fin n → Ω → ℝ) (hXi : iIndepFun X μ) + (hXm : ∀ i, Measurable (X i)) (ν : Measure ℝ) + (hLaw : ∀ i, HasLaw (X i) ν μ) {t : ℝ} (ht : 0 < t) + (hi : Integrable (fun x : ℝ => Real.exp (t*x)) ν) (a : ℝ) : + μ {ω | a ≤ (∑ i, X i ω)/(n:ℝ)} ≤ + ENNReal.ofReal (Real.exp (-((t*a-cgf id ν t)*(n:ℝ)))) := by + have he (i : Fin n) : Integrable (fun ω => Real.exp (t*X i ω)) μ := + by + rw [← (hLaw i).map_eq] at hi + exact (integrable_map_measure (by fun_prop) (hLaw i).aemeasurable).mp hi + have hsum := hXi.integrable_exp_mul_sum hXm (s := Finset.univ) (fun i _ => he i) + have hc := measure_ge_le_exp_cgf (μ := μ) (X := ∑ i, X i) (a*n) ht.le hsum + have hcgf (i : Fin n) : cgf (X i) μ t = cgf id ν t := by + unfold cgf mgf + congr 1 + exact (hLaw i).integral_comp (f := fun x : ℝ => Real.exp (t*x)) (by fun_prop) + rw [hXi.cgf_sum hXm (fun i _ => he i)] at hc + simp only [hcgf, Finset.sum_const, Finset.card_univ, Fintype.card_fin, + nsmul_eq_mul] at hc + have hset : {ω | a*(n:ℝ) ≤ (∑ i, X i) ω} = + {ω | a ≤ (∑ i, X i ω)/(n:ℝ)} := by + ext ω + simp only [Finset.sum_apply, Set.mem_ofPred_eq, + le_div_iff₀ ((show (0:ℝ) positivity + +lemma squareTail_le (R x : ℝ) : squareTail R x ≤ x^2 := by + unfold squareTail + split_ifs <;> simp [sq_nonneg] + +lemma measurable_squareTail (R : ℝ) : Measurable (squareTail R) := by + unfold squareTail + exact Measurable.ite (measurableSet_lt measurable_const measurable_abs) + (by fun_prop) measurable_const + +lemma integrable_exp_squareTail {ν : Measure ℝ} + (hi : Integrable (fun x : ℝ => Real.exp (x^2/4)) ν) (R : ℝ) : + Integrable (fun x => Real.exp (squareTail R x/4)) ν := by + apply hi.mono' (((measurable_squareTail R).div_const 4).exp.aestronglyMeasurable) + filter_upwards [] with x + rw [Real.norm_eq_abs, abs_of_pos (Real.exp_pos _)] + exact Real.exp_le_exp.mpr (div_le_div_of_nonneg_right (squareTail_le R x) (by norm_num)) + +lemma tendsto_squareTail_mgf {ν : Measure ℝ} [IsProbabilityMeasure ν] + (hi : Integrable (fun x : ℝ => Real.exp (x^2/4)) ν) : + Tendsto (fun R : ℕ => ∫ x, Real.exp (squareTail R x/4) ∂ν) atTop (𝓝 1) := by + have ht : Tendsto (fun R : ℕ => ∫ x, Real.exp (squareTail R x/4) ∂ν) + atTop (𝓝 (∫ _x : ℝ, (1:ℝ) ∂ν)) := by + apply tendsto_integral_of_dominated_convergence (fun x : ℝ => Real.exp (x^2/4)) + · intro R + exact (((measurable_squareTail R).div_const 4).exp.aestronglyMeasurable) + · exact hi + · intro R + filter_upwards [] with x + rw [Real.norm_eq_abs, abs_of_pos (Real.exp_pos _)] + exact Real.exp_le_exp.mpr (div_le_div_of_nonneg_right (squareTail_le R x) (by norm_num)) + · filter_upwards [] with x + apply tendsto_const_nhds.congr' + filter_upwards [eventually_ge_atTop (⌈|x|⌉₊)] with R hR + have hx : |x| ≤ (R:ℝ) := (Nat.le_ceil _).trans (by exact_mod_cast hR) + simp [squareTail, not_lt.mpr hx] + simpa using ht + +def ExponentialSquareTails {H : ℕ → Type*} [∀ n, MeasurableSpace (H n)] + (ρ : ∀ n, Measure (H n)) (X : ∀ n, H n → Fin n → ℝ) : Prop := + ∀ ε : ℝ, 0 < ε → ∃ R : ℝ, 0 < R ∧ + ExponentiallyRare ρ (fun n => {h | ε ≤ (∑ i, squareTail R (X n h i))/(n:ℝ)}) + +theorem iid_exponential_squareTails {H : ℕ → Type*} [∀ n, MeasurableSpace (H n)] + (ρ : ∀ n, Measure (H n)) [∀ n, IsProbabilityMeasure (ρ n)] + (X : ∀ n, H n → Fin n → ℝ) + (hXm : ∀ n i, Measurable (fun h => X n h i)) + (hXi : ∀ n, iIndepFun (fun i h => X n h i) (ρ n)) + (ν : Measure ℝ) [IsProbabilityMeasure ν] + (hLaw : ∀ n i, HasLaw (fun h => X n h i) ν (ρ n)) + (hi : Integrable (fun x : ℝ => Real.exp (x^2/4)) ν) : + ExponentialSquareTails ρ X := by + intro ε hε + have ht : Tendsto (fun R : ℕ => Real.log (∫ x, Real.exp (squareTail R x/4) ∂ν)) + atTop (𝓝 0) := by + simpa only [Function.comp_def, Real.log_one] using (Real.continuousAt_log (by norm_num : (1:ℝ)≠0)).tendsto.comp + (tendsto_squareTail_mgf hi) + have he : ∀ᶠ R : ℕ in atTop, + Real.log (∫ x, Real.exp (squareTail R x/4) ∂ν) < ε/4 := + ht.eventually (gt_mem_nhds (by positivity)) + obtain ⟨R,hR,hm⟩ := (eventually_ge_atTop 1 |>.and he).exists + let m := Real.log (∫ x, Real.exp (squareTail R x/4) ∂ν) + have htm : Measurable (squareTail R) := measurable_squareTail R + have hl : HasLaw (squareTail R) (ν.map (squareTail R)) ν := ⟨htm.aemeasurable,rfl⟩ + have hcg : cgf id (ν.map (squareTail R)) (1/4) = m := by + unfold cgf mgf m + rw [integral_map htm.aemeasurable (by fun_prop)] + congr 2 + ext x + simp only [id_eq] + congr 1 + ring + have hint : Integrable (fun x : ℝ => Real.exp (1/4*x)) (ν.map (squareTail R)) := by + rw [integrable_map_measure (by fun_prop) htm.aemeasurable] + simpa only [Function.comp_def, one_div_mul_eq_div] using integrable_exp_squareTail hi R + refine ⟨R,by exact_mod_cast hR,1,ε/4-m,by norm_num,sub_pos.mpr hm,?_⟩ + filter_upwards [eventually_ge_atTop 1] with n hn + have hb := iid_upper_deviation_of_log_mgf hn (fun i h => squareTail R (X n h i)) + ((hXi n).comp (fun _ => squareTail R) (fun _ => htm)) + (fun i => htm.comp (hXm n i)) (ν.map (squareTail R)) + (fun i => hl.fun_comp (hLaw n i)) (by norm_num : (0:ℝ)<1/4) hint ε + rw [hcg] at hb + simpa only [one_mul, one_div_mul_eq_div, neg_mul] using hb + +theorem gaussian_exponential_squareTails : + ExponentialSquareTails (fun n => standardArrayLaw (Fin n)) (fun _ g => g) := by + exact iid_exponential_squareTails _ _ (fun _ _ => measurable_pi_apply _) + (fun _ => coordinates_independent) (gaussianReal 0 1) (fun _ _ => coordinate_hasLaw _) + gaussian_integrable_exp_quarter_sq + +lemma squareTail_perturbation (R x y : ℝ) (_hR : 0 ≤ R) : + squareTail (2*R) y ≤ 4*squareTail R x+4*(x-y)^2 := by + unfold squareTail + split_ifs with hy hx + · nlinarith [sq_nonneg (x+y)] + · have hx' := le_of_not_gt hx + have habs := abs_sub_abs_le_abs_sub y x + have hxy : R < |y-x| := by linarith + have hyb : |y| ≤ 2*|y-x| := by linarith + have hs := mul_self_le_mul_self (abs_nonneg y) hyb + nlinarith [sq_abs y, sq_abs (y-x)] + · positivity + · positivity + +theorem ExponentialSquareTails.l2_stability + {H : ℕ → Type*} [∀ n, MeasurableSpace (H n)] + {ρ : ∀ n, Measure (H n)} {X Y : ∀ n, H n → Fin n → ℝ} + (hX : ExponentialSquareTails ρ X) + (hXY : ExponentialConvergence ρ + (fun n h => (∑ i, (X n h i-Y n h i)^2)/(n:ℝ)) 0) : + ExponentialSquareTails ρ Y := by + intro ε hε + obtain ⟨R,hR,ht⟩ := hX (ε/8) (by positivity) + refine ⟨2*R,by positivity,?_⟩ + apply (ht.union (hXY (ε/8) (by positivity))).mono + filter_upwards [eventually_ge_atTop 1] with n hn + intro h hh + simp only [Set.mem_ofPred_eq] at hh + by_cases hx : ε/8 ≤ (∑ i, squareTail R (X n h i))/(n:ℝ) + · exact Or.inl hx + apply Or.inr + have hb : (∑ i, squareTail (2*R) (Y n h i))/(n:ℝ) ≤ + 4*((∑ i, squareTail R (X n h i))/(n:ℝ))+ + 4*((∑ i, (X n h i-Y n h i)^2)/(n:ℝ)) := by + calc + _ ≤ (∑ i, (4*squareTail R (X n h i)+4*(X n h i-Y n h i)^2))/(n:ℝ) := by + apply div_le_div_of_nonneg_right _ (Nat.cast_nonneg _) + exact Finset.sum_le_sum (fun i _ => squareTail_perturbation R _ _ hR.le) + _ = _ := by rw [Finset.sum_add_distrib, ← Finset.mul_sum, ← Finset.mul_sum]; ring + change ε/8 ≤ dist ((∑ i, (X n h i-Y n h i)^2)/(n:ℝ)) 0 + rw [Real.dist_eq, sub_zero, abs_of_nonneg (by positivity)] + have hx' := lt_of_not_ge hx + linarith + +lemma squareTail_add (R x y : ℝ) (_hR : 0 ≤ R) : + squareTail (2*R) (x+y) ≤ 4*(squareTail R x+squareTail R y) := by + unfold squareTail + split_ifs with hxy hx hy hy + · nlinarith [sq_nonneg (x-y)] + · have hy' := le_of_not_gt hy + have hxy' : |y| ≤ |x| := hy'.trans (le_of_lt hx) + have hs := mul_self_le_mul_self (abs_nonneg y) hxy' + nlinarith [sq_abs x, sq_abs y, sq_nonneg (x-y)] + · have hx' := le_of_not_gt hx + have hxy' : |x| ≤ |y| := hx'.trans (le_of_lt hy) + have hs := mul_self_le_mul_self (abs_nonneg x) hxy' + nlinarith [sq_abs x, sq_abs y, sq_nonneg (x-y)] + · have hx' := le_of_not_gt hx + have hy' := le_of_not_gt hy + have := abs_add_le x y + linarith + all_goals positivity + +lemma squareTail_antitone (x : ℝ) : Antitone (fun R => squareTail R x) := by + intro R S hRS + dsimp only [squareTail] + split_ifs <;> first | exact le_rfl | positivity | (exfalso; linarith) + +theorem ExponentialSquareTails.add + {H : ℕ → Type*} [∀ n, MeasurableSpace (H n)] + {ρ : ∀ n, Measure (H n)} {X Y : ∀ n, H n → Fin n → ℝ} + (hX : ExponentialSquareTails ρ X) (hY : ExponentialSquareTails ρ Y) : + ExponentialSquareTails ρ (fun n h i => X n h i+Y n h i) := by + intro ε hε + obtain ⟨R,hR,ht⟩ := hX (ε/8) (by positivity) + obtain ⟨S,hS,hs⟩ := hY (ε/8) (by positivity) + refine ⟨2*max R S,by positivity,?_⟩ + apply (ht.union hs).mono + filter_upwards [eventually_ge_atTop 1] with n hn + intro h hh + simp only [Set.mem_ofPred_eq] at hh + by_cases hx : ε/8 ≤ (∑ i, squareTail R (X n h i))/(n:ℝ) + · exact Or.inl hx + apply Or.inr + have hb : (∑ i, squareTail (2*max R S) (X n h i+Y n h i))/(n:ℝ) ≤ + 4*((∑ i, squareTail R (X n h i))/(n:ℝ))+ + 4*((∑ i, squareTail S (Y n h i))/(n:ℝ)) := by + calc + _ ≤ (∑ i, 4*(squareTail R (X n h i)+squareTail S (Y n h i)))/(n:ℝ) := by + apply div_le_div_of_nonneg_right _ (Nat.cast_nonneg _) + apply Finset.sum_le_sum + intro i _ + exact (squareTail_add _ _ _ (le_max_of_le_left hR.le)).trans + (mul_le_mul_of_nonneg_left (add_le_add + (squareTail_antitone _ (le_max_left _ _)) + (squareTail_antitone _ (le_max_right _ _))) (by norm_num)) + _ = _ := by simp_rw [mul_add]; rw [Finset.sum_add_distrib, ← Finset.mul_sum, + ← Finset.mul_sum]; ring + have hx' := lt_of_not_ge hx + change ε/8 ≤ (∑ i, squareTail S (Y n h i))/(n:ℝ) + linarith + +lemma squareTail_mul (R x a B : ℝ) (_hR : 0 ≤ R) (ha : |a| ≤ B) : + squareTail (B*R) (a*x) ≤ B^2*squareTail R x := by + have hB := (abs_nonneg a).trans ha + unfold squareTail + split_ifs with hax hx + · have hs := mul_self_le_mul_self (abs_nonneg a) ha + have hsq : a^2 ≤ B^2 := by nlinarith [sq_abs a] + nlinarith [mul_le_mul_of_nonneg_right hsq (sq_nonneg x)] + · have hx' := le_of_not_gt hx + have hab : |a*x| ≤ B*R := by rw [abs_mul]; exact mul_le_mul ha hx' (abs_nonneg x) hB + exact False.elim ((not_lt_of_ge hab) hax) + all_goals positivity + +lemma ExponentialSquareTails.bounded_mul + {H : ℕ → Type*} [∀ n, MeasurableSpace (H n)] + {ρ : ∀ n, Measure (H n)} {X : ∀ n, H n → Fin n → ℝ} + (hX : ExponentialSquareTails ρ X) + (a : ∀ n, H n → Fin n → ℝ) (B : ℝ) (hB : 0 ≤ B) + (ha : ∀ n h i, |a n h i| ≤ B) : + ExponentialSquareTails ρ (fun n h i => a n h i*X n h i) := by + intro ε hε + obtain ⟨R,hR,ht⟩ := hX (ε/(B+1)^2) (by positivity) + refine ⟨(B+1)*R,by positivity,ht.mono ?_⟩ + filter_upwards [] with n + intro h hh + change ε/(B+1)^2 ≤ (∑ i, squareTail R (X n h i))/(n:ℝ) + apply (div_le_iff₀ (by positivity : 0 < (B+1)^2)).mpr + have hb : (∑ i, squareTail ((B+1)*R) (a n h i*X n h i))/(n:ℝ) ≤ + (B+1)^2*((∑ i, squareTail R (X n h i))/(n:ℝ)) := by + calc + _ ≤ (∑ i, (B+1)^2*squareTail R (X n h i))/(n:ℝ) := by + apply div_le_div_of_nonneg_right _ (Nat.cast_nonneg _) + exact Finset.sum_le_sum (fun i _ => squareTail_mul R _ _ _ hR.le ((ha n h i).trans (by linarith))) + _ = _ := by rw [← Finset.mul_sum]; ring + exact (show ε ≤ _ from hh).trans (by simpa [mul_comm] using hb) + +noncomputable def clippedSquare (R x : ℝ) : ℝ := (min |x| R)^2 + +lemma clippedSquare_bounds (R x : ℝ) (hR : 0 ≤ R) : + 0 ≤ clippedSquare R x ∧ clippedSquare R x ≤ x^2 ∧ clippedSquare R x ≤ R^2 := by + have hm := le_min (abs_nonneg x) hR + have hx := mul_self_le_mul_self hm (min_le_left |x| R) + have hr := mul_self_le_mul_self hm (min_le_right |x| R) + dsimp [clippedSquare] + exact ⟨sq_nonneg _, by nlinarith [sq_abs x], by nlinarith⟩ + +lemma clippedSquare_error (R x : ℝ) (hR : 0 ≤ R) : + |x^2-clippedSquare R x| ≤ squareTail R x := by + rw [abs_of_nonneg (sub_nonneg.mpr (clippedSquare_bounds R x hR).2.1)] + by_cases hx : R < |x| + · simp only [squareTail, ite_eq_left hx] + linarith [(clippedSquare_bounds R x hR).1] + · simp [clippedSquare, squareTail, hx, min_eq_left (le_of_not_gt hx)] + +lemma clippedSquare_lipschitz (R : ℝ≥0) : + LipschitzWith (2*R) (clippedSquare R) := by + have ha : LipschitzWith 1 (fun x : ℝ => |x|) := by + apply LipschitzWith.of_dist_le_mul + intro x y + simpa only [Real.dist_eq, NNReal.coe_one, one_mul] using abs_abs_sub_abs_le_abs_sub x y + have h : LipschitzWith 1 (fun x : ℝ => min |x| (R:ℝ)) := ha.min_const _ + have hb (x : ℝ) : |min |x| (R:ℝ)| ≤ R := by + rw [abs_of_nonneg (le_min (abs_nonneg _) R.coe_nonneg)] + exact min_le_right _ _ + change LipschitzWith (2*R) (fun x : ℝ => (min |x| (R:ℝ))^2) + simpa only [one_mul, ← two_mul, pow_two] using bounded_product_lipschitz h h hb hb + +lemma integrable_clippedSquare (ν : Measure ℝ) [IsProbabilityMeasure ν] + (R : ℝ≥0) : Integrable (clippedSquare R) ν := by + apply integrable_bounded_lipschitz ν (clippedSquare_lipschitz R) ((R:ℝ)^2) + intro x + rw [abs_of_nonneg (clippedSquare_bounds R x R.coe_nonneg).1] + exact (clippedSquare_bounds R x R.coe_nonneg).2.2 + +lemma tendsto_integral_clippedSquare (ν : Measure ℝ) + (hi : Integrable (fun x : ℝ => x^2) ν) : + Tendsto (fun R : ℕ => ∫ x, clippedSquare R x ∂ν) atTop (𝓝 (∫ x, x^2 ∂ν)) := by + apply tendsto_integral_of_dominated_convergence (fun x : ℝ => x^2) + · intro R + exact (clippedSquare_lipschitz R).continuous.measurable.aestronglyMeasurable + · exact hi + · intro R + filter_upwards [] with x + rw [Real.norm_eq_abs, abs_of_nonneg (clippedSquare_bounds R x (Nat.cast_nonneg _)).1] + exact (clippedSquare_bounds R x (Nat.cast_nonneg _)).2.1 + · filter_upwards [] with x + apply tendsto_const_nhds.congr' + filter_upwards [eventually_ge_atTop (⌈|x|⌉₊)] with R hR + have hx : |x| ≤ (R:ℝ) := (Nat.le_ceil _).trans (by exact_mod_cast hR) + simp [clippedSquare, min_eq_left hx] + +theorem ExponentialEmpiricalConcentration.secondMoment + {H : ℕ → Type*} [∀ n, MeasurableSpace (H n)] + {ρ : ∀ n, Measure (H n)} {X : ∀ n, H n → Fin n → ℝ} + {ν : Measure ℝ} [IsProbabilityMeasure ν] + (hX : ExponentialEmpiricalConcentration ρ X ν) + (hT : ExponentialSquareTails ρ X) + (hi : Integrable (fun x : ℝ => x^2) ν) : + ExponentialConvergence ρ (fun n h => (∑ i, X n h i^2)/(n:ℝ)) + (∫ x, x^2 ∂ν) := by + intro ε hε + obtain ⟨R,hR,ht⟩ := hT (ε/3) (by positivity) + have hbias : ∀ᶠ k : ℕ in atTop, + |(∫ x, clippedSquare k x ∂ν) - ∫ x, x^2 ∂ν| < ε/3 := by + simpa only [Real.dist_eq] using (Metric.tendsto_nhds.mp + (tendsto_integral_clippedSquare ν hi)) (ε/3) (by positivity) + obtain ⟨k,hk,hbias⟩ := ((eventually_ge_atTop ⌈R⌉₊).and hbias).exists + have hRk : R ≤ (k:ℝ) := (Nat.le_ceil _).trans (by exact_mod_cast hk) + have hc : ExponentiallyRare ρ (fun n => {h | ε/3 ≤ + |(∑ i, clippedSquare k (X n h i))/(n:ℝ) - ∫ x, clippedSquare k x ∂ν|}) := by + apply hX (clippedSquare k) (2*(k:ℝ≥0)) (clippedSquare_lipschitz k) + ((k:ℝ)^2) + · intro x + rw [abs_of_nonneg (clippedSquare_bounds k x (Nat.cast_nonneg _)).1] + exact (clippedSquare_bounds k x (Nat.cast_nonneg _)).2.2 + · positivity + apply (ht.union hc).mono + filter_upwards [eventually_ge_atTop 1] with n hn + intro h hh + change ε ≤ |(∑ i, X n h i^2)/(n:ℝ) - ∫ x, x^2 ∂ν| at hh + by_cases htail : ε/3 ≤ (∑ i, squareTail R (X n h i))/(n:ℝ) + · exact Or.inl htail + apply Or.inr + by_contra hclip + have herror : |(∑ i, X n h i^2)/(n:ℝ) - + (∑ i, clippedSquare k (X n h i))/(n:ℝ)| ≤ + (∑ i, squareTail R (X n h i))/(n:ℝ) := by + rw [← sub_div, abs_div, abs_of_nonneg (Nat.cast_nonneg n : (0:ℝ) ≤ n), ← Finset.sum_sub_distrib] + apply div_le_div_of_nonneg_right _ (Nat.cast_nonneg _) + calc + _ ≤ ∑ i, |X n h i^2-clippedSquare k (X n h i)| := Finset.abs_sum_le_sum_abs _ _ + _ ≤ ∑ i, squareTail R (X n h i) := by + apply Finset.sum_le_sum + intro i _ + exact (clippedSquare_error k _ (Nat.cast_nonneg _)).trans + (squareTail_antitone _ hRk) + have htriangle := abs_add_three + ((∑ i, X n h i^2)/(n:ℝ)-(∑ i, clippedSquare k (X n h i))/(n:ℝ)) + ((∑ i, clippedSquare k (X n h i))/(n:ℝ)-∫ x, clippedSquare k x ∂ν) + ((∫ x, clippedSquare k x ∂ν)-∫ x, x^2 ∂ν) + rw [sub_add_sub_cancel, sub_add_sub_cancel] at htriangle + have ht' := lt_of_not_ge htail + simp only [Set.mem_ofPred_eq] at hclip + have hc' := lt_of_not_ge hclip + linarith + +lemma exponentialSquareTails_of_bounded + {H : ℕ → Type*} [∀ n, MeasurableSpace (H n)] + (ρ : ∀ n, Measure (H n)) (X : ∀ n, H n → Fin n → ℝ) (B : ℝ) + (hB : ∀ n h i, |X n h i| ≤ B) : ExponentialSquareTails ρ X := by + intro ε hε + refine ⟨|B|+1,by positivity, (exponentiallyRare_empty ρ).mono ?_⟩ + filter_upwards [] with n + intro h hh + have hz : ∀ i, squareTail (|B|+1) (X n h i) = 0 := by + intro i + have hb := (hB n h i).trans (le_abs_self B) + simp [squareTail, show ¬ |B|+1 < |X n h i| by linarith] + simp only [Set.mem_ofPred_eq, hz, Finset.sum_const_zero, zero_div] at hh + exact False.elim ((not_le_of_gt hε) hh) + +end SKRatioClock.Regression + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Matrices/GaussianSupport.lean b/lean/OAI/Probability/SKRatio/Matrices/GaussianSupport.lean new file mode 100644 index 0000000000000000000000000000000000000000..48deb2a7d80bc26b22ffd4aed63111c099fed859 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Matrices/GaussianSupport.lean @@ -0,0 +1,306 @@ +import Mathlib +import OAI.Probability.SKRatio.FiniteChain.Mean +import OAI.Probability.SKRatio.Matrices.Spin +import OAI.Probability.SKRatio.Matrices.MatrixCoordinates +import OAI.Probability.SKRatio.Matrices.GaussianCoordinates + +namespace OAI + +section +section + +noncomputable section +open MeasureTheory ProbabilityTheory Matrix +open scoped BigOperators ENNReal +namespace SKRatioGaussian.GaussianRegression + +theorem law_eq_of_mean_covariance {Ω Ω' ι : Type*} + [MeasurableSpace Ω] [MeasurableSpace Ω'] [Fintype ι] [DecidableEq ι] + {P : Measure Ω} {P' : Measure Ω'} {X : Ω → ι → ℝ} {Y : Ω' → ι → ℝ} + (hX : HasGaussianLaw X P) (hY : HasGaussianLaw Y P') + (hm : ∀ i, (∫ w, X w i ∂P) = ∫ w, Y w i ∂P') + (hc : ∀ i k, cov[fun w => X w i, fun w => X w k; P] = + cov[fun w => Y w i, fun w => Y w k; P']) : + P.map X = P'.map Y := by + classical + have := hX.isProbabilityMeasure + have := hY.isProbabilityMeasure + apply Measure.ext_of_charFunDual + ext L + rw [hX.charFunDual_map_eq,hY.charFunDual_map_eq] + let c : ι → ℝ := fun i => L (fun k => if i=k then 1 else 0) + have hL (x : ι → ℝ) : L x = ∑ i, x i * c i := by + simpa only [c, smul_eq_mul, ContinuousLinearMap.coe_coe] using L.toLinearMap.pi_apply_eq_sum_univ x + have hLX : L ∘ X = fun w => ∑ i, X w i*c i := funext (fun w => hL (X w)) + have hLY : L ∘ Y = fun w => ∑ i, Y w i*c i := funext (fun w => hL (Y w)) + have hiX (i : ι) := (hX.eval i).memLp_two + have hiY (i : ι) := (hY.eval i).memLp_two + have hem : (∫ w, (L ∘ X) w ∂P) = ∫ w, (L ∘ Y) w ∂P' := by + rw [hLX,hLY] + rw [integral_finsetSum _ (fun i _ => ((hX.eval i).integrable.mul_const _)), + integral_finsetSum _ (fun i _ => ((hY.eval i).integrable.mul_const _))] + simp only [integral_mul_const,hm] + have hev : Var[L ∘ X; P] = Var[L ∘ Y; P'] := by + rw [← covariance_self (hX.map L).aemeasurable, + ← covariance_self (hY.map L).aemeasurable] + rw [hLX,hLY] + rw [covariance_fun_sum_fun_sum (fun i => (hiX i).mul_const _) (fun i => (hiX i).mul_const _), + covariance_fun_sum_fun_sum (fun i => (hiY i).mul_const _) (fun i => (hiY i).mul_const _)] + simp only [covariance_mul_const_left,covariance_mul_const_right,hc] + rw [hev,hem] + +def matrixCLM {ι κ : Type*} [Fintype κ] (A : Matrix ι κ ℝ) : + (κ → ℝ) →L[ℝ] (ι → ℝ) := A.mulVecLin.toContinuousLinearMap + +@[simp] lemma matrixCLM_apply {ι κ : Type*} [Fintype κ] (A : Matrix ι κ ℝ) (x : κ → ℝ) : + matrixCLM A x = A *ᵥ x := rfl + +theorem residual_independent {Ω ι κ : Type*} [MeasurableSpace Ω] + [Fintype ι] [Fintype κ] {P : Measure Ω} {X : Ω → ι → ℝ} {Y : Ω → κ → ℝ} + (hXY : HasGaussianLaw (fun w => (X w,Y w)) P) (K : Matrix ι κ ℝ) + (hcov : ∀ i k, cov[fun w => X w i, fun w => Y w k; P] = + ∑ l, K i l * cov[fun w => Y w l,fun w => Y w k; P]) : + IndepFun (fun w => X w-K*ᵥ Y w) Y P := by + have := hXY.isProbabilityMeasure + have hR : HasGaussianLaw (fun w => (X w-K*ᵥ Y w,Y w)) P := by + exact hXY.map_fun (((ContinuousLinearMap.fst ℝ (ι → ℝ) (κ → ℝ))- + (matrixCLM K).comp (ContinuousLinearMap.snd ℝ (ι → ℝ) (κ → ℝ))).prod + (ContinuousLinearMap.snd ℝ (ι → ℝ) (κ → ℝ))) + apply hR.indepFun_of_covariance_eval + intro i k + change cov[fun w => X w i-∑ l, K i l*Y w l,fun w => Y w k; P]=0 + have hK : MemLp (fun w => ∑ l, K i l*Y w l) 2 P := + ((hXY.snd.map (matrixCLM K)).eval i).memLp_two + rw [covariance_fun_sub_left (hXY.fst.eval i).memLp_two hK (hXY.snd.eval k).memLp_two] + rw [covariance_fun_sum_left (fun l => (hXY.snd.eval l).memLp_two.const_mul _) + (hXY.snd.eval k).memLp_two] + simp only [covariance_const_mul_left,hcov,sub_self] + +end SKRatioGaussian.GaussianRegression +end +end + +section +noncomputable section +namespace SKRatioGaussian +open MeasureTheory ProbabilityTheory Matrix +open scoped BigOperators ENNReal + +lemma coordinate_hasLaw {κ : Type*} [Fintype κ] (i : κ) : + HasLaw (fun g : κ → ℝ => g i) (gaussianReal 0 1) (gaussianCoordinates κ) := + ⟨(measurable_pi_apply i).aemeasurable, + (measurePreserving_eval (fun _ : κ => gaussianReal 0 1) i).map_eq⟩ + +lemma coordinates_gaussian {κ : Type*} [Fintype κ] : + HasGaussianLaw (fun g : κ → ℝ => g) (gaussianCoordinates κ) := + (iIndepFun_pi (fun _ : κ => aemeasurable_id)).hasGaussianLaw + (fun i => (coordinate_hasLaw i).hasGaussianLaw) + +lemma coordinate_covariance {κ : Type*} [Fintype κ] [DecidableEq κ] (i k : κ) : + cov[fun g : κ → ℝ => g i,fun g : κ → ℝ => g k;gaussianCoordinates κ] = + if i=k then 1 else 0 := by + by_cases h : i=k + · subst k + rw [ite_eq_left rfl,covariance_self (measurable_pi_apply i).aemeasurable, + (coordinate_hasLaw i).variance_eq] + simp + · rw [ite_eq_right h] + exact ((iIndepFun_pi (fun _ : κ => aemeasurable_id)).indepFun h).covariance_eq_zero + (coordinate_hasLaw i).hasGaussianLaw.memLp_two (coordinate_hasLaw k).hasGaussianLaw.memLp_two + +lemma linear_gaussian_mean {κ : Type*} [Fintype κ] (a : κ → ℝ) : + (∫ g, ∑ i, a i*g i ∂gaussianCoordinates κ) = 0 := by + rw [integral_finsetSum _ (fun i _ => (coordinate_hasLaw i).hasGaussianLaw.integrable.const_mul _)] + simp [integral_const_mul,(coordinate_hasLaw _).integral_eq] + +lemma linear_gaussian_covariance {κ : Type*} [Fintype κ] [DecidableEq κ] (a b : κ → ℝ) : + cov[fun g => ∑ i, a i*g i,fun g => ∑ i, b i*g i;gaussianCoordinates κ] = + ∑ i, a i*b i := by + rw [covariance_fun_sum_fun_sum + (fun i => (coordinate_hasLaw i).hasGaussianLaw.memLp_two.const_mul _) + (fun i => (coordinate_hasLaw i).hasGaussianLaw.memLp_two.const_mul _)] + simp only [covariance_const_mul_left,covariance_const_mul_right,coordinate_covariance] + simp [mul_comm] + +lemma matrix_sample_gaussian {ι κ : Type*} [Fintype ι] [Fintype κ] (A : Matrix ι κ ℝ) : + HasGaussianLaw (fun g => A*ᵥg) (gaussianCoordinates κ) := + coordinates_gaussian.map_fun (GaussianRegression.matrixCLM A) + +lemma matrix_sample_covariance {ι κ : Type*} [Fintype κ] [DecidableEq κ] + (A : Matrix ι κ ℝ) (i k : ι) : + cov[fun g => (A*ᵥg) i,fun g => (A*ᵥg) k;gaussianCoordinates κ] = (A*Aᵀ) i k := + linear_gaussian_covariance (A i) (A k) + +end SKRatioGaussian +end +end + +section +noncomputable section +namespace SKRatioGaussian +open MeasureTheory ProbabilityTheory Matrix Real +open scoped BigOperators ENNReal + +variable {ι : Type*} [Fintype ι] [DecidableEq ι] + +def goeEntryCoeff (r : ℝ) : Matrix (ι × ι) (MatrixCoordinates ι) ℝ := + fun p a => sqrt (2*r)/2 * ((if a=Sum.inl p then 1 else 0)+ + (if a=Sum.inl (p.2,p.1) then 1 else 0)) + +lemma goeEntryCoeff_sample (r : ℝ) (g : MatrixCoordinates ι → ℝ) (i k : ι) : + (goeEntryCoeff r*ᵥg) (i,k) = goeMatrix r g i k := by + simp only [mulVec,dotProduct,goeEntryCoeff,mul_assoc,add_mul] + rw [← Finset.mul_sum,Finset.sum_add_distrib] + simp [goeMatrix] + +lemma goe_matrix_gaussian (r : ℝ) : + HasGaussianLaw (fun (g : MatrixCoordinates ι → ℝ) (p : ι × ι) => goeMatrix r g p.1 p.2) (gaussianCoordinates (MatrixCoordinates ι)) := by + have hh := matrix_sample_gaussian (goeEntryCoeff (ι := ι) r) + simpa only [show (fun g => goeEntryCoeff (ι := ι) r*ᵥg) = + (fun g p => goeMatrix r g p.1 p.2) from funext (fun g => funext (fun p => goeEntryCoeff_sample r g p.1 p.2))] using hh + +lemma goe_mean_zero (r : ℝ) (i k : ι) : + (∫ g, goeMatrix r g i k ∂gaussianCoordinates (MatrixCoordinates ι))=0 := by + simpa only [← goeEntryCoeff_sample,mulVec,dotProduct] using linear_gaussian_mean (goeEntryCoeff (ι := ι) r (i,k)) + +lemma goe_entry_cov {r : ℝ} (hr : 0 ≤ r) (i k l m : ι) : + cov[fun g => goeMatrix r g i k,fun g => goeMatrix r g l m; + gaussianCoordinates (MatrixCoordinates ι)] = + r*((if i=l then 1 else 0)*(if k=m then 1 else 0)+ + (if i=m then 1 else 0)*(if k=l then 1 else 0)) := by + let μ := gaussianCoordinates (MatrixCoordinates ι) + have hm (a : MatrixCoordinates ι) := (coordinate_hasLaw a).hasGaussianLaw.memLp_two + change cov[fun g : MatrixCoordinates ι → ℝ => sqrt (2*r)/2*(g (.inl (i,k))+g (.inl (k,i))), + fun g => sqrt (2*r)/2*(g (.inl (l,m))+g (.inl (m,l))); μ]=_ + rw [covariance_const_mul_left,covariance_const_mul_right] + change sqrt (2*r)/2*(sqrt (2*r)/2*cov[(fun g => g (.inl (i,k))) + (fun g => g (.inl (k,i))), + (fun g => g (.inl (l,m))) + (fun g => g (.inl (m,l)));gaussianCoordinates (MatrixCoordinates ι)]) = _ + rw [covariance_add_left (hm _) (hm _) ((hm _).add (hm _)), + covariance_add_right (hm _) (hm _) (hm _), + covariance_add_right (hm _) (hm _) (hm _)] + simp only [coordinate_covariance,Sum.inl.injEq,Prod.mk.injEq] + have hs : (sqrt (2*r)/2)^2=r/2 := by rw [div_pow,sq_sqrt (by positivity)]; ring + have hs' : sqrt (2*r)/2*(sqrt (2*r)/2)=r/2 := by nlinarith only [hs] + rw [← mul_assoc,hs'] + have hind (p q : Prop) [Decidable p] [Decidable q] : + (if p ∧ q then (1:ℝ) else 0)=(if p then 1 else 0)*(if q then 1 else 0) := by + split_ifs <;> simp_all + simp_rw [hind] + ring + +end SKRatioGaussian +end +end + +section +noncomputable section +namespace SKRatioGaussian +open MeasureTheory ProbabilityTheory Matrix Real +open scoped BigOperators +variable {n : ℕ} + +def goeDisorder (r : ℝ) (g : MatrixCoordinates (Fin n)→ℝ) : Disorder n := + fun e=>goeMatrix r g e.1.1 e.1.2 + +lemma goeDisorder_gaussian (r : ℝ) : + HasGaussianLaw (goeDisorder (n:=n) r) (gaussianCoordinates (MatrixCoordinates (Fin n))) := + (goe_matrix_gaussian (ι:=Fin n) r).map_fun (ContinuousLinearMap.pi (fun e : Edge n=>ContinuousLinearMap.proj e.1)) + +lemma goeDisorder_mean (r : ℝ) (e : Edge n) : + (∫ g,goeDisorder r g e ∂gaussianCoordinates (MatrixCoordinates (Fin n)))=0 := + goe_mean_zero r e.1.1 e.1.2 + +lemma goeDisorder_cov {r : ℝ} (hr : 0 ≤ r) (e f : Edge n) : + cov[fun g=>goeDisorder r g e,fun g=>goeDisorder r g f; + gaussianCoordinates (MatrixCoordinates (Fin n))]=if e=f then r else 0 := by + change cov[fun g=>goeMatrix r g e.1.1 e.1.2,fun g=>goeMatrix r g f.1.1 f.1.2; + gaussianCoordinates (MatrixCoordinates (Fin n))]=_ + rw [goe_entry_cov hr] + have heq : e=f ↔ e.1.1=f.1.1 ∧ e.1.2=f.1.2 := by simp only [Subtype.ext_iff,Prod.ext_iff] + have hcross : ¬(e.1.1=f.1.2 ∧ e.1.2=f.1.1) := by + rintro ⟨h1,h2⟩ + have he := e.2 + rw [h1,h2] at he + exact (lt_asymm f.2 he) + split_ifs <;> simp_all + +lemma goeDisorder_hasLaw {r : ℝ} (hr : 0 ≤ r) : + HasLaw (goeDisorder (n:=n) r) (Measure.pi (fun _ : Edge n=>gaussianReal 0 (Real.toNNReal r))) + (gaussianCoordinates (MatrixCoordinates (Fin n))) := by + have hg := goeDisorder_gaussian (n:=n) r + have hl (e : Edge n) : HasLaw (fun g=>goeDisorder r g e) + (gaussianReal 0 (Real.toNNReal r)) (gaussianCoordinates (MatrixCoordinates (Fin n))) := by + refine ⟨(hg.eval e).aemeasurable,?_⟩ + rw [(hg.eval e).map_eq_gaussianReal,goeDisorder_mean, + ← covariance_self (hg.eval e).aemeasurable,goeDisorder_cov hr,ite_eq_left rfl] + exact iIndepFun.hasLaw_pi hl (hg.iIndepFun_of_covariance_eq_zero + (fun e f h=>by rw [goeDisorder_cov hr,ite_eq_right h])) + +lemma goe_actual_disorder_hasLaw (β : ℝ) (n : ℕ) : + HasLaw (goeDisorder (n:=n) (β^2/(n:ℝ))) (disorderLaw β n) + (gaussianCoordinates (MatrixCoordinates (Fin n))) := + goeDisorder_hasLaw (by positivity) + +lemma coupling_goeDisorder (r : ℝ) (g : MatrixCoordinates (Fin n)→ℝ) : + Matrix.of (coupling (goeDisorder r g))=goeMatrix r g-Matrix.diagonal (fun i=>goeMatrix r g i i) := by + ext i k + by_cases hik : i=k + · subst k + simp [coupling] + · rcases lt_or_gt_of_ne hik with h | h + · simp [coupling,h,hik,goeDisorder] + · simp [coupling,h,not_lt_of_gt h,hik,goeDisorder,goeMatrix,add_comm] +end SKRatioGaussian + +end +end + +section +noncomputable section +namespace SKRatioGaussian +open MeasureTheory ProbabilityTheory Matrix Real +open scoped BigOperators +variable {ι κ : Type*} [Fintype ι] [DecidableEq ι] [Fintype κ] [DecidableEq κ] + +omit [DecidableEq κ] in +lemma goe_row_gaussian (r : ℝ) (i : ι) (e : κ→ι) : + HasGaussianLaw (fun g : MatrixCoordinates ι→ℝ=>fun k=>goeMatrix r g i (e k)) + (gaussianCoordinates (MatrixCoordinates ι)) := by + exact (goe_matrix_gaussian r).map_fun + (ContinuousLinearMap.pi (fun k=>ContinuousLinearMap.proj (i,e k)) : + ((ι × ι)→ℝ) →L[ℝ] (κ→ℝ)) + +omit [Fintype κ] in +lemma goe_row_cov {r : ℝ} (hr : 0 ≤ r) (i : ι) (e : κ ↪ ι) + (he : ∀ k,e k≠i) (k l : κ) : + cov[fun g=>goeMatrix r g i (e k),fun g=>goeMatrix r g i (e l); + gaussianCoordinates (MatrixCoordinates ι)]=if k=l then r else 0 := by + classical + rw [goe_entry_cov hr] + have hi : ∀ k,¬i=e k := fun k=>Ne.symm (he k) + simp only [ite_true,hi,he,e.injective.eq_iff] + simp only [ite_false,mul_zero,add_zero] + split_ifs <;> simp_all + +lemma goe_row_hasLaw {r : ℝ} (hr : 0 ≤ r) (i : ι) (e : κ ↪ ι) + (he : ∀ k,e k≠i) : + HasLaw (fun g : MatrixCoordinates ι→ℝ=>fun k=>goeMatrix r g i (e k)) + (Measure.pi (fun _ : κ=>gaussianReal 0 (Real.toNNReal r))) + (gaussianCoordinates (MatrixCoordinates ι)) := by + classical + have hg := goe_row_gaussian r i e + have hl (k : κ) : HasLaw (fun g=>goeMatrix r g i (e k)) + (gaussianReal 0 (Real.toNNReal r)) (gaussianCoordinates (MatrixCoordinates ι)) := by + refine ⟨(hg.eval k).aemeasurable,?_⟩ + rw [(hg.eval k).map_eq_gaussianReal,goe_mean_zero, + ← covariance_self (hg.eval k).aemeasurable,goe_row_cov hr i e he,ite_eq_left rfl] + exact iIndepFun.hasLaw_pi hl (hg.iIndepFun_of_covariance_eq_zero + (fun k l h=>by rw [goe_row_cov hr i e he,ite_eq_right h])) +end SKRatioGaussian + +end +end + +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Matrices/GaussianTails.lean b/lean/OAI/Probability/SKRatio/Matrices/GaussianTails.lean new file mode 100644 index 0000000000000000000000000000000000000000..44452bea4e4d2d45bef8cb50884fdee171519e4e --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Matrices/GaussianTails.lean @@ -0,0 +1,305 @@ +import Mathlib +import OAI.Probability.SKRatio.Matrices.GaussianSupport + +namespace OAI + +section +section +noncomputable section +namespace SKRatioGaussian +open MeasureTheory ProbabilityTheory Real +open scoped BigOperators + +lemma gaussian_square_exp_integral : + (∫ x : ℝ,exp (x^2/4) ∂gaussianReal 0 1) ≤ 2 := by + rw [gaussianReal_of_var_ne_zero 0 (one_ne_zero), + integral_withDensity_eq_integral_toReal_smul (measurable_gaussianPDF 0 1) + (ae_of_all _ (fun y=>by simp [gaussianPDF]))] + simp only [gaussianPDF,ENNReal.toReal_ofReal (gaussianPDFReal_nonneg _ _ _),smul_eq_mul] + have he : (fun x : ℝ=>gaussianPDFReal 0 1 x*exp (x^2/4))= + (fun x : ℝ=>(1/sqrt (2*Real.pi))*exp (-(1/4:ℝ)*x^2)) := by + funext x + simp only [gaussianPDFReal,NNReal.coe_one,sub_zero,mul_one] + rw [mul_assoc,← exp_add] + congr 2 <;> ring + rw [he,integral_const_mul,integral_gaussian] + have hp := Real.pi_pos + have h1 := sq_sqrt (show 0 ≤ 2*Real.pi by positivity) + have h2 := sq_sqrt (show 0 ≤ Real.pi/(1/4:ℝ) by positivity) + have h3 := sqrt_nonneg (2*Real.pi) + have h4 := sqrt_nonneg (Real.pi/(1/4:ℝ)) + rw [one_div,mul_comm,← div_eq_mul_inv] + apply (div_le_iff₀ (sqrt_pos.mpr (by positivity))).mpr + nlinarith + +lemma gaussian_square_exp_integrable : + Integrable (fun x : ℝ=>exp (x^2/4)) (gaussianReal 0 1) := by + rw [gaussianReal_of_var_ne_zero 0 (one_ne_zero),integrable_withDensity_iff + (measurable_gaussianPDF 0 1) (ae_of_all _ (fun y=>by simp [gaussianPDF]))] + simp only [gaussianPDF,ENNReal.toReal_ofReal (gaussianPDFReal_nonneg _ _ _)] + have hi := (integrable_exp_neg_mul_sq (show (0:ℝ) < 1/4 by norm_num)).const_mul (1/sqrt (2*Real.pi)) + have he : (fun g : ℝ=>exp (g^2/4)*gaussianPDFReal 0 1 g)= + (fun g : ℝ=>(1/sqrt (2*Real.pi))*exp (-(1/4:ℝ)*g^2)) := by + funext g + simp only [gaussianPDFReal,NNReal.coe_one,sub_zero,mul_one] + rw [mul_left_comm,← exp_add] + congr 2 <;> ring + rw [he] + exact hi + +lemma product_gaussian_square_exp_integral {ι : Type*} [Fintype ι] : + (∫ g : ι→ℝ,exp ((∑ i,g i^2)/4) ∂Measure.pi (fun _ : ι=>gaussianReal 0 1)) ≤ + exp ((Fintype.card ι:ℝ)*log 2) := by + have he (g : ι→ℝ) : exp ((∑ i,g i^2)/4)=∏ i,exp (g i^2/4) := by + rw [← exp_sum,Finset.sum_div] + simp_rw [he] + rw [integral_fintype_prod_eq_prod (f:=fun _ : ι=>fun x : ℝ=>exp (x^2/4))] + calc + _ ≤ ∏ _i : ι,(2:ℝ) := Finset.prod_le_prod₀ + (fun i _=>integral_nonneg (fun x=>(exp_pos _).le)) + (fun i _=>gaussian_square_exp_integral) + _ = _ := by rw [Finset.prod_const,Finset.card_univ,exp_nat_mul,exp_log (by norm_num : (0:ℝ)<2)] + +lemma product_gaussian_square_exp_integrable {ι : Type*} [Fintype ι] : + Integrable (fun g : ι→ℝ=>exp ((∑ i,g i^2)/4)) + (Measure.pi (fun _ : ι=>gaussianReal 0 1)) := by + have hi := Integrable.fintype_prod (fun _ : ι=>gaussian_square_exp_integrable) + convert hi using 1 + ext g + rw [← exp_sum,Finset.sum_div] + +lemma product_gaussian_square_tail {ι : Type*} [Fintype ι] (t : ℝ) : + (Measure.pi (fun _ : ι=>gaussianReal 0 1)).real {g | t < ∑ i,g i^2} ≤ + exp (-t/4+(Fintype.card ι:ℝ)*log 2) := by + have hm := mul_meas_ge_le_integral_of_nonneg + (ae_of_all (Measure.pi (fun _ : ι=>gaussianReal 0 1)) + (fun g=>(exp_pos ((∑ i,g i^2)/4)).le)) product_gaussian_square_exp_integrable (exp (t/4)) + have hs : {g : ι→ℝ| t < ∑ i,g i^2} ⊆ {g | exp (t/4) ≤ exp ((∑ i,g i^2)/4)} := by + intro g hg + exact exp_le_exp.mpr (by linarith only [show t < ∑ i,g i^2 from hg]) + have hb := (mul_le_mul_of_nonneg_left (measureReal_mono hs) + (exp_pos (t/4)).le).trans (hm.trans product_gaussian_square_exp_integral) + rw [show -t/4+(Fintype.card ι:ℝ)*log 2=(Fintype.card ι:ℝ)*log 2-t/4 by ring,exp_sub] + apply (le_div_iff₀ (exp_pos _)).mpr + simpa only [mul_comm] using hb +end SKRatioGaussian +end +end + +section +noncomputable section +namespace SKRatioGaussian +open MeasureTheory ProbabilityTheory Real +open scoped BigOperators NNReal +variable {κ : Type*} [Fintype κ] + +lemma gaussian_scaled_coordinates_hasLaw {r : ℝ} (hr : 0 ≤ r) : + HasLaw (fun g : κ→ℝ=>fun k=>sqrt r*g k) + (Measure.pi (fun _ : κ=>gaussianReal 0 (Real.toNNReal r))) (gaussianCoordinates κ) := by + have hl (k : κ) : HasLaw (fun g : κ→ℝ=>sqrt r*g k) + (gaussianReal 0 (Real.toNNReal r)) (gaussianCoordinates κ) := by + have h := gaussianReal_const_mul (coordinate_hasLaw (κ:=κ) k) (sqrt r) + have hv : (⟨(sqrt r)^2,sq_nonneg _⟩:ℝ≥0)*1=Real.toNNReal r := by + apply NNReal.eq + change (sqrt r)^2*1=↑(Real.toNNReal r) + rw [mul_one,sq_sqrt hr,Real.coe_toNNReal _ hr] + rw [mul_zero] at h + convert h using 1 + exact congrArg (gaussianReal 0) hv.symm + exact iIndepFun.hasLaw_pi hl ((iIndepFun_pi (fun _ : κ=>aemeasurable_id)).comp + (fun _=>fun x : ℝ=>sqrt r*x) (fun _=>by fun_prop)) + +lemma scaled_gaussian_square_tail {r : ℝ} (hr : 0 < r) (t : ℝ) : + (Measure.pi (fun _ : κ=>gaussianReal 0 (Real.toNNReal r))).real {g | t < ∑ i,g i^2} ≤ + exp (-t/(4*r)+(Fintype.card κ:ℝ)*log 2) := by + have hm : MeasurableSet {g : κ→ℝ | t < ∑ i,g i^2} := by measurability + rw [← (gaussian_scaled_coordinates_hasLaw (κ:=κ) hr.le).measureReal_eq hm] + have he : {g : κ→ℝ | t < ∑ i,(sqrt r*g i)^2}={g | t/r < ∑ i,g i^2} := by + ext g + simp only [Set.mem_ofPred_eq,mul_pow,sq_sqrt hr.le,← Finset.mul_sum] + rw [div_lt_iff₀ hr,mul_comm] + rw [he] + convert product_gaussian_square_tail (ι:=κ) (t/r) using 1 + congr 2 + ring_nf +end SKRatioGaussian +end +end + +section +noncomputable section +namespace SKRatioGaussian +open MeasureTheory ProbabilityTheory Real +open scoped BigOperators + +lemma gaussian_real_square_tail {r : ℝ} (hr : 0 < r) (t : ℝ) : + (gaussianReal 0 (Real.toNNReal r)).real {x : ℝ | t < x^2} ≤ exp (-t/(4*r)+log 2) := by + have h : HasLaw (fun v : Unit→ℝ=>v ()) (gaussianReal 0 (Real.toNNReal r)) + (Measure.pi (fun _ : Unit=>gaussianReal 0 (Real.toNNReal r))) := + ⟨(measurable_pi_apply ()).aemeasurable,(measurePreserving_eval (fun _ : Unit=>gaussianReal 0 (Real.toNNReal r)) ()).map_eq⟩ + rw [← h.measureReal_eq (by measurability : MeasurableSet {x : ℝ | t < x^2})] + simpa using scaled_gaussian_square_tail (κ:=Unit) hr t + +lemma gaussian_real_abs_tail {r : ℝ} (hr : 0 < r) {d : ℝ} (hd : 0 ≤ d) : + (gaussianReal 0 (Real.toNNReal r)).real {x : ℝ | d < |x|} ≤ 2*exp (-d^2/(4*r)) := by + have he : {x : ℝ | d < |x|}={x | d^2 < x^2} := by + ext x + simpa only [Set.mem_ofPred_eq,sq_abs] using (sq_lt_sq₀ hd (abs_nonneg x)).symm + rw [he] + apply (gaussian_real_square_tail hr (d^2)).trans_eq + rw [exp_add,exp_log (by norm_num : (0:ℝ) < 2),mul_comm] +end SKRatioGaussian +end +end + +section +noncomputable section +namespace SKRatioGaussian +open MeasureTheory ProbabilityTheory Matrix Real Set +open scoped BigOperators Matrix.Norms.L2Operator +variable {ι : Type*} [Fintype ι] [DecidableEq ι] + +lemma goe_diagonal_hasLaw {r : ℝ} (hr : 0 ≤ r) (i : ι) : + HasLaw (fun g : MatrixCoordinates ι→ℝ=>goeMatrix r g i i) + (gaussianReal 0 (Real.toNNReal (2*r))) (gaussianCoordinates (MatrixCoordinates ι)) := by + have hg := (goe_matrix_gaussian (ι:=ι) r).eval (i,i) + refine ⟨hg.aemeasurable,?_⟩ + rw [hg.map_eq_gaussianReal,goe_mean_zero,← covariance_self hg.aemeasurable,goe_entry_cov hr] + simp only [ite_true,mul_one] + congr 2 + ring + +lemma goe_diagonal_tail {r d : ℝ} (hr : 0 < r) (hd : 0 ≤ d) : + (gaussianCoordinates (MatrixCoordinates ι)).real + {g | ∃ i : ι,d < |goeMatrix r g i i|} ≤ + 2*(Fintype.card ι:ℝ)*exp (-d^2/(8*r)) := by + have hsingle (i : ι) : + (gaussianCoordinates (MatrixCoordinates ι)).real {g | d < |goeMatrix r g i i|} ≤ + 2*exp (-d^2/(8*r)) := by + rw [(goe_diagonal_hasLaw hr.le i).measureReal_eq + (by measurability : MeasurableSet {x : ℝ | d < |x|})] + convert gaussian_real_abs_tail (r:=2*r) (by positivity) hd using 1 + ring_nf + have he : {g : MatrixCoordinates ι→ℝ | ∃ i : ι,d < |goeMatrix r g i i|}= + ⋃ i : ι,{g | d < |goeMatrix r g i i|} := by ext g;simp + rw [he] + apply (measureReal_iUnion_fintype_le _).trans + apply (Finset.sum_le_sum (fun i _=>hsingle i)).trans_eq + simp only [Finset.sum_const,Finset.card_univ,nsmul_eq_mul] + ring + +lemma diagonal_norm_le {d : ℝ} (hd : 0 ≤ d) (v : ι→ℝ) (hv : ∀ i,|v i| ≤ d) : + ‖Matrix.diagonal v‖ ≤ d := by + rw [Matrix.l2_opNorm_diagonal] + exact (pi_norm_le_iff_of_nonneg hd).mpr (fun i=>by simpa only [Real.norm_eq_abs] using hv i) +end SKRatioGaussian +end +end + +section +noncomputable section +namespace SKRatioGaussian +open MeasureTheory ProbabilityTheory Matrix Real Set +open scoped BigOperators +variable {n : ℕ} + +lemma coupling_goe_offdiag (r : ℝ) (g : MatrixCoordinates (Fin n)→ℝ) (i k : Fin n) + (hik : i≠k) : coupling (goeDisorder r g) i k=goeMatrix r g i k := by + have h := congrFun (congrFun (coupling_goeDisorder r g) i) k + simpa only [of_apply,Matrix.sub_apply,diagonal_apply_ne _ hik,sub_zero] using h + +lemma coupling_goe_row_square_sum (r : ℝ) (g : MatrixCoordinates (Fin n)→ℝ) + (i : Fin n) (S : Finset (Fin n)) : + (∑ k∈S,coupling (goeDisorder r g) i k^2)=∑ k : S.erase i,goeMatrix r g i k^2 := by + rw [Finset.sum_coe_sort (S.erase i) (fun k : Fin n=>goeMatrix r g i k^2)] + calc + _ = ∑ k∈S.erase i,coupling (goeDisorder r g) i k^2 := + by + by_cases hi : i∈S + · rw [Finset.sum_erase_eq_sub hi] + simp [coupling] + · rw [Finset.erase_eq_self.mpr hi] + _ = _ := Finset.sum_congr rfl (fun k hk=>by rw [coupling_goe_offdiag r g i k (Ne.symm (Finset.ne_of_mem_erase hk))]) + +lemma coupling_goe_row_tail {r : ℝ} (hr : 0 < r) (i : Fin n) (S : Finset (Fin n)) (t : ℝ) : + (gaussianCoordinates (MatrixCoordinates (Fin n))).real + {g | t < ∑ k∈S,coupling (goeDisorder r g) i k^2} ≤ + exp (-t/(4*r)+(S.card:ℝ)*log 2) := by + let e : S.erase i ↪ Fin n := ⟨Subtype.val,Subtype.val_injective⟩ + have havoid (k : S.erase i) : e k≠i := Finset.ne_of_mem_erase k.2 + have hm : MeasurableSet {v : S.erase i→ℝ | t < ∑ k,v k^2} := by measurability + simp_rw [coupling_goe_row_square_sum] + have heq := (goe_row_hasLaw hr.le i e havoid).measureReal_eq hm + change (gaussianCoordinates (MatrixCoordinates (Fin n))).real + {g | t < ∑ k : S.erase i,goeMatrix r g i k^2} = (Measure.pi (fun _ : S.erase i=>gaussianReal 0 (Real.toNNReal r))).real {v | t < ∑ k,v k^2} at heq + rw [heq] + apply (scaled_gaussian_square_tail hr t).trans + apply exp_le_exp.mpr + have hcard : (Fintype.card (S.erase i):ℝ) ≤ S.card := by + rw [Fintype.card_coe] + exact_mod_cast Finset.card_erase_le + exact add_le_add (le_refl _) (mul_le_mul_of_nonneg_right hcard (log_nonneg (show (1:ℝ) ≤ 2 by norm_num))) + +end SKRatioGaussian +end +end + +section +noncomputable section +namespace SKRatioGaussian +open MeasureTheory ProbabilityTheory Matrix Real Set +open scoped BigOperators +variable {n : ℕ} + +lemma coupling_goe_all_rows_tail [NeZero n] {j t : ℝ} (hj : 0 < j) : + (gaussianCoordinates (MatrixCoordinates (Fin n))).real + {g | ∃ i : Fin n,t < ∑ k,coupling (goeDisorder (j/(n:ℝ)) g) i k^2} ≤ + (n:ℝ)*exp (-(n:ℝ)*(t/(4*j)-log 2)) := by + have hn : (0:ℝ) < n := by exact_mod_cast NeZero.pos n + have he : {g : MatrixCoordinates (Fin n)→ℝ | ∃ i : Fin n,t < ∑ k,coupling (goeDisorder (j/(n:ℝ)) g) i k^2}= + ⋃ i : Fin n,{g | t < ∑ k,coupling (goeDisorder (j/(n:ℝ)) g) i k^2} := by ext g;simp + rw [he] + apply (measureReal_iUnion_fintype_le _).trans + have hb (i : Fin n) := coupling_goe_row_tail (div_pos hj hn) i Finset.univ t + simp only [Finset.card_univ,Fintype.card_fin] at hb + apply (Finset.sum_le_sum (fun i _=>hb i)).trans_eq + simp only [Finset.sum_const,Finset.card_univ,Fintype.card_fin,nsmul_eq_mul] + congr 2 + field_simp + ring + +lemma coupling_goe_max_entry_tail [NeZero n] {j d : ℝ} (hj : 0 < j) (hd : 0 ≤ d) : + (gaussianCoordinates (MatrixCoordinates (Fin n))).real + {g | ∃ i k : Fin n,d < |coupling (goeDisorder (j/(n:ℝ)) g) i k|} ≤ + 2*(n:ℝ)^2*exp (-(n:ℝ)*d^2/(4*j)) := by + have hn : (0:ℝ) < n := by exact_mod_cast NeZero.pos n + have hsingle (i k : Fin n) : + (gaussianCoordinates (MatrixCoordinates (Fin n))).real + {g | d < |coupling (goeDisorder (j/(n:ℝ)) g) i k|} ≤ + 2*exp (-(n:ℝ)*d^2/(4*j)) := by + have he : {g : MatrixCoordinates (Fin n)→ℝ | d < |coupling (goeDisorder (j/(n:ℝ)) g) i k|}= + {g | d^2 < ∑ l∈({k} : Finset (Fin n)),coupling (goeDisorder (j/(n:ℝ)) g) i l^2} := by + ext g + simp only [Finset.sum_singleton,Set.mem_ofPred_eq] + simpa only [sq_abs] using (sq_lt_sq₀ hd (abs_nonneg (coupling (goeDisorder (j/(n:ℝ)) g) i k))).symm + rw [he] + apply (coupling_goe_row_tail (div_pos hj hn) i {k} (d^2)).trans_eq + simp only [Finset.card_singleton,Nat.cast_one,one_mul,exp_add,exp_log (by norm_num : (0:ℝ) < 2)] + rw [mul_comm] + congr 2 + field_simp + have he : {g : MatrixCoordinates (Fin n)→ℝ | ∃ i k : Fin n,d < |coupling (goeDisorder (j/(n:ℝ)) g) i k|}= + ⋃ i : Fin n,⋃ k : Fin n,{g | d < |coupling (goeDisorder (j/(n:ℝ)) g) i k|} := by ext g;simp + rw [he] + apply (measureReal_iUnion_fintype_le _).trans + apply (Finset.sum_le_sum (fun i _=>(measureReal_iUnion_fintype_le _).trans (Finset.sum_le_sum (fun k _=>hsingle i k)))).trans_eq + simp only [Finset.sum_const,Finset.card_univ,Fintype.card_fin,nsmul_eq_mul] + ring +end SKRatioGaussian + +end +end + +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Matrices/GoeInverseLoopCentered.lean b/lean/OAI/Probability/SKRatio/Matrices/GoeInverseLoopCentered.lean new file mode 100644 index 0000000000000000000000000000000000000000..376ddec57a38d6fcad306e47b280175c6221c618 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Matrices/GoeInverseLoopCentered.lean @@ -0,0 +1,110 @@ +import Mathlib +import OAI.Probability.SKRatio.Matrices.MatrixEntryCLM +import OAI.Probability.SKRatio.Matrices.GaussianProductIntegral +import OAI.Probability.SKRatio.Matrices.IntegralProductDeviation + +namespace OAI + +section +section +noncomputable section +open MeasureTheory ProbabilityTheory InformationTheory Real Set +open scoped NNReal ENNReal +open Filter +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius ENNReal NNReal +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius NNReal +noncomputable section +open MeasureTheory ProbabilityTheory Real Set Filter +open MeasureTheory.Measure +open scoped ENNReal NNReal MeasureTheory Topology +open MeasureTheory +noncomputable section +namespace SKRatioGaussian +open Matrix Real MeasureTheory ProbabilityTheory +open scoped BigOperators Matrix.Norms.Frobenius NNReal ENNReal +variable {ι : Type*} [Fintype ι] [DecidableEq ι] + +theorem goe_inverse_loop_centered {r : ℝ} (hr : 0 ≤ r) (B : Matrix ι ι ℝ) (i : ι) + {K : Matrix ι ι ℝ → Matrix ι ι ℝ} {L T : ℝ≥0} {C : ℝ} + {s : Set (MatrixCoordinates ι → ℝ)} + (hK : LipschitzWith L K) (hC : ∀ M, opNorm (K M) ≤ C) + (hT : LipschitzWith T (fun g : EuclideanSpace ℝ (MatrixCoordinates ι) => + Matrix.trace (K (goeMatrix r g)*B))) (hT0 : 0 < T) + (hs : MeasurableSet s) + (hder : ∀ g ∈ s, ∀ b, HasDerivAt + (fun t : ℝ => K (goeMatrix r g+t • symmetricElementary i b) b i) + ((K (goeMatrix r g)*B*symmetricElementary i b*K (goeMatrix r g)) b i) 0) : + let μ := Measure.pi (fun _ : MatrixCoordinates ι => gaussianReal 0 1) + let Lπ : ℝ≥0 := L*(⟨sqrt (2*r),sqrt_nonneg _⟩ * + (Fintype.card (MatrixCoordinates ι) : ℝ≥0) ^ (1/(2:ℝ≥0∞)).toReal) + |(∫ g, (goeMatrix r g*K (goeMatrix r g)) i i ∂μ)- + r*(∫ g, Matrix.trace (K (goeMatrix r g)*B) ∂μ)*(∫ g, K (goeMatrix r g) i i ∂μ)| ≤ + (Fintype.card ι:ℝ)*(sqrt (2*r)*(Lπ:ℝ)+r*(2*C*opNorm B*C))*μ.real sᶜ+ + r*(C*((2*exp (π^2/8))*(T:ℝ))+C*opNorm B*C) := by + intro μ Lπ + have hC0 : 0 ≤ C := (norm_nonneg _).trans (hC 0) + have hcomp : LipschitzWith Lπ (fun g => K (goeMatrix r g)) := + hK.comp (goeMatrix_pi_lipschitz r) + have hf (a b : ι) : LipschitzWith Lπ (fun g => K (goeMatrix r g) a b) := by + simpa only [one_mul] using! (matrixEntry_lipschitz a b).comp hcomp + have hc (g : MatrixCoordinates ι → ℝ) (a b : ι) : + ‖K (goeMatrix r g) a b‖ ≤ C := by + simpa only [Real.norm_eq_abs] using (matrix_entry_le_opNorm _ a b).trans (hC _) + have hd (g : MatrixCoordinates ι → ℝ) (b : ι) : + ‖(K (goeMatrix r g)*B*symmetricElementary i b*K (goeMatrix r g)) b i‖ ≤ + 2*C*opNorm B*C := by + have he : ‖(K (goeMatrix r g)*B*symmetricElementary i b*K (goeMatrix r g)) b i‖ ≤ + ‖K (goeMatrix r g)*B*symmetricElementary i b*K (goeMatrix r g)‖ := by + simpa only [Real.norm_eq_abs] using! + matrix_entry_le_frobenius (K (goeMatrix r g)*B*symmetricElementary i b*K (goeMatrix r g)) b i + apply he.trans + apply (matrix_inverse_diff_bound _ _ _).trans + calc + _ ≤ C*(opNorm B*2)*C := by + exact mul_le_mul + (mul_le_mul (hC _) (mul_le_mul_of_nonneg_left (symmetricElementary_norm_le i b) (norm_nonneg _)) + (mul_nonneg (norm_nonneg _) (norm_nonneg _)) hC0) + (hC _) (norm_nonneg _) (mul_nonneg hC0 (mul_nonneg (norm_nonneg _) (by norm_num))) + _ = _ := by ring + have hz (g : MatrixCoordinates ι → ℝ) : + ‖∑ b, (K (goeMatrix r g)*B) b i*K (goeMatrix r g) b i‖ ≤ C*opNorm B*C := by + rw [Real.norm_eq_abs] + apply (goe_cross_contraction_bound _ _ _).trans + exact mul_le_mul (mul_le_mul_of_nonneg_right (hC _) (norm_nonneg _)) (hC _) + (norm_nonneg _) (mul_nonneg hC0 (norm_nonneg _)) + have hzi : Integrable (fun g => ∑ b, (K (goeMatrix r g)*B) b i*K (goeMatrix r g) b i) μ := + Integrable.mono' (integrable_const (C*opNorm B*C)) (by + have hc := hcomp.continuous + exact (continuous_finsetSum _ (fun b _ => + ((hc.mul continuous_const).matrix_elem b i).mul (hc.matrix_elem b i))).aestronglyMeasurable) + (ae_of_all _ hz) + have hi : Integrable (fun g => Matrix.trace (K (goeMatrix r g)*B)) μ := + gaussianProduct_integrable_lipschitz hT + have ht : (∫ g, |Matrix.trace (K (goeMatrix r g)*B)- + ∫ h, Matrix.trace (K (goeMatrix r h)*B) ∂μ| ∂μ) ≤ (2*exp (π^2/8))*(T:ℝ) := + gaussianProduct_centered_L1 hT hT0 + exact integral_loop_deviation hr hi (hf i i).continuous.aestronglyMeasurable + (ae_of_all _ (fun g => hc g i i)) hzi (ae_of_all _ hz) ht + (goe_inverse_loop_raw hr B i hf hc hd hs hder) + +end SKRatioGaussian + +noncomputable section +open MeasureTheory Set NormedSpace +open scoped Topology + +end +end +end +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Matrices/GoeMatrixQuadCoeff.lean b/lean/OAI/Probability/SKRatio/Matrices/GoeMatrixQuadCoeff.lean new file mode 100644 index 0000000000000000000000000000000000000000..fa58af3de14422901e62b45c7445bd746ef995bb --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Matrices/GoeMatrixQuadCoeff.lean @@ -0,0 +1,165 @@ +import Mathlib +import OAI.Probability.SKRatio.Matrices.DiagonalTMemLp +import OAI.Probability.SKRatio.Matrices.MatrixQuad + +namespace OAI + +section +section +noncomputable section +open MeasureTheory ProbabilityTheory InformationTheory Real Set +open scoped NNReal ENNReal +open Filter +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius ENNReal NNReal +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius NNReal +noncomputable section +open MeasureTheory ProbabilityTheory Real Set Filter +open MeasureTheory.Measure +open scoped ENNReal NNReal MeasureTheory Topology +open MeasureTheory +noncomputable section +noncomputable section +open MeasureTheory Set NormedSpace +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius +noncomputable section +open Set Real +open scoped Topology +noncomputable section +open Matrix Set Filter +open scoped Topology Matrix.Norms.Frobenius +noncomputable section +open Matrix NormedSpace ContinuousLinearMap +open scoped Matrix.Norms.Frobenius +noncomputable section +open Matrix +noncomputable section +open MeasureTheory ProbabilityTheory Real Set +open scoped ENNReal NNReal +noncomputable section +open MeasureTheory ProbabilityTheory InformationTheory Real Set +open scoped NNReal ENNReal +noncomputable section +open scoped BigOperators +open MeasureTheory ProbabilityTheory +open Real +noncomputable section +open scoped BigOperators Topology +open Filter Real +namespace SKRatioGaussian +section GOEEvents +variable {ι : Type*} [Fintype ι] [DecidableEq ι] [Nonempty ι] + +omit [DecidableEq ι] [Nonempty ι] in +lemma goeMatrix_quad_coeff (r : ℝ) (g : MatrixCoordinates ι → ℝ) + (p : EuclideanSpace ℝ ι) : + matrixQuad (goeMatrix r g) p = ∑ k, quadraticCoeff r p k * g k := by + rw [goeMatrix_quad, Fintype.sum_sum_type] + simp only [quadraticCoeff, zero_mul, Finset.sum_const_zero, add_zero, + Fintype.sum_prod_type] + +omit [DecidableEq ι] [Nonempty ι] in +lemma diagonal_affine_matrix (r z q : ℝ) (a : ι → ℝ) + (g : MatrixCoordinates ι → ℝ) (p : UnitBall ι) : + gaussianAffine (diagonalOffset a z q) + (fun p k => z * quadraticCoeff r (diagonalSqrt a p) k) g p = + z * matrixQuad (goeMatrix r g) (diagonalSqrt a p) - + z^2*q*‖diagonalSqrt a p‖^2 := by + rw [goeMatrix_quad_coeff] + simp only [gaussianAffine, diagonalOffset, Finset.mul_sum] + simp_rw [mul_assoc] + ring + +omit [Fintype ι] [DecidableEq ι] [Nonempty ι] in +lemma diagonalSqrt_one (p : EuclideanSpace ℝ ι) : + diagonalSqrt (fun _ : ι => 1) p = p := by + ext i + simp [diagonalSqrt] + +omit [DecidableEq ι] [Nonempty ι] in +lemma goe_quad_le_top (r : ℝ) (g : MatrixCoordinates ι → ℝ) + (p : EuclideanSpace ℝ ι) (hp : ‖p‖ ≤ 1) : + matrixQuad (goeMatrix r g) p ≤ diagonalProcess r (fun _ : ι => 1) 1 0 g := by + let p' : UnitBall ι := ⟨p, by simpa only [Metric.mem_closedBall, dist_zero_right] using hp⟩ + have h := gaussianAffine_le_gaussianSup (continuous_diagonalOffset (fun _ : ι => 1) 1 0) + (continuous_diagonalCoeff (continuous_quadraticCoeff r) (fun _ : ι => 1) 1) g p' + rw [diagonal_affine_matrix, diagonalSqrt_one] at h + simpa only [one_mul, mul_zero, zero_mul, sub_zero, diagonalProcess, p'] using h + +omit [DecidableEq ι] [Nonempty ι] in +lemma matrixQuad_neg (M : Matrix ι ι ℝ) (p : EuclideanSpace ℝ ι) : + matrixQuad (-M) p = -matrixQuad M p := by + simp [matrixQuad, Finset.sum_neg_distrib] + +omit [Nonempty ι] in +lemma goe_norm_le_of_top {r R : ℝ} (hR : 0 ≤ R) (g : MatrixCoordinates ι → ℝ) + (hpos : diagonalProcess r (fun _ : ι => 1) 1 0 g ≤ R) + (hneg : diagonalProcess r (fun _ : ι => 1) 1 0 (-g) ≤ R) : + ‖matrixOperator (goeMatrix r g)‖ ≤ R := by + apply matrixOperator_norm_le_of_quad (goeMatrix_symm r g) hR + intro p hp + apply abs_le.mpr + constructor + · have h := (goe_quad_le_top r (-g) p hp).trans hneg + rw [goeMatrix_neg, matrixQuad_neg] at h + linarith + · exact (goe_quad_le_top r g p hp).trans hpos + +theorem goe_norm_tail {j ε : ℝ} (hj : 0 < j) (hε : 0 ≤ ε) : + (gaussianCoordinates (MatrixCoordinates ι)).real + {g | 2*sqrt j+ε < ‖matrixOperator (goeMatrix (j/(Fintype.card ι:ℝ)) g)‖} ≤ + 2*Real.exp (-ε^2*(Fintype.card ι:ℝ)/(π^2*j)) := by + let r := j/(Fintype.card ι:ℝ) + let R := 2*sqrt j+ε + let P := diagonalProcess r (fun _ : ι => 1) 1 0 + let E : Set (MatrixCoordinates ι → ℝ) := {g | R < P g} + have hc : Continuous P := continuous_gaussianSup + (continuous_diagonalOffset (fun _ : ι => 1) 1 0) + (continuous_diagonalCoeff (continuous_quadraticCoeff r) (fun _ : ι => 1) 1) + have hm : MeasurableSet E := measurableSet_lt measurable_const hc.measurable + have hp := goe_top_tail (ι := ι) hj hε + have hn : (gaussianCoordinates (MatrixCoordinates ι)).real {g | R < P (-g)} = + (gaussianCoordinates (MatrixCoordinates ι)).real E := by + exact congrArg ENNReal.toReal (gaussianCoordinates_preserving_neg.measure_preimage hm.nullMeasurableSet) + have hs : {g : MatrixCoordinates ι → ℝ | R < ‖matrixOperator (goeMatrix r g)‖} ⊆ E ∪ {g | R < P (-g)} := by + intro g hg + by_contra hh + have hh' : ¬ R < P g ∧ ¬ R < P (-g) := by simpa only [Set.mem_union, E, Set.mem_ofPred_eq, not_or] using hh + exact (not_lt_of_ge (goe_norm_le_of_top (by dsimp [R]; positivity) g + (le_of_not_gt hh'.1) (le_of_not_gt hh'.2))) hg + calc + _ ≤ (gaussianCoordinates (MatrixCoordinates ι)).real (E ∪ {g | R < P (-g)}) := measureReal_mono hs + _ ≤ (gaussianCoordinates (MatrixCoordinates ι)).real E + + (gaussianCoordinates (MatrixCoordinates ι)).real {g | R < P (-g)} := measureReal_union_le _ _ + _ = 2*(gaussianCoordinates (MatrixCoordinates ι)).real E := by rw [hn]; ring + _ ≤ _ := mul_le_mul_of_nonneg_left hp (by norm_num) + +end GOEEvents +end SKRatioGaussian + +end +end +end +end +end +end +end +end +end +end +end +end +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Matrices/Imaginary.lean b/lean/OAI/Probability/SKRatio/Matrices/Imaginary.lean new file mode 100644 index 0000000000000000000000000000000000000000..2a996ffcc9103bac5980b9e6ba04396668b57af0 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Matrices/Imaginary.lean @@ -0,0 +1,148 @@ +import Mathlib +import OAI.Probability.SKRatio.Matrices.LinSub + +namespace OAI + +section +section +noncomputable section +open MeasureTheory ProbabilityTheory InformationTheory Real Set +open scoped NNReal ENNReal +open Filter +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius ENNReal NNReal +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius NNReal +noncomputable section +open MeasureTheory ProbabilityTheory Real Set Filter +open MeasureTheory.Measure +open scoped ENNReal NNReal MeasureTheory Topology +open MeasureTheory +noncomputable section +noncomputable section +open MeasureTheory Set NormedSpace +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius +namespace SKRatioGaussian.ComplexMatrix +open MeasureTheory Set NormedSpace +open scoped Topology FourierTransform SchwartzMap +variable {ι : Type*} [Fintype ι] [DecidableEq ι] + +local instance : ContinuousENorm (Matrix ι ι ℂ) := + @SeminormedAddGroup.toContinuousENorm _ Matrix.frobeniusSeminormedAddCommGroup.toSeminormedAddGroup +local instance : TopologicalSpace.PseudoMetrizableSpace (Matrix ι ι ℂ) := + inferInstanceAs (TopologicalSpace.PseudoMetrizableSpace (ι → ι → ℂ)) + +lemma lin_csmul (z : ℂ) (M : Matrix ι ι ℂ) : lin (z • M) = z • lin M := + (linEquiv (ι := ι)).map_smul z M + +lemma opNorm_csmul (z : ℂ) (M : Matrix ι ι ℂ) : opNorm (z • M) = ‖z‖ * opNorm M := by + simp only [opNorm,lin_csmul,norm_smul] + +noncomputable def imaginary (t : ℝ) (M : Matrix ι ι ℂ) : Matrix ι ι ℂ := + ((t : ℂ)*Complex.I) • M + +omit [Fintype ι] [DecidableEq ι] in +lemma imaginary_skew (t : ℝ) (M : Matrix ι ι ℂ) (hM : Mᴴ = M) : + (imaginary t M)ᴴ = -(imaginary t M) := by + simp [imaginary,Matrix.conjTranspose_smul,hM,star_mul,mul_comm] + +lemma imaginary_norm (t : ℝ) (M : Matrix ι ι ℂ) : ‖imaginary t M‖ = |t| * ‖M‖ := by + simp [imaginary,norm_smul] + +lemma imaginary_opNorm (t : ℝ) (M : Matrix ι ι ℂ) : opNorm (imaginary t M) = |t| * opNorm M := by + simp [imaginary,opNorm_csmul] + +omit [Fintype ι] [DecidableEq ι] in +lemma imaginary_sub (t : ℝ) (M N : Matrix ι ι ℂ) : + imaginary t (M-N) = imaginary t M-imaginary t N := by simp [imaginary,smul_sub] + +lemma imaginary_exp_unitary (t : ℝ) (M : Matrix ι ι ℂ) (hM : Mᴴ = M) : + exp (imaginary t M) ∈ unitary (Matrix ι ι ℂ) := by + simpa using unitary_exp_smul _ (imaginary_skew t M hM) 1 + +lemma imaginary_exp_norm (t : ℝ) (M : Matrix ι ι ℂ) (hM : Mᴴ = M) : + ‖exp (imaginary t M)‖ = ‖(1 : Matrix ι ι ℂ)‖ := by + simpa using frobenius_unitary_mul (exp (imaginary t M)) 1 (imaginary_exp_unitary t M hM) + +lemma imaginary_exp_opNorm_le (t : ℝ) (M : Matrix ι ι ℂ) (hM : Mᴴ = M) : + opNorm (exp (imaginary t M)) ≤ 1 := by + apply ContinuousLinearMap.opNorm_le_bound _ (by norm_num) + intro x + rw [ContinuousLinearMap.norm_map_of_mem_unitary (lin_unitary _ (imaginary_exp_unitary t M hM))] + simp + +noncomputable def kernelMatrix (g : ℝ → ℂ) (M : Matrix ι ι ℂ) : Matrix ι ι ℂ := + ∫ t : ℝ, g t • exp (imaginary t M) + +lemma kernel_integrable {g : ℝ → ℂ} (hg : Integrable g) (M : Matrix ι ι ℂ) (hM : Mᴴ = M) : + Integrable (fun t : ℝ => g t • exp (imaginary t M)) := by + have hc : Continuous (fun t : ℝ => exp (imaginary t M)) := by dsimp [imaginary]; fun_prop + apply (hg.norm.mul_const ‖(1 : Matrix ι ι ℂ)‖).mono' (hg.aestronglyMeasurable.smul hc.aestronglyMeasurable) + filter_upwards [] with t + change ‖g t • exp (imaginary t M)‖ ≤ _ + rw [norm_smul,imaginary_exp_norm t M hM] + +lemma kernelMatrix_lipschitz {g : ℝ → ℂ} (hg : Integrable g) + (hg₁ : Integrable (fun t : ℝ => ‖g t‖*|t|)) + (M N : Matrix ι ι ℂ) (hM : Mᴴ = M) (hN : Nᴴ = N) : + ‖kernelMatrix g M-kernelMatrix g N‖ ≤ (∫ t : ℝ, ‖g t‖*|t|) * ‖M-N‖ := by + rw [kernelMatrix,kernelMatrix,← integral_sub (kernel_integrable hg M hM) (kernel_integrable hg N hN)] + calc + _ ≤ ∫ t : ℝ, ‖g t • exp (imaginary t M)-g t • exp (imaginary t N)‖ := norm_integral_le_integral_norm _ + _ ≤ ∫ t : ℝ, (‖g t‖*|t|)*‖M-N‖ := by + apply integral_mono ((kernel_integrable hg M hM).sub (kernel_integrable hg N hN)).norm (hg₁.mul_const _) + intro t + dsimp only [Pi.sub_apply] + rw [← smul_sub,norm_smul] + have hh := frobenius_exp_sub _ _ (imaginary_skew t M hM) (imaginary_skew t N hN) + rw [← imaginary_sub,imaginary_norm] at hh + exact (mul_le_mul_of_nonneg_left hh (norm_nonneg _)).trans_eq (mul_assoc _ _ _).symm + _ = _ := integral_mul_const _ _ + +lemma kernelMatrix_four_point {g : ℝ → ℂ} (hg : Integrable g) + (hg₁ : Integrable (fun t : ℝ => ‖g t‖*|t|)) + (hg₂ : Integrable (fun t : ℝ => ‖g t‖*|t|^2)) + (a b c d : Matrix ι ι ℂ) (ha : aᴴ = a) (hb : bᴴ = b) (hc : cᴴ = c) (hd : dᴴ = d) : + ‖(kernelMatrix g a-kernelMatrix g b)-(kernelMatrix g c-kernelMatrix g d)‖ ≤ + (∫ t : ℝ, ‖g t‖*|t|)*‖(a-b)-(c-d)‖ + + (∫ t : ℝ, ‖g t‖*|t|^2)*(opNorm (a-c)+opNorm (b-d))*‖c-d‖ := by + let F := fun (M : Matrix ι ι ℂ) (t : ℝ) => g t • exp (imaginary t M) + have hi (M : Matrix ι ι ℂ) (hM : Mᴴ = M) : Integrable (F M) := kernel_integrable hg M hM + have hi' := ((hi a ha).sub (hi b hb)).sub ((hi c hc).sub (hi d hd)) + change ‖((∫ t, F a t)-(∫ t, F b t))-((∫ t, F c t)-(∫ t, F d t))‖ ≤ _ + rw [← integral_sub (hi a ha) (hi b hb),← integral_sub (hi c hc) (hi d hd), + ← integral_sub (f := fun t => F a t-F b t) (g := fun t => F c t-F d t) + ((hi a ha).sub (hi b hb)) ((hi c hc).sub (hi d hd))] + calc + _ ≤ ∫ t : ℝ, ‖(F a t-F b t)-(F c t-F d t)‖ := norm_integral_le_integral_norm _ + _ ≤ ∫ t : ℝ, (‖g t‖*|t|)*‖(a-b)-(c-d)‖ + + (‖g t‖*|t|^2)*(opNorm (a-c)+opNorm (b-d))*‖c-d‖ := by + apply integral_mono hi'.norm ((hg₁.mul_const _).add ((hg₂.mul_const _).mul_const _)) + intro t + dsimp only [F,Pi.sub_apply] + rw [← smul_sub,← smul_sub,← smul_sub,norm_smul] + have hh := exp_four_point (imaginary t a) (imaginary t b) (imaginary t c) (imaginary t d) + (imaginary_skew t a ha) (imaginary_skew t b hb) (imaginary_skew t c hc) (imaginary_skew t d hd) + simp only [← imaginary_sub,imaginary_norm,imaginary_opNorm] at hh + exact (mul_le_mul_of_nonneg_left hh (norm_nonneg _)).trans_eq (by dsimp only [Pi.add_apply]; ring) + _ = _ := by rw [integral_add (hg₁.mul_const _) ((hg₂.mul_const _).mul_const _)]; simp only [integral_mul_const] + +end SKRatioGaussian.ComplexMatrix + +end +end +end +end +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Matrices/IntegralAbsSet.lean b/lean/OAI/Probability/SKRatio/Matrices/IntegralAbsSet.lean new file mode 100644 index 0000000000000000000000000000000000000000..318b4927c39804da961eaff009cae2b14e4158cb --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Matrices/IntegralAbsSet.lean @@ -0,0 +1,100 @@ +import Mathlib + +namespace OAI + +section +section +noncomputable section +open MeasureTheory ProbabilityTheory InformationTheory Real Set +open scoped NNReal ENNReal +open Filter +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius ENNReal NNReal +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius NNReal +noncomputable section +open MeasureTheory ProbabilityTheory Real Set Filter +open MeasureTheory.Measure +open scoped ENNReal NNReal MeasureTheory Topology +open MeasureTheory +noncomputable section +noncomputable section +open MeasureTheory Set NormedSpace +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius +noncomputable section +open Set Real +open scoped Topology +noncomputable section +open Matrix Set Filter +open scoped Topology Matrix.Norms.Frobenius +noncomputable section +open Matrix NormedSpace ContinuousLinearMap +open scoped Matrix.Norms.Frobenius +noncomputable section +open Matrix +noncomputable section +open MeasureTheory ProbabilityTheory Real Set +open scoped ENNReal NNReal +namespace SKRatioGaussian +variable {Ω : Type*} [MeasurableSpace Ω] {μ : Measure Ω} [IsProbabilityMeasure μ] + +lemma integral_abs_on_set_le {F : Ω → ℝ} (hF : MemLp F 2 μ) + {s : Set Ω} (hs : MeasurableSet s) : + (∫ x in s, |F x| ∂μ) ≤ sqrt (∫ x, (F x)^2 ∂μ)*sqrt (μ.real s) := by + have hG : MemLp (s.indicator (fun _ : Ω => (1:ℝ))) 2 μ := + memLp_indicator_const 2 hs 1 (Or.inr (measure_ne_top _ _)) + have hh := integral_mul_norm_le_Lp_mul_Lq Real.HolderConjugate.two_two + (by simpa using hF) (by simpa using hG) + have he : (fun x => ‖F x‖*‖s.indicator (fun _ : Ω => (1:ℝ)) x‖) = + s.indicator (fun x => |F x|) := by + funext x + by_cases hx : x ∈ s <;> simp [hx,Real.norm_eq_abs] + have hg : (fun x => ‖s.indicator (fun _ : Ω => (1:ℝ)) x‖^(2:ℝ)) = + s.indicator (fun _ : Ω => (1:ℝ)) := by + funext x + by_cases hx : x ∈ s <;> simp [hx] + rw [he,hg,integral_indicator hs,integral_indicator hs] at hh + simpa only [Real.rpow_two,Real.norm_eq_abs,sq_abs,← Real.sqrt_eq_rpow, + integral_const,smul_eq_mul,mul_one,measureReal_restrict_apply_univ] using hh + +omit [IsProbabilityMeasure μ] in +lemma integral_exceptional_equal_bound {F G H : Ω → ℝ} {s : Set Ω} + (hs : MeasurableSet s) (hF : Integrable F μ) (hG : Integrable G μ) + (hH : Integrable H μ) (he : ∀ x ∉ s, F x=G x) + (hb : ∀ x ∈ s, ‖F x-G x‖ ≤ H x) : + |(∫ x, F x ∂μ)-(∫ x, G x ∂μ)| ≤ ∫ x in s, H x ∂μ := by + rw [← integral_sub hF hG] + rw [← Real.norm_eq_abs] + apply (norm_integral_le_integral_norm _).trans + rw [← integral_indicator hs] + apply integral_mono ((hF.sub hG).norm) (hH.indicator hs) + intro x + change ‖F x-G x‖ ≤ s.indicator H x + by_cases hx : x∈s + · simpa only [Set.indicator_of_mem hx] using hb x hx + · simp only [Set.indicator_of_notMem hx,he x hx,sub_self,norm_zero,le_refl] + +end SKRatioGaussian + +end +end +end +end +end +end +end +end +end +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Matrices/IntegralProductDeviation.lean b/lean/OAI/Probability/SKRatio/Matrices/IntegralProductDeviation.lean new file mode 100644 index 0000000000000000000000000000000000000000..00938ee02eae2e6206e57ceb9b4dd71ef24524c0 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Matrices/IntegralProductDeviation.lean @@ -0,0 +1,87 @@ +import Mathlib + +namespace OAI + +section +section +noncomputable section +open MeasureTheory ProbabilityTheory InformationTheory Real Set +open scoped NNReal ENNReal +open Filter +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius ENNReal NNReal +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius NNReal +noncomputable section +open MeasureTheory ProbabilityTheory Real Set Filter +open MeasureTheory.Measure +open scoped ENNReal NNReal MeasureTheory Topology +open MeasureTheory +noncomputable section +namespace SKRatioGaussian +variable {Ω : Type*} [MeasurableSpace Ω] {μ : Measure Ω} [IsProbabilityMeasure μ] + +lemma integral_product_deviation {X Y : Ω → ℝ} {C T : ℝ} + (hX : Integrable X μ) (hY : AEStronglyMeasurable Y μ) + (hC : ∀ᵐ x ∂μ, ‖Y x‖ ≤ C) + (hT : (∫ x, |X x-∫ y, X y ∂μ| ∂μ) ≤ T) : + |(∫ x, X x*Y x ∂μ)-(∫ x, X x ∂μ)*(∫ x, Y x ∂μ)| ≤ C*T := by + have hC0 : 0 ≤ C := by + obtain ⟨x,hx⟩ := hC.exists + exact (norm_nonneg _).trans hx + have hYi : Integrable Y μ := (integrable_const C).mono' hY hC + have hXY : Integrable (fun x => X x*Y x) μ := by + simpa only [mul_comm] using hX.bdd_mul hY hC + have hcenter : Integrable (fun x => X x-∫ y, X y ∂μ) μ := hX.sub (integrable_const _) + have hci : Integrable (fun x => (X x-∫ y, X y ∂μ)*Y x) μ := by + simpa only [mul_comm] using hcenter.bdd_mul hY hC + have he : (∫ x, X x*Y x ∂μ)-(∫ x, X x ∂μ)*(∫ x, Y x ∂μ) = + ∫ x, (X x-∫ y, X y ∂μ)*Y x ∂μ := by + simp_rw [sub_mul] + rw [integral_sub hXY (hYi.const_mul _),integral_const_mul] + rw [he] + calc + _ ≤ ∫ x, ‖(X x-∫ y, X y ∂μ)*Y x‖ ∂μ := norm_integral_le_integral_norm _ + _ ≤ ∫ x, C*|X x-∫ y, X y ∂μ| ∂μ := by + apply integral_mono_ae hci.norm (hcenter.norm.const_mul C) + filter_upwards [hC] with x hx + simpa only [norm_mul,Real.norm_eq_abs,mul_comm] using + mul_le_mul_of_nonneg_left hx (norm_nonneg (X x-∫ y, X y ∂μ)) + _ = C*(∫ x, |X x-∫ y, X y ∂μ| ∂μ) := integral_const_mul _ _ + _ ≤ _ := mul_le_mul_of_nonneg_left hT hC0 + +lemma integral_loop_deviation {X Y Z V : Ω → ℝ} {r C T B E : ℝ} + (hr : 0 ≤ r) (hX : Integrable X μ) (hY : AEStronglyMeasurable Y μ) + (hC : ∀ᵐ x ∂μ, ‖Y x‖ ≤ C) + (hZ : Integrable Z μ) (hB : ∀ᵐ x ∂μ, ‖Z x‖ ≤ B) + (hT : (∫ x, |X x-∫ y, X y ∂μ| ∂μ) ≤ T) + (hE : |(∫ x, V x ∂μ)-r*(∫ x, X x*Y x+Z x ∂μ)| ≤ E) : + |(∫ x, V x ∂μ)-r*(∫ x, X x ∂μ)*(∫ x, Y x ∂μ)| ≤ E+r*(C*T+B) := by + have hXY : Integrable (fun x => X x*Y x) μ := by + simpa only [mul_comm] using hX.bdd_mul hY hC + have hbound := integral_product_deviation hX hY hC hT + have hb : |∫ x, Z x ∂μ| ≤ B := by + exact (norm_integral_le_integral_norm _).trans ((integral_mono_ae hZ.norm (integrable_const B) hB).trans_eq (by simp)) + have he : (∫ x, V x ∂μ)-r*(∫ x, X x ∂μ)*(∫ x, Y x ∂μ) = + ((∫ x, V x ∂μ)-r*(∫ x, X x*Y x+Z x ∂μ))+ + r*((∫ x, X x*Y x ∂μ)-(∫ x, X x ∂μ)*(∫ x, Y x ∂μ)+(∫ x, Z x ∂μ)) := by + rw [integral_add hXY hZ]; ring + rw [he] + exact (abs_add_le _ _).trans (add_le_add hE (by + rw [abs_mul,abs_of_nonneg hr] + exact mul_le_mul_of_nonneg_left ((abs_add_le _ _).trans (add_le_add hbound hb)) hr)) + +end SKRatioGaussian + +end +end +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Matrices/InverseSubSquareMul.lean b/lean/OAI/Probability/SKRatio/Matrices/InverseSubSquareMul.lean new file mode 100644 index 0000000000000000000000000000000000000000..a5f00f2acc135db6415d32747f38a3fa3bfe0e19 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Matrices/InverseSubSquareMul.lean @@ -0,0 +1,92 @@ +import Mathlib + +namespace OAI + +section +section +noncomputable section +open MeasureTheory ProbabilityTheory InformationTheory Real Set +open scoped NNReal ENNReal +open Filter +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius ENNReal NNReal +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius NNReal +noncomputable section +open MeasureTheory ProbabilityTheory Real Set Filter +open MeasureTheory.Measure +open scoped ENNReal NNReal MeasureTheory Topology +open MeasureTheory +noncomputable section +noncomputable section +open MeasureTheory Set NormedSpace +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius +noncomputable section +open Set Real +open scoped Topology +noncomputable section +open Matrix Set Filter +open scoped Topology Matrix.Norms.Frobenius +noncomputable section +open Matrix NormedSpace ContinuousLinearMap +open scoped Matrix.Norms.Frobenius +noncomputable section +open Matrix +namespace SKRatioGaussian.ResolventIdentity +variable {ι : Type*} [Fintype ι] [DecidableEq ι] +variable {𝕜 : Type*} [RCLike 𝕜] + +lemma inverse_one_sub_square_mul (D V : Matrix ι ι 𝕜) + (hS : IsUnit (1-D*V*D)) : + (1-D*D*V)⁻¹ = 1+D*(1-D*V*D)⁻¹*D*V := by + apply Matrix.inv_eq_right_inv + have hSS : (1-D*V*D)*(1-D*V*D)⁻¹ = 1 := + Matrix.mul_nonsing_inv _ (((1-D*V*D).isUnit_iff_isUnit_det).mp hS) + calc + _ = (1-D*D*V)+D*((1-D*V*D)*(1-D*V*D)⁻¹)*D*V := by noncomm_ring + _ = 1 := by rw [hSS]; noncomm_ring + +lemma inverse_one_sub_square_mul_unit (D V : Matrix ι ι 𝕜) + (hS : IsUnit (1-D*V*D)) : IsUnit (1-D*D*V) := by + have hSS : (1-D*V*D)*(1-D*V*D)⁻¹ = 1 := + Matrix.mul_nonsing_inv _ (((1-D*V*D).isUnit_iff_isUnit_det).mp hS) + apply ((1-D*D*V).isUnit_iff_isUnit_det).mpr + have hh : (1-D*D*V)*(1+D*(1-D*V*D)⁻¹*D*V) = 1 := by + calc + _ = (1-D*D*V)+D*((1-D*V*D)*(1-D*V*D)⁻¹)*D*V := by noncomm_ring + _ = 1 := by rw [hSS]; noncomm_ring + exact Matrix.isUnit_det_of_right_inverse hh + +lemma inverse_one_sub_square_mul_square (D V : Matrix ι ι 𝕜) + (hS : IsUnit (1-D*V*D)) : + (1-D*D*V)⁻¹*(D*D) = D*(1-D*V*D)⁻¹*D := by + rw [inverse_one_sub_square_mul D V hS] + have hSS : (1-D*V*D)⁻¹*(1-D*V*D) = 1 := + Matrix.nonsing_inv_mul _ (((1-D*V*D).isUnit_iff_isUnit_det).mp hS) + calc + _ = D*(1-D*V*D)⁻¹*D+D*(1-(1-D*V*D)⁻¹*(1-D*V*D))*D := by noncomm_ring + _ = _ := by rw [hSS]; simp + +end SKRatioGaussian.ResolventIdentity + +end +end +end +end +end +end +end +end +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Matrices/LiftMatrix.lean b/lean/OAI/Probability/SKRatio/Matrices/LiftMatrix.lean new file mode 100644 index 0000000000000000000000000000000000000000..7bc7de46373cff2885fceed94a8c73526e6f27af --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Matrices/LiftMatrix.lean @@ -0,0 +1,159 @@ +import Mathlib +import OAI.Probability.SKRatio.Matrices.OpNorm + +namespace OAI + +section +section +noncomputable section +open MeasureTheory ProbabilityTheory InformationTheory Real Set +open scoped NNReal ENNReal +open Filter +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius ENNReal NNReal +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius NNReal +noncomputable section +open MeasureTheory ProbabilityTheory Real Set Filter +open MeasureTheory.Measure +open scoped ENNReal NNReal MeasureTheory Topology +open MeasureTheory +noncomputable section +noncomputable section +open MeasureTheory Set NormedSpace +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius +noncomputable section +open Set Real +open scoped Topology +noncomputable section +open Matrix Set Filter +open scoped Topology Matrix.Norms.Frobenius +noncomputable section +open Matrix NormedSpace ContinuousLinearMap +open scoped Matrix.Norms.Frobenius +noncomputable section +open Matrix +namespace SKRatioGaussian.RealComplex +open scoped Matrix.Norms.Frobenius +variable {ι : Type*} [Fintype ι] [DecidableEq ι] + +def liftMatrix (M : Matrix ι ι ℝ) : Matrix ι ι ℂ := M.map Complex.ofReal +abbrev clin (M : Matrix ι ι ℂ) := M.toEuclideanLin.toContinuousLinearMap +abbrev rlin (M : Matrix ι ι ℝ) := M.toEuclideanLin.toContinuousLinearMap + +def reVec (x : EuclideanSpace ℂ ι) : EuclideanSpace ℝ ι := + WithLp.toLp 2 (fun i => (x i).re) +def imVec (x : EuclideanSpace ℂ ι) : EuclideanSpace ℝ ι := + WithLp.toLp 2 (fun i => (x i).im) +def liftVec (x : EuclideanSpace ℝ ι) : EuclideanSpace ℂ ι := + WithLp.toLp 2 (fun i => (x i : ℂ)) + +omit [DecidableEq ι] in +lemma vec_norm_split (x : EuclideanSpace ℂ ι) : + ‖x‖^2 = ‖reVec x‖^2+‖imVec x‖^2 := by + simp only [EuclideanSpace.norm_sq_eq,← Finset.sum_add_distrib] + apply Finset.sum_congr rfl + intro i _ + change ‖x i‖^2 = ‖(x i).re‖^2+‖(x i).im‖^2 + rw [Complex.sq_norm,Complex.normSq_apply] + simp only [Real.norm_eq_abs] + rw [sq_abs,sq_abs] + ring + +omit [DecidableEq ι] in +lemma norm_liftVec (x : EuclideanSpace ℝ ι) : ‖liftVec x‖ = ‖x‖ := by + have hh : ‖liftVec x‖^2 = ‖x‖^2 := by simp [EuclideanSpace.norm_sq_eq,liftVec] + nlinarith [norm_nonneg (liftVec x),norm_nonneg x] + +lemma reVec_clin (M : Matrix ι ι ℝ) (x : EuclideanSpace ℂ ι) : + reVec (clin (liftMatrix M) x) = rlin M (reVec x) := by + ext i + change (∑ j, (M i j : ℂ)*x j).re = ∑ j, M i j*(x j).re + simp + +lemma imVec_clin (M : Matrix ι ι ℝ) (x : EuclideanSpace ℂ ι) : + imVec (clin (liftMatrix M) x) = rlin M (imVec x) := by + ext i + change (∑ j, (M i j : ℂ)*x j).im = ∑ j, M i j*(x j).im + simp + +lemma clin_liftVec (M : Matrix ι ι ℝ) (x : EuclideanSpace ℝ ι) : + clin (liftMatrix M) (liftVec x) = liftVec (rlin M x) := by + ext i + change (∑ j, (M i j : ℂ)*(x j : ℂ)) = ((∑ j, M i j*x j : ℝ) : ℂ) + simp + +lemma operator_norm_lift (M : Matrix ι ι ℝ) : ‖clin (liftMatrix M)‖ = opNorm M := by + apply le_antisymm + · apply ContinuousLinearMap.opNorm_le_bound _ (norm_nonneg _) + intro x + apply nonneg_le_nonneg_of_sq_le_sq (mul_nonneg (norm_nonneg _) (norm_nonneg _)) + simp only [← sq] + change ‖clin (liftMatrix M) x‖^2 ≤ (opNorm M*‖x‖)^2 + rw [vec_norm_split,reVec_clin,imVec_clin,mul_pow,vec_norm_split,mul_add] + have hr := (rlin M).le_opNorm (reVec x) + have hi := (rlin M).le_opNorm (imVec x) + change ‖rlin M (reVec x)‖ ≤ opNorm M*‖reVec x‖ at hr + change ‖rlin M (imVec x)‖ ≤ opNorm M*‖imVec x‖ at hi + nlinarith [norm_nonneg (rlin M (reVec x)),norm_nonneg (rlin M (imVec x)), + mul_nonneg (norm_nonneg (rlin M)) (norm_nonneg (reVec x)), + mul_nonneg (norm_nonneg (rlin M)) (norm_nonneg (imVec x))] + · apply ContinuousLinearMap.opNorm_le_bound _ (norm_nonneg _) + intro x + have hh := (clin (liftMatrix M)).le_opNorm (liftVec x) + rwa [clin_liftVec,norm_liftVec,norm_liftVec] at hh + +lemma norm_liftMatrix (M : Matrix ι ι ℝ) : ‖liftMatrix M‖ = ‖M‖ := + Matrix.frobenius_norm_map_eq M Complex.ofReal (fun x => by simp) + +omit [Fintype ι] [DecidableEq ι] in +lemma liftMatrix_sub (M N : Matrix ι ι ℝ) : + liftMatrix (M-N) = liftMatrix M-liftMatrix N := by ext i j; simp [liftMatrix] +omit [Fintype ι] [DecidableEq ι] in +lemma liftMatrix_add (M N : Matrix ι ι ℝ) : + liftMatrix (M+N) = liftMatrix M+liftMatrix N := by ext i j; simp [liftMatrix] +omit [DecidableEq ι] in +lemma liftMatrix_mul (M N : Matrix ι ι ℝ) : + liftMatrix (M*N) = liftMatrix M*liftMatrix N := by + exact Matrix.map_mul (f := Complex.ofRealHom) +omit [Fintype ι] in +lemma liftMatrix_one : liftMatrix (1 : Matrix ι ι ℝ) = 1 := + Matrix.map_one Complex.ofReal (by simp) (by simp) +omit [Fintype ι] [DecidableEq ι] in +lemma liftMatrix_smul (s : ℝ) (M : Matrix ι ι ℝ) : + liftMatrix (s • M) = s • liftMatrix M := by ext i j; simp [liftMatrix] +omit [Fintype ι] [DecidableEq ι] in +lemma liftMatrix_conjTranspose (M : Matrix ι ι ℝ) : + (liftMatrix M)ᴴ = liftMatrix Mᵀ := by ext i j; simp [liftMatrix] +omit [Fintype ι] [DecidableEq ι] in +lemma liftMatrix_hermitian (M : Matrix ι ι ℝ) (hM : Mᵀ = M) : + (liftMatrix M)ᴴ = liftMatrix M := by rw [liftMatrix_conjTranspose,hM] +omit [Fintype ι] [DecidableEq ι] in +lemma liftMatrix_injective : Function.Injective (liftMatrix (ι := ι)) := by + intro M N h + ext i j + exact Complex.ofReal_injective (congrFun (congrFun h i) j) + +end SKRatioGaussian.RealComplex + +end +end +end +end +end +end +end +end +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Matrices/Lin.lean b/lean/OAI/Probability/SKRatio/Matrices/Lin.lean new file mode 100644 index 0000000000000000000000000000000000000000..7acc7019b2e3ab643fdd3d3935b8d2955b240b0e --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Matrices/Lin.lean @@ -0,0 +1,123 @@ +import Mathlib +import OAI.Probability.SKRatio.Matrices.FrobeniusSq + +namespace OAI + +section +section +noncomputable section +open MeasureTheory ProbabilityTheory InformationTheory Real Set +open scoped NNReal ENNReal +open Filter +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius ENNReal NNReal +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius NNReal +noncomputable section +open MeasureTheory ProbabilityTheory Real Set Filter +open MeasureTheory.Measure +open scoped ENNReal NNReal MeasureTheory Topology +open MeasureTheory +noncomputable section +noncomputable section +open MeasureTheory Set NormedSpace +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius +namespace SKRatioGaussian +namespace ComplexMatrix +variable {ι : Type*} [Fintype ι] [DecidableEq ι] + +abbrev lin (M : Matrix ι ι ℂ) := M.toEuclideanLin.toContinuousLinearMap +noncomputable def opNorm (M : Matrix ι ι ℂ) : ℝ := ‖lin M‖ +noncomputable def colVec (M : Matrix ι ι ℂ) (k : ι) : EuclideanSpace ℂ ι := WithLp.toLp 2 (fun i => M i k) + +lemma frobenius_sq (M : Matrix ι ι ℂ) : ‖M‖^2 = ∑ i,∑ k, ‖M i k‖^2 := by + rw [Matrix.frobenius_norm_def] + simp only [Real.rpow_two] + rw [← Real.sqrt_eq_rpow,Real.sq_sqrt] + positivity + +lemma frobenius_col_sq (M : Matrix ι ι ℂ) : ‖M‖^2 = ∑ k, ‖colVec M k‖^2 := by + rw [frobenius_sq,Finset.sum_comm] + apply Finset.sum_congr rfl + intro k _ + simp [EuclideanSpace.norm_sq_eq,colVec] + +lemma colVec_mul (M N : Matrix ι ι ℂ) (k : ι) : + colVec (M*N) k = lin M (colVec N k) := by ext i; rfl + +lemma lin_mul (M N : Matrix ι ι ℂ) : lin (M*N) = lin M * lin N := by + apply ContinuousLinearMap.ext + intro x + exact congrArg (fun T : EuclideanSpace ℂ ι →ₗ[ℂ] EuclideanSpace ℂ ι => T x) + (Matrix.toLpLin_mul 2 2 2 M N) + +lemma lin_one : lin (1 : Matrix ι ι ℂ) = 1 := by + ext x i + change (Matrix.mulVec 1 (WithLp.ofLp x)) i = x i + simp + +lemma frobenius_mul_le_opNorm (M N : Matrix ι ι ℂ) : ‖M*N‖ ≤ opNorm M * ‖N‖ := by + have hp : 0 ≤ opNorm M := norm_nonneg _ + apply nonneg_le_nonneg_of_sq_le_sq (mul_nonneg hp (norm_nonneg N)) + simp only [← sq] + rw [frobenius_col_sq,mul_pow,frobenius_col_sq,Finset.mul_sum] + apply Finset.sum_le_sum + intro k _ + rw [colVec_mul] + have hh := (lin M).le_opNorm (colVec N k) + change ‖lin M (colVec N k)‖ ≤ opNorm M * ‖colVec N k‖ at hh + nlinarith only [hh,norm_nonneg (lin M (colVec N k)),mul_nonneg hp (norm_nonneg (colVec N k))] + +lemma lin_adjoint (M : Matrix ι ι ℂ) : lin Mᴴ = (lin M).adjoint := by + rw [lin,Matrix.toEuclideanLin_conjTranspose_eq_adjoint,LinearMap.adjoint_toContinuousLinearMap] + +lemma opNorm_adjoint (M : Matrix ι ι ℂ) : opNorm Mᴴ = opNorm M := by + rw [opNorm,lin_adjoint,ContinuousLinearMap.adjoint.norm_map] + rfl + +lemma frobenius_mul_le_opNorm_right (M N : Matrix ι ι ℂ) : ‖M*N‖ ≤ ‖M‖ * opNorm N := by + rw [← Matrix.frobenius_norm_conjTranspose (M*N),Matrix.conjTranspose_mul] + exact (frobenius_mul_le_opNorm Nᴴ Mᴴ).trans_eq (by rw [opNorm_adjoint,Matrix.frobenius_norm_conjTranspose,mul_comm]) + +lemma lin_unitary (U : Matrix ι ι ℂ) (hU : U ∈ unitary (Matrix ι ι ℂ)) : + lin U ∈ unitary (EuclideanSpace ℂ ι →L[ℂ] EuclideanSpace ℂ ι) := by + change (lin U).adjoint * lin U = 1 ∧ lin U * (lin U).adjoint = 1 + rw [← lin_adjoint,← lin_mul,← lin_mul] + constructor + · rw [show Uᴴ * U = 1 from Unitary.star_mul_self_of_mem hU,lin_one] + · rw [show U * Uᴴ = 1 from Unitary.mul_star_self_of_mem hU,lin_one] + +lemma frobenius_unitary_mul (U M : Matrix ι ι ℂ) (hU : U ∈ unitary (Matrix ι ι ℂ)) : + ‖U*M‖ = ‖M‖ := by + have hh : ‖U*M‖^2 = ‖M‖^2 := by + rw [frobenius_col_sq,frobenius_col_sq] + apply Finset.sum_congr rfl + intro k _ + rw [colVec_mul,ContinuousLinearMap.norm_map_of_mem_unitary (lin_unitary U hU)] + nlinarith [norm_nonneg (U*M),norm_nonneg M] + +lemma frobenius_mul_unitary (M U : Matrix ι ι ℂ) (hU : U ∈ unitary (Matrix ι ι ℂ)) : + ‖M*U‖ = ‖M‖ := by + rw [← Matrix.frobenius_norm_conjTranspose (M*U),Matrix.conjTranspose_mul] + rw [frobenius_unitary_mul Uᴴ Mᴴ (Unitary.star_mem hU),Matrix.frobenius_norm_conjTranspose] + +end ComplexMatrix +end SKRatioGaussian + +end +end +end +end +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Matrices/LinCLM.lean b/lean/OAI/Probability/SKRatio/Matrices/LinCLM.lean new file mode 100644 index 0000000000000000000000000000000000000000..4656db0f7751ca732b855711cefa022292df13d2 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Matrices/LinCLM.lean @@ -0,0 +1,107 @@ +import Mathlib +import OAI.Probability.SKRatio.Matrices.EntryLM + +namespace OAI + +section +section +noncomputable section +open MeasureTheory ProbabilityTheory InformationTheory Real Set +open scoped NNReal ENNReal +open Filter +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius ENNReal NNReal +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius NNReal +noncomputable section +open MeasureTheory ProbabilityTheory Real Set Filter +open MeasureTheory.Measure +open scoped ENNReal NNReal MeasureTheory Topology +open MeasureTheory +noncomputable section +noncomputable section +open MeasureTheory Set NormedSpace +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius +namespace SKRatioGaussian.ComplexMatrix +open MeasureTheory Set NormedSpace +open scoped Topology FourierTransform SchwartzMap +variable {ι : Type*} [Fintype ι] [DecidableEq ι] +local instance : ContinuousENorm (Matrix ι ι ℂ) := + @SeminormedAddGroup.toContinuousENorm _ Matrix.frobeniusSeminormedAddCommGroup.toSeminormedAddGroup +local instance : TopologicalSpace.PseudoMetrizableSpace (Matrix ι ι ℂ) := + inferInstanceAs (TopologicalSpace.PseudoMetrizableSpace (ι → ι → ℂ)) + +def linCLM : Matrix ι ι ℂ →L[ℂ] (EuclideanSpace ℂ ι →L[ℂ] EuclideanSpace ℂ ι) := + (linEquiv (ι := ι)).toLinearMap.toContinuousLinearMap + +lemma opNorm_kernelMatrix {g : ℝ → ℂ} (hg : Integrable g) + (M : Matrix ι ι ℂ) (hM : Mᴴ = M) : + opNorm (kernelMatrix g M) ≤ ∫ t : ℝ, ‖g t‖ := by + let : CompleteSpace (EuclideanSpace ℂ ι) := PiLp.completeSpace _ _ + let : CompleteSpace (EuclideanSpace ℂ ι →L[ℂ] EuclideanSpace ℂ ι) := + ContinuousLinearMap.instCompleteSpace + have hi := linCLM.integral_comp_comm (kernel_integrable hg M hM) + change ‖linCLM (∫ t : ℝ, g t • exp (imaginary t M))‖ ≤ _ + calc + _ = ‖∫ t : ℝ, linCLM (g t • exp (imaginary t M))‖ := congrArg norm hi.symm + _ ≤ ∫ t : ℝ, ‖linCLM (g t • exp (imaginary t M))‖ := norm_integral_le_integral_norm _ + _ ≤ ∫ t : ℝ, ‖g t‖ := by + apply integral_mono (linCLM.integrable_comp (kernel_integrable hg M hM)).norm hg.norm + intro t + change ‖lin (g t • exp (imaginary t M))‖ ≤ _ + rw [lin_csmul,norm_smul] + exact (mul_le_mul_of_nonneg_left (imaginary_exp_opNorm_le t M hM) (norm_nonneg _)).trans_eq (mul_one _) + +lemma schwartzMatrix_opNorm (f : 𝓢(ℝ,ℂ)) (M : Matrix ι ι ℂ) (hM : Mᴴ = M) : + opNorm (schwartzMatrix f M) ≤ ∫ t : ℝ, ‖(𝓕 f) t‖ := + opNorm_kernelMatrix (𝓕 f).integrable _ (by simp [hM]) + +lemma schwartzMatrix_eq_inverse (f : 𝓢(ℝ,ℂ)) {lo hi : ℝ} (hlo : 0 < lo) + (hf : ∀ x ∈ Icc lo hi, f x = (x : ℂ)⁻¹) + (M : Matrix ι ι ℂ) (hM : M.IsHermitian) + (hspec : ∀ i, hM.eigenvalues i ∈ Icc lo hi) : + schwartzMatrix f M = M⁻¹ := by + rw [schwartzMatrix_spectral f M hM] + symm + apply Matrix.inv_eq_left_inv + conv_lhs => rhs; rw [hM.spectral_theorem] + change conjugate hM.eigenvectorUnitary (diagonal (fun i => f (hM.eigenvalues i))) * + conjugate hM.eigenvectorUnitary (diagonal (fun i => (hM.eigenvalues i : ℂ))) = 1 + rw [← map_mul,diagonal_mul_diagonal] + have hd : diagonal (fun i => f (hM.eigenvalues i) * (hM.eigenvalues i : ℂ)) = (1 : Matrix ι ι ℂ) := by + have hz (i : ι) : (hM.eigenvalues i : ℂ) ≠ 0 := by exact_mod_cast ne_of_gt (lt_of_lt_of_le hlo (hspec i).1) + simp_rw [hf _ (hspec _),inv_mul_cancel₀ (hz _)] + exact diagonal_one + rw [hd,map_one] + +lemma schwartzMatrix_hermitian (f : 𝓢(ℝ,ℂ)) (hf : ∀ x, star (f x) = f x) + (M : Matrix ι ι ℂ) (hM : M.IsHermitian) : (schwartzMatrix f M).IsHermitian := by + rw [schwartzMatrix_spectral f M hM] + change star (conjugate hM.eigenvectorUnitary (diagonal _)) = _ + rw [← map_star] + congr 1 + change (diagonal (fun i => f (hM.eigenvalues i)))ᴴ = _ + rw [Matrix.diagonal_conjTranspose] + congr 1 + funext i + exact hf (hM.eigenvalues i) + +end SKRatioGaussian.ComplexMatrix + +end +end +end +end +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Matrices/LinEquiv.lean b/lean/OAI/Probability/SKRatio/Matrices/LinEquiv.lean new file mode 100644 index 0000000000000000000000000000000000000000..081acab3a229bd598dcf06b20bf9a0fe17b401a4 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Matrices/LinEquiv.lean @@ -0,0 +1,62 @@ +import Mathlib +import OAI.Probability.SKRatio.Matrices.Lin + +namespace OAI + +section +section +noncomputable section +open MeasureTheory ProbabilityTheory InformationTheory Real Set +open scoped NNReal ENNReal +open Filter +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius ENNReal NNReal +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius NNReal +noncomputable section +open MeasureTheory ProbabilityTheory Real Set Filter +open MeasureTheory.Measure +open scoped ENNReal NNReal MeasureTheory Topology +open MeasureTheory +noncomputable section +noncomputable section +open MeasureTheory Set NormedSpace +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius +namespace SKRatioGaussian.ComplexMatrix +variable {ι : Type*} [Fintype ι] [DecidableEq ι] + +def linEquiv : Matrix ι ι ℂ ≃ₗ[ℂ] (EuclideanSpace ℂ ι →L[ℂ] EuclideanSpace ℂ ι) := + Matrix.toEuclideanLin.trans LinearMap.toContinuousLinearMap + +def linHom : Matrix ι ι ℂ →+* (EuclideanSpace ℂ ι →L[ℂ] EuclideanSpace ℂ ι) where + toFun := lin + map_one' := lin_one + map_mul' := lin_mul + map_zero' := linEquiv.map_zero + map_add' := linEquiv.map_add + +lemma continuous_lin : Continuous (lin : Matrix ι ι ℂ → _) := + (linEquiv (ι := ι)).toLinearMap.continuous_of_finiteDimensional + +lemma lin_exp (M : Matrix ι ι ℂ) : lin (NormedSpace.exp M) = NormedSpace.exp (lin M) := + NormedSpace.map_exp linHom continuous_lin M + +end SKRatioGaussian.ComplexMatrix + +end +end +end +end +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Matrices/LinSub.lean b/lean/OAI/Probability/SKRatio/Matrices/LinSub.lean new file mode 100644 index 0000000000000000000000000000000000000000..340b022299a7e5e2bb9494e13a9393e3f730d5eb --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Matrices/LinSub.lean @@ -0,0 +1,135 @@ +import Mathlib +import OAI.Probability.SKRatio.Matrices.ExpDuhamel +import OAI.Probability.SKRatio.Matrices.LinEquiv + +namespace OAI + +section +section +noncomputable section +open MeasureTheory ProbabilityTheory InformationTheory Real Set +open scoped NNReal ENNReal +open Filter +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius ENNReal NNReal +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius NNReal +noncomputable section +open MeasureTheory ProbabilityTheory Real Set Filter +open MeasureTheory.Measure +open scoped ENNReal NNReal MeasureTheory Topology +open MeasureTheory +noncomputable section +noncomputable section +open MeasureTheory Set NormedSpace +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius +namespace SKRatioGaussian.ComplexMatrix +open MeasureTheory Set NormedSpace +open scoped Topology +variable {ι : Type*} [Fintype ι] [DecidableEq ι] + +lemma lin_sub (M N : Matrix ι ι ℂ) : lin (M-N) = lin M - lin N := linEquiv.map_sub M N +lemma lin_neg (M : Matrix ι ι ℂ) : lin (-M) = - lin M := linEquiv.map_neg M +lemma opNorm_smul (t : ℝ) (M : Matrix ι ι ℂ) : opNorm (t • M) = |t| * opNorm M := by + change ‖lin (t • M)‖ = _ + have hh : lin (t • M) = t • lin M := by ext x i; simp [lin,Matrix.toEuclideanLin,Matrix.toLpLin_apply,Matrix.smul_mulVec] + rw [hh,norm_smul,Real.norm_eq_abs] + rfl + +lemma unitary_exp_smul (M : Matrix ι ι ℂ) (hM : Mᴴ = -M) (u : ℝ) : + exp (u • M) ∈ unitary (Matrix ι ι ℂ) := by + apply exp_mem_unitary_of_mem_skewAdjoint + change (u • M)ᴴ = -(u • M) + simp [hM] + +lemma opNorm_exp_sub (M N : Matrix ι ι ℂ) (hM : Mᴴ = -M) (hN : Nᴴ = -N) : + opNorm (exp M-exp N) ≤ opNorm (M-N) := by + have hMl : star (lin M) = -lin M := by rw [ContinuousLinearMap.star_eq_adjoint,← lin_adjoint,hM,lin_neg] + have hNl : star (lin N) = -lin N := by rw [ContinuousLinearMap.star_eq_adjoint,← lin_adjoint,hN,lin_neg] + let : CompleteSpace (EuclideanSpace ℂ ι) := PiLp.completeSpace _ _ + let : CompleteSpace (EuclideanSpace ℂ ι →L[ℂ] EuclideanSpace ℂ ι) := + ContinuousLinearMap.instCompleteSpace + let : NormedAlgebra ℚ (EuclideanSpace ℂ ι →L[ℂ] EuclideanSpace ℂ ι) := .restrictScalars ℚ ℝ _ + have hh := SKRatioGaussian.exp_skew_difference (lin M) (lin N) hMl hNl + simpa only [opNorm,lin_sub,lin_exp] using hh + +lemma frobenius_exp_sub (M N : Matrix ι ι ℂ) (hM : Mᴴ = -M) (hN : Nᴴ = -N) : + ‖exp M-exp N‖ ≤ ‖M-N‖ := by + rw [show exp M-exp N = _ from SKRatioGaussian.exp_duhamel M N] + have hh (u : ℝ) : ‖exp ((1-u) • M) * (M-N) * exp (u • N)‖ = ‖M-N‖ := by + rw [frobenius_mul_unitary _ _ (unitary_exp_smul N hN u), + frobenius_unitary_mul _ _ (unitary_exp_smul M hM (1-u))] + calc + _ ≤ ∫ u : ℝ in (0 : ℝ)..1, ‖exp ((1-u) • M) * (M-N) * exp (u • N)‖ := + intervalIntegral.norm_integral_le_integral_norm (by norm_num) + _ = ‖M-N‖ := by simp only [hh]; simp + +lemma exp_four_point (a b c d : Matrix ι ι ℂ) + (ha : aᴴ = -a) (hb : bᴴ = -b) (hc : cᴴ = -c) (hd : dᴴ = -d) : + ‖(exp a-exp b)-(exp c-exp d)‖ ≤ + ‖(a-b)-(c-d)‖ + (opNorm (a-c)+opNorm (b-d))*‖c-d‖ := by + let F := fun a b : Matrix ι ι ℂ => fun u : ℝ => exp ((1-u) • a) * (a-b) * exp (u • b) + have hF (a b : Matrix ι ι ℂ) : Continuous (F a b) := by dsimp [F]; fun_prop + have hbound (u : ℝ) (hu : u ∈ Icc (0 : ℝ) 1) : + ‖F a b u-F c d u‖ ≤ ‖(a-b)-(c-d)‖ + (opNorm (a-c)+opNorm (b-d))*‖c-d‖ := by + have hsa : ((1-u) • a)ᴴ = -((1-u) • a) := by simp [ha] + have hsc : ((1-u) • c)ᴴ = -((1-u) • c) := by simp [hc] + have hsb : (u • b)ᴴ = -(u • b) := by simp [hb] + have hsd : (u • d)ᴴ = -(u • d) := by simp [hd] + have h₁ := opNorm_exp_sub ((1-u) • a) ((1-u) • c) hsa hsc + have h₂ := opNorm_exp_sub (u • b) (u • d) hsb hsd + rw [← smul_sub,opNorm_smul,abs_of_nonneg (sub_nonneg.mpr hu.2)] at h₁ + rw [← smul_sub,opNorm_smul,abs_of_nonneg hu.1] at h₂ + have ha0 : 0 ≤ opNorm (a-c) := norm_nonneg _ + have hb0 : 0 ≤ opNorm (b-d) := norm_nonneg _ + have h₁' : opNorm (exp ((1-u) • a)-exp ((1-u) • c)) ≤ opNorm (a-c) := by nlinarith [hu.1] + have h₂' : opNorm (exp (u • b)-exp (u • d)) ≤ opNorm (b-d) := by nlinarith [hu.2] + have hid : F a b u-F c d u = + exp ((1-u) • a)*((a-b)-(c-d))*exp (u • b) + + (exp ((1-u) • a)-exp ((1-u) • c))*(c-d)*exp (u • b) + + exp ((1-u) • c)*(c-d)*(exp (u • b)-exp (u • d)) := by dsimp [F]; noncomm_ring + rw [hid] + have hfirst : ‖exp ((1-u) • a)*((a-b)-(c-d))*exp (u • b)‖ = ‖(a-b)-(c-d)‖ := by + rw [frobenius_mul_unitary _ _ (unitary_exp_smul b hb u), + frobenius_unitary_mul _ _ (unitary_exp_smul a ha (1-u))] + have hsecond : ‖(exp ((1-u) • a)-exp ((1-u) • c))*(c-d)*exp (u • b)‖ ≤ opNorm (a-c)*‖c-d‖ := by + rw [frobenius_mul_unitary _ _ (unitary_exp_smul b hb u)] + exact (frobenius_mul_le_opNorm _ _).trans (mul_le_mul_of_nonneg_right h₁' (norm_nonneg _)) + have hthird : ‖exp ((1-u) • c)*(c-d)*(exp (u • b)-exp (u • d))‖ ≤ opNorm (b-d)*‖c-d‖ := by + rw [mul_assoc,frobenius_unitary_mul _ _ (unitary_exp_smul c hc (1-u))] + exact (frobenius_mul_le_opNorm_right _ _).trans (by nlinarith [norm_nonneg (c-d)]) + calc + _ ≤ ‖exp ((1-u) • a)*((a-b)-(c-d))*exp (u • b)‖ + + ‖(exp ((1-u) • a)-exp ((1-u) • c))*(c-d)*exp (u • b)‖ + + ‖exp ((1-u) • c)*(c-d)*(exp (u • b)-exp (u • d))‖ := norm_add₃_le + _ ≤ _ := by rw [hfirst]; nlinarith + rw [show exp a-exp b = _ from SKRatioGaussian.exp_duhamel a b, show exp c-exp d = _ from SKRatioGaussian.exp_duhamel c d] + change ‖(∫ u : ℝ in (0 : ℝ)..1, F a b u)-(∫ u : ℝ in (0 : ℝ)..1, F c d u)‖ ≤ _ + rw [← intervalIntegral.integral_sub ((hF a b).intervalIntegrable 0 1) ((hF c d).intervalIntegrable 0 1)] + calc + _ ≤ ∫ u : ℝ in (0 : ℝ)..1, ‖F a b u-F c d u‖ := intervalIntegral.norm_integral_le_integral_norm (by norm_num) + _ ≤ ∫ _ : ℝ in (0 : ℝ)..1, ‖(a-b)-(c-d)‖ + (opNorm (a-c)+opNorm (b-d))*‖c-d‖ := by + apply intervalIntegral.integral_mono_on (by norm_num) (((hF a b).sub (hF c d)).norm.intervalIntegrable 0 1) + (intervalIntegrable_const) + exact hbound + _ = _ := by simp + +end SKRatioGaussian.ComplexMatrix + +end +end +end +end +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Matrices/LipschitzNormedConvolution.lean b/lean/OAI/Probability/SKRatio/Matrices/LipschitzNormedConvolution.lean new file mode 100644 index 0000000000000000000000000000000000000000..2603bd76d4fd3d42825c9d4c2c42833aecf9c5a4 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Matrices/LipschitzNormedConvolution.lean @@ -0,0 +1,439 @@ +import Mathlib + +namespace OAI + +section +section +noncomputable section +open MeasureTheory ProbabilityTheory InformationTheory Real Set +open scoped NNReal ENNReal +open Filter +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius ENNReal NNReal +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius NNReal +noncomputable section +open MeasureTheory ProbabilityTheory Real Set Filter +open MeasureTheory.Measure +open scoped ENNReal NNReal MeasureTheory Topology +namespace SKRatioGaussian + +section Smoothing +open NormedSpace +open scoped Convolution ContDiff +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] + [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] + +theorem lipschitz_normed_convolution {f : E → ℝ} {L : ℝ≥0} + (hf : LipschitzWith L f) (φ : ContDiffBump (0 : E)) + (μ : Measure E) [μ.IsAddHaarMeasure] : + LipschitzWith L (φ.normed μ ⋆[ContinuousLinearMap.lsmul ℝ ℝ, μ] f) := by + have hcv : ConvolutionExists (φ.normed μ) f (ContinuousLinearMap.lsmul ℝ ℝ) μ := + (φ.hasCompactSupport_normed (μ := μ)).convolutionExists_left + (ContinuousLinearMap.lsmul ℝ ℝ) φ.continuous_normed + (hf.continuous.locallyIntegrable (μ := μ)) + apply LipschitzWith.of_dist_le_mul + intro x y + simp only [dist_eq_norm, convolution_def, ContinuousLinearMap.lsmul_apply, smul_eq_mul] + have hx : Integrable (fun t => φ.normed μ t * f (x - t)) μ := hcv x + have hy : Integrable (fun t => φ.normed μ t * f (y - t)) μ := hcv y + rw [← integral_sub hx hy] + calc + _ ≤ ∫ t, φ.normed μ t * ((L : ℝ) * ‖x - y‖) ∂μ := by + apply norm_integral_le_of_norm_le (φ.integrable_normed.mul_const _) + filter_upwards [] with t + rw [← mul_sub, norm_mul, Real.norm_eq_abs (φ.normed μ t), + abs_of_nonneg (φ.nonneg_normed _)] + apply mul_le_mul_of_nonneg_left _ (φ.nonneg_normed _) + simpa only [sub_sub_sub_cancel_right] using hf.norm_sub_le (x - t) (y - t) + _ = (L : ℝ) * ‖x - y‖ := by rw [integral_mul_const, φ.integral_normed, one_mul] + +theorem exists_smooth_lipschitz_approx {f : E → ℝ} {L : ℝ≥0} + (hf : LipschitzWith L f) {ε : ℝ} (hε : 0 < ε) : + ∃ g : E → ℝ, ContDiff ℝ ∞ g ∧ LipschitzWith L g ∧ + ∀ x, dist (g x) (f x) ≤ (L : ℝ) * ε := by + let μ : Measure E := addHaar + let φ : ContDiffBump (0 : E) := ⟨ε / 2, ε, half_pos hε, half_lt_self hε⟩ + let g := φ.normed μ ⋆[ContinuousLinearMap.lsmul ℝ ℝ, μ] f + refine ⟨g, ?_, lipschitz_normed_convolution hf φ μ, ?_⟩ + · exact φ.hasCompactSupport_normed.contDiff_convolution_left + (ContinuousLinearMap.lsmul ℝ ℝ) φ.contDiff_normed hf.continuous.locallyIntegrable + · intro x + apply ContDiffBump.dist_normed_convolution_le hf.continuous.aestronglyMeasurable + intro y hy + apply (hf.dist_le_mul y x).trans + exact mul_le_mul_of_nonneg_left (Metric.mem_ball.mp hy).le L.coe_nonneg + +end Smoothing + +section GaussianMoments +variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] + [MeasurableSpace E] [BorelSpace E] [SecondCountableTopology E] [CompleteSpace E] + {μ : Measure E} [IsGaussian μ] + +theorem gaussian_integrable_exp_norm (a : ℝ) : + Integrable (fun x : E => exp (a * ‖x‖)) μ := by + obtain ⟨C, hC, hI⟩ := IsGaussian.exists_integrable_exp_sq μ + apply (hI.const_mul (exp (a ^ 2 / (4 * C)))).mono' (by fun_prop) + filter_upwards [] with x + rw [Real.norm_eq_abs, abs_of_pos (exp_pos _), ← exp_add] + apply exp_le_exp.mpr + have hs := sq_nonneg (‖x‖ - a / (2 * C)) + have hC0 : C ≠ 0 := ne_of_gt hC + have heq : C * (‖x‖ - a / (2 * C)) ^ 2 = + C * ‖x‖ ^ 2 - a * ‖x‖ + a ^ 2 / (4 * C) := by field_simp; ring + nlinarith [mul_nonneg (le_of_lt hC) hs] + +end GaussianMoments + +section StandardGaussian +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] + [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] + +theorem stdGaussian_map_dual (L : StrongDual ℝ E) : + (stdGaussian E).map L = gaussianReal 0 (Real.toNNReal (‖L‖ ^ 2)) := by + rw [IsGaussian.map_eq_gaussianReal, integral_strongDual_stdGaussian, + variance_dual_stdGaussian] + +theorem stdGaussian_integrable_exp_dual (L : StrongDual ℝ E) (r : ℝ) : + Integrable (fun x => exp (r * L x)) (stdGaussian E) := by + have h := integrable_exp_mul_gaussianReal (μ := 0) + (v := Real.toNNReal (‖L‖ ^ 2)) r + rw [← stdGaussian_map_dual L] at h + exact h.comp_measurable L.continuous.measurable + +theorem stdGaussian_integral_exp_dual (L : StrongDual ℝ E) (r : ℝ) : + (∫ x, exp (r * L x) ∂stdGaussian E) = exp (r ^ 2 * ‖L‖ ^ 2 / 2) := by + have hm := mgf_gaussianReal + ⟨L.continuous.measurable.aemeasurable, stdGaussian_map_dual L⟩ r + simpa [mgf, Real.toNNReal_of_nonneg (sq_nonneg _), mul_div_assoc, mul_comm] using hm + +theorem gaussian_integrable_exp_lipschitz {μ : Measure E} [IsGaussian μ] + {f : E → ℝ} {L : ℝ≥0} (hf : LipschitzWith L f) (r : ℝ) : + Integrable (fun x => exp (r * f x)) μ := by + have hfc := hf.continuous + have hI := (gaussian_integrable_exp_norm (μ := μ) (|r| * L)).const_mul + (exp (|r| * |f 0|)) + apply hI.mono' (by fun_prop) + filter_upwards [] with x + rw [Real.norm_eq_abs, abs_of_pos (exp_pos _), ← exp_add] + apply exp_le_exp.mpr + have hx : |f x| ≤ |f 0| + L * ‖x‖ := by + have hh := hf.norm_sub_le x 0 + simp only [sub_zero, Real.norm_eq_abs] at hh + have ht := abs_add_le (f x - f 0) (f 0) + rw [sub_add_cancel] at ht + linarith + calc + r * f x ≤ |r * f x| := le_abs_self _ + _ = |r| * |f x| := abs_mul _ _ + _ ≤ |r| * (|f 0| + L * ‖x‖) := mul_le_mul_of_nonneg_left hx (abs_nonneg _) + _ = _ := by ring + +theorem gaussian_integrable_lipschitz {μ : Measure E} [IsGaussian μ] + {f : E → ℝ} {L : ℝ≥0} (hf : LipschitzWith L f) : Integrable f μ := by + have hI := ((IsGaussian.integrable_id (μ := μ)).norm.const_mul (L : ℝ)).add + (integrable_const |f 0|) + apply hI.mono' hf.continuous.aestronglyMeasurable + filter_upwards [] with x + change |f x| ≤ (L : ℝ) * ‖x‖ + |f 0| + have hh := hf.norm_sub_le x 0 + simp only [sub_zero, Real.norm_eq_abs] at hh ⊢ + have ht := abs_add_le (f x - f 0) (f 0) + rw [sub_add_cancel] at ht + linarith + +end StandardGaussian + +theorem exp_interval_average_le {a : ℝ} (ha : 0 < a) {g : ℝ → ℝ} + (hg : Continuous g) : + exp (a⁻¹ * ∫ t in (0 : ℝ)..a, g t) ≤ + a⁻¹ * ∫ t in (0 : ℝ)..a, exp (g t) := by + have h0 : volume (Icc (0 : ℝ) a) ≠ 0 := by + rw [volume_Icc, sub_zero, ENNReal.ofReal_ne_zero_iff] + exact ha + have ht : volume (Icc (0 : ℝ) a) ≠ ∞ := by simp + have hJ := convexOn_exp.map_set_average_le continuous_exp.continuousOn isClosed_univ + h0 ht (by filter_upwards [] with x; exact mem_univ _) + hg.integrableOn_Icc (continuous_exp.comp hg).integrableOn_Icc + have hvol : volume.real (Icc (0 : ℝ) a) = a := by + simp [measureReal_def, volume_Icc, ha.le] + simpa only [setAverage_eq, hvol, smul_eq_mul, + integral_Icc_eq_integral_Ioc, ← intervalIntegral.integral_of_le ha.le] using hJ + +section Rotation +variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] + +theorem rotation_snd_norm_le (θ : ℝ) (p : E × E) : + ‖(ContinuousLinearMap.rotation θ p).2‖ ≤ ‖p.1‖ + ‖p.2‖ := by + rw [ContinuousLinearMap.rotation_apply] + calc + ‖-sin θ • p.1 + cos θ • p.2‖ ≤ ‖-sin θ • p.1‖ + ‖cos θ • p.2‖ := norm_add_le _ _ + _ = |sin θ| * ‖p.1‖ + |cos θ| * ‖p.2‖ := by simp [norm_smul, Real.norm_eq_abs] + _ ≤ 1 * ‖p.1‖ + 1 * ‖p.2‖ := + add_le_add (mul_le_mul_of_nonneg_right (abs_sin_le_one _) (norm_nonneg _)) + (mul_le_mul_of_nonneg_right (abs_cos_le_one _) (norm_nonneg _)) + _ = _ := by ring + +theorem hasDerivAt_rotation_fst (θ : ℝ) (p : E × E) : + HasDerivAt (fun t => (ContinuousLinearMap.rotation t p).1) + (ContinuousLinearMap.rotation θ p).2 θ := by + exact ((hasDerivAt_cos θ).smul_const p.1).add + ((hasDerivAt_sin θ).smul_const p.2) + +theorem rotation_fundamental_theorem {f : E → ℝ} {df : E → StrongDual ℝ E} + (hf : ∀ x, HasFDerivAt f (df x) x) (hdf : Continuous df) (p : E × E) : + (∫ θ in (0 : ℝ)..π / 2, + df (ContinuousLinearMap.rotation θ p).1 (ContinuousLinearMap.rotation θ p).2) = + f p.2 - f p.1 := by + have hd : ∀ θ, HasDerivAt (fun t => f (ContinuousLinearMap.rotation t p).1) + (df (ContinuousLinearMap.rotation θ p).1 (ContinuousLinearMap.rotation θ p).2) θ := + fun θ => (hf _).comp_hasDerivAt θ (hasDerivAt_rotation_fst θ p) + have hc : Continuous (fun θ => + df (ContinuousLinearMap.rotation θ p).1 (ContinuousLinearMap.rotation θ p).2) := by + simp only [ContinuousLinearMap.rotation_apply] + fun_prop + have hi := intervalIntegral.integral_eq_sub_of_hasDerivAt (fun θ _ => hd θ) + (hc.intervalIntegrable 0 (π / 2)) + simpa [ContinuousLinearMap.rotation_apply] using hi + +theorem rotation_exp_difference_le {f : E → ℝ} {df : E → StrongDual ℝ E} + (hf : ∀ x, HasFDerivAt f (df x) x) (hdf : Continuous df) (r : ℝ) (p : E × E) : + exp (r * (f p.2 - f p.1)) ≤ (π / 2)⁻¹ * + ∫ θ in (0 : ℝ)..π / 2, exp (r * (π / 2) * + df (ContinuousLinearMap.rotation θ p).1 (ContinuousLinearMap.rotation θ p).2) := by + have hc : Continuous (fun θ => r * (π / 2) * + df (ContinuousLinearMap.rotation θ p).1 (ContinuousLinearMap.rotation θ p).2) := by + simp only [ContinuousLinearMap.rotation_apply] + fun_prop + have hJ := exp_interval_average_le (half_pos pi_pos) hc + rw [intervalIntegral.integral_const_mul, rotation_fundamental_theorem hf hdf] at hJ + convert hJ using 1 + congr 1 + field_simp + +theorem exp_dual_le {L : ℝ≥0} (D : StrongDual ℝ E) (hD : ‖D‖ ≤ L) (r : ℝ) (y : E) : + exp (r * D y) ≤ exp (|r| * L * ‖y‖) := by + apply exp_le_exp.mpr + calc + r * D y ≤ |r * D y| := le_abs_self _ + _ = |r| * ‖D y‖ := by rw [abs_mul, Real.norm_eq_abs] + _ ≤ |r| * (‖D‖ * ‖y‖) := mul_le_mul_of_nonneg_left (D.le_opNorm y) (abs_nonneg _) + _ ≤ |r| * ((L : ℝ) * ‖y‖) := by gcongr + _ = _ := by ring + +theorem rotation_exp_dual_le {L : ℝ≥0} {df : E → StrongDual ℝ E} + (hdf : ∀ x, ‖df x‖ ≤ L) (r θ : ℝ) (p : E × E) : + exp (r * df (ContinuousLinearMap.rotation θ p).1 (ContinuousLinearMap.rotation θ p).2) ≤ + exp (|r| * L * ‖p.1‖) * exp (|r| * L * ‖p.2‖) := by + calc + _ ≤ exp (|r| * L * ‖(ContinuousLinearMap.rotation θ p).2‖) := exp_dual_le _ (hdf _) _ _ + _ ≤ exp (|r| * L * (‖p.1‖ + ‖p.2‖)) := by + gcongr + exact rotation_snd_norm_le θ p + _ = _ := by rw [mul_add, exp_add] + +end Rotation + +section StandardGaussianRotation +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] + [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] + +theorem stdGaussian_integrable_variable_dual {df : E → StrongDual ℝ E} (hc : Continuous df) + {L : ℝ≥0} (hdf : ∀ x, ‖df x‖ ≤ L) (r : ℝ) : + Integrable (fun p : E × E => exp (r * df p.1 p.2)) + ((stdGaussian E).prod (stdGaussian E)) := by + apply ((gaussian_integrable_exp_norm (μ := stdGaussian E) (|r| * L)).comp_snd + (stdGaussian E)).mono' (by fun_prop) + filter_upwards [] with p + rw [Real.norm_eq_abs, abs_of_pos (exp_pos _)] + exact exp_dual_le _ (hdf _) _ _ + +theorem stdGaussian_integral_variable_dual_le {df : E → StrongDual ℝ E} (hc : Continuous df) + {L : ℝ≥0} (hdf : ∀ x, ‖df x‖ ≤ L) (r : ℝ) : + (∫ p : E × E, exp (r * df p.1 p.2) ∂(stdGaussian E).prod (stdGaussian E)) ≤ + exp (r ^ 2 * (L : ℝ) ^ 2 / 2) := by + have hi := stdGaussian_integrable_variable_dual hc hdf r + have hio := hi.integral_prod_left + simp only [stdGaussian_integral_exp_dual] at hio + rw [integral_prod _ hi] + simp only [stdGaussian_integral_exp_dual] + calc + _ ≤ ∫ _x : E, exp (r ^ 2 * (L : ℝ) ^ 2 / 2) ∂stdGaussian E := by + apply integral_mono hio (integrable_const _) + intro x + apply exp_le_exp.mpr + gcongr + exact hdf x + _ = _ := by simp + +theorem stdGaussian_integral_rotation_variable_dual_le {df : E → StrongDual ℝ E} + (hc : Continuous df) {L : ℝ≥0} (hdf : ∀ x, ‖df x‖ ≤ L) (r θ : ℝ) : + (∫ p : E × E, exp (r * df (ContinuousLinearMap.rotation θ p).1 + (ContinuousLinearMap.rotation θ p).2) ∂(stdGaussian E).prod (stdGaussian E)) ≤ + exp (r ^ 2 * (L : ℝ) ^ 2 / 2) := by + have hm := IsGaussian.map_rotation_eq_self (μ := stdGaussian E) (by simp) θ + rw [← integral_map (ContinuousLinearMap.rotation θ).continuous.aemeasurable + (f := fun p : E × E => exp (r * df p.1 p.2)) (by fun_prop), hm] + exact stdGaussian_integral_variable_dual_le hc hdf r + +theorem stdGaussian_integrable_rotation_variable_dual {df : E → StrongDual ℝ E} + (hc : Continuous df) {L : ℝ≥0} (hdf : ∀ x, ‖df x‖ ≤ L) (r : ℝ) + (ν : Measure ℝ) [IsFiniteMeasure ν] : + Integrable (fun z : ℝ × (E × E) => + exp (r * df (ContinuousLinearMap.rotation z.1 z.2).1 + (ContinuousLinearMap.rotation z.1 z.2).2)) + (ν.prod ((stdGaussian E).prod (stdGaussian E))) := by + have hI := gaussian_integrable_exp_norm (μ := stdGaussian E) (|r| * L) + apply ((hI.mul_prod hI).comp_snd ν).mono' + · simp only [ContinuousLinearMap.rotation_apply] + fun_prop + · filter_upwards [] with z + rw [Real.norm_eq_abs, abs_of_pos (exp_pos _)] + exact rotation_exp_dual_le hdf _ _ _ + +omit [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] in +theorem lipschitz_of_bounded_derivative {f : E → ℝ} {df : E → StrongDual ℝ E} + (hf : ∀ x, HasFDerivAt f (df x) x) {L : ℝ≥0} (hdf : ∀ x, ‖df x‖ ≤ L) : + LipschitzWith L f := by + apply lipschitzWith_of_nnnorm_fderiv_le (fun x => (hf x).differentiableAt) + intro x + rw [(hf x).fderiv] + exact hdf x + +lemma exp_mul_sub (r a b : ℝ) : exp (r * (a - b)) = exp (-r * b) * exp (r * a) := by + rw [← exp_add] + congr 1 + ring + +theorem stdGaussian_integrable_exp_difference {f : E → ℝ} {L : ℝ≥0} + (hf : LipschitzWith L f) (r : ℝ) : + Integrable (fun p : E × E => exp (r * (f p.2 - f p.1))) + ((stdGaussian E).prod (stdGaussian E)) := by + simp_rw [exp_mul_sub] + exact (gaussian_integrable_exp_lipschitz hf (-r)).mul_prod + (gaussian_integrable_exp_lipschitz hf r) + +theorem stdGaussian_mgf_difference_le {f : E → ℝ} {df : E → StrongDual ℝ E} + (hf : ∀ x, HasFDerivAt f (df x) x) (hc : Continuous df) + {L : ℝ≥0} (hdf : ∀ x, ‖df x‖ ≤ L) (r : ℝ) : + (∫ p : E × E, exp (r * (f p.2 - f p.1)) ∂(stdGaussian E).prod (stdGaussian E)) ≤ + exp (π ^ 2 * r ^ 2 * (L : ℝ) ^ 2 / 8) := by + let ν : Measure ℝ := volume.restrict (Ioc (0 : ℝ) (π / 2)) + have hν : IsFiniteMeasure ν := by dsimp [ν]; infer_instance + let R := r * (π / 2) + let G : ℝ → E × E → ℝ := fun θ p => exp (R * + df (ContinuousLinearMap.rotation θ p).1 (ContinuousLinearMap.rotation θ p).2) + have hI : Integrable (Function.uncurry G) (ν.prod ((stdGaussian E).prod (stdGaussian E))) := + stdGaussian_integrable_rotation_variable_dual hc hdf R ν + have hD := stdGaussian_integrable_exp_difference (lipschitz_of_bounded_derivative hf hdf) r + have hpos : 0 < π / 2 := half_pos pi_pos + have hvol : ν.real univ = π / 2 := by + simp [ν, measureReal_def, Real.volume_Ioc, hpos.le] + have hpoint (p : E × E) : exp (r * (f p.2 - f p.1)) ≤ + (π / 2)⁻¹ * ∫ θ, G θ p ∂ν := by + simpa only [intervalIntegral.integral_of_le hpos.le] using rotation_exp_difference_le hf hc r p + calc + _ ≤ ∫ p : E × E, (π / 2)⁻¹ * (∫ θ, G θ p ∂ν) + ∂(stdGaussian E).prod (stdGaussian E) := + integral_mono hD (hI.integral_prod_right.const_mul _) hpoint + _ = (π / 2)⁻¹ * ∫ θ, (∫ p : E × E, G θ p + ∂(stdGaussian E).prod (stdGaussian E)) ∂ν := by + rw [integral_const_mul, ← integral_integral_swap hI] + _ ≤ (π / 2)⁻¹ * ∫ _θ, exp (R ^ 2 * (L : ℝ) ^ 2 / 2) ∂ν := by + apply mul_le_mul_of_nonneg_left _ (inv_nonneg.mpr hpos.le) + apply integral_mono hI.integral_prod_left (integrable_const _) + intro θ + exact stdGaussian_integral_rotation_variable_dual_le hc hdf R θ + _ = exp (π ^ 2 * r ^ 2 * (L : ℝ) ^ 2 / 8) := by + rw [integral_const, smul_eq_mul, hvol, ← mul_assoc, inv_mul_cancel₀ hpos.ne', one_mul] + congr 1 + dsimp [R] + ring + +theorem stdGaussian_mgf_centered_le {f : E → ℝ} {df : E → StrongDual ℝ E} + (hf : ∀ x, HasFDerivAt f (df x) x) (hc : Continuous df) + {L : ℝ≥0} (hdf : ∀ x, ‖df x‖ ≤ L) (r : ℝ) : + (∫ x, exp (r * (f x - ∫ y, f y ∂stdGaussian E)) ∂stdGaussian E) ≤ + exp (π ^ 2 * r ^ 2 * (L : ℝ) ^ 2 / 8) := by + have hLip := lipschitz_of_bounded_derivative hf hdf + have hF := gaussian_integrable_lipschitz (μ := stdGaussian E) hLip + have hG := gaussian_integrable_exp_lipschitz (μ := stdGaussian E) hLip (-r) + have hpair := stdGaussian_integrable_exp_difference hLip (-r) + have hcenter : Integrable (fun x => exp (r * (f x - ∫ y, f y ∂stdGaussian E))) + (stdGaussian E) := by + simp_rw [exp_mul_sub] + exact (gaussian_integrable_exp_lipschitz hLip r).const_mul _ + have hj (x : E) : exp (r * (f x - ∫ y, f y ∂stdGaussian E)) ≤ + ∫ y, exp (r * (f x - f y)) ∂stdGaussian E := by + have hsub := ((integrable_const (f x)).sub hF).const_mul r + have he : Integrable (fun y => exp (r * (f x - f y))) (stdGaussian E) := by + simp_rw [exp_mul_sub] + exact hG.mul_const _ + have h := convexOn_exp.map_integral_le continuous_exp.continuousOn isClosed_univ + (by filter_upwards [] with y; exact mem_univ _) hsub he + simp only [Pi.sub_apply] at h + simpa only [integral_const_mul, integral_sub (integrable_const _) hF, + integral_const, probReal_univ, one_smul] using h + have heq (x y : E) : r * (f x - f y) = -r * (f y - f x) := by ring + simp_rw [heq] at hj + calc + _ ≤ ∫ x, (∫ y, exp (-r * (f y - f x)) ∂stdGaussian E) ∂stdGaussian E := + integral_mono hcenter hpair.integral_prod_left hj + _ = ∫ p : E × E, exp (-r * (f p.2 - f p.1)) + ∂(stdGaussian E).prod (stdGaussian E) := (integral_prod _ hpair).symm + _ ≤ exp (π ^ 2 * r ^ 2 * (L : ℝ) ^ 2 / 8) := by + simpa using stdGaussian_mgf_difference_le hf hc hdf (-r) + +theorem centered_mgf_le_of_uniform_dist {f g : E → ℝ} {L M : ℝ≥0} + (hf : LipschitzWith L f) (hg : LipschitzWith M g) {δ : ℝ} + (hfg : ∀ x, dist (f x) (g x) ≤ δ) (r : ℝ) : + (∫ x, exp (r * (f x - ∫ y, f y ∂stdGaussian E)) ∂stdGaussian E) ≤ + exp (2 * |r| * δ) * + (∫ x, exp (r * (g x - ∫ y, g y ∂stdGaussian E)) ∂stdGaussian E) := by + let μ := stdGaussian E + have hfi : Integrable f μ := gaussian_integrable_lipschitz hf + have hgi : Integrable g μ := gaussian_integrable_lipschitz hg + have hmean : |(∫ y, f y ∂μ) - ∫ y, g y ∂μ| ≤ δ := by + have hi : ‖∫ x, f x - g x ∂μ‖ ≤ δ * μ.real univ := + norm_integral_le_of_norm_le_const (μ := μ) + (Eventually.of_forall (fun x => by simpa only [dist_eq_norm] using hfg x)) + rw [integral_sub hfi hgi] at hi + simpa only [Real.norm_eq_abs, probReal_univ, mul_one] using hi + have he (h : E → ℝ) {K : ℝ≥0} (hh : LipschitzWith K h) : + Integrable (fun x => exp (r * (h x - ∫ y, h y ∂μ))) μ := by + simp_rw [exp_mul_sub] + exact (gaussian_integrable_exp_lipschitz hh r).const_mul _ + rw [← integral_const_mul] + apply integral_mono (he f hf) ((he g hg).const_mul _) + intro x + dsimp only + rw [← exp_add] + apply exp_le_exp.mpr + have hdiff : |(f x - ∫ y, f y ∂μ) - (g x - ∫ y, g y ∂μ)| ≤ 2 * δ := by + have hx : |f x - g x| ≤ δ := by simpa only [Real.dist_eq] using hfg x + calc + _ = |(f x - g x) - ((∫ y, f y ∂μ) - ∫ y, g y ∂μ)| := by congr 1; ring + _ ≤ |f x - g x| + |(∫ y, f y ∂μ) - ∫ y, g y ∂μ| := by + simpa only [Real.norm_eq_abs] using norm_sub_le + (f x - g x) ((∫ y, f y ∂μ) - ∫ y, g y ∂μ) + _ ≤ 2 * δ := by linarith + have hh := le_abs_self (r * ((f x - ∫ y, f y ∂μ) - (g x - ∫ y, g y ∂μ))) + rw [abs_mul] at hh + have hb := mul_le_mul_of_nonneg_left hdiff (abs_nonneg r) + dsimp [μ] at * + nlinarith + +end StandardGaussianRotation +end SKRatioGaussian +end +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Matrices/MatrixCoordinates.lean b/lean/OAI/Probability/SKRatio/Matrices/MatrixCoordinates.lean new file mode 100644 index 0000000000000000000000000000000000000000..f51b5cc5042ae0ae089fc74b37affd38c0a32ae8 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Matrices/MatrixCoordinates.lean @@ -0,0 +1,103 @@ +import Mathlib + +namespace OAI + +section +section +noncomputable section +open MeasureTheory ProbabilityTheory InformationTheory Real Set +open scoped NNReal ENNReal +open Filter +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius ENNReal NNReal +namespace SKRatioGaussian +abbrev MatrixCoordinates (ι : Type*) := (ι × ι) ⊕ ι + +variable {ι : Type*} + +def goeMatrix (r : ℝ) (g : MatrixCoordinates ι → ℝ) : Matrix ι ι ℝ := + fun i k => sqrt (2*r)/2 * (g (.inl (i,k)) + g (.inl (k,i))) + +variable [Fintype ι] + +def rawCoordinateMatrix (g : MatrixCoordinates ι → ℝ) : Matrix ι ι ℝ := + fun i k => g (.inl (i,k)) + +lemma rawCoordinateMatrix_norm (g : EuclideanSpace ℝ (MatrixCoordinates ι)) : + ‖rawCoordinateMatrix g‖ ≤ ‖g‖ := by + apply nonneg_le_nonneg_of_sq_le_sq (norm_nonneg _) + simp only [← sq] + rw [Matrix.frobenius_norm_def,← Real.sqrt_eq_rpow,Real.sq_sqrt (by positivity), + EuclideanSpace.norm_sq_eq] + simp only [Real.rpow_two,Real.norm_eq_abs,sq_abs,Fintype.sum_sum_type,Fintype.sum_prod_type, + rawCoordinateMatrix] + exact le_add_of_nonneg_right (Finset.sum_nonneg (fun _ _ => sq_nonneg _)) + +lemma goeMatrix_norm (r : ℝ) (g : EuclideanSpace ℝ (MatrixCoordinates ι)) : + ‖goeMatrix r g‖ ≤ sqrt (2*r)*‖g‖ := by + have he : goeMatrix r g = (sqrt (2*r)/2) • + (rawCoordinateMatrix g+(rawCoordinateMatrix g)ᵀ) := by ext; rfl + rw [he,norm_smul,Real.norm_eq_abs,abs_of_nonneg (by positivity)] + calc + _ ≤ (sqrt (2*r)/2)*(‖rawCoordinateMatrix g‖+‖(rawCoordinateMatrix g)ᵀ‖) := + mul_le_mul_of_nonneg_left (norm_add_le _ _) (by positivity) + _ = sqrt (2*r)*‖rawCoordinateMatrix g‖ := by rw [Matrix.frobenius_norm_transpose]; ring + _ ≤ _ := mul_le_mul_of_nonneg_left (rawCoordinateMatrix_norm g) (sqrt_nonneg _) + +omit [Fintype ι] in +lemma goeMatrix_sub (r : ℝ) (g h : MatrixCoordinates ι → ℝ) : + goeMatrix r (g-h) = goeMatrix r g-goeMatrix r h := by + ext i k; simp only [goeMatrix,Pi.sub_apply,Matrix.sub_apply]; ring + +lemma goeMatrix_L2_lipschitz (r : ℝ) : + LipschitzWith ⟨sqrt (2*r),sqrt_nonneg _⟩ + (fun g : EuclideanSpace ℝ (MatrixCoordinates ι) => goeMatrix r g) := by + apply LipschitzWith.of_dist_le_mul + intro g h + simpa only [dist_eq_norm,← goeMatrix_sub] using! goeMatrix_norm r (g-h) + +lemma goeMatrix_pi_lipschitz (r : ℝ) : + LipschitzWith (⟨sqrt (2*r),sqrt_nonneg _⟩ * + (Fintype.card (MatrixCoordinates ι) : ℝ≥0) ^ (1/(2:ℝ≥0∞)).toReal) + (goeMatrix (ι := ι) r) := by + exact (goeMatrix_L2_lipschitz (ι := ι) r).comp + (PiLp.lipschitzWith_toLp 2 (fun _ : MatrixCoordinates ι => ℝ)) + +variable [DecidableEq ι] + +def symmetricElementary (a b : ι) : Matrix ι ι ℝ := + Matrix.single a b 1+Matrix.single b a 1 + +omit [Fintype ι] in +lemma goeMatrix_update (r : ℝ) (g : MatrixCoordinates ι → ℝ) (a b : ι) (t : ℝ) : + goeMatrix r (Function.update g (.inl (a,b)) t) = + goeMatrix r g + ((sqrt (2*r)/2)*(t-g (.inl (a,b)))) • symmetricElementary a b := by + ext i k + simp only [goeMatrix,Matrix.add_apply,Matrix.smul_apply,smul_eq_mul,symmetricElementary, + Matrix.single_apply] + by_cases hi : i=a <;> by_cases hk : k=b <;> by_cases hi' : i=b <;> by_cases hk' : k=a <;> + simp_all [Function.update_apply,Prod.ext_iff,eq_comm] <;> ring + +lemma symmetricElementary_norm_le (a b : ι) : ‖symmetricElementary a b‖ ≤ 2 := by + unfold symmetricElementary + exact (norm_add_le _ _).trans (by simpa [Matrix.frobenius_norm_def,Matrix.single_apply,ite_and] using (show (1:ℝ)+1 ≤ 2 by norm_num)) + +lemma goeMatrix_updated_hasDerivAt (r : ℝ) (g : MatrixCoordinates ι → ℝ) (a b : ι) : + HasDerivAt (fun t => goeMatrix r (Function.update g (.inl (a,b)) t)) + ((sqrt (2*r)/2) • symmetricElementary a b) (g (.inl (a,b))) := by + simp_rw [goeMatrix_update] + have ha := (hasDerivAt_id (g (.inl (a,b)))).sub_const (g (.inl (a,b))) + have hb := ha.const_mul (sqrt (2*r)/2) + have hh := (hb.smul_const (symmetricElementary a b)).const_add (goeMatrix r g) + simpa only [mul_one,id_eq] using! hh + +end SKRatioGaussian + +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Matrices/MatrixEntryCLM.lean b/lean/OAI/Probability/SKRatio/Matrices/MatrixEntryCLM.lean new file mode 100644 index 0000000000000000000000000000000000000000..123a60e55576f9259b27f2e8348f61e279e1557c --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Matrices/MatrixEntryCLM.lean @@ -0,0 +1,115 @@ +import Mathlib +import OAI.Probability.SKRatio.Matrices.FrobeniusSq + +namespace OAI + +section +section +noncomputable section +open MeasureTheory ProbabilityTheory InformationTheory Real Set +open scoped NNReal ENNReal +open Filter +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius ENNReal NNReal +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius NNReal +namespace SKRatioGaussian +variable {ι : Type*} [Fintype ι] [DecidableEq ι] + +lemma matrix_entry_le_frobenius (M : Matrix ι ι ℝ) (i k : ι) : |M i k| ≤ ‖M‖ := by + have h₁ : (M i k)^2 ≤ ∑ j, (M i j)^2 := + Finset.single_le_sum (fun j _ => sq_nonneg _) (Finset.mem_univ k) + have h₂ : (∑ j, (M i j)^2) ≤ ∑ a,∑ j, (M a j)^2 := + Finset.single_le_sum (fun a _ => Finset.sum_nonneg (fun j _ => sq_nonneg _)) (Finset.mem_univ i) + have hh : (M i k)^2 ≤ ‖M‖^2 := by rw [frobenius_sq]; exact h₁.trans h₂ + nlinarith only [hh,sq_abs (M i k),abs_nonneg (M i k),norm_nonneg M] + +noncomputable def matrixEntryCLM (i k : ι) : Matrix ι ι ℝ →L[ℝ] ℝ := + ({ toFun := fun M => M i k + map_add' := by intros; rfl + map_smul' := by intros; rfl } : Matrix ι ι ℝ →ₗ[ℝ] ℝ).mkContinuous 1 + (fun M => by simpa [Real.norm_eq_abs] using! matrix_entry_le_frobenius M i k) + +lemma matrixEntry_lipschitz (i k : ι) : LipschitzWith 1 (fun M : Matrix ι ι ℝ => M i k) := by + apply LipschitzWith.of_dist_le_mul + intro M N + simpa only [dist_eq_norm,Real.norm_eq_abs,NNReal.coe_one,one_mul,Matrix.sub_apply] using! + matrix_entry_le_frobenius (M-N) i k + +omit [DecidableEq ι] in +lemma matrixEntry_derivative {f : ℝ → Matrix ι ι ℝ} {v : Matrix ι ι ℝ} {t : ℝ} + (hf : HasDerivAt f v t) (i k : ι) : HasDerivAt (fun s => f s i k) (v i k) t := by + classical + exact (matrixEntryCLM i k).hasFDerivAt.comp_hasDerivAt t hf + +lemma matrix_inverse_diff_bound (K B E : Matrix ι ι ℝ) : + ‖K*B*E*K‖ ≤ opNorm K*(opNorm B*‖E‖)*opNorm K := by + calc + _ ≤ ‖K*B*E‖*opNorm K := frobenius_mul_le_opNorm_right _ _ + _ = ‖K*(B*E)‖*opNorm K := by rw [mul_assoc K B E] + _ ≤ (opNorm K*‖B*E‖)*opNorm K := + mul_le_mul_of_nonneg_right (frobenius_mul_le_opNorm _ _) (norm_nonneg _) + _ ≤ _ := mul_le_mul_of_nonneg_right + (mul_le_mul_of_nonneg_left (frobenius_mul_le_opNorm _ _) (norm_nonneg _)) (norm_nonneg _) + +noncomputable def diagonalVector (M : Matrix ι ι ℝ) : EuclideanSpace ℝ ι := + WithLp.toLp 2 (fun i => M i i) + +lemma diagonalVector_norm_le (M : Matrix ι ι ℝ) : ‖diagonalVector M‖ ≤ ‖M‖ := by + apply nonneg_le_nonneg_of_sq_le_sq (norm_nonneg M) + simp only [← sq] + rw [EuclideanSpace.norm_sq_eq,frobenius_sq] + apply Finset.sum_le_sum + intro i _ + simpa only [diagonalVector,Real.norm_eq_abs,sq_abs] using + (Finset.single_le_sum (fun j _ => sq_nonneg (M i j)) (Finset.mem_univ i)) + +lemma abs_trace_le_frobenius (M : Matrix ι ι ℝ) : + |Matrix.trace M| ≤ sqrt (Fintype.card ι)*‖M‖ := by + let v : EuclideanSpace ℝ ι := WithLp.toLp 2 (fun _ => 1) + have hv : ‖v‖ = sqrt (Fintype.card ι) := by + rw [EuclideanSpace.norm_eq]; simp [v] + have hi := abs_real_inner_le_norm (diagonalVector M) v + change |∑ i, 1*M i i| ≤ ‖diagonalVector M‖*‖v‖ at hi + simp only [one_mul,hv] at hi + change |Matrix.trace M| ≤ ‖diagonalVector M‖*sqrt (Fintype.card ι) at hi + exact hi.trans ((mul_le_mul_of_nonneg_right (diagonalVector_norm_le M) (sqrt_nonneg _)).trans_eq (mul_comm _ _)) + +lemma matrixTrace_mul_lipschitz {Ω : Type*} [PseudoMetricSpace Ω] + {K : Ω → Matrix ι ι ℝ} {L : ℝ≥0} (hK : LipschitzWith L K) + (B : Matrix ι ι ℝ) : + LipschitzWith (⟨sqrt (Fintype.card ι)*opNorm B,by exact mul_nonneg (sqrt_nonneg _) (norm_nonneg _)⟩*L) + (fun x => Matrix.trace (K x*B)) := by + apply LipschitzWith.of_dist_le_mul + intro x y + change |Matrix.trace (K x*B)-Matrix.trace (K y*B)| ≤ + (sqrt (Fintype.card ι)*opNorm B*(L:ℝ))*dist x y + rw [← Matrix.trace_sub,← sub_mul] + calc + _ ≤ sqrt (Fintype.card ι)*‖(K x-K y)*B‖ := abs_trace_le_frobenius _ + _ ≤ sqrt (Fintype.card ι)*(‖K x-K y‖*opNorm B) := + mul_le_mul_of_nonneg_left (frobenius_mul_le_opNorm_right _ _) (sqrt_nonneg _) + _ ≤ sqrt (Fintype.card ι)*(((L:ℝ)*dist x y)*opNorm B) := by + exact mul_le_mul_of_nonneg_left + (mul_le_mul_of_nonneg_right (by simpa only [dist_eq_norm] using hK.dist_le_mul x y) + (norm_nonneg _)) (sqrt_nonneg _) + _ = _ := by ring + +end SKRatioGaussian + +noncomputable section +open MeasureTheory ProbabilityTheory Real Set Filter +open MeasureTheory.Measure +open scoped ENNReal NNReal MeasureTheory Topology + +end +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Matrices/MatrixQuad.lean b/lean/OAI/Probability/SKRatio/Matrices/MatrixQuad.lean new file mode 100644 index 0000000000000000000000000000000000000000..77ee56a95546074b871f38db452003c0c4d8f6ba --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Matrices/MatrixQuad.lean @@ -0,0 +1,170 @@ +import Mathlib +import OAI.Probability.SKRatio.Matrices.MatrixCoordinates + +namespace OAI + +section +section +noncomputable section +open MeasureTheory ProbabilityTheory InformationTheory Real Set +open scoped NNReal ENNReal +open Filter +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius ENNReal NNReal +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius NNReal +noncomputable section +open MeasureTheory ProbabilityTheory Real Set Filter +open MeasureTheory.Measure +open scoped ENNReal NNReal MeasureTheory Topology +open MeasureTheory +noncomputable section +noncomputable section +open MeasureTheory Set NormedSpace +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius +noncomputable section +open Set Real +open scoped Topology +noncomputable section +open Matrix Set Filter +open scoped Topology Matrix.Norms.Frobenius +noncomputable section +open Matrix NormedSpace ContinuousLinearMap +open scoped Matrix.Norms.Frobenius +noncomputable section +open Matrix +noncomputable section +open MeasureTheory ProbabilityTheory Real Set +open scoped ENNReal NNReal +noncomputable section +open MeasureTheory ProbabilityTheory InformationTheory Real Set +open scoped NNReal ENNReal +noncomputable section +open scoped BigOperators +open MeasureTheory ProbabilityTheory +open Real +noncomputable section +open scoped BigOperators Topology +open Filter Real +namespace SKRatioGaussian +variable {ι : Type*} [Fintype ι] [DecidableEq ι] +def matrixQuad (M : Matrix ι ι ℝ) (p : EuclideanSpace ℝ ι) : ℝ := + ∑ i, ∑ k, p i * M i k * p k + +def matrixOperator (M : Matrix ι ι ℝ) : + EuclideanSpace ℝ ι →L[ℝ] EuclideanSpace ℝ ι := + M.toEuclideanLin.toContinuousLinearMap + +lemma matrixOperator_apply (M : Matrix ι ι ℝ) (p : EuclideanSpace ℝ ι) (i : ι) : + matrixOperator M p i = ∑ k, M i k * p k := by + rfl + +lemma matrixQuad_inner (M : Matrix ι ι ℝ) (p : EuclideanSpace ℝ ι) : + matrixQuad M p = inner ℝ p (matrixOperator M p) := by + simp only [PiLp.inner_apply, RCLike.inner_apply, conj_trivial, matrixOperator_apply, + matrixQuad, Finset.sum_mul] + apply Finset.sum_congr rfl + intro i _ + apply Finset.sum_congr rfl + intro k _ + ring + +omit [DecidableEq ι] in +lemma matrixQuad_smul (M : Matrix ι ι ℝ) (p : EuclideanSpace ℝ ι) (c : ℝ) : + matrixQuad M (c • p) = c^2 * matrixQuad M p := by + simp only [matrixQuad, PiLp.smul_apply, smul_eq_mul, Finset.mul_sum] + apply Finset.sum_congr rfl + intro i _ + apply Finset.sum_congr rfl + intro k _ + ring + +omit [Fintype ι] [DecidableEq ι] in +lemma goeMatrix_symm (r : ℝ) (g : MatrixCoordinates ι → ℝ) : + (goeMatrix r g).IsHermitian := by + ext i k + simp [goeMatrix, add_comm] + +omit [Fintype ι] [DecidableEq ι] in +lemma goeMatrix_neg (r : ℝ) (g : MatrixCoordinates ι → ℝ) : + goeMatrix r (-g) = -goeMatrix r g := by + ext i k + simp only [goeMatrix, Pi.neg_apply, Matrix.neg_apply] + ring + +omit [DecidableEq ι] in +lemma goeMatrix_quad (r : ℝ) (g : MatrixCoordinates ι → ℝ) (p : EuclideanSpace ℝ ι) : + matrixQuad (goeMatrix r g) p = + ∑ i, ∑ k, sqrt (2*r) * p i * p k * g (.inl (i,k)) := by + have hs : (∑ i, ∑ k, p i * g (.inl (k,i)) * p k) = + ∑ i, ∑ k, p i * g (.inl (i,k)) * p k := by + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro i _ + apply Finset.sum_congr rfl + intro k _ + ring + calc + _ = sqrt (2*r)/2 * ((∑ i, ∑ k, p i * g (.inl (i,k)) * p k) + + ∑ i, ∑ k, p i * g (.inl (k,i)) * p k) := by + simp only [matrixQuad, goeMatrix, Finset.mul_sum, ← Finset.sum_add_distrib] + apply Finset.sum_congr rfl + intro i _ + apply Finset.sum_congr rfl + intro k _ + ring + _ = _ := by + rw [hs] + simp only [Finset.mul_sum, ← Finset.sum_add_distrib] + apply Finset.sum_congr rfl + intro i _ + apply Finset.sum_congr rfl + intro k _ + ring + +lemma matrixOperator_norm_le_of_quad {M : Matrix ι ι ℝ} (hM : M.IsHermitian) + {R : ℝ} (hR : 0 ≤ R) + (hq : ∀ p : EuclideanSpace ℝ ι, ‖p‖ ≤ 1 → |matrixQuad M p| ≤ R) : + ‖matrixOperator M‖ ≤ R := by + have hs : (matrixOperator M).IsSymmetric := Matrix.isSymmetric_toEuclideanLin_iff.mpr hM + rw [ContinuousLinearMap.norm_eq_iSup_rayleighQuotient (T := matrixOperator M) hs] + apply ciSup_le + intro p + by_cases hp : p = 0 + · simp [hp, ContinuousLinearMap.rayleighQuotient, hR] + have hp0 : 0 < ‖p‖ := norm_pos_iff.mpr hp + have hunit : ‖‖p‖⁻¹ • p‖ ≤ 1 := by + rw [norm_smul, Real.norm_eq_abs, abs_inv, abs_of_pos hp0, inv_mul_cancel₀ hp0.ne'] + have hh := hq (‖p‖⁻¹ • p) hunit + rw [matrixQuad_smul, abs_mul, abs_pow, abs_inv, abs_of_pos hp0] at hh + simpa only [ContinuousLinearMap.rayleighQuotient, ContinuousLinearMap.reApplyInnerSelf_apply, + RCLike.re_to_real, real_inner_comm, ← matrixQuad_inner, abs_div, + abs_pow, abs_of_pos hp0, inv_pow, div_eq_mul_inv, mul_comm, abs_mul, abs_inv] using hh + +end SKRatioGaussian + +end +end +end +end +end +end +end +end +end +end +end +end +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Matrices/NormalizedIncrement.lean b/lean/OAI/Probability/SKRatio/Matrices/NormalizedIncrement.lean new file mode 100644 index 0000000000000000000000000000000000000000..2d8297d9c9ae4db9605a8e9d4965483637a477bc --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Matrices/NormalizedIncrement.lean @@ -0,0 +1,145 @@ +import Mathlib +import OAI.Probability.SKRatio.Matrices.BrownianUnitLaw + +namespace OAI + +section +section +noncomputable section +namespace SKRatioGaussian.PathBridge +open MeasureTheory ProbabilityTheory Real Set +open scoped BigOperators ENNReal NNReal Topology +variable {Ω : Type*} [MeasurableSpace Ω] {P : Measure Ω} {B : ℝ≥0→Ω→ℝ} + +def normalizedIncrement (B : ℝ≥0→Ω→ℝ) (s δ : ℝ≥0) : ℝ≥0→Ω→ℝ := + fun t ω=>(sqrt δ)⁻¹*(B (s+δ*t) ω-B s ω) + +def incrementEnergy (B : ℝ≥0→Ω→ℝ) (s δ : ℝ≥0) (n : ℕ) (ω : Fin n→Ω) : ℝ := + pathEnergy n (fun i=>continuousPathVersion (unitBrownianProcess (normalizedIncrement B s δ)) (ω i)) + +lemma incrementEnergy_tail (hB : IsBrownianReal B P) : + ∃ H : ℝ, 0P)).real + {ω | H*(n:ℝ) ≤ incrementEnergy B s δ n ω} ≤ exp (-(n:ℝ)) := by + let : IsProbabilityMeasure P := hB.isGaussianProcess.isProbabilityMeasure + obtain ⟨H,hH,ht⟩ := brownian_normalized_increment_tail hB + refine ⟨H,hH,fun s δ hδ n=>?_⟩ + have hb : IsBrownianReal (normalizedIncrement B s δ) P := (hB.shift s).smul hδ + have hm := aemeasurable_continuousPathVersion (brownian_unit_gaussian hb).aemeasurable + (brownian_unit_continuous hb) + let := brownianUnitLaw_probability hb + have hp := Measure.pi_map_pi (ι:=Fin n) (fun _=>hm) + have ha : AEMeasurable (fun ω : Fin n→Ω=>fun i=> + continuousPathVersion (unitBrownianProcess (normalizedIncrement B s δ)) (ω i)) + (Measure.pi (fun _ : Fin n=>P)) := + AEMeasurable.of_eval (fun index=>hm.comp_quasiMeasurePreserving + (Measure.quasiMeasurePreserving_eval _ index)) + have hset : MeasurableSet {f : Fin n→UnitPath | H*(n:ℝ) ≤ pathEnergy n f} := by + apply measurableSet_le measurable_const + unfold pathEnergy + fun_prop + have hh := map_measureReal_apply_of_aemeasurable ha hset + rw [hp] at hh + rw [show {ω : Fin n→Ω | H*(n:ℝ) ≤ incrementEnergy B s δ n ω} = + (fun ω : Fin n→Ω=>fun i=>continuousPathVersion + (unitBrownianProcess (normalizedIncrement B s δ)) (ω i)) ⁻¹' + {f | H*(n:ℝ) ≤ pathEnergy n f} from rfl,← hh] + exact ht s δ hδ n + +omit [MeasurableSpace Ω] in +lemma increment_square_sum_le {s δ : ℝ≥0} (hδ : δ≠0) (n : ℕ) (ω : Fin n→Ω) + (hc : ∀ i,Continuous (fun t=>unitBrownianProcess (normalizedIncrement B s δ) t (ω i))) + (t : UnitInterval) : + ∑ i,(B (s+δ*⟨t.1,t.2.1⟩) (ω i)-B s (ω i))^2 ≤ + (δ:ℝ)*incrementEnergy B s δ n ω := by + have hδp : 0<(δ:ℝ) := NNReal.coe_pos.mpr (pos_iff_ne_zero.mpr hδ) + have hs : 0.2 hn + rw [sq_abs,mul_pow,inv_pow,Real.sq_sqrt hδp.le] at hh + have hv := mul_le_mul_of_nonneg_left hh hδp.le + simpa only [← mul_assoc,mul_inv_cancel₀ hδp.ne',one_mul] using hv + +theorem brownian_coordinate_modulus (hB : IsBrownianReal B P) {κ : ℝ} (hκ : 0<κ) : + ∃ δ : ℝ≥0, 0<δ ∧ ∀ s : ℝ≥0, ∀ n : ℕ, + (Measure.pi (fun _ : Fin n=>P)).real + {ω | ∃ t : UnitInterval, + κ^2*(n:ℝ) < ∑ i,(B (s+δ*⟨t.1,t.2.1⟩) (ω i)-B s (ω i))^2} ≤ exp (-(n:ℝ)) := by + let : IsProbabilityMeasure P := hB.isGaussianProcess.isProbabilityMeasure + obtain ⟨H,hH,ht⟩ := incrementEnergy_tail hB + let δ : ℝ≥0 := ⟨κ^2/H,le_of_lt (div_pos (sq_pos_of_pos hκ) hH)⟩ + have hδ : 0<δ := div_pos (sq_pos_of_pos hκ) hH + refine ⟨δ,hδ,fun s n=>?_⟩ + have hb : IsBrownianReal (normalizedIncrement B s δ) P := (hB.shift s).smul hδ.ne' + have hc : ∀ᵐ ω : Fin n→Ω ∂Measure.pi (fun _ : Fin n=>P), + ∀ i,Continuous (fun t=>unitBrownianProcess (normalizedIncrement B s δ) t (ω i)) := by + apply ae_all_iff.mpr + intro i + exact (Measure.tendsto_eval_ae_ae (μ:=fun _ : Fin n=>P) (i:=i)) (brownian_unit_continuous hb) + have hm : ∀ᵐ ω ∂Measure.pi (fun _ : Fin n=>P), + (∃ t : UnitInterval,κ^2*(n:ℝ) < ∑ i,(B (s+δ*⟨t.1,t.2.1⟩) (ω i)-B s (ω i))^2) → + H*(n:ℝ) ≤ incrementEnergy B s δ n ω := by + filter_upwards [hc] with ω hω + rintro ⟨t,ht⟩ + have hh := increment_square_sum_le hδ.ne' n ω hω t + change _ ≤ (κ^2/H)*_ at hh + rw [div_mul_eq_mul_div,le_div_iff₀ hH] at hh + nlinarith [sq_pos_of_pos hκ] + calc + _ ≤ (Measure.pi (fun _ : Fin n=>P)).real {ω | H*(n:ℝ) ≤ incrementEnergy B s δ n ω} := + ENNReal.toReal_mono (measure_ne_top _ _) (measure_mono_ae hm) + _ ≤ _ := ht s δ hδ.ne' n + +theorem brownian_coordinate_modulus_small (hB : IsBrownianReal B P) {κ : ℝ} (hκ : 0<κ) : + ∃ δ₀ : ℝ, 0<δ₀ ∧ ∀ s δ : ℝ≥0, 0<δ → (δ:ℝ)≤δ₀ → ∀ n : ℕ, + (Measure.pi (fun _ : Fin n=>P)).real + {ω | ∃ t : UnitInterval, + κ^2*(n:ℝ) < ∑ i,(B (s+δ*⟨t.1,t.2.1⟩) (ω i)-B s (ω i))^2} ≤ exp (-(n:ℝ)) := by + let : IsProbabilityMeasure P := hB.isGaussianProcess.isProbabilityMeasure + obtain ⟨H,hH,ht⟩ := incrementEnergy_tail hB + refine ⟨κ^2/H,div_pos (sq_pos_of_pos hκ) hH,fun s δ hδ hδ₀ n=>?_⟩ + have hb : IsBrownianReal (normalizedIncrement B s δ) P := (hB.shift s).smul hδ.ne' + have hc : ∀ᵐ ω : Fin n→Ω ∂Measure.pi (fun _ : Fin n=>P), + ∀ i,Continuous (fun t=>unitBrownianProcess (normalizedIncrement B s δ) t (ω i)) := by + apply ae_all_iff.mpr + intro i + exact (Measure.tendsto_eval_ae_ae (μ:=fun _ : Fin n=>P) (i:=i)) (brownian_unit_continuous hb) + have hm : ∀ᵐ ω ∂Measure.pi (fun _ : Fin n=>P), + (∃ t : UnitInterval,κ^2*(n:ℝ) < ∑ i,(B (s+δ*⟨t.1,t.2.1⟩) (ω i)-B s (ω i))^2) → + H*(n:ℝ) ≤ incrementEnergy B s δ n ω := by + filter_upwards [hc] with ω hω + rintro ⟨t,ht⟩ + have hh := increment_square_sum_le hδ.ne' n ω hω t + have he : 0 ≤ incrementEnergy B s δ n ω := by + unfold incrementEnergy pathEnergy + exact Finset.sum_nonneg (fun i _=>sq_nonneg _) + have hh' := hh.trans (mul_le_mul_of_nonneg_right hδ₀ he) + rw [div_mul_eq_mul_div,le_div_iff₀ hH] at hh' + nlinarith [sq_pos_of_pos hκ] + calc + _ ≤ (Measure.pi (fun _ : Fin n=>P)).real {ω | H*(n:ℝ) ≤ incrementEnergy B s δ n ω} := + ENNReal.toReal_mono (measure_ne_top _ _) (measure_mono_ae hm) + _ ≤ _ := ht s δ hδ.ne' n +end SKRatioGaussian.PathBridge + +end +end + +section +noncomputable section + +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Matrices/OpNorm.lean b/lean/OAI/Probability/SKRatio/Matrices/OpNorm.lean new file mode 100644 index 0000000000000000000000000000000000000000..8f97c83ce3d926635e351f4b1ce8c5462364312b --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Matrices/OpNorm.lean @@ -0,0 +1,137 @@ +import Mathlib +import OAI.Probability.SKRatio.Matrices.SymmetricElementaryComm + +namespace OAI + +section +section +noncomputable section +open MeasureTheory ProbabilityTheory InformationTheory Real Set +open scoped NNReal ENNReal +open Filter +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius ENNReal NNReal +namespace SKRatioGaussian +open MeasureTheory ProbabilityTheory Matrix +open scoped BigOperators Matrix.Norms.Frobenius +variable {ι : Type*} [Fintype ι] [DecidableEq ι] + +lemma mul_symmetricElementary_mul (P Q : Matrix ι ι ℝ) (a b i k : ι) : + (P*symmetricElementary a b*Q) i k = P i a*Q b k+P i b*Q a k := by + simp [symmetricElementary,Matrix.mul_add, + Matrix.mul_apply,Matrix.single_apply,ite_and,add_mul,Finset.sum_add_distrib,ite_mul] + +lemma goe_inverse_contraction (K B : Matrix ι ι ℝ) (i : ι) : + (∑ b, (K*B*symmetricElementary i b*K) b i) = + (Matrix.trace (K*B))*K i i+∑ b, (K*B) b i*K b i := by + simp_rw [mul_symmetricElementary_mul] + rw [Finset.sum_add_distrib,← Finset.sum_mul,Matrix.trace] + exact add_comm _ _ + +def opNorm (M : Matrix ι ι ℝ) : ℝ := ‖M.toEuclideanLin.toContinuousLinearMap‖ +def colVec (M : Matrix ι ι ℝ) (k : ι) : EuclideanSpace ℝ ι := WithLp.toLp 2 (fun i => M i k) + +lemma colVec_eq (M : Matrix ι ι ℝ) (k : ι) : + colVec M k = M.toEuclideanLin.toContinuousLinearMap (EuclideanSpace.single k (1:ℝ)) := by + ext i + simp [colVec,Matrix.toLpLin_apply] + +lemma colVec_norm_le (M : Matrix ι ι ℝ) (k : ι) : ‖colVec M k‖ ≤ opNorm M := by + rw [colVec_eq] + simpa only [PiLp.norm_single,norm_one,mul_one,opNorm] using! + M.toEuclideanLin.toContinuousLinearMap.le_opNorm (EuclideanSpace.single k (1:ℝ)) + +lemma matrix_entry_le_opNorm (M : Matrix ι ι ℝ) (i k : ι) : |M i k| ≤ opNorm M := by + have h : |M i k| ≤ ‖colVec M k‖ := by + simpa only [colVec,Real.norm_eq_abs] using (PiLp.norm_apply_le (colVec M k) i) + exact h.trans (colVec_norm_le M k) + +lemma opNorm_mul (M N : Matrix ι ι ℝ) : opNorm (M*N) ≤ opNorm M*opNorm N := by + have he : (M*N).toEuclideanLin.toContinuousLinearMap = + M.toEuclideanLin.toContinuousLinearMap * N.toEuclideanLin.toContinuousLinearMap := by + ext x i + exact congrFun (congrArg (fun T : EuclideanSpace ℝ ι →ₗ[ℝ] EuclideanSpace ℝ ι => (T x).ofLp) + (Matrix.toLpLin_mul 2 2 2 M N)) i + exact (congrArg norm he).le.trans (norm_mul_le _ _) + +lemma goe_cross_contraction_bound (K B : Matrix ι ι ℝ) (i : ι) : + |∑ b, (K*B) b i*K b i| ≤ opNorm K*opNorm B*opNorm K := by + have hh := abs_real_inner_le_norm (colVec (K*B) i) (colVec K i) + change |∑ b, K b i*(K*B) b i| ≤ _ at hh + simp_rw [mul_comm (K _ _)] at hh + apply hh.trans + calc + ‖colVec (K*B) i‖*‖colVec K i‖ ≤ opNorm (K*B)*opNorm K := + mul_le_mul (colVec_norm_le _ _) (colVec_norm_le _ _) (norm_nonneg _) (norm_nonneg _) + _ ≤ _ := mul_le_mul_of_nonneg_right (opNorm_mul _ _) (norm_nonneg _) + +lemma trace_mul_diagonal (K : Matrix ι ι ℝ) (a : ι → ℝ) : + Matrix.trace (K*Matrix.diagonal a) = ∑ i, a i*K i i := by + simp [Matrix.trace,Matrix.mul_diagonal,mul_comm] + +theorem goe_inverse_loop_raw {r : ℝ} (hr : 0 ≤ r) (B : Matrix ι ι ℝ) (i : ι) + {K : Matrix ι ι ℝ → Matrix ι ι ℝ} {L : ℝ≥0} {C D : ℝ} + {s : Set (MatrixCoordinates ι → ℝ)} + (hf : ∀ a b, LipschitzWith L (fun g => K (goeMatrix r g) a b)) + (hC : ∀ g a b, ‖K (goeMatrix r g) a b‖ ≤ C) + (hD : ∀ g b, ‖(K (goeMatrix r g)*B*symmetricElementary i b*K (goeMatrix r g)) b i‖ ≤ D) + (hs : MeasurableSet s) + (hder : ∀ g ∈ s, ∀ b, HasDerivAt + (fun t : ℝ => K (goeMatrix r g+t • symmetricElementary i b) b i) + ((K (goeMatrix r g)*B*symmetricElementary i b*K (goeMatrix r g)) b i) 0) : + |(∫ g, (goeMatrix r g*K (goeMatrix r g)) i i + ∂Measure.pi (fun _ : MatrixCoordinates ι => gaussianReal 0 1)) - + r*(∫ g, Matrix.trace (K (goeMatrix r g)*B)*K (goeMatrix r g) i i+ + ∑ b, (K (goeMatrix r g)*B) b i*K (goeMatrix r g) b i + ∂Measure.pi (fun _ : MatrixCoordinates ι => gaussianReal 0 1))| ≤ + (Fintype.card ι:ℝ)*(sqrt (2*r)*(L:ℝ)+r*D)* + (Measure.pi (fun _ : MatrixCoordinates ι => gaussianReal 0 1)).real sᶜ := by + let μ := Measure.pi (fun _ : MatrixCoordinates ι => gaussianReal 0 1) + let d (b : ι) (g : MatrixCoordinates ι → ℝ) := + (K (goeMatrix r g)*B*symmetricElementary i b*K (goeMatrix r g)) b i + have hK : Continuous (fun g => K (goeMatrix r g)) := + continuous_pi (fun a => continuous_pi (fun b => (hf a b).continuous)) + have hd (b : ι) : Continuous (d b) := by + exact ((hK.mul continuous_const).mul continuous_const |>.mul hK).matrix_elem b i + have hdint (b : ι) : Integrable (d b) μ := + Integrable.mono' (integrable_const D) (hd b).aestronglyMeasurable (ae_of_all _ (fun g => hD g b)) + have hwint (b : ι) : Integrable (fun g => goeMatrix r g i b*K (goeMatrix r g) b i) μ := by + have he (a : MatrixCoordinates ι) : Integrable (fun g : MatrixCoordinates ι → ℝ => g a) μ := + integrable_eval (i := a) IsGaussian.integrable_id + have hw : Integrable (fun g => goeMatrix r g i b) μ := + ((he (.inl (i,b))).add (he (.inl (b,i)))).const_mul _ + simpa only [mul_comm] using hw.bdd_mul (hf b i).continuous.aestronglyMeasurable + (ae_of_all _ (fun g => hC g b i)) + have hb (b : ι) := goe_IBP_error hr i b (H := fun M => K M b i) (d := d b) (hf b i) (fun g => hC g b i) + (hd b).measurable (fun g => hD g b) hs (fun g hg => hder g hg b) + have he : (∫ g, Matrix.trace (K (goeMatrix r g)*B)*K (goeMatrix r g) i i+ + ∑ b, (K (goeMatrix r g)*B) b i*K (goeMatrix r g) b i ∂μ) = + ∑ b, ∫ g, d b g ∂μ := by + simp_rw [← goe_inverse_contraction] + exact integral_finsetSum Finset.univ (fun b _ => hdint b) + change |(∫ g, (goeMatrix r g*K (goeMatrix r g)) i i ∂μ)-r*(_)| ≤ _ + rw [he] + simp_rw [Matrix.mul_apply] + rw [integral_finsetSum Finset.univ (fun b _ => hwint b),Finset.mul_sum,← Finset.sum_sub_distrib] + calc + _ ≤ ∑ b, |(∫ g, goeMatrix r g i b*K (goeMatrix r g) b i ∂μ)-r*(∫ g, d b g ∂μ)| := + Finset.abs_sum_le_sum_abs _ _ + _ ≤ ∑ _b : ι, (sqrt (2*r)*(L:ℝ)+r*D)*μ.real sᶜ := + Finset.sum_le_sum (fun b _ => hb b) + _ = _ := by simp only [Finset.sum_const,Finset.card_univ,nsmul_eq_mul]; ring + +end SKRatioGaussian + +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius NNReal + +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Matrices/OpNormKernelMatrixSub.lean b/lean/OAI/Probability/SKRatio/Matrices/OpNormKernelMatrixSub.lean new file mode 100644 index 0000000000000000000000000000000000000000..cb6e73e94e7d2d8ab6937fbbcb2bd84ec3578aca --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Matrices/OpNormKernelMatrixSub.lean @@ -0,0 +1,94 @@ +import Mathlib +import OAI.Probability.SKRatio.Matrices.LinCLM +import OAI.Probability.SKRatio.Matrices.FourierMoment + +namespace OAI + +section +section +noncomputable section +open MeasureTheory ProbabilityTheory InformationTheory Real Set +open scoped NNReal ENNReal +open Filter +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius ENNReal NNReal +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius NNReal +noncomputable section +open MeasureTheory ProbabilityTheory Real Set Filter +open MeasureTheory.Measure +open scoped ENNReal NNReal MeasureTheory Topology +open MeasureTheory +noncomputable section +noncomputable section +open MeasureTheory Set NormedSpace +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius +namespace SKRatioGaussian.ComplexMatrix +open MeasureTheory NormedSpace +open scoped FourierTransform SchwartzMap +variable {ι : Type*} [Fintype ι] [DecidableEq ι] + +local instance : ContinuousENorm (Matrix ι ι ℂ) := + @SeminormedAddGroup.toContinuousENorm _ Matrix.frobeniusSeminormedAddCommGroup.toSeminormedAddGroup +local instance : TopologicalSpace.PseudoMetrizableSpace (Matrix ι ι ℂ) := + inferInstanceAs (TopologicalSpace.PseudoMetrizableSpace (ι → ι → ℂ)) + +lemma opNorm_kernelMatrix_sub {g : ℝ → ℂ} (hg : Integrable g) + (hg₁ : Integrable (fun t : ℝ => ‖g t‖*|t|)) + (M N : Matrix ι ι ℂ) (hM : Mᴴ = M) (hN : Nᴴ = N) : + opNorm (kernelMatrix g M-kernelMatrix g N) ≤ + (∫ t : ℝ, ‖g t‖*|t|)*opNorm (M-N) := by + let : CompleteSpace (EuclideanSpace ℂ ι) := PiLp.completeSpace _ _ + let : CompleteSpace (EuclideanSpace ℂ ι →L[ℂ] EuclideanSpace ℂ ι) := + ContinuousLinearMap.instCompleteSpace + let F := fun t : ℝ => g t • exp (imaginary t M)-g t • exp (imaginary t N) + have hi : Integrable F := (kernel_integrable hg M hM).sub (kernel_integrable hg N hN) + have hh := linCLM.integral_comp_comm hi + have he : kernelMatrix g M-kernelMatrix g N = ∫ t : ℝ, F t := by + exact (integral_sub (kernel_integrable hg M hM) (kernel_integrable hg N hN)).symm + rw [he] + change ‖linCLM (∫ t : ℝ, F t)‖ ≤ _ + calc + _ = ‖∫ t : ℝ, linCLM (F t)‖ := congrArg norm hh.symm + _ ≤ ∫ t : ℝ, ‖linCLM (F t)‖ := norm_integral_le_integral_norm _ + _ ≤ ∫ t : ℝ, (‖g t‖*|t|)*opNorm (M-N) := by + apply integral_mono (linCLM.integrable_comp hi).norm (hg₁.mul_const _) + intro t + have hb := opNorm_exp_sub (imaginary t M) (imaginary t N) (imaginary_skew t M hM) (imaginary_skew t N hN) + rw [← imaginary_sub,imaginary_opNorm] at hb + change opNorm (F t) ≤ _ + dsimp only [F] + rw [← smul_sub,opNorm_csmul] + exact (mul_le_mul_of_nonneg_left hb (norm_nonneg _)).trans_eq (by ring) + _ = _ := integral_mul_const _ _ + +lemma schwartzMatrix_opNorm_lipschitz (f : 𝓢(ℝ,ℂ)) (M N : Matrix ι ι ℂ) + (hM : Mᴴ = M) (hN : Nᴴ = N) : + opNorm (schwartzMatrix f M-schwartzMatrix f N) ≤ + (2*Real.pi*fourierMoment f 1)*opNorm (M-N) := by + have hf₁ : Integrable (fun t : ℝ => ‖(𝓕 f) t‖*|t|) := by + simpa only [pow_one] using fourierMoment_integrable f 1 + have hh := opNorm_kernelMatrix_sub (𝓕 f).integrable hf₁ + ((2*Real.pi:ℝ) • M) ((2*Real.pi:ℝ) • N) (by simp [hM]) (by simp [hN]) + rw [← smul_sub,opNorm_smul,abs_of_pos (by positivity : 0 < (2*Real.pi:ℝ))] at hh + exact hh.trans_eq (by simp only [fourierMoment,pow_one]; ring) + +end SKRatioGaussian.ComplexMatrix + +end +end +end +end +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Matrices/OpNormNonneg.lean b/lean/OAI/Probability/SKRatio/Matrices/OpNormNonneg.lean new file mode 100644 index 0000000000000000000000000000000000000000..9a73e8763ce866a15c6d6e1a5b11b38948e3d658 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Matrices/OpNormNonneg.lean @@ -0,0 +1,129 @@ +import Mathlib +import OAI.Probability.SKRatio.Matrices.LinEquiv + +namespace OAI + +section +section +noncomputable section +open MeasureTheory ProbabilityTheory InformationTheory Real Set +open scoped NNReal ENNReal +open Filter +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius ENNReal NNReal +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius NNReal +noncomputable section +open MeasureTheory ProbabilityTheory Real Set Filter +open MeasureTheory.Measure +open scoped ENNReal NNReal MeasureTheory Topology +open MeasureTheory +noncomputable section +noncomputable section +open MeasureTheory Set NormedSpace +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius +namespace SKRatioGaussian.ComplexMatrix +variable {ι : Type*} [Fintype ι] [DecidableEq ι] + +lemma opNorm_nonneg (M : Matrix ι ι ℂ) : 0 ≤ opNorm M := norm_nonneg _ +lemma opNorm_add (M N : Matrix ι ι ℂ) : opNorm (M+N) ≤ opNorm M+opNorm N := by + change ‖linEquiv (M+N)‖ ≤ _ + rw [(linEquiv (ι := ι)).map_add] + exact norm_add_le _ _ +lemma opNorm_sub (M N : Matrix ι ι ℂ) : opNorm (M-N) ≤ opNorm M+opNorm N := by + change ‖lin (M-N)‖ ≤ _ + have hh : lin (M-N) = lin M-lin N := linEquiv.map_sub M N + rw [hh] + exact norm_sub_le _ _ +lemma opNorm_mul (M N : Matrix ι ι ℂ) : opNorm (M*N) ≤ opNorm M*opNorm N := by + change ‖lin (M*N)‖ ≤ _ + rw [lin_mul] + exact norm_mul_le _ _ +lemma opNorm_neg (M : Matrix ι ι ℂ) : opNorm (-M) = opNorm M := by + change ‖lin (-M)‖ = _ + have hh : lin (-M) = -lin M := linEquiv.map_neg M + rw [hh,norm_neg] + rfl +lemma opNorm_one_le : opNorm (1 : Matrix ι ι ℂ) ≤ 1 := by + rw [opNorm,lin_one] + exact ContinuousLinearMap.norm_id_le + +lemma sandwich_frobenius (D E : Matrix ι ι ℂ) : + ‖D*E*D‖ ≤ opNorm D^2*‖E‖ := by + calc + _ ≤ ‖D*E‖*opNorm D := frobenius_mul_le_opNorm_right _ _ + _ ≤ (opNorm D*‖E‖)*opNorm D := mul_le_mul_of_nonneg_right (frobenius_mul_le_opNorm _ _) (opNorm_nonneg _) + _ = _ := by ring + +lemma sandwich_opNorm (D E : Matrix ι ι ℂ) : + opNorm (D*E*D) ≤ opNorm D^2*opNorm E := by + calc + _ ≤ opNorm (D*E)*opNorm D := opNorm_mul _ _ + _ ≤ (opNorm D*opNorm E)*opNorm D := mul_le_mul_of_nonneg_right (opNorm_mul _ _) (opNorm_nonneg _) + _ = _ := by ring + +lemma sandwich_difference_frobenius (D D' E : Matrix ι ι ℂ) : + ‖D*E*D-D'*E*D'‖ ≤ (opNorm D+opNorm D')*opNorm (D-D')*‖E‖ := by + have he : D*E*D-D'*E*D' = (D-D')*E*D+D'*E*(D-D') := by noncomm_ring + rw [he] + calc + _ ≤ ‖(D-D')*E*D‖+‖D'*E*(D-D')‖ := norm_add_le _ _ + _ ≤ (opNorm (D-D')*‖E‖)*opNorm D+(opNorm D'*‖E‖)*opNorm (D-D') := by + apply add_le_add + · exact (frobenius_mul_le_opNorm_right _ _).trans + (mul_le_mul_of_nonneg_right (frobenius_mul_le_opNorm _ _) (opNorm_nonneg _)) + · exact (frobenius_mul_le_opNorm_right _ _).trans + (mul_le_mul_of_nonneg_right (frobenius_mul_le_opNorm _ _) (opNorm_nonneg _)) + _ = _ := by ring + +lemma sandwich_difference_opNorm (D D' E : Matrix ι ι ℂ) : + opNorm (D*E*D-D'*E*D') ≤ (opNorm D+opNorm D')*opNorm (D-D')*opNorm E := by + have he : D*E*D-D'*E*D' = (D-D')*E*D+D'*E*(D-D') := by noncomm_ring + rw [he] + calc + _ ≤ opNorm ((D-D')*E*D)+opNorm (D'*E*(D-D')) := opNorm_add _ _ + _ ≤ (opNorm (D-D')*opNorm E)*opNorm D+(opNorm D'*opNorm E)*opNorm (D-D') := by + apply add_le_add + · exact (opNorm_mul _ _).trans + (mul_le_mul_of_nonneg_right (opNorm_mul _ _) (opNorm_nonneg _)) + · exact (opNorm_mul _ _).trans + (mul_le_mul_of_nonneg_right (opNorm_mul _ _) (opNorm_nonneg _)) + _ = _ := by ring + +lemma product_four_point (a b c d e f g h : Matrix ι ι ℂ) : + ‖(a*e-b*f)-(c*g-d*h)‖ ≤ + ‖(a-b)-(c-d)‖*opNorm e + ‖c-d‖*opNorm (e-g) + + opNorm (b-d)*‖e-f‖ + opNorm d*‖(e-f)-(g-h)‖ := by + have he : (a*e-b*f)-(c*g-d*h) = + ((a-b)-(c-d))*e+(c-d)*(e-g)+(b-d)*(e-f)+d*((e-f)-(g-h)) := by noncomm_ring + rw [he] + calc + _ ≤ ‖((a-b)-(c-d))*e+(c-d)*(e-g)+(b-d)*(e-f)‖+‖d*((e-f)-(g-h))‖ := norm_add_le _ _ + _ ≤ (‖((a-b)-(c-d))*e+(c-d)*(e-g)‖+‖(b-d)*(e-f)‖)+‖d*((e-f)-(g-h))‖ := by gcongr; exact norm_add_le _ _ + _ ≤ ((‖((a-b)-(c-d))*e‖+‖(c-d)*(e-g)‖)+‖(b-d)*(e-f)‖)+‖d*((e-f)-(g-h))‖ := by gcongr; exact norm_add_le _ _ + _ ≤ _ := by + gcongr + · exact frobenius_mul_le_opNorm_right _ _ + · exact frobenius_mul_le_opNorm_right _ _ + · exact frobenius_mul_le_opNorm _ _ + · exact frobenius_mul_le_opNorm _ _ + +end SKRatioGaussian.ComplexMatrix + +end +end +end +end +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Matrices/PathEnergy.lean b/lean/OAI/Probability/SKRatio/Matrices/PathEnergy.lean new file mode 100644 index 0000000000000000000000000000000000000000..9fd2a6d2ef73b483d0e7f4b905ec0fcd968b6ea7 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Matrices/PathEnergy.lean @@ -0,0 +1,88 @@ +import Mathlib +import OAI.Probability.SKRatio.Matrices.UnitInterval + +namespace OAI + +section +section +noncomputable section +namespace SKRatioGaussian.PathBridge +open MeasureTheory ProbabilityTheory Real Set +open scoped BigOperators ENNReal NNReal Topology + +def pathEnergy (n : ℕ) (f : Fin n→UnitPath) : ℝ := ∑ i,‖f i‖^2 + +lemma energy_exponential_prod (n : ℕ) (a : ℝ) (f : Fin n→UnitPath) : + exp (a*pathEnergy n f)=∏ i,exp (a*‖f i‖^2) := by + rw [pathEnergy,Finset.mul_sum,exp_sum] + +lemma pathEnergy_exponential_integrable (μ : Measure UnitPath) [IsProbabilityMeasure μ] + (a : ℝ) (hi : Integrable (fun f : UnitPath=>exp (a*‖f‖^2)) μ) (n : ℕ) : + Integrable (fun f=>exp (a*pathEnergy n f)) (Measure.pi (fun _ : Fin n=>μ)) := by + simp_rw [energy_exponential_prod] + exact Integrable.fintype_prod (fun _=>hi) + +lemma pathEnergy_exponential_integral (μ : Measure UnitPath) [IsProbabilityMeasure μ] + (a : ℝ) (n : ℕ) : + (∫ f,exp (a*pathEnergy n f) ∂Measure.pi (fun _ : Fin n=>μ))= + (∫ f : UnitPath,exp (a*‖f‖^2) ∂μ)^n := by + simp_rw [energy_exponential_prod] + simpa using integral_fintype_prod_eq_pow (ι:=Fin n) (μ:=μ) (fun f : UnitPath=>exp (a*‖f‖^2)) + +theorem pathEnergy_dimension_tail (μ : Measure UnitPath) [IsProbabilityMeasure μ] + (hG : IsGaussianProcess (fun t : UnitInterval=>fun f : UnitPath=>f t) μ) + (h0 : ∀ t : UnitInterval, ∫ f : UnitPath,f t ∂μ=0) : + ∃ H : ℝ, 0μ)).real {f | H*(n:ℝ) ≤ pathEnergy n f} ≤ exp (-(n:ℝ)) := by + obtain ⟨a,ha,hi⟩ := centered_gaussian_path_fernique μ hG h0 + let M := ∫ f : UnitPath,exp (a*‖f‖^2) ∂μ + have hM : 1≤M := by + calc + 1 = ∫ _ : UnitPath,(1:ℝ) ∂μ := by simp + _ ≤ M := integral_mono (integrable_const _) hi (fun f=>by + exact one_le_exp_iff.mpr (mul_nonneg ha.le (sq_nonneg _))) + have hMp : 0?_⟩ + calc + _ ≤ exp (-a*(H*(n:ℝ)))*mgf (pathEnergy n) (Measure.pi (fun _ : Fin n=>μ)) a := + measure_ge_le_exp_mul_mgf _ ha.le (pathEnergy_exponential_integrable μ a hi n) + _ = exp (-(n:ℝ)) := by + rw [mgf,pathEnergy_exponential_integral] + change exp (-a*(H*(n:ℝ)))*M^n=_ + rw [← exp_log hMp,← exp_nat_mul,← exp_add] + congr 1 + dsimp [H] + field_simp + ring + +theorem scaledPath_dimension_tail (μ : Measure UnitPath) [IsProbabilityMeasure μ] + (hG : IsGaussianProcess (fun t : UnitInterval=>fun f : UnitPath=>f t) μ) + (h0 : ∀ t : UnitInterval, ∫ f : UnitPath,f t ∂μ=0) {κ : ℝ} (hκ : 0<κ) : + ∃ δ : ℝ, 0<δ ∧ ∀ n : ℕ, + (Measure.pi (fun _ : Fin n=>μ)).real + {f | κ^2*(n:ℝ) ≤ δ*pathEnergy n f} ≤ exp (-(n:ℝ)) := by + obtain ⟨H,hH,ht⟩ := pathEnergy_dimension_tail μ hG h0 + refine ⟨κ^2/H,div_pos (sq_pos_of_pos hκ) hH,fun n=>?_⟩ + convert ht n using 2 + ext f + simp only [Set.mem_ofPred_eq] + rw [div_mul_eq_mul_div,le_div_iff₀ hH] + constructor <;> intro h + · nlinarith [sq_pos_of_pos hκ] + · nlinarith [sq_pos_of_pos hκ] +end SKRatioGaussian.PathBridge + +end +end + +section + +noncomputable section + +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Matrices/PathEvaluations.lean b/lean/OAI/Probability/SKRatio/Matrices/PathEvaluations.lean new file mode 100644 index 0000000000000000000000000000000000000000..fb7e73667ddb33f881d9f28b5b0884d4884b2a8b --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Matrices/PathEvaluations.lean @@ -0,0 +1,118 @@ +import Mathlib +import OAI.Probability.SKRatio.Matrices.UnitInterval + +namespace OAI + +section +section +noncomputable section +namespace SKRatioGaussian.PathBridge +open MeasureTheory ProbabilityTheory Real Set TopologicalSpace +open scoped BigOperators ENNReal NNReal Topology + +def pathEvaluations (f : UnitPath) : ℕ→ℝ := fun k=>f (denseSeq UnitInterval k) +lemma measurableEmbedding_pathEvaluations : MeasurableEmbedding pathEvaluations := by + apply Continuous.measurableEmbedding + · apply continuous_pi + intro k + exact (ContinuousMap.evalCLM ℝ (denseSeq UnitInterval k)).continuous + · intro p q h + apply ContinuousMap.coe_injective + apply (denseRange_denseSeq UnitInterval).equalizer p.continuous q.continuous + exact h + +variable {Ω : Type*} [MeasurableSpace Ω] + +def continuousPathVersion (X : UnitInterval→Ω→ℝ) (ω : Ω) : UnitPath := by + classical + exact if h : Continuous (fun t=>X t ω) then ⟨fun t=>X t ω,h⟩ else 0 + +lemma continuousPathVersion_eval {μ : Measure Ω} {X : UnitInterval→Ω→ℝ} + (hc : ∀ᵐ ω ∂μ,Continuous (fun t=>X t ω)) (t : UnitInterval) : + (fun ω=>continuousPathVersion X ω t)=ᵐ[μ] X t := by + filter_upwards [hc] with ω hω + simp only [continuousPathVersion,dite_eq_left hω,ContinuousMap.coe_mk] + +lemma aemeasurable_continuousPathVersion {μ : Measure Ω} {X : UnitInterval→Ω→ℝ} + (hX : ∀ t,AEMeasurable (X t) μ) + (hc : ∀ᵐ ω ∂μ,Continuous (fun t=>X t ω)) : + AEMeasurable (continuousPathVersion X) μ := by + apply measurableEmbedding_pathEvaluations.aemeasurable_comp_iff.mp + apply AEMeasurable.of_eval + intro k + exact (hX _).congr (continuousPathVersion_eval hc _).symm + +lemma gaussian_continuousPathVersion {μ : Measure Ω} {X : UnitInterval→Ω→ℝ} + (hG : IsGaussianProcess X μ) + (hc : ∀ᵐ ω ∂μ,Continuous (fun t=>X t ω)) : + IsGaussianProcess (fun t : UnitInterval=>fun f : UnitPath=>f t) + (μ.map (continuousPathVersion X)) := by + have hm := aemeasurable_continuousPathVersion hG.aemeasurable hc + have hv := hG.congr (fun t=>(continuousPathVersion_eval hc t).symm) + constructor + intro I + have he : Measurable (fun f : UnitPath=>I.restrict (fun t=>f t)) := by + apply Measurable.of_eval + intro t + exact (show Continuous (fun f : UnitPath=>f (t:UnitInterval)) from + (ContinuousMap.evalCLM ℝ (t:UnitInterval)).continuous).measurable + refine ⟨he.aemeasurable, ?_⟩ + rw [AEMeasurable.map_map_of_aemeasurable he.aemeasurable hm] + exact (hv.hasGaussianLaw I).isGaussian_map + +lemma mean_continuousPathVersion {μ : Measure Ω} {X : UnitInterval→Ω→ℝ} + (hX : ∀ t,AEMeasurable (X t) μ) + (hc : ∀ᵐ ω ∂μ,Continuous (fun t=>X t ω)) (t : UnitInterval) : + (∫ f : UnitPath,f t ∂μ.map (continuousPathVersion X))=∫ ω,X t ω ∂μ := by + have he : Measurable (fun f : UnitPath=>f t) := + (show Continuous (fun f : UnitPath=>f t) from (ContinuousMap.evalCLM ℝ t).continuous).measurable + rw [integral_map (aemeasurable_continuousPathVersion hX hc) he.aestronglyMeasurable] + exact integral_congr_ae (continuousPathVersion_eval hc t) + +theorem continuous_gaussian_process_fernique {μ : Measure Ω} [IsProbabilityMeasure μ] + {X : UnitInterval→Ω→ℝ} (hG : IsGaussianProcess X μ) + (hc : ∀ᵐ ω ∂μ,Continuous (fun t=>X t ω)) + (h0 : ∀ t,∫ ω,X t ω ∂μ=0) : + ∃ a : ℝ, 0exp (a*‖continuousPathVersion X ω‖^2)) μ := by + have hm := aemeasurable_continuousPathVersion hG.aemeasurable hc + let : IsProbabilityMeasure (μ.map (continuousPathVersion X)) := + (Measure.isProbabilityMeasure_map_iff hm).2 inferInstance + obtain ⟨a,ha,hi⟩ := centered_gaussian_path_fernique (μ.map (continuousPathVersion X)) + (gaussian_continuousPathVersion hG hc) (fun t=>by + rw [mean_continuousPathVersion hG.aemeasurable hc,h0]) + refine ⟨a,ha,?_⟩ + exact (integrable_map_measure (by fun_prop) hm).mp hi + +def unitBrownianProcess (B : ℝ≥0→Ω→ℝ) : UnitInterval→Ω→ℝ := + fun t=>B ⟨t.1,t.2.1⟩ + +lemma brownian_unit_gaussian {P : Measure Ω} {B : ℝ≥0→Ω→ℝ} + (hB : IsBrownianReal B P) : IsGaussianProcess (unitBrownianProcess B) P := + hB.isGaussianProcess.comp_right (fun t : UnitInterval=>⟨t.1,t.2.1⟩) + +lemma brownian_unit_continuous {P : Measure Ω} {B : ℝ≥0→Ω→ℝ} + (hB : IsBrownianReal B P) : + ∀ᵐ ω ∂P,Continuous (fun t=>unitBrownianProcess B t ω) := by + filter_upwards [hB.cont] with ω hω + exact hω.comp (by fun_prop) + +theorem brownian_unit_fernique {P : Measure Ω} [IsProbabilityMeasure P] + {B : ℝ≥0→Ω→ℝ} (hB : IsBrownianReal B P) : + ∃ a : ℝ, 0exp (a*‖continuousPathVersion (unitBrownianProcess B) ω‖^2)) P := + continuous_gaussian_process_fernique (brownian_unit_gaussian hB) + (brownian_unit_continuous hB) (fun time=>hB.integral_eval ⟨time.1,time.2.1⟩) +end SKRatioGaussian.PathBridge + +end +end + +section + +noncomputable section + +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Matrices/PathResolvent.lean b/lean/OAI/Probability/SKRatio/Matrices/PathResolvent.lean new file mode 100644 index 0000000000000000000000000000000000000000..129fc160561e557ed8abb2b1df08e85a77f45b01 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Matrices/PathResolvent.lean @@ -0,0 +1,88 @@ +import Mathlib + +namespace OAI + +section +section +noncomputable section +open MeasureTheory ProbabilityTheory InformationTheory Real Set +open scoped NNReal ENNReal +open Filter +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius ENNReal NNReal +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius NNReal +noncomputable section +open MeasureTheory ProbabilityTheory Real Set Filter +open MeasureTheory.Measure +open scoped ENNReal NNReal MeasureTheory Topology +open MeasureTheory +noncomputable section +noncomputable section +open MeasureTheory Set NormedSpace +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius +noncomputable section +open Set Real +open scoped Topology +noncomputable section +open Matrix Set Filter +open scoped Topology Matrix.Norms.Frobenius +noncomputable section +open Matrix NormedSpace ContinuousLinearMap +open scoped Matrix.Norms.Frobenius +namespace SKRatioGaussian.ComplexMatrix +variable {ι : Type*} [Fintype ι] [DecidableEq ι] + +lemma matrix_hasDerivAt_inverse {Q : ℝ → Matrix ι ι ℂ} {Q' : Matrix ι ι ℂ} {t : ℝ} + (hQ : HasDerivAt Q Q' t) (hunit : IsUnit (Q t)) : + HasDerivAt (fun s => (Q s)⁻¹) (-(Q t)⁻¹*Q'*(Q t)⁻¹) t := by + obtain ⟨u, hu⟩ := hunit + have hfi := hasFDerivAt_ringInverse (𝕜 := ℝ) u + rw [hu] at hfi + have hi := hfi.comp_hasDerivAt t hQ + have hv : (↑u⁻¹ : Matrix ι ι ℂ) = (Q t)⁻¹ := by + rw [← hu,Matrix.nonsing_inv_eq_ringInverse,Ring.inverse_unit] + simpa only [Function.comp_def,← Matrix.nonsing_inv_eq_ringInverse,_root_.neg_apply, + ContinuousLinearMap.mulLeftRight_apply,hv,neg_mul] using! hi + +noncomputable def pathResolvent (z b : ℝ) (A M : Matrix ι ι ℂ) : Matrix ι ι ℂ := + (1-z • (A*M)+(z^2*b) • A)⁻¹ + +lemma pathResolvent_derivative (z b : ℝ) (A M E : Matrix ι ι ℂ) + (hunit : IsUnit (1-z • (A*M)+(z^2*b) • A)) : + HasDerivAt (fun t : ℝ => pathResolvent z b A (M+t • E)) + (z • (pathResolvent z b A M*A*E*pathResolvent z b A M)) 0 := by + have hm : HasDerivAt (fun t : ℝ => M+t • E) E 0 := by + convert! (hasDerivAt_id (0:ℝ)).smul_const E |>.const_add M using 1 + simp only [one_smul] + have hq := ((hm.const_mul A).const_smul z).const_sub 1 |>.add_const ((z^2*b) • A) + have hq' : HasDerivAt (fun t : ℝ => 1-z • (A*(M+t • E))+(z^2*b) • A) (-(z • (A*E))) 0 := hq + have hi := matrix_hasDerivAt_inverse hq' (by simpa using hunit) + simpa only [pathResolvent,zero_smul,add_zero,mul_neg,neg_mul,smul_neg,neg_neg,mul_smul_comm,smul_mul_assoc,mul_assoc] using! hi + +end SKRatioGaussian.ComplexMatrix + +noncomputable section +open Matrix + +end +end +end +end +end +end +end +end +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Matrices/PlantedGOE.lean b/lean/OAI/Probability/SKRatio/Matrices/PlantedGOE.lean new file mode 100644 index 0000000000000000000000000000000000000000..93ea4dddf8e434cea80c7a98749d58eb9af6c401 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Matrices/PlantedGOE.lean @@ -0,0 +1,231 @@ +import Mathlib +import OAI.Probability.SKRatio.Matrices.GaussianSupport +import OAI.Probability.SKRatio.Matrices.GOERegression +import OAI.Probability.SKRatio.Gaussian.Planted + +namespace OAI + +section +noncomputable section +open scoped BigOperators NNReal ENNReal Matrix Matrix.Norms.Elementwise Topology +open MeasureTheory ProbabilityTheory Filter Real +namespace SKRatio.Planted +open SKRatioClock.Regression +attribute [local instance] Classical.propDecidable +variable {n : ℕ} + +def augmented (β : ℝ) (g : (Fin n × Fin n) → ℝ) : Matrix (Fin n) (Fin n) ℝ := + fun i j => β * goe g i j + β^2/(n:ℝ) + +def augmentedDisorder (β : ℝ) (g : (Fin n × Fin n) → ℝ) : Disorder n := + fun e => augmented β g e.1.1 e.1.2 + +lemma augmented_symmetric (β : ℝ) (g : (Fin n × Fin n) → ℝ) : + (augmented β g)ᵀ = augmented β g := by + funext i j + simp only [Matrix.transpose_apply,augmented,goe,add_comm (g (j,i))] + +lemma augmentedDisorder_gaussian (β : ℝ) : + HasGaussianLaw (augmentedDisorder (n := n) β) (standardArrayLaw (Fin n × Fin n)) := by + let L : ((Fin n × Fin n) → ℝ) →L[ℝ] Disorder n := + β • ContinuousLinearMap.pi (fun e : Edge n => (entryCLM e.1.1 e.1.2).comp (goeCLM n)) + have h := gaussian_add_constant (coordinates_gaussian.map_fun L) (fun _ : Edge n => β^2/(n:ℝ)) + apply h.congr + exact Eventually.of_forall (fun g => by + funext e + simp only [L,smul_apply, + ContinuousLinearMap.pi_apply,ContinuousLinearMap.comp_apply,entryCLM_apply, + goeCLM_apply,Pi.add_apply,Pi.smul_apply,smul_eq_mul,augmentedDisorder,augmented]) + +lemma augmented_mean (β : ℝ) (i j : Fin n) : + (∫ g, augmented β g i j ∂standardArrayLaw (Fin n × Fin n)) = β^2/(n:ℝ) := by + unfold augmented + rw [integral_add (((goe_gaussian n).eval i |>.eval j).integrable.const_mul β) + (integrable_const _),integral_const_mul,goe_entry_mean] + simp + +lemma augmented_covariance (hn : 0 < n) (β : ℝ) (i j k l : Fin n) : + cov[fun g => augmented β g i j, fun g => augmented β g k l; + standardArrayLaw (Fin n × Fin n)] = + (β^2/(n:ℝ))*((if i=k ∧ j=l then 1 else 0)+(if i=l ∧ j=k then 1 else 0)) := by + unfold augmented + rw [covariance_add_const_left (((goe_gaussian n).eval i |>.eval j).integrable.const_mul β), + covariance_add_const_right (((goe_gaussian n).eval k |>.eval l).integrable.const_mul β), + covariance_const_mul_left,covariance_const_mul_right,goe_entry_covariance hn] + ring + +lemma augmentedDisorder_covariance (hn : 0 < n) (β : ℝ) (e f : Edge n) : + cov[fun g => augmentedDisorder β g e,fun g => augmentedDisorder β g f; + standardArrayLaw (Fin n × Fin n)] = if e=f then β^2/(n:ℝ) else 0 := by + unfold augmentedDisorder + rw [augmented_covariance hn] + have heq : e=f ↔ e.1.1=f.1.1 ∧ e.1.2=f.1.2 := by + simp only [Subtype.ext_iff,Prod.ext_iff] + have hcross : ¬(e.1.1=f.1.2 ∧ e.1.2=f.1.1) := by + rintro ⟨h₁,h₂⟩ + have h := e.2 + rw [h₁,h₂] at h + exact lt_asymm f.2 h + simp only [ite_eq_right hcross,add_zero,←heq] + split_ifs <;> simp + +theorem augmentedDisorder_hasLaw (hn : 0 < n) (β : ℝ) : + HasLaw (augmentedDisorder (n := n) β) (law β n) (standardArrayLaw (Fin n × Fin n)) := by + have hg := augmentedDisorder_gaussian (n := n) β + have hl (e : Edge n) : HasLaw (fun g => augmentedDisorder β g e) + (gaussianReal (β^2/(n:ℝ)) (Real.toNNReal (β^2/(n:ℝ)))) + (standardArrayLaw (Fin n × Fin n)) := by + refine ⟨(hg.eval e).aemeasurable,?_⟩ + rw [(hg.eval e).map_eq_gaussianReal,show (∫ g, augmentedDisorder β g e + ∂standardArrayLaw (Fin n × Fin n)) = β^2/(n:ℝ) from augmented_mean β _ _, + ←covariance_self (hg.eval e).aemeasurable,augmentedDisorder_covariance hn,ite_eq_left rfl] + exact iIndepFun.hasLaw_pi hl (hg.iIndepFun_of_covariance_eq_zero + (fun e f h => by rw [augmentedDisorder_covariance hn,ite_eq_right h])) + +lemma coupling_augmentedDisorder (β : ℝ) (g : (Fin n × Fin n) → ℝ) : + Matrix.of (coupling (augmentedDisorder β g)) = augmented β g - Matrix.diagonal (fun i => augmented β g i i) := by + ext i j + by_cases h : i=j + · subst j + simp [coupling] + · rcases lt_or_gt_of_ne h with hij | hij + · simp [coupling,hij,h,augmentedDisorder] + · simp [coupling,hij,not_lt_of_gt hij,h,augmentedDisorder,augmented,goe,add_comm] + +def augmentedField (β : ℝ) (g : (Fin n × Fin n) → ℝ) : Fin n → ℝ := + fun i => ∑ j, augmented β g i j + +lemma augmentedField_gaussian (β : ℝ) : + HasGaussianLaw (augmentedField (n := n) β) (standardArrayLaw (Fin n × Fin n)) := by + let L : ((Fin n × Fin n) → ℝ) →L[ℝ] (Fin n → ℝ) := + β • ContinuousLinearMap.pi (fun i : Fin n => ∑ j : Fin n, + (entryCLM i j).comp (goeCLM n)) + have h := gaussian_add_constant (coordinates_gaussian.map_fun L) + (fun _ : Fin n => (n:ℝ)*(β^2/(n:ℝ))) + apply h.congr + exact Eventually.of_forall (fun g => by + ext i + simp [L,augmentedField,augmented,Finset.sum_add_distrib,Finset.mul_sum]) + +lemma augmentedField_mean (hn : 0 < n) (β : ℝ) (i : Fin n) : + (∫ g, augmentedField β g i ∂standardArrayLaw (Fin n × Fin n)) = β^2 := by + have hi (j : Fin n) : Integrable (fun g => augmented β g i j) + (standardArrayLaw (Fin n × Fin n)) := + (((goe_gaussian n).eval i |>.eval j).integrable.const_mul β).add (integrable_const _) + change (∫ g, ∑ j : Fin n, augmented β g i j ∂standardArrayLaw (Fin n × Fin n)) = _ + rw [integral_finsetSum _ (fun j _ => hi j)] + simp only [augmented_mean,Finset.sum_const,Finset.card_univ,Fintype.card_fin,nsmul_eq_mul] + exact mul_div_cancel₀ _ (Nat.cast_ne_zero.mpr hn.ne') + +lemma augmentedField_covariance (hn : 0 < n) (β : ℝ) (i k : Fin n) : + cov[fun g => augmentedField β g i,fun g => augmentedField β g k; + standardArrayLaw (Fin n × Fin n)] = (if i=k then β^2 else 0)+β^2/(n:ℝ) := by + have hLp (i j : Fin n) : MemLp (fun g => augmented β g i j) 2 + (standardArrayLaw (Fin n × Fin n)) := + ((goe_entry_memLp i j).const_mul β).add (memLp_const _) + unfold augmentedField + rw [covariance_fun_sum_fun_sum (hLp i) (hLp k)] + simp_rw [augmented_covariance hn,ite_and,mul_add,Finset.sum_add_distrib,mul_ite, + mul_one,mul_zero,Finset.sum_ite_irrel,Finset.sum_ite_eq,Finset.mem_univ,ite_true] + simp only [Finset.sum_const,Finset.card_univ,Fintype.card_fin,nsmul_eq_mul] + have hn0 : (n:ℝ) ≠ 0 := Nat.cast_ne_zero.mpr hn.ne' + split_ifs <;> simp [mul_div_cancel₀ _ hn0] + +theorem augmentedField_law (hn : 0 < n) (β : ℝ) : + (standardArrayLaw (Fin n × Fin n)).map (augmentedField β) = + (standardArrayLaw (Option (Fin n))).map + (sharedGaussianField (β^2) β (β/sqrt n)) := by + apply SKRatioGaussian.GaussianRegression.law_eq_of_mean_covariance + (augmentedField_gaussian β) (sharedGaussianField_gaussian n _ _ _) + · intro i + rw [augmentedField_mean hn,sharedGaussianField_mean] + · intro i k + rw [augmentedField_covariance hn,sharedGaussianField_covariance,div_pow, + sq_sqrt (Nat.cast_nonneg n)] + +def constantDirection (n : ℕ) : Fin n → ℝ := fun _ => (sqrt n)⁻¹ + +lemma constantDirection_unit (hn : 0 < n) : + ∑ i : Fin n, constantDirection n i^2 = 1 := by + have hn0 : (n:ℝ) ≠ 0 := Nat.cast_ne_zero.mpr hn.ne' + simp [constantDirection,inv_pow,sq_sqrt (Nat.cast_nonneg n),hn0] + +lemma constantColumn_unit (hn : 0 < n) : + (queryColumn (constantDirection n))ᵀ * queryColumn (constantDirection n) = 1 := + queryColumn_unit _ (constantDirection_unit hn) + +def fieldProjection (n : ℕ) : Matrix (Fin n) (Fin n) ℝ := + residualProjection (queryColumn (constantDirection n)) + +lemma augmentedField_query (hn : 0 < n) (β : ℝ) (g : (Fin n × Fin n) → ℝ) (i : Fin n) : + augmentedField β g i = sqrt n*β*(goe g*queryColumn (constantDirection n)) i 0+β^2 := by + have hn0 : (n:ℝ) ≠ 0 := Nat.cast_ne_zero.mpr hn.ne' + have hs0 : sqrt (n:ℝ) ≠ 0 := (sqrt_pos.mpr (Nat.cast_pos.mpr hn)).ne' + simp only [augmentedField,augmented,Finset.sum_add_distrib,←Finset.mul_sum, + Finset.sum_const,Finset.card_univ,Fintype.card_fin,nsmul_eq_mul, + Matrix.mul_apply,queryColumn,constantDirection,←Finset.sum_mul] + field_simp + +theorem field_residual_independent (hn : 0 < n) (β : ℝ) : + IndepFun (fun g : (Fin n × Fin n) → ℝ => fun p : Fin n × Fin n => + (fieldProjection n*(β • goe g)*fieldProjection n) p.1 p.2) + (augmentedField β) (standardArrayLaw (Fin n × Fin n)) := by + have h := residual_answer_independent hn (queryColumn (constantDirection n)) (constantColumn_unit hn) + have hc := h.comp + (φ := fun x : (Fin n × Fin n) → ℝ => fun p => β*x p) + (ψ := fun y : (Fin n × Fin 1) → ℝ => fun i => sqrt n*β*y (i,0)+β^2) + (by fun_prop) (by fun_prop) + convert! hc using 1 + · funext g p + simp [fieldProjection] + · funext g i + exact augmentedField_query hn β g i + +lemma projected_rows_formula (hn : 0 < n) (M : Matrix (Fin n) (Fin n) ℝ) + (hM : Mᵀ = M) (i j : Fin n) : + M i j = (fieldProjection n*M*fieldProjection n) i j + + ((∑ k, M i k)+(∑ k, M j k)-(∑ l, ∑ k, M l k)/(n:ℝ))/(n:ℝ) := by + have hs0 : sqrt (n:ℝ) ≠ 0 := (sqrt_pos.mpr (Nat.cast_pos.mpr hn)).ne' + have hn0 : (n:ℝ) ≠ 0 := Nat.cast_ne_zero.mpr hn.ne' + have hr := congrFun (congrFun + (regression_decomposition M (queryColumn (constantDirection n)) hM) i) j + simp only [Matrix.add_apply,Matrix.sub_apply,Matrix.mul_apply,Matrix.transpose_apply, + queryColumn,constantDirection,Fin.sum_univ_one,←Finset.sum_mul,←Finset.mul_sum] at hr + change M i j = _ + _ - _ + (fieldProjection n*M*fieldProjection n) i j at hr + have hs : (sqrt (n:ℝ))⁻¹ * (sqrt n)⁻¹ = (n:ℝ)⁻¹ := by + rw [←mul_inv_rev,←pow_two,sq_sqrt (Nat.cast_nonneg n)] + calc + M i j = _ := hr + _ = _ := by + calc + _ = (fieldProjection n*M*fieldProjection n) i j + + ((∑ k, M i k)+(∑ k, M j k)-(∑ l, ∑ k, M l k)* + ((sqrt (n:ℝ))⁻¹*(sqrt n)⁻¹))*((sqrt (n:ℝ))⁻¹*(sqrt n)⁻¹) := by ring + _ = _ := by rw [hs]; simp only [div_eq_mul_inv] + +theorem augmented_decomposition (hn : 0 < n) (β : ℝ) + (g : (Fin n × Fin n) → ℝ) (i j : Fin n) : + augmented β g i j = + (fieldProjection n*(β • goe g)*fieldProjection n) i j + + (augmentedField β g i + augmentedField β g j - + (∑ k, augmentedField β g k)/(n:ℝ))/(n:ℝ) := by + have hn0 : (n:ℝ) ≠ 0 := Nat.cast_ne_zero.mpr hn.ne' + have hM : (β • goe g)ᵀ = β • goe g := by + simp only [Matrix.transpose_smul,goe_symmetric] + have h := projected_rows_formula hn (β • goe g) hM i j + have hsum (i : Fin n) : augmentedField β g i = (∑ k, (β • goe g) i k) + β^2 := by + simp [augmentedField,augmented,Finset.sum_add_distrib,mul_div_cancel₀ _ hn0] + simp_rw [hsum] + rw [Finset.sum_add_distrib] + simp only [Finset.sum_const,Finset.card_univ,Fintype.card_fin,nsmul_eq_mul] + change β*goe g i j+β^2/(n:ℝ) = _ + rw [show β*goe g i j = (β • goe g) i j from rfl,h] + field_simp + ring + +end SKRatio.Planted + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Matrices/PlantedSquares.lean b/lean/OAI/Probability/SKRatio/Matrices/PlantedSquares.lean new file mode 100644 index 0000000000000000000000000000000000000000..f2c778518dcb379c00bdefadde01a3077f1f8330 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Matrices/PlantedSquares.lean @@ -0,0 +1,177 @@ +import Mathlib +import OAI.Probability.SKRatio.Gaussian.GaussianEvents +import OAI.Probability.SKRatio.Gaussian.Planted +import OAI.Probability.SKRatio.Matrices.GaussianSquareMatrix + +namespace OAI + +section +noncomputable section +open scoped BigOperators NNReal ENNReal Topology +open MeasureTheory ProbabilityTheory Filter Set Real +namespace SKRatio.Planted +open SKRatioClock.Regression MatrixNet +attribute [local instance] Classical.propDecidable + +def affineDisorder {n : ℕ} (β : ℝ) (z : Disorder n) : Disorder n := + fun e => (β / sqrt n)*z e+β^2/n + +lemma affineDisorder_hasLaw {n : ℕ} (hn : 0 (β/sqrt n)*x+β^2/n) + (fun _ => by fun_prop) + apply iIndepFun.hasLaw_pi (μ := fun _ => gaussianReal (β^2/n) (Real.toNNReal (β^2/n))) _ hi + intro e + have h := gaussianReal_add_const (gaussianReal_const_mul (coordinate_hasLaw e) (β/sqrt n)) (β^2/n) + have hv : (NNReal.mk ((β/sqrt n)^2) (sq_nonneg _) : ℝ≥0)*1 = Real.toNNReal (β^2/n) := by + apply NNReal.coe_injective + simp only [NNReal.coe_mk,mul_one, + Real.coe_toNNReal _ (div_nonneg (sq_nonneg _) (Nat.cast_nonneg n))] + rw [div_pow,sq_sqrt (Nat.cast_pos.mpr hn).le] + simpa only [mul_zero,zero_add,hv,Function.comp_def] using h + +lemma coupling_scaled_norm {n : ℕ} (c : ℝ) (g : Disorder n) : + ‖Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) (coupling (fun e => c*g e))‖ = + |c| *‖Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) (coupling g)‖ := by + rw [coupling_const_mul] + change ‖Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) (c • Matrix.of (coupling g))‖ = _ + rw [map_smul,norm_smul,Real.norm_eq_abs] + rfl + +lemma normalized_absolute_row_le {n : ℕ} (hn : 0 by + nlinarith [sq_nonneg (|z e|-1),sq_abs (z e)]) + _ = (∑ e ∈ incidentEdges i, z e^2)+((incidentEdges i).card:ℝ) := by simp [Finset.sum_add_distrib] + _ ≤ _ := add_le_add_right (by exact_mod_cast incidentEdges_card_le i) _ + have hd := div_le_div_of_nonneg_right hsum (Nat.cast_nonneg n : (0:ℝ)≤n) + simpa only [add_div,div_self (show (n:ℝ)≠0 from Nat.cast_ne_zero.mpr hn.ne')] using hd + +lemma normalized_matrix_norm_le_row_square {n : ℕ} (hn : 0 z e/n))‖ ≤ C+1 := by + have hr (i : Fin n) : ∑ j, |coupling (fun e => z e/n) i j| ≤ C+1 := by + simp_rw [abs_coupling] + rw [sum_coupling_row] + simp only [abs_div,abs_of_nonneg (Nat.cast_nonneg n : (0:ℝ)≤n),←Finset.sum_div] + exact (normalized_absolute_row_le hn z i).trans (add_le_add_left (hrow i) _) + exact matrix_opNorm_le_schur _ (C+1) (by linarith) hr + (fun j => by simpa only [coupling_symm] using hr j) + +lemma gaussian_rows_square_bounded : + ∃ C : ℝ, 0 standardArrayLaw (Edge n)) + (fun n => {z | ∃ i : Fin n, C < (∑ e ∈ incidentEdges i, z e^2)/(n:ℝ)}) := by + obtain ⟨R,c,hR,hc,_,ht⟩ := gaussian_squareTail_row_bound (a := 1) zero_lt_one + refine ⟨R^2+1,by positivity,?_⟩ + have hr : ExponentiallyRare (fun n => standardArrayLaw (Edge n)) + (fun n => ⋃ i : Fin n, {z | 1 ≤ (∑ e ∈ incidentEdges i, squareTail R (z e))/(n:ℝ)}) := by + apply exponentiallyRare_iUnion_polynomial _ _ hc (hC := zero_lt_one) (hD := zero_lt_one) 1 + · exact Eventually.of_forall (fun n => by simp) + · filter_upwards [eventually_gt_atTop 0] with n hn + intro i + simpa only [one_mul] using ht (incidentEdges i) hn (incidentEdges_card_le i) + apply hr.mono + filter_upwards [eventually_gt_atTop 0] with n hn + rintro z ⟨i,hi⟩ + apply mem_iUnion.mpr + refine ⟨i,?_⟩ + have hb : (∑ e ∈ incidentEdges i, z e^2)/(n:ℝ) ≤ R^2+ + (∑ e ∈ incidentEdges i, squareTail R (z e))/(n:ℝ) := by + have hs : ∑ e ∈ incidentEdges i, z e^2 ≤ + (n:ℝ)*R^2+∑ e ∈ incidentEdges i, squareTail R (z e) := by + calc + _ ≤ ∑ e ∈ incidentEdges i, (R^2+squareTail R (z e)) := + Finset.sum_le_sum (fun e _ => by + linarith [clippedSquare_le R (z e),square_sub_clip_le hR.le (z e)]) + _ = ((incidentEdges i).card:ℝ)*R^2+∑ e ∈ incidentEdges i, squareTail R (z e) := by simp [Finset.sum_add_distrib] + _ ≤ _ := add_le_add_left (mul_le_mul_of_nonneg_right + (by exact_mod_cast incidentEdges_card_le i) (sq_nonneg R)) _ + have hd := div_le_div_of_nonneg_right hs (Nat.cast_nonneg n : (0:ℝ)≤n) + simpa only [add_div,mul_div_cancel_left₀ _ (show (n:ℝ)≠0 from Nat.cast_ne_zero.mpr hn.ne')] using hd + change (1:ℝ) ≤ (∑ e ∈ incidentEdges i, squareTail R (z e))/(n:ℝ) + linarith only [hb,hi] + +lemma affine_square_decomposition {n : ℕ} (hn : 0 affineDisorder β z e^2-β^2/n) = + (fun e => β^2*((z e^2-1)/n)) + + (fun e => (2*β^3/sqrt n)*(z e/n)) + (fun _ => β^4/(n:ℝ)^2) := by + have hnR : (n:ℝ)≠0 := Nat.cast_ne_zero.mpr hn.ne' + have hs : sqrt (n:ℝ)≠0 := (sqrt_pos.mpr (Nat.cast_pos.mpr hn)).ne' + funext e + dsimp only [affineDisorder,Pi.add_apply] + rw [add_sq,mul_pow,div_pow,sq_sqrt (Nat.cast_nonneg n)] + field_simp + ring + +lemma affine_square_norm_le {n : ℕ} (hn : 0 affineDisorder β z e^2-β^2/n))‖ ≤ + β^2*‖Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) (coupling (fun e => (z e^2-1)/n))‖ + + |2*β^3/sqrt n| *(C+1)+β^4/n := by + rw [affine_square_decomposition hn] + apply (coupling_norm_add_three _ _ _).trans + rw [coupling_scaled_norm,coupling_scaled_norm,abs_of_nonneg (sq_nonneg β)] + apply add_le_add + · apply add_le_add_right + exact mul_le_mul_of_nonneg_left (normalized_matrix_norm_le_row_square hn z hC hrow) (abs_nonneg _) + · have hh := coupling_const_norm_le (n := n) (β^4/(n:ℝ)^2) + have hm : (n:ℝ)*|β^4/(n:ℝ)^2| = β^4/n := by + rw [abs_of_nonneg (by positivity)] + field_simp + simpa only [hm] using hh + +lemma affine_square_matrix_rare (β : ℝ) {u : ℝ} (hu : 0 standardArrayLaw (Edge n)) + (fun n => {z | u < ‖Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) + (coupling (fun e => affineDisorder β z e^2-β^2/n))‖}) := by + obtain ⟨C,hC,hrows⟩ := gaussian_rows_square_bounded + have hsq := centered_gaussian_square_matrix_rare (u := u/(2*(β^2+1))) (by positivity) + have hn := (tendsto_natCast_atTop_atTop : Tendsto (fun n : ℕ => (n:ℝ)) atTop atTop) + have hl : Tendsto (fun n : ℕ => |2*β^3/sqrt n| *(C+1)+β^4/n) atTop (𝓝 0) := by + have h1 := ((tendsto_const_nhds (x := 2*β^3)).div_atTop (tendsto_sqrt_atTop.comp hn)).abs.mul_const (C+1) + have h2 := (tendsto_const_nhds (x := β^4)).div_atTop hn + simpa only [abs_zero,zero_mul,zero_add,Function.comp_def] using h1.add h2 + apply (hsq.union hrows).mono + filter_upwards [eventually_gt_atTop 0,hl.eventually (gt_mem_nhds (by positivity : (0:ℝ) hnot (Or.inr ⟨i,hi⟩)) + have hsmall : ‖Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) + (coupling (fun e => (z e^2-1)/n))‖ ≤ u/(2*(β^2+1)) := + le_of_not_gt (fun hi => hnot (Or.inl hi)) + have ha := affine_square_norm_le hn β z hC.le hgood + have hh := mul_le_mul_of_nonneg_left hsmall (sq_nonneg β) + have ht : β^2*(u/(2*(β^2+1))) ≤ u/2 := by + rw [← mul_div_assoc] + exact (div_le_iff₀ (by positivity : (0:ℝ)<2*(β^2+1))).mpr (by nlinarith) + change u < _ at hz + linarith only [ha,hh,ht,hb,hz] + +theorem square_matrix_rare (β : ℝ) {u : ℝ} (hu : 0 {g | u < ‖Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) + (coupling (fun e => g e^2-β^2/n))‖}) := by + obtain ⟨C,c,hC,hc,hb⟩ := affine_square_matrix_rare β hu + refine ⟨C,c,hC,hc,?_⟩ + filter_upwards [hb,eventually_gt_atTop 0] with n hn hdim + have hm : MeasurableSet {g : Disorder n | u < + ‖Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) (coupling (fun e => g e^2-β^2/n))‖} := by + apply measurableSet_lt measurable_const + exact ((Gaussian.continuous_operator_norm (n := n)).comp (continuous_pi (fun e => + ((continuous_apply e).pow 2).sub continuous_const))).measurable + rw [←(affineDisorder_hasLaw hdim β).measure_eq hm] + exact hn + +end SKRatio.Planted + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Matrices/PowExponentialPair.lean b/lean/OAI/Probability/SKRatio/Matrices/PowExponentialPair.lean new file mode 100644 index 0000000000000000000000000000000000000000..0b04983a79821befeb739edde8073786bcbf89cb --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Matrices/PowExponentialPair.lean @@ -0,0 +1,109 @@ +import Mathlib +import OAI.Probability.SKRatio.Matrices.StdGaussianMgfLipschitz + +namespace OAI + +section +section +noncomputable section +open MeasureTheory ProbabilityTheory InformationTheory Real Set +open scoped NNReal ENNReal +open Filter +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius ENNReal NNReal +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius NNReal +noncomputable section +open MeasureTheory ProbabilityTheory Real Set Filter +open MeasureTheory.Measure +open scoped ENNReal NNReal MeasureTheory Topology +namespace SKRatioGaussian +open MeasureTheory ProbabilityTheory Real +open scoped Topology +section SubgaussianMoments +variable {Ω : Type*} [MeasurableSpace Ω] {μ : Measure Ω} {X : Ω → ℝ} {c : ℝ≥0} + +lemma pow_le_exponential_pair (x : ℝ) {r : ℝ} (hr : 0 < r) (k : ℕ) : + |x|^k ≤ ((k.factorial : ℝ)/r^k) * (exp (r*x)+exp (-r*x)) := by + have hk : 0 < (k.factorial : ℝ) := by exact_mod_cast k.factorial_pos + have hh := Real.pow_div_factorial_le_exp (r*|x|) (mul_nonneg hr.le (abs_nonneg x)) k + have he : exp (r*|x|) ≤ exp (r*x)+exp (-r*x) := by + rcases le_total 0 x with hx | hx + · rw [abs_of_nonneg hx]; exact le_add_of_nonneg_right (exp_nonneg _) + · rw [abs_of_nonpos hx]; have hid : r * -x = -r*x := by ring + rw [hid]; exact le_add_of_nonneg_left (exp_nonneg _) + have hg := hh.trans he + rw [div_le_iff₀ hk,mul_pow] at hg + rw [div_mul_eq_mul_div] + apply (le_div_iff₀ (pow_pos hr k)).mpr + convert hg using 1 <;> ring + +lemma subgaussian_abs_moment {r : ℝ} (hr : 0 < r) (hX : HasSubgaussianMGF X c μ) (k : ℕ) : + (∫ x, |X x|^k ∂μ) ≤ + 2*((k.factorial : ℝ)/r^k)*exp ((c : ℝ)*r^2/2) := by + let C := (k.factorial : ℝ)/r^k + have hC : 0 ≤ C := by dsimp [C]; positivity + have he : Integrable (fun x => C*(exp (r*X x)+exp (-r*X x))) μ := + ((hX.integrable_exp_mul r).add (hX.integrable_exp_mul (-r))).const_mul C + have hp (x : Ω) : |X x|^k ≤ C*(exp (r*X x)+exp (-r*X x)) := pow_le_exponential_pair (X x) hr k + have hi : Integrable (fun x => |X x|^k) μ := by + apply he.mono' (hX.integrable.aestronglyMeasurable.norm.pow k) + filter_upwards [] with x + simpa only [Pi.pow_apply,Real.norm_eq_abs,abs_pow,abs_abs] using hp x + calc + _ ≤ ∫ x, C*(exp (r*X x)+exp (-r*X x)) ∂μ := integral_mono hi he hp + _ = C*(mgf X μ r+mgf X μ (-r)) := by + rw [integral_const_mul,integral_add (hX.integrable_exp_mul r) (hX.integrable_exp_mul (-r))] + rfl + _ ≤ C*(exp ((c:ℝ)*r^2/2)+exp ((c:ℝ)*r^2/2)) := by + apply mul_le_mul_of_nonneg_left _ hC + simpa only [neg_sq] using add_le_add (hX.mgf_le r) (hX.mgf_le (-r)) + _ = _ := by dsimp only [C]; ring +end SubgaussianMoments + +section GaussianMoments +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] + [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] + +lemma stdGaussian_subgaussian_lipschitz {f : E → ℝ} {L : ℝ≥0} (hf : LipschitzWith L f) : + HasSubgaussianMGF (fun x => f x-∫ y, f y ∂stdGaussian E) + ⟨π^2*(L:ℝ)^2/4,by positivity⟩ (stdGaussian E) where + integrable_exp_mul r := by + apply gaussian_integrable_exp_lipschitz (L := L) _ r + apply LipschitzWith.of_dist_le_mul + intro x y + simpa only [Real.dist_eq,sub_sub_sub_cancel_right] using hf.dist_le_mul x y + mgf_le r := by + have hh := stdGaussian_mgf_lipschitz_le hf r + change (∫ x, exp (r*(f x-∫ y, f y ∂stdGaussian E)) ∂stdGaussian E) ≤ _ + apply hh.trans_eq + change exp (π^2*r^2*(L:ℝ)^2/8) = exp ((π^2*(L:ℝ)^2/4)*r^2/2) + congr 1 + ring + +lemma stdGaussian_abs_centered_moment {f : E → ℝ} {L : ℝ≥0} (hf : LipschitzWith L f) + (hL : 0 < L) (k : ℕ) : + (∫ x, |f x-∫ y, f y ∂stdGaussian E|^k ∂stdGaussian E) ≤ + (2*(k.factorial : ℝ)*exp (π^2/8))*(L:ℝ)^k := by + have hLr : 0 < (L:ℝ) := hL + have hh := subgaussian_abs_moment (inv_pos.mpr hLr) (stdGaussian_subgaussian_lipschitz hf) k + convert hh using 1 + have he : π^2*(L:ℝ)^2/4*((L:ℝ)⁻¹)^2/2 = π^2/8 := by field_simp [ne_of_gt hLr]; ring + change 2*(k.factorial : ℝ)*exp (π^2/8)*(L:ℝ)^k = + 2*((k.factorial:ℝ)/(L:ℝ)⁻¹^k)*exp ((π^2*(L:ℝ)^2/4)*(L:ℝ)⁻¹^2/2) + rw [he,inv_pow,div_inv_eq_mul] + ring +end GaussianMoments +end SKRatioGaussian + +end +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Matrices/Quadratic.lean b/lean/OAI/Probability/SKRatio/Matrices/Quadratic.lean new file mode 100644 index 0000000000000000000000000000000000000000..be154bab777a48ad111f10c3bced2e1d0df35096 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Matrices/Quadratic.lean @@ -0,0 +1,124 @@ +import Mathlib + +namespace OAI + +section +section +noncomputable section +open MeasureTheory ProbabilityTheory InformationTheory Real Set +open scoped NNReal ENNReal +open Filter +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius ENNReal NNReal +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius NNReal +noncomputable section +open MeasureTheory ProbabilityTheory Real Set Filter +open MeasureTheory.Measure +open scoped ENNReal NNReal MeasureTheory Topology +open MeasureTheory +noncomputable section +noncomputable section +open MeasureTheory Set NormedSpace +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius +noncomputable section +open Set Real +open scoped Topology +noncomputable section +open Matrix Set Filter +open scoped Topology Matrix.Norms.Frobenius +namespace SKRatioGaussian.ComplexSpectral +variable {ι : Type*} [Fintype ι] + +def quadratic (M : Matrix ι ι ℂ) (x : EuclideanSpace ℂ ι) : ℝ := + (dotProduct (star x.ofLp) (M *ᵥ x.ofLp)).re + +def unitSphere (ι : Type*) [Fintype ι] : Set (EuclideanSpace ℂ ι) := Metric.sphere 0 1 + +def lowerRayleigh (M : Matrix ι ι ℂ) : ℝ := sInf (quadratic M '' unitSphere ι) + +lemma continuous_quadratic : + Continuous (fun p : Matrix ι ι ℂ × EuclideanSpace ℂ ι => quadratic p.1 p.2) := by + unfold quadratic dotProduct mulVec + fun_prop + +lemma compact_unitSphere : IsCompact (unitSphere ι) := isCompact_sphere _ _ + +lemma continuous_lowerRayleigh : Continuous (lowerRayleigh (ι := ι)) := + compact_unitSphere.continuous_sInf continuous_quadratic + +lemma quadratic_neg (M : Matrix ι ι ℂ) (x : EuclideanSpace ℂ ι) : + quadratic (-M) x = -quadratic M x := by simp [quadratic,Matrix.neg_mulVec,dotProduct_neg] + +lemma lowerRayleigh_le (M : Matrix ι ι ℂ) {x : EuclideanSpace ℂ ι} + (hx : x ∈ unitSphere ι) : lowerRayleigh M ≤ quadratic M x := by + have hb : BddBelow (quadratic M '' unitSphere ι) := + (compact_unitSphere.image (continuous_quadratic.comp (continuous_const.prodMk continuous_id))).bddBelow + exact csInf_le hb ⟨x,hx,rfl⟩ + +lemma lowerRayleigh_ge [Nonempty ι] {M : Matrix ι ι ℂ} {c : ℝ} + (hc : ∀ x ∈ unitSphere ι, c ≤ quadratic M x) : c ≤ lowerRayleigh M := by + classical + obtain ⟨i⟩ := ‹Nonempty ι› + have hn : (quadratic M '' unitSphere ι).Nonempty := by + refine ⟨quadratic M (EuclideanSpace.single i (1:ℂ)),?_⟩ + exact ⟨_,by simp [unitSphere],rfl⟩ + exact le_csInf hn (by rintro _ ⟨x,hx,rfl⟩; exact hc x hx) + +variable [DecidableEq ι] + +lemma quadratic_eigenvector {M : Matrix ι ι ℂ} (hM : M.IsHermitian) (i : ι) : + quadratic M (hM.eigenvectorBasis i) = hM.eigenvalues i := by + exact (hM.eigenvalues_eq i).symm + +lemma eigenvalue_lower_bound {M : Matrix ι ι ℂ} (hM : M.IsHermitian) (i : ι) : + lowerRayleigh M ≤ hM.eigenvalues i := by + rw [← quadratic_eigenvector hM i] + apply lowerRayleigh_le + simpa only [unitSphere,Metric.mem_sphere,dist_zero_right] using hM.eigenvectorBasis.orthonormal.1 i + +lemma eigenvalue_upper_bound {M : Matrix ι ι ℂ} (hM : M.IsHermitian) (i : ι) : + hM.eigenvalues i ≤ -lowerRayleigh (-M) := by + have hh := lowerRayleigh_le (-M) (x := hM.eigenvectorBasis i) + (by simpa only [unitSphere,Metric.mem_sphere,dist_zero_right] using hM.eigenvectorBasis.orthonormal.1 i) + rw [quadratic_neg,quadratic_eigenvector] at hh + linarith + +lemma spectral_interval_eventually {S : ℝ → Matrix ι ι ℂ} {t lo hi : ℝ} + (hS : ContinuousAt S t) (hself : ∀ s, (S s).IsHermitian) + (hlo : lo < lowerRayleigh (S t)) (hhi : lowerRayleigh (-(S t)) > -hi) : + ∀ᶠ s in 𝓝 t, ∀ i, (hself s).eigenvalues i ∈ Icc lo hi := by + have hl := (continuous_lowerRayleigh.continuousAt.comp hS).eventually (lt_mem_nhds hlo) + have hu := (continuous_lowerRayleigh.continuousAt.comp hS.neg).eventually (lt_mem_nhds hhi) + filter_upwards [hl,hu] with s hs hs' i + refine ⟨hs.le.trans (eigenvalue_lower_bound (hself s) i),?_⟩ + have hh := eigenvalue_upper_bound (hself s) i + change -hi < lowerRayleigh (-(S s)) at hs' + linarith + +end SKRatioGaussian.ComplexSpectral + +noncomputable section +open Matrix NormedSpace ContinuousLinearMap +open scoped Matrix.Norms.Frobenius + +end +end +end +end +end +end +end +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Matrices/QuadraticCoeff.lean b/lean/OAI/Probability/SKRatio/Matrices/QuadraticCoeff.lean new file mode 100644 index 0000000000000000000000000000000000000000..905efaba0b6a97bb132fc7de7afd1452003e8f4b --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Matrices/QuadraticCoeff.lean @@ -0,0 +1,172 @@ +import Mathlib +import OAI.Probability.SKRatio.Matrices.MatrixCoordinates + +namespace OAI + +section +section +noncomputable section +open MeasureTheory ProbabilityTheory InformationTheory Real Set +open scoped NNReal ENNReal +open Filter +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius ENNReal NNReal +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius NNReal +noncomputable section +open MeasureTheory ProbabilityTheory Real Set Filter +open MeasureTheory.Measure +open scoped ENNReal NNReal MeasureTheory Topology +open MeasureTheory +noncomputable section +noncomputable section +open MeasureTheory Set NormedSpace +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius +noncomputable section +open Set Real +open scoped Topology +noncomputable section +open Matrix Set Filter +open scoped Topology Matrix.Norms.Frobenius +noncomputable section +open Matrix NormedSpace ContinuousLinearMap +open scoped Matrix.Norms.Frobenius +noncomputable section +open Matrix +noncomputable section +open MeasureTheory ProbabilityTheory Real Set +open scoped ENNReal NNReal +noncomputable section +open MeasureTheory ProbabilityTheory InformationTheory Real Set +open scoped NNReal ENNReal +noncomputable section +open scoped BigOperators +open MeasureTheory ProbabilityTheory +namespace SKRatioGaussian +section GaussianQuadratic +variable {ι : Type*} [Fintype ι] + +def quadraticCoeff (r : ℝ) (w : EuclideanSpace ℝ ι) : MatrixCoordinates ι → ℝ + | Sum.inl (i, k) => Real.sqrt (2 * r) * w i * w k + | Sum.inr _ => 0 + +def linearCoeff (r : ℝ) (w : EuclideanSpace ℝ ι) : MatrixCoordinates ι → ℝ + | Sum.inl _ => 0 + | Sum.inr i => 2 * Real.sqrt r * ‖w‖ * w i + +lemma sum_coord_sq (w : EuclideanSpace ℝ ι) : ∑ i, (w i)^2 = ‖w‖^2 := by + simp only [EuclideanSpace.norm_sq_eq, Real.norm_eq_abs, sq_abs] + +lemma sum_outer_sq (w v : ι → ℝ) : + (∑ i, ∑ k, (w i * w k - v i * v k)^2) = + (∑ i, w i ^ 2)^2 + (∑ i, v i ^ 2)^2 - 2 * (∑ i, w i * v i)^2 := by + simp_rw [show ∀ i k, (w i * w k - v i * v k)^2 = + w i ^ 2 * w k ^ 2 + v i ^ 2 * v k ^ 2 - 2 * (w i * v i) * (w k * v k) by + intros; ring] + simp only [Finset.sum_add_distrib, Finset.sum_sub_distrib, ← Finset.mul_sum, + ← Finset.sum_mul] + ring + +lemma quadraticCoeff_increment (r : ℝ) (hr : 0 ≤ r) (w v : EuclideanSpace ℝ ι) : + (∑ k, (quadraticCoeff r w k - quadraticCoeff r v k)^2) = + 2 * r * (‖w‖^4 + ‖v‖^4 - 2 * (∑ i, w i * v i)^2) := by + rw [Fintype.sum_sum_type] + simp only [quadraticCoeff, sub_self, zero_pow (by norm_num : (2 : ℕ) ≠ 0), + Finset.sum_const_zero, add_zero, Fintype.sum_prod_type] + simp_rw [show ∀ i k, (Real.sqrt (2*r) * w i * w k - + Real.sqrt (2*r) * v i * v k)^2 = 2*r*(w i*w k-v i*v k)^2 by + intro i k + calc + _ = (Real.sqrt (2*r))^2 * (w i*w k-v i*v k)^2 := by ring + _ = _ := by rw [Real.sq_sqrt (by positivity)]] + simp_rw [← Finset.mul_sum] + rw [sum_outer_sq, sum_coord_sq, sum_coord_sq] + ring + +lemma linearCoeff_increment (r : ℝ) (hr : 0 ≤ r) (w v : EuclideanSpace ℝ ι) : + (∑ k, (linearCoeff r w k - linearCoeff r v k)^2) = + 4 * r * (‖w‖^4 + ‖v‖^4 - 2 * ‖w‖ * ‖v‖ * (∑ i, w i * v i)) := by + rw [Fintype.sum_sum_type] + simp only [linearCoeff, sub_self, zero_pow (by norm_num : (2 : ℕ) ≠ 0), + Finset.sum_const_zero, zero_add] + simp_rw [show ∀ i, (2 * Real.sqrt r * ‖w‖ * w i - + 2 * Real.sqrt r * ‖v‖ * v i)^2 = + 4*r*(‖w‖^2*(w i)^2 + ‖v‖^2*(v i)^2 - 2*‖w‖*‖v‖*(w i*v i)) by + intro i + calc + _ = 4*(Real.sqrt r)^2*(‖w‖^2*(w i)^2 + ‖v‖^2*(v i)^2 - + 2*‖w‖*‖v‖*(w i*v i)) := by ring + _ = _ := by rw [Real.sq_sqrt hr]] + simp only [← Finset.mul_sum, Finset.sum_add_distrib, Finset.sum_sub_distrib] + simp only [sum_coord_sq] + ring + +theorem quadratic_linear_increment_difference (r : ℝ) (hr : 0 ≤ r) + (w v : EuclideanSpace ℝ ι) : + (∑ k, (linearCoeff r w k - linearCoeff r v k)^2) - + (∑ k, (quadraticCoeff r w k - quadraticCoeff r v k)^2) = + 2*r*((‖w‖^2 - ‖v‖^2)^2 + + 2*(‖w‖*‖v‖ - ∑ i, w i*v i)^2) := by + rw [linearCoeff_increment r hr, quadraticCoeff_increment r hr] + ring + +theorem quadratic_linear_increment_le (r : ℝ) (hr : 0 ≤ r) + (w v : EuclideanSpace ℝ ι) : + (∑ k, (quadraticCoeff r w k - quadraticCoeff r v k)^2) ≤ + ∑ k, (linearCoeff r w k - linearCoeff r v k)^2 := by + have h := quadratic_linear_increment_difference r hr w v + have : 0 ≤ 2*r*((‖w‖^2 - ‖v‖^2)^2 + + 2*(‖w‖*‖v‖ - ∑ i, w i*v i)^2) := by positivity + linarith + +lemma quadratic_linear_orthogonal (r : ℝ) (w v : EuclideanSpace ℝ ι) : + ∑ k, (linearCoeff r w k - linearCoeff r v k) * + (quadraticCoeff r w k - quadraticCoeff r v k) = 0 := by + rw [Fintype.sum_sum_type] + simp only [linearCoeff, quadraticCoeff, sub_self, zero_mul, mul_zero, + Finset.sum_const_zero, add_zero] + +omit [Fintype ι] in +lemma continuous_quadraticCoeff (r : ℝ) : Continuous (quadraticCoeff (ι := ι) r) := by + apply continuous_pi + intro k + cases k with + | inl ik => + exact ((continuous_const.mul (PiLp.continuous_apply 2 (fun _ : ι => ℝ) ik.1)).mul + (PiLp.continuous_apply 2 (fun _ : ι => ℝ) ik.2)) + | inr i => exact continuous_const + +lemma continuous_linearCoeff (r : ℝ) : Continuous (linearCoeff (ι := ι) r) := by + apply continuous_pi + intro k + cases k with + | inl ik => exact continuous_const + | inr i => exact (continuous_const.mul continuous_norm).mul (PiLp.continuous_apply 2 (fun _ : ι => ℝ) i) + +end GaussianQuadratic +end SKRatioGaussian + +end +end +end +end +end +end +end +end +end +end +end +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Matrices/RandomMatrixBounded.lean b/lean/OAI/Probability/SKRatio/Matrices/RandomMatrixBounded.lean new file mode 100644 index 0000000000000000000000000000000000000000..d83d0dcd9f6407ca6657d62bf86f7687030f9989 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Matrices/RandomMatrixBounded.lean @@ -0,0 +1,185 @@ +import Mathlib +import OAI.Probability.SKRatio.Gaussian.GaussianEmpirical +import OAI.Probability.SKRatio.Matrices.RandomMatrixNet + +namespace OAI + +section +noncomputable section +open scoped BigOperators NNReal ENNReal Topology +open MeasureTheory ProbabilityTheory Filter Set +namespace SKRatio.MatrixNet +open SKRatioClock.Regression +attribute [local instance] Classical.propDecidable + +def bilinearCoefficient {n : ℕ} (x y : Fin n → ℝ) (p : Fin n × Fin n) : ℝ := + if p.1 < p.2 then x p.1 * y p.2 + x p.2 * y p.1 else 0 + +lemma bilinearCoefficient_sq_le {n : ℕ} (x y : Fin n → ℝ) : + ∑ p, bilinearCoefficient x y p ^ 2 ≤ + 2 * (∑ i, x i^2) * (∑ i, y i^2) := by + have hp (i j : Fin n) : bilinearCoefficient x y (i,j)^2 + + bilinearCoefficient x y (j,i)^2 ≤ 2 * (x i^2*y j^2 + x j^2*y i^2) := by + rcases lt_trichotomy i j with h | h | h + · simp only [bilinearCoefficient, h, not_lt_of_ge h.le, ite_true, ite_false, zero_pow (by decide : (2:ℕ) ≠ 0), add_zero] + nlinarith [sq_nonneg (x i*y j-x j*y i)] + · subst j; simp only [bilinearCoefficient, lt_self_iff_false, ite_false, zero_pow (by decide : (2:ℕ) ≠ 0), add_zero] + positivity + · simp only [bilinearCoefficient, h, not_lt_of_ge h.le, ite_true, ite_false, zero_pow (by decide : (2:ℕ) ≠ 0), zero_add] + nlinarith [sq_nonneg (x i*y j-x j*y i)] + have hs := Finset.sum_le_sum (s := Finset.univ) (fun i _ => + Finset.sum_le_sum (s := Finset.univ) (fun j _ => hp i j)) + simp only [mul_add, Finset.sum_add_distrib] at hs + rw [Finset.sum_comm (f := fun i j => bilinearCoefficient x y (j,i)^2)] at hs + rw [Fintype.sum_prod_type] + have he : ∑ i, ∑ j, 2*(x i^2*y j^2) = 2 * (∑ i, x i^2) * (∑ j, y j^2) := by + calc + _ = 2 * (∑ i, ∑ j, x i^2*y j^2) := by simp only [Finset.mul_sum] + _ = 2 * ((∑ i, x i^2) * (∑ j, y j^2)) := by rw [Finset.sum_mul_sum] + _ = _ := by ring + have he' : ∑ i, ∑ j, 2*(x j^2*y i^2) = 2 * (∑ i, x i^2) * (∑ j, y j^2) := by + rw [Finset.sum_comm]; exact he + rw [he, he'] at hs + linarith + +lemma coupling_bilinear {n : ℕ} (x y : Fin n → ℝ) (g : Disorder n) : + ∑ i, ∑ j, x i*coupling g i j*y j = + ∑ e : Edge n, (x e.1.1*y e.1.2+x e.1.2*y e.1.1)*g e := by + let F : Fin n × Fin n → ℝ := fun p => + if h : p.1 < p.2 then x p.1*y p.2*g ⟨p,h⟩ else 0 + let G : Fin n × Fin n → ℝ := fun p => + if h : p.1 < p.2 then x p.2*y p.1*g ⟨p,h⟩ else 0 + have hid (i j : Fin n) : x i*coupling g i j*y j = F (i,j)+G (j,i) := by + dsimp [F,G,coupling] + split_ifs with h₁ h₂ h₂ <;> try omega + all_goals ring + simp_rw [hid] + simp only [Finset.sum_add_distrib] + rw [Finset.sum_comm (f := fun i j => G (j,i)), ← Finset.sum_add_distrib] + simp_rw [←Finset.sum_add_distrib] + rw [←Fintype.sum_prod_type (f := fun p => F p+G p)] + apply Finset.sum_congr_set (s := {p : Fin n × Fin n | p.1 ∑ i, a i*X i ω) (∑ i, (NNReal.mk (a i^2) (sq_nonneg (a i)))*c) μ := by + have hi := hXi.comp (fun i z => a i*z) (fun i => measurable_const.mul measurable_id) + have hh := HasSubgaussianMGF.sum_of_iIndepFun hi (s := Finset.univ) (fun i _ => (hX i).const_mul (a i)) + exact hh + +lemma bounded_matrix_inner_tail {Ω : Type*} [MeasurableSpace Ω] {μ : Measure Ω} + [IsProbabilityMeasure μ] {n : ℕ} (hn : 0 X e ω/n)) x) y|} ≤ + 2*ENNReal.ofReal (Real.exp (-u^2*(n:ℝ)^2/(4*(T:ℝ)^2))) := by + let a : Edge n → ℝ := fun e => (y e.1.1*x e.1.2+y e.1.2*x e.1.1)/(n:ℝ) + have hnR : (0:ℝ) X e ω/n)) x) y = + ∑ e : Edge n, a e*X e ω := by + rw [coupling_inner] + apply Finset.sum_congr rfl + intro e _ + dsimp only [a] + ring + simp_rw [hid] + convert hh using 2 + congr 2 + rw [Real.coe_toNNReal _ (by positivity : (0:ℝ) ≤ 2*(T:ℝ)^2/(n:ℝ)^2)] + have htR : (T:ℝ) ≠ 0 := ne_of_gt hT + field_simp + ring + +lemma bounded_matrix_opNorm_tail {Ω : Type*} [MeasurableSpace Ω] {μ : Measure Ω} + [IsProbabilityMeasure μ] {n : ℕ} (hn : 0 X e ω/n))‖} ≤ + ENNReal.ofReal (2*(81:ℝ)^n*Real.exp (-u^2*(n:ℝ)^2/(4*(T:ℝ)^2))) := by + have h := opNorm_tail_of_bilinear μ _ hu _ + (fun x y hx hy => bounded_matrix_inner_tail hn X hXi hT hX x y hx hy hu) + convert h using 1 + rw [ENNReal.ofReal_mul (by positivity),ENNReal.ofReal_mul (by norm_num : (0:ℝ)≤2)] + simp only [ENNReal.ofReal_ofNat,ENNReal.ofReal_pow (by norm_num : (0:ℝ)≤81)] + ring + +end SKRatio.MatrixNet + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Matrices/RandomMatrixNet.lean b/lean/OAI/Probability/SKRatio/Matrices/RandomMatrixNet.lean new file mode 100644 index 0000000000000000000000000000000000000000..9f7613de15f20b6e26a98f34b2cfcfc65645b937 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Matrices/RandomMatrixNet.lean @@ -0,0 +1,205 @@ +import Mathlib + +namespace OAI + +section +noncomputable section +open scoped BigOperators NNReal ENNReal +open MeasureTheory Metric Set +namespace SKRatio.MatrixNet + +lemma separated_card_le {n : ℕ} (s : Finset (EuclideanSpace ℝ (Fin n))) + (hb : ∀ x ∈ s, ‖x‖ ≤ 1) + (hs : ∀ x ∈ s, ∀ y ∈ s, x ≠ y → (1/4:ℝ) < dist x y) : + (s.card : ℝ) ≤ (9:ℝ)^n := by + have hd : Set.PairwiseDisjoint (↑s) (fun x : EuclideanSpace ℝ (Fin n) => ball x (1/8)) := by + intro x hx y hy hxy + exact ball_disjoint_ball (by linarith [hs x hx y hy hxy]) + have hsub : (⋃ x ∈ s, ball x (1/8)) ⊆ ball (0 : EuclideanSpace ℝ (Fin n)) (9/8) := by + intro y hy + obtain ⟨x, hx, hy⟩ := Set.mem_iUnion₂.mp hy + have h := dist_triangle y x (0 : EuclideanSpace ℝ (Fin n)) + simp only [mem_ball, dist_zero_right] at hy h ⊢ + linarith [hb x hx] + have hm := measureReal_mono (μ := volume) hsub measure_ball_ne_top + rw [measureReal_biUnion_finset hd (fun _ _ => measurableSet_ball)] at hm + have hvol (x : EuclideanSpace ℝ (Fin n)) (r : ℝ) (hr : 0 < r) : + volume.real (ball x r) = r ^ n * volume.real (ball (0 : EuclideanSpace ℝ (Fin n)) 1) := by + simp only [measureReal_def, Measure.addHaar_ball_of_pos volume x hr, + ENNReal.toReal_mul, ENNReal.toReal_ofReal (pow_nonneg hr.le _), finrank_euclideanSpace, + Fintype.card_fin] + simp only [hvol _ _ (by norm_num : (0:ℝ) < 1/8), + hvol _ _ (by norm_num : (0:ℝ) < 9/8), Finset.sum_const, nsmul_eq_mul] at hm + have hp : 0 < volume.real (ball (0 : EuclideanSpace ℝ (Fin n)) 1) := by + exact ENNReal.toReal_pos (measure_ball_pos volume _ zero_lt_one).ne' measure_ball_ne_top + have hh : (s.card : ℝ) * (1/8:ℝ)^n ≤ (9/8:ℝ)^n := + (mul_le_mul_iff_left₀ hp).mp (by simpa only [mul_assoc] using hm) + have he : (9/8:ℝ)^n = (9:ℝ)^n * (1/8:ℝ)^n := by rw [← mul_pow]; congr 1; norm_num + rw [he] at hh + exact (mul_le_mul_iff_left₀ (show 0 < (1/8:ℝ)^n by positivity)).mp + (by simpa only [mul_comm] using hh) + +lemma unit_ball_net (n : ℕ) : + ∃ s : Finset (EuclideanSpace ℝ (Fin n)), + (∀ x ∈ s, ‖x‖ ≤ 1) ∧ + (∀ x : EuclideanSpace ℝ (Fin n), ‖x‖ ≤ 1 → ∃ y ∈ s, dist x y ≤ 1/4) ∧ + (s.card : ℝ) ≤ (9:ℝ)^n := by + classical + let A := closedBall (0 : EuclideanSpace ℝ (Fin n)) 1 + obtain ⟨C, _, hCf, hC⟩ := exists_finite_isCover_of_isCompact + (by norm_num : (1/8 : ℝ≥0) ≠ 0) (isCompact_closedBall (0 : EuclideanSpace ℝ (Fin n)) 1) + have hpack : packingNumber (1/4 : ℝ≥0) A ≠ ⊤ := by + have hle := (packingNumber_two_mul_le_externalCoveringNumber (1/8 : ℝ≥0) A).trans + hC.externalCoveringNumber_le_encard + norm_num only [show (2:ℝ≥0)*(1/8) = 1/4 by norm_num] at hle + exact ne_top_of_le_ne_top (Set.encard_ne_top_iff.mpr hCf) hle + + let D := maximalSeparatedSet (1/4 : ℝ≥0) A + have hDf : D.Finite := Set.encard_ne_top_iff.mp (by + rw [show D = maximalSeparatedSet (1/4 : ℝ≥0) A from rfl, encard_maximalSeparatedSet hpack] + exact hpack) + refine ⟨hDf.toFinset, ?_, ?_, ?_⟩ + · intro x hx + have h := maximalSeparatedSet_subset (ε := (1/4 : ℝ≥0)) (A := A) (hDf.mem_toFinset.mp hx) + simpa only [A, mem_closedBall, dist_zero_right] using h + · intro x hx + have hxA : x ∈ A := by simpa only [A, mem_closedBall, dist_zero_right] using hx + obtain ⟨y, hy, hdist⟩ := isCover_maximalSeparatedSet hpack hxA + refine ⟨y, hDf.mem_toFinset.mpr hy, ?_⟩ + change edist x y ≤ ((1/4 : ℝ≥0) : ℝ≥0∞) at hdist + have h := ENNReal.toReal_mono (by norm_num : ((1/4 : ℝ≥0) : ℝ≥0∞) ≠ ⊤) hdist + simpa only [edist_dist, ENNReal.toReal_ofReal (dist_nonneg : 0 ≤ dist x y), + ENNReal.coe_toReal, NNReal.coe_div, NNReal.coe_one, NNReal.coe_ofNat] using h + · apply separated_card_le + · intro x hx + have h := maximalSeparatedSet_subset (ε := (1/4 : ℝ≥0)) (A := A) (hDf.mem_toFinset.mp hx) + simpa only [A, mem_closedBall, dist_zero_right] using h + · intro x hx y hy hxy + have h := isSeparated_maximalSeparatedSet (ε := (1/4 : ℝ≥0)) (A := A) + (hDf.mem_toFinset.mp hx) (hDf.mem_toFinset.mp hy) hxy + simpa only [edist_dist, ENNReal.coe_lt_ofReal, NNReal.coe_div, NNReal.coe_one, + NNReal.coe_ofNat] using h + +lemma opNorm_le_of_net {n : ℕ} (A : EuclideanSpace ℝ (Fin n) →L[ℝ] EuclideanSpace ℝ (Fin n)) + (s : Finset (EuclideanSpace ℝ (Fin n))) + (hb : ∀ x ∈ s, ‖x‖ ≤ 1) + (hcover : ∀ x : EuclideanSpace ℝ (Fin n), ‖x‖ ≤ 1 → ∃ y ∈ s, dist x y ≤ 1/4) + (M : ℝ) (hM : 0 ≤ M) + (hnet : ∀ x ∈ s, ∀ y ∈ s, |inner (𝕜 := ℝ) (A x) y| ≤ M) : ‖A‖ ≤ 2*M := by + have hh : ‖A‖ ≤ M + ‖A‖/2 := by + apply ContinuousLinearMap.opNorm_le_of_re_inner_le (by positivity) + intro x y hx hy + obtain ⟨a, ha, hxa⟩ := hcover x hx.le + obtain ⟨b, hb', hyb⟩ := hcover y hy.le + have hxan : ‖x-a‖ ≤ 1/4 := by simpa only [dist_eq_norm] using hxa + have hybn : ‖y-b‖ ≤ 1/4 := by simpa only [dist_eq_norm] using hyb + have h₁ : |inner (𝕜 := ℝ) (A (x-a)) y| ≤ ‖A‖/4 := by + calc + _ ≤ ‖A (x-a)‖ * ‖y‖ := abs_real_inner_le_norm _ _ + _ ≤ (‖A‖ * ‖x-a‖) * ‖y‖ := mul_le_mul_of_nonneg_right (A.le_opNorm _) (norm_nonneg _) + _ ≤ ‖A‖/4 := by rw [hy, mul_one]; nlinarith [norm_nonneg A] + have h₂ : |inner (𝕜 := ℝ) (A a) (y-b)| ≤ ‖A‖/4 := by + calc + _ ≤ ‖A a‖ * ‖y-b‖ := abs_real_inner_le_norm _ _ + _ ≤ (‖A‖ * ‖a‖) * ‖y-b‖ := mul_le_mul_of_nonneg_right (A.le_opNorm _) (norm_nonneg _) + _ ≤ ‖A‖ * (1:ℝ) * (1/4) := mul_le_mul + (mul_le_mul_of_nonneg_left (hb a ha) (norm_nonneg A)) hybn (norm_nonneg _) (by positivity) + _ = ‖A‖/4 := by ring + have he : inner (𝕜 := ℝ) (A x) y = inner (𝕜 := ℝ) (A (x-a)) y + + inner (𝕜 := ℝ) (A a) (y-b) + inner (𝕜 := ℝ) (A a) b := by + simp only [map_sub, inner_sub_left, inner_sub_right]; ring + change inner (𝕜 := ℝ) (A x) y ≤ M + ‖A‖/2 + rw [he] + have hh := hnet a ha b hb' + linarith [le_abs_self (inner (𝕜 := ℝ) (A (x-a)) y), + le_abs_self (inner (𝕜 := ℝ) (A a) (y-b)), le_abs_self (inner (𝕜 := ℝ) (A a) b)] + linarith + +lemma opNorm_tail_of_bilinear {Ω : Type*} [MeasurableSpace Ω] (μ : Measure Ω) + {n : ℕ} (A : Ω → EuclideanSpace ℝ (Fin n) →L[ℝ] EuclideanSpace ℝ (Fin n)) + {u : ℝ} (hu : 0 ≤ u) (P : ℝ≥0∞) + (h : ∀ x y : EuclideanSpace ℝ (Fin n), ‖x‖ ≤ 1 → ‖y‖ ≤ 1 → + μ {ω | u ≤ |inner (𝕜 := ℝ) (A ω x) y|} ≤ P) : + μ {ω | 2*u < ‖A ω‖} ≤ (81:ℝ≥0∞)^n*P := by + classical + obtain ⟨s,hb,hc,hs⟩ := unit_ball_net n + let E (x y : EuclideanSpace ℝ (Fin n)) : Set Ω := + {ω | u ≤ |inner (𝕜 := ℝ) (A ω x) y|} + have hsub : {ω | 2*u < ‖A ω‖} ⊆ ⋃ x ∈ s, ⋃ y ∈ s, E x y := by + intro ω hω + by_contra hn + have hnet : ∀ x ∈ s, ∀ y ∈ s, |inner (𝕜 := ℝ) (A ω x) y| ≤ u := by + intro x hx y hy + have he : ω ∉ E x y := fun hh => hn + (mem_iUnion₂.mpr ⟨x,hx,mem_iUnion₂.mpr ⟨y,hy,hh⟩⟩) + exact (not_le.mp he).le + exact not_lt_of_ge (opNorm_le_of_net (A ω) s hb hc u hu hnet) hω + have hs2 : (s.card:ℝ)^2 ≤ (81:ℝ)^n := by + calc + _ ≤ ((9:ℝ)^n)^2 := pow_le_pow_left₀ (by positivity) hs 2 + _ = _ := by rw [←pow_mul,mul_comm n 2,pow_mul]; norm_num + have hsE : (s.card : ℝ≥0∞)^2 ≤ (81:ℝ≥0∞)^n := by + simpa only [ENNReal.ofReal_pow (Nat.cast_nonneg s.card), + ENNReal.ofReal_pow (by norm_num : (0:ℝ) ≤ 81), + ENNReal.ofReal_natCast, ENNReal.ofReal_ofNat] using ENNReal.ofReal_le_ofReal hs2 + calc + _ ≤ μ (⋃ x ∈ s, ⋃ y ∈ s, E x y) := measure_mono hsub + _ ≤ ∑ x ∈ s, ∑ y ∈ s, μ (E x y) := + (measure_biUnion_finset_le s _).trans + (Finset.sum_le_sum (fun x _ => measure_biUnion_finset_le s (E x))) + _ ≤ ∑ _x ∈ s, ∑ _y ∈ s, P := Finset.sum_le_sum + (fun x hx => Finset.sum_le_sum (fun y hy => h x y (hb x hx) (hb y hy))) + _ = (s.card:ℝ≥0∞)^2*P := by simp only [Finset.sum_const,nsmul_eq_mul]; ring + _ ≤ _ := mul_le_mul' hsE le_rfl + +lemma matrix_opNorm_le_schur {n : ℕ} (A : Matrix (Fin n) (Fin n) ℝ) (R : ℝ) (hR : 0 ≤ R) + (hr : ∀ i, ∑ j, |A i j| ≤ R) (hc : ∀ j, ∑ i, |A i j| ≤ R) : + ‖Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) A‖ ≤ R := by + apply ContinuousLinearMap.opNorm_le_of_re_inner_le hR + intro x y hx hy + change inner (𝕜 := ℝ) (Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) A x) y ≤ R + rw [real_inner_comm, Matrix.inner_toEuclideanCLM] + change (∑ i, y i * ∑ j, A i j*x j) ≤ R + simp only [Finset.mul_sum] + calc + _ ≤ ∑ i, ∑ j, |A i j| * ((y i)^2 + (x j)^2)/2 := by + apply Finset.sum_le_sum + intro i _ + apply Finset.sum_le_sum + intro j _ + have hab : 2*|y i| *|x j| ≤ (y i)^2+(x j)^2 := by + nlinarith [sq_nonneg (|y i|-|x j|), sq_abs (y i), sq_abs (x j)] + have hp := mul_le_mul_of_nonneg_left hab (abs_nonneg (A i j)) + have hh : y i*(A i j*x j) ≤ |y i| *|A i j| *|x j| := by + simpa only [abs_mul, mul_assoc] using le_abs_self (y i*(A i j*x j)) + nlinarith + _ = ((∑ i, (y i)^2 * ∑ j, |A i j|) + ∑ j, (x j)^2 * ∑ i, |A i j|)/2 := by + simp only [mul_add, add_div, Finset.sum_add_distrib, ← Finset.sum_div] + rw [Finset.sum_comm (f := fun i j => |A i j| * (x j)^2)] + simp only [← Finset.sum_mul] + congr 2 <;> apply Finset.sum_congr rfl <;> intro i _ <;> ring + _ ≤ ((∑ i, (y i)^2 * R) + ∑ j, (x j)^2*R)/2 := by + apply div_le_div_of_nonneg_right _ (by norm_num) + exact add_le_add + (Finset.sum_le_sum (fun i _ => mul_le_mul_of_nonneg_left (hr i) (sq_nonneg _))) + (Finset.sum_le_sum (fun i _ => mul_le_mul_of_nonneg_left (hc i) (sq_nonneg _))) + _ = R := by + rw [← Finset.sum_mul, ← Finset.sum_mul, ← EuclideanSpace.real_norm_sq_eq, + ← EuclideanSpace.real_norm_sq_eq, hx, hy] + ring + +lemma matrix_diagonal_opNorm_le {n : ℕ} (d : Fin n → ℝ) (R : ℝ) (hR : 0 ≤ R) + (hd : ∀ i, |d i| ≤ R) : + ‖Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) (Matrix.diagonal d)‖ ≤ R := by + apply matrix_opNorm_le_schur _ R hR + · intro i + simpa [Matrix.diagonal, apply_ite, abs_zero] using hd i + · intro i + simpa [Matrix.diagonal, apply_ite, abs_zero] using hd i + +end SKRatio.MatrixNet + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Matrices/RealPart.lean b/lean/OAI/Probability/SKRatio/Matrices/RealPart.lean new file mode 100644 index 0000000000000000000000000000000000000000..6a032db0235fd5e092e7d4c89d1a8aec99b1735b --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Matrices/RealPart.lean @@ -0,0 +1,109 @@ +import Mathlib +import OAI.Probability.SKRatio.Matrices.LiftMatrix + +namespace OAI + +section +section +noncomputable section +open MeasureTheory ProbabilityTheory InformationTheory Real Set +open scoped NNReal ENNReal +open Filter +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius ENNReal NNReal +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius NNReal +noncomputable section +open MeasureTheory ProbabilityTheory Real Set Filter +open MeasureTheory.Measure +open scoped ENNReal NNReal MeasureTheory Topology +open MeasureTheory +noncomputable section +noncomputable section +open MeasureTheory Set NormedSpace +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius +noncomputable section +open Set Real +open scoped Topology +noncomputable section +open Matrix Set Filter +open scoped Topology Matrix.Norms.Frobenius +noncomputable section +open Matrix NormedSpace ContinuousLinearMap +open scoped Matrix.Norms.Frobenius +noncomputable section +open Matrix +namespace SKRatioGaussian.RealComplex +open scoped Matrix.Norms.Frobenius +variable {ι : Type*} [Fintype ι] [DecidableEq ι] + +def realPart (M : Matrix ι ι ℂ) : Matrix ι ι ℝ := M.map Complex.re + +lemma norm_realPart_le (M : Matrix ι ι ℂ) : ‖realPart M‖ ≤ ‖M‖ := by + rw [Matrix.frobenius_norm_def,Matrix.frobenius_norm_def] + apply Real.rpow_le_rpow (by positivity) _ (by norm_num) + apply Finset.sum_le_sum + intro i _ + apply Finset.sum_le_sum + intro k _ + simp only [realPart,Matrix.map_apply,Real.rpow_two] + exact pow_le_pow_left₀ (norm_nonneg _) (by simpa only [Real.norm_eq_abs] using Complex.abs_re_le_norm (M i k)) 2 + +omit [Fintype ι] [DecidableEq ι] in +lemma realPart_sub (M N : Matrix ι ι ℂ) : realPart (M-N) = realPart M-realPart N := by + ext i k; simp [realPart] +omit [Fintype ι] [DecidableEq ι] in +lemma realPart_liftMatrix (M : Matrix ι ι ℝ) : realPart (liftMatrix M) = M := by + ext i k; simp [realPart,liftMatrix] + +lemma realPart_lipschitz : LipschitzWith 1 (realPart (ι := ι)) := by + apply LipschitzWith.of_dist_le_mul + intro M N + simpa only [dist_eq_norm,NNReal.coe_one,one_mul,realPart_sub] using norm_realPart_le (M-N) + +omit [DecidableEq ι] in +lemma reVec_norm_le (x : EuclideanSpace ℂ ι) : ‖reVec x‖ ≤ ‖x‖ := by + have h := vec_norm_split x + nlinarith [sq_nonneg ‖imVec x‖,norm_nonneg (reVec x),norm_nonneg x] + +lemma realPart_operator (M : Matrix ι ι ℂ) (x : EuclideanSpace ℝ ι) : + rlin (realPart M) x = reVec (clin M (liftVec x)) := by + ext i + change (∑ k, (M i k).re*x k) = (∑ k, M i k*(x k : ℂ)).re + simp + +lemma operator_realPart_le (M : Matrix ι ι ℂ) : opNorm (realPart M) ≤ ‖clin M‖ := by + apply ContinuousLinearMap.opNorm_le_bound _ (norm_nonneg _) + intro x + rw [realPart_operator] + exact (reVec_norm_le _).trans ((clin M).le_opNorm (liftVec x) |>.trans_eq (by rw [norm_liftVec])) + +lemma liftMatrix_inverse {M : Matrix ι ι ℝ} (hM : IsUnit M) : + liftMatrix M⁻¹ = (liftMatrix M)⁻¹ := by + symm + apply Matrix.inv_eq_right_inv + rw [← liftMatrix_mul,Matrix.mul_nonsing_inv M (M.isUnit_iff_isUnit_det.mp hM),liftMatrix_one] + +end SKRatioGaussian.RealComplex + +end +end +end +end +end +end +end +end +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Matrices/RealPartCLM.lean b/lean/OAI/Probability/SKRatio/Matrices/RealPartCLM.lean new file mode 100644 index 0000000000000000000000000000000000000000..01010e3e56b953213f5055fc430ca76876481176 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Matrices/RealPartCLM.lean @@ -0,0 +1,218 @@ +import Mathlib +import OAI.Probability.SKRatio.Matrices.SandShiftSpecial +import OAI.Probability.SKRatio.Matrices.RealPart + +namespace OAI + +section +section +noncomputable section +open MeasureTheory ProbabilityTheory InformationTheory Real Set +open scoped NNReal ENNReal +open Filter +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius ENNReal NNReal +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius NNReal +noncomputable section +open MeasureTheory ProbabilityTheory Real Set Filter +open MeasureTheory.Measure +open scoped ENNReal NNReal MeasureTheory Topology +open MeasureTheory +noncomputable section +noncomputable section +open MeasureTheory Set NormedSpace +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius +noncomputable section +open Set Real +open scoped Topology +noncomputable section +open Matrix Set Filter +open scoped Topology Matrix.Norms.Frobenius +noncomputable section +open Matrix NormedSpace ContinuousLinearMap +open scoped Matrix.Norms.Frobenius +noncomputable section +open Matrix +namespace SKRatioGaussian.RealComplex +open scoped Matrix.Norms.Frobenius SchwartzMap ComplexOrder +open SKRatioGaussian.ComplexMatrix +variable {ι : Type*} [Fintype ι] [DecidableEq ι] + +lemma liftMatrix_isUnit_iff (M : Matrix ι ι ℝ) : IsUnit (liftMatrix M) ↔ IsUnit M := by + rw [(liftMatrix M).isUnit_iff_isUnit_det,M.isUnit_iff_isUnit_det, + isUnit_iff_ne_zero,isUnit_iff_ne_zero] + have he : (liftMatrix M).det = (M.det : ℂ) := (Complex.ofRealHom.map_det M).symm + rw [he] + exact not_congr Complex.ofReal_eq_zero + +noncomputable def realPartCLM : Matrix ι ι ℂ →L[ℝ] Matrix ι ι ℝ := + ({ toFun := realPart + map_add' := by intros; ext; simp [realPart] + map_smul' := by intros; ext; simp [realPart] } : Matrix ι ι ℂ →ₗ[ℝ] Matrix ι ι ℝ).mkContinuous + 1 (fun M => by simpa using norm_realPart_le M) + +noncomputable def realTruncatedK (f : 𝓢(ℝ,ℂ)) (R : ℝ) (hR : 0 ≤ R) + (D C M : Matrix ι ι ℝ) : Matrix ι ι ℝ := + realPart (truncatedK f R hR (1+liftMatrix D*liftMatrix C*liftMatrix D) + (liftMatrix D) (liftMatrix C) (liftMatrix M)) + +lemma realTruncatedK_sub_norm (f : 𝓢(ℝ,ℂ)) {R : ℝ} (hR : 0 ≤ R) + (D C M N : Matrix ι ι ℝ) (hD : Dᵀ = D) (hC : Cᵀ = C) : + ‖realTruncatedK f R hR D C M-realTruncatedK f R hR D C N‖ ≤ + kLip f R (liftMatrix D) (liftMatrix C)*‖M-N‖ := by + have hD' := liftMatrix_hermitian D hD + have hC' := liftMatrix_hermitian C hC + have hB : (1+liftMatrix D*liftMatrix C*liftMatrix D)ᴴ = + 1+liftMatrix D*liftMatrix C*liftMatrix D := by simp [Matrix.conjTranspose_mul,hD',hC',mul_assoc] + unfold realTruncatedK + rw [← realPart_sub] + apply (norm_realPart_le _).trans + simpa only [← liftMatrix_sub,norm_liftMatrix] using + truncatedK_sub_norm f hR _ _ _ (liftMatrix M) (liftMatrix N) hB hD' + +lemma realTruncatedK_opNorm (f : 𝓢(ℝ,ℂ)) {R : ℝ} (hR : 0 ≤ R) + (D C M : Matrix ι ι ℝ) (hD : Dᵀ = D) (hC : Cᵀ = C) : + SKRatioGaussian.opNorm (realTruncatedK f R hR D C M) ≤ kBound f R (liftMatrix D) (liftMatrix C) := by + have hD' := liftMatrix_hermitian D hD + have hC' := liftMatrix_hermitian C hC + have hB : (1+liftMatrix D*liftMatrix C*liftMatrix D)ᴴ = + 1+liftMatrix D*liftMatrix C*liftMatrix D := by simp [Matrix.conjTranspose_mul,hD',hC',mul_assoc] + exact (operator_realPart_le _).trans (truncatedK_opNorm f hR _ _ _ _ hB hD') + +lemma realTruncatedK_eq_inverse (f : 𝓢(ℝ,ℂ)) {lo hi : ℝ} (hlo : 0 < lo) + (hf : ∀ x ∈ Set.Icc lo hi, f x = (x : ℂ)⁻¹) + {R : ℝ} (hR : 0 ≤ R) (D C M : Matrix ι ι ℝ) + (hD : Dᵀ = D) (hC : Cᵀ = C) (hM : Mᵀ = M) (hMR : SKRatioGaussian.opNorm M ≤ R) + (hl : lo ≤ SKRatioGaussian.ComplexSpectral.lowerRayleigh (liftMatrix (1-D*(M-C)*D))) + (hu : -hi ≤ SKRatioGaussian.ComplexSpectral.lowerRayleigh (-liftMatrix (1-D*(M-C)*D))) : + realTruncatedK f R hR D C M = (1-D*D*(M-C))⁻¹ := by + have hD' := liftMatrix_hermitian D hD + have hC' := liftMatrix_hermitian C hC + have hM' := liftMatrix_hermitian M hM + have hB : (1+liftMatrix D*liftMatrix C*liftMatrix D)ᴴ = + 1+liftMatrix D*liftMatrix C*liftMatrix D := by simp [Matrix.conjTranspose_mul,hD',hC',mul_assoc] + have hid : sandShift (1+liftMatrix D*liftMatrix C*liftMatrix D) (liftMatrix D) (liftMatrix M) = + liftMatrix (1-D*(M-C)*D) := by + rw [sandShift_special]; simp only [liftMatrix_sub,liftMatrix_mul,liftMatrix_one] + have hS : (sandShift (1+liftMatrix D*liftMatrix C*liftMatrix D) (liftMatrix D) (liftMatrix M)).IsHermitian := + sandShift_hermitian _ _ _ hB hD' hM' + have hspec : ∀ i, hS.eigenvalues i ∈ Set.Icc lo hi := by + intro i + have hm := SKRatioGaussian.ComplexSpectral.eigenvalue_lower_bound hS i + have hp := SKRatioGaussian.ComplexSpectral.eigenvalue_upper_bound hS i + have hl' : lo ≤ SKRatioGaussian.ComplexSpectral.lowerRayleigh + (sandShift (1+liftMatrix D*liftMatrix C*liftMatrix D) (liftMatrix D) (liftMatrix M)) := by + simpa only [hid] using hl + have hu' : -hi ≤ SKRatioGaussian.ComplexSpectral.lowerRayleigh + (-sandShift (1+liftMatrix D*liftMatrix C*liftMatrix D) (liftMatrix D) (liftMatrix M)) := by + simpa only [hid] using hu + constructor <;> linarith + have hsunit : IsUnit (1-liftMatrix D*(liftMatrix M-liftMatrix C)*liftMatrix D) := by + rw [← sandShift_special] + exact (hS.posDef_iff_eigenvalues_pos.mpr (fun i => hlo.trans_le (hspec i).1)).isUnit + have hrunit : IsUnit (1-D*D*(M-C)) := by + apply (liftMatrix_isUnit_iff _).mp + simpa only [liftMatrix_sub,liftMatrix_mul,liftMatrix_one] using + SKRatioGaussian.ResolventIdentity.inverse_one_sub_square_mul_unit (liftMatrix D) (liftMatrix M-liftMatrix C) hsunit + unfold realTruncatedK + rw [truncatedK_eq_inverse f hlo hf hR _ _ _ hD' hC' hM' + (by simpa only [SKRatioGaussian.ComplexMatrix.opNorm,SKRatioGaussian.ComplexMatrix.lin,operator_norm_lift] using hMR) hspec] + rw [← liftMatrix_one,← liftMatrix_mul,← liftMatrix_sub,← liftMatrix_mul,← liftMatrix_sub, + ← liftMatrix_inverse hrunit,realPart_liftMatrix] + +lemma real_matrix_hasDerivAt_inverse {Q : ℝ → Matrix ι ι ℝ} {Q' : Matrix ι ι ℝ} {t : ℝ} + (hQ : HasDerivAt Q Q' t) (hunit : IsUnit (Q t)) : + HasDerivAt (fun s => (Q s)⁻¹) (-(Q t)⁻¹*Q'*(Q t)⁻¹) t := by + obtain ⟨u,hu⟩ := hunit + have hfi := hasFDerivAt_ringInverse (𝕜 := ℝ) u + rw [hu] at hfi + have hi := hfi.comp_hasDerivAt t hQ + have hv : (↑u⁻¹ : Matrix ι ι ℝ) = (Q t)⁻¹ := by + rw [← hu,Matrix.nonsing_inv_eq_ringInverse,Ring.inverse_unit] + simpa only [Function.comp_def,← Matrix.nonsing_inv_eq_ringInverse,_root_.neg_apply, + ContinuousLinearMap.mulLeftRight_apply,hv,neg_mul] using! hi + +lemma continuous_realOpNorm : Continuous (SKRatioGaussian.opNorm : Matrix ι ι ℝ → ℝ) := by + have h : Continuous (fun M : Matrix ι ι ℝ => liftMatrix M) := by + dsimp [liftMatrix]; fun_prop + have hc := SKRatioGaussian.ComplexMatrix.continuous_lin.norm.comp h + simpa only [Function.comp_def,SKRatioGaussian.ComplexMatrix.lin,operator_norm_lift] using hc + +lemma realTruncatedK_eventually_inverse (f : 𝓢(ℝ,ℂ)) {lo hi : ℝ} (hlo : 0 < lo) + (hf : ∀ x ∈ Set.Icc lo hi, f x = (x : ℂ)⁻¹) + {R : ℝ} (hR : 0 ≤ R) (D C M E : Matrix ι ι ℝ) + (hD : Dᵀ = D) (hC : Cᵀ = C) (hM : Mᵀ = M) (hE : Eᵀ = E) + (hMR : SKRatioGaussian.opNorm M < R) + (hl : lo < SKRatioGaussian.ComplexSpectral.lowerRayleigh (liftMatrix (1-D*(M-C)*D))) + (hu : -hi < SKRatioGaussian.ComplexSpectral.lowerRayleigh (-liftMatrix (1-D*(M-C)*D))) : + (fun t : ℝ => realTruncatedK f R hR D C (M+t • E)) =ᶠ[𝓝 (0:ℝ)] + (fun t => (1-D*D*(M+t • E-C))⁻¹) := by + have hcont : Continuous (fun t : ℝ => liftMatrix (1-D*(M+t • E-C)*D)) := by + dsimp [liftMatrix]; fun_prop + have hcont' : Continuous (fun t : ℝ => SKRatioGaussian.opNorm (M+t • E)) := + continuous_realOpNorm.comp (continuous_const.add (continuous_id.smul continuous_const)) + have hl' : ∀ᶠ t in 𝓝 (0:ℝ), lo < SKRatioGaussian.ComplexSpectral.lowerRayleigh (liftMatrix (1-D*(M+t • E-C)*D)) := + (SKRatioGaussian.ComplexSpectral.continuous_lowerRayleigh.comp hcont).continuousAt.eventually + (lt_mem_nhds (by simpa using hl)) + have hu' : ∀ᶠ t in 𝓝 (0:ℝ), -hi < SKRatioGaussian.ComplexSpectral.lowerRayleigh (-liftMatrix (1-D*(M+t • E-C)*D)) := + (SKRatioGaussian.ComplexSpectral.continuous_lowerRayleigh.comp hcont.neg).continuousAt.eventually + (lt_mem_nhds (by simpa using hu)) + have hm' : ∀ᶠ t in 𝓝 (0:ℝ), SKRatioGaussian.opNorm (M+t • E) < R := + hcont'.continuousAt.eventually (gt_mem_nhds (by simpa using hMR)) + filter_upwards [hl',hu',hm'] with t ht ht' hm + exact realTruncatedK_eq_inverse f hlo hf hR D C (M+t • E) hD hC + (by simp [Matrix.transpose_smul,hM,hE]) hm.le ht.le ht'.le + +lemma realTruncatedK_derivative (f : 𝓢(ℝ,ℂ)) {lo hi : ℝ} (hlo : 0 < lo) + (hf : ∀ x ∈ Set.Icc lo hi, f x = (x : ℂ)⁻¹) + {R : ℝ} (hR : 0 ≤ R) (D C M E : Matrix ι ι ℝ) + (hD : Dᵀ = D) (hC : Cᵀ = C) (hM : Mᵀ = M) (hE : Eᵀ = E) + (hMR : SKRatioGaussian.opNorm M < R) + (hl : lo < SKRatioGaussian.ComplexSpectral.lowerRayleigh (liftMatrix (1-D*(M-C)*D))) + (hu : -hi < SKRatioGaussian.ComplexSpectral.lowerRayleigh (-liftMatrix (1-D*(M-C)*D))) : + HasDerivAt (fun t : ℝ => realTruncatedK f R hR D C (M+t • E)) + (realTruncatedK f R hR D C M*(D*D)*E*realTruncatedK f R hR D C M) 0 := by + have hid := realTruncatedK_eq_inverse f hlo hf hR D C M hD hC hM hMR.le hl.le hu.le + have he := realTruncatedK_eventually_inverse f hlo hf hR D C M E hD hC hM hE hMR hl hu + have hunit : IsUnit (1-D*D*(M-C)) := by + have hSH : (liftMatrix (1-D*(M-C)*D)).IsHermitian := + liftMatrix_hermitian _ (by simp [Matrix.transpose_mul,hD,hC,hM,mul_assoc]) + have hp : (liftMatrix (1-D*(M-C)*D)).PosDef := hSH.posDef_iff_eigenvalues_pos.mpr (fun i => + hlo.trans (hl.trans_le (SKRatioGaussian.ComplexSpectral.eigenvalue_lower_bound hSH i))) + have hS : IsUnit (1-D*(M-C)*D) := (liftMatrix_isUnit_iff _).mp hp.isUnit + exact SKRatioGaussian.ResolventIdentity.inverse_one_sub_square_mul_unit D (M-C) hS + have hm : HasDerivAt (fun t : ℝ => M+t • E-C) E 0 := by + convert! ((hasDerivAt_id (0:ℝ)).smul_const E |>.const_add M).sub_const C using 1 + simp only [one_smul] + have hq := (hm.const_mul (D*D)).const_sub 1 + have hi := real_matrix_hasDerivAt_inverse hq (by simpa using hunit) + rw [hid] + have hi' : HasDerivAt (fun t : ℝ => (1-D*D*(M+t • E-C))⁻¹) + ((1-D*D*(M-C))⁻¹*(D*D)*E*(1-D*D*(M-C))⁻¹) 0 := by + simpa only [zero_smul,add_zero,mul_neg,neg_mul,neg_neg,mul_assoc] using! hi + exact hi'.congr_of_eventuallyEq he + +end SKRatioGaussian.RealComplex + +end +end +end +end +end +end +end +end +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Matrices/RealSymmetricResolventUnit.lean b/lean/OAI/Probability/SKRatio/Matrices/RealSymmetricResolventUnit.lean new file mode 100644 index 0000000000000000000000000000000000000000..fb9de3f26883b988ed45dad0053c8d8e7d8416fc --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Matrices/RealSymmetricResolventUnit.lean @@ -0,0 +1,135 @@ +import Mathlib +import OAI.Probability.SKRatio.Matrices.TruncationGoodSet +import OAI.Probability.SKRatio.Matrices.AbsMulEntryBound + +namespace OAI + +section +section +noncomputable section +open MeasureTheory ProbabilityTheory InformationTheory Real Set +open scoped NNReal ENNReal +open Filter +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius ENNReal NNReal +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius NNReal +noncomputable section +open MeasureTheory ProbabilityTheory Real Set Filter +open MeasureTheory.Measure +open scoped ENNReal NNReal MeasureTheory Topology +open MeasureTheory +noncomputable section +noncomputable section +open MeasureTheory Set NormedSpace +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius +noncomputable section +open Set Real +open scoped Topology +noncomputable section +open Matrix Set Filter +open scoped Topology Matrix.Norms.Frobenius +noncomputable section +open Matrix NormedSpace ContinuousLinearMap +open scoped Matrix.Norms.Frobenius +noncomputable section +open Matrix +noncomputable section +open MeasureTheory ProbabilityTheory Real Set +open scoped ENNReal NNReal +namespace SKRatioGaussian +open RealComplex ComplexSpectral +open Matrix MeasureTheory ProbabilityTheory Real +open scoped BigOperators Matrix.Norms.Frobenius NNReal ENNReal SchwartzMap ComplexOrder +variable {ι : Type*} [Fintype ι] [DecidableEq ι] + +lemma real_symmetric_resolvent_isUnit (D C M : Matrix ι ι ℝ) + (hD : Dᵀ = D) (hC : Cᵀ = C) (hM : Mᵀ = M) + (hl : 0 < lowerRayleigh (liftMatrix (1-D*(M-C)*D))) : + IsUnit (1-D*D*(M-C)) := by + have hs : (liftMatrix (1-D*(M-C)*D)).IsHermitian := by + rw [liftMatrix_sub,liftMatrix_one,liftMatrix_mul,liftMatrix_mul,liftMatrix_sub] + change (1-liftMatrix D*(liftMatrix M-liftMatrix C)*liftMatrix D)ᴴ = _ + simp only [Matrix.conjTranspose_sub,Matrix.conjTranspose_one,Matrix.conjTranspose_mul, + liftMatrix_hermitian D hD,liftMatrix_hermitian C hC,liftMatrix_hermitian M hM,mul_assoc] + have hsu : IsUnit (liftMatrix (1-D*(M-C)*D)) := + (hs.posDef_iff_eigenvalues_pos.mpr (fun i => hl.trans_le (eigenvalue_lower_bound hs i))).isUnit + have hrs := (liftMatrix_isUnit_iff _).mp hsu + exact ResolventIdentity.inverse_one_sub_square_mul_unit D (M-C) hrs + +lemma diagonal_resolvent_identity (d c : ι → ℝ) (M K : Matrix ι ι ℝ) + (hK : (1-diagonal d*diagonal d*(M-diagonal c))*K=1) (i : ι) : + K i i = 1+(d i)^2*((M*K) i i-c i*K i i) := by + have he : (1-diagonal d*diagonal d*(M-diagonal c))*K = + K-diagonal (fun a => (d a)^2)*(M*K-diagonal c*K) := by + have hd : diagonal d*diagonal d = diagonal (fun a => (d a)^2) := by + rw [Matrix.diagonal_mul_diagonal]; congr 1; ext a; simp only [pow_two] + rw [hd] + noncomm_ring + rw [he] at hK + have hh := congrFun (congrFun hK i) i + simp only [Matrix.sub_apply,Matrix.diagonal_mul,Matrix.one_apply_eq] at hh + nlinarith only [hh] + +theorem realTruncatedK_second_loop (f : 𝓢(ℝ,ℂ)) {lo hi : ℝ} (hlo : 0 < lo) + (hf : ∀ x ∈ Set.Icc lo hi, f x = (x : ℂ)⁻¹) + {R r : ℝ} (hR : 0 ≤ R) (hr : 0 ≤ r) (d c : ι → ℝ) (i : ι) : + let D := diagonal d + let C := diagonal c + let K := realTruncatedK f R hR D C + let b := ComplexMatrix.kBound f R (liftMatrix D) (liftMatrix C) + let μ := Measure.pi (fun _ : MatrixCoordinates ι => gaussianReal 0 1) + let s := truncationGoodSet r R lo hi D C + |(∫ g, K (goeMatrix r g) i i ∂μ)- + (1+(d i)^2*((∫ g, (goeMatrix r g*K (goeMatrix r g)) i i ∂μ)- + c i*(∫ g, K (goeMatrix r g) i i ∂μ)))| ≤ + (b+1+|(d i)^2*c i| *b)*μ.real sᶜ+ + (|(d i)^2| *b)*(Fintype.card ι:ℝ)*sqrt (2*r)*sqrt (μ.real sᶜ) := by + intro D C K b μ s + have hD : Dᵀ=D := Matrix.diagonal_transpose _ + have hC : Cᵀ=C := Matrix.diagonal_transpose _ + have hKL := realTruncatedK_lipschitz f hR D C hD hC + apply goe_diagonal_inverse_loop hr (fun a => (d a)^2) c i + (hKL.continuous.comp (goeMatrix_pi_lipschitz r).continuous) + (fun g a b => (matrix_entry_le_opNorm _ a b).trans + (realTruncatedK_opNorm f hR D C _ hD hC)) + (truncationGoodSet_measurable r R lo hi D C) + intro g hg + apply diagonal_resolvent_identity d c (goeMatrix r g) (K (goeMatrix r g)) + have hunit := real_symmetric_resolvent_isUnit D C (goeMatrix r g) hD hC + (goeMatrix_transpose r g) (hlo.trans hg.2.1) + have hid := realTruncatedK_eq_inverse f hlo hf hR D C (goeMatrix r g) hD hC + (goeMatrix_transpose r g) hg.1.le hg.2.1.le hg.2.2.le + change (1-D*D*(goeMatrix r g-C))*K (goeMatrix r g)=1 + rw [show K (goeMatrix r g) = _ from hid] + exact Matrix.mul_nonsing_inv _ (((1-D*D*(goeMatrix r g-C)).isUnit_iff_isUnit_det).mp hunit) + +end SKRatioGaussian + +noncomputable section +open MeasureTheory ProbabilityTheory InformationTheory Real Set +open scoped NNReal ENNReal + +end +end +end +end +end +end +end +end +end +end +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Matrices/RowGeometry.lean b/lean/OAI/Probability/SKRatio/Matrices/RowGeometry.lean new file mode 100644 index 0000000000000000000000000000000000000000..f005a0c59ca72fd2668e94564f3b1d3464a307c4 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Matrices/RowGeometry.lean @@ -0,0 +1,115 @@ +import Mathlib +import OAI.Probability.SKRatio.Matrices.PlantedSquares + +namespace OAI + +section +noncomputable section +open scoped BigOperators Topology +open Set Real +namespace SKRatio.Planted +open MatrixNet +attribute [local instance] Classical.propDecidable +variable {n : ℕ} + +def otherEnd (i : Fin n) (e : Edge n) : Fin n := + if e.1.1=i then e.1.2 else e.1.1 + +lemma mem_incident (i : Fin n) (e : Edge n) : + e∈incidentEdges i ↔ e.1.1=i ∨ e.1.2=i := by simp [incidentEdges] + +lemma otherEnd_ne {i : Fin n} {e : Edge n} (he : e∈incidentEdges i) : + otherEnd i e ≠ i := by + have h := (mem_incident i e).mp he + unfold otherEnd + split_ifs with h₁ + · have hlt := e.2 + rw [h₁] at hlt + exact ne_of_gt hlt + · exact h₁ + +lemma coupling_otherEnd {i : Fin n} {e : Edge n} (g : Disorder n) + (he : e∈incidentEdges i) : coupling g i (otherEnd i e)=g e := by + have h := (mem_incident i e).mp he + rcases h with h | h + · simp only [otherEnd,ite_eq_left h] + subst i + simp [coupling,e.2] + · have h₁ : e.1.1 ≠ i := by rw [←h]; exact ne_of_lt e.2 + simp only [otherEnd,ite_eq_right h₁] + subst i + simp [coupling,not_lt_of_gt e.2,e.2] + +lemma sum_coupling_weighted_row (g : Disorder n) (i : Fin n) (f : Fin n → ℝ) : + ∑ j, coupling g i j*f j = ∑ e∈incidentEdges i, g e*f (otherEnd i e) := by + have he := coupling_bilinear (fun j => if j=i then 1 else 0) f g + simp only [ite_mul,one_mul,zero_mul,Finset.sum_ite_irrel, + Finset.sum_const_zero,Finset.sum_ite_eq',Finset.mem_univ,ite_true] at he + rw [he,incidentEdges,Finset.sum_filter] + apply Finset.sum_congr rfl + intro e _ + have hne : e.1.1≠e.1.2 := ne_of_lt e.2 + by_cases h₁ : e.1.1=i <;> by_cases h₂ : e.1.2=i <;> + simp_all [otherEnd,mul_comm] + +def diagonalField (ζ : Fin n → ℝ) (g : Disorder n) (j : Fin n) : ℝ := + ζ j+∑ k, coupling g j k + +def eraseRow (i : Fin n) (g : Disorder n) : Disorder n := + fun e => if e∈incidentEdges i then 0 else g e + +lemma coupling_eraseRow (i : Fin n) (g : Disorder n) (j k : Fin n) : + coupling (eraseRow i g) j k = if j=i ∨ k=i then 0 else coupling g j k := by + unfold coupling eraseRow + split_ifs <;> simp_all [mem_incident] + +lemma diagonalField_eraseRow (ζ : Fin n → ℝ) (g : Disorder n) (i j : Fin n) + (hji : j≠i) : + diagonalField ζ g j-diagonalField ζ (eraseRow i g) j = coupling g i j := by + have h (k : Fin n) : coupling g j k - coupling (eraseRow i g) j k = + if k=i then coupling g j i else 0 := by + rw [coupling_eraseRow] + by_cases hk : k=i <;> simp [hji,hk] + simp only [diagonalField,add_sub_add_left_eq_sub,←Finset.sum_sub_distrib,h, + Finset.sum_ite_eq',Finset.mem_univ,ite_true,coupling_symm g j i] + +def outsideDisorder (β : ℝ) (i : Fin n) + (y : {e // e∉incidentEdges i} → ℝ) : Disorder n := + fun e => if he : e∈incidentEdges i then 0 else β/sqrt n*y ⟨e,he⟩+β^2/(n:ℝ) + +lemma outsideDisorder_eq (β : ℝ) (i : Fin n) (z : Disorder n) : + outsideDisorder β i (fun e => z e) = eraseRow i (affineDisorder β z) := by + funext e + simp only [outsideDisorder,eraseRow,affineDisorder] + split_ifs <;> rfl + +lemma outside_field_error (β : ℝ) (i : Fin n) (ζ : Fin n → ℝ) (z : Disorder n) + (e : incidentEdges i) : + diagonalField ζ (affineDisorder β z) (otherEnd i e) - + diagonalField ζ (outsideDisorder β i (fun j => z j)) (otherEnd i e) = + affineDisorder β z e := by + rw [outsideDisorder_eq,diagonalField_eraseRow ζ _ i _ (otherEnd_ne e.2),coupling_otherEnd _ e.2] + +lemma continuous_diagonalField (j : Fin n) : + Continuous (fun p : (Fin n → ℝ) × Disorder n => diagonalField p.1 p.2 j) := by + apply ((continuous_apply j).comp continuous_fst).add + exact continuous_finsetSum _ (fun k _ => (continuous_coupling j k).comp continuous_snd) + +lemma continuous_outsideDisorder (β : ℝ) (i : Fin n) : + Continuous (outsideDisorder β i) := by + apply continuous_pi + intro e + unfold outsideDisorder + split_ifs <;> fun_prop + +lemma continuous_outside_field (β : ℝ) (i j : Fin n) : + Continuous (fun p : (Fin n → ℝ) × ({e // e∉incidentEdges i} → ℝ) => + diagonalField p.1 (outsideDisorder β i p.2) j) := + (continuous_diagonalField j).comp (continuous_fst.prodMk ((continuous_outsideDisorder β i).comp continuous_snd)) + +end SKRatio.Planted + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Matrices/SandShift.lean b/lean/OAI/Probability/SKRatio/Matrices/SandShift.lean new file mode 100644 index 0000000000000000000000000000000000000000..7aafd6e49baba9fd88ed077e6f7960eed4c7646d --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Matrices/SandShift.lean @@ -0,0 +1,126 @@ +import Mathlib +import OAI.Probability.SKRatio.Matrices.FourierMoment +import OAI.Probability.SKRatio.Matrices.OpNormNonneg + +namespace OAI + +section +section +noncomputable section +open MeasureTheory ProbabilityTheory InformationTheory Real Set +open scoped NNReal ENNReal +open Filter +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius ENNReal NNReal +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius NNReal +noncomputable section +open MeasureTheory ProbabilityTheory Real Set Filter +open MeasureTheory.Measure +open scoped ENNReal NNReal MeasureTheory Topology +open MeasureTheory +noncomputable section +noncomputable section +open MeasureTheory Set NormedSpace +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius +namespace SKRatioGaussian.ComplexMatrix +open scoped FourierTransform SchwartzMap +variable {ι : Type*} [Fintype ι] [DecidableEq ι] + +def sandShift (B D M : Matrix ι ι ℂ) : Matrix ι ι ℂ := B-D*M*D + +omit [DecidableEq ι] in +lemma sandShift_hermitian (B D M : Matrix ι ι ℂ) (hB : Bᴴ = B) (hD : Dᴴ = D) (hM : Mᴴ = M) : + (sandShift B D M)ᴴ = sandShift B D M := by + simp [sandShift,Matrix.conjTranspose_mul,hB,hD,hM,mul_assoc] + +lemma sandShift_sub (B D M N : Matrix ι ι ℂ) : + sandShift B D M-sandShift B D N = -(D*(M-N)*D) := by dsimp [sandShift]; noncomm_ring + +lemma sandShift_lipschitz (B D M N : Matrix ι ι ℂ) : + ‖sandShift B D M-sandShift B D N‖ ≤ opNorm D^2*‖M-N‖ := by + rw [sandShift_sub,norm_neg] + exact sandwich_frobenius _ _ + +lemma sandShift_parameter (B B' D D' M : Matrix ι ι ℂ) : + opNorm (sandShift B D M-sandShift B' D' M) ≤ + opNorm (B-B')+(opNorm D+opNorm D')*opNorm (D-D')*opNorm M := by + have he : sandShift B D M-sandShift B' D' M = (B-B')-(D*M*D-D'*M*D') := by dsimp [sandShift]; abel + rw [he] + calc + _ ≤ opNorm (B-B')+opNorm (D*M*D-D'*M*D') := opNorm_sub (B-B') (D*M*D-D'*M*D') + _ ≤ _ := by + have hh := sandwich_difference_opNorm D D' M + linarith only [hh] + +lemma sandShift_four_point (B B' D D' M N : Matrix ι ι ℂ) : + ‖(sandShift B D M-sandShift B D N)-(sandShift B' D' M-sandShift B' D' N)‖ ≤ + (opNorm D+opNorm D')*opNorm (D-D')*‖M-N‖ := by + rw [sandShift_sub,sandShift_sub,← norm_neg] + have he : -(-(D*(M-N)*D)- -(D'*(M-N)*D')) = D*(M-N)*D-D'*(M-N)*D' := by abel + rw [he] + exact sandwich_difference_frobenius _ _ _ + +lemma schwartzMatrix_sandShift_lipschitz (f : 𝓢(ℝ,ℂ)) (B D M N : Matrix ι ι ℂ) + (hB : Bᴴ = B) (hD : Dᴴ = D) (hM : Mᴴ = M) (hN : Nᴴ = N) : + ‖schwartzMatrix f (sandShift B D M)-schwartzMatrix f (sandShift B D N)‖ ≤ + (2*Real.pi*fourierMoment f 1)*opNorm D^2*‖M-N‖ := by + exact (schwartzMatrix_lipschitz f _ _ (sandShift_hermitian _ _ _ hB hD hM) + (sandShift_hermitian _ _ _ hB hD hN)).trans + ((mul_le_mul_of_nonneg_left (sandShift_lipschitz B D M N) + (by positivity [fourierMoment_nonneg f 1])).trans_eq (by ring)) + +lemma schwartzMatrix_sandShift_four_point (f : 𝓢(ℝ,ℂ)) (B B' D D' M N : Matrix ι ι ℂ) + (hB : Bᴴ = B) (hB' : B'ᴴ = B') (hD : Dᴴ = D) (hD' : D'ᴴ = D') + (hM : Mᴴ = M) (hN : Nᴴ = N) : + ‖(schwartzMatrix f (sandShift B D M)-schwartzMatrix f (sandShift B D N))- + (schwartzMatrix f (sandShift B' D' M)-schwartzMatrix f (sandShift B' D' N))‖ ≤ + ((2*Real.pi*fourierMoment f 1)*(opNorm D+opNorm D')*opNorm (D-D')+ + ((2*Real.pi)^2*fourierMoment f 2)* + (2*opNorm (B-B')+(opNorm D+opNorm D')*opNorm (D-D')*(opNorm M+opNorm N))*opNorm D'^2)*‖M-N‖ := by + have hL : 0 ≤ 2*Real.pi*fourierMoment f 1 := by have := fourierMoment_nonneg f 1; positivity + have hQ : 0 ≤ (2*Real.pi)^2*fourierMoment f 2 := by have := fourierMoment_nonneg f 2; positivity + have hP : 0 ≤ (opNorm D+opNorm D')*opNorm (D-D') := + mul_nonneg (add_nonneg (opNorm_nonneg _) (opNorm_nonneg _)) (opNorm_nonneg _) + have hp := add_le_add (sandShift_parameter B B' D D' M) (sandShift_parameter B B' D D' N) + have hp' : opNorm (sandShift B D M-sandShift B' D' M)+opNorm (sandShift B D N-sandShift B' D' N) ≤ + 2*opNorm (B-B')+(opNorm D+opNorm D')*opNorm (D-D')*(opNorm M+opNorm N) := by nlinarith only [hp] + have hx := schwartzMatrix_four_point f (sandShift B D M) (sandShift B D N) (sandShift B' D' M) (sandShift B' D' N) + (sandShift_hermitian _ _ _ hB hD hM) (sandShift_hermitian _ _ _ hB hD hN) + (sandShift_hermitian _ _ _ hB' hD' hM) (sandShift_hermitian _ _ _ hB' hD' hN) + apply hx.trans + calc + _ ≤ (2*Real.pi*fourierMoment f 1)*((opNorm D+opNorm D')*opNorm (D-D')*‖M-N‖)+ + ((2*Real.pi)^2*fourierMoment f 2)* + (2*opNorm (B-B')+(opNorm D+opNorm D')*opNorm (D-D')*(opNorm M+opNorm N))*(opNorm D'^2*‖M-N‖) := by + apply add_le_add + · exact mul_le_mul_of_nonneg_left (sandShift_four_point _ _ _ _ _ _) hL + · apply mul_le_mul (mul_le_mul_of_nonneg_left hp' hQ) (sandShift_lipschitz B' D' M N) (norm_nonneg _) + exact mul_nonneg hQ (add_nonneg (mul_nonneg (by norm_num) (opNorm_nonneg _)) + (mul_nonneg hP (add_nonneg (opNorm_nonneg _) (opNorm_nonneg _)))) + _ = _ := by ring + +end SKRatioGaussian.ComplexMatrix + +noncomputable section +open Set Real +open scoped Topology + +end +end +end +end +end +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Matrices/SandShiftSpecial.lean b/lean/OAI/Probability/SKRatio/Matrices/SandShiftSpecial.lean new file mode 100644 index 0000000000000000000000000000000000000000..17e7f6030dc640c02f6b2f4855dad029aff96792 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Matrices/SandShiftSpecial.lean @@ -0,0 +1,146 @@ +import Mathlib +import OAI.Probability.SKRatio.Matrices.Fl1 +import OAI.Probability.SKRatio.Matrices.Quadratic +import OAI.Probability.SKRatio.Matrices.PathResolvent +import OAI.Probability.SKRatio.Matrices.InverseSubSquareMul + +namespace OAI + +section +section +noncomputable section +open MeasureTheory ProbabilityTheory InformationTheory Real Set +open scoped NNReal ENNReal +open Filter +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius ENNReal NNReal +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius NNReal +noncomputable section +open MeasureTheory ProbabilityTheory Real Set Filter +open MeasureTheory.Measure +open scoped ENNReal NNReal MeasureTheory Topology +open MeasureTheory +noncomputable section +noncomputable section +open MeasureTheory Set NormedSpace +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius +noncomputable section +open Set Real +open scoped Topology +noncomputable section +open Matrix Set Filter +open scoped Topology Matrix.Norms.Frobenius +noncomputable section +open Matrix NormedSpace ContinuousLinearMap +open scoped Matrix.Norms.Frobenius +noncomputable section +open Matrix +namespace SKRatioGaussian.ComplexMatrix +open scoped SchwartzMap ComplexOrder +open Set Filter +open scoped Topology +variable {ι : Type*} [Fintype ι] [DecidableEq ι] + +lemma sandShift_special (D C M : Matrix ι ι ℂ) : + sandShift (1+D*C*D) D M = 1-D*(M-C)*D := by + dsimp [sandShift]; noncomm_ring + +lemma truncatedK_eq_inverse (f : 𝓢(ℝ,ℂ)) {lo hi : ℝ} (hlo : 0 < lo) + (hf : ∀ x ∈ Icc lo hi, f x = (x : ℂ)⁻¹) + {R : ℝ} (hR : 0 ≤ R) (D C M : Matrix ι ι ℂ) + (hD : Dᴴ = D) (hC : Cᴴ = C) (hM : Mᴴ = M) (hMR : opNorm M ≤ R) + (hspec : ∀ i, Matrix.IsHermitian.eigenvalues (sandShift_hermitian (1+D*C*D) D M + (by simp [Matrix.conjTranspose_mul,hD,hC,mul_assoc]) hD hM) i ∈ Icc lo hi) : + truncatedK f R hR (1+D*C*D) D C M = (1-D*D*(M-C))⁻¹ := by + have hB : (1+D*C*D)ᴴ = 1+D*C*D := by simp [Matrix.conjTranspose_mul,hD,hC,mul_assoc] + have hS : IsUnit (sandShift (1+D*C*D) D M) := + ((Matrix.IsHermitian.posDef_iff_eigenvalues_pos (sandShift_hermitian _ _ _ hB hD hM)).mpr + (fun i => hlo.trans_le (hspec i).1)).isUnit + rw [truncatedK,truncatedG_eq_inverse f hlo hf R hR _ _ _ hB hD hM hMR hspec, + matrixProject_eq_self R hR M hM hMR,sandShift_special] + exact (SKRatioGaussian.ResolventIdentity.inverse_one_sub_square_mul D (M-C) (by + simpa only [sandShift_special] using hS)).symm + +lemma truncatedK_eventually_eq_inverse (f : 𝓢(ℝ,ℂ)) {lo hi : ℝ} (hlo : 0 < lo) + (hf : ∀ x ∈ Icc lo hi, f x = (x : ℂ)⁻¹) + {R : ℝ} (hR : 0 ≤ R) (D C : Matrix ι ι ℂ) + {M : ℝ → Matrix ι ι ℂ} {t : ℝ} (hMc : ContinuousAt M t) + (hD : Dᴴ = D) (hC : Cᴴ = C) (hM : ∀ s, (M s)ᴴ = M s) + (hMR : opNorm (M t) < R) + (hl : lo < SKRatioGaussian.ComplexSpectral.lowerRayleigh (sandShift (1+D*C*D) D (M t))) + (hu : -hi < SKRatioGaussian.ComplexSpectral.lowerRayleigh (-sandShift (1+D*C*D) D (M t))) : + (fun s => truncatedK f R hR (1+D*C*D) D C (M s)) =ᶠ[𝓝 t] + (fun s => (1-D*D*(M s-C))⁻¹) := by + have hB : (1+D*C*D)ᴴ = 1+D*C*D := by simp [Matrix.conjTranspose_mul,hD,hC,mul_assoc] + have hs : ContinuousAt (fun s => sandShift (1+D*C*D) D (M s)) t := by + dsimp [sandShift]; fun_prop + have he := SKRatioGaussian.ComplexSpectral.spectral_interval_eventually hs + (fun s => sandShift_hermitian _ _ _ hB hD (hM s)) hl hu + have hm := ((continuous_lin.norm).continuousAt.comp hMc).eventually (gt_mem_nhds hMR) + filter_upwards [he,hm] with s hs hm + exact truncatedK_eq_inverse f hlo hf hR D C (M s) hD hC (hM s) hm.le hs + +lemma square_resolvent_derivative (D C M E : Matrix ι ι ℂ) + (hunit : IsUnit (1-D*D*(M-C))) : + HasDerivAt (fun t : ℝ => (1-D*D*(M+t • E-C))⁻¹) + ((1-D*D*(M-C))⁻¹*(D*D)*E*(1-D*D*(M-C))⁻¹) 0 := by + have hm : HasDerivAt (fun t : ℝ => M+t • E-C) E 0 := by + convert! ((hasDerivAt_id (0:ℝ)).smul_const E |>.const_add M).sub_const C using 1 + simp only [one_smul] + have hq := (hm.const_mul (D*D)).const_sub 1 + have hi := matrix_hasDerivAt_inverse hq (by simpa using hunit) + simpa only [zero_smul,add_zero,mul_neg,neg_mul,neg_neg,mul_assoc] using! hi + +lemma truncatedK_derivative (f : 𝓢(ℝ,ℂ)) {lo hi : ℝ} (hlo : 0 < lo) + (hf : ∀ x ∈ Icc lo hi, f x = (x : ℂ)⁻¹) + {R : ℝ} (hR : 0 ≤ R) (D C M E : Matrix ι ι ℂ) + (hD : Dᴴ = D) (hC : Cᴴ = C) (hM : Mᴴ = M) (hE : Eᴴ = E) + (hMR : opNorm M < R) + (hl : lo < SKRatioGaussian.ComplexSpectral.lowerRayleigh (sandShift (1+D*C*D) D M)) + (hu : -hi < SKRatioGaussian.ComplexSpectral.lowerRayleigh (-sandShift (1+D*C*D) D M)) : + HasDerivAt (fun t : ℝ => truncatedK f R hR (1+D*C*D) D C (M+t • E)) + (truncatedK f R hR (1+D*C*D) D C M*(D*D)*E* + truncatedK f R hR (1+D*C*D) D C M) 0 := by + have hB : (1+D*C*D)ᴴ = 1+D*C*D := by simp [Matrix.conjTranspose_mul,hD,hC,mul_assoc] + have hSM : (sandShift (1+D*C*D) D M).IsHermitian := sandShift_hermitian _ _ _ hB hD hM + have hspec : ∀ i, hSM.eigenvalues i ∈ Icc lo hi := by + intro i + have hm := SKRatioGaussian.ComplexSpectral.eigenvalue_lower_bound hSM i + have hp := SKRatioGaussian.ComplexSpectral.eigenvalue_upper_bound hSM i + constructor <;> linarith + have hS : IsUnit (1-D*(M-C)*D) := by + rw [← sandShift_special] + exact (hSM.posDef_iff_eigenvalues_pos.mpr (fun i => hlo.trans_le (hspec i).1)).isUnit + have hunit := SKRatioGaussian.ResolventIdentity.inverse_one_sub_square_mul_unit D (M-C) hS + have hid := truncatedK_eq_inverse f hlo hf hR D C M hD hC hM hMR.le hspec + rw [hid] + have he := truncatedK_eventually_eq_inverse f hlo hf hR D C + (M := fun t : ℝ => M+t • E) (t := 0) (by fun_prop) hD hC + (fun t => by simp [Matrix.conjTranspose_smul,hM,hE]) + (by simpa using hMR) (by simpa using hl) (by simpa using hu) + exact (square_resolvent_derivative D C M E hunit).congr_of_eventuallyEq he + +end SKRatioGaussian.ComplexMatrix + +end +end +end +end +end +end +end +end +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Matrices/ScaledDiagonalExpectedMargin.lean b/lean/OAI/Probability/SKRatio/Matrices/ScaledDiagonalExpectedMargin.lean new file mode 100644 index 0000000000000000000000000000000000000000..6f6ab3b88c1e7db0ddc2736251032e820cdf9085 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Matrices/ScaledDiagonalExpectedMargin.lean @@ -0,0 +1,161 @@ +import Mathlib +import OAI.Probability.SKRatio.Matrices.UnitBall +import OAI.Probability.SKRatio.Matrices.GaussianProductUpperTailLipschitz +import OAI.Probability.SKRatio.Matrices.DiagonalSum + +namespace OAI + +section +section +noncomputable section +open MeasureTheory ProbabilityTheory InformationTheory Real Set +open scoped NNReal ENNReal +open Filter +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius ENNReal NNReal +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius NNReal +noncomputable section +open MeasureTheory ProbabilityTheory Real Set Filter +open MeasureTheory.Measure +open scoped ENNReal NNReal MeasureTheory Topology +open MeasureTheory +noncomputable section +noncomputable section +open MeasureTheory Set NormedSpace +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius +noncomputable section +open Set Real +open scoped Topology +noncomputable section +open Matrix Set Filter +open scoped Topology Matrix.Norms.Frobenius +noncomputable section +open Matrix NormedSpace ContinuousLinearMap +open scoped Matrix.Norms.Frobenius +noncomputable section +open Matrix +noncomputable section +open MeasureTheory ProbabilityTheory Real Set +open scoped ENNReal NNReal +noncomputable section +open MeasureTheory ProbabilityTheory InformationTheory Real Set +open scoped NNReal ENNReal +noncomputable section +open scoped BigOperators +open MeasureTheory ProbabilityTheory +open Real +noncomputable section +open scoped BigOperators Topology +open Filter Real +namespace SKRatioGaussian +section DiagonalProbability +open MeasureTheory ProbabilityTheory Real Set Filter +variable {ι : Type*} [Fintype ι] [Nonempty ι] + +lemma scaled_diagonal_expected_margin {j A : ℝ} {a : ι → ℝ} + (hj : 0 ≤ j) (ha : ∀ i, 0 ≤ a i) (hA : ∀ i, a i ≤ A) (hA0 : 0 ≤ A) + (hsub : sqrt j*A ≤ 1) : + (∫ g, diagonalProcess (j/(Fintype.card ι:ℝ)) a 1 + ((j/(Fintype.card ι:ℝ))*∑ i, a i) g + ∂gaussianCoordinates (MatrixCoordinates ι)) ≤ + 1-(1-sqrt j*A)^2 + + 2*sqrt A*sqrt (sqrt (2*j^2*A^2/(Fintype.card ι:ℝ))) := by + have h := diagonalProcess_expected_margin (div_nonneg hj (by positivity)) ha hA hA0 + (by norm_num : (0:ℝ) ≤ 1) le_rfl (scaled_sqrt_mean_bound hj ha hA hA0) hsub + exact h.trans (add_le_add_right + (mul_le_mul_of_nonneg_left (sqrt_le_sqrt (sqrt_le_sqrt + (scaled_variance_bound (j := j) ha hA))) (show 0 ≤ 2*sqrt A by positivity)) _) + +theorem scaled_diagonal_path_tail {j A : ℝ} {a : ι → ℝ} + (hj : 0 < j) (hA0 : 0 < A) (ha : ∀ i, 0 ≤ a i) (hA : ∀ i, a i ≤ A) + (hsub : sqrt j*A < 1) + (herr : 2*sqrt A*sqrt (sqrt (2*j^2*A^2/(Fintype.card ι:ℝ))) ≤ + (1-sqrt j*A)^2/4) : + (gaussianCoordinates (MatrixCoordinates ι)).real + {g | ∃ z ∈ Icc (0:ℝ) 1, + 1-(1-sqrt j*A)^2/2 < diagonalProcess (j/(Fintype.card ι:ℝ)) a z + ((j/(Fintype.card ι:ℝ))*∑ i, a i) g} ≤ + Real.exp (-((1-sqrt j*A)^2)^2 * (Fintype.card ι:ℝ) / (16*π^2*j*A^2)) := by + let r := j/(Fintype.card ι:ℝ) + let q := r*∑ i, a i + let δ := (1-sqrt j*A)^2 + let c := 1-δ/2 + let P := diagonalProcess r a 1 q + have hn : 0 < (Fintype.card ι:ℝ) := by exact_mod_cast Fintype.card_pos + have hr : 0 < r := div_pos hj hn + have hq : 0 ≤ q := mul_nonneg hr.le (Finset.sum_nonneg (fun i _ => ha i)) + have hd : 0 < δ := sq_pos_of_pos (sub_pos.mpr hsub) + have hd1 : δ ≤ 1 := by + dsimp [δ] + have hb : 0 ≤ sqrt j*A := by positivity + nlinarith + have hc : 0 ≤ c := by dsimp [c]; linarith + have hqc : q*A ≤ c := scaled_qA_bound hj.le hA hA0.le hsub.le + have hmean : (∫ g, P g ∂gaussianCoordinates (MatrixCoordinates ι)) ≤ 1-3*δ/4 := by + have h := scaled_diagonal_expected_margin hj.le ha hA hA0.le hsub.le + change (∫ g, P g ∂gaussianCoordinates (MatrixCoordinates ι)) ≤ 1-δ+_ at h + change _ ≤ δ/4 at herr + linarith + have hlip := diagonalProcess_lipschitz hr.le ha hA hA0.le (by norm_num : (0:ℝ) ≤ 1) q + have hL : 0 < Real.toNNReal (1*sqrt (2*r)*A) := by + rw [Real.toNNReal_pos] + positivity + have htail := gaussianProduct_upper_tail_lipschitz hlip hL (show 0 ≤ δ/4 by positivity) + have hset : {g | ∃ z ∈ Icc (0:ℝ) 1, c < diagonalProcess r a z q g} ⊆ + {g | δ/4 ≤ P g - ∫ y, P y ∂gaussianCoordinates (MatrixCoordinates ι)} := by + rintro g ⟨z, hz, hg⟩ + have hgc : c < P g := by + by_contra h + have hpath := diagonalProcess_path_le ha hA hA0.le hq hc hqc + (le_of_not_gt h) hz.1 hz.2 + exact (not_lt_of_ge hpath) hg + change δ/4 ≤ _ + dsimp [c] at hgc + linarith + refine (measureReal_mono hset).trans (htail.trans_eq ?_) + congr 1 + rw [Real.coe_toNNReal _ (by positivity)] + have hs : (sqrt (2*r))^2 = 2*r := sq_sqrt (by positivity) + simp only [one_mul] + rw [mul_pow, hs] + dsimp [δ, r] + field_simp + ring + +theorem exists_uniform_diagonal_cutoff {j A : ℝ} (hsub : sqrt j*A < 1) : + ∃ n₀ : ℕ, ∀ n ≥ n₀, + 2*sqrt A*sqrt (sqrt (2*j^2*A^2/(n:ℝ))) ≤ (1-sqrt j*A)^2/4 := by + have hpos : 0 < (1-sqrt j*A)^2/4 := by positivity + have h := (diagonal_error_tendsto j A).eventually (gt_mem_nhds hpos) + obtain ⟨n₀, hn⟩ := eventually_atTop.mp h + exact ⟨n₀, fun n hn' => (hn n hn').le⟩ + +end DiagonalProbability +end SKRatioGaussian + +end +end +end +end +end +end +end +end +end +end +end +end +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Matrices/Spin.lean b/lean/OAI/Probability/SKRatio/Matrices/Spin.lean new file mode 100644 index 0000000000000000000000000000000000000000..544d999580207be58a9a7366786d43d0de00c529 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Matrices/Spin.lean @@ -0,0 +1,216 @@ +import Mathlib + +namespace OAI + +section +noncomputable section +open scoped BigOperators +open MeasureTheory ProbabilityTheory Filter + +namespace SKRatioGaussian + +abbrev Spin (n : ℕ) := Fin n → Bool +abbrev Edge (n : ℕ) := {p : Fin n × Fin n // p.1 < p.2} +abbrev Disorder (n : ℕ) := Edge n → ℝ + +def spinValue (b : Bool) : ℝ := if b then 1 else -1 + +def coupling {n : ℕ} (g : Disorder n) (i k : Fin n) : ℝ := + if h : i < k then g ⟨(i, k), h⟩ else + if h : k < i then g ⟨(k, i), h⟩ else 0 + +def hamiltonian {n : ℕ} (g : Disorder n) (h : Fin n → ℝ) (x : Spin n) : ℝ := + (1 / 2 : ℝ) * ∑ i, ∑ k, spinValue (x i) * coupling g i k * spinValue (x k) + + ∑ i, h i * spinValue (x i) + +def weight {n : ℕ} (g : Disorder n) (h : Fin n → ℝ) (x : Spin n) : ℝ := + Real.exp (hamiltonian g h x) + +def partition {n : ℕ} (g : Disorder n) (h : Fin n → ℝ) : ℝ := + ∑ x, weight g h x + +def mass {n : ℕ} (g : Disorder n) (h : Fin n → ℝ) (x : Spin n) : ℝ := + weight g h x / partition g h + +def expectation {n : ℕ} (g : Disorder n) (h : Fin n → ℝ) (f : Spin n → ℝ) : ℝ := + ∑ x, mass g h x * f x + +def variance {n : ℕ} (g : Disorder n) (h : Fin n → ℝ) (f : Spin n → ℝ) : ℝ := + expectation g h (fun x => (f x - expectation g h f) ^ 2) + +def flip {n : ℕ} (i : Fin n) (x : Spin n) : Spin n := + Function.update x i (!(x i)) + +def conditionalExpectation {n : ℕ} (g : Disorder n) (h : Fin n → ℝ) + (i : Fin n) (f : Spin n → ℝ) (x : Spin n) : ℝ := + (weight g h x * f x + weight g h (flip i x) * f (flip i x)) / + (weight g h x + weight g h (flip i x)) + +def dirichlet {n : ℕ} (g : Disorder n) (h : Fin n → ℝ) (f : Spin n → ℝ) : ℝ := + ∑ i, expectation g h (fun x => (f x - conditionalExpectation g h i f x) ^ 2) + +def disorderLaw (β : ℝ) (n : ℕ) : Measure (Disorder n) := + Measure.pi (fun _ : Edge n => gaussianReal 0 (Real.toNNReal (β ^ 2 / n))) + +def poincareEvent (n : ℕ) (C : ℝ) : Set (Disorder n) := + {g | ∀ f : Spin n → ℝ, variance g 0 f ≤ C * dirichlet g 0 f} + +def discreteGap {n : ℕ} (g : Disorder n) : ℝ := + sInf {r : ℝ | ∃ f : Spin n → ℝ, 0 < variance g 0 f ∧ + r = dirichlet g 0 f / ((n : ℝ) * variance g 0 f)} + +def MainStatement (β : ℝ) : Prop := + ∃ C : ℝ, 0 < C ∧ + Tendsto (fun n : ℕ => disorderLaw β n (poincareEvent n C)) atTop (nhds 1) ∧ + Tendsto (fun n : ℕ => disorderLaw β n {g | 1 / (C * (n : ℝ)) ≤ discreteGap g}) + atTop (nhds 1) + +section FiniteSpinCalculus + +variable {n : ℕ} + +@[simp] theorem spinValue_true : spinValue true = 1 := rfl +@[simp] theorem spinValue_false : spinValue false = -1 := rfl +@[simp] theorem spinValue_not (b : Bool) : spinValue (!b) = -spinValue b := by + cases b <;> norm_num [spinValue] +@[simp] theorem spinValue_sq (b : Bool) : spinValue b ^ 2 = 1 := by + cases b <;> norm_num [spinValue] + +@[simp] theorem coupling_diag (g : Disorder n) (i : Fin n) : coupling g i i = 0 := by + simp [coupling] + +theorem coupling_symm (g : Disorder n) (i k : Fin n) : coupling g i k = coupling g k i := by + rcases lt_trichotomy i k with hik | rfl | hki + · simp [coupling, hik, not_lt_of_gt hik] + · rfl + · simp [coupling, hki, not_lt_of_gt hki] + +@[simp] theorem flip_same (i : Fin n) (x : Spin n) : flip i x i = !(x i) := by + simp [flip] + +@[simp] theorem flip_other (i k : Fin n) (x : Spin n) (h : k ≠ i) : flip i x k = x k := by + simp [flip, h] + +@[simp] theorem flip_flip (i : Fin n) (x : Spin n) : flip i (flip i x) = x := by + ext k + by_cases h : k = i + · subst k; simp + · simp [flip_other, h] + +def flipEquiv (i : Fin n) : Spin n ≃ Spin n := + Function.Involutive.toPerm (flip i) (flip_flip i) + +theorem sum_flip (i : Fin n) (f : Spin n → ℝ) : ∑ x, f (flip i x) = ∑ x, f x := + (flipEquiv i).sum_comp f + +theorem weight_pos (g : Disorder n) (h : Fin n → ℝ) (x : Spin n) : + 0 < weight g h x := Real.exp_pos _ + +theorem partition_pos (g : Disorder n) (h : Fin n → ℝ) : 0 < partition g h := by + exact Finset.sum_pos (fun x _ => weight_pos g h x) Finset.univ_nonempty + +theorem mass_pos (g : Disorder n) (h : Fin n → ℝ) (x : Spin n) : + 0 < mass g h x := div_pos (weight_pos g h x) (partition_pos g h) + +theorem mass_nonneg (g : Disorder n) (h : Fin n → ℝ) (x : Spin n) : + 0 ≤ mass g h x := (mass_pos g h x).le + +@[simp] theorem sum_mass (g : Disorder n) (h : Fin n → ℝ) : ∑ x, mass g h x = 1 := by + simp only [mass, ← Finset.sum_div] + exact div_self (ne_of_gt (partition_pos g h)) + +@[simp] theorem expectation_const (g : Disorder n) (h : Fin n → ℝ) (c : ℝ) : + expectation g h (fun _ => c) = c := by + simp [expectation, ← Finset.sum_mul] + +theorem expectation_add (g : Disorder n) (h : Fin n → ℝ) (f k : Spin n → ℝ) : + expectation g h (fun x => f x + k x) = expectation g h f + expectation g h k := by + simp [expectation, mul_add, Finset.sum_add_distrib] + +theorem expectation_sub (g : Disorder n) (h : Fin n → ℝ) (f k : Spin n → ℝ) : + expectation g h (fun x => f x - k x) = expectation g h f - expectation g h k := by + simp [expectation, mul_sub, Finset.sum_sub_distrib] + +theorem expectation_mul_const (g : Disorder n) (h : Fin n → ℝ) (f : Spin n → ℝ) (c : ℝ) : + expectation g h (fun x => f x * c) = expectation g h f * c := by + simp only [expectation, Finset.sum_mul, mul_assoc] + +theorem expectation_const_mul (g : Disorder n) (h : Fin n → ℝ) (f : Spin n → ℝ) (c : ℝ) : + expectation g h (fun x => c * f x) = c * expectation g h f := by + simp only [mul_comm c, expectation_mul_const] + +theorem expectation_nonneg (g : Disorder n) (h : Fin n → ℝ) {f : Spin n → ℝ} + (hf : ∀ x, 0 ≤ f x) : 0 ≤ expectation g h f := + Finset.sum_nonneg (fun x _ => mul_nonneg (mass_nonneg g h x) (hf x)) + +theorem variance_nonneg (g : Disorder n) (h : Fin n → ℝ) (f : Spin n → ℝ) : + 0 ≤ variance g h f := expectation_nonneg g h (fun _ => sq_nonneg _) + +theorem dirichlet_nonneg (g : Disorder n) (h : Fin n → ℝ) (f : Spin n → ℝ) : + 0 ≤ dirichlet g h f := + Finset.sum_nonneg (fun _ _ => expectation_nonneg g h (fun _ => sq_nonneg _)) + +theorem variance_eq_zero_iff (g : Disorder n) (h : Fin n → ℝ) (f : Spin n → ℝ) : + variance g h f = 0 ↔ ∀ x, f x = expectation g h f := by + unfold variance expectation + rw [Finset.sum_eq_zero_iff_of_nonneg (fun x _ => + mul_nonneg (mass_nonneg g h x) (sq_nonneg _))] + simp only [Finset.mem_univ, true_implies, mul_eq_zero, ne_of_gt (mass_pos g h _), + false_or, sq_eq_zero_iff, sub_eq_zero] + +theorem variance_pos_of_ne (g : Disorder n) (h : Fin n → ℝ) {f : Spin n → ℝ} + {x y : Spin n} (hxy : f x ≠ f y) : 0 < variance g h f := by + refine lt_of_le_of_ne (variance_nonneg g h f) ?_ + intro heq + have hf := (variance_eq_zero_iff g h f).mp heq.symm + exact hxy ((hf x).trans (hf y).symm) + +theorem exists_positive_variance (g : Disorder n) (hn : 0 < n) : + ∃ f : Spin n → ℝ, 0 < variance g 0 f := by + let i : Fin n := ⟨0, hn⟩ + refine ⟨fun x => spinValue (x i), variance_pos_of_ne g 0 (x := fun _ => true) + (y := fun _ => false) ?_⟩ + norm_num + +theorem lower_bound_discreteGap (g : Disorder n) (hn : 0 < n) {C : ℝ} (hC : 0 < C) + (hP : ∀ f : Spin n → ℝ, variance g 0 f ≤ C * dirichlet g 0 f) : + 1 / (C * (n : ℝ)) ≤ discreteGap g := by + obtain ⟨f, hf⟩ := exists_positive_variance g hn + apply le_csInf + · exact ⟨_, f, hf, rfl⟩ + · rintro r ⟨f, hv, rfl⟩ + have hn' : 0 < (n : ℝ) := Nat.cast_pos.mpr hn + apply (div_le_div_iff₀ (mul_pos hC hn') (mul_pos hn' hv)).mpr + nlinarith [mul_le_mul_of_nonneg_left (hP f) hn'.le] + +instance disorderLaw_probability (β : ℝ) (n : ℕ) : IsProbabilityMeasure (disorderLaw β n) := by + unfold disorderLaw + infer_instance + +theorem gap_probability_of_poincare (β C : ℝ) (hC : 0 < C) + (hP : Tendsto (fun n : ℕ => disorderLaw β n (poincareEvent n C)) atTop (nhds 1)) : + Tendsto (fun n : ℕ => disorderLaw β n {g | 1 / (C * (n : ℝ)) ≤ discreteGap g}) + atTop (nhds 1) := by + apply tendsto_of_tendsto_of_tendsto_of_le_of_le' hP tendsto_const_nhds + · filter_upwards [eventually_gt_atTop (0 : ℕ)] with n hn + apply measure_mono + intro g hg + exact lower_bound_discreteGap g hn hC hg + · filter_upwards [] with n + exact (measure_mono (Set.subset_univ _)).trans_eq (measure_univ) + +end FiniteSpinCalculus + +end SKRatioGaussian + +end + +section + +noncomputable section + +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Matrices/StandardGaussianProduct.lean b/lean/OAI/Probability/SKRatio/Matrices/StandardGaussianProduct.lean new file mode 100644 index 0000000000000000000000000000000000000000..8394acfe1bba6ede16f331ae97602176034fd484 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Matrices/StandardGaussianProduct.lean @@ -0,0 +1,134 @@ +import Mathlib + +namespace OAI + +section +section +noncomputable section +open MeasureTheory ProbabilityTheory InformationTheory Real Set +open scoped NNReal ENNReal +namespace SKRatioGaussian + +theorem hasDerivAt_gaussianPDFReal (d : ℝ) {s : ℝ≥0} (hs : s ≠ 0) (y : ℝ) : + HasDerivAt (gaussianPDFReal d s) + (-(y - d) / (s : ℝ) * gaussianPDFReal d s y) y := by + have hsp : 0 < (s : ℝ) := NNReal.coe_pos.mpr (pos_iff_ne_zero.mpr hs) + unfold gaussianPDFReal + convert! (((((hasDerivAt_id y).sub_const d).pow 2).neg.div_const + (2 * (s : ℝ))).exp).const_mul (1 / sqrt (2 * π * (s : ℝ))) using 1 + · ext x + simp only [one_div, Pi.neg_apply, Pi.pow_apply, id_eq] + · simp only [Pi.neg_apply, Pi.pow_apply, id_eq] + norm_num + ring + +theorem integrable_gaussian_iff {d : ℝ} {s : ℝ≥0} (hs : s ≠ 0) {f : ℝ → ℝ} : + Integrable f (gaussianReal d s) ↔ Integrable (fun y => gaussianPDFReal d s y * f y) := by + rw [gaussianReal_of_var_ne_zero d hs, + integrable_withDensity_iff_integrable_smul' (measurable_gaussianPDF d s) + (ae_of_all _ (fun _ => gaussianPDF_lt_top))] + simp only [toReal_gaussianPDF, smul_eq_mul] + +theorem gaussian_integration_by_parts {d : ℝ} {s : ℝ≥0} (hs : s ≠ 0) + {f f' : ℝ → ℝ} (hd : ∀ y, HasDerivAt f (f' y) y) + (hf : Integrable f (gaussianReal d s)) (hf' : Integrable f' (gaussianReal d s)) + (hyf : Integrable (fun y => (y - d) * f y) (gaussianReal d s)) : + (∫ y, (y - d) * f y ∂gaussianReal d s) = + (s : ℝ) * (∫ y, f' y ∂gaussianReal d s) := by + have hsp : 0 < (s : ℝ) := NNReal.coe_pos.mpr (pos_iff_ne_zero.mpr hs) + have hfg := (integrable_gaussian_iff hs).mp hf + have hf'g := (integrable_gaussian_iff hs).mp hf' + have hyfg := (integrable_gaussian_iff hs).mp hyf + have hder (y : ℝ) : HasDerivAt (fun y => gaussianPDFReal d s y * f y) + (gaussianPDFReal d s y * f' y - + (gaussianPDFReal d s y * ((y - d) * f y)) / (s : ℝ)) y := by + convert! (hasDerivAt_gaussianPDFReal d hs y).mul (hd y) using 1 + ring + have hii : Integrable (fun y => gaussianPDFReal d s y * f' y - + (gaussianPDFReal d s y * ((y - d) * f y)) / (s : ℝ)) := + hf'g.sub (hyfg.div_const _) + have hz := integral_eq_zero_of_hasDerivAt_of_integrable hder hii hfg + rw [integral_sub hf'g (hyfg.div_const (s : ℝ)), integral_div] at hz + rw [integral_gaussianReal_eq_integral_smul hs, + integral_gaussianReal_eq_integral_smul hs] + simp only [smul_eq_mul] + have he : (∫ y, gaussianPDFReal d s y * ((y - d) * f y)) / (s : ℝ) = + ∫ y, gaussianPDFReal d s y * f' y := by linarith + have hm := (div_eq_iff hsp.ne').mp he + nlinarith only [hm] + +def standardGaussianProduct (n : ℕ) : Measure (Fin n → ℝ) := + Measure.pi (fun _ => gaussianReal 0 1) + +instance (n : ℕ) : IsProbabilityMeasure (standardGaussianProduct n) := by + unfold standardGaussianProduct + infer_instance + +theorem continuous_insertNth {n : ℕ} (i : Fin (n + 1)) (u : Fin n → ℝ) : + Continuous (fun z : ℝ => i.insertNth (α := fun _ => ℝ) z u) := by + apply continuous_pi + refine i.forall_iff_succAbove.mpr ⟨?_, ?_⟩ + · simp only [Fin.insertNth_apply_same] + convert! (continuous_id : Continuous (fun x : ℝ => x)) using 1 + · intro k + simpa only [Fin.insertNth_apply_succAbove] using + (continuous_const : Continuous (fun _ : ℝ => u k)) + +theorem gaussianProduct_coordinate_IBP {n : ℕ} (i : Fin (n + 1)) + {f df : (Fin (n + 1) → ℝ) → ℝ} {C D : ℝ} + (hf : Continuous f) (hdf : Continuous df) + (hfbound : ∀ x, ‖f x‖ ≤ C) (hdfbound : ∀ x, ‖df x‖ ≤ D) + (hder : ∀ (u : Fin n → ℝ) (z : ℝ), + HasDerivAt (fun z => f (i.insertNth z u)) (df (i.insertNth z u)) z) : + (∫ x, x i * f x ∂standardGaussianProduct (n + 1)) = + ∫ x, df x ∂standardGaussianProduct (n + 1) := by + let e := MeasurableEquiv.piFinSuccAbove (fun _ : Fin (n + 1) => ℝ) i + have hp : MeasurePreserving e.symm + ((gaussianReal 0 1).prod (standardGaussianProduct n)) + (standardGaussianProduct (n + 1)) := + (measurePreserving_piFinSuccAbove (fun _ => gaussianReal 0 1) i).symm + have hi : Integrable (fun x : Fin (n + 1) → ℝ => x i * f x) + (standardGaussianProduct (n + 1)) := by + simpa only [mul_comm, standardGaussianProduct] using + (integrable_eval (i := i) IsGaussian.integrable_id).bdd_mul + hf.aestronglyMeasurable (ae_of_all _ hfbound) + have hi' : Integrable df (standardGaussianProduct (n + 1)) := + Integrable.of_bound hdf.aestronglyMeasurable D (ae_of_all _ hdfbound) + have hsplit (g : (Fin (n + 1) → ℝ) → ℝ) + (hg : Integrable g (standardGaussianProduct (n + 1))) : + (∫ x, g x ∂standardGaussianProduct (n + 1)) = + ∫ u, ∫ z, g (i.insertNth z u) ∂gaussianReal 0 1 ∂standardGaussianProduct n := by + have hi2 : Integrable (fun x => g (e.symm x)) + ((gaussianReal 0 1).prod (standardGaussianProduct n)) := + hp.integrable_comp_of_integrable hg + rw [← hp.integral_comp' g, integral_prod _ hi2] + rw [integral_integral_swap hi2] + rfl + rw [hsplit _ hi, hsplit _ hi'] + apply integral_congr_ae + filter_upwards [] with u + simp only [Fin.insertNth_apply_same] + have hfu : Integrable (fun z => f (i.insertNth z u)) (gaussianReal 0 1) := + Integrable.of_bound (hf.comp (continuous_insertNth i u)).aestronglyMeasurable C + (ae_of_all _ (fun z => hfbound _)) + have hdfu : Integrable (fun z => df (i.insertNth z u)) (gaussianReal 0 1) := + Integrable.of_bound (hdf.comp (continuous_insertNth i u)).aestronglyMeasurable D + (ae_of_all _ (fun z => hdfbound _)) + have hzfu : Integrable (fun z => z * f (i.insertNth z u)) (gaussianReal 0 1) := by + simpa only [mul_comm, id_eq, Function.comp_def] using (IsGaussian.integrable_id (μ := gaussianReal 0 1)).bdd_mul + (hf.comp (continuous_insertNth i u)).aestronglyMeasurable + (ae_of_all _ (fun z => hfbound _)) + simpa only [NNReal.coe_one, sub_zero, one_mul] using + gaussian_integration_by_parts (d := 0) (s := 1) one_ne_zero (hder u) hfu hdfu + (by simpa only [sub_zero] using hzfu) + +end SKRatioGaussian + +open Filter +open scoped Topology + +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Matrices/StdGaussianMgfLipschitz.lean b/lean/OAI/Probability/SKRatio/Matrices/StdGaussianMgfLipschitz.lean new file mode 100644 index 0000000000000000000000000000000000000000..5a6448a73b20c365050e54102a47f161c7da05b0 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Matrices/StdGaussianMgfLipschitz.lean @@ -0,0 +1,125 @@ +import Mathlib +import OAI.Probability.SKRatio.Matrices.LipschitzNormedConvolution + +namespace OAI + +section +section +noncomputable section +open MeasureTheory ProbabilityTheory InformationTheory Real Set +open scoped NNReal ENNReal +open Filter +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius ENNReal NNReal +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius NNReal +noncomputable section +open MeasureTheory ProbabilityTheory Real Set Filter +open MeasureTheory.Measure +open scoped ENNReal NNReal MeasureTheory Topology +namespace SKRatioGaussian +section StandardGaussianRotation +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] + [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] + +theorem stdGaussian_mgf_lipschitz_le {f : E → ℝ} {L : ℝ≥0} + (hf : LipschitzWith L f) (r : ℝ) : + (∫ x, exp (r * (f x - ∫ y, f y ∂stdGaussian E)) ∂stdGaussian E) ≤ + exp (π ^ 2 * r ^ 2 * (L : ℝ) ^ 2 / 8) := by + have hε (ε : ℝ) (hε : 0 < ε) : + (∫ x, exp (r * (f x - ∫ y, f y ∂stdGaussian E)) ∂stdGaussian E) ≤ + exp (2 * |r| * ((L : ℝ) * ε)) * exp (π ^ 2 * r ^ 2 * (L : ℝ) ^ 2 / 8) := by + obtain ⟨g, hgs, hgl, hgf⟩ := exists_smooth_lipschitz_approx hf hε + have hmg := stdGaussian_mgf_centered_le + (fun x => (hgs.differentiable (by simp) x).hasFDerivAt) + (hgs.continuous_fderiv (by simp)) (fun _ => norm_fderiv_le_of_lipschitz ℝ hgl) r + exact (centered_mgf_le_of_uniform_dist hf hgl + (fun x => by simpa only [dist_comm] using hgf x) r).trans + (mul_le_mul_of_nonneg_left hmg (exp_pos _).le) + have ht : Tendsto (fun ε : ℝ => exp (2 * |r| * ((L : ℝ) * ε)) * + exp (π ^ 2 * r ^ 2 * (L : ℝ) ^ 2 / 8)) (𝓝[>] 0) + (𝓝 (exp (π ^ 2 * r ^ 2 * (L : ℝ) ^ 2 / 8))) := by + have hc : Continuous (fun ε : ℝ => exp (2 * |r| * ((L : ℝ) * ε)) * + exp (π ^ 2 * r ^ 2 * (L : ℝ) ^ 2 / 8)) := by fun_prop + simpa using ((hc.tendsto 0).mono_left (nhdsWithin_le_nhds (s := Ioi (0 : ℝ)))) + apply ge_of_tendsto ht + filter_upwards [self_mem_nhdsWithin] with ε heps + exact hε ε heps + +theorem stdGaussian_upper_tail_lipschitz {f : E → ℝ} {L : ℝ≥0} + (hf : LipschitzWith L f) (hL : 0 < L) {u : ℝ} (hu : 0 ≤ u) : + (stdGaussian E).real {x | u ≤ f x - ∫ y, f y ∂stdGaussian E} ≤ + exp (-2 * u ^ 2 / (π ^ 2 * (L : ℝ) ^ 2)) := by + let t : ℝ := 4 * u / (π ^ 2 * (L : ℝ) ^ 2) + have hLr : 0 < (L : ℝ) := hL + have hden : 0 < π ^ 2 * (L : ℝ) ^ 2 := mul_pos (sq_pos_of_pos pi_pos) (sq_pos_of_pos hLr) + have ht : 0 ≤ t := div_nonneg (mul_nonneg (by norm_num) hu) hden.le + have hi : Integrable (fun x => exp (t * (f x - ∫ y, f y ∂stdGaussian E))) + (stdGaussian E) := by + simp_rw [exp_mul_sub] + exact (gaussian_integrable_exp_lipschitz hf t).const_mul _ + calc + _ ≤ exp (-t * u) * ∫ x, exp (t * (f x - ∫ y, f y ∂stdGaussian E)) + ∂stdGaussian E := measure_ge_le_exp_mul_mgf u ht hi + _ ≤ exp (-t * u) * exp (π ^ 2 * t ^ 2 * (L : ℝ) ^ 2 / 8) := + mul_le_mul_of_nonneg_left (stdGaussian_mgf_lipschitz_le hf t) (exp_pos _).le + _ = exp (-2 * u ^ 2 / (π ^ 2 * (L : ℝ) ^ 2)) := by + rw [← exp_add] + congr 1 + dsimp [t] + field_simp + ring + +theorem stdGaussian_lower_tail_lipschitz {f : E → ℝ} {L : ℝ≥0} + (hf : LipschitzWith L f) (hL : 0 < L) {u : ℝ} (hu : 0 ≤ u) : + (stdGaussian E).real {x | f x - ∫ y, f y ∂stdGaussian E ≤ -u} ≤ + exp (-2 * u ^ 2 / (π ^ 2 * (L : ℝ) ^ 2)) := by + have h := stdGaussian_upper_tail_lipschitz hf.neg hL hu + have he : {x | (fun x => -f x) x - ∫ y, -f y ∂stdGaussian E ≥ u} = + {x | f x - ∫ y, f y ∂stdGaussian E ≤ -u} := by + ext x + simp only [mem_ofPred_eq, integral_neg] + constructor <;> intro hx <;> linarith + simp only [Pi.neg_apply] at h + rw [he] at h + exact h + +theorem stdGaussian_tail_lipschitz {f : E → ℝ} {L : ℝ≥0} + (hf : LipschitzWith L f) (hL : 0 < L) {u : ℝ} (hu : 0 ≤ u) : + (stdGaussian E).real {x | u ≤ |f x - ∫ y, f y ∂stdGaussian E|} ≤ + 2 * exp (-2 * u ^ 2 / (π ^ 2 * (L : ℝ) ^ 2)) := by + have he : {x | u ≤ |f x - ∫ y, f y ∂stdGaussian E|} = + {x | u ≤ f x - ∫ y, f y ∂stdGaussian E} ∪ + {x | f x - ∫ y, f y ∂stdGaussian E ≤ -u} := by + ext x + simp only [mem_union, mem_ofPred_eq, le_abs] + constructor <;> rintro (hx | hx) + · exact Or.inl hx + · right; linarith + · exact Or.inl hx + · right; linarith + rw [he] + calc + _ ≤ (stdGaussian E).real {x | u ≤ f x - ∫ y, f y ∂stdGaussian E} + + (stdGaussian E).real {x | f x - ∫ y, f y ∂stdGaussian E ≤ -u} := + measureReal_union_le _ _ + _ ≤ exp (-2 * u ^ 2 / (π ^ 2 * (L : ℝ) ^ 2)) + + exp (-2 * u ^ 2 / (π ^ 2 * (L : ℝ) ^ 2)) := + add_le_add (stdGaussian_upper_tail_lipschitz hf hL hu) + (stdGaussian_lower_tail_lipschitz hf hL hu) + _ = _ := by ring + +end StandardGaussianRotation +end SKRatioGaussian + +end +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Matrices/SymmetricElementaryComm.lean b/lean/OAI/Probability/SKRatio/Matrices/SymmetricElementaryComm.lean new file mode 100644 index 0000000000000000000000000000000000000000..2b6149246ba14119e6901db82760b78cc12d4349 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Matrices/SymmetricElementaryComm.lean @@ -0,0 +1,99 @@ +import Mathlib +import OAI.Probability.SKRatio.Matrices.GaussianFiniteIBPError +import OAI.Probability.SKRatio.Matrices.MatrixCoordinates + +namespace OAI + +section +section +noncomputable section +open MeasureTheory ProbabilityTheory InformationTheory Real Set +open scoped NNReal ENNReal +open Filter +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius ENNReal NNReal +namespace SKRatioGaussian +open MeasureTheory ProbabilityTheory +open scoped ENNReal NNReal +variable {ι : Type*} [Fintype ι] [DecidableEq ι] + +omit [Fintype ι] in +lemma symmetricElementary_comm (a b : ι) : symmetricElementary a b = symmetricElementary b a := + add_comm _ _ + +omit [Fintype ι] in +lemma goeMatrix_updated_observable_derivative {r : ℝ} + {H : Matrix ι ι ℝ → ℝ} {g : MatrixCoordinates ι → ℝ} {a b : ι} {d : ℝ} + (hd : HasDerivAt (fun t : ℝ => H (goeMatrix r g+t • symmetricElementary a b)) d 0) : + HasDerivAt (fun t => H (goeMatrix r (Function.update g (.inl (a,b)) t))) + ((sqrt (2*r)/2)*d) (g (.inl (a,b))) := by + have ha := ((hasDerivAt_id (g (.inl (a,b)))).sub_const (g (.inl (a,b)))).const_mul (sqrt (2*r)/2) + have ho : HasDerivAt (fun t : ℝ => H (goeMatrix r g+t • symmetricElementary a b)) d + ((fun y : ℝ => (sqrt (2*r)/2)*(y-g (.inl (a,b)))) (g (.inl (a,b)))) := by simpa using hd + have hh := ho.comp (g (.inl (a,b))) ha + simpa only [Function.comp_def,goeMatrix_update,mul_one,one_mul,mul_comm,id_eq] using! hh + +theorem goe_IBP_error {r : ℝ} (hr : 0 ≤ r) (a b : ι) + {H : Matrix ι ι ℝ → ℝ} {d : (MatrixCoordinates ι → ℝ) → ℝ} + {L : ℝ≥0} {C D : ℝ} {s : Set (MatrixCoordinates ι → ℝ)} + (hf : LipschitzWith L (fun g => H (goeMatrix r g))) + (hC : ∀ g, ‖H (goeMatrix r g)‖ ≤ C) + (hd : Measurable d) (hD : ∀ g, ‖d g‖ ≤ D) (hs : MeasurableSet s) + (hder : ∀ g ∈ s, HasDerivAt (fun t : ℝ => H (goeMatrix r g+t • symmetricElementary a b)) (d g) 0) : + |(∫ g, goeMatrix r g a b * H (goeMatrix r g) + ∂Measure.pi (fun _ : MatrixCoordinates ι => gaussianReal 0 1)) - + r*(∫ g, d g ∂Measure.pi (fun _ : MatrixCoordinates ι => gaussianReal 0 1))| ≤ + (sqrt (2*r)*(L:ℝ)+r*D)* + (Measure.pi (fun _ : MatrixCoordinates ι => gaussianReal 0 1)).real sᶜ := by + let μ := Measure.pi (fun _ : MatrixCoordinates ι => gaussianReal 0 1) + let c : ℝ := sqrt (2*r)/2 + have hc : 0 ≤ c := by dsimp [c]; positivity + have hc2 : 2*c^2 = r := by + dsimp [c]; rw [div_pow,Real.sq_sqrt (by positivity)]; ring + have hD' : ∀ g, ‖c*d g‖ ≤ c*D := fun g => by + rw [norm_mul,Real.norm_eq_abs,abs_of_nonneg hc] + exact mul_le_mul_of_nonneg_left (hD g) hc + have h₁ := gaussianFinite_IBP_error (.inl (a,b)) hf hC (hd.const_mul c) hD' hs + (fun g hg => goeMatrix_updated_observable_derivative (hder g hg)) + have h₂ := gaussianFinite_IBP_error (.inl (b,a)) hf hC (hd.const_mul c) hD' hs + (fun g hg => goeMatrix_updated_observable_derivative (by + simpa only [symmetricElementary_comm b a] using hder g hg)) + rw [integral_const_mul] at h₁ h₂ + have hi (i : MatrixCoordinates ι) : Integrable (fun g : MatrixCoordinates ι → ℝ => + g i*H (goeMatrix r g)) μ := by + simpa only [mul_comm] using (integrable_eval (i := i) IsGaussian.integrable_id).bdd_mul + hf.continuous.aestronglyMeasurable (ae_of_all _ hC) + have he : (∫ g, goeMatrix r g a b*H (goeMatrix r g) ∂μ) = + c*((∫ g, g (.inl (a,b))*H (goeMatrix r g) ∂μ)+ + ∫ g, g (.inl (b,a))*H (goeMatrix r g) ∂μ) := by + simp_rw [goeMatrix,mul_assoc,add_mul] + rw [integral_const_mul,integral_add (hi _) (hi _)] + change |(∫ g, goeMatrix r g a b*H (goeMatrix r g) ∂μ)-r*(∫ g, d g ∂μ)| ≤ _ + rw [he] + have he' : c*((∫ g, g (.inl (a,b))*H (goeMatrix r g) ∂μ)+ + ∫ g, g (.inl (b,a))*H (goeMatrix r g) ∂μ)-r*(∫ g, d g ∂μ) = + c*(((∫ g, g (.inl (a,b))*H (goeMatrix r g) ∂μ)-c*(∫ g, d g ∂μ))+ + ((∫ g, g (.inl (b,a))*H (goeMatrix r g) ∂μ)-c*(∫ g, d g ∂μ))) := by + rw [← hc2]; ring + rw [he',abs_mul,abs_of_nonneg hc] + calc + _ ≤ c*(|((∫ g, g (.inl (a,b))*H (goeMatrix r g) ∂μ)-c*(∫ g, d g ∂μ))|+ + |((∫ g, g (.inl (b,a))*H (goeMatrix r g) ∂μ)-c*(∫ g, d g ∂μ))|) := + mul_le_mul_of_nonneg_left (abs_add_le _ _) hc + _ ≤ c*(((L:ℝ)+c*D)*μ.real sᶜ+((L:ℝ)+c*D)*μ.real sᶜ) := + mul_le_mul_of_nonneg_left (add_le_add h₁ h₂) hc + _ = _ := by + change _ = (sqrt (2*r)*(L:ℝ)+r*D)*μ.real sᶜ + have hec : sqrt (2*r) = 2*c := by dsimp [c]; ring + rw [hec,← hc2]; ring + +end SKRatioGaussian + +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Matrices/TendstoGaussianPDFRealTop.lean b/lean/OAI/Probability/SKRatio/Matrices/TendstoGaussianPDFRealTop.lean new file mode 100644 index 0000000000000000000000000000000000000000..3bc8e8aaa7c03027ef0f37b131ac2dd46ff2e9f4 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Matrices/TendstoGaussianPDFRealTop.lean @@ -0,0 +1,95 @@ +import Mathlib +import OAI.Probability.SKRatio.Matrices.StandardGaussianProduct + +namespace OAI + +section +section +noncomputable section +open MeasureTheory ProbabilityTheory InformationTheory Real Set +open scoped NNReal ENNReal +open Filter +open scoped Topology +namespace SKRatioGaussian +lemma tendsto_gaussianPDFReal_atTop (d : ℝ) {s : ℝ≥0} (hs : 0 < s) : + Filter.Tendsto (gaussianPDFReal d s) Filter.atTop (𝓝 0) := by + have hsp : (0:ℝ) < s := hs + have hshift : Tendsto (fun x : ℝ => x-d) atTop atTop := by + apply tendsto_atTop.2 + intro b + filter_upwards [eventually_ge_atTop (b+d)] with x hx + linarith + have hpow : Filter.Tendsto (fun x : ℝ => (x-d)^2) Filter.atTop Filter.atTop := + (tendsto_pow_atTop (by norm_num : (2:ℕ) ≠ 0)).comp hshift + have hexp := Real.tendsto_exp_neg_atTop_nhds_zero.comp (hpow.atTop_div_const (by positivity : 0 < 2*(s:ℝ))) + rw [gaussianPDFReal_def] + simpa only [neg_div, mul_zero,one_div,Function.comp_apply] using hexp.const_mul (1/sqrt (2*Real.pi*(s:ℝ))) + +lemma tendsto_gaussianPDFReal_neg_atTop (d : ℝ) {s : ℝ≥0} (hs : 0 < s) : + Filter.Tendsto (fun x => gaussianPDFReal d s (-x)) Filter.atTop (𝓝 0) := by + have he : (fun x => gaussianPDFReal d s (-x)) = gaussianPDFReal (-d) s := by + funext x + unfold gaussianPDFReal + congr 2 + ring + rw [he] + exact tendsto_gaussianPDFReal_atTop (-d) hs + +theorem gaussian_lipschitz_IBP {f : ℝ → ℝ} {L : ℝ≥0} {C d : ℝ} {s : ℝ≥0} + (hs : 0 < s) (hL : LipschitzWith L f) (hC : ∀ x, ‖f x‖ ≤ C) : + (∫ y, (y-d)*f y ∂gaussianReal d s) = (s:ℝ)*(∫ y, deriv f y ∂gaussianReal d s) := by + have hC0 : 0 ≤ C := (norm_nonneg (f 0)).trans (hC 0) + have hdf : Integrable (deriv f) (gaussianReal d s) := + Integrable.of_bound (measurable_deriv f).aestronglyMeasurable (L:ℝ) + (ae_of_all _ (fun _ => norm_deriv_le_of_lipschitz hL)) + have hyf : Integrable (fun y => (y-d)*f y) (gaussianReal d s) := by + have hh := ((IsGaussian.integrable_id (μ := gaussianReal d s)).sub (integrable_const d)).bdd_mul + (f := f) hL.continuous.aestronglyMeasurable (ae_of_all _ hC) + simpa only [mul_comm,Pi.sub_apply,id_eq] using hh + let p := gaussianPDFReal d s + have hpi : Integrable (fun y => p y*deriv f y) := (integrable_gaussian_iff hs.ne').mp hdf + have hxi : Integrable (fun y => p y*((y-d)*f y)) := (integrable_gaussian_iff hs.ne').mp hyf + let g : ℝ → ℝ := fun y => p y*deriv f y-(p y*((y-d)*f y))/(s:ℝ) + have hgi : Integrable g := hpi.sub (hxi.div_const _) + have hpd (y : ℝ) : deriv p y = -(y-d)/(s:ℝ)*p y := (hasDerivAt_gaussianPDFReal d hs.ne' y).deriv + have hpac (a b : ℝ) : AbsolutelyContinuousOnInterval p a b := by + apply ContDiffOn.absolutelyContinuousOnInterval + have hh : ContDiff ℝ 1 p := by + change ContDiff ℝ 1 (fun x : ℝ => (sqrt (2 * π * (s : ℝ)))⁻¹ * exp (-(x-d)^2/(2*(s:ℝ)))) + fun_prop + exact hh.contDiffOn + have hfac (a b : ℝ) : AbsolutelyContinuousOnInterval f a b := hL.lipschitzOnWith.absolutelyContinuousOnInterval + have hftc (a b : ℝ) : (∫ y in a..b, g y) = p b*f b-p a*f a := by + rw [← (hpac a b).integral_deriv_mul_eq_sub (hfac a b)] + apply intervalIntegral.integral_congr + intro y _ + dsimp [g] + rw [hpd] + ring + have hbd (u : ℝ → ℝ) (hp : Filter.Tendsto (fun x => p (u x)) Filter.atTop (𝓝 0)) : + Filter.Tendsto (fun x => p (u x)*f (u x)) Filter.atTop (𝓝 0) := by + apply squeeze_zero_norm (fun x => ?_) (by simpa only [zero_mul] using hp.mul_const C) + rw [norm_mul, Real.norm_eq_abs (p (u x)),abs_of_nonneg (gaussianPDFReal_nonneg _ _ _)] + exact mul_le_mul_of_nonneg_left (hC _) (gaussianPDFReal_nonneg _ _ _) + have htop := hbd id (tendsto_gaussianPDFReal_atTop d hs) + have hbot := hbd Neg.neg (tendsto_gaussianPDFReal_neg_atTop d hs) + have hlim := intervalIntegral_tendsto_integral hgi Filter.tendsto_neg_atTop_atBot Filter.tendsto_id + simp only [hftc] at hlim + have hz : (∫ y, g y) = 0 := by + simpa only [id_eq,sub_zero] using tendsto_nhds_unique hlim (htop.sub hbot) + dsimp [g] at hz + rw [integral_sub hpi (hxi.div_const _),integral_div] at hz + rw [integral_gaussianReal_eq_integral_smul hs.ne',integral_gaussianReal_eq_integral_smul hs.ne'] + simp only [smul_eq_mul] + have hh : (∫ y, p y*((y-d)*f y))/(s:ℝ) = ∫ y, p y*deriv f y := by linarith + have hm := (div_eq_iff (ne_of_gt (show (0:ℝ) < s from hs))).mp hh + dsimp [p] at hm + nlinarith only [hm] + +end SKRatioGaussian + +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Matrices/TruncatedG.lean b/lean/OAI/Probability/SKRatio/Matrices/TruncatedG.lean new file mode 100644 index 0000000000000000000000000000000000000000..e7d41b22b19db7d81326aa8da9278ef3d84e1b40 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Matrices/TruncatedG.lean @@ -0,0 +1,108 @@ +import Mathlib +import OAI.Probability.SKRatio.Matrices.LinCLM +import OAI.Probability.SKRatio.Matrices.SandShift +import OAI.Probability.SKRatio.Matrices.Vectorize + +namespace OAI + +section +section +noncomputable section +open MeasureTheory ProbabilityTheory InformationTheory Real Set +open scoped NNReal ENNReal +open Filter +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius ENNReal NNReal +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius NNReal +noncomputable section +open MeasureTheory ProbabilityTheory Real Set Filter +open MeasureTheory.Measure +open scoped ENNReal NNReal MeasureTheory Topology +open MeasureTheory +noncomputable section +noncomputable section +open MeasureTheory Set NormedSpace +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius +noncomputable section +open Set Real +open scoped Topology +namespace SKRatioGaussian.ComplexMatrix +open scoped FourierTransform SchwartzMap +variable {ι : Type*} [Fintype ι] [DecidableEq ι] + +noncomputable def truncatedG (f : 𝓢(ℝ,ℂ)) (R : ℝ) (hR : 0 ≤ R) + (B D M : Matrix ι ι ℂ) : Matrix ι ι ℂ := + D*schwartzMatrix f (sandShift B D (matrixProject R hR M))*D + +lemma matrixProject_sub_norm (R : ℝ) (hR : 0 ≤ R) (M N : Matrix ι ι ℂ) : + ‖matrixProject R hR M-matrixProject R hR N‖ ≤ ‖M-N‖ := by + simpa only [dist_eq_norm,NNReal.coe_one,one_mul] using (matrixProject_lipschitz R hR).dist_le_mul M N + +lemma truncatedG_opNorm (f : 𝓢(ℝ,ℂ)) (R : ℝ) (hR : 0 ≤ R) (B D M : Matrix ι ι ℂ) + (hB : Bᴴ = B) (hD : Dᴴ = D) : + opNorm (truncatedG f R hR B D M) ≤ opNorm D^2*fourierMoment f 0 := by + have hS := sandShift_hermitian B D (matrixProject R hR M) hB hD (matrixProject_bound R hR M).1 + apply (sandwich_opNorm D _).trans + apply mul_le_mul_of_nonneg_left _ (sq_nonneg _) + simpa only [fourierMoment,pow_zero,mul_one] using schwartzMatrix_opNorm f _ hS + +lemma truncatedG_sub_norm (f : 𝓢(ℝ,ℂ)) (R : ℝ) (hR : 0 ≤ R) (B D M N : Matrix ι ι ℂ) + (hB : Bᴴ = B) (hD : Dᴴ = D) : + ‖truncatedG f R hR B D M-truncatedG f R hR B D N‖ ≤ + (2*Real.pi*fourierMoment f 1)*opNorm D^4*‖M-N‖ := by + have hL : 0 ≤ 2*Real.pi*fourierMoment f 1 := by have := fourierMoment_nonneg f 1; positivity + have hM := (matrixProject_bound R hR M).1 + have hN := (matrixProject_bound R hR N).1 + have hl := schwartzMatrix_sandShift_lipschitz f B D (matrixProject R hR M) (matrixProject R hR N) hB hD hM hN + have he : truncatedG f R hR B D M-truncatedG f R hR B D N = + D*(schwartzMatrix f (sandShift B D (matrixProject R hR M))- + schwartzMatrix f (sandShift B D (matrixProject R hR N)))*D := by dsimp [truncatedG]; noncomm_ring + rw [he] + calc + _ ≤ opNorm D^2*‖schwartzMatrix f (sandShift B D (matrixProject R hR M))- + schwartzMatrix f (sandShift B D (matrixProject R hR N))‖ := sandwich_frobenius _ _ + _ ≤ opNorm D^2*((2*Real.pi*fourierMoment f 1)*opNorm D^2*‖matrixProject R hR M-matrixProject R hR N‖) := + mul_le_mul_of_nonneg_left hl (sq_nonneg _) + _ ≤ opNorm D^2*((2*Real.pi*fourierMoment f 1)*opNorm D^2*‖M-N‖) := by + gcongr + exact matrixProject_sub_norm _ _ _ _ + _ = _ := by ring + +lemma truncatedG_hermitian (f : 𝓢(ℝ,ℂ)) (hf : ∀ x, star (f x) = f x) + (R : ℝ) (hR : 0 ≤ R) (B D M : Matrix ι ι ℂ) (hB : Bᴴ = B) (hD : Dᴴ = D) : + (truncatedG f R hR B D M)ᴴ = truncatedG f R hR B D M := by + have hs := schwartzMatrix_hermitian f hf (sandShift B D (matrixProject R hR M)) + (sandShift_hermitian B D (matrixProject R hR M) hB hD (matrixProject_bound R hR M).1) + change (D*schwartzMatrix f (sandShift B D (matrixProject R hR M))*D)ᴴ = _ + simp only [Matrix.conjTranspose_mul,hD,hs.eq,truncatedG,mul_assoc] + +lemma truncatedG_eq_inverse (f : 𝓢(ℝ,ℂ)) {lo hi : ℝ} (hlo : 0 < lo) + (hf : ∀ x ∈ Set.Icc lo hi, f x = (x : ℂ)⁻¹) + (R : ℝ) (hR : 0 ≤ R) (B D M : Matrix ι ι ℂ) (hB : Bᴴ = B) (hD : Dᴴ = D) + (hM : Mᴴ = M) (hMR : opNorm M ≤ R) + (hspec : ∀ i, Matrix.IsHermitian.eigenvalues (sandShift_hermitian B D M hB hD hM) i ∈ Set.Icc lo hi) : + truncatedG f R hR B D M = D*(sandShift B D M)⁻¹*D := by + rw [truncatedG,matrixProject_eq_self R hR M hM hMR, + schwartzMatrix_eq_inverse f hlo hf _ (sandShift_hermitian B D M hB hD hM) hspec] + +end SKRatioGaussian.ComplexMatrix + +end +end +end +end +end +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Matrices/TruncationGoodSet.lean b/lean/OAI/Probability/SKRatio/Matrices/TruncationGoodSet.lean new file mode 100644 index 0000000000000000000000000000000000000000..d6949903afdac90f49fe90193726044436b3ec26 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Matrices/TruncationGoodSet.lean @@ -0,0 +1,141 @@ +import Mathlib +import OAI.Probability.SKRatio.Matrices.GoeInverseLoopCentered +import OAI.Probability.SKRatio.Matrices.RealPartCLM + +namespace OAI + +section +section +noncomputable section +open MeasureTheory ProbabilityTheory InformationTheory Real Set +open scoped NNReal ENNReal +open Filter +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius ENNReal NNReal +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius NNReal +noncomputable section +open MeasureTheory ProbabilityTheory Real Set Filter +open MeasureTheory.Measure +open scoped ENNReal NNReal MeasureTheory Topology +open MeasureTheory +noncomputable section +noncomputable section +open MeasureTheory Set NormedSpace +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius +noncomputable section +open Set Real +open scoped Topology +noncomputable section +open Matrix Set Filter +open scoped Topology Matrix.Norms.Frobenius +noncomputable section +open Matrix NormedSpace ContinuousLinearMap +open scoped Matrix.Norms.Frobenius +noncomputable section +open Matrix +namespace SKRatioGaussian +open Matrix Real MeasureTheory ProbabilityTheory +open SKRatioGaussian.RealComplex +open scoped BigOperators Matrix.Norms.Frobenius NNReal ENNReal SchwartzMap +variable {ι : Type*} [Fintype ι] [DecidableEq ι] + +def truncationGoodSet (r R lo hi : ℝ) (D C : Matrix ι ι ℝ) : Set (MatrixCoordinates ι → ℝ) := + {g | opNorm (goeMatrix r g) < R ∧ + lo < ComplexSpectral.lowerRayleigh (liftMatrix (1-D*(goeMatrix r g-C)*D)) ∧ + -hi < ComplexSpectral.lowerRayleigh (-liftMatrix (1-D*(goeMatrix r g-C)*D))} + +lemma truncationGoodSet_measurable (r R lo hi : ℝ) (D C : Matrix ι ι ℝ) : + MeasurableSet (truncationGoodSet r R lo hi D C) := by + have hg := (goeMatrix_pi_lipschitz (ι := ι) r).continuous + have hc : Continuous (fun g => liftMatrix (1-D*(goeMatrix r g-C)*D)) := by + dsimp [liftMatrix]; fun_prop + exact (measurableSet_lt (continuous_realOpNorm.comp hg).measurable measurable_const).inter + ((measurableSet_lt measurable_const (ComplexSpectral.continuous_lowerRayleigh.comp hc).measurable).inter + (measurableSet_lt measurable_const (ComplexSpectral.continuous_lowerRayleigh.comp hc.neg).measurable)) + +lemma realTruncatedK_lipschitz (f : 𝓢(ℝ,ℂ)) {R : ℝ} (hR : 0 ≤ R) + (D C : Matrix ι ι ℝ) (hD : Dᵀ = D) (hC : Cᵀ = C) : + LipschitzWith (Real.toNNReal (ComplexMatrix.kLip f R (liftMatrix D) (liftMatrix C))) + (realTruncatedK f R hR D C) := by + apply LipschitzWith.of_dist_le_mul + intro M N + simp only [dist_eq_norm] + exact (realTruncatedK_sub_norm f hR D C M N hD hC).trans + (mul_le_mul_of_nonneg_right (Real.le_coe_toNNReal _) (norm_nonneg _)) + +omit [Fintype ι] [DecidableEq ι] in +lemma goeMatrix_transpose (r : ℝ) (g : MatrixCoordinates ι → ℝ) : + (goeMatrix r g)ᵀ = goeMatrix r g := by + ext i k + simp [goeMatrix,add_comm] + +omit [Fintype ι] in +lemma symmetricElementary_transpose (i k : ι) : + (symmetricElementary i k)ᵀ = symmetricElementary i k := by + simp [symmetricElementary,Matrix.transpose_add,Matrix.transpose_single,add_comm] + +lemma realTruncatedK_goe_derivative (f : 𝓢(ℝ,ℂ)) {lo hi : ℝ} (hlo : 0 < lo) + (hf : ∀ x ∈ Set.Icc lo hi, f x = (x : ℂ)⁻¹) + {R : ℝ} (hR : 0 ≤ R) (D C : Matrix ι ι ℝ) (r : ℝ) + (hD : Dᵀ = D) (hC : Cᵀ = C) (g : MatrixCoordinates ι → ℝ) + (hg : g ∈ truncationGoodSet r R lo hi D C) (i b : ι) : + HasDerivAt (fun t : ℝ => realTruncatedK f R hR D C (goeMatrix r g+t • symmetricElementary i b) b i) + ((realTruncatedK f R hR D C (goeMatrix r g)*(D*D)*symmetricElementary i b* + realTruncatedK f R hR D C (goeMatrix r g)) b i) 0 := by + exact matrixEntry_derivative + (realTruncatedK_derivative f hlo hf hR D C (goeMatrix r g) (symmetricElementary i b) + hD hC (goeMatrix_transpose r g) (symmetricElementary_transpose i b) hg.1 hg.2.1 hg.2.2) b i + +theorem realTruncatedK_first_loop (f : 𝓢(ℝ,ℂ)) {lo hi : ℝ} (hlo : 0 < lo) + (hf : ∀ x ∈ Set.Icc lo hi, f x = (x : ℂ)⁻¹) + {R r : ℝ} (hR : 0 ≤ R) (hr : 0 ≤ r) (D C : Matrix ι ι ℝ) + (hD : Dᵀ = D) (hC : Cᵀ = C) (i : ι) : + let K := realTruncatedK f R hR D C + let c := ComplexMatrix.kBound f R (liftMatrix D) (liftMatrix C) + let L := Real.toNNReal (ComplexMatrix.kLip f R (liftMatrix D) (liftMatrix C)) + let Lπ : ℝ≥0 := L*(⟨sqrt (2*r),sqrt_nonneg _⟩ * + (Fintype.card (MatrixCoordinates ι) : ℝ≥0) ^ (1/(2:ℝ≥0∞)).toReal) + let T : ℝ≥0 := (⟨sqrt (Fintype.card ι)*opNorm (D*D), + mul_nonneg (sqrt_nonneg _) (norm_nonneg _)⟩*L)*⟨sqrt (2*r),sqrt_nonneg _⟩+1 + let μ := Measure.pi (fun _ : MatrixCoordinates ι => gaussianReal 0 1) + |(∫ g, (goeMatrix r g*K (goeMatrix r g)) i i ∂μ)- + r*(∫ g, Matrix.trace (K (goeMatrix r g)*(D*D)) ∂μ)*(∫ g, K (goeMatrix r g) i i ∂μ)| ≤ + (Fintype.card ι:ℝ)*(sqrt (2*r)*(Lπ:ℝ)+r*(2*c*opNorm (D*D)*c))* + μ.real (truncationGoodSet r R lo hi D C)ᶜ+ + r*(c*((2*Real.exp (π^2/8))*(T:ℝ))+c*opNorm (D*D)*c) := by + intro K c L Lπ T μ + have hK : LipschitzWith L K := realTruncatedK_lipschitz f hR D C hD hC + have ht : LipschitzWith T (fun g : EuclideanSpace ℝ (MatrixCoordinates ι) => + Matrix.trace (K (goeMatrix r g)*(D*D))) := by + exact ((matrixTrace_mul_lipschitz hK (D*D)).comp (goeMatrix_L2_lipschitz r)).weaken + (le_add_of_nonneg_right (by norm_num)) + have ht0 : 0 < T := by dsimp [T]; positivity + exact goe_inverse_loop_centered hr (D*D) i hK + (fun M => realTruncatedK_opNorm f hR D C M hD hC) ht ht0 + (truncationGoodSet_measurable r R lo hi D C) + (fun g hg b => realTruncatedK_goe_derivative f hlo hf hR D C r hD hC g hg i b) + +end SKRatioGaussian + +end +end +end +end +end +end +end +end +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Matrices/UnitBall.lean b/lean/OAI/Probability/SKRatio/Matrices/UnitBall.lean new file mode 100644 index 0000000000000000000000000000000000000000..efa711e870da17ceb8e3982352856a4bb65667f2 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Matrices/UnitBall.lean @@ -0,0 +1,318 @@ +import Mathlib +import OAI.Probability.SKRatio.Matrices.GaussianQuadraticSupComparison +import OAI.Probability.SKRatio.Matrices.GaussianAffineGaussianSup +import OAI.Probability.SKRatio.Matrices.DiagonalSqrt +import OAI.Probability.SKRatio.Matrices.GaussianQuadratic + +namespace OAI + +section +section +noncomputable section +open MeasureTheory ProbabilityTheory InformationTheory Real Set +open scoped NNReal ENNReal +open Filter +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius ENNReal NNReal +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius NNReal +noncomputable section +open MeasureTheory ProbabilityTheory Real Set Filter +open MeasureTheory.Measure +open scoped ENNReal NNReal MeasureTheory Topology +open MeasureTheory +noncomputable section +noncomputable section +open MeasureTheory Set NormedSpace +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius +noncomputable section +open Set Real +open scoped Topology +noncomputable section +open Matrix Set Filter +open scoped Topology Matrix.Norms.Frobenius +noncomputable section +open Matrix NormedSpace ContinuousLinearMap +open scoped Matrix.Norms.Frobenius +noncomputable section +open Matrix +noncomputable section +open MeasureTheory ProbabilityTheory Real Set +open scoped ENNReal NNReal +noncomputable section +open MeasureTheory ProbabilityTheory InformationTheory Real Set +open scoped NNReal ENNReal +noncomputable section +open scoped BigOperators +open MeasureTheory ProbabilityTheory +open Real +namespace SKRatioGaussian +lemma quadratic_interpolation {z q v c : ℝ} (hz0 : 0 ≤ z) (hz1 : z ≤ 1) + (hc : 0 ≤ c) (hqc : q*v ≤ c) {X : ℝ} (hX : X - q*v ≤ c) : + z*X-z^2*q*v ≤ c := by + have h1 := mul_le_mul_of_nonneg_left hX hz0 + have h2 := mul_le_mul_of_nonneg_left hqc (mul_nonneg hz0 (sub_nonneg.mpr hz1)) + have h3 := mul_nonneg hc (sq_nonneg (1-z)) + nlinarith only [h1, h2, h3] + +section DiagonalProcess +variable {ι : Type*} [Fintype ι] + +abbrev UnitBall (ι : Type*) [Fintype ι] := + ↥(Metric.closedBall (0 : EuclideanSpace ℝ ι) 1) + +instance : Nonempty (UnitBall ι) := ⟨⟨0, by simp⟩⟩ + +lemma norm_UnitBall_le (p : UnitBall ι) : ‖(p : EuclideanSpace ℝ ι)‖ ≤ 1 := by + simpa only [Metric.mem_closedBall, dist_zero_right] using p.property + +def diagonalOffset (a : ι → ℝ) (z q : ℝ) (p : UnitBall ι) : ℝ := + -z^2 * q * ‖diagonalSqrt a p‖^2 + +def diagonalProcess (r : ℝ) (a : ι → ℝ) (z q : ℝ) + (g : MatrixCoordinates ι → ℝ) : ℝ := + gaussianSup (diagonalOffset a z q) + (fun p k => z * quadraticCoeff r (diagonalSqrt a p) k) g + +def diagonalLinearProcess (r : ℝ) (a : ι → ℝ) (z q : ℝ) + (g : MatrixCoordinates ι → ℝ) : ℝ := + gaussianSup (diagonalOffset a z q) + (fun p k => z * linearCoeff r (diagonalSqrt a p) k) g + +def diagonalWeights (r : ℝ) (a : ι → ℝ) : MatrixCoordinates ι → ℝ + | Sum.inl _ => 0 + | Sum.inr i => r * a i + +def diagonalT (r : ℝ) (a : ι → ℝ) (g : MatrixCoordinates ι → ℝ) : ℝ := + sqrt (gaussianQuadratic (diagonalWeights r a) g) + +lemma continuous_diagonalOffset (a : ι → ℝ) (z q : ℝ) : + Continuous (diagonalOffset a z q) := by + exact continuous_const.mul (((continuous_diagonalSqrt a).comp continuous_subtype_val).norm.pow 2) + +lemma continuous_diagonalCoeff {f : EuclideanSpace ℝ ι → MatrixCoordinates ι → ℝ} + (hf : Continuous f) (a : ι → ℝ) (z : ℝ) : + Continuous (fun p : UnitBall ι => fun k => z * f (diagonalSqrt a p) k) := by + apply continuous_pi + intro k + exact continuous_const.mul ((continuous_apply k).comp + (hf.comp ((continuous_diagonalSqrt a).comp continuous_subtype_val))) + +lemma integrable_diagonalProcess (r : ℝ) (a : ι → ℝ) (z q : ℝ) : + Integrable (diagonalProcess r a z q) (gaussianCoordinates (MatrixCoordinates ι)) := + integrable_gaussianSup (continuous_diagonalOffset a z q) + (continuous_diagonalCoeff (continuous_quadraticCoeff r) a z) + +lemma integrable_diagonalLinearProcess (r : ℝ) (a : ι → ℝ) (z q : ℝ) : + Integrable (diagonalLinearProcess r a z q) (gaussianCoordinates (MatrixCoordinates ι)) := + integrable_gaussianSup (continuous_diagonalOffset a z q) + (continuous_diagonalCoeff (continuous_linearCoeff r) a z) + +lemma diagonalT_norm {r : ℝ} (hr : 0 ≤ r) {a : ι → ℝ} (ha : ∀ i, 0 ≤ a i) + (g : MatrixCoordinates ι → ℝ) : + diagonalT r a g = sqrt r * ‖diagonalSqrt a (WithLp.toLp 2 (fun i => g (.inr i)))‖ := by + unfold diagonalT gaussianQuadratic + rw [Fintype.sum_sum_type] + simp only [diagonalWeights, zero_mul, Finset.sum_const_zero, zero_add] + simp_rw [mul_assoc] + rw [← Finset.mul_sum, Real.sqrt_mul hr] + have he := diagonalSqrt_norm_sq a ha (WithLp.toLp 2 (fun i => g (.inr i))) + rw [← he, Real.sqrt_sq (norm_nonneg _)] + +lemma diagonalWeights_sum (r : ℝ) (a : ι → ℝ) : + (∑ k, diagonalWeights r a k) = r * ∑ i, a i := by + simp only [Fintype.sum_sum_type, diagonalWeights, Finset.sum_const_zero, zero_add, + Finset.mul_sum] + +lemma diagonalWeights_sum_sq (r : ℝ) (a : ι → ℝ) : + (∑ k, (diagonalWeights r a k)^2) = r^2 * ∑ i, (a i)^2 := by + simp only [Fintype.sum_sum_type, diagonalWeights, zero_pow (by norm_num : (2:ℕ)≠0), + Finset.sum_const_zero, zero_add, mul_pow, Finset.mul_sum] + +lemma diagonalT_integrable {r : ℝ} (hr : 0 ≤ r) {a : ι → ℝ} (ha : ∀ i, 0 ≤ a i) : + Integrable (diagonalT r a) (gaussianCoordinates (MatrixCoordinates ι)) := by + apply (memLp_sqrt_of_nonneg ((gaussianQuadratic_memLp (diagonalWeights r a)).integrable + (by norm_num)) ?_).integrable (by norm_num) + intro g + apply Finset.sum_nonneg + intro k _ + apply mul_nonneg _ (sq_nonneg _) + cases k <;> simp only [diagonalWeights] + · exact le_rfl + · exact mul_nonneg hr (ha _) + +lemma diagonalT_fluctuation {r : ℝ} (hr : 0 ≤ r) {a : ι → ℝ} (ha : ∀ i, 0 ≤ a i) : + (∫ g, |diagonalT r a g - sqrt (r * ∑ i, a i)| + ∂gaussianCoordinates (MatrixCoordinates ι)) ≤ + sqrt (sqrt (2*r^2 * ∑ i, (a i)^2)) := by + have hp (g) : 0 ≤ gaussianQuadratic (diagonalWeights r a) g := by + apply Finset.sum_nonneg + intro k _ + apply mul_nonneg _ (sq_nonneg _) + cases k <;> simp only [diagonalWeights] + · exact le_rfl + · exact mul_nonneg hr (ha _) + have h := integral_sqrt_fluctuation (gaussianQuadratic_memLp (diagonalWeights r a)) hp + rw [gaussianQuadratic_mean, gaussianQuadratic_variance, + diagonalWeights_sum, diagonalWeights_sum_sq, ← mul_assoc] at h + exact h + +lemma diagonalLinearProcess_le {r z q A b : ℝ} {a : ι → ℝ} + (hr : 0 ≤ r) (ha : ∀ i, 0 ≤ a i) (hA : ∀ i, a i ≤ A) (hA0 : 0 ≤ A) + (hz0 : 0 ≤ z) (hz1 : z ≤ 1) (hq : 0 ≤ q) + (hqb : sqrt q * sqrt A ≤ b) (hb : b ≤ 1) + (g : MatrixCoordinates ι → ℝ) : + diagonalLinearProcess r a z q g ≤ + 1-(1-b)^2 + 2 * sqrt A * |diagonalT r a g - sqrt q| := by + unfold diagonalLinearProcess + apply gaussianSup_le (continuous_diagonalOffset a z q) + (continuous_diagonalCoeff (continuous_linearCoeff r) a z) + intro p + let w := diagonalSqrt a p + let v := ‖w‖ + have hv0 : 0 ≤ v := norm_nonneg _ + have hv : v ≤ sqrt A := diagonalSqrt_norm_le_sqrt ha hA0 hA (norm_UnitBall_le p) + have hdot := diagonal_sum_mul_le_norm a (p : EuclideanSpace ℝ ι) + (WithLp.toLp 2 (fun i => g (.inr i))) + have hdot' : (∑ i, w i * g (.inr i)) ≤ + ‖diagonalSqrt a (WithLp.toLp 2 (fun i => g (.inr i)))‖ := + hdot.trans ((mul_le_mul_of_nonneg_right (norm_UnitBall_le p) (norm_nonneg _)).trans_eq + (one_mul _)) + have hcoeff : (∑ k, (z * linearCoeff r w k) * g k) = + 2*z*sqrt r*v * (∑ i, w i * g (.inr i)) := by + simp only [Fintype.sum_sum_type, linearCoeff, mul_zero, zero_mul, + Finset.sum_const_zero, zero_add, Finset.mul_sum] + apply Finset.sum_congr rfl + intro i _ + dsimp [v] + ring + have hlin := mul_le_mul_of_nonneg_left hdot' (show 0 ≤ 2*z*sqrt r*v by positivity) + have hT := diagonalT_norm hr ha g + have hlin' : (∑ k, (z * linearCoeff r w k) * g k) ≤ 2*z*v*diagonalT r a g := by + rw [hcoeff, hT] + nlinarith only [hlin] + have hd0 : 0 ≤ z * sqrt q * v := by positivity + have hzb : z * sqrt q * v ≤ b := by + calc + _ ≤ sqrt q * v := by nlinarith [mul_nonneg (sqrt_nonneg q) hv0] + _ ≤ sqrt q * sqrt A := mul_le_mul_of_nonneg_left hv (sqrt_nonneg q) + _ ≤ b := hqb + have hmargin := quadratic_margin hd0 hzb hb + have hs := sq_sqrt hq + have hab := le_abs_self (diagonalT r a g - sqrt q) + have hvz : z*v ≤ sqrt A := (mul_le_of_le_one_left hv0 hz1).trans hv + have herr : 2*z*v*(diagonalT r a g - sqrt q) ≤ + 2*sqrt A*|diagonalT r a g - sqrt q| := by + exact (mul_le_mul_of_nonneg_left hab (by positivity)).trans + (mul_le_mul_of_nonneg_right (by nlinarith) (abs_nonneg _)) + change -z^2*q*v^2 + (∑ k, (z * linearCoeff r w k) * g k) ≤ _ + nlinarith only [hlin', hmargin, herr, hs, sq_nonneg (z*v)] + +theorem diagonalProcess_expected_margin [Nonempty ι] + {r z A b : ℝ} {a : ι → ℝ} + (hr : 0 ≤ r) (ha : ∀ i, 0 ≤ a i) (hA : ∀ i, a i ≤ A) (hA0 : 0 ≤ A) + (hz0 : 0 ≤ z) (hz1 : z ≤ 1) + (hqb : sqrt (r * ∑ i, a i) * sqrt A ≤ b) (hb : b ≤ 1) : + (∫ g, diagonalProcess r a z (r * ∑ i, a i) g + ∂gaussianCoordinates (MatrixCoordinates ι)) ≤ + 1-(1-b)^2 + 2*sqrt A * sqrt (sqrt (2*r^2 * ∑ i, (a i)^2)) := by + let q := r * ∑ i, a i + have hq : 0 ≤ q := mul_nonneg hr (Finset.sum_nonneg (fun i _ => ha i)) + have hcomp := gaussian_quadraticSup_comparison + (continuous_diagonalOffset a z q) + ((continuous_diagonalSqrt a).comp continuous_subtype_val) hr z + have hfluct := diagonalT_fluctuation hr ha + have hi : Integrable (fun g => |diagonalT r a g - sqrt q|) + (gaussianCoordinates (MatrixCoordinates ι)) := + ((diagonalT_integrable hr ha).sub (integrable_const _)).abs + have hbound : (∫ g, diagonalLinearProcess r a z q g + ∂gaussianCoordinates (MatrixCoordinates ι)) ≤ + 1-(1-b)^2 + 2*sqrt A * + (∫ g, |diagonalT r a g - sqrt q| ∂gaussianCoordinates (MatrixCoordinates ι)) := by + calc + _ ≤ ∫ g, (1-(1-b)^2 + 2*sqrt A*|diagonalT r a g - sqrt q|) + ∂gaussianCoordinates (MatrixCoordinates ι) := + integral_mono (integrable_diagonalLinearProcess r a z q) + ((integrable_const _).add (hi.const_mul _)) + (diagonalLinearProcess_le hr ha hA hA0 hz0 hz1 hq hqb hb) + _ = _ := by rw [integral_add (integrable_const _) (hi.const_mul _), + integral_const, probReal_univ, one_smul, integral_const_mul] + exact hcomp.trans (hbound.trans (add_le_add le_rfl + (mul_le_mul_of_nonneg_left hfluct (show 0 ≤ 2*sqrt A by positivity)))) + +lemma diagonalProcess_lipschitz {r z A : ℝ} {a : ι → ℝ} + (hr : 0 ≤ r) (ha : ∀ i, 0 ≤ a i) (hA : ∀ i, a i ≤ A) (hA0 : 0 ≤ A) + (hz : 0 ≤ z) (q : ℝ) : + LipschitzWith (Real.toNNReal (z * sqrt (2*r) * A)) + (fun g : EuclideanSpace ℝ (MatrixCoordinates ι) => + diagonalProcess r a z q g.ofLp) := by + apply gaussianSup_lipschitz (continuous_diagonalOffset a z q) + (continuous_diagonalCoeff (continuous_quadraticCoeff r) a z) + intro p + have hsq := diagonalSqrt_norm_sq_le ha hA (p : EuclideanSpace ℝ ι) + have hp2 : ‖(p : EuclideanSpace ℝ ι)‖^2 ≤ 1 := by + nlinarith [norm_UnitBall_le p, norm_nonneg (p : EuclideanSpace ℝ ι)] + have hw : ‖diagonalSqrt a p‖^2 ≤ A := + hsq.trans ((mul_le_mul_of_nonneg_left hp2 hA0).trans_eq (mul_one A)) + have he : WithLp.toLp 2 (fun k => z * quadraticCoeff r (diagonalSqrt a p) k) = + z • WithLp.toLp 2 (quadraticCoeff r (diagonalSqrt a p)) := rfl + rw [he, norm_smul, Real.norm_eq_abs, abs_of_nonneg hz, quadraticCoeff_norm hr, + Real.toNNReal_of_nonneg (by positivity)] + simpa only [mul_assoc, NNReal.coe_mk] using + mul_le_mul_of_nonneg_left hw (show 0 ≤ z * sqrt (2*r) by positivity) + +theorem diagonalProcess_path_le {r A q c : ℝ} {a : ι → ℝ} + (ha : ∀ i, 0 ≤ a i) (hA : ∀ i, a i ≤ A) (hA0 : 0 ≤ A) + (hq : 0 ≤ q) (hc : 0 ≤ c) (hqc : q*A ≤ c) + {g : MatrixCoordinates ι → ℝ} (hg : diagonalProcess r a 1 q g ≤ c) + {z : ℝ} (hz0 : 0 ≤ z) (hz1 : z ≤ 1) : + diagonalProcess r a z q g ≤ c := by + apply gaussianSup_le (continuous_diagonalOffset a z q) + (continuous_diagonalCoeff (continuous_quadraticCoeff r) a z) + intro p + let w := diagonalSqrt a p + let v := ‖w‖^2 + let X := ∑ k, quadraticCoeff r w k * g k + have hp2 : ‖(p : EuclideanSpace ℝ ι)‖^2 ≤ 1 := by + nlinarith [norm_UnitBall_le p, norm_nonneg (p : EuclideanSpace ℝ ι)] + have hv : v ≤ A := (diagonalSqrt_norm_sq_le ha hA _).trans + ((mul_le_mul_of_nonneg_left hp2 hA0).trans_eq (mul_one A)) + have hqv : q*v ≤ c := (mul_le_mul_of_nonneg_left hv hq).trans hqc + have hX : X - q*v ≤ c := by + have h := (gaussianAffine_le_gaussianSup (continuous_diagonalOffset a 1 q) + (continuous_diagonalCoeff (continuous_quadraticCoeff r) a 1) g p).trans hg + simp only [gaussianAffine, diagonalOffset, one_mul, one_pow, neg_mul] at h + simpa only [sub_eq_add_neg, add_comm, X, v, w] using h + have h := quadratic_interpolation hz0 hz1 hc hqv hX + convert h using 1 + simp only [gaussianAffine, diagonalOffset, X, v, w, Finset.mul_sum] + simp_rw [mul_assoc] + ring + +end DiagonalProcess +end SKRatioGaussian + +end +end +end +end +end +end +end +end +end +end +end +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Matrices/UnitInterval.lean b/lean/OAI/Probability/SKRatio/Matrices/UnitInterval.lean new file mode 100644 index 0000000000000000000000000000000000000000..61366095410e4b2d9be52af941e425291cc4f2c3 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Matrices/UnitInterval.lean @@ -0,0 +1,94 @@ +import Mathlib + +namespace OAI + +section +section +noncomputable section +namespace SKRatioGaussian.PathBridge +open MeasureTheory ProbabilityTheory Real Set TopologicalSpace +open scoped BigOperators ENNReal NNReal Topology +abbrev UnitInterval := Set.Icc (0:ℝ) 1 +abbrev UnitPath := C(UnitInterval,ℝ) +instance pathMeasurable : MeasurableSpace UnitPath := borel _ +instance pathBorel : BorelSpace UnitPath := ⟨rfl⟩ + +def pathPairEvaluations (p : UnitPath × UnitPath) : ℕ→ℝ×ℝ := + fun k=>(p.1 (denseSeq UnitInterval k),p.2 (denseSeq UnitInterval k)) + +lemma continuous_pathPairEvaluations : Continuous pathPairEvaluations := by + apply continuous_pi + intro k + exact ((ContinuousMap.evalCLM ℝ (denseSeq UnitInterval k)).continuous.comp continuous_fst).prodMk + ((ContinuousMap.evalCLM ℝ (denseSeq UnitInterval k)).continuous.comp continuous_snd) + +lemma injective_pathPairEvaluations : Function.Injective pathPairEvaluations := by + intro p q h + apply Prod.ext + · apply ContinuousMap.coe_injective + apply (denseRange_denseSeq UnitInterval).equalizer p.1.continuous q.1.continuous + funext k + exact congrArg Prod.fst (congrFun h k) + · apply ContinuousMap.coe_injective + apply (denseRange_denseSeq UnitInterval).equalizer p.2.continuous q.2.continuous + funext k + exact congrArg Prod.snd (congrFun h k) + +lemma measurableEmbedding_pathPairEvaluations : MeasurableEmbedding pathPairEvaluations := + continuous_pathPairEvaluations.measurableEmbedding injective_pathPairEvaluations + +lemma centered_gaussian_path_rotation (μ : Measure UnitPath) [IsProbabilityMeasure μ] + (hG : IsGaussianProcess (fun t : UnitInterval=>fun f : UnitPath=>f t) μ) + (h0 : ∀ t : UnitInterval, ∫ f : UnitPath,f t ∂μ=0) (θ : ℝ) : + (μ.prod μ).map (ContinuousLinearMap.rotation θ)=μ.prod μ := by + apply measurableEmbedding_pathPairEvaluations.map_injective + rw [Measure.map_map continuous_pathPairEvaluations.measurable (by fun_prop)] + apply (map_eq_iff_forall_finset_map_restrict_eq + (continuous_pathPairEvaluations.measurable.comp (by fun_prop)).aemeasurable + continuous_pathPairEvaluations.measurable.aemeasurable).2 + intro s + let e : UnitPath→s→ℝ := fun f i=>f (denseSeq UnitInterval i) + have he : Measurable e := by + apply Measurable.of_eval + intro i + exact (ContinuousMap.evalCLM ℝ (denseSeq UnitInterval i)).continuous.measurable + have heG : HasGaussianLaw e μ := (hG.comp_right (denseSeq UnitInterval)).hasGaussianLaw s + let ν := μ.map e + let : IsGaussian ν := heG.isGaussian_map + have hν0 : (∫ x : s→ℝ,id x ∂ν)=0 := by + rw [show ν=μ.map e from rfl,integral_map he.aemeasurable measurable_id.aestronglyMeasurable] + ext i + have hh := (ContinuousLinearMap.proj i : (s→ℝ)→L[ℝ]ℝ).integral_comp_comm heG.integrable + exact hh.symm.trans (h0 _) + have hr := IsGaussian.map_rotation_eq_self (μ:=ν) hν0 θ + let pair : ((s→ℝ)×(s→ℝ))→s→ℝ×ℝ := fun p i=>(p.1 i,p.2 i) + have hp : Measurable pair := by fun_prop + have hr' := congrArg (Measure.map pair) hr + rw [Measure.map_map hp (by fun_prop)] at hr' + have hn : ν.prod ν=(μ.prod μ).map (Prod.map e e) := Measure.map_prod_map μ μ he he + rw [hn,Measure.map_map (hp.comp (by fun_prop)) (he.prodMap he), + Measure.map_map hp (he.prodMap he)] at hr' + convert hr' using 1 + · congr 1 + · rfl + +theorem centered_gaussian_path_fernique (μ : Measure UnitPath) [IsProbabilityMeasure μ] + (hG : IsGaussianProcess (fun t : UnitInterval=>fun f : UnitPath=>f t) μ) + (h0 : ∀ t : UnitInterval, ∫ f : UnitPath,f t ∂μ=0) : + ∃ a : ℝ, 0exp (a*‖f‖^2)) μ := + exists_integrable_exp_sq_of_map_rotation_eq_self + (centered_gaussian_path_rotation μ hG h0 (-(π/4))) +end SKRatioGaussian.PathBridge + +end +end + +section + +noncomputable section + +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Matrices/Vectorize.lean b/lean/OAI/Probability/SKRatio/Matrices/Vectorize.lean new file mode 100644 index 0000000000000000000000000000000000000000..b99066b44b33d223ce0c9b4ab53811c0231f588c --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Matrices/Vectorize.lean @@ -0,0 +1,116 @@ +import Mathlib +import OAI.Probability.SKRatio.Matrices.LinEquiv +import OAI.Probability.SKRatio.Matrices.ClosedConvexNonempty + +namespace OAI + +section +section +noncomputable section +open MeasureTheory ProbabilityTheory InformationTheory Real Set +open scoped NNReal ENNReal +open Filter +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius ENNReal NNReal +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius NNReal +noncomputable section +open MeasureTheory ProbabilityTheory Real Set Filter +open MeasureTheory.Measure +open scoped ENNReal NNReal MeasureTheory Topology +open MeasureTheory +noncomputable section +noncomputable section +open MeasureTheory Set NormedSpace +open scoped Topology +noncomputable section +open Matrix Real +open scoped BigOperators Matrix.Norms.Frobenius +noncomputable section +open Set Real +open scoped Topology +namespace SKRatioGaussian.ComplexMatrix +open Set +variable {ι : Type*} [Fintype ι] [DecidableEq ι] + +def vectorize : Matrix ι ι ℂ →ₗ[ℝ] EuclideanSpace ℂ (ι × ι) where + toFun M := WithLp.toLp 2 (fun p => M p.1 p.2) + map_add' _ _ := rfl + map_smul' _ _ := rfl + +lemma vectorize_norm (M : Matrix ι ι ℂ) : ‖vectorize M‖ = ‖M‖ := by + have hh : ‖vectorize M‖^2 = ‖M‖^2 := by + rw [EuclideanSpace.norm_sq_eq,frobenius_sq] + change (∑ p : ι × ι, ‖M p.1 p.2‖^2) = ∑ i, ∑ k, ‖M i k‖^2 + exact Fintype.sum_prod_type _ + nlinarith [norm_nonneg (vectorize M),norm_nonneg M] + +noncomputable instance frobeniusInnerProduct : InnerProductSpace ℝ (Matrix ι ι ℂ) where + inner M N := inner ℝ (vectorize M) (vectorize N) + norm_sq_eq_re_inner M := by + change ‖M‖^2 = inner ℝ (vectorize M) (vectorize M) + rw [real_inner_self_eq_norm_sq,vectorize_norm] + conj_inner_symm M N := by simp only [conj_trivial]; exact real_inner_comm _ _ + add_left M N P := by rw [map_add,inner_add_left] + smul_left M N r := by rw [map_smul,inner_smul_left] + +noncomputable def hermitianBall (R : ℝ) : Set (Matrix ι ι ℂ) := + {M | Mᴴ = M ∧ opNorm M ≤ R} + +lemma hermitianBall_closed (R : ℝ) : IsClosed (hermitianBall (ι := ι) R) := by + apply IsClosed.inter + · exact isClosed_eq (by fun_prop : Continuous (fun M : Matrix ι ι ℂ => Mᴴ)) continuous_id + · exact isClosed_le continuous_lin.norm continuous_const + +lemma hermitianBall_convex (R : ℝ) : Convex ℝ (hermitianBall (ι := ι) R) := by + intro M hM N hN a b ha hb hab + constructor + · simp only [Matrix.conjTranspose_add,Matrix.conjTranspose_smul,hM.1,hN.1,star_trivial] + · have he : lin (a • M+b • N) = a • lin M+b • lin N := by + exact (linEquiv (ι := ι)).toLinearMap.restrictScalars ℝ |>.map_add _ _ |>.trans + (by rw [LinearMap.map_smul,LinearMap.map_smul]; rfl) + change ‖lin (a • M+b • N)‖ ≤ R + rw [he] + calc + _ ≤ ‖a • lin M‖+‖b • lin N‖ := norm_add_le _ _ + _ = a*opNorm M+b*opNorm N := by simp [norm_smul,Real.norm_eq_abs,abs_of_nonneg ha,abs_of_nonneg hb,opNorm] + _ ≤ a*R+b*R := add_le_add (mul_le_mul_of_nonneg_left hM.2 ha) (mul_le_mul_of_nonneg_left hN.2 hb) + _ = R := by rw [← add_mul,hab,one_mul] + +lemma hermitianBall_good {R : ℝ} (hR : 0 ≤ R) : SKRatioGaussian.ClosedConvexNonempty (hermitianBall (ι := ι) R) where + nonempty := ⟨0,by simp [hermitianBall,opNorm,lin,hR]⟩ + complete := (hermitianBall_closed R).isComplete + convex := by convert hermitianBall_convex (ι := ι) R using 0 + +noncomputable def matrixProject (R : ℝ) (hR : 0 ≤ R) : Matrix ι ι ℂ → Matrix ι ι ℂ := + SKRatioGaussian.convexProject (hermitianBall_good hR) + +lemma matrixProject_lipschitz (R : ℝ) (hR : 0 ≤ R) : + LipschitzWith 1 (matrixProject (ι := ι) R hR) := + SKRatioGaussian.convexProject_lipschitz _ + +lemma matrixProject_bound (R : ℝ) (hR : 0 ≤ R) (M : Matrix ι ι ℂ) : + (matrixProject R hR M)ᴴ = matrixProject R hR M ∧ opNorm (matrixProject R hR M) ≤ R := + SKRatioGaussian.convexProject_mem (hermitianBall_good (ι := ι) hR) M + +lemma matrixProject_eq_self (R : ℝ) (hR : 0 ≤ R) (M : Matrix ι ι ℂ) + (hM : Mᴴ = M) (hMR : opNorm M ≤ R) : matrixProject R hR M = M := + SKRatioGaussian.convexProject_eq_self _ ⟨hM,hMR⟩ + +end SKRatioGaussian.ComplexMatrix + +end +end +end +end +end +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Matrices/WeightedDiagonalSquares.lean b/lean/OAI/Probability/SKRatio/Matrices/WeightedDiagonalSquares.lean new file mode 100644 index 0000000000000000000000000000000000000000..30df2968fadcbaa54ee47159dbc7050c8dfb3f6b --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Matrices/WeightedDiagonalSquares.lean @@ -0,0 +1,177 @@ +import Mathlib +import OAI.Probability.SKRatio.Matrices.WeightedSquares +import OAI.Probability.SKRatio.Matrices.RowGeometry +import OAI.Probability.SKRatio.Gaussian.ExponentialProducts +import OAI.Probability.SKRatio.Gaussian.PlantedEntries +import OAI.Probability.SKRatio.Matrices.ConditionalAffineSquares + +namespace OAI + +section +noncomputable section +open scoped BigOperators NNReal ENNReal Topology +open MeasureTheory ProbabilityTheory Filter Set Real Metric +namespace SKRatio.Planted +open SKRatioClock.Regression MatrixNet +attribute [local instance] Classical.propDecidable + +lemma incident_absolute_square_error {n : ℕ} (hn : 0 Iff.rfl)] using h + calc + _ ≤ ∑ e : incidentEdges i, (affineDisorder β z e^2+β^2/(n:ℝ)) := by + apply Finset.sum_le_sum + intro e _ + exact (abs_sub _ _).trans (by rw [abs_of_nonneg (sq_nonneg _),abs_of_nonneg (by positivity)]) + _ = (∑ e : incidentEdges i, affineDisorder β z e^2)+ + ((incidentEdges i).card:ℝ)*(β^2/(n:ℝ)) := by simp [Finset.sum_add_distrib] + _ ≤ (2*β^2*C+2*β^4)+β^2 := by + apply add_le_add hs + calc + _ ≤ (n:ℝ)*(β^2/(n:ℝ)) := mul_le_mul_of_nonneg_right hc (by positivity) + _ = _ := mul_div_cancel₀ _ hnr.ne' + +lemma weighted_sum_difference_le {ι : Type*} [Fintype ι] + (a f g : ι → ℝ) {δ R : ℝ} (hδ : 0≤δ) + (ha : ∑ i, |a i| ≤ R) (hfg : ∀ i, |f i-g i|≤δ) : + |(∑ i, a i*f i)-(∑ i, a i*g i)| ≤ δ*R := by + rw [←Finset.sum_sub_distrib] + calc + _ ≤ ∑ i, |a i*f i-a i*g i| := Finset.abs_sum_le_sum_abs _ _ + _ = ∑ i, |a i| * |f i-g i| := by simp only [←mul_sub,abs_mul] + _ ≤ ∑ i, |a i| * δ := Finset.sum_le_sum (fun i _ => mul_le_mul_of_nonneg_left (hfg i) (abs_nonneg _)) + _ = δ*(∑ i, |a i|) := by rw [←Finset.sum_mul,mul_comm] + _ ≤ _ := mul_le_mul_of_nonneg_left ha hδ + +lemma compact_first_mesh {X : Type*} [PseudoMetricSpace X] [CompactSpace X] + {δ : ℝ} (hδ : 0<δ) : + ∃ (s : Finset X) (q : X → s), ∀ x : X, dist x (q x : X) < δ := by + classical + obtain ⟨s,_,hs,hcov⟩ := finite_cover_balls_of_compact (X := X) isCompact_univ hδ + have hnear (x : X) : ∃ y : {z // z∈hs.toFinset}, dist x y<δ := by + obtain ⟨y,hy,hxy⟩ := Set.mem_iUnion₂.mp (hcov (Set.mem_univ x)) + exact ⟨⟨y,hs.mem_toFinset.mpr hy⟩,hxy⟩ + choose q hq using hnear + exact ⟨hs.toFinset,q,hq⟩ + +theorem continuous_weighted_diagonal_rare {X : Type} [PseudoMetricSpace X] [CompactSpace X] + (G : X × X → ℝ) (hG : Continuous G) (b : ℝ → X) {K : ℝ≥0} (hb : LipschitzWith K b) + (β : ℝ) (μ : ∀ n, Measure (Fin n → ℝ)) [∀ n, IsProbabilityMeasure (μ n)] + {u : ℝ} (hu : 0 (μ n).prod (standardArrayLaw (Edge n))) + (fun n => {p | ∃ i : Fin n, ∃ a : X, + u < |∑ e : incidentEdges i, (affineDisorder β p.2 e^2-β^2/(n:ℝ))* + G (a,b (diagonalField p.1 (affineDisorder β p.2) (otherEnd i e)))|}) := by + obtain ⟨C,hC,hrows⟩ := gaussian_rows_square_bounded + let R := 2*β^2*C+2*β^4+β^2 + have hR : 0≤R := by dsimp [R]; positivity + let v := u/(2*(R+1)) + have hv : 0 p.2 j)) (otherEnd i e)))* + ((β/sqrt n*p.2 e+β^2/(n:ℝ))^2-β^2/(n:ℝ))| ∧ + (∑ e : incidentEdges i, p.2 e^2)/(n:ℝ)≤C} + have hbad (a : s) : ExponentiallyRare + (fun n => (μ n).prod (standardArrayLaw (Edge n))) (bad a) := by + apply exponentiallyRare_iUnion_polynomial _ _ hc (by norm_num : (0:ℝ)<3) + (by norm_num : (0:ℝ)<1) 1 + · exact Eventually.of_forall (fun n => by simp) + · filter_upwards [ht] with n hn i + apply hn (μ n) (incidentEdges i) + (fun ζ y e => G (a,b (diagonalField ζ (outsideDisorder β i y) (otherEnd i e)))) + (incidentEdges_card_le i) + · intro e + exact (hG.comp (continuous_const.prodMk (hb.continuous.comp + (continuous_outside_field β i (otherEnd i e))))).measurable + · intro ζ y e + exact hAb _ _ + let d := δ/(2*((K:ℝ)+1)) + have hd : 0 hfail (Or.inl (Or.inl ⟨i,hi⟩))) + have he : ∀ e, |affineDisorder β p.2 e|≤d := by + intro e + exact le_of_not_gt (fun hh => hfail (Or.inl (Or.inr ⟨e,hh⟩))) + have hg : ∀ a : s, ∀ i : Fin n, + |∑ e : incidentEdges i, + (affineDisorder β p.2 e^2-β^2/(n:ℝ))* + G (a,b (diagonalField p.1 (outsideDisorder β i (fun j => p.2 j)) (otherEnd i e)))|≤u/2 := by + intro a i + apply le_of_not_gt + intro hh + apply hfail + right + apply mem_iUnion.mpr + refine ⟨a,mem_iUnion.mpr ⟨i,?_,?_⟩⟩ + · simpa only [affineDisorder,mul_comm] using hh + · simpa only [Finset.sum_subtype (incidentEdges i) (fun _ => Iff.rfl)] using hr i + obtain ⟨i,a,hi⟩ := hp + have hsr : ∑ e : incidentEdges i, |affineDisorder β p.2 e^2-β^2/(n:ℝ)|≤R := + incident_absolute_square_error hn β p.2 hr i + have hf (e : incidentEdges i) : + |G (a,b (diagonalField p.1 (affineDisorder β p.2) (otherEnd i e)))- + G (q a,b (diagonalField p.1 (outsideDisorder β i (fun j => p.2 j)) (otherEnd i e)))|≤v := by + apply le_of_lt + rw [←Real.dist_eq] + apply hcont + rw [Prod.dist_eq,max_lt_iff] + refine ⟨hq a,?_⟩ + have hdist := hb.dist_le_mul + (diagonalField p.1 (affineDisorder β p.2) (otherEnd i e)) + (diagonalField p.1 (outsideDisorder β i (fun j => p.2 j)) (otherEnd i e)) + rw [Real.dist_eq,outside_field_error] at hdist + exact (hdist.trans (mul_le_mul_of_nonneg_left (he e) K.coe_nonneg)).trans_lt hKd + have herr := weighted_sum_difference_le + (fun e : incidentEdges i => affineDisorder β p.2 e^2-β^2/(n:ℝ)) + (fun e => G (a,b (diagonalField p.1 (affineDisorder β p.2) (otherEnd i e)))) + (fun e => G (q a,b (diagonalField p.1 (outsideDisorder β i (fun j => p.2 j)) (otherEnd i e)))) + hv.le hsr hf + have htri := abs_sub_abs_le_abs_sub + (∑ e : incidentEdges i, (affineDisorder β p.2 e^2-β^2/(n:ℝ))* + G (a,b (diagonalField p.1 (affineDisorder β p.2) (otherEnd i e)))) + (∑ e : incidentEdges i, (affineDisorder β p.2 e^2-β^2/(n:ℝ))* + G (q a,b (diagonalField p.1 (outsideDisorder β i (fun j => p.2 j)) (otherEnd i e)))) + have hgood := hg (q a) i + linarith only [htri,herr,hgood,hvR,hi] + +end SKRatio.Planted + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Matrices/WeightedGaussianSquares.lean b/lean/OAI/Probability/SKRatio/Matrices/WeightedGaussianSquares.lean new file mode 100644 index 0000000000000000000000000000000000000000..9a87fa45fd2c7ca7a7b486e84373e794eda1af7b --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Matrices/WeightedGaussianSquares.lean @@ -0,0 +1,155 @@ +import Mathlib +import OAI.Probability.SKRatio.Matrices.GaussianSquareMatrix + +namespace OAI + +section +noncomputable section +open scoped BigOperators NNReal ENNReal Topology +open MeasureTheory ProbabilityTheory Filter Set Real +namespace SKRatio.MatrixNet +open SKRatioClock.Regression +attribute [local instance] Classical.propDecidable + +lemma bounded_weights_sum_square {ι : Type*} (s : Finset ι) (a : ι → ℝ) + {A : ℝ} (hA : 0≤A) (ha : ∀ i∈s, |a i|≤A) {n : ℕ} (hn : s.card≤n) : + ∑ i∈s, a i^2 ≤ (n:ℝ)*A^2 := by + calc + _ ≤ ∑ _i∈s, A^2 := Finset.sum_le_sum (fun i hi => by + nlinarith [sq_abs (a i),ha i hi,abs_nonneg (a i)]) + _ = (s.card:ℝ)*A^2 := by simp + _ ≤ _ := mul_le_mul_of_nonneg_right (by exact_mod_cast hn) (sq_nonneg _) + +lemma weighted_centered_clip_tail {ι : Type*} [Fintype ι] + (s : Finset ι) (a : ι → ℝ) {A R : ℝ} (hA : 0 clippedSquare R x-(∫ y, clippedSquare R y ∂gaussianReal 0 1)) + (fun _ => ((continuous_clippedSquare R).sub continuous_const).measurable) + have his := hi.comp (fun i z => a i*z) (fun _ => measurable_const.mul measurable_id) + have hsum := HasSubgaussianMGF.sum_of_iIndepFun his (s := s) + (fun i _ => (centered_clip_subgaussian hR i).const_mul (a i)) + have hv : (∑ i∈s, (NNReal.mk (a i^2) (sq_nonneg (a i)))*(Real.toNNReal (R^2))^2) ≤ + Real.toNNReal ((n:ℝ)*A^2*R^4) := by + apply NNReal.coe_le_coe.mp + simp only [NNReal.coe_sum,NNReal.coe_mul,NNReal.coe_pow,NNReal.coe_mk, + Real.coe_toNNReal _ (sq_nonneg _), Real.coe_toNNReal _ (by positivity : (0:ℝ) ≤ (n:ℝ)*A^2*R^4), + ←Finset.sum_mul,show (R^2)^2=R^4 by ring] + exact mul_le_mul_of_nonneg_right (bounded_weights_sum_square s a hA.le ha hc) (by positivity) + have ht := subgaussian_abs_tail (subgaussian_mono hsum hv) (u*n) (by positivity) + have hnR : (0:ℝ) (ha i hi).trans (by linarith)) hn hs (by positivity : 0≤u/2) + have hcn : exp (-c*n) ≤ exp (-min c c'*n) := exp_le_exp.mpr (by + have := min_le_left c c'; nlinarith [Nat.cast_nonneg (α := ℝ) n]) + have hcn' : exp (-c'*n) ≤ exp (-min c c'*n) := exp_le_exp.mpr (by + have := min_le_right c c'; nlinarith [Nat.cast_nonneg (α := ℝ) n]) + have hc'id : -(u/2)^2*(n:ℝ)/(2*(A+1)^2*R^4) = -c'*n := by dsimp [c']; ring + rw [hc'id] at hF + calc + _ ≤ _ := measure_mono hsub + _ ≤ _ := measure_union_le E F + _ ≤ ENNReal.ofReal (exp (-c*n))+2*ENNReal.ofReal (exp (-c'*n)) := add_le_add hE hF + _ ≤ ENNReal.ofReal (exp (-min c c'*n))+2*ENNReal.ofReal (exp (-min c c'*n)) := + add_le_add (ENNReal.ofReal_le_ofReal hcn) (mul_le_mul_right (ENNReal.ofReal_le_ofReal hcn') _) + _ = _ := by rw [ENNReal.ofReal_mul (by norm_num : (0:ℝ)≤3)]; norm_num; ring + +end SKRatio.MatrixNet + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Matrices/WeightedSquares.lean b/lean/OAI/Probability/SKRatio/Matrices/WeightedSquares.lean new file mode 100644 index 0000000000000000000000000000000000000000..1f3c15bf4e78d789714080cf89bbee203ed4c48e --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Matrices/WeightedSquares.lean @@ -0,0 +1,136 @@ +import Mathlib +import OAI.Probability.SKRatio.Matrices.PlantedSquares + +namespace OAI + +section +noncomputable section +open scoped BigOperators NNReal ENNReal Topology +open MeasureTheory ProbabilityTheory Filter Set Real +namespace SKRatio.Planted +open SKRatioClock.Regression MatrixNet +attribute [local instance] Classical.propDecidable + +def squareError {n : ℕ} (β : ℝ) (g : Disorder n) : Matrix (Fin n) (Fin n) ℝ := + fun i j => coupling g i j^2-β^2/n + +lemma squareError_decomposition {n : ℕ} (β : ℝ) (g : Disorder n) : + squareError β g = Matrix.of (coupling (fun e => g e^2-β^2/n)) - + Matrix.diagonal (fun _ => β^2/(n:ℝ)) := by + ext i j + by_cases h : i=j + · subst j + simp [squareError,coupling] + · rcases lt_or_gt_of_ne h with hij | hij + · simp [squareError,coupling,hij,h] + · simp [squareError,coupling,hij,not_lt_of_gt hij,h] + +lemma squareError_symmetric {n : ℕ} (β : ℝ) (g : Disorder n) (i j : Fin n) : + squareError β g i j = squareError β g j i := by + simp only [squareError,coupling_symm g i j] + +theorem squareError_rare (β : ℝ) {u : ℝ} (hu : 0 {g | u < + ‖Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) (squareError β g)‖}) := by + have h := square_matrix_rare β (half_pos hu) + have ht : Tendsto (fun n : ℕ => β^2/(n:ℝ)) atTop (𝓝 0) := + tendsto_const_nhds.div_atTop tendsto_natCast_atTop_atTop + apply h.mono + filter_upwards [ht.eventually (gt_mem_nhds (half_pos hu))] with n hn + intro g hg + change u/2 < _ + apply lt_of_not_ge + intro hsmall + have hd := matrix_diagonal_opNorm_le (n := n) (fun _ => β^2/(n:ℝ)) + (β^2/(n:ℝ)) (by positivity) (fun _ => le_of_eq (abs_of_nonneg (by positivity))) + have hh : ‖Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) (squareError β g)‖ ≤ + ‖Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) (coupling (fun e => g e^2-β^2/n))‖+ + β^2/(n:ℝ) := by + rw [squareError_decomposition,map_sub] + exact (norm_sub_le _ _).trans (add_le_add_right hd _) + change u < _ at hg + change _ ≤ u/2 at hsmall + linarith only [hh,hg,hsmall,hn] + +lemma coupling_sq {n : ℕ} (g : Disorder n) (i j : Fin n) : + coupling g i j^2 = coupling (fun e => g e^2) i j := by + unfold coupling + split_ifs <;> simp + +lemma affine_square_row_bound {n : ℕ} (hn : 0 {g | ∃ i : Fin n, C < ∑ j, coupling g i j^2}) := by + obtain ⟨C,hC,hrows⟩ := gaussian_rows_square_bounded + let D := 2*β^2*C+2*β^4+1 + have hD : 0 standardArrayLaw (Edge n)) + (fun n => {z | ∃ i : Fin n, D < ∑ j, coupling (affineDisorder β z) i j^2}) := by + apply hrows.mono + filter_upwards [eventually_gt_atTop 0] with n hn + rintro z ⟨i,hi⟩ + by_contra hnot + have hrow : ∀ j, (∑ e ∈ incidentEdges j, z e^2)/(n:ℝ) ≤ C := by + intro j + exact le_of_not_gt (fun hj => hnot ⟨j,hj⟩) + have hs := affine_square_row_bound hn β z hrow i + dsimp [D] at hi + linarith only [hs,hi] + obtain ⟨A,c,hA,hc,hb⟩ := ht + refine ⟨D,hD,A,c,hA,hc,?_⟩ + filter_upwards [hb,eventually_gt_atTop 0] with n hn hn0 + have hm : MeasurableSet {g : Disorder n | ∃ i : Fin n, D < ∑ j, coupling g i j^2} := by + simp only [Set.ofPred_exists] + apply MeasurableSet.iUnion + intro i + apply measurableSet_lt measurable_const + exact (continuous_finsetSum _ (fun j _ => (continuous_coupling i j).pow 2)).measurable + rw [←(affineDisorder_hasLaw hn0 β).measure_eq hm] + exact hn + +lemma squareError_absolute_row {n : ℕ} (β : ℝ) (g : Disorder n) (i : Fin n) : + ∑ j, |squareError β g i j| ≤ (∑ j, coupling g i j^2)+β^2 := by + calc + _ ≤ ∑ j, (coupling g i j^2+β^2/(n:ℝ)) := by + apply Finset.sum_le_sum + intro j _ + exact (abs_sub _ _).trans (by rw [abs_of_nonneg (sq_nonneg _),abs_of_nonneg (by positivity)]) + _ ≤ _ := by + rw [Finset.sum_add_distrib] + simp only [Finset.sum_const,Finset.card_univ,Fintype.card_fin,nsmul_eq_mul] + have hn : (n:ℝ) ≠ 0 := Nat.cast_ne_zero.mpr (by have := i.isLt; omega) + rw [mul_div_cancel₀ _ hn] + +end SKRatio.Planted + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Quantization/BinCoefficients.lean b/lean/OAI/Probability/SKRatio/Quantization/BinCoefficients.lean new file mode 100644 index 0000000000000000000000000000000000000000..bb000bd1a5124ed9055fbe0c16fb63ca1a821dfb --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Quantization/BinCoefficients.lean @@ -0,0 +1,185 @@ +import Mathlib +import OAI.Probability.SKRatio.Quantization.BinGeometry + +namespace OAI + +noncomputable section +open scoped BigOperators Matrix +open MeasureTheory ProbabilityTheory Filter Real +namespace SKRatio.Bins +variable {ι α : Type*} [Fintype ι] [Fintype α] [DecidableEq α] + +def matrixInner (A B : Matrix ι ι ℝ) : ℝ := ∑ i, ∑ j, A i j*B i j + +lemma matrixInner_symm (A B : Matrix ι ι ℝ) : matrixInner A B=matrixInner B A := by + simp only [matrixInner,mul_comm] + +lemma matrixInner_add_left (A B C : Matrix ι ι ℝ) : + matrixInner (A+B) C=matrixInner A C+matrixInner B C := by + simp [matrixInner,add_mul,Finset.sum_add_distrib] + +lemma matrixInner_add_right (A B C : Matrix ι ι ℝ) : + matrixInner A (B+C)=matrixInner A B+matrixInner A C := by + simp [matrixInner,mul_add,Finset.sum_add_distrib] + +lemma matrixInner_transpose (A B : Matrix ι ι ℝ) : + matrixInner Aᵀ Bᵀ=matrixInner A B := by + unfold matrixInner + exact Finset.sum_comm + +lemma matrixInner_transpose_left (A B : Matrix ι ι ℝ) : + matrixInner Aᵀ B=matrixInner A Bᵀ := by + simpa only [Matrix.transpose_transpose] using matrixInner_transpose A Bᵀ + +lemma matrixInner_sq_sub (A B : Matrix ι ι ℝ) : + (∑ i, ∑ j, (A i j-B i j)^2)=matrixInner A A+matrixInner B B-2*matrixInner A B := by + simp only [matrixInner,Finset.mul_sum,←Finset.sum_add_distrib,←Finset.sum_sub_distrib] + apply Finset.sum_congr rfl + intro i _ + apply Finset.sum_congr rfl + intro j _ + ring + +def linearMatrix (σ : ι → α) (C : α → α → ℝ) (u : ι → ℝ) : Matrix ι ι ℝ := + fun i j => u i*C (σ i) (σ j) + +def quadraticMatrix (σ : ι → α) (K : α → α → ℝ) (u : ι → ℝ) : Matrix ι ι ℝ := + fun i j => K (σ i) (σ j)*u i*u j + +def binVariance (σ : ι → α) (C : α → α → ℝ) (a : α) : ℝ := + ∑ j, C a (σ j)^2 + +omit [Fintype α] [DecidableEq α] in +lemma binVariance_nonneg (σ : ι → α) (C : α → α → ℝ) (a : α) : + 0 ≤ binVariance σ C a := Finset.sum_nonneg (fun _ _ => sq_nonneg _) + +lemma linearMatrix_inner (σ : ι → α) (C : α → α → ℝ) (u z : ι → ℝ) : + matrixInner (linearMatrix σ C u) (linearMatrix σ C z) = + ∑ a, overlap σ u z a*binVariance σ C a := by + unfold matrixInner linearMatrix + have he (i j : ι) : u i*C (σ i) (σ j)*(z i*C (σ i) (σ j)) = + (u i*z i)*C (σ i) (σ j)^2 := by ring + simp_rw [he,←Finset.mul_sum] + exact sum_weighted σ (fun i => u i*z i) (binVariance σ C) + +lemma linearMatrix_cross_zero {σ : ι → α} (C : α → α → ℝ) {u : ι → ℝ} + (hu : ZeroSum σ u) (z : ι → ℝ) : + matrixInner (linearMatrix σ C u) (linearMatrix σ C z)ᵀ=0 := by + unfold matrixInner linearMatrix + change (∑ i, ∑ j, u i*C (σ i) (σ j)*(z j*C (σ j) (σ i)))=0 + convert zero_sum_bilinear hu z (fun a d => C a d*C d a) using 1 + apply Finset.sum_congr rfl + intro i _ + apply Finset.sum_congr rfl + intro j _ + ring + +omit [Fintype ι] [Fintype α] [DecidableEq α] in +lemma quadraticMatrix_transpose (σ : ι → α) (K : α → α → ℝ) + (hK : ∀ a d, K a d=K d a) (u : ι → ℝ) : (quadraticMatrix σ K u)ᵀ=quadraticMatrix σ K u := by + ext i j + simp only [quadraticMatrix,Matrix.transpose_apply,hK (σ j) (σ i)] + ring + +lemma linear_quadratic_inner_zero {σ : ι → α} (C K : α → α → ℝ) (u : ι → ℝ) + {z : ι → ℝ} (hz : ZeroSum σ z) : + matrixInner (linearMatrix σ C u) (quadraticMatrix σ K z)=0 := by + unfold matrixInner linearMatrix quadraticMatrix + apply Finset.sum_eq_zero + intro i _ + convert zero_sum_weighted hz (fun d => u i*z i*C (σ i) d*K (σ i) d) using 1 + apply Finset.sum_congr rfl + intro j _ + ring + +lemma quadraticMatrix_inner (σ : ι → α) (K : α → α → ℝ) (u z : ι → ℝ) : + matrixInner (quadraticMatrix σ K u) (quadraticMatrix σ K z)= + ∑ a, ∑ d, K a d^2*overlap σ u z a*overlap σ u z d := by + have he (i j : ι) : (K (σ i) (σ j)*u i*u j)*(K (σ i) (σ j)*z i*z j)= + (u i*z i)*(u j*z j)*K (σ i) (σ j)^2 := by ring + unfold matrixInner quadraticMatrix + simp_rw [he] + rw [double_weighted σ (fun i => u i*z i) (fun i => u i*z i) (fun a d => K a d^2)] + apply Finset.sum_congr rfl + intro a _ + apply Finset.sum_congr rfl + intro d _ + change overlap σ u z a*overlap σ u z d*K a d^2= _ + ring + +def residualMatrix (σ : ι → α) (C K : α → α → ℝ) (u : ι → ℝ) : Matrix ι ι ℝ := + linearMatrix σ C u+(linearMatrix σ C u)ᵀ+quadraticMatrix σ K u + +lemma residualMatrix_inner {σ : ι → α} (C K : α → α → ℝ) + (hK : ∀ a d, K a d=K d a) {u z : ι → ℝ} + (hu : ZeroSum σ u) (hz : ZeroSum σ z) : + matrixInner (residualMatrix σ C K u) (residualMatrix σ C K z)= + 2*(∑ a, overlap σ u z a*binVariance σ C a)+ + ∑ a, ∑ d, K a d^2*overlap σ u z a*overlap σ u z d := by + unfold residualMatrix + simp only [matrixInner_add_left,matrixInner_add_right] + rw [matrixInner_transpose_left _ (quadraticMatrix σ K z),quadraticMatrix_transpose σ K hK z] + rw [matrixInner_symm (quadraticMatrix σ K u) _,matrixInner_symm (quadraticMatrix σ K u) _] + rw [matrixInner_transpose_left _ (quadraticMatrix σ K u),quadraticMatrix_transpose σ K hK u] + simp only [linearMatrix_cross_zero C hu,linear_quadratic_inner_zero C K u hz, + linear_quadratic_inner_zero C K z hu,matrixInner_transpose_left,Matrix.transpose_transpose, + linearMatrix_inner,quadraticMatrix_inner,add_zero,zero_add] + ring + +lemma residualMatrix_increment {σ : ι → α} (C K : α → α → ℝ) + (hK : ∀ a d, K a d=K d a) {u z : ι → ℝ} {s : α → ℝ} + (hu : ZeroSum σ u) (hz : ZeroSum σ z) + (hus : overlap σ u u=s) (hzs : overlap σ z z=s) : + (∑ i, ∑ j, (residualMatrix σ C K u i j-residualMatrix σ C K z i j)^2) ≤ + 4*∑ a, (s a-overlap σ u z a)*(binVariance σ C a+∑ d, K a d^2*s d) := by + rw [matrixInner_sq_sub,residualMatrix_inner C K hK hu hu, + residualMatrix_inner C K hK hz hz,residualMatrix_inner C K hK hu hz,hus,hzs] + let q := overlap σ u z + have hq : ∀ a, q a ≤ s a := overlap_le hus hzs + have hineq : (∑ a, ∑ d, K a d^2*(s a*s d-q a*q d)) ≤ + ∑ a, ∑ d, K a d^2*(s a*(s d-q d)+s d*(s a-q a)) := by + apply Finset.sum_le_sum + intro a _ + apply Finset.sum_le_sum + intro d _ + exact mul_le_mul_of_nonneg_left (overlap_product_bound hq a d) (sq_nonneg _) + have he : (∑ a, ∑ d, K a d^2*(s a*(s d-q d)+s d*(s a-q a))) = + 2*∑ a, (s a-q a)*(∑ d, K a d^2*s d) := by + simp only [mul_add,Finset.sum_add_distrib] + have hs : (∑ a, ∑ d, K a d^2*(s a*(s d-q d))) = + ∑ a, ∑ d, K a d^2*(s d*(s a-q a)) := by + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro a _ + apply Finset.sum_congr rfl + intro d _ + rw [hK d a] + rw [hs] + rw [two_mul] + congr 1 <;> apply Finset.sum_congr rfl + all_goals + intro a _ + rw [Finset.mul_sum] + apply Finset.sum_congr rfl + intro d _ + ring + rw [he] at hineq + have he1 : (∑ a, ∑ d, K a d^2*(s a*s d-q a*q d)) = + (∑ a, ∑ d, K a d^2*s a*s d)-(∑ a, ∑ d, K a d^2*q a*q d) := by + simp only [mul_sub,Finset.sum_sub_distrib,mul_assoc] + have he2 : (∑ a, (s a-q a)*(binVariance σ C a+∑ d, K a d^2*s d)) = + (∑ a, s a*binVariance σ C a)-(∑ a, q a*binVariance σ C a)+ + ∑ a, (s a-q a)*(∑ d, K a d^2*s d) := by + simp only [mul_add,sub_mul,Finset.sum_add_distrib,Finset.sum_sub_distrib] + rw [he1] at hineq + change _ ≤ 4*∑ a, (s a-q a)*(binVariance σ C a+∑ d, K a d^2*s d) + rw [he2] + dsimp only [q] at hineq + dsimp only [q] + linarith only [hineq] + +end SKRatio.Bins + +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Quantization/BinDirections.lean b/lean/OAI/Probability/SKRatio/Quantization/BinDirections.lean new file mode 100644 index 0000000000000000000000000000000000000000..b9b702887e98910a1bcbbd4f94c9ccadae9a091c --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Quantization/BinDirections.lean @@ -0,0 +1,231 @@ +import Mathlib +import OAI.Probability.SKRatio.Quantization.BinParameters + +namespace OAI + +noncomputable section +open scoped BigOperators +open MeasureTheory ProbabilityTheory Filter Real +namespace SKRatio.Bins +variable {ι α : Type*} [Fintype ι] [DecidableEq α] +attribute [local instance] Classical.propDecidable + +lemma sum_scale_bin (σ : ι → α) (c : α → ℝ) (u : ι → ℝ) (a : α) : + sum σ (fun i => c (σ i)*u i) a = c a*sum σ u a := by + unfold sum + rw [Finset.mul_sum] + apply Finset.sum_congr rfl + intro i hi + dsimp only [] + rw [(Finset.mem_filter.mp hi).2] + +lemma zeroSum_scale_bin {σ : ι → α} (c : α → ℝ) {u : ι → ℝ} (hu : ZeroSum σ u) : + ZeroSum σ (fun i => c (σ i)*u i) := by + intro a + rw [sum_scale_bin,hu a,mul_zero] + +lemma overlap_scale_bin (σ : ι → α) (c : α → ℝ) (u : ι → ℝ) (a : α) : + overlap σ (fun i => c (σ i)*u i) (fun i => c (σ i)*u i) a = + c a^2*overlap σ u u a := by + have he : (fun i => (c (σ i)*u i)*(c (σ i)*u i)) = + fun i => c (σ i)^2*(u i*u i) := by ext i; ring + rw [overlap,he,sum_scale_bin σ (fun a => c a^2)] + rfl + +def DirectionSet (σ : ι → α) : Set (EuclideanSpace ℝ ι) := + {u | ∀ a, sum σ u a=0 ∧ overlap σ u u a=1} + +abbrev Directions (σ : ι → α) := ↥(DirectionSet σ) + +lemma directions_zeroSum {σ : ι → α} (u : Directions σ) : ZeroSum σ u.val := + fun a => (u.property a).1 + +lemma directions_overlap {σ : ι → α} (u : Directions σ) (a : α) : + overlap σ u.val u.val a=1 := (u.property a).2 + +variable [Fintype α] + +lemma directions_norm_sq {σ : ι → α} (u : Directions σ) : ‖u.val‖^2=(Fintype.card α:ℝ) := by + rw [EuclideanSpace.real_norm_sq_eq,←sum_fibers σ] + have he (a : α) : sum σ (fun i => u.val i^2) a=1 := by + simpa only [pow_two,overlap] using directions_overlap u a + simp only [he,Finset.sum_const,Finset.card_univ,nsmul_eq_mul,mul_one] + +omit [Fintype α] in +lemma directionSet_closed (σ : ι → α) : IsClosed (DirectionSet σ) := by + simp only [DirectionSet,Set.ofPred_forall,Set.ofPred_and] + apply isClosed_iInter + intro a + apply IsClosed.inter <;> apply isClosed_eq _ continuous_const + · exact continuous_finsetSum _ (fun i _ => (EuclideanSpace.proj i).continuous) + · exact continuous_finsetSum _ (fun i _ => (EuclideanSpace.proj i).continuous.mul + (EuclideanSpace.proj i).continuous) + +lemma directionSet_compact (σ : ι → α) : IsCompact (DirectionSet σ) := by + apply (isCompact_closedBall (0 : EuclideanSpace ℝ ι) (sqrt (Fintype.card α))).of_isClosed_subset + (directionSet_closed σ) + intro u hu + simp only [Metric.mem_closedBall,dist_zero_right] + have hs := directions_norm_sq (⟨u,hu⟩ : Directions σ) + exact (le_sqrt (norm_nonneg _) (Nat.cast_nonneg _)).mpr hs.le + +instance (σ : ι → α) : CompactSpace (Directions σ) := isCompact_iff_compactSpace.mp (directionSet_compact σ) + +omit [Fintype α] in +lemma two_sites_of_count {σ : ι → α} (hcount : ∀ a, 2≤count σ a) (a : α) : + ∃ i j : ι, σ i=a ∧ σ j=a ∧ i≠j := by + obtain ⟨i,hi,j,hj,hij⟩ := Finset.one_lt_card.mp (show 1<(Finset.univ.filter (fun i => σ i=a)).card from hcount a) + exact ⟨i,j,(Finset.mem_filter.mp hi).2,(Finset.mem_filter.mp hj).2,hij⟩ + +omit [Fintype α] in +lemma directions_nonempty {σ : ι → α} (hcount : ∀ a, 2≤count σ a) : Nonempty (Directions σ) := by + choose i j hi hj hij using two_sites_of_count hcount + let u : ι → ℝ := fun k => (if k=i (σ k) then 1/sqrt 2 else 0)- + (if k=j (σ k) then 1/sqrt 2 else 0) + refine ⟨⟨WithLp.toLp 2 u,fun a => ?_⟩⟩ + have himem : i a∈Finset.univ.filter (fun k => σ k=a) := by simp only [Finset.mem_filter,Finset.mem_univ,true_and,hi] + have hjmem : j a∈Finset.univ.filter (fun k => σ k=a) := by simp only [Finset.mem_filter,Finset.mem_univ,true_and,hj] + have hue (k : ι) (hk : k∈Finset.univ.filter (fun k => σ k=a)) : + u k = (if k=i a then 1/sqrt 2 else 0)-(if k=j a then 1/sqrt 2 else 0) := by + dsimp only [u] + rw [(Finset.mem_filter.mp hk).2] + constructor + · change (∑ k with σ k=a, u k)=0 + rw [Finset.sum_congr rfl hue,Finset.sum_sub_distrib] + simp only [Finset.sum_ite_eq',himem,hjmem,ite_true,sub_self] + · change (∑ k with σ k=a, u k*u k)=1 + have hh (k : ι) (hk : k∈Finset.univ.filter (fun k => σ k=a)) : + u k*u k=(if k=i a then (1:ℝ)/2 else 0)+(if k=j a then (1:ℝ)/2 else 0) := by + rw [hue k hk] + split_ifs with hki hkj + · exact False.elim (hij a (hki.symm.trans hkj)) + · simp only [sub_zero,←pow_two,div_pow,one_pow,sq_sqrt (show (0:ℝ)≤2 by norm_num),add_zero] + · simp only [zero_sub,←pow_two,neg_sq,div_pow,one_pow,sq_sqrt (show (0:ℝ)≤2 by norm_num),zero_add] + · ring + rw [Finset.sum_congr rfl hh,Finset.sum_add_distrib] + simp only [Finset.sum_ite_eq',himem,hjmem,ite_true] + norm_num + +def vectorOf {σ : ι → α} (z : Parameters α) (u : Directions σ) (i : ι) : ℝ := + paramB z (σ i)/sqrt (count σ (σ i):ℝ)+paramR z (σ i)*u.val i + +lemma vectorOf_unit {σ : ι → α} (hcount : ∀ a, 0 vectorOf z u i^2) a = + (paramB z a)^2+(paramR z a)^2 := by + simp only [vectorOf] + rw [bin_orthogonal_decomposition (zeroSum_scale_bin (paramR z) (directions_zeroSum u)) + (fun a => paramB z a/sqrt (count σ a:ℝ)) a, + overlap_scale_bin,directions_overlap,mul_one,div_pow,sq_sqrt (Nat.cast_nonneg _)] + congr 1 + exact mul_div_cancel₀ _ (Nat.cast_ne_zero.mpr (hcount a).ne') + simp only [he,param_sum_sq] + +lemma vectorOf_continuous {σ : ι → α} (z : Parameters α) : + Continuous (fun u : Directions σ => vectorOf z u) := by + apply continuous_pi + intro i + exact continuous_const.add (((EuclideanSpace.proj i).continuous.comp continuous_subtype_val).const_mul _) + +lemma scaled_directions_continuous {σ : ι → α} (z : Parameters α) : + Continuous (fun u : Directions σ => fun i => paramR z (σ i)*u.val i) := by + apply continuous_pi + intro i + exact ((EuclideanSpace.proj i).continuous.comp continuous_subtype_val).const_mul _ + +lemma vectorOf_difference {σ : ι → α} (hcount : ∀ a, 0 vectorOf z u i-vectorOf z' u i)‖=‖z.val-z'.val‖ := by + have he (i : ι) : vectorOf z u i-vectorOf z' u i= + (paramB z (σ i)-paramB z' (σ i))/sqrt (count σ (σ i):ℝ)+ + (paramR z (σ i)-paramR z' (σ i))*u.val i := by unfold vectorOf; ring + have hs : ‖WithLp.toLp 2 (fun i => vectorOf z u i-vectorOf z' u i)‖^2=‖z.val-z'.val‖^2 := by + rw [EuclideanSpace.real_norm_sq_eq,EuclideanSpace.real_norm_sq_eq] + simp only [he,←sum_fibers σ] + have hh (a : α) : sum σ (fun i => + ((paramB z (σ i)-paramB z' (σ i))/sqrt (count σ (σ i):ℝ)+ + (paramR z (σ i)-paramR z' (σ i))*u.val i)^2) a= + (paramB z a-paramB z' a)^2+(paramR z a-paramR z' a)^2 := by + rw [bin_orthogonal_decomposition (zeroSum_scale_bin (fun a => paramR z a-paramR z' a) (directions_zeroSum u)) + (fun a => (paramB z a-paramB z' a)/sqrt (count σ a:ℝ)) a, + overlap_scale_bin σ (fun a => paramR z a-paramR z' a),directions_overlap,mul_one,div_pow,sq_sqrt (Nat.cast_nonneg _)] + congr 1 + exact mul_div_cancel₀ _ (Nat.cast_ne_zero.mpr (hcount a).ne') + conv_lhs => + arg 2 + intro a + rw [hh a] + simp only [Finset.sum_add_distrib,Fintype.sum_sum_type,PiLp.sub_apply,paramB,paramR] + exact (sq_eq_sq₀ (norm_nonneg _) (norm_nonneg _)).mp hs + +omit [Fintype α] in +lemma fiber_sq_le (σ : ι → α) (u : ι → ℝ) (i : ι) : + u i^2≤overlap σ u u (σ i) := by + simpa only [overlap,sum,pow_two] using + Finset.single_le_sum (s := Finset.univ.filter (fun k => σ k=σ i)) + (f := fun k => u k^2) (fun k _ => sq_nonneg (u k)) (by simp) + +omit [Fintype α] in +lemma fiber_zero_of_sqrt_zero {σ : ι → α} {u : ι → ℝ} {i : ι} + (h : sqrt (overlap σ u u (σ i))=0) : u i=0 := by + have ht : overlap σ u u (σ i)=0 := by + simpa only [h,zero_pow (by decide : (2:ℕ)≠0)] using (sq_sqrt (overlap_self_nonneg σ u (σ i))).symm + have hs := fiber_sq_le σ u i + rw [ht] at hs + exact sq_eq_zero_iff.mp (le_antisymm hs (sq_nonneg _)) + +theorem vectorOf_surjective {σ : ι → α} (hcount : ∀ a, 2≤count σ a) + (p : ι → ℝ) (hp : ∑ i, p i^2=1) : + ∃ u : Directions σ, vectorOf (parametersOf σ p hp) u=p := by + obtain ⟨u₀⟩ := directions_nonempty hcount + let q := binCentered σ p + let r := fun a => sqrt (overlap σ q q a) + let u : ι → ℝ := fun i => if r (σ i)=0 then u₀.val i else (r (σ i))⁻¹*q i + have hu : WithLp.toLp 2 u ∈ DirectionSet σ := by + intro a + by_cases hr : r a=0 + · have he : ∀ i∈Finset.univ.filter (fun i => σ i=a), u i=u₀.val i := by + intro i hi + dsimp only [u] + rw [(Finset.mem_filter.mp hi).2,ite_eq_left hr] + constructor + · exact (Finset.sum_congr rfl he).trans (directions_zeroSum u₀ a) + · exact (Finset.sum_congr rfl (fun i hi => congrArg (fun t : ℝ => t*t) (he i hi))).trans + (directions_overlap u₀ a) + · have he : ∀ i∈Finset.univ.filter (fun i => σ i=a), u i=(r a)⁻¹*q i := by + intro i hi + dsimp only [u] + rw [(Finset.mem_filter.mp hi).2,ite_eq_right hr] + constructor + · change (∑ i with σ i=a, u i)=0 + rw [Finset.sum_congr rfl he,←Finset.mul_sum] + change (r a)⁻¹*sum σ q a=0 + rw [binCentered_zeroSum σ p a,mul_zero] + · change (∑ i with σ i=a, u i*u i)=1 + have hs (i : ι) (hi : i∈Finset.univ.filter (fun i => σ i=a)) : + u i*u i=((r a)⁻¹)^2*(q i*q i) := by rw [he i hi]; ring + rw [Finset.sum_congr rfl hs,←Finset.mul_sum] + change ((r a)⁻¹)^2*overlap σ q q a=1 + rw [←sq_sqrt (overlap_self_nonneg σ q a)] + change (r a)⁻¹^2*r a^2=1 + simpa only [inv_pow] using inv_mul_cancel₀ (pow_ne_zero 2 hr) + refine ⟨⟨WithLp.toLp 2 u,hu⟩,?_⟩ + funext i + simp only [vectorOf,parametersOf_B,parametersOf_R] + have hpos : sqrt (count σ (σ i):ℝ)≠0 := (sqrt_pos.mpr (Nat.cast_pos.mpr (lt_of_lt_of_le (by norm_num) (hcount (σ i))))).ne' + rw [mul_div_cancel_left₀ _ hpos] + change binMean σ p (σ i)+r (σ i)*u i=p i + rw [binCentered_decomp σ p i] + congr 1 + by_cases hr : r (σ i)=0 + · have hqi : q i=0 := fiber_zero_of_sqrt_zero hr + rw [hr,zero_mul] + exact hqi.symm + · simp only [u,ite_eq_right hr,←mul_assoc,mul_inv_cancel₀ hr,one_mul,q] + +end SKRatio.Bins + +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Quantization/BinEmpirical.lean b/lean/OAI/Probability/SKRatio/Quantization/BinEmpirical.lean new file mode 100644 index 0000000000000000000000000000000000000000..334cd291640ef7271223ce1566c7672d2ce94aac --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Quantization/BinEmpirical.lean @@ -0,0 +1,60 @@ +import Mathlib +import OAI.Probability.SKRatio.Quantization.BinPartition +import OAI.Probability.SKRatio.Quantization.IntervalBins + +namespace OAI + +noncomputable section +open scoped BigOperators NNReal ENNReal Topology +open MeasureTheory ProbabilityTheory Filter Real +namespace SKRatio.Bins +open Planted Scalar SKRatioClock.Regression +variable {Ω : ℕ → Type*} [∀ n, MeasurableSpace (Ω n)] + {ρ : ∀ n, Measure (Ω n)} {X : ∀ n, Ω n → Fin n → ℝ} + {μ : Measure ℝ} [IsProbabilityMeasure μ] [NullSingletonClass μ] + {N : ℕ} {e : Fin N → ℝ} + +lemma binT_eq_sqrt {α : Type*} [Fintype α] [DecidableEq α] {n : ℕ} + (σ : Fin n → α) (d : α) : binT σ d=sqrt ((count σ d:ℝ)/(n:ℝ)) := by + rw [binT,Fintype.card_fin,sqrt_div (Nat.cast_nonneg _)] + +lemma intervalBin_roots_empirical (hN : 0 binT (fun i => intervalBin e (X n ω i))) + (massRoot μ (intervalBin e)) := by + apply ExponentialConvergence.pi_finite + intro d + have hh := (intervalBin_empirical hN he hX d).continuous_map continuous_sqrt.continuousAt + simpa only [binT_eq_sqrt,massRoot,binMass] using hh + +lemma intervalBin_binSize_rare (hN : 0 {ω | ∃ d, count (fun i => intervalBin e (X n ω i)) d<2}) := by + have hd (d : Fin (N+1)) : ExponentiallyRare ρ + (fun n => {ω | count (fun i => intervalBin e (X n ω i)) d<2}) := by + let p := binMass μ (intervalBin e) d + have hp : 0

(n:ℝ)) atTop atTop).eventually + (eventually_ge_atTop (4/p)) + filter_upwards [hlarge,eventually_gt_atTop 0] with n hn hn0 + intro ω hω + have hc : (count (fun i => intervalBin e (X n ω i)) d:ℝ)≤1 := by + exact_mod_cast (show count (fun i => intervalBin e (X n ω i)) d≤1 from by simpa using hω) + have hnR : (0:ℝ) intervalBin e (X n ω i)) d:ℝ)/(n:ℝ)-p| + have hpn := (div_le_iff₀ hp).mp hn + have hu : (count (fun i => intervalBin e (X n ω i)) d:ℝ)/(n:ℝ)≤p/2 := by + apply (div_le_iff₀ hnR).mpr + nlinarith only [hc,hpn] + have hh := neg_le_abs ((count (fun i => intervalBin e (X n ω i)) d:ℝ)/(n:ℝ)-p) + linarith only [hu,hh] + apply (ExponentiallyRare.iUnion_finite hd).mono + exact .of_forall (fun _ _ ⟨d,hd⟩ => Set.mem_iUnion.mpr ⟨d,hd⟩) + +end SKRatio.Bins + +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Quantization/BinForm.lean b/lean/OAI/Probability/SKRatio/Quantization/BinForm.lean new file mode 100644 index 0000000000000000000000000000000000000000..796c761633bf268220a60dc6b996b4de2af86123 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Quantization/BinForm.lean @@ -0,0 +1,111 @@ +import Mathlib +import OAI.Probability.SKRatio.Quantization.BinFunctional + +namespace OAI + +noncomputable section +open scoped BigOperators Matrix +open MeasureTheory ProbabilityTheory Filter Real +namespace SKRatio.Bins +open Planted Scalar SKRatioClock.Regression +variable {α : Type*} [Fintype α] [DecidableEq α] {n : ℕ} +attribute [local instance] Classical.propDecidable + +def siteMoment (p f : Fin n → ℝ) : ℝ := (∑ i, p i*f i)/sqrt (n:ℝ) + +lemma siteMoment_bin {σ : Fin n → α} (hcount : ∀ a, 0 f (σ i)) = moment (binT σ) (paramB z) f := by + simpa only [siteMoment,Fintype.card_fin] using vectorOf_moment hcount z u f + +lemma momentProduct (p f q k : Fin n → ℝ) : + siteMoment p f*siteMoment q k=(∑ i, p i*f i)*(∑ i, q i*k i)/(n:ℝ) := by + unfold siteMoment + rw [div_mul_div_comm,←pow_two,sq_sqrt (Nat.cast_nonneg n)] + +def correctedForm (β : ℝ) (H p : Fin n → ℝ) : ℝ := + siteMoment p H*siteMoment p (fun i => v (H i))+ + siteMoment p (fun _ => 1)*siteMoment p (fun i => H i*v (H i))- + β^2*siteMoment p (fun _ => 1)*siteMoment p (fun i => v (H i))+ + 2*β^2*siteMoment p (fun _ => 1)*siteMoment p (fun i => m (H i)*v (H i))+ + diagonalForm (fun _ _ => β^2/(n:ℝ)) compactF (fun i => compactWeight (H i)) p+ + weightedForm (fun _ _ => β^2/(n:ℝ)) compactK (fun i => compactWeight (H i)) p + +lemma deterministic_corrected (β : ℝ) (H p : Fin n → ℝ) : + deterministicForm β H p = correctedForm β H p+ + (β^2-(∑ i, H i)/(n:ℝ))*siteMoment p (fun _ => 1)*siteMoment p (fun i => v (H i)) := by + unfold deterministicForm correctedForm rankForm + simp only [mul_assoc] + simp only [←mul_assoc,momentProduct,mul_one,Finset.sum_mul] + ring + +lemma diagonalForm_bin {σ : Fin n → α} (hcount : ∀ a, 0 β^2/(n:ℝ)) compactF + (fun i => compactWeight (h (σ i))) (vectorOf z u) = + β^2*(∑ a, ∑ d, binT σ d^2*(v (h d)^2/(w (h a)+w (h d)))* + ((paramB z a)^2+(paramR z a)^2)) := by + let p := vectorOf z u + let K : α → α → ℝ := fun a d => v (h d)^2/(w (h a)+w (h d)) + have he : diagonalForm (fun _ _ => β^2/(n:ℝ)) compactF + (fun i => compactWeight (h (σ i))) p = + β^2/(n:ℝ)*(∑ i, ∑ j, p i^2*(1:ℝ)*K (σ i) (σ j)) := by + simp only [diagonalForm,compactF_weight,Finset.sum_mul,Finset.mul_sum,K,mul_one] + apply Finset.sum_congr rfl + intro i _ + apply Finset.sum_congr rfl + intro j _ + ring + rw [he,double_weighted σ (fun i => p i^2) (fun _ => 1) K] + simp only [p,vectorOf_sq_sum hcount,sum_const_bin σ (fun _ => 1),mul_one, + binT_sq,Fintype.card_fin,Finset.mul_sum] + apply Finset.sum_congr rfl + intro a _ + apply Finset.sum_congr rfl + intro d _ + dsimp [K] + ring + +lemma weightedForm_bin {σ : Fin n → α} (hcount : ∀ a, 0 β^2/(n:ℝ)) compactK + (fun i => compactWeight (h (σ i))) (vectorOf z u) = + β^2*(∑ a, ∑ d, binT σ a*paramB z a*kernel (h a) (h d)*(binT σ d*paramB z d)) := by + let p := vectorOf z u + have he : weightedForm (fun _ _ => β^2/(n:ℝ)) compactK + (fun i => compactWeight (h (σ i))) p = + β^2/(n:ℝ)*(∑ i, ∑ j, p i*p j*kernel (h (σ i)) (h (σ j))) := by + simp only [weightedForm,quadratic,compactK_weight,Finset.mul_sum] + apply Finset.sum_congr rfl + intro i _ + apply Finset.sum_congr rfl + intro j _ + ring + rw [he,double_weighted σ p p (fun a d => kernel (h a) (h d))] + simp only [p,vectorOf_sum hcount,binT,Fintype.card_fin,Finset.mul_sum] + apply Finset.sum_congr rfl + intro a _ + apply Finset.sum_congr rfl + intro d _ + rw [show sqrt (count σ a:ℝ)/sqrt (n:ℝ)*paramB z a*kernel (h a) (h d)* + (sqrt (count σ d:ℝ)/sqrt (n:ℝ)*paramB z d) = + (sqrt (count σ a:ℝ)*paramB z a*sqrt (count σ d:ℝ)*paramB z d*kernel (h a) (h d))/ + (sqrt (n:ℝ))^2 by ring, + sq_sqrt (Nat.cast_nonneg n)] + ring + +theorem correctedForm_bin {σ : Fin n → α} (hcount : ∀ a, 0 h (σ i)) (vectorOf z u) = finiteA β (binT σ) h z := by + unfold correctedForm + rw [diagonalForm_bin hcount,weightedForm_bin hcount] + simp only [siteMoment_bin hcount z u h,siteMoment_bin hcount z u (fun a => v (h a)), + siteMoment_bin hcount z u (fun _ => 1),siteMoment_bin hcount z u (fun a => h a*v (h a)), + siteMoment_bin hcount z u (fun a => m (h a)*v (h a))] + rfl + +end SKRatio.Bins + +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Quantization/BinFunctional.lean b/lean/OAI/Probability/SKRatio/Quantization/BinFunctional.lean new file mode 100644 index 0000000000000000000000000000000000000000..2f2a89e690612c38e656dfa397dd40d191179647 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Quantization/BinFunctional.lean @@ -0,0 +1,216 @@ +import Mathlib +import OAI.Probability.SKRatio.Quantization.BinProjected +import OAI.Probability.SKRatio.Quantization.BinDirections + +namespace OAI + +noncomputable section +open scoped BigOperators Matrix +open MeasureTheory ProbabilityTheory Filter Real +namespace SKRatio.Bins +open Planted Scalar SKRatioClock.Regression +variable {ι α : Type*} [Fintype ι] [DecidableEq ι] [Fintype α] [DecidableEq α] +attribute [local instance] Classical.propDecidable + +def binT (σ : ι → α) (a : α) : ℝ := sqrt (count σ a:ℝ)/sqrt (Fintype.card ι:ℝ) + +omit [DecidableEq ι] in +lemma sum_count (σ : ι → α) : (∑ a, (count σ a:ℝ))=(Fintype.card ι:ℝ) := by + have hh := sum_fibers σ (fun _ => (1:ℝ)) + simpa only [sum,Finset.sum_const,Finset.card_univ,nsmul_eq_mul,mul_one,count] using hh + +omit [DecidableEq ι] [Fintype α] in +lemma binT_nonneg (σ : ι → α) (a : α) : 0≤binT σ a := by unfold binT; positivity + +omit [DecidableEq ι] [Fintype α] in +lemma binT_sq (σ : ι → α) (a : α) : binT σ a^2=(count σ a:ℝ)/(Fintype.card ι:ℝ) := by + simp only [binT,div_pow,sq_sqrt (Nat.cast_nonneg _)] + +omit [DecidableEq ι] in +lemma binT_unit [Nonempty ι] (σ : ι → α) : (∑ a, binT σ a^2)=1 := by + simp only [binT_sq,←Finset.sum_div,sum_count] + exact div_self (Nat.cast_ne_zero.mpr Fintype.card_ne_zero) + +omit [DecidableEq ι] [Fintype α] in +lemma sqrt_count_mul_div {σ : ι → α} (hcount : ∀ a, 0 paramB z a/sqrt (count σ a:ℝ)), + zeroSum_scale_bin (paramR z) (directions_zeroSum u) a,add_zero] + exact sqrt_count_mul_div hcount (paramB z) a + +omit [DecidableEq ι] in +lemma vectorOf_sq_sum {σ : ι → α} (hcount : ∀ a, 0 vectorOf z u i^2) a=(paramB z a)^2+(paramR z a)^2 := by + simp only [vectorOf] + rw [bin_orthogonal_decomposition (zeroSum_scale_bin (paramR z) (directions_zeroSum u)) + (fun a => paramB z a/sqrt (count σ a:ℝ)) a, + overlap_scale_bin,directions_overlap,mul_one,div_pow,sq_sqrt (Nat.cast_nonneg _)] + congr 1 + exact mul_div_cancel₀ _ (Nat.cast_ne_zero.mpr (hcount a).ne') + +def moment (t B f : α → ℝ) : ℝ := ∑ a, t a*B a*f a + +omit [DecidableEq ι] in +lemma vectorOf_moment {σ : ι → α} (hcount : ∀ a, 0 v a+v d))^2 + +def finiteGaussian (β : ℝ) (t v : α → ℝ) (z : Parameters α) : ℝ := + β*∑ a, t a*paramR z a*sqrt (finiteRadicalSq t v z a) + +omit [DecidableEq ι] in +lemma binVariance_normalized [Nonempty ι] {σ : ι → α} (hcount : ∀ a, 0 B d/sqrt (count σ d:ℝ))) a= + (∑ d, (v a+v d)^2*B d^2)-(moment (binT σ) B (fun d => v a+v d))^2 := by + let f : ι → ℝ := fun i => (v a+v (σ i))*(B (σ i)/sqrt (count σ (σ i):ℝ)) + have he : binVariance σ (crossCoeff σ v (fun d => B d/sqrt (count σ d:ℝ))) a = + ∑ i, centered f i^2 := rfl + rw [he,centered_sq] + have hsum : (∑ i, f i)=sqrt (Fintype.card ι:ℝ)*moment (binT σ) B (fun d => v a+v d) := by + rw [←sum_fibers σ] + have hf (d : α) : sum σ f d=sqrt (count σ d:ℝ)*B d*(v a+v d) := by + change sum σ (fun i => (fun d => (v a+v d)*(B d/sqrt (count σ d:ℝ))) (σ i)) d=_ + rw [sum_const_bin σ (fun d => (v a+v d)*(B d/sqrt (count σ d:ℝ)))] + rw [show (count σ d:ℝ)*((v a+v d)*(B d/sqrt (count σ d:ℝ)))= + ((count σ d:ℝ)*(B d/sqrt (count σ d:ℝ)))*(v a+v d) by ring, + sqrt_count_mul_div hcount] + simp only [hf,moment,Finset.mul_sum,binT] + apply Finset.sum_congr rfl + intro d _ + have hn : sqrt (Fintype.card ι:ℝ)≠0 := (sqrt_pos.mpr (Nat.cast_pos.mpr Fintype.card_pos)).ne' + field_simp + have hsq : (∑ i, f i^2)=∑ d, (v a+v d)^2*B d^2 := by + rw [←sum_fibers σ] + apply Finset.sum_congr rfl + intro d _ + change sum σ (fun i => (fun d => ((v a+v d)*(B d/sqrt (count σ d:ℝ)))^2) (σ i)) d=_ + rw [sum_const_bin σ (fun d => ((v a+v d)*(B d/sqrt (count σ d:ℝ)))^2),mul_pow,div_pow,sq_sqrt (Nat.cast_nonneg _)] + have hc : (count σ d:ℝ)≠0 := Nat.cast_ne_zero.mpr (hcount d).ne' + field_simp + rw [hsq,average,hsum] + have hn : (Fintype.card ι:ℝ)≠0 := Nat.cast_ne_zero.mpr Fintype.card_ne_zero + rw [div_pow,mul_pow,sq_sqrt (Nat.cast_nonneg _)] + field_simp + +omit [DecidableEq ι] in +lemma radicalSq_normalized [Nonempty ι] {σ : ι → α} (hcount : ∀ a, 0 paramB z d/sqrt (count σ d:ℝ))) + (fun a d => v a+v d) (fun d => (paramR z d)^2) a= + finiteRadicalSq (binT σ) v z a := by + rw [radicalSq,binVariance_normalized hcount] + simp only [finiteRadicalSq,mul_add,Finset.sum_add_distrib] + ring + +theorem normalized_projected_tail {n : ℕ} (hn : 0 v (σ i)) (vectorOf z : Directions σ → Fin n → ℝ) g}≤ + exp (-a^2*(n:ℝ)/(π^2*β^2)) := by + have : Nonempty (Fin n) := Fin.pos_iff_nonempty.mp hn + have : Nonempty (Directions σ) := directions_nonempty hcount + have hc : ∀ a, 0 lt_of_lt_of_le (by norm_num) (hcount a) + have hh := projectedSup_tail hn σ v (fun a => paramB z a/sqrt (count σ a:ℝ)) hv hβ + (scaled_directions_continuous z) + (fun u => zeroSum_scale_bin (paramR z) (directions_zeroSum u)) + (show ∀ u : Directions σ, overlap σ (fun i => paramR z (σ i)*u.val i) + (fun i => paramR z (σ i)*u.val i)=(fun a => (paramR z a)^2) from by + intro u + ext a + rw [overlap_scale_bin,directions_overlap,mul_one]) + (fun u => vectorOf_unit hc z u) ha + have he : (∑ d, β/sqrt n*sqrt (radicalSq σ + (crossCoeff σ v (fun a => paramB z a/sqrt (count σ a:ℝ))) + (fun a d => v a+v d) (fun a => (paramR z a)^2) d)* + sqrt ((paramR z d)^2)*sqrt ((Finset.univ.filter (fun i => σ i=d)).card : ℝ))= + finiteGaussian β (binT σ) v z := by + simp_rw [radicalSq_normalized hc,sqrt_sq (paramR_nonneg z _)] + unfold finiteGaussian binT + rw [Finset.mul_sum] + apply Finset.sum_congr rfl + intro d _ + simp only [count,Fintype.card_fin] + ring + rw [he] at hh + exact hh + +def finiteA (β : ℝ) (t h : α → ℝ) (z : Parameters α) : ℝ := + moment t (paramB z) h*moment t (paramB z) (fun a => v (h a))+ + moment t (paramB z) (fun _ => 1)*moment t (paramB z) (fun a => h a*v (h a))- + β^2*moment t (paramB z) (fun _ => 1)*moment t (paramB z) (fun a => v (h a))+ + 2*β^2*moment t (paramB z) (fun _ => 1)*moment t (paramB z) (fun a => m (h a)*v (h a))+ + β^2*(∑ a, ∑ d, t d^2*(v (h d)^2/(w (h a)+w (h d)))* + ((paramB z a)^2+(paramR z a)^2))+ + β^2*(∑ a, ∑ d, t a*paramB z a*kernel (h a) (h d)*(t d*paramB z d)) + +def finiteV (β : ℝ) (t h : α → ℝ) (z : Parameters α) : ℝ := + finiteA β t h z+finiteGaussian β t (fun a => v (h a)) z + +omit [DecidableEq α] + +lemma continuous_paramB (a : α) : Continuous (fun z : Parameters α => paramB z a) := + (EuclideanSpace.proj (Sum.inl a : α ⊕ α)).continuous.comp continuous_subtype_val +lemma continuous_paramR (a : α) : Continuous (fun z : Parameters α => paramR z a) := + (EuclideanSpace.proj (Sum.inr a : α ⊕ α)).continuous.comp continuous_subtype_val + +lemma continuous_moment : Continuous (fun q : (α → ℝ) × (α → ℝ) × (α → ℝ) => + moment q.1 q.2.1 q.2.2) := by + unfold moment + fun_prop + +lemma continuous_finiteRadicalSq (v : α → ℝ) (a : α) : + Continuous (fun q : (α → ℝ) × Parameters α => finiteRadicalSq q.1 v q.2 a) := by + unfold finiteRadicalSq moment + have hb (d : α) := (continuous_paramB d).comp (continuous_snd (X := α → ℝ)) + have hr (d : α) := (continuous_paramR d).comp (continuous_snd (X := α → ℝ)) + fun_prop + +lemma continuous_finiteGaussian (β : ℝ) (v : α → ℝ) : + Continuous (fun q : (α → ℝ) × Parameters α => finiteGaussian β q.1 v q.2) := by + unfold finiteGaussian + apply Continuous.const_mul + apply continuous_finsetSum + intro a _ + exact (((continuous_apply a).comp continuous_fst).mul + ((continuous_paramR a).comp continuous_snd)).mul + (continuous_sqrt.comp (continuous_finiteRadicalSq v a)) + +lemma continuous_finiteA (β : ℝ) (h : α → ℝ) : + Continuous (fun q : (α → ℝ) × Parameters α => finiteA β q.1 h q.2) := by + unfold finiteA moment + have hb (a : α) := (continuous_paramB a).comp (continuous_snd (X := α → ℝ)) + have hr (a : α) := (continuous_paramR a).comp (continuous_snd (X := α → ℝ)) + fun_prop + +lemma continuous_finiteV (β : ℝ) (h : α → ℝ) : + Continuous (fun q : (α → ℝ) × Parameters α => finiteV β q.1 h q.2) := + (continuous_finiteA β h).add (continuous_finiteGaussian β (fun a => v (h a))) + +end SKRatio.Bins + +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Quantization/BinGaussian.lean b/lean/OAI/Probability/SKRatio/Quantization/BinGaussian.lean new file mode 100644 index 0000000000000000000000000000000000000000..b2a89eccc2a362ab65a8ced614d5d6744ab6615f --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Quantization/BinGaussian.lean @@ -0,0 +1,205 @@ +import Mathlib +import OAI.Probability.SKRatio.Matrices.GaussianCoordinates +import OAI.Probability.SKRatio.Matrices.GaussianQuadratic +import OAI.Probability.SKRatio.Matrices.GOERegression +import OAI.Probability.SKRatio.Quantization.BinCoefficients + +namespace OAI + +noncomputable section +open scoped BigOperators Matrix NNReal +open MeasureTheory ProbabilityTheory Filter Real +namespace SKRatio.Bins +variable {ι α : Type*} [Fintype ι] [Fintype α] [DecidableEq α] +attribute [local instance] Classical.propDecidable + +abbrev Coordinates (ι : Type*) := (ι × ι) ⊕ ι + +def radicalSq (σ : ι → α) (C K : α → α → ℝ) (s : α → ℝ) (a : α) : ℝ := + binVariance σ C a+∑ d, K a d^2*s d + +omit [DecidableEq α] in +lemma radicalSq_nonneg (σ : ι → α) (C K : α → α → ℝ) {s : α → ℝ} + (hs : ∀ a, 0 ≤ s a) (a : α) : 0≤radicalSq σ C K s a := + add_nonneg (binVariance_nonneg _ _ _) (Finset.sum_nonneg (fun d _ => mul_nonneg (sq_nonneg _) (hs d))) + +def residualCoeff (σ : ι → α) (C K : α → α → ℝ) (δ : ℝ) (u : ι → ℝ) : Coordinates ι → ℝ + | Sum.inl (i,j) => δ/sqrt 2*residualMatrix σ C K u i j + | Sum.inr _ => 0 + +def comparisonCoeff (σ : ι → α) (C K : α → α → ℝ) (s : α → ℝ) (δ : ℝ) + (u : ι → ℝ) : Coordinates ι → ℝ + | Sum.inl _ => 0 + | Sum.inr i => δ*sqrt (radicalSq σ C K s (σ i))*u i + +omit [DecidableEq α] in +lemma coeff_orthogonal (σ : ι → α) (C K : α → α → ℝ) (s : α → ℝ) (δ : ℝ) + (u z : ι → ℝ) : + (∑ k, (comparisonCoeff σ C K s δ u k-comparisonCoeff σ C K s δ z k)* + (residualCoeff σ C K δ u k-residualCoeff σ C K δ z k))=0 := by + simp [Fintype.sum_sum_type,residualCoeff,comparisonCoeff] + +lemma comparisonCoeff_increment (σ : ι → α) (C K : α → α → ℝ) (δ : ℝ) + {s : α → ℝ} (hs : ∀ a, 0 ≤ s a) {u z : ι → ℝ} + (hu : overlap σ u u=s) (hz : overlap σ z z=s) : + (∑ k, (comparisonCoeff σ C K s δ u k-comparisonCoeff σ C K s δ z k)^2)= + 2*δ^2*∑ a, (s a-overlap σ u z a)*radicalSq σ C K s a := by + simp only [Fintype.sum_sum_type,comparisonCoeff,sub_self,zero_pow (by norm_num : (2:ℕ)≠0), + Finset.sum_const_zero,zero_add] + have he (i : ι) : (δ*sqrt (radicalSq σ C K s (σ i))*u i-δ*sqrt (radicalSq σ C K s (σ i))*z i)^2 = + δ^2*(u i-z i)^2*radicalSq σ C K s (σ i) := by + rw [←mul_sub,mul_pow,mul_pow,sq_sqrt (radicalSq_nonneg σ C K hs _)] + ring + simp_rw [he] + rw [sum_weighted σ (fun i => δ^2*(u i-z i)^2) (radicalSq σ C K s),Finset.mul_sum] + apply Finset.sum_congr rfl + intro a _ + have hf : sum σ (fun i => δ^2*(u i-z i)^2) a = + δ^2*(overlap σ u u a+overlap σ z z a-2*overlap σ u z a) := by + unfold overlap sum + simp only [mul_sub,mul_add,Finset.mul_sum,←Finset.sum_add_distrib,←Finset.sum_sub_distrib] + apply Finset.sum_congr rfl + intro i _ + ring + rw [hf,hu,hz] + ring + +lemma coeff_increment_le {σ : ι → α} (C K : α → α → ℝ) + (hK : ∀ a d, K a d=K d a) (δ : ℝ) {u z : ι → ℝ} {s : α → ℝ} + (hu : ZeroSum σ u) (hz : ZeroSum σ z) + (hus : overlap σ u u=s) (hzs : overlap σ z z=s) : + (∑ k, (residualCoeff σ C K δ u k-residualCoeff σ C K δ z k)^2) ≤ + ∑ k, (comparisonCoeff σ C K s δ u k-comparisonCoeff σ C K s δ z k)^2 := by + have hs : ∀ a, 0 ≤ s a := fun a => hus ▸ overlap_self_nonneg σ u a + rw [comparisonCoeff_increment σ C K δ hs hus hzs] + simp only [Fintype.sum_sum_type,residualCoeff,sub_self,zero_pow (by norm_num : (2:ℕ)≠0), + Finset.sum_const_zero,add_zero,Fintype.sum_prod_type] + have hex : (∑ i, ∑ j, (δ/sqrt 2*residualMatrix σ C K u i j-δ/sqrt 2*residualMatrix σ C K z i j)^2) = + (δ^2/2)*(∑ i, ∑ j, (residualMatrix σ C K u i j-residualMatrix σ C K z i j)^2) := by + simp only [←mul_sub,mul_pow,div_pow,sq_sqrt (by norm_num : (0:ℝ)≤2),Finset.mul_sum] + rw [hex] + have hh := mul_le_mul_of_nonneg_left (residualMatrix_increment C K hK hu hz hus hzs) + (show 0≤δ^2/2 by positivity) + dsimp only [radicalSq] + convert hh using 1 + first | rfl | ring + +omit [Fintype ι] [Fintype α] [DecidableEq α] in +lemma continuous_residualCoeff (σ : ι → α) (C K : α → α → ℝ) (δ : ℝ) : + Continuous (residualCoeff σ C K δ) := by + apply continuous_pi + intro k + cases k with + | inl ij => + dsimp [residualCoeff,residualMatrix,linearMatrix,quadraticMatrix] + fun_prop + | inr i => exact continuous_const + +omit [DecidableEq α] in +lemma continuous_comparisonCoeff (σ : ι → α) (C K : α → α → ℝ) (s : α → ℝ) (δ : ℝ) : + Continuous (comparisonCoeff σ C K s δ) := by + apply continuous_pi + intro k + cases k with + | inl ij => exact continuous_const + | inr i => exact continuous_const.mul (continuous_apply i) + +def blockNorm (σ : ι → α) (a : α) (g : Coordinates ι → ℝ) : ℝ := + sqrt (sum σ (fun i => g (Sum.inr i)^2) a) + +omit [Fintype α] in +lemma blockNorm_memLp (σ : ι → α) (a : α) : + MemLp (blockNorm σ a) 2 (SKRatioGaussian.gaussianCoordinates (Coordinates ι)) := by + apply SKRatioGaussian.memLp_sqrt_of_nonneg + · apply integrable_finsetSum + intro i _ + exact (SKRatioClock.Regression.coordinate_hasLaw (Sum.inr i : Coordinates ι)).hasGaussianLaw.memLp_two.integrable_sq + · intro g + exact Finset.sum_nonneg (fun _ _ => sq_nonneg _) + +omit [Fintype α] in +lemma blockNorm_mean_le (σ : ι → α) (a : α) : + (∫ g, blockNorm σ a g ∂SKRatioGaussian.gaussianCoordinates (Coordinates ι)) ≤ + sqrt ((Finset.univ.filter (fun i => σ i=a)).card : ℝ) := by + have h := SKRatioGaussian.integral_abs_le_sqrt_sq (blockNorm_memLp σ a) + have he (g : Coordinates ι → ℝ) : blockNorm σ a g^2=sum σ (fun i => g (.inr i)^2) a := + sq_sqrt (Finset.sum_nonneg (fun _ _ => sq_nonneg _)) + simp_rw [he,abs_of_nonneg (show 0≤blockNorm σ a _ from sqrt_nonneg _)] at h + have hm : (∫ g, sum σ (fun i => g (.inr i)^2) a ∂SKRatioGaussian.gaussianCoordinates (Coordinates ι)) = + (Finset.univ.filter (fun i => σ i=a)).card := by + change (∫ g, ∑ i with σ i=a, g (.inr i)^2 ∂SKRatioClock.Regression.standardArrayLaw (Coordinates ι)) = _ + rw [integral_finsetSum _ (fun i _ => + (SKRatioClock.Regression.coordinate_hasLaw (Sum.inr i : Coordinates ι)).hasGaussianLaw.memLp_two.integrable_sq)] + have hint (i : ι) : (∫ g, g (.inr i)^2 ∂SKRatioClock.Regression.standardArrayLaw (Coordinates ι))=1 := by + calc + _ = ∫ x : ℝ, x^2 ∂gaussianReal 0 1 := + (SKRatioClock.Regression.coordinate_hasLaw (Sum.inr i : Coordinates ι)).integral_comp (by fun_prop) + _ = 1 := SKRatioGaussian.gaussian_integral_sq + simp only [hint,Finset.sum_const, nsmul_eq_mul,mul_one] + rwa [hm] at h + +lemma comparison_pointwise {σ : ι → α} (C K : α → α → ℝ) + {s : α → ℝ} {δ : ℝ} (hδ : 0≤δ) {u : ι → ℝ} (hu : overlap σ u u=s) + (g : Coordinates ι → ℝ) : + (∑ k, comparisonCoeff σ C K s δ u k*g k) ≤ + ∑ a, δ*sqrt (radicalSq σ C K s a)*sqrt (s a)*blockNorm σ a g := by + simp only [Fintype.sum_sum_type,comparisonCoeff,zero_mul,Finset.sum_const_zero,zero_add] + have he : (∑ i, δ*sqrt (radicalSq σ C K s (σ i))*u i*g (.inr i)) = + ∑ a, δ*sqrt (radicalSq σ C K s a)*sum σ (fun i => u i*g (.inr i)) a := by + convert sum_weighted σ (fun i => u i*g (.inr i)) (fun a => δ*sqrt (radicalSq σ C K s a)) using 1 + · apply Finset.sum_congr rfl + intro i _ + ring + · apply Finset.sum_congr rfl + intro a _ + ring + rw [he] + apply Finset.sum_le_sum + intro a _ + have h := Real.sum_mul_le_sqrt_mul_sqrt (Finset.univ.filter (fun i => σ i=a)) u (fun i => g (.inr i)) + have hsq : (∑ i with σ i=a, u i^2)=s a := by + simpa only [overlap,sum,←pow_two] using congrFun hu a + rw [hsq] at h + exact (mul_le_mul_of_nonneg_left h (mul_nonneg hδ (sqrt_nonneg _))).trans_eq (by + change δ*sqrt _*(sqrt _*blockNorm σ a g)=_ + ring) + +variable {I : Type*} [TopologicalSpace I] [CompactSpace I] [Nonempty I] + +theorem residual_sup_expectation_le [Nonempty ι] (σ : ι → α) (C K : α → α → ℝ) + (hK : ∀ a d, K a d=K d a) {s : α → ℝ} {δ : ℝ} (hδ : 0≤δ) + {u : I → ι → ℝ} (huc : Continuous u) (hu0 : ∀ t, ZeroSum σ (u t)) + (hus : ∀ t, overlap σ (u t) (u t)=s) : + (∫ g, SKRatioGaussian.gaussianSup (fun _ : I => 0) (fun t => residualCoeff σ C K δ (u t)) g + ∂SKRatioGaussian.gaussianCoordinates (Coordinates ι)) ≤ + ∑ a, δ*sqrt (radicalSq σ C K s a)*sqrt (s a)* + sqrt ((Finset.univ.filter (fun i => σ i=a)).card : ℝ) := by + let X := fun t => residualCoeff σ C K δ (u t) + let Y := fun t => comparisonCoeff σ C K s δ (u t) + have hX : Continuous X := (continuous_residualCoeff σ C K δ).comp huc + have hY : Continuous Y := (continuous_comparisonCoeff σ C K s δ).comp huc + have hcomp := SKRatioGaussian.gaussianSup_comparison (m := fun _ : I => 0) + continuous_const hY hX (fun t r => coeff_orthogonal σ C K s δ (u t) (u r)) + (fun t r => coeff_increment_le C K hK δ (hu0 t) (hu0 r) (hus t) (hus r)) + apply hcomp.trans + have hbound : ∀ g, SKRatioGaussian.gaussianSup (fun _ : I => 0) Y g ≤ + ∑ a, δ*sqrt (radicalSq σ C K s a)*sqrt (s a)*blockNorm σ a g := by + intro g + apply SKRatioGaussian.gaussianSup_le continuous_const hY + intro t + simpa only [SKRatioGaussian.gaussianAffine,zero_add] using comparison_pointwise C K hδ (hus t) g + have hib : Integrable (fun g => ∑ a, δ*sqrt (radicalSq σ C K s a)*sqrt (s a)*blockNorm σ a g) + (SKRatioGaussian.gaussianCoordinates (Coordinates ι)) := integrable_finsetSum _ (fun a _ => + ((blockNorm_memLp σ a).integrable (by norm_num)).const_mul _) + apply (integral_mono (SKRatioGaussian.integrable_gaussianSup continuous_const hY) hib hbound).trans + rw [integral_finsetSum _ (fun a _ => ((blockNorm_memLp σ a).integrable (by norm_num)).const_mul _)] + simp only [integral_const_mul] + apply Finset.sum_le_sum + intro a _ + exact mul_le_mul_of_nonneg_left (blockNorm_mean_le σ a) (by positivity) + +end SKRatio.Bins + +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Quantization/BinGeometry.lean b/lean/OAI/Probability/SKRatio/Quantization/BinGeometry.lean new file mode 100644 index 0000000000000000000000000000000000000000..bc2e4b5e2f47a976961eb61a3bf45622816db2ec --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Quantization/BinGeometry.lean @@ -0,0 +1,108 @@ +import Mathlib + +namespace OAI + +noncomputable section +open scoped BigOperators +open MeasureTheory ProbabilityTheory Filter Real +namespace SKRatio.Bins +variable {ι α : Type*} [Fintype ι] [Fintype α] [DecidableEq α] +attribute [local instance] Classical.propDecidable + +def sum (σ : ι → α) (f : ι → ℝ) (a : α) : ℝ := + ∑ i with σ i = a, f i + +def overlap (σ : ι → α) (u z : ι → ℝ) (a : α) : ℝ := + sum σ (fun i => u i*z i) a + +def ZeroSum (σ : ι → α) (u : ι → ℝ) : Prop := ∀ a, sum σ u a = 0 + +lemma sum_fibers (σ : ι → α) (f : ι → ℝ) : ∑ a, sum σ f a = ∑ i, f i := by + classical + simpa only [sum,Finset.mem_univ,true_and] using + (Finset.sum_fiberwise_of_maps_to (s := Finset.univ) (t := Finset.univ) (g := σ) + (fun _ _ => Finset.mem_univ _) f) + +lemma sum_weighted (σ : ι → α) (f : ι → ℝ) (c : α → ℝ) : + ∑ i, f i*c (σ i) = ∑ a, sum σ f a*c a := by + rw [←sum_fibers σ (fun i => f i*c (σ i))] + apply Finset.sum_congr rfl + intro a _ + unfold sum + rw [Finset.sum_mul] + apply Finset.sum_congr rfl + intro i hi + change f i*c (σ i)=f i*c a + rw [(Finset.mem_filter.mp hi).2] + +lemma zero_sum_weighted {σ : ι → α} {u : ι → ℝ} (hu : ZeroSum σ u) (c : α → ℝ) : + (∑ i, u i*c (σ i)) = 0 := by + rw [sum_weighted] + simp only [show ∀ a, sum σ u a=0 from hu,zero_mul,Finset.sum_const_zero] + +lemma zero_sum_bilinear {σ : ι → α} {u : ι → ℝ} (hu : ZeroSum σ u) + (z : ι → ℝ) (K : α → α → ℝ) : + (∑ i, ∑ j, u i*z j*K (σ i) (σ j)) = 0 := by + rw [Finset.sum_comm] + apply Finset.sum_eq_zero + intro j _ + simpa only [mul_assoc] using zero_sum_weighted hu (fun a => z j*K a (σ j)) + +omit [Fintype α] in +lemma overlap_symm (σ : ι → α) (u z : ι → ℝ) : overlap σ u z = overlap σ z u := by + funext a + simp only [overlap,mul_comm] + +omit [Fintype α] in +lemma overlap_self_nonneg (σ : ι → α) (u : ι → ℝ) (a : α) : 0 ≤ overlap σ u u a := by + exact Finset.sum_nonneg (fun i _ => mul_self_nonneg (u i)) + +omit [Fintype α] in +lemma overlap_le {σ : ι → α} {u z : ι → ℝ} {s : α → ℝ} + (hu : overlap σ u u = s) (hz : overlap σ z z = s) (a : α) : + overlap σ u z a ≤ s a := by + have h : 0 ≤ ∑ i with σ i=a, (u i-z i)^2 := Finset.sum_nonneg (fun _ _ => sq_nonneg _) + have he : (∑ i with σ i=a, (u i-z i)^2) = + overlap σ u u a+overlap σ z z a-2*overlap σ u z a := by + unfold overlap sum + simp only [Finset.mul_sum] + rw [←Finset.sum_add_distrib,←Finset.sum_sub_distrib] + apply Finset.sum_congr rfl + intro i _ + ring + rw [he,hu,hz] at h + linarith + +omit [Fintype α] in +lemma overlap_abs_le {σ : ι → α} {u z : ι → ℝ} {s : α → ℝ} + (hu : overlap σ u u = s) (hz : overlap σ z z = s) (a : α) : + |overlap σ u z a| ≤ s a := by + have hz' : overlap σ (fun i => -z i) (fun i => -z i) = s := by + calc + _ = overlap σ z z := by ext a; simp only [overlap,neg_mul_neg] + _ = s := hz + have hh := overlap_le hu hz' a + have he : overlap σ u (fun i => -z i) a = -overlap σ u z a := by + simp [overlap,sum] + rw [he] at hh + exact abs_le.mpr ⟨by linarith,overlap_le hu hz a⟩ + +omit [Fintype α] [DecidableEq α] in +lemma overlap_product_bound {s q : α → ℝ} (hq : ∀ a, q a ≤ s a) (a d : α) : + s a*s d-q a*q d ≤ s a*(s d-q d)+s d*(s a-q a) := by + nlinarith only [mul_nonneg (sub_nonneg.mpr (hq a)) (sub_nonneg.mpr (hq d))] + +lemma double_weighted (σ : ι → α) (f g : ι → ℝ) (K : α → α → ℝ) : + (∑ i, ∑ j, f i*g j*K (σ i) (σ j)) = + ∑ a, ∑ d, sum σ f a*sum σ g d*K a d := by + simp_rw [mul_assoc,←Finset.mul_sum,sum_weighted σ g] + rw [sum_weighted σ f (fun a => ∑ d, sum σ g d*K a d)] + +lemma sum_overlap (σ : ι → α) (u z : ι → ℝ) : + (∑ a, overlap σ u z a) = ∑ i, u i*z i := sum_fibers _ _ + +end SKRatio.Bins + +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Quantization/BinNet.lean b/lean/OAI/Probability/SKRatio/Quantization/BinNet.lean new file mode 100644 index 0000000000000000000000000000000000000000..7c48f38d08374802d1d84a341beb3d2dec61c39a --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Quantization/BinNet.lean @@ -0,0 +1,134 @@ +import Mathlib +import OAI.Probability.SKRatio.Quantization.BinFunctional + +namespace OAI + +noncomputable section +open scoped BigOperators Matrix +open MeasureTheory ProbabilityTheory Filter Real +namespace SKRatio.Bins +open Planted Scalar SKRatioClock.Regression MatrixNet Calculus +variable {α : Type*} [Fintype α] [DecidableEq α] {n : ℕ} +attribute [local instance] Classical.propDecidable + +lemma norm_of_sum_sq_one {p : Fin n → ℝ} (hp : ∑ i, p i^2=1) : + ‖WithLp.toLp 2 p‖=1 := by + have he := EuclideanSpace.real_norm_sq_eq (WithLp.toLp 2 p) + simp only [hp] at he + nlinarith only [he,norm_nonneg (WithLp.toLp 2 p)] + +lemma quadratic_vector_difference (M : Matrix (Fin n) (Fin n) ℝ) + {p q : Fin n → ℝ} (hp : ∑ i, p i^2=1) (hq : ∑ i, q i^2=1) : + |quadratic M p-quadratic M q| ≤ + 2*euclideanOpNorm M*‖WithLp.toLp 2 (fun i => p i-q i)‖ := by + let A := Matrix.toEuclideanCLM (𝕜 := ℝ) M + let P : EuclideanSpace ℝ (Fin n) := WithLp.toLp 2 p + let Q : EuclideanSpace ℝ (Fin n) := WithLp.toLp 2 q + have hP : ‖P‖=1 := norm_of_sum_sq_one hp + have hQ : ‖Q‖=1 := norm_of_sum_sq_one hq + have he : inner ℝ P (A P)-inner ℝ Q (A Q) = + inner ℝ (P-Q) (A P)+inner ℝ Q (A (P-Q)) := by + simp only [map_sub,inner_sub_left,inner_sub_right] + ring + rw [quadratic_inner,quadratic_inner] + change |inner ℝ P (A P)-inner ℝ Q (A Q)|≤_ + rw [he] + have h1 := (abs_real_inner_le_norm (P-Q) (A P)).trans + (mul_le_mul_of_nonneg_left (A.le_opNorm P) (norm_nonneg _)) + have h2 := (abs_real_inner_le_norm Q (A (P-Q))).trans + (mul_le_mul_of_nonneg_left (A.le_opNorm (P-Q)) (norm_nonneg _)) + rw [hP] at h1 + rw [hQ] at h2 + have ht := abs_add_le (inner ℝ (P-Q) (A P)) (inner ℝ Q (A (P-Q))) + change |inner ℝ (P-Q) (A P)+inner ℝ Q (A (P-Q))|≤2*‖A‖*‖P-Q‖ + nlinarith only [ht,h1,h2] + +lemma variance_bilinear_difference (M : Matrix (Fin n) (Fin n) ℝ) + (v : Fin n → ℝ) (hv : ∀ i, |v i|≤1) + {p q : Fin n → ℝ} (hp : ∑ i, p i^2=1) (hq : ∑ i, q i^2=1) : + |p ⬝ᵥ (M*ᵥ(fun i => v i*p i))-q ⬝ᵥ (M*ᵥ(fun i => v i*q i))|≤ + 2*euclideanOpNorm M*‖WithLp.toLp 2 (fun i => p i-q i)‖ := by + have he (p : Fin n → ℝ) : p ⬝ᵥ (M*ᵥ(fun i => v i*p i))= + quadratic (M*Matrix.diagonal v) p := by + simp only [quadratic,Matrix.mul_diagonal,dotProduct,Matrix.mulVec,Finset.mul_sum] + apply Finset.sum_congr rfl + intro i _ + apply Finset.sum_congr rfl + intro j _ + ring + rw [he,he] + apply (quadratic_vector_difference _ hp hq).trans + have hd := matrix_diagonal_opNorm_le v 1 (by norm_num) hv + have hn : euclideanOpNorm (M*Matrix.diagonal v)≤euclideanOpNorm M := by + unfold euclideanOpNorm + rw [map_mul] + exact (norm_mul_le _ _).trans ((mul_le_mul_of_nonneg_left hd (norm_nonneg _)).trans_eq (mul_one _)) + gcongr + +abbrev WeightBox (α : Type*) := α → Set.Icc (0:ℝ) 1 + +lemma binT_le_one [Nonempty (Fin n)] (σ : Fin n → α) (a : α) : binT σ a≤1 := by + have hs : binT σ a^2≤1 := by + rw [←binT_unit σ] + exact Finset.single_le_sum (fun i _ => sq_nonneg (binT σ i)) (Finset.mem_univ a) + nlinarith only [hs] + +def binBox [Nonempty (Fin n)] (σ : Fin n → α) : WeightBox α := + fun a => ⟨binT σ a,binT_nonneg σ a,binT_le_one σ a⟩ + +omit [DecidableEq α] in +lemma finiteA_parameter_tolerance (β : ℝ) (h : α → ℝ) {a : ℝ} (ha : 0 t d) h z-finiteA β (fun d => t d) h z'| + finiteA β (fun d => q.1 d) h q.2) := by + unfold finiteA moment + have hb (d : α) := (continuous_paramB d).comp (continuous_snd (X := WeightBox α)) + have hr (d : α) := (continuous_paramR d).comp (continuous_snd (X := WeightBox α)) + have ht (d : α) : Continuous (fun q : WeightBox α × Parameters α => (q.1 d:ℝ)) := + continuous_subtype_val.comp ((continuous_apply d).comp continuous_fst) + fun_prop + obtain ⟨δ,hδ,hcont⟩ := Metric.uniformContinuous_iff.mp + (CompactSpace.uniformContinuous_of_continuous hc) a ha + refine ⟨δ,hδ,fun t z z' hh => ?_⟩ + apply hcont (a := (t,z)) (b := (t,z')) + simp only [Prod.dist_eq,dist_self,Subtype.dist_eq,dist_eq_norm,max_lt_iff] + exact ⟨hδ,hh⟩ + +theorem binForm_finite_net (β : ℝ) (h : α → ℝ) {K a : ℝ} (hK : 0≤K) (ha : 0 v (h (σ i))*vectorOf z u i))+ + finiteA β (binT σ) h z ≤ + (vectorOf z' u) ⬝ᵥ (M*ᵥ(fun i => v (h (σ i))*vectorOf z' u i))+ + finiteA β (binT σ) h z'+a := by + obtain ⟨δ,hδ,hA⟩ := finiteA_parameter_tolerance β h (show 0 lt_of_lt_of_le (by norm_num) (hc d) + obtain ⟨z',hz',hnear⟩ := hF z + refine ⟨z',hz',?_⟩ + have hA' := (le_abs_self _).trans (hA (binBox σ) z z' (hnear.trans_le (min_le_left _ _))).le + have hdiff := variance_bilinear_difference M (fun i => v (h (σ i))) + (fun i => by rw [abs_of_nonneg (v_pos _).le]; exact v_le_one _) + (vectorOf_unit hc' z u) (vectorOf_unit hc' z' u) + rw [vectorOf_difference hc'] at hdiff + have hkd := mul_le_mul_of_nonneg_right hM (norm_nonneg (z.val-z'.val)) + have hηd := (lt_div_iff₀ (by positivity : 0<4*K+1)).mp (hnear.trans_le (min_le_right _ _)) + have habs := le_abs_self ((vectorOf z u) ⬝ᵥ (M*ᵥ (fun i => v (h (σ i))*vectorOf z u i))- + (vectorOf z' u) ⬝ᵥ (M*ᵥ (fun i => v (h (σ i))*vectorOf z' u i))) + change finiteA β (binT σ) h z-finiteA β (binT σ) h z'≤a/2 at hA' + nlinarith only [habs,hdiff,hkd,hηd,hA',norm_nonneg (z.val-z'.val)] + +end SKRatio.Bins + +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Quantization/BinParameters.lean b/lean/OAI/Probability/SKRatio/Quantization/BinParameters.lean new file mode 100644 index 0000000000000000000000000000000000000000..d4d71b0c1764c6aa43c6e681b9dd5c40344e47d9 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Quantization/BinParameters.lean @@ -0,0 +1,150 @@ +import Mathlib +import OAI.Probability.SKRatio.Quantization.BinGeometry + +namespace OAI + +noncomputable section +open scoped BigOperators +open MeasureTheory ProbabilityTheory Filter Real +namespace SKRatio.Bins +variable {ι α : Type*} [Fintype ι] [DecidableEq α] +attribute [local instance] Classical.propDecidable + +def count (σ : ι → α) (a : α) : ℕ := (Finset.univ.filter (fun i => σ i=a)).card + +def binMean (σ : ι → α) (p : ι → ℝ) (a : α) : ℝ := sum σ p a/(count σ a:ℝ) + +def binCentered (σ : ι → α) (p : ι → ℝ) (i : ι) : ℝ := p i-binMean σ p (σ i) + +lemma sum_const_bin (σ : ι → α) (c : α → ℝ) (a : α) : + sum σ (fun i => c (σ i)) a = (count σ a:ℝ)*c a := by + unfold sum count + calc + _ = ∑ i with σ i=a, c a := Finset.sum_congr rfl (fun i hi => by dsimp only []; rw [(Finset.mem_filter.mp hi).2]) + _ = _ := by simp + +lemma sum_add_bin (σ : ι → α) (p q : ι → ℝ) (a : α) : + sum σ (fun i => p i+q i) a = sum σ p a+sum σ q a := Finset.sum_add_distrib +lemma sum_sub_bin (σ : ι → α) (p q : ι → ℝ) (a : α) : + sum σ (fun i => p i-q i) a = sum σ p a-sum σ q a := Finset.sum_sub_distrib _ _ + +lemma count_mul_binMean (σ : ι → α) (p : ι → ℝ) (a : α) : + (count σ a:ℝ)*binMean σ p a=sum σ p a := by + by_cases h : count σ a=0 + · have he : Finset.univ.filter (fun i => σ i=a)=∅ := Finset.card_eq_zero.mp h + simp [binMean,h,sum,he] + · exact mul_div_cancel₀ _ (Nat.cast_ne_zero.mpr h) + +lemma binCentered_zeroSum (σ : ι → α) (p : ι → ℝ) : ZeroSum σ (binCentered σ p) := by + intro a + change sum σ (fun i => p i-binMean σ p (σ i)) a=0 + rw [sum_sub_bin,sum_const_bin,count_mul_binMean,sub_self] + +lemma binCentered_decomp (σ : ι → α) (p : ι → ℝ) (i : ι) : + p i=binMean σ p (σ i)+binCentered σ p i := by unfold binCentered; ring + +lemma bin_orthogonal_decomposition {σ : ι → α} {u : ι → ℝ} (hu : ZeroSum σ u) + (b : α → ℝ) (a : α) : + sum σ (fun i => (b (σ i)+u i)^2) a = + (count σ a:ℝ)*b a^2+overlap σ u u a := by + have he : sum σ (fun i => b (σ i)*u i) a = b a*sum σ u a := by + unfold sum + rw [Finset.mul_sum] + apply Finset.sum_congr rfl + intro i hi + dsimp only [] + rw [(Finset.mem_filter.mp hi).2] + simp only [add_sq,sum_add_bin] + have hcross : sum σ (fun i => 2*b (σ i)*u i) a=0 := by + calc + _ = 2*sum σ (fun i => b (σ i)*u i) a := by unfold sum; simp [mul_assoc,Finset.mul_sum] + _ = 0 := by rw [he,hu a,mul_zero,mul_zero] + rw [sum_const_bin σ (fun a => b a^2),hcross,add_zero] + simp only [overlap,pow_two] + +lemma centered_fiber_sq (σ : ι → α) (p : ι → ℝ) (a : α) : + sum σ (fun i => p i^2) a = + (count σ a:ℝ)*binMean σ p a^2+overlap σ (binCentered σ p) (binCentered σ p) a := by + have he : (fun i => p i^2) = (fun i => (binMean σ p (σ i)+binCentered σ p i)^2) := by + ext i + rw [←binCentered_decomp] + rw [he,bin_orthogonal_decomposition (binCentered_zeroSum σ p)] + +lemma normalized_fiber_sq (σ : ι → α) (p : ι → ℝ) (a : α) : + (sqrt (count σ a:ℝ)*binMean σ p a)^2+ + (sqrt (overlap σ (binCentered σ p) (binCentered σ p) a))^2 = + sum σ (fun i => p i^2) a := by + rw [mul_pow,sq_sqrt (Nat.cast_nonneg _),sq_sqrt (overlap_self_nonneg ..),centered_fiber_sq] + +variable [Fintype α] + +abbrev ParameterSpace (α : Type*) [Fintype α] := EuclideanSpace ℝ (α ⊕ α) + +def ParameterSet (α : Type*) [Fintype α] : Set (ParameterSpace α) := + {z | ‖z‖=1 ∧ ∀ a, 0≤z (.inr a)} + +abbrev Parameters (α : Type*) [Fintype α] := ↥(ParameterSet α) + +omit [DecidableEq α] in +lemma parameterSet_compact : IsCompact (ParameterSet α) := by + have hc : IsClosed {z : ParameterSpace α | ∀ a, 0≤z (.inr a)} := by + simp only [Set.ofPred_forall] + apply isClosed_iInter + intro a + exact isClosed_le continuous_const (EuclideanSpace.proj (Sum.inr a : α ⊕ α)).continuous + simpa only [ParameterSet,Metric.sphere,dist_zero_right,Set.ofPred_and] using + (isCompact_sphere (0 : ParameterSpace α) 1).inter_right hc + +instance : CompactSpace (Parameters α) := isCompact_iff_compactSpace.mp parameterSet_compact + +def paramB (z : Parameters α) (a : α) : ℝ := z.val (.inl a) +def paramR (z : Parameters α) (a : α) : ℝ := z.val (.inr a) + +omit [DecidableEq α] in +lemma paramR_nonneg (z : Parameters α) (a : α) : 0≤paramR z a := z.property.2 a + +omit [DecidableEq α] in +lemma param_sum_sq (z : Parameters α) : (∑ a, ((paramB z a)^2+(paramR z a)^2))=1 := by + have hh := EuclideanSpace.real_norm_sq_eq z.val + rw [z.property.1] at hh + simpa only [one_pow,Fintype.sum_sum_type,Finset.sum_add_distrib,paramB,paramR] using hh.symm + +def parametersOf (σ : ι → α) (p : ι → ℝ) (hp : ∑ i, p i^2=1) : Parameters α := + ⟨WithLp.toLp 2 (Sum.elim (fun a => sqrt (count σ a:ℝ)*binMean σ p a) + (fun a => sqrt (overlap σ (binCentered σ p) (binCentered σ p) a))),by + constructor + · have hs : ‖WithLp.toLp 2 (Sum.elim (fun a => sqrt (count σ a:ℝ)*binMean σ p a) + (fun a => sqrt (overlap σ (binCentered σ p) (binCentered σ p) a)))‖^2=1 := by + rw [EuclideanSpace.real_norm_sq_eq] + simp only [Fintype.sum_sum_type,Sum.elim_inl,Sum.elim_inr, + ←Finset.sum_add_distrib,normalized_fiber_sq,sum_fibers,hp] + nlinarith only [hs,norm_nonneg (WithLp.toLp 2 (Sum.elim (fun a => sqrt (count σ a:ℝ)*binMean σ p a) + (fun a => sqrt (overlap σ (binCentered σ p) (binCentered σ p) a))))] + · intro a + exact sqrt_nonneg _⟩ + +@[simp] lemma parametersOf_B (σ : ι → α) (p : ι → ℝ) (hp : ∑ i, p i^2=1) (a : α) : + paramB (parametersOf σ p hp) a = sqrt (count σ a:ℝ)*binMean σ p a := rfl +@[simp] lemma parametersOf_R (σ : ι → α) (p : ι → ℝ) (hp : ∑ i, p i^2=1) (a : α) : + paramR (parametersOf σ p hp) a = sqrt (overlap σ (binCentered σ p) (binCentered σ p) a) := rfl + +omit [DecidableEq α] in +theorem parameters_finite_net {η : ℝ} (hη : 0<η) : + ∃ F : Finset (Parameters α), ∀ z : Parameters α, + ∃ z' ∈ F, ‖z.val-z'.val‖<η := by + have hcover : (Set.univ : Set (Parameters α)) ⊆ ⋃ z : Parameters α, Metric.ball z η := by + intro z _ + exact Set.mem_iUnion.mpr ⟨z,by simpa using hη⟩ + obtain ⟨s,hs,hsfin,hscov⟩ := isCompact_univ.elim_finite_subcover_image + (b := (Set.univ : Set (Parameters α))) (c := fun z => Metric.ball z η) + (fun z _ => Metric.isOpen_ball) (by simpa using hcover) + refine ⟨hsfin.toFinset,fun z => ?_⟩ + have hz := hscov (Set.mem_univ z) + obtain ⟨z',hz',hd⟩ := Set.mem_iUnion₂.mp hz + exact ⟨z',by simpa using hz',by simpa only [Metric.mem_ball,Subtype.dist_eq,dist_eq_norm] using hd⟩ + +end SKRatio.Bins + +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Quantization/BinPartition.lean b/lean/OAI/Probability/SKRatio/Quantization/BinPartition.lean new file mode 100644 index 0000000000000000000000000000000000000000..8f4002d0b07d8bc48d258ff8ee2962e22256fdfb --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Quantization/BinPartition.lean @@ -0,0 +1,101 @@ +import Mathlib +import OAI.Probability.SKRatio.Quantization.BinFunctional + +namespace OAI + +noncomputable section +open scoped NNReal ENNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Real +namespace SKRatio.Bins +open Planted Scalar +variable {Ω α : Type*} [MeasurableSpace Ω] [Fintype α] [MeasurableSpace α] + [MeasurableSingletonClass α] {μ : Measure Ω} [IsProbabilityMeasure μ] + +def binMass (μ : Measure Ω) (σ : Ω → α) (a : α) : ℝ := μ.real {x | σ x=a} + +def massRoot (μ : Measure Ω) (σ : Ω → α) (a : α) : ℝ := sqrt (binMass μ σ a) + +def pullback (μ : Measure Ω) (σ : Ω → α) (B : α → ℝ) (x : Ω) : ℝ := + B (σ x)/massRoot μ σ (σ x) + +lemma integral_finite_partition {σ : Ω → α} (hσ : Measurable σ) (f : α → ℝ) : + (∫ x, f (σ x) ∂μ)=∑ a, binMass μ σ a*f a := by + rw [←integral_map hσ.aemeasurable (measurable_of_countable f).aestronglyMeasurable, + integral_fintype (by exact Integrable.of_finite)] + apply Finset.sum_congr rfl + intro a _ + rw [smul_eq_mul,map_measureReal_apply hσ (measurableSet_singleton a)] + rfl + +omit [Fintype α] [MeasurableSpace α] [MeasurableSingletonClass α] [IsProbabilityMeasure μ] in +lemma binMass_nonneg (σ : Ω → α) (a : α) : 0 ≤ binMass μ σ a := measureReal_nonneg + +omit [Fintype α] [MeasurableSpace α] [MeasurableSingletonClass α] [IsProbabilityMeasure μ] in +lemma massRoot_sq (σ : Ω → α) (a : α) : massRoot μ σ a^2=binMass μ σ a := + sq_sqrt (binMass_nonneg σ a) + +lemma sum_binMass {σ : Ω → α} (hσ : Measurable σ) : (∑ a, binMass μ σ a)=1 := by + have hh := integral_finite_partition (μ := μ) hσ (fun _ => (1:ℝ)) + simpa only [mul_one,integral_const,probReal_univ,smul_eq_mul,one_mul] using hh.symm + +lemma massRoot_unit {σ : Ω → α} (hσ : Measurable σ) : (∑ a, massRoot μ σ a^2)=1 := by + simp_rw [massRoot_sq] + exact sum_binMass hσ + +lemma measurable_finite_comp {σ : Ω → α} (hσ : Measurable σ) (f : α → ℝ) : + Measurable (fun x => f (σ x)) := (measurable_of_countable f).comp hσ + +lemma memLp_finite_comp {σ : Ω → α} (hσ : Measurable σ) (f : α → ℝ) : + MemLp (fun x => f (σ x)) 2 μ := by + apply MemLp.of_bound (measurable_finite_comp hσ f).aestronglyMeasurable (∑ a, |f a|) + exact ae_of_all _ (fun x => by + rw [norm_eq_abs] + exact Finset.single_le_sum (fun a _ => abs_nonneg (f a)) (Finset.mem_univ (σ x))) + +omit [IsProbabilityMeasure μ] in +lemma measurable_pullback {σ : Ω → α} (hσ : Measurable σ) (B : α → ℝ) : + Measurable (pullback μ σ B) := measurable_finite_comp hσ (fun a => B a / massRoot μ σ a) + +lemma memLp_pullback {σ : Ω → α} (hσ : Measurable σ) (B : α → ℝ) : + MemLp (pullback μ σ B) 2 μ := memLp_finite_comp hσ (fun a => B a / massRoot μ σ a) + +omit [Fintype α] [MeasurableSpace α] [MeasurableSingletonClass α] [IsProbabilityMeasure μ] in +lemma massRoot_pos {σ : Ω → α} (hm : ∀ a, 0 pullback μ σ B x*f (σ x))= + (fun x => (fun a => B a/massRoot μ σ a*f a) (σ x)) from rfl, + integral_finite_partition (μ := μ) hσ (fun a => B a / massRoot μ σ a * f a)] + unfold moment + apply Finset.sum_congr rfl + intro a _ + have hs := massRoot_sq (μ := μ) σ a + have hn := (massRoot_pos hm a).ne' + rw [←hs] + field_simp + +lemma integral_pullback_energy {σ : Ω → α} (hσ : Measurable σ) + (hm : ∀ a, 0 f (σ x)*(pullback μ σ B x^2+pullback μ σ R x^2))= + (fun x => (fun a => f a*((B a/massRoot μ σ a)^2+(R a/massRoot μ σ a)^2)) (σ x)) from rfl, + integral_finite_partition (μ := μ) hσ (fun a => f a*((B a/massRoot μ σ a)^2+(R a/massRoot μ σ a)^2))] + apply Finset.sum_congr rfl + intro a _ + rw [div_pow,div_pow,massRoot_sq] + field_simp [(hm a).ne'] + +lemma pullback_normalized [DecidableEq α] {σ : Ω → α} (hσ : Measurable σ) + (hm : ∀ a, 0 1)).trans + (by simpa only [one_mul] using param_sum_sq z) + +end SKRatio.Bins + +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Quantization/BinProcess.lean b/lean/OAI/Probability/SKRatio/Quantization/BinProcess.lean new file mode 100644 index 0000000000000000000000000000000000000000..ab6b662815a8dda9802b01b0869240cdb8753dfb --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Quantization/BinProcess.lean @@ -0,0 +1,276 @@ +import Mathlib +import OAI.Probability.SKRatio.Matrices.GaussianAffineGaussianSup +import OAI.Probability.SKRatio.Matrices.GaussianProductUpperTailLipschitz +import OAI.Probability.SKRatio.Quantization.BinGaussian + +namespace OAI + +noncomputable section +open scoped BigOperators Matrix NNReal +open MeasureTheory ProbabilityTheory Filter Real +namespace SKRatio.Bins +variable {ι α : Type*} [Fintype ι] [Nonempty ι] [Fintype α] [DecidableEq α] +attribute [local instance] Classical.propDecidable + +def average (p : ι → ℝ) : ℝ := (∑ i, p i)/(Fintype.card ι:ℝ) +def centered (p : ι → ℝ) : ι → ℝ := fun i => p i-average p + +omit [Nonempty ι] in +lemma average_add (p q : ι → ℝ) : average (fun i => p i+q i)=average p+average q := by + simp only [average,Finset.sum_add_distrib,add_div] +omit [Nonempty ι] in +lemma average_mul (p : ι → ℝ) (c : ℝ) : average (fun i => c*p i)=c*average p := by + simp only [average,←Finset.mul_sum,mul_div_assoc] +lemma average_const (c : ℝ) : average (fun _ : ι => c)=c := by + have hn : (Fintype.card ι:ℝ)≠0 := Nat.cast_ne_zero.mpr Fintype.card_ne_zero + simp [average,mul_div_cancel_left₀ _ hn] +omit [Nonempty ι] in +lemma average_zeroSum {σ : ι → α} {u : ι → ℝ} (hu : ZeroSum σ u) : average u=0 := by + have h := zero_sum_weighted hu (fun _ => 1) + simpa only [mul_one, average, zero_div] using congrArg (fun z : ℝ => z/(Fintype.card ι:ℝ)) h + +lemma centered_sq (p : ι → ℝ) : (∑ i, centered p i^2)=(∑ i, p i^2)- + (Fintype.card ι:ℝ)*average p^2 := by + have hn : (Fintype.card ι:ℝ)≠0 := Nat.cast_ne_zero.mpr Fintype.card_ne_zero + have hsum : (∑ i, p i)=(Fintype.card ι:ℝ)*average p := by + dsimp [average] + field_simp + simp only [centered,sub_sq,Finset.sum_add_distrib,Finset.sum_sub_distrib, + ←Finset.sum_mul,←Finset.mul_sum,Finset.sum_const,Finset.card_univ,nsmul_eq_mul] + rw [hsum] + ring +lemma centered_sq_le (p : ι → ℝ) : (∑ i, centered p i^2)≤∑ i, p i^2 := by + rw [centered_sq] + exact sub_le_self _ (mul_nonneg (Nat.cast_nonneg _) (sq_nonneg _)) + +def fullCoeff (v p : ι → ℝ) (δ : ℝ) : Coordinates ι → ℝ + | .inl (i,j) => δ/sqrt 2*(centered p i*centered (fun k => v k*p k) j+ + centered p j*centered (fun k => v k*p k) i) + | .inr _ => 0 + +omit [Nonempty ι] in +lemma continuous_centered : Continuous (centered (ι := ι)) := by + apply continuous_pi + intro i + exact (continuous_apply i).sub ((continuous_finsetSum _ (fun j _ => continuous_apply j)).div_const _) + +omit [Nonempty ι] in +lemma continuous_fullCoeff (v : ι → ℝ) (δ : ℝ) : Continuous (fun p => fullCoeff v p δ) := by + apply continuous_pi + intro k + cases k with + | inr i => exact continuous_const + | inl ij => + change Continuous (fun p => δ/sqrt 2*(centered p ij.1*centered (fun k => v k*p k) ij.2+ + centered p ij.2*centered (fun k => v k*p k) ij.1)) + have hm : Continuous (fun p : ι → ℝ => fun k => v k*p k) := by fun_prop + exact (((continuous_apply ij.1).comp continuous_centered |>.mul + ((continuous_apply ij.2).comp (continuous_centered.comp hm))).add + (((continuous_apply ij.2).comp continuous_centered).mul + ((continuous_apply ij.1).comp (continuous_centered.comp hm)))).const_mul _ + +def crossCoeff (σ : ι → α) (v b : α → ℝ) (a d : α) : ℝ := + (v a+v d)*b d-average (fun i => (v a+v (σ i))*b (σ i)) + +omit [Nonempty ι] [Fintype α] [DecidableEq α] in +lemma crossCoeff_eq (σ : ι → α) (v b : α → ℝ) (a : α) (j : ι) : + crossCoeff σ v b a (σ j)=centered (fun i => v (σ i)*b (σ i)) j+ + v a*centered (fun i => b (σ i)) j := by + have he : (fun i => (v a+v (σ i))*b (σ i))= + (fun i => v a*b (σ i)+v (σ i)*b (σ i)) := by ext i; ring + rw [crossCoeff,he,average_add,average_mul] + dsimp only [centered] + ring + +omit [Nonempty ι] in +lemma centered_add_zeroSum {σ : ι → α} (b : α → ℝ) {u : ι → ℝ} (hu : ZeroSum σ u) : + centered (fun i => b (σ i)+u i)=fun i => centered (fun k => b (σ k)) i+u i := by + ext i + simp only [centered,average_add,average_zeroSum hu,add_zero] + ring + +omit [Nonempty ι] [Fintype α] in +lemma zeroSum_mul {σ : ι → α} (v : α → ℝ) {u : ι → ℝ} (hu : ZeroSum σ u) : + ZeroSum σ (fun i => v (σ i)*u i) := by + intro a + have he : sum σ (fun i => v (σ i)*u i) a = v a*sum σ u a := by + unfold sum + rw [Finset.mul_sum] + apply Finset.sum_congr rfl + intro i hi + change v (σ i)*u i=v a*u i + rw [(Finset.mem_filter.mp hi).2] + rw [he,hu a,mul_zero] + +omit [Nonempty ι] in +lemma fullCoeff_decomposition {σ : ι → α} (v b : α → ℝ) (δ : ℝ) {u : ι → ℝ} + (hu : ZeroSum σ u) : + fullCoeff (fun i => v (σ i)) (fun i => b (σ i)+u i) δ = + fun k => fullCoeff (fun i => v (σ i)) (fun i => b (σ i)) δ k+ + residualCoeff σ (crossCoeff σ v b) (fun a d => v a+v d) δ u k := by + have he : (fun i => v (σ i)*(b (σ i)+u i))= + fun i => v (σ i)*b (σ i)+v (σ i)*u i := by ext i; ring + have hcen := centered_add_zeroSum (fun a => v a*b a) (zeroSum_mul v hu) + ext k + cases k with + | inr i => simp [fullCoeff,residualCoeff] + | inl ij => + rcases ij with ⟨i,j⟩ + simp only [fullCoeff,residualCoeff,centered_add_zeroSum b hu,he,hcen,residualMatrix, + Matrix.add_apply,Matrix.transpose_apply,linearMatrix,quadraticMatrix,crossCoeff_eq] + ring + +lemma fullCoeff_sq_le {v p : ι → ℝ} (hv : ∀ i, |v i|≤1) (δ : ℝ) : + (∑ k, fullCoeff v p δ k^2) ≤ 2*δ^2*(∑ i, p i^2)^2 := by + let x := centered p + let y := centered (fun i => v i*p i) + have hx : (∑ i, x i^2)≤∑ i, p i^2 := centered_sq_le p + have hy : (∑ i, y i^2)≤∑ i, p i^2 := (centered_sq_le _).trans (by + apply Finset.sum_le_sum + intro i _ + have hvi : v i^2≤1 := (sq_le_one_iff_abs_le_one (v i)).mpr (hv i) + simpa only [mul_pow,one_mul] using mul_le_mul_of_nonneg_right hvi (sq_nonneg (p i))) + have hprod : (∑ i, x i^2)*(∑ j, y j^2)≤(∑ i, p i^2)^2 := by + rw [pow_two] + exact mul_le_mul hx hy (Finset.sum_nonneg (fun _ _ => sq_nonneg _)) + (Finset.sum_nonneg (fun _ _ => sq_nonneg _)) + have hsq : (∑ i, ∑ j, (x i*y j+x j*y i)^2)≤4*((∑ i, x i^2)*(∑ j, y j^2)) := by + calc + _ ≤ ∑ i, ∑ j, 2*((x i*y j)^2+(x j*y i)^2) := by + apply Finset.sum_le_sum + intro i _ + apply Finset.sum_le_sum + intro j _ + nlinarith only [sq_nonneg (x i*y j-x j*y i)] + _ = _ := by + simp only [mul_add,mul_pow,Finset.sum_add_distrib,←Finset.mul_sum,←Finset.sum_mul] + ring + simp only [Fintype.sum_sum_type,fullCoeff,zero_pow (by norm_num : (2:ℕ)≠0), + Finset.sum_const_zero,add_zero,Fintype.sum_prod_type,mul_pow,div_pow, + sq_sqrt (by norm_num : (0:ℝ)≤2),←Finset.mul_sum] + change δ^2/2*(∑ i, ∑ j, (x i*y j+x j*y i)^2)≤_ + have h := mul_le_mul_of_nonneg_left (hsq.trans (mul_le_mul_of_nonneg_left hprod (by norm_num))) + (show 0≤δ^2/2 by positivity) + convert h using 1 + first | rfl | ring + +lemma fullCoeff_norm_le {v p : ι → ℝ} (hv : ∀ i, |v i|≤1) {δ : ℝ} (hδ : 0≤δ) + (hp : ∑ i, p i^2=1) : ‖WithLp.toLp 2 (fullCoeff v p δ)‖≤ sqrt 2*δ := by + have h := fullCoeff_sq_le (p := p) hv δ + rw [hp] at h + have he : ‖WithLp.toLp 2 (fullCoeff v p δ)‖^2=∑ k, fullCoeff v p δ k^2 := by + simp only [EuclideanSpace.norm_sq_eq,Real.norm_eq_abs,sq_abs] + have hs := sq_sqrt (show (0:ℝ)≤2 by norm_num) + have hpos : 0≤ sqrt 2*δ := mul_nonneg (sqrt_nonneg _) hδ + apply (sq_le_sq₀ (norm_nonneg _) hpos).mp + rw [mul_pow,hs,he] + simpa only [one_pow,mul_one] using h + +section Translation +variable {κ I : Type*} [Fintype κ] [TopologicalSpace I] [CompactSpace I] [Nonempty I] + +lemma gaussianSup_add_common {a : I → κ → ℝ} (ha : Continuous a) (c : κ → ℝ) + (g : κ → ℝ) : + SKRatioGaussian.gaussianSup (fun _ : I => 0) (fun t k => c k+a t k) g = + (∑ k, c k*g k)+SKRatioGaussian.gaussianSup (fun _ : I => 0) a g := by + have hac : Continuous (fun t k => c k+a t k) := continuous_const.add ha + have he (t : I) : SKRatioGaussian.gaussianAffine (fun _ : I => 0) (fun t k => c k+a t k) g t = + (∑ k, c k*g k)+SKRatioGaussian.gaussianAffine (fun _ : I => 0) a g t := by + simp only [SKRatioGaussian.gaussianAffine,add_mul,Finset.sum_add_distrib,zero_add] + apply le_antisymm + · apply SKRatioGaussian.gaussianSup_le continuous_const hac + intro t + rw [he] + exact add_le_add le_rfl (SKRatioGaussian.gaussianAffine_le_gaussianSup continuous_const ha g t) + · obtain ⟨t, ht, _⟩ := SKRatioGaussian.gaussianSup_attained continuous_const ha g + rw [ht,←he] + exact SKRatioGaussian.gaussianAffine_le_gaussianSup continuous_const hac g t + +lemma integral_gaussianSup_add_common {a : I → κ → ℝ} (ha : Continuous a) (c : κ → ℝ) : + (∫ g, SKRatioGaussian.gaussianSup (fun _ : I => 0) (fun t k => c k+a t k) g + ∂SKRatioGaussian.gaussianCoordinates κ) = + ∫ g, SKRatioGaussian.gaussianSup (fun _ : I => 0) a g ∂SKRatioGaussian.gaussianCoordinates κ := by + have hi (k : κ) : Integrable (fun g : κ → ℝ => c k*g k) (SKRatioGaussian.gaussianCoordinates κ) := + ((SKRatioClock.Regression.coordinate_hasLaw k).hasGaussianLaw.integrable).const_mul _ + simp_rw [gaussianSup_add_common ha c] + rw [integral_add (integrable_finsetSum _ (fun k _ => hi k)) + (SKRatioGaussian.integrable_gaussianSup continuous_const ha), + integral_finsetSum _ (fun k _ => hi k)] + have hm (k : κ) : (∫ g : κ → ℝ, c k*g k ∂SKRatioGaussian.gaussianCoordinates κ)=0 := by + rw [integral_const_mul] + change c k*(∫ g : κ → ℝ, g k ∂SKRatioClock.Regression.standardArrayLaw κ)=0 + rw [SKRatioClock.Regression.coordinate_mean,mul_zero] + simp only [hm,Finset.sum_const_zero,zero_add] +end Translation + +variable {I : Type*} [TopologicalSpace I] [CompactSpace I] [Nonempty I] + +theorem full_sup_expectation_le (σ : ι → α) (v b : α → ℝ) + {s : α → ℝ} {δ : ℝ} (hδ : 0≤δ) {u : I → ι → ℝ} + (huc : Continuous u) (hu0 : ∀ t, ZeroSum σ (u t)) + (hus : ∀ t, overlap σ (u t) (u t)=s) : + (∫ g, SKRatioGaussian.gaussianSup (fun _ : I => 0) + (fun t => fullCoeff (fun i => v (σ i)) (fun i => b (σ i)+u t i) δ) g + ∂SKRatioGaussian.gaussianCoordinates (Coordinates ι)) ≤ + ∑ a, δ*sqrt (radicalSq σ (crossCoeff σ v b) (fun a d => v a+v d) s a)* + sqrt (s a)*sqrt ((Finset.univ.filter (fun i => σ i=a)).card : ℝ) := by + have hd (t : I) := fullCoeff_decomposition v b δ (hu0 t) + simp_rw [hd] + have hi := integral_gaussianSup_add_common + ((continuous_residualCoeff σ (crossCoeff σ v b) (fun a d => v a+v d) δ).comp huc) + (fullCoeff (fun i => v (σ i)) (fun i => b (σ i)) δ) + exact hi.trans_le (residual_sup_expectation_le σ _ _ (fun a d => add_comm _ _) hδ huc hu0 hus) + +theorem full_sup_lipschitz (v : ι → ℝ) (hv : ∀ i, |v i|≤1) + {δ : ℝ} (hδ : 0≤δ) {p : I → ι → ℝ} (hpc : Continuous p) + (hp : ∀ t, ∑ i, p t i^2=1) : + LipschitzWith ⟨sqrt 2*δ,by positivity⟩ + (fun g : EuclideanSpace ℝ (Coordinates ι) => + SKRatioGaussian.gaussianSup (fun _ : I => 0) (fun t => fullCoeff v (p t) δ) g.ofLp) := by + apply SKRatioGaussian.gaussianSup_lipschitz continuous_const ((continuous_fullCoeff v δ).comp hpc) + intro t + exact fullCoeff_norm_le hv hδ (hp t) + +theorem full_sup_tail (σ : ι → α) (v b : α → ℝ) (hv : ∀ a, |v a|≤1) + {s : α → ℝ} {δ : ℝ} (hδ : 0<δ) {u : I → ι → ℝ} + (huc : Continuous u) (hu0 : ∀ t, ZeroSum σ (u t)) + (hus : ∀ t, overlap σ (u t) (u t)=s) + (hp : ∀ t, ∑ i, (b (σ i)+u t i)^2=1) {a : ℝ} (ha : 0≤a) : + (SKRatioGaussian.gaussianCoordinates (Coordinates ι)).real {g | + (∑ d, δ*sqrt (radicalSq σ (crossCoeff σ v b) (fun a d => v a+v d) s d)* + sqrt (s d)*sqrt ((Finset.univ.filter (fun i => σ i=d)).card : ℝ))+a ≤ + SKRatioGaussian.gaussianSup (fun _ : I => 0) + (fun t => fullCoeff (fun i => v (σ i)) (fun i => b (σ i)+u t i) δ) g} ≤ + exp (-a^2/(π^2*δ^2)) := by + let p : I → ι → ℝ := fun t i => b (σ i)+u t i + have hpc : Continuous p := continuous_const.add huc + let f := SKRatioGaussian.gaussianSup (fun _ : I => 0) + (fun t => fullCoeff (fun i => v (σ i)) (p t) δ) + have hL : (0:ℝ≥0) < ⟨sqrt 2*δ,by positivity⟩ := by + change (0:ℝ) hv (σ i)) hδ.le hpc hp) hL ha + have he := full_sup_expectation_le σ v b hδ.le huc hu0 hus + have hsub : {g | (∑ d, δ*sqrt (radicalSq σ (crossCoeff σ v b) (fun a d => v a+v d) s d)* + sqrt (s d)*sqrt ((Finset.univ.filter (fun i => σ i=d)).card : ℝ))+a ≤ f g} ⊆ + {g | a ≤ f g-∫ y, f y ∂SKRatioGaussian.gaussianCoordinates (Coordinates ι)} := by + intro g hg + change _+a≤f g at hg + change (∫ y, f y ∂SKRatioGaussian.gaussianCoordinates (Coordinates ι))≤_ at he + change a≤f g-(∫ y, f y ∂SKRatioGaussian.gaussianCoordinates (Coordinates ι)) + linarith only [hg,he] + have hcont : Continuous f := SKRatioGaussian.continuous_gaussianSup continuous_const + ((continuous_fullCoeff _ _).comp hpc) + apply (measureReal_mono hsub).trans + convert hc using 1 <;> try rfl + apply congrArg Real.exp + change -a^2/(π^2*δ^2) = -2*a^2/(π^2*(sqrt 2*δ)^2) + rw [mul_pow,sq_sqrt (by norm_num : (0:ℝ)≤2)] + ring + +end SKRatio.Bins + +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Quantization/BinProjected.lean b/lean/OAI/Probability/SKRatio/Quantization/BinProjected.lean new file mode 100644 index 0000000000000000000000000000000000000000..4c9798624e7a0b6a7548169a7a60fc5e15ee9cc8 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Quantization/BinProjected.lean @@ -0,0 +1,234 @@ +import Mathlib +import OAI.Probability.SKRatio.Quantization.BinProcess +import OAI.Probability.SKRatio.Variational.ReducedForm + +namespace OAI + +noncomputable section +open scoped BigOperators Matrix +open MeasureTheory ProbabilityTheory Filter Real +namespace SKRatio.Planted +open SKRatioClock.Regression Scalar +attribute [local instance] Classical.propDecidable +variable {n : ℕ} + +lemma fieldProjection_apply (i j : Fin n) : + fieldProjection n i j = (if i=j then 1 else 0)-(n:ℝ)⁻¹ := by + simp only [fieldProjection,residualProjection,Matrix.sub_apply,Matrix.one_apply, + Matrix.mul_apply,Matrix.transpose_apply,queryColumn,constantDirection,Fin.sum_univ_one] + congr 1 + rw [←mul_inv_rev,←pow_two,sq_sqrt (Nat.cast_nonneg n)] + +lemma fieldProjection_symmetric : (fieldProjection n)ᵀ=fieldProjection n := by + ext i j + simp only [Matrix.transpose_apply,fieldProjection_apply,eq_comm] + +lemma fieldProjection_mulVec (p : Fin n → ℝ) : + fieldProjection n *ᵥ p = Bins.centered p := by + ext i + simp only [Matrix.mulVec,dotProduct,fieldProjection_apply,sub_mul,Finset.sum_sub_distrib, + ite_mul,one_mul,zero_mul,Finset.sum_ite_eq,Finset.mem_univ,ite_true, + ←Finset.mul_sum,Bins.centered,Bins.average,Fintype.card_fin,div_eq_mul_inv] + ring + +lemma fieldProjection_vecMul (p : Fin n → ℝ) : + p ᵥ* fieldProjection n = Bins.centered p := by + rw [←fieldProjection_symmetric,Matrix.vecMul_transpose,fieldProjection_mulVec] + +lemma projected_bilinear (M : Matrix (Fin n) (Fin n) ℝ) (p q : Fin n → ℝ) : + p ⬝ᵥ ((fieldProjection n*M*fieldProjection n)*ᵥ q) = + Bins.centered p ⬝ᵥ (M*ᵥ Bins.centered q) := by + rw [←Matrix.mulVec_mulVec,fieldProjection_mulVec,←Matrix.mulVec_mulVec, + Matrix.dotProduct_mulVec,fieldProjection_vecMul] + +lemma fullCoeff_goe (β : ℝ) (v p : Fin n → ℝ) + (g : Bins.Coordinates (Fin n) → ℝ) : + (∑ k, Bins.fullCoeff v p (β/sqrt n) k*g k) = + p ⬝ᵥ ((fieldProjection n*(β • goe (fun ij => g (.inl ij)))*fieldProjection n)*ᵥ + (fun i => v i*p i)) := by + rw [projected_bilinear] + simp only [Fintype.sum_sum_type,Bins.fullCoeff,zero_mul,Finset.sum_const_zero,add_zero, + Fintype.sum_prod_type,dotProduct,Matrix.mulVec,Matrix.smul_apply,smul_eq_mul,goe, + Finset.mul_sum] + have hs : sqrt (2*(n:ℝ))=sqrt 2*sqrt n := sqrt_mul (by norm_num) _ + rw [hs] + let x := Bins.centered p + let y := Bins.centered (fun i => v i*p i) + change (∑ i, ∑ j, β/sqrt n/sqrt 2*(x i*y j+x j*y i)*g (.inl (i,j))) = + ∑ i, ∑ j, x i*(β*((g (.inl (i,j))+g (.inl (j,i)))/(sqrt 2*sqrt n))*y j) + have he (i j : Fin n) : β/sqrt n/sqrt 2*(x i*y j+x j*y i)*g (.inl (i,j)) = + β/(sqrt 2*sqrt n)*(x i*y j*g (.inl (i,j))+x j*y i*g (.inl (i,j))) := by ring + simp_rw [he,mul_add,Finset.sum_add_distrib,←Finset.mul_sum] + have hswap : (∑ i, ∑ j, x j*y i*g (.inl (i,j)))= + ∑ i, ∑ j, x i*y j*g (.inl (j,i)) := Finset.sum_comm + rw [hswap] + simp only [Finset.mul_sum,←Finset.sum_add_distrib] + apply Finset.sum_congr rfl + intro i _ + apply Finset.sum_congr rfl + intro j _ + ring + +lemma weightedForm_variance_bilinear (M : Matrix (Fin n) (Fin n) ℝ) + (H p : Fin n → ℝ) : + weightedForm M varianceKernel (fun i => compactWeight (H i)) p = + p ⬝ᵥ (M*ᵥ (fun i => v (H i)*p i)) := by + simp only [weightedForm,quadratic,varianceKernel,compactV_weight,dotProduct, + Matrix.mulVec,Finset.mul_sum] + apply Finset.sum_congr rfl + intro i _ + apply Finset.sum_congr rfl + intro j _ + ring + +def rankForm (H v p : Fin n → ℝ) : ℝ := + ((∑ i, p i*H i)*(∑ i, p i*v i)+(∑ i, p i)*(∑ i, p i*H i*v i)- + ((∑ i, H i)/(n:ℝ))*(∑ i, p i)*(∑ i, p i*v i))/(n:ℝ) + +lemma rank_form_expansion (H v p : Fin n → ℝ) : + (∑ i, ∑ j, ((H i+H j-(∑ k, H k)/(n:ℝ))/(n:ℝ))*v j*p i*p j) = + rankForm H v p := by + simp only [rankForm,add_div,sub_div,add_mul,sub_mul,Finset.sum_add_distrib, + Finset.sum_sub_distrib] + have h1 (i : Fin n) : (∑ j, H i/(n:ℝ)*v j*p i*p j) = + p i*H i*(∑ j, p j*v j)/(n:ℝ) := by + rw [Finset.mul_sum,Finset.sum_div] + apply Finset.sum_congr rfl + intro j _ + ring + have h2 (i : Fin n) : (∑ j, H j/(n:ℝ)*v j*p i*p j) = + p i*(∑ j, p j*H j*v j)/(n:ℝ) := by + rw [Finset.mul_sum,Finset.sum_div] + apply Finset.sum_congr rfl + intro j _ + ring + have h3 (i : Fin n) : (∑ j, ((∑ k, H k)/(n:ℝ))/(n:ℝ)*v j*p i*p j) = + ((∑ k, H k)/(n:ℝ))*p i*(∑ j, p j*v j)/(n:ℝ) := by + conv_rhs => rw [Finset.mul_sum,Finset.sum_div] + apply Finset.sum_congr rfl + intro j _ + ring + simp_rw [h1,h2,h3] + simp only [←Finset.sum_div,←Finset.sum_mul,←Finset.mul_sum] + +def deterministicForm (β : ℝ) (H p : Fin n → ℝ) : ℝ := + rankForm H (fun i => v (H i)) p + + 2*β^2/(n:ℝ)*(∑ i, p i)*(∑ i, p i*m (H i)*v (H i)) + + diagonalForm (fun _ _ => β^2/(n:ℝ)) compactF (fun i => compactWeight (H i)) p + + weightedForm (fun _ _ => β^2/(n:ℝ)) compactK (fun i => compactWeight (H i)) p + +theorem reducedForm_decomposition (hn : 0 v (augmentedField β g i)*p i)) + + deterministicForm β (augmentedField β g) p := by + have h1 : weightedForm (augmented β g) varianceKernel + (fun i => compactWeight (augmentedField β g i)) p = + weightedForm (fieldProjection n*(β • goe g)*fieldProjection n) varianceKernel + (fun i => compactWeight (augmentedField β g i)) p + + rankForm (augmentedField β g) (fun i => v (augmentedField β g i)) p := by + simp only [weightedForm,quadratic,varianceKernel,compactV_weight] + simp_rw [augmented_decomposition hn,add_mul,Finset.sum_add_distrib] + rw [rank_form_expansion] + have h2 : 2*weightedForm (fun _ _ => β^2/(n:ℝ)) meanVarianceKernel + (fun i => compactWeight (augmentedField β g i)) p = + 2*β^2/(n:ℝ)*(∑ i, p i)*(∑ i, p i*m (augmentedField β g i)*v (augmentedField β g i)) := by + simp only [weightedForm,quadratic,meanVarianceKernel,compactV_weight,compactWeight_coe, + w,sub_sub_cancel] + simp only [Finset.mul_sum,Finset.sum_mul] + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro i _ + apply Finset.sum_congr rfl + intro j _ + ring + dsimp only [reducedForm] + rw [h1,h2,weightedForm_variance_bilinear] + unfold deterministicForm + ring + +end SKRatio.Planted + +namespace SKRatio.Bins +open SKRatioClock.Regression Planted +attribute [local instance] Classical.propDecidable +variable {n : ℕ} {α : Type*} [Fintype α] [DecidableEq α] +variable {I : Type*} [TopologicalSpace I] [CompactSpace I] [Nonempty I] + +lemma inl_array_hasLaw : + HasLaw (fun g : Coordinates (Fin n) → ℝ => fun ij : Fin n × Fin n => g (.inl ij)) + (standardArrayLaw (Fin n × Fin n)) (SKRatioGaussian.gaussianCoordinates (Coordinates (Fin n))) := by + exact iIndepFun.hasLaw_pi (fun ij => coordinate_hasLaw (Sum.inl ij : Coordinates (Fin n))) + (iIndepFun.precomp Sum.inl_injective coordinates_independent) + +def projectedSup (β : ℝ) (v : Fin n → ℝ) (p : I → Fin n → ℝ) + (g : (Fin n × Fin n) → ℝ) : ℝ := + sSup (Set.range (fun t => p t ⬝ᵥ + ((fieldProjection n*(β • goe g)*fieldProjection n)*ᵥ (fun i => v i*p t i)))) + +omit [TopologicalSpace I] [CompactSpace I] [Nonempty I] in +lemma projectedSup_eq (β : ℝ) (v : Fin n → ℝ) (p : I → Fin n → ℝ) + (g : Coordinates (Fin n) → ℝ) : + projectedSup β v p (fun ij => g (.inl ij)) = + SKRatioGaussian.gaussianSup (fun _ : I => 0) (fun t => fullCoeff v (p t) (β/sqrt n)) g := by + unfold projectedSup SKRatioGaussian.gaussianSup + congr 2 + funext t + simp only [SKRatioGaussian.gaussianAffine,zero_add,fullCoeff_goe] + +omit [Nonempty I] in +lemma projectedSup_continuous [Nonempty (Fin n)] (β : ℝ) (v : Fin n → ℝ) + {p : I → Fin n → ℝ} (hp : Continuous p) : Continuous (projectedSup β v p) := by + have he : projectedSup β v p = fun g => + SKRatioGaussian.gaussianSup (fun _ : I => 0) (fun t => fullCoeff v (p t) (β/sqrt n)) + (Sum.elim g (fun _ => 0)) := by + ext g + exact projectedSup_eq β v p (Sum.elim g (fun _ => 0)) + rw [he] + apply (SKRatioGaussian.continuous_gaussianSup continuous_const ((continuous_fullCoeff v _).comp hp)).comp + apply continuous_pi + intro k + cases k with + | inl ij => exact continuous_apply ij + | inr i => exact continuous_const + +lemma le_projectedSup [Nonempty (Fin n)] (β : ℝ) (v : Fin n → ℝ) {p : I → Fin n → ℝ} + (hp : Continuous p) (g : (Fin n × Fin n) → ℝ) (t : I) : + p t ⬝ᵥ ((fieldProjection n*(β • goe g)*fieldProjection n)*ᵥ (fun i => v i*p t i)) ≤ + projectedSup β v p g := by + have hh := SKRatioGaussian.gaussianAffine_le_gaussianSup (m := fun _ : I => 0) continuous_const + ((continuous_fullCoeff v (β/sqrt n)).comp hp) (Sum.elim g (fun _ => 0)) t + simpa only [SKRatioGaussian.gaussianAffine,Function.comp_def,zero_add,fullCoeff_goe,←projectedSup_eq,Sum.elim_inl] using hh + +theorem projectedSup_tail (hn : 0 v a+v d) s d)* + sqrt (s d)*sqrt ((Finset.univ.filter (fun i => σ i=d)).card : ℝ))+a ≤ + projectedSup β (fun i => v (σ i)) (fun t i => b (σ i)+u t i) g} ≤ + exp (-a^2*(n:ℝ)/(π^2*β^2)) := by + have : Nonempty (Fin n) := Fin.pos_iff_nonempty.mp hn + have hδ : 0<β/sqrt (n:ℝ) := div_pos hβ (sqrt_pos.mpr (Nat.cast_pos.mpr hn)) + have hsup := full_sup_tail σ v b hv hδ huc hu0 hus hp ha + have hmeas : MeasurableSet {g | + (∑ d, β/sqrt n*sqrt (radicalSq σ (crossCoeff σ v b) (fun a d => v a+v d) s d)* + sqrt (s d)*sqrt ((Finset.univ.filter (fun i => σ i=d)).card : ℝ))+a ≤ + projectedSup β (fun i => v (σ i)) (fun t i => b (σ i)+u t i) g} := + measurableSet_le measurable_const + (projectedSup_continuous β _ (continuous_const.add huc)).measurable + rw [←inl_array_hasLaw.measureReal_eq hmeas] + simp_rw [projectedSup_eq] + convert hsup using 1 + apply congrArg Real.exp + rw [div_pow,sq_sqrt (Nat.cast_nonneg n)] + field_simp + +end SKRatio.Bins + +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Quantization/BinPullback.lean b/lean/OAI/Probability/SKRatio/Quantization/BinPullback.lean new file mode 100644 index 0000000000000000000000000000000000000000..8a3935306efbe2a7fdb2773314e6212e05a63a97 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Quantization/BinPullback.lean @@ -0,0 +1,93 @@ +import Mathlib +import OAI.Probability.SKRatio.Quantization.BinPartition +import OAI.Probability.SKRatio.Variational.FieldFunctional + +namespace OAI + +noncomputable section +open scoped NNReal ENNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Real +namespace SKRatio.Bins +open Planted Scalar +variable {α : Type*} [Fintype α] [MeasurableSpace α] + [MeasurableSingletonClass α] {μ : Measure ℝ} [IsProbabilityMeasure μ] + +lemma integral_finite_partition_prod {σ : ℝ → α} (hσ : Measurable σ) (F : α → α → ℝ) : + (∫ z : ℝ×ℝ, F (σ z.1) (σ z.2) ∂μ.prod μ)= + ∑ a, ∑ d, binMass μ σ a*binMass μ σ d*F a d := by + have hi : Integrable (fun z : ℝ×ℝ => F (σ z.1) (σ z.2)) (μ.prod μ) := + (memLp_finite_comp ((hσ.comp measurable_fst).prodMk (hσ.comp measurable_snd)) + (fun ad : α×α => F ad.1 ad.2)).integrable (by norm_num : (1:ENNReal) ≤ 2) + rw [integral_prod _ hi] + simp_rw [integral_finite_partition (μ := μ) hσ (F (σ _))] + rw [integral_finite_partition (μ := μ) hσ (fun a => ∑ d, binMass μ σ d*F a d)] + simp only [Finset.mul_sum,mul_assoc] + +lemma fieldRadicand_pullback {σ : ℝ → α} (hσ : Measurable σ) + (hm : ∀ a, 0 < binMass μ σ a) (h : α → ℝ) (z : Parameters α) (x : ℝ) : + fieldRadicand μ (fun x => h (σ x)) (pullback μ σ (paramB z)) + (pullback μ σ (paramR z)) x= + finiteRadicalSq (massRoot μ σ) (fun a => v (h a)) z (σ x) := by + rw [fieldRadicand_expansion (memLp_pullback hσ _) (memLp_pullback hσ _) + (measurable_finite_comp hσ h)] + rw [integral_pullback_energy hσ hm (paramB z) (paramR z) + (fun a => (v (h (σ x))+v (h a))^2)] + simp_rw [mul_comm (v (h (σ x))+v (h (σ _))) (pullback μ σ (paramB z) _)] + rw [integral_pullback hσ hm (paramB z) (fun a => v (h (σ x))+v (h a))] + rfl + +lemma fieldDiagonal_partition {σ : ℝ → α} (hσ : Measurable σ) (h : α → ℝ) (x : ℝ) : + fieldDiagonal μ (fun x => h (σ x)) x= + ∑ d, massRoot μ σ d^2*(v (h d)^2/(w (h (σ x))+w (h d))) := by + simp_rw [massRoot_sq] + exact integral_finite_partition hσ (fun d => v (h d)^2/(w (h (σ x))+w (h d))) + +lemma field_diagonal_pullback {σ : ℝ → α} (hσ : Measurable σ) + (hm : ∀ a, 0 < binMass μ σ a) (β : ℝ) (h : α → ℝ) (z : Parameters α) : + (∫ x, (β^2*fieldDiagonal μ (fun x => h (σ x)) x)* + (pullback μ σ (paramB z) x^2+pullback μ σ (paramR z) x^2) ∂μ)= + β^2*(∑ a, ∑ d, massRoot μ σ d^2*(v (h d)^2/(w (h a)+w (h d)))* + ((paramB z a)^2+(paramR z a)^2)) := by + simp_rw [fieldDiagonal_partition hσ h,mul_assoc,integral_const_mul] + rw [integral_pullback_energy hσ hm (paramB z) (paramR z) + (fun a => ∑ d, massRoot μ σ d^2*(v (h d)^2/(w (h a)+w (h d))))] + simp only [Finset.sum_mul, mul_assoc] + +lemma field_kernel_pullback {σ : ℝ → α} (hσ : Measurable σ) + (hm : ∀ a, 0 < binMass μ σ a) (h : α → ℝ) (B : α → ℝ) : + (∫ z : ℝ×ℝ, pullback μ σ B z.1*kernel (h (σ z.1)) (h (σ z.2))* + pullback μ σ B z.2 ∂μ.prod μ)= + ∑ a, ∑ d, massRoot μ σ a*B a*kernel (h a) (h d)*(massRoot μ σ d*B d) := by + change (∫ z : ℝ×ℝ, (fun a d => (B a/massRoot μ σ a)*kernel (h a) (h d)* + (B d/massRoot μ σ d)) (σ z.1) (σ z.2) ∂μ.prod μ)=_ + rw [integral_finite_partition_prod (μ := μ) hσ (fun a d => (B a/massRoot μ σ a)*kernel (h a) (h d)*(B d/massRoot μ σ d))] + apply Finset.sum_congr rfl + intro a _ + apply Finset.sum_congr rfl + intro d _ + rw [←massRoot_sq σ a,←massRoot_sq σ d] + field_simp [(massRoot_pos hm a).ne',(massRoot_pos hm d).ne'] + +theorem fieldForm_pullback {σ : ℝ → α} (hσ : Measurable σ) + (hm : ∀ a, 0 < binMass μ σ a) (β : ℝ) (h : α → ℝ) (z : Parameters α) : + fieldForm μ β (fun x => h (σ x)) (pullback μ σ (paramB z)) + (pullback μ σ (paramR z))=finiteV β (massRoot μ σ) h z := by + unfold fieldForm + rw [field_diagonal_pullback hσ hm β h z,field_kernel_pullback hσ hm] + simp_rw [fieldRadicand_pullback hσ hm h z] + rw [integral_pullback hσ hm (paramB z) h, + integral_pullback hσ hm (paramB z) (fun a => v (h a)), + integral_pullback hσ hm (paramB z) (fun a => h a*v (h a)), + integral_pullback hσ hm (paramB z) (fun a => m (h a)*v (h a)), + integral_pullback hσ hm (paramR z) (fun a => sqrt (finiteRadicalSq (massRoot μ σ) (fun a => v (h a)) z a))] + have hmean : (∫ x, pullback μ σ (paramB z) x ∂μ)=moment (massRoot μ σ) (paramB z) (fun _ => 1) := by + simpa only [mul_one] using integral_pullback hσ hm (paramB z) (fun _ => 1) + rw [hmean] + unfold finiteV finiteA finiteGaussian moment + ring + +end SKRatio.Bins + +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Quantization/BinStability.lean b/lean/OAI/Probability/SKRatio/Quantization/BinStability.lean new file mode 100644 index 0000000000000000000000000000000000000000..56f857123d4276cb1dfc8d70f4605e9f77338513 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Quantization/BinStability.lean @@ -0,0 +1,193 @@ +import Mathlib +import OAI.Probability.SKRatio.Quantization.BinForm +import OAI.Probability.SKRatio.Quantization.BinNet + +namespace OAI + +noncomputable section +open scoped BigOperators Matrix +open MeasureTheory ProbabilityTheory Filter Real +namespace SKRatio.Bins +open Planted Scalar SKRatioClock.Regression MatrixNet Calculus +variable {n : ℕ} +attribute [local instance] Classical.propDecidable + +def siteNorm (f : Fin n → ℝ) : ℝ := ‖WithLp.toLp 2 f‖/sqrt (n:ℝ) + +lemma siteNorm_nonneg (f : Fin n → ℝ) : 0≤ siteNorm f := by unfold siteNorm; positivity + +lemma siteNorm_sq (f : Fin n → ℝ) : siteNorm f^2=(∑ i, f i^2)/(n:ℝ) := by + rw [siteNorm,div_pow,EuclideanSpace.real_norm_sq_eq,sq_sqrt (Nat.cast_nonneg n)] + +lemma siteNorm_add (f g : Fin n → ℝ) : + siteNorm (fun i => f i+g i)≤ siteNorm f+siteNorm g := by + unfold siteNorm + rw [←add_div] + exact div_le_div_of_nonneg_right + (norm_add_le (WithLp.toLp 2 f) (WithLp.toLp 2 g)) (sqrt_nonneg _) + +lemma siteNorm_le_of_abs_le {f : Fin n → ℝ} {D : ℝ} (hD : 0≤D) + (hf : ∀ i, |f i|≤D) : siteNorm f≤D := by + have hs : (∑ i, f i^2)≤(n:ℝ)*D^2 := by + calc + _ ≤ ∑ _i : Fin n, D^2 := Finset.sum_le_sum (fun i _ => by + simpa only [sq_abs] using (sq_le_sq₀ (abs_nonneg _) hD).mpr (hf i)) + _ = _ := by simp only [Finset.sum_const,Finset.card_univ,Fintype.card_fin,nsmul_eq_mul] + by_cases hn : n=0 + · simp only [siteNorm,hn,Nat.cast_zero,sqrt_zero,div_zero] + exact hD + · have hnR : (0:ℝ) f i*g i)≤D*siteNorm f := by + have hs : (∑ i, (f i*g i)^2)≤D^2*(∑ i, f i^2) := by + rw [Finset.mul_sum] + apply Finset.sum_le_sum + intro i _ + have hh : g i^2≤D^2 := by simpa only [sq_abs] using (sq_le_sq₀ (abs_nonneg _) hD).mpr (hg i) + rw [mul_pow,mul_comm (D^2)] + exact mul_le_mul_of_nonneg_left hh (sq_nonneg _) + have hh : siteNorm (fun i => f i*g i)^2≤(D*siteNorm f)^2 := by + rw [mul_pow,siteNorm_sq,siteNorm_sq,←mul_div_assoc] + exact div_le_div_of_nonneg_right hs (Nat.cast_nonneg n) + have hz : 0≤D*siteNorm f := mul_nonneg hD (siteNorm_nonneg f) + nlinarith only [hh,siteNorm_nonneg (fun i => f i*g i),hz] + +lemma siteMoment_abs_le {p : Fin n → ℝ} (hp : ∑ i, p i^2=1) (f : Fin n → ℝ) : + |siteMoment p f|≤ siteNorm f := by + have hh := abs_real_inner_le_norm (WithLp.toLp 2 p) (WithLp.toLp 2 f) + rw [norm_of_sum_sq_one hp,one_mul] at hh + have he : inner ℝ (WithLp.toLp 2 p) (WithLp.toLp 2 f) = ∑ i, p i*f i := by + simp only [PiLp.inner_apply,RCLike.inner_apply,conj_trivial,mul_comm] + rw [he] at hh + unfold siteMoment siteNorm + rw [abs_div,abs_of_nonneg (sqrt_nonneg _)] + exact div_le_div_of_nonneg_right hh (sqrt_nonneg _) + +lemma siteMoment_sub (p f g : Fin n → ℝ) : + siteMoment p (fun i => f i-g i)=siteMoment p f-siteMoment p g := by + simp only [siteMoment,mul_sub,Finset.sum_sub_distrib,sub_div] + +lemma siteMoment_one {p : Fin n → ℝ} (hp : ∑ i, p i^2=1) : + |siteMoment p (fun _ => 1)|≤1 := + (siteMoment_abs_le hp _).trans (siteNorm_le_of_abs_le (by norm_num) (fun _ => by norm_num)) + +lemma v_abs_le_one (x : ℝ) : |v x|≤1 := by rw [abs_of_nonneg (v_pos x).le]; exact v_le_one x + +lemma siteMoment_v {p : Fin n → ℝ} (hp : ∑ i, p i^2=1) (H : Fin n → ℝ) : + |siteMoment p (fun i => v (H i))|≤1 := + (siteMoment_abs_le hp _).trans (siteNorm_le_of_abs_le (by norm_num) (fun _ => v_abs_le_one _)) + +lemma product_error {x y x' y' S T d e : ℝ} (hS : 0≤S) (hT : 0≤T) + (hy : |y|≤S) (hx : |x'|≤T) (hd : |x-x'|≤d) (he : |y-y'|≤e) : + |x*y-x'*y'|≤d*S+T*e := by + rw [show x*y-x'*y'=(x-x')*y+x'*(y-y') by ring] + calc + _ ≤ |(x-x')*y|+|x'*(y-y')| := abs_add_le _ _ + _ ≤ d*S+T*e := by + simp only [abs_mul] + exact add_le_add ((mul_le_mul_of_nonneg_left hy (abs_nonneg _)).trans + (mul_le_mul_of_nonneg_right hd hS)) + (mul_le_mul hx he (abs_nonneg _) hT) + +lemma mean_constant_rows (hn : 0 H i-H' i)≤d) (hsize : siteNorm H'≤T) + (hv : ∀ i, |v (H i)-v (H' i)|≤a) + (hmv : ∀ i, |m (H i)*v (H i)-m (H' i)*v (H' i)|≤a) + (hf : ∀ i j, |compactF (compactWeight (H i),compactWeight (H j))- + compactF (compactWeight (H' i),compactWeight (H' j))|≤a) + (hk : ∀ i j, |compactK (compactWeight (H i),compactWeight (H j))- + compactK (compactWeight (H' i),compactWeight (H' j))|≤a) : + |correctedForm β H p-correctedForm β H' p|≤2*d+2*T*a+5*β^2*a := by + have hH : |siteMoment p H-siteMoment p H'|≤d := by + rw [←siteMoment_sub] + exact (siteMoment_abs_le hp _).trans he + have hV : |siteMoment p (fun i => v (H i))-siteMoment p (fun i => v (H' i))|≤a := by + rw [←siteMoment_sub] + exact (siteMoment_abs_le hp _).trans (siteNorm_le_of_abs_le ha hv) + have hMV : |siteMoment p (fun i => m (H i)*v (H i))- + siteMoment p (fun i => m (H' i)*v (H' i))|≤a := by + rw [←siteMoment_sub] + exact (siteMoment_abs_le hp _).trans (siteNorm_le_of_abs_le ha hmv) + have hHv : |siteMoment p (fun i => H i*v (H i))- + siteMoment p (fun i => H' i*v (H' i))|≤d+T*a := by + rw [←siteMoment_sub] + apply (siteMoment_abs_le hp _).trans + have heq : (fun i => H i*v (H i)-H' i*v (H' i))= + (fun i => (H i-H' i)*v (H i)+H' i*(v (H i)-v (H' i))) := by funext i; ring + rw [heq] + apply (siteNorm_add _ _).trans + have h1 := siteNorm_mul_le (f := fun i => H i-H' i) (by norm_num : (0:ℝ)≤1) + (fun i => v_abs_le_one (H i)) + have h2 := siteNorm_mul_le (f := H') ha hv + have h3 := mul_le_mul_of_nonneg_left hsize ha + nlinarith only [h1,h2,h3,he] + have h1 := product_error (by norm_num : (0:ℝ)≤1) hT (siteMoment_v hp H) + ((siteMoment_abs_le hp H').trans hsize) hH hV + have h₂ : |siteMoment p (fun _ => 1)*siteMoment p (fun i => H i*v (H i))- + siteMoment p (fun _ => 1)*siteMoment p (fun i => H' i*v (H' i))|≤d+T*a := by + rw [←mul_sub,abs_mul,mul_comm] + exact (mul_le_mul hHv (siteMoment_one hp) (abs_nonneg _) + (add_nonneg hd (mul_nonneg hT ha))).trans_eq (mul_one _) + have h₃ : |β^2*siteMoment p (fun _ => 1)* + (siteMoment p (fun i => v (H i))-siteMoment p (fun i => v (H' i)))|≤β^2*a := by + rw [abs_mul,abs_mul,abs_of_nonneg (sq_nonneg β)] + exact mul_le_mul ((mul_le_mul_of_nonneg_left (siteMoment_one hp) (sq_nonneg β)).trans_eq (mul_one _)) + hV (abs_nonneg _) (sq_nonneg β) + have h₄ : |2*β^2*siteMoment p (fun _ => 1)* + (siteMoment p (fun i => m (H i)*v (H i))-siteMoment p (fun i => m (H' i)*v (H' i)))|≤2*β^2*a := by + rw [abs_mul,abs_mul,abs_of_nonneg (by positivity : 0≤2*β^2)] + exact mul_le_mul ((mul_le_mul_of_nonneg_left (siteMoment_one hp) (by positivity : 0≤2*β^2)).trans_eq (mul_one _)) + hMV (abs_nonneg _) (by positivity) + have h₅ := diagonalForm_field_bound (fun _ _ => β^2/(n:ℝ)) compactF + (fun i => compactWeight (H i)) (fun i => compactWeight (H' i)) p ha + (fun i => (mean_constant_rows hn β i).le) hf + have h₆ := weightedForm_field_bound (fun _ _ => β^2/(n:ℝ)) compactK + (fun i => compactWeight (H i)) (fun i => compactWeight (H' i)) p ha (sq_nonneg β) + (fun i => (mean_constant_rows hn β i).le) (fun i => (mean_constant_rows hn β i).le) hk + rw [hp,mul_one] at h₅ h₆ + let A := siteMoment p H*siteMoment p (fun i => v (H i))- + siteMoment p H'*siteMoment p (fun i => v (H' i)) + let B := siteMoment p (fun _ => 1)*siteMoment p (fun i => H i*v (H i))- + siteMoment p (fun _ => 1)*siteMoment p (fun i => H' i*v (H' i)) + let C := β^2*siteMoment p (fun _ => 1)*(siteMoment p (fun i => v (H i))-siteMoment p (fun i => v (H' i))) + let D := 2*β^2*siteMoment p (fun _ => 1)*(siteMoment p (fun i => m (H i)*v (H i))- + siteMoment p (fun i => m (H' i)*v (H' i))) + let E := diagonalForm (fun _ _ => β^2/(n:ℝ)) compactF (fun i => compactWeight (H i)) p- + diagonalForm (fun _ _ => β^2/(n:ℝ)) compactF (fun i => compactWeight (H' i)) p + let F := weightedForm (fun _ _ => β^2/(n:ℝ)) compactK (fun i => compactWeight (H i)) p- + weightedForm (fun _ _ => β^2/(n:ℝ)) compactK (fun i => compactWeight (H' i)) p + have heq : correctedForm β H p-correctedForm β H' p=A+B-C+D+E+F := by + dsimp [correctedForm,A,B,C,D,E,F]; ring + rw [heq] + have ht : |A+B-C+D+E+F|≤|A|+|B|+|C|+|D|+|E|+|F| := by + calc + _ ≤ |A+B-C+D+E|+|F| := abs_add_le _ _ + _ ≤ (|A+B-C+D|+|E|)+|F| := by gcongr; exact abs_add_le _ _ + _ ≤ ((|A+B-C|+|D|)+|E|)+|F| := by gcongr; exact abs_add_le _ _ + _ ≤ (((|A+B|+|C|)+|D|)+|E|)+|F| := by gcongr; exact abs_sub _ _ + _ ≤ _ := by gcongr; exact abs_add_le _ _ + change |A|≤_ at h1 + change |B|≤_ at h₂ + change |C|≤_ at h₃ + change |D|≤_ at h₄ + change |E|≤_ at h₅ + change |F|≤_ at h₆ + nlinarith only [ht,h1,h₂,h₃,h₄,h₅,h₆] + +end SKRatio.Bins + +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Quantization/BinTail.lean b/lean/OAI/Probability/SKRatio/Quantization/BinTail.lean new file mode 100644 index 0000000000000000000000000000000000000000..49aa40735b57dab4be830236fece0fc8ab198e78 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Quantization/BinTail.lean @@ -0,0 +1,80 @@ +import Mathlib +import OAI.Probability.SKRatio.Quantization.BinForm +import OAI.Probability.SKRatio.Quantization.BinNet + +namespace OAI + +noncomputable section +open scoped BigOperators Matrix +open MeasureTheory ProbabilityTheory Filter Real +namespace SKRatio.Bins +open Planted Scalar SKRatioClock.Regression MatrixNet Calculus +variable {α : Type*} [Fintype α] [DecidableEq α] +attribute [local instance] Classical.propDecidable + +def binFormBad {n : ℕ} (β : ℝ) (h : α → ℝ) (σ : Fin n → α) + (K C : ℝ) : Set ((Fin n × Fin n) → ℝ) := + {g | euclideanOpNorm (fieldProjection n*(β • goe g)*fieldProjection n)≤K ∧ + ∃ p : Fin n → ℝ, (∑ i, p i^2)=1 ∧ C < + p ⬝ᵥ ((fieldProjection n*(β • goe g)*fieldProjection n)*ᵥ + (fun i => v (h (σ i))*p i))+ correctedForm β (fun i => h (σ i)) p} + +theorem binForm_tail {β K a : ℝ} (hβ : 0<β) (hK : 0≤K) (ha : 0 {g : (Fin n × Fin n) → ℝ | + finiteGaussian β (binT σ) (fun d => v (h d)) z+a ≤ + projectedSup β (fun i => v (h (σ i))) (vectorOf z : Directions σ → Fin n → ℝ) g} + have hsub : binFormBad β h σ K (C+2*a) ⊆ ⋃ z∈F, E z := by + intro g hg + obtain ⟨hM,p,hp,hbad⟩ := hg + obtain ⟨u,hu⟩ := vectorOf_surjective hc p hp + let z := parametersOf σ p hp + obtain ⟨z',hz',hnet⟩ := hF hn σ hc _ hM z u + have he : correctedForm β (fun i => h (σ i)) p=finiteA β (binT σ) h z := by + rw [←hu] + exact correctedForm_bin (fun d => lt_of_lt_of_le (by norm_num) (hc d)) β h z u + change vectorOf z u=p at hu + rw [hu] at hnet + rw [he] at hbad + have hsup := le_projectedSup β (fun i => v (h (σ i))) + (vectorOf_continuous z') g u + have hCZ := hC z' + dsimp only [finiteV] at hCZ + have htail : g∈E z' := by + change finiteGaussian β (binT σ) (fun d => v (h d)) z'+a ≤ + projectedSup β (fun i => v (h (σ i))) (vectorOf z' : Directions σ → Fin n → ℝ) g + have hS : (vectorOf z' u ⬝ᵥ + ((fieldProjection n*(β • goe g)*fieldProjection n)*ᵥ + (fun i => v (h (σ i))*vectorOf z' u i))) ≤ + projectedSup β (fun i => v (h (σ i))) + (vectorOf z' : Directions σ → Fin n → ℝ) g := hsup + have hT := hbad.trans_le hnet + have hU := _root_.add_le_add_left (_root_.add_le_add_left hS (finiteA β (binT σ) h z')) a + have hV := hT.trans_le hU + linarith only [hV,hCZ] + exact Set.mem_iUnion.mpr ⟨z',Set.mem_iUnion.mpr ⟨hz',htail⟩⟩ + calc + _ ≤ (standardArrayLaw (Fin n × Fin n)).real (⋃ z∈F, E z) := measureReal_mono hsub (measure_ne_top _ _) + _ ≤ ∑ z∈F, (standardArrayLaw (Fin n × Fin n)).real (E z) := measureReal_biUnion_finset_le F E + _ ≤ ∑ _z∈F, exp (-a^2*(n:ℝ)/(π^2*β^2)) := by + apply Finset.sum_le_sum + intro z _ + exact normalized_projected_tail hn hc (fun d => v (h d)) + (fun d => by rw [abs_of_nonneg (v_pos _).le]; exact v_le_one _) hβ z ha.le + _ = _ := by simp only [Finset.sum_const,nsmul_eq_mul] + +end SKRatio.Bins + +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Quantization/BinWeightContinuity.lean b/lean/OAI/Probability/SKRatio/Quantization/BinWeightContinuity.lean new file mode 100644 index 0000000000000000000000000000000000000000..ea635ec8ce908cf3b96480cc9b0dc5054a01aae5 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Quantization/BinWeightContinuity.lean @@ -0,0 +1,69 @@ +import Mathlib +import OAI.Probability.SKRatio.Quantization.BinPartition +import OAI.Probability.SKRatio.Quantization.BinNet +import OAI.Probability.SKRatio.Variational.ScalarCoherent + +namespace OAI + +noncomputable section +open scoped BigOperators NNReal ENNReal Topology +open MeasureTheory ProbabilityTheory Filter Real +namespace SKRatio.Bins +open Planted Scalar +variable {α : Type*} [Fintype α] [DecidableEq α] + +omit [DecidableEq α] in +lemma finiteV_weight_tolerance (β : ℝ) (h : α → ℝ) {a : ℝ} (ha : 0 t d) h z-finiteV β (fun d => t' d) h z| + finiteV β (fun d => q.1 d) h q.2) := by + have ht : Continuous (fun q : WeightBox α × Parameters α => + fun d => (q.1 d : ℝ)) := continuous_pi (fun d => + continuous_subtype_val.comp ((continuous_apply d).comp continuous_fst)) + have hc' := (continuous_finiteV β h).comp (ht.prodMk + (continuous_snd : Continuous (fun q : WeightBox α × Parameters α => q.2))) + convert hc' using 1 + rfl + obtain ⟨δ,hδ,hcont⟩ := Metric.uniformContinuous_iff.mp + (CompactSpace.uniformContinuous_of_continuous hc) a ha + refine ⟨δ,hδ,fun t t' z hh => ?_⟩ + apply hcont (a := (t,z)) (b := (t',z)) + simp only [Prod.dist_eq,dist_self,max_lt_iff] + refine ⟨(dist_pi_lt_iff hδ).mpr ?_,hδ⟩ + intro d + simpa only [Subtype.dist_eq,Real.dist_eq] using hh d + +variable {Ω : Type*} [MeasurableSpace Ω] [MeasurableSpace α] + [MeasurableSingletonClass α] {μ : Measure Ω} [IsProbabilityMeasure μ] + +omit [DecidableEq α] in +lemma massRoot_le_one {σ : Ω → α} (hσ : Measurable σ) (a : α) : massRoot μ σ a≤1 := by + have hs : massRoot μ σ a^2≤1 := by + rw [←massRoot_unit (μ := μ) hσ] + exact Finset.single_le_sum (fun d _ => sq_nonneg (massRoot μ σ d)) (Finset.mem_univ a) + nlinarith only [hs] + +def populationBox {σ : Ω → α} (hσ : Measurable σ) : WeightBox α := + fun a => ⟨massRoot μ σ a,sqrt_nonneg _,massRoot_le_one hσ a⟩ + +lemma finiteV_population_tolerance {σ : Ω → α} (hσ : Measurable σ) + (β : ℝ) (h : α → ℝ) {a : ℝ} (ha : 0 (1-(u:ℝ))*compactV u) := + (continuous_const.sub continuous_subtype_val).mul continuous_compactV + obtain ⟨δv,hδv,hv⟩ := Metric.uniformContinuous_iff.mp + (CompactSpace.uniformContinuous_of_continuous continuous_compactV) a ha + obtain ⟨δm,hδm,hm⟩ := Metric.uniformContinuous_iff.mp + (CompactSpace.uniformContinuous_of_continuous cm) a ha + obtain ⟨δf,hδf,hf⟩ := Metric.uniformContinuous_iff.mp + (CompactSpace.uniformContinuous_of_continuous continuous_compactF) a ha + obtain ⟨δk,hδk,hk⟩ := Metric.uniformContinuous_iff.mp + (CompactSpace.uniformContinuous_of_continuous continuous_compactK) a ha + let δ := min (min δv δm) (min δf δk) + have hδ : 0<δ := lt_min (lt_min hδv hδm) (lt_min hδf hδk) + have hδv' : δ≤δv := (min_le_left _ _).trans (min_le_left _ _) + have hδm' : δ≤δm := (min_le_left _ _).trans (min_le_right _ _) + have hδf' : δ≤δf := (min_le_right _ _).trans (min_le_left _ _) + have hδk' : δ≤δk := (min_le_right _ _).trans (min_le_right _ _) + refine ⟨δ,hδ,fun H hH => ⟨?_,?_,?_,?_⟩⟩ + · intro x + have he := hv ((hH x).trans_le hδv') + simpa only [Real.dist_eq,compactV_weight] using he.le + · intro x + have he := hm ((hH x).trans_le hδm') + have heq (x : ℝ) : 1-(compactWeight x:ℝ)=m x := by dsimp [compactWeight,w]; ring + simpa only [Real.dist_eq,compactV_weight,heq] using he.le + · intro x y + have hd : dist (compactWeight x,compactWeight y) (compactWeight (H x),compactWeight (H y))<δf := by + rw [Prod.dist_eq,max_lt_iff] + exact ⟨(hH x).trans_le hδf',(hH y).trans_le hδf'⟩ + have he := hf hd + simpa only [Real.dist_eq,compactF_weight] using he.le + · intro x y + have hd : dist (compactWeight x,compactWeight y) (compactWeight (H x),compactWeight (H y))<δk := by + rw [Prod.dist_eq,max_lt_iff] + exact ⟨(hH x).trans_le hδk',(hH y).trans_le hδk'⟩ + have he := hk hd + simpa only [Real.dist_eq,compactK_weight] using he.le + +lemma field_error_tolerance (β T : ℝ) {e : ℝ} (he : 0 2*a+2*T*a+5*β^2*a+4*β*sqrt a) 0 := by fun_prop + simp only [ContinuousAt,mul_zero,add_zero,sqrt_zero] at hc + have hh := hc.eventually (gt_mem_nhds he) + have hu : ∀ᶠ a : ℝ in 𝓝 0, a<1 := gt_mem_nhds (by norm_num) + have hp : ∀ᶠ a : ℝ in 𝓝[>] 0, 0 X ⁻¹' {d})) := by + intro d e hde + exact Set.disjoint_left.mpr (fun ω hd he => hde ((Set.mem_singleton_iff.mp hd).symm.trans + (Set.mem_singleton_iff.mp he))) + have hsum : (∑ d, μ.real (X ⁻¹' {d})) = 1 := by + rw [←measureReal_iUnion_fintype hdis (fun d => (MeasurableSet.singleton d).preimage hX),hall] + simp [Measure.real] + have hb (d : D) : μ.real (R ⁻¹' E d ∩ X ⁻¹' {d}) ≤ B*μ.real (X ⁻¹' {d}) := by + have hi := hRX.measure_inter_preimage_eq_mul (E d) {d} (hE d) (MeasurableSet.singleton d) + change (μ _).toReal ≤ _ + rw [hi,ENNReal.toReal_mul] + exact mul_le_mul_of_nonneg_right (hB d) ENNReal.toReal_nonneg + calc + _ ≤ μ.real (⋃ d : D, R ⁻¹' E d ∩ X ⁻¹' {d}) := by + apply measureReal_mono _ (measure_ne_top _ _) + intro ω hω + exact Set.mem_iUnion.mpr ⟨X ω,hω,rfl⟩ + _ ≤ ∑ d, μ.real (R ⁻¹' E d ∩ X ⁻¹' {d}) := measureReal_iUnion_fintype_le _ + _ ≤ ∑ d, B*μ.real (X ⁻¹' {d}) := Finset.sum_le_sum (fun d _ => hb d) + _ = B := by rw [←Finset.mul_sum,hsum,mul_one] + +def residualFormBad {α : Type*} {n : ℕ} (β : ℝ) (h : α → ℝ) + (σ : Fin n → α) (K C : ℝ) : Set ((Fin n × Fin n) → ℝ) := + {M | euclideanOpNorm (fun i j => M (i,j)) ≤ K ∧ + ∃ p : Fin n → ℝ, (∑ i, p i^2)=1 ∧ C < + p ⬝ᵥ ((fun i j => M (i,j))*ᵥ (fun i => v (h (σ i))*p i))+ + correctedForm β (fun i => h (σ i)) p} + +lemma residualFormBad_measurable {α : Type*} {n : ℕ} + (β : ℝ) (h : α → ℝ) (σ : Fin n → α) (K C : ℝ) : + MeasurableSet (residualFormBad β h σ K C) := by + have hc : Continuous (fun M : (Fin n × Fin n) → ℝ => + euclideanOpNorm (fun i j => M (i,j))) := by + have : ContinuousSMul ℝ (EuclideanSpace ℝ (Fin n)) := + IsBoundedSMul.continuousSMul + have : ContinuousSMul ℝ (EuclideanSpace ℝ (Fin n) →L[ℝ] EuclideanSpace ℝ (Fin n)) := + ContinuousLinearMap.continuousSMul + exact continuous_norm.comp + (((Matrix.toEuclideanCLM (𝕜 := ℝ) (n := Fin n)).toAlgEquiv.toLinearEquiv.toLinearMap.continuous_of_finiteDimensional).comp + (by fun_prop)) + have ho : IsOpen {M : (Fin n × Fin n) → ℝ | + ∃ p : Fin n → ℝ, (∑ i, p i^2)=1 ∧ C < + p ⬝ᵥ ((fun i j => M (i,j))*ᵥ (fun i => v (h (σ i))*p i))+ + correctedForm β (fun i => h (σ i)) p} := by + have he : {M : (Fin n × Fin n) → ℝ | ∃ p : Fin n → ℝ, (∑ i, p i^2)=1 ∧ C < + p ⬝ᵥ ((fun i j => M (i,j))*ᵥ (fun i => v (h (σ i))*p i))+ + correctedForm β (fun i => h (σ i)) p} = + ⋃ p : {p : Fin n → ℝ // (∑ i, p i^2)=1}, {M | C < + p.val ⬝ᵥ ((fun i j => M (i,j))*ᵥ (fun i => v (h (σ i))*p.val i))+ + correctedForm β (fun i => h (σ i)) p.val} := by + ext M + simp + rw [he] + apply isOpen_iUnion + intro p + apply isOpen_lt continuous_const + unfold dotProduct Matrix.mulVec + fun_prop + exact (measurableSet_le hc.measurable measurable_const).inter ho.measurableSet + +theorem random_binForm_tail {α : Type*} [Fintype α] [DecidableEq α] + [MeasurableSpace α] [MeasurableSingletonClass α] + {β K a C : ℝ} (hβ : 0<β) (hK : 0≤K) (ha : 0 q (augmentedField β g i)) d) ∧ + (∀ z : Parameters α, finiteV β (binT (fun i => q (augmentedField β g i))) h z≤C) ∧ + g ∈ binFormBad β h (fun i => q (augmentedField β g i)) K (C+2*a)} ≤ + N*exp (-a^2*(n:ℝ)/(π^2*β^2)) := by + obtain ⟨N,hN⟩ := binForm_tail hβ hK ha h + refine ⟨N,?_⟩ + intro n hn + let μ := standardArrayLaw (Fin n × Fin n) + let R := fun g : (Fin n × Fin n) → ℝ => fun p : Fin n × Fin n => + (fieldProjection n*(β • goe g)*fieldProjection n) p.1 p.2 + let X := fun g : (Fin n × Fin n) → ℝ => fun i => q (augmentedField β g i) + let good := fun σ : Fin n → α => (∀ d, 2≤count σ d) ∧ + (∀ z : Parameters α, finiteV β (binT σ) h z≤C) + let E := fun σ : Fin n → α => if good σ then residualFormBad β h σ K (C+2*a) else ∅ + have hX : Measurable X := by + apply Measurable.of_eval + intro i + apply hq.comp + unfold augmentedField augmented goe + fun_prop + have hi : IndepFun R X μ := by + have ht := (field_residual_independent hn β).comp measurable_id + (show Measurable (fun H : Fin n → ℝ => fun i => q (H i)) from + Measurable.of_eval (fun i => hq.comp (measurable_pi_apply i))) + exact ht + have hE (σ : Fin n → α) : MeasurableSet (E σ) := by + dsimp only [E] + split_ifs + · exact residualFormBad_measurable β h σ K (C+2*a) + · exact MeasurableSet.empty + have hb (σ : Fin n → α) : μ.real (R ⁻¹' E σ) ≤ + N*exp (-a^2*(n:ℝ)/(π^2*β^2)) := by + dsimp only [E] + split_ifs with hg + · exact hN hn σ hg.1 C hg.2 + · simp only [Set.preimage_empty,measureReal_empty] + positivity + apply (measureReal_mono ?_ (measure_ne_top μ _)).trans + (independent_finite_selection_bound hX hi E hE hb) + intro g hg + change R g ∈ E (X g) + dsimp only [E] + rw [ite_eq_left (show good (X g) from ⟨hg.1,hg.2.1⟩)] + exact hg.2.2 + +end SKRatio.Bins + +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Quantization/IntervalBins.lean b/lean/OAI/Probability/SKRatio/Quantization/IntervalBins.lean new file mode 100644 index 0000000000000000000000000000000000000000..f56ae3af6823bc56c6a057564c8cf5f3ae5c3d07 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Quantization/IntervalBins.lean @@ -0,0 +1,153 @@ +import Mathlib +import OAI.Probability.SKRatio.Gaussian.ExponentialEvents +import OAI.Probability.SKRatio.Gaussian.EmpiricalIntervals +import OAI.Probability.SKRatio.Variational.ScalarMoments +import OAI.Probability.SKRatio.Quantization.BinParameters + +namespace OAI + +noncomputable section +open scoped BigOperators NNReal ENNReal Topology +open MeasureTheory ProbabilityTheory Filter Real Set +namespace SKRatio.Bins +open Planted Scalar SKRatioClock.Regression +attribute [local instance] Classical.propDecidable + +def intervalBin {N : ℕ} (e : Fin N → ℝ) (x : ℝ) : Fin (N+1) := + ⟨(Finset.univ.filter (fun i => e i e i e i e i e i by have := hh.mpr hx; omega) + · intro h + have hh' : ¬ (intervalBin e x).val≤N-1 := fun hu => not_le.mpr h (hh.mp hu) + omega + +lemma intervalBin_eq_middle {N : ℕ} {e : Fin N → ℝ} (he : StrictMono e) + (x : ℝ) (j : Fin (N+1)) (hj0 : 0 by have := hlo.mpr hx; omega) + · exact hhi.mp (by omega) + · rintro ⟨hl,hu⟩ + have h1 := hhi.mpr hu + have h2 : ¬ (intervalBin e x).val≤j.val-1 := fun h => not_le.mpr hl (hlo.mp h) + omega + +lemma measurableSet_intervalBin {N : ℕ} (hN : 0 (count (fun i => intervalBin e (X n ω i)) j:ℝ)/(n:ℝ)) + (μ.real {x | intervalBin e x=j}) := by + have heq (n : ℕ) (ω : Ω n) : (count (fun i => intervalBin e (X n ω i)) j:ℝ) = + ∑ i, {x | intervalBin e x=j}.indicator (fun _ : ℝ => (1:ℝ)) (X n ω i) := by + simp only [count,Finset.cast_card,Set.indicator,Set.mem_ofPred_eq] + exact Finset.sum_filter _ _ + simp_rw [heq] + by_cases hj0 : j.val=0 + · have hj : j=0 := Fin.ext hj0 + simpa only [hj,intervalBin_eq_zero hN he,Set.Iic_def] using hX.Iic (e ⟨0,hN⟩) + · by_cases hjN : j.val=N + · have hj : j=Fin.last N := Fin.ext hjN + simpa only [hj,intervalBin_eq_last hN he,Set.Ioi_def] using hX.Ioi (e ⟨N-1,by omega⟩) + · have h1 : 0 hE.ne' (gaussianReal_absolutelyContinuous' μ hs h) + +lemma intervalBin_mass_pos {N : ℕ} (hN : 0 (x:ℝ)) hh + rw [variance_coe,NNReal.coe_zero] at hh' + exact hβ (sq_eq_zero_iff.mp hh') + apply gaussianReal_real_pos_of_volume_pos (β^2) hv + by_cases hj0 : j.val=0 + · have hj : j=0 := Fin.ext hj0 + simp only [hj,intervalBin_eq_zero hN he,Set.Iic_def,Real.volume_Iic] + exact ENNReal.zero_lt_top + · by_cases hjN : j.val=N + · have hj : j=Fin.last N := Fin.ext hjN + simp only [hj,intervalBin_eq_last hN he,Set.Ioi_def,Real.volume_Ioi] + exact ENNReal.zero_lt_top + · have h1 : 0 gridQuant R N x-x)≤a := by + unfold l2Norm + apply (sqrt_le_iff).mpr ⟨ha,?_⟩ + simpa only [sub_sq_comm] using herr + have ht := l2Norm_add (memLp_field β) (hH.sub (memLp_field β)) + change l2Norm (fieldLaw β) (fun x => x+(gridQuant R N x-x))≤ + l2Norm (fieldLaw β) id+l2Norm (fieldLaw β) (fun x => gridQuant R N x-x) at ht + have heq : (fun x => x+(gridQuant R N x-x))=gridQuant R N := by ext x; ring + rw [heq] at ht + rw [l2Norm_field] at ht + linarith only [ht,he] + +lemma finiteV_le_of_quantizer {β C a : ℝ} (hβ : 0≤β) (ha : 0≤a) + (hscalar : ∀ b r : ℝ → ℝ, MemLp b 2 (fieldLaw β) → MemLp r 2 (fieldLaw β) → + (∫ x, b x^2+r x^2 ∂fieldLaw β)=1 → variational β b r≤C) + {R : ℝ} (hR : 0 x-gridQuant R N x)≤a := + (sqrt_le_iff).mpr ⟨ha,herr⟩ + have hbnd := fieldForm_error (μ := fieldLaw β) β hβ hb hr + (measurable_pullback hs _) (measurable_pullback hs _) measurable_id + (measurable_gridQuant hR hN) (memLp_field β) hH he ha hT herr' + ((quantizer_l2Norm_le hR hN ha herr).trans hsize) hv hmv hf hk + have hp := fieldForm_pullback (μ := fieldLaw β) hs hm β (gridRep R N) z + change fieldForm (fieldLaw β) β (gridQuant R N) b r = _ at hp + rw [fieldForm_id,hp] at hbnd + have hu := hscalar b r hb hr he + have hle := neg_le_abs (variational β b r-finiteV β (massRoot (fieldLaw β) σ) (gridRep R N) z) + change finiteV β (massRoot (fieldLaw β) σ) (gridRep R N) z≤_ + linarith only [hle,hbnd,hu] + +theorem scalar_quantizer_exists + {Ω : ℕ → Type*} [∀ n, MeasurableSpace (Ω n)] + {ρ : ∀ n, Measure (Ω n)} {X : ∀ n, Ω n → Fin n → ℝ} + (hX : ExponentialSquareTails ρ X) + {β K C e : ℝ} (hβ : 0<β) (hK : 0≤K) (he : 0 {ω | a≤ siteNorm (fun i => X n ω i-gridQuant R N (X n ω i))}) := by + let T := sqrt (β^2+β^4)+2 + have hT : 0≤T := by dsimp [T]; positivity + obtain ⟨a,ha,ha1,hea⟩ := field_error_tolerance β (T+K/2) he + have htotal : 2*a+2*T*a+5*β^2*a+K*a+4*β*sqrt a not_le.mpr hxL (by + simpa only [gridCut,Fin.val_mk,Nat.cast_zero,mul_zero,add_zero] using + (intervalBin_eq_zero (by omega) (gridCut_strictMono hR hN) x).mp hh) + have hjLast : j≠Fin.last (N+1) := fun hh => not_lt.mpr hxU (by + simpa only [Nat.add_sub_cancel,gridCut,Fin.val_mk,div_mul_cancel₀ _ ((Nat.cast_ne_zero.mpr hN.ne' : (N:ℝ)≠0)), + show -R+2*R=R by ring] using + (intervalBin_eq_last (by omega) (gridCut_strictMono hR hN) x).mp hh) + have hj0' : 0 hj0 (Fin.ext he); omega + have hjN : j.val hjLast (Fin.ext he) + omega + have hbounds := (intervalBin_eq_middle (gridCut_strictMono hR hN) x j hj0' hjN).mp rfl + change |x-gridRep R N j|≤_ + rw [gridRep_middle R j hjN] + simp only [gridCut] at hbounds ⊢ + have hcast : ((j.val-1:ℕ):ℝ)=(j.val:ℝ)-1 := by rw [Nat.cast_sub (by omega),Nat.cast_one] + rw [hcast] at hbounds + rw [abs_of_nonpos (sub_nonpos.mpr hbounds.2)] + linarith only [hbounds.1] + +lemma gridQuant_square_error {R : ℝ} (hR : 0 x^2) μ) : + Integrable (fun x => (x-gridQuant R N x)^2) μ := by + apply ((integrable_const ((2*R/N)^2)).add (integrable_squareTail hi R)).mono' + ((measurable_id.sub (measurable_gridQuant hR hN)).pow_const 2).aestronglyMeasurable + exact ae_of_all _ (fun x => by + rw [norm_eq_abs,abs_of_nonneg (sq_nonneg _)] + exact gridQuant_square_error hR hN x) + +theorem quantizer_exists + {Ω : ℕ → Type*} [∀ n, MeasurableSpace (Ω n)] + {ρ : ∀ n, Measure (Ω n)} {X : ∀ n, Ω n → Fin n → ℝ} + (hX : ExponentialSquareTails ρ X) + {μ : Measure ℝ} [IsProbabilityMeasure μ] (hi : Integrable (fun x : ℝ => x^2) μ) + {δ d : ℝ} (hδ : 0<δ) (hd : 0 {ω | d≤ siteNorm (fun i => X n ω i-gridQuant R N (X n ω i))}) := by + obtain ⟨Rt,hRt,ht⟩ := hX (d^2/2) (by positivity) + obtain ⟨Rc,hRc,hc⟩ := tanh_tail_uniform hδ + have he := (tendsto_integral_squareTail hi).eventually (gt_mem_nhds (by positivity : (0:ℝ) X n ω i-gridQuant R N (X n ω i)) at hω + have hnR : (0:ℝ) gridQuant_square_error hR hN0 (X n ω i)) + have h3 := Finset.sum_le_sum (s := Finset.univ) (fun i _ => squareTail_antitone hRtR (X n ω i)) + rw [Finset.sum_add_distrib,Finset.sum_const,Finset.card_univ,Fintype.card_fin,nsmul_eq_mul] at h2 + have hh := div_le_div_of_nonneg_right h2 hnR.le + rw [add_div,mul_div_cancel_left₀ _ (ne_of_gt hnR)] at hh + have hh' := div_le_div_of_nonneg_right h3 hnR.le + change d^2/2≤(∑ i, squareTail Rt (X n ω i))/(n:ℝ) + nlinarith only [h1,hh,hh',hmeshd,sq_nonneg d] + +end SKRatio.Bins + +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Quantization/TanhEnds.lean b/lean/OAI/Probability/SKRatio/Quantization/TanhEnds.lean new file mode 100644 index 0000000000000000000000000000000000000000..865d6a822bb7e1fea4686aae7df792289c09562f --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Quantization/TanhEnds.lean @@ -0,0 +1,98 @@ +import Mathlib +import OAI.Probability.SKRatio.Matrices.GaussianSquareTails + +namespace OAI + +noncomputable section +open scoped Topology +open Filter MeasureTheory Real Set +namespace SKRatio.Bins +open SKRatioClock.Regression + +lemma tanh_exp_negative (x : ℝ) : tanh x=(1-exp (-2*x))/(1+exp (-2*x)) := by + rw [tanh_eq] + have he : exp (-2*x)=exp (-x)/exp x := by + rw [←exp_sub]; congr 1; ring + rw [he] + field_simp + +lemma tendsto_tanh_atTop : Tendsto tanh atTop (𝓝 1) := by + have hn : Tendsto (fun x : ℝ => -2*x) atTop atBot := by + convert tendsto_neg_atTop_atBot.comp (tendsto_id.const_mul_atTop (by norm_num : (0:ℝ)<2)) using 1 + funext x + simp + have he := tendsto_exp_atBot.comp hn + have hh := ((tendsto_const_nhds (x := (1 : ℝ))).sub he).div ((tendsto_const_nhds (x := (1 : ℝ))).add he) + (by norm_num : (1:ℝ)+0≠0) + change Tendsto (fun x : ℝ => (1-exp (-2*x))/(1+exp (-2*x))) atTop (𝓝 ((1-0)/(1+0))) at hh + simpa only [sub_zero,add_zero,div_one,←tanh_exp_negative] using hh + +lemma tanh_tail_uniform {δ : ℝ} (hδ : 0<δ) : ∃ R : ℝ, 0 x^2) μ) (R : ℝ) : + Integrable (squareTail R) μ := by + apply hi.mono' (measurable_squareTail R).aestronglyMeasurable + exact ae_of_all _ (fun x => by + rw [norm_eq_abs,abs_of_nonneg (squareTail_nonneg _ _)] + exact squareTail_le R x) + +lemma tendsto_integral_squareTail {μ : Measure ℝ} (hi : Integrable (fun x : ℝ => x^2) μ) : + Tendsto (fun R : ℕ => ∫ x, squareTail R x ∂μ) atTop (𝓝 0) := by + have hh : Tendsto (fun R : ℕ => ∫ x, squareTail R x ∂μ) atTop (𝓝 (∫ _x, (0:ℝ) ∂μ)) := by + apply tendsto_integral_of_dominated_convergence (fun x : ℝ => x^2) + · intro R + exact (measurable_squareTail R).aestronglyMeasurable + · exact hi + · intro R + exact ae_of_all _ (fun x => by + rw [norm_eq_abs,abs_of_nonneg (squareTail_nonneg _ _)] + exact squareTail_le R x) + · apply ae_of_all + intro x + apply tendsto_const_nhds.congr' + filter_upwards [eventually_ge_atTop (⌈|x|⌉₊)] with R hR + have hx : |x|≤(R:ℝ) := (Nat.le_ceil _).trans (by exact_mod_cast hR) + simp [squareTail,not_lt.mpr hx] + simpa only [integral_zero] using hh + +end SKRatio.Bins + +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Variational/CompactField.lean b/lean/OAI/Probability/SKRatio/Variational/CompactField.lean new file mode 100644 index 0000000000000000000000000000000000000000..3d70bfaaddbdfbcfe4aa1649b0ac5f26501e56f0 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Variational/CompactField.lean @@ -0,0 +1,123 @@ +import Mathlib +import OAI.Probability.SKRatio.Calculus.PlusSpin +import OAI.Probability.SKRatio.Variational.ScalarKernel + +namespace OAI + +section +noncomputable section +open scoped BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Set Real +namespace SKRatio.Planted +open Scalar Calculus + +abbrev FieldWeight := Set.Icc (0:ℝ) 2 + +instance : CompactSpace FieldWeight := inferInstanceAs (CompactSpace (Set.Icc (0:ℝ) 2)) + +def compactWeight (h : ℝ) : FieldWeight := + ⟨w h, (w_pos h).le, by unfold w; linarith [(m_bounds h).1]⟩ + +lemma compactWeight_lipschitz : LipschitzWith 1 compactWeight := by + apply LipschitzWith.of_dist_le_mul + intro h t + change |w h-w t| ≤ (1:ℝ)*|h-t| + simpa only [w,m,sub_sub_sub_cancel_left,abs_sub_comm,one_mul] using tanh_lipschitz_abs h t + +@[simp] lemma compactWeight_coe (h : ℝ) : (compactWeight h : ℝ) = w h := rfl + +def compactV (a : FieldWeight) : ℝ := (a:ℝ)*(2-a) + +def compactF (p : FieldWeight × FieldWeight) : ℝ := + (p.2:ℝ)^2*(2-p.2)^2/((p.1:ℝ)+p.2) +def compactK (p : FieldWeight × FieldWeight) : ℝ := + compactV p.1*compactV p.2/((p.1:ℝ)+p.2) + +lemma compactV_nonneg (a : FieldWeight) : 0≤compactV a := + mul_nonneg a.2.1 (sub_nonneg.mpr a.2.2) +lemma compactV_le_one (a : FieldWeight) : compactV a≤1 := by + dsimp [compactV] + nlinarith [sq_nonneg ((a:ℝ)-1)] +lemma compactV_le (a : FieldWeight) : compactV a≤2*a := by + dsimp [compactV] + nlinarith [sq_nonneg (a:ℝ)] +lemma compactF_nonneg (p : FieldWeight × FieldWeight) : 0≤compactF p := by + unfold compactF + exact div_nonneg (mul_nonneg (sq_nonneg _) (sq_nonneg _)) (add_nonneg p.1.2.1 p.2.2.1) +lemma compactK_nonneg (p : FieldWeight × FieldWeight) : 0≤compactK p := by + unfold compactK + exact div_nonneg (mul_nonneg (compactV_nonneg _) (compactV_nonneg _)) (add_nonneg p.1.2.1 p.2.2.1) + +lemma compactF_bound (p : FieldWeight × FieldWeight) : compactF p ≤ 4*(p.2:ℝ) := by + by_cases hz : (p.1:ℝ)+(p.2:ℝ)=0 + · simp only [compactF,hz,div_zero] + exact mul_nonneg (by norm_num) p.2.2.1 + have hd : 0<(p.1:ℝ)+(p.2:ℝ) := lt_of_le_of_ne (add_nonneg p.1.2.1 p.2.2.1) (Ne.symm hz) + apply (div_le_iff₀ hd).mpr + have hs : (2-(p.2:ℝ))^2≤4 := by nlinarith [p.2.2.1,p.2.2.2] + have hm := mul_le_mul_of_nonneg_left hs (sq_nonneg (p.2:ℝ)) + nlinarith only [hm,mul_nonneg p.1.2.1 p.2.2.1] + +lemma compactK_bound (p : FieldWeight × FieldWeight) : compactK p ≤ 4*(p.2:ℝ) := by + by_cases hz : (p.1:ℝ)+(p.2:ℝ)=0 + · simp only [compactK,hz,div_zero] + exact mul_nonneg (by norm_num) p.2.2.1 + have hd : 0<(p.1:ℝ)+(p.2:ℝ) := lt_of_le_of_ne (add_nonneg p.1.2.1 p.2.2.1) (Ne.symm hz) + apply (div_le_iff₀ hd).mpr + have hm := mul_le_mul (compactV_le p.1) (compactV_le p.2) + (compactV_nonneg p.2) (mul_nonneg (by norm_num : (0:ℝ)≤2) p.1.2.1) + nlinarith only [hm,sq_nonneg (p.2:ℝ)] + +lemma continuous_compactV : Continuous compactV := by unfold compactV; fun_prop + +lemma continuous_compact_div {f : FieldWeight × FieldWeight → ℝ} + (hnonneg : ∀ p, 0≤f p) (hbound : ∀ p, f p≤4*(p.2:ℝ)) + (hoff : ∀ p, (p.1:ℝ)+(p.2:ℝ)≠0 → ContinuousAt f p) : Continuous f := by + apply continuous_iff_continuousAt.mpr + intro p + by_cases hz : (p.1:ℝ)+(p.2:ℝ)=0 + · have h2 : (p.2:ℝ)=0 := by linarith [p.1.2.1,p.2.2.1] + have hp : f p=0 := le_antisymm (by simpa [h2] using hbound p) (hnonneg p) + rw [ContinuousAt,hp] + apply tendsto_of_tendsto_of_tendsto_of_le_of_le tendsto_const_nhds + (h := fun q : FieldWeight × FieldWeight => 4*(q.2:ℝ)) + (by simpa only [ContinuousAt,h2,mul_zero] using + (show Continuous (fun q : FieldWeight × FieldWeight => 4*(q.2:ℝ)) by fun_prop).continuousAt (x := p)) + hnonneg hbound + · exact hoff p hz + +lemma continuous_compactF : Continuous compactF := by + apply continuous_compact_div compactF_nonneg compactF_bound + intro p hp + exact ContinuousAt.div (by fun_prop) (by fun_prop) hp + +lemma continuous_compactK : Continuous compactK := by + apply continuous_compact_div compactK_nonneg compactK_bound + intro p hp + exact ContinuousAt.div + ((continuous_compactV.comp continuous_fst).mul (continuous_compactV.comp continuous_snd)).continuousAt + (by fun_prop) hp + +lemma compactV_weight (h : ℝ) : compactV (compactWeight h) = v h := by + unfold compactV compactWeight w v + dsimp + ring + +lemma compactF_weight (h t : ℝ) : compactF (compactWeight h,compactWeight t) = + v t^2/(w h+w t) := by + unfold compactF + simp only [compactWeight_coe,←mul_pow] + rw [show w t*(2-w t)=v t from compactV_weight t] + +lemma compactK_weight (h t : ℝ) : compactK (compactWeight h,compactWeight t) = + kernel h t := by + unfold compactK kernel + rw [compactV_weight,compactV_weight] + rfl + +end SKRatio.Planted + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Variational/FieldFunctional.lean b/lean/OAI/Probability/SKRatio/Variational/FieldFunctional.lean new file mode 100644 index 0000000000000000000000000000000000000000..72e6b1fc11169d7517619bb2319db3242bb870a0 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Variational/FieldFunctional.lean @@ -0,0 +1,226 @@ +import Mathlib +import OAI.Probability.SKRatio.Quantization.BinStability +import OAI.Probability.SKRatio.Variational.FieldRadical +import OAI.Probability.SKRatio.Variational.ScalarVariance + +namespace OAI + +noncomputable section +open scoped NNReal ENNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Real +namespace SKRatio.Bins +open Planted Scalar + +variable {μ : Measure ℝ} [IsProbabilityMeasure μ] + +def fieldDiagonal (μ : Measure ℝ) (H : ℝ → ℝ) (x : ℝ) : ℝ := + ∫ y, v (H y)^2/(w (H x)+w (H y)) ∂μ + +def fieldForm (μ : Measure ℝ) (β : ℝ) (H b r : ℝ → ℝ) : ℝ := + (∫ x, (β^2*fieldDiagonal μ H x)*(b x^2+r x^2) ∂μ)+ + (∫ x, b x*H x ∂μ)*(∫ x, b x*v (H x) ∂μ)+ + (∫ x, b x ∂μ)*(∫ x, b x*(H x*v (H x)) ∂μ)- + β^2*(∫ x, b x ∂μ)*(∫ x, b x*v (H x) ∂μ)+ + 2*β^2*(∫ x, b x ∂μ)*(∫ x, b x*(m (H x)*v (H x)) ∂μ)+ + β^2*(∫ z : ℝ×ℝ, b z.1*kernel (H z.1) (H z.2)*b z.2 ∂μ.prod μ)+ + β*(∫ x, r x*sqrt (fieldRadicand μ H b r x) ∂μ) + +lemma fieldForm_id (β : ℝ) (b r : ℝ → ℝ) : + fieldForm (fieldLaw β) β id b r=variational β b r := rfl + +lemma measurable_fieldDiagonal {H : ℝ → ℝ} (hH : Measurable H) : + Measurable (fieldDiagonal μ H) := by + have hm : StronglyMeasurable (fun z : ℝ×ℝ => v (H z.2)^2/(w (H z.1)+w (H z.2))) := + (continuous_diagonal_kernel.measurable.comp + ((hH.comp measurable_fst).prodMk (hH.comp measurable_snd))).stronglyMeasurable + exact hm.integral_prod_right.measurable + +lemma fieldDiagonal_integrable {H : ℝ → ℝ} (hH : Measurable H) (x : ℝ) : + Integrable (fun y => v (H y)^2/(w (H x)+w (H y))) μ := by + apply (integrable_const (2:ℝ)).mono' + (continuous_diagonal_kernel.measurable.comp (measurable_const.prodMk hH)).aestronglyMeasurable + exact ae_of_all _ (fun y => by simpa only [norm_eq_abs,Function.comp_apply] using abs_diagonal_kernel_le (H x) (H y)) + +lemma abs_fieldDiagonal_le {H : ℝ → ℝ} (hH : Measurable H) (x : ℝ) : + |fieldDiagonal μ H x| ≤ 2 := + integral_abs_bound (fieldDiagonal_integrable hH x) + (fun point => abs_diagonal_kernel_le (H x) (H point)) + +lemma fieldDiagonal_error {H H' : ℝ → ℝ} (hH : Measurable H) (hH' : Measurable H') + {a : ℝ} (hf : ∀ x y, |v (H y)^2/(w (H x)+w (H y))- + v (H' y)^2/(w (H' x)+w (H' y))| ≤ a) (x : ℝ) : + |fieldDiagonal μ H x-fieldDiagonal μ H' x| ≤ a := by + unfold fieldDiagonal + rw [←integral_sub (fieldDiagonal_integrable hH x) (fieldDiagonal_integrable hH' x)] + exact integral_abs_bound ((fieldDiagonal_integrable hH x).sub (fieldDiagonal_integrable hH' x)) (hf x) + +lemma fieldKernel_integrable {H b : ℝ → ℝ} (hH : Measurable H) (hb : MemLp b 2 μ) : + Integrable (fun z : ℝ×ℝ => b z.1*kernel (H z.1) (H z.2)*b z.2) (μ.prod μ) := by + have hI := hb.integrable (by norm_num : (1:ENNReal) ≤ 2) + apply (hI.norm.mul_prod hI.norm).mono' + ((hb.aestronglyMeasurable.comp_fst.mul + (continuous_kernel.measurable.comp ((hH.comp measurable_fst).prodMk + (hH.comp measurable_snd))).aestronglyMeasurable).mul hb.aestronglyMeasurable.comp_snd) + exact ae_of_all _ (fun z => by + change |b z.1*kernel (H z.1) (H z.2)*b z.2| ≤ |b z.1| * |b z.2| + simp only [abs_mul] + have hh := mul_le_mul_of_nonneg_right + (mul_le_mul_of_nonneg_left (abs_kernel_le_one (H z.1) (H z.2)) (abs_nonneg (b z.1))) (abs_nonneg (b z.2)) + simpa only [mul_one] using hh) + +lemma fieldKernel_error {H H' b : ℝ → ℝ} (hH : Measurable H) (hH' : Measurable H') + (hb : MemLp b 2 μ) (hb1 : l2Norm μ b ≤ 1) {a : ℝ} (ha : 0 ≤ a) + (hk : ∀ x y, |kernel (H x) (H y)-kernel (H' x) (H' y)| ≤ a) : + |(∫ z : ℝ×ℝ, b z.1*kernel (H z.1) (H z.2)*b z.2 ∂μ.prod μ)- + (∫ z : ℝ×ℝ, b z.1*kernel (H' z.1) (H' z.2)*b z.2 ∂μ.prod μ)| ≤ a := by + have hI := hb.integrable (by norm_num : (1:ENNReal) ≤ 2) + rw [←integral_sub (fieldKernel_integrable hH hb) (fieldKernel_integrable hH' hb)] + apply abs_integral_le_integral_abs.trans + have hi := integral_mono ((fieldKernel_integrable hH hb).sub (fieldKernel_integrable hH' hb)).abs + ((hI.abs.mul_prod hI.abs).const_mul a) (fun z : ℝ×ℝ => by + change |b z.1*kernel (H z.1) (H z.2)*b z.2-b z.1*kernel (H' z.1) (H' z.2)*b z.2| ≤ a*(|b z.1| * |b z.2|) + rw [show b z.1*kernel (H z.1) (H z.2)*b z.2-b z.1*kernel (H' z.1) (H' z.2)*b z.2= + (kernel (H z.1) (H z.2)-kernel (H' z.1) (H' z.2))*(b z.1*b z.2) by ring,abs_mul,abs_mul] + exact mul_le_mul_of_nonneg_right (hk z.1 z.2) (mul_nonneg (abs_nonneg _) (abs_nonneg _))) + rw [integral_const_mul,integral_prod_mul (fun x => |b x|) (fun x => |b x|)] at hi + apply hi.trans + have hn : 0 ≤ ∫ x, |b x| ∂μ := integral_nonneg (fun x => abs_nonneg (b x)) + have hh := (integral_abs_le_l2 hb).trans hb1 + nlinarith only [mul_nonneg ha (sub_nonneg.mpr hh), + mul_nonneg (mul_nonneg ha hn) (sub_nonneg.mpr hh)] + +omit [IsProbabilityMeasure μ] in +lemma field_pair_difference {b f g : ℝ → ℝ} (hb : MemLp b 2 μ) + (hb1 : l2Norm μ b ≤ 1) (hf : MemLp f 2 μ) (hg : MemLp g 2 μ) : + |(∫ x, b x*f x ∂μ)-(∫ x, b x*g x ∂μ)| ≤ l2Norm μ (fun x => f x-g x) := by + have hfi : Integrable (fun x => b x*f x) μ := hb.integrable_mul hf + have hgi : Integrable (fun x => b x*g x) μ := hb.integrable_mul hg + rw [←integral_sub hfi hgi] + simp_rw [←mul_sub] + exact field_pair_abs_le hb (hf.sub hg) hb1 + +lemma field_pair_v_abs {b H : ℝ → ℝ} (hb : MemLp b 2 μ) (hb1 : l2Norm μ b ≤ 1) + (hH : Measurable H) : |∫ x, b x*v (H x) ∂μ| ≤ 1 := + (field_pair_abs_le hb (memLp_bounded (continuous_v.measurable.comp hH) + (fun x => v_abs_le_one (H x))) hb1).trans + (l2Norm_le_bounded (continuous_v.measurable.comp hH) (by norm_num) (fun x => v_abs_le_one (H x))) + +lemma mean_abs_le_one {b : ℝ → ℝ} (hb : MemLp b 2 μ) (hb1 : l2Norm μ b ≤ 1) : + |∫ x, b x ∂μ| ≤ 1 := (abs_integral_le_integral_abs.trans (integral_abs_le_l2 hb)).trans hb1 + +omit [IsProbabilityMeasure μ] in +lemma memLp_Hv {H : ℝ → ℝ} (hH : Measurable H) (hH2 : MemLp H 2 μ) : + MemLp (fun x => H x*v (H x)) 2 μ := + memLp_field_mul hH2 (continuous_v.measurable.comp hH) (fun point => v_abs_le_one (H point)) + +omit [IsProbabilityMeasure μ] in +lemma Hv_error {H H' : ℝ → ℝ} (hH : Measurable H) (hH' : Measurable H') + (hH2 : MemLp H 2 μ) (hH2' : MemLp H' 2 μ) + {a d T : ℝ} (ha : 0 ≤ a) (he : l2Norm μ (fun x => H x-H' x) ≤ d) + (hsize : l2Norm μ H' ≤ T) (hv : ∀ x, |v (H x)-v (H' x)| ≤ a) : + l2Norm μ (fun x => H x*v (H x)-H' x*v (H' x)) ≤ d+T*a := by + have heq : (fun x => H x*v (H x)-H' x*v (H' x))= + (fun x => (H x-H' x)*v (H x)+H' x*(v (H x)-v (H' x))) := by funext x; ring + rw [heq] + have h1 := l2Norm_field_mul (hH2.sub hH2') (continuous_v.measurable.comp hH) + (by norm_num : (0:ℝ) ≤ 1) (fun x => v_abs_le_one _) + have h2 := l2Norm_field_mul hH2' + ((continuous_v.measurable.comp hH).sub (continuous_v.measurable.comp hH')) ha hv + have ht := l2Norm_add (memLp_field_mul (hH2.sub hH2') + (continuous_v.measurable.comp hH) (fun x => v_abs_le_one _)) + (memLp_field_mul hH2' ((continuous_v.measurable.comp hH).sub (continuous_v.measurable.comp hH')) hv) + have h3 := mul_le_mul_of_nonneg_left hsize ha + simp only [Pi.sub_apply,Pi.sub_def,Function.comp_apply] at h1 h2 ht + nlinarith only [h1,h2,ht,h3,he] + +lemma field_radical_pair_error {b r H H' : ℝ → ℝ} (hb : MemLp b 2 μ) (hr : MemLp r 2 μ) + (hbm : Measurable b) (hrm : Measurable r) (hH : Measurable H) (hH' : Measurable H') + (he : (∫ x, b x^2+r x^2 ∂μ)=1) {a : ℝ} (ha : 0 ≤ a) + (hv : ∀ x, |v (H x)-v (H' x)| ≤ a) : + |(∫ x, r x*sqrt (fieldRadicand μ H b r x) ∂μ)- + (∫ x, r x*sqrt (fieldRadicand μ H' b r x) ∂μ)| ≤ 4*sqrt a := by + apply bounded_pair_error hr (norm_components hb hr he).2 + ((measurable_fieldRadicand hbm hrm hH).sqrt) ((measurable_fieldRadicand hbm hrm hH').sqrt) + (C := 2) (D := 2) _ _ (by positivity) (sqrt_fieldRadicand_error hb hr hH hH' he ha hv) + · intro x + rw [abs_of_nonneg (sqrt_nonneg _)] + exact (sqrt_le_iff).mpr ⟨by norm_num,by norm_num only [show (2:ℝ)^2=4 by norm_num]; exact fieldRadicand_le hb hr hH he x⟩ + · intro x + rw [abs_of_nonneg (sqrt_nonneg _)] + exact (sqrt_le_iff).mpr ⟨by norm_num,by norm_num only [show (2:ℝ)^2=4 by norm_num]; exact fieldRadicand_le hb hr hH' he x⟩ + +theorem fieldForm_error {b r H H' : ℝ → ℝ} (β : ℝ) (hβ : 0 ≤ β) + (hb : MemLp b 2 μ) (hr : MemLp r 2 μ) (hbm : Measurable b) (hrm : Measurable r) + (hH : Measurable H) (hH' : Measurable H') (hH2 : MemLp H 2 μ) (hH2' : MemLp H' 2 μ) + (he : (∫ x, b x^2+r x^2 ∂μ)=1) {a d T : ℝ} (ha : 0 ≤ a) (hT : 0 ≤ T) + (herr : l2Norm μ (fun x => H x-H' x) ≤ d) (hsize : l2Norm μ H' ≤ T) + (hv : ∀ x, |v (H x)-v (H' x)| ≤ a) + (hmv : ∀ x, |m (H x)*v (H x)-m (H' x)*v (H' x)| ≤ a) + (hf : ∀ x y, |v (H y)^2/(w (H x)+w (H y))- + v (H' y)^2/(w (H' x)+w (H' y))| ≤ a) + (hk : ∀ x y, |kernel (H x) (H y)-kernel (H' x) (H' y)| ≤ a) : + |fieldForm μ β H b r-fieldForm μ β H' b r| ≤ + 2*d+2*T*a+5*β^2*a+4*β*sqrt a := by + have hb1 := (norm_components hb hr he).1 + have hV := bounded_pair_error hb hb1 (continuous_v.measurable.comp hH) + (continuous_v.measurable.comp hH') (fun x => v_abs_le_one _) (fun x => v_abs_le_one _) ha hv + have hmabs (x : ℝ) : |m x*v x| ≤ 1 := by + have hm : |m x| ≤ 1 := abs_le.mpr ⟨(m_bounds x).1.le,(m_bounds x).2.le⟩ + rw [abs_mul] + simpa only [mul_one] using mul_le_mul hm (v_abs_le_one x) (abs_nonneg _) (by norm_num : (0:ℝ) ≤ 1) + have hMV := bounded_pair_error hb hb1 + ((continuous_m.mul continuous_v).measurable.comp hH) + ((continuous_m.mul continuous_v).measurable.comp hH') + (fun x => hmabs _) (fun x => hmabs _) ha hmv + have hHv := (field_pair_difference hb hb1 (memLp_Hv hH hH2) + (memLp_Hv hH' hH2')).trans (Hv_error hH hH' hH2 hH2' ha herr hsize hv) + have h₁ := product_error (by norm_num : (0:ℝ) ≤ 1) hT (field_pair_v_abs hb hb1 hH) + ((field_pair_abs_le hb hH2' hb1).trans hsize) + ((field_pair_difference hb hb1 hH2 hH2').trans herr) hV + have h₂ : |(∫ x, b x ∂μ)*(∫ x, b x*(H x*v (H x)) ∂μ)- + (∫ x, b x ∂μ)*(∫ x, b x*(H' x*v (H' x)) ∂μ)| ≤ d+T*a := by + rw [←mul_sub,abs_mul] + exact (mul_le_mul (mean_abs_le_one hb hb1) hHv (abs_nonneg _) (by norm_num : (0:ℝ) ≤ 1)).trans_eq (one_mul _) + have h₃ : |β^2*(∫ x, b x ∂μ)*((∫ x, b x*v (H x) ∂μ)- + (∫ x, b x*v (H' x) ∂μ))| ≤ β^2*a := by + rw [abs_mul,abs_mul,abs_of_nonneg (sq_nonneg β)] + exact mul_le_mul ((mul_le_mul_of_nonneg_left (mean_abs_le_one hb hb1) (sq_nonneg β)).trans_eq (mul_one _)) + hV (abs_nonneg _) (sq_nonneg β) + have h₄ : |2*β^2*(∫ x, b x ∂μ)*((∫ x, b x*(m (H x)*v (H x)) ∂μ)- + (∫ x, b x*(m (H' x)*v (H' x)) ∂μ))| ≤ 2*β^2*a := by + rw [abs_mul,abs_mul,abs_of_nonneg (by positivity : 0 ≤ 2*β^2)] + exact mul_le_mul ((mul_le_mul_of_nonneg_left (mean_abs_le_one hb hb1) (by positivity : 0 ≤ 2*β^2)).trans_eq (mul_one _)) + hMV (abs_nonneg _) (by positivity) + have hd := energy_error hb hr he (measurable_fieldDiagonal (μ := μ) hH) (measurable_fieldDiagonal (μ := μ) hH') + (abs_fieldDiagonal_le hH) (abs_fieldDiagonal_le hH') (fieldDiagonal_error hH hH' hf) + have h₅ : |(∫ x, (β^2*fieldDiagonal μ H x)*(b x^2+r x^2) ∂μ)- + (∫ x, (β^2*fieldDiagonal μ H' x)*(b x^2+r x^2) ∂μ)| ≤ β^2*a := by + simp_rw [mul_assoc,integral_const_mul] + rw [←mul_sub,abs_mul,abs_of_nonneg (sq_nonneg β)] + exact mul_le_mul_of_nonneg_left hd (sq_nonneg β) + have h₆ : |β^2*((∫ z : ℝ×ℝ, b z.1*kernel (H z.1) (H z.2)*b z.2 ∂μ.prod μ)- + (∫ z : ℝ×ℝ, b z.1*kernel (H' z.1) (H' z.2)*b z.2 ∂μ.prod μ))| ≤ β^2*a := by + rw [abs_mul,abs_of_nonneg (sq_nonneg β)] + exact mul_le_mul_of_nonneg_left (fieldKernel_error hH hH' hb hb1 ha hk) (sq_nonneg β) + have h₇ : |β*((∫ x, r x*sqrt (fieldRadicand μ H b r x) ∂μ)- + (∫ x, r x*sqrt (fieldRadicand μ H' b r x) ∂μ))| ≤ 4*β*sqrt a := by + rw [abs_mul,abs_of_nonneg hβ] + have hh := mul_le_mul_of_nonneg_left (field_radical_pair_error hb hr hbm hrm hH hH' he ha hv) hβ + nlinarith only [hh] + unfold fieldForm + simp only [Function.comp_apply] at h₁ + have bounds₁ := abs_le.mp h₁ + have bounds₂ := abs_le.mp h₂ + have bounds₃ := abs_le.mp h₃ + have bounds₄ := abs_le.mp h₄ + have bounds₅ := abs_le.mp h₅ + have bounds₆ := abs_le.mp h₆ + have bounds₇ := abs_le.mp h₇ + exact abs_le.mpr ⟨by nlinarith only [bounds₁.1,bounds₂.1,bounds₃.2,bounds₄.1,bounds₅.1,bounds₆.1,bounds₇.1], + by nlinarith only [bounds₁.2,bounds₂.2,bounds₃.1,bounds₄.2,bounds₅.2,bounds₆.2,bounds₇.2]⟩ + +end SKRatio.Bins + +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Variational/FieldL2.lean b/lean/OAI/Probability/SKRatio/Variational/FieldL2.lean new file mode 100644 index 0000000000000000000000000000000000000000..67951fe55e9da487442be7a683f67d75d3b3125a --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Variational/FieldL2.lean @@ -0,0 +1,129 @@ +import Mathlib +import OAI.Probability.SKRatio.Variational.ScalarHilbert + +namespace OAI + +noncomputable section +open scoped NNReal ENNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Real +namespace SKRatio.Bins +open Planted Scalar + +variable {μ : Measure ℝ} [IsProbabilityMeasure μ] + +lemma memLp_bounded {f : ℝ → ℝ} (hf : Measurable f) {C : ℝ} + (hC : ∀ x, |f x| ≤ C) : MemLp f 2 μ := + MemLp.of_bound hf.aestronglyMeasurable C (ae_of_all _ (fun x => by + simpa only [norm_eq_abs] using hC x)) + +lemma l2Norm_le_bounded {f : ℝ → ℝ} (hf : Measurable f) {C : ℝ} + (hC : 0 ≤ C) (hfC : ∀ x, |f x| ≤ C) : l2Norm μ f ≤ C := by + have hi := integral_mono (memLp_bounded hf hfC (μ := μ)).integrable_sq + (integrable_const (C^2)) (fun x => show f x^2 ≤ C^2 by + simpa only [sq_abs] using (sq_le_sq₀ (abs_nonneg _) hC).mpr (hfC x)) + simp only [integral_const,probReal_univ,smul_eq_mul,one_mul] at hi + have hs := l2Norm_sq (μ := μ) f + nlinarith only [hi,hs,l2Norm_nonneg (μ := μ) f,hC] + +omit [IsProbabilityMeasure μ] in +lemma memLp_field_mul {f u : ℝ → ℝ} (hf : MemLp f 2 μ) + (hu : Measurable u) {C : ℝ} (hC : ∀ x, |u x| ≤ C) : + MemLp (fun x => f x*u x) 2 μ := by + apply hf.of_le_mul (hf.aestronglyMeasurable.mul hu.aestronglyMeasurable) (c := C) + exact ae_of_all _ (fun x => by + change |f x*u x| ≤ C*|f x| + rw [abs_mul] + nlinarith only [mul_le_mul_of_nonneg_left (hC x) (abs_nonneg (f x))]) + +omit [IsProbabilityMeasure μ] in +lemma l2Norm_field_mul {f u : ℝ → ℝ} (hf : MemLp f 2 μ) + (hu : Measurable u) {C : ℝ} (hC : 0 ≤ C) (huC : ∀ x, |u x| ≤ C) : + l2Norm μ (fun x => f x*u x) ≤ C*l2Norm μ f := by + have hi := integral_mono (memLp_field_mul hf hu huC).integrable_sq + (hf.integrable_sq.const_mul (C^2)) (fun x => show (f x*u x)^2 ≤ C^2*f x^2 by + have hh : u x^2 ≤ C^2 := by + simpa only [sq_abs] using (sq_le_sq₀ (abs_nonneg _) hC).mpr (huC x) + simpa only [mul_pow,mul_comm] using mul_le_mul_of_nonneg_left hh (sq_nonneg (f x))) + rw [integral_const_mul,←l2Norm_sq,←l2Norm_sq] at hi + have hn := l2Norm_nonneg (μ := μ) (fun x => f x*u x) + have hn' : 0 ≤ C*l2Norm μ f := mul_nonneg hC (l2Norm_nonneg f) + nlinarith only [hi,hn,hn'] + +omit [IsProbabilityMeasure μ] in +lemma norm_components {b r : ℝ → ℝ} (hb : MemLp b 2 μ) (hr : MemLp r 2 μ) + (he : (∫ x, b x^2+r x^2 ∂μ)=1) : l2Norm μ b ≤ 1 ∧ l2Norm μ r ≤ 1 := by + rw [integral_add hb.integrable_sq hr.integrable_sq,←l2Norm_sq,←l2Norm_sq] at he + constructor <;> nlinarith only [he,sq_nonneg (l2Norm μ b),sq_nonneg (l2Norm μ r)] + +lemma integral_abs_le_l2 {f : ℝ → ℝ} (hf : MemLp f 2 μ) : + (∫ x, |f x| ∂μ) ≤ l2Norm μ f := by + have hh : |∫ x, |f x| * (1:ℝ) ∂μ| ≤ l2Norm μ (fun x => |f x|)*l2Norm μ (fun _ => (1:ℝ)) := + abs_integral_mul_le hf.abs (memLp_const (1:ℝ) (μ := μ) (p := 2)) + have he : l2Norm μ (fun x => |f x|)=l2Norm μ f := by simp only [l2Norm,sq_abs] + have ho : l2Norm μ (fun _ : ℝ => (1:ℝ))=1 := by + simp only [l2Norm,one_pow,integral_const,probReal_univ,smul_eq_mul,one_mul,sqrt_one] + simp only [mul_one,he,ho] at hh + rw [abs_of_nonneg (integral_nonneg (fun x : ℝ => abs_nonneg (f x)))] at hh + exact hh + +omit [IsProbabilityMeasure μ] in +lemma field_pair_abs_le {b f : ℝ → ℝ} (hb : MemLp b 2 μ) (hf : MemLp f 2 μ) + (hb1 : l2Norm μ b ≤ 1) : |∫ x, b x*f x ∂μ| ≤ l2Norm μ f := + (abs_integral_mul_le hb hf).trans (by + simpa only [one_mul] using mul_le_mul_of_nonneg_right hb1 (l2Norm_nonneg f)) + +lemma integral_abs_bound {f : ℝ → ℝ} (hf : Integrable f μ) {C : ℝ} + (hC : ∀ x, |f x| ≤ C) : |∫ x, f x ∂μ| ≤ C := by + apply abs_integral_le_integral_abs.trans + simpa only [integral_const,probReal_univ,smul_eq_mul,one_mul] using + integral_mono hf.abs (integrable_const C) hC + +lemma bounded_pair_error {b f g : ℝ → ℝ} (hb : MemLp b 2 μ) + (hb1 : l2Norm μ b ≤ 1) (hf : Measurable f) (hg : Measurable g) + {C D a : ℝ} (hfC : ∀ x, |f x| ≤ C) (hgD : ∀ x, |g x| ≤ D) + (ha : 0 ≤ a) (he : ∀ x, |f x-g x| ≤ a) : + |(∫ x, b x*f x ∂μ)-(∫ x, b x*g x ∂μ)| ≤ a := by + have hfi : Integrable (fun x => b x*f x) μ := hb.integrable_mul (memLp_bounded hf hfC) + have hgi : Integrable (fun x => b x*g x) μ := hb.integrable_mul (memLp_bounded hg hgD) + rw [←integral_sub hfi hgi] + simp_rw [←mul_sub] + exact (field_pair_abs_le hb ((memLp_bounded hf hfC).sub (memLp_bounded hg hgD)) hb1).trans + (l2Norm_le_bounded (hf.sub hg) ha he) + +omit [IsProbabilityMeasure μ] in +lemma energy_error {b r f g : ℝ → ℝ} (hb : MemLp b 2 μ) (hr : MemLp r 2 μ) + (he : (∫ x, b x^2+r x^2 ∂μ)=1) + (hf : Measurable f) (hg : Measurable g) {C D a : ℝ} + (hfC : ∀ x, |f x| ≤ C) (hgD : ∀ x, |g x| ≤ D) (hfg : ∀ x, |f x-g x| ≤ a) : + |(∫ x, f x*(b x^2+r x^2) ∂μ)-(∫ x, g x*(b x^2+r x^2) ∂μ)| ≤ a := by + have ih : Integrable (fun x => b x^2+r x^2) μ := hb.integrable_sq.add hr.integrable_sq + have ihf := ih.bdd_mul hf.aestronglyMeasurable (ae_of_all _ (fun x => by simpa only [norm_eq_abs] using hfC x)) + have ihg := ih.bdd_mul hg.aestronglyMeasurable (ae_of_all _ (fun x => by simpa only [norm_eq_abs] using hgD x)) + rw [←integral_sub ihf ihg] + apply abs_integral_le_integral_abs.trans + have hi := integral_mono (ihf.sub ihg).abs (ih.const_mul a) (fun x => by + simp only [Pi.sub_apply,←sub_mul,abs_mul,abs_of_nonneg (add_nonneg (sq_nonneg (b x)) (sq_nonneg (r x)))] + exact mul_le_mul_of_nonneg_right (hfg x) (add_nonneg (sq_nonneg _) (sq_nonneg _))) + simpa only [integral_const_mul,Pi.add_apply,Pi.sub_apply,he,mul_one] using hi + +lemma sqrt_difference {s t e : ℝ} (hs : 0 ≤ s) (ht : 0 ≤ t) + (he : |s-t| ≤ e) : |sqrt s-sqrt t| ≤ sqrt e := by + have he0 := (abs_nonneg (s-t)).trans he + have hs2 := sq_sqrt hs + have ht2 := sq_sqrt ht + have he2 := sq_sqrt he0 + have habs : (sqrt s-sqrt t)^2 ≤ e := by + rcases le_total s t with hst|hts + · rw [abs_of_nonpos (sub_nonpos.mpr hst)] at he + have hh := sqrt_le_sqrt hst + nlinarith only [he,hh,hs2,ht2,mul_nonneg (sqrt_nonneg s) (sub_nonneg.mpr hh)] + · rw [abs_of_nonneg (sub_nonneg.mpr hts)] at he + have hh := sqrt_le_sqrt hts + nlinarith only [he,hh,hs2,ht2,mul_nonneg (sqrt_nonneg t) (sub_nonneg.mpr hh)] + exact (sq_le_sq₀ (abs_nonneg _) (sqrt_nonneg e)).mp (by simpa only [sq_abs,he2] using habs) + +end SKRatio.Bins + +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Variational/FieldRadical.lean b/lean/OAI/Probability/SKRatio/Variational/FieldRadical.lean new file mode 100644 index 0000000000000000000000000000000000000000..f787b191bce85246a4552af20d04703a6dd003e1 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Variational/FieldRadical.lean @@ -0,0 +1,136 @@ +import Mathlib +import OAI.Probability.SKRatio.Variational.FieldL2 + +namespace OAI + +noncomputable section +open scoped NNReal ENNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Real +namespace SKRatio.Bins +open Planted Scalar + +variable {μ : Measure ℝ} [IsProbabilityMeasure μ] + +def fieldRadicand (μ : Measure ℝ) (H b r : ℝ → ℝ) (x : ℝ) : ℝ := + (∫ y, ((v (H x)+v (H y))*r y)^2 ∂μ)+ + (∫ y, ((v (H x)+v (H y))*b y-(∫ t, (v (H x)+v (H t))*b t ∂μ))^2 ∂μ) + +omit [IsProbabilityMeasure μ] in +lemma fieldRadicand_nonneg (H b r : ℝ → ℝ) (x : ℝ) : + 0 ≤ fieldRadicand μ H b r x := + add_nonneg (integral_nonneg (fun _ => sq_nonneg _)) + (integral_nonneg (fun _ => sq_nonneg _)) + +omit [IsProbabilityMeasure μ] in +lemma memLp_sum_v_field {b H : ℝ → ℝ} (hb : MemLp b 2 μ) (hH : Measurable H) + (x : ℝ) : MemLp (fun y => (v (H x)+v (H y))*b y) 2 μ := by + have hh := memLp_field_mul hb (u := fun y => v (H x)+v (H y)) + (measurable_const.add (continuous_v.measurable.comp hH)) (fun y => abs_v_sum_le (H x) (H y)) + simpa only [mul_comm] using hh + +omit [IsProbabilityMeasure μ] in +lemma field_energy_integrable {b r H : ℝ → ℝ} (hb : MemLp b 2 μ) (hr : MemLp r 2 μ) + (hH : Measurable H) (x : ℝ) : + Integrable (fun y => (v (H x)+v (H y))^2*(b y^2+r y^2)) μ := by + have he (y : ℝ) : (v (H x)+v (H y))^2*(b y^2+r y^2)= + ((v (H x)+v (H y))*b y)^2+((v (H x)+v (H y))*r y)^2 := by ring + simp_rw [he] + exact (memLp_sum_v_field hb hH x).integrable_sq.add (memLp_sum_v_field hr hH x).integrable_sq + +lemma fieldRadicand_expansion {b r H : ℝ → ℝ} (hb : MemLp b 2 μ) (hr : MemLp r 2 μ) + (hH : Measurable H) (x : ℝ) : fieldRadicand μ H b r x = + (∫ y, (v (H x)+v (H y))^2*(b y^2+r y^2) ∂μ)- + (∫ y, (v (H x)+v (H y))*b y ∂μ)^2 := by + rw [fieldRadicand,integral_centered_sq (memLp_sum_v_field hb hH x)] + have he (y : ℝ) : (v (H x)+v (H y))^2*(b y^2+r y^2)= + ((v (H x)+v (H y))*b y)^2+((v (H x)+v (H y))*r y)^2 := by ring + simp_rw [he] + rw [integral_add (memLp_sum_v_field hb hH x).integrable_sq + (memLp_sum_v_field hr hH x).integrable_sq] + ring + +lemma fieldRadicand_le {b r H : ℝ → ℝ} (hb : MemLp b 2 μ) (hr : MemLp r 2 μ) + (hH : Measurable H) (he : (∫ x, b x^2+r x^2 ∂μ)=1) (x : ℝ) : + fieldRadicand μ H b r x ≤ 4 := by + rw [fieldRadicand_expansion hb hr hH] + have ih : Integrable (fun y => b y^2+r y^2) μ := hb.integrable_sq.add hr.integrable_sq + have hi := integral_mono (field_energy_integrable hb hr hH x) (ih.const_mul (4:ℝ)) + (fun y => mul_le_mul_of_nonneg_right (v_sum_sq_le (H x) (H y)) + (add_nonneg (sq_nonneg _) (sq_nonneg _))) + rw [integral_const_mul,he,mul_one] at hi + nlinarith only [hi,sq_nonneg (∫ y, (v (H x)+v (H y))*b y ∂μ)] + +lemma measurable_fieldRadicand {b r H : ℝ → ℝ} (hb : Measurable b) (hr : Measurable r) + (hH : Measurable H) : Measurable (fieldRadicand μ H b r) := by + have hv := continuous_v.measurable.comp hH + have hm : Measurable (fun x => ∫ t, (v (H x)+v (H t))*b t ∂μ) := + (((hv.comp measurable_fst).add (hv.comp measurable_snd)).mul + (hb.comp measurable_snd)).stronglyMeasurable.integral_prod_right.measurable + have h1 : Measurable (fun x => ∫ y, ((v (H x)+v (H y))*r y)^2 ∂μ) := + ((((hv.comp measurable_fst).add (hv.comp measurable_snd)).mul + (hr.comp measurable_snd)).pow_const 2).stronglyMeasurable.integral_prod_right.measurable + have h2 : Measurable (fun x => ∫ y, + ((v (H x)+v (H y))*b y-(∫ t, (v (H x)+v (H t))*b t ∂μ))^2 ∂μ) := + (((((hv.comp measurable_fst).add (hv.comp measurable_snd)).mul + (hb.comp measurable_snd)).sub (hm.comp measurable_fst)).pow_const 2).stronglyMeasurable.integral_prod_right.measurable + exact h1.add h2 + +lemma abs_square_sub_le {x y C e : ℝ} (hC : 0 ≤ C) (hx : |x| ≤ C) (hy : |y| ≤ C) + (he : |x-y| ≤ e) : |x^2-y^2| ≤ 2*C*e := by + rw [show x^2-y^2=(x-y)*(x+y) by ring,abs_mul] + have hsum : |x+y| ≤ 2*C := (abs_add_le _ _).trans (by linarith) + nlinarith only [mul_le_mul hsum he (abs_nonneg _) (mul_nonneg (by norm_num) hC)] + +lemma fieldRadicand_error {b r H H' : ℝ → ℝ} (hb : MemLp b 2 μ) (hr : MemLp r 2 μ) + (hH : Measurable H) (hH' : Measurable H') + (he : (∫ x, b x^2+r x^2 ∂μ)=1) {a : ℝ} (ha : 0 ≤ a) + (hv : ∀ x, |v (H x)-v (H' x)| ≤ a) (x : ℝ) : + |fieldRadicand μ H b r x-fieldRadicand μ H' b r x| ≤ 16*a := by + let f := fun y => v (H x)+v (H y) + let g := fun y => v (H' x)+v (H' y) + have hf : Measurable f := measurable_const.add (continuous_v.measurable.comp hH) + have hg : Measurable g := measurable_const.add (continuous_v.measurable.comp hH') + have hf2 (y : ℝ) : |f y| ≤ 2 := abs_v_sum_le _ _ + have hg2 (y : ℝ) : |g y| ≤ 2 := abs_v_sum_le _ _ + have hfg (y : ℝ) : |f y-g y| ≤ 2*a := by + have heq : f y-g y=(v (H x)-v (H' x))+(v (H y)-v (H' y)) := by dsimp [f,g]; ring + rw [heq] + exact (abs_add_le _ _).trans (by linarith [hv x,hv y]) + have hf_sq (y : ℝ) : |f y^2| ≤ 4 := by rw [abs_of_nonneg (sq_nonneg _)]; exact v_sum_sq_le _ _ + have hg_sq (y : ℝ) : |g y^2| ≤ 4 := by rw [abs_of_nonneg (sq_nonneg _)]; exact v_sum_sq_le _ _ + have he_sq (y : ℝ) : |f y^2-g y^2| ≤ 8*a := by + have hh := abs_square_sub_le (by norm_num : (0:ℝ) ≤ 2) (hf2 y) (hg2 y) (hfg y) + nlinarith only [hh] + have he' := energy_error hb hr he (hf.pow_const 2) (hg.pow_const 2) hf_sq hg_sq he_sq + have hb1 := (norm_components hb hr he).1 + have hp := bounded_pair_error hb hb1 hf hg hf2 hg2 (show 0 ≤ 2*a by positivity) hfg + have hpf : |∫ y, b y*f y ∂μ| ≤ 2 := (field_pair_abs_le hb (memLp_bounded hf hf2) hb1).trans + (l2Norm_le_bounded hf (by norm_num) hf2) + have hpg : |∫ y, b y*g y ∂μ| ≤ 2 := (field_pair_abs_le hb (memLp_bounded hg hg2) hb1).trans + (l2Norm_le_bounded hg (by norm_num) hg2) + have hps := abs_square_sub_le (by norm_num : (0:ℝ) ≤ 2) hpf hpg hp + rw [fieldRadicand_expansion hb hr hH,fieldRadicand_expansion hb hr hH'] + change |(∫ y, f y^2*(b y^2+r y^2) ∂μ)-(∫ y, f y*b y ∂μ)^2- + ((∫ y, g y^2*(b y^2+r y^2) ∂μ)-(∫ y, g y*b y ∂μ)^2)| ≤ _ + simp_rw [mul_comm (f _) (b _),mul_comm (g _) (b _)] + have heq : (∫ y, f y^2*(b y^2+r y^2) ∂μ)-(∫ y, b y*f y ∂μ)^2- + ((∫ y, g y^2*(b y^2+r y^2) ∂μ)-(∫ y, b y*g y ∂μ)^2)= + ((∫ y, f y^2*(b y^2+r y^2) ∂μ)-(∫ y, g y^2*(b y^2+r y^2) ∂μ))- + ((∫ y, b y*f y ∂μ)^2-(∫ y, b y*g y ∂μ)^2) := by ring + rw [heq] + exact (abs_sub _ _).trans (by linarith only [he',hps]) + +lemma sqrt_fieldRadicand_error {b r H H' : ℝ → ℝ} (hb : MemLp b 2 μ) (hr : MemLp r 2 μ) + (hH : Measurable H) (hH' : Measurable H') + (he : (∫ x, b x^2+r x^2 ∂μ)=1) {a : ℝ} (ha : 0 ≤ a) + (hv : ∀ x, |v (H x)-v (H' x)| ≤ a) (x : ℝ) : + |sqrt (fieldRadicand μ H b r x)-sqrt (fieldRadicand μ H' b r x)| ≤ 4*sqrt a := by + have hh := sqrt_difference (fieldRadicand_nonneg H b r x) (fieldRadicand_nonneg H' b r x) + (fieldRadicand_error hb hr hH hH' he ha hv x) + simpa only [sqrt_mul (by norm_num : (0:ℝ) ≤ 16),show sqrt (16:ℝ)=4 by norm_num] using hh + +end SKRatio.Bins + +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Variational/FormAlgebra.lean b/lean/OAI/Probability/SKRatio/Variational/FormAlgebra.lean new file mode 100644 index 0000000000000000000000000000000000000000..eac32cca373f392ac37953a17fb6dc5042f50605 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Variational/FormAlgebra.lean @@ -0,0 +1,162 @@ +import Mathlib +import OAI.Probability.SKRatio.Calculus.RowControl +import OAI.Probability.SKRatio.Variational.CompactField + +namespace OAI + +section +noncomputable section +open scoped BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Set Real +namespace SKRatio.Planted +open Scalar Calculus +attribute [local instance] Classical.propDecidable +variable {n : ℕ} + +def quadratic (A : Matrix (Fin n) (Fin n) ℝ) (p : Fin n → ℝ) : ℝ := + ∑ i, ∑ j, A i j*p i*p j + +def weightedForm (A : Matrix (Fin n) (Fin n) ℝ) (G : FieldWeight × FieldWeight → ℝ) + (x : Fin n → FieldWeight) (p : Fin n → ℝ) : ℝ := + quadratic (fun i j => A i j*G (x i,x j)) p + +def diagonalForm (A : Matrix (Fin n) (Fin n) ℝ) (G : FieldWeight × FieldWeight → ℝ) + (x : Fin n → FieldWeight) (p : Fin n → ℝ) : ℝ := + ∑ i, (∑ j, A i j*G (x i,x j))*p i^2 + +def varianceKernel (p : FieldWeight × FieldWeight) : ℝ := compactV p.2 +def meanVarianceKernel (p : FieldWeight × FieldWeight) : ℝ := + (1-(p.2:ℝ))*compactV p.2 + +lemma continuous_varianceKernel : Continuous varianceKernel := + continuous_compactV.comp continuous_snd +lemma continuous_meanVarianceKernel : Continuous meanVarianceKernel := by + unfold meanVarianceKernel + exact (continuous_const.sub (continuous_subtype_val.comp continuous_snd)).mul + (continuous_compactV.comp continuous_snd) + +def compactForm (J : Interaction n) (x : Fin n → FieldWeight) (p : Fin n → ℝ) : ℝ := + weightedForm J varianceKernel x p + + 2*weightedForm (fun i j => J i j^2) meanVarianceKernel x p + + diagonalForm (fun i j => J i j^2) compactF x p + + weightedForm (fun i j => J i j^2) compactK x p + +lemma quadratic_add (A B : Matrix (Fin n) (Fin n) ℝ) (p : Fin n → ℝ) : + quadratic (A+B) p = quadratic A p+quadratic B p := by + simp only [quadratic,Matrix.add_apply,add_mul,Finset.sum_add_distrib] +lemma quadratic_sub (A B : Matrix (Fin n) (Fin n) ℝ) (p : Fin n → ℝ) : + quadratic (A-B) p = quadratic A p-quadratic B p := by + simp only [quadratic,Matrix.sub_apply,sub_mul,Finset.sum_sub_distrib] +lemma quadratic_const_mul (a : ℝ) (A : Matrix (Fin n) (Fin n) ℝ) (p : Fin n → ℝ) : + quadratic (a • A) p = a*quadratic A p := by + simp only [quadratic,Matrix.smul_apply,smul_eq_mul,mul_assoc,←Finset.mul_sum] + +lemma quadratic_inner (A : Matrix (Fin n) (Fin n) ℝ) (p : Fin n → ℝ) : + quadratic A p = inner ℝ (WithLp.toLp 2 p) + (Matrix.toEuclideanCLM (𝕜 := ℝ) (n := Fin n) A (WithLp.toLp 2 p)) := by + rw [Matrix.inner_toEuclideanCLM] + simp only [quadratic,dotProduct,Matrix.mulVec,Finset.mul_sum] + congr 1 + ext i + apply Finset.sum_congr rfl + intro j _ + ring + +lemma quadratic_abs_le (A : Matrix (Fin n) (Fin n) ℝ) (p : Fin n → ℝ) : + |quadratic A p| ≤ euclideanOpNorm A*(∑ i, p i^2) := by + rw [quadratic_inner] + let P : EuclideanSpace ℝ (Fin n) := WithLp.toLp 2 p + have hb := (abs_real_inner_le_norm P (Matrix.toEuclideanCLM (𝕜 := ℝ) A P)).trans + (mul_le_mul_of_nonneg_left ((Matrix.toEuclideanCLM (𝕜 := ℝ) A).le_opNorm P) (norm_nonneg P)) + calc + _ ≤ ‖P‖*(‖Matrix.toEuclideanCLM (𝕜 := ℝ) A‖*‖P‖) := hb + _ = euclideanOpNorm A*(∑ i, p i^2) := by + rw [show ‖P‖*(‖Matrix.toEuclideanCLM (𝕜 := ℝ) A‖*‖P‖) = + euclideanOpNorm A*‖P‖^2 by unfold euclideanOpNorm; ring] + rw [EuclideanSpace.real_norm_sq_eq] + +lemma weightedForm_sub (A B : Matrix (Fin n) (Fin n) ℝ) + (G : FieldWeight × FieldWeight → ℝ) (x : Fin n → FieldWeight) (p : Fin n → ℝ) : + weightedForm A G x p-weightedForm B G x p = weightedForm (A-B) G x p := by + simp only [weightedForm,quadratic,Matrix.sub_apply,sub_mul,Finset.sum_sub_distrib] + +lemma diagonalForm_sub (A B : Matrix (Fin n) (Fin n) ℝ) + (G : FieldWeight × FieldWeight → ℝ) (x : Fin n → FieldWeight) (p : Fin n → ℝ) : + diagonalForm A G x p-diagonalForm B G x p = diagonalForm (A-B) G x p := by + simp only [diagonalForm,Matrix.sub_apply,sub_mul,Finset.sum_sub_distrib] + +lemma diagonalForm_abs_le (A : Matrix (Fin n) (Fin n) ℝ) + (G : FieldWeight × FieldWeight → ℝ) (x : Fin n → FieldWeight) (p : Fin n → ℝ) + {C : ℝ} (hC : ∀ i, |∑ j, A i j*G (x i,x j)| ≤ C) : + |diagonalForm A G x p| ≤ C*∑ i, p i^2 := by + apply (Finset.abs_sum_le_sum_abs _ _).trans + calc + _ ≤ ∑ i, C*p i^2 := Finset.sum_le_sum (fun i _ => by + rw [abs_mul,abs_of_nonneg (sq_nonneg (p i))] + exact mul_le_mul_of_nonneg_right (hC i) (sq_nonneg _)) + _ = _ := (Finset.mul_sum ..).symm + +lemma sum_offdiag_eq_full {F : Fin n → Fin n → ℝ} (hF : ∀ i, F i i=0) : + (∑ i, ∑ j ∈ Finset.univ.erase i, F i j) = ∑ i, ∑ j, F i j := by + apply Finset.sum_congr rfl + intro i _ + simpa only [hF i,add_zero] using Finset.sum_erase_add Finset.univ (F i) (Finset.mem_univ i) + +lemma gradient_pair_expansion (J : Interaction n) (hJ : ∀ i j, J i j=J j i) + (hdiag : ∀ i, J i i=0) (H p : Fin n → ℝ) : + pairSum (fun i j => J i j^2*(v (H j)*p i+v (H i)*p j)^2/(w (H i)+w (H j))) = + diagonalForm (fun i j => J i j^2) compactF (fun i => compactWeight (H i)) p + + weightedForm (fun i j => J i j^2) compactK (fun i => compactWeight (H i)) p := by + have hd : ∀ i, J i i^2*(v (H i)^2/(w (H i)+w (H i)))*p i^2=0 := by simp [hdiag] + have hk : ∀ i, J i i^2*kernel (H i) (H i)*p i*p i=0 := by simp [hdiag] + simp only [diagonalForm,weightedForm,quadratic,compactF_weight,compactK_weight,Finset.sum_mul] + rw [←sum_offdiag_eq_full hd,←sum_offdiag_eq_full hk,sum_offdiag_pairs,sum_offdiag_pairs,←pairSum_add] + unfold pairSum + apply Finset.sum_congr rfl + intro i _ + apply Finset.sum_congr rfl + intro j _ + dsimp only [] + rw [hJ j i] + dsimp [kernel] + rw [add_comm (w (H j)) (w (H i))] + ring + +theorem gradientForm_eq_compactForm (J : Interaction n) (hJ : ∀ i j, J i j=J j i) + (hdiag : ∀ i, J i i=0) (p : Fin n → ℝ) : + gradientForm J p = compactForm J (fun i => compactWeight (∑ j, J i j)) p := by + have hm (i : Fin n) : mean J (plusSpin n) i = m (∑ j, J i j) := by + simp [mean,field,plusSpin,spin,m] + have hv (i : Fin n) : conditionalVariance J (plusSpin n) i = v (∑ j, J i j) := by + simp only [conditionalVariance,hm,v] + have hw (i : Fin n) : gradientWeight J (plusSpin n) i = w (∑ j, J i j) := by + simp [gradientWeight,plusSpin,spin,hm,w] + simp only [gradientForm,hm,hv,hw,gradient_pair_expansion J hJ hdiag, + compactForm,weightedForm,quadratic,varianceKernel,meanVarianceKernel, + compactV_weight,compactWeight_coe] + have h₁ : (∑ i, ∑ j ∈ Finset.univ.erase i, J i j*p i*v (∑ k, J j k)*p j) = + ∑ i, ∑ j, J i j*v (∑ k, J j k)*p i*p j := by + rw [sum_offdiag_eq_full (by intro i; simp [hdiag])] + apply Finset.sum_congr rfl + intro i _ + apply Finset.sum_congr rfl + intro j _ + ring + have h₂ : (∑ i, ∑ j ∈ Finset.univ.erase i, J i j^2*p i*m (∑ k, J j k)*v (∑ k, J j k)*p j) = + ∑ i, ∑ j, J i j^2*((1-w (∑ k, J j k))*v (∑ k, J j k))*p i*p j := by + rw [sum_offdiag_eq_full (by intro i; simp [hdiag])] + apply Finset.sum_congr rfl + intro i _ + apply Finset.sum_congr rfl + intro j _ + simp only [w] + ring + rw [h₁,h₂] + ring + +end SKRatio.Planted + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Variational/FormContinuity.lean b/lean/OAI/Probability/SKRatio/Variational/FormContinuity.lean new file mode 100644 index 0000000000000000000000000000000000000000..f66c795d25e0f8c08d584765555d046fae224662 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Variational/FormContinuity.lean @@ -0,0 +1,164 @@ +import Mathlib +import OAI.Probability.SKRatio.Matrices.CompactMatrixMasks +import OAI.Probability.SKRatio.Variational.FormAlgebra + +namespace OAI + +noncomputable section +open scoped BigOperators Topology +open MeasureTheory ProbabilityTheory Filter Set Real +namespace SKRatio.Planted +open Scalar Calculus MatrixNet +attribute [local instance] Classical.propDecidable +variable {n : ℕ} + +lemma weightedForm_field_sub (A : Matrix (Fin n) (Fin n) ℝ) + (G : FieldWeight × FieldWeight → ℝ) (x y : Fin n → FieldWeight) (p : Fin n → ℝ) : + weightedForm A G x p-weightedForm A G y p = + quadratic (fun i j => A i j*(G (x i,x j)-G (y i,y j))) p := by + simp only [weightedForm,quadratic,mul_sub,sub_mul,Finset.sum_sub_distrib] + +lemma weightedForm_field_bound (A : Matrix (Fin n) (Fin n) ℝ) + (G : FieldWeight × FieldWeight → ℝ) (x y : Fin n → FieldWeight) (p : Fin n → ℝ) + {a C : ℝ} (ha : 0≤a) (hC : 0≤C) + (hr : ∀ i, ∑ j, |A i j| ≤ C) (hc : ∀ j, ∑ i, |A i j| ≤ C) + (he : ∀ i j, |G (x i,x j)-G (y i,y j)| ≤ a) : + |weightedForm A G x p-weightedForm A G y p| ≤ a*C*∑ i, p i^2 := by + rw [weightedForm_field_sub] + exact (quadratic_abs_le _ p).trans (mul_le_mul_of_nonneg_right + (kernel_error_norm_le A _ _ ha hC hr hc he) (Finset.sum_nonneg (fun i _ => sq_nonneg (p i)))) + +lemma diagonalForm_field_bound (A : Matrix (Fin n) (Fin n) ℝ) + (G : FieldWeight × FieldWeight → ℝ) (x y : Fin n → FieldWeight) (p : Fin n → ℝ) + {a C : ℝ} (ha : 0≤a) + (hr : ∀ i, ∑ j, |A i j| ≤ C) + (he : ∀ i j, |G (x i,x j)-G (y i,y j)| ≤ a) : + |diagonalForm A G x p-diagonalForm A G y p| ≤ a*C*∑ i, p i^2 := by + have hid : diagonalForm A G x p-diagonalForm A G y p = + ∑ i, (∑ j, A i j*(G (x i,x j)-G (y i,y j)))*p i^2 := by + simp only [diagonalForm,mul_sub,sub_mul,Finset.sum_sub_distrib] + have hb (i : Fin n) : |∑ j, A i j*(G (x i,x j)-G (y i,y j))| ≤ a*C := by + calc + _ ≤ ∑ j, |A i j*(G (x i,x j)-G (y i,y j))| := Finset.abs_sum_le_sum_abs _ _ + _ ≤ ∑ j, a*|A i j| := Finset.sum_le_sum (fun j _ => by + rw [abs_mul,mul_comm] + exact mul_le_mul_of_nonneg_right (he i j) (abs_nonneg _)) + _ = a*(∑ j, |A i j|) := (Finset.mul_sum ..).symm + _ ≤ _ := mul_le_mul_of_nonneg_left (hr i) ha + rw [hid] + calc + _ ≤ ∑ i, |(∑ j, A i j*(G (x i,x j)-G (y i,y j)))*p i^2| := Finset.abs_sum_le_sum_abs _ _ + _ ≤ ∑ i, (a*C)*p i^2 := Finset.sum_le_sum (fun i _ => by + rw [abs_mul,abs_of_nonneg (sq_nonneg (p i))] + exact mul_le_mul_of_nonneg_right (hb i) (sq_nonneg _)) + _ = _ := (Finset.mul_sum ..).symm + +lemma weightedForm_variance_eq (J : Interaction n) (x : Fin n → FieldWeight) (p : Fin n → ℝ) : + weightedForm J varianceKernel x p = quadratic ((Matrix.of J)* + Matrix.diagonal (fun i => compactV (x i))) p := by + simp only [weightedForm,quadratic,varianceKernel,Matrix.mul_diagonal,Matrix.of_apply] + +lemma weightedForm_variance_field_bound (J : Interaction n) (x y : Fin n → FieldWeight) + (p : Fin n → ℝ) {a : ℝ} (ha : 0≤a) + (he : ∀ i, |compactV (x i)-compactV (y i)| ≤ a) : + |weightedForm J varianceKernel x p-weightedForm J varianceKernel y p| ≤ + a*euclideanOpNorm J*∑ i, p i^2 := by + let D : Matrix (Fin n) (Fin n) ℝ := Matrix.diagonal (fun i => compactV (x i)-compactV (y i)) + have heq : (Matrix.of J)*Matrix.diagonal (fun i => compactV (x i)) - + (Matrix.of J)*Matrix.diagonal (fun i => compactV (y i)) = (Matrix.of J)*D := by + apply Matrix.ext + intro i j + simp only [Matrix.sub_apply,Matrix.mul_diagonal,Matrix.of_apply,D] + ring + rw [weightedForm_variance_eq,weightedForm_variance_eq,←quadratic_sub,heq] + have hnD : ‖Matrix.toEuclideanCLM (n := Fin n) (𝕜 := ℝ) D‖ ≤ a := + matrix_diagonal_opNorm_le _ a ha he + have hn : euclideanOpNorm ((Matrix.of J)*D) ≤ a*euclideanOpNorm J := by + unfold euclideanOpNorm + rw [map_mul,mul_comm a] + apply (norm_mul_le _ _).trans + exact mul_le_mul_of_nonneg_left hnD (norm_nonneg _) + exact (quadratic_abs_le _ p).trans (mul_le_mul_of_nonneg_right hn + (Finset.sum_nonneg (fun i _ => sq_nonneg (p i)))) + +lemma compactForm_field_bound (J : Interaction n) (hJ : ∀ i j, J i j=J j i) + (x y : Fin n → FieldWeight) (p : Fin n → ℝ) {a C : ℝ} (ha : 0≤a) (hC : 0≤C) + (hr : ∀ i, ∑ j, J i j^2 ≤ C) + (hv : ∀ i, |compactV (x i)-compactV (y i)| ≤ a) + (hm : ∀ i j, |meanVarianceKernel (x i,x j)-meanVarianceKernel (y i,y j)| ≤ a) + (hf : ∀ i j, |compactF (x i,x j)-compactF (y i,y j)| ≤ a) + (hk : ∀ i j, |compactK (x i,x j)-compactK (y i,y j)| ≤ a) : + |compactForm J x p-compactForm J y p| ≤ a*(euclideanOpNorm J+4*C)*(∑ i, p i^2) := by + have hr' (i : Fin n) : ∑ j, |J i j^2| ≤ C := by simpa only [abs_pow,sq_abs] using hr i + have hc' (j : Fin n) : ∑ i, |J i j^2| ≤ C := by simpa only [hJ,abs_pow,sq_abs] using hr j + let L := weightedForm J varianceKernel x p-weightedForm J varianceKernel y p + let M := weightedForm (fun i j => J i j^2) meanVarianceKernel x p-weightedForm (fun i j => J i j^2) meanVarianceKernel y p + let D := diagonalForm (fun i j => J i j^2) compactF x p-diagonalForm (fun i j => J i j^2) compactF y p + let K := weightedForm (fun i j => J i j^2) compactK x p-weightedForm (fun i j => J i j^2) compactK y p + have hid : compactForm J x p-compactForm J y p=L+2*M+D+K := by dsimp [compactForm,L,M,D,K]; ring + have hL : |L| ≤ a*euclideanOpNorm J*(∑ i, p i^2) := weightedForm_variance_field_bound J x y p ha hv + have hM : |M| ≤ a*C*(∑ i, p i^2) := weightedForm_field_bound _ _ x y p ha hC hr' hc' hm + have hD : |D| ≤ a*C*(∑ i, p i^2) := diagonalForm_field_bound _ _ x y p ha hr' hf + have hK : |K| ≤ a*C*(∑ i, p i^2) := weightedForm_field_bound _ _ x y p ha hC hr' hc' hk + rw [hid] + have ht := (abs_add_le (L+2*M+D) K).trans + (add_le_add ((abs_add_le (L+2*M) D).trans (add_le_add (abs_add_le L (2*M)) le_rfl)) le_rfl) + rw [abs_mul,abs_of_pos (by norm_num : (0:ℝ)<2)] at ht + nlinarith only [ht,hL,hM,hD,hK] + +lemma form_kernels_uniform {a : ℝ} (ha : 0 + ![varianceKernel p,meanVarianceKernel p,compactF p,compactK p] + have hG : Continuous G := by + apply continuous_pi + intro i + fin_cases i + · exact continuous_varianceKernel + · exact continuous_meanVarianceKernel + · exact continuous_compactF + · exact continuous_compactK + obtain ⟨δ,hδ,hcont⟩ := Metric.uniformContinuous_iff.mp + (CompactSpace.uniformContinuous_of_continuous hG) a ha + refine ⟨δ,hδ,?_⟩ + intro x y x' y' hx hy + have hh := (dist_pi_lt_iff ha).mp (hcont (a := (x,y)) (b := (x',y')) + (by simpa only [Prod.dist_eq,max_lt_iff] using And.intro hx hy)) + exact ⟨(hh 0).le,(hh 1).le,(hh 2).le,(hh 3).le⟩ + +lemma compactForm_uniform_field_change {C K u : ℝ} (hC : 0≤C) (hK : 0≤K) (hu : 0 compactWeight (H i)) p- + compactForm J (fun i => compactWeight (H' i)) p| ≤ u*(∑ i, p i^2) := by + let a := u/(K+4*C+1) + have ha : 0 (hcont _ _ _ _ (hd i) (hd i)).1) + (fun i j => (hcont _ _ _ _ (hd i) (hd j)).2.1) + (fun i j => (hcont _ _ _ _ (hd i) (hd j)).2.2.1) + (fun i j => (hcont _ _ _ _ (hd i) (hd j)).2.2.2) + apply hb.trans + apply mul_le_mul_of_nonneg_right _ (Finset.sum_nonneg (fun _ _ => sq_nonneg _)) + have hden : 0 squareError β g i j*G (x i,x j))} := by + let : ContinuousSMul ℝ (EuclideanSpace ℝ (Fin n)) := IsBoundedSMul.continuousSMul + let : ContinuousSMul ℝ (EuclideanSpace ℝ (Fin n) →L[ℝ] EuclideanSpace ℝ (Fin n)) := + ContinuousLinearMap.continuousSMul + simp only [ofPred_exists] + apply IsOpen.measurableSet + apply isOpen_iUnion + intro x + apply isOpen_lt continuous_const + apply continuous_norm.comp + apply ((Matrix.toEuclideanCLM (𝕜 := ℝ) (n := Fin n)).toAlgEquiv.toLinearEquiv.toLinearMap.continuous_of_finiteDimensional).comp + apply continuous_pi + intro i + apply continuous_pi + intro j + exact (((continuous_coupling i j).pow 2).sub continuous_const).mul_const _ + +lemma augmented_weighted_operator_rare {X : Type*} [PseudoMetricSpace X] [CompactSpace X] + (β : ℝ) (G : X × X → ℝ) (hG : Continuous G) {u : ℝ} (hu : 0 standardArrayLaw (Fin n × Fin n)) + (fun n => {g | ∃ x : Fin n → X, u < euclideanOpNorm + (fun i j => squareError β (augmentedDisorder β g) i j*G (x i,x j))}) := by + obtain ⟨C,c,hC,hc,ht⟩ := weighted_square_operator_rare β G hG hu + refine ⟨C,c,hC,hc,?_⟩ + filter_upwards [ht,eventually_gt_atTop 0] with n hn hn0 + rw [(augmentedDisorder_hasLaw hn0 β).measure_eq (weighted_operator_event_measurable β u G)] + exact hn + +lemma squareError_row (β : ℝ) (g : Disorder n) (f : Fin n → ℝ) (i : Fin n) : + (∑ j, squareError β g i j*f j) = + (∑ e : incidentEdges i, (g e^2-β^2/(n:ℝ))*f (otherEnd i e))-β^2/(n:ℝ)*f i := by + have he := squareError_decomposition β g + simp_rw [show (fun i j => squareError β g i j)= + (fun i j => coupling (fun e => g e^2-β^2/(n:ℝ)) i j- + Matrix.diagonal (fun _ => β^2/(n:ℝ)) i j) from congrArg (fun m => fun i j => m i j) he] + simp only [sub_mul,Finset.sum_sub_distrib] + rw [sum_coupling_weighted_row] + simp only [←Finset.sum_attach (s := incidentEdges i)] + congr 1 + · simp only [sub_mul,Finset.sum_sub_distrib, Finset.attach_eq_univ] + · simp [Matrix.diagonal_apply,ite_mul] + +lemma diagonal_weight_bound (G : FieldWeight × FieldWeight → ℝ) (x : Fin n → FieldWeight) + (p ζ : Fin n → ℝ) {u : ℝ} (hζ : ∀ i, |ζ i| ≤ u) + (hG : ∀ a : FieldWeight, |G (a,a)| ≤ 1) : + |weightedForm (Matrix.diagonal ζ) G x p| ≤ u*∑ i, p i^2 := by + have hf : weightedForm (Matrix.diagonal ζ) G x p = ∑ i, ζ i*G (x i,x i)*p i^2 := by + simp only [weightedForm,quadratic,Matrix.diagonal_apply,ite_mul,zero_mul, + Finset.sum_ite_eq,Finset.mem_univ,ite_true] + apply Finset.sum_congr rfl + intro i _ + ring + rw [hf] + apply (Finset.abs_sum_le_sum_abs _ _).trans + calc + _ ≤ ∑ i, u*p i^2 := Finset.sum_le_sum (fun i _ => by + rw [abs_mul,abs_mul,abs_of_nonneg (sq_nonneg (p i))] + exact mul_le_mul_of_nonneg_right + ((mul_le_mul_of_nonneg_left (hG (x i)) (abs_nonneg _)).trans (by simpa only [mul_one] using hζ i)) + (sq_nonneg _)) + _ = _ := (Finset.mul_sum ..).symm + +lemma compactF_le_eight (a b : FieldWeight) : |compactF (a,b)|≤8 := by + rw [abs_of_nonneg (compactF_nonneg _)] + exact (compactF_bound _).trans (by nlinarith [b.2.2]) + +def reducedForm (β : ℝ) (g : (Fin n × Fin n) → ℝ) (p : Fin n → ℝ) : ℝ := + let x := fun i => compactWeight (augmentedField β g i) + weightedForm (augmented β g) varianceKernel x p + + 2*weightedForm (fun _ _ => β^2/(n:ℝ)) meanVarianceKernel x p + + diagonalForm (fun _ _ => β^2/(n:ℝ)) compactF x p + + weightedForm (fun _ _ => β^2/(n:ℝ)) compactK x p + +lemma compactForm_reduced_error (β : ℝ) (g : (Fin n × Fin n) → ℝ) + (p : Fin n → ℝ) {a d : ℝ} + (hdiag : ∀ i, |augmentedDiagonal β g i|≤a) + (hm : ∀ x : Fin n → FieldWeight, euclideanOpNorm + (fun i j => squareError β (augmentedDisorder β g) i j*meanVarianceKernel (x i,x j)) ≤ a) + (hk : ∀ x : Fin n → FieldWeight, euclideanOpNorm + (fun i j => squareError β (augmentedDisorder β g) i j*compactK (x i,x j)) ≤ a) + (hf : ∀ i, |∑ e : incidentEdges i, (augmentedDisorder β g e^2-β^2/(n:ℝ))* + compactF (compactWeight (augmentedField β g i),compactWeight (augmentedField β g (otherEnd i e)))| ≤ d) : + |compactForm (coupling (augmentedDisorder β g)) + (fun i => compactWeight (augmentedField β g i)) p-reducedForm β g p| ≤ + (4*a+d+8*β^2/(n:ℝ))*(∑ i, p i^2) := by + let J := coupling (augmentedDisorder β g) + let x := fun i => compactWeight (augmentedField β g i) + let L := weightedForm J varianceKernel x p-weightedForm (augmented β g) varianceKernel x p + let Q : Matrix (Fin n) (Fin n) ℝ := Matrix.of (fun i j => J i j^2) + let B : Matrix (Fin n) (Fin n) ℝ := Matrix.of (fun _ _ => β^2/(n:ℝ)) + let M := weightedForm Q meanVarianceKernel x p-weightedForm B meanVarianceKernel x p + let D := diagonalForm Q compactF x p-diagonalForm B compactF x p + let K := weightedForm Q compactK x p-weightedForm B compactK x p + have hL : |L|≤a*(∑ i, p i^2) := by + have hd := diagonal_weight_bound varianceKernel x p (augmentedDiagonal β g) hdiag + (fun b => by simpa only [varianceKernel,abs_of_nonneg (compactV_nonneg b)] using compactV_le_one b) + have he : weightedForm (augmented β g) varianceKernel x p = + weightedForm J varianceKernel x p+weightedForm (Matrix.diagonal (augmentedDiagonal β g)) varianceKernel x p := by + have hmat : augmented β g = (Matrix.of J)+Matrix.diagonal (augmentedDiagonal β g) := by + dsimp only [J] + rw [coupling_augmentedDisorder] + change augmented β g = (augmented β g - Matrix.diagonal (augmentedDiagonal β g)) + Matrix.diagonal (augmentedDiagonal β g) + exact (sub_add_cancel _ _).symm + rw [hmat] + simp only [weightedForm,quadratic,Matrix.add_apply,add_mul,Finset.sum_add_distrib,Matrix.of_apply] + dsimp [L] + rw [he,sub_add_cancel_left,abs_neg] + exact hd + have hM : |M|≤a*(∑ i, p i^2) := by + dsimp only [M] + rw [weightedForm_sub] + exact (quadratic_abs_le _ p).trans (mul_le_mul_of_nonneg_right (hm x) + (Finset.sum_nonneg (fun _ _ => sq_nonneg _))) + have hK : |K|≤a*(∑ i, p i^2) := by + dsimp only [K] + rw [weightedForm_sub] + exact (quadratic_abs_le _ p).trans (mul_le_mul_of_nonneg_right (hk x) + (Finset.sum_nonneg (fun _ _ => sq_nonneg _))) + have hD : |D|≤(d+8*β^2/(n:ℝ))*(∑ i, p i^2) := by + dsimp only [D] + rw [diagonalForm_sub] + apply diagonalForm_abs_le + intro i + change |∑ j, squareError β (augmentedDisorder β g) i j*compactF (x i,x j)|≤_ + rw [squareError_row] + apply (abs_sub _ _).trans + apply add_le_add (hf i) + rw [abs_mul,abs_of_nonneg (by positivity : 0≤β^2/(n:ℝ))] + have hh := mul_le_mul_of_nonneg_left (compactF_le_eight (x i) (x i)) + (show 0≤β^2/(n:ℝ) by positivity) + convert hh using 1 + ring + have hid : compactForm J x p-reducedForm β g p=L+2*M+D+K := by + dsimp [compactForm,reducedForm,L,M,D,K,x,Q,B] + simp only [weightedForm,diagonalForm,Matrix.of_apply] + ring + change |compactForm J x p-reducedForm β g p| ≤ _ + rw [hid] + have ht := (abs_add_le (L+2*M+D) K).trans + (add_le_add ((abs_add_le (L+2*M) D).trans (add_le_add (abs_add_le L (2*M)) le_rfl)) le_rfl) + rw [abs_mul,abs_of_pos (by norm_num : (0:ℝ)<2)] at ht + nlinarith only [ht,hL,hM,hD,hK] + +theorem reduced_error_rare {β : ℝ} (hβ : 0<β) {u : ℝ} (hu : 0 standardArrayLaw (Fin n × Fin n)) + (fun n => {g | ∃ p : Fin n → ℝ, u*(∑ i, p i^2)< + |gradientForm (coupling (augmentedDisorder β g)) p-reducedForm β g p|}) := by + let K := 2*β+β^2+1 + have hK : 0≤K := by dsimp [K]; positivity + let a := u/8 + have ha : 0 hn.le) + filter_upwards [ht] with n hn + rintro g ⟨p,hp⟩ + by_contra hb + have hnorm : euclideanOpNorm (coupling (augmentedDisorder β g))≤K := + le_of_not_gt (fun h => hb (Or.inl (Or.inl (Or.inl (Or.inl h))))) + have hdiag : ∀ i, |augmentedDiagonal β g i|≤ min δ a := + fun i => le_of_not_gt (fun h => hb (Or.inl (Or.inl (Or.inl (Or.inr ⟨i,h⟩))))) + have hm : ∀ x : Fin n → FieldWeight, euclideanOpNorm + (fun i j => squareError β (augmentedDisorder β g) i j*meanVarianceKernel (x i,x j))≤a := + fun x => le_of_not_gt (fun h => hb (Or.inl (Or.inl (Or.inr ⟨x,h⟩)))) + have hk : ∀ x : Fin n → FieldWeight, euclideanOpNorm + (fun i j => squareError β (augmentedDisorder β g) i j*compactK (x i,x j))≤a := + fun x => le_of_not_gt (fun h => hb (Or.inl (Or.inr ⟨x,h⟩))) + have hf : ∀ i, |∑ e : incidentEdges i, (augmentedDisorder β g e^2-β^2/(n:ℝ))* + compactF (compactWeight (augmentedField β g i),compactWeight (augmentedField β g (otherEnd i e)))|≤a := + fun i => le_of_not_gt (fun h => hb (Or.inr ⟨i,h⟩)) + let J := coupling (augmentedDisorder β g) + have hefield (i : Fin n) : |(∑ j, J i j)-augmentedField β g i|≤δ := by + rw [←diagonalField_augmented] + change |(∑ j, J i j)-(augmentedDiagonal β g i+(∑ j, J i j))|≤δ + rw [sub_add_cancel_right,abs_neg] + exact (hdiag i).trans (min_le_left _ _) + have h₁ := hfield J (coupling_symm _) hnorm + (row_squares_le_opNorm J (coupling_symm _) hK hnorm) _ _ p hefield + have h₂ := compactForm_reduced_error β g p (fun i => (hdiag i).trans (min_le_right _ _)) hm hk hf + have hgrad := gradientForm_eq_compactForm J (coupling_symm _) (coupling_diag _) p + rw [hgrad] at hp + have habs := abs_sub_le (compactForm J (fun i => compactWeight (∑ j, J i j)) p) + (compactForm J (fun i => compactWeight (augmentedField β g i)) p) (reducedForm β g p) + have hnorm0 : 0≤∑ i, p i^2 := Finset.sum_nonneg (fun _ _ => sq_nonneg _) + have hh := mul_le_mul_of_nonneg_right hn hnorm0 + dsimp [a] at h₁ h₂ hh + nlinarith only [hp,habs,h₁,h₂,hh,hu,hnorm0] + +end SKRatio.Planted + +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Variational/ScalarCoherent.lean b/lean/OAI/Probability/SKRatio/Variational/ScalarCoherent.lean new file mode 100644 index 0000000000000000000000000000000000000000..30b4a03776a6210e15f8210e454bbe4424f57b40 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Variational/ScalarCoherent.lean @@ -0,0 +1,299 @@ +import Mathlib +import OAI.Probability.SKRatio.Variational.ScalarHilbert + +namespace OAI + +noncomputable section +open scoped Topology NNReal ENNReal +open MeasureTheory ProbabilityTheory Real +namespace SKRatio.Scalar + +def a (β : ℝ) : ℝ := ∫ h, v h ∂fieldLaw β + +def l (β : ℝ) : ℝ := ∫ h, multiplier h ∂fieldLaw β + +def G (β : ℝ) : ℝ := ∫ h, g h ∂fieldLaw β + +def R (β : ℝ) : ℝ := ∫ h, rho h ∂fieldLaw β + +lemma l_eq (β : ℝ) : l β = 64/100-(19/100)*a β := mean_multiplier β +lemma l_pos (β : ℝ) : 0 < l β := mean_multiplier_pos _ +lemma a_nonneg (β : ℝ) : 0 ≤ a β := integral_nonneg (fun h => (v_pos h).le) +lemma a_le_one (β : ℝ) : a β ≤ 1 := by + have h := integral_mono (memLp_v.integrable (by norm_num : (1:ENNReal) ≤ 2)) + (integrable_const (μ := fieldLaw β) 1) v_le_one + simpa only [a,integral_const,probReal_univ,smul_eq_mul,one_mul] using h +lemma l_lower (β : ℝ) : 45/100 ≤ l β := by + rw [l_eq] + linarith [a_le_one β] +lemma R_nonneg (β : ℝ) : 0 ≤ R β := integral_rho_nonneg + +def F (β : ℝ) (h : ℝ) : ℝ := + (v h+a β)*h + 2*β^2*m h*v h + (50/100-β^2*a β/l β)*v h + + (12/100)*m h + 3*β^2*G β*g h + +def U₀ (β : ℝ) : ℝ := l β+18/1000+ + β^2*(a β^2/l β-a β-(3/2)*G β^2)-β^2*R β + +def U₁ (β : ℝ) : ℝ := (4644/10000)-β*sd (fieldLaw β) v/2+ + β^2*(∫ h, m h*v h ∂fieldLaw β)- + β^2*((3/2)*sd (fieldLaw β) g^2+R β) + +lemma multiplier_affine_v (h : ℝ) : + multiplier h = (70/100)-(1/4)*v h-(6/100)*m h := by + unfold multiplier v + ring + +lemma memLp_F (β : ℝ) : MemLp (F β) 2 (fieldLaw β) := by + convert! (((((memLp_field_v β).add ((memLp_field β).const_mul (a β))).add + (memLp_mv.const_mul (2*β^2))).add (memLp_v.const_mul (50/100-β^2*a β/l β))).add + (memLp_m.const_mul (12/100:ℝ))).add (memLp_g.const_mul (3*β^2*G β)) using 1 + ext h + dsimp [F] + ring + +lemma integral_F_pairing (β : ℝ) {b : ℝ → ℝ} (hb : MemLp b 2 (fieldLaw β)) : + ∫ h, b h*F β h ∂fieldLaw β = + (∫ h, b h*(h*v h) ∂fieldLaw β)+a β*(∫ h, b h*h ∂fieldLaw β)+ + (2*β^2)*(∫ h, b h*(m h*v h) ∂fieldLaw β)+ + (50/100-β^2*a β/l β)*(∫ h, b h*v h ∂fieldLaw β)+ + (12/100)*(∫ h, b h*m h ∂fieldLaw β)+ + (3*β^2*G β)*(∫ h, b h*g h ∂fieldLaw β) := by + have ihv : Integrable (fun h => b h*(h*v h)) (fieldLaw β) := hb.integrable_mul (memLp_field_v β) + have ih : Integrable (fun h => b h*h) (fieldLaw β) := hb.integrable_mul (memLp_field β) + have imv : Integrable (fun h => b h*(m h*v h)) (fieldLaw β) := hb.integrable_mul (memLp_mv (p := 2)) + have iv : Integrable (fun h => b h*v h) (fieldLaw β) := hb.integrable_mul (memLp_v (p := 2)) + have im : Integrable (fun h => b h*m h) (fieldLaw β) := hb.integrable_mul (memLp_m (p := 2)) + have ig : Integrable (fun h => b h*g h) (fieldLaw β) := hb.integrable_mul memLp_g + have he (h : ℝ) : b h*F β h = + b h*(h*v h)+a β*(b h*h)+(2*β^2)*(b h*(m h*v h))+ + (50/100-β^2*a β/l β)*(b h*v h)+(12/100)*(b h*m h)+ + (3*β^2*G β)*(b h*g h) := by unfold F; ring + simp_rw [he] + have i1 : Integrable (fun h => b h*(h*v h)+a β*(b h*h)) (fieldLaw β) := + ihv.add (ih.const_mul _) + have i2 : Integrable (fun h => b h*(h*v h)+a β*(b h*h)+(2*β^2)*(b h*(m h*v h))) + (fieldLaw β) := i1.add (imv.const_mul _) + have i3 : Integrable (fun h => b h*(h*v h)+a β*(b h*h)+(2*β^2)*(b h*(m h*v h))+ + (50/100-β^2*a β/l β)*(b h*v h)) (fieldLaw β) := i2.add (iv.const_mul _) + have i4 : Integrable (fun h => b h*(h*v h)+a β*(b h*h)+(2*β^2)*(b h*(m h*v h))+ + (50/100-β^2*a β/l β)*(b h*v h)+(12/100)*(b h*m h)) (fieldLaw β) := + i3.add (im.const_mul _) + rw [integral_add i4 (ig.const_mul _),integral_add i3 (im.const_mul _), + integral_add i2 (iv.const_mul _),integral_add i1 (imv.const_mul _), + integral_add ihv (ih.const_mul _)] + simp only [integral_const_mul] + +lemma integral_mean_zero_multiplier (β : ℝ) {b : ℝ → ℝ} + (hb : MemLp b 2 (fieldLaw β)) (hmean : ∫ h, b h ∂fieldLaw β = 0) : + ∫ h, b h*multiplier h ∂fieldLaw β = + -(1/4)*(∫ h, b h*v h ∂fieldLaw β)-(6/100)*(∫ h, b h*m h ∂fieldLaw β) := by + have ib := hb.integrable (by norm_num : (1:ENNReal) ≤ 2) + have iv : Integrable (fun h => b h*v h) (fieldLaw β) := hb.integrable_mul (memLp_v (p := 2)) + have im : Integrable (fun h => b h*m h) (fieldLaw β) := hb.integrable_mul (memLp_m (p := 2)) + have he (h : ℝ) : b h*multiplier h = + (70/100)*b h-(1/4)*(b h*v h)-(6/100)*(b h*m h) := by + rw [multiplier_affine_v] + ring + simp_rw [he] + have i1 : Integrable (fun h => (70/100)*b h-(1/4)*(b h*v h)) (fieldLaw β) := + (ib.const_mul _).sub (iv.const_mul _) + rw [integral_sub i1 (im.const_mul _),integral_sub (ib.const_mul _) (iv.const_mul _)] + simp only [integral_const_mul,hmean,mul_zero,zero_sub,neg_mul] + +lemma mean_field (β : ℝ) : ∫ h, h ∂fieldLaw β = β^2 := integral_id_gaussianReal + +lemma sd_field {β : ℝ} (hβ : 0 ≤ β) : sd (fieldLaw β) (fun h => h) = β := by + have hh := variance_id_gaussianReal (μ := β^2) (v := variance β) + rw [variance_eq_integral measurable_id.aemeasurable] at hh + change ∫ h, (h-(∫ t, t ∂fieldLaw β))^2 ∂fieldLaw β = _ at hh + rw [variance_coe] at hh + unfold sd l2Norm centered + rw [hh,sqrt_sq hβ] + +lemma field_centered_covariance (β : ℝ) : + ∫ h, centered (fieldLaw β) (fun t => t) h*centered (fieldLaw β) v h ∂fieldLaw β = + -2*β^2*(∫ h, m h*v h ∂fieldLaw β) := by + have hm := integral_centered (memLp_field β) + rw [pairing_centered (memLp_centered (memLp_field β)) memLp_v hm] + have he := coherent_paired_expansion β (memLp_const (1:ℝ)) + simp only [one_mul,field_variance_identity] at he + have hd := integral_mul_decomposition (memLp_field β) (memLp_v (p := 2)) + rw [mean_field] at hd + linarith only [he,hd] + +lemma centered_field_v_rank_bound {β : ℝ} (hβ : 0 ≤ β) {b : ℝ → ℝ} + (hb : MemLp b 2 (fieldLaw β)) (hmean : ∫ h, b h ∂fieldLaw β = 0) : + (∫ h, b h*h ∂fieldLaw β)*(∫ h, b h*v h ∂fieldLaw β) ≤ + (β*sd (fieldLaw β) v/2-β^2*(∫ h, m h*v h ∂fieldLaw β))* + (∫ h, b h^2 ∂fieldLaw β) := by + have h := rank_two_bound hb (memLp_centered (memLp_field β)) + (memLp_centered (memLp_v (p := 2))) + rw [pairing_centered hb (memLp_field β) hmean, + pairing_centered hb memLp_v hmean,field_centered_covariance] at h + change _ ≤ ((sd (fieldLaw β) (fun h => h)*sd (fieldLaw β) v+ + -2*β^2*(∫ h, m h*v h ∂fieldLaw β))/2)*_ at h + rw [sd_field hβ] at h + convert! h using 1 + ring + +section WeightedSquare +variable {μ : Measure ℝ} [IsProbabilityMeasure μ] + +omit [IsProbabilityMeasure μ] in +lemma integrable_multiplier_translate_square {b : ℝ → ℝ} (hb : MemLp b 2 μ) (c : ℝ) : + Integrable (fun h => (multiplier h+c)*b h^2) μ := by + simp_rw [add_mul] + exact (integrable_multiplier_square hb).add (hb.integrable_sq.const_mul c) + +lemma weighted_square_centered {b : ℝ → ℝ} (hb : MemLp b 2 μ) (c : ℝ) : + ∫ h, (multiplier h+c)*b h^2 ∂μ = + (∫ h, b h ∂μ)^2*((∫ h, multiplier h ∂μ)+c)+ + (2*(∫ h, b h ∂μ))*(∫ h, centered μ b h*multiplier h ∂μ)+ + (∫ h, (multiplier h+c)*centered μ b h^2 ∂μ) := by + let A := ∫ h, b h ∂μ + let b₀ := centered μ b + have hb0 : MemLp b₀ 2 μ := memLp_centered hb + have hbI := hb0.integrable (by norm_num : (1:ENNReal) ≤ 2) + have hL : Integrable (fun h => b₀ h*multiplier h) μ := hb0.integrable_mul memLp_multiplier + have hI := integrable_multiplier_translate_square hb0 c + have iL : Integrable multiplier μ := integrable_multiplier μ + have he (h : ℝ) : (multiplier h+c)*b h^2 = + A^2*(multiplier h+c)+(2*A)*(b₀ h*multiplier h)+(2*A*c)*b₀ h+ + (multiplier h+c)*b₀ h^2 := by dsimp [A,b₀,centered]; ring + simp_rw [he] + have i1 : Integrable (fun h => A^2*(multiplier h+c)) μ := + (iL.add (integrable_const c)).const_mul _ + have i2 : Integrable (fun h => A^2*(multiplier h+c)+(2*A)*(b₀ h*multiplier h)) μ := + i1.add (hL.const_mul _) + have i3 : Integrable (fun h => A^2*(multiplier h+c)+(2*A)*(b₀ h*multiplier h)+ + (2*A*c)*b₀ h) μ := i2.add (hbI.const_mul _) + rw [integral_add i3 hI,integral_add i2 (hbI.const_mul _),integral_add i1 (hL.const_mul _)] + simp only [integral_const_mul] + rw [integral_add iL (integrable_const c),integral_const] + simp only [probReal_univ,smul_eq_mul,one_mul,show (∫ h, b₀ h ∂μ) = 0 from integral_centered hb, + mul_zero,add_zero] + rfl + +omit [IsProbabilityMeasure μ] in +lemma weighted_square_floor {b : ℝ → ℝ} (hb : MemLp b 2 μ) (c : ℝ) : + (4464/10000+c)*(∫ h, b h^2 ∂μ) ≤ ∫ h, (multiplier h+c)*b h^2 ∂μ := by + rw [←integral_const_mul] + apply integral_mono (hb.integrable_sq.const_mul _) (integrable_multiplier_translate_square hb c) + intro h + exact mul_le_mul_of_nonneg_right (by linarith [multiplier_pos h]) (sq_nonneg _) + +end WeightedSquare + +def coherentUpper (β : ℝ) (b : ℝ → ℝ) : ℝ := + (∫ h, b h*h ∂fieldLaw β)*(∫ h, b h*v h ∂fieldLaw β)+ + (∫ h, b h ∂fieldLaw β)*(∫ h, b h*((h-β^2+2*β^2*m h)*v h) ∂fieldLaw β)+ + β^2*((3/2)*(∫ h, b h*g h ∂fieldLaw β)^2+R β*(∫ h, b h^2 ∂fieldLaw β))- + β^2/(4*l β)*((∫ h, b h*v h ∂fieldLaw β)+a β*(∫ h, b h ∂fieldLaw β))^2 + +lemma coherent_le_upper (β : ℝ) {b : ℝ → ℝ} (hb : MemLp b 2 (fieldLaw β)) : + coherent β b ≤ coherentUpper β b := by + have h := mul_le_mul_of_nonneg_left (kernel_bound hb) (sq_nonneg β) + unfold coherent coherentUpper a l R + linarith only [h] + +lemma memLp_stein_v (β : ℝ) : + MemLp (fun h => (h-β^2+2*β^2*m h)*v h) 2 (fieldLaw β) := by + convert! ((memLp_field_v β).sub (memLp_v.const_mul (β^2))).add + (memLp_mv.const_mul (2*β^2)) using 1 + ext h + dsimp + ring + +theorem coherent_full_expansion (β : ℝ) {b : ℝ → ℝ} (hb : MemLp b 2 (fieldLaw β)) : + let A := ∫ h, b h ∂fieldLaw β + let b₀ := centered (fieldLaw β) b + coherentUpper β b-(∫ h, (multiplier h+18/1000)*b h^2 ∂fieldLaw β) = + -U₀ β*A^2 + A*(∫ h, b₀ h*F β h ∂fieldLaw β)+ + (∫ h, b₀ h*h ∂fieldLaw β)*(∫ h, b₀ h*v h ∂fieldLaw β)+ + (3/2)*β^2*(∫ h, b₀ h*g h ∂fieldLaw β)^2+ + β^2*R β*(∫ h, b₀ h^2 ∂fieldLaw β)- + β^2/(4*l β)*(∫ h, b₀ h*v h ∂fieldLaw β)^2- + (∫ h, (multiplier h+18/1000)*b₀ h^2 ∂fieldLaw β) := by + dsimp only + have hb0 := memLp_centered hb + have hmean := integral_centered hb + have hdH := integral_mul_decomposition hb (memLp_field β) + have hdV := integral_mul_decomposition hb (memLp_v (p := 2)) + have hdG := integral_mul_decomposition hb memLp_g + have hdT := integral_mul_decomposition hb (memLp_stein_v β) + rw [field_variance_identity,mul_zero,zero_add] at hdT + rw [mean_field] at hdH + unfold coherentUpper + rw [hdH,hdV,hdG,hdT,l2_decomposition hb,weighted_square_centered hb, + integral_F_pairing β hb0,coherent_paired_expansion β hb0, + integral_mean_zero_multiplier β hb0 hmean] + unfold U₀ a l G + field_simp + ring + +theorem coherent_two_dimensional {β : ℝ} (hβ : 0 ≤ β) {b : ℝ → ℝ} + (hb : MemLp b 2 (fieldLaw β)) : + let A := ∫ h, b h ∂fieldLaw β + let b₀ := centered (fieldLaw β) b + coherent β b-(∫ h, (multiplier h+18/1000)*b h^2 ∂fieldLaw β) ≤ + -U₀ β*A^2-U₁ β*(∫ h, b₀ h^2 ∂fieldLaw β)+A*(∫ h, b₀ h*F β h ∂fieldLaw β) := by + dsimp only + have hb0 := memLp_centered hb + have hmean := integral_centered hb + have hform := coherent_le_upper β hb + have hexp := coherent_full_expansion β hb + dsimp only at hexp + have hHV := centered_field_v_rank_bound hβ hb0 hmean + have hG := mul_le_mul_of_nonneg_left (pairing_centered_sq_le hb0 memLp_g hmean) + (show 0 ≤ (3/2:ℝ)*β^2 by positivity) + have hL := weighted_square_floor hb0 (18/1000) + have hneg : 0 ≤ β^2/(4*l β)*(∫ h, centered (fieldLaw β) b h*v h ∂fieldLaw β)^2 := + mul_nonneg (div_nonneg (sq_nonneg β) (by positivity [l_pos β])) (sq_nonneg _) + unfold U₁ + nlinarith only [hform,hexp,hHV,hG,hL,hneg] + +lemma quadratic_slack_bound {u₀ u₁ s A t : ℝ} (hu : 0 < u₀) (_ht : 0 ≤ t) + (_hs : 0 ≤ s) (hdisc : s^2 ≤ 4*u₀*u₁) : + -u₀*A^2-u₁*t^2+abs A*s*t ≤ 0 := by + have hsq := sq_nonneg (2*u₀*abs A-s*t) + have hd := mul_le_mul_of_nonneg_right hdisc (sq_nonneg t) + have he : (2*u₀*abs A-s*t)^2 = 4*u₀^2*A^2-4*u₀*abs A*s*t+s^2*t^2 := by + ring_nf + rw [sq_abs] + rw [he] at hsq + apply (mul_le_mul_iff_of_pos_left (show 0 < 4*u₀ by positivity)).mp + nlinarith only [hsq,hd] + +theorem coherent_bound_of_slacks {β : ℝ} (hβ : 0 ≤ β) + (hU₀ : 0 < U₀ β) (hdisc : sd (fieldLaw β) (F β)^2 ≤ 4*U₀ β*U₁ β) + {b : ℝ → ℝ} (hb : MemLp b 2 (fieldLaw β)) : + coherent β b ≤ ∫ h, (multiplier h+18/1000)*b h^2 ∂fieldLaw β := by + have htwo := coherent_two_dimensional hβ hb + dsimp only at htwo + let A := ∫ h, b h ∂fieldLaw β + let b₀ := centered (fieldLaw β) b + let t := l2Norm (fieldLaw β) b₀ + let s := sd (fieldLaw β) (F β) + have hb0 : MemLp b₀ 2 (fieldLaw β) := memLp_centered hb + have hs : 0 ≤ s := sd_nonneg _ + have ht : 0 ≤ t := l2Norm_nonneg _ + have ht2 : t^2 = ∫ h, b₀ h^2 ∂fieldLaw β := l2Norm_sq _ + have hcs := abs_pairing_centered_le hb0 (memLp_F β) (integral_centered hb) + have hcross : A*(∫ h, b₀ h*F β h ∂fieldLaw β) ≤ abs A*s*t := by + calc + _ ≤ |A*(∫ h, b₀ h*F β h ∂fieldLaw β)| := le_abs_self _ + _ = abs A*|∫ h, b₀ h*F β h ∂fieldLaw β| := abs_mul _ _ + _ ≤ abs A*(t*s) := mul_le_mul_of_nonneg_left hcs (abs_nonneg _) + _ = _ := by ring + have hq := quadratic_slack_bound (A := A) hU₀ ht hs hdisc + rw [ht2] at hq + change coherent β b-_ ≤ -U₀ β*A^2-U₁ β*(∫ h, b₀ h^2 ∂fieldLaw β)+ + A*(∫ h, b₀ h*F β h ∂fieldLaw β) at htwo + linarith only [htwo,hcross,hq] + +end SKRatio.Scalar + +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Variational/ScalarDensity.lean b/lean/OAI/Probability/SKRatio/Variational/ScalarDensity.lean new file mode 100644 index 0000000000000000000000000000000000000000..e349b991244f87c019cc8d0c3104e1504d8b7dbc --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Variational/ScalarDensity.lean @@ -0,0 +1,89 @@ +import Mathlib +import OAI.Probability.SKRatio.Variational.ScalarVariance + +namespace OAI + +noncomputable section +open scoped Topology ENNReal NNReal +open MeasureTheory ProbabilityTheory Real +namespace SKRatio.Scalar + +lemma field_pdf_ratio {β z : ℝ} (hβ : 0 < β) (hz : 0 < z) (h : ℝ) : + gaussianPDFReal (β^2) (variance β) h = + (z/β)*exp ((z^2-β^2)/2+(1/(2*z^2)-1/(2*β^2))*h^2)* + gaussianPDFReal (z^2) (variance z) h := by + rw [field_pdf hβ,field_pdf hz] + have he : (z^2-β^2)/2+(1/(2*z^2)-1/(2*β^2))*h^2 + + (-z^2/2+h-h^2/(2*z^2)) = -β^2/2+h-h^2/(2*β^2) := by ring + calc + _ = (z/β)*(sqrt (2*Real.pi)*z)⁻¹*exp (-β^2/2+h-h^2/(2*β^2)) := by + field_simp + _ = _ := by rw [←he,exp_add]; ring + +def densityFactor (β z : ℝ) : ℝ := z/β*exp ((z^2-β^2)/2) + +lemma densityFactor_pos {β z : ℝ} (hβ : 0 < β) (hz : 0 < z) : + 0 < densityFactor β z := mul_pos (div_pos hz hβ) (exp_pos _) + +lemma field_pdf_le_factor {β z : ℝ} (hβ : 0 < β) (hβz : β ≤ z) (h : ℝ) : + gaussianPDFReal (β^2) (variance β) h ≤ + densityFactor β z*gaussianPDFReal (z^2) (variance z) h := by + have hz : 0 < z := hβ.trans_le hβz + rw [field_pdf_ratio hβ hz] + have hi : 1/(2*z^2) ≤ 1/(2*β^2) := by + apply one_div_le_one_div_of_le (by positivity) + nlinarith + apply mul_le_mul_of_nonneg_right _ (gaussianPDFReal_nonneg _ _ _) + apply mul_le_mul_of_nonneg_left _ (div_pos hz hβ).le + apply exp_le_exp.mpr + have hh := mul_nonpos_of_nonpos_of_nonneg (sub_nonpos.mpr hi) (sq_nonneg h) + linarith + +lemma densityFactor_mono_left {j β z : ℝ} (hj : 0 < j) (hjβ : j ≤ β) (hβz : β ≤ z) : + densityFactor β z ≤ densityFactor j z := by + have hβ : 0 < β := hj.trans_le hjβ + have hz : 0 < z := hβ.trans_le hβz + apply mul_le_mul + · exact div_le_div_of_nonneg_left hz.le hj hjβ + · apply exp_le_exp.mpr + nlinarith + · exact (exp_pos _).le + · exact (div_pos hz hj).le + +lemma fieldLaw_le_factor {β z : ℝ} (hβ : 0 < β) (hβz : β ≤ z) : + fieldLaw β ≤ ENNReal.ofReal (densityFactor β z) • fieldLaw z := by + have hz : 0 < z := hβ.trans_le hβz + rw [fieldLaw,fieldLaw,gaussianReal_of_var_ne_zero _ (variance_ne_zero hβ), + gaussianReal_of_var_ne_zero _ (variance_ne_zero hz), + ←withDensity_smul' _ _ ENNReal.ofReal_ne_top] + apply withDensity_mono + apply ae_of_all + intro h + simp only [Pi.smul_apply,smul_eq_mul,gaussianPDF, + ←ENNReal.ofReal_mul (densityFactor_pos hβ hz).le] + exact ENNReal.ofReal_le_ofReal (field_pdf_le_factor hβ hβz h) + +lemma fieldLaw_le_interval_factor {j β z : ℝ} (hj : 0 < j) (hjβ : j ≤ β) (hβz : β ≤ z) : + fieldLaw β ≤ ENNReal.ofReal (densityFactor j z) • fieldLaw z := by + apply (fieldLaw_le_factor (hj.trans_le hjβ) hβz).trans + intro s + simp only [Measure.smul_apply,smul_eq_mul] + exact mul_le_mul_of_nonneg_right (ENNReal.ofReal_le_ofReal (densityFactor_mono_left hj hjβ hβz)) (bot_le : (0:ENNReal) ≤ _) + +lemma sd_temperature_bound {β z : ℝ} (hβ : 0 < β) (hβz : β ≤ z) + {f : ℝ → ℝ} (hf : MemLp f 2 (fieldLaw β)) (hf' : MemLp f 2 (fieldLaw z)) : + sd (fieldLaw β) f ≤ sqrt (densityFactor β z)*sd (fieldLaw z) f := + sd_mono_measure_sqrt (densityFactor_pos hβ (hβ.trans_le hβz)).le + (fieldLaw_le_factor hβ hβz) hf hf' + +lemma sd_temperature_interval_bound {j β z : ℝ} (hj : 0 < j) (hjβ : j ≤ β) (hβz : β ≤ z) + {f : ℝ → ℝ} (hf : MemLp f 2 (fieldLaw β)) (hf' : MemLp f 2 (fieldLaw z)) : + sd (fieldLaw β) f ≤ sqrt (densityFactor j z)*sd (fieldLaw z) f := + sd_mono_measure_sqrt (densityFactor_pos hj (hj.trans_le (hjβ.trans hβz))).le + (fieldLaw_le_interval_factor hj hjβ hβz) hf hf' + +end SKRatio.Scalar + +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Variational/ScalarEnvelope.lean b/lean/OAI/Probability/SKRatio/Variational/ScalarEnvelope.lean new file mode 100644 index 0000000000000000000000000000000000000000..7d8bb19f6b7f228279b522cd83aab88c5003ca42 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Variational/ScalarEnvelope.lean @@ -0,0 +1,195 @@ +import Mathlib +import OAI.Probability.SKRatio.Variational.ScalarTemperature + +namespace OAI + +noncomputable section +open scoped Topology ENNReal NNReal +open MeasureTheory ProbabilityTheory Real +namespace SKRatio.Scalar + +def endpointK (y : ℝ) : ℝ := + (1/16)*(∫ h, (1-y^2+v h)^2/multiplier h ∂fieldLaw (1/2)) +def endpointD (y : ℝ) : ℝ := + (1/4)*(∫ h, v h^2/(2-y-m h) ∂fieldLaw (1/2)) +def endpointDPrime : ℝ := + (1/4)*(∫ h, v h^2/(2-m h)^2 ∂fieldLaw (1/2)) + +lemma integrable_K_integrand {μ : Measure ℝ} [IsProbabilityMeasure μ] + {y : ℝ} (hy : |y| ≤ 1) : + Integrable (fun h => (1-y^2+v h)^2/multiplier h) μ := by + have hy2 : y^2 ≤ 1 := by simpa only [sq_abs,one_pow] using + (sq_le_sq₀ (abs_nonneg y) (by norm_num : (0:ℝ) ≤ 1)).mpr hy + apply (integrable_const (12:ℝ)).mono' + (((continuous_const.add continuous_v).pow 2).div continuous_multiplier + (fun h => (multiplier_strict_pos h).ne')).aestronglyMeasurable + apply ae_of_all + intro h + change |(1-y^2+v h)^2/multiplier h| ≤ 12 + have hs : (1-y^2+v h)^2 ≤ 4 := by nlinarith [sq_nonneg y,v_le_one h,(v_pos h).le] + rw [abs_of_nonneg (div_nonneg (sq_nonneg _) (multiplier_strict_pos h).le)] + exact (div_le_div_of_nonneg_right hs (multiplier_strict_pos h).le).trans (by + rw [div_le_iff₀ (multiplier_strict_pos h)] + linarith [multiplier_pos h]) + +lemma D_integrand_pos {y : ℝ} (hy : y ≤ 1) (h : ℝ) : 0 < 2-y-m h := by + linarith [(m_bounds h).2] + +lemma D_integrand_le_two {y : ℝ} (hy : y ≤ 1) (h : ℝ) : + |v h^2/(2-y-m h)| ≤ 2 := by + have hd := D_integrand_pos hy h + rw [abs_of_nonneg (div_nonneg (sq_nonneg _) hd.le)] + apply (div_le_iff₀ hd).mpr + have hbase : v h^2 ≤ 2*(1-m h) := by + have hvw : v h = (1-m h)*(1+m h) := by unfold v; ring + have hv : v h^2 ≤ v h := by nlinarith [v_le_one h,(v_pos h).le] + have hmu := (m_bounds h).2 + have hmm : v h ≤ 2*(1-m h) := by rw [hvw]; nlinarith [sq_nonneg (1-m h)] + linarith + linarith + +lemma integrable_D_integrand {μ : Measure ℝ} [IsProbabilityMeasure μ] + {y : ℝ} (hy : y ≤ 1) : Integrable (fun h => v h^2/(2-y-m h)) μ := by + exact (integrable_const (2:ℝ)).mono' + ((continuous_v.pow 2).div (continuous_const.sub continuous_m) + (fun h => (D_integrand_pos hy h).ne')).aestronglyMeasurable + (ae_of_all _ (fun h => by simpa only [norm_eq_abs] using D_integrand_le_two hy h)) + +lemma integrable_DPrime_integrand {μ : Measure ℝ} [IsProbabilityMeasure μ] : + Integrable (fun h => v h^2/(2-m h)^2) μ := by + have hden (h : ℝ) : 0 < 2-m h := by linarith [(m_bounds h).2] + apply (integrable_const (1:ℝ)).mono' + ((continuous_v.pow 2).div ((continuous_const.sub continuous_m).pow 2) + (fun h => pow_ne_zero _ (hden h).ne')).aestronglyMeasurable + apply ae_of_all + intro h + change |v h^2/(2-m h)^2| ≤ 1 + rw [abs_of_nonneg (div_nonneg (sq_nonneg _) (sq_nonneg _))] + apply (div_le_one (sq_pos_of_pos (hden h))).mpr + nlinarith [v_le_one h,(v_pos h).le,(m_bounds h).2] + +lemma endpointK_quadratic {y : ℝ} (hy : |y| ≤ 1) : + endpointK y ≤ endpointK 0+(endpointK 1-endpointK 0)*y^2 := by + have hy2 : y^2 ≤ 1 := by simpa only [sq_abs,one_pow] using + (sq_le_sq₀ (abs_nonneg y) (by norm_num : (0:ℝ) ≤ 1)).mpr hy + have hi0 : Integrable (fun h => (1+v h)^2/multiplier h) (fieldLaw (1/2)) := by + simpa using integrable_K_integrand (y := 0) (μ := fieldLaw (1/2)) (by norm_num) + have hi1 : Integrable (fun h => v h^2/multiplier h) (fieldLaw (1/2)) := by + simpa using integrable_K_integrand (y := 1) (μ := fieldLaw (1/2)) (by norm_num) + have hp (h : ℝ) : (1-y^2+v h)^2/multiplier h ≤ + (1-y^2)*((1+v h)^2/multiplier h)+y^2*(v h^2/multiplier h) := by + have hs : (1-y^2+v h)^2 ≤ (1-y^2)*(1+v h)^2+y^2*v h^2 := by + nlinarith only [mul_nonneg (sq_nonneg y) (sub_nonneg.mpr hy2)] + convert! div_le_div_of_nonneg_right hs (multiplier_strict_pos h).le using 1 + ring + have hi := integral_mono (integrable_K_integrand hy) + ((hi0.const_mul (1-y^2)).add (hi1.const_mul (y^2))) hp + simp only [Pi.add_apply] at hi + rw [integral_add (hi0.const_mul _) (hi1.const_mul _),integral_const_mul,integral_const_mul] at hi + dsimp [endpointK] + simp only [zero_pow (by decide : (2:ℕ) ≠ 0),sub_zero,one_pow,sub_self,zero_add] + nlinarith only [hi] + +lemma resolvent_quadratic {A y : ℝ} (hA : 1 < A) (hy : y ≤ 1) : + 1/(A-y) ≤ 1/A+y/A^2+y^2*(1/(A-1)-1/A-1/A^2) := by + have hA0 : 0 < A := by linarith + have hA1 : 0 < A-1 := by linarith + have hAy : 0 < A-y := by linarith + have he : (1/A+y/A^2+y^2*(1/(A-1)-1/A-1/A^2))-1/(A-y) = + y^2*(1-y)/(A^2*(A-1)*(A-y)) := by + field_simp + ring + have hz : 0 ≤ y^2*(1-y)/(A^2*(A-1)*(A-y)) := + div_nonneg (mul_nonneg (sq_nonneg _) (sub_nonneg.mpr hy)) (by positivity) + linarith only [he,hz] + +lemma endpointD_quadratic {y : ℝ} (hy : y ≤ 1) : + endpointD y ≤ endpointD 0+endpointDPrime*y+ + y^2*(endpointD 1-endpointD 0-endpointDPrime) := by + let b0 := fun h => v h^2/(2-m h) + let b1 := fun h => v h^2/(1-m h) + let bp := fun h => v h^2/(2-m h)^2 + have hi0 : Integrable b0 (fieldLaw (1/2)) := by + simpa only [sub_zero,b0] using integrable_D_integrand (y := 0) (μ := fieldLaw (1/2)) (by norm_num) + have hi1 : Integrable b1 (fieldLaw (1/2)) := by + simpa only [b1,show (2:ℝ)-1=1 from by norm_num] using + integrable_D_integrand (y := 1) (μ := fieldLaw (1/2)) (by norm_num) + have hip : Integrable bp (fieldLaw (1/2)) := integrable_DPrime_integrand + have hrem : Integrable (fun h => b1 h-b0 h-bp h) (fieldLaw (1/2)) := + (hi1.sub hi0).sub hip + have ihl : Integrable (fun h => b0 h+y*bp h) (fieldLaw (1/2)) := hi0.add (hip.const_mul _) + have hp (h : ℝ) : v h^2/(2-y-m h) ≤ b0 h+y*bp h+y^2*(b1 h-b0 h-bp h) := by + have hh := mul_le_mul_of_nonneg_left (resolvent_quadratic (A := 2-m h) (by + linarith [(m_bounds h).2]) hy) (sq_nonneg (v h)) + convert! hh using 1 + · have hd : (2:ℝ)-m h-y = 2-y-m h := by ring + rw [hd]; ring + · dsimp [b0,b1,bp] + have hd : (2:ℝ)-m h-1 = 1-m h := by ring + rw [hd]; ring + have hi := integral_mono (integrable_D_integrand hy) (ihl.add (hrem.const_mul _)) hp + simp only [Pi.add_apply] at hi + rw [integral_add ihl (hrem.const_mul _),integral_add hi0 (hip.const_mul _), + integral_const_mul,integral_const_mul] at hi + have hir : (∫ h, b1 h-b0 h-bp h ∂fieldLaw (1/2)) = + (∫ h, b1 h ∂fieldLaw (1/2))-(∫ h, b0 h ∂fieldLaw (1/2))-(∫ h, bp h ∂fieldLaw (1/2)) := by + have hsub : Integrable (fun h => b1 h-b0 h) (fieldLaw (1/2)) := hi1.sub hi0 + rw [integral_sub hsub hip,integral_sub hi1 hi0] + rw [hir] at hi + dsimp [endpointD,endpointDPrime] + simp only [sub_zero,show (2:ℝ)-1=1 from by norm_num] + dsimp [b0,b1,bp] at hi + nlinarith only [hi] + +lemma endpointD_field (h : ℝ) : diagonal (fieldLaw (1/2)) (1/2) h = endpointD (m h) := by + unfold diagonal endpointD w + have hd (t : ℝ) : 1-m h+(1-m t) = 2-m h-m t := by ring + simp_rw [hd] + congr 1 + norm_num + +lemma endpointK_field (h : ℝ) : cost (fieldLaw (1/2)) (1/2) h = endpointK (m h) := by + unfold cost endpointK + norm_num only [show (1/2:ℝ)^2/4 = 1/16 by norm_num] + rw [←integral_const_mul] + apply integral_congr_ae + apply ae_of_all + intro t + rw [v] + change (1/16)*(v t+(1-m h^2))^2/multiplier t = (1/16)*((1-m h^2+v t)^2/multiplier t) + ring + +lemma envelope_of_endpoint_data + (hk0 : endpointK 0 ≤ 4280/10000) (hk1 : endpointK 1 ≤ 902/10000) + (hd0 : endpointD 0 ≤ 929/10000) (hd1 : endpointD 1 ≤ 2292/10000) + (hdp0 : 520/10000 ≤ endpointDPrime) (hdp1 : endpointDPrime ≤ 526/10000) + {β : ℝ} (hβ : 0 < β) (hβh : β ≤ 1/2) (h : ℝ) : + multiplier h+diagonal (fieldLaw β) β h+cost (fieldLaw β) β h ≤ 9789/10000 := by + have hm := m_bounds h + have hma : |m h| ≤ 1 := (abs_lt.mpr hm).le + have hy2 : m h^2 ≤ 1 := (tanh_sq_lt_one h).le + have hD := diagonal_temperature_mono hβ hβh (by norm_num : (1/2:ℝ) ≤ 1) h + have hK := cost_temperature_mono hβ hβh (by norm_num : (1/2:ℝ) ≤ 1) h + rw [endpointD_field] at hD + rw [endpointK_field] at hK + have hDQ := endpointD_quadratic hm.2.le + have hKQ := endpointK_quadratic hma + have hA : 45/100+endpointD 0+endpointK 0 ≤ (9709/10000:ℝ) := by linarith + have hB : 70/100+endpointK 1+endpointD 1-endpointDPrime ≤ (9709/10000:ℝ) := by linarith + have hM : |endpointDPrime-6/100| ≤ (80/10000:ℝ) := by + rw [abs_le] + constructor <;> linarith + have hC : (endpointDPrime-6/100)*m h ≤ (80/10000:ℝ) := by + calc + _ ≤ |endpointDPrime-6/100| *|m h| := by rw [←abs_mul]; exact le_abs_self _ + _ ≤ 80/10000 := by nlinarith [mul_le_mul hM hma (abs_nonneg _) (by norm_num : (0:ℝ) ≤ 80/10000)] + have hAw := mul_le_mul_of_nonneg_left hA (sub_nonneg.mpr hy2) + have hBw := mul_le_mul_of_nonneg_left hB (sq_nonneg (m h)) + unfold multiplier + nlinarith only [hD,hK,hDQ,hKQ,hAw,hBw,hC] + +end SKRatio.Scalar + +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Variational/ScalarHilbert.lean b/lean/OAI/Probability/SKRatio/Variational/ScalarHilbert.lean new file mode 100644 index 0000000000000000000000000000000000000000..36f82c264cf8494b2c0bc7e1d1dabfc7defca8b1 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Variational/ScalarHilbert.lean @@ -0,0 +1,169 @@ +import Mathlib +import OAI.Probability.SKRatio.Variational.ScalarReduction + +namespace OAI + +section +noncomputable section +open MeasureTheory Real +namespace SKRatio.Scalar + +section Measure +variable {α : Type*} [MeasurableSpace α] {μ : Measure α} + +def l2Norm (μ : Measure α) (f : α → ℝ) : ℝ := sqrt (∫ x, f x^2 ∂μ) + +lemma l2Norm_nonneg (f : α → ℝ) : 0 ≤ l2Norm μ f := sqrt_nonneg _ +lemma l2Norm_sq (f : α → ℝ) : l2Norm μ f^2 = ∫ x, f x^2 ∂μ := + sq_sqrt (integral_nonneg (fun x => sq_nonneg (f x))) + +lemma abs_integral_mul_le {f u : α → ℝ} (hf : MemLp f 2 μ) (hu : MemLp u 2 μ) : + |∫ x, f x*u x ∂μ| ≤ l2Norm μ f*l2Norm μ u := by + have h := integral_mul_norm_le_Lp_mul_Lq Real.HolderConjugate.two_two + (by simpa using hf) (by simpa using hu) + simp only [norm_eq_abs,Real.rpow_two,sq_abs,←sqrt_eq_rpow] at h + have h' : |∫ x, f x*u x ∂μ| ≤ ∫ x, |f x| * |u x| ∂μ := by + simpa only [abs_mul] using (abs_integral_le_integral_abs (f := fun x => f x*u x) (μ := μ)) + exact h'.trans h + +lemma integral_mul_sq_le {f u : α → ℝ} (hf : MemLp f 2 μ) (hu : MemLp u 2 μ) : + (∫ x, f x*u x ∂μ)^2 ≤ (∫ x, f x^2 ∂μ)*(∫ x, u x^2 ∂μ) := by + have h := sq_le_sq₀ (abs_nonneg _) (mul_nonneg (l2Norm_nonneg f) (l2Norm_nonneg u)) + |>.mpr (abs_integral_mul_le hf hu) + simpa only [sq_abs,mul_pow,l2Norm_sq] using h + +lemma integral_pairing_add {f u z : α → ℝ} + (hf : MemLp f 2 μ) (hu : MemLp u 2 μ) (hz : MemLp z 2 μ) (s t : ℝ) : + ∫ x, f x*(s*u x+t*z x) ∂μ = + s*(∫ x, f x*u x ∂μ)+t*(∫ x, f x*z x ∂μ) := by + have h1 : Integrable (fun x => f x*u x) μ := hf.integrable_mul hu + have h2 : Integrable (fun x => f x*z x) μ := hf.integrable_mul hz + have he (x : α) : f x*(s*u x+t*z x) = s*(f x*u x)+t*(f x*z x) := by ring + simp_rw [he] + rw [integral_add (h1.const_mul _) (h2.const_mul _),integral_const_mul,integral_const_mul] + +lemma integral_square_add {u z : α → ℝ} + (hu : MemLp u 2 μ) (hz : MemLp z 2 μ) (s t : ℝ) : + ∫ x, (s*u x+t*z x)^2 ∂μ = + s^2*(∫ x, u x^2 ∂μ)+(2*s*t)*(∫ x, u x*z x ∂μ)+t^2*(∫ x, z x^2 ∂μ) := by + have hpair : Integrable (fun x => u x*z x) μ := hu.integrable_mul hz + have hsum : Integrable (fun x => s^2*u x^2+(2*s*t)*(u x*z x)) μ := + (hu.integrable_sq.const_mul _).add (hpair.const_mul _) + have he (x : α) : (s*u x+t*z x)^2 = s^2*u x^2+(2*s*t)*(u x*z x)+t^2*z x^2 := by ring + simp_rw [he] + rw [integral_add hsum (hz.integrable_sq.const_mul _), + integral_add (hu.integrable_sq.const_mul _) (hpair.const_mul _), + integral_const_mul,integral_const_mul,integral_const_mul] + +theorem rank_two_bound {f u z : α → ℝ} + (hf : MemLp f 2 μ) (hu : MemLp u 2 μ) (hz : MemLp z 2 μ) : + (∫ x, f x*u x ∂μ)*(∫ x, f x*z x ∂μ) ≤ + ((l2Norm μ u*l2Norm μ z+(∫ x, u x*z x ∂μ))/2)*(∫ x, f x^2 ∂μ) := by + let U := l2Norm μ u + let Z := l2Norm μ z + have hU : 0 ≤ U := l2Norm_nonneg u + have hZ : 0 ≤ Z := l2Norm_nonneg z + have hU2 : (∫ x, u x^2 ∂μ) = U^2 := (l2Norm_sq u).symm + have hZ2 : (∫ x, z x^2 ∂μ) = Z^2 := (l2Norm_sq z).symm + have hfu := integral_mul_sq_le hf hu + have hfz := integral_mul_sq_le hf hz + have huz := integral_mul_sq_le hu hz + rw [hU2] at hfu huz + rw [hZ2] at hfz huz + by_cases hzero : U*Z = 0 + · have hcross : (∫ x, u x*z x ∂μ) = 0 := by + have hh : U^2*Z^2 = 0 := by nlinarith [sq_nonneg (U*Z)] + rw [hh] at huz + nlinarith only [huz,sq_nonneg (∫ x, u x*z x ∂μ)] + have hprod : (∫ x, f x*u x ∂μ)*(∫ x, f x*z x ∂μ) = 0 := by + rcases mul_eq_zero.mp hzero with hu0|hz0 + · rw [hu0] at hfu + have hd : (∫ x, f x*u x ∂μ) = 0 := by nlinarith only [hfu,sq_nonneg (∫ x, f x*u x ∂μ)] + rw [hd,zero_mul] + · rw [hz0] at hfz + have hd : (∫ x, f x*z x ∂μ) = 0 := by nlinarith only [hfz,sq_nonneg (∫ x, f x*z x ∂μ)] + rw [hd,mul_zero] + change _ ≤ ((U*Z+(∫ x, u x*z x ∂μ))/2)*_ + rw [hprod,hzero,hcross] + simp + · have hpos : 0 < U*Z := lt_of_le_of_ne (mul_nonneg hU hZ) (Ne.symm hzero) + have hw : MemLp (fun x => Z*u x+U*z x) 2 μ := + (hu.const_mul Z).add (hz.const_mul U) + have h := integral_mul_sq_le hf hw + rw [integral_pairing_add hf hu hz,integral_square_add hu hz,hU2,hZ2] at h + have hsq := sq_nonneg (Z*(∫ x, f x*u x ∂μ)-U*(∫ x, f x*z x ∂μ)) + apply (mul_le_mul_iff_of_pos_left (show 0 < 4*(U*Z) by positivity)).mp + change 4*(U*Z)*((∫ x, f x*u x ∂μ)*(∫ x, f x*z x ∂μ)) ≤ + 4*(U*Z)*(((U*Z+(∫ x, u x*z x ∂μ))/2)*(∫ x, f x^2 ∂μ)) + nlinarith only [h,hsq] + +end Measure + +section Probability +variable {μ : Measure ℝ} [IsProbabilityMeasure μ] + +def centered (μ : Measure ℝ) (f : ℝ → ℝ) (h : ℝ) : ℝ := f h-(∫ t, f t ∂μ) +def sd (μ : Measure ℝ) (f : ℝ → ℝ) : ℝ := l2Norm μ (centered μ f) + +omit [IsProbabilityMeasure μ] in +lemma sd_nonneg (f : ℝ → ℝ) : 0 ≤ sd μ f := l2Norm_nonneg _ + +lemma memLp_centered {f : ℝ → ℝ} (hf : MemLp f 2 μ) : MemLp (centered μ f) 2 μ := + hf.sub (memLp_const _) + +lemma integral_centered {f : ℝ → ℝ} (hf : MemLp f 2 μ) : + ∫ h, centered μ f h ∂μ = 0 := by + unfold centered + rw [integral_sub (hf.integrable (by norm_num)) (integrable_const _),integral_const] + simp + +lemma pairing_centered {f z : ℝ → ℝ} (hf : MemLp f 2 μ) (hz : MemLp z 2 μ) + (hmean : ∫ h, f h ∂μ = 0) : + ∫ h, f h*centered μ z h ∂μ = ∫ h, f h*z h ∂μ := by + have hpair : Integrable (fun h => f h*z h) μ := hf.integrable_mul hz + have he (h : ℝ) : f h*centered μ z h = f h*z h - f h*(∫ t, z t ∂μ) := by + unfold centered + ring + simp_rw [he] + rw [integral_sub hpair ((hf.integrable (by norm_num)).mul_const _),integral_mul_const,hmean] + simp + +lemma abs_pairing_centered_le {f z : ℝ → ℝ} (hf : MemLp f 2 μ) (hz : MemLp z 2 μ) + (hmean : ∫ h, f h ∂μ = 0) : + |∫ h, f h*z h ∂μ| ≤ l2Norm μ f*sd μ z := by + have h := abs_integral_mul_le hf (memLp_centered hz) + rwa [pairing_centered hf hz hmean] at h + +lemma pairing_centered_sq_le {f z : ℝ → ℝ} (hf : MemLp f 2 μ) (hz : MemLp z 2 μ) + (hmean : ∫ h, f h ∂μ = 0) : + (∫ h, f h*z h ∂μ)^2 ≤ sd μ z^2*(∫ h, f h^2 ∂μ) := by + have h := sq_le_sq₀ (abs_nonneg _) (mul_nonneg (l2Norm_nonneg f) (sd_nonneg z)) + |>.mpr (abs_pairing_centered_le hf hz hmean) + rw [sq_abs,mul_pow,l2Norm_sq] at h + simpa only [mul_comm] using h + +lemma l2_decomposition {f : ℝ → ℝ} (hf : MemLp f 2 μ) : + ∫ h, f h^2 ∂μ = (∫ h, f h ∂μ)^2+(∫ h, centered μ f h^2 ∂μ) := by + change ∫ h, f h^2 ∂μ = (∫ h, f h ∂μ)^2 + (∫ h, (f h-(∫ t, f t ∂μ))^2 ∂μ) + rw [integral_centered_sq hf] + ring + +lemma integral_mul_decomposition {b z : ℝ → ℝ} (hb : MemLp b 2 μ) (hz : MemLp z 2 μ) : + ∫ h, b h*z h ∂μ = (∫ h, b h ∂μ)*(∫ h, z h ∂μ) + + (∫ h, centered μ b h*z h ∂μ) := by + have hpair : Integrable (fun h => b h*z h) μ := hb.integrable_mul hz + have hzI : Integrable z μ := hz.integrable (by norm_num) + have he (h : ℝ) : centered μ b h*z h = b h*z h-(∫ t, b t ∂μ)*z h := by + unfold centered + ring + simp_rw [he] + rw [integral_sub hpair (hzI.const_mul _),integral_const_mul] + ring + +end Probability +end SKRatio.Scalar + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Variational/ScalarInterpolation.lean b/lean/OAI/Probability/SKRatio/Variational/ScalarInterpolation.lean new file mode 100644 index 0000000000000000000000000000000000000000..4fd80ecaf6994458f576d5b3c3297183e609b3ce --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Variational/ScalarInterpolation.lean @@ -0,0 +1,179 @@ +import Mathlib +import OAI.Probability.SKRatio.Variational.ScalarMonotone + +namespace OAI + +noncomputable section +open scoped Topology ENNReal NNReal +open MeasureTheory ProbabilityTheory Real +namespace SKRatio.Scalar + +lemma G_nonneg (β : ℝ) : 0 ≤ G β := by + apply integral_nonneg + intro h + exact div_nonneg (v_pos h).le (by linarith [w_pos h]) + +lemma l_temperature_monotone {β z : ℝ} (hβ : 0 < β) (hβz : β ≤ z) : l β ≤ l z := by + rw [l_eq,l_eq] + linarith [a_temperature_antitone hβ hβz] + +lemma memLp_F_other (β z : ℝ) : MemLp (F β) 2 (fieldLaw z) := by + convert! (((((memLp_field_v z).add ((memLp_field z).const_mul (a β))).add + (memLp_mv.const_mul (2*β^2))).add (memLp_v.const_mul (50/100-β^2*a β/l β))).add + (memLp_m.const_mul (12/100:ℝ))).add (memLp_g.const_mul (3*β^2*G β)) using 1 + ext h + dsimp [F] + ring + +lemma F_sub_F (β z h : ℝ) : F β h-F z h = + (a β-a z)*h+(2*(β^2-z^2))*(m h*v h)+ + (z^2*a z/l z-β^2*a β/l β)*v h+(3*(β^2*G β-z^2*G z))*g h := by + unfold F + ring + +lemma sd_F_difference (β z : ℝ) : sd (fieldLaw z) (fun h => F β h-F z h) ≤ + |a β-a z| *|z|+2*|β^2-z^2| *sd (fieldLaw z) (fun h => m h*v h)+ + |z^2*a z/l z-β^2*a β/l β| *sd (fieldLaw z) v+ + 3*|β^2*G β-z^2*G z| *sd (fieldLaw z) g := by + let A := fun h : ℝ => (a β-a z)*h + let B := fun h : ℝ => (2*(β^2-z^2))*(m h*v h) + let C := fun h : ℝ => (z^2*a z/l z-β^2*a β/l β)*v h + let D := fun h : ℝ => (3*(β^2*G β-z^2*G z))*g h + have hA : MemLp A 2 (fieldLaw z) := (memLp_field z).const_mul _ + have hB : MemLp B 2 (fieldLaw z) := memLp_mv.const_mul _ + have hC : MemLp C 2 (fieldLaw z) := memLp_v.const_mul _ + have hD : MemLp D 2 (fieldLaw z) := memLp_g.const_mul _ + have hAB : MemLp (fun h => A h+B h) 2 (fieldLaw z) := hA.add hB + have hABC : MemLp (fun h => A h+B h+C h) 2 (fieldLaw z) := hAB.add hC + have h1 := sd_add hA hB + have h2 := sd_add hAB hC + have h3 := sd_add hABC hD + have hsum : sd (fieldLaw z) (fun h => A h+B h+C h+D h) ≤ + sd (fieldLaw z) A+sd (fieldLaw z) B+sd (fieldLaw z) C+sd (fieldLaw z) D := by linarith + simp_rw [F_sub_F] + have hzsd : sd (fieldLaw z) (fun h : ℝ => h) = |z| := by + have hh := variance_id_gaussianReal (μ := z^2) (v := variance z) + rw [variance_eq_integral measurable_id.aemeasurable] at hh + change ∫ h, (h-(∫ t, t ∂fieldLaw z))^2 ∂fieldLaw z = _ at hh + rw [variance_coe] at hh + unfold sd l2Norm centered + rw [hh,sqrt_sq_eq_abs] + have hAsd : sd (fieldLaw z) A = |a β-a z| * |z| := by + change sd (fieldLaw z) (fun h => (a β-a z)*(fun x : ℝ => x) h) = _ + rw [sd_const_mul,hzsd] + rw [hAsd] at hsum + dsimp [B,C,D] at hsum + simp only [sd_const_mul,abs_mul,show |(2:ℝ)|=2 from by norm_num, + show |(3:ℝ)|=3 from by norm_num] at hsum + exact hsum + +lemma abs_sub_le_interval {x y L U : ℝ} (hxL : L ≤ x) (hxU : x ≤ U) + (hyL : L ≤ y) (hyU : y ≤ U) : |x-y| ≤ U-L := by + exact abs_le.mpr ⟨by linarith,by linarith⟩ + +lemma temp_a_ratio_bounds {j β z : ℝ} (hj : 0 < j) (hjβ : j ≤ β) (hβz : β ≤ z) : + j^2*a z/l z ≤ β^2*a β/l β ∧ β^2*a β/l β ≤ z^2*a j/l j := by + have hβ : 0 < β := hj.trans_le hjβ + have ha1 := a_temperature_antitone hj hjβ + have ha2 := a_temperature_antitone hβ hβz + have hl1 := l_temperature_monotone hj hjβ + have hl2 := l_temperature_monotone hβ hβz + have hb1 : j^2*a z ≤ β^2*a β := mul_le_mul (by nlinarith) ha2 (a_nonneg _) (sq_nonneg _) + have hb2 : β^2*a β ≤ z^2*a j := mul_le_mul (by nlinarith) ha1 (a_nonneg _) (sq_nonneg _) + exact ⟨(div_le_div_of_nonneg_left (mul_nonneg (sq_nonneg _) (a_nonneg _)) (l_pos β) hl2).trans + (div_le_div_of_nonneg_right hb1 (l_pos β).le), + (div_le_div_of_nonneg_right hb2 (l_pos β).le).trans + (div_le_div_of_nonneg_left (mul_nonneg (sq_nonneg _) (a_nonneg _)) (l_pos j) hl1)⟩ + +lemma temp_G_bounds {j β z : ℝ} (hj : 0 < j) (hjβ : j ≤ β) (hβz : β ≤ z) : + j^2*G z ≤ β^2*G β ∧ β^2*G β ≤ z^2*G j := by + have hβ : 0 < β := hj.trans_le hjβ + exact ⟨mul_le_mul (by nlinarith) (G_temperature_antitone hβ hβz) (G_nonneg _) (sq_nonneg _), + mul_le_mul (by nlinarith) (G_temperature_antitone hj hjβ) (G_nonneg _) (sq_nonneg _)⟩ + +def crossBound (j z : ℝ) : ℝ := sqrt (densityFactor j z)* + (sd (fieldLaw z) (F z)+(a j-a z)*z+ + 2*(z^2-j^2)*sd (fieldLaw z) (fun h => m h*v h)+ + (z^2*a j/l j-j^2*a z/l z)*sd (fieldLaw z) v+ + 3*(z^2*G j-j^2*G z)*sd (fieldLaw z) g) + +theorem sd_F_interval {j β z : ℝ} (hj : 0 < j) (hjβ : j ≤ β) (hβz : β ≤ z) : + sd (fieldLaw β) (F β) ≤ crossBound j z := by + have hβ : 0 < β := hj.trans_le hjβ + have hz : 0 < z := hβ.trans_le hβz + have hfchg := sd_temperature_interval_bound hj hjβ hβz (memLp_F β) (memLp_F_other β z) + have hfd := sd_F_difference β z + have hftriangle := abs_sd_sub_le (memLp_F_other β z) (memLp_F z) + have haβ := a_temperature_antitone hβ hβz + have haj := a_temperature_antitone hj hjβ + have ha : |a β-a z| ≤ a j-a z := by rw [abs_of_nonneg (sub_nonneg.mpr haβ)]; linarith + have hsqβ : β^2 ≤ z^2 := by nlinarith + have hj2 : j^2 ≤ β^2 := by nlinarith + have hb : |β^2-z^2| ≤ z^2-j^2 := by rw [abs_of_nonpos (sub_nonpos.mpr hsqβ)]; linarith + have hal1 := temp_a_ratio_bounds hj hjβ hβz + have hal2 := temp_a_ratio_bounds hj (hjβ.trans hβz) (le_refl z) + have hc := abs_sub_le_interval hal2.1 hal2.2 hal1.1 hal1.2 + have hgl1 := temp_G_bounds hj hjβ hβz + have hgl2 := temp_G_bounds hj (hjβ.trans hβz) (le_refl z) + have hd := abs_sub_le_interval hgl1.1 hgl1.2 hgl2.1 hgl2.2 + rw [abs_of_pos hz] at hfd + have hupper : sd (fieldLaw z) (F β) ≤ + sd (fieldLaw z) (F z)+(a j-a z)*z+ + 2*(z^2-j^2)*sd (fieldLaw z) (fun h => m h*v h)+ + (z^2*a j/l j-j^2*a z/l z)*sd (fieldLaw z) v+ + 3*(z^2*G j-j^2*G z)*sd (fieldLaw z) g := by + have hat := mul_le_mul_of_nonneg_right ha hz.le + have hbt := mul_le_mul_of_nonneg_right hb (sd_nonneg (μ := fieldLaw z) (fun h => m h*v h)) + have hct := mul_le_mul_of_nonneg_right hc (sd_nonneg (μ := fieldLaw z) v) + have hdt := mul_le_mul_of_nonneg_right hd (sd_nonneg (μ := fieldLaw z) g) + have htri := (le_abs_self _).trans hftriangle + nlinarith only [hfd,htri,hat,hbt,hct,hdt] + exact hfchg.trans (mul_le_mul_of_nonneg_left hupper (sqrt_nonneg _)) + +def slackBound₀ (j z : ℝ) : ℝ := l j+18/1000+ + j^2*(a z^2/l z-a z-(3/2)*G j^2)-z^2*R z + +def slackBound₁ (j z : ℝ) : ℝ := 4644/10000-z*sd (fieldLaw z) v/2+ + j^2*(∫ h, m h*v h ∂fieldLaw j)-z^2*((3/2)*sd (fieldLaw z) g^2+R z) + +theorem U₁_interval {j β z : ℝ} (hj : 0 < j) (hjβ : j ≤ β) (hβz : β ≤ z) (hz : z ≤ 1) : + slackBound₁ j z ≤ U₁ β := by + have hβ : 0 < β := hj.trans_le hjβ + have hv := weighted_sd_temperature_mono' hβ hβz hz memLp_v memLp_v + have hm := weighted_mv_temperature_mono hj hjβ (hβz.trans hz) + have hg := weighted_sd_temperature_mono hβ hβz hz memLp_g memLp_g + have hr := weighted_R_temperature_mono hβ hβz hz + unfold slackBound₁ U₁ + nlinarith only [hv,hm,hg,hr] + +lemma coherent_a_slack_mono {x y t : ℝ} (ht : 0 < t) (_hy : 0 ≤ y) + (hyx : y ≤ x) (hreg : t ≤ 2*y) : y^2/t-y ≤ x^2/t-x := by + apply (mul_le_mul_iff_of_pos_right ht).mp + field_simp + have hp := mul_nonneg (sub_nonneg.mpr hyx) (show 0 ≤ x+y-t by linarith) + nlinarith only [hp] + +theorem U₀_interval {j β z : ℝ} (hj : 0 < j) (hjβ : j ≤ β) (hβz : β ≤ z) (hz : z ≤ 1) + (hreg : l z ≤ 2*a z) (hc : 0 ≤ a z^2/l z-a z-(3/2)*G j^2) : + slackBound₀ j z ≤ U₀ β := by + have hβ : 0 < β := hj.trans_le hjβ + have hj2 : j^2 ≤ β^2 := by nlinarith + have ha := a_temperature_antitone hβ hβz + have hg := G_temperature_antitone hj hjβ + have hl1 := l_temperature_monotone hj hjβ + have hl2 := l_temperature_monotone hβ hβz + have hh1 := coherent_a_slack_mono (l_pos z) (a_nonneg z) ha hreg + have hh2 := div_le_div_of_nonneg_left (sq_nonneg (a β)) (l_pos β) hl2 + have hg2 : G β^2 ≤ G j^2 := (sq_le_sq₀ (G_nonneg β) (G_nonneg j)).mpr hg + have hcoef : a z^2/l z-a z-(3/2)*G j^2 ≤ a β^2/l β-a β-(3/2)*G β^2 := by + linarith + have hprod := mul_le_mul hj2 hcoef hc (sq_nonneg β) + have hr := weighted_R_temperature_mono hβ hβz hz + unfold slackBound₀ U₀ + linarith + +end SKRatio.Scalar + +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Variational/ScalarKernel.lean b/lean/OAI/Probability/SKRatio/Variational/ScalarKernel.lean new file mode 100644 index 0000000000000000000000000000000000000000..aff45b3fd5a993ec7884d03be18ff417fc298bc9 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Variational/ScalarKernel.lean @@ -0,0 +1,209 @@ +import Mathlib + +namespace OAI + +section +noncomputable section +open scoped BigOperators Topology +open MeasureTheory ProbabilityTheory Real +namespace SKRatio.Scalar + +def m (h : ℝ) : ℝ := tanh h +def v (h : ℝ) : ℝ := 1 - m h ^ 2 +def w (h : ℝ) : ℝ := 1 - m h +def kernel (h t : ℝ) : ℝ := v h * v t / (w h + w t) +def g (h : ℝ) : ℝ := v h / (w h + 3/4) +def q (h : ℝ) : ℝ := (w h - 3/4) / (w h + 3/4) +def rho (h : ℝ) : ℝ := (1+m h)*v h/2 - (3/2)*g h^2 + +lemma m_bounds (h : ℝ) : -1 < m h ∧ m h < 1 := + ⟨neg_one_lt_tanh h, tanh_lt_one h⟩ +lemma v_pos (h : ℝ) : 0 < v h := sub_pos.mpr (tanh_sq_lt_one h) +lemma v_le_one (h : ℝ) : v h ≤ 1 := by dsimp [v]; nlinarith [sq_nonneg (m h)] +lemma w_pos (h : ℝ) : 0 < w h := sub_pos.mpr (m_bounds h).2 +lemma v_factor (h : ℝ) : v h = w h * (1+m h) := by unfold v w; ring +lemma kernel_nonneg (h t : ℝ) : 0 ≤ kernel h t := + div_nonneg (mul_nonneg (v_pos h).le (v_pos t).le) (add_pos (w_pos h) (w_pos t)).le +lemma kernel_diag (h : ℝ) : kernel h h = (1+m h)*v h/2 := by + unfold kernel + nth_rw 1 [v_factor h] + have hw := (w_pos h).ne' + field_simp + ring + +lemma kernel_diag_le_one (h : ℝ) : kernel h h ≤ 1 := by + rw [kernel_diag] + have hm := (m_bounds h).2.le + have hv := v_le_one h + have hv0 := (v_pos h).le + nlinarith [(mul_le_mul_of_nonneg_right (show 1+m h ≤ 2 by linarith) hv0)] + +lemma kernel_square_le (h t : ℝ) : kernel h t^2 ≤ kernel h h * kernel t t := by + have ha := w_pos h + have hb := w_pos t + have hab : 0 < w h+w t := add_pos ha hb + unfold kernel + rw [div_pow,div_mul_div_comm] + apply (div_le_div_iff₀ (sq_pos_of_pos hab) (mul_pos (add_pos ha ha) (add_pos hb hb))).mpr + have hh := mul_nonneg (sq_nonneg (v h*v t)) (sq_nonneg (w h-w t)) + nlinarith only [hh] + +lemma abs_kernel_le_one (h t : ℝ) : |kernel h t| ≤ 1 := by + rw [abs_of_nonneg (kernel_nonneg h t)] + have hs := kernel_square_le h t + have hd := mul_le_mul (kernel_diag_le_one h) (kernel_diag_le_one t) + (kernel_nonneg t t) (by norm_num : (0:ℝ) ≤ 1) + nlinarith [sq_nonneg (kernel h t-1)] + +lemma residual_identity (h t : ℝ) : + kernel h t - (3/2)*g h*g t = kernel h t*q h*q t := by + have hht := (add_pos (w_pos h) (w_pos t)).ne' + have hh : w h+3/4 ≠ 0 := by linarith [w_pos h] + have ht : w t+3/4 ≠ 0 := by linarith [w_pos t] + unfold kernel g q + have hh4 : w h*4+3 ≠ 0 := by linarith [w_pos h] + have ht4 : w t*4+3 ≠ 0 := by linarith [w_pos t] + field_simp [hht,hh4,ht4] + ring + +lemma rho_eq (h : ℝ) : rho h = kernel h h * q h^2 := by + have hh := residual_identity h h + rw [kernel_diag] at hh + unfold rho + rw [kernel_diag] + nlinarith only [hh] + +lemma rho_nonneg (h : ℝ) : 0 ≤ rho h := by + rw [rho_eq] + exact mul_nonneg (kernel_nonneg h h) (sq_nonneg (q h)) + +lemma rho_le_one (h : ℝ) : rho h ≤ 1 := by + have hi := kernel_diag_le_one h + rw [kernel_diag] at hi + unfold rho + nlinarith [sq_nonneg (g h)] + +lemma abs_g_le_one (h : ℝ) : |g h| ≤ 1 := by + have hi := kernel_diag_le_one h + rw [kernel_diag] at hi + have hr := rho_nonneg h + unfold rho at hr + rw [abs_le] + constructor <;> nlinarith [sq_nonneg (g h+1),sq_nonneg (g h-1)] + +lemma abs_residual_le (h t : ℝ) : + |kernel h t - (3/2)*g h*g t| ≤ sqrt (rho h)*sqrt (rho t) := by + have hs := mul_le_mul_of_nonneg_right (kernel_square_le h t) + (mul_nonneg (sq_nonneg (q h)) (sq_nonneg (q t))) + have hsq : (kernel h t - (3/2)*g h*g t)^2 ≤ rho h*rho t := by + rw [residual_identity,rho_eq h,rho_eq t] + nlinarith only [hs] + have hprod : 0 ≤ sqrt (rho h)*sqrt (rho t) := mul_nonneg (sqrt_nonneg _) (sqrt_nonneg _) + apply (sq_le_sq₀ (abs_nonneg _) hprod).mp + rw [sq_abs,mul_pow,sq_sqrt (rho_nonneg h),sq_sqrt (rho_nonneg t)] + exact hsq + +lemma continuous_m : Continuous m := by + unfold m + simp_rw [tanh_eq_sinh_div_cosh] + exact Continuous.div Real.continuous_sinh Real.continuous_cosh (fun h => ne_of_gt (Real.cosh_pos h)) +lemma continuous_v : Continuous v := continuous_const.sub (continuous_m.pow 2) +lemma continuous_w : Continuous w := continuous_const.sub continuous_m +lemma continuous_g : Continuous g := by + apply continuous_v.div (continuous_w.add continuous_const) + intro h + change w h+3/4 ≠ 0 + linarith [w_pos h] +lemma continuous_kernel : Continuous (Function.uncurry kernel) := by + apply ((continuous_v.comp continuous_fst).mul (continuous_v.comp continuous_snd)).div + ((continuous_w.comp continuous_fst).add (continuous_w.comp continuous_snd)) + intro x + exact (add_pos (w_pos x.1) (w_pos x.2)).ne' +lemma continuous_rho : Continuous rho := + (((continuous_const.add continuous_m).mul continuous_v).div_const 2).sub + ((continuous_g.pow 2).const_mul (3/2)) + +section Integration +variable {μ : Measure ℝ} [IsProbabilityMeasure μ] + +lemma memLp_g : MemLp g 2 μ := by + apply (memLp_const (1:ℝ)).of_le_mul continuous_g.aestronglyMeasurable + (c := (1:ℝ)) + exact Filter.Eventually.of_forall (fun h => by simpa using abs_g_le_one h) + +lemma memLp_sqrt_rho : MemLp (fun h => sqrt (rho h)) 2 μ := by + apply (memLp_const (1:ℝ)).of_le_mul + (continuous_sqrt.comp continuous_rho).aestronglyMeasurable (c := (1:ℝ)) + apply Filter.Eventually.of_forall + intro h + simp only [Function.comp_apply,Real.norm_eq_abs,abs_one,mul_one,abs_of_nonneg (sqrt_nonneg _)] + exact (sqrt_le_one).mpr (rho_le_one h) + +lemma integrable_rho : Integrable rho μ := by + exact ((integrable_const (1:ℝ)).mono' continuous_rho.aestronglyMeasurable + (Filter.Eventually.of_forall (fun h => by + simpa only [Real.norm_eq_abs,abs_of_nonneg (rho_nonneg h)] using rho_le_one h))) + +lemma integral_abs_mul_sq_le {α : Type*} [MeasurableSpace α] {ν : Measure α} + {f z : α → ℝ} (hf : MemLp f 2 ν) (hz : MemLp z 2 ν) : + (∫ x, |f x| *|z x| ∂ν)^2 ≤ (∫ x, f x^2 ∂ν)*(∫ x, z x^2 ∂ν) := by + have hb := integral_mul_norm_le_Lp_mul_Lq Real.HolderConjugate.two_two + (by simpa using hf) (by simpa using hz) + simp only [Real.rpow_two,Real.norm_eq_abs,sq_abs,←Real.sqrt_eq_rpow] at hb + have ha : 0 ≤ ∫ x, |f x| *|z x| ∂ν := integral_nonneg (fun x => mul_nonneg (abs_nonneg _) (abs_nonneg _)) + have hs := sq_le_sq₀ ha (mul_nonneg (sqrt_nonneg _) (sqrt_nonneg _)) |>.mpr hb + simpa only [mul_pow,sq_sqrt (integral_nonneg (fun x => sq_nonneg (f x))), + sq_sqrt (integral_nonneg (fun x => sq_nonneg (z x)))] using hs + +lemma kernel_pair_integrable {b : ℝ → ℝ} (hb : MemLp b 2 μ) : + Integrable (fun z : ℝ×ℝ => b z.1 * kernel z.1 z.2 * b z.2) (μ.prod μ) := by + have hI := hb.integrable (by norm_num : (1:ENNReal) ≤ 2) + apply (hI.norm.mul_prod hI.norm).mono' + ((hb.aestronglyMeasurable.comp_fst.mul continuous_kernel.aestronglyMeasurable).mul + hb.aestronglyMeasurable.comp_snd) + apply Filter.Eventually.of_forall + intro z + change |b z.1*kernel z.1 z.2*b z.2| ≤ |b z.1| * |b z.2| + simp only [abs_mul] + calc + |b z.1| *|kernel z.1 z.2| *|b z.2| ≤ |b z.1| *1*|b z.2| := by + gcongr + exact abs_kernel_le_one _ _ + _ = |b z.1| *|b z.2| := by ring + +theorem kernel_bound {b : ℝ → ℝ} (hb : MemLp b 2 μ) : + ∫ z : ℝ×ℝ, b z.1*kernel z.1 z.2*b z.2 ∂μ.prod μ ≤ + (3/2)*(∫ h, b h*g h ∂μ)^2 + + (∫ h, rho h ∂μ)*(∫ h, b h^2 ∂μ) := by + have hbg : Integrable (fun h => b h*g h) μ := hb.integrable_mul memLp_g + have hbr : Integrable (fun h => |b h| *sqrt (rho h)) μ := + hb.norm.integrable_mul memLp_sqrt_rho + have hmain := (hbg.mul_prod hbg).const_mul (3/2:ℝ) + have hrem := hbr.mul_prod hbr + have him := integral_mono (kernel_pair_integrable hb) (hmain.add hrem) + (fun z => show b z.1*kernel z.1 z.2*b z.2 ≤ + (3/2)*((b z.1*g z.1)*(b z.2*g z.2)) + + (|b z.1| *sqrt (rho z.1))*(|b z.2| *sqrt (rho z.2)) from by + have ha := mul_le_mul_of_nonneg_left (abs_residual_le z.1 z.2) + (mul_nonneg (abs_nonneg (b z.1)) (abs_nonneg (b z.2))) + have hh := le_abs_self (b z.1*(kernel z.1 z.2-(3/2)*g z.1*g z.2)*b z.2) + simp only [abs_mul] at hh + nlinarith only [ha,hh]) + simp only [Pi.add_apply] at him + rw [integral_add hmain hrem,integral_const_mul, + integral_prod_mul (fun h => b h*g h) (fun h => b h*g h), + integral_prod_mul (fun h => |b h| * sqrt (rho h)) (fun h => |b h| * sqrt (rho h))] at him + have hcs := integral_abs_mul_sq_le hb (memLp_sqrt_rho (μ := μ)) + simp only [abs_of_nonneg (sqrt_nonneg _),sq_sqrt (rho_nonneg _)] at hcs + nlinarith only [him,hcs] + +omit [IsProbabilityMeasure μ] in +lemma integral_rho_nonneg : 0 ≤ ∫ h, rho h ∂μ := integral_nonneg rho_nonneg + +end Integration +end SKRatio.Scalar + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Variational/ScalarMoments.lean b/lean/OAI/Probability/SKRatio/Variational/ScalarMoments.lean new file mode 100644 index 0000000000000000000000000000000000000000..69221d924168c6b4421e1bba5744ab49e8afad9d --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Variational/ScalarMoments.lean @@ -0,0 +1,206 @@ +import Mathlib +import OAI.Probability.SKRatio.Matrices.StandardGaussianProduct +import OAI.Probability.SKRatio.Gaussian.Planted +import OAI.Probability.SKRatio.Variational.ScalarKernel + +namespace OAI + +section +noncomputable section +open scoped Topology NNReal ENNReal +open MeasureTheory ProbabilityTheory Real +namespace SKRatio.Scalar + +def variance (β : ℝ) : ℝ≥0 := Real.toNNReal (β^2) + +@[simp] lemma variance_coe (β : ℝ) : (variance β : ℝ) = β^2 := + Real.coe_toNNReal _ (sq_nonneg β) + +def fieldLaw (β : ℝ) : Measure ℝ := gaussianReal (β^2) (variance β) +instance (β : ℝ) : IsProbabilityMeasure (fieldLaw β) := by + unfold fieldLaw + infer_instance + +lemma memLp_m {μ : Measure ℝ} [IsFiniteMeasure μ] {p : ENNReal} : MemLp m p μ := by + apply MemLp.of_bound continuous_m.aestronglyMeasurable 1 + exact ae_of_all _ (fun h => by simpa only [Real.norm_eq_abs] using (abs_lt.mpr (m_bounds h)).le) + +lemma memLp_v {μ : Measure ℝ} [IsFiniteMeasure μ] {p : ENNReal} : MemLp v p μ := by + apply MemLp.of_bound continuous_v.aestronglyMeasurable 1 + exact ae_of_all _ (fun h => by simpa only [Real.norm_eq_abs,abs_of_nonneg (v_pos h).le] using v_le_one h) + +lemma memLp_mv {μ : Measure ℝ} [IsFiniteMeasure μ] {p : ENNReal} : + MemLp (fun h => m h*v h) p μ := by + apply MemLp.of_bound (continuous_m.mul continuous_v).aestronglyMeasurable 1 + apply ae_of_all + intro h + change |m h*v h| ≤ 1 + rw [abs_mul,abs_of_nonneg (v_pos h).le] + exact (mul_le_mul (abs_lt.mpr (m_bounds h)).le (v_le_one h) + (v_pos h).le (by norm_num : (0:ℝ) ≤ 1)).trans_eq (by ring) + +lemma tilted_integral (β : ℝ) (f : ℝ → ℝ) : + ∫ h, f h ∂fieldLaw β = + ∫ h, exp (h-β^2/2)*f h ∂gaussianReal 0 (variance β) := by + have he := Planted.gaussianReal_tilt 0 (variance β) 1 + simp only [one_mul,mul_zero,one_pow,mul_one,zero_add,variance_coe] at he + rw [fieldLaw,←he,integral_withDensity_eq_integral_toReal_smul (by fun_prop) + (ae_of_all _ (fun h => ENNReal.ofReal_lt_top))] + simp only [ENNReal.toReal_ofReal (exp_pos _).le,smul_eq_mul] + +lemma centered_gaussian_integral_neg (s : ℝ≥0) (f : ℝ → ℝ) : + ∫ h, f (-h) ∂gaussianReal 0 s = ∫ h, f h ∂gaussianReal 0 s := by + have hp : MeasurePreserving (fun h : ℝ => -h) (gaussianReal 0 s) (gaussianReal 0 s) := + ⟨measurable_neg,by simpa using (gaussianReal_map_neg (μ := 0) (v := s))⟩ + exact hp.integral_comp (Homeomorph.neg ℝ).measurableEmbedding f + +lemma tilted_odd_integrand (h : ℝ) : + exp h*(m h-m h^2) = -(exp (-h)*(m (-h)-m (-h)^2)) := by + have hh := Calculus.exp_two_mul_one_sub_tanh h + have hp := exp_pos h + simp only [show 2*h=h+h by ring,exp_add,m,tanh_neg,neg_sq] at hh ⊢ + rw [exp_neg] + field_simp + nlinarith only [hh, mul_eq_mul_right_iff.mp (congrArg (fun t : ℝ => t*tanh h) hh)] + +theorem sign_identity (β : ℝ) (F : ℝ → ℝ) (hF : Measurable F) + (heven : ∀ h, F (-h) = F h) {C : ℝ} (hC : ∀ h, |F h| ≤ C) : + ∫ h, m h*F h ∂fieldLaw β = ∫ h, m h^2*F h ∂fieldLaw β := by + have hFlp : MemLp F 2 (fieldLaw β) := MemLp.of_bound hF.aestronglyMeasurable C + (ae_of_all _ (fun h => by simpa only [Real.norm_eq_abs] using hC h)) + have h1 : Integrable (fun h => m h*F h) (fieldLaw β) := (memLp_m (p := 2)).integrable_mul hFlp + have hm2 : MemLp (fun h => m h^2) 2 (fieldLaw β) := by + apply MemLp.of_bound (continuous_m.pow 2).aestronglyMeasurable 1 + exact ae_of_all _ (fun h => by + change |m h^2| ≤ 1 + rw [abs_of_nonneg (sq_nonneg _)] + exact (tanh_sq_lt_one h).le) + have h2 : Integrable (fun h => m h^2*F h) (fieldLaw β) := hm2.integrable_mul hFlp + suffices hz : ∫ h, m h*F h-m h^2*F h ∂fieldLaw β = 0 by + rw [integral_sub h1 h2] at hz + linarith + rw [tilted_integral] + let A : ℝ → ℝ := fun h => exp (h-β^2/2)*(m h*F h-m h^2*F h) + have ha (h : ℝ) : A (-h) = -A h := by + have hh := tilted_odd_integrand h + dsimp [A] + rw [heven h,exp_sub,exp_sub] + have hd := (exp_pos (β^2/2)).ne' + apply (mul_right_cancel₀ hd) + field_simp + have hhh := congrArg (fun t : ℝ => t*F h) hh + nlinarith only [hhh] + have hi := centered_gaussian_integral_neg (variance β) A + simp_rw [ha,integral_neg] at hi + change ∫ h, A h ∂gaussianReal 0 (variance β) = 0 + linarith + +lemma mean_m_eq_mean_m_sq (β : ℝ) : + ∫ h, m h ∂fieldLaw β = ∫ h, m h^2 ∂fieldLaw β := by + simpa using sign_identity β (fun _ => (1:ℝ)) measurable_const (fun _ => rfl) + (C := 1) (fun _ => by norm_num) + +lemma mean_mv_eq_mean_m_sq_v (β : ℝ) : + ∫ h, m h*v h ∂fieldLaw β = ∫ h, m h^2*v h ∂fieldLaw β := by + apply sign_identity β v continuous_v.measurable + · intro h + simp [v,m,tanh_neg] + · intro h + simpa only [abs_of_nonneg (v_pos h).le] using v_le_one h + +lemma mean_mv_nonneg (β : ℝ) : 0 ≤ ∫ h, m h*v h ∂fieldLaw β := by + rw [mean_mv_eq_mean_m_sq_v] + exact integral_nonneg (fun h => mul_nonneg (sq_nonneg _) (v_pos h).le) + +lemma memLp_field (β : ℝ) : MemLp (fun h : ℝ => h) 2 (fieldLaw β) := + memLp_id_gaussianReal 2 + +lemma memLp_field_v (β : ℝ) : MemLp (fun h : ℝ => h*v h) 2 (fieldLaw β) := by + apply (memLp_field β).of_le_mul + (continuous_id.mul continuous_v).aestronglyMeasurable (c := (1:ℝ)) + apply ae_of_all + intro h + change |h*v h| ≤ 1*|h| + simp only [abs_mul,one_mul,abs_of_nonneg (v_pos h).le] + exact mul_le_of_le_one_right (abs_nonneg _) (v_le_one h) + +lemma v_hasDerivAt (h : ℝ) : HasDerivAt v (-2*m h*v h) h := by + convert! (hasDerivAt_const h (1:ℝ)).sub ((Calculus.hasDerivAt_tanh h).pow 2) using 1 + simp only [v,m,Nat.cast_ofNat,show 2-1=1 from rfl,pow_one] + ring + +theorem field_variance_identity (β : ℝ) : + ∫ h, (h-β^2+2*β^2*m h)*v h ∂fieldLaw β = 0 := by + by_cases hβ : β = 0 + · subst β + have he : fieldLaw 0 = Measure.dirac 0 := by + unfold fieldLaw + norm_num [variance] + rw [he] + simp [m,v] + have hs : ((variance β) : ℝ≥0) ≠ 0 := by + intro h + have hh := congrArg (fun x : ℝ≥0 => (x:ℝ)) h + exact hβ (by simpa only [variance_coe,NNReal.coe_zero,pow_eq_zero_iff (by decide : (2:ℕ) ≠ 0)] using hh) + have hvI : Integrable v (fieldLaw β) := memLp_v.integrable (by norm_num : (1:ENNReal) ≤ 2) + have hmvI : Integrable (fun h => m h*v h) (fieldLaw β) := + memLp_mv.integrable (by norm_num : (1:ENNReal) ≤ 2) + have hhvI : Integrable (fun h => h*v h) (fieldLaw β) := + (memLp_field_v β).integrable (by norm_num) + have hvder : Integrable (fun h => -2*m h*v h) (fieldLaw β) := by + simpa only [mul_assoc] using hmvI.const_mul (-2:ℝ) + have hcenter : Integrable (fun h => (h-β^2)*v h) (fieldLaw β) := by + convert! hhvI.sub (hvI.const_mul (β^2)) using 1 + ext h + dsimp + ring + have hh := SKRatioGaussian.gaussian_integration_by_parts hs v_hasDerivAt hvI hvder hcenter + have hexp (h : ℝ) : (h-β^2+2*β^2*m h)*v h = (h-β^2)*v h+(2*β^2)*(m h*v h) := by ring + simp_rw [hexp] + rw [integral_add hcenter (hmvI.const_mul _),integral_const_mul] + have hsimp : (∫ h, (h-β^2)*v h ∂fieldLaw β) = + β^2*((-2)*(∫ h, m h*v h ∂fieldLaw β)) := by + simpa only [fieldLaw,variance_coe,mul_assoc,integral_const_mul] using hh + rw [hsimp] + ring + +def multiplier (h : ℝ) : ℝ := 45/100 + (1/4)*m h^2 - (6/100)*m h + +lemma multiplier_pos (h : ℝ) : 4464/10000 ≤ multiplier h := by + unfold multiplier + nlinarith [sq_nonneg (m h-12/100)] + +lemma multiplier_le (h : ℝ) : multiplier h ≤ 76/100 := by + unfold multiplier + have hm := m_bounds h + have hs := (tanh_sq_lt_one h).le + change m h^2 ≤ 1 at hs + nlinarith + +lemma continuous_multiplier : Continuous multiplier := by + exact (continuous_const.add ((continuous_m.pow 2).const_mul (1/4))).sub + (continuous_m.const_mul (6/100)) + +lemma mean_multiplier (β : ℝ) : + ∫ h, multiplier h ∂fieldLaw β = 64/100-(19/100)*(∫ h, v h ∂fieldLaw β) := by + have hmI : Integrable m (fieldLaw β) := memLp_m.integrable (by norm_num : (1:ENNReal) ≤ 2) + have hm2I : Integrable (fun h => m h^2) (fieldLaw β) := memLp_m.integrable_sq + have hv : (∫ h, v h ∂fieldLaw β) = 1-∫ h, m h^2 ∂fieldLaw β := by + unfold v + rw [integral_sub (integrable_const 1) hm2I,integral_const] + simp + have hsum : Integrable (fun h => 45/100+(1/4)*m h^2) (fieldLaw β) := by + exact (integrable_const (45/100:ℝ)).add (hm2I.const_mul (1/4:ℝ)) + unfold multiplier + rw [integral_sub hsum (hmI.const_mul _), + integral_add (integrable_const _) (hm2I.const_mul _),integral_const_mul,integral_const_mul, + integral_const,mean_m_eq_mean_m_sq,hv] + simp only [probReal_univ,smul_eq_mul,one_mul] + ring + +end SKRatio.Scalar + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Variational/ScalarMonotone.lean b/lean/OAI/Probability/SKRatio/Variational/ScalarMonotone.lean new file mode 100644 index 0000000000000000000000000000000000000000..15f6396b1bf006438b1230a5805e19bdddb84294 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Variational/ScalarMonotone.lean @@ -0,0 +1,240 @@ +import Mathlib +import OAI.Probability.SKRatio.Variational.ScalarDensity + +namespace OAI + +noncomputable section +open scoped Topology ENNReal NNReal +open MeasureTheory ProbabilityTheory Real +namespace SKRatio.Scalar + +section Covariance +variable {μ : Measure ℝ} [IsProbabilityMeasure μ] + +lemma covariance_nonpos_of_pairwise {f r : ℝ → ℝ} + (hf : Integrable f μ) (hr : Integrable r μ) + (hfr : Integrable (fun x => f x*r x) μ) + (hsign : ∀ x y, (f x-f y)*(r x-r y) ≤ 0) : + (∫ x, f x*r x ∂μ) ≤ (∫ x, f x ∂μ)*(∫ x, r x ∂μ) := by + have hpoint (x : ℝ) : + f x*r x-f x*(∫ y, r y ∂μ)-r x*(∫ y, f y ∂μ)+(∫ y, f y*r y ∂μ) ≤ 0 := by + have hc1 : Integrable (fun y => f x*r x-f x*r y) μ := + (integrable_const _).sub (hr.const_mul _) + have hc : Integrable (fun y => f x*r x-f x*r y-r x*f y) μ := + hc1.sub (hf.const_mul _) + have he (y : ℝ) : (f x-f y)*(r x-r y) = f x*r x-f x*r y-r x*f y+f y*r y := by ring + have hi := integral_nonpos (μ := μ) (hsign x) + simp_rw [he] at hi + rw [integral_add hc hfr, + integral_sub hc1 (hf.const_mul _), + integral_sub (integrable_const _) (hr.const_mul _),integral_const_mul,integral_const_mul, + integral_const] at hi + simpa only [integral_const_mul,probReal_univ,smul_eq_mul,one_mul] using hi + have hh := integral_nonpos (μ := μ) hpoint + have hc1 : Integrable (fun x => f x*r x-f x*(∫ y, r y ∂μ)) μ := hfr.sub (hf.mul_const _) + have hc : Integrable (fun x => f x*r x-f x*(∫ y, r y ∂μ)-r x*(∫ y, f y ∂μ)) μ := + hc1.sub (hr.mul_const _) + rw [integral_add hc (integrable_const _), + integral_sub hc1 (hr.mul_const _), + integral_sub hfr (hf.mul_const _),integral_mul_const,integral_mul_const,integral_const] at hh + simp only [probReal_univ,smul_eq_mul,one_mul] at hh + nlinarith only [hh] +end Covariance + +def likelihood (β z h : ℝ) : ℝ := + (β/z)*exp ((β^2-z^2)/2+(1/(2*β^2)-1/(2*z^2))*h^2) + +lemma continuous_likelihood (β z : ℝ) : Continuous (likelihood β z) := by + unfold likelihood + fun_prop + +lemma likelihood_pos {β z : ℝ} (hβ : 0 < β) (hz : 0 < z) (h : ℝ) : + 0 < likelihood β z h := mul_pos (div_pos hβ hz) (exp_pos _) + +lemma fieldLaw_withDensity_likelihood {β z : ℝ} (hβ : 0 < β) (hz : 0 < z) : + (fieldLaw β).withDensity (fun h => ENNReal.ofReal (likelihood β z h)) = fieldLaw z := by + rw [fieldLaw,fieldLaw,gaussianReal_of_var_ne_zero _ (variance_ne_zero hβ), + gaussianReal_of_var_ne_zero _ (variance_ne_zero hz), + ←withDensity_mul _ (measurable_gaussianPDF _ _) ((continuous_likelihood β z).measurable.ennreal_ofReal)] + apply withDensity_congr_ae + apply ae_of_all + intro h + simp only [Pi.mul_apply,gaussianPDF,←ENNReal.ofReal_mul (gaussianPDFReal_nonneg _ _ _)] + congr 1 + exact (mul_comm _ _).trans (field_pdf_ratio hz hβ h).symm + +lemma integral_likelihood {β z : ℝ} (hβ : 0 < β) (hz : 0 < z) : + ∫ h, likelihood β z h ∂fieldLaw β = 1 := by + have hh := integral_const (μ := fieldLaw z) (1:ℝ) + rw [←fieldLaw_withDensity_likelihood hβ hz, + integral_withDensity_eq_integral_toReal_smul ((continuous_likelihood β z).measurable.ennreal_ofReal) + (ae_of_all _ (fun _ => ENNReal.ofReal_lt_top))] at hh + simpa only [ENNReal.toReal_ofReal (likelihood_pos hβ hz _).le,smul_eq_mul,mul_one, + fieldLaw_withDensity_likelihood hβ hz,probReal_univ,one_mul] using hh + +lemma likelihood_integrable_iff {β z : ℝ} (hβ : 0 < β) (hz : 0 < z) (f : ℝ → ℝ) : + Integrable f (fieldLaw z) ↔ Integrable (fun h => f h*likelihood β z h) (fieldLaw β) := by + rw [←fieldLaw_withDensity_likelihood hβ hz, + integrable_withDensity_iff ((continuous_likelihood β z).measurable.ennreal_ofReal) + (ae_of_all _ (fun _ => ENNReal.ofReal_lt_top))] + simp only [ENNReal.toReal_ofReal (likelihood_pos hβ hz _).le] + +lemma integral_mul_likelihood {β z : ℝ} (hβ : 0 < β) (hz : 0 < z) (f : ℝ → ℝ) : + ∫ h, f h*likelihood β z h ∂fieldLaw β = ∫ h, f h ∂fieldLaw z := by + rw [←fieldLaw_withDensity_likelihood hβ hz, + integral_withDensity_eq_integral_toReal_smul ((continuous_likelihood β z).measurable.ennreal_ofReal) + (ae_of_all _ (fun _ => ENNReal.ofReal_lt_top))] + simp only [ENNReal.toReal_ofReal (likelihood_pos hβ hz _).le,smul_eq_mul,mul_comm] + +lemma likelihood_mono_sq {β z : ℝ} (hβ : 0 < β) (hβz : β ≤ z) {x y : ℝ} (hxy : x^2 ≤ y^2) : + likelihood β z x ≤ likelihood β z y := by + have hz : 0 < z := hβ.trans_le hβz + have hi : 1/(2*z^2) ≤ 1/(2*β^2) := by + apply one_div_le_one_div_of_le (by positivity) + nlinarith + unfold likelihood + apply mul_le_mul_of_nonneg_left _ (div_pos hβ hz).le + apply exp_le_exp.mpr + nlinarith only [mul_le_mul_of_nonneg_left hxy (sub_nonneg.mpr hi)] + +lemma integral_temperature_antitone {β z : ℝ} (hβ : 0 < β) (hβz : β ≤ z) + {f : ℝ → ℝ} (hf : Integrable f (fieldLaw β)) (hf' : Integrable f (fieldLaw z)) + (hanti : ∀ x y : ℝ, x^2 ≤ y^2 → f y ≤ f x) : + ∫ h, f h ∂fieldLaw z ≤ ∫ h, f h ∂fieldLaw β := by + have hz : 0 < z := hβ.trans_le hβz + have hr : Integrable (likelihood β z) (fieldLaw β) := by + simpa only [one_mul] using (likelihood_integrable_iff hβ hz (fun _ => (1:ℝ))).mp (integrable_const _) + have hcov := covariance_nonpos_of_pairwise hf hr ((likelihood_integrable_iff hβ hz f).mp hf') + (fun x y => by + rcases le_total (x^2) (y^2) with hh|hh + · exact mul_nonpos_of_nonneg_of_nonpos (sub_nonneg.mpr (hanti x y hh)) + (sub_nonpos.mpr (likelihood_mono_sq hβ hβz hh)) + · exact mul_nonpos_of_nonpos_of_nonneg (sub_nonpos.mpr (hanti y x hh)) + (sub_nonneg.mpr (likelihood_mono_sq hβ hβz hh))) + simpa only [integral_mul_likelihood hβ hz,integral_likelihood hβ hz,mul_one] using hcov + +lemma m_mono : Monotone m := by + apply monotone_of_deriv_nonneg + (fun r => (Calculus.hasDerivAt_tanh r).differentiableAt) + intro r + rw [(Calculus.hasDerivAt_tanh r).deriv] + exact (v_pos r).le + +lemma m_nonneg {h : ℝ} (hh : 0 ≤ h) : 0 ≤ m h := by + have hh' := m_mono hh + simpa only [m,tanh_zero] using hh' + +lemma m_abs_sq (x : ℝ) : m |x|^2 = m x^2 := by + rcases le_total 0 x with h|h + · rw [abs_of_nonneg h] + · rw [abs_of_nonpos h] + simp only [m,tanh_neg,neg_sq] + +lemma m_sq_mono_sq {x y : ℝ} (hxy : x^2 ≤ y^2) : m x^2 ≤ m y^2 := by + rw [←m_abs_sq x,←m_abs_sq y] + exact (sq_le_sq₀ (m_nonneg (abs_nonneg _)) (m_nonneg (abs_nonneg _))).mpr + (m_mono (sq_le_sq.mp hxy)) + +lemma a_temperature_antitone {β z : ℝ} (hβ : 0 < β) (hβz : β ≤ z) : a z ≤ a β := by + apply integral_temperature_antitone hβ hβz + (memLp_v.integrable (by norm_num : (1:ENNReal) ≤ 2)) + (memLp_v.integrable (by norm_num : (1:ENNReal) ≤ 2)) + intro x y hxy + exact sub_le_sub_left (m_sq_mono_sq hxy) 1 + +def signMeanG (h : ℝ) : ℝ := (1-m h^2)*(7/4+m h^2)/((7/4)^2-m h^2) + +def gSignFactor (h : ℝ) : ℝ := v h/((7/4)^2-m h^2) + +lemma gSignFactor_denom (h : ℝ) : (2:ℝ) < (7/4)^2-m h^2 := by + have hh := tanh_sq_lt_one h + change m h^2 < 1 at hh + linarith + +lemma continuous_gSignFactor : Continuous gSignFactor := + continuous_v.div (continuous_const.sub (continuous_m.pow 2)) + (fun h => ne_of_gt (lt_trans (by norm_num : (0:ℝ) < 2) (gSignFactor_denom h))) + +lemma gSignFactor_abs_le (h : ℝ) : |gSignFactor h| ≤ 1 := by + have hd : 0 < (7/4)^2-m h^2 := lt_trans (by norm_num) (gSignFactor_denom h) + rw [gSignFactor,abs_of_nonneg (div_nonneg (v_pos h).le hd.le)] + apply (div_le_one hd).mpr + linarith [v_le_one h,gSignFactor_denom h] + +lemma memLp_gSignFactor {μ : Measure ℝ} [IsProbabilityMeasure μ] : MemLp gSignFactor 2 μ := + MemLp.of_bound continuous_gSignFactor.aestronglyMeasurable 1 + (ae_of_all _ (fun h => by simpa only [Real.norm_eq_abs] using gSignFactor_abs_le h)) + +lemma g_sign_expansion (h : ℝ) : + g h = (7/4)*gSignFactor h+m h*gSignFactor h := by + have hm := m_bounds h + have hd := gSignFactor_denom h + have h0 : (7/4:ℝ)-m h ≠ 0 := by linarith [hm.2] + have h1 : (7/4:ℝ)^2-m h^2 ≠ 0 := by linarith + calc + g h = v h/(7/4-m h) := by unfold g w; congr 1; ring + _ = ((7/4+m h)*v h)/((7/4)^2-m h^2) := + (div_eq_div_iff h0 h1).mpr (by ring) + _ = _ := by unfold gSignFactor; ring + +lemma signMeanG_expansion (h : ℝ) : + signMeanG h = (7/4)*gSignFactor h+m h^2*gSignFactor h := by + unfold signMeanG gSignFactor v + ring + +lemma memLp_signMeanG {μ : Measure ℝ} [IsProbabilityMeasure μ] : MemLp signMeanG 2 μ := by + have hi : MemLp (fun h => m h^2*gSignFactor h) 2 μ := by + apply memLp_gSignFactor.of_le_mul + ((continuous_m.pow 2).mul continuous_gSignFactor).aestronglyMeasurable (c := (1:ℝ)) + apply ae_of_all + intro h + change |m h^2*gSignFactor h| ≤ 1*|gSignFactor h| + rw [abs_mul,abs_of_nonneg (sq_nonneg _)] + exact mul_le_mul_of_nonneg_right (tanh_sq_lt_one h).le (abs_nonneg _) + convert! (memLp_gSignFactor.const_mul (7/4:ℝ)).add hi using 1 + exact funext signMeanG_expansion + +lemma G_eq_signMeanG (β : ℝ) : G β = ∫ h, signMeanG h ∂fieldLaw β := by + have hkey := sign_identity β gSignFactor continuous_gSignFactor.measurable + (fun h => by simp only [gSignFactor,v,m,tanh_neg,neg_sq]) gSignFactor_abs_le + have hf : Integrable gSignFactor (fieldLaw β) := memLp_gSignFactor.integrable (by norm_num) + have hmf : Integrable (fun h => m h*gSignFactor h) (fieldLaw β) := + (memLp_m (p := 2)).integrable_mul memLp_gSignFactor + have hm2f : Integrable (fun h => m h^2*gSignFactor h) (fieldLaw β) := by + have hi := memLp_signMeanG.integrable (μ := fieldLaw β) (by norm_num : (1:ENNReal) ≤ 2) + convert! hi.sub (hf.const_mul (7/4:ℝ)) using 1 + ext h + simp only [Pi.sub_apply,signMeanG_expansion] + ring + unfold G + simp_rw [g_sign_expansion,signMeanG_expansion] + rw [integral_add (hf.const_mul _) hmf,integral_add (hf.const_mul _) hm2f,hkey] + +lemma signMeanG_antitone_sq {x y : ℝ} (hxy : x^2 ≤ y^2) : signMeanG y ≤ signMeanG x := by + let u := m x^2 + let t := m y^2 + have hu : 0 ≤ u := sq_nonneg _ + have hut : u ≤ t := m_sq_mono_sq hxy + have ht : t ≤ 1 := (tanh_sq_lt_one y).le + have hdenu : 0 < (7/4)^2-u := by dsimp [u]; linarith [gSignFactor_denom x] + have hdent : 0 < (7/4)^2-t := by dsimp [t]; linarith [gSignFactor_denom y] + change (1-t)*(7/4+t)/((7/4)^2-t) ≤ (1-u)*(7/4+u)/((7/4)^2-u) + apply (div_le_div_iff₀ hdent hdenu).mpr + have hprod : 0 ≤ (t-u)*(35/64+(49/16)*(u+t)-u*t) := by + apply mul_nonneg (sub_nonneg.mpr hut) + have hh : u*t ≤ u := by nlinarith only [mul_nonneg hu (sub_nonneg.mpr ht)] + nlinarith only [hh,hu,hut] + nlinarith only [hprod] + +lemma G_temperature_antitone {β z : ℝ} (hβ : 0 < β) (hβz : β ≤ z) : G z ≤ G β := by + simp_rw [G_eq_signMeanG] + exact integral_temperature_antitone hβ hβz + (memLp_signMeanG.integrable (by norm_num : (1:ENNReal) ≤ 2)) + (memLp_signMeanG.integrable (by norm_num : (1:ENNReal) ≤ 2)) + (fun _ _ => signMeanG_antitone_sq) + +end SKRatio.Scalar + +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Variational/ScalarReduction.lean b/lean/OAI/Probability/SKRatio/Variational/ScalarReduction.lean new file mode 100644 index 0000000000000000000000000000000000000000..f8514261dacf2cffbbc9e6b1726fbce05eb0b8f0 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Variational/ScalarReduction.lean @@ -0,0 +1,491 @@ +import Mathlib +import OAI.Probability.SKRatio.Variational.ScalarMoments + +namespace OAI + +noncomputable section +open scoped Topology BigOperators +open MeasureTheory ProbabilityTheory Real +namespace SKRatio.Scalar + +lemma multiplier_strict_pos (h : ℝ) : 0 < multiplier h := by + linarith [multiplier_pos h] + +lemma abs_inv_multiplier_le (h : ℝ) : |(multiplier h)⁻¹| ≤ 3 := by + rw [abs_of_pos (inv_pos.mpr (multiplier_strict_pos h)),inv_eq_one_div,div_le_iff₀ (multiplier_strict_pos h)] + linarith [multiplier_pos h] + +lemma continuous_inv_multiplier : Continuous (fun h => (multiplier h)⁻¹) := + continuous_multiplier.inv₀ (fun h => (multiplier_strict_pos h).ne') + +lemma abs_v_sum_le (h t : ℝ) : |v h+v t| ≤ 2 := by + rw [abs_of_nonneg (add_nonneg (v_pos h).le (v_pos t).le)] + linarith [v_le_one h,v_le_one t] + +lemma v_sum_sq_le (h t : ℝ) : (v h+v t)^2 ≤ 4 := by + nlinarith [abs_v_sum_le h t,neg_le_abs (v h+v t),le_abs_self (v h+v t)] + +lemma abs_diagonal_kernel_le (h t : ℝ) : |v t^2/(w h+w t)| ≤ 2 := by + rw [abs_of_nonneg (div_nonneg (sq_nonneg _) (add_pos (w_pos h) (w_pos t)).le)] + apply (div_le_iff₀ (add_pos (w_pos h) (w_pos t))).mpr + have ht : v t ≤ 2*w t := by rw [v_factor]; nlinarith [w_pos t,(m_bounds t).2] + have hv : v t^2 ≤ v t := by nlinarith [v_pos t,v_le_one t] + linarith [w_pos h] + +lemma continuous_diagonal_kernel : + Continuous (fun z : ℝ×ℝ => v z.2^2/(w z.1+w z.2)) := by + apply ((continuous_v.comp continuous_snd).pow 2).div + ((continuous_w.comp continuous_fst).add (continuous_w.comp continuous_snd)) + intro z + exact (add_pos (w_pos z.1) (w_pos z.2)).ne' + +section Probability +variable (μ : Measure ℝ) [IsProbabilityMeasure μ] + +def diagonal (β : ℝ) (h : ℝ) : ℝ := + β^2 * ∫ t, v t^2/(w h+w t) ∂μ + +def cost (β : ℝ) (t : ℝ) : ℝ := + ∫ h, (β^2/4)*(v h+v t)^2/(multiplier h) ∂μ + +lemma integrable_multiplier : Integrable multiplier μ := by + apply (integrable_const (76/100:ℝ)).mono' continuous_multiplier.aestronglyMeasurable + exact ae_of_all _ (fun h => by + simpa only [norm_eq_abs,abs_of_pos (multiplier_strict_pos h)] using multiplier_le h) + +lemma mean_multiplier_pos : 0 < ∫ h, multiplier h ∂μ := by + have h := integral_mono (integrable_const (4464/10000:ℝ)) (integrable_multiplier μ) + multiplier_pos + simp only [integral_const,probReal_univ,smul_eq_mul,one_mul] at h + linarith + +lemma continuous_diagonal (β : ℝ) : Continuous (diagonal μ β) := by + apply Continuous.const_mul + apply continuous_of_dominated (bound := fun _ => (2:ℝ)) + · intro h + exact (continuous_diagonal_kernel.comp (continuous_const.prodMk continuous_id)).aestronglyMeasurable + · intro h + exact ae_of_all _ (fun t => by simpa only [norm_eq_abs] using abs_diagonal_kernel_le h t) + · exact integrable_const _ + · apply ae_of_all + intro t + exact continuous_const.div (continuous_w.add continuous_const) + (fun h => (add_pos (w_pos h) (w_pos t)).ne') + +lemma abs_diagonal_le (β h : ℝ) : |diagonal μ β h| ≤ 2*β^2 := by + have hb : |∫ t, v t^2/(w h+w t) ∂μ| ≤ 2 := by + exact (abs_integral_le_integral_abs).trans (by + simpa only [integral_const,probReal_univ,smul_eq_mul,one_mul,Function.comp_apply,id_eq] using + integral_mono ((integrable_const (μ := μ) (2:ℝ)).mono' + (continuous_diagonal_kernel.comp (continuous_const.prodMk continuous_id)).aestronglyMeasurable + (ae_of_all _ (fun t => by simpa only [norm_eq_abs,Function.comp_apply,id_eq] using abs_diagonal_kernel_le h t))).abs + (integrable_const 2) (abs_diagonal_kernel_le h)) + unfold diagonal + rw [abs_mul,abs_of_nonneg (sq_nonneg β)] + nlinarith [sq_nonneg β] + +lemma abs_cost_integrand_le (β h t : ℝ) : + |(β^2/4)*(v h+v t)^2/(multiplier h)| ≤ 3*β^2 := by + rw [div_eq_mul_inv,abs_mul,abs_mul,abs_of_nonneg (div_nonneg (sq_nonneg β) (by norm_num)), + abs_of_nonneg (sq_nonneg _)] + calc + _ ≤ (β^2/4)*4*3 := by + gcongr + · exact v_sum_sq_le h t + · exact abs_inv_multiplier_le h + _ = _ := by ring + +lemma continuous_cost_integrand (β : ℝ) : + Continuous (fun z : ℝ×ℝ => (β^2/4)*(v z.1+v z.2)^2/(multiplier z.1)) := by + exact ((((continuous_v.comp continuous_fst).add (continuous_v.comp continuous_snd)).pow 2).const_mul _).div + (continuous_multiplier.comp continuous_fst) (fun z => (multiplier_strict_pos z.1).ne') + +lemma continuous_cost (β : ℝ) : Continuous (cost μ β) := by + apply continuous_of_dominated (bound := fun _ => 3*β^2) + · intro t + exact ((continuous_cost_integrand β).comp (continuous_id.prodMk continuous_const)).aestronglyMeasurable + · intro t + exact ae_of_all _ (fun h => by simpa only [norm_eq_abs] using abs_cost_integrand_le β h t) + · exact integrable_const _ + · apply ae_of_all + intro h + exact (((continuous_const.add continuous_v).pow 2).const_mul _).div_const _ + +lemma abs_cost_le (β t : ℝ) : |cost μ β t| ≤ 3*β^2 := by + unfold cost + apply abs_integral_le_integral_abs.trans + have hI : Integrable (fun h => (β^2/4)*(v h+v t)^2/(multiplier h)) μ := by + exact (integrable_const (3*β^2)).mono' + (((continuous_cost_integrand β).comp (continuous_id.prodMk continuous_const)).aestronglyMeasurable) + (ae_of_all _ (fun h => by simpa only [norm_eq_abs] using abs_cost_integrand_le β h t)) + simpa only [integral_const,probReal_univ,smul_eq_mul,one_mul,Function.comp_apply,id_eq] using + integral_mono hI.abs (integrable_const (3*β^2)) (fun h => abs_cost_integrand_le β h t) + +variable {μ} + +omit [IsProbabilityMeasure μ] in +lemma memLp_v_sum_mul {b : ℝ → ℝ} (hb : MemLp b 2 μ) (h : ℝ) : + MemLp (fun t => (v h+v t)*b t) 2 μ := by + apply hb.of_le_mul (((continuous_const.add continuous_v).aestronglyMeasurable).mul + hb.aestronglyMeasurable) (c := (2:ℝ)) + exact ae_of_all _ (fun t => by + change |(v h+v t)*b t| ≤ 2*|b t| + rw [abs_mul] + exact mul_le_mul_of_nonneg_right (abs_v_sum_le h t) (abs_nonneg _)) + +lemma integral_v_sum_mul {b : ℝ → ℝ} (hb : MemLp b 2 μ) (h : ℝ) : + ∫ t, (v h+v t)*b t ∂μ = (∫ t, b t*v t ∂μ)+v h*(∫ t, b t ∂μ) := by + have hbI := hb.integrable (by norm_num : (1:ENNReal) ≤ 2) + have hbvI : Integrable (fun t => b t*v t) μ := hb.integrable_mul (memLp_v (p := 2)) + have he : (fun t => (v h+v t)*b t) = fun t => b t*v t+v h*b t := by funext t; ring + rw [he,integral_add hbvI (hbI.const_mul _),integral_const_mul] + +def radicand (μ : Measure ℝ) (b r : ℝ → ℝ) (h : ℝ) : ℝ := + (∫ t, ((v h+v t)*r t)^2 ∂μ) + + (∫ t, ((v h+v t)*b t - (∫ s, (v h+v s)*b s ∂μ))^2 ∂μ) + +omit [IsProbabilityMeasure μ] in +lemma radicand_nonneg (b r : ℝ → ℝ) (h : ℝ) : 0 ≤ radicand μ b r h := + add_nonneg (integral_nonneg (fun _ => sq_nonneg _)) + (integral_nonneg (fun _ => sq_nonneg _)) + +lemma integral_centered_sq {f : ℝ → ℝ} (hf : MemLp f 2 μ) : + ∫ h, (f h-(∫ t, f t ∂μ))^2 ∂μ = + (∫ h, f h^2 ∂μ)-(∫ h, f h ∂μ)^2 := by + have hI := hf.integrable (by norm_num : (1:ENNReal) ≤ 2) + have hid (h : ℝ) : (f h-(∫ t, f t ∂μ))^2 = + f h^2-(2*(∫ t, f t ∂μ))*f h+(∫ t, f t ∂μ)^2 := by ring + simp_rw [hid] + have hsub : Integrable (fun h => f h^2-(2*(∫ t, f t ∂μ))*f h) μ := + hf.integrable_sq.sub (hI.const_mul _) + rw [integral_add hsub (integrable_const _), + integral_sub hf.integrable_sq (hI.const_mul _),integral_const_mul,integral_const] + simp only [probReal_univ,smul_eq_mul,one_mul] + ring + +omit [IsProbabilityMeasure μ] in +lemma v_sum_square_integrable {b r : ℝ → ℝ} (hb : MemLp b 2 μ) (hr : MemLp r 2 μ) + (h : ℝ) : Integrable (fun t => (v h+v t)^2*(b t^2+r t^2)) μ := by + have he : (fun t => (v h+v t)^2*(b t^2+r t^2)) = + fun t => ((v h+v t)*b t)^2+((v h+v t)*r t)^2 := by funext t; ring + rw [he] + exact (memLp_v_sum_mul hb h).integrable_sq.add (memLp_v_sum_mul hr h).integrable_sq + +lemma radicand_expansion {b r : ℝ → ℝ} (hb : MemLp b 2 μ) (hr : MemLp r 2 μ) + (h : ℝ) : radicand μ b r h = + (∫ t, (v h+v t)^2*(b t^2+r t^2) ∂μ) - + ((∫ t, b t*v t ∂μ)+v h*(∫ t, b t ∂μ))^2 := by + rw [radicand,integral_centered_sq (memLp_v_sum_mul hb h),integral_v_sum_mul hb h] + have he : (fun t => (v h+v t)^2*(b t^2+r t^2)) = + fun t => ((v h+v t)*b t)^2+((v h+v t)*r t)^2 := by funext t; ring + rw [he,integral_add (memLp_v_sum_mul hb h).integrable_sq (memLp_v_sum_mul hr h).integrable_sq] + ring + +lemma radicand_le {b r : ℝ → ℝ} (hb : MemLp b 2 μ) (hr : MemLp r 2 μ) + (h : ℝ) : radicand μ b r h ≤ 4*∫ t, b t^2+r t^2 ∂μ := by + rw [radicand_expansion hb hr h] + have hI := hb.integrable_sq.add hr.integrable_sq + have he := integral_mono (v_sum_square_integrable hb hr h) (hI.const_mul (4:ℝ)) + (fun t => mul_le_mul_of_nonneg_right (v_sum_sq_le h t) (add_nonneg (sq_nonneg _) (sq_nonneg _))) + simp only [integral_const_mul,Pi.add_apply] at he + nlinarith [sq_nonneg ((∫ t, b t*v t ∂μ)+v h*(∫ t, b t ∂μ))] + +lemma continuous_radicand {b r : ℝ → ℝ} (hb : MemLp b 2 μ) (hr : MemLp r 2 μ) : + Continuous (radicand μ b r) := by + have he : radicand μ b r = fun h => + (∫ t, (v h+v t)^2*(b t^2+r t^2) ∂μ) - + ((∫ t, b t*v t ∂μ)+v h*(∫ t, b t ∂μ))^2 := funext (radicand_expansion hb hr) + rw [he] + apply Continuous.sub + · apply continuous_of_dominated (bound := fun t => 4*(b t^2+r t^2)) + · intro h + exact (v_sum_square_integrable hb hr h).aestronglyMeasurable + · intro h + apply ae_of_all + intro t + rw [norm_eq_abs,abs_of_nonneg (mul_nonneg (sq_nonneg _) (add_nonneg (sq_nonneg _) (sq_nonneg _)))] + exact mul_le_mul_of_nonneg_right (v_sum_sq_le h t) (add_nonneg (sq_nonneg _) (sq_nonneg _)) + · exact (hb.integrable_sq.add hr.integrable_sq).const_mul _ + · exact ae_of_all _ (fun t => ((continuous_v.add continuous_const).pow 2).mul_const _) + · exact (continuous_const.add (continuous_v.mul_const _)).pow 2 + +lemma memLp_sqrt_radicand {b r : ℝ → ℝ} (hb : MemLp b 2 μ) (hr : MemLp r 2 μ) : + MemLp (fun h => sqrt (radicand μ b r h)) 2 μ := by + apply MemLp.of_bound (continuous_sqrt.comp (continuous_radicand hb hr)).aestronglyMeasurable + (sqrt (4*∫ t, b t^2+r t^2 ∂μ)) + exact ae_of_all _ (fun h => by + simpa only [Function.comp_apply,norm_eq_abs,abs_of_nonneg (sqrt_nonneg _)] using + sqrt_le_sqrt (radicand_le hb hr h)) + +lemma integrable_radical {b r : ℝ → ℝ} (hb : MemLp b 2 μ) (hr : MemLp r 2 μ) : + Integrable (fun h => r h*sqrt (radicand μ b r h)) μ := + hr.integrable_mul (memLp_sqrt_radicand hb hr) + +lemma memLp_multiplier : MemLp multiplier 2 μ := by + apply MemLp.of_bound continuous_multiplier.aestronglyMeasurable (76/100:ℝ) + exact ae_of_all _ (fun h => by + simpa only [norm_eq_abs,abs_of_pos (multiplier_strict_pos h)] using multiplier_le h) + +lemma integral_weighted_square {f : ℝ → ℝ} (hf : MemLp f 2 μ) : + (∫ h, f h ∂μ)^2 / (∫ h, multiplier h ∂μ) ≤ + ∫ h, f h^2/(multiplier h) ∂μ := by + have hF : Integrable f μ := hf.integrable (by norm_num) + have hQ : Integrable (fun h => f h^2/(multiplier h)) μ := by + simp_rw [div_eq_mul_inv] + exact hf.integrable_sq.mul_bdd continuous_inv_multiplier.aestronglyMeasurable + (ae_of_all _ (fun h => by simpa only [norm_eq_abs] using abs_inv_multiplier_le h)) + let l := ∫ h, multiplier h ∂μ + have hl : 0 < l := mean_multiplier_pos μ + let c := (∫ h, f h ∂μ)/l + have hid (h : ℝ) : (f h-c*multiplier h)^2/(multiplier h) = + f h^2/(multiplier h)-(2*c)*f h+c^2*multiplier h := by + field_simp [(multiplier_strict_pos h).ne'] + ring + have hnonneg : 0 ≤ ∫ h, (f h-c*multiplier h)^2/(multiplier h) ∂μ := + integral_nonneg (fun h => div_nonneg (sq_nonneg _) (multiplier_strict_pos h).le) + have hsub : Integrable (fun h => f h^2/(multiplier h)-(2*c)*f h) μ := + hQ.sub (hF.const_mul _) + simp_rw [hid] at hnonneg + rw [integral_add hsub ((integrable_multiplier μ).const_mul _), + integral_sub hQ (hF.const_mul _),integral_const_mul,integral_const_mul] at hnonneg + have hc : c*l = ∫ h, f h ∂μ := div_mul_cancel₀ _ hl.ne' + change (∫ h, f h ∂μ)^2/l ≤ _ + apply (div_le_iff₀ hl).mpr + have hn := mul_nonneg hl.le hnonneg + change 0 ≤ l*((∫ h, f h^2/multiplier h ∂μ)-(2*c)*(∫ h, f h ∂μ)+c^2*l) at hn + nlinarith only [hn,sq_nonneg (c*l-(∫ h, f h ∂μ)),hc] + +lemma young_radical_pointwise (β r T Λ : ℝ) (hT : 0 ≤ T) (hΛ : 0 < Λ) : + β*r*sqrt T ≤ Λ*r^2+(β^2/4)*T/Λ := by + have hs := sq_nonneg (β*sqrt T-2*Λ*r) + have hsqrt := sq_sqrt hT + apply (mul_le_mul_iff_of_pos_right (show 0 < 4*Λ by positivity)).mp + have hd : (Λ*r^2+(β^2/4)*T/Λ)*(4*Λ) = 4*Λ^2*r^2+β^2*T := by + field_simp + rw [hd] + nlinarith only [hs,hsqrt] + +lemma cost_product_integrable (β : ℝ) {Z : ℝ → ℝ} (hZ : Integrable Z μ) : + Integrable (fun z : ℝ×ℝ => + ((β^2/4)*(v z.1+v z.2)^2/multiplier z.1)*Z z.2) (μ.prod μ) := by + exact (hZ.comp_snd μ).bdd_mul (continuous_cost_integrand β).aestronglyMeasurable + (ae_of_all _ (fun z => by + simpa only [norm_eq_abs] using abs_cost_integrand_le β z.1 z.2)) + +lemma cost_fubini (β : ℝ) {Z : ℝ → ℝ} (hZ : Integrable Z μ) : + ∫ h, (β^2/4)*(∫ t, (v h+v t)^2*Z t ∂μ)/multiplier h ∂μ = + ∫ t, cost μ β t*Z t ∂μ := by + have hI := cost_product_integrable β hZ + have he (h : ℝ) : (β^2/4)*(∫ t, (v h+v t)^2*Z t ∂μ)/multiplier h = + ∫ t, ((β^2/4)*(v h+v t)^2/multiplier h)*Z t ∂μ := by + rw [div_eq_mul_inv,←integral_const_mul,←integral_mul_const] + apply integral_congr_ae + exact ae_of_all _ (fun t => by ring) + simp_rw [he] + rw [integral_integral_swap hI] + simp_rw [integral_mul_const] + rfl + +lemma integrable_cost_quadratic (β : ℝ) {b r : ℝ → ℝ} + (hb : MemLp b 2 μ) (hr : MemLp r 2 μ) : + Integrable (fun h => cost μ β h*(b h^2+r h^2)) μ := by + exact (hb.integrable_sq.add hr.integrable_sq).bdd_mul + (continuous_cost μ β).aestronglyMeasurable + (ae_of_all _ (fun h => by simpa only [norm_eq_abs] using abs_cost_le μ β h)) + +omit [IsProbabilityMeasure μ] in +lemma integrable_multiplier_square {r : ℝ → ℝ} (hr : MemLp r 2 μ) : + Integrable (fun h => multiplier h*r h^2) μ := by + exact hr.integrable_sq.bdd_mul continuous_multiplier.aestronglyMeasurable + (ae_of_all _ (fun h => by + simpa only [norm_eq_abs,abs_of_pos (multiplier_strict_pos h)] using multiplier_le h)) + +lemma memLp_linear_v (A B : ℝ) : MemLp (fun h => B+v h*A) 2 μ := + (memLp_const B).add (memLp_v.mul_const A) + +lemma integral_linear_v (A B : ℝ) : + ∫ h, B+v h*A ∂μ = B+(∫ h, v h ∂μ)*A := by + have hv : Integrable v μ := memLp_v.integrable (by norm_num : (1:ENNReal) ≤ 2) + rw [integral_add (integrable_const _) (hv.mul_const _),integral_const,integral_mul_const] + simp only [probReal_univ,smul_eq_mul,one_mul] + +lemma integrable_linear_v_cost (β A B : ℝ) : + Integrable (fun h => (β^2/4)*(B+v h*A)^2/multiplier h) μ := by + simp_rw [div_eq_mul_inv,mul_assoc] + exact ((memLp_linear_v A B (μ := μ)).integrable_sq.mul_bdd + continuous_inv_multiplier.aestronglyMeasurable + (ae_of_all _ (fun h => by simpa only [norm_eq_abs] using abs_inv_multiplier_le h))).const_mul (4:ℝ)⁻¹ |>.const_mul (β^2) + +lemma radical_young (β : ℝ) {b r : ℝ → ℝ} (hb : MemLp b 2 μ) (hr : MemLp r 2 μ) : + β*(∫ h, r h*sqrt (radicand μ b r h) ∂μ) ≤ + (∫ h, cost μ β h*(b h^2+r h^2) ∂μ) + (∫ h, multiplier h*r h^2 ∂μ) - + β^2/(4*(∫ h, multiplier h ∂μ))* + ((∫ h, b h*v h ∂μ)+(∫ h, v h ∂μ)*(∫ h, b h ∂μ))^2 := by + let A := ∫ h, b h ∂μ + let B := ∫ h, b h*v h ∂μ + let P := fun h => (β^2/4)*(∫ t, (v h+v t)^2*(b t^2+r t^2) ∂μ)/multiplier h + let N := fun h => (β^2/4)*(B+v h*A)^2/multiplier h + have hP : Integrable P μ := by + have hh := (cost_product_integrable β (hb.integrable_sq.add hr.integrable_sq)).integral_prod_left + have he : P = fun h => ∫ t, + ((β^2/4)*(v h+v t)^2/multiplier h)*(b t^2+r t^2) ∂μ := by + funext h + dsimp [P] + simp_rw [div_eq_mul_inv] + rw [←integral_const_mul,←integral_mul_const] + apply integral_congr_ae + exact ae_of_all _ (fun t => by ring) + rw [he] + exact hh + have hN : Integrable N μ := integrable_linear_v_cost β A B + have hmul := integrable_multiplier_square hr + have hupper : Integrable (fun h => multiplier h*r h^2+P h-N h) μ := (hmul.add hP).sub hN + have ht := integral_mono ((integrable_radical hb hr).const_mul β) hupper + (fun h => show β*(r h*sqrt (radicand μ b r h)) ≤ multiplier h*r h^2+P h-N h from by + have hh := young_radical_pointwise β (r h) (radicand μ b r h) (multiplier h) + (radicand_nonneg b r h) (multiplier_strict_pos h) + rw [radicand_expansion hb hr h] at hh ⊢ + dsimp [P,N,A,B] + convert! hh using 1 <;> ring) + have hsum : Integrable (fun h => multiplier h*r h^2+P h) μ := hmul.add hP + rw [integral_const_mul,integral_sub hsum hN,integral_add hmul hP] at ht + have hpvalue : (∫ h, P h ∂μ) = ∫ h, cost μ β h*(b h^2+r h^2) ∂μ := + cost_fubini β (hb.integrable_sq.add hr.integrable_sq) + rw [hpvalue] at ht + have hcs := integral_weighted_square (memLp_linear_v A B (μ := μ)) + rw [integral_linear_v] at hcs + have hnscale : (∫ h, N h ∂μ) = (β^2/4)*(∫ h, (B+v h*A)^2/multiplier h ∂μ) := by + dsimp [N] + simp_rw [mul_div_assoc] + rw [integral_const_mul] + rw [hnscale] at ht + have hbound := mul_le_mul_of_nonneg_left hcs (by positivity : 0 ≤ β^2/4) + have hid : (β^2/4)*((B+(∫ h, v h ∂μ)*A)^2/(∫ h, multiplier h ∂μ)) = + β^2/(4*(∫ h, multiplier h ∂μ))*(B+(∫ h, v h ∂μ)*A)^2 := by ring + rw [hid] at hbound + dsimp [A,B] at hbound + linarith only [ht,hbound] + +end Probability + +def variational (β : ℝ) (b r : ℝ → ℝ) : ℝ := + (∫ h, diagonal (fieldLaw β) β h*(b h^2+r h^2) ∂fieldLaw β) + + (∫ h, b h*h ∂fieldLaw β)*(∫ h, b h*v h ∂fieldLaw β) + + (∫ h, b h ∂fieldLaw β)*(∫ h, b h*(h*v h) ∂fieldLaw β) - + β^2*(∫ h, b h ∂fieldLaw β)*(∫ h, b h*v h ∂fieldLaw β) + + 2*β^2*(∫ h, b h ∂fieldLaw β)*(∫ h, b h*(m h*v h) ∂fieldLaw β) + + β^2*(∫ z : ℝ×ℝ, b z.1*kernel z.1 z.2*b z.2 ∂(fieldLaw β).prod (fieldLaw β)) + + β*(∫ h, r h*sqrt (radicand (fieldLaw β) b r h) ∂fieldLaw β) + +def coherent (β : ℝ) (b : ℝ → ℝ) : ℝ := + (∫ h, b h*h ∂fieldLaw β)*(∫ h, b h*v h ∂fieldLaw β) + + (∫ h, b h ∂fieldLaw β)*(∫ h, b h*((h-β^2+2*β^2*m h)*v h) ∂fieldLaw β) + + β^2*(∫ z : ℝ×ℝ, b z.1*kernel z.1 z.2*b z.2 ∂(fieldLaw β).prod (fieldLaw β)) - + β^2/(4*(∫ h, multiplier h ∂fieldLaw β))* + ((∫ h, b h*v h ∂fieldLaw β)+(∫ h, v h ∂fieldLaw β)*(∫ h, b h ∂fieldLaw β))^2 + +lemma coherent_paired_integrable (β : ℝ) {b : ℝ → ℝ} + (hb : MemLp b 2 (fieldLaw β)) : + Integrable (fun h => b h*((h-β^2+2*β^2*m h)*v h)) (fieldLaw β) := by + have hco : MemLp (fun h => (h-β^2+2*β^2*m h)*v h) 2 (fieldLaw β) := by + convert! ((memLp_field_v β).sub (memLp_v.const_mul (β^2))).add + (memLp_mv.const_mul (2*β^2)) using 1 + ext h + dsimp + ring + exact hb.integrable_mul hco + +lemma coherent_paired_expansion (β : ℝ) {b : ℝ → ℝ} + (hb : MemLp b 2 (fieldLaw β)) : + (∫ h, b h*((h-β^2+2*β^2*m h)*v h) ∂fieldLaw β) = + (∫ h, b h*(h*v h) ∂fieldLaw β)-β^2*(∫ h, b h*v h ∂fieldLaw β) + + (2*β^2)*(∫ h, b h*(m h*v h) ∂fieldLaw β) := by + have h1 : Integrable (fun h => b h*(h*v h)) (fieldLaw β) := hb.integrable_mul (memLp_field_v β) + have h2 : Integrable (fun h => b h*v h) (fieldLaw β) := hb.integrable_mul (memLp_v (p := 2)) + have h3 : Integrable (fun h => b h*(m h*v h)) (fieldLaw β) := hb.integrable_mul (memLp_mv (p := 2)) + have hsub : Integrable (fun h => b h*(h*v h)-β^2*(b h*v h)) (fieldLaw β) := h1.sub (h2.const_mul _) + have he (h : ℝ) : b h*((h-β^2+2*β^2*m h)*v h) = + b h*(h*v h)-β^2*(b h*v h)+(2*β^2)*(b h*(m h*v h)) := by ring + simp_rw [he] + rw [integral_add hsub (h3.const_mul _),integral_sub h1 (h2.const_mul _), + integral_const_mul,integral_const_mul] + +lemma integrable_diagonal_quadratic (β : ℝ) {b r : ℝ → ℝ} + (hb : MemLp b 2 (fieldLaw β)) (hr : MemLp r 2 (fieldLaw β)) : + Integrable (fun h => diagonal (fieldLaw β) β h*(b h^2+r h^2)) (fieldLaw β) := by + exact (hb.integrable_sq.add hr.integrable_sq).bdd_mul + (continuous_diagonal _ β).aestronglyMeasurable + (ae_of_all _ (fun h => by simpa only [norm_eq_abs] using abs_diagonal_le _ β h)) + +theorem variational_young (β : ℝ) {b r : ℝ → ℝ} + (hb : MemLp b 2 (fieldLaw β)) (hr : MemLp r 2 (fieldLaw β)) : + variational β b r ≤ + (∫ h, (diagonal (fieldLaw β) β h+cost (fieldLaw β) β h)*(b h^2+r h^2) ∂fieldLaw β) + + (∫ h, multiplier h*r h^2 ∂fieldLaw β) + coherent β b := by + have hy := radical_young β hb hr + have hd := integrable_diagonal_quadratic β hb hr + have hk := integrable_cost_quadratic β hb hr + have he : (∫ h, (diagonal (fieldLaw β) β h+cost (fieldLaw β) β h)*(b h^2+r h^2) ∂fieldLaw β) = + (∫ h, diagonal (fieldLaw β) β h*(b h^2+r h^2) ∂fieldLaw β) + + (∫ h, cost (fieldLaw β) β h*(b h^2+r h^2) ∂fieldLaw β) := by + simp_rw [add_mul] + exact integral_add hd hk + unfold variational coherent + rw [he,coherent_paired_expansion β hb] + nlinarith only [hy] + +lemma integrable_total_coefficient (β : ℝ) {b r : ℝ → ℝ} + (hb : MemLp b 2 (fieldLaw β)) (hr : MemLp r 2 (fieldLaw β)) : + Integrable (fun h => (diagonal (fieldLaw β) β h+cost (fieldLaw β) β h+multiplier h)* + (b h^2+r h^2)) (fieldLaw β) := by + simp_rw [add_mul,mul_add (multiplier _)] + exact ((integrable_diagonal_quadratic β hb hr).add (integrable_cost_quadratic β hb hr)).add + ((integrable_multiplier_square hb).add (integrable_multiplier_square hr)) + +theorem variational_bound_of_two_estimates (β d c : ℝ) (hc : 0 ≤ c) + (henvelope : ∀ h, multiplier h+diagonal (fieldLaw β) β h+cost (fieldLaw β) β h ≤ d) + (hcoherent : ∀ b : ℝ → ℝ, MemLp b 2 (fieldLaw β) → + coherent β b ≤ ∫ h, (multiplier h+c)*b h^2 ∂fieldLaw β) + {b r : ℝ → ℝ} (hb : MemLp b 2 (fieldLaw β)) (hr : MemLp r 2 (fieldLaw β)) + (hnorm : (∫ h, b h^2+r h^2 ∂fieldLaw β) = 1) : + variational β b r ≤ d+c := by + have hy := variational_young β hb hr + have hco := hcoherent b hb + have hsum : Integrable (fun h => (diagonal (fieldLaw β) β h+cost (fieldLaw β) β h)* + (b h^2+r h^2)) (fieldLaw β) := by + simp_rw [add_mul] + exact (integrable_diagonal_quadratic β hb hr).add (integrable_cost_quadratic β hb hr) + have hDK : Integrable (fun h => diagonal (fieldLaw β) β h*(b h^2+r h^2)+ + cost (fieldLaw β) β h*(b h^2+r h^2)) (fieldLaw β) := + (integrable_diagonal_quadratic β hb hr).add (integrable_cost_quadratic β hb hr) + have hLR : Integrable (fun h => multiplier h*b h^2+multiplier h*r h^2) (fieldLaw β) := + (integrable_multiplier_square hb).add (integrable_multiplier_square hr) + have hexp : (∫ h, (diagonal (fieldLaw β) β h+cost (fieldLaw β) β h+multiplier h)* + (b h^2+r h^2) ∂fieldLaw β) = + (∫ h, (diagonal (fieldLaw β) β h+cost (fieldLaw β) β h)*(b h^2+r h^2) ∂fieldLaw β)+ + (∫ h, multiplier h*b h^2 ∂fieldLaw β)+(∫ h, multiplier h*r h^2 ∂fieldLaw β) := by + simp_rw [add_mul,mul_add (multiplier _)] + rw [integral_add hDK hLR, + integral_add (integrable_multiplier_square hb) (integrable_multiplier_square hr)] + ring + have hpoint := integral_mono (integrable_total_coefficient β hb hr) + ((hb.integrable_sq.add hr.integrable_sq).const_mul d) + (fun h => mul_le_mul_of_nonneg_right (by linarith [henvelope h]) (add_nonneg (sq_nonneg _) (sq_nonneg _))) + simp only [integral_const_mul,Pi.add_apply,hnorm,mul_one,hexp] at hpoint + have hcb : (∫ h, (multiplier h+c)*b h^2 ∂fieldLaw β) = + (∫ h, multiplier h*b h^2 ∂fieldLaw β)+c*(∫ h, b h^2 ∂fieldLaw β) := by + simp_rw [add_mul] + rw [integral_add (integrable_multiplier_square hb) (hb.integrable_sq.const_mul c),integral_const_mul] + rw [hcb] at hco + have hbb : (∫ h, b h^2 ∂fieldLaw β) ≤ 1 := by + rw [integral_add hb.integrable_sq hr.integrable_sq] at hnorm + have hn : 0 ≤ ∫ h, r h^2 ∂fieldLaw β := integral_nonneg (fun h => sq_nonneg (r h)) + linarith only [hn,hnorm] + have hbc := mul_le_mul_of_nonneg_left hbb hc + nlinarith only [hy,hco,hpoint,hbc] + +end SKRatio.Scalar + +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Variational/ScalarTemperature.lean b/lean/OAI/Probability/SKRatio/Variational/ScalarTemperature.lean new file mode 100644 index 0000000000000000000000000000000000000000..d7d67767ab8da6cc88f3ddb6a6c7d8abc7cd30e0 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Variational/ScalarTemperature.lean @@ -0,0 +1,118 @@ +import Mathlib +import OAI.Probability.SKRatio.Variational.ScalarReduction + +namespace OAI + +noncomputable section +open scoped Topology NNReal ENNReal +open MeasureTheory ProbabilityTheory Real Set +namespace SKRatio.Scalar + +lemma variance_ne_zero {β : ℝ} (hβ : 0 < β) : variance β ≠ 0 := by + intro hz + have he := congrArg (fun t : ℝ≥0 => (t:ℝ)) hz + simp only [variance_coe,NNReal.coe_zero] at he + nlinarith + +lemma field_pdf {β : ℝ} (hβ : 0 < β) (h : ℝ) : + gaussianPDFReal (β^2) (variance β) h = + (sqrt (2*Real.pi)*β)⁻¹*exp (-β^2/2+h-h^2/(2*β^2)) := by + unfold gaussianPDFReal + rw [variance_coe,sqrt_mul (by positivity : 0 ≤ 2*Real.pi),sqrt_sq hβ.le] + congr 2 + field_simp + ring + +lemma thermal_prefactor_deriv (β : ℝ) : + HasDerivAt (fun t : ℝ => t*exp (-t^2/2)) + ((1-β^2)*exp (-β^2/2)) β := by + convert! (hasDerivAt_id β).mul + ((((hasDerivAt_id β).pow 2).neg.div_const 2).exp) using 1 + simp only [Nat.cast_ofNat,show 2-1=1 from rfl,pow_one,id_eq,Pi.neg_apply,Pi.pow_apply] + ring + +lemma thermal_prefactor_mono {β z : ℝ} (hβ : 0 ≤ β) (hβz : β ≤ z) (hz : z ≤ 1) : + β*exp (-β^2/2) ≤ z*exp (-z^2/2) := by + apply (monotoneOn_of_hasDerivWithinAt_nonneg (convex_Icc (0:ℝ) 1) + (fun x _ => (thermal_prefactor_deriv x).continuousAt.continuousWithinAt) + (fun x _ => (thermal_prefactor_deriv x).hasDerivWithinAt) ?_) ⟨hβ,le_trans hβz hz⟩ ⟨le_trans hβ hβz,hz⟩ hβz + intro x hx + have hx' : x ∈ Icc (0:ℝ) 1 := interior_subset hx + exact mul_nonneg (by nlinarith [hx'.1,hx'.2]) (exp_pos _).le + +lemma scaled_field_pdf {β : ℝ} (hβ : 0 < β) (h : ℝ) : + β^2*gaussianPDFReal (β^2) (variance β) h = + (sqrt (2*Real.pi))⁻¹*(β*exp (-β^2/2))*exp (h-h^2/(2*β^2)) := by + rw [field_pdf hβ] + have he : -β^2/2+h-h^2/(2*β^2) = -β^2/2+(h-h^2/(2*β^2)) := by ring + rw [he,exp_add] + field_simp + +lemma scaled_field_pdf_mono {β z : ℝ} (hβ : 0 < β) (hβz : β ≤ z) (hz : z ≤ 1) (h : ℝ) : + β^2*gaussianPDFReal (β^2) (variance β) h ≤ + z^2*gaussianPDFReal (z^2) (variance z) h := by + have hzpos : 0 < z := lt_of_lt_of_le hβ hβz + rw [scaled_field_pdf hβ,scaled_field_pdf hzpos] + have hq : h^2/(2*z^2) ≤ h^2/(2*β^2) := by + apply div_le_div_of_nonneg_left (sq_nonneg h) (by positivity) + nlinarith + apply mul_le_mul + · exact mul_le_mul_of_nonneg_left (thermal_prefactor_mono hβ.le hβz hz) (by positivity) + · exact exp_le_exp.mpr (by linarith only [hq]) + · exact (exp_pos _).le + · positivity + +theorem scaled_fieldLaw_mono {β z : ℝ} (hβ : 0 < β) (hβz : β ≤ z) (hz : z ≤ 1) : + ENNReal.ofReal (β^2) • fieldLaw β ≤ ENNReal.ofReal (z^2) • fieldLaw z := by + have hzpos : 0 < z := lt_of_lt_of_le hβ hβz + rw [fieldLaw,fieldLaw,gaussianReal_of_var_ne_zero _ (variance_ne_zero hβ), + gaussianReal_of_var_ne_zero _ (variance_ne_zero hzpos), + ←withDensity_smul' _ _ ENNReal.ofReal_ne_top,←withDensity_smul' _ _ ENNReal.ofReal_ne_top] + apply withDensity_mono + apply ae_of_all + intro h + simp only [Pi.smul_apply,smul_eq_mul,gaussianPDF,←ENNReal.ofReal_mul (sq_nonneg β), + ←ENNReal.ofReal_mul (sq_nonneg z)] + exact ENNReal.ofReal_le_ofReal (scaled_field_pdf_mono hβ hβz hz h) + +lemma scaled_integral_mono {β z : ℝ} (hβ : 0 < β) (hβz : β ≤ z) (hz : z ≤ 1) + {f : ℝ → ℝ} (hf : ∀ h, 0 ≤ f h) (hfi : Integrable f (fieldLaw z)) : + β^2*(∫ h, f h ∂fieldLaw β) ≤ z^2*(∫ h, f h ∂fieldLaw z) := by + have h := integral_mono_measure (scaled_fieldLaw_mono hβ hβz hz) + (ae_of_all _ hf) (hfi.smul_measure ENNReal.ofReal_ne_top) + simpa only [integral_smul_measure,ENNReal.toReal_ofReal (sq_nonneg _),smul_eq_mul] using h + +lemma integral_diagonal_kernel {μ : Measure ℝ} [IsProbabilityMeasure μ] (h : ℝ) : + Integrable (fun t => v t^2/(w h+w t)) μ := by + apply (integrable_const (2:ℝ)).mono' + (continuous_diagonal_kernel.comp (continuous_const.prodMk continuous_id)).aestronglyMeasurable + exact ae_of_all _ (fun t => by + simpa only [norm_eq_abs,Function.comp_apply,id_eq] using abs_diagonal_kernel_le h t) + +lemma diagonal_temperature_mono {β z : ℝ} (hβ : 0 < β) (hβz : β ≤ z) (hz : z ≤ 1) (h : ℝ) : + diagonal (fieldLaw β) β h ≤ diagonal (fieldLaw z) z h := by + apply scaled_integral_mono hβ hβz hz + (fun t => div_nonneg (sq_nonneg _) (add_pos (w_pos h) (w_pos t)).le) + (integral_diagonal_kernel h) + +lemma cost_temperature_mono {β z : ℝ} (hβ : 0 < β) (hβz : β ≤ z) (hz : z ≤ 1) (t : ℝ) : + cost (fieldLaw β) β t ≤ cost (fieldLaw z) z t := by + have hi : Integrable (fun h => (v h+v t)^2/(4*multiplier h)) (fieldLaw z) := by + have hehe (h : ℝ) : (v h+v t)^2/(4*multiplier h) = + ((1:ℝ)^2/4)*(v h+v t)^2/multiplier h := by ring + simp_rw [hehe] + exact (integrable_const (3:ℝ)).mono' + ((continuous_cost_integrand 1).comp (continuous_id.prodMk continuous_const)).aestronglyMeasurable + (ae_of_all _ (fun h => by simpa only [norm_eq_abs,one_pow,mul_one] using abs_cost_integrand_le 1 h t)) + have he (B h : ℝ) : (B^2/4)*(v h+v t)^2/multiplier h = + B^2*((v h+v t)^2/(4*multiplier h)) := by ring + unfold cost + simp_rw [he,integral_const_mul] + exact scaled_integral_mono hβ hβz hz + (fun h => div_nonneg (sq_nonneg _) (mul_pos (by norm_num) (multiplier_strict_pos h)).le) hi + +end SKRatio.Scalar + +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Variational/ScalarTransfer.lean b/lean/OAI/Probability/SKRatio/Variational/ScalarTransfer.lean new file mode 100644 index 0000000000000000000000000000000000000000..684e4600bd375d632eb9393aad56df2d798fda76 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Variational/ScalarTransfer.lean @@ -0,0 +1,212 @@ +import Mathlib +import OAI.Probability.SKRatio.Quantization.BinWeightContinuity +import OAI.Probability.SKRatio.Quantization.BinEmpirical +import OAI.Probability.SKRatio.Quantization.QuantizedPopulation +import OAI.Probability.SKRatio.Quantization.ConditionalBins +import OAI.Probability.SKRatio.FiniteChain.FieldSize +import OAI.Probability.SKRatio.FiniteChain.ResidualBounds +import OAI.Probability.SKRatio.Gaussian.PlantedCriterion + +namespace OAI + +noncomputable section +open scoped BigOperators Matrix NNReal ENNReal Topology +open MeasureTheory ProbabilityTheory Filter Real +namespace SKRatio.Bins +open Planted Scalar SKRatioClock.Regression MatrixNet Calculus +attribute [local instance] Classical.propDecidable +variable {n : ℕ} + +lemma variance_bilinear_field_error (M : Matrix (Fin n) (Fin n) ℝ) + (v v' p : Fin n → ℝ) (hp : ∑ i, p i^2=1) {K a : ℝ} + (hK : 0 ≤ K) (ha : 0 ≤ a) (hM : euclideanOpNorm M ≤ K) + (hv : ∀ i, |v i-v' i| ≤ a) : + |p ⬝ᵥ (M*ᵥ (fun i => v i*p i))-p ⬝ᵥ (M*ᵥ (fun i => v' i*p i))| ≤ K*a := by + have he : p ⬝ᵥ (M*ᵥ (fun i => v i*p i))-p ⬝ᵥ (M*ᵥ (fun i => v' i*p i)) = + quadratic (M*Matrix.diagonal (fun i => v i-v' i)) p := by + simp only [quadratic,Matrix.mul_diagonal,dotProduct,Matrix.mulVec,Finset.mul_sum, + ←Finset.sum_sub_distrib] + apply Finset.sum_congr rfl + intro i _ + apply Finset.sum_congr rfl + intro j _ + ring + rw [he] + have hd := matrix_diagonal_opNorm_le (fun i => v i-v' i) a ha hv + have hnorm : euclideanOpNorm (M*Matrix.diagonal (fun i => v i-v' i)) ≤ K*a := by + unfold euclideanOpNorm + rw [map_mul] + exact (norm_mul_le _ _).trans (mul_le_mul hM hd (norm_nonneg _) hK) + simpa only [hp,mul_one] using (quadratic_abs_le _ p).trans + (mul_le_mul_of_nonneg_right hnorm (Finset.sum_nonneg (fun i _ => sq_nonneg (p i)))) + +lemma deterministic_corrected_error (β : ℝ) (H p : Fin n → ℝ) + (hp : ∑ i, p i^2=1) : + |deterministicForm β H p-correctedForm β H p| ≤ |(∑ i, H i)/(n:ℝ)-β^2| := by + rw [deterministic_corrected,add_sub_cancel_left,abs_mul,abs_mul,abs_sub_comm] + have h1 := mul_le_mul_of_nonneg_left (siteMoment_one hp) (abs_nonneg ((∑ i, H i)/(n:ℝ)-β^2)) + have h2 := mul_le_mul_of_nonneg_left (siteMoment_v hp H) (abs_nonneg ((∑ i, H i)/(n:ℝ)-β^2)) + calc + _ ≤ |(∑ i, H i)/(n:ℝ)-β^2| *|siteMoment p (fun i => v (H i))| := by + gcongr + simpa only [mul_one] using h1 + _ ≤ _ := by simpa only [mul_one] using h2 + +lemma quantized_siteNorm_le (H H' : Fin n → ℝ) {s a : ℝ} + (hs : siteNorm H ≤ s) (he : siteNorm (fun i => H i-H' i) ≤ a) : siteNorm H' ≤ s+a := by + have hneg : siteNorm (fun i => H' i-H i)=siteNorm (fun i => H i-H' i) := by + rw [siteNorm_eq_sqrt,siteNorm_eq_sqrt] + congr 2 + apply Finset.sum_congr rfl + intro i _ + ring + have ht := siteNorm_add H (fun i => H' i-H i) + have hid : (fun i => H i+(H' i-H i))=H' := by ext i; ring + rw [hid,hneg] at ht + linarith only [ht,hs,he] + +theorem reducedForm_upper_rare {β C e : ℝ} (hβ : 0 < β) (he : 0 < e) + (hscalar : ∀ b r : ℝ → ℝ, MemLp b 2 (fieldLaw β) → MemLp r 2 (fieldLaw β) → + (∫ x, b x^2+r x^2 ∂fieldLaw β)=1 → variational β b r ≤ C) : + ExponentiallyRare (fun n => standardArrayLaw (Fin n × Fin n)) + (fun n => {g | ∃ p : Fin n → ℝ, (∑ i, p i^2)=1 ∧ C+6*e < reducedForm β g p}) := by + let K := 2*β+2*β^2+2 + have hK : 0 ≤ K := by dsimp [K]; positivity + obtain ⟨a,R,N,ha,ha1,hR,hN,htotal,hv,hmv,hf,hk,hpop,herr⟩ := + scalar_quantizer_exists (augmentedField_squareTails β hβ) hβ hK he hscalar + let q := intervalBin (gridCut R N) + let h := gridRep R N + have hq : Measurable q := measurable_intervalBin (Nat.succ_pos N) (gridCut_strictMono hR hN) + have hnull : NullSingletonClass (fieldLaw β) := by + unfold fieldLaw + exact nullSingletonClass_gaussianReal (variance_ne_zero hβ) + have hemp := augmentedField_empirical β hβ + have hcount := intervalBin_binSize_rare (Nat.succ_pos N) (gridCut_strictMono hR hN) hemp + (intervalBin_mass_pos (Nat.succ_pos N) (gridCut_strictMono hR hN) β hβ.ne') + obtain ⟨δ,hδ,htol⟩ := finiteV_population_tolerance (μ := fieldLaw β) hq β h he + have hroot := (intervalBin_roots_empirical (Nat.succ_pos N) (gridCut_strictMono hR hN) hemp) δ hδ + have hmean := (augmentedField_firstMoment β hβ) e he + have hsize := (augmentedField_siteNorm β hβ) 1 (by norm_num) + obtain ⟨L,hL⟩ := random_binForm_tail (C := C+2*e) hβ hK he h q hq + let E := fun n => {g : (Fin n × Fin n) → ℝ | + (∀ d, 2 ≤ count (fun i => q (augmentedField β g i)) d) ∧ + (∀ z, finiteV β (binT (fun i => q (augmentedField β g i))) h z ≤ C+2*e) ∧ + g ∈ binFormBad β h (fun i => q (augmentedField β g i)) K ((C+2*e)+2*e)} + have hE : ExponentiallyRare (fun n => standardArrayLaw (Fin n × Fin n)) E := by + refine ⟨(L:ℝ)+1,e^2/(π^2*β^2),by positivity,by positivity [pi_pos],?_⟩ + filter_upwards [eventually_gt_atTop 0] with n hn + rw [←ENNReal.ofReal_toReal (measure_ne_top (standardArrayLaw (Fin n × Fin n)) (E n))] + apply ENNReal.ofReal_le_ofReal + have ht := hL hn + have hexp : -e^2*(n:ℝ)/(π^2*β^2)= -(e^2/(π^2*β^2))*(n:ℝ) := by ring + rw [hexp] at ht + exact ht.trans (by nlinarith only [exp_pos (-(e^2/(π^2*β^2))*(n:ℝ))]) + apply ((((((residual_norm_rare hβ).union herr).union hcount).union hroot).union hmean).union hsize).union hE |>.mono + filter_upwards [eventually_gt_atTop 0] with n hn + rintro g ⟨p,hp,hbad⟩ + by_contra hb + have hM : euclideanOpNorm (fieldProjection n*(β • goe g)*fieldProjection n) ≤ K := + not_lt.mp (fun hx => hb (Or.inl (Or.inl (Or.inl (Or.inl (Or.inl (Or.inl hx))))))) + have herr' : siteNorm (fun i => augmentedField β g i-gridQuant R N (augmentedField β g i)) < a := + lt_of_not_ge (fun hx => hb (Or.inl (Or.inl (Or.inl (Or.inl (Or.inl (Or.inr hx))))))) + have hcount' : ∀ d, 2 ≤ count (fun i => q (augmentedField β g i)) d := by + intro d + exact not_lt.mp (fun hx => hb (Or.inl (Or.inl (Or.inl (Or.inl (Or.inr ⟨d,hx⟩)))))) + have hroot' : dist (binT (fun i => q (augmentedField β g i))) (massRoot (fieldLaw β) q) < δ := + lt_of_not_ge (fun hx => hb (Or.inl (Or.inl (Or.inl (Or.inr hx))))) + have hmean' : |(∑ i, augmentedField β g i)/(n:ℝ)-β^2| < e := + lt_of_not_ge (fun hx => hb (Or.inl (Or.inl (Or.inr hx)))) + have hsize' : siteNorm (augmentedField β g) < sqrt (β^2+β^4)+1 := by + have hh : |siteNorm (augmentedField β g)-sqrt (β^2+β^4)| < 1 := + lt_of_not_ge (fun hx => hb (Or.inl (Or.inr hx))) + have hh' := (le_abs_self _).trans_lt hh + linarith only [hh'] + have hfinite : ∀ z, finiteV β (binT (fun i => q (augmentedField β g i))) h z ≤ C+2*e := by + intro z + have hne : ∀ d, |binT (fun i => q (augmentedField β g i)) d-massRoot (fieldLaw β) q d| < δ := + fun d => by simpa only [Real.dist_eq] using (dist_pi_lt_iff hδ).mp hroot' d + have h1 := htol hn _ hne z + have h2 := hpop z + change finiteV β (massRoot (fieldLaw β) q) h z < C+e at h2 + linarith only [h1,h2] + have hform : p ⬝ᵥ ((fieldProjection n*(β • goe g)*fieldProjection n)*ᵥ + (fun i => v (h (q (augmentedField β g i)))*p i))+ + correctedForm β (fun i => h (q (augmentedField β g i))) p ≤ C+4*e := by + apply not_lt.mp + intro hh + apply hb + exact Or.inr ⟨hcount',hfinite,hM, p,hp,by linarith only [hh]⟩ + have hsquant : siteNorm (fun i => gridQuant R N (augmentedField β g i)) ≤ sqrt (β^2+β^4)+2 := by + have ht := quantized_siteNorm_le _ _ hsize'.le herr'.le + linarith only [ht,ha1] + have hcf := correctedForm_field_error hn β (augmentedField β g) + (fun i => gridQuant R N (augmentedField β g i)) p hp ha.le ha.le + (show 0 ≤ sqrt (β^2+β^4)+2 by positivity) herr'.le hsquant + (fun i => hv _) (fun i => hmv _) + (by intro i j; simpa only [compactF_weight] using hf (augmentedField β g i) (augmentedField β g j)) + (by intro i j; simpa only [compactK_weight] using hk (augmentedField β g i) (augmentedField β g j)) + have hbil := variance_bilinear_field_error (fieldProjection n*(β • goe g)*fieldProjection n) + (fun i => v (augmentedField β g i)) (fun i => v (gridQuant R N (augmentedField β g i))) p + hp hK ha.le hM (fun i => hv _) + have hcor := deterministic_corrected_error β (augmentedField β g) p hp + rw [reducedForm_decomposition hn] at hbad + have hsum : 0 ≤ 4*β*sqrt a := by positivity + change p ⬝ᵥ ((fieldProjection n*(β • goe g)*fieldProjection n)*ᵥ + (fun i => v (gridQuant R N (augmentedField β g i))*p i))+ + correctedForm β (fun i => gridQuant R N (augmentedField β g i)) p ≤ C+4*e at hform + have hcf' := (le_abs_self _).trans hcf + have hbil' := (le_abs_self _).trans hbil + have hcor' := (le_abs_self _).trans hcor + linarith only [hbad,hform,hcf',hbil',hcor',htotal,hmean',hsum] + +end SKRatio.Bins + +namespace SKRatio.Planted +open Bins Scalar SKRatioClock.Regression Calculus +attribute [local instance] Classical.propDecidable + +theorem formBad_rare_of_scalar {β C : ℝ} (hβ : 0 < β) (hC : C < 1) + (hscalar : ∀ b r : ℝ → ℝ, MemLp b 2 (fieldLaw β) → MemLp r 2 (fieldLaw β) → + (∫ x, b x^2+r x^2 ∂fieldLaw β)=1 → variational β b r ≤ C) : + ∃ ρ : ℝ, 0 < ρ ∧ ExponentiallyRare (law β) (formBad ρ) := by + let e := (1-C)/10 + have he : 0 < e := by dsimp [e]; positivity + have hred := reducedForm_upper_rare hβ he hscalar + have herr := reduced_error_rare hβ he + have hbad : ExponentiallyRare (fun n => standardArrayLaw (Fin n × Fin n)) + (fun n => (augmentedDisorder β) ⁻¹' formBad e n) := by + apply (hred.union herr).mono + exact .of_forall (fun n g hg => by + obtain ⟨p,hp,hbad⟩ := (formBad_iff_unit e _).mp hg + by_contra hnot + have hr : reducedForm β g p ≤ C+6*e := not_lt.mp (fun hx => hnot (Or.inl ⟨p,hp,hx⟩)) + have hu : |gradientForm (coupling (augmentedDisorder β g)) p-reducedForm β g p| ≤ e := by + have hh : |gradientForm (coupling (augmentedDisorder β g)) p-reducedForm β g p| ≤ + e*(∑ i, p i^2) := not_lt.mp (fun hx => hnot (Or.inr ⟨p,hx⟩)) + simpa only [hp,mul_one] using hh + have hle := (le_abs_self _).trans hu + dsimp [e] at hr hu hbad hle + linarith only [hr,hbad,hle,hC]) + obtain ⟨A,c,hA,hc,hrare⟩ := hbad + refine ⟨e,he,A,c,hA,hc,?_⟩ + filter_upwards [hrare,eventually_gt_atTop 0] with n hn hn0 + have hl := (augmentedDisorder_hasLaw hn0 β).measure_eq (formBad_measurable e n) + exact hl.symm.le.trans hn + +theorem ratio_cutoff_of_scalar (β ε η C : ℝ) + (hβ : 0 < β) (hβhalf : β < 1/2) (hε : 0 < ε) (hεhalf : ε < 1/2) (hη : 0 < η) + (hC : C < 1) + (hscalar : ∀ b r : ℝ → ℝ, MemLp b 2 (fieldLaw β) → MemLp r 2 (fieldLaw β) → + (∫ x, b x^2+r x^2 ∂fieldLaw β)=1 → variational β b r ≤ C) : + Tendsto (fun n : ℕ => disorderLaw β n + {g : Disorder n | 1+η < (mixingTime g ε : ℝ)/(mixingTime g (1-ε) : ℝ)}) atTop (𝓝 0) ∧ + (∀ᶠ n : ℕ in atTop, ∀ g : Disorder n, 0 < mixingTime g (1-ε)) := by + obtain ⟨ρ,hρ,hρrare⟩ := formBad_rare_of_scalar hβ hC hscalar + obtain ⟨κ,hκ,hplant⟩ := hρrare.without_prefactor + exact ratio_cutoff_of_planted_form β ε η hβ.le hβhalf hε hεhalf hη hρ hκ hplant + +end SKRatio.Planted + +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Variational/ScalarVariance.lean b/lean/OAI/Probability/SKRatio/Variational/ScalarVariance.lean new file mode 100644 index 0000000000000000000000000000000000000000..2c44693cf722f9fbb4d35ce3683785ec0b782a09 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Variational/ScalarVariance.lean @@ -0,0 +1,180 @@ +import Mathlib +import OAI.Probability.SKRatio.Variational.ScalarCoherent +import OAI.Probability.SKRatio.Variational.ScalarTemperature + +namespace OAI + +noncomputable section +open scoped Topology ENNReal NNReal +open MeasureTheory ProbabilityTheory Real +namespace SKRatio.Scalar + +section Norm +variable {μ : Measure ℝ} + +lemma l2Norm_add {f g : ℝ → ℝ} (hf : MemLp f 2 μ) (hg : MemLp g 2 μ) : + l2Norm μ (fun x => f x+g x) ≤ l2Norm μ f+l2Norm μ g := by + have he := integral_square_add hf hg 1 1 + simp only [one_mul,one_pow,mul_one] at he + have hcs := (le_abs_self _).trans (abs_integral_mul_le hf hg) + apply (sq_le_sq₀ (l2Norm_nonneg _) (add_nonneg (l2Norm_nonneg _) (l2Norm_nonneg _))).mp + rw [l2Norm_sq,he] + nlinarith only [hcs,l2Norm_sq (μ := μ) f,l2Norm_sq (μ := μ) g] + +lemma l2Norm_const_mul (f : ℝ → ℝ) (c : ℝ) : + l2Norm μ (fun x => c*f x) = |c| *l2Norm μ f := by + apply (sq_eq_sq₀ (l2Norm_nonneg _) (mul_nonneg (abs_nonneg _) (l2Norm_nonneg _))).mp + simp only [l2Norm_sq,mul_pow,integral_const_mul,sq_abs] + +end Norm +section Probability +variable {μ ν : Measure ℝ} [IsProbabilityMeasure μ] [IsProbabilityMeasure ν] + +omit [IsProbabilityMeasure μ] in +lemma sd_sq (f : ℝ → ℝ) : sd μ f^2 = ∫ x, centered μ f x^2 ∂μ := l2Norm_sq _ + +lemma sd_sq_eq {f : ℝ → ℝ} (hf : MemLp f 2 μ) : + sd μ f^2 = (∫ x, f x^2 ∂μ)-(∫ x, f x ∂μ)^2 := by + rw [sd_sq] + exact integral_centered_sq hf + +lemma square_center_expansion {f : ℝ → ℝ} (hf : MemLp f 2 μ) (c : ℝ) : + ∫ x, (f x-c)^2 ∂μ = sd μ f^2+((∫ x, f x ∂μ)-c)^2 := by + have he := integral_square_add hf (memLp_const (1:ℝ)) 1 (-c) + simp only [one_mul,one_pow,mul_one,one_mul,←sub_eq_add_neg,neg_sq, + integral_const,probReal_univ,smul_eq_mul,one_mul] at he + rw [he,sd_sq_eq hf] + ring + +lemma sd_min_center {f : ℝ → ℝ} (hf : MemLp f 2 μ) (c : ℝ) : + sd μ f^2 ≤ ∫ x, (f x-c)^2 ∂μ := by + rw [square_center_expansion hf c] + exact le_add_of_nonneg_right (sq_nonneg _) + +omit [IsProbabilityMeasure μ] in +lemma centered_add {f g : ℝ → ℝ} (hf : Integrable f μ) (hg : Integrable g μ) : + centered μ (fun x => f x+g x) = fun x => centered μ f x+centered μ g x := by + ext x + simp only [centered,integral_add hf hg] + ring + +omit [IsProbabilityMeasure μ] in +lemma centered_const_mul (f : ℝ → ℝ) (c : ℝ) : + centered μ (fun x => c*f x) = fun x => c*centered μ f x := by + ext x + simp only [centered,integral_const_mul] + ring + +lemma centered_sub_const {f : ℝ → ℝ} (hf : Integrable f μ) (c : ℝ) : + centered μ (fun x => f x-c) = centered μ f := by + ext x + simp only [centered,integral_sub hf (integrable_const _),integral_const, + probReal_univ,smul_eq_mul,one_mul] + ring + +lemma sd_add {f g : ℝ → ℝ} (hf : MemLp f 2 μ) (hg : MemLp g 2 μ) : + sd μ (fun x => f x+g x) ≤ sd μ f+sd μ g := by + unfold sd + rw [centered_add (hf.integrable (by norm_num)) (hg.integrable (by norm_num))] + exact l2Norm_add (memLp_centered hf) (memLp_centered hg) + +omit [IsProbabilityMeasure μ] in +lemma sd_const_mul (f : ℝ → ℝ) (c : ℝ) : + sd μ (fun x => c*f x) = |c| *sd μ f := by + unfold sd + rw [centered_const_mul,l2Norm_const_mul] + +lemma sd_sub_const {f : ℝ → ℝ} (hf : MemLp f 2 μ) (c : ℝ) : + sd μ (fun x => f x-c) = sd μ f := by + unfold sd + rw [centered_sub_const (hf.integrable (by norm_num))] + +lemma sd_sub {f g : ℝ → ℝ} (hf : MemLp f 2 μ) (hg : MemLp g 2 μ) : + sd μ (fun x => f x-g x) ≤ sd μ f+sd μ g := by + have he (x : ℝ) : f x-g x = f x+(-1)*g x := by ring + simp_rw [he] + have hh := sd_add hf (hg.const_mul (-1)) + simpa only [sd_const_mul,abs_neg,abs_one,one_mul] using hh + +lemma abs_sd_sub_le {f g : ℝ → ℝ} (hf : MemLp f 2 μ) (hg : MemLp g 2 μ) : + |sd μ f-sd μ g| ≤ sd μ (fun x => f x-g x) := by + have h1 := sd_add (hf.sub hg) hg + have h2 := sd_sub hf (hf.sub hg) + simp only [Pi.sub_apply,sub_add_cancel,sub_sub_cancel] at h1 h2 + change sd μ f ≤ sd μ (fun x => f x-g x)+sd μ g at h1 + change sd μ g ≤ sd μ f+sd μ (fun x => f x-g x) at h2 + exact abs_le.mpr ⟨by linarith,by linarith⟩ + +lemma sd_mono_measure {C : ℝ} (hC : 0 ≤ C) + (hμν : μ ≤ ENNReal.ofReal C • ν) + {f : ℝ → ℝ} (hf : MemLp f 2 μ) (hf' : MemLp f 2 ν) : + sd μ f^2 ≤ C*sd ν f^2 := by + calc + sd μ f^2 ≤ ∫ x, (f x-(∫ y, f y ∂ν))^2 ∂μ := sd_min_center hf _ + _ ≤ ∫ x, (f x-(∫ y, f y ∂ν))^2 ∂(ENNReal.ofReal C • ν) := + integral_mono_measure hμν (ae_of_all _ (fun _ => sq_nonneg _)) + ((memLp_centered hf').integrable_sq.smul_measure ENNReal.ofReal_ne_top) + _ = C*sd ν f^2 := by + rw [integral_smul_measure,ENNReal.toReal_ofReal hC,smul_eq_mul,sd_sq] + rfl + +lemma sd_mono_measure_sqrt {C : ℝ} (hC : 0 ≤ C) + (hμν : μ ≤ ENNReal.ofReal C • ν) + {f : ℝ → ℝ} (hf : MemLp f 2 μ) (hf' : MemLp f 2 ν) : + sd μ f ≤ sqrt C*sd ν f := by + apply (sq_le_sq₀ (sd_nonneg _) (mul_nonneg (sqrt_nonneg _) (sd_nonneg _))).mp + rw [mul_pow,sq_sqrt hC] + exact sd_mono_measure hC hμν hf hf' + +lemma weighted_sd_mono_measure {B Z : ℝ} (hB : 0 ≤ B) (hZ : 0 ≤ Z) + (hμν : ENNReal.ofReal B • μ ≤ ENNReal.ofReal Z • ν) + {f : ℝ → ℝ} (hf : MemLp f 2 μ) (hf' : MemLp f 2 ν) : + B*sd μ f^2 ≤ Z*sd ν f^2 := by + calc + B*sd μ f^2 ≤ B*(∫ x, (f x-(∫ y, f y ∂ν))^2 ∂μ) := + mul_le_mul_of_nonneg_left (sd_min_center hf _) hB + _ = ∫ x, (f x-(∫ y, f y ∂ν))^2 ∂(ENNReal.ofReal B • μ) := by + rw [integral_smul_measure,ENNReal.toReal_ofReal hB,smul_eq_mul] + _ ≤ ∫ x, (f x-(∫ y, f y ∂ν))^2 ∂(ENNReal.ofReal Z • ν) := + integral_mono_measure hμν (ae_of_all _ (fun _ => sq_nonneg _)) + ((memLp_centered hf').integrable_sq.smul_measure ENNReal.ofReal_ne_top) + _ = Z*sd ν f^2 := by + rw [integral_smul_measure,ENNReal.toReal_ofReal hZ,smul_eq_mul,sd_sq] + rfl +end Probability + +lemma weighted_sd_temperature_mono {β z : ℝ} (hβ : 0 < β) (hβz : β ≤ z) (hz : z ≤ 1) + {f : ℝ → ℝ} (hf : MemLp f 2 (fieldLaw β)) (hf' : MemLp f 2 (fieldLaw z)) : + β^2*sd (fieldLaw β) f^2 ≤ z^2*sd (fieldLaw z) f^2 := + weighted_sd_mono_measure (sq_nonneg _) (sq_nonneg _) + (scaled_fieldLaw_mono hβ hβz hz) hf hf' + +lemma weighted_sd_temperature_mono' {β z : ℝ} (hβ : 0 < β) (hβz : β ≤ z) (hz : z ≤ 1) + {f : ℝ → ℝ} (hf : MemLp f 2 (fieldLaw β)) (hf' : MemLp f 2 (fieldLaw z)) : + β*sd (fieldLaw β) f ≤ z*sd (fieldLaw z) f := by + apply (sq_le_sq₀ (mul_nonneg hβ.le (sd_nonneg _)) + (mul_nonneg (hβ.le.trans hβz) (sd_nonneg _))).mp + simpa only [mul_pow] using weighted_sd_temperature_mono hβ hβz hz hf hf' + +lemma weighted_mv_temperature_mono {β z : ℝ} (hβ : 0 < β) (hβz : β ≤ z) (hz : z ≤ 1) : + β^2*(∫ h, m h*v h ∂fieldLaw β) ≤ z^2*(∫ h, m h*v h ∂fieldLaw z) := by + simp_rw [mean_mv_eq_mean_m_sq_v] + apply scaled_integral_mono hβ hβz hz (fun h => mul_nonneg (sq_nonneg _) (v_pos h).le) + apply (integrable_const (1:ℝ)).mono' + ((continuous_m.pow 2).mul continuous_v).aestronglyMeasurable + apply ae_of_all + intro h + change |m h^2*v h| ≤ 1 + rw [abs_of_nonneg (mul_nonneg (sq_nonneg _) (v_pos h).le)] + exact (mul_le_mul_of_nonneg_right (tanh_sq_lt_one h).le (v_pos h).le).trans (by simpa using v_le_one h) + +lemma weighted_R_temperature_mono {β z : ℝ} (hβ : 0 < β) (hβz : β ≤ z) (hz : z ≤ 1) : + β^2*R β ≤ z^2*R z := by + apply scaled_integral_mono hβ hβz hz rho_nonneg + exact integrable_rho + +end SKRatio.Scalar + +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Variational/UniformDrift.lean b/lean/OAI/Probability/SKRatio/Variational/UniformDrift.lean new file mode 100644 index 0000000000000000000000000000000000000000..99771efe06d8d7a42661d648de34e776cfdaa35f --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Variational/UniformDrift.lean @@ -0,0 +1,180 @@ +import Mathlib +import OAI.Probability.SKRatio.Dynamics.Assembly +import OAI.Probability.SKRatio.Calculus.SpectralLower + +namespace OAI + +section +noncomputable section +open scoped BigOperators Topology Matrix +open MeasureTheory Filter +namespace SKRatio.Calculus +attribute [local instance] Classical.propDecidable + +lemma replace_difference_le {n : ℕ} (f : Observables n) {a : ℝ} (ha : 0 ≤ a) + (h : ∀ x i, |halfDiff i f x| ≤ a) (x : Spin n) (i : Fin n) (b : Bool) : + |f (replace x i b)-f x| ≤ 2*a := by + by_cases hb : b = x i + · subst b + rw [replace_self,sub_self,abs_zero] + positivity + · have he : b = !(x i) := by cases hi : x i <;> cases b <;> simp_all + rw [he] + change |f (flip i x)-f x| ≤ 2*a + rw [flip_sub,abs_mul,abs_mul] + have hs : |spin x i| = 1 := by cases hi : x i <;> simp [spin,hi] + rw [hs] + norm_num + linarith [h x i] + +lemma oscillation_le_of_halfDiff {n : ℕ} (f : Observables n) {a : ℝ} (ha : 0 ≤ a) + (h : ∀ x i, |halfDiff i f x| ≤ a) (x y : Spin n) : + |f x-f y| ≤ 2*(n:ℝ)*a := by + have hp (k : ℕ) (hk : k ≤ n) : + |f (updatePath x y k)-f x| ≤ 2*(k:ℝ)*a := by + induction k with + | zero => simp + | succ k ih => + have hk' : k < n := by omega + have hstep := replace_difference_le f ha h (updatePath x y k) ⟨k,hk'⟩ (y ⟨k,hk'⟩) + change |f (Function.update (updatePath x y k) ⟨k,hk'⟩ (y ⟨k,hk'⟩)) - + f (updatePath x y k)| ≤ 2*a at hstep + rw [←updatePath_succ x y k hk'] at hstep + have htri := abs_sub_le (f (updatePath x y (k+1))) (f (updatePath x y k)) (f x) + have hprev := ih (by omega) + push_cast + linarith + simpa only [updatePath_end,abs_sub_comm] using hp n le_rfl + +lemma halfDiff_le_sqrt_gradient {n : ℕ} (f : Observables n) {B : ℝ} + (hB : ∀ x, unweightedGradient f x ≤ B) (x : Spin n) (i : Fin n) : + |halfDiff i f x| ≤ Real.sqrt B := by + have hsq : (halfDiff i f x)^2 ≤ B := + (Finset.single_le_sum (fun j _ => sq_nonneg (halfDiff j f x)) (Finset.mem_univ i)).trans (hB x) + exact (Real.sqrt_sq_eq_abs _).symm ▸ Real.sqrt_le_sqrt hsq + +lemma mean_difference_le_of_oscillation {n : ℕ} (g : Disorder n) (f : Observables n) + {B : ℝ} (hosc : ∀ x y, |f x-f y| ≤ B) (x : Spin n) : + |f x-FiniteLaw.mean (mass g 0) f| ≤ B := by + have hid : f x-FiniteLaw.mean (mass g 0) f = + ∑ y, mass g 0 y*(f x-f y) := by + simp only [mul_sub,Finset.sum_sub_distrib,←Finset.sum_mul,sum_mass,one_mul,FiniteLaw.mean] + rw [hid] + calc + _ ≤ ∑ y, |mass g 0 y*(f x-f y)| := Finset.abs_sum_le_sum_abs _ _ + _ ≤ ∑ y, mass g 0 y*B := by + apply Finset.sum_le_sum + intro y _ + rw [abs_mul,abs_of_nonneg (mass_nonneg g 0 y)] + exact mul_le_mul_of_nonneg_left (hosc x y) (mass_nonneg g 0 y) + _ = B := by rw [←Finset.sum_mul,sum_mass,one_mul] + +theorem distance_upper_of_uniform_gradient_drift {n : ℕ} (g : Disorder n) {κ t : ℝ} + (ht : 0 ≤ t) + (hgrad : ∀ f : Observables n, ∀ r : ℝ, ∀ y, + deriv (fun v => unweightedGradient (semigroup (coupling g) v f) y) r - + generator (coupling g) (unweightedGradient (semigroup (coupling g) r f)) y ≤ + -κ*unweightedGradient (semigroup (coupling g) r f) y) : + continuousDistance g t ≤ (n:ℝ)*Real.sqrt ((n:ℝ)*Real.exp (-κ*t)) := by + apply Finset.sup'_le + intro x _ + apply FiniteLaw.totalVariation_le_of_tests + intro f hf + rw [←semigroup_eq_kernel,←gibbsMean_semigroup g t f] + have hB (y : Spin n) : unweightedGradient (semigroup (coupling g) t f) y ≤ + (n:ℝ)*Real.exp (-κ*t) := by + simpa only [mul_comm] using gradient_envelope_of_drift (coupling g) f ht + (fun r _ y => hgrad f r y) (unweightedGradient_le_dim f hf) y + have ho := oscillation_le_of_halfDiff (semigroup (coupling g) t f) (Real.sqrt_nonneg _) + (halfDiff_le_sqrt_gradient _ hB) + exact (mean_difference_le_of_oscillation g _ ho x).trans_eq (by ring) + +theorem uniform_median_upper_of_uniform_gradient + (G : ∀ n : ℕ, Set (Disorder n)) {κ : ℝ} (hκ : 0 < κ) + (hgrad : ∀ n, ∀ g ∈ G n, ∀ f : Observables n, ∀ r : ℝ, ∀ y, + deriv (fun v => unweightedGradient (semigroup (coupling g) v f) y) r - + generator (coupling g) (unweightedGradient (semigroup (coupling g) r f)) y ≤ + -κ*unweightedGradient (semigroup (coupling g) r f) y) : + ∀ᶠ n : ℕ in atTop, ∀ g ∈ G n, medianTime g ≤ (4/κ)*Real.log n := by + have hlim := (dimensionDecay_tendsto_zero (by norm_num : (0:ℝ)<1)).sqrt + simp only [Real.sqrt_zero] at hlim + filter_upwards [eventually_gt_atTop (1:ℕ), hlim.eventually (gt_mem_nhds (by norm_num : (0:ℝ)<1/2))] + with n hn hbound + intro g hg + have ht : 0 ≤ (4/κ)*Real.log n := by positivity + have he : -κ*((4/κ)*Real.log n) = -(4:ℝ)*Real.log n := by field_simp + have hid : (n:ℝ)*Real.sqrt ((n:ℝ)*Real.exp (-κ*((4/κ)*Real.log n))) = + Real.sqrt (dimensionDecay 1 n) := by + rw [he] + change (n:ℝ)*Real.sqrt ((n:ℝ)*dimensionDecay 4 n) = _ + have hsq : (n:ℝ)^2*((n:ℝ)*dimensionDecay 4 n) = dimensionDecay 1 n := by + calc + _ = (n:ℝ)*((n:ℝ)*((n:ℝ)*dimensionDecay 4 n)) := by ring + _ = (n:ℝ)*((n:ℝ)*dimensionDecay 3 n) := by rw [nat_mul_dimensionDecay (by omega)];norm_num + _ = (n:ℝ)*dimensionDecay 2 n := by rw [nat_mul_dimensionDecay (by omega)];norm_num + _ = dimensionDecay 1 n := by rw [nat_mul_dimensionDecay (by omega)];norm_num + rw [←hsq,Real.sqrt_mul (sq_nonneg _),Real.sqrt_sq (Nat.cast_nonneg _)] + apply (medianTime_le_iff g ht).mpr + exact (distance_upper_of_uniform_gradient_drift g ht (hgrad n g hg)).trans (hid ▸ hbound.le) + +theorem ratio_cutoff_of_uniform_gradient (β ε η : ℝ) + (hε : 0 < ε) (hε1 : ε < 1) (hη : 0 < η) + (G : ∀ n : ℕ, Set (Disorder n)) {κ γ K : ℝ} + (hκ : 0 < κ) (hγ : 0 < γ) (hK : 0 < K) + (hG : Tendsto (fun n => disorderLaw β n (G n)ᶜ) atTop (𝓝 0)) + (hnorm : ∀ n, ∀ g ∈ G n, euclideanOpNorm (coupling g) ≤ K) + (hgap : ∀ n, ∀ g ∈ G n, ∀ f : Observables n, + γ*FiniteLaw.variance (mass g 0) f ≤ stationaryEnergy g f) + (hgrad : ∀ n, ∀ g ∈ G n, ∀ f : Observables n, ∀ r : ℝ, ∀ y, + deriv (fun v => unweightedGradient (semigroup (coupling g) v f) y) r - + generator (coupling g) (unweightedGradient (semigroup (coupling g) r f)) y ≤ + -κ*unweightedGradient (semigroup (coupling g) r f) y) : + Tendsto + (fun n : ℕ => disorderLaw β n + {g : Disorder n | 1+η < + (mixingTime g ε : ℝ)/(mixingTime g (1-ε) : ℝ)}) + atTop (𝓝 0) ∧ + (∀ᶠ n : ℕ in atTop, ∀ g : Disorder n, 0 < mixingTime g (1-ε)) := by + let bad : ∀ n, Disorder n → Set (Spin n) := fun _ _ => ∅ + have hgp : ∀ᶠ n : ℕ in atTop, ∀ g ∈ G n, ∀ f : Observables n, + γ*FiniteLaw.variance (mass g 0) f ≤ stationaryEnergy g f := Eventually.of_forall hgap + have hgd (D : ℝ) (_hD : 0 < D) : ∀ᶠ n : ℕ in atTop, ∀ g ∈ G n, + ∀ f : Observables n, ∀ r ∈ Set.Icc (0:ℝ) (D*Real.log n), ∀ y, + deriv (fun v => unweightedGradient (semigroup (coupling g) v f) y) r - + generator (coupling g) (unweightedGradient (semigroup (coupling g) r f)) y ≤ + (-κ + if y ∈ bad n g then 0 else 0)* + unweightedGradient (semigroup (coupling g) r f) y := by + apply Eventually.of_forall + intro n g hg f r hr y + simpa only [ite_self,add_zero] using hgrad n g hg f r y + have hav (D m : ℝ) (_hD : 0 < D) (_hm : 0 < m) : + ∀ᶠ n : ℕ in atTop, ∀ g ∈ G n, ∀ u ∈ Set.Icc (0:ℝ) (D*Real.log n), ∀ x, + semigroup (coupling g) u (fun y => if y ∈ bad n g then 1 else 0) x ≤ dimensionDecay m n := by + apply Eventually.of_forall + intro n g hg u hu x + simpa [bad,semigroup_const] using (dimensionDecay_pos m n).le + have hrow : ∀ᶠ n : ℕ in atTop, ∀ g ∈ G n, ∀ i, ∑ j, coupling g i j ^ 2 ≤ K^2 := by + apply Eventually.of_forall + intro n g hg i + exact row_squares_le_opNorm (coupling g) (coupling_symm g) hK.le (hnorm n g hg) i + have hfields := uniform_field_tails_of_small_set G bad hκ (le_refl 0) (le_refl 0) + hγ (sq_nonneg K) hrow hgp (by simpa only [ite_self] using hgd) + (by simpa only [bad,Set.mem_empty_iff_false,ite_false] using hav) + have hlag := uniform_positive_lag_of_small_set_gradient G bad hκ (le_refl 0) + (le_refl 0) hγ hgp (by simpa only [ite_self] using hgd) + (by simpa only [bad,Set.mem_empty_iff_false,ite_false] using hav) hfields + have hlo := uniform_median_lower_of_small_set G bad hκ (le_refl 0) (le_refl 0) hγ hgp (by simpa only [ite_self] using hgd) + (by simpa only [bad,Set.mem_empty_iff_false,ite_false] using hav) + have hup := uniform_median_upper_of_uniform_gradient G hκ hgrad + apply ratio_cutoff_of_positive_lag β ε η hε hε1 hη G (c := 1/4) (C := 4/κ) + (by norm_num) hK hnorm hG _ hlag + filter_upwards [hlo,hup] with n hnlo hnup + intro g hg + exact ⟨by simpa only [one_div_mul_eq_div] using hnlo g hg,hnup g hg⟩ + +end SKRatio.Calculus + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKRatio/Variational/UniformGap.lean b/lean/OAI/Probability/SKRatio/Variational/UniformGap.lean new file mode 100644 index 0000000000000000000000000000000000000000..e97344f6c9592639779de09e80d93d8c6bad3046 --- /dev/null +++ b/lean/OAI/Probability/SKRatio/Variational/UniformGap.lean @@ -0,0 +1,150 @@ +import Mathlib +import OAI.Probability.SKRatio.Calculus.SpectralLower +import OAI.Probability.SKRatio.Calculus.Curvature + +namespace OAI + +section +noncomputable section +open scoped BigOperators RealInnerProductSpace +namespace SKRatio.Fields +open Real Matrix Calculus +attribute [local instance] Classical.propDecidable +variable {n : ℕ} + +lemma coupling_smul (g : Disorder n) (s : ℝ) (i j : Fin n) : + coupling (s • g) i j = s*coupling g i j := by + unfold coupling + split_ifs <;> simp + +lemma euclideanOpNorm_smul (T : Interaction n) (s : ℝ) : + euclideanOpNorm (fun i j => s*T i j) = |s| *euclideanOpNorm T := by + have he : Matrix.toEuclideanCLM (𝕜 := ℝ) (n := Fin n) (fun i j => s*T i j) = + s • Matrix.toEuclideanCLM (𝕜 := ℝ) (n := Fin n) T := by + ext z i + change (∑ j, s*T i j*z j) = s*(∑ j, T i j*z j) + simp only [Finset.mul_sum,mul_assoc] + unfold euclideanOpNorm + rw [he,norm_smul,Real.norm_eq_abs] + +theorem scaled_poincare_of_matrix_bounds (g : Disorder n) {K B δ ρ : ℝ} + (hK : 0 ≤ K) (hB : 0 ≤ B) (hδ : 0 ≤ δ) (hδsmall : δ ≤ 1/1000) + (hρ : 0 < ρ) (hmargin : ρ ≤ 1-(K+δ*B/3)-3840000*(δ*B)) + (hBK : 2*B ≤ K) (hnorm : euclideanOpNorm (coupling g) ≤ K) + (he : ∀ i j, |coupling g i j| ≤ δ) (hrow : ∀ i, ∑ j, coupling g i j^2 ≤ B) + {s : ℝ} (hs : 0 ≤ s) (hs1 : s ≤ 1) (h : Fin n → ℝ) (f : Spin n → ℝ) : + ρ*variance (s • g) h f ≤ dirichlet (s • g) h f := by + apply poincare_of_matrix_bounds (s • g) hK hB hδ hδsmall hρ hmargin hBK + · simp only [show coupling (s • g) = fun i j => s*coupling g i j by + funext i j; exact coupling_smul g s i j,euclideanOpNorm_smul,abs_of_nonneg hs] + exact (mul_le_mul_of_nonneg_left hnorm hs).trans (by nlinarith [hK,hs1]) + · intro i j + rw [coupling_smul,abs_mul,abs_of_nonneg hs] + exact (mul_le_mul_of_nonneg_left (he i j) hs).trans (by nlinarith [hδ,hs1]) + · intro i + simp only [coupling_smul,mul_pow,←Finset.mul_sum] + apply le_trans (mul_le_mul_of_nonneg_left (hrow i) (sq_nonneg s)) + have hs2 : s^2 ≤ 1 := by nlinarith [mul_nonneg hs (sub_nonneg.mpr hs1)] + nlinarith [mul_nonneg hB (sub_nonneg.mpr hs2)] + +def linearObservable (a : Fin n → ℝ) (x : Spin n) : ℝ := ∑ i, a i*spinValue (x i) + +lemma spinGradient_linearObservable (a : Fin n → ℝ) (i : Fin n) (x : Spin n) : + spinGradient i (linearObservable a) x = a i := by + unfold spinGradient linearObservable + rw [←Finset.sum_sub_distrib] + have he : (∑ j, (a j*spinValue (Function.update x i true j)- + a j*spinValue (Function.update x i false j))) = 2*a i := by + rw [Finset.sum_eq_single i] + · simp;ring + · intro j _ hji + simp [Function.update_of_ne hji] + · simp + rw [he];ring + +lemma dirichlet_linearObservable (g : Disorder n) (h a : Fin n → ℝ) : + dirichlet g h (linearObservable a) ≤ ∑ i, a i^2 := by + rw [dirichlet_weighted] + apply Finset.sum_le_sum + intro i _ + simp only [spinGradient_linearObservable] + calc + _ ≤ expectation g h (fun _ => a i^2) := by + apply SKRatio.Fields.expectation_mono + intro x + exact mul_le_of_le_one_left (sq_nonneg (a i)) (siteVariance_le_one g h i x) + _ = _ := expectation_const g h _ + +theorem covariance_bound_of_poincare (g : Disorder n) (h : Fin n → ℝ) {ρ : ℝ} + (hρ : 0 < ρ) (hgap : ∀ f, ρ*variance g h f ≤ dirichlet g h f) (a : Fin n → ℝ) : + variance g h (linearObservable a) ≤ ρ⁻¹*(∑ i, a i^2) := by + have hg := (hgap (linearObservable a)).trans (dirichlet_linearObservable g h a) + rw [inv_mul_eq_div,le_div_iff₀ hρ] + simpa only [mul_comm ρ] using hg + +lemma heatBathGenerator_zero_field (g : Disorder n) (f : Spin n → ℝ) (x : Spin n) : + heatBathGenerator g 0 f x = -generator (coupling g) f x := by + simp only [heatBathGenerator,conditionalDifference_local,generator, + ←Finset.sum_neg_distrib] + apply Finset.sum_congr rfl + intro i _ + change (spinValue (x i)-tanh (0+field (coupling g) x i))*halfDiff i f x = + -((tanh (field (coupling g) x i)-spinValue (x i))*halfDiff i f x) + rw [zero_add];ring + +lemma variance_eq_finiteLaw (g : Disorder n) (h : Fin n → ℝ) (f : Spin n → ℝ) : + variance g h f = FiniteLaw.variance (mass g h) f := rfl + +lemma dirichlet_zero_eq_stationaryEnergy (g : Disorder n) (f : Spin n → ℝ) : + dirichlet g 0 f = stationaryEnergy g f := by + rw [←heatBathGenerator_form,stationaryEnergy_eq] + simp only [heatBathGenerator_zero_field,expectation,FiniteLaw.mean,mul_neg, + Finset.sum_neg_distrib] + +theorem stationary_poincare_of_matrix_bounds (g : Disorder n) {K B δ ρ : ℝ} + (hK : 0 ≤ K) (hB : 0 ≤ B) (hδ : 0 ≤ δ) (hδsmall : δ ≤ 1/1000) + (hρ : 0 < ρ) (hmargin : ρ ≤ 1-(K+δ*B/3)-3840000*(δ*B)) + (hBK : 2*B ≤ K) (hnorm : euclideanOpNorm (coupling g) ≤ K) + (he : ∀ i j, |coupling g i j| ≤ δ) (hrow : ∀ i, ∑ j, coupling g i j^2 ≤ B) + (f : Observables n) : ρ*FiniteLaw.variance (mass g 0) f ≤ stationaryEnergy g f := by + simpa only [variance_eq_finiteLaw,dirichlet_zero_eq_stationaryEnergy] using + poincare_of_matrix_bounds g hK hB hδ hδsmall hρ hmargin hBK hnorm he hrow 0 f + +theorem exists_uniform_gap_tolerance {β : ℝ} (hβ : 0 ≤ β) (hβhalf : β < 1/2) : + ∃ δ ρ : ℝ, 0 < δ ∧ 0 < ρ ∧ + ∀ n : ℕ, ∀ g : Disorder n, + euclideanOpNorm (coupling g) ≤ 2*β+δ → + (∀ i j, |coupling g i j| ≤ δ) → + (∀ i, ∑ j, coupling g i j^2 ≤ β^2+δ) → + ∀ s ∈ Set.Icc (0:ℝ) 1, ∀ h : Fin n → ℝ, + (∀ f, ρ*variance (s • g) h f ≤ dirichlet (s • g) h f) ∧ + (∀ a, variance (s • g) h (linearObservable a) ≤ ρ⁻¹*(∑ i, a i^2)) := by + let δ := min (1/1000:ℝ) ((1-2*β)/16000000) + let ρ := (1-2*β)/2 + have hd : 0 < δ := lt_min (by norm_num) (div_pos (by linarith) (by norm_num)) + have hdsmall : δ ≤ 1/1000 := min_le_left _ _ + have hdt : δ ≤ (1-2*β)/16000000 := min_le_right _ _ + have hr : 0 < ρ := by dsimp [ρ];linarith + refine ⟨δ,ρ,hd,hr,?_⟩ + intro n g hnorm he hrow s hs h + have hB : 0 ≤ β^2+δ := add_nonneg (sq_nonneg β) hd.le + have hB1 : β^2+δ ≤ 1 := by + nlinarith [mul_nonneg hβ (show 0 ≤ 1/2-β by linarith)] + have hBK : 2*(β^2+δ) ≤ 2*β+2*δ := by + nlinarith [mul_nonneg hβ (show 0 ≤ 1-β by linarith)] + have hmargin : ρ ≤ 1-(2*β+2*δ+δ*(β^2+δ)/3)-3840000*(δ*(β^2+δ)) := by + have he₁ : δ*(β^2+δ) ≤ δ := by nlinarith [mul_nonneg hd.le (sub_nonneg.mpr hB1)] + dsimp [ρ] + nlinarith only [he₁,hdt,hd.le] + have hg : ∀ f, ρ*variance (s • g) h f ≤ dirichlet (s • g) h f := fun f => + scaled_poincare_of_matrix_bounds g (by positivity : 0 ≤ 2*β+2*δ) + hB hd.le hdsmall hr hmargin hBK (hnorm.trans (by linarith)) + he hrow hs.1 hs.2 h f + exact ⟨hg,covariance_bound_of_poincare (s • g) h hr hg⟩ + +end SKRatio.Fields + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKSupport/Backward/Backward.lean b/lean/OAI/Probability/SKSupport/Backward/Backward.lean new file mode 100644 index 0000000000000000000000000000000000000000..06fb326a30a7cc77a98c8ba636df4163cb307151 --- /dev/null +++ b/lean/OAI/Probability/SKSupport/Backward/Backward.lean @@ -0,0 +1,105 @@ +import Mathlib +import OAI.Probability.SKSupport.Foundations.DerivWithinVarianceHeatWeightExp + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology ContDiff +noncomputable section +namespace ZeroTemperatureSK.Heat + +def backward (c T : ℝ) (f : ℝ → ℝ) (t x : ℝ) := varianceLogHeat c (T-t) f x + +def backwardRate (c T : ℝ) (f : ℝ → ℝ) (t x : ℝ) := + -(1/2:ℝ)*varianceTilted c (T-t) f (generatorWeight c f) x + +lemma backward_terminal (c T : ℝ) (f : ℝ → ℝ) (x : ℝ) : backward c T f T x = f x := by + unfold backward + rw [sub_self] + by_cases hc : c = 0 + · simp [varianceLogHeat, hc, varianceHeat_zero] + · simp [varianceLogHeat, hc, varianceHeat_zero, Real.log_exp, mul_div_cancel_left₀ _ hc] + +structure VerificationData (F D : ℝ → ℝ → ℝ) (c T : ℝ) : Prop where + smooth : ∀ t, ContDiff ℝ 3 (F t) + gradient_bound : ∀ t z, |deriv (F t) z| ≤ 1 + bounds : ∃ C₂ C₃ Ct L : ℝ≥0, + (∀ t z, |deriv (deriv (F t)) z| ≤ C₂) ∧ + (∀ t z, |iteratedDeriv 3 (F t) z| ≤ C₃) ∧ + (∀ t, Measurable (D t)) ∧ + (∀ t z, |D t z| ≤ Ct) ∧ + (∀ r ∈ Set.Icc (0:ℝ) T, ∀ z, + HasDerivWithinAt (fun t => F t z) (D r z) (Set.Icc (0:ℝ) T) r) ∧ + (∀ r ∈ Set.Icc (0:ℝ) T, ∀ s ∈ Set.Icc (0:ℝ) T, ∀ z y, + |D r z-D s y| ≤ (L:ℝ)*(|r-s|+|z-y|)) ∧ + (∀ t ∈ Set.Icc (0:ℝ) T, ∀ z, + D t z+(1/2:ℝ)*deriv (deriv (F t)) z+c/2*(deriv (F t) z)^2 = 0) + +lemma backward_verificationData {f : ℝ → ℝ} (hf : RegularDatum f) + (hLip : LipschitzWith 1 f) {c : ℝ} (hc : 0 ≤ c) (T : ℝ) : + VerificationData (backward c T f) (backwardRate c T f) c T := by + have hw := boundedSmooth_generatorWeight hf c + obtain ⟨C₂,hC₂⟩ := uniform_varianceLogHeat_derivative_bounds hf hLip hc 1 + obtain ⟨C₃,hC₃⟩ := uniform_varianceLogHeat_derivative_bounds hf hLip hc 2 + obtain ⟨G,hG⟩ := hw.bound + obtain ⟨L,hL⟩ := varianceTilted_joint_bound hf hLip hw hc + obtain ⟨A,hA⟩ := varianceTilted_space_lipschitz hf hLip hw hc + constructor + · intro t + exact (regularDatum_varianceLogHeat hf hLip hc (T-t)).smooth.of_le + (ENat.natCast_le_of_coe_top_le_withTop le_rfl 3) + · intro t z + exact norm_deriv_le_of_lipschitz (varianceLogHeat_lipschitz hLip hc (T-t)) + · refine ⟨C₂,C₃,G/2,L,?_,?_,?_,?_,?_,?_,?_⟩ + · intro t z + change |deriv (deriv (varianceLogHeat c (T-t) f)) z| ≤ C₂ + simpa only [iteratedDeriv_succ, iteratedDeriv_zero] using hC₂ (T-t) z + · intro t z + exact hC₃ (T-t) z + · intro t + exact measurable_const.mul (hA (T-t)).continuous.measurable + · intro t z + dsimp only [backwardRate] + rw [abs_mul, abs_neg, abs_of_pos (by norm_num : (0:ℝ)<1/2)] + have hb := varianceTilted_bound hLip hw.smooth.continuous.measurable hG c (T-t) z + simp only [NNReal.coe_div, NNReal.coe_ofNat] + linarith + · intro r hr z + have hd := (varianceLogHeat_time_derivative hf hLip c (sub_nonneg.mpr hr.2) z).comp r + (((hasDerivAt_const r T).sub (hasDerivAt_id r)).hasDerivWithinAt (s := Set.Icc (0:ℝ) T)) + (fun (s : ℝ) (hs : s ∈ Set.Icc (0:ℝ) T) => show 0 ≤ T-s from sub_nonneg.mpr hs.2) + convert hd using 1 <;> try rfl + dsimp only [backwardRate] + ring + · intro r hr s hs z y + have hb := hL (T-r) (sub_nonneg.mpr hr.2) (T-s) (sub_nonneg.mpr hs.2) z y + have he : |(T-r)-(T-s)| = |r-s| := by + rw [show (T-r)-(T-s) = -(r-s) by ring, abs_neg] + rw [he] at hb + dsimp only [backwardRate] + rw [← mul_sub, abs_mul, abs_neg, abs_of_pos (by norm_num : (0:ℝ)<1/2)] + have hn := abs_nonneg (varianceTilted c (T-r) f (generatorWeight c f) z- + varianceTilted c (T-s) f (generatorWeight c f) y) + linarith + · intro t ht z + have he := varianceLogHeat_generator_identity hf hLip c (sub_nonneg.mpr ht.2) z + change -(1/2:ℝ)*varianceTilted c (T-t) f (generatorWeight c f) z+ + (1/2:ℝ)*deriv (deriv (varianceLogHeat c (T-t) f)) z+ + c/2*(deriv (varianceLogHeat c (T-t) f) z)^2 = 0 + linarith + +end ZeroTemperatureSK.Heat + +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKSupport/Backward/BackwardComparison.lean b/lean/OAI/Probability/SKSupport/Backward/BackwardComparison.lean new file mode 100644 index 0000000000000000000000000000000000000000..ebb44f2dc1cf234d35e05e039c9e0a97c360da7c --- /dev/null +++ b/lean/OAI/Probability/SKSupport/Backward/BackwardComparison.lean @@ -0,0 +1,174 @@ +import Mathlib +import OAI.Probability.SKSupport.Parabolic.FullLineComparison +import OAI.Probability.SKSupport.Moments.BurgersJets + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology ContDiff +noncomputable section +namespace ZeroTemperatureSK.Heat + +lemma bounded_linear_nonpositive {F r Ft c : ℝ → ℝ → ℝ} {C : ℝ} + (hF : BoundedSmoothFamily F) (hr : BoundedSmoothFamily r) + (hcont : ∀ T, ContinuousOn (fun p : ℝ × ℝ => F p.1 p.2) (Icc (0:ℝ) T ×ˢ univ)) + (htime : ∀ t, 0 < t → ∀ x, HasDerivAt (fun s => F s x) (Ft t x) t) + (hc : ∀ t, 0 < t → ∀ x, 0 < x → c t x ≤ C) + (hpde : ∀ t, 0 < t → ∀ x, 0 < x → + Ft t x=(1/2:ℝ)*iteratedDeriv 2 (F t) x+r t x*deriv (F t) x+c t x*F t x) + (hzero : ∀ t, 0 ≤ t → F t 0=0) + (hinit : ∀ x, 0 ≤ x → F 0 x ≤ 0) : + ∀ t, 0 ≤ t → ∀ x, 0 ≤ x → F t x ≤ 0 := by + obtain ⟨R,hR⟩ := hr.bound + obtain ⟨M,hM⟩ := hF.bound + intro T hT x hx + have hh := Parabolic.nonnegative_halfLine_bounded + (u := fun t x => - F t x) (ut := fun t x => -Ft t x) + (ux := fun t x => -deriv (F t) x) (uxx := fun t x => -iteratedDeriv 2 (F t) x) + (β := r) (c := c) (C := C) (K := (R:ℝ)) (M := (M:ℝ)) R.coe_nonneg M.coe_nonneg + ((hcont T).neg.mono (prod_mono subset_rfl (subset_univ _))) + (fun t _ => (hF.regular t).smooth.continuous.neg) + (fun t ht x _ => (htime t ht.1 x).neg.hasDerivWithinAt) + (fun t _ x _ => ((hF.regular t).smooth.differentiable (by simp) x).hasDerivAt.neg) + (fun t _ x _ => ?_) (fun t _ x hxp => ?_) + (fun t ht x hxp => hc t ht.1 x hxp) + (fun t ht x hxp => ?_) + (fun t _ x _ => neg_le_neg ((le_abs_self _).trans (hM t x))) + (fun x hx => neg_nonneg.mpr (hinit x hx)) + (fun t ht => by rw [hzero t ht.1]; simp) T ⟨hT,le_rfl⟩ x hx + · exact neg_nonneg.mp hh + · have he : deriv (fun y => -F t y) = fun y => -deriv (F t) y := + funext (fun y => ((hF.regular t).smooth.differentiable (by simp) y).hasDerivAt.neg.deriv) + rw [he] + convert (hasDerivAt_spatialJet (hF.regular t).smooth 1 x).neg using 1 + first | rfl | (simp only [iteratedDeriv_one]; rfl) + · have hb := mul_le_mul_of_nonneg_right ((le_abs_self _).trans (hR t x)) hxp.le + have hh : x ≤ 1+x^2 := by nlinarith [sq_nonneg (x-1)] + exact hb.trans (mul_le_mul_of_nonneg_left hh R.coe_nonneg) + · rw [hpde t ht.1 x hxp] + ring_nf + exact le_rfl + +namespace SmoothBurgers +variable {r : ℝ → ℝ → ℝ} (hr : SmoothBurgers r) +include hr + +lemma second_odd (ho : ∀ t, Function.Odd (r t)) (t : ℝ) : + Function.Odd (iteratedDeriv 2 (r t)) := by + simpa only [iteratedDeriv_succ,iteratedDeriv_zero] using + (even_deriv_odd ((hr.family.deriv.regular t).smooth.differentiable (by simp)) + (odd_deriv_even ((hr.family.regular t).smooth.differentiable (by simp)) (ho t))) + +theorem second_nonpos (ho : ∀ t, Function.Odd (r t)) + (hi : ∀ x, 0 ≤ x → iteratedDeriv 2 (r 0) x ≤ 0) : + ∀ t, 0 ≤ t → ∀ x, 0 ≤ x → iteratedDeriv 2 (r t) x ≤ 0 := by + obtain ⟨V,hV⟩ := hr.family.deriv.bound + apply bounded_linear_nonpositive (hr.family.iteratedDeriv 2) hr.family + (fun T => hr.jet_continuous 2 T) (fun t ht x => hr.time_derivative 2 t ht x) + (c := fun t x => 3*deriv (r t) x) (C := 3*(V:ℝ)) + · intro t ht x hx + exact mul_le_mul_of_nonneg_left ((le_abs_self _).trans (hV t x)) (by norm_num) + · intro t ht x hx + rw [hr.rate_jet2] + simp only [iteratedDeriv_succ,iteratedDeriv_zero] + ring + · intro t ht + have hh := hr.second_odd ho t 0 + simp only [neg_zero] at hh + linarith + · exact hi + +theorem rate_nonpos (ho : ∀ t, Function.Odd (r t)) + (hi : ∀ x, 0 ≤ x → burgersRate r 0 x ≤ 0) : + ∀ t, 0 ≤ t → ∀ x, 0 ≤ x → burgersRate r t x ≤ 0 := by + obtain ⟨V,hV⟩ := hr.family.deriv.bound + apply bounded_linear_nonpositive hr.rate_family hr.family hr.rate_continuous + (fun t ht x => hr.rate_time ht x) (c := fun t x => deriv (r t) x) (C := (V:ℝ)) + · intro t ht x hx + exact (le_abs_self _).trans (hV t x) + · intro t ht x hx + rfl + · intro t ht + have hh := hr.rate_odd ho t 0 + simp only [neg_zero] at hh + linarith + · exact hi + +end SmoothBurgers +end ZeroTemperatureSK.Heat + +end +end +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology ContDiff +noncomputable section +namespace ZeroTemperatureSK.Heat +namespace SmoothBurgers +variable {r : ℝ → ℝ → ℝ} (hr : SmoothBurgers r) +include hr + +lemma pos_halfLine (ho : ∀ t, Function.Odd (r t)) + (hv : ∀ t, 0 ≤ t → ∀ x, 0 < deriv (r t) x) {t x : ℝ} (ht : 0 ≤ t) (hx : 0 < x) : + 0 < r t x := by + have hm : StrictMono (r t) := strictMonoOn_univ.1 <| + strictMonoOn_of_deriv_pos convex_univ (hr.family.regular t).smooth.continuous.continuousOn + (fun spatial _ => hv t ht spatial) + have hz : r t 0=0 := by + have hh := ho t 0 + simp only [neg_zero] at hh + linarith + simpa only [hz] using hm hx + +theorem wronskian_nonneg (ho : ∀ t, Function.Odd (r t)) + (hv : ∀ t, 0 ≤ t → ∀ x, 0 < deriv (r t) x) + (hiw : ∀ x, 0 ≤ x → iteratedDeriv 2 (r 0) x ≤ 0) + (hip : ∀ x, 0 ≤ x → burgersRate r 0 x ≤ 0) + (hiK : ∀ x, 0 ≤ x → 0 ≤ backwardWronskian r 0 x) : + ∀ t, 0 ≤ t → ∀ x, 0 ≤ x → 0 ≤ backwardWronskian r t x := by + have hw := hr.second_nonpos ho hiw + have hp := hr.rate_nonpos ho hip + obtain ⟨R,hR⟩ := hr.family.bound + obtain ⟨M,hM⟩ := hr.wronskian_family.bound + intro T hT x hx + apply Parabolic.nonnegative_halfLine_bounded + (u := backwardWronskian r) (ut := wronskianRate r) + (ux := fun t => deriv (backwardWronskian r t)) + (uxx := fun t => iteratedDeriv 2 (backwardWronskian r t)) + (β := fun t x => r t x-deriv (r t) x/r t x) + (c := fun t x => 2*(burgersRate r t x/r t x)) (C := 0) (K := (R:ℝ)) (M := (M:ℝ)) + R.coe_nonneg M.coe_nonneg + ((hr.wronskian_continuous T).mono (prod_mono subset_rfl (subset_univ _))) + (fun t _ => (hr.wronskian_family.regular t).smooth.continuous) + (fun t ht x _ => (hr.wronskian_time ht.1 x).hasDerivWithinAt) + (fun t _ x _ => ((hr.wronskian_family.regular t).smooth.differentiable (by simp) x).hasDerivAt) + (fun t _ x _ => by simpa only [iteratedDeriv_one] using + hasDerivAt_spatialJet (hr.wronskian_family.regular t).smooth 1 x) + (fun t ht x hx => ?_) (fun t ht x hx => ?_) (fun t ht x hx => ?_) + (fun t _ x _ => (neg_le_neg (hM t x)).trans (neg_abs_le _)) hiK + (fun t ht => ?_) T ⟨hT,le_rfl⟩ x hx + · have hpos := hr.pos_halfLine ho hv ht.1.le hx + have hsub : 0 ≤ deriv (r t) x/r t x*x := + mul_nonneg (div_nonneg (hv t ht.1.le x).le hpos.le) hx.le + have hb := mul_le_mul_of_nonneg_right ((le_abs_self _).trans (hR t x)) hx.le + have hxx : x ≤ 1+x^2 := by nlinarith [sq_nonneg (x-1)] + have hlast := mul_le_mul_of_nonneg_left hxx R.coe_nonneg + nlinarith + · exact mul_nonpos_of_nonneg_of_nonpos (by norm_num) + (div_nonpos_of_nonpos_of_nonneg (hp t ht.1.le x hx.le) (hr.pos_halfLine ho hv ht.1.le hx).le) + · rw [hr.wronskian_equation t x (ne_of_gt (hr.pos_halfLine ho hv ht.1.le hx))] + exact mul_nonneg_of_nonpos_of_nonpos + (mul_nonpos_of_nonneg_of_nonpos (hr.pos_halfLine ho hv ht.1.le hx).le (hw t ht.1.le x hx.le)) + (hp t ht.1.le x hx.le) + · have hh := hr.wronskian_odd ho t 0 + simp only [neg_zero] at hh + linarith + +end SmoothBurgers +end ZeroTemperatureSK.Heat + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKSupport/Backward/BackwardGradientMild.lean b/lean/OAI/Probability/SKSupport/Backward/BackwardGradientMild.lean new file mode 100644 index 0000000000000000000000000000000000000000..fe6c6469d1dbb67a46e4bd5b17a893e56da39e3a --- /dev/null +++ b/lean/OAI/Probability/SKSupport/Backward/BackwardGradientMild.lean @@ -0,0 +1,79 @@ +import Mathlib +import OAI.Probability.SKSupport.Backward.BackwardGradientSqJointBound +import OAI.Probability.SKSupport.Foundations.MeasurableSpatialDeriv + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology ContDiff +noncomputable section +namespace ZeroTemperatureSK.Heat + +lemma backward_gradient_mild {f : ℝ → ℝ} (hf : RegularDatum f) + (hLip : LipschitzWith 1 f) {c : ℝ} (hc : 0 ≤ c) {a b : ℝ} + (ha : 0 ≤ a) (hab : a ≤ b) (x : ℝ) : + deriv (backward c b f a) x = varianceHeat (b-a) (deriv f) x+ + c*(∫ r in a..b, varianceHeat (r-a) + (fun z => deriv (backward c b f r) z*deriv (deriv (backward c b f r)) z) x) := by + let U : ℝ → ℝ → ℝ := fun r => deriv (backward c b f r) + let W : ℝ → ℝ → ℝ := fun r => deriv (deriv (backward c b f r)) + have hreg (r : ℝ) : RegularDatum (backward c b f r) := regularDatum_varianceLogHeat hf hLip hc (b-r) + have hUr (r : ℝ) : BoundedSmooth (U r) := (hreg r).deriv_bounded + have hUm : Measurable (fun p : ℝ × ℝ => U p.1 p.2) := + measurable_spatial_deriv (measurable_backward hf.smooth.continuous.measurable c b) + (fun r => (hreg r).smooth.differentiable (by simp)) + have hub (r z : ℝ) : |U r z| ≤ 1 := (backward_verificationData hf hLip hc b).gradient_bound r z + obtain ⟨C,hC⟩ := uniform_varianceLogHeat_derivative_bounds hf hLip hc 1 + have hwb (r z : ℝ) : |W r z| ≤ C := by + change |deriv (deriv (backward c b f r)) z| ≤ C + rw [show backward c b f r = varianceLogHeat c (b-r) f from rfl] + simpa only [iteratedDeriv_succ,iteratedDeriv_zero] using hC (b-r) z + have hsqreg (r : ℝ) : BoundedSmooth (fun z => (U r z)^2) := by + simpa only [pow_two] using (hUr r).mul (hUr r) + have hsqder (r : ℝ) : deriv (fun z => (U r z)^2) = fun z => 2*(U r z*W r z) := by + funext z + have hd := ((hUr r).smooth.differentiable (by simp) z).hasDerivAt.pow 2 + convert hd.deriv using 1 + simp only [Nat.cast_ofNat] + ring + have hsqbound (r z : ℝ) : |(U r z)^2| ≤ (1:ℝ≥0) := by + rw [abs_pow]; norm_num only [NNReal.coe_one] + nlinarith [hub r z,abs_nonneg (U r z)] + have hsqdb (r z : ℝ) : |deriv (fun z => (U r z)^2) z| ≤ (2*C:ℝ≥0) := by + rw [hsqder] + norm_num only [abs_mul,abs_of_nonneg (by norm_num : (0:ℝ)≤2),NNReal.coe_mul,NNReal.coe_ofNat] + have hh := mul_le_mul (hub r z) (hwb r z) (abs_nonneg _) (by norm_num : (0:ℝ)≤1) + nlinarith + have hDt := hasDerivAt_integral_varianceHeat (hUm.pow_const 2) hsqreg hsqbound hsqdb a b x + have hHt : HasDerivAt (varianceHeat (b-a) f) (varianceHeat (b-a) (deriv f) x) x := + hasDerivAt_scaled_space (hf.smooth.of_le (by simp)) (exponentialBound_of_lipschitz hLip) + (ExponentialBound.of_bounded (A := 1) (fun z => by + simpa only [Real.norm_eq_abs,NNReal.coe_one] using norm_deriv_le_of_lipschitz (x₀ := z) hLip)) (Real.sqrt (b-a)) x + have heFun : backward c b f a = fun z => varianceHeat (b-a) f z+ + (c/2)*(∫ r in a..b, varianceHeat (r-a) (fun y => (U r y)^2) z) := + funext (backward_mild hf hLip hc ha hab) + have hdR : deriv (fun z => varianceHeat (b-a) f z+ + (c/2)*(∫ r in a..b, varianceHeat (r-a) (fun y => (U r y)^2) z)) x = + varianceHeat (b-a) (deriv f) x+(c/2)*(∫ r in a..b, varianceHeat (r-a) (deriv (fun y => (U r y)^2)) x) := + (hHt.add (hDt.const_mul (c/2))).deriv + rw [heFun,hdR] + simp_rw [hsqder,varianceHeat_const_mul] + rw [intervalIntegral.integral_const_mul] + change varianceHeat (b-a) (deriv f) x + c/2*(2*_) = varianceHeat (b-a) (deriv f) x+c*_ + ring + +end ZeroTemperatureSK.Heat + +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKSupport/Backward/BackwardGradientSqJointBound.lean b/lean/OAI/Probability/SKSupport/Backward/BackwardGradientSqJointBound.lean new file mode 100644 index 0000000000000000000000000000000000000000..f03eb9dc3c54fe8fae73601859f7cf9460f73c6b --- /dev/null +++ b/lean/OAI/Probability/SKSupport/Backward/BackwardGradientSqJointBound.lean @@ -0,0 +1,72 @@ +import Mathlib +import OAI.Probability.SKSupport.Backward.BackwardJointBound + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology ContDiff +noncomputable section +namespace ZeroTemperatureSK.Heat + +lemma backward_gradient_sq_joint_bound {f : ℝ → ℝ} (hf : RegularDatum f) + (hLip : LipschitzWith 1 f) {c : ℝ} (hc : 0 ≤ c) (b : ℝ) : + ∃ L : ℝ≥0, ∀ r ∈ Set.Icc (0:ℝ) b, ∀ s ∈ Set.Icc (0:ℝ) b, ∀ z y, + |(deriv (backward c b f r) z)^2-(deriv (backward c b f s) y)^2| ≤ + (L:ℝ)*(|r-s|+|z-y|) := by + obtain ⟨L,hL⟩ := backward_gradient_joint_bound hf hLip hc b + refine ⟨2*L,fun r hr s hs z y => ?_⟩ + have hu := (backward_verificationData hf hLip hc b).gradient_bound r z + have hv := (backward_verificationData hf hLip hc b).gradient_bound s y + have hdiff := hL r hr s hs z y + rw [sq_sub_sq,abs_mul] + have hsum : |deriv (backward c b f r) z+deriv (backward c b f s) y| ≤ 2 := + (abs_add_le _ _).trans (by linarith) + have hprod := mul_le_mul hdiff hsum (abs_nonneg _) (by positivity : 0 ≤ (L:ℝ)*(|r-s|+|z-y|)) + simp only [NNReal.coe_mul,NNReal.coe_ofNat] + nlinarith [hprod] + +lemma continuousOn_backward_source_heat {f : ℝ → ℝ} (hf : RegularDatum f) + (hLip : LipschitzWith 1 f) {c : ℝ} (hc : 0 ≤ c) {a b : ℝ} + (ha : 0 ≤ a) (hab : a ≤ b) (x : ℝ) : + ContinuousOn (fun r => varianceHeat (r-a) (fun z => (deriv (backward c b f r) z)^2) x) + (Set.Icc a b) := by + obtain ⟨L,hL⟩ := backward_gradient_sq_joint_bound hf hLip hc b + exact continuousOn_moving_heat hab + (fun r => ((regularDatum_varianceLogHeat hf hLip hc (b-r)).deriv_bounded.smooth.continuous.measurable.pow_const 2)) + (fun r hr s hs => hL r ⟨ha.trans hr.1,hr.2⟩ s ⟨ha.trans hs.1,hs.2⟩) x + +lemma backward_mild {f : ℝ → ℝ} (hf : RegularDatum f) + (hLip : LipschitzWith 1 f) {c : ℝ} (hc : 0 ≤ c) {a b : ℝ} + (ha : 0 ≤ a) (hab : a ≤ b) (x : ℝ) : + backward c b f a x = varianceHeat (b-a) f x+ + (c/2)*(∫ r in a..b, varianceHeat (r-a) (fun z => (deriv (backward c b f r) z)^2) x) := by + obtain ⟨L,hL⟩ := backward_joint_bound hf hLip hc b + have hcont := continuousOn_moving_heat hab + (fun r => (regularDatum_varianceLogHeat hf hLip hc (b-r)).smooth.continuous.measurable) + (fun r hr s hs => hL r ⟨ha.trans hr.1,hr.2⟩ s ⟨ha.trans hs.1,hs.2⟩) x + have hint : IntervalIntegrable (fun r => -(c/2)*varianceHeat (r-a) (fun z => (deriv (backward c b f r) z)^2) x) volume a b := + ((continuousOn_backward_source_heat hf hLip hc ha hab x).const_mul (-(c/2))).intervalIntegrable_of_Icc hab + have he := intervalIntegral.integral_eq_sub_of_hasDerivAt_of_le hab hcont + (fun r hr => hasDerivAt_moving_backward_heat hf hLip hc hr.1 hr.2 x) hint + have ht : varianceLogHeat c 0 f = f := by + funext z + simpa only [backward,sub_self] using backward_terminal c b f z + simp only [intervalIntegral.integral_const_mul,sub_self,ht,varianceHeat_zero] at he + change varianceLogHeat c (b-a) f x = _ + linarith + +end ZeroTemperatureSK.Heat + +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKSupport/Backward/BackwardJointBound.lean b/lean/OAI/Probability/SKSupport/Backward/BackwardJointBound.lean new file mode 100644 index 0000000000000000000000000000000000000000..5aed662dc9406141c1c27e607de818cb7b2362ff --- /dev/null +++ b/lean/OAI/Probability/SKSupport/Backward/BackwardJointBound.lean @@ -0,0 +1,230 @@ +import Mathlib +import OAI.Probability.SKSupport.Foundations.DerivVarianceHeatCurve + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology ContDiff +noncomputable section +namespace ZeroTemperatureSK.Heat + +lemma backward_joint_bound {f : ℝ → ℝ} (hf : RegularDatum f) + (hLip : LipschitzWith 1 f) {c : ℝ} (hc : 0 ≤ c) (b : ℝ) : + ∃ L : ℝ≥0, ∀ r ∈ Set.Icc (0:ℝ) b, ∀ s ∈ Set.Icc (0:ℝ) b, ∀ z y, + |backward c b f r z-backward c b f s y| ≤ (L:ℝ)*(|r-s|+|z-y|) := by + obtain ⟨C₂,C₃,Ct,L,h₂,h₃,hm,hCt,hd,hJ,hE⟩ := (backward_verificationData hf hLip hc b).bounds + have ht (z : ℝ) : LipschitzOnWith Ct (fun r => backward c b f r z) (Set.Icc 0 b) := by + apply (convex_Icc (0:ℝ) b).lipschitzOnWith_of_nnnorm_hasDerivWithin_le (fun r hr => hd r hr z) + intro r hr + exact NNReal.coe_le_coe.mp (by simpa only [coe_nnnorm,Real.norm_eq_abs] using hCt r z) + refine ⟨Ct+1, fun r hr s hs z y => ?_⟩ + have htime := (ht z).dist_le_mul r hr s hs + have hspace := (varianceLogHeat_lipschitz hLip hc (b-s)).dist_le_mul z y + simp only [Real.dist_eq, NNReal.coe_one, one_mul] at htime hspace + change |backward c b f s z-backward c b f s y| ≤ |z-y| at hspace + have htri := abs_sub_le (backward c b f r z) (backward c b f s z) (backward c b f s y) + simp only [NNReal.coe_add, NNReal.coe_one] + nlinarith [abs_nonneg (r-s),mul_nonneg Ct.coe_nonneg (abs_nonneg (z-y))] + +lemma deriv_varianceLogHeat_tilted {f : ℝ → ℝ} {K : ℝ≥0} + (hf : RegularDatum f) (hLip : LipschitzWith K f) {c : ℝ} (hc : 0 ≤ c) (t : ℝ) : + deriv (varianceLogHeat c t f) = varianceTilted c t f (deriv f) := by + have he : varianceLogHeat c t f = logSemigroup c (Real.toNNReal t) f := + funext (varianceLogHeat_eq_logSemigroup_toNNReal hf.smooth.continuous.measurable c t) + rw [he] + funext x + rw [varianceTilted_eq_tiltedMean hf.smooth.continuous.measurable + hf.deriv_bounded.smooth.continuous.measurable] + by_cases hc0 : c = 0 + · subst c + have hz : logSemigroup 0 (Real.toNNReal t) f = semigroup (Real.toNNReal t) f := by + funext z; simp [logSemigroup] + rw [hz,(hasDerivAt_semigroup (hf.smooth.of_le (by simp)) hLip (Real.toNNReal t) x).deriv] + simp [tiltedMean,semigroup] + · exact (hasDerivAt_logSemigroup (hf.smooth.of_le (by simp)) hLip + (lt_of_le_of_ne hc (Ne.symm hc0)) (Real.toNNReal t) x).deriv + +lemma backward_gradient_joint_bound {f : ℝ → ℝ} (hf : RegularDatum f) + (hLip : LipschitzWith 1 f) {c : ℝ} (hc : 0 ≤ c) (b : ℝ) : + ∃ L : ℝ≥0, ∀ r ∈ Set.Icc (0:ℝ) b, ∀ s ∈ Set.Icc (0:ℝ) b, ∀ z y, + |deriv (backward c b f r) z-deriv (backward c b f s) y| ≤ (L:ℝ)*(|r-s|+|z-y|) := by + obtain ⟨L,hL⟩ := varianceTilted_joint_bound hf hLip hf.deriv_bounded hc + refine ⟨L, fun r hr s hs z y => ?_⟩ + rw [show backward c b f r = varianceLogHeat c (b-r) f from rfl, + show backward c b f s = varianceLogHeat c (b-s) f from rfl, + deriv_varianceLogHeat_tilted hf hLip hc, deriv_varianceLogHeat_tilted hf hLip hc] + have hb := hL (b-r) (sub_nonneg.mpr hr.2) (b-s) (sub_nonneg.mpr hs.2) z y + have he : |(b-r)-(b-s)| = |r-s| := by rw [show (b-r)-(b-s) = -(r-s) by ring,abs_neg] + rwa [he] at hb + +lemma continuousOn_of_joint_bound {F : ℝ → ℝ → ℝ} {L : ℝ≥0} {a b : ℝ} + (hL : ∀ r ∈ Set.Icc a b, ∀ s ∈ Set.Icc a b, ∀ z y, + |F r z-F s y| ≤ (L:ℝ)*(|r-s|+|z-y|)) : + ContinuousOn (fun p : ℝ × ℝ => F p.1 p.2) (Set.Icc a b ×ˢ Set.univ) := by + have hl : LipschitzOnWith (2*L) (fun p : ℝ × ℝ => F p.1 p.2) (Set.Icc a b ×ˢ Set.univ) := by + apply LipschitzOnWith.of_dist_le_mul + intro p hp q hq + have hh := hL p.1 hp.1 q.1 hq.1 p.2 q.2 + rw [Real.dist_eq] + have ht : |p.1-q.1| ≤ dist p q := by + change dist p.1 q.1 ≤ max (dist p.1 q.1) (dist p.2 q.2) + exact le_max_left _ _ + have hx : |p.2-q.2| ≤ dist p q := by + change dist p.2 q.2 ≤ max (dist p.1 q.1) (dist p.2 q.2) + exact le_max_right _ _ + simp only [NNReal.coe_mul,NNReal.coe_ofNat] + nlinarith [mul_le_mul_of_nonneg_left (add_le_add ht hx) L.coe_nonneg] + exact hl.continuousOn + +lemma continuousOn_moving_heat {F : ℝ → ℝ → ℝ} {L : ℝ≥0} {a b : ℝ} (hab : a ≤ b) + (hm : ∀ r, Measurable (F r)) + (hL : ∀ r ∈ Set.Icc a b, ∀ s ∈ Set.Icc a b, ∀ z y, + |F r z-F s y| ≤ (L:ℝ)*(|r-s|+|z-y|)) (x : ℝ) : + ContinuousOn (fun r => varianceHeat (r-a) (F r) x) (Set.Icc a b) := by + apply continuousOn_of_dominated + (bound := fun y : ℝ => |F a x|+(L:ℝ)*((b-a)+Real.sqrt (b-a)*|y|)) + · intro r hr + exact ((hm r).comp (measurable_const.add (measurable_const.mul measurable_id))).aestronglyMeasurable + · intro r hr + filter_upwards [] with y + have hh := hL r hr a ⟨le_rfl,hab⟩ (x+Real.sqrt (r-a)*y) x + have ht := abs_add_le (F r (x+Real.sqrt (r-a)*y)-F a x) (F a x) + rw [sub_add_cancel] at ht + rw [add_sub_cancel_left,abs_mul,abs_of_nonneg (Real.sqrt_nonneg _)] at hh + rw [abs_of_nonneg (sub_nonneg.mpr hr.1)] at hh + have hs : Real.sqrt (r-a) ≤ Real.sqrt (b-a) := Real.sqrt_le_sqrt (by linarith [hr.2]) + rw [Real.norm_eq_abs] + change |F r (x+Real.sqrt (r-a)*y)| ≤ _ + have hmrs := mul_le_mul_of_nonneg_right hs (abs_nonneg y) + have hh' := mul_le_mul_of_nonneg_left (add_le_add (show r-a ≤ b-a by linarith [hr.2]) hmrs) L.coe_nonneg + linarith + · exact (integrable_const _).add + (((integrable_const _).add (integrable_standardGaussian_abs.const_mul _)).const_mul _) + · filter_upwards [] with y + exact (continuousOn_of_joint_bound hL).comp + ((continuous_id.prodMk (continuous_const.add ((Real.continuous_sqrt.comp + (continuous_id.sub continuous_const)).mul continuous_const))).continuousOn) + (fun r hr => ⟨hr,Set.mem_univ _⟩) + +end ZeroTemperatureSK.Heat + +namespace ZeroTemperatureSK.Heat + +lemma hasDerivAt_backward_curve {f X : ℝ → ℝ} (hf : RegularDatum f) + (hLip : LipschitzWith 1 f) (c b : ℝ) {s X' : ℝ} + (hX : HasDerivAt X X' s) (hs : s < b) : + HasDerivAt (fun r => backward c b f r (X r)) + (-(1/2:ℝ)*deriv (deriv (backward c b f s)) (X s)- + c/2*(deriv (backward c b f s) (X s))^2+ + X'*deriv (backward c b f s) (X s)) s := by + have hd := hasDerivAt_varianceLogHeat_curve hf hLip c + ((hasDerivAt_const s b).sub (hasDerivAt_id s)) hX (sub_pos.mpr hs) + simp only [Pi.sub_apply,id_eq] at hd + rw [show backward c b f s = varianceLogHeat c (b-s) f from rfl] + convert hd using 1 <;> first | rfl | ring + +lemma hasDerivAt_moving_backward_heat {f : ℝ → ℝ} (hf : RegularDatum f) + (hLip : LipschitzWith 1 f) {c : ℝ} (hc : 0 ≤ c) {a b s : ℝ} + (has : a < s) (hsb : s < b) (x : ℝ) : + HasDerivAt (fun r => varianceHeat (r-a) (backward c b f r) x) + (-(c/2)*varianceHeat (s-a) (fun z => (deriv (backward c b f s) z)^2) x) s := by + let U : ℝ → ℝ → ℝ := fun r => deriv (backward c b f r) + let W : ℝ → ℝ → ℝ := fun r => deriv (deriv (backward c b f r)) + let D : ℝ → ℝ → ℝ := fun r y => + -(1/2:ℝ)*W r (x+Real.sqrt (r-a)*y)-c/2*(U r (x+Real.sqrt (r-a)*y))^2+ + (y/(2*Real.sqrt (r-a)))*U r (x+Real.sqrt (r-a)*y) + obtain ⟨C₂,C₃,Ct,L,h₂,h₃,hm,hCt,hdt,hJ,hE⟩ := (backward_verificationData hf hLip hc b).bounds + have hub (r z : ℝ) : |U r z| ≤ 1 := (backward_verificationData hf hLip hc b).gradient_bound r z + have hwb (r z : ℝ) : |W r z| ≤ C₂ := h₂ r z + have hreg (r : ℝ) : RegularDatum (backward c b f r) := regularDatum_varianceLogHeat hf hLip hc (b-r) + have hUmeas (r : ℝ) : Measurable (U r) := (hreg r).deriv_bounded.smooth.continuous.measurable + have hWmeas (r : ℝ) : Measurable (W r) := (hreg r).deriv_bounded.deriv.smooth.continuous.measurable + have hsmall : 0 < (s-a)/2 := by linarith + have hroot : 0 < Real.sqrt ((s-a)/2) := Real.sqrt_pos.mpr hsmall + have hiF : Integrable (fun y => backward c b f s (x+Real.sqrt (s-a)*y)) (gaussianReal 0 1) := + integrable_scaled_of_expBound (hreg s).smooth.continuous.measurable + (exponentialBound_of_lipschitz (varianceLogHeat_lipschitz hLip hc (b-s))) _ _ + have hDm : AEStronglyMeasurable (D s) (gaussianReal 0 1) := by + dsimp only [D] + exact (((measurable_const.mul ((hWmeas s).comp (by fun_prop))).sub + (measurable_const.mul (((hUmeas s).comp (by fun_prop)).pow_const 2))).add + ((measurable_id.div_const _).mul ((hUmeas s).comp (by fun_prop)))).aestronglyMeasurable + have hd := hasDerivAt_integral_of_dominated_loc_of_deriv_le + (F := fun r y => backward c b f r (x+Real.sqrt (r-a)*y)) (F' := D) + (bound := fun y : ℝ => ((C₂:ℝ)+c)/2+|y|/(2*Real.sqrt ((s-a)/2))) + (s := Set.Ioo ((a+s)/2) b) (Ioo_mem_nhds (by linarith) hsb) + (Filter.Eventually.of_forall (fun r => ((hreg r).smooth.continuous.measurable.comp + (measurable_const.add (measurable_const.mul measurable_id))).aestronglyMeasurable)) + hiF hDm + (by + filter_upwards [] with y r hr + have hra : 0 < r-a := by linarith [hr.1] + have hsr : Real.sqrt ((s-a)/2) ≤ Real.sqrt (r-a) := Real.sqrt_le_sqrt (by linarith [hr.1]) + have hratio : |y|/(2*Real.sqrt (r-a)) ≤ |y|/(2*Real.sqrt ((s-a)/2)) := by + exact div_le_div_of_nonneg_left (abs_nonneg y) (by positivity) (by linarith) + dsimp only [D] + rw [Real.norm_eq_abs] + apply (abs_add_le _ _).trans + apply (add_le_add (abs_sub _ _) le_rfl).trans + have hU := hub r (x+Real.sqrt (r-a)*y) + have hW := hwb r (x+Real.sqrt (r-a)*y) + rw [abs_mul, abs_neg, abs_of_pos (by norm_num : (0:ℝ)<1/2), abs_mul, + abs_of_nonneg (div_nonneg hc (by norm_num)), abs_pow, + abs_mul, abs_div, abs_of_pos (show 0 < 2*Real.sqrt (r-a) by positivity)] + have hU2 : |U r (x+Real.sqrt (r-a)*y)|^2 ≤ 1 := by nlinarith [abs_nonneg (U r (x+Real.sqrt (r-a)*y))] + have hUterm := mul_le_mul_of_nonneg_left hU (show 0 ≤ |y|/(2*Real.sqrt (r-a)) by positivity) + have hU2term := mul_le_mul_of_nonneg_left hU2 (div_nonneg hc (by norm_num : (0:ℝ)≤2)) + nlinarith) + ((integrable_const _).add (integrable_standardGaussian_abs.div_const _)) + (by + filter_upwards [] with y r hr + have hra : 0 < r-a := by linarith [hr.1] + have hX : HasDerivAt (fun t : ℝ => x+Real.sqrt (t-a)*y) + (y/(2*Real.sqrt (r-a))) r := by + convert ((((hasDerivAt_id r).sub_const a).sqrt (ne_of_gt hra)).mul_const y).const_add x using 1 <;> first | rfl | (simp only [id_eq]; ring) + exact hasDerivAt_backward_curve hf hLip c b hX hr.2) + have hUc : BoundedSmooth (U s) := (hreg s).deriv_bounded + have hUe : ExponentialBound (U s) := ExponentialBound.of_bounded (A := 1) (hub s) + have hWe : ExponentialBound (W s) := ExponentialBound.of_bounded (hwb s) + have hUi := integrable_mul_scaled_of_expBound (hUmeas s) hUe (Real.sqrt (s-a)) x + have hWi := integrable_scaled_of_expBound (hWmeas s) hWe (Real.sqrt (s-a)) x + have hU2m : Measurable (fun z => (U s z)^2) := (hUmeas s).pow_const 2 + have hU2e : ExponentialBound (fun z => (U s z)^2) := ExponentialBound.of_bounded (A := 1) (fun z => by + rw [abs_pow]; norm_num only [NNReal.coe_one]; nlinarith [hub s z,abs_nonneg (U s z)]) + have hU2i := integrable_scaled_of_expBound hU2m hU2e (Real.sqrt (s-a)) x + have hstein := scaled_gradient_stein hUc (Real.sqrt (s-a)) x + rw [(hasDerivAt_scaled_space (hUc.smooth.of_le (by simp)) hUe hWe (Real.sqrt (s-a)) x).deriv] at hstein + have heD : D s = fun y => -(1/2:ℝ)*W s (x+Real.sqrt (s-a)*y)- + c/2*(U s (x+Real.sqrt (s-a)*y))^2+ + (1/(2*Real.sqrt (s-a)))*(y*U s (x+Real.sqrt (s-a)*y)) := by + funext y; dsimp only [D]; ring + have he : (∫ y,D s y ∂gaussianReal 0 1) = + -(c/2)*varianceHeat (s-a) (fun z => (U s z)^2) x := by + rw [heD] + dsimp only + have hsplit := integral_add ((hWi.const_mul (-(1/2:ℝ))).sub (hU2i.const_mul (c/2))) (hUi.const_mul (1/(2*Real.sqrt (s-a)))) + have hsub := integral_sub (hWi.const_mul (-(1/2:ℝ))) (hU2i.const_mul (c/2)) + simp only [Pi.sub_apply] at hsplit hsub + rw [hsplit,hsub,integral_const_mul,integral_const_mul,integral_const_mul,← hstein] + change -(1/2:ℝ)*scaled (Real.sqrt (s-a)) (W s) x-c/2*scaled (Real.sqrt (s-a)) (fun z => (U s z)^2) x+ + (1/(2*Real.sqrt (s-a)))*(Real.sqrt (s-a)*scaled (Real.sqrt (s-a)) (W s) x) = _ + dsimp only [varianceHeat] + field_simp [ne_of_gt (Real.sqrt_pos.mpr (sub_pos.mpr has))] + ring + exact hd.2.congr_deriv he + +end ZeroTemperatureSK.Heat + +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKSupport/Backward/BackwardRescale.lean b/lean/OAI/Probability/SKSupport/Backward/BackwardRescale.lean new file mode 100644 index 0000000000000000000000000000000000000000..c66c9396ae04bcc025d91f01a582bf8e7ef6a83b --- /dev/null +++ b/lean/OAI/Probability/SKSupport/Backward/BackwardRescale.lean @@ -0,0 +1,93 @@ +import Mathlib +import OAI.Probability.SKSupport.Backward.BackwardComparison + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology ContDiff +noncomputable section +namespace ZeroTemperatureSK.Heat + +structure BackwardShape (r : ℝ → ℝ) : Prop where + odd : Function.Odd r + derivative_pos : ∀ x, 0 < deriv r x + second_nonpos : ∀ x, 0 ≤ x → iteratedDeriv 2 r x ≤ 0 + rate_nonpos : ∀ x, 0 ≤ x → burgersRate (fun _ => r) 0 x ≤ 0 + wronskian_nonneg : ∀ x, 0 ≤ x → 0 ≤ backwardWronskian (fun _ => r) 0 x + +lemma scaled_jet {r : ℝ → ℝ} (hr : ContDiff ℝ ∞ r) (α : ℝ) (n : ℕ) (x : ℝ) : + iteratedDeriv n (fun y => α*r y) x = α*iteratedDeriv n r x := + iteratedDeriv_const_mul α (hr.of_le (ENat.natCast_le_of_coe_top_le_withTop le_rfl n) |>.contDiffAt) + +lemma scaled_rate {r : ℝ → ℝ} (hr : ContDiff ℝ ∞ r) (α x : ℝ) : + burgersRate (fun _ y => α*r y) 0 x = + α*burgersRate (fun _ => r) 0 x+α*(α-1)*r x*deriv r x := by + have he := scaled_jet hr α 1 x + simp only [iteratedDeriv_one] at he + simp only [burgersRate,scaled_jet hr α 2 x,he] + ring + +lemma scaled_wronskian {r : ℝ → ℝ} (hr : ContDiff ℝ ∞ r) (α x : ℝ) : + backwardWronskian (fun _ y => α*r y) 0 x = + α^2*backwardWronskian (fun _ => r) 0 x+ + α^2*(α-1)*(r x)^2*iteratedDeriv 2 r x := by + have hr' := contDiff_iteratedDeriv_infty hr 1 + have hr'' := contDiff_iteratedDeriv_infty hr 2 + have hp : ContDiff ℝ ∞ (burgersRate (fun _ => r) 0) := by + exact (contDiff_const.mul hr'').add (hr.mul (by simpa only [iteratedDeriv_one] using hr')) + have he : burgersRate (fun _ y => α*r y) 0 = fun y => + α*burgersRate (fun _ => r) 0 y+α*(α-1)*r y*deriv r y := funext (scaled_rate hr α) + have hd := ((hp.differentiable (by simp) x).hasDerivAt.const_mul α).add + (((hasDerivAt_spatialJet hr 0 x).const_mul (α*(α-1))).mul (hasDerivAt_spatialJet hr 1 x)) + have hd' : HasDerivAt (burgersRate (fun _ y => α*r y) 0) + (α*deriv (burgersRate (fun _ => r) 0) x+ + α*(α-1)*((deriv r x)^2+r x*iteratedDeriv 2 r x)) x := by + rw [he] + convert hd using 1 <;> first | rfl | ((try funext y); simp only + [Pi.add_apply,Pi.mul_apply,iteratedDeriv_succ,iteratedDeriv_zero] <;> ring) + have he' := scaled_jet hr α 1 x + simp only [iteratedDeriv_one] at he' + rw [backwardWronskian,hd'.deriv,he',scaled_rate hr α x] + simp only [backwardWronskian] + ring + +theorem BackwardShape.rescale {r : ℝ → ℝ} (hr : ContDiff ℝ ∞ r) (hs : BackwardShape r) + {α : ℝ} (hα : 0 < α) (hα' : α ≤ 1) : BackwardShape (fun x => α*r x) := by + have hv : ∀ x, deriv (fun y => α*r y) x=α*deriv r x := fun x => by + simpa only [iteratedDeriv_one] using scaled_jet hr α 1 x + have hzero : r 0=0 := by + have hh := hs.odd 0 + simp only [neg_zero] at hh + linarith + have hpos (x : ℝ) (hx : 0 ≤ x) : 0 ≤ r x := by + have hm := (strictMono_of_deriv_pos hs.derivative_pos).monotone hx + simpa only [hzero] using hm + refine ⟨?_,fun x => by rw [hv]; exact mul_pos hα (hs.derivative_pos x),?_,?_,?_⟩ + · intro x + change α*r (-x) = -(α*r x) + rw [hs.odd x] + ring + · intro x hx + rw [scaled_jet hr α] + exact mul_nonpos_of_nonneg_of_nonpos hα.le (hs.second_nonpos x hx) + · intro x hx + rw [scaled_rate hr α] + apply add_nonpos (mul_nonpos_of_nonneg_of_nonpos hα.le (hs.rate_nonpos x hx)) + apply mul_nonpos_of_nonpos_of_nonneg _ (hs.derivative_pos x).le + exact mul_nonpos_of_nonpos_of_nonneg + (mul_nonpos_of_nonneg_of_nonpos hα.le (sub_nonpos.mpr hα')) (hpos x hx) + · intro x hx + rw [scaled_wronskian hr α] + apply add_nonneg (mul_nonneg (sq_nonneg α) (hs.wronskian_nonneg x hx)) + exact mul_nonneg_of_nonpos_of_nonpos + (mul_nonpos_of_nonpos_of_nonneg + (mul_nonpos_of_nonneg_of_nonpos (sq_nonneg α) (sub_nonpos.mpr hα')) (sq_nonneg (r x))) + (hs.second_nonpos x hx) + +end ZeroTemperatureSK.Heat + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKSupport/Backward/GaussianBackwardShapes.lean b/lean/OAI/Probability/SKSupport/Backward/GaussianBackwardShapes.lean new file mode 100644 index 0000000000000000000000000000000000000000..66b026aaf5feacbf06eebacda4f2cf8351ccfcfb --- /dev/null +++ b/lean/OAI/Probability/SKSupport/Backward/GaussianBackwardShapes.lean @@ -0,0 +1,237 @@ +import Mathlib +import OAI.Probability.SKSupport.Regularity.Regularity +import OAI.Probability.SKSupport.Moments.FiniteStrictConvex +import OAI.Probability.SKSupport.Parabolic.ForwardSigns +import OAI.Probability.SKSupport.Backward.BackwardRescale +import OAI.Probability.SKSupport.Diffusion.TerminalShapes + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology ContDiff +noncomputable section +namespace ZeroTemperatureSK.Heat + +theorem gaussianBurgers_shape {f : ℝ → ℝ} {K : ℝ≥0} + (hf : RegularDatum f) (hLip : LipschitzWith K f) (he : Function.Even f) + (hcurv : ∀ x, 0 < deriv (deriv f) x) {c : ℝ} (hc : 0 < c) + (hi : BackwardShape (fun x => c*deriv f x)) + {t : ℝ} (ht : 0 ≤ t) : BackwardShape (gaussianBurgers c f t) := by + have hr := gaussianBurgers_smooth hf hLip hc.le + have ho := gaussianBurgers_odd hf hLip he hc.le + have hz := gaussianBurgers_terminal (f := f) c + have hiv : BackwardShape (gaussianBurgers c f 0) := by rw [hz]; exact hi + have hv (s : ℝ) (_hs : 0 ≤ s) (x : ℝ) : 0 < deriv (gaussianBurgers c f s) x := by + have hj := gaussianBurgers_jet hf hLip hc.le 1 s x + simp only [iteratedDeriv_one] at hj + rw [hj] + exact mul_pos hc (by simpa only [iteratedDeriv_succ,iteratedDeriv_zero] using + varianceLogHeat_curvature_pos hf hLip hcurv hc.le s x) + refine ⟨ho t,hv t ht,?_,?_,?_⟩ + · exact hr.second_nonpos ho hiv.second_nonpos t ht + · exact hr.rate_nonpos ho hiv.rate_nonpos t ht + · exact hr.wronskian_nonneg ho hv hiv.second_nonpos hiv.rate_nonpos hiv.wronskian_nonneg t ht + +theorem logSemigroup_backward_shape {f : ℝ → ℝ} {K : ℝ≥0} + (hf : RegularDatum f) (hLip : LipschitzWith K f) (he : Function.Even f) + (hcurv : ∀ x, 0 < deriv (deriv f) x) {c : ℝ} (hc : 0 < c) + (hi : BackwardShape (fun x => c*deriv f x)) (h : ℝ≥0) : + BackwardShape (fun x => c*deriv (logSemigroup c h f) x) := by + have hh := gaussianBurgers_shape hf hLip he hcurv hc hi h.coe_nonneg + have heq : varianceLogHeat c h f = logSemigroup c h f := + funext (varianceLogHeat_eq_logSemigroup hf.smooth.continuous.measurable c h) + have heq' : gaussianBurgers c f h = fun x => c*deriv (logSemigroup c h f) x := by + funext x + rw [gaussianBurgers,heq] + rwa [heq'] at hh + +lemma softAbs_backward_shape {M c : ℝ} (hc : 0 < c) (hM : c ≤ M) : + BackwardShape (fun x => c*deriv (softAbs M) x) := by + have hMp := hc.trans_le hM + have he : (fun x => c*deriv (softAbs M) x) = tanhDrift c M := by + funext x + rw [(hasDerivAt_softAbs (ne_of_gt hMp) x).deriv] + rfl + rw [he] + refine ⟨?_,?_,fun x hx => (tanhDrift_initial_signs hc hM x hx).1, + fun x hx => (tanhDrift_initial_signs hc hM x hx).2.1, + fun x hx => (tanhDrift_initial_signs hc hM x hx).2.2⟩ + · intro x + simp only [tanhDrift,mul_neg,Real.tanh_neg] + · intro x + rw [(tanhDrift_derivative c M x).deriv] + exact mul_pos (mul_pos hc hMp) (tanh_sq_gap_pos (M*x)) + +end ZeroTemperatureSK.Heat + +end +end +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology ContDiff +noncomputable section +namespace ZeroTemperatureSK.Heat + +theorem cascade_backward_shape {M : ℝ} (c : ℕ → ℝ≥0) + (hc : ∀ i, 0 < (c i:ℝ)) (hmono : Monotone c) (hM : ∀ i, (c i:ℝ) ≤ M) + (h : ℝ≥0) (N i : ℕ) : + BackwardShape (fun x => (c i:ℝ)*deriv (cascade c h (softAbs M) N i) x) := by + have hMp : 0 < M := (hc 0).trans_le (hM 0) + have hf := regularDatum_softAbs (ne_of_gt hMp) + have hLip := softAbs_lipschitz (ne_of_gt hMp) + induction N generalizing i with + | zero => exact softAbs_backward_shape (hc i) (hM i) + | succ N ih => + have hdatum := cascade_regular hf hLip c h N (i+1) + have hsmooth : ContDiff ℝ ∞ (fun x => (c (i+1):ℝ)*deriv (cascade c h (softAbs M) N (i+1)) x) := + contDiff_const.mul hdatum.deriv_bounded.smooth + have hir := BackwardShape.rescale hsmooth (ih (i+1)) + (div_pos (hc i) (hc (i+1))) + ((div_le_one (hc (i+1))).mpr (show (c i:ℝ) ≤ c (i+1) from hmono (Nat.le_succ i))) + have he : (fun x => ((c i:ℝ)/(c (i+1):ℝ))* + ((c (i+1):ℝ)*deriv (cascade c h (softAbs M) N (i+1)) x)) = + fun x => (c i:ℝ)*deriv (cascade c h (softAbs M) N (i+1)) x := by + funext x + field_simp [ne_of_gt (hc (i+1))] + rw [he] at hir + exact logSemigroup_backward_shape hdatum (cascade_lipschitz hLip c h N (i+1)) + (cascade_even hf hLip (softAbs_even M) c h N (i+1)) + (cascade_curvature_pos hf hLip (softAbs_curvature_pos hMp) c h N (i+1)) + (hc i) hir h + +theorem finiteHead_backward_shape {M : ℝ} (c : ℕ → ℝ≥0) + (hc : ∀ i, 0 < (c i:ℝ)) (hmono : Monotone c) (hM : ∀ i, (c i:ℝ) ≤ M) + (h : ℝ≥0) (N i : ℕ) (t : ℝ) (ht : t ≤ h) : + BackwardShape (fun x => (c i:ℝ)*deriv (finiteValue c h (softAbs M) (N+1) i t) x) := by + have hMp : 0 < M := (hc 0).trans_le (hM 0) + have hf := regularDatum_softAbs (ne_of_gt hMp) + have hLip := softAbs_lipschitz (ne_of_gt hMp) + have hdatum := cascade_regular hf hLip c h N (i+1) + have hsmooth : ContDiff ℝ ∞ (fun x => (c (i+1):ℝ)*deriv (cascade c h (softAbs M) N (i+1)) x) := + contDiff_const.mul hdatum.deriv_bounded.smooth + have hir := BackwardShape.rescale hsmooth (cascade_backward_shape c hc hmono hM h N (i+1)) + (div_pos (hc i) (hc (i+1))) + ((div_le_one (hc (i+1))).mpr (show (c i:ℝ) ≤ c (i+1) from hmono (Nat.le_succ i))) + have he : (fun x => ((c i:ℝ)/(c (i+1):ℝ))* + ((c (i+1):ℝ)*deriv (cascade c h (softAbs M) N (i+1)) x)) = + fun x => (c i:ℝ)*deriv (cascade c h (softAbs M) N (i+1)) x := by + funext x + field_simp [ne_of_gt (hc (i+1))] + rw [he] at hir + have hh := gaussianBurgers_shape hdatum (cascade_lipschitz hLip c h N (i+1)) + (cascade_even hf hLip (softAbs_even M) c h N (i+1)) + (cascade_curvature_pos hf hLip (softAbs_curvature_pos hMp) c h N (i+1)) + (hc i) hir (sub_nonneg.mpr ht) + have heq : (fun x => (c i:ℝ)*deriv (finiteValue c h (softAbs M) (N+1) i t) x) = + gaussianBurgers (c i) (cascade c h (softAbs M) N (i+1)) ((h:ℝ)-t) := by + rw [finiteValue_head _ c h N i ht] + rfl + rwa [heq] + +end ZeroTemperatureSK.Heat + +end +end +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology ContDiff +noncomputable section +namespace ZeroTemperatureSK.Heat + +lemma RegularDatum.exists_lipschitz {f : ℝ → ℝ} (hf : RegularDatum f) : + ∃ K : ℝ≥0, LipschitzWith K f := by + obtain ⟨K,hK⟩ := hf.deriv_bounded.bound + exact ⟨K,lipschitzWith_of_nnnorm_deriv_le (hf.smooth.differentiable (by simp)) + (fun x => NNReal.coe_le_coe.mp (by simpa only [coe_nnnorm,Real.norm_eq_abs] using hK x))⟩ + +lemma RegularDatum.sub_mul {f g : ℝ → ℝ} (hf : RegularDatum f) (hg : RegularDatum g) (δ : ℝ) : + RegularDatum (fun x => f x-δ*g x) := by + refine ⟨hf.smooth.sub (contDiff_const.mul hg.smooth),?_⟩ + have he : deriv (fun x => f x-δ*g x)=fun x => deriv f x+(-δ)*deriv g x := by + funext x + convert (((hf.smooth.differentiable (by simp)) x).hasDerivAt.sub + (((hg.smooth.differentiable (by simp)) x).hasDerivAt.const_mul δ)).deriv using 1 + first | rfl | ring + rw [he] + exact hf.deriv_bounded.add (hg.deriv_bounded.const_mul (-δ)) + +def backwardBoundary (c : ℕ → ℝ≥0) (h : ℝ≥0) (f : ℝ → ℝ) (N i : ℕ) : ℝ → ℝ := + cascade c h f (N-i) i + +def forwardBoundary (c : ℕ → ℝ≥0) (h : ℝ≥0) (f : ℝ → ℝ) (N : ℕ) : ℕ → ℝ → ℝ + | 0 => fun _ => -(c 0:ℝ)*backwardBoundary c h f N 0 0 + | i+1 => fun x => (if i=0 then + -(1/2:ℝ)*Real.log (2*Real.pi*(h:ℝ))-(c 0:ℝ)*backwardBoundary c h f N 0 0 + else forwardCorrection ((i:ℝ)*h) (forwardBoundary c h f N i) h x)- + ((c (i+1):ℝ)-(c i:ℝ))*backwardBoundary c h f N (i+1) x + +lemma forwardBoundary_regular {f : ℝ → ℝ} (hf : RegularDatum f) (hLip : LipschitzWith 1 f) + (c : ℕ → ℝ≥0) {h : ℝ≥0} (hh : 0 < (h:ℝ)) (N i : ℕ) : + RegularDatum (forwardBoundary c h f N i) := by + induction i with + | zero => exact RegularDatum.const _ + | succ i ih => + have hφ : RegularDatum (backwardBoundary c h f N (i+1)) := cascade_regular hf hLip c h _ _ + rw [forwardBoundary] + by_cases hi : i=0 + · subst i + simp only [ite_true] + exact (RegularDatum.const _).sub_mul hφ _ + · simp only [hi,ite_false] + obtain ⟨K,hK⟩ := ih.exists_lipschitz + exact (forwardCorrection_regular (mul_pos (Nat.cast_pos.mpr (Nat.pos_of_ne_zero hi)) hh) ih hK h).sub_mul hφ _ + +lemma backwardBoundary_shape {M : ℝ} (c : ℕ → ℝ≥0) + (hc : ∀ i, 0 < (c i:ℝ)) (hmono : Monotone c) (hM : ∀ i, (c i:ℝ) ≤ M) + (h : ℝ≥0) (N i : ℕ) : + BackwardShape (fun x => (c i:ℝ)*deriv (backwardBoundary c h (softAbs M) N i) x) := + cascade_backward_shape c hc hmono hM h _ _ + +lemma backwardBoundary_third_nonpos {M : ℝ} (c : ℕ → ℝ≥0) + (hc : ∀ i, 0 < (c i:ℝ)) (hmono : Monotone c) (hM : ∀ i, (c i:ℝ) ≤ M) + (h : ℝ≥0) (N i : ℕ) (x : ℝ) (hx : 0 ≤ x) : + iteratedDeriv 3 (backwardBoundary c h (softAbs M) N i) x ≤ 0 := by + have hp := (hc 0).trans_le (hM 0) + have hf : RegularDatum (backwardBoundary c h (softAbs M) N i) := + cascade_regular (regularDatum_softAbs (ne_of_gt hp)) (softAbs_lipschitz (ne_of_gt hp)) c h _ _ + have hh := (backwardBoundary_shape c hc hmono hM h N i).second_nonpos x hx + rw [iteratedDeriv_const_mul_field,← iteratedDeriv_succ'] at hh + exact nonpos_of_mul_nonpos_right hh (hc i) + +lemma forwardBoundary_shape {M : ℝ} (c : ℕ → ℝ≥0) + (hc : ∀ i, 0 < (c i:ℝ)) (hmono : Monotone c) (hM : ∀ i, (c i:ℝ) ≤ M) + {h : ℝ≥0} (hh : 0 < (h:ℝ)) (N i : ℕ) : + ForwardDatumShape (forwardBoundary c h (softAbs M) N i) := by + have hp := (hc 0).trans_le (hM 0) + have hf := regularDatum_softAbs (ne_of_gt hp) + have hLip := softAbs_lipschitz (ne_of_gt hp) + induction i with + | zero => exact ForwardDatumShape.const _ + | succ i ih => + have hφ : RegularDatum (backwardBoundary c h (softAbs M) N (i+1)) := cascade_regular hf hLip c h _ _ + have heφ := cascade_even hf hLip (softAbs_even M) c h (N-(i+1)) (i+1) + have hv : ∀ x, 0 ≤ iteratedDeriv 2 (backwardBoundary c h (softAbs M) N (i+1)) x := by + intro x + simpa only [backwardBoundary,iteratedDeriv_succ,iteratedDeriv_zero] using + (cascade_curvature_pos hf hLip (softAbs_curvature_pos hp) c h (N-(i+1)) (i+1) x).le + have hw := backwardBoundary_third_nonpos c hc hmono hM h N (i+1) + have hδ : 0 ≤ (c (i+1):ℝ)-(c i:ℝ) := sub_nonneg.mpr (hmono (Nat.le_succ i)) + rw [forwardBoundary] + by_cases hi : i=0 + · subst i + simp only [ite_true] + exact ForwardDatumShape.jump contDiff_const hφ.smooth (ForwardDatumShape.const _) heφ hv hw hδ + · simp only [hi,ite_false] + have hr := forwardBoundary_regular hf hLip c hh N i + obtain ⟨K,hK⟩ := hr.exists_lipschitz + have ha := mul_pos (Nat.cast_pos.mpr (Nat.pos_of_ne_zero hi)) hh + exact ForwardDatumShape.jump (forwardCorrection_smooth hr hK h) hφ.smooth + (forwardCorrection_shape ha hr hK ih h.coe_nonneg) heφ hv hw hδ + +end ZeroTemperatureSK.Heat + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKSupport/Backward/TerminalTailValue.lean b/lean/OAI/Probability/SKSupport/Backward/TerminalTailValue.lean new file mode 100644 index 0000000000000000000000000000000000000000..38658064b2f76d05c4f1bc7c1bc48e3ccf1f7da5 --- /dev/null +++ b/lean/OAI/Probability/SKSupport/Backward/TerminalTailValue.lean @@ -0,0 +1,85 @@ +import Mathlib +import OAI.Probability.SKSupport.Diffusion.FiniteTransition + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology ContDiff +noncomputable section +namespace ZeroTemperatureSK +open Heat WeakIto Nonuniform +variable {Ω : Type*} [MeasurableSpace Ω] + +lemma abs_lipschitz : LipschitzWith (1:ℝ≥0) (abs : ℝ → ℝ) := by + apply LipschitzWith.of_dist_le_mul + intro x y + simpa only [Real.dist_eq,NNReal.coe_one,one_mul] using abs_abs_sub_abs_le_abs_sub x y + +lemma plateau_grid_error_zero (γ : OrderParameter) {a c t : ℝ} (hc0 : 0 ≤ c) + (ht0 : 0 ≤ t) (hat : a < t) (ht1 : t < 1) (hc : ∀ s ∈ Ioo a 1, extend γ.val s=c) : + gridError (fun _ => Real.toNNReal (1-t)) (fun _ => ⟨c,hc0⟩) (fun r => extend γ.val (t+r)) 1=0 := by + simp only [gridError,Finset.sum_range_one,time_zero,time_succ,zero_add,NNReal.coe_zero, + Real.coe_toNNReal _ (sub_nonneg.mpr ht1.le)] + have he : (∫ r in (0:ℝ)..(1-t), |c-extend γ.val (t+r)|)=∫ _r in (0:ℝ)..(1-t), (0:ℝ) := by + apply intervalIntegral.integral_congr_Ioo_of_le (sub_nonneg.mpr ht1.le) + intro r hr + change |c-extend γ.val (t+r)|=0 + have htr : t+r ∈ Ico (0:ℝ) 1 := ⟨add_nonneg ht0 hr.1.le,by linarith [hr.2]⟩ + have hval : γ.val ⟨t+r,htr⟩=c := by + simpa only [extend,dite_eq_left htr] using hc (t+r) ⟨by linarith [hr.1],htr.2⟩ + rw [extend,dite_eq_left htr,hval,sub_self,abs_zero] + change (∫ r in (0:ℝ)..(1-t), |c-extend γ.val (t+r)|)=0 + rw [he,intervalIntegral.integral_zero] + +theorem value_on_terminal_plateau (W : BrownianSystem Ω) (γ : OrderParameter) {a c t : ℝ} + (hc0 : 0 ≤ c) (ht0 : 0 ≤ t) (hat : a < t) (ht1 : t < 1) + (hc : ∀ s ∈ Ioo a 1, extend γ.val s=c) : + value W γ t=varianceLogHeat c (1-t) abs := by + funext x + rw [varianceLogHeat_eq_logSemigroup_toNNReal measurable_abs] + let H : ℕ → ℝ≥0 := fun _ => Real.toNNReal (1-t) + let C : ℕ → ℝ≥0 := fun _ => ⟨c,hc0⟩ + have hH : (time H 1:ℝ)=1-t := by simp only [time_succ,time_zero,zero_add,H,Real.coe_toNNReal _ (sub_nonneg.mpr ht1.le)] + have hb (n : ℕ) : |value W γ t x-logSemigroup c (Real.toNNReal (1-t)) abs x| ≤ + (2*Real.log 2)*(approxMesh n:ℝ) := by + let M : ℝ := ((n+1:ℕ):ℝ) + have hM : 0 < M := by dsimp [M];positivity + have he (z : ℝ) : |softAbs M z-abs z| ≤ Real.log 2/M := by + rw [abs_of_nonneg (softAbs_bounds hM z).1] + exact (softAbs_bounds hM z).2 + have hv := cascadeV_value_error W γ t x ht0 ht1.le H C 1 hH + (regularDatum_softAbs hM.ne') (softAbs_lipschitz hM.ne') he + rw [plateau_grid_error_zero γ hc0 ht0 hat ht1 hc] at hv + simp only [cascadeV,C,H,mul_zero,add_zero] at hv + change |logSemigroup c (Real.toNNReal (1-t)) (softAbs M) x-value W γ t x| ≤ Real.log 2/M at hv + have hv' : |value W γ t x-logSemigroup c (Real.toNNReal (1-t)) (softAbs M) x| ≤ Real.log 2/M := by + simpa only [abs_sub_comm] using hv + have hs := logSemigroup_terminal_stability (softAbs_lipschitz hM.ne') abs_lipschitz hc0 he (Real.toNNReal (1-t)) x + have htri := abs_sub_le (value W γ t x) (logSemigroup c (Real.toNNReal (1-t)) (softAbs M) x) + (logSemigroup c (Real.toNNReal (1-t)) abs x) + have heM : Real.log 2/M+Real.log 2/M=(2*Real.log 2)*(approxMesh n:ℝ) := by + simp only [M,approxMesh,NNReal.coe_inv,NNReal.coe_natCast] + ring + linarith + have hz : Tendsto (fun n => (2*Real.log 2)*(approxMesh n:ℝ)) atTop (𝓝 0) := by + simpa only [mul_zero] using tendsto_const_nhds.mul approxMesh_limit (a := 2*Real.log 2) + have he := ge_of_tendsto hz (Eventually.of_forall hb) + exact sub_eq_zero.mp (abs_eq_zero.mp (le_antisymm he (abs_nonneg _))) + +lemma value_plateau_semigroup (W : BrownianSystem Ω) (γ : OrderParameter) {a c s T : ℝ} + (hc0 : 0 ≤ c) (hs0 : 0 ≤ s) (has : a < s) (hsT : s ≤ T) (hT1 : T < 1) + (hc : ∀ r ∈ Ioo a 1, extend γ.val r=c) : + value W γ s=varianceLogHeat c (T-s) (value W γ T) := by + rw [value_on_terminal_plateau W γ hc0 hs0 has (hsT.trans_lt hT1) hc, + value_on_terminal_plateau W γ hc0 (hs0.trans hsT) (has.trans_le hsT) hT1 hc, + ← varianceLogHeat_add abs_lipschitz hc0 (sub_nonneg.mpr hsT) (sub_nonneg.mpr hT1.le)] + congr 1 + ring + +end ZeroTemperatureSK + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKSupport/Backward/TerminalTransition.lean b/lean/OAI/Probability/SKSupport/Backward/TerminalTransition.lean new file mode 100644 index 0000000000000000000000000000000000000000..a5bb9df50305671dca5ea79898ea25454e3417b6 --- /dev/null +++ b/lean/OAI/Probability/SKSupport/Backward/TerminalTransition.lean @@ -0,0 +1,59 @@ +import Mathlib +import OAI.Probability.SKSupport.Backward.TerminalTailValue +import OAI.Probability.SKSupport.Moments.StripSquareMoment + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology ContDiff +noncomputable section +namespace ZeroTemperatureSK +open Heat WeakIto +variable {Ω : Type*} [MeasurableSpace Ω] + +lemma value_regular (W : BrownianSystem Ω) (γ : OrderParameter) {t : ℝ} + (ht0 : 0 ≤ t) (ht1 : t < 1) : RegularDatum (value W γ t) := by + refine ⟨value_contDiff W γ ht0 ht1,?_⟩ + have hh := (compactGradient_family W γ ht0 ht1).regular t + change BoundedSmooth (deriv (value W γ (stripClamp t t))) at hh + rw [stripClamp_eq (show t ∈ Icc (0:ℝ) t from ⟨ht0,le_rfl⟩)] at hh + exact hh + +lemma gradientDefect_smooth (W : BrownianSystem Ω) (γ : OrderParameter) {t : ℝ} + (ht0 : 0 ≤ t) (ht1 : t < 1) : BoundedSmooth (fun x => 1-(gradient W γ t x)^2) := by + have hu := (value_regular W γ ht0 ht1).deriv_bounded + convert (BoundedSmooth.const 1).add ((hu.mul hu).const_mul (-1)) using 1 + funext x + unfold gradient + ring + +theorem terminal_plateau_transition (W : BrownianSystem Ω) (γ : OrderParameter) + {a c : ℝ} (hc0 : 0 ≤ c) (hc : ∀ r ∈ Ioo a 1, extend γ.val r=c) + (s T : Time) (has : a < (s:ℝ)) (hsT : s ≤ T) {g : ℝ → ℝ} (hg : BoundedSmooth g) : + (∫ ξ, g (diffusion W γ (⟨T,T.property.1⟩:ℝ≥0) ξ) ∂W.law)= + ∫ ξ, varianceTilted c ((T:ℝ)-s) (value W γ T) g + (diffusion W γ (⟨s,s.property.1⟩:ℝ≥0) ξ) ∂W.law := by + have hm : ∀ t ∈ Ico (s:ℝ) T, ∀ x, + (stripDrift W γ T).f t x=c*deriv (varianceLogHeat c ((T:ℝ)-t) (value W γ T)) x := by + intro t ht x + rw [stripDrift_eq W γ T ⟨s.property.1.trans ht.1,ht.2.le⟩, + hc t ⟨has.trans_le ht.1,ht.2.trans T.property.2⟩] + unfold gradient + rw [value_plateau_semigroup W γ hc0 (s.property.1.trans ht.1) (has.trans_le ht.1) ht.2.le T.property.2 hc] + have hh := expected_transition_tiltedMean W (stripDrift W γ T) + (value_regular W γ T.property.1 T.property.2) (value_lipschitz W γ T T.property.2.le) hg hc0 + (a := (⟨s,s.property.1⟩:ℝ≥0)) (T := (⟨T,T.property.1⟩:ℝ≥0)) hsT hm + have eT : diffusion W γ (⟨T,T.property.1⟩:ℝ≥0)=(stripDrift W γ T).solution W.driver (⟨T,T.property.1⟩:ℝ≥0) := + funext (diffusion_eq_strip W γ T (⟨T,T.property.1⟩:ℝ≥0) le_rfl) + have es : diffusion W γ (⟨s,s.property.1⟩:ℝ≥0)=(stripDrift W γ T).solution W.driver (⟨s,s.property.1⟩:ℝ≥0) := + funext (diffusion_eq_strip W γ T (⟨s,s.property.1⟩:ℝ≥0) hsT) + rw [eT,es] + exact hh + +end ZeroTemperatureSK + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKSupport/Backward/TiltedBackward.lean b/lean/OAI/Probability/SKSupport/Backward/TiltedBackward.lean new file mode 100644 index 0000000000000000000000000000000000000000..18befdaf619d2758ad009df8f916fe53eaf29303 --- /dev/null +++ b/lean/OAI/Probability/SKSupport/Backward/TiltedBackward.lean @@ -0,0 +1,136 @@ +import Mathlib +import OAI.Probability.SKSupport.Parabolic.ForwardRegularity +import OAI.Probability.SKSupport.Parabolic.TiltedEvolution + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology ContDiff +noncomputable section +namespace ZeroTemperatureSK.Heat + +lemma varianceTilted_time_continuous {f g : ℝ → ℝ} {K : ℝ≥0} + (hf : RegularDatum f) (hLip : LipschitzWith K f) (hg : BoundedSmooth g) (c x : ℝ) : + Continuous (fun t => varianceTilted c t f g x) := by + have hNc : Continuous (fun y => g y*Real.exp (c*f y)) := + hg.smooth.continuous.mul (Real.continuous_exp.comp (continuous_const.mul hf.smooth.continuous)) + have hNb : ExponentialBound (fun y => g y*Real.exp (c*f y)) := by + simpa only [iteratedDeriv_zero] using exponentialBound_weightExp_iteratedDeriv hf hLip hg c 0 + exact (continuous_varianceHeat hNc hNb x).div + (continuous_varianceHeat (Real.continuous_exp.comp (continuous_const.mul hf.smooth.continuous)) + (exponentialBound_exp hLip c) x) + (fun t => ne_of_gt (varianceHeat_exp_pos hLip c t x)) + +lemma varianceTilted_joint_continuous {f g : ℝ → ℝ} {K : ℝ≥0} + (hf : RegularDatum f) (hLip : LipschitzWith K f) (hg : BoundedSmooth g) {c : ℝ} (hc : 0 ≤ c) : + Continuous (fun p : ℝ × ℝ => varianceTilted c p.1 f g p.2) := by + obtain ⟨L,hL⟩ := varianceTilted_space_lipschitz hf hLip hg hc + apply continuous_iff_continuousAt.mpr + intro p + have hlim : Tendsto (fun q : ℝ × ℝ => (L:ℝ)*|q.2-p.2|+ + |varianceTilted c q.1 f g p.2-varianceTilted c p.1 f g p.2|) (𝓝 p) (𝓝 0) := by + have hh : Continuous (fun q : ℝ × ℝ => (L:ℝ)*|q.2-p.2|+ + |varianceTilted c q.1 f g p.2-varianceTilted c p.1 f g p.2|) := by + exact (continuous_const.mul (continuous_snd.sub continuous_const).abs).add + (((varianceTilted_time_continuous hf hLip hg c p.2).comp continuous_fst).sub continuous_const).abs + simpa only [sub_self,abs_zero,mul_zero,add_zero] using hh.continuousAt.tendsto (x := p) + change Tendsto (fun q : ℝ × ℝ => varianceTilted c q.1 f g q.2) (𝓝 p) + (𝓝 (varianceTilted c p.1 f g p.2)) + rw [Metric.tendsto_nhds] + intro ε hε + filter_upwards [hlim.eventually (gt_mem_nhds hε)] with q hq + have hb := (hL q.1).dist_le_mul q.2 p.2 + have htri := dist_triangle (varianceTilted c q.1 f g q.2) (varianceTilted c q.1 f g p.2) + (varianceTilted c p.1 f g p.2) + simp only [Real.dist_eq] at hb htri ⊢ + exact (htri.trans (add_le_add hb le_rfl)).trans_lt hq + +def tiltedRate (c : ℝ) (f g : ℝ → ℝ) (t x : ℝ) := + (1/2:ℝ)*deriv (deriv (varianceTilted c t f g)) x+ + c*deriv (varianceLogHeat c t f) x*deriv (varianceTilted c t f g) x + +lemma tiltedRate_family {f g : ℝ → ℝ} {K : ℝ≥0} + (hf : RegularDatum f) (hLip : LipschitzWith K f) (hg : BoundedSmooth g) {c : ℝ} (hc : 0 ≤ c) : + BoundedSmoothFamily (tiltedRate c f g) := by + have hU := varianceTilted_family hf hLip hg hc + exact (hU.deriv.deriv.const_mul (1/2:ℝ)).add (((varianceGradient_family hf hLip hc).const_mul c).mul hU.deriv) + +lemma tiltedRate_continuousOn {f g : ℝ → ℝ} {K : ℝ≥0} + (hf : RegularDatum f) (hLip : LipschitzWith K f) (hg : BoundedSmooth g) {c : ℝ} (hc : 0 ≤ c) (T : ℝ) : + ContinuousOn (fun p : ℝ × ℝ => tiltedRate c f g p.1 p.2) (Icc (0:ℝ) T ×ˢ univ) := by + have hU := varianceTilted_family hf hLip hg hc + have hUc := varianceTilted_joint_continuous hf hLip hg hc + have hUx := hU.continuous_iteratedDeriv hUc 1 + have hUxx := hU.continuous_iteratedDeriv hUc 2 + simp only [iteratedDeriv_succ,iteratedDeriv_zero] at hUx hUxx + exact (continuous_const.mul hUxx).continuousOn.add + ((continuousOn_const.mul (varianceGradient_continuousOn hf hLip hc T)).mul hUx.continuousOn) + +def tiltedBackward (c T : ℝ) (f g : ℝ → ℝ) (t x : ℝ) := varianceTilted c (T-t) f g x + +def tiltedBackwardRate (c T : ℝ) (f g : ℝ → ℝ) (t x : ℝ) := -tiltedRate c f g (T-t) x + +lemma tiltedBackward_family {f g : ℝ → ℝ} {K : ℝ≥0} + (hf : RegularDatum f) (hLip : LipschitzWith K f) (hg : BoundedSmooth g) {c : ℝ} (hc : 0 ≤ c) (T : ℝ) : + BoundedSmoothFamily (tiltedBackward c T f g) := by + unfold tiltedBackward + simpa only [one_mul] using (varianceTilted_family hf hLip hg hc).reparam + (A := fun t => T-t) (C := fun _ => 1) (measurable_const.sub measurable_id) measurable_const (fun _ => by norm_num) + +lemma tiltedBackwardRate_family {f g : ℝ → ℝ} {K : ℝ≥0} + (hf : RegularDatum f) (hLip : LipschitzWith K f) (hg : BoundedSmooth g) {c : ℝ} (hc : 0 ≤ c) (T : ℝ) : + BoundedSmoothFamily (tiltedBackwardRate c T f g) := by + unfold tiltedBackwardRate + simpa only [one_mul,neg_one_mul] using ((tiltedRate_family hf hLip hg hc).reparam + (A := fun t => T-t) (C := fun _ => 1) (measurable_const.sub measurable_id) measurable_const + (fun _ => by norm_num)).const_mul (-1) + +lemma tiltedBackward_continuous {f g : ℝ → ℝ} {K : ℝ≥0} + (hf : RegularDatum f) (hLip : LipschitzWith K f) (hg : BoundedSmooth g) {c : ℝ} (hc : 0 ≤ c) (T : ℝ) : + Continuous (fun p : ℝ × ℝ => tiltedBackward c T f g p.1 p.2) := + (varianceTilted_joint_continuous hf hLip hg hc).comp ((continuous_const.sub continuous_fst).prodMk continuous_snd) + +lemma tiltedBackwardRate_continuousOn {f g : ℝ → ℝ} {K : ℝ≥0} + (hf : RegularDatum f) (hLip : LipschitzWith K f) (hg : BoundedSmooth g) {c : ℝ} (hc : 0 ≤ c) (T : ℝ) : + ContinuousOn (fun p : ℝ × ℝ => tiltedBackwardRate c T f g p.1 p.2) (Icc (0:ℝ) T ×ˢ univ) := by + change ContinuousOn (fun p : ℝ × ℝ => -tiltedRate c f g (T-p.1) p.2) _ + exact (tiltedRate_continuousOn hf hLip hg hc T |>.neg).comp + (f := fun p : ℝ × ℝ => (T-p.1,p.2)) + ((continuous_const.sub continuous_fst).prodMk continuous_snd).continuousOn + (fun p hp => ⟨⟨sub_nonneg.mpr hp.1.2,sub_le_self _ hp.1.1⟩,mem_univ _⟩) + +lemma tiltedBackward_time {f g : ℝ → ℝ} {K : ℝ≥0} + (hf : RegularDatum f) (hLip : LipschitzWith K f) (hg : BoundedSmooth g) {c : ℝ} (hc : 0 ≤ c) + {T t : ℝ} (ht : t < T) (x : ℝ) : + HasDerivAt (fun u => tiltedBackward c T f g u x) (tiltedBackwardRate c T f g t x) t := by + have hh := ((varianceTilted_equation hf hLip hg hc (sub_nonneg.mpr ht.le) x).hasDerivAt + (Ici_mem_nhds (sub_pos.mpr ht))).comp t ((hasDerivAt_id t).const_sub T) + convert hh using 1 <;> first | rfl | (dsimp [tiltedBackwardRate,tiltedRate];ring) + +lemma tiltedBackward_integrated_rate {f g : ℝ → ℝ} {K : ℝ≥0} + (hf : RegularDatum f) (hLip : LipschitzWith K f) (hg : BoundedSmooth g) {c : ℝ} (hc : 0 ≤ c) + {T a b : ℝ} (ha : 0 ≤ a) (hab : a ≤ b) (hb : b ≤ T) (x : ℝ) : + tiltedBackward c T f g b x-tiltedBackward c T f g a x = + ∫ t in a..b, tiltedBackwardRate c T f g t x := by + symm + apply intervalIntegral.integral_eq_sub_of_hasDerivAt_of_le hab + · exact ((tiltedBackward_continuous hf hLip hg hc T).comp + (continuous_id.prodMk continuous_const)).continuousOn + · intro t ht + exact tiltedBackward_time hf hLip hg hc (ht.2.trans_le hb) x + · apply ContinuousOn.intervalIntegrable_of_Icc hab + exact (tiltedBackwardRate_continuousOn hf hLip hg hc T).comp + (f := fun t : ℝ => (t,x)) (continuous_id.prodMk continuous_const).continuousOn + (fun t ht => ⟨⟨ha.trans ht.1,ht.2.trans hb⟩,mem_univ _⟩) + +lemma tiltedBackward_terminal (c T : ℝ) (f g : ℝ → ℝ) (x : ℝ) : tiltedBackward c T f g T x=g x := by + simp only [tiltedBackward,sub_self,varianceTilted,varianceHeat_zero] + exact mul_div_cancel_right₀ _ (Real.exp_ne_zero _) + +end ZeroTemperatureSK.Heat + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKSupport/Control/CoefficientApprox.lean b/lean/OAI/Probability/SKSupport/Control/CoefficientApprox.lean new file mode 100644 index 0000000000000000000000000000000000000000..74ab91e372508f87006a601ee170bce86a4669fb --- /dev/null +++ b/lean/OAI/Probability/SKSupport/Control/CoefficientApprox.lean @@ -0,0 +1,236 @@ +import Mathlib +import OAI.Probability.SKSupport.Foundations.Taylor1Bound +import OAI.Probability.SKSupport.Control.GridApprox + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology ContDiff +noncomputable section +namespace ZeroTemperatureSK +open WeakIto Heat Nonuniform + +def approxMesh (n : ℕ) : ℝ≥0 := ((n+1:ℕ):ℝ≥0)⁻¹ + +lemma approxMesh_pos (n : ℕ) : 0 < approxMesh n := by unfold approxMesh; positivity + +lemma approxMesh_horizon (n : ℕ) : ((n+1:ℕ):ℝ)*approxMesh n = 1 := by + simp only [approxMesh,NNReal.coe_inv,NNReal.coe_natCast] + exact mul_inv_cancel₀ (by positivity) + +lemma approxMesh_limit : Tendsto (fun n => (approxMesh n:ℝ)) atTop (𝓝 0) := by + simpa only [approxMesh,NNReal.coe_inv,NNReal.coe_natCast,Nat.cast_add,Nat.cast_one,NNReal.coe_add,NNReal.coe_one,one_div] using + (tendsto_one_div_add_atTop_nhds_zero_nat (𝕜 := ℝ)) + +lemma sample_mem (n j : ℕ) (hj : j < n+1) : (j:ℝ)*approxMesh n ∈ Ico (0:ℝ) 1 := by + refine ⟨mul_nonneg (Nat.cast_nonneg _) (approxMesh n).coe_nonneg,?_⟩ + rw [← approxMesh_horizon n] + exact mul_lt_mul_of_pos_right (by exact_mod_cast hj) (by exact_mod_cast approxMesh_pos n) + +def approxCoeff (γ : OrderParameter) (n j : ℕ) : ℝ≥0 := + if hj : j < n+1 then + Real.toNNReal (γ.val ⟨(j:ℝ)*approxMesh n,sample_mem n j hj⟩) else 0 + +def approxGamma (γ : OrderParameter) (n : ℕ) : ℝ → ℝ := + finiteCoeff (approxCoeff γ n) (approxMesh n) (n+1) 0 + +lemma approxCoeff_eq (γ : OrderParameter) (n j : ℕ) (hj : j < n+1) : + (approxCoeff γ n j:ℝ) = γ.val ⟨(j:ℝ)*approxMesh n,sample_mem n j hj⟩ := by + unfold approxCoeff + rw [dite_eq_left hj,Real.coe_toNNReal _ (γ.nonneg _)] + +lemma approxGamma_samples (γ : OrderParameter) (n : ℕ) (t : Time) : + ∃ (j : ℕ) (hj : j < n+1), approxGamma γ n t = γ.val ⟨(j:ℝ)*approxMesh n,sample_mem n j hj⟩ ∧ + (j:ℝ)*approxMesh n ≤ t ∧ (t:ℝ) ≤ ((j+1:ℕ):ℝ)*approxMesh n := by + obtain ⟨j,hj,he,hl,hu⟩ := finiteCoeff_sample (approxCoeff γ n) (approxMesh_pos n) + (n+1) 0 t.property.1 (by rw [approxMesh_horizon]; exact t.property.2.le) (by omega) + refine ⟨j,hj,?_,hl,hu⟩ + simpa only [approxGamma,Nat.zero_add,approxCoeff_eq γ n j hj] using he + +lemma approxGamma_bounds (γ : OrderParameter) (n : ℕ) (t : Time) : + 0 ≤ approxGamma γ n t ∧ approxGamma γ n t ≤ γ.val t := by + obtain ⟨j,hj,he,hl,hu⟩ := approxGamma_samples γ n t + rw [he] + exact ⟨γ.nonneg _,γ.monotone hl⟩ + +lemma approxGamma_tendsto (γ : OrderParameter) (t : Time) (ht : ContinuousAt γ.val t) : + Tendsto (fun n => approxGamma γ n t) atTop (𝓝 (γ.val t)) := by + choose j hj he hl hu using fun n => approxGamma_samples γ n t + let q (n : ℕ) : Time := ⟨(j n:ℝ)*approxMesh n,sample_mem n (j n) (hj n)⟩ + have hq : Tendsto (fun n => (q n:ℝ)) atTop (𝓝 (t:ℝ)) := by + apply tendsto_of_tendsto_of_tendsto_of_le_of_le + (show Tendsto (fun n => (t:ℝ)-(approxMesh n:ℝ)) atTop (𝓝 (t:ℝ)) by + simpa only [sub_zero] using tendsto_const_nhds.sub approxMesh_limit) + tendsto_const_nhds + · intro n + have hh := hu n + push_cast at hh + dsimp only [q] + nlinarith + · exact hl + have hqt : Tendsto q atTop (𝓝 t) := tendsto_subtype_rng.mpr hq + have hh := ht.tendsto.comp hqt + convert hh using 1 + funext n + exact he n + +lemma OrderParameter.ae_continuous (γ : OrderParameter) : + ∀ᵐ s : ℝ, ∀ hs : s ∈ Ico (0:ℝ) 1, ContinuousAt γ.val ⟨s,hs⟩ := by + have hc := γ.monotone.countable_not_continuousAt.image (fun t : Time => (t:ℝ)) + have hz := hc.measure_zero volume + have ha : ∀ᵐ s : ℝ, s ∉ (fun t : Time => (t:ℝ)) '' {t | ¬ContinuousAt γ.val t} := + (ae_iff.mpr (by simpa only [not_not,Set.ofPred_mem_eq] using hz)) + filter_upwards [ha] with s hs hmem + by_contra hn + exact hs ⟨⟨s,hmem⟩,hn,rfl⟩ + +lemma approxGamma_L1 (γ : OrderParameter) : + Tendsto (fun n => ∫ s in (0:ℝ)..1, |approxGamma γ n s-extend γ.val s|) + atTop (𝓝 0) := by + have hint : ∀ n, AEStronglyMeasurable (fun s => |approxGamma γ n s-extend γ.val s|) + (volume.restrict (Ioo (0:ℝ) 1)) := fun n => + ((measurable_finiteCoeff _ _ _ _).sub γ.measurable_extend).abs.aestronglyMeasurable + have hb : ∀ n, ∀ᵐ s ∂volume.restrict (Ioo (0:ℝ) 1), + ‖|approxGamma γ n s-extend γ.val s|‖ ≤ extend γ.val s := by + intro n + filter_upwards [ae_restrict_mem measurableSet_Ioo] with s hs + have hm : s ∈ Ico (0:ℝ) 1 := ⟨hs.1.le,hs.2⟩ + have hh := approxGamma_bounds γ n ⟨s,hm⟩ + rw [Real.norm_eq_abs,abs_abs,show extend γ.val s = γ.val ⟨s,hm⟩ by simp [extend,hm]] + rw [abs_of_nonpos (sub_nonpos.mpr hh.2)] + linarith [hh.1] + have hlim : ∀ᵐ s ∂volume.restrict (Ioo (0:ℝ) 1), + Tendsto (fun n => |approxGamma γ n s-extend γ.val s|) atTop (𝓝 (0:ℝ)) := by + filter_upwards [ae_restrict_mem measurableSet_Ioo, + (γ.ae_continuous).filter_mono (ae_mono Measure.restrict_le_self)] with s hs hc + have hm : s ∈ Ico (0:ℝ) 1 := ⟨hs.1.le,hs.2⟩ + have hh := (approxGamma_tendsto γ ⟨s,hm⟩ (hc hm)).sub (tendsto_const_nhds (x := γ.val ⟨s,hm⟩)) + have he : extend γ.val s = γ.val ⟨s,hm⟩ := by simp [extend,hm] + simpa only [he,sub_self,abs_zero] using hh.abs + have hh := tendsto_integral_of_dominated_convergence (extend γ.val) hint + γ.integrable.integrableOn hb hlim + simp only [integral_zero] at hh + convert hh using 1 + funext n + exact intervalIntegral.integral_of_le (by norm_num : (0:ℝ) ≤ 1) |>.trans + (integral_Ioc_eq_integral_Ioo) + +end ZeroTemperatureSK + +end +end +section +open Set Filter MeasureTheory ProbabilityTheory +open scoped Topology ContDiff NNReal ENNReal +noncomputable section +namespace ZeroTemperatureSK.Heat + +lemma uniformCauchySeq_deriv_of_bound {f : ℕ → ℝ → ℝ} {g : ℝ → ℝ} + (hf : ∀ n, ContDiff ℝ 2 (f n)) {C : ℝ} (hC : 0 ≤ C) + (hb : ∀ n x, |deriv (deriv (f n)) x| ≤ C) + (hlim : TendstoUniformly f g atTop) : + UniformCauchySeqOn (fun n => deriv (f n)) atTop Set.univ := by + rw [Metric.uniformCauchySeqOn_iff] + rw [Metric.tendstoUniformly_iff] at hlim + intro ε hε + let h : ℝ := ε / (2*C+1) + have hh : 0 < h := div_pos hε (by positivity) + have hδ : 0 < ε*h/8 := by positivity + obtain ⟨N,hN⟩ := eventually_atTop.mp (hlim (ε*h/8) hδ) + refine ⟨N,fun m hm n hn x _ => ?_⟩ + have hA : ∀ y, |(f m-f n) y| ≤ 2*(ε*h/8) := by + intro y + have hm' := hN m hm y + have hn' := hN n hn y + simp only [Real.dist_eq] at hm' hn' + calc + _ = |(g y-f n y)-(g y-f m y)| := by simp only [Pi.sub_apply]; congr 1; ring + _ ≤ |g y-f n y|+|g y-f m y| := abs_sub _ _ + _ ≤ _ := by linarith + have hd (y : ℝ) : deriv (f m-f n) y = deriv (f m) y-deriv (f n) y := + deriv_sub ((hf m).differentiable (by norm_num) y) ((hf n).differentiable (by norm_num) y) + have hdd (y : ℝ) : deriv (deriv (f m-f n)) y = + deriv (deriv (f m)) y-deriv (deriv (f n)) y := by + rw [show deriv (f m-f n) = deriv (f m)-deriv (f n) from funext hd] + exact deriv_sub + (by simpa only [iteratedDeriv_one] using (hf m).differentiable_iteratedDeriv 1 (by norm_num) y) + (by simpa only [iteratedDeriv_one] using (hf n).differentiable_iteratedDeriv 1 (by norm_num) y) + have hdC : ∀ y, |deriv (deriv (f m-f n)) y| ≤ 2*C := by + intro y + rw [hdd] + exact (abs_sub _ _).trans (by linarith [hb m y,hb n y]) + have hi := derivative_interpolation ((hf m).sub (hf n)) hA hdC hh x + have hc : h*(2*C) < ε := by + dsimp [h] + rw [div_mul_eq_mul_div] + apply (div_lt_iff₀ (by positivity : (0:ℝ)<2*C+1)).mpr + nlinarith + have he : 2*(2*(ε*h/8))/h = ε/2 := by field_simp; ring + change |deriv (f m-f n) x| ≤ 2*(2*(ε*h/8))/h+h*(2*C)/2 at hi + rw [he,hd] at hi + rw [Real.dist_eq] + linarith + +theorem tendstoUniformly_deriv_of_bound {f : ℕ → ℝ → ℝ} {g : ℝ → ℝ} + (hf : ∀ n, ContDiff ℝ 2 (f n)) {C : ℝ} (hC : 0 ≤ C) + (hb : ∀ n x, |deriv (deriv (f n)) x| ≤ C) + (hlim : TendstoUniformly f g atTop) : + Differentiable ℝ g ∧ + TendstoUniformly (fun n => deriv (f n)) (deriv g) atTop := by + have hc := uniformCauchySeq_deriv_of_bound hf hC hb hlim + let d : ℝ → ℝ := fun x => atTop.limUnder (fun n => deriv (f n) x) + have hd : TendstoUniformly (fun n => deriv (f n)) d atTop := by + rw [← tendstoUniformlyOn_univ] + exact hc.tendstoUniformlyOn_of_tendsto (fun x _ => (hc.cauchySeq (mem_univ x)).tendsto_limUnder) + have hg (x : ℝ) : HasDerivAt g (d x) x := + hasDerivAt_of_tendstoUniformly hd (Filter.Eventually.of_forall + (fun n x => ((hf n).differentiable (by norm_num) x).hasDerivAt)) hlim.tendsto_at x + refine ⟨fun x => (hg x).differentiableAt, ?_⟩ + have he : deriv g = d := funext (fun x => (hg x).deriv) + rwa [he] + +lemma contDiff_iteratedDeriv_infty {f : ℝ → ℝ} (hf : ContDiff ℝ ∞ f) (m : ℕ) : + ContDiff ℝ ∞ (iteratedDeriv m f) := by + induction m with + | zero => simpa only [iteratedDeriv_zero] using hf + | succ m ih => + rw [iteratedDeriv_succ] + exact (contDiff_infty_iff_deriv.mp ih).2 + +theorem smooth_limit_of_uniform_derivative_bounds {f : ℕ → ℝ → ℝ} {g : ℝ → ℝ} + (hf : ∀ n, ContDiff ℝ ∞ (f n)) + (hb : ∀ m : ℕ, ∃ C : ℝ, 0 ≤ C ∧ ∀ n x, |iteratedDeriv (m+2) (f n) x| ≤ C) + (hlim : TendstoUniformly f g atTop) : + ContDiff ℝ ∞ g ∧ + ∀ m : ℕ, TendstoUniformly (fun n => iteratedDeriv m (f n)) (iteratedDeriv m g) atTop := by + have hconv (m : ℕ) : + TendstoUniformly (fun n => iteratedDeriv m (f n)) (iteratedDeriv m g) atTop := by + induction m with + | zero => simpa only [iteratedDeriv_zero] using hlim + | succ m ih => + obtain ⟨C,hC,hbC⟩ := hb m + have hh := tendstoUniformly_deriv_of_bound + (fun n => (contDiff_iteratedDeriv_infty (hf n) m).of_le (ENat.natCast_le_of_coe_top_le_withTop le_rfl 2)) + hC (by simpa only [show m+2=(m+1)+1 by omega,iteratedDeriv_succ] using hbC) ih + simpa only [iteratedDeriv_succ] using hh.2 + refine ⟨?_,hconv⟩ + apply contDiff_of_differentiable_iteratedDeriv + intro m _hm + obtain ⟨C,hC,hbC⟩ := hb m + exact (tendstoUniformly_deriv_of_bound + (fun n => (contDiff_iteratedDeriv_infty (hf n) m).of_le (ENat.natCast_le_of_coe_top_le_withTop le_rfl 2)) + hC (by simpa only [show m+2=(m+1)+1 by omega,iteratedDeriv_succ] using hbC) (hconv m)).1 + +lemma iteratedDeriv_limit_bound {f : ℕ → ℝ → ℝ} {g : ℝ → ℝ} (m : ℕ) {C : ℝ} + (hconv : TendstoUniformly (fun n => iteratedDeriv m (f n)) (iteratedDeriv m g) atTop) + (hb : ∀ n x, |iteratedDeriv m (f n) x| ≤ C) (x : ℝ) : + |iteratedDeriv m g x| ≤ C := by + exact le_of_tendsto (hconv.tendsto_at x).abs (Filter.Eventually.of_forall (fun n => hb n x)) + +end ZeroTemperatureSK.Heat + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKSupport/Control/ControlPayoffConvex.lean b/lean/OAI/Probability/SKSupport/Control/ControlPayoffConvex.lean new file mode 100644 index 0000000000000000000000000000000000000000..1873adca207fdd77f07b6ba1d6bf1c9219695430 --- /dev/null +++ b/lean/OAI/Probability/SKSupport/Control/ControlPayoffConvex.lean @@ -0,0 +1,74 @@ +import Mathlib +import OAI.Probability.SKSupport.Control.ExpectedControlPayoff + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section +namespace ZeroTemperatureSK + +variable {Ω : Type*} [MeasurableSpace Ω] + +lemma controlPayoff_convex (W : BrownianSystem Ω) (γ : OrderParameter) + (t : ℝ) (α : Control W (Real.toNNReal t)) (ω : Ω) : + ConvexOn ℝ Set.univ (fun x => controlPayoff W γ t x α ω) := by + have h := ((convexOn_norm (E := ℝ) (s := Set.univ) convex_univ).translate_left + (W.B 1 ω - W.B (Real.toNNReal t) ω + + ∫ s in t..1, extend γ.val s * α.val (Real.toNNReal (s-t)) ω)).add_const + (-(1 / 2 : ℝ) * ∫ s in t..1, extend γ.val s * (α.val (Real.toNNReal (s-t)) ω)^2) + simpa only [Set.preimage_univ, Function.comp_def, Pi.add_def, Pi.add_apply, Real.norm_eq_abs, controlPayoff, + sub_eq_add_neg, neg_mul, add_assoc] using h + +lemma expected_controlPayoff_convex (W : BrownianSystem Ω) (γ : OrderParameter) + (t : ℝ) (ht : t ≤ 1) (α : Control W (Real.toNNReal t)) : + ConvexOn ℝ Set.univ (fun x => ∫ ω, controlPayoff W γ t x α ω ∂W.law) := by + exact integral_convexOn_of_integrand_ae convex_univ + (Filter.Eventually.of_forall (controlPayoff_convex W γ t α)) + (fun x _ => controlPayoff_integrable W γ t x ht α) + +theorem value_convex (W : BrownianSystem Ω) (γ : OrderParameter) + (t : ℝ) (ht : t ≤ 1) : ConvexOn ℝ Set.univ (value W γ t) := by + refine ⟨convex_univ, ?_⟩ + intro x hx y hy a b ha hb hab + simp only [smul_eq_mul] + change sSup (Set.range (fun α : Control W (Real.toNNReal t) => + ∫ ω, controlPayoff W γ t (a*x+b*y) α ω ∂W.law)) ≤ _ + refine csSup_le ?_ ?_ + · exact ⟨_, ⟨zeroControl W (Real.toNNReal t), rfl⟩⟩ + rintro _ ⟨α, rfl⟩ + calc + _ ≤ a * (∫ ω, controlPayoff W γ t x α ω ∂W.law) + + b * (∫ ω, controlPayoff W γ t y α ω ∂W.law) := by + simpa only [smul_eq_mul] using + (expected_controlPayoff_convex W γ t ht α).2 hx hy ha hb hab + _ ≤ _ := add_le_add + (mul_le_mul_of_nonneg_left (expected_controlPayoff_le_value W γ t x ht α) ha) + (mul_le_mul_of_nonneg_left (expected_controlPayoff_le_value W γ t y ht α) hb) + +lemma OrderParameter.local_bound (γ : OrderParameter) (t b : Time) (htb : t ≤ b) : + γ.val t ≤ (∫ s in (0 : ℝ)..1, extend γ.val s) / (1 - (b : ℝ)) := by + have hpoint : (fun _ : ℝ => γ.val t) ≤ᵐ[volume.restrict (Set.Icc (b : ℝ) 1)] extend γ.val := by + apply (ae_restrict_iff' measurableSet_Icc).2 + filter_upwards [volume.ae_ne (1 : ℝ)] with s hs hsb + have hs1 : s < 1 := lt_of_le_of_ne hsb.2 hs + have hs0 : 0 ≤ s := le_trans b.property.1 hsb.1 + have hts : t ≤ (⟨s, hs0, hs1⟩ : Time) := le_trans htb hsb.1 + simpa only [extend, dite_eq_left (show s ∈ Set.Ico (0 : ℝ) 1 from ⟨hs0, hs1⟩)] using + γ.monotone hts + have hlow := intervalIntegral.integral_mono_ae_restrict b.property.2.le + (intervalIntegrable_const (c := γ.val t)) γ.integrable.intervalIntegrable hpoint + simp only [intervalIntegral.integral_const, smul_eq_mul] at hlow + have hupper := intervalIntegral.integral_mono_interval b.property.1 b.property.2.le + (le_refl (1 : ℝ)) (Filter.Eventually.of_forall (fun s => γ.extend_nonneg s)) + γ.integrable.intervalIntegrable + apply (le_div_iff₀ (sub_pos.mpr b.property.2)).2 + linarith + +end ZeroTemperatureSK + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKSupport/Control/ControlledGrid.lean b/lean/OAI/Probability/SKSupport/Control/ControlledGrid.lean new file mode 100644 index 0000000000000000000000000000000000000000..3af6b0d7bec51d02fc71e6750187dd72c1203274 --- /dev/null +++ b/lean/OAI/Probability/SKSupport/Control/ControlledGrid.lean @@ -0,0 +1,137 @@ +import Mathlib +import OAI.Probability.SKSupport.Foundations.ControlledState +import OAI.Probability.SKSupport.Foundations.ElementaryControl + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section +namespace ZeroTemperatureSK.WeakIto +variable {Ω : Type*} [mΩ : MeasurableSpace Ω] {P : Measure Ω} {B : ℝ≥0 → Ω → ℝ} + +lemma progressive_stepDrift_measurable (ℱ : Filtration ℝ≥0 mΩ) + {α : ℝ≥0 → Ω → ℝ} (hap : IsProgressive ℱ α) (hab : ∀ t ω, |α t ω| ≤ 1) + (s h : ℝ≥0) (c : ℝ) : + Measurable[ℱ (s+h)] (stepDrift (fun r => α (Real.toNNReal r)) s h c) := by + have ham := progressive_joint_measurable ℱ hap + have ham' : Measurable (fun p : ℝ × Ω => α (Real.toNNReal p.1) p.2) := + ham.comp (measurable_fst.real_toNNReal.prodMk measurable_snd) + have h₁ := progressive_integral_measurable ℱ hap (s+h) (w := fun _ => c) measurable_const + have h₂ := (progressive_integral_measurable ℱ hap s (w := fun _ => c) measurable_const).mono + (ℱ.mono (show s ≤ s+h from le_add_of_nonneg_right (show (0:ℝ≥0) ≤ h from zero_le))) le_rfl + have he : stepDrift (fun r => α (Real.toNNReal r)) s h c = fun ω => + (∫ r in (0:ℝ)..((s+h:ℝ≥0):ℝ), c*α (Real.toNNReal r) ω)- + (∫ r in (0:ℝ)..(s:ℝ), c*α (Real.toNNReal r) ω) := by + funext ω + have hh := stepDrift_add (α := fun r => α (Real.toNNReal r)) ham' (fun r ω => hab _ ω) c s h ω + simpa only [stepDrift, zero_add, NNReal.coe_add] using (eq_sub_of_add_eq' hh.symm) + rw [he] + exact h₁.sub h₂ + +def controlledGrid (B : ℝ≥0 → Ω → ℝ) (α : ℝ≥0 → Ω → ℝ) (h : ℝ≥0) + (c : ℕ → ℝ≥0) (x : ℝ) : ℕ → Ω → ℝ + | 0, _ => x + | n+1, ω => controlledGrid B α h c x n ω+ + (B (((n+1:ℕ):ℝ≥0)*h) ω-B ((n:ℝ≥0)*h) ω)+ + stepDrift (fun r => α (Real.toNNReal r)) ((n:ℝ≥0)*h) h (c n) ω + +lemma controlledGrid_adapted (hm : ∀ t, Measurable (B t)) + {α : ℝ≥0 → Ω → ℝ} + (hap : IsProgressive (Filtration.natural B (fun t => (hm t).stronglyMeasurable)) α) + (hab : ∀ t ω, |α t ω| ≤ 1) (h : ℝ≥0) (c : ℕ → ℝ≥0) (x : ℝ) (n : ℕ) : + Measurable[Filtration.natural B (fun t => (hm t).stronglyMeasurable) ((n:ℝ≥0)*h)] + (controlledGrid B α h c x n) := by + induction n with + | zero => exact measurable_const + | succ n IH => + have hle : (n:ℝ≥0)*h ≤ ((n+1:ℕ):ℝ≥0)*h := by gcongr; exact_mod_cast Nat.le_succ n + have hYm := IH.mono ((Filtration.natural B (fun t => (hm t).stronglyMeasurable)).mono hle) le_rfl + have hBs := (Filtration.stronglyAdapted_natural (fun t => (hm t).stronglyMeasurable) ((n:ℝ≥0)*h)).measurable.mono + ((Filtration.natural B (fun t => (hm t).stronglyMeasurable)).mono hle) le_rfl + have hBt := (Filtration.stronglyAdapted_natural (fun t => (hm t).stronglyMeasurable) (((n+1:ℕ):ℝ≥0)*h)).measurable + have ht : (n:ℝ≥0)*h+h = ((n+1:ℕ):ℝ≥0)*h := by push_cast; ring + have hAm := progressive_stepDrift_measurable _ hap hab ((n:ℝ≥0)*h) h (c n) + rw [ht] at hAm + exact (hYm.add (hBt.sub hBs)).add hAm + +lemma controlledGrid_integrable (hB : IsPreBrownianReal B P) + {α : ℝ≥0 → Ω → ℝ} (ham : Measurable (fun p : ℝ≥0 × Ω => α p.1 p.2)) + (hab : ∀ t ω, |α t ω| ≤ 1) (h : ℝ≥0) (c : ℕ → ℝ≥0) (x : ℝ) (n : ℕ) : + Integrable (controlledGrid B α h c x n) P := by + let := hB.isGaussianProcess.isProbabilityMeasure + have ham' : Measurable (fun p : ℝ × Ω => α (Real.toNNReal p.1) p.2) := + ham.comp (measurable_fst.real_toNNReal.prodMk measurable_snd) + induction n with + | zero => exact integrable_const x + | succ n IH => + exact (IH.add ((hB.integrable_eval _).sub (hB.integrable_eval _))).add + (stepDrift_integrable ham' (fun r ω => hab _ ω) ((n:ℝ≥0)*h) h (c n) h.coe_nonneg (c n).coe_nonneg) + +lemma variable_grid_verification_upper (hB : IsPreBrownianReal B P) + (hm : ∀ t, Measurable (B t)) {α : ℝ≥0 → Ω → ℝ} + (hap : IsProgressive (Filtration.natural B (fun t => (hm t).stronglyMeasurable)) α) + (hab : ∀ t ω, |α t ω| ≤ 1) (h : ℝ≥0) (c : ℕ → ℝ≥0) (x : ℝ) (n : ℕ) + {F D : ℕ → ℝ → ℝ → ℝ} (C₂ C₃ Ct L : ℕ → ℝ≥0) + (hf : ∀ k < n, ∀ t, ContDiff ℝ 3 (F k t)) + (hC₁ : ∀ k < n, ∀ t z, |deriv (F k t) z| ≤ 1) + (hC₂ : ∀ k < n, ∀ t z, |deriv (deriv (F k t)) z| ≤ C₂ k) + (hC₃ : ∀ k < n, ∀ t z, |iteratedDeriv 3 (F k t) z| ≤ C₃ k) + (hDm : ∀ k < n, Measurable (D k ((k:ℝ≥0)*h))) + (hCt : ∀ k < n, ∀ z, |D k ((k:ℝ≥0)*h) z| ≤ Ct k) + (hD : ∀ k < n, ∀ r ∈ Set.Icc ((k:ℝ)*(h:ℝ)) (((k:ℝ)+1)*(h:ℝ)), ∀ z, + HasDerivWithinAt (fun t => F k t z) (D k r z) + (Set.Icc ((k:ℝ)*(h:ℝ)) (((k:ℝ)+1)*(h:ℝ))) r) + (hL : ∀ k < n, ∀ r ∈ Set.Icc ((k:ℝ)*(h:ℝ)) (((k:ℝ)+1)*(h:ℝ)), ∀ z y, + |D k r z-D k ((k:ℝ≥0)*h) y| ≤ (L k:ℝ)*(|r-(k:ℝ)*(h:ℝ)|+|z-y|)) + (hPDE : ∀ k < n, ∀ z, D k ((k:ℝ≥0)*h) z+ + (1/2:ℝ)*deriv (deriv (F k ((k:ℝ≥0)*h))) z+ + (c k:ℝ)/2*(deriv (F k ((k:ℝ≥0)*h)) z)^2 = 0) + (hseam : ∀ k < n, F k (((k+1:ℕ):ℝ)*(h:ℝ)) = F (k+1) (((k+1:ℕ):ℝ)*(h:ℝ))) + {ε : ℝ} (hε : ∀ k < n, verificationError (c k) (C₂ k) (C₃ k) (L k) h ≤ ε) : + (∫ ω, F n ((n:ℝ)*(h:ℝ)) (controlledGrid B α h c x n ω) ∂P)-F 0 0 x- + (∑ k ∈ Finset.range n, ∫ ω, stepCost (fun r => α (Real.toNNReal r)) + ((k:ℝ≥0)*h) h (c k) ω ∂P) ≤ (n:ℝ)*ε := by + let := hB.isGaussianProcess.isProbabilityMeasure + have ham := progressive_joint_measurable _ hap + have ham' : Measurable (fun p : ℝ × Ω => α (Real.toNNReal p.1) p.2) := + ham.comp (measurable_fst.real_toNNReal.prodMk measurable_snd) + let Q (k : ℕ) := ∫ ω, F k ((k:ℝ)*(h:ℝ)) (controlledGrid B α h c x k ω) ∂P + let K (k : ℕ) := ∫ ω, stepCost (fun r => α (Real.toNNReal r)) ((k:ℝ≥0)*h) h (c k) ω ∂P + have hstep : ∀ k < n, Q (k+1)-Q k-K k ≤ ε := by + intro k hk + have ht : (k:ℝ≥0)*h+h = ((k+1:ℕ):ℝ≥0)*h := by push_cast; ring + have ht' : (↑((k:ℝ≥0)*h):ℝ)+(h:ℝ) = (((k:ℝ)+1)*(h:ℝ)) := by push_cast; ring + have hu := expected_verification_step hB hm ((k:ℝ≥0)*h) h (c k) + (controlledGrid_adapted hm hap hab h c x k) (controlledGrid_integrable hB ham hab h c x k) + (α := fun r => α (Real.toNNReal r)) ham' (fun r ω => hab _ ω) (hf k hk) 1 (C₂ k) (C₃ k) (Ct k) (L k) + (hC₁ k hk) (hC₂ k hk) (hC₃ k hk) (hDm k hk) (hCt k hk) + (by simpa only [NNReal.coe_mul, NNReal.coe_natCast, add_mul, one_mul] using hD k hk) + (by simpa only [NNReal.coe_mul, NNReal.coe_natCast, add_mul, one_mul] using hL k hk) + (hPDE k hk) + have he : (fun ω => F k ((↑((k:ℝ≥0)*h):ℝ)+(h:ℝ)) + (controlledGrid B α h c x k ω+(B ((k:ℝ≥0)*h+h) ω-B ((k:ℝ≥0)*h) ω)+ + stepDrift (fun r => α (Real.toNNReal r)) ((k:ℝ≥0)*h) h (c k) ω)) = + fun ω => F (k+1) (((k+1:ℕ):ℝ)*(h:ℝ)) (controlledGrid B α h c x (k+1) ω) := by + funext ω + rw [ht, ht'] + simp only [← Nat.cast_add_one, hseam k hk, controlledGrid] + simp only [NNReal.coe_mul, NNReal.coe_natCast] at hu he + rw [he] at hu + exact (show Q (k+1)-Q k-K k ≤ verificationError (c k) (C₂ k) (C₃ k) (L k) h from hu).trans (hε k hk) + have hh := finite_mesh_verification Q K n ε hstep + have hz : Q 0 = F 0 0 x := by simp [Q, controlledGrid] + rw [hz] at hh + exact hh + +end ZeroTemperatureSK.WeakIto + +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKSupport/Control/ExpectedControlPayoff.lean b/lean/OAI/Probability/SKSupport/Control/ExpectedControlPayoff.lean new file mode 100644 index 0000000000000000000000000000000000000000..28637612c080d96f1f3364228e362026c7251fcb --- /dev/null +++ b/lean/OAI/Probability/SKSupport/Control/ExpectedControlPayoff.lean @@ -0,0 +1,123 @@ +import Mathlib +import OAI.Probability.SKSupport.Regularity.AbsExtend + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section +namespace ZeroTemperatureSK + +variable {Ω : Type*} [MeasurableSpace Ω] + +lemma expected_controlPayoff_le (W : BrownianSystem Ω) (γ : OrderParameter) + (t x : ℝ) (ht : t ≤ 1) (α : Control W (Real.toNNReal t)) : + (∫ ω, controlPayoff W γ t x α ω ∂W.law) ≤ + (∫ ω, |x + W.B 1 ω - W.B (Real.toNNReal t) ω| ∂W.law) + + (1 / 2 : ℝ) * ∫ s in t..1, extend γ.val s := by + let := W.isProbability + have hnoise : Integrable (fun ω => |x + W.B 1 ω - W.B (Real.toNNReal t) ω|) W.law := + (((integrable_const x).add (W.brownian.integrable_eval 1)).sub + (W.brownian.integrable_eval (Real.toNNReal t))).abs + calc + _ ≤ ∫ ω, (|x + W.B 1 ω - W.B (Real.toNNReal t) ω| + + (1 / 2 : ℝ) * ∫ s in t..1, extend γ.val s) ∂W.law := + integral_mono (controlPayoff_integrable W γ t x ht α) + (hnoise.add (integrable_const _)) (controlPayoff_le W γ t x ht α) + _ = _ := by rw [integral_add hnoise (integrable_const _)]; simp + +lemma control_values_bddAbove (W : BrownianSystem Ω) (γ : OrderParameter) + (t x : ℝ) (ht : t ≤ 1) : + BddAbove (Set.range (fun α : Control W (Real.toNNReal t) => + ∫ ω, controlPayoff W γ t x α ω ∂W.law)) := by + refine ⟨(∫ ω, |x + W.B 1 ω - W.B (Real.toNNReal t) ω| ∂W.law) + + (1 / 2 : ℝ) * ∫ s in t..1, extend γ.val s, ?_⟩ + rintro _ ⟨α, rfl⟩ + exact expected_controlPayoff_le W γ t x ht α + +lemma expected_controlPayoff_le_value (W : BrownianSystem Ω) (γ : OrderParameter) + (t x : ℝ) (ht : t ≤ 1) (α : Control W (Real.toNNReal t)) : + (∫ ω, controlPayoff W γ t x α ω ∂W.law) ≤ value W γ t x := by + exact le_csSup (control_values_bddAbove W γ t x ht) ⟨α, rfl⟩ + +lemma value_le_expected_abs (W : BrownianSystem Ω) (γ : OrderParameter) + (t x : ℝ) (ht : t ≤ 1) : + value W γ t x ≤ (∫ ω, |x + W.B 1 ω - W.B (Real.toNNReal t) ω| ∂W.law) + + (1 / 2 : ℝ) * ∫ s in t..1, extend γ.val s := by + unfold value + refine csSup_le ?_ ?_ + · exact ⟨_, ⟨zeroControl W (Real.toNNReal t), rfl⟩⟩ + rintro _ ⟨α, rfl⟩ + exact expected_controlPayoff_le W γ t x ht α + +lemma abs_le_value (W : BrownianSystem Ω) (γ : OrderParameter) + (t x : ℝ) (ht : t ≤ 1) : |x| ≤ value W γ t x := by + let := W.isProbability + have hmean : (∫ ω, (x + W.B 1 ω - W.B (Real.toNNReal t) ω) ∂W.law) = x := by + have ha : Integrable (fun ω => x + W.B 1 ω) W.law := + (integrable_const x).add (W.brownian.integrable_eval 1) + rw [integral_sub ha + (W.brownian.integrable_eval (Real.toNNReal t)), + integral_add (integrable_const x) (W.brownian.integrable_eval 1)] + simp [W.brownian.integral_eval] + calc + |x| = |∫ ω, (x + W.B 1 ω - W.B (Real.toNNReal t) ω) ∂W.law| := by rw [hmean] + _ ≤ ∫ ω, |x + W.B 1 ω - W.B (Real.toNNReal t) ω| ∂W.law := + abs_integral_le_integral_abs + _ = ∫ ω, controlPayoff W γ t x (zeroControl W (Real.toNNReal t)) ω ∂W.law := by + simp [controlPayoff, zeroControl] + _ ≤ value W γ t x := expected_controlPayoff_le_value W γ t x ht _ + +lemma controlPayoff_space_le (W : BrownianSystem Ω) (γ : OrderParameter) + (t x y : ℝ) (α : Control W (Real.toNNReal t)) (ω : Ω) : + controlPayoff W γ t x α ω ≤ controlPayoff W γ t y α ω + |x - y| := by + have h := abs_add_le + (y + W.B 1 ω - W.B (Real.toNNReal t) ω + + ∫ s in t..1, extend γ.val s * α.val (Real.toNNReal (s - t)) ω) (x-y) + have heq : y + W.B 1 ω - W.B (Real.toNNReal t) ω + + (∫ s in t..1, extend γ.val s * α.val (Real.toNNReal (s - t)) ω) + (x-y) = + x + W.B 1 ω - W.B (Real.toNNReal t) ω + + ∫ s in t..1, extend γ.val s * α.val (Real.toNNReal (s - t)) ω := by ring + rw [heq] at h + dsimp [controlPayoff] + linarith + +lemma value_space_le (W : BrownianSystem Ω) (γ : OrderParameter) + (t x y : ℝ) (ht : t ≤ 1) : value W γ t x ≤ value W γ t y + |x - y| := by + let := W.isProbability + unfold value + refine csSup_le ?_ ?_ + · exact ⟨_, ⟨zeroControl W (Real.toNNReal t), rfl⟩⟩ + rintro _ ⟨α, rfl⟩ + calc + (∫ ω, controlPayoff W γ t x α ω ∂W.law) ≤ + ∫ ω, (controlPayoff W γ t y α ω + |x-y|) ∂W.law := + integral_mono (controlPayoff_integrable W γ t x ht α) + ((controlPayoff_integrable W γ t y ht α).add (integrable_const _)) + (controlPayoff_space_le W γ t x y α) + _ = (∫ ω, controlPayoff W γ t y α ω ∂W.law) + |x-y| := by + rw [integral_add (controlPayoff_integrable W γ t y ht α) (integrable_const _)] + simp + _ ≤ value W γ t y + |x-y| := + add_le_add (expected_controlPayoff_le_value W γ t y ht α) le_rfl + +theorem value_lipschitz (W : BrownianSystem Ω) (γ : OrderParameter) + (t : ℝ) (ht : t ≤ 1) : LipschitzWith 1 (value W γ t) := by + apply LipschitzWith.of_dist_le_mul + intro x y + simp only [Real.dist_eq, NNReal.coe_one, one_mul] + rw [abs_le] + constructor + · have h := value_space_le W γ t y x ht + rw [abs_sub_comm y x] at h + linarith + · have h := value_space_le W γ t x y ht + linarith + +end ZeroTemperatureSK + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKSupport/Control/FiniteContinuity.lean b/lean/OAI/Probability/SKSupport/Control/FiniteContinuity.lean new file mode 100644 index 0000000000000000000000000000000000000000..4e7b09d7681f9161026a0c8ae6a96f7b00255767 --- /dev/null +++ b/lean/OAI/Probability/SKSupport/Control/FiniteContinuity.lean @@ -0,0 +1,227 @@ +import Mathlib +import OAI.Probability.SKSupport.Regularity.BoundedSmoothFamily + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology ContDiff +noncomputable section +namespace ZeroTemperatureSK.Heat + +lemma finiteValue_time_bound {f : ℝ → ℝ} (hf : RegularDatum f) (hLip : LipschitzWith 1 f) + (c : ℕ → ℝ≥0) (h : ℝ≥0) (N i : ℕ) : + ∃ L : ℝ≥0, ∀ r ∈ Icc (0:ℝ) ((N:ℝ)*h), ∀ s ∈ Icc (0:ℝ) ((N:ℝ)*h), ∀ x, + |finiteValue c h f N i r x-finiteValue c h f N i s x| ≤ (L:ℝ)*|r-s| := by + induction N generalizing i with + | zero => exact ⟨0,by simp [finiteValue]⟩ + | succ N ih => + obtain ⟨K,hK⟩ := ih (i+1) + obtain ⟨L,hL⟩ := backward_joint_bound (cascade_regular hf hLip c h N (i+1)) + (cascade_lipschitz hLip c h N (i+1)) (c i).coe_nonneg (h:ℝ) + have hhead (r s : ℝ) (hr : r ∈ Icc 0 (h:ℝ)) (hs : s ∈ Icc 0 (h:ℝ)) (x : ℝ) : + |finiteValue c h f (N+1) i r x-finiteValue c h f (N+1) i s x| ≤ (L:ℝ)*|r-s| := by + rw [finiteValue_head f c h N i hr.2,finiteValue_head f c h N i hs.2] + simpa only [sub_self,abs_zero,add_zero] using hL r hr s hs x x + have htail (r s : ℝ) (hr : r ∈ Icc (h:ℝ) (((N+1:ℕ):ℝ)*h)) + (hs : s ∈ Icc (h:ℝ) (((N+1:ℕ):ℝ)*h)) (x : ℝ) : + |finiteValue c h f (N+1) i r x-finiteValue c h f (N+1) i s x| ≤ (K:ℝ)*|r-s| := by + rw [finiteValue_tail_of_le hf hLip c h N i hr.1,finiteValue_tail_of_le hf hLip c h N i hs.1] + have hr' : r-h ∈ Icc (0:ℝ) ((N:ℝ)*h) := by + constructor + · exact sub_nonneg.mpr hr.1 + · have hh := hr.2; push_cast at hh; nlinarith + have hs' : s-h ∈ Icc (0:ℝ) ((N:ℝ)*h) := by + constructor + · exact sub_nonneg.mpr hs.1 + · have hh := hs.2; push_cast at hh; nlinarith + simpa only [sub_sub_sub_cancel_right] using hK (r-h) hr' (s-h) hs' x + refine ⟨L+K,?_⟩ + have hsum (A : ℝ) (hA : 0 ≤ A) : (L:ℝ)*A ≤ ((L+K:ℝ≥0):ℝ)*A ∧ + (K:ℝ)*A ≤ ((L+K:ℝ≥0):ℝ)*A := by + simp only [NNReal.coe_add] + constructor <;> nlinarith [L.coe_nonneg,K.coe_nonneg] + have hhN : (h:ℝ) ≤ ((N+1:ℕ):ℝ)*h := by + push_cast + nlinarith [mul_nonneg (Nat.cast_nonneg (α := ℝ) N) h.coe_nonneg] + have hord (r s : ℝ) (hr : r ∈ Icc (0:ℝ) (((N+1:ℕ):ℝ)*h)) + (hs : s ∈ Icc (0:ℝ) (((N+1:ℕ):ℝ)*h)) (hrs : r ≤ s) (x : ℝ) : + |finiteValue c h f (N+1) i r x-finiteValue c h f (N+1) i s x| ≤ ((L+K:ℝ≥0):ℝ)*|r-s| := by + by_cases hsh : s ≤ h + · exact (hhead r s ⟨hr.1,hrs.trans hsh⟩ ⟨hs.1,hsh⟩ x).trans (hsum _ (abs_nonneg _)).1 + by_cases hhr : (h:ℝ) ≤ r + · exact (htail r s ⟨hhr,hr.2⟩ ⟨hhr.trans hrs,hs.2⟩ x).trans (hsum _ (abs_nonneg _)).2 + have hrh : r ≤ h := (lt_of_not_ge hhr).le + have hhs : (h:ℝ) ≤ s := (lt_of_not_ge hsh).le + have ha := hhead r h ⟨hr.1,hrh⟩ ⟨h.coe_nonneg,le_rfl⟩ x + have hb := htail h s ⟨le_rfl,hhN⟩ ⟨hhs,hs.2⟩ x + have ht := abs_sub_le (finiteValue c h f (N+1) i r x) + (finiteValue c h f (N+1) i h x) (finiteValue c h f (N+1) i s x) + rw [abs_of_nonpos (sub_nonpos.mpr hrh)] at ha + rw [abs_of_nonpos (sub_nonpos.mpr hhs)] at hb + rw [abs_of_nonpos (sub_nonpos.mpr hrs),NNReal.coe_add] + nlinarith [mul_nonneg L.coe_nonneg (sub_nonneg.mpr hhs), + mul_nonneg K.coe_nonneg (sub_nonneg.mpr hrh)] + intro r hr s hs x + rcases le_total r s with hrs|hsr + · exact hord r s hr hs hrs x + · simpa only [abs_sub_comm] using hord s r hs hr hsr x + +lemma finiteValue_joint_bound {f : ℝ → ℝ} (hf : RegularDatum f) (hLip : LipschitzWith 1 f) + (c : ℕ → ℝ≥0) (h : ℝ≥0) (N i : ℕ) : + ∃ L : ℝ≥0, ∀ r ∈ Icc (0:ℝ) ((N:ℝ)*h), ∀ s ∈ Icc (0:ℝ) ((N:ℝ)*h), ∀ x y, + |finiteValue c h f N i r x-finiteValue c h f N i s y| ≤ (L:ℝ)*(|r-s|+|x-y|) := by + obtain ⟨L,hL⟩ := finiteValue_time_bound hf hLip c h N i + refine ⟨L+1,fun r hr s hs x y => ?_⟩ + have ht := hL r hr s hs x + have hl := (finiteValue_lipschitz hLip c h N i s).dist_le_mul x y + simp only [Real.dist_eq,NNReal.coe_one,one_mul] at hl + have htri := abs_sub_le (finiteValue c h f N i r x) (finiteValue c h f N i s x) + (finiteValue c h f N i s y) + simp only [NNReal.coe_add,NNReal.coe_one] + nlinarith [mul_nonneg L.coe_nonneg (abs_nonneg (x-y)),abs_nonneg (r-s)] + +lemma finiteValue_continuousOn {f : ℝ → ℝ} (hf : RegularDatum f) (hLip : LipschitzWith 1 f) + (c : ℕ → ℝ≥0) (h : ℝ≥0) (N i : ℕ) : + ContinuousOn (fun p : ℝ × ℝ => finiteValue c h f N i p.1 p.2) + (Icc (0:ℝ) ((N:ℝ)*h) ×ˢ Set.univ) := by + obtain ⟨L,hL⟩ := finiteValue_joint_bound hf hLip c h N i + exact continuousOn_of_joint_bound hL + +end ZeroTemperatureSK.Heat + +end +end +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology ContDiff +noncomputable section +namespace ZeroTemperatureSK.Heat + +def finiteRate (c : ℕ → ℝ≥0) (h : ℝ≥0) (f : ℝ → ℝ) (N i : ℕ) (t x : ℝ) : ℝ := + -(1/2:ℝ)*deriv (deriv (finiteValue c h f N i t)) x-(1/2:ℝ)*finiteSource c h f N i t x + +lemma measurable_finiteRate {f : ℝ → ℝ} (hf : RegularDatum f) (hLip : LipschitzWith 1 f) + (c : ℕ → ℝ≥0) (h : ℝ≥0) (N i : ℕ) : + Measurable (fun p : ℝ × ℝ => finiteRate c h f N i p.1 p.2) := by + exact (measurable_const.mul (finiteGradient_family hf hLip c h N i).deriv.measurable).sub + (measurable_const.mul (measurable_finiteSource hf hLip c h N i)) + +lemma finiteRate_bounded {f : ℝ → ℝ} (hf : RegularDatum f) (hLip : LipschitzWith 1 f) + (c : ℕ → ℝ≥0) (h : ℝ≥0) (N i : ℕ) : + ∃ C : ℝ≥0, ∀ t x, |finiteRate c h f N i t x| ≤ C := by + obtain ⟨A,hA⟩ := (finiteGradient_family hf hLip c h N i).deriv.bound + obtain ⟨B,hB⟩ := finiteSource_bounded hLip c h N i + refine ⟨A+B,fun t x => ?_⟩ + have ha := hA t x + have hb := hB t x + unfold finiteRate + refine (abs_sub _ _).trans ?_ + simp only [abs_mul,abs_neg,abs_of_nonneg (show (0:ℝ) ≤ 1/2 by norm_num),NNReal.coe_add] + nlinarith [abs_nonneg (deriv (deriv (finiteValue c h f N i t)) x), + abs_nonneg (finiteSource c h f N i t x)] + +lemma intervalIntegrable_finiteRate {f : ℝ → ℝ} (hf : RegularDatum f) (hLip : LipschitzWith 1 f) + (c : ℕ → ℝ≥0) (h : ℝ≥0) (N i : ℕ) (a b x : ℝ) : + IntervalIntegrable (fun t => finiteRate c h f N i t x) volume a b := by + obtain ⟨C,hC⟩ := finiteRate_bounded hf hLip c h N i + apply (intervalIntegrable_const (c := (C:ℝ))).mono_fun + ((measurable_finiteRate hf hLip c h N i).comp (measurable_id.prodMk measurable_const)).aestronglyMeasurable + filter_upwards [] with t + simpa only [Function.comp_def,id_eq,Real.norm_eq_abs,abs_of_nonneg C.coe_nonneg] using hC t x + +lemma finiteRate_head {f : ℝ → ℝ} (hf : RegularDatum f) (hLip : LipschitzWith 1 f) + (c : ℕ → ℝ≥0) (h : ℝ≥0) (N i : ℕ) {t : ℝ} (ht : t ∈ Icc (0:ℝ) h) : + finiteRate c h f (N+1) i t = backwardRate (c i) h (cascade c h f N (i+1)) t := by + funext x + obtain ⟨C₂,C₃,Ct,L,h₂,h₃,hm,hCt,hd,hJ,hE⟩ := + (backward_verificationData (cascade_regular hf hLip c h N (i+1)) + (cascade_lipschitz hLip c h N (i+1)) (c i).coe_nonneg (h:ℝ)).bounds + have he := hE t ht x + rw [finiteRate,finiteSource_head f c h N i ht.2,finiteValue_head f c h N i ht.2] + linarith + +lemma finiteRate_tail (f : ℝ → ℝ) (c : ℕ → ℝ≥0) (h : ℝ≥0) (N i : ℕ) {t : ℝ} + (ht : (h:ℝ) < t) : finiteRate c h f (N+1) i t = finiteRate c h f N (i+1) (t-h) := by + funext x + rw [finiteRate,finiteValue_tail f c h N i ht,finiteSource_tail f c h N i ht] + rfl + +lemma integral_finiteRate_tail (f : ℝ → ℝ) (c : ℕ → ℝ≥0) (h : ℝ≥0) (N i : ℕ) + {a b : ℝ} (ha : (h:ℝ) ≤ a) (hab : a ≤ b) (x : ℝ) : + (∫ t in a..b, finiteRate c h f (N+1) i t x) = + ∫ t in a-h..b-h, finiteRate c h f N (i+1) t x := by + rw [← intervalIntegral.integral_comp_sub_right (f := fun t => finiteRate c h f N (i+1) t x) (h:ℝ)] + apply intervalIntegral.integral_congr_Ioo_of_le hab + intro t ht + dsimp only + rw [finiteRate_tail f c h N i (ha.trans_lt ht.1)] + +lemma backward_integral_rate {f : ℝ → ℝ} (hf : RegularDatum f) (hLip : LipschitzWith 1 f) + {c : ℝ} (hc : 0 ≤ c) {a b T : ℝ} (ha : 0 ≤ a) (hab : a ≤ b) (hb : b ≤ T) (x : ℝ) : + (∫ t in a..b, backwardRate c T f t x) = backward c T f b x-backward c T f a x := by + obtain ⟨C₂,C₃,Ct,L,h₂,h₃,hm,hCt,hd,hJ,hE⟩ := (backward_verificationData hf hLip hc T).bounds + have hcont : ContinuousOn (fun t => backward c T f t x) (Icc a b) := by + intro t ht + exact (hd t ⟨ha.trans ht.1,ht.2.trans hb⟩ x).continuousWithinAt.mono + (Icc_subset_Icc ha hb) + have hrate : ContinuousOn (fun t => backwardRate c T f t x) (Icc a b) := by + apply ((continuousOn_of_joint_bound hJ).comp + (continuous_id.prodMk continuous_const).continuousOn (fun t ht => ⟨ht,mem_univ _⟩)).mono + (Icc_subset_Icc ha hb) + apply intervalIntegral.integral_eq_sub_of_hasDerivAt_of_le hab hcont _ + (hrate.intervalIntegrable_of_Icc hab) + intro t ht + exact (hd t ⟨ha.trans ht.1.le,ht.2.le.trans hb⟩ x).hasDerivAt + (Icc_mem_nhds (ha.trans_lt ht.1) (ht.2.trans_le hb)) + +theorem finiteValue_integral_rate {f : ℝ → ℝ} (hf : RegularDatum f) (hLip : LipschitzWith 1 f) + (c : ℕ → ℝ≥0) (h : ℝ≥0) (N i : ℕ) {a b : ℝ} + (ha : 0 ≤ a) (hab : a ≤ b) (hb : b ≤ (N:ℝ)*h) (x : ℝ) : + (∫ t in a..b, finiteRate c h f N i t x) = finiteValue c h f N i b x-finiteValue c h f N i a x := by + induction N generalizing i a b with + | zero => + have hb0 : b = 0 := by simp only [Nat.cast_zero,zero_mul] at hb; linarith + have ha0 : a = 0 := by linarith + simp only [ha0,hb0,intervalIntegral.integral_same,sub_self] + | succ N ih => + have hhead {a b : ℝ} (ha : 0 ≤ a) (hab : a ≤ b) (hb : b ≤ h) : + (∫ t in a..b, finiteRate c h f (N+1) i t x) = + finiteValue c h f (N+1) i b x-finiteValue c h f (N+1) i a x := by + rw [finiteValue_head f c h N i hb,finiteValue_head f c h N i (hab.trans hb)] + have hi : (∫ t in a..b, finiteRate c h f (N+1) i t x) = + (∫ t in a..b, backwardRate (c i) h (cascade c h f N (i+1)) t x) := by + apply intervalIntegral.integral_congr_Ioo_of_le hab + intro t ht + dsimp only + rw [finiteRate_head hf hLip c h N i ⟨ha.trans ht.1.le,ht.2.le.trans hb⟩] + rw [hi] + exact backward_integral_rate (cascade_regular hf hLip c h N (i+1)) + (cascade_lipschitz hLip c h N (i+1)) (c i).coe_nonneg ha hab hb x + have htail {a b : ℝ} (ha : (h:ℝ) ≤ a) (hab : a ≤ b) (hb : b ≤ (((N+1:ℕ):ℝ)*h)) : + (∫ t in a..b, finiteRate c h f (N+1) i t x) = + finiteValue c h f (N+1) i b x-finiteValue c h f (N+1) i a x := by + rw [integral_finiteRate_tail f c h N i ha hab x, + finiteValue_tail_of_le hf hLip c h N i (ha.trans hab), + finiteValue_tail_of_le hf hLip c h N i ha] + apply ih (i+1) (sub_nonneg.mpr ha) (by linarith) + push_cast at hb + nlinarith + by_cases hbh : b ≤ h + · exact hhead ha hab hbh + by_cases hah : (h:ℝ) ≤ a + · exact htail hah hab hb + have hah' : a ≤ h := (lt_of_not_ge hah).le + have hhb : (h:ℝ) ≤ b := (lt_of_not_ge hbh).le + rw [← intervalIntegral.integral_add_adjacent_intervals + (intervalIntegrable_finiteRate hf hLip c h (N+1) i a h x) + (intervalIntegrable_finiteRate hf hLip c h (N+1) i h b x), + hhead ha hah' le_rfl,htail le_rfl hhb hb] + ring + +end ZeroTemperatureSK.Heat + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKSupport/Control/GridApprox.lean b/lean/OAI/Probability/SKSupport/Control/GridApprox.lean new file mode 100644 index 0000000000000000000000000000000000000000..c4d60b5187785be331763c71c5c50d8882f8cdcd --- /dev/null +++ b/lean/OAI/Probability/SKSupport/Control/GridApprox.lean @@ -0,0 +1,204 @@ +import Mathlib +import OAI.Probability.SKSupport.Control.ExpectedControlPayoff +import OAI.Probability.SKSupport.Control.GridBridge + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology ContDiff +noncomputable section +namespace ZeroTemperatureSK +open WeakIto Heat Nonuniform + +lemma finiteCoeff_cell (c : ℕ → ℝ≥0) (h : ℝ≥0) (N i k : ℕ) (hk : k < N) + {r : ℝ} (hr0 : 0 < r) (hrh : r ≤ h) : + finiteCoeff c h N i ((k:ℝ)*h+r) = c (i+k) := by + induction N generalizing i k with + | zero => omega + | succ N ih => + cases k with + | zero => simp only [Nat.cast_zero,zero_mul,zero_add,finiteCoeff,ite_eq_left hrh,Nat.add_zero] + | succ k => + have hgt : (h:ℝ) < ((k+1:ℕ):ℝ)*h+r := by + push_cast + nlinarith [mul_nonneg (Nat.cast_nonneg (α := ℝ) k) h.coe_nonneg] + simp only [finiteCoeff,ite_eq_right (not_le.mpr hgt)] + have he : ((k+1:ℕ):ℝ)*h+r-h = (k:ℝ)*h+r := by push_cast; ring + rw [he,ih (i+1) k (by omega), show i+1+k = i+(k+1) by omega] + +lemma finiteCoeff_intervalIntegrable (c : ℕ → ℝ≥0) (h : ℝ≥0) (N i : ℕ) (a b : ℝ) : + IntervalIntegrable (finiteCoeff c h N i) volume a b := by + obtain ⟨C,hC⟩ := finiteCoeff_bounds c h N i + apply (intervalIntegrable_const (c := (C:ℝ))).mono_fun' + (measurable_finiteCoeff c h N i).aestronglyMeasurable + filter_upwards [] with r + rw [Real.norm_eq_abs,abs_of_nonneg (hC r).1] + exact (hC r).2 + +lemma finiteCoeff_remaining_cell (c : ℕ → ℝ≥0) (h : ℝ≥0) (N k : ℕ) (hk : k < N) + {t r : ℝ} (ht : 0 ≤ t) + (hr : r ∈ Ioo (time (remainingLengths h t) k:ℝ) + (time (remainingLengths h t) (k+1):ℝ)) : + finiteCoeff c h N 0 (t+r) = c k := by + rw [remainingLengths_time h ht,remainingLengths_time h ht] at hr + simp only [Real.coe_toNNReal',Set.mem_Ioo] at hr + obtain ⟨hrlo,hrhi⟩ := hr + have hkr : (k:ℝ)*h < t+r := by linarith [hrlo,le_max_left ((k:ℝ)*h-t) 0] + have hrpos : 0 < r := (le_max_right ((k:ℝ)*h-t) 0).trans_lt hrlo + have htkr : 0 < ((k+1:ℕ):ℝ)*h-t := by + by_contra hn + rw [max_eq_right (le_of_not_gt hn)] at hrhi + linarith + have hrr : t+r ≤ ((k+1:ℕ):ℝ)*h := by + rw [max_eq_left htkr.le] at hrhi + linarith + have hloc : t+r-(k:ℝ)*h ≤ h := by push_cast at hrr; nlinarith + have he := finiteCoeff_cell c h N 0 k hk (sub_pos.mpr hkr) hloc + simp only [Nat.zero_add] at he + simpa only [add_sub_cancel] using he + +lemma finiteCoeff_nonneg (c : ℕ → ℝ≥0) (h : ℝ≥0) (N i : ℕ) (t : ℝ) : + 0 ≤ finiteCoeff c h N i t := by + obtain ⟨C,hC⟩ := finiteCoeff_bounds c h N i + exact (hC t).1 + +lemma finiteCoeff_sample (c : ℕ → ℝ≥0) {h : ℝ≥0} (_hh : 0 < h) (N i : ℕ) + {t : ℝ} (ht0 : 0 ≤ t) (htN : t ≤ (N:ℝ)*h) (hN : 0 < N) : + ∃ j < N, finiteCoeff c h N i t = c (i+j) ∧ + (j:ℝ)*h ≤ t ∧ t ≤ (j+1:ℕ)*h := by + induction N generalizing i t with + | zero => omega + | succ N ih => + by_cases hth : t ≤ h + · refine ⟨0,by omega,?_,?_,?_⟩ + · simp only [finiteCoeff,ite_eq_left hth,Nat.add_zero] + · simpa using ht0 + · simpa using hth + · have hNp : 0 < N := by + by_contra hn + have : N = 0 := by omega + subst N + norm_num at htN + exact hth htN + have htt : t-h ≤ (N:ℝ)*h := by push_cast at htN; nlinarith + obtain ⟨j,hj,he,hl,hu⟩ := ih (i+1) (by linarith) htt hNp + refine ⟨j+1,by omega,?_,?_,?_⟩ + · simp only [finiteCoeff,ite_eq_right hth,he] + rw [show i+1+j = i+(j+1) by omega] + · push_cast + linarith + · push_cast at hu ⊢ + nlinarith + +end ZeroTemperatureSK + +end +end +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology ContDiff +noncomputable section +namespace ZeroTemperatureSK +open WeakIto Heat Nonuniform + +lemma gridError_remaining (c : ℕ → ℝ≥0) (h : ℝ≥0) (N : ℕ) (hN : (N:ℝ)*h = 1) + (γ : OrderParameter) {t : ℝ} (ht0 : 0 ≤ t) (ht1 : t ≤ 1) : + gridError (remainingLengths h t) c (fun r => extend γ.val (t+r)) N = + ∫ s in t..1, |finiteCoeff c h N 0 s-extend γ.val s| := by + let d := remainingLengths h t + let g := fun r => |finiteCoeff c h N 0 (t+r)-extend γ.val (t+r)| + have hH : (time d N:ℝ) = 1-t := by + rw [remainingLengths_time h ht0,hN,Real.coe_toNNReal _ (by linarith)] + have hg (a b : ℝ) : IntervalIntegrable g volume a b := by + have hh := ((finiteCoeff_intervalIntegrable c h N 0 (t+a) (t+b)).sub + γ.integrable.intervalIntegrable).abs.comp_add_left t + simpa only [add_sub_cancel_left] using hh + have he : gridError d c (fun r => extend γ.val (t+r)) N = + ∑ k ∈ Finset.range N, ∫ r in (time d k:ℝ)..(time d (k+1):ℝ), g r := by + apply Finset.sum_congr rfl + intro k hk + apply intervalIntegral.integral_congr_Ioo_of_le + (by exact_mod_cast time_mono d (Nat.le_succ k)) + intro r hr + dsimp only [g] + rw [finiteCoeff_remaining_cell c h N k (Finset.mem_range.mp hk) ht0 hr] + rw [he,intervalIntegral.sum_integral_adjacent_intervals (fun k _ => hg _ _),time_zero,NNReal.coe_zero,hH] + have hs := intervalIntegral.integral_comp_add_left + (fun s => |finiteCoeff c h N 0 s-extend γ.val s|) t (a := 0) (b := 1-t) + simpa only [add_zero,add_sub_cancel] using hs + +lemma gridError_remaining_le (c : ℕ → ℝ≥0) (h : ℝ≥0) (N : ℕ) (hN : (N:ℝ)*h = 1) + (γ : OrderParameter) {t : ℝ} (ht0 : 0 ≤ t) (ht1 : t ≤ 1) : + gridError (remainingLengths h t) c (fun r => extend γ.val (t+r)) N ≤ + ∫ s in (0:ℝ)..1, |finiteCoeff c h N 0 s-extend γ.val s| := by + rw [gridError_remaining c h N hN γ ht0 ht1] + exact intervalIntegral.integral_mono_interval ht0 ht1 le_rfl + (Eventually.of_forall (fun s => abs_nonneg _)) + (((finiteCoeff_intervalIntegrable c h N 0 0 1).sub γ.integrable.intervalIntegrable).abs) + +variable {Ω : Type*} [MeasurableSpace Ω] + +lemma cascadeV_value_error (W : BrownianSystem Ω) (γ : OrderParameter) (t x : ℝ) + (ht0 : 0 ≤ t) (ht1 : t ≤ 1) (h c : ℕ → ℝ≥0) (N : ℕ) + (hH : (time h N:ℝ) = 1-t) {f : ℝ → ℝ} (hf : RegularDatum f) + (hLip : LipschitzWith 1 f) {ε : ℝ} (he : ∀ z, |f z-abs z| ≤ ε) : + |cascadeV h c f N 0 x-value W γ t x| ≤ + ε+(3/2:ℝ)*gridError h c (fun r => extend γ.val (t+r)) N := by + let B := fun s ξ => W.B (Real.toNNReal t+s) ξ-W.B (Real.toNNReal t) ξ + have hB : IsPreBrownianReal B W.law := W.brownian.toIsPreBrownianReal.shift _ + have hm (s : ℝ≥0) : Measurable (B s) := (W.measurable _).sub (W.measurable _) + let E := ε+(3/2:ℝ)*gridError h c (fun r => extend γ.val (t+r)) N + have hobj : ∀ v ∈ objectives (P := W.law) hm h c f x N, v ≤ value W γ t x+E := by + intro v hv + obtain ⟨a,hap,hab,rfl⟩ := hv + let α : Control W (Real.toNNReal t) := ⟨a,hap,hab⟩ + have hh := control_profit_error W γ t x ht0 ht1 α h c N hH hLip he + have hp := expected_controlPayoff_le_value W γ t x ht1 α + have := (abs_le.mp hh).2 + change profit (P := W.law) B a h c f x N - + (∫ ξ, controlPayoff W γ t x α ξ ∂W.law) ≤ E at this + linarith + have hb : BddAbove (objectives (P := W.law) hm h c f x N) := ⟨_,hobj⟩ + have hc := cascadeV_eq_control_sup hB hm hf hLip h c N x + have hu : cascadeV h c f N 0 x ≤ value W γ t x+E := by + rw [hc] + exact csSup_le (objectives_nonempty hm h c f x N) hobj + change |cascadeV h c f N 0 x-value W γ t x| ≤ E + apply abs_sub_le_iff.mpr + refine ⟨by linarith,?_⟩ + have hl : value W γ t x ≤ cascadeV h c f N 0 x+E := by + unfold value + refine csSup_le ⟨_,⟨zeroControl W (Real.toNNReal t),rfl⟩⟩ ?_ + rintro y ⟨α,rfl⟩ + have hh := control_profit_error W γ t x ht0 ht1 α h c N hH hLip he + have hmem : profit (P := W.law) B α.val h c f x N ∈ objectives (P := W.law) hm h c f x N := + ⟨α.val,α.progressive,α.bound,rfl⟩ + have hp := le_csSup hb hmem + rw [← hc] at hp + have hh' := (abs_le.mp hh).1 + change -E ≤ profit (P := W.law) B α.val h c f x N - + (∫ ξ, controlPayoff W γ t x α ξ ∂W.law) at hh' + linarith + linarith + +theorem finiteValue_control_error (W : BrownianSystem Ω) (γ : OrderParameter) + (c : ℕ → ℝ≥0) (h : ℝ≥0) (N : ℕ) (hN : (N:ℝ)*h = 1) + {f : ℝ → ℝ} (hf : RegularDatum f) (hLip : LipschitzWith 1 f) + {ε : ℝ} (he : ∀ z, |f z-abs z| ≤ ε) {t : ℝ} (ht0 : 0 ≤ t) (ht1 : t ≤ 1) (x : ℝ) : + |finiteValue c h f N 0 t x-value W γ t x| ≤ + ε+(3/2:ℝ)*∫ s in (0:ℝ)..1, |finiteCoeff c h N 0 s-extend γ.val s| := by + rw [finiteValue_eq_remaining hf hLip c h N 0 ht0] + simp only [Nat.zero_add] + have hH : (time (remainingLengths h t) N:ℝ) = 1-t := by + rw [remainingLengths_time h ht0,hN,Real.coe_toNNReal _ (by linarith)] + exact (cascadeV_value_error W γ t x ht0 ht1 (remainingLengths h t) c N hH hf hLip he).trans + (add_le_add le_rfl (mul_le_mul_of_nonneg_left (gridError_remaining_le c h N hN γ ht0 ht1) + (by norm_num : (0:ℝ) ≤ 3/2))) + +end ZeroTemperatureSK + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKSupport/Control/GridBridge.lean b/lean/OAI/Probability/SKSupport/Control/GridBridge.lean new file mode 100644 index 0000000000000000000000000000000000000000..321d54b7b8baf84d1ace1e861042af38b2505e1d --- /dev/null +++ b/lean/OAI/Probability/SKSupport/Control/GridBridge.lean @@ -0,0 +1,279 @@ +import Mathlib +import OAI.Probability.SKSupport.Regularity.AbsExtend +import OAI.Probability.SKSupport.Foundations.FiniteValue +import OAI.Probability.SKSupport.Control.VariableGrid + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology ContDiff +noncomputable section +namespace ZeroTemperatureSK +open WeakIto Heat Nonuniform + +def remainingLengths (h : ℝ≥0) (t : ℝ) (j : ℕ) : ℝ≥0 := + Real.toNNReal (min (h:ℝ) (((j+1:ℕ):ℝ)*h-t)) + +lemma remainingLengths_shift (h : ℝ≥0) (t : ℝ) (j : ℕ) : + remainingLengths h t (j+1) = remainingLengths h (t-h) j := by + unfold remainingLengths + congr 2 + push_cast + ring + +lemma remainingLengths_nonpos (h : ℝ≥0) {t : ℝ} (ht : t ≤ 0) (j : ℕ) : + remainingLengths h t j = h := by + have hh : (h:ℝ) ≤ ((j+1:ℕ):ℝ)*h-t := by + push_cast + nlinarith [h.coe_nonneg, mul_nonneg (Nat.cast_nonneg (α := ℝ) j) h.coe_nonneg] + unfold remainingLengths + rw [min_eq_left hh] + exact Real.toNNReal_coe + +lemma remainingLengths_head (h : ℝ≥0) {t : ℝ} (ht : 0 ≤ t) : + remainingLengths h t 0 = Real.toNNReal ((h:ℝ)-t) := by + simp only [remainingLengths,Nat.zero_add,Nat.cast_one,one_mul] + rw [min_eq_right (by linarith)] + +lemma remainingLengths_time (h : ℝ≥0) {t : ℝ} (ht : 0 ≤ t) (n : ℕ) : + Nonuniform.time (remainingLengths h t) n = Real.toNNReal ((n:ℝ)*h-t) := by + induction n with + | zero => simp only [Nonuniform.time_zero,Nat.cast_zero,zero_mul,zero_sub] + rw [Real.toNNReal_of_nonpos (by linarith)] + | succ n ih => + rw [Nonuniform.time_succ,ih] + apply NNReal.coe_injective + simp only [NNReal.coe_add,remainingLengths,Real.coe_toNNReal'] + push_cast + have hn := h.coe_nonneg + by_cases hc : (n:ℝ)*h ≤ t + · rw [max_eq_right (by linarith)] + have hm : ((n:ℝ)+1)*h-t ≤ h := by nlinarith + rw [min_eq_right hm,zero_add] + · have hp : 0 ≤ (n:ℝ)*h-t := by linarith + rw [max_eq_left hp,min_eq_left (by nlinarith),max_eq_left hn, + max_eq_left (by nlinarith)] + ring + +lemma cascadeV_shift (h c : ℕ → ℝ≥0) (f : ℝ → ℝ) (n k j : ℕ) : + cascadeV (fun l => h (k+l)) (fun l => c (k+l)) f n j = cascadeV h c f n (k+j) := by + induction n generalizing j with + | zero => rfl + | succ n ih => + simp only [cascadeV,ih] + rw [Nat.add_assoc] + +lemma cascadeV_uniform (h : ℝ≥0) (c : ℕ → ℝ≥0) (f : ℝ → ℝ) (n k : ℕ) : + cascadeV (fun _ => h) c f n k = cascade c h f n k := by + induction n generalizing k with + | zero => rfl + | succ n ih => simp only [cascadeV,cascade,ih] + +lemma finiteValue_eq_remaining {f : ℝ → ℝ} (hf : RegularDatum f) (hLip : LipschitzWith 1 f) + (c : ℕ → ℝ≥0) (h : ℝ≥0) (n i : ℕ) {t : ℝ} (ht : 0 ≤ t) : + finiteValue c h f n i t = cascadeV (remainingLengths h t) (fun j => c (i+j)) f n 0 := by + induction n generalizing i t with + | zero => rfl + | succ n ih => + have hs : cascadeV (remainingLengths h t) (fun j => c (i+j)) f n 1 = + cascadeV (remainingLengths h (t-h)) (fun j => c ((i+1)+j)) f n 0 := by + have he := cascadeV_shift (remainingLengths h t) (fun j => c (i+j)) f n 1 0 + simp only [Nat.add_zero] at he + rw [← he] + congr 2 + · funext j + rw [Nat.add_comm 1 j,remainingLengths_shift] + · funext j + congr 1 + omega + by_cases hth : t ≤ h + · rw [finiteValue_head f c h n i hth] + have hl : remainingLengths h (t-h) = fun _ => h := by + funext j + exact remainingLengths_nonpos h (sub_nonpos.mpr hth) j + funext x + simp only [cascadeV,Nat.add_zero] + rw [hs,hl,cascadeV_uniform] + have hc := cascadeV_shift (fun _ => h) c f n (i+1) 0 + simp only [Nat.add_zero,cascadeV_uniform] at hc + rw [hc] + rw [remainingLengths_head h ht] + exact varianceLogHeat_eq_logSemigroup_toNNReal + (cascade_regular hf hLip c h n (i+1)).smooth.continuous.measurable (c i) (h-t) x + · rw [finiteValue_tail f c h n i (lt_of_not_ge hth),ih (i+1) (by linarith)] + funext x + simp only [cascadeV,Nat.add_zero] + rw [hs,remainingLengths_head h ht,Real.toNNReal_of_nonpos (by linarith)] + simp only [logSemigroup,semigroup,gaussianReal_zero_var,integral_dirac,add_zero] + split_ifs with hc + · rfl + · rw [Real.log_exp,mul_div_cancel_left₀ _ (by exact_mod_cast hc)] + +end ZeroTemperatureSK + +end +end +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology ContDiff +noncomputable section +namespace ZeroTemperatureSK +open WeakIto Heat Nonuniform + +def gridError (h c : ℕ → ℝ≥0) (g : ℝ → ℝ) (N : ℕ) : ℝ := + ∑ k ∈ Finset.range N, ∫ r in (time h k:ℝ)..(time h (k+1):ℝ), |(c k:ℝ)-g r| + +lemma grid_integral_error (h c : ℕ → ℝ≥0) {g a : ℝ → ℝ} + (hg : Integrable g) (ha : Measurable a) (hab : ∀ r, |a r| ≤ 1) (N : ℕ) : + |(∑ k ∈ Finset.range N, ∫ r in (time h k:ℝ)..(time h (k+1):ℝ), (c k:ℝ)*a r) - + ∫ r in (0:ℝ)..(time h N:ℝ), g r*a r| ≤ gridError h c g N := by + have hga : Integrable (fun r => g r*a r) := hg.mul_bdd ha.aestronglyMeasurable + (Eventually.of_forall (by simpa only [Real.norm_eq_abs] using hab)) + have haI (k : ℕ) : IntervalIntegrable a volume (time h k:ℝ) (time h (k+1):ℝ) := by + rw [intervalIntegrable_iff_integrableOn_Ioc_of_le (by exact_mod_cast time_mono h (Nat.le_succ k))] + exact Integrable.of_bound ha.aestronglyMeasurable 1 + (Eventually.of_forall (by simpa only [Real.norm_eq_abs] using hab)) + have hs := intervalIntegral.sum_integral_adjacent_intervals + (a := fun k => (time h k:ℝ)) (n := N) (fun k _ => hga.intervalIntegrable) + simp only [time_zero,NNReal.coe_zero] at hs + rw [← hs,← Finset.sum_sub_distrib] + apply (Finset.abs_sum_le_sum_abs _ _).trans + apply Finset.sum_le_sum + intro k hk + rw [← intervalIntegral.integral_sub ((haI k).const_mul _) hga.intervalIntegrable] + have hc : IntervalIntegrable (fun r => |(c k:ℝ)-g r|) volume (time h k:ℝ) (time h (k+1):ℝ) := + (intervalIntegrable_const.sub hg.intervalIntegrable).abs + change ‖∫ r in (time h k:ℝ)..(time h (k+1):ℝ), (c k:ℝ)*a r-g r*a r‖ ≤ _ + apply intervalIntegral.norm_integral_le_of_norm_le + (by exact_mod_cast time_mono h (Nat.le_succ k)) _ hc + filter_upwards [] with r hr + rw [← sub_mul,Real.norm_eq_abs,abs_mul] + simpa only [mul_one] using mul_le_mul_of_nonneg_left (hab r) (abs_nonneg ((c k:ℝ)-g r)) + +variable {Ω : Type*} [MeasurableSpace Ω] + +lemma Control.elapsed_integral (W : BrownianSystem Ω) (γ : OrderParameter) + (t : ℝ) (α : Control W (Real.toNNReal t)) (ξ : Ω) (p : ℕ) : + (∫ r in (0:ℝ)..(1-t), extend γ.val (t+r)*(α.val (Real.toNNReal r) ξ)^p) = + ∫ s in t..1, extend γ.val s*(α.val (Real.toNNReal (s-t)) ξ)^p := by + have he := intervalIntegral.integral_comp_add_left + (fun s => extend γ.val s*(α.val (Real.toNNReal (s-t)) ξ)^p) t (a := 0) (b := 1-t) + simpa only [add_sub_cancel_left,add_zero,add_sub_cancel] using he + +lemma profit_eq_integral {B α : ℝ≥0 → Ω → ℝ} {P : Measure Ω} (hB : IsPreBrownianReal B P) + (ham : Measurable (fun p : ℝ≥0 × Ω => α p.1 p.2)) (hab : ∀ t ξ, |α t ξ| ≤ 1) + (h c : ℕ → ℝ≥0) {f : ℝ → ℝ} (hf : LipschitzWith 1 f) (x : ℝ) (N : ℕ) : + profit (P := P) B α h c f x N = ∫ ξ, f (controlled B α h c x N ξ)- + ∑ k ∈ Finset.range N, stepCost (fun r => α (Real.toNNReal r)) (time h k) (h k) (c k) ξ ∂P := by + let := hB.isGaussianProcess.isProbabilityMeasure + have hi := controlled_integrable hB ham hab h c x N + have hfI : Integrable (fun ξ => f (controlled B α h c x N ξ)) P := by + apply ((integrable_const |f 0|).add hi.norm).mono' + (hf.continuous.comp_aestronglyMeasurable hi.aestronglyMeasurable) + filter_upwards [] with ξ + have hh := hf.dist_le_mul (controlled B α h c x N ξ) 0 + simp only [Real.dist_eq,NNReal.coe_one,one_mul,sub_zero] at hh + change |f (controlled B α h c x N ξ)| ≤ |f 0|+|controlled B α h c x N ξ| + have htri := abs_sub_le (f (controlled B α h c x N ξ)) (f 0) 0 + simp only [sub_zero] at htri + linarith + have hiC (k : ℕ) : Integrable (stepCost (fun r => α (Real.toNNReal r)) (time h k) (h k) (c k)) P := + stepCost_integrable (ham.comp (measurable_fst.real_toNNReal.prodMk measurable_snd)) + (fun r ξ => hab _ ξ) _ _ _ (h k).coe_nonneg (c k).coe_nonneg + rw [integral_sub hfI (integrable_finsetSum (Finset.range N) (fun k _ => hiC k)),integral_finsetSum _ (fun k _ => hiC k)] + rfl + +lemma control_profit_error (W : BrownianSystem Ω) (γ : OrderParameter) (t x : ℝ) + (ht0 : 0 ≤ t) (ht1 : t ≤ 1) (α : Control W (Real.toNNReal t)) + (h c : ℕ → ℝ≥0) (N : ℕ) (hH : (time h N:ℝ) = 1-t) + {f : ℝ → ℝ} (hf : LipschitzWith 1 f) {ε : ℝ} (he : ∀ z, |f z - abs z| ≤ ε) : + |profit (P := W.law) (fun s ξ => W.B (Real.toNNReal t+s) ξ-W.B (Real.toNNReal t) ξ) + α.val h c f x N - ∫ ξ, controlPayoff W γ t x α ξ ∂W.law| ≤ + ε+(3/2:ℝ)*gridError h c (fun r => extend γ.val (t+r)) N := by + let := W.isProbability + let B := fun s ξ => W.B (Real.toNNReal t+s) ξ-W.B (Real.toNNReal t) ξ + have hB : IsPreBrownianReal B W.law := W.brownian.toIsPreBrownianReal.shift _ + have hpred : Real.toNNReal t+time h N = 1 := by + apply NNReal.coe_injective + simp only [NNReal.coe_add,Real.coe_toNNReal _ ht0,hH,NNReal.coe_one] + ring + have hg : Integrable (fun r => extend γ.val (t+r)) := γ.integrable.comp_add_left t + have ham : Measurable (fun p : ℝ × Ω => α.val (Real.toNNReal p.1) p.2) := + α.measurable.comp (measurable_fst.real_toNNReal.prodMk measurable_snd) + let E := gridError h c (fun r => extend γ.val (t+r)) N + have hpath (ξ : Ω) : + |(f (controlled B α.val h c x N ξ)-∑ k ∈ Finset.range N, + stepCost (fun r => α.val (Real.toNNReal r)) (time h k) (h k) (c k) ξ)- + controlPayoff W γ t x α ξ| ≤ ε+(3/2:ℝ)*E := by + have hamξ : Measurable (fun r => α.val (Real.toNNReal r) ξ) := ham.comp measurable_prodMk_right + have hd := grid_integral_error h c hg hamξ + (fun r => α.bound _ ξ) N + have hc := grid_integral_error h c hg (hamξ.pow_const 2) + (fun r => by simpa only [abs_pow,one_pow] using + pow_le_pow_left₀ (abs_nonneg (α.val (Real.toNNReal r) ξ)) (α.bound _ ξ) 2) N + rw [hH,Control.elapsed_integral W γ t α ξ 2] at hc + have hdp := Control.elapsed_integral W γ t α ξ 1 + simp only [pow_one] at hdp + rw [hH,hdp] at hd + have hstate : |controlled B α.val h c x N ξ- + (x+W.B 1 ξ-W.B (Real.toNNReal t) ξ+ + ∫ s in t..1, extend γ.val s*α.val (Real.toNNReal (s-t)) ξ)| ≤ E := by + rw [controlled_formula] + simp only [B,hpred,add_zero,sub_self,sub_zero,stepDrift,← coe_time_succ] + convert hd using 1 + simp only [sub_eq_add_neg,add_assoc] + congr 1 + ring + have hferr := (abs_sub_le (f (controlled B α.val h c x N ξ)) + |controlled B α.val h c x N ξ| + |x+W.B 1 ξ-W.B (Real.toNNReal t) ξ+ + ∫ s in t..1, extend γ.val s*α.val (Real.toNNReal (s-t)) ξ|).trans + (add_le_add (he _) ((abs_abs_sub_abs_le_abs_sub _ _).trans hstate)) + have hcost : |(∑ k ∈ Finset.range N, stepCost (fun r => α.val (Real.toNNReal r)) + (time h k) (h k) (c k) ξ)-(1/2:ℝ)*∫ s in t..1, + extend γ.val s*(α.val (Real.toNNReal (s-t)) ξ)^2| ≤ (1/2:ℝ)*E := by + simp only [stepCost,← coe_time_succ,← Finset.mul_sum,← mul_sub,abs_mul,abs_of_pos (by norm_num : (0:ℝ)<1/2)] + exact mul_le_mul_of_nonneg_left hc (by norm_num) + unfold controlPayoff + have hp := abs_sub_le (f (controlled B α.val h c x N ξ)-∑ k ∈ Finset.range N, + stepCost (fun r => α.val (Real.toNNReal r)) (time h k) (h k) (c k) ξ) + (|x+W.B 1 ξ-W.B (Real.toNNReal t) ξ+ + ∫ s in t..1, extend γ.val s*α.val (Real.toNNReal (s-t)) ξ|- + ∑ k ∈ Finset.range N, stepCost (fun r => α.val (Real.toNNReal r)) (time h k) (h k) (c k) ξ) + (|x+W.B 1 ξ-W.B (Real.toNNReal t) ξ+ + ∫ s in t..1, extend γ.val s*α.val (Real.toNNReal (s-t)) ξ|- + (1/2:ℝ)*∫ s in t..1, extend γ.val s*(α.val (Real.toNNReal (s-t)) ξ)^2) + simp only [sub_sub_sub_cancel_right,sub_sub_sub_cancel_left,abs_sub_comm] at hp + linarith + rw [profit_eq_integral hB α.measurable α.bound h c hf x N] + have hi := controlled_integrable hB α.measurable α.bound h c x N + have hfI : Integrable (fun ξ => f (controlled B α.val h c x N ξ)) W.law := by + apply ((integrable_const (|f 0|)).add hi.norm).mono' + (hf.continuous.comp_aestronglyMeasurable hi.aestronglyMeasurable) + filter_upwards [] with ξ + have hh := hf.dist_le_mul (controlled B α.val h c x N ξ) 0 + simp only [Real.dist_eq,NNReal.coe_one,one_mul,sub_zero] at hh + change |f (controlled B α.val h c x N ξ)| ≤ |f 0|+|controlled B α.val h c x N ξ| + have htri := abs_sub_le (f (controlled B α.val h c x N ξ)) (f 0) 0 + simp only [sub_zero] at htri + linarith + have hiC (k : ℕ) : Integrable (stepCost (fun r => α.val (Real.toNNReal r)) (time h k) (h k) (c k)) W.law := + stepCost_integrable ham (fun r ξ => α.bound _ ξ) _ _ _ (h k).coe_nonneg (c k).coe_nonneg + have hdiff := integral_sub (hfI.sub (integrable_finsetSum (Finset.range N) (fun k _ => hiC k))) + (controlPayoff_integrable W γ t x ht1 α) + simp only [Pi.sub_apply] at hdiff + rw [← hdiff] + have hn := norm_integral_le_of_norm_le_const (μ := W.law) + (f := fun ξ => (f (controlled B α.val h c x N ξ)-∑ k ∈ Finset.range N, + stepCost (fun r => α.val (Real.toNNReal r)) (time h k) (h k) (c k) ξ)- + controlPayoff W γ t x α ξ) + (Eventually.of_forall (fun ξ => by simpa only [Real.norm_eq_abs] using hpath ξ)) + simpa only [Real.norm_eq_abs,Measure.real,measure_univ,ENNReal.toReal_one,mul_one] using hn + +end ZeroTemperatureSK + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKSupport/Control/ValueDifference.lean b/lean/OAI/Probability/SKSupport/Control/ValueDifference.lean new file mode 100644 index 0000000000000000000000000000000000000000..49e249441446f86d0e772bcab18b718090b4ff5c --- /dev/null +++ b/lean/OAI/Probability/SKSupport/Control/ValueDifference.lean @@ -0,0 +1,106 @@ +import Mathlib +import OAI.Probability.SKSupport.Regularity.RightRegularity +import OAI.Probability.SKSupport.Regularity.TimeFields + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology ContDiff +noncomputable section +namespace ZeroTemperatureSK +open Heat WeakIto +variable {Ω : Type*} [MeasurableSpace Ω] + +def coefficientDistance (β γ : OrderParameter) : ℝ := + ∫ s in (0:ℝ)..1, |extend β.val s-extend γ.val s| + +lemma coefficientDistance_nonneg (β γ : OrderParameter) : 0 ≤ coefficientDistance β γ := + intervalIntegral.integral_nonneg (by norm_num) (fun s _ => abs_nonneg _) + +lemma value_difference_bound (W : BrownianSystem Ω) (β γ : OrderParameter) + {t : ℝ} (ht0 : 0 ≤ t) (ht1 : t ≤ 1) (x : ℝ) : + |value W β t x-value W γ t x| ≤ (3/2:ℝ)*coefficientDistance β γ := by + apply (value_coefficient_stability W β γ t x ht1).trans + apply mul_le_mul_of_nonneg_left _ (by norm_num) + exact intervalIntegral.integral_mono_interval ht0 ht1 le_rfl + (Eventually.of_forall (fun s => abs_nonneg _)) ((β.integrable.sub γ.integrable).abs.intervalIntegrable) + +def compactDifference (W : BrownianSystem Ω) (β γ : OrderParameter) (T t x : ℝ) : ℝ := + value W β (stripClamp T t) x-value W γ (stripClamp T t) x + +def compactDifferenceRate (W : BrownianSystem Ω) (β γ : OrderParameter) (T t x : ℝ) : ℝ := + compactValueRate W β T t x-compactValueRate W γ T t x + +lemma compactDifference_continuous (W : BrownianSystem Ω) (β γ : OrderParameter) + {T : ℝ} (hT0 : 0 ≤ T) (hT1 : T < 1) : + Continuous (fun p : ℝ × ℝ => compactDifference W β γ T p.1 p.2) := by + have hcl : ContinuousOn (fun p : ℝ × ℝ => (stripClamp T p.1,p.2)) univ := + (((continuous_stripClamp T).comp continuous_fst).prodMk continuous_snd).continuousOn + have hm : MapsTo (fun p : ℝ × ℝ => (stripClamp T p.1,p.2)) univ + (Icc (0:ℝ) T ×ˢ (univ : Set ℝ)) := fun p _ => ⟨stripClamp_mem hT0 p.1,mem_univ _⟩ + have hβ := (value_derivative_continuousOn W β hT0 hT1 0).comp hcl hm + have hγ := (value_derivative_continuousOn W γ hT0 hT1 0).comp hcl hm + exact continuousOn_univ.mp (hβ.sub hγ) + +lemma compactDifference_deriv (W : BrownianSystem Ω) (β γ : OrderParameter) + {T : ℝ} (hT0 : 0 ≤ T) (hT1 : T < 1) (t : ℝ) : + deriv (compactDifference W β γ T t)=fun x => compactGradient W β T t x-compactGradient W γ T t x := by + funext x + have hb := ((value_contDiff W β (stripClamp_mem hT0 t).1 ((stripClamp_mem hT0 t).2.trans_lt hT1)).differentiable (by simp) x).hasDerivAt + have hg := ((value_contDiff W γ (stripClamp_mem hT0 t).1 ((stripClamp_mem hT0 t).2.trans_lt hT1)).differentiable (by simp) x).hasDerivAt + exact (hb.sub hg).deriv + +lemma compactDifference_family (W : BrownianSystem Ω) (β γ : OrderParameter) + {T : ℝ} (hT0 : 0 ≤ T) (hT1 : T < 1) : BoundedSmoothFamily (compactDifference W β γ T) := by + have hs (t : ℝ) : ContDiff ℝ ∞ (compactDifference W β γ T t) := + (value_contDiff W β (stripClamp_mem hT0 t).1 ((stripClamp_mem hT0 t).2.trans_lt hT1)).sub + (value_contDiff W γ (stripClamp_mem hT0 t).1 ((stripClamp_mem hT0 t).2.trans_lt hT1)) + have hg : BoundedSmoothFamily (fun t x => compactGradient W β T t x-compactGradient W γ T t x) := by + convert (compactGradient_family W β hT0 hT1).add ((compactGradient_family W γ hT0 hT1).const_mul (-1)) using 1 + funext t x;ring + have hb (n : ℕ) : ∃ C : ℝ≥0, ∀ t x, |iteratedDeriv n (compactDifference W β γ T t) x| ≤ C := by + cases n with + | zero => + refine ⟨⟨(3/2:ℝ)*coefficientDistance β γ,mul_nonneg (by norm_num) (coefficientDistance_nonneg β γ)⟩,?_⟩ + intro t x + exact value_difference_bound W β γ (stripClamp_mem hT0 t).1 ((stripClamp_mem hT0 t).2.trans hT1.le) x + | succ n => + obtain ⟨C,hC⟩ := hg.bounds n + refine ⟨C,fun t x => ?_⟩ + rw [iteratedDeriv_succ',compactDifference_deriv W β γ hT0 hT1] + exact hC t x + exact ⟨(compactDifference_continuous W β γ hT0 hT1).measurable, + fun t => ⟨hs t,fun n => (hb n).imp (fun C hC x => hC t x)⟩,hb⟩ + +lemma compactDifferenceRate_family (W : BrownianSystem Ω) (β γ : OrderParameter) + {T : ℝ} (hT0 : 0 ≤ T) (hT1 : T < 1) : BoundedSmoothFamily (compactDifferenceRate W β γ T) := by + convert (compactValueRate_family W β hT0 hT1).add ((compactValueRate_family W γ hT0 hT1).const_mul (-1)) using 1 + funext t x + unfold compactDifferenceRate + ring + +def differenceField (W : BrownianSystem Ω) (β γ : OrderParameter) {T : ℝ} + (hT0 : 0 ≤ T) (hT1 : T < 1) : TimeField T where + f := compactDifference W β γ T + d := compactDifferenceRate W β γ T + smooth := compactDifference_family W β γ hT0 hT1 + rate_smooth := compactDifferenceRate_family W β γ hT0 hT1 + continuous := compactDifference_continuous W β γ hT0 hT1 + rate_right := fun t x => ((compactValueRate_rightSmooth W β hT0 hT1 0 t x).mono Ioi_subset_Ici_self).sub + ((compactValueRate_rightSmooth W γ hT0 hT1 0 t x).mono Ioi_subset_Ici_self) + time_deriv := by + intro t ht0 htT x + have hd := (value_derivative_hasDerivWithinAt_right W β hT0 hT1 ht0 htT 0 x).sub + (value_derivative_hasDerivWithinAt_right W γ hT0 hT1 ht0 htT 0 x) + apply hd.congr_of_eventuallyEq + · filter_upwards [self_mem_nhdsWithin,mem_nhdsWithin_of_mem_nhds (gt_mem_nhds htT)] with s hs hsT + simp only [compactDifference,stripClamp_eq ⟨ht0.trans hs.le,hsT.le⟩,iteratedDeriv_zero,Pi.sub_apply] + · simp only [compactDifference,stripClamp_eq ⟨ht0,htT.le⟩,iteratedDeriv_zero,Pi.sub_apply] + +end ZeroTemperatureSK + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKSupport/Control/VariableGrid.lean b/lean/OAI/Probability/SKSupport/Control/VariableGrid.lean new file mode 100644 index 0000000000000000000000000000000000000000..28b7f6bf2249a8bfd9fb14e2a898e238e1b82fd3 --- /dev/null +++ b/lean/OAI/Probability/SKSupport/Control/VariableGrid.lean @@ -0,0 +1,679 @@ +import Mathlib +import OAI.Probability.SKSupport.Diffusion.ExpectedFeedbackStep +import OAI.Probability.SKSupport.Foundations.SumRangeBlocks +import OAI.Probability.SKSupport.Backward.Backward + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology ContDiff +noncomputable section +namespace ZeroTemperatureSK.Nonuniform +open WeakIto Heat +variable {Ω : Type*} [mΩ : MeasurableSpace Ω] {P : Measure Ω} + +def time (h : ℕ → ℝ≥0) (n : ℕ) : ℝ≥0 := ∑ k ∈ Finset.range n, h k + +@[simp] lemma time_zero (h : ℕ → ℝ≥0) : time h 0 = 0 := by simp [time] +@[simp] lemma time_succ (h : ℕ → ℝ≥0) (n : ℕ) : time h (n+1) = time h n+h n := by + simp only [time,Finset.sum_range_succ] +lemma time_mono (h : ℕ → ℝ≥0) : Monotone (time h) := by + apply monotone_nat_of_le_succ + intro n + rw [time_succ] + exact le_add_of_nonneg_right (bot_le : (0:ℝ≥0) ≤ h n) + +lemma coe_time_succ (h : ℕ → ℝ≥0) (n : ℕ) : (time h (n+1):ℝ) = (time h n:ℝ)+(h n:ℝ) := by + rw [time_succ,NNReal.coe_add] + +def controlled (B α : ℝ≥0 → Ω → ℝ) (h c : ℕ → ℝ≥0) (x : ℝ) : ℕ → Ω → ℝ + | 0, _ => x + | k+1, ξ => controlled B α h c x k ξ + (B (time h (k+1)) ξ-B (time h k) ξ)+ + stepDrift (fun r => α (Real.toNNReal r)) (time h k) (h k) (c k) ξ + +lemma controlled_adapted {B α : ℝ≥0 → Ω → ℝ} (hm : ∀ t, Measurable (B t)) + (hap : IsProgressive (Filtration.natural B (fun t => (hm t).stronglyMeasurable)) α) + (hab : ∀ t ξ, |α t ξ| ≤ 1) (h c : ℕ → ℝ≥0) (x : ℝ) (n : ℕ) : + Measurable[Filtration.natural B (fun t => (hm t).stronglyMeasurable) (time h n)] + (controlled B α h c x n) := by + induction n with + | zero => exact measurable_const + | succ n ih => + have hle := time_mono h (Nat.le_succ n) + have hYm := ih.mono ((Filtration.natural B (fun t => (hm t).stronglyMeasurable)).mono hle) le_rfl + have hBs := (Filtration.stronglyAdapted_natural (fun t => (hm t).stronglyMeasurable) (time h n)).measurable.mono + ((Filtration.natural B (fun t => (hm t).stronglyMeasurable)).mono hle) le_rfl + have hBt := (Filtration.stronglyAdapted_natural (fun t => (hm t).stronglyMeasurable) (time h (n+1))).measurable + have hAm := progressive_stepDrift_measurable _ hap hab (time h n) (h n) (c n) + rw [← time_succ] at hAm + exact (hYm.add (hBt.sub hBs)).add hAm + +lemma controlled_integrable {B α : ℝ≥0 → Ω → ℝ} (hB : IsPreBrownianReal B P) + (ham : Measurable (fun p : ℝ≥0 × Ω => α p.1 p.2)) + (hab : ∀ t ξ, |α t ξ| ≤ 1) (h c : ℕ → ℝ≥0) (x : ℝ) (n : ℕ) : + Integrable (controlled B α h c x n) P := by + let := hB.isGaussianProcess.isProbabilityMeasure + have ham' : Measurable (fun p : ℝ × Ω => α (Real.toNNReal p.1) p.2) := + ham.comp (measurable_fst.real_toNNReal.prodMk measurable_snd) + induction n with + | zero => exact integrable_const x + | succ n ih => + exact (ih.add ((hB.integrable_eval _).sub (hB.integrable_eval _))).add + (stepDrift_integrable ham' (fun r ξ => hab _ ξ) (time h n) (h n) (c n) + (h n).coe_nonneg (c n).coe_nonneg) + +omit mΩ in +lemma controlled_formula (B α : ℝ≥0 → Ω → ℝ) (h c : ℕ → ℝ≥0) (x : ℝ) (n : ℕ) (ξ : Ω) : + controlled B α h c x n ξ = x+B (time h n) ξ-B 0 ξ+ + ∑ k ∈ Finset.range n, stepDrift (fun r => α (Real.toNNReal r)) (time h k) (h k) (c k) ξ := by + induction n with + | zero => simp [controlled] + | succ n ih => rw [controlled,ih,Finset.sum_range_succ]; ring + +def elementary (h : ℕ → ℝ≥0) (a : ℕ → Ω → ℝ) : ℕ → ℝ≥0 → Ω → ℝ + | 0, _, _ => 0 + | n+1, t, ξ => if time h n ≤ t ∧ t < time h (n+1) then a n ξ else elementary h a n t ξ + +omit mΩ in +lemma elementary_bound (h : ℕ → ℝ≥0) {a : ℕ → Ω → ℝ} (ha : ∀ k ξ, |a k ξ| ≤ 1) + (n : ℕ) (t : ℝ≥0) (ξ : Ω) : |elementary h a n t ξ| ≤ 1 := by + induction n with + | zero => simp [elementary] + | succ n ih => simp only [elementary]; split_ifs <;> first | exact ha n ξ | exact ih + +lemma elementary_progressive (ℱ : Filtration ℝ≥0 mΩ) (h : ℕ → ℝ≥0) + {a : ℕ → Ω → ℝ} (ha : ∀ n, Measurable[ℱ (time h n)] (a n)) (n : ℕ) : + IsProgressive ℱ (elementary h a n) := by + induction n with + | zero => exact isProgressive_const ℱ 0 + | succ n ih => + intro s + by_cases hns : time h n ≤ s + · have ham : Measurable[ℱ s] (a n) := (ha n).mono (ℱ.mono hns) le_rfl + let : MeasurableSpace Ω := ℱ s + have htime : Measurable (fun p : Set.Iic s × Ω => (p.1:ℝ≥0)) := + measurable_subtype_coe.comp measurable_fst + have hset : MeasurableSet {p : Set.Iic s × Ω | + time h n ≤ (p.1:ℝ≥0) ∧ (p.1:ℝ≥0) < time h (n+1)} := + (measurableSet_le (measurable_const : Measurable (fun _ : Set.Iic s × Ω => time h n)) htime).inter + (measurableSet_lt (α := ℝ≥0) (f := fun p : Set.Iic s × Ω => (p.1:ℝ≥0)) + (g := fun _ : Set.Iic s × Ω => time h (n+1)) htime measurable_const) + exact (ham.comp measurable_snd).ite hset (ih s) + · convert ih s using 1 + funext p + have hn : ¬time h n ≤ (p.1:ℝ≥0) := fun ht => hns (ht.trans p.1.property) + simp only [elementary,hn,false_and,↓reduceIte] + +omit mΩ in +lemma elementary_on_step (h : ℕ → ℝ≥0) (a : ℕ → Ω → ℝ) (n k : ℕ) (hk : k < n) + (t : ℝ≥0) (ht : time h k ≤ t ∧ t < time h (k+1)) (ξ : Ω) : + elementary h a n t ξ = a k ξ := by + induction n with + | zero => omega + | succ n ih => + by_cases hkn : k = n + · subst k; simp only [elementary,ite_eq_left ht] + · have hk' : k < n := by omega + have hlt : t < time h n := ht.2.trans_le (time_mono h (by omega : k+1 ≤ n)) + simp only [elementary,not_le.mpr hlt,false_and,↓reduceIte] + exact ih hk' + +omit mΩ in +lemma elementary_integral_on_step (h : ℕ → ℝ≥0) (a : ℕ → Ω → ℝ) + (n k : ℕ) (hk : k < n) (φ : ℝ → ℝ) (ξ : Ω) : + (∫ r in (time h k:ℝ)..(time h k:ℝ)+(h k:ℝ), + φ (elementary h a n (Real.toNNReal r) ξ)) = (h k:ℝ)*φ (a k ξ) := by + have he : (∫ r in (time h k:ℝ)..(time h k:ℝ)+(h k:ℝ), + φ (elementary h a n (Real.toNNReal r) ξ)) = + ∫ _r in (time h k:ℝ)..(time h k:ℝ)+(h k:ℝ), φ (a k ξ) := by + apply intervalIntegral.integral_congr_Ioo_of_le (by linarith [(h k).coe_nonneg]) + intro r hr + have hr0 : 0 ≤ r := (time h k).coe_nonneg.trans hr.1.le + have ht : time h k ≤ Real.toNNReal r ∧ Real.toNNReal r < time h (k+1) := by + constructor + · apply NNReal.coe_le_coe.mp + rw [Real.coe_toNNReal _ hr0] + exact hr.1.le + · apply NNReal.coe_lt_coe.mp + rw [Real.coe_toNNReal _ hr0,coe_time_succ] + exact hr.2 + change φ (elementary h a n (Real.toNNReal r) ξ) = φ (a k ξ) + rw [elementary_on_step h a n k hk _ ht ξ] + rw [he,intervalIntegral.integral_const] + simp only [add_sub_cancel_left,smul_eq_mul] + +structure GridData (N : ℕ) (h c : ℕ → ℝ≥0) (F D : ℕ → ℝ → ℝ → ℝ) where + C₂ : ℝ≥0 + C₃ : ℝ≥0 + Ct : ℝ≥0 + L : ℝ≥0 + Γ : ℝ≥0 + smooth : ∀ k t, ContDiff ℝ 3 (F k t) + gradient_bound : ∀ k t z, |deriv (F k t) z| ≤ 1 + seam : ∀ k < N, F k (time h (k+1)) = F (k+1) (time h (k+1)) + coefficient_bound : ∀ k < N, c k ≤ Γ + second_bound : ∀ k < N, ∀ t z, |deriv (deriv (F k t)) z| ≤ C₂ + third_bound : ∀ k < N, ∀ t z, |iteratedDeriv 3 (F k t) z| ≤ C₃ + rate_measurable : ∀ k t, Measurable (D k t) + rate_bound : ∀ k < N, ∀ t z, |D k t z| ≤ Ct + time_derivative : ∀ k < N, ∀ r ∈ Icc (time h k:ℝ) (time h (k+1):ℝ), ∀ z, + HasDerivWithinAt (fun t => F k t z) (D k r z) + (Icc (time h k:ℝ) (time h (k+1):ℝ)) r + rate_joint : ∀ k < N, ∀ r ∈ Icc (time h k:ℝ) (time h (k+1):ℝ), + ∀ s ∈ Icc (time h k:ℝ) (time h (k+1):ℝ), ∀ z y, + |D k r z-D k s y| ≤ (L:ℝ)*(|r-s|+|z-y|) + pde : ∀ k < N, ∀ t ∈ Icc (time h k:ℝ) (time h (k+1):ℝ), ∀ z, + D k t z+(1/2:ℝ)*deriv (deriv (F k t)) z+(c k:ℝ)/2*(deriv (F k t) z)^2 = 0 + +def profit (B α : ℝ≥0 → Ω → ℝ) (h c : ℕ → ℝ≥0) (f : ℝ → ℝ) (x : ℝ) (N : ℕ) : ℝ := + (∫ ξ, f (controlled B α h c x N ξ) ∂P)- + ∑ k ∈ Finset.range N, ∫ ξ, stepCost (fun r => α (Real.toNNReal r)) (time h k) (h k) (c k) ξ ∂P + +lemma telescope_bound (Q K ε : ℕ → ℝ) (n : ℕ) + (hs : ∀ k < n, Q (k+1)-Q k-K k ≤ ε k) : + Q n-Q 0-(∑ k ∈ Finset.range n, K k) ≤ ∑ k ∈ Finset.range n, ε k := by + induction n with + | zero => simp + | succ n ih => + have hprev := ih (fun k hk => hs k (by omega)) + have hlast := hs n (by omega) + rw [Finset.sum_range_succ,Finset.sum_range_succ] + linarith + +lemma GridData.mesh_upper {B α : ℝ≥0 → Ω → ℝ} (hB : IsPreBrownianReal B P) + (hm : ∀ t, Measurable (B t)) + (hap : IsProgressive (Filtration.natural B (fun t => (hm t).stronglyMeasurable)) α) + (hab : ∀ t ξ, |α t ξ| ≤ 1) {N : ℕ} {h c : ℕ → ℝ≥0} {F D : ℕ → ℝ → ℝ → ℝ} + (sd : GridData N h c F D) (x : ℝ) : + profit (P := P) B α h c (F N (time h N)) x N-F 0 0 x ≤ + ∑ k ∈ Finset.range N, verificationError sd.Γ sd.C₂ sd.C₃ sd.L (h k) := by + let := hB.isGaussianProcess.isProbabilityMeasure + have ham := progressive_joint_measurable _ hap + have ham' : Measurable (fun p : ℝ × Ω => α (Real.toNNReal p.1) p.2) := + ham.comp (measurable_fst.real_toNNReal.prodMk measurable_snd) + let Q (k : ℕ) := ∫ ξ, F k (time h k) (controlled B α h c x k ξ) ∂P + let K (k : ℕ) := ∫ ξ, stepCost (fun r => α (Real.toNNReal r)) (time h k) (h k) (c k) ξ ∂P + have hstep (k : ℕ) (hk : k < N) : Q (k+1)-Q k-K k ≤ verificationError sd.Γ sd.C₂ sd.C₃ sd.L (h k) := by + have hleft : (time h k:ℝ) ∈ Icc (time h k:ℝ) (time h (k+1):ℝ) := + ⟨le_rfl,NNReal.coe_le_coe.mpr (time_mono h (Nat.le_succ k))⟩ + have hu := expected_verification_step hB hm (time h k) (h k) (c k) + (controlled_adapted hm hap hab h c x k) (controlled_integrable hB ham hab h c x k) + (α := fun r => α (Real.toNNReal r)) ham' (fun r ξ => hab _ ξ) + (sd.smooth k) 1 sd.C₂ sd.C₃ sd.Ct sd.L + (sd.gradient_bound k) (sd.second_bound k hk) (sd.third_bound k hk) + (sd.rate_measurable k _) (sd.rate_bound k hk _) + (by simpa only [coe_time_succ] using sd.time_derivative k hk) + (by simpa only [coe_time_succ] using + fun r hr z y => sd.rate_joint k hk r hr (time h k) hleft z y) + (sd.pde k hk (time h k) hleft) + have he : (fun ξ => F k ((time h k:ℝ)+(h k:ℝ)) + (controlled B α h c x k ξ+(B (time h k+h k) ξ-B (time h k) ξ)+ + stepDrift (fun r => α (Real.toNNReal r)) (time h k) (h k) (c k) ξ)) = + fun ξ => F (k+1) (time h (k+1)) (controlled B α h c x (k+1) ξ) := by + funext ξ + rw [← time_succ,← coe_time_succ,sd.seam k hk] + rfl + rw [he] at hu + exact hu.trans (verificationError_mono (c k) sd.Γ sd.C₂ sd.C₂ sd.C₃ sd.C₃ sd.L sd.L (h k) + (sd.coefficient_bound k hk) le_rfl le_rfl le_rfl) + have hh := telescope_bound Q K (fun k => verificationError sd.Γ sd.C₂ sd.C₃ sd.L (h k)) N hstep + have hz : Q 0 = F 0 0 x := by simp [Q,controlled] + rw [hz] at hh + dsimp only [profit] + linarith + +def euler (B : ℝ≥0 → Ω → ℝ) (h c : ℕ → ℝ≥0) (u : ℕ → ℝ → ℝ) (x : ℝ) : ℕ → Ω → ℝ + | 0, _ => x + | k+1, ξ => euler B h c u x k ξ+(B (time h (k+1)) ξ-B (time h k) ξ)+ + (c k:ℝ)*(h k:ℝ)*u k (euler B h c u x k ξ) + +lemma euler_adapted {B : ℝ≥0 → Ω → ℝ} (hm : ∀ t, Measurable (B t)) + (h c : ℕ → ℝ≥0) {u : ℕ → ℝ → ℝ} (hum : ∀ k, Measurable (u k)) (x : ℝ) (n : ℕ) : + Measurable[Filtration.natural B (fun t => (hm t).stronglyMeasurable) (time h n)] + (euler B h c u x n) := by + induction n with + | zero => exact measurable_const + | succ n ih => + have hle := time_mono h (Nat.le_succ n) + have hYm := ih.mono ((Filtration.natural B (fun t => (hm t).stronglyMeasurable)).mono hle) le_rfl + have hBs := (Filtration.stronglyAdapted_natural (fun t => (hm t).stronglyMeasurable) (time h n)).measurable.mono + ((Filtration.natural B (fun t => (hm t).stronglyMeasurable)).mono hle) le_rfl + have hBt := (Filtration.stronglyAdapted_natural (fun t => (hm t).stronglyMeasurable) (time h (n+1))).measurable + exact (hYm.add (hBt.sub hBs)).add (((hum n).comp hYm).const_mul ((c n:ℝ)*(h n:ℝ))) + +omit mΩ in +lemma euler_controlled {B : ℝ≥0 → Ω → ℝ} (h c : ℕ → ℝ≥0) (u : ℕ → ℝ → ℝ) + (x : ℝ) (n k : ℕ) (hk : k ≤ n) (ξ : Ω) : + controlled B (elementary h (fun j ξ => u j (euler B h c u x j ξ)) n) h c x k ξ = + euler B h c u x k ξ := by + induction k with + | zero => rfl + | succ k ih => + have hk' : k < n := by omega + have he := elementary_integral_on_step h (fun j ξ => u j (euler B h c u x j ξ)) n k hk' + (fun z => (c k:ℝ)*z) ξ + change stepDrift (fun r => elementary h (fun j ξ => u j (euler B h c u x j ξ)) n (Real.toNNReal r)) + (time h k) (h k) (c k) ξ = (h k:ℝ)*((c k:ℝ)*u k (euler B h c u x k ξ)) at he + rw [controlled,he,ih (by omega),euler] + ring + +lemma GridData.mesh_lower {B : ℝ≥0 → Ω → ℝ} (hB : IsPreBrownianReal B P) + (hm : ∀ t, Measurable (B t)) {N : ℕ} {h c : ℕ → ℝ≥0} {F D : ℕ → ℝ → ℝ → ℝ} + (sd : GridData N h c F D) (x : ℝ) : + ∃ α : ℝ≥0 → Ω → ℝ, + IsProgressive (Filtration.natural B (fun t => (hm t).stronglyMeasurable)) α ∧ + (∀ t ξ, |α t ξ| ≤ 1) ∧ + F 0 0 x-(∑ k ∈ Finset.range N, verificationError sd.Γ sd.C₂ sd.C₃ sd.L (h k)) ≤ + profit (P := P) B α h c (F N (time h N)) x N := by + let := hB.isGaussianProcess.isProbabilityMeasure + let u (k : ℕ) := deriv (F k (time h k)) + let a (k : ℕ) (ξ : Ω) := u k (euler B h c u x k ξ) + let α := elementary h a N + have hum : ∀ k, Measurable (u k) := fun k => + (show ContDiff ℝ 2 (u k) from (sd.smooth k _).deriv').continuous.measurable + have hap : IsProgressive (Filtration.natural B (fun t => (hm t).stronglyMeasurable)) α := + elementary_progressive _ h (fun k => (hum k).comp (euler_adapted hm h c hum x k)) N + have hab : ∀ t ξ, |α t ξ| ≤ 1 := elementary_bound h (fun k ξ => sd.gradient_bound _ _ _) N + refine ⟨α,hap,hab,?_⟩ + have ham := progressive_joint_measurable _ hap + have hgrid (k : ℕ) (hk : k ≤ N) (ξ : Ω) : + controlled B α h c x k ξ = euler B h c u x k ξ := euler_controlled h c u x N k hk ξ + let Q (k : ℕ) := ∫ ξ, F k (time h k) (controlled B α h c x k ξ) ∂P + let K (k : ℕ) := ∫ ξ, stepCost (fun r => α (Real.toNNReal r)) (time h k) (h k) (c k) ξ ∂P + have hstep (k : ℕ) (hk : k < N) : -Q (k+1)-(-Q k)-(-K k) ≤ + verificationError sd.Γ sd.C₂ sd.C₃ sd.L (h k) := by + have hleft : (time h k:ℝ) ∈ Icc (time h k:ℝ) (time h (k+1):ℝ) := + ⟨le_rfl,NNReal.coe_le_coe.mpr (time_mono h (Nat.le_succ k))⟩ + have hg := expected_feedback_step hB hm (time h k) (h k) (c k) + (controlled_adapted hm hap hab h c x k) (controlled_integrable hB ham hab h c x k) + (sd.smooth k) sd.C₂ sd.C₃ sd.Ct sd.L (sd.gradient_bound k) (sd.second_bound k hk) + (sd.third_bound k hk) (sd.rate_measurable k _) (sd.rate_bound k hk _) + (by simpa only [coe_time_succ] using sd.time_derivative k hk) + (by simpa only [coe_time_succ] using + fun r hr z y => sd.rate_joint k hk r hr (time h k) hleft z y) + (sd.pde k hk (time h k) hleft) + have he : (fun ξ => F k ((time h k:ℝ)+(h k:ℝ)) + (controlled B α h c x k ξ+(B (time h k+h k) ξ-B (time h k) ξ)+ + (c k:ℝ)*(h k:ℝ)*deriv (F k (time h k)) (controlled B α h c x k ξ))) = + fun ξ => F (k+1) (time h (k+1)) (controlled B α h c x (k+1) ξ) := by + funext ξ + rw [← time_succ,← coe_time_succ,sd.seam k hk] + rw [hgrid k hk.le,hgrid (k+1) (by omega)] + rfl + rw [he] at hg + have hK : K k = (c k:ℝ)*(h k:ℝ)/2* + (∫ ξ, (deriv (F k (time h k)) (controlled B α h c x k ξ))^2 ∂P) := by + dsimp only [K] + rw [← integral_const_mul] + apply integral_congr_ae + filter_upwards [] with ξ + have hh := elementary_integral_on_step h a N k hk (fun z => (c k:ℝ)*z^2) ξ + change stepCost (fun r => α (Real.toNNReal r)) (time h k) (h k) (c k) ξ = _ + rw [stepCost,hh] + dsimp only [a,u] + rw [hgrid k hk.le] + ring + have hg' : |Q (k+1)-Q k-K k| ≤ verificationError sd.Γ sd.C₂ sd.C₃ sd.L (h k) := by + rw [hK] + exact hg.trans (verificationError_mono (c k) sd.Γ sd.C₂ sd.C₂ sd.C₃ sd.C₃ sd.L sd.L (h k) + (sd.coefficient_bound k hk) le_rfl le_rfl le_rfl) + linarith [(abs_le.mp hg').1] + have hh := telescope_bound (fun k => -Q k) (fun k => -K k) + (fun k => verificationError sd.Γ sd.C₂ sd.C₃ sd.L (h k)) N hstep + have hz : Q 0 = F 0 0 x := by simp [Q,controlled] + rw [hz,Finset.sum_neg_distrib] at hh + change F 0 0 x-(∑ k ∈ Finset.range N, verificationError sd.Γ sd.C₂ sd.C₃ sd.L (h k)) ≤ + Q N-∑ k ∈ Finset.range N, K k + linarith + +def refineLengths (h : ℕ → ℝ≥0) (m : ℕ) : ℕ → ℝ≥0 := fun j => h (j/m)/(m:ℝ≥0) + +lemma refine_time_block (h : ℕ → ℝ≥0) {m : ℕ} (hm : 0 < m) (k : ℕ) : + time (refineLengths h m) (k*m) = time h k := by + apply NNReal.coe_injective + simp only [time,NNReal.coe_sum,refineLengths,NNReal.coe_div,NNReal.coe_natCast] + rw [sum_range_blocks] + apply Finset.sum_congr rfl + intro i hi + have he : (∑ j ∈ Finset.range m, (h ((i*m+j)/m):ℝ)/(m:ℝ)) = + ∑ _j ∈ Finset.range m, (h i:ℝ)/(m:ℝ) := by + apply Finset.sum_congr rfl + intro j hj + rw [refined_coefficient hm (Finset.mem_range.mp hj)] + rw [he] + simp only [Finset.sum_const,Finset.card_range,nsmul_eq_mul] + have hm0 : (m:ℝ) ≠ 0 := by exact_mod_cast hm.ne' + field_simp + +lemma refine_time_inside (h : ℕ → ℝ≥0) {m : ℕ} (hm : 0 < m) (k j : ℕ) (hj : j ≤ m) : + time (refineLengths h m) (k*m+j) = time h k+(j:ℝ≥0)*(h k/(m:ℝ≥0)) := by + induction j with + | zero => simp only [refine_time_block h hm,Nat.cast_zero,zero_mul,add_zero] + | succ j ih => + have hjm : j < m := by omega + rw [show k*m+(j+1) = (k*m+j)+1 by omega,time_succ,ih (by omega)] + simp only [refineLengths,refined_coefficient hm hjm,Nat.cast_add,Nat.cast_one] + ring + +lemma refine_cell_subset (h : ℕ → ℝ≥0) {m : ℕ} (hm : 0 < m) (j : ℕ) : + Icc (time (refineLengths h m) j:ℝ) (time (refineLengths h m) (j+1):ℝ) ⊆ + Icc (time h (j/m):ℝ) (time h (j/m+1):ℝ) := by + have hl : j/m*m ≤ j := Nat.div_mul_le_self _ _ + have hu : j+1 ≤ (j/m+1)*m := (Nat.div_lt_iff_lt_mul hm).mp (Nat.lt_succ_self _) + intro r hr + constructor + · have ht := time_mono (refineLengths h m) hl + rw [refine_time_block h hm] at ht + exact (NNReal.coe_le_coe.mpr ht).trans hr.1 + · have ht := time_mono (refineLengths h m) hu + rw [refine_time_block h hm] at ht + exact hr.2.trans (NNReal.coe_le_coe.mpr ht) + +lemma grid_drift_refinement {α : ℝ → Ω → ℝ} + (hm : Measurable (fun p : ℝ × Ω => α p.1 p.2)) (hb : ∀ r ξ, |α r ξ| ≤ 1) + (h c : ℕ → ℝ≥0) (n m : ℕ) (hmpos : 0 < m) (ξ : Ω) : + (∑ j ∈ Finset.range (n*m), stepDrift α (time (refineLengths h m) j) + (refineLengths h m j) (c (j/m)) ξ) = + ∑ k ∈ Finset.range n, stepDrift α (time h k) (h k) (c k) ξ := by + rw [sum_range_blocks] + apply Finset.sum_congr rfl + intro k hk + have he : (∑ j ∈ Finset.range m, stepDrift α (time (refineLengths h m) (k*m+j)) + (refineLengths h m (k*m+j)) (c ((k*m+j)/m)) ξ) = + ∑ j ∈ Finset.range m, stepDrift α ((time h k:ℝ)+(j:ℝ)*((h k:ℝ)/(m:ℝ))) + ((h k:ℝ)/(m:ℝ)) (c k) ξ := by + apply Finset.sum_congr rfl + intro j hj + have hjm := Finset.mem_range.mp hj + rw [refine_time_inside h hmpos k j hjm.le] + simp only [refineLengths,refined_coefficient hmpos hjm,NNReal.coe_add,NNReal.coe_mul, + NNReal.coe_div,NNReal.coe_natCast] + rw [he] + exact stepDrift_subdivision hm hb (time h k) (h k) (c k) (h k).coe_nonneg m hmpos ξ + +lemma grid_cost_refinement {α : ℝ → Ω → ℝ} + (hm : Measurable (fun p : ℝ × Ω => α p.1 p.2)) (hb : ∀ r ξ, |α r ξ| ≤ 1) + (h c : ℕ → ℝ≥0) (n m : ℕ) (hmpos : 0 < m) (ξ : Ω) : + (∑ j ∈ Finset.range (n*m), stepCost α (time (refineLengths h m) j) + (refineLengths h m j) (c (j/m)) ξ) = + ∑ k ∈ Finset.range n, stepCost α (time h k) (h k) (c k) ξ := by + rw [sum_range_blocks] + apply Finset.sum_congr rfl + intro k hk + have he : (∑ j ∈ Finset.range m, stepCost α (time (refineLengths h m) (k*m+j)) + (refineLengths h m (k*m+j)) (c ((k*m+j)/m)) ξ) = + ∑ j ∈ Finset.range m, stepCost α ((time h k:ℝ)+(j:ℝ)*((h k:ℝ)/(m:ℝ))) + ((h k:ℝ)/(m:ℝ)) (c k) ξ := by + apply Finset.sum_congr rfl + intro j hj + have hjm := Finset.mem_range.mp hj + rw [refine_time_inside h hmpos k j hjm.le] + simp only [refineLengths,refined_coefficient hmpos hjm,NNReal.coe_add,NNReal.coe_mul, + NNReal.coe_div,NNReal.coe_natCast] + rw [he] + exact stepCost_subdivision hm hb (time h k) (h k) (c k) (h k).coe_nonneg m hmpos ξ +lemma controlled_refinement (B : ℝ≥0 → Ω → ℝ) {α : ℝ≥0 → Ω → ℝ} + (hm : Measurable (fun p : ℝ≥0 × Ω => α p.1 p.2)) (hb : ∀ r ξ, |α r ξ| ≤ 1) + (h c : ℕ → ℝ≥0) (x : ℝ) (n m : ℕ) (hmpos : 0 < m) (ξ : Ω) : + controlled B α (refineLengths h m) (fun j => c (j/m)) x (n*m) ξ = + controlled B α h c x n ξ := by + have hm' : Measurable (fun p : ℝ × Ω => α (Real.toNNReal p.1) p.2) := + hm.comp (measurable_fst.real_toNNReal.prodMk measurable_snd) + simp only [controlled_formula,refine_time_block h hmpos] + rw [grid_drift_refinement hm' (fun r ξ => hb _ ξ) h c n m hmpos ξ] + +lemma profit_refinement {B α : ℝ≥0 → Ω → ℝ} [IsProbabilityMeasure P] + (ham : Measurable (fun p : ℝ≥0 × Ω => α p.1 p.2)) (hab : ∀ t ξ, |α t ξ| ≤ 1) + (h c : ℕ → ℝ≥0) (f : ℝ → ℝ) (x : ℝ) (N m : ℕ) (hmpos : 0 < m) : + profit (P := P) B α (refineLengths h m) (fun j => c (j/m)) f x (N*m) = + profit (P := P) B α h c f x N := by + have ham' : Measurable (fun p : ℝ × Ω => α (Real.toNNReal p.1) p.2) := + ham.comp (measurable_fst.real_toNNReal.prodMk measurable_snd) + unfold profit + congr 1 + · apply integral_congr_ae + filter_upwards [] with ξ + rw [controlled_refinement B ham hab h c x N m hmpos ξ] + · have hi (d a : ℝ≥0) (s : ℝ) : Integrable (stepCost (fun r => α (Real.toNNReal r)) s d a) P := + stepCost_integrable (α := fun r => α (Real.toNNReal r)) ham' (fun r ξ => hab _ ξ) s d a d.coe_nonneg a.coe_nonneg + rw [← integral_finsetSum (Finset.range (N*m)) (fun j _ => hi _ _ _), + ← integral_finsetSum (Finset.range N) (fun k _ => hi _ _ _)] + apply integral_congr_ae + filter_upwards [] with ξ + exact grid_cost_refinement ham' (fun r ξ => hab _ ξ) h c N m hmpos ξ + +noncomputable def GridData.refine {N : ℕ} {h c : ℕ → ℝ≥0} {F D : ℕ → ℝ → ℝ → ℝ} + (sd : GridData N h c F D) (m : ℕ) (hm : 0 < m) : + GridData (N*m) (refineLengths h m) (fun j => c (j/m)) (fun j => F (j/m)) (fun j => D (j/m)) := by + have hq (j : ℕ) (hj : j < N*m) : j/m < N := (Nat.div_lt_iff_lt_mul hm).mpr hj + refine ⟨sd.C₂,sd.C₃,sd.Ct,sd.L,sd.Γ, + fun j => sd.smooth (j/m), fun j => sd.gradient_bound (j/m), ?_, + fun j hj => sd.coefficient_bound _ (hq j hj), + fun j hj => sd.second_bound _ (hq j hj), + fun j hj => sd.third_bound _ (hq j hj), fun j => sd.rate_measurable (j/m), + fun j hj => sd.rate_bound _ (hq j hj), ?_,?_,?_⟩ + · intro j hj + rcases refinement_successor hm j with he | ⟨he,hde⟩ + · rw [he] + · rw [he,hde,refine_time_block h hm] + exact sd.seam (j/m) (hq j hj) + · intro j hj r hr z + exact (sd.time_derivative _ (hq j hj) r (refine_cell_subset h hm j hr) z).mono + (refine_cell_subset h hm j) + · intro j hj r hr s hs z y + exact sd.rate_joint _ (hq j hj) r (refine_cell_subset h hm j hr) s + (refine_cell_subset h hm j hs) z y + · intro j hj t ht z + exact sd.pde _ (hq j hj) t (refine_cell_subset h hm j ht) z + +lemma sum_error_refinement (h : ℕ → ℝ≥0) (N m : ℕ) (hm : 0 < m) (Γ C₂ C₃ L : ℝ≥0) : + (∑ j ∈ Finset.range (N*m), verificationError Γ C₂ C₃ L (refineLengths h m j)) = + ∑ k ∈ Finset.range N, (m:ℝ)*verificationError Γ C₂ C₃ L ((h k:ℝ)/(m:ℝ)) := by + rw [sum_range_blocks] + apply Finset.sum_congr rfl + intro k hk + have he : (∑ j ∈ Finset.range m, verificationError Γ C₂ C₃ L (refineLengths h m (k*m+j))) = + ∑ _j ∈ Finset.range m, verificationError Γ C₂ C₃ L ((h k:ℝ)/(m:ℝ)) := by + apply Finset.sum_congr rfl + intro j hj + simp only [refineLengths,refined_coefficient hm (Finset.mem_range.mp hj),NNReal.coe_div,NNReal.coe_natCast] + rw [he] + simp only [Finset.sum_const,Finset.card_range,nsmul_eq_mul] + +lemma refined_error_limit (h : ℕ → ℝ≥0) (N : ℕ) (Γ C₂ C₃ L : ℝ≥0) : + Tendsto (fun m : ℕ => ∑ k ∈ Finset.range N, + (m:ℝ)*verificationError Γ C₂ C₃ L ((h k:ℝ)/(m:ℝ))) atTop (𝓝 0) := by + simpa only [Finset.sum_const_zero] using + tendsto_finsetSum (Finset.range N) (fun k _ => verificationError_limit (h k) Γ C₂ C₃ L) + +def objectives {B : ℝ≥0 → Ω → ℝ} (hm : ∀ t, Measurable (B t)) (h c : ℕ → ℝ≥0) + (f : ℝ → ℝ) (x : ℝ) (N : ℕ) : Set ℝ := + {v | ∃ α : ℝ≥0 → Ω → ℝ, + IsProgressive (Filtration.natural B (fun t => (hm t).stronglyMeasurable)) α ∧ + (∀ t ξ, |α t ξ| ≤ 1) ∧ v = profit (P := P) B α h c f x N} + +lemma objectives_nonempty {B : ℝ≥0 → Ω → ℝ} (hm : ∀ t, Measurable (B t)) + (h c : ℕ → ℝ≥0) (f : ℝ → ℝ) (x : ℝ) (N : ℕ) : (objectives (P := P) hm h c f x N).Nonempty := by + exact ⟨_,fun _ _ => 0,isProgressive_const _ _,by simp,rfl⟩ + +lemma GridData.control_upper {B α : ℝ≥0 → Ω → ℝ} (hB : IsPreBrownianReal B P) + (hm : ∀ t, Measurable (B t)) + (hap : IsProgressive (Filtration.natural B (fun t => (hm t).stronglyMeasurable)) α) + (hab : ∀ t ξ, |α t ξ| ≤ 1) {N : ℕ} {h c : ℕ → ℝ≥0} {F D : ℕ → ℝ → ℝ → ℝ} + (sd : GridData N h c F D) (x : ℝ) : + profit (P := P) B α h c (F N (time h N)) x N ≤ F 0 0 x := by + let := hB.isGaussianProcess.isProbabilityMeasure + have hlim := refined_error_limit h N sd.Γ sd.C₂ sd.C₃ sd.L + have hh : profit (P := P) B α h c (F N (time h N)) x N-F 0 0 x ≤ 0 := by + apply ge_of_tendsto hlim + filter_upwards [eventually_ge_atTop (1:ℕ)] with m hm1 + have hmpos : 0 < m := by omega + have hu := (sd.refine m hmpos).mesh_upper hB hm hap hab x + have hdiv : N*m/m = N := by rw [Nat.mul_comm,Nat.mul_div_cancel_left _ hmpos] + change profit (P := P) B α (refineLengths h m) (fun j => c (j/m)) + (F (N*m/m) (time (refineLengths h m) (N*m))) x (N*m)-F (0/m) 0 x ≤ + ∑ j ∈ Finset.range (N*m), verificationError sd.Γ sd.C₂ sd.C₃ sd.L (refineLengths h m j) at hu + rw [hdiv,refine_time_block h hmpos,Nat.zero_div, + profit_refinement (progressive_joint_measurable _ hap) hab h c _ x N m hmpos, + sum_error_refinement h N m hmpos] at hu + exact hu + linarith + +lemma GridData.control_lower {B : ℝ≥0 → Ω → ℝ} (hB : IsPreBrownianReal B P) + (hm : ∀ t, Measurable (B t)) {N : ℕ} {h c : ℕ → ℝ≥0} {F D : ℕ → ℝ → ℝ → ℝ} + (sd : GridData N h c F D) (x : ℝ) {ε : ℝ} (hε : 0 < ε) : + ∃ v ∈ objectives (P := P) hm h c (F N (time h N)) x N, F 0 0 x-ε ≤ v := by + let := hB.isGaussianProcess.isProbabilityMeasure + have hlim := refined_error_limit h N sd.Γ sd.C₂ sd.C₃ sd.L + obtain ⟨m,hm1,he⟩ := ((eventually_ge_atTop (1:ℕ)).and (hlim.eventually (gt_mem_nhds hε))).exists + have hmpos : 0 < m := by omega + obtain ⟨α,hap,hab,hl⟩ := (sd.refine m hmpos).mesh_lower hB hm x + have hdiv : N*m/m = N := by rw [Nat.mul_comm,Nat.mul_div_cancel_left _ hmpos] + change F (0/m) 0 x-(∑ j ∈ Finset.range (N*m), + verificationError sd.Γ sd.C₂ sd.C₃ sd.L (refineLengths h m j)) ≤ + profit (P := P) B α (refineLengths h m) (fun j => c (j/m)) + (F (N*m/m) (time (refineLengths h m) (N*m))) x (N*m) at hl + rw [hdiv,refine_time_block h hmpos,Nat.zero_div, + profit_refinement (progressive_joint_measurable _ hap) hab h c _ x N m hmpos, + sum_error_refinement h N m hmpos] at hl + refine ⟨_,⟨α,hap,hab,rfl⟩,?_⟩ + linarith + +def cascadeV (h c : ℕ → ℝ≥0) (f : ℝ → ℝ) : ℕ → ℕ → ℝ → ℝ + | 0, _, x => f x + | n+1, k, x => logSemigroup (c k) (h k) (cascadeV h c f n (k+1)) x + +lemma cascadeV_lipschitz {f : ℝ → ℝ} {K : ℝ≥0} (hf : LipschitzWith K f) + (h c : ℕ → ℝ≥0) (N k : ℕ) : LipschitzWith K (cascadeV h c f N k) := by + induction N generalizing k with + | zero => exact hf + | succ N ih => exact logSemigroup_lipschitz (ih (k+1)) (c k).coe_nonneg (h k) + +lemma cascadeV_regular {f : ℝ → ℝ} (hf : RegularDatum f) (hLip : LipschitzWith 1 f) + (h c : ℕ → ℝ≥0) (N k : ℕ) : RegularDatum (cascadeV h c f N k) := by + induction N generalizing k with + | zero => exact hf + | succ N ih => + exact regularDatum_logSemigroup (ih (k+1)) + (cascadeV_lipschitz hLip h c N (k+1)) (c k).coe_nonneg (h k) + +def cascadeVAt (h c : ℕ → ℝ≥0) (f : ℝ → ℝ) (N k : ℕ) : ℝ → ℝ := + cascadeV h c f (N-k) k + +def cellVHeat (h c : ℕ → ℝ≥0) (f : ℝ → ℝ) (N k : ℕ) : ℝ → ℝ → ℝ := + backward (c k) (time h (min (k+1) N)) (cascadeVAt h c f N (k+1)) + +def cellVRate (h c : ℕ → ℝ≥0) (f : ℝ → ℝ) (N k : ℕ) : ℝ → ℝ → ℝ := + backwardRate (c k) (time h (min (k+1) N)) (cascadeVAt h c f N (k+1)) + +lemma cellVHeat_verificationData {f : ℝ → ℝ} (hf : RegularDatum f) (hLip : LipschitzWith 1 f) + (h c : ℕ → ℝ≥0) (N k : ℕ) : + VerificationData (cellVHeat h c f N k) (cellVRate h c f N k) (c k) (time h (min (k+1) N)) := + backward_verificationData (cascadeV_regular hf hLip h c _ _) + (cascadeV_lipschitz hLip h c _ _) (c k).coe_nonneg _ + +lemma cellVHeat_left {f : ℝ → ℝ} (hf : RegularDatum f) (hLip : LipschitzWith 1 f) + (h c : ℕ → ℝ≥0) (N k : ℕ) (hk : k ≤ N) : + cellVHeat h c f N k (time h k) = cascadeVAt h c f N k := by + by_cases he : k = N + · subst k + funext x + simpa [cellVHeat,cascadeVAt,cascadeV,Nat.min_eq_right (Nat.le_succ N)] using + backward_terminal (c N) (time h N) f x + · have hk' : k < N := lt_of_le_of_ne hk he + have hN : N-k = (N-(k+1))+1 := by omega + funext x + unfold cellVHeat cascadeVAt backward + rw [Nat.min_eq_left (by omega : k+1 ≤ N)] + have ht : (time h (k+1):ℝ)-(time h k:ℝ) = (h k:ℝ) := by rw [coe_time_succ]; ring + rw [ht,hN,cascadeV] + exact varianceLogHeat_eq_logSemigroup + (cascadeV_regular hf hLip h c _ _).smooth.continuous.measurable (c k) (h k) x + +lemma cellVHeat_right (h c : ℕ → ℝ≥0) (f : ℝ → ℝ) (N k : ℕ) (hk : k < N) : + cellVHeat h c f N k (time h (k+1)) = cascadeVAt h c f N (k+1) := by + funext x + dsimp only [cellVHeat] + rw [Nat.min_eq_left (by omega : k+1 ≤ N)] + exact backward_terminal _ _ _ _ + +lemma cellVHeat_seam {f : ℝ → ℝ} (hf : RegularDatum f) (hLip : LipschitzWith 1 f) + (h c : ℕ → ℝ≥0) (N k : ℕ) (hk : k < N) : + cellVHeat h c f N k (time h (k+1)) = cellVHeat h c f N (k+1) (time h (k+1)) := by + rw [cellVHeat_right h c f N k hk,cellVHeat_left hf hLip h c N (k+1) (by omega)] + +noncomputable def cellVHeat_gridData {f : ℝ → ℝ} (hf : RegularDatum f) (hLip : LipschitzWith 1 f) + (h c : ℕ → ℝ≥0) (N : ℕ) : GridData N h c (cellVHeat h c f N) (cellVRate h c f N) := by + classical + have hd (k : ℕ) := cellVHeat_verificationData hf hLip h c N k + have hb (k : ℕ) := (hd k).bounds + choose C₂ C₃ Ct L H using hb + refine ⟨(Finset.range N).sup C₂,(Finset.range N).sup C₃, + (Finset.range N).sup Ct,(Finset.range N).sup L,(Finset.range N).sup c, + fun k => (hd k).smooth,fun k => (hd k).gradient_bound, + cellVHeat_seam hf hLip h c N,?_,?_,?_,?_,?_,?_,?_,?_⟩ + · intro k hk + exact Finset.le_sup (f := c) (Finset.mem_range.mpr hk) + · intro k hk t z + exact ((H k).1 t z).trans (by exact_mod_cast Finset.le_sup (f := C₂) (Finset.mem_range.mpr hk)) + · intro k hk t z + exact ((H k).2.1 t z).trans (by exact_mod_cast Finset.le_sup (f := C₃) (Finset.mem_range.mpr hk)) + · exact fun k => (H k).2.2.1 + · intro k hk t z + exact ((H k).2.2.2.1 t z).trans (by exact_mod_cast Finset.le_sup (f := Ct) (Finset.mem_range.mpr hk)) + · intro k hk r hr z + have hs : Icc (time h k:ℝ) (time h (k+1):ℝ) ⊆ Icc (0:ℝ) (time h (min (k+1) N):ℝ) := by + rw [Nat.min_eq_left (by omega : k+1 ≤ N)] + exact fun s hs => ⟨(time h k).coe_nonneg.trans hs.1,hs.2⟩ + exact ((H k).2.2.2.2.1 r (hs hr) z).mono hs + · intro k hk r hr s hs z y + have hsub : Icc (time h k:ℝ) (time h (k+1):ℝ) ⊆ Icc (0:ℝ) (time h (min (k+1) N):ℝ) := by + rw [Nat.min_eq_left (by omega : k+1 ≤ N)] + exact fun t ht => ⟨(time h k).coe_nonneg.trans ht.1,ht.2⟩ + exact ((H k).2.2.2.2.2.1 r (hsub hr) s (hsub hs) z y).trans (by + gcongr + exact_mod_cast Finset.le_sup (f := L) (Finset.mem_range.mpr hk)) + · intro k hk t ht z + apply (H k).2.2.2.2.2.2 t + rw [Nat.min_eq_left (by omega : k+1 ≤ N)] + exact ⟨(time h k).coe_nonneg.trans ht.1,ht.2⟩ + +theorem cascadeV_eq_control_sup {B : ℝ≥0 → Ω → ℝ} (hB : IsPreBrownianReal B P) + (hm : ∀ t, Measurable (B t)) {f : ℝ → ℝ} (hf : RegularDatum f) (hLip : LipschitzWith 1 f) + (h c : ℕ → ℝ≥0) (N : ℕ) (x : ℝ) : + cascadeV h c f N 0 x = sSup (objectives (P := P) hm h c f x N) := by + let sd := cellVHeat_gridData hf hLip h c N + have hend : cellVHeat h c f N N (time h N) = f := by + rw [cellVHeat_left hf hLip h c N N le_rfl] + simp [cascadeVAt,cascadeV] + have hstart : cellVHeat h c f N 0 0 x = cascadeV h c f N 0 x := by + have he := congrFun (cellVHeat_left hf hLip h c N 0 (Nat.zero_le N)) x + simpa only [time_zero,NNReal.coe_zero,cascadeVAt,Nat.sub_zero] using he + have hu : ∀ v ∈ objectives (P := P) hm h c f x N, v ≤ cascadeV h c f N 0 x := by + intro v hv + obtain ⟨α,hap,hab,hv⟩ := hv + rw [hv] + have hh := sd.control_upper hB hm hap hab x + change profit (P := P) B α h c (cellVHeat h c f N N (time h N)) x N ≤ + cellVHeat h c f N 0 0 x at hh + rwa [hend,hstart] at hh + have hb : BddAbove (objectives (P := P) hm h c f x N) := ⟨_,hu⟩ + apply le_antisymm + · apply le_of_forall_pos_le_add + intro ε hε + have hh := sd.control_lower hB hm x hε + change ∃ v ∈ objectives (P := P) hm h c (cellVHeat h c f N N (time h N)) x N, + cellVHeat h c f N 0 0 x-ε ≤ v at hh + rw [hend,hstart] at hh + obtain ⟨v,hv,hl⟩ := hh + have hs := le_csSup hb hv + linarith + · exact csSup_le (objectives_nonempty hm h c f x N) hu + +end ZeroTemperatureSK.Nonuniform + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKSupport/Density/Certificate.lean b/lean/OAI/Probability/SKSupport/Density/Certificate.lean new file mode 100644 index 0000000000000000000000000000000000000000..dee91f556e3552faa05e07e00dc98168a6ac6243 --- /dev/null +++ b/lean/OAI/Probability/SKSupport/Density/Certificate.lean @@ -0,0 +1,209 @@ +import Mathlib +import OAI.Probability.SKSupport.Model + +namespace OAI + +section +namespace ZeroTemperatureSK.Certificate +noncomputable section + +abbrev A : ℝ := 1 / 13 +abbrev C : ℝ := 53 / 24 +abbrev k : ℝ := 19 / 16 +abbrev T₀ : ℝ := 73 / 48 +abbrev g₀ : ℝ := 2331 / 10000 +abbrev h : ℝ := 87 / 2500 +abbrev x₀ : ℝ := 4663 / 5000 +abbrev y : ℝ := 6853 / 10000 +abbrev m : ℝ := -1051 / 400 +abbrev n₀ : ℝ := -1073 / 500 + +def Q (R K v b : ℝ) : ℝ := A * v * b + C * v ^ 2 + k * K * v - 2*k*R*b + T₀*R*v +def T (R v j : ℝ) : ℝ := g₀*R*v + h*j*v +def F₁ (R K v b j : ℝ) : ℝ := + b^2*(2*R*k-A*v) + b*(-2*K*k*v-R*g₀*v-2*R*T₀*v-2*C*v^2-h*j*v) +def F₂ (R K v b j : ℝ) : ℝ := x₀*v^2*j + y*v^3 + m*K*v^2 + n₀*R*v^2 - F₁ R K v b j + +def P₀ (R v b j : ℝ) : ℝ := R*j*(b-7*v)^2 +def P₁ (R v b B : ℝ) : ℝ := R*B*(b-7/3*v)^2 +def P₂ (K v b : ℝ) : ℝ := K*v*(b-9/2*v)^2 +def P₃ (R K v B : ℝ) : ℝ := v*B*(K+1/4*R-1/7*v)^2 +def P₄ (R K v b : ℝ) : ℝ := (v*b-14/5*v^2-13/4*K*v+4/3*R*v)^2 + +def weightedSquares (R K v b B j : ℝ) : ℝ := + 337/10000*P₀ R v b j + 183/2500*P₁ R v b B + 411/10000*P₂ K v b + + 11461/5000*P₃ R K v B + 647/10000*P₄ R K v b + +def remainder (R K v B j : ℝ) : ℝ := + 223/160000*R^2*v^2 + 4007/240000*R^2*v*B + 1097/120000*R^2*B^2 + + 83/80000*R*K*v^2 + 3343/24000*R*K*v*B + 16259/23400000*R*v^3 + + 30179/5460000*R*v^2*B + 26/625*R*v^2*j + 107/15000*R*v*B^2 + + 3/2500*R*v*B*j + 121/32500*R*B^3 + 11/10000*R*B^2*j + + 579/20000*K^2*v^2 + 207/2500*K^2*v*B + 911/975000*K*v^3 + + 349/420000*K*v^2*B + 5011/5000*K*v^2*j + 133/130000*K*v*B^2 + + 87/2500*K*v*B*j + 1661507/1521000000*v^4 + + 633799/621075000*v^3*B + 10657/1690000*v^2*B^2 + +def F₂R (_R _K v b _j : ℝ) : ℝ := n₀*v^2 - 2*k*b^2 + (g₀+2*T₀)*b*v +def F₂K (_R _K v b _j : ℝ) : ℝ := m*v^2 + 2*k*b*v +def F₂v (R K v b j : ℝ) : ℝ := + 2*x₀*v*j + 3*y*v^2 + 2*m*K*v + 2*n₀*R*v + A*b^2 + + b*(2*K*k + R*g₀ + 2*R*T₀ + 4*C*v + h*j) +def F₂b (R K v b j : ℝ) : ℝ := 2*Q R K v b + T R v j +def F₂j (_R _K v b _j : ℝ) : ℝ := x₀*v^2 + h*b*v + +def DF₂ (R K v b j z L : ℝ) : ℝ := + (2*R*v)*F₂R R K v b j + (2*v*K+R*j)*F₂K R K v b j + + (-R*b)*F₂v R K v b j + (-z-b*v)*F₂b R K v b j + + (-j*v+K*b-L)*F₂j R K v b j + +def WF₂ (R K v b j z L : ℝ) : ℝ := DF₂ R K v b j z L + (v+R-K)*F₂ R K v b j + +theorem rational_identity (R K v b j z L : ℝ) : + z^2 - 12*R*v*b^2 + 6*v^4 = + (z+Q R K v b)^2 + (z+b*v-2*R*b)*T R v j + + weightedSquares R K v b (b-2*v) j + WF₂ R K v b j z L + + L*(x₀*v^2+h*b*v) + remainder R K v (b-2*v) j := by + unfold Q T weightedSquares P₀ P₁ P₂ P₃ P₄ WF₂ DF₂ F₂R F₂K F₂v F₂b F₂j F₂ F₁ + unfold Q T remainder A C k T₀ g₀ h x₀ y m n₀ + ring + +theorem hasDerivAt_F₂ {R K v b j : ℝ → ℝ} {R' K' v' b' j' x : ℝ} + (hR : HasDerivAt R R' x) (hK : HasDerivAt K K' x) + (hv : HasDerivAt v v' x) (hb : HasDerivAt b b' x) (hj : HasDerivAt j j' x) : + HasDerivAt (fun t => F₂ (R t) (K t) (v t) (b t) (j t)) + (R' * F₂R (R x) (K x) (v x) (b x) (j x) + + K' * F₂K (R x) (K x) (v x) (b x) (j x) + + v' * F₂v (R x) (K x) (v x) (b x) (j x) + + b' * F₂b (R x) (K x) (v x) (b x) (j x) + + j' * F₂j (R x) (K x) (v x) (b x) (j x)) x := by + have hM := ((hR.const_mul 2).mul_const k).sub (hv.const_mul A) + have hN := ((((((hK.const_mul (-2)).mul_const k).mul hv).sub + ((hR.mul_const g₀).mul hv)).sub (((hR.const_mul 2).mul_const T₀).mul hv)).sub + ((hv.pow 2).const_mul (2*C))).sub ((hj.const_mul h).mul hv) + have hF₁ := ((hb.pow 2).mul hM).add (hb.mul hN) + have hF₂ := ((((((hv.pow 2).const_mul x₀).mul hj).add ((hv.pow 3).const_mul y)).add + ((hK.const_mul m).mul (hv.pow 2))).add ((hR.const_mul n₀).mul (hv.pow 2))).sub hF₁ + convert! hF₂ using 1 + simp only [F₂R, F₂K, F₂v, F₂b, F₂j, Q, T, + Pi.sub_apply, Pi.mul_apply, Pi.pow_apply] + ring + +theorem remainder_lower_bound {R K v B j : ℝ} + (hR : 0 ≤ R) (hK : 0 ≤ K) (hv : 0 ≤ v) (hB : 0 ≤ B) (hj : 0 ≤ j) : + (1661507 / 1521000000 : ℝ) * v^4 ≤ remainder R K v B j := by + unfold remainder + have hrest : 0 ≤ + 223/160000*R^2*v^2 + 4007/240000*R^2*v*B + 1097/120000*R^2*B^2 + + 83/80000*R*K*v^2 + 3343/24000*R*K*v*B + 16259/23400000*R*v^3 + + 30179/5460000*R*v^2*B + 26/625*R*v^2*j + 107/15000*R*v*B^2 + + 3/2500*R*v*B*j + 121/32500*R*B^3 + 11/10000*R*B^2*j + + 579/20000*K^2*v^2 + 207/2500*K^2*v*B + 911/975000*K*v^3 + + 349/420000*K*v^2*B + 5011/5000*K*v^2*j + 133/130000*K*v*B^2 + + 87/2500*K*v*B*j + 633799/621075000*v^3*B + 10657/1690000*v^2*B^2 := by + positivity + linarith only [hrest] + +theorem pointwise_coercivity {R K v b j z L : ℝ} + (hR : 0 ≤ R) (hK : 0 ≤ K) (hv : 0 ≤ v) (hj : 0 ≤ j) + (hB : 0 ≤ b - 2*v) (hL : 0 ≤ L) (hS : 0 ≤ z+b*v-2*R*b) : + (1661507 / 1521000000 : ℝ) * v^4 + WF₂ R K v b j z L ≤ + z^2 - 12*R*v*b^2 + 6*v^4 := by + have hb : 0 ≤ b := by linarith + have hT : 0 ≤ T R v j := by unfold T g₀ h; positivity + have hST : 0 ≤ (z+b*v-2*R*b)*T R v j := mul_nonneg hS hT + have hsq : 0 ≤ weightedSquares R K v b (b-2*v) j := by + unfold weightedSquares P₀ P₁ P₂ P₃ P₄ + positivity + have hcorr : 0 ≤ L*(x₀*v^2+h*b*v) := by unfold x₀ h; positivity + have hrem := remainder_lower_bound hR hK hv hB hj + have hid := rational_identity R K v b j z L + have hz : 0 ≤ (z+Q R K v b)^2 := sq_nonneg _ + linarith only [hST, hsq, hcorr, hrem, hid, hz] + +theorem coercivity_constant : (1 / 1000 : ℝ) < 1661507 / 1521000000 := by + norm_num + +theorem hasDerivAt_flux {r s ρ R K v b j : ℝ → ℝ} + {dR dK dv db dj z L x : ℝ} + (hr : HasDerivAt r (v x) x) + (hρ : HasDerivAt ρ ((r x - s x) * ρ x) x) + (hR : HasDerivAt R dR x) (hK : HasDerivAt K dK x) + (hv : HasDerivAt v dv x) (hb : HasDerivAt b db x) + (hj : HasDerivAt j dj x) + (hRval : R x = (r x)^2) (hKval : K x = r x * s x) + (hDR : r x*dR = 2*R x*v x) + (hDK : r x*dK = 2*v x*K x + R x*j x) + (hDv : r x*dv = -R x*b x) + (hDb : r x*db = -z-b x*v x) + (hDj : r x*dj = -j x*v x+K x*b x-L) : + HasDerivAt (fun t => r t * F₂ (R t) (K t) (v t) (b t) (j t) * ρ t) + (ρ x * WF₂ (R x) (K x) (v x) (b x) (j x) z L) x := by + have hF := hasDerivAt_F₂ hR hK hv hb hj + have hD : r x * (dR * F₂R (R x) (K x) (v x) (b x) (j x) + + dK * F₂K (R x) (K x) (v x) (b x) (j x) + + dv * F₂v (R x) (K x) (v x) (b x) (j x) + + db * F₂b (R x) (K x) (v x) (b x) (j x) + + dj * F₂j (R x) (K x) (v x) (b x) (j x)) = + DF₂ (R x) (K x) (v x) (b x) (j x) z L := by + calc + _ = (r x*dR) * F₂R (R x) (K x) (v x) (b x) (j x) + + (r x*dK) * F₂K (R x) (K x) (v x) (b x) (j x) + + (r x*dv) * F₂v (R x) (K x) (v x) (b x) (j x) + + (r x*db) * F₂b (R x) (K x) (v x) (b x) (j x) + + (r x*dj) * F₂j (R x) (K x) (v x) (b x) (j x) := by ring + _ = _ := by rw [hDR, hDK, hDv, hDb, hDj]; rfl + convert! (hr.mul hF).mul hρ using 1 + simp only [Pi.mul_apply] + unfold WF₂ + rw [← hD, hRval, hKval] + ring + +open MeasureTheory Filter +open scoped Topology + +theorem integrated_coercivity_of_flux {r ρ R K v b j z L : ℝ → ℝ} + (hρ : ∀ x, 0 ≤ ρ x) + (hR : ∀ x, 0 ≤ R x) (hK : ∀ x, 0 ≤ K x) (hv : ∀ x, 0 ≤ v x) + (hj : ∀ x, 0 ≤ j x) (hB : ∀ x, 0 ≤ b x - 2*v x) + (hL : ∀ x, 0 ≤ L x) (hS : ∀ x, 0 ≤ z x+b x*v x-2*R x*b x) + (hderiv : ∀ x, HasDerivAt + (fun t => r t * F₂ (R t) (K t) (v t) (b t) (j t) * ρ t) + (ρ x * WF₂ (R x) (K x) (v x) (b x) (j x) (z x) (L x)) x) + (hbot : Tendsto (fun t => r t * F₂ (R t) (K t) (v t) (b t) (j t) * ρ t) + atBot (𝓝 0)) + (htop : Tendsto (fun t => r t * F₂ (R t) (K t) (v t) (b t) (j t) * ρ t) + atTop (𝓝 0)) + (hv4 : Integrable (fun t => ρ t * (v t)^4)) + (hW : Integrable (fun t => ρ t * WF₂ (R t) (K t) (v t) (b t) (j t) (z t) (L t))) + (hI : Integrable (fun t => ρ t * ((z t)^2-12*R t*v t*(b t)^2+6*(v t)^4))) : + (1661507 / 1521000000 : ℝ) * (∫ t, ρ t * (v t)^4) ≤ + ∫ t, ρ t * ((z t)^2-12*R t*v t*(b t)^2+6*(v t)^4) := by + have hzero : (∫ t, ρ t * WF₂ (R t) (K t) (v t) (b t) (j t) (z t) (L t)) = 0 := by + simpa using integral_of_hasDerivAt_of_tendsto hderiv hW hbot htop + have hpoint : ∀ t, (1661507 / 1521000000 : ℝ) * (ρ t * (v t)^4) + + ρ t * WF₂ (R t) (K t) (v t) (b t) (j t) (z t) (L t) ≤ + ρ t * ((z t)^2-12*R t*v t*(b t)^2+6*(v t)^4) := by + intro t + have hh := mul_le_mul_of_nonneg_left + (pointwise_coercivity (hR t) (hK t) (hv t) (hj t) (hB t) (hL t) (hS t)) (hρ t) + nlinarith only [hh] + have hint := integral_mono ((hv4.const_mul _).add hW) hI hpoint + simp only [Pi.add_apply] at hint + rw [integral_add (hv4.const_mul _) hW, integral_const_mul, hzero, add_zero] at hint + exact hint + +theorem coercivity_constant_integral {ρ v : ℝ → ℝ} (hρ : ∀ t, 0 ≤ ρ t) : + (1 / 1000 : ℝ) * (∫ t, ρ t * (v t)^4) ≤ + (1661507 / 1521000000 : ℝ) * (∫ t, ρ t * (v t)^4) := by + apply mul_le_mul_of_nonneg_right (le_of_lt coercivity_constant) + apply integral_nonneg + intro t + exact mul_nonneg (hρ t) (pow_nonneg (sq_nonneg (v t)) 2) |>.trans_eq (by ring) + +end +end ZeroTemperatureSK.Certificate + +end + +end OAI diff --git a/lean/OAI/Probability/SKSupport/Density/CoerciveMoments.lean b/lean/OAI/Probability/SKSupport/Density/CoerciveMoments.lean new file mode 100644 index 0000000000000000000000000000000000000000..0ea14e99733621894e47c0128fa286bce92fcf1f --- /dev/null +++ b/lean/OAI/Probability/SKSupport/Density/CoerciveMoments.lean @@ -0,0 +1,148 @@ +import Mathlib +import OAI.Probability.SKSupport.Diffusion.FiniteFeedback +import OAI.Probability.SKSupport.Regularity.PositiveRegularity +import OAI.Probability.SKSupport.Density.GaussianLogDensity + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology ContDiff +noncomputable section +namespace ZeroTemperatureSK +open Heat + +def coerciveJetPolynomial (c A B C : ℝ) : ℝ := c^2*C^2-12*c^3*A*B^2+6*c^4*A^4 + +def quarticJetPolynomial (c A : ℝ) : ℝ := c^4*A^4 + +lemma quarticMoment_scaled {f : ℝ → ℝ} (hf : ContDiff ℝ ∞ f) (c x : ℝ) : + quarticMoment (fun y => c*deriv f y) x=quarticJetPolynomial c (iteratedDeriv 2 f x) := by + have hd := contDiff_infty_iff_deriv.mp hf |>.2 + have he := scaled_jet hd c 1 x + simp only [iteratedDeriv_one] at he + simp only [quarticMoment,certV,he,quarticJetPolynomial,iteratedDeriv_succ,iteratedDeriv_zero] + ring + +lemma coercivePolynomial_scaled {f : ℝ → ℝ} (hf : ContDiff ℝ ∞ f) (c x : ℝ) : + coercivePolynomial (fun y => c*deriv f y) x=coerciveJetPolynomial c + (iteratedDeriv 2 f x) (iteratedDeriv 3 f x) (iteratedDeriv 4 f x) := by + have hd := contDiff_infty_iff_deriv.mp hf |>.2 + have he := scaled_jet hd c 1 x + simp only [iteratedDeriv_one] at he + simp only [coercivePolynomial,certV,certW,certZ,he,scaled_jet hd, + coerciveJetPolynomial,iteratedDeriv_succ,iteratedDeriv_zero] + ring + +lemma quarticJetPolynomial_bound {c A D E : ℝ} (hc : |c| ≤ D) (hA : |A| ≤ E) : + |quarticJetPolynomial c A| ≤ D^4*E^4 := by + simp only [quarticJetPolynomial,abs_mul,abs_pow] + exact mul_le_mul (pow_le_pow_left₀ (abs_nonneg _) hc 4) (pow_le_pow_left₀ (abs_nonneg _) hA 4) + (by positivity) (by positivity) + +lemma coerciveJetPolynomial_bound {c A B C D E F G : ℝ} + (hc : |c| ≤ D) (hA : |A| ≤ E) (hB : |B| ≤ F) (hC : |C| ≤ G) : + |coerciveJetPolynomial c A B C| ≤ D^2*G^2+12*D^3*E*F^2+6*D^4*E^4 := by + have hD : 0 ≤ D := (abs_nonneg _).trans hc + have hE : 0 ≤ E := (abs_nonneg _).trans hA + have hF : 0 ≤ F := (abs_nonneg _).trans hB + have hG : 0 ≤ G := (abs_nonneg _).trans hC + have h1 : |c^2*C^2| ≤ D^2*G^2 := by + simp only [abs_mul,abs_pow] + exact mul_le_mul (pow_le_pow_left₀ (abs_nonneg _) hc 2) (pow_le_pow_left₀ (abs_nonneg _) hC 2) (by positivity) (by positivity) + have h2 : |12*c^3*A*B^2| ≤ 12*D^3*E*F^2 := by + simp only [abs_mul,abs_pow,abs_of_nonneg (by norm_num : (0:ℝ) ≤ 12)] + exact mul_le_mul (mul_le_mul (mul_le_mul_of_nonneg_left (pow_le_pow_left₀ (abs_nonneg _) hc 3) (by norm_num)) hA (abs_nonneg _) (by positivity)) + (pow_le_pow_left₀ (abs_nonneg _) hB 2) (by positivity) (by positivity) + have h3 : |6*c^4*A^4| ≤ 6*D^4*E^4 := by + simp only [abs_mul,abs_pow,abs_of_nonneg (by norm_num : (0:ℝ) ≤ 6)] + exact mul_le_mul (mul_le_mul_of_nonneg_left (pow_le_pow_left₀ (abs_nonneg _) hc 4) (by norm_num)) + (pow_le_pow_left₀ (abs_nonneg _) hA 4) (by positivity) (by positivity) + exact (abs_add_le _ _).trans (add_le_add ((abs_sub _ _).trans (add_le_add h1 h2)) h3) + +end ZeroTemperatureSK + +end +end +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology ContDiff +noncomputable section +namespace ZeroTemperatureSK +open Heat + +def sampleIndex (n : ℕ) (t : Time) : ℕ := ⌊(t:ℝ)/(approxMesh n:ℝ)⌋₊ + +def sampleNNTime (n : ℕ) (t : Time) : ℝ≥0 := (sampleIndex n t:ℝ≥0)*approxMesh n + +lemma sampleIndex_lt (n : ℕ) (t : Time) : sampleIndex n t < n+1 := by + unfold sampleIndex + rw [Nat.floor_lt (div_nonneg t.property.1 (approxMesh n).coe_nonneg),div_lt_iff₀ (by exact_mod_cast approxMesh_pos n),approxMesh_horizon] + exact t.property.2 + +lemma sampleNNTime_le (n : ℕ) (t : Time) : (sampleNNTime n t:ℝ) ≤ t := by + have hh := Nat.floor_le (div_nonneg t.property.1 (approxMesh n).coe_nonneg) + rw [le_div_iff₀ (by exact_mod_cast approxMesh_pos n)] at hh + exact hh + +lemma sampleNNTime_lower (n : ℕ) (t : Time) : (t:ℝ)-(approxMesh n:ℝ) < sampleNNTime n t := by + have hh := Nat.lt_floor_add_one ((t:ℝ)/(approxMesh n:ℝ)) + rw [div_lt_iff₀ (by exact_mod_cast approxMesh_pos n)] at hh + change (t:ℝ)-(approxMesh n:ℝ) < (sampleIndex n t:ℝ)*(approxMesh n:ℝ) + dsimp only [sampleIndex] + nlinarith + +def sampleTime (n : ℕ) (t : Time) : Time := + ⟨sampleNNTime n t,⟨(sampleNNTime n t).coe_nonneg,(sampleNNTime_le n t).trans_lt t.property.2⟩⟩ + +lemma sampleTime_limit (t : Time) : Tendsto (fun n => sampleTime n t) atTop (𝓝 t) := by + apply tendsto_subtype_rng.mpr + apply tendsto_of_tendsto_of_tendsto_of_le_of_le + (show Tendsto (fun n => (t:ℝ)-(approxMesh n:ℝ)) atTop (𝓝 (t:ℝ)) by + simpa only [sub_zero] using tendsto_const_nhds.sub approxMesh_limit) tendsto_const_nhds + (fun n => (sampleNNTime_lower n t).le) (fun n => sampleNNTime_le n t) + +lemma sampleNNTime_limit (t : Time) : Tendsto (fun n => sampleNNTime n t) atTop (𝓝 (⟨t,t.property.1⟩:ℝ≥0)) := by + apply tendsto_subtype_rng.mpr + exact (continuous_subtype_val.tendsto t).comp (sampleTime_limit t) + +lemma sampleIndex_pos_eventually (t : Time) (ht : 0 < (t:ℝ)) : ∀ᶠ n in atTop, 0 < sampleIndex n t := by + filter_upwards [approxMesh_limit.eventually (gt_mem_nhds ht)] with n hn + rw [sampleIndex,Nat.floor_pos,le_div_iff₀ (by exact_mod_cast approxMesh_pos n)] + simpa only [one_mul] using hn.le + +lemma positiveCoeff_sample_eq (γ : OrderParameter) (n : ℕ) (t : Time) : + (positiveCoeff γ n (sampleIndex n t):ℝ)=γ.val (sampleTime n t)+(approxMesh n:ℝ) := by + unfold positiveCoeff + rw [min_eq_left (by have := sampleIndex_lt n t;omega),NNReal.coe_add,approxCoeff_eq γ n _ (sampleIndex_lt n t)] + rfl + +lemma positiveCoeff_sample_limit (γ : OrderParameter) (t : Time) (ht : ContinuousAt γ.val t) : + Tendsto (fun n => (positiveCoeff γ n (sampleIndex n t):ℝ)) atTop (𝓝 (γ.val t)) := by + simp_rw [positiveCoeff_sample_eq] + simpa only [add_zero,Function.comp_apply] using (ht.tendsto.comp (sampleTime_limit t)).add approxMesh_limit + +lemma positiveCoeff_sample_bound (γ : OrderParameter) (n : ℕ) (t : Time) : + (positiveCoeff γ n (sampleIndex n t):ℝ) ≤ γ.val t+1 := by + rw [positiveCoeff_sample_eq] + apply add_le_add (γ.monotone (sampleNNTime_le n t)) + unfold approxMesh + simp only [NNReal.coe_inv,NNReal.coe_natCast] + exact inv_le_one_of_one_le₀ (by exact_mod_cast Nat.succ_le_succ (Nat.zero_le n)) + +lemma positiveValue_sample (γ : OrderParameter) (n : ℕ) (t : Time) : + positiveValue γ n (sampleTime n t)=backwardBoundary (positiveCoeff γ n) (approxMesh n) + (softAbs (positiveTerminal γ n)) (n+1) (sampleIndex n t) := by + have hf := regularDatum_softAbs (ne_of_gt (positiveTerminal_pos γ n)) + have hLip := softAbs_lipschitz (ne_of_gt (positiveTerminal_pos γ n)) + have hh := finiteValue_shift hf hLip (positiveCoeff γ n) (approxMesh n) + ((sampleIndex_lt n t).le) 0 (le_refl (0:ℝ)) + simp only [add_zero,Nat.zero_add,finiteValue_zero hf hLip] at hh + exact hh + +end ZeroTemperatureSK + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKSupport/Density/DensityFubini.lean b/lean/OAI/Probability/SKSupport/Density/DensityFubini.lean new file mode 100644 index 0000000000000000000000000000000000000000..eca2a473de9aadd93f33a289b55a573646c8cd51 --- /dev/null +++ b/lean/OAI/Probability/SKSupport/Density/DensityFubini.lean @@ -0,0 +1,163 @@ +import Mathlib +import OAI.Probability.SKSupport.Diffusion.FiniteTransition +import OAI.Probability.SKSupport.Density.DensityHeat +import OAI.Probability.SKSupport.Density.GaussianDecay + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section +namespace ZeroTemperatureSK.Heat + +lemma heatKernel_even (t x : ℝ) : heatKernel t (-x)=heatKernel t x := by + simp only [heatKernel,gaussianPDFReal,sub_zero,neg_sq] + +lemma heatKernel_measurable (t : ℝ) : Measurable (heatKernel t) := measurable_gaussianPDFReal 0 _ + +lemma integrable_gaussian_heat_product {f g : ℝ → ℝ} (hfm : Measurable f) (hgm : Measurable g) + (hf : ExponentialBound f) (hg : ExponentialBound g) {a t : ℝ} (ha : 0 < a) (ht : 0 < t) : + Integrable (fun p : ℝ × ℝ => Real.exp (-p.1^2/(2*a))*f p.1*heatKernel t (p.2-p.1)*g p.2) + (volume.prod volume) := by + obtain ⟨A,K,hA⟩ := hf + obtain ⟨B,J,hB⟩ := hg + let d := 1/(8*(a+t)) + have hd : 0 < d := by dsimp [d];positivity + have hmajor := ((integrable_gaussian_linear hd K).mul_prod (integrable_gaussian_linear hd J)).const_mul + ((A:ℝ)*(B:ℝ)*(Real.sqrt (2*Real.pi*t))⁻¹) + apply hmajor.mono' + · exact ((((measurable_id.fst.pow_const 2).neg.div_const (2*a)).exp.mul (hfm.comp measurable_fst)).mul + ((heatKernel_measurable t).comp (measurable_snd.sub measurable_fst)) |>.mul (hgm.comp measurable_snd)).aestronglyMeasurable + · filter_upwards [] with p + simp only [Real.norm_eq_abs,abs_mul,abs_of_pos (Real.exp_pos _),abs_of_pos (heatKernel_pos ht _)] + have he := gaussian_convolution_quadratic ha ht p.1 p.2 + change d*(p.1^2+p.2^2) ≤ _ at he + have hk := (heatKernel_pos ht (p.2-p.1)).le + calc + Real.exp (-p.1^2/(2*a))*|f p.1| * heatKernel t (p.2-p.1)*|g p.2| ≤ + Real.exp (-p.1^2/(2*a))*((A:ℝ)*Real.exp ((K:ℝ)*|p.1|))*heatKernel t (p.2-p.1)* + ((B:ℝ)*Real.exp ((J:ℝ)*|p.2|)) := by + apply mul_le_mul _ (hB p.2) (abs_nonneg _) (by positivity) + exact mul_le_mul_of_nonneg_right + (mul_le_mul_of_nonneg_left (hA p.1) (Real.exp_nonneg _)) hk + _ = ((A:ℝ)*(B:ℝ)*(Real.sqrt (2*Real.pi*t))⁻¹)* + Real.exp (-p.1^2/(2*a)-(p.2-p.1)^2/(2*t)+(K:ℝ)*|p.1|+(J:ℝ)*|p.2|) := by + rw [heatKernel_formula ht.le] + simp only [sub_eq_add_neg,neg_div,Real.exp_add] + ring + _ ≤ ((A:ℝ)*(B:ℝ)*(Real.sqrt (2*Real.pi*t))⁻¹)* + Real.exp ((-d*p.1^2+(K:ℝ)*|p.1|)+(-d*p.2^2+(J:ℝ)*|p.2|)) := by + apply mul_le_mul_of_nonneg_left _ (by positivity) + apply Real.exp_le_exp.mpr + simp only [neg_div] + nlinarith only [he] + _ = _ := by rw [Real.exp_add] + +lemma gaussian_heat_pairing {f g : ℝ → ℝ} (hfm : Measurable f) (hgm : Measurable g) + (hf : ExponentialBound f) (hg : ExponentialBound g) {a t : ℝ} (ha : 0 < a) (ht : 0 < t) : + (∫ x, (Real.exp (-x^2/(2*a))*f x)*varianceHeat t g x) = + ∫ y, varianceHeat t (fun x => Real.exp (-x^2/(2*a))*f x) y*g y := by + have hprod := integrable_gaussian_heat_product hfm hgm hf hg ha ht + have hwm : Measurable (fun x : ℝ => Real.exp (-x^2/(2*a))*f x) := by fun_prop + calc + _ = ∫ x, ∫ y, Real.exp (-x^2/(2*a))*f x*heatKernel t (y-x)*g y := by + apply integral_congr_ae + filter_upwards [] with x + rw [varianceHeat_kernel hgm ht,← integral_const_mul] + apply integral_congr_ae + filter_upwards [] with y + ring + _ = ∫ y, ∫ x, Real.exp (-x^2/(2*a))*f x*heatKernel t (y-x)*g y := + integral_integral_swap hprod + _ = _ := by + apply integral_congr_ae + filter_upwards [] with y + rw [varianceHeat_kernel hwm ht,← integral_mul_const] + apply integral_congr_ae + filter_upwards [] with x + rw [show y-x=-(x-y) by ring,heatKernel_even] + ring + +lemma gaussian_heat_forward_pairing {L g : ℝ → ℝ} {K : ℝ≥0} (hL : LipschitzWith K L) + (hgm : Measurable g) (hg : ExponentialBound g) {a t : ℝ} (ha : 0 < a) (ht : 0 < t) : + (∫ x, Real.exp (-x^2/(2*a)+L x)*varianceHeat t g x) = + ∫ y, Real.exp (-y^2/(2*(a+t))+forwardCorrection a L t y)*g y := by + have hf := exponentialBound_exp hL 1 + simp only [one_mul] at hf + have hh := gaussian_heat_pairing hL.continuous.measurable.exp hgm hf hg ha ht + have he : (fun x : ℝ => Real.exp (-x^2/(2*a))*Real.exp (L x))= + fun x => Real.exp (-x^2/(2*a)+L x) := by funext x;rw [Real.exp_add] + simp_rw [he,varianceHeat_gaussian_forwardCorrection hL ha ht] at hh + simpa only [Real.exp_add] using hh + +end ZeroTemperatureSK.Heat + +end +end +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section +namespace ZeroTemperatureSK.Heat + +lemma density_tilted_pairing {L f g : ℝ → ℝ} {K J : ℝ≥0} + (hL : LipschitzWith K L) (hf : LipschitzWith J f) (hg : BoundedSmooth g) + {a t c : ℝ} (ha : 0 < a) (ht : 0 < t) (hc : c ≠ 0) : + (∫ x, Real.exp (c*varianceLogHeat c t f x-x^2/(2*a)+L x)*varianceTilted c t f g x)= + ∫ y, Real.exp (c*f y-y^2/(2*(a+t))+forwardCorrection a L t y)*g y := by + obtain ⟨G,hG⟩ := hg.bound + have hwm : Measurable (fun y => g y*Real.exp (c*f y)) := by + exact hg.smooth.continuous.measurable.mul ((measurable_const.mul hf.continuous.measurable).exp) + have hw := (exponentialBound_exp hf c).bdd_mul hG + calc + _ = ∫ x, Real.exp (-x^2/(2*a)+L x)*varianceHeat t (fun y => g y*Real.exp (c*f y)) x := by + apply integral_congr_ae + filter_upwards [] with x + rw [show c*varianceLogHeat c t f x-x^2/(2*a)+L x= + (-x^2/(2*a)+L x)+c*varianceLogHeat c t f x by ring] + rw [Real.exp_add,exp_varianceLogHeat hf hc] + unfold varianceTilted + field_simp [ne_of_gt (varianceHeat_exp_pos hf c t x)] + _ = ∫ y, Real.exp (-y^2/(2*(a+t))+forwardCorrection a L t y)* + (g y*Real.exp (c*f y)) := gaussian_heat_forward_pairing hL hwm hw ha ht + _ = _ := by + apply integral_congr_ae + filter_upwards [] with y + simp only [sub_eq_add_neg,neg_div,Real.exp_add] + ring + +def finiteDensity (c : ℕ → ℝ≥0) (h : ℝ≥0) (f : ℝ → ℝ) (N i : ℕ) (x : ℝ) : ℝ := + Real.exp ((c i:ℝ)*backwardBoundary c h f N i x-x^2/(2*((i:ℝ)*h))+ + forwardBoundary c h f N i x) + +lemma finiteDensity_step_pairing {f g : ℝ → ℝ} (hf : RegularDatum f) (hLip : LipschitzWith 1 f) + (hg : BoundedSmooth g) (c : ℕ → ℝ≥0) (hc : ∀ i, 0 < (c i:ℝ)) + {h : ℝ≥0} (hh : 0 < (h:ℝ)) {N i : ℕ} (hi : 0 < i) (hiN : i < N) : + (∫ x, finiteDensity c h f N i x*varianceTilted (c i) h (backwardBoundary c h f N (i+1)) g x)= + ∫ y, finiteDensity c h f N (i+1) y*g y := by + obtain ⟨K,hK⟩ := (forwardBoundary_regular hf hLip c hh N i).exists_lipschitz + have he := density_tilted_pairing hK (cascade_lipschitz hLip c h (N-(i+1)) (i+1)) hg + (mul_pos (Nat.cast_pos.mpr hi) hh) hh (ne_of_gt (hc i)) + change (∫ x, Real.exp ((c i:ℝ)*varianceLogHeat (c i) h (backwardBoundary c h f N (i+1)) x- + x^2/(2*((i:ℝ)*h))+forwardBoundary c h f N i x)*_) = _ at he + rw [backwardBoundary_step hf hLip c h hiN] at he + change (∫ x, finiteDensity c h f N i x*_) = _ at he + refine he.trans ?_ + apply integral_congr_ae + filter_upwards [] with y + congr 1 + unfold finiteDensity + rw [forwardBoundary] + dsimp only + rw [ite_eq_right (Nat.ne_of_gt hi)] + congr 1 + simp only [backwardBoundary,Nat.cast_add,Nat.cast_one] + ring + +end ZeroTemperatureSK.Heat + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKSupport/Density/DensityHeat.lean b/lean/OAI/Probability/SKSupport/Density/DensityHeat.lean new file mode 100644 index 0000000000000000000000000000000000000000..3e15fe5a50adbd21b46b69c62a4dc14b68110218 --- /dev/null +++ b/lean/OAI/Probability/SKSupport/Density/DensityHeat.lean @@ -0,0 +1,193 @@ +import Mathlib +import OAI.Probability.SKSupport.Parabolic.ForwardGeometry + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section +namespace ZeroTemperatureSK.Heat + +def heatKernel (t x : ℝ) := gaussianPDFReal 0 (Real.toNNReal t) x + +lemma heatKernel_formula {t : ℝ} (ht : 0 ≤ t) (x : ℝ) : + heatKernel t x=(Real.sqrt (2*Real.pi*t))⁻¹*Real.exp (-x^2/(2*t)) := by + simp only [heatKernel,gaussianPDFReal,Real.coe_toNNReal _ ht,sub_zero] + +lemma heatKernel_pos {t : ℝ} (ht : 0 < t) (x : ℝ) : 0 < heatKernel t x := + gaussianPDFReal_pos 0 _ x (ne_of_gt (Real.toNNReal_pos.mpr ht)) + +lemma varianceHeat_kernel {g : ℝ → ℝ} (hg : Measurable g) {t : ℝ} (ht : 0 < t) (x : ℝ) : + varianceHeat t g x=∫ y, heatKernel t (y-x)*g y := by + rw [varianceHeat_eq_semigroup_toNNReal hg] + unfold semigroup + rw [integral_gaussianReal_eq_integral_smul (ne_of_gt (Real.toNNReal_pos.mpr ht))] + rw [← integral_add_left_eq_self (fun y => heatKernel t (y-x)*g y) x] + apply integral_congr_ae + filter_upwards [] with y + simp only [heatKernel,smul_eq_mul,add_sub_cancel_left] + +lemma heatKernel_complete_square {a t : ℝ} (ha : 0 < a) (ht : 0 < t) (x y : ℝ) : + heatKernel t (y-x)*Real.exp (-y^2/(2*a)) = + Real.sqrt (a/(a+t))*Real.exp (-x^2/(2*(a+t)))* + heatKernel (a*t/(a+t)) (y-a/(a+t)*x) := by + have hs := add_pos ha ht + have hv : 0 < a*t/(a+t) := div_pos (mul_pos ha ht) hs + have hscale : 0 < a/(a+t) := div_pos ha hs + have he : -(y-x)^2/(2*t)+ -y^2/(2*a)= + -x^2/(2*(a+t))+ -(y-a/(a+t)*x)^2/(2*(a*t/(a+t))) := by + field_simp [ne_of_gt ha,ne_of_gt ht,ne_of_gt hs] + ring + have hroot : Real.sqrt (2*Real.pi*(a*t/(a+t))) = + Real.sqrt (a/(a+t))*Real.sqrt (2*Real.pi*t) := by + rw [← Real.sqrt_mul hscale.le] + congr 1 + ring + have hn : (Real.sqrt (2*Real.pi*t))⁻¹ = + Real.sqrt (a/(a+t))*(Real.sqrt (2*Real.pi*(a*t/(a+t))))⁻¹ := by + rw [hroot,mul_inv_rev] + field_simp [ne_of_gt (Real.sqrt_pos.mpr hscale)] + rw [heatKernel_formula ht.le,heatKernel_formula hv.le] + rw [mul_assoc,← Real.exp_add,he,Real.exp_add,hn] + ring + +lemma varianceHeat_gaussian_weight {L : ℝ → ℝ} (hL : Measurable L) + {a t : ℝ} (ha : 0 < a) (ht : 0 < t) (x : ℝ) : + varianceHeat t (fun y => Real.exp (-y^2/(2*a)+L y)) x = + Real.sqrt (a/(a+t))*Real.exp (-x^2/(2*(a+t)))* + varianceHeat (a*t/(a+t)) (fun y => Real.exp (L y)) (a/(a+t)*x) := by + have hm : Measurable (fun y : ℝ => Real.exp (-y^2/(2*a)+L y)) := by fun_prop + rw [varianceHeat_kernel hm ht,varianceHeat_kernel hL.exp (div_pos (mul_pos ha ht) (add_pos ha ht))] + rw [← integral_const_mul] + apply integral_congr_ae + filter_upwards [] with y + rw [Real.exp_add,← mul_assoc,heatKernel_complete_square ha ht] + ring + +lemma exp_varianceLogHeat_one {L : ℝ → ℝ} {K : ℝ≥0} (hL : LipschitzWith K L) (t x : ℝ) : + Real.exp (varianceLogHeat 1 t L x)=varianceHeat t (fun y => Real.exp (L y)) x := by + simp only [varianceLogHeat,one_ne_zero,ite_false,div_one,one_mul] + exact Real.exp_log (by simpa only [one_mul] using varianceHeat_exp_pos hL 1 t x) + +lemma exp_half_log {x : ℝ} (hx : 0 < x) : Real.exp ((1/2:ℝ)*Real.log x)=Real.sqrt x := by + apply (sq_eq_sq₀ (Real.exp_nonneg _) (Real.sqrt_nonneg _)).mp + rw [Real.sq_sqrt hx.le,← Real.exp_nat_mul] + norm_num only [Nat.cast_ofNat] + rw [show (2:ℝ)*((1/2)*Real.log x)=Real.log x by ring,Real.exp_log hx] + +lemma varianceHeat_gaussian_forwardCorrection {L : ℝ → ℝ} {K : ℝ≥0} + (hL : LipschitzWith K L) {a t : ℝ} (ha : 0 < a) (ht : 0 < t) (x : ℝ) : + varianceHeat t (fun y => Real.exp (-y^2/(2*a)+L y)) x = + Real.exp (-x^2/(2*(a+t))+forwardCorrection a L t x) := by + rw [varianceHeat_gaussian_weight hL.continuous.measurable ha ht] + simp only [forwardCorrection,forwardVariance,forwardScale,forwardTime,max_eq_left ht.le] + rw [Real.exp_add,Real.exp_add,exp_varianceLogHeat_one hL,exp_half_log (div_pos ha (add_pos ha ht))] + ring + +end ZeroTemperatureSK.Heat + +end +end +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section +namespace ZeroTemperatureSK.Heat + +lemma heatKernel_uniform_lower {δ h x y : ℝ} (hδ : 0 < δ) (hδh : δ ≤ h) (hh : h ≤ 1) + (hx : |x| ≤ 1) (hy : |y| ≤ 1) : + (Real.sqrt (2*Real.pi))⁻¹*Real.exp (-2/δ) ≤ heatKernel h (y-x) := by + have hh0 := hδ.trans_le hδh + have hz : |y-x| ≤ 2 := (abs_sub y x).trans (by linarith) + have hz2 : (y-x)^2 ≤ 4 := by + have hh := (sq_le_sq₀ (abs_nonneg (y-x)) (show (0:ℝ) ≤ 2 by norm_num)).mpr hz + simpa only [sq_abs,show (2:ℝ)^2=4 by norm_num] using hh + rw [heatKernel_formula hh0.le] + apply mul_le_mul + · apply inv_anti₀ (by positivity) + apply Real.sqrt_le_sqrt + nlinarith [Real.pi_pos] + · apply Real.exp_le_exp.mpr + have hq : (y-x)^2/(2*h) ≤ 2/δ := by + apply (div_le_div_iff₀ (by positivity : 0 < 2*h) hδ).mpr + nlinarith + simpa only [neg_div] using neg_le_neg hq + · positivity + · positivity + +lemma integrable_weighted_heatKernel {f g : ℝ → ℝ} {K : ℝ≥0} + (hf : LipschitzWith K f) (hg : BoundedSmooth g) (c : ℝ) {h : ℝ} (hh : 0 < h) (x : ℝ) : + Integrable (fun y => heatKernel h (y-x)*(g y*Real.exp (c*f y))) := by + obtain ⟨G,hG⟩ := hg.bound + have hi := integrable_weight_exp_translate hf hg.smooth.continuous.measurable hG c (Real.toNNReal h) x + rw [gaussianReal_of_var_ne_zero _ (ne_of_gt (Real.toNNReal_pos.mpr hh))] at hi + have hj := (integrable_withDensity_iff_integrable_smul' (measurable_gaussianPDF 0 (Real.toNNReal h)) + (Eventually.of_forall (fun y => gaussianPDF_lt_top))).mp hi + simp only [gaussianPDF,ENNReal.toReal_ofReal (gaussianPDFReal_nonneg _ _ _),smul_eq_mul] at hj + have hk := hj.comp_add_left (-x) + apply hk.congr + filter_upwards [] with y + simp only [← add_assoc,add_neg_cancel,zero_add] + rw [show -x+y=y-x by ring] + rfl + +lemma varianceHeat_exp_eq_exp_log {f : ℝ → ℝ} {K : ℝ≥0} (hf : LipschitzWith K f) + (c h x : ℝ) : varianceHeat h (fun y => Real.exp (c*f y)) x=Real.exp (c*varianceLogHeat c h f x) := by + by_cases hc : c=0 + · subst c + simp only [zero_mul,Real.exp_zero] + unfold varianceHeat scaled + simp + · unfold varianceLogHeat + rw [ite_eq_right hc] + rw [mul_div_cancel₀ _ hc,Real.exp_log (varianceHeat_exp_pos hf c h x)] + +lemma varianceTilted_lower_window {f g : ℝ → ℝ} {K : ℝ≥0} + (hf : LipschitzWith K f) (hg : BoundedSmooth g) {c δ h r x M : ℝ} + (hc : 0 ≤ c) (hf0 : ∀ y, 0 ≤ f y) (hg0 : ∀ y, 0 ≤ g y) + (hδ : 0 < δ) (hδh : δ ≤ h) (hh1 : h ≤ 1) (hr0 : 0 ≤ r) (hr1 : r ≤ 1) + (hx : |x| ≤ 1) (hgwin : ∀ y, |y| ≤ r → 3/4 ≤ g y) + (hden : varianceHeat h (fun y => Real.exp (c*f y)) x ≤ M) : + ((3/2:ℝ)*(Real.sqrt (2*Real.pi))⁻¹*Real.exp (-2/δ)*r)/M ≤ varianceTilted c h f g x := by + have hh0 := hδ.trans_le hδh + have hM : 0 < M := (varianceHeat_exp_pos hf c h x).trans_le hden + let k : ℝ := (Real.sqrt (2*Real.pi))⁻¹*Real.exp (-2/δ) + have hk : 0 ≤ k := by dsimp [k];positivity + have hi := integrable_weighted_heatKernel hf hg c hh0 x + have hnon (y : ℝ) : 0 ≤ heatKernel h (y-x)*(g y*Real.exp (c*f y)) := + mul_nonneg (heatKernel_pos hh0 _).le (mul_nonneg (hg0 y) (Real.exp_nonneg _)) + have hlower : (3/4:ℝ)*k*(2*r) ≤ ∫ y, heatKernel h (y-x)*(g y*Real.exp (c*f y)) := by + have hm := setIntegral_mono_on (f := fun _ => (3/4:ℝ)*k) + (s := Icc (-r) r) (integrableOn_const measure_Icc_lt_top.ne) hi.integrableOn measurableSet_Icc + (fun y hy => by + have hab : |y| ≤ r := abs_le.mpr hy + have hw := heatKernel_uniform_lower hδ hδh hh1 hx (hab.trans hr1) + have hg' := hgwin y hab + have hex : 1 ≤ Real.exp (c*f y) := Real.one_le_exp_iff.mpr (mul_nonneg hc (hf0 y)) + have hge : (3/4:ℝ) ≤ g y*Real.exp (c*f y) := le_trans hg' (by nlinarith [hg0 y]) + change (3/4:ℝ)*k ≤ _ + rw [mul_comm (3/4:ℝ)] + exact mul_le_mul hw hge (by norm_num) (heatKernel_pos hh0 _).le) + have hs : ∫ _y in Icc (-r) r, (3/4:ℝ)*k = (3/4:ℝ)*k*(2*r) := by + rw [setIntegral_const,Real.volume_real_Icc_of_le (neg_le_self hr0),smul_eq_mul] + ring + rw [hs] at hm + exact hm.trans (setIntegral_le_integral hi (Eventually.of_forall hnon)) + have hgm := hg.smooth.continuous.measurable + have hfm := hf.continuous.measurable + unfold varianceTilted + rw [varianceHeat_kernel (g := fun y => g y*Real.exp (c*f y)) (by fun_prop) hh0] + have hn : 0 ≤ (3/4:ℝ)*k*(2*r) := by positivity + have hd := div_le_div_of_nonneg_left hn (varianceHeat_exp_pos hf c h x) hden + have hu := div_le_div_of_nonneg_right hlower (varianceHeat_exp_pos hf c h x).le + have he : (3/2:ℝ)*(Real.sqrt (2*Real.pi))⁻¹*Real.exp (-2/δ)*r=(3/4:ℝ)*k*(2*r) := by dsimp [k];ring + rw [he] + exact hd.trans hu + +end ZeroTemperatureSK.Heat + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKSupport/Density/FiniteDensity.lean b/lean/OAI/Probability/SKSupport/Density/FiniteDensity.lean new file mode 100644 index 0000000000000000000000000000000000000000..6af87481a5b5376ff1bbafd7adfad958c5aeffb4 --- /dev/null +++ b/lean/OAI/Probability/SKSupport/Density/FiniteDensity.lean @@ -0,0 +1,195 @@ +import Mathlib +import OAI.Probability.SKSupport.Density.GaussianLogDensity +import OAI.Probability.SKSupport.Density.DensityFubini + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section +namespace ZeroTemperatureSK +open Heat + +lemma Heat.finiteDensity_first_formula (c : ℕ → ℝ≥0) {h : ℝ≥0} + (hh : 0 < (h:ℝ)) (f : ℝ → ℝ) (N : ℕ) (x : ℝ) : + finiteDensity c h f N 1 x=heatKernel h x* + Real.exp ((c 0:ℝ)*backwardBoundary c h f N 1 x-(c 0:ℝ)*backwardBoundary c h f N 0 0) := by + have hn : Real.exp (-(1/2:ℝ)*Real.log (2*Real.pi*(h:ℝ)))= + (Real.sqrt (2*Real.pi*(h:ℝ)))⁻¹ := by + rw [show -(1/2:ℝ)*Real.log (2*Real.pi*(h:ℝ))= -((1/2:ℝ)*Real.log (2*Real.pi*(h:ℝ))) by ring, + Real.exp_neg,exp_half_log (by positivity)] + unfold finiteDensity + rw [forwardBoundary] + simp only [Nat.cast_one,one_mul,ite_true,Nat.zero_add] + rw [show (c 1:ℝ)*backwardBoundary c h f N 1 x-x^2/(2*(h:ℝ))+ + (-(1/2:ℝ)*Real.log (2*Real.pi*(h:ℝ))-(c 0:ℝ)*backwardBoundary c h f N 0 0- + ((c 1:ℝ)-(c 0:ℝ))*backwardBoundary c h f N 1 x)= + (-(1/2:ℝ)*Real.log (2*Real.pi*(h:ℝ)))+(-x^2/(2*(h:ℝ)))+ + ((c 0:ℝ)*backwardBoundary c h f N 1 x-(c 0:ℝ)*backwardBoundary c h f N 0 0) by ring, + Real.exp_add,Real.exp_add,hn,heatKernel_formula hh.le] + +lemma Heat.finiteDensity_first_pairing {f g : ℝ → ℝ} + (hf : RegularDatum f) (hLip : LipschitzWith 1 f) (hg : BoundedSmooth g) + (c : ℕ → ℝ≥0) (hc : 0 < (c 0:ℝ)) {h : ℝ≥0} (hh : 0 < (h:ℝ)) {N : ℕ} (hN : 0 < N) : + varianceTilted (c 0) h (backwardBoundary c h f N 1) g 0= + ∫ x, finiteDensity c h f N 1 x*g x := by + have hφ : LipschitzWith 1 (backwardBoundary c h f N 1) := cascade_lipschitz hLip c h _ _ + have hem := exp_varianceLogHeat hφ (ne_of_gt hc) (h:ℝ) 0 + rw [backwardBoundary_step hf hLip c h hN] at hem + have hgm : Measurable (fun z => g z*Real.exp ((c 0:ℝ)*backwardBoundary c h f N 1 z)) := + hg.smooth.continuous.measurable.mul ((measurable_const.mul hφ.continuous.measurable).exp) + unfold varianceTilted + rw [← hem,varianceHeat_kernel hgm hh,← integral_div] + apply integral_congr_ae + filter_upwards [] with x + rw [finiteDensity_first_formula c hh,Real.exp_sub] + simp only [sub_zero] + ring + +variable {Ω : Type*} [MeasurableSpace Ω] + +theorem finite_density_identity (W : BrownianSystem Ω) {f g : ℝ → ℝ} + (hf : RegularDatum f) (hLip : LipschitzWith 1 f) (hg : BoundedSmooth g) + (c : ℕ → ℝ≥0) (hc : ∀ i, 0 < (c i:ℝ)) {h : ℝ≥0} (hh : 0 < (h:ℝ)) + {N i : ℕ} (hi : 0 < i) (hiN : i ≤ N) : + (∫ w, g ((finiteFeedback hf hLip c h N 0).solution W.driver ((i:ℝ≥0)*h) w) ∂W.law)= + ∫ x, finiteDensity c h f N i x*g x := by + let := W.isProbability + induction i generalizing g with + | zero => omega + | succ i ih => + rw [finite_transition_tilted W hf hLip hg c h (by omega : i < N)] + by_cases h0 : i=0 + · subst i + simp only [Nat.cast_zero,zero_mul,BoundedLipschitzDrift.solution_zero] + simpa using finiteDensity_first_pairing hf hLip hg c (hc 0) hh (N := N) (by omega) + · have hip : 0 < i := Nat.pos_of_ne_zero h0 + have hφ : RegularDatum (backwardBoundary c h f N (i+1)) := cascade_regular hf hLip c h _ _ + have hφL : LipschitzWith 1 (backwardBoundary c h f N (i+1)) := cascade_lipschitz hLip c h _ _ + have hgt := (varianceTilted_family hφ hφL hg (hc i).le).regular (h:ℝ) + rw [ih hgt hip (by omega)] + exact finiteDensity_step_pairing hf hLip hg c hc hh hip (by omega) + +end ZeroTemperatureSK + +end +end +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology ContDiff +noncomputable section +namespace ZeroTemperatureSK.Heat + +lemma datumScore_regular {L : ℝ → ℝ} (hL : RegularDatum L) (a : ℝ) : RegularDatum (datumScore a L) := by + refine ⟨(contDiff_id.div_const a).sub (contDiff_infty_iff_deriv.mp hL.smooth |>.2),?_⟩ + have he : deriv (datumScore a L)=fun x => 1/a+(-1)*deriv (deriv L) x := by + funext x + rw [datumScore_deriv hL.smooth] + simp only [iteratedDeriv_succ,iteratedDeriv_zero] + ring + rw [he] + exact (BoundedSmooth.const _).add (hL.deriv_bounded.deriv.const_mul (-1)) + +lemma datumScore_odd {L : ℝ → ℝ} (hL : ContDiff ℝ ∞ L) (he : Function.Even L) (a : ℝ) : + Function.Odd (datumScore a L) := by + have hh := even_deriv_odd (hL.differentiable (by simp)) he + intro x + dsimp only [datumScore] + rw [hh x] + ring + +lemma datumScore_second {L : ℝ → ℝ} (hL : ContDiff ℝ ∞ L) (a x : ℝ) : + iteratedDeriv 2 (datumScore a L) x= -iteratedDeriv 3 L x := by + have he : deriv (datumScore a L)=fun y => 1/a-iteratedDeriv 2 L y := by + funext y;exact datumScore_deriv hL a y + simp only [show (2:ℕ)=1+1 from rfl,iteratedDeriv_succ,iteratedDeriv_zero] + rw [he] + convert ((hasDerivAt_const x (1/a)).sub (hasDerivAt_spatialJet hL 2 x)).deriv using 1 + first | rfl | simp [iteratedDeriv_succ,iteratedDeriv_zero] + +theorem finite_density_coercivity {M : ℝ} (c : ℕ → ℝ≥0) + (hc : ∀ i, 0 < (c i:ℝ)) (hmono : Monotone c) (hM : ∀ i, (c i:ℝ) ≤ M) + {h : ℝ≥0} (hh : 0 < (h:ℝ)) {N i : ℕ} (hi : 0 < i) (hiN : i ≤ N) : + let r := fun x => (c i:ℝ)*deriv (backwardBoundary c h (softAbs M) N i) x + (1/1000:ℝ)*(∫ x, finiteDensity c h (softAbs M) N i x*quarticMoment r x) ≤ + ∫ x, finiteDensity c h (softAbs M) N i x*coercivePolynomial r x := by + let φ := backwardBoundary c h (softAbs M) N i + let L := forwardBoundary c h (softAbs M) N i + let a : ℝ := (i:ℝ)*h + let r := fun x => (c i:ℝ)*deriv φ x + let s := datumScore a L + let U := fun x => (c i:ℝ)*φ x+L x + let d : ℝ := 1/(2*a) + have ha : 0 < a := mul_pos (Nat.cast_pos.mpr hi) hh + have hp := (hc 0).trans_le (hM 0) + have hf := regularDatum_softAbs (ne_of_gt hp) + have hLip := softAbs_lipschitz (ne_of_gt hp) + have hφ : RegularDatum φ := cascade_regular hf hLip c h _ _ + have hL : RegularDatum L := forwardBoundary_regular hf hLip c hh N i + have hLe : ForwardDatumShape L := forwardBoundary_shape c hc hmono hM hh N i + have hr : BoundedSmooth r := hφ.deriv_bounded.const_mul _ + have hs : RegularDatum s := datumScore_regular hL a + have hshape : BackwardShape r := backwardBoundary_shape c hc hmono hM h N i + have hso : Function.Odd s := datumScore_odd hL.smooth hLe.even a + have hsa (x : ℝ) : 0 ≤ deriv s x := by + rw [datumScore_deriv hL.smooth] + linarith [hLe.second x,one_div_pos.mpr ha] + have hsw (x : ℝ) (hx : 0 ≤ x) : iteratedDeriv 2 s x ≤ 0 := by + rw [datumScore_second hL.smooth] + exact neg_nonpos.mpr (hLe.third x hx) + have hQ (x : ℝ) (hx : 0 ≤ x) : 0 ≤ r x*deriv s x-s x*deriv r x := + boundaryRatio_nonneg c hc hmono hM hh N i hi hiN x hx + have hUr : RegularDatum U := by + convert hL.sub_mul hφ (-(c i:ℝ)) using 1 + funext x;dsimp only [U];ring + obtain ⟨K,hU⟩ := hUr.exists_lipschitz + have hUe : Function.Even U := by + have heφ : Function.Even φ := cascade_even hf hLip (softAbs_even M) c h _ _ + intro x + dsimp only [U] + rw [heφ x,hLe.even x] + have hUd (x : ℝ) : HasDerivAt U (r x-s x+2*d*x) x := by + have he : r x-s x+2*d*x=(c i:ℝ)*deriv φ x+deriv L x := by + dsimp only [r,s,datumScore,d] + field_simp [ne_of_gt ha] + ring + rw [he] + convert (((hφ.smooth.differentiable (by simp)) x).hasDerivAt.const_mul (c i:ℝ)).add + (((hL.smooth.differentiable (by simp)) x).hasDerivAt) using 1 + have he : finiteDensity c h (softAbs M) N i=gaussianLogDensity d U := by + funext x + unfold finiteDensity gaussianLogDensity + congr 1 + dsimp only [d,U,a,φ,L] + ring + rw [he] + exact gaussian_shape_coercivity hr hs hshape hso hsa hsw hQ hU hUe (by dsimp [d];positivity) hUd + +end Heat +open Heat +variable {Ω : Type*} [MeasurableSpace Ω] + +theorem finite_feedback_coercivity (W : BrownianSystem Ω) {M : ℝ} (c : ℕ → ℝ≥0) + (hc : ∀ i, 0 < (c i:ℝ)) (hmono : Monotone c) (hM : ∀ i, (c i:ℝ) ≤ M) + {h : ℝ≥0} (hh : 0 < (h:ℝ)) {N i : ℕ} (hi : 0 < i) (hiN : i ≤ N) : + let hMp : M ≠ 0 := ne_of_gt ((hc 0).trans_le (hM 0)) + let X := (finiteFeedback (regularDatum_softAbs hMp) (softAbs_lipschitz hMp) c h N 0).solution W.driver + let r := fun x => (c i:ℝ)*deriv (backwardBoundary c h (softAbs M) N i) x + (1/1000:ℝ)*(∫ w, quarticMoment r (X ((i:ℝ≥0)*h) w) ∂W.law) ≤ + ∫ w, coercivePolynomial r (X ((i:ℝ≥0)*h) w) ∂W.law := by + dsimp only + have hMp : M ≠ 0 := ne_of_gt ((hc 0).trans_le (hM 0)) + have hr : BoundedSmooth (fun x => (c i:ℝ)*deriv (backwardBoundary c h (softAbs M) N i) x) := (cascade_regular (regularDatum_softAbs hMp) (softAbs_lipschitz hMp) c h (N-i) i).deriv_bounded.const_mul (c i:ℝ) + rw [finite_density_identity W (regularDatum_softAbs hMp) (softAbs_lipschitz hMp) + (quarticMoment_boundedSmooth hr) c hc hh hi hiN, + finite_density_identity W (regularDatum_softAbs hMp) (softAbs_lipschitz hMp) + (coercivePolynomial_boundedSmooth hr) c hc hh hi hiN] + exact finite_density_coercivity c hc hmono hM hh hi hiN + +end ZeroTemperatureSK + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKSupport/Density/FiniteForwardRatio.lean b/lean/OAI/Probability/SKSupport/Density/FiniteForwardRatio.lean new file mode 100644 index 0000000000000000000000000000000000000000..7fbe99f03ae924d26d3d2ad6c31608f64a4ae0c6 --- /dev/null +++ b/lean/OAI/Probability/SKSupport/Density/FiniteForwardRatio.lean @@ -0,0 +1,238 @@ +import Mathlib +import OAI.Probability.SKSupport.Backward.GaussianBackwardShapes +import OAI.Probability.SKSupport.Density.Certificate +import OAI.Probability.SKSupport.Density.RatioComparison + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology ContDiff +noncomputable section +namespace ZeroTemperatureSK.Heat + +def backwardSegment (c : ℕ → ℝ≥0) (h : ℝ≥0) (f : ℝ → ℝ) (N i : ℕ) (t x : ℝ) := + gaussianBurgers (c i) (backwardBoundary c h f N (i+1)) ((h:ℝ)-t) x + +lemma backwardSegment_initial {f : ℝ → ℝ} (hf : RegularDatum f) (hLip : LipschitzWith 1 f) + (c : ℕ → ℝ≥0) (h : ℝ≥0) {N i : ℕ} (hi : i < N) : + backwardSegment c h f N i 0=fun x => (c i:ℝ)*deriv (backwardBoundary c h f N i) x := by + have hn : N-i=(N-(i+1))+1 := by omega + have hφ := (cascade_regular hf hLip c h (N-(i+1)) (i+1)).smooth.continuous.measurable + have he : varianceLogHeat (c i) (h:ℝ) (backwardBoundary c h f N (i+1)) = + backwardBoundary c h f N i := by + funext x + unfold backwardBoundary + rw [varianceLogHeat_eq_logSemigroup_toNNReal hφ,Real.toNNReal_coe] + simp only [hn,cascade] + change (fun x => (c i:ℝ)*deriv (varianceLogHeat (c i) ((h:ℝ)-0) (backwardBoundary c h f N (i+1))) x)=_ + rw [sub_zero,he] + +lemma backwardSegment_terminal (c : ℕ → ℝ≥0) (h : ℝ≥0) (f : ℝ → ℝ) (N i : ℕ) : + backwardSegment c h f N i h=fun x => (c i:ℝ)*deriv (backwardBoundary c h f N (i+1)) x := by + change (fun x => (c i:ℝ)*deriv (varianceLogHeat (c i) ((h:ℝ)-h) (backwardBoundary c h f N (i+1))) x)=_ + have he : varianceLogHeat (c i) 0 (backwardBoundary c h f N (i+1))=backwardBoundary c h f N (i+1) := by + funext x + simpa only [backward,sub_self] using backward_terminal (c i) (h:ℝ) (backwardBoundary c h f N (i+1)) x + rw [sub_self,he] + +lemma backwardSegment_reverse {f : ℝ → ℝ} (hf : RegularDatum f) (hLip : LipschitzWith 1 f) + (c : ℕ → ℝ≥0) (h : ℝ≥0) (N i : ℕ) : ReverseBurgers (backwardSegment c h f N i) h := + (gaussianBurgers_smooth (cascade_regular hf hLip c h _ _) + (cascade_lipschitz hLip c h _ _) (c i).coe_nonneg).reverse h.coe_nonneg + +lemma backwardSegment_shape {M : ℝ} (c : ℕ → ℝ≥0) + (hc : ∀ i, 0 < (c i:ℝ)) (hmono : Monotone c) (hM : ∀ i, (c i:ℝ) ≤ M) + (h : ℝ≥0) (N i : ℕ) {t : ℝ} (ht : t ≤ h) : + BackwardShape (backwardSegment c h (softAbs M) N i t) := by + have hh := finiteHead_backward_shape c hc hmono hM h (N-(i+1)) i t ht + rw [finiteValue_head _ c h _ i ht] at hh + exact hh + +def boundaryRatio (c : ℕ → ℝ≥0) (h : ℝ≥0) (f : ℝ → ℝ) (N i : ℕ) (x : ℝ) := + ratioWronskian (fun _ y => (c i:ℝ)*deriv (backwardBoundary c h f N i) y) + (fun _ => datumScore ((i:ℝ)*h) (forwardBoundary c h f N i)) 0 x + +lemma forwardSegment_ratio {M : ℝ} (c : ℕ → ℝ≥0) + (hc : ∀ i, 0 < (c i:ℝ)) (hmono : Monotone c) (hM : ∀ i, (c i:ℝ) ≤ M) + {h : ℝ≥0} (hh : 0 < (h:ℝ)) {N i : ℕ} (hi0 : 0 < i) (hiN : i < N) + (hi : ∀ x, 0 ≤ x → 0 ≤ boundaryRatio c h (softAbs M) N i x) + {t : ℝ} (ht : t ∈ Icc (0:ℝ) h) (x : ℝ) (hx : 0 ≤ x) : + 0 ≤ ratioWronskian (backwardSegment c h (softAbs M) N i) + (forwardScore ((i:ℝ)*h) (forwardBoundary c h (softAbs M) N i)) t x := by + have hp := (hc 0).trans_le (hM 0) + have hf := regularDatum_softAbs (ne_of_gt hp) + have hLip := softAbs_lipschitz (ne_of_gt hp) + have hL := forwardBoundary_regular hf hLip c hh N i + obtain ⟨K,hK⟩ := hL.exists_lipschitz + have ha := mul_pos (Nat.cast_pos.mpr hi0) hh + have hshape := forwardBoundary_shape c hc hmono hM hh N i + have hs := forwardScore_smooth ha hL hK + apply (backwardSegment_reverse hf hLip c h N i).ratio_nonneg hs + (fun τ hτ => backwardSegment_shape c hc hmono hM h N i hτ.2) + (forwardScore_odd hL hK hshape.even) (fun τ hτ y => ?_) (fun τ hτ y hy => ?_) + (fun y hy => ?_) ht x hx + · rw [forwardScore_deriv hL hK] + have h₂ := (forwardCorrection_shape ha hL hK hshape hτ).second y + have hb := inv_pos.mpr (forwardTime_pos ha τ) + linarith + · rw [forwardScore_second hL hK] + exact neg_nonpos.mpr ((forwardCorrection_shape ha hL hK hshape hτ).third y hy) + · have hh := hi y hy + change 0 ≤ (backwardSegment c h (softAbs M) N i 0 y)* + deriv (forwardScore ((i:ℝ)*h) (forwardBoundary c h (softAbs M) N i) 0) y- + forwardScore ((i:ℝ)*h) (forwardBoundary c h (softAbs M) N i) 0 y* + deriv (backwardSegment c h (softAbs M) N i 0) y + rw [backwardSegment_initial hf hLip c h hiN,forwardScore_initial (ne_of_gt ha)] + exact hh + +theorem boundaryRatio_nonneg {M : ℝ} (c : ℕ → ℝ≥0) + (hc : ∀ i, 0 < (c i:ℝ)) (hmono : Monotone c) (hM : ∀ i, (c i:ℝ) ≤ M) + {h : ℝ≥0} (hh : 0 < (h:ℝ)) (N i : ℕ) (hi0 : 0 < i) (hiN : i ≤ N) : + ∀ x, 0 ≤ x → 0 ≤ boundaryRatio c h (softAbs M) N i x := by + have hp := (hc 0).trans_le (hM 0) + have hf := regularDatum_softAbs (ne_of_gt hp) + have hLip := softAbs_lipschitz (ne_of_gt hp) + induction i with + | zero => omega + | succ i ih => + intro x hx + by_cases hi : i=0 + · subst i + have hφ := (cascade_regular hf hLip c h (N-1) 1).smooth + have hs := backwardBoundary_shape c hc hmono hM h N 1 + simpa only [boundaryRatio,forwardBoundary,ite_true,Nat.zero_add,Nat.cast_one,one_mul,backwardBoundary] using + ratioWronskian_first_jump hφ hh (hc 0) (hc 1) (C := -(1/2:ℝ)*Real.log (2*Real.pi*(h:ℝ))- + (c 0:ℝ)*backwardBoundary c h (softAbs M) N 0 0) hs hx + · have hi0' : 0 < i := Nat.pos_of_ne_zero hi + have hiN' : i < N := by omega + have hprev := forwardSegment_ratio c hc hmono hM hh hi0' hiN' + (ih hi0' hiN'.le) (t := (h:ℝ)) ⟨h.coe_nonneg,le_rfl⟩ x hx + have hφ : ContDiff ℝ ∞ (backwardBoundary c h (softAbs M) N (i+1)) := + (cascade_regular hf hLip c h (N-(i+1)) (i+1)).smooth + have hL := forwardBoundary_regular hf hLip c hh N i + obtain ⟨K,hK⟩ := hL.exists_lipschitz + have he : ((i+1:ℕ):ℝ)*(h:ℝ)=(i:ℝ)*h+h := by push_cast;ring + change 0 ≤ ratioWronskian (fun _ => backwardSegment c h (softAbs M) N i h) + (fun _ => forwardScore ((i:ℝ)*h) (forwardBoundary c h (softAbs M) N i) h) 0 x at hprev + rw [forwardScore_eq_datumScore h.coe_nonneg,backwardSegment_terminal] at hprev + dsimp only [boundaryRatio] + simp only [forwardBoundary,ite_eq_right hi,he] + rw [ratioWronskian_jump (forwardCorrection_smooth hL hK h) hφ _ _ _ _ (ne_of_gt (hc i))] + exact mul_nonneg (div_nonneg (hc (i+1)).le (hc i).le) hprev + +theorem finite_forward_ratio {M : ℝ} (c : ℕ → ℝ≥0) + (hc : ∀ i, 0 < (c i:ℝ)) (hmono : Monotone c) (hM : ∀ i, (c i:ℝ) ≤ M) + {h : ℝ≥0} (hh : 0 < (h:ℝ)) {N i : ℕ} (hi0 : 0 < i) (hiN : i < N) + {t : ℝ} (ht : t ∈ Icc (0:ℝ) h) {x : ℝ} (hx : 0 ≤ x) : + 0 ≤ ratioWronskian (backwardSegment c h (softAbs M) N i) + (forwardScore ((i:ℝ)*h) (forwardBoundary c h (softAbs M) N i)) t x := + forwardSegment_ratio c hc hmono hM hh hi0 hiN + (boundaryRatio_nonneg c hc hmono hM hh N i hi0 hiN.le) ht x hx + +end ZeroTemperatureSK.Heat + +end +end +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology ContDiff +noncomputable section +namespace ZeroTemperatureSK.Heat + +def certR (r : ℝ → ℝ) (x : ℝ) := (r x)^2 +def certK (r s : ℝ → ℝ) (x : ℝ) := r x*s x +def certV (r : ℝ → ℝ) := deriv r +def certW (r : ℝ → ℝ) := iteratedDeriv 2 r +def certZ (r : ℝ → ℝ) := iteratedDeriv 3 r +def certB (r : ℝ → ℝ) (x : ℝ) := -certW r x/r x +def certJ (r s : ℝ → ℝ) (x : ℝ) := deriv s x-(s x/r x)*certV r x +def certL (r s : ℝ → ℝ) (x : ℝ) := -r x*iteratedDeriv 2 s x + +def certFlux (r s ρ : ℝ → ℝ) (x : ℝ) := + r x*Certificate.F₂ (certR r x) (certK r s x) (certV r x) (certB r x) (certJ r s x)*ρ x + +def certDivergence (r s ρ : ℝ → ℝ) (x : ℝ) := + ρ x*Certificate.WF₂ (certR r x) (certK r s x) (certV r x) (certB r x) (certJ r s x) + (certZ r x) (certL r s x) + +lemma cert_flux_derivative {r s ρ : ℝ → ℝ} (hr : ContDiff ℝ ∞ r) (hs : ContDiff ℝ ∞ s) + {x : ℝ} (hne : r x ≠ 0) (hρ : HasDerivAt ρ ((r x-s x)*ρ x) x) : + HasDerivAt (certFlux r s ρ) (certDivergence r s ρ x) x := by + have hr' : HasDerivAt r (certV r x) x := (hr.differentiable (by simp) x).hasDerivAt + have hv : HasDerivAt (certV r) (certW r x) x := by simpa only [iteratedDeriv_one,certV,certW] using hasDerivAt_spatialJet hr 1 x + have hw : HasDerivAt (certW r) (certZ r x) x := hasDerivAt_spatialJet hr 2 x + have hs' : HasDerivAt s (deriv s x) x := (hs.differentiable (by simp) x).hasDerivAt + have hs'' : HasDerivAt (deriv s) (iteratedDeriv 2 s x) x := by simpa only [iteratedDeriv_one] using hasDerivAt_spatialJet hs 1 x + apply Certificate.hasDerivAt_flux hr' hρ (hr'.pow 2) (hr'.mul hs') hv + (hw.neg.div hr' hne) (hs''.sub (((hs'.div hr' hne).mul hv))) rfl rfl + · simp only [Pi.pow_apply];ring + · dsimp [certK,certR,certJ] + field_simp [hne] + ring + · dsimp [certR,certB] + field_simp [hne] + · dsimp [certB] + field_simp [hne] + · dsimp [certJ,certK,certB,certL] + field_simp [hne] + ring + +lemma cert_halfLine_signs {r s : ℝ → ℝ} (hr : ContDiff ℝ ∞ r) (hs : ContDiff ℝ ∞ s) + (hshape : BackwardShape r) (hso : Function.Odd s) (hsa : ∀ x, 0 ≤ deriv s x) + (hsw : ∀ x, 0 ≤ x → iteratedDeriv 2 s x ≤ 0) + (hQ : ∀ x, 0 ≤ x → 0 ≤ r x*deriv s x-s x*deriv r x) + {x : ℝ} (hx : 0 < x) : + 0 ≤ certR r x ∧ 0 ≤ certK r s x ∧ 0 ≤ certV r x ∧ 0 ≤ certJ r s x ∧ + 0 ≤ certB r x-2*certV r x ∧ 0 ≤ certL r s x ∧ + 0 ≤ certZ r x+certB r x*certV r x-2*certR r x*certB r x := by + have hp := hshape.pos hx + have hn := ne_of_gt hp + have hs0 : s 0=0 := by have hh := hso 0;simp only [neg_zero] at hh;linarith + have hsp : 0 ≤ s x := by + simpa only [hs0] using (monotone_of_deriv_nonneg (hs.differentiable (by simp)) hsa hx.le) + refine ⟨sq_nonneg _,mul_nonneg hp.le hsp,(hshape.derivative_pos x).le,?_,?_,?_,?_⟩ + · have he : certJ r s x=(r x*deriv s x-s x*deriv r x)/r x := by + dsimp [certJ,certV] + field_simp + rw [he] + exact div_nonneg (hQ x hx.le) hp.le + · have he : certB r x-2*certV r x= -2*burgersRate (fun _ => r) 0 x/r x := by + dsimp [certB,certW,certV,burgersRate] + field_simp [hn] + ring + rw [he] + exact div_nonneg (mul_nonneg_of_nonpos_of_nonpos (by norm_num) (hshape.rate_nonpos x hx.le)) hp.le + · exact mul_nonneg_of_nonpos_of_nonpos (neg_nonpos.mpr hp.le) (hsw x hx.le) + · have he : certZ r x+certB r x*certV r x-2*certR r x*certB r x= + 2*backwardWronskian (fun _ => r) 0 x/r x := by + rw [backwardWronskian,burgersRate_spatial_deriv hr] + dsimp [certZ,certB,certW,certV,certR,burgersRate] + field_simp [hn] + ring + rw [he] + exact div_nonneg (mul_nonneg (by norm_num) (hshape.wronskian_nonneg x hx.le)) hp.le + +lemma cert_halfLine_coercive {r s : ℝ → ℝ} (hr : ContDiff ℝ ∞ r) (hs : ContDiff ℝ ∞ s) + (hshape : BackwardShape r) (hso : Function.Odd s) (hsa : ∀ x, 0 ≤ deriv s x) + (hsw : ∀ x, 0 ≤ x → iteratedDeriv 2 s x ≤ 0) + (hQ : ∀ x, 0 ≤ x → 0 ≤ r x*deriv s x-s x*deriv r x) + {x : ℝ} (hx : 0 < x) : + (1661507/1521000000:ℝ)*(certV r x)^4+ + Certificate.WF₂ (certR r x) (certK r s x) (certV r x) (certB r x) (certJ r s x) + (certZ r x) (certL r s x) ≤ + (certZ r x)^2-12*certV r x*(certW r x)^2+6*(certV r x)^4 := by + obtain ⟨hR,hK,hv,hj,hB,hL,hS⟩ := cert_halfLine_signs hr hs hshape hso hsa hsw hQ hx + have he : certR r x*(certB r x)^2=(certW r x)^2 := by + dsimp [certR,certB] + field_simp [ne_of_gt (hshape.pos hx)] + have hh := Certificate.pointwise_coercivity hR hK hv hj hB hL hS + rw [show 12*certR r x*certV r x*(certB r x)^2=12*certV r x*(certR r x*(certB r x)^2) by ring,he] at hh + exact hh + +end ZeroTemperatureSK.Heat + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKSupport/Density/GaussianDecay.lean b/lean/OAI/Probability/SKSupport/Density/GaussianDecay.lean new file mode 100644 index 0000000000000000000000000000000000000000..40b7d6f10d6030b372199c7a438d2ee691ea91f4 --- /dev/null +++ b/lean/OAI/Probability/SKSupport/Density/GaussianDecay.lean @@ -0,0 +1,168 @@ +import Mathlib +import OAI.Probability.SKSupport.Backward.BackwardRescale + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section +namespace ZeroTemperatureSK.Heat + +lemma linear_abs_le_quadratic {d : ℝ} (hd : 0 < d) (K x : ℝ) : + K*|x| ≤ d/2*x^2+K^2/(2*d) := by + apply (mul_le_mul_iff_of_pos_left (show (0:ℝ)<2*d by positivity)).mp + have he : (2*d)*(d/2*x^2+K^2/(2*d))=d^2*x^2+K^2 := by field_simp + rw [he] + have hs : 0 ≤ d^2*x^2-2*d*K*|x|+K^2 := by + have heq : d^2*x^2-2*d*K*|x|+K^2=(d*|x|-K)^2 := by + rw [sub_sq,mul_pow,sq_abs] + ring + rw [heq] + exact sq_nonneg _ + nlinarith only [hs] + +lemma integrable_gaussian_linear {d : ℝ} (hd : 0 < d) (K : ℝ) : + Integrable (fun x : ℝ => Real.exp (-d*x^2+K*|x|)) := by + apply ((integrable_exp_neg_mul_sq (half_pos hd)).const_mul (Real.exp (K^2/(2*d)))).mono' (by fun_prop) + filter_upwards [] with x + rw [Real.norm_eq_abs,abs_of_pos (Real.exp_pos _),← Real.exp_add] + apply Real.exp_le_exp.mpr + have hh := linear_abs_le_quadratic hd K x + linarith + +lemma integrable_gaussian_expBound {g : ℝ → ℝ} (hgm : Measurable g) (hg : ExponentialBound g) + {d : ℝ} (hd : 0 < d) : Integrable (fun x => Real.exp (-d*x^2)*g x) := by + obtain ⟨A,K,hA⟩ := hg + apply ((integrable_gaussian_linear hd K).const_mul (A:ℝ)).mono' (by fun_prop) + filter_upwards [] with x + simp only [Real.norm_eq_abs,abs_mul,abs_of_pos (Real.exp_pos _)] + calc + Real.exp (-d*x^2)*|g x| ≤ Real.exp (-d*x^2)*((A:ℝ)*Real.exp ((K:ℝ)*|x|)) := + mul_le_mul_of_nonneg_left (hA x) (Real.exp_nonneg _) + _ = (A:ℝ)*Real.exp (-d*x^2+(K:ℝ)*|x|) := by rw [Real.exp_add];ring + +lemma ExponentialBound.mul {f g : ℝ → ℝ} (hf : ExponentialBound f) (hg : ExponentialBound g) : + ExponentialBound (fun x => f x*g x) := by + obtain ⟨A,K,hA⟩ := hf + obtain ⟨B,J,hB⟩ := hg + refine ⟨A*B,K+J,fun x => ?_⟩ + rw [abs_mul] + calc + |f x| * |g x| ≤ ((A:ℝ)*Real.exp ((K:ℝ)*|x|))*((B:ℝ)*Real.exp ((J:ℝ)*|x|)) := + mul_le_mul (hA x) (hB x) (abs_nonneg _) (by positivity) + _ = ((A*B:ℝ≥0):ℝ)*Real.exp (((K+J:ℝ≥0):ℝ)*|x|) := by + simp only [NNReal.coe_mul,NNReal.coe_add,add_mul,Real.exp_add] + ring + +lemma gaussian_convolution_quadratic {a t : ℝ} (ha : 0 < a) (ht : 0 < t) (x y : ℝ) : + (1/(8*(a+t)))*(x^2+y^2) ≤ x^2/(2*a)+(y-x)^2/(2*t) := by + have hs := add_pos ha ht + have h1 : 1/(2*(a+t)) ≤ 1/(2*a) := one_div_le_one_div_of_le (by positivity) (by linarith) + have h2 : 1/(2*(a+t)) ≤ 1/(2*t) := one_div_le_one_div_of_le (by positivity) (by linarith) + have hq : x^2+y^2 ≤ 4*(x^2+(y-x)^2) := by nlinarith [sq_nonneg (y-2*x),sq_nonneg x] + calc + _ ≤ (1/(8*(a+t)))*(4*(x^2+(y-x)^2)) := mul_le_mul_of_nonneg_left hq (by positivity) + _ = (1/(2*(a+t)))*x^2+(1/(2*(a+t)))*(y-x)^2 := by + field_simp + ring + _ ≤ (1/(2*a))*x^2+(1/(2*t))*(y-x)^2 := add_le_add + (mul_le_mul_of_nonneg_right h1 (sq_nonneg _)) (mul_le_mul_of_nonneg_right h2 (sq_nonneg _)) + _ = _ := by ring + +end ZeroTemperatureSK.Heat + +end +end +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology ContDiff +noncomputable section +namespace ZeroTemperatureSK.Heat + +lemma continuous_dslope_zero {f : ℝ → ℝ} (hf : Differentiable ℝ f) : Continuous (dslope f 0) := by + apply continuous_iff_continuousAt.mpr + intro x + by_cases hx : x=0 + · subst x;exact continuousAt_dslope_same.mpr (hf 0) + · exact (continuousAt_dslope_of_ne hx).mpr (hf x).continuousAt + +def quotientExtension (g r : ℝ → ℝ) (x : ℝ) := dslope g 0 x/dslope r 0 x + +lemma BackwardShape.nonzero {r : ℝ → ℝ} (hr : BackwardShape r) {x : ℝ} (hx : x ≠ 0) : r x ≠ 0 := by + intro he + exact hx ((strictMono_of_deriv_pos hr.derivative_pos).injective (he.trans hr.odd.map_zero.symm)) + +lemma BackwardShape.dslope_nonzero {r : ℝ → ℝ} (hr : BackwardShape r) (x : ℝ) : dslope r 0 x ≠ 0 := by + by_cases hx : x=0 + · subst x;simpa only [dslope_same] using ne_of_gt (hr.derivative_pos 0) + · simp only [dslope_of_ne r hx,slope,vsub_eq_sub,sub_zero,hr.odd.map_zero,smul_eq_mul] + exact mul_ne_zero (inv_ne_zero hx) (hr.nonzero hx) + +lemma quotientExtension_continuous {g r : ℝ → ℝ} (hg : Differentiable ℝ g) + (hr : Differentiable ℝ r) (hshape : BackwardShape r) : Continuous (quotientExtension g r) := + (continuous_dslope_zero hg).div (continuous_dslope_zero hr) hshape.dslope_nonzero + +lemma quotientExtension_eq {g r : ℝ → ℝ} (hg0 : g 0=0) (hr0 : r 0=0) {x : ℝ} (hx : x ≠ 0) : + quotientExtension g r x=g x/r x := by + dsimp [quotientExtension] + simp only [dslope_of_ne _ hx,slope,vsub_eq_sub,hg0,hr0,sub_zero,smul_eq_mul] + field_simp + +lemma BackwardShape.abs_eq {r : ℝ → ℝ} (hr : BackwardShape r) (x : ℝ) : |r x|=r |x| := by + have hm := (strictMono_of_deriv_pos hr.derivative_pos).monotone + by_cases hx : 0 ≤ x + · rw [abs_of_nonneg hx,abs_of_nonneg (by simpa only [hr.odd.map_zero] using hm hx)] + · have hxn : x ≤ 0 := le_of_lt (lt_of_not_ge hx) + rw [abs_of_nonpos hxn,abs_of_nonpos (by simpa only [hr.odd.map_zero] using hm hxn),hr.odd] + +lemma quotient_linear_bound {g r : ℝ → ℝ} {K : ℝ≥0} + (hg : Differentiable ℝ g) (hLip : LipschitzWith K g) (hg0 : g 0=0) + (hr : Differentiable ℝ r) (hshape : BackwardShape r) : + ∃ C : ℝ≥0, ∀ x, |g x/r x| ≤ (C:ℝ)*(1+|x|) := by + have hq := quotientExtension_continuous hg hr hshape + obtain ⟨R,hR⟩ := (isCompact_Icc : IsCompact (Icc (-1:ℝ) 1)).bddAbove_image hq.abs.continuousOn + let C := Real.toNNReal (|R|+(K:ℝ)/r 1) + have hr1 : 0 < r 1 := by + simpa only [hshape.odd.map_zero] using + strictMono_of_deriv_pos hshape.derivative_pos (by norm_num : (0:ℝ)<1) + have hCR : R ≤ (C:ℝ) := (le_abs_self R).trans ((le_add_of_nonneg_right (div_nonneg K.coe_nonneg hr1.le)).trans (Real.le_coe_toNNReal _)) + have hCK : (K:ℝ)/r 1 ≤ (C:ℝ) := (le_add_of_nonneg_left (abs_nonneg R)).trans (Real.le_coe_toNNReal _) + refine ⟨C,fun x => ?_⟩ + by_cases hx : x=0 + · subst x;simp only [hg0,zero_div,abs_zero,add_zero,mul_one];exact C.coe_nonneg + by_cases hsmall : |x| ≤ 1 + · have hmem : x ∈ Icc (-1:ℝ) 1 := abs_le.mp hsmall + have hb : |quotientExtension g r x| ≤ R := hR ⟨x,hmem,rfl⟩ + rw [quotientExtension_eq hg0 hshape.odd.map_zero hx] at hb + exact (hb.trans hCR).trans (le_mul_of_one_le_right C.coe_nonneg (by linarith [abs_nonneg x])) + · have hden : r 1 ≤ |r x| := by + rw [hshape.abs_eq] + exact (strictMono_of_deriv_pos hshape.derivative_pos).monotone (le_of_lt (lt_of_not_ge hsmall)) + have hnum : |g x| ≤ (K:ℝ)*|x| := by simpa only [Real.norm_eq_abs,hg0,sub_zero] using hLip.norm_sub_le x 0 + rw [abs_div] + calc + |g x|/|r x| ≤ ((K:ℝ)*|x|)/|r x| := div_le_div_of_nonneg_right hnum (abs_nonneg _) + _ ≤ ((K:ℝ)*|x|)/r 1 := div_le_div_of_nonneg_left (by positivity) hr1 hden + _ = ((K:ℝ)/r 1)*|x| := by ring + _ ≤ (C:ℝ)*|x| := mul_le_mul_of_nonneg_right hCK (abs_nonneg x) + _ ≤ (C:ℝ)*(1+|x|) := by nlinarith [C.coe_nonneg] + +lemma exponentialBound_of_linear_bound {g : ℝ → ℝ} {C : ℝ≥0} + (hC : ∀ x, |g x| ≤ (C:ℝ)*(1+|x|)) : ExponentialBound g := by + refine ⟨C,1,fun x => ?_⟩ + simp only [NNReal.coe_one,one_mul] + exact (hC x).trans (mul_le_mul_of_nonneg_left (by simpa only [add_comm] using Real.add_one_le_exp |x|) C.coe_nonneg) + +lemma exponentialBound_quotient {g r : ℝ → ℝ} {K : ℝ≥0} + (hg : Differentiable ℝ g) (hLip : LipschitzWith K g) (hg0 : g 0=0) + (hr : Differentiable ℝ r) (hshape : BackwardShape r) : ExponentialBound (fun x => g x/r x) := by + obtain ⟨C,hC⟩ := quotient_linear_bound hg hLip hg0 hr hshape + exact exponentialBound_of_linear_bound hC + +end ZeroTemperatureSK.Heat + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKSupport/Density/GaussianLogDensity.lean b/lean/OAI/Probability/SKSupport/Density/GaussianLogDensity.lean new file mode 100644 index 0000000000000000000000000000000000000000..a038f1a3c59dfd0ea54ae03fcdeb9f578e5f04be --- /dev/null +++ b/lean/OAI/Probability/SKSupport/Density/GaussianLogDensity.lean @@ -0,0 +1,169 @@ +import Mathlib +import OAI.Probability.SKSupport.Density.GaussianTails + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section +namespace ZeroTemperatureSK.Heat + +def gaussianLogDensity (d : ℝ) (U : ℝ → ℝ) (x : ℝ) := Real.exp (-d*x^2+U x) + +lemma gaussianLogDensity_continuous {U : ℝ → ℝ} (hU : Continuous U) (d : ℝ) : + Continuous (gaussianLogDensity d U) := by unfold gaussianLogDensity;fun_prop + +lemma gaussianLogDensity_pos (d : ℝ) (U : ℝ → ℝ) (x : ℝ) : 0 < gaussianLogDensity d U x := Real.exp_pos _ + +lemma gaussianLogDensity_even {U : ℝ → ℝ} (hU : Function.Even U) (d : ℝ) : + Function.Even (gaussianLogDensity d U) := by intro x;simp only [gaussianLogDensity,neg_sq,hU x] + +lemma gaussianLogDensity_derivative {U : ℝ → ℝ} {d x U' : ℝ} (hU : HasDerivAt U U' x) : + HasDerivAt (gaussianLogDensity d U) ((U'-2*d*x)*gaussianLogDensity d U x) x := by + convert (((hasDerivAt_id x).pow 2).const_mul (-d) |>.add hU).exp using 1 <;> + first | rfl | (dsimp [gaussianLogDensity];ring) + +lemma gaussianLogDensity_integrable_mul {U g : ℝ → ℝ} {K : ℝ≥0} (hU : LipschitzWith K U) + (hgm : Measurable g) (hg : ExponentialBound g) {d : ℝ} (hd : 0 < d) : + Integrable (fun x => gaussianLogDensity d U x*g x) := by + have hE : ExponentialBound (fun x => Real.exp (U x)) := by simpa only [one_mul] using exponentialBound_exp hU 1 + have hh := integrable_gaussian_expBound (hU.continuous.measurable.exp.mul hgm) (hE.mul hg) hd + simpa only [gaussianLogDensity,Real.exp_add,mul_assoc,Pi.mul_apply] using hh + +lemma gaussianLogDensity_tendsto_mul {U g : ℝ → ℝ} {K : ℝ≥0} (hU : LipschitzWith K U) + (hg : ExponentialBound g) {d : ℝ} (hd : 0 < d) : + Tendsto (fun x => gaussianLogDensity d U x*g x) atTop (𝓝 0) := by + have hE : ExponentialBound (fun x => Real.exp (U x)) := by simpa only [one_mul] using exponentialBound_exp hU 1 + simpa only [gaussianLogDensity,Real.exp_add,mul_assoc,Pi.mul_apply] using gaussian_expBound_tendsto_zero (hE.mul hg) hd + +end ZeroTemperatureSK.Heat + +end +end +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology ContDiff +noncomputable section +namespace ZeroTemperatureSK.Heat + +lemma BoundedSmooth.pow {f : ℝ → ℝ} (hf : BoundedSmooth f) (n : ℕ) : BoundedSmooth (fun x => (f x)^n) := by + induction n with + | zero => simpa only [pow_zero] using BoundedSmooth.const 1 + | succ n ih => simpa only [pow_succ] using ih.mul hf + +def coercivePolynomial (r : ℝ → ℝ) (x : ℝ) := + (certZ r x)^2-12*certV r x*(certW r x)^2+6*(certV r x)^4 + +def quarticMoment (r : ℝ → ℝ) (x : ℝ) := (certV r x)^4 + +lemma quarticMoment_boundedSmooth {r : ℝ → ℝ} (hr : BoundedSmooth r) : BoundedSmooth (quarticMoment r) := hr.deriv.pow 4 + +lemma coercivePolynomial_boundedSmooth {r : ℝ → ℝ} (hr : BoundedSmooth r) : BoundedSmooth (coercivePolynomial r) := by + have hw : BoundedSmooth (certW r) := by simpa only [certW,iteratedDeriv_succ,iteratedDeriv_zero] using hr.deriv.deriv + have hz : BoundedSmooth (certZ r) := by simpa only [certZ,iteratedDeriv_succ,iteratedDeriv_zero] using hr.deriv.deriv.deriv + convert ((hz.pow 2).add ((hr.deriv.mul (hw.pow 2)).const_mul (-12))).add ((hr.deriv.pow 4).const_mul 6) using 1 + funext x + dsimp [coercivePolynomial,certV] + ring + +lemma quarticMoment_even {r : ℝ → ℝ} (hr : ContDiff ℝ ∞ r) (ho : Function.Odd r) : Function.Even (quarticMoment r) := by + intro x;simp only [quarticMoment,certV_even hr ho x] + +lemma coercivePolynomial_even {r : ℝ → ℝ} (hr : ContDiff ℝ ∞ r) (ho : Function.Odd r) : Function.Even (coercivePolynomial r) := by + intro x + simp only [coercivePolynomial,certV_even hr ho x,certZ_even hr ho x,certW_odd hr ho x,neg_sq] + +lemma integral_even_two_Ioi {f : ℝ → ℝ} (hf : Function.Even f) : (∫ x, f x)=2*∫ x in Ioi (0:ℝ), f x := by + have he : (fun x => f |x|)=f := by + funext x + by_cases hx : 0 ≤ x + · rw [abs_of_nonneg hx] + · rw [abs_of_nonpos (le_of_lt (lt_of_not_ge hx)),hf x] + have hh := integral_comp_abs (f := f) + rw [he] at hh + exact hh + +lemma certificate_polynomial_measurable {r s : ℝ → ℝ} (hr : ContDiff ℝ ∞ r) (hs : ContDiff ℝ ∞ s) : + Measurable (fun x => Certificate.WF₂ (certR r x) (certK r s x) (certV r x) (certB r x) (certJ r s x) + (certZ r x) (certL r s x)) := by + have hrm := hr.continuous.measurable + have hsm := hs.continuous.measurable + have hvm : Measurable (certV r) := (contDiff_infty_iff_deriv.mp hr |>.2).continuous.measurable + have hwm : Measurable (certW r) := (contDiff_iteratedDeriv_infty hr 2).continuous.measurable + have hzm : Measurable (certZ r) := (contDiff_iteratedDeriv_infty hr 3).continuous.measurable + have hsdm : Measurable (deriv s) := (contDiff_infty_iff_deriv.mp hs |>.2).continuous.measurable + have hssm : Measurable (iteratedDeriv 2 s) := (contDiff_iteratedDeriv_infty hs 2).continuous.measurable + have hR : Measurable (certR r) := hrm.pow_const 2 + have hK : Measurable (certK r s) := hrm.mul hsm + have hB : Measurable (certB r) := hwm.neg.div hrm + have hJ : Measurable (certJ r s) := hsdm.sub ((hsm.div hrm).mul hvm) + have hL : Measurable (certL r s) := hrm.neg.mul hssm + dsimp only [Certificate.WF₂,Certificate.DF₂,Certificate.F₂R,Certificate.F₂K,Certificate.F₂v, + Certificate.F₂b,Certificate.F₂j,Certificate.F₂,Certificate.F₁,Certificate.Q,Certificate.T] + fun_prop + +theorem gaussian_shape_coercivity {r s U : ℝ → ℝ} {K : ℝ≥0} {d : ℝ} + (hr : BoundedSmooth r) (hs : RegularDatum s) (hshape : BackwardShape r) + (hso : Function.Odd s) (hsa : ∀ x, 0 ≤ deriv s x) + (hsw : ∀ x, 0 ≤ x → iteratedDeriv 2 s x ≤ 0) + (hQ : ∀ x, 0 ≤ x → 0 ≤ r x*deriv s x-s x*deriv r x) + (hU : LipschitzWith K U) (hUe : Function.Even U) (hd : 0 < d) + (hUd : ∀ x, HasDerivAt U (r x-s x+2*d*x) x) : + (1/1000:ℝ)*(∫ x, gaussianLogDensity d U x*quarticMoment r x) ≤ + ∫ x, gaussianLogDensity d U x*coercivePolynomial r x := by + let ρ := gaussianLogDensity d U + have hρ : Continuous ρ := gaussianLogDensity_continuous hU.continuous d + have hρpos : ∀ x, 0 ≤ ρ x := fun x => (gaussianLogDensity_pos d U x).le + have hρe : Function.Even ρ := gaussianLogDensity_even hUe d + have hρd (x : ℝ) : HasDerivAt ρ ((r x-s x)*ρ x) x := by + convert gaussianLogDensity_derivative (d := d) (hUd x) using 1 + first | rfl | ring + obtain ⟨hF,hW⟩ := certificate_growth hr hs hshape hso + have hiV : Integrable (fun x => ρ x*quarticMoment r x) := + gaussianLogDensity_integrable_mul hU (quarticMoment_boundedSmooth hr).smooth.continuous.measurable + (quarticMoment_boundedSmooth hr).exponentialBound hd + have hiP : Integrable (fun x => ρ x*coercivePolynomial r x) := + gaussianLogDensity_integrable_mul hU (coercivePolynomial_boundedSmooth hr).smooth.continuous.measurable + (coercivePolynomial_boundedSmooth hr).exponentialBound hd + have hiD : Integrable (certDivergence r s ρ) := + gaussianLogDensity_integrable_mul hU (certificate_polynomial_measurable hr.smooth hs.smooth) hW hd + have htFlux : Tendsto (certFlux r s ρ) atTop (𝓝 0) := by + unfold certFlux + have hh := gaussianLogDensity_tendsto_mul hU (hr.exponentialBound.mul hF) hd + simpa only [certFlux,ρ,Pi.mul_apply,mul_comm,mul_left_comm,mul_assoc] using hh + have hiZero : (∫ x in Ioi (0:ℝ), certDivergence r s ρ x)=0 := by + have hh := integral_Ioi_of_hasDerivAt_of_tendsto + (cert_flux_continuous hr.smooth hs.smooth hshape hso hρ |>.continuousWithinAt (x := 0)) + (fun x hx => cert_flux_derivative hr.smooth hs.smooth (ne_of_gt (hshape.pos hx)) (hρd x)) + hiD.integrableOn htFlux + simpa only [certFlux,hshape.zero,zero_mul,sub_zero] using hh + have hhalf : (1661507/1521000000:ℝ)*(∫ x in Ioi (0:ℝ), ρ x*quarticMoment r x) ≤ + ∫ x in Ioi (0:ℝ), ρ x*coercivePolynomial r x := by + have hm := integral_mono_ae ((hiV.const_mul (1661507/1521000000:ℝ)).add hiD).integrableOn hiP.integrableOn + (show ∀ᵐ x ∂volume.restrict (Ioi (0:ℝ)), + (1661507/1521000000:ℝ)*(ρ x*quarticMoment r x)+certDivergence r s ρ x ≤ ρ x*coercivePolynomial r x from by + filter_upwards [ae_restrict_mem measurableSet_Ioi] with x hx + have hh := mul_le_mul_of_nonneg_left + (cert_halfLine_coercive hr.smooth hs.smooth hshape hso hsa hsw hQ hx) (hρpos x) + dsimp only [quarticMoment,coercivePolynomial,certDivergence] + nlinarith only [hh]) + simp only [Pi.add_apply] at hm + rw [integral_add (hiV.const_mul _).integrableOn hiD.integrableOn,integral_const_mul,hiZero,add_zero] at hm + exact hm + have hVe : Function.Even (fun x => ρ x*quarticMoment r x) := by + intro x;dsimp only;rw [hρe x,quarticMoment_even hr.smooth hshape.odd x] + have hPe : Function.Even (fun x => ρ x*coercivePolynomial r x) := by + intro x;dsimp only;rw [hρe x,coercivePolynomial_even hr.smooth hshape.odd x] + have hfull : (1661507/1521000000:ℝ)*(∫ x, ρ x*quarticMoment r x) ≤ ∫ x, ρ x*coercivePolynomial r x := by + rw [integral_even_two_Ioi hVe,integral_even_two_Ioi hPe] + nlinarith only [hhalf] + exact (mul_le_mul_of_nonneg_right Certificate.coercivity_constant.le + (integral_nonneg (fun x => mul_nonneg (hρpos x) (by exact pow_nonneg (le_of_lt (hshape.derivative_pos x)) 4)))).trans hfull + +end ZeroTemperatureSK.Heat + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKSupport/Density/GaussianTails.lean b/lean/OAI/Probability/SKSupport/Density/GaussianTails.lean new file mode 100644 index 0000000000000000000000000000000000000000..de81b61ded049dfda6934bc35a9d0a5a7a502dbc --- /dev/null +++ b/lean/OAI/Probability/SKSupport/Density/GaussianTails.lean @@ -0,0 +1,157 @@ +import Mathlib +import OAI.Probability.SKSupport.Density.FiniteForwardRatio +import OAI.Probability.SKSupport.Density.GaussianDecay + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section +namespace ZeroTemperatureSK.Heat + +lemma ExponentialBound.const (a : ℝ) : ExponentialBound (fun _ => a) := + ExponentialBound.of_bounded (A := Real.nnabs a) (fun _ => le_rfl) + +lemma ExponentialBound.neg {f : ℝ → ℝ} (hf : ExponentialBound f) : ExponentialBound (fun x => -f x) := by + obtain ⟨A,K,hA⟩ := hf + exact ⟨A,K,fun x => by simpa only [abs_neg] using hA x⟩ + +lemma ExponentialBound.add {f g : ℝ → ℝ} (hf : ExponentialBound f) (hg : ExponentialBound g) : + ExponentialBound (fun x => f x+g x) := by + obtain ⟨A,K,hA⟩ := hf + obtain ⟨B,J,hB⟩ := hg + refine ⟨A+B,K+J,fun x => ?_⟩ + simp only [NNReal.coe_add] + have hk : Real.exp ((K:ℝ)*|x|) ≤ Real.exp (((K:ℝ)+J)*|x|) := by gcongr;exact le_add_of_nonneg_right J.coe_nonneg + have hj : Real.exp ((J:ℝ)*|x|) ≤ Real.exp (((K:ℝ)+J)*|x|) := by gcongr;exact le_add_of_nonneg_left K.coe_nonneg + calc + |f x+g x| ≤ |f x|+|g x| := abs_add_le _ _ + _ ≤ (A:ℝ)*Real.exp ((K:ℝ)*|x|)+(B:ℝ)*Real.exp ((J:ℝ)*|x|) := add_le_add (hA x) (hB x) + _ ≤ ((A:ℝ)+B)*Real.exp (((K:ℝ)+J)*|x|) := by + rw [add_mul] + exact add_le_add (mul_le_mul_of_nonneg_left hk A.coe_nonneg) (mul_le_mul_of_nonneg_left hj B.coe_nonneg) + +lemma ExponentialBound.sub {f g : ℝ → ℝ} (hf : ExponentialBound f) (hg : ExponentialBound g) : + ExponentialBound (fun x => f x-g x) := by simpa only [sub_eq_add_neg] using hf.add hg.neg + +lemma ExponentialBound.pow {f : ℝ → ℝ} (hf : ExponentialBound f) (n : ℕ) : ExponentialBound (fun x => (f x)^n) := by + induction n with + | zero => simpa only [pow_zero] using ExponentialBound.const 1 + | succ n ih => simpa only [pow_succ] using ih.mul hf + +lemma gaussian_expBound_tendsto_zero {g : ℝ → ℝ} (hg : ExponentialBound g) + {d : ℝ} (hd : 0 < d) : Tendsto (fun x => Real.exp (-d*x^2)*g x) atTop (𝓝 0) := by + obtain ⟨A,K,hA⟩ := hg + have hpow : Tendsto (fun x : ℝ => x^2) atTop atTop := tendsto_pow_atTop (by norm_num) + have he : Tendsto (fun x : ℝ => Real.exp (-(d/2)*x^2)) atTop (𝓝 0) := by + convert Real.tendsto_exp_atBot.comp (tendsto_neg_atTop_atBot.comp (hpow.const_mul_atTop (half_pos hd))) using 1 + first | rfl | (funext x;dsimp only [Function.comp_apply];congr 1;ring) + have hlim := he.const_mul ((A:ℝ)*Real.exp ((K:ℝ)^2/(2*d))) + simp only [mul_zero] at hlim + apply squeeze_zero_norm _ hlim + intro x + simp only [Real.norm_eq_abs,abs_mul,abs_of_pos (Real.exp_pos _)] + calc + Real.exp (-d*x^2)*|g x| ≤ Real.exp (-d*x^2)*((A:ℝ)*Real.exp ((K:ℝ)*|x|)) := + mul_le_mul_of_nonneg_left (hA x) (Real.exp_nonneg _) + _ = (A:ℝ)*Real.exp (-d*x^2+(K:ℝ)*|x|) := by rw [Real.exp_add];ring + _ ≤ (A:ℝ)*Real.exp (((K:ℝ)^2/(2*d)) + (-(d/2)*x^2)) := by + apply mul_le_mul_of_nonneg_left _ A.coe_nonneg + apply Real.exp_le_exp.mpr + linarith [linear_abs_le_quadratic hd (K:ℝ) x] + _ = _ := by rw [Real.exp_add];ring + +end ZeroTemperatureSK.Heat + +end +end +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology ContDiff +noncomputable section +namespace ZeroTemperatureSK.Heat + +lemma BoundedSmooth.regular {r : ℝ → ℝ} (hr : BoundedSmooth r) : RegularDatum r := ⟨hr.smooth,hr.deriv⟩ + +lemma BoundedSmooth.exponentialBound {r : ℝ → ℝ} (hr : BoundedSmooth r) : ExponentialBound r := by + obtain ⟨C,hC⟩ := hr.bound + exact ExponentialBound.of_bounded hC + +lemma certW_odd {r : ℝ → ℝ} (hr : ContDiff ℝ ∞ r) (ho : Function.Odd r) : Function.Odd (certW r) := by + simpa only [certW,iteratedDeriv_succ,iteratedDeriv_zero] using + even_deriv_odd ((contDiff_infty_iff_deriv.mp hr |>.2).differentiable (by simp)) + (odd_deriv_even (hr.differentiable (by simp)) ho) + +lemma certV_even {r : ℝ → ℝ} (hr : ContDiff ℝ ∞ r) (ho : Function.Odd r) : Function.Even (certV r) := + odd_deriv_even (hr.differentiable (by simp)) ho + +lemma certZ_even {r : ℝ → ℝ} (hr : ContDiff ℝ ∞ r) (ho : Function.Odd r) : Function.Even (certZ r) := by + have hh := odd_deriv_even ((contDiff_iteratedDeriv_infty hr 2).differentiable (by simp)) (certW_odd hr ho) + simpa only [certZ,certW,iteratedDeriv_succ] using hh + +lemma odd_zero {r : ℝ → ℝ} (ho : Function.Odd r) : r 0=0 := by + have hh := ho 0 + simp only [neg_zero] at hh + linarith + +lemma cert_flux_continuous {r s ρ : ℝ → ℝ} (hr : ContDiff ℝ ∞ r) (hs : ContDiff ℝ ∞ s) + (hshape : BackwardShape r) (hso : Function.Odd s) (hρ : Continuous ρ) : Continuous (certFlux r s ρ) := by + have hw := contDiff_iteratedDeriv_infty hr 2 + have hbw := quotientExtension_continuous (hw.differentiable (by simp)) (hr.differentiable (by simp)) hshape + have hbs := quotientExtension_continuous (hs.differentiable (by simp)) (hr.differentiable (by simp)) hshape + have hv : Continuous (certV r) := (contDiff_infty_iff_deriv.mp hr |>.2).continuous + have hsd : Continuous (deriv s) := (contDiff_infty_iff_deriv.mp hs |>.2).continuous + have he : certFlux r s ρ = fun x => r x*Certificate.F₂ (certR r x) (certK r s x) (certV r x) + (-quotientExtension (certW r) r x) (deriv s x-quotientExtension s r x*certV r x)*ρ x := by + funext x + by_cases hx : x=0 + · subst x;simp only [certFlux,hshape.zero,zero_mul] + · rw [quotientExtension_eq (odd_zero (certW_odd hr hshape.odd)) hshape.zero hx, + quotientExtension_eq (odd_zero hso) hshape.zero hx] + simp only [certFlux,certB,certJ,neg_div] + rw [he] + dsimp only [Certificate.F₂,Certificate.F₁,certR,certK] + fun_prop + +lemma certificate_growth {r s : ℝ → ℝ} (hr : BoundedSmooth r) (hs : RegularDatum s) + (hshape : BackwardShape r) (hso : Function.Odd s) : + ExponentialBound (fun x => Certificate.F₂ (certR r x) (certK r s x) (certV r x) (certB r x) (certJ r s x)) ∧ + ExponentialBound (fun x => Certificate.WF₂ (certR r x) (certK r s x) (certV r x) (certB r x) (certJ r s x) + (certZ r x) (certL r s x)) := by + obtain ⟨K,hK⟩ := hs.exists_lipschitz + have hsE := exponentialBound_of_lipschitz hK + have hrE := hr.exponentialBound + have hR : ExponentialBound (certR r) := hrE.pow 2 + have hKv : ExponentialBound (certK r s) := hrE.mul hsE + have hv : ExponentialBound (certV r) := hr.deriv.exponentialBound + have hw : BoundedSmooth (certW r) := by simpa only [certW,iteratedDeriv_succ,iteratedDeriv_zero] using hr.deriv.deriv + obtain ⟨J,hJ⟩ := hw.regular.exists_lipschitz + have hbe := exponentialBound_quotient (hw.smooth.differentiable (by simp)) hJ + (odd_zero (certW_odd hr.smooth hshape.odd)) (hr.smooth.differentiable (by simp)) hshape + have hb : ExponentialBound (certB r) := by + unfold certB + simpa only [neg_div] using hbe.neg + have hse := exponentialBound_quotient (hs.smooth.differentiable (by simp)) hK (odd_zero hso) + (hr.smooth.differentiable (by simp)) hshape + have hj : ExponentialBound (certJ r s) := hs.deriv_bounded.exponentialBound.sub (hse.mul hv) + have hz : ExponentialBound (certZ r) := by + simpa only [certZ,iteratedDeriv_succ,iteratedDeriv_zero] using hr.deriv.deriv.deriv.exponentialBound + have hL : ExponentialBound (certL r s) := by + unfold certL + simpa only [iteratedDeriv_succ,iteratedDeriv_zero] using hrE.neg.mul hs.deriv_bounded.deriv.exponentialBound + constructor + · dsimp only [Certificate.F₂,Certificate.F₁] + repeat' first | assumption | apply ExponentialBound.add | apply ExponentialBound.sub | + apply ExponentialBound.mul | apply ExponentialBound.neg | apply ExponentialBound.pow | exact ExponentialBound.const _ + · dsimp only [Certificate.WF₂,Certificate.DF₂,Certificate.F₂R,Certificate.F₂K,Certificate.F₂v, + Certificate.F₂b,Certificate.F₂j,Certificate.F₂,Certificate.F₁,Certificate.Q,Certificate.T] + repeat' first | assumption | apply ExponentialBound.add | apply ExponentialBound.sub | + apply ExponentialBound.mul | apply ExponentialBound.neg | apply ExponentialBound.pow | exact ExponentialBound.const _ + +end ZeroTemperatureSK.Heat + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKSupport/Density/RatioComparison.lean b/lean/OAI/Probability/SKSupport/Density/RatioComparison.lean new file mode 100644 index 0000000000000000000000000000000000000000..d41b34f270efd430dd544740471c35cddfd2fa9e --- /dev/null +++ b/lean/OAI/Probability/SKSupport/Density/RatioComparison.lean @@ -0,0 +1,227 @@ +import Mathlib +import OAI.Probability.SKSupport.Backward.BackwardRescale +import OAI.Probability.SKSupport.Parabolic.ReverseBurgers + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology ContDiff +noncomputable section +namespace ZeroTemperatureSK.Heat + +lemma BackwardShape.zero {r : ℝ → ℝ} (hr : BackwardShape r) : r 0=0 := by + have hh := hr.odd 0 + simp only [neg_zero] at hh + linarith + +lemma BackwardShape.pos {r : ℝ → ℝ} (hr : BackwardShape r) {x : ℝ} (hx : 0 < x) : + 0 < r x := by + simpa only [hr.zero] using strictMono_of_deriv_pos hr.derivative_pos hx + +theorem ReverseBurgers.ratio_nonneg_interior {r s : ℝ → ℝ → ℝ} {H : ℝ} + (hr : ReverseBurgers r H) (hs : SmoothForward s) + (hshape : ∀ t ∈ Icc (0:ℝ) H, BackwardShape (r t)) + (hso : ∀ t, Function.Odd (s t)) + (hsa : ∀ t, 0 ≤ t → ∀ x, 0 ≤ deriv (s t) x) + (hsw : ∀ t, 0 ≤ t → ∀ x, 0 ≤ x → iteratedDeriv 2 (s t) x ≤ 0) + (hi : ∀ x, 0 ≤ x → 0 ≤ ratioWronskian r s 0 x) + {T : ℝ} (hT : 0 ≤ T) (hTH : T < H) : + ∀ x, 0 ≤ x → 0 ≤ ratioWronskian r s T x := by + obtain ⟨R,hR⟩ := hr.family.bound + obtain ⟨V,hV⟩ := hr.family.deriv.bound + obtain ⟨A,hA⟩ := hs.deriv_family.bound + obtain ⟨C,hC,hCs⟩ := hs.family.bound + have hsz (t : ℝ) : s t 0=0 := by + have hh := hso t 0 + simp only [neg_zero] at hh + linarith + have hsp (t : ℝ) (ht : 0 ≤ t) (x : ℝ) (hx : 0 ≤ x) : 0 ≤ s t x := by + have hm := monotone_of_deriv_nonneg ((hs.family.smooth t).differentiable (by simp)) (hsa t ht) + simpa only [hsz] using hm hx + have hlow (t : ℝ) (ht : t ∈ Icc (0:ℝ) T) (x : ℝ) (hx : 0 ≤ x) : + -((R:ℝ)*A+C*((V:ℝ)+R)) ≤ ratioWronskian r s t x := by + have hrsh := hshape t ⟨ht.1,ht.2.trans hTH.le⟩ + have hv : 0 ≤ deriv (r t) x := (hrsh.derivative_pos x).le + have hvb : deriv (r t) x ≤ V := (le_abs_self _).trans (hV t x) + have htangent := tangent_bound_of_concave_odd (hr.family.regular t).smooth hrsh.zero + (fun _ hy => hrsh.second_nonpos _ hy.le) hx + have hrb : r t x ≤ R := (le_abs_self _).trans (hR t x) + have hsb : s t x ≤ C*(1+x) := by + simpa only [abs_of_nonneg hx] using (le_abs_self _).trans (hCs t x) + have hp1 : -((R:ℝ)*A) ≤ r t x*deriv (s t) x := by + have hh := mul_le_mul (hR t x) (hA t x) (abs_nonneg _) R.coe_nonneg + rw [← abs_mul] at hh + exact (neg_le_neg hh).trans (neg_abs_le _) + have hp2 : s t x*deriv (r t) x ≤ C*((V:ℝ)+R) := by + have hh := mul_le_mul_of_nonneg_right hsb hv + have hh₂ := mul_le_mul_of_nonneg_left (show (1+x)*deriv (r t) x ≤ (V:ℝ)+R by nlinarith) hC + nlinarith + dsimp [ratioWronskian] + linarith + intro x hx + apply Parabolic.nonnegative_halfLine_bounded + (u := ratioWronskian r s) (ut := ratioWronskianRate r s) + (ux := fun t => deriv (ratioWronskian r s t)) + (uxx := fun t => iteratedDeriv 2 (ratioWronskian r s t)) + (β := fun t x => -(deriv (r t) x/r t x)) + (c := fun t x => -(deriv (r t) x+deriv (s t) x)) (C := 0) (K := 0) + (M := (R:ℝ)*A+C*((V:ℝ)+R)) (by norm_num) (by positivity) + ((hr.ratio_continuous hs).mono (by intro p hp;exact ⟨⟨hp.1.1,hp.1.2.trans hTH.le⟩,mem_univ _⟩)) + (fun t _ => (((hr.family.regular t).smooth.continuous.mul (hs.deriv_family.regular t).smooth.continuous).sub + ((hs.family.smooth t).continuous.mul (hr.family.deriv.regular t).smooth.continuous))) + (fun t ht x _ => (hr.ratio_time hs ht.1 (ht.2.trans_lt hTH) x).hasDerivWithinAt) + (fun t _ x _ => by + rw [(ratioWronskian_spatial (hr.family.regular t).smooth (hs.family.smooth t) x).deriv] + exact ratioWronskian_spatial (hr.family.regular t).smooth (hs.family.smooth t) x) + (fun t _ x _ => by + convert ratioWronskian_second (hr.family.regular t).smooth (hs.family.smooth t) x using 1 + rw [iteratedDeriv_succ,iteratedDeriv_one, + (ratioWronskian_second (hr.family.regular t).smooth (hs.family.smooth t) x).deriv]) + (fun t ht x hx => ?_) (fun t ht x _ => ?_) (fun t ht x hx => ?_) + hlow hi (fun t ht => ?_) T ⟨hT,le_rfl⟩ x hx + · have hrsh := hshape t ⟨ht.1.le,ht.2.trans hTH.le⟩ + simpa only [zero_mul] using mul_nonpos_of_nonpos_of_nonneg + (neg_nonpos.mpr (div_nonneg (hrsh.derivative_pos x).le (hrsh.pos hx).le)) hx.le + · exact neg_nonpos.mpr (add_nonneg + (hshape t ⟨ht.1.le,ht.2.trans hTH.le⟩ |>.derivative_pos x |>.le) (hsa t ht.1.le x)) + · have hrsh := hshape t ⟨ht.1.le,ht.2.trans hTH.le⟩ + have he := ratioWronskian_equation hs (hr.family.regular t).smooth x (ne_of_gt (hrsh.pos hx)) + have hk : 0 ≤ backwardWronskian r t x := hrsh.wronskian_nonneg x hx.le + have hnon : 0 ≤ r t x*s t x*(2*backwardWronskian r t x/(r t x)^2- + iteratedDeriv 2 (r t) x-iteratedDeriv 2 (s t) x) := + mul_nonneg (mul_nonneg (hrsh.pos hx).le (hsp t ht.1.le x hx.le)) + (by have hh := div_nonneg (mul_nonneg (by norm_num : (0:ℝ)≤2) hk) (sq_nonneg (r t x)) + linarith [hrsh.second_nonpos x hx.le,hsw t ht.1.le x hx.le]) + convert he ▸ hnon using 1 + ring + · dsimp [ratioWronskian] + rw [(hshape t ⟨ht.1,ht.2.trans hTH.le⟩).zero,hsz] + simp + +theorem ReverseBurgers.ratio_nonneg {r s : ℝ → ℝ → ℝ} {H : ℝ} + (hr : ReverseBurgers r H) (hs : SmoothForward s) + (hshape : ∀ t ∈ Icc (0:ℝ) H, BackwardShape (r t)) + (hso : ∀ t, Function.Odd (s t)) + (hsa : ∀ t, 0 ≤ t → ∀ x, 0 ≤ deriv (s t) x) + (hsw : ∀ t, 0 ≤ t → ∀ x, 0 ≤ x → iteratedDeriv 2 (s t) x ≤ 0) + (hi : ∀ x, 0 ≤ x → 0 ≤ ratioWronskian r s 0 x) + {T : ℝ} (hT : T ∈ Icc (0:ℝ) H) : + ∀ x, 0 ≤ x → 0 ≤ ratioWronskian r s T x := by + intro x hx + by_cases hTH : T < H + · exact hr.ratio_nonneg_interior hs hshape hso hsa hsw hi hT.1 hTH x hx + have he : T=H := le_antisymm hT.2 (le_of_not_gt hTH) + subst T + by_cases hH : H=0 + · simpa only [hH] using hi x hx + have hHp : 0 < H := lt_of_le_of_ne hT.1 (Ne.symm hH) + have : NeBot (𝓝[Ico (0:ℝ) H] H) := right_nhdsWithin_Ico_neBot hHp + have hc : ContinuousOn (fun t => ratioWronskian r s t x) (Icc (0:ℝ) H) := + (hr.ratio_continuous hs).comp (continuous_id.prodMk continuous_const).continuousOn + (fun _ ht => ⟨ht,mem_univ _⟩) + apply ge_of_tendsto ((hc H ⟨hHp.le,le_rfl⟩).mono Ico_subset_Icc_self) + filter_upwards [self_mem_nhdsWithin] with t ht + exact hr.ratio_nonneg_interior hs hshape hso hsa hsw hi ht.1 ht.2 x hx + +end ZeroTemperatureSK.Heat + +end +end +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology ContDiff +noncomputable section +namespace ZeroTemperatureSK.Heat + +def datumScore (a : ℝ) (L : ℝ → ℝ) (x : ℝ) := x/a-deriv L x + +lemma forwardScore_eq_datumScore {a : ℝ} {L : ℝ → ℝ} {t : ℝ} (ht : 0 ≤ t) : + forwardScore a L t=datumScore (a+t) (forwardCorrection a L t) := by + funext x + simp only [forwardScore,datumScore,forwardTime,max_eq_left ht] + +lemma forwardScore_initial {a : ℝ} (ha : a ≠ 0) (L : ℝ → ℝ) : + forwardScore a L 0=datumScore a L := by + rw [forwardScore_eq_datumScore le_rfl,add_zero,forwardCorrection_terminal a ha] + +lemma datumScore_deriv {L : ℝ → ℝ} (hL : ContDiff ℝ ∞ L) (a x : ℝ) : + deriv (datumScore a L) x=1/a-iteratedDeriv 2 L x := by + have hh := ((hasDerivAt_id x).div_const a).sub (hasDerivAt_spatialJet hL 1 x) + apply HasDerivAt.deriv + convert hh using 1 + first | rfl | ((try funext y);simp only [datumScore,id_eq,iteratedDeriv_succ,iteratedDeriv_zero,Pi.sub_apply]) + +lemma datumScore_jump {L φ : ℝ → ℝ} (hL : ContDiff ℝ ∞ L) (hφ : ContDiff ℝ ∞ φ) (a δ : ℝ) : + datumScore a (fun x => L x-δ*φ x)=fun x => datumScore a L x+δ*deriv φ x := by + funext x + have hd : deriv (fun x => L x-δ*φ x) x=deriv L x-δ*deriv φ x := by + apply HasDerivAt.deriv + convert (((hL.differentiable (by simp)) x).hasDerivAt.sub + (((hφ.differentiable (by simp)) x).hasDerivAt.const_mul δ)) using 1 + rw [datumScore,hd] + dsimp only [datumScore] + ring + +lemma ratioWronskian_jump {L φ : ℝ → ℝ} (hL : ContDiff ℝ ∞ L) (hφ : ContDiff ℝ ∞ φ) + (a c d x : ℝ) (hc : c ≠ 0) : + ratioWronskian (fun _ y => d*deriv φ y) + (fun _ => datumScore a (fun y => L y-(d-c)*φ y)) 0 x = + d/c*ratioWronskian (fun _ y => c*deriv φ y) (fun _ => datumScore a L) 0 x := by + have hds : ContDiff ℝ ∞ (datumScore a L) := + (contDiff_id.div_const a).sub (contDiff_infty_iff_deriv.mp hL |>.2) + rw [datumScore_jump hL hφ] + have hder (k : ℝ) : deriv (fun y => k*deriv φ y) x=k*iteratedDeriv 2 φ x := by + apply HasDerivAt.deriv + convert (hasDerivAt_spatialJet hφ 1 x).const_mul k using 1 + first | rfl | simp only [iteratedDeriv_succ,iteratedDeriv_zero] + have hd : deriv (fun y => datumScore a L y+(d-c)*deriv φ y) x = + deriv (datumScore a L) x+(d-c)*iteratedDeriv 2 φ x := by + apply HasDerivAt.deriv + convert ((hds.differentiable (by simp)) x).hasDerivAt.add + ((hasDerivAt_spatialJet hφ 1 x).const_mul (d-c)) using 1 + first | rfl | ((try funext y);simp only [iteratedDeriv_succ,iteratedDeriv_zero,Pi.add_apply]) + dsimp only [ratioWronskian] + rw [hd,hder,hder] + field_simp [hc] + ring + +lemma ratioWronskian_first_jump {φ : ℝ → ℝ} (hφ : ContDiff ℝ ∞ φ) + {a c d C : ℝ} (ha : 0 < a) (hc : 0 < c) (hd : 0 < d) + (hshape : BackwardShape (fun x => d*deriv φ x)) {x : ℝ} (hx : 0 ≤ x) : + 0 ≤ ratioWronskian (fun _ y => d*deriv φ y) + (fun _ => datumScore a (fun y => C-(d-c)*φ y)) 0 x := by + rw [ratioWronskian_jump contDiff_const hφ a c d x (ne_of_gt hc)] + have htan := tangent_bound_of_concave_odd + (contDiff_const.mul (contDiff_infty_iff_deriv.mp hφ |>.2)) hshape.zero + (fun y hy => hshape.second_nonpos y hy.le) hx + have hv : deriv (fun y => d*deriv φ y) x=d*iteratedDeriv 2 φ x := by + apply HasDerivAt.deriv + convert (hasDerivAt_spatialJet hφ 1 x).const_mul d using 1 + first | rfl | simp only [iteratedDeriv_succ,iteratedDeriv_zero] + rw [hv] at htan + have ht : 0 ≤ deriv φ x-x*iteratedDeriv 2 φ x := by nlinarith + have he : ratioWronskian (fun _ y => c*deriv φ y) + (fun _ => datumScore a (fun _ => C)) 0 x = c/a*(deriv φ x-x*iteratedDeriv 2 φ x) := by + have hs : datumScore a (fun _ => C)=fun y => y/a := by + funext y + simp [datumScore] + rw [hs] + have hv' : deriv (fun y => c*deriv φ y) x=c*iteratedDeriv 2 φ x := by + apply HasDerivAt.deriv + convert (hasDerivAt_spatialJet hφ 1 x).const_mul c using 1 + first | rfl | simp only [iteratedDeriv_succ,iteratedDeriv_zero] + have hq : deriv (fun y : ℝ => y/a) x=1/a := by + exact ((hasDerivAt_id x).div_const a).deriv + dsimp only [ratioWronskian] + rw [hv',hq] + ring + rw [he] + exact mul_nonneg (div_nonneg hd.le hc.le) (mul_nonneg (div_nonneg hc.le ha.le) ht) + +end ZeroTemperatureSK.Heat + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKSupport/Density/RatioJets.lean b/lean/OAI/Probability/SKSupport/Density/RatioJets.lean new file mode 100644 index 0000000000000000000000000000000000000000..e9a84b9e0be7ddf568f57a052b64712f8ead89f4 --- /dev/null +++ b/lean/OAI/Probability/SKSupport/Density/RatioJets.lean @@ -0,0 +1,99 @@ +import Mathlib +import OAI.Probability.SKSupport.Parabolic.ForwardConstruction +import OAI.Probability.SKSupport.Moments.BurgersJets + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology ContDiff +noncomputable section +namespace ZeroTemperatureSK.Heat + +def ratioWronskian (r s : ℝ → ℝ → ℝ) (t x : ℝ) := + r t x*deriv (s t) x-s t x*deriv (r t) x + +def ratioWronskianRate (r s : ℝ → ℝ → ℝ) (t x : ℝ) := + -burgersRate r t x*deriv (s t) x+r t x*deriv (scoreRate s t) x- + scoreRate s t x*deriv (r t) x+s t x*deriv (burgersRate r t) x + +lemma burgersRate_spatial_deriv {r : ℝ → ℝ → ℝ} {t : ℝ} + (hr : ContDiff ℝ ∞ (r t)) (x : ℝ) : + deriv (burgersRate r t) x=(1/2:ℝ)*iteratedDeriv 3 (r t) x+ + (deriv (r t) x)^2+r t x*iteratedDeriv 2 (r t) x := by + have hd := ((hasDerivAt_spatialJet hr 2 x).const_mul (1/2:ℝ)).add + ((hasDerivAt_spatialJet hr 0 x).mul (hasDerivAt_spatialJet hr 1 x)) + have hd' : HasDerivAt (burgersRate r t) ((1/2:ℝ)*iteratedDeriv 3 (r t) x+ + (deriv (r t) x)^2+r t x*iteratedDeriv 2 (r t) x) x := by + convert hd using 1 <;> first | rfl | ((try funext y); simp only [burgersRate,Pi.add_apply,Pi.mul_apply,iteratedDeriv_succ,iteratedDeriv_zero] <;> ring) + exact hd'.deriv + +lemma ratioWronskian_spatial {r s : ℝ → ℝ → ℝ} {t : ℝ} + (hr : ContDiff ℝ ∞ (r t)) (hs : ContDiff ℝ ∞ (s t)) (x : ℝ) : + HasDerivAt (ratioWronskian r s t) + (r t x*iteratedDeriv 2 (s t) x-s t x*iteratedDeriv 2 (r t) x) x := by + convert ((hasDerivAt_spatialJet hr 0 x).mul (hasDerivAt_spatialJet hs 1 x)).sub + ((hasDerivAt_spatialJet hs 0 x).mul (hasDerivAt_spatialJet hr 1 x)) using 1 <;> + first | rfl | ((try funext y); simp only [ratioWronskian,Pi.sub_apply,Pi.mul_apply,iteratedDeriv_succ,iteratedDeriv_zero] <;> ring) + +lemma ratioWronskian_second {r s : ℝ → ℝ → ℝ} {t : ℝ} + (hr : ContDiff ℝ ∞ (r t)) (hs : ContDiff ℝ ∞ (s t)) (x : ℝ) : + HasDerivAt (deriv (ratioWronskian r s t)) + (deriv (r t) x*iteratedDeriv 2 (s t) x+r t x*iteratedDeriv 3 (s t) x- + deriv (s t) x*iteratedDeriv 2 (r t) x-s t x*iteratedDeriv 3 (r t) x) x := by + have he : deriv (ratioWronskian r s t)=fun y => + r t y*iteratedDeriv 2 (s t) y-s t y*iteratedDeriv 2 (r t) y := + funext (fun y => (ratioWronskian_spatial hr hs y).deriv) + rw [he] + convert ((hasDerivAt_spatialJet hr 0 x).mul (hasDerivAt_spatialJet hs 2 x)).sub + ((hasDerivAt_spatialJet hs 0 x).mul (hasDerivAt_spatialJet hr 2 x)) using 1 <;> + first | rfl | (simp only [iteratedDeriv_succ,iteratedDeriv_zero]; ring) + +lemma ratioWronskian_time {r s : ℝ → ℝ → ℝ} (hs : SmoothForward s) {t : ℝ} (ht : 0 < t) (x : ℝ) + (hrt : HasDerivAt (fun u => r u x) (-burgersRate r t x) t) + (hvt : HasDerivAt (fun u => deriv (r u) x) (-deriv (burgersRate r t) x) t) : + HasDerivAt (fun u => ratioWronskian r s u x) (ratioWronskianRate r s t x) t := by + convert (hrt.mul (hs.time_derivative 1 t ht x)).sub + ((hs.time_derivative 0 t ht x).mul hvt) using 1 <;> + first | rfl | ((try funext y); simp only [ratioWronskian,ratioWronskianRate,Pi.sub_apply,Pi.mul_apply,iteratedDeriv_succ,iteratedDeriv_zero] <;> ring) + +lemma ratioWronskian_equation {r s : ℝ → ℝ → ℝ} (hs : SmoothForward s) {t : ℝ} + (hr : ContDiff ℝ ∞ (r t)) (x : ℝ) (hne : r t x ≠ 0) : + ratioWronskianRate r s t x-(1/2:ℝ)*iteratedDeriv 2 (ratioWronskian r s t) x+ + (deriv (r t) x/r t x)*deriv (ratioWronskian r s t) x+ + (deriv (r t) x+deriv (s t) x)*ratioWronskian r s t x = + r t x*s t x*(2*backwardWronskian r t x/(r t x)^2- + iteratedDeriv 2 (r t) x-iteratedDeriv 2 (s t) x) := by + have hxx : iteratedDeriv 2 (ratioWronskian r s t) x = + deriv (r t) x*iteratedDeriv 2 (s t) x+r t x*iteratedDeriv 3 (s t) x- + deriv (s t) x*iteratedDeriv 2 (r t) x-s t x*iteratedDeriv 3 (r t) x := by + simpa only [iteratedDeriv_succ,iteratedDeriv_zero] using (ratioWronskian_second hr (hs.family.smooth t) x).deriv + rw [hxx,(ratioWronskian_spatial hr (hs.family.smooth t) x).deriv] + simp only [ratioWronskianRate,ratioWronskian,backwardWronskian, + burgersRate_spatial_deriv hr,hs.rate_deriv,burgersRate,scoreRate] + field_simp [hne] + ring + +lemma tangent_bound_of_concave_odd {r : ℝ → ℝ} (hr : ContDiff ℝ ∞ r) + (hzero : r 0=0) (hw : ∀ x, 0 < x → iteratedDeriv 2 r x ≤ 0) + {x : ℝ} (hx : 0 ≤ x) : x*deriv r x ≤ r x := by + let F (x : ℝ) := r x-x*deriv r x + have hd (x : ℝ) : HasDerivAt F (-x*iteratedDeriv 2 r x) x := by + convert (hasDerivAt_spatialJet hr 0 x).sub ((hasDerivAt_id x).mul (hasDerivAt_spatialJet hr 1 x)) using 1 <;> + first | rfl | ((try funext y); simp only [F,id_eq,iteratedDeriv_zero,iteratedDeriv_succ,Pi.mul_apply,Pi.sub_apply] <;> ring) + have hm := monotoneOn_of_hasDerivWithinAt_nonneg (D := Ici (0:ℝ)) (convex_Ici (0:ℝ)) + (show ContinuousOn F (Ici (0:ℝ)) from (continuous_iff_continuousAt.mpr (fun x => (hd x).continuousAt)).continuousOn) + (fun x _ => (hd x).hasDerivWithinAt) (fun x hx => ?_) + · have hh := hm (mem_Ici.mpr le_rfl) (mem_Ici.mpr hx) hx + dsimp [F] at hh + rw [hzero,zero_mul,sub_zero] at hh + linarith + · have hxp : 0 < x := by simpa only [interior_Ici,mem_Ioi] using hx + exact mul_nonneg_of_nonpos_of_nonpos (neg_nonpos.mpr hxp.le) (hw x hxp) + +end ZeroTemperatureSK.Heat + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKSupport/Density/SampleJets.lean b/lean/OAI/Probability/SKSupport/Density/SampleJets.lean new file mode 100644 index 0000000000000000000000000000000000000000..61df2ed6186e675986dff3b8c40333772aba0900 --- /dev/null +++ b/lean/OAI/Probability/SKSupport/Density/SampleJets.lean @@ -0,0 +1,150 @@ +import Mathlib +import OAI.Probability.SKSupport.Density.FiniteDensity +import OAI.Probability.SKSupport.Density.CoerciveMoments +import OAI.Probability.SKSupport.Moments.PositiveGradientError + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology ContDiff +noncomputable section +namespace ZeroTemperatureSK +open Heat +variable {Ω : Type*} [MeasurableSpace Ω] + +lemma positivePath_sample_limit (W : BrownianSystem Ω) (γ : OrderParameter) (t : Time) : + ∀ᵐ ξ ∂W.law, Tendsto (fun n => positivePath W γ n (sampleNNTime n t) ξ) atTop + (𝓝 (diffusion W γ (⟨t,t.property.1⟩:ℝ≥0) ξ)) := by + filter_upwards [diffusion_continuous W γ] with ξ hc + have hh := (hc.tendsto (⟨t,t.property.1⟩:ℝ≥0)).comp (sampleNNTime_limit t) + rw [Metric.tendsto_nhds] at hh ⊢ + intro ε hε + filter_upwards [positivePath_uniform_error W γ t (ε/2) (by linarith),hh (ε/2) (by linarith)] with n hn hξ + have h := hn (sampleNNTime n t) (sampleNNTime_le n t) ξ + apply lt_of_le_of_lt (dist_triangle _ (diffusion W γ (sampleNNTime n t) ξ) _) + simp only [Real.dist_eq,Function.comp_apply] at * + linarith + +def sampleJet (W : BrownianSystem Ω) (γ : OrderParameter) (n : ℕ) (t : Time) (m : ℕ) (ξ : Ω) : ℝ := + iteratedDeriv m (positiveValue γ n (sampleTime n t)) (positivePath W γ n (sampleNNTime n t) ξ) + +def actualJet (W : BrownianSystem Ω) (γ : OrderParameter) (t : Time) (m : ℕ) (ξ : Ω) : ℝ := + iteratedDeriv m (value W γ t) (diffusion W γ (⟨t,t.property.1⟩:ℝ≥0) ξ) + +lemma sampleJet_limit (W : BrownianSystem Ω) (γ : OrderParameter) (t : Time) (m : ℕ) : + ∀ᵐ ξ ∂W.law, Tendsto (fun n => sampleJet W γ n t m ξ) atTop (𝓝 (actualJet W γ t m ξ)) := by + filter_upwards [positivePath_sample_limit W γ t] with ξ hξ + have hp : Tendsto (fun n => ((sampleTime n t:ℝ),positivePath W γ n (sampleNNTime n t) ξ)) atTop + (𝓝 ((t:ℝ),diffusion W γ (⟨t,t.property.1⟩:ℝ≥0) ξ)) := + (((continuous_subtype_val.tendsto t).comp (sampleTime_limit t))).prodMk_nhds hξ + have hpw : Tendsto (fun n => ((sampleTime n t:ℝ),positivePath W γ n (sampleNNTime n t) ξ)) atTop + (𝓝[Icc (0:ℝ) t ×ˢ Set.univ] ((t:ℝ),diffusion W γ (⟨t,t.property.1⟩:ℝ≥0) ξ)) := by + apply tendsto_nhdsWithin_iff.mpr + refine ⟨hp,Eventually.of_forall (fun n => ?_)⟩ + exact ⟨⟨(sampleTime n t).property.1,sampleNNTime_le n t⟩,mem_univ _⟩ + exact (positiveValue_derivative_uniform W γ t.property.1 t.property.2 m).tendsto_comp + (value_derivative_continuousOn W γ t.property.1 t.property.2 m _ ⟨⟨t.property.1,le_rfl⟩,mem_univ _⟩) hpw + +lemma sampleJet_measurable (W : BrownianSystem Ω) (γ : OrderParameter) (n : ℕ) (t : Time) (m : ℕ) : + Measurable (sampleJet W γ n t m) := by + exact (contDiff_iteratedDeriv_infty (positiveValue_regular γ n (sampleTime n t)).smooth m).continuous.measurable.comp + ((positiveDrift γ n).solution_measurable W (sampleNNTime n t)) + +lemma sampleJet_bound (W : BrownianSystem Ω) (γ : OrderParameter) (t : Time) (m : ℕ) : + ∃ C : ℝ, 0 ≤ C ∧ ∀ n ξ, |sampleJet W γ n t (m+1) ξ| ≤ C := by + obtain ⟨C,hC,hb⟩ := positiveValue_uniform_derivative_bounds γ t.property.1 t.property.2 m + exact ⟨C,hC,fun n ξ => hb n (sampleTime n t) ⟨(sampleTime n t).property.1,sampleNNTime_le n t⟩ _⟩ + +end ZeroTemperatureSK + +end +end +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology ContDiff +noncomputable section +namespace ZeroTemperatureSK +open Heat +variable {Ω : Type*} [MeasurableSpace Ω] + +def sampleQuartic (W : BrownianSystem Ω) (γ : OrderParameter) (n : ℕ) (t : Time) (ξ : Ω) : ℝ := + quarticJetPolynomial (positiveCoeff γ n (sampleIndex n t)) (sampleJet W γ n t 2 ξ) + +def sampleCoercive (W : BrownianSystem Ω) (γ : OrderParameter) (n : ℕ) (t : Time) (ξ : Ω) : ℝ := + coerciveJetPolynomial (positiveCoeff γ n (sampleIndex n t)) + (sampleJet W γ n t 2 ξ) (sampleJet W γ n t 3 ξ) (sampleJet W γ n t 4 ξ) + +lemma sample_coercivity (W : BrownianSystem Ω) (γ : OrderParameter) (t : Time) (n : ℕ) + (hi : 0 < sampleIndex n t) : + (1/1000:ℝ)*(∫ ξ, sampleQuartic W γ n t ξ ∂W.law) ≤ ∫ ξ, sampleCoercive W γ n t ξ ∂W.law := by + have hs := (positiveValue_regular γ n (sampleTime n t)).smooth + rw [positiveValue_sample] at hs + have hh := finite_feedback_coercivity W (positiveCoeff γ n) (positiveCoeff_pos γ n) + (positiveCoeff_monotone γ n) (positiveCoeff_bound γ n) + (by exact_mod_cast approxMesh_pos n) hi ((sampleIndex_lt n t).le) + dsimp only at hh + simp_rw [quarticMoment_scaled hs,coercivePolynomial_scaled hs,← positiveValue_sample γ n t] at hh + exact hh + +lemma sampleQuartic_integral_limit (W : BrownianSystem Ω) (γ : OrderParameter) (t : Time) + (ht : ContinuousAt γ.val t) : + Tendsto (fun n => ∫ ξ, sampleQuartic W γ n t ξ ∂W.law) atTop + (𝓝 (∫ ξ, quarticJetPolynomial (γ.val t) (actualJet W γ t 2 ξ) ∂W.law)) := by + let := W.isProbability + obtain ⟨C,hC,hb⟩ := sampleJet_bound W γ t 1 + have hm (n : ℕ) : AEStronglyMeasurable (sampleQuartic W γ n t) W.law := by + have hh := sampleJet_measurable W γ n t 2 + exact (measurable_const.mul (hh.pow_const 4)).aestronglyMeasurable + apply tendsto_integral_of_dominated_convergence (fun _ : Ω => (γ.val t+1)^4*C^4) hm + (integrable_const _) _ _ + · intro n + exact Eventually.of_forall (fun ξ => quarticJetPolynomial_bound + (by rw [abs_of_nonneg (positiveCoeff γ n (sampleIndex n t)).coe_nonneg];exact positiveCoeff_sample_bound γ n t) + (hb n ξ)) + · filter_upwards [sampleJet_limit W γ t 2] with ξ hξ + exact ((positiveCoeff_sample_limit γ t ht).pow 4).mul (hξ.pow 4) + +lemma sampleCoercive_integral_limit (W : BrownianSystem Ω) (γ : OrderParameter) (t : Time) + (ht : ContinuousAt γ.val t) : + Tendsto (fun n => ∫ ξ, sampleCoercive W γ n t ξ ∂W.law) atTop + (𝓝 (∫ ξ, coerciveJetPolynomial (γ.val t) + (actualJet W γ t 2 ξ) (actualJet W γ t 3 ξ) (actualJet W γ t 4 ξ) ∂W.law)) := by + let := W.isProbability + obtain ⟨A,hA,hbA⟩ := sampleJet_bound W γ t 1 + obtain ⟨B,hB,hbB⟩ := sampleJet_bound W γ t 2 + obtain ⟨C,hC,hbC⟩ := sampleJet_bound W γ t 3 + let D := γ.val t+1 + have hm (n : ℕ) : AEStronglyMeasurable (sampleCoercive W γ n t) W.law := by + have h2 := sampleJet_measurable W γ n t 2 + have h3 := sampleJet_measurable W γ n t 3 + have h4 := sampleJet_measurable W γ n t 4 + exact (((measurable_const.mul (h4.pow_const 2)).sub ((measurable_const.mul h2).mul (h3.pow_const 2))).add + (measurable_const.mul (h2.pow_const 4))).aestronglyMeasurable + apply tendsto_integral_of_dominated_convergence (fun _ : Ω => D^2*C^2+12*D^3*A*B^2+6*D^4*A^4) hm + (integrable_const _) _ _ + · intro n + exact Eventually.of_forall (fun ξ => coerciveJetPolynomial_bound + (by rw [abs_of_nonneg (positiveCoeff γ n (sampleIndex n t)).coe_nonneg];exact positiveCoeff_sample_bound γ n t) + (hbA n ξ) (hbB n ξ) (hbC n ξ)) + · filter_upwards [sampleJet_limit W γ t 2,sampleJet_limit W γ t 3,sampleJet_limit W γ t 4] with ξ h2 h3 h4 + have hc := positiveCoeff_sample_limit γ t ht + exact (((hc.pow 2).mul (h4.pow 2)).sub (((hc.pow 3).const_mul 12).mul h2 |>.mul (h3.pow 2))).add + (((hc.pow 4).const_mul 6).mul (h2.pow 4)) + +theorem actual_coercivity (W : BrownianSystem Ω) (γ : OrderParameter) (t : Time) + (ht0 : 0 < (t:ℝ)) (ht : ContinuousAt γ.val t) : + (1/1000:ℝ)*(∫ ξ, quarticJetPolynomial (γ.val t) (actualJet W γ t 2 ξ) ∂W.law) ≤ + ∫ ξ, coerciveJetPolynomial (γ.val t) + (actualJet W γ t 2 ξ) (actualJet W γ t 3 ξ) (actualJet W γ t 4 ξ) ∂W.law := by + apply le_of_tendsto_of_tendsto ((sampleQuartic_integral_limit W γ t ht).const_mul (1/1000:ℝ)) + (sampleCoercive_integral_limit W γ t ht) + filter_upwards [sampleIndex_pos_eventually t ht0] with n hn + exact sample_coercivity W γ t n hn + +end ZeroTemperatureSK + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKSupport/Diffusion/AbsIncrement.lean b/lean/OAI/Probability/SKSupport/Diffusion/AbsIncrement.lean new file mode 100644 index 0000000000000000000000000000000000000000..b8e9f08039f07b752d803dceea69d08c1d0c9f47 --- /dev/null +++ b/lean/OAI/Probability/SKSupport/Diffusion/AbsIncrement.lean @@ -0,0 +1,61 @@ +import Mathlib +import OAI.Probability.SKSupport.Control.ExpectedControlPayoff +import OAI.Probability.SKSupport.Foundations.IntegralIoiMulExpSq + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section +namespace ZeroTemperatureSK +variable {Ω : Type*} [MeasurableSpace Ω] + +lemma BrownianSystem.abs_increment (W : BrownianSystem Ω) (t : ℝ) + (ht0 : 0 ≤ t) (ht1 : t ≤ 1) : + (∫ ω, |W.B 1 ω - W.B (Real.toNNReal t) ω| ∂W.law) = + Real.sqrt (2*(1-t)/Real.pi) := by + have h := (W.brownian.hasLaw_sub 1 (Real.toNNReal t)).integral_comp + (f := abs) (continuous_abs.measurable.aestronglyMeasurable) + change (∫ ω, |W.B 1 ω - W.B (Real.toNNReal t) ω| ∂W.law) = _ at h + rw [h, Gaussian.gaussian_abs_moment] + congr 1 + rw [coe_nndist, Real.dist_eq] + change 2 * |(1:ℝ) - (Real.toNNReal t : ℝ)| / Real.pi = _ + rw [Real.coe_toNNReal _ ht0, abs_of_nonneg (sub_nonneg.mpr ht1)] + +theorem value_terminal_uniform (W : BrownianSystem Ω) (γ : OrderParameter) + (t x : ℝ) (ht0 : 0 ≤ t) (ht1 : t ≤ 1) : + 0 ≤ value W γ t x - |x| ∧ + value W γ t x - |x| ≤ Real.sqrt (2*(1-t)/Real.pi) + + (1/2 : ℝ) * ∫ s in t..1, extend γ.val s := by + let := W.isProbability + refine ⟨sub_nonneg.mpr (abs_le_value W γ t x ht1), ?_⟩ + have hi : Integrable (fun ω => W.B 1 ω - W.B (Real.toNNReal t) ω) W.law := + (W.brownian.integrable_eval 1).sub (W.brownian.integrable_eval _) + have hbound : (∫ ω, |x + W.B 1 ω - W.B (Real.toNNReal t) ω| ∂W.law) ≤ + |x| + Real.sqrt (2*(1-t)/Real.pi) := by + calc + _ ≤ ∫ ω, (|x| + |W.B 1 ω - W.B (Real.toNNReal t) ω|) ∂W.law := by + apply integral_mono (((integrable_const x).add + (W.brownian.integrable_eval 1)).sub (W.brownian.integrable_eval _)).abs + ((integrable_const _).add hi.abs) + intro ω + change |x + W.B 1 ω - W.B (Real.toNNReal t) ω| ≤ + |x| + |W.B 1 ω - W.B (Real.toNNReal t) ω| + simpa only [add_sub_assoc] using abs_add_le x (W.B 1 ω - W.B (Real.toNNReal t) ω) + _ = _ := by rw [integral_add (integrable_const _) hi.abs]; simp [W.abs_increment t ht0 ht1] + have := value_le_expected_abs W γ t x ht1 + linarith + +end ZeroTemperatureSK + +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section + +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKSupport/Diffusion/AffineComparison.lean b/lean/OAI/Probability/SKSupport/Diffusion/AffineComparison.lean new file mode 100644 index 0000000000000000000000000000000000000000..492aa395ef1a27b369523d22b54f92d60f27ff49 --- /dev/null +++ b/lean/OAI/Probability/SKSupport/Diffusion/AffineComparison.lean @@ -0,0 +1,77 @@ +import Mathlib +import OAI.Probability.SKSupport.Parabolic.FullLineComparison + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology ContDiff +noncomputable section +namespace ZeroTemperatureSK.Heat + +lemma AffineSmoothFamily.drift_bound {β : ℝ → ℝ → ℝ} (hβ : AffineSmoothFamily β) : + ∃ K : ℝ, 0 ≤ K ∧ ∀ t x, β t x*x ≤ K*(1+x^2) := by + obtain ⟨C,hC,hb⟩ := hβ.bound + refine ⟨2*C,by positivity,fun t x => ?_⟩ + have hh : β t x*x ≤ C*(1+|x|)*|x| := by + apply (le_abs_self _).trans + rw [abs_mul] + exact mul_le_mul_of_nonneg_right (hb t x) (abs_nonneg x) + have hx : |x| ≤ 1+x^2 := by nlinarith [sq_nonneg (|x|-1),sq_abs x] + have hmul := mul_le_mul_of_nonneg_left hx hC + have he : |x| * |x| = x*x := by nlinarith [sq_abs x] + nlinarith [mul_nonneg hC (sq_nonneg x)] + +lemma affineDrift_nonnegative_full {F β Ft c : ℝ → ℝ → ℝ} {C : ℝ} + (hF : BoundedSmoothFamily F) (hβ : AffineSmoothFamily β) + (hcont : Continuous (fun p : ℝ × ℝ => F p.1 p.2)) + (htime : ∀ t, 0 < t → ∀ x, HasDerivAt (fun s => F s x) (Ft t x) t) + (hc : ∀ t, 0 < t → ∀ x, c t x ≤ C) + (hpde : ∀ t, 0 < t → ∀ x, + Ft t x=(1/2:ℝ)*iteratedDeriv 2 (F t) x+β t x*deriv (F t) x+c t x*F t x) + (hinit : ∀ x, 0 ≤ F 0 x) : ∀ t, 0 ≤ t → ∀ x, 0 ≤ F t x := by + obtain ⟨K,hK,hβb⟩ := hβ.drift_bound + obtain ⟨M,hM⟩ := hF.bound + intro T hT x + apply Parabolic.nonnegative_fullLine_bounded (u := F) (ut := Ft) + (ux := fun t => deriv (F t)) (uxx := fun t => iteratedDeriv 2 (F t)) + (β := β) (c := c) (C := C) (K := K) (M := (M:ℝ)) hK M.coe_nonneg + hcont.continuousOn (fun t _ => (hF.regular t).smooth.continuous) + (fun t ht x => (htime t ht.1 x).hasDerivWithinAt) + (fun t _ x => ((hF.regular t).smooth.differentiable (by simp) x).hasDerivAt) + (fun t _ x => by simpa only [iteratedDeriv_one] using hasDerivAt_spatialJet (hF.regular t).smooth 1 x) + (fun t _ x => hβb t x) (fun t ht x => hc t ht.1 x) + (fun t ht x => by rw [hpde t ht.1 x];ring_nf;exact le_rfl) + (fun t _ x => (neg_le_neg (hM t x)).trans (neg_abs_le _)) hinit T ⟨hT,le_rfl⟩ x + +lemma affineDrift_nonnegative_half {F β Ft c : ℝ → ℝ → ℝ} {C : ℝ} + (hF : BoundedSmoothFamily F) (hβ : AffineSmoothFamily β) + (hcont : Continuous (fun p : ℝ × ℝ => F p.1 p.2)) + (htime : ∀ t, 0 < t → ∀ x, HasDerivAt (fun s => F s x) (Ft t x) t) + (hc : ∀ t, 0 < t → ∀ x, 0 < x → c t x ≤ C) + (hpde : ∀ t, 0 < t → ∀ x, 0 < x → + Ft t x=(1/2:ℝ)*iteratedDeriv 2 (F t) x+β t x*deriv (F t) x+c t x*F t x) + (hzero : ∀ t, 0 ≤ t → 0 ≤ F t 0) + (hinit : ∀ x, 0 ≤ x → 0 ≤ F 0 x) : + ∀ t, 0 ≤ t → ∀ x, 0 ≤ x → 0 ≤ F t x := by + obtain ⟨K,hK,hβb⟩ := hβ.drift_bound + obtain ⟨M,hM⟩ := hF.bound + intro T hT x hx + apply Parabolic.nonnegative_halfLine_bounded (u := F) (ut := Ft) + (ux := fun t => deriv (F t)) (uxx := fun t => iteratedDeriv 2 (F t)) + (β := β) (c := c) (C := C) (K := K) (M := (M:ℝ)) hK M.coe_nonneg + hcont.continuousOn (fun t _ => (hF.regular t).smooth.continuous) + (fun t ht x _ => (htime t ht.1 x).hasDerivWithinAt) + (fun t _ x _ => ((hF.regular t).smooth.differentiable (by simp) x).hasDerivAt) + (fun t _ x _ => by simpa only [iteratedDeriv_one] using hasDerivAt_spatialJet (hF.regular t).smooth 1 x) + (fun t _ x _ => hβb t x) (fun t ht x hx => hc t ht.1 x hx) + (fun t ht x hx => by rw [hpde t ht.1 x hx];ring_nf;exact le_rfl) + (fun t _ x _ => (neg_le_neg (hM t x)).trans (neg_abs_le _)) hinit + (fun t ht => hzero t ht.1) T ⟨hT,le_rfl⟩ x hx + +end ZeroTemperatureSK.Heat + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKSupport/Diffusion/BoundedDiffusionProperties.lean b/lean/OAI/Probability/SKSupport/Diffusion/BoundedDiffusionProperties.lean new file mode 100644 index 0000000000000000000000000000000000000000..1572903d7d57bdb0636a8634f7ae68ed86eeb89b --- /dev/null +++ b/lean/OAI/Probability/SKSupport/Diffusion/BoundedDiffusionProperties.lean @@ -0,0 +1,97 @@ +import Mathlib +import OAI.Probability.SKSupport.Diffusion.PicardDiffusion +import OAI.Probability.SKSupport.Diffusion.ProgressiveBrownian +import OAI.Probability.SKSupport.Regularity.IntegralTimeStep + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section +namespace ZeroTemperatureSK +open WeakIto +variable {Ω : Type*} [mΩ : MeasurableSpace Ω] + +lemma progressive_measurable_at (ℱ : Filtration ℝ≥0 mΩ) {X : ℝ≥0 → Ω → ℝ} + (hX : IsProgressive ℱ X) (t : ℝ≥0) : Measurable[ℱ t] (X t) := + hX.adapted t + +namespace BoundedLipschitzDrift +variable (b : BoundedLipschitzDrift) (W : BrownianSystem Ω) + +lemma solution_adapted (t : ℝ≥0) : + Measurable[Filtration.natural W.B (fun t => (W.measurable t).stronglyMeasurable) t] + (b.solution W.driver t) := + progressive_measurable_at _ (b.solution_progressive _ W.driver_progressive) t + +lemma solution_measurable (t : ℝ≥0) : Measurable (b.solution W.driver t) := + (b.solution_adapted W t).mono + ((Filtration.natural W.B (fun t => (W.measurable t).stronglyMeasurable)).le t) le_rfl + +lemma solution_integrable (t : ℝ≥0) : Integrable (b.solution W.driver t) W.law := by + let := W.isProbability + have hc : Integrable (b.correction W.driver t) W.law := by + apply Integrable.of_bound + ((progressive_joint_measurable _ (b.correction_progressive _ W.driver_progressive)).comp + (measurable_const.prodMk measurable_id)).aestronglyMeasurable + ((b.bound:ℝ)*(t:ℝ)) + exact Eventually.of_forall (b.correction_bound _ W.driver_progressive t) + have hd : Integrable (W.driver t) W.law := + (W.brownian.integrable_eval t).congr (W.driver_indistinguishable.mono (fun _ h => (h t).symm)) + exact hd.add hc + +lemma solution_continuous_ae : ∀ᵐ ω ∂W.law, Continuous (fun t => b.solution W.driver t ω) := by + filter_upwards [W.driver_continuous] with ω hω + exact b.solution_continuous _ W.driver_progressive hω + +def pathDrift (t : ℝ) (ω : Ω) : ℝ := + b.f (Real.toNNReal t) (b.solution W.driver (Real.toNNReal t) ω) + +lemma pathDrift_measurable : Measurable (fun p : ℝ × Ω => b.pathDrift W p.1 p.2) := by + have hx := progressive_joint_measurable _ (b.solution_progressive _ W.driver_progressive) + exact b.measurable.comp + ((measurable_subtype_coe.comp (measurable_real_toNNReal.comp measurable_fst)).prodMk + (hx.comp ((measurable_real_toNNReal.comp measurable_fst).prodMk measurable_snd))) + +lemma pathDrift_bound (t : ℝ) (ω : Ω) : |b.pathDrift W t ω| ≤ b.bound := b.bounded _ _ + +lemma pathDrift_integrable (a c : ℝ) (ω : Ω) : + IntervalIntegrable (fun t => b.pathDrift W t ω) volume a c := by + apply (intervalIntegrable_const (c := (b.bound:ℝ))).mono_fun + ((b.pathDrift_measurable W).comp measurable_prodMk_right).aestronglyMeasurable + exact Eventually.of_forall (fun t => by + simpa only [Function.comp_apply,id_eq,Real.norm_eq_abs,abs_of_nonneg b.bound.coe_nonneg] using b.pathDrift_bound W t ω) + +def displacement (s t : ℝ) (ω : Ω) : ℝ := ∫ r in s..t, b.pathDrift W r ω + +lemma displacement_measurable (s t : ℝ) : Measurable (b.displacement W s t) := + measurable_time_integral (b.pathDrift_measurable W) s t + +lemma displacement_bound (s t : ℝ) (ω : Ω) : + |b.displacement W s t ω| ≤ (b.bound:ℝ)*|t-s| := + intervalIntegral.norm_integral_le_of_norm_le_const + (f := fun r => b.pathDrift W r ω) (C := (b.bound:ℝ)) + (fun r _ => b.pathDrift_bound W r ω) + +lemma solution_increment (s h : ℝ≥0) : ∀ᵐ ω ∂W.law, + b.solution W.driver (s+h) ω = b.solution W.driver s ω+ + (W.B (s+h) ω-W.B s ω)+b.displacement W s (s+h) ω := by + filter_upwards [W.driver_indistinguishable] with ω hω + rw [b.solution_eq _ W.driver_progressive (s+h),b.solution_eq _ W.driver_progressive s,hω,hω] + have he := intervalIntegral.integral_add_adjacent_intervals + (b.pathDrift_integrable W 0 s ω) (b.pathDrift_integrable W s (s+h) ω) + change (∫ r in (0:ℝ)..(s:ℝ), b.pathDrift W r ω)+b.displacement W s (s+h) ω = + ∫ r in (0:ℝ)..((s+h:ℝ≥0):ℝ), b.pathDrift W r ω at he + change W.B (s+h) ω+(∫ r in (0:ℝ)..((s+h:ℝ≥0):ℝ), b.pathDrift W r ω) = + W.B s ω+(∫ r in (0:ℝ)..(s:ℝ), b.pathDrift W r ω)+(W.B (s+h) ω-W.B s ω)+b.displacement W s (s+h) ω + rw [← he] + ring + +end BoundedLipschitzDrift +end ZeroTemperatureSK + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKSupport/Diffusion/CompactDrift.lean b/lean/OAI/Probability/SKSupport/Diffusion/CompactDrift.lean new file mode 100644 index 0000000000000000000000000000000000000000..5e0af6e96c3d18b56cf47585644b800753c5a04d --- /dev/null +++ b/lean/OAI/Probability/SKSupport/Diffusion/CompactDrift.lean @@ -0,0 +1,334 @@ +import Mathlib +import OAI.Probability.SKSupport.Foundations.GradientAbs +import OAI.Probability.SKSupport.Diffusion.ProgressiveBrownian +import OAI.Probability.SKSupport.Diffusion.PicardUniqueness +import OAI.Probability.SKSupport.Regularity.JointRegularity + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology ContDiff +noncomputable section +namespace ZeroTemperatureSK +open Heat + +def stripClamp (T t : ℝ) : ℝ := max 0 (min T t) + +lemma stripClamp_mem {T : ℝ} (hT : 0 ≤ T) (t : ℝ) : stripClamp T t ∈ Icc (0:ℝ) T := + ⟨le_max_left _ _,max_le hT (min_le_left _ _)⟩ + +lemma stripClamp_eq {T t : ℝ} (ht : t ∈ Icc (0:ℝ) T) : stripClamp T t = t := by + simp only [stripClamp,min_eq_right ht.2,max_eq_right ht.1] + +lemma continuous_stripClamp (T : ℝ) : Continuous (stripClamp T) := + continuous_const.max (continuous_const.min continuous_id) + +variable {Ω : Type*} [MeasurableSpace Ω] + +def compactGradient (W : BrownianSystem Ω) (γ : OrderParameter) (T : ℝ) (t x : ℝ) : ℝ := + gradient W γ (stripClamp T t) x + +def compactCoeff (γ : OrderParameter) (T t : ℝ) : ℝ := extend γ.val (stripClamp T t) + +def compactDrift (W : BrownianSystem Ω) (γ : OrderParameter) (T t x : ℝ) : ℝ := + compactCoeff γ T t*compactGradient W γ T t x + +lemma compactGradient_continuous (W : BrownianSystem Ω) (γ : OrderParameter) + {T : ℝ} (hT0 : 0 ≤ T) (hT1 : T < 1) : + Continuous (fun p : ℝ × ℝ => compactGradient W γ T p.1 p.2) := by + have hc := value_derivative_continuousOn W γ hT0 hT1 1 + simp only [iteratedDeriv_one] at hc + apply continuousOn_univ.mp + exact hc.comp (((continuous_stripClamp T).comp continuous_fst).prodMk continuous_snd).continuousOn + (fun p _ => ⟨stripClamp_mem hT0 p.1,mem_univ _⟩) + +lemma compactGradient_bound (W : BrownianSystem Ω) (γ : OrderParameter) + {T : ℝ} (hT0 : 0 ≤ T) (hT1 : T < 1) (t x : ℝ) : + |compactGradient W γ T t x| ≤ 1 := + gradient_abs_le_one W γ _ x ((stripClamp_mem hT0 t).2.trans hT1.le) + +lemma compactCoeff_measurable (γ : OrderParameter) (T : ℝ) : Measurable (compactCoeff γ T) := + γ.measurable_extend.comp (continuous_stripClamp T).measurable + +lemma compactCoeff_bounds (γ : OrderParameter) {T : ℝ} (hT0 : 0 ≤ T) (hT1 : T < 1) (t : ℝ) : + 0 ≤ compactCoeff γ T t ∧ compactCoeff γ T t ≤ γ.val ⟨T,⟨hT0,hT1⟩⟩ := by + have ht := stripClamp_mem hT0 t + have hm : stripClamp T t ∈ Ico (0:ℝ) 1 := ⟨ht.1,ht.2.trans_lt hT1⟩ + simp only [compactCoeff,extend,dite_eq_left hm] + exact ⟨γ.nonneg _,γ.monotone ht.2⟩ + +lemma compactDrift_measurable (W : BrownianSystem Ω) (γ : OrderParameter) + {T : ℝ} (hT0 : 0 ≤ T) (hT1 : T < 1) : + Measurable (fun p : ℝ × ℝ => compactDrift W γ T p.1 p.2) := + ((compactCoeff_measurable γ T).comp measurable_fst).mul + (compactGradient_continuous W γ hT0 hT1).measurable + +lemma compactDrift_bound (W : BrownianSystem Ω) (γ : OrderParameter) + {T : ℝ} (hT0 : 0 ≤ T) (hT1 : T < 1) (t x : ℝ) : + |compactDrift W γ T t x| ≤ γ.val ⟨T,⟨hT0,hT1⟩⟩ := by + have hc := compactCoeff_bounds γ hT0 hT1 t + rw [compactDrift,abs_mul,abs_of_nonneg hc.1] + exact (mul_le_of_le_one_right hc.1 (compactGradient_bound W γ hT0 hT1 t x)).trans hc.2 + +lemma compactGradient_lipschitz (W : BrownianSystem Ω) (γ : OrderParameter) + {T : ℝ} (hT0 : 0 ≤ T) (hT1 : T < 1) : + ∃ L : ℝ≥0, ∀ t, LipschitzWith L (compactGradient W γ T t) := by + obtain ⟨C,hC,hb⟩ := value_uniform_derivative_bounds W γ hT0 hT1 1 + refine ⟨⟨C,hC⟩,fun t => ?_⟩ + apply lipschitzWith_of_nnnorm_deriv_le + · change Differentiable ℝ (deriv (value W γ (stripClamp T t))) + simpa only [iteratedDeriv_one] using (value_contDiff W γ (stripClamp_mem hT0 t).1 + ((stripClamp_mem hT0 t).2.trans_lt hT1)).differentiable_iteratedDeriv 1 (by simp) + · intro x + apply NNReal.coe_le_coe.mp + change |deriv (deriv (value W γ (stripClamp T t))) x| ≤ C + simpa only [iteratedDeriv_succ, + iteratedDeriv_zero] using hb (stripClamp T t) (stripClamp_mem hT0 t) x + +lemma compactDrift_lipschitz (W : BrownianSystem Ω) (γ : OrderParameter) + {T : ℝ} (hT0 : 0 ≤ T) (hT1 : T < 1) : + ∃ L : ℝ≥0, ∀ t, LipschitzWith L (compactDrift W γ T t) := by + obtain ⟨L,hL⟩ := compactGradient_lipschitz W γ hT0 hT1 + let D : ℝ≥0 := ⟨γ.val ⟨T,⟨hT0,hT1⟩⟩,γ.nonneg _⟩ + refine ⟨D*L,fun t => ?_⟩ + apply LipschitzWith.of_dist_le_mul + intro x y + have hg := (hL t).dist_le_mul x y + have hc := compactCoeff_bounds γ hT0 hT1 t + rw [Real.dist_eq,compactDrift,compactDrift,← mul_sub,abs_mul,abs_of_nonneg hc.1, + NNReal.coe_mul,Real.dist_eq] + simp only [Real.dist_eq] at hg + exact (mul_le_mul_of_nonneg_left hg hc.1).trans (by + change compactCoeff γ T t * ((L:ℝ) * |x-y|) ≤ + γ.val ⟨T,⟨hT0,hT1⟩⟩ * (L:ℝ) * |x-y| + rw [mul_assoc] + exact mul_le_mul_of_nonneg_right hc.2 (mul_nonneg L.coe_nonneg (abs_nonneg _))) + +lemma compactDrift_eq (W : BrownianSystem Ω) (γ : OrderParameter) {T t : ℝ} + (ht : t ∈ Icc (0:ℝ) T) (x : ℝ) : + compactDrift W γ T t x = extend γ.val t*gradient W γ t x := by + simp only [compactDrift,compactCoeff,compactGradient,stripClamp_eq ht] + +end ZeroTemperatureSK + +end +end +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section +namespace ZeroTemperatureSK +open WeakIto + +def diffusionHorizon (n : ℕ) : ℝ := 1-1/((n+2:ℕ):ℝ) + +lemma diffusionHorizon_mem (n : ℕ) : diffusionHorizon n ∈ Ico (0:ℝ) 1 := by + have hd : (0:ℝ) < ((n+2:ℕ):ℝ) := by positivity + have hge : (1:ℝ) ≤ ((n+2:ℕ):ℝ) := by exact_mod_cast (by omega : 1 ≤ n+2) + have hh : (1:ℝ)/((n+2:ℕ):ℝ) ≤ 1 := (div_le_one hd).mpr hge + have hp : (0:ℝ) < 1/((n+2:ℕ):ℝ) := by positivity + exact ⟨by unfold diffusionHorizon; linarith,by unfold diffusionHorizon; linarith⟩ + +lemma diffusionHorizon_tendsto : Tendsto diffusionHorizon atTop (𝓝 1) := by + change Tendsto (fun n : ℕ => 1-1/((n+2:ℕ):ℝ)) atTop (𝓝 1) + have hh := (tendsto_const_div_atTop_nhds_zero_nat (1:ℝ)).comp (tendsto_add_atTop_nat 2) + simpa only [diffusionHorizon,sub_zero,Function.comp_apply] using tendsto_const_nhds.sub hh (a := (1:ℝ)) + +lemma eventually_le_diffusionHorizon {t : ℝ} (ht : t < 1) : + ∀ᶠ n : ℕ in atTop, t ≤ diffusionHorizon n := + (diffusionHorizon_tendsto.eventually (eventually_gt_nhds ht)).mono (fun _ h => h.le) + +def diffusionHorizonTime (n : ℕ) : Time := ⟨diffusionHorizon n,diffusionHorizon_mem n⟩ + +variable {Ω : Type*} [mΩ : MeasurableSpace Ω] + +def stripDrift (W : BrownianSystem Ω) (γ : OrderParameter) (T : Time) : BoundedLipschitzDrift where + f := compactDrift W γ T + bound := ⟨γ.val T,γ.nonneg T⟩ + lip := (compactDrift_lipschitz W γ T.property.1 T.property.2).choose + measurable := compactDrift_measurable W γ T.property.1 T.property.2 + bounded := compactDrift_bound W γ T.property.1 T.property.2 + lipschitz := (compactDrift_lipschitz W γ T.property.1 T.property.2).choose_spec + +lemma stripDrift_eq (W : BrownianSystem Ω) (γ : OrderParameter) (T : Time) + {t : ℝ} (ht : t ∈ Icc (0:ℝ) (T:ℝ)) (x : ℝ) : + (stripDrift W γ T).f t x = extend γ.val t*gradient W γ t x := compactDrift_eq W γ ht x + +def localDiffusion (W : BrownianSystem Ω) (γ : OrderParameter) (n : ℕ) : ℝ≥0 → Ω → ℝ := + (stripDrift W γ (diffusionHorizonTime n)).solution W.driver + +lemma localDiffusion_progressive (W : BrownianSystem Ω) (γ : OrderParameter) (n : ℕ) : + IsProgressive (Filtration.natural W.B (fun t => (W.measurable t).stronglyMeasurable)) + (localDiffusion W γ n) := + (stripDrift W γ (diffusionHorizonTime n)).solution_progressive _ W.driver_progressive + +lemma localDiffusion_agree (W : BrownianSystem Ω) (γ : OrderParameter) (m n : ℕ) + (t : ℝ≥0) (hm : (t:ℝ) ≤ diffusionHorizon m) (hn : (t:ℝ) ≤ diffusionHorizon n) (ω : Ω) : + localDiffusion W γ m t ω = localDiffusion W γ n t ω := by + apply (stripDrift W γ (diffusionHorizonTime m)).solution_eq_of_agree + (stripDrift W γ (diffusionHorizonTime n)) _ W.driver_progressive t _ t le_rfl ω + intro s hs x + have hst : (s:ℝ) ≤ (t:ℝ) := hs + rw [stripDrift_eq W γ _ ⟨s.coe_nonneg,hst.trans hm⟩, + stripDrift_eq W γ _ ⟨s.coe_nonneg,hst.trans hn⟩] + +def rawDiffusion (W : BrownianSystem Ω) (γ : OrderParameter) (t : ℝ≥0) (ω : Ω) : ℝ := + atTop.limUnder (fun n => localDiffusion W γ n t ω) + +lemma rawDiffusion_progressive (W : BrownianSystem Ω) (γ : OrderParameter) : + IsProgressive (Filtration.natural W.B (fun t => (W.measurable t).stronglyMeasurable)) + (rawDiffusion W γ) := by + intro t + let ℱ := Filtration.natural W.B (fun t => (W.measurable t).stronglyMeasurable) + have hm (n : ℕ) : StronglyMeasurable[(Subtype.instMeasurableSpace).prod (ℱ t)] + (fun p : Iic t × Ω => localDiffusion W γ n p.1 p.2) := + (localDiffusion_progressive W γ n t).stronglyMeasurable + let : MeasurableSpace Ω := ℱ t + exact (StronglyMeasurable.limUnder hm).measurable + +lemma rawDiffusion_eq_local (W : BrownianSystem Ω) (γ : OrderParameter) (n : ℕ) + (t : ℝ≥0) (ht : (t:ℝ) ≤ diffusionHorizon n) (ω : Ω) : + rawDiffusion W γ t ω = localDiffusion W γ n t ω := by + apply Tendsto.limUnder_eq + apply tendsto_const_nhds.congr' + filter_upwards [eventually_le_diffusionHorizon (ht.trans_lt (diffusionHorizon_mem n).2)] with m hm + exact localDiffusion_agree W γ n m t ht hm ω + +lemma rawDiffusion_eq_integral (W : BrownianSystem Ω) (γ : OrderParameter) + (t : ℝ≥0) (ht : (t:ℝ) < 1) (ω : Ω) : + rawDiffusion W γ t ω = W.driver t ω+∫ s in (0:ℝ)..(t:ℝ), + extend γ.val s*gradient W γ s (rawDiffusion W γ (Real.toNNReal s) ω) := by + obtain ⟨n,hn⟩ := (eventually_le_diffusionHorizon ht).exists + rw [rawDiffusion_eq_local W γ n t hn] + rw [localDiffusion, (stripDrift W γ (diffusionHorizonTime n)).solution_eq _ W.driver_progressive] + congr 1 + apply intervalIntegral.integral_congr + intro s hs + dsimp only + rw [uIcc_of_le t.coe_nonneg] at hs + have hsn : ((Real.toNNReal s):ℝ) ≤ diffusionHorizon n := by + rw [Real.coe_toNNReal _ hs.1] + exact hs.2.trans hn + rw [rawDiffusion_eq_local W γ n (Real.toNNReal s) hsn] + rw [stripDrift_eq W γ _ ⟨(Real.toNNReal s).coe_nonneg,hsn⟩,Real.coe_toNNReal _ hs.1] + rfl + +def beforeOneGradient (W : BrownianSystem Ω) (γ : OrderParameter) (t : ℝ≥0) (x : ℝ) : ℝ := + if (t:ℝ) < 1 then gradient W γ t x else 0 + +lemma beforeOneGradient_measurable (W : BrownianSystem Ω) (γ : OrderParameter) : + Measurable (fun p : ℝ≥0 × ℝ => beforeOneGradient W γ p.1 p.2) := by + let f (n : ℕ) (p : ℝ≥0 × ℝ) := if (p.1:ℝ) ≤ diffusionHorizon n then + compactGradient W γ (diffusionHorizon n) p.1 p.2 else 0 + have hm (n : ℕ) : Measurable (f n) := by + apply Measurable.ite (measurableSet_le (measurable_subtype_coe.comp measurable_fst) measurable_const) + · exact (compactGradient_continuous W γ (diffusionHorizon_mem n).1 + (diffusionHorizon_mem n).2).measurable.comp + ((measurable_subtype_coe.comp measurable_fst).prodMk measurable_snd) + · exact measurable_const + apply measurable_of_tendsto_metrizable hm + apply tendsto_pi_nhds.mpr + intro p + by_cases hp : (p.1:ℝ) < 1 + · apply tendsto_const_nhds.congr' + filter_upwards [eventually_le_diffusionHorizon hp] with n hn + simp only [f,ite_eq_left hn,beforeOneGradient,ite_eq_left hp,compactGradient, + stripClamp_eq ⟨p.1.coe_nonneg,hn⟩] + · apply tendsto_const_nhds.congr' + filter_upwards [] with n + have hn : ¬ (p.1:ℝ) ≤ diffusionHorizon n := + not_le.mpr ((diffusionHorizon_mem n).2.trans_le (not_lt.mp hp)) + simp only [f,ite_eq_right hn,beforeOneGradient,ite_eq_right hp] + +lemma beforeOneGradient_bound (W : BrownianSystem Ω) (γ : OrderParameter) (t : ℝ≥0) (x : ℝ) : + |beforeOneGradient W γ t x| ≤ 1 := by + unfold beforeOneGradient + split_ifs with ht + · exact gradient_abs_le_one W γ _ _ ht.le + · norm_num + +def rawFeedback (W : BrownianSystem Ω) (γ : OrderParameter) (t : ℝ≥0) (ω : Ω) : ℝ := + beforeOneGradient W γ t (rawDiffusion W γ t ω) + +lemma rawFeedback_progressive (W : BrownianSystem Ω) (γ : OrderParameter) : + IsProgressive (Filtration.natural W.B (fun t => (W.measurable t).stronglyMeasurable)) + (rawFeedback W γ) := by + intro t + exact (beforeOneGradient_measurable W γ).comp + ((measurable_subtype_coe.comp measurable_fst).prodMk (rawDiffusion_progressive W γ t)) + +lemma rawFeedback_bound (W : BrownianSystem Ω) (γ : OrderParameter) (t : ℝ≥0) (ω : Ω) : + |rawFeedback W γ t ω| ≤ 1 := beforeOneGradient_bound W γ _ _ + +lemma rawFeedback_eq (W : BrownianSystem Ω) (γ : OrderParameter) (t : ℝ≥0) + (ht : (t:ℝ) < 1) (ω : Ω) : + rawFeedback W γ t ω = gradient W γ t (rawDiffusion W γ t ω) := by + simp only [rawFeedback,beforeOneGradient,ite_eq_left ht] + +lemma rawDrift_integrable (W : BrownianSystem Ω) (γ : OrderParameter) (ω : Ω) : + Integrable (fun s : ℝ => extend γ.val s*rawFeedback W γ (Real.toNNReal s) ω) := by + apply γ.integrable.mul_bdd + (progressive_time_measurable _ (rawFeedback_progressive W γ) ω).aestronglyMeasurable + exact Eventually.of_forall (fun _ => rawFeedback_bound W γ _ _) + +def diffusion (W : BrownianSystem Ω) (γ : OrderParameter) (t : ℝ≥0) (ω : Ω) : ℝ := + W.driver t ω+∫ s in (0:ℝ)..(t:ℝ), extend γ.val s*rawFeedback W γ (Real.toNNReal s) ω + +lemma diffusion_progressive (W : BrownianSystem Ω) (γ : OrderParameter) : + IsProgressive (Filtration.natural W.B (fun t => (W.measurable t).stronglyMeasurable)) + (diffusion W γ) := by + have hm : StronglyAdapted (Filtration.natural W.B (fun t => (W.measurable t).stronglyMeasurable)) + (fun t ω => ∫ s in (0:ℝ)..(t:ℝ), extend γ.val s*rawFeedback W γ (Real.toNNReal s) ω) := + fun t => (progressive_integral_measurable _ (rawFeedback_progressive W γ) t γ.measurable_extend).stronglyMeasurable + have hc (ω : Ω) : Continuous (fun t : ℝ≥0 => + ∫ s in (0:ℝ)..(t:ℝ), extend γ.val s*rawFeedback W γ (Real.toNNReal s) ω) := + (rawDrift_integrable W γ ω).continuous_primitive 0 |>.comp continuous_subtype_val + exact W.driver_progressive.add (hm.isStronglyProgressive_of_continuous hc).isProgressive + +lemma diffusion_eq_raw (W : BrownianSystem Ω) (γ : OrderParameter) (t : ℝ≥0) + (ht : (t:ℝ) < 1) (ω : Ω) : diffusion W γ t ω = rawDiffusion W γ t ω := by + rw [rawDiffusion_eq_integral W γ t ht ω] + unfold diffusion + congr 1 + apply intervalIntegral.integral_congr + intro s hs + dsimp only + rw [uIcc_of_le t.coe_nonneg] at hs + have hs1 : ((Real.toNNReal s):ℝ) < 1 := by rw [Real.coe_toNNReal _ hs.1]; exact hs.2.trans_lt ht + rw [rawFeedback_eq W γ _ hs1,Real.coe_toNNReal _ hs.1] + +lemma diffusion_continuous (W : BrownianSystem Ω) (γ : OrderParameter) : + ∀ᵐ ω ∂W.law, Continuous (fun t => diffusion W γ t ω) := by + filter_upwards [W.driver_continuous] with ω hc + exact hc.add ((rawDrift_integrable W γ ω).continuous_primitive 0 |>.comp continuous_subtype_val) + +lemma diffusion_zero (W : BrownianSystem Ω) (γ : OrderParameter) (ω : Ω) : diffusion W γ 0 ω = 0 := by + simp only [diffusion,NNReal.coe_zero,intervalIntegral.integral_same,W.driver_zero,add_zero] + +theorem diffusion_isDiffusion (W : BrownianSystem Ω) (γ : OrderParameter) : + IsDiffusion W γ (diffusion W γ) := by + refine ⟨diffusion_progressive W γ,?_⟩ + filter_upwards [diffusion_continuous W γ,W.driver_indistinguishable] with ω hc hB + refine ⟨(hc.comp (by fun_prop : Continuous Real.toNNReal)).continuousOn,diffusion_zero W γ ω,?_⟩ + intro t ht + rw [diffusion,hB,Real.coe_toNNReal _ ht.1] + congr 1 + apply intervalIntegral.integral_congr + intro s hs + dsimp only + rw [uIcc_of_le ht.1] at hs + by_cases hs1 : s < 1 + · have hsn : ((Real.toNNReal s):ℝ) < 1 := by rw [Real.coe_toNNReal _ hs.1]; exact hs1 + rw [rawFeedback_eq W γ _ hsn,Real.coe_toNNReal _ hs.1,diffusion_eq_raw W γ _ hsn] + · have hse : s = 1 := le_antisymm (hs.2.trans ht.2) (not_lt.mp hs1) + subst s + have he : extend γ.val 1 = 0 := by simp [extend] + simp only [he,zero_mul] + +end ZeroTemperatureSK + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKSupport/Diffusion/Diffusion.lean b/lean/OAI/Probability/SKSupport/Diffusion/Diffusion.lean new file mode 100644 index 0000000000000000000000000000000000000000..8aff66a74258d30b8b19ec43f4fa701b30119a35 --- /dev/null +++ b/lean/OAI/Probability/SKSupport/Diffusion/Diffusion.lean @@ -0,0 +1,90 @@ +import Mathlib +import OAI.Probability.SKSupport.Moments.StripSquareMoment + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section +namespace ZeroTemperatureSK +open Heat WeakIto +variable {Ω : Type*} [MeasurableSpace Ω] + +lemma independent_gaussian_sum_interval_pos (P : Measure Ω) [IsProbabilityMeasure P] + {Y Z : Ω → ℝ} (hY : Measurable Y) (hZ : Measurable Z) {v : ℝ≥0} (hv : v ≠ 0) + (hLaw : HasLaw Z (gaussianReal 0 v) P) (hi : IndepFun Y Z P) + {a b : ℝ} (hab : a < b) : 0 < P {ξ | Y ξ+Z ξ ∈ Ioo a b} := by + let S : Set (ℝ × ℝ) := {p | p.1+p.2 ∈ Ioo a b} + have hS : MeasurableSet S := measurableSet_Ioo.preimage (measurable_fst.add measurable_snd) + have he := (indepFun_iff_map_prod_eq_prod_map_map hY.aemeasurable hZ.aemeasurable).mp hi + apply pos_iff_ne_zero.mpr + intro hz + have hp : ((P.map Y).prod (gaussianReal 0 v)) S=0 := by + rw [← hLaw.map_eq,← he,Measure.map_apply (hY.prodMk hZ) hS] + exact hz + obtain ⟨y,hy⟩ := (Measure.measure_prod_null hS |>.mp hp).exists + have hy0 := gaussianReal_absolutelyContinuous' 0 hv hy + have hsec : Prod.mk y ⁻¹' S=Ioo (a-y) (b-y) := by + ext z + change (a < y+z ∧ y+z < b) ↔ (a-y < z ∧ z < b-y) + constructor <;> rintro ⟨h1,h2⟩ <;> constructor <;> linarith + rw [hsec,Real.volume_Ioo,ENNReal.ofReal_eq_zero] at hy0 + linarith + +lemma BoundedLipschitzDrift.solution_interval_pos (b : BoundedLipschitzDrift) (W : BrownianSystem Ω) + (t : ℝ≥0) (ht : 0 < (t:ℝ)) {a c : ℝ} (hac : a < c) : + 0 < W.law {ξ | b.solution W.driver t ξ ∈ Ioo a c} := by + let := W.isProbability + have hD : 0 < (b.bound:ℝ)+1 := by positivity + have hw : 0 < (c-a)/(4*((b.bound:ℝ)+1)) := div_pos (sub_pos.mpr hac) (by positivity) + obtain ⟨h,hh0,hh⟩ := exists_between (lt_min ht hw) + have hht : h < (t:ℝ) := (lt_min_iff.mp hh).1 + have hhw : 4*((b.bound:ℝ)+1)*h < c-a := by + have h1 := (lt_div_iff₀ (by positivity : (0:ℝ) < 4*((b.bound:ℝ)+1))).mp (lt_min_iff.mp hh).2 + nlinarith + have hdh : 2*(b.bound:ℝ)*h < c-a := by nlinarith [b.bound.coe_nonneg] + let H : ℝ≥0 := ⟨h,hh0.le⟩ + let S : ℝ≥0 := ⟨(t:ℝ)-h,sub_nonneg.mpr hht.le⟩ + have htime : S+H=t := by apply NNReal.coe_injective;change (t:ℝ)-h+h=t;ring + have hi := adapted_indep_increment W.brownian.toIsPreBrownianReal W.measurable S H (b.solution_adapted W S) + have hLaw := W.brownian.toIsPreBrownianReal.hasLaw_sub (S+H) S + have hv : nndist ((S+H:ℝ≥0):ℝ) (S:ℝ)=H := by + apply NNReal.coe_injective + rw [coe_nndist,Real.dist_eq,NNReal.coe_add,add_sub_cancel_left,abs_of_nonneg H.coe_nonneg] + have hLaw' : HasLaw (fun ξ => W.B (S+H) ξ-W.B S ξ) (gaussianReal 0 H) W.law := by + convert hLaw using 1 + congr 1 + exact hv.symm + have hp := independent_gaussian_sum_interval_pos W.law (b.solution_measurable W S) + ((W.measurable (S+H)).sub (W.measurable S)) (show H ≠ 0 from ne_of_gt hh0) hLaw' hi + (a := a+(b.bound:ℝ)*h) (b := c-(b.bound:ℝ)*h) (by linarith) + apply hp.trans_le + apply measure_mono_ae + filter_upwards [b.solution_increment W S H] with ξ hξ hmem + rw [htime,← NNReal.coe_add,htime] at hξ + have hd := b.displacement_bound W S t ξ + have he : |(t:ℝ)-(S:ℝ)|=h := by change |(t:ℝ)-((t:ℝ)-h)|=h; rw [sub_sub_cancel,abs_of_pos hh0] + rw [he] at hd + rcases abs_le.mp hd with ⟨hdl,hdu⟩ + change a+(b.bound:ℝ)*h < b.solution W.driver S ξ+(W.B (S+H) ξ-W.B S ξ) ∧ + b.solution W.driver S ξ+(W.B (S+H) ξ-W.B S ξ) < c-(b.bound:ℝ)*h at hmem + rw [htime] at hmem + change a < b.solution W.driver t ξ ∧ b.solution W.driver t ξ < c + rw [hξ] + constructor <;> linarith [hmem.1,hmem.2] + +theorem diffusion_interval_pos (W : BrownianSystem Ω) (γ : OrderParameter) (t : Time) + (ht : 0 < (t:ℝ)) {a b : ℝ} (hab : a < b) : + 0 < W.law {ξ | diffusion W γ (⟨t,t.property.1⟩:ℝ≥0) ξ ∈ Ioo a b} := by + have he : diffusion W γ (⟨t,t.property.1⟩:ℝ≥0)=(stripDrift W γ t).solution W.driver (⟨t,t.property.1⟩:ℝ≥0) := + funext (diffusion_eq_strip W γ t _ le_rfl) + rw [he] + exact (stripDrift W γ t).solution_interval_pos W (⟨t,t.property.1⟩:ℝ≥0) ht hab + +end ZeroTemperatureSK + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKSupport/Diffusion/DiffusionStability.lean b/lean/OAI/Probability/SKSupport/Diffusion/DiffusionStability.lean new file mode 100644 index 0000000000000000000000000000000000000000..eba5a4443f2f16e159d29e5bd0dbd1448af510b6 --- /dev/null +++ b/lean/OAI/Probability/SKSupport/Diffusion/DiffusionStability.lean @@ -0,0 +1,203 @@ +import Mathlib +import OAI.Probability.SKSupport.Moments.StripSquareMoment +import OAI.Probability.SKSupport.Regularity.PositiveRegularity +import OAI.Probability.SKSupport.Foundations.RightCoeffApprox + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section +namespace ZeroTemperatureSK.BoundedLipschitzDrift +variable {Ω : Type*} [mΩ : MeasurableSpace Ω] + +lemma solution_stability_on (b b' : BoundedLipschitzDrift) (ℱ : Filtration ℝ≥0 mΩ) + {B : ℝ≥0 → Ω → ℝ} (hB : IsProgressive ℱ B) (T : ℝ≥0) {E : ℝ} (hE : 0 ≤ E) + (ω : Ω) + (he : ∀ t ≤ T, |timePrimitive (b.action B (b'.correction B)) t ω-b'.correction B t ω| ≤ E) + (t : ℝ≥0) (ht : t ≤ T) : + |b.solution B t ω-b'.solution B t ω| ≤ 2*E*Real.exp (b.rate*t) := by + let A : ℝ := ((b.bound:ℝ)+(b'.bound:ℝ))*(T:ℝ) + have hA : 0 ≤ A := by dsimp [A];positivity + have hbase (s : ℝ≥0) (hs : s ≤ T) : |b.correction B s ω-b'.correction B s ω| ≤ A := by + apply (abs_sub _ _).trans + have hb := b.correction_bound ℱ hB s ω + have hb' := b'.correction_bound ℱ hB s ω + have hst : (s:ℝ) ≤ T := hs + dsimp [A] + nlinarith [b.bound.coe_nonneg,b'.bound.coe_nonneg] + have hest (n : ℕ) (s : ℝ≥0) (hs : s ≤ T) : + |b.correction B s ω-b'.correction B s ω| ≤ (2*E+A*(1/2:ℝ)^n)*Real.exp (b.rate*s) := by + induction n generalizing s with + | zero => + simp only [pow_zero,mul_one] + apply (hbase s hs).trans + have hex : 1 ≤ Real.exp (b.rate*s) := Real.one_le_exp (mul_nonneg b.rate_pos.le s.coe_nonneg) + nlinarith + | succ n ih => + have hh := b.timePrimitive_action_sub_estimate ℱ hB (b.correction_progressive ℱ hB) + (b'.correction_progressive ℱ hB) (show 0 ≤ 2*E+A*(1/2:ℝ)^n by positivity) + s ω (fun u hu => ih u (hu.trans hs)) + rw [← b.correction_eq_integral ℱ hB] at hh + have htri := abs_sub_le (b.correction B s ω) + (timePrimitive (b.action B (b'.correction B)) s ω) (b'.correction B s ω) + have her := he s hs + have hex : 1 ≤ Real.exp (b.rate*s) := Real.one_le_exp (mul_nonneg b.rate_pos.le s.coe_nonneg) + rw [pow_succ] + nlinarith [mul_le_mul_of_nonneg_left hex hE] + have hlim : Tendsto (fun n : ℕ => (2*E+A*(1/2:ℝ)^n)*Real.exp (b.rate*t)) atTop + (𝓝 (2*E*Real.exp (b.rate*t))) := by + have hh := tendsto_pow_atTop_nhds_zero_of_lt_one (by norm_num : (0:ℝ) ≤ 1/2) (by norm_num : (1/2:ℝ)<1) + simpa only [mul_zero,add_zero] using (tendsto_const_nhds.add (tendsto_const_nhds.mul hh) (a := 2*E)).mul_const (Real.exp (b.rate*t)) + have hh := ge_of_tendsto hlim (Eventually.of_forall (fun n => hest n t ht)) + simpa only [solution,add_sub_add_left_eq_sub] using hh + +end ZeroTemperatureSK.BoundedLipschitzDrift + +end +end +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section +namespace ZeroTemperatureSK.BoundedLipschitzDrift +variable {Ω : Type*} [mΩ : MeasurableSpace Ω] + +lemma residual_integral_bound (b b' : BoundedLipschitzDrift) (ℱ : Filtration ℝ≥0 mΩ) + {B : ℝ≥0 → Ω → ℝ} (hB : IsProgressive ℱ B) (T : ℝ≥0) {e : ℝ → ℝ} + (hei : IntervalIntegrable e volume 0 T) + (hen : ∀ s ∈ Icc (0:ℝ) T, 0 ≤ e s) + (he : ∀ᵐ s : ℝ, s ∈ Icc (0:ℝ) T → ∀ x, |b.f s x-b'.f s x| ≤ e s) + (t : ℝ≥0) (ht : t ≤ T) (ω : Ω) : + |timePrimitive (b.action B (b'.correction B)) t ω-b'.correction B t ω| ≤ ∫ s in (0:ℝ)..(T:ℝ), e s := by + have hZ := b'.correction_progressive ℱ hB + have hi := progressive_bounded_integrable ℱ (b.action_progressive ℱ hB hZ) (b.action_bound _ _) ω 0 t + have hi' := progressive_bounded_integrable ℱ (b'.action_progressive ℱ hB hZ) (b'.action_bound _ _) ω 0 t + rw [b'.correction_eq_integral ℱ hB,timePrimitive,timePrimitive,← intervalIntegral.integral_sub hi hi'] + calc + _ ≤ ∫ s in (0:ℝ)..(t:ℝ), e s := by + rw [← Real.norm_eq_abs] + apply intervalIntegral.norm_integral_le_of_norm_le t.coe_nonneg _ + (hei.mono_set (by rw [uIcc_of_le t.coe_nonneg,uIcc_of_le T.coe_nonneg];exact Icc_subset_Icc le_rfl ht)) + filter_upwards [he] with s hs hst + have hmem : s ∈ Icc (0:ℝ) T := ⟨hst.1.le,hst.2.trans ht⟩ + change |b.f (Real.toNNReal s) _-b'.f (Real.toNNReal s) _| ≤ e s + rw [Real.coe_toNNReal _ hmem.1] + exact hs hmem _ + _ ≤ _ := by + apply intervalIntegral.integral_mono_interval le_rfl t.coe_nonneg ht _ hei + filter_upwards [ae_restrict_mem measurableSet_Ioc] with s hs + exact hen s ⟨hs.1.le,hs.2⟩ + +lemma solution_stability_integral (b b' : BoundedLipschitzDrift) (ℱ : Filtration ℝ≥0 mΩ) + {B : ℝ≥0 → Ω → ℝ} (hB : IsProgressive ℱ B) (T : ℝ≥0) {e : ℝ → ℝ} + (hei : IntervalIntegrable e volume 0 T) + (hen : ∀ s ∈ Icc (0:ℝ) T, 0 ≤ e s) + (he : ∀ᵐ s : ℝ, s ∈ Icc (0:ℝ) T → ∀ x, |b.f s x-b'.f s x| ≤ e s) + (t : ℝ≥0) (ht : t ≤ T) (ω : Ω) : + |b.solution B t ω-b'.solution B t ω| ≤ + 2*(∫ s in (0:ℝ)..(T:ℝ), e s)*Real.exp (b.rate*t) := by + exact solution_stability_on b b' ℱ hB T + (intervalIntegral.integral_nonneg T.coe_nonneg (fun s hs => hen s hs)) ω + (fun u hu => residual_integral_bound b b' ℱ hB T hei hen he u hu ω) t ht + +end ZeroTemperatureSK.BoundedLipschitzDrift + +end +end +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology ContDiff +noncomputable section +namespace ZeroTemperatureSK +open Heat +variable {Ω : Type*} [MeasurableSpace Ω] + +def positiveDrift (γ : OrderParameter) (n : ℕ) : BoundedLipschitzDrift := + finiteFeedback (regularDatum_softAbs (ne_of_gt (positiveTerminal_pos γ n))) + (softAbs_lipschitz (ne_of_gt (positiveTerminal_pos γ n))) + (positiveCoeff γ n) (approxMesh n) (n+1) 0 + +def positivePath (W : BrownianSystem Ω) (γ : OrderParameter) (n : ℕ) : ℝ≥0 → Ω → ℝ := + (positiveDrift γ n).solution W.driver + +def positiveCoeffError (γ : OrderParameter) (n : ℕ) : ℝ := + ∫ s in (0:ℝ)..1, |positiveGamma γ n s-extend γ.val s| + +lemma positiveCoeffError_nonneg (γ : OrderParameter) (n : ℕ) : 0 ≤ positiveCoeffError γ n := by + exact intervalIntegral.integral_nonneg (by norm_num) (fun _ _ => abs_nonneg _) + +lemma positiveCoeffError_limit (γ : OrderParameter) : Tendsto (positiveCoeffError γ) atTop (𝓝 0) := positiveGamma_L1 γ + +lemma mul_sub_mul_error {a b u v D δ : ℝ} (hδ : 0 ≤ δ) (hD : |a| ≤ D) + (hv : |v| ≤ 1) (huv : |u-v| ≤ δ) : |a*u-b*v| ≤ |a-b|+D*δ := by + calc + _ = |(a-b)*v+a*(u-v)| := by congr 1;ring + _ ≤ |(a-b)*v|+|a*(u-v)| := abs_add_le _ _ + _ = |a-b| * |v|+|a| * |u-v| := by rw [abs_mul,abs_mul] + _ ≤ |a-b| * 1+D*δ := add_le_add (mul_le_mul_of_nonneg_left hv (abs_nonneg _)) + ((mul_le_mul_of_nonneg_left huv (abs_nonneg _)).trans (mul_le_mul_of_nonneg_right hD hδ)) + _ = _ := by ring + +lemma positiveDrift_error (W : BrownianSystem Ω) (γ : OrderParameter) (T : Time) + (n : ℕ) {δ : ℝ} (hδ : 0 ≤ δ) + (hd : ∀ s ∈ Icc (0:ℝ) T, ∀ x, |deriv (positiveValue γ n s) x-gradient W γ s x| ≤ δ) : + ∀ᵐ s : ℝ, s ∈ Icc (0:ℝ) T → ∀ x, + |(stripDrift W γ T).f s x-(positiveDrift γ n).f s x| ≤ + |positiveGamma γ n s-extend γ.val s|+γ.val T*δ := by + filter_upwards [rightCoeff_ae (positiveCoeff γ n) (approxMesh n) (n+1) 0] with s hs hst x + rw [stripDrift_eq W γ T hst] + change |extend γ.val s*gradient W γ s x-rightCoeff (positiveCoeff γ n) (approxMesh n) (n+1) 0 s* + deriv (positiveValue γ n s) x| ≤ _ + rw [hs] + have ha : |extend γ.val s| ≤ γ.val T := by + have hmem : s ∈ Ico (0:ℝ) 1 := ⟨hst.1,hst.2.trans_lt T.property.2⟩ + simp only [extend,dite_eq_left hmem,abs_of_nonneg (γ.nonneg _)] + exact γ.monotone hst.2 + have hu : |deriv (positiveValue γ n s) x| ≤ 1 := by + exact norm_deriv_le_of_lipschitz (finiteValue_lipschitz + (softAbs_lipschitz (ne_of_gt (positiveTerminal_pos γ n))) _ _ _ _ _) (x₀ := x) + simpa only [positiveGamma,abs_sub_comm] using mul_sub_mul_error (b := positiveGamma γ n s) hδ ha hu (by simpa only [abs_sub_comm] using hd s hst x) + +lemma positivePath_error (W : BrownianSystem Ω) (γ : OrderParameter) (T : Time) + (n : ℕ) {δ : ℝ} (hδ : 0 ≤ δ) + (hd : ∀ s ∈ Icc (0:ℝ) T, ∀ x, |deriv (positiveValue γ n s) x-gradient W γ s x| ≤ δ) + (t : ℝ≥0) (ht : (t:ℝ) ≤ T) (ξ : Ω) : + |positivePath W γ n t ξ-diffusion W γ t ξ| ≤ + 2*(positiveCoeffError γ n+γ.val T*(T:ℝ)*δ)*Real.exp ((stripDrift W γ T).rate*T) := by + let e := fun s => |positiveGamma γ n s-extend γ.val s|+γ.val T*δ + have hei (a b : ℝ) : IntervalIntegrable e volume a b := + (((finiteCoeff_intervalIntegrable (positiveCoeff γ n) (approxMesh n) (n+1) 0 a b).sub + γ.integrable.intervalIntegrable).abs).add intervalIntegrable_const + have hen (s : ℝ) : 0 ≤ e s := add_nonneg (abs_nonneg _) (mul_nonneg (γ.nonneg T) hδ) + let TT : ℝ≥0 := ⟨T,T.property.1⟩ + have hh := (stripDrift W γ T).solution_stability_integral (positiveDrift γ n) _ W.driver_progressive TT + (hei 0 T) (fun s _ => hen s) (positiveDrift_error W γ T n hδ hd) t ht ξ + rw [← diffusion_eq_strip W γ T t ht] at hh + rw [abs_sub_comm] at hh + change |positivePath W γ n t ξ-diffusion W γ t ξ| ≤ _ at hh + have hi0 : 0 ≤ ∫ s in (0:ℝ)..(T:ℝ), e s := + intervalIntegral.integral_nonneg T.property.1 (fun s _ => hen s) + have hi : (∫ s in (0:ℝ)..(T:ℝ), e s) ≤ positiveCoeffError γ n+γ.val T*(T:ℝ)*δ := by + have hgi (a b : ℝ) := ((finiteCoeff_intervalIntegrable (positiveCoeff γ n) (approxMesh n) (n+1) 0 a b).sub γ.integrable.intervalIntegrable).abs + dsimp only [e,positiveGamma] + rw [intervalIntegral.integral_add (hgi 0 T) intervalIntegrable_const,intervalIntegral.integral_const] + dsimp only [positiveCoeffError] + have hi := intervalIntegral.integral_mono_interval (a := (0:ℝ)) (b := (T:ℝ)) + (c := (0:ℝ)) (d := 1) le_rfl T.property.1 T.property.2.le + (Eventually.of_forall (fun s => abs_nonneg (positiveGamma γ n s-extend γ.val s))) (hgi 0 1) + dsimp only [e,positiveGamma] at * + simp only [sub_zero,smul_eq_mul] at * + nlinarith only [hi] + have hex : Real.exp ((stripDrift W γ T).rate*t) ≤ Real.exp ((stripDrift W γ T).rate*T) := + Real.exp_le_exp.mpr (mul_le_mul_of_nonneg_left ht (stripDrift W γ T).rate_pos.le) + exact hh.trans (mul_le_mul (mul_le_mul_of_nonneg_left hi (by norm_num)) hex + (Real.exp_pos _).le (mul_nonneg (by norm_num) (hi0.trans hi))) + +end ZeroTemperatureSK + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKSupport/Diffusion/ExpectedBrownianStep.lean b/lean/OAI/Probability/SKSupport/Diffusion/ExpectedBrownianStep.lean new file mode 100644 index 0000000000000000000000000000000000000000..3d25da888fc1b40545f78095db76c8402441b9b2 --- /dev/null +++ b/lean/OAI/Probability/SKSupport/Diffusion/ExpectedBrownianStep.lean @@ -0,0 +1,124 @@ +import Mathlib +import OAI.Probability.SKSupport.Foundations.AdaptedIndepIncrement +import OAI.Probability.SKSupport.Moments.NormalThirdMoment +import OAI.Probability.SKSupport.Foundations.IntegrableCompBoundedDeriv + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section +namespace ZeroTemperatureSK.WeakIto +variable {Ω : Type*} [MeasurableSpace Ω] {P : Measure Ω} {B : ℝ≥0 → Ω → ℝ} + +lemma expected_brownian_step (hB : IsPreBrownianReal B P) + (hm : ∀ t, Measurable (B t)) (s h : ℝ≥0) {Y : Ω → ℝ} + (hY : Measurable[Filtration.natural B (fun t => (hm t).stronglyMeasurable) s] Y) + (hYi : Integrable Y P) {f : ℝ → ℝ} (hf : ContDiff ℝ 3 f) + (C₁ C₂ C₃ : ℝ≥0) (hC₁ : ∀ x, |deriv f x| ≤ C₁) + (hC₂ : ∀ x, |deriv (deriv f) x| ≤ C₂) + (hC₃ : ∀ x, |iteratedDeriv 3 f x| ≤ C₃) : + |(∫ ω, f (Y ω + (B (s+h) ω - B s ω)) ∂P) - + (∫ ω, f (Y ω) ∂P) - + (h:ℝ)/2 * (∫ ω, deriv (deriv f) (Y ω) ∂P)| ≤ + (C₃:ℝ)/6 * ((h:ℝ)*Real.sqrt (h:ℝ)*normalThirdMoment) := by + let := hB.isGaussianProcess.isProbabilityMeasure + have hYm := hY.mono + ((Filtration.natural B (fun t => (hm t).stronglyMeasurable)).le s) le_rfl + have hd : Integrable (fun ω => B (s+h) ω - B s ω) P := + (hB.integrable_eval _).sub (hB.integrable_eval _) + have m2 := hB.isGaussianProcess.hasGaussianLaw_sub (s := s+h) (t := s) |>.memLp_two + have hd2 : Integrable (fun ω => (B (s+h) ω - B s ω)^2) P := by + simpa only [Pi.sub_apply] using m2.integrable_sq + have hd3 : Integrable (fun ω => |B (s+h) ω - B s ω|^3) P := by + have hh := hB.isGaussianProcess.hasGaussianLaw_sub (s := s+h) (t := s) |>.memLp + (p := (3 : ℝ≥0∞)) (by norm_num) + simpa only [Real.norm_eq_abs, Pi.sub_apply] using hh.integrable_norm_pow (by norm_num : 3 ≠ 0) + have hf₁ : ContDiff ℝ 2 (deriv f) := hf.deriv' + have hf₂ : ContDiff ℝ 1 (deriv (deriv f)) := hf₁.deriv' + have hm₁ : AEStronglyMeasurable (fun ω => deriv f (Y ω)) P := + (hf₁.continuous.measurable.comp hYm).aestronglyMeasurable + have hm₂ : AEStronglyMeasurable (fun ω => deriv (deriv f) (Y ω)) P := + (hf₂.continuous.measurable.comp hYm).aestronglyMeasurable + have hi₀ := integrable_comp_of_bounded_deriv (hf.differentiable (by norm_num)) C₁ hC₁ hYi + have hi₁ : Integrable (fun ω => f (Y ω + (B (s+h) ω - B s ω))) P := by + simpa only [Pi.add_apply] using integrable_comp_of_bounded_deriv + (hf.differentiable (by norm_num)) C₁ hC₁ (hYi.add hd) + have hiL := hd.bdd_mul hm₁ (Filter.Eventually.of_forall (fun ω => by + simpa only [Real.norm_eq_abs] using hC₁ (Y ω))) + have hiQ := hd2.bdd_mul hm₂ (Filter.Eventually.of_forall (fun ω => by + simpa only [Real.norm_eq_abs] using hC₂ (Y ω))) + have hLin := integral_adapted_mul_increment hB hm s h (hf₁.continuous.measurable.comp hY) + have hQuad := integral_adapted_mul_increment_sq hB hm s h (hf₂.continuous.measurable.comp hY) + simp only [Function.comp_apply] at hLin hQuad + have hiD : Integrable (fun ω => f (Y ω + (B (s+h) ω - B s ω)) - f (Y ω)) P := hi₁.sub hi₀ + have hiDL : Integrable (fun ω => f (Y ω + (B (s+h) ω - B s ω)) - f (Y ω) - + deriv f (Y ω) * (B (s+h) ω - B s ω)) P := hiD.sub hiL + let R (ω : Ω) := f (Y ω + (B (s+h) ω - B s ω)) - f (Y ω) - + deriv f (Y ω) * (B (s+h) ω - B s ω) - + (1/2:ℝ) * (deriv (deriv f) (Y ω) * (B (s+h) ω - B s ω)^2) + have hiR : Integrable R P := ((hi₁.sub hi₀).sub hiL).sub (hiQ.const_mul (1/2:ℝ)) + have hR : (∫ ω, R ω ∂P) = (∫ ω, f (Y ω + (B (s+h) ω - B s ω)) ∂P) - + (∫ ω, f (Y ω) ∂P) - (h:ℝ)/2 * ∫ ω, deriv (deriv f) (Y ω) ∂P := by + dsimp only [R] + rw [integral_sub hiDL (hiQ.const_mul (1/2:ℝ)), + integral_sub hiD hiL, integral_sub hi₁ hi₀, integral_const_mul, + hLin, hQuad] + ring + rw [← hR] + calc + _ ≤ ∫ ω, |R ω| ∂P := abs_integral_le_integral_abs + _ ≤ ∫ ω, (C₃:ℝ)/6 * |B (s+h) ω - B s ω|^3 ∂P := by + apply integral_mono hiR.abs (hd3.const_mul _) + intro ω + dsimp only [R] + simpa only [mul_assoc] using taylor2_bound hf hC₃ (Y ω) (B (s+h) ω - B s ω) + _ = _ := by rw [integral_const_mul, increment_abs_cube hB s h] + +end ZeroTemperatureSK.WeakIto + +namespace ZeroTemperatureSK.WeakIto + +lemma drift_perturbation_bound {f : ℝ → ℝ} (hf : ContDiff ℝ 2 f) + (C : ℝ≥0) (hC : ∀ x, |deriv (deriv f) x| ≤ C) (x d a : ℝ) : + |f (x+d+a) - f (x+d) - deriv f x*a| ≤ (C:ℝ)*(|d|+|a|)*|a| := by + have hfd : ContDiff ℝ 1 (deriv f) := hf.deriv' + have hl : LipschitzWith C (deriv f) := lipschitzWith_of_nnnorm_deriv_le + (hfd.differentiable (by norm_num)) + (fun z => show ‖deriv (deriv f) z‖₊ ≤ C from by exact_mod_cast hC z) + let g : ℝ → ℝ := fun z => f z - deriv f x*z + have hgd (z : ℝ) : HasDerivAt g (deriv f z-deriv f x) z := by + have h1 : HasDerivAt f (deriv f z) z := (hf.differentiable (by norm_num) z).hasDerivAt + have h2 : HasDerivAt (fun t : ℝ => deriv f x*t) (deriv f x) z := by + simpa using (hasDerivAt_id z).const_mul (deriv f x) + exact h1.sub h2 + have hb (z : ℝ) (hz : z ∈ Set.uIcc (x+d) (x+d+a)) : + ‖deriv f z - deriv f x‖ ≤ (C:ℝ)*(|d|+|a|) := by + have hh := abs_sub_left_of_mem_uIcc hz + rw [add_sub_cancel_left] at hh + have hh' : |z-x| ≤ |d|+|a| := by + have := abs_add_le (z-(x+d)) d + have he : z-(x+d)+d = z-x := by ring + rw [he] at this + linarith + have hg := hl.norm_sub_le z x + simp only [Real.norm_eq_abs] at hg ⊢ + exact hg.trans (mul_le_mul_of_nonneg_left hh' C.coe_nonneg) + have hmv := (convex_uIcc (x+d) (x+d+a)).norm_image_sub_le_of_norm_hasDerivWithin_le + (fun z _ => (hgd z).hasDerivWithinAt) hb left_mem_uIcc right_mem_uIcc + simp only [g, Real.norm_eq_abs, add_sub_cancel_left] at hmv + convert hmv using 1 + congr 1 + ring + +end ZeroTemperatureSK.WeakIto + +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKSupport/Diffusion/ExpectedFeedbackStep.lean b/lean/OAI/Probability/SKSupport/Diffusion/ExpectedFeedbackStep.lean new file mode 100644 index 0000000000000000000000000000000000000000..eae5e661b57469ebc0779af9e07291d5af04c4aa --- /dev/null +++ b/lean/OAI/Probability/SKSupport/Diffusion/ExpectedFeedbackStep.lean @@ -0,0 +1,250 @@ +import Mathlib +import OAI.Probability.SKSupport.Foundations.ControlledState +import OAI.Probability.SKSupport.Foundations.ElementaryControl + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section +namespace ZeroTemperatureSK.WeakIto +variable {Ω : Type*} [mΩ : MeasurableSpace Ω] {P : Measure Ω} {B : ℝ≥0 → Ω → ℝ} + +lemma expected_feedback_step (hB : IsPreBrownianReal B P) + (hm : ∀ t, Measurable (B t)) (s h c : ℝ≥0) {Y : Ω → ℝ} + (hY : Measurable[Filtration.natural B (fun t => (hm t).stronglyMeasurable) s] Y) + (hYi : Integrable Y P) {F D : ℝ → ℝ → ℝ} (hf : ∀ t, ContDiff ℝ 3 (F t)) + (C₂ C₃ Ct L : ℝ≥0) (hC₁ : ∀ t z, |deriv (F t) z| ≤ 1) + (hC₂ : ∀ t z, |deriv (deriv (F t)) z| ≤ C₂) + (hC₃ : ∀ t z, |iteratedDeriv 3 (F t) z| ≤ C₃) + (hDm : Measurable (D s)) (hCt : ∀ z, |D s z| ≤ Ct) + (hD : ∀ r ∈ Set.Icc (s:ℝ) ((s:ℝ)+(h:ℝ)), ∀ z, + HasDerivWithinAt (fun t => F t z) (D r z) + (Set.Icc (s:ℝ) ((s:ℝ)+(h:ℝ))) r) + (hL : ∀ r ∈ Set.Icc (s:ℝ) ((s:ℝ)+(h:ℝ)), ∀ z y, + |D r z-D s y| ≤ (L:ℝ)*(|r-(s:ℝ)|+|z-y|)) + (hPDE : ∀ z, D s z+(1/2:ℝ)*deriv (deriv (F s)) z+ + (c:ℝ)/2*(deriv (F s) z)^2 = 0) : + |(∫ ω, F ((s:ℝ)+(h:ℝ)) + (Y ω+(B (s+h) ω-B s ω)+(c:ℝ)*(h:ℝ)*deriv (F s) (Y ω)) ∂P) - + (∫ ω, F s (Y ω) ∂P) - + (c:ℝ)*(h:ℝ)/2*(∫ ω, (deriv (F s) (Y ω))^2 ∂P)| ≤ + verificationError c C₂ C₃ L h := by + let := hB.isGaussianProcess.isProbabilityMeasure + have hYm := hY.mono ((Filtration.natural B (fun t => (hm t).stronglyMeasurable)).le s) le_rfl + have hfd : ContDiff ℝ 2 (deriv (F s)) := (hf s).deriv' + have hfm : Measurable (fun ω => deriv (F s) (Y ω)) := hfd.continuous.measurable.comp hYm + let A (ω : Ω) := (c:ℝ)*(h:ℝ)*deriv (F s) (Y ω) + have hAm : Measurable A := hfm.const_mul _ + have hAb : ∀ ω, |A ω| ≤ (c:ℝ)*(h:ℝ) := by + intro ω + dsimp only [A] + rw [abs_mul, abs_mul, abs_of_nonneg c.coe_nonneg, abs_of_nonneg h.coe_nonneg] + nlinarith [mul_le_mul_of_nonneg_left (hC₁ s (Y ω)) (mul_nonneg c.coe_nonneg h.coe_nonneg)] + have hG := expected_time_space_step hB hm s h hY hYi hAm c hAb hf + 1 C₂ C₃ Ct L hC₁ hC₂ hC₃ hDm hCt hD hL + have hui : Integrable (fun ω => (deriv (F s) (Y ω))^2) P := by + apply Integrable.of_bound (hfm.pow_const 2).aestronglyMeasurable 1 + filter_upwards [] with ω + rw [Real.norm_eq_abs, abs_pow] + simpa using pow_le_pow_left₀ (abs_nonneg _) (hC₁ s (Y ω)) 2 + have hDi : Integrable (fun ω => D s (Y ω)) P := Integrable.of_bound + (hDm.comp hYm).aestronglyMeasurable Ct (Filter.Eventually.of_forall (fun ω => by + simpa only [Real.norm_eq_abs] using hCt (Y ω))) + have hfdd : ContDiff ℝ 1 (deriv (deriv (F s))) := hfd.deriv' + have hddi : Integrable (fun ω => deriv (deriv (F s)) (Y ω)) P := Integrable.of_bound + (hfdd.continuous.measurable.comp hYm).aestronglyMeasurable C₂ + (Filter.Eventually.of_forall (fun ω => by simpa only [Real.norm_eq_abs] using hC₂ s (Y ω))) + have hPe : (∫ ω, D s (Y ω)+(1/2:ℝ)*deriv (deriv (F s)) (Y ω)+ + (c:ℝ)/2*(deriv (F s) (Y ω))^2 ∂P) = 0 := by + have he : (fun ω => D s (Y ω)+(1/2:ℝ)*deriv (deriv (F s)) (Y ω)+ + (c:ℝ)/2*(deriv (F s) (Y ω))^2) = fun _ => (0:ℝ) := funext (fun ω => hPDE (Y ω)) + rw [he, integral_zero] + have hsplit := integral_add (hDi.add (hddi.const_mul (1/2:ℝ))) (hui.const_mul ((c:ℝ)/2)) + simp only [Pi.add_apply] at hsplit + rw [hsplit] at hPe + have hsplit' := integral_add hDi (hddi.const_mul (1/2:ℝ)) + rw [hsplit', integral_const_mul, integral_const_mul] at hPe + have hAe : (∫ ω, deriv (F s) (Y ω)*A ω ∂P) = + (c:ℝ)*(h:ℝ)*(∫ ω, (deriv (F s) (Y ω))^2 ∂P) := by + rw [← integral_const_mul] + apply integral_congr_ae + filter_upwards [] with ω + dsimp only [A] + ring + rw [hAe] at hG + have hid : (c:ℝ)*(h:ℝ)*(∫ ω, (deriv (F s) (Y ω))^2 ∂P) + + (h:ℝ)*((∫ ω, D s (Y ω) ∂P)+(1/2:ℝ)*(∫ ω, deriv (deriv (F s)) (Y ω) ∂P)) = + (c:ℝ)*(h:ℝ)/2*(∫ ω, (deriv (F s) (Y ω))^2 ∂P) := by + have he := congrArg (fun z : ℝ => (h:ℝ)*z) hPe + nlinarith + rw [sub_sub] at hG + rw [hid] at hG + exact hG + +end ZeroTemperatureSK.WeakIto + +namespace ZeroTemperatureSK.WeakIto +variable {Ω : Type*} [mΩ : MeasurableSpace Ω] {P : Measure Ω} {B : ℝ≥0 → Ω → ℝ} + +lemma feedback_controlledState_grid (hm : ∀ t, Measurable (B t)) (h c : ℝ≥0) + {u : ℝ → ℝ → ℝ} (hum : ∀ t, Measurable (u t)) (hub : ∀ t z, |u t z| ≤ 1) + (x : ℝ) (n k : ℕ) (hk : k ≤ n) (ω : Ω) : + controlledState B + (elementaryControl h (fun i ω => u ((i:ℝ≥0)*h) (feedbackEuler B h c u x i ω)) n) + c x ((k:ℝ≥0)*h) ω = feedbackEuler B h c u x k ω := by + let a (i : ℕ) (ω : Ω) := u ((i:ℝ≥0)*h) (feedbackEuler B h c u x i ω) + have hap : IsProgressive (Filtration.natural B (fun t => (hm t).stronglyMeasurable)) + (elementaryControl h a n) := elementaryControl_progressive _ h + (fun i => (hum _).comp (feedbackEuler_adapted hm h c hum x i)) n + have ham := progressive_joint_measurable _ hap + have hab : ∀ t ω, |elementaryControl h a n t ω| ≤ 1 := + elementaryControl_bound h (fun i ω => hub _ _) n + induction k with + | zero => simp [controlledState_zero, feedbackEuler] + | succ k IH => + have hk' : k < n := by omega + have ht : ((k+1:ℕ):ℝ≥0)*h = (k:ℝ≥0)*h+h := by push_cast; ring + change controlledState B (elementaryControl h a n) c x (((k+1:ℕ):ℝ≥0)*h) ω = _ + rw [ht, controlledState_increment ham hab c x ((k:ℝ≥0)*h) h ω] + have he : stepDrift (fun r => elementaryControl h a n (Real.toNNReal r)) + ((k:ℝ≥0)*h) h c ω = (h:ℝ)*((c:ℝ)*a k ω) := by + exact elementaryControl_integral_on_step h a n k hk' (fun z => (c:ℝ)*z) ω + change stepDrift (fun r => elementaryControl h a n (Real.toNNReal r)) + (↑((k:ℝ≥0)*h)) h c ω = (h:ℝ)*((c:ℝ)*a k ω) at he + have hIH : controlledState B (elementaryControl h a n) c x ((k:ℝ≥0)*h) ω = + feedbackEuler B h c u x k ω := IH (by omega) + rw [he, hIH] + simp only [feedbackEuler, ht, a] + ring + +omit mΩ in +lemma elementary_stepCost (h c : ℝ≥0) (a : ℕ → Ω → ℝ) (n k : ℕ) (hk : k < n) (ω : Ω) : + stepCost (fun r => elementaryControl h a n (Real.toNNReal r)) ((k:ℝ≥0)*h) h c ω = + (c:ℝ)*(h:ℝ)/2*(a k ω)^2 := by + unfold stepCost + rw [elementaryControl_integral_on_step h a n k hk (fun z => (c:ℝ)*z^2) ω] + ring + +end ZeroTemperatureSK.WeakIto + +namespace ZeroTemperatureSK.WeakIto +variable {Ω : Type*} [mΩ : MeasurableSpace Ω] {P : Measure Ω} {B : ℝ≥0 → Ω → ℝ} + +lemma finite_feedback_verification (hB : IsPreBrownianReal B P) + (hm : ∀ t, Measurable (B t)) (h c : ℝ≥0) (x : ℝ) (n : ℕ) + {F D : ℝ → ℝ → ℝ} (hf : ∀ t, ContDiff ℝ 3 (F t)) + (C₂ C₃ Ct L : ℝ≥0) (hC₁ : ∀ t z, |deriv (F t) z| ≤ 1) + (hC₂ : ∀ t z, |deriv (deriv (F t)) z| ≤ C₂) + (hC₃ : ∀ t z, |iteratedDeriv 3 (F t) z| ≤ C₃) + (hDm : ∀ t, Measurable (D t)) (hCt : ∀ t z, |D t z| ≤ Ct) + (hD : ∀ r ∈ Set.Icc (0:ℝ) ((n:ℝ)*(h:ℝ)), ∀ z, + HasDerivWithinAt (fun t => F t z) (D r z) + (Set.Icc (0:ℝ) ((n:ℝ)*(h:ℝ))) r) + (hL : ∀ r ∈ Set.Icc (0:ℝ) ((n:ℝ)*(h:ℝ)), + ∀ s ∈ Set.Icc (0:ℝ) ((n:ℝ)*(h:ℝ)), ∀ z y, + |D r z-D s y| ≤ (L:ℝ)*(|r-s|+|z-y|)) + (hPDE : ∀ t ∈ Set.Icc (0:ℝ) ((n:ℝ)*(h:ℝ)), ∀ z, + D t z+(1/2:ℝ)*deriv (deriv (F t)) z+(c:ℝ)/2*(deriv (F t) z)^2 = 0) : + let u := fun t => deriv (F t) + let α := elementaryControl h (fun k ω => + u ((k:ℝ≥0)*h) (feedbackEuler B h c u x k ω)) n + F 0 x - (n:ℝ)*verificationError c C₂ C₃ L h ≤ + (∫ ω, F ((n:ℝ)*(h:ℝ)) (controlledState B α c x ((n:ℝ≥0)*h) ω) ∂P) - + (∫ ω, stepCost (fun r => α (Real.toNNReal r)) 0 ((n:ℝ)*(h:ℝ)) c ω ∂P) := by + let := hB.isGaussianProcess.isProbabilityMeasure + let u := fun t => deriv (F t) + let a (k : ℕ) (ω : Ω) := u ((k:ℝ≥0)*h) (feedbackEuler B h c u x k ω) + let α := elementaryControl h a n + have hum : ∀ t, Measurable (u t) := fun t => (show ContDiff ℝ 2 (deriv (F t)) from (hf t).deriv').continuous.measurable + have hap : IsProgressive (Filtration.natural B (fun t => (hm t).stronglyMeasurable)) α := + elementaryControl_progressive _ h (fun k => (hum _).comp (feedbackEuler_adapted hm h c hum x k)) n + have ham := progressive_joint_measurable _ hap + have hab : ∀ t ω, |α t ω| ≤ 1 := elementaryControl_bound h (fun k ω => hC₁ _ _) n + let A (r : ℝ) := α (Real.toNNReal r) + have hAm : Measurable (fun p : ℝ × Ω => A p.1 p.2) := + ham.comp (measurable_fst.real_toNNReal.prodMk measurable_snd) + have hAb : ∀ r ω, |A r ω| ≤ 1 := fun r ω => hab _ ω + let Q (k : ℕ) := (∫ ω, F ((k:ℝ)*(h:ℝ)) (controlledState B α c x ((k:ℝ≥0)*h) ω) ∂P) - + (∫ ω, stepCost A 0 ((k:ℝ)*(h:ℝ)) c ω ∂P) + have hgrid (k : ℕ) (hk : k ≤ n) (ω : Ω) : + controlledState B α c x ((k:ℝ≥0)*h) ω = feedbackEuler B h c u x k ω := + feedback_controlledState_grid hm h c hum hC₁ x n k hk ω + have hstep (k : ℕ) (hk : k < n) : -(Q (k+1)) - (-(Q k)) - 0 ≤ verificationError c C₂ C₃ L h := by + let s : ℝ≥0 := (k:ℝ≥0)*h + have hs : (s:ℝ) ∈ Set.Icc (0:ℝ) ((n:ℝ)*(h:ℝ)) := by + constructor + · exact s.coe_nonneg + · dsimp only [s]; push_cast; gcongr + have hsub : Set.Icc (s:ℝ) ((s:ℝ)+(h:ℝ)) ⊆ Set.Icc (0:ℝ) ((n:ℝ)*(h:ℝ)) := by + intro r hr + refine ⟨s.coe_nonneg.trans hr.1, hr.2.trans ?_⟩ + have hn : (k:ℝ)+1 ≤ (n:ℝ) := by exact_mod_cast (by omega : k+1 ≤ n) + dsimp only [s]; push_cast + nlinarith [mul_le_mul_of_nonneg_right hn h.coe_nonneg] + have hg := expected_feedback_step hB hm s h c + (controlledState_adapted hm hap c x s) (controlledState_integrable hB ham hab c x s) + hf C₂ C₃ Ct L hC₁ hC₂ hC₃ (hDm s) (hCt s) + (fun r hr z => (hD r (hsub hr) z).mono hsub) + (fun r hr z y => hL r (hsub hr) s hs z y) (hPDE s hs) + have ht : s+h = ((k+1:ℕ):ℝ≥0)*h := by dsimp only [s]; push_cast; ring + have hnext (ω : Ω) : controlledState B α c x s ω+(B (s+h) ω-B s ω)+ + (c:ℝ)*(h:ℝ)*deriv (F s) (controlledState B α c x s ω) = + controlledState B α c x (((k+1:ℕ):ℝ≥0)*h) ω := by + rw [hgrid (k+1) (by omega)] + change controlledState B α c x ((k:ℝ≥0)*h) ω+_+_ = _ + rw [hgrid k hk.le] + simp only [feedbackEuler, ht, s, u, NNReal.coe_mul] + have hK : (∫ ω, stepCost A 0 ((s:ℝ)+(h:ℝ)) c ω ∂P) = + (∫ ω, stepCost A 0 s c ω ∂P)+ + (c:ℝ)*(h:ℝ)/2*(∫ ω, (deriv (F s) (controlledState B α c x s ω))^2 ∂P) := by + have he : stepCost A 0 ((s:ℝ)+(h:ℝ)) c = fun ω => + stepCost A 0 s c ω+stepCost A s h c ω := funext (stepCost_add hAm hAb c s h) + rw [he, integral_add (stepCost_integrable hAm hAb 0 s c s.coe_nonneg c.coe_nonneg) + (stepCost_integrable hAm hAb s h c h.coe_nonneg c.coe_nonneg)] + congr 1 + rw [← integral_const_mul] + apply integral_congr_ae + filter_upwards [] with ω + have hh := elementary_stepCost h c a n k hk ω + change stepCost A (s:ℝ) h c ω = (c:ℝ)*(h:ℝ)/2*(a k ω)^2 at hh + rw [hh] + congr 2 + change a k ω = u ((k:ℝ≥0)*h) (controlledState B α c x ((k:ℝ≥0)*h) ω) + rw [hgrid k hk.le] + have heF : (fun ω => F ((s:ℝ)+(h:ℝ)) + (controlledState B α c x s ω+(B (s+h) ω-B s ω)+ + (c:ℝ)*(h:ℝ)*deriv (F s) (controlledState B α c x s ω))) = + fun ω => F (((k+1:ℕ):ℝ)*(h:ℝ)) (controlledState B α c x (((k+1:ℕ):ℝ≥0)*h) ω) := by + funext ω + rw [hnext] + congr 1 + dsimp only [s]; push_cast; ring + rw [heF] at hg + have htime : ((k+1:ℕ):ℝ)*(h:ℝ) = (s:ℝ)+(h:ℝ) := by dsimp only [s]; push_cast; ring + rw [htime] at hg + dsimp only [Q] + rw [htime, hK] + have hleft := neg_le_of_abs_le hg + dsimp only [s] at hleft ⊢ + push_cast at hleft ⊢ + linarith + have hh := finite_mesh_verification (fun k => -Q k) (fun _ => 0) n + (verificationError c C₂ C₃ L h) hstep + simp only [Finset.sum_const_zero, sub_zero] at hh + have hQ0 : Q 0 = F 0 x := by simp [Q, controlledState_zero, stepCost] + rw [hQ0] at hh + change F 0 x - _ ≤ Q n + linarith + +end ZeroTemperatureSK.WeakIto + +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKSupport/Diffusion/FeedbackVerification.lean b/lean/OAI/Probability/SKSupport/Diffusion/FeedbackVerification.lean new file mode 100644 index 0000000000000000000000000000000000000000..ff92a8a9ec252a4c9c8c1b6956df1c01440f287a --- /dev/null +++ b/lean/OAI/Probability/SKSupport/Diffusion/FeedbackVerification.lean @@ -0,0 +1,65 @@ +import Mathlib +import OAI.Probability.SKSupport.Diffusion.ExpectedFeedbackStep + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section +namespace ZeroTemperatureSK.WeakIto +variable {Ω : Type*} [mΩ : MeasurableSpace Ω] {P : Measure Ω} {B : ℝ≥0 → Ω → ℝ} + +lemma exists_feedback_verification (hB : IsPreBrownianReal B P) + (hm : ∀ t, Measurable (B t)) (T c : ℝ≥0) (x : ℝ) + {F D : ℝ → ℝ → ℝ} (hf : ∀ t, ContDiff ℝ 3 (F t)) + (C₂ C₃ Ct L : ℝ≥0) (hC₁ : ∀ t z, |deriv (F t) z| ≤ 1) + (hC₂ : ∀ t z, |deriv (deriv (F t)) z| ≤ C₂) + (hC₃ : ∀ t z, |iteratedDeriv 3 (F t) z| ≤ C₃) + (hDm : ∀ t, Measurable (D t)) (hCt : ∀ t z, |D t z| ≤ Ct) + (hD : ∀ r ∈ Set.Icc (0:ℝ) T, ∀ z, + HasDerivWithinAt (fun t => F t z) (D r z) (Set.Icc (0:ℝ) T) r) + (hL : ∀ r ∈ Set.Icc (0:ℝ) T, ∀ s ∈ Set.Icc (0:ℝ) T, ∀ z y, + |D r z-D s y| ≤ (L:ℝ)*(|r-s|+|z-y|)) + (hPDE : ∀ t ∈ Set.Icc (0:ℝ) T, ∀ z, + D t z+(1/2:ℝ)*deriv (deriv (F t)) z+(c:ℝ)/2*(deriv (F t) z)^2 = 0) + {ε : ℝ} (hε : 0 < ε) : + ∃ α : ℝ≥0 → Ω → ℝ, + IsProgressive (Filtration.natural B (fun t => (hm t).stronglyMeasurable)) α ∧ + (∀ t ω, |α t ω| ≤ 1) ∧ + F 0 x-ε ≤ (∫ ω, F T (controlledState B α c x T ω) ∂P) - + (∫ ω, stepCost (fun r => α (Real.toNNReal r)) 0 T c ω ∂P) := by + have hevent := (verificationError_limit T c C₂ C₃ L).eventually (gt_mem_nhds hε) + obtain ⟨n, hn, he⟩ := ((eventually_ge_atTop (1:ℕ)).and hevent).exists + have hn0 : (n:ℝ≥0) ≠ 0 := by exact_mod_cast (by omega : n ≠ 0) + let h : ℝ≥0 := T/n + have hend : (n:ℝ≥0)*h = T := by dsimp only [h]; field_simp + have hend' : (n:ℝ)*(h:ℝ) = (T:ℝ) := by exact_mod_cast hend + let u := fun t => deriv (F t) + let α := elementaryControl h (fun k ω => u ((k:ℝ≥0)*h) (feedbackEuler B h c u x k ω)) n + have hum : ∀ t, Measurable (u t) := fun t => (show ContDiff ℝ 2 (deriv (F t)) from (hf t).deriv').continuous.measurable + have hap : IsProgressive (Filtration.natural B (fun t => (hm t).stronglyMeasurable)) α := + elementaryControl_progressive _ h (fun k => (hum _).comp (feedbackEuler_adapted hm h c hum x k)) n + have hab : ∀ t ω, |α t ω| ≤ 1 := elementaryControl_bound h (fun k ω => hC₁ _ _) n + refine ⟨α, hap, hab, ?_⟩ + have hv := finite_feedback_verification hB hm h c x n hf C₂ C₃ Ct L hC₁ hC₂ hC₃ hDm hCt + (by simpa only [hend'] using hD) (by simpa only [hend'] using hL) + (by simpa only [hend'] using hPDE) + change F 0 x-(n:ℝ)*verificationError c C₂ C₃ L h ≤ + (∫ ω, F ((n:ℝ)*(h:ℝ)) (controlledState B α c x ((n:ℝ≥0)*h) ω) ∂P) - + (∫ ω, stepCost (fun r => α (Real.toNNReal r)) 0 ((n:ℝ)*(h:ℝ)) c ω ∂P) at hv + rw [hend, hend'] at hv + have herr : (n:ℝ)*verificationError c C₂ C₃ L h < ε := by + simpa only [h, NNReal.coe_div, NNReal.coe_natCast] using he + linarith + +end ZeroTemperatureSK.WeakIto + +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKSupport/Diffusion/FiniteFeedback.lean b/lean/OAI/Probability/SKSupport/Diffusion/FiniteFeedback.lean new file mode 100644 index 0000000000000000000000000000000000000000..c89fadf6fe357e6cb2877722ea0e15cd58e154f8 --- /dev/null +++ b/lean/OAI/Probability/SKSupport/Diffusion/FiniteFeedback.lean @@ -0,0 +1,122 @@ +import Mathlib +import OAI.Probability.SKSupport.Backward.GaussianBackwardShapes +import OAI.Probability.SKSupport.Diffusion.PicardDiffusion + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section +namespace ZeroTemperatureSK +open Heat + +lemma Heat.BoundedSmoothFamily.uniform_lipschitz {F : ℝ → ℝ → ℝ} (hF : BoundedSmoothFamily F) : + ∃ L : ℝ≥0, ∀ t, LipschitzWith L (F t) := by + obtain ⟨L,hL⟩ := hF.deriv.bound + exact ⟨L,fun t => lipschitzWith_of_nnnorm_deriv_le + ((hF.regular t).smooth.differentiable (by simp)) (fun x => hL t x)⟩ + +def Heat.BoundedSmoothFamily.toDrift {F : ℝ → ℝ → ℝ} (hF : BoundedSmoothFamily F) : BoundedLipschitzDrift where + f := F + bound := hF.bound.choose + lip := hF.uniform_lipschitz.choose + measurable := hF.measurable + bounded := hF.bound.choose_spec + lipschitz := hF.uniform_lipschitz.choose_spec + +def rightCoeff (c : ℕ → ℝ≥0) (h : ℝ≥0) : ℕ → ℕ → ℝ → ℝ + | 0, _, _ => 0 + | N+1, i, t => if t < h then c i else rightCoeff c h N (i+1) (t-h) + +lemma rightCoeff_measurable (c : ℕ → ℝ≥0) (h : ℝ≥0) (N i : ℕ) : Measurable (rightCoeff c h N i) := by + induction N generalizing i with + | zero => exact measurable_const + | succ N ih => + exact Measurable.ite (measurableSet_lt (f := id) (g := fun _ : ℝ => (h:ℝ)) measurable_id measurable_const) + measurable_const ((ih (i+1)).comp (measurable_id.sub_const (h:ℝ))) + +lemma rightCoeff_bounds (c : ℕ → ℝ≥0) (h : ℝ≥0) (N i : ℕ) : + ∃ C : ℝ≥0, ∀ t, 0 ≤ rightCoeff c h N i t ∧ rightCoeff c h N i t ≤ C := by + induction N generalizing i with + | zero => exact ⟨0,fun _ => ⟨le_rfl,le_rfl⟩⟩ + | succ N ih => + obtain ⟨C,hC⟩ := ih (i+1) + refine ⟨c i+C,fun t => ?_⟩ + dsimp only [rightCoeff] + split_ifs with ht + · exact ⟨(c i).coe_nonneg,by simp only [NNReal.coe_add];linarith [C.coe_nonneg]⟩ + · exact ⟨(hC _).1,by simp only [NNReal.coe_add];linarith [(hC (t-h)).2,(c i).coe_nonneg]⟩ + +lemma rightCoeff_family (c : ℕ → ℝ≥0) (h : ℝ≥0) (N i : ℕ) : + BoundedSmoothFamily (fun t (_ : ℝ) => rightCoeff c h N i t) := by + obtain ⟨C,hC⟩ := rightCoeff_bounds c h N i + exact BoundedSmoothFamily.timeConst (rightCoeff_measurable c h N i) + (fun t => by simpa only [abs_of_nonneg (hC t).1] using (hC t).2) + +def finiteFeedbackFun (c : ℕ → ℝ≥0) (h : ℝ≥0) (f : ℝ → ℝ) (N i : ℕ) (t x : ℝ) := + rightCoeff c h N i t*deriv (finiteValue c h f N i t) x + +lemma finiteFeedback_family {f : ℝ → ℝ} (hf : RegularDatum f) (hLip : LipschitzWith 1 f) + (c : ℕ → ℝ≥0) (h : ℝ≥0) (N i : ℕ) : BoundedSmoothFamily (finiteFeedbackFun c h f N i) := + (rightCoeff_family c h N i).mul (finiteGradient_family hf hLip c h N i) + +def finiteFeedback {f : ℝ → ℝ} (hf : RegularDatum f) (hLip : LipschitzWith 1 f) + (c : ℕ → ℝ≥0) (h : ℝ≥0) (N i : ℕ) : BoundedLipschitzDrift := + (finiteFeedback_family hf hLip c h N i).toDrift + +lemma finiteValue_shift {f : ℝ → ℝ} (hf : RegularDatum f) (hLip : LipschitzWith 1 f) + (c : ℕ → ℝ≥0) (h : ℝ≥0) {N j : ℕ} (hj : j ≤ N) (i : ℕ) {t : ℝ} (ht : 0 ≤ t) : + finiteValue c h f N i ((j:ℝ)*h+t)=finiteValue c h f (N-j) (i+j) t := by + induction j generalizing N i with + | zero => simp + | succ j ih => + cases N with + | zero => omega + | succ N => + have hh : (h:ℝ) ≤ ((j+1:ℕ):ℝ)*h+t := by push_cast;nlinarith [mul_nonneg (Nat.cast_nonneg (α := ℝ) j) h.coe_nonneg] + rw [finiteValue_tail_of_le hf hLip c h N i hh] + have he : ((j+1:ℕ):ℝ)*(h:ℝ)+t-h=(j:ℝ)*h+t := by push_cast;ring + rw [he,ih (by omega)] + rw [show (N+1)-(j+1)=N-j by omega,show i+1+j=i+(j+1) by omega] + +lemma rightCoeff_shift (c : ℕ → ℝ≥0) (h : ℝ≥0) {N j : ℕ} (hj : j ≤ N) + (i : ℕ) {t : ℝ} (ht : 0 ≤ t) : + rightCoeff c h N i ((j:ℝ)*h+t)=rightCoeff c h (N-j) (i+j) t := by + induction j generalizing N i with + | zero => simp + | succ j ih => + cases N with + | zero => omega + | succ N => + have hh : ¬((j+1:ℕ):ℝ)*(h:ℝ)+t Real.exp (c*f y)) x := by + simp only [varianceLogHeat,ite_eq_right hc] + rw [mul_div_cancel₀ _ hc,Real.exp_log (varianceHeat_exp_pos hLip c t x)] + +theorem finite_transition_tilted (W : BrownianSystem Ω) {f g : ℝ → ℝ} + (hf : RegularDatum f) (hLip : LipschitzWith 1 f) (hg : BoundedSmooth g) + (c : ℕ → ℝ≥0) (h : ℝ≥0) {N i : ℕ} (hi : i < N) : + (∫ w, g ((finiteFeedback hf hLip c h N 0).solution W.driver ((i+1:ℕ)*h) w) ∂W.law)= + ∫ w, varianceTilted (c i) h (backwardBoundary c h f N (i+1)) g + ((finiteFeedback hf hLip c h N 0).solution W.driver ((i:ℝ≥0)*h) w) ∂W.law := by + have ht : (i:ℝ≥0)*h ≤ ((i+1:ℕ):ℝ≥0)*h := mul_le_mul_of_nonneg_right (by exact_mod_cast Nat.le_succ i) h.coe_nonneg + have hh := expected_transition_tiltedMean W (finiteFeedback hf hLip c h N 0) + (cascade_regular hf hLip c h (N-(i+1)) (i+1)) (cascade_lipschitz hLip c h _ _) hg (c i).coe_nonneg ht + (fun t htt x => by + have he := finiteFeedback_step hf hLip c h hi (t := t) (by simpa only [NNReal.coe_mul,NNReal.coe_natCast] using htt) x + simpa only [NNReal.coe_mul,NNReal.coe_natCast,backwardBoundary] using he) + have he : ((((i+1:ℕ):ℝ≥0)*h:ℝ≥0):ℝ)-(((i:ℝ≥0)*h:ℝ≥0):ℝ)=(h:ℝ) := by push_cast;ring + simpa only [he,backwardBoundary] using hh + +lemma Heat.varianceLogHeat_add {f : ℝ → ℝ} {K : ℝ≥0} (hLip : LipschitzWith K f) + {c a b : ℝ} (hc : 0 ≤ c) (ha : 0 ≤ a) (hb : 0 ≤ b) : + varianceLogHeat c (a+b) f=varianceLogHeat c a (varianceLogHeat c b f) := by + funext x + rw [varianceLogHeat_eq_logSemigroup_toNNReal hLip.continuous.measurable, + varianceLogHeat_eq_logSemigroup_toNNReal (varianceLogHeat_lipschitz hLip hc b).continuous.measurable] + have he : varianceLogHeat c b f=logSemigroup c (Real.toNNReal b) f := + funext (varianceLogHeat_eq_logSemigroup_toNNReal hLip.continuous.measurable c b) + rw [he,Real.toNNReal_add ha hb,logSemigroup_add hLip] + +end ZeroTemperatureSK + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKSupport/Diffusion/MixedDrift.lean b/lean/OAI/Probability/SKSupport/Diffusion/MixedDrift.lean new file mode 100644 index 0000000000000000000000000000000000000000..f6e9abccd1da9e25f20e4574d5ecf13cd7170141 --- /dev/null +++ b/lean/OAI/Probability/SKSupport/Diffusion/MixedDrift.lean @@ -0,0 +1,109 @@ +import Mathlib +import OAI.Probability.SKSupport.Diffusion.BoundedDiffusionProperties +import OAI.Probability.SKSupport.Regularity.RightRegularity + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section +namespace ZeroTemperatureSK +open Heat WeakIto +variable {Ω : Type*} [MeasurableSpace Ω] + +def compactMixedGradient (W : BrownianSystem Ω) (β γ : OrderParameter) (T t x : ℝ) : ℝ := + (compactGradient W β T t x+compactGradient W γ T t x)/2 + +def compactMixedDrift (W : BrownianSystem Ω) (β γ : OrderParameter) (T t x : ℝ) : ℝ := + compactCoeff β T t*compactMixedGradient W β γ T t x + +lemma compactMixedGradient_continuous (W : BrownianSystem Ω) (β γ : OrderParameter) + {T : ℝ} (hT0 : 0 ≤ T) (hT1 : T < 1) : + Continuous (fun p : ℝ × ℝ => compactMixedGradient W β γ T p.1 p.2) := + ((compactGradient_continuous W β hT0 hT1).add (compactGradient_continuous W γ hT0 hT1)).div_const 2 + +lemma compactMixedGradient_bound (W : BrownianSystem Ω) (β γ : OrderParameter) + {T : ℝ} (hT0 : 0 ≤ T) (hT1 : T < 1) (t x : ℝ) : + |compactMixedGradient W β γ T t x| ≤ 1 := by + have hb := compactGradient_bound W β hT0 hT1 t x + have hg := compactGradient_bound W γ hT0 hT1 t x + unfold compactMixedGradient + rw [abs_div,abs_of_nonneg (by norm_num : (0:ℝ) ≤ 2)] + apply (div_le_iff₀ (by norm_num : (0:ℝ)<2)).mpr + linarith [abs_add_le (compactGradient W β T t x) (compactGradient W γ T t x)] + +lemma compactMixedDrift_bound (W : BrownianSystem Ω) (β γ : OrderParameter) + {T : ℝ} (hT0 : 0 ≤ T) (hT1 : T < 1) (t x : ℝ) : + |compactMixedDrift W β γ T t x| ≤ β.val ⟨T,⟨hT0,hT1⟩⟩ := by + unfold compactMixedDrift + rw [abs_mul,abs_of_nonneg (compactCoeff_bounds β hT0 hT1 t).1] + exact (mul_le_of_le_one_right (compactCoeff_bounds β hT0 hT1 t).1 + (compactMixedGradient_bound W β γ hT0 hT1 t x)).trans (compactCoeff_bounds β hT0 hT1 t).2 + +lemma compactMixedDrift_lipschitz (W : BrownianSystem Ω) (β γ : OrderParameter) + {T : ℝ} (hT0 : 0 ≤ T) (hT1 : T < 1) : + ∃ L : ℝ≥0, ∀ t, LipschitzWith L (compactMixedDrift W β γ T t) := by + obtain ⟨Lβ,hβ⟩ := compactGradient_lipschitz W β hT0 hT1 + obtain ⟨Lγ,hγ⟩ := compactGradient_lipschitz W γ hT0 hT1 + let D : ℝ≥0 := ⟨β.val ⟨T,⟨hT0,hT1⟩⟩,β.nonneg _⟩ + refine ⟨D*((Lβ+Lγ)/2),fun t => ?_⟩ + apply LipschitzWith.of_dist_le_mul + intro x y + have hsum := abs_add_le (compactGradient W β T t x-compactGradient W β T t y) + (compactGradient W γ T t x-compactGradient W γ T t y) + have hb := (hβ t).dist_le_mul x y + have hg := (hγ t).dist_le_mul x y + simp only [Real.dist_eq] at hb hg + have hmix : |compactMixedGradient W β γ T t x-compactMixedGradient W β γ T t y| ≤ + ((Lβ:ℝ)+(Lγ:ℝ))/2*|x-y| := by + have he : compactMixedGradient W β γ T t x-compactMixedGradient W β γ T t y= + ((compactGradient W β T t x-compactGradient W β T t y)+ + (compactGradient W γ T t x-compactGradient W γ T t y))/2 := by unfold compactMixedGradient;ring + rw [he,abs_div,abs_of_nonneg (by norm_num : (0:ℝ)≤2)] + linarith + rw [Real.dist_eq,compactMixedDrift,compactMixedDrift,← mul_sub,abs_mul, + abs_of_nonneg (compactCoeff_bounds β hT0 hT1 t).1] + calc + _ ≤ compactCoeff β T t*(((Lβ:ℝ)+(Lγ:ℝ))/2*|x-y|) := + mul_le_mul_of_nonneg_left hmix (compactCoeff_bounds β hT0 hT1 t).1 + _ ≤ β.val ⟨T,⟨hT0,hT1⟩⟩*(((Lβ:ℝ)+(Lγ:ℝ))/2*|x-y|) := + mul_le_mul_of_nonneg_right (compactCoeff_bounds β hT0 hT1 t).2 (by positivity) + _ = _ := by + change β.val ⟨T,⟨hT0,hT1⟩⟩*(((Lβ:ℝ)+(Lγ:ℝ))/2*|x-y|)= + ((D:ℝ)*(((Lβ:ℝ)+(Lγ:ℝ))/2))*|x-y| + change β.val ⟨T,⟨hT0,hT1⟩⟩*(((Lβ:ℝ)+(Lγ:ℝ))/2*|x-y|)= + (β.val ⟨T,⟨hT0,hT1⟩⟩*(((Lβ:ℝ)+(Lγ:ℝ))/2))*|x-y| + ring + +def mixedStripDrift (W : BrownianSystem Ω) (β γ : OrderParameter) (T : Time) : BoundedLipschitzDrift where + f := compactMixedDrift W β γ T + bound := ⟨β.val T,β.nonneg T⟩ + lip := (compactMixedDrift_lipschitz W β γ T.property.1 T.property.2).choose + measurable := ((compactCoeff_measurable β T).comp measurable_fst).mul + (compactMixedGradient_continuous W β γ T.property.1 T.property.2).measurable + bounded := compactMixedDrift_bound W β γ T.property.1 T.property.2 + lipschitz := (compactMixedDrift_lipschitz W β γ T.property.1 T.property.2).choose_spec + +lemma mixedStripDrift_pathDrift_right (W : BrownianSystem Ω) (β γ : OrderParameter) + (T : Time) (s : ℝ≥0) : + ∀ᵐ ξ ∂W.law, ContinuousWithinAt (fun r => (mixedStripDrift W β γ T).pathDrift W r ξ) (Ioi (s:ℝ)) s := by + filter_upwards [(mixedStripDrift W β γ T).solution_continuous_ae W] with ξ hξ + have hx : Continuous (fun r : ℝ => (mixedStripDrift W β γ T).solution W.driver (Real.toNNReal r) ξ) := + hξ.comp (by fun_prop : Continuous Real.toNNReal) + have hu : Continuous (fun r : ℝ => compactMixedGradient W β γ T r + ((mixedStripDrift W β γ T).solution W.driver (Real.toNNReal r) ξ)) := + (compactMixedGradient_continuous W β γ T.property.1 T.property.2).comp (continuous_id.prodMk hx) + have hh := ((compactCoeff_rightContinuous β T.property.1 T.property.2 (s:ℝ)).mono Ioi_subset_Ici_self).mul hu.continuousWithinAt + apply hh.congr_of_eventuallyEq + · filter_upwards [self_mem_nhdsWithin] with r hr + simp only [BoundedLipschitzDrift.pathDrift,mixedStripDrift,compactMixedDrift, + Real.coe_toNNReal _ (s.coe_nonneg.trans hr.le),Pi.mul_apply] + · simp only [BoundedLipschitzDrift.pathDrift,mixedStripDrift,compactMixedDrift,Real.toNNReal_coe,Pi.mul_apply] + +end ZeroTemperatureSK + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKSupport/Diffusion/MixedPathStability.lean b/lean/OAI/Probability/SKSupport/Diffusion/MixedPathStability.lean new file mode 100644 index 0000000000000000000000000000000000000000..3fd3d494c2c8685d4661729aa893aef9fb03fc67 --- /dev/null +++ b/lean/OAI/Probability/SKSupport/Diffusion/MixedPathStability.lean @@ -0,0 +1,70 @@ +import Mathlib +import OAI.Probability.SKSupport.Diffusion.MixedDrift +import OAI.Probability.SKSupport.Diffusion.DiffusionStability + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section +namespace ZeroTemperatureSK +open Heat +variable {Ω : Type*} [MeasurableSpace Ω] + +lemma mixedDrift_error (W : BrownianSystem Ω) (β γ : OrderParameter) (T : Time) + {δ : ℝ} (hδ : 0 ≤ δ) + (hd : ∀ s x, |compactGradient W β T s x-compactGradient W γ T s x| ≤ δ) : + ∀ s ∈ Icc (0:ℝ) T, ∀ x, + |(stripDrift W γ T).f s x-(mixedStripDrift W β γ T).f s x| ≤ + |extend β.val s-extend γ.val s|+γ.val T*δ := by + intro s hs x + have hm : |compactGradient W γ T s x-compactMixedGradient W β γ T s x| ≤ δ := by + have he : compactGradient W γ T s x-compactMixedGradient W β γ T s x= + -(compactGradient W β T s x-compactGradient W γ T s x)/2 := by unfold compactMixedGradient;ring + rw [he,abs_div,abs_neg,abs_of_nonneg (by norm_num : (0:ℝ) ≤ 2)] + have hh := hd s x + linarith + have hc : |compactCoeff γ T s| ≤ γ.val T := by + rw [abs_of_nonneg (compactCoeff_bounds γ T.property.1 T.property.2 s).1] + exact (compactCoeff_bounds γ T.property.1 T.property.2 s).2 + have hh := mul_sub_mul_error (b := compactCoeff β T s) hδ hc + (compactMixedGradient_bound W β γ T.property.1 T.property.2 s x) hm + simpa only [stripDrift,compactDrift,mixedStripDrift,compactMixedDrift,compactCoeff,stripClamp_eq hs,abs_sub_comm] using hh + +lemma mixedPath_error (W : BrownianSystem Ω) (β γ : OrderParameter) (T : Time) + {δ : ℝ} (hδ : 0 ≤ δ) + (hd : ∀ s x, |compactGradient W β T s x-compactGradient W γ T s x| ≤ δ) + (t : ℝ≥0) (ht : (t:ℝ) ≤ T) (ξ : Ω) : + |(mixedStripDrift W β γ T).solution W.driver t ξ-diffusion W γ t ξ| ≤ + 2*(coefficientDistance β γ+γ.val T*(T:ℝ)*δ)*Real.exp ((stripDrift W γ T).rate*T) := by + let e (s : ℝ) := |extend β.val s-extend γ.val s|+γ.val T*δ + have hei (a b : ℝ) : IntervalIntegrable e volume a b := + ((β.integrable.sub γ.integrable).abs.intervalIntegrable).add intervalIntegrable_const + have hen (s : ℝ) : 0 ≤ e s := add_nonneg (abs_nonneg _) (mul_nonneg (γ.nonneg _) hδ) + let TT : ℝ≥0 := ⟨T,T.property.1⟩ + have hh := (stripDrift W γ T).solution_stability_integral (mixedStripDrift W β γ T) _ W.driver_progressive TT + (hei 0 T) (fun s _ => hen s) (Eventually.of_forall (fun s => mixedDrift_error W β γ T hδ hd s)) t ht ξ + rw [← diffusion_eq_strip W γ T t ht,abs_sub_comm] at hh + have hi0 : 0 ≤ ∫ s in (0:ℝ)..(T:ℝ), e s := intervalIntegral.integral_nonneg T.property.1 (fun s _ => hen s) + have hi : (∫ s in (0:ℝ)..(T:ℝ), e s) ≤ coefficientDistance β γ+γ.val T*(T:ℝ)*δ := by + dsimp only [e,coefficientDistance] + have hfi : IntervalIntegrable (fun s => |extend β.val s-extend γ.val s|) volume 0 T := (β.integrable.sub γ.integrable).abs.intervalIntegrable + rw [intervalIntegral.integral_add hfi intervalIntegrable_const, + intervalIntegral.integral_const] + have hh := intervalIntegral.integral_mono_interval (a := (0:ℝ)) (b := (T:ℝ)) (c := (0:ℝ)) (d := 1) + le_rfl T.property.1 T.property.2.le (Eventually.of_forall (fun s => abs_nonneg (extend β.val s-extend γ.val s))) + ((β.integrable.sub γ.integrable).abs.intervalIntegrable) + simp only [sub_zero,smul_eq_mul] + nlinarith only [hh] + have hex : Real.exp ((stripDrift W γ T).rate*t) ≤ Real.exp ((stripDrift W γ T).rate*T) := + Real.exp_le_exp.mpr (mul_le_mul_of_nonneg_left ht (stripDrift W γ T).rate_pos.le) + exact hh.trans (mul_le_mul (mul_le_mul_of_nonneg_left hi (by norm_num)) hex + (Real.exp_pos _).le (mul_nonneg (by norm_num) (hi0.trans hi))) + +end ZeroTemperatureSK + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKSupport/Diffusion/PicardDiffusion.lean b/lean/OAI/Probability/SKSupport/Diffusion/PicardDiffusion.lean new file mode 100644 index 0000000000000000000000000000000000000000..2ab806aa70724d5c451d97bbed617765a424f41e --- /dev/null +++ b/lean/OAI/Probability/SKSupport/Diffusion/PicardDiffusion.lean @@ -0,0 +1,267 @@ +import Mathlib +import OAI.Probability.SKSupport.Diffusion.ProgressiveIntegralMeasurable +import OAI.Probability.SKSupport.Foundations.ElementaryControl + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section +namespace ZeroTemperatureSK +open WeakIto + +structure BoundedLipschitzDrift where + f : ℝ → ℝ → ℝ + bound : ℝ≥0 + lip : ℝ≥0 + measurable : Measurable (fun p : ℝ × ℝ => f p.1 p.2) + bounded : ∀ t x, |f t x| ≤ bound + lipschitz : ∀ t, LipschitzWith lip (f t) + +variable {Ω : Type*} [mΩ : MeasurableSpace Ω] + +lemma progressive_time_measurable (ℱ : Filtration ℝ≥0 mΩ) {α : ℝ≥0 → Ω → ℝ} + (ha : IsProgressive ℱ α) (ω : Ω) : Measurable (fun t : ℝ => α (Real.toNNReal t) ω) := + ((progressive_joint_measurable ℱ ha).comp + (measurable_id.prodMk measurable_const)).comp measurable_real_toNNReal + +lemma progressive_bounded_integrable (ℱ : Filtration ℝ≥0 mΩ) {α : ℝ≥0 → Ω → ℝ} + (ha : IsProgressive ℱ α) {D : ℝ} (hb : ∀ t ω, |α t ω| ≤ D) (ω : Ω) (a b : ℝ) : + IntervalIntegrable (fun t => α (Real.toNNReal t) ω) volume a b := by + apply (intervalIntegrable_const (c := D)).mono_fun + · exact (progressive_time_measurable ℱ ha ω).aestronglyMeasurable + · filter_upwards [] with t + simpa only [Real.norm_eq_abs] using (hb (Real.toNNReal t) ω).trans (le_abs_self D) + +def timePrimitive (α : ℝ≥0 → Ω → ℝ) (t : ℝ≥0) (ω : Ω) : ℝ := + ∫ s in (0:ℝ)..(t:ℝ), α (Real.toNNReal s) ω + +lemma timePrimitive_continuous (ℱ : Filtration ℝ≥0 mΩ) {α : ℝ≥0 → Ω → ℝ} + (ha : IsProgressive ℱ α) {D : ℝ} (hb : ∀ t ω, |α t ω| ≤ D) (ω : Ω) : + Continuous (fun t => timePrimitive α t ω) := + (intervalIntegral.continuous_primitive (progressive_bounded_integrable ℱ ha hb ω) 0).comp + continuous_subtype_val + +lemma timePrimitive_progressive (ℱ : Filtration ℝ≥0 mΩ) {α : ℝ≥0 → Ω → ℝ} + (ha : IsProgressive ℱ α) {D : ℝ} (hb : ∀ t ω, |α t ω| ≤ D) : + IsProgressive ℱ (timePrimitive α) := by + have hm : StronglyAdapted ℱ (timePrimitive α) := by + intro t + have hh := progressive_integral_measurable ℱ ha t (w := fun _ => 1) measurable_const + change StronglyMeasurable[ℱ t] (fun ω => ∫ s in (0:ℝ)..(t:ℝ), α (Real.toNNReal s) ω) + simpa only [one_mul] using hh.stronglyMeasurable + exact (hm.isStronglyProgressive_of_continuous (timePrimitive_continuous ℱ ha hb)).isProgressive + +lemma timePrimitive_bound (ℱ : Filtration ℝ≥0 mΩ) {α : ℝ≥0 → Ω → ℝ} + (ha : IsProgressive ℱ α) {D : ℝ} (hb : ∀ t ω, |α t ω| ≤ D) (t : ℝ≥0) (ω : Ω) : + |timePrimitive α t ω| ≤ D*(t:ℝ) := by + calc + |timePrimitive α t ω| ≤ ∫ s in (0:ℝ)..(t:ℝ), |α (Real.toNNReal s) ω| := + intervalIntegral.abs_integral_le_integral_abs t.coe_nonneg + _ ≤ ∫ _s in (0:ℝ)..(t:ℝ), D := + intervalIntegral.integral_mono t.coe_nonneg + (progressive_bounded_integrable ℱ ha hb ω 0 t).abs intervalIntegrable_const + (fun _ => hb _ _) + _ = D*(t:ℝ) := by simp [mul_comm] + +namespace BoundedLipschitzDrift + +variable (b : BoundedLipschitzDrift) + +def action (B Y : ℝ≥0 → Ω → ℝ) (t : ℝ≥0) (ω : Ω) : ℝ := b.f t (B t ω+Y t ω) + +lemma action_progressive (ℱ : Filtration ℝ≥0 mΩ) {B Y : ℝ≥0 → Ω → ℝ} + (hB : IsProgressive ℱ B) (hY : IsProgressive ℱ Y) : IsProgressive ℱ (b.action B Y) := by + intro t + exact b.measurable.comp ((measurable_subtype_coe.comp (measurable_subtype_coe.comp + measurable_fst)).prodMk ((hB t).add (hY t))) + +omit mΩ in +lemma action_bound (B Y : ℝ≥0 → Ω → ℝ) (t : ℝ≥0) (ω : Ω) : + |b.action B Y t ω| ≤ b.bound := b.bounded _ _ + +def correctionIter (b : BoundedLipschitzDrift) (B : ℝ≥0 → Ω → ℝ) : ℕ → ℝ≥0 → Ω → ℝ + | 0 => fun _ _ => 0 + | n+1 => timePrimitive (b.action B (correctionIter b B n)) + +lemma correctionIter_progressive (ℱ : Filtration ℝ≥0 mΩ) {B : ℝ≥0 → Ω → ℝ} + (hB : IsProgressive ℱ B) (n : ℕ) : IsProgressive ℱ (b.correctionIter B n) := by + induction n with + | zero => exact isProgressive_const ℱ 0 + | succ n hn => exact timePrimitive_progressive ℱ (b.action_progressive ℱ hB hn) (b.action_bound _ _) + +lemma correctionIter_continuous (ℱ : Filtration ℝ≥0 mΩ) {B : ℝ≥0 → Ω → ℝ} + (hB : IsProgressive ℱ B) (n : ℕ) (ω : Ω) : Continuous (fun t => b.correctionIter B n t ω) := by + cases n with + | zero => exact continuous_const + | succ n => + exact timePrimitive_continuous ℱ + (b.action_progressive ℱ hB (b.correctionIter_progressive ℱ hB n)) (b.action_bound _ _) ω + +lemma correctionIter_bound (ℱ : Filtration ℝ≥0 mΩ) {B : ℝ≥0 → Ω → ℝ} + (hB : IsProgressive ℱ B) (n : ℕ) (t : ℝ≥0) (ω : Ω) : + |b.correctionIter B n t ω| ≤ (b.bound:ℝ)*(t:ℝ) := by + cases n with + | zero => simpa only [correctionIter,abs_zero] using mul_nonneg b.bound.coe_nonneg t.coe_nonneg + | succ n => + exact timePrimitive_bound ℱ + (b.action_progressive ℱ hB (b.correctionIter_progressive ℱ hB n)) (b.action_bound _ _) t ω + +def rate : ℝ := 2*(b.lip:ℝ)+1 + +lemma rate_pos : 0 < b.rate := by unfold rate; positivity +lemma one_le_rate : 1 ≤ b.rate := by unfold rate; linarith [b.lip.coe_nonneg] + +lemma integral_exp_rate (t : ℝ≥0) : + (∫ s in (0:ℝ)..(t:ℝ), Real.exp (b.rate*s))*b.rate = Real.exp (b.rate*t)-1 := by + have hd (s : ℝ) : HasDerivAt (fun r => Real.exp (b.rate*r)) + (Real.exp (b.rate*s)*b.rate) s := by + convert ((hasDerivAt_id s).const_mul b.rate).exp using 1 <;> simp + have hh := intervalIntegral.integral_eq_sub_of_hasDerivAt (fun s _ => hd s) + (((Real.continuous_exp.comp (continuous_const.mul continuous_id)).mul continuous_const).intervalIntegrable _ _) + (a := (0:ℝ)) (b := (t:ℝ)) + simpa only [intervalIntegral.integral_mul_const,mul_zero,Real.exp_zero] using hh + +lemma integral_exp_contraction {A : ℝ} (hA : 0 ≤ A) (t : ℝ≥0) : + (∫ s in (0:ℝ)..(t:ℝ), (b.lip:ℝ)*A*Real.exp (b.rate*s)) ≤ + A/2*Real.exp (b.rate*t) := by + rw [intervalIntegral.integral_const_mul] + have hi : 0 ≤ ∫ s in (0:ℝ)..(t:ℝ), Real.exp (b.rate*s) := + intervalIntegral.integral_nonneg t.coe_nonneg (fun _ _ => (Real.exp_pos _).le) + have hl : (b.lip:ℝ) ≤ b.rate/2 := by unfold rate; linarith + calc + _ ≤ (b.rate/2)*A*(∫ s in (0:ℝ)..(t:ℝ), Real.exp (b.rate*s)) := + mul_le_mul_of_nonneg_right (mul_le_mul_of_nonneg_right hl hA) hi + _ = A/2*(Real.exp (b.rate*t)-1) := by rw [← b.integral_exp_rate t]; ring + _ ≤ A/2*Real.exp (b.rate*t) := by nlinarith + +lemma timePrimitive_action_sub_estimate (ℱ : Filtration ℝ≥0 mΩ) + {B Y Z : ℝ≥0 → Ω → ℝ} (hB : IsProgressive ℱ B) (hY : IsProgressive ℱ Y) + (hZ : IsProgressive ℱ Z) {A : ℝ} (hA : 0 ≤ A) (t : ℝ≥0) (ω : Ω) + (he : ∀ s ≤ t, |Y s ω-Z s ω| ≤ A*Real.exp (b.rate*s)) : + |timePrimitive (b.action B Y) t ω-timePrimitive (b.action B Z) t ω| ≤ + A/2*Real.exp (b.rate*t) := by + have hiY := progressive_bounded_integrable ℱ (b.action_progressive ℱ hB hY) (b.action_bound B Y) ω 0 t + have hiZ := progressive_bounded_integrable ℱ (b.action_progressive ℱ hB hZ) (b.action_bound B Z) ω 0 t + rw [timePrimitive,timePrimitive,← intervalIntegral.integral_sub hiY hiZ] + apply le_trans _ (b.integral_exp_contraction hA t) + rw [← Real.norm_eq_abs] + apply intervalIntegral.norm_integral_le_of_norm_le t.coe_nonneg _ + ((continuous_const.mul (Real.continuous_exp.comp (continuous_const.mul continuous_id))).intervalIntegrable _ _) + filter_upwards [] with s hs + have hst : Real.toNNReal s ≤ t := Real.toNNReal_le_iff_le_coe.mpr hs.2 + have hh := he _ hst + have hl := (b.lipschitz (Real.toNNReal s)).dist_le_mul + (B (Real.toNNReal s) ω+Y (Real.toNNReal s) ω) + (B (Real.toNNReal s) ω+Z (Real.toNNReal s) ω) + simp only [Real.dist_eq,add_sub_add_left_eq_sub] at hl + simp only [Real.coe_toNNReal _ hs.1.le] at hh + change |b.action B Y (Real.toNNReal s) ω-b.action B Z (Real.toNNReal s) ω| ≤ _ + exact hl.trans (by simpa only [mul_assoc,Pi.mul_apply,Function.comp_apply,id_eq] using mul_le_mul_of_nonneg_left hh b.lip.coe_nonneg) + +lemma correctionIter_diff_bound (ℱ : Filtration ℝ≥0 mΩ) {B : ℝ≥0 → Ω → ℝ} + (hB : IsProgressive ℱ B) (n : ℕ) (t : ℝ≥0) (ω : Ω) : + |b.correctionIter B (n+1) t ω-b.correctionIter B n t ω| ≤ + (b.bound:ℝ)*(1/2:ℝ)^n*Real.exp (b.rate*t) := by + induction n generalizing t with + | zero => + simp only [correctionIter,_root_.sub_zero,pow_zero,mul_one] + apply (timePrimitive_bound ℱ (b.action_progressive ℱ hB (isProgressive_const ℱ 0)) + (b.action_bound _ _) t ω).trans + apply mul_le_mul_of_nonneg_left _ b.bound.coe_nonneg + have ht : (t:ℝ) ≤ b.rate*t := by nlinarith [b.one_le_rate,t.coe_nonneg] + linarith [Real.add_one_le_exp (b.rate*t)] + | succ n hn => + have hh := b.timePrimitive_action_sub_estimate ℱ hB + (b.correctionIter_progressive ℱ hB (n+1)) (b.correctionIter_progressive ℱ hB n) + (show 0 ≤ (b.bound:ℝ)*(1/2:ℝ)^n by positivity) t ω (fun s _ => hn s) + convert hh using 1 <;> simp only [correctionIter,pow_succ] + ring + +def correction (B : ℝ≥0 → Ω → ℝ) (t : ℝ≥0) (ω : Ω) : ℝ := + atTop.limUnder (fun n => b.correctionIter B n t ω) + +lemma correctionIter_tendsto (ℱ : Filtration ℝ≥0 mΩ) {B : ℝ≥0 → Ω → ℝ} + (hB : IsProgressive ℱ B) (t : ℝ≥0) (ω : Ω) : + Tendsto (fun n => b.correctionIter B n t ω) atTop (𝓝 (b.correction B t ω)) := by + apply CauchySeq.tendsto_limUnder + apply cauchySeq_of_le_geometric (1/2:ℝ) ((b.bound:ℝ)*Real.exp (b.rate*t)) (by norm_num) + intro n + rw [Real.dist_eq,abs_sub_comm] + convert b.correctionIter_diff_bound ℱ hB n t ω using 1 + ring + +lemma correction_progressive (ℱ : Filtration ℝ≥0 mΩ) {B : ℝ≥0 → Ω → ℝ} + (hB : IsProgressive ℱ B) : IsProgressive ℱ (b.correction B) := by + intro t + have hm (n : ℕ) : StronglyMeasurable[(Subtype.instMeasurableSpace).prod (ℱ t)] + (fun p : Iic t × Ω => b.correctionIter B n p.1 p.2) := + (b.correctionIter_progressive ℱ hB n t).stronglyMeasurable + let : MeasurableSpace Ω := ℱ t + exact (StronglyMeasurable.limUnder hm).measurable + +lemma correction_bound (ℱ : Filtration ℝ≥0 mΩ) {B : ℝ≥0 → Ω → ℝ} + (hB : IsProgressive ℱ B) (t : ℝ≥0) (ω : Ω) : + |b.correction B t ω| ≤ (b.bound:ℝ)*(t:ℝ) := + le_of_tendsto (b.correctionIter_tendsto ℱ hB t ω).abs + (Eventually.of_forall (fun n => b.correctionIter_bound ℱ hB n t ω)) + +lemma correction_eq_integral (ℱ : Filtration ℝ≥0 mΩ) {B : ℝ≥0 → Ω → ℝ} + (hB : IsProgressive ℱ B) (t : ℝ≥0) (ω : Ω) : + b.correction B t ω = timePrimitive (b.action B (b.correction B)) t ω := by + have hm (n : ℕ) : AEStronglyMeasurable + (fun s : ℝ => b.action B (b.correctionIter B n) (Real.toNNReal s) ω) + (volume.restrict (Ioc 0 (t:ℝ))) := + (progressive_time_measurable ℱ (b.action_progressive ℱ hB + (b.correctionIter_progressive ℱ hB n)) ω).aestronglyMeasurable + have hd (n : ℕ) : ∀ᵐ s ∂volume.restrict (Ioc 0 (t:ℝ)), + ‖b.action B (b.correctionIter B n) (Real.toNNReal s) ω‖ ≤ (b.bound:ℝ) := + Eventually.of_forall (fun s => b.action_bound _ _ _ _) + have hl : ∀ᵐ s ∂volume.restrict (Ioc 0 (t:ℝ)), Tendsto + (fun n => b.action B (b.correctionIter B n) (Real.toNNReal s) ω) atTop + (𝓝 (b.action B (b.correction B) (Real.toNNReal s) ω)) := by + filter_upwards [] with s + exact ((b.lipschitz (Real.toNNReal s)).continuous.tendsto _).comp + (tendsto_const_nhds.add (b.correctionIter_tendsto ℱ hB (Real.toNNReal s) ω)) + have hi : Integrable (fun _ : ℝ => (b.bound:ℝ)) (volume.restrict (Ioc 0 (t:ℝ))) := + (intervalIntegrable_const (c := (b.bound:ℝ))).1 + have hh := tendsto_integral_of_dominated_convergence (fun _ => (b.bound:ℝ)) hm hi hd hl + have hh' : Tendsto (fun n => b.correctionIter B (n+1) t ω) atTop + (𝓝 (timePrimitive (b.action B (b.correction B)) t ω)) := by + simpa only [correctionIter,timePrimitive,intervalIntegral.integral_of_le t.coe_nonneg] using hh + exact tendsto_nhds_unique ((b.correctionIter_tendsto ℱ hB t ω).comp (tendsto_add_atTop_nat 1)) hh' + +lemma correction_continuous (ℱ : Filtration ℝ≥0 mΩ) {B : ℝ≥0 → Ω → ℝ} + (hB : IsProgressive ℱ B) (ω : Ω) : Continuous (fun t => b.correction B t ω) := by + have he : (fun t => b.correction B t ω) = + (fun t => timePrimitive (b.action B (b.correction B)) t ω) := + funext (fun t => b.correction_eq_integral ℱ hB t ω) + rw [he] + exact timePrimitive_continuous ℱ (b.action_progressive ℱ hB (b.correction_progressive ℱ hB)) + (b.action_bound _ _) ω + +def solution (B : ℝ≥0 → Ω → ℝ) (t : ℝ≥0) (ω : Ω) : ℝ := B t ω+b.correction B t ω + +lemma solution_progressive (ℱ : Filtration ℝ≥0 mΩ) {B : ℝ≥0 → Ω → ℝ} + (hB : IsProgressive ℱ B) : IsProgressive ℱ (b.solution B) := hB.add (b.correction_progressive ℱ hB) + +lemma solution_eq (ℱ : Filtration ℝ≥0 mΩ) {B : ℝ≥0 → Ω → ℝ} + (hB : IsProgressive ℱ B) (t : ℝ≥0) (ω : Ω) : + b.solution B t ω = B t ω+∫ s in (0:ℝ)..(t:ℝ), + b.f (Real.toNNReal s) (b.solution B (Real.toNNReal s) ω) := by + change B t ω+b.correction B t ω = B t ω+_ + rw [b.correction_eq_integral ℱ hB t ω] + rfl + +lemma solution_continuous (ℱ : Filtration ℝ≥0 mΩ) {B : ℝ≥0 → Ω → ℝ} + (hB : IsProgressive ℱ B) {ω : Ω} (hc : Continuous (fun t => B t ω)) : + Continuous (fun t => b.solution B t ω) := hc.add (b.correction_continuous ℱ hB ω) + +end BoundedLipschitzDrift +end ZeroTemperatureSK + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKSupport/Diffusion/PicardUniqueness.lean b/lean/OAI/Probability/SKSupport/Diffusion/PicardUniqueness.lean new file mode 100644 index 0000000000000000000000000000000000000000..5787d7d1e025200ac9b7b926021dae40409f6edc --- /dev/null +++ b/lean/OAI/Probability/SKSupport/Diffusion/PicardUniqueness.lean @@ -0,0 +1,70 @@ +import Mathlib +import OAI.Probability.SKSupport.Diffusion.PicardDiffusion + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section +namespace ZeroTemperatureSK.BoundedLipschitzDrift + +variable {Ω : Type*} [mΩ : MeasurableSpace Ω] +variable (b : BoundedLipschitzDrift) + +lemma correction_unique_on (ℱ : Filtration ℝ≥0 mΩ) {B Z : ℝ≥0 → Ω → ℝ} + (hB : IsProgressive ℱ B) (hZ : IsProgressive ℱ Z) (T : ℝ≥0) (ω : Ω) + (hfix : ∀ t ≤ T, Z t ω = timePrimitive (b.action B Z) t ω) : + ∀ t ≤ T, b.correction B t ω = Z t ω := by + have hbase (t : ℝ≥0) (ht : t ≤ T) : + |b.correction B t ω-Z t ω| ≤ 2*(b.bound:ℝ)*Real.exp (b.rate*t) := by + have hzb : |Z t ω| ≤ (b.bound:ℝ)*(t:ℝ) := by + rw [hfix t ht] + exact timePrimitive_bound ℱ (b.action_progressive ℱ hB hZ) (b.action_bound _ _) _ _ + have htt : (t:ℝ) ≤ Real.exp (b.rate*t) := by + have hh : (t:ℝ) ≤ b.rate*t := by nlinarith [b.one_le_rate,t.coe_nonneg] + linarith [Real.add_one_le_exp (b.rate*t)] + apply (abs_sub _ _).trans + nlinarith [b.correction_bound ℱ hB t ω, + mul_le_mul_of_nonneg_left htt b.bound.coe_nonneg] + have hest (n : ℕ) (t : ℝ≥0) (ht : t ≤ T) : + |b.correction B t ω-Z t ω| ≤ 2*(b.bound:ℝ)*(1/2:ℝ)^n*Real.exp (b.rate*t) := by + induction n generalizing t with + | zero => simpa only [pow_zero,mul_one] using hbase t ht + | succ n hn => + rw [b.correction_eq_integral ℱ hB t ω,hfix t ht] + have hh := b.timePrimitive_action_sub_estimate ℱ hB (b.correction_progressive ℱ hB) hZ + (show 0 ≤ 2*(b.bound:ℝ)*(1/2:ℝ)^n by positivity) t ω (fun s hs => hn s (hs.trans ht)) + convert hh using 1 + rw [pow_succ] + ring + intro t ht + have hh : Tendsto (fun n : ℕ => 2*(b.bound:ℝ)*(1/2:ℝ)^n*Real.exp (b.rate*t)) atTop (𝓝 0) := by + simpa only [mul_zero,zero_mul] using + (tendsto_const_nhds.mul (tendsto_pow_atTop_nhds_zero_of_lt_one + (show (0:ℝ) ≤ 1/2 by norm_num) (by norm_num : (1/2:ℝ)<1)) + (a := 2*(b.bound:ℝ))).mul_const (Real.exp (b.rate*t)) + have hz : |b.correction B t ω-Z t ω| ≤ 0 := + ge_of_tendsto hh (Eventually.of_forall (fun n => hest n t ht)) + exact sub_eq_zero.mp (abs_eq_zero.mp (le_antisymm hz (abs_nonneg _))) + +lemma solution_eq_of_agree (b' : BoundedLipschitzDrift) (ℱ : Filtration ℝ≥0 mΩ) + {B : ℝ≥0 → Ω → ℝ} (hB : IsProgressive ℱ B) (T : ℝ≥0) + (he : ∀ t : ℝ≥0, t ≤ T → ∀ x, b.f t x = b'.f t x) (t : ℝ≥0) (ht : t ≤ T) (ω : Ω) : + b.solution B t ω = b'.solution B t ω := by + have hu := b.correction_unique_on ℱ hB (b'.correction_progressive ℱ hB) T ω + apply congrArg (B t ω+ ·) + apply hu _ t ht + intro s hs + rw [b'.correction_eq_integral ℱ hB s ω] + apply intervalIntegral.integral_congr + intro r hr + rw [uIcc_of_le s.coe_nonneg] at hr + exact (he (Real.toNNReal r) ((Real.toNNReal_le_iff_le_coe.mpr hr.2).trans hs) _).symm + +end ZeroTemperatureSK.BoundedLipschitzDrift + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKSupport/Diffusion/ProgressiveBrownian.lean b/lean/OAI/Probability/SKSupport/Diffusion/ProgressiveBrownian.lean new file mode 100644 index 0000000000000000000000000000000000000000..dcefbbf73c36202e65f9cb24a9356379a62eecb1 --- /dev/null +++ b/lean/OAI/Probability/SKSupport/Diffusion/ProgressiveBrownian.lean @@ -0,0 +1,121 @@ +import Mathlib +import OAI.Probability.SKSupport.Model + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section +namespace ZeroTemperatureSK + +def leftMeshTime (n : ℕ) (t : ℝ≥0) : ℝ≥0 := + (⌊((n+1:ℕ):ℝ)*(t:ℝ)⌋₊:ℝ≥0)/((n+1:ℕ):ℝ≥0) + +lemma leftMeshTime_le (n : ℕ) (t : ℝ≥0) : leftMeshTime n t ≤ t := by + apply NNReal.coe_le_coe.mp + simp only [leftMeshTime,NNReal.coe_div,NNReal.coe_natCast] + apply (div_le_iff₀ (show (0:ℝ)<((n+1:ℕ):ℝ) by positivity)).mpr + have hh := Nat.floor_le (mul_nonneg (Nat.cast_nonneg (α := ℝ) (n+1)) t.coe_nonneg) + nlinarith + +lemma leftMeshTime_gt (n : ℕ) (t : ℝ≥0) : (t:ℝ)-1/((n+1:ℕ):ℝ) < leftMeshTime n t := by + simp only [leftMeshTime,NNReal.coe_div,NNReal.coe_natCast] + have hh := Nat.lt_floor_add_one (((n+1:ℕ):ℝ)*(t:ℝ)) + apply (lt_div_iff₀ (show (0:ℝ)<((n+1:ℕ):ℝ) by positivity)).mpr + have he : ((t:ℝ)-1/((n+1:ℕ):ℝ))*((n+1:ℕ):ℝ) = ((n+1:ℕ):ℝ)*(t:ℝ)-1 := by + field_simp + rw [he] + linarith + +lemma leftMeshTime_tendsto (t : ℝ≥0) : Tendsto (fun n => leftMeshTime n t) atTop (𝓝 t) := by + apply tendsto_subtype_rng.mpr + have hl : Tendsto (fun n : ℕ => (t:ℝ)-1/((n+1:ℕ):ℝ)) atTop (𝓝 (t:ℝ)) := by + simpa only [sub_zero,Nat.cast_add,Nat.cast_one] using + tendsto_const_nhds.sub (tendsto_one_div_add_atTop_nhds_zero_nat (𝕜 := ℝ)) (a := (t:ℝ)) + exact tendsto_of_tendsto_of_tendsto_of_le_of_le hl tendsto_const_nhds + (fun n => (leftMeshTime_gt n t).le) (fun n => leftMeshTime_le n t) + +variable {Ω : Type*} [mΩ : MeasurableSpace Ω] + +lemma leftMesh_progressive (ℱ : Filtration ℝ≥0 mΩ) {B : ℝ≥0 → Ω → ℝ} + (hB : Adapted ℱ B) (n : ℕ) : IsProgressive ℱ (fun t ξ => B (leftMeshTime n t) ξ) := by + intro s + have hm (k : ℕ) : Measurable[ℱ s] (B (min ((k:ℝ≥0)/((n+1:ℕ):ℝ≥0)) s)) := + (hB _).mono (ℱ.mono (min_le_right _ _)) le_rfl + let : MeasurableSpace Ω := ℱ s + have hprod : Measurable[(inferInstance : MeasurableSpace ℕ).prod (ℱ s)] + (fun p : ℕ × Ω => B (min ((p.1:ℝ≥0)/((n+1:ℕ):ℝ≥0)) s) p.2) := by + let : MeasurableSpace Ω := ℱ s + exact measurable_from_prod_countable_right hm + have ht : Measurable[(Subtype.instMeasurableSpace).prod (ℱ s)] + (fun p : Set.Iic s × Ω => ((p.1:ℝ≥0):ℝ)) := by fun_prop + have hi : Measurable[(Subtype.instMeasurableSpace).prod (ℱ s)] + (fun p : Set.Iic s × Ω => ⌊((n+1:ℕ):ℝ)*((p.1:ℝ≥0):ℝ)⌋₊) := + (measurable_const.mul ht).nat_floor + have hh := hprod.comp (hi.prodMk measurable_snd) + have he : (fun p : Set.Iic s × Ω => B (leftMeshTime n p.1) p.2) = + (fun p : ℕ × Ω => B (min ((p.1:ℝ≥0)/((n+1:ℕ):ℝ≥0)) s) p.2) ∘ + (fun p : Set.Iic s × Ω => (⌊((n+1:ℕ):ℝ)*((p.1:ℝ≥0):ℝ)⌋₊,p.2)) := by + funext p + have hle := (leftMeshTime_le n (p.1:ℝ≥0)).trans p.1.property + dsimp only [leftMeshTime] at hle + simp only [Function.comp_def,leftMeshTime,min_eq_left hle] + rw [he] + exact hh + +def BrownianSystem.progressiveVersion (W : BrownianSystem Ω) (t : ℝ≥0) (ξ : Ω) : ℝ := + atTop.limUnder (fun n => W.B (leftMeshTime n t) ξ) + +lemma BrownianSystem.progressiveVersion_progressive (W : BrownianSystem Ω) : + IsProgressive (Filtration.natural W.B (fun t => (W.measurable t).stronglyMeasurable)) + W.progressiveVersion := by + intro s + let ℱ := Filtration.natural W.B (fun t => (W.measurable t).stronglyMeasurable) + have hn : Adapted ℱ W.B := fun t => + (Filtration.stronglyAdapted_natural (fun t => (W.measurable t).stronglyMeasurable) t).measurable + let B : ℝ≥0 → Ω → ℝ := W.B + have hm (n : ℕ) : StronglyMeasurable[(Subtype.instMeasurableSpace).prod (ℱ s)] + (fun p : Set.Iic s × Ω => B (leftMeshTime n p.1) p.2) := + (leftMesh_progressive ℱ hn n s).stronglyMeasurable + let : MeasurableSpace Ω := ℱ s + exact (StronglyMeasurable.limUnder hm).measurable + +lemma BrownianSystem.progressiveVersion_eq (W : BrownianSystem Ω) {ξ : Ω} + (hc : Continuous (fun t => W.B t ξ)) (t : ℝ≥0) : W.progressiveVersion t ξ = W.B t ξ := + ((hc.tendsto t).comp (leftMeshTime_tendsto t)).limUnder_eq + +lemma BrownianSystem.progressiveVersion_indistinguishable (W : BrownianSystem Ω) : + ∀ᵐ ξ ∂W.law, ∀ t, W.progressiveVersion t ξ = W.B t ξ := by + filter_upwards [W.brownian.cont] with ξ hξ + exact W.progressiveVersion_eq hξ + +def BrownianSystem.driver (W : BrownianSystem Ω) (t : ℝ≥0) (ξ : Ω) : ℝ := + W.progressiveVersion t ξ-W.progressiveVersion 0 ξ + +lemma BrownianSystem.driver_progressive (W : BrownianSystem Ω) : + IsProgressive (Filtration.natural W.B (fun t => (W.measurable t).stronglyMeasurable)) W.driver := by + intro s + have hm := W.progressiveVersion_progressive.adapted 0 + have hm' := hm.mono ((Filtration.natural W.B (fun t => (W.measurable t).stronglyMeasurable)).mono + (show (0:ℝ≥0) ≤ s by positivity)) le_rfl + exact (W.progressiveVersion_progressive s).sub (hm'.comp measurable_snd) + +lemma BrownianSystem.driver_zero (W : BrownianSystem Ω) (ξ : Ω) : W.driver 0 ξ = 0 := sub_self _ + +lemma BrownianSystem.driver_indistinguishable (W : BrownianSystem Ω) : + ∀ᵐ ξ ∂W.law, ∀ t, W.driver t ξ = W.B t ξ := by + filter_upwards [W.progressiveVersion_indistinguishable,W.brownian.eval_zero_ae_eq_zero] with ξ hh h₀ t + simp only [BrownianSystem.driver,hh,h₀,sub_zero] + +lemma BrownianSystem.driver_continuous (W : BrownianSystem Ω) : + ∀ᵐ ξ ∂W.law, Continuous (fun t => W.driver t ξ) := by + filter_upwards [W.driver_indistinguishable,W.brownian.cont] with ξ hh hc + simpa only [hh] using hc + +end ZeroTemperatureSK + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKSupport/Diffusion/ProgressiveIntegralMeasurable.lean b/lean/OAI/Probability/SKSupport/Diffusion/ProgressiveIntegralMeasurable.lean new file mode 100644 index 0000000000000000000000000000000000000000..88a5de19294578360da68297166305c26b25c7b3 --- /dev/null +++ b/lean/OAI/Probability/SKSupport/Diffusion/ProgressiveIntegralMeasurable.lean @@ -0,0 +1,48 @@ +import Mathlib +import OAI.Probability.SKSupport.Model + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section +namespace ZeroTemperatureSK.WeakIto +variable {Ω : Type*} [mΩ : MeasurableSpace Ω] + +lemma progressive_integral_measurable (ℱ : Filtration ℝ≥0 mΩ) + {α : ℝ≥0 → Ω → ℝ} (hα : IsProgressive ℱ α) (s : ℝ≥0) {w : ℝ → ℝ} + (hw : Measurable w) : + Measurable[ℱ s] (fun ω => ∫ r in (0:ℝ)..(s:ℝ), w r*α (Real.toNNReal r) ω) := by + let clip (p : ℝ × Ω) := α (min (Real.toNNReal p.1) s) p.2 + have htime : Measurable[(borel ℝ).prod (ℱ s)] + (fun p : ℝ × Ω => min (Real.toNNReal p.1) s) := + (measurable_fst.real_toNNReal).min measurable_const + have hclip : Measurable[(borel ℝ).prod (ℱ s)] clip := by + exact (hα s).comp ((htime.subtype_mk (h := fun p : ℝ × Ω => (min_le_right (Real.toNNReal p.1) s))).prodMk measurable_snd) + have hwm : Measurable[(borel ℝ).prod (ℱ s)] (fun p : ℝ × Ω => w p.1*clip p) := + (hw.comp measurable_fst).mul hclip + have hint : Measurable[ℱ s] + (fun ω => ∫ r in (0:ℝ)..(s:ℝ), w r*clip (r,ω)) := by + let : MeasurableSpace Ω := ℱ s + simp_rw [intervalIntegral.integral_of_le s.coe_nonneg] + exact hwm.stronglyMeasurable.integral_prod_left.measurable + convert hint using 1 + funext ω + apply intervalIntegral.integral_congr + intro r hr + rw [Set.uIcc_of_le s.coe_nonneg] at hr + have hle : Real.toNNReal r ≤ s := by + exact Real.toNNReal_le_iff_le_coe.mpr hr.2 + simp only [clip, min_eq_left hle] + +end ZeroTemperatureSK.WeakIto + +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKSupport/Diffusion/StepDrift.lean b/lean/OAI/Probability/SKSupport/Diffusion/StepDrift.lean new file mode 100644 index 0000000000000000000000000000000000000000..b237faf51711299429c78daeddee1406b279062b --- /dev/null +++ b/lean/OAI/Probability/SKSupport/Diffusion/StepDrift.lean @@ -0,0 +1,110 @@ +import Mathlib +import OAI.Probability.SKSupport.Moments.IntegratedCompletionSquare + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section +namespace ZeroTemperatureSK.WeakIto +variable {Ω : Type*} [MeasurableSpace Ω] {P : Measure Ω} [IsProbabilityMeasure P] + +def stepDrift (α : ℝ → Ω → ℝ) (s h c : ℝ) (ω : Ω) : ℝ := + ∫ r in s..s+h, c*α r ω + +def stepCost (α : ℝ → Ω → ℝ) (s h c : ℝ) (ω : Ω) : ℝ := + (1/2:ℝ)*∫ r in s..s+h, c*(α r ω)^2 + +lemma bounded_control_intervalIntegrable {α : ℝ → Ω → ℝ} + (hm : Measurable (fun p : ℝ × Ω => α p.1 p.2)) + (hb : ∀ r ω, |α r ω| ≤ 1) (s h : ℝ) (hh : 0 ≤ h) (ω : Ω) : + IntervalIntegrable (fun r => α r ω) volume s (s+h) ∧ + IntervalIntegrable (fun r => (α r ω)^2) volume s (s+h) := by + have hm₁ : Measurable (fun r => α r ω) := hm.comp measurable_prodMk_right + rw [intervalIntegrable_iff_integrableOn_Ioc_of_le (by linarith : s ≤ s+h), + intervalIntegrable_iff_integrableOn_Ioc_of_le (by linarith : s ≤ s+h)] + constructor + · exact Integrable.of_bound hm₁.aestronglyMeasurable 1 + (Filter.Eventually.of_forall (fun r => by simpa only [Real.norm_eq_abs] using hb r ω)) + · apply Integrable.of_bound (hm₁.pow_const 2).aestronglyMeasurable 1 + filter_upwards [] with r + rw [Real.norm_eq_abs, abs_pow] + simpa using pow_le_pow_left₀ (abs_nonneg (α r ω)) (hb r ω) 2 + +lemma stepDrift_measurable {α : ℝ → Ω → ℝ} + (hm : Measurable (fun p : ℝ × Ω => α p.1 p.2)) (s h c : ℝ) (hh : 0 ≤ h) : + Measurable (stepDrift α s h c) := by + unfold stepDrift + simp_rw [intervalIntegral.integral_of_le (by linarith : s ≤ s+h)] + exact (hm.const_mul c).stronglyMeasurable.integral_prod_left.measurable + +lemma stepCost_measurable {α : ℝ → Ω → ℝ} + (hm : Measurable (fun p : ℝ × Ω => α p.1 p.2)) (s h c : ℝ) (hh : 0 ≤ h) : + Measurable (stepCost α s h c) := by + unfold stepCost + simp_rw [intervalIntegral.integral_of_le (by linarith : s ≤ s+h)] + exact (((hm.pow_const 2).const_mul c).stronglyMeasurable.integral_prod_left.measurable).const_mul _ + +omit [MeasurableSpace Ω] in +lemma stepDrift_bound {α : ℝ → Ω → ℝ} + (hb : ∀ r ω, |α r ω| ≤ 1) (s h c : ℝ) (hh : 0 ≤ h) (hc : 0 ≤ c) (ω : Ω) : + |stepDrift α s h c ω| ≤ c*h := by + unfold stepDrift + rw [← Real.norm_eq_abs] + have hbound : ‖∫ r in s..s+h, c*α r ω‖ ≤ ∫ _r in s..s+h, c := by + apply intervalIntegral.norm_integral_le_of_norm_le (by linarith) + _ intervalIntegrable_const + filter_upwards [] with r hr + rw [Real.norm_eq_abs, abs_mul, abs_of_nonneg hc] + nlinarith [hb r ω] + simpa only [intervalIntegral.integral_const, smul_eq_mul, add_sub_cancel_left, mul_comm] using hbound + +omit [MeasurableSpace Ω] in +lemma stepCost_bound {α : ℝ → Ω → ℝ} + (hb : ∀ r ω, |α r ω| ≤ 1) (s h c : ℝ) (hh : 0 ≤ h) (hc : 0 ≤ c) (ω : Ω) : + |stepCost α s h c ω| ≤ c*h/2 := by + unfold stepCost + rw [abs_mul, abs_of_nonneg (by norm_num : (0:ℝ) ≤ 1/2)] + have hbound : |∫ r in s..s+h, c*(α r ω)^2| ≤ c*h := by + apply stepDrift_bound (α := fun r ω => (α r ω)^2) _ s h c hh hc ω + intro r ω + rw [abs_pow] + simpa using pow_le_pow_left₀ (abs_nonneg (α r ω)) (hb r ω) 2 + linarith + +lemma stepDrift_integrable {α : ℝ → Ω → ℝ} + (hm : Measurable (fun p : ℝ × Ω => α p.1 p.2)) + (hb : ∀ r ω, |α r ω| ≤ 1) (s h c : ℝ) (hh : 0 ≤ h) (hc : 0 ≤ c) : + Integrable (stepDrift α s h c) P := by + exact Integrable.of_bound (stepDrift_measurable hm s h c hh).aestronglyMeasurable (c*h) + (Filter.Eventually.of_forall (fun ω => by + simpa only [Real.norm_eq_abs] using (stepDrift_bound hb s h c hh hc ω))) + +lemma stepCost_integrable {α : ℝ → Ω → ℝ} + (hm : Measurable (fun p : ℝ × Ω => α p.1 p.2)) + (hb : ∀ r ω, |α r ω| ≤ 1) (s h c : ℝ) (hh : 0 ≤ h) (hc : 0 ≤ c) : + Integrable (stepCost α s h c) P := by + exact Integrable.of_bound (stepCost_measurable hm s h c hh).aestronglyMeasurable (c*h/2) + (Filter.Eventually.of_forall (fun ω => by + simpa only [Real.norm_eq_abs] using (stepCost_bound hb s h c hh hc ω))) + +lemma step_completion_square {α : ℝ → Ω → ℝ} + (hm : Measurable (fun p : ℝ × Ω => α p.1 p.2)) + (hb : ∀ r ω, |α r ω| ≤ 1) (s h c : ℝ) (hh : 0 ≤ h) (hc : 0 ≤ c) + (u : ℝ) (ω : Ω) : + u*stepDrift α s h c ω-stepCost α s h c ω ≤ h*c/2*u^2 := by + obtain ⟨hα,hα₂⟩ := bounded_control_intervalIntegrable hm hb s h hh ω + simpa only [stepDrift, stepCost, add_sub_cancel_left] using + integrated_completion_square s (s+h) c u (by linarith) hc hα hα₂ + +end ZeroTemperatureSK.WeakIto + +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKSupport/Diffusion/TerminalShapes.lean b/lean/OAI/Probability/SKSupport/Diffusion/TerminalShapes.lean new file mode 100644 index 0000000000000000000000000000000000000000..7063272759a926601800804deab3bc7a053dbe9b --- /dev/null +++ b/lean/OAI/Probability/SKSupport/Diffusion/TerminalShapes.lean @@ -0,0 +1,100 @@ +import Mathlib +import OAI.Probability.SKSupport.Moments.BurgersJets + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology ContDiff +noncomputable section +namespace ZeroTemperatureSK.Heat + +def tanhDrift (c M x : ℝ) : ℝ := c*Real.tanh (M*x) + +lemma tanh_scaled_derivative (M x : ℝ) : + HasDerivAt (fun y => Real.tanh (M*y)) (M*(1-(Real.tanh (M*x))^2)) x := by + convert (hasDerivAt_tanh (M*x)).comp x ((hasDerivAt_id x).const_mul M) using 1 <;> + first | rfl | ring + +lemma tanhDrift_derivative (c M x : ℝ) : + HasDerivAt (tanhDrift c M) (c*M*(1-(Real.tanh (M*x))^2)) x := by + convert (tanh_scaled_derivative M x).const_mul c using 1 <;> first | rfl | ring + +lemma tanhDrift_second (c M x : ℝ) : + iteratedDeriv 2 (tanhDrift c M) x = -2*c*M^2*Real.tanh (M*x)*(1-(Real.tanh (M*x))^2) := by + have he : deriv (tanhDrift c M) = fun y => c*M*(1-(Real.tanh (M*y))^2) := + funext (fun y => (tanhDrift_derivative c M y).deriv) + rw [iteratedDeriv_succ (n := 1),iteratedDeriv_one,he] + convert ((((tanh_scaled_derivative M x).pow 2).const_sub 1).const_mul (c*M)).deriv using 1 + ring + +lemma tanhDrift_rate (c M x : ℝ) : + burgersRate (fun _ => tanhDrift c M) 0 x = + c*M*(c-M)*Real.tanh (M*x)*(1-(Real.tanh (M*x))^2) := by + rw [burgersRate,tanhDrift_second,(tanhDrift_derivative c M x).deriv] + dsimp only [tanhDrift] + ring + +lemma tanhDrift_wronskian (c M x : ℝ) : + backwardWronskian (fun _ => tanhDrift c M) 0 x = + 2*c^2*M^2*(M-c)*(Real.tanh (M*x))^3*(1-(Real.tanh (M*x))^2) := by + have he : burgersRate (fun _ => tanhDrift c M) 0 = fun y => + c*M*(c-M)*Real.tanh (M*y)*(1-(Real.tanh (M*y))^2) := funext (tanhDrift_rate c M) + have hd := ((tanh_scaled_derivative M x).const_mul (c*M*(c-M))).mul + (((tanh_scaled_derivative M x).pow 2).const_sub 1) + have hd' : HasDerivAt (fun y => c*M*(c-M)*Real.tanh (M*y)*(1-(Real.tanh (M*y))^2)) + (c*M^2*(c-M)*(1-(Real.tanh (M*x))^2)*(1-3*(Real.tanh (M*x))^2)) x := by + convert hd using 1 + simp only [Pi.pow_apply] + ring + rw [backwardWronskian,he,hd'.deriv,(tanhDrift_derivative c M x).deriv] + dsimp only [tanhDrift] + ring + +lemma tanh_sq_gap_pos (y : ℝ) : 0 < 1-(Real.tanh y)^2 := by + have hh := Real.abs_tanh_lt_one y + nlinarith [sq_abs (Real.tanh y),abs_nonneg (Real.tanh y)] + +lemma tanh_nonneg_of_nonneg {y : ℝ} (hy : 0 ≤ y) : 0 ≤ Real.tanh y := by + rw [Real.tanh_eq_sinh_div_cosh] + exact div_nonneg (Real.sinh_nonneg_iff.mpr hy) (Real.cosh_pos y).le + +lemma tanhDrift_initial_signs {c M : ℝ} (hc : 0 < c) (hM : c ≤ M) (x : ℝ) (hx : 0 ≤ x) : + iteratedDeriv 2 (tanhDrift c M) x ≤ 0 ∧ + burgersRate (fun _ => tanhDrift c M) 0 x ≤ 0 ∧ + 0 ≤ backwardWronskian (fun _ => tanhDrift c M) 0 x := by + have hMp : 0 < M := hc.trans_le hM + have hT := tanh_nonneg_of_nonneg (mul_nonneg hMp.le hx) + have hD := (tanh_sq_gap_pos (M*x)).le + rw [tanhDrift_second,tanhDrift_rate,tanhDrift_wronskian] + refine ⟨?_,?_,?_⟩ + · apply mul_nonpos_of_nonpos_of_nonneg _ hD + apply mul_nonpos_of_nonpos_of_nonneg _ hT + apply mul_nonpos_of_nonpos_of_nonneg _ (sq_nonneg M) + exact mul_nonpos_of_nonpos_of_nonneg (by norm_num) hc.le + · apply mul_nonpos_of_nonpos_of_nonneg _ hD + apply mul_nonpos_of_nonpos_of_nonneg _ hT + exact mul_nonpos_of_nonneg_of_nonpos (mul_nonneg hc.le hMp.le) (sub_nonpos.mpr hM) + · exact mul_nonneg (mul_nonneg (mul_nonneg (by positivity) (sub_nonneg.mpr hM)) + (pow_nonneg hT _)) hD + +lemma gaussianBurgers_terminal {f : ℝ → ℝ} (c : ℝ) : + gaussianBurgers c f 0 = fun x => c*deriv f x := by + have he : varianceLogHeat c 0 f = f := funext (fun x => by + simpa only [backward,sub_self] using backward_terminal c 0 f x) + funext x + rw [gaussianBurgers,he] + +lemma gaussianBurgers_softAbs_terminal {M : ℝ} (hM : M ≠ 0) (c : ℝ) : + gaussianBurgers c (softAbs M) 0 = tanhDrift c M := by + rw [gaussianBurgers_terminal] + funext x + rw [(hasDerivAt_softAbs hM x).deriv] + rfl + +end ZeroTemperatureSK.Heat + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKSupport/Diffusion/Uniqueness.lean b/lean/OAI/Probability/SKSupport/Diffusion/Uniqueness.lean new file mode 100644 index 0000000000000000000000000000000000000000..0e06bf5e26b598629d20a0e71de2513bf46f05a6 --- /dev/null +++ b/lean/OAI/Probability/SKSupport/Diffusion/Uniqueness.lean @@ -0,0 +1,70 @@ +import Mathlib +import OAI.Probability.SKSupport.Moments.StripSquareMoment + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section +namespace ZeroTemperatureSK +variable {Ω : Type*} [MeasurableSpace Ω] + +theorem diffusion_uniqueness (W : BrownianSystem Ω) (γ : OrderParameter) + {X : ℝ≥0 → Ω → ℝ} (hX : IsDiffusion W γ X) : + ∀ᵐ ω ∂W.law, ∀ t : ℝ≥0, t ≤ 1 → X t ω = diffusion W γ t ω := by + let ℱ := Filtration.natural W.B (fun t => (W.measurable t).stronglyMeasurable) + have hZ : IsProgressive ℱ (fun t ω => X t ω-W.driver t ω) := hX.1.sub W.driver_progressive + filter_upwards [hX.2,W.driver_indistinguishable] with ω hω hB + have hbefore (t : ℝ≥0) (ht : (t:ℝ) < 1) : X t ω = diffusion W γ t ω := by + let T : Time := ⟨t,⟨t.coe_nonneg,ht⟩⟩ + let b := stripDrift W γ T + have he := b.correction_unique_on ℱ W.driver_progressive hZ t ω + have hfix : ∀ s ≤ t, X s ω-W.driver s ω = + timePrimitive (b.action W.driver (fun r ω => X r ω-W.driver r ω)) s ω := by + intro s hs + have hst : (s:ℝ) ≤ t := hs + have hs1 : (s:ℝ) ≤ 1 := hst.trans ht.le + have hi := hω.2.2 (s:ℝ) ⟨s.coe_nonneg,hs1⟩ + simp only [Real.toNNReal_coe] at hi + rw [hi,hB s,add_sub_cancel_left] + unfold timePrimitive BoundedLipschitzDrift.action + apply intervalIntegral.integral_congr + intro r hr + rw [uIcc_of_le s.coe_nonneg] at hr + have hrt : ((Real.toNNReal r):ℝ) ≤ (T:ℝ) := by rw [Real.coe_toNNReal _ hr.1]; exact hr.2.trans hst + dsimp only + rw [add_sub_cancel,stripDrift_eq W γ T ⟨(Real.toNNReal r).coe_nonneg,hrt⟩, + Real.coe_toNNReal _ hr.1] + have hc := he hfix t le_rfl + rw [diffusion_eq_strip W γ T t le_rfl] + change X t ω = W.driver t ω+b.correction W.driver t ω + rw [hc] + ring + intro t ht + by_cases ht1 : (t:ℝ) < 1 + · exact hbefore t ht1 + have he : t=1 := le_antisymm ht (by exact_mod_cast not_lt.mp ht1) + subst t + have hi := hω.2.2 1 ⟨by norm_num,le_rfl⟩ + simp only [Real.toNNReal_one] at hi + rw [hi,diffusion,hB 1] + congr 1 + apply intervalIntegral.integral_congr + intro r hr + rw [uIcc_of_le (show (0:ℝ) ≤ 1 by norm_num)] at hr + by_cases hr1 : r<1 + · have hrr : ((Real.toNNReal r):ℝ) < 1 := by rw [Real.coe_toNNReal _ hr.1]; exact hr1 + dsimp only + rw [rawFeedback_eq W γ _ hrr,Real.coe_toNNReal _ hr.1, + hbefore (Real.toNNReal r) hrr,diffusion_eq_raw W γ _ hrr] + · have hr_eq : r=1 := le_antisymm hr.2 (not_lt.mp hr1) + subst r + simp [extend] + +end ZeroTemperatureSK + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKSupport/Diffusion/VariableFeedbackEuler.lean b/lean/OAI/Probability/SKSupport/Diffusion/VariableFeedbackEuler.lean new file mode 100644 index 0000000000000000000000000000000000000000..4d680fad28e0f7669bb97b9aae4344b567d0eb5c --- /dev/null +++ b/lean/OAI/Probability/SKSupport/Diffusion/VariableFeedbackEuler.lean @@ -0,0 +1,151 @@ +import Mathlib +import OAI.Probability.SKSupport.Diffusion.ExpectedFeedbackStep +import OAI.Probability.SKSupport.Control.ControlledGrid + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section +namespace ZeroTemperatureSK.WeakIto +variable {Ω : Type*} [mΩ : MeasurableSpace Ω] {P : Measure Ω} {B : ℝ≥0 → Ω → ℝ} + +def variableFeedbackEuler (B : ℝ≥0 → Ω → ℝ) (h : ℝ≥0) (c : ℕ → ℝ≥0) + (u : ℕ → ℝ → ℝ) (x : ℝ) : ℕ → Ω → ℝ + | 0, _ => x + | k+1, ω => variableFeedbackEuler B h c u x k ω + + (B (((k+1:ℕ):ℝ≥0)*h) ω-B ((k:ℝ≥0)*h) ω)+ + (c k:ℝ)*(h:ℝ)*u k (variableFeedbackEuler B h c u x k ω) + +lemma variableFeedbackEuler_adapted (hm : ∀ t, Measurable (B t)) + (h : ℝ≥0) (c : ℕ → ℝ≥0) {u : ℕ → ℝ → ℝ} (hum : ∀ k, Measurable (u k)) + (x : ℝ) (n : ℕ) : + Measurable[Filtration.natural B (fun t => (hm t).stronglyMeasurable) ((n:ℝ≥0)*h)] + (variableFeedbackEuler B h c u x n) := by + induction n with + | zero => exact measurable_const + | succ n IH => + have hle : (n:ℝ≥0)*h ≤ ((n+1:ℕ):ℝ≥0)*h := by gcongr; exact_mod_cast Nat.le_succ n + have hYm := IH.mono ((Filtration.natural B (fun t => (hm t).stronglyMeasurable)).mono hle) le_rfl + have hBs := (Filtration.stronglyAdapted_natural (fun t => (hm t).stronglyMeasurable) ((n:ℝ≥0)*h)).measurable.mono + ((Filtration.natural B (fun t => (hm t).stronglyMeasurable)).mono hle) le_rfl + have hBt := (Filtration.stronglyAdapted_natural (fun t => (hm t).stronglyMeasurable) (((n+1:ℕ):ℝ≥0)*h)).measurable + exact (hYm.add (hBt.sub hBs)).add (((hum _).comp hYm).const_mul ((c n:ℝ)*(h:ℝ))) + +omit mΩ in +lemma variableFeedback_controlledGrid (h : ℝ≥0) (c : ℕ → ℝ≥0) + (u : ℕ → ℝ → ℝ) (x : ℝ) (n k : ℕ) (hk : k ≤ n) (ω : Ω) : + let a := fun j ω => u j (variableFeedbackEuler B h c u x j ω) + controlledGrid B (elementaryControl h a n) h c x k ω = + variableFeedbackEuler B h c u x k ω := by + dsimp only + induction k with + | zero => rfl + | succ k IH => + have hk' : k < n := by omega + have he := elementaryControl_integral_on_step h + (fun j ω => u j (variableFeedbackEuler B h c u x j ω)) n k hk' + (fun z => (c k:ℝ)*z) ω + change stepDrift (fun r => elementaryControl h + (fun j ω => u j (variableFeedbackEuler B h c u x j ω)) n (Real.toNNReal r)) + ((k:ℝ≥0)*h) h (c k) ω = _ at he + simp only [controlledGrid, he, IH hk'.le, variableFeedbackEuler] + ring + +lemma variable_grid_verification_lower (hB : IsPreBrownianReal B P) + (hm : ∀ t, Measurable (B t)) (h : ℝ≥0) (c : ℕ → ℝ≥0) (x : ℝ) (n : ℕ) + {F D : ℕ → ℝ → ℝ → ℝ} (C₂ C₃ Ct L : ℕ → ℝ≥0) + (hf : ∀ k t, ContDiff ℝ 3 (F k t)) + (hC₁ : ∀ k t z, |deriv (F k t) z| ≤ 1) + (hC₂ : ∀ k < n, ∀ t z, |deriv (deriv (F k t)) z| ≤ C₂ k) + (hC₃ : ∀ k < n, ∀ t z, |iteratedDeriv 3 (F k t) z| ≤ C₃ k) + (hDm : ∀ k < n, Measurable (D k ((k:ℝ≥0)*h))) + (hCt : ∀ k < n, ∀ z, |D k ((k:ℝ≥0)*h) z| ≤ Ct k) + (hD : ∀ k < n, ∀ r ∈ Set.Icc ((k:ℝ)*(h:ℝ)) (((k:ℝ)+1)*(h:ℝ)), ∀ z, + HasDerivWithinAt (fun t => F k t z) (D k r z) + (Set.Icc ((k:ℝ)*(h:ℝ)) (((k:ℝ)+1)*(h:ℝ))) r) + (hL : ∀ k < n, ∀ r ∈ Set.Icc ((k:ℝ)*(h:ℝ)) (((k:ℝ)+1)*(h:ℝ)), ∀ z y, + |D k r z-D k ((k:ℝ≥0)*h) y| ≤ (L k:ℝ)*(|r-(k:ℝ)*(h:ℝ)|+|z-y|)) + (hPDE : ∀ k < n, ∀ z, D k ((k:ℝ≥0)*h) z+ + (1/2:ℝ)*deriv (deriv (F k ((k:ℝ≥0)*h))) z+ + (c k:ℝ)/2*(deriv (F k ((k:ℝ≥0)*h)) z)^2 = 0) + (hseam : ∀ k < n, F k (((k+1:ℕ):ℝ)*(h:ℝ)) = F (k+1) (((k+1:ℕ):ℝ)*(h:ℝ))) + {ε : ℝ} (hε : ∀ k < n, verificationError (c k) (C₂ k) (C₃ k) (L k) h ≤ ε) : + ∃ α : ℝ≥0 → Ω → ℝ, + IsProgressive (Filtration.natural B (fun t => (hm t).stronglyMeasurable)) α ∧ + (∀ t ω, |α t ω| ≤ 1) ∧ + F 0 0 x-(n:ℝ)*ε ≤ + (∫ ω, F n ((n:ℝ)*(h:ℝ)) (controlledGrid B α h c x n ω) ∂P)- + (∑ k ∈ Finset.range n, ∫ ω, stepCost (fun r => α (Real.toNNReal r)) + ((k:ℝ≥0)*h) h (c k) ω ∂P) := by + let := hB.isGaussianProcess.isProbabilityMeasure + let u (k : ℕ) := deriv (F k ((k:ℝ≥0)*h)) + let a (k : ℕ) (ω : Ω) := u k (variableFeedbackEuler B h c u x k ω) + let α := elementaryControl h a n + have hum : ∀ k, Measurable (u k) := fun k => + (show ContDiff ℝ 2 (u k) from (hf k _).deriv').continuous.measurable + have hap : IsProgressive (Filtration.natural B (fun t => (hm t).stronglyMeasurable)) α := + elementaryControl_progressive _ h (fun k => (hum k).comp + (variableFeedbackEuler_adapted hm h c hum x k)) n + have hab : ∀ t ω, |α t ω| ≤ 1 := elementaryControl_bound h (fun k ω => hC₁ _ _ _) n + refine ⟨α,hap,hab,?_⟩ + have ham := progressive_joint_measurable _ hap + have hgrid (k : ℕ) (hk : k ≤ n) (ω : Ω) : + controlledGrid B α h c x k ω = variableFeedbackEuler B h c u x k ω := + variableFeedback_controlledGrid h c u x n k hk ω + let Q (k : ℕ) := ∫ ω, F k ((k:ℝ)*(h:ℝ)) (controlledGrid B α h c x k ω) ∂P + let K (k : ℕ) := ∫ ω, stepCost (fun r => α (Real.toNNReal r)) ((k:ℝ≥0)*h) h (c k) ω ∂P + have hstep : ∀ k < n, -Q (k+1)-(-Q k)-(-K k) ≤ ε := by + intro k hk + have ht : (k:ℝ≥0)*h+h = ((k+1:ℕ):ℝ≥0)*h := by push_cast; ring + have ht' : (↑((k:ℝ≥0)*h):ℝ)+(h:ℝ) = (((k:ℝ)+1)*(h:ℝ)) := by push_cast; ring + have hg := expected_feedback_step hB hm ((k:ℝ≥0)*h) h (c k) + (controlledGrid_adapted hm hap hab h c x k) (controlledGrid_integrable hB ham hab h c x k) + (hf k) (C₂ k) (C₃ k) (Ct k) (L k) (hC₁ k) (hC₂ k hk) (hC₃ k hk) (hDm k hk) (hCt k hk) + (by simpa only [NNReal.coe_mul, NNReal.coe_natCast, add_mul, one_mul] using hD k hk) + (by simpa only [NNReal.coe_mul, NNReal.coe_natCast, add_mul, one_mul] using hL k hk) + (hPDE k hk) + have he : (fun ω => F k ((↑((k:ℝ≥0)*h):ℝ)+(h:ℝ)) + (controlledGrid B α h c x k ω+(B ((k:ℝ≥0)*h+h) ω-B ((k:ℝ≥0)*h) ω)+ + (c k:ℝ)*(h:ℝ)*deriv (F k ((k:ℝ≥0)*h)) (controlledGrid B α h c x k ω))) = + fun ω => F (k+1) (((k+1:ℕ):ℝ)*(h:ℝ)) (controlledGrid B α h c x (k+1) ω) := by + funext ω + rw [ht, ht'] + simp only [← Nat.cast_add_one, hseam k hk] + rw [hgrid k hk.le, hgrid (k+1) (by omega)] + rfl + simp only [NNReal.coe_mul, NNReal.coe_natCast] at hg he + rw [he] at hg + have hK : K k = (c k:ℝ)*(h:ℝ)/2* + (∫ ω, (deriv (F k ((k:ℝ≥0)*h)) (controlledGrid B α h c x k ω))^2 ∂P) := by + dsimp only [K] + rw [← integral_const_mul] + apply integral_congr_ae + filter_upwards [] with ω + have hh := elementary_stepCost h (c k) a n k hk ω + change stepCost (fun r => α (Real.toNNReal r)) ((k:ℝ≥0)*h) h (c k) ω = + (c k:ℝ)*(h:ℝ)/2*(a k ω)^2 at hh + rw [hh] + dsimp only [a, u] + rw [hgrid k hk.le] + have hg' : |Q (k+1)-Q k-K k| ≤ ε := by + rw [hK] + exact hg.trans (hε k hk) + linarith [(abs_le.mp hg').1] + have hh := finite_mesh_verification (fun k => -Q k) (fun k => -K k) n ε hstep + have hz : Q 0 = F 0 0 x := by simp [Q, controlledGrid] + rw [hz, Finset.sum_neg_distrib] at hh + change F 0 0 x-(n:ℝ)*ε ≤ Q n-∑ k ∈ Finset.range n, K k + linarith + +end ZeroTemperatureSK.WeakIto + +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKSupport/Foundations/AdaptedIndepIncrement.lean b/lean/OAI/Probability/SKSupport/Foundations/AdaptedIndepIncrement.lean new file mode 100644 index 0000000000000000000000000000000000000000..5e3a879cf7725babe93f1930fa8ae355cea142cf --- /dev/null +++ b/lean/OAI/Probability/SKSupport/Foundations/AdaptedIndepIncrement.lean @@ -0,0 +1,106 @@ +import Mathlib +import OAI.Probability.SKSupport.Model + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section +namespace ZeroTemperatureSK.WeakIto +variable {Ω : Type*} [mΩ : MeasurableSpace Ω] {P : Measure Ω} +variable {B : ℝ≥0 → Ω → ℝ} + +lemma adapted_indep_increment (hB : IsPreBrownianReal B P) + (hm : ∀ t, Measurable (B t)) (s h : ℝ≥0) {Y : Ω → ℝ} + (hY : Measurable[Filtration.natural B (fun t => (hm t).stronglyMeasurable) s] Y) : + IndepFun Y (fun ω => B (s+h) ω - B s ω) P := by + have hi := (hB.indepFun_shift s).comp (measurable_pi_apply h) measurable_id + change IndepFun (fun ω => B (s+h) ω - B s ω) + (fun ω (t : Set.Iic s) => B t ω) P at hi + apply Indep.symm + apply indep_of_indep_of_le hi le_rfl + rw [← Filtration.natural_eq_comap B (fun t => (hm t).stronglyMeasurable) s] + exact measurable_iff_comap_le.mp hY + +lemma integral_adapted_mul_increment (hB : IsPreBrownianReal B P) + (hm : ∀ t, Measurable (B t)) (s h : ℝ≥0) {Y : Ω → ℝ} + (hY : Measurable[Filtration.natural B (fun t => (hm t).stronglyMeasurable) s] Y) : + (∫ ω, Y ω * (B (s+h) ω - B s ω) ∂P) = 0 := by + have hYm : Measurable Y := hY.mono + ((Filtration.natural B (fun t => (hm t).stronglyMeasurable)).le s) le_rfl + rw [(adapted_indep_increment hB hm s h hY).integral_fun_mul_eq_mul_integral + hYm.aestronglyMeasurable ((hm (s+h)).sub (hm s)).aestronglyMeasurable] + rw [integral_sub (hB.integrable_eval _) (hB.integrable_eval _), hB.integral_eval, + hB.integral_eval] + simp + +lemma gaussian_second_moment (v : ℝ≥0) : + (∫ x : ℝ, x^2 ∂gaussianReal 0 v) = (v : ℝ) := by + have h := variance_fun_id_gaussianReal (μ := 0) (v := v) + rw [variance_eq_integral (X := fun x : ℝ => x) measurable_id'.aemeasurable] at h + simpa using h + +lemma integral_adapted_mul_increment_sq (hB : IsPreBrownianReal B P) + (hm : ∀ t, Measurable (B t)) (s h : ℝ≥0) {Y : Ω → ℝ} + (hY : Measurable[Filtration.natural B (fun t => (hm t).stronglyMeasurable) s] Y) : + (∫ ω, Y ω * (B (s+h) ω - B s ω)^2 ∂P) = (h : ℝ) * ∫ ω, Y ω ∂P := by + have hYm : Measurable Y := hY.mono + ((Filtration.natural B (fun t => (hm t).stronglyMeasurable)).le s) le_rfl + have hi := (adapted_indep_increment hB hm s h hY).comp measurable_id + (measurable_id.pow_const 2) + change IndepFun Y (fun ω => (B (s+h) ω - B s ω)^2) P at hi + rw [hi.integral_fun_mul_eq_mul_integral hYm.aestronglyMeasurable + (((hm (s+h)).sub (hm s)).pow_const 2).aestronglyMeasurable] + have he := (hB.hasLaw_sub (s+h) s).integral_comp + (f := fun x : ℝ => x^2) ((measurable_id.pow_const 2).aestronglyMeasurable) + change (∫ ω, (B (s+h) ω - B s ω)^2 ∂P) = _ at he + rw [he, gaussian_second_moment] + rw [coe_nndist, Real.dist_eq] + change (∫ ω, Y ω ∂P) * |((s+h : ℝ≥0) : ℝ) - (s : ℝ)| = _ + rw [NNReal.coe_add, add_sub_cancel_left, abs_of_nonneg h.coe_nonneg] + ring + +end ZeroTemperatureSK.WeakIto + +namespace ZeroTemperatureSK.WeakIto + +lemma taylor2_bound {f : ℝ → ℝ} (hf : ContDiff ℝ 3 f) {C : ℝ} + (hC : ∀ x, |iteratedDeriv 3 f x| ≤ C) (x d : ℝ) : + |f (x+d) - f x - deriv f x*d - (1/2:ℝ)*deriv (deriv f) x*d^2| ≤ + C / 6 * |d|^3 := by + by_cases hd : d = 0 + · simp [hd] + have hxd : x ≠ x+d := by intro h; apply hd; linarith + obtain ⟨y, hy, he⟩ := taylor_mean_remainder_lagrange_iteratedDeriv + (n := 2) hxd hf.contDiffOn + have hu := uniqueDiffOn_uIcc hxd + have hx : x ∈ Set.uIcc x (x+d) := left_mem_uIcc + have h1 : iteratedDerivWithin 1 f (Set.uIcc x (x+d)) x = deriv f x := by + rw [iteratedDerivWithin_eq_iteratedDeriv hu (hf.of_le (by norm_num)).contDiffAt hx, + iteratedDeriv_one] + have h2 : iteratedDerivWithin 2 f (Set.uIcc x (x+d)) x = deriv (deriv f) x := by + rw [iteratedDerivWithin_eq_iteratedDeriv hu (hf.of_le (by norm_num)).contDiffAt hx, + iteratedDeriv_succ, iteratedDeriv_one] + simp only [taylorWithinEval_succ, taylor_within_zero_eval, h1, h2] at he + norm_num at he + have he' : f (x+d) - f x - deriv f x*d - (1/2:ℝ)*deriv (deriv f) x*d^2 = + iteratedDeriv 3 f y * d^3 / 6 := by + calc + _ = f (x+d) - (f x + d * deriv f x + (1/2:ℝ)*d^2*deriv (deriv f) x) := by ring + _ = _ := by convert he using 1 + rw [he', abs_div, abs_mul, abs_pow] + norm_num + have := mul_le_mul_of_nonneg_right (hC y) (pow_nonneg (abs_nonneg d) 3) + nlinarith + +end ZeroTemperatureSK.WeakIto + +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKSupport/Foundations/BoundedSmooth.lean b/lean/OAI/Probability/SKSupport/Foundations/BoundedSmooth.lean new file mode 100644 index 0000000000000000000000000000000000000000..7013da65b89dd2e1df94934b013adc69f2a9fbca --- /dev/null +++ b/lean/OAI/Probability/SKSupport/Foundations/BoundedSmooth.lean @@ -0,0 +1,134 @@ +import Mathlib +import OAI.Probability.SKSupport.Foundations.ExpTranslateLocalBound + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology ContDiff +noncomputable section +namespace ZeroTemperatureSK.Heat + +structure BoundedSmooth (g : ℝ → ℝ) : Prop where + smooth : ContDiff ℝ ∞ g + bounds : ∀ n : ℕ, ∃ C : ℝ≥0, ∀ x, |iteratedDeriv n g x| ≤ C + +lemma BoundedSmooth.bound {g : ℝ → ℝ} (hg : BoundedSmooth g) : + ∃ C : ℝ≥0, ∀ x, |g x| ≤ C := by simpa using hg.bounds 0 + +lemma BoundedSmooth.deriv {g : ℝ → ℝ} (hg : BoundedSmooth g) : BoundedSmooth (deriv g) := by + constructor + · exact contDiff_infty_iff_deriv.mp hg.smooth |>.2 + · intro n + simpa only [iteratedDeriv_succ'] using hg.bounds (n+1) + +lemma BoundedSmooth.const (c : ℝ) : BoundedSmooth (fun _ : ℝ => c) := by + constructor + · exact contDiff_const + · intro n + refine ⟨Real.nnabs c, fun x => ?_⟩ + cases n <;> simp [iteratedDeriv_const, Real.coe_nnabs] + +lemma BoundedSmooth.add {f g : ℝ → ℝ} (hf : BoundedSmooth f) (hg : BoundedSmooth g) : + BoundedSmooth (fun x => f x+g x) := by + constructor + · exact hf.smooth.add hg.smooth + · intro n + obtain ⟨A,hA⟩ := hf.bounds n + obtain ⟨B,hB⟩ := hg.bounds n + refine ⟨A+B, fun x => ?_⟩ + rw [iteratedDeriv_fun_add (n := n) (hf.smooth.of_le (ENat.natCast_le_of_coe_top_le_withTop le_rfl n) |>.contDiffAt) + (hg.smooth.of_le (ENat.natCast_le_of_coe_top_le_withTop le_rfl n) |>.contDiffAt)] + exact (abs_add_le _ _).trans (add_le_add (hA x) (hB x)) + +lemma BoundedSmooth.mul {f g : ℝ → ℝ} (hf : BoundedSmooth f) (hg : BoundedSmooth g) : + BoundedSmooth (fun x => f x*g x) := by + classical + constructor + · exact hf.smooth.mul hg.smooth + · intro n + choose A hA using hf.bounds + choose B hB using hg.bounds + refine ⟨∑ i ∈ Finset.range (n+1), (n.choose i:ℝ≥0)*A i*B (n-i), fun x => ?_⟩ + rw [iteratedDeriv_fun_mul (n := n) (hf.smooth.of_le (ENat.natCast_le_of_coe_top_le_withTop le_rfl n) |>.contDiffAt) + (hg.smooth.of_le (ENat.natCast_le_of_coe_top_le_withTop le_rfl n) |>.contDiffAt)] + push_cast + apply (Finset.abs_sum_le_sum_abs _ _).trans + apply Finset.sum_le_sum + intro i hi + simp only [abs_mul, abs_of_nonneg (show (0:ℝ) ≤ (n.choose i:ℝ) from Nat.cast_nonneg _)] + gcongr + · exact hA i x + · exact hB (n-i) x + +lemma BoundedSmooth.const_mul {g : ℝ → ℝ} (hg : BoundedSmooth g) (c : ℝ) : + BoundedSmooth (fun x => c*g x) := (BoundedSmooth.const c).mul hg + +structure RegularDatum (f : ℝ → ℝ) : Prop where + smooth : ContDiff ℝ ∞ f + deriv_bounded : BoundedSmooth (deriv f) + +lemma weighted_derivative_boundedSmooth {f g : ℝ → ℝ} + (hf : RegularDatum f) (hg : BoundedSmooth g) (c : ℝ) : + BoundedSmooth (fun x => deriv g x+c*g x*deriv f x) := + hg.deriv.add ((hg.const_mul c).mul hf.deriv_bounded) + +lemma weighted_derivative_formula {f g : ℝ → ℝ} {K : ℝ≥0} + (hf : RegularDatum f) (hLip : LipschitzWith K f) (hg : BoundedSmooth g) + {c : ℝ} (hc : 0 ≤ c) (h : ℝ≥0) : + deriv (semigroup h (fun z => g z*Real.exp (c*f z))) = + semigroup h (fun z => (deriv g z+c*g z*deriv f z)*Real.exp (c*f z)) := by + obtain ⟨G,hG⟩ := hg.bound + obtain ⟨G₁,hG₁⟩ := hg.deriv.bound + funext x + exact (hasDerivAt_semigroup_weight_exp (hf.smooth.of_le (by simp)) hLip + (hg.smooth.of_le (by simp)) hG hG₁ hc h x).deriv + +lemma contDiff_nat_semigroup_weight_exp {f : ℝ → ℝ} {K : ℝ≥0} + (hf : RegularDatum f) (hLip : LipschitzWith K f) {c : ℝ} (hc : 0 ≤ c) + (h : ℝ≥0) (n : ℕ) : ∀ g : ℝ → ℝ, BoundedSmooth g → + ContDiff ℝ n (semigroup h (fun z => g z*Real.exp (c*f z))) := by + induction n with + | zero => + intro g hg + rw [Nat.cast_zero, contDiff_zero] + apply Differentiable.continuous (𝕜 := ℝ) + intro x + obtain ⟨G,hG⟩ := hg.bound + obtain ⟨G₁,hG₁⟩ := hg.deriv.bound + exact (hasDerivAt_semigroup_weight_exp (hf.smooth.of_le (by simp)) hLip + (hg.smooth.of_le (by simp)) hG hG₁ hc h x).differentiableAt + | succ n IH => + intro g hg + rw [Nat.cast_add, Nat.cast_one, contDiff_succ_iff_deriv] + refine ⟨?_, by simp, ?_⟩ + · intro x + obtain ⟨G,hG⟩ := hg.bound + obtain ⟨G₁,hG₁⟩ := hg.deriv.bound + exact (hasDerivAt_semigroup_weight_exp (hf.smooth.of_le (by simp)) hLip + (hg.smooth.of_le (by simp)) hG hG₁ hc h x).differentiableAt + · rw [weighted_derivative_formula hf hLip hg hc h] + exact IH _ (weighted_derivative_boundedSmooth hf hg c) + +lemma contDiff_semigroup_weight_exp {f g : ℝ → ℝ} {K : ℝ≥0} + (hf : RegularDatum f) (hLip : LipschitzWith K f) (hg : BoundedSmooth g) + {c : ℝ} (hc : 0 ≤ c) (h : ℝ≥0) : + ContDiff ℝ ∞ (semigroup h (fun z => g z*Real.exp (c*f z))) := by + apply contDiff_iff_forall_nat_le.mpr + intro n hn + exact contDiff_nat_semigroup_weight_exp hf hLip hc h n g hg + +end ZeroTemperatureSK.Heat + +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKSupport/Foundations/Cascade.lean b/lean/OAI/Probability/SKSupport/Foundations/Cascade.lean new file mode 100644 index 0000000000000000000000000000000000000000..1d522d55a2be4fb81e4c107708f868878659594e --- /dev/null +++ b/lean/OAI/Probability/SKSupport/Foundations/Cascade.lean @@ -0,0 +1,194 @@ +import Mathlib +import OAI.Probability.SKSupport.Backward.Backward +import OAI.Probability.SKSupport.Foundations.SoftAbs + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology ContDiff +noncomputable section +namespace ZeroTemperatureSK.Heat + +def cascade (c : ℕ → ℝ≥0) (h : ℝ≥0) (f : ℝ → ℝ) : ℕ → ℕ → ℝ → ℝ + | 0, _, x => f x + | n+1, k, x => logSemigroup (c k) h (cascade c h f n (k+1)) x + +lemma cascade_lipschitz {f : ℝ → ℝ} {K : ℝ≥0} (hf : LipschitzWith K f) + (c : ℕ → ℝ≥0) (h : ℝ≥0) (n k : ℕ) : LipschitzWith K (cascade c h f n k) := by + induction n generalizing k with + | zero => exact hf + | succ n IH => exact logSemigroup_lipschitz (IH (k+1)) (c k).coe_nonneg h + +lemma cascade_regular {f : ℝ → ℝ} (hf : RegularDatum f) (hLip : LipschitzWith 1 f) + (c : ℕ → ℝ≥0) (h : ℝ≥0) (n k : ℕ) : RegularDatum (cascade c h f n k) := by + induction n generalizing k with + | zero => exact hf + | succ n IH => + exact regularDatum_logSemigroup (IH (k+1)) (cascade_lipschitz hLip c h n (k+1)) (c k).coe_nonneg h + +lemma cascade_terminal_stability {f g : ℝ → ℝ} {K J : ℝ≥0} + (hf : LipschitzWith K f) (hg : LipschitzWith J g) {δ : ℝ} + (hδ : ∀ z, |f z-g z| ≤ δ) (c : ℕ → ℝ≥0) (h : ℝ≥0) (n k : ℕ) (x : ℝ) : + |cascade c h f n k x-cascade c h g n k x| ≤ δ := by + induction n generalizing k x with + | zero => exact hδ x + | succ n IH => + exact logSemigroup_terminal_stability (cascade_lipschitz hf c h n (k+1)) + (cascade_lipschitz hg c h n (k+1)) (c k).coe_nonneg (IH (k+1)) h x + +end ZeroTemperatureSK.Heat + +namespace ZeroTemperatureSK.Heat + +def cascadeAt (c : ℕ → ℝ≥0) (h : ℝ≥0) (f : ℝ → ℝ) (N k : ℕ) : ℝ → ℝ := + cascade c h f (N-k) k + +def cellHeat (c : ℕ → ℝ≥0) (h : ℝ≥0) (f : ℝ → ℝ) (N k : ℕ) : ℝ → ℝ → ℝ := + backward (c k) ((min (k+1) N:ℕ)*h) (cascadeAt c h f N (k+1)) + +def cellRate (c : ℕ → ℝ≥0) (h : ℝ≥0) (f : ℝ → ℝ) (N k : ℕ) : ℝ → ℝ → ℝ := + backwardRate (c k) ((min (k+1) N:ℕ)*h) (cascadeAt c h f N (k+1)) + +lemma cellHeat_verificationData {f : ℝ → ℝ} (hf : RegularDatum f) + (hLip : LipschitzWith 1 f) (c : ℕ → ℝ≥0) (h : ℝ≥0) (N k : ℕ) : + VerificationData (cellHeat c h f N k) (cellRate c h f N k) + (c k) ((min (k+1) N:ℕ)*h) := + backward_verificationData (cascade_regular hf hLip c h _ _) + (cascade_lipschitz hLip c h _ _) (c k).coe_nonneg _ + +lemma cellHeat_left {f : ℝ → ℝ} (hf : RegularDatum f) (hLip : LipschitzWith 1 f) + (c : ℕ → ℝ≥0) (h : ℝ≥0) (N k : ℕ) (hk : k ≤ N) : + cellHeat c h f N k ((k:ℝ)*(h:ℝ)) = cascadeAt c h f N k := by + by_cases he : k = N + · subst k + funext x + simpa [cellHeat, cascadeAt, cascade, Nat.min_eq_right (Nat.le_succ N)] using + backward_terminal (c N) ((N:ℝ)*(h:ℝ)) f x + · have hk' : k < N := lt_of_le_of_ne hk he + have hN : N-k = (N-(k+1))+1 := by omega + funext x + unfold cellHeat cascadeAt backward + rw [Nat.min_eq_left (by omega : k+1 ≤ N)] + have ht : ((k+1:ℕ):ℝ)*(h:ℝ)-(k:ℝ)*(h:ℝ) = (h:ℝ) := by push_cast; ring + rw [ht, hN, cascade] + exact varianceLogHeat_eq_logSemigroup + (cascade_regular hf hLip c h _ _).smooth.continuous.measurable (c k) h x + +lemma cellHeat_right (c : ℕ → ℝ≥0) (h : ℝ≥0) (f : ℝ → ℝ) (N k : ℕ) (hk : k < N) : + cellHeat c h f N k (((k+1:ℕ):ℝ)*(h:ℝ)) = cascadeAt c h f N (k+1) := by + funext x + dsimp only [cellHeat] + rw [Nat.min_eq_left (by omega : k+1 ≤ N)] + exact backward_terminal _ _ _ _ + +lemma cellHeat_seam {f : ℝ → ℝ} (hf : RegularDatum f) (hLip : LipschitzWith 1 f) + (c : ℕ → ℝ≥0) (h : ℝ≥0) (N k : ℕ) (hk : k < N) : + cellHeat c h f N k (((k+1:ℕ):ℝ)*(h:ℝ)) = + cellHeat c h f N (k+1) (((k+1:ℕ):ℝ)*(h:ℝ)) := by + rw [cellHeat_right c h f N k hk, cellHeat_left hf hLip c h N (k+1) (by omega)] + +end ZeroTemperatureSK.Heat + +namespace ZeroTemperatureSK.Heat + +lemma hasFDerivAt_scaled_joint {g : ℝ → ℝ} (hgc : ContDiff ℝ 1 g) + (hg : ExponentialBound g) (hg' : ExponentialBound (deriv g)) (p : ℝ × ℝ) : + HasFDerivAt (fun q : ℝ × ℝ => scaled q.2 g q.1) + (scaled p.2 (deriv g) p.1 • ContinuousLinearMap.fst ℝ ℝ ℝ + + (∫ y, y*deriv g (p.1+p.2*y) ∂gaussianReal 0 1) • ContinuousLinearMap.snd ℝ ℝ ℝ) p := by + obtain ⟨A,K,hA⟩ := hg' + let L : ℝ → (ℝ × ℝ) →L[ℝ] ℝ := fun y => + ContinuousLinearMap.fst ℝ ℝ ℝ+y • ContinuousLinearMap.snd ℝ ℝ ℝ + let D : (ℝ × ℝ) → ℝ → (ℝ × ℝ) →L[ℝ] ℝ := fun q y => deriv g (q.1+q.2*y) • L y + let R : ℝ := (A:ℝ)*Real.exp ((K:ℝ)*(|p.1|+1)) + let k : ℝ := (K:ℝ)*(|p.2|+1) + have hgi : Integrable (fun y => deriv g (p.1+p.2*y)) (gaussianReal 0 1) := + integrable_scaled_of_expBound hgc.continuous_deriv_one.measurable ⟨A,K,hA⟩ _ _ + have hygi : Integrable (fun y => y*deriv g (p.1+p.2*y)) (gaussianReal 0 1) := + integrable_mul_scaled_of_expBound hgc.continuous_deriv_one.measurable ⟨A,K,hA⟩ _ _ + have hDi : Integrable (D p) (gaussianReal 0 1) := by + have hv := (hgi.smul_const (ContinuousLinearMap.fst ℝ ℝ ℝ)).add + (hygi.smul_const (ContinuousLinearMap.snd ℝ ℝ ℝ)) + apply hv.congr + filter_upwards [] with y + simp only [D,L,smul_add,smul_smul,Pi.add_apply] + congr 2; ring + have hd := hasFDerivAt_integral_of_dominated_of_fderiv_le + (F := fun q : ℝ × ℝ => fun y : ℝ => g (q.1+q.2*y)) (F' := D) + (bound := fun y : ℝ => R*(1+|y|)*Real.exp (k*|y|)) + (Metric.ball_mem_nhds p (show (0:ℝ)<1 by norm_num)) + (Filter.Eventually.of_forall (fun q => by fun_prop)) + (integrable_scaled_of_expBound hgc.continuous.measurable hg p.2 p.1) + hDi.aestronglyMeasurable + (by + filter_upwards [] with y q hq + have hx : |q.1| ≤ |p.1|+1 := by + have hdq := (max_lt_iff.mp (show max (dist q.1 p.1) (dist q.2 p.2) < 1 from hq)).1 + rw [Real.dist_eq] at hdq + have ht := abs_add_le (q.1-p.1) p.1 + rw [sub_add_cancel] at ht + linarith + have ha : |q.2| ≤ |p.2|+1 := by + have hdq := (max_lt_iff.mp (show max (dist q.1 p.1) (dist q.2 p.2) < 1 from hq)).2 + rw [Real.dist_eq] at hdq + have ht := abs_add_le (q.2-p.2) p.2 + rw [sub_add_cancel] at ht + linarith + have hL : ‖L y‖ ≤ 1+|y| := by + apply (norm_add_le _ _).trans + simp only [norm_smul, Real.norm_eq_abs] + have hf : ‖ContinuousLinearMap.fst ℝ ℝ ℝ‖ ≤ 1 := ContinuousLinearMap.norm_fst_le ℝ ℝ ℝ + have hs : ‖ContinuousLinearMap.snd ℝ ℝ ℝ‖ ≤ 1 := ContinuousLinearMap.norm_snd_le ℝ ℝ ℝ + nlinarith [mul_le_mul_of_nonneg_left hs (abs_nonneg y)] + dsimp only [D] + rw [norm_smul, Real.norm_eq_abs] + have hb : |deriv g (q.1+q.2*y)| ≤ R*Real.exp (k*|y|) := by + apply (exponentialBound_scaled hA q.1 q.2 y (|p.2|+1) ha).trans + dsimp only [R,k] + gcongr + calc + _ ≤ (R*Real.exp (k*|y|))*(1+|y|) := mul_le_mul hb hL (norm_nonneg _) (by positivity) + _ = _ := by ring) + (by + have hi := ((integrable_exp_abs k 0 1).add (integrable_abs_mul_exp_abs k)).const_mul R + convert hi using 1 + funext y; dsimp only [Pi.add_apply]; ring) + (by + filter_upwards [] with y q hq + have hl : HasFDerivAt (fun q : ℝ × ℝ => q.1+q.2*y) (L y) q := by + convert ((hasFDerivAt_fst (𝕜 := ℝ) (p := q)).add + ((hasFDerivAt_snd (𝕜 := ℝ) (p := q)).mul_const y)) using 1 + convert (hgc.differentiable (by norm_num) (q.1+q.2*y)).hasDerivAt.comp_hasFDerivAt q hl using 1 + rfl + ) + have heq : (∫ y, D p y ∂gaussianReal 0 1) = + scaled p.2 (deriv g) p.1 • ContinuousLinearMap.fst ℝ ℝ ℝ + + (∫ y, y*deriv g (p.1+p.2*y) ∂gaussianReal 0 1) • ContinuousLinearMap.snd ℝ ℝ ℝ := by + apply ContinuousLinearMap.ext + intro z + rw [ContinuousLinearMap.integral_apply hDi] + dsimp only [D,L] + simp only [smul_apply, add_apply, + ContinuousLinearMap.coe_fst', ContinuousLinearMap.coe_snd', smul_eq_mul] + have he : (fun y => deriv g (p.1+p.2*y)*(z.1+y*z.2)) = + fun y => deriv g (p.1+p.2*y)*z.1+(y*deriv g (p.1+p.2*y))*z.2 := by funext y; ring + rw [he, integral_add (hgi.mul_const _) (hygi.mul_const _), integral_mul_const, integral_mul_const] + rfl + rw [heq] at hd + exact hd + +end ZeroTemperatureSK.Heat + +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKSupport/Foundations/Const.lean b/lean/OAI/Probability/SKSupport/Foundations/Const.lean new file mode 100644 index 0000000000000000000000000000000000000000..35c6015e70a1fc56443e050a5fb162817194aa0a --- /dev/null +++ b/lean/OAI/Probability/SKSupport/Foundations/Const.lean @@ -0,0 +1,254 @@ +import Mathlib +import OAI.Probability.SKSupport.Parabolic.TiltedMean + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology ContDiff +noncomputable section +namespace ZeroTemperatureSK.Heat + +lemma RegularDatum.const (a : ℝ) : RegularDatum (fun _ : ℝ => a) := by + refine ⟨contDiff_const, ?_⟩ + simpa only [deriv_const'] using BoundedSmooth.const 0 + +lemma boundedSmooth_semigroup {g : ℝ → ℝ} (hg : BoundedSmooth g) (h : ℝ≥0) : + BoundedSmooth (semigroup h g) := by + have hm := boundedSmooth_tiltedMean (RegularDatum.const 0) + (LipschitzWith.const (0:ℝ)) hg (c := 0) le_rfl h + have he : tiltedMean 0 h (fun _ => 0) g = semigroup h g := by + funext x; simp [tiltedMean, semigroup] + rw [he] at hm + exact hm + +lemma regularDatum_semigroup {f : ℝ → ℝ} {K : ℝ≥0} + (hf : RegularDatum f) (hLip : LipschitzWith K f) (h : ℝ≥0) : + RegularDatum (semigroup h f) := by + have he : deriv (semigroup h f) = semigroup h (deriv f) := funext (fun x => + (hasDerivAt_semigroup (hf.smooth.of_le (by simp)) hLip h x).deriv) + have hd := boundedSmooth_semigroup hf.deriv_bounded h + constructor + · apply contDiff_infty_iff_deriv.mpr + constructor + · exact fun x => (hasDerivAt_semigroup (hf.smooth.of_le (by simp)) hLip h x).differentiableAt + · rw [he]; exact hd.smooth + · rw [he]; exact hd + +lemma regularDatum_logSemigroup {f : ℝ → ℝ} {K : ℝ≥0} + (hf : RegularDatum f) (hLip : LipschitzWith K f) {c : ℝ} (hc : 0 ≤ c) + (h : ℝ≥0) : RegularDatum (logSemigroup c h f) := by + by_cases hc0 : c = 0 + · subst c + have he : logSemigroup 0 h f = semigroup h f := by funext x; simp [logSemigroup] + rw [he]; exact regularDatum_semigroup hf hLip h + have hder : deriv (logSemigroup c h f) = tiltedMean c h f (deriv f) := by + funext x + exact (hasDerivAt_logSemigroup (hf.smooth.of_le (by simp)) hLip (lt_of_le_of_ne hc (Ne.symm hc0)) h x).deriv + have hd := boundedSmooth_tiltedMean hf hLip hf.deriv_bounded hc h + constructor + · apply contDiff_infty_iff_deriv.mpr + constructor + · intro x + exact (hasDerivAt_logSemigroup (hf.smooth.of_le (by simp)) hLip (lt_of_le_of_ne hc (Ne.symm hc0)) h x).differentiableAt + · rw [hder]; exact hd.smooth + · rw [hder]; exact hd + +end ZeroTemperatureSK.Heat + +namespace ZeroTemperatureSK.Heat + +lemma integrable_mul_standardGaussianPDF {g : ℝ → ℝ} + (hg : Integrable g (gaussianReal 0 1)) : + Integrable (fun y => gaussianPDFReal 0 1 y*g y) := by + rw [gaussianReal_of_var_ne_zero 0 one_ne_zero] at hg + have hh := (integrable_withDensity_iff_integrable_smul' + (measurable_gaussianPDF 0 1) (Filter.Eventually.of_forall + (fun y => (gaussianPDF_lt_top (μ := 0) (v := 1) (x := y))))).mp hg + simpa only [gaussianPDF, ENNReal.toReal_ofReal (gaussianPDFReal_nonneg _ _ _), + smul_eq_mul] using hh + +lemma hasDerivAt_standardGaussianPDF (x : ℝ) : + HasDerivAt (gaussianPDFReal 0 1) (-x*gaussianPDFReal 0 1 x) x := by + have he : gaussianPDFReal 0 1 = fun y : ℝ => + (Real.sqrt (2*Real.pi))⁻¹*Real.exp (-y^2/2) := by + funext y + simp only [gaussianPDFReal, NNReal.coe_one, mul_one, sub_zero] + rw [he] + have hd := (((((hasDerivAt_id x).pow 2).neg.div_const (2:ℝ)).exp).const_mul + ((Real.sqrt (2*Real.pi))⁻¹)) + apply hd.congr_deriv + simp only [id_eq, Pi.pow_apply, Pi.neg_apply, Nat.cast_ofNat, Nat.reduceSub, pow_one] + ring + +lemma standardGaussian_stein {g g' : ℝ → ℝ} (hd : ∀ x, HasDerivAt g (g' x) x) + (hg : Integrable g (gaussianReal 0 1)) (hg' : Integrable g' (gaussianReal 0 1)) + (hyg : Integrable (fun y => y*g y) (gaussianReal 0 1)) : + (∫ y, y*g y ∂gaussianReal 0 1) = ∫ y, g' y ∂gaussianReal 0 1 := by + have hv := integrable_mul_standardGaussianPDF hg + have hv' := integrable_mul_standardGaussianPDF hg' + have hyv := integrable_mul_standardGaussianPDF hyg + have ha : Integrable (fun y => g y*(-y*gaussianPDFReal 0 1 y)) := by + convert hyv.neg using 1 + funext y; simp only [Pi.neg_apply]; ring + have hb : Integrable (fun y => g' y*gaussianPDFReal 0 1 y) := by + simpa only [mul_comm] using hv' + have hc : Integrable (fun y => g y*gaussianPDFReal 0 1 y) := by + simpa only [mul_comm] using hv + have hi := integral_mul_deriv_eq_deriv_mul_of_integrable + (u := g) (u' := g') (v := gaussianPDFReal 0 1) + (v' := fun y => -y*gaussianPDFReal 0 1 y) + (fun y _ => hd y) (fun y _ => hasDerivAt_standardGaussianPDF y) ha hb hc + rw [integral_gaussianReal_eq_integral_smul one_ne_zero, + integral_gaussianReal_eq_integral_smul one_ne_zero] + simp only [smul_eq_mul] + have he : (fun y => g y*(-y*gaussianPDFReal 0 1 y)) = + fun y => -(gaussianPDFReal 0 1 y*(y*g y)) := by funext y; ring + rw [he, integral_neg] at hi + have hh := neg_injective hi + simpa only [mul_comm] using hh + +end ZeroTemperatureSK.Heat + +namespace ZeroTemperatureSK.Heat + +def ExponentialBound (g : ℝ → ℝ) : Prop := + ∃ A K : ℝ≥0, ∀ z, |g z| ≤ (A:ℝ)*Real.exp ((K:ℝ)*|z|) + +lemma ExponentialBound.of_bounded {g : ℝ → ℝ} {A : ℝ≥0} (hA : ∀ z, |g z| ≤ A) : + ExponentialBound g := by + exact ⟨A, 0, fun z => by simpa using hA z⟩ + +lemma integrable_abs_mul_exp_abs (K : ℝ) : + Integrable (fun y : ℝ => |y| *Real.exp (K*|y|)) (gaussianReal 0 1) := by + apply Integrable.mono' (integrable_exp_abs (K+1) 0 1) (by fun_prop) + filter_upwards [] with y + rw [Real.norm_eq_abs, abs_of_nonneg (by positivity)] + calc + |y| *Real.exp (K*|y|) ≤ Real.exp |y| *Real.exp (K*|y|) := by + gcongr + linarith [Real.add_one_le_exp |y|] + _ = Real.exp ((K+1)*|y|) := by rw [← Real.exp_add]; congr 1; ring + +lemma exponentialBound_scaled {g : ℝ → ℝ} {A K : ℝ≥0} + (hg : ∀ z, |g z| ≤ (A:ℝ)*Real.exp ((K:ℝ)*|z|)) + (x a y R : ℝ) (ha : |a| ≤ R) : + |g (x+a*y)| ≤ (A:ℝ)*Real.exp ((K:ℝ)*|x|)*Real.exp (((K:ℝ)*R)*|y|) := by + calc + _ ≤ (A:ℝ)*Real.exp ((K:ℝ)*|x+a*y|) := hg _ + _ ≤ (A:ℝ)*Real.exp ((K:ℝ)*(|x|+R*|y|)) := by + gcongr + exact (abs_add_le _ _).trans (by rw [abs_mul]; gcongr) + _ = _ := by rw [mul_assoc, ← Real.exp_add]; congr 2; ring + +lemma integrable_scaled_of_expBound {g : ℝ → ℝ} (hgm : Measurable g) + (hg : ExponentialBound g) (a x : ℝ) : + Integrable (fun y => g (x+a*y)) (gaussianReal 0 1) := by + obtain ⟨A,K,hg⟩ := hg + apply Integrable.mono' ((integrable_exp_abs ((K:ℝ)*|a|) 0 1).const_mul + ((A:ℝ)*Real.exp ((K:ℝ)*|x|))) + ((hgm.comp (measurable_const.add (measurable_const.mul measurable_id))).aestronglyMeasurable) + filter_upwards [] with y + change ‖g (x+a*y)‖ ≤ _ + simpa only [Real.norm_eq_abs] using exponentialBound_scaled hg x a y |a| le_rfl + +lemma integrable_mul_scaled_of_expBound {g : ℝ → ℝ} (hgm : Measurable g) + (hg : ExponentialBound g) (a x : ℝ) : + Integrable (fun y => y*g (x+a*y)) (gaussianReal 0 1) := by + obtain ⟨A,K,hg⟩ := hg + apply Integrable.mono' ((integrable_abs_mul_exp_abs ((K:ℝ)*|a|)).const_mul + ((A:ℝ)*Real.exp ((K:ℝ)*|x|))) + ((measurable_id.mul (hgm.comp (measurable_const.add (measurable_const.mul measurable_id)))).aestronglyMeasurable) + filter_upwards [] with y + change ‖y*g (x+a*y)‖ ≤ _ + rw [Real.norm_eq_abs, abs_mul] + calc + _ ≤ |y| *((A:ℝ)*Real.exp ((K:ℝ)*|x|)*Real.exp (((K:ℝ)*|a|)*|y|)) := by + gcongr + exact exponentialBound_scaled hg x a y |a| le_rfl + _ = _ := by ring + +def scaled (a : ℝ) (g : ℝ → ℝ) (x : ℝ) : ℝ := + ∫ y, g (x+a*y) ∂gaussianReal 0 1 + +lemma semigroup_eq_scaled {g : ℝ → ℝ} (hgm : Measurable g) (h : ℝ≥0) (x : ℝ) : + semigroup h g x = scaled (Real.sqrt (h:ℝ)) g x := by + have hs : (gaussianReal 0 1).map (fun y : ℝ => Real.sqrt (h:ℝ)*y) = gaussianReal 0 h := by + rw [gaussianReal_map_const_mul] + congr 1 + · simp + · ext; simp [Real.sq_sqrt h.coe_nonneg] + unfold semigroup scaled + rw [← hs] + exact integral_map (by fun_prop) + (show AEStronglyMeasurable (fun y => g (x+y)) _ from + (hgm.comp (measurable_const.add measurable_id)).aestronglyMeasurable) + +lemma continuous_scaled {g : ℝ → ℝ} (hgc : Continuous g) (hg : ExponentialBound g) + (x : ℝ) : Continuous (fun a => scaled a g x) := by + obtain ⟨A,K,hg⟩ := hg + apply continuous_iff_continuousAt.mpr + intro a + apply continuousAt_of_dominated + (bound := fun y => (A:ℝ)*Real.exp ((K:ℝ)*|x|)*Real.exp (((K:ℝ)*(|a|+1))*|y|)) + · exact Filter.Eventually.of_forall (fun z => (by fun_prop)) + · filter_upwards [Metric.ball_mem_nhds a (show (0:ℝ)<1 by norm_num)] with z hz + filter_upwards [] with y + have hz' : |z| ≤ |a|+1 := by + have ht := abs_add_le (z-a) a + rw [sub_add_cancel] at ht + have hd : |z-a| < 1 := by simpa only [Metric.mem_ball, Real.dist_eq] using hz + linarith + simpa only [Real.norm_eq_abs] using exponentialBound_scaled hg x z y (|a|+1) hz' + · exact (integrable_exp_abs ((K:ℝ)*(|a|+1)) 0 1).const_mul _ + · filter_upwards [] with y + exact hgc.continuousAt.comp (by fun_prop) + +lemma hasDerivAt_scaled {g : ℝ → ℝ} (hgc : ContDiff ℝ 1 g) + (hg : ExponentialBound g) (hg' : ExponentialBound (deriv g)) (a x : ℝ) : + HasDerivAt (fun z => scaled z g x) + (∫ y, y*deriv g (x+a*y) ∂gaussianReal 0 1) a := by + obtain ⟨A,K,hg'⟩ := hg' + have hdm := hgc.continuous_deriv_one.measurable + have hm : ∀ᶠ z in 𝓝 a, AEStronglyMeasurable (fun y => g (x+z*y)) (gaussianReal 0 1) := + Filter.Eventually.of_forall (fun z => by fun_prop) + have hdmeas : AEStronglyMeasurable (fun y => y*deriv g (x+a*y)) (gaussianReal 0 1) := by fun_prop + have hb : ∀ᵐ y ∂gaussianReal 0 1, ∀ z ∈ Metric.ball a 1, + ‖y*deriv g (x+z*y)‖ ≤ + ((A:ℝ)*Real.exp ((K:ℝ)*|x|))*(|y| *Real.exp (((K:ℝ)*(|a|+1))*|y|)) := by + filter_upwards [] with y z hz + have hz' : |z| ≤ |a|+1 := by + have ht := abs_add_le (z-a) a + rw [sub_add_cancel] at ht + have hd : |z-a| < 1 := by simpa only [Metric.mem_ball, Real.dist_eq] using hz + linarith + rw [Real.norm_eq_abs, abs_mul] + calc + _ ≤ |y| *((A:ℝ)*Real.exp ((K:ℝ)*|x|)*Real.exp (((K:ℝ)*(|a|+1))*|y|)) := by + gcongr + exact exponentialBound_scaled hg' x z y (|a|+1) hz' + _ = _ := by ring + have hD : ∀ᵐ y ∂gaussianReal 0 1, ∀ z ∈ Metric.ball a 1, + HasDerivAt (fun w => g (x+w*y)) (y*deriv g (x+z*y)) z := by + filter_upwards [] with y z hz + convert (hgc.differentiable (by norm_num) (x+z*y)).hasDerivAt.comp z + (((hasDerivAt_id z).mul_const y).const_add x) using 1 <;> first | rfl | simp [mul_comm] + exact (hasDerivAt_integral_of_dominated_loc_of_deriv_le + (Metric.ball_mem_nhds a (show (0:ℝ)<1 by norm_num)) hm + (integrable_scaled_of_expBound hgc.continuous.measurable hg a x) hdmeas hb + ((integrable_abs_mul_exp_abs ((K:ℝ)*(|a|+1))).const_mul _) hD).2 + +end ZeroTemperatureSK.Heat + +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKSupport/Foundations/Control.lean b/lean/OAI/Probability/SKSupport/Foundations/Control.lean new file mode 100644 index 0000000000000000000000000000000000000000..2afe40400ba7ad50bae4b9ab98e3d56d11085e4f --- /dev/null +++ b/lean/OAI/Probability/SKSupport/Foundations/Control.lean @@ -0,0 +1,83 @@ +import Mathlib +import OAI.Probability.SKSupport.Model + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology + +noncomputable section + +namespace ZeroTemperatureSK + +variable {Ω : Type*} [MeasurableSpace Ω] + +def zeroControl (W : BrownianSystem Ω) (t : ℝ≥0) : Control W t where + val := fun _ _ => 0 + progressive := isProgressive_const _ _ + bound := by simp + +end ZeroTemperatureSK + +namespace ZeroTemperatureSK + +@[simp] theorem extend_coe (γ : Time → ℝ) (t : Time) : extend γ t = γ t := by + simp [extend, t.property] + +lemma OrderParameter.extend_nonneg (γ : OrderParameter) (t : ℝ) : 0 ≤ extend γ.val t := by + unfold extend + split + · exact γ.nonneg _ + · rfl + +lemma OrderParameter.measurable_extend (γ : OrderParameter) : Measurable (extend γ.val) := by + exact γ.monotone.measurable.dite measurable_const measurableSet_Ico + +variable {Ω : Type*} [MeasurableSpace Ω] + +lemma Control.measurable {W : BrownianSystem Ω} {t : ℝ≥0} (α : Control W t) : + Measurable (fun p : ℝ≥0 × Ω => α.val p.1 p.2) := by + have hclip (n : ℕ) : Measurable (fun p : ℝ≥0 × Ω => α.val (min p.1 n) p.2) := by + have hs : Measurable[inferInstance, incrementFiltration W t (n : ℝ≥0)] + (fun p : ℝ≥0 × Ω => p.2) := + measurable_snd.mono le_rfl ((incrementFiltration W t).le n) + exact (α.progressive n).comp + (((measurable_fst.min measurable_const).subtype_mk + (h := fun p : ℝ≥0 × Ω => min_le_right p.1 (n : ℝ≥0))).prodMk hs) + apply measurable_of_tendsto_metrizable hclip + apply tendsto_pi_nhds.mpr + intro p + apply tendsto_const_nhds.congr' + filter_upwards [(tendsto_natCast_atTop_atTop (R := ℝ≥0)).eventually + (eventually_ge_atTop p.1)] with n hn + simp only [min_eq_left hn] + +lemma Control.measurable_elapsed {W : BrownianSystem Ω} {t : ℝ≥0} + (α : Control W t) (b : ℝ) : + Measurable (fun p : ℝ × Ω => α.val (Real.toNNReal (p.1 - b)) p.2) := by + exact α.measurable.comp + (((measurable_fst.sub measurable_const).real_toNNReal).prodMk measurable_snd) + +lemma Control.integrable_weighted {W : BrownianSystem Ω} {t : ℝ≥0} + (α : Control W t) (γ : OrderParameter) (b : ℝ) (ω : Ω) : + Integrable (fun s : ℝ => extend γ.val s * α.val (Real.toNNReal (s - b)) ω) := by + exact γ.integrable.mul_bdd + ((α.measurable_elapsed b).comp measurable_prodMk_right).aestronglyMeasurable + (Filter.Eventually.of_forall (fun s => by simpa only [Real.norm_eq_abs] using α.bound _ _)) + +lemma Control.integrable_weighted_sq {W : BrownianSystem Ω} {t : ℝ≥0} + (α : Control W t) (γ : OrderParameter) (b : ℝ) (ω : Ω) : + Integrable (fun s : ℝ => extend γ.val s * (α.val (Real.toNNReal (s - b)) ω)^2) := by + apply γ.integrable.mul_bdd + (((α.measurable_elapsed b).comp measurable_prodMk_right).pow_const 2).aestronglyMeasurable + exact Filter.Eventually.of_forall (fun s => by + simpa only [Real.norm_eq_abs, abs_pow, one_pow, Function.comp_apply] using + pow_le_pow_left₀ (abs_nonneg (α.val (Real.toNNReal (s - b)) ω)) (α.bound _ _) 2) + +end ZeroTemperatureSK + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKSupport/Foundations/ControlledState.lean b/lean/OAI/Probability/SKSupport/Foundations/ControlledState.lean new file mode 100644 index 0000000000000000000000000000000000000000..ce022f8ecac338b36fcaf8a7dad9dd1167d514db --- /dev/null +++ b/lean/OAI/Probability/SKSupport/Foundations/ControlledState.lean @@ -0,0 +1,195 @@ +import Mathlib +import OAI.Probability.SKSupport.Foundations.ExpectedVerificationStep +import OAI.Probability.SKSupport.Diffusion.ProgressiveIntegralMeasurable + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section +namespace ZeroTemperatureSK.WeakIto +variable {Ω : Type*} [mΩ : MeasurableSpace Ω] {P : Measure Ω} + +def controlledState (B : ℝ≥0 → Ω → ℝ) (α : ℝ≥0 → Ω → ℝ) + (c x : ℝ) (t : ℝ≥0) (ω : Ω) : ℝ := + x + B t ω - B 0 ω + stepDrift (fun r => α (Real.toNNReal r)) 0 t c ω + +omit mΩ in +lemma controlledState_zero (B : ℝ≥0 → Ω → ℝ) (α : ℝ≥0 → Ω → ℝ) + (c x : ℝ) (ω : Ω) : controlledState B α c x 0 ω = x := by + simp [controlledState, stepDrift] + +lemma controlledState_adapted {B : ℝ≥0 → Ω → ℝ} + (hm : ∀ t, Measurable (B t)) {α : ℝ≥0 → Ω → ℝ} + (hα : IsProgressive (Filtration.natural B (fun t => (hm t).stronglyMeasurable)) α) + (c x : ℝ) (t : ℝ≥0) : + Measurable[Filtration.natural B (fun t => (hm t).stronglyMeasurable) t] + (controlledState B α c x t) := by + have hBt := (Filtration.stronglyAdapted_natural (fun t => (hm t).stronglyMeasurable) t).measurable + have hB0 := (Filtration.stronglyAdapted_natural (fun t => (hm t).stronglyMeasurable) 0).measurable.mono + ((Filtration.natural B (fun t => (hm t).stronglyMeasurable)).mono (show (0:ℝ≥0) ≤ t from bot_le)) le_rfl + have hA := progressive_integral_measurable _ hα t (w := fun _ => c) measurable_const + have hx : Measurable[Filtration.natural B (fun t => (hm t).stronglyMeasurable) t] + (fun _ : Ω => x) := measurable_const + unfold controlledState stepDrift + simp only [zero_add] + exact ((hx.add hBt).sub hB0).add hA + +lemma controlledState_integrable {B : ℝ≥0 → Ω → ℝ} + (hB : IsPreBrownianReal B P) {α : ℝ≥0 → Ω → ℝ} + (hm : Measurable (fun p : ℝ≥0 × Ω => α p.1 p.2)) + (hb : ∀ r ω, |α r ω| ≤ 1) (c : ℝ≥0) (x : ℝ) (t : ℝ≥0) : + Integrable (controlledState B α c x t) P := by + let := hB.isGaussianProcess.isProbabilityMeasure + have hm' : Measurable (fun p : ℝ × Ω => α (Real.toNNReal p.1) p.2) := + hm.comp (measurable_fst.real_toNNReal.prodMk measurable_snd) + exact ((integrable_const x).add (hB.integrable_eval t) |>.sub (hB.integrable_eval 0)).add + (stepDrift_integrable hm' (fun r ω => hb _ ω) 0 t c t.coe_nonneg c.coe_nonneg) + +lemma stepDrift_add {α : ℝ → Ω → ℝ} + (hm : Measurable (fun p : ℝ × Ω => α p.1 p.2)) + (hb : ∀ r ω, |α r ω| ≤ 1) (c : ℝ) (s h : ℝ≥0) (ω : Ω) : + stepDrift α 0 (s+h) c ω = stepDrift α 0 s c ω + stepDrift α s h c ω := by + have h0 := (bounded_control_intervalIntegrable hm hb 0 s s.coe_nonneg ω).1.const_mul c + have hs := (bounded_control_intervalIntegrable hm hb s h h.coe_nonneg ω).1.const_mul c + simp only [zero_add] at h0 + simpa only [stepDrift, zero_add, NNReal.coe_add] using + (intervalIntegral.integral_add_adjacent_intervals h0 hs).symm + +lemma stepCost_add {α : ℝ → Ω → ℝ} + (hm : Measurable (fun p : ℝ × Ω => α p.1 p.2)) + (hb : ∀ r ω, |α r ω| ≤ 1) (c : ℝ) (s h : ℝ≥0) (ω : Ω) : + stepCost α 0 (s+h) c ω = stepCost α 0 s c ω + stepCost α s h c ω := by + have h0 := (bounded_control_intervalIntegrable hm hb 0 s s.coe_nonneg ω).2.const_mul c + have hs := (bounded_control_intervalIntegrable hm hb s h h.coe_nonneg ω).2.const_mul c + simp only [zero_add] at h0 + have he := intervalIntegral.integral_add_adjacent_intervals h0 hs + simp only [stepCost, zero_add] + rw [← he, mul_add] + +lemma controlledState_increment {B : ℝ≥0 → Ω → ℝ} {α : ℝ≥0 → Ω → ℝ} + (hm : Measurable (fun p : ℝ≥0 × Ω => α p.1 p.2)) + (hb : ∀ r ω, |α r ω| ≤ 1) (c x : ℝ) (s h : ℝ≥0) (ω : Ω) : + controlledState B α c x (s+h) ω = controlledState B α c x s ω + + (B (s+h) ω-B s ω) + stepDrift (fun r => α (Real.toNNReal r)) s h c ω := by + have hm' : Measurable (fun p : ℝ × Ω => α (Real.toNNReal p.1) p.2) := + hm.comp (measurable_fst.real_toNNReal.prodMk measurable_snd) + simp only [controlledState] + simp only [NNReal.coe_add] + rw [stepDrift_add (α := fun r => α (Real.toNNReal r)) hm' (fun r ω => hb _ ω) c s h ω] + ring + +end ZeroTemperatureSK.WeakIto + +namespace ZeroTemperatureSK.WeakIto + +def verificationError (c C₂ C₃ L h : ℝ) : ℝ := + C₃/6*(h*Real.sqrt h*normalThirdMoment) + + C₂*c*h*(Real.sqrt h*normalFirstMoment+c*h) + + L*h*(h+Real.sqrt h*normalFirstMoment+c*h) + +lemma verificationError_limit (T c C₂ C₃ L : ℝ) : + Tendsto (fun n : ℕ => (n:ℝ)*verificationError c C₂ C₃ L (T/(n:ℝ))) + atTop (𝓝 0) := by + convert vanishing_mesh_error T + (C₃/6*normalThirdMoment+C₂*c*normalFirstMoment+L*normalFirstMoment) + (C₂*c^2+L*(1+c)) using 1 + funext n + unfold verificationError + ring + +variable {Ω : Type*} [mΩ : MeasurableSpace Ω] {P : Measure Ω} {B : ℝ≥0 → Ω → ℝ} + +theorem constant_interval_verification_upper (hB : IsPreBrownianReal B P) + (hm : ∀ t, Measurable (B t)) {α : ℝ≥0 → Ω → ℝ} + (hαm : Measurable (fun p : ℝ≥0 × Ω => α p.1 p.2)) + (hαp : IsProgressive (Filtration.natural B (fun t => (hm t).stronglyMeasurable)) α) + (hαb : ∀ t ω, |α t ω| ≤ 1) (T c : ℝ≥0) (x : ℝ) + {F D : ℝ → ℝ → ℝ} (hf : ∀ t, ContDiff ℝ 3 (F t)) + (C₁ C₂ C₃ Ct L : ℝ≥0) (hC₁ : ∀ t z, |deriv (F t) z| ≤ C₁) + (hC₂ : ∀ t z, |deriv (deriv (F t)) z| ≤ C₂) + (hC₃ : ∀ t z, |iteratedDeriv 3 (F t) z| ≤ C₃) + (hDm : ∀ t, Measurable (D t)) (hCt : ∀ t z, |D t z| ≤ Ct) + (hD : ∀ r ∈ Set.Icc (0:ℝ) T, ∀ z, + HasDerivWithinAt (fun t => F t z) (D r z) (Set.Icc (0:ℝ) T) r) + (hL : ∀ r ∈ Set.Icc (0:ℝ) T, ∀ s ∈ Set.Icc (0:ℝ) T, ∀ z y, + |D r z-D s y| ≤ (L:ℝ)*(|r-s|+|z-y|)) + (hPDE : ∀ t ∈ Set.Icc (0:ℝ) T, ∀ z, + D t z+(1/2:ℝ)*deriv (deriv (F t)) z+(c:ℝ)/2*(deriv (F t) z)^2 = 0) : + (∫ ω, F T (controlledState B α c x T ω) ∂P) - + (∫ ω, stepCost (fun r => α (Real.toNNReal r)) 0 T c ω ∂P) ≤ F 0 x := by + let := hB.isGaussianProcess.isProbabilityMeasure + let A (r : ℝ) := α (Real.toNNReal r) + have hAm : Measurable (fun p : ℝ × Ω => A p.1 p.2) := + hαm.comp (measurable_fst.real_toNNReal.prodMk measurable_snd) + have hAb : ∀ r ω, |A r ω| ≤ 1 := fun r ω => hαb _ ω + let Q (t : ℝ≥0) := (∫ ω, F t (controlledState B α c x t ω) ∂P) - + (∫ ω, stepCost A 0 t c ω ∂P) + have hstep (s h : ℝ≥0) (hst : s+h ≤ T) : + Q (s+h)-Q s ≤ verificationError c C₂ C₃ L h := by + have hs : (s:ℝ) ∈ Set.Icc (0:ℝ) T := + ⟨s.coe_nonneg, NNReal.coe_le_coe.mpr (le_trans (le_add_of_nonneg_right (show (0:ℝ≥0) ≤ h from bot_le)) hst)⟩ + have hsub : Set.Icc (s:ℝ) ((s:ℝ)+(h:ℝ)) ⊆ Set.Icc (0:ℝ) T := by + intro r hr + constructor + · exact le_trans s.coe_nonneg hr.1 + · exact hr.2.trans (by exact_mod_cast hst) + have hh := expected_verification_step hB hm s h c + (controlledState_adapted hm hαp c x s) (controlledState_integrable hB hαm hαb c x s) hAm hAb + hf C₁ C₂ C₃ Ct L hC₁ hC₂ hC₃ (hDm s) (hCt s) + (fun r hr z => (hD r (hsub hr) z).mono hsub) + (fun r hr z y => hL r (hsub hr) s hs z y) (hPDE s hs) + have hK : (∫ ω, stepCost A 0 ((s:ℝ)+(h:ℝ)) c ω ∂P) = + (∫ ω, stepCost A 0 s c ω ∂P)+(∫ ω, stepCost A s h c ω ∂P) := by + have he : stepCost A 0 ((s:ℝ)+(h:ℝ)) c = fun ω => + stepCost A 0 s c ω+stepCost A s h c ω := funext (stepCost_add hAm hAb c s h) + rw [he, integral_add (stepCost_integrable hAm hAb 0 s c s.coe_nonneg c.coe_nonneg) + (stepCost_integrable hAm hAb s h c h.coe_nonneg c.coe_nonneg)] + have hF : (fun ω => F ((s:ℝ)+(h:ℝ)) + (controlledState B α c x s ω+(B (s+h) ω-B s ω)+stepDrift A s h c ω)) = + (fun ω => F (s+h) (controlledState B α c x (s+h) ω)) := by + funext ω + rw [controlledState_increment hαm hαb c x s h ω] + rw [hF] at hh + dsimp only [Q] + simp only [NNReal.coe_add] + rw [hK] + unfold verificationError + linarith + have hmesh : ∀ᶠ n : ℕ in atTop, + Q T-Q 0 ≤ (n:ℝ)*verificationError c C₂ C₃ L ((T:ℝ)/(n:ℝ)) := by + filter_upwards [eventually_ge_atTop (1:ℕ)] with n hn + have hn0 : (n:ℝ≥0) ≠ 0 := by exact_mod_cast (by omega : n ≠ 0) + let h : ℝ≥0 := T/n + have hend : (n:ℝ≥0)*h = T := by dsimp only [h]; field_simp + have hh := finite_mesh_verification (fun k => Q ((k:ℝ≥0)*h)) (fun _ => 0) n + (verificationError c C₂ C₃ L h) (by + intro k hk + have hbound : (k:ℝ≥0)*h+h ≤ T := by + calc + _ = ((k+1:ℕ):ℝ≥0)*h := by push_cast; ring + _ ≤ (n:ℝ≥0)*h := mul_le_mul_of_nonneg_right (by exact_mod_cast (by omega : k+1 ≤ n)) (show (0:ℝ≥0) ≤ h from bot_le) + _ = T := hend + have he := hstep ((k:ℝ≥0)*h) h hbound + have ht : ((k:ℝ≥0)*h+h) = ((k+1:ℕ):ℝ≥0)*h := by push_cast; ring + simpa only [ht, sub_zero] using he) + simpa only [hend, Nat.cast_zero, zero_mul, Finset.sum_const_zero, sub_zero, + h, NNReal.coe_div, NNReal.coe_natCast] using hh + have hle : Q T-Q 0 ≤ 0 := + ge_of_tendsto (verificationError_limit T c C₂ C₃ L) hmesh + have hQ0 : Q 0 = F 0 x := by + simp [Q, controlledState_zero, stepCost] + rw [hQ0] at hle + exact sub_nonpos.mp hle + +end ZeroTemperatureSK.WeakIto + +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKSupport/Foundations/DerivVarianceHeatCurve.lean b/lean/OAI/Probability/SKSupport/Foundations/DerivVarianceHeatCurve.lean new file mode 100644 index 0000000000000000000000000000000000000000..16ca31aae078b5e1bf409148989766ac13578f2b --- /dev/null +++ b/lean/OAI/Probability/SKSupport/Foundations/DerivVarianceHeatCurve.lean @@ -0,0 +1,168 @@ +import Mathlib +import OAI.Probability.SKSupport.Foundations.Cascade + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology ContDiff +noncomputable section +namespace ZeroTemperatureSK.Heat + +lemma hasDerivAt_varianceHeat_curve {g V X : ℝ → ℝ} (hgc : ContDiff ℝ 2 g) + (hg : ExponentialBound g) (hg' : ExponentialBound (deriv g)) + (hg'' : ExponentialBound (deriv (deriv g))) {s V' X' : ℝ} + (hV : HasDerivAt V V' s) (hX : HasDerivAt X X' s) (hpos : 0 < V s) : + HasDerivAt (fun r => varianceHeat (V r) g (X r)) + (V'/2*varianceHeat (V s) (deriv (deriv g)) (X s)+ + X'*varianceHeat (V s) (deriv g) (X s)) s := by + have hrs : Real.sqrt (V s) ≠ 0 := ne_of_gt (Real.sqrt_pos.mpr hpos) + have hd := (hasFDerivAt_scaled_joint (hgc.of_le (by norm_num)) hg hg' + (X s, Real.sqrt (V s))).comp_hasDerivAt s + (hX.prodMk (hV.sqrt (ne_of_gt hpos))) + have hs := (hasDerivAt_scaled (hgc.of_le (by norm_num)) hg hg' + (Real.sqrt (V s)) (X s)).unique + (hasDerivAt_scaled_second hgc hg hg' hg'' (Real.sqrt (V s)) (X s)) + convert hd using 1 <;> first | rfl | skip + simp only [add_apply, smul_apply, + ContinuousLinearMap.coe_fst', ContinuousLinearMap.coe_snd', smul_eq_mul] + rw [hs] + dsimp only [varianceHeat] + field_simp [hrs] + ring + +end ZeroTemperatureSK.Heat + +namespace ZeroTemperatureSK.Heat + +lemma hasDerivAt_varianceLogHeat_curve {f V X : ℝ → ℝ} {K : ℝ≥0} + (hf : RegularDatum f) (hLip : LipschitzWith K f) (c : ℝ) {s V' X' : ℝ} + (hV : HasDerivAt V V' s) (hX : HasDerivAt X X' s) (hpos : 0 < V s) : + HasDerivAt (fun r => varianceLogHeat c (V r) f (X r)) + (V'*((1/2:ℝ)*deriv (deriv (varianceLogHeat c (V s) f)) (X s)+ + c/2*(deriv (varianceLogHeat c (V s) f) (X s))^2)+ + X'*deriv (varianceLogHeat c (V s) f) (X s)) s := by + by_cases hc : c = 0 + · subst c + obtain ⟨C,hC⟩ := hf.deriv_bounded.bound + obtain ⟨D,hD⟩ := hf.deriv_bounded.deriv.bound + have hfg := exponentialBound_of_lipschitz hLip + have hfg' := ExponentialBound.of_bounded hC + have hfg'' := ExponentialBound.of_bounded hD + have hfc : ContDiff ℝ 2 f := hf.smooth.of_le (ENat.natCast_le_of_coe_top_le_withTop le_rfl 2) + have heF : varianceLogHeat 0 (V s) f = varianceHeat (V s) f := by funext z; simp [varianceLogHeat] + rw [heF] + simp only [varianceLogHeat, ↓reduceIte, zero_div, zero_mul, add_zero] + rw [deriv_deriv_varianceHeat hfc hfg hfg' hfg'', + deriv_varianceHeat (hfc.of_le (by norm_num)) hfg hfg'] + convert hasDerivAt_varianceHeat_curve hfc hfg hfg' hfg'' hV hX hpos using 1; ring + · let g : ℝ → ℝ := fun z => Real.exp (c*f z) + have hgc : ContDiff ℝ 2 g := ((contDiff_const.mul hf.smooth).exp).of_le (ENat.natCast_le_of_coe_top_le_withTop le_rfl 2) + have hg : ExponentialBound g := exponentialBound_exp hLip c + have hg' : ExponentialBound (deriv g) := by + simpa only [iteratedDeriv_one] using exponentialBound_exp_iteratedDeriv hf hLip c 1 + have hg'' : ExponentialBound (deriv (deriv g)) := by + simpa only [iteratedDeriv_succ, iteratedDeriv_one, iteratedDeriv_zero] using + exponentialBound_exp_iteratedDeriv hf hLip c 2 + have hq : varianceHeat (V s) g (X s) ≠ 0 := ne_of_gt (varianceHeat_exp_pos hLip c (V s) (X s)) + have hd := ((hasDerivAt_varianceHeat_curve hgc hg hg' hg'' hV hX hpos).log hq).div_const c + have ht := (((hasDerivWithinAt_varianceHeat hgc hg hg' hg'' hpos.le (X s)).hasDerivAt + (Ici_mem_nhds hpos)).log hq).div_const c + have hteq : ((1/2:ℝ)*varianceHeat (V s) (deriv (deriv g)) (X s))/ + varianceHeat (V s) g (X s)/c = + (1/2:ℝ)*deriv (deriv (varianceLogHeat c (V s) f)) (X s)+ + c/2*(deriv (varianceLogHeat c (V s) f) (X s))^2 := by + apply ht.unique + simpa only [varianceLogHeat, hc, ↓reduceIte, g] using + (varianceLogHeat_equation hf hLip c hpos.le (X s)).hasDerivAt (Ici_mem_nhds hpos) + have hs := ((hasDerivAt_scaled_space (hgc.of_le (by norm_num)) hg hg' + (Real.sqrt (V s)) (X s)).log hq).div_const c + have hseq : varianceHeat (V s) (deriv g) (X s)/varianceHeat (V s) g (X s)/c = + deriv (varianceLogHeat c (V s) f) (X s) := by + have heF : varianceLogHeat c (V s) f = fun z => Real.log (varianceHeat (V s) g z)/c := by + funext z; simp only [varianceLogHeat,hc,↓reduceIte,g] + rw [heF] + exact hs.deriv.symm + have hfun : (fun r => Real.log (varianceHeat (V r) g (X r))/c) = + fun r => varianceLogHeat c (V r) f (X r) := by + funext r; simp only [varianceLogHeat, hc, ↓reduceIte, g] + rw [hfun] at hd + apply hd.congr_deriv + rw [← hteq, ← hseq] + ring + +end ZeroTemperatureSK.Heat +namespace ZeroTemperatureSK.Heat + +def kernelConstant : ℝ := ∫ y : ℝ, |y| ∂gaussianReal 0 1 + +lemma kernelConstant_nonneg : 0 ≤ kernelConstant := integral_nonneg (fun _ => abs_nonneg _) + +lemma integrable_standardGaussian_abs : Integrable (fun y : ℝ => |y|) (gaussianReal 0 1) := by + simpa only [zero_mul, Real.exp_zero, mul_one] using integrable_abs_mul_exp_abs 0 + +lemma scaled_gradient_stein {g : ℝ → ℝ} (hg : BoundedSmooth g) (a x : ℝ) : + a * deriv (scaled a g) x = ∫ y, y*g (x+a*y) ∂gaussianReal 0 1 := by + obtain ⟨C,hC⟩ := hg.bound + obtain ⟨D,hD⟩ := hg.deriv.bound + have hgc : ContDiff ℝ 1 g := hg.smooth.of_le (by simp) + rw [(hasDerivAt_scaled_space hgc (ExponentialBound.of_bounded hC) + (ExponentialBound.of_bounded hD) a x).deriv] + have he := standardGaussian_stein (g := fun y => g (x+a*y)) + (g' := fun y => a*deriv g (x+a*y)) (fun y => by + convert (hgc.differentiable (by norm_num) (x+a*y)).hasDerivAt.comp y + (((hasDerivAt_id y).const_mul a).const_add x) using 1 <;> first | rfl | ring) + (integrable_scaled_of_expBound hg.smooth.continuous.measurable + (ExponentialBound.of_bounded hC) a x) + ((integrable_scaled_of_expBound hg.deriv.smooth.continuous.measurable + (ExponentialBound.of_bounded hD) a x).const_mul a) + (integrable_mul_scaled_of_expBound hg.smooth.continuous.measurable + (ExponentialBound.of_bounded hC) a x) + simpa only [integral_const_mul, scaled] using he.symm + +lemma scaled_gradient_bound {g : ℝ → ℝ} (hg : BoundedSmooth g) + {C : ℝ≥0} (hC : ∀ z, |g z| ≤ C) {a : ℝ} (ha : 0 < a) (x : ℝ) : + |deriv (scaled a g) x| ≤ kernelConstant * C / a := by + have he := scaled_gradient_stein hg a x + have hi := integrable_mul_scaled_of_expBound hg.smooth.continuous.measurable + (ExponentialBound.of_bounded hC) a x + have hh : |a*deriv (scaled a g) x| ≤ kernelConstant*C := by + rw [he] + apply abs_integral_le_integral_abs.trans + calc + (∫ y, |y*g (x+a*y)| ∂gaussianReal 0 1) ≤ + ∫ y : ℝ, |y| *(C:ℝ) ∂gaussianReal 0 1 := by + apply integral_mono hi.abs (integrable_standardGaussian_abs.mul_const C) + intro y + change |y*g (x+a*y)| ≤ |y| *(C:ℝ) + rw [abs_mul] + gcongr + exact hC _ + _ = kernelConstant*C := by rw [integral_mul_const]; rfl + rw [abs_mul, abs_of_pos ha] at hh + apply (le_div_iff₀ ha).mpr + linarith + +lemma semigroup_gradient_bound {g : ℝ → ℝ} (hg : BoundedSmooth g) + {C : ℝ≥0} (hC : ∀ z, |g z| ≤ C) {h : ℝ≥0} (hh : 0 < h) (x : ℝ) : + |deriv (semigroup h g) x| ≤ kernelConstant * C / Real.sqrt (h:ℝ) := by + have he : semigroup h g = scaled (Real.sqrt (h:ℝ)) g := + funext (fun z => semigroup_eq_scaled hg.smooth.continuous.measurable h z) + rw [he] + apply scaled_gradient_bound hg hC + exact Real.sqrt_pos.mpr (by exact_mod_cast hh) + +end ZeroTemperatureSK.Heat + +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKSupport/Foundations/DerivWithinVarianceHeatWeightExp.lean b/lean/OAI/Probability/SKSupport/Foundations/DerivWithinVarianceHeatWeightExp.lean new file mode 100644 index 0000000000000000000000000000000000000000..4a9026e4a514ed69ec4d8621c9e874957e9566d0 --- /dev/null +++ b/lean/OAI/Probability/SKSupport/Foundations/DerivWithinVarianceHeatWeightExp.lean @@ -0,0 +1,197 @@ +import Mathlib +import OAI.Probability.SKSupport.Parabolic.VarianceTilted + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology ContDiff +noncomputable section +namespace ZeroTemperatureSK.Heat + +lemma hasDerivWithinAt_varianceHeat_weightExp {f g : ℝ → ℝ} {K : ℝ≥0} + (hf : RegularDatum f) (hLip : LipschitzWith K f) (hg : BoundedSmooth g) (c : ℝ) + {t : ℝ} (ht : 0 ≤ t) (x : ℝ) : + HasDerivWithinAt (fun s => varianceHeat s (fun z => g z*Real.exp (c*f z)) x) + ((1/2:ℝ)*varianceHeat t (deriv (deriv (fun z => g z*Real.exp (c*f z)))) x) + (Set.Ici 0) t := by + exact hasDerivWithinAt_varianceHeat + ((hg.smooth.mul (contDiff_const.mul hf.smooth).exp).of_le + (ENat.natCast_le_of_coe_top_le_withTop le_rfl 2)) + (by simpa only [iteratedDeriv_zero] using exponentialBound_weightExp_iteratedDeriv hf hLip hg c 0) + (by simpa only [iteratedDeriv_one] using exponentialBound_weightExp_iteratedDeriv hf hLip hg c 1) + (by simpa only [iteratedDeriv_succ, iteratedDeriv_one, iteratedDeriv_zero] using + exponentialBound_weightExp_iteratedDeriv hf hLip hg c 2) ht x + +lemma hasDerivWithinAt_varianceTilted {f g q r : ℝ → ℝ} {K : ℝ≥0} + (hf : RegularDatum f) (hLip : LipschitzWith K f) (hg : BoundedSmooth g) (c : ℝ) + (hq : deriv (deriv (fun z => g z*Real.exp (c*f z))) = fun z => q z*Real.exp (c*f z)) + (hr : deriv (deriv (fun z => Real.exp (c*f z))) = fun z => r z*Real.exp (c*f z)) + {t : ℝ} (ht : 0 ≤ t) (x : ℝ) : + HasDerivWithinAt (fun s => varianceTilted c s f g x) + ((1/2:ℝ)*(varianceTilted c t f q x-varianceTilted c t f g x*varianceTilted c t f r x)) + (Set.Ici 0) t := by + have hd := (hasDerivWithinAt_varianceHeat_weightExp hf hLip hg c ht x).div + (hasDerivWithinAt_varianceHeat_exp hf hLip c ht x) + (ne_of_gt (varianceHeat_exp_pos hLip c t x)) + rw [hq, hr] at hd + convert hd using 1 <;> try rfl + all_goals + try dsimp only [varianceTilted] + field_simp [ne_of_gt (varianceHeat_exp_pos hLip c t x)] + +lemma varianceTilted_time_lipschitz {f g : ℝ → ℝ} {K : ℝ≥0} + (hf : RegularDatum f) (hLip : LipschitzWith K f) (hg : BoundedSmooth g) (c : ℝ) : + ∃ C : ℝ≥0, ∀ x, LipschitzOnWith C (fun t => varianceTilted c t f g x) (Set.Ici 0) := by + obtain ⟨q,hqs,hq⟩ := weightExp_iteratedDeriv_weight hf hg c 2 + obtain ⟨r,hrs,hr⟩ := exp_iteratedDeriv_weight hf c 2 + simp only [iteratedDeriv_succ, iteratedDeriv_zero] at hq hr + obtain ⟨Q,hQ⟩ := hqs.bound + obtain ⟨R,hR⟩ := hrs.bound + obtain ⟨G,hG⟩ := hg.bound + refine ⟨(Q+G*R)/2, fun x => ?_⟩ + apply (convex_Ici (0:ℝ)).lipschitzOnWith_of_nnnorm_hasDerivWithin_le + (fun t ht => hasDerivWithinAt_varianceTilted hf hLip hg c hq hr ht x) + intro t ht + apply NNReal.coe_le_coe.mp + simp only [coe_nnnorm, Real.norm_eq_abs, NNReal.coe_div, NNReal.coe_add, + NNReal.coe_mul, NNReal.coe_ofNat] + rw [abs_mul, abs_of_pos (by norm_num : (0:ℝ)<1/2)] + have hb : |varianceTilted c t f q x-varianceTilted c t f g x*varianceTilted c t f r x| ≤ + (Q:ℝ)+(G:ℝ)*(R:ℝ) := by + calc + _ ≤ |varianceTilted c t f q x|+|varianceTilted c t f g x*varianceTilted c t f r x| := abs_sub _ _ + _ ≤ (Q:ℝ)+(G:ℝ)*(R:ℝ) := by + apply add_le_add (varianceTilted_bound hLip hqs.smooth.continuous.measurable hQ c t x) + rw [abs_mul] + exact mul_le_mul + (varianceTilted_bound hLip hg.smooth.continuous.measurable hG c t x) + (varianceTilted_bound hLip hrs.smooth.continuous.measurable hR c t x) + (abs_nonneg _) G.coe_nonneg + linarith + +lemma varianceTilted_space_lipschitz {f g : ℝ → ℝ} {K : ℝ≥0} + (hf : RegularDatum f) (hLip : LipschitzWith K f) (hg : BoundedSmooth g) + {c : ℝ} (hc : 0 ≤ c) : + ∃ C : ℝ≥0, ∀ t, LipschitzWith C (varianceTilted c t f g) := by + obtain ⟨C,hC⟩ := uniform_tiltedMean_bounds hf hLip hg hc 1 + refine ⟨C, fun t => ?_⟩ + have he : varianceTilted c t f g = tiltedMean c (Real.toNNReal t) f g := + funext (varianceTilted_eq_tiltedMean hf.smooth.continuous.measurable + hg.smooth.continuous.measurable c t) + rw [he] + apply lipschitzWith_of_nnnorm_deriv_le + ((contDiff_tiltedMean hf hLip hg hc _).differentiable (by simp)) + intro x + exact NNReal.coe_le_coe.mp (by + simpa only [coe_nnnorm, Real.norm_eq_abs, iteratedDeriv_one] using (hC (Real.toNNReal t) x)) + +lemma varianceTilted_joint_bound {f g : ℝ → ℝ} {K : ℝ≥0} + (hf : RegularDatum f) (hLip : LipschitzWith K f) (hg : BoundedSmooth g) + {c : ℝ} (hc : 0 ≤ c) : + ∃ L : ℝ≥0, ∀ t ∈ Set.Ici (0:ℝ), ∀ s ∈ Set.Ici (0:ℝ), ∀ x y, + |varianceTilted c t f g x-varianceTilted c s f g y| ≤ (L:ℝ)*(|t-s|+|x-y|) := by + obtain ⟨A,hA⟩ := varianceTilted_time_lipschitz hf hLip hg c + obtain ⟨B,hB⟩ := varianceTilted_space_lipschitz hf hLip hg hc + refine ⟨A+B, fun t ht s hs x y => ?_⟩ + have ha := (hA x).dist_le_mul t ht s hs + have hb := (hB s).dist_le_mul x y + simp only [Real.dist_eq] at ha hb + have htri := abs_sub_le (varianceTilted c t f g x) (varianceTilted c s f g x) + (varianceTilted c s f g y) + simp only [NNReal.coe_add] + nlinarith [mul_nonneg A.coe_nonneg (abs_nonneg (x-y)), + mul_nonneg B.coe_nonneg (abs_nonneg (t-s))] + +end ZeroTemperatureSK.Heat + +namespace ZeroTemperatureSK.Heat + +lemma varianceHeat_const_mul (a t : ℝ) (g : ℝ → ℝ) (x : ℝ) : + varianceHeat t (fun z => a*g z) x = a*varianceHeat t g x := by + exact integral_const_mul a _ + +lemma varianceTilted_zero (t : ℝ) (f g : ℝ → ℝ) (x : ℝ) : + varianceTilted 0 t f g x = varianceHeat t g x := by + simp [varianceTilted, varianceHeat, scaled] + +def generatorWeight (c : ℝ) (f : ℝ → ℝ) : ℝ → ℝ := + fun z => deriv (deriv f) z+c*(deriv f z)^2 + +lemma boundedSmooth_generatorWeight {f : ℝ → ℝ} (hf : RegularDatum f) (c : ℝ) : + BoundedSmooth (generatorWeight c f) := by + have hh := hf.deriv_bounded.deriv.add ((hf.deriv_bounded.mul hf.deriv_bounded).const_mul c) + change BoundedSmooth (fun z => deriv (deriv f) z+c*(deriv f z)^2) + simpa only [pow_two] using hh + +lemma deriv_exp_comp {f : ℝ → ℝ} (hf : RegularDatum f) (c : ℝ) : + deriv (fun z => Real.exp (c*f z)) = fun z => c*deriv f z*Real.exp (c*f z) := by + funext z + convert (((hf.smooth.differentiable (by simp) z).hasDerivAt.const_mul c).exp).deriv using 1 + ring + +lemma deriv_deriv_exp_comp {f : ℝ → ℝ} (hf : RegularDatum f) (c : ℝ) : + deriv (deriv (fun z => Real.exp (c*f z))) = + fun z => c*(generatorWeight c f z*Real.exp (c*f z)) := by + rw [deriv_exp_comp hf c, deriv_weightExp hf (hf.deriv_bounded.const_mul c) c] + funext z + have hd : deriv (fun z => c*deriv f z) z = c*deriv (deriv f) z := + (((hf.deriv_bounded.smooth.differentiable (by simp) z).hasDerivAt).const_mul c).deriv + simp only [hd, generatorWeight] + ring + +lemma varianceLogHeat_time_derivative {f : ℝ → ℝ} {K : ℝ≥0} + (hf : RegularDatum f) (hLip : LipschitzWith K f) (c : ℝ) + {t : ℝ} (ht : 0 ≤ t) (x : ℝ) : + HasDerivWithinAt (fun s => varianceLogHeat c s f x) + ((1/2:ℝ)*varianceTilted c t f (generatorWeight c f) x) (Set.Ici 0) t := by + by_cases hc : c = 0 + · subst c + have he : (fun s => varianceLogHeat 0 s f x) = fun s => varianceHeat s f x := by + funext s; simp [varianceLogHeat] + rw [he, varianceTilted_zero] + have hw : generatorWeight 0 f = deriv (deriv f) := by funext z; simp [generatorWeight] + rw [hw] + obtain ⟨C,hC⟩ := hf.deriv_bounded.bound + obtain ⟨C',hC'⟩ := hf.deriv_bounded.deriv.bound + exact hasDerivWithinAt_varianceHeat + (hf.smooth.of_le (ENat.natCast_le_of_coe_top_le_withTop le_rfl 2)) + (exponentialBound_of_lipschitz hLip) (ExponentialBound.of_bounded hC) + (ExponentialBound.of_bounded hC') ht x + · have hd := ((hasDerivWithinAt_varianceHeat_exp hf hLip c ht x).log + (ne_of_gt (varianceHeat_exp_pos hLip c t x))).div_const c + have he : (fun s => varianceLogHeat c s f x) = fun s => + Real.log (varianceHeat s (fun z => Real.exp (c*f z)) x)/c := by + funext s; simp [varianceLogHeat, hc] + rw [he] + rw [deriv_deriv_exp_comp hf c, varianceHeat_const_mul] at hd + convert hd using 1 + dsimp only [varianceTilted] + field_simp [hc, ne_of_gt (varianceHeat_exp_pos hLip c t x)] + +lemma varianceLogHeat_generator_identity {f : ℝ → ℝ} {K : ℝ≥0} + (hf : RegularDatum f) (hLip : LipschitzWith K f) (c : ℝ) + {t : ℝ} (ht : 0 ≤ t) (x : ℝ) : + (1/2:ℝ)*varianceTilted c t f (generatorWeight c f) x = + (1/2:ℝ)*deriv (deriv (varianceLogHeat c t f)) x+ + c/2*(deriv (varianceLogHeat c t f) x)^2 := by + have h₁ := (varianceLogHeat_time_derivative hf hLip c ht x).derivWithin + (uniqueDiffOn_Ici (0:ℝ) t ht) + have h₂ := (varianceLogHeat_equation hf hLip c ht x).derivWithin + (uniqueDiffOn_Ici (0:ℝ) t ht) + exact h₁.symm.trans h₂ + +end ZeroTemperatureSK.Heat + +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKSupport/Foundations/ElementaryControl.lean b/lean/OAI/Probability/SKSupport/Foundations/ElementaryControl.lean new file mode 100644 index 0000000000000000000000000000000000000000..c7e41f81cacc05f0d96f94b282a46d7ae0df6dd4 --- /dev/null +++ b/lean/OAI/Probability/SKSupport/Foundations/ElementaryControl.lean @@ -0,0 +1,134 @@ +import Mathlib +import OAI.Probability.SKSupport.Model + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section +namespace ZeroTemperatureSK.WeakIto +variable {Ω : Type*} [mΩ : MeasurableSpace Ω] + +def elementaryControl (h : ℝ≥0) (a : ℕ → Ω → ℝ) : ℕ → ℝ≥0 → Ω → ℝ + | 0, _, _ => 0 + | n+1, t, ω => if (n:ℝ≥0)*h ≤ t ∧ t < ((n+1:ℕ):ℝ≥0)*h then a n ω + else elementaryControl h a n t ω + +omit mΩ in +lemma elementaryControl_bound (h : ℝ≥0) {a : ℕ → Ω → ℝ} + (ha : ∀ n ω, |a n ω| ≤ 1) (n : ℕ) (t : ℝ≥0) (ω : Ω) : + |elementaryControl h a n t ω| ≤ 1 := by + induction n with + | zero => simp [elementaryControl] + | succ n IH => simp only [elementaryControl]; split_ifs <;> first | exact ha n ω | exact IH + +lemma elementaryControl_progressive (ℱ : Filtration ℝ≥0 mΩ) (h : ℝ≥0) + {a : ℕ → Ω → ℝ} (ha : ∀ n : ℕ, Measurable[ℱ ((n:ℝ≥0)*h)] (a n)) (n : ℕ) : + IsProgressive ℱ (elementaryControl h a n) := by + induction n with + | zero => exact isProgressive_const ℱ 0 + | succ n IH => + intro s + by_cases hns : (n:ℝ≥0)*h ≤ s + · have ham : Measurable[ℱ s] (a n) := (ha n).mono (ℱ.mono hns) le_rfl + let : MeasurableSpace Ω := ℱ s + have htime : Measurable (fun p : Set.Iic s × Ω => (p.1:ℝ≥0)) := + measurable_subtype_coe.comp measurable_fst + have hset : MeasurableSet {p : Set.Iic s × Ω | + (n:ℝ≥0)*h ≤ (p.1:ℝ≥0) ∧ (p.1:ℝ≥0) < ((n+1:ℕ):ℝ≥0)*h} := + (measurableSet_le (measurable_const : Measurable (fun _ : Set.Iic s × Ω => (n:ℝ≥0)*h)) htime).inter + (measurableSet_lt (α := ℝ≥0) (f := fun p : Set.Iic s × Ω => (p.1:ℝ≥0)) + (g := fun _ : Set.Iic s × Ω => ((n+1:ℕ):ℝ≥0)*h) htime measurable_const) + exact (ham.comp measurable_snd).ite hset (IH s) + · convert IH s using 1 + funext p + have hn : ¬(n:ℝ≥0)*h ≤ (p.1:ℝ≥0) := fun ht => hns (ht.trans p.1.property) + simp only [elementaryControl, hn, false_and, ↓reduceIte] + +lemma progressive_joint_measurable (ℱ : Filtration ℝ≥0 mΩ) + {α : ℝ≥0 → Ω → ℝ} (hα : IsProgressive ℱ α) : + Measurable (fun p : ℝ≥0 × Ω => α p.1 p.2) := by + have hclip (n : ℕ) : Measurable (fun p : ℝ≥0 × Ω => α (min p.1 n) p.2) := by + have hs : Measurable[inferInstance, ℱ (n:ℝ≥0)] (fun p : ℝ≥0 × Ω => p.2) := + measurable_snd.mono le_rfl (ℱ.le n) + exact (hα n).comp (((measurable_fst.min measurable_const).subtype_mk + (h := fun p : ℝ≥0 × Ω => min_le_right p.1 (n:ℝ≥0))).prodMk hs) + apply measurable_of_tendsto_metrizable hclip + apply tendsto_pi_nhds.mpr + intro p + apply tendsto_const_nhds.congr' + filter_upwards [(tendsto_natCast_atTop_atTop : Tendsto (fun n : ℕ => (n:ℝ≥0)) atTop atTop).eventually + (eventually_ge_atTop p.1)] with n hn + simp only [min_eq_left hn] + +omit mΩ in +lemma elementaryControl_on_step (h : ℝ≥0) (a : ℕ → Ω → ℝ) (n k : ℕ) (hk : k < n) + (t : ℝ≥0) (ht : (k:ℝ≥0)*h ≤ t ∧ t < ((k+1:ℕ):ℝ≥0)*h) (ω : Ω) : + elementaryControl h a n t ω = a k ω := by + induction n with + | zero => omega + | succ n IH => + by_cases hkn : k = n + · subst k + simp only [elementaryControl, ht, and_self, ↓reduceIte] + · have hkn' : k < n := by omega + have hlt : t < (n:ℝ≥0)*h := ht.2.trans_le + (mul_le_mul_of_nonneg_right (by exact_mod_cast (by omega : k+1 ≤ n)) (by positivity)) + simp only [elementaryControl, not_le.mpr hlt, false_and, ↓reduceIte] + exact IH hkn' + +omit mΩ in +lemma elementaryControl_integral_on_step (h : ℝ≥0) (a : ℕ → Ω → ℝ) + (n k : ℕ) (hk : k < n) (φ : ℝ → ℝ) (ω : Ω) : + (∫ r in ((k:ℝ≥0)*h:ℝ)..((k:ℝ≥0)*h:ℝ)+(h:ℝ), + φ (elementaryControl h a n (Real.toNNReal r) ω)) = (h:ℝ)*φ (a k ω) := by + have he : (∫ r in ((k:ℝ≥0)*h:ℝ)..((k:ℝ≥0)*h:ℝ)+(h:ℝ), + φ (elementaryControl h a n (Real.toNNReal r) ω)) = + ∫ _r in ((k:ℝ≥0)*h:ℝ)..((k:ℝ≥0)*h:ℝ)+(h:ℝ), φ (a k ω) := by + apply intervalIntegral.integral_congr_Ioo_of_le (by linarith [h.coe_nonneg]) + intro r hr + have hr0 : 0 ≤ r := le_trans ((k:ℝ≥0)*h).coe_nonneg hr.1.le + have hr' : (k:ℝ≥0)*h ≤ Real.toNNReal r ∧ Real.toNNReal r < ((k+1:ℕ):ℝ≥0)*h := by + constructor + · apply NNReal.coe_le_coe.mp + rw [Real.coe_toNNReal _ hr0] + exact hr.1.le + · apply NNReal.coe_lt_coe.mp + rw [Real.coe_toNNReal _ hr0] + simpa only [NNReal.coe_mul, NNReal.coe_natCast, Nat.cast_add, Nat.cast_one, add_mul, one_mul, NNReal.coe_add] using hr.2 + change φ (elementaryControl h a n (Real.toNNReal r) ω) = φ (a k ω) + rw [elementaryControl_on_step h a n k hk (Real.toNNReal r) hr' ω] + rw [he, intervalIntegral.integral_const] + simp only [add_sub_cancel_left, smul_eq_mul] + +def feedbackEuler (B : ℝ≥0 → Ω → ℝ) (h c : ℝ≥0) (u : ℝ → ℝ → ℝ) (x : ℝ) : + ℕ → Ω → ℝ + | 0, _ => x + | n+1, ω => feedbackEuler B h c u x n ω + (B (((n+1:ℕ):ℝ≥0)*h) ω-B ((n:ℝ≥0)*h) ω) + + (c:ℝ)*(h:ℝ)*u ((n:ℝ≥0)*h) (feedbackEuler B h c u x n ω) + +lemma feedbackEuler_adapted {B : ℝ≥0 → Ω → ℝ} (hm : ∀ t, Measurable (B t)) + (h c : ℝ≥0) {u : ℝ → ℝ → ℝ} (hum : ∀ t, Measurable (u t)) (x : ℝ) (n : ℕ) : + Measurable[Filtration.natural B (fun t => (hm t).stronglyMeasurable) ((n:ℝ≥0)*h)] + (feedbackEuler B h c u x n) := by + induction n with + | zero => exact measurable_const + | succ n IH => + have hle : (n:ℝ≥0)*h ≤ ((n+1:ℕ):ℝ≥0)*h := by gcongr; exact_mod_cast Nat.le_succ n + have hYm := IH.mono ((Filtration.natural B (fun t => (hm t).stronglyMeasurable)).mono hle) le_rfl + have hBs := (Filtration.stronglyAdapted_natural (fun t => (hm t).stronglyMeasurable) ((n:ℝ≥0)*h)).measurable.mono + ((Filtration.natural B (fun t => (hm t).stronglyMeasurable)).mono hle) le_rfl + have hBt := (Filtration.stronglyAdapted_natural (fun t => (hm t).stronglyMeasurable) (((n+1:ℕ):ℝ≥0)*h)).measurable + exact (hYm.add (hBt.sub hBs)).add (((hum _).comp hYm).const_mul ((c:ℝ)*(h:ℝ))) + +end ZeroTemperatureSK.WeakIto + +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKSupport/Foundations/Equation.lean b/lean/OAI/Probability/SKSupport/Foundations/Equation.lean new file mode 100644 index 0000000000000000000000000000000000000000..8c7ba10bc5f87163ef5a20ba93a5b033b099cf72 --- /dev/null +++ b/lean/OAI/Probability/SKSupport/Foundations/Equation.lean @@ -0,0 +1,197 @@ +import Mathlib +import OAI.Probability.SKSupport.Diffusion.CompactDrift + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology ContDiff +noncomputable section +namespace ZeroTemperatureSK +open WeakIto Heat +variable {Ω : Type*} [MeasurableSpace Ω] + +def valueRate (W : BrownianSystem Ω) (γ : OrderParameter) (t x : ℝ) : ℝ := + -(1/2:ℝ)*curvature W γ t x-(1/2:ℝ)*extend γ.val t*(gradient W γ t x)^2 + +lemma approxRate_eq (γ : OrderParameter) (n : ℕ) (t x : ℝ) : + finiteRate (approxCoeff γ n) (approxMesh n) (softAbs ((n+1:ℕ):ℝ)) (n+1) 0 t x = + -(1/2:ℝ)*iteratedDeriv 2 (approxValue γ n t) x- + (1/2:ℝ)*approxGamma γ n t*(iteratedDeriv 1 (approxValue γ n t) x)^2 := by + simp only [finiteRate,finiteSource,approxValue,approxGamma,iteratedDeriv_succ, + iteratedDeriv_zero] + ring + +lemma approxRate_tendsto (W : BrownianSystem Ω) (γ : OrderParameter) (t : Time) + (ht : ContinuousAt γ.val t) (x : ℝ) : + Tendsto (fun n => finiteRate (approxCoeff γ n) (approxMesh n) + (softAbs ((n+1:ℕ):ℝ)) (n+1) 0 t x) atTop (𝓝 (valueRate W γ t x)) := by + have h₂ := (approxValue_derivative_uniform_spatial W γ t.property.1 t.property.2 2).tendsto_at x + have h₁ := (approxValue_derivative_uniform_spatial W γ t.property.1 t.property.2 1).tendsto_at x + have hc := approxGamma_tendsto γ t ht + simp only [approxRate_eq] + have he : extend γ.val t = γ.val t := by simp [extend,t.property] + unfold valueRate curvature gradient + rw [he] + convert (tendsto_const_nhds.mul h₂ (a := -(1/2:ℝ))).sub + ((tendsto_const_nhds.mul hc (a := (1/2:ℝ))).mul (h₁.pow 2)) using 1 + simp only [iteratedDeriv_succ,iteratedDeriv_zero] + +lemma approxRate_bounded_on (γ : OrderParameter) {T : ℝ} (hT0 : 0 ≤ T) (hT1 : T < 1) : + ∃ C : ℝ, 0 ≤ C ∧ ∀ n, ∀ t ∈ Icc (0:ℝ) T, ∀ x, + |finiteRate (approxCoeff γ n) (approxMesh n) (softAbs ((n+1:ℕ):ℝ)) (n+1) 0 t x| ≤ C := by + obtain ⟨C,hC,hb⟩ := approxValue_uniform_derivative_bounds γ hT0 hT1 1 + let D := γ.val ⟨T,⟨hT0,hT1⟩⟩ + have hD : 0 ≤ D := γ.nonneg _ + refine ⟨C+D,add_nonneg hC hD,fun n t ht x => ?_⟩ + rw [approxRate_eq] + have ha := hb n t ht x + have hg : |iteratedDeriv 1 (approxValue γ n t) x| ≤ 1 := by + rw [iteratedDeriv_one] + exact norm_deriv_le_of_lipschitz (finiteValue_lipschitz + (softAbs_lipschitz (show ((n+1:ℕ):ℝ) ≠ 0 by positivity)) _ _ _ _ _) + have hc := approxGamma_bounds γ n (⟨t,⟨ht.1,ht.2.trans_lt hT1⟩⟩ : Time) + have hcd : approxGamma γ n t ≤ D := hc.2.trans (γ.monotone ht.2) + have hsq : |iteratedDeriv 1 (approxValue γ n t) x|^2 ≤ 1 := by + nlinarith [abs_nonneg (iteratedDeriv 1 (approxValue γ n t) x)] + have hc0 : 0 ≤ approxGamma γ n t := hc.1 + refine (abs_sub _ _).trans ?_ + simp only [abs_mul,abs_neg,abs_pow, + abs_of_nonneg (show (0:ℝ) ≤ 1/2 by norm_num),abs_of_nonneg hc0] + change |iteratedDeriv 2 (approxValue γ n t) x| ≤ C at ha + nlinarith [mul_le_mul_of_nonneg_left hsq hc0] + +lemma approxRate_integral_limit (W : BrownianSystem Ω) (γ : OrderParameter) + {a b : ℝ} (ha : 0 ≤ a) (hab : a ≤ b) (hb : b < 1) (x : ℝ) : + Tendsto (fun n => ∫ t in a..b, finiteRate (approxCoeff γ n) (approxMesh n) + (softAbs ((n+1:ℕ):ℝ)) (n+1) 0 t x) atTop (𝓝 (∫ t in a..b, valueRate W γ t x)) := by + obtain ⟨C,hC,hbound⟩ := approxRate_bounded_on γ (ha.trans hab) hb + have hm : ∀ n, AEStronglyMeasurable (fun t => finiteRate (approxCoeff γ n) (approxMesh n) + (softAbs ((n+1:ℕ):ℝ)) (n+1) 0 t x) (volume.restrict (Ioc a b)) := by + intro n + exact ((measurable_finiteRate (regularDatum_softAbs (by positivity)) + (softAbs_lipschitz (by positivity)) _ _ _ _).comp + (measurable_id.prodMk measurable_const)).aestronglyMeasurable + have hdom : ∀ n, ∀ᵐ t ∂volume.restrict (Ioc a b), + ‖finiteRate (approxCoeff γ n) (approxMesh n) (softAbs ((n+1:ℕ):ℝ)) (n+1) 0 t x‖ ≤ C := by + intro n + filter_upwards [ae_restrict_mem measurableSet_Ioc] with t ht + simpa only [Real.norm_eq_abs] using hbound n t ⟨ha.trans ht.1.le,ht.2⟩ x + have hlim : ∀ᵐ t ∂volume.restrict (Ioc a b), Tendsto + (fun n => finiteRate (approxCoeff γ n) (approxMesh n) (softAbs ((n+1:ℕ):ℝ)) (n+1) 0 t x) + atTop (𝓝 (valueRate W γ t x)) := by + filter_upwards [ae_restrict_mem measurableSet_Ioc, + (γ.ae_continuous).filter_mono (ae_mono Measure.restrict_le_self)] with t ht hc + have hmem : t ∈ Ico (0:ℝ) 1 := ⟨ha.trans ht.1.le,ht.2.trans_lt hb⟩ + exact approxRate_tendsto W γ ⟨t,hmem⟩ (hc hmem) x + have hint : Integrable (fun _ : ℝ => C) (volume.restrict (Ioc a b)) := + (intervalIntegrable_const (c := C)).1 + have hh := tendsto_integral_of_dominated_convergence (fun _ => C) hm hint hdom hlim + simpa only [intervalIntegral.integral_of_le hab] using hh + +theorem value_integral_rate (W : BrownianSystem Ω) (γ : OrderParameter) + {a b : ℝ} (ha : 0 ≤ a) (hab : a ≤ b) (hb : b < 1) (x : ℝ) : + (∫ t in a..b, valueRate W γ t x) = value W γ b x-value W γ a x := by + have hvb := (approxValue_uniform_spatial W γ (ha.trans hab) hb.le).tendsto_at x + have hva := (approxValue_uniform_spatial W γ ha (hab.trans hb.le)).tendsto_at x + have he (n : ℕ) : (∫ t in a..b, finiteRate (approxCoeff γ n) (approxMesh n) + (softAbs ((n+1:ℕ):ℝ)) (n+1) 0 t x) = approxValue γ n b x-approxValue γ n a x := by + exact finiteValue_integral_rate (regularDatum_softAbs (by positivity)) + (softAbs_lipschitz (by positivity)) _ _ _ _ ha hab (by rw [approxMesh_horizon]; exact hb.le) x + exact tendsto_nhds_unique (approxRate_integral_limit W γ ha hab hb x) + ((hvb.sub hva).congr (fun n => (he n).symm)) + +end ZeroTemperatureSK + +end +end +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology ContDiff +noncomputable section +namespace ZeroTemperatureSK +open Heat +variable {Ω : Type*} [MeasurableSpace Ω] + +lemma compactGradient_family (W : BrownianSystem Ω) (γ : OrderParameter) + {T : ℝ} (hT0 : 0 ≤ T) (hT1 : T < 1) : + BoundedSmoothFamily (compactGradient W γ T) := by + have hb (n : ℕ) : ∃ C : ℝ≥0, ∀ t x, |iteratedDeriv n (compactGradient W γ T t) x| ≤ C := by + obtain ⟨C,hC,hb⟩ := value_uniform_derivative_bounds W γ hT0 hT1 n + refine ⟨⟨C,hC⟩,fun t x => ?_⟩ + change |iteratedDeriv n (deriv (value W γ (stripClamp T t))) x| ≤ C + simpa only [iteratedDeriv_succ'] using hb (stripClamp T t) (stripClamp_mem hT0 t) x + refine ⟨(compactGradient_continuous W γ hT0 hT1).measurable,fun t => ?_,hb⟩ + refine ⟨?_,fun n => ?_⟩ + · change ContDiff ℝ ∞ (deriv (value W γ (stripClamp T t))) + exact (contDiff_infty_iff_deriv.mp (value_contDiff W γ (stripClamp_mem hT0 t).1 + ((stripClamp_mem hT0 t).2.trans_lt hT1))).2 + · obtain ⟨C,hC⟩ := hb n + exact ⟨C,hC t⟩ + +def compactValueRate (W : BrownianSystem Ω) (γ : OrderParameter) (T t x : ℝ) : ℝ := + valueRate W γ (stripClamp T t) x + +lemma compactValueRate_family (W : BrownianSystem Ω) (γ : OrderParameter) + {T : ℝ} (hT0 : 0 ≤ T) (hT1 : T < 1) : + BoundedSmoothFamily (compactValueRate W γ T) := by + have hu := compactGradient_family W γ hT0 hT1 + have hc : BoundedSmoothFamily (fun t (_x : ℝ) => compactCoeff γ T t) := by + apply BoundedSmoothFamily.timeConst (C := ⟨γ.val ⟨T,⟨hT0,hT1⟩⟩,γ.nonneg _⟩) (compactCoeff_measurable γ T) + intro t + rw [abs_of_nonneg (compactCoeff_bounds γ hT0 hT1 t).1] + exact (compactCoeff_bounds γ hT0 hT1 t).2 + have hh := (hu.deriv.const_mul (-(1/2:ℝ))).add ((hc.mul (hu.mul hu)).const_mul (-(1/2:ℝ))) + convert hh using 1 + funext t x + change -(1/2:ℝ)*deriv (deriv (value W γ (stripClamp T t))) x- + (1/2:ℝ)*extend γ.val (stripClamp T t)*(deriv (value W γ (stripClamp T t)) x)^2 = + -(1/2:ℝ)*deriv (deriv (value W γ (stripClamp T t))) x+ + -(1/2:ℝ)*(extend γ.val (stripClamp T t)* + (deriv (value W γ (stripClamp T t)) x*deriv (value W γ (stripClamp T t)) x)) + ring + +lemma compactRate_integral_derivative (W : BrownianSystem Ω) (γ : OrderParameter) + {T a b : ℝ} (hT0 : 0 ≤ T) (hT1 : T < 1) (ha : 0 ≤ a) (hab : a ≤ b) (hb : b ≤ T) + (m : ℕ) (x : ℝ) : + (∫ t in a..b, iteratedDeriv m (compactValueRate W γ T t) x) = + iteratedDeriv m (value W γ b) x-iteratedDeriv m (value W γ a) x := by + have he : (fun z => ∫ t in a..b, compactValueRate W γ T t z) = + (fun z => value W γ b z-value W γ a z) := by + funext z + rw [← value_integral_rate W γ ha hab (hb.trans_lt hT1) z] + apply intervalIntegral.integral_congr + intro t ht + rw [uIcc_of_le hab] at ht + simp only [compactValueRate,stripClamp_eq ⟨ha.trans ht.1,ht.2.trans hb⟩] + have hi := (compactValueRate_family W γ hT0 hT1).iteratedDeriv_integral m a b x + rw [he,iteratedDeriv_fun_sub (n := m) + ((value_contDiff W γ (ha.trans hab) (hb.trans_lt hT1)).of_le + (ENat.natCast_le_of_coe_top_le_withTop le_rfl m) |>.contDiffAt) + ((value_contDiff W γ ha (hab.trans_lt (hb.trans_lt hT1))).of_le + (ENat.natCast_le_of_coe_top_le_withTop le_rfl m) |>.contDiffAt)] at hi + exact hi.symm + +theorem value_derivative_time_bound (W : BrownianSystem Ω) (γ : OrderParameter) + {T : ℝ} (hT0 : 0 ≤ T) (hT1 : T < 1) (m : ℕ) : + ∃ C : ℝ≥0, ∀ a ∈ Icc (0:ℝ) T, ∀ b ∈ Icc (0:ℝ) T, ∀ x, + |iteratedDeriv m (value W γ b) x-iteratedDeriv m (value W γ a) x| ≤ C*|b-a| := by + obtain ⟨C,hC⟩ := (compactValueRate_family W γ hT0 hT1).bounds m + have hh (a b : ℝ) (ha : 0 ≤ a) (hab : a ≤ b) (hb : b ≤ T) (x : ℝ) : + |iteratedDeriv m (value W γ b) x-iteratedDeriv m (value W γ a) x| ≤ C*|b-a| := by + rw [← compactRate_integral_derivative W γ hT0 hT1 ha hab hb m x] + simpa only [Real.norm_eq_abs] using intervalIntegral.norm_integral_le_of_norm_le_const + (f := fun t => iteratedDeriv m (compactValueRate W γ T t) x) + (C := (C:ℝ)) (fun t (_ht : t ∈ uIoc a b) => by + simpa only [Real.norm_eq_abs] using hC t x) + refine ⟨C,fun a ha b hb x => ?_⟩ + rcases le_total a b with hab | hba + · exact hh a b ha.1 hab hb.2 x + · simpa only [abs_sub_comm] using hh b a hb.1 hba ha.2 x + +end ZeroTemperatureSK + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKSupport/Foundations/ExpTranslateLocalBound.lean b/lean/OAI/Probability/SKSupport/Foundations/ExpTranslateLocalBound.lean new file mode 100644 index 0000000000000000000000000000000000000000..8b65774c5214fb28834c5dab003b6101a011dfc2 --- /dev/null +++ b/lean/OAI/Probability/SKSupport/Foundations/ExpTranslateLocalBound.lean @@ -0,0 +1,211 @@ +import Mathlib +import OAI.Probability.SKSupport.Foundations.Semigroup + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology ContDiff +noncomputable section +namespace ZeroTemperatureSK.Heat + +lemma exp_translate_local_bound {f : ℝ → ℝ} {K : ℝ≥0} + (hf : LipschitzWith K f) {c : ℝ} (hc : 0 ≤ c) (x z y : ℝ) + (hz : |z-x| ≤ 1) : + Real.exp (c*f (z+y)) ≤ + Real.exp (c*f x+c*(K:ℝ))*Real.exp ((c*(K:ℝ))*|y|) := by + rw [← Real.exp_add] + apply Real.exp_le_exp.mpr + have hfz := hf.norm_sub_le (z+y) x + simp only [Real.norm_eq_abs] at hfz + have hz' : |z+y-x| ≤ 1+|y| := by + have he : z+y-x = (z-x)+y := by ring + rw [he] + exact (abs_add_le _ _).trans (by linarith) + have h₁ := mul_le_mul_of_nonneg_left hz' K.coe_nonneg + have h₂ := (le_abs_self (f (z+y)-f x)).trans (hfz.trans h₁) + nlinarith [mul_le_mul_of_nonneg_left h₂ hc] + +lemma hasDerivAt_semigroup_exp {f : ℝ → ℝ} {K : ℝ≥0} + (hf : ContDiff ℝ 1 f) (hLip : LipschitzWith K f) {c : ℝ} (hc : 0 ≤ c) + (h : ℝ≥0) (x : ℝ) : + HasDerivAt (semigroup h (fun z => Real.exp (c*f z))) + (∫ y, c*deriv f (x+y)*Real.exp (c*f (x+y)) ∂gaussianReal 0 h) x := by + have hdf : Continuous (deriv f) := hf.continuous_deriv (by norm_num) + let bound (y : ℝ) := c*(K:ℝ)*Real.exp (c*f x+c*(K:ℝ))*Real.exp ((c*(K:ℝ))*|y|) + have hb : Integrable bound (gaussianReal 0 h) := + (integrable_exp_abs (c*(K:ℝ)) 0 h).const_mul _ + have hi := integrable_exp_translate_of_lipschitz hLip c h x + have hm : ∀ᶠ z in 𝓝 x, + AEStronglyMeasurable (fun y => Real.exp (c*f (z+y))) (gaussianReal 0 h) := + Filter.Eventually.of_forall (fun z => by + exact (measurable_const.mul (hf.continuous.measurable.comp + (measurable_const.add measurable_id))).exp.aestronglyMeasurable) + have hdm : AEStronglyMeasurable + (fun y => c*deriv f (x+y)*Real.exp (c*f (x+y))) (gaussianReal 0 h) := by + exact ((measurable_const.mul (hdf.measurable.comp (measurable_const.add measurable_id))).mul + (measurable_const.mul (hf.continuous.measurable.comp + (measurable_const.add measurable_id))).exp).aestronglyMeasurable + have hbound : ∀ᵐ y ∂gaussianReal 0 h, ∀ z ∈ Metric.ball x 1, + ‖c*deriv f (z+y)*Real.exp (c*f (z+y))‖ ≤ bound y := by + filter_upwards [] with y z hz + have hz' : |z-x| ≤ 1 := by simpa only [Metric.mem_ball, Real.dist_eq] using le_of_lt hz + have hD : |deriv f (z+y)| ≤ K := by + simpa only [Real.norm_eq_abs] using norm_deriv_le_of_lipschitz (x₀ := z+y) hLip + rw [Real.norm_eq_abs, abs_mul, abs_mul, abs_of_nonneg hc, + abs_of_pos (Real.exp_pos _)] + change c*|deriv f (z+y)| * Real.exp (c*f (z+y)) ≤ + c*(K:ℝ)*Real.exp (c*f x+c*(K:ℝ))*Real.exp ((c*(K:ℝ))*|y|) + calc + _ ≤ c*(K:ℝ)*Real.exp (c*f (z+y)) := by gcongr + _ ≤ _ := by + have he := mul_le_mul_of_nonneg_left (exp_translate_local_bound hLip hc x z y hz') + (mul_nonneg hc K.coe_nonneg) + simpa only [mul_assoc] using he + have hdiff : ∀ᵐ y ∂gaussianReal 0 h, ∀ z ∈ Metric.ball x 1, + HasDerivAt (fun w => Real.exp (c*f (w+y))) + (c*deriv f (z+y)*Real.exp (c*f (z+y))) z := by + filter_upwards [] with y z hz + have h1 : HasDerivAt (fun w => f (w+y)) (deriv f (z+y)) z := by + convert (hf.differentiable (by norm_num) (z+y)).hasDerivAt.comp z + ((hasDerivAt_id z).add_const y) using 1 <;> first | rfl | simp + have h2 := (h1.const_mul c).exp + convert h2 using 1 + ring + exact (hasDerivAt_integral_of_dominated_loc_of_deriv_le + (Metric.ball_mem_nhds x (by norm_num : (0:ℝ)<1)) hm hi hdm hbound hb hdiff).2 + +lemma hasDerivAt_logSemigroup {f : ℝ → ℝ} {K : ℝ≥0} + (hf : ContDiff ℝ 1 f) (hLip : LipschitzWith K f) {c : ℝ} (hc : 0 < c) + (h : ℝ≥0) (x : ℝ) : + HasDerivAt (logSemigroup c h f) + ((∫ y, deriv f (x+y)*Real.exp (c*f (x+y)) ∂gaussianReal 0 h) / + semigroup h (fun z => Real.exp (c*f z)) x) x := by + have hd := hasDerivAt_semigroup_exp hf hLip hc.le h x + have he : (∫ y, c*deriv f (x+y)*Real.exp (c*f (x+y)) ∂gaussianReal 0 h) = + c*(∫ y, deriv f (x+y)*Real.exp (c*f (x+y)) ∂gaussianReal 0 h) := by + rw [← integral_const_mul] + apply integral_congr_ae + filter_upwards [] with y + ring + rw [he] at hd + have hh := ((hd.log (ne_of_gt (semigroup_exp_pos hLip c h x))).div_const c) + have hfun : logSemigroup c h f = fun z => + Real.log (semigroup h (fun w => Real.exp (c*f w)) z)/c := by + funext z + simp only [logSemigroup, ne_of_gt hc, ↓reduceIte] + rw [hfun] + convert hh using 1 + first | rfl | field_simp [ne_of_gt hc] + +end ZeroTemperatureSK.Heat + +namespace ZeroTemperatureSK.Heat + +lemma integrable_weight_exp_translate {f g : ℝ → ℝ} {K G : ℝ≥0} + (hf : LipschitzWith K f) (hg : Measurable g) (hG : ∀ z, |g z| ≤ G) + (c : ℝ) (h : ℝ≥0) (x : ℝ) : + Integrable (fun y => g (x+y)*Real.exp (c*f (x+y))) (gaussianReal 0 h) := by + apply (integrable_exp_translate_of_lipschitz hf c h x).bdd_mul + (hg.comp (measurable_const.add measurable_id)).aestronglyMeasurable + filter_upwards [] with y + change ‖g (x+y)‖ ≤ (G:ℝ) + simpa only [Real.norm_eq_abs] using hG (x+y) + +lemma hasDerivAt_semigroup_weight_exp {f g : ℝ → ℝ} {K G G₁ : ℝ≥0} + (hf : ContDiff ℝ 1 f) (hLip : LipschitzWith K f) + (hg : ContDiff ℝ 1 g) (hG : ∀ z, |g z| ≤ G) (hG₁ : ∀ z, |deriv g z| ≤ G₁) + {c : ℝ} (hc : 0 ≤ c) (h : ℝ≥0) (x : ℝ) : + HasDerivAt (semigroup h (fun z => g z*Real.exp (c*f z))) + (∫ y, (deriv g (x+y)+c*g (x+y)*deriv f (x+y))*Real.exp (c*f (x+y)) + ∂gaussianReal 0 h) x := by + have hdf : Continuous (deriv f) := hf.continuous_deriv_one + have hdg : Continuous (deriv g) := hg.continuous_deriv_one + let C : ℝ := (G₁:ℝ)+c*(G:ℝ)*(K:ℝ) + have hC : 0 ≤ C := by dsimp only [C]; positivity + let bound (y : ℝ) := C*Real.exp (c*f x+c*(K:ℝ))*Real.exp ((c*(K:ℝ))*|y|) + have hb : Integrable bound (gaussianReal 0 h) := + (integrable_exp_abs (c*(K:ℝ)) 0 h).const_mul _ + have hi := integrable_weight_exp_translate hLip hg.continuous.measurable hG c h x + have hm : ∀ᶠ z in 𝓝 x, AEStronglyMeasurable + (fun y => g (z+y)*Real.exp (c*f (z+y))) (gaussianReal 0 h) := by + filter_upwards [] with z + exact ((hg.continuous.measurable.comp (measurable_const.add measurable_id)).mul + ((measurable_const.mul (hf.continuous.measurable.comp + (measurable_const.add measurable_id))).exp)).aestronglyMeasurable + have hdm : AEStronglyMeasurable (fun y => + (deriv g (x+y)+c*g (x+y)*deriv f (x+y))*Real.exp (c*f (x+y))) (gaussianReal 0 h) := by + exact ((hdg.measurable.comp (measurable_const.add measurable_id)).add + ((measurable_const.mul (hg.continuous.measurable.comp (measurable_const.add measurable_id))).mul + (hdf.measurable.comp (measurable_const.add measurable_id))) |>.mul + ((measurable_const.mul (hf.continuous.measurable.comp + (measurable_const.add measurable_id))).exp)).aestronglyMeasurable + have hbound : ∀ᵐ y ∂gaussianReal 0 h, ∀ z ∈ Metric.ball x 1, + ‖(deriv g (z+y)+c*g (z+y)*deriv f (z+y))*Real.exp (c*f (z+y))‖ ≤ bound y := by + filter_upwards [] with y z hz + have hz' : |z-x| ≤ 1 := by simpa only [Metric.mem_ball, Real.dist_eq] using le_of_lt hz + have hD : |deriv f (z+y)| ≤ K := by + simpa only [Real.norm_eq_abs] using norm_deriv_le_of_lipschitz (x₀ := z+y) hLip + have hw : |deriv g (z+y)+c*g (z+y)*deriv f (z+y)| ≤ C := by + calc + _ ≤ |deriv g (z+y)|+|c*g (z+y)*deriv f (z+y)| := abs_add_le _ _ + _ = |deriv g (z+y)|+c*|g (z+y)| * |deriv f (z+y)| := by + rw [abs_mul, abs_mul, abs_of_nonneg hc] + _ ≤ C := by dsimp only [C]; gcongr; exact hG₁ _; exact hG _ + rw [Real.norm_eq_abs, abs_mul, abs_of_pos (Real.exp_pos _)] + calc + _ ≤ C*Real.exp (c*f (z+y)) := mul_le_mul_of_nonneg_right hw (Real.exp_nonneg _) + _ ≤ bound y := by + have he := mul_le_mul_of_nonneg_left (exp_translate_local_bound hLip hc x z y hz') hC + simpa only [bound, mul_assoc] using he + have hdiff : ∀ᵐ y ∂gaussianReal 0 h, ∀ z ∈ Metric.ball x 1, + HasDerivAt (fun w => g (w+y)*Real.exp (c*f (w+y))) + ((deriv g (z+y)+c*g (z+y)*deriv f (z+y))*Real.exp (c*f (z+y))) z := by + filter_upwards [] with y z hz + have h1 : HasDerivAt (fun w => f (w+y)) (deriv f (z+y)) z := by + convert (hf.differentiable (by norm_num) (z+y)).hasDerivAt.comp z + ((hasDerivAt_id z).add_const y) using 1 <;> first | rfl | simp + have h2 : HasDerivAt (fun w => g (w+y)) (deriv g (z+y)) z := by + convert (hg.differentiable (by norm_num) (z+y)).hasDerivAt.comp z + ((hasDerivAt_id z).add_const y) using 1 <;> first | rfl | simp + convert h2.mul (h1.const_mul c).exp using 1 + first | rfl | ring + exact (hasDerivAt_integral_of_dominated_loc_of_deriv_le + (Metric.ball_mem_nhds x (by norm_num : (0:ℝ)<1)) hm hi hdm hbound hb hdiff).2 + +lemma hasDerivAt_semigroup {f : ℝ → ℝ} {K : ℝ≥0} + (hf : ContDiff ℝ 1 f) (hLip : LipschitzWith K f) (h : ℝ≥0) (x : ℝ) : + HasDerivAt (semigroup h f) (semigroup h (deriv f) x) x := by + have hdf : Continuous (deriv f) := hf.continuous_deriv_one + have hm : ∀ᶠ z in 𝓝 x, AEStronglyMeasurable (fun y => f (z+y)) (gaussianReal 0 h) := + Filter.Eventually.of_forall (fun z => (hf.continuous.measurable.comp + (measurable_const.add measurable_id)).aestronglyMeasurable) + have hdm : AEStronglyMeasurable (fun y => deriv f (x+y)) (gaussianReal 0 h) := + (hdf.measurable.comp (measurable_const.add measurable_id)).aestronglyMeasurable + have hbound : ∀ᵐ y ∂gaussianReal 0 h, ∀ z ∈ Metric.ball x 1, + ‖deriv f (z+y)‖ ≤ (K:ℝ) := by + filter_upwards [] with y z hz + exact norm_deriv_le_of_lipschitz hLip + have hdiff : ∀ᵐ y ∂gaussianReal 0 h, ∀ z ∈ Metric.ball x 1, + HasDerivAt (fun w => f (w+y)) (deriv f (z+y)) z := by + filter_upwards [] with y z hz + convert (hf.differentiable (by norm_num) (z+y)).hasDerivAt.comp z + ((hasDerivAt_id z).add_const y) using 1 <;> first | rfl | simp + exact (hasDerivAt_integral_of_dominated_loc_of_deriv_le + (Metric.ball_mem_nhds x (by norm_num : (0:ℝ)<1)) hm + (integrable_translate_of_lipschitz hLip h x) hdm hbound (integrable_const _) hdiff).2 + +end ZeroTemperatureSK.Heat + +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKSupport/Foundations/ExpectedVerificationStep.lean b/lean/OAI/Probability/SKSupport/Foundations/ExpectedVerificationStep.lean new file mode 100644 index 0000000000000000000000000000000000000000..9712d4be03309ccb3a9395f72c16aaebbe3f0ca9 --- /dev/null +++ b/lean/OAI/Probability/SKSupport/Foundations/ExpectedVerificationStep.lean @@ -0,0 +1,91 @@ +import Mathlib +import OAI.Probability.SKSupport.Regularity.TimeStepBound +import OAI.Probability.SKSupport.Diffusion.StepDrift + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section +namespace ZeroTemperatureSK.WeakIto +variable {Ω : Type*} [MeasurableSpace Ω] {P : Measure Ω} {B : ℝ≥0 → Ω → ℝ} + +lemma expected_verification_step (hB : IsPreBrownianReal B P) + (hm : ∀ t, Measurable (B t)) (s h c : ℝ≥0) {Y : Ω → ℝ} + (hY : Measurable[Filtration.natural B (fun t => (hm t).stronglyMeasurable) s] Y) + (hYi : Integrable Y P) {α : ℝ → Ω → ℝ} + (hαm : Measurable (fun p : ℝ × Ω => α p.1 p.2)) (hαb : ∀ r ω, |α r ω| ≤ 1) + {F D : ℝ → ℝ → ℝ} (hf : ∀ t, ContDiff ℝ 3 (F t)) + (C₁ C₂ C₃ Ct L : ℝ≥0) (hC₁ : ∀ t x, |deriv (F t) x| ≤ C₁) + (hC₂ : ∀ t x, |deriv (deriv (F t)) x| ≤ C₂) + (hC₃ : ∀ t x, |iteratedDeriv 3 (F t) x| ≤ C₃) + (hDm : Measurable (D s)) (hCt : ∀ x, |D s x| ≤ Ct) + (hD : ∀ r ∈ Set.Icc (s:ℝ) ((s:ℝ)+(h:ℝ)), ∀ z, + HasDerivWithinAt (fun t => F t z) (D r z) + (Set.Icc (s:ℝ) ((s:ℝ)+(h:ℝ))) r) + (hL : ∀ r ∈ Set.Icc (s:ℝ) ((s:ℝ)+(h:ℝ)), ∀ z x, + |D r z-D s x| ≤ (L:ℝ)*(|r-(s:ℝ)|+|z-x|)) + (hPDE : ∀ x, D s x + (1/2:ℝ)*deriv (deriv (F s)) x + + (c:ℝ)/2*(deriv (F s) x)^2 = 0) : + (∫ ω, F ((s:ℝ)+(h:ℝ)) (Y ω+(B (s+h) ω-B s ω)+stepDrift α s h c ω) ∂P) - + (∫ ω, F s (Y ω) ∂P) - (∫ ω, stepCost α s h c ω ∂P) ≤ + (C₃:ℝ)/6 * ((h:ℝ)*Real.sqrt (h:ℝ)*normalThirdMoment) + + (C₂:ℝ)*(c:ℝ)*(h:ℝ) * (Real.sqrt (h:ℝ)*normalFirstMoment + (c:ℝ)*(h:ℝ)) + + (L:ℝ)*(h:ℝ) * ((h:ℝ) + Real.sqrt (h:ℝ)*normalFirstMoment + (c:ℝ)*(h:ℝ)) := by + let := hB.isGaussianProcess.isProbabilityMeasure + have hYm := hY.mono + ((Filtration.natural B (fun t => (hm t).stronglyMeasurable)).le s) le_rfl + have hAm := stepDrift_measurable hαm s h c h.coe_nonneg + have hAi := stepDrift_integrable (P := P) hαm hαb s h c h.coe_nonneg c.coe_nonneg + have hKi := stepCost_integrable (P := P) hαm hαb s h c h.coe_nonneg c.coe_nonneg + have hG := expected_time_space_step hB hm s h hY hYi hAm c + (stepDrift_bound hαb s h c h.coe_nonneg c.coe_nonneg) hf + C₁ C₂ C₃ Ct L hC₁ hC₂ hC₃ hDm hCt hD hL + have hfd : ContDiff ℝ 2 (deriv (F s)) := (hf s).deriv' + have hfm : Measurable (fun ω => deriv (F s) (Y ω)) := hfd.continuous.measurable.comp hYm + have hfi : Integrable (fun ω => deriv (F s) (Y ω)*stepDrift α s h c ω) P := + hAi.bdd_mul hfm.aestronglyMeasurable (Filter.Eventually.of_forall (fun ω => by + simpa only [Real.norm_eq_abs] using hC₁ s (Y ω))) + have hdi : Integrable (fun ω => D s (Y ω)) P := Integrable.of_bound + (hDm.comp hYm).aestronglyMeasurable Ct (Filter.Eventually.of_forall (fun ω => by + simpa only [Real.norm_eq_abs] using hCt (Y ω))) + have hfdd : ContDiff ℝ 1 (deriv (deriv (F s))) := hfd.deriv' + have hddi : Integrable (fun ω => deriv (deriv (F s)) (Y ω)) P := Integrable.of_bound + (hfdd.continuous.measurable.comp hYm).aestronglyMeasurable C₂ + (Filter.Eventually.of_forall (fun ω => by simpa only [Real.norm_eq_abs] using hC₂ s (Y ω))) + let H (ω : Ω) := deriv (F s) (Y ω)*stepDrift α s h c ω-stepCost α s h c ω + + (h:ℝ)*(D s (Y ω)+(1/2:ℝ)*deriv (deriv (F s)) (Y ω)) + have hH : (∫ ω, H ω ∂P) ≤ 0 := by + apply integral_nonpos_of_ae + filter_upwards [] with ω + have hsq := step_completion_square hαm hαb s h c h.coe_nonneg c.coe_nonneg + (deriv (F s) (Y ω)) ω + have he := congrArg (fun z : ℝ => (h:ℝ)*z) (hPDE (Y ω)) + change H ω ≤ 0 + dsimp only [H] + nlinarith + have hsub : Integrable (fun ω => deriv (F s) (Y ω)*stepDrift α s h c ω- + stepCost α s h c ω) P := hfi.sub hKi + have hadd : Integrable (fun ω => D s (Y ω)+(1/2:ℝ)*deriv (deriv (F s)) (Y ω)) P := + hdi.add (hddi.const_mul _) + dsimp only [H] at hH + rw [integral_add hsub (hadd.const_mul _), integral_sub hfi hKi, + integral_const_mul, integral_add hdi (hddi.const_mul _), integral_const_mul] at hH + have ha := le_abs_self + ((∫ ω, F ((s:ℝ)+(h:ℝ)) (Y ω+(B (s+h) ω-B s ω)+stepDrift α s h c ω) ∂P) - + (∫ ω, F s (Y ω) ∂P) - + (∫ ω, deriv (F s) (Y ω)*stepDrift α s h c ω ∂P) - + (h:ℝ)*((∫ ω, D s (Y ω) ∂P)+(1/2:ℝ)*(∫ ω, deriv (deriv (F s)) (Y ω) ∂P))) + linarith + +end ZeroTemperatureSK.WeakIto + +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKSupport/Foundations/ExponentialBoundLipschitz.lean b/lean/OAI/Probability/SKSupport/Foundations/ExponentialBoundLipschitz.lean new file mode 100644 index 0000000000000000000000000000000000000000..c69acf8c403ff9c28aa1fc50237f7068ae52ba85 --- /dev/null +++ b/lean/OAI/Probability/SKSupport/Foundations/ExponentialBoundLipschitz.lean @@ -0,0 +1,230 @@ +import Mathlib +import OAI.Probability.SKSupport.Foundations.VarianceHeat + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology ContDiff +noncomputable section +namespace ZeroTemperatureSK.Heat + +lemma exponentialBound_of_lipschitz {f : ℝ → ℝ} {K : ℝ≥0} (hf : LipschitzWith K f) : + ExponentialBound f := by + refine ⟨Real.nnabs (f 0)+K, 1, fun z => ?_⟩ + have hl := hf.norm_sub_le z 0 + have ht := norm_add_le (f z-f 0) (f 0) + simp only [sub_zero, sub_add_cancel, Real.norm_eq_abs] at hl ht + have he : |z| ≤ Real.exp |z| := by linarith [Real.add_one_le_exp |z|] + have he1 : 1 ≤ Real.exp |z| := Real.one_le_exp (abs_nonneg z) + simp only [NNReal.coe_add, Real.coe_nnabs, NNReal.coe_one, one_mul] + nlinarith [mul_le_mul_of_nonneg_left he K.coe_nonneg, + mul_le_mul_of_nonneg_left he1 (abs_nonneg (f 0))] + +lemma exponentialBound_exp {f : ℝ → ℝ} {K : ℝ≥0} (hf : LipschitzWith K f) (c : ℝ) : + ExponentialBound (fun z => Real.exp (c*f z)) := by + refine ⟨⟨Real.exp (c*f 0), (Real.exp_pos _).le⟩, Real.nnabs c*K, fun z => ?_⟩ + rw [abs_of_pos (Real.exp_pos _)] + change Real.exp (c*f z) ≤ Real.exp (c*f 0)*Real.exp ((|c| *(K:ℝ))*|z|) + rw [← Real.exp_add] + apply Real.exp_le_exp.mpr + have hl := hf.norm_sub_le z 0 + simp only [sub_zero, Real.norm_eq_abs] at hl + have h₁ : c*(f z-f 0) ≤ |c| *|f z-f 0| := by + exact (le_abs_self _).trans_eq (abs_mul _ _) + nlinarith [mul_le_mul_of_nonneg_left hl (abs_nonneg c)] + +lemma ExponentialBound.bdd_mul {f g : ℝ → ℝ} (hf : ExponentialBound f) + {G : ℝ≥0} (hg : ∀ z, |g z| ≤ G) : ExponentialBound (fun z => g z*f z) := by + obtain ⟨A,K,hf⟩ := hf + refine ⟨G*A, K, fun z => ?_⟩ + rw [abs_mul] + have hh := mul_le_mul (hg z) (hf z) (abs_nonneg (f z)) G.coe_nonneg + simpa only [NNReal.coe_mul, mul_assoc] using hh + +lemma hasDerivAt_weightExp {f g : ℝ → ℝ} (hf : RegularDatum f) (hg : BoundedSmooth g) + (c x : ℝ) : HasDerivAt (fun z => g z*Real.exp (c*f z)) + ((deriv g x+c*g x*deriv f x)*Real.exp (c*f x)) x := by + have hfd := (hf.smooth.differentiable (by simp) x).hasDerivAt + have hgd := (hg.smooth.differentiable (by simp) x).hasDerivAt + convert hgd.mul (hfd.const_mul c).exp using 1 + first | rfl | ring + +lemma deriv_weightExp {f g : ℝ → ℝ} (hf : RegularDatum f) (hg : BoundedSmooth g) (c : ℝ) : + deriv (fun z => g z*Real.exp (c*f z)) = fun x => + (deriv g x+c*g x*deriv f x)*Real.exp (c*f x) := + funext (fun x => (hasDerivAt_weightExp hf hg c x).deriv) + +lemma exp_iteratedDeriv_weight {f : ℝ → ℝ} (hf : RegularDatum f) (c : ℝ) (n : ℕ) : + ∃ g : ℝ → ℝ, BoundedSmooth g ∧ + iteratedDeriv n (fun z => Real.exp (c*f z)) = fun z => g z*Real.exp (c*f z) := by + induction n with + | zero => exact ⟨fun _ => 1, BoundedSmooth.const 1, by funext z; simp⟩ + | succ n IH => + obtain ⟨g,hg,he⟩ := IH + exact ⟨fun z => deriv g z+c*g z*deriv f z, weighted_derivative_boundedSmooth hf hg c, + by rw [iteratedDeriv_succ, he, deriv_weightExp hf hg c]⟩ + +lemma exponentialBound_exp_iteratedDeriv {f : ℝ → ℝ} {K : ℝ≥0} + (hf : RegularDatum f) (hLip : LipschitzWith K f) (c : ℝ) (n : ℕ) : + ExponentialBound (iteratedDeriv n (fun z => Real.exp (c*f z))) := by + obtain ⟨g,hg,he⟩ := exp_iteratedDeriv_weight hf c n + obtain ⟨G,hG⟩ := hg.bound + rw [he] + exact (exponentialBound_exp hLip c).bdd_mul hG + +lemma hasDerivWithinAt_varianceHeat_exp {f : ℝ → ℝ} {K : ℝ≥0} + (hf : RegularDatum f) (hLip : LipschitzWith K f) (c : ℝ) + {t : ℝ} (ht : 0 ≤ t) (x : ℝ) : + HasDerivWithinAt (fun s => varianceHeat s (fun z => Real.exp (c*f z)) x) + ((1/2:ℝ)*varianceHeat t (deriv (deriv (fun z => Real.exp (c*f z)))) x) + (Set.Ici 0) t := by + apply hasDerivWithinAt_varianceHeat + ((contDiff_const.mul hf.smooth).exp.of_le (ENat.natCast_le_of_coe_top_le_withTop le_rfl 2)) (exponentialBound_exp hLip c) + (by simpa only [iteratedDeriv_one] using exponentialBound_exp_iteratedDeriv hf hLip c 1) + (by simpa only [iteratedDeriv_succ, iteratedDeriv_one, iteratedDeriv_zero] using exponentialBound_exp_iteratedDeriv hf hLip c 2) + ht x + +end ZeroTemperatureSK.Heat + +namespace ZeroTemperatureSK.Heat + +lemma hasDerivAt_scaled_space {g : ℝ → ℝ} (hgc : ContDiff ℝ 1 g) + (hg : ExponentialBound g) (hg' : ExponentialBound (deriv g)) (a x : ℝ) : + HasDerivAt (scaled a g) (scaled a (deriv g) x) x := by + obtain ⟨A,K,hg'⟩ := hg' + have hdm := hgc.continuous_deriv_one.measurable + have hm : ∀ᶠ z in 𝓝 x, AEStronglyMeasurable (fun y => g (z+a*y)) (gaussianReal 0 1) := + Filter.Eventually.of_forall (fun z => by fun_prop) + have hdmeas : AEStronglyMeasurable (fun y => deriv g (x+a*y)) (gaussianReal 0 1) := by fun_prop + have hb : ∀ᵐ y ∂gaussianReal 0 1, ∀ z ∈ Metric.ball x 1, + ‖deriv g (z+a*y)‖ ≤ + ((A:ℝ)*Real.exp ((K:ℝ)*(|x|+1)))*Real.exp (((K:ℝ)*|a|)*|y|) := by + filter_upwards [] with y z hz + have hz' : |z| ≤ |x|+1 := by + have ht := abs_add_le (z-x) x + rw [sub_add_cancel] at ht + have hd : |z-x| < 1 := by simpa only [Metric.mem_ball, Real.dist_eq] using hz + linarith + rw [Real.norm_eq_abs] + exact (exponentialBound_scaled hg' z a y |a| le_rfl).trans (by gcongr) + have hD : ∀ᵐ y ∂gaussianReal 0 1, ∀ z ∈ Metric.ball x 1, + HasDerivAt (fun w => g (w+a*y)) (deriv g (z+a*y)) z := by + filter_upwards [] with y z hz + convert (hgc.differentiable (by norm_num) (z+a*y)).hasDerivAt.comp z + ((hasDerivAt_id z).add_const (a*y)) using 1 <;> first | rfl | simp + exact (hasDerivAt_integral_of_dominated_loc_of_deriv_le + (Metric.ball_mem_nhds x (show (0:ℝ)<1 by norm_num)) hm + (integrable_scaled_of_expBound hgc.continuous.measurable hg a x) hdmeas hb + ((integrable_exp_abs ((K:ℝ)*|a|) 0 1).const_mul _) hD).2 + +lemma deriv_varianceHeat {g : ℝ → ℝ} (hgc : ContDiff ℝ 1 g) + (hg : ExponentialBound g) (hg' : ExponentialBound (deriv g)) (t : ℝ) : + deriv (varianceHeat t g) = varianceHeat t (deriv g) := + funext (fun x => (hasDerivAt_scaled_space hgc hg hg' (Real.sqrt t) x).deriv) + +lemma deriv_deriv_varianceHeat {g : ℝ → ℝ} (hgc : ContDiff ℝ 2 g) + (hg : ExponentialBound g) (hg' : ExponentialBound (deriv g)) + (hg'' : ExponentialBound (deriv (deriv g))) (t : ℝ) : + deriv (deriv (varianceHeat t g)) = varianceHeat t (deriv (deriv g)) := by + rw [deriv_varianceHeat (hgc.of_le (by norm_num)) hg hg', + deriv_varianceHeat (show ContDiff ℝ 1 (deriv g) from hgc.deriv') hg' hg''] + +lemma varianceHeat_equation {g : ℝ → ℝ} (hgc : ContDiff ℝ 2 g) + (hg : ExponentialBound g) (hg' : ExponentialBound (deriv g)) + (hg'' : ExponentialBound (deriv (deriv g))) {t : ℝ} (ht : 0 ≤ t) (x : ℝ) : + HasDerivWithinAt (fun s => varianceHeat s g x) + ((1/2:ℝ)*deriv (deriv (varianceHeat t g)) x) (Set.Ici 0) t := by + rw [deriv_deriv_varianceHeat hgc hg hg' hg''] + exact hasDerivWithinAt_varianceHeat hgc hg hg' hg'' ht x + +end ZeroTemperatureSK.Heat + +namespace ZeroTemperatureSK.Heat + +lemma logarithmic_heat_equation {g : ℝ → ℝ} (hgc : ContDiff ℝ 2 g) + (hg : ExponentialBound g) (hg' : ExponentialBound (deriv g)) + (hg'' : ExponentialBound (deriv (deriv g))) {c : ℝ} (hc : c ≠ 0) + {t : ℝ} (ht : 0 ≤ t) (hpos : ∀ z, 0 < varianceHeat t g z) (x : ℝ) : + HasDerivWithinAt (fun s => Real.log (varianceHeat s g x)/c) + ((1/2:ℝ)*deriv (deriv (fun z => Real.log (varianceHeat t g z)/c)) x + + c/2*(deriv (fun z => Real.log (varianceHeat t g z)/c) x)^2) + (Set.Ici 0) t := by + have hdx (z : ℝ) : HasDerivAt (varianceHeat t g) (varianceHeat t (deriv g) z) z := + hasDerivAt_scaled_space (hgc.of_le (by norm_num)) hg hg' (Real.sqrt t) z + have hddx (z : ℝ) : HasDerivAt (varianceHeat t (deriv g)) + (varianceHeat t (deriv (deriv g)) z) z := + hasDerivAt_scaled_space (show ContDiff ℝ 1 (deriv g) from hgc.deriv') hg' hg'' (Real.sqrt t) z + have hdf : deriv (fun z => Real.log (varianceHeat t g z)/c) = + fun z => (varianceHeat t (deriv g) z/varianceHeat t g z)/c := by + funext z + exact ((hdx z).log (ne_of_gt (hpos z)) |>.div_const c).deriv + have hdd := ((hddx x).div (hdx x) (ne_of_gt (hpos x))).div_const c + simp only [Pi.div_apply] at hdd + have htime := ((hasDerivWithinAt_varianceHeat hgc hg hg' hg'' ht x).log + (ne_of_gt (hpos x))).div_const c + apply htime.congr_deriv + rw [hdf, hdd.deriv] + field_simp [hc, ne_of_gt (hpos x)] + ring + +def varianceLogHeat (c t : ℝ) (f : ℝ → ℝ) (x : ℝ) := + if c = 0 then varianceHeat t f x else Real.log (varianceHeat t (fun z => Real.exp (c*f z)) x)/c + +lemma varianceLogHeat_eq_logSemigroup {f : ℝ → ℝ} (hfm : Measurable f) (c : ℝ) + (h : ℝ≥0) (x : ℝ) : varianceLogHeat c h f x = logSemigroup c h f x := by + by_cases hc : c = 0 + · simp only [varianceLogHeat, logSemigroup, hc, ↓reduceIte] + exact varianceHeat_eq_semigroup hfm h x + · simp only [varianceLogHeat, logSemigroup, hc, ↓reduceIte] + have hem : Measurable (fun z => Real.exp (c*f z)) := (measurable_const.mul hfm).exp + rw [varianceHeat_eq_semigroup hem h x] + +lemma varianceHeat_exp_pos {f : ℝ → ℝ} {K : ℝ≥0} (hf : LipschitzWith K f) + (c t x : ℝ) : 0 < varianceHeat t (fun z => Real.exp (c*f z)) x := by + unfold varianceHeat scaled + exact integral_pos_iff_support_of_nonneg (fun y => (Real.exp_pos _).le) + (integrable_scaled_of_expBound (measurable_const.mul hf.continuous.measurable |>.exp) + (exponentialBound_exp hf c) (Real.sqrt t) x) |>.mpr (by simp [Function.support]) + +lemma varianceLogHeat_equation {f : ℝ → ℝ} {K : ℝ≥0} + (hf : RegularDatum f) (hLip : LipschitzWith K f) (c : ℝ) {t : ℝ} (ht : 0 ≤ t) (x : ℝ) : + HasDerivWithinAt (fun s => varianceLogHeat c s f x) + ((1/2:ℝ)*deriv (deriv (varianceLogHeat c t f)) x + + c/2*(deriv (varianceLogHeat c t f) x)^2) (Set.Ici 0) t := by + by_cases hc : c = 0 + · subst c + have he : (fun s => varianceLogHeat 0 s f x) = fun s => varianceHeat s f x := by + funext s; simp [varianceLogHeat] + have he' : varianceLogHeat 0 t f = varianceHeat t f := by funext z; simp [varianceLogHeat] + rw [he, he'] + simp only [zero_div, zero_mul, add_zero] + obtain ⟨C,hC⟩ := hf.deriv_bounded.bound + obtain ⟨C',hC'⟩ := hf.deriv_bounded.deriv.bound + exact varianceHeat_equation (hf.smooth.of_le (ENat.natCast_le_of_coe_top_le_withTop le_rfl 2)) (exponentialBound_of_lipschitz hLip) + (ExponentialBound.of_bounded hC) (ExponentialBound.of_bounded hC') ht x + · have he : (fun s => varianceLogHeat c s f x) = fun s => + Real.log (varianceHeat s (fun z => Real.exp (c*f z)) x)/c := by funext s; simp [varianceLogHeat, hc] + have he' : varianceLogHeat c t f = fun z => + Real.log (varianceHeat t (fun y => Real.exp (c*f y)) z)/c := by funext z; simp [varianceLogHeat, hc] + rw [he, he'] + exact logarithmic_heat_equation ((contDiff_const.mul hf.smooth).exp.of_le (ENat.natCast_le_of_coe_top_le_withTop le_rfl 2)) + (exponentialBound_exp hLip c) + (by simpa only [iteratedDeriv_one] using exponentialBound_exp_iteratedDeriv hf hLip c 1) + (by simpa only [iteratedDeriv_succ, iteratedDeriv_one, iteratedDeriv_zero] using exponentialBound_exp_iteratedDeriv hf hLip c 2) + hc ht (varianceHeat_exp_pos hLip c t) x + +end ZeroTemperatureSK.Heat + +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKSupport/Foundations/Finite.lean b/lean/OAI/Probability/SKSupport/Foundations/Finite.lean new file mode 100644 index 0000000000000000000000000000000000000000..ccfb345b388fda7769e9a2aa6e5a4f1de01dde7a --- /dev/null +++ b/lean/OAI/Probability/SKSupport/Foundations/Finite.lean @@ -0,0 +1,170 @@ +import Mathlib +import OAI.Probability.SKSupport.Foundations.FiniteValue + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology ContDiff +noncomputable section +namespace ZeroTemperatureSK.Heat + +lemma finiteValue_tail_of_le {f : ℝ → ℝ} (hf : RegularDatum f) + (hLip : LipschitzWith 1 f) (c : ℕ → ℝ≥0) (h : ℝ≥0) (N i : ℕ) {t : ℝ} + (ht : (h:ℝ) ≤ t) : finiteValue c h f (N+1) i t = finiteValue c h f N (i+1) (t-h) := by + rcases lt_or_eq_of_le ht with ht|rfl + · exact finiteValue_tail f c h N i ht + · rw [finiteValue_head f c h N i le_rfl,sub_self,finiteValue_zero hf hLip] + funext x + exact backward_terminal _ _ _ _ + +def finiteSource (c : ℕ → ℝ≥0) (h : ℝ≥0) (f : ℝ → ℝ) (N i : ℕ) (t x : ℝ) : ℝ := + finiteCoeff c h N i t*(deriv (finiteValue c h f N i t) x)^2 + +lemma measurable_finiteSource {f : ℝ → ℝ} (hf : RegularDatum f) + (hLip : LipschitzWith 1 f) (c : ℕ → ℝ≥0) (h : ℝ≥0) (N i : ℕ) : + Measurable (fun p : ℝ × ℝ => finiteSource c h f N i p.1 p.2) := by + exact ((measurable_finiteCoeff c h N i).comp measurable_fst).mul + ((measurable_spatial_deriv (measurable_finiteValue hf hLip c h N i) + (fun r => (finiteValue_regular hf hLip c h N i r).smooth.differentiable (by simp))).pow_const 2) + +lemma finiteSource_bounded {f : ℝ → ℝ} (hLip : LipschitzWith 1 f) + (c : ℕ → ℝ≥0) (h : ℝ≥0) (N i : ℕ) : + ∃ C : ℝ≥0, ∀ t x, |finiteSource c h f N i t x| ≤ C := by + obtain ⟨C,hC⟩ := finiteCoeff_bounds c h N i + refine ⟨C,fun t x => ?_⟩ + have hd : |deriv (finiteValue c h f N i t) x| ≤ 1 := by + simpa only [Real.norm_eq_abs,NNReal.coe_one] using + norm_deriv_le_of_lipschitz (x₀ := x) (finiteValue_lipschitz hLip c h N i t) + rw [finiteSource,abs_mul,abs_pow,abs_of_nonneg (hC t).1] + have hs : |deriv (finiteValue c h f N i t) x|^2 ≤ 1 := by + nlinarith [abs_nonneg (deriv (finiteValue c h f N i t) x)] + nlinarith [(hC t).1,(hC t).2] + +lemma intervalIntegrable_heat_finiteSource {f : ℝ → ℝ} (hf : RegularDatum f) + (hLip : LipschitzWith 1 f) (c : ℕ → ℝ≥0) (h : ℝ≥0) (N i : ℕ) (p a b x : ℝ) : + IntervalIntegrable (fun r => varianceHeat (r-p) (finiteSource c h f N i r) x) volume a b := by + obtain ⟨C,hC⟩ := finiteSource_bounded hLip c h N i + have hm := measurable_varianceHeat_family (measurable_finiteSource hf hLip c h N i) + (measurable_id.sub_const p) + apply (intervalIntegrable_const (c := (C:ℝ))).mono_fun + (hm.comp (measurable_id.prodMk measurable_const)).aestronglyMeasurable + filter_upwards [] with r + simpa only [Function.comp_def,id_eq,Real.norm_eq_abs,abs_of_nonneg C.coe_nonneg] using varianceHeat_abs_le (hC r) (r-p) x + +lemma finiteSource_head (f : ℝ → ℝ) (c : ℕ → ℝ≥0) (h : ℝ≥0) (N i : ℕ) {t : ℝ} + (ht : t ≤ h) : finiteSource c h f (N+1) i t = + fun x => (c i:ℝ)*(deriv (backward (c i) h (cascade c h f N (i+1)) t) x)^2 := by + funext x + rw [finiteSource,finiteValue_head f c h N i ht] + simp only [finiteCoeff,ite_eq_left ht] + +lemma finiteSource_tail (f : ℝ → ℝ) (c : ℕ → ℝ≥0) (h : ℝ≥0) (N i : ℕ) {t : ℝ} + (ht : (h:ℝ) < t) : finiteSource c h f (N+1) i t = finiteSource c h f N (i+1) (t-h) := by + funext x + rw [finiteSource,finiteValue_tail f c h N i ht] + simp only [finiteCoeff,ite_eq_right (not_le.mpr ht),finiteSource] + +lemma integral_heat_finiteSource_tail (f : ℝ → ℝ) (c : ℕ → ℝ≥0) (h : ℝ≥0) + (N i : ℕ) {a b : ℝ} (ha : (h:ℝ) ≤ a) (hab : a ≤ b) (p x : ℝ) : + (∫ r in a..b, varianceHeat (r-p) (finiteSource c h f (N+1) i r) x) = + ∫ r in a-h..b-h, varianceHeat (r-(p-h)) (finiteSource c h f N (i+1) r) x := by + rw [← intervalIntegral.integral_comp_sub_right (f := fun r => varianceHeat (r-(p-h)) + (finiteSource c h f N (i+1) r) x) (h:ℝ)] + apply intervalIntegral.integral_congr_Ioo_of_le hab + intro r hr + dsimp only + rw [finiteSource_tail f c h N i (ha.trans_lt hr.1)] + rw [show r-(h:ℝ)-(p-h) = r-p by ring] + +lemma finiteValue_heat_dual {f : ℝ → ℝ} (hf : RegularDatum f) + (hLip : LipschitzWith 1 f) (c : ℕ → ℝ≥0) (h : ℝ≥0) (N i : ℕ) + {p a b : ℝ} (ha : 0 ≤ a) (hpa : p ≤ a) (hab : a ≤ b) (hb : b ≤ (N:ℝ)*h) (x : ℝ) : + varianceHeat (b-p) (finiteValue c h f N i b) x = + varianceHeat (a-p) (finiteValue c h f N i a) x- + (1/2)*(∫ r in a..b, varianceHeat (r-p) (finiteSource c h f N i r) x) := by + induction N generalizing i p a b with + | zero => + have hb0 : b = 0 := by simp only [Nat.cast_zero,zero_mul] at hb; linarith + have ha0 : a = 0 := by linarith + simp only [ha0,hb0,intervalIntegral.integral_same,mul_zero,sub_zero] + | succ N ih => + by_cases hbh : b ≤ h + · rw [finiteValue_head f c h N i hbh,finiteValue_head f c h N i (hab.trans hbh)] + have hi : (∫ r in a..b, varianceHeat (r-p) (finiteSource c h f (N+1) i r) x) = + (c i:ℝ)*(∫ r in a..b, varianceHeat (r-p) + (fun z => (deriv (backward (c i) h (cascade c h f N (i+1)) r) z)^2) x) := by + rw [← intervalIntegral.integral_const_mul] + apply intervalIntegral.integral_congr_Ioo_of_le hab + intro r hr + dsimp only + rw [finiteSource_head f c h N i (hr.2.le.trans hbh),varianceHeat_const_mul] + rw [hi] + have he := backward_heat_dual (cascade_regular hf hLip c h N (i+1)) + (cascade_lipschitz hLip c h N (i+1)) (c i).coe_nonneg ha hpa hab hbh x + linarith + · have hhb : (h:ℝ) < b := lt_of_not_ge hbh + have hbn : b-h ≤ (N:ℝ)*h := by + push_cast at hb + nlinarith + by_cases hah : (h:ℝ) ≤ a + · rw [finiteValue_tail_of_le hf hLip c h N i hhb.le, + finiteValue_tail_of_le hf hLip c h N i hah, + integral_heat_finiteSource_tail f c h N i hah hab] + have he := ih (i+1) (p := p-h) (a := a-h) (b := b-h) + (sub_nonneg.mpr hah) (by linarith) (by linarith) hbn + rw [show b-(h:ℝ)-(p-h) = b-p by ring, + show a-(h:ℝ)-(p-h) = a-p by ring] at he + exact he + · have hah' : a ≤ h := (lt_of_not_ge hah).le + have hjoin := intervalIntegral.integral_add_adjacent_intervals + (intervalIntegrable_heat_finiteSource hf hLip c h (N+1) i p a h x) + (intervalIntegrable_heat_finiteSource hf hLip c h (N+1) i p h b x) + have hhead := backward_heat_dual (cascade_regular hf hLip c h N (i+1)) + (cascade_lipschitz hLip c h N (i+1)) (c i).coe_nonneg ha hpa hah' le_rfl x + have hihead : (∫ r in a..(h:ℝ), varianceHeat (r-p) (finiteSource c h f (N+1) i r) x) = + (c i:ℝ)*(∫ r in a..(h:ℝ), varianceHeat (r-p) + (fun z => (deriv (backward (c i) h (cascade c h f N (i+1)) r) z)^2) x) := by + rw [← intervalIntegral.integral_const_mul] + apply intervalIntegral.integral_congr_Ioo_of_le hah' + intro r hr + dsimp only + rw [finiteSource_head f c h N i hr.2.le,varianceHeat_const_mul] + have htail := ih (i+1) (p := p-h) (a := 0) (b := b-h) + le_rfl (by linarith) (sub_nonneg.mpr hhb.le) hbn + rw [finiteValue_zero hf hLip] at htail + have hseam : backward (c i) h (cascade c h f N (i+1)) h = cascade c h f N (i+1) := by + funext z; exact backward_terminal _ _ _ _ + rw [hseam] at hhead + rw [finiteValue_tail_of_le hf hLip c h N i hhb.le, + finiteValue_head f c h N i hah',← hjoin,hihead, + integral_heat_finiteSource_tail f c h N i le_rfl hhb.le] + simp only [sub_self] at * + have he1 : b-(h:ℝ)-(p-h) = b-p := by ring + have he2 : 0-(p-(h:ℝ)) = h-p := by ring + rw [he1,he2] at htail + linarith + +lemma finiteValue_mild {f : ℝ → ℝ} (hf : RegularDatum f) + (hLip : LipschitzWith 1 f) (c : ℕ → ℝ≥0) (h : ℝ≥0) (N i : ℕ) + {a b : ℝ} (ha : 0 ≤ a) (hab : a ≤ b) (hb : b ≤ (N:ℝ)*h) (x : ℝ) : + finiteValue c h f N i a x = varianceHeat (b-a) (finiteValue c h f N i b) x+ + (1/2)*(∫ r in a..b, varianceHeat (r-a) (finiteSource c h f N i r) x) := by + have he := finiteValue_heat_dual hf hLip c h N i ha le_rfl hab hb x + rw [sub_self,varianceHeat_zero] at he + linarith + +end ZeroTemperatureSK.Heat + +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKSupport/Foundations/FiniteValue.lean b/lean/OAI/Probability/SKSupport/Foundations/FiniteValue.lean new file mode 100644 index 0000000000000000000000000000000000000000..c61f7e7ff470f7fa0365cd263777011fc5f0db4d --- /dev/null +++ b/lean/OAI/Probability/SKSupport/Foundations/FiniteValue.lean @@ -0,0 +1,195 @@ +import Mathlib +import OAI.Probability.SKSupport.Backward.BackwardGradientSqJointBound +import OAI.Probability.SKSupport.Foundations.MeasurableSpatialDeriv + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology ContDiff +noncomputable section +namespace ZeroTemperatureSK.Heat + +lemma continuousOn_moving_heat_from {F : ℝ → ℝ → ℝ} {L : ℝ≥0} {p l u : ℝ} + (hpl : p ≤ l) (hlu : l ≤ u) (hm : ∀ r, Measurable (F r)) + (hL : ∀ r ∈ Icc l u, ∀ s ∈ Icc l u, ∀ z y, + |F r z-F s y| ≤ (L:ℝ)*(|r-s|+|z-y|)) (x : ℝ) : + ContinuousOn (fun r => varianceHeat (r-p) (F r) x) (Icc l u) := by + apply continuousOn_of_dominated + (bound := fun y : ℝ => |F l x|+(L:ℝ)*((u-l)+Real.sqrt (u-p)*|y|)) + · intro r hr + exact ((hm r).comp (measurable_const.add (measurable_const.mul measurable_id))).aestronglyMeasurable + · intro r hr + filter_upwards [] with y + have hh := hL r hr l ⟨le_rfl,hlu⟩ (x+Real.sqrt (r-p)*y) x + have htri := abs_add_le (F r (x+Real.sqrt (r-p)*y)-F l x) (F l x) + rw [sub_add_cancel] at htri + rw [add_sub_cancel_left,abs_mul,abs_of_nonneg (Real.sqrt_nonneg _),abs_of_nonneg (sub_nonneg.mpr hr.1)] at hh + have hs : Real.sqrt (r-p) ≤ Real.sqrt (u-p) := + (Real.sqrt_le_sqrt_iff (sub_nonneg.mpr (hpl.trans hlu))).mpr (sub_le_sub_right hr.2 p) + rw [Real.norm_eq_abs] + change |F r (x+Real.sqrt (r-p)*y)| ≤ _ + have hmul := mul_le_mul_of_nonneg_right hs (abs_nonneg y) + have hhi := mul_le_mul_of_nonneg_left (add_le_add (show r-l ≤ u-l by linarith [hr.2]) hmul) L.coe_nonneg + linarith + · exact (integrable_const _).add + (((integrable_const _).add (integrable_standardGaussian_abs.const_mul _)).const_mul _) + · filter_upwards [] with y + exact (continuousOn_of_joint_bound hL).comp + ((continuous_id.prodMk (continuous_const.add ((Real.continuous_sqrt.comp + (continuous_id.sub continuous_const)).mul continuous_const))).continuousOn) + (fun r hr => ⟨hr,Set.mem_univ _⟩) + +lemma backward_heat_dual {f : ℝ → ℝ} (hf : RegularDatum f) + (hLip : LipschitzWith 1 f) {c : ℝ} (hc : 0 ≤ c) {p l u b : ℝ} + (hl : 0 ≤ l) (hpl : p ≤ l) (hlu : l ≤ u) (hub : u ≤ b) (x : ℝ) : + varianceHeat (u-p) (backward c b f u) x = + varianceHeat (l-p) (backward c b f l) x- + (c/2)*(∫ r in l..u, varianceHeat (r-p) (fun z => (deriv (backward c b f r) z)^2) x) := by + obtain ⟨L,hL⟩ := backward_joint_bound hf hLip hc b + obtain ⟨J,hJ⟩ := backward_gradient_sq_joint_bound hf hLip hc b + have hinc : Icc l u ⊆ Icc 0 b := fun r hr => ⟨hl.trans hr.1,hr.2.trans hub⟩ + have hcont : ContinuousOn (fun r => varianceHeat (r-p) (backward c b f r) x) (Icc l u) := + continuousOn_moving_heat_from hpl hlu + (fun r => (regularDatum_varianceLogHeat hf hLip hc (b-r)).smooth.continuous.measurable) + (fun r hr s hs => hL r (hinc hr) s (hinc hs)) x + have hscont := continuousOn_moving_heat_from hpl hlu + (fun r => (regularDatum_varianceLogHeat hf hLip hc (b-r)).deriv_bounded.smooth.continuous.measurable.pow_const 2) + (fun r hr s hs => hJ r (hinc hr) s (hinc hs)) x + have hint : IntervalIntegrable (fun r => -(c/2)*varianceHeat (r-p) + (fun z => (deriv (backward c b f r) z)^2) x) volume l u := + (hscont.const_mul (-(c/2))).intervalIntegrable_of_Icc hlu + have he := intervalIntegral.integral_eq_sub_of_hasDerivAt_of_le hlu hcont + (fun r hr => hasDerivAt_moving_backward_heat hf hLip hc (hpl.trans_lt hr.1) (hr.2.trans_le hub) x) hint + rw [intervalIntegral.integral_const_mul] at he + linarith + +def finiteValue (c : ℕ → ℝ≥0) (h : ℝ≥0) (f : ℝ → ℝ) : ℕ → ℕ → ℝ → ℝ → ℝ + | 0, _, _, x => f x + | N+1, i, t, x => if t ≤ h then + backward (c i) h (cascade c h f N (i+1)) t x + else finiteValue c h f N (i+1) (t-h) x + +def finiteCoeff (c : ℕ → ℝ≥0) (h : ℝ≥0) : ℕ → ℕ → ℝ → ℝ + | 0, _, _ => 0 + | N+1, i, t => if t ≤ h then c i else finiteCoeff c h N (i+1) (t-h) + +lemma finiteValue_regular {f : ℝ → ℝ} (hf : RegularDatum f) (hLip : LipschitzWith 1 f) + (c : ℕ → ℝ≥0) (h : ℝ≥0) (N i : ℕ) (t : ℝ) : + RegularDatum (finiteValue c h f N i t) := by + induction N generalizing i t with + | zero => exact hf + | succ N ih => + by_cases ht : t ≤ h + · have he : finiteValue c h f (N+1) i t = backward (c i) h (cascade c h f N (i+1)) t := by + funext x; simp only [finiteValue,ite_eq_left ht] + rw [he] + exact regularDatum_varianceLogHeat (cascade_regular hf hLip c h N (i+1)) + (cascade_lipschitz hLip c h N (i+1)) (c i).coe_nonneg (h-t) + · have he : finiteValue c h f (N+1) i t = finiteValue c h f N (i+1) (t-h) := by + funext x; simp only [finiteValue,ite_eq_right ht] + rw [he] + exact ih (i+1) (t-h) + +lemma finiteValue_lipschitz {f : ℝ → ℝ} (hLip : LipschitzWith 1 f) + (c : ℕ → ℝ≥0) (h : ℝ≥0) (N i : ℕ) (t : ℝ) : + LipschitzWith 1 (finiteValue c h f N i t) := by + induction N generalizing i t with + | zero => exact hLip + | succ N ih => + by_cases ht : t ≤ h + · have he : finiteValue c h f (N+1) i t = varianceLogHeat (c i) (h-t) (cascade c h f N (i+1)) := by + funext x; simp only [finiteValue,ite_eq_left ht,backward] + rw [he] + exact varianceLogHeat_lipschitz (cascade_lipschitz hLip c h N (i+1)) (c i).coe_nonneg _ + · have he : finiteValue c h f (N+1) i t = finiteValue c h f N (i+1) (t-h) := by + funext x; simp only [finiteValue,ite_eq_right ht] + rw [he] + exact ih (i+1) (t-h) + +lemma finiteValue_head (f : ℝ → ℝ) (c : ℕ → ℝ≥0) (h : ℝ≥0) (N i : ℕ) {t : ℝ} + (ht : t ≤ h) : finiteValue c h f (N+1) i t = backward (c i) h (cascade c h f N (i+1)) t := by + funext x; simp only [finiteValue,ite_eq_left ht] + +lemma finiteValue_tail (f : ℝ → ℝ) (c : ℕ → ℝ≥0) (h : ℝ≥0) (N i : ℕ) {t : ℝ} + (ht : (h:ℝ) < t) : finiteValue c h f (N+1) i t = finiteValue c h f N (i+1) (t-h) := by + funext x; simp only [finiteValue,ite_eq_right (not_le.mpr ht)] + +lemma finiteValue_zero {f : ℝ → ℝ} (hf : RegularDatum f) (hLip : LipschitzWith 1 f) + (c : ℕ → ℝ≥0) (h : ℝ≥0) (N i : ℕ) : finiteValue c h f N i 0 = cascade c h f N i := by + cases N with + | zero => rfl + | succ N => + rw [finiteValue_head f c h N i h.coe_nonneg] + funext x + simp only [backward,sub_zero,cascade] + exact varianceLogHeat_eq_logSemigroup (cascade_regular hf hLip c h N (i+1)).smooth.continuous.measurable (c i) h x + +lemma measurable_finiteValue {f : ℝ → ℝ} (hf : RegularDatum f) (hLip : LipschitzWith 1 f) + (c : ℕ → ℝ≥0) (h : ℝ≥0) (N i : ℕ) : + Measurable (fun p : ℝ × ℝ => finiteValue c h f N i p.1 p.2) := by + induction N generalizing i with + | zero => exact hf.smooth.continuous.measurable.comp measurable_snd + | succ N ih => + exact Measurable.ite (measurableSet_le measurable_fst measurable_const) + (measurable_backward (cascade_regular hf hLip c h N (i+1)).smooth.continuous.measurable (c i) h) + ((ih (i+1)).comp ((measurable_fst.sub_const (h:ℝ)).prodMk measurable_snd)) + +lemma measurable_finiteCoeff (c : ℕ → ℝ≥0) (h : ℝ≥0) (N i : ℕ) : + Measurable (finiteCoeff c h N i) := by + induction N generalizing i with + | zero => exact measurable_const + | succ N ih => + exact Measurable.ite (measurableSet_le measurable_id measurable_const) + measurable_const ((ih (i+1)).comp (measurable_id.sub_const (h:ℝ))) + +lemma finiteCoeff_bounds (c : ℕ → ℝ≥0) (h : ℝ≥0) (N i : ℕ) : + ∃ C : ℝ≥0, ∀ t, 0 ≤ finiteCoeff c h N i t ∧ finiteCoeff c h N i t ≤ C := by + induction N generalizing i with + | zero => exact ⟨0,fun _ => ⟨le_rfl,le_rfl⟩⟩ + | succ N ih => + obtain ⟨C,hC⟩ := ih (i+1) + refine ⟨c i+C,fun t => ?_⟩ + dsimp only [finiteCoeff] + split_ifs with ht + · constructor + · exact (c i).coe_nonneg + · simp only [NNReal.coe_add]; linarith [C.coe_nonneg] + · constructor + · exact (hC (t-h)).1 + · simp only [NNReal.coe_add]; linarith [(hC (t-h)).2,(c i).coe_nonneg] + +lemma finiteValue_uniform_derivative_bounds {f : ℝ → ℝ} (hf : RegularDatum f) + (hLip : LipschitzWith 1 f) (c : ℕ → ℝ≥0) (h : ℝ≥0) (N i n : ℕ) : + ∃ C : ℝ≥0, ∀ t x, |iteratedDeriv (n+1) (finiteValue c h f N i t) x| ≤ C := by + induction N generalizing i with + | zero => + obtain ⟨C,hC⟩ := hf.deriv_bounded.bounds n + exact ⟨C,fun _ x => by simpa only [finiteValue,iteratedDeriv_succ'] using hC x⟩ + | succ N ih => + obtain ⟨C,hC⟩ := uniform_varianceLogHeat_derivative_bounds + (cascade_regular hf hLip c h N (i+1)) (cascade_lipschitz hLip c h N (i+1)) (c i).coe_nonneg n + obtain ⟨D,hD⟩ := ih (i+1) + refine ⟨C+D,fun t x => ?_⟩ + by_cases ht : t ≤ h + · rw [finiteValue_head f c h N i ht] + rw [show backward (c i) h (cascade c h f N (i+1)) t = + varianceLogHeat (c i) (h-t) (cascade c h f N (i+1)) from rfl] + exact (hC (h-t) x).trans (by simp only [NNReal.coe_add]; linarith [D.coe_nonneg]) + · rw [finiteValue_tail f c h N i (lt_of_not_ge ht)] + exact (hD (t-h) x).trans (by simp only [NNReal.coe_add]; linarith [C.coe_nonneg]) + +end ZeroTemperatureSK.Heat + +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKSupport/Foundations/GradientAbs.lean b/lean/OAI/Probability/SKSupport/Foundations/GradientAbs.lean new file mode 100644 index 0000000000000000000000000000000000000000..600f7204f1883eb83ed5eb92faf309c156fdc676 --- /dev/null +++ b/lean/OAI/Probability/SKSupport/Foundations/GradientAbs.lean @@ -0,0 +1,99 @@ +import Mathlib +import OAI.Probability.SKSupport.Control.ExpectedControlPayoff + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section +namespace ZeroTemperatureSK + +variable {Ω : Type*} [MeasurableSpace Ω] + +lemma gradient_abs_le_one (W : BrownianSystem Ω) (γ : OrderParameter) + (t x : ℝ) (ht : t ≤ 1) : |gradient W γ t x| ≤ 1 := by + simpa only [gradient, Real.norm_eq_abs, NNReal.coe_one] using + (norm_deriv_le_of_lipschitz (x₀ := x) (value_lipschitz W γ t ht)) + +lemma integral_weighted_difference_bound {g h a : ℝ → ℝ} (hg : Integrable g) + (hh : Integrable h) (ha : Measurable a) (hbound : ∀ s, |a s| ≤ 1) + (t : ℝ) (ht : t ≤ 1) : + |(∫ s in t..1, g s*a s) - (∫ s in t..1, h s*a s)| ≤ + ∫ s in t..1, |g s-h s| := by + have hg' : Integrable (fun s => g s*a s) := hg.mul_bdd ha.aestronglyMeasurable + (Filter.Eventually.of_forall (fun s => by simpa only [Real.norm_eq_abs] using hbound s)) + have hh' : Integrable (fun s => h s*a s) := hh.mul_bdd ha.aestronglyMeasurable + (Filter.Eventually.of_forall (fun s => by simpa only [Real.norm_eq_abs] using hbound s)) + rw [← intervalIntegral.integral_sub hg'.intervalIntegrable hh'.intervalIntegrable, + ← Real.norm_eq_abs] + apply intervalIntegral.norm_integral_le_of_norm_le ht _ (hg.sub hh).abs.intervalIntegrable + exact Filter.Eventually.of_forall (fun s _ => by + simp only [Pi.sub_apply, Real.norm_eq_abs, ← sub_mul, abs_mul] + simpa only [mul_one] using mul_le_mul_of_nonneg_left (hbound s) (abs_nonneg (g s-h s))) + +lemma controlPayoff_coeff_le (W : BrownianSystem Ω) (γ η : OrderParameter) + (t x : ℝ) (ht : t ≤ 1) (α : Control W (Real.toNNReal t)) (ω : Ω) : + controlPayoff W γ t x α ω ≤ controlPayoff W η t x α ω + + (3 / 2 : ℝ) * ∫ s in t..1, |extend γ.val s-extend η.val s| := by + have ha : Measurable (fun s : ℝ => α.val (Real.toNNReal (s-t)) ω) := + (α.measurable_elapsed t).comp measurable_prodMk_right + have hd := integral_weighted_difference_bound γ.integrable η.integrable ha + (fun s => α.bound _ _) t ht + have hc := integral_weighted_difference_bound γ.integrable η.integrable (ha.pow_const 2) + (fun s => by simpa only [abs_pow, one_pow, Function.comp_apply] using + pow_le_pow_left₀ (abs_nonneg _) (α.bound (Real.toNNReal (s-t)) ω) 2) t ht + have htri := abs_add_le + (x + W.B 1 ω - W.B (Real.toNNReal t) ω + + ∫ s in t..1, extend η.val s * α.val (Real.toNNReal (s-t)) ω) + ((∫ s in t..1, extend γ.val s * α.val (Real.toNNReal (s-t)) ω) - + ∫ s in t..1, extend η.val s * α.val (Real.toNNReal (s-t)) ω) + have heq : x + W.B 1 ω - W.B (Real.toNNReal t) ω + + (∫ s in t..1, extend η.val s * α.val (Real.toNNReal (s-t)) ω) + + ((∫ s in t..1, extend γ.val s * α.val (Real.toNNReal (s-t)) ω) - + ∫ s in t..1, extend η.val s * α.val (Real.toNNReal (s-t)) ω) = + x + W.B 1 ω - W.B (Real.toNNReal t) ω + + ∫ s in t..1, extend γ.val s * α.val (Real.toNNReal (s-t)) ω := by ring + rw [heq] at htri + have hcost := neg_le_abs + ((∫ s in t..1, extend γ.val s * (α.val (Real.toNNReal (s-t)) ω)^2) - + ∫ s in t..1, extend η.val s * (α.val (Real.toNNReal (s-t)) ω)^2) + dsimp [controlPayoff] + linarith + +lemma value_coeff_le (W : BrownianSystem Ω) (γ η : OrderParameter) + (t x : ℝ) (ht : t ≤ 1) : value W γ t x ≤ value W η t x + + (3 / 2 : ℝ) * ∫ s in t..1, |extend γ.val s-extend η.val s| := by + let := W.isProbability + unfold value + refine csSup_le ?_ ?_ + · exact ⟨_, ⟨zeroControl W (Real.toNNReal t), rfl⟩⟩ + rintro _ ⟨α, rfl⟩ + calc + (∫ ω, controlPayoff W γ t x α ω ∂W.law) ≤ + ∫ ω, (controlPayoff W η t x α ω + + (3 / 2 : ℝ) * ∫ s in t..1, |extend γ.val s-extend η.val s|) ∂W.law := + integral_mono (controlPayoff_integrable W γ t x ht α) + ((controlPayoff_integrable W η t x ht α).add (integrable_const _)) + (controlPayoff_coeff_le W γ η t x ht α) + _ = (∫ ω, controlPayoff W η t x α ω ∂W.law) + + (3 / 2 : ℝ) * ∫ s in t..1, |extend γ.val s-extend η.val s| := by + rw [integral_add (controlPayoff_integrable W η t x ht α) (integrable_const _)] + simp + _ ≤ _ := add_le_add (expected_controlPayoff_le_value W η t x ht α) le_rfl + +theorem value_coefficient_stability (W : BrownianSystem Ω) (γ η : OrderParameter) + (t x : ℝ) (ht : t ≤ 1) : |value W γ t x - value W η t x| ≤ + (3 / 2 : ℝ) * ∫ s in t..1, |extend γ.val s-extend η.val s| := by + rw [abs_le] + have h₁ := value_coeff_le W γ η t x ht + have h₂ := value_coeff_le W η γ t x ht + simp_rw [abs_sub_comm (extend η.val _) (extend γ.val _)] at h₂ + constructor <;> linarith + +end ZeroTemperatureSK + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKSupport/Foundations/IntegrableCompBoundedDeriv.lean b/lean/OAI/Probability/SKSupport/Foundations/IntegrableCompBoundedDeriv.lean new file mode 100644 index 0000000000000000000000000000000000000000..42106a11309ab58722727befc9953557075b4772 --- /dev/null +++ b/lean/OAI/Probability/SKSupport/Foundations/IntegrableCompBoundedDeriv.lean @@ -0,0 +1,38 @@ +import Mathlib +import OAI.Probability.SKSupport.Model + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section +namespace ZeroTemperatureSK.WeakIto +variable {Ω : Type*} [MeasurableSpace Ω] {P : Measure Ω} + +lemma integrable_comp_of_bounded_deriv [IsFiniteMeasure P] {f : ℝ → ℝ} (hf : Differentiable ℝ f) + (C : ℝ≥0) (hC : ∀ x, |deriv f x| ≤ C) {Y : Ω → ℝ} (hY : Integrable Y P) : + Integrable (fun ω => f (Y ω)) P := by + have hl : LipschitzWith C f := lipschitzWith_of_nnnorm_deriv_le hf + (fun x => show ‖deriv f x‖₊ ≤ C from by exact_mod_cast hC x) + apply ((integrable_const ‖f 0‖).add (hY.norm.const_mul (C:ℝ))).mono' + (hf.continuous.comp_aestronglyMeasurable hY.aestronglyMeasurable) + filter_upwards [] with ω + have h := hl.norm_sub_le (Y ω) 0 + simp only [sub_zero] at h + have htri := norm_add_le (f (Y ω)-f 0) (f 0) + rw [sub_add_cancel] at htri + dsimp + simp only [Real.norm_eq_abs] at h htri + linarith + +end ZeroTemperatureSK.WeakIto + +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKSupport/Foundations/IntegralIoiMulExpSq.lean b/lean/OAI/Probability/SKSupport/Foundations/IntegralIoiMulExpSq.lean new file mode 100644 index 0000000000000000000000000000000000000000..ed2178f3f5428742506d290572625716455c5635 --- /dev/null +++ b/lean/OAI/Probability/SKSupport/Foundations/IntegralIoiMulExpSq.lean @@ -0,0 +1,86 @@ +import Mathlib +import OAI.Probability.SKSupport.Model + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section +namespace ZeroTemperatureSK.Gaussian + +lemma integral_Ioi_mul_exp_sq {a : ℝ} (ha : 0 < a) : + (∫ x : ℝ in Set.Ioi 0, x * Real.exp (-a*x^2)) = (2*a)⁻¹ := by + have hderiv (x : ℝ) : HasDerivAt (fun y : ℝ => -(2*a)⁻¹ * Real.exp (-a*y^2)) + (x * Real.exp (-a*x^2)) x := by + apply ((((hasDerivAt_id x).pow 2).const_mul (-a)).exp.const_mul (-(2*a)⁻¹)).congr_deriv + simp only [id_eq, Pi.pow_apply, Nat.cast_ofNat, Nat.reduceSub, pow_one] + field_simp + have hlim : Tendsto (fun y : ℝ => -(2*a)⁻¹ * Real.exp (-a*y^2)) + atTop (𝓝 (-(2*a)⁻¹ * 0)) := by + apply Tendsto.const_mul + exact Real.tendsto_exp_atBot.comp + ((tendsto_pow_atTop (by norm_num : 2 ≠ 0)).const_mul_atTop_of_neg (neg_lt_zero.mpr ha)) + simpa using integral_Ioi_of_hasDerivAt_of_tendsto' (a := (0 : ℝ)) (fun x _ => hderiv x) + (integrable_mul_exp_neg_mul_sq ha).integrableOn hlim + +lemma integral_abs_mul_exp_sq {a : ℝ} (ha : 0 < a) : + (∫ x : ℝ, |x| * Real.exp (-a*x^2)) = a⁻¹ := by + have hi : Integrable (fun x : ℝ => |x| * Real.exp (-a*x^2)) := by + simpa only [Real.norm_eq_abs, abs_mul, abs_of_pos (Real.exp_pos _)] using + (integrable_mul_exp_neg_mul_sq ha).norm + have hp : (∫ x : ℝ in Set.Ioi 0, |x| * Real.exp (-a*x^2)) = (2*a)⁻¹ := by + rw [← integral_Ioi_mul_exp_sq ha] + apply setIntegral_congr_fun measurableSet_Ioi + intro x hx + simp only [abs_of_pos (show 0 < x from hx)] + have hneg (x : ℝ) : |(-x)| * Real.exp (-a*(-x)^2) = |x| * Real.exp (-a*x^2) := by + rw [abs_neg] + congr 2 + ring + have he : (∫ x : ℝ in Set.Ioi 0, |x| * Real.exp (-a*x^2)) = + ∫ x : ℝ in Set.Iic 0, |x| * Real.exp (-a*x^2) := by + have h := integral_comp_neg_Ioi (0 : ℝ) (fun x : ℝ => |x| * Real.exp (-a*x^2)) + change (∫ x : ℝ in Set.Ioi 0, |(-x)| * Real.exp (-a*(-x)^2)) = + ∫ x : ℝ in Set.Iic (-0), |x| * Real.exp (-a*x^2) at h + simpa only [hneg, neg_zero] using h + calc + _ = (∫ x : ℝ in Set.Ioi 0, |x| * Real.exp (-a*x^2)) + + ∫ x : ℝ in Set.Iic 0, |x| * Real.exp (-a*x^2) := by + simpa only [Set.compl_Ioi] using (integral_add_compl measurableSet_Ioi hi).symm + _ = (2*a)⁻¹ + (2*a)⁻¹ := by rw [← he, hp] + _ = a⁻¹ := by field_simp; norm_num + +theorem gaussian_abs_moment (v : ℝ≥0) : + (∫ x : ℝ, |x| ∂gaussianReal 0 v) = Real.sqrt (2*(v:ℝ)/Real.pi) := by + by_cases hv : v = 0 + · simp [hv] + have hv' : (0 : ℝ) < v := by exact_mod_cast (pos_iff_ne_zero.mpr hv) + have ha : 0 < (2*(v:ℝ))⁻¹ := by positivity + rw [integral_gaussianReal_eq_integral_smul hv] + have heq : (fun x : ℝ => gaussianPDFReal 0 v x • |x|) = + (fun x : ℝ => (Real.sqrt (2*Real.pi*v))⁻¹ * (|x| * Real.exp (-(2*(v:ℝ))⁻¹*x^2))) := by + funext x + simp only [gaussianPDFReal, sub_zero, smul_eq_mul] + have hexp : -x^2/(2*(v:ℝ)) = -(2*(v:ℝ))⁻¹*x^2 := by ring + rw [hexp] + ring + rw [heq, integral_const_mul, integral_abs_mul_exp_sq ha, inv_inv] + have hs : 0 < Real.sqrt (2*Real.pi*(v:ℝ)) := Real.sqrt_pos.mpr (by positivity) + have hr : 0 ≤ Real.sqrt (2*(v:ℝ)/Real.pi) := Real.sqrt_nonneg _ + have hs2 := Real.sq_sqrt (show 0 ≤ 2*Real.pi*(v:ℝ) by positivity) + have hr2 := Real.sq_sqrt (show 0 ≤ 2*(v:ℝ)/Real.pi by positivity) + rw [inv_mul_eq_div] + apply (div_eq_iff (ne_of_gt hs)).mpr + have he : (2*(v:ℝ))^2 = (Real.sqrt (2*(v:ℝ)/Real.pi) * Real.sqrt (2*Real.pi*(v:ℝ)))^2 := by + simp only [mul_pow] + rw [hs2, hr2] + field_simp + nlinarith [mul_nonneg hr hs.le] + +end ZeroTemperatureSK.Gaussian + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKSupport/Foundations/InvSqrtNegHalf.lean b/lean/OAI/Probability/SKSupport/Foundations/InvSqrtNegHalf.lean new file mode 100644 index 0000000000000000000000000000000000000000..66cb0bac38b3b07d78d844d5925217602a3e24da --- /dev/null +++ b/lean/OAI/Probability/SKSupport/Foundations/InvSqrtNegHalf.lean @@ -0,0 +1,177 @@ +import Mathlib +import OAI.Probability.SKSupport.Model + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology ContDiff +noncomputable section +open MeasureTheory Set Filter +open scoped Topology +noncomputable section +namespace ZeroTemperatureSK.Smoothing + +lemma inv_sqrt_eq_neg_half {x : ℝ} (hx : 0 ≤ x) : + 1/Real.sqrt x = x^(-(1/2:ℝ)) := by + rw [Real.rpow_neg hx,← Real.sqrt_eq_rpow,one_div] + +lemma intervalIntegrable_inv_sqrt {a b : ℝ} (ha : 0 ≤ a) (hab : a ≤ b) : + IntervalIntegrable (fun x : ℝ => 1/Real.sqrt x) volume a b := by + apply (intervalIntegral.intervalIntegrable_rpow' (a := a) (b := b) (r := -(1/2:ℝ)) (by norm_num)).congr + intro x hx + rw [uIoc_of_le hab] at hx + exact (inv_sqrt_eq_neg_half (ha.trans hx.1.le)).symm + +lemma integral_inv_sqrt {b : ℝ} (hb : 0 ≤ b) : + (∫ x in (0:ℝ)..b, 1/Real.sqrt x) = 2*Real.sqrt b := by + have he : (∫ x in (0:ℝ)..b, 1/Real.sqrt x) = ∫ x in (0:ℝ)..b, x^(-(1/2:ℝ)) := by + apply intervalIntegral.integral_congr + intro x hx + rw [uIcc_of_le hb] at hx + exact inv_sqrt_eq_neg_half hx.1 + rw [he,integral_rpow (Or.inl (by norm_num : -(1:ℝ) < -(1/2:ℝ)))] + norm_num only [neg_add_cancel_left,show -(1/2:ℝ)+1=1/2 by norm_num,Real.zero_rpow (by norm_num : (1/2:ℝ) ≠ 0),sub_zero] + rw [← Real.sqrt_eq_rpow] + ring + +lemma intervalIntegrable_inv_sqrt_sub {a b : ℝ} (hab : a ≤ b) : + IntervalIntegrable (fun r => 1/Real.sqrt (r-a)) volume a b := by + simpa only [zero_add,sub_add_cancel] using + (intervalIntegrable_inv_sqrt (a := 0) (b := b-a) le_rfl (sub_nonneg.mpr hab)).comp_sub_right a + +lemma intervalIntegrable_inv_sqrt_sub' {a b : ℝ} (hab : a ≤ b) : + IntervalIntegrable (fun r => 1/Real.sqrt (b-r)) volume a b := by + have h := (intervalIntegrable_inv_sqrt (a := 0) (b := b-a) le_rfl (sub_nonneg.mpr hab)).comp_sub_left b + simpa only [sub_zero,sub_sub_cancel] using h.symm + +lemma integral_inv_sqrt_sub {a b : ℝ} (hab : a ≤ b) : + (∫ r in a..b, 1/Real.sqrt (r-a)) = 2*Real.sqrt (b-a) := by + rw [intervalIntegral.integral_comp_sub_right (fun x : ℝ => 1/Real.sqrt x) a,sub_self,integral_inv_sqrt (sub_nonneg.mpr hab)] + +lemma integral_inv_sqrt_sub' {a b : ℝ} (hab : a ≤ b) : + (∫ r in a..b, 1/Real.sqrt (b-r)) = 2*Real.sqrt (b-a) := by + rw [intervalIntegral.integral_comp_sub_left (fun x : ℝ => 1/Real.sqrt x) b,sub_self,integral_inv_sqrt (sub_nonneg.mpr hab)] + +lemma sqrt_kernel_bound {a r b : ℝ} (har : a < r) (hrb : r < b) : + 1/(Real.sqrt (r-a)*Real.sqrt (b-r)) ≤ + (2/Real.sqrt (b-a))*(1/Real.sqrt (r-a)+1/Real.sqrt (b-r)) := by + have hp : 0 < Real.sqrt (r-a) := Real.sqrt_pos.mpr (sub_pos.mpr har) + have hq : 0 < Real.sqrt (b-r) := Real.sqrt_pos.mpr (sub_pos.mpr hrb) + have hh : 0 < Real.sqrt (b-a) := Real.sqrt_pos.mpr (sub_pos.mpr (har.trans hrb)) + have hps := Real.sq_sqrt (sub_pos.mpr har).le + have hqs := Real.sq_sqrt (sub_pos.mpr hrb).le + have hhs := Real.sq_sqrt (sub_pos.mpr (har.trans hrb)).le + have hs : Real.sqrt (b-a) ≤ 2*(Real.sqrt (r-a)+Real.sqrt (b-r)) := by + nlinarith [mul_nonneg hp.le hq.le] + apply (div_le_iff₀ (mul_pos hp hq)).mpr + have he : (2/Real.sqrt (b-a))*(1/Real.sqrt (r-a)+1/Real.sqrt (b-r)) * + (Real.sqrt (r-a)*Real.sqrt (b-r)) = + 2*(Real.sqrt (r-a)+Real.sqrt (b-r))/Real.sqrt (b-a) := by + field_simp + ring + rw [he] + exact (le_div_iff₀ hh).mpr (by simpa using hs) + +lemma intervalIntegrable_sqrt_kernel {a b : ℝ} (hab : a < b) : + IntervalIntegrable (fun r => 1/(Real.sqrt (r-a)*Real.sqrt (b-r))) volume a b := by + apply (((intervalIntegrable_inv_sqrt_sub hab.le).add + (intervalIntegrable_inv_sqrt_sub' hab.le)).const_mul (2/Real.sqrt (b-a))).mono_fun' + ((measurable_const.div ((measurable_id.sub_const a).sqrt.mul ((measurable_const.sub measurable_id).sqrt))).aestronglyMeasurable) + rw [uIoc_of_le hab.le] + filter_upwards [ae_restrict_mem measurableSet_Ioc,show ∀ᵐ r ∂volume.restrict (Ioc a b), r ≠ b from + (ae_restrict_of_ae (volume.ae_ne b))] with r hr hrb + simp only [Pi.div_apply,Pi.mul_apply,Pi.sub_apply,id_eq] + rw [Real.norm_eq_abs,abs_of_nonneg (show 0 ≤ 1/(Real.sqrt (r-a)*Real.sqrt (b-r)) by positivity)] + exact sqrt_kernel_bound hr.1 (lt_of_le_of_ne hr.2 hrb) + +lemma integral_sqrt_kernel_le {a b : ℝ} (hab : a < b) : + (∫ r in a..b, 1/(Real.sqrt (r-a)*Real.sqrt (b-r))) ≤ 8 := by + have hL := intervalIntegrable_inv_sqrt_sub hab.le + have hR := intervalIntegrable_inv_sqrt_sub' hab.le + have h := intervalIntegral.integral_mono_on_of_le_Ioo hab.le + (intervalIntegrable_sqrt_kernel hab) ((hL.add hR).const_mul (2/Real.sqrt (b-a))) + (fun r hr => sqrt_kernel_bound hr.1 hr.2) + rw [intervalIntegral.integral_const_mul,intervalIntegral.integral_add hL hR, + integral_inv_sqrt_sub hab.le,integral_inv_sqrt_sub' hab.le] at h + have hr : Real.sqrt (b-a) ≠ 0 := ne_of_gt (Real.sqrt_pos.mpr (sub_pos.mpr hab)) + have he : 2/Real.sqrt (b-a)*(2*Real.sqrt (b-a)+2*Real.sqrt (b-a)) = 8 := by field_simp; ring + rwa [he] at h + +end ZeroTemperatureSK.Smoothing + +namespace ZeroTemperatureSK.Smoothing + +def weightedValues (F : ℝ → ℝ → ℝ) (a b : ℝ) : Set ℝ := + {z | ∃ t ∈ Icc a b, ∃ x, z = Real.sqrt (b-t)*|F t x|} + +def weightedSize (F : ℝ → ℝ → ℝ) (a b : ℝ) : ℝ := sSup (weightedValues F a b) + +lemma weightedValues_nonempty (F : ℝ → ℝ → ℝ) {a b : ℝ} (hab : a ≤ b) : + (weightedValues F a b).Nonempty := by + refine ⟨0,b,⟨hab,le_rfl⟩,0,?_⟩ + simp + +lemma weightedValues_bddAbove {F : ℝ → ℝ → ℝ} {a b C : ℝ} + (hC : ∀ t ∈ Icc a b, ∀ x, |F t x| ≤ C) : BddAbove (weightedValues F a b) := by + refine ⟨Real.sqrt (b-a)*max C 0,?_⟩ + rintro _ ⟨t,ht,x,rfl⟩ + apply mul_le_mul (Real.sqrt_le_sqrt (by linarith [ht.1])) + ((hC t ht x).trans (le_max_left _ _)) (abs_nonneg _) (Real.sqrt_nonneg _) + +lemma weighted_le_size {F : ℝ → ℝ → ℝ} {a b C : ℝ} + (hC : ∀ t ∈ Icc a b, ∀ x, |F t x| ≤ C) {t : ℝ} (ht : t ∈ Icc a b) (x : ℝ) : + Real.sqrt (b-t)*|F t x| ≤ weightedSize F a b := + le_csSup (weightedValues_bddAbove hC) ⟨t,ht,x,rfl⟩ + +lemma weightedSize_nonneg {F : ℝ → ℝ → ℝ} {a b C : ℝ} (hab : a ≤ b) + (hC : ∀ t ∈ Icc a b, ∀ x, |F t x| ≤ C) : 0 ≤ weightedSize F a b := by + have h := weighted_le_size hC (t := b) ⟨hab,le_rfl⟩ 0 + simpa using h + +lemma abs_le_weightedSize {F : ℝ → ℝ → ℝ} {a b C : ℝ} + (hC : ∀ t ∈ Icc a b, ∀ x, |F t x| ≤ C) {t : ℝ} (ht : t ∈ Ico a b) (x : ℝ) : + |F t x| ≤ weightedSize F a b/Real.sqrt (b-t) := by + apply (le_div_iff₀ (Real.sqrt_pos.mpr (sub_pos.mpr ht.2))).mpr + simpa only [mul_comm] using weighted_le_size hC ⟨ht.1,ht.2.le⟩ x + +lemma weightedSize_le {F : ℝ → ℝ → ℝ} {a b K : ℝ} (hab : a ≤ b) + (hK : ∀ t ∈ Icc a b, ∀ x, Real.sqrt (b-t)*|F t x| ≤ K) : + weightedSize F a b ≤ K := by + apply csSup_le (weightedValues_nonempty F hab) + rintro _ ⟨t,ht,x,rfl⟩ + exact hK t ht x + +lemma weighted_absorption {F : ℝ → ℝ → ℝ} {a b C K ε : ℝ} (hab : a < b) + (hC : ∀ t ∈ Icc a b, ∀ x, |F t x| ≤ C) (hK : 0 ≤ K) (hε : 0 ≤ ε) + (hsmall : ε*Real.sqrt (b-a) ≤ 1/2) + (hineq : ∀ t ∈ Ico a b, ∀ x, + Real.sqrt (b-t)*|F t x| ≤ K+ε*Real.sqrt (b-t)*weightedSize F a b) : + weightedSize F a b ≤ 2*K := by + have hM := weightedSize_nonneg hab.le hC + have hsup : weightedSize F a b ≤ K+ε*Real.sqrt (b-a)*weightedSize F a b := by + apply weightedSize_le hab.le + intro t ht x + rcases lt_or_eq_of_le ht.2 with htb | rfl + · apply (hineq t ⟨ht.1,htb⟩ x).trans + gcongr + linarith [ht.1] + · simp only [sub_self,Real.sqrt_zero,zero_mul] + positivity + nlinarith [mul_le_mul_of_nonneg_right hsmall hM] + +end ZeroTemperatureSK.Smoothing + +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKSupport/Foundations/MeasurableSpatialDeriv.lean b/lean/OAI/Probability/SKSupport/Foundations/MeasurableSpatialDeriv.lean new file mode 100644 index 0000000000000000000000000000000000000000..f2c973abdc5ca694197f1e2da3a2dda5fce7af9d --- /dev/null +++ b/lean/OAI/Probability/SKSupport/Foundations/MeasurableSpatialDeriv.lean @@ -0,0 +1,93 @@ +import Mathlib +import OAI.Probability.SKSupport.Backward.Backward + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology ContDiff +noncomputable section +namespace ZeroTemperatureSK.Heat + +lemma measurable_spatial_deriv {F : ℝ → ℝ → ℝ} + (hm : Measurable (fun p : ℝ × ℝ => F p.1 p.2)) + (hd : ∀ r, Differentiable ℝ (F r)) : + Measurable (fun p : ℝ × ℝ => deriv (F p.1) p.2) := by + let h : ℕ → ℝ := fun n => 1/((n:ℝ)+1) + have ht : Tendsto h atTop (𝓝[≠] (0:ℝ)) := by + apply tendsto_nhdsWithin_iff.mpr + refine ⟨tendsto_one_div_add_atTop_nhds_zero_nat,?_⟩ + exact Eventually.of_forall (fun n => by simp only [Set.mem_compl_iff,Set.mem_singleton_iff]; dsimp [h]; positivity) + apply measurable_of_tendsto_metrizable + (f := fun n (p : ℝ × ℝ) => (h n)⁻¹*(F p.1 (p.2+h n)-F p.1 p.2)) + · intro n + exact measurable_const.mul ((hm.comp (measurable_fst.prodMk (measurable_snd.add_const _))).sub hm) + · apply tendsto_pi_nhds.mpr + intro p + simpa only [Function.comp_def,smul_eq_mul] using (hd p.1 p.2).hasDerivAt.tendsto_slope_zero.comp ht + +lemma measurable_varianceHeat_family {F : ℝ → ℝ → ℝ} {V : ℝ → ℝ} + (hm : Measurable (fun p : ℝ × ℝ => F p.1 p.2)) (hV : Measurable V) : + Measurable (fun p : ℝ × ℝ => varianceHeat (V p.1) (F p.1) p.2) := by + have hj : Measurable (fun q : (ℝ × ℝ) × ℝ => F q.1.1 (q.1.2+Real.sqrt (V q.1.1)*q.2)) := + hm.comp ((measurable_fst.comp measurable_fst).prodMk + ((measurable_snd.comp measurable_fst).add (((hV.comp (measurable_fst.comp measurable_fst)).sqrt).mul measurable_snd))) + exact hj.stronglyMeasurable.integral_prod_right.measurable + +lemma measurable_backward {f : ℝ → ℝ} (hf : Measurable f) (c b : ℝ) : + Measurable (fun p : ℝ × ℝ => backward c b f p.1 p.2) := by + unfold backward varianceLogHeat + split_ifs with hc + · exact measurable_varianceHeat_family (F := fun _ z => f z) (hf.comp measurable_snd) (measurable_const.sub measurable_id) + · exact (measurable_varianceHeat_family (F := fun _ z => Real.exp (c*f z)) + ((measurable_const.mul (hf.comp measurable_snd)).exp) (measurable_const.sub measurable_id)).log.div_const c + +lemma varianceHeat_abs_le {g : ℝ → ℝ} {A : ℝ} (hA : ∀ z, |g z| ≤ A) (t x : ℝ) : + |varianceHeat t g x| ≤ A := by + have hnn : 0 ≤ A := (abs_nonneg (g 0)).trans (hA 0) + change ‖∫ y, g (x+Real.sqrt t*y) ∂gaussianReal 0 1‖ ≤ A + have hh := norm_integral_le_of_norm_le_const (μ := gaussianReal 0 1) + (f := fun y => g (x+Real.sqrt t*y)) (C := A) + (ae_of_all _ (fun y => by simpa only [Real.norm_eq_abs] using hA (x+Real.sqrt t*y))) + simpa using hh + +lemma hasDerivAt_integral_varianceHeat {F : ℝ → ℝ → ℝ} {A B : ℝ≥0} + (hm : Measurable (fun p : ℝ × ℝ => F p.1 p.2)) + (hf : ∀ r, BoundedSmooth (F r)) (hA : ∀ r z, |F r z| ≤ A) + (hB : ∀ r z, |deriv (F r) z| ≤ B) (a b x : ℝ) : + HasDerivAt (fun z => ∫ r in a..b, varianceHeat (r-a) (F r) z) + (∫ r in a..b, varianceHeat (r-a) (deriv (F r)) x) x := by + have hm' := measurable_spatial_deriv hm (fun r => (hf r).smooth.differentiable (by simp)) + have hH := measurable_varianceHeat_family hm (measurable_id.sub_const a) + have hH' := measurable_varianceHeat_family (F := fun r => deriv (F r)) hm' (measurable_id.sub_const a) + refine (intervalIntegral.hasDerivAt_integral_of_dominated_loc_of_deriv_le + (F := fun z r => varianceHeat (r-a) (F r) z) + (F' := fun z r => varianceHeat (r-a) (deriv (F r)) z) + (bound := fun _ => (B:ℝ)) (s := Set.univ) (Filter.univ_mem) + (Eventually.of_forall (fun z => (hH.comp (measurable_id.prodMk measurable_const)).aestronglyMeasurable)) + ?_ ((hH'.comp (measurable_id.prodMk measurable_const)).aestronglyMeasurable) ?_ + (intervalIntegrable_const) ?_).2 + · apply (intervalIntegrable_const (c := (A:ℝ))).mono_fun + (hH.comp (measurable_id.prodMk measurable_const)).aestronglyMeasurable + filter_upwards [] with r + simpa only [Function.comp_def,id_eq,Real.norm_eq_abs,abs_of_nonneg A.coe_nonneg] using varianceHeat_abs_le (hA r) (r-a) x + · filter_upwards [] with r hr z hz + simpa only [Real.norm_eq_abs] using varianceHeat_abs_le (hB r) (r-a) z + · filter_upwards [] with r hr z hz + exact hasDerivAt_scaled_space ((hf r).smooth.of_le (by simp)) + (ExponentialBound.of_bounded (hA r)) (ExponentialBound.of_bounded (hB r)) (Real.sqrt (r-a)) z + +end ZeroTemperatureSK.Heat + +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKSupport/Foundations/RightCoeffApprox.lean b/lean/OAI/Probability/SKSupport/Foundations/RightCoeffApprox.lean new file mode 100644 index 0000000000000000000000000000000000000000..0b6613226e57648e0212209a46493704ed231232 --- /dev/null +++ b/lean/OAI/Probability/SKSupport/Foundations/RightCoeffApprox.lean @@ -0,0 +1,59 @@ +import Mathlib +import OAI.Probability.SKSupport.Diffusion.FiniteFeedback + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section +namespace ZeroTemperatureSK +open Heat + +lemma rightCoeff_eq_finiteCoeff (c : ℕ → ℝ≥0) (h : ℝ≥0) (N i : ℕ) {t : ℝ} + (hne : ∀ k < N, t ≠ ((k+1:ℕ):ℝ)*h) : rightCoeff c h N i t=finiteCoeff c h N i t := by + induction N generalizing i t with + | zero => rfl + | succ N ih => + have hh : t ≠ (h:ℝ) := by simpa using hne 0 (by omega) + rw [rightCoeff,finiteCoeff] + by_cases ht : t < h + · rw [ite_eq_left ht,ite_eq_left ht.le] + · rw [ite_eq_right ht,ite_eq_right (by exact not_le.mpr (lt_of_le_of_ne (le_of_not_gt ht) hh.symm))] + apply ih + intro k hk he + apply hne (k+1) (by omega) + have he' := he + push_cast at he' ⊢ + linarith + +lemma rightCoeff_ae (c : ℕ → ℝ≥0) (h : ℝ≥0) (N i : ℕ) : + rightCoeff c h N i =ᵐ[volume] finiteCoeff c h N i := by + have hn : ∀ᵐ t : ℝ, ∀ k : ℕ, t ≠ ((k+1:ℕ):ℝ)*h := by + rw [ae_all_iff] + intro k + exact ae_iff.mpr (by simp) + filter_upwards [hn] with t ht + exact rightCoeff_eq_finiteCoeff c h N i (fun k _ => ht k) + +lemma rightCoeff_intervalIntegrable (c : ℕ → ℝ≥0) (h : ℝ≥0) (N i : ℕ) (a b : ℝ) : + IntervalIntegrable (rightCoeff c h N i) volume a b := + (finiteCoeff_intervalIntegrable c h N i a b).congr_ae (ae_restrict_of_ae (rightCoeff_ae c h N i).symm) + +lemma finiteFeedback_bound_on {f : ℝ → ℝ} (hf : RegularDatum f) (hLip : LipschitzWith 1 f) + (c : ℕ → ℝ≥0) (h : ℝ≥0) (N : ℕ) {T D : ℝ} + (hD : ∀ s ∈ Icc (0:ℝ) T, finiteCoeff c h N 0 s ≤ D) : + ∀ᵐ s ∂volume, ∀ _ : s ∈ Icc (0:ℝ) T, ∀ x, |(finiteFeedback hf hLip c h N 0).f s x| ≤ D := by + filter_upwards [rightCoeff_ae c h N 0] with s hs hst x + change |rightCoeff c h N 0 s*deriv (finiteValue c h f N 0 s) x| ≤ D + rw [hs,abs_mul,abs_of_nonneg (finiteCoeff_nonneg c h N 0 s)] + have hg := norm_deriv_le_of_lipschitz (finiteValue_lipschitz hLip c h N 0 s) (x₀ := x) + have hb : |deriv (finiteValue c h f N 0 s) x| ≤ 1 := by simpa only [Real.norm_eq_abs,NNReal.coe_one] using hg + exact (mul_le_mul_of_nonneg_left hb (finiteCoeff_nonneg c h N 0 s)).trans (by simpa using hD s hst) + +end ZeroTemperatureSK + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKSupport/Foundations/RightGenerator.lean b/lean/OAI/Probability/SKSupport/Foundations/RightGenerator.lean new file mode 100644 index 0000000000000000000000000000000000000000..920e2eb00d6d1b4c319a0ca991711b657eef200a --- /dev/null +++ b/lean/OAI/Probability/SKSupport/Foundations/RightGenerator.lean @@ -0,0 +1,138 @@ +import Mathlib +import OAI.Probability.SKSupport.Diffusion.BoundedDiffusionProperties + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section +namespace ZeroTemperatureSK +open WeakIto Heat +variable {Ω : Type*} [MeasurableSpace Ω] + +theorem expected_hasDerivWithinAt_right (W : BrownianSystem Ω) (b : BoundedLipschitzDrift) + {F D : ℝ → ℝ → ℝ} (hF : BoundedSmoothFamily F) (hD : BoundedSmoothFamily D) + {T : ℝ} (he : ∀ a c, 0 ≤ a → a ≤ c → c ≤ T → ∀ x, + F c x-F a x = ∫ r in a..c, D r x) + (s : ℝ≥0) (hsT : (s:ℝ) < T) + (hDr : ∀ x, ContinuousWithinAt (fun r => D r x) (Ioi (s:ℝ)) s) + (hbr : ∀ᵐ ω ∂W.law, ContinuousWithinAt (fun r => b.pathDrift W r ω) (Ioi (s:ℝ)) s) : + HasDerivWithinAt + (fun t : ℝ => ∫ ω, F t (b.solution W.driver (Real.toNNReal t) ω) ∂W.law) + ((∫ ω, deriv (F s) (b.solution W.driver s ω)*b.pathDrift W s ω ∂W.law)+ + (1/2:ℝ)*(∫ ω, deriv (deriv (F s)) (b.solution W.driver s ω) ∂W.law)+ + (∫ ω, D s (b.solution W.driver s ω) ∂W.law)) (Ioi (s:ℝ)) s := by + let := W.isProbability + let Y := b.solution W.driver s + have hYm : Measurable Y := b.solution_measurable W s + obtain ⟨C₁,hC₁⟩ := hF.deriv.bound + obtain ⟨C₂,hC₂⟩ := hF.deriv.deriv.bound + obtain ⟨C₃,hC₃⟩ := hF.bounds 3 + obtain ⟨Ct,hCt⟩ := hD.bound + obtain ⟨L,hL⟩ := BoundedSmoothFamily_lipschitz hD + let Q (t : ℝ) := ∫ ω, F t (b.solution W.driver (Real.toNNReal t) ω) ∂W.law + let H : ℝ := ∫ ω, deriv (deriv (F s)) (Y ω) ∂W.law + let A (t : ℝ) := ∫ ω, deriv (F s) (Y ω)*b.displacement W s t ω ∂W.law + let J (t : ℝ) := ∫ ω, (∫ r in (s:ℝ)..t, D r (Y ω)) ∂W.law + let K (t : ℝ) := A t/(t-s)+(1/2:ℝ)*H+J t/(t-s) + have hcoeff : Measurable (fun ω => deriv (F s) (Y ω)) := + ((hF.deriv.regular s).smooth.continuous.measurable).comp hYm + have hma : Measurable (fun p : ℝ × Ω => deriv (F s) (Y p.2)*b.pathDrift W p.1 p.2) := + (hcoeff.comp measurable_snd).mul (b.pathDrift_measurable W) + have halim := expected_time_average_tendsto_right (P := W.law) hma + (mul_nonneg C₁.coe_nonneg b.bound.coe_nonneg) + (fun r ω => by + rw [abs_mul] + exact mul_le_mul (hC₁ s (Y ω)) (b.pathDrift_bound W r ω) (abs_nonneg _) C₁.coe_nonneg) + (s:ℝ) (by + filter_upwards [hbr] with ω hω + exact continuousWithinAt_const.mul hω) + have hAlim : Tendsto (fun t => A t/(t-s)) (𝓝[>] (s:ℝ)) + (𝓝 (∫ ω, deriv (F s) (Y ω)*b.pathDrift W s ω ∂W.law)) := by + convert halim using 1 + funext t + rw [← integral_div] + apply integral_congr_ae + filter_upwards [] with ω + rw [intervalIntegral.integral_const_mul] + rfl + have hmj : Measurable (fun p : ℝ × Ω => D p.1 (Y p.2)) := + hD.measurable.comp (measurable_fst.prodMk (hYm.comp measurable_snd)) + have hjlim := expected_time_average_tendsto_right (P := W.law) hmj Ct.coe_nonneg + (fun r ω => hCt r (Y ω)) (s:ℝ) (Eventually.of_forall (fun ω => hDr (Y ω))) + have hJlim : Tendsto (fun t => J t/(t-s)) (𝓝[>] (s:ℝ)) + (𝓝 (∫ ω, D s (Y ω) ∂W.law)) := by + convert hjlim using 1 + funext t + exact (integral_div (t-(s:ℝ)) _).symm + have hKlim := (hAlim.add_const ((1/2:ℝ)*H)).add hJlim + let E (t : ℝ) := (C₃:ℝ)/6*(Real.sqrt (t-s)*normalThirdMoment)+ + (C₂:ℝ)*(b.bound:ℝ)*(Real.sqrt (t-s)*normalFirstMoment+(b.bound:ℝ)*(t-s))+ + (L:ℝ)*(Real.sqrt (t-s)*normalFirstMoment+(b.bound:ℝ)*(t-s)) + have hzero : Tendsto (fun t : ℝ => t-(s:ℝ)) (𝓝[>] (s:ℝ)) (𝓝 0) := by + have hh : Tendsto (fun t : ℝ => t) (𝓝[>] (s:ℝ)) (𝓝 (s:ℝ)) := tendsto_id.mono_left nhdsWithin_le_nhds + simpa only [sub_self] using hh.sub_const (s:ℝ) + have hsqrt := hzero.sqrt + have hElim : Tendsto E (𝓝[>] (s:ℝ)) (𝓝 0) := by + have hbase := (hsqrt.mul_const normalFirstMoment).add (hzero.const_mul (b.bound:ℝ)) + simpa only [E,Real.sqrt_zero,zero_mul,mul_zero,add_zero] using + (((hsqrt.mul_const normalThirdMoment).const_mul ((C₃:ℝ)/6)).add + (hbase.const_mul ((C₂:ℝ)*(b.bound:ℝ)))).add (hbase.const_mul (L:ℝ)) + have hbound : ∀ᶠ t in 𝓝[>] (s:ℝ), |slope Q s t-K t| ≤ E t := by + filter_upwards [self_mem_nhdsWithin,mem_nhdsWithin_of_mem_nhds (gt_mem_nhds hsT)] with t hst htT + have hp : 0 < t-(s:ℝ) := sub_pos.mpr hst + let h := Real.toNNReal (t-(s:ℝ)) + have hcoe : (h:ℝ)=t-(s:ℝ) := Real.coe_toNNReal _ hp.le + have htime : (s:ℝ)+(h:ℝ)=t := by rw [hcoe]; ring + have hnn : s+h=Real.toNNReal t := by + apply NNReal.coe_injective + rw [NNReal.coe_add,htime,Real.coe_toNNReal _ (s.coe_nonneg.trans hst.le)] + have hstep := expected_integral_time_step W.brownian.toIsPreBrownianReal W.measurable s h + (b.solution_adapted W s) (b.solution_integrable W s) + (b.displacement_measurable W s (s+h)) b.bound + (fun ω => by + have hb := b.displacement_bound W (s:ℝ) ((s+h:ℝ≥0):ℝ) ω + simpa only [NNReal.coe_add,add_sub_cancel_left,abs_of_nonneg h.coe_nonneg] using hb) + hF hD C₁ C₂ C₃ L (hC₁ s) (hC₂ s) (hC₃ s) hL + (he s ((s:ℝ)+(h:ℝ)) s.coe_nonneg (by linarith [h.coe_nonneg]) (by rw [htime]; exact htT.le)) + have hsol : (∫ ω, F ((s:ℝ)+(h:ℝ)) + (b.solution W.driver s ω+(W.B (s+h) ω-W.B s ω)+b.displacement W s (s+h) ω) ∂W.law) = Q t := by + unfold Q + apply integral_congr_ae + filter_upwards [b.solution_increment W s h] with ω hω + rw [← hω,hnn,htime] + rw [hsol] at hstep + have hqs : (∫ ω, F s (b.solution W.driver s ω) ∂W.law) = Q s := by simp only [Q,Real.toNNReal_coe] + rw [hqs] at hstep + have hat : (∫ ω, deriv (F s) (b.solution W.driver s ω)*b.displacement W s (s+h) ω ∂W.law) = A t := by + simp only [A,Y,htime] + rw [hat,htime,hcoe] at hstep + change |Q t-Q s-A t-(t-(s:ℝ))/2*H-J t| ≤ _ at hstep + have heq : slope Q s t-K t = (Q t-Q s-A t-(t-(s:ℝ))/2*H-J t)/(t-s) := by + rw [slope_def_field] + dsimp only [K] + field_simp + ring + rw [heq,abs_div,abs_of_pos hp,div_le_iff₀ hp] + convert hstep using 1 + all_goals try dsimp only [E] + all_goals first | rfl | ring + have herr : Tendsto (fun t => slope Q s t-K t) (𝓝[>] (s:ℝ)) (𝓝 0) := by + rw [tendsto_zero_iff_norm_tendsto_zero] + apply squeeze_zero' (Eventually.of_forall (fun t => norm_nonneg _)) _ hElim + simpa only [Real.norm_eq_abs] using hbound + have hh := herr.add hKlim + apply (hasDerivWithinAt_iff_tendsto_slope' (show (s:ℝ) ∉ Ioi (s:ℝ) by simp)).mpr + convert hh using 1 + · funext t + dsimp only [K] at * + ring + · simp only [zero_add,H,Y] + +end ZeroTemperatureSK + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKSupport/Foundations/Semigroup.lean b/lean/OAI/Probability/SKSupport/Foundations/Semigroup.lean new file mode 100644 index 0000000000000000000000000000000000000000..2d49a520c3d89b64e2929a9795a0979b821d7f08 --- /dev/null +++ b/lean/OAI/Probability/SKSupport/Foundations/Semigroup.lean @@ -0,0 +1,181 @@ +import Mathlib +import OAI.Probability.SKSupport.Model + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology ContDiff +noncomputable section +namespace ZeroTemperatureSK.Heat + +def semigroup (h : ℝ≥0) (f : ℝ → ℝ) (x : ℝ) : ℝ := + ∫ y : ℝ, f (x+y) ∂gaussianReal 0 h + +def logSemigroup (c : ℝ) (h : ℝ≥0) (f : ℝ → ℝ) (x : ℝ) : ℝ := + if c = 0 then semigroup h f x else Real.log (semigroup h (fun z => Real.exp (c*f z)) x) / c + +lemma integrable_exp_abs (c : ℝ) (μ : ℝ) (h : ℝ≥0) : + Integrable (fun y : ℝ => Real.exp (c*|y|)) (gaussianReal μ h) := by + apply Integrable.mono' ((integrable_exp_mul_gaussianReal (μ := μ) (v := h) c).add + (integrable_exp_mul_gaussianReal (μ := μ) (v := h) (-c))) + (by fun_prop) + filter_upwards [] with y + rw [Real.norm_eq_abs, abs_of_pos (Real.exp_pos _)] + by_cases hy : 0 ≤ y + · rw [abs_of_nonneg hy] + exact le_add_of_nonneg_right (Real.exp_nonneg _) + · rw [abs_of_neg (lt_of_not_ge hy)] + have he : c*(-y) = (-c)*y := by ring + rw [he] + exact le_add_of_nonneg_left (Real.exp_nonneg _) + +lemma integrable_translate_of_lipschitz {f : ℝ → ℝ} {K : ℝ≥0} + (hf : LipschitzWith K f) (h : ℝ≥0) (x : ℝ) : + Integrable (fun y => f (x+y)) (gaussianReal 0 h) := by + apply Integrable.mono' ((integrable_const ‖f x‖).add + (((memLp_id_gaussianReal (μ := 0) (v := h) 1).integrable (by simp)).norm.const_mul (K:ℝ))) + (hf.continuous.measurable.comp (measurable_const.add measurable_id) |>.aestronglyMeasurable) + filter_upwards [] with y + have hb := hf.norm_sub_le (x+y) x + have hh := norm_sub_le (f (x+y)) (f x) + have hh' := norm_add_le (f (x+y)-f x) (f x) + simp only [add_sub_cancel_left, sub_add_cancel] at hb hh' + change ‖f (x+y)‖ ≤ ‖f x‖+(K:ℝ)*‖y‖ + linarith + +lemma integrable_exp_translate_of_lipschitz {f : ℝ → ℝ} {K : ℝ≥0} + (hf : LipschitzWith K f) (c : ℝ) (h : ℝ≥0) (x : ℝ) : + Integrable (fun y => Real.exp (c*f (x+y))) (gaussianReal 0 h) := by + apply Integrable.mono' ((integrable_exp_abs (|c| * (K:ℝ)) 0 h).const_mul (Real.exp (c*f x))) + ((measurable_const.mul (hf.continuous.measurable.comp (measurable_const.add measurable_id))).exp.aestronglyMeasurable) + filter_upwards [] with y + rw [Real.norm_eq_abs, abs_of_pos (Real.exp_pos _), ← Real.exp_add] + apply Real.exp_le_exp.mpr + have h₁ := hf.norm_sub_le (x+y) x + simp only [Real.norm_eq_abs, add_sub_cancel_left] at h₁ + have h₂ : c*(f (x+y)-f x) ≤ |c| * |f (x+y)-f x| := by + calc + _ ≤ |c*(f (x+y)-f x)| := le_abs_self _ + _ = _ := abs_mul _ _ + have h₃ := mul_le_mul_of_nonneg_left h₁ (abs_nonneg c) + change c*f (x+y) ≤ c*f x+(|c| * (K:ℝ))*|y| + nlinarith + +lemma semigroup_exp_pos {f : ℝ → ℝ} {K : ℝ≥0} + (hf : LipschitzWith K f) (c : ℝ) (h : ℝ≥0) (x : ℝ) : + 0 < semigroup h (fun z => Real.exp (c*f z)) x := by + unfold semigroup + exact integral_pos_iff_support_of_nonneg (fun y => (Real.exp_pos _).le) + (integrable_exp_translate_of_lipschitz hf c h x) |>.mpr (by simp [Function.support]) + +end ZeroTemperatureSK.Heat + +namespace ZeroTemperatureSK.Heat + +lemma semigroup_lipschitz {f : ℝ → ℝ} {K : ℝ≥0} + (hf : LipschitzWith K f) (h : ℝ≥0) : LipschitzWith K (semigroup h f) := by + apply LipschitzWith.of_dist_le_mul + intro x z + rw [Real.dist_eq, Real.dist_eq] + unfold semigroup + rw [← integral_sub (integrable_translate_of_lipschitz hf h x) + (integrable_translate_of_lipschitz hf h z)] + calc + _ ≤ ∫ y, |f (x+y)-f (z+y)| ∂gaussianReal 0 h := abs_integral_le_integral_abs + _ ≤ ∫ _y, (K:ℝ)*|x-z| ∂gaussianReal 0 h := by + apply integral_mono ((integrable_translate_of_lipschitz hf h x).sub + (integrable_translate_of_lipschitz hf h z)).abs (integrable_const _) + intro y + change |f (x+y)-f (z+y)| ≤ (K:ℝ)*|x-z| + simpa only [Real.norm_eq_abs, add_sub_add_right_eq_sub] using hf.norm_sub_le (x+y) (z+y) + _ = _ := by simp + +lemma logSemigroup_sub_le {f : ℝ → ℝ} {K : ℝ≥0} + (hf : LipschitzWith K f) {c : ℝ} (hc : 0 < c) (h : ℝ≥0) (x z : ℝ) : + logSemigroup c h f x-logSemigroup c h f z ≤ (K:ℝ)*|x-z| := by + have hx := semigroup_exp_pos hf c h x + have hz := semigroup_exp_pos hf c h z + have hE : semigroup h (fun w => Real.exp (c*f w)) x ≤ + Real.exp (c*((K:ℝ)*|x-z|))*semigroup h (fun w => Real.exp (c*f w)) z := by + unfold semigroup + rw [← integral_const_mul] + apply integral_mono (integrable_exp_translate_of_lipschitz hf c h x) + ((integrable_exp_translate_of_lipschitz hf c h z).const_mul _) + intro y + change Real.exp (c*f (x+y)) ≤ Real.exp (c*((K:ℝ)*|x-z|))*Real.exp (c*f (z+y)) + rw [← Real.exp_add] + apply Real.exp_le_exp.mpr + have hh := hf.norm_sub_le (x+y) (z+y) + simp only [Real.norm_eq_abs, add_sub_add_right_eq_sub] at hh + have hh' := (le_abs_self (f (x+y)-f (z+y))).trans hh + nlinarith + have hlog := Real.log_le_log hx hE + rw [Real.log_mul (Real.exp_ne_zero _) (ne_of_gt hz), Real.log_exp] at hlog + simp only [logSemigroup, ne_of_gt hc, ↓reduceIte] + rw [← sub_div, div_le_iff₀ hc] + nlinarith + +lemma logSemigroup_lipschitz {f : ℝ → ℝ} {K : ℝ≥0} + (hf : LipschitzWith K f) {c : ℝ} (hc : 0 ≤ c) (h : ℝ≥0) : + LipschitzWith K (logSemigroup c h f) := by + by_cases hc0 : c = 0 + · subst c + have he : logSemigroup 0 h f = semigroup h f := by + funext x + simp only [logSemigroup, ↓reduceIte] + rw [he] + exact semigroup_lipschitz hf h + · have hcp : 0 < c := lt_of_le_of_ne hc (Ne.symm hc0) + apply LipschitzWith.of_dist_le_mul + intro x z + rw [Real.dist_eq, Real.dist_eq, abs_le] + constructor + · have he := logSemigroup_sub_le hf hcp h z x + rw [abs_sub_comm z x] at he + linarith + · exact logSemigroup_sub_le hf hcp h x z + +lemma semigroup_even {f : ℝ → ℝ} (hf : Measurable f) (he : Function.Even f) + (h : ℝ≥0) : Function.Even (semigroup h f) := by + intro x + have hn : HasLaw (fun y : ℝ => -y) (gaussianReal 0 h) (gaussianReal 0 h) := by + constructor + · exact measurable_neg.aemeasurable + · simpa using gaussianReal_map_neg (μ := 0) (v := h) + have hh := hn.integral_comp (f := fun y => f (-x+y)) + (hf.comp (measurable_const.add measurable_id) |>.aestronglyMeasurable) + change (∫ y : ℝ, f (-x + -y) ∂gaussianReal 0 h) = semigroup h f (-x) at hh + rw [← hh] + unfold semigroup + apply integral_congr_ae + filter_upwards [] with y + rw [← neg_add, he] + +lemma logSemigroup_even {f : ℝ → ℝ} (hf : Measurable f) (he : Function.Even f) + (c : ℝ) (h : ℝ≥0) : Function.Even (logSemigroup c h f) := by + intro x + by_cases hc : c = 0 + · simp only [logSemigroup, hc, ↓reduceIte, semigroup_even hf he h x] + · have hhe : Function.Even (fun z => Real.exp (c*f z)) := by + intro z + change Real.exp (c*f (-z)) = Real.exp (c*f z) + rw [he] + simp only [logSemigroup, hc, ↓reduceIte] + exact congrArg (fun v : ℝ => Real.log v/c) + (semigroup_even (measurable_const.mul hf |>.exp) hhe h x) + +end ZeroTemperatureSK.Heat + +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKSupport/Foundations/SmoothingStep.lean b/lean/OAI/Probability/SKSupport/Foundations/SmoothingStep.lean new file mode 100644 index 0000000000000000000000000000000000000000..94d946dbc10b683b31186c90de3210be46819917 --- /dev/null +++ b/lean/OAI/Probability/SKSupport/Foundations/SmoothingStep.lean @@ -0,0 +1,122 @@ +import Mathlib +import OAI.Probability.SKSupport.Foundations.VarianceHeatGradientBound + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology ContDiff +noncomputable section +open MeasureTheory Set Filter +open scoped Topology +noncomputable section +namespace ZeroTemperatureSK.Heat +open ZeroTemperatureSK.Smoothing + +lemma exists_smoothing_step {D δ : ℝ} (hD : 0 ≤ D) (hδ : 0 < δ) : + ∃ η : ℝ, 0 < η ∧ η ≤ δ/2 ∧ + 8*kernelConstant*D*Real.sqrt η ≤ 1/2 := by + have hκ := kernelConstant_nonneg + let q : ℝ := 1/(16*(kernelConstant*D+1)) + have hq : 0 < q := by dsimp [q]; positivity + let η := min (δ/2) (q^2) + have hη : 0 < η := lt_min (by positivity) (sq_pos_of_pos hq) + refine ⟨η,hη,min_le_left _ _,?_⟩ + have hs : Real.sqrt η ≤ q := Real.sqrt_le_iff.mpr ⟨hq.le,min_le_right _ _⟩ + calc + 8*kernelConstant*D*Real.sqrt η ≤ 8*kernelConstant*D*q := + mul_le_mul_of_nonneg_left hs (by positivity) + _ = (8*kernelConstant*D)/(16*(kernelConstant*D+1)) := by dsimp [q]; ring + _ ≤ 1/2 := (div_le_iff₀ (by positivity)).mpr (by nlinarith) + +theorem finiteGradient_uniform_smoothing (m : ℕ) (D : ℝ) (hD : 0 ≤ D) : + ∀ δ : ℝ, 0 < δ → ∃ C : ℝ, 0 ≤ C ∧ + ∀ (f : ℝ → ℝ), RegularDatum f → LipschitzWith 1 f → + ∀ (c : ℕ → ℝ≥0) (h : ℝ≥0) (N i : ℕ) (L : ℝ), 0 ≤ L → + L+δ ≤ (N:ℝ)*h → + (∀ s ∈ Icc (0:ℝ) (L+δ), finiteCoeff c h N i s ≤ D) → + ∀ j ≤ m, ∀ t ∈ Icc (0:ℝ) L, ∀ x : ℝ, + |iteratedDeriv j (deriv (finiteValue c h f N i t)) x| ≤ C := by + induction m with + | zero => + intro δ hδ + refine ⟨1,by positivity,?_⟩ + intro f hf hLip c h N i L hL hhor hcoef j hj t ht x + have hj0 : j = 0 := by omega + subst j + simpa only [iteratedDeriv_zero,Real.norm_eq_abs,NNReal.coe_one] using + norm_deriv_le_of_lipschitz (x₀ := x) (finiteValue_lipschitz hLip c h N i t) + | succ m ih => + intro δ hδ + obtain ⟨C,hC,hbounds⟩ := ih (δ/2) (by positivity) + obtain ⟨η,hη,hηδ,hηsmall⟩ := exists_smoothing_step hD hδ + let R : ℝ := D*(∑ j ∈ Finset.range m,(m.choose (j+1):ℝ))*C^2 + have hR : 0 ≤ R := by dsimp [R]; positivity + let K : ℝ := 2*kernelConstant*(C+2*R*η)/Real.sqrt η + have hκ := kernelConstant_nonneg + have hK : 0 ≤ K := by dsimp [K]; positivity + refine ⟨max C K,le_max_of_le_left hC,?_⟩ + intro f hf hLip c h N i L hL hhor hcoef j hj t ht x + have hlow : ∀ k ≤ m, ∀ s ∈ Icc (0:ℝ) (L+δ/2), ∀ z : ℝ, + |iteratedDeriv k (deriv (finiteValue c h f N i s)) z| ≤ C := by + apply hbounds f hf hLip c h N i (L+δ/2) (by positivity) + · linarith + · intro s hs + apply hcoef s + constructor + · exact hs.1 + · linarith [hs.2] + by_cases hjm : j ≤ m + · exact (hlow j hjm t ⟨ht.1,by linarith [ht.2]⟩ x).trans (le_max_left _ _) + have hje : j = m+1 := by omega + subst j + let V : ℝ → ℝ → ℝ := fun r => iteratedDeriv m (deriv (finiteValue c h f N i r)) + let G : ℝ → ℝ → ℝ := fun r => iteratedDeriv m (finiteBurgersSource c h f N i r) + have hU := finiteGradient_family hf hLip c h N i + have hS := finiteBurgersSource_family hf hLip c h N i + have hV : BoundedSmoothFamily V := hU.iteratedDeriv m + have hG : BoundedSmoothFamily G := hS.iteratedDeriv m + obtain ⟨A₀,hA₀⟩ := hG.bound + obtain ⟨B₀,hB₀⟩ := hG.deriv.bound + obtain ⟨C₀,hC₀⟩ := hV.deriv.bound + have htb : t < t+η := by linarith + have hbL : t+η ≤ L+δ/2 := by linarith [ht.2] + have hbhor : t+η ≤ (N:ℝ)*h := by linarith + have hterminal (z : ℝ) : |V (t+η) z| ≤ C := + hlow m le_rfl (t+η) ⟨by linarith [ht.1],hbL⟩ z + have hsource (r : ℝ) (hr : r ∈ Icc t (t+η)) (z : ℝ) : + |G r z| ≤ D*|deriv (V r) z|+R := by + apply iteratedDeriv_finiteBurgersSource_bound hf hLip c h N i m hC hD + · apply hcoef r + exact ⟨ht.1.trans hr.1,by linarith [hr.2]⟩ + · intro k hk y + exact hlow k hk r ⟨ht.1.trans hr.1,hr.2.trans hbL⟩ y + have hmild (r : ℝ) (hr : r ∈ Ico t (t+η)) (z : ℝ) : + V r z = varianceHeat (t+η-r) (V (t+η)) z+ + ∫ s in r..t+η, varianceHeat (s-r) (G s) z := by + exact iteratedDeriv_mild hU hS (finiteGradient_mild hf hLip c h N i + (ht.1.trans hr.1) hr.2.le hbhor) m z + have hshort : 8*kernelConstant*D*Real.sqrt (t+η-t) ≤ 1/2 := by + simpa only [add_sub_cancel_left] using hηsmall + have hbound := uniform_gradient_bound_of_mild htb hC hD hR + (hV.regular (t+η)) hG.measurable hG.regular hA₀ hB₀ + (fun r _ z => hC₀ r z) hterminal hsource hmild hshort x + apply (show |iteratedDeriv (m+1) (deriv (finiteValue c h f N i t)) x| ≤ K from ?_).trans + (le_max_right _ _) + simpa only [V,K,iteratedDeriv_succ,add_sub_cancel_left] using hbound + +end ZeroTemperatureSK.Heat + +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKSupport/Foundations/SoftAbs.lean b/lean/OAI/Probability/SKSupport/Foundations/SoftAbs.lean new file mode 100644 index 0000000000000000000000000000000000000000..d44ac5a22b929c298669e619abbb3b15c13e4ac0 --- /dev/null +++ b/lean/OAI/Probability/SKSupport/Foundations/SoftAbs.lean @@ -0,0 +1,211 @@ +import Mathlib +import OAI.Probability.SKSupport.Foundations.BoundedSmooth + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology ContDiff +noncomputable section +namespace ZeroTemperatureSK.Heat + +lemma boundedSmooth_of_polynomial_deriv {f : ℝ → ℝ} (hf : ContDiff ℝ ∞ f) + {C : ℝ≥0} (hC : ∀ x, |f x| ≤ C) (P : Polynomial ℝ) + (hD : ∀ x, deriv f x = P.eval (f x)) : BoundedSmooth f := by + have hrepr : ∀ n : ℕ, ∃ Q : Polynomial ℝ, iteratedDeriv n f = fun x => Q.eval (f x) := by + intro n + induction n with + | zero => exact ⟨Polynomial.X, by funext x; simp⟩ + | succ n IH => + obtain ⟨Q,hQ⟩ := IH + refine ⟨Q.derivative*P, ?_⟩ + rw [iteratedDeriv_succ, hQ] + funext x + have hd := (Q.hasDerivAt (f x)).comp x ((hf.differentiable (by simp) x).hasDerivAt) + simpa only [Function.comp_def, hD, Polynomial.eval_mul] using hd.deriv + refine ⟨hf, fun n => ?_⟩ + obtain ⟨Q,hQ⟩ := hrepr n + obtain ⟨R,hR⟩ := (isCompact_Icc : IsCompact (Set.Icc (-(C:ℝ)) C)).bddAbove_image + Q.continuous.abs.continuousOn + refine ⟨Real.toNNReal R, fun x => ?_⟩ + rw [hQ] + have hb : |Q.eval (f x)| ≤ R := hR ⟨f x, abs_le.mp (hC x), rfl⟩ + exact hb.trans (Real.le_coe_toNNReal R) + +lemma contDiff_tanh : ContDiff ℝ ∞ Real.tanh := by + have he : Real.tanh = fun x => Real.sinh x/Real.cosh x := funext Real.tanh_eq_sinh_div_cosh + rw [he] + exact Real.contDiff_sinh.div Real.contDiff_cosh (fun x => ne_of_gt (Real.cosh_pos x)) + +lemma hasDerivAt_tanh (x : ℝ) : HasDerivAt Real.tanh (1-(Real.tanh x)^2) x := by + have hne := ne_of_gt (Real.cosh_pos x) + have hd := (Real.hasDerivAt_sinh x).div (Real.hasDerivAt_cosh x) hne + have he : Real.tanh = fun y => Real.sinh y/Real.cosh y := funext Real.tanh_eq_sinh_div_cosh + rw [he] + convert hd using 1 + field_simp + +lemma boundedSmooth_tanh_mul (M : ℝ) : BoundedSmooth (fun x => Real.tanh (M*x)) := by + apply boundedSmooth_of_polynomial_deriv + (contDiff_tanh.comp (contDiff_const.mul contDiff_id)) + (C := 1) (fun x => (Real.abs_tanh_lt_one (M*x)).le) + (Polynomial.C M*(1-Polynomial.X^2)) + intro x + have hd := (hasDerivAt_tanh (M*x)).comp x ((hasDerivAt_id x).const_mul M) + simp only [Function.comp_def, mul_one] at hd + convert hd.deriv using 1 <;> try rfl + all_goals + try simp only [Polynomial.eval_mul, Polynomial.eval_C, + Polynomial.eval_sub, Polynomial.eval_one, Polynomial.eval_pow, Polynomial.eval_X, + Function.comp_def, id_eq] + ring + +def softAbs (M : ℝ) (x : ℝ) := Real.log (2*Real.cosh (M*x))/M + +lemma hasDerivAt_softAbs {M : ℝ} (hM : M ≠ 0) (x : ℝ) : + HasDerivAt (softAbs M) (Real.tanh (M*x)) x := by + have hn : 2*Real.cosh (M*x) ≠ 0 := mul_ne_zero (by norm_num) (ne_of_gt (Real.cosh_pos _)) + have hd := ((((Real.hasDerivAt_cosh (M*x)).comp x ((hasDerivAt_id x).const_mul M)).const_mul 2).log hn).div_const M + simp only [Function.comp_def, mul_one] at hd + convert hd using 1 <;> try rfl + rw [Real.tanh_eq_sinh_div_cosh] + field_simp [hM, ne_of_gt (Real.cosh_pos (M*x))] + +lemma regularDatum_softAbs {M : ℝ} (hM : M ≠ 0) : RegularDatum (softAbs M) := by + constructor + · exact ((contDiff_const.mul (Real.contDiff_cosh.comp (contDiff_const.mul contDiff_id))).log + (fun x => mul_ne_zero (by norm_num) (ne_of_gt (Real.cosh_pos _)))).div_const M + · have he : deriv (softAbs M) = fun x => Real.tanh (M*x) := funext (fun x => (hasDerivAt_softAbs hM x).deriv) + rw [he] + exact boundedSmooth_tanh_mul M + +lemma softAbs_lipschitz {M : ℝ} (hM : M ≠ 0) : LipschitzWith 1 (softAbs M) := by + apply lipschitzWith_of_nnnorm_deriv_le (fun x => (hasDerivAt_softAbs hM x).differentiableAt) + intro x + apply NNReal.coe_le_coe.mp + simpa only [coe_nnnorm, Real.norm_eq_abs, NNReal.coe_one, (hasDerivAt_softAbs hM x).deriv] using + (Real.abs_tanh_lt_one (M*x)).le + +lemma softAbs_even (M : ℝ) : Function.Even (softAbs M) := by + intro x + simp [softAbs, Real.cosh_neg] + +lemma exp_abs_bounds (y : ℝ) : + Real.exp |y| ≤ Real.exp y+Real.exp (-y) ∧ + Real.exp y+Real.exp (-y) ≤ 2*Real.exp |y| := by + constructor + · by_cases hy : 0 ≤ y + · rw [abs_of_nonneg hy] + exact le_add_of_nonneg_right (Real.exp_nonneg _) + · rw [abs_of_neg (lt_of_not_ge hy)] + exact le_add_of_nonneg_left (Real.exp_nonneg _) + · have h₁ := Real.exp_le_exp.mpr (le_abs_self y) + have h₂ := Real.exp_le_exp.mpr (neg_le_abs y) + linarith + +lemma softAbs_bounds {M : ℝ} (hM : 0 < M) (x : ℝ) : + 0 ≤ softAbs M x-|x| ∧ softAbs M x-|x| ≤ Real.log 2/M := by + have hb := exp_abs_bounds (M*x) + have habs : |M*x| = M*|x| := by rw [abs_mul, abs_of_nonneg hM.le] + rw [habs] at hb + have hc : 2*Real.cosh (M*x) = Real.exp (M*x)+Real.exp (-(M*x)) := by rw [Real.cosh_eq]; ring + have hlo := Real.log_le_log (Real.exp_pos _) hb.1 + have hhi := Real.log_le_log (add_pos (Real.exp_pos _) (Real.exp_pos _)) hb.2 + rw [Real.log_exp] at hlo + rw [Real.log_mul (by norm_num : (2:ℝ) ≠ 0) (ne_of_gt (Real.exp_pos _)), Real.log_exp] at hhi + dsimp only [softAbs] + rw [hc] + constructor + · apply sub_nonneg.mpr + apply (le_div_iff₀ hM).mpr + nlinarith + · apply (sub_le_iff_le_add).mpr + apply (div_le_iff₀ hM).mpr + field_simp + nlinarith + +end ZeroTemperatureSK.Heat + +namespace ZeroTemperatureSK.Heat + +lemma semigroup_add {g : ℝ → ℝ} (h k : ℝ≥0) (x : ℝ) + (hg : Integrable (fun y => g (x+y)) (gaussianReal 0 (h+k))) : + semigroup (h+k) g x = semigroup h (semigroup k g) x := by + have he : gaussianReal 0 (h+k) = (gaussianReal 0 h) ∗ (gaussianReal 0 k) := by + simpa only [zero_add] using (gaussianReal_conv_gaussianReal (m₁ := 0) (m₂ := 0) + (v₁ := h) (v₂ := k)).symm + rw [he] at hg + have hh := integral_conv hg + simpa only [← he, semigroup, add_assoc] using hh + +lemma logSemigroup_add {f : ℝ → ℝ} {K : ℝ≥0} (hf : LipschitzWith K f) + (c : ℝ) (h k : ℝ≥0) (x : ℝ) : + logSemigroup c (h+k) f x = logSemigroup c h (logSemigroup c k f) x := by + by_cases hc : c = 0 + · subst c + have he : logSemigroup 0 k f = semigroup k f := by funext z; simp [logSemigroup] + simp only [logSemigroup, ↓reduceIte, he] + exact semigroup_add h k x (integrable_translate_of_lipschitz hf (h+k) x) + · have he : (fun z => Real.exp (c*logSemigroup c k f z)) = + semigroup k (fun z => Real.exp (c*f z)) := by + funext z + simp only [logSemigroup, hc, ↓reduceIte] + rw [mul_div_cancel₀ _ hc, Real.exp_log (semigroup_exp_pos hf c k z)] + rw [logSemigroup, ite_eq_right hc, logSemigroup, ite_eq_right hc, he] + rw [semigroup_add h k x (integrable_exp_translate_of_lipschitz hf c (h+k) x)] + +lemma logSemigroup_terminal_domination {f g : ℝ → ℝ} {K J : ℝ≥0} + (hf : LipschitzWith K f) (hg : LipschitzWith J g) {c : ℝ} (hc : 0 ≤ c) + {δ : ℝ} (hδ : ∀ z, f z ≤ g z+δ) (h : ℝ≥0) (x : ℝ) : + logSemigroup c h f x ≤ logSemigroup c h g x+δ := by + by_cases hc0 : c = 0 + · subst c + simp only [logSemigroup, ↓reduceIte] + have hh := integral_mono (integrable_translate_of_lipschitz hf h x) + ((integrable_translate_of_lipschitz hg h x).add (integrable_const δ)) (fun y => hδ (x+y)) + change (∫ y, f (x+y) ∂gaussianReal 0 h) ≤ (∫ y, g (x+y)+δ ∂gaussianReal 0 h) at hh + rw [integral_add (integrable_translate_of_lipschitz hg h x) (integrable_const δ)] at hh + simpa [semigroup, integral_const, Measure.real] using hh + · have hcp := lt_of_le_of_ne hc (Ne.symm hc0) + have hE : semigroup h (fun z => Real.exp (c*f z)) x ≤ + Real.exp (c*δ)*semigroup h (fun z => Real.exp (c*g z)) x := by + unfold semigroup + rw [← integral_const_mul] + apply integral_mono (integrable_exp_translate_of_lipschitz hf c h x) + ((integrable_exp_translate_of_lipschitz hg c h x).const_mul _) + intro y + change Real.exp (c*f (x+y)) ≤ Real.exp (c*δ)*Real.exp (c*g (x+y)) + rw [← Real.exp_add] + apply Real.exp_le_exp.mpr + nlinarith [hδ (x+y)] + have hh := Real.log_le_log (semigroup_exp_pos hf c h x) hE + rw [Real.log_mul (Real.exp_ne_zero _) (ne_of_gt (semigroup_exp_pos hg c h x)), Real.log_exp] at hh + simp only [logSemigroup, hc0, ↓reduceIte] + apply (div_le_iff₀ hcp).mpr + field_simp + nlinarith + +lemma logSemigroup_terminal_stability {f g : ℝ → ℝ} {K J : ℝ≥0} + (hf : LipschitzWith K f) (hg : LipschitzWith J g) {c : ℝ} (hc : 0 ≤ c) + {δ : ℝ} (hδ : ∀ z, |f z-g z| ≤ δ) (h : ℝ≥0) (x : ℝ) : + |logSemigroup c h f x-logSemigroup c h g x| ≤ δ := by + have h₁ := logSemigroup_terminal_domination hf hg hc (δ := δ) + (fun z => by linarith [(abs_le.mp (hδ z)).2]) h x + have h₂ := logSemigroup_terminal_domination hg hf hc (δ := δ) + (fun z => by linarith [(abs_le.mp (hδ z)).1]) h x + exact abs_le.mpr ⟨by linarith, by linarith⟩ + +end ZeroTemperatureSK.Heat + +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKSupport/Foundations/StepData.lean b/lean/OAI/Probability/SKSupport/Foundations/StepData.lean new file mode 100644 index 0000000000000000000000000000000000000000..5db04d4ac5de257e4308818935d1efdd0843ec1f --- /dev/null +++ b/lean/OAI/Probability/SKSupport/Foundations/StepData.lean @@ -0,0 +1,307 @@ +import Mathlib +import OAI.Probability.SKSupport.Diffusion.VariableFeedbackEuler +import OAI.Probability.SKSupport.Foundations.SumRangeBlocks +import OAI.Probability.SKSupport.Foundations.Cascade + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology ContDiff +noncomputable section +open MeasureTheory Set Filter +open scoped Topology +noncomputable section +namespace ZeroTemperatureSK.FiniteVerification +open Heat WeakIto +variable {Ω : Type*} [mΩ : MeasurableSpace Ω] {P : Measure Ω} {B : ℝ≥0 → Ω → ℝ} + +structure StepData (N : ℕ) (h : ℝ≥0) (c : ℕ → ℝ≥0) (F D : ℕ → ℝ → ℝ → ℝ) where + C₂ : ℝ≥0 + C₃ : ℝ≥0 + Ct : ℝ≥0 + L : ℝ≥0 + Γ : ℝ≥0 + smooth : ∀ k t, ContDiff ℝ 3 (F k t) + gradient_bound : ∀ k t z, |deriv (F k t) z| ≤ 1 + seam : ∀ k < N, F k (((k+1:ℕ):ℝ)*(h:ℝ)) = F (k+1) (((k+1:ℕ):ℝ)*(h:ℝ)) + coefficient_bound : ∀ k < N, c k ≤ Γ + second_bound : ∀ k < N, ∀ t z, |deriv (deriv (F k t)) z| ≤ C₂ + third_bound : ∀ k < N, ∀ t z, |iteratedDeriv 3 (F k t) z| ≤ C₃ + rate_measurable : ∀ k t, Measurable (D k t) + rate_bound : ∀ k < N, ∀ t z, |D k t z| ≤ Ct + time_derivative : ∀ k < N, ∀ r ∈ Set.Icc ((k:ℝ)*(h:ℝ)) (((k:ℝ)+1)*(h:ℝ)), ∀ z, + HasDerivWithinAt (fun t => F k t z) (D k r z) + (Set.Icc ((k:ℝ)*(h:ℝ)) (((k:ℝ)+1)*(h:ℝ))) r + rate_joint : ∀ k < N, ∀ r ∈ Set.Icc ((k:ℝ)*(h:ℝ)) (((k:ℝ)+1)*(h:ℝ)), + ∀ s ∈ Set.Icc ((k:ℝ)*(h:ℝ)) (((k:ℝ)+1)*(h:ℝ)), ∀ z y, + |D k r z-D k s y| ≤ (L:ℝ)*(|r-s|+|z-y|) + pde : ∀ k < N, ∀ t ∈ Set.Icc ((k:ℝ)*(h:ℝ)) (((k:ℝ)+1)*(h:ℝ)), ∀ z, + D k t z+(1/2:ℝ)*deriv (deriv (F k t)) z+(c k:ℝ)/2*(deriv (F k t) z)^2 = 0 + +noncomputable def cellHeat_stepData {f : ℝ → ℝ} (hf : RegularDatum f) (hLip : LipschitzWith 1 f) + (c : ℕ → ℝ≥0) (h : ℝ≥0) (N : ℕ) : + StepData N h c (cellHeat c h f N) (cellRate c h f N) := by + classical + have hd (k : ℕ) := cellHeat_verificationData hf hLip c h N k + have hb (k : ℕ) := (hd k).bounds + choose C₂ C₃ Ct L H using hb + refine ⟨(Finset.range N).sup C₂, (Finset.range N).sup C₃, + (Finset.range N).sup Ct, (Finset.range N).sup L, (Finset.range N).sup c, + fun k => (hd k).smooth, fun k => (hd k).gradient_bound, + cellHeat_seam hf hLip c h N, ?_,?_,?_,?_,?_,?_,?_,?_⟩ + · intro k hk + exact Finset.le_sup (f := c) (Finset.mem_range.mpr hk) + · intro k hk t z + exact ((H k).1 t z).trans (by exact_mod_cast Finset.le_sup (f := C₂) (Finset.mem_range.mpr hk)) + · intro k hk t z + exact ((H k).2.1 t z).trans (by exact_mod_cast Finset.le_sup (f := C₃) (Finset.mem_range.mpr hk)) + · exact fun k => (H k).2.2.1 + · intro k hk t z + exact ((H k).2.2.2.1 t z).trans (by exact_mod_cast Finset.le_sup (f := Ct) (Finset.mem_range.mpr hk)) + · intro k hk r hr z + have hs : Set.Icc ((k:ℝ)*(h:ℝ)) (((k:ℝ)+1)*(h:ℝ)) ⊆ + Set.Icc (0:ℝ) ((min (k+1) N:ℕ)*h) := by + intro s hs + rw [Nat.min_eq_left (by omega : k+1 ≤ N)] + constructor + · exact le_trans (mul_nonneg (Nat.cast_nonneg k) h.coe_nonneg) hs.1 + · simpa only [Nat.cast_add, Nat.cast_one] using hs.2 + exact ((H k).2.2.2.2.1 r (hs hr) z).mono hs + · intro k hk r hr s hs z y + have hsub : Set.Icc ((k:ℝ)*(h:ℝ)) (((k:ℝ)+1)*(h:ℝ)) ⊆ + Set.Icc (0:ℝ) ((min (k+1) N:ℕ)*h) := by + intro t ht + rw [Nat.min_eq_left (by omega : k+1 ≤ N)] + constructor + · exact le_trans (mul_nonneg (Nat.cast_nonneg k) h.coe_nonneg) ht.1 + · simpa only [Nat.cast_add, Nat.cast_one] using ht.2 + exact ((H k).2.2.2.2.2.1 r (hsub hr) s (hsub hs) z y).trans (by + gcongr + exact_mod_cast Finset.le_sup (f := L) (Finset.mem_range.mpr hk)) + · intro k hk t ht z + apply (H k).2.2.2.2.2.2 t + · rw [Nat.min_eq_left (by omega : k+1 ≤ N)] + constructor + · exact le_trans (mul_nonneg (Nat.cast_nonneg k) h.coe_nonneg) ht.1 + · simpa only [Nat.cast_add, Nat.cast_one] using ht.2 + +def profit (B : ℝ≥0 → Ω → ℝ) (α : ℝ≥0 → Ω → ℝ) (h : ℝ≥0) (c : ℕ → ℝ≥0) + (f : ℝ → ℝ) (x : ℝ) (N : ℕ) : ℝ := + (∫ ξ, f (controlledGrid B α h c x N ξ) ∂P)- + ∑ k ∈ Finset.range N, ∫ ξ, stepCost (fun r => α (Real.toNNReal r)) ((k:ℝ≥0)*h) h (c k) ξ ∂P + +def objectives (hm : ∀ t, Measurable (B t)) (h : ℝ≥0) (c : ℕ → ℝ≥0) + (f : ℝ → ℝ) (x : ℝ) (N : ℕ) : Set ℝ := + {v | ∃ α : ℝ≥0 → Ω → ℝ, + IsProgressive (Filtration.natural B (fun t => (hm t).stronglyMeasurable)) α ∧ + (∀ t ξ, |α t ξ| ≤ 1) ∧ v = profit (P := P) B α h c f x N} + +lemma objectives_nonempty (hm : ∀ t, Measurable (B t)) (h : ℝ≥0) (c : ℕ → ℝ≥0) + (f : ℝ → ℝ) (x : ℝ) (N : ℕ) : (objectives (P := P) hm h c f x N).Nonempty := by + exact ⟨_, fun _ _ => 0, isProgressive_const _ _, by simp, rfl⟩ + +lemma profit_refinement [IsProbabilityMeasure P] {α : ℝ≥0 → Ω → ℝ} + (ham : Measurable (fun p : ℝ≥0 × Ω => α p.1 p.2)) (hab : ∀ t ξ, |α t ξ| ≤ 1) + (h : ℝ≥0) (c : ℕ → ℝ≥0) (f : ℝ → ℝ) (x : ℝ) (N m : ℕ) (hmpos : 0 < m) : + profit (P := P) B α (h/(m:ℝ≥0)) (fun j => c (j/m)) f x (N*m) = + profit (P := P) B α h c f x N := by + have ham' : Measurable (fun p : ℝ × Ω => α (Real.toNNReal p.1) p.2) := + ham.comp (measurable_fst.real_toNNReal.prodMk measurable_snd) + unfold profit + congr 1 + · apply integral_congr_ae + filter_upwards [] with ξ + rw [controlledGrid_refinement B ham hab h c x N m hmpos ξ] + · have hi (d a : ℝ≥0) (s : ℝ) : Integrable (stepCost (fun r => α (Real.toNNReal r)) s d a) P := + stepCost_integrable (α := fun r => α (Real.toNNReal r)) ham' (fun r ξ => hab _ ξ) s d a d.coe_nonneg a.coe_nonneg + rw [← integral_finsetSum (Finset.range (N*m)) (fun j _ => hi _ _ _), + ← integral_finsetSum (Finset.range N) (fun k _ => hi _ _ _)] + apply integral_congr_ae + filter_upwards [] with ξ + exact grid_cost_refinement (α := fun r => α (Real.toNNReal r)) ham' (fun r ξ => hab _ ξ) h c N m hmpos ξ + +noncomputable def StepData.refine {N : ℕ} {h : ℝ≥0} {c : ℕ → ℝ≥0} + {F D : ℕ → ℝ → ℝ → ℝ} (sd : StepData N h c F D) (m : ℕ) (hm : 0 < m) : + StepData (N*m) (h/(m:ℝ≥0)) (fun j => c (j/m)) (fun j => F (j/m)) (fun j => D (j/m)) := by + have hq (j : ℕ) (hj : j < N*m) : j/m < N := (Nat.div_lt_iff_lt_mul hm).mpr hj + have hsub (j : ℕ) : Set.Icc ((j:ℝ)*(↑(h/(m:ℝ≥0)):ℝ)) (((j:ℝ)+1)*(↑(h/(m:ℝ≥0)):ℝ)) ⊆ + Set.Icc ((j/m:ℕ)*(h:ℝ)) (((j/m:ℕ)+1)*(h:ℝ)) := by + simpa only [NNReal.coe_div, NNReal.coe_natCast] using refined_cell_subset h hm j + refine ⟨sd.C₂,sd.C₃,sd.Ct,sd.L,sd.Γ, + fun j => sd.smooth (j/m), fun j => sd.gradient_bound (j/m), ?_, + fun j hj => sd.coefficient_bound _ (hq j hj), + fun j hj => sd.second_bound _ (hq j hj), + fun j hj => sd.third_bound _ (hq j hj), fun j => sd.rate_measurable (j/m), + fun j hj => sd.rate_bound _ (hq j hj), ?_,?_,?_⟩ + · intro j hj + rcases refinement_successor hm j with he | ⟨he, hde⟩ + · rw [he] + · rw [he] + have ht : (((j+1:ℕ):ℝ)*(↑(h/(m:ℝ≥0)):ℝ)) = (((j/m+1:ℕ):ℝ)*(h:ℝ)) := by + rw [hde] + have hh := congrArg NNReal.toReal (refined_time h hm (j/m+1) 0) + simpa only [Nat.add_zero, NNReal.coe_add, NNReal.coe_mul, NNReal.coe_div, + NNReal.coe_natCast, Nat.cast_zero, zero_mul, add_zero] using hh + rw [ht] + exact sd.seam (j/m) (hq j hj) + · intro j hj r hr z + exact (sd.time_derivative _ (hq j hj) r (hsub j hr) z).mono (hsub j) + · intro j hj r hr s hs z y + exact sd.rate_joint _ (hq j hj) r (hsub j hr) s (hsub j hs) z y + · intro j hj t ht z + exact sd.pde _ (hq j hj) t (hsub j ht) z + +lemma StepData.mesh_upper (hB : IsPreBrownianReal B P) (hm : ∀ t, Measurable (B t)) + {α : ℝ≥0 → Ω → ℝ} + (hap : IsProgressive (Filtration.natural B (fun t => (hm t).stronglyMeasurable)) α) + (hab : ∀ t ξ, |α t ξ| ≤ 1) + {N : ℕ} {h : ℝ≥0} {c : ℕ → ℝ≥0} {F D : ℕ → ℝ → ℝ → ℝ} + (sd : StepData N h c F D) (x : ℝ) : + profit (P := P) B α h c (F N ((N:ℝ)*(h:ℝ))) x N-F 0 0 x ≤ + (N:ℝ)*verificationError sd.Γ sd.C₂ sd.C₃ sd.L h := by + have hleft (k : ℕ) : (k:ℝ)*(h:ℝ) ∈ Set.Icc ((k:ℝ)*(h:ℝ)) (((k:ℝ)+1)*(h:ℝ)) := + ⟨le_rfl, by nlinarith [h.coe_nonneg]⟩ + have hu := variable_grid_verification_upper hB hm hap hab h c x N + (fun _ => sd.C₂) (fun _ => sd.C₃) (fun _ => sd.Ct) (fun _ => sd.L) + (fun k _ => sd.smooth k) (fun k _ => sd.gradient_bound k) + sd.second_bound sd.third_bound (fun k _ => sd.rate_measurable k _) + (fun k hk => sd.rate_bound k hk _) sd.time_derivative + (fun k hk r hr z y => by + simpa only [NNReal.coe_mul, NNReal.coe_natCast] using + sd.rate_joint k hk r hr ((k:ℝ)*(h:ℝ)) (hleft k) z y) + (fun k hk z => by + simpa only [NNReal.coe_mul, NNReal.coe_natCast] using + sd.pde k hk ((k:ℝ)*(h:ℝ)) (hleft k) z) sd.seam + (fun k hk => verificationError_mono (c k) sd.Γ sd.C₂ sd.C₂ sd.C₃ sd.C₃ sd.L sd.L h + (sd.coefficient_bound k hk) le_rfl le_rfl le_rfl) + dsimp only [profit] + linarith + +lemma StepData.mesh_lower (hB : IsPreBrownianReal B P) (hm : ∀ t, Measurable (B t)) + {N : ℕ} {h : ℝ≥0} {c : ℕ → ℝ≥0} {F D : ℕ → ℝ → ℝ → ℝ} + (sd : StepData N h c F D) (x : ℝ) : + ∃ α : ℝ≥0 → Ω → ℝ, + IsProgressive (Filtration.natural B (fun t => (hm t).stronglyMeasurable)) α ∧ + (∀ t ξ, |α t ξ| ≤ 1) ∧ + F 0 0 x-(N:ℝ)*verificationError sd.Γ sd.C₂ sd.C₃ sd.L h ≤ + profit (P := P) B α h c (F N ((N:ℝ)*(h:ℝ))) x N := by + have hleft (k : ℕ) : (k:ℝ)*(h:ℝ) ∈ Set.Icc ((k:ℝ)*(h:ℝ)) (((k:ℝ)+1)*(h:ℝ)) := + ⟨le_rfl, by nlinarith [h.coe_nonneg]⟩ + exact variable_grid_verification_lower hB hm h c x N + (fun _ => sd.C₂) (fun _ => sd.C₃) (fun _ => sd.Ct) (fun _ => sd.L) + sd.smooth sd.gradient_bound sd.second_bound sd.third_bound + (fun k _ => sd.rate_measurable k _) (fun k hk => sd.rate_bound k hk _) sd.time_derivative + (fun k hk r hr z y => by + simpa only [NNReal.coe_mul, NNReal.coe_natCast] using + sd.rate_joint k hk r hr ((k:ℝ)*(h:ℝ)) (hleft k) z y) + (fun k hk z => by + simpa only [NNReal.coe_mul, NNReal.coe_natCast] using + sd.pde k hk ((k:ℝ)*(h:ℝ)) (hleft k) z) sd.seam + (fun k hk => verificationError_mono (c k) sd.Γ sd.C₂ sd.C₂ sd.C₃ sd.C₃ sd.L sd.L h + (sd.coefficient_bound k hk) le_rfl le_rfl le_rfl) + +lemma refinement_endpoint (h : ℝ≥0) (N m : ℕ) (hm : 0 < m) : + (((N*m:ℕ):ℝ)*((h/(m:ℝ≥0)):ℝ)) = (N:ℝ)*(h:ℝ) := by + have he := congrArg NNReal.toReal (refined_time h hm N 0) + simpa only [Nat.add_zero, NNReal.coe_add, NNReal.coe_mul, NNReal.coe_div, + NNReal.coe_natCast, Nat.cast_zero, zero_mul, add_zero] using he + +lemma StepData.control_upper (hB : IsPreBrownianReal B P) (hm : ∀ t, Measurable (B t)) + {α : ℝ≥0 → Ω → ℝ} + (hap : IsProgressive (Filtration.natural B (fun t => (hm t).stronglyMeasurable)) α) + (hab : ∀ t ξ, |α t ξ| ≤ 1) + {N : ℕ} {h : ℝ≥0} {c : ℕ → ℝ≥0} {F D : ℕ → ℝ → ℝ → ℝ} + (sd : StepData N h c F D) (x : ℝ) : + profit (P := P) B α h c (F N ((N:ℝ)*(h:ℝ))) x N ≤ F 0 0 x := by + let := hB.isGaussianProcess.isProbabilityMeasure + have hlim : Tendsto (fun m : ℕ => (N*m:ℕ)*verificationError sd.Γ sd.C₂ sd.C₃ sd.L + ((h:ℝ)/(m:ℝ))) atTop (𝓝 0) := by + convert (verificationError_limit h sd.Γ sd.C₂ sd.C₃ sd.L).const_mul (N:ℝ) using 1 + · funext m; push_cast; ring + · simp + have hh : profit (P := P) B α h c (F N ((N:ℝ)*(h:ℝ))) x N-F 0 0 x ≤ 0 := by + apply ge_of_tendsto hlim + filter_upwards [eventually_ge_atTop (1:ℕ)] with m hm1 + have hmpos : 0 < m := by omega + have hu := (sd.refine m hmpos).mesh_upper hB hm hap hab x + have hdiv : N*m/m = N := by rw [Nat.mul_comm, Nat.mul_div_cancel_left _ hmpos] + change profit (P := P) B α (h/(m:ℝ≥0)) (fun j => c (j/m)) + (F (N*m/m) (((N*m:ℕ):ℝ)*(h/(m:ℝ≥0)))) x (N*m)-F (0/m) 0 x ≤ + ((N*m:ℕ):ℝ)*verificationError sd.Γ sd.C₂ sd.C₃ sd.L (h/(m:ℝ≥0)) at hu + rw [hdiv, refinement_endpoint h N m hmpos, Nat.zero_div, + profit_refinement (progressive_joint_measurable _ hap) hab h c _ x N m hmpos] at hu + simpa only [NNReal.coe_div, NNReal.coe_natCast] using hu + linarith + +lemma StepData.control_lower (hB : IsPreBrownianReal B P) (hm : ∀ t, Measurable (B t)) + {N : ℕ} {h : ℝ≥0} {c : ℕ → ℝ≥0} {F D : ℕ → ℝ → ℝ → ℝ} + (sd : StepData N h c F D) (x : ℝ) {ε : ℝ} (hε : 0 < ε) : + ∃ v ∈ objectives (P := P) hm h c (F N ((N:ℝ)*(h:ℝ))) x N, F 0 0 x-ε ≤ v := by + let := hB.isGaussianProcess.isProbabilityMeasure + have hlim : Tendsto (fun m : ℕ => (N*m:ℕ)*verificationError sd.Γ sd.C₂ sd.C₃ sd.L + ((h:ℝ)/(m:ℝ))) atTop (𝓝 0) := by + convert (verificationError_limit h sd.Γ sd.C₂ sd.C₃ sd.L).const_mul (N:ℝ) using 1 + · funext m; push_cast; ring + · simp + obtain ⟨m,hm1,he⟩ := ((eventually_ge_atTop (1:ℕ)).and + (hlim.eventually (gt_mem_nhds hε))).exists + have hmpos : 0 < m := by omega + obtain ⟨α,hap,hab,hl⟩ := (sd.refine m hmpos).mesh_lower hB hm x + have hdiv : N*m/m = N := by rw [Nat.mul_comm, Nat.mul_div_cancel_left _ hmpos] + change F (0/m) 0 x-((N*m:ℕ):ℝ)*verificationError sd.Γ sd.C₂ sd.C₃ sd.L (h/(m:ℝ≥0)) ≤ + profit (P := P) B α (h/(m:ℝ≥0)) (fun j => c (j/m)) + (F (N*m/m) (((N*m:ℕ):ℝ)*(h/(m:ℝ≥0)))) x (N*m) at hl + rw [hdiv, refinement_endpoint h N m hmpos, Nat.zero_div, + profit_refinement (progressive_joint_measurable _ hap) hab h c _ x N m hmpos] at hl + refine ⟨_, ⟨α,hap,hab,rfl⟩, ?_⟩ + simp only [NNReal.coe_natCast] at hl + linarith + +theorem cascade_eq_control_sup (hB : IsPreBrownianReal B P) (hm : ∀ t, Measurable (B t)) + {f : ℝ → ℝ} (hf : RegularDatum f) (hLip : LipschitzWith 1 f) + (c : ℕ → ℝ≥0) (h : ℝ≥0) (N : ℕ) (x : ℝ) : + cascade c h f N 0 x = sSup (objectives (P := P) hm h c f x N) := by + let sd := cellHeat_stepData hf hLip c h N + have hend : cellHeat c h f N N ((N:ℝ)*(h:ℝ)) = f := by + rw [cellHeat_left hf hLip c h N N le_rfl] + simp [cascadeAt, cascade] + have hstart : cellHeat c h f N 0 0 x = cascade c h f N 0 x := by + have he := congrFun (cellHeat_left hf hLip c h N 0 (Nat.zero_le N)) x + simpa only [Nat.cast_zero, zero_mul, cascadeAt, Nat.sub_zero] using he + have hu : ∀ v ∈ objectives (P := P) hm h c f x N, v ≤ cascade c h f N 0 x := by + intro v hv + obtain ⟨α,hap,hab,hv⟩ := hv + rw [hv] + have hh := sd.control_upper hB hm hap hab x + change profit (P := P) B α h c (cellHeat c h f N N ((N:ℝ)*(h:ℝ))) x N ≤ + cellHeat c h f N 0 0 x at hh + rwa [hend,hstart] at hh + have hb : BddAbove (objectives (P := P) hm h c f x N) := ⟨_,hu⟩ + apply le_antisymm + · apply le_of_forall_pos_le_add + intro ε hε + have hh := sd.control_lower hB hm x hε + change ∃ v ∈ objectives (P := P) hm h c (cellHeat c h f N N ((N:ℝ)*(h:ℝ))) x N, + cellHeat c h f N 0 0 x-ε ≤ v at hh + rw [hend,hstart] at hh + obtain ⟨v,hv,hl⟩ := hh + have hs := le_csSup hb hv + linarith + · exact csSup_le (objectives_nonempty hm h c f x N) hu + +end ZeroTemperatureSK.FiniteVerification + +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKSupport/Foundations/SumRangeBlocks.lean b/lean/OAI/Probability/SKSupport/Foundations/SumRangeBlocks.lean new file mode 100644 index 0000000000000000000000000000000000000000..96270e05197e7df0c1c78af161398778b3c5e2a0 --- /dev/null +++ b/lean/OAI/Probability/SKSupport/Foundations/SumRangeBlocks.lean @@ -0,0 +1,206 @@ +import Mathlib +import OAI.Probability.SKSupport.Control.ControlledGrid + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section +namespace ZeroTemperatureSK.WeakIto +variable {Ω : Type*} [mΩ : MeasurableSpace Ω] {P : Measure Ω} + +lemma sum_range_blocks (f : ℕ → ℝ) (n m : ℕ) : + ∑ j ∈ Finset.range (n*m), f j = + ∑ k ∈ Finset.range n, ∑ j ∈ Finset.range m, f (k*m+j) := by + induction n with + | zero => simp + | succ n IH => + rw [Nat.succ_mul, Finset.sum_range_add, IH, Finset.sum_range_succ] + +omit mΩ in +lemma controlledGrid_formula (B : ℝ≥0 → Ω → ℝ) (α : ℝ≥0 → Ω → ℝ) + (h : ℝ≥0) (c : ℕ → ℝ≥0) (x : ℝ) (n : ℕ) (ω : Ω) : + controlledGrid B α h c x n ω = x+B ((n:ℝ≥0)*h) ω-B 0 ω+ + ∑ k ∈ Finset.range n, stepDrift (fun r => α (Real.toNNReal r)) ((k:ℝ≥0)*h) h (c k) ω := by + induction n with + | zero => simp [controlledGrid] + | succ n IH => + rw [controlledGrid, IH, Finset.sum_range_succ] + ring + +lemma stepDrift_subdivision {α : ℝ → Ω → ℝ} + (hm : Measurable (fun p : ℝ × Ω => α p.1 p.2)) (hb : ∀ r ω, |α r ω| ≤ 1) + (s h c : ℝ) (hh : 0 ≤ h) (m : ℕ) (hmpos : 0 < m) (ω : Ω) : + (∑ j ∈ Finset.range m, stepDrift α (s+(j:ℝ)*(h/(m:ℝ))) (h/(m:ℝ)) c ω) = + stepDrift α s h c ω := by + have hm0 : (m:ℝ) ≠ 0 := by exact_mod_cast hmpos.ne' + have hd : 0 ≤ h/(m:ℝ) := div_nonneg hh (Nat.cast_nonneg m) + have hint : ∀ j < m, IntervalIntegrable (fun r => c*α r ω) volume + (s+(j:ℝ)*(h/(m:ℝ))) (s+((j+1:ℕ):ℝ)*(h/(m:ℝ))) := by + intro j hj + convert (bounded_control_intervalIntegrable hm hb (s+(j:ℝ)*(h/(m:ℝ))) (h/(m:ℝ)) hd ω).1.const_mul c using 1 + push_cast + ring + have hsum := intervalIntegral.sum_integral_adjacent_intervals hint + convert hsum using 1 + · apply Finset.sum_congr rfl + intro j hj + unfold stepDrift + congr 1 + push_cast + ring + · unfold stepDrift + congr 1 + · simp + · field_simp + +lemma stepCost_subdivision {α : ℝ → Ω → ℝ} + (hm : Measurable (fun p : ℝ × Ω => α p.1 p.2)) (hb : ∀ r ω, |α r ω| ≤ 1) + (s h c : ℝ) (hh : 0 ≤ h) (m : ℕ) (hmpos : 0 < m) (ω : Ω) : + (∑ j ∈ Finset.range m, stepCost α (s+(j:ℝ)*(h/(m:ℝ))) (h/(m:ℝ)) c ω) = + stepCost α s h c ω := by + have hsq : Measurable (fun p : ℝ × Ω => (α p.1 p.2)^2) := hm.pow_const 2 + have hb2 : ∀ r ω, |(α r ω)^2| ≤ 1 := fun r ω => by + rw [abs_pow] + simpa using pow_le_pow_left₀ (abs_nonneg _) (hb r ω) 2 + have he := stepDrift_subdivision (α := fun r ω => (α r ω)^2) hsq hb2 s h c hh m hmpos ω + unfold stepCost + rw [← Finset.mul_sum] + exact congrArg (fun z : ℝ => (1/2:ℝ)*z) he + +lemma refined_time (h : ℝ≥0) {m : ℕ} (hm : 0 < m) (k j : ℕ) : + ((k*m+j:ℕ):ℝ≥0)*(h/(m:ℝ≥0)) = (k:ℝ≥0)*h+(j:ℝ≥0)*(h/(m:ℝ≥0)) := by + have hm0 : (m:ℝ≥0) ≠ 0 := by exact_mod_cast hm.ne' + push_cast + field_simp + +lemma refined_coefficient {m j : ℕ} (hm : 0 < m) (hj : j < m) (k : ℕ) : + (k*m+j)/m = k := by + rw [Nat.mul_comm k m, Nat.mul_add_div hm, Nat.div_eq_of_lt hj, Nat.add_zero] + +lemma grid_drift_refinement {α : ℝ → Ω → ℝ} + (hm : Measurable (fun p : ℝ × Ω => α p.1 p.2)) (hb : ∀ r ω, |α r ω| ≤ 1) + (h : ℝ≥0) (c : ℕ → ℝ≥0) (n m : ℕ) (hmpos : 0 < m) (ω : Ω) : + (∑ j ∈ Finset.range (n*m), stepDrift α ((j:ℝ≥0)*(h/(m:ℝ≥0))) (h/(m:ℝ≥0)) (c (j/m)) ω) = + ∑ k ∈ Finset.range n, stepDrift α ((k:ℝ≥0)*h) h (c k) ω := by + rw [sum_range_blocks] + apply Finset.sum_congr rfl + intro k hk + have ht (j : ℕ) : ((k*m+j:ℕ):ℝ)*(↑h/(↑m:ℝ)) = + (k:ℝ)*(h:ℝ)+(j:ℝ)*((h:ℝ)/(m:ℝ)) := by + have he := congrArg NNReal.toReal (refined_time h hmpos k j) + simpa only [NNReal.coe_mul, NNReal.coe_div, NNReal.coe_add, NNReal.coe_natCast] using he + simp only [NNReal.coe_natCast] + have he : (∑ j ∈ Finset.range m, + stepDrift α (((k*m+j:ℕ):ℝ)*((h:ℝ)/(m:ℝ))) ((h:ℝ)/(m:ℝ)) (c ((k*m+j)/m)) ω) = + ∑ j ∈ Finset.range m, + stepDrift α ((k:ℝ)*(h:ℝ)+(j:ℝ)*((h:ℝ)/(m:ℝ))) ((h:ℝ)/(m:ℝ)) (c k) ω := by + apply Finset.sum_congr rfl + intro j hj + rw [refined_coefficient hmpos (Finset.mem_range.mp hj) k, ht j] + rw [he] + exact stepDrift_subdivision hm hb ((k:ℝ)*(h:ℝ)) h (c k) h.coe_nonneg m hmpos ω + +lemma grid_cost_refinement {α : ℝ → Ω → ℝ} + (hm : Measurable (fun p : ℝ × Ω => α p.1 p.2)) (hb : ∀ r ω, |α r ω| ≤ 1) + (h : ℝ≥0) (c : ℕ → ℝ≥0) (n m : ℕ) (hmpos : 0 < m) (ω : Ω) : + (∑ j ∈ Finset.range (n*m), stepCost α ((j:ℝ≥0)*(h/(m:ℝ≥0))) (h/(m:ℝ≥0)) (c (j/m)) ω) = + ∑ k ∈ Finset.range n, stepCost α ((k:ℝ≥0)*h) h (c k) ω := by + rw [sum_range_blocks] + apply Finset.sum_congr rfl + intro k hk + have ht (j : ℕ) : ((k*m+j:ℕ):ℝ)*(↑h/(↑m:ℝ)) = + (k:ℝ)*(h:ℝ)+(j:ℝ)*((h:ℝ)/(m:ℝ)) := by + have he := congrArg NNReal.toReal (refined_time h hmpos k j) + simpa only [NNReal.coe_mul, NNReal.coe_div, NNReal.coe_add, NNReal.coe_natCast] using he + simp only [NNReal.coe_natCast] + have he : (∑ j ∈ Finset.range m, + stepCost α (((k*m+j:ℕ):ℝ)*((h:ℝ)/(m:ℝ))) ((h:ℝ)/(m:ℝ)) (c ((k*m+j)/m)) ω) = + ∑ j ∈ Finset.range m, + stepCost α ((k:ℝ)*(h:ℝ)+(j:ℝ)*((h:ℝ)/(m:ℝ))) ((h:ℝ)/(m:ℝ)) (c k) ω := by + apply Finset.sum_congr rfl + intro j hj + rw [refined_coefficient hmpos (Finset.mem_range.mp hj) k, ht j] + rw [he] + exact stepCost_subdivision hm hb ((k:ℝ)*(h:ℝ)) h (c k) h.coe_nonneg m hmpos ω + +lemma controlledGrid_refinement (B : ℝ≥0 → Ω → ℝ) {α : ℝ≥0 → Ω → ℝ} + (hm : Measurable (fun p : ℝ≥0 × Ω => α p.1 p.2)) (hb : ∀ r ω, |α r ω| ≤ 1) + (h : ℝ≥0) (c : ℕ → ℝ≥0) (x : ℝ) (n m : ℕ) (hmpos : 0 < m) (ω : Ω) : + controlledGrid B α (h/(m:ℝ≥0)) (fun j => c (j/m)) x (n*m) ω = + controlledGrid B α h c x n ω := by + have hm' : Measurable (fun p : ℝ × Ω => α (Real.toNNReal p.1) p.2) := + hm.comp (measurable_fst.real_toNNReal.prodMk measurable_snd) + have ht : ((n*m:ℕ):ℝ≥0)*(h/(m:ℝ≥0)) = (n:ℝ≥0)*h := by + simpa using refined_time h hmpos n 0 + simp only [controlledGrid_formula] + rw [ht] + have he := grid_drift_refinement (α := fun r => α (Real.toNNReal r)) hm' (fun r ω => hb _ ω) h c n m hmpos ω + simp only [NNReal.coe_div, NNReal.coe_natCast] at he ⊢ + rw [he] + +end ZeroTemperatureSK.WeakIto + +namespace ZeroTemperatureSK.WeakIto + +lemma refinement_successor {m : ℕ} (hm : 0 < m) (j : ℕ) : + (j+1)/m = j/m ∨ ((j+1)/m = j/m+1 ∧ j+1 = (j/m+1)*m) := by + have hj := Nat.div_add_mod j m + have hr := Nat.mod_lt j hm + by_cases he : j%m+1 < m + · left + have hde : j+1 = m*(j/m)+(j%m+1) := by omega + rw [hde, Nat.mul_add_div hm, Nat.div_eq_of_lt he, Nat.add_zero] + · right + have he' : j%m+1 = m := by omega + have hde : j+1 = (j/m+1)*m := by + calc j+1 = m*(j/m)+(j%m+1) := by omega + _ = m*(j/m)+m := by rw [he'] + _ = (j/m+1)*m := by ring + refine ⟨?_, hde⟩ + rw [hde, Nat.mul_comm, Nat.mul_div_cancel_left _ hm] + +lemma refined_cell_subset (h : ℝ≥0) {m : ℕ} (hm : 0 < m) (j : ℕ) : + Set.Icc ((j:ℝ)*((h:ℝ)/(m:ℝ))) (((j:ℝ)+1)*((h:ℝ)/(m:ℝ))) ⊆ + Set.Icc ((j/m:ℕ)*(h:ℝ)) (((j/m:ℕ)+1)*(h:ℝ)) := by + have hd : 0 ≤ (h:ℝ)/(m:ℝ) := div_nonneg h.coe_nonneg (Nat.cast_nonneg m) + have hl : j/m*m ≤ j := Nat.div_mul_le_self _ _ + have hu : j+1 ≤ (j/m+1)*m := (Nat.div_lt_iff_lt_mul hm).mp (Nat.lt_succ_self _) + have ht (k : ℕ) : ((k*m:ℕ):ℝ)*((h:ℝ)/(m:ℝ)) = (k:ℝ)*(h:ℝ) := by + have he := congrArg NNReal.toReal (refined_time h hm k 0) + simpa only [Nat.add_zero, NNReal.coe_mul, NNReal.coe_div, NNReal.coe_add, + NNReal.coe_natCast, Nat.cast_zero, zero_mul, add_zero] using he + intro r hr + constructor + · calc (j/m:ℕ)*(h:ℝ) = ((j/m*m:ℕ):ℝ)*((h:ℝ)/(m:ℝ)) := (ht _).symm + _ ≤ (j:ℝ)*((h:ℝ)/(m:ℝ)) := mul_le_mul_of_nonneg_right (by exact_mod_cast hl) hd + _ ≤ r := hr.1 + · calc r ≤ ((j:ℝ)+1)*((h:ℝ)/(m:ℝ)) := hr.2 + _ ≤ (((j/m+1)*m:ℕ):ℝ)*((h:ℝ)/(m:ℝ)) := + mul_le_mul_of_nonneg_right (by exact_mod_cast hu) hd + _ = ((j/m:ℕ)+1)*(h:ℝ) := by simpa only [Nat.cast_add, Nat.cast_one] using ht (j/m+1) + +lemma verificationError_mono (c d C₂ D₂ C₃ D₃ L M h : ℝ≥0) + (hc : c ≤ d) (h₂ : C₂ ≤ D₂) (h₃ : C₃ ≤ D₃) (hL : L ≤ M) : + verificationError c C₂ C₃ L h ≤ verificationError d D₂ D₃ M h := by + have hF := normalFirstMoment_nonneg + have hT := normalThirdMoment_nonneg + unfold verificationError + gcongr + +end ZeroTemperatureSK.WeakIto + +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology ContDiff +noncomputable section + +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKSupport/Foundations/Taylor1Bound.lean b/lean/OAI/Probability/SKSupport/Foundations/Taylor1Bound.lean new file mode 100644 index 0000000000000000000000000000000000000000..ffe4d549e00836d258212db620a078114af2684e --- /dev/null +++ b/lean/OAI/Probability/SKSupport/Foundations/Taylor1Bound.lean @@ -0,0 +1,87 @@ +import Mathlib +import OAI.Probability.SKSupport.Model + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology ContDiff +noncomputable section +namespace ZeroTemperatureSK.Heat + +lemma taylor1_bound {f : ℝ → ℝ} (hf : ContDiff ℝ 2 f) {C : ℝ} + (hC : ∀ x, |deriv (deriv f) x| ≤ C) (x d : ℝ) : + |f (x+d)-f x-deriv f x*d| ≤ C/2*|d|^2 := by + by_cases hd : d = 0 + · simp [hd] + have hxd : x ≠ x+d := by intro h; apply hd; linarith + obtain ⟨y,hy,he⟩ := taylor_mean_remainder_lagrange_iteratedDeriv + (n := 1) hxd hf.contDiffOn + have h1 : iteratedDerivWithin 1 f (Set.uIcc x (x+d)) x = deriv f x := by + rw [iteratedDerivWithin_eq_iteratedDeriv (uniqueDiffOn_uIcc hxd) + (hf.of_le (by norm_num)).contDiffAt left_mem_uIcc, iteratedDeriv_one] + simp only [taylorWithinEval_succ, taylor_within_zero_eval, h1, + iteratedDeriv_succ] at he + norm_num at he + have he' : f (x+d)-f x-deriv f x*d = deriv (deriv f) y*d^2/2 := by + calc + _ = f (x+d)-(f x+d*deriv f x) := by ring + _ = _ := by convert he using 1 + rw [he', abs_div, abs_mul, abs_pow] + norm_num + have := mul_le_mul_of_nonneg_right (hC y) (sq_nonneg d) + nlinarith + +lemma derivative_interpolation {f : ℝ → ℝ} (hf : ContDiff ℝ 2 f) + {A C : ℝ} (hA : ∀ x, |f x| ≤ A) (hC : ∀ x, |deriv (deriv f) x| ≤ C) + {h : ℝ} (hh : 0 < h) (x : ℝ) : + |deriv f x| ≤ 2*A/h+h*C/2 := by + have ht := taylor1_bound hf hC x h + rw [abs_of_pos hh] at ht + have hs : |deriv f x*h| ≤ 2*A+C/2*h^2 := by + calc + _ = |f (x+h)-f x-(f (x+h)-f x-deriv f x*h)| := by congr 1; ring + _ ≤ |f (x+h)-f x|+|f (x+h)-f x-deriv f x*h| := abs_sub _ _ + _ ≤ (|f (x+h)|+|f x|)+C/2*h^2 := add_le_add (abs_sub _ _) ht + _ ≤ 2*A+C/2*h^2 := by linarith [hA (x+h),hA x] + rw [abs_mul, abs_of_pos hh] at hs + have he : (2*A/h+h*C/2)*h = 2*A+C/2*h^2 := by field_simp + nlinarith + +lemma tendstoUniformly_deriv_zero {ι : Type*} {l : Filter ι} + {f : ι → ℝ → ℝ} (hf : ∀ i, ContDiff ℝ 2 (f i)) + {C : ℝ≥0} (hC : ∀ i x, |deriv (deriv (f i)) x| ≤ C) + (hlim : TendstoUniformly f (fun _ => 0) l) : + TendstoUniformly (fun i => deriv (f i)) (fun _ => 0) l := by + rw [Metric.tendstoUniformly_iff] at hlim ⊢ + intro ε hε + let h : ℝ := ε / ((C:ℝ)+1) + have hh : 0 < h := div_pos hε (by positivity) + have hδ : 0 < ε*h/4 := by positivity + filter_upwards [hlim (ε*h/4) hδ] with i hi x + have hA : ∀ y, |f i y| ≤ ε*h/4 := fun y => le_of_lt (by + simpa only [Real.dist_eq, sub_zero, abs_sub_comm] using hi y) + have hd := derivative_interpolation (hf i) hA (hC i) hh x + have hc : h*(C:ℝ) < ε := by + dsimp [h] + rw [div_mul_eq_mul_div] + apply (div_lt_iff₀ (show (0:ℝ) scaled z g x) (a*scaled a (deriv (deriv g)) x) a := by + have hgd : ContDiff ℝ 1 (deriv g) := hgc.deriv' + have hs := standardGaussian_stein + (g := fun y => deriv g (x+a*y)) + (g' := fun y => a*deriv (deriv g) (x+a*y)) + (fun y => by + convert (hgd.differentiable (by norm_num) (x+a*y)).hasDerivAt.comp y + (((hasDerivAt_id y).const_mul a).const_add x) using 1 <;> first | rfl | simp [mul_comm]) + (integrable_scaled_of_expBound hgd.continuous.measurable hg' a x) + ((integrable_scaled_of_expBound hgd.continuous_deriv_one.measurable hg'' a x).const_mul a) + (integrable_mul_scaled_of_expBound hgd.continuous.measurable hg' a x) + rw [integral_const_mul] at hs + exact (hasDerivAt_scaled (hgc.of_le (by norm_num)) hg hg' a x).congr_deriv hs + +def varianceHeat (t : ℝ) (g : ℝ → ℝ) (x : ℝ) := scaled (Real.sqrt t) g x + +lemma varianceHeat_zero (g : ℝ → ℝ) (x : ℝ) : varianceHeat 0 g x = g x := by + simp [varianceHeat, scaled] + +lemma continuous_varianceHeat {g : ℝ → ℝ} (hgc : Continuous g) (hg : ExponentialBound g) + (x : ℝ) : Continuous (fun t => varianceHeat t g x) := + (continuous_scaled hgc hg x).comp Real.continuous_sqrt + +lemma varianceHeat_eq_semigroup {g : ℝ → ℝ} (hgm : Measurable g) (h : ℝ≥0) (x : ℝ) : + varianceHeat h g x = semigroup h g x := (semigroup_eq_scaled hgm h x).symm + +lemma hasDerivAt_varianceHeat_pos {g : ℝ → ℝ} (hgc : ContDiff ℝ 2 g) + (hg : ExponentialBound g) (hg' : ExponentialBound (deriv g)) + (hg'' : ExponentialBound (deriv (deriv g))) {t : ℝ} (ht : 0 < t) (x : ℝ) : + HasDerivAt (fun s => varianceHeat s g x) ((1/2:ℝ)*varianceHeat t (deriv (deriv g)) x) t := by + have hd := (hasDerivAt_scaled_second hgc hg hg' hg'' (Real.sqrt t) x).comp t + (Real.hasDerivAt_sqrt (ne_of_gt ht)) + apply hd.congr_deriv + change (Real.sqrt t*scaled (Real.sqrt t) (deriv (deriv g)) x)*(1/(2*Real.sqrt t)) = _ + dsimp only [varianceHeat] + field_simp [ne_of_gt (Real.sqrt_pos.mpr ht)] + +lemma hasDerivWithinAt_varianceHeat {g : ℝ → ℝ} (hgc : ContDiff ℝ 2 g) + (hg : ExponentialBound g) (hg' : ExponentialBound (deriv g)) + (hg'' : ExponentialBound (deriv (deriv g))) {t : ℝ} (ht : 0 ≤ t) (x : ℝ) : + HasDerivWithinAt (fun s => varianceHeat s g x) + ((1/2:ℝ)*varianceHeat t (deriv (deriv g)) x) (Set.Ici 0) t := by + by_cases ht0 : t = 0 + · subst t + apply hasDerivWithinAt_Ici_of_tendsto_deriv (s := Set.Ioi 0) + · intro r hr + exact (hasDerivAt_varianceHeat_pos hgc hg hg' hg'' hr x).differentiableAt.differentiableWithinAt + · exact (continuous_varianceHeat hgc.continuous hg x).continuousAt.continuousWithinAt + · exact self_mem_nhdsWithin + · have hc : Continuous (fun r => (1/2:ℝ)*varianceHeat r (deriv (deriv g)) x) := + continuous_const.mul (continuous_varianceHeat + (show Continuous (deriv (deriv g)) from (show ContDiff ℝ 1 (deriv g) from hgc.deriv').continuous_deriv_one) + hg'' x) + apply hc.continuousAt.tendsto.mono_left nhdsWithin_le_nhds |>.congr' + filter_upwards [self_mem_nhdsWithin] with r hr + exact (hasDerivAt_varianceHeat_pos hgc hg hg' hg'' hr x).deriv.symm + · exact (hasDerivAt_varianceHeat_pos hgc hg hg' hg'' (lt_of_le_of_ne ht (Ne.symm ht0)) x).hasDerivWithinAt + +end ZeroTemperatureSK.Heat + +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKSupport/Foundations/VarianceHeatGradientBound.lean b/lean/OAI/Probability/SKSupport/Foundations/VarianceHeatGradientBound.lean new file mode 100644 index 0000000000000000000000000000000000000000..df24d6d5a14a3150419db022a005eaa8f0f75b0d --- /dev/null +++ b/lean/OAI/Probability/SKSupport/Foundations/VarianceHeatGradientBound.lean @@ -0,0 +1,221 @@ +import Mathlib +import OAI.Probability.SKSupport.Regularity.BoundedSmoothFamily +import OAI.Probability.SKSupport.Foundations.InvSqrtNegHalf + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology ContDiff +noncomputable section +open MeasureTheory Set Filter +open scoped Topology +noncomputable section +namespace ZeroTemperatureSK.Heat +open ZeroTemperatureSK.Smoothing + +lemma varianceHeat_gradient_bound {g : ℝ → ℝ} (hg : BoundedSmooth g) + {C : ℝ} (hC : 0 ≤ C) (hbound : ∀ z, |g z| ≤ C) {h : ℝ} (hh : 0 < h) (x : ℝ) : + |deriv (varianceHeat h g) x| ≤ kernelConstant*C/Real.sqrt h := by + change |deriv (scaled (Real.sqrt h) g) x| ≤ _ + exact scaled_gradient_bound hg (C := ⟨C,hC⟩) hbound (Real.sqrt_pos.mpr hh) x + +lemma deriv_varianceHeat_of_bounded {g : ℝ → ℝ} (hg : BoundedSmooth g) (h : ℝ) : + deriv (varianceHeat h g) = varianceHeat h (deriv g) := by + obtain ⟨A,hA⟩ := hg.bound + obtain ⟨B,hB⟩ := hg.deriv.bound + exact deriv_varianceHeat (hg.smooth.of_le (by simp)) + (ExponentialBound.of_bounded hA) (ExponentialBound.of_bounded hB) h + +lemma deriv_of_mild {V G : ℝ → ℝ → ℝ} {A B : ℝ≥0} {t b : ℝ} + (hV : BoundedSmooth (V b)) (hm : Measurable (fun p : ℝ × ℝ => G p.1 p.2)) + (hG : ∀ r, BoundedSmooth (G r)) (hA : ∀ r z, |G r z| ≤ A) + (hB : ∀ r z, |deriv (G r) z| ≤ B) + (hmild : ∀ x, V t x = varianceHeat (b-t) (V b) x+ + ∫ r in t..b, varianceHeat (r-t) (G r) x) (x : ℝ) : + deriv (V t) x = deriv (varianceHeat (b-t) (V b)) x+ + ∫ r in t..b, deriv (varianceHeat (r-t) (G r)) x := by + have hDt := hasDerivAt_integral_varianceHeat hm hG hA hB t b x + obtain ⟨C,hC⟩ := hV.bound + obtain ⟨D,hD⟩ := hV.deriv.bound + have hHt : HasDerivAt (varianceHeat (b-t) (V b)) (varianceHeat (b-t) (deriv (V b)) x) x := + hasDerivAt_scaled_space (hV.smooth.of_le (by simp)) + (ExponentialBound.of_bounded hC) (ExponentialBound.of_bounded hD) (Real.sqrt (b-t)) x + have heV : V t = fun z => varianceHeat (b-t) (V b) z+∫ r in t..b, varianceHeat (r-t) (G r) z := funext hmild + have hdR : deriv (fun z => varianceHeat (b-t) (V b) z+∫ r in t..b, varianceHeat (r-t) (G r) z) x = + varianceHeat (b-t) (deriv (V b)) x+∫ r in t..b, varianceHeat (r-t) (deriv (G r)) x := (hHt.add hDt).deriv + rw [heV,hdR] + simp_rw [deriv_varianceHeat_of_bounded hV,deriv_varianceHeat_of_bounded (hG _)] + +lemma uniform_gradient_bound_of_mild {V G : ℝ → ℝ → ℝ} {A₀ B₀ : ℝ≥0} + {a b A D R C : ℝ} (hab : a < b) (hA : 0 ≤ A) (hD : 0 ≤ D) (hR : 0 ≤ R) + (hV : BoundedSmooth (V b)) (hm : Measurable (fun p : ℝ × ℝ => G p.1 p.2)) + (hG : ∀ r, BoundedSmooth (G r)) (hA₀ : ∀ r z, |G r z| ≤ A₀) + (hB₀ : ∀ r z, |deriv (G r) z| ≤ B₀) + (hC : ∀ r ∈ Icc a b, ∀ x, |deriv (V r) x| ≤ C) + (hterminal : ∀ x, |V b x| ≤ A) + (hsource : ∀ r ∈ Icc a b, ∀ x, |G r x| ≤ D*|deriv (V r) x|+R) + (hmild : ∀ t ∈ Ico a b, ∀ x, V t x = varianceHeat (b-t) (V b) x+ + ∫ r in t..b, varianceHeat (r-t) (G r) x) + (hsmall : 8*kernelConstant*D*Real.sqrt (b-a) ≤ 1/2) (x : ℝ) : + |deriv (V a) x| ≤ 2*kernelConstant*(A+2*R*(b-a))/Real.sqrt (b-a) := by + let W : ℝ → ℝ → ℝ := fun r => deriv (V r) + let M : ℝ := weightedSize W a b + have hM : 0 ≤ M := weightedSize_nonneg hab.le hC + have hκ := kernelConstant_nonneg + have hpoint (t : ℝ) (ht : t ∈ Ico a b) (z : ℝ) : + Real.sqrt (b-t)*|W t z| ≤ kernelConstant*(A+2*R*(b-a))+ + (8*kernelConstant*D)*Real.sqrt (b-t)*M := by + have htb : 0 < b-t := sub_pos.mpr ht.2 + have hs : 0 < Real.sqrt (b-t) := Real.sqrt_pos.mpr htb + let H : ℝ → ℝ := fun r => (kernelConstant*D*M)*(1/(Real.sqrt (r-t)*Real.sqrt (b-r)))+ + (kernelConstant*R)*(1/Real.sqrt (r-t)) + have hHi : IntervalIntegrable H volume t b := + ((intervalIntegrable_sqrt_kernel ht.2).const_mul _).add + ((intervalIntegrable_inv_sqrt_sub ht.2.le).const_mul _) + have hdom (r : ℝ) (hr : r ∈ Ioo t b) : + |deriv (varianceHeat (r-t) (G r)) z| ≤ H r := by + have hrab : r ∈ Ico a b := ⟨ht.1.trans hr.1.le,hr.2⟩ + have hwr (y : ℝ) : |W r y| ≤ M/Real.sqrt (b-r) := abs_le_weightedSize hC hrab y + have hbnd (y : ℝ) : |G r y| ≤ D*(M/Real.sqrt (b-r))+R := + (hsource r ⟨hrab.1,hrab.2.le⟩ y).trans (add_le_add (mul_le_mul_of_nonneg_left (hwr y) hD) le_rfl) + have hbnd0 : 0 ≤ D*(M/Real.sqrt (b-r))+R := by positivity + apply (varianceHeat_gradient_bound (hG r) hbnd0 hbnd (sub_pos.mpr hr.1) z).trans_eq + dsimp only [H] + field_simp + have hnorm : |∫ r in t..b, deriv (varianceHeat (r-t) (G r)) z| ≤ ∫ r in t..b, H r := by + rw [← Real.norm_eq_abs] + apply intervalIntegral.norm_integral_le_of_norm_le ht.2.le _ hHi + filter_upwards [volume.ae_ne b] with r hrb hr + simpa only [Real.norm_eq_abs] using hdom r ⟨hr.1,lt_of_le_of_ne hr.2 hrb⟩ + have hHbound : (∫ r in t..b,H r) ≤ 8*kernelConstant*D*M+2*kernelConstant*R*Real.sqrt (b-t) := by + dsimp only [H] + rw [intervalIntegral.integral_add ((intervalIntegrable_sqrt_kernel ht.2).const_mul _) + ((intervalIntegrable_inv_sqrt_sub ht.2.le).const_mul _),intervalIntegral.integral_const_mul, + intervalIntegral.integral_const_mul,integral_inv_sqrt_sub ht.2.le] + have hh := mul_le_mul_of_nonneg_left (integral_sqrt_kernel_le ht.2) + (show 0 ≤ kernelConstant*D*M by positivity) + nlinarith + have he := deriv_of_mild hV hm hG hA₀ hB₀ (hmild t ht) z + have hinitial := varianceHeat_gradient_bound hV hA hterminal htb z + have hsum : |W t z| ≤ kernelConstant*A/Real.sqrt (b-t)+ + 8*kernelConstant*D*M+2*kernelConstant*R*Real.sqrt (b-t) := by + change |deriv (V t) z| ≤ _ + rw [he] + have hh := abs_add_le (deriv (varianceHeat (b-t) (V b)) z) + (∫ r in t..b, deriv (varianceHeat (r-t) (G r)) z) + linarith + have hscaled := mul_le_mul_of_nonneg_left hsum hs.le + have hcancel : Real.sqrt (b-t)*(kernelConstant*A/Real.sqrt (b-t)) = kernelConstant*A := by + field_simp + have hsq := Real.sq_sqrt htb.le + have hgap : b-t ≤ b-a := by linarith [ht.1] + have hrr := mul_le_mul_of_nonneg_left hgap (show 0 ≤ 2*kernelConstant*R by positivity) + have hscaled' : Real.sqrt (b-t)*|W t z| ≤ kernelConstant*A+ + 8*kernelConstant*D*Real.sqrt (b-t)*M+2*kernelConstant*R*(b-t) := by + apply hscaled.trans_eq + rw [mul_add,mul_add,hcancel] + have he : Real.sqrt (b-t)*(2*kernelConstant*R*Real.sqrt (b-t)) = 2*kernelConstant*R*(b-t) := by + calc + _ = 2*kernelConstant*R*(Real.sqrt (b-t))^2 := by ring + _ = _ := by rw [hsq] + rw [he] + ring + nlinarith [hscaled'] + have hMbound : M ≤ 2*(kernelConstant*(A+2*R*(b-a))) := + weighted_absorption hab hC (by positivity) (by positivity) hsmall hpoint + have hw := abs_le_weightedSize hC (t := a) ⟨le_rfl,hab⟩ x + apply hw.trans + exact (div_le_div_of_nonneg_right hMbound (Real.sqrt_nonneg _)).trans_eq (by ring) + +end ZeroTemperatureSK.Heat + +namespace ZeroTemperatureSK.Heat +open ZeroTemperatureSK.Smoothing + +lemma iteratedDeriv_mild {V G : ℝ → ℝ → ℝ} + (hV : BoundedSmoothFamily V) (hG : BoundedSmoothFamily G) {a b : ℝ} + (hmild : ∀ z, V a z = varianceHeat (b-a) (V b) z+ + ∫ r in a..b, varianceHeat (r-a) (G r) z) (n : ℕ) (x : ℝ) : + iteratedDeriv n (V a) x = varianceHeat (b-a) (iteratedDeriv n (V b)) x+ + ∫ r in a..b, varianceHeat (r-a) (iteratedDeriv n (G r)) x := by + induction n generalizing x with + | zero => simpa only [iteratedDeriv_zero] using hmild x + | succ n ih => + have hGn := hG.iteratedDeriv n + obtain ⟨A,hA⟩ := hGn.bound + obtain ⟨B,hB⟩ := hGn.deriv.bound + have hd := deriv_of_mild (V := fun t => iteratedDeriv n (V t)) + ((hV.iteratedDeriv n).regular b) hGn.measurable hGn.regular hA hB ih x + simp_rw [deriv_varianceHeat_of_bounded ((hV.iteratedDeriv n).regular b), + deriv_varianceHeat_of_bounded (hGn.regular _)] at hd + simpa only [iteratedDeriv_succ] using hd + +lemma burgers_source_derivative_bound {U : ℝ → ℝ} (hU : BoundedSmooth U) + {C : ℝ} (hC : 0 ≤ C) (hU1 : ∀ x, |U x| ≤ 1) (n : ℕ) + (hb : ∀ j ≤ n, ∀ x, |iteratedDeriv j U x| ≤ C) (x : ℝ) : + |iteratedDeriv n (fun z => U z*deriv U z) x| ≤ |iteratedDeriv (n+1) U x|+ + (∑ j ∈ Finset.range n, (n.choose (j+1):ℝ))*C^2 := by + rw [iteratedDeriv_fun_mul + (hU.smooth.of_le (ENat.natCast_le_of_coe_top_le_withTop le_rfl n) |>.contDiffAt) + (hU.deriv.smooth.of_le (ENat.natCast_le_of_coe_top_le_withTop le_rfl n) |>.contDiffAt)] + rw [Finset.sum_range_succ'] + simp only [Nat.choose_zero_right,Nat.cast_one,iteratedDeriv_zero,one_mul,Nat.sub_zero, + ← iteratedDeriv_succ'] + apply (abs_add_le _ _).trans + have hlead : |U x*iteratedDeriv (n+1) U x| ≤ |iteratedDeriv (n+1) U x| := by + rw [abs_mul] + simpa only [one_mul] using mul_le_mul_of_nonneg_right (hU1 x) (abs_nonneg (iteratedDeriv (n+1) U x)) + have hrem : |∑ j ∈ Finset.range n, + (n.choose (j+1):ℝ)*iteratedDeriv (j+1) U x*iteratedDeriv (n-(j+1)+1) U x| ≤ + (∑ j ∈ Finset.range n,(n.choose (j+1):ℝ))*C^2 := by + apply (Finset.abs_sum_le_sum_abs _ _).trans + rw [Finset.sum_mul] + apply Finset.sum_le_sum + intro j hj + have hjn : j < n := Finset.mem_range.mp hj + rw [abs_mul,abs_mul,abs_of_nonneg (Nat.cast_nonneg _)] + have h1 := hb (j+1) (by omega) x + have h2 := hb (n-(j+1)+1) (by omega) x + have hh := mul_le_mul h1 h2 (abs_nonneg _) hC + have hh' := mul_le_mul_of_nonneg_left hh (show (0:ℝ) ≤ (n.choose (j+1):ℝ) by positivity) + nlinarith + simpa only [add_comm] using add_le_add hrem hlead + +lemma iteratedDeriv_finiteBurgersSource_bound {f : ℝ → ℝ} (hf : RegularDatum f) + (hLip : LipschitzWith 1 f) (c : ℕ → ℝ≥0) (h : ℝ≥0) (N i n : ℕ) + {C D t : ℝ} (hC : 0 ≤ C) (hD : 0 ≤ D) (hcoef : finiteCoeff c h N i t ≤ D) + (hb : ∀ j ≤ n, ∀ x, |iteratedDeriv j (deriv (finiteValue c h f N i t)) x| ≤ C) (x : ℝ) : + |iteratedDeriv n (finiteBurgersSource c h f N i t) x| ≤ + D*|deriv (iteratedDeriv n (deriv (finiteValue c h f N i t))) x|+ + D*(∑ j ∈ Finset.range n,(n.choose (j+1):ℝ))*C^2 := by + have hUnn : 0 ≤ finiteCoeff c h N i t := by + obtain ⟨K,hK⟩ := finiteCoeff_bounds c h N i; exact (hK t).1 + have hU1 (z : ℝ) : |deriv (finiteValue c h f N i t) z| ≤ 1 := by + simpa only [Real.norm_eq_abs,NNReal.coe_one] using + norm_deriv_le_of_lipschitz (x₀ := z) (finiteValue_lipschitz hLip c h N i t) + have hbnd := burgers_source_derivative_bound + (finiteValue_regular hf hLip c h N i t).deriv_bounded hC hU1 n hb x + change |iteratedDeriv n (fun z => finiteCoeff c h N i t* + (deriv (finiteValue c h f N i t) z*deriv (deriv (finiteValue c h f N i t)) z)) x| ≤ _ + rw [iteratedDeriv_const_mul_field,abs_mul,abs_of_nonneg hUnn] + have hm := mul_le_mul hcoef hbnd (abs_nonneg _) hD + apply hm.trans_eq + simp only [iteratedDeriv_succ] + ring + +end ZeroTemperatureSK.Heat + +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKSupport/Main.lean b/lean/OAI/Probability/SKSupport/Main.lean new file mode 100644 index 0000000000000000000000000000000000000000..754afb2758e552895c41a93c867007cf04a35cbd --- /dev/null +++ b/lean/OAI/Probability/SKSupport/Main.lean @@ -0,0 +1,66 @@ +import Mathlib +import OAI.Probability.SKSupport.Diffusion.AbsIncrement +import OAI.Probability.SKSupport.Diffusion.FeedbackVerification +import OAI.Probability.SKSupport.Backward.BackwardGradientMild +import OAI.Probability.SKSupport.Foundations.StepData +import OAI.Probability.SKSupport.Support.NoTerminalPlateau +import OAI.Probability.SKSupport.Support.GapCurvature +import OAI.Probability.SKSupport.Diffusion.Uniqueness + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section +namespace ZeroTemperatureSK +variable {Ω : Type*} [MeasurableSpace Ω] + +theorem minimizer_full_support_actual (W : BrownianSystem Ω) (γ : OrderParameter) (hmin : IsMinimizer W γ) + {μ : Measure Time} (hμ : IsStieltjesMeasure γ μ) : + μ.support=univ ∧ StrictMonoOn (extend γ.val) (Ico (0:ℝ) 1) ∧ + ∀ t ∈ Ico (0:ℝ) 1, squareMoment W γ (diffusion W γ) t=t ∧ curvatureMoment W γ t=1 := by + have hh := SupportDeterministic.Variation.full_support_of_contact_and_gap_curvature + (γ.original_deterministic) (stieltjes_deterministic γ hμ) + (squareMoment_continuousOn W γ) (curvatureMoment_continuousOn_unit W γ) + (fun t ht => squareMoment_hasDerivAt W γ ht.1 ht.2) (squareMoment_zero W γ) + (minimizer_contact W γ hmin hμ) (minimizer_no_terminal_plateau W γ hmin) + (fun a b c ha hab hb hc hconst => positive_gap_curvature W γ ha hab hb hc hconst) + (fun a b ha hab hb hconst => zero_gap_curvature W γ ha hab hb hconst) + have ha := SupportDeterministic.Variation.derivative_eq_one_of_full_contact hh.2.2 + (fun t ht => squareMoment_hasDerivAt W γ ht.1 ht.2) + (squareMoment_hasDerivWithinAt W γ (by norm_num : (0:ℝ) ≤ 0) (by norm_num : (0:ℝ) < 1)) + exact ⟨hh.1,hh.2.1,fun t ht => ⟨hh.2.2 t ht,ha t ht⟩⟩ + +theorem full_support (W : BrownianSystem Ω) (γ : OrderParameter) + (hmin : IsMinimizer W γ) : FullSupportConclusion W γ := by + have hμ := parameterMeasure_isStieltjes γ + have hs := minimizer_full_support_actual W γ hmin hμ + refine ⟨⟨parameterMeasure γ,hμ⟩,⟨diffusion W γ,diffusion_isDiffusion W γ⟩, + fun μ hμ => (minimizer_full_support_actual W γ hmin hμ).1,?_,?_⟩ + · intro a b hab + have hh := hs.2.1 a.property b.property hab + simpa only [extend,dite_eq_left a.property,dite_eq_left b.property] using hh + · intro X hX t + have he : X (Real.toNNReal t)=ᵐ[W.law] diffusion W γ (Real.toNNReal t) := by + filter_upwards [diffusion_uniqueness W γ hX] with ξ hξ + apply hξ + rw [← NNReal.coe_le_coe,Real.coe_toNNReal _ t.property.1,NNReal.coe_one] + exact t.property.2.le + have hq : squareMoment W γ X t=squareMoment W γ (diffusion W γ) t := by + apply integral_congr_ae + filter_upwards [he] with ξ hξ + rw [hξ] + have ha : (∫ ξ, (curvature W γ t (X (Real.toNNReal t) ξ))^2 ∂W.law)=curvatureMoment W γ t := by + apply integral_congr_ae + filter_upwards [he] with ξ hξ + rw [hξ] + rw [hq,ha] + exact hs.2.2 t t.property + +end ZeroTemperatureSK + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKSupport/Model.lean b/lean/OAI/Probability/SKSupport/Model.lean new file mode 100644 index 0000000000000000000000000000000000000000..4ad79e01ced7bd414ead755185c49a2ce22911ce --- /dev/null +++ b/lean/OAI/Probability/SKSupport/Model.lean @@ -0,0 +1,94 @@ +import Mathlib + +namespace OAI + +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology + +noncomputable section + +namespace ZeroTemperatureSK + +abbrev Time := Set.Ico (0 : ℝ) 1 + +def extend (γ : Time → ℝ) (t : ℝ) : ℝ := + if ht : t ∈ Set.Ico (0 : ℝ) 1 then γ ⟨t, ht⟩ else 0 + +structure OrderParameter where + val : Time → ℝ + nonneg : ∀ t, 0 ≤ val t + monotone : Monotone val + right_continuous : ∀ t, ContinuousWithinAt val (Set.Ici t) t + integrable : Integrable (extend val) + +structure BrownianSystem (Ω : Type*) [MeasurableSpace Ω] where + law : Measure Ω + isProbability : IsProbabilityMeasure law + B : ℝ≥0 → Ω → ℝ + measurable : ∀ t, Measurable (B t) + brownian : IsBrownianReal B law + +variable {Ω : Type*} [MeasurableSpace Ω] + +def incrementFiltration (W : BrownianSystem Ω) (t : ℝ≥0) : + Filtration ℝ≥0 ‹MeasurableSpace Ω› := + Filtration.natural (fun s ω => W.B (t + s) ω - W.B t ω) + (fun s => ((W.measurable (t + s)).sub (W.measurable t)).stronglyMeasurable) + +structure Control (W : BrownianSystem Ω) (t : ℝ≥0) where + val : ℝ≥0 → Ω → ℝ + progressive : IsProgressive (incrementFiltration W t) val + bound : ∀ s ω, |val s ω| ≤ 1 + +def controlPayoff (W : BrownianSystem Ω) (γ : OrderParameter) (t x : ℝ) + (α : Control W (Real.toNNReal t)) (ω : Ω) : ℝ := + |x + W.B 1 ω - W.B (Real.toNNReal t) ω + + ∫ s in t..1, extend γ.val s * α.val (Real.toNNReal (s - t)) ω| - + (1 / 2 : ℝ) * ∫ s in t..1, extend γ.val s * (α.val (Real.toNNReal (s - t)) ω)^2 + +def value (W : BrownianSystem Ω) (γ : OrderParameter) (t x : ℝ) : ℝ := + sSup (Set.range (fun α : Control W (Real.toNNReal t) => + ∫ ω, controlPayoff W γ t x α ω ∂W.law)) + +def gradient (W : BrownianSystem Ω) (γ : OrderParameter) (t x : ℝ) : ℝ := + deriv (value W γ t) x + +def curvature (W : BrownianSystem Ω) (γ : OrderParameter) (t x : ℝ) : ℝ := + deriv (gradient W γ t) x + +def parisi (W : BrownianSystem Ω) (γ : OrderParameter) : ℝ := + value W γ 0 0 - (1 / 2 : ℝ) * ∫ t in (0 : ℝ)..1, t * extend γ.val t + +def IsMinimizer (W : BrownianSystem Ω) (γ : OrderParameter) : Prop := + ∀ η : OrderParameter, parisi W γ ≤ parisi W η + +def IsStieltjesMeasure (γ : OrderParameter) (μ : Measure Time) : Prop := + ∀ t : Time, μ (Set.Iic t) = ENNReal.ofReal (γ.val t) + +def IsDiffusion (W : BrownianSystem Ω) (γ : OrderParameter) + (X : ℝ≥0 → Ω → ℝ) : Prop := + IsProgressive (Filtration.natural W.B (fun t => (W.measurable t).stronglyMeasurable)) X ∧ + (∀ᵐ ω ∂W.law, ContinuousOn (fun t : ℝ => X (Real.toNNReal t) ω) (Set.Icc 0 1) ∧ + X 0 ω = 0 ∧ ∀ t ∈ Set.Icc (0 : ℝ) 1, + X (Real.toNNReal t) ω = W.B (Real.toNNReal t) ω + + ∫ s in (0 : ℝ)..t, extend γ.val s * + gradient W γ s (X (Real.toNNReal s) ω)) + +def squareMoment (W : BrownianSystem Ω) (γ : OrderParameter) + (X : ℝ≥0 → Ω → ℝ) (t : ℝ) : ℝ := + ∫ ω, (gradient W γ t (X (Real.toNNReal t) ω))^2 ∂W.law + +def FullSupportConclusion (W : BrownianSystem Ω) (γ : OrderParameter) : Prop := + (∃ μ : Measure Time, IsStieltjesMeasure γ μ) ∧ + (∃ X : ℝ≥0 → Ω → ℝ, IsDiffusion W γ X) ∧ + (∀ μ : Measure Time, IsStieltjesMeasure γ μ → μ.support = Set.univ) ∧ + (∀ a b : Time, a < b → γ.val a < γ.val b) ∧ + ∀ X : ℝ≥0 → Ω → ℝ, IsDiffusion W γ X → ∀ t : Time, + squareMoment W γ X t = (t : ℝ) ∧ + (∫ ω, (curvature W γ t (X (Real.toNNReal t) ω))^2 ∂W.law) = 1 + +end ZeroTemperatureSK + +end + +end OAI diff --git a/lean/OAI/Probability/SKSupport/Moments/BurgersJets.lean b/lean/OAI/Probability/SKSupport/Moments/BurgersJets.lean new file mode 100644 index 0000000000000000000000000000000000000000..f2bfbc215f34fd07a50662cee4f26c3db6bb2e5b --- /dev/null +++ b/lean/OAI/Probability/SKSupport/Moments/BurgersJets.lean @@ -0,0 +1,198 @@ +import Mathlib +import OAI.Probability.SKSupport.Parabolic.BurgersConstruction + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology ContDiff +noncomputable section +namespace ZeroTemperatureSK.Heat + +namespace SmoothBurgers +variable {r : ℝ → ℝ → ℝ} (hr : SmoothBurgers r) +include hr + +lemma jet_spatial (n : ℕ) (t x : ℝ) : + HasDerivAt (iteratedDeriv n (r t)) (iteratedDeriv (n+1) (r t) x) x := + hasDerivAt_spatialJet (hr.family.regular t).smooth n x + +lemma jet_continuous (n : ℕ) (T : ℝ) : + ContinuousOn (fun p : ℝ × ℝ => iteratedDeriv n (r p.1) p.2) (Icc (0:ℝ) T ×ˢ univ) := + hr.family.continuousOn_iteratedDeriv (hr.continuous T) n + +lemma rate_family : BoundedSmoothFamily (burgersRate r) := by + convert (hr.family.deriv.deriv.const_mul (1/2:ℝ)).add (hr.family.mul hr.family.deriv) using 1 + funext t x + simp only [burgersRate,iteratedDeriv_succ,iteratedDeriv_zero] + +lemma rate_continuous (T : ℝ) : + ContinuousOn (fun p : ℝ × ℝ => burgersRate r p.1 p.2) (Icc (0:ℝ) T ×ˢ univ) := by + exact (continuousOn_const.mul (hr.jet_continuous 2 T)).add + ((hr.continuous T).mul (by simpa only [iteratedDeriv_one] using hr.jet_continuous 1 T)) + +lemma rate_deriv (t x : ℝ) : + deriv (burgersRate r t) x = (1/2:ℝ)*iteratedDeriv 3 (r t) x+ + (deriv (r t) x)^2+r t x*iteratedDeriv 2 (r t) x := by + have hd := ((hr.jet_spatial 2 t x).const_mul (1/2:ℝ)).add + ((hr.jet_spatial 0 t x).mul (hr.jet_spatial 1 t x)) + have hd' : HasDerivAt (burgersRate r t) ((1/2:ℝ)*iteratedDeriv 3 (r t) x+ + (deriv (r t) x)^2+r t x*iteratedDeriv 2 (r t) x) x := by + convert hd using 1 <;> first | rfl | ((try funext y); simp only + [burgersRate,Pi.add_apply,Pi.mul_apply,iteratedDeriv_succ,iteratedDeriv_zero] <;> ring) + exact hd'.deriv + +lemma rate_jet2 (t x : ℝ) : + iteratedDeriv 2 (burgersRate r t) x = (1/2:ℝ)*iteratedDeriv 4 (r t) x+ + 3*deriv (r t) x*iteratedDeriv 2 (r t) x+r t x*iteratedDeriv 3 (r t) x := by + have he : deriv (burgersRate r t) = fun y => (1/2:ℝ)*iteratedDeriv 3 (r t) y+ + (deriv (r t) y)^2+r t y*iteratedDeriv 2 (r t) y := funext (hr.rate_deriv t) + have hd := (((hr.jet_spatial 3 t x).const_mul (1/2:ℝ)).add + ((hr.jet_spatial 1 t x).pow 2)).add ((hr.jet_spatial 0 t x).mul (hr.jet_spatial 2 t x)) + rw [iteratedDeriv_succ (n := 1),iteratedDeriv_one,he] + convert hd.deriv using 1 <;> first | rfl | (simp only [iteratedDeriv_succ,iteratedDeriv_zero]; first | rfl | ring) + +lemma rate_jet3 (t x : ℝ) : + iteratedDeriv 3 (burgersRate r t) x = (1/2:ℝ)*iteratedDeriv 5 (r t) x+ + 3*(iteratedDeriv 2 (r t) x)^2+4*deriv (r t) x*iteratedDeriv 3 (r t) x+ + r t x*iteratedDeriv 4 (r t) x := by + have he : iteratedDeriv 2 (burgersRate r t) = fun y => (1/2:ℝ)*iteratedDeriv 4 (r t) y+ + 3*deriv (r t) y*iteratedDeriv 2 (r t) y+r t y*iteratedDeriv 3 (r t) y := funext (hr.rate_jet2 t) + have hd := (((hr.jet_spatial 4 t x).const_mul (1/2:ℝ)).add + (((hr.jet_spatial 1 t x).const_mul 3).mul (hr.jet_spatial 2 t x))).add + ((hr.jet_spatial 0 t x).mul (hr.jet_spatial 3 t x)) + rw [iteratedDeriv_succ (n := 2),he] + convert hd.deriv using 1 <;> first | rfl | (simp only [iteratedDeriv_succ,iteratedDeriv_zero]; first | rfl | ring) + +lemma rate_time {t : ℝ} (ht : 0 < t) (x : ℝ) : + HasDerivAt (fun s => burgersRate r s x) + ((1/2:ℝ)*iteratedDeriv 2 (burgersRate r t) x+ + r t x*deriv (burgersRate r t) x+deriv (r t) x*burgersRate r t x) t := by + convert ((hr.time_derivative 2 t ht x).const_mul (1/2:ℝ)).add + ((hr.time_derivative 0 t ht x).mul (hr.time_derivative 1 t ht x)) using 1 <;> + first | rfl | ((try funext y); simp only [burgersRate,Pi.add_apply,Pi.mul_apply,iteratedDeriv_succ,iteratedDeriv_zero] <;> ring) + +lemma rate_deriv_time {t : ℝ} (ht : 0 < t) (x : ℝ) : + HasDerivAt (fun s => deriv (burgersRate r s) x) + ((1/2:ℝ)*iteratedDeriv 3 (burgersRate r t) x+ + 2*deriv (r t) x*deriv (burgersRate r t) x+ + burgersRate r t x*iteratedDeriv 2 (r t) x+ + r t x*iteratedDeriv 2 (burgersRate r t) x) t := by + have he : (fun s => deriv (burgersRate r s) x) = fun s => + (1/2:ℝ)*iteratedDeriv 3 (r s) x+(deriv (r s) x)^2+r s x*iteratedDeriv 2 (r s) x := + funext (fun s => hr.rate_deriv s x) + rw [he] + convert (((hr.time_derivative 3 t ht x).const_mul (1/2:ℝ)).add + ((hr.time_derivative 1 t ht x).pow 2)).add + ((hr.time_derivative 0 t ht x).mul (hr.time_derivative 2 t ht x)) using 1 <;> + first | rfl | ((try funext y); simp only [Pi.add_apply,Pi.mul_apply,Pi.pow_apply,iteratedDeriv_succ,iteratedDeriv_zero] <;> ring) + +lemma rate_odd (ho : ∀ t, Function.Odd (r t)) (t : ℝ) : Function.Odd (burgersRate r t) := by + have he := odd_deriv_even ((hr.family.regular t).smooth.differentiable (by simp)) (ho t) + have hw := even_deriv_odd ((hr.family.deriv.regular t).smooth.differentiable (by simp)) he + intro x + simp only [burgersRate,iteratedDeriv_succ,iteratedDeriv_zero,hw x,he x,ho t x] + ring + +end SmoothBurgers +end ZeroTemperatureSK.Heat + +end +end +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology ContDiff +noncomputable section +namespace ZeroTemperatureSK.Heat + +def backwardWronskian (r : ℝ → ℝ → ℝ) (t x : ℝ) : ℝ := + r t x*deriv (burgersRate r t) x-deriv (r t) x*burgersRate r t x + +def wronskianRate (r : ℝ → ℝ → ℝ) (t x : ℝ) : ℝ := + burgersRate r t x*deriv (burgersRate r t) x+ + r t x*((1/2:ℝ)*iteratedDeriv 3 (burgersRate r t) x+ + 2*deriv (r t) x*deriv (burgersRate r t) x+ + burgersRate r t x*iteratedDeriv 2 (r t) x+ + r t x*iteratedDeriv 2 (burgersRate r t) x)- + (deriv (burgersRate r t) x*burgersRate r t x+ + deriv (r t) x*((1/2:ℝ)*iteratedDeriv 2 (burgersRate r t) x+ + r t x*deriv (burgersRate r t) x+deriv (r t) x*burgersRate r t x)) + +namespace SmoothBurgers +variable {r : ℝ → ℝ → ℝ} (hr : SmoothBurgers r) +include hr + +lemma wronskian_family : BoundedSmoothFamily (backwardWronskian r) := by + convert (hr.family.mul hr.rate_family.deriv).add + ((hr.family.deriv.mul hr.rate_family).const_mul (-1)) using 1 + funext t x + simp only [backwardWronskian] + ring + +lemma wronskian_continuous (T : ℝ) : + ContinuousOn (fun p : ℝ × ℝ => backwardWronskian r p.1 p.2) (Icc (0:ℝ) T ×ˢ univ) := by + apply ContinuousOn.sub + · exact (hr.continuous T).mul (by simpa only [iteratedDeriv_one] using + hr.rate_family.continuousOn_iteratedDeriv (hr.rate_continuous T) 1) + · have hv : ContinuousOn (fun p : ℝ × ℝ => deriv (r p.1) p.2) (Icc (0:ℝ) T ×ˢ univ) := by + simpa only [iteratedDeriv_one] using hr.jet_continuous 1 T + exact hv.mul (hr.rate_continuous T) + +lemma wronskian_deriv (t x : ℝ) : + deriv (backwardWronskian r t) x = + r t x*iteratedDeriv 2 (burgersRate r t) x-iteratedDeriv 2 (r t) x*burgersRate r t x := by + have hp (n) := hasDerivAt_spatialJet (hr.rate_family.regular t).smooth n x + have hd := ((hr.jet_spatial 0 t x).mul (hp 1)).sub ((hr.jet_spatial 1 t x).mul (hp 0)) + have hd' : HasDerivAt (backwardWronskian r t) + (r t x*iteratedDeriv 2 (burgersRate r t) x-iteratedDeriv 2 (r t) x*burgersRate r t x) x := by + convert hd using 1 <;> first | rfl | ((try funext y); simp only + [backwardWronskian,Pi.sub_apply,Pi.mul_apply,iteratedDeriv_succ,iteratedDeriv_zero] <;> ring) + exact hd'.deriv + +lemma wronskian_jet2 (t x : ℝ) : + iteratedDeriv 2 (backwardWronskian r t) x = + deriv (r t) x*iteratedDeriv 2 (burgersRate r t) x+ + r t x*iteratedDeriv 3 (burgersRate r t) x- + (iteratedDeriv 3 (r t) x*burgersRate r t x+ + iteratedDeriv 2 (r t) x*deriv (burgersRate r t) x) := by + have hp (n) := hasDerivAt_spatialJet (hr.rate_family.regular t).smooth n x + have he : deriv (backwardWronskian r t) = fun y => + r t y*iteratedDeriv 2 (burgersRate r t) y-iteratedDeriv 2 (r t) y*burgersRate r t y := + funext (hr.wronskian_deriv t) + rw [iteratedDeriv_succ (n := 1),iteratedDeriv_one,he] + convert (((hr.jet_spatial 0 t x).mul (hp 2)).sub ((hr.jet_spatial 2 t x).mul (hp 0))).deriv + using 1 <;> first | rfl | simp only [iteratedDeriv_succ,iteratedDeriv_zero] + +lemma wronskian_time {t : ℝ} (ht : 0 < t) (x : ℝ) : + HasDerivAt (fun s => backwardWronskian r s x) (wronskianRate r t x) t := by + convert ((hr.time_derivative 0 t ht x).mul (hr.rate_deriv_time ht x)).sub + ((hr.time_derivative 1 t ht x).mul (hr.rate_time ht x)) using 1 <;> + first | rfl | ((try funext y); simp only [backwardWronskian,wronskianRate, + Pi.sub_apply,Pi.mul_apply,iteratedDeriv_succ,iteratedDeriv_zero]) + +lemma wronskian_equation (t x : ℝ) (hne : r t x ≠ 0) : + wronskianRate r t x-(1/2:ℝ)*iteratedDeriv 2 (backwardWronskian r t) x- + (r t x-deriv (r t) x/r t x)*deriv (backwardWronskian r t) x- + 2*(burgersRate r t x/r t x)*backwardWronskian r t x = + r t x*iteratedDeriv 2 (r t) x*burgersRate r t x := by + rw [hr.wronskian_jet2,hr.wronskian_deriv] + simp only [wronskianRate,backwardWronskian,hr.rate_deriv,hr.rate_jet2,hr.rate_jet3,burgersRate] + field_simp [hne] + ring + +lemma wronskian_odd (ho : ∀ t, Function.Odd (r t)) (t : ℝ) : + Function.Odd (backwardWronskian r t) := by + have hr' := odd_deriv_even ((hr.family.regular t).smooth.differentiable (by simp)) (ho t) + have hp := hr.rate_odd ho t + have hp' := odd_deriv_even ((hr.rate_family.regular t).smooth.differentiable (by simp)) hp + intro x + simp only [backwardWronskian,ho t x,hr' x,hp x,hp' x] + ring + +end SmoothBurgers +end ZeroTemperatureSK.Heat + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKSupport/Moments/Curvature.lean b/lean/OAI/Probability/SKSupport/Moments/Curvature.lean new file mode 100644 index 0000000000000000000000000000000000000000..fb54486ebd4e121e93e5cfafb7c8c9585f36acb3 --- /dev/null +++ b/lean/OAI/Probability/SKSupport/Moments/Curvature.lean @@ -0,0 +1,103 @@ +import Mathlib +import OAI.Probability.SKSupport.Moments.ThirdFields +import OAI.Probability.SKSupport.Moments.StrictMoments +import OAI.Probability.SKSupport.Density.SampleJets + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology ContDiff +noncomputable section +namespace ZeroTemperatureSK +open Heat WeakIto +variable {Ω : Type*} [MeasurableSpace Ω] + +lemma compactJet_eq_value (W : BrownianSystem Ω) (γ : OrderParameter) (T : Time) + {t : ℝ} (ht : t ∈ Icc (0:ℝ) T) (n : ℕ) (x : ℝ) : + compactJet W γ T n t x=iteratedDeriv (n+1) (value W γ t) x := by + unfold compactJet compactGradient gradient + rw [stripClamp_eq ht,iteratedDeriv_succ'] + +lemma stripSecond_eq_actual (W : BrownianSystem Ω) (γ : OrderParameter) (T t : Time) + (htT : t ≤ T) (c : ℝ) : + stripSecond W γ T c t = ∫ ξ, (actualJet W γ t 3 ξ)^2-2*c*(actualJet W γ t 2 ξ)^3 ∂W.law := by + unfold stripSecond TimeField.expected + apply integral_congr_ae + filter_upwards [] with ξ + rw [secondCurvatureField_eq] + have heNN : Real.toNNReal (t:ℝ)=(⟨t,t.property.1⟩:ℝ≥0) := by ext;exact Real.coe_toNNReal _ t.property.1 + rw [heNN] + have hd := diffusion_eq_strip W γ T (⟨t,t.property.1⟩:ℝ≥0) htT ξ + rw [← hd,compactJet_eq_value W γ T ⟨t.property.1,htT⟩, + compactJet_eq_value W γ T ⟨t.property.1,htT⟩] + rfl + +lemma stripThird_eq_actual (W : BrownianSystem Ω) (γ : OrderParameter) (T t : Time) + (htT : t ≤ T) (c : ℝ) : + stripThird W γ T c t = ∫ ξ, (actualJet W γ t 4 ξ)^2- + 12*c*actualJet W γ t 2 ξ*(actualJet W γ t 3 ξ)^2+6*c^2*(actualJet W γ t 2 ξ)^4 ∂W.law := by + unfold stripThird TimeField.expected + apply integral_congr_ae + filter_upwards [] with ξ + rw [thirdCurvatureField_eq] + have heNN : Real.toNNReal (t:ℝ)=(⟨t,t.property.1⟩:ℝ≥0) := by ext;exact Real.coe_toNNReal _ t.property.1 + rw [heNN] + have hd := diffusion_eq_strip W γ T (⟨t,t.property.1⟩:ℝ≥0) htT ξ + rw [← hd,compactJet_eq_value W γ T ⟨t.property.1,htT⟩, + compactJet_eq_value W γ T ⟨t.property.1,htT⟩,compactJet_eq_value W γ T ⟨t.property.1,htT⟩] + rfl + +lemma actualQuartic_pos (W : BrownianSystem Ω) (γ : OrderParameter) (t : Time) + (ht : 0 < (t:ℝ)) : 0 < ∫ ξ, (actualJet W γ t 2 ξ)^4 ∂W.law := by + apply actual_jet_even_moment_pos W γ t ht 1 2 (by norm_num) + have hn := curvature_not_identically_zero W γ t.property.1 t.property.2 + change ∃ x, deriv (deriv (value W γ t)) x ≠ 0 at hn + simpa only [iteratedDeriv_succ,iteratedDeriv_zero] using hn + +lemma actualThirdSquare_pos (W : BrownianSystem Ω) (γ : OrderParameter) (t : Time) + (ht : 0 < (t:ℝ)) : 0 < ∫ ξ, (actualJet W γ t 3 ξ)^2 ∂W.law := by + apply actual_jet_even_moment_pos W γ t ht 2 1 (by norm_num) + have hn := third_not_identically_zero W γ t.property.1 t.property.2 + change ∃ x, deriv (deriv (deriv (value W γ t))) x ≠ 0 at hn + simpa only [iteratedDeriv_succ,iteratedDeriv_zero] using hn + +lemma stripThird_coercive (W : BrownianSystem Ω) (γ : OrderParameter) (T t : Time) + (ht : 0 < (t:ℝ)) (htT : t ≤ T) (hcont : ContinuousAt γ.val t) : + (1/1000:ℝ)*(γ.val t)^4*(∫ ξ, (actualJet W γ t 2 ξ)^4 ∂W.law) ≤ + (γ.val t)^2 * stripThird W γ T (γ.val t) t := by + have hh := actual_coercivity W γ t ht hcont + have hl : (∫ ξ, quarticJetPolynomial (γ.val t) (actualJet W γ t 2 ξ) ∂W.law)= + (γ.val t)^4*(∫ ξ, (actualJet W γ t 2 ξ)^4 ∂W.law) := by + exact integral_const_mul _ _ + have hr : (∫ ξ, coerciveJetPolynomial (γ.val t) + (actualJet W γ t 2 ξ) (actualJet W γ t 3 ξ) (actualJet W γ t 4 ξ) ∂W.law)= + (γ.val t)^2 * stripThird W γ T (γ.val t) t := by + rw [stripThird_eq_actual W γ T t htT,← integral_const_mul] + apply integral_congr_ae + filter_upwards [] with ξ + unfold coerciveJetPolynomial + ring + rw [hl,hr] at hh + simpa only [mul_assoc] using hh + +lemma stripThird_pos (W : BrownianSystem Ω) (γ : OrderParameter) (T t : Time) + (ht : 0 < (t:ℝ)) (htT : t ≤ T) (hcont : ContinuousAt γ.val t) (hc : 0 < γ.val t) : + 0 < stripThird W γ T (γ.val t) t := by + have hp := actualQuartic_pos W γ t ht + have hh := stripThird_coercive W γ T t ht htT hcont + have hl : 0 < (1/1000:ℝ)*(γ.val t)^4*(∫ ξ, (actualJet W γ t 2 ξ)^4 ∂W.law) := by positivity + exact (mul_pos_iff_of_pos_left (sq_pos_of_pos hc)).mp (hl.trans_le hh) + +lemma stripSecond_zero_pos (W : BrownianSystem Ω) (γ : OrderParameter) (T t : Time) + (ht : 0 < (t:ℝ)) (htT : t ≤ T) : 0 < stripSecond W γ T 0 t := by + rw [stripSecond_eq_actual W γ T t htT] + simp only [mul_zero,zero_mul,sub_zero] + exact actualThirdSquare_pos W γ t ht + +end ZeroTemperatureSK + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKSupport/Moments/FamilyReparam.lean b/lean/OAI/Probability/SKSupport/Moments/FamilyReparam.lean new file mode 100644 index 0000000000000000000000000000000000000000..781180883c7c9af1ad36742eccd4b76417daf6e0 --- /dev/null +++ b/lean/OAI/Probability/SKSupport/Moments/FamilyReparam.lean @@ -0,0 +1,47 @@ +import Mathlib +import OAI.Probability.SKSupport.Regularity.BoundedSmoothFamily + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology ContDiff +noncomputable section +namespace ZeroTemperatureSK.Heat + +lemma scaled_composition_jet {f : ℝ → ℝ} (hf : ContDiff ℝ ∞ f) (a : ℝ) (n : ℕ) (x : ℝ) : + _root_.iteratedDeriv n (fun y => f (a*y)) x = a^n*_root_.iteratedDeriv n f (a*x) := by + exact congrFun (iteratedDeriv_comp_const_mul + (hf.of_le (ENat.natCast_le_of_coe_top_le_withTop le_rfl n)) a) x + +lemma BoundedSmoothFamily.reparam {F : ℝ → ℝ → ℝ} (hF : BoundedSmoothFamily F) + {A C : ℝ → ℝ} (hA : Measurable A) (hC : Measurable C) (hb : ∀ t, |C t| ≤ 1) : + BoundedSmoothFamily (fun t x => F (A t) (C t*x)) := by + have hbound (n : ℕ) : ∃ K : ℝ≥0, ∀ t x, + |_root_.iteratedDeriv n (fun y => F (A t) (C t*y)) x| ≤ K := by + obtain ⟨K,hK⟩ := hF.bounds n + refine ⟨K,fun t x => ?_⟩ + rw [scaled_composition_jet (hF.regular (A t)).smooth,abs_mul,abs_pow] + calc + |C t|^n*|_root_.iteratedDeriv n (F (A t)) (C t*x)| ≤ 1*(K:ℝ) := + mul_le_mul (pow_le_one₀ (abs_nonneg _) (hb t)) (hK _ _) (abs_nonneg _) (by norm_num) + _ = _ := one_mul _ + refine ⟨hF.measurable.comp ((hA.comp measurable_fst).prodMk + ((hC.comp measurable_fst).mul measurable_snd)),?_,hbound⟩ + intro t + refine ⟨(hF.regular (A t)).smooth.comp (contDiff_const.mul contDiff_id),?_⟩ + intro n + obtain ⟨K,hK⟩ := hbound n + exact ⟨K,hK t⟩ + +lemma BoundedSmoothFamily.timeMul {F : ℝ → ℝ → ℝ} (hF : BoundedSmoothFamily F) + {C : ℝ → ℝ} {K : ℝ≥0} (hC : Measurable C) (hb : ∀ t, |C t| ≤ K) : + BoundedSmoothFamily (fun t x => C t*F t x) := + (BoundedSmoothFamily.timeConst hC hb).mul hF + +end ZeroTemperatureSK.Heat + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKSupport/Moments/FiniteStrictConvex.lean b/lean/OAI/Probability/SKSupport/Moments/FiniteStrictConvex.lean new file mode 100644 index 0000000000000000000000000000000000000000..48dadc17c25b7c6276f5c405e54a95fb61e190d1 --- /dev/null +++ b/lean/OAI/Probability/SKSupport/Moments/FiniteStrictConvex.lean @@ -0,0 +1,64 @@ +import Mathlib +import OAI.Probability.SKSupport.Parabolic.AffineEvolution + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology ContDiff +noncomputable section +namespace ZeroTemperatureSK.Heat + +lemma softAbs_curvature_pos {M : ℝ} (hM : 0 < M) (x : ℝ) : + 0 < deriv (deriv (softAbs M)) x := by + have he : deriv (softAbs M) = fun y => Real.tanh (M*y) := + funext (fun y => (hasDerivAt_softAbs (ne_of_gt hM) y).deriv) + rw [he] + have hd := (hasDerivAt_tanh (M*x)).comp x ((hasDerivAt_id x).const_mul M) + have hd' : HasDerivAt (fun y => Real.tanh (M*y)) ((1-(Real.tanh (M*x))^2)*M) x := by + simpa only [Function.comp_def,id_eq,mul_one] using hd + rw [hd'.deriv] + have hh := Real.abs_tanh_lt_one (M*x) + have hs : (Real.tanh (M*x))^2 < 1 := by nlinarith [sq_abs (Real.tanh (M*x)),abs_nonneg (Real.tanh (M*x))] + exact mul_pos (sub_pos.mpr hs) hM + +lemma cascade_curvature_pos {f : ℝ → ℝ} (hf : RegularDatum f) (hLip : LipschitzWith 1 f) + (hpos : ∀ x, 0 < deriv (deriv f) x) (c : ℕ → ℝ≥0) (h : ℝ≥0) (N i : ℕ) (x : ℝ) : + 0 < deriv (deriv (cascade c h f N i)) x := by + induction N generalizing i x with + | zero => exact hpos x + | succ N ih => + exact logSemigroup_curvature_pos (cascade_regular hf hLip c h N (i+1)) + (cascade_lipschitz hLip c h N (i+1)) (ih (i+1)) (c i).coe_nonneg h x + +lemma varianceLogHeat_curvature_pos {f : ℝ → ℝ} {K : ℝ≥0} + (hf : RegularDatum f) (hLip : LipschitzWith K f) (hpos : ∀ x, 0 < deriv (deriv f) x) + {c : ℝ} (hc : 0 ≤ c) (t x : ℝ) : + 0 < deriv (deriv (varianceLogHeat c t f)) x := by + have he : varianceLogHeat c t f = logSemigroup c (Real.toNNReal t) f := + funext (varianceLogHeat_eq_logSemigroup_toNNReal hf.smooth.continuous.measurable c t) + rw [he] + exact logSemigroup_curvature_pos hf hLip hpos hc _ x + +theorem finite_softAbs_curvature_pos {M : ℝ} (hM : 0 < M) + (c : ℕ → ℝ≥0) (h : ℝ≥0) (N i : ℕ) (t x : ℝ) : + 0 < deriv (deriv (finiteValue c h (softAbs M) N i t)) x := by + induction N generalizing i t with + | zero => exact softAbs_curvature_pos hM x + | succ N ih => + by_cases ht : t ≤ h + · rw [finiteValue_head _ c h N i ht] + exact varianceLogHeat_curvature_pos + (cascade_regular (regularDatum_softAbs (ne_of_gt hM)) (softAbs_lipschitz (ne_of_gt hM)) c h N (i+1)) + (cascade_lipschitz (softAbs_lipschitz (ne_of_gt hM)) c h N (i+1)) + (cascade_curvature_pos (regularDatum_softAbs (ne_of_gt hM)) (softAbs_lipschitz (ne_of_gt hM)) + (softAbs_curvature_pos hM) c h N (i+1)) (c i).coe_nonneg (h-t) x + · rw [finiteValue_tail _ c h N i (lt_of_not_ge ht)] + exact ih (i+1) (t-h) + +end ZeroTemperatureSK.Heat + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKSupport/Moments/IntegratedCompletionSquare.lean b/lean/OAI/Probability/SKSupport/Moments/IntegratedCompletionSquare.lean new file mode 100644 index 0000000000000000000000000000000000000000..18d9bd90a140941dc1bed529b66624ee62b26aa1 --- /dev/null +++ b/lean/OAI/Probability/SKSupport/Moments/IntegratedCompletionSquare.lean @@ -0,0 +1,65 @@ +import Mathlib +import OAI.Probability.SKSupport.Model + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section +namespace ZeroTemperatureSK.WeakIto + +lemma integrated_completion_square (a b c u : ℝ) (hab : a ≤ b) (hc : 0 ≤ c) + {α : ℝ → ℝ} (hα : IntervalIntegrable α volume a b) + (hα₂ : IntervalIntegrable (fun t => (α t)^2) volume a b) : + u * (∫ t in a..b, c*α t) - (1/2:ℝ)*(∫ t in a..b, c*(α t)^2) ≤ + (b-a)*c/2*u^2 := by + have hmono : (∫ t in a..b, u*(c*α t)-(1/2:ℝ)*(c*(α t)^2)) ≤ + ∫ _t in a..b, c/2*u^2 := by + apply intervalIntegral.integral_mono_on hab + ((hα.const_mul c).const_mul u |>.sub ((hα₂.const_mul c).const_mul (1/2:ℝ))) + intervalIntegrable_const + intro t ht + nlinarith [mul_nonneg hc (sq_nonneg (α t-u))] + rw [intervalIntegral.integral_sub ((hα.const_mul c).const_mul u) + ((hα₂.const_mul c).const_mul (1/2:ℝ)), intervalIntegral.integral_const_mul, + intervalIntegral.integral_const_mul, intervalIntegral.integral_const] at hmono + simpa only [intervalIntegral.integral_const_mul, smul_eq_mul, mul_div_assoc, mul_assoc] using hmono + +lemma completion_square_feedback (c h u : ℝ) : + u*(c*h*u)-(c*h/2*u^2) = h*c/2*u^2 := by ring + +lemma finite_mesh_verification (F K : ℕ → ℝ) (n : ℕ) (ε : ℝ) + (hstep : ∀ k < n, F (k+1)-F k-K k ≤ ε) : + F n-F 0-(∑ k ∈ Finset.range n, K k) ≤ (n:ℝ)*ε := by + have hh := Finset.sum_le_sum (s := Finset.range n) + (f := fun k => F (k+1)-F k-K k) (g := fun _ => ε) + (fun k hk => hstep k (Finset.mem_range.mp hk)) + rw [Finset.sum_sub_distrib, Finset.sum_range_sub F] at hh + simpa using hh + +lemma vanishing_mesh_error (T A C : ℝ) : + Tendsto (fun n : ℕ => + (n:ℝ) * (A*(T/(n:ℝ))*Real.sqrt (T/(n:ℝ)) + C*(T/(n:ℝ))^2)) atTop (𝓝 0) := by + have hn : Tendsto (fun n : ℕ => (n:ℝ)) atTop atTop := tendsto_natCast_atTop_atTop + have hh : Tendsto (fun n : ℕ => T/(n:ℝ)) atTop (𝓝 0) := + tendsto_const_nhds.div_atTop hn + have hlim : Tendsto (fun n : ℕ => A*T*Real.sqrt (T/(n:ℝ)) + C*T*(T/(n:ℝ))) + atTop (𝓝 0) := by + simpa using ((tendsto_const_nhds.mul (Real.continuous_sqrt.tendsto 0 |>.comp hh)).add + (tendsto_const_nhds.mul hh)) + apply hlim.congr' + filter_upwards [eventually_ge_atTop (1:ℕ)] with n hn + have hn' : (n:ℝ) ≠ 0 := by exact_mod_cast (Nat.ne_of_gt (lt_of_lt_of_le (by decide : 0<1) hn)) + field_simp + +end ZeroTemperatureSK.WeakIto + +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKSupport/Moments/JetFields.lean b/lean/OAI/Probability/SKSupport/Moments/JetFields.lean new file mode 100644 index 0000000000000000000000000000000000000000..e0574183c34cc74cca5d902161cb8b8418563d2c --- /dev/null +++ b/lean/OAI/Probability/SKSupport/Moments/JetFields.lean @@ -0,0 +1,183 @@ +import Mathlib +import OAI.Probability.SKSupport.Moments.SquareEquation +import OAI.Probability.SKSupport.Regularity.TimeFields + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology ContDiff +noncomputable section +namespace ZeroTemperatureSK +open Heat WeakIto +variable {Ω : Type*} [MeasurableSpace Ω] + +def compactJet (W : BrownianSystem Ω) (γ : OrderParameter) (T : ℝ) (n : ℕ) (t x : ℝ) : ℝ := + iteratedDeriv n (compactGradient W γ T t) x + +lemma compactJet_hasDerivAt (W : BrownianSystem Ω) (γ : OrderParameter) {T : ℝ} + (hT0 : 0 ≤ T) (hT1 : T < 1) (n : ℕ) (t x : ℝ) : + HasDerivAt (compactJet W γ T n t) (compactJet W γ T (n+1) t x) x := + by + have hh : ContDiff ℝ ∞ (compactJet W γ T n t) := + (((compactGradient_family W γ hT0 hT1).iteratedDeriv n).regular t).smooth + have he : compactJet W γ T (n+1) t x=deriv (compactJet W γ T n t) x := by + unfold compactJet + rw [iteratedDeriv_succ] + rw [he] + exact (hh.differentiable (by simp) x).hasDerivAt + +lemma deriv_compactJet (W : BrownianSystem Ω) (γ : OrderParameter) {T : ℝ} + (hT0 : 0 ≤ T) (hT1 : T < 1) (n : ℕ) (t : ℝ) : + deriv (compactJet W γ T n t)=compactJet W γ T (n+1) t := + funext (fun x => (compactJet_hasDerivAt W γ hT0 hT1 n t x).deriv) + +def compactJetField (W : BrownianSystem Ω) (γ : OrderParameter) {T : ℝ} + (hT0 : 0 ≤ T) (hT1 : T < 1) (n : ℕ) : TimeField T where + f := compactJet W γ T n + d := fun t x => iteratedDeriv (n+1) (compactValueRate W γ T t) x + smooth := (compactGradient_family W γ hT0 hT1).iteratedDeriv n + rate_smooth := (compactValueRate_family W γ hT0 hT1).iteratedDeriv (n+1) + continuous := compactGradient_derivative_continuous W γ hT0 hT1 n + rate_right := fun t x => (compactValueRate_rightSmooth W γ hT0 hT1 (n+1) t x).mono Ioi_subset_Ici_self + time_deriv := by + intro t ht0 htT x + have hh := value_derivative_hasDerivWithinAt_right W γ hT0 hT1 ht0 htT (n+1) x + apply hh.congr_of_eventuallyEq + · filter_upwards [self_mem_nhdsWithin,mem_nhdsWithin_of_mem_nhds (gt_mem_nhds htT)] with s hs hsT + unfold compactJet compactGradient gradient + rw [stripClamp_eq ⟨ht0.trans hs.le,hsT.le⟩,iteratedDeriv_succ'] + · unfold compactJet compactGradient gradient + rw [stripClamp_eq ⟨ht0,htT.le⟩,iteratedDeriv_succ'] + +lemma compactRate_jet_one (W : BrownianSystem Ω) (γ : OrderParameter) {T : ℝ} + (hT0 : 0 ≤ T) (hT1 : T < 1) (t x : ℝ) : + deriv (compactValueRate W γ T t) x= -(1/2:ℝ)*compactJet W γ T 2 t x- + compactCoeff γ T t*compactJet W γ T 0 t x*compactJet W γ T 1 t x := by + simpa only [compactJet,iteratedDeriv_succ,iteratedDeriv_zero] using deriv_compactValueRate W γ hT0 hT1 t x + +lemma compactRate_jet_two (W : BrownianSystem Ω) (γ : OrderParameter) {T : ℝ} + (hT0 : 0 ≤ T) (hT1 : T < 1) (t x : ℝ) : + iteratedDeriv 2 (compactValueRate W γ T t) x= -(1/2:ℝ)*compactJet W γ T 3 t x- + compactCoeff γ T t*((compactJet W γ T 1 t x)^2+compactJet W γ T 0 t x*compactJet W γ T 2 t x) := by + have he : deriv (compactValueRate W γ T t)=fun y => -(1/2:ℝ)*compactJet W γ T 2 t y- + compactCoeff γ T t*compactJet W γ T 0 t y*compactJet W γ T 1 t y := funext (compactRate_jet_one W γ hT0 hT1 t) + have hd (n : ℕ) := compactJet_hasDerivAt W γ hT0 hT1 n t x + have hh := ((hd 2).const_mul (-(1/2:ℝ))).sub (((hd 0).const_mul (compactCoeff γ T t)).mul (hd 1)) + have hdv := hh.deriv + change deriv (fun y => -(1/2:ℝ)*compactJet W γ T 2 t y- + compactCoeff γ T t*compactJet W γ T 0 t y*compactJet W γ T 1 t y) x = _ at hdv + simp only [show (2:ℕ)=1+1 from rfl,iteratedDeriv_succ,iteratedDeriv_zero] at ⊢ + rw [he,hdv] + ring + +lemma compactRate_jet_three (W : BrownianSystem Ω) (γ : OrderParameter) {T : ℝ} + (hT0 : 0 ≤ T) (hT1 : T < 1) (t x : ℝ) : + iteratedDeriv 3 (compactValueRate W γ T t) x= -(1/2:ℝ)*compactJet W γ T 4 t x- + compactCoeff γ T t*(3*compactJet W γ T 1 t x*compactJet W γ T 2 t x+ + compactJet W γ T 0 t x*compactJet W γ T 3 t x) := by + have he : iteratedDeriv 2 (compactValueRate W γ T t)=fun y => -(1/2:ℝ)*compactJet W γ T 3 t y- + compactCoeff γ T t*((compactJet W γ T 1 t y)^2+compactJet W γ T 0 t y*compactJet W γ T 2 t y) := + funext (compactRate_jet_two W γ hT0 hT1 t) + have hd (n : ℕ) := compactJet_hasDerivAt W γ hT0 hT1 n t x + have hh := ((hd 3).const_mul (-(1/2:ℝ))).sub + ((((hd 1).pow 2).add ((hd 0).mul (hd 2))).const_mul (compactCoeff γ T t)) + have hdv := hh.deriv + change deriv (fun y => -(1/2:ℝ)*compactJet W γ T 3 t y- + compactCoeff γ T t*((compactJet W γ T 1 t y)^2+compactJet W γ T 0 t y*compactJet W γ T 2 t y)) x = _ at hdv + rw [show (3:ℕ)=2+1 from rfl,iteratedDeriv_succ,he,hdv] + ring + +lemma compactJetField_generator_one (W : BrownianSystem Ω) (γ : OrderParameter) {T : ℝ} + (hT0 : 0 ≤ T) (hT1 : T < 1) (t x : ℝ) : + (compactJetField W γ hT0 hT1 1).generator (compactDrift W γ T) t x= + -compactCoeff γ T t*(compactJet W γ T 1 t x)^2 := by + dsimp only [TimeField.generator,compactJetField] + rw [deriv_compactJet W γ hT0 hT1,deriv_compactJet W γ hT0 hT1, + compactRate_jet_two W γ hT0 hT1] + change compactJet W γ T 2 t x*(compactCoeff γ T t*compactJet W γ T 0 t x)+_+_= _ + ring + +lemma compactJetField_generator_two (W : BrownianSystem Ω) (γ : OrderParameter) {T : ℝ} + (hT0 : 0 ≤ T) (hT1 : T < 1) (t x : ℝ) : + (compactJetField W γ hT0 hT1 2).generator (compactDrift W γ T) t x= + -3*compactCoeff γ T t*compactJet W γ T 1 t x*compactJet W γ T 2 t x := by + dsimp only [TimeField.generator,compactJetField] + rw [deriv_compactJet W γ hT0 hT1,deriv_compactJet W γ hT0 hT1, + compactRate_jet_three W γ hT0 hT1] + change compactJet W γ T 3 t x*(compactCoeff γ T t*compactJet W γ T 0 t x)+_+_= _ + ring + +end ZeroTemperatureSK + +end +end +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section +namespace ZeroTemperatureSK +open Heat WeakIto +variable {Ω : Type*} [MeasurableSpace Ω] + +def curvatureField (W : BrownianSystem Ω) (γ : OrderParameter) {T : ℝ} + (hT0 : 0 ≤ T) (hT1 : T < 1) : TimeField T := + (compactJetField W γ hT0 hT1 1).mul (compactJetField W γ hT0 hT1 1) + +def secondCurvatureField (W : BrownianSystem Ω) (γ : OrderParameter) {T : ℝ} + (hT0 : 0 ≤ T) (hT1 : T < 1) (c : ℝ) : TimeField T := + ((compactJetField W γ hT0 hT1 2).mul (compactJetField W γ hT0 hT1 2)).add + (((curvatureField W γ hT0 hT1).mul (compactJetField W γ hT0 hT1 1)).const_mul (-2*c)) + +lemma curvatureField_deriv (W : BrownianSystem Ω) (γ : OrderParameter) {T : ℝ} + (hT0 : 0 ≤ T) (hT1 : T < 1) (t x : ℝ) : + deriv ((curvatureField W γ hT0 hT1).f t) x= + 2*compactJet W γ T 1 t x*compactJet W γ T 2 t x := by + have hd := compactJet_hasDerivAt W γ hT0 hT1 1 t x + exact (hd.mul hd).deriv.trans (by ring) + +lemma curvatureField_generator (W : BrownianSystem Ω) (γ : OrderParameter) {T : ℝ} + (hT0 : 0 ≤ T) (hT1 : T < 1) (t x : ℝ) : + (curvatureField W γ hT0 hT1).generator (compactDrift W γ T) t x= + (secondCurvatureField W γ hT0 hT1 (compactCoeff γ T t)).f t x := by + unfold curvatureField + rw [TimeField.generator_mul,compactJetField_generator_one W γ hT0 hT1] + dsimp only [compactJetField] + rw [deriv_compactJet W γ hT0 hT1] + dsimp only [secondCurvatureField,curvatureField,TimeField.add,TimeField.mul,TimeField.const_mul,compactJetField] + ring + +lemma secondCurvatureField_generator (W : BrownianSystem Ω) (γ : OrderParameter) {T : ℝ} + (hT0 : 0 ≤ T) (hT1 : T < 1) (c t x : ℝ) (hc : compactCoeff γ T t=c) : + (secondCurvatureField W γ hT0 hT1 c).generator (compactDrift W γ T) t x= + (compactJet W γ T 3 t x)^2-12*c*compactJet W γ T 1 t x*(compactJet W γ T 2 t x)^2+ + 6*c^2*(compactJet W γ T 1 t x)^4 := by + unfold secondCurvatureField + rw [TimeField.generator_add,TimeField.generator_const_mul,TimeField.generator_mul,TimeField.generator_mul, + curvatureField_generator W γ hT0 hT1,compactJetField_generator_one W γ hT0 hT1, + compactJetField_generator_two W γ hT0 hT1,curvatureField_deriv W γ hT0 hT1] + dsimp only [compactJetField] + rw [deriv_compactJet W γ hT0 hT1,deriv_compactJet W γ hT0 hT1] + dsimp only [secondCurvatureField,curvatureField,TimeField.add,TimeField.mul,TimeField.const_mul,compactJetField] + rw [hc] + ring + +lemma curvatureField_eq (W : BrownianSystem Ω) (γ : OrderParameter) {T : ℝ} + (hT0 : 0 ≤ T) (hT1 : T < 1) (t x : ℝ) : + (curvatureField W γ hT0 hT1).f t x=(compactJet W γ T 1 t x)^2 := by + dsimp only [curvatureField,TimeField.mul,compactJetField] + ring + +lemma secondCurvatureField_eq (W : BrownianSystem Ω) (γ : OrderParameter) {T : ℝ} + (hT0 : 0 ≤ T) (hT1 : T < 1) (c t x : ℝ) : + (secondCurvatureField W γ hT0 hT1 c).f t x= + (compactJet W γ T 2 t x)^2-2*c*(compactJet W γ T 1 t x)^3 := by + dsimp only [secondCurvatureField,curvatureField,TimeField.add,TimeField.mul,TimeField.const_mul,compactJetField] + ring + +end ZeroTemperatureSK + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKSupport/Moments/NormalFirstMoment.lean b/lean/OAI/Probability/SKSupport/Moments/NormalFirstMoment.lean new file mode 100644 index 0000000000000000000000000000000000000000..e5eb7b79f0fbdb533c0d19978d51bc077ca22e65 --- /dev/null +++ b/lean/OAI/Probability/SKSupport/Moments/NormalFirstMoment.lean @@ -0,0 +1,118 @@ +import Mathlib +import OAI.Probability.SKSupport.Diffusion.ExpectedBrownianStep + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section +namespace ZeroTemperatureSK.WeakIto + +def normalFirstMoment : ℝ := ∫ x : ℝ, |x| ∂gaussianReal 0 1 + +lemma normalFirstMoment_nonneg : 0 ≤ normalFirstMoment := integral_nonneg abs_nonneg + +variable {Ω : Type*} [MeasurableSpace Ω] {P : Measure Ω} {B : ℝ≥0 → Ω → ℝ} + +lemma increment_abs_first (hB : IsPreBrownianReal B P) (s h : ℝ≥0) : + (∫ ω, |B (s+h) ω - B s ω| ∂P) = Real.sqrt (h:ℝ)*normalFirstMoment := by + have he := (hB.hasLaw_sub (s+h) s).integral_comp + (f := abs) continuous_abs.measurable.aestronglyMeasurable + change (∫ ω, |B (s+h) ω - B s ω| ∂P) = _ at he + rw [he] + have hh := gaussian_abs_pow 1 (nndist ((s+h:ℝ≥0):ℝ) (s:ℝ)) + simp only [pow_one] at hh + change (∫ x : ℝ, |x| ∂gaussianReal 0 (nndist ((s+h:ℝ≥0):ℝ) (s:ℝ))) = _ + rw [hh] + change Real.sqrt ((nndist ((s+h:ℝ≥0):ℝ) (s:ℝ):ℝ≥0):ℝ) * normalFirstMoment = _ + rw [coe_nndist, Real.dist_eq] + rw [NNReal.coe_add, add_sub_cancel_left, abs_of_nonneg h.coe_nonneg] + +lemma expected_control_step (hB : IsPreBrownianReal B P) + (hm : ∀ t, Measurable (B t)) (s h : ℝ≥0) {Y A : Ω → ℝ} + (hY : Measurable[Filtration.natural B (fun t => (hm t).stronglyMeasurable) s] Y) + (hYi : Integrable Y P) (hA : Measurable A) (M : ℝ≥0) + (hAb : ∀ ω, |A ω| ≤ (M:ℝ)*(h:ℝ)) {f : ℝ → ℝ} (hf : ContDiff ℝ 3 f) + (C₁ C₂ C₃ : ℝ≥0) (hC₁ : ∀ x, |deriv f x| ≤ C₁) + (hC₂ : ∀ x, |deriv (deriv f) x| ≤ C₂) + (hC₃ : ∀ x, |iteratedDeriv 3 f x| ≤ C₃) : + |(∫ ω, f (Y ω + (B (s+h) ω - B s ω) + A ω) ∂P) - + (∫ ω, f (Y ω) ∂P) - (∫ ω, deriv f (Y ω) * A ω ∂P) - + (h:ℝ)/2 * (∫ ω, deriv (deriv f) (Y ω) ∂P)| ≤ + (C₃:ℝ)/6 * ((h:ℝ)*Real.sqrt (h:ℝ)*normalThirdMoment) + + (C₂:ℝ)*(M:ℝ)*(h:ℝ) * (Real.sqrt (h:ℝ)*normalFirstMoment + (M:ℝ)*(h:ℝ)) := by + let := hB.isGaussianProcess.isProbabilityMeasure + have hYm := hY.mono + ((Filtration.natural B (fun t => (hm t).stronglyMeasurable)).le s) le_rfl + have hd : Integrable (fun ω => B (s+h) ω - B s ω) P := + (hB.integrable_eval _).sub (hB.integrable_eval _) + have hAi : Integrable A P := Integrable.of_bound hA.aestronglyMeasurable ((M:ℝ)*(h:ℝ)) + (Filter.Eventually.of_forall (fun ω => by simpa only [Real.norm_eq_abs] using hAb ω)) + have hf₁ : ContDiff ℝ 2 (deriv f) := hf.deriv' + have hiF : Integrable (fun ω => f (Y ω + (B (s+h) ω - B s ω))) P := by + simpa only [Pi.add_apply] using integrable_comp_of_bounded_deriv + (hf.differentiable (by norm_num)) C₁ hC₁ (hYi.add hd) + have hiFA : Integrable (fun ω => f (Y ω + (B (s+h) ω - B s ω) + A ω)) P := by + simpa only [Pi.add_apply] using integrable_comp_of_bounded_deriv + (hf.differentiable (by norm_num)) C₁ hC₁ ((hYi.add hd).add hAi) + have hiL : Integrable (fun ω => deriv f (Y ω)*A ω) P := hAi.bdd_mul + (hf₁.continuous.measurable.comp hYm).aestronglyMeasurable + (Filter.Eventually.of_forall (fun ω => by simpa only [Real.norm_eq_abs] using hC₁ (Y ω))) + let R (ω : Ω) := f (Y ω + (B (s+h) ω - B s ω) + A ω) - + f (Y ω + (B (s+h) ω - B s ω)) - deriv f (Y ω)*A ω + have hiD : Integrable (fun ω => f (Y ω + (B (s+h) ω - B s ω) + A ω) - + f (Y ω + (B (s+h) ω - B s ω))) P := hiFA.sub hiF + have hiR : Integrable R P := hiD.sub hiL + have hR : (∫ ω, R ω ∂P) = + (∫ ω, f (Y ω + (B (s+h) ω - B s ω) + A ω) ∂P) - + (∫ ω, f (Y ω + (B (s+h) ω - B s ω)) ∂P) - + (∫ ω, deriv f (Y ω)*A ω ∂P) := by + dsimp only [R] + rw [integral_sub hiD hiL, integral_sub hiFA hiF] + have hRb : |∫ ω, R ω ∂P| ≤ (C₂:ℝ)*(M:ℝ)*(h:ℝ) * + (Real.sqrt (h:ℝ)*normalFirstMoment + (M:ℝ)*(h:ℝ)) := by + calc + _ ≤ ∫ ω, |R ω| ∂P := abs_integral_le_integral_abs + _ ≤ ∫ ω, (C₂:ℝ)*(M:ℝ)*(h:ℝ) * (|B (s+h) ω - B s ω| + (M:ℝ)*(h:ℝ)) ∂P := by + apply integral_mono hiR.abs ((hd.abs.add (integrable_const _)).const_mul _) + intro ω + have hb := drift_perturbation_bound (hf.of_le (by norm_num)) C₂ hC₂ + (Y ω) (B (s+h) ω - B s ω) (A ω) + change |R ω| ≤ _ + apply hb.trans + have h₁ := mul_le_mul_of_nonneg_left (add_le_add_left (hAb ω) + |B (s+h) ω - B s ω|) C₂.coe_nonneg + have h₂ := mul_le_mul h₁ (hAb ω) (abs_nonneg (A ω)) + (mul_nonneg C₂.coe_nonneg (by positivity)) + convert h₂ using 1 <;> (try dsimp only [Pi.add_apply]) <;> ring + _ = _ := by + rw [integral_const_mul, integral_add hd.abs (integrable_const _), + increment_abs_first hB s h] + simp + rw [hR] at hRb + have hG := expected_brownian_step hB hm s h hY hYi hf C₁ C₂ C₃ hC₁ hC₂ hC₃ + have htri := abs_add_le + ((∫ ω, f (Y ω + (B (s+h) ω - B s ω)) ∂P) - (∫ ω, f (Y ω) ∂P) - + (h:ℝ)/2 * (∫ ω, deriv (deriv f) (Y ω) ∂P)) + ((∫ ω, f (Y ω + (B (s+h) ω - B s ω) + A ω) ∂P) - + (∫ ω, f (Y ω + (B (s+h) ω - B s ω)) ∂P) - + (∫ ω, deriv f (Y ω)*A ω ∂P)) + calc + _ = |((∫ ω, f (Y ω + (B (s+h) ω - B s ω)) ∂P) - (∫ ω, f (Y ω) ∂P) - + (h:ℝ)/2 * (∫ ω, deriv (deriv f) (Y ω) ∂P)) + + ((∫ ω, f (Y ω + (B (s+h) ω - B s ω) + A ω) ∂P) - + (∫ ω, f (Y ω + (B (s+h) ω - B s ω)) ∂P) - + (∫ ω, deriv f (Y ω)*A ω ∂P))| := by congr 1; ring + _ ≤ _ := htri.trans (add_le_add hG hRb) + +end ZeroTemperatureSK.WeakIto + +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKSupport/Moments/NormalThirdMoment.lean b/lean/OAI/Probability/SKSupport/Moments/NormalThirdMoment.lean new file mode 100644 index 0000000000000000000000000000000000000000..451bab791a18d35debaacbe146596dceb58b6e9e --- /dev/null +++ b/lean/OAI/Probability/SKSupport/Moments/NormalThirdMoment.lean @@ -0,0 +1,58 @@ +import Mathlib +import OAI.Probability.SKSupport.Model + +namespace OAI + +noncomputable section + +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +namespace ZeroTemperatureSK.WeakIto + +def normalThirdMoment : ℝ := ∫ x : ℝ, |x|^3 ∂gaussianReal 0 1 + +lemma gaussian_abs_pow_integrable (p : ℕ) (v : ℝ≥0) : + Integrable (fun x : ℝ => |x|^p) (gaussianReal 0 v) := by + simpa only [id_eq, Real.norm_eq_abs] using + (memLp_id_gaussianReal (μ := 0) (v := v) p).integrable_norm_pow' + +lemma normalThirdMoment_nonneg : 0 ≤ normalThirdMoment := + integral_nonneg (fun x => pow_nonneg (abs_nonneg x) 3) + +lemma gaussian_abs_pow (p : ℕ) (v : ℝ≥0) : + (∫ x : ℝ, |x|^p ∂gaussianReal 0 v) = + (Real.sqrt (v : ℝ))^p * ∫ x : ℝ, |x|^p ∂gaussianReal 0 1 := by + have hs : (gaussianReal 0 1).map (fun x : ℝ => Real.sqrt (v:ℝ)*x) = gaussianReal 0 v := by + rw [gaussianReal_map_const_mul] + congr 1 + · simp + · ext + simp [Real.sq_sqrt v.coe_nonneg] + rw [← hs, integral_map (by fun_prop) (by fun_prop)] + simp only [abs_mul, abs_of_nonneg (Real.sqrt_nonneg _), mul_pow] + exact integral_const_mul _ _ + +variable {Ω : Type*} [MeasurableSpace Ω] {P : Measure Ω} {B : ℝ≥0 → Ω → ℝ} + +lemma increment_abs_cube (hB : IsPreBrownianReal B P) (s h : ℝ≥0) : + (∫ ω, |B (s+h) ω - B s ω|^3 ∂P) = (h:ℝ)*Real.sqrt (h:ℝ)*normalThirdMoment := by + have he := (hB.hasLaw_sub (s+h) s).integral_comp + (f := fun x : ℝ => |x|^3) ((continuous_abs.pow 3).measurable.aestronglyMeasurable) + change (∫ ω, |B (s+h) ω - B s ω|^3 ∂P) = _ at he + rw [he, gaussian_abs_pow] + have hd : nndist ((s+h : ℝ≥0):ℝ) (s:ℝ) = h := by + ext + rw [coe_nndist, Real.dist_eq] + rw [NNReal.coe_add, add_sub_cancel_left, abs_of_nonneg h.coe_nonneg] + change Real.sqrt ((nndist ((s+h : ℝ≥0):ℝ) (s:ℝ) : ℝ≥0):ℝ)^3 * + normalThirdMoment = _ + rw [hd] + rw [pow_succ, Real.sq_sqrt h.coe_nonneg] + +end ZeroTemperatureSK.WeakIto + +end + +end OAI diff --git a/lean/OAI/Probability/SKSupport/Moments/PerturbationLimits.lean b/lean/OAI/Probability/SKSupport/Moments/PerturbationLimits.lean new file mode 100644 index 0000000000000000000000000000000000000000..1f0a370b2b99392ce3d9fb1d58983676208c4032 --- /dev/null +++ b/lean/OAI/Probability/SKSupport/Moments/PerturbationLimits.lean @@ -0,0 +1,172 @@ +import Mathlib +import OAI.Probability.SKSupport.Parabolic.GradientStability +import OAI.Probability.SKSupport.Diffusion.MixedPathStability +import OAI.Probability.SKSupport.Regularity.MixedIdentity + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section +namespace ZeroTemperatureSK +open Heat +variable {Ω : Type*} [MeasurableSpace Ω] + +def perturbationGradientErrors (W : BrownianSystem Ω) (γ β : OrderParameter) (T : Time) (n : ℕ) : Set ℝ := + Set.range (fun p : ℝ × ℝ => |compactGradient W (perturbation γ β n) T p.1 p.2-compactGradient W γ T p.1 p.2|) + +def perturbationGradientError (W : BrownianSystem Ω) (γ β : OrderParameter) (T : Time) (n : ℕ) : ℝ := + sSup (perturbationGradientErrors W γ β T n) + +lemma perturbationGradientErrors_bddAbove (W : BrownianSystem Ω) (γ β : OrderParameter) (T : Time) (n : ℕ) : + BddAbove (perturbationGradientErrors W γ β T n) := by + refine ⟨2,?_⟩ + rintro z ⟨p,rfl⟩ + have hb := compactGradient_bound W (perturbation γ β n) T.property.1 T.property.2 p.1 p.2 + have hg := compactGradient_bound W γ T.property.1 T.property.2 p.1 p.2 + exact (abs_sub _ _).trans (by linarith) + +lemma perturbationGradientError_nonneg (W : BrownianSystem Ω) (γ β : OrderParameter) (T : Time) (n : ℕ) : + 0 ≤ perturbationGradientError W γ β T n := + (abs_nonneg _).trans (le_csSup (perturbationGradientErrors_bddAbove W γ β T n) ⟨((0:ℝ),(0:ℝ)),rfl⟩) + +lemma perturbationGradientError_bound (W : BrownianSystem Ω) (γ β : OrderParameter) (T : Time) (n : ℕ) (t x : ℝ) : + |compactGradient W (perturbation γ β n) T t x-compactGradient W γ T t x| ≤ perturbationGradientError W γ β T n := + le_csSup (perturbationGradientErrors_bddAbove W γ β T n) ⟨(t,x),rfl⟩ + +lemma perturbationGradientError_limit (W : BrownianSystem Ω) (γ β : OrderParameter) (T : Time) : + Tendsto (perturbationGradientError W γ β T) atTop (𝓝 0) := by + obtain ⟨L,hL⟩ := compactGradient_stability W γ T + rw [Metric.tendsto_nhds] + intro ε hε + let h : ℝ := ε/(4*((L:ℝ)+1)) + have hh : 0 < h := by dsimp [h];positivity + have hLe : (L:ℝ)*h < ε/2 := by + have hl : 0 < (L:ℝ)+1 := by positivity + have he : (4*((L:ℝ)+1))*h=ε := by dsimp [h];field_simp + nlinarith [L.coe_nonneg] + have hlim : Tendsto (fun n => 3*coefficientDistance (perturbation γ β n) γ/h) atTop (𝓝 0) := by + simpa only [mul_zero,zero_div] using (tendsto_const_nhds.mul (perturbation_distance_limit γ β) (a := (3:ℝ))).div_const h + filter_upwards [hlim.eventually (gt_mem_nhds (by linarith : (0:ℝ)<ε/2))] with n hn + have hb : perturbationGradientError W γ β T n ≤ 3*coefficientDistance (perturbation γ β n) γ/h+(L:ℝ)*h := by + apply csSup_le (Set.range_nonempty _) + rintro z ⟨p,rfl⟩ + exact hL (perturbation γ β n) h hh p.1 p.2 + rw [Real.dist_eq,sub_zero,abs_of_nonneg (perturbationGradientError_nonneg W γ β T n)] + linarith + +def perturbationPathError (W : BrownianSystem Ω) (γ β : OrderParameter) (T : Time) (n : ℕ) : ℝ := + 2*(coefficientDistance (perturbation γ β n) γ+γ.val T*(T:ℝ)*perturbationGradientError W γ β T n)* + Real.exp ((stripDrift W γ T).rate*T) + +lemma perturbationPathError_limit (W : BrownianSystem Ω) (γ β : OrderParameter) (T : Time) : + Tendsto (perturbationPathError W γ β T) atTop (𝓝 0) := by + unfold perturbationPathError + have hh := (perturbation_distance_limit γ β).add + (tendsto_const_nhds.mul (perturbationGradientError_limit W γ β T) (a := γ.val T*(T:ℝ))) + simpa only [mul_zero,zero_add,zero_mul] using + (tendsto_const_nhds.mul hh (a := (2:ℝ))).mul_const (Real.exp ((stripDrift W γ T).rate*T)) + +lemma perturbationPathError_bound (W : BrownianSystem Ω) (γ β : OrderParameter) (T : Time) (n : ℕ) + (t : ℝ≥0) (ht : (t:ℝ) ≤ T) (ξ : Ω) : + |(mixedStripDrift W (perturbation γ β n) γ T).solution W.driver t ξ-diffusion W γ t ξ| ≤ + perturbationPathError W γ β T n := + mixedPath_error W (perturbation γ β n) γ T (perturbationGradientError_nonneg W γ β T n) + (perturbationGradientError_bound W γ β T n) t ht ξ + +lemma perturbationPath_limit (W : BrownianSystem Ω) (γ β : OrderParameter) (T : Time) + (t : ℝ≥0) (ht : (t:ℝ) ≤ T) (ξ : Ω) : + Tendsto (fun n => (mixedStripDrift W (perturbation γ β n) γ T).solution W.driver t ξ) + atTop (𝓝 (diffusion W γ t ξ)) := by + rw [Metric.tendsto_nhds] + intro ε hε + filter_upwards [(perturbationPathError_limit W γ β T).eventually (gt_mem_nhds hε)] with n hn + exact (perturbationPathError_bound W γ β T n t ht ξ).trans_lt hn + +lemma mixedQ_perturbation_limit (W : BrownianSystem Ω) (γ β : OrderParameter) (T : Time) + {t : ℝ} (ht : t ∈ Icc (0:ℝ) T) : + Tendsto (fun n => mixedQ W (perturbation γ β n) γ T t) atTop + (𝓝 (squareMoment W γ (diffusion W γ) t)) := by + let := W.isProbability + let f (n : ℕ) (ξ : Ω) := (compactGradient W γ T t + ((mixedStripDrift W (perturbation γ β n) γ T).solution W.driver (Real.toNNReal t) ξ))^2 + have hc : Continuous (compactGradient W γ T t) := + (compactGradient_continuous W γ T.property.1 T.property.2).comp (continuous_const.prodMk continuous_id) + have hm (n : ℕ) : AEStronglyMeasurable (f n) W.law := + ((hc.measurable.comp ((mixedStripDrift W (perturbation γ β n) γ T).solution_measurable W (Real.toNNReal t))).pow_const 2).aestronglyMeasurable + have hb (n : ℕ) : ∀ᵐ ξ ∂W.law, ‖f n ξ‖ ≤ 1 := by + filter_upwards [] with ξ + have hh := compactGradient_bound W γ T.property.1 T.property.2 t + ((mixedStripDrift W (perturbation γ β n) γ T).solution W.driver (Real.toNNReal t) ξ) + rw [abs_le] at hh + dsimp only [f] + rw [Real.norm_eq_abs,abs_of_nonneg (sq_nonneg _)] + nlinarith + have hl : ∀ᵐ ξ ∂W.law, Tendsto (fun n => f n ξ) atTop + (𝓝 ((gradient W γ t (diffusion W γ (Real.toNNReal t) ξ))^2)) := by + filter_upwards [] with ξ + have hh := (hc.tendsto _).comp (perturbationPath_limit W γ β T (Real.toNNReal t) + (by rw [Real.coe_toNNReal _ ht.1];exact ht.2) ξ) + simpa only [Function.comp_apply,f,compactGradient,stripClamp_eq ht] using hh.pow 2 + exact tendsto_integral_of_dominated_convergence (fun _ => (1:ℝ)) hm (integrable_const _) hb hl + +end ZeroTemperatureSK + +end +end +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section +namespace ZeroTemperatureSK +variable {Ω : Type*} [MeasurableSpace Ω] + +lemma squareMoment_bounds (W : BrownianSystem Ω) (γ : OrderParameter) {t : ℝ} (ht : t ≤ 1) : + 0 ≤ squareMoment W γ (diffusion W γ) t ∧ |squareMoment W γ (diffusion W γ) t| ≤ 1 := by + let := W.isProbability + refine ⟨integral_nonneg (fun ξ => sq_nonneg _),?_⟩ + have hb : ∀ᵐ ξ ∂W.law, ‖(gradient W γ t (diffusion W γ (Real.toNNReal t) ξ))^2‖ ≤ 1 := by + filter_upwards [] with ξ + have hh := abs_le.mp (gradient_abs_le_one W γ t (diffusion W γ (Real.toNNReal t) ξ) ht) + rw [Real.norm_eq_abs,abs_of_nonneg (sq_nonneg _)] + nlinarith + have hh := norm_integral_le_of_norm_le_const hb + simpa [squareMoment,Real.norm_eq_abs] using hh + +lemma squareMoment_continuousOn (W : BrownianSystem Ω) (γ : OrderParameter) : + ContinuousOn (squareMoment W γ (diffusion W γ)) (Ico (0:ℝ) 1) := by + intro t ht + exact (squareMoment_hasDerivWithinAt W γ ht.1 ht.2).continuousWithinAt.mono Ico_subset_Ici_self + +lemma curvatureMoment_continuousOn_unit (W : BrownianSystem Ω) (γ : OrderParameter) : + ContinuousOn (curvatureMoment W γ) (Ico (0:ℝ) 1) := by + intro t ht + let T : ℝ := (t+1)/2 + have hT0 : 0 ≤ T := by dsimp [T];linarith [ht.1,ht.2] + have hT1 : T < 1 := by dsimp [T];linarith [ht.1,ht.2] + have htt : t < T := by dsimp [T];linarith [ht.1,ht.2] + have hc := curvatureMoment_continuousOn W γ hT0 hT1 t ⟨ht.1,htt.le⟩ + apply hc.mono_of_mem_nhdsWithin + filter_upwards [self_mem_nhdsWithin,mem_nhdsWithin_of_mem_nhds (gt_mem_nhds htt)] with s hs hsT + exact ⟨hs.1,hsT.le⟩ + +lemma squareMoment_hasDerivAt (W : BrownianSystem Ω) (γ : OrderParameter) {t : ℝ} + (ht0 : 0 < t) (ht1 : t < 1) : + HasDerivAt (squareMoment W γ (diffusion W γ)) (curvatureMoment W γ t) t := + (squareMoment_hasDerivWithinAt W γ ht0.le ht1).hasDerivAt (Ici_mem_nhds ht0) + +lemma squareMoment_weighted_integrable (W : BrownianSystem Ω) (γ : OrderParameter) {η : ℝ → ℝ} + (hη : Integrable η) : IntervalIntegrable (fun t => η t*squareMoment W γ (diffusion W γ) t) volume 0 1 := by + rw [intervalIntegrable_iff_integrableOn_Ico_of_le (by norm_num : (0:ℝ) ≤ 1)] + apply hη.integrableOn.mul_bdd + · exact (squareMoment_continuousOn W γ).aestronglyMeasurable measurableSet_Ico + · filter_upwards [ae_restrict_mem measurableSet_Ico] with t ht + exact (squareMoment_bounds W γ ht.2.le).2 + +end ZeroTemperatureSK + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKSupport/Moments/PositiveGradientError.lean b/lean/OAI/Probability/SKSupport/Moments/PositiveGradientError.lean new file mode 100644 index 0000000000000000000000000000000000000000..47b6d3f80f3541602ca1e0fd394bd26a3d426940 --- /dev/null +++ b/lean/OAI/Probability/SKSupport/Moments/PositiveGradientError.lean @@ -0,0 +1,76 @@ +import Mathlib +import OAI.Probability.SKSupport.Diffusion.DiffusionStability + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology ContDiff +noncomputable section +namespace ZeroTemperatureSK +open Heat +variable {Ω : Type*} [MeasurableSpace Ω] + +def positiveGradientErrors (W : BrownianSystem Ω) (γ : OrderParameter) (T : Time) (n : ℕ) : Set ℝ := + Set.range (fun p : ℝ × ℝ => |deriv (positiveValue γ n (stripClamp T p.1)) p.2-compactGradient W γ T p.1 p.2|) + +def positiveGradientError (W : BrownianSystem Ω) (γ : OrderParameter) (T : Time) (n : ℕ) : ℝ := + sSup (positiveGradientErrors W γ T n) + +lemma positiveGradientErrors_bddAbove (W : BrownianSystem Ω) (γ : OrderParameter) (T : Time) (n : ℕ) : + BddAbove (positiveGradientErrors W γ T n) := by + obtain ⟨C,hC,hb⟩ := positiveValue_uniform_derivative_bounds γ T.property.1 T.property.2 0 + refine ⟨C+1,?_⟩ + rintro z ⟨p,rfl⟩ + have hh := hb n (stripClamp T p.1) (stripClamp_mem T.property.1 p.1) p.2 + simp only [Nat.zero_add,iteratedDeriv_one] at hh + exact (abs_sub _ _).trans (add_le_add hh (compactGradient_bound W γ T.property.1 T.property.2 p.1 p.2)) + +lemma positiveGradientError_nonneg (W : BrownianSystem Ω) (γ : OrderParameter) (T : Time) (n : ℕ) : + 0 ≤ positiveGradientError W γ T n := by + exact (abs_nonneg _).trans (le_csSup (positiveGradientErrors_bddAbove W γ T n) ⟨((0:ℝ),(0:ℝ)),rfl⟩) + +lemma positiveGradientError_bound (W : BrownianSystem Ω) (γ : OrderParameter) (T : Time) (n : ℕ) + {s : ℝ} (hs : s ∈ Icc (0:ℝ) T) (x : ℝ) : + |deriv (positiveValue γ n s) x-gradient W γ s x| ≤ positiveGradientError W γ T n := by + have hh := le_csSup (positiveGradientErrors_bddAbove W γ T n) + (show |deriv (positiveValue γ n (stripClamp T s)) x-compactGradient W γ T s x| ∈ + positiveGradientErrors W γ T n from ⟨(s,x),rfl⟩) + simpa only [compactGradient,stripClamp_eq hs,positiveGradientError] using hh + +lemma positiveGradientError_limit (W : BrownianSystem Ω) (γ : OrderParameter) (T : Time) : + Tendsto (positiveGradientError W γ T) atTop (𝓝 0) := by + rw [Metric.tendsto_nhds] + intro ε hε + have hu := positiveValue_derivative_uniform W γ T.property.1 T.property.2 1 + rw [Metric.tendstoUniformlyOn_iff] at hu + filter_upwards [hu (ε/2) (by linarith)] with n hn + have he : positiveGradientError W γ T n ≤ ε/2 := by + apply csSup_le (Set.range_nonempty _) + rintro z ⟨p,rfl⟩ + have hh := hn (stripClamp T p.1,p.2) ⟨stripClamp_mem T.property.1 p.1,mem_univ _⟩ + simpa only [iteratedDeriv_one,Real.dist_eq,compactGradient,gradient,abs_sub_comm] using hh.le + rw [Real.dist_eq,sub_zero,abs_of_nonneg (positiveGradientError_nonneg W γ T n)] + linarith + +lemma positivePath_uniform_error (W : BrownianSystem Ω) (γ : OrderParameter) (T : Time) : + ∀ ε > 0, ∀ᶠ n in atTop, ∀ t : ℝ≥0, (t:ℝ) ≤ T → ∀ ξ, + |positivePath W γ n t ξ-diffusion W γ t ξ| < ε := by + let E (n : ℕ) := 2*(positiveCoeffError γ n+γ.val T*(T:ℝ)*positiveGradientError W γ T n)* + Real.exp ((stripDrift W γ T).rate*T) + have hE : Tendsto E atTop (𝓝 0) := by + have hh := (positiveCoeffError_limit γ).add + (tendsto_const_nhds.mul (positiveGradientError_limit W γ T) (a := γ.val T*(T:ℝ))) + simpa only [E,mul_zero,zero_add,zero_mul] using + (tendsto_const_nhds.mul hh (a := (2:ℝ))).mul_const (Real.exp ((stripDrift W γ T).rate*T)) + intro ε hε + filter_upwards [hE.eventually (gt_mem_nhds hε)] with n hn t ht ξ + exact (positivePath_error W γ T n (positiveGradientError_nonneg W γ T n) + (fun s hs x => positiveGradientError_bound W γ T n hs x) t ht ξ).trans_lt hn + +end ZeroTemperatureSK + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKSupport/Moments/SquareEquation.lean b/lean/OAI/Probability/SKSupport/Moments/SquareEquation.lean new file mode 100644 index 0000000000000000000000000000000000000000..faa2fcfbed86227632bcf13e4483a58df5b8591a --- /dev/null +++ b/lean/OAI/Probability/SKSupport/Moments/SquareEquation.lean @@ -0,0 +1,183 @@ +import Mathlib +import OAI.Probability.SKSupport.Diffusion.BoundedDiffusionProperties +import OAI.Probability.SKSupport.Regularity.RightRegularity + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section +namespace ZeroTemperatureSK +open Heat WeakIto +variable {Ω : Type*} [MeasurableSpace Ω] + +lemma compactValueRate_eq (W : BrownianSystem Ω) (γ : OrderParameter) (T t x : ℝ) : + compactValueRate W γ T t x = -(1/2:ℝ)*deriv (compactGradient W γ T t) x- + (1/2:ℝ)*compactCoeff γ T t*(compactGradient W γ T t x)^2 := rfl + +lemma compactGradient_hasDerivWithinAt_right (W : BrownianSystem Ω) (γ : OrderParameter) + {T t : ℝ} (hT0 : 0 ≤ T) (hT1 : T < 1) (ht0 : 0 ≤ t) (htT : t < T) (x : ℝ) : + HasDerivWithinAt (fun s => compactGradient W γ T s x) + (deriv (compactValueRate W γ T t) x) (Ioi t) t := by + have hh := value_derivative_hasDerivWithinAt_right W γ hT0 hT1 ht0 htT 1 x + simp only [iteratedDeriv_one] at hh + apply hh.congr_of_eventuallyEq + · filter_upwards [self_mem_nhdsWithin,mem_nhdsWithin_of_mem_nhds (gt_mem_nhds htT)] with s hs hsT + simp only [compactGradient,stripClamp_eq ⟨ht0.trans hs.le,hsT.le⟩,gradient] + · simp only [compactGradient,stripClamp_eq ⟨ht0,htT.le⟩,gradient] + +lemma deriv_compactValueRate (W : BrownianSystem Ω) (γ : OrderParameter) + {T : ℝ} (hT0 : 0 ≤ T) (hT1 : T < 1) (t x : ℝ) : + deriv (compactValueRate W γ T t) x = + -(1/2:ℝ)*deriv (deriv (compactGradient W γ T t)) x- + compactCoeff γ T t*compactGradient W γ T t x*deriv (compactGradient W γ T t) x := by + have hu := compactGradient_family W γ hT0 hT1 + have hd := ((hu.regular t).smooth.differentiable (by simp) x).hasDerivAt + have hdd := ((hu.deriv.regular t).smooth.differentiable (by simp) x).hasDerivAt + have hh := (hdd.const_mul (-(1/2:ℝ))).sub ((hd.pow 2).const_mul ((1/2:ℝ)*compactCoeff γ T t)) + have he : (compactValueRate W γ T t) = (fun x => + -(1/2:ℝ)*deriv (compactGradient W γ T t) x-(1/2:ℝ)*compactCoeff γ T t*(compactGradient W γ T t x)^2) := + funext (compactValueRate_eq W γ T t) + rw [he] + calc + _ = _ := hh.deriv + _ = _ := by ring + +def compactSquare (W : BrownianSystem Ω) (γ : OrderParameter) (T t x : ℝ) : ℝ := + compactGradient W γ T t x*compactGradient W γ T t x + +def compactSquareRate (W : BrownianSystem Ω) (γ : OrderParameter) (T t x : ℝ) : ℝ := + 2*compactGradient W γ T t x*deriv (compactValueRate W γ T t) x + +lemma compactSquare_family (W : BrownianSystem Ω) (γ : OrderParameter) + {T : ℝ} (hT0 : 0 ≤ T) (hT1 : T < 1) : BoundedSmoothFamily (compactSquare W γ T) := + (compactGradient_family W γ hT0 hT1).mul (compactGradient_family W γ hT0 hT1) + +lemma compactSquareRate_family (W : BrownianSystem Ω) (γ : OrderParameter) + {T : ℝ} (hT0 : 0 ≤ T) (hT1 : T < 1) : BoundedSmoothFamily (compactSquareRate W γ T) := + ((compactGradient_family W γ hT0 hT1).const_mul 2).mul + (compactValueRate_family W γ hT0 hT1).deriv + +lemma compactSquareRate_right (W : BrownianSystem Ω) (γ : OrderParameter) + {T : ℝ} (hT0 : 0 ≤ T) (hT1 : T < 1) (t x : ℝ) : + ContinuousWithinAt (fun s => compactSquareRate W γ T s x) (Ioi t) t := by + have hu := compactGradient_rightSmooth W γ hT0 hT1 0 t x + have hD := compactValueRate_rightSmooth W γ hT0 hT1 1 t x + simp only [iteratedDeriv_zero,iteratedDeriv_one] at hu hD + exact ((continuousWithinAt_const.mul hu).mul hD).mono Ioi_subset_Ici_self + +lemma compactSquare_integral_rate (W : BrownianSystem Ω) (γ : OrderParameter) + {T a b : ℝ} (hT0 : 0 ≤ T) (hT1 : T < 1) (ha : 0 ≤ a) (hab : a ≤ b) (hb : b ≤ T) (x : ℝ) : + compactSquare W γ T b x-compactSquare W γ T a x = + ∫ r in a..b, compactSquareRate W γ T r x := by + apply (intervalIntegral.integral_eq_sub_of_hasDeriv_right_of_le hab _ _ + ((compactSquareRate_family W γ hT0 hT1).intervalIntegrable x a b)).symm + · have hc : Continuous (fun t => compactGradient W γ T t x) := + (compactGradient_continuous W γ hT0 hT1).comp + (continuous_id.prodMk continuous_const) + exact (hc.mul hc).continuousOn + · intro t ht + have hd := compactGradient_hasDerivWithinAt_right W γ hT0 hT1 (ha.trans ht.1.le) (ht.2.trans_le hb) x + convert hd.mul hd using 1 <;> (try rfl) + dsimp only [compactSquareRate] + ring + +lemma compactSquare_generator (W : BrownianSystem Ω) (γ : OrderParameter) + {T : ℝ} (hT0 : 0 ≤ T) (hT1 : T < 1) (t x : ℝ) : + deriv (compactSquare W γ T t) x*compactDrift W γ T t x+ + (1/2:ℝ)*deriv (deriv (compactSquare W γ T t)) x+compactSquareRate W γ T t x = + (deriv (compactGradient W γ T t) x)^2 := by + have hu := compactGradient_family W γ hT0 hT1 + have hd (x : ℝ) := ((hu.regular t).smooth.differentiable (by simp) x).hasDerivAt + have hdd (x : ℝ) := ((hu.deriv.regular t).smooth.differentiable (by simp) x).hasDerivAt + have he (x : ℝ) : deriv (compactSquare W γ T t) x = + deriv (compactGradient W γ T t) x*compactGradient W γ T t x+ + compactGradient W γ T t x*deriv (compactGradient W γ T t) x := (hd x |>.mul (hd x)).deriv + have he2 : deriv (compactSquare W γ T t) = fun x => + deriv (compactGradient W γ T t) x*compactGradient W γ T t x+ + compactGradient W γ T t x*deriv (compactGradient W γ T t) x := funext he + have hh := ((hdd x |>.mul (hd x)).add ((hd x).mul (hdd x))).deriv + change deriv (fun y => deriv (compactGradient W γ T t) y*compactGradient W γ T t y+ + compactGradient W γ T t y*deriv (compactGradient W γ T t) y) x = _ at hh + rw [he,he2,hh] + unfold compactDrift compactSquareRate + rw [deriv_compactValueRate W γ hT0 hT1] + ring + +end ZeroTemperatureSK + +end +end +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section +namespace ZeroTemperatureSK +open Heat WeakIto +variable {Ω : Type*} [MeasurableSpace Ω] + +lemma compactGradient_derivative_continuous (W : BrownianSystem Ω) (γ : OrderParameter) + {T : ℝ} (hT0 : 0 ≤ T) (hT1 : T < 1) (n : ℕ) : + Continuous (fun p : ℝ × ℝ => iteratedDeriv n (compactGradient W γ T p.1) p.2) := by + change Continuous (fun p : ℝ × ℝ => iteratedDeriv n (deriv (value W γ (stripClamp T p.1))) p.2) + simp only [← iteratedDeriv_succ'] + have hc := value_derivative_continuousOn W γ hT0 hT1 (n+1) + have hg : ContinuousOn (fun p : ℝ × ℝ => (stripClamp T p.1,p.2)) univ := + (((continuous_stripClamp T).comp continuous_fst).prodMk continuous_snd).continuousOn + have hm : MapsTo (fun p : ℝ × ℝ => (stripClamp T p.1,p.2)) univ + (Icc (0:ℝ) T ×ˢ (univ : Set ℝ)) := fun p _ => ⟨stripClamp_mem hT0 p.1,mem_univ _⟩ + exact continuousOn_univ.mp (ContinuousOn.comp + (f := fun p : ℝ × ℝ => (stripClamp T p.1,p.2)) + (g := fun p : ℝ × ℝ => iteratedDeriv (n+1) (value W γ p.1) p.2) hc hg hm) + +lemma BoundedLipschitzDrift.expected_continuous (b : BoundedLipschitzDrift) + (W : BrownianSystem Ω) {F : ℝ → ℝ → ℝ} (hF : BoundedSmoothFamily F) + (hc : Continuous (fun p : ℝ × ℝ => F p.1 p.2)) : + Continuous (fun r : ℝ => ∫ ω, F r (b.solution W.driver (Real.toNNReal r) ω) ∂W.law) := by + let := W.isProbability + obtain ⟨C,hC⟩ := hF.bound + apply continuous_of_dominated (bound := fun _ => (C:ℝ)) + · intro r + exact ((hF.regular r).smooth.continuous.measurable.comp + (b.solution_measurable W (Real.toNNReal r))).aestronglyMeasurable + · intro r + exact Eventually.of_forall (fun ω => by simpa only [Real.norm_eq_abs] using hC r (b.solution W.driver (Real.toNNReal r) ω)) + · exact integrable_const _ + · filter_upwards [b.solution_continuous_ae W] with ω hω + exact hc.comp (continuous_id.prodMk (hω.comp (by fun_prop : Continuous Real.toNNReal))) + +lemma stripDrift_pathDrift_right (W : BrownianSystem Ω) (γ : OrderParameter) + (T : Time) (s : ℝ≥0) : + ∀ᵐ ω ∂W.law, ContinuousWithinAt (fun r => (stripDrift W γ T).pathDrift W r ω) (Ioi (s:ℝ)) s := by + filter_upwards [(stripDrift W γ T).solution_continuous_ae W] with ω hω + have hx : Continuous (fun r : ℝ => (stripDrift W γ T).solution W.driver (Real.toNNReal r) ω) := + hω.comp (by fun_prop : Continuous Real.toNNReal) + have hu : Continuous (fun r : ℝ => compactGradient W γ T r + ((stripDrift W γ T).solution W.driver (Real.toNNReal r) ω)) := + (compactGradient_continuous W γ T.property.1 T.property.2).comp (continuous_id.prodMk hx) + have hh := ((compactCoeff_rightContinuous γ T.property.1 T.property.2 (s:ℝ)).mono Ioi_subset_Ici_self).mul hu.continuousWithinAt + apply hh.congr_of_eventuallyEq + · filter_upwards [self_mem_nhdsWithin] with r hr + simp only [BoundedLipschitzDrift.pathDrift,stripDrift,compactDrift, + Real.coe_toNNReal _ (s.coe_nonneg.trans hr.le),Pi.mul_apply] + · simp only [BoundedLipschitzDrift.pathDrift,stripDrift,compactDrift,Real.toNNReal_coe,Pi.mul_apply] + +lemma compactSquare_continuous (W : BrownianSystem Ω) (γ : OrderParameter) + {T : ℝ} (hT0 : 0 ≤ T) (hT1 : T < 1) : + Continuous (fun p : ℝ × ℝ => compactSquare W γ T p.1 p.2) := + (compactGradient_continuous W γ hT0 hT1).mul (compactGradient_continuous W γ hT0 hT1) + +lemma compactCurvatureSquare_continuous (W : BrownianSystem Ω) (γ : OrderParameter) + {T : ℝ} (hT0 : 0 ≤ T) (hT1 : T < 1) : + Continuous (fun p : ℝ × ℝ => (deriv (compactGradient W γ T p.1) p.2)^2) := by + have hh := compactGradient_derivative_continuous W γ hT0 hT1 1 + simp only [iteratedDeriv_one] at hh + exact hh.pow 2 + +end ZeroTemperatureSK + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKSupport/Moments/StrictMoments.lean b/lean/OAI/Probability/SKSupport/Moments/StrictMoments.lean new file mode 100644 index 0000000000000000000000000000000000000000..d8323fd347ca0984a176a6b6d1198bf7389a9cb7 --- /dev/null +++ b/lean/OAI/Probability/SKSupport/Moments/StrictMoments.lean @@ -0,0 +1,108 @@ +import Mathlib +import OAI.Probability.SKSupport.Diffusion.Diffusion + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology ContDiff +noncomputable section +namespace ZeroTemperatureSK +open Heat WeakIto +variable {Ω : Type*} [MeasurableSpace Ω] + +lemma integral_pos_of_interval_support {P : Measure Ω} {X : Ω → ℝ} {f : ℝ → ℝ} + (hX : ∀ a b : ℝ, a < b → 0 < P {ξ | X ξ ∈ Ioo a b}) + (hf : Continuous f) (hn : ∀ x, 0 ≤ f x) (hi : Integrable (fun ξ => f (X ξ)) P) + (hne : ∃ x, f x ≠ 0) : 0 < ∫ ξ, f (X ξ) ∂P := by + obtain ⟨x,hx⟩ := hne + have he : ∀ᶠ y in 𝓝 x, f y ≠ 0 := hf.continuousAt.preimage_mem_nhds (isOpen_compl_singleton.mem_nhds hx) + obtain ⟨ε,hε,hball⟩ := Metric.eventually_nhds_iff.mp he + apply (integral_pos_iff_support_of_nonneg (fun ξ => hn (X ξ)) hi).mpr + apply (hX (x-ε) (x+ε) (by linarith)).trans_le + apply measure_mono + intro ξ hξ + change f (X ξ) ≠ 0 + apply hball + rw [Real.dist_eq,abs_lt] + change x-ε < X ξ ∧ X ξ < x+ε at hξ + constructor <;> linarith [hξ.1,hξ.2] + +lemma curvature_not_identically_zero (W : BrownianSystem Ω) (γ : OrderParameter) + {t : ℝ} (ht0 : 0 ≤ t) (ht1 : t < 1) : ∃ x, curvature W γ t x ≠ 0 := by + by_contra hh + push Not at hh + have hV := value_contDiff W γ ht0 ht1 + have hG := (contDiff_infty_iff_deriv.mp hV).2 + have hg (x : ℝ) : gradient W γ t x=0 := by + have hc := is_const_of_deriv_eq_zero (hG.differentiable (by simp)) hh x 0 + exact hc.trans (gradient_zero W γ ht0 ht1) + have hv (x : ℝ) := is_const_of_deriv_eq_zero (hV.differentiable (by simp)) hg x 0 + have h := abs_le_value W γ t (value W γ t 0+1) ht1.le + rw [hv (value W γ t 0+1)] at h + have := le_abs_self (value W γ t 0+1) + linarith + +lemma third_not_identically_zero (W : BrownianSystem Ω) (γ : OrderParameter) + {t : ℝ} (ht0 : 0 ≤ t) (ht1 : t < 1) : ∃ x, deriv (curvature W γ t) x ≠ 0 := by + by_contra hh + push Not at hh + have hV := value_contDiff W γ ht0 ht1 + have hG := (contDiff_infty_iff_deriv.mp hV).2 + have hC := (contDiff_infty_iff_deriv.mp hG).2 + have hc (x : ℝ) : curvature W γ t x=curvature W γ t 0 := + is_const_of_deriv_eq_zero (hC.differentiable (by simp)) hh x 0 + let c := curvature W γ t 0 + have ha (x : ℝ) : HasDerivAt (fun y => gradient W γ t y-c*y) 0 x := by + have hd := (hG.differentiable (by simp) x).hasDerivAt + change HasDerivAt (gradient W γ t) (curvature W γ t x) x at hd + have hdc := hd.sub ((hasDerivAt_id x).const_mul c) + have hz : curvature W γ t x-c=0 := by rw [hc];dsimp only [c];ring + rw [mul_one,hz] at hdc + exact hdc + have he (x : ℝ) : gradient W γ t x=c*x := by + have h := is_const_of_deriv_eq_zero (fun y => (ha y).differentiableAt) (fun y => (ha y).deriv) x 0 + rw [gradient_zero W γ ht0 ht1,mul_zero,sub_zero] at h + linarith + have hz : c=0 := by + by_contra hc0 + have hb := gradient_abs_le_one W γ t (2/c) ht1.le + rw [he,mul_div_cancel₀ _ hc0] at hb + norm_num at hb + obtain ⟨x,hx⟩ := curvature_not_identically_zero W γ ht0 ht1 + exact hx ((hc x).trans hz) + +lemma actual_jet_even_moment_pos (W : BrownianSystem Ω) (γ : OrderParameter) (t : Time) + (ht0 : 0 < (t:ℝ)) (n k : ℕ) (hk : 0 < k) + (hne : ∃ x, iteratedDeriv (n+1) (value W γ t) x ≠ 0) : + 0 < ∫ ξ, (iteratedDeriv (n+1) (value W γ t) + (diffusion W γ (⟨t,t.property.1⟩:ℝ≥0) ξ))^(2*k) ∂W.law := by + let := W.isProbability + have hs := contDiff_iteratedDeriv_infty (value_contDiff W γ t.property.1 t.property.2) (n+1) + have hm : Measurable (diffusion W γ (⟨t,t.property.1⟩:ℝ≥0)) := by + let ℱ := Filtration.natural W.B (fun s => (W.measurable s).stronglyMeasurable) + have ha : Measurable[ℱ (⟨t,t.property.1⟩:ℝ≥0)] (diffusion W γ (⟨t,t.property.1⟩:ℝ≥0)) := + (diffusion_progressive W γ).adapted (⟨t,t.property.1⟩:ℝ≥0) + exact ha.mono (ℱ.le _) le_rfl + obtain ⟨C,hC,hbound⟩ := value_uniform_derivative_bounds W γ t.property.1 t.property.2 n + have hi : Integrable (fun ξ => (iteratedDeriv (n+1) (value W γ t) + (diffusion W γ (⟨t,t.property.1⟩:ℝ≥0) ξ))^(2*k)) W.law := by + apply Integrable.mono' (integrable_const (μ := W.law) (C^(2*k))) + · exact ((hs.continuous.measurable.comp hm).pow_const _).aestronglyMeasurable + · filter_upwards [] with ξ + rw [Real.norm_eq_abs,abs_pow] + exact pow_le_pow_left₀ (abs_nonneg _) (hbound t ⟨t.property.1,le_rfl⟩ _) _ + apply integral_pos_of_interval_support + (P := W.law) (X := diffusion W γ (⟨t,t.property.1⟩:ℝ≥0)) + (f := fun x => (iteratedDeriv (n+1) (value W γ t) x)^(2*k)) + (fun a b hab => diffusion_interval_pos W γ t ht0 hab) + (hs.continuous.pow _) (fun x => by rw [pow_mul];exact pow_nonneg (pow_two_nonneg _) k) hi + obtain ⟨x,hx⟩ := hne + exact ⟨x,(pow_ne_zero_iff (Nat.ne_of_gt (Nat.mul_pos (by decide) hk))).mpr hx⟩ + +end ZeroTemperatureSK + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKSupport/Moments/StripSquareMoment.lean b/lean/OAI/Probability/SKSupport/Moments/StripSquareMoment.lean new file mode 100644 index 0000000000000000000000000000000000000000..c8876c744fbaaeb08b07e823a9fd6b8f2a83f7f4 --- /dev/null +++ b/lean/OAI/Probability/SKSupport/Moments/StripSquareMoment.lean @@ -0,0 +1,174 @@ +import Mathlib +import OAI.Probability.SKSupport.Foundations.RightGenerator +import OAI.Probability.SKSupport.Moments.SquareEquation + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section +namespace ZeroTemperatureSK +open Heat WeakIto +variable {Ω : Type*} [MeasurableSpace Ω] + +def stripQ (W : BrownianSystem Ω) (γ : OrderParameter) (T : Time) (t : ℝ) : ℝ := + ∫ ω, compactSquare W γ T t ((stripDrift W γ T).solution W.driver (Real.toNNReal t) ω) ∂W.law + +def stripA (W : BrownianSystem Ω) (γ : OrderParameter) (T : Time) (t : ℝ) : ℝ := + ∫ ω, (deriv (compactGradient W γ T t) ((stripDrift W γ T).solution W.driver (Real.toNNReal t) ω))^2 ∂W.law + +lemma stripQ_continuous (W : BrownianSystem Ω) (γ : OrderParameter) (T : Time) : + Continuous (stripQ W γ T) := + (stripDrift W γ T).expected_continuous W (compactSquare_family W γ T.property.1 T.property.2) + (compactSquare_continuous W γ T.property.1 T.property.2) + +lemma stripA_continuous (W : BrownianSystem Ω) (γ : OrderParameter) (T : Time) : + Continuous (stripA W γ T) := by + have hu := (compactGradient_family W γ T.property.1 T.property.2).deriv + have hf : BoundedSmoothFamily (fun t x => (deriv (compactGradient W γ T t) x)^2) := by + simpa only [pow_two] using hu.mul hu + exact (stripDrift W γ T).expected_continuous W hf + (compactCurvatureSquare_continuous W γ T.property.1 T.property.2) + +lemma stripQ_zero (W : BrownianSystem Ω) (γ : OrderParameter) (T : Time) : stripQ W γ T 0 = 0 := by + have hx (ω : Ω) : (stripDrift W γ T).solution W.driver 0 ω = 0 := by + rw [(stripDrift W γ T).solution_eq _ W.driver_progressive] + simp only [NNReal.coe_zero,intervalIntegral.integral_same,W.driver_zero,add_zero] + have hu : compactGradient W γ T 0 0 = 0 := by + rw [compactGradient,stripClamp_eq ⟨le_rfl,T.property.1⟩] + exact gradient_zero W γ (by norm_num) (by norm_num) + simp only [stripQ,Real.toNNReal_zero,hx,compactSquare,hu,mul_zero,integral_zero] + +lemma stripQ_hasDerivWithinAt_right (W : BrownianSystem Ω) (γ : OrderParameter) + (T : Time) (s : ℝ≥0) (hsT : (s:ℝ) < T) : + HasDerivWithinAt (stripQ W γ T) (stripA W γ T s) (Ioi (s:ℝ)) s := by + let := W.isProbability + let b := stripDrift W γ T + have hf := compactSquare_family W γ T.property.1 T.property.2 + have hd := compactSquareRate_family W γ T.property.1 T.property.2 + have hgen := expected_hasDerivWithinAt_right W b hf hd + (fun a c ha hac hc => compactSquare_integral_rate W γ T.property.1 T.property.2 ha hac hc) + s hsT (compactSquareRate_right W γ T.property.1 T.property.2 (s:ℝ)) (stripDrift_pathDrift_right W γ T s) + have hx := b.solution_measurable W s + have hi1 : Integrable (fun ω => deriv (compactSquare W γ T s) (b.solution W.driver s ω)*b.pathDrift W s ω) W.law := by + apply (integrable_family_comp hf.deriv (s:ℝ) hx).mul_bdd + · exact ((b.pathDrift_measurable W).comp measurable_prodMk_left).aestronglyMeasurable + · exact Eventually.of_forall (fun ω => b.pathDrift_bound W s ω) + have hi2 := integrable_family_comp (P := W.law) hf.deriv.deriv (s:ℝ) hx + have hi3 := integrable_family_comp (P := W.law) hd (s:ℝ) hx + have he : (∫ ω, deriv (compactSquare W γ T s) (b.solution W.driver s ω)*b.pathDrift W s ω ∂W.law)+ + (1/2:ℝ)*(∫ ω, deriv (deriv (compactSquare W γ T s)) (b.solution W.driver s ω) ∂W.law)+ + (∫ ω, compactSquareRate W γ T s (b.solution W.driver s ω) ∂W.law) = stripA W γ T s := by + have hi12 : Integrable (fun ω => deriv (compactSquare W γ T s) (b.solution W.driver s ω)*b.pathDrift W s ω+ + (1/2:ℝ)*deriv (deriv (compactSquare W γ T s)) (b.solution W.driver s ω)) W.law := + hi1.add (hi2.const_mul (1/2:ℝ)) + rw [← integral_const_mul,← integral_add hi1 (hi2.const_mul (1/2:ℝ)),← integral_add hi12 hi3] + apply integral_congr_ae + filter_upwards [] with ω + simpa only [stripA,Real.toNNReal_coe,BoundedLipschitzDrift.pathDrift,b,stripDrift] using + compactSquare_generator W γ T.property.1 T.property.2 (s:ℝ) (b.solution W.driver s ω) + rw [he] at hgen + exact hgen + +theorem stripQ_eq_integral (W : BrownianSystem Ω) (γ : OrderParameter) + (T : Time) {t : ℝ} (ht0 : 0 ≤ t) (htT : t ≤ T) : + stripQ W γ T t = ∫ s in (0:ℝ)..t, stripA W γ T s := by + have hi := intervalIntegral.integral_eq_sub_of_hasDeriv_right_of_le ht0 + (stripQ_continuous W γ T).continuousOn + (fun s hs => by + have hh := stripQ_hasDerivWithinAt_right W γ T (Real.toNNReal s) + (by rw [Real.coe_toNNReal _ hs.1.le]; exact hs.2.trans_le htT) + simpa only [Real.coe_toNNReal _ hs.1.le] using hh) + ((stripA_continuous W γ T).intervalIntegrable 0 t) + rw [stripQ_zero,sub_zero] at hi + exact hi.symm + +end ZeroTemperatureSK + +end +end +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section +namespace ZeroTemperatureSK +open Heat WeakIto +variable {Ω : Type*} [MeasurableSpace Ω] + +lemma diffusion_eq_strip (W : BrownianSystem Ω) (γ : OrderParameter) (T : Time) + (s : ℝ≥0) (hs : (s:ℝ) ≤ T) (ω : Ω) : + diffusion W γ s ω = (stripDrift W γ T).solution W.driver s ω := by + have hs1 := hs.trans_lt T.property.2 + obtain ⟨n,hn⟩ := (eventually_le_diffusionHorizon hs1).exists + rw [diffusion_eq_raw W γ s hs1,rawDiffusion_eq_local W γ n s hn] + apply (stripDrift W γ (diffusionHorizonTime n)).solution_eq_of_agree + (stripDrift W γ T) _ W.driver_progressive s _ s le_rfl ω + intro r hr x + have hrs : (r:ℝ) ≤ (s:ℝ) := hr + rw [stripDrift_eq W γ _ ⟨r.coe_nonneg,hrs.trans hn⟩, + stripDrift_eq W γ _ ⟨r.coe_nonneg,hrs.trans hs⟩] + +def curvatureMoment (W : BrownianSystem Ω) (γ : OrderParameter) (t : ℝ) : ℝ := + ∫ ω, (curvature W γ t (diffusion W γ (Real.toNNReal t) ω))^2 ∂W.law + +lemma stripQ_eq_squareMoment (W : BrownianSystem Ω) (γ : OrderParameter) (T : Time) + {t : ℝ} (ht : t ∈ Icc (0:ℝ) T) : stripQ W γ T t = squareMoment W γ (diffusion W γ) t := by + have hs : ((Real.toNNReal t):ℝ) ≤ T := by rw [Real.coe_toNNReal _ ht.1]; exact ht.2 + unfold stripQ squareMoment + apply integral_congr_ae + filter_upwards [] with ω + rw [diffusion_eq_strip W γ T _ hs] + simp only [compactSquare,compactGradient,stripClamp_eq ht,pow_two] + +lemma stripA_eq_curvatureMoment (W : BrownianSystem Ω) (γ : OrderParameter) (T : Time) + {t : ℝ} (ht : t ∈ Icc (0:ℝ) T) : stripA W γ T t = curvatureMoment W γ t := by + have hs : ((Real.toNNReal t):ℝ) ≤ T := by rw [Real.coe_toNNReal _ ht.1]; exact ht.2 + have he : compactGradient W γ T t = gradient W γ t := by + funext x + simp only [compactGradient,stripClamp_eq ht] + unfold stripA curvatureMoment + apply integral_congr_ae + filter_upwards [] with ω + rw [diffusion_eq_strip W γ T _ hs,he] + rfl + +theorem squareMoment_eq_integral_curvatureMoment (W : BrownianSystem Ω) (γ : OrderParameter) + {t : ℝ} (ht0 : 0 ≤ t) (ht1 : t < 1) : + squareMoment W γ (diffusion W γ) t = ∫ s in (0:ℝ)..t, curvatureMoment W γ s := by + let T : Time := ⟨t,⟨ht0,ht1⟩⟩ + rw [← stripQ_eq_squareMoment W γ T ⟨ht0,le_rfl⟩,stripQ_eq_integral W γ T ht0 le_rfl] + apply intervalIntegral.integral_congr + intro s hs + rw [uIcc_of_le ht0] at hs + exact stripA_eq_curvatureMoment W γ T hs + +lemma curvatureMoment_continuousOn (W : BrownianSystem Ω) (γ : OrderParameter) + {T : ℝ} (hT0 : 0 ≤ T) (hT1 : T < 1) : ContinuousOn (curvatureMoment W γ) (Icc (0:ℝ) T) := by + exact (stripA_continuous W γ ⟨T,⟨hT0,hT1⟩⟩).continuousOn.congr + (fun t ht => (stripA_eq_curvatureMoment W γ ⟨T,⟨hT0,hT1⟩⟩ ht).symm) + +lemma squareMoment_zero (W : BrownianSystem Ω) (γ : OrderParameter) : + squareMoment W γ (diffusion W γ) 0 = 0 := by + rw [squareMoment_eq_integral_curvatureMoment W γ (by norm_num) (by norm_num),intervalIntegral.integral_same] + +theorem squareMoment_hasDerivWithinAt (W : BrownianSystem Ω) (γ : OrderParameter) + {t : ℝ} (ht0 : 0 ≤ t) (ht1 : t < 1) : + HasDerivWithinAt (squareMoment W γ (diffusion W γ)) (curvatureMoment W γ t) (Ici (0:ℝ)) t := by + let T : Time := ⟨(t+1)/2,⟨by linarith,by linarith⟩⟩ + have htt : t < (T:ℝ) := by dsimp [T]; linarith + have hc := stripA_continuous W γ T + have hd := intervalIntegral.integral_hasDerivAt_right (hc.intervalIntegrable 0 t) + hc.stronglyMeasurable.stronglyMeasurableAtFilter hc.continuousAt + rw [stripA_eq_curvatureMoment W γ T ⟨ht0,htt.le⟩] at hd + apply hd.hasDerivWithinAt.congr_of_eventuallyEq + · filter_upwards [self_mem_nhdsWithin,mem_nhdsWithin_of_mem_nhds (gt_mem_nhds htt)] with s hs hsT + rw [← stripQ_eq_squareMoment W γ T ⟨hs,hsT.le⟩,stripQ_eq_integral W γ T hs hsT.le] + · rw [← stripQ_eq_squareMoment W γ T ⟨ht0,htt.le⟩,stripQ_eq_integral W γ T ht0 htt.le] + +end ZeroTemperatureSK + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKSupport/Moments/ThirdFields.lean b/lean/OAI/Probability/SKSupport/Moments/ThirdFields.lean new file mode 100644 index 0000000000000000000000000000000000000000..193fb455fbe712c6e496252f11dcd2836808b463 --- /dev/null +++ b/lean/OAI/Probability/SKSupport/Moments/ThirdFields.lean @@ -0,0 +1,148 @@ +import Mathlib +import OAI.Probability.SKSupport.Moments.StripSquareMoment +import OAI.Probability.SKSupport.Moments.JetFields + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section +namespace ZeroTemperatureSK +open Heat WeakIto +variable {Ω : Type*} [MeasurableSpace Ω] + +def thirdCurvatureField (W : BrownianSystem Ω) (γ : OrderParameter) {T : ℝ} + (hT0 : 0 ≤ T) (hT1 : T < 1) (c : ℝ) : TimeField T := + (((compactJetField W γ hT0 hT1 3).mul (compactJetField W γ hT0 hT1 3)).add + (((compactJetField W γ hT0 hT1 1).mul + ((compactJetField W γ hT0 hT1 2).mul (compactJetField W γ hT0 hT1 2))).const_mul (-12*c))).add + (((curvatureField W γ hT0 hT1).mul (curvatureField W γ hT0 hT1)).const_mul (6*c^2)) + +lemma thirdCurvatureField_eq (W : BrownianSystem Ω) (γ : OrderParameter) {T : ℝ} + (hT0 : 0 ≤ T) (hT1 : T < 1) (c t x : ℝ) : + (thirdCurvatureField W γ hT0 hT1 c).f t x= + (compactJet W γ T 3 t x)^2-12*c*compactJet W γ T 1 t x*(compactJet W γ T 2 t x)^2+ + 6*c^2*(compactJet W γ T 1 t x)^4 := by + dsimp only [thirdCurvatureField,curvatureField,TimeField.add,TimeField.mul,TimeField.const_mul,compactJetField] + ring + +lemma secondCurvatureField_generator_eq (W : BrownianSystem Ω) (γ : OrderParameter) {T : ℝ} + (hT0 : 0 ≤ T) (hT1 : T < 1) (c t x : ℝ) (hc : compactCoeff γ T t=c) : + (secondCurvatureField W γ hT0 hT1 c).generator (compactDrift W γ T) t x= + (thirdCurvatureField W γ hT0 hT1 c).f t x := by + rw [thirdCurvatureField_eq] + exact secondCurvatureField_generator W γ hT0 hT1 c t x hc + +end ZeroTemperatureSK + +end +end +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section +namespace ZeroTemperatureSK + +lemma hasDerivAt_of_right_on_Ioo {F G : ℝ → ℝ} {a b t : ℝ} + (hF : Continuous F) (hG : Continuous G) (ht : t ∈ Ioo a b) + (hd : ∀ s ∈ Ioo a b, HasDerivWithinAt F (G s) (Ioi s) s) : + HasDerivAt F (G t) t := by + have he (s : ℝ) (hs : s ∈ Ioo a b) : F s=(∫ r in a..s, G r)+F a := by + have hi := intervalIntegral.integral_eq_sub_of_hasDeriv_right_of_le hs.1.le hF.continuousOn + (fun r hr => hd r ⟨hr.1,hr.2.trans hs.2⟩) (hG.intervalIntegrable a s) + linarith + have hh := (intervalIntegral.integral_hasDerivAt_right (hG.intervalIntegrable a t) + hG.stronglyMeasurable.stronglyMeasurableAtFilter hG.continuousAt).add_const (F a) + apply hh.congr_of_eventuallyEq + filter_upwards [Ioo_mem_nhds ht.1 ht.2] with s hs + exact he s hs + +end ZeroTemperatureSK + +end +end +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section +namespace ZeroTemperatureSK +open Heat WeakIto +variable {Ω : Type*} [MeasurableSpace Ω] + +def stripSecond (W : BrownianSystem Ω) (γ : OrderParameter) (T : Time) (c : ℝ) : ℝ → ℝ := + (secondCurvatureField W γ T.property.1 T.property.2 c).expected (stripDrift W γ T) W + +def stripThird (W : BrownianSystem Ω) (γ : OrderParameter) (T : Time) (c : ℝ) : ℝ → ℝ := + (thirdCurvatureField W γ T.property.1 T.property.2 c).expected (stripDrift W γ T) W + +lemma stripSecond_continuous (W : BrownianSystem Ω) (γ : OrderParameter) (T : Time) (c : ℝ) : + Continuous (stripSecond W γ T c) := TimeField.expected_continuous _ _ _ + +lemma stripThird_continuous (W : BrownianSystem Ω) (γ : OrderParameter) (T : Time) (c : ℝ) : + Continuous (stripThird W γ T c) := TimeField.expected_continuous _ _ _ + +lemma curvatureField_expected (W : BrownianSystem Ω) (γ : OrderParameter) (T : Time) : + (curvatureField W γ T.property.1 T.property.2).expected (stripDrift W γ T) W=stripA W γ T := by + funext t + unfold TimeField.expected stripA + apply integral_congr_ae + filter_upwards [] with ξ + rw [curvatureField_eq] + simp only [compactJet,iteratedDeriv_one] + +lemma stripA_hasDerivWithinAt_right (W : BrownianSystem Ω) (γ : OrderParameter) + (T : Time) (s : ℝ≥0) (hs : (s:ℝ) < T) : + HasDerivWithinAt (stripA W γ T) (stripSecond W γ T (compactCoeff γ T s) s) (Ioi (s:ℝ)) s := by + have hd := (curvatureField W γ T.property.1 T.property.2).expected_hasDerivWithinAt_right + (stripDrift W γ T) W s hs (stripDrift_pathDrift_right W γ T s) + rw [curvatureField_expected] at hd + convert hd using 1 + unfold stripSecond TimeField.expected + apply integral_congr_ae + filter_upwards [] with ξ + simp only [Real.toNNReal_coe,stripDrift] + exact (curvatureField_generator W γ T.property.1 T.property.2 (s:ℝ) _).symm + +lemma stripSecond_hasDerivWithinAt_right (W : BrownianSystem Ω) (γ : OrderParameter) + (T : Time) (c : ℝ) (s : ℝ≥0) (hs : (s:ℝ) < T) (hc : compactCoeff γ T s=c) : + HasDerivWithinAt (stripSecond W γ T c) (stripThird W γ T c s) (Ioi (s:ℝ)) s := by + have hd := (secondCurvatureField W γ T.property.1 T.property.2 c).expected_hasDerivWithinAt_right + (stripDrift W γ T) W s hs (stripDrift_pathDrift_right W γ T s) + change HasDerivWithinAt (stripSecond W γ T c) _ _ _ at hd + convert hd using 1 + unfold stripThird TimeField.expected + apply integral_congr_ae + filter_upwards [] with ξ + simp only [Real.toNNReal_coe,stripDrift] + exact (secondCurvatureField_generator_eq W γ T.property.1 T.property.2 c (s:ℝ) _ hc).symm + +lemma stripA_hasDerivAt_on_constant (W : BrownianSystem Ω) (γ : OrderParameter) (T : Time) + {a b c t : ℝ} (ha : 0 ≤ a) (hbT : b ≤ T) (ht : t ∈ Ioo a b) + (hc : ∀ s ∈ Ioo a b, compactCoeff γ T s=c) : + HasDerivAt (stripA W γ T) (stripSecond W γ T c t) t := by + apply hasDerivAt_of_right_on_Ioo (stripA_continuous W γ T) (stripSecond_continuous W γ T c) ht + intro s hs + have hs0 := ha.trans hs.1.le + have hd := stripA_hasDerivWithinAt_right W γ T (Real.toNNReal s) + (by rw [Real.coe_toNNReal _ hs0]; exact hs.2.trans_le hbT) + simpa only [Real.coe_toNNReal _ hs0,hc s hs] using hd + +lemma stripSecond_hasDerivAt_on_constant (W : BrownianSystem Ω) (γ : OrderParameter) (T : Time) + {a b c t : ℝ} (ha : 0 ≤ a) (hbT : b ≤ T) (ht : t ∈ Ioo a b) + (hc : ∀ s ∈ Ioo a b, compactCoeff γ T s=c) : + HasDerivAt (stripSecond W γ T c) (stripThird W γ T c t) t := by + apply hasDerivAt_of_right_on_Ioo (stripSecond_continuous W γ T c) (stripThird_continuous W γ T c) ht + intro s hs + have hs0 := ha.trans hs.1.le + have hd := stripSecond_hasDerivWithinAt_right W γ T c (Real.toNNReal s) + (by rw [Real.coe_toNNReal _ hs0]; exact hs.2.trans_le hbT) + (by rw [Real.coe_toNNReal _ hs0];exact hc s hs) + simpa only [Real.coe_toNNReal _ hs0] using hd + +end ZeroTemperatureSK + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKSupport/Parabolic/AffineEvolution.lean b/lean/OAI/Probability/SKSupport/Parabolic/AffineEvolution.lean new file mode 100644 index 0000000000000000000000000000000000000000..50b08a61cde5b6c79db00e71ec98f3c7180f5a3a --- /dev/null +++ b/lean/OAI/Probability/SKSupport/Parabolic/AffineEvolution.lean @@ -0,0 +1,169 @@ +import Mathlib +import OAI.Probability.SKSupport.Parabolic.ForwardRegularity + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology ContDiff +noncomputable section +namespace ZeroTemperatureSK.Heat + +lemma AffineSmoothFamily.mul_bounded {F G : ℝ → ℝ → ℝ} + (hF : AffineSmoothFamily F) (hG : BoundedSmoothFamily G) + (hcG : Continuous (fun p : ℝ × ℝ => G p.1 p.2)) : + AffineSmoothFamily (fun t x => F t x*G t x) := by + obtain ⟨A,B,hA,hAc,hB,hBc,rfl⟩ := hF + refine ⟨fun t x => A t x*G t x,fun t x => B t x*G t x, + hA.mul hG,hAc.mul hcG,hB.mul hG,hBc.mul hcG,?_⟩ + funext t x + ring + +lemma integral_affine_rate {F R : ℝ → ℝ → ℝ} + (hc : Continuous (fun p : ℝ × ℝ => F p.1 p.2)) (hR : AffineSmoothFamily R) + (ht : ∀ t, 0 < t → ∀ x, HasDerivAt (fun s => F s x) (R t x) t) + {a b : ℝ} (ha : 0 ≤ a) (hab : a ≤ b) (x : ℝ) : + (∫ t in a..b, R t x) = F b x-F a x := by + apply intervalIntegral.integral_eq_sub_of_hasDerivAt_of_le hab + · exact (hc.comp (continuous_id.prodMk continuous_const)).continuousOn + · intro t htt + exact ht t (ha.trans_lt htt.1) x + · exact hR.intervalIntegrable x a b + +lemma integral_affine_rate_derivative {F R : ℝ → ℝ → ℝ} + (hc : Continuous (fun p : ℝ × ℝ => F p.1 p.2)) (hR : AffineSmoothFamily R) + (hs : ∀ t, ContDiff ℝ ∞ (F t)) + (ht : ∀ t, 0 < t → ∀ x, HasDerivAt (fun s => F s x) (R t x) t) + {a b : ℝ} (ha : 0 ≤ a) (hab : a ≤ b) (n : ℕ) (x : ℝ) : + (∫ t in a..b, iteratedDeriv n (R t) x) = iteratedDeriv n (F b) x-iteratedDeriv n (F a) x := by + have he : (fun z => ∫ t in a..b, R t z) = fun z => F b z-F a z := + funext (integral_affine_rate hc hR ht ha hab) + have hh := hR.iteratedDeriv_integral n a b x + rw [he,iteratedDeriv_fun_sub (n := n) + ((hs b).of_le (ENat.natCast_le_of_coe_top_le_withTop le_rfl n) |>.contDiffAt) + ((hs a).of_le (ENat.natCast_le_of_coe_top_le_withTop le_rfl n) |>.contDiffAt)] at hh + exact hh.symm + +lemma hasDerivAt_affine_evolution_jet {F R : ℝ → ℝ → ℝ} + (hc : Continuous (fun p : ℝ × ℝ => F p.1 p.2)) (hR : AffineSmoothFamily R) + (hs : ∀ t, ContDiff ℝ ∞ (F t)) + (ht : ∀ t, 0 < t → ∀ x, HasDerivAt (fun s => F s x) (R t x) t) + {t : ℝ} (htp : 0 < t) (n : ℕ) (x : ℝ) : + HasDerivAt (fun s => iteratedDeriv n (F s) x) (iteratedDeriv n (R t) x) t := by + have hJ := hR.iteratedDeriv n + have hcont : Continuous (fun s => iteratedDeriv n (R s) x) := + hJ.continuous.comp (continuous_id.prodMk continuous_const) + have hi := intervalIntegral.integral_hasDerivAt_right (hJ.intervalIntegrable x 0 t) + (hcont.measurable.stronglyMeasurable.stronglyMeasurableAtFilter) hcont.continuousAt + apply (hi.const_add (iteratedDeriv n (F 0) x)).congr_of_eventuallyEq + filter_upwards [Ioi_mem_nhds htp] with s hsp + rw [integral_affine_rate_derivative hc hR hs ht le_rfl hsp.le n x] + ring + +end ZeroTemperatureSK.Heat + +end +end +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology ContDiff +noncomputable section +namespace ZeroTemperatureSK.Heat + +lemma tiltedMean_add {f g q : ℝ → ℝ} {K : ℝ≥0} + (hf : LipschitzWith K f) (hg : BoundedSmooth g) (hq : BoundedSmooth q) + (c : ℝ) (h : ℝ≥0) (x : ℝ) : + tiltedMean c h f (fun z => g z+q z) x = tiltedMean c h f g x+tiltedMean c h f q x := by + obtain ⟨G,hG⟩ := hg.bound + obtain ⟨Q,hQ⟩ := hq.bound + have hgI := integrable_weight_exp_translate hf hg.smooth.continuous.measurable hG c h x + have hqI := integrable_weight_exp_translate hf hq.smooth.continuous.measurable hQ c h x + unfold tiltedMean semigroup + simp_rw [add_mul] + rw [integral_add hgI hqI,add_div] + +lemma tiltedMean_const_mul (f g : ℝ → ℝ) (c d : ℝ) (h : ℝ≥0) (x : ℝ) : + tiltedMean c h f (fun z => d*g z) x = d*tiltedMean c h f g x := by + unfold tiltedMean semigroup + simp_rw [mul_assoc] + rw [integral_const_mul] + ring + +lemma tiltedMean_const {f : ℝ → ℝ} {K : ℝ≥0} (hf : LipschitzWith K f) + (c d : ℝ) (h : ℝ≥0) (x : ℝ) : tiltedMean c h f (fun _ => d) x = d := by + unfold tiltedMean + have he : semigroup h (fun z => d*Real.exp (c*f z)) x = + d*semigroup h (fun z => Real.exp (c*f z)) x := integral_const_mul d _ + rw [he] + exact mul_div_cancel_right₀ d (ne_of_gt (semigroup_exp_pos hf c h x)) + +lemma tiltedMean_nonneg {f g : ℝ → ℝ} {K : ℝ≥0} (hf : LipschitzWith K f) + (hg : ∀ x, 0 ≤ g x) (c : ℝ) (h : ℝ≥0) (x : ℝ) : 0 ≤ tiltedMean c h f g x := by + apply div_nonneg _ (semigroup_exp_pos hf c h x).le + exact integral_nonneg (fun y => mul_nonneg (hg _) (Real.exp_nonneg _)) + +lemma tiltedMean_pos {f g : ℝ → ℝ} {K : ℝ≥0} (hf : LipschitzWith K f) + (hg : BoundedSmooth g) (hpos : ∀ x, 0 < g x) (c : ℝ) (h : ℝ≥0) (x : ℝ) : + 0 < tiltedMean c h f g x := by + obtain ⟨G,hG⟩ := hg.bound + apply div_pos _ (semigroup_exp_pos hf c h x) + apply (integral_pos_iff_support_of_nonneg (fun y => + (mul_pos (hpos (x+y)) (Real.exp_pos _)).le) + (integrable_weight_exp_translate hf hg.smooth.continuous.measurable hG c h x)).mpr + have he : Function.support (fun y => g (x+y)*Real.exp (c*f (x+y))) = univ := by + ext y + simp only [Function.mem_support,mem_univ,iff_true] + exact ne_of_gt (mul_pos (hpos _) (Real.exp_pos _)) + rw [he,measure_univ] + norm_num + +lemma tiltedMean_variance_nonneg {f g : ℝ → ℝ} {K : ℝ≥0} + (hf : LipschitzWith K f) (hg : BoundedSmooth g) (c : ℝ) (h : ℝ≥0) (x : ℝ) : + 0 ≤ tiltedMean c h f (fun z => (g z)^2) x-(tiltedMean c h f g x)^2 := by + let m := tiltedMean c h f g x + have he : (fun z => (g z-m)^2) = fun z => (g z*g z+(-2*m)*g z)+m*m := by + funext z; ring + have hh := tiltedMean_nonneg hf (fun z => sq_nonneg (g z-m)) c h x + rw [he,tiltedMean_add hf ((hg.mul hg).add (hg.const_mul (-2*m))) (BoundedSmooth.const (m*m)), + tiltedMean_add hf (hg.mul hg) (hg.const_mul (-2*m)),tiltedMean_const_mul, + tiltedMean_const hf] at hh + change 0 ≤ tiltedMean c h f (fun z => g z^2) x-m^2 + have hpow : (fun z => g z*g z) = fun z => g z^2 := by funext z; ring + rw [hpow] at hh + dsimp only [m] at hh ⊢ + nlinarith + +lemma deriv_logSemigroup_tilted {f : ℝ → ℝ} {K : ℝ≥0} + (hf : RegularDatum f) (hLip : LipschitzWith K f) {c : ℝ} (hc : 0 ≤ c) (h : ℝ≥0) : + deriv (logSemigroup c h f) = tiltedMean c h f (deriv f) := by + funext x + by_cases hc0 : c = 0 + · subst c + have he : logSemigroup 0 h f = semigroup h f := by funext z; simp [logSemigroup] + rw [he,(hasDerivAt_semigroup (hf.smooth.of_le (by simp)) hLip h x).deriv] + simp [tiltedMean,semigroup] + · exact (hasDerivAt_logSemigroup (hf.smooth.of_le (by simp)) hLip + (lt_of_le_of_ne hc (Ne.symm hc0)) h x).deriv + +lemma logSemigroup_curvature_pos {f : ℝ → ℝ} {K : ℝ≥0} + (hf : RegularDatum f) (hLip : LipschitzWith K f) (hpos : ∀ x, 0 < deriv (deriv f) x) + {c : ℝ} (hc : 0 ≤ c) (h : ℝ≥0) (x : ℝ) : + 0 < deriv (deriv (logSemigroup c h f)) x := by + rw [deriv_logSemigroup_tilted hf hLip hc, + (hasDerivAt_tiltedMean hf hLip hf.deriv_bounded hc h x).deriv] + have he : (fun z => deriv (deriv f) z+c*deriv f z*deriv f z) = + fun z => deriv (deriv f) z+c*(deriv f z*deriv f z) := by funext z; ring + rw [he,tiltedMean_add hLip hf.deriv_bounded.deriv + ((hf.deriv_bounded.mul hf.deriv_bounded).const_mul c),tiltedMean_const_mul] + have hp := tiltedMean_pos hLip hf.deriv_bounded.deriv hpos c h x + have hv := mul_nonneg hc (tiltedMean_variance_nonneg hLip hf.deriv_bounded c h x) + have hpow : (fun z => deriv f z*deriv f z) = fun z => (deriv f z)^2 := by funext z; ring + rw [hpow] + nlinarith + +end ZeroTemperatureSK.Heat + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKSupport/Parabolic/BurgersConstruction.lean b/lean/OAI/Probability/SKSupport/Parabolic/BurgersConstruction.lean new file mode 100644 index 0000000000000000000000000000000000000000..117980b919366fe9070567dff2d1d76d4fb88e14 --- /dev/null +++ b/lean/OAI/Probability/SKSupport/Parabolic/BurgersConstruction.lean @@ -0,0 +1,240 @@ +import Mathlib +import OAI.Probability.SKSupport.Control.CoefficientApprox +import OAI.Probability.SKSupport.Parabolic.AffineEvolution + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology ContDiff +noncomputable section +namespace ZeroTemperatureSK.Heat + +lemma hasDerivAt_spatialJet {f : ℝ → ℝ} (hf : ContDiff ℝ ∞ f) (n : ℕ) (x : ℝ) : + HasDerivAt (iteratedDeriv n f) (iteratedDeriv (n+1) f x) x := by + simpa only [iteratedDeriv_succ] using + ((contDiff_iteratedDeriv_infty hf n).differentiable (by simp) x).hasDerivAt + +def burgersRate (r : ℝ → ℝ → ℝ) (t x : ℝ) : ℝ := + (1/2:ℝ)*iteratedDeriv 2 (r t) x+r t x*deriv (r t) x + +structure SmoothBurgers (r : ℝ → ℝ → ℝ) : Prop where + family : BoundedSmoothFamily r + continuous : ∀ T, ContinuousOn (fun p : ℝ × ℝ => r p.1 p.2) (Icc (0:ℝ) T ×ˢ univ) + time_derivative : ∀ n t, 0 < t → ∀ x, + HasDerivAt (fun s => iteratedDeriv n (r s) x) (iteratedDeriv n (burgersRate r t) x) t + +def gaussianBurgers (c : ℝ) (f : ℝ → ℝ) (t x : ℝ) : ℝ := + c*deriv (varianceLogHeat c t f) x + +lemma gaussianBurgers_jet {f : ℝ → ℝ} {K : ℝ≥0} + (hf : RegularDatum f) (hLip : LipschitzWith K f) {c : ℝ} (hc : 0 ≤ c) + (n : ℕ) (t x : ℝ) : iteratedDeriv n (gaussianBurgers c f t) x = + c*iteratedDeriv (n+1) (varianceLogHeat c t f) x := by + change iteratedDeriv n (fun x => c*deriv (varianceLogHeat c t f) x) x = _ + rw [iteratedDeriv_const_mul c + ((regularDatum_varianceLogHeat hf hLip hc t).deriv_bounded.smooth.of_le + (ENat.natCast_le_of_coe_top_le_withTop le_rfl n) |>.contDiffAt),iteratedDeriv_succ'] + +lemma gaussianBurgers_rate {f : ℝ → ℝ} {K : ℝ≥0} + (hf : RegularDatum f) (hLip : LipschitzWith K f) {c : ℝ} (hc : 0 ≤ c) + (t : ℝ) : burgersRate (gaussianBurgers c f) t = fun x => c*deriv (gaussianRate c f t) x := by + have hG := (regularDatum_varianceLogHeat hf hLip hc t).smooth + funext x + have h₁ := hasDerivAt_spatialJet hG 1 x + have h₂ := hasDerivAt_spatialJet hG 2 x + have hd : HasDerivAt (gaussianRate c f t) + ((1/2:ℝ)*iteratedDeriv 3 (varianceLogHeat c t f) x+ + c*deriv (varianceLogHeat c t f) x*iteratedDeriv 2 (varianceLogHeat c t f) x) x := by + convert (h₂.const_mul (1/2:ℝ)).add ((h₁.pow 2).const_mul (c/2)) using 1 <;> + first | rfl | ((try funext y); simp only [gaussianRate, Pi.add_apply, Pi.pow_apply,iteratedDeriv_succ,iteratedDeriv_zero] <;> ring) + rw [hd.deriv,burgersRate,gaussianBurgers_jet hf hLip hc 2] + have he := gaussianBurgers_jet hf hLip hc 1 t x + simp only [iteratedDeriv_one] at he + rw [he] + dsimp only [gaussianBurgers] + ring + +theorem gaussianBurgers_smooth {f : ℝ → ℝ} {K : ℝ≥0} + (hf : RegularDatum f) (hLip : LipschitzWith K f) {c : ℝ} (hc : 0 ≤ c) : + SmoothBurgers (gaussianBurgers c f) := by + refine ⟨(varianceGradient_family hf hLip hc).const_mul c,?_,?_⟩ + · intro T + exact continuousOn_const.mul (varianceGradient_continuousOn hf hLip hc T) + · intro n t ht x + have he : (fun s => iteratedDeriv n (gaussianBurgers c f s) x) = + fun s => c*iteratedDeriv (n+1) (varianceLogHeat c s f) x := + funext (fun s => gaussianBurgers_jet hf hLip hc n s x) + rw [he,gaussianBurgers_rate hf hLip hc, + iteratedDeriv_const_mul c (((gaussianRate_family hf hLip hc).deriv.regular t).smooth.of_le + (ENat.natCast_le_of_coe_top_le_withTop le_rfl n) |>.contDiffAt),← iteratedDeriv_succ'] + exact (hasDerivAt_varianceLogHeat_derivative hf hLip hc ht (n+1) x).const_mul c + +lemma even_deriv_odd {f : ℝ → ℝ} (hf : Differentiable ℝ f) (he : Function.Even f) : + Function.Odd (deriv f) := by + intro x + have hh := (hf (-x)).hasDerivAt.comp x ((hasDerivAt_id x).neg) + have heq : (fun y => f (-y)) = f := funext he + change HasDerivAt (fun y => f (-y)) (deriv f (-x)*(-1)) x at hh + rw [heq] at hh + linarith [hh.deriv] + +lemma odd_deriv_even {f : ℝ → ℝ} (hf : Differentiable ℝ f) (he : Function.Odd f) : + Function.Even (deriv f) := by + intro x + have hh := (hf (-x)).hasDerivAt.comp x ((hasDerivAt_id x).neg) + have heq : (fun y => f (-y)) = fun y => -f y := funext he + change HasDerivAt (fun y => f (-y)) (deriv f (-x)*(-1)) x at hh + rw [heq] at hh + have hder := (hf x).hasDerivAt.neg + have he' := hh.unique hder + linarith + +lemma gaussianBurgers_odd {f : ℝ → ℝ} {K : ℝ≥0} + (hf : RegularDatum f) (hLip : LipschitzWith K f) (he : Function.Even f) + {c : ℝ} (hc : 0 ≤ c) (t : ℝ) : Function.Odd (gaussianBurgers c f t) := by + have heq : varianceLogHeat c t f = logSemigroup c (Real.toNNReal t) f := + funext (varianceLogHeat_eq_logSemigroup_toNNReal hf.smooth.continuous.measurable c t) + have hodd := even_deriv_odd ((regularDatum_varianceLogHeat hf hLip hc t).smooth.differentiable (by simp)) + (by rw [heq]; exact logSemigroup_even hf.smooth.continuous.measurable he _ _) + intro x + simp only [gaussianBurgers,hodd x,mul_neg] + +end ZeroTemperatureSK.Heat + +end +end +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology ContDiff +noncomputable section +namespace ZeroTemperatureSK.Heat + +lemma inverse_forwardTime_family {a : ℝ} (ha : 0 < a) : + BoundedSmoothFamily (fun t (_x : ℝ) => (forwardTime a t)⁻¹) := by + apply BoundedSmoothFamily.timeConst (C := Real.toNNReal a⁻¹) + (continuous_forwardTime a).measurable.inv + intro t + change |(forwardTime a t)⁻¹| ≤ (Real.toNNReal a⁻¹ : ℝ) + rw [Real.coe_toNNReal _ (inv_nonneg.mpr ha.le),abs_of_pos (inv_pos.mpr (forwardTime_pos ha t))] + exact inv_anti₀ ha (le_add_of_nonneg_right (le_max_right _ _)) + +lemma inverse_forwardTime_continuous {a : ℝ} (ha : 0 < a) : + Continuous (fun t => (forwardTime a t)⁻¹) := + (continuous_forwardTime a).inv₀ (fun t => ne_of_gt (forwardTime_pos ha t)) + +lemma forwardCorrectionRate_affine {a : ℝ} (ha : 0 < a) {f : ℝ → ℝ} {K : ℝ≥0} + (hf : RegularDatum f) (hLip : LipschitzWith K f) : + AffineSmoothFamily (forwardCorrectionRate a f) := by + have hU := forwardGradient_family ha hf hLip + have hUc := forwardGradient_continuous ha hf hLip + have hUx : Continuous (fun p : ℝ × ℝ => deriv (deriv (forwardCorrection a f p.1)) p.2) := by + simpa only [iteratedDeriv_one] using hU.continuous_iteratedDeriv hUc 1 + have hI := inverse_forwardTime_family ha + have hIc : Continuous (fun p : ℝ × ℝ => (forwardTime a p.1)⁻¹) := + (inverse_forwardTime_continuous ha).comp continuous_fst + let A (t x : ℝ) := (1/2:ℝ)*deriv (deriv (forwardCorrection a f t)) x+ + (1/2:ℝ)*(deriv (forwardCorrection a f t) x)^2-(1/2:ℝ)*(forwardTime a t)⁻¹ + let B (t x : ℝ) := -(forwardTime a t)⁻¹*deriv (forwardCorrection a f t) x + refine ⟨A,B,?_,?_,?_,?_,?_⟩ + · convert ((hU.deriv.const_mul (1/2:ℝ)).add ((hU.mul hU).const_mul (1/2:ℝ))).add + (hI.const_mul (-1/2:ℝ)) using 1 + funext t x + dsimp [A] + ring + · dsimp [A] + exact ((hUx.const_mul (1/2:ℝ)).add ((hUc.pow 2).const_mul (1/2:ℝ))).sub (hIc.const_mul (1/2:ℝ)) + · convert (hI.const_mul (-1)).mul hU using 1 + simp only [neg_one_mul] + rfl + · exact hIc.neg.mul hUc + · funext t x + dsimp [A,B,forwardCorrectionRate] + simp only [iteratedDeriv_succ,iteratedDeriv_zero,div_eq_mul_inv] + ring + +lemma hasDerivAt_forwardCorrection_jet {a t : ℝ} (ha : 0 < a) {f : ℝ → ℝ} {K : ℝ≥0} + (hf : RegularDatum f) (hLip : LipschitzWith K f) (ht : 0 < t) (n : ℕ) (x : ℝ) : + HasDerivAt (fun s => iteratedDeriv n (forwardCorrection a f s) x) + (iteratedDeriv n (forwardCorrectionRate a f t) x) t := + hasDerivAt_affine_evolution_jet (forwardCorrection_continuous ha hf hLip) + (forwardCorrectionRate_affine ha hf hLip) (forwardCorrection_smooth hf hLip) + (fun _ htt x => hasDerivAt_forwardCorrection ha hf hLip htt x) ht n x + +lemma forwardScore_affine {a : ℝ} (ha : 0 < a) {f : ℝ → ℝ} {K : ℝ≥0} + (hf : RegularDatum f) (hLip : LipschitzWith K f) : AffineSmoothFamily (forwardScore a f) := by + have hI := inverse_forwardTime_family ha + have hIc : Continuous (fun p : ℝ × ℝ => (forwardTime a p.1)⁻¹) := + (inverse_forwardTime_continuous ha).comp continuous_fst + have hU := forwardGradient_family ha hf hLip + have hUc := forwardGradient_continuous ha hf hLip + convert (hI.affine_id_mul hIc).add ((hU.affine hUc).const_mul (-1)) using 1 + funext t x + simp only [forwardScore,div_eq_mul_inv,neg_one_mul,sub_eq_add_neg] + +lemma forwardScore_deriv {a : ℝ} {f : ℝ → ℝ} {K : ℝ≥0} + (hf : RegularDatum f) (hLip : LipschitzWith K f) (t x : ℝ) : + deriv (forwardScore a f t) x=(forwardTime a t)⁻¹-iteratedDeriv 2 (forwardCorrection a f t) x := by + have hh := ((hasDerivAt_id x).div_const (forwardTime a t)).sub + (hasDerivAt_spatialJet (forwardCorrection_smooth (a := a) hf hLip t) 1 x) + convert hh.deriv using 1 <;> first | rfl | (simp only [one_div,iteratedDeriv_one] <;> rfl) + +lemma forwardScore_deriv_family {a : ℝ} (ha : 0 < a) {f : ℝ → ℝ} {K : ℝ≥0} + (hf : RegularDatum f) (hLip : LipschitzWith K f) : + BoundedSmoothFamily (fun t => deriv (forwardScore a f t)) := by + convert (inverse_forwardTime_family ha).add ((forwardGradient_family ha hf hLip).deriv.const_mul (-1)) using 1 + funext t x + rw [forwardScore_deriv hf hLip] + simp only [iteratedDeriv_succ,iteratedDeriv_zero,neg_one_mul,sub_eq_add_neg] + +lemma forwardScore_second {a : ℝ} {f : ℝ → ℝ} {K : ℝ≥0} + (hf : RegularDatum f) (hLip : LipschitzWith K f) (t x : ℝ) : + iteratedDeriv 2 (forwardScore a f t) x = -iteratedDeriv 3 (forwardCorrection a f t) x := by + have he : deriv (forwardScore a f t) = fun x => + (forwardTime a t)⁻¹-iteratedDeriv 2 (forwardCorrection a f t) x := funext (forwardScore_deriv hf hLip t) + rw [iteratedDeriv_succ (n := 1),iteratedDeriv_one,he] + exact ((hasDerivAt_spatialJet (forwardCorrection_smooth (a := a) hf hLip t) 2 x).const_sub _).deriv + +def scoreRate (s : ℝ → ℝ → ℝ) (t x : ℝ) := + (1/2:ℝ)*iteratedDeriv 2 (s t) x-s t x*deriv (s t) x + +lemma forwardCorrectionRate_deriv {a : ℝ} {f : ℝ → ℝ} {K : ℝ≥0} + (hf : RegularDatum f) (hLip : LipschitzWith K f) (t x : ℝ) : + deriv (forwardCorrectionRate a f t) x = + (1/2:ℝ)*iteratedDeriv 3 (forwardCorrection a f t) x+ + deriv (forwardCorrection a f t) x*iteratedDeriv 2 (forwardCorrection a f t) x- + ((forwardTime a t)⁻¹*deriv (forwardCorrection a f t) x+ + x/forwardTime a t*iteratedDeriv 2 (forwardCorrection a f t) x) := by + have hL := forwardCorrection_smooth (a := a) hf hLip t + have hh := ((((hasDerivAt_spatialJet hL 2 x).const_mul (1/2:ℝ)).add + (((hasDerivAt_spatialJet hL 1 x).pow 2).const_mul (1/2:ℝ))).sub + (((hasDerivAt_id x).div_const (forwardTime a t)).mul (hasDerivAt_spatialJet hL 1 x))).sub_const + ((1/2:ℝ)/forwardTime a t) + have hh' : HasDerivAt (forwardCorrectionRate a f t) + ((1/2:ℝ)*iteratedDeriv 3 (forwardCorrection a f t) x+ + deriv (forwardCorrection a f t) x*iteratedDeriv 2 (forwardCorrection a f t) x- + ((forwardTime a t)⁻¹*deriv (forwardCorrection a f t) x+ + x/forwardTime a t*iteratedDeriv 2 (forwardCorrection a f t) x)) x := by + convert hh using 1 <;> first | rfl | ((try funext y); simp only [forwardCorrectionRate,iteratedDeriv_one,id_eq,one_div,Pi.add_apply,Pi.sub_apply,Pi.mul_apply,Pi.pow_apply] <;> ring) + exact hh'.deriv + +lemma hasDerivAt_forwardScore {a t : ℝ} (ha : 0 < a) {f : ℝ → ℝ} {K : ℝ≥0} + (hf : RegularDatum f) (hLip : LipschitzWith K f) (ht : 0 < t) (x : ℝ) : + HasDerivAt (fun u => forwardScore a f u x) (scoreRate (forwardScore a f) t x) t := by + have hd := ((hasDerivAt_const t x).div (hasDerivAt_forwardTime ht) + (ne_of_gt (forwardTime_pos ha t))).sub (hasDerivAt_forwardCorrection_jet ha hf hLip ht 1 x) + convert hd using 1 + · funext u + simp only [forwardScore,iteratedDeriv_one,Pi.sub_apply,Pi.div_apply] + simp only [iteratedDeriv_one] + rw [forwardCorrectionRate_deriv hf hLip, scoreRate,forwardScore_second hf hLip,forwardScore_deriv hf hLip] + dsimp only [forwardScore] + field_simp [ne_of_gt (forwardTime_pos ha t)] + ring + +end ZeroTemperatureSK.Heat + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKSupport/Parabolic/ForwardConstruction.lean b/lean/OAI/Probability/SKSupport/Parabolic/ForwardConstruction.lean new file mode 100644 index 0000000000000000000000000000000000000000..76be77c45137f79b93dd8575b99b4d38e140fb5e --- /dev/null +++ b/lean/OAI/Probability/SKSupport/Parabolic/ForwardConstruction.lean @@ -0,0 +1,298 @@ +import Mathlib +import OAI.Probability.SKSupport.Parabolic.BurgersConstruction + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology ContDiff +noncomputable section +namespace ZeroTemperatureSK.Heat + +structure SmoothForward (s : ℝ → ℝ → ℝ) : Prop where + family : AffineSmoothFamily s + deriv_family : BoundedSmoothFamily (fun t => deriv (s t)) + time_derivative : ∀ n t, 0 < t → ∀ x, + HasDerivAt (fun u => iteratedDeriv n (s u) x) (iteratedDeriv n (scoreRate s t) x) t + +lemma scoreRate_affine {s : ℝ → ℝ → ℝ} (hs : AffineSmoothFamily s) + (hds : BoundedSmoothFamily (fun t => deriv (s t))) : AffineSmoothFamily (scoreRate s) := by + have hc := hs.deriv.continuous + have h₂c := hs.deriv.deriv.continuous + convert ((hds.deriv.affine h₂c).const_mul (1/2:ℝ)).add + ((hs.mul_bounded hds hc).const_mul (-1)) using 1 + funext t x + simp only [scoreRate,iteratedDeriv_succ,iteratedDeriv_zero,neg_one_mul,sub_eq_add_neg] + +theorem forwardScore_smooth {a : ℝ} (ha : 0 < a) {f : ℝ → ℝ} {K : ℝ≥0} + (hf : RegularDatum f) (hLip : LipschitzWith K f) : SmoothForward (forwardScore a f) := by + have hs := forwardScore_affine ha hf hLip + have hds := forwardScore_deriv_family ha hf hLip + refine ⟨hs,hds,fun n t ht x => ?_⟩ + exact hasDerivAt_affine_evolution_jet hs.continuous (scoreRate_affine hs hds) hs.smooth + (fun t htt x => hasDerivAt_forwardScore ha hf hLip htt x) ht n x + +namespace SmoothForward +variable {s : ℝ → ℝ → ℝ} (hs : SmoothForward s) +include hs + +lemma jet_spatial (n : ℕ) (t x : ℝ) : + HasDerivAt (iteratedDeriv n (s t)) (iteratedDeriv (n+1) (s t) x) x := + hasDerivAt_spatialJet (hs.family.smooth t) n x + +lemma jet_continuous (n : ℕ) : + Continuous (fun p : ℝ × ℝ => iteratedDeriv n (s p.1) p.2) := + (hs.family.iteratedDeriv n).continuous + +lemma jet_family (n : ℕ) : BoundedSmoothFamily (fun t => iteratedDeriv (n+1) (s t)) := by + simpa only [iteratedDeriv_succ'] using hs.deriv_family.iteratedDeriv n + +lemma rate_deriv (t x : ℝ) : deriv (scoreRate s t) x = + (1/2:ℝ)*iteratedDeriv 3 (s t) x-(deriv (s t) x)^2-s t x*iteratedDeriv 2 (s t) x := by + have hd := ((hs.jet_spatial 2 t x).const_mul (1/2:ℝ)).sub + ((hs.jet_spatial 0 t x).mul (hs.jet_spatial 1 t x)) + have hd' : HasDerivAt (scoreRate s t) ((1/2:ℝ)*iteratedDeriv 3 (s t) x- + (deriv (s t) x)^2-s t x*iteratedDeriv 2 (s t) x) x := by + convert hd using 1 <;> first | rfl | ((try funext y); simp only [scoreRate,Pi.sub_apply,Pi.mul_apply,iteratedDeriv_succ,iteratedDeriv_zero] <;> ring) + exact hd'.deriv + +lemma rate_jet2 (t x : ℝ) : iteratedDeriv 2 (scoreRate s t) x = + (1/2:ℝ)*iteratedDeriv 4 (s t) x-3*deriv (s t) x*iteratedDeriv 2 (s t) x- + s t x*iteratedDeriv 3 (s t) x := by + have he : deriv (scoreRate s t) = fun y => (1/2:ℝ)*iteratedDeriv 3 (s t) y- + (deriv (s t) y)^2-s t y*iteratedDeriv 2 (s t) y := funext (hs.rate_deriv t) + have hd := (((hs.jet_spatial 3 t x).const_mul (1/2:ℝ)).sub + ((hs.jet_spatial 1 t x).pow 2)).sub ((hs.jet_spatial 0 t x).mul (hs.jet_spatial 2 t x)) + rw [iteratedDeriv_succ (n := 1),iteratedDeriv_one,he] + apply HasDerivAt.deriv + convert hd using 1 <;> first | rfl | ((try funext y); simp only [iteratedDeriv_succ,iteratedDeriv_zero,Pi.sub_apply,Pi.mul_apply,Pi.pow_apply] <;> ring) + +lemma second_odd (ho : ∀ t, Function.Odd (s t)) (t : ℝ) : + Function.Odd (iteratedDeriv 2 (s t)) := by + simpa only [iteratedDeriv_succ,iteratedDeriv_zero] using + (even_deriv_odd ((hs.deriv_family.regular t).smooth.differentiable (by simp)) + (odd_deriv_even ((hs.family.smooth t).differentiable (by simp)) (ho t))) + +end SmoothForward + +lemma forwardScore_odd {a : ℝ} {f : ℝ → ℝ} {K : ℝ≥0} + (hf : RegularDatum f) (hLip : LipschitzWith K f) (he : Function.Even f) (t : ℝ) : + Function.Odd (forwardScore a f t) := by + have hd := even_deriv_odd ((forwardCorrection_smooth (a := a) hf hLip t).differentiable (by simp)) + (forwardCorrection_even hf hLip he t) + intro x + simp only [forwardScore,neg_div,hd x] + ring + +end ZeroTemperatureSK.Heat + +end +end +section +open Set Filter +open scoped Topology + +namespace ZeroTemperatureSK.Parabolic + +theorem second_derivative_nonnegative_at_min {f : ℝ → ℝ} {x d₂ : ℝ} + (hf : Continuous f) (hm : IsLocalMin f x) + (hd₂ : HasDerivAt (deriv f) d₂ x) : 0 ≤ d₂ := by + by_contra hn + have hneg : d₂ < 0 := lt_of_not_ge hn + have hzero : deriv f x = 0 := hm.deriv_eq_zero + have hr := (hasDerivAt_iff_tendsto_slope_left_right.mp hd₂).2 + have he : ∀ᶠ y in 𝓝[>] x, deriv f y < 0 := by + filter_upwards [hr.eventually (Iio_mem_nhds hneg), self_mem_nhdsWithin] with y hy hxy + have hpos : 0 < y-x := sub_pos.mpr hxy + simpa only [slope_def_field, hzero, sub_zero, div_lt_iff₀ hpos, zero_mul] using hy + have he' : ∀ᶠ y in 𝓝[>] x, deriv f y < 0 ∧ f x ≤ f y := + he.and (hm.filter_mono nhdsWithin_le_nhds) + obtain ⟨b, hxb, hb⟩ := mem_nhdsGT_iff_exists_Ioo_subset.mp he' + obtain ⟨y, hxy, hyb⟩ := exists_between (show x < b from hxb) + have hanti : StrictAntiOn f (Icc x y) := by + apply strictAntiOn_of_deriv_neg (convex_Icc x y) hf.continuousOn + intro t ht + rw [interior_Icc] at ht + exact (hb ⟨ht.1, ht.2.trans hyb⟩).1 + have hlt := hanti (left_mem_Icc.mpr hxy.le) (right_mem_Icc.mpr hxy.le) hxy + exact (not_lt_of_ge (hb ⟨hxy, hyb⟩).2) hlt + +theorem time_derivative_nonpositive {f : ℝ → ℝ} {a b x d : ℝ} + (hax : a < x) (hxb : x ≤ b) + (hd : HasDerivWithinAt f d (Icc a b) x) + (hm : IsMinOn f (Icc a b) x) : d ≤ 0 := by + have hd' : HasDerivWithinAt f d (Icc a x) x := + hd.mono (Icc_subset_Icc_right hxb) + have hs := hasDerivWithinAt_iff_tendsto_slope.mp hd' + have hset : Icc a x \ {x} = Ico a x := by + ext y + simp only [Set.mem_sdiff, mem_Icc, mem_singleton_iff, mem_Ico] + constructor + · rintro ⟨⟨hay, hyx⟩, hne⟩ + exact ⟨hay, lt_of_le_of_ne hyx hne⟩ + · rintro ⟨hay, hyx⟩ + exact ⟨⟨hay, hyx.le⟩, hyx.ne⟩ + rw [hset, nhdsWithin_Ico_eq_nhdsLT hax] at hs + apply le_of_tendsto hs + have hmem : ∀ᶠ y in 𝓝[<] x, y ∈ Ico a x := by + rw [← nhdsWithin_Ico_eq_nhdsLT hax] + exact self_mem_nhdsWithin + filter_upwards [hmem] with y hy + rw [slope_def_field] + exact div_nonpos_of_nonneg_of_nonpos + (sub_nonneg.mpr (hm ⟨hy.1, hy.2.le.trans hxb⟩)) (sub_nonpos.mpr hy.2.le) + +theorem nonnegative_of_parabolic_inequality + {u ut ux uxx κ β ℓ : ℝ → ℝ → ℝ} {t₀ t₁ a b : ℝ} + (hc : ContinuousOn (fun p : ℝ × ℝ => u p.1 p.2) (Icc t₀ t₁ ×ˢ Icc a b)) + (hs : ∀ t ∈ Icc t₀ t₁, Continuous (u t)) + (ht : ∀ t ∈ Ioc t₀ t₁, ∀ x ∈ Ioo a b, + HasDerivWithinAt (fun s => u s x) (ut t x) (Icc t₀ t₁) t) + (hx : ∀ t ∈ Ioc t₀ t₁, ∀ x ∈ Ioo a b, HasDerivAt (u t) (ux t x) x) + (hxx : ∀ t ∈ Ioc t₀ t₁, ∀ x ∈ Ioo a b, + HasDerivAt (deriv (u t)) (uxx t x) x) + (hk : ∀ t ∈ Ioc t₀ t₁, ∀ x ∈ Ioo a b, 0 ≤ κ t x) + (hl : ∀ t ∈ Ioc t₀ t₁, ∀ x ∈ Ioo a b, 0 < ℓ t x) + (hpde : ∀ t ∈ Ioc t₀ t₁, ∀ x ∈ Ioo a b, + 0 ≤ ut t x - κ t x * uxx t x - β t x * ux t x + ℓ t x * u t x) + (hinit : ∀ x ∈ Icc a b, 0 ≤ u t₀ x) + (hleft : ∀ t ∈ Icc t₀ t₁, 0 ≤ u t a) + (hright : ∀ t ∈ Icc t₀ t₁, 0 ≤ u t b) : + ∀ t ∈ Icc t₀ t₁, ∀ x ∈ Icc a b, 0 ≤ u t x := by + intro t htmem x hxmem + by_contra hn + have hnegative : u t x < 0 := lt_of_not_ge hn + obtain ⟨p, hp, hm⟩ := (isCompact_Icc.prod isCompact_Icc).exists_isMinOn + ⟨(t,x), htmem, hxmem⟩ hc + have hpneg : u p.1 p.2 < 0 := lt_of_le_of_lt (hm (show (t, x) ∈ Icc t₀ t₁ ×ˢ Icc a b from ⟨htmem, hxmem⟩)) hnegative + have hpt : p.1 ∈ Ioc t₀ t₁ := by + refine ⟨lt_of_le_of_ne hp.1.1 ?_, hp.1.2⟩ + intro heq + have hz := hinit p.2 hp.2 + rw [heq] at hz + exact (not_lt_of_ge hz) hpneg + have hpx : p.2 ∈ Ioo a b := by + constructor + · refine lt_of_le_of_ne hp.2.1 ?_ + intro heq + have hz := hleft p.1 hp.1 + rw [heq] at hz + exact (not_lt_of_ge hz) hpneg + · refine lt_of_le_of_ne hp.2.2 ?_ + intro heq + have hz := hright p.1 hp.1 + rw [← heq] at hz + exact (not_lt_of_ge hz) hpneg + have hmintime : IsMinOn (fun s => u s p.2) (Icc t₀ t₁) p.1 := by + intro s hs + exact hm (show (s, p.2) ∈ Icc t₀ t₁ ×ˢ Icc a b from ⟨hs, hp.2⟩) + have hut : ut p.1 p.2 ≤ 0 := + time_derivative_nonpositive hpt.1 hpt.2 (ht p.1 hpt p.2 hpx) hmintime + have hminspace : IsMinOn (u p.1) (Icc a b) p.2 := by + intro y hy + exact hm (show (p.1, y) ∈ Icc t₀ t₁ ×ˢ Icc a b from ⟨hp.1, hy⟩) + have hlocal := hminspace.isLocalMin (Icc_mem_nhds hpx.1 hpx.2) + have hux : ux p.1 p.2 = 0 := hlocal.hasDerivAt_eq_zero (hx p.1 hpt p.2 hpx) + have huxx : 0 ≤ uxx p.1 p.2 := + second_derivative_nonnegative_at_min (hs p.1 hp.1) hlocal (hxx p.1 hpt p.2 hpx) + have h1 := mul_nonneg (hk p.1 hpt p.2 hpx) huxx + have h2 := mul_neg_of_pos_of_neg (hl p.1 hpt p.2 hpx) hpneg + have h3 := hpde p.1 hpt p.2 hpx + rw [hux, mul_zero, sub_zero] at h3 + linarith + +theorem exponential_lower_barrier + {u ut ux uxx κ β c : ℝ → ℝ → ℝ} {t₀ t₁ a b C ε : ℝ} + (hε : 0 ≤ ε) + (hc : ContinuousOn (fun p : ℝ × ℝ => u p.1 p.2) (Icc t₀ t₁ ×ˢ Icc a b)) + (hs : ∀ t ∈ Icc t₀ t₁, Continuous (u t)) + (ht : ∀ t ∈ Ioc t₀ t₁, ∀ x ∈ Ioo a b, + HasDerivWithinAt (fun s => u s x) (ut t x) (Icc t₀ t₁) t) + (hx : ∀ t ∈ Ioc t₀ t₁, ∀ x ∈ Ioo a b, HasDerivAt (u t) (ux t x) x) + (hxx : ∀ t ∈ Ioc t₀ t₁, ∀ x ∈ Ioo a b, + HasDerivAt (deriv (u t)) (uxx t x) x) + (hk : ∀ t ∈ Ioc t₀ t₁, ∀ x ∈ Ioo a b, 0 ≤ κ t x) + (hbound : ∀ t ∈ Ioc t₀ t₁, ∀ x ∈ Ioo a b, c t x ≤ C) + (hpde : ∀ t ∈ Ioc t₀ t₁, ∀ x ∈ Ioo a b, + 0 ≤ ut t x - κ t x * uxx t x - β t x * ux t x - c t x * u t x) + (hinit : ∀ x ∈ Icc a b, 0 ≤ u t₀ x) + (hleft : ∀ t ∈ Icc t₀ t₁, -ε ≤ u t a) + (hright : ∀ t ∈ Icc t₀ t₁, -ε ≤ u t b) : + ∀ t ∈ Icc t₀ t₁, ∀ x ∈ Icc a b, + -ε * Real.exp ((max C 0 + 1) * (t - t₀)) ≤ u t x := by + let k := max C 0 + 1 + let E := fun t : ℝ => Real.exp (-k * (t-t₀)) + let V := fun t x => E t * u t x + ε + have hEpos : ∀ t, 0 < E t := fun _ => Real.exp_pos _ + have hkpos : 0 < k := by dsimp [k]; linarith [le_max_right C 0] + have hEderiv : ∀ t, HasDerivAt E (-k * E t) t := by + intro t + convert! ((((hasDerivAt_id t).sub_const t₀).const_mul (-k)).exp) using 1 + dsimp [E, id] + ring + have hEle : ∀ t ∈ Icc t₀ t₁, E t ≤ 1 := by + intro t ht + apply Real.exp_le_one_iff.mpr + exact mul_nonpos_of_nonpos_of_nonneg (neg_nonpos.mpr hkpos.le) (sub_nonneg.mpr ht.1) + have hVcont : ContinuousOn (fun p : ℝ × ℝ => V p.1 p.2) (Icc t₀ t₁ ×ˢ Icc a b) := by + exact (((show Continuous (fun p : ℝ × ℝ => E p.1) by dsimp [E]; fun_prop).continuousOn).mul hc).add_const ε + have hVs : ∀ t ∈ Icc t₀ t₁, Continuous (V t) := by + intro t ht + exact ((hs t ht).const_mul (E t)).add_const ε + have hVt : ∀ t ∈ Ioc t₀ t₁, ∀ x ∈ Ioo a b, + HasDerivWithinAt (fun s => V s x) (E t * (ut t x - k * u t x)) (Icc t₀ t₁) t := by + intro t htmem x hxmem + convert! (((hEderiv t).hasDerivWithinAt.mul (ht t htmem x hxmem)).add_const ε) using 1 + ring + have hVx : ∀ t ∈ Ioc t₀ t₁, ∀ x ∈ Ioo a b, + HasDerivAt (V t) (E t * ux t x) x := by + intro t htmem x hxmem + exact ((hx t htmem x hxmem).const_mul (E t)).add_const ε + have hVxx : ∀ t ∈ Ioc t₀ t₁, ∀ x ∈ Ioo a b, + HasDerivAt (deriv (V t)) (E t * uxx t x) x := by + intro t htmem x hxmem + have heq : deriv (V t) = fun x => E t * deriv (u t) x := by + funext x + simp only [V, deriv_add_const, deriv_const_mul_field] + rw [heq] + exact (hxx t htmem x hxmem).const_mul (E t) + have hl : ∀ t ∈ Ioc t₀ t₁, ∀ x ∈ Ioo a b, 0 < k - c t x := by + intro t htmem x hxmem + have := hbound t htmem x hxmem + dsimp [k] + linarith [le_max_left C 0] + have hVpde : ∀ t ∈ Ioc t₀ t₁, ∀ x ∈ Ioo a b, + 0 ≤ E t * (ut t x - k * u t x) - κ t x * (E t * uxx t x) - + β t x * (E t * ux t x) + (k-c t x) * V t x := by + intro t htmem x hxmem + have h1 := mul_nonneg (hEpos t).le (hpde t htmem x hxmem) + have h2 := mul_nonneg (hl t htmem x hxmem).le hε + dsimp [V] + nlinarith + have hVinit : ∀ x ∈ Icc a b, 0 ≤ V t₀ x := by + intro x hxmem + exact add_nonneg (mul_nonneg (hEpos t₀).le (hinit x hxmem)) hε + have boundary : ∀ t ∈ Icc t₀ t₁, ∀ z, -ε ≤ u t z → 0 ≤ V t z := by + intro t htmem z hz + have h1 := mul_le_mul_of_nonneg_left hz (hEpos t).le + have h2 := mul_le_mul_of_nonneg_right (hEle t htmem) hε + dsimp [V] + nlinarith + have hnonneg := nonnegative_of_parabolic_inequality hVcont hVs hVt hVx hVxx hk hl hVpde + hVinit (fun t ht => boundary t ht a (hleft t ht)) (fun t ht => boundary t ht b (hright t ht)) + intro t htmem x hxmem + have hv := hnonneg t htmem x hxmem + have hinv : E t * Real.exp (k * (t-t₀)) = 1 := by + dsimp [E] + rw [← Real.exp_add, neg_mul, neg_add_cancel, Real.exp_zero] + apply (mul_le_mul_iff_right₀ (hEpos t)).mp + change E t * (-ε * Real.exp (k * (t-t₀))) ≤ E t * u t x + calc + E t * (-ε * Real.exp (k * (t-t₀))) = -ε := by nlinarith [hinv] + _ ≤ E t * u t x := by dsimp [V] at hv; linarith + +end ZeroTemperatureSK.Parabolic + +end + +end OAI diff --git a/lean/OAI/Probability/SKSupport/Parabolic/ForwardGeometry.lean b/lean/OAI/Probability/SKSupport/Parabolic/ForwardGeometry.lean new file mode 100644 index 0000000000000000000000000000000000000000..b999e9a2a0ccf399787e06dbea657f05c3d10c93 --- /dev/null +++ b/lean/OAI/Probability/SKSupport/Parabolic/ForwardGeometry.lean @@ -0,0 +1,88 @@ +import Mathlib +import OAI.Probability.SKSupport.Backward.Backward + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology ContDiff +noncomputable section +namespace ZeroTemperatureSK.Heat + +def forwardTime (a t : ℝ) : ℝ := a+max t 0 +def forwardScale (a t : ℝ) : ℝ := a/forwardTime a t +def forwardVariance (a t : ℝ) : ℝ := a*max t 0/forwardTime a t + +def forwardCorrection (a : ℝ) (f : ℝ → ℝ) (t x : ℝ) : ℝ := + (1/2:ℝ)*Real.log (forwardScale a t)+ + varianceLogHeat 1 (forwardVariance a t) f (forwardScale a t*x) + +def forwardScore (a : ℝ) (f : ℝ → ℝ) (t x : ℝ) : ℝ := + x/forwardTime a t-deriv (forwardCorrection a f t) x + +lemma forwardTime_pos {a : ℝ} (ha : 0 < a) (t : ℝ) : 0 < forwardTime a t := + add_pos_of_pos_of_nonneg ha (le_max_right _ _) + +lemma forwardScale_pos {a : ℝ} (ha : 0 < a) (t : ℝ) : 0 < forwardScale a t := + div_pos ha (forwardTime_pos ha t) + +lemma forwardScale_le_one {a : ℝ} (ha : 0 < a) (t : ℝ) : forwardScale a t ≤ 1 := by + apply (div_le_one (forwardTime_pos ha t)).mpr + exact le_add_of_nonneg_right (le_max_right _ _) + +lemma forwardVariance_nonneg {a : ℝ} (ha : 0 < a) (t : ℝ) : 0 ≤ forwardVariance a t := + div_nonneg (mul_nonneg ha.le (le_max_right _ _)) (forwardTime_pos ha t).le + +lemma forwardVariance_le {a : ℝ} (ha : 0 < a) (t : ℝ) : forwardVariance a t ≤ a := by + apply (div_le_iff₀ (forwardTime_pos ha t)).mpr + try dsimp [forwardTime] + nlinarith [sq_nonneg a] + +lemma continuous_forwardTime (a : ℝ) : Continuous (forwardTime a) := + continuous_const.add (continuous_id.max continuous_const) +lemma continuous_forwardScale {a : ℝ} (ha : 0 < a) : Continuous (forwardScale a) := + continuous_const.div (continuous_forwardTime a) (fun t => ne_of_gt (forwardTime_pos ha t)) +lemma continuous_forwardVariance {a : ℝ} (ha : 0 < a) : Continuous (forwardVariance a) := + (continuous_const.mul (continuous_id.max continuous_const)).div (continuous_forwardTime a) + (fun t => ne_of_gt (forwardTime_pos ha t)) + +lemma hasDerivAt_forwardTime {a t : ℝ} (ht : 0 < t) : HasDerivAt (forwardTime a) 1 t := by + apply ((hasDerivAt_id t).const_add a).congr_of_eventuallyEq + filter_upwards [Ioi_mem_nhds ht] with s hs + simp only [forwardTime,max_eq_left (show (0:ℝ) ≤ s from le_of_lt hs),id_eq] + +lemma hasDerivAt_forwardScale {a t : ℝ} (ha : 0 < a) (ht : 0 < t) : + HasDerivAt (forwardScale a) (-forwardScale a t/forwardTime a t) t := by + convert (hasDerivAt_const t a).div (hasDerivAt_forwardTime ht) (ne_of_gt (forwardTime_pos ha t)) using 1 <;> + first | rfl | (dsimp [forwardScale]; field_simp; ring) + +lemma hasDerivAt_forwardVariance {a t : ℝ} (ha : 0 < a) (ht : 0 < t) : + HasDerivAt (forwardVariance a) ((forwardScale a t)^2) t := by + have he : forwardVariance a = fun s => a-a*forwardScale a s := by + funext s + dsimp [forwardVariance,forwardScale] + field_simp [ne_of_gt (forwardTime_pos ha s)] + dsimp [forwardTime] + ring + rw [he] + convert ((hasDerivAt_forwardScale ha ht).const_mul a).const_sub a using 1 + dsimp [forwardScale] + field_simp + +lemma forwardVariance_pos {a t : ℝ} (ha : 0 < a) (ht : 0 < t) : 0 < forwardVariance a t := by + exact div_pos (mul_pos ha (lt_of_lt_of_le ht (le_max_left _ _))) (forwardTime_pos ha t) + +lemma forwardCorrection_terminal (a : ℝ) (ha : a ≠ 0) (f : ℝ → ℝ) : + forwardCorrection a f 0 = f := by + have he : varianceLogHeat 1 0 f = f := funext (fun x => by + simpa only [backward,sub_self] using backward_terminal 1 0 f x) + funext x + simp only [forwardCorrection,forwardScale,forwardVariance,forwardTime,max_self,add_zero, + mul_zero,zero_div,div_self ha,Real.log_one,mul_zero,zero_add,one_mul,he] + +end ZeroTemperatureSK.Heat + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKSupport/Parabolic/ForwardRegularity.lean b/lean/OAI/Probability/SKSupport/Parabolic/ForwardRegularity.lean new file mode 100644 index 0000000000000000000000000000000000000000..4f217d0a803971444f612f9e3416b33f7d7f8032 --- /dev/null +++ b/lean/OAI/Probability/SKSupport/Parabolic/ForwardRegularity.lean @@ -0,0 +1,250 @@ +import Mathlib +import OAI.Probability.SKSupport.Regularity.GaussianFlowRegularity +import OAI.Probability.SKSupport.Moments.FamilyReparam +import OAI.Probability.SKSupport.Parabolic.ForwardGeometry +import OAI.Probability.SKSupport.Regularity.GaussianValueContinuity + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology ContDiff +noncomputable section +namespace ZeroTemperatureSK.Heat + +lemma forwardCorrection_smooth {a : ℝ} {f : ℝ → ℝ} {K : ℝ≥0} + (hf : RegularDatum f) (hLip : LipschitzWith K f) (t : ℝ) : + ContDiff ℝ ∞ (forwardCorrection a f t) := by + exact contDiff_const.add ((regularDatum_varianceLogHeat hf hLip (by norm_num : (0:ℝ)≤1) _).smooth.comp + (contDiff_const.mul contDiff_id)) + +lemma forwardCorrection_deriv {a : ℝ} {f : ℝ → ℝ} {K : ℝ≥0} + (hf : RegularDatum f) (hLip : LipschitzWith K f) (t x : ℝ) : + deriv (forwardCorrection a f t) x = forwardScale a t* + deriv (varianceLogHeat 1 (forwardVariance a t) f) (forwardScale a t*x) := by + have hs := ((regularDatum_varianceLogHeat hf hLip (by norm_num : (0:ℝ)≤1) (forwardVariance a t)).smooth.differentiable + (by simp) (forwardScale a t*x)).hasDerivAt + have hd := (hs.comp x ((hasDerivAt_id x).const_mul (forwardScale a t))).const_add + ((1/2:ℝ)*Real.log (forwardScale a t)) + convert hd.deriv using 1 <;> first | rfl | ring + +lemma forwardGradient_family {a : ℝ} (ha : 0 < a) {f : ℝ → ℝ} {K : ℝ≥0} + (hf : RegularDatum f) (hLip : LipschitzWith K f) : + BoundedSmoothFamily (fun t => deriv (forwardCorrection a f t)) := by + have hb (t) : |forwardScale a t| ≤ (1:ℝ≥0) := by + rw [abs_of_pos (forwardScale_pos ha t)] + exact forwardScale_le_one ha t + have hh := ((varianceGradient_family hf hLip (by norm_num : (0:ℝ)≤1)).reparam + (continuous_forwardVariance ha).measurable (continuous_forwardScale ha).measurable hb).timeMul + (continuous_forwardScale ha).measurable hb + convert hh using 1 + funext t x + exact forwardCorrection_deriv hf hLip t x + +lemma forwardCorrection_regular {a : ℝ} (ha : 0 < a) {f : ℝ → ℝ} {K : ℝ≥0} + (hf : RegularDatum f) (hLip : LipschitzWith K f) (t : ℝ) : + RegularDatum (forwardCorrection a f t) := + ⟨forwardCorrection_smooth hf hLip t,(forwardGradient_family ha hf hLip).regular t⟩ + +lemma forwardCorrection_jet {a : ℝ} {f : ℝ → ℝ} {K : ℝ≥0} + (hf : RegularDatum f) (hLip : LipschitzWith K f) (n : ℕ) (t x : ℝ) : + iteratedDeriv (n+1) (forwardCorrection a f t) x = (forwardScale a t)^(n+1)* + iteratedDeriv (n+1) (varianceLogHeat 1 (forwardVariance a t) f) (forwardScale a t*x) := by + have hg := (regularDatum_varianceLogHeat hf hLip (by norm_num : (0:ℝ)≤1) (forwardVariance a t)).deriv_bounded.smooth + have he : deriv (forwardCorrection a f t) = fun x => forwardScale a t* + deriv (varianceLogHeat 1 (forwardVariance a t) f) (forwardScale a t*x) := + funext (forwardCorrection_deriv hf hLip t) + rw [iteratedDeriv_succ',he,iteratedDeriv_const_mul_field,scaled_composition_jet hg] + rw [← iteratedDeriv_succ'] + ring + +lemma forwardCorrection_continuous {a : ℝ} (ha : 0 < a) {f : ℝ → ℝ} {K : ℝ≥0} + (hf : RegularDatum f) (hLip : LipschitzWith K f) : + Continuous (fun p : ℝ × ℝ => forwardCorrection a f p.1 p.2) := by + exact (continuous_const.mul (((continuous_forwardScale ha).comp continuous_fst).log + (fun p => ne_of_gt (forwardScale_pos ha p.1)))).add + ((varianceLogHeat_joint_continuous hf hLip (by norm_num : (0:ℝ)≤1)).comp + (((continuous_forwardVariance ha).comp continuous_fst).prodMk + (((continuous_forwardScale ha).comp continuous_fst).mul continuous_snd))) + +lemma forwardGradient_continuous {a : ℝ} (ha : 0 < a) {f : ℝ → ℝ} {K : ℝ≥0} + (hf : RegularDatum f) (hLip : LipschitzWith K f) : + Continuous (fun p : ℝ × ℝ => deriv (forwardCorrection a f p.1) p.2) := by + obtain ⟨C,hC⟩ := (forwardGradient_family ha hf hLip).deriv.bound + have hh := continuousOn_deriv_family + (S := Set.univ) (forwardCorrection_continuous ha hf hLip).continuousOn + (fun t _ => (forwardCorrection_smooth hf hLip t).of_le + (ENat.natCast_le_of_coe_top_le_withTop le_rfl 2)) C.coe_nonneg (fun t _ x => hC t x) + exact continuousOn_univ.mp (by simpa only [univ_prod_univ] using hh) + +lemma forwardCorrection_even {a : ℝ} {f : ℝ → ℝ} {K : ℝ≥0} + (hf : RegularDatum f) (hLip : LipschitzWith K f) (he : Function.Even f) (t : ℝ) : + Function.Even (forwardCorrection a f t) := by + have heq : varianceLogHeat 1 (forwardVariance a t) f = + logSemigroup 1 (Real.toNNReal (forwardVariance a t)) f := + funext (varianceLogHeat_eq_logSemigroup_toNNReal hLip.continuous.measurable 1 _) + have hEven := logSemigroup_even hf.smooth.continuous.measurable he 1 (Real.toNNReal (forwardVariance a t)) + intro x + simp only [forwardCorrection,heq,mul_neg] + rw [hEven] + +def forwardCorrectionRate (a : ℝ) (f : ℝ → ℝ) (t x : ℝ) : ℝ := + (1/2:ℝ)*iteratedDeriv 2 (forwardCorrection a f t) x+ + (1/2:ℝ)*(deriv (forwardCorrection a f t) x)^2- + (x/forwardTime a t)*deriv (forwardCorrection a f t) x- + (1/2:ℝ)/forwardTime a t + +lemma hasDerivAt_forwardCorrection {a t : ℝ} (ha : 0 < a) {f : ℝ → ℝ} {K : ℝ≥0} + (hf : RegularDatum f) (hLip : LipschitzWith K f) (ht : 0 < t) (x : ℝ) : + HasDerivAt (fun s => forwardCorrection a f s x) (forwardCorrectionRate a f t x) t := by + have hh := hasDerivAt_varianceLogHeat_curve hf hLip 1 (hasDerivAt_forwardVariance ha ht) + ((hasDerivAt_forwardScale ha ht).mul_const x) (forwardVariance_pos ha ht) + have hl := ((hasDerivAt_forwardScale ha ht).log (ne_of_gt (forwardScale_pos ha t))).const_mul (1/2:ℝ) + convert hl.add hh using 1 <;> first | rfl | skip + rw [forwardCorrectionRate,forwardCorrection_jet hf hLip 1,forwardCorrection_deriv hf hLip] + simp only [iteratedDeriv_succ,iteratedDeriv_zero] + field_simp [ne_of_gt (forwardTime_pos ha t),ne_of_gt (forwardScale_pos ha t)] + ring + +end ZeroTemperatureSK.Heat + +end +end +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology ContDiff +noncomputable section +namespace ZeroTemperatureSK.Heat + +def AffineSmoothFamily (F : ℝ → ℝ → ℝ) : Prop := + ∃ A B : ℝ → ℝ → ℝ, BoundedSmoothFamily A ∧ + Continuous (fun p : ℝ × ℝ => A p.1 p.2) ∧ BoundedSmoothFamily B ∧ + Continuous (fun p : ℝ × ℝ => B p.1 p.2) ∧ F = fun t x => A t x+x*B t x + +lemma BoundedSmoothFamily.continuous_iteratedDeriv {F : ℝ → ℝ → ℝ} + (hF : BoundedSmoothFamily F) (hc : Continuous (fun p : ℝ × ℝ => F p.1 p.2)) (n : ℕ) : + Continuous (fun p : ℝ × ℝ => _root_.iteratedDeriv n (F p.1) p.2) := by + exact continuousOn_univ.mp (by simpa only [univ_prod_univ] using + hF.continuousOn_iteratedDeriv (S := univ) hc.continuousOn n) + +lemma BoundedSmoothFamily.affine {F : ℝ → ℝ → ℝ} + (hF : BoundedSmoothFamily F) (hc : Continuous (fun p : ℝ × ℝ => F p.1 p.2)) : + AffineSmoothFamily F := by + refine ⟨F,fun _ _ => 0,hF,hc,BoundedSmoothFamily.timeConst (C := 0) measurable_const + (fun _ => by simp),continuous_const,?_⟩ + funext t x + simp + +lemma BoundedSmoothFamily.affine_id_mul {F : ℝ → ℝ → ℝ} + (hF : BoundedSmoothFamily F) (hc : Continuous (fun p : ℝ × ℝ => F p.1 p.2)) : + AffineSmoothFamily (fun t x => x*F t x) := by + refine ⟨fun _ _ => 0,F,BoundedSmoothFamily.timeConst (C := 0) measurable_const + (fun _ => by simp),continuous_const,hF,hc,?_⟩ + funext t x + simp + +lemma AffineSmoothFamily.add {F G : ℝ → ℝ → ℝ} + (hF : AffineSmoothFamily F) (hG : AffineSmoothFamily G) : + AffineSmoothFamily (fun t x => F t x+G t x) := by + obtain ⟨A,B,hA,hAc,hB,hBc,rfl⟩ := hF + obtain ⟨C,D,hC,hCc,hD,hDc,rfl⟩ := hG + refine ⟨fun t x => A t x+C t x,fun t x => B t x+D t x,hA.add hC,hAc.add hCc, + hB.add hD,hBc.add hDc,?_⟩ + funext t x + ring + +lemma AffineSmoothFamily.const_mul {F : ℝ → ℝ → ℝ} + (hF : AffineSmoothFamily F) (c : ℝ) : AffineSmoothFamily (fun t x => c*F t x) := by + obtain ⟨A,B,hA,hAc,hB,hBc,rfl⟩ := hF + refine ⟨fun t x => c*A t x,fun t x => c*B t x,hA.const_mul c,hAc.const_mul c, + hB.const_mul c,hBc.const_mul c,?_⟩ + funext t x + ring + +lemma AffineSmoothFamily.continuous {F : ℝ → ℝ → ℝ} (hF : AffineSmoothFamily F) : + Continuous (fun p : ℝ × ℝ => F p.1 p.2) := by + obtain ⟨A,B,hA,hAc,hB,hBc,rfl⟩ := hF + exact hAc.add (continuous_snd.mul hBc) + +lemma AffineSmoothFamily.smooth {F : ℝ → ℝ → ℝ} (hF : AffineSmoothFamily F) (t : ℝ) : + ContDiff ℝ ∞ (F t) := by + obtain ⟨A,B,hA,hAc,hB,hBc,rfl⟩ := hF + exact (hA.regular t).smooth.add (contDiff_id.mul (hB.regular t).smooth) + +lemma AffineSmoothFamily.deriv {F : ℝ → ℝ → ℝ} (hF : AffineSmoothFamily F) : + AffineSmoothFamily (fun t => _root_.deriv (F t)) := by + obtain ⟨A,B,hA,hAc,hB,hBc,rfl⟩ := hF + have hdA : Continuous (fun p : ℝ × ℝ => _root_.deriv (A p.1) p.2) := by + simpa only [iteratedDeriv_one] using hA.continuous_iteratedDeriv hAc 1 + have hdB : Continuous (fun p : ℝ × ℝ => _root_.deriv (B p.1) p.2) := by + simpa only [iteratedDeriv_one] using hB.continuous_iteratedDeriv hBc 1 + refine ⟨fun t x => _root_.deriv (A t) x+B t x,fun t => _root_.deriv (B t), + hA.deriv.add hB,hdA.add hBc,hB.deriv,hdB,?_⟩ + funext t x + have hh := ((hA.regular t).smooth.differentiable (by simp) x).hasDerivAt.add + ((hasDerivAt_id x).mul ((hB.regular t).smooth.differentiable (by simp) x).hasDerivAt) + convert hh.deriv using 1 <;> first | rfl | (simp only [id_eq];ring) + +lemma AffineSmoothFamily.iteratedDeriv {F : ℝ → ℝ → ℝ} + (hF : AffineSmoothFamily F) (n : ℕ) : + AffineSmoothFamily (fun t => _root_.iteratedDeriv n (F t)) := by + induction n with + | zero => exact hF + | succ n hn => simpa only [iteratedDeriv_succ] using hn.deriv + +lemma AffineSmoothFamily.bound {F : ℝ → ℝ → ℝ} (hF : AffineSmoothFamily F) : + ∃ C : ℝ, 0 ≤ C ∧ ∀ t x, |F t x| ≤ C*(1+|x|) := by + obtain ⟨A,B,hA,hAc,hB,hBc,rfl⟩ := hF + obtain ⟨C,hC⟩ := hA.bound + obtain ⟨D,hD⟩ := hB.bound + refine ⟨C+D, by positivity,fun t x => ?_⟩ + apply (abs_add_le _ _).trans + rw [abs_mul] + have hh := mul_le_mul_of_nonneg_left (hD t x) (abs_nonneg x) + nlinarith [hC t x,mul_nonneg C.coe_nonneg (abs_nonneg x)] + +lemma AffineSmoothFamily.intervalIntegrable {F : ℝ → ℝ → ℝ} + (hF : AffineSmoothFamily F) (x a b : ℝ) : + IntervalIntegrable (fun t => F t x) volume a b := + (hF.continuous.comp (continuous_id.prodMk continuous_const)).intervalIntegrable _ _ + +lemma AffineSmoothFamily.hasDerivAt_integral {F : ℝ → ℝ → ℝ} + (hF : AffineSmoothFamily F) (a b x : ℝ) : + HasDerivAt (fun z => ∫ t in a..b, F t z) (∫ t in a..b, _root_.deriv (F t) x) x := by + obtain ⟨C,hC,hbound⟩ := hF.deriv.bound + refine (intervalIntegral.hasDerivAt_integral_of_dominated_loc_of_deriv_le + (F := fun z t => F t z) (F' := fun z t => _root_.deriv (F t) z) + (bound := fun _ => C*(2+|x|)) (s := Metric.ball x 1) (Metric.ball_mem_nhds x zero_lt_one) + (Eventually.of_forall (fun z => (hF.continuous.comp + (continuous_id.prodMk continuous_const)).aestronglyMeasurable)) + (hF.intervalIntegrable x a b) ((hF.deriv.continuous.comp + (continuous_id.prodMk continuous_const)).aestronglyMeasurable) ?_ + (intervalIntegrable_const) ?_).2 + · filter_upwards [] with t ht z hz + have hz' : |z-x| < 1 := by simpa only [Metric.mem_ball,Real.dist_eq] using hz + have habs : |z| ≤ 1+|x| := by + have hh := abs_add_le (z-x) x + rw [sub_add_cancel] at hh + linarith + exact (hbound t z).trans (by nlinarith) + · filter_upwards [] with t ht z hz + exact ((hF.smooth t).differentiable (by simp) z).hasDerivAt + +lemma AffineSmoothFamily.iteratedDeriv_integral {F : ℝ → ℝ → ℝ} + (hF : AffineSmoothFamily F) (n : ℕ) (a b x : ℝ) : + _root_.iteratedDeriv n (fun z => ∫ t in a..b, F t z) x = + ∫ t in a..b, _root_.iteratedDeriv n (F t) x := by + induction n generalizing x with + | zero => rfl + | succ n hn => + have he : _root_.iteratedDeriv n (fun z => ∫ t in a..b, F t z) = + fun z => ∫ t in a..b, _root_.iteratedDeriv n (F t) z := funext hn + rw [iteratedDeriv_succ,he] + simpa only [iteratedDeriv_succ] using ((hF.iteratedDeriv n).hasDerivAt_integral a b x).deriv + +end ZeroTemperatureSK.Heat + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKSupport/Parabolic/ForwardSigns.lean b/lean/OAI/Probability/SKSupport/Parabolic/ForwardSigns.lean new file mode 100644 index 0000000000000000000000000000000000000000..ea472bff3c94250911d463ef903f7cd156ce2ffd --- /dev/null +++ b/lean/OAI/Probability/SKSupport/Parabolic/ForwardSigns.lean @@ -0,0 +1,150 @@ +import Mathlib +import OAI.Probability.SKSupport.Diffusion.AffineComparison + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology ContDiff +noncomputable section +namespace ZeroTemperatureSK.Heat +namespace SmoothForward +variable {s : ℝ → ℝ → ℝ} (hs : SmoothForward s) +include hs + +theorem deriv_ge_inverse {a : ℝ} (ha : 0 < a) + (hi : ∀ x, a⁻¹ ≤ deriv (s 0) x) : + ∀ t, 0 ≤ t → ∀ x, (forwardTime a t)⁻¹ ≤ deriv (s t) x := by + let F (t x : ℝ) := deriv (s t) x-(forwardTime a t)⁻¹ + let Ft (t x : ℝ) := deriv (scoreRate s t) x+((forwardTime a t)⁻¹)^2 + have hF : BoundedSmoothFamily F := by + convert hs.deriv_family.add ((inverse_forwardTime_family ha).const_mul (-1)) using 1 + funext t x + simp only [F,neg_one_mul,sub_eq_add_neg] + have hFc : Continuous (fun p : ℝ × ℝ => F p.1 p.2) := + hs.family.deriv.continuous.sub ((inverse_forwardTime_continuous ha).comp continuous_fst) + have hFt (t : ℝ) (ht : 0 < t) (x : ℝ) : HasDerivAt (fun u => F u x) (Ft t x) t := by + have hb := (hasDerivAt_forwardTime (a := a) ht).inv (ne_of_gt (forwardTime_pos ha t)) + convert (hs.time_derivative 1 t ht x).sub hb using 1 <;> + first | rfl | ((try funext u); simp only [F,Ft,iteratedDeriv_one,Pi.sub_apply,Pi.inv_apply] <;> ring) + have hFx (t x : ℝ) : deriv (F t) x=iteratedDeriv 2 (s t) x := by + simpa only [F,iteratedDeriv_one] using ((hs.jet_spatial 1 t x).sub_const ((forwardTime a t)⁻¹)).deriv + have hFxx (t x : ℝ) : iteratedDeriv 2 (F t) x=iteratedDeriv 3 (s t) x := by + rw [iteratedDeriv_succ (n := 1),iteratedDeriv_one,show deriv (F t)=iteratedDeriv 2 (s t) from funext (hFx t)] + exact (hs.jet_spatial 2 t x).deriv + have hβ : AffineSmoothFamily (fun t x => -s t x) := by + simpa only [neg_one_mul] using hs.family.const_mul (-1) + obtain ⟨V,hV⟩ := hs.deriv_family.bound + have hh := affineDrift_nonnegative_full hF hβ hFc hFt + (c := fun t x => -(deriv (s t) x+(forwardTime a t)⁻¹)) (C := (V:ℝ)) + (fun t ht x => ?_) (fun t ht x => ?_) (fun x => ?_) + · intro t ht x + exact sub_nonneg.mp (hh t ht x) + · have hb := inv_pos.mpr (forwardTime_pos ha t) + have hv := (neg_abs_le (deriv (s t) x)).trans' (neg_le_neg (hV t x)) + linarith + · rw [hFx,hFxx] + dsimp only [Ft,F] + rw [hs.rate_deriv] + ring + · simpa only [F,forwardTime,max_self,add_zero] using sub_nonneg.mpr (hi x) + +theorem second_nonpos (ho : ∀ t, Function.Odd (s t)) + (hi : ∀ x, 0 ≤ x → iteratedDeriv 2 (s 0) x ≤ 0) : + ∀ t, 0 ≤ t → ∀ x, 0 ≤ x → iteratedDeriv 2 (s t) x ≤ 0 := by + let F (t x : ℝ) := -iteratedDeriv 2 (s t) x + have hF : BoundedSmoothFamily F := by + simpa only [neg_one_mul] using (hs.jet_family 1).const_mul (-1) + have hFc : Continuous (fun p : ℝ × ℝ => F p.1 p.2) := (hs.jet_continuous 2).neg + have hFx (t x : ℝ) : deriv (F t) x= -iteratedDeriv 3 (s t) x := + ((hs.jet_spatial 2 t x).neg).deriv + have hFxx (t x : ℝ) : iteratedDeriv 2 (F t) x= -iteratedDeriv 4 (s t) x := by + rw [iteratedDeriv_succ (n := 1),iteratedDeriv_one,show deriv (F t)=(fun x => -iteratedDeriv 3 (s t) x) from funext (hFx t)] + exact ((hs.jet_spatial 3 t x).neg).deriv + have hβ : AffineSmoothFamily (fun t x => -s t x) := by + simpa only [neg_one_mul] using hs.family.const_mul (-1) + obtain ⟨V,hV⟩ := hs.deriv_family.bound + have hh := affineDrift_nonnegative_half hF hβ hFc + (fun t ht x => (hs.time_derivative 2 t ht x).neg) + (c := fun t x => -3*deriv (s t) x) (C := 3*(V:ℝ)) + (fun t ht x hx => ?_) (fun t ht x hx => ?_) (fun t ht => ?_) (fun x hx => neg_nonneg.mpr (hi x hx)) + · intro t ht x hx + exact neg_nonneg.mp (hh t ht x hx) + · have hv := (neg_abs_le (deriv (s t) x)).trans' (neg_le_neg (hV t x)) + linarith + · rw [hFx,hFxx,hs.rate_jet2] + dsimp only [F] + ring + · have hz := hs.second_odd ho t 0 + simp only [neg_zero] at hz + dsimp [F] + linarith + +end SmoothForward +end ZeroTemperatureSK.Heat + +end +end +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology ContDiff +noncomputable section +namespace ZeroTemperatureSK.Heat + +structure ForwardDatumShape (f : ℝ → ℝ) : Prop where + even : Function.Even f + second : ∀ x, iteratedDeriv 2 f x ≤ 0 + third : ∀ x, 0 ≤ x → 0 ≤ iteratedDeriv 3 f x + +lemma forwardCorrection_shape {a : ℝ} (ha : 0 < a) {f : ℝ → ℝ} {K : ℝ≥0} + (hf : RegularDatum f) (hLip : LipschitzWith K f) (hshape : ForwardDatumShape f) + {t : ℝ} (ht : 0 ≤ t) : ForwardDatumShape (forwardCorrection a f t) := by + have hi (x : ℝ) : a⁻¹ ≤ deriv (forwardScore a f 0) x := by + rw [forwardScore_deriv hf hLip,forwardCorrection_terminal a (ne_of_gt ha),forwardTime] + simp only [max_self,add_zero] + linarith [hshape.second x] + have hge := (forwardScore_smooth ha hf hLip).deriv_ge_inverse ha hi t ht + have h₂ : ∀ x, iteratedDeriv 2 (forwardCorrection a f t) x ≤ 0 := by + intro x + have hh := hge x + rw [forwardScore_deriv hf hLip] at hh + linarith + have hi₂ (x : ℝ) (hx : 0 ≤ x) : iteratedDeriv 2 (forwardScore a f 0) x ≤ 0 := by + rw [forwardScore_second hf hLip,forwardCorrection_terminal a (ne_of_gt ha)] + exact neg_nonpos.mpr (hshape.third x hx) + have hle := (forwardScore_smooth ha hf hLip).second_nonpos (forwardScore_odd hf hLip hshape.even) hi₂ t ht + refine ⟨forwardCorrection_even hf hLip hshape.even t,h₂,fun x hx => ?_⟩ + have hh := hle x hx + rw [forwardScore_second hf hLip] at hh + exact neg_nonpos.mp hh + +lemma ForwardDatumShape.const (c : ℝ) : ForwardDatumShape (fun _ : ℝ => c) := by + refine ⟨fun _ => rfl,fun x => ?_,fun x hx => ?_⟩ <;> simp [iteratedDeriv_const] + +lemma ForwardDatumShape.jump {f φ : ℝ → ℝ} (hf : ContDiff ℝ ∞ f) + (hφ : ContDiff ℝ ∞ φ) (hshape : ForwardDatumShape f) (heφ : Function.Even φ) + (hv : ∀ x, 0 ≤ iteratedDeriv 2 φ x) (hw : ∀ x, 0 ≤ x → iteratedDeriv 3 φ x ≤ 0) + {δ : ℝ} (hδ : 0 ≤ δ) : ForwardDatumShape (fun x => f x-δ*φ x) := by + have hj (n : ℕ) (x : ℝ) : iteratedDeriv n (fun x => f x-δ*φ x) x = + iteratedDeriv n f x-δ*iteratedDeriv n φ x := by + rw [iteratedDeriv_fun_sub (n := n) + (hf.of_le (ENat.natCast_le_of_coe_top_le_withTop le_rfl n) |>.contDiffAt) + ((contDiff_const.mul hφ).of_le (ENat.natCast_le_of_coe_top_le_withTop le_rfl n) |>.contDiffAt), + iteratedDeriv_const_mul_field] + refine ⟨?_,?_,?_⟩ + · intro x + change f (-x) - δ * φ (-x) = f x - δ * φ x + rw [hshape.even x,heφ x] + · intro x + rw [hj] + linarith [hshape.second x,mul_nonneg hδ (hv x)] + · intro x hx + rw [hj] + linarith [hshape.third x hx,mul_nonpos_of_nonneg_of_nonpos hδ (hw x hx)] + +end ZeroTemperatureSK.Heat + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKSupport/Parabolic/FullLineComparison.lean b/lean/OAI/Probability/SKSupport/Parabolic/FullLineComparison.lean new file mode 100644 index 0000000000000000000000000000000000000000..061463b341bc2dfd927d2f28e07ea9f2b5c88b8c --- /dev/null +++ b/lean/OAI/Probability/SKSupport/Parabolic/FullLineComparison.lean @@ -0,0 +1,238 @@ +import Mathlib +import OAI.Probability.SKSupport.Parabolic.ForwardConstruction + +namespace OAI + +section +open Set Filter +open scoped Topology +noncomputable section +namespace ZeroTemperatureSK.Parabolic + +theorem nonnegative_fullLine_bounded + {u ut ux uxx β c : ℝ → ℝ → ℝ} {t₀ t₁ C K M : ℝ} + (hK : 0 ≤ K) (hM : 0 ≤ M) + (hc : ContinuousOn (fun p : ℝ × ℝ => u p.1 p.2) (Icc t₀ t₁ ×ˢ univ)) + (hs : ∀ t ∈ Icc t₀ t₁, Continuous (u t)) + (ht : ∀ t ∈ Ioc t₀ t₁, ∀ x, + HasDerivWithinAt (fun s => u s x) (ut t x) (Icc t₀ t₁) t) + (hx : ∀ t ∈ Ioc t₀ t₁, ∀ x, HasDerivAt (u t) (ux t x) x) + (hxx : ∀ t ∈ Ioc t₀ t₁, ∀ x, + HasDerivAt (deriv (u t)) (uxx t x) x) + (hb : ∀ t ∈ Ioc t₀ t₁, ∀ x, β t x*x ≤ K*(1+x^2)) + (hbound : ∀ t ∈ Ioc t₀ t₁, ∀ x, c t x ≤ C) + (hpde : ∀ t ∈ Ioc t₀ t₁, ∀ x, + 0 ≤ ut t x-(1/2:ℝ)*uxx t x-β t x*ux t x-c t x*u t x) + (hlower : ∀ t ∈ Icc t₀ t₁, ∀ x, -M ≤ u t x) + (hinit : ∀ x, 0 ≤ u t₀ x) : + ∀ t ∈ Icc t₀ t₁, ∀ x, 0 ≤ u t x := by + let k := max C 0+2*K+2 + let E (t : ℝ) := Real.exp (-k*(t-t₀)) + have hk : 0 < k := by dsimp [k]; linarith [le_max_right C 0] + have hEp (t : ℝ) : 0 < E t := Real.exp_pos _ + have hEd (t : ℝ) : HasDerivAt E (-k*E t) t := by + convert ((((hasDerivAt_id t).sub_const t₀).const_mul (-k)).exp) using 1 <;> dsimp [E,id] + ring + have hEle (t : ℝ) (ht : t ∈ Icc t₀ t₁) : E t ≤ 1 := + Real.exp_le_one_iff.mpr (mul_nonpos_of_nonpos_of_nonneg (neg_nonpos.mpr hk.le) (sub_nonneg.mpr ht.1)) + have hperturb (ε : ℝ) (hε : 0 < ε) (t : ℝ) (htm : t ∈ Icc t₀ t₁) + (x : ℝ) : 0 ≤ E t*u t x+ε*(1+x^2) := by + let A := |x|+M/ε+1 + have hdiv : 0 ≤ M/ε := div_nonneg hM hε.le + have hA : 1 ≤ A := by dsimp [A]; linarith [abs_nonneg x] + have hxA : x ≤ A := by dsimp [A]; linarith [le_abs_self x] + have hAx : -A ≤ x := by dsimp [A]; linarith [neg_abs_le x] + have hAm : M ≤ ε*A := by + have he : ε*(M/ε)=M := by field_simp + dsimp [A] + nlinarith [abs_nonneg x] + have hAb : M ≤ ε*(1+A^2) := by + nlinarith [mul_nonneg hε.le (sq_nonneg (A-1))] + let V (t x : ℝ) := E t*u t x+ε*(1+x^2) + have hVc : ContinuousOn (fun p : ℝ × ℝ => V p.1 p.2) (Icc t₀ t₁ ×ˢ Icc (-A) A) := by + apply ContinuousOn.add + · exact (show Continuous (fun p : ℝ × ℝ => E p.1) by dsimp [E]; fun_prop).continuousOn.mul + (hc.mono (prod_mono subset_rfl (subset_univ _))) + · fun_prop + have hVs (r : ℝ) (hr : r ∈ Icc t₀ t₁) : Continuous (V r) := + ((hs r hr).const_mul (E r)).add (by fun_prop) + have hVt (r : ℝ) (hr : r ∈ Ioc t₀ t₁) (y : ℝ) (hy : y ∈ Ioo (-A) A) : + HasDerivWithinAt (fun s => V s y) (E r*(ut r y-k*u r y)) (Icc t₀ t₁) r := by + convert (((hEd r).hasDerivWithinAt.mul (ht r hr y)).add_const (ε*(1+y^2))) using 1 + ring + have hVx (r : ℝ) (hr : r ∈ Ioc t₀ t₁) (y : ℝ) (hy : y ∈ Ioo (-A) A) : + HasDerivAt (V r) (E r*ux r y+ε*(2*y)) y := by + convert ((hx r hr y).const_mul (E r)).add + ((((hasDerivAt_id y).pow 2).const_add 1).const_mul ε) using 1 <;> first | rfl | ((try simp only [id_eq]); ring) + have hVxx (r : ℝ) (hr : r ∈ Ioc t₀ t₁) (y : ℝ) (hy : y ∈ Ioo (-A) A) : + HasDerivAt (deriv (V r)) (E r*uxx r y+2*ε) y := by + have heloc : deriv (V r) =ᶠ[𝓝 y] (fun z => E r*deriv (u r) z+ε*(2*z)) := by + filter_upwards [Ioo_mem_nhds hy.1 hy.2] with z hz + have hp : HasDerivAt (fun z : ℝ => ε*(1+z^2)) (ε*(2*z)) z := by + convert (((hasDerivAt_id z).pow 2).const_add 1).const_mul ε using 1 <;> first | rfl | ((try simp only [id_eq]); ring) + rw [(hx r hr z).deriv] + exact (((hx r hr z).const_mul (E r)).add hp).deriv + apply HasDerivAt.congr_of_eventuallyEq _ heloc + convert ((hxx r hr y).const_mul (E r)).add + (((hasDerivAt_id y).const_mul 2).const_mul ε) using 1 <;> first | rfl | ring + have hl (r : ℝ) (hr : r ∈ Ioc t₀ t₁) (y : ℝ) (hy : y ∈ Ioo (-A) A) : 0 < k-c r y := by + have hh := hbound r hr y + dsimp [k] + linarith [le_max_left C 0] + have hVp (r : ℝ) (hr : r ∈ Ioc t₀ t₁) (y : ℝ) (hy : y ∈ Ioo (-A) A) : + 0 ≤ E r*(ut r y-k*u r y)-(1/2:ℝ)*(E r*uxx r y+2*ε)- + β r y*(E r*ux r y+ε*(2*y))+(k-c r y)*V r y := by + have hp := mul_nonneg (hEp r).le (hpde r hr y) + have hc' : 2*K+2 ≤ k-c r y := by + have hh := hbound r hr y + dsimp [k] + linarith [le_max_left C 0] + have hprod := mul_le_mul_of_nonneg_right hc' (show 0 ≤ 1+y^2 by positivity) + have hβ := hb r hr y + have hbar : 0 ≤ (k-c r y)*(1+y^2)-1-2*β r y*y := by nlinarith [sq_nonneg y] + have hh := mul_nonneg hε.le hbar + dsimp [V] + nlinarith + have hVi (y : ℝ) (hy : y ∈ Icc (-A) A) : 0 ≤ V t₀ y := by + exact add_nonneg (mul_nonneg (hEp t₀).le (hinit y)) (by positivity) + have hVl (r : ℝ) (hr : r ∈ Icc t₀ t₁) : 0 ≤ V r (-A) := by + have hh := mul_le_mul_of_nonneg_left (hlower r hr (-A)) (hEp r).le + have hh' := mul_le_mul_of_nonneg_right (hEle r hr) hM + dsimp [V] + nlinarith + have hVr (r : ℝ) (hr : r ∈ Icc t₀ t₁) : 0 ≤ V r A := by + have hh := mul_le_mul_of_nonneg_left (hlower r hr A) (hEp r).le + have hh' := mul_le_mul_of_nonneg_right (hEle r hr) hM + dsimp [V] + nlinarith + exact nonnegative_of_parabolic_inequality hVc hVs hVt hVx hVxx (fun _ _ _ _ => by norm_num) + hl hVp hVi hVl hVr t htm x ⟨hAx,hxA⟩ + intro t htt x + have he : 0 ≤ E t*u t x := by + apply le_of_forall_pos_le_add + intro δ hδ + have hq : 0 < 1+x^2 := by positivity + have hh := hperturb (δ/(1+x^2)) (div_pos hδ hq) t htt x + simpa only [div_mul_cancel₀ _ (ne_of_gt hq)] using hh + exact (mul_nonneg_iff_of_pos_left (hEp t)).mp he + +end ZeroTemperatureSK.Parabolic + +end +end +section +open Set Filter +open scoped Topology +noncomputable section +namespace ZeroTemperatureSK.Parabolic + +theorem nonnegative_halfLine_bounded + {u ut ux uxx β c : ℝ → ℝ → ℝ} {t₀ t₁ C K M : ℝ} + (hK : 0 ≤ K) (hM : 0 ≤ M) + (hc : ContinuousOn (fun p : ℝ × ℝ => u p.1 p.2) (Icc t₀ t₁ ×ˢ Ici 0)) + (hs : ∀ t ∈ Icc t₀ t₁, Continuous (u t)) + (ht : ∀ t ∈ Ioc t₀ t₁, ∀ x, 0 < x → + HasDerivWithinAt (fun s => u s x) (ut t x) (Icc t₀ t₁) t) + (hx : ∀ t ∈ Ioc t₀ t₁, ∀ x, 0 < x → HasDerivAt (u t) (ux t x) x) + (hxx : ∀ t ∈ Ioc t₀ t₁, ∀ x, 0 < x → + HasDerivAt (deriv (u t)) (uxx t x) x) + (hb : ∀ t ∈ Ioc t₀ t₁, ∀ x, 0 < x → β t x*x ≤ K*(1+x^2)) + (hbound : ∀ t ∈ Ioc t₀ t₁, ∀ x, 0 < x → c t x ≤ C) + (hpde : ∀ t ∈ Ioc t₀ t₁, ∀ x, 0 < x → + 0 ≤ ut t x-(1/2:ℝ)*uxx t x-β t x*ux t x-c t x*u t x) + (hlower : ∀ t ∈ Icc t₀ t₁, ∀ x, 0 ≤ x → -M ≤ u t x) + (hinit : ∀ x, 0 ≤ x → 0 ≤ u t₀ x) + (hzero : ∀ t ∈ Icc t₀ t₁, 0 ≤ u t 0) : + ∀ t ∈ Icc t₀ t₁, ∀ x, 0 ≤ x → 0 ≤ u t x := by + let k := max C 0+2*K+2 + let E (t : ℝ) := Real.exp (-k*(t-t₀)) + have hk : 0 < k := by dsimp [k]; linarith [le_max_right C 0] + have hEp (t : ℝ) : 0 < E t := Real.exp_pos _ + have hEd (t : ℝ) : HasDerivAt E (-k*E t) t := by + convert ((((hasDerivAt_id t).sub_const t₀).const_mul (-k)).exp) using 1 <;> dsimp [E,id] + ring + have hEle (t : ℝ) (ht : t ∈ Icc t₀ t₁) : E t ≤ 1 := + Real.exp_le_one_iff.mpr (mul_nonpos_of_nonpos_of_nonneg (neg_nonpos.mpr hk.le) (sub_nonneg.mpr ht.1)) + have hperturb (ε : ℝ) (hε : 0 < ε) (t : ℝ) (htm : t ∈ Icc t₀ t₁) + (x : ℝ) (hxm : 0 ≤ x) : 0 ≤ E t*u t x+ε*(1+x^2) := by + let A := x+M/ε+1 + have hdiv : 0 ≤ M/ε := div_nonneg hM hε.le + have hA : 1 ≤ A := by dsimp [A]; linarith + have hxA : x ≤ A := by dsimp [A]; linarith + have hAm : M ≤ ε*A := by + have he : ε*(M/ε)=M := by field_simp + dsimp [A] + nlinarith + have hAb : M ≤ ε*(1+A^2) := by + nlinarith [mul_nonneg hε.le (sq_nonneg (A-1))] + let V (t x : ℝ) := E t*u t x+ε*(1+x^2) + have hVc : ContinuousOn (fun p : ℝ × ℝ => V p.1 p.2) (Icc t₀ t₁ ×ˢ Icc 0 A) := by + apply ContinuousOn.add + · exact (show Continuous (fun p : ℝ × ℝ => E p.1) by dsimp [E]; fun_prop).continuousOn.mul + (hc.mono (by intro p hp; exact ⟨hp.1,hp.2.1⟩)) + · fun_prop + have hVs (r : ℝ) (hr : r ∈ Icc t₀ t₁) : Continuous (V r) := + ((hs r hr).const_mul (E r)).add (by fun_prop) + have hVt (r : ℝ) (hr : r ∈ Ioc t₀ t₁) (y : ℝ) (hy : y ∈ Ioo 0 A) : + HasDerivWithinAt (fun s => V s y) (E r*(ut r y-k*u r y)) (Icc t₀ t₁) r := by + convert (((hEd r).hasDerivWithinAt.mul (ht r hr y hy.1)).add_const (ε*(1+y^2))) using 1 + ring + have hVx (r : ℝ) (hr : r ∈ Ioc t₀ t₁) (y : ℝ) (hy : y ∈ Ioo 0 A) : + HasDerivAt (V r) (E r*ux r y+ε*(2*y)) y := by + convert ((hx r hr y hy.1).const_mul (E r)).add + ((((hasDerivAt_id y).pow 2).const_add 1).const_mul ε) using 1 <;> first | rfl | ((try simp only [id_eq]); ring) + have hVxx (r : ℝ) (hr : r ∈ Ioc t₀ t₁) (y : ℝ) (hy : y ∈ Ioo 0 A) : + HasDerivAt (deriv (V r)) (E r*uxx r y+2*ε) y := by + have heloc : deriv (V r) =ᶠ[𝓝 y] (fun z => E r*deriv (u r) z+ε*(2*z)) := by + filter_upwards [Ioo_mem_nhds hy.1 hy.2] with z hz + have hp : HasDerivAt (fun z : ℝ => ε*(1+z^2)) (ε*(2*z)) z := by + convert (((hasDerivAt_id z).pow 2).const_add 1).const_mul ε using 1 <;> first | rfl | ((try simp only [id_eq]); ring) + rw [(hx r hr z hz.1).deriv] + exact (((hx r hr z hz.1).const_mul (E r)).add hp).deriv + apply HasDerivAt.congr_of_eventuallyEq _ heloc + convert ((hxx r hr y hy.1).const_mul (E r)).add + (((hasDerivAt_id y).const_mul 2).const_mul ε) using 1 <;> first | rfl | ring + have hl (r : ℝ) (hr : r ∈ Ioc t₀ t₁) (y : ℝ) (hy : y ∈ Ioo 0 A) : 0 < k-c r y := by + have hh := hbound r hr y hy.1 + dsimp [k] + linarith [le_max_left C 0] + have hVp (r : ℝ) (hr : r ∈ Ioc t₀ t₁) (y : ℝ) (hy : y ∈ Ioo 0 A) : + 0 ≤ E r*(ut r y-k*u r y)-(1/2:ℝ)*(E r*uxx r y+2*ε)- + β r y*(E r*ux r y+ε*(2*y))+(k-c r y)*V r y := by + have hp := mul_nonneg (hEp r).le (hpde r hr y hy.1) + have hc' : 2*K+2 ≤ k-c r y := by + have hh := hbound r hr y hy.1 + dsimp [k] + linarith [le_max_left C 0] + have hprod := mul_le_mul_of_nonneg_right hc' (show 0 ≤ 1+y^2 by positivity) + have hβ := hb r hr y hy.1 + have hbar : 0 ≤ (k-c r y)*(1+y^2)-1-2*β r y*y := by nlinarith [sq_nonneg y] + have hh := mul_nonneg hε.le hbar + dsimp [V] + nlinarith + have hVi (y : ℝ) (hy : y ∈ Icc 0 A) : 0 ≤ V t₀ y := by + exact add_nonneg (mul_nonneg (hEp t₀).le (hinit y hy.1)) (by positivity) + have hVl (r : ℝ) (hr : r ∈ Icc t₀ t₁) : 0 ≤ V r 0 := by + exact add_nonneg (mul_nonneg (hEp r).le (hzero r hr)) (by positivity) + have hVr (r : ℝ) (hr : r ∈ Icc t₀ t₁) : 0 ≤ V r A := by + have hh := mul_le_mul_of_nonneg_left (hlower r hr A (by linarith)) (hEp r).le + have hh' := mul_le_mul_of_nonneg_right (hEle r hr) hM + dsimp [V] + nlinarith + exact nonnegative_of_parabolic_inequality hVc hVs hVt hVx hVxx (fun _ _ _ _ => by norm_num) + hl hVp hVi hVl hVr t htm x ⟨hxm,hxA⟩ + intro t htt x hxx + have he : 0 ≤ E t*u t x := by + apply le_of_forall_pos_le_add + intro δ hδ + have hq : 0 < 1+x^2 := by positivity + have hh := hperturb (δ/(1+x^2)) (div_pos hδ hq) t htt x hxx + simpa only [div_mul_cancel₀ _ (ne_of_gt hq)] using hh + exact (mul_nonneg_iff_of_pos_left (hEp t)).mp he + +end ZeroTemperatureSK.Parabolic + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKSupport/Parabolic/GradientStability.lean b/lean/OAI/Probability/SKSupport/Parabolic/GradientStability.lean new file mode 100644 index 0000000000000000000000000000000000000000..8714d2184f07aa0b902fa3714184d1764be325ff --- /dev/null +++ b/lean/OAI/Probability/SKSupport/Parabolic/GradientStability.lean @@ -0,0 +1,68 @@ +import Mathlib +import OAI.Probability.SKSupport.Control.ValueDifference + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology ContDiff +noncomputable section +namespace ZeroTemperatureSK +open Heat + +lemma convex_gradient_comparison {f g : ℝ → ℝ} (hf : ConvexOn ℝ univ f) + (hg : ConvexOn ℝ univ g) (hfd : Differentiable ℝ f) (hgd : Differentiable ℝ g) + {L : ℝ≥0} (hL : LipschitzWith L (deriv g)) {E : ℝ} (hE : ∀ x, |f x-g x| ≤ E) + {h : ℝ} (hh : 0 < h) (x : ℝ) : + |deriv f x-deriv g x| ≤ 2*E/h+(L:ℝ)*h := by + have hfU := hf.deriv_le_slope (mem_univ x) (mem_univ (x+h)) (by linarith) (hfd x) + have hfL := hf.slope_le_deriv (mem_univ (x-h)) (mem_univ x) (by linarith) (hfd x) + have hgU := hg.slope_le_deriv (mem_univ x) (mem_univ (x+h)) (by linarith) (hgd (x+h)) + have hgL := hg.deriv_le_slope (mem_univ (x-h)) (mem_univ x) (by linarith) (hgd (x-h)) + have hplus := hL.dist_le_mul (x+h) x + have hminus := hL.dist_le_mul (x-h) x + rw [Real.dist_eq,Real.dist_eq,add_sub_cancel_left,abs_of_pos hh] at hplus + rw [Real.dist_eq,Real.dist_eq,sub_sub_cancel_left,abs_neg,abs_of_pos hh] at hminus + have e0 := (abs_le.mp (hE x)) + have e1 := (abs_le.mp (hE (x+h))) + have e2 := (abs_le.mp (hE (x-h))) + have hp := abs_le.mp hplus + have hm := abs_le.mp hminus + simp only [slope_def_field,add_sub_cancel_left,sub_sub_cancel] at hfU hfL hgU hgL + have hFU := (le_div_iff₀ hh).mp hfU + have hFL := (div_le_iff₀ hh).mp hfL + have hGU := (div_le_iff₀ hh).mp hgU + have hGL := (le_div_iff₀ hh).mp hgL + apply abs_le.mpr + constructor <;> apply (mul_le_mul_iff_right₀ hh).mp + · have hdiv : (2*E/h)*h=2*E := div_mul_cancel₀ _ hh.ne' + nlinarith [mul_le_mul_of_nonneg_right hm.1 hh.le] + · have hdiv : (2*E/h)*h=2*E := div_mul_cancel₀ _ hh.ne' + nlinarith [mul_le_mul_of_nonneg_right hp.2 hh.le] + +variable {Ω : Type*} [MeasurableSpace Ω] + +lemma compactGradient_stability (W : BrownianSystem Ω) (γ : OrderParameter) (T : Time) : + ∃ L : ℝ≥0, ∀ β : OrderParameter, ∀ h > 0, ∀ t x, + |compactGradient W β T t x-compactGradient W γ T t x| ≤ + 3*coefficientDistance β γ/h+(L:ℝ)*h := by + obtain ⟨L,hL⟩ := compactGradient_lipschitz W γ T.property.1 T.property.2 + refine ⟨L,fun β h hh t x => ?_⟩ + have ht0 := (stripClamp_mem T.property.1 t).1 + have ht1 := (stripClamp_mem T.property.1 t).2.trans_lt T.property.2 + have hg : LipschitzWith L (deriv (value W γ (stripClamp T t))) := hL t + have hb := convex_gradient_comparison (value_convex W β _ ht1.le) + (value_convex W γ _ ht1.le) + ((value_contDiff W β ht0 ht1).differentiable (by simp)) + ((value_contDiff W γ ht0 ht1).differentiable (by simp)) hg + (fun y => value_difference_bound W β γ ht0 ht1.le y) hh x + change |deriv (value W β (stripClamp T t)) x-deriv (value W γ (stripClamp T t)) x| ≤ _ + convert hb using 1 + ring + +end ZeroTemperatureSK + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKSupport/Parabolic/ReverseBurgers.lean b/lean/OAI/Probability/SKSupport/Parabolic/ReverseBurgers.lean new file mode 100644 index 0000000000000000000000000000000000000000..7c8a6b64485fc55d4b579800458654a906d79e67 --- /dev/null +++ b/lean/OAI/Probability/SKSupport/Parabolic/ReverseBurgers.lean @@ -0,0 +1,61 @@ +import Mathlib +import OAI.Probability.SKSupport.Density.RatioJets + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology ContDiff +noncomputable section +namespace ZeroTemperatureSK.Heat + +structure ReverseBurgers (r : ℝ → ℝ → ℝ) (H : ℝ) : Prop where + family : BoundedSmoothFamily r + continuous : ContinuousOn (fun p : ℝ × ℝ => r p.1 p.2) (Icc (0:ℝ) H ×ˢ univ) + time_derivative : ∀ n t, 0 < t → t < H → ∀ x, + HasDerivAt (fun u => iteratedDeriv n (r u) x) (-iteratedDeriv n (burgersRate r t) x) t + +lemma SmoothBurgers.reverse {r : ℝ → ℝ → ℝ} (hr : SmoothBurgers r) {H : ℝ} (_ : 0 ≤ H) : + ReverseBurgers (fun t x => r (H-t) x) H := by + have hfm : BoundedSmoothFamily (fun t x => r (H-t) x) := by + simpa only [one_mul] using hr.family.reparam (A := fun t => H-t) (C := fun _ => 1) + (measurable_const.sub measurable_id) measurable_const (fun _ => by norm_num) + refine ⟨hfm,?_,?_⟩ + · apply (hr.continuous H).comp + (f := fun p : ℝ × ℝ => (H-p.1,p.2)) + ((continuous_const.sub continuous_fst).prodMk continuous_snd).continuousOn + intro p hp + exact ⟨⟨sub_nonneg.mpr hp.1.2,sub_le_self _ hp.1.1⟩,mem_univ _⟩ + · intro n t ht htH x + have hd := (hr.time_derivative n (H-t) (sub_pos.mpr htH) x).comp t + ((hasDerivAt_id t).const_sub H) + convert hd using 1 <;> first | rfl | (simp only [mul_neg,mul_one];rfl) + +namespace ReverseBurgers +variable {r : ℝ → ℝ → ℝ} {H : ℝ} (hr : ReverseBurgers r H) +include hr + +lemma jet_continuous (n : ℕ) : + ContinuousOn (fun p : ℝ × ℝ => iteratedDeriv n (r p.1) p.2) (Icc (0:ℝ) H ×ˢ univ) := + hr.family.continuousOn_iteratedDeriv hr.continuous n + +lemma ratio_continuous {s : ℝ → ℝ → ℝ} (hs : SmoothForward s) : + ContinuousOn (fun p : ℝ × ℝ => ratioWronskian r s p.1 p.2) (Icc (0:ℝ) H ×ˢ univ) := by + have hv : ContinuousOn (fun p : ℝ × ℝ => deriv (r p.1) p.2) (Icc (0:ℝ) H ×ˢ univ) := by + simpa only [iteratedDeriv_one] using hr.jet_continuous 1 + exact (hr.continuous.mul hs.family.deriv.continuous.continuousOn).sub + (hs.family.continuous.continuousOn.mul hv) + +lemma ratio_time {s : ℝ → ℝ → ℝ} (hs : SmoothForward s) {t : ℝ} (ht : 0 < t) (htH : t < H) (x : ℝ) : + HasDerivAt (fun u => ratioWronskian r s u x) (ratioWronskianRate r s t x) t := by + apply ratioWronskian_time hs ht x + · simpa only [iteratedDeriv_zero] using hr.time_derivative 0 t ht htH x + · simpa only [iteratedDeriv_one] using hr.time_derivative 1 t ht htH x + +end ReverseBurgers +end ZeroTemperatureSK.Heat + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKSupport/Parabolic/TiltedEvolution.lean b/lean/OAI/Probability/SKSupport/Parabolic/TiltedEvolution.lean new file mode 100644 index 0000000000000000000000000000000000000000..5c207ad6bff59d975f0bd4ef54454c671ee62515 --- /dev/null +++ b/lean/OAI/Probability/SKSupport/Parabolic/TiltedEvolution.lean @@ -0,0 +1,123 @@ +import Mathlib +import OAI.Probability.SKSupport.Regularity.BoundedSmoothFamily + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology ContDiff +noncomputable section +namespace ZeroTemperatureSK.Heat + +lemma varianceTilted_family {f g : ℝ → ℝ} {K : ℝ≥0} + (hf : RegularDatum f) (hLip : LipschitzWith K f) (hg : BoundedSmooth g) + {c : ℝ} (hc : 0 ≤ c) : BoundedSmoothFamily (fun t => varianceTilted c t f g) := by + have he (t : ℝ) : varianceTilted c t f g=tiltedMean c (Real.toNNReal t) f g := + funext (varianceTilted_eq_tiltedMean hf.smooth.continuous.measurable hg.smooth.continuous.measurable c t) + refine ⟨?_,fun t => by rw [he];exact boundedSmooth_tiltedMean hf hLip hg hc _,?_⟩ + · exact (measurable_varianceHeat_family (F := fun _ y => g y*Real.exp (c*f y)) + (hg.smooth.continuous.measurable.comp measurable_snd |>.mul + ((measurable_const.mul (hf.smooth.continuous.measurable.comp measurable_snd)).exp)) measurable_id).div + (measurable_varianceHeat_family (F := fun _ y => Real.exp (c*f y)) + ((measurable_const.mul (hf.smooth.continuous.measurable.comp measurable_snd)).exp) measurable_id) + · intro n + obtain ⟨C,hC⟩ := uniform_tiltedMean_bounds hf hLip hg hc n + exact ⟨C,fun t x => by rw [he];exact hC _ x⟩ + +lemma varianceTilted_continuousOn {f g : ℝ → ℝ} {K : ℝ≥0} + (hf : RegularDatum f) (hLip : LipschitzWith K f) (hg : BoundedSmooth g) + {c : ℝ} (hc : 0 ≤ c) (T : ℝ) : + ContinuousOn (fun p : ℝ × ℝ => varianceTilted c p.1 f g p.2) (Icc (0:ℝ) T ×ˢ univ) := by + obtain ⟨L,hL⟩ := varianceTilted_joint_bound hf hLip hg hc + apply continuousOn_of_joint_bound (F := fun t => varianceTilted c t f g) (L := L) + intro t ht s hs x y + exact hL t ht.1 s hs.1 x y + +lemma second_deriv_mul {F G : ℝ → ℝ} (hF : ContDiff ℝ 2 F) (hG : ContDiff ℝ 2 G) (x : ℝ) : + deriv (deriv (fun y => F y*G y)) x = + deriv (deriv F) x*G x+2*deriv F x*deriv G x+F x*deriv (deriv G) x := by + have he : deriv (fun y => F y*G y)=fun y => deriv F y*G y+F y*deriv G y := by + funext y + exact (((hF.differentiable (by norm_num)) y).hasDerivAt.mul + ((hG.differentiable (by norm_num)) y).hasDerivAt).deriv + rw [he] + convert (((((show ContDiff ℝ 1 (deriv F) from hF.deriv').differentiable (by norm_num)) x).hasDerivAt.mul + ((hG.differentiable (by norm_num)) x).hasDerivAt).add + (((hF.differentiable (by norm_num)) x).hasDerivAt.mul + (((show ContDiff ℝ 1 (deriv G) from hG.deriv').differentiable (by norm_num)) x).hasDerivAt)).deriv using 1 + ring + +lemma quotient_heat_equation {N D : ℝ → ℝ → ℝ} {t : ℝ} {S : Set ℝ} + (hN : ContDiff ℝ 2 (N t)) (hD : ContDiff ℝ 2 (D t)) + (hne : ∀ x, D t x ≠ 0) + (hNt : ∀ x, HasDerivWithinAt (fun u => N u x) ((1/2:ℝ)*deriv (deriv (N t)) x) S t) + (hDt : ∀ x, HasDerivWithinAt (fun u => D u x) ((1/2:ℝ)*deriv (deriv (D t)) x) S t) (x : ℝ) : + HasDerivWithinAt (fun u => N u x/D u x) + ((1/2:ℝ)*deriv (deriv (fun y => N t y/D t y)) x+ + (deriv (D t) x/D t x)*deriv (fun y => N t y/D t y) x) S t := by + let F := fun y => N t y/D t y + have hF : ContDiff ℝ 2 F := hN.div hD hne + have he : N t=fun y => F y*D t y := by funext y;dsimp [F];field_simp [hne y] + have hxx : deriv (deriv (N t)) x=deriv (deriv F) x*D t x+ + 2*deriv F x*deriv (D t) x+F x*deriv (deriv (D t)) x := by + calc + _ = deriv (deriv (fun y => F y*D t y)) x := congrArg (fun f => deriv (deriv f) x) he + _ = _ := second_deriv_mul hF hD x + convert (hNt x).div (hDt x) (hne x) using 1 + rw [hxx] + dsimp only [F] + field_simp [hne x] + ring + +lemma varianceTilted_equation {f g : ℝ → ℝ} {K : ℝ≥0} + (hf : RegularDatum f) (hLip : LipschitzWith K f) (hg : BoundedSmooth g) + {c : ℝ} (hc : 0 ≤ c) {t : ℝ} (ht : 0 ≤ t) (x : ℝ) : + HasDerivWithinAt (fun u => varianceTilted c u f g x) + ((1/2:ℝ)*deriv (deriv (varianceTilted c t f g)) x+ + c*deriv (varianceLogHeat c t f) x*deriv (varianceTilted c t f g) x) (Ici 0) t := by + let N := fun u => varianceHeat u (fun y => g y*Real.exp (c*f y)) + let D := fun u => varianceHeat u (fun y => Real.exp (c*f y)) + have hD (u : ℝ) : ContDiff ℝ ∞ (D u) := by + have he : D u=semigroup (Real.toNNReal u) (fun y => Real.exp (c*f y)) := + funext (varianceHeat_eq_semigroup_toNNReal ((measurable_const.mul hf.smooth.continuous.measurable).exp) u) + rw [he] + exact contDiff_semigroup_exp hf hLip hc _ + have hN (u : ℝ) : ContDiff ℝ ∞ (N u) := by + have he : N u=semigroup (Real.toNNReal u) (fun y => g y*Real.exp (c*f y)) := + funext (varianceHeat_eq_semigroup_toNNReal (hg.smooth.continuous.measurable.mul + ((measurable_const.mul hf.smooth.continuous.measurable).exp)) u) + rw [he] + exact contDiff_semigroup_weight_exp hf hLip hg hc _ + have hNt (y : ℝ) : HasDerivWithinAt (fun u => N u y) ((1/2:ℝ)*deriv (deriv (N t)) y) (Ici 0) t := + varianceHeat_equation ((hg.smooth.mul (contDiff_const.mul hf.smooth).exp).of_le (ENat.natCast_le_of_coe_top_le_withTop le_rfl 2)) + (by simpa only [iteratedDeriv_zero] using exponentialBound_weightExp_iteratedDeriv hf hLip hg c 0) + (by simpa only [iteratedDeriv_one] using exponentialBound_weightExp_iteratedDeriv hf hLip hg c 1) + (by simpa only [iteratedDeriv_succ,iteratedDeriv_zero] using exponentialBound_weightExp_iteratedDeriv hf hLip hg c 2) ht y + have hDt (y : ℝ) : HasDerivWithinAt (fun u => D u y) ((1/2:ℝ)*deriv (deriv (D t)) y) (Ici 0) t := by + convert varianceHeat_equation ((contDiff_const.mul hf.smooth).exp.of_le (ENat.natCast_le_of_coe_top_le_withTop le_rfl 2)) + (exponentialBound_exp hLip c) + (by simpa only [iteratedDeriv_one] using exponentialBound_exp_iteratedDeriv hf hLip c 1) + (by simpa only [iteratedDeriv_succ,iteratedDeriv_zero] using exponentialBound_exp_iteratedDeriv hf hLip c 2) ht y using 1 + have hratio : deriv (D t) x/D t x=c*deriv (varianceLogHeat c t f) x := by + rw [deriv_varianceLogHeat_tilted hf hLip hc] + have hd := hasDerivAt_semigroup_exp (hf.smooth.of_le (ENat.natCast_le_of_coe_top_le_withTop le_rfl 1)) hLip hc (Real.toNNReal t) x + have he : D t=semigroup (Real.toNNReal t) (fun y => Real.exp (c*f y)) := + funext (varianceHeat_eq_semigroup_toNNReal ((measurable_const.mul hf.smooth.continuous.measurable).exp) t) + rw [he,hd.deriv,varianceTilted_eq_tiltedMean hf.smooth.continuous.measurable hf.deriv_bounded.smooth.continuous.measurable] + simp only [tiltedMean,semigroup] + rw [← mul_div_assoc,← integral_const_mul] + apply congrArg (fun z : ℝ => z / ∫ y, Real.exp (c*f (x+y)) ∂gaussianReal 0 (Real.toNNReal t)) + apply integral_congr_ae + filter_upwards [] with y + ring + have hh := quotient_heat_equation ((hN t).of_le (ENat.natCast_le_of_coe_top_le_withTop le_rfl 2)) ((hD t).of_le (ENat.natCast_le_of_coe_top_le_withTop le_rfl 2)) + (fun y => ne_of_gt (varianceHeat_exp_pos hLip c t y)) hNt hDt x + rw [hratio] at hh + exact hh + +end ZeroTemperatureSK.Heat + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKSupport/Parabolic/TiltedMean.lean b/lean/OAI/Probability/SKSupport/Parabolic/TiltedMean.lean new file mode 100644 index 0000000000000000000000000000000000000000..cde64c4a944a55fd04216fdb0a55caa5a16bc460 --- /dev/null +++ b/lean/OAI/Probability/SKSupport/Parabolic/TiltedMean.lean @@ -0,0 +1,174 @@ +import Mathlib +import OAI.Probability.SKSupport.Foundations.BoundedSmooth + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology ContDiff +noncomputable section +namespace ZeroTemperatureSK.Heat + +def tiltedMean (c : ℝ) (h : ℝ≥0) (f g : ℝ → ℝ) (x : ℝ) : ℝ := + semigroup h (fun z => g z*Real.exp (c*f z)) x / + semigroup h (fun z => Real.exp (c*f z)) x + +lemma tiltedMean_bound {f g : ℝ → ℝ} {K G : ℝ≥0} + (hLip : LipschitzWith K f) (hgm : Measurable g) (hG : ∀ x, |g x| ≤ G) + (c : ℝ) (h : ℝ≥0) (x : ℝ) : |tiltedMean c h f g x| ≤ G := by + have hE := semigroup_exp_pos hLip c h x + unfold tiltedMean + rw [abs_div, abs_of_pos hE, div_le_iff₀ hE] + unfold semigroup + rw [← integral_const_mul] + apply abs_integral_le_integral_abs.trans + apply integral_mono (integrable_weight_exp_translate hLip hgm hG c h x).abs + ((integrable_exp_translate_of_lipschitz hLip c h x).const_mul _) + intro y + change |g (x+y)*Real.exp (c*f (x+y))| ≤ (G:ℝ)*Real.exp (c*f (x+y)) + rw [abs_mul, abs_of_pos (Real.exp_pos _)] + exact mul_le_mul_of_nonneg_right (hG _) (Real.exp_nonneg _) + +lemma contDiff_semigroup_exp {f : ℝ → ℝ} {K : ℝ≥0} + (hf : RegularDatum f) (hLip : LipschitzWith K f) {c : ℝ} (hc : 0 ≤ c) (h : ℝ≥0) : + ContDiff ℝ ∞ (semigroup h (fun z => Real.exp (c*f z))) := by + simpa only [one_mul] using contDiff_semigroup_weight_exp hf hLip (BoundedSmooth.const 1) hc h + +lemma contDiff_tiltedMean {f g : ℝ → ℝ} {K : ℝ≥0} + (hf : RegularDatum f) (hLip : LipschitzWith K f) (hg : BoundedSmooth g) + {c : ℝ} (hc : 0 ≤ c) (h : ℝ≥0) : ContDiff ℝ ∞ (tiltedMean c h f g) := by + exact (contDiff_semigroup_weight_exp hf hLip hg hc h).div + (contDiff_semigroup_exp hf hLip hc h) (fun x => ne_of_gt (semigroup_exp_pos hLip c h x)) + +lemma hasDerivAt_tiltedMean {f g : ℝ → ℝ} {K : ℝ≥0} + (hf : RegularDatum f) (hLip : LipschitzWith K f) (hg : BoundedSmooth g) + {c : ℝ} (hc : 0 ≤ c) (h : ℝ≥0) (x : ℝ) : + HasDerivAt (tiltedMean c h f g) + (tiltedMean c h f (fun z => deriv g z+c*g z*deriv f z) x - + c*tiltedMean c h f g x*tiltedMean c h f (deriv f) x) x := by + obtain ⟨G,hG⟩ := hg.bound + obtain ⟨G₁,hG₁⟩ := hg.deriv.bound + have hN := hasDerivAt_semigroup_weight_exp (hf.smooth.of_le (by simp)) hLip + (hg.smooth.of_le (by simp)) hG hG₁ hc h x + have hD := hasDerivAt_semigroup_exp (hf.smooth.of_le (by simp)) hLip hc h x + have he : (∫ y, c*deriv f (x+y)*Real.exp (c*f (x+y)) ∂gaussianReal 0 h) = + c*semigroup h (fun z => deriv f z*Real.exp (c*f z)) x := by + unfold semigroup + rw [← integral_const_mul] + apply integral_congr_ae + filter_upwards [] with y + ring + rw [he] at hD + have hE := ne_of_gt (semigroup_exp_pos hLip c h x) + change HasDerivAt _ (semigroup h (fun z => (deriv g z+c*g z*deriv f z)*Real.exp (c*f z)) x) x at hN + have hND := hN.div hD hE + change HasDerivAt _ (_/semigroup h (fun z => Real.exp (c*f z)) x - + c*(_/semigroup h (fun z => Real.exp (c*f z)) x)* + (_/semigroup h (fun z => Real.exp (c*f z)) x)) x + convert hND using 1 <;> first | rfl | field_simp + +lemma deriv_tiltedMean {f g : ℝ → ℝ} {K : ℝ≥0} + (hf : RegularDatum f) (hLip : LipschitzWith K f) (hg : BoundedSmooth g) + {c : ℝ} (hc : 0 ≤ c) (h : ℝ≥0) : + deriv (tiltedMean c h f g) = fun x => + tiltedMean c h f (fun z => deriv g z+c*g z*deriv f z) x - + c*tiltedMean c h f g x*tiltedMean c h f (deriv f) x := by + funext x + exact (hasDerivAt_tiltedMean hf hLip hg hc h x).deriv + +lemma iteratedDeriv_mul_bound {f g : ℝ → ℝ} (n : ℕ) + (hf : ContDiff ℝ n f) (hg : ContDiff ℝ n g) (A B : ℕ → ℝ≥0) + (hA : ∀ i ≤ n, ∀ x, |iteratedDeriv i f x| ≤ A i) + (hB : ∀ i ≤ n, ∀ x, |iteratedDeriv i g x| ≤ B i) (x : ℝ) : + |iteratedDeriv n (fun z => f z*g z) x| ≤ + ∑ i ∈ Finset.range (n+1), (n.choose i:ℝ)*A i*B (n-i) := by + rw [iteratedDeriv_fun_mul hf.contDiffAt hg.contDiffAt] + apply (Finset.abs_sum_le_sum_abs _ _).trans + apply Finset.sum_le_sum + intro i hi + have hi' : i ≤ n := by simpa only [Finset.mem_range, Nat.lt_succ_iff] using hi + simp only [abs_mul, abs_of_nonneg (show (0:ℝ) ≤ (n.choose i:ℝ) from Nat.cast_nonneg _)] + gcongr + · exact hA i hi' x + · exact hB (n-i) (Nat.sub_le _ _) x + +lemma boundedSmooth_tiltedMean {f g : ℝ → ℝ} {K : ℝ≥0} + (hf : RegularDatum f) (hLip : LipschitzWith K f) (hg : BoundedSmooth g) + {c : ℝ} (hc : 0 ≤ c) (h : ℝ≥0) : BoundedSmooth (tiltedMean c h f g) := by + classical + constructor + · exact contDiff_tiltedMean hf hLip hg hc h + · have hbounds : ∀ n : ℕ, ∀ g : ℝ → ℝ, BoundedSmooth g → + ∃ C : ℝ≥0, ∀ x, |iteratedDeriv n (tiltedMean c h f g) x| ≤ C := by + intro n + induction n using Nat.strong_induction_on with + | h n IH => + intro g hg + cases n with + | zero => + obtain ⟨G,hG⟩ := hg.bound + refine ⟨G, fun x => ?_⟩ + simpa only [iteratedDeriv_zero] using + (tiltedMean_bound hLip hg.smooth.continuous.measurable hG c h x) + | succ m => + let q (z : ℝ) := deriv g z+c*g z*deriv f z + have hq : BoundedSmooth q := weighted_derivative_boundedSmooth hf hg c + obtain ⟨Cq,hCq⟩ := IH m (by omega) q hq + have hAg : ∀ i : ℕ, ∃ C : ℝ≥0, + i ≤ m → ∀ x, |iteratedDeriv i (tiltedMean c h f g) x| ≤ C := by + intro i + by_cases hi : i ≤ m + · obtain ⟨C,hC⟩ := IH i (by omega) g hg + exact ⟨C, fun _ => hC⟩ + · exact ⟨0, fun hi' => (hi hi').elim⟩ + have hBg : ∀ i : ℕ, ∃ C : ℝ≥0, + i ≤ m → ∀ x, |iteratedDeriv i (tiltedMean c h f (deriv f)) x| ≤ C := by + intro i + by_cases hi : i ≤ m + · obtain ⟨C,hC⟩ := IH i (by omega) (deriv f) hf.deriv_bounded + exact ⟨C, fun _ => hC⟩ + · exact ⟨0, fun hi' => (hi hi').elim⟩ + choose A hA using hAg + choose B hB using hBg + let Cprod : ℝ≥0 := ∑ i ∈ Finset.range (m+1), (m.choose i:ℝ≥0)*A i*B (m-i) + refine ⟨Cq+⟨|c|, abs_nonneg c⟩*Cprod, fun x => ?_⟩ + rw [iteratedDeriv_succ', deriv_tiltedMean hf hLip hg hc h] + have hcg := contDiff_tiltedMean hf hLip hg hc h + have hcdf := contDiff_tiltedMean hf hLip hf.deriv_bounded hc h + have hcq := contDiff_tiltedMean hf hLip hq hc h + have he : (fun x => tiltedMean c h f q x-c*tiltedMean c h f g x*tiltedMean c h f (deriv f) x) = + (fun x => tiltedMean c h f q x-c*(tiltedMean c h f g x*tiltedMean c h f (deriv f) x)) := by + funext x; ring + change |iteratedDeriv m (fun x => tiltedMean c h f q x- + c*tiltedMean c h f g x*tiltedMean c h f (deriv f) x) x| ≤ _ + rw [he, iteratedDeriv_fun_sub (n := m) (hcq.of_le (ENat.natCast_le_of_coe_top_le_withTop le_rfl m) |>.contDiffAt) + (contDiff_const.mul (hcg.mul hcdf) |>.of_le (ENat.natCast_le_of_coe_top_le_withTop le_rfl m) |>.contDiffAt), + iteratedDeriv_const_mul_field] + have hp := iteratedDeriv_mul_bound m (hcg.of_le (ENat.natCast_le_of_coe_top_le_withTop le_rfl m)) (hcdf.of_le (ENat.natCast_le_of_coe_top_le_withTop le_rfl m)) + A B hA hB x + have hp' : |iteratedDeriv m (fun z => tiltedMean c h f g z*tiltedMean c h f (deriv f) z) x| ≤ Cprod := by + simpa only [Cprod, NNReal.coe_sum, NNReal.coe_mul, NNReal.coe_natCast] using hp + calc + _ ≤ |iteratedDeriv m (tiltedMean c h f q) x| + + |c*iteratedDeriv m (fun z => tiltedMean c h f g z*tiltedMean c h f (deriv f) z) x| := by + have hh := norm_sub_le (iteratedDeriv m (tiltedMean c h f q) x) + (c*iteratedDeriv m (fun z => tiltedMean c h f g z*tiltedMean c h f (deriv f) z) x) + simpa only [Real.norm_eq_abs] using hh + _ ≤ (Cq:ℝ)+|c| *(Cprod:ℝ) := by rw [abs_mul]; gcongr; exact hCq x + _ = _ := rfl + exact fun n => hbounds n g hg + +end ZeroTemperatureSK.Heat + +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKSupport/Parabolic/TiltedTransition.lean b/lean/OAI/Probability/SKSupport/Parabolic/TiltedTransition.lean new file mode 100644 index 0000000000000000000000000000000000000000..d1887e0059f069ba3f005933492dd2ff088ae871 --- /dev/null +++ b/lean/OAI/Probability/SKSupport/Parabolic/TiltedTransition.lean @@ -0,0 +1,135 @@ +import Mathlib +import OAI.Probability.SKSupport.Backward.TiltedBackward +import OAI.Probability.SKSupport.Foundations.RightGenerator + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section +namespace ZeroTemperatureSK +open Heat WeakIto +variable {Ω : Type*} [MeasurableSpace Ω] + +lemma Heat.varianceGradient_joint_continuous {f : ℝ → ℝ} {K : ℝ≥0} + (hf : RegularDatum f) (hLip : LipschitzWith K f) {c : ℝ} (hc : 0 ≤ c) : + Continuous (fun p : ℝ × ℝ => deriv (varianceLogHeat c p.1 f) p.2) := by + have he : (fun p : ℝ × ℝ => deriv (varianceLogHeat c p.1 f) p.2)= + fun p => varianceTilted c p.1 f (deriv f) p.2 := + funext (fun p => congrFun (deriv_varianceLogHeat_tilted hf hLip hc p.1) p.2) + rw [he] + exact varianceTilted_joint_continuous hf hLip hf.deriv_bounded hc + +lemma Heat.tiltedBackwardRate_continuous {f g : ℝ → ℝ} {K : ℝ≥0} + (hf : RegularDatum f) (hLip : LipschitzWith K f) (hg : BoundedSmooth g) {c : ℝ} (hc : 0 ≤ c) (T : ℝ) : + Continuous (fun p : ℝ × ℝ => tiltedBackwardRate c T f g p.1 p.2) := by + have hU := varianceTilted_family hf hLip hg hc + have hUc := varianceTilted_joint_continuous hf hLip hg hc + have hUx := hU.continuous_iteratedDeriv hUc 1 + have hUxx := hU.continuous_iteratedDeriv hUc 2 + simp only [iteratedDeriv_succ,iteratedDeriv_zero] at hUx hUxx + have hr : Continuous (fun p : ℝ × ℝ => tiltedRate c f g p.1 p.2) := + (continuous_const.mul hUxx).add + ((continuous_const.mul (varianceGradient_joint_continuous hf hLip hc)).mul hUx) + change Continuous (fun p : ℝ × ℝ => -tiltedRate c f g (T-p.1) p.2) + exact hr.neg.comp (f := fun p : ℝ × ℝ => (T-p.1,p.2)) + ((continuous_const.sub continuous_fst).prodMk continuous_snd) + +lemma drift_tilted_path_continuous_right (W : BrownianSystem Ω) (b : BoundedLipschitzDrift) + {f : ℝ → ℝ} {K : ℝ≥0} (hf : RegularDatum f) (hLip : LipschitzWith K f) + {c a T : ℝ} (hc : 0 ≤ c) + (hmatch : ∀ t ∈ Ico a T, ∀ x, b.f t x=c*deriv (varianceLogHeat c (T-t) f) x) + (s : ℝ≥0) (has : a ≤ s) (hsT : (s:ℝ) < T) : + ∀ᵐ ω ∂W.law, ContinuousWithinAt (fun r => b.pathDrift W r ω) (Ioi (s:ℝ)) s := by + filter_upwards [b.solution_continuous_ae W] with ω hω + have hβ : Continuous (fun t : ℝ => c*deriv (varianceLogHeat c (T-t) f) + (b.solution W.driver (Real.toNNReal t) ω)) := + continuous_const.mul ((varianceGradient_joint_continuous hf hLip hc).comp + ((continuous_const.sub continuous_id).prodMk (hω.comp (by fun_prop : Continuous Real.toNNReal)))) + apply hβ.continuousWithinAt.congr_of_eventuallyEq + · filter_upwards [self_mem_nhdsWithin,mem_nhdsWithin_of_mem_nhds (gt_mem_nhds hsT)] with r hr hrT + unfold BoundedLipschitzDrift.pathDrift + rw [Real.coe_toNNReal _ (s.coe_nonneg.trans hr.le)] + exact hmatch r ⟨has.trans hr.le,hrT⟩ _ + · unfold BoundedLipschitzDrift.pathDrift + rw [Real.toNNReal_coe] + exact hmatch s ⟨has,hsT⟩ _ + +theorem expected_tiltedBackward_right_zero (W : BrownianSystem Ω) (b : BoundedLipschitzDrift) + {f g : ℝ → ℝ} {K : ℝ≥0} (hf : RegularDatum f) (hLip : LipschitzWith K f) (hg : BoundedSmooth g) + {c a T : ℝ} (hc : 0 ≤ c) + (hmatch : ∀ t ∈ Ico a T, ∀ x, b.f t x=c*deriv (varianceLogHeat c (T-t) f) x) + (s : ℝ≥0) (has : a ≤ s) (hsT : (s:ℝ) < T) : + HasDerivWithinAt (fun t : ℝ => ∫ ω, tiltedBackward c T f g t + (b.solution W.driver (Real.toNNReal t) ω) ∂W.law) 0 (Ioi (s:ℝ)) s := by + let := W.isProbability + have hF := tiltedBackward_family hf hLip hg hc T + have hD := tiltedBackwardRate_family hf hLip hg hc T + have hgen := expected_hasDerivWithinAt_right W b hF hD + (fun a d ha had hd => tiltedBackward_integrated_rate hf hLip hg hc ha had hd) + s hsT (fun x => ((tiltedBackwardRate_continuous hf hLip hg hc T).comp + (continuous_id.prodMk continuous_const)).continuousWithinAt) + (drift_tilted_path_continuous_right W b hf hLip hc hmatch s has hsT) + have hx := b.solution_measurable W s + have hi1 : Integrable (fun ω => deriv (tiltedBackward c T f g s) (b.solution W.driver s ω)*b.pathDrift W s ω) W.law := by + apply (integrable_family_comp hF.deriv (s:ℝ) hx).mul_bdd + · exact ((b.pathDrift_measurable W).comp measurable_prodMk_left).aestronglyMeasurable + · exact Eventually.of_forall (fun ω => b.pathDrift_bound W s ω) + have hi2 := integrable_family_comp (P := W.law) hF.deriv.deriv (s:ℝ) hx + have hi3 := integrable_family_comp (P := W.law) hD (s:ℝ) hx + have he : (∫ ω, deriv (tiltedBackward c T f g s) (b.solution W.driver s ω)*b.pathDrift W s ω ∂W.law)+ + (1/2:ℝ)*(∫ ω, deriv (deriv (tiltedBackward c T f g s)) (b.solution W.driver s ω) ∂W.law)+ + (∫ ω, tiltedBackwardRate c T f g s (b.solution W.driver s ω) ∂W.law)=0 := by + have hsum := integral_add (hi1.add (hi2.const_mul (1/2:ℝ))) hi3 + dsimp only [Pi.add_apply] at hsum + rw [← integral_const_mul,← integral_add hi1 (hi2.const_mul (1/2:ℝ)),← hsum] + have hz : (fun ω => deriv (tiltedBackward c T f g s) (b.solution W.driver s ω)*b.pathDrift W s ω+ + (1/2:ℝ)*deriv (deriv (tiltedBackward c T f g s)) (b.solution W.driver s ω)+ + tiltedBackwardRate c T f g s (b.solution W.driver s ω))=fun _ => 0 := by + funext ω + unfold tiltedBackward + simp only [BoundedLipschitzDrift.pathDrift,Real.toNNReal_coe, + hmatch s ⟨has,hsT⟩,tiltedBackwardRate,tiltedRate] + ring + rw [hz,integral_zero] + rwa [he] at hgen + +theorem expected_transition_tiltedMean (W : BrownianSystem Ω) (b : BoundedLipschitzDrift) + {f g : ℝ → ℝ} {K : ℝ≥0} (hf : RegularDatum f) (hLip : LipschitzWith K f) (hg : BoundedSmooth g) + {c : ℝ} (hc : 0 ≤ c) {a T : ℝ≥0} (haT : a ≤ T) + (hmatch : ∀ t ∈ Ico (a:ℝ) T, ∀ x, b.f t x=c*deriv (varianceLogHeat c (T-t) f) x) : + (∫ ω, g (b.solution W.driver T ω) ∂W.law)= + ∫ ω, varianceTilted c ((T:ℝ)-a) f g (b.solution W.driver a ω) ∂W.law := by + have hcF : Continuous (fun r : ℝ => + ∫ ω, tiltedBackward c T f g r (b.solution W.driver (Real.toNNReal r) ω) ∂W.law) := by + let := W.isProbability + have hF := tiltedBackward_family hf hLip hg hc T + obtain ⟨C,hC⟩ := hF.bound + apply continuous_of_dominated (bound := fun _ => (C:ℝ)) + · intro r + exact ((hF.regular r).smooth.continuous.measurable.comp + (b.solution_measurable W (Real.toNNReal r))).aestronglyMeasurable + · intro r + exact Eventually.of_forall (fun ω => by + simpa only [Real.norm_eq_abs] using hC r (b.solution W.driver (Real.toNNReal r) ω)) + · exact integrable_const _ + · filter_upwards [b.solution_continuous_ae W] with ω hω + exact (tiltedBackward_continuous hf hLip hg hc T).comp + (continuous_id.prodMk (hω.comp (by fun_prop : Continuous Real.toNNReal))) + have hi := intervalIntegral.integral_eq_sub_of_hasDeriv_right_of_le (show (a:ℝ) ≤ T from haT) + hcF.continuousOn (f' := fun _ => (0:ℝ)) (fun r hr => by + have hh := expected_tiltedBackward_right_zero W b hf hLip hg hc hmatch (Real.toNNReal r) + (by rw [Real.coe_toNNReal _ (a.coe_nonneg.trans hr.1.le)];exact hr.1.le) + (by rw [Real.coe_toNNReal _ (a.coe_nonneg.trans hr.1.le)];exact hr.2) + simpa only [Real.coe_toNNReal _ (a.coe_nonneg.trans hr.1.le)] using hh) + (intervalIntegrable_const) + simp only [intervalIntegral.integral_zero,Real.toNNReal_coe,tiltedBackward_terminal] at hi + exact sub_eq_zero.mp hi.symm + +end ZeroTemperatureSK + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKSupport/Parabolic/UniformTiltedMeanBounds.lean b/lean/OAI/Probability/SKSupport/Parabolic/UniformTiltedMeanBounds.lean new file mode 100644 index 0000000000000000000000000000000000000000..62a0828d3cc4853093269fa5f809a03f88213b67 --- /dev/null +++ b/lean/OAI/Probability/SKSupport/Parabolic/UniformTiltedMeanBounds.lean @@ -0,0 +1,91 @@ +import Mathlib +import OAI.Probability.SKSupport.Parabolic.TiltedMean + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology ContDiff +noncomputable section +namespace ZeroTemperatureSK.Heat + +lemma uniform_tiltedMean_bounds {f g : ℝ → ℝ} {K : ℝ≥0} + (hf : RegularDatum f) (hLip : LipschitzWith K f) (hg : BoundedSmooth g) + {c : ℝ} (hc : 0 ≤ c) : + ∀ n : ℕ, ∃ C : ℝ≥0, ∀ h : ℝ≥0, ∀ x, + |iteratedDeriv n (tiltedMean c h f g) x| ≤ C := by + classical + have hbounds : ∀ n : ℕ, ∀ g : ℝ → ℝ, BoundedSmooth g → + ∃ C : ℝ≥0, ∀ h : ℝ≥0, ∀ x, |iteratedDeriv n (tiltedMean c h f g) x| ≤ C := by + intro n + induction n using Nat.strong_induction_on with + | h n IH => + intro g hg + cases n with + | zero => + obtain ⟨G,hG⟩ := hg.bound + refine ⟨G, fun h x => ?_⟩ + simpa only [iteratedDeriv_zero] using + (tiltedMean_bound hLip hg.smooth.continuous.measurable hG c h x) + | succ m => + let q (z : ℝ) := deriv g z+c*g z*deriv f z + have hq : BoundedSmooth q := weighted_derivative_boundedSmooth hf hg c + obtain ⟨Cq,hCq⟩ := IH m (by omega) q hq + have hAg : ∀ i : ℕ, ∃ C : ℝ≥0, + i ≤ m → ∀ h : ℝ≥0, ∀ x, |iteratedDeriv i (tiltedMean c h f g) x| ≤ C := by + intro i + by_cases hi : i ≤ m + · obtain ⟨C,hC⟩ := IH i (by omega) g hg + exact ⟨C, fun _ => hC⟩ + · exact ⟨0, fun hi' => (hi hi').elim⟩ + have hBg : ∀ i : ℕ, ∃ C : ℝ≥0, + i ≤ m → ∀ h : ℝ≥0, ∀ x, |iteratedDeriv i (tiltedMean c h f (deriv f)) x| ≤ C := by + intro i + by_cases hi : i ≤ m + · obtain ⟨C,hC⟩ := IH i (by omega) (deriv f) hf.deriv_bounded + exact ⟨C, fun _ => hC⟩ + · exact ⟨0, fun hi' => (hi hi').elim⟩ + choose A hA using hAg + choose B hB using hBg + let Cprod : ℝ≥0 := ∑ i ∈ Finset.range (m+1), (m.choose i:ℝ≥0)*A i*B (m-i) + refine ⟨Cq+⟨|c|, abs_nonneg c⟩*Cprod, fun h x => ?_⟩ + rw [iteratedDeriv_succ', deriv_tiltedMean hf hLip hg hc h] + have hcg := contDiff_tiltedMean hf hLip hg hc h + have hcdf := contDiff_tiltedMean hf hLip hf.deriv_bounded hc h + have hcq := contDiff_tiltedMean hf hLip hq hc h + have he : (fun x => tiltedMean c h f q x-c*tiltedMean c h f g x*tiltedMean c h f (deriv f) x) = + (fun x => tiltedMean c h f q x-c*(tiltedMean c h f g x*tiltedMean c h f (deriv f) x)) := by + funext x; ring + change |iteratedDeriv m (fun x => tiltedMean c h f q x- + c*tiltedMean c h f g x*tiltedMean c h f (deriv f) x) x| ≤ _ + rw [he, iteratedDeriv_fun_sub (n := m) (hcq.of_le (ENat.natCast_le_of_coe_top_le_withTop le_rfl m) |>.contDiffAt) + (contDiff_const.mul (hcg.mul hcdf) |>.of_le (ENat.natCast_le_of_coe_top_le_withTop le_rfl m) |>.contDiffAt), + iteratedDeriv_const_mul_field] + have hp := iteratedDeriv_mul_bound m (hcg.of_le (ENat.natCast_le_of_coe_top_le_withTop le_rfl m)) (hcdf.of_le (ENat.natCast_le_of_coe_top_le_withTop le_rfl m)) + A B (fun i hi => hA i hi h) (fun i hi => hB i hi h) x + have hp' : |iteratedDeriv m (fun z => tiltedMean c h f g z*tiltedMean c h f (deriv f) z) x| ≤ Cprod := by + simpa only [Cprod, NNReal.coe_sum, NNReal.coe_mul, NNReal.coe_natCast] using hp + calc + _ ≤ |iteratedDeriv m (tiltedMean c h f q) x| + + |c*iteratedDeriv m (fun z => tiltedMean c h f g z*tiltedMean c h f (deriv f) z) x| := by + have hh := norm_sub_le (iteratedDeriv m (tiltedMean c h f q) x) + (c*iteratedDeriv m (fun z => tiltedMean c h f g z*tiltedMean c h f (deriv f) z) x) + simpa only [Real.norm_eq_abs] using hh + _ ≤ (Cq:ℝ)+|c| *(Cprod:ℝ) := by rw [abs_mul]; gcongr; exact hCq h x + _ = _ := rfl + exact fun n => hbounds n g hg + +end ZeroTemperatureSK.Heat + +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKSupport/Parabolic/VarianceTilted.lean b/lean/OAI/Probability/SKSupport/Parabolic/VarianceTilted.lean new file mode 100644 index 0000000000000000000000000000000000000000..7154641e9cab8810a4c48a30f76d6f8e3cf3ab05 --- /dev/null +++ b/lean/OAI/Probability/SKSupport/Parabolic/VarianceTilted.lean @@ -0,0 +1,126 @@ +import Mathlib +import OAI.Probability.SKSupport.Parabolic.UniformTiltedMeanBounds +import OAI.Probability.SKSupport.Foundations.ExponentialBoundLipschitz + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology ContDiff +noncomputable section +namespace ZeroTemperatureSK.Heat + +lemma varianceHeat_eq_semigroup_toNNReal {g : ℝ → ℝ} (hgm : Measurable g) (t x : ℝ) : + varianceHeat t g x = semigroup (Real.toNNReal t) g x := by + rw [semigroup_eq_scaled hgm] + unfold varianceHeat + have he : Real.sqrt ((Real.toNNReal t:ℝ≥0):ℝ) = Real.sqrt t := by + simp only [Real.sqrt, Real.toNNReal_coe] + rw [he] + +lemma varianceLogHeat_eq_logSemigroup_toNNReal {f : ℝ → ℝ} (hfm : Measurable f) (c t x : ℝ) : + varianceLogHeat c t f x = logSemigroup c (Real.toNNReal t) f x := by + by_cases hc : c = 0 + · simp only [varianceLogHeat, logSemigroup, hc, ↓reduceIte] + exact varianceHeat_eq_semigroup_toNNReal hfm t x + · simp only [varianceLogHeat, logSemigroup, hc, ↓reduceIte] + have hem : Measurable (fun z => Real.exp (c*f z)) := (measurable_const.mul hfm).exp + rw [varianceHeat_eq_semigroup_toNNReal hem t x] + +lemma uniform_logSemigroup_derivative_bounds {f : ℝ → ℝ} {K : ℝ≥0} + (hf : RegularDatum f) (hLip : LipschitzWith K f) {c : ℝ} (hc : 0 ≤ c) (n : ℕ) : + ∃ C : ℝ≥0, ∀ h : ℝ≥0, ∀ x, |iteratedDeriv (n+1) (logSemigroup c h f) x| ≤ C := by + by_cases hc0 : c = 0 + · subst c + obtain ⟨C,hC⟩ := uniform_tiltedMean_bounds (RegularDatum.const 0) + (LipschitzWith.const (0:ℝ)) hf.deriv_bounded (c := 0) le_rfl n + refine ⟨C, fun h x => ?_⟩ + have he : logSemigroup 0 h f = semigroup h f := by funext z; simp [logSemigroup] + have hd : deriv (semigroup h f) = semigroup h (deriv f) := funext (fun z => + (hasDerivAt_semigroup (hf.smooth.of_le (by simp)) hLip h z).deriv) + have hm : tiltedMean 0 h (fun _ => 0) (deriv f) = semigroup h (deriv f) := by + funext z; simp [tiltedMean, semigroup] + rw [he, iteratedDeriv_succ', hd] + simpa only [hm] using hC h x + · obtain ⟨C,hC⟩ := uniform_tiltedMean_bounds hf hLip hf.deriv_bounded hc n + refine ⟨C, fun h x => ?_⟩ + have hd : deriv (logSemigroup c h f) = tiltedMean c h f (deriv f) := funext (fun z => + (hasDerivAt_logSemigroup (hf.smooth.of_le (by simp)) hLip (lt_of_le_of_ne hc (Ne.symm hc0)) h z).deriv) + rw [iteratedDeriv_succ', hd] + exact hC h x + +lemma regularDatum_varianceLogHeat {f : ℝ → ℝ} {K : ℝ≥0} + (hf : RegularDatum f) (hLip : LipschitzWith K f) {c : ℝ} (hc : 0 ≤ c) (t : ℝ) : + RegularDatum (varianceLogHeat c t f) := by + have he : varianceLogHeat c t f = logSemigroup c (Real.toNNReal t) f := + funext (varianceLogHeat_eq_logSemigroup_toNNReal hf.smooth.continuous.measurable c t) + rw [he] + exact regularDatum_logSemigroup hf hLip hc _ + +lemma uniform_varianceLogHeat_derivative_bounds {f : ℝ → ℝ} {K : ℝ≥0} + (hf : RegularDatum f) (hLip : LipschitzWith K f) {c : ℝ} (hc : 0 ≤ c) (n : ℕ) : + ∃ C : ℝ≥0, ∀ t x : ℝ, |iteratedDeriv (n+1) (varianceLogHeat c t f) x| ≤ C := by + obtain ⟨C,hC⟩ := uniform_logSemigroup_derivative_bounds hf hLip hc n + refine ⟨C, fun t x => ?_⟩ + have he : varianceLogHeat c t f = logSemigroup c (Real.toNNReal t) f := + funext (varianceLogHeat_eq_logSemigroup_toNNReal hf.smooth.continuous.measurable c t) + rw [he] + exact hC _ x + +lemma varianceLogHeat_lipschitz {f : ℝ → ℝ} {K : ℝ≥0} (hf : LipschitzWith K f) + {c : ℝ} (hc : 0 ≤ c) (t : ℝ) : LipschitzWith K (varianceLogHeat c t f) := by + have he : varianceLogHeat c t f = logSemigroup c (Real.toNNReal t) f := + funext (varianceLogHeat_eq_logSemigroup_toNNReal hf.continuous.measurable c t) + rw [he] + exact logSemigroup_lipschitz hf hc _ + +def varianceTilted (c t : ℝ) (f g : ℝ → ℝ) (x : ℝ) := + varianceHeat t (fun z => g z*Real.exp (c*f z)) x / + varianceHeat t (fun z => Real.exp (c*f z)) x + +lemma varianceTilted_eq_tiltedMean {f g : ℝ → ℝ} (hfm : Measurable f) (hgm : Measurable g) + (c t x : ℝ) : varianceTilted c t f g x = tiltedMean c (Real.toNNReal t) f g x := by + unfold varianceTilted tiltedMean + have hwm : Measurable (fun z => g z*Real.exp (c*f z)) := hgm.mul ((measurable_const.mul hfm).exp) + have hem : Measurable (fun z => Real.exp (c*f z)) := (measurable_const.mul hfm).exp + rw [varianceHeat_eq_semigroup_toNNReal hwm t x, varianceHeat_eq_semigroup_toNNReal hem t x] + +lemma varianceTilted_bound {f g : ℝ → ℝ} {K G : ℝ≥0} (hf : LipschitzWith K f) + (hgm : Measurable g) (hG : ∀ z, |g z| ≤ G) (c t x : ℝ) : + |varianceTilted c t f g x| ≤ G := by + rw [varianceTilted_eq_tiltedMean hf.continuous.measurable hgm] + exact tiltedMean_bound hf hgm hG c _ x + +lemma weightExp_iteratedDeriv_weight {f g : ℝ → ℝ} (hf : RegularDatum f) + (hg : BoundedSmooth g) (c : ℝ) (n : ℕ) : + ∃ q : ℝ → ℝ, BoundedSmooth q ∧ + iteratedDeriv n (fun z => g z*Real.exp (c*f z)) = fun z => q z*Real.exp (c*f z) := by + induction n with + | zero => exact ⟨g, hg, by funext z; simp⟩ + | succ n IH => + obtain ⟨q,hq,he⟩ := IH + exact ⟨fun z => deriv q z+c*q z*deriv f z, weighted_derivative_boundedSmooth hf hq c, + by rw [iteratedDeriv_succ, he, deriv_weightExp hf hq c]⟩ + +lemma exponentialBound_weightExp_iteratedDeriv {f g : ℝ → ℝ} {K : ℝ≥0} + (hf : RegularDatum f) (hLip : LipschitzWith K f) (hg : BoundedSmooth g) (c : ℝ) (n : ℕ) : + ExponentialBound (iteratedDeriv n (fun z => g z*Real.exp (c*f z))) := by + obtain ⟨q,hq,he⟩ := weightExp_iteratedDeriv_weight hf hg c n + obtain ⟨G,hG⟩ := hq.bound + rw [he] + exact (exponentialBound_exp hLip c).bdd_mul hG + +end ZeroTemperatureSK.Heat + +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKSupport/Regularity/AbsExtend.lean b/lean/OAI/Probability/SKSupport/Regularity/AbsExtend.lean new file mode 100644 index 0000000000000000000000000000000000000000..5eb09a98e882f15c0310873ea508fada66ab5738 --- /dev/null +++ b/lean/OAI/Probability/SKSupport/Regularity/AbsExtend.lean @@ -0,0 +1,126 @@ +import Mathlib +import OAI.Probability.SKSupport.Foundations.Control + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section +namespace ZeroTemperatureSK + +variable {Ω : Type*} [MeasurableSpace Ω] + +@[simp] lemma OrderParameter.abs_extend (γ : OrderParameter) (s : ℝ) : + |extend γ.val s| = extend γ.val s := abs_of_nonneg (γ.extend_nonneg s) + +lemma Control.measurable_drift_integral {W : BrownianSystem Ω} (γ : OrderParameter) + (t : ℝ) (ht : t ≤ 1) (α : Control W (Real.toNNReal t)) : + Measurable (fun ω => ∫ s in t..1, extend γ.val s * α.val (Real.toNNReal (s - t)) ω) := by + simp_rw [intervalIntegral.integral_of_le ht] + exact ((γ.measurable_extend.comp measurable_fst).mul + (α.measurable_elapsed t)).stronglyMeasurable.integral_prod_left.measurable + +lemma Control.measurable_cost_integral {W : BrownianSystem Ω} (γ : OrderParameter) + (t : ℝ) (ht : t ≤ 1) (α : Control W (Real.toNNReal t)) : + Measurable (fun ω => ∫ s in t..1, extend γ.val s * (α.val (Real.toNNReal (s - t)) ω)^2) := by + simp_rw [intervalIntegral.integral_of_le ht] + exact ((γ.measurable_extend.comp measurable_fst).mul + ((α.measurable_elapsed t).pow_const 2)).stronglyMeasurable.integral_prod_left.measurable + +lemma Control.drift_integral_bound {W : BrownianSystem Ω} (γ : OrderParameter) + (t : ℝ) (ht : t ≤ 1) (α : Control W (Real.toNNReal t)) (ω : Ω) : + |∫ s in t..1, extend γ.val s * α.val (Real.toNNReal (s - t)) ω| ≤ + ∫ s in t..1, extend γ.val s := by + rw [← Real.norm_eq_abs] + apply intervalIntegral.norm_integral_le_of_norm_le ht _ γ.integrable.intervalIntegrable + exact Filter.Eventually.of_forall (fun s _ => by + simp only [Real.norm_eq_abs, abs_mul, γ.abs_extend] + simpa only [mul_one] using mul_le_mul_of_nonneg_left (α.bound _ _) (γ.extend_nonneg s)) + +lemma Control.cost_integral_bound {W : BrownianSystem Ω} (γ : OrderParameter) + (t : ℝ) (ht : t ≤ 1) (α : Control W (Real.toNNReal t)) (ω : Ω) : + |∫ s in t..1, extend γ.val s * (α.val (Real.toNNReal (s - t)) ω)^2| ≤ + ∫ s in t..1, extend γ.val s := by + rw [← Real.norm_eq_abs] + apply intervalIntegral.norm_integral_le_of_norm_le ht _ γ.integrable.intervalIntegrable + exact Filter.Eventually.of_forall (fun s _ => by + simp only [Real.norm_eq_abs, abs_mul, γ.abs_extend, abs_pow] + simpa only [one_pow, mul_one] using mul_le_mul_of_nonneg_left + (pow_le_pow_left₀ (abs_nonneg _) (α.bound _ _) 2) (γ.extend_nonneg s)) + +lemma controlPayoff_measurable (W : BrownianSystem Ω) (γ : OrderParameter) + (t x : ℝ) (ht : t ≤ 1) (α : Control W (Real.toNNReal t)) : + Measurable (controlPayoff W γ t x α) := by + exact (((measurable_const.add (W.measurable 1)).sub + (W.measurable (Real.toNNReal t))).add + (α.measurable_drift_integral γ t ht)).abs.sub + ((α.measurable_cost_integral γ t ht).const_mul _) + +lemma controlPayoff_abs_bound (W : BrownianSystem Ω) (γ : OrderParameter) + (t x : ℝ) (ht : t ≤ 1) (α : Control W (Real.toNNReal t)) (ω : Ω) : + |controlPayoff W γ t x α ω| ≤ |x + W.B 1 ω - W.B (Real.toNNReal t) ω| + + (3 / 2 : ℝ) * ∫ s in t..1, extend γ.val s := by + have hd := α.drift_integral_bound γ t ht ω + have hc := α.cost_integral_bound γ t ht ω + have htri := abs_add_le (x + W.B 1 ω - W.B (Real.toNNReal t) ω) + (∫ s in t..1, extend γ.val s * α.val (Real.toNNReal (s - t)) ω) + have hall := abs_sub + |x + W.B 1 ω - W.B (Real.toNNReal t) ω + + ∫ s in t..1, extend γ.val s * α.val (Real.toNNReal (s - t)) ω| + ((1 / 2 : ℝ) * ∫ s in t..1, extend γ.val s * (α.val (Real.toNNReal (s - t)) ω)^2) + simp only [abs_abs, abs_mul, abs_of_nonneg (by norm_num : (0 : ℝ) ≤ 1 / 2)] at hall + dsimp [controlPayoff] + linarith + +lemma controlPayoff_integrable (W : BrownianSystem Ω) (γ : OrderParameter) + (t x : ℝ) (ht : t ≤ 1) (α : Control W (Real.toNNReal t)) : + Integrable (controlPayoff W γ t x α) W.law := by + let := W.isProbability + have h := (((integrable_const x).add (W.brownian.integrable_eval 1)).sub + (W.brownian.integrable_eval (Real.toNNReal t))).abs.add + (integrable_const ((3 / 2 : ℝ) * ∫ s in t..1, extend γ.val s)) + exact h.mono' (controlPayoff_measurable W γ t x ht α).aestronglyMeasurable + (Filter.Eventually.of_forall (fun ω => controlPayoff_abs_bound W γ t x ht α ω)) + +lemma controlPayoff_le (W : BrownianSystem Ω) (γ : OrderParameter) + (t x : ℝ) (ht : t ≤ 1) (α : Control W (Real.toNNReal t)) (ω : Ω) : + controlPayoff W γ t x α ω ≤ |x + W.B 1 ω - W.B (Real.toNNReal t) ω| + + (1 / 2 : ℝ) * ∫ s in t..1, extend γ.val s := by + have habs : Integrable (fun s : ℝ => extend γ.val s * |α.val (Real.toNNReal (s - t)) ω|) := by + exact γ.integrable.mul_bdd + (((α.measurable_elapsed t).comp measurable_prodMk_right).abs.aestronglyMeasurable) + (Filter.Eventually.of_forall (fun s => by + simpa only [Real.norm_eq_abs, Function.comp_apply, abs_abs] using α.bound _ _)) + have hnorm : |∫ s in t..1, extend γ.val s * α.val (Real.toNNReal (s - t)) ω| ≤ + ∫ s in t..1, extend γ.val s * |α.val (Real.toNNReal (s - t)) ω| := by + simpa only [Real.norm_eq_abs, abs_mul, γ.abs_extend] using + (intervalIntegral.norm_integral_le_integral_norm (f := fun s => + extend γ.val s * α.val (Real.toNNReal (s - t)) ω) ht) + have hcomp := intervalIntegral.integral_mono_on ht + (habs.sub ((α.integrable_weighted_sq γ t ω).const_mul (1 / 2 : ℝ))).intervalIntegrable + (γ.integrable.const_mul (1 / 2 : ℝ)).intervalIntegrable + (fun s (_ : s ∈ Set.Icc t 1) => show + extend γ.val s * |α.val (Real.toNNReal (s - t)) ω| - + (1 / 2 : ℝ) * (extend γ.val s * (α.val (Real.toNNReal (s - t)) ω)^2) ≤ + (1 / 2 : ℝ) * extend γ.val s from by + have he : |α.val (Real.toNNReal (s - t)) ω| - + (1 / 2 : ℝ) * (α.val (Real.toNNReal (s - t)) ω)^2 ≤ 1 / 2 := by + nlinarith [sq_nonneg (|α.val (Real.toNNReal (s - t)) ω| - 1), + sq_abs (α.val (Real.toNNReal (s - t)) ω)] + nlinarith [mul_le_mul_of_nonneg_left he (γ.extend_nonneg s)]) + simp only [Pi.sub_apply] at hcomp + rw [intervalIntegral.integral_sub habs.intervalIntegrable + ((α.integrable_weighted_sq γ t ω).const_mul (1 / 2 : ℝ)).intervalIntegrable, + intervalIntegral.integral_const_mul, intervalIntegral.integral_const_mul] at hcomp + have htri := abs_add_le (x + W.B 1 ω - W.B (Real.toNNReal t) ω) + (∫ s in t..1, extend γ.val s * α.val (Real.toNNReal (s - t)) ω) + dsimp [controlPayoff] + linarith + +end ZeroTemperatureSK + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKSupport/Regularity/BoundedSmoothFamily.lean b/lean/OAI/Probability/SKSupport/Regularity/BoundedSmoothFamily.lean new file mode 100644 index 0000000000000000000000000000000000000000..eca087271d8d8f9af8b71b74124be9deebb263d1 --- /dev/null +++ b/lean/OAI/Probability/SKSupport/Regularity/BoundedSmoothFamily.lean @@ -0,0 +1,156 @@ +import Mathlib +import OAI.Probability.SKSupport.Foundations.Finite + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology ContDiff +noncomputable section +namespace ZeroTemperatureSK.Heat + +structure BoundedSmoothFamily (F : ℝ → ℝ → ℝ) : Prop where + measurable : Measurable (fun p : ℝ × ℝ => F p.1 p.2) + regular : ∀ t, BoundedSmooth (F t) + bounds : ∀ n : ℕ, ∃ C : ℝ≥0, ∀ t x, |iteratedDeriv n (F t) x| ≤ C + +lemma BoundedSmoothFamily.bound {F : ℝ → ℝ → ℝ} (hF : BoundedSmoothFamily F) : + ∃ C : ℝ≥0, ∀ t x, |F t x| ≤ C := by simpa using hF.bounds 0 + +lemma BoundedSmoothFamily.deriv {F : ℝ → ℝ → ℝ} (hF : BoundedSmoothFamily F) : + BoundedSmoothFamily (fun t => deriv (F t)) := by + refine ⟨measurable_spatial_deriv hF.measurable + (fun t => (hF.regular t).smooth.differentiable (by simp)),fun t => (hF.regular t).deriv,?_⟩ + intro n + simpa only [iteratedDeriv_succ'] using hF.bounds (n+1) + +lemma BoundedSmoothFamily.mul {F G : ℝ → ℝ → ℝ} + (hF : BoundedSmoothFamily F) (hG : BoundedSmoothFamily G) : + BoundedSmoothFamily (fun t x => F t x*G t x) := by + classical + refine ⟨hF.measurable.mul hG.measurable,fun t => (hF.regular t).mul (hG.regular t),?_⟩ + intro n + choose A hA using hF.bounds + choose B hB using hG.bounds + refine ⟨∑ j ∈ Finset.range (n+1), (n.choose j:ℝ≥0)*A j*B (n-j),fun t x => ?_⟩ + rw [iteratedDeriv_fun_mul (n := n) + ((hF.regular t).smooth.of_le (ENat.natCast_le_of_coe_top_le_withTop le_rfl n) |>.contDiffAt) + ((hG.regular t).smooth.of_le (ENat.natCast_le_of_coe_top_le_withTop le_rfl n) |>.contDiffAt)] + push_cast + apply (Finset.abs_sum_le_sum_abs _ _).trans + apply Finset.sum_le_sum + intro j hj + simp only [abs_mul,abs_of_nonneg (show (0:ℝ) ≤ (n.choose j:ℝ) from Nat.cast_nonneg _)] + gcongr + · exact hA j t x + · exact hB (n-j) t x + +lemma BoundedSmoothFamily.timeConst {d : ℝ → ℝ} {C : ℝ≥0} + (hm : Measurable d) (hC : ∀ t, |d t| ≤ C) : + BoundedSmoothFamily (fun t (_x : ℝ) => d t) := by + refine ⟨hm.comp measurable_fst,fun t => BoundedSmooth.const (d t),?_⟩ + intro n + cases n with + | zero => exact ⟨C,fun t x => by simpa only [iteratedDeriv_zero] using hC t⟩ + | succ n => exact ⟨0,fun t x => by simp [iteratedDeriv_const]⟩ + +lemma BoundedSmoothFamily.iteratedDeriv {F : ℝ → ℝ → ℝ} + (hF : BoundedSmoothFamily F) (n : ℕ) : + BoundedSmoothFamily (fun t => iteratedDeriv n (F t)) := by + induction n with + | zero => simpa only [iteratedDeriv_zero] using hF + | succ n ih => simpa only [iteratedDeriv_succ] using ih.deriv + +lemma finiteGradient_family {f : ℝ → ℝ} (hf : RegularDatum f) + (hLip : LipschitzWith 1 f) (c : ℕ → ℝ≥0) (h : ℝ≥0) (N i : ℕ) : + BoundedSmoothFamily (fun t => deriv (finiteValue c h f N i t)) := by + refine ⟨measurable_spatial_deriv (measurable_finiteValue hf hLip c h N i) + (fun t => (finiteValue_regular hf hLip c h N i t).smooth.differentiable (by simp)), + fun t => (finiteValue_regular hf hLip c h N i t).deriv_bounded,?_⟩ + intro n + simpa only [iteratedDeriv_succ'] using finiteValue_uniform_derivative_bounds hf hLip c h N i n + +lemma finiteCoeff_family (c : ℕ → ℝ≥0) (h : ℝ≥0) (N i : ℕ) : + BoundedSmoothFamily (fun t (_x : ℝ) => finiteCoeff c h N i t) := by + obtain ⟨C,hC⟩ := finiteCoeff_bounds c h N i + exact BoundedSmoothFamily.timeConst (measurable_finiteCoeff c h N i) + (fun t => by simpa only [abs_of_nonneg (hC t).1] using (hC t).2) + +lemma finiteSource_family {f : ℝ → ℝ} (hf : RegularDatum f) + (hLip : LipschitzWith 1 f) (c : ℕ → ℝ≥0) (h : ℝ≥0) (N i : ℕ) : + BoundedSmoothFamily (finiteSource c h f N i) := by + have hU := finiteGradient_family hf hLip c h N i + change BoundedSmoothFamily (fun t x => finiteCoeff c h N i t*(deriv (finiteValue c h f N i t) x)^2) + simpa only [pow_two] using (finiteCoeff_family c h N i).mul (hU.mul hU) + +def finiteBurgersSource (c : ℕ → ℝ≥0) (h : ℝ≥0) (f : ℝ → ℝ) (N i : ℕ) (t x : ℝ) : ℝ := + finiteCoeff c h N i t*(deriv (finiteValue c h f N i t) x*deriv (deriv (finiteValue c h f N i t)) x) + +lemma finiteBurgersSource_family {f : ℝ → ℝ} (hf : RegularDatum f) + (hLip : LipschitzWith 1 f) (c : ℕ → ℝ≥0) (h : ℝ≥0) (N i : ℕ) : + BoundedSmoothFamily (finiteBurgersSource c h f N i) := by + have hU := finiteGradient_family hf hLip c h N i + exact (finiteCoeff_family c h N i).mul (hU.mul hU.deriv) + +lemma deriv_finiteSource {f : ℝ → ℝ} (hf : RegularDatum f) + (hLip : LipschitzWith 1 f) (c : ℕ → ℝ≥0) (h : ℝ≥0) (N i : ℕ) (t : ℝ) : + deriv (finiteSource c h f N i t) = fun x => 2*finiteBurgersSource c h f N i t x := by + funext x + have hd := (((finiteValue_regular hf hLip c h N i t).deriv_bounded.smooth.differentiable (by simp) x).hasDerivAt.fun_pow 2).const_mul (finiteCoeff c h N i t) + change deriv (fun x => finiteCoeff c h N i t*(deriv (finiteValue c h f N i t) x)^2) x = _ + have hd' : deriv (fun z => finiteCoeff c h N i t*(deriv (finiteValue c h f N i t) z)^2) x = + finiteCoeff c h N i t*(2*deriv (finiteValue c h f N i t) x*deriv (deriv (finiteValue c h f N i t)) x) := by + simpa only [Nat.cast_ofNat,Nat.reduceSub,pow_one] using hd.deriv + rw [hd'] + simp only [finiteBurgersSource] + ring + +lemma finiteGradient_mild {f : ℝ → ℝ} (hf : RegularDatum f) + (hLip : LipschitzWith 1 f) (c : ℕ → ℝ≥0) (h : ℝ≥0) (N i : ℕ) + {a b : ℝ} (ha : 0 ≤ a) (hab : a ≤ b) (hb : b ≤ (N:ℝ)*h) (x : ℝ) : + deriv (finiteValue c h f N i a) x = varianceHeat (b-a) (deriv (finiteValue c h f N i b)) x+ + ∫ r in a..b, varianceHeat (r-a) (finiteBurgersSource c h f N i r) x := by + have hS := finiteSource_family hf hLip c h N i + obtain ⟨A,hA⟩ := hS.bound + obtain ⟨B,hB⟩ := hS.deriv.bound + have hDt := hasDerivAt_integral_varianceHeat hS.measurable hS.regular hA hB a b x + have hbreg := finiteValue_regular hf hLip c h N i b + have hbLip := finiteValue_lipschitz hLip c h N i b + have hHt : HasDerivAt (varianceHeat (b-a) (finiteValue c h f N i b)) + (varianceHeat (b-a) (deriv (finiteValue c h f N i b)) x) x := + hasDerivAt_scaled_space (hbreg.smooth.of_le (by simp)) (exponentialBound_of_lipschitz hbLip) + (ExponentialBound.of_bounded (A := 1) (fun z => by + simpa only [Real.norm_eq_abs,NNReal.coe_one] using norm_deriv_le_of_lipschitz (x₀ := z) hbLip)) (Real.sqrt (b-a)) x + have heFun : finiteValue c h f N i a = fun z => + varianceHeat (b-a) (finiteValue c h f N i b) z+ + (1/2)*(∫ r in a..b, varianceHeat (r-a) (finiteSource c h f N i r) z) := + funext (finiteValue_mild hf hLip c h N i ha hab hb) + have hdR : deriv (fun z => varianceHeat (b-a) (finiteValue c h f N i b) z+ + (1/2)*(∫ r in a..b, varianceHeat (r-a) (finiteSource c h f N i r) z)) x = + varianceHeat (b-a) (deriv (finiteValue c h f N i b)) x+ + (1/2)*(∫ r in a..b, varianceHeat (r-a) (deriv (finiteSource c h f N i r)) x) := + (hHt.add (hDt.const_mul (1/2))).deriv + rw [heFun,hdR] + simp_rw [deriv_finiteSource hf hLip,varianceHeat_const_mul] + rw [intervalIntegral.integral_const_mul] + ring + +end ZeroTemperatureSK.Heat + +open MeasureTheory Set Filter +open scoped Topology +noncomputable section + +end +end +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKSupport/Regularity/ClosedTime.lean b/lean/OAI/Probability/SKSupport/Regularity/ClosedTime.lean new file mode 100644 index 0000000000000000000000000000000000000000..18c380c23f888e09d737b45c19103a96112abb62 --- /dev/null +++ b/lean/OAI/Probability/SKSupport/Regularity/ClosedTime.lean @@ -0,0 +1,81 @@ +import Mathlib +import OAI.Probability.SKSupport.Model + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section +namespace ZeroTemperatureSK + +abbrev ClosedTime := Set.Icc (0 : ℝ) 1 + +variable {Ω : Type*} [MeasurableSpace Ω] + +def closedFiltration (W : BrownianSystem Ω) : Filtration ClosedTime ‹MeasurableSpace Ω› where + seq t := Filtration.natural W.B (fun s => (W.measurable s).stronglyMeasurable) (Real.toNNReal t) + mono' := fun _ _ h => (Filtration.natural W.B + (fun s => (W.measurable s).stronglyMeasurable)).mono (Real.toNNReal_mono h) + le' t := (Filtration.natural W.B (fun s => (W.measurable s).stronglyMeasurable)).le (Real.toNNReal t) + +def terminalGradient (W : BrownianSystem Ω) (γ : OrderParameter) + (X : ℝ≥0 → Ω → ℝ) (U₁ : Ω → ℝ) (t : ClosedTime) : Ω → ℝ := + if (t : ℝ) < 1 then fun ω => gradient W γ t (X (Real.toNNReal t) ω) else U₁ + +abbrev GaussianSample (N : ℕ) := Fin (N+1) → ℝ + +def gaussianLaw (N : ℕ) : Measure (GaussianSample N) := + Measure.pi (fun _ => gaussianReal 0 1) + +def gaussianCoordinate (N i : ℕ) (z : GaussianSample N) : ℝ := + if hi : i < N+1 then z ⟨i, hi⟩ else 0 + +def meshStep (T : ℝ) (N : ℕ) : ℝ := T / N + +def meshTime (T : ℝ) (N j : ℕ) : ℝ := j * meshStep T N + +def eulerState (W : BrownianSystem Ω) (γ : OrderParameter) (T : ℝ) (N : ℕ) : + ℕ → GaussianSample N → ℝ + | 0, _ => 0 + | j+1, z => eulerState W γ T N j z + Real.sqrt (meshStep T N) * gaussianCoordinate N j z + + meshStep T N * extend γ.val (meshTime T N j) * + gradient W γ (meshTime T N j) (eulerState W γ T N j z) + +def eulerCurvatureMoment (W : BrownianSystem Ω) (γ : OrderParameter) + (T : ℝ) (N j : ℕ) : ℝ := + ∫ z, (curvature W γ (meshTime T N (j-1)) (eulerState W γ T N (j-1) z))^2 ∂gaussianLaw N + +def eulerNormalizer (W : BrownianSystem Ω) (γ : OrderParameter) + (T : ℝ) (N j : ℕ) : ℝ := (Real.sqrt (eulerCurvatureMoment W γ T N j))⁻¹ + +def normalizedIncrement (W : BrownianSystem Ω) (γ : OrderParameter) + (T : ℝ) (N j : ℕ) (z : GaussianSample N) : ℝ := + eulerNormalizer W γ T N j * + curvature W γ (meshTime T N (j-1)) (eulerState W γ T N (j-1) z) * + gaussianCoordinate N (j-1) z + +def randomizedSign (W : BrownianSystem Ω) (γ : OrderParameter) + (T : ℝ) (N : ℕ) (z : GaussianSample N) : ℝ := + (SignType.sign (gradient W γ T (eulerState W γ T N N z) + + 2 * cdf (gaussianReal 0 1) (gaussianCoordinate N N z) - 1) : ℝ) + +def gaussianCoeffA (W : BrownianSystem Ω) (γ : OrderParameter) + (T : ℝ) (N j : ℕ) : ℝ := + if j = 0 then 0 else + ∫ z, randomizedSign W γ T N z * normalizedIncrement W γ T N j z ∂gaussianLaw N + +def gaussianCoeffB (W : BrownianSystem Ω) (γ : OrderParameter) + (T : ℝ) (N i : ℕ) : ℝ := + ∫ z, randomizedSign W γ T N z * gaussianCoordinate N (i-1) z ∂gaussianLaw N + +def gaussianValueSum (W : BrownianSystem Ω) (γ : OrderParameter) + (T : ℝ) (N : ℕ) : ℝ := + ∑ j ∈ Finset.range (N+1), gaussianCoeffA W γ T N j * gaussianCoeffB W γ T N (j+1) + +end ZeroTemperatureSK + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKSupport/Regularity/FamilyDifferentiation.lean b/lean/OAI/Probability/SKSupport/Regularity/FamilyDifferentiation.lean new file mode 100644 index 0000000000000000000000000000000000000000..10be55db0caf696eb30fc27a3825091da5f63dd2 --- /dev/null +++ b/lean/OAI/Probability/SKSupport/Regularity/FamilyDifferentiation.lean @@ -0,0 +1,162 @@ +import Mathlib +import OAI.Probability.SKSupport.Foundations.Taylor1Bound +import OAI.Probability.SKSupport.Regularity.BoundedSmoothFamily + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology ContDiff +noncomputable section +namespace ZeroTemperatureSK.Heat + +lemma BoundedSmoothFamily.add {F G : ℝ → ℝ → ℝ} + (hF : BoundedSmoothFamily F) (hG : BoundedSmoothFamily G) : + BoundedSmoothFamily (fun t x => F t x+G t x) := by + refine ⟨hF.measurable.add hG.measurable,fun t => (hF.regular t).add (hG.regular t),?_⟩ + intro n + obtain ⟨A,hA⟩ := hF.bounds n + obtain ⟨B,hB⟩ := hG.bounds n + refine ⟨A+B,fun t x => ?_⟩ + rw [iteratedDeriv_fun_add (n := n) + ((hF.regular t).smooth.of_le (ENat.natCast_le_of_coe_top_le_withTop le_rfl n) |>.contDiffAt) + ((hG.regular t).smooth.of_le (ENat.natCast_le_of_coe_top_le_withTop le_rfl n) |>.contDiffAt)] + exact (abs_add_le _ _).trans (add_le_add (hA t x) (hB t x)) + +lemma BoundedSmoothFamily.const_mul {F : ℝ → ℝ → ℝ} + (hF : BoundedSmoothFamily F) (c : ℝ) : BoundedSmoothFamily (fun t x => c*F t x) := + (BoundedSmoothFamily.timeConst (C := Real.nnabs c) measurable_const (fun _ => by simp [Real.coe_nnabs])).mul hF + +lemma BoundedSmoothFamily.intervalIntegrable {F : ℝ → ℝ → ℝ} + (hF : BoundedSmoothFamily F) (x a b : ℝ) : IntervalIntegrable (fun t => F t x) volume a b := by + obtain ⟨C,hC⟩ := hF.bound + apply (intervalIntegrable_const (c := (C:ℝ))).mono_fun + (hF.measurable.comp (measurable_id.prodMk measurable_const)).aestronglyMeasurable + filter_upwards [] with t + simpa only [Function.comp_apply, id_eq, Real.norm_eq_abs,abs_of_nonneg C.coe_nonneg] using hC t x + +lemma BoundedSmoothFamily.hasDerivAt_integral {F : ℝ → ℝ → ℝ} + (hF : BoundedSmoothFamily F) (a b x : ℝ) : + HasDerivAt (fun z => ∫ t in a..b, F t z) (∫ t in a..b, _root_.deriv (F t) x) x := by + obtain ⟨C,hC⟩ := hF.deriv.bound + refine (intervalIntegral.hasDerivAt_integral_of_dominated_loc_of_deriv_le + (F := fun z t => F t z) (F' := fun z t => _root_.deriv (F t) z) + (bound := fun _ => (C:ℝ)) (s := Set.univ) (Filter.univ_mem) + (Eventually.of_forall (fun z => (hF.measurable.comp + (measurable_id.prodMk measurable_const)).aestronglyMeasurable)) + (hF.intervalIntegrable x a b) ((hF.deriv.measurable.comp + (measurable_id.prodMk measurable_const)).aestronglyMeasurable) ?_ + (intervalIntegrable_const) ?_).2 + · filter_upwards [] with t ht z hz + exact hC t z + · filter_upwards [] with t ht z hz + exact ((hF.regular t).smooth.differentiable (by simp) z).hasDerivAt + +lemma BoundedSmoothFamily.iteratedDeriv_integral {F : ℝ → ℝ → ℝ} + (hF : BoundedSmoothFamily F) (n : ℕ) (a b x : ℝ) : + _root_.iteratedDeriv n (fun z => ∫ t in a..b, F t z) x = + ∫ t in a..b, _root_.iteratedDeriv n (F t) x := by + induction n generalizing x with + | zero => rfl + | succ n hn => + have he : _root_.iteratedDeriv n (fun z => ∫ t in a..b, F t z) = + fun z => ∫ t in a..b, _root_.iteratedDeriv n (F t) z := funext hn + rw [iteratedDeriv_succ,he] + simpa only [iteratedDeriv_succ] using ((hF.iteratedDeriv n).hasDerivAt_integral a b x).deriv + +end ZeroTemperatureSK.Heat + +end +end +section +open Set Filter MeasureTheory ProbabilityTheory +open scoped Topology ContDiff NNReal ENNReal +noncomputable section +namespace ZeroTemperatureSK.Heat + +lemma tendstoUniformlyOn_deriv_family {A : Type*} {S : Set A} + {f : ℕ → A → ℝ → ℝ} {g : A → ℝ → ℝ} + (hf : ∀ n, ∀ t ∈ S, ContDiff ℝ 2 (f n t)) + (hg : ∀ t ∈ S, ContDiff ℝ 2 (g t)) {C : ℝ} (hC : 0 ≤ C) + (hb : ∀ n, ∀ t ∈ S, ∀ x, |deriv (deriv (f n t)) x| ≤ C) + (hbg : ∀ t ∈ S, ∀ x, |deriv (deriv (g t)) x| ≤ C) + (hlim : TendstoUniformlyOn (fun n (p : A × ℝ) => f n p.1 p.2) + (fun p => g p.1 p.2) atTop (S ×ˢ Set.univ)) : + TendstoUniformlyOn (fun n (p : A × ℝ) => deriv (f n p.1) p.2) + (fun p => deriv (g p.1) p.2) atTop (S ×ˢ Set.univ) := by + rw [Metric.tendstoUniformlyOn_iff] at hlim ⊢ + intro ε hε + let h : ℝ := ε / (2*C+1) + have hh : 0 < h := div_pos hε (by positivity) + filter_upwards [hlim (ε*h/4) (by positivity)] with n hn p hp + have hA : ∀ x, |(f n p.1-g p.1) x| ≤ ε*h/4 := by + intro x + exact le_of_lt (by simpa only [Real.dist_eq,Pi.sub_apply,abs_sub_comm] using hn (p.1,x) ⟨hp.1,mem_univ _⟩) + have hd (x : ℝ) : deriv (f n p.1-g p.1) x = deriv (f n p.1) x-deriv (g p.1) x := + deriv_sub ((hf n p.1 hp.1).differentiable (by norm_num) x) + ((hg p.1 hp.1).differentiable (by norm_num) x) + have hdd (x : ℝ) : deriv (deriv (f n p.1-g p.1)) x = + deriv (deriv (f n p.1)) x-deriv (deriv (g p.1)) x := by + rw [show deriv (f n p.1-g p.1) = deriv (f n p.1)-deriv (g p.1) from funext hd] + exact deriv_sub + (by simpa only [iteratedDeriv_one] using (hf n p.1 hp.1).differentiable_iteratedDeriv 1 (by norm_num) x) + (by simpa only [iteratedDeriv_one] using (hg p.1 hp.1).differentiable_iteratedDeriv 1 (by norm_num) x) + have hB : ∀ x, |deriv (deriv (f n p.1-g p.1)) x| ≤ 2*C := by + intro x + rw [hdd] + exact (abs_sub _ _).trans (by linarith [hb n p.1 hp.1 x,hbg p.1 hp.1 x]) + have hi := derivative_interpolation ((hf n p.1 hp.1).sub (hg p.1 hp.1)) hA hB hh p.2 + have hc : h*(2*C) < ε := by + dsimp [h] + rw [div_mul_eq_mul_div] + apply (div_lt_iff₀ (by positivity : (0:ℝ)<2*C+1)).mpr + nlinarith + have he : 2*(ε*h/4)/h = ε/2 := by field_simp; ring + change |deriv (f n p.1-g p.1) p.2| ≤ 2*(ε*h/4)/h+h*(2*C)/2 at hi + rw [he,hd] at hi + rw [Real.dist_eq,abs_sub_comm] + linarith + +lemma continuousOn_deriv_family {A : Type*} [TopologicalSpace A] {S : Set A} + {f : A → ℝ → ℝ} (hc : ContinuousOn (fun p : A × ℝ => f p.1 p.2) (S ×ˢ Set.univ)) + (hf : ∀ t ∈ S, ContDiff ℝ 2 (f t)) {C : ℝ} (hC : 0 ≤ C) + (hb : ∀ t ∈ S, ∀ x, |deriv (deriv (f t)) x| ≤ C) : + ContinuousOn (fun p : A × ℝ => deriv (f p.1) p.2) (S ×ˢ Set.univ) := by + let h : ℕ → ℝ := fun n => 1/((n+1:ℕ):ℝ) + have hh (n : ℕ) : 0 < h n := by dsimp [h]; positivity + have hlim : Tendsto h atTop (𝓝 0) := by + simpa only [h,Nat.cast_add,Nat.cast_one] using (tendsto_one_div_add_atTop_nhds_zero_nat : Tendsto (fun n : ℕ => 1/((n:ℝ)+1)) atTop (𝓝 0)) + let F : ℕ → A × ℝ → ℝ := fun n p => (f p.1 (p.2+h n)-f p.1 p.2)/h n + have hcont (n : ℕ) : ContinuousOn (F n) (S ×ˢ Set.univ) := by + dsimp [F] + apply ContinuousOn.div_const + apply ContinuousOn.sub _ hc + apply hc.comp (continuous_fst.prodMk (continuous_snd.add_const (h n))).continuousOn + intro p hp + exact ⟨hp.1,mem_univ _⟩ + have hconv : TendstoUniformlyOn F (fun p => deriv (f p.1) p.2) atTop (S ×ˢ Set.univ) := by + rw [Metric.tendstoUniformlyOn_iff] + intro ε hε + have hc0 : Tendsto (fun n => C/2*h n) atTop (𝓝 0) := by + simpa only [mul_zero] using tendsto_const_nhds.mul hlim (a := C/2) + filter_upwards [hc0.eventually (Metric.ball_mem_nhds 0 hε)] with n hn p hp + rw [Real.dist_eq,sub_zero, + abs_of_nonneg (mul_nonneg (div_nonneg hC (by norm_num)) (hh n).le)] at hn + have ht := taylor1_bound (hf p.1 hp.1) (hb p.1 hp.1) p.2 (h n) + have hb' : |F n p-deriv (f p.1) p.2| ≤ C/2*h n := by + dsimp [F] + have he : (f p.1 (p.2+h n)-f p.1 p.2)/h n-deriv (f p.1) p.2 = + (f p.1 (p.2+h n)-f p.1 p.2-deriv (f p.1) p.2*h n)/h n := by field_simp [ne_of_gt (hh n)] + rw [he,abs_div,abs_of_pos (hh n),div_le_iff₀ (hh n)] + rw [abs_of_pos (hh n)] at ht + nlinarith + rw [Real.dist_eq,abs_sub_comm] + exact hb'.trans_lt hn + exact hconv.continuousOn (Filter.Eventually.of_forall hcont).frequently + +end ZeroTemperatureSK.Heat + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKSupport/Regularity/GaussianFlowRegularity.lean b/lean/OAI/Probability/SKSupport/Regularity/GaussianFlowRegularity.lean new file mode 100644 index 0000000000000000000000000000000000000000..56073019607303637ac181bd0bf18252233c394d --- /dev/null +++ b/lean/OAI/Probability/SKSupport/Regularity/GaussianFlowRegularity.lean @@ -0,0 +1,122 @@ +import Mathlib +import OAI.Probability.SKSupport.Regularity.FamilyDifferentiation + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology ContDiff +noncomputable section +namespace ZeroTemperatureSK.Heat + +lemma BoundedSmoothFamily.continuousOn_iteratedDeriv {F : ℝ → ℝ → ℝ} {S : Set ℝ} + (hF : BoundedSmoothFamily F) + (hc : ContinuousOn (fun p : ℝ × ℝ => F p.1 p.2) (S ×ˢ univ)) (n : ℕ) : + ContinuousOn (fun p : ℝ × ℝ => _root_.iteratedDeriv n (F p.1) p.2) (S ×ˢ univ) := by + induction n with + | zero => exact hc + | succ n hn => + obtain ⟨C,hC⟩ := (hF.iteratedDeriv n).deriv.deriv.bound + simpa only [iteratedDeriv_succ] using continuousOn_deriv_family hn + (fun t _ => ((hF.iteratedDeriv n).regular t).smooth.of_le + (ENat.natCast_le_of_coe_top_le_withTop le_rfl 2)) C.coe_nonneg + (fun t _ x => hC t x) + +lemma varianceGradient_family {f : ℝ → ℝ} {K : ℝ≥0} + (hf : RegularDatum f) (hLip : LipschitzWith K f) {c : ℝ} (hc : 0 ≤ c) : + BoundedSmoothFamily (fun t => deriv (varianceLogHeat c t f)) := by + have hm : Measurable (fun p : ℝ × ℝ => varianceLogHeat c p.1 f p.2) := by + have hh := (measurable_backward hf.smooth.continuous.measurable c 0).comp + (measurable_fst.neg.prodMk measurable_snd) + simpa only [Function.comp_def,Pi.neg_apply,backward,zero_sub,neg_neg] using hh + refine ⟨measurable_spatial_deriv hm (fun t => + (regularDatum_varianceLogHeat hf hLip hc t).smooth.differentiable (by simp)), + fun t => (regularDatum_varianceLogHeat hf hLip hc t).deriv_bounded,?_⟩ + intro n + simpa only [iteratedDeriv_succ'] using uniform_varianceLogHeat_derivative_bounds hf hLip hc n + +lemma varianceGradient_continuousOn {f : ℝ → ℝ} {K : ℝ≥0} + (hf : RegularDatum f) (hLip : LipschitzWith K f) {c : ℝ} (hc : 0 ≤ c) (T : ℝ) : + ContinuousOn (fun p : ℝ × ℝ => deriv (varianceLogHeat c p.1 f) p.2) (Icc (0:ℝ) T ×ˢ univ) := by + obtain ⟨L,hL⟩ := varianceTilted_joint_bound hf hLip hf.deriv_bounded hc + apply continuousOn_of_joint_bound (F := fun t => deriv (varianceLogHeat c t f)) (L := L) + intro t ht s hs x y + rw [deriv_varianceLogHeat_tilted hf hLip hc,deriv_varianceLogHeat_tilted hf hLip hc] + exact hL t ht.1 s hs.1 x y + +def gaussianRate (c : ℝ) (f : ℝ → ℝ) (t x : ℝ) : ℝ := + (1/2:ℝ)*deriv (deriv (varianceLogHeat c t f)) x+ + c/2*(deriv (varianceLogHeat c t f) x)^2 + +lemma gaussianRate_family {f : ℝ → ℝ} {K : ℝ≥0} + (hf : RegularDatum f) (hLip : LipschitzWith K f) {c : ℝ} (hc : 0 ≤ c) : + BoundedSmoothFamily (gaussianRate c f) := by + have hu := varianceGradient_family hf hLip hc + convert (hu.deriv.const_mul (1/2:ℝ)).add ((hu.mul hu).const_mul (c/2)) using 1 + funext t x + simp only [gaussianRate,pow_two] + +lemma gaussianRate_continuousOn {f : ℝ → ℝ} {K : ℝ≥0} + (hf : RegularDatum f) (hLip : LipschitzWith K f) {c : ℝ} (hc : 0 ≤ c) (T : ℝ) : + ContinuousOn (fun p : ℝ × ℝ => gaussianRate c f p.1 p.2) (Icc (0:ℝ) T ×ˢ univ) := by + have hu := varianceGradient_continuousOn hf hLip hc T + have hv := (varianceGradient_family hf hLip hc).continuousOn_iteratedDeriv hu 1 + convert ((continuousOn_const (c := (1/2:ℝ))).mul hv).add + ((continuousOn_const (c := c/2)).mul (hu.pow 2)) using 1 + funext p + simp only [gaussianRate,iteratedDeriv_one,Pi.add_apply,Pi.mul_apply,Pi.pow_apply] + +lemma varianceLogHeat_integral_rate {f : ℝ → ℝ} {K : ℝ≥0} + (hf : RegularDatum f) (hLip : LipschitzWith K f) {c a b : ℝ} + (hc : 0 ≤ c) (ha : 0 ≤ a) (hab : a ≤ b) (x : ℝ) : + (∫ t in a..b, gaussianRate c f t x) = varianceLogHeat c b f x-varianceLogHeat c a f x := by + apply intervalIntegral.integral_eq_sub_of_hasDerivAt_of_le hab + · intro t ht + exact (varianceLogHeat_equation hf hLip c (ha.trans ht.1) x).continuousWithinAt.mono + (fun s hs => ha.trans hs.1) + · intro t ht + exact (varianceLogHeat_equation hf hLip c (ha.trans ht.1.le) x).hasDerivAt + (Ici_mem_nhds (ha.trans_lt ht.1)) + · exact (gaussianRate_family hf hLip hc).intervalIntegrable x a b + +lemma gaussianRate_integral_derivative {f : ℝ → ℝ} {K : ℝ≥0} + (hf : RegularDatum f) (hLip : LipschitzWith K f) {c a b : ℝ} + (hc : 0 ≤ c) (ha : 0 ≤ a) (hab : a ≤ b) (n : ℕ) (x : ℝ) : + (∫ t in a..b, iteratedDeriv n (gaussianRate c f t) x) = + iteratedDeriv n (varianceLogHeat c b f) x-iteratedDeriv n (varianceLogHeat c a f) x := by + have he : (fun z => ∫ t in a..b, gaussianRate c f t z) = + fun z => varianceLogHeat c b f z-varianceLogHeat c a f z := + funext (varianceLogHeat_integral_rate hf hLip hc ha hab) + have hh := (gaussianRate_family hf hLip hc).iteratedDeriv_integral n a b x + rw [he,iteratedDeriv_fun_sub (n := n) + ((regularDatum_varianceLogHeat hf hLip hc b).smooth.of_le + (ENat.natCast_le_of_coe_top_le_withTop le_rfl n) |>.contDiffAt) + ((regularDatum_varianceLogHeat hf hLip hc a).smooth.of_le + (ENat.natCast_le_of_coe_top_le_withTop le_rfl n) |>.contDiffAt)] at hh + exact hh.symm + +lemma hasDerivAt_varianceLogHeat_derivative {f : ℝ → ℝ} {K : ℝ≥0} + (hf : RegularDatum f) (hLip : LipschitzWith K f) {c t : ℝ} + (hc : 0 ≤ c) (ht : 0 < t) (n : ℕ) (x : ℝ) : + HasDerivAt (fun s => iteratedDeriv n (varianceLogHeat c s f) x) + (iteratedDeriv n (gaussianRate c f t) x) t := by + have hF := (gaussianRate_family hf hLip hc).iteratedDeriv n + have hj := (gaussianRate_family hf hLip hc).continuousOn_iteratedDeriv + (gaussianRate_continuousOn hf hLip hc (t+1)) n + have hcont : ContinuousAt (fun s => iteratedDeriv n (gaussianRate c f s) x) t := by + have hh := hj.comp (f := fun s : ℝ => (s,x)) (continuous_id.prodMk continuous_const).continuousOn + (fun s (hs : s ∈ Icc (0:ℝ) (t+1)) => ⟨hs,mem_univ _⟩) + exact (hh t ⟨ht.le,by linarith⟩).continuousAt (Icc_mem_nhds ht (by linarith)) + have hi := intervalIntegral.integral_hasDerivAt_right (hF.intervalIntegrable x 0 t) + ((hF.measurable.comp (measurable_id.prodMk measurable_const)).stronglyMeasurable.stronglyMeasurableAtFilter) hcont + apply (hi.const_add (iteratedDeriv n (varianceLogHeat c 0 f) x)).congr_of_eventuallyEq + filter_upwards [Ioi_mem_nhds ht] with s hs + rw [gaussianRate_integral_derivative hf hLip hc le_rfl hs.le n x] + ring + +end ZeroTemperatureSK.Heat + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKSupport/Regularity/GaussianValueContinuity.lean b/lean/OAI/Probability/SKSupport/Regularity/GaussianValueContinuity.lean new file mode 100644 index 0000000000000000000000000000000000000000..94c767af0c42db6d88b46048093d1b9d2654f194 --- /dev/null +++ b/lean/OAI/Probability/SKSupport/Regularity/GaussianValueContinuity.lean @@ -0,0 +1,52 @@ +import Mathlib +import OAI.Probability.SKSupport.Parabolic.VarianceTilted + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology ContDiff +noncomputable section +namespace ZeroTemperatureSK.Heat + +lemma varianceLogHeat_time_continuous {f : ℝ → ℝ} {K : ℝ≥0} + (hf : RegularDatum f) (hLip : LipschitzWith K f) (c x : ℝ) : + Continuous (fun t => varianceLogHeat c t f x) := by + by_cases hc : c=0 + · subst c + simpa only [varianceLogHeat,↓reduceIte] using + continuous_varianceHeat hf.smooth.continuous (exponentialBound_of_lipschitz hLip) x + · change Continuous (fun t => if c=0 then _ else _) + simp only [hc,↓reduceIte] + exact ((continuous_varianceHeat (Real.continuous_exp.comp (continuous_const.mul hf.smooth.continuous)) + (exponentialBound_exp hLip c) x).log + (fun t => ne_of_gt (varianceHeat_exp_pos hLip c t x))).div_const c + +lemma varianceLogHeat_joint_continuous {f : ℝ → ℝ} {K : ℝ≥0} + (hf : RegularDatum f) (hLip : LipschitzWith K f) {c : ℝ} (hc : 0 ≤ c) : + Continuous (fun p : ℝ × ℝ => varianceLogHeat c p.1 f p.2) := by + apply continuous_iff_continuousAt.mpr + intro p + let F := fun q : ℝ × ℝ => varianceLogHeat c q.1 f q.2 + have hlim : Tendsto (fun q : ℝ × ℝ => (K:ℝ)*|q.2-p.2|+ + |varianceLogHeat c q.1 f p.2-varianceLogHeat c p.1 f p.2|) (𝓝 p) (𝓝 0) := by + have hh : Continuous (fun q : ℝ × ℝ => (K:ℝ)*|q.2-p.2|+ + |varianceLogHeat c q.1 f p.2-varianceLogHeat c p.1 f p.2|) := by + exact (continuous_const.mul (continuous_snd.sub continuous_const).abs).add + (((varianceLogHeat_time_continuous hf hLip c p.2).comp continuous_fst).sub continuous_const).abs + simpa only [sub_self,abs_zero,mul_zero,add_zero] using hh.continuousAt.tendsto (x := p) + change Tendsto (fun q : ℝ × ℝ => varianceLogHeat c q.1 f q.2) (𝓝 p) (𝓝 (varianceLogHeat c p.1 f p.2)) + rw [Metric.tendsto_nhds] + intro ε hε + filter_upwards [hlim.eventually (gt_mem_nhds hε)] with q hq + have hb := (varianceLogHeat_lipschitz hLip hc q.1).dist_le_mul q.2 p.2 + have htri := dist_triangle (F q) (varianceLogHeat c q.1 f p.2) (F p) + simp only [Real.dist_eq] at hb htri ⊢ + exact (htri.trans (add_le_add hb le_rfl)).trans_lt hq + +end ZeroTemperatureSK.Heat + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKSupport/Regularity/IntegralTimeStep.lean b/lean/OAI/Probability/SKSupport/Regularity/IntegralTimeStep.lean new file mode 100644 index 0000000000000000000000000000000000000000..c510cf63b396eb6301f01ca6b9bd83d3a1f08b21 --- /dev/null +++ b/lean/OAI/Probability/SKSupport/Regularity/IntegralTimeStep.lean @@ -0,0 +1,190 @@ +import Mathlib +import OAI.Probability.SKSupport.Moments.NormalFirstMoment +import OAI.Probability.SKSupport.Regularity.BoundedSmoothFamily +import OAI.Probability.SKSupport.Regularity.FamilyDifferentiation + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section +namespace ZeroTemperatureSK.WeakIto +open Heat + +lemma BoundedSmoothFamily_lipschitz {F : ℝ → ℝ → ℝ} (hF : BoundedSmoothFamily F) : + ∃ L : ℝ≥0, ∀ t, LipschitzWith L (F t) := by + obtain ⟨L,hL⟩ := hF.deriv.bound + refine ⟨L,fun t => lipschitzWith_of_nnnorm_deriv_le + ((hF.regular t).smooth.differentiable (by simp)) (fun x => ?_)⟩ + exact_mod_cast hL t x + +lemma time_integral_spatial_bound {D : ℝ → ℝ → ℝ} (hD : BoundedSmoothFamily D) + {L : ℝ≥0} (hL : ∀ t, LipschitzWith L (D t)) (a b x z : ℝ) : + |(∫ r in a..b, D r z)-(∫ r in a..b, D r x)| ≤ + (L:ℝ)*|b-a| *|z-x| := by + rw [← intervalIntegral.integral_sub (hD.intervalIntegrable z a b) (hD.intervalIntegrable x a b)] + have hh := intervalIntegral.norm_integral_le_of_norm_le_const + (f := fun r => D r z-D r x) (C := (L:ℝ)*|z-x|) + (fun r (_hr : r ∈ uIoc a b) => by + simpa only [Real.norm_eq_abs] using (hL r).norm_sub_le z x) + simpa only [Real.norm_eq_abs,mul_right_comm] using hh + +variable {Ω : Type*} [MeasurableSpace Ω] {P : Measure Ω} + +lemma integrable_family_comp [IsFiniteMeasure P] {F : ℝ → ℝ → ℝ} + (hF : BoundedSmoothFamily F) (t : ℝ) {Y : Ω → ℝ} (hY : Measurable Y) : + Integrable (fun ω => F t (Y ω)) P := by + obtain ⟨C,hC⟩ := hF.bound + exact Integrable.of_bound (((hF.regular t).smooth.continuous.measurable).comp hY).aestronglyMeasurable + C (Eventually.of_forall (fun ω => hC t (Y ω))) + +lemma measurable_family_integral {D : ℝ → ℝ → ℝ} (hD : BoundedSmoothFamily D) (a b : ℝ) : + Measurable (fun x => ∫ r in a..b, D r x) := + (show Differentiable ℝ (fun x => ∫ r in a..b, D r x) from + fun x => (hD.hasDerivAt_integral a b x).differentiableAt).continuous.measurable + +lemma integrable_family_integral_comp [IsFiniteMeasure P] {D : ℝ → ℝ → ℝ} + (hD : BoundedSmoothFamily D) (a b : ℝ) {Y : Ω → ℝ} (hY : Measurable Y) : + Integrable (fun ω => ∫ r in a..b, D r (Y ω)) P := by + obtain ⟨C,hC⟩ := hD.bound + apply Integrable.of_bound ((measurable_family_integral hD a b).comp hY).aestronglyMeasurable + ((C:ℝ)*|b-a|) + filter_upwards [] with ω + exact intervalIntegral.norm_integral_le_of_norm_le_const (fun r _ => hC r (Y ω)) + +lemma expected_integral_time_step {B : ℝ≥0 → Ω → ℝ} + (hB : IsPreBrownianReal B P) (hm : ∀ t, Measurable (B t)) (s h : ℝ≥0) + {Y A : Ω → ℝ} + (hY : Measurable[Filtration.natural B (fun t => (hm t).stronglyMeasurable) s] Y) + (hYi : Integrable Y P) (hA : Measurable A) (M : ℝ≥0) + (hAb : ∀ ω, |A ω| ≤ (M:ℝ)*(h:ℝ)) {F D : ℝ → ℝ → ℝ} + (hF : BoundedSmoothFamily F) (hD : BoundedSmoothFamily D) + (C₁ C₂ C₃ L : ℝ≥0) (hC₁ : ∀ x, |deriv (F s) x| ≤ C₁) + (hC₂ : ∀ x, |deriv (deriv (F s)) x| ≤ C₂) + (hC₃ : ∀ x, |iteratedDeriv 3 (F s) x| ≤ C₃) + (hL : ∀ r, LipschitzWith L (D r)) + (he : ∀ x, F ((s:ℝ)+(h:ℝ)) x-F s x = ∫ r in (s:ℝ)..((s:ℝ)+(h:ℝ)), D r x) : + |(∫ ω, F ((s:ℝ)+(h:ℝ)) (Y ω+(B (s+h) ω-B s ω)+A ω) ∂P)- + (∫ ω, F s (Y ω) ∂P)-(∫ ω, deriv (F s) (Y ω)*A ω ∂P)- + (h:ℝ)/2*(∫ ω, deriv (deriv (F s)) (Y ω) ∂P)- + (∫ ω, (∫ r in (s:ℝ)..((s:ℝ)+(h:ℝ)), D r (Y ω)) ∂P)| ≤ + (C₃:ℝ)/6*((h:ℝ)*Real.sqrt (h:ℝ)*normalThirdMoment)+ + (C₂:ℝ)*(M:ℝ)*(h:ℝ)*(Real.sqrt (h:ℝ)*normalFirstMoment+(M:ℝ)*(h:ℝ))+ + (L:ℝ)*(h:ℝ)*(Real.sqrt (h:ℝ)*normalFirstMoment+(M:ℝ)*(h:ℝ)) := by + let := hB.isGaussianProcess.isProbabilityMeasure + have hYm := hY.mono ((Filtration.natural B (fun t => (hm t).stronglyMeasurable)).le s) le_rfl + let Z (ω : Ω) := Y ω+(B (s+h) ω-B s ω)+A ω + have hZm : Measurable Z := (hYm.add ((hm _).sub (hm _))).add hA + have hd : Integrable (fun ω => B (s+h) ω-B s ω) P := + (hB.integrable_eval _).sub (hB.integrable_eval _) + let R (ω : Ω) := F ((s:ℝ)+(h:ℝ)) (Z ω)-F s (Z ω)- + ∫ r in (s:ℝ)..((s:ℝ)+(h:ℝ)), D r (Y ω) + have hiR : Integrable R P := + ((integrable_family_comp hF _ hZm).sub (integrable_family_comp hF _ hZm)).sub + (integrable_family_integral_comp hD _ _ hYm) + have hRb (ω : Ω) : |R ω| ≤ (L:ℝ)*(h:ℝ)*(|B (s+h) ω-B s ω|+(M:ℝ)*(h:ℝ)) := by + dsimp only [R] + rw [he] + have hi := time_integral_spatial_bound hD hL (s:ℝ) ((s:ℝ)+(h:ℝ)) (Y ω) (Z ω) + rw [add_sub_cancel_left,abs_of_nonneg h.coe_nonneg] at hi + apply hi.trans + have hz : |Z ω-Y ω| ≤ |B (s+h) ω-B s ω|+(M:ℝ)*(h:ℝ) := by + have heq : Z ω-Y ω = (B (s+h) ω-B s ω)+A ω := by dsimp [Z]; ring + rw [heq] + exact (abs_add_le _ _).trans (add_le_add_right (hAb ω) _) + exact mul_le_mul_of_nonneg_left hz (mul_nonneg L.coe_nonneg h.coe_nonneg) + have hRe : |∫ ω, R ω ∂P| ≤ + (L:ℝ)*(h:ℝ)*(Real.sqrt (h:ℝ)*normalFirstMoment+(M:ℝ)*(h:ℝ)) := by + calc + _ ≤ ∫ ω, |R ω| ∂P := abs_integral_le_integral_abs + _ ≤ ∫ ω, (L:ℝ)*(h:ℝ)*(|B (s+h) ω-B s ω|+(M:ℝ)*(h:ℝ)) ∂P := + integral_mono hiR.abs ((hd.abs.add (integrable_const _)).const_mul _) hRb + _ = _ := by + rw [integral_const_mul,integral_add hd.abs (integrable_const _),increment_abs_first hB s h] + simp + have hRi : (∫ ω, R ω ∂P) = + (∫ ω, F ((s:ℝ)+(h:ℝ)) (Z ω) ∂P)-(∫ ω, F s (Z ω) ∂P)- + (∫ ω, (∫ r in (s:ℝ)..((s:ℝ)+(h:ℝ)), D r (Y ω)) ∂P) := by + have h1 := integrable_family_comp (P := P) hF ((s:ℝ)+(h:ℝ)) hZm + have h0 := integrable_family_comp (P := P) hF (s:ℝ) hZm + have hdI := integrable_family_integral_comp (P := P) hD (s:ℝ) ((s:ℝ)+(h:ℝ)) hYm + calc + _ = (∫ ω, F ((s:ℝ)+(h:ℝ)) (Z ω)-F s (Z ω) ∂P)- + (∫ ω, (∫ r in (s:ℝ)..((s:ℝ)+(h:ℝ)), D r (Y ω)) ∂P) := + integral_sub (h1.sub h0) hdI + _ = _ := by rw [integral_sub h1 h0] + + have hS := expected_control_step hB hm s h hY hYi hA M hAb + ((hF.regular s).smooth.of_le (ENat.natCast_le_of_coe_top_le_withTop le_rfl 3)) C₁ C₂ C₃ hC₁ hC₂ hC₃ + rw [hRi] at hRe + have ht := (abs_add_le + ((∫ ω, F s (Z ω) ∂P)-(∫ ω, F s (Y ω) ∂P)- + (∫ ω, deriv (F s) (Y ω)*A ω ∂P)-(h:ℝ)/2*(∫ ω, deriv (deriv (F s)) (Y ω) ∂P)) + ((∫ ω, F ((s:ℝ)+(h:ℝ)) (Z ω) ∂P)-(∫ ω, F s (Z ω) ∂P)- + (∫ ω, (∫ r in (s:ℝ)..((s:ℝ)+(h:ℝ)), D r (Y ω)) ∂P))).trans + (add_le_add hS hRe) + convert ht using 1 + congr 1 + ring + +end ZeroTemperatureSK.WeakIto + +end +end +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section +namespace ZeroTemperatureSK.WeakIto + +lemma time_average_bound {f : ℝ → ℝ} {C a b : ℝ} (hC : 0 ≤ C) + (hb : ∀ t, |f t| ≤ C) : |(∫ t in a..b, f t)/(b-a)| ≤ C := by + by_cases he : b=a + · simp [he,hC] + have hp : 0 < |b-a| := abs_pos.mpr (sub_ne_zero.mpr he) + rw [abs_div,div_le_iff₀ hp] + exact intervalIntegral.norm_integral_le_of_norm_le_const (f := f) (C := C) (fun t _ => by simpa only [Real.norm_eq_abs] using hb t) + +lemma time_average_tendsto_right {f : ℝ → ℝ} (hm : Measurable f) (a : ℝ) + (hc : ContinuousWithinAt f (Ioi a) a) : + Tendsto (fun b => (∫ t in a..b, f t)/(b-a)) (𝓝[>] a) (𝓝 (f a)) := by + have hh := intervalIntegral.integral_hasDerivWithinAt_right + (a := a) (b := a) (s := Ici a) (t := Ioi a) IntervalIntegrable.refl + hm.stronglyMeasurable.stronglyMeasurableAtFilter hc + have hl := (hasDerivWithinAt_iff_tendsto_slope' (show a ∉ Ioi a by simp)).mp + (hh.mono Ioi_subset_Ici_self) + apply hl.congr + intro b + simp only [slope_def_field,intervalIntegral.integral_same,sub_zero] + +variable {Ω : Type*} [MeasurableSpace Ω] {P : Measure Ω} + +lemma measurable_time_integral {f : ℝ → Ω → ℝ} + (hm : Measurable (fun p : ℝ × Ω => f p.1 p.2)) (a b : ℝ) : + Measurable (fun ω => ∫ t in a..b, f t ω) := by + rw [show (fun ω => ∫ t in a..b, f t ω) = + (fun ω => (∫ t in Ioc a b, f t ω)-(∫ t in Ioc b a, f t ω)) from rfl] + exact hm.stronglyMeasurable.integral_prod_left.measurable.sub + hm.stronglyMeasurable.integral_prod_left.measurable + +lemma expected_time_average_tendsto_right [IsFiniteMeasure P] {f : ℝ → Ω → ℝ} + (hm : Measurable (fun p : ℝ × Ω => f p.1 p.2)) {C : ℝ} (hC : 0 ≤ C) + (hb : ∀ t ω, |f t ω| ≤ C) (a : ℝ) + (hc : ∀ᵐ ω ∂P, ContinuousWithinAt (fun t => f t ω) (Ioi a) a) : + Tendsto (fun b => ∫ ω, (∫ t in a..b, f t ω)/(b-a) ∂P) + (𝓝[>] a) (𝓝 (∫ ω, f a ω ∂P)) := by + apply tendsto_integral_filter_of_dominated_convergence (fun _ => C) + · exact Eventually.of_forall fun b => ((measurable_time_integral hm a b).div_const _).aestronglyMeasurable + · exact Eventually.of_forall fun b => Eventually.of_forall fun ω => + time_average_bound hC (fun t => hb t ω) + · exact integrable_const C + · filter_upwards [hc] with ω hω + exact time_average_tendsto_right (hm.comp measurable_prodMk_right) a hω + +end ZeroTemperatureSK.WeakIto + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKSupport/Regularity/JointRegularity.lean b/lean/OAI/Probability/SKSupport/Regularity/JointRegularity.lean new file mode 100644 index 0000000000000000000000000000000000000000..44ac788990c51aa18dd93b961c79689d2c3fd9e1 --- /dev/null +++ b/lean/OAI/Probability/SKSupport/Regularity/JointRegularity.lean @@ -0,0 +1,75 @@ +import Mathlib +import OAI.Probability.SKSupport.Regularity.Regularity +import OAI.Probability.SKSupport.Control.FiniteContinuity +import OAI.Probability.SKSupport.Regularity.FamilyDifferentiation + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology ContDiff +noncomputable section +namespace ZeroTemperatureSK +open WeakIto Heat Nonuniform +variable {Ω : Type*} [MeasurableSpace Ω] + +lemma approxValue_continuousOn (γ : OrderParameter) (n : ℕ) : + ContinuousOn (fun p : ℝ × ℝ => approxValue γ n p.1 p.2) (Icc (0:ℝ) 1 ×ˢ Set.univ) := by + simpa only [approxValue,approxMesh_horizon] using finiteValue_continuousOn + (regularDatum_softAbs (show ((n+1:ℕ):ℝ) ≠ 0 by positivity)) + (softAbs_lipschitz (show ((n+1:ℕ):ℝ) ≠ 0 by positivity)) (approxCoeff γ n) (approxMesh n) (n+1) 0 + +lemma value_continuousOn (W : BrownianSystem Ω) (γ : OrderParameter) : + ContinuousOn (fun p : ℝ × ℝ => value W γ p.1 p.2) (Icc (0:ℝ) 1 ×ˢ Set.univ) := + (approxValue_uniform W γ).continuousOn (Filter.Eventually.of_forall (approxValue_continuousOn γ)).frequently + +lemma approxValue_derivative_uniform (W : BrownianSystem Ω) (γ : OrderParameter) + {T : ℝ} (hT0 : 0 ≤ T) (hT1 : T < 1) (m : ℕ) : + TendstoUniformlyOn (fun n (p : ℝ × ℝ) => iteratedDeriv m (approxValue γ n p.1) p.2) + (fun p => iteratedDeriv m (value W γ p.1) p.2) atTop (Icc (0:ℝ) T ×ˢ Set.univ) := by + induction m with + | zero => + simp only [iteratedDeriv_zero] + exact (approxValue_uniform W γ).mono (Set.prod_mono (Icc_subset_Icc le_rfl hT1.le) (Subset.refl _)) + | succ m ih => + obtain ⟨C,hC,hb⟩ := approxValue_uniform_derivative_bounds γ hT0 hT1 (m+1) + have hbg : ∀ t ∈ Icc (0:ℝ) T, ∀ x, |iteratedDeriv (m+2) (value W γ t) x| ≤ C := by + intro t ht x + exact iteratedDeriv_limit_bound (m+2) + (approxValue_derivative_uniform_spatial W γ ht.1 (ht.2.trans_lt hT1) (m+2)) + (fun n y => by simpa only [Nat.add_assoc] using hb n t ht y) x + have hh := tendstoUniformlyOn_deriv_family (S := Icc (0:ℝ) T) + (f := fun n t => iteratedDeriv m (approxValue γ n t)) + (g := fun t => iteratedDeriv m (value W γ t)) + (fun n t _ => (contDiff_iteratedDeriv_infty (approxValue_regular γ n t).smooth m).of_le + (ENat.natCast_le_of_coe_top_le_withTop le_rfl 2)) + (fun t ht => (contDiff_iteratedDeriv_infty (value_contDiff W γ ht.1 (ht.2.trans_lt hT1)) m).of_le + (ENat.natCast_le_of_coe_top_le_withTop le_rfl 2)) hC + (by simpa only [show m+2=(m+1)+1 by omega,iteratedDeriv_succ] using hb) + (by simpa only [show m+2=(m+1)+1 by omega,iteratedDeriv_succ] using hbg) ih + simpa only [iteratedDeriv_succ] using hh + +theorem value_derivative_continuousOn (W : BrownianSystem Ω) (γ : OrderParameter) + {T : ℝ} (hT0 : 0 ≤ T) (hT1 : T < 1) (m : ℕ) : + ContinuousOn (fun p : ℝ × ℝ => iteratedDeriv m (value W γ p.1) p.2) + (Icc (0:ℝ) T ×ˢ Set.univ) := by + induction m with + | zero => + simp only [iteratedDeriv_zero] + exact (value_continuousOn W γ).mono + (Set.prod_mono (Icc_subset_Icc le_rfl hT1.le) (Subset.refl _)) + | succ m ih => + obtain ⟨C,hC,hb⟩ := value_uniform_derivative_bounds W γ hT0 hT1 (m+1) + have hh := continuousOn_deriv_family (S := Icc (0:ℝ) T) + (f := fun t => iteratedDeriv m (value W γ t)) ih + (fun t ht => (contDiff_iteratedDeriv_infty (value_contDiff W γ ht.1 (ht.2.trans_lt hT1)) m).of_le + (ENat.natCast_le_of_coe_top_le_withTop le_rfl 2)) hC + (by simpa only [show m+2=(m+1)+1 by omega,iteratedDeriv_succ] using hb) + simpa only [iteratedDeriv_succ] using hh + +end ZeroTemperatureSK + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKSupport/Regularity/MixedIdentity.lean b/lean/OAI/Probability/SKSupport/Regularity/MixedIdentity.lean new file mode 100644 index 0000000000000000000000000000000000000000..11edd4a79e35367ce609c030368c4f3b4814ca14 --- /dev/null +++ b/lean/OAI/Probability/SKSupport/Regularity/MixedIdentity.lean @@ -0,0 +1,126 @@ +import Mathlib +import OAI.Probability.SKSupport.Moments.SquareEquation +import OAI.Probability.SKSupport.Control.ValueDifference +import OAI.Probability.SKSupport.Diffusion.MixedDrift + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology ContDiff +noncomputable section +namespace ZeroTemperatureSK +open Heat WeakIto +variable {Ω : Type*} [MeasurableSpace Ω] + +lemma differenceField_generator (W : BrownianSystem Ω) (β γ : OrderParameter) + {T : ℝ} (hT0 : 0 ≤ T) (hT1 : T < 1) (t x : ℝ) : + (differenceField W β γ hT0 hT1).generator (compactMixedDrift W β γ T) t x = + -(1/2:ℝ)*(compactCoeff β T t-compactCoeff γ T t)*(compactGradient W γ T t x)^2 := by + have hb := (((compactGradient_family W β hT0 hT1).regular t).smooth.differentiable (by simp) x).hasDerivAt + have hg := (((compactGradient_family W γ hT0 hT1).regular t).smooth.differentiable (by simp) x).hasDerivAt + change deriv (compactDifference W β γ T t) x*compactMixedDrift W β γ T t x+ + (1/2:ℝ)*deriv (deriv (compactDifference W β γ T t)) x+compactDifferenceRate W β γ T t x=_ + have hd := (hb.sub hg).deriv + change deriv (fun y => compactGradient W β T t y-compactGradient W γ T t y) x=_ at hd + rw [compactDifference_deriv W β γ hT0 hT1,hd] + unfold compactDifferenceRate compactValueRate valueRate compactMixedDrift compactMixedGradient + compactCoeff compactGradient curvature gradient + ring + +def mixedQ (W : BrownianSystem Ω) (β γ : OrderParameter) (T : Time) (t : ℝ) : ℝ := + ∫ ξ, (compactGradient W γ T t ((mixedStripDrift W β γ T).solution W.driver (Real.toNNReal t) ξ))^2 ∂W.law + +lemma mixedQ_continuous (W : BrownianSystem Ω) (β γ : OrderParameter) (T : Time) : + Continuous (mixedQ W β γ T) := by + convert (mixedStripDrift W β γ T).expected_continuous W + (compactSquare_family W γ T.property.1 T.property.2) + (compactSquare_continuous W γ T.property.1 T.property.2) using 1 + funext t + apply integral_congr_ae + filter_upwards [] with ξ + simp only [compactSquare,pow_two] + +lemma mixedQ_bounds (W : BrownianSystem Ω) (β γ : OrderParameter) (T : Time) (t : ℝ) : + 0 ≤ mixedQ W β γ T t ∧ mixedQ W β γ T t ≤ 1 := by + let := W.isProbability + have hi : Integrable (fun ξ => (compactGradient W γ T t + ((mixedStripDrift W β γ T).solution W.driver (Real.toNNReal t) ξ))^2) W.law := by + simpa only [pow_two,compactSquare] using + integrable_family_comp (P := W.law) (compactSquare_family W γ T.property.1 T.property.2) t + ((mixedStripDrift W β γ T).solution_measurable W (Real.toNNReal t)) + refine ⟨integral_nonneg (fun ξ => sq_nonneg _),?_⟩ + calc + mixedQ W β γ T t ≤ ∫ _ : Ω, (1:ℝ) ∂W.law := integral_mono hi (integrable_const _) (fun ξ => by + have hh := compactGradient_bound W γ T.property.1 T.property.2 t + ((mixedStripDrift W β γ T).solution W.driver (Real.toNNReal t) ξ) + rw [abs_le] at hh + nlinarith) + _ = 1 := by simp + +lemma mixed_difference_right (W : BrownianSystem Ω) (β γ : OrderParameter) (T : Time) + (s : ℝ≥0) (hs : (s:ℝ) < T) : + HasDerivWithinAt ((differenceField W β γ T.property.1 T.property.2).expected + (mixedStripDrift W β γ T) W) + (-(1/2:ℝ)*(compactCoeff β T s-compactCoeff γ T s)*mixedQ W β γ T s) (Ioi (s:ℝ)) s := by + have hh := (differenceField W β γ T.property.1 T.property.2).expected_hasDerivWithinAt_right + (mixedStripDrift W β γ T) W s hs (mixedStripDrift_pathDrift_right W β γ T s) + have he : (∫ ξ, (differenceField W β γ T.property.1 T.property.2).generator + (mixedStripDrift W β γ T).f s ((mixedStripDrift W β γ T).solution W.driver s ξ) ∂W.law) = + -(1/2:ℝ)*(compactCoeff β T s-compactCoeff γ T s)*mixedQ W β γ T s := by + simp only [mixedStripDrift,differenceField_generator,mixedQ,Real.toNNReal_coe] + rw [integral_const_mul] + rw [he] at hh + exact hh + +lemma mixed_difference_zero (W : BrownianSystem Ω) (β γ : OrderParameter) (T : Time) : + (differenceField W β γ T.property.1 T.property.2).expected (mixedStripDrift W β γ T) W 0 = + value W β 0 0-value W γ 0 0 := by + let := W.isProbability + have hx (ξ : Ω) : (mixedStripDrift W β γ T).solution W.driver 0 ξ=0 := by + rw [(mixedStripDrift W β γ T).solution_eq _ W.driver_progressive] + simp only [NNReal.coe_zero,intervalIntegral.integral_same,W.driver_zero,add_zero] + simp [TimeField.expected,differenceField,Real.toNNReal_zero,hx,compactDifference, + stripClamp_eq ⟨le_rfl,T.property.1⟩] + +lemma mixed_difference_integral (W : BrownianSystem Ω) (β γ : OrderParameter) (T : Time) : + value W β 0 0-value W γ 0 0 = + (differenceField W β γ T.property.1 T.property.2).expected (mixedStripDrift W β γ T) W T+ + (1/2:ℝ)*(∫ s in (0:ℝ)..(T:ℝ), (extend β.val s-extend γ.val s)*mixedQ W β γ T s) := by + let f := (differenceField W β γ T.property.1 T.property.2) + have hc : ContinuousOn (f.expected (mixedStripDrift W β γ T) W) (Icc (0:ℝ) T) := + (f.expected_continuous (mixedStripDrift W β γ T) W).continuousOn + have hi : IntervalIntegrable (fun s => (extend β.val s-extend γ.val s)*mixedQ W β γ T s) volume 0 T := + ((β.integrable.sub γ.integrable).intervalIntegrable).mul_continuousOn + (mixedQ_continuous W β γ T).continuousOn + have hh := intervalIntegral.integral_eq_sub_of_hasDeriv_right_of_le T.property.1 hc + (f' := fun s => -(1/2:ℝ)*((extend β.val s-extend γ.val s)*mixedQ W β γ T s)) + (fun s hs => by + have hh := mixed_difference_right W β γ T (Real.toNNReal s) + (by rw [Real.coe_toNNReal _ hs.1.le];exact hs.2) + simpa only [Real.coe_toNNReal _ hs.1.le,compactCoeff,stripClamp_eq ⟨hs.1.le,hs.2.le⟩,mul_assoc] using hh) + (hi.const_mul _) + rw [intervalIntegral.integral_const_mul,mixed_difference_zero] at hh + dsimp only [f] at hh ⊢ + linarith + +lemma mixed_difference_terminal_bound (W : BrownianSystem Ω) (β γ : OrderParameter) (T : Time) : + |(differenceField W β γ T.property.1 T.property.2).expected (mixedStripDrift W β γ T) W T| ≤ + (3/2:ℝ)*(∫ s in (T:ℝ)..1, |extend β.val s-extend γ.val s|) := by + let := W.isProbability + change |∫ ξ, compactDifference W β γ T T _ ∂W.law| ≤ _ + rw [← Real.norm_eq_abs] + have hh := norm_integral_le_of_norm_le_const (μ := W.law) + (f := fun ξ => compactDifference W β γ T T ((mixedStripDrift W β γ T).solution W.driver (Real.toNNReal T) ξ)) + (C := (3/2:ℝ)*(∫ s in (T:ℝ)..1, |extend β.val s-extend γ.val s|)) (by + filter_upwards [] with ξ + simp only [compactDifference,stripClamp_eq ⟨T.property.1,le_rfl⟩,Real.norm_eq_abs] + exact value_coefficient_stability W β γ T _ T.property.2.le) + simpa using hh + +end ZeroTemperatureSK + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKSupport/Regularity/ParameterChords.lean b/lean/OAI/Probability/SKSupport/Regularity/ParameterChords.lean new file mode 100644 index 0000000000000000000000000000000000000000..74ad49cb7f780f717a0dbafa27e8f4d4500d7181 --- /dev/null +++ b/lean/OAI/Probability/SKSupport/Regularity/ParameterChords.lean @@ -0,0 +1,182 @@ +import Mathlib +import OAI.Probability.SKSupport.Control.ValueDifference + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section +namespace ZeroTemperatureSK + +def OrderParameter.chord (γ β : OrderParameter) (ε : ℝ) (hε : ε ∈ Icc (0:ℝ) 1) : OrderParameter where + val := fun t => (1-ε)*γ.val t+ε*β.val t + nonneg := fun t => add_nonneg (mul_nonneg (sub_nonneg.mpr hε.2) (γ.nonneg t)) (mul_nonneg hε.1 (β.nonneg t)) + monotone := fun a b hab => add_le_add (mul_le_mul_of_nonneg_left (γ.monotone hab) (sub_nonneg.mpr hε.2)) + (mul_le_mul_of_nonneg_left (β.monotone hab) hε.1) + right_continuous := fun t => ((γ.right_continuous t).const_mul (1-ε)).add ((β.right_continuous t).const_mul ε) + integrable := by + have he : extend (fun t => (1-ε)*γ.val t+ε*β.val t)=fun t => (1-ε)*extend γ.val t+ε*extend β.val t := by + funext t + by_cases ht : t ∈ Ico (0:ℝ) 1 <;> simp [extend,ht] + rw [he] + exact (γ.integrable.const_mul (1-ε)).add (β.integrable.const_mul ε) + +lemma OrderParameter.chord_extend (γ β : OrderParameter) (ε : ℝ) (hε : ε ∈ Icc (0:ℝ) 1) (t : ℝ) : + extend (γ.chord β ε hε).val t=extend γ.val t+ε*(extend β.val t-extend γ.val t) := by + by_cases ht : t ∈ Ico (0:ℝ) 1 + · simp only [extend,dite_eq_left ht,chord];ring + · simp [extend,ht] + +lemma OrderParameter.chord_distance (γ β : OrderParameter) (ε : ℝ) (hε : ε ∈ Icc (0:ℝ) 1) : + coefficientDistance (γ.chord β ε hε) γ=ε*coefficientDistance β γ := by + simp only [coefficientDistance,γ.chord_extend β ε hε,add_sub_cancel_left,abs_mul,abs_of_nonneg hε.1] + rw [intervalIntegral.integral_const_mul] + +lemma OrderParameter.chord_bound (γ β : OrderParameter) (ε : ℝ) (hε : ε ∈ Icc (0:ℝ) 1) (t : Time) : + (γ.chord β ε hε).val t ≤ γ.val t+β.val t := by + change (1-ε)*γ.val t+ε*β.val t ≤ _ + nlinarith [mul_nonneg hε.1 (γ.nonneg t),mul_nonneg (sub_nonneg.mpr hε.2) (β.nonneg t)] + +def variationStep (n : ℕ) : ℝ := 1/((n:ℝ)+1) +lemma variationStep_pos (n : ℕ) : 0 < variationStep n := by unfold variationStep;positivity +lemma variationStep_mem (n : ℕ) : variationStep n ∈ Icc (0:ℝ) 1 := by + refine ⟨(variationStep_pos n).le,?_⟩ + unfold variationStep + apply (div_le_iff₀ (by positivity : (0:ℝ)<(n:ℝ)+1)).mpr + norm_num +lemma variationStep_limit : Tendsto variationStep atTop (𝓝 0) := by + change Tendsto (fun n : ℕ => 1/((n:ℝ)+1)) atTop (𝓝 0) + simpa only [variationStep,one_div,Function.comp_def,Nat.cast_add,Nat.cast_one] using tendsto_inv_atTop_zero.comp ((tendsto_natCast_atTop_atTop (R := ℝ)).comp (tendsto_add_atTop_nat 1)) + +def perturbation (γ β : OrderParameter) (n : ℕ) : OrderParameter := γ.chord β (variationStep n) (variationStep_mem n) + +lemma perturbation_diff (γ β : OrderParameter) (n : ℕ) (t : ℝ) : + extend (perturbation γ β n).val t-extend γ.val t=variationStep n*(extend β.val t-extend γ.val t) := by + simp only [perturbation,γ.chord_extend β _ _,add_sub_cancel_left] + +lemma perturbation_distance_limit (γ β : OrderParameter) : + Tendsto (fun n => coefficientDistance (perturbation γ β n) γ) atTop (𝓝 0) := by + simp only [perturbation,OrderParameter.chord_distance] + simpa only [zero_mul] using variationStep_limit.mul_const (coefficientDistance β γ) + +end ZeroTemperatureSK + +end +end +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology ContDiff +noncomputable section +namespace ZeroTemperatureSK +open WeakIto Heat Nonuniform + +lemma finiteCoeff_offset (c d : ℕ → ℝ≥0) (h : ℝ≥0) (ε : ℝ) (N i : ℕ) + (he : ∀ j < N, (d (i+j):ℝ)=(c (i+j):ℝ)+ε) + {t : ℝ} (ht : t ≤ (N:ℝ)*h) (hN : 0 < N) : + finiteCoeff d h N i t=finiteCoeff c h N i t+ε := by + induction N generalizing i t with + | zero => omega + | succ N ih => + by_cases hh : t ≤ h + · simp only [finiteCoeff,ite_eq_left hh] + simpa only [Nat.add_zero] using he 0 (by omega) + · simp only [finiteCoeff,ite_eq_right hh] + have hp : 0 < N := by + by_contra hn + have hn0 : N=0 := by omega + subst N + norm_num at ht + exact hh ht + apply ih (i+1) _ _ hp + · intro j hj + simpa only [show i+1+j=i+(j+1) by omega] using he (j+1) (by omega) + · push_cast at ht + nlinarith + +def positiveCoeff (γ : OrderParameter) (n j : ℕ) : ℝ≥0 := + approxCoeff γ n (min j n)+approxMesh n + +def positiveGamma (γ : OrderParameter) (n : ℕ) : ℝ → ℝ := + finiteCoeff (positiveCoeff γ n) (approxMesh n) (n+1) 0 + +def positiveTerminal (γ : OrderParameter) (n : ℕ) : ℝ := + ((n+1:ℕ):ℝ)+(positiveCoeff γ n n:ℝ) + +lemma positiveCoeff_pos (γ : OrderParameter) (n j : ℕ) : 0 < (positiveCoeff γ n j:ℝ) := by + unfold positiveCoeff + exact_mod_cast add_pos_of_nonneg_of_pos (bot_le : 0 ≤ approxCoeff γ n (min j n)) (approxMesh_pos n) + +lemma positiveCoeff_monotone (γ : OrderParameter) (n : ℕ) : Monotone (positiveCoeff γ n) := by + intro i j hij + unfold positiveCoeff + apply add_le_add _ le_rfl + apply NNReal.coe_le_coe.mp + rw [approxCoeff_eq γ n _ (by omega),approxCoeff_eq γ n _ (by omega)] + apply γ.monotone + exact mul_le_mul_of_nonneg_right (by exact_mod_cast min_le_min_right n hij) (approxMesh n).coe_nonneg + +lemma positiveCoeff_bound (γ : OrderParameter) (n j : ℕ) : (positiveCoeff γ n j:ℝ) ≤ positiveTerminal γ n := by + have he : positiveCoeff γ n j=positiveCoeff γ n (min j n) := by simp only [positiveCoeff,min_assoc,min_self] + have hh := positiveCoeff_monotone γ n (min_le_right j n) + rw [← he] at hh + unfold positiveTerminal + exact (show (positiveCoeff γ n j:ℝ) ≤ positiveCoeff γ n n from hh).trans (by linarith [Nat.cast_nonneg (α := ℝ) (n+1)]) + +lemma positiveTerminal_pos (γ : OrderParameter) (n : ℕ) : 0 < positiveTerminal γ n := by + unfold positiveTerminal;positivity + +lemma positiveGamma_eq (γ : OrderParameter) (n : ℕ) {t : ℝ} (ht : t ≤ 1) : + positiveGamma γ n t=approxGamma γ n t+(approxMesh n:ℝ) := by + apply finiteCoeff_offset _ _ _ _ (n+1) 0 _ (by simpa only [approxMesh_horizon] using ht) (by omega) + intro j hj + simp only [Nat.zero_add,positiveCoeff,min_eq_left (by omega : j ≤ n),NNReal.coe_add] + +lemma positiveGamma_intervalIntegrable (γ : OrderParameter) (n : ℕ) : + IntervalIntegrable (positiveGamma γ n) volume 0 1 := finiteCoeff_intervalIntegrable _ _ _ _ _ _ + +lemma positiveGamma_L1_bound (γ : OrderParameter) (n : ℕ) : + (∫ t in (0:ℝ)..1, |positiveGamma γ n t-extend γ.val t|) ≤ + (∫ t in (0:ℝ)..1, |approxGamma γ n t-extend γ.val t|)+(approxMesh n:ℝ) := by + have hf : IntervalIntegrable (fun t => |approxGamma γ n t-extend γ.val t|) volume 0 1 := ((finiteCoeff_intervalIntegrable (approxCoeff γ n) (approxMesh n) (n+1) 0 0 1).sub γ.integrable.intervalIntegrable).abs + have hg := ((positiveGamma_intervalIntegrable γ n).sub γ.integrable.intervalIntegrable).abs + calc + _ ≤ ∫ t in (0:ℝ)..1, |approxGamma γ n t-extend γ.val t|+(approxMesh n:ℝ) := by + apply intervalIntegral.integral_mono_on (by norm_num) hg (hf.add intervalIntegrable_const) + intro t ht + rw [positiveGamma_eq γ n ht.2] + have he : approxGamma γ n t+(approxMesh n:ℝ)-extend γ.val t= + (approxGamma γ n t-extend γ.val t)+(approxMesh n:ℝ) := by ring + rw [he] + exact (abs_add_le _ _).trans (by rw [abs_of_nonneg (approxMesh n).coe_nonneg]) + _ = _ := by rw [intervalIntegral.integral_add hf intervalIntegrable_const,intervalIntegral.integral_const];simp + +lemma positiveGamma_L1 (γ : OrderParameter) : + Tendsto (fun n => ∫ t in (0:ℝ)..1, |positiveGamma γ n t-extend γ.val t|) atTop (𝓝 0) := by + apply squeeze_zero (fun n => intervalIntegral.integral_nonneg (by norm_num) (fun _ _ => abs_nonneg _)) + (positiveGamma_L1_bound γ) + simpa only [zero_add] using (approxGamma_L1 γ).add approxMesh_limit + +lemma positiveGamma_bound (γ : OrderParameter) (n : ℕ) (t : Time) : + positiveGamma γ n t ≤ γ.val t+1 := by + rw [positiveGamma_eq γ n t.property.2.le] + have hm : (approxMesh n:ℝ) ≤ 1 := by + unfold approxMesh + simp only [NNReal.coe_inv,NNReal.coe_natCast] + exact inv_le_one_of_one_le₀ (by exact_mod_cast Nat.succ_le_succ (Nat.zero_le n)) + exact add_le_add (approxGamma_bounds γ n t).2 hm + +lemma positiveTerminal_inv_tendsto (γ : OrderParameter) : + Tendsto (fun n => (positiveTerminal γ n)⁻¹) atTop (𝓝 0) := by + apply squeeze_zero (fun n => inv_nonneg.mpr (positiveTerminal_pos γ n).le) (fun n => ?_) approxMesh_limit + change (positiveTerminal γ n)⁻¹ ≤ (((n+1:ℕ):ℝ))⁻¹ + apply inv_anti₀ (by positivity) + unfold positiveTerminal + exact le_add_of_nonneg_right (positiveCoeff γ n n).coe_nonneg + +end ZeroTemperatureSK + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKSupport/Regularity/PositiveRegularity.lean b/lean/OAI/Probability/SKSupport/Regularity/PositiveRegularity.lean new file mode 100644 index 0000000000000000000000000000000000000000..005e51648e069b14c9ab73db4c57c0b9d8f23dc1 --- /dev/null +++ b/lean/OAI/Probability/SKSupport/Regularity/PositiveRegularity.lean @@ -0,0 +1,146 @@ +import Mathlib +import OAI.Probability.SKSupport.Regularity.ParameterChords + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology ContDiff +noncomputable section +namespace ZeroTemperatureSK +open WeakIto Heat Nonuniform + +def positiveValue (γ : OrderParameter) (n : ℕ) : ℝ → ℝ → ℝ := + finiteValue (positiveCoeff γ n) (approxMesh n) (softAbs (positiveTerminal γ n)) (n+1) 0 + +def positiveError (γ : OrderParameter) (n : ℕ) : ℝ := + Real.log 2 / positiveTerminal γ n+(3/2:ℝ)*∫ s in (0:ℝ)..1, |positiveGamma γ n s-extend γ.val s| + +lemma positiveError_limit (γ : OrderParameter) : Tendsto (positiveError γ) atTop (𝓝 0) := by + have hh : Tendsto (fun n => Real.log 2 / positiveTerminal γ n) atTop (𝓝 0) := by + simpa only [div_eq_mul_inv,mul_zero] using + tendsto_const_nhds.mul (positiveTerminal_inv_tendsto γ) (a := Real.log 2) + have hi := tendsto_const_nhds.mul (positiveGamma_L1 γ) (a := (3/2:ℝ)) + have h := hh.add hi + unfold positiveError + convert h using 1 + simp only [mul_zero,add_zero] + +variable {Ω : Type*} [MeasurableSpace Ω] + +lemma positiveValue_error (W : BrownianSystem Ω) (γ : OrderParameter) (n : ℕ) + {t : ℝ} (ht0 : 0 ≤ t) (ht1 : t ≤ 1) (x : ℝ) : + |positiveValue γ n t x-value W γ t x| ≤ positiveError γ n := by + apply finiteValue_control_error W γ _ _ _ (approxMesh_horizon n) + (regularDatum_softAbs (ne_of_gt (positiveTerminal_pos γ n))) (softAbs_lipschitz (ne_of_gt (positiveTerminal_pos γ n))) _ ht0 ht1 x + intro z + have hh := softAbs_bounds (positiveTerminal_pos γ n) z + rw [abs_of_nonneg hh.1] + exact hh.2 + +lemma positiveValue_uniform (W : BrownianSystem Ω) (γ : OrderParameter) : + TendstoUniformlyOn (fun n (p : ℝ × ℝ) => positiveValue γ n p.1 p.2) + (fun p => value W γ p.1 p.2) atTop (Icc (0:ℝ) 1 ×ˢ Set.univ) := by + rw [Metric.tendstoUniformlyOn_iff] + intro ε hε + filter_upwards [(positiveError_limit γ).eventually (gt_mem_nhds hε)] with n hn p hp + rw [Real.dist_eq,abs_sub_comm] + exact (positiveValue_error W γ n hp.1.1 hp.1.2 p.2).trans_lt hn + +lemma positiveValue_uniform_spatial (W : BrownianSystem Ω) (γ : OrderParameter) + {t : ℝ} (ht0 : 0 ≤ t) (ht1 : t ≤ 1) : + TendstoUniformly (fun n => positiveValue γ n t) (value W γ t) atTop := by + rw [Metric.tendstoUniformly_iff] + intro ε hε + filter_upwards [(positiveError_limit γ).eventually (gt_mem_nhds hε)] with n hn x + rw [Real.dist_eq,abs_sub_comm] + exact (positiveValue_error W γ n ht0 ht1 x).trans_lt hn + +lemma positiveValue_regular (γ : OrderParameter) (n : ℕ) (t : ℝ) : + RegularDatum (positiveValue γ n t) := + finiteValue_regular (regularDatum_softAbs (ne_of_gt (positiveTerminal_pos γ n))) + (softAbs_lipschitz (ne_of_gt (positiveTerminal_pos γ n))) _ _ _ _ _ + +lemma positiveValue_uniform_derivative_bounds (γ : OrderParameter) {T : ℝ} + (hT0 : 0 ≤ T) (hT1 : T < 1) (m : ℕ) : + ∃ C : ℝ, 0 ≤ C ∧ ∀ n, ∀ t ∈ Icc (0:ℝ) T, ∀ x, + |iteratedDeriv (m+1) (positiveValue γ n t) x| ≤ C := by + let δ := (1-T)/2 + have hδ : 0 < δ := by dsimp [δ]; linarith + have hB : T+δ ∈ Ico (0:ℝ) 1 := by dsimp [δ]; constructor <;> linarith + let D := γ.val ⟨T+δ,hB⟩+1 + obtain ⟨C,hC,hbound⟩ := finiteGradient_uniform_smoothing m D (by dsimp [D]; linarith [γ.nonneg ⟨T+δ,hB⟩]) δ hδ + refine ⟨C,hC,fun n t ht x => ?_⟩ + have hc : ∀ s ∈ Icc (0:ℝ) (T+δ), + finiteCoeff (positiveCoeff γ n) (approxMesh n) (n+1) 0 s ≤ D := by + intro s hs + have hmem : s ∈ Ico (0:ℝ) 1 := ⟨hs.1,hs.2.trans_lt hB.2⟩ + have hh := γ.monotone (show (⟨s,hmem⟩ : Time) ≤ ⟨T+δ,hB⟩ from hs.2) + exact (positiveGamma_bound γ n ⟨s,hmem⟩).trans (add_le_add hh le_rfl) + have hh := hbound _ (regularDatum_softAbs (ne_of_gt (positiveTerminal_pos γ n))) + (softAbs_lipschitz (ne_of_gt (positiveTerminal_pos γ n))) (positiveCoeff γ n) (approxMesh n) (n+1) 0 T hT0 + (by rw [approxMesh_horizon]; exact hB.2.le) hc m le_rfl t ht x + simpa only [positiveValue,iteratedDeriv_succ'] using hh + +theorem positive_limit_contDiff (W : BrownianSystem Ω) (γ : OrderParameter) + {t : ℝ} (ht0 : 0 ≤ t) (ht1 : t < 1) : ContDiff ℝ ∞ (value W γ t) := by + apply (smooth_limit_of_uniform_derivative_bounds + (fun n => (positiveValue_regular γ n t).smooth) _ + (positiveValue_uniform_spatial W γ ht0 ht1.le)).1 + intro m + obtain ⟨C,hC,hb⟩ := positiveValue_uniform_derivative_bounds γ ht0 ht1 (m+1) + exact ⟨C,hC,fun n x => hb n t ⟨ht0,le_rfl⟩ x⟩ + +lemma positiveValue_derivative_uniform_spatial (W : BrownianSystem Ω) (γ : OrderParameter) + {t : ℝ} (ht0 : 0 ≤ t) (ht1 : t < 1) (m : ℕ) : + TendstoUniformly (fun n => iteratedDeriv m (positiveValue γ n t)) + (iteratedDeriv m (value W γ t)) atTop := by + apply (smooth_limit_of_uniform_derivative_bounds + (fun n => (positiveValue_regular γ n t).smooth) _ + (positiveValue_uniform_spatial W γ ht0 ht1.le)).2 m + intro j + obtain ⟨C,hC,hb⟩ := positiveValue_uniform_derivative_bounds γ ht0 ht1 (j+1) + exact ⟨C,hC,fun n x => hb n t ⟨ht0,le_rfl⟩ x⟩ + +theorem positive_limit_derivative_bounds (W : BrownianSystem Ω) (γ : OrderParameter) + {T : ℝ} (hT0 : 0 ≤ T) (hT1 : T < 1) (m : ℕ) : + ∃ C : ℝ, 0 ≤ C ∧ ∀ t ∈ Icc (0:ℝ) T, ∀ x, + |iteratedDeriv (m+1) (value W γ t) x| ≤ C := by + obtain ⟨C,hC,hb⟩ := positiveValue_uniform_derivative_bounds γ hT0 hT1 m + refine ⟨C,hC,fun t ht x => ?_⟩ + exact iteratedDeriv_limit_bound (m+1) + (positiveValue_derivative_uniform_spatial W γ ht.1 (ht.2.trans_lt hT1) (m+1)) + (fun n x => hb n t ht x) x + +lemma positiveValue_derivative_uniform (W : BrownianSystem Ω) (γ : OrderParameter) + {T : ℝ} (hT0 : 0 ≤ T) (hT1 : T < 1) (m : ℕ) : + TendstoUniformlyOn (fun n (p : ℝ × ℝ) => iteratedDeriv m (positiveValue γ n p.1) p.2) + (fun p => iteratedDeriv m (value W γ p.1) p.2) atTop (Icc (0:ℝ) T ×ˢ Set.univ) := by + induction m with + | zero => + simp only [iteratedDeriv_zero] + exact (positiveValue_uniform W γ).mono (Set.prod_mono (Icc_subset_Icc le_rfl hT1.le) (Subset.refl _)) + | succ m ih => + obtain ⟨C,hC,hb⟩ := positiveValue_uniform_derivative_bounds γ hT0 hT1 (m+1) + have hbg : ∀ t ∈ Icc (0:ℝ) T, ∀ x, |iteratedDeriv (m+2) (value W γ t) x| ≤ C := by + intro t ht x + exact iteratedDeriv_limit_bound (m+2) + (positiveValue_derivative_uniform_spatial W γ ht.1 (ht.2.trans_lt hT1) (m+2)) + (fun n y => by simpa only [Nat.add_assoc] using hb n t ht y) x + have hh := tendstoUniformlyOn_deriv_family (S := Icc (0:ℝ) T) + (f := fun n t => iteratedDeriv m (positiveValue γ n t)) + (g := fun t => iteratedDeriv m (value W γ t)) + (fun n t _ => (contDiff_iteratedDeriv_infty (positiveValue_regular γ n t).smooth m).of_le + (ENat.natCast_le_of_coe_top_le_withTop le_rfl 2)) + (fun t ht => (contDiff_iteratedDeriv_infty (value_contDiff W γ ht.1 (ht.2.trans_lt hT1)) m).of_le + (ENat.natCast_le_of_coe_top_le_withTop le_rfl 2)) hC + (by simpa only [show m+2=(m+1)+1 by omega,iteratedDeriv_succ] using hb) + (by simpa only [show m+2=(m+1)+1 by omega,iteratedDeriv_succ] using hbg) ih + simpa only [iteratedDeriv_succ] using hh + +end ZeroTemperatureSK + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKSupport/Regularity/Regularity.lean b/lean/OAI/Probability/SKSupport/Regularity/Regularity.lean new file mode 100644 index 0000000000000000000000000000000000000000..2ec6e890a40b4ec6549f8c9c56d8b3efd9e0cd66 --- /dev/null +++ b/lean/OAI/Probability/SKSupport/Regularity/Regularity.lean @@ -0,0 +1,199 @@ +import Mathlib +import OAI.Probability.SKSupport.Control.ControlPayoffConvex +import OAI.Probability.SKSupport.Foundations.SmoothingStep +import OAI.Probability.SKSupport.Control.CoefficientApprox + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology ContDiff +noncomputable section +namespace ZeroTemperatureSK +open WeakIto Heat Nonuniform + +def approxValue (γ : OrderParameter) (n : ℕ) : ℝ → ℝ → ℝ := + finiteValue (approxCoeff γ n) (approxMesh n) (softAbs ((n+1:ℕ):ℝ)) (n+1) 0 + +def approxError (γ : OrderParameter) (n : ℕ) : ℝ := + Real.log 2 / ((n+1:ℕ):ℝ)+(3/2:ℝ)*∫ s in (0:ℝ)..1, |approxGamma γ n s-extend γ.val s| + +lemma approxError_limit (γ : OrderParameter) : Tendsto (approxError γ) atTop (𝓝 0) := by + have hh : Tendsto (fun n => Real.log 2 / ((n+1:ℕ):ℝ)) atTop (𝓝 0) := by + simpa only [approxMesh,NNReal.coe_inv,NNReal.coe_natCast,mul_zero,div_eq_mul_inv] using + tendsto_const_nhds.mul approxMesh_limit (a := Real.log 2) + have hi := tendsto_const_nhds.mul (approxGamma_L1 γ) (a := (3/2:ℝ)) + have h := hh.add hi + unfold approxError + convert h using 1 + simp only [mul_zero,add_zero] + +variable {Ω : Type*} [MeasurableSpace Ω] + +lemma approxValue_error (W : BrownianSystem Ω) (γ : OrderParameter) (n : ℕ) + {t : ℝ} (ht0 : 0 ≤ t) (ht1 : t ≤ 1) (x : ℝ) : + |approxValue γ n t x-value W γ t x| ≤ approxError γ n := by + apply finiteValue_control_error W γ _ _ _ (approxMesh_horizon n) + (regularDatum_softAbs (by positivity)) (softAbs_lipschitz (by positivity)) _ ht0 ht1 x + intro z + have hh := softAbs_bounds (show (0:ℝ)<((n+1:ℕ):ℝ) by positivity) z + rw [abs_of_nonneg hh.1] + exact hh.2 + +lemma approxValue_uniform (W : BrownianSystem Ω) (γ : OrderParameter) : + TendstoUniformlyOn (fun n (p : ℝ × ℝ) => approxValue γ n p.1 p.2) + (fun p => value W γ p.1 p.2) atTop (Icc (0:ℝ) 1 ×ˢ Set.univ) := by + rw [Metric.tendstoUniformlyOn_iff] + intro ε hε + filter_upwards [(approxError_limit γ).eventually (gt_mem_nhds hε)] with n hn p hp + rw [Real.dist_eq,abs_sub_comm] + exact (approxValue_error W γ n hp.1.1 hp.1.2 p.2).trans_lt hn + +lemma approxValue_uniform_spatial (W : BrownianSystem Ω) (γ : OrderParameter) + {t : ℝ} (ht0 : 0 ≤ t) (ht1 : t ≤ 1) : + TendstoUniformly (fun n => approxValue γ n t) (value W γ t) atTop := by + rw [Metric.tendstoUniformly_iff] + intro ε hε + filter_upwards [(approxError_limit γ).eventually (gt_mem_nhds hε)] with n hn x + rw [Real.dist_eq,abs_sub_comm] + exact (approxValue_error W γ n ht0 ht1 x).trans_lt hn + +lemma approxValue_regular (γ : OrderParameter) (n : ℕ) (t : ℝ) : + RegularDatum (approxValue γ n t) := + finiteValue_regular (regularDatum_softAbs (by positivity)) + (softAbs_lipschitz (by positivity)) _ _ _ _ _ + +lemma approxValue_uniform_derivative_bounds (γ : OrderParameter) {T : ℝ} + (hT0 : 0 ≤ T) (hT1 : T < 1) (m : ℕ) : + ∃ C : ℝ, 0 ≤ C ∧ ∀ n, ∀ t ∈ Icc (0:ℝ) T, ∀ x, + |iteratedDeriv (m+1) (approxValue γ n t) x| ≤ C := by + let δ := (1-T)/2 + have hδ : 0 < δ := by dsimp [δ]; linarith + have hB : T+δ ∈ Ico (0:ℝ) 1 := by dsimp [δ]; constructor <;> linarith + let D := γ.val ⟨T+δ,hB⟩ + obtain ⟨C,hC,hbound⟩ := finiteGradient_uniform_smoothing m D (γ.nonneg _) δ hδ + refine ⟨C,hC,fun n t ht x => ?_⟩ + have hc : ∀ s ∈ Icc (0:ℝ) (T+δ), + finiteCoeff (approxCoeff γ n) (approxMesh n) (n+1) 0 s ≤ D := by + intro s hs + have hmem : s ∈ Ico (0:ℝ) 1 := ⟨hs.1,hs.2.trans_lt hB.2⟩ + exact (approxGamma_bounds γ n ⟨s,hmem⟩).2.trans (γ.monotone hs.2) + have hh := hbound _ (regularDatum_softAbs (show ((n+1:ℕ):ℝ) ≠ 0 by positivity)) + (softAbs_lipschitz (by positivity)) (approxCoeff γ n) (approxMesh n) (n+1) 0 T hT0 + (by rw [approxMesh_horizon]; exact hB.2.le) hc m le_rfl t ht x + simpa only [approxValue,iteratedDeriv_succ'] using hh + +theorem value_contDiff (W : BrownianSystem Ω) (γ : OrderParameter) + {t : ℝ} (ht0 : 0 ≤ t) (ht1 : t < 1) : ContDiff ℝ ∞ (value W γ t) := by + apply (smooth_limit_of_uniform_derivative_bounds + (fun n => (approxValue_regular γ n t).smooth) _ + (approxValue_uniform_spatial W γ ht0 ht1.le)).1 + intro m + obtain ⟨C,hC,hb⟩ := approxValue_uniform_derivative_bounds γ ht0 ht1 (m+1) + exact ⟨C,hC,fun n x => hb n t ⟨ht0,le_rfl⟩ x⟩ + +lemma approxValue_derivative_uniform_spatial (W : BrownianSystem Ω) (γ : OrderParameter) + {t : ℝ} (ht0 : 0 ≤ t) (ht1 : t < 1) (m : ℕ) : + TendstoUniformly (fun n => iteratedDeriv m (approxValue γ n t)) + (iteratedDeriv m (value W γ t)) atTop := by + apply (smooth_limit_of_uniform_derivative_bounds + (fun n => (approxValue_regular γ n t).smooth) _ + (approxValue_uniform_spatial W γ ht0 ht1.le)).2 m + intro j + obtain ⟨C,hC,hb⟩ := approxValue_uniform_derivative_bounds γ ht0 ht1 (j+1) + exact ⟨C,hC,fun n x => hb n t ⟨ht0,le_rfl⟩ x⟩ + +theorem value_uniform_derivative_bounds (W : BrownianSystem Ω) (γ : OrderParameter) + {T : ℝ} (hT0 : 0 ≤ T) (hT1 : T < 1) (m : ℕ) : + ∃ C : ℝ, 0 ≤ C ∧ ∀ t ∈ Icc (0:ℝ) T, ∀ x, + |iteratedDeriv (m+1) (value W γ t) x| ≤ C := by + obtain ⟨C,hC,hb⟩ := approxValue_uniform_derivative_bounds γ hT0 hT1 m + refine ⟨C,hC,fun t ht x => ?_⟩ + exact iteratedDeriv_limit_bound (m+1) + (approxValue_derivative_uniform_spatial W γ ht.1 (ht.2.trans_lt hT1) (m+1)) + (fun n x => hb n t ht x) x + +end ZeroTemperatureSK + +end +end +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology ContDiff +noncomputable section +namespace ZeroTemperatureSK +open Heat + +lemma cascade_even {f : ℝ → ℝ} (hf : RegularDatum f) (hLip : LipschitzWith 1 f) + (he : Function.Even f) (c : ℕ → ℝ≥0) (h : ℝ≥0) (N i : ℕ) : + Function.Even (cascade c h f N i) := by + induction N generalizing i with + | zero => exact he + | succ N ih => + exact logSemigroup_even (cascade_regular hf hLip c h N (i+1)).smooth.continuous.measurable + (ih (i+1)) (c i) h + +lemma finiteValue_even {f : ℝ → ℝ} (hf : RegularDatum f) (hLip : LipschitzWith 1 f) + (he : Function.Even f) (c : ℕ → ℝ≥0) (h : ℝ≥0) (N i : ℕ) (t : ℝ) : + Function.Even (finiteValue c h f N i t) := by + induction N generalizing i t with + | zero => exact he + | succ N ih => + by_cases ht : t ≤ h + · rw [finiteValue_head f c h N i ht] + have hm := (cascade_regular hf hLip c h N (i+1)).smooth.continuous.measurable + have heq : backward (c i) h (cascade c h f N (i+1)) t = + logSemigroup (c i) (Real.toNNReal (h-t)) (cascade c h f N (i+1)) := + funext (varianceLogHeat_eq_logSemigroup_toNNReal hm (c i) (h-t)) + rw [heq] + exact logSemigroup_even hm (cascade_even hf hLip he c h N (i+1)) _ _ + · rw [finiteValue_tail f c h N i (lt_of_not_ge ht)] + exact ih (i+1) (t-h) + +variable {Ω : Type*} [MeasurableSpace Ω] + +theorem value_even (W : BrownianSystem Ω) (γ : OrderParameter) {t : ℝ} + (ht0 : 0 ≤ t) (ht1 : t ≤ 1) : Function.Even (value W γ t) := by + intro x + have h₁ := (approxValue_uniform_spatial W γ ht0 ht1).tendsto_at (-x) + have h₂ := (approxValue_uniform_spatial W γ ht0 ht1).tendsto_at x + apply tendsto_nhds_unique h₁ + exact h₂.congr (fun n => (finiteValue_even (regularDatum_softAbs (by positivity)) + (softAbs_lipschitz (by positivity)) (softAbs_even _) _ _ _ _ t x).symm) + +lemma gradient_odd (W : BrownianSystem Ω) (γ : OrderParameter) {t : ℝ} + (ht0 : 0 ≤ t) (ht1 : t < 1) : Function.Odd (gradient W γ t) := by + intro x + have hf := (value_contDiff W γ ht0 ht1).differentiable (by simp) + have hcomp := (hf (-x)).hasDerivAt.comp x ((hasDerivAt_id x).neg) + have he : (fun y => value W γ t (-y)) = value W γ t := funext (value_even W γ ht0 ht1.le) + change HasDerivAt (fun y => value W γ t (-y)) _ x at hcomp + rw [he] at hcomp + have hd := hcomp.deriv + change deriv (value W γ t) x = deriv (value W γ t) (-x)*(-1) at hd + unfold gradient + linarith + +lemma gradient_zero (W : BrownianSystem Ω) (γ : OrderParameter) {t : ℝ} + (ht0 : 0 ≤ t) (ht1 : t < 1) : gradient W γ t 0 = 0 := by + have hh := gradient_odd W γ ht0 ht1 0 + simp only [neg_zero] at hh + linarith + +lemma gradient_monotone (W : BrownianSystem Ω) (γ : OrderParameter) {t : ℝ} + (ht0 : 0 ≤ t) (ht1 : t < 1) : Monotone (gradient W γ t) := by + have hc := (value_convex W γ t ht1.le).monotoneOn_deriv + (fun x _ => (value_contDiff W γ ht0 ht1).differentiable (by simp) x) + intro x y hxy + exact hc (mem_univ x) (mem_univ y) hxy + +lemma curvature_nonneg (W : BrownianSystem Ω) (γ : OrderParameter) {t : ℝ} + (ht0 : 0 ≤ t) (ht1 : t < 1) (x : ℝ) : 0 ≤ curvature W γ t x := + (gradient_monotone W γ ht0 ht1).deriv_nonneg + +end ZeroTemperatureSK + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKSupport/Regularity/RightRegularity.lean b/lean/OAI/Probability/SKSupport/Regularity/RightRegularity.lean new file mode 100644 index 0000000000000000000000000000000000000000..0d4baebbdf8a4c72cae8474b5ef904508ebc8960 --- /dev/null +++ b/lean/OAI/Probability/SKSupport/Regularity/RightRegularity.lean @@ -0,0 +1,144 @@ +import Mathlib +import OAI.Probability.SKSupport.Foundations.Equation + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section +namespace ZeroTemperatureSK +open Heat + +def SpatialRightContinuous (F : ℝ → ℝ → ℝ) : Prop := + ∀ n : ℕ, ∀ t x, ContinuousWithinAt (fun s => iteratedDeriv n (F s) x) (Ici t) t + +lemma SpatialRightContinuous.deriv {F : ℝ → ℝ → ℝ} (hF : SpatialRightContinuous F) : + SpatialRightContinuous (fun t => deriv (F t)) := by + intro n t x + simpa only [iteratedDeriv_succ'] using hF (n+1) t x + +lemma SpatialRightContinuous.add {F G : ℝ → ℝ → ℝ} + (hf : BoundedSmoothFamily F) (hg : BoundedSmoothFamily G) + (hF : SpatialRightContinuous F) (hG : SpatialRightContinuous G) : + SpatialRightContinuous (fun t x => F t x+G t x) := by + intro n t x + have he (s : ℝ) : iteratedDeriv n (fun x => F s x+G s x) x = + iteratedDeriv n (F s) x+iteratedDeriv n (G s) x := + iteratedDeriv_fun_add ((hf.regular s).smooth.of_le + (ENat.natCast_le_of_coe_top_le_withTop le_rfl n) |>.contDiffAt) + ((hg.regular s).smooth.of_le (ENat.natCast_le_of_coe_top_le_withTop le_rfl n) |>.contDiffAt) + simp_rw [he] + exact (hF n t x).add (hG n t x) + +lemma SpatialRightContinuous.const_mul {F : ℝ → ℝ → ℝ} + (hf : BoundedSmoothFamily F) (hF : SpatialRightContinuous F) (c : ℝ) : + SpatialRightContinuous (fun t x => c*F t x) := by + intro n t x + simp_rw [iteratedDeriv_const_mul c ((hf.regular _).smooth.of_le + (ENat.natCast_le_of_coe_top_le_withTop le_rfl n) |>.contDiffAt)] + exact continuousWithinAt_const.mul (hF n t x) + +lemma SpatialRightContinuous.mul {F G : ℝ → ℝ → ℝ} + (hf : BoundedSmoothFamily F) (hg : BoundedSmoothFamily G) + (hF : SpatialRightContinuous F) (hG : SpatialRightContinuous G) : + SpatialRightContinuous (fun t x => F t x*G t x) := by + intro n t x + have he (s : ℝ) : iteratedDeriv n (fun x => F s x*G s x) x = + ∑ j ∈ Finset.range (n+1), (n.choose j:ℝ)*iteratedDeriv j (F s) x*iteratedDeriv (n-j) (G s) x := + iteratedDeriv_fun_mul ((hf.regular s).smooth.of_le + (ENat.natCast_le_of_coe_top_le_withTop le_rfl n) |>.contDiffAt) + ((hg.regular s).smooth.of_le (ENat.natCast_le_of_coe_top_le_withTop le_rfl n) |>.contDiffAt) + simp_rw [he] + exact tendsto_finsetSum _ (fun j _ => + (continuousWithinAt_const.mul (hF j t x)).mul (hG (n-j) t x)) + +lemma SpatialRightContinuous.timeConst {c : ℝ → ℝ} + (hc : ∀ t, ContinuousWithinAt c (Ici t) t) : + SpatialRightContinuous (fun t (_x : ℝ) => c t) := by + intro n t x + cases n with + | zero => exact hc t + | succ n => simpa only [iteratedDeriv_const,Nat.succ_ne_zero,ite_false] using + (continuousWithinAt_const : ContinuousWithinAt (fun _ : ℝ => (0:ℝ)) (Ici t) t) + +lemma compactCoeff_rightContinuous (γ : OrderParameter) {T : ℝ} (hT0 : 0 ≤ T) (hT1 : T < 1) + (t : ℝ) : ContinuousWithinAt (compactCoeff γ T) (Ici t) t := by + let g : ℝ → Time := fun s => ⟨stripClamp T s,⟨(stripClamp_mem hT0 s).1, + (stripClamp_mem hT0 s).2.trans_lt hT1⟩⟩ + have hg : Continuous g := (continuous_stripClamp T).subtype_mk _ + have hm : MapsTo g (Ici t) (Ici (g t)) := by + intro s hs + change stripClamp T t ≤ stripClamp T s + exact max_le_max_left _ (min_le_min_left _ hs) + have hh := (γ.right_continuous (g t)).comp hg.continuousAt.continuousWithinAt hm + have he : compactCoeff γ T = fun s => γ.val (g s) := by + funext s + exact extend_coe γ.val (g s) + rw [he] + exact hh + +variable {Ω : Type*} [MeasurableSpace Ω] + +lemma compactGradient_rightSmooth (W : BrownianSystem Ω) (γ : OrderParameter) + {T : ℝ} (hT0 : 0 ≤ T) (hT1 : T < 1) : SpatialRightContinuous (compactGradient W γ T) := by + intro n t x + have hc := value_derivative_continuousOn W γ hT0 hT1 (n+1) + have hh : Continuous (fun s => iteratedDeriv (n+1) (value W γ (stripClamp T s)) x) := by + have hg : ContinuousOn (fun s : ℝ => (stripClamp T s,x)) univ := + ((continuous_stripClamp T).prodMk continuous_const).continuousOn + have hm : MapsTo (fun s : ℝ => (stripClamp T s,x)) univ (Icc (0:ℝ) T ×ˢ (univ : Set ℝ)) := + fun s _ => ⟨stripClamp_mem hT0 s,mem_univ _⟩ + have he : ContinuousOn + ((fun p : ℝ × ℝ => iteratedDeriv (n+1) (value W γ p.1) p.2) ∘ + (fun s : ℝ => (stripClamp T s,x))) univ := + ContinuousOn.comp (f := fun s : ℝ => (stripClamp T s,x)) + (g := fun p : ℝ × ℝ => iteratedDeriv (n+1) (value W γ p.1) p.2) hc hg hm + exact continuousOn_univ.mp he + change ContinuousWithinAt (fun s => iteratedDeriv n (deriv (value W γ (stripClamp T s))) x) (Ici t) t + simpa only [iteratedDeriv_succ'] using hh.continuousAt.continuousWithinAt + +lemma compactValueRate_rightSmooth (W : BrownianSystem Ω) (γ : OrderParameter) + {T : ℝ} (hT0 : 0 ≤ T) (hT1 : T < 1) : SpatialRightContinuous (compactValueRate W γ T) := by + have hu := compactGradient_family W γ hT0 hT1 + have hur := compactGradient_rightSmooth W γ hT0 hT1 + have hc : BoundedSmoothFamily (fun t (_x : ℝ) => compactCoeff γ T t) := by + apply BoundedSmoothFamily.timeConst (C := ⟨γ.val ⟨T,⟨hT0,hT1⟩⟩,γ.nonneg _⟩) (compactCoeff_measurable γ T) + intro t + rw [abs_of_nonneg (compactCoeff_bounds γ hT0 hT1 t).1] + exact (compactCoeff_bounds γ hT0 hT1 t).2 + have hcr := SpatialRightContinuous.timeConst (compactCoeff_rightContinuous γ hT0 hT1) + have hh := SpatialRightContinuous.add (hu.deriv.const_mul (-(1/2:ℝ))) + ((hc.mul (hu.mul hu)).const_mul (-(1/2:ℝ))) + (SpatialRightContinuous.const_mul hu.deriv hur.deriv (-(1/2:ℝ))) + (SpatialRightContinuous.const_mul (hc.mul (hu.mul hu)) + (SpatialRightContinuous.mul hc (hu.mul hu) hcr (SpatialRightContinuous.mul hu hu hur hur)) (-(1/2:ℝ))) + convert hh using 1 + funext t x + unfold compactValueRate valueRate compactGradient curvature gradient compactCoeff + ring + +theorem value_derivative_hasDerivWithinAt_right (W : BrownianSystem Ω) (γ : OrderParameter) + {T t : ℝ} (hT0 : 0 ≤ T) (hT1 : T < 1) (ht0 : 0 ≤ t) (htT : t < T) + (m : ℕ) (x : ℝ) : + HasDerivWithinAt (fun s => iteratedDeriv m (value W γ s) x) + (iteratedDeriv m (compactValueRate W γ T t) x) (Ioi t) t := by + have hD := (compactValueRate_family W γ hT0 hT1).iteratedDeriv m + have hi := intervalIntegral.integral_hasDerivWithinAt_right + (a := t) (b := t) (s := Ici t) (t := Ioi t) + (hD.intervalIntegrable x t t) + ((hD.measurable.comp (measurable_id.prodMk measurable_const)).stronglyMeasurable.stronglyMeasurableAtFilter) + ((compactValueRate_rightSmooth W γ hT0 hT1 m t x).mono Ioi_subset_Ici_self) + have hh := (hi.mono Ioi_subset_Ici_self).const_add (iteratedDeriv m (value W γ t) x) + apply hh.congr_of_eventuallyEq + · filter_upwards [self_mem_nhdsWithin,mem_nhdsWithin_of_mem_nhds (gt_mem_nhds htT)] with s hs hsT + rw [compactRate_integral_derivative W γ hT0 hT1 ht0 hs.le hsT.le m x] + ring + · simp + +end ZeroTemperatureSK + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKSupport/Regularity/TimeFields.lean b/lean/OAI/Probability/SKSupport/Regularity/TimeFields.lean new file mode 100644 index 0000000000000000000000000000000000000000..a9924083a270a2a32412827fb09cc51bfa0cc033 --- /dev/null +++ b/lean/OAI/Probability/SKSupport/Regularity/TimeFields.lean @@ -0,0 +1,160 @@ +import Mathlib +import OAI.Probability.SKSupport.Foundations.RightGenerator + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section +namespace ZeroTemperatureSK +open Heat WeakIto + +structure TimeField (T : ℝ) where + f : ℝ → ℝ → ℝ + d : ℝ → ℝ → ℝ + smooth : BoundedSmoothFamily f + rate_smooth : BoundedSmoothFamily d + continuous : Continuous (fun p : ℝ × ℝ => f p.1 p.2) + rate_right : ∀ t x, ContinuousWithinAt (fun s => d s x) (Ioi t) t + time_deriv : ∀ t, 0 ≤ t → t < T → ∀ x, + HasDerivWithinAt (fun s => f s x) (d t x) (Ioi t) t + +namespace TimeField +variable {T : ℝ} + +def add (F G : TimeField T) : TimeField T where + f := fun t x => F.f t x+G.f t x + d := fun t x => F.d t x+G.d t x + smooth := F.smooth.add G.smooth + rate_smooth := F.rate_smooth.add G.rate_smooth + continuous := F.continuous.add G.continuous + rate_right := fun t x => (F.rate_right t x).add (G.rate_right t x) + time_deriv := fun t ht hT x => (F.time_deriv t ht hT x).add (G.time_deriv t ht hT x) + +def const_mul (c : ℝ) (F : TimeField T) : TimeField T where + f := fun t x => c*F.f t x + d := fun t x => c*F.d t x + smooth := F.smooth.const_mul c + rate_smooth := F.rate_smooth.const_mul c + continuous := continuous_const.mul F.continuous + rate_right := fun t x => continuousWithinAt_const.mul (F.rate_right t x) + time_deriv := fun t ht hT x => (F.time_deriv t ht hT x).const_mul c + +def mul (F G : TimeField T) : TimeField T where + f := fun t x => F.f t x*G.f t x + d := fun t x => F.d t x*G.f t x+F.f t x*G.d t x + smooth := F.smooth.mul G.smooth + rate_smooth := (F.rate_smooth.mul G.smooth).add (F.smooth.mul G.rate_smooth) + continuous := F.continuous.mul G.continuous + rate_right := fun t x => ((F.rate_right t x).mul + ((G.continuous.comp (continuous_id.prodMk continuous_const)).continuousAt.continuousWithinAt)).add + (((F.continuous.comp (continuous_id.prodMk continuous_const)).continuousAt.continuousWithinAt).mul (G.rate_right t x)) + time_deriv := fun t ht hT x => (F.time_deriv t ht hT x).mul (G.time_deriv t ht hT x) + +lemma integral_rate (F : TimeField T) {a b : ℝ} (ha : 0 ≤ a) (hab : a ≤ b) (hb : b ≤ T) (x : ℝ) : + F.f b x-F.f a x=∫ t in a..b, F.d t x := by + apply (intervalIntegral.integral_eq_sub_of_hasDeriv_right_of_le hab _ _ + (F.rate_smooth.intervalIntegrable x a b)).symm + · exact (F.continuous.comp (continuous_id.prodMk continuous_const)).continuousOn + · intro t ht + exact F.time_deriv t (ha.trans ht.1.le) (ht.2.trans_le hb) x + +def generator (F : TimeField T) (b : ℝ → ℝ → ℝ) (t x : ℝ) : ℝ := + deriv (F.f t) x*b t x+(1/2:ℝ)*deriv (deriv (F.f t)) x+F.d t x + +lemma generator_add (F G : TimeField T) (b : ℝ → ℝ → ℝ) (t x : ℝ) : + (F.add G).generator b t x=F.generator b t x+G.generator b t x := by + have hF (x : ℝ) := ((F.smooth.regular t).smooth.differentiable (by simp) x).hasDerivAt + have hG (x : ℝ) := ((G.smooth.regular t).smooth.differentiable (by simp) x).hasDerivAt + have hFd (x : ℝ) := ((F.smooth.deriv.regular t).smooth.differentiable (by simp) x).hasDerivAt + have hGd (x : ℝ) := ((G.smooth.deriv.regular t).smooth.differentiable (by simp) x).hasDerivAt + have he : deriv (fun y => F.f t y+G.f t y)=fun y => deriv (F.f t) y+deriv (G.f t) y := + funext (fun y => ((hF y).add (hG y)).deriv) + dsimp only [generator,add] + have hd := ((hFd x).add (hGd x)).deriv + change deriv (fun y => deriv (F.f t) y+deriv (G.f t) y) x = _ at hd + rw [he,hd] + ring + +lemma generator_const_mul (F : TimeField T) (c : ℝ) (b : ℝ → ℝ → ℝ) (t x : ℝ) : + (F.const_mul c).generator b t x=c*F.generator b t x := by + have hF (x : ℝ) := ((F.smooth.regular t).smooth.differentiable (by simp) x).hasDerivAt + have hFd (x : ℝ) := ((F.smooth.deriv.regular t).smooth.differentiable (by simp) x).hasDerivAt + have he : deriv (fun y => c*F.f t y)=fun y => c*deriv (F.f t) y := + funext (fun y => ((hF y).const_mul c).deriv) + dsimp only [generator,const_mul] + rw [he,((hFd x).const_mul c).deriv] + ring + +lemma generator_mul (F G : TimeField T) (b : ℝ → ℝ → ℝ) (t x : ℝ) : + (F.mul G).generator b t x=F.f t x*G.generator b t x+G.f t x*F.generator b t x+ + deriv (F.f t) x*deriv (G.f t) x := by + have hF (x : ℝ) := ((F.smooth.regular t).smooth.differentiable (by simp) x).hasDerivAt + have hG (x : ℝ) := ((G.smooth.regular t).smooth.differentiable (by simp) x).hasDerivAt + have hFd (x : ℝ) := ((F.smooth.deriv.regular t).smooth.differentiable (by simp) x).hasDerivAt + have hGd (x : ℝ) := ((G.smooth.deriv.regular t).smooth.differentiable (by simp) x).hasDerivAt + have he : deriv (fun y => F.f t y*G.f t y)=fun y => deriv (F.f t) y*G.f t y+F.f t y*deriv (G.f t) y := + funext (fun y => ((hF y).mul (hG y)).deriv) + have hd := (((hFd x).mul (hG x)).add ((hF x).mul (hGd x))).deriv + change deriv (fun y => deriv (F.f t) y*G.f t y+F.f t y*deriv (G.f t) y) x = _ at hd + dsimp only [generator,mul] + rw [he,hd] + ring + +variable {Ω : Type*} [MeasurableSpace Ω] + +def expected (F : TimeField T) (b : BoundedLipschitzDrift) (W : BrownianSystem Ω) (t : ℝ) : ℝ := + ∫ ξ, F.f t (b.solution W.driver (Real.toNNReal t) ξ) ∂W.law + +lemma expected_continuous (F : TimeField T) (b : BoundedLipschitzDrift) (W : BrownianSystem Ω) : + Continuous (F.expected b W) := by + let := W.isProbability + obtain ⟨bound,hbound⟩ := F.smooth.bound + apply continuous_of_dominated (bound := fun _ => (bound:ℝ)) + · intro time + exact (integrable_family_comp F.smooth time (b.solution_measurable W _)).aestronglyMeasurable + · intro time + exact Eventually.of_forall (fun sample => by + simpa only [Real.norm_eq_abs] using + hbound time (b.solution W.driver (Real.toNNReal time) sample)) + · exact integrable_const _ + · filter_upwards [b.solution_continuous_ae W] with sample hsample + exact F.continuous.comp (continuous_id.prodMk (hsample.comp continuous_real_toNNReal)) + +lemma expected_hasDerivWithinAt_right (F : TimeField T) (b : BoundedLipschitzDrift) (W : BrownianSystem Ω) + (s : ℝ≥0) (hs : (s:ℝ) < T) + (hbr : ∀ᵐ ξ ∂W.law, ContinuousWithinAt (fun r => b.pathDrift W r ξ) (Ioi (s:ℝ)) s) : + HasDerivWithinAt (F.expected b W) + (∫ ξ, F.generator b.f s (b.solution W.driver s ξ) ∂W.law) (Ioi (s:ℝ)) s := by + let := W.isProbability + have hd := ZeroTemperatureSK.expected_hasDerivWithinAt_right W b F.smooth F.rate_smooth + (fun a c ha hac hc x => F.integral_rate ha hac hc x) s hs (F.rate_right s) hbr + have hx := b.solution_measurable W s + have hi1 : Integrable (fun ξ => deriv (F.f s) (b.solution W.driver s ξ)*b.pathDrift W s ξ) W.law := by + apply (integrable_family_comp F.smooth.deriv (s:ℝ) hx).mul_bdd + · exact ((b.pathDrift_measurable W).comp measurable_prodMk_left).aestronglyMeasurable + · exact Eventually.of_forall (fun ξ => b.pathDrift_bound W s ξ) + have hi2 := integrable_family_comp (P := W.law) F.smooth.deriv.deriv (s:ℝ) hx + have hi3 := integrable_family_comp (P := W.law) F.rate_smooth (s:ℝ) hx + have he : (∫ ξ, deriv (F.f s) (b.solution W.driver s ξ)*b.pathDrift W s ξ ∂W.law)+ + (1/2:ℝ)*(∫ ξ, deriv (deriv (F.f s)) (b.solution W.driver s ξ) ∂W.law)+ + (∫ ξ, F.d s (b.solution W.driver s ξ) ∂W.law) = + ∫ ξ, F.generator b.f s (b.solution W.driver s ξ) ∂W.law := by + have hi12 : Integrable (fun ξ => deriv (F.f s) (b.solution W.driver s ξ)*b.pathDrift W s ξ+ + (1/2:ℝ)*deriv (deriv (F.f s)) (b.solution W.driver s ξ)) W.law := hi1.add (hi2.const_mul (1/2:ℝ)) + rw [← integral_const_mul,← integral_add hi1 (hi2.const_mul (1/2:ℝ)), + ← integral_add hi12 hi3] + apply integral_congr_ae + filter_upwards [] with ξ + simp only [generator,BoundedLipschitzDrift.pathDrift,Real.toNNReal_coe] + rw [he] at hd + exact hd + +end TimeField +end ZeroTemperatureSK + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKSupport/Regularity/TimeStepBound.lean b/lean/OAI/Probability/SKSupport/Regularity/TimeStepBound.lean new file mode 100644 index 0000000000000000000000000000000000000000..f4c77e18bff987e20ab91fff2f21d6bd14306467 --- /dev/null +++ b/lean/OAI/Probability/SKSupport/Regularity/TimeStepBound.lean @@ -0,0 +1,138 @@ +import Mathlib +import OAI.Probability.SKSupport.Moments.NormalFirstMoment + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section +namespace ZeroTemperatureSK.WeakIto + +lemma time_step_bound {F D : ℝ → ℝ → ℝ} (s h x z : ℝ) (hh : 0 ≤ h) + (L : ℝ≥0) + (hD : ∀ r ∈ Set.Icc s (s+h), + HasDerivWithinAt (fun t => F t z) (D r z) (Set.Icc s (s+h)) r) + (hL : ∀ r ∈ Set.Icc s (s+h), |D r z-D s x| ≤ (L:ℝ)*(|r-s|+|z-x|)) : + |F (s+h) z-F s z-h*D s x| ≤ (L:ℝ)*h*(h+|z-x|) := by + let g : ℝ → ℝ := fun t => F t z-t*D s x + have hd (r : ℝ) (hr : r ∈ Set.Icc s (s+h)) : + HasDerivWithinAt g (D r z-D s x) (Set.Icc s (s+h)) r := by + have h2 : HasDerivWithinAt (fun t : ℝ => t*D s x) (D s x) (Set.Icc s (s+h)) r := by + simpa using ((hasDerivAt_id r).mul_const (D s x)).hasDerivWithinAt + exact (hD r hr).sub h2 + have hb (r : ℝ) (hr : r ∈ Set.Icc s (s+h)) : + ‖D r z-D s x‖ ≤ (L:ℝ)*(h+|z-x|) := by + rw [Real.norm_eq_abs] + apply (hL r hr).trans + apply mul_le_mul_of_nonneg_left _ L.coe_nonneg + rw [abs_of_nonneg (sub_nonneg.mpr hr.1)] + linarith [hr.2] + have hm := (convex_Icc s (s+h)).norm_image_sub_le_of_norm_hasDerivWithin_le + (fun r hr => hd r hr) hb + (show s ∈ Set.Icc s (s+h) by constructor <;> linarith) + (show s+h ∈ Set.Icc s (s+h) by constructor <;> linarith) + simp only [g, Real.norm_eq_abs, add_sub_cancel_left, abs_of_nonneg hh] at hm + convert hm using 1 + · congr 1; ring + · ring + +variable {Ω : Type*} [MeasurableSpace Ω] {P : Measure Ω} {B : ℝ≥0 → Ω → ℝ} + +lemma expected_time_space_step (hB : IsPreBrownianReal B P) + (hm : ∀ t, Measurable (B t)) (s h : ℝ≥0) {Y A : Ω → ℝ} + (hY : Measurable[Filtration.natural B (fun t => (hm t).stronglyMeasurable) s] Y) + (hYi : Integrable Y P) (hA : Measurable A) (M : ℝ≥0) + (hAb : ∀ ω, |A ω| ≤ (M:ℝ)*(h:ℝ)) {F D : ℝ → ℝ → ℝ} + (hf : ∀ t, ContDiff ℝ 3 (F t)) + (C₁ C₂ C₃ Ct L : ℝ≥0) (hC₁ : ∀ t x, |deriv (F t) x| ≤ C₁) + (hC₂ : ∀ t x, |deriv (deriv (F t)) x| ≤ C₂) + (hC₃ : ∀ t x, |iteratedDeriv 3 (F t) x| ≤ C₃) + (hDm : Measurable (D s)) (hCt : ∀ x, |D s x| ≤ Ct) + (hD : ∀ r ∈ Set.Icc (s:ℝ) ((s:ℝ)+(h:ℝ)), ∀ z, + HasDerivWithinAt (fun t => F t z) (D r z) + (Set.Icc (s:ℝ) ((s:ℝ)+(h:ℝ))) r) + (hL : ∀ r ∈ Set.Icc (s:ℝ) ((s:ℝ)+(h:ℝ)), ∀ z x, + |D r z-D s x| ≤ (L:ℝ)*(|r-(s:ℝ)|+|z-x|)) : + |(∫ ω, F ((s:ℝ)+(h:ℝ)) (Y ω + (B (s+h) ω-B s ω) + A ω) ∂P) - + (∫ ω, F s (Y ω) ∂P) - (∫ ω, deriv (F s) (Y ω)*A ω ∂P) - + (h:ℝ) * ((∫ ω, D s (Y ω) ∂P) + + (1/2:ℝ) * (∫ ω, deriv (deriv (F s)) (Y ω) ∂P))| ≤ + (C₃:ℝ)/6 * ((h:ℝ)*Real.sqrt (h:ℝ)*normalThirdMoment) + + (C₂:ℝ)*(M:ℝ)*(h:ℝ) * (Real.sqrt (h:ℝ)*normalFirstMoment + (M:ℝ)*(h:ℝ)) + + (L:ℝ)*(h:ℝ) * ((h:ℝ) + Real.sqrt (h:ℝ)*normalFirstMoment + (M:ℝ)*(h:ℝ)) := by + let := hB.isGaussianProcess.isProbabilityMeasure + have hYm := hY.mono + ((Filtration.natural B (fun t => (hm t).stronglyMeasurable)).le s) le_rfl + have hd : Integrable (fun ω => B (s+h) ω - B s ω) P := + (hB.integrable_eval _).sub (hB.integrable_eval _) + have hAi : Integrable A P := Integrable.of_bound hA.aestronglyMeasurable ((M:ℝ)*(h:ℝ)) + (Filter.Eventually.of_forall (fun ω => by simpa only [Real.norm_eq_abs] using hAb ω)) + let Z (ω : Ω) := Y ω + (B (s+h) ω-B s ω) + A ω + have hZi : Integrable Z P := (hYi.add hd).add hAi + have hiF (t : ℝ) : Integrable (fun ω => F t (Z ω)) P := + integrable_comp_of_bounded_deriv ((hf t).differentiable (by norm_num)) C₁ (hC₁ t) hZi + have hiD : Integrable (fun ω => D s (Y ω)) P := Integrable.of_bound + (hDm.comp hYm).aestronglyMeasurable Ct + (Filter.Eventually.of_forall (fun ω => by simpa only [Real.norm_eq_abs] using hCt (Y ω))) + let R (ω : Ω) := F ((s:ℝ)+(h:ℝ)) (Z ω)-F s (Z ω)-(h:ℝ)*D s (Y ω) + have hiR : Integrable R P := ((hiF _).sub (hiF _)).sub (hiD.const_mul _) + have hiDb : Integrable (fun ω => (h:ℝ)+|B (s+h) ω-B s ω|+(M:ℝ)*(h:ℝ)) P := + ((integrable_const _).add hd.abs).add (integrable_const _) + have hRb : |∫ ω, R ω ∂P| ≤ + (L:ℝ)*(h:ℝ) * ((h:ℝ) + Real.sqrt (h:ℝ)*normalFirstMoment + (M:ℝ)*(h:ℝ)) := by + calc + _ ≤ ∫ ω, |R ω| ∂P := abs_integral_le_integral_abs + _ ≤ ∫ ω, (L:ℝ)*(h:ℝ) * ((h:ℝ)+|B (s+h) ω-B s ω|+(M:ℝ)*(h:ℝ)) ∂P := by + apply integral_mono hiR.abs (hiDb.const_mul _) + intro ω + have he := time_step_bound (s:ℝ) (h:ℝ) (Y ω) (Z ω) h.coe_nonneg L + (fun r hr => hD r hr (Z ω)) (fun r hr => hL r hr (Z ω) (Y ω)) + apply he.trans + have hz : |Z ω-Y ω| ≤ |B (s+h) ω-B s ω|+(M:ℝ)*(h:ℝ) := by + have hz : Z ω-Y ω = (B (s+h) ω-B s ω)+A ω := by dsimp only [Z]; ring + rw [hz] + have habs := abs_add_le (B (s+h) ω-B s ω) (A ω) + linarith [hAb ω] + apply mul_le_mul_of_nonneg_left _ (mul_nonneg L.coe_nonneg h.coe_nonneg) + linarith + _ = _ := by + have hiDa : Integrable (fun ω => (h:ℝ)+|B (s+h) ω-B s ω|) P := + (integrable_const _).add hd.abs + rw [integral_const_mul, integral_add hiDa (integrable_const _), + integral_add (integrable_const _) hd.abs, increment_abs_first hB s h] + simp + have hR : (∫ ω, R ω ∂P) = (∫ ω, F ((s:ℝ)+(h:ℝ)) (Z ω) ∂P) - + (∫ ω, F s (Z ω) ∂P) - (h:ℝ)*(∫ ω, D s (Y ω) ∂P) := by + have hiFd : Integrable (fun ω => F ((s:ℝ)+(h:ℝ)) (Z ω)-F s (Z ω)) P := + (hiF _).sub (hiF _) + dsimp only [R] + rw [integral_sub hiFd (hiD.const_mul _), integral_sub (hiF _) (hiF _), + integral_const_mul] + have hG := expected_control_step hB hm s h hY hYi hA M hAb (hf s) + C₁ C₂ C₃ (hC₁ s) (hC₂ s) (hC₃ s) + rw [hR] at hRb + have htri := abs_add_le + ((∫ ω, F s (Z ω) ∂P) - (∫ ω, F s (Y ω) ∂P) - + (∫ ω, deriv (F s) (Y ω)*A ω ∂P) - + (h:ℝ)/2*(∫ ω, deriv (deriv (F s)) (Y ω) ∂P)) + ((∫ ω, F ((s:ℝ)+(h:ℝ)) (Z ω) ∂P) - (∫ ω, F s (Z ω) ∂P) - + (h:ℝ)*(∫ ω, D s (Y ω) ∂P)) + calc + _ = |((∫ ω, F s (Z ω) ∂P) - (∫ ω, F s (Y ω) ∂P) - + (∫ ω, deriv (F s) (Y ω)*A ω ∂P) - + (h:ℝ)/2*(∫ ω, deriv (deriv (F s)) (Y ω) ∂P)) + + ((∫ ω, F ((s:ℝ)+(h:ℝ)) (Z ω) ∂P) - (∫ ω, F s (Z ω) ∂P) - + (h:ℝ)*(∫ ω, D s (Y ω) ∂P))| := by congr 1; dsimp only [Z]; ring + _ ≤ _ := htri.trans (add_le_add hG hRb) + +end ZeroTemperatureSK.WeakIto + +end +end +end + +end OAI diff --git a/lean/OAI/Probability/SKSupport/Support/CDFParameters.lean b/lean/OAI/Probability/SKSupport/Support/CDFParameters.lean new file mode 100644 index 0000000000000000000000000000000000000000..5ba82666e210d7b86d935414d6b8f995a12ad7e9 --- /dev/null +++ b/lean/OAI/Probability/SKSupport/Support/CDFParameters.lean @@ -0,0 +1,165 @@ +import Mathlib +import OAI.Probability.SKSupport.Regularity.RightRegularity +import OAI.Probability.SKSupport.Support.FiniteCDF +import OAI.Probability.SKSupport.Support.Closure + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section +namespace ZeroTemperatureSK + +lemma extend_add_fun (f g : Time → ℝ) : extend (fun t => f t+g t)=fun t => extend f t+extend g t := by + funext t + by_cases ht : t ∈ Ico (0:ℝ) 1 <;> simp [extend,ht] +lemma extend_sub_fun (f g : Time → ℝ) : extend (fun t => f t-g t)=fun t => extend f t-extend g t := by + funext t + by_cases ht : t ∈ Ico (0:ℝ) 1 <;> simp [extend,ht] + +def OrderParameter.addCDF (γ : OrderParameter) (ν : Measure Time) [IsFiniteMeasure ν] : OrderParameter where + val := fun t => γ.val t+finiteCDF ν t + nonneg := fun t => add_nonneg (γ.nonneg t) (finiteCDF_nonneg ν t) + monotone := γ.monotone.add (finiteCDF_monotone ν) + right_continuous := fun t => (γ.right_continuous t).add (finiteCDF_rightContinuous ν t) + integrable := by rw [extend_add_fun];exact γ.integrable.add (finiteCDF_integrable ν) + +lemma OrderParameter.addCDF_difference (γ : OrderParameter) (ν : Measure Time) [IsFiniteMeasure ν] (t : ℝ) : + extend (γ.addCDF ν).val t-extend γ.val t=extend (finiteCDF ν) t := by + change extend (fun t => γ.val t+finiteCDF ν t) t-extend γ.val t=_ + rw [extend_add_fun] + ring + +lemma stieltjes_real (γ : OrderParameter) {μ : Measure Time} (hμ : IsStieltjesMeasure γ μ) (t : Time) : + (μ (Iic t)).toReal=γ.val t := by rw [hμ t,ENNReal.toReal_ofReal (γ.nonneg t)] + +lemma finiteCDF_le_parameter (γ : OrderParameter) {μ ν : Measure Time} (hμ : IsStieltjesMeasure γ μ) + (hν : ν ≤ μ) (t : Time) : finiteCDF ν t ≤ γ.val t := by + rw [← stieltjes_real γ hμ t] + apply ENNReal.toReal_mono + · rw [hμ t];exact ENNReal.ofReal_ne_top + · exact hν (Iic t) + +lemma cdf_real_add_Ioc {μ : Measure Time} {a b : Time} (hab : a ≤ b) (hfinite : μ (Iic b) ≠ ⊤) : + (μ (Iic a)).toReal+(μ (Ioc a b)).toReal=(μ (Iic b)).toReal := by + have hf1 := ne_top_of_le_ne_top hfinite (measure_mono (Iic_subset_Iic.mpr hab)) + have hf2 := ne_top_of_le_ne_top hfinite (measure_mono (show Ioc a b ⊆ Iic b from fun _ h => h.2)) + have he : μ (Iic a)+μ (Ioc a b)=μ (Iic b) := by + rw [← measure_union (Iic_disjoint_Ioc le_rfl) measurableSet_Ioc,Iic_union_Ioc_eq_Iic hab] + have hh := congrArg ENNReal.toReal he + rw [ENNReal.toReal_add hf1 hf2] at hh + exact hh + +lemma removeCDF_monotone (γ : OrderParameter) {μ ν : Measure Time} [IsFiniteMeasure ν] + (hμ : IsStieltjesMeasure γ μ) (hν : ν ≤ μ) : Monotone (fun t => γ.val t-finiteCDF ν t) := by + intro a b hab + have hf : μ (Iic b) ≠ ⊤ := by rw [hμ b];exact ENNReal.ofReal_ne_top + have hm := cdf_real_add_Ioc hab hf + rw [stieltjes_real γ hμ a,stieltjes_real γ hμ b] at hm + have hn := cdf_real_add_Ioc (μ := ν) hab (measure_ne_top ν _) + have hi : (ν (Ioc a b)).toReal ≤ (μ (Ioc a b)).toReal := + ENNReal.toReal_mono (ne_top_of_le_ne_top hf (measure_mono (fun _ h => h.2))) (hν (Ioc a b)) + change γ.val a-(ν (Iic a)).toReal ≤ γ.val b-(ν (Iic b)).toReal + linarith + +def OrderParameter.removeCDF (γ : OrderParameter) {μ ν : Measure Time} [IsFiniteMeasure ν] + (hμ : IsStieltjesMeasure γ μ) (hν : ν ≤ μ) : OrderParameter where + val := fun t => γ.val t-finiteCDF ν t + nonneg := fun t => sub_nonneg.mpr (finiteCDF_le_parameter γ hμ hν t) + monotone := removeCDF_monotone γ hμ hν + right_continuous := fun t => (γ.right_continuous t).sub (finiteCDF_rightContinuous ν t) + integrable := by rw [extend_sub_fun];exact γ.integrable.sub (finiteCDF_integrable ν) + +lemma OrderParameter.removeCDF_difference (γ : OrderParameter) {μ ν : Measure Time} [IsFiniteMeasure ν] + (hμ : IsStieltjesMeasure γ μ) (hν : ν ≤ μ) (t : ℝ) : + extend (γ.removeCDF hμ hν).val t-extend γ.val t= -extend (finiteCDF ν) t := by + change extend (fun t => γ.val t-finiteCDF ν t) t-extend γ.val t=_ + rw [extend_sub_fun] + ring + +lemma OrderParameter.original_deterministic (γ : OrderParameter) : + SupportDeterministic.IsOrderParameter (extend γ.val) where + nonneg := fun t _ => γ.extend_nonneg t + monotone := by + intro a ha b hb hab + simpa only [extend,dite_eq_left ha,dite_eq_left hb] using γ.monotone (show (⟨a,ha⟩ : Time) ≤ ⟨b,hb⟩ from hab) + rightContinuous := by + intro t ht + let T : ℝ := (t+1)/2 + have hT0 : 0 ≤ T := by dsimp [T];linarith [ht.1,ht.2] + have hT1 : T < 1 := by dsimp [T];linarith [ht.1,ht.2] + have htT : t < T := by dsimp [T];linarith [ht.2] + have hc := compactCoeff_rightContinuous γ hT0 hT1 t + have he : compactCoeff γ T =ᶠ[𝓝[Ici t] t] extend γ.val := by + filter_upwards [self_mem_nhdsWithin,mem_nhdsWithin_of_mem_nhds (gt_mem_nhds htT)] with s hs hsT + rw [compactCoeff,stripClamp_eq ⟨ht.1.trans hs,hsT.le⟩] + have hh := hc.tendsto.congr' he + change Tendsto (extend γ.val) (𝓝[Ici t] t) (𝓝 (extend γ.val t)) + simpa only [compactCoeff,stripClamp_eq ⟨ht.1,htT.le⟩] using hh + integrable := γ.integrable.integrableOn + +lemma stieltjes_deterministic (γ : OrderParameter) {μ : Measure Time} (hμ : IsStieltjesMeasure γ μ) : + SupportDeterministic.IsStieltjesMeasure (extend γ.val) μ := by + intro t + simpa only [extend,dite_eq_left t.property] using hμ t + +end ZeroTemperatureSK + +end +end +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section +namespace ZeroTemperatureSK + +lemma finiteCDF_fubini {H : ℝ → ℝ} (hH : IntervalIntegrable H volume 0 1) + (ν : Measure Time) [IsFiniteMeasure ν] : + (∫ t in (0:ℝ)..1, extend (finiteCDF ν) t*H t)=∫ r : Time, (∫ t in (r:ℝ)..1, H t) ∂ν := by + let κ : Measure ℝ := volume.restrict (Ioc (0:ℝ) 1) + let F : ℝ → Time → ℝ := fun t r => if (r:ℝ) ≤ t then H t else 0 + have hHi : Integrable H κ := hH.1 + have hs : MeasurableSet {p : ℝ × Time | (p.2:ℝ) ≤ p.1} := + (isClosed_le (continuous_subtype_val.comp continuous_snd) continuous_fst).measurableSet + have hFi : Integrable (Function.uncurry F) (κ.prod ν) := by + have he : Function.uncurry F = {p : ℝ × Time | (p.2:ℝ) ≤ p.1}.indicator (fun p => H p.1) := by + funext p + rfl + rw [he] + exact (hHi.comp_fst ν).indicator hs + have hleft : (∫ t in (0:ℝ)..1, extend (finiteCDF ν) t*H t)=∫ t, ∫ r, F t r ∂ν ∂κ := by + rw [intervalIntegral.integral_of_le (by norm_num : (0:ℝ) ≤ 1)] + apply integral_congr_ae + filter_upwards [ae_restrict_mem measurableSet_Ioc,ae_restrict_of_ae (volume.ae_ne (1:ℝ))] with t ht ht1 + have htt : t ∈ Ico (0:ℝ) 1 := ⟨ht.1.le,lt_of_le_of_ne ht.2 ht1⟩ + rw [extend,dite_eq_left htt,finiteCDF_integral,← integral_mul_const] + apply integral_congr_ae + filter_upwards [] with r + change (if r ≤ (⟨t,htt⟩ : Time) then (1:ℝ) else 0)*H t=(if (r:ℝ) ≤ t then H t else 0) + by_cases hr : (r:ℝ) ≤ t <;> simp [hr,show (r ≤ (⟨t,htt⟩ : Time)) ↔ (r:ℝ) ≤ t from Iff.rfl] + have hright (r : Time) : (∫ t, F t r ∂κ)=∫ t in (r:ℝ)..1, H t := by + have he : (∫ t, F t r ∂κ)=∫ t, (Ioi (r:ℝ)).indicator H t ∂κ := by + apply integral_congr_ae + filter_upwards [ae_restrict_of_ae (volume.ae_ne (r:ℝ))] with t htr + simp only [F,indicator_apply,mem_Ioi] + simp only [le_iff_lt_or_eq,or_iff_left (Ne.symm htr)] + rw [he,integral_indicator measurableSet_Ioi] + change (∫ t, H t ∂((volume.restrict (Ioc (0:ℝ) 1)).restrict (Ioi (r:ℝ))))=_ + rw [Measure.restrict_restrict measurableSet_Ioi] + have heS : Ioi (r:ℝ) ∩ Ioc (0:ℝ) 1=Ioc (r:ℝ) 1 := by + ext t + simp only [mem_inter_iff,mem_Ioi,mem_Ioc] + constructor + · exact fun h => ⟨h.1,h.2.2⟩ + · exact fun h => ⟨h.1,lt_of_le_of_lt r.property.1 h.1,h.2⟩ + rw [heS,intervalIntegral.integral_of_le r.property.2.le] + rw [hleft,integral_integral_swap hFi] + exact integral_congr_ae (Eventually.of_forall hright) + +end ZeroTemperatureSK + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKSupport/Support/Closure.lean b/lean/OAI/Probability/SKSupport/Support/Closure.lean new file mode 100644 index 0000000000000000000000000000000000000000..6e772824376f0e0d0d99ab8c5c556389fee9726a --- /dev/null +++ b/lean/OAI/Probability/SKSupport/Support/Closure.lean @@ -0,0 +1,488 @@ +import Mathlib +import OAI.Probability.SKSupport.Model + +namespace OAI + +section +open MeasureTheory Set Filter +open scoped Topology ENNReal + +namespace ZeroTemperatureSK.SupportDeterministic +abbrev Time := Set.Ico (0 : ℝ) 1 + +structure IsOrderParameter (γ : ℝ → ℝ) : Prop where + nonneg : ∀ t ∈ Set.Ico (0 : ℝ) 1, 0 ≤ γ t + monotone : MonotoneOn γ (Set.Ico (0 : ℝ) 1) + rightContinuous : ∀ t ∈ Set.Ico (0 : ℝ) 1, ContinuousWithinAt γ (Set.Ici t) t + integrable : IntegrableOn γ (Set.Ico (0 : ℝ) 1) + +def IsStieltjesMeasure (γ : ℝ → ℝ) (μ : Measure Time) : Prop := + ∀ t : Time, μ (Set.Iic t) = ENNReal.ofReal (γ t) + +namespace IsStieltjesMeasure + +variable {γ : ℝ → ℝ} {μ : Measure Time} + +lemma cdf_add_Ioc (hμ : IsStieltjesMeasure γ μ) {a b : Time} (hab : a ≤ b) : + ENNReal.ofReal (γ a) + μ (Ioc a b) = ENNReal.ofReal (γ b) := by + rw [← hμ a, ← hμ b, ← measure_union (Iic_disjoint_Ioc le_rfl) measurableSet_Ioc, + Iic_union_Ioc_eq_Iic hab] + +lemma eq_cdf_of_measure_Ioc_zero (hμ : IsStieltjesMeasure γ μ) + (hγ : IsOrderParameter γ) {a b : Time} (hab : a ≤ b) + (hz : μ (Ioc a b) = 0) : γ a = γ b := by + have he := hμ.cdf_add_Ioc hab + rw [hz, add_zero] at he + exact (ENNReal.ofReal_eq_ofReal_iff (hγ.nonneg a a.property) (hγ.nonneg b b.property)).mp he + +lemma measure_zero_of_disjoint_support {s : Set Time} + (hs : Disjoint s μ.support) : μ s = 0 := by + apply measure_mono_null (Set.disjoint_left.mp hs) μ.measure_compl_support + +lemma eq_cdf_of_support_free (hμ : IsStieltjesMeasure γ μ) + (hγ : IsOrderParameter γ) {a b : Time} (hab : a ≤ b) + (hs : Disjoint (Ioc a b) μ.support) : γ a = γ b := + hμ.eq_cdf_of_measure_Ioc_zero hγ hab (measure_zero_of_disjoint_support hs) + +lemma lt_cdf_of_full_support (hμ : IsStieltjesMeasure γ μ) + (hS : μ.support = univ) {a b : Time} (hab : a < b) : γ a < γ b := by + let c : Time := ⟨((a : ℝ) + b) / 2, by + constructor + · linarith [a.property.1, b.property.1] + · linarith [a.property.2, b.property.2]⟩ + have hac : a < c := by change (a : ℝ) < ((a : ℝ) + b) / 2; change (a : ℝ) < b at hab; linarith + have hcb : c < b := by change ((a : ℝ) + b) / 2 < b; change (a : ℝ) < b at hab; linarith + have hcS : c ∈ μ.support := by rw [hS]; trivial + have hpos : 0 < μ (Ioc a b) := + lt_of_lt_of_le ((μ.mem_support_iff_forall c).mp hcS _ (Ioo_mem_nhds hac hcb)) + (measure_mono Ioo_subset_Ioc_self) + have hlt : ENNReal.ofReal (γ a) < ENNReal.ofReal (γ b) := by + rw [← hμ.cdf_add_Ioc hab.le] + exact ENNReal.lt_add_right ENNReal.ofReal_ne_top hpos.ne' + exact (ENNReal.ofReal_lt_ofReal_iff'.mp hlt).1 + +lemma strictMonoOn_of_full_support (hμ : IsStieltjesMeasure γ μ) + (hS : μ.support = univ) : StrictMonoOn γ (Ico (0 : ℝ) 1) := by + intro a ha b hb hab + exact hμ.lt_cdf_of_full_support hS (a := ⟨a,ha⟩) (b := ⟨b,hb⟩) hab + +end IsStieltjesMeasure + +def InSupport (μ : Measure Time) (t : ℝ) : Prop := + ∃ ht : t ∈ Ico (0 : ℝ) 1, (⟨t, ht⟩ : Time) ∈ μ.support + +lemma inSupport_coe {μ : Measure Time} {t : Time} : + InSupport μ t ↔ t ∈ μ.support := by + constructor + · rintro ⟨ht, h⟩; exact h + · intro ht; exact ⟨t.property, ht⟩ + +lemma exists_support_gap {μ : Measure Time} {x : Time} + (hx : x ∉ μ.support) (hright : ∃ B ∈ μ.support, x < B) : + ∃ a b : ℝ, 0 ≤ a ∧ a < b ∧ b < 1 ∧ (a = 0 ∨ InSupport μ a) ∧ + InSupport μ b ∧ ∀ t ∈ Ioo a b, ¬ InSupport μ t := by + obtain ⟨F, hF, hpre⟩ := + (Topology.IsInducing.subtypeVal (t := Ico (0 : ℝ) 1)).isClosed_iff.mp μ.isClosed_support + have hFiff (t : Time) : (t : ℝ) ∈ F ↔ t ∈ μ.support := by + change t ∈ (Subtype.val ⁻¹' F) ↔ _ + rw [hpre] + obtain ⟨B, hBS, hxB⟩ := hright + have hcompactA : IsCompact ({0} ∪ (F ∩ Icc (0 : ℝ) x)) := + isCompact_singleton.union (isCompact_Icc.inter_left hF) + obtain ⟨a, ha⟩ := hcompactA.exists_isGreatest (by exact ⟨0, Or.inl rfl⟩) + have hcompactB : IsCompact (F ∩ Icc (x : ℝ) B) := + isCompact_Icc.inter_left hF + obtain ⟨b, hb⟩ := hcompactB.exists_isLeast + ⟨B, (hFiff B).mpr hBS, hxB.le, le_rfl⟩ + have ha0 : 0 ≤ a := ha.2 (Or.inl rfl) + have hax : a ≤ x := by + rcases ha.1 with heq | hm + · simpa only [mem_singleton_iff] using heq ▸ x.property.1 + · exact hm.2.2 + have hb1 : b < 1 := hb.1.2.2.trans_lt B.property.2 + have hxb : (x : ℝ) < b := by + refine lt_of_le_of_ne hb.1.2.1 ?_ + intro heq + apply hx + apply (hFiff x).mp + simpa [heq] using hb.1.1 + refine ⟨a, b, ha0, hax.trans_lt hxb, hb1, ?_, ?_, ?_⟩ + · rcases ha.1 with heq | hm + · exact Or.inl heq + · exact Or.inr ⟨⟨ha0, hax.trans_lt x.property.2⟩, + (hFiff ⟨a, ⟨ha0, hax.trans_lt x.property.2⟩⟩).mp hm.1⟩ + · exact ⟨⟨x.property.1.trans hxb.le, hb1⟩, + (hFiff ⟨b, ⟨x.property.1.trans hxb.le, hb1⟩⟩).mp hb.1.1⟩ + · intro t ht hts + obtain ⟨ht01, hts⟩ := hts + have htF : t ∈ F := (hFiff ⟨t, ht01⟩).mpr hts + by_cases htx : t ≤ x + · exact (not_lt_of_ge (ha.2 (Or.inr ⟨htF, ht01.1, htx⟩))) ht.1 + · exact (not_lt_of_ge (hb.2 ⟨htF, le_of_not_ge htx, ht.2.le.trans hb.1.2.2⟩)) ht.2 + +lemma support_cofinal_of_no_terminal_plateau {γ : ℝ → ℝ} {μ : Measure Time} + (hγ : IsOrderParameter γ) (hμ : IsStieltjesMeasure γ μ) + (hend : ¬ ∃ a c : ℝ, 0 ≤ a ∧ a < 1 ∧ 0 ≤ c ∧ + ∀ t ∈ Ioo a 1, γ t = c) (x : Time) : + ∃ B ∈ μ.support, x < B := by + by_contra hn + push Not at hn + let d : Time := ⟨((x : ℝ) + 1) / 2, by + constructor <;> linarith [x.property.1, x.property.2]⟩ + apply hend + refine ⟨x, γ d, x.property.1, x.property.2, hγ.nonneg d d.property, ?_⟩ + intro t ht + let t' : Time := ⟨t, ⟨x.property.1.trans ht.1.le, ht.2⟩⟩ + have hxd : x < d := by change (x : ℝ) < ((x : ℝ)+1)/2; linarith [x.property.2] + have heq {u v : Time} (hu : x < u) (hv : x < v) (huv : u ≤ v) : + γ u = γ v := by + apply hμ.eq_cdf_of_support_free hγ huv + rw [Set.disjoint_left] + intro z hz hzs + exact (not_lt_of_ge (hn z hzs)) (hu.trans hz.1) + change γ t' = γ d + rcases le_total t' d with htd | hdt + · exact heq ht.1 hxd htd + · exact (heq hxd ht.1 hdt).symm + +lemma constant_on_support_gap {γ : ℝ → ℝ} {μ : Measure Time} + (hγ : IsOrderParameter γ) (hμ : IsStieltjesMeasure γ μ) + {a b : ℝ} (ha : 0 ≤ a) (hab : a < b) (hb : b < 1) + (hgap : ∀ t ∈ Ioo a b, ¬ InSupport μ t) : + ∃ c, 0 ≤ c ∧ ∀ t ∈ Ioo a b, γ t = c := by + let d : Time := ⟨(a+b)/2, by constructor <;> linarith⟩ + have hd : (d : ℝ) ∈ Ioo a b := by change a < (a+b)/2 ∧ (a+b)/2 < b; constructor <;> linarith + refine ⟨γ d, hγ.nonneg d d.property, ?_⟩ + have heq {u v : Time} (hu : (u : ℝ) ∈ Ioo a b) + (hv : (v : ℝ) ∈ Ioo a b) (huv : u ≤ v) : γ u = γ v := by + apply hμ.eq_cdf_of_support_free hγ huv + rw [Set.disjoint_left] + intro z hz hzs + exact hgap z ⟨hu.1.trans (show (u : ℝ) < z from hz.1), (show (z : ℝ) ≤ v from hz.2).trans_lt hv.2⟩ ⟨z.property, hzs⟩ + intro t ht + let t' : Time := ⟨t, ⟨ha.trans ht.1.le, ht.2.trans hb⟩⟩ + change γ t' = γ d + rcases le_total t' d with htd | hdt + · exact heq ht hd htd + · exact (heq hd ht hdt).symm + +lemma zero_on_initial_support_gap {γ : ℝ → ℝ} {μ : Measure Time} + (hγ : IsOrderParameter γ) (hμ : IsStieltjesMeasure γ μ) {b : ℝ} + (hb : b < 1) (h0 : ¬ InSupport μ 0) + (hgap : ∀ t ∈ Ioo 0 b, ¬ InSupport μ t) : + ∀ t ∈ Ioo 0 b, γ t = 0 := by + intro t ht + let t' : Time := ⟨t, ⟨ht.1.le, ht.2.trans hb⟩⟩ + have hm : μ (Iic t') = 0 := by + apply IsStieltjesMeasure.measure_zero_of_disjoint_support + rw [Set.disjoint_left] + intro z hz hzs + by_cases hz0 : (z : ℝ) = 0 + · exact h0 (hz0 ▸ ⟨z.property, hzs⟩) + · exact hgap z ⟨lt_of_le_of_ne z.property.1 (Ne.symm hz0), hz.trans_lt ht.2⟩ + ⟨z.property, hzs⟩ + rw [hμ t', ENNReal.ofReal_eq_zero] at hm + exact le_antisymm hm (hγ.nonneg t' t'.property) + +lemma IsStieltjesMeasure.finiteOnCompacts {γ : ℝ → ℝ} {μ : Measure Time} + (hμ : IsStieltjesMeasure γ μ) : IsFiniteMeasureOnCompacts μ := by + constructor + intro K hK + rcases K.eq_empty_or_nonempty with rfl | hne + · simp + · obtain ⟨b, hb⟩ := (hK.image continuous_subtype_val).exists_isGreatest (hne.image Subtype.val) + obtain ⟨b', hb'K, rfl⟩ := hb.1 + apply lt_of_le_of_lt (measure_mono (t := Iic b') ?_) + · rw [hμ b']; exact ENNReal.ofReal_lt_top + · intro t ht; exact hb.2 ⟨t, ht, rfl⟩ + +lemma isCompact_time_Iic (b : Time) : IsCompact (Iic b) := by + rw [Subtype.isCompact_iff] + have heq : Subtype.val '' Iic b = Icc (0 : ℝ) b := by + ext t + constructor + · rintro ⟨u, hu, rfl⟩; exact ⟨u.property.1, hu⟩ + · intro ht + exact ⟨⟨t, ⟨ht.1, ht.2.trans_lt b.property.2⟩⟩, ht.2, rfl⟩ + rw [heq] + exact isCompact_Icc + +end ZeroTemperatureSK.SupportDeterministic + +namespace ZeroTemperatureSK.SupportDeterministic.Variation + +lemma continuous_zero_on_support_of_integral_nonpos + {Y : Type*} [TopologicalSpace Y] [MeasurableSpace Y] + {ν : Measure Y} {F : Y → ℝ} (hF : Continuous F) + (hF0 : ∀ x, 0 ≤ F x) (hFi : Integrable F ν) (hI : ∫ x, F x ∂ν ≤ 0) : + ∀ x ∈ ν.support, F x = 0 := by + have hz : ∫ x, F x ∂ν = 0 := le_antisymm hI (integral_nonneg hF0) + have hae : F =ᵐ[ν] 0 := (integral_eq_zero_iff_of_nonneg hF0 hFi).mp hz + intro x hx + by_contra hne + have hn : {y | F y ≠ 0} ∈ 𝓝 x := + (isOpen_ne.preimage hF).mem_nhds hne + have hp : 0 < ν {y | F y ≠ 0} := (ν.mem_support_iff_forall x).mp hx _ hn + have hzset : ν {y | F y ≠ 0} = 0 := by + simpa only [Filter.EventuallyEq, ae_iff, Pi.zero_apply] using hae + exact hp.ne' hzset + +theorem zero_on_support_of_compact_mass_removal {γ G : ℝ → ℝ} {μ : Measure Time} + (hμ : IsStieltjesMeasure γ μ) + (hGc : ContinuousOn G (Ico (0 : ℝ) 1)) + (hG0 : ∀ t ∈ Ico (0 : ℝ) 1, 0 ≤ G t) + (hremove : ∀ K : Set Time, IsCompact K → ∫ t in K, G t ∂μ ≤ 0) : + ∀ t, InSupport μ t → G t = 0 := by + let : IsFiniteMeasureOnCompacts μ := hμ.finiteOnCompacts + have hcont : Continuous (fun t : Time => G t) := + continuousOn_iff_continuous_domRestrict.mp hGc + intro t ht + obtain ⟨ht, hts⟩ := ht + let x : Time := ⟨t,ht⟩ + let b : Time := ⟨(t+1)/2, by constructor <;> linarith [ht.1, ht.2]⟩ + have hxb : x < b := by change t < (t+1)/2; linarith [ht.2] + have hxint : x ∈ interior (Iic b) := + mem_interior_iff_mem_nhds.mpr (mem_of_superset (Iio_mem_nhds hxb) Iio_subset_Iic_self) + have hxs : x ∈ (μ.restrict (Iic b)).support := μ.interior_inter_support ⟨hxint, hts⟩ + exact continuous_zero_on_support_of_integral_nonpos hcont + (fun y => hG0 y y.property) + (hcont.continuousOn.integrableOn_compact (isCompact_time_Iic b)) + (hremove (Iic b) (isCompact_time_Iic b)) x hxs + +lemma value_contact_of_potential_min {q G : ℝ → ℝ} {s : ℝ} + (hs : s ∈ Ioo (0 : ℝ) 1) (hG0 : ∀ t ∈ Ico (0 : ℝ) 1, 0 ≤ G t) + (hGs : G s = 0) (hGd : HasDerivAt G (s - q s) s) : q s = s := by + have hmin : IsLocalMin G s := by + filter_upwards [Ioo_mem_nhds hs.1 hs.2] with t ht + rw [hGs] + exact hG0 t ⟨ht.1.le, ht.2⟩ + have hzero := hmin.hasDerivAt_eq_zero hGd + linarith + +lemma derivative_contact_of_potential_min {q G : ℝ → ℝ} {s d : ℝ} + (hs : s ∈ Ico (0 : ℝ) 1) + (hGc : ContinuousOn G (Ico (0 : ℝ) 1)) + (hG0 : ∀ t ∈ Ico (0 : ℝ) 1, 0 ≤ G t) + (hGs : G s = 0) (hqs : q s = s) + (hqd : HasDerivWithinAt q d (Ici s) s) + (hGd : ∀ t ∈ Ioo s 1, HasDerivAt G (t - q t) t) : d ≤ 1 := by + by_contra hd + have hd : 1 < d := lt_of_not_ge hd + have hsel : Ici s \ {s} = Ioi s := by ext t; simp + have hlim : Tendsto (slope q s) (𝓝[>] s) (𝓝 d) := by + simpa only [hsel] using (hasDerivWithinAt_iff_tendsto_slope.mp hqd) + have he : ∀ᶠ t in 𝓝[>] s, 1 < slope q s t ∧ t < 1 := + (hlim.eventually (Ioi_mem_nhds hd)).and + (mem_nhdsWithin_of_mem_nhds (gt_mem_nhds hs.2)) + obtain ⟨b, hsb, hb⟩ := mem_nhdsGT_iff_exists_Ioo_subset.mp he + obtain ⟨y, hsy, hyb⟩ := exists_between (show s < b from hsb) + have hy1 : y < 1 := (hb ⟨hsy, hyb⟩).2 + have hanti : StrictAntiOn G (Icc s y) := by + apply strictAntiOn_of_deriv_neg (convex_Icc s y) + (hGc.mono (by intro t ht; exact ⟨hs.1.trans ht.1, ht.2.trans_lt hy1⟩)) + intro t ht + rw [interior_Icc] at ht + have hslt := (hb ⟨ht.1, ht.2.trans hyb⟩).1 + have hgt : t < q t := by + rw [slope_def_field, hqs, lt_div_iff₀ (sub_pos.mpr ht.1)] at hslt + linarith + rw [(hGd t ⟨ht.1, ht.2.trans hy1⟩).deriv] + exact sub_neg.mpr hgt + have hneg := hanti (left_mem_Icc.mpr hsy.le) (right_mem_Icc.mpr hsy.le) hsy + rw [hGs] at hneg + exact (not_lt_of_ge (hG0 y ⟨hs.1.trans hsy.le, hy1⟩)) hneg + +theorem contact_conditions {γ q q' G : ℝ → ℝ} {μ : Measure Time} + (hμ : IsStieltjesMeasure γ μ) + (hGc : ContinuousOn G (Ico (0 : ℝ) 1)) + (hG0 : ∀ t ∈ Ico (0 : ℝ) 1, 0 ≤ G t) + (hremove : ∀ K : Set Time, IsCompact K → ∫ t in K, G t ∂μ ≤ 0) + (hq0 : q 0 = 0) + (hqderiv : ∀ t ∈ Ico (0 : ℝ) 1, HasDerivWithinAt q (q' t) (Ici t) t) + (hGderiv : ∀ t ∈ Ioo (0 : ℝ) 1, HasDerivAt G (t - q t) t) : + ∀ t, InSupport μ t → q t = t ∧ q' t ≤ 1 := by + intro t ht + have ht01 : t ∈ Ico (0 : ℝ) 1 := ht.choose + have hGt : G t = 0 := zero_on_support_of_compact_mass_removal hμ hGc hG0 hremove t ht + have hqt : q t = t := by + rcases eq_or_lt_of_le ht01.1 with ht0 | htpos + · simpa only [← ht0] using hq0 + · exact value_contact_of_potential_min ⟨htpos, ht01.2⟩ hG0 hGt + (hGderiv t ⟨htpos, ht01.2⟩) + exact ⟨hqt, derivative_contact_of_potential_min ht01 hGc hG0 hGt hqt (hqderiv t ht01) + (fun s hs => hGderiv s ⟨ht01.1.trans_lt hs.1, hs.2⟩)⟩ + +noncomputable def contactPotential (q : ℝ → ℝ) (s : ℝ) : ℝ := + ∫ t in s..1, q t - t + +lemma contact_integrable {q : ℝ → ℝ} + (hqc : ContinuousOn q (Ico (0 : ℝ) 1)) + (hqbound : ∀ t ∈ Ico (0 : ℝ) 1, |q t| ≤ 1) : + IntegrableOn (fun t => q t - t) (Icc (0 : ℝ) 1) := by + apply (integrableOn_Icc_iff_integrableOn_Ico).mpr + apply (integrableOn_const (C := (2 : ℝ)) measure_Ico_lt_top.ne).mono' + ((hqc.sub continuousOn_id).aestronglyMeasurable measurableSet_Ico) + filter_upwards [ae_restrict_mem measurableSet_Ico] with t ht + calc + ‖q t - t‖ = |q t - t| := Real.norm_eq_abs _ + _ ≤ |q t| + |t| := abs_sub _ _ + _ ≤ 2 := by rw [abs_of_nonneg ht.1]; linarith [hqbound t ht, ht.2] + +lemma contactPotential_continuousOn {q : ℝ → ℝ} + (hqi : IntegrableOn (fun t => q t - t) (Icc (0 : ℝ) 1)) : + ContinuousOn (contactPotential q) (Icc (0 : ℝ) 1) := by + have hqi' : IntegrableOn (fun t => q t - t) (uIcc (0 : ℝ) 1) := by + simpa only [uIcc_of_le zero_le_one] using hqi + change ContinuousOn (fun s => ∫ t in s..1, q t - t) (Icc (0 : ℝ) 1) + simpa only [uIcc_of_le zero_le_one] using + intervalIntegral.continuousOn_primitive_interval_left hqi' + +lemma contactPotential_hasDerivAt {q : ℝ → ℝ} + (hqi : IntegrableOn (fun t => q t - t) (Icc (0 : ℝ) 1)) + (hqc : ContinuousOn q (Ico (0 : ℝ) 1)) + {s : ℝ} (hs : s ∈ Ioo (0 : ℝ) 1) : + HasDerivAt (contactPotential q) (s - q s) s := by + have hfi : IntervalIntegrable (fun t => q t - t) volume s 1 := by + apply IntegrableOn.intervalIntegrable + rw [uIcc_of_le hs.2.le] + exact hqi.mono_set (by intro t ht; exact ⟨hs.1.le.trans ht.1, ht.2⟩) + have hcont : ContinuousOn (fun t => q t - t) (Ioo (0 : ℝ) 1) := + (hqc.mono Ioo_subset_Ico_self).sub continuousOn_id + have hd := intervalIntegral.integral_hasDerivAt_left hfi + (hcont.stronglyMeasurableAtFilter isOpen_Ioo s hs) + (hcont.continuousAt (Ioo_mem_nhds hs.1 hs.2)) + change HasDerivAt (fun s => ∫ t in s..1, q t - t) (s - q s) s + simpa only [neg_sub] using hd + +end ZeroTemperatureSK.SupportDeterministic.Variation + +namespace ZeroTemperatureSK.SupportDeterministic.Variation + +theorem no_gap_of_derivative_lt_one {q q' : ℝ → ℝ} {a b : ℝ} + (hab : a < b) (hc : ContinuousOn q (Icc a b)) + (hd : ∀ t ∈ Ioo a b, HasDerivAt q (q' t) t) + (ha : q a = a) (hb : q b = b) + (hbound : ∀ t ∈ Ioo a b, q' t < 1) : False := by + obtain ⟨t, ht, heq⟩ := exists_hasDerivAt_eq_slope q q' hab hc hd + rw [ha, hb, div_self (sub_ne_zero.mpr hab.ne')] at heq + exact (hbound t ht).ne heq + +theorem no_gap_of_strictConvex_derivative {q q' : ℝ → ℝ} {a b : ℝ} + (hab : a < b) (hc : ContinuousOn q (Icc a b)) + (hd : ∀ t ∈ Ioo a b, HasDerivAt q (q' t) t) + (ha : q a = a) (hb : q b = b) + (hconvex : StrictConvexOn ℝ (Icc a b) q') + (hda : q' a ≤ 1) (hdb : q' b ≤ 1) : False := by + apply no_gap_of_derivative_lt_one hab hc hd ha hb + intro t ht + exact (hconvex.lt_on_openSegment + (left_mem_Icc.mpr hab.le) (right_mem_Icc.mpr hab.le) + hab.ne (Ioo_subset_openSegment ht)).trans_le (max_le hda hdb) + +theorem no_positive_constant_gap {q q' : ℝ → ℝ} {a b : ℝ} + (hab : a < b) (hc : ContinuousOn q (Icc a b)) + (hc' : ContinuousOn q' (Icc a b)) + (hd : ∀ t ∈ Ioo a b, HasDerivAt q (q' t) t) + (ha : q a = a) (hb : q b = b) + (hcurvature : ∀ t ∈ Ioo a b, 0 < (deriv^[2] q') t) + (hda : q' a ≤ 1) (hdb : q' b ≤ 1) : False := by + apply no_gap_of_strictConvex_derivative hab hc hd ha hb ?_ hda hdb + apply strictConvexOn_of_deriv2_pos (convex_Icc a b) hc' + simpa only [interior_Icc] using hcurvature + +theorem no_zero_constant_gap {q q' : ℝ → ℝ} {a b : ℝ} + (hab : a < b) (hc : ContinuousOn q (Icc a b)) + (hc' : ContinuousOn q' (Icc a b)) + (hd : ∀ t ∈ Ioo a b, HasDerivAt q (q' t) t) + (ha : q a = a) (hb : q b = b) + (hcurvature : ∀ t ∈ Ioo a b, 0 < deriv q' t) + (hdb : q' b ≤ 1) : False := by + have hm : StrictMonoOn q' (Icc a b) := + strictMonoOn_of_deriv_pos (convex_Icc a b) hc' + (by simpa only [interior_Icc] using hcurvature) + apply no_gap_of_derivative_lt_one hab hc hd ha hb + intro t ht + exact (hm (Ioo_subset_Icc_self ht) (right_mem_Icc.mpr hab.le) ht.2).trans_le hdb + +end ZeroTemperatureSK.SupportDeterministic.Variation + +namespace ZeroTemperatureSK.SupportDeterministic.Variation + +theorem full_support_of_contact_and_gap_curvature + {γ q q' : ℝ → ℝ} {μ : Measure Time} + (hγ : IsOrderParameter γ) (hμ : IsStieltjesMeasure γ μ) + (hc : ContinuousOn q (Ico (0 : ℝ) 1)) + (hc' : ContinuousOn q' (Ico (0 : ℝ) 1)) + (hd : ∀ t ∈ Ioo (0 : ℝ) 1, HasDerivAt q (q' t) t) + (hq0 : q 0 = 0) + (hcontact : ∀ t, InSupport μ t → q t = t ∧ q' t ≤ 1) + (hend : ¬ ∃ a c : ℝ, 0 ≤ a ∧ a < 1 ∧ 0 ≤ c ∧ + ∀ t ∈ Ioo a 1, γ t = c) + (hpositive : ∀ a b c : ℝ, 0 ≤ a → a < b → b < 1 → 0 < c → + (∀ t ∈ Ioo a b, γ t = c) → ∀ t ∈ Ioo a b, 0 < (deriv^[2] q') t) + (hzero : ∀ a b : ℝ, 0 ≤ a → a < b → b < 1 → + (∀ t ∈ Ioo a b, γ t = 0) → ∀ t ∈ Ioo a b, 0 < deriv q' t) : + μ.support = univ ∧ StrictMonoOn γ (Ico (0 : ℝ) 1) ∧ + ∀ t ∈ Ico (0 : ℝ) 1, q t = t := by + have hS : μ.support = univ := by + apply Set.eq_univ_of_forall + intro x + by_contra hx + obtain ⟨a, b, ha, hab, hb, haS, hbS, hgap⟩ := + exists_support_gap hx (support_cofinal_of_no_terminal_plateau hγ hμ hend x) + have hsub : Icc a b ⊆ Ico (0 : ℝ) 1 := by + intro t ht; exact ⟨ha.trans ht.1, ht.2.trans_lt hb⟩ + have hderiv : ∀ t ∈ Ioo a b, HasDerivAt q (q' t) t := by + intro t ht; exact hd t ⟨ha.trans_lt ht.1, ht.2.trans hb⟩ + have hqa : q a = a := by + rcases haS with rfl | haS + · exact hq0 + · exact (hcontact a haS).1 + have hqb : q b = b := (hcontact b hbS).1 + have hdb : q' b ≤ 1 := (hcontact b hbS).2 + obtain ⟨c, hc0, hconstant⟩ := constant_on_support_gap hγ hμ ha hab hb hgap + rcases eq_or_lt_of_le hc0 with heq | hpos + · apply no_zero_constant_gap hab (hc.mono hsub) (hc'.mono hsub) hderiv hqa hqb + (hzero a b ha hab hb (by simpa only [← heq] using hconstant)) hdb + · have hda : q' a ≤ 1 := by + by_cases haS' : InSupport μ a + · exact (hcontact a haS').2 + · have ha0 : a = 0 := haS.resolve_right haS' + subst a + have hz := zero_on_initial_support_gap hγ hμ hb haS' hgap + have hmid : b / 2 ∈ Ioo (0 : ℝ) b := by constructor <;> linarith + have heq : c = 0 := (hconstant _ hmid).symm.trans (hz _ hmid) + exact False.elim (hpos.ne' heq) + exact no_positive_constant_gap hab (hc.mono hsub) (hc'.mono hsub) + hderiv hqa hqb (hpositive a b c ha hab hb hpos hconstant) hda hdb + refine ⟨hS, hμ.strictMonoOn_of_full_support hS, ?_⟩ + intro t ht + exact (hcontact t ⟨ht, by rw [hS]; trivial⟩).1 + +theorem derivative_eq_one_of_full_contact {q q' : ℝ → ℝ} + (hq : ∀ t ∈ Ico (0 : ℝ) 1, q t = t) + (hd : ∀ t ∈ Ioo (0 : ℝ) 1, HasDerivAt q (q' t) t) + (hd0 : HasDerivWithinAt q (q' 0) (Ici (0 : ℝ)) 0) : + ∀ t ∈ Ico (0 : ℝ) 1, q' t = 1 := by + intro t ht + rcases eq_or_lt_of_le ht.1 with ht0 | htpos + · subst t + have heq : q =ᶠ[𝓝[Ici (0 : ℝ)] 0] id := by + filter_upwards [self_mem_nhdsWithin, + mem_nhdsWithin_of_mem_nhds (gt_mem_nhds (show (0 : ℝ) < 1 by norm_num))] with x hx hx1 + exact hq x ⟨hx, hx1⟩ + have hid : HasDerivWithinAt q 1 (Ici (0 : ℝ)) 0 := + (hasDerivAt_id (0 : ℝ)).hasDerivWithinAt.congr_of_eventuallyEq heq (hq 0 (by simp)) + exact (hd0.derivWithin (uniqueDiffWithinAt_Ici 0)).symm.trans + (hid.derivWithin (uniqueDiffWithinAt_Ici 0)) + · have heq : q =ᶠ[𝓝 t] id := by + filter_upwards [Ioo_mem_nhds htpos ht.2] with x hx + exact hq x ⟨hx.1.le, hx.2⟩ + have hid : HasDerivAt q 1 t := (hasDerivAt_id t).congr_of_eventuallyEq heq + exact (hd t ⟨htpos, ht.2⟩).unique hid + +end ZeroTemperatureSK.SupportDeterministic.Variation + +end + +end OAI diff --git a/lean/OAI/Probability/SKSupport/Support/ContactPotential.lean b/lean/OAI/Probability/SKSupport/Support/ContactPotential.lean new file mode 100644 index 0000000000000000000000000000000000000000..1e9970adb3cd44622115d252300fb236a66203c9 --- /dev/null +++ b/lean/OAI/Probability/SKSupport/Support/ContactPotential.lean @@ -0,0 +1,215 @@ +import Mathlib +import OAI.Probability.SKSupport.Support.TerminalCurvature +import OAI.Probability.SKSupport.Backward.TerminalTransition +import OAI.Probability.SKSupport.Density.DensityHeat +import OAI.Probability.SKSupport.Diffusion.Diffusion +import OAI.Probability.SKSupport.Support.VariationIntegrals +import OAI.Probability.SKSupport.Support.CDFParameters + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section +namespace ZeroTemperatureSK +variable {Ω : Type*} [MeasurableSpace Ω] + +def contactPotential (W : BrownianSystem Ω) (γ : OrderParameter) (s : ℝ) : ℝ := + ∫ t in s..1, squareMoment W γ (diffusion W γ) t-t + +lemma squareMoment_integrable (W : BrownianSystem Ω) (γ : OrderParameter) : + IntervalIntegrable (squareMoment W γ (diffusion W γ)) volume 0 1 := by + rw [intervalIntegrable_iff_integrableOn_Ico_of_le (by norm_num : (0:ℝ) ≤ 1)] + apply IntegrableOn.of_bound measure_Ico_lt_top ((squareMoment_continuousOn W γ).aestronglyMeasurable measurableSet_Ico) 1 + filter_upwards [ae_restrict_mem measurableSet_Ico] with t ht + simpa only [Real.norm_eq_abs] using (squareMoment_bounds W γ ht.2.le).2 + +lemma contactIntegrand_integrable (W : BrownianSystem Ω) (γ : OrderParameter) : + IntervalIntegrable (fun t => squareMoment W γ (diffusion W γ) t-t) volume 0 1 := + (squareMoment_integrable W γ).sub (continuous_id.intervalIntegrable 0 1) + +lemma contactPotential_continuousOn (W : BrownianSystem Ω) (γ : OrderParameter) : + ContinuousOn (contactPotential W γ) (Icc (0:ℝ) 1) := by + have hi : IntegrableOn (fun t => squareMoment W γ (diffusion W γ) t-t) (uIcc (0:ℝ) 1) := by + rw [uIcc_of_le (by norm_num : (0:ℝ) ≤ 1)] + exact (intervalIntegrable_iff_integrableOn_Icc_of_le (by norm_num : (0:ℝ) ≤ 1)).mp (contactIntegrand_integrable W γ) + unfold contactPotential + simpa only [uIcc_of_le (by norm_num : (0:ℝ) ≤ 1)] using intervalIntegral.continuousOn_primitive_interval_left hi + +lemma contactIntegrand_tail_integrable (W : BrownianSystem Ω) (γ : OrderParameter) {s : ℝ} + (hs : s ∈ Icc (0:ℝ) 1) : + IntervalIntegrable (fun t => squareMoment W γ (diffusion W γ) t-t) volume s 1 := by + apply (contactIntegrand_integrable W γ).mono_set + rw [uIcc_of_le hs.2,uIcc_of_le (by norm_num : (0:ℝ) ≤ 1)] + exact Icc_subset_Icc_left hs.1 + +lemma contactPotential_hasDerivAt (W : BrownianSystem Ω) (γ : OrderParameter) {s : ℝ} + (hs : s ∈ Ioo (0:ℝ) 1) : + HasDerivAt (contactPotential W γ) (s-squareMoment W γ (diffusion W γ) s) s := by + have hc : ContinuousOn (fun t => squareMoment W γ (diffusion W γ) t-t) (Ioo (0:ℝ) 1) := + ((squareMoment_continuousOn W γ).mono Ioo_subset_Ico_self).sub continuousOn_id + have hh := intervalIntegral.integral_hasDerivAt_left (contactIntegrand_tail_integrable W γ ⟨hs.1.le,hs.2.le⟩) + (hc.stronglyMeasurableAtFilter isOpen_Ioo _ hs) (hc.continuousAt (Ioo_mem_nhds hs.1 hs.2)) + unfold contactPotential + simpa only [neg_sub] using hh + +lemma contactPotential_nonneg (W : BrownianSystem Ω) (γ : OrderParameter) (hmin : IsMinimizer W γ) + (s : Time) : 0 ≤ contactPotential W γ s := by + have hn := minimizer_variational_inequality W γ hmin (γ.addCDF (Measure.dirac s)) + simp only [OrderParameter.addCDF_difference] at hn + rw [finiteCDF_fubini (contactIntegrand_integrable W γ),integral_dirac] at hn + exact hn + +lemma contactPotential_remove (W : BrownianSystem Ω) (γ : OrderParameter) (hmin : IsMinimizer W γ) + {μ ν : Measure Time} [IsFiniteMeasure ν] (hμ : IsStieltjesMeasure γ μ) (hν : ν ≤ μ) : + ∫ s : Time, contactPotential W γ s ∂ν ≤ 0 := by + have hn := minimizer_variational_inequality W γ hmin (γ.removeCDF hμ hν) + simp only [OrderParameter.removeCDF_difference,neg_mul,intervalIntegral.integral_neg] at hn + rw [finiteCDF_fubini (contactIntegrand_integrable W γ)] at hn + change 0 ≤ -(∫ s : Time, contactPotential W γ s ∂ν) at hn + linarith + +lemma contactPotential_compact_mass_removal (W : BrownianSystem Ω) (γ : OrderParameter) (hmin : IsMinimizer W γ) + {μ : Measure Time} (hμ : IsStieltjesMeasure γ μ) (K : Set Time) (hK : IsCompact K) : + ∫ s in K, contactPotential W γ s ∂μ ≤ 0 := by + let : IsFiniteMeasureOnCompacts μ := (stieltjes_deterministic γ hμ).finiteOnCompacts + let : IsFiniteMeasure (μ.restrict K) := ⟨by rw [Measure.restrict_apply_univ];exact hK.measure_lt_top⟩ + exact contactPotential_remove W γ hmin hμ Measure.restrict_le_self + +theorem minimizer_contact (W : BrownianSystem Ω) (γ : OrderParameter) (hmin : IsMinimizer W γ) + {μ : Measure Time} (hμ : IsStieltjesMeasure γ μ) : + ∀ t, SupportDeterministic.InSupport μ t → + squareMoment W γ (diffusion W γ) t=t ∧ curvatureMoment W γ t ≤ 1 := by + apply SupportDeterministic.Variation.contact_conditions (stieltjes_deterministic γ hμ) + ((contactPotential_continuousOn W γ).mono Ico_subset_Icc_self) + · exact fun t ht => contactPotential_nonneg W γ hmin ⟨t,ht⟩ + · exact contactPotential_compact_mass_removal W γ hmin hμ + · exact squareMoment_zero W γ + · intro t ht + exact (squareMoment_hasDerivWithinAt W γ ht.1 ht.2).mono (Ici_subset_Ici.mpr ht.1) + · intro t ht + exact contactPotential_hasDerivAt W γ ht + +end ZeroTemperatureSK + +end +end +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section +namespace ZeroTemperatureSK +open Heat WeakIto +variable {Ω : Type*} [MeasurableSpace Ω] + +lemma gradientDefect_nonneg (W : BrownianSystem Ω) (γ : OrderParameter) {t : ℝ} (ht : t ≤ 1) (x : ℝ) : + 0 ≤ 1-(gradient W γ t x)^2 := by + have hh := abs_le.mp (gradient_abs_le_one W γ t x ht) + nlinarith + +lemma terminal_plateau_denominator (W : BrownianSystem Ω) (γ : OrderParameter) + {a c : ℝ} (hc0 : 0 ≤ c) (hc : ∀ r ∈ Ioo a 1, extend γ.val r=c) + (s T : Time) (has : a < (s:ℝ)) (hsT : s ≤ T) {x : ℝ} (hx : |x| ≤ 1) : + varianceHeat ((T:ℝ)-s) (fun y => Real.exp (c*value W γ T y)) x ≤ + Real.exp (c*(value W γ s 0+1)) := by + rw [varianceHeat_exp_eq_exp_log (value_lipschitz W γ T T.property.2.le), + ← value_plateau_semigroup W γ hc0 s.property.1 has hsT T.property.2 hc] + apply Real.exp_le_exp.mpr + apply mul_le_mul_of_nonneg_left _ hc0 + have hh := (value_lipschitz W γ s s.property.2.le).norm_sub_le x 0 + simp only [Real.norm_eq_abs,NNReal.coe_one,one_mul,sub_zero] at hh + linarith [le_abs_self (value W γ s x-value W γ s 0)] + +lemma terminal_plateau_second_moment_defect (W : BrownianSystem Ω) (γ : OrderParameter) + {a c : ℝ} (ha : a < 1) (hc0 : 0 ≤ c) (hc : ∀ r ∈ Ioo a 1, extend γ.val r=c) + (s : Time) (hs0 : 0 < (s:ℝ)) (has : a < (s:ℝ)) : + ∃ C : ℝ, 0 < C ∧ ∀ T : Time, ((s:ℝ)+1)/2 ≤ T → + 8*kernelConstant*c*Real.sqrt (1-(T:ℝ)) ≤ 1/2 → + C*Real.sqrt (1-(T:ℝ)) ≤ 1-squareMoment W γ (diffusion W γ) T := by + let := W.isProbability + let δ : ℝ := (1-(s:ℝ))/2 + have hδ : 0 < δ := by dsimp [δ];linarith [s.property.2] + let M : ℝ := Real.exp (c*(value W γ s 0+1)) + have hM : 0 < M := Real.exp_pos _ + let E : Set Ω := {ξ | diffusion W γ (⟨s,s.property.1⟩:ℝ≥0) ξ ∈ Ioo (-1:ℝ) 1} + have hmX : Measurable (diffusion W γ (⟨s,s.property.1⟩:ℝ≥0)) := + ((diffusion_progressive W γ).adapted _).mono (Filtration.le _ _) le_rfl + have hE : MeasurableSet E := hmX measurableSet_Ioo + have hEpos : 0 < W.law.real E := by + apply ENNReal.toReal_pos + · exact ne_of_gt (diffusion_interval_pos W γ s hs0 (show (-1:ℝ) < 1 by norm_num)) + · exact measure_ne_top _ _ + let K : ℝ := ((3/2:ℝ)*(Real.sqrt (2*Real.pi))⁻¹*Real.exp (-2/δ))/(M*(4*kernelConstant+2)) + have hκ := kernelConstant_nonneg + have hK : 0 < K := by dsimp [K];positivity + refine ⟨W.law.real E*K,mul_pos hEpos hK,fun T hsT hsmall => ?_⟩ + have hst : s ≤ T := by change (s:ℝ) ≤ T;linarith [s.property.2] + let r : ℝ := Real.sqrt (1-(T:ℝ))/(4*kernelConstant+2) + have hr0 : 0 ≤ r := by dsimp [r];positivity + have hr1 : r ≤ 1 := by + apply (div_le_iff₀ (by positivity : 0 < 4*kernelConstant+2)).mpr + have hr := Real.sqrt_le_one.mpr (show 1-(T:ℝ) ≤ 1 by linarith [T.property.1]) + linarith + let g : ℝ → ℝ := fun y => 1-(gradient W γ T y)^2 + have hg := gradientDefect_smooth W γ T.property.1 T.property.2 + have hf := value_regular W γ T.property.1 T.property.2 + have hLip := value_lipschitz W γ T T.property.2.le + have hg0 : ∀ y, 0 ≤ g y := gradientDefect_nonneg W γ T.property.2.le + have hgwin : ∀ y, |y| ≤ r → 3/4 ≤ g y := by + intro y hy + have hu := abs_le.mp (gradient_terminal_small W γ hc0 + (parameter_bound_of_terminal_plateau γ ha hc) T.property.1 T.property.2 hsmall hy) + dsimp [g] + nlinarith + let F : Ω → ℝ := fun ξ => varianceTilted c ((T:ℝ)-s) (value W γ T) g + (diffusion W γ (⟨s,s.property.1⟩:ℝ≥0) ξ) + have hfi : Integrable F W.law := integrable_family_comp (varianceTilted_family hf hLip hg hc0) _ hmX + have hF0 : ∀ ξ, 0 ≤ F ξ := by + intro ξ + dsimp [F] + rw [varianceTilted_eq_tiltedMean hLip.continuous.measurable hg.smooth.continuous.measurable] + exact tiltedMean_nonneg hLip hg0 c _ _ + have hlower : ∀ ξ ∈ E, K*Real.sqrt (1-(T:ℝ)) ≤ F ξ := by + intro ξ hξ + have hx : |diffusion W γ (⟨s,s.property.1⟩:ℝ≥0) ξ| ≤ 1 := abs_le.mpr ⟨hξ.1.le,hξ.2.le⟩ + have hh := varianceTilted_lower_window hLip hg hc0 + (fun y => (abs_nonneg y).trans (abs_le_value W γ T y T.property.2.le)) hg0 hδ + (show δ ≤ (T:ℝ)-s by dsimp [δ];linarith) + (show (T:ℝ)-s ≤ 1 by linarith [T.property.2,s.property.1]) hr0 hr1 hx hgwin + (terminal_plateau_denominator W γ hc0 hc s T has hst hx) + have he : ((3/2:ℝ)*(Real.sqrt (2*Real.pi))⁻¹*Real.exp (-2/δ)*r)/M=K*Real.sqrt (1-(T:ℝ)) := by + dsimp [r,K] + rw [mul_div_assoc,div_div, mul_comm (4*kernelConstant+2) M] + ring + rw [he] at hh + exact hh + have hint := setIntegral_mono_on (f := fun _ => K*Real.sqrt (1-(T:ℝ))) + (integrable_const _).integrableOn hfi.integrableOn hE hlower + rw [setIntegral_const,smul_eq_mul] at hint + have hb := hint.trans (setIntegral_le_integral hfi (Eventually.of_forall hF0)) + have htrans := terminal_plateau_transition W γ hc0 hc s T has hst hg + have hiq : Integrable (fun ξ => (gradient W γ T (diffusion W γ (⟨T,T.property.1⟩:ℝ≥0) ξ))^2) W.law := by + have hmT : Measurable (diffusion W γ (⟨T,T.property.1⟩:ℝ≥0)) := + ((diffusion_progressive W γ).adapted _).mono (Filtration.le _ _) le_rfl + have hu := hf.deriv_bounded + have hsq : BoundedSmooth (fun y => (gradient W γ T y)^2) := by simpa only [gradient,pow_two] using hu.mul hu + obtain ⟨G,hG⟩ := hsq.bound + exact Integrable.of_bound (hsq.smooth.continuous.measurable.comp hmT).aestronglyMeasurable G (Eventually.of_forall (fun ξ => hG _)) + have he : (∫ ξ, g (diffusion W γ (⟨T,T.property.1⟩:ℝ≥0) ξ) ∂W.law)=1-squareMoment W γ (diffusion W γ) T := by + dsimp [g] + rw [integral_sub (integrable_const _) hiq,integral_const] + simp only [measureReal_def,measure_univ,ENNReal.toReal_one,one_smul,squareMoment] + congr 2 + funext ξ + congr 3 + exact (Real.toNNReal_coe (r := (⟨T,T.property.1⟩:ℝ≥0))).symm + rw [← htrans,he] at hb + simpa only [mul_assoc] using hb + +end ZeroTemperatureSK + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKSupport/Support/FiniteCDF.lean b/lean/OAI/Probability/SKSupport/Support/FiniteCDF.lean new file mode 100644 index 0000000000000000000000000000000000000000..032041129d8927002fb6f29b6d956f683b835ad7 --- /dev/null +++ b/lean/OAI/Probability/SKSupport/Support/FiniteCDF.lean @@ -0,0 +1,72 @@ +import Mathlib +import OAI.Probability.SKSupport.Model + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section +namespace ZeroTemperatureSK + +def finiteCDF (ν : Measure Time) (t : Time) : ℝ := (ν (Iic t)).toReal + +lemma finiteCDF_nonneg (ν : Measure Time) (t : Time) : 0 ≤ finiteCDF ν t := ENNReal.toReal_nonneg + +lemma finiteCDF_monotone (ν : Measure Time) [IsFiniteMeasure ν] : Monotone (finiteCDF ν) := by + intro a b hab + exact ENNReal.toReal_mono (measure_ne_top ν _) (measure_mono (Iic_subset_Iic.mpr hab)) + +lemma finiteCDF_bound (ν : Measure Time) [IsFiniteMeasure ν] (t : Time) : finiteCDF ν t ≤ (ν univ).toReal := + ENNReal.toReal_mono (measure_ne_top ν _) (measure_mono (subset_univ _)) + +lemma finiteCDF_integral (ν : Measure Time) (t : Time) : + finiteCDF ν t=∫ r : Time, (if r ≤ t then (1:ℝ) else 0) ∂ν := by + have he : (fun r : Time => if r ≤ t then (1:ℝ) else 0)=(Iic t).indicator (fun _ => (1:ℝ)) := by + funext r + simp only [Set.indicator_apply,mem_Iic] + rw [he,integral_indicator measurableSet_Iic] + simp only [finiteCDF,integral_const,measureReal_def,smul_eq_mul,mul_one,Measure.restrict_apply_univ] + +lemma finiteCDF_rightContinuous (ν : Measure Time) [IsFiniteMeasure ν] (t : Time) : + ContinuousWithinAt (finiteCDF ν) (Ici t) t := by + change Tendsto (fun u => finiteCDF ν u) (𝓝[Ici t] t) (𝓝 (finiteCDF ν t)) + simp only [finiteCDF_integral] + apply tendsto_integral_filter_of_dominated_convergence (fun _ : Time => (1:ℝ)) + · exact Eventually.of_forall (fun u => (measurable_const.piecewise measurableSet_Iic measurable_const).aestronglyMeasurable) + · exact Eventually.of_forall (fun u => Eventually.of_forall (fun r => by split_ifs <;> norm_num)) + · exact integrable_const _ + · filter_upwards [] with r + by_cases hrt : r ≤ t + · simp only [ite_eq_left hrt] + apply tendsto_const_nhds.congr' + filter_upwards [self_mem_nhdsWithin] with u hu + simp only [ite_eq_left (hrt.trans hu)] + · have htr : t < r := lt_of_not_ge hrt + simp only [ite_eq_right hrt] + apply tendsto_const_nhds.congr' + filter_upwards [mem_nhdsWithin_of_mem_nhds (gt_mem_nhds htr)] with u hu + rw [ite_eq_right (not_le_of_gt hu)] + +lemma integrable_extend_of_bounded {f : Time → ℝ} (hf : Measurable f) {C : ℝ} + (hC : ∀ t, |f t| ≤ C) : Integrable (extend f) := by + have hm : Measurable (extend f) := hf.dite measurable_const measurableSet_Ico + have hi : Integrable ((Ico (0:ℝ) 1).indicator (fun _ => C)) := + (integrableOn_const (C := C) measure_Ico_lt_top.ne).integrable_indicator measurableSet_Ico + apply hi.mono' hm.aestronglyMeasurable + filter_upwards [] with t + by_cases ht : t ∈ Ico (0:ℝ) 1 + · simp only [extend,dite_eq_left ht,Real.norm_eq_abs,indicator_of_mem ht] + exact hC _ + · simp only [extend,dite_eq_right ht,Real.norm_eq_abs,abs_zero,indicator_of_notMem ht,le_refl] + +lemma finiteCDF_integrable (ν : Measure Time) [IsFiniteMeasure ν] : Integrable (extend (finiteCDF ν)) := + integrable_extend_of_bounded (finiteCDF_monotone ν).measurable + (fun t => by rw [abs_of_nonneg (finiteCDF_nonneg ν t)];exact finiteCDF_bound ν t) + +end ZeroTemperatureSK + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKSupport/Support/GapCurvature.lean b/lean/OAI/Probability/SKSupport/Support/GapCurvature.lean new file mode 100644 index 0000000000000000000000000000000000000000..915c9a8072254119fc6dfa4762ee2d5e152cf23a --- /dev/null +++ b/lean/OAI/Probability/SKSupport/Support/GapCurvature.lean @@ -0,0 +1,126 @@ +import Mathlib +import OAI.Probability.SKSupport.Moments.Curvature + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section +namespace ZeroTemperatureSK +open Heat WeakIto +variable {Ω : Type*} [MeasurableSpace Ω] + +lemma OrderParameter.continuousAt_of_constant {γ : OrderParameter} {a b c : ℝ} + (hc : ∀ s ∈ Ioo a b, extend γ.val s=c) (t : Time) (ht : (t:ℝ) ∈ Ioo a b) : + ContinuousAt γ.val t := by + have hh : γ.val =ᶠ[𝓝 t] fun _ => c := by + filter_upwards [(continuous_subtype_val.tendsto t).eventually (Ioo_mem_nhds ht.1 ht.2)] with s hs + have he := hc s hs + simpa only [extend,dite_eq_left s.property] using he + exact continuousAt_const.congr_of_eventuallyEq hh + +lemma compactCoeff_constant (γ : OrderParameter) (T : Time) {a b c : ℝ} + (ha : 0 ≤ a) (hb : b ≤ T) (hc : ∀ s ∈ Ioo a b, extend γ.val s=c) : + ∀ s ∈ Ioo a b, compactCoeff γ T s=c := by + intro s hs + rw [compactCoeff,stripClamp_eq ⟨ha.trans hs.1.le,hs.2.le.trans hb⟩] + exact hc s hs + +lemma curvatureMoment_hasDerivAt_on_constant (W : BrownianSystem Ω) (γ : OrderParameter) (T : Time) + {a b c t : ℝ} (ha : 0 ≤ a) (hbT : b ≤ T) (ht : t ∈ Ioo a b) + (hc : ∀ s ∈ Ioo a b, extend γ.val s=c) : + HasDerivAt (curvatureMoment W γ) (stripSecond W γ T c t) t := by + have hd := stripA_hasDerivAt_on_constant W γ T ha hbT ht (compactCoeff_constant γ T ha hbT hc) + apply hd.congr_of_eventuallyEq + filter_upwards [Ioo_mem_nhds (ha.trans_lt ht.1) (ht.2.trans_le hbT)] with s hs + exact (stripA_eq_curvatureMoment W γ T ⟨hs.1.le,hs.2.le⟩).symm + +lemma curvatureMoment_deriv_hasDerivAt_on_constant (W : BrownianSystem Ω) (γ : OrderParameter) (T : Time) + {a b c t : ℝ} (ha : 0 ≤ a) (hbT : b ≤ T) (ht : t ∈ Ioo a b) + (hc : ∀ s ∈ Ioo a b, extend γ.val s=c) : + HasDerivAt (deriv (curvatureMoment W γ)) (stripThird W γ T c t) t := by + have hd := stripSecond_hasDerivAt_on_constant W γ T ha hbT ht (compactCoeff_constant γ T ha hbT hc) + apply hd.congr_of_eventuallyEq + filter_upwards [Ioo_mem_nhds ht.1 ht.2] with s hs + exact (curvatureMoment_hasDerivAt_on_constant W γ T ha hbT hs hc).deriv + +theorem positive_gap_curvature (W : BrownianSystem Ω) (γ : OrderParameter) + {a b c : ℝ} (ha : 0 ≤ a) (hab : a < b) (hb : b < 1) (hc0 : 0 < c) + (hc : ∀ s ∈ Ioo a b, extend γ.val s=c) : + ∀ t ∈ Ioo a b, 0 < (deriv^[2] (curvatureMoment W γ)) t := by + intro t ht + let T : Time := ⟨b,⟨ha.trans hab.le,hb⟩⟩ + have htt : t ∈ Ico (0:ℝ) 1 := ⟨ha.trans ht.1.le,ht.2.trans hb⟩ + let τ : Time := ⟨t,htt⟩ + have he : γ.val τ=c := by simpa only [extend,dite_eq_left htt] using hc t ht + change 0 < deriv (deriv (curvatureMoment W γ)) t + rw [(curvatureMoment_deriv_hasDerivAt_on_constant W γ T ha le_rfl ht hc).deriv] + have hp := stripThird_pos W γ T τ (ha.trans_lt ht.1) ht.2.le + (γ.continuousAt_of_constant hc τ ht) (by rw [he];exact hc0) + simpa only [he] using hp + +theorem zero_gap_curvature (W : BrownianSystem Ω) (γ : OrderParameter) + {a b : ℝ} (ha : 0 ≤ a) (hab : a < b) (hb : b < 1) + (hc : ∀ s ∈ Ioo a b, extend γ.val s=0) : + ∀ t ∈ Ioo a b, 0 < deriv (curvatureMoment W γ) t := by + intro t ht + let T : Time := ⟨b,⟨ha.trans hab.le,hb⟩⟩ + let τ : Time := ⟨t,⟨ha.trans ht.1.le,ht.2.trans hb⟩⟩ + rw [(curvatureMoment_hasDerivAt_on_constant W γ T ha le_rfl ht hc).deriv] + exact stripSecond_zero_pos W γ T τ (ha.trans_lt ht.1) ht.2.le + +end ZeroTemperatureSK + +end +end +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section +namespace ZeroTemperatureSK + +instance timeCompactIccSpace : CompactIccSpace Time where + isCompact_Icc {a} {b} := by + rw [Subtype.isCompact_iff] + have he : Subtype.val '' Icc a b=Icc (a:ℝ) (b:ℝ) := by + ext t + constructor + · rintro ⟨u,hu,rfl⟩ + exact hu + · intro ht + exact ⟨⟨t,⟨a.property.1.trans ht.1,ht.2.trans_lt b.property.2⟩⟩,ht,rfl⟩ + rw [he] + exact isCompact_Icc + +def parameterStieltjes (γ : OrderParameter) : StieltjesFunction Time where + toFun := γ.val + mono' := γ.monotone + right_continuous' := γ.right_continuous + +lemma parameterStieltjes_atBot (γ : OrderParameter) : + Tendsto (parameterStieltjes γ) atBot (𝓝 (γ.val ⊥)) := by + apply tendsto_const_nhds.congr' + filter_upwards [eventually_le_atBot (⊥ : Time)] with t ht + have he : t=⊥ := le_antisymm ht bot_le + subst t + rfl + +def parameterMeasure (γ : OrderParameter) : Measure Time := + (parameterStieltjes γ).measure + ENNReal.ofReal (γ.val ⊥) • Measure.dirac ⊥ + +lemma parameterMeasure_isStieltjes (γ : OrderParameter) : IsStieltjesMeasure γ (parameterMeasure γ) := by + intro t + rw [parameterMeasure,Measure.add_apply,(parameterStieltjes γ).measure_Iic (parameterStieltjes_atBot γ), + Measure.smul_apply,Measure.dirac_apply' _ measurableSet_Iic] + have hbot : (⊥ : Time) ∈ Iic t := by change (⊥ : Time) ≤ t; exact bot_le + simp only [Set.indicator_of_mem hbot,Pi.one_apply,smul_eq_mul,mul_one] + change ENNReal.ofReal (γ.val t-γ.val ⊥)+ENNReal.ofReal (γ.val ⊥)=ENNReal.ofReal (γ.val t) + rw [← ENNReal.ofReal_add (sub_nonneg.mpr (γ.monotone bot_le)) (γ.nonneg ⊥),sub_add_cancel] + +end ZeroTemperatureSK + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKSupport/Support/NoTerminalPlateau.lean b/lean/OAI/Probability/SKSupport/Support/NoTerminalPlateau.lean new file mode 100644 index 0000000000000000000000000000000000000000..671e979d13665ad0eafbe44ed0b73b5e5c7e4819 --- /dev/null +++ b/lean/OAI/Probability/SKSupport/Support/NoTerminalPlateau.lean @@ -0,0 +1,148 @@ +import Mathlib +import OAI.Probability.SKSupport.Regularity.ClosedTime +import OAI.Probability.SKSupport.Support.ContactPotential + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section +namespace ZeroTemperatureSK +open Heat +variable {Ω : Type*} [MeasurableSpace Ω] + +lemma terminal_plateau_q_lt_near_one (W : BrownianSystem Ω) (γ : OrderParameter) + {a c : ℝ} (ha0 : 0 ≤ a) (ha1 : a < 1) (hc0 : 0 ≤ c) + (hc : ∀ r ∈ Ioo a 1, extend γ.val r=c) : + ∃ b : ℝ, 0 ≤ b ∧ b < 1 ∧ ∀ t ∈ Ioo b 1, squareMoment W γ (diffusion W γ) t < t := by + let s₀ : ℝ := (a+1)/2 + have hs0 : 0 < s₀ := by dsimp [s₀];linarith + have hs1 : s₀ < 1 := by dsimp [s₀];linarith + have has : a < s₀ := by dsimp [s₀];linarith + let s : Time := ⟨s₀,⟨hs0.le,hs1⟩⟩ + obtain ⟨C,hC,hbound⟩ := terminal_plateau_second_moment_defect W γ ha1 hc0 hc s hs0 has + have hl : Tendsto (fun t : ℝ => Real.sqrt (1-t)) (𝓝 1) (𝓝 0) := by + have hcroot : Continuous (fun t : ℝ => Real.sqrt (1-t)) := by fun_prop + simpa only [sub_self,Real.sqrt_zero] using hcroot.tendsto (1:ℝ) + have hm : Tendsto (fun t : ℝ => 8*kernelConstant*c*Real.sqrt (1-t)) (𝓝 1) (𝓝 0) := by + simpa only [mul_zero] using tendsto_const_nhds.mul hl (a := 8*kernelConstant*c) + have hev : ∀ᶠ t in 𝓝 (1:ℝ), ((s:ℝ)+1)/2 ≤ t ∧ + 8*kernelConstant*c*Real.sqrt (1-t) ≤ 1/2 ∧ Real.sqrt (1-t) < C := by + filter_upwards [lt_mem_nhds (show ((s:ℝ)+1)/2 < 1 by change (s₀+1)/2 < 1;linarith), + hm.eventually_lt_const (show (0:ℝ) < 1/2 by norm_num),hl.eventually_lt_const hC] with t ht ht' ht'' + exact ⟨ht.le,ht'.le,ht''⟩ + obtain ⟨ε,hε,hball⟩ := Metric.mem_nhds_iff.mp hev + let b : ℝ := max 0 (1-ε/2) + have hb0 : 0 ≤ b := le_max_left _ _ + have hb1 : b < 1 := max_lt (by norm_num) (by linarith) + refine ⟨b,hb0,hb1,fun t ht => ?_⟩ + have hεt : t ∈ Metric.ball (1:ℝ) ε := by + rw [Metric.mem_ball,Real.dist_eq,abs_of_neg (sub_neg.mpr ht.2)] + dsimp [b] at ht + linarith [ht.1,le_max_right (0:ℝ) (1-ε/2)] + obtain ⟨hm0,hm1,hm2⟩ := hball hεt + have ht0 := hb0.trans ht.1.le + have hbq := hbound ⟨t,⟨ht0,ht.2⟩⟩ hm0 hm1 + have hroot := Real.sqrt_pos.mpr (sub_pos.mpr ht.2) + have hsqr := Real.sq_sqrt (sub_nonneg.mpr ht.2.le) + have hmul := mul_lt_mul_of_pos_right hm2 hroot + change C*Real.sqrt (1-t) ≤ 1-squareMoment W γ (diffusion W γ) t at hbq + nlinarith + +theorem minimizer_no_terminal_plateau (W : BrownianSystem Ω) (γ : OrderParameter) (hmin : IsMinimizer W γ) : + ¬ ∃ a c : ℝ, 0 ≤ a ∧ a < 1 ∧ 0 ≤ c ∧ ∀ t ∈ Ioo a 1, extend γ.val t=c := by + rintro ⟨a,c,ha0,ha1,hc0,hc⟩ + obtain ⟨b,hb0,hb1,hneg⟩ := terminal_plateau_q_lt_near_one W γ ha0 ha1 hc0 hc + have hi := (contactIntegrand_tail_integrable W γ ⟨hb0,hb1.le⟩).neg + have hip : IntegrableOn (fun t => t-squareMoment W γ (diffusion W γ) t) (Ioo b 1) := by + have hh := (intervalIntegrable_iff_integrableOn_Ioo_of_le hb1.le).mp hi + change IntegrableOn (fun t => -(squareMoment W γ (diffusion W γ) t-t)) (Ioo b 1) at hh + simpa only [neg_sub] using hh + have hn : 0 ≤ᵐ[volume.restrict (Ioo b 1)] (fun t => t-squareMoment W γ (diffusion W γ) t) := by + filter_upwards [ae_restrict_mem measurableSet_Ioo] with t ht + exact sub_nonneg.mpr (hneg t ht).le + have hsupp : Ioo b 1 ⊆ Function.support (fun t => t-squareMoment W γ (diffusion W γ) t) := by + intro t ht + exact ne_of_gt (sub_pos.mpr (hneg t ht)) + have hμpos : 0 < (volume.restrict (Ioo b 1)) (Ioo b 1) := by + rw [Measure.restrict_apply measurableSet_Ioo,inter_self,Real.volume_Ioo] + exact ENNReal.ofReal_pos.mpr (sub_pos.mpr hb1) + have hp := (integral_pos_iff_support_of_nonneg_ae hn hip).mpr (hμpos.trans_le (measure_mono hsupp)) + have he : (∫ t in Ioo b 1, t-squareMoment W γ (diffusion W γ) t)=-contactPotential W γ b := by + unfold contactPotential + rw [← intervalIntegral.integral_neg] + simp only [neg_sub] + rw [intervalIntegral.integral_of_le hb1.le,integral_Ioc_eq_integral_Ioo] + rw [he] at hp + linarith [contactPotential_nonneg W γ hmin ⟨b,⟨hb0,hb1⟩⟩] + +end ZeroTemperatureSK + +end +end +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section + +namespace ZeroTemperatureSK + +def spinHamiltonian (n : ℕ) (J : (Fin n × Fin n) → ℝ) (σ : Fin n → Bool) : ℝ := + (∑ i : Fin n, ∑ j : Fin n, if i < j then + J (i,j) * (if σ i then 1 else -1) * (if σ j then 1 else -1) else 0) / Real.sqrt n + +def spinDisorder (n : ℕ) : Measure ((Fin n × Fin n) → ℝ) := + Measure.pi (fun _ => gaussianReal 0 1) + +def expectedSKMaximum (n : ℕ) : ℝ := + (∫ J, sSup (Set.range (spinHamiltonian n J)) ∂spinDisorder n) / n + +def groundStateValue : ℝ := limUnder atTop expectedSKMaximum + +variable {Ω : Type*} [MeasurableSpace Ω] + +def TerminalValueConclusion (W : BrownianSystem Ω) (γ : OrderParameter) + (X : ℝ≥0 → Ω → ℝ) : Prop := + Tendsto expectedSKMaximum atTop (𝓝 groundStateValue) ∧ + ∃ U₁ : Ω → ℝ, + Martingale (terminalGradient W γ X U₁) (closedFiltration W) W.law ∧ + (∀ᵐ ω ∂W.law, |U₁ ω| ≤ 1 ∧ (U₁ ω)^2 = 1) ∧ + MemLp U₁ 2 W.law ∧ + (∀ᵐ ω ∂W.law, + Tendsto (fun t : ℝ => gradient W γ t (X (Real.toNNReal t) ω)) + (𝓝[<] (1 : ℝ)) (𝓝 (U₁ ω))) ∧ + Tendsto (fun t : ℝ => eLpNorm + (fun ω => gradient W γ t (X (Real.toNNReal t) ω) - U₁ ω) 2 W.law) + (𝓝[<] (1 : ℝ)) (𝓝 0) ∧ + Integrable (fun ω => |X 1 ω|) W.law ∧ + Integrable (fun ω => U₁ ω * W.B 1 ω) W.law ∧ + IntervalIntegrable (fun t : ℝ => t * extend γ.val t) volume 0 1 ∧ + IntervalIntegrable (fun t : ℝ => ∫ ω, curvature W γ t + (X (Real.toNNReal t) ω) ∂W.law) volume 0 1 ∧ + groundStateValue = parisi W γ ∧ + groundStateValue = (∫ ω, |X 1 ω| ∂W.law) - + ∫ t in (0 : ℝ)..1, t * extend γ.val t ∧ + groundStateValue = (∫ ω, U₁ ω * W.B 1 ω ∂W.law) ∧ + groundStateValue = (∫ t in (0 : ℝ)..1, + ∫ ω, curvature W γ t (X (Real.toNNReal t) ω) ∂W.law) + +def GaussianConclusion (W : BrownianSystem Ω) (γ : OrderParameter) + (X : ℝ≥0 → Ω → ℝ) (T : ℝ) : Prop := + (∃ N₀ : ℕ, ∀ N ≥ N₀, 1 ≤ N → ∀ j ∈ Finset.Icc 1 N, + Integrable (fun z => (curvature W γ (meshTime T N (j-1)) + (eulerState W γ T N (j-1) z))^2) (gaussianLaw N) ∧ + 0 < eulerCurvatureMoment W γ T N j ∧ 0 < eulerNormalizer W γ T N j) ∧ + Tendsto (gaussianValueSum W γ T) atTop + (𝓝 (∫ t in (0 : ℝ)..T, + ∫ ω, curvature W γ t (X (Real.toNNReal t) ω) ∂W.law)) ∧ + Tendsto (fun T : ℝ => ∫ t in (0 : ℝ)..T, + ∫ ω, curvature W γ t (X (Real.toNNReal t) ω) ∂W.law) + (𝓝[<] (1 : ℝ)) (𝓝 groundStateValue) + +end ZeroTemperatureSK + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKSupport/Support/TerminalCurvature.lean b/lean/OAI/Probability/SKSupport/Support/TerminalCurvature.lean new file mode 100644 index 0000000000000000000000000000000000000000..08a35e2d04acc03d1e052777fda12d134d667946 --- /dev/null +++ b/lean/OAI/Probability/SKSupport/Support/TerminalCurvature.lean @@ -0,0 +1,107 @@ +import Mathlib +import OAI.Probability.SKSupport.Regularity.Regularity + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology ContDiff +noncomputable section +namespace ZeroTemperatureSK +open Heat +variable {Ω : Type*} [MeasurableSpace Ω] + +lemma parameter_bound_of_terminal_plateau (γ : OrderParameter) {a c : ℝ} (ha : a < 1) + (hc : ∀ t ∈ Ioo a 1, extend γ.val t=c) : ∀ t : Time, γ.val t ≤ c := by + intro t + let s : ℝ := (max (t:ℝ) a+1)/2 + have hm : max (t:ℝ) a < 1 := max_lt t.property.2 ha + have hts : (t:ℝ) ≤ s := by dsimp [s];linarith [le_max_left (t:ℝ) a] + have has : a < s := by dsimp [s];linarith [le_max_right (t:ℝ) a] + have hs1 : s < 1 := by dsimp [s];linarith + have hs : s ∈ Ico (0:ℝ) 1 := ⟨t.property.1.trans hts,hs1⟩ + have hh := hc s ⟨has,hs1⟩ + rw [extend,dite_eq_left hs] at hh + exact (γ.monotone (a := t) (b := ⟨s,hs⟩) hts).trans_eq hh + +lemma finite_terminal_curvature_bound {f : ℝ → ℝ} (hf : RegularDatum f) (hLip : LipschitzWith 1 f) + (c : ℕ → ℝ≥0) (h : ℝ≥0) (N i : ℕ) {D t b : ℝ} + (ht0 : 0 ≤ t) (htb : t < b) (hb : b ≤ (N:ℝ)*h) (hD : 0 ≤ D) + (hc : ∀ r ∈ Icc t b, finiteCoeff c h N i r ≤ D) + (hsmall : 8*kernelConstant*D*Real.sqrt (b-t) ≤ 1/2) (x : ℝ) : + |deriv (deriv (finiteValue c h f N i t)) x| ≤ 2*kernelConstant/Real.sqrt (b-t) := by + let V := fun r => deriv (finiteValue c h f N i r) + let G := finiteBurgersSource c h f N i + have hV := finiteGradient_family hf hLip c h N i + have hG := finiteBurgersSource_family hf hLip c h N i + obtain ⟨A₀,hA₀⟩ := hG.bound + obtain ⟨B₀,hB₀⟩ := hG.deriv.bound + obtain ⟨C₀,hC₀⟩ := hV.deriv.bound + have hu (r x : ℝ) : |V r x| ≤ 1 := by + simpa only [V,Real.norm_eq_abs,NNReal.coe_one] using + norm_deriv_le_of_lipschitz (x₀ := x) (finiteValue_lipschitz hLip c h N i r) + have hsource (r : ℝ) (hr : r ∈ Icc t b) (z : ℝ) : |G r z| ≤ D*|deriv (V r) z|+0 := by + have hh := iteratedDeriv_finiteBurgersSource_bound hf hLip c h N i 0 + (by norm_num : (0:ℝ) ≤ 1) hD (hc r hr) (fun j hj y => by + have hj0 : j=0 := Nat.eq_zero_of_le_zero hj + subst j + exact hu r y) z + simpa only [G,V,iteratedDeriv_zero,iteratedDeriv_one,Finset.range_zero,Finset.sum_empty,mul_zero,zero_mul] using hh + have hh := uniform_gradient_bound_of_mild htb (by norm_num : (0:ℝ) ≤ 1) hD (by norm_num : (0:ℝ) ≤ 0) + (hV.regular b) hG.measurable hG.regular hA₀ hB₀ (fun r _ z => hC₀ r z) (hu b) hsource + (fun r hr z => finiteGradient_mild hf hLip c h N i (ht0.trans hr.1) hr.2.le hb z) hsmall x + simpa only [V,mul_zero,zero_mul,add_zero,mul_one] using hh + +lemma approxGamma_global_cap (γ : OrderParameter) {D : ℝ} (hcap : ∀ t : Time, γ.val t ≤ D) + (n : ℕ) {s : ℝ} (hs : s ∈ Icc (0:ℝ) 1) : approxGamma γ n s ≤ D := by + obtain ⟨j,hj,he,_,_⟩ := finiteCoeff_sample (approxCoeff γ n) (approxMesh_pos n) (n+1) 0 hs.1 + (by rw [approxMesh_horizon];exact hs.2) (by omega) + change finiteCoeff (approxCoeff γ n) (approxMesh n) (n+1) 0 s ≤ D + rw [he] + simpa only [Nat.zero_add,approxCoeff_eq γ n j hj] using hcap ⟨(j:ℝ)*approxMesh n,sample_mem n j hj⟩ + +lemma curvature_terminal_bound (W : BrownianSystem Ω) (γ : OrderParameter) {D t : ℝ} + (hD : 0 ≤ D) (hcap : ∀ s : Time, γ.val s ≤ D) (ht0 : 0 ≤ t) (ht1 : t < 1) + (hsmall : 8*kernelConstant*D*Real.sqrt (1-t) ≤ 1/2) (x : ℝ) : + |curvature W γ t x| ≤ 2*kernelConstant/Real.sqrt (1-t) := by + have hl := (approxValue_derivative_uniform_spatial W γ ht0 ht1 2).tendsto_at x |>.abs + have hb (n : ℕ) : |iteratedDeriv 2 (approxValue γ n t) x| ≤ 2*kernelConstant/Real.sqrt (1-t) := by + have hh := finite_terminal_curvature_bound (regularDatum_softAbs (M := ((n+1:ℕ):ℝ)) (by positivity)) (softAbs_lipschitz (M := ((n+1:ℕ):ℝ)) (by positivity)) + (approxCoeff γ n) (approxMesh n) (n+1) 0 ht0 ht1 (by rw [approxMesh_horizon]) hD + (fun r hr => approxGamma_global_cap γ hcap n ⟨ht0.trans hr.1,hr.2⟩) hsmall x + simpa only [approxValue,iteratedDeriv_succ,iteratedDeriv_zero] using hh + have hh := le_of_tendsto hl (Eventually.of_forall hb) + unfold curvature gradient + simpa only [iteratedDeriv_succ,iteratedDeriv_zero] using hh + +lemma gradient_terminal_small (W : BrownianSystem Ω) (γ : OrderParameter) {D t y : ℝ} + (hD : 0 ≤ D) (hcap : ∀ s : Time, γ.val s ≤ D) (ht0 : 0 ≤ t) (ht1 : t < 1) + (hsmall : 8*kernelConstant*D*Real.sqrt (1-t) ≤ 1/2) + (hy : |y| ≤ Real.sqrt (1-t)/(4*kernelConstant+2)) : + |gradient W γ t y| ≤ 1/2 := by + have hκ := kernelConstant_nonneg + have hden : 0 < 4*kernelConstant+2 := by positivity + have hroot := Real.sqrt_pos.mpr (sub_pos.mpr ht1) + have hd : Differentiable ℝ (gradient W γ t) := by + unfold gradient + simpa only [iteratedDeriv_one] using (value_contDiff W γ ht0 ht1).differentiable_iteratedDeriv 1 (by simp) + have hL := (lipschitzWith_of_nnnorm_deriv_le hd (C := Real.toNNReal (2*kernelConstant/Real.sqrt (1-t))) (fun x => by + apply NNReal.coe_le_coe.mp + rw [Real.coe_toNNReal _ (by positivity)] + exact curvature_terminal_bound W γ hD hcap ht0 ht1 hsmall x)) + have hh := hL.norm_sub_le y 0 + rw [gradient_zero W γ ht0 ht1,sub_zero,Real.norm_eq_abs,sub_zero,Real.norm_eq_abs, + Real.coe_toNNReal _ (by positivity)] at hh + apply hh.trans + calc + (2*kernelConstant/Real.sqrt (1-t))*|y| ≤ (2*kernelConstant/Real.sqrt (1-t))*(Real.sqrt (1-t)/(4*kernelConstant+2)) := + mul_le_mul_of_nonneg_left hy (by positivity) + _ = 2*kernelConstant/(4*kernelConstant+2) := by field_simp + _ ≤ 1/2 := by apply (div_le_iff₀ hden).mpr;linarith + +end ZeroTemperatureSK + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKSupport/Support/VariationIntegrals.lean b/lean/OAI/Probability/SKSupport/Support/VariationIntegrals.lean new file mode 100644 index 0000000000000000000000000000000000000000..4bf9eba5e21a91d92939946efd78f41b5ed95782 --- /dev/null +++ b/lean/OAI/Probability/SKSupport/Support/VariationIntegrals.lean @@ -0,0 +1,182 @@ +import Mathlib +import OAI.Probability.SKSupport.Moments.PerturbationLimits + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section +namespace ZeroTemperatureSK +variable {Ω : Type*} [MeasurableSpace Ω] + +def normalizedValueDifference (W : BrownianSystem Ω) (γ β : OrderParameter) (n : ℕ) : ℝ := + (value W (perturbation γ β n) 0 0-value W γ 0 0)/variationStep n + +def variationTail (γ β : OrderParameter) (T : ℝ) : ℝ := + ∫ s in T..1, |extend β.val s-extend γ.val s| + +lemma variationTail_nonneg (γ β : OrderParameter) {T : ℝ} (hT : T ≤ 1) : 0 ≤ variationTail γ β T := + intervalIntegral.integral_nonneg hT (fun _ _ => abs_nonneg _) + +lemma variationTail_limit (γ β : OrderParameter) : + Tendsto (fun n => variationTail γ β (diffusionHorizon n)) atTop (𝓝 0) := by + let f := fun s => |extend β.val s-extend γ.val s| + have hi : Integrable f := (β.integrable.sub γ.integrable).abs + have he (n : ℕ) : variationTail γ β (diffusionHorizon n)= + (∫ s in (0:ℝ)..1, f s)-(∫ s in (0:ℝ)..diffusionHorizon n, f s) := by + have hh := intervalIntegral.integral_add_adjacent_intervals (hi.intervalIntegrable (a := 0) (b := diffusionHorizon n)) + (hi.intervalIntegrable (a := diffusionHorizon n) (b := 1)) + change _ + variationTail γ β (diffusionHorizon n)=_ at hh + linarith + have hc := (hi.continuous_primitive 0).tendsto (1:ℝ) |>.comp diffusionHorizon_tendsto + simpa only [he,sub_self,Function.comp_apply] using tendsto_const_nhds.sub hc (a := ∫ s in (0:ℝ)..1, f s) + +lemma mixedQ_weighted_limit (W : BrownianSystem Ω) (γ β : OrderParameter) (T : Time) : + Tendsto (fun n => ∫ s in (0:ℝ)..(T:ℝ), (extend β.val s-extend γ.val s)*mixedQ W (perturbation γ β n) γ T s) + atTop (𝓝 (∫ s in (0:ℝ)..(T:ℝ), (extend β.val s-extend γ.val s)*squareMoment W γ (diffusion W γ) s)) := by + simp only [intervalIntegral.integral_of_le T.property.1] + apply tendsto_integral_of_dominated_convergence (fun s => |extend β.val s-extend γ.val s|) + · intro n + exact ((β.measurable_extend.sub γ.measurable_extend).mul (mixedQ_continuous W (perturbation γ β n) γ T).measurable).aestronglyMeasurable + · exact (β.integrable.sub γ.integrable).abs.integrableOn + · intro n + filter_upwards [] with s + rw [Real.norm_eq_abs,abs_mul,abs_of_nonneg (mixedQ_bounds W (perturbation γ β n) γ T s).1] + exact mul_le_of_le_one_right (abs_nonneg _) (mixedQ_bounds W (perturbation γ β n) γ T s).2 + · filter_upwards [ae_restrict_mem measurableSet_Ioc] with s hs + exact (mixedQ_perturbation_limit W γ β T ⟨hs.1.le,hs.2⟩).const_mul _ + +lemma normalizedValueDifference_truncation (W : BrownianSystem Ω) (γ β : OrderParameter) (T : Time) (n : ℕ) : + |normalizedValueDifference W γ β n-(1/2:ℝ)*(∫ s in (0:ℝ)..(T:ℝ), + (extend β.val s-extend γ.val s)*mixedQ W (perturbation γ β n) γ T s)| ≤ (3/2:ℝ)*variationTail γ β T := by + let R := (differenceField W (perturbation γ β n) γ T.property.1 T.property.2).expected + (mixedStripDrift W (perturbation γ β n) γ T) W T + let I := ∫ s in (0:ℝ)..(T:ℝ), (extend β.val s-extend γ.val s)*mixedQ W (perturbation γ β n) γ T s + have he := mixed_difference_integral W (perturbation γ β n) γ T + simp only [perturbation_diff,mul_assoc,intervalIntegral.integral_const_mul] at he + change value W (perturbation γ β n) 0 0-value W γ 0 0=R+(1/2:ℝ)*(variationStep n*I) at he + have hb := mixed_difference_terminal_bound W (perturbation γ β n) γ T + simp only [perturbation_diff,abs_mul,abs_of_nonneg (variationStep_pos n).le,intervalIntegral.integral_const_mul] at hb + change |R| ≤ (3/2:ℝ)*(variationStep n*variationTail γ β T) at hb + change |normalizedValueDifference W γ β n-(1/2:ℝ)*I| ≤ _ + have hid : normalizedValueDifference W γ β n-(1/2:ℝ)*I=R/variationStep n := by + unfold normalizedValueDifference + rw [he] + field_simp [(variationStep_pos n).ne'] + ring + rw [hid,abs_div,abs_of_pos (variationStep_pos n)] + apply (div_le_iff₀ (variationStep_pos n)).mpr + nlinarith only [hb] + +lemma weighted_square_tail_bound (W : BrownianSystem Ω) (γ β : OrderParameter) (T : Time) : + |∫ s in (T:ℝ)..1, (extend β.val s-extend γ.val s)*squareMoment W γ (diffusion W γ) s| ≤ variationTail γ β T := by + rw [← Real.norm_eq_abs] + apply intervalIntegral.norm_integral_le_of_norm_le T.property.2.le _ ((β.integrable.sub γ.integrable).abs.intervalIntegrable) + filter_upwards [] with s hs + rw [Real.norm_eq_abs,abs_mul] + exact mul_le_of_le_one_right (abs_nonneg _) (squareMoment_bounds W γ hs.2).2 + +end ZeroTemperatureSK + +end +end +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section +namespace ZeroTemperatureSK +variable {Ω : Type*} [MeasurableSpace Ω] + +lemma normalizedValueDifference_limit (W : BrownianSystem Ω) (γ β : OrderParameter) : + Tendsto (normalizedValueDifference W γ β) atTop + (𝓝 ((1/2:ℝ)*(∫ s in (0:ℝ)..1, (extend β.val s-extend γ.val s)*squareMoment W γ (diffusion W γ) s))) := by + rw [Metric.tendsto_nhds] + intro ε hε + obtain ⟨k,hk⟩ := ((variationTail_limit γ β).eventually (gt_mem_nhds (by linarith : (0:ℝ)<ε/8))).exists + let T := diffusionHorizonTime k + have htail : variationTail γ β T < ε/8 := hk + let I (n : ℕ) := (1/2:ℝ)*(∫ s in (0:ℝ)..(T:ℝ), (extend β.val s-extend γ.val s)*mixedQ W (perturbation γ β n) γ T s) + let J := (1/2:ℝ)*(∫ s in (0:ℝ)..(T:ℝ), (extend β.val s-extend γ.val s)*squareMoment W γ (diffusion W γ) s) + let K := (1/2:ℝ)*(∫ s in (T:ℝ)..1, (extend β.val s-extend γ.val s)*squareMoment W γ (diffusion W γ) s) + let L := (1/2:ℝ)*(∫ s in (0:ℝ)..1, (extend β.val s-extend γ.val s)*squareMoment W γ (diffusion W γ) s) + have hIL : Tendsto I atTop (𝓝 J) := (mixedQ_weighted_limit W γ β T).const_mul (1/2:ℝ) + have hi := squareMoment_weighted_integrable W γ (β.integrable.sub γ.integrable) + have hi0 : IntervalIntegrable (fun s => (extend β.val s-extend γ.val s)*squareMoment W γ (diffusion W γ) s) volume 0 T := + hi.mono_set (by rw [uIcc_of_le T.property.1,uIcc_of_le (by norm_num : (0:ℝ)≤1)];exact Icc_subset_Icc le_rfl T.property.2.le) + have hi1 : IntervalIntegrable (fun s => (extend β.val s-extend γ.val s)*squareMoment W γ (diffusion W γ) s) volume T 1 := + hi.mono_set (by rw [uIcc_of_le T.property.2.le,uIcc_of_le (by norm_num : (0:ℝ)≤1)];exact Icc_subset_Icc T.property.1 le_rfl) + have hL : L=J+K := by + have hh := intervalIntegral.integral_add_adjacent_intervals hi0 hi1 + dsimp only [L,J,K] + rw [← hh,mul_add] + have hK : |K| ≤ (1/2:ℝ)*variationTail γ β T := by + dsimp only [K] + rw [abs_mul,abs_of_nonneg (by norm_num : (0:ℝ) ≤ 1/2)] + exact mul_le_mul_of_nonneg_left (weighted_square_tail_bound W γ β T) (by norm_num) + filter_upwards [(Metric.tendsto_nhds.mp hIL) (ε/2) (by linarith)] with n hn + change |normalizedValueDifference W γ β n-L| < ε + have h1 := normalizedValueDifference_truncation W γ β T n + change |normalizedValueDifference W γ β n-I n| ≤ (3/2:ℝ)*variationTail γ β T at h1 + rw [Real.dist_eq] at hn + have hh := abs_sub_le (normalizedValueDifference W γ β n) (I n) L + have hh' := abs_sub_le (I n) J L + have hJL : |J-L|=|K| := by rw [hL];ring_nf;rw [abs_neg] + rw [hJL] at hh' + linarith + +lemma penalty_integrable (γ : OrderParameter) : + IntervalIntegrable (fun s : ℝ => s*extend γ.val s) volume 0 1 := by + have hh := γ.integrable.intervalIntegrable (a := (0:ℝ)) (b := 1) |>.mul_continuousOn continuousOn_id + simpa only [id_eq,mul_comm] using hh + +lemma penalty_difference (γ β : OrderParameter) (n : ℕ) : + (∫ s in (0:ℝ)..1, s*extend (perturbation γ β n).val s)-(∫ s in (0:ℝ)..1, s*extend γ.val s)= + variationStep n*(∫ s in (0:ℝ)..1, s*(extend β.val s-extend γ.val s)) := by + rw [← intervalIntegral.integral_sub (penalty_integrable _) (penalty_integrable _),← intervalIntegral.integral_const_mul] + apply intervalIntegral.integral_congr + intro s _ + change s*extend (perturbation γ β n).val s-s*extend γ.val s=variationStep n*(s*(extend β.val s-extend γ.val s)) + rw [← mul_sub,perturbation_diff] + ring + +lemma normalizedParisiDifference_eq (W : BrownianSystem Ω) (γ β : OrderParameter) (n : ℕ) : + (parisi W (perturbation γ β n)-parisi W γ)/variationStep n= + normalizedValueDifference W γ β n-(1/2:ℝ)*(∫ s in (0:ℝ)..1, s*(extend β.val s-extend γ.val s)) := by + have he := penalty_difference γ β n + have hn := (variationStep_pos n).ne' + unfold parisi normalizedValueDifference + field_simp [hn] + nlinarith only [he] + +theorem parisi_chord_derivative (W : BrownianSystem Ω) (γ β : OrderParameter) : + Tendsto (fun n => (parisi W (perturbation γ β n)-parisi W γ)/variationStep n) atTop + (𝓝 ((1/2:ℝ)*(∫ s in (0:ℝ)..1, (extend β.val s-extend γ.val s)*(squareMoment W γ (diffusion W γ) s-s)))) := by + have hiq := squareMoment_weighted_integrable W γ (β.integrable.sub γ.integrable) + have hit : IntervalIntegrable (fun s => (extend β.val s-extend γ.val s)*s) volume 0 1 := + (β.integrable.sub γ.integrable).intervalIntegrable.mul_continuousOn continuousOn_id + change IntervalIntegrable (fun s => (extend β.val s-extend γ.val s)*squareMoment W γ (diffusion W γ) s) volume 0 1 at hiq + have he : (1/2:ℝ)*(∫ s in (0:ℝ)..1, (extend β.val s-extend γ.val s)*squareMoment W γ (diffusion W γ) s)- + (1/2:ℝ)*(∫ s in (0:ℝ)..1, s*(extend β.val s-extend γ.val s))= + (1/2:ℝ)*(∫ s in (0:ℝ)..1, (extend β.val s-extend γ.val s)*(squareMoment W γ (diffusion W γ) s-s)) := by + rw [← mul_sub,← intervalIntegral.integral_sub hiq (by simpa only [id_eq,mul_comm] using hit)] + congr 1 + apply intervalIntegral.integral_congr + intro s _ + ring + simpa only [normalizedParisiDifference_eq,he] using + (normalizedValueDifference_limit W γ β).sub_const ((1/2:ℝ)*(∫ s in (0:ℝ)..1, s*(extend β.val s-extend γ.val s))) + +theorem minimizer_variational_inequality (W : BrownianSystem Ω) (γ : OrderParameter) + (hmin : IsMinimizer W γ) (β : OrderParameter) : + 0 ≤ ∫ s in (0:ℝ)..1, (extend β.val s-extend γ.val s)*(squareMoment W γ (diffusion W γ) s-s) := by + have hz := ge_of_tendsto (parisi_chord_derivative W γ β) (Eventually.of_forall (fun n => + div_nonneg (sub_nonneg.mpr (hmin (perturbation γ β n))) (variationStep_pos n).le)) + linarith + +end ZeroTemperatureSK + +end +end + +end OAI diff --git a/lean/OAI/Probability/SKValue/Coercivity/Coercivity.lean b/lean/OAI/Probability/SKValue/Coercivity/Coercivity.lean new file mode 100644 index 0000000000000000000000000000000000000000..8d6c14b2f84169150d136bedbbb0a29d463d7de1 --- /dev/null +++ b/lean/OAI/Probability/SKValue/Coercivity/Coercivity.lean @@ -0,0 +1,135 @@ +import Mathlib +import OAI.Probability.SKValue.Gaussian.DensityJump + +namespace OAI + +section + +namespace SKValue.Certificate +noncomputable def Q (R K v b : ℝ) : ℝ := + (1/13)*v*b+(53/24)*v^2+(19/16)*K*v-2*(19/16)*R*b+(73/48)*R*v +noncomputable def T (R v j : ℝ) : ℝ := (2331/10000)*R*v+(87/2500)*j*v +noncomputable def F₂ (R K v b j : ℝ) : ℝ := + (4663/5000)*v^2*j+(6853/10000)*v^3-(1051/400)*K*v^2-(1073/500)*R*v^2- + (b^2*(2*R*(19/16)-(1/13)*v)+ + b*(-2*K*(19/16)*v-R*(2331/10000)*v-2*R*(73/48)*v-2*(53/24)*v^2-(87/2500)*j*v)) +noncomputable def W₂ (R K v b j z L : ℝ) : ℝ := + (2*R*v)*(-(1073/500)*v^2-2*(19/16)*b^2+b*((2331/10000)*v+2*(73/48)*v))+ + (2*v*K+R*j)*(-(1051/400)*v^2+2*(19/16)*b*v)+ + (-R*b)*(2*(4663/5000)*v*j+3*(6853/10000)*v^2-2*(1051/400)*K*v- + 2*(1073/500)*R*v+(1/13)*b^2+ + b*(2*K*(19/16)+R*(2331/10000)+2*R*(73/48)+4*(53/24)*v+(87/2500)*j))+ + (-z-b*v)*(-2*b*(2*R*(19/16)-(1/13)*v)+2*K*(19/16)*v+ + R*(2331/10000)*v+2*R*(73/48)*v+2*(53/24)*v^2+(87/2500)*j*v)+ + (-j*v+K*b-L)*((4663/5000)*v^2+(87/2500)*b*v)+(v+R-K)*F₂ R K v b j +noncomputable def remainder (R K v B j : ℝ) : ℝ := + (223/160000)*R^2*v^2+(4007/240000)*R^2*v*B+(1097/120000)*R^2*B^2+ + (83/80000)*R*K*v^2+(3343/24000)*R*K*v*B+(16259/23400000)*R*v^3+ + (30179/5460000)*R*v^2*B+(26/625)*R*v^2*j+(107/15000)*R*v*B^2+ + (3/2500)*R*v*B*j+(121/32500)*R*B^3+(11/10000)*R*B^2*j+ + (579/20000)*K^2*v^2+(207/2500)*K^2*v*B+(911/975000)*K*v^3+ + (349/420000)*K*v^2*B+(5011/5000)*K*v^2*j+(133/130000)*K*v*B^2+ + (87/2500)*K*v*B*j+(1661507/1521000000)*v^4+ + (633799/621075000)*v^3*B+(10657/1690000)*v^2*B^2 + +theorem rational_identity (R K v B j z L : ℝ) : + let b:=B+2*v + z^2-12*R*v*b^2+6*v^4= + (z+Q R K v b)^2+(z+b*v-2*R*b)*T R v j+ + (337/10000)*(R*j*(b-7*v)^2)+ + (183/2500)*(R*B*(b-(7/3)*v)^2)+ + (411/10000)*(K*v*(b-(9/2)*v)^2)+ + (11461/5000)*(v*B*(K+(1/4)*R-(1/7)*v)^2)+ + (647/10000)*(v*b-(14/5)*v^2-(13/4)*K*v+(4/3)*R*v)^2+ + W₂ R K v b j z L+L*((4663/5000)*v^2+(87/2500)*b*v)+remainder R K v B j := by + dsimp only [Q,T,W₂,F₂,remainder] + ring + +theorem pointwise_coercivity {R K v B j z L : ℝ} + (hR : 0≤R) (hK : 0≤K) (hv : 0≤v) (hB : 0≤B) (hj : 0≤j) (hL : 0≤L) + (hS : 0≤z+(B+2*v)*v-2*R*(B+2*v)) : + (1661507/1521000000)*v^4+W₂ R K v (B+2*v) j z L≤ + z^2-12*R*v*(B+2*v)^2+6*v^4 := by + have he := rational_identity R K v B j z L + dsimp only at he + have hrem : (1661507/1521000000)*v^4≤remainder R K v B j := by + unfold remainder + have hrest : 0≤ + (223/160000)*R^2*v^2+(4007/240000)*R^2*v*B+(1097/120000)*R^2*B^2+ + (83/80000)*R*K*v^2+(3343/24000)*R*K*v*B+(16259/23400000)*R*v^3+ + (30179/5460000)*R*v^2*B+(26/625)*R*v^2*j+(107/15000)*R*v*B^2+ + (3/2500)*R*v*B*j+(121/32500)*R*B^3+(11/10000)*R*B^2*j+ + (579/20000)*K^2*v^2+(207/2500)*K^2*v*B+(911/975000)*K*v^3+ + (349/420000)*K*v^2*B+(5011/5000)*K*v^2*j+(133/130000)*K*v*B^2+ + (87/2500)*K*v*B*j+ + (633799/621075000)*v^3*B+(10657/1690000)*v^2*B^2 := by positivity + linarith + have hT : 0≤T R v j := by unfold T; positivity + have hST := mul_nonneg hS hT + have h0 : 0≤(337/10000 : ℝ)*(R*j*(B+2*v-7*v)^2) := by positivity + have h1 : 0≤(183/2500 : ℝ)*(R*B*(B+2*v-(7/3)*v)^2) := by positivity + have h2 : 0≤(411/10000 : ℝ)*(K*v*(B+2*v-(9/2)*v)^2) := by positivity + have h3 : 0≤(11461/5000 : ℝ)*(v*B*(K+(1/4)*R-(1/7)*v)^2) := by positivity + have h4 : 0≤(647/10000 : ℝ)*(v*(B+2*v)-(14/5)*v^2-(13/4)*K*v+(4/3)*R*v)^2 := by positivity + have hLC : 0≤L*((4663/5000)*v^2+(87/2500)*(B+2*v)*v) := by positivity + have hs := sq_nonneg (z+Q R K v (B+2*v)) + linarith only [he,hrem,hST,h0,h1,h2,h3,h4,hLC,hs] +end SKValue.Certificate + +end + +section +namespace SKValue.Certificate +lemma growth_F {R K v b j:ℝ → ℝ} (hR:ExpGrowth R) (hK:ExpGrowth K) + (hv:ExpGrowth v) (hb:ExpGrowth b) (hj:ExpGrowth j) : + ExpGrowth (fun x ↦ F₂ (R x) (K x) (v x) (b x) (j x)) := by + have h := (((((((ExpGrowth.const (4663/5000:ℝ)).mul (hv.pow 2)).mul hj).add ((ExpGrowth.const (6853/10000:ℝ)).mul (hv.pow 3))).sub (((ExpGrowth.const (1051/400:ℝ)).mul hK).mul (hv.pow 2))).sub (((ExpGrowth.const (1073/500:ℝ)).mul hR).mul (hv.pow 2))).sub (((hb.pow 2).mul ((((ExpGrowth.const (2/1:ℝ)).mul hR).mul (ExpGrowth.const (19/16:ℝ))).sub ((ExpGrowth.const (1/13:ℝ)).mul hv))).add (hb.mul ((((((((ExpGrowth.const (-2/1:ℝ)).mul hK).mul (ExpGrowth.const (19/16:ℝ))).mul hv).sub ((hR.mul (ExpGrowth.const (2331/10000:ℝ))).mul hv)).sub ((((ExpGrowth.const (2/1:ℝ)).mul hR).mul (ExpGrowth.const (73/48:ℝ))).mul hv)).sub ((ExpGrowth.const (53/12:ℝ)).mul (hv.pow 2))).sub (((ExpGrowth.const (87/2500:ℝ)).mul hj).mul hv))))) + convert! h using 1 + funext x + dsimp [F₂] + ring +lemma growth_W {R K v b j z L:ℝ → ℝ} (hR:ExpGrowth R) (hK:ExpGrowth K) + (hv:ExpGrowth v) (hb:ExpGrowth b) (hj:ExpGrowth j) (hz:ExpGrowth z) (hL:ExpGrowth L) : + ExpGrowth (fun x ↦ W₂ (R x) (K x) (v x) (b x) (j x) (z x) (L x)) := by + have hF:=growth_F hR hK hv hb hj + have h := (((((((((ExpGrowth.const (2/1:ℝ)).mul hR).mul hv).mul ((((ExpGrowth.const (-1073/500:ℝ)).mul (hv.pow 2)).sub ((ExpGrowth.const (19/8:ℝ)).mul (hb.pow 2))).add (hb.mul (((ExpGrowth.const (2331/10000:ℝ)).mul hv).add ((ExpGrowth.const (73/24:ℝ)).mul hv))))).add (((((ExpGrowth.const (2/1:ℝ)).mul hv).mul hK).add (hR.mul hj)).mul (((ExpGrowth.const (-1051/400:ℝ)).mul (hv.pow 2)).add (((ExpGrowth.const (19/8:ℝ)).mul hb).mul hv)))).add (((hR.neg).mul hb).mul ((((((((ExpGrowth.const (4663/2500:ℝ)).mul hv).mul hj).add ((ExpGrowth.const (20559/10000:ℝ)).mul (hv.pow 2))).sub (((ExpGrowth.const (1051/200:ℝ)).mul hK).mul hv)).sub (((ExpGrowth.const (1073/250:ℝ)).mul hR).mul hv)).add ((ExpGrowth.const (1/13:ℝ)).mul (hb.pow 2))).add (hb.mul (((((((ExpGrowth.const (2/1:ℝ)).mul hK).mul (ExpGrowth.const (19/16:ℝ))).add (hR.mul (ExpGrowth.const (2331/10000:ℝ)))).add (((ExpGrowth.const (2/1:ℝ)).mul hR).mul (ExpGrowth.const (73/48:ℝ)))).add ((ExpGrowth.const (53/6:ℝ)).mul hv)).add ((ExpGrowth.const (87/2500:ℝ)).mul hj)))))).add (((hz.neg).sub (hb.mul hv)).mul ((((((((ExpGrowth.const (-2/1:ℝ)).mul hb).mul ((((ExpGrowth.const (2/1:ℝ)).mul hR).mul (ExpGrowth.const (19/16:ℝ))).sub ((ExpGrowth.const (1/13:ℝ)).mul hv))).add ((((ExpGrowth.const (2/1:ℝ)).mul hK).mul (ExpGrowth.const (19/16:ℝ))).mul hv)).add ((hR.mul (ExpGrowth.const (2331/10000:ℝ))).mul hv)).add ((((ExpGrowth.const (2/1:ℝ)).mul hR).mul (ExpGrowth.const (73/48:ℝ))).mul hv)).add ((ExpGrowth.const (53/12:ℝ)).mul (hv.pow 2))).add (((ExpGrowth.const (87/2500:ℝ)).mul hj).mul hv)))).add (((((hj.neg).mul hv).add (hK.mul hb)).sub hL).mul (((ExpGrowth.const (4663/5000:ℝ)).mul (hv.pow 2)).add (((ExpGrowth.const (87/2500:ℝ)).mul hb).mul hv)))).add (((hv.add hR).sub hK).mul hF)) + convert! h using 1 + funext x + dsimp [W₂] + ring +end SKValue.Certificate + +end + +section +open MeasureTheory Set Filter +open scoped Topology +namespace SKValue.Certificate + +lemma flux_derivative {r v w z s a d f:ℝ → ℝ} {x:ℝ} + (hr:HasDerivAt r (v x) x) (hv:HasDerivAt v (w x) x) + (hw:HasDerivAt w (z x) x) (hs:HasDerivAt s (a x) x) + (ha:HasDerivAt a (d x) x) (hf:HasDerivAt f ((r x-s x)*f x) x) + (hn:r x≠0) : + HasDerivAt (fun y ↦ r y*F₂ (r y^2) (r y*s y) (v y) (-w y/r y) + (a y-s y/r y*v y)*f y) + (W₂ (r x^2) (r x*s x) (v x) (-w x/r x) (a x-s x/r x*v x) + (z x) (-r x*d x)*f x) x := by + have hR := hr.pow 2 + have hK := hr.mul hs + have hb := hw.neg.div hr hn + have hj := ha.sub ((hs.div hr hn).mul hv) + have hF := (((((((hasDerivAt_const x (4663/5000:ℝ)).mul (hv.pow 2)).mul hj).add ((hasDerivAt_const x (6853/10000:ℝ)).mul (hv.pow 3))).sub (((hasDerivAt_const x (1051/400:ℝ)).mul hK).mul (hv.pow 2))).sub (((hasDerivAt_const x (1073/500:ℝ)).mul hR).mul (hv.pow 2))).sub (((hb.pow 2).mul ((((hasDerivAt_const x (2/1:ℝ)).mul hR).mul (hasDerivAt_const x (19/16:ℝ))).sub ((hasDerivAt_const x (1/13:ℝ)).mul hv))).add (hb.mul ((((((((hasDerivAt_const x (-2/1:ℝ)).mul hK).mul (hasDerivAt_const x (19/16:ℝ))).mul hv).sub ((hR.mul (hasDerivAt_const x (2331/10000:ℝ))).mul hv)).sub ((((hasDerivAt_const x (2/1:ℝ)).mul hR).mul (hasDerivAt_const x (73/48:ℝ))).mul hv)).sub ((hasDerivAt_const x (53/12:ℝ)).mul (hv.pow 2))).sub (((hasDerivAt_const x (87/2500:ℝ)).mul hj).mul hv))))) + have hflux := (hr.mul hF).mul hf + convert! hflux using 1 + · funext y + dsimp [F₂] + ring + · dsimp [W₂,F₂] + field_simp + ring +end SKValue.Certificate + +end + +end OAI diff --git a/lean/OAI/Probability/SKValue/Coercivity/CurvatureMoment.lean b/lean/OAI/Probability/SKValue/Coercivity/CurvatureMoment.lean new file mode 100644 index 0000000000000000000000000000000000000000..ba6c2a13b5f3507ec2d24405d4e6285a57937981 --- /dev/null +++ b/lean/OAI/Probability/SKValue/Coercivity/CurvatureMoment.lean @@ -0,0 +1,133 @@ +import Mathlib +import OAI.Probability.SKValue.Variation.OrderVariations +import OAI.Probability.SKValue.Equations.PolynomialMoment +import OAI.Probability.SKValue.Processes.CurvatureNonneg + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped Topology NNReal +namespace SKValue +lemma IsDiffusion.polyJet_integrable {W:BrownianSpace} {γ:OrderParameter} {X:ℝ → W.Ω → ℝ} + (hX:IsDiffusion W γ X) {t:ℝ} (ht:t∈Ico (0:ℝ) 1) (e:JetExpr): + Integrable (fun z ↦ polyJet (phi W γ) e t (X t z)) W.μ := by + have hj:=(phi_evolution W γ ht).polyJet_joint e + obtain ⟨C,hC,hb⟩:=hj.bounded + apply Integrable.of_bound + · exact ((hj.slice ⟨ht.1,le_rfl⟩).measurable.comp (hX.measurable ⟨ht.1,ht.2.le⟩)).aestronglyMeasurable + · exact Eventually.of_forall (fun z ↦ by simpa only [Real.norm_eq_abs] using hb t ⟨ht.1,le_rfl⟩ (X t z)) +lemma IsDiffusion.jetMoment_hasDerivAt_integral {W:BrownianSpace} {γ:OrderParameter} {X:ℝ → W.Ω → ℝ} + (hX:IsDiffusion W γ X) {t:ℝ} (ht:t∈Ioo (0:ℝ) 1) (hc:ContinuousAt γ.coeff t) (e:JetExpr): + HasDerivAt (jetMoment W γ X e) (∫ z,polyJet (phi W γ) e.sourceA t (X t z)+ + γ.coeff t*polyJet (phi W γ) e.sourceP t (X t z) ∂W.μ) t := by + rw [integral_add (hX.polyJet_integrable ⟨ht.1.le,ht.2⟩ _) ((hX.polyJet_integrable ⟨ht.1.le,ht.2⟩ _).const_mul _),integral_const_mul] + exact hX.jetMoment_hasDerivAt ht hc e +lemma IsDiffusion.momentExpr_hasDerivAt {W:BrownianSpace} {γ:OrderParameter} {X:ℝ → W.Ω → ℝ} + (hX:IsDiffusion W γ X) {t:ℝ} (ht:t∈Ioo (0:ℝ) 1) (hc:ContinuousAt γ.coeff t): + HasDerivAt (jetMoment W γ X JetExpr.momentExpr) (jetMoment W γ X JetExpr.curvatureExpr t) t := by + have hd:=hX.jetMoment_hasDerivAt_integral ht hc JetExpr.momentExpr + simpa only [polyJet,JetExpr.momentExpr_sourceA,JetExpr.momentExpr_sourceP,mul_zero,add_zero,jetMoment] using hd +lemma IsDiffusion.curvatureExpr_hasDerivAt {W:BrownianSpace} {γ:OrderParameter} {X:ℝ → W.Ω → ℝ} + (hX:IsDiffusion W γ X) {t c:ℝ} (ht:t∈Ioo (0:ℝ) 1) (hc:ContinuousAt γ.coeff t) (he:γ.coeff t=c): + HasDerivAt (jetMoment W γ X JetExpr.curvatureExpr) (jetMoment W γ X (JetExpr.curvatureSlope c) t) t := by + have hd:=hX.jetMoment_hasDerivAt_integral ht hc JetExpr.curvatureExpr + convert hd using 1 + unfold jetMoment + apply integral_congr_ae + refine Eventually.of_forall (fun z ↦ ?_) + simp only [polyJet,JetExpr.curvatureSlope_eval,JetExpr.curvatureExpr_sourceA,JetExpr.curvatureExpr_sourceP,he] + ring +lemma IsDiffusion.curvatureSlope_hasDerivAt {W:BrownianSpace} {γ:OrderParameter} {X:ℝ → W.Ω → ℝ} + (hX:IsDiffusion W γ X) {t c:ℝ} (ht:t∈Ioo (0:ℝ) 1) (hc:ContinuousAt γ.coeff t) (he:γ.coeff t=c): + HasDerivAt (jetMoment W γ X (JetExpr.curvatureSlope c)) + (∫ z,(iteratedDeriv 3 (deriv (phi W γ t)) (X t z))^2- + 12*γ.coeff t*iteratedDeriv 1 (deriv (phi W γ t)) (X t z)*(iteratedDeriv 2 (deriv (phi W γ t)) (X t z))^2+ + 6*(γ.coeff t)^2*(iteratedDeriv 1 (deriv (phi W γ t)) (X t z))^4 ∂W.μ) t := by + have hd:=hX.jetMoment_hasDerivAt_integral ht hc (JetExpr.curvatureSlope c) + convert hd using 1 + apply integral_congr_ae + refine Eventually.of_forall (fun z ↦ ?_) + simp only [polyJet,JetExpr.curvatureSlope_sourceA,JetExpr.curvatureSlope_sourceP,he] + ring +end SKValue + +end + +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped Topology NNReal +namespace SKValue +lemma continuousAt_of_constant_interval {f:ℝ → ℝ} {a b c t:ℝ} + (ht:t∈Ioo a b) (he:∀s∈Ioo a b,f s=c):ContinuousAt f t := by + apply continuousAt_const.congr_of_eventuallyEq + filter_upwards [Ioo_mem_nhds ht.1 ht.2] with s hs + exact he s hs +lemma IsDiffusion.jetMoment_continuousAt {W:BrownianSpace} {γ:OrderParameter} {X:ℝ → W.Ω → ℝ} + (hX:IsDiffusion W γ X) {t:ℝ} (ht:t∈Ioo (0:ℝ) 1) (e:JetExpr): + ContinuousAt (jetMoment W γ X e) t := by + obtain ⟨T,htT,hT⟩:=exists_between ht.2 + exact (hX.jetMoment_continuous ⟨ht.1.le.trans htT.le,hT⟩ e).continuousAt (Icc_mem_nhds ht.1 htT) +lemma momentExpr_eq_gradientMoment (W:BrownianSpace) (γ:OrderParameter) (X:ℝ → W.Ω → ℝ): + jetMoment W γ X JetExpr.momentExpr=gradientMoment W γ X := by + funext t + simp only [jetMoment,polyJet,JetExpr.momentExpr_eval,iteratedDeriv_zero,gradientMoment,gradient] +lemma IsDiffusion.curvature_convexOn {W:BrownianSpace} {γ:OrderParameter} {X:ℝ → W.Ω → ℝ} + (hX:IsDiffusion W γ X) {a b c:ℝ} (ha:0≤a) (hb:b≤1) + (he:∀t∈Ioo a b,γ.coeff t=c):ConvexOn ℝ (Ioo a b) (jetMoment W γ X JetExpr.curvatureExpr) := by + apply convexOn_of_hasDerivWithinAt2_nonneg (convex_Ioo a b) + (f':=jetMoment W γ X (JetExpr.curvatureSlope c)) + · intro t ht + exact (hX.jetMoment_continuousAt ⟨ha.trans_lt ht.1,ht.2.trans_le hb⟩ _).continuousWithinAt + · intro t ht + rw [interior_Ioo] at ht + exact (hX.curvatureExpr_hasDerivAt ⟨ha.trans_lt ht.1,ht.2.trans_le hb⟩ + (continuousAt_of_constant_interval ht he) (he t ht)).hasDerivWithinAt + · intro t ht + rw [interior_Ioo] at ht + exact (hX.curvatureSlope_hasDerivAt ⟨ha.trans_lt ht.1,ht.2.trans_le hb⟩ + (continuousAt_of_constant_interval ht he) (he t ht)).hasDerivWithinAt + · intro t ht + rw [interior_Ioo] at ht + exact hX.curvature_generator_nonneg ⟨ha.trans_lt ht.1,ht.2.trans_le hb⟩ +lemma IsDiffusion.moment_convexOn_zero {W:BrownianSpace} {γ:OrderParameter} {X:ℝ → W.Ω → ℝ} + (hX:IsDiffusion W γ X) {a b:ℝ} (ha:0≤a) (hb:b≤1) + (he:∀t∈Ioo a b,γ.coeff t=0):ConvexOn ℝ (Ioo a b) (gradientMoment W γ X) := by + apply convexOn_of_hasDerivWithinAt2_nonneg (convex_Ioo a b) + (f':=jetMoment W γ X JetExpr.curvatureExpr) (f'':=jetMoment W γ X (JetExpr.curvatureSlope 0)) + · exact hX.gradientMoment_continuous.mono (fun t ht ↦ ⟨(ha.trans_lt ht.1).le,ht.2.trans_le hb⟩) + · intro t ht + rw [interior_Ioo] at ht + simpa only [momentExpr_eq_gradientMoment] using + (hX.momentExpr_hasDerivAt ⟨ha.trans_lt ht.1,ht.2.trans_le hb⟩ + (continuousAt_of_constant_interval ht he)).hasDerivWithinAt (s:=interior (Ioo a b)) + · intro t ht + rw [interior_Ioo] at ht + exact (hX.curvatureExpr_hasDerivAt ⟨ha.trans_lt ht.1,ht.2.trans_le hb⟩ + (continuousAt_of_constant_interval ht he) (he t ht)).hasDerivWithinAt + · intro t ht + simp only [jetMoment,polyJet,JetExpr.curvatureSlope_eval,mul_zero,zero_mul,sub_zero] + exact integral_nonneg (fun z ↦ sq_nonneg _) +lemma IsDiffusion.moment_convexOn_zero_closed {W:BrownianSpace} {γ:OrderParameter} {X:ℝ → W.Ω → ℝ} + (hX:IsDiffusion W γ X) {a b:ℝ} (ha:0≤a) (hb:b<1) + (he:∀t∈Ioo a b,γ.coeff t=0):ConvexOn ℝ (Icc a b) (gradientMoment W γ X) := by + apply convexOn_of_hasDerivWithinAt2_nonneg (convex_Icc a b) + (f':=jetMoment W γ X JetExpr.curvatureExpr) (f'':=jetMoment W γ X (JetExpr.curvatureSlope 0)) + · exact hX.gradientMoment_continuous.mono (fun t ht ↦ ⟨ha.trans ht.1,ht.2.trans_lt hb⟩) + · intro t ht + rw [interior_Icc] at ht + simpa only [momentExpr_eq_gradientMoment] using + (hX.momentExpr_hasDerivAt ⟨ha.trans_lt ht.1,ht.2.trans hb⟩ + (continuousAt_of_constant_interval ht he)).hasDerivWithinAt (s:=interior (Icc a b)) + · intro t ht + rw [interior_Icc] at ht + exact (hX.curvatureExpr_hasDerivAt ⟨ha.trans_lt ht.1,ht.2.trans hb⟩ + (continuousAt_of_constant_interval ht he) (he t ht)).hasDerivWithinAt + · intro t ht + simp only [jetMoment,polyJet,JetExpr.curvatureSlope_eval,mul_zero,zero_mul,sub_zero] + exact integral_nonneg (fun z ↦ sq_nonneg _) +end SKValue + +end + +end OAI diff --git a/lean/OAI/Probability/SKValue/Coercivity/FiniteCoercivity.lean b/lean/OAI/Probability/SKValue/Coercivity/FiniteCoercivity.lean new file mode 100644 index 0000000000000000000000000000000000000000..711ee68f9d98a122ab1c3912ee477ad491ce5711 --- /dev/null +++ b/lean/OAI/Probability/SKValue/Coercivity/FiniteCoercivity.lean @@ -0,0 +1,82 @@ +import Mathlib +import OAI.Probability.SKValue.Equations.GeneralProfileShape +import OAI.Probability.SKValue.Coercivity.IntegratedCoercivity +import OAI.Probability.SKValue.Processes.FiniteProfileLaw + +namespace OAI + +section + +open MeasureTheory ProbabilityTheory Set Filter +open scoped Topology NNReal +namespace SKValue +lemma BoundedSmooth.pow {f:ℝ → ℝ} (hf:BoundedSmooth f) (n:ℕ) : + BoundedSmooth (fun x ↦ f x^n) := by + induction n with + | zero => simpa only [pow_zero] using BoundedSmooth.const (1:ℝ) + | succ n ih => simpa only [pow_succ] using ih.mul hf +lemma BoundedSmooth.sub {f g:ℝ → ℝ} (hf:BoundedSmooth f) (hg:BoundedSmooth g) : + BoundedSmooth (fun x ↦ f x-g x) := by + simpa only [neg_one_mul,sub_eq_add_neg] using hf.add (hg.const_mul (-1)) +lemma SmoothTerminal.spatialJet_boundedSmooth {A:ℝ → ℝ} (hA:SmoothTerminal A) + (c:ℝ) (n:ℕ) : BoundedSmooth (spatialJet c A n) := + (hA.jets.iteratedDeriv n).const_mul c + +lemma BackwardShape.profile_coercivity {A:ℝ → ℝ} {C:ℝ} (hA:SmoothTerminal A) + (hB:BackwardShape C A) {p:ℝ≥0 × ℝ≥0} {l:HeatProfile} + (hp:0<(p.2:ℝ)) (ht:0<(p.1:ℝ)) + (hl:(p::l).Pairwise (fun p q ↦ p.2≤q.2)) (hup:∀ q∈p::l,(q.2:ℝ)≤C) : + (1/1000:ℝ)*profileResponse A (fun x ↦ (spatialJet C A 1 x)^4) (p::l) 0 0≤ + profileResponse A (fun x ↦ (spatialJet C A 3 x)^2- + 12*spatialJet C A 1 x*(spatialJet C A 2 x)^2+6*(spatialJet C A 1 x)^4) (p::l) 0 0 := by + obtain ⟨E,hE,hpair⟩:=hB.profile_density hA hp ht hl hup + have hC:0] (0:ℝ)) (𝓝 (γ.coeff 0)) := + (γ.rightContinuous 0 ⟨le_rfl,by norm_num⟩).mono_left (nhdsWithin_mono _ Ioi_subset_Ici_self) + have hr:Tendsto γ.coeff (𝓝[>] (0:ℝ)) (𝓝 c) := by + apply tendsto_const_nhds.congr' + filter_upwards [self_mem_nhdsWithin,mem_nhdsWithin_of_mem_nhds (Iio_mem_nhds hb)] with t ht htb + exact (he t ⟨ht,htb⟩).symm + exact tendsto_nhds_unique hl hr +lemma IsDiffusion.moment_origin {W:BrownianSpace} {γ:OrderParameter} {X:ℝ → W.Ω → ℝ} + (hX:IsDiffusion W γ X):gradientMoment W γ X 0=0 := by + have hz:∀ᵐ z ∂W.μ,X 0 z=0 := by + filter_upwards [hX.2,W.brownian.toIsPreBrownianReal.eval_zero_ae_eq_zero] with z h h0 + simpa only [Real.toNNReal_zero,intervalIntegral.integral_same,add_zero,h0] using h.2 0 ⟨le_rfl,by norm_num⟩ + unfold gradientMoment + calc + (∫ z,(gradient W γ 0 (X 0 z))^2 ∂W.μ)=∫ z,(0:ℝ) ∂W.μ := by + apply integral_congr_ae + filter_upwards [hz] with z hz + rw [hz,phi_gradient_zero,zero_pow (by norm_num : (2:ℕ)≠0)] + _=0:=integral_zero W.Ω ℝ +end SKValue + +end + +section +open Set +namespace SKValue +lemma positive_gap_endpoints {G:ℝ → ℝ} (hc:ContinuousOn G (Icc (0:ℝ) 1)) + (hn:∀t∈Icc (0:ℝ) 1,0≤G t) (h1:G 1=0) {x:ℝ} (hx:x∈Ioo (0:ℝ) 1) (hxp:0.trans hyb⟩) + obtain ⟨s,hs,hes⟩:=exists_hasDerivAt_eq_slope f f' hxy + (hc.mono (Icc_subset_Icc hax.le hyb.le)) + (fun t ht ↦ hd t ⟨hax.trans ht.1,ht.2.trans hyb⟩) + obtain ⟨u,hu,heu⟩:=exists_hasDerivAt_eq_slope f f' hyb + (hc.mono (Icc_subset_Icc (hax.le.trans hxy.le) le_rfl)) + (fun t ht ↦ hd t ⟨hax.trans hxy |>.trans ht.1,ht.2⟩) + have hr0:f' r≤0:=by rw [her];exact div_nonpos_of_nonpos_of_nonneg (sub_nonpos.mpr hleft) (sub_pos.mpr hax).le + have hs0:0.trans hyb⟩ + ⟨hax.trans hxy |>.trans hu.1,hu.2⟩ ⟨(hr.2.trans hs.1).le,(hs.2.trans hu.1).le⟩ + exact (not_lt_of_ge (hh.trans (max_le hr0 hu0))) hs0 +end SKValue + +end + +section +open Set +namespace SKValue +lemma positive_hump_impossible {f f' G:ℝ → ℝ} {a b x:ℝ} + (hax:a.prod (f t)) inferInstance + (fun p ↦ α (min (Real.toNNReal p.1) t) p.2) := by + have hj := hα t + let : MeasurableSpace Ω := f t + have hc : Measurable (fun p : ℝ×Ω ↦ + (⟨min (Real.toNNReal p.1) t, Set.mem_Iic.mpr (min_le_right _ _)⟩ : Iic t)) := + ((measurable_real_toNNReal.comp measurable_fst).min measurable_const).subtype_mk + exact hj.comp (hc.prodMk measurable_snd) + +lemma controlAccum_measurable {Ω : Type*} [m : MeasurableSpace Ω] + {f : Filtration ℝ≥0 m} {α : ℝ≥0 → Ω → ℝ} {γ : ℝ → ℝ} + (hα : IsProgressive f α) (hγ : Measurable γ) (n : ℕ) {t : ℝ} (ht : 0≤t) : + Measurable[f (Real.toNNReal t)] (controlAccum γ α n t) := by + let : MeasurableSpace Ω := f (Real.toNNReal t) + have hm : Measurable (fun p : ℝ×Ω ↦ γ p.1*(α (min (Real.toNNReal p.1) (Real.toNNReal t)) p.2)^n) := + (hγ.comp measurable_fst).mul ((progressive_clamped_measurable (m := m) hα _).pow_const n) + have heq : controlAccum γ α n t = fun ω ↦ + ∫ s in (0 : ℝ)..t, γ s*(α (min (Real.toNNReal s) (Real.toNNReal t)) ω)^n := by + funext ω + apply intervalIntegral.integral_congr + intro s hs + rw [uIcc_of_le ht] at hs + dsimp only + rw [min_eq_left (Real.toNNReal_mono hs.2)] + rw [heq] + unfold intervalIntegral + exact hm.stronglyMeasurable.integral_prod_left.measurable.sub + hm.stronglyMeasurable.integral_prod_left.measurable + +lemma controlAccum_bound {Ω : Type*} {γ : ℝ → ℝ} {α : ℝ≥0 → Ω → ℝ} + {T t G : ℝ} (ht : 0≤t) (htT : t≤T) + (hα : ∀ s ω, |α s ω|≤1) (hγ : ∀ s∈Icc (0 : ℝ) T, |γ s|≤G) + (n : ℕ) (ω : Ω) : |controlAccum γ α n t ω|≤t*G := by + have hh := intervalIntegral.norm_integral_le_of_norm_le_const + (a := 0) (b := t) (f := fun s ↦ γ s*(α (Real.toNNReal s) ω)^n) (C := G) (fun s hs ↦ by + rw [uIoc_of_le ht] at hs + rw [Real.norm_eq_abs,abs_mul,abs_pow] + exact (mul_le_mul_of_nonneg_left (pow_le_one₀ (abs_nonneg _) (hα _ _)) (abs_nonneg _)).trans + (by simpa only [mul_one] using hγ s ⟨hs.1.le,hs.2.trans htT⟩)) + simpa only [controlAccum,Real.norm_eq_abs,sub_zero,abs_of_nonneg ht,mul_comm G t] using hh + +lemma controlAccum_integrable {Ω : Type*} [m : MeasurableSpace Ω] + {μ : Measure Ω} [IsFiniteMeasure μ] + {f : Filtration ℝ≥0 m} {α : ℝ≥0 → Ω → ℝ} {γ : ℝ → ℝ} {T t G : ℝ} + (hα : IsProgressive f α) (hαb : ∀ s ω, |α s ω|≤1) (hγ : Measurable γ) + (hγb : ∀ s∈Icc (0 : ℝ) T, |γ s|≤G) (n : ℕ) (ht : 0≤t) (htT : t≤T) : + Integrable (controlAccum γ α n t) μ := by + apply Integrable.of_bound + ((controlAccum_measurable hα hγ n ht).mono (f.le _) le_rfl).aestronglyMeasurable (t*G) + exact Eventually.of_forall (fun ω ↦ by + simpa only [Real.norm_eq_abs] using controlAccum_bound ht htT hαb hγb n ω) + +lemma controlAccum_integrand_intervalIntegrable {Ω : Type*} [m : MeasurableSpace Ω] + {f : Filtration ℝ≥0 m} {α : ℝ≥0 → Ω → ℝ} {γ : ℝ → ℝ} {T : ℝ} + (hα : IsProgressive f α) (hαb : ∀ s ω, |α s ω|≤1) (hγ : Measurable γ) + (hi : IntervalIntegrable γ volume 0 T) (hT : 0≤T) (n : ℕ) (ω : Ω) : + IntervalIntegrable (fun s ↦ γ s*(α (Real.toNNReal s) ω)^n) volume 0 T := by + have hm : Measurable (fun s ↦ γ s*(α (min (Real.toNNReal s) (Real.toNNReal T)) ω)^n) := by + let : MeasurableSpace Ω := f (Real.toNNReal T) + exact hγ.mul (((progressive_clamped_measurable (m := m) hα _).comp + (measurable_id.prodMk measurable_const)).pow_const n) + have hint : IntervalIntegrable (fun s ↦ γ s*(α (min (Real.toNNReal s) (Real.toNNReal T)) ω)^n) volume 0 T := by + apply hi.norm.mono_fun' + · exact hm.aestronglyMeasurable + · exact Eventually.of_forall (fun s ↦ by + dsimp only + rw [Real.norm_eq_abs,abs_mul,abs_pow,Real.norm_eq_abs] + exact (mul_le_mul_of_nonneg_left (pow_le_one₀ (abs_nonneg _) (hαb _ _)) + (abs_nonneg _)).trans_eq (mul_one _)) + apply hint.congr + intro s hs + rw [uIoc_of_le hT] at hs + dsimp only + rw [min_eq_left (Real.toNNReal_mono hs.2)] + +end SKValue + +namespace SKValue + +noncomputable def controlState {Ω : Type*} (B : ℝ≥0 → Ω → ℝ) + (γ : ℝ → ℝ) (α : ℝ≥0 → Ω → ℝ) (x t : ℝ) (ω : Ω) : ℝ := + x+B (Real.toNNReal t) ω+controlAccum γ α 1 t ω + +lemma controlState_past_measurable {Ω : Type*} [m : MeasurableSpace Ω] + {B : ℝ≥0 → Ω → ℝ} (hBm : ∀ t, StronglyMeasurable (B t)) + {γ : ℝ → ℝ} {α : ℝ≥0 → Ω → ℝ} + (hα : IsProgressive (Filtration.natural B hBm) α) (hγ : Measurable γ) (x : ℝ) + {t : ℝ} (ht : 0≤t) : + StronglyMeasurable[Filtration.natural B hBm (Real.toNNReal t)] (controlState B γ α x t) := + (stronglyMeasurable_const.add (Filtration.stronglyAdapted_natural hBm _)).add + (controlAccum_measurable hα hγ 1 ht).stronglyMeasurable + +lemma controlState_memLp_two {Ω : Type*} [m : MeasurableSpace Ω] + {μ : Measure Ω} [IsProbabilityMeasure μ] {B : ℝ≥0 → Ω → ℝ} + (hB : IsPreBrownianReal B μ) (hBm : ∀ t, StronglyMeasurable (B t)) + {γ : ℝ → ℝ} {α : ℝ≥0 → Ω → ℝ} {T t G : ℝ} + (hα : IsProgressive (Filtration.natural B hBm) α) (hαb : ∀ s ω, |α s ω|≤1) + (hγ : Measurable γ) (hγb : ∀ s∈Icc (0 : ℝ) T, |γ s|≤G) + (x : ℝ) (ht : 0≤t) (htT : t≤T) : MemLp (controlState B γ α x t) 2 μ := by + have hi : MemLp (controlAccum γ α 1 t) 2 μ := MemLp.of_bound + ((controlAccum_measurable hα hγ 1 ht).mono (Filtration.le _ _) le_rfl).aestronglyMeasurable + (t*G) (Eventually.of_forall (fun ω ↦ by + simpa only [Real.norm_eq_abs] using controlAccum_bound ht htT hαb hγb 1 ω)) + exact ((memLp_const x).add (hB.hasLaw_eval _).hasGaussianLaw.memLp_two).add hi + +lemma controlState_initial {Ω : Type*} [MeasurableSpace Ω] + {μ : Measure Ω} {B : ℝ≥0 → Ω → ℝ} (hB : IsPreBrownianReal B μ) + (γ : ℝ → ℝ) (α : ℝ≥0 → Ω → ℝ) (x : ℝ) : + ∀ᵐ ω ∂μ, controlState B γ α x 0 ω=x := by + filter_upwards [hB.eval_zero_ae_eq_zero] with ω hω + simp only [controlState,controlAccum,Real.toNNReal_zero,hω,add_zero, + intervalIntegral.integral_same] + +end SKValue + +end + +end OAI diff --git a/lean/OAI/Probability/SKValue/Control/FiniteStepControl.lean b/lean/OAI/Probability/SKValue/Control/FiniteStepControl.lean new file mode 100644 index 0000000000000000000000000000000000000000..3b6128fbe6fb0c9547345b70ea25110e3504ad11 --- /dev/null +++ b/lean/OAI/Probability/SKValue/Control/FiniteStepControl.lean @@ -0,0 +1,65 @@ +import Mathlib +import OAI.Probability.SKValue.Evolution.FiniteStepEvolution +import OAI.Probability.SKValue.Evolution.EvolutionShift + +namespace OAI + +section + +open MeasureTheory ProbabilityTheory Set Filter +open scoped Topology NNReal ENNReal BigOperators +namespace SKValue + +lemma SmoothEvolution.progressive_control_from + {Ω : Type*} [m : MeasurableSpace Ω] {μ : Measure Ω} [IsProbabilityMeasure μ] + {B : ℝ≥0 → Ω → ℝ} (hB : IsPreBrownianReal B μ) (hBm : ∀ s, StronglyMeasurable (B s)) + {T a b : ℝ} {γ : ℝ → ℝ} {V : ℝ → ℝ → ℝ} + (h : SmoothEvolution T γ V) (ha : 0≤a) (hab : a linarith [hs.1,hs.2] + obtain ⟨K,L,hstrip⟩ := ((h.time_shift ha hab.le hb).space_translate x).toValueStrip + (sub_nonneg.mpr hab.le) (fun s hs ↦ hγ _ (hmem s hs)) + (fun s hs t ht hst ↦ hm (hmem s hs) (hmem t ht) (add_le_add le_rfl hst)) + have he := hstrip.progressive_control_value hB hBm (sub_pos.mpr hab) hd + (hM.comp (measurable_const.add measurable_id)) + simpa only [add_sub_cancel,add_zero] using he + +theorem SmoothTerminal.profile_control_from (W : BrownianSpace) + {ψ : ℝ → ℝ} (hψ : SmoothTerminal ψ) {l : HeatProfile} + (hl : l.Pairwise (fun p q ↦ p.2≤q.2)) (hT : profileTime l=1) + {t : ℝ} (ht : t∈Ico (0 : ℝ) 1) (x : ℝ) : + sSup {r | ∃ α : ℝ≥0 → W.Ω → ℝ, Admissible W t α ∧ + r=∫ ω, ψ (x+W.B 1 ω-W.B t.toNNReal ω+ + ∫ s in (0 : ℝ)..(1-t), profileCoeff l (t+s)*α s.toNNReal ω)- + (1/2 : ℝ)*(∫ s in (0 : ℝ)..(1-t), profileCoeff l (t+s)*(α s.toNNReal ω)^2) ∂W.μ} = + profileValue ψ l t x := by + let B := fun s ω ↦ W.B (t.toNNReal+s) ω-W.B t.toNNReal ω + have hm : ∀ s, StronglyMeasurable (B s) := fun s ↦ (W.measurable _).sub (W.measurable _) + have he := (hψ.profile_evolution l).progressive_control_from + (W.brownian.toIsPreBrownianReal.shift t.toNNReal) hm ht.1 ht.2 (by rw [hT]) + (by linarith [ht.1]) (fun s _ ↦ profileCoeff_nonneg l s) (profileCoeff_mono hl) + (profileCoeff_measurable l) x + have hend : t.toNNReal+(1-t).toNNReal=1 := by + apply NNReal.eq + simp only [NNReal.coe_add,Real.coe_toNNReal _ ht.1,Real.coe_toNNReal _ (sub_nonneg.mpr ht.2.le),NNReal.coe_one] + ring + have hv : profileValue ψ l 1=ψ := hT ▸ profileValue_terminal ψ l + change sSup {r | ∃ α, Admissible W t α ∧ r=_}= _ + convert he using 1 + congr 1 + ext r + simp only [Admissible,shiftedFiltration,and_assoc,hv,controlState,controlAccum,pow_one,zero_add, + sub_eq_add_neg,add_assoc] + simp only [←sub_eq_add_neg,hend] + +end SKValue + +end + +end OAI diff --git a/lean/OAI/Probability/SKValue/Control/Forced.lean b/lean/OAI/Probability/SKValue/Control/Forced.lean new file mode 100644 index 0000000000000000000000000000000000000000..8ef019dcb66c6aea7b637b12146b61a066e59978 --- /dev/null +++ b/lean/OAI/Probability/SKValue/Control/Forced.lean @@ -0,0 +1,41 @@ +import Mathlib +import OAI.Probability.SKValue.Equations.ForcedGenerator + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped Topology NNReal BigOperators +namespace SKValue +lemma ForcedTest.source_measurable {T K L:ℝ} {γ:ℝ → ℝ} {u V b p:ℝ → ℝ → ℝ} + (h:ForcedTest T γ u V b p K L) {t:ℝ} (ht:t∈Icc (0:ℝ) T) : + Measurable (forcedSource γ u V b p t) := by + have h1:=((h.smooth t ht).continuous_deriv (by norm_num)).measurable + have h2:Measurable (fun x ↦ deriv (deriv (V t)) x) := by + have hh:=((h.smooth t ht).continuous_iteratedDeriv 2 (by norm_num)).measurable + simpa only [show (2:ℕ)=1+1 from rfl,iteratedDeriv_succ,iteratedDeriv_one,iteratedDeriv_zero] using hh + exact ((h.b_measurable t ht).add h2).const_mul (1/2:ℝ) |>.add + (((h.p_measurable t ht).add ((h.drift_measurable t ht).mul h1)).const_mul (γ t)) +lemma ForcedTest.source_bound {T K L:ℝ} {γ:ℝ → ℝ} {u V b p:ℝ → ℝ → ℝ} + (h:ForcedTest T γ u V b p K L) {t:ℝ} (ht:t∈Icc (0:ℝ) T) (x:ℝ) : + |forcedSource γ u V b p t x| ≤ (1+2*γ T)*K := by + have hb:|b t x+deriv (deriv (V t)) x| ≤ K+K := + (abs_add_le _ _).trans (add_le_add (h.b_bound t ht x) (h.second_bound t ht x)) + have hp:|p t x+u t x*deriv (V t) x| ≤ K+K := by + apply (abs_add_le _ _).trans + apply add_le_add (h.p_bound t ht x) + rw [abs_mul] + simpa only [one_mul] using mul_le_mul (h.drift_bound t ht x) (h.first_bound t ht x) (abs_nonneg _) (by norm_num : (0:ℝ) ≤ 1) + unfold forcedSource + apply (abs_add_le _ _).trans + rw [abs_mul,abs_mul,abs_of_nonneg (h.gamma_nonneg t ht)] + norm_num only [abs_div,abs_one,abs_of_nonneg (by norm_num : (0:ℝ) ≤ 2)] + have hγ:=h.gamma_mono ht ⟨ht.1.trans ht.2,le_rfl⟩ ht.2 + have hK:=h.K_nonneg + have hmul:=mul_le_mul hp hγ (h.gamma_nonneg t ht) (by linarith : (0:ℝ) ≤ K+K) + nlinarith +end SKValue + +end + +end OAI diff --git a/lean/OAI/Probability/SKValue/Control/PhiRegularity.lean b/lean/OAI/Probability/SKValue/Control/PhiRegularity.lean new file mode 100644 index 0000000000000000000000000000000000000000..a0116e85a29ec5e43615bc7578fb620a3c247662 --- /dev/null +++ b/lean/OAI/Probability/SKValue/Control/PhiRegularity.lean @@ -0,0 +1,164 @@ +import Mathlib +import OAI.Probability.SKValue.Evolution.SmoothApproxBounds +import OAI.Probability.SKValue.Equations.StripIntegralLimit + +namespace OAI + +section + +open MeasureTheory ProbabilityTheory Set Filter +open scoped Topology NNReal ENNReal BigOperators ContDiff +namespace SKValue + +lemma phi_bulk_jets (W : BrownianSpace) (γ : OrderParameter) {S : ℝ} + (hS : S∈Ico (0 : ℝ) 1) (k : ℕ) : + ∃ C : ℝ, 0 ≤ C ∧ ∀ t∈Icc (0 : ℝ) S, ∀ x, + |iteratedDeriv k (deriv (phi W γ t)) x| ≤ C := by + obtain ⟨C,hC,hb⟩ := smoothApprox_bulk_jets γ hS k + refine ⟨C,hC,?_⟩ + intro t ht x + exact le_of_tendsto (phi_jet_limit W γ hS ht k x).abs + (Eventually.of_forall (fun n ↦ hb n t ht k le_rfl x)) + +lemma phi_bulk_temporal (W : BrownianSpace) (γ : OrderParameter) {S : ℝ} + (hS : S∈Ico (0 : ℝ) 1) (k : ℕ) : + ∃ L : ℝ, 0 ≤ L ∧ ∀ s∈Icc (0 : ℝ) S, ∀ t∈Icc (0 : ℝ) S, ∀ x, + |iteratedDeriv k (deriv (phi W γ s)) x-iteratedDeriv k (deriv (phi W γ t)) x| ≤ L*|s-t| := by + obtain ⟨L,hL,hb⟩ := smoothApprox_bulk_temporal γ hS k + refine ⟨L,hL,?_⟩ + intro s hs t ht x + exact le_of_tendsto ((phi_jet_limit W γ hS hs k x).sub (phi_jet_limit W γ hS ht k x)).abs + (Eventually.of_forall (fun n ↦ hb n s hs t ht x)) + +lemma phi_smoothTerminal (W : BrownianSpace) (γ : OrderParameter) {t : ℝ} + (ht : t∈Ico (0 : ℝ) 1) : SmoothTerminal (phi W γ t) := by + have hs := (phi_smooth_and_jet_limits W γ ht).2 t ⟨ht.1,le_rfl⟩ + refine ⟨phi_lipschitz W γ ⟨ht.1,ht.2.le⟩,hs,(contDiff_infty_iff_deriv.mp hs).2,?_⟩ + intro k + obtain ⟨C,hC,hb⟩ := phi_bulk_jets W γ ht k + exact ⟨C,hC,hb t ⟨ht.1,le_rfl⟩⟩ + +lemma phi_time_jet_continuous (W : BrownianSpace) (γ : OrderParameter) {S : ℝ} + (hS : S∈Ico (0 : ℝ) 1) (k : ℕ) (x : ℝ) : + ContinuousOn (fun t ↦ iteratedDeriv k (phi W γ t) x) (Icc (0 : ℝ) S) := by + have hh := ((phi_smooth_and_jet_limits W γ hS).1 k).comp + (fun t : Icc (0 : ℝ) S ↦ (t,x)) + apply continuousOn_iff_continuous_domRestrict.mpr + apply hh.continuous + apply Eventually.frequently (Eventually.of_forall _) + intro n + have hc : ContinuousOn (fun t ↦ iteratedDeriv k (smoothApprox γ n t) x) (Icc (0 : ℝ) S) := by + have hsub : Icc (0 : ℝ) S⊆Icc (0 : ℝ) 1 := Icc_subset_Icc le_rfl hS.2.le + cases k with + | zero => simpa only [iteratedDeriv_zero] using ((smoothApprox_evolution γ n).continuous_value x).mono hsub + | succ k => simpa only [iteratedDeriv_succ'] using ((smoothApprox_evolution γ n).continuous_jet k x).mono hsub + exact continuousOn_iff_continuous_domRestrict.mp hc + +lemma smoothApprox_time_jet_continuous (γ : OrderParameter) {S : ℝ} + (hS : S∈Ico (0 : ℝ) 1) (n k : ℕ) (x : ℝ) : + ContinuousOn (fun t ↦ iteratedDeriv k (deriv (smoothApprox γ n t)) x) (Icc (0 : ℝ) S) := + ((smoothApprox_evolution γ n).continuous_jet k x).mono (Icc_subset_Icc le_rfl hS.2.le) + +lemma OrderParameter.grid_bulk_bound (γ : OrderParameter) {S : ℝ} + (hS : S∈Ico (0 : ℝ) 1) (n : ℕ) {t : ℝ} (ht : t∈Icc (0 : ℝ) S) : + |profileCoeff (γ.grid n) t| ≤ γ.coeff S := by + rw [abs_of_nonneg (profileCoeff_nonneg _ _)] + exact (γ.grid_le n ⟨ht.1,ht.2.trans_lt hS.2⟩).trans + (γ.monotone ⟨ht.1,ht.2.trans_lt hS.2⟩ hS ht.2) + +lemma OrderParameter.grid_bulk_ae_tendsto (γ : OrderParameter) {S : ℝ} + (hS : S∈Ico (0 : ℝ) 1) : + ∀ᵐ t ∂volume, t∈Icc (0 : ℝ) S → + Tendsto (fun n ↦ profileCoeff (γ.grid n) t) atTop (𝓝 (γ.coeff t)) := by + filter_upwards [γ.grid_ae_tendsto,Measure.ae_ne volume (0 : ℝ)] with t hc hne ht + have ht' : t∈Ioc (0 : ℝ) 1 := ⟨lt_of_le_of_ne ht.1 hne.symm,ht.2.trans hS.2.le⟩ + simpa only [OrderParameter.cutoff,indicator_of_mem (show t∈Ico (0 : ℝ) 1 from ⟨ht.1,ht.2.trans_lt hS.2⟩)] using hc ht' + +end SKValue + +end + +section + +open MeasureTheory ProbabilityTheory Set Filter +open scoped Topology NNReal ENNReal BigOperators ContDiff +namespace SKValue + +lemma phi_value_pde (W : BrownianSpace) (γ : OrderParameter) {S : ℝ} + (hS : S∈Ico (0 : ℝ) 1) {t s : ℝ} (ht : t∈Icc (0 : ℝ) S) (hs : s∈Icc (0 : ℝ) S) (x : ℝ) : + phi W γ s x-phi W γ t x = -(∫ r in t..s, + (1/2 : ℝ)*deriv (deriv (phi W γ r)) x+ + γ.coeff r*((1/2 : ℝ)*(deriv (phi W γ r) x)^2)) := by + obtain ⟨C,hC,hb⟩ := smoothApprox_bulk_jets γ hS 1 + have hD := strip_integral_limit (c := fun n ↦ profileCoeff (γ.grid n)) (γ := γ.coeff) + (f := fun n r ↦ (1/2 : ℝ)*iteratedDeriv 1 (deriv (smoothApprox γ n r)) x) + (g := fun n r ↦ (1/2 : ℝ)*(iteratedDeriv 0 (deriv (smoothApprox γ n r)) x)^2) + (F := fun r ↦ (1/2 : ℝ)*iteratedDeriv 1 (deriv (phi W γ r)) x) + (G := fun r ↦ (1/2 : ℝ)*(iteratedDeriv 0 (deriv (phi W γ r)) x)^2) + (Γ := γ.coeff S) (A := C/2) (B := C^2/2) ht hs + (fun n ↦ profileCoeff_measurable _) (fun n ↦ continuousOn_const.mul (smoothApprox_time_jet_continuous γ hS n 1 x)) + (fun n ↦ continuousOn_const.mul ((smoothApprox_time_jet_continuous γ hS n 0 x).pow 2)) + (fun n r hr ↦ γ.grid_bulk_bound hS n hr) + (fun n r hr ↦ by + rw [abs_mul,abs_of_pos (by norm_num : (0 : ℝ)<1/2)] + linarith [hb n r hr 1 le_rfl x]) + (fun n r hr ↦ by + rw [abs_mul,abs_pow,abs_of_pos (by norm_num : (0 : ℝ)<1/2)] + have hh := hb n r hr 0 (by omega) x + nlinarith [abs_nonneg (iteratedDeriv 0 (deriv (smoothApprox γ n r)) x)]) + (γ.nonneg _ hS) (γ.grid_bulk_ae_tendsto hS) + (fun r hr ↦ (phi_jet_limit W γ hS hr 1 x).const_mul (1/2 : ℝ)) + (fun r hr ↦ ((phi_jet_limit W γ hS hr 0 x).pow 2).const_mul (1/2 : ℝ)) + simp only [iteratedDeriv_one,iteratedDeriv_zero] at hD + have hvs := (smoothApprox_tendsto W γ).tendsto_at (⟨s,⟨hs.1,hs.2.trans_lt hS.2⟩⟩,x) + have hvt := (smoothApprox_tendsto W γ).tendsto_at (⟨t,⟨ht.1,ht.2.trans_lt hS.2⟩⟩,x) + have he (n : ℕ) := (smoothApprox_evolution γ n).value_pde t ⟨ht.1,ht.2.trans hS.2.le⟩ s ⟨hs.1,hs.2.trans hS.2.le⟩ x + exact tendsto_nhds_unique (hvs.sub hvt) (hD.neg.congr (fun n ↦ (he n).symm)) + +lemma phi_gradient_pde (W : BrownianSpace) (γ : OrderParameter) {S : ℝ} + (hS : S∈Ico (0 : ℝ) 1) {t s : ℝ} (ht : t∈Icc (0 : ℝ) S) (hs : s∈Icc (0 : ℝ) S) (x : ℝ) : + deriv (phi W γ s) x-deriv (phi W γ t) x = -(∫ r in t..s, + (1/2 : ℝ)*deriv (deriv (deriv (phi W γ r))) x+ + γ.coeff r*(deriv (phi W γ r) x*deriv (deriv (phi W γ r)) x)) := by + obtain ⟨C,hC,hb⟩ := smoothApprox_bulk_jets γ hS 2 + have hD := strip_integral_limit (c := fun n ↦ profileCoeff (γ.grid n)) (γ := γ.coeff) + (f := fun n r ↦ (1/2 : ℝ)*iteratedDeriv 2 (deriv (smoothApprox γ n r)) x) + (g := fun n r ↦ iteratedDeriv 0 (deriv (smoothApprox γ n r)) x*iteratedDeriv 1 (deriv (smoothApprox γ n r)) x) + (F := fun r ↦ (1/2 : ℝ)*iteratedDeriv 2 (deriv (phi W γ r)) x) + (G := fun r ↦ iteratedDeriv 0 (deriv (phi W γ r)) x*iteratedDeriv 1 (deriv (phi W γ r)) x) + (Γ := γ.coeff S) (A := C/2) (B := C^2) ht hs + (fun n ↦ profileCoeff_measurable _) (fun n ↦ continuousOn_const.mul (smoothApprox_time_jet_continuous γ hS n 2 x)) + (fun n ↦ (smoothApprox_time_jet_continuous γ hS n 0 x).mul (smoothApprox_time_jet_continuous γ hS n 1 x)) + (fun n r hr ↦ γ.grid_bulk_bound hS n hr) + (fun n r hr ↦ by + rw [abs_mul,abs_of_pos (by norm_num : (0 : ℝ)<1/2)] + linarith [hb n r hr 2 le_rfl x]) + (fun n r hr ↦ by + rw [abs_mul,pow_two] + exact mul_le_mul (hb n r hr 0 (by omega) x) (hb n r hr 1 (by omega) x) (abs_nonneg _) hC) + (γ.nonneg _ hS) (γ.grid_bulk_ae_tendsto hS) + (fun r hr ↦ (phi_jet_limit W γ hS hr 2 x).const_mul (1/2 : ℝ)) + (fun r hr ↦ (phi_jet_limit W γ hS hr 0 x).mul (phi_jet_limit W γ hS hr 1 x)) + simp only [show (2 : ℕ)=1+1 from rfl,iteratedDeriv_succ,iteratedDeriv_zero] at hD + have hvs := phi_jet_limit W γ hS hs 0 x + have hvt := phi_jet_limit W γ hS ht 0 x + simp only [iteratedDeriv_zero] at hvs hvt + have he (n : ℕ) := (smoothApprox_evolution γ n).gradient_pde t ⟨ht.1,ht.2.trans hS.2.le⟩ s ⟨hs.1,hs.2.trans hS.2.le⟩ x + exact tendsto_nhds_unique (hvs.sub hvt) (hD.neg.congr (fun n ↦ (he n).symm)) + +lemma phi_evolution (W : BrownianSpace) (γ : OrderParameter) {S : ℝ} + (hS : S∈Ico (0 : ℝ) 1) : SmoothEvolution S γ.coeff (phi W γ) := by + refine ⟨fun t ht ↦ phi_smoothTerminal W γ ⟨ht.1,ht.2.trans_lt hS.2⟩,?_,?_, + phi_bulk_jets W γ hS,phi_bulk_temporal W γ hS,?_,?_⟩ + · intro x + simpa only [iteratedDeriv_zero] using phi_time_jet_continuous W γ hS 0 x + · intro n x + simpa only [iteratedDeriv_succ'] using phi_time_jet_continuous W γ hS (n+1) x + · exact fun t ht s hs x ↦ phi_value_pde W γ hS ht hs x + · exact fun t ht s hs x ↦ phi_gradient_pde W γ hS ht hs x + +end SKValue + +end + +end OAI diff --git a/lean/OAI/Probability/SKValue/Control/PolynomialGenerator.lean b/lean/OAI/Probability/SKValue/Control/PolynomialGenerator.lean new file mode 100644 index 0000000000000000000000000000000000000000..60b6fbc12ac21a905f234e3343fb6109f1afae95 --- /dev/null +++ b/lean/OAI/Probability/SKValue/Control/PolynomialGenerator.lean @@ -0,0 +1,90 @@ +import Mathlib +import OAI.Probability.SKValue.Equations.ForcedGenerator +import OAI.Probability.SKValue.Equations.PolynomialForced +import OAI.Probability.SKValue.Equations.PolynomialObservable +import OAI.Probability.SKValue.Processes.ForcedDiffusion + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped Topology NNReal BigOperators +namespace SKValue +namespace JetExpr +noncomputable def sourceA (e:JetExpr):JetExpr := mul (const (1/2)) (add e.timeB (e.spatialIter 2)) +noncomputable def sourceP (e:JetExpr):JetExpr := add e.timeP (mul (coord 0) e.spatial) +end JetExpr +lemma SmoothEvolution.polyJet_source {T:ℝ} {γ:ℝ → ℝ} {V:ℝ → ℝ → ℝ} + (h:SmoothEvolution T γ V) (e:JetExpr) {t:ℝ} (ht:t∈Icc (0:ℝ) T) (x:ℝ): + forcedSource γ (fun t ↦ deriv (V t)) (polyJet V e) (polyJet V e.timeB) (polyJet V e.timeP) t x= + polyJet V e.sourceA t x+γ t*polyJet V e.sourceP t x := by + have hd:deriv (polyJet V e t)=polyJet V e.spatial t := funext (fun y ↦ (h.polyJet_hasDeriv e ht y).deriv) + have hdd:=h.polyJet_iterated e ht 2 + simp only [show (2:ℕ)=1+1 from rfl,iteratedDeriv_succ,iteratedDeriv_zero] at hdd + unfold forcedSource + rw [hdd,hd] + simp only [polyJet,JetExpr.sourceA,JetExpr.sourceP,JetExpr.eval,iteratedDeriv_zero] + +lemma IsDiffusion.polyJet_generator {W:BrownianSpace} {γ:OrderParameter} {X:ℝ → W.Ω → ℝ} + (hX:IsDiffusion W γ X) {T:ℝ} (hT:0 norm_num)) + hP hjP.continuous hPb hD2 + simp only [one_mul] at hlimA + have hXM (t:ℝ) (ht:t∈Icc (0:ℝ) T):AEStronglyMeasurable (X t) W.μ := + (hX.memLp (p:=2) ⟨ht.1,ht.2.trans hT1.le⟩ (by norm_num)).aestronglyMeasurable + have hpaths:=hX.strip_paths hT.le hT1 hLu (fun t ht s hs x y ↦ hu s hs t ht y x) + have hAi:IntervalIntegrable (fun t ↦ ∫ z,polyJet (phi W γ) e.sourceA t (X t z) ∂W.μ) volume 0 T := by + apply ContinuousOn.intervalIntegrable + rw [uIcc_of_le hT.le] + exact mean_observable_continuous hjA.continuous hAb hXM (hpaths.mono (fun _ hz ↦ hz.1)) + have hPi:IntervalIntegrable (fun t ↦ γ.coeff t*(∫ z,polyJet (phi W γ) e.sourceP t (X t z) ∂W.μ)) volume 0 T := by + apply hi.mul_continuousOn + rw [uIcc_of_le hT.le] + exact mean_observable_continuous hjP.continuous hPb hXM (hpaths.mono (fun _ hz ↦ hz.1)) + apply hf.diffusion_generator_of_source_limit W.brownian.toIsPreBrownianReal hT hT1.le hG hLu hu hXM hpaths + rw [intervalIntegral.integral_add hAi hPi] + apply (hlimA.add hlimP).congr' + filter_upwards [eventually_gt_atTop 0] with N hN + rw [←mul_add,←Finset.sum_add_distrib] + rw [←Fin.sum_univ_eq_sum_range] + congr 1 + apply Finset.sum_congr rfl + intro j hj + have ht:=mesh_time_mem hT.le hN j.isLt.le + have hIA:Integrable (fun z ↦ polyJet (phi W γ) e.sourceA (meshTime T N j) (euler T N γ.coeff (gradient W γ) z j)) + (gaussianProduct (Fin (N+1))) := by + apply Integrable.of_bound + · exact ((hjA.slice ht).measurable.comp (measurable_euler T N γ.coeff (gradient W γ) (fun i hi ↦ (hG.smooth _ (mesh_time_mem hT.le hN hi.le)).continuous.measurable) j j.isLt.le)).aestronglyMeasurable + · exact Eventually.of_forall (fun z ↦ by simpa only [Real.norm_eq_abs] using hAb _ ht _) + have hIP:Integrable (fun z ↦ polyJet (phi W γ) e.sourceP (meshTime T N j) (euler T N γ.coeff (gradient W γ) z j)) + (gaussianProduct (Fin (N+1))) := by + apply Integrable.of_bound + · exact ((hjP.slice ht).measurable.comp (measurable_euler T N γ.coeff (gradient W γ) (fun i hi ↦ (hG.smooth _ (mesh_time_mem hT.le hN hi.le)).continuous.measurable) j j.isLt.le)).aestronglyMeasurable + · exact Eventually.of_forall (fun z ↦ by simpa only [Real.norm_eq_abs] using hPb _ ht _) + rw [←integral_const_mul,←integral_add hIA (hIP.const_mul _)] + apply integral_congr_ae + exact Eventually.of_forall (fun z ↦ (h.polyJet_source e ht _).symm) +end SKValue + +end + +end OAI diff --git a/lean/OAI/Probability/SKValue/Control/Regularity.lean b/lean/OAI/Probability/SKValue/Control/Regularity.lean new file mode 100644 index 0000000000000000000000000000000000000000..040ad350b5807a7dc8caa5cdd163a282c6639230 --- /dev/null +++ b/lean/OAI/Probability/SKValue/Control/Regularity.lean @@ -0,0 +1,137 @@ +import Mathlib +import OAI.Probability.SKValue.Control.StripRegularity +import OAI.Probability.SKValue.Control.PhiRegularity + +namespace OAI + +section + +open MeasureTheory ProbabilityTheory Set Filter +open scoped Topology NNReal ENNReal BigOperators +namespace SKValue + +lemma phi_even (W : BrownianSpace) (γ : OrderParameter) {t : ℝ} + (ht : t∈Ico (0 : ℝ) 1) (x : ℝ) : phi W γ t (-x)=phi W γ t x := by + have hl := (smoothApprox_tendsto W γ).tendsto_at (⟨t,ht⟩,-x) + have hr := (smoothApprox_tendsto W γ).tendsto_at (⟨t,ht⟩,x) + exact tendsto_nhds_unique hl (hr.congr (fun n ↦ (smoothApprox_even γ n t x).symm)) + +lemma phi_gradient_zero (W : BrownianSpace) (γ : OrderParameter) : gradient W γ 0 0=0 := + deriv_even_zero (phi_even W γ (by norm_num)) + +theorem sourceStripRegularity (W : BrownianSpace) (γ : OrderParameter) : SourceStripRegularity W γ := by + intro T hT + have h := phi_evolution W γ hT + have hγ : ∀ t∈Icc (0 : ℝ) T, 0 ≤ γ.coeff t := + fun t ht ↦ γ.nonneg _ ⟨ht.1,ht.2.trans_lt hT.2⟩ + have hmono : MonotoneOn γ.coeff (Icc (0 : ℝ) T) := + γ.monotone.mono (fun _ ht ↦ ⟨ht.1,ht.2.trans_lt hT.2⟩) + obtain ⟨Kv,Lv,hV⟩ := h.toValueStrip hT.1 hγ hmono + obtain ⟨K,L,hG⟩ := h.toGradientStrip hT.1 hγ hmono (phi_gradient_zero W γ) + obtain ⟨D,hD,hb⟩ := h.bound 1 + obtain ⟨Lu,hLu,hu⟩ := h.jet_joint 0 + obtain ⟨La,hLa,ha⟩ := h.jet_joint 1 + refine ⟨Kv,Lv,K,L,D,Lu,La,hV,hG,hD,hLu,hLa,?_,?_,?_⟩ + · intro t ht x + change |deriv (deriv (phi W γ t)) x| ≤ D + simpa only [iteratedDeriv_one] using hb t ht x + · intro s hs t ht x y + simpa only [iteratedDeriv_zero,gradient] using hu s hs t ht y x + · intro s hs t ht x y + change |deriv (deriv (phi W γ s)) x-deriv (deriv (phi W γ t)) y| ≤ _ + simpa only [iteratedDeriv_one] using ha s hs t ht y x + +end SKValue + +end + +section + +open MeasureTheory ProbabilityTheory Set Filter +open scoped Topology NNReal ENNReal BigOperators +namespace SKValue + +lemma ValueStrip.drift_one_step {T K L G t δ x z r : ℝ} + {γ : ℝ → ℝ} {V : ℝ → ℝ → ℝ} (h : ValueStrip T γ V K L) + (ht : 0≤t) (hδ : 0≤δ) (hδ1 : δ≤1) (htδ : t+δ≤T) + (hG : γ T≤G) (hr : |r|≤G) : + |V (t+δ) (x+Real.sqrt δ*z+δ*r)-V t x-deriv (V t) x*Real.sqrt δ*z- + (1/2 : ℝ)*δ*deriv (deriv (V t)) x*(z^2-1)- + δ*(deriv (V t) x*r-(1/2 : ℝ)*γ t*(deriv (V t) x)^2)| ≤ + δ*Real.sqrt δ*cubicEnvelope G K ((1/2+G)*L) z+ + δ*K*(γ (t+δ)-γ t) := by + have htT : t≤T := (le_add_of_nonneg_right hδ).trans htδ + have hT : 0≤T := ht.trans htT + have hsub : Icc t (t+δ)⊆Icc (0 : ℝ) T := Icc_subset_Icc ht htδ + have htm : t∈Icc (0 : ℝ) T := ⟨ht,htT⟩ + have hem : t+δ∈Icc (0 : ℝ) T := ⟨by linarith,htδ⟩ + have hTm : T∈Icc (0 : ℝ) T := ⟨hT,le_rfl⟩ + have hbint (y : ℝ) : IntervalIntegrable (fun s ↦ deriv (deriv (V s)) y) volume t (t+δ) := + (h.second_integrable y).mono_set (by + rw [uIcc_of_le (by linarith : t≤t+δ),uIcc_of_le hT] + exact hsub) + have hpint (y : ℝ) : IntervalIntegrable (fun s ↦ γ s*((1/2 : ℝ)*(deriv (V s) y)^2)) volume t (t+δ) := + (h.product_integrable y).mono_set (by + rw [uIcc_of_le (by linarith : t≤t+δ),uIcc_of_le hT] + exact hsub) + have hh := value_bounded_drift_one_step (V := V) (γ := γ) (x := x) (z := z) + hδ hδ1 ((h.gamma_nonneg T hTm).trans hG) h.K_nonneg h.L_nonneg hr + (h.gamma_mono.mono hsub) (h.gamma_nonneg t htm) + ((h.gamma_mono htm hTm htT).trans hG) (h.smooth t htm) + (h.second_bound t htm x) (h.third_bound t htm) + (fun s hs ↦ h.product_bound s (hsub hs)) + (fun s hs y ↦ h.second_lipschitz t htm s (hsub hs) x y) + (fun s hs y ↦ h.product_lipschitz t htm s (hsub hs) x y) + hbint hpint (fun y ↦ h.pde t htm (t+δ) hem y) + simpa only [add_assoc] using hh + +noncomputable def crossFeedback (V U : ℝ → ℝ → ℝ) (t x : ℝ) : ℝ := + (deriv (U t) x+deriv (V t) x)/2 + +lemma crossFeedback_bound {V U : ℝ → ℝ → ℝ} {t x : ℝ} + (hV : |deriv (V t) x|≤1) (hU : |deriv (U t) x|≤1) : + |crossFeedback V U t x|≤1 := by + dsimp [crossFeedback] + rw [abs_div,abs_of_pos (by norm_num : (0 : ℝ)<2),div_le_iff₀ (by norm_num : (0 : ℝ)<2)] + calc |deriv (U t) x+deriv (V t) x| ≤ |deriv (U t) x|+|deriv (V t) x| := abs_add_le _ _ + _ ≤ 1*2 := by linarith + +lemma cross_generator_identity (β γ p q : ℝ) : + (q*(β*((q+p)/2))-(1/2 : ℝ)*β*q^2)- + (p*(β*((q+p)/2))-(1/2 : ℝ)*γ*p^2) = -(1/2 : ℝ)*(β-γ)*p^2 := by ring + +lemma cross_value_one_step {T K L K' L' G t δ x z : ℝ} + {γ β : ℝ → ℝ} {V U : ℝ → ℝ → ℝ} + (hV : ValueStrip T γ V K L) (hU : ValueStrip T β U K' L') + (ht : 0≤t) (hδ : 0≤δ) (hδ1 : δ≤1) (htδ : t+δ≤T) + (hG : γ T≤G) (hG' : β T≤G) : + let y := x+Real.sqrt δ*z+δ*(β t*crossFeedback V U t x) + |(U (t+δ) y-V (t+δ) y)-(U t x-V t x)- + (deriv (U t) x-deriv (V t) x)*Real.sqrt δ*z- + (1/2 : ℝ)*δ*(deriv (deriv (U t)) x-deriv (deriv (V t)) x)*(z^2-1)+ + (δ/2)*(β t-γ t)*(deriv (V t) x)^2| ≤ + δ*Real.sqrt δ*(cubicEnvelope G K ((1/2+G)*L) z+ + cubicEnvelope G K' ((1/2+G)*L') z)+ + δ*K*(γ (t+δ)-γ t)+δ*K'*(β (t+δ)-β t) := by + have htT : t≤T := (le_add_of_nonneg_right hδ).trans htδ + have htm : t∈Icc (0 : ℝ) T := ⟨ht,htT⟩ + have hβ : 0≤β t := hU.gamma_nonneg t htm + have hr : |β t*crossFeedback V U t x|≤G := by + rw [abs_mul,abs_of_nonneg hβ] + calc β t*|crossFeedback V U t x| ≤ β t*1 := + mul_le_mul_of_nonneg_left (crossFeedback_bound (hV.bounded _ htm _) (hU.bounded _ htm _)) hβ + _ ≤ G := by simpa only [mul_one] using (hU.gamma_mono htm ⟨ht.trans htT,le_rfl⟩ htT).trans hG' + have hv := hV.drift_one_step (x := x) (z := z) ht hδ hδ1 htδ hG hr + have hu := hU.drift_one_step (x := x) (z := z) ht hδ hδ1 htδ hG' hr + dsimp only + have hab (a b : ℝ) : |a-b|≤|a|+|b| := by + simpa only [sub_zero,zero_sub,abs_neg] using abs_sub_le a 0 b + convert (hab _ _).trans (add_le_add hu hv) using 1 <;> + try dsimp only [crossFeedback] + all_goals ring_nf + +end SKValue + +end + +end OAI diff --git a/lean/OAI/Probability/SKValue/Control/StripRegularity.lean b/lean/OAI/Probability/SKValue/Control/StripRegularity.lean new file mode 100644 index 0000000000000000000000000000000000000000..abf6a59c9774299f85c4aeb18f5ff55d964c2965 --- /dev/null +++ b/lean/OAI/Probability/SKValue/Control/StripRegularity.lean @@ -0,0 +1,125 @@ +import Mathlib +import OAI.Probability.SKValue.Processes.MeshBrownian +import OAI.Probability.SKValue.Evolution.L1Terminal + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set +open scoped ENNReal NNReal BigOperators +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators Topology +open MeasureTheory ProbabilityTheory Set Filter +open scoped Topology BigOperators +open MeasureTheory ProbabilityTheory Set Filter +open scoped Topology ENNReal NNReal +open Filter Set +open scoped Topology BigOperators +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology +open MeasureTheory Set Filter +open scoped Topology BigOperators +open MeasureTheory Set Filter Finset +open scoped Topology BigOperators +namespace SKValue +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology NNReal + +def SourceStripRegularity (W : BrownianSpace) (γ : OrderParameter) : Prop := + ∀ T∈Ico (0 : ℝ) 1, ∃ Kv Lv K L D Lu La : ℝ, + ValueStrip T γ.coeff (phi W γ) Kv Lv ∧ + GradientStrip T γ.coeff (gradient W γ) K L ∧ + 0≤D ∧ 0≤Lu ∧ 0≤La ∧ + (∀ t∈Icc (0 : ℝ) T, ∀ x, |curvature W γ t x|≤D) ∧ + (∀ s∈Icc (0 : ℝ) T, ∀ t∈Icc (0 : ℝ) T, ∀ x y, + |gradient W γ s x-gradient W γ t y|≤Lu*(|s-t|+|x-y|)) ∧ + (∀ s∈Icc (0 : ℝ) T, ∀ t∈Icc (0 : ℝ) T, ∀ x y, + |curvature W γ s x-curvature W γ t y|≤La*(|s-t|+|x-y|)) + +lemma SourceStripRegularity.core {W : BrownianSpace} {γ : OrderParameter} + (h : SourceStripRegularity W γ) : + ∀ T∈Ico (0 : ℝ) 1, ∃ K L Lu : ℝ, 0≤Lu ∧ + GradientStripCore T γ.coeff (gradient W γ) K L ∧ + ∀ s∈Icc (0 : ℝ) T, ∀ t∈Icc (0 : ℝ) T, ∀ x y, + |gradient W γ s x-gradient W γ t y|≤Lu*(|s-t|+|x-y|) := by + intro T hT + obtain ⟨Kv,Lv,K,L,D,Lu,La,hV,hG,hD,hLu,hLa,hDb,hu,ha⟩ := h T hT + exact ⟨K,L,Lu,hLu,hG.toCore,hu⟩ + +lemma IsDiffusion.curvature_mean_continuous {W : BrownianSpace} {γ : OrderParameter} + {X : ℝ → W.Ω → ℝ} (hX : IsDiffusion W γ X) (hreg : SourceStripRegularity W γ) : + ContinuousOn (fun t ↦ ∫ ω, curvature W γ t (X t ω) ∂W.μ) (Ico (0 : ℝ) 1) := by + intro t ht + obtain ⟨T,htT,hT1⟩ := exists_between ht.2 + obtain ⟨Kv,Lv,K,L,D,Lu,La,hV,hG,hD,hLu,hLa,hDb,hu,ha⟩ := hreg T ⟨ht.1.trans htT.le,hT1⟩ + have hc := mean_derivative_continuous hLa + (fun s hs ↦ (hG.smooth s hs).continuous_deriv (by norm_num)) hDb ha + (fun s hs ↦ (hX.measurable ⟨hs.1,hs.2.trans hT1.le⟩).aestronglyMeasurable) + (hX.2.mono (fun _ hω ↦ hω.1.mono (Icc_subset_Icc le_rfl hT1.le))) + apply (hc t ⟨ht.1,htT.le⟩).mono_of_mem_nhdsWithin + filter_upwards [self_mem_nhdsWithin,mem_nhdsWithin_of_mem_nhds (Iio_mem_nhds htT)] with s hs hsT + exact ⟨hs.1,hsT.le⟩ + +lemma IsDiffusion.curvature_memLp {W : BrownianSpace} {γ : OrderParameter} + {X : ℝ → W.Ω → ℝ} (hX : IsDiffusion W γ X) (hreg : SourceStripRegularity W γ) + {t : ℝ} (ht : t∈Ico (0 : ℝ) 1) (p : ℝ≥0∞) : + MemLp (fun ω ↦ curvature W γ t (X t ω)) p W.μ := by + obtain ⟨Kv,Lv,K,L,D,Lu,La,hV,hG,hD,hLu,hLa,hDb,hu,ha⟩ := hreg t ht + exact MemLp.of_bound + (((hG.smooth t ⟨ht.1,le_rfl⟩).continuous_deriv (by norm_num)).measurable.comp + (hX.measurable ⟨ht.1,ht.2.le⟩)).aestronglyMeasurable D + (Eventually.of_forall (fun ω ↦ (Real.norm_eq_abs _).trans_le (hDb t ⟨ht.1,le_rfl⟩ _))) + +lemma IsDiffusion.curvature_mean_integrable {W : BrownianSpace} {γ : OrderParameter} + {X : ℝ → W.Ω → ℝ} (hX : IsDiffusion W γ X) (hreg : SourceStripRegularity W γ) + (ha : ∀ t∈Ico (0 : ℝ) 1, (∫ ω, (curvature W γ t (X t ω))^2 ∂W.μ)=1) : + IntervalIntegrable (fun t ↦ ∫ ω, curvature W γ t (X t ω) ∂W.μ) volume 0 1 := by + have hb (t : ℝ) (ht : t∈Ico (0 : ℝ) 1) : + |∫ ω, curvature W γ t (X t ω) ∂W.μ|≤1 := by + apply abs_integral_le_integral_abs.trans + simpa only [ha t ht,Real.sqrt_one] using integral_abs_le_sqrt_second (hX.curvature_memLp hreg ht 2) + have hi : IntegrableOn (fun t ↦ ∫ ω, curvature W γ t (X t ω) ∂W.μ) (Ico (0 : ℝ) 1) := + Integrable.of_bound ((hX.curvature_mean_continuous hreg).aestronglyMeasurable measurableSet_Ico) + 1 ((ae_restrict_mem measurableSet_Ico).mono (fun t ht ↦ (Real.norm_eq_abs _).trans_le (hb t ht))) + exact (intervalIntegrable_iff_integrableOn_Ioc_of_le (by norm_num : (0 : ℝ)≤1)).mpr + (hi.congr_set_ae Ico_ae_eq_Ioc.symm) + +lemma IsDiffusion.terminal_brownian_covariance {W : BrownianSpace} {γ : OrderParameter} + {X : ℝ → W.Ω → ℝ} (hX : IsDiffusion W γ X) (hreg : SourceStripRegularity W γ) + (hm : UnitMomentMartingale (μ := W.μ) W.realFiltration (fun t ω ↦ gradient W γ t (X t ω))) + {U : W.Ω → ℝ} (hUm : StronglyMeasurable[W.realFiltration 1] U) + (hU : ∀ᵐ ω ∂W.μ, |U ω|≤1 ∧ + Tendsto (fun n ↦ gradient W γ (terminalTime n) (X (terminalTime n) ω)) atTop (𝓝 (U ω))) + {T : ℝ} (hT : 0 dsimp only [cubicEnvelope, d] + all_goals congr 1 + all_goals ring + +lemma control_completion_square {γ α : ℝ → ℝ} {a b p : ℝ} + (hab : a≤b) (hγ : ∀ s∈Icc a b, 0≤γ s) + (hi : IntervalIntegrable γ volume a b) + (hi₁ : IntervalIntegrable (fun s ↦ γ s*α s) volume a b) + (hi₂ : IntervalIntegrable (fun s ↦ γ s*(α s)^2) volume a b) : + p*(∫ s in a..b, γ s*α s)-(1/2 : ℝ)*(∫ s in a..b, γ s*(α s)^2) ≤ + ((1/2 : ℝ)*p^2)*(∫ s in a..b, γ s) := by + have hpw : ∀ s∈Icc a b, + p*(γ s*α s)-(1/2 : ℝ)*(γ s*(α s)^2) ≤ ((1/2 : ℝ)*p^2)*γ s := by + intro s hs + nlinarith [mul_nonneg (hγ s hs) (sq_nonneg (α s-p))] + have hh := intervalIntegral.integral_mono_on hab + ((hi₁.const_mul p).sub (hi₂.const_mul (1/2))) (hi.const_mul ((1/2 : ℝ)*p^2)) hpw + simpa only [intervalIntegral.integral_sub (hi₁.const_mul p) (hi₂.const_mul (1/2)), + intervalIntegral.integral_const_mul] using hh + +lemma ValueStrip.control_one_step {T K L t δ x z : ℝ} {γ α : ℝ → ℝ} + {V : ℝ → ℝ → ℝ} (h : ValueStrip T γ V K L) + (ht : 0≤t) (hδ : 0<δ) (hδ1 : δ≤1) (htδ : t+δ≤T) + (hα : ∀ s∈Icc t (t+δ), |α s|≤1) + (hi : IntervalIntegrable γ volume t (t+δ)) + (hi₁ : IntervalIntegrable (fun s ↦ γ s*α s) volume t (t+δ)) + (hi₂ : IntervalIntegrable (fun s ↦ γ s*(α s)^2) volume t (t+δ)) : + V (t+δ) (x+Real.sqrt δ*z+(∫ s in t..(t+δ), γ s*α s))- + (1/2 : ℝ)*(∫ s in t..(t+δ), γ s*(α s)^2)-V t x- + deriv (V t) x*Real.sqrt δ*z- + (1/2 : ℝ)*δ*deriv (deriv (V t)) x*(z^2-1) ≤ + δ*Real.sqrt δ*cubicEnvelope (γ T) K ((1/2+γ T)*L) z+ + 2*δ*K*(γ (t+δ)-γ t) := by + have htT : t≤T := (le_add_of_nonneg_right hδ.le).trans htδ + have hT : 0≤T := ht.trans htT + have hsub : Icc t (t+δ)⊆Icc (0 : ℝ) T := Icc_subset_Icc ht htδ + have htm : t∈Icc (0 : ℝ) T := ⟨ht,htT⟩ + have hem : t+δ∈Icc (0 : ℝ) T := ⟨by linarith,htδ⟩ + have hTm : T∈Icc (0 : ℝ) T := ⟨hT,le_rfl⟩ + have hG := h.gamma_nonneg T hTm + have hγm := h.gamma_mono.mono hsub + have hγn : ∀ s∈Icc t (t+δ), 0≤γ s := fun s hs ↦ h.gamma_nonneg s (hsub hs) + have hγb : ∀ s∈Icc t (t+δ), γ s≤γ T := + fun s hs ↦ h.gamma_mono (hsub hs) hTm (hs.2.trans htδ) + let D := ∫ s in t..(t+δ), γ s*α s + let r := D/δ + have hD : |D|≤δ*(γ T) := by + have hh := intervalIntegral.norm_integral_le_of_norm_le_const + (a := t) (b := t+δ) (f := fun s ↦ γ s*α s) (C := γ T) (fun s hs ↦ by + rw [uIoc_of_le (by linarith : t≤t+δ)] at hs + have hs' : s∈Icc t (t+δ) := ⟨hs.1.le,hs.2⟩ + rw [Real.norm_eq_abs, abs_mul, abs_of_nonneg (hγn s hs')] + exact (mul_le_mul_of_nonneg_left (hα s hs') (hγn s hs')).trans + (by simpa only [mul_one] using hγb s hs')) + simpa only [Real.norm_eq_abs, show t+δ-t=δ by ring, + abs_of_nonneg hδ.le, mul_comm (γ T) δ] using hh + have hr : |r|≤γ T := by + dsimp only [r] + rw [abs_div, abs_of_pos hδ, div_le_iff₀ hδ] + simpa only [mul_comm] using hD + have hdr : δ*r=D := by dsimp [r]; field_simp + have hbint (y : ℝ) : IntervalIntegrable (fun s ↦ deriv (deriv (V s)) y) volume t (t+δ) := + (h.second_integrable y).mono_set (by + rw [uIcc_of_le (by linarith : t≤t+δ),uIcc_of_le hT] + exact hsub) + have hpint (y : ℝ) : IntervalIntegrable (fun s ↦ γ s*((1/2 : ℝ)*(deriv (V s) y)^2)) volume t (t+δ) := + (h.product_integrable y).mono_set (by + rw [uIcc_of_le (by linarith : t≤t+δ),uIcc_of_le hT] + exact hsub) + have hh := value_bounded_drift_one_step (V := V) (γ := γ) (x := x) (z := z) + hδ.le hδ1 hG h.K_nonneg h.L_nonneg hr hγm (h.gamma_nonneg t htm) + (h.gamma_mono htm hTm htT) (h.smooth t htm) (h.second_bound t htm x) + (h.third_bound t htm) (fun s hs ↦ h.product_bound s (hsub hs)) + (fun s hs y ↦ h.second_lipschitz t htm s (hsub hs) x y) + (fun s hs y ↦ h.product_lipschitz t htm s (hsub hs) x y) + hbint hpint (fun y ↦ h.pde t htm (t+δ) hem y) + dsimp only at hh + rw [hdr, ←add_assoc] at hh + have hcomp := control_completion_square (p := deriv (V t) x) + (by linarith : t≤t+δ) hγn hi hi₁ hi₂ + have hγint : (∫ s in t..(t+δ), γ s)≤δ*γ (t+δ) := by + have hc := intervalIntegral.integral_mono_on (by linarith : t≤t+δ) hi + (intervalIntegrable_const (c := γ (t+δ))) + (fun s hs ↦ h.gamma_mono (hsub hs) hem hs.2) + simpa only [intervalIntegral.integral_const, smul_eq_mul, show t+δ-t=δ by ring] using hc + have hp0 : 0≤(1/2 : ℝ)*(deriv (V t) x)^2 := by positivity + have hpK : (1/2 : ℝ)*(deriv (V t) x)^2≤K := + (le_abs_self _).trans (h.product_bound t htm x) + have hgap : 0≤γ (t+δ)-γ t := sub_nonneg.mpr (h.gamma_mono htm hem (by linarith)) + have hdiff : (1/2 : ℝ)*(deriv (V t) x)^2*(∫ s in t..(t+δ), γ s)- + δ*((1/2 : ℝ)*γ t*(deriv (V t) x)^2) ≤ δ*K*(γ (t+δ)-γ t) := by + calc + _ ≤ (1/2 : ℝ)*(deriv (V t) x)^2*(δ*γ (t+δ))- + δ*((1/2 : ℝ)*γ t*(deriv (V t) x)^2) := by gcongr + _ = δ*((1/2 : ℝ)*(deriv (V t) x)^2)*(γ (t+δ)-γ t) := by ring + _ ≤ _ := by gcongr + have hhu := (le_abs_self _).trans hh + have hcomp' : deriv (V t) x*D-(1/2 : ℝ)*(∫ s in t..(t+δ), γ s*(α s)^2)- + δ*((1/2 : ℝ)*γ t*(deriv (V t) x)^2) ≤ δ*K*(γ (t+δ)-γ t) := by + dsimp only [D] + linarith + have heq : δ*(deriv (V t) x*r-(1/2 : ℝ)*γ t*(deriv (V t) x)^2) = + deriv (V t) x*D-δ*((1/2 : ℝ)*γ t*(deriv (V t) x)^2) := by rw [mul_sub, mul_left_comm δ, hdr] + rw [heq] at hhu + dsimp only [D] at hhu hcomp' + linarith + +end SKValue + +namespace SKValue + +lemma ValueStrip.control_mesh_bound {T K L x : ℝ} {N : ℕ} {γ α W X : ℝ → ℝ} + {V : ℝ → ℝ → ℝ} {Z : Fin N → ℝ} + (hT : 0 exact hf 0 le_rfl + | succ n ih => exact (ih (fun j hj ↦ hf j (by omega))).sup (hf (n+1) le_rfl) + +lemma mesh_time_mem_total {T : ℝ} (hT : 0≤T) {N j : ℕ} (hj : j≤N) : + meshTime T N j∈Icc (0 : ℝ) T := by + by_cases hN : N=0 + · subst N + simp only [meshTime, stepSize, Nat.cast_zero, div_zero, mul_zero] + exact ⟨le_rfl,hT⟩ + · exact mesh_time_mem hT (Nat.pos_of_ne_zero hN) hj + +lemma meshMaxError_measurable_on {Ω : Type*} [MeasurableSpace Ω] {μ : Measure Ω} + {T : ℝ} {X : ℝ → Ω → ℝ} {Y : ℕ → ℕ → Ω → ℝ} (hT : 0≤T) + (hXM : ∀ t∈Icc (0 : ℝ) T, AEStronglyMeasurable (X t) μ) + (hYM : ∀ N j, j≤N → AEStronglyMeasurable (Y N j) μ) (N : ℕ) : + AEStronglyMeasurable (meshMaxError T X Y N) μ := by + apply aestronglyMeasurable_initialMax_on + intro j hj + exact ((hYM N j hj).sub (hXM _ (mesh_time_mem_total hT hj))).norm + +lemma driven_euler_L2_convergence_on {Ω : Type*} [MeasurableSpace Ω] {μ : Measure Ω} + [IsFiniteMeasure μ] {T L : ℝ} {u : ℝ → ℝ → ℝ} {γ : ℝ → ℝ} + {W X : ℝ → Ω → ℝ} {Y : ℕ → ℕ → Ω → ℝ} + (hT : 0 ≤ T) (hL : 0 ≤ L) + (hγ : MonotoneOn γ (Icc (0 : ℝ) T)) (hγ0 : 0 ≤ γ 0) + (hu : ∀ t ∈ Icc (0 : ℝ) T, ∀ x, |u t x| ≤ 1) + (hLip : ∀ s ∈ Icc (0 : ℝ) T, ∀ t ∈ Icc (0 : ℝ) T, ∀ x y, + |u s x-u t y| ≤ L*(|s-t|+|x-y|)) + (hXM : ∀ t∈Icc (0 : ℝ) T, AEStronglyMeasurable (X t) μ) + (hYM : ∀ N j, j≤N → AEStronglyMeasurable (Y N j) μ) + (hpaths : ∀ᵐ ω ∂μ, + ContinuousOn (fun t ↦ X t ω) (Icc (0 : ℝ) T) ∧ + IntervalIntegrable (fun s ↦ γ s*u s (X s ω)) volume 0 T ∧ + (∀ t ∈ Icc (0 : ℝ) T, + X t ω = W t ω + ∫ s in (0 : ℝ)..t, γ s*u s (X s ω)) ∧ X 0 ω = 0) + (hY0 : ∀ N ω, Y N 0 ω = 0) + (hY : ∀ N > 0, ∀ j < N, ∀ ω, + Y N (j+1) ω = Y N j ω + W (((j+1 : ℕ) : ℝ)*(T/N)) ω-W ((j : ℝ)*(T/N)) ω + + (T/N)*γ ((j : ℝ)*(T/N))*u ((j : ℝ)*(T/N)) (Y N j ω)) : + Tendsto (fun N ↦ ∫ ω, (meshMaxError T X Y N ω)^2 ∂μ) atTop (𝓝 (0 : ℝ)) := by + have hmeas : ∀ N, AEStronglyMeasurable (fun ω ↦ (meshMaxError T X Y N ω)^2) μ := by + intro N + exact (meshMaxError_measurable_on hT hXM hYM N).fun_pow 2 + have hbound : ∀ᶠ N in atTop, ∀ᵐ ω ∂μ, + ‖(meshMaxError T X Y N ω)^2‖ ≤ (2*T*γ T)^2 := by + filter_upwards [eventually_gt_atTop 0] with N hN + filter_upwards [hpaths] with ω hω + have hδ : 0 ≤ T/(N : ℝ) := div_nonneg hT (Nat.cast_nonneg _) + have horizon : (N : ℝ)*(T/N) = T := by field_simp + have H := driven_euler_uniform_bound (Y := fun j ↦ Y N j ω) hδ hT horizon hγ hγ0 hu hω.2.2.1 hω.2.2.2 + (hY0 N ω) (fun j hj ↦ hY N hN j hj ω) + have he : meshMaxError T X Y N ω ≤ 2*T*γ T := initialMax_le_iff.mpr H + rw [Real.norm_eq_abs, abs_of_nonneg (sq_nonneg _)] + exact pow_le_pow_left₀ (meshMaxError_nonneg T X Y N ω) he 2 + have hlim : ∀ᵐ ω ∂μ, Tendsto (fun N ↦ (meshMaxError T X Y N ω)^2) atTop (𝓝 (0 : ℝ)) := by + filter_upwards [hpaths] with ω hω + have H := driven_euler_uniform_convergence (Y := fun N j ↦ Y N j ω) hT hL hγ hγ0 hu hLip hω.1 hω.2.1 hω.2.2.1 + hω.2.2.2 (fun N ↦ hY0 N ω) (fun N hN j hj ↦ hY N hN j hj ω) + have hzero : Tendsto (fun N ↦ meshMaxError T X Y N ω) atTop (𝓝 (0 : ℝ)) := by + rw [Metric.tendsto_nhds] + intro ε hε + filter_upwards [H ε hε] with N hN + rw [Real.dist_eq,sub_zero,abs_of_nonneg (meshMaxError_nonneg T X Y N ω)] + exact initialMax_lt_iff.mpr hN + simpa using hzero.pow 2 + have H := tendsto_integral_filter_of_dominated_convergence (fun _ : Ω ↦ (2*T*γ T)^2) + (Eventually.of_forall hmeas) hbound (integrable_const _) hlim + simpa using H + +end SKValue + +end + +end OAI diff --git a/lean/OAI/Probability/SKValue/Equations/BackwardComparison.lean b/lean/OAI/Probability/SKValue/Equations/BackwardComparison.lean new file mode 100644 index 0000000000000000000000000000000000000000..a01a7c819e10050ae5fcb9719d2e866992e316e2 --- /dev/null +++ b/lean/OAI/Probability/SKValue/Equations/BackwardComparison.lean @@ -0,0 +1,224 @@ +import Mathlib +import OAI.Probability.SKValue.Equations.HalflineComparison +import OAI.Probability.SKValue.Equations.BackwardPolynomials + +namespace OAI + +section + +open Set Filter +open scoped Topology +namespace SKValue.BackwardBurgers +variable (F : SKValue.BackwardBurgers) + +lemma preserve_w (hinit : ∀ x,0≤x → F.jet 2 0 x≤0) {t x : ℝ} + (ht : 0≤t) (hx : 0≤x) : F.jet 2 t x≤0 := by + obtain ⟨B,hB,hb⟩ := F.bound 0 + obtain ⟨C,hC,hc⟩ := F.bound 1 + obtain ⟨M,hM,hm⟩ := F.bound 2 + have hh := halfline_parabolic_nonneg (T := t) (B := B) (C := 3*C) (M := M) ht hB hM + (u := fun s y ↦ -F.jet 2 s y) + (ut := fun s y ↦ -((1/2:ℝ)*F.jet 4 s y+3*F.jet 1 s y*F.jet 2 s y+F.jet 0 s y*F.jet 3 s y)) + (ux := fun s y ↦ -F.jet 3 s y) (uxx := fun s y ↦ -F.jet 4 s y) + (β := F.jet 0) (c := fun s y ↦ 3*F.jet 1 s y) + (F.continuous 2).neg.continuousOn + (by intro s hs y hy; exact (F.time2 s hs.1 y).neg) + (by intro s hs y; exact (F.space 2 s y).neg) + (by intro s hs y; exact (F.space 3 s y).neg) + (by intro y hy; exact neg_nonneg.mpr (hinit y hy)) + (by intro s hs; simp only [F.zero2,neg_zero,le_refl]) + (by intro s hs y hy; have hh := (le_abs_self _).trans (hm s y); linarith) + (by intro s hs y hy; exact (le_abs_self _).trans (hb s y)) + (by intro s hs y hy; have hh := (le_abs_self _).trans (hc s y); linarith) + (by intro s hs y hy; ring_nf; exact le_rfl) t ⟨ht,le_rfl⟩ x hx + linarith + +lemma preserve_k (hinit : ∀ x,0≤x → F.k 0 x≤0) {t x : ℝ} + (ht : 0≤t) (hx : 0≤x) : F.k t x≤0 := by + obtain ⟨B,hB,hb⟩ := F.bound 0 + obtain ⟨C,hC,hc⟩ := F.bound 1 + obtain ⟨M,hM,hm⟩ := F.k_bound + have hh := halfline_parabolic_nonneg (T := t) (B := B) (C := C) (M := M) ht hB hM + (u := fun s y ↦ -F.k s y) (ut := fun s y ↦ -F.kt s y) + (ux := fun s y ↦ -F.kx s y) (uxx := fun s y ↦ -F.kxx s y) + (β := F.jet 0) (c := F.jet 1) + F.k_continuous.neg.continuousOn + (by intro s hs y hy; exact (F.k_time hs.1 y).neg) + (by intro s hs y; exact (F.k_space s y).neg) + (by intro s hs y; exact (F.kx_space s y).neg) + (by intro y hy; exact neg_nonneg.mpr (hinit y hy)) + (by intro s hs; simp only [k_zero,neg_zero,le_refl]) + (by intro s hs y hy; have hh := (le_abs_self _).trans (hm s y); linarith) + (by intro s hs y hy; exact (le_abs_self _).trans (hb s y)) + (by intro s hs y hy; exact (le_abs_self _).trans (hc s y)) + (by intro s hs y hy; dsimp only [kt]; ring_nf; exact le_rfl) t ⟨ht,le_rfl⟩ x hx + linarith + +lemma preserve_n (hw : ∀ x,0≤x → F.jet 2 0 x≤0) + (hk : ∀ x,0≤x → F.k 0 x≤0) (hn : ∀ x,0≤x → 0≤F.n 0 x) + {t x : ℝ} (ht : 0≤t) (hx : 0≤x) : 0≤F.n t x := by + obtain ⟨B,hB,hb⟩ := F.bound 0 + obtain ⟨M,hM,hm⟩ := F.n_bound + apply halfline_parabolic_nonneg (T := t) (B := B) (C := 0) (M := M) ht hB hM + (u := F.n) (ut := F.nt) (ux := F.nx) (uxx := F.nxx) + (β := fun s y ↦ F.jet 0 s y-F.jet 1 s y/F.jet 0 s y) + (c := fun s y ↦ F.k s y/F.jet 0 s y) + F.n_continuous.continuousOn + (by intro s hs y hy; exact F.n_time hs.1 hy) + (by intro s hs y; exact F.n_space s y) + (by intro s hs y; exact F.nx_space s y) + hn + (by intro s hs; simp only [n_zero,le_refl]) + (by intro s hs y hy; exact (neg_le_abs _).trans (hm s y) |> neg_le_neg |>.trans_eq (neg_neg _)) + (by + intro s hs y hy + have hd := div_nonneg (F.slope_nonneg s y) (F.positive s y hy).le + have hh := (le_abs_self _).trans (hb s y) + linarith) + (by + intro s hs y hy + exact div_nonpos_of_nonpos_of_nonneg (F.preserve_k hk hs.1.le hy.le) (F.positive s y hy).le) + (by + intro s hs y hy + have hf := mul_nonneg (F.positive s y hy).le + (mul_nonneg_of_nonpos_of_nonpos (F.preserve_w hw hs.1.le hy.le) (F.preserve_k hk hs.1.le hy.le)) + dsimp only [nt] + nlinarith only [hf]) t ⟨ht,le_rfl⟩ x hx + +lemma preserve_shape (hw : ∀ x,0≤x → F.jet 2 0 x≤0) + (hk : ∀ x,0≤x → F.k 0 x≤0) (hn : ∀ x,0≤x → 0≤F.n 0 x) + {t x : ℝ} (ht : 0≤t) (hx : 0≤x) : + F.jet 2 t x≤0 ∧ F.k t x≤0 ∧ 0≤F.n t x := + ⟨F.preserve_w hw ht hx,F.preserve_k hk ht hx,F.preserve_n hw hk hn ht hx⟩ + +end SKValue.BackwardBurgers + +end + +section + +open Set Filter +open scoped Topology +namespace SKValue + +lemma halfline_parabolic_nonneg_linear {T B C M : ℝ} (hT : 0≤T) (hB : 0≤B) (hM : 0≤M) + {u ut ux uxx β c : ℝ → ℝ → ℝ} + (hc : ContinuousOn (fun p : ℝ×ℝ ↦ u p.1 p.2) ((Icc 0 T)×ˢ(Ici 0))) + (hdt : ∀ t∈Ioc (0 : ℝ) T, ∀ x∈Ioi (0 : ℝ), HasDerivAt (u · x) (ut t x) t) + (hdx : ∀ t∈Ioc (0 : ℝ) T, ∀ x, HasDerivAt (u t) (ux t x) x) + (hdxx : ∀ t∈Ioc (0 : ℝ) T, ∀ x, HasDerivAt (ux t) (uxx t x) x) + (hinit : ∀ x, 0≤x → 0≤u 0 x) + (hleft : ∀ t∈Icc (0 : ℝ) T, 0≤u t 0) + (hbound : ∀ t∈Icc (0 : ℝ) T, ∀ x, 0≤x → -M*(1+x)≤u t x) + (hβ : ∀ t∈Ioc (0 : ℝ) T, ∀ x, 0.sub stronglyMeasurable_const).aestronglyMeasurable + have heq := h.symm.integral_mul_eq_mul_integral hFm.aestronglyMeasurable hQm + simpa only [Function.comp_def, id_eq, Pi.mul_apply, h0, mul_zero] using heq + +end SKValue + +namespace SKValue +open MeasureTheory ProbabilityTheory Set Filter Finset +open scoped Topology NNReal ENNReal BigOperators + +noncomputable def driftDefect (T : ℝ) (N : ℕ) (γ : ℝ → ℝ) (u : ℝ → ℝ → ℝ) + (X W : ℝ → ℝ) : ℝ := + ∑ i : Fin N, |X (meshTime T N (i+1))-X (meshTime T N i)- + (W (meshTime T N (i+1))-W (meshTime T N i))- + stepSize T N*γ (meshTime T N i)*u (meshTime T N i) (X (meshTime T N i))| + +lemma driftDefect_nonneg (T : ℝ) (N : ℕ) (γ : ℝ → ℝ) (u : ℝ → ℝ → ℝ) + (X W : ℝ → ℝ) : 0≤driftDefect T N γ u X W := + Finset.sum_nonneg (fun _ _ ↦ abs_nonneg _) + +lemma driftDefect_error_bound {T L ε : ℝ} {N : ℕ} {u : ℝ → ℝ → ℝ} + {γ W X : ℝ → ℝ} (hT : 0≤T) (hN : 0] a) (𝓝 (deriv (V a) x)) := by + have hh := (h.heat_gradient_continuousOn a x a haT).mono_of_mem_nhdsWithin + (mem_of_superset (Ioo_mem_nhdsGT hab) (fun s hs ↦ ⟨ha.trans hs.1.le,hs.2.le.trans hb⟩)) + simpa only [sub_self,heat_zero] using hh.tendsto + have hI : Tendsto (fun q ↦ ∫ s in q..b, g s) (𝓝[>] a) (𝓝 (∫ s in a..b, g s)) := by + have hgI : IntegrableOn g (uIcc a b) volume := (intervalIntegrable_iff').mp hg + have hh := (intervalIntegral.continuousOn_primitive_interval_left hgI a + (by simp only [uIcc_of_le hab.le]; exact ⟨le_rfl,hab.le⟩)).mono_of_mem_nhdsWithin + (mem_of_superset (Ioo_mem_nhdsGT hab) (by intro s hs; simpa only [uIcc_of_le hab.le] using ⟨hs.1.le,hs.2.le⟩)) + exact hh.tendsto + have he : (fun q ↦ heat (q-a) (deriv (V q)) x) =ᶠ[𝓝[>] a] + (fun q ↦ heat (b-a) (deriv (V b)) x+∫ s in q..b, g s) := by + filter_upwards [Ioo_mem_nhdsGT hab] with q hq + have hh := h.heat_gradient_interval hm hγ ha hq.1 hq.2.le hb x + change _ = -(∫ s in q..b, g s) at hh + linarith + exact tendsto_nhds_unique hF ((tendsto_const_nhds.add hI).congr' he.symm) + +end SKValue + +end + +end OAI diff --git a/lean/OAI/Probability/SKValue/Equations/CoupledComparison.lean b/lean/OAI/Probability/SKValue/Equations/CoupledComparison.lean new file mode 100644 index 0000000000000000000000000000000000000000..708a1353a99366be2039e4ef7b0eb6ca4465b143 --- /dev/null +++ b/lean/OAI/Probability/SKValue/Equations/CoupledComparison.lean @@ -0,0 +1,249 @@ +import Mathlib +import OAI.Probability.SKValue.Evolution.LogCoshTerminal +import OAI.Probability.SKValue.Equations.BackwardComparison +import OAI.Probability.SKValue.Equations.ForwardComparison + +namespace OAI + +section + +open Set Filter +open scoped Topology +namespace SKValue +namespace BackwardBurgers +variable {T : ℝ} (B : BackwardBurgers) (F : ForwardBurgers T) (b : ℝ) +noncomputable def ratioJ (t x : ℝ) : ℝ := B.jet 0 (b-t) x*F.jet 1 t x-F.jet 0 t x*B.jet 1 (b-t) x +noncomputable def ratioJx (t x : ℝ) : ℝ := B.jet 0 (b-t) x*F.jet 2 t x-F.jet 0 t x*B.jet 2 (b-t) x +noncomputable def ratioJxx (t x : ℝ) : ℝ := B.jet 1 (b-t) x*F.jet 2 t x+ + B.jet 0 (b-t) x*F.jet 3 t x-F.jet 1 t x*B.jet 2 (b-t) x-F.jet 0 t x*B.jet 3 (b-t) x +noncomputable def ratioJt (t x : ℝ) : ℝ := (1/2:ℝ)*B.ratioJxx F b t x- + (B.jet 1 (b-t) x/B.jet 0 (b-t) x)*B.ratioJx F b t x- + (B.jet 1 (b-t) x+F.jet 1 t x)*B.ratioJ F b t x+ + (F.jet 0 t x/B.jet 0 (b-t) x)*B.n (b-t) x- + B.jet 0 (b-t) x*F.jet 0 t x*(B.jet 2 (b-t) x+F.jet 2 t x) +lemma ratioJ_space (t x : ℝ) : HasDerivAt (B.ratioJ F b t) (B.ratioJx F b t x) x := by + have hh := ((B.space 0 (b-t) x).mul (F.space 1 t x)).sub + ((F.space 0 t x).mul (B.space 1 (b-t) x)) + convert! hh using 1 + dsimp [ratioJ,ratioJx] + ring +lemma ratioJx_space (t x : ℝ) : HasDerivAt (B.ratioJx F b t) (B.ratioJxx F b t x) x := by + have hh := ((B.space 0 (b-t) x).mul (F.space 2 t x)).sub + ((F.space 0 t x).mul (B.space 2 (b-t) x)) + convert! hh using 1 + dsimp [ratioJx,ratioJxx] + ring +lemma ratioJ_time {t x : ℝ} (ht : t∈Ioc (0:ℝ) T) (hb : T.sub aestronglyMeasurable_const) + exact ((((h.smooth T ⟨hT,le_rfl⟩).continuous.comp_aestronglyMeasurable (hXM T ⟨hT,le_rfl⟩)).sub + ((h.smooth 0 ⟨le_rfl,hT⟩).continuous.comp_aestronglyMeasurable (hXM 0 ⟨le_rfl,hT⟩))).sub + (Finset.aestronglyMeasurable_fun_sum _ (fun i _ ↦ hprodA i))).sub + ((Finset.aestronglyMeasurable_fun_sum _ (fun i _ ↦ hprodQ i)).const_mul (1/2)) + +noncomputable def cubicEnvelopeMean (G K C : ℝ) : ℝ := + ∫ z : ℝ, cubicEnvelope G K C z ∂standardGaussian + +lemma pathGradientResidual_L1_bound + {Ω : Type*} [MeasurableSpace Ω] {μ : Measure Ω} [IsProbabilityMeasure μ] + {T K L Lu : ℝ} {N : ℕ} {γ : ℝ → ℝ} {u : ℝ → ℝ → ℝ} {X W : ℝ → Ω → ℝ} + {Z : Fin N → Ω → ℝ} + (hT : 0.mul_const + (cubicEnvelopeMean (γ T) K ((1/2+γ T)*L)))).add + ((hs.mul_const K).mul_const (γ T-γ 0)) + apply squeeze_zero' (Eventually.of_forall (fun N ↦ integral_nonneg (fun ω ↦ abs_nonneg _))) _ hLim + filter_upwards [eventually_gt_atTop 0] with N hN + exact (pathGradientResidual_L1_bound hT hT1 hN hLu h + (fun t ht x y ↦ by simpa only [sub_self,abs_zero,zero_add] using hLip t ht t ht x y) + hXM hWM (hZlaw N hN) (hZ N hN) (hpaths.mono (fun _ hh ↦ hh.2))).2 + +lemma weighted_pathGradientResidual_tendsto + {Ω : Type*} [MeasurableSpace Ω] {μ : Measure Ω} [IsProbabilityMeasure μ] + {T K L Lu H : ℝ} {γ : ℝ → ℝ} {u : ℝ → ℝ → ℝ} {X W : ℝ → Ω → ℝ} + {F : Ω → ℝ} {Z : (N : ℕ) → Fin N → Ω → ℝ} + (hT : 0.prodMk measurable_snd) + +lemma limitedControl_eq {W : BrownianSpace} (α : ℝ≥0 → W.Ω → ℝ) {s : ℝ} + (hs : s≤1) (ω : W.Ω) : limitedControl α s ω=α (Real.toNNReal s) ω := by + have hs' : Real.toNNReal s≤(1 : ℝ≥0) := Real.toNNReal_le_iff_le_coe.mpr hs + simp only [limitedControl, min_eq_left hs'] + +lemma Admissible.limited_bound {W : BrownianSpace} {t : ℝ} {α : ℝ≥0 → W.Ω → ℝ} + (hα : Admissible W t α) (s : ℝ) (ω : W.Ω) : |limitedControl α s ω|≤1 := hα.2 _ _ + +lemma OrderParameter.intervalIntegrable (γ : OrderParameter) : + IntervalIntegrable γ.coeff volume 0 1 := + (intervalIntegrable_iff_integrableOn_Ioc_of_le (by norm_num)).mpr γ.integrable + +lemma OrderParameter.shift_integrable (γ : OrderParameter) {t : ℝ} (ht : t∈Icc (0 : ℝ) 1) : + IntervalIntegrable (fun s ↦ γ.coeff (t+s)) volume 0 (1-t) := by + have hi := γ.intervalIntegrable.mono_set (show uIcc t 1⊆uIcc (0 : ℝ) 1 by + rw [uIcc_of_le ht.2, uIcc_of_le (by norm_num : (0 : ℝ)≤1)] + exact Icc_subset_Icc ht.1 le_rfl) + simpa only [sub_self] using hi.comp_add_left t + +end SKValue + +end + +end OAI diff --git a/lean/OAI/Probability/SKValue/Equations/DriftDefectUniformBound.lean b/lean/OAI/Probability/SKValue/Equations/DriftDefectUniformBound.lean new file mode 100644 index 0000000000000000000000000000000000000000..dea5379d36699a7460f07b2aa97864d03fbbbc3f --- /dev/null +++ b/lean/OAI/Probability/SKValue/Equations/DriftDefectUniformBound.lean @@ -0,0 +1,139 @@ +import Mathlib +import OAI.Probability.SKValue.Equations.AestronglyMeasurableInitialMax +import OAI.Probability.SKValue.Equations.BrownianIncrementIndepPast + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set +open scoped ENNReal NNReal BigOperators +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators Topology +open MeasureTheory ProbabilityTheory Set Filter +open scoped Topology BigOperators +open MeasureTheory ProbabilityTheory Set Filter +open scoped Topology ENNReal NNReal +open Filter Set +open scoped Topology BigOperators +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology +open MeasureTheory Set Filter +open scoped Topology BigOperators +open MeasureTheory Set Filter Finset +open scoped Topology BigOperators +namespace SKValue +open MeasureTheory ProbabilityTheory Set Filter Finset +open scoped Topology NNReal ENNReal BigOperators + +lemma driftDefect_uniform_bound {T : ℝ} {N : ℕ} {u : ℝ → ℝ → ℝ} + {γ W X : ℝ → ℝ} (hT : 0≤T) + (hγ : MonotoneOn γ (Icc (0 : ℝ) T)) (hγ0 : 0≤γ 0) + (hu : ∀ t∈Icc (0 : ℝ) T, ∀ x, |u t x|≤1) + (hint : IntervalIntegrable (fun s ↦ γ s*u s (X s)) volume 0 T) + (hX : ∀ t∈Icc (0 : ℝ) T, X t=W t+∫ s in (0 : ℝ)..t, γ s*u s (X s)) : + driftDefect T N γ u X W≤2*T*γ T := by + have ht0 : (0 : ℝ)∈Icc (0 : ℝ) T := ⟨le_rfl,hT⟩ + have htT : T∈Icc (0 : ℝ) T := ⟨hT,le_rfl⟩ + have hG : 0≤γ T := hγ0.trans (hγ ht0 htT hT) + by_cases hN : N=0 + · subst N + simp only [driftDefect, Fin.sum_univ_zero] + positivity + have hNpos : 0 exact h + | succ n ih => simpa only [iteratedDeriv_succ] using ih.deriv + +lemma BoundedSmoothFamily.duhamel_iteratedDeriv {T a b : ℝ} {γ : ℝ → ℝ} {F : ℝ → ℝ → ℝ} + (h : BoundedSmoothFamily T F) (hi : IntervalIntegrable γ volume a b) + (ha : 0≤a) (hab : a≤b) (hb : b≤T) (n : ℕ) : + _root_.iteratedDeriv n (duhamel a b γ F)=duhamel a b γ (fun t ↦ _root_.iteratedDeriv n (F t)) := by + induction n with + | zero => rfl + | succ n ih => + rw [iteratedDeriv_succ,ih,(h.iteratedDeriv n).duhamel_deriv hi ha hab hb] + simp only [iteratedDeriv_succ] + +end SKValue + +end + +end OAI diff --git a/lean/OAI/Probability/SKValue/Equations/FiniteRounded.lean b/lean/OAI/Probability/SKValue/Equations/FiniteRounded.lean new file mode 100644 index 0000000000000000000000000000000000000000..cfb6987f107d1ba7ae36263e5965e91029676d38 --- /dev/null +++ b/lean/OAI/Probability/SKValue/Equations/FiniteRounded.lean @@ -0,0 +1,193 @@ +import Mathlib +import OAI.Probability.SKValue.Equations.MemLpLinearCombination +import OAI.Probability.SKValue.Gaussian.CoordinateDependsBefore + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set +open scoped ENNReal NNReal BigOperators +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators Topology +open MeasureTheory ProbabilityTheory Set Filter +open scoped Topology BigOperators +open MeasureTheory ProbabilityTheory Set Filter +open scoped Topology ENNReal NNReal +namespace SKValue +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators + +noncomputable def finiteRounded {N : ℕ} (U : (Fin (N+1) → ℝ) → ℝ) : + (Fin (N+1) → ℝ) → ℝ := + fun z ↦ Real.sign (U z+2*cdf standardGaussian (coordinate N N z)-1) + +noncomputable def finiteRawMartingale {N : ℕ} (δ : ℝ) + (H : Fin N → (Fin (N+1) → ℝ) → ℝ) : (Fin (N+1) → ℝ) → ℝ := + fun z ↦ ∑ i : Fin N, Real.sqrt δ * H i z * coordinate N i z + +lemma finiteRawMartingale_eq_normalized {N : ℕ} {δ : ℝ} + {H : Fin N → (Fin (N+1) → ℝ) → ℝ} + (hpos : ∀ i, 0 < ∫ z, (H i z)^2 ∂gaussianProduct (Fin (N+1))) : + finiteRawMartingale δ H = fun z ↦ ∑ i : Fin N, + (Real.sqrt δ / predictableNormalizer (H i) (gaussianProduct (Fin (N+1)))) * + normalizedIncrement (H i) (coordinate N i) (gaussianProduct (Fin (N+1))) z := by + ext z + apply Finset.sum_congr rfl + intro i _ + have hc := ne_of_gt (predictableNormalizer_pos (hpos i)) + simp only [normalizedIncrement] + field_simp + +lemma finiteRawMartingale_memLp {N : ℕ} {δ : ℝ} + {H : Fin N → (Fin (N+1) → ℝ) → ℝ} + (hm : ∀ i, Measurable (H i)) (hp : ∀ i : Fin N, DependsBefore (i : ℕ) (H i)) + (hH : ∀ i, MemLp (H i) 2 (gaussianProduct (Fin (N+1)))) + (hpos : ∀ i, 0 < ∫ z, (H i z)^2 ∂gaussianProduct (Fin (N+1))) : + MemLp (finiteRawMartingale δ H) 2 (gaussianProduct (Fin (N+1))) := by + rw [finiteRawMartingale_eq_normalized hpos] + exact memLp_linearCombination (fun i ↦ normalizedIncrement_memLp_two (hH i) + (coordinate_hasLaw N i) ((hp i).independent (by omega) (hm i))) _ + +lemma finiteRawMartingale_normalized_coefficient {N : ℕ} {δ : ℝ} + {H : Fin N → (Fin (N+1) → ℝ) → ℝ} + (hm : ∀ i, Measurable (H i)) (hp : ∀ i : Fin N, DependsBefore (i : ℕ) (H i)) + (hH : ∀ i, MemLp (H i) 2 (gaussianProduct (Fin (N+1)))) + (hpos : ∀ i, 0 < ∫ z, (H i z)^2 ∂gaussianProduct (Fin (N+1))) (j : Fin N) : + (∫ z, finiteRawMartingale δ H z * + normalizedIncrement (H j) (coordinate N j) (gaussianProduct (Fin (N+1))) z + ∂gaussianProduct (Fin (N+1))) = + Real.sqrt δ / predictableNormalizer (H j) (gaussianProduct (Fin (N+1))) := by + rw [finiteRawMartingale_eq_normalized hpos] + exact orthogonal_linearCombination_coefficient + (fun i ↦ normalizedIncrement_memLp_two (hH i) (coordinate_hasLaw N i) + ((hp i).independent (by omega) (hm i))) (normalized_family_orthonormal hm hp hpos) _ j + +lemma finiteRawMartingale_coordinate_coefficient {N : ℕ} {δ : ℝ} + {H : Fin N → (Fin (N+1) → ℝ) → ℝ} + (hm : ∀ i, Measurable (H i)) (hp : ∀ i : Fin N, DependsBefore (i : ℕ) (H i)) + (hH : ∀ i, MemLp (H i) 2 (gaussianProduct (Fin (N+1)))) + (hpos : ∀ i, 0 < ∫ z, (H i z)^2 ∂gaussianProduct (Fin (N+1))) (j : Fin N) : + (∫ z, finiteRawMartingale δ H z * coordinate N j z ∂gaussianProduct (Fin (N+1))) = + Real.sqrt δ * ∫ z, H j z ∂gaussianProduct (Fin (N+1)) := by + rw [finiteRawMartingale_eq_normalized hpos, + integral_linearCombination_mul + (fun i ↦ normalizedIncrement_memLp_two (hH i) (coordinate_hasLaw N i) + ((hp i).independent (by omega) (hm i))) + (gaussian_memLp (coordinate_hasLaw N j) 2 (by norm_num))] + simp_rw [normalized_coordinate_pair hm hp] + simp only [mul_ite, mul_zero, Finset.sum_ite_eq', Finset.mem_univ, ite_true] + have hc := ne_of_gt (predictableNormalizer_pos (hpos j)) + field_simp + +lemma finite_coefficient_L2_errors {N : ℕ} {δ : ℝ} + {H : Fin N → (Fin (N+1) → ℝ) → ℝ} {U : (Fin (N+1) → ℝ) → ℝ} + (hm : ∀ i, Measurable (H i)) (hp : ∀ i : Fin N, DependsBefore (i : ℕ) (H i)) + (hH : ∀ i, MemLp (H i) 2 (gaussianProduct (Fin (N+1)))) + (hpos : ∀ i, 0 < ∫ z, (H i z)^2 ∂gaussianProduct (Fin (N+1))) + (hUm : Measurable U) (hUp : DependsBefore N U) (hUb : ∀ z, |U z|≤1) : + (∑ i : Fin N, ((∫ z, finiteRounded U z * + normalizedIncrement (H i) (coordinate N i) (gaussianProduct (Fin (N+1))) z + ∂gaussianProduct (Fin (N+1))) - + Real.sqrt δ / predictableNormalizer (H i) (gaussianProduct (Fin (N+1))))^2) ≤ + ∫ z, (U z-finiteRawMartingale δ H z)^2 ∂gaussianProduct (Fin (N+1)) ∧ + (∑ i : Fin N, ((∫ z, finiteRounded U z * coordinate N i z ∂gaussianProduct (Fin (N+1))) - + Real.sqrt δ * ∫ z, H i z ∂gaussianProduct (Fin (N+1)))^2) ≤ + ∫ z, (U z-finiteRawMartingale δ H z)^2 ∂gaussianProduct (Fin (N+1)) := by + let : IsProbabilityMeasure (gaussianProduct (Fin (N+1))) := gaussianProduct_probability _ + have hU : MemLp U 2 (gaussianProduct (Fin (N+1))) := + MemLp.of_bound hUm.aestronglyMeasurable 1 (Eventually.of_forall (by simpa only [Real.norm_eq_abs] using hUb)) + have hg : ∀ i, MemLp (normalizedIncrement (H i) (coordinate N i) + (gaussianProduct (Fin (N+1)))) 2 (gaussianProduct (Fin (N+1))) := fun i ↦ + normalizedIncrement_memLp_two (hH i) (coordinate_hasLaw N i) ((hp i).independent (by omega) (hm i)) + have hM := finiteRawMartingale_memLp (δ := δ) hm hp hH hpos + have hA : ∀ i : Fin N, (∫ z, finiteRounded U z * + normalizedIncrement (H i) (coordinate N i) (gaussianProduct (Fin (N+1))) z + ∂gaussianProduct (Fin (N+1))) = + ∫ z, U z * normalizedIncrement (H i) (coordinate N i) (gaussianProduct (Fin (N+1))) z + ∂gaussianProduct (Fin (N+1)) := fun i ↦ + finite_rounding_coefficient hUm (measurable_normalizedIncrement (hm i)) + ((hg i).integrable (by norm_num)) hUb hUp + ((normalizedIncrement_dependsBefore (by omega) (hp i)).mono (by omega)) + have hB : ∀ i : Fin N, (∫ z, finiteRounded U z * coordinate N i z + ∂gaussianProduct (Fin (N+1))) = ∫ z, U z * coordinate N i z + ∂gaussianProduct (Fin (N+1)) := fun i ↦ + finite_rounding_coefficient hUm (measurable_coordinate N i) + ((gaussian_memLp (coordinate_hasLaw N i) 2 (by norm_num)).integrable (by norm_num)) hUb hUp + (coordinate_dependsBefore (by omega) i.isLt) + constructor + · have h := finite_projection_error hg (normalized_family_orthonormal hm hp hpos) hU hM + simpa only [finiteRawMartingale_normalized_coefficient hm hp hH hpos, hA] using h + · have h := finite_projection_error + (fun i : Fin N ↦ gaussian_memLp (coordinate_hasLaw N i) 2 (by norm_num)) + (coordinate_family_orthonormal N) hU hM + simpa only [finiteRawMartingale_coordinate_coefficient hm hp hH hpos, hB] using h + +lemma finiteRounded_measurable {N : ℕ} {U : (Fin (N+1) → ℝ) → ℝ} + (hU : Measurable U) : Measurable (finiteRounded U) := by + apply measurable_real_sign.comp + exact (hU.add ((((monotone_cdf standardGaussian).measurable).comp + (measurable_coordinate N N)).const_mul 2)).sub_const 1 + +lemma finiteRounded_memLp {N : ℕ} {U : (Fin (N+1) → ℝ) → ℝ} + (hU : Measurable U) : MemLp (finiteRounded U) 2 (gaussianProduct (Fin (N+1))) := by + let : IsProbabilityMeasure (gaussianProduct (Fin (N+1))) := gaussianProduct_probability _ + exact MemLp.of_bound (finiteRounded_measurable hU).aestronglyMeasurable 1 + (Eventually.of_forall (fun z ↦ by + simpa only [Real.norm_eq_abs, finiteRounded] using abs_real_sign_le_one + (U z+2*cdf standardGaussian (coordinate N N z)-1))) + +lemma finiteRounded_square_le_one {N : ℕ} {U : (Fin (N+1) → ℝ) → ℝ} + (hU : Measurable U) : + (∫ z, (finiteRounded U z)^2 ∂gaussianProduct (Fin (N+1))) ≤ 1 := by + let : IsProbabilityMeasure (gaussianProduct (Fin (N+1))) := gaussianProduct_probability _ + calc + _ ≤ ∫ _ : Fin (N+1) → ℝ, (1 : ℝ) ∂gaussianProduct (Fin (N+1)) := by + apply integral_mono (finiteRounded_memLp hU).integrable_sq (integrable_const 1) + intro z + exact (sq_le_one_iff_abs_le_one _).2 (abs_real_sign_le_one _) + _ = _ := by simp + +lemma finiteRounded_coordinate_norms {N : ℕ} {U : (Fin (N+1) → ℝ) → ℝ} + (hU : Measurable U) : + (∑ i : Fin N, (∫ z, finiteRounded U z * coordinate N i z + ∂gaussianProduct (Fin (N+1)))^2) ≤ 1 ∧ + |∫ z, finiteRounded U z * coordinate N N z ∂gaussianProduct (Fin (N+1))| ≤ 1 := by + have hF := finiteRounded_memLp hU + constructor + · exact (finite_bessel (fun i : Fin N ↦ gaussian_memLp (coordinate_hasLaw N i) 2 (by norm_num)) + (coordinate_family_orthonormal N) hF).trans (finiteRounded_square_le_one hU) + · have h := finite_bessel (g := fun _ : Unit ↦ coordinate N N) + (fun _ ↦ gaussian_memLp (coordinate_hasLaw N N) 2 (by norm_num)) + (fun _ _ ↦ by simpa only [← pow_two, ite_true] using gaussian_second_moment (coordinate_hasLaw N N)) hF + simp only [Fintype.sum_unique] at h + exact (sq_le_one_iff_abs_le_one _).mp (h.trans (finiteRounded_square_le_one hU)) + +lemma sqrt_div_normalizer_sq {Ω : Type*} [MeasurableSpace Ω] {μ : Measure Ω} + {H : Ω → ℝ} {δ : ℝ} (hδ : 0≤δ) : + (Real.sqrt δ / predictableNormalizer H μ)^2 = δ * ∫ z, (H z)^2 ∂μ := by + simp only [predictableNormalizer, div_inv_eq_mul, mul_pow, Real.sq_sqrt hδ, + Real.sq_sqrt (integral_nonneg (fun z ↦ sq_nonneg (H z)))] + +lemma sqrt_div_normalizer_bound {Ω : Type*} [MeasurableSpace Ω] {μ : Measure Ω} + [IsProbabilityMeasure μ] {H : Ω → ℝ} {δ K : ℝ} + (hH : MemLp H 2 μ) (hK : 0≤K) (hbound : ∀ᵐ z ∂μ, |H z|≤K) : + |Real.sqrt δ / predictableNormalizer H μ| ≤ Real.sqrt δ * K := by + have hi : (∫ z, (H z)^2 ∂μ)≤K^2 := by + calc + _ ≤ ∫ _ : Ω, K^2 ∂μ := by + apply integral_mono_ae hH.integrable_sq (integrable_const _) + filter_upwards [hbound] with z hz + simpa only [sq_abs] using (sq_le_sq₀ (abs_nonneg _) hK).2 hz + _ = _ := by simp + simp only [predictableNormalizer, div_inv_eq_mul, abs_mul, abs_of_nonneg (Real.sqrt_nonneg _)] + exact mul_le_mul_of_nonneg_left (by simpa only [Real.sqrt_sq hK] using Real.sqrt_le_sqrt hi) + (Real.sqrt_nonneg δ) + +end SKValue + +open Filter Set +open scoped Topology BigOperators + +end + +end OAI diff --git a/lean/OAI/Probability/SKValue/Equations/FirstMomentPerturbation.lean b/lean/OAI/Probability/SKValue/Equations/FirstMomentPerturbation.lean new file mode 100644 index 0000000000000000000000000000000000000000..4f94c17baeebf79f7e2da42b41025b98e75f92f0 --- /dev/null +++ b/lean/OAI/Probability/SKValue/Equations/FirstMomentPerturbation.lean @@ -0,0 +1,119 @@ +import Mathlib +import OAI.Probability.SKValue.Equations.ShiftedPairing +import OAI.Probability.SKValue.Gaussian.CoupledCoordinates + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set +open scoped ENNReal NNReal BigOperators +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators Topology +open MeasureTheory ProbabilityTheory Set Filter +open scoped Topology BigOperators +open MeasureTheory ProbabilityTheory Set Filter +open scoped Topology ENNReal NNReal +open Filter Set +open scoped Topology BigOperators +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology +open MeasureTheory Set Filter +open scoped Topology BigOperators +open MeasureTheory Set Filter Finset +open scoped Topology BigOperators +namespace SKValue +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology BigOperators + +lemma first_moment_perturbation {Ω : Type*} [MeasurableSpace Ω] {μ : Measure Ω} + [IsProbabilityMeasure μ] {f g e : Ω → ℝ} {L : ℝ} + (hf : MemLp f 2 μ) (hg : MemLp g 2 μ) (he : MemLp e 2 μ) (hL : 0≤L) + (hbound : ∀ᵐ ω ∂μ, |f ω-g ω|≤L*|e ω|) : + |(∫ ω, f ω ∂μ)-(∫ ω, g ω ∂μ)|≤L*Real.sqrt (∫ ω, (e ω)^2 ∂μ) := by + have hfi := hf.integrable (by norm_num : (1 : ENNReal)≤2) + have hgi := hg.integrable (by norm_num : (1 : ENNReal)≤2) + have hei := he.integrable (by norm_num : (1 : ENNReal)≤2) + calc + _ = |∫ ω, f ω-g ω ∂μ| := by rw [integral_sub hfi hgi] + _ ≤ ∫ ω, |f ω-g ω| ∂μ := abs_integral_le_integral_abs + _ ≤ ∫ ω, L*|e ω| ∂μ := integral_mono_ae (hfi.sub hgi).abs (hei.abs.const_mul L) hbound + _ = L*(∫ ω, |e ω| ∂μ) := integral_const_mul _ _ + _ ≤ _ := mul_le_mul_of_nonneg_left (integral_abs_le_sqrt_integral_sq he) hL + +lemma coupled_mesh_error_memLp {Ω : Type*} [MeasurableSpace Ω] {μ : Measure Ω} + [IsFiniteMeasure μ] {B : ℝ≥0 → Ω → ℝ} (hB : IsPreBrownianReal B μ) + {X : ℝ → Ω → ℝ} {T K L : ℝ} {γ : ℝ → ℝ} {u : ℝ → ℝ → ℝ} + (hT : 0 exact hB.lower hM hc.le hcM + | cons p l ih => + obtain ⟨hp,hl⟩ := List.pairwise_cons.mp hl + have hcp : c≤(p.2:ℝ) := hlow p (by simp) + have hp0 : 0<(p.2:ℝ) := hc.trans_le hcp + have hpM : (p.2:ℝ)≤M := hupp p (by simp) + have hlo : ∀ q∈l,c≤(q.2:ℝ) := fun q hq ↦ hlow q (by simp [hq]) + have hup : ∀ q∈l,(q.2:ℝ)≤M := fun q hq ↦ hupp q (by simp [hq]) + change BackwardShape c (patchTime (p.1:ℝ) _ _ t) + by_cases ht : t≤(p.1:ℝ) + · rw [patchTime_left _ _ ht] + have hs := ih hp0 hpM hl (fun q hq ↦ by exact_mod_cast hp q hq) hup 0 + have hψ := hA.profile_evolution l + have hsm := hψ.slices 0 ⟨le_rfl,profileTime_nonneg l⟩ + exact (hs.evolve hsm hp0 (sub_nonneg.mpr ht)).lower hp0 hc.le hcp + · rw [patchTime_right _ _ (lt_of_not_ge ht)] + exact ih hc hcM hl hlo hup _ + +end SKValue + +end + +section + +open Set Filter MeasureTheory +open scoped Topology NNReal +namespace SKValue +lemma profileValue_zero_cons (A:ℝ → ℝ) (p:ℝ≥0 × ℝ≥0) (l:HeatProfile) : + profileValue A (p::l) 0=coleHopf p.2 p.1 (profileValue A l 0) := by + simp only [profileValue,patchTime_left _ _ p.1.coe_nonneg,sub_zero] +lemma profileResponse_zero_cons (A f:ℝ → ℝ) (p:ℝ≥0 × ℝ≥0) (l:HeatProfile) : + profileResponse A f (p::l) 0=responseJet p.2 (profileValue A l 0) (profileResponse A f l 0) 0 p.1 := by + simp only [profileResponse,patchTime_left _ _ p.1.coe_nonneg,sub_zero] + +lemma ForwardShape.profile {A:ℝ → ℝ} {C d:ℝ} (hA:SmoothTerminal A) + (hB:BackwardShape C A) (hd:0 + let E:=D.jump hA hB.even (C-d) (sub_nonneg.mpr hdC) + refine ⟨E,hF.jump hA (hB.lower (hd.trans_le hdC) hd.le hdC) hd hdC,?_⟩ + intro f hf + apply integral_congr_ae + filter_upwards [] with x + rw [ForwardDensityData.jump_density _ _ _ hdC] + rfl + | cons p l ih => + have hdp:d≤(p.2:ℝ) := hlo p (by simp) + have hp:0<(p.2:ℝ) := hd.trans_le hdp + have hpC:(p.2:ℝ)≤C := hup p (by simp) + obtain ⟨hpl,hll⟩:=List.pairwise_cons.mp hl + have hpl':∀ q∈l,(p.2:ℝ)≤(q.2:ℝ) := fun q hq ↦ by exact_mod_cast hpl q hq + have hup':∀ q∈l,(q.2:ℝ)≤C := fun q hq ↦ hup q (by simp [hq]) + let B:=profileValue A l 0 + have hBs:SmoothTerminal B := (hA.profile_evolution l).slices 0 ⟨le_rfl,profileTime_nonneg l⟩ + have hBb:BackwardShape p.2 B := hB.profile hA (hd.trans_le hdC) hp hpC hll hpl' hup' 0 + let V:=profileValue A (p::l) 0 + have hVs:SmoothTerminal V := (hA.profile_evolution (p::l)).slices 0 ⟨le_rfl,profileTime_nonneg _⟩ + have hVb:BackwardShape d V := hB.profile hA (hd.trans_le hdC) hd hdC hl hlo hup 0 + let D':=D.jump hVs hVb.even ((p.2:ℝ)-d) (sub_nonneg.mpr hdp) + have hF':ForwardShape p.2 V D' := hF.jump hVs hVb hd hdp + have hstart:ForwardShape p.2 (coleHopf p.2 p.1 B) D' := by + simpa only [V,profileValue_zero_cons] using hF' + have hend:ForwardShape p.2 B (D'.evolve p.1 p.1.coe_nonneg) := + hstart.evolve hBs hBb hp p.1.coe_nonneg + obtain ⟨E,hE,hpair⟩:=ih hp hpC hll hpl' hup' hend + refine ⟨E,hE,?_⟩ + intro f hf + have htest:BoundedSmooth (profileResponse A f l 0) := + (hA.linear_profile hf l).slices 0 ⟨le_rfl,profileTime_nonneg l⟩ + calc + _ = ∫ x,(Real.exp ((p.2:ℝ)*V x)*D'.weight x)*profileResponse A f (p::l) 0 x := by + apply integral_congr_ae + filter_upwards [] with x + rw [ForwardDensityData.jump_density _ _ _ hdp] + _ = ∫ x,(Real.exp ((p.2:ℝ)*B x)*(D'.evolve p.1 p.1.coe_nonneg).weight x)*profileResponse A f l 0 x := by + rw [profileResponse_zero_cons] + change (∫ x,(Real.exp ((p.2:ℝ)*profileValue A (p::l) 0 x)*D'.weight x)*_) = _ + rw [profileValue_zero_cons] + exact D'.response_pairing hBs htest hp p.1.coe_nonneg + _ = _ := hpair f hf + +lemma BackwardShape.profile_density {A:ℝ → ℝ} {C:ℝ} (hA:SmoothTerminal A) + (hB:BackwardShape C A) {p:ℝ≥0 × ℝ≥0} {l:HeatProfile} + (hp:0<(p.2:ℝ)) (ht:0<(p.1:ℝ)) + (hl:(p::l).Pairwise (fun p q ↦ p.2≤q.2)) (hup:∀ q∈p::l,(q.2:ℝ)≤C) : + ∃ E:ForwardDensityData,ForwardShape C A E ∧ ∀ f:ℝ → ℝ,BoundedSmooth f → + profileResponse A f (p::l) 0 0=Real.exp (-((p.2:ℝ)*profileValue A (p::l) 0 0))* + (∫ x,(Real.exp (C*A x)*E.weight x)*f x) := by + obtain ⟨hpl,hll⟩:=List.pairwise_cons.mp hl + have hpC:(p.2:ℝ)≤C := hup p (by simp) + have hpl':∀ q∈l,(p.2:ℝ)≤(q.2:ℝ) := fun q hq ↦ by exact_mod_cast hpl q hq + have hup':∀ q∈l,(q.2:ℝ)≤C := fun q hq ↦ hup q (by simp [hq]) + have hBs:SmoothTerminal (profileValue A l 0) := (hA.profile_evolution l).slices 0 ⟨le_rfl,profileTime_nonneg l⟩ + have hBb:BackwardShape p.2 (profileValue A l 0) := hB.profile hA (hp.trans_le hpC) hp hpC hll hpl' hup' 0 + have hF:=hBb.gaussian_forwardShape hBs ht + obtain ⟨E,hE,hpair⟩:=hF.profile hA hB hp hpC hll hpl' hup' + refine ⟨E,hE,?_⟩ + intro f hf + rw [profileResponse_zero_cons,profileValue_zero_cons] + have htest:BoundedSmooth (profileResponse A f l 0) := (hA.linear_profile hf l).slices 0 ⟨le_rfl,profileTime_nonneg l⟩ + rw [first_response_density hBs htest hp ht,hpair f hf] +end SKValue + +end + +end OAI diff --git a/lean/OAI/Probability/SKValue/Equations/GradientErrorConstant.lean b/lean/OAI/Probability/SKValue/Equations/GradientErrorConstant.lean new file mode 100644 index 0000000000000000000000000000000000000000..2947370d3e4d14efdb4feeee0bd36244b3b57f47 --- /dev/null +++ b/lean/OAI/Probability/SKValue/Equations/GradientErrorConstant.lean @@ -0,0 +1,244 @@ +import Mathlib +import OAI.Probability.SKValue.Equations.GradientStrip + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set +open scoped ENNReal NNReal BigOperators +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators Topology +open MeasureTheory ProbabilityTheory Set Filter +open scoped Topology BigOperators +namespace SKValue +open MeasureTheory ProbabilityTheory Set Filter +open scoped Topology BigOperators + +lemma gaussian_mesh_bound_linear {δ T n K V M J : ℝ} (hδ : 0≤δ) (hδ1 : δ≤1) + (hmesh : n*δ=T) : + 2*((δ/2)^2*n*K^2*V)+4*(δ*Real.sqrt δ)^2*n^2*M+4*(δ*K*J)^2 ≤ + δ*(T/2*K^2*V+4*T^2*M+4*K^2*J^2) := by + have hfirst : 2*((δ/2)^2*n*K^2*V)=δ*(T/2*K^2*V) := by rw [← hmesh]; ring + have hsecond : 4*(δ*Real.sqrt δ)^2*n^2*M=δ*(4*T^2*M) := by + rw [mul_pow, Real.sq_sqrt hδ, ← hmesh] + ring + have hd2 : δ^2≤δ := by nlinarith + have hthird := mul_le_mul_of_nonneg_right hd2 (show 0≤4*K^2*J^2 by positivity) + rw [hfirst, hsecond] + nlinarith + +noncomputable def gradientErrorConstant (T K L : ℝ) (γ : ℝ → ℝ) : ℝ := + T/2*K^2*gaussianSquareVariance+4*T^2*cubicEnvelopeMoment (γ T) K ((1/2+γ T)*L)+ + 4*K^2*(γ T-γ 0)^2 + +lemma gradientMeshError_bound_linear {T K L : ℝ} {γ : ℝ → ℝ} {u : ℝ → ℝ → ℝ} + (hT : 0 rw [h] <;> norm_num + +lemma uniform_rounding_mean {a : ℝ} (ha : |a|≤1) : + ∫ z in Ioc (0 : ℝ) 1, Real.sign (a+2*z-1) = a := by + let r : ℝ := (1-a)/2 + have hr0 : 0≤r := by dsimp [r]; linarith [(abs_le.mp ha).2] + have hr1 : r≤1 := by dsimp [r]; linarith [(abs_le.mp ha).1] + have hi : Iic r ∩ Ioc (0 : ℝ) 1 = Ioc 0 r := by + ext z + constructor + · exact fun hz ↦ ⟨hz.2.1,hz.1⟩ + · exact fun hz ↦ ⟨hz.2,hz.1,hz.2.trans hr1⟩ + have heq : (fun z ↦ Real.sign (a+2*z-1)) =ᵐ[volume.restrict (Ioc (0 : ℝ) 1)] + (fun z ↦ 1 - 2 * (Iic r).indicator (fun _ ↦ (1 : ℝ)) z) := by + filter_upwards [(volume.restrict (Ioc (0 : ℝ) 1)).ae_ne r] with z hz + rcases lt_or_gt_of_ne hz with hzr | hrz + · rw [Real.sign_of_neg (by dsimp [r] at hzr; linarith), indicator_of_mem (show z ∈ Iic r from hzr.le)] + norm_num + · rw [Real.sign_of_pos (by dsimp [r] at hrz; linarith), indicator_of_notMem (show z ∉ Iic r from not_le_of_gt hrz)] + norm_num + rw [integral_congr_ae heq, + integral_sub (integrable_const _) (((integrable_const (1 : ℝ)).indicator measurableSet_Iic).const_mul 2), + integral_const, integral_const_mul, integral_indicator_const _ measurableSet_Iic, + measureReal_restrict_apply measurableSet_Iic, hi, Real.volume_real_Ioc] + simp only [measureReal_restrict_apply MeasurableSet.univ, + univ_inter, Real.volume_real_Ioc, sub_zero, max_eq_left hr0] + norm_num + dsimp [r] + ring + +lemma gaussian_rounding_mean {a : ℝ} (ha : |a|≤1) : + ∫ z, Real.sign (a+2*cdf (gaussianReal 0 1) z-1) ∂gaussianReal 0 1 = a := by + have hm : Measurable (fun z : ℝ ↦ Real.sign (a+2*z-1)) := + measurable_real_sign.comp (by fun_prop) + have H := standardGaussian_cdf_hasLaw_uniform.integral_comp hm.aestronglyMeasurable + exact H.trans (uniform_rounding_mean ha) + +lemma product_rounding_integral {Ω : Type*} [MeasurableSpace Ω] {μ : Measure Ω} + [IsFiniteMeasure μ] {U K : Ω → ℝ} + (hU : Measurable U) (hbound : ∀ᵐ ω ∂μ, |U ω| ≤ 1) (hK : Integrable K μ) : + ∫ p : Ω × ℝ, Real.sign (U p.1 + 2*cdf (gaussianReal 0 1) p.2-1)*K p.1 + ∂μ.prod (gaussianReal 0 1) = ∫ ω, U ω*K ω ∂μ := by + have hm : Measurable (fun p : Ω × ℝ ↦ + Real.sign (U p.1+2*cdf (gaussianReal 0 1) p.2-1)) := by + apply measurable_real_sign.comp + have hc : Measurable (fun p : Ω × ℝ ↦ cdf (gaussianReal 0 1) p.2) := + ((monotone_cdf _).measurable).comp measurable_snd + exact ((hU.comp measurable_fst).add (hc.const_mul 2)).sub_const 1 + have hi : Integrable (fun p : Ω × ℝ ↦ + Real.sign (U p.1+2*cdf (gaussianReal 0 1) p.2-1)*K p.1) + (μ.prod (gaussianReal 0 1)) := by + apply (hK.comp_fst _).bdd_mul hm.aestronglyMeasurable + exact Filter.Eventually.of_forall (fun p ↦ by + simpa only [Real.norm_eq_abs] using abs_real_sign_le_one (U p.1+2*cdf (gaussianReal 0 1) p.2-1)) + rw [integral_prod _ hi] + apply integral_congr_ae + filter_upwards [hbound] with ω hω + rw [integral_mul_const, gaussian_rounding_mean hω] + +lemma independent_rounding_integral {Ω : Type*} [MeasurableSpace Ω] {μ : Measure Ω} + [IsProbabilityMeasure μ] {U K Z : Ω → ℝ} + (hU : Measurable U) (hK : Measurable K) (hKi : Integrable K μ) + (hbound : ∀ᵐ ω ∂μ, |U ω|≤1) (hZ : HasLaw Z (gaussianReal 0 1) μ) + (hind : IndepFun (fun ω ↦ (U ω,K ω)) Z μ) : + (∫ ω, Real.sign (U ω+2*cdf (gaussianReal 0 1) (Z ω)-1)*K ω ∂μ) = + ∫ ω, U ω*K ω ∂μ := by + let V : Ω → ℝ × ℝ := fun ω ↦ (U ω,K ω) + let ν : Measure (ℝ × ℝ) := μ.map V + have hV : Measurable V := hU.prodMk hK + have hLaw : HasLaw V ν μ := ⟨hV.aemeasurable, rfl⟩ + have hJoint := hind.hasLaw_prod hLaw hZ + have hKi' : Integrable (Prod.snd : ℝ × ℝ → ℝ) ν := + (integrable_map_measure measurable_snd.aestronglyMeasurable hV.aemeasurable).mpr hKi + have hbound' : ∀ᵐ p : ℝ × ℝ ∂ν, |p.1|≤1 := by + apply (ae_map_iff hV.aemeasurable (measurableSet_le measurable_fst.abs measurable_const)).mpr + exact hbound + have hm : Measurable (fun p : (ℝ × ℝ) × ℝ ↦ + Real.sign (p.1.1+2*cdf (gaussianReal 0 1) p.2-1)*p.1.2) := by + have hc : Measurable (fun p : (ℝ × ℝ) × ℝ ↦ cdf (gaussianReal 0 1) p.2) := + ((monotone_cdf _).measurable).comp measurable_snd + exact (measurable_real_sign.comp + (((measurable_fst.comp measurable_fst).add (hc.const_mul 2)).sub_const 1)).mul + (measurable_snd.comp measurable_fst) + calc + _ = ∫ p : (ℝ × ℝ) × ℝ, Real.sign (p.1.1+2*cdf (gaussianReal 0 1) p.2-1)*p.1.2 + ∂ν.prod (gaussianReal 0 1) := hJoint.integral_comp hm.aestronglyMeasurable + _ = ∫ p : ℝ × ℝ, p.1*p.2 ∂ν := product_rounding_integral measurable_fst hbound' hKi' + _ = _ := (hLaw.integral_comp (measurable_fst.mul measurable_snd).aestronglyMeasurable).symm + +end SKValue + +end + +end OAI diff --git a/lean/OAI/Probability/SKValue/Equations/GradientStrip.lean b/lean/OAI/Probability/SKValue/Equations/GradientStrip.lean new file mode 100644 index 0000000000000000000000000000000000000000..03f1d7de47dfb39c77bd99b63dbfb3b04a748287 --- /dev/null +++ b/lean/OAI/Probability/SKValue/Equations/GradientStrip.lean @@ -0,0 +1,139 @@ +import Mathlib +import OAI.Probability.SKValue.Equations.ThirdOrderRemainderBound +import OAI.Probability.SKValue.Equations.SumStepsSub + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set +open scoped ENNReal NNReal BigOperators +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators Topology +open MeasureTheory ProbabilityTheory Set Filter +open scoped Topology BigOperators +namespace SKValue +open MeasureTheory ProbabilityTheory Set Filter +open scoped Topology BigOperators + +structure GradientStrip (T : ℝ) (γ : ℝ → ℝ) (u : ℝ → ℝ → ℝ) (K L : ℝ) : Prop where + K_nonneg : 0≤K + L_nonneg : 0≤L + gamma_nonneg : ∀ t ∈ Icc (0 : ℝ) T, 0≤γ t + gamma_mono : MonotoneOn γ (Icc (0 : ℝ) T) + smooth : ∀ t ∈ Icc (0 : ℝ) T, ContDiff ℝ 3 (u t) + bounded : ∀ t ∈ Icc (0 : ℝ) T, ∀ x, |u t x|≤1 + second_bound : ∀ t ∈ Icc (0 : ℝ) T, ∀ x, |deriv (deriv (u t)) x|≤K + third_bound : ∀ t ∈ Icc (0 : ℝ) T, ∀ x, |iteratedDeriv 3 (u t) x|≤K + product_bound : ∀ t ∈ Icc (0 : ℝ) T, ∀ x, |u t x*deriv (u t) x|≤K + second_lipschitz : ∀ t ∈ Icc (0 : ℝ) T, ∀ s ∈ Icc (0 : ℝ) T, ∀ x y, + |deriv (deriv (u s)) y-deriv (deriv (u t)) x|≤L*(|s-t|+|y-x|) + product_lipschitz : ∀ t ∈ Icc (0 : ℝ) T, ∀ s ∈ Icc (0 : ℝ) T, ∀ x y, + |u s y*deriv (u s) y-u t x*deriv (u t) x|≤L*(|s-t|+|y-x|) + second_integrable : ∀ x, IntervalIntegrable (fun s ↦ deriv (deriv (u s)) x) volume 0 T + product_integrable : ∀ x, IntervalIntegrable (fun s ↦ γ s*(u s x*deriv (u s) x)) volume 0 T + pde : ∀ t ∈ Icc (0 : ℝ) T, ∀ s ∈ Icc (0 : ℝ) T, ∀ x, + u s x-u t x = -(∫ r in t..s, (1/2 : ℝ)*deriv (deriv (u r)) x+γ r*(u r x*deriv (u r) x)) + initial : u 0 0=0 + +lemma mesh_mem_strip_ito {δ T : ℝ} {N j : ℕ} (hδ : 0≤δ) + (horizon : (N : ℝ)*δ=T) (hj : j≤N) : (j : ℝ)*δ∈Icc (0 : ℝ) T := by + constructor + · positivity + · rw [← horizon] + exact mul_le_mul_of_nonneg_right (by exact_mod_cast hj) hδ + +lemma GradientStrip.measurable_second {T K L : ℝ} {γ : ℝ → ℝ} {u : ℝ → ℝ → ℝ} + (h : GradientStrip T γ u K L) {t : ℝ} (ht : t∈Icc (0 : ℝ) T) : + Measurable (deriv (deriv (u t))) := by + have hc := (h.smooth t ht).continuous_iteratedDeriv 2 (by norm_num) + simpa only [show 2=1+1 from rfl, iteratedDeriv_succ, iteratedDeriv_one, iteratedDeriv_zero] using hc.measurable + +noncomputable def gradientMeshError (T : ℝ) (N : ℕ) (γ : ℝ → ℝ) (u : ℝ → ℝ → ℝ) : ℝ := + ∫ z, (u T (euler T N γ u z N)-∑ i : Fin N, + Real.sqrt (stepSize T N)*deriv (u (meshTime T N i)) (euler T N γ u z i)*coordinate N i z)^2 + ∂gaussianProduct (Fin (N+1)) + +lemma gradientMeshError_nonneg (T : ℝ) (N : ℕ) (γ : ℝ → ℝ) (u : ℝ → ℝ → ℝ) : + 0≤gradientMeshError T N γ u := integral_nonneg (fun _ ↦ sq_nonneg _) + +lemma gradientMeshError_bound {T K L : ℝ} {γ : ℝ → ℝ} {u : ℝ → ℝ → ℝ} + (hT : 0 simp [he0] + | succ n ih => + have hnN : n < N := by omega + have ih' := ih (by omega) + have hsum : 0 ≤ ∑ j ∈ range n, r j := + sum_nonneg (fun j hj ↦ hr j (lt_of_lt_of_le (mem_range.mp hj) (by omega))) + have hexp : 1 ≤ Real.exp (((n+1 : ℕ) : ℝ)*c) := + Real.one_le_exp (mul_nonneg (Nat.cast_nonneg _) hc) + calc + e (n+1) ≤ (1+c) * e n + r n := hrec n hnN + _ ≤ (1+c) * ((∑ j ∈ range n, r j) * Real.exp ((n : ℝ)*c)) + r n := by + gcongr + _ ≤ Real.exp c * ((∑ j ∈ range n, r j) * Real.exp ((n : ℝ)*c)) + + r n * Real.exp (((n+1 : ℕ) : ℝ)*c) := by + apply add_le_add + · exact mul_le_mul_of_nonneg_right (by simpa [add_comm] using Real.add_one_le_exp c) + (mul_nonneg hsum (Real.exp_pos _).le) + · exact le_mul_of_one_le_right (hr n hnN) hexp + _ = (∑ j ∈ range (n+1), r j) * Real.exp (((n+1 : ℕ) : ℝ)*c) := by + rw [sum_range_succ, Nat.cast_add, Nat.cast_one, add_mul, one_mul, Real.exp_add] + ring + +lemma finite_discrete_gronwall_uniform {e r : ℕ → ℝ} {c : ℝ} {N : ℕ} + (hc : 0 ≤ c) (he0 : e 0 = 0) + (hr : ∀ j < N, 0 ≤ r j) + (hrec : ∀ j < N, e (j+1) ≤ (1+c) * e j + r j) + {R : ℝ} (hR : (∑ j ∈ range N, r j) ≤ R) : + ∀ n ≤ N, e n ≤ R * Real.exp ((N : ℝ)*c) := by + intro n hn + apply (finite_discrete_gronwall hc he0 hr hrec n hn).trans + apply mul_le_mul + · exact (sum_le_sum_of_subset_of_nonneg (range_mono hn) + (fun j hj _ ↦ hr j (mem_range.mp hj))).trans hR + · exact Real.exp_le_exp.mpr (mul_le_mul_of_nonneg_right (by exact_mod_cast hn) hc) + · exact (Real.exp_pos _).le + · exact le_trans (sum_nonneg (fun j hj ↦ hr j (mem_range.mp hj))) hR + +lemma driven_euler_stability {δ G L : ℝ} {N : ℕ} {u : ℝ → ℝ → ℝ} + {γ W X : ℝ → ℝ} {Y r : ℕ → ℝ} + (hδ : 0 ≤ δ) (hG : 0 ≤ G) (hL : 0 ≤ L) + (hX0 : X 0 = 0) (hY0 : Y 0 = 0) + (hγ : ∀ j < N, |γ ((j : ℝ)*δ)| ≤ G) + (hu : ∀ j < N, ∀ x y, + |u ((j : ℝ)*δ) x - u ((j : ℝ)*δ) y| ≤ L * |x-y|) + (hY : ∀ j < N, Y (j+1) = Y j + W (((j+1 : ℕ) : ℝ)*δ) - W ((j : ℝ)*δ) + + δ * γ ((j : ℝ)*δ) * u ((j : ℝ)*δ) (Y j)) + (hdefect : ∀ j < N, + |X (((j+1 : ℕ) : ℝ)*δ) - X ((j : ℝ)*δ) - + (W (((j+1 : ℕ) : ℝ)*δ) - W ((j : ℝ)*δ)) - + δ * γ ((j : ℝ)*δ) * u ((j : ℝ)*δ) (X ((j : ℝ)*δ))| ≤ r j) + {R : ℝ} (hR : (∑ j ∈ range N, r j) ≤ R) : + ∀ j ≤ N, |Y j - X ((j : ℝ)*δ)| ≤ R * Real.exp ((N : ℝ)*δ*G*L) := by + have hr : ∀ j < N, 0 ≤ r j := fun j hj ↦ (abs_nonneg _).trans (hdefect j hj) + have hrec : ∀ j < N, + |Y (j+1) - X (((j+1 : ℕ) : ℝ)*δ)| ≤ + (1+δ*G*L) * |Y j - X ((j : ℝ)*δ)| + r j := by + intro j hj + let q := X (((j+1 : ℕ) : ℝ)*δ) - X ((j : ℝ)*δ) - + (W (((j+1 : ℕ) : ℝ)*δ) - W ((j : ℝ)*δ)) - + δ * γ ((j : ℝ)*δ) * u ((j : ℝ)*δ) (X ((j : ℝ)*δ)) + have heq : Y (j+1) - X (((j+1 : ℕ) : ℝ)*δ) = + (Y j - X ((j : ℝ)*δ)) + δ * γ ((j : ℝ)*δ) * + (u ((j : ℝ)*δ) (Y j) - u ((j : ℝ)*δ) (X ((j : ℝ)*δ))) - q := by + rw [hY j hj] + dsimp [q] + ring + rw [heq] + calc + _ ≤ |Y j - X ((j : ℝ)*δ)| + + |δ * γ ((j : ℝ)*δ) * (u ((j : ℝ)*δ) (Y j) - + u ((j : ℝ)*δ) (X ((j : ℝ)*δ)))| + |q| := + (abs_sub _ _).trans (add_le_add (abs_add_le _ _) le_rfl) + _ ≤ |Y j - X ((j : ℝ)*δ)| + δ * G * (L * |Y j - X ((j : ℝ)*δ)|) + r j := by + rw [abs_mul, abs_mul, abs_of_nonneg hδ] + gcongr + · exact hγ j hj + · exact hu j hj _ _ + · exact hdefect j hj + _ = (1+δ*G*L) * |Y j - X ((j : ℝ)*δ)| + r j := by ring + simpa only [mul_assoc] using + finite_discrete_gronwall_uniform (mul_nonneg (mul_nonneg hδ hG) hL) + (by simp [hY0, hX0]) hr hrec hR + +lemma monotone_drift_local_error {a b G L ε : ℝ} {γ X : ℝ → ℝ} + {u : ℝ → ℝ → ℝ} (hab : a ≤ b) (hG : 0 ≤ G) (hL : 0 ≤ L) (_ : 0 ≤ ε) + (hγ : MonotoneOn γ (Icc a b)) (hγ0 : 0 ≤ γ a) (hγG : γ a ≤ G) + (hu : ∀ s ∈ Icc a b, |u s (X s)| ≤ 1) + (hLip : ∀ s ∈ Icc a b, + |u s (X s) - u a (X a)| ≤ L * (|s-a| + |X s-X a|)) + (hX : ∀ s ∈ Icc a b, |X s-X a| ≤ ε) + (hint : IntervalIntegrable (fun s ↦ γ s * u s (X s)) volume a b) : + |(∫ s in a..b, γ s * u s (X s)) - (b-a) * γ a * u a (X a)| ≤ + (b-a) * (γ b-γ a) + (b-a) * G * L * ((b-a)+ε) := by + have ha : a ∈ Icc a b := ⟨le_rfl, hab⟩ + have hb : b ∈ Icc a b := ⟨hab, le_rfl⟩ + have hp : ∀ s ∈ Icc a b, + |γ s * u s (X s) - γ a * u a (X a)| ≤ (γ b-γ a) + G*L*((b-a)+ε) := by + intro s hs + have hsa := hγ ha hs hs.1 + have hsb := hγ hs hb hs.2 + calc + _ = |(γ s-γ a)*u s (X s) + γ a*(u s (X s)-u a (X a))| := by + congr 1; ring + _ ≤ |(γ s-γ a)*u s (X s)| + |γ a*(u s (X s)-u a (X a))| := abs_add_le _ _ + _ = (γ s-γ a)*|u s (X s)| + γ a*|u s (X s)-u a (X a)| := by + rw [abs_mul, abs_mul, abs_of_nonneg (sub_nonneg.mpr hsa), abs_of_nonneg hγ0] + _ ≤ (γ b-γ a) + G*L*((b-a)+ε) := by + calc + _ ≤ (γ s-γ a)*1 + G*(L*((b-a)+ε)) := by + gcongr + · exact hu s hs + · exact hLip s hs |>.trans (by + gcongr + · rw [abs_of_nonneg (sub_nonneg.mpr hs.1)] + exact sub_le_sub_right hs.2 a + · exact hX s hs) + _ ≤ (γ b-γ a) + G*L*((b-a)+ε) := by nlinarith + have hi := intervalIntegral.norm_integral_le_of_norm_le_const + (a := a) (b := b) (f := fun s ↦ γ s*u s (X s)-γ a*u a (X a)) + (C := (γ b-γ a)+G*L*((b-a)+ε)) (fun s hs ↦ by + rw [Real.norm_eq_abs] + rw [uIoc_of_le hab] at hs + exact hp s ⟨hs.1.le, hs.2⟩) + rw [intervalIntegral.integral_sub hint intervalIntegrable_const, + intervalIntegral.integral_const, smul_eq_mul, Real.norm_eq_abs, + abs_of_nonneg (sub_nonneg.mpr hab)] at hi + convert hi using 1 + · congr 1; ring + · ring + +lemma mesh_mem_strip {δ T : ℝ} {N j : ℕ} (hδ : 0 ≤ δ) + (horizon : (N : ℝ)*δ = T) (hj : j ≤ N) : (j : ℝ)*δ ∈ Icc (0 : ℝ) T := by + constructor + · positivity + · rw [← horizon] + exact mul_le_mul_of_nonneg_right (by exact_mod_cast hj) hδ + +lemma intervalIntegrable_substrip {f : ℝ → ℝ} {T a b : ℝ} (hT : 0 ≤ T) + (hf : IntervalIntegrable f volume 0 T) (ha : a ∈ Icc (0 : ℝ) T) + (hb : b ∈ Icc (0 : ℝ) T) : IntervalIntegrable f volume a b := by + apply hf.mono_set + rw [uIcc_of_le hT] + exact uIcc_subset_Icc ha hb + +lemma driven_euler_error_bound {δ T L ε : ℝ} {N : ℕ} {u : ℝ → ℝ → ℝ} + {γ W X : ℝ → ℝ} {Y : ℕ → ℝ} + (hδ : 0 ≤ δ) (hT : 0 ≤ T) (hL : 0 ≤ L) (hε : 0 ≤ ε) + (horizon : (N : ℝ)*δ = T) + (hγ : MonotoneOn γ (Icc (0 : ℝ) T)) (hγ0 : 0 ≤ γ 0) + (hu : ∀ t ∈ Icc (0 : ℝ) T, ∀ x, |u t x| ≤ 1) + (hLip : ∀ s ∈ Icc (0 : ℝ) T, ∀ t ∈ Icc (0 : ℝ) T, ∀ x y, + |u s x-u t y| ≤ L*(|s-t|+|x-y|)) + (hXosc : ∀ s ∈ Icc (0 : ℝ) T, ∀ t ∈ Icc (0 : ℝ) T, + |s-t| ≤ δ → |X s-X t| ≤ ε) + (hint : IntervalIntegrable (fun s ↦ γ s*u s (X s)) volume 0 T) + (hX : ∀ t ∈ Icc (0 : ℝ) T, X t = W t + ∫ s in (0 : ℝ)..t, γ s*u s (X s)) + (hX0 : X 0 = 0) (hY0 : Y 0 = 0) + (hY : ∀ j < N, Y (j+1) = Y j + W (((j+1 : ℕ) : ℝ)*δ)-W ((j : ℝ)*δ) + + δ*γ ((j : ℝ)*δ)*u ((j : ℝ)*δ) (Y j)) : + ∀ j ≤ N, |Y j-X ((j : ℝ)*δ)| ≤ + (δ*(γ T-γ 0)+T*γ T*L*(δ+ε))*Real.exp (T*γ T*L) := by + have h0 : (0 : ℝ) ∈ Icc (0 : ℝ) T := ⟨le_rfl,hT⟩ + have h1 : T ∈ Icc (0 : ℝ) T := ⟨hT,le_rfl⟩ + have hG : 0 ≤ γ T := hγ0.trans (hγ h0 h1 hT) + have hmesh := fun j hj ↦ mesh_mem_strip hδ horizon (j := j) hj + have hγnonneg : ∀ t ∈ Icc (0 : ℝ) T, 0 ≤ γ t := + fun t ht ↦ hγ0.trans (hγ h0 ht ht.1) + let r : ℕ → ℝ := fun j ↦ δ*(γ (((j+1 : ℕ) : ℝ)*δ)-γ ((j : ℝ)*δ)) + + δ*γ T*L*(δ+ε) + have hdefect : ∀ j < N, + |X (((j+1 : ℕ) : ℝ)*δ)-X ((j : ℝ)*δ) - + (W (((j+1 : ℕ) : ℝ)*δ)-W ((j : ℝ)*δ)) - + δ*γ ((j : ℝ)*δ)*u ((j : ℝ)*δ) (X ((j : ℝ)*δ))| ≤ r j := by + intro j hj + have ha := hmesh j (by omega) + have hb := hmesh (j+1) (by omega) + have hab : (j : ℝ)*δ ≤ ((j+1 : ℕ) : ℝ)*δ := by push_cast; nlinarith + have hlength : ((j+1 : ℕ) : ℝ)*δ-(j : ℝ)*δ = δ := by push_cast; ring + have hsub : Icc ((j : ℝ)*δ) (((j+1 : ℕ) : ℝ)*δ) ⊆ Icc (0 : ℝ) T := + Icc_subset_Icc ha.1 hb.2 + have hquadrature := monotone_drift_local_error hab hG hL hε + (hγ.mono hsub) (hγnonneg _ ha) (hγ ha h1 ha.2) + (fun s hs ↦ hu s (hsub hs) _) + (fun s hs ↦ hLip s (hsub hs) _ ha _ _) + (fun s hs ↦ hXosc s (hsub hs) _ ha (by + rw [abs_of_nonneg (sub_nonneg.mpr hs.1)] + calc s-(j : ℝ)*δ ≤ ((j+1 : ℕ) : ℝ)*δ-(j : ℝ)*δ := sub_le_sub_right hs.2 _ + _ = δ := hlength)) + (intervalIntegrable_substrip hT hint ha hb) + rw [hlength] at hquadrature + have hdiff : X (((j+1 : ℕ) : ℝ)*δ)-X ((j : ℝ)*δ) - + (W (((j+1 : ℕ) : ℝ)*δ)-W ((j : ℝ)*δ)) = + ∫ s in (j : ℝ)*δ..((j+1 : ℕ) : ℝ)*δ, γ s*u s (X s) := by + rw [hX _ hb, hX _ ha] + have hi := intervalIntegral.integral_interval_sub_left + (intervalIntegrable_substrip hT hint h0 hb) + (intervalIntegrable_substrip hT hint h0 ha) + linear_combination hi + simpa only [hdiff, r] using hquadrature + have hsum : (∑ j ∈ range N, r j) = δ*(γ T-γ 0)+T*γ T*L*(δ+ε) := by + dsimp [r] + rw [sum_add_distrib, ← mul_sum, sum_range_sub (fun j : ℕ ↦ γ ((j : ℝ)*δ))] + simp only [Nat.cast_zero, zero_mul, sum_const, card_range, nsmul_eq_mul] + rw [horizon] + rw [← horizon] + ring + have hbound := driven_euler_stability hδ hG hL hX0 hY0 + (fun j hj ↦ by + rw [abs_of_nonneg (hγnonneg _ (hmesh j (by omega)))] + exact hγ (hmesh j (by omega)) h1 (hmesh j (by omega)).2) + (fun j hj x y ↦ by simpa using hLip _ (hmesh j (by omega)) _ (hmesh j (by omega)) x y) + hY hdefect hsum.le + simpa only [horizon] using hbound + +lemma driven_euler_uniform_convergence {T L : ℝ} {u : ℝ → ℝ → ℝ} + {γ W X : ℝ → ℝ} {Y : ℕ → ℕ → ℝ} + (hT : 0 ≤ T) (hL : 0 ≤ L) + (hγ : MonotoneOn γ (Icc (0 : ℝ) T)) (hγ0 : 0 ≤ γ 0) + (hu : ∀ t ∈ Icc (0 : ℝ) T, ∀ x, |u t x| ≤ 1) + (hLip : ∀ s ∈ Icc (0 : ℝ) T, ∀ t ∈ Icc (0 : ℝ) T, ∀ x y, + |u s x-u t y| ≤ L*(|s-t|+|x-y|)) + (hXcont : ContinuousOn X (Icc (0 : ℝ) T)) + (hint : IntervalIntegrable (fun s ↦ γ s*u s (X s)) volume 0 T) + (hX : ∀ t ∈ Icc (0 : ℝ) T, X t = W t + ∫ s in (0 : ℝ)..t, γ s*u s (X s)) + (hX0 : X 0 = 0) (hY0 : ∀ N, Y N 0 = 0) + (hY : ∀ N > 0, ∀ j < N, + Y N (j+1) = Y N j + W (((j+1 : ℕ) : ℝ)*(T/N))-W ((j : ℝ)*(T/N)) + + (T/N)*γ ((j : ℝ)*(T/N))*u ((j : ℝ)*(T/N)) (Y N j)) : + ∀ ε > 0, ∀ᶠ N in atTop, ∀ j ≤ N, |Y N j-X ((j : ℝ)*(T/N))| < ε := by + intro ε hε + have hG : 0 ≤ γ T := hγ0.trans (hγ ⟨le_rfl,hT⟩ ⟨hT,le_rfl⟩ hT) + let E := Real.exp (T*γ T*L) + let C := T*γ T*L*E + have hE : 0 < E := Real.exp_pos _ + have hC : 0 ≤ C := mul_nonneg (mul_nonneg (mul_nonneg hT hG) hL) hE.le + let η := ε/(2*(C+1)) + have hη : 0 < η := div_pos hε (by positivity) + have hηeq : η*(2*(C+1)) = ε := div_mul_cancel₀ _ (by positivity) + have hCη : C*η < ε/2 := by nlinarith + obtain ⟨θ,hθ,hmod⟩ := Metric.uniformContinuousOn_iff_le.mp + (isCompact_Icc.uniformContinuousOn_of_continuous hXcont) η hη + have hδ : Tendsto (fun N : ℕ ↦ T/N) atTop (𝓝 (0 : ℝ)) := + tendsto_const_div_atTop_nhds_zero_nat T + have htail : Tendsto (fun N : ℕ ↦ (T/N)*((γ T-γ 0)+T*γ T*L)*E) + atTop (𝓝 (0 : ℝ)) := by + simpa using (hδ.mul_const ((γ T-γ 0)+T*γ T*L)).mul_const E + filter_upwards [hδ.eventually_le_const hθ, + htail.eventually_lt_const (half_pos hε), eventually_gt_atTop 0] with N hNθ hNerr hN + have hδnonneg : 0 ≤ T/(N : ℝ) := div_nonneg hT (Nat.cast_nonneg _) + have horizon : (N : ℝ)*(T/N) = T := by + field_simp + have hbound := driven_euler_error_bound hδnonneg hT hL hη.le horizon hγ hγ0 hu hLip + (fun s hs t ht hst ↦ by + have hh := hmod s hs t ht (by simpa [Real.dist_eq] using hst.trans hNθ) + simpa [Real.dist_eq] using hh) + hint hX hX0 (hY0 N) (hY N hN) + intro j hj + apply (hbound j hj).trans_lt + change (T/(N : ℝ)*(γ T-γ 0)+T*γ T*L*(T/N+η))*E < ε + dsimp [C] at hCη + nlinarith [hNerr,hCη] + +lemma driven_euler_uniform_bound {δ T : ℝ} {N : ℕ} {u : ℝ → ℝ → ℝ} + {γ W X : ℝ → ℝ} {Y : ℕ → ℝ} + (hδ : 0 ≤ δ) (hT : 0 ≤ T) (horizon : (N : ℝ)*δ = T) + (hγ : MonotoneOn γ (Icc (0 : ℝ) T)) (hγ0 : 0 ≤ γ 0) + (hu : ∀ t ∈ Icc (0 : ℝ) T, ∀ x, |u t x| ≤ 1) + (hX : ∀ t ∈ Icc (0 : ℝ) T, X t = W t + ∫ s in (0 : ℝ)..t, γ s*u s (X s)) + (hX0 : X 0 = 0) (hY0 : Y 0 = 0) + (hY : ∀ j < N, Y (j+1) = Y j + W (((j+1 : ℕ) : ℝ)*δ)-W ((j : ℝ)*δ) + + δ*γ ((j : ℝ)*δ)*u ((j : ℝ)*δ) (Y j)) : + ∀ j ≤ N, |Y j-X ((j : ℝ)*δ)| ≤ 2*T*γ T := by + have h0 : (0 : ℝ) ∈ Icc (0 : ℝ) T := ⟨le_rfl,hT⟩ + have h1 : T ∈ Icc (0 : ℝ) T := ⟨hT,le_rfl⟩ + have hG : 0 ≤ γ T := hγ0.trans (hγ h0 h1 hT) + have hW0 : W 0 = 0 := by simpa [hX0] using (hX 0 h0).symm + have hmesh := fun j hj ↦ mesh_mem_strip hδ horizon (j := j) hj + have hγnonneg : ∀ t ∈ Icc (0 : ℝ) T, 0 ≤ γ t := + fun t ht ↦ hγ0.trans (hγ h0 ht ht.1) + have hγu : ∀ t ∈ Icc (0 : ℝ) T, ∀ x, |γ t*u t x| ≤ γ T := by + intro t ht x + rw [abs_mul, abs_of_nonneg (hγnonneg t ht)] + calc γ t*|u t x| ≤ γ t*1 := mul_le_mul_of_nonneg_left (hu t ht x) (hγnonneg t ht) + _ ≤ γ T := by simpa using hγ ht h1 ht.2 + have hYbound : ∀ j ≤ N, |Y j-W ((j : ℝ)*δ)| ≤ ((j : ℝ)*δ)*γ T := by + intro j hj + induction j with + | zero => simp [hY0,hW0] + | succ j ih => + have hjN : j < N := by omega + have ih' := ih (by omega) + have heq : Y (j+1)-W (((j+1 : ℕ) : ℝ)*δ) = + (Y j-W ((j : ℝ)*δ)) + δ*(γ ((j : ℝ)*δ)*u ((j : ℝ)*δ) (Y j)) := by + rw [hY j hjN]; ring + calc + _ = |(Y j-W ((j : ℝ)*δ)) + δ*(γ ((j : ℝ)*δ)*u ((j : ℝ)*δ) (Y j))| := congrArg abs heq + _ ≤ |Y j-W ((j : ℝ)*δ)| + |δ*(γ ((j : ℝ)*δ)*u ((j : ℝ)*δ) (Y j))| := abs_add_le _ _ + _ ≤ ((j : ℝ)*δ)*γ T+δ*γ T := by + rw [abs_mul,abs_of_nonneg hδ] + exact add_le_add ih' (mul_le_mul_of_nonneg_left (hγu _ (hmesh j (by omega)) _) hδ) + _ = (((j+1 : ℕ) : ℝ)*δ)*γ T := by push_cast; ring + intro j hj + have hm := hmesh j hj + have hi := intervalIntegral.norm_integral_le_of_norm_le_const + (a := 0) (b := (j : ℝ)*δ) (f := fun s ↦ γ s*u s (X s)) (C := γ T) + (fun s hs ↦ by + rw [uIoc_of_le hm.1] at hs + rw [Real.norm_eq_abs] + exact hγu s ⟨hs.1.le,hs.2.trans hm.2⟩ _) + simp only [Real.norm_eq_abs, sub_zero, abs_of_nonneg hm.1] at hi + calc + _ = |(Y j-W ((j : ℝ)*δ)) - ∫ s in (0 : ℝ)..(j : ℝ)*δ, γ s*u s (X s)| := by + rw [hX _ hm]; congr 1; ring + _ ≤ |Y j-W ((j : ℝ)*δ)| + |∫ s in (0 : ℝ)..(j : ℝ)*δ, γ s*u s (X s)| := abs_sub _ _ + _ ≤ ((j : ℝ)*δ)*γ T+γ T*((j : ℝ)*δ) := add_le_add (hYbound j hj) hi + _ ≤ 2*T*γ T := by nlinarith [mul_le_mul_of_nonneg_right hm.2 hG] + +noncomputable def initialMax (f : ℕ → ℝ) : ℕ → ℝ + | 0 => f 0 + | n+1 => max (initialMax f n) (f (n+1)) + +lemma initialMax_le_iff {f : ℕ → ℝ} {n : ℕ} {b : ℝ} : + initialMax f n ≤ b ↔ ∀ j ≤ n, f j ≤ b := by + induction n with + | zero => simp [initialMax] + | succ n ih => + simp only [initialMax, max_le_iff, ih] + constructor + · rintro ⟨ha,hb⟩ j hj + obtain hj | rfl := lt_or_eq_of_le hj + · exact ha j (by omega) + · exact hb + · intro h + exact ⟨fun j hj ↦ h j (by omega), h _ le_rfl⟩ + +lemma initialMax_lt_iff {f : ℕ → ℝ} {n : ℕ} {b : ℝ} : + initialMax f n < b ↔ ∀ j ≤ n, f j < b := by + induction n with + | zero => simp [initialMax] + | succ n ih => + simp only [initialMax, max_lt_iff, ih] + constructor + · rintro ⟨ha,hb⟩ j hj + obtain hj | rfl := lt_or_eq_of_le hj + · exact ha j (by omega) + · exact hb + · intro h + exact ⟨fun j hj ↦ h j (by omega), h _ le_rfl⟩ + +lemma le_initialMax {f : ℕ → ℝ} {n j : ℕ} (hj : j ≤ n) : f j ≤ initialMax f n := + initialMax_le_iff.mp le_rfl j hj + +lemma aestronglyMeasurable_initialMax {Ω : Type*} [MeasurableSpace Ω] {μ : Measure Ω} + {f : ℕ → Ω → ℝ} (hf : ∀ j, AEStronglyMeasurable (f j) μ) (n : ℕ) : + AEStronglyMeasurable (fun ω ↦ initialMax (fun j ↦ f j ω) n) μ := by + induction n with + | zero => exact hf 0 + | succ n ih => exact ih.sup (hf (n+1)) + +end SKValue +end + +end OAI diff --git a/lean/OAI/Probability/SKValue/Equations/IntegralAbsSqrtSecond.lean b/lean/OAI/Probability/SKValue/Equations/IntegralAbsSqrtSecond.lean new file mode 100644 index 0000000000000000000000000000000000000000..a2ee7730dd8226f625b13e1d37456ff05eb639a4 --- /dev/null +++ b/lean/OAI/Probability/SKValue/Equations/IntegralAbsSqrtSecond.lean @@ -0,0 +1,117 @@ +import Mathlib +import OAI.Probability.SKValue.Processes.Measurable + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set +open scoped ENNReal NNReal BigOperators +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators Topology +open MeasureTheory ProbabilityTheory Set Filter +open scoped Topology BigOperators +open MeasureTheory ProbabilityTheory Set Filter +open scoped Topology ENNReal NNReal +open Filter Set +open scoped Topology BigOperators +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology +open MeasureTheory Set Filter +open scoped Topology BigOperators +open MeasureTheory Set Filter Finset +open scoped Topology BigOperators +namespace SKValue +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology NNReal ENNReal BigOperators + +lemma integral_abs_le_sqrt_second {Ω : Type*} [MeasurableSpace Ω] {μ : Measure Ω} + [IsProbabilityMeasure μ] {f : Ω → ℝ} (hf : MemLp f 2 μ) : + (∫ ω, |f ω| ∂μ)≤Real.sqrt (∫ ω, (f ω)^2 ∂μ) := by + have hab : MemLp (fun ω ↦ |f ω|) 2 μ := by simpa only [Real.norm_eq_abs] using hf.norm + have hv := variance_nonneg (fun ω ↦ |f ω|) μ + rw [variance_eq_sub hab] at hv + simp only [Pi.pow_apply,sq_abs] at hv + apply (Real.le_sqrt (integral_nonneg (fun _ ↦ abs_nonneg _)) (integral_nonneg (fun _ ↦ sq_nonneg _))).mpr + linarith + +lemma IsDiffusion.L1_terminal {W : BrownianSpace} {γ : OrderParameter} + {X : ℝ → W.Ω → ℝ} (hX : IsDiffusion W γ X) : + Tendsto (fun t ↦ ∫ ω, |X t ω-X 1 ω| ∂W.μ) (𝓝[<] (1 : ℝ)) (𝓝 (0 : ℝ)) := by + apply squeeze_zero' (Eventually.of_forall (fun t ↦ integral_nonneg (fun _ ↦ abs_nonneg _))) ?_ + (by simpa only [Real.sqrt_zero,Function.comp_def] using Real.continuous_sqrt.continuousAt.tendsto.comp hX.L2_terminal) + filter_upwards [eventually_time_mem] with t ht + exact integral_abs_le_sqrt_second ((hX.memLp ht (by norm_num)).sub + (hX.memLp (by norm_num : (1 : ℝ)∈Icc (0 : ℝ) 1) (by norm_num))) + +lemma IsDiffusion.phi_integrable {W : BrownianSpace} {γ : OrderParameter} + {X : ℝ → W.Ω → ℝ} (hX : IsDiffusion W γ X) {t : ℝ} (ht : t∈Icc (0 : ℝ) 1) : + Integrable (fun ω ↦ phi W γ t (X t ω)) W.μ := by + have hi := (hX.memLp ht (p := 1) (by norm_num)).integrable le_rfl + apply (hi.abs.add (integrable_const (terminalError γ t))).mono' + (((phi_lipschitz W γ ht).continuous.measurable.comp (hX.measurable ht)).aestronglyMeasurable) + filter_upwards [] with ω + dsimp only [Function.comp_apply,Pi.add_apply] + rw [Real.norm_eq_abs,abs_of_nonneg ((abs_nonneg _).trans (phi_lower W γ ht (X t ω)))] + have h := (phi_terminal_bound W γ ht (X t ω)).2 + change _≤terminalError γ t at h + linarith + +lemma IsDiffusion.phi_expectation_terminal {W : BrownianSpace} {γ : OrderParameter} + {X : ℝ → W.Ω → ℝ} (hX : IsDiffusion W γ X) : + Tendsto (fun t ↦ ∫ ω, phi W γ t (X t ω) ∂W.μ) (𝓝[<] (1 : ℝ)) + (𝓝 (∫ ω, |X 1 ω| ∂W.μ)) := by + have h1 : Integrable (X 1) W.μ := (hX.memLp (by norm_num) (p := 1) (by norm_num)).integrable le_rfl + have hb : ∀ t∈Icc (0 : ℝ) 1, + |(∫ ω, phi W γ t (X t ω) ∂W.μ)-(∫ ω, |X 1 ω| ∂W.μ)|≤ + terminalError γ t+(∫ ω, |X t ω-X 1 ω| ∂W.μ) := by + intro t ht + have hp := hX.phi_integrable ht + have hi : Integrable (X t) W.μ := (hX.memLp ht (p := 1) (by norm_num)).integrable le_rfl + have hdiff : Integrable (fun ω ↦ |X t ω-X 1 ω|) W.μ := (hi.sub h1).abs + calc + _ = |∫ ω, (phi W γ t (X t ω)-|X 1 ω|) ∂W.μ| := by rw [integral_sub hp h1.abs] + _ ≤ ∫ ω, |phi W γ t (X t ω)-(|X 1 ω|)| ∂W.μ := abs_integral_le_integral_abs + _ ≤ ∫ ω, terminalError γ t+|X t ω-X 1 ω| ∂W.μ := by + apply integral_mono (hp.sub h1.abs).abs ((integrable_const _).add (hi.sub h1).abs) + intro ω + dsimp only [Pi.add_apply,Pi.sub_apply] + have hphi := phi_terminal_bound W γ ht (X t ω) + have hz : |phi W γ t (X t ω)-(|X t ω|)|≤terminalError γ t := by + rw [abs_of_nonneg hphi.1] + exact hphi.2 + have he : phi W γ t (X t ω)-|X 1 ω| = + (phi W γ t (X t ω)-|X t ω|)+(|X t ω|-|X 1 ω|) := by ring + rw [he] + exact (abs_add_le _ _).trans (add_le_add hz (abs_abs_sub_abs_le_abs_sub _ _)) + _ = _ := by + rw [integral_add (integrable_const (terminalError γ t)) hdiff, integral_const] + simp + have he : Tendsto (fun t ↦ terminalError γ t) (𝓝[<] (1 : ℝ)) (𝓝 (0 : ℝ)) := by + simpa only [terminalError_one] using ((terminalError_continuous γ).tendsto 1).mono_left nhdsWithin_le_nhds + have hh : Tendsto (fun t ↦ |(∫ ω, phi W γ t (X t ω) ∂W.μ)-(∫ ω, |X 1 ω| ∂W.μ)|) + (𝓝[<] (1 : ℝ)) (𝓝 (0 : ℝ)) := + squeeze_zero' (Eventually.of_forall (fun _ ↦ abs_nonneg _)) + (eventually_time_mem.mono (fun t ht ↦ hb t ht)) (by simpa only [add_zero] using he.add hX.L1_terminal) + exact tendsto_iff_norm_sub_tendsto_zero.mpr (by simpa only [Real.norm_eq_abs] using hh) + +lemma IsDiffusion.terminal_gradient_product {W : BrownianSpace} {γ : OrderParameter} + {X : ℝ → W.Ω → ℝ} (hX : IsDiffusion W γ X) {U : W.Ω → ℝ} + (hd : ∀ᵐ ω ∂W.μ, ∀ᶠ t in 𝓝[<] (1 : ℝ), DifferentiableAt ℝ (phi W γ t) (X t ω)) + (hU : ∀ᵐ ω ∂W.μ, Tendsto (fun t ↦ gradient W γ t (X t ω)) (𝓝[<] (1 : ℝ)) (𝓝 (U ω))) : + ∀ᵐ ω ∂W.μ, U ω*X 1 ω=|X 1 ω| := by + filter_upwards [hX.ae_tendsto,hd,hU] with ω hXω hdω hUω + by_cases hz : X 1 ω=0 + · simp [hz] + have hs := gradient_terminal_tendsto W γ id (fun t ↦ X t ω) + (tendsto_id.mono_left nhdsWithin_le_nhds) eventually_time_mem hXω hz hdω + have hu : U ω=Real.sign (X 1 ω) := tendsto_nhds_unique hUω hs + rw [hu] + rcases lt_or_gt_of_ne hz with hn | hp + · simp [Real.sign_of_neg hn,abs_of_neg hn] + · simp [Real.sign_of_pos hp,abs_of_pos hp] + +end SKValue + +end + +end OAI diff --git a/lean/OAI/Probability/SKValue/Equations/JetAlgebra.lean b/lean/OAI/Probability/SKValue/Equations/JetAlgebra.lean new file mode 100644 index 0000000000000000000000000000000000000000..516db87cfcd93d875953fa8674b574d31d8f1a49 --- /dev/null +++ b/lean/OAI/Probability/SKValue/Equations/JetAlgebra.lean @@ -0,0 +1,99 @@ +import Mathlib + +namespace OAI + +section + +open MeasureTheory ProbabilityTheory Set Filter +open scoped Topology NNReal ENNReal BigOperators ContDiff +namespace SKValue + +inductive JetExpr where + | const : ℝ → JetExpr + | coord : ℕ → JetExpr + | add : JetExpr → JetExpr → JetExpr + | mul : JetExpr → JetExpr → JetExpr + +namespace JetExpr +noncomputable def eval (R : ℕ → ℝ) : JetExpr → ℝ + | const c => c + | coord j => R j + | add e f => eval R e+eval R f + | mul e f => eval R e*eval R f + +noncomputable def D (σ : ℕ → JetExpr) : JetExpr → JetExpr + | const _ => const 0 + | coord j => σ j + | add e f => add (D σ e) (D σ f) + | mul e f => add (mul (D σ e) f) (mul e (D σ f)) + +lemma hasDerivAt_eval {R : ℕ → ℝ → ℝ} {σ : ℕ → JetExpr} {x : ℝ} + (hR : ∀ j, HasDerivAt (R j) (eval (fun i ↦ R i x) (σ j)) x) (e : JetExpr) : + HasDerivAt (fun y ↦ eval (fun i ↦ R i y) e) (eval (fun i ↦ R i x) (D σ e)) x := by + induction e with + | const c => exact hasDerivAt_const x c + | coord j => exact hR j + | add e f he hf => exact he.add hf + | mul e f he hf => exact he.mul hf + +lemma continuous_eval {α : Type*} [TopologicalSpace α] {R : ℕ → α → ℝ} + (hR : ∀ j, Continuous (R j)) (e : JetExpr) : + Continuous (fun a ↦ eval (fun j ↦ R j a) e) := by + induction e with + | const c => exact continuous_const + | coord j => exact hR j + | add e f he hf => exact he.add hf + | mul e f he hf => exact he.mul hf + +lemma uniform_bound {α : Type*} {R : ℕ → α → ℝ} + (hR : ∀ j, ∃ C : ℝ, 0≤C ∧ ∀ a, |R j a|≤C) (e : JetExpr) : + ∃ C : ℝ, 0≤C ∧ ∀ a, |eval (fun j ↦ R j a) e|≤C := by + induction e with + | const c => exact ⟨|c|,abs_nonneg c,fun _ ↦ le_rfl⟩ + | coord j => exact hR j + | add e f he hf => + obtain ⟨A,hA,he⟩ := he + obtain ⟨B,hB,hf⟩ := hf + exact ⟨A+B,add_nonneg hA hB,fun a ↦ (abs_add_le _ _).trans (add_le_add (he a) (hf a))⟩ + | mul e f he hf => + obtain ⟨A,hA,he⟩ := he + obtain ⟨B,hB,hf⟩ := hf + exact ⟨A*B,mul_nonneg hA hB,fun a ↦ by + simpa only [eval,abs_mul] using mul_le_mul (he a) (hf a) (abs_nonneg _) hA⟩ + +noncomputable def σx (j : ℕ) : JetExpr := + add (coord (j+1)) (mul (const (-1)) (mul (coord j) (coord 1))) + +noncomputable def σh (j : ℕ) : JetExpr := + mul (const (1/2)) (add (coord (j+2)) (mul (const (-1)) (mul (coord j) (coord 2)))) + +noncomputable def logGradientJet : ℕ → JetExpr + | 0 => coord 1 + | n+1 => D σx (logGradientJet n) + +lemma eval_σx (R : ℕ → ℝ) (j : ℕ) : eval R (σx j)=R (j+1)-R j*R 1 := by + simp only [σx,eval]; ring +lemma eval_σh (R : ℕ → ℝ) (j : ℕ) : eval R (σh j)=(1/2 : ℝ)*(R (j+2)-R j*R 2) := by + simp only [σh,eval]; ring + +lemma iteratedDeriv_logGradientJet {R : ℕ → ℝ → ℝ} + (hs : ∀ j, ContDiff ℝ ∞ (R j)) + (hd : ∀ j, deriv (R j)=fun x ↦ R (j+1) x-R j x*R 1 x) (n : ℕ) : + iteratedDeriv n (R 1)=fun x ↦ eval (fun j ↦ R j x) (logGradientJet n) := by + induction n with + | zero => rfl + | succ n ih => + rw [iteratedDeriv_succ,ih] + funext x + apply HasDerivAt.deriv + apply hasDerivAt_eval + intro j + have hj := (((hs j).differentiable (ne_of_gt (ENat.natCast_lt_of_coe_top_le_withTop le_rfl 0))) x).hasDerivAt + simpa only [hd,eval_σx] using hj + +end JetExpr +end SKValue + +end + +end OAI diff --git a/lean/OAI/Probability/SKValue/Equations/LineComparison.lean b/lean/OAI/Probability/SKValue/Equations/LineComparison.lean new file mode 100644 index 0000000000000000000000000000000000000000..4388bc4e05c59c7a1962e1939ca6b72d4bef287c --- /dev/null +++ b/lean/OAI/Probability/SKValue/Equations/LineComparison.lean @@ -0,0 +1,131 @@ +import Mathlib +import OAI.Probability.SKValue.Equations.ParabolicComparison + +namespace OAI + +section + +open Set Filter +open scoped Topology +namespace SKValue + +lemma line_parabolic_nonneg {T B C M : ℝ} (hT : 0≤T) (hB : 0≤B) (hM : 0≤M) + {u ut ux uxx β c : ℝ → ℝ → ℝ} + (hc : ContinuousOn (fun p : ℝ×ℝ ↦ u p.1 p.2) ((Icc 0 T)×ˢ(univ))) + (hdt : ∀ t∈Ioc (0 : ℝ) T, ∀ x, HasDerivAt (u · x) (ut t x) t) + (hdx : ∀ t∈Ioc (0 : ℝ) T, ∀ x, HasDerivAt (u t) (ux t x) x) + (hdxx : ∀ t∈Ioc (0 : ℝ) T, ∀ x, HasDerivAt (ux t) (uxx t x) x) + (hinit : ∀ x, 0≤u 0 x) + (hbound : ∀ t∈Icc (0 : ℝ) T, ∀ x, -M≤u t x) + (hβ : ∀ t∈Ioc (0 : ℝ) T, ∀ x, β t x*x≤B*(1+x^2)) + (hcbd : ∀ t∈Ioc (0 : ℝ) T, ∀ x, c t x≤C) + (hpde : ∀ t∈Ioc (0 : ℝ) T, ∀ x, + 0≤ut t x-(1/2 : ℝ)*uxx t x-β t x*ux t x-c t x*u t x) : + ∀ t∈Icc (0 : ℝ) T, ∀ x, 0≤u t x := by + let k := max C 0+2*B+2 + have hk : 0≤k := by dsimp [k]; linarith [le_max_right C 0] + have hεbound : ∀ ε : ℝ, 0<ε → ∀ t∈Icc (0 : ℝ) T, ∀ x, + -ε*Real.exp (k*t)*(1+x^2)≤u t x := by + intro ε hε t ht x + let A := max 1 (max |x| (M/ε+1)) + have hA1 : 1≤A := le_max_left _ _ + have hxA : |x|≤A := (le_max_left _ _).trans (le_max_right _ _) + have hMA : M≤ε*A := by + have hA := (le_max_right |x| (M/ε+1)).trans (le_max_right 1 (max |x| (M/ε+1))) + have hh := mul_le_mul_of_nonneg_left hA hε.le + rw [mul_add,mul_div_cancel₀ M hε.ne'] at hh + linarith + have hA0 : 0≤A := (mul_nonneg_iff_of_pos_left hε).mp (hM.trans hMA) + have hMA2 : M≤ε*(1+A^2) := by + have hAA : A≤A^2 := by nlinarith + nlinarith [mul_nonneg hε.le (sub_nonneg.mpr hAA)] + let q := fun s : ℝ ↦ ε*Real.exp (k*s) + have hqpos : ∀ s, 0≤q s := fun s ↦ mul_nonneg hε.le (Real.exp_pos _).le + have hqε : ∀ s∈Icc (0 : ℝ) T, ε≤q s := by + intro s hs + have hh : 1≤Real.exp (k*s) := Real.one_le_exp_iff.mpr (mul_nonneg hk hs.1) + simpa only [mul_one] using mul_le_mul_of_nonneg_left hh hε.le + have hqder : ∀ s, HasDerivAt q (k*q s) s := by + intro s + have hd : HasDerivAt q (ε*(Real.exp (k*s)*k)) s := + by simpa only [id_eq,mul_one] using (((hasDerivAt_id s).const_mul k).exp).const_mul ε + convert! hd using 1 + dsimp [q] + ring + have hqcont : Continuous q := by fun_prop + have hpder : ∀ y : ℝ, HasDerivAt (fun z : ℝ ↦ 1+z^2) (2*y) y := by + intro y + convert! ((hasDerivAt_id y).pow 2).const_add 1 using 1 + simp + have hcmp := parabolic_barrier (C := C) (ε := 0) hT (show -A≤A by linarith) le_rfl + (u := fun s y ↦ u s y+q s*(1+y^2)) + (ut := fun s y ↦ ut s y+k*q s*(1+y^2)) + (ux := fun s y ↦ ux s y+q s*(2*y)) + (uxx := fun s y ↦ uxx s y+2*q s) (β := β) (c := c) + ((hc.mono (fun p hp ↦ ⟨hp.1,mem_univ _⟩)).add + (((hqcont.comp continuous_fst).mul (continuous_const.add + (continuous_snd.pow 2))).continuousOn)) + (by + intro s hs y hy + exact (hdt s hs y).add ((hqder s).mul_const (1+y^2))) + (by + intro s hs y hy + exact (hdx s hs y).add ((hpder y).const_mul (q s))) + (by + intro s hs y hy + have he : deriv (fun z ↦ u s z+q s*(1+z^2))= + fun z ↦ ux s z+q s*(2*z) := by + funext z + exact ((hdx s hs z).add ((hpder z).const_mul (q s))).deriv + rw [he] + convert! (hdxx s hs y).add (((hasDerivAt_id y).const_mul 2).const_mul (q s)) using 1 + simp + ring) + (by + intro y hy + exact add_nonneg (hinit y) (mul_nonneg (hqpos _) (by positivity))) + (by + intro s hs + have hb := hbound s hs (-A) + have hq := mul_le_mul_of_nonneg_right (hqε s hs) (show 0≤1+A^2 by positivity) + change -(0 : ℝ)≤u s (-A)+q s*(1+(-A)^2) + rw [neg_sq] + linarith) + (by + intro s hs + have hb := hbound s hs A + have hq := mul_le_mul_of_nonneg_right (hqε s hs) (show 0≤1+A^2 by positivity) + change -(0 : ℝ)≤u s A+q s*(1+A^2) + linarith) + (by intro s hs y hy; exact hcbd s hs y) + (by + intro s hs y hy + have hp := hpde s hs y + have hb := hβ s hs y + have hc' := hcbd s hs y + have hkC : 2*B+2≤k-c s y := by dsimp [k]; linarith [le_max_left C 0] + have hh1 := mul_nonneg (sub_nonneg.mpr hkC) (show 0≤1+y^2 by positivity) + have hbr : 0≤(k-c s y)*(1+y^2)-1-2*β s y*y := by nlinarith [sq_nonneg y] + have hbq := mul_nonneg (hqpos s) hbr + nlinarith only [hp,hbq]) t ht x ((abs_le.mp hxA)) + simp only [neg_zero,zero_mul] at hcmp + dsimp [q] at hcmp + linarith + intro t ht x + by_contra hn + have hu : u t x<0 := lt_of_not_ge hn + let D := Real.exp (k*t)*(1+x^2) + have hD : 0 dsimp [e] + ring + have hecont : Continuous e := by fun_prop + have hbound : ∀ t∈Icc (0 : ℝ) T, 0≤e t ∧ e t≤1 := by + intro t ht + refine ⟨(hepos t).le,Real.exp_le_one_iff.mpr ?_⟩ + exact mul_nonpos_of_nonpos_of_nonneg (neg_nonpos.mpr hk.le) ht.1 + have hlbound {t v : ℝ} (ht : t∈Icc (0 : ℝ) T) (hv : -ε≤v) : 0≤e t*v+ε := by + have hh := mul_le_mul_of_nonneg_left hv (hepos t).le + have hh' := mul_le_mul_of_nonneg_left (hbound t ht).2 hε + nlinarith + have hh := parabolic_nonneg_of_negative_zeroth hT hab + (u := fun t x ↦ e t*u t x+ε) + (ut := fun t x ↦ e t*(ut t x-k*u t x)) + (ux := fun t x ↦ e t*ux t x) (uxx := fun t x ↦ e t*uxx t x) + (β := β) (c := fun t x ↦ c t x-k) + (((hecont.comp continuous_fst).continuousOn.mul hc).add continuousOn_const) + (by + intro t ht x hx + have hd : HasDerivAt (fun s : ℝ ↦ e s*u s x+ε) + ((-k*e t)*u t x+e t*ut t x) t := + ((heder t).mul (hdt t ht x hx)).add_const ε + convert hd using 1 + ring) + (by + intro t ht x hx + exact ((hdx t ht x hx).const_mul (e t)).add_const ε) + (by + intro t ht x hx + have heq : (deriv (fun y ↦ e t*u t y+ε))=fun y ↦ e t*deriv (u t) y := by + funext y + rw [deriv_add_const,deriv_const_mul_field] + rw [heq] + exact (hdxx t ht x hx).const_mul (e t)) + (by intro x hx; simpa only [e,mul_zero,Real.exp_zero,one_mul] using add_nonneg (hinit x hx) hε) + (by intro t ht; exact hlbound ht (hleft t ht)) + (by intro t ht; exact hlbound ht (hright t ht)) + (by intro t ht x hx; have hb := hcbd t ht x hx; dsimp [k]; linarith [le_max_left C 0]) + (by + intro t ht x hx + have hp := mul_nonneg (hepos t).le (hpde t ht x hx) + have hb : c t x-k≤0 := by have hb := hcbd t ht x hx; dsimp [k]; linarith [le_max_left C 0] + have hbε := mul_nonpos_of_nonpos_of_nonneg hb hε + nlinarith only [hp,hbε]) + intro t ht x hx + have hn := hh t ht x hx + have heinv : e t*Real.exp (k*t)=1 := by + dsimp [e] + rw [←Real.exp_add, neg_mul, neg_add_cancel, Real.exp_zero] + have hmul : 0≤Real.exp (k*t)*(e t*u t x+ε) := mul_nonneg (Real.exp_pos _).le hn + have heq : Real.exp (k*t)*(e t*u t x+ε)=u t x+ε*Real.exp (k*t) := by + calc + _ = (e t*Real.exp (k*t))*u t x+ε*Real.exp (k*t) := by ring + _ = _ := by rw [heinv,one_mul] + rw [heq] at hmul + change -ε*Real.exp (k*t)≤u t x + linarith + +end SKValue + +end + +end OAI diff --git a/lean/OAI/Probability/SKValue/Equations/ParametricChain.lean b/lean/OAI/Probability/SKValue/Equations/ParametricChain.lean new file mode 100644 index 0000000000000000000000000000000000000000..99f499996e291b56c0d9a13b01c0fe81376b86d6 --- /dev/null +++ b/lean/OAI/Probability/SKValue/Equations/ParametricChain.lean @@ -0,0 +1,63 @@ +import Mathlib + +namespace OAI + +section + +open MeasureTheory ProbabilityTheory Set Filter Asymptotics +open scoped Topology NNReal ENNReal BigOperators Convex +namespace SKValue + +theorem parametric_spatial_error + {α 𝕜 E F : Type*} [NontriviallyNormedField 𝕜] [IsRCLikeNormedField 𝕜] [NormedAddCommGroup E] + [NormedSpace ℝ E] [NormedSpace 𝕜 E] [NormedAddCommGroup F] [NormedSpace 𝕜 F] + {u : E} {v w : α → E} {l : Filter α} (hv : Tendsto v l (𝓝 u)) (hw : Tendsto w l (𝓝 u)) + (s : Set E := Set.univ) (seg : ∀ᶠ χ in l, [w χ -[ℝ] v χ] ⊆ s := by simp) + {f : α → E → F} {f' : α → E → E →L[𝕜] F} + (df' : ∀ᶠ p in l ×ˢ 𝓝[s] u, HasFDerivWithinAt (f p.1) (f' p.1 p.2) s p.2) + {φ : E →L[𝕜] F} (cf' : Tendsto ↿f' (l ×ˢ 𝓝[s] u) (𝓝 φ)) : + (fun χ => f χ (v χ) - f χ (w χ) - φ (v χ - w χ)) =o[l] (fun χ => v χ - w χ) := by + rw [isLittleO_iff] + intro ε hε + replace df' : ∀ᶠ χ in l, ∀ z ∈ [w χ -[ℝ] v χ], HasFDerivWithinAt (f χ) (f' χ z) s z := + df'.segment_of_prod_nhdsWithin hw hv seg + replace cf' : ∀ᶠ χ in l, ∀ z ∈ [w χ -[ℝ] v χ], ‖f' χ z - φ‖ < ε := by + simp_rw [Metric.tendsto_nhds, dist_eq_norm_sub] at cf' + exact (cf' ε hε).segment_of_prod_nhdsWithin hw hv seg + filter_upwards [seg, df', cf'] with χ seg df' cf' + exact Convex.norm_image_sub_le_of_norm_hasFDerivWithin_le' + (fun z hz => (df' z hz).mono seg) (fun z hz => (cf' z hz).le) + (convex_segment ..) (left_mem_segment ..) (right_mem_segment ..) + +lemma hasDerivAt_parametric_comp {f fx : ℝ → ℝ → ℝ} {φ : ℝ → ℝ} {t a b : ℝ} + (hd : HasDerivAt (fun s ↦ f s (φ t)) a t) (hφ : HasDerivAt φ b t) + (hx : ∀ᶠ p : ℝ×ℝ in 𝓝 (t,φ t), HasDerivAt (f p.1) (fx p.1 p.2) p.2) + (hc : ContinuousAt (fun p : ℝ×ℝ ↦ fx p.1 p.2) (t,φ t)) : + HasDerivAt (fun s ↦ f s (φ s)) (a+fx t (φ t)*b) t := by + have hsp := parametric_spatial_error hφ.continuousAt tendsto_const_nhds + (s := Set.univ) (seg := by simp) (f := f) (f' := fun s x ↦ (1 : ℝ →L[ℝ] ℝ).smulRight (fx s x)) + (φ := (1 : ℝ →L[ℝ] ℝ).smulRight (fx t (φ t))) + (df' := by + rw [nhdsWithin_univ,←nhds_prod_eq] + exact hx.mono (fun p hp ↦ hp.hasFDerivAt.hasFDerivWithinAt)) + (cf' := by + rw [nhdsWithin_univ,←nhds_prod_eq] + exact (ContinuousLinearMap.smulRightL ℝ ℝ ℝ 1).continuous.continuousAt.comp hc) + have hsmall := (hsp.trans_isBigO hφ.isBigO_sub).add + (hd.isLittleO.add (hφ.isLittleO.const_mul_left (fx t (φ t)))) + apply HasDerivAt.of_isLittleO + have heq : (fun s ↦ f s (φ s)-f s (φ t)- + (1 : ℝ →L[ℝ] ℝ).smulRight (fx t (φ t)) (φ s-φ t) + + ((f s (φ t)-f t (φ t)-(s-t) • a)+fx t (φ t)*(φ s-φ t-(s-t) • b))) = + (fun s ↦ f s (φ s)-f t (φ t)-(s-t) • (a+fx t (φ t)*b)) := by + funext s + simp only [ContinuousLinearMap.smulRight_apply,one_apply_eq_self,smul_eq_mul] + ring + rw [heq] at hsmall + exact hsmall + +end SKValue + +end + +end OAI diff --git a/lean/OAI/Probability/SKValue/Equations/PolynomialForced.lean b/lean/OAI/Probability/SKValue/Equations/PolynomialForced.lean new file mode 100644 index 0000000000000000000000000000000000000000..1cbf65119952526e592a621a4b678229ee75c552 --- /dev/null +++ b/lean/OAI/Probability/SKValue/Equations/PolynomialForced.lean @@ -0,0 +1,69 @@ +import Mathlib +import OAI.Probability.SKValue.Equations.ForcedGenerator +import OAI.Probability.SKValue.Evolution.HigherPDE + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped Topology NNReal BigOperators ContDiff +namespace SKValue +lemma BoundedJoint.at_continuous {T:ℝ} {F:ℝ → ℝ → ℝ} (h:BoundedJoint T F) (x:ℝ): + ContinuousOn (fun t ↦ F t x) (Icc (0:ℝ) T) := + h.continuous.comp (continuousOn_id.prodMk continuousOn_const) + ((mapsTo_id _).prodMk (mapsTo_univ (fun _ ↦ x) _)) +lemma BoundedJoint.slice {T:ℝ} {F:ℝ → ℝ → ℝ} (h:BoundedJoint T F) {t:ℝ} + (ht:t∈Icc (0:ℝ) T):Continuous (F t) := by + obtain ⟨L,hl⟩:=h.spatial + exact (hl t ht).continuous +lemma SmoothEvolution.polynomial_forced {T:ℝ} {γ:ℝ → ℝ} {V:ℝ → ℝ → ℝ} + (h:SmoothEvolution T γ V) (hT:0≤T) (hi:IntervalIntegrable γ volume 0 T) + (hm:MonotoneOn γ (Icc (0:ℝ) T)) (hn:∀t∈Icc (0:ℝ) T,0≤γ t) + (hu:∀t∈Icc (0:ℝ) T,∀x,|deriv (V t) x|≤1) (e:JetExpr): + ∃ K L:ℝ,ForcedTest T γ (fun t ↦ deriv (V t)) (polyJet V e) + (polyJet V e.timeB) (polyJet V e.timeP) K L := by + obtain ⟨A,hA,ha⟩:=(h.polyJet_joint e).bounded + obtain ⟨B,hB,hb⟩:=(h.polyJet_joint (e.spatialIter 1)).bounded + obtain ⟨C,hC,hc⟩:=(h.polyJet_joint (e.spatialIter 2)).bounded + obtain ⟨D,hD,hd⟩:=(h.polyJet_joint (e.spatialIter 3)).bounded + obtain ⟨E,hE,he⟩:=(h.polyJet_joint e.timeB).bounded + obtain ⟨F,hF,hf⟩:=(h.polyJet_joint e.timeP).bounded + obtain ⟨L,hL,hl⟩:=(h.polyJet_joint e.timeB).joint + obtain ⟨M,hM,hm'⟩:=(h.polyJet_joint e.timeP).joint + refine ⟨A+B+C+D+E+F,L+M,⟨by positivity,by positivity,hn,hm,?_,hu,?_,?_,?_,?_,?_,?_,?_,?_,?_,?_,?_,?_,?_,?_⟩⟩ + · intro t ht;exact ((h.slices t ht).jets.smooth.continuous).measurable + · intro t ht;exact (h.polyJet_smooth e ht).of_le (ENat.natCast_le_of_coe_top_le_withTop le_rfl 3) + · intro t ht x;linarith [ha t ht x] + · intro t ht x + have hh:=hb t ht x + rw [←h.polyJet_iterated e ht 1,iteratedDeriv_one] at hh + linarith + · intro t ht x + have hh:=hc t ht x + rw [←h.polyJet_iterated e ht 2] at hh + simp only [show (2:ℕ)=1+1 from rfl,iteratedDeriv_succ,iteratedDeriv_zero] at hh + linarith + · intro t ht x + have hh:=hd t ht x + rw [←h.polyJet_iterated e ht 3] at hh + linarith + · intro t ht;exact ((h.polyJet_joint e.timeB).slice ht).measurable + · intro t ht;exact ((h.polyJet_joint e.timeP).slice ht).measurable + · intro t ht x;linarith [he t ht x] + · intro t ht x;linarith [hf t ht x] + · intro t ht s hs x y + exact (hl t ht s hs x y).trans (mul_le_mul_of_nonneg_right (le_add_of_nonneg_right hM) (by positivity)) + · intro t ht s hs x y + exact (hm' t ht s hs x y).trans (mul_le_mul_of_nonneg_right (le_add_of_nonneg_left hL) (by positivity)) + · intro y + apply ContinuousOn.intervalIntegrable + simpa only [uIcc_of_le hT] using (h.polyJet_joint e.timeB).at_continuous y + · intro y + apply hi.mul_continuousOn + simpa only [uIcc_of_le hT] using (h.polyJet_joint e.timeP).at_continuous y + · intro a ha b hb x;exact h.polyJet_pde hi hm ha hb e x +end SKValue + +end + +end OAI diff --git a/lean/OAI/Probability/SKValue/Equations/PolynomialMoment.lean b/lean/OAI/Probability/SKValue/Equations/PolynomialMoment.lean new file mode 100644 index 0000000000000000000000000000000000000000..cc084142900b144a5b8ea2bb6a180d15281138ab --- /dev/null +++ b/lean/OAI/Probability/SKValue/Equations/PolynomialMoment.lean @@ -0,0 +1,84 @@ +import Mathlib +import OAI.Probability.SKValue.Evolution.HigherPDE +import OAI.Probability.SKValue.Control.PolynomialGenerator + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped Topology NNReal BigOperators +namespace SKValue +noncomputable def jetMoment (W:BrownianSpace) (γ:OrderParameter) (X:ℝ → W.Ω → ℝ) + (e:JetExpr) (t:ℝ):ℝ := ∫ z,polyJet (phi W γ) e t (X t z) ∂W.μ +lemma IsDiffusion.jetMoment_continuous {W:BrownianSpace} {γ:OrderParameter} {X:ℝ → W.Ω → ℝ} + (hX:IsDiffusion W γ X) {T:ℝ} (hT:T∈Ico (0:ℝ) 1) (e:JetExpr): + ContinuousOn (jetMoment W γ X e) (Icc (0:ℝ) T) := by + have hj:=(phi_evolution W γ hT).polyJet_joint e + obtain ⟨C,hC,hb⟩:=hj.bounded + apply mean_observable_continuous hj.continuous hb + · intro t ht;exact (hX.memLp (p:=2) ⟨ht.1,ht.2.trans hT.2.le⟩ (by norm_num)).aestronglyMeasurable + · obtain ⟨Kv,Lv,K,L,D,Lu,La,hV,hG,hD,hLu,hLa,hDb,hu,ha⟩:=sourceStripRegularity W γ T hT + exact (hX.strip_paths hT.1 hT.2 hLu (fun t ht s hs x y ↦ hu s hs t ht y x)).mono (fun _ hz ↦ hz.1) +lemma IsDiffusion.jetMoment_hasDerivAt {W:BrownianSpace} {γ:OrderParameter} {X:ℝ → W.Ω → ℝ} + (hX:IsDiffusion W γ X) {t:ℝ} (ht:t∈Ioo (0:ℝ) 1) (hγ:ContinuousAt γ.coeff t) + (e:JetExpr):HasDerivAt (jetMoment W γ X e) + (jetMoment W γ X e.sourceA t+γ.coeff t*jetMoment W γ X e.sourceP t) t := by + obtain ⟨S,htS,hS⟩:=exists_between ht.2 + have hS0:0≤S:=ht.1.le.trans htS.le + have hSt:S∈Ico (0:ℝ) 1:=⟨hS0,hS⟩ + let F:=fun r ↦ jetMoment W γ X e.sourceA r+γ.coeff r*jetMoment W γ X e.sourceP r + have hcA:=hX.jetMoment_continuous hSt e.sourceA + have hcP:=hX.jetMoment_continuous hSt e.sourceP + have hmono:MonotoneOn γ.coeff (uIcc (0:ℝ) S) := by + rw [uIcc_of_le hS0];exact γ.monotone.mono (fun _ hr ↦ ⟨hr.1,hr.2.trans_lt hS⟩) + have hi:IntervalIntegrable F volume 0 S := by + apply IntervalIntegrable.add + · exact ContinuousOn.intervalIntegrable (by simpa only [uIcc_of_le hS0] using hcA) + · exact hmono.intervalIntegrable.mul_continuousOn (by simpa only [uIcc_of_le hS0] using hcP) + have hn:Icc (0:ℝ) S∈𝓝 t:=Icc_mem_nhds ht.1 htS + have hc:ContinuousAt F t := (hcA.continuousAt hn).add (hγ.mul (hcP.continuousAt hn)) + have hsub:uIcc (0:ℝ) t⊆uIcc (0:ℝ) S:=by + rw [uIcc_of_le ht.1.le,uIcc_of_le hS0];exact Icc_subset_Icc le_rfl htS.le + have hIi:IntegrableOn F (Icc (0:ℝ) S) volume := by + simpa only [uIcc_of_le hS0] using (intervalIntegrable_iff').mp hi + have hd:=((intervalIntegral.integral_hasDerivAt_right (hi.mono_set hsub) + ⟨Icc (0:ℝ) S,hn,hIi.aestronglyMeasurable⟩ hc).const_add (polyJet (phi W γ) e 0 0)) + apply hd.congr_of_eventuallyEq + filter_upwards [Ioo_mem_nhds ht.1 htS] with s hs + exact hX.polyJet_generator hs.1 (hs.2.trans hS) e +end SKValue + +end + +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped Topology NNReal +namespace SKValue +namespace JetExpr +noncomputable def square (e:JetExpr):JetExpr := mul e e +noncomputable def cube (e:JetExpr):JetExpr := mul (mul e e) e +noncomputable def momentExpr : JetExpr := square (coord 0) +noncomputable def curvatureExpr : JetExpr := square (coord 1) +noncomputable def curvatureSlope (c:ℝ) : JetExpr := add (square (coord 2)) (mul (const (-2*c)) (cube (coord 1))) +lemma momentExpr_eval (R:ℕ → ℝ):eval R momentExpr=(R 0)^2 := by simp only [momentExpr,square,eval,pow_two] +lemma curvatureExpr_eval (R:ℕ → ℝ):eval R curvatureExpr=(R 1)^2 := by simp only [curvatureExpr,square,eval,pow_two] +lemma curvatureSlope_eval (R:ℕ → ℝ) (c:ℝ):eval R (curvatureSlope c)=(R 2)^2-2*c*(R 1)^3 := by + simp only [curvatureSlope,square,cube,eval];ring +lemma momentExpr_sourceA (R:ℕ → ℝ):eval R momentExpr.sourceA=eval R curvatureExpr := by + norm_num [momentExpr,curvatureExpr,square,sourceA,timeB,spatialIter,spatial,D,eval];ring +lemma momentExpr_sourceP (R:ℕ → ℝ):eval R momentExpr.sourceP=0 := by + norm_num [momentExpr,square,sourceP,timeP,spatialIter,spatial,D,eval];ring +lemma curvatureExpr_sourceA (R:ℕ → ℝ):eval R curvatureExpr.sourceA=(R 2)^2 := by + norm_num [curvatureExpr,square,sourceA,timeB,spatialIter,spatial,D,eval];ring +lemma curvatureExpr_sourceP (R:ℕ → ℝ):eval R curvatureExpr.sourceP= -2*(R 1)^3 := by + norm_num [curvatureExpr,square,sourceP,timeP,spatialIter,spatial,D,eval];ring +lemma curvatureSlope_sourceA (R:ℕ → ℝ) (c:ℝ):eval R (curvatureSlope c).sourceA=(R 3)^2-6*c*R 1*(R 2)^2 := by + norm_num [curvatureSlope,square,cube,sourceA,timeB,spatialIter,spatial,D,eval];ring +lemma curvatureSlope_sourceP (R:ℕ → ℝ) (c:ℝ):eval R (curvatureSlope c).sourceP= -6*R 1*(R 2)^2+6*c*(R 1)^4 := by + norm_num [curvatureSlope,square,cube,sourceP,timeP,spatialIter,spatial,D,eval];ring +end JetExpr +end SKValue + +end + +end OAI diff --git a/lean/OAI/Probability/SKValue/Equations/PolynomialObservable.lean b/lean/OAI/Probability/SKValue/Equations/PolynomialObservable.lean new file mode 100644 index 0000000000000000000000000000000000000000..739413d9dcae9a80869ad627bfeae42e907ebfe1 --- /dev/null +++ b/lean/OAI/Probability/SKValue/Equations/PolynomialObservable.lean @@ -0,0 +1,160 @@ +import Mathlib +import OAI.Probability.SKValue.Evolution.SmoothFamily + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped Topology NNReal BigOperators ContDiff +namespace SKValue +structure BoundedJoint (T:ℝ) (F:ℝ → ℝ → ℝ) : Prop where + bounded : ∃ C:ℝ,0≤C ∧ ∀ t∈Icc (0:ℝ) T,∀ x,|F t x|≤C + joint : ∃ L:ℝ,0≤L ∧ ∀ t∈Icc (0:ℝ) T,∀ s∈Icc (0:ℝ) T,∀ x y, + |F s y-F t x|≤L*(|s-t|+|y-x|) +lemma BoundedJoint.const (T c:ℝ):BoundedJoint T (fun _ _ ↦ c) := by + refine ⟨⟨|c|,abs_nonneg c,fun _ _ _ ↦ le_rfl⟩,⟨0,le_rfl,?_⟩⟩ + intros;simp +lemma BoundedJoint.add {T:ℝ} {F G:ℝ → ℝ → ℝ} (hF:BoundedJoint T F) (hG:BoundedJoint T G): + BoundedJoint T (fun t x ↦ F t x+G t x) := by + obtain ⟨A,hA,hFA⟩:=hF.bounded;obtain ⟨B,hB,hGB⟩:=hG.bounded + obtain ⟨L,hL,hFL⟩:=hF.joint;obtain ⟨M,hM,hGM⟩:=hG.joint + refine ⟨⟨A+B,add_nonneg hA hB,fun t ht x ↦ (abs_add_le _ _).trans (add_le_add (hFA t ht x) (hGB t ht x))⟩, + ⟨L+M,add_nonneg hL hM,?_⟩⟩ + intro t ht s hs x y + calc + _ = |(F s y-F t x)+(G s y-G t x)| := by congr 1;ring + _ ≤ |F s y-F t x|+|G s y-G t x| := abs_add_le _ _ + _ ≤ L*(|s-t|+|y-x|)+M*(|s-t|+|y-x|) := add_le_add (hFL t ht s hs x y) (hGM t ht s hs x y) + _ = _ := by ring +lemma BoundedJoint.mul {T:ℝ} {F G:ℝ → ℝ → ℝ} (hF:BoundedJoint T F) (hG:BoundedJoint T G): + BoundedJoint T (fun t x ↦ F t x*G t x) := by + obtain ⟨A,hA,hFA⟩:=hF.bounded;obtain ⟨B,hB,hGB⟩:=hG.bounded + obtain ⟨L,hL,hFL⟩:=hF.joint;obtain ⟨M,hM,hGM⟩:=hG.joint + refine ⟨⟨A*B,mul_nonneg hA hB,?_⟩,⟨L*B+A*M,by positivity,?_⟩⟩ + · intro t ht x;rw [abs_mul];exact mul_le_mul (hFA t ht x) (hGB t ht x) (abs_nonneg _) hA + · intro t ht s hs x y + calc + _ = |(F s y-F t x)*G s y+F t x*(G s y-G t x)| := by congr 1;ring + _ ≤ |(F s y-F t x)*G s y|+|F t x*(G s y-G t x)| := abs_add_le _ _ + _ ≤ L*(|s-t|+|y-x|)*B+A*(M*(|s-t|+|y-x|)) := by + rw [abs_mul,abs_mul] + exact add_le_add (mul_le_mul (hFL t ht s hs x y) (hGB s hs y) (abs_nonneg _) (by positivity)) + (mul_le_mul (hFA t ht x) (hGM t ht s hs x y) (abs_nonneg _) hA) + _ = _ := by ring +lemma BoundedJoint.continuous {T:ℝ} {F:ℝ → ℝ → ℝ} (hF:BoundedJoint T F): + ContinuousOn (fun p:ℝ×ℝ ↦ F p.1 p.2) (Icc (0:ℝ) T ×ˢ univ) := by + obtain ⟨L,hL,hl⟩:=hF.joint + have hh:LipschitzOnWith ⟨2*L,by positivity⟩ (fun p:ℝ×ℝ ↦ F p.1 p.2) (Icc (0:ℝ) T ×ˢ univ) := by + apply LipschitzOnWith.of_dist_le_mul + intro p hp q hq + simp only [Real.dist_eq,Prod.dist_eq] + have hb:=hl q.1 hq.1 p.1 hp.1 q.2 p.2 + change |F p.1 p.2-F q.1 q.2|≤(2*L)*max |p.1-q.1| |p.2-q.2| + nlinarith [le_max_left |p.1-q.1| |p.2-q.2|,le_max_right |p.1-q.1| |p.2-q.2|] + exact hh.continuousOn +lemma BoundedJoint.spatial {T:ℝ} {F:ℝ → ℝ → ℝ} (hF:BoundedJoint T F): + ∃ L:ℝ≥0,∀ t∈Icc (0:ℝ) T,LipschitzWith L (F t) := by + obtain ⟨L,hL,hl⟩:=hF.joint + refine ⟨Real.toNNReal L,fun t ht ↦ ?_⟩ + rw [lipschitzWith_iff_dist_le_mul] + intro x y + simpa only [Real.coe_toNNReal _ hL,Real.dist_eq,sub_self,abs_zero,zero_add] using hl t ht t ht y x +namespace JetExpr +noncomputable def spatial (e:JetExpr):JetExpr := D (fun n ↦ coord (n+1)) e +noncomputable def spatialIter : ℕ → JetExpr → JetExpr + | 0,e => e + | n+1,e => spatial (spatialIter n e) +end JetExpr +noncomputable def polyJet (V:ℝ → ℝ → ℝ) (e:JetExpr) (t x:ℝ):ℝ := + e.eval (fun n ↦ iteratedDeriv n (deriv (V t)) x) +lemma SmoothEvolution.polyJet_joint {T:ℝ} {γ:ℝ → ℝ} {V:ℝ → ℝ → ℝ} + (h:SmoothEvolution T γ V) (e:JetExpr):BoundedJoint T (polyJet V e) := by + induction e with + | const c => exact BoundedJoint.const T c + | coord n => + obtain ⟨L,hL,hl⟩:=h.jet_joint n + exact ⟨h.bound n,⟨L,hL,fun t ht s hs x y ↦ hl s hs t ht x y⟩⟩ + | add e f he hf => exact he.add hf + | mul e f he hf => exact he.mul hf +lemma SmoothEvolution.polyJet_smooth {T:ℝ} {γ:ℝ → ℝ} {V:ℝ → ℝ → ℝ} + (h:SmoothEvolution T γ V) (e:JetExpr) {t:ℝ} (ht:t∈Icc (0:ℝ) T): + ContDiff ℝ ∞ (polyJet V e t) := by + induction e with + | const c => exact contDiff_const + | coord n => exact ((h.slices t ht).jets.iteratedDeriv n).smooth + | add e f he hf => exact he.add hf + | mul e f he hf => exact he.mul hf +lemma SmoothEvolution.polyJet_hasDeriv {T:ℝ} {γ:ℝ → ℝ} {V:ℝ → ℝ → ℝ} + (h:SmoothEvolution T γ V) (e:JetExpr) {t:ℝ} (ht:t∈Icc (0:ℝ) T) (x:ℝ): + HasDerivAt (polyJet V e t) (polyJet V e.spatial t x) x := by + apply JetExpr.hasDerivAt_eval + intro n + simpa only [JetExpr.eval,iteratedDeriv_succ] using + (((h.slices t ht).jets.iteratedDeriv n).smooth.differentiable (by norm_num) x).hasDerivAt +lemma SmoothEvolution.polyJet_iterated {T:ℝ} {γ:ℝ → ℝ} {V:ℝ → ℝ → ℝ} + (h:SmoothEvolution T γ V) (e:JetExpr) {t:ℝ} (ht:t∈Icc (0:ℝ) T) (n:ℕ): + iteratedDeriv n (polyJet V e t)=polyJet V (e.spatialIter n) t := by + induction n with + | zero => rfl + | succ n ih => + rw [iteratedDeriv_succ,ih] + funext x + exact (h.polyJet_hasDeriv _ ht x).deriv +end SKValue + +end + +section + +open MeasureTheory ProbabilityTheory Set Filter +open scoped Topology NNReal ENNReal BigOperators ContDiff +namespace SKValue + +lemma BoundedSmoothFamily.at_continuous {T:ℝ} {F:ℝ → ℝ → ℝ} + (h:BoundedSmoothFamily T F) (x:ℝ) : ContinuousOn (fun t ↦ F t x) (Icc (0:ℝ) T) := by + have hh := (h.joint 0).comp (continuousOn_id.prodMk continuousOn_const) (fun t ht ↦ ⟨ht,mem_univ x⟩) + simpa only [iteratedDeriv_zero,Function.comp_def,id_eq] using hh + +noncomputable def weightedFamilyIntegral (a b : ℝ) (γ : ℝ → ℝ) (F : ℝ → ℝ → ℝ) (x : ℝ) : ℝ := + ∫ s in a..b, γ s*F s x + +lemma BoundedSmoothFamily.weightedFamilyIntegral_hasDerivAt {T a b : ℝ} {γ : ℝ → ℝ} {F : ℝ → ℝ → ℝ} + (h : BoundedSmoothFamily T F) (hi : IntervalIntegrable γ volume a b) + (ha : 0≤a) (hab : a≤b) (hb : b≤T) (x : ℝ) : + HasDerivAt (weightedFamilyIntegral a b γ F) (weightedFamilyIntegral a b γ (fun t ↦ _root_.deriv (F t)) x) x := by + have hfi (u : ℝ) : IntervalIntegrable (fun s ↦ γ s*F s u) volume a b := by + apply hi.mul_continuousOn + simpa only [uIcc_of_le hab] using (h.at_continuous u).mono (Icc_subset_Icc ha hb) + have hf'i (u : ℝ) : IntervalIntegrable (fun s ↦ γ s*_root_.deriv (F s) u) volume a b := by + apply hi.mul_continuousOn + simpa only [uIcc_of_le hab] using (h.deriv.at_continuous u).mono (Icc_subset_Icc ha hb) + obtain ⟨C,hC,hbd⟩ := h.bound 1 + simp only [iteratedDeriv_one] at hbd + have hi' := (intervalIntegrable_iff_integrableOn_Ioc_of_le hab).mp hi + have hd := hasDerivAt_integral_of_dominated_loc_of_deriv_le + (F := fun u s ↦ γ s*F s u) + (F' := fun u s ↦ γ s*_root_.deriv (F s) u) + (s := univ) (bound := fun s ↦ |γ s| * C) (μ := volume.restrict (Ioc a b)) + univ_mem (Eventually.of_forall (fun u ↦ ((intervalIntegrable_iff_integrableOn_Ioc_of_le hab).mp (hfi u)).aestronglyMeasurable)) + ((intervalIntegrable_iff_integrableOn_Ioc_of_le hab).mp (hfi x)) + ((intervalIntegrable_iff_integrableOn_Ioc_of_le hab).mp (hf'i x)).aestronglyMeasurable + (by + filter_upwards [ae_restrict_mem measurableSet_Ioc] with s hs + intro u _ + rw [Real.norm_eq_abs,abs_mul] + exact mul_le_mul_of_nonneg_left (hbd s ⟨ha.trans hs.1.le,hs.2.trans hb⟩ u) (abs_nonneg _)) + (hi'.abs.mul_const C) + (by + filter_upwards [ae_restrict_mem measurableSet_Ioc] with s hs + intro u _ + have hfs := h.slices s ⟨ha.trans hs.1.le,hs.2.trans hb⟩ + exact ((hfs.smooth.differentiable (by norm_num)) u).hasDerivAt.const_mul (γ s)) + change HasDerivAt (fun u ↦ ∫ s in a..b, γ s*F s u) + (∫ s in a..b, γ s*_root_.deriv (F s) x) x + simpa only [intervalIntegral.integral_of_le hab] using hd.2 + +end SKValue + +end + +end OAI diff --git a/lean/OAI/Probability/SKValue/Equations/ProfileShape.lean b/lean/OAI/Probability/SKValue/Equations/ProfileShape.lean new file mode 100644 index 0000000000000000000000000000000000000000..16d8cb906ab241f92fd730b1ca185e8628eaa03b --- /dev/null +++ b/lean/OAI/Probability/SKValue/Equations/ProfileShape.lean @@ -0,0 +1,65 @@ +import Mathlib +import OAI.Probability.SKValue.Equations.CoupledComparison + +namespace OAI + +section + +open Set Filter +open scoped Topology ContDiff NNReal +namespace SKValue + +lemma profile_backwardShape {M c : ℝ} (hM : 0 exact logCoshTerminal_backwardShape hM hc hcM + | cons p l ih => + obtain ⟨hp,hl⟩ := List.pairwise_cons.mp hl + have hcp : c≤(p.2:ℝ) := hlow p (by simp) + have hp0 : 0<(p.2:ℝ) := hc.trans_le hcp + have hpM : (p.2:ℝ)≤M := hupp p (by simp) + have hlo : ∀ q∈l,c≤(q.2:ℝ) := fun q hq ↦ hlow q (by simp [hq]) + have hup : ∀ q∈l,(q.2:ℝ)≤M := fun q hq ↦ hupp q (by simp [hq]) + change BackwardShape c (patchTime (p.1:ℝ) _ _ t) + by_cases ht : t≤(p.1:ℝ) + · rw [patchTime_left _ _ ht] + have hs := ih hp0 hpM hl (fun q hq ↦ by exact_mod_cast hp q hq) hup 0 + have hψ := (logCoshTerminal_smoothTerminal hM).profile_evolution l + have hsm := hψ.slices 0 ⟨le_rfl,profileTime_nonneg l⟩ + exact (hs.evolve hsm hp0 (sub_nonneg.mpr ht)).lower hp0 hc.le hcp + · rw [patchTime_right _ _ (lt_of_not_ge ht)] + exact ih hc hcM hl hlo hup _ + +end SKValue + +end + +section + +open Set Filter +open scoped Topology +namespace SKValue +lemma moving_partial_deriv {f ft fx : ℝ → ℝ → ℝ} {p q : ℝ → ℝ} {p' q' t : ℝ} + (hdt : ∀ᶠ z : ℝ×ℝ in 𝓝 (p t,q t), HasDerivAt (f · z.2) (ft z.1 z.2) z.1) + (hdx : ∀ᶠ z : ℝ×ℝ in 𝓝 (p t,q t), HasDerivAt (f z.1) (fx z.1 z.2) z.2) + (hct : ContinuousAt (fun z : ℝ×ℝ ↦ ft z.1 z.2) (p t,q t)) + (hcx : ContinuousAt (fun z : ℝ×ℝ ↦ fx z.1 z.2) (p t,q t)) + (hp : HasDerivAt p p' t) (hq : HasDerivAt q q' t) : + HasDerivAt (fun s ↦ f (p s) (q s)) (ft (p t) (q t)*p'+fx (p t) (q t)*q') t := by + have hd := hasStrictFDerivAt_uncurry_coprod + (f₁ := fun a b ↦ ContinuousLinearMap.toSpanSingleton ℝ (ft a b)) + (f₂ := fun a b ↦ ContinuousLinearMap.toSpanSingleton ℝ (fx a b)) + (hdt.mono (fun z hz ↦ hz.hasFDerivAt)) + (hdx.mono (fun z hz ↦ hz.hasFDerivAt)) + (ContinuousLinearMap.toSpanSingletonCLE.continuous.continuousAt.comp hct) + (ContinuousLinearMap.toSpanSingletonCLE.continuous.continuousAt.comp hcx) + convert! hd.hasFDerivAt.comp_hasDerivAt t (hp.prodMk hq) using 1 + change ft (p t) (q t)*p'+fx (p t) (q t)*q'=p'*ft (p t) (q t)+q'*fx (p t) (q t) + ring +end SKValue + +end + +end OAI diff --git a/lean/OAI/Probability/SKValue/Equations/RawIncrement.lean b/lean/OAI/Probability/SKValue/Equations/RawIncrement.lean new file mode 100644 index 0000000000000000000000000000000000000000..8a901fa9c1702e019e507498c881ceb38c4b9a9c --- /dev/null +++ b/lean/OAI/Probability/SKValue/Equations/RawIncrement.lean @@ -0,0 +1,420 @@ +import Mathlib +import OAI.Probability.SKValue.Evolution.UniformGridRiemannBound +import OAI.Probability.SKValue.Equations.FirstMomentPerturbation + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set +open scoped ENNReal NNReal BigOperators +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators Topology +open MeasureTheory ProbabilityTheory Set Filter +open scoped Topology BigOperators +open MeasureTheory ProbabilityTheory Set Filter +open scoped Topology ENNReal NNReal +open Filter Set +open scoped Topology BigOperators +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology +open MeasureTheory Set Filter +open scoped Topology BigOperators +open MeasureTheory Set Filter Finset +open scoped Topology BigOperators +namespace SKValue +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology BigOperators + +noncomputable def rawIncrement {N : ℕ} (H : (Fin (N+1) → ℝ) → ℝ) (j : ℕ) : + (Fin (N+1) → ℝ) → ℝ := fun z ↦ H z * coordinate N j z + +lemma rawIncrement_memLp {N j : ℕ} {H : (Fin (N+1) → ℝ) → ℝ} + (hj : j exact hb x + | cons p l ih => + simp only [profileResponse] + by_cases ht:t ≤ (p.1:ℝ) + · rw [patchTime_left _ _ ht,patchTime_left _ _ ht] + exact responseJet_zero_contraction + ((hψ.profile_evolution l).slices 0 ⟨le_rfl,profileTime_nonneg l⟩) + ((hψ.linear_profile hf l).slices 0 ⟨le_rfl,profileTime_nonneg l⟩) + ((hψ.linear_profile hg l).slices 0 ⟨le_rfl,profileTime_nonneg l⟩) + p.2.coe_nonneg (fun y ↦ ih 0 y) _ x + · rw [patchTime_right _ _ (lt_of_not_ge ht),patchTime_right _ _ (lt_of_not_ge ht)] + exact ih _ x +end SKValue + +end + +end OAI diff --git a/lean/OAI/Probability/SKValue/Equations/ResponseJets.lean b/lean/OAI/Probability/SKValue/Equations/ResponseJets.lean new file mode 100644 index 0000000000000000000000000000000000000000..d008931241d634c3b0f810279f2dd0bbb73a16d0 --- /dev/null +++ b/lean/OAI/Probability/SKValue/Equations/ResponseJets.lean @@ -0,0 +1,116 @@ +import Mathlib +import OAI.Probability.SKValue.Evolution.TestHeat + +namespace OAI + +section + +open MeasureTheory ProbabilityTheory Set Filter +open scoped Topology ContDiff NNReal +namespace SKValue +noncomputable def combinedJet (c:ℝ) (ψ f:ℝ → ℝ) (j:ℕ) (t x:ℝ) : ℝ := + if j%2=0 then baseJet c ψ (j/2) t x else responseJet c ψ f (j/2) t x +lemma combinedJet_even (c:ℝ) (ψ f:ℝ → ℝ) (j:ℕ) (t x:ℝ) : + combinedJet c ψ f (2*j) t x=baseJet c ψ j t x := by simp [combinedJet] +lemma combinedJet_odd (c:ℝ) (ψ f:ℝ → ℝ) (j:ℕ) (t x:ℝ) : + combinedJet c ψ f (2*j+1) t x=responseJet c ψ f j t x := by simp [combinedJet,Nat.add_div] +lemma baseJet_continuous {ψ:ℝ → ℝ} (hψ:SmoothTerminal ψ) {c:ℝ} (hc:0≤c) (j:ℕ) : + Continuous (fun p:ℝ×ℝ ↦ baseJet c ψ j p.1 p.2) := + heat_normalizedJet_continuous ((contDiff_const.mul hψ.smooth).exp) + (exp_iteratedDeriv_growth hψ.lipschitz hψ.smooth hψ.jets hc) + (fun t x ↦ (lipschitz_exp_integral_pos hψ.lipschitz hc x (Real.sqrt t)).ne') j +lemma baseJet_time {ψ:ℝ → ℝ} (hψ:SmoothTerminal ψ) {c t:ℝ} (hc:0≤c) (ht:0 coord 1 + | n+1 => D responseσx (responseExpr n) +lemma eval_responseσx (R:ℕ → ℝ) (j:ℕ) : eval R (responseσx j)=R (j+2)-R j*R 2 := by + simp only [responseσx,eval];ring +lemma eval_responseσt (R:ℕ → ℝ) (j:ℕ) : eval R (responseσt j)=(1/2:ℝ)*(R (j+4)-R j*R 4) := by + simp only [responseσt,eval];ring +end JetExpr +lemma responseJet_zero_expr {ψ f:ℝ → ℝ} (hψ:SmoothTerminal ψ) (hf:BoundedSmooth f) + {c:ℝ} (hc:0≤c) (n:ℕ) (t:ℝ) : + iteratedDeriv n (responseJet c ψ f 0 t)= + fun x ↦ JetExpr.eval (fun j ↦ combinedJet c ψ f j t x) (JetExpr.responseExpr n) := by + induction n with + | zero => simp only [iteratedDeriv_zero,JetExpr.responseExpr,JetExpr.eval];rfl + | succ n ih => + rw [iteratedDeriv_succ,ih] + funext x + apply HasDerivAt.deriv + apply JetExpr.hasDerivAt_eval + intro j + simpa only [JetExpr.eval_responseσx] using combinedJet_space hψ hf hc j t x +lemma responseJet_joint_jets {ψ f:ℝ → ℝ} (hψ:SmoothTerminal ψ) (hf:BoundedSmooth f) + {c:ℝ} (hc:0≤c) (n:ℕ) : + Continuous (fun p:ℝ×ℝ ↦ iteratedDeriv n (responseJet c ψ f 0 p.1) p.2) := by + simp_rw [responseJet_zero_expr hψ hf hc] + exact JetExpr.continuous_eval (combinedJet_continuous hψ hf hc) _ +lemma responseJet_time_jets {ψ f:ℝ → ℝ} (hψ:SmoothTerminal ψ) (hf:BoundedSmooth f) + {c:ℝ} (hc:0≤c) (n:ℕ) : + ∃ d:ℝ → ℝ → ℝ,Continuous (fun p:ℝ×ℝ ↦ d p.1 p.2) ∧ + (∃ C:ℝ,0≤C ∧ ∀ t x,|d t x|≤C) ∧ + ∀ t x,0 linarith [ht.1,ht.2] + have ha' : a∈Icc (0 : ℝ) T := ⟨ha,hab.trans hb⟩ + have hb' : b∈Icc (0 : ℝ) T := ⟨ha.trans hab,hb⟩ + refine ⟨h.K_nonneg,h.L_nonneg,fun t ht ↦ h.gamma_nonneg _ (hmem t ht),?_, + fun t ht ↦ h.smooth _ (hmem t ht),fun t ht ↦ h.bounded _ (hmem t ht), + fun t ht ↦ h.second_bound _ (hmem t ht),fun t ht ↦ h.third_bound _ (hmem t ht), + fun t ht ↦ h.product_bound _ (hmem t ht),?_,?_,?_,?_,?_⟩ + · intro s hs t ht hst + exact h.gamma_mono (hmem s hs) (hmem t ht) (add_le_add le_rfl hst) + · intro t ht s hs x y + simpa only [add_sub_add_left_eq_sub] using h.second_lipschitz _ (hmem t ht) _ (hmem s hs) x y + · intro t ht s hs x y + simpa only [add_sub_add_left_eq_sub] using h.product_lipschitz _ (hmem t ht) _ (hmem s hs) x y + · intro x + have hi := intervalIntegrable_substrip hT (h.second_integrable x) ha' hb' + simpa only [sub_self] using hi.comp_add_left a + · intro x + have hi := intervalIntegrable_substrip hT (h.product_integrable x) ha' hb' + simpa only [sub_self] using hi.comp_add_left a + · intro t ht s hs x + rw [intervalIntegral.integral_comp_add_left + (fun r ↦ (1/2 : ℝ)*deriv (deriv (u r)) x+γ r*(u r x*deriv (u r) x)) a] + exact h.pde _ (hmem t ht) _ (hmem s hs) x + +lemma diffusion_gradient_condExp_local + {Ω : Type*} [MeasurableSpace Ω] {μ : Measure Ω} [IsProbabilityMeasure μ] + {B : ℝ≥0 → Ω → ℝ} (hB : IsPreBrownianReal B μ) + (hBm : ∀ t, StronglyMeasurable (B t)) (a : ℝ≥0) + {T K L Lu : ℝ} {γ : ℝ → ℝ} {u : ℝ → ℝ → ℝ} {X W : ℝ → Ω → ℝ} + (hT : 0 simp [hω] + have heq := diffusion_gradient_weak_martingale_local hB hBm a hT hT1 hLu (by norm_num : (0:ℝ)≤1) + h hLip hXM hWM hW hpaths hF hFb + have hprod (t : ℝ) : (fun ω ↦ s.indicator (fun _ : Ω ↦ (1 : ℝ)) ω*u t (X t ω))= + s.indicator (fun ω ↦ u t (X t ω)) := by + funext ω + by_cases hω : ω∈s <;> simp [hω] + rw [hprod T,hprod 0,integral_indicator (ℱ.le a s hs),integral_indicator (ℱ.le a s hs)] at heq + exact heq.symm + +end SKValue + +end + +end OAI diff --git a/lean/OAI/Probability/SKValue/Equations/ShiftedPairing.lean b/lean/OAI/Probability/SKValue/Equations/ShiftedPairing.lean new file mode 100644 index 0000000000000000000000000000000000000000..1a3d4f37e239ed763ca1f174e8d49c17564883ff --- /dev/null +++ b/lean/OAI/Probability/SKValue/Equations/ShiftedPairing.lean @@ -0,0 +1,210 @@ +import Mathlib + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set +open scoped ENNReal NNReal BigOperators +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators Topology +open MeasureTheory ProbabilityTheory Set Filter +open scoped Topology BigOperators +open MeasureTheory ProbabilityTheory Set Filter +open scoped Topology ENNReal NNReal +open Filter Set +open scoped Topology BigOperators +namespace SKValue + +lemma abs_sum_mul_le_of_sq_bounds {ι : Type*} [Fintype ι] + {x y : ι → ℝ} {a b : ℝ} (ha : 0≤a) (hb : 0≤b) + (hx : (∑ i, (x i)^2)≤a^2) (hy : (∑ i, (y i)^2)≤b^2) : + |∑ i, x i*y i|≤a*b := by + have hcs := Finset.sum_mul_sq_le_sq_mul_sq Finset.univ x y + have hmul := mul_le_mul hx hy (Finset.sum_nonneg (fun i _ ↦ sq_nonneg (y i))) (sq_nonneg a) + have hs : |∑ i, x i*y i|^2≤(a*b)^2 := by simpa only [sq_abs, mul_pow] using hcs.trans hmul + exact (sq_le_sq₀ (abs_nonneg _) (mul_nonneg ha hb)).1 hs + +lemma sum_fin_castSucc_sq_le {N : ℕ} (f : Fin (N+1) → ℝ) : + (∑ i : Fin N, (f i.castSucc)^2)≤∑ i, (f i)^2 := by + rw [Fin.sum_univ_castSucc] + exact le_add_of_nonneg_right (sq_nonneg _) + +lemma sum_fin_succ_sq_le {N : ℕ} (f : Fin (N+1) → ℝ) : + (∑ i : Fin N, (f i.succ)^2)≤∑ i, (f i)^2 := by + rw [Fin.sum_univ_succ] + exact le_add_of_nonneg_left (sq_nonneg _) + +lemma pointwise_le_sqrt_sum_sq {ι : Type*} [Fintype ι] (f : ι → ℝ) (j : ι) : + |f j|≤Real.sqrt (∑ i, (f i)^2) := by + have hsq : (f j)^2≤∑ i, (f i)^2 := + Finset.single_le_sum (fun i _ ↦ sq_nonneg (f i)) (Finset.mem_univ j) + exact (Real.le_sqrt (abs_nonneg _) (Finset.sum_nonneg (fun i _ ↦ sq_nonneg (f i)))).2 + (by simpa only [sq_abs] using hsq) + +def shiftedPairing {N : ℕ} (A B : Fin (N+1) → ℝ) (bstar : ℝ) : ℝ := + (∑ i : Fin N, A i.castSucc*B i.succ)+A (Fin.last N)*bstar + +lemma shiftedPairing_error {N : ℕ} {A B α β : Fin (N+1) → ℝ} {bstar e C : ℝ} + (he : 0≤e) (hC : 0≤C) + (hA : (∑ i, (A i-α i)^2)≤e) (hB : (∑ i, (B i-β i)^2)≤e) + (hBn : (∑ i, (B i)^2)≤1) (hαn : (∑ i, (α i)^2)≤C^2) + (hb : |bstar|≤1) : + |shiftedPairing A B bstar-∑ i : Fin N, α i.castSucc*β i.succ| ≤ + (2+C)*Real.sqrt e+|α (Fin.last N)| := by + have hAe : (∑ i : Fin N, (A i.castSucc-α i.castSucc)^2)≤(Real.sqrt e)^2 := by + rw [Real.sq_sqrt he] + exact (sum_fin_castSucc_sq_le (fun i ↦ A i-α i)).trans hA + have hBe : (∑ i : Fin N, (B i.succ-β i.succ)^2)≤(Real.sqrt e)^2 := by + rw [Real.sq_sqrt he] + exact (sum_fin_succ_sq_le (fun i ↦ B i-β i)).trans hB + have hBns : (∑ i : Fin N, (B i.succ)^2)≤(1 : ℝ)^2 := by + simpa using (sum_fin_succ_sq_le B).trans hBn + have hαns : (∑ i : Fin N, (α i.castSucc)^2)≤C^2 := (sum_fin_castSucc_sq_le α).trans hαn + have hfirst := abs_sum_mul_le_of_sq_bounds (Real.sqrt_nonneg e) (by norm_num : (0:ℝ)≤1) hAe hBns + have hsecond := abs_sum_mul_le_of_sq_bounds hC (Real.sqrt_nonneg e) hαns hBe + have hAend : |A (Fin.last N)-α (Fin.last N)|≤Real.sqrt e := + (pointwise_le_sqrt_sum_sq (fun i ↦ A i-α i) (Fin.last N)).trans (Real.sqrt_le_sqrt hA) + have hend : |A (Fin.last N)*bstar|≤Real.sqrt e+|α (Fin.last N)| := by + rw [abs_mul] + calc + _ ≤ |A (Fin.last N)| *1 := mul_le_mul_of_nonneg_left hb (abs_nonneg _) + _ ≤ (|A (Fin.last N)-α (Fin.last N)|+|α (Fin.last N)|)*1 := by + gcongr + simpa only [sub_add_cancel] using + abs_add_le (A (Fin.last N)-α (Fin.last N)) (α (Fin.last N)) + _ ≤ _ := by simpa only [mul_one] using add_le_add hAend le_rfl + have hdecomp : shiftedPairing A B bstar-∑ i : Fin N, α i.castSucc*β i.succ = + (∑ i : Fin N, (A i.castSucc-α i.castSucc)*B i.succ)+ + (∑ i : Fin N, α i.castSucc*(B i.succ-β i.succ))+A (Fin.last N)*bstar := by + unfold shiftedPairing + rw [← Finset.sum_add_distrib] + ring_nf + simp only [Finset.sum_sub_distrib] + ring + rw [hdecomp] + calc + _ ≤ |∑ i : Fin N, (A i.castSucc-α i.castSucc)*B i.succ|+ + |∑ i : Fin N, α i.castSucc*(B i.succ-β i.succ)|+|A (Fin.last N)*bstar| := + (abs_add_le _ _).trans (add_le_add (abs_add_le _ _) le_rfl) + _ ≤ Real.sqrt e*1+C*Real.sqrt e+(Real.sqrt e+|α (Fin.last N)|) := by + exact add_le_add (add_le_add hfirst hsecond) hend + _ = _ := by ring + +lemma shiftedPairing_tendsto_error_zero + {A B α β : (N : ℕ) → Fin (N+1) → ℝ} {bstar e r : ℕ → ℝ} {C : ℝ} + (he : ∀ N, 0≤e N) (hC : 0≤C) + (hA : ∀ᶠ N in atTop, (∑ i, (A N i-α N i)^2)≤e N) + (hB : ∀ᶠ N in atTop, (∑ i, (B N i-β N i)^2)≤e N) + (hBn : ∀ᶠ N in atTop, (∑ i, (B N i)^2)≤1) + (hαn : ∀ᶠ N in atTop, (∑ i, (α N i)^2)≤C^2) + (hb : ∀ᶠ N in atTop, |bstar N|≤1) + (hend : ∀ᶠ N in atTop, |α N (Fin.last N)|≤r N) + (he0 : Tendsto e atTop (𝓝 0)) (hr0 : Tendsto r atTop (𝓝 0)) : + Tendsto (fun N ↦ shiftedPairing (A N) (B N) (bstar N)- + ∑ i : Fin N, α N i.castSucc*β N i.succ) atTop (𝓝 0) := by + apply squeeze_zero_norm' (a := fun N ↦ (2+C)*Real.sqrt (e N)+r N) + · filter_upwards [hA,hB,hBn,hαn,hb,hend] with N hA hB hBn hαn hb hend + rw [Real.norm_eq_abs] + exact (shiftedPairing_error (he N) hC hA hB hBn hαn hb).trans (add_le_add le_rfl hend) + · simpa only [Real.sqrt_zero, mul_zero, add_zero, Function.comp_apply] using + ((Real.continuous_sqrt.tendsto 0).comp he0 |>.const_mul (2+C)).add hr0 + +end SKValue + +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology +namespace SKValue + +lemma integral_sq_le_integral_sq {Ω : Type*} [MeasurableSpace Ω] + {μ : Measure Ω} [IsProbabilityMeasure μ] {f : Ω → ℝ} (hf : MemLp f 2 μ) : + (∫ ω, f ω ∂μ)^2 ≤ ∫ ω, (f ω)^2 ∂μ := by + have h := variance_nonneg f μ + rw [variance_eq_sub hf] at h + exact sub_nonneg.mp h + +lemma integral_abs_le_sqrt_integral_sq {Ω : Type*} [MeasurableSpace Ω] + {μ : Measure Ω} [IsProbabilityMeasure μ] {f : Ω → ℝ} (hf : MemLp f 2 μ) : + (∫ ω, |f ω| ∂μ) ≤ Real.sqrt (∫ ω, (f ω)^2 ∂μ) := by + have hab : MemLp (fun ω ↦ |f ω|) 2 μ := by + simpa only [Real.norm_eq_abs] using hf.norm + have h := integral_sq_le_integral_sq hab + simp only [sq_abs] at h + exact (Real.le_sqrt (integral_nonneg (fun _ ↦ abs_nonneg _)) + (integral_nonneg (fun _ ↦ sq_nonneg _))).mpr h + +lemma square_difference_bound {x y K L e : ℝ} + (_hK : 0≤K) (hL : 0≤L) (he : 0≤e) + (hx : |x|≤K) (hy : |y|≤K) (hxy : |x-y|≤L*e) : + |x^2-y^2| ≤ (2*K*L)*e := by + have hs : |x+y|≤2*K := (abs_add_le _ _).trans (by linarith) + calc + |x^2-y^2| = |x-y| * |x+y| := by rw [← abs_mul]; congr 1; ring + _ ≤ (L*e)*(2*K) := mul_le_mul hxy hs (abs_nonneg _) (mul_nonneg hL he) + _ = _ := by ring + +lemma second_moment_perturbation {Ω : Type*} [MeasurableSpace Ω] + {μ : Measure Ω} [IsProbabilityMeasure μ] {f g e : Ω → ℝ} {K L : ℝ} + (hf : MemLp f 2 μ) (hg : MemLp g 2 μ) (he : MemLp e 2 μ) + (hK : 0≤K) (hL : 0≤L) + (hbound : ∀ᵐ ω ∂μ, |f ω|≤K ∧ |g ω|≤K ∧ |f ω-g ω|≤L*|e ω|) : + |(∫ ω, (f ω)^2 ∂μ)-(∫ ω, (g ω)^2 ∂μ)| ≤ + (2*K*L)*Real.sqrt (∫ ω, (e ω)^2 ∂μ) := by + have hfi : Integrable (fun ω ↦ (f ω)^2) μ := hf.integrable_sq + have hgi : Integrable (fun ω ↦ (g ω)^2) μ := hg.integrable_sq + have hei : Integrable (fun ω ↦ |e ω|) μ := by + simpa only [Real.norm_eq_abs] using (he.integrable (by norm_num : (1 : ENNReal)≤2)).norm + calc + _ = |∫ ω, (f ω)^2-(g ω)^2 ∂μ| := by rw [integral_sub hfi hgi] + _ ≤ ∫ ω, |(f ω)^2-(g ω)^2| ∂μ := abs_integral_le_integral_abs + _ ≤ ∫ ω, (2*K*L)*|e ω| ∂μ := by + apply integral_mono_ae + · exact (hfi.sub hgi).abs + · exact hei.const_mul _ + · filter_upwards [hbound] with ω hω + exact square_difference_bound hK hL (abs_nonneg _) hω.1 hω.2.1 hω.2.2 + _ = (2*K*L)*(∫ ω, |e ω| ∂μ) := integral_const_mul _ _ + _ ≤ _ := mul_le_mul_of_nonneg_left (integral_abs_le_sqrt_integral_sq he) (by positivity) + +lemma uniform_moment_positive {q : ℕ → ℕ → ℝ} {r : ℕ → ℝ} + (hr : Tendsto r atTop (𝓝 0)) + (hq : ∀ N j, j0, ∀ᶠ N in atTop, ∀ j0, ∀ᶠ N in atTop, ∀ j + intro S hS hST + refine ⟨1,by norm_num,?_⟩ + intro γ V h hm hmono hbd t ht k hk x + have hk' : k=0 := by omega + subst k + simpa only [iteratedDeriv_zero] using h.deriv_bound ⟨ht.1,ht.2.trans hST.le⟩ x + | succ m ih => + intro S hS hST + let S' := (S+T)/2 + have hSS' : S [] + | p::l => (p.1,p.2+ε*k)::liftProfile ε (k+1) l + +lemma liftProfile_time (ε : ℝ≥0) (k : ℕ) (l : HeatProfile) : + profileTime (liftProfile ε k l)=profileTime l := by + induction l generalizing k with + | nil => rfl + | cons p l ih => simp only [liftProfile,profileTime,ih] + +lemma liftProfile_lower (ε : ℝ≥0) (k : ℕ) {c : ℝ≥0} {l : HeatProfile} + (h : ∀ p∈l,c≤p.2) : ∀ r∈liftProfile ε k l,c+ε*k≤r.2 := by + induction l generalizing k with + | nil => simp [liftProfile] + | cons p l ih => + intro r hr + simp only [liftProfile,List.mem_cons] at hr + rcases hr with rfl | hr + · exact add_le_add_left (h p (List.mem_cons_self ..)) _ + · exact (add_le_add_right (mul_le_mul_of_nonneg_left (show (k : ℝ≥0)≤(k+1 : ℕ) by exact_mod_cast (Nat.le_succ k)) (show 0≤ε from zero_le)) c).trans + (ih (k+1) (fun p hp ↦ h p (List.mem_cons_of_mem _ hp)) r hr) + +lemma liftProfile_strict {ε : ℝ≥0} (hε : 0<ε) (k : ℕ) {l : HeatProfile} + (h : l.Pairwise (fun p r ↦ p.2≤r.2)) : + (liftProfile ε k l).Pairwise (fun p r ↦ p.2 exact List.Pairwise.nil + | cons p l ih => + obtain ⟨hp,hl⟩ := List.pairwise_cons.mp h + apply List.pairwise_cons.mpr + refine ⟨?_,ih (k+1) hl⟩ + intro r hr + have hb := liftProfile_lower ε (k+1) hp r hr + apply lt_of_lt_of_le _ hb + apply add_lt_add_right + exact mul_lt_mul_of_pos_left (by exact_mod_cast (Nat.lt_succ_self k)) hε + +lemma liftProfile_positive {ε : ℝ≥0} (hε : 0<ε) {k : ℕ} (hk : 0 exact le_rfl + | cons p l ih => + change patchTime _ _ _ t≤patchTime _ _ _ t + by_cases ht : t≤(p.1 : ℝ) + · rw [patchTime_left _ _ ht,patchTime_left _ _ ht] + simp only [NNReal.coe_add,NNReal.coe_mul,NNReal.coe_natCast] + exact le_add_of_nonneg_right (by positivity) + · rw [patchTime_right _ _ (lt_of_not_ge ht),patchTime_right _ _ (lt_of_not_ge ht)] + exact ih _ _ + +lemma liftProfile_error (ε : ℝ≥0) (k : ℕ) (l : HeatProfile) (t : ℝ) : + |profileCoeff (liftProfile ε k l) t-profileCoeff l t|≤(ε : ℝ)*(k+l.length) := by + induction l generalizing k t with + | nil => simp only [liftProfile,profileCoeff,sub_self,abs_zero,List.length_nil,Nat.cast_zero,add_zero]; positivity + | cons p l ih => + change |patchTime _ _ _ t-patchTime _ _ _ t|≤_ + by_cases ht : t≤(p.1 : ℝ) + · rw [patchTime_left _ _ ht,patchTime_left _ _ ht] + simp only [NNReal.coe_add,NNReal.coe_mul,NNReal.coe_natCast,add_sub_cancel_left,List.length_cons,Nat.cast_add,Nat.cast_one] + rw [abs_of_nonneg (by positivity)] + nlinarith [ε.coe_nonneg,(show (0 : ℝ)≤l.length by positivity)] + · rw [patchTime_right _ _ (lt_of_not_ge ht),patchTime_right _ _ (lt_of_not_ge ht)] + convert ih (k+1) (t-p.1) using 1 + simp only [List.length_cons,Nat.cast_add,Nat.cast_one] + ring + +lemma liftProfile_mono {ε : ℝ≥0} (hε : 0<ε) (k : ℕ) {l : HeatProfile} + (h : l.Pairwise (fun p r ↦ p.2≤r.2)) : + (liftProfile ε k l).Pairwise (fun p r ↦ p.2≤r.2) := + (liftProfile_strict hε k h).imp (fun h ↦ h.le) + +lemma SmoothTerminal.liftProfile_bound (W : BrownianSpace) {ψ : ℝ → ℝ} (hψ : SmoothTerminal ψ) + {l : HeatProfile} (hl : l.Pairwise (fun p r ↦ p.2≤r.2)) (hT : profileTime l=1) + {ε : ℝ≥0} (hε : 0<ε) (k : ℕ) (x : ℝ) : + |profileValue ψ (liftProfile ε k l) 0 x-profileValue ψ l 0 x|≤(3/2 : ℝ)*(ε : ℝ)*(k+l.length) := by + have hhT : profileTime (liftProfile ε k l)=1 := by rw [liftProfile_time,hT] + have hi : IntervalIntegrable (profileCoeff l) volume 0 1 := hT ▸ profileCoeff_integrable l + have hj : IntervalIntegrable (profileCoeff (liftProfile ε k l)) volume 0 1 := hhT ▸ profileCoeff_integrable _ + have he := elapsedValue_difference_bound (f := shiftedFiltration W 0) (brownian_increment_memLp W 0) + hψ.lipschitz hψ.lipschitz (fun y ↦ by simp : ∀ y,|ψ y-ψ y|≤(0 : ℝ)) + (profileCoeff_measurable (liftProfile ε k l)) (profileCoeff_measurable l) hj hi (by norm_num : (0 : ℝ)≤1) (x := x) + have hid := (hj.sub hi).abs + have hb : (∫ t in (0 : ℝ)..1,|profileCoeff (liftProfile ε k l) t-profileCoeff l t|)≤(ε : ℝ)*(k+l.length) := by + calc + _ ≤ ∫ t in (0 : ℝ)..1,(ε : ℝ)*(k+l.length) := + intervalIntegral.integral_mono (by norm_num) hid intervalIntegrable_const (fun t ↦ liftProfile_error ε k l t) + _ = _ := by simp + have he1 := hψ.profile_elapsedValue W (liftProfile_mono hε k hl) hhT (show (0 : ℝ)∈Ico 0 1 by norm_num) x + have he2 := hψ.profile_elapsedValue W hl hT (show (0 : ℝ)∈Ico 0 1 by norm_num) x + simp only [zero_add,sub_zero] at he1 he2 + rw [he1,he2] at he + linarith + +end SKValue + +end + +end OAI diff --git a/lean/OAI/Probability/SKValue/Equations/StripIntegralLimit.lean b/lean/OAI/Probability/SKValue/Equations/StripIntegralLimit.lean new file mode 100644 index 0000000000000000000000000000000000000000..e840da4c668ef3d1e0a6d73929a1401b48dd4fa4 --- /dev/null +++ b/lean/OAI/Probability/SKValue/Equations/StripIntegralLimit.lean @@ -0,0 +1,48 @@ +import Mathlib + +namespace OAI + +section + +open MeasureTheory Set Filter +open scoped Topology +namespace SKValue + +lemma strip_integral_limit {T a b Γ A B : ℝ} + {c : ℕ → ℝ → ℝ} {γ : ℝ → ℝ} {f g : ℕ → ℝ → ℝ} {F G : ℝ → ℝ} + (ha : a∈Icc (0 : ℝ) T) (hb : b∈Icc (0 : ℝ) T) + (hc : ∀ n, Measurable (c n)) + (hf : ∀ n, ContinuousOn (f n) (Icc (0 : ℝ) T)) + (hg : ∀ n, ContinuousOn (g n) (Icc (0 : ℝ) T)) + (hcb : ∀ n t, t∈Icc (0 : ℝ) T → |c n t| ≤ Γ) + (hfb : ∀ n t, t∈Icc (0 : ℝ) T → |f n t| ≤ A) + (hgb : ∀ n t, t∈Icc (0 : ℝ) T → |g n t| ≤ B) + (hΓ : 0 ≤ Γ) + (hlc : ∀ᵐ t ∂volume, t∈Icc (0 : ℝ) T → Tendsto (fun n ↦ c n t) atTop (𝓝 (γ t))) + (hlf : ∀ t∈Icc (0 : ℝ) T, Tendsto (fun n ↦ f n t) atTop (𝓝 (F t))) + (hlg : ∀ t∈Icc (0 : ℝ) T, Tendsto (fun n ↦ g n t) atTop (𝓝 (G t))) : + Tendsto (fun n ↦ ∫ t in a..b, f n t+c n t*g n t) atTop + (𝓝 (∫ t in a..b, F t+γ t*G t)) := by + have hsub : uIoc a b⊆Icc (0 : ℝ) T := uIoc_subset_uIcc.trans (uIcc_subset_Icc ha hb) + apply intervalIntegral.tendsto_integral_filter_of_dominated_convergence (fun _ ↦ A+Γ*B) + · apply Eventually.of_forall + intro n + exact ((hf n).aestronglyMeasurable measurableSet_Icc |>.mono_set hsub).add + ((hc n).aestronglyMeasurable.mul ((hg n).aestronglyMeasurable measurableSet_Icc |>.mono_set hsub)) + · apply Eventually.of_forall + intro n + apply Eventually.of_forall + intro t ht + rw [Real.norm_eq_abs] + exact (abs_add_le _ _).trans (add_le_add (hfb n t (hsub ht)) (by + rw [abs_mul] + exact mul_le_mul (hcb n t (hsub ht)) (hgb n t (hsub ht)) (abs_nonneg _) hΓ)) + · exact intervalIntegrable_const + · filter_upwards [hlc] with t hlt ht + exact (hlf t (hsub ht)).add ((hlt (hsub ht)).mul (hlg t (hsub ht))) + +end SKValue + +end + +end OAI diff --git a/lean/OAI/Probability/SKValue/Equations/SumStepsSub.lean b/lean/OAI/Probability/SKValue/Equations/SumStepsSub.lean new file mode 100644 index 0000000000000000000000000000000000000000..cb2ea54d6e8fd90bb035304233f15c65e320536d --- /dev/null +++ b/lean/OAI/Probability/SKValue/Equations/SumStepsSub.lean @@ -0,0 +1,125 @@ +import Mathlib +import OAI.Probability.SKValue.Gaussian.GaussianSquareVariance + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set +open scoped ENNReal NNReal BigOperators +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators Topology +open MeasureTheory ProbabilityTheory Set Filter +open scoped Topology BigOperators +namespace SKValue +open MeasureTheory ProbabilityTheory Set Filter +open scoped Topology BigOperators +variable {Ω : Type*} [MeasurableSpace Ω] {μ : Measure Ω} + +lemma sum_steps_sub {N : ℕ} (U : ℕ → ℝ) : + (∑ i : Fin N, (U (i+1)-U i))=U N-U 0 := by + rw [Fin.sum_univ_eq_sum_range (fun j ↦ U (j+1)-U j)] + exact Finset.sum_range_sub U N + +lemma sum_local_residual {N : ℕ} (U : ℕ → ℝ) (V W : Fin N → ℝ) : + (∑ i : Fin N, (U (i+1)-U i-V i-W i)) = U N-U 0-(∑ i, V i)-(∑ i, W i) := by + rw [Finset.sum_sub_distrib, Finset.sum_sub_distrib, sum_steps_sub] + +lemma sum_local_residual_bound {N : ℕ} {U : ℕ → ℝ} {V W P : Fin N → ℝ} + {Γ : ℕ → ℝ} {α β : ℝ} + (hlocal : ∀ i : Fin N, |U (i+1)-U i-V i-W i|≤α*P i+β*(Γ (i+1)-Γ i)) : + |U N-U 0-(∑ i, V i)-(∑ i, W i)|≤α*(∑ i, P i)+β*(Γ N-Γ 0) := by + rw [← sum_local_residual] + calc + _ ≤ ∑ i : Fin N, |U (i+1)-U i-V i-W i| := Finset.abs_sum_le_sum_abs _ _ + _ ≤ ∑ i : Fin N, (α*P i+β*(Γ (i+1)-Γ i)) := Finset.sum_le_sum (fun i _ ↦ hlocal i) + _ = _ := by rw [Finset.sum_add_distrib, ← Finset.mul_sum, ← Finset.mul_sum, sum_steps_sub] + +lemma finite_envelope_memLp [IsProbabilityMeasure μ] {ι : Type*} [Fintype ι] + {P : ι → Ω → ℝ} {R : Ω → ℝ} {α β : ℝ} + (hα : 0≤α) (hβ : 0≤β) (hPm : ∀ i, MemLp (P i) 2 μ) + (hPpos : ∀ i ω, 0≤P i ω) (hRm : AEStronglyMeasurable R μ) + (hR : ∀ ω, |R ω|≤α*(∑ i, P i ω)+β) : MemLp R 2 μ := by + have hsum : MemLp (fun ω ↦ ∑ i, P i ω) 2 μ := memLp_finsetSum _ (fun i _ ↦ hPm i) + have henv := (hsum.const_mul α).add (memLp_const β) + apply henv.mono hRm + filter_upwards [] with ω + have hs : 0≤∑ i, P i ω := Finset.sum_nonneg (fun i _ ↦ hPpos i ω) + have he : 0≤α*(∑ i, P i ω)+β := add_nonneg (mul_nonneg hα hs) hβ + simpa only [Pi.add_apply, Real.norm_eq_abs, abs_of_nonneg he] using hR ω + +lemma integral_square_add_le {R Q : Ω → ℝ} (hR : MemLp R 2 μ) (hQ : MemLp Q 2 μ) : + (∫ ω, (R ω+Q ω)^2 ∂μ)≤2*(∫ ω, (R ω)^2 ∂μ)+2*(∫ ω, (Q ω)^2 ∂μ) := by + calc + _ ≤ ∫ ω, 2*(R ω)^2+2*(Q ω)^2 ∂μ := by + apply integral_mono (hR.add hQ).integrable_sq + ((hR.integrable_sq.const_mul 2).add (hQ.integrable_sq.const_mul 2)) + intro ω + change (R ω+Q ω)^2≤2*(R ω)^2+2*(Q ω)^2 + nlinarith [sq_nonneg (R ω-Q ω)] + _ = _ := by + rw [integral_add (hR.integrable_sq.const_mul 2) (hQ.integrable_sq.const_mul 2), + integral_const_mul, integral_const_mul] + +lemma discrete_gradient_residual_L2 {N : ℕ} {δ G K C : ℝ} {Γ : ℕ → ℝ} + {U : ℕ → (Fin (N+1) → ℝ) → ℝ} + {A H : Fin N → (Fin (N+1) → ℝ) → ℝ} + (hδ : 0≤δ) (hG : 0≤G) (hK : 0≤K) (hC : 0≤C) + (hΓ : Γ 0≤Γ N) + (hUm : ∀ j ≤ N, Measurable (U j)) + (hAm : ∀ i, Measurable (A i)) + (hHm : ∀ i, Measurable (H i)) (hHp : ∀ i : Fin N, DependsBefore (i : ℕ) (H i)) + (hHb : ∀ i z, |H i z|≤K) + (hloc : ∀ (i : Fin N) z, + |U (i+1) z-U i z-Real.sqrt δ*A i z*coordinate N i z- + (δ/2)*H i z*((coordinate N i z)^2-1)| ≤ + δ*Real.sqrt δ*cubicEnvelope G K C (coordinate N i z)+δ*K*(Γ (i+1)-Γ i)) : + (∫ z, (U N z-U 0 z-∑ i : Fin N, Real.sqrt δ*A i z*coordinate N i z)^2 + ∂gaussianProduct (Fin (N+1))) ≤ + 2*((δ/2)^2*(N : ℝ)*K^2*gaussianSquareVariance)+ + 4*(δ*Real.sqrt δ)^2*(N : ℝ)^2*cubicEnvelopeMoment G K C+ + 4*(δ*K*(Γ N-Γ 0))^2 := by + let P (i : Fin N) (z : Fin (N+1) → ℝ) := cubicEnvelope G K C (coordinate N i z) + let Q (z : Fin (N+1) → ℝ) := + (δ/2)*(∑ i : Fin N, H i z*((coordinate N i z)^2-1)) + let R (z : Fin (N+1) → ℝ) := + U N z-U 0 z-(∑ i : Fin N, Real.sqrt δ*A i z*coordinate N i z)-Q z + have hPm (i : Fin N) : MemLp (P i) 2 (gaussianProduct (Fin (N+1))) := + cubicEnvelope_memLp_two (coordinate_hasLaw N i) hG K C + have hPpos (i : Fin N) z : 0≤P i z := cubicEnvelope_nonneg hG hK hC _ + have hPval (i : Fin N) : (∫ z, (P i z)^2 ∂gaussianProduct (Fin (N+1)))≤cubicEnvelopeMoment G K C := + le_of_eq (cubicEnvelope_moment_eq (coordinate_hasLaw N i) G K C) + have hQm : MemLp Q 2 (gaussianProduct (Fin (N+1))) := + (memLp_finsetSum Finset.univ (fun (i : Fin N) _ ↦ + predictableCenteredSquare_memLp (j := (i:ℕ)) (hHm i) (hHb i))).const_mul (δ/2) + have hRm : Measurable R := by + dsimp only [R, Q] + exact ((hUm N le_rfl).sub (hUm 0 (Nat.zero_le _))).sub (Finset.measurable_fun_sum _ (fun i _ ↦ + ((hAm i).const_mul _).mul (measurable_coordinate N i))) |>.sub + ((Finset.measurable_fun_sum _ (fun i _ ↦ + (hHm i).mul (((measurable_coordinate N i).pow_const 2).sub measurable_const))).const_mul _) + have hRbound (z : Fin (N+1) → ℝ) : + |R z|≤(δ*Real.sqrt δ)*(∑ i, P i z)+δ*K*(Γ N-Γ 0) := by + have hb := sum_local_residual_bound (U := fun j ↦ U j z) + (V := fun i ↦ Real.sqrt δ*A i z*coordinate N i z) + (W := fun i ↦ (δ/2)*H i z*((coordinate N i z)^2-1)) + (P := fun i ↦ P i z) (Γ := Γ) (fun i ↦ hloc i z) + simpa only [R, Q, P, mul_assoc, Finset.mul_sum] using hb + have hβ : 0≤δ*K*(Γ N-Γ 0) := mul_nonneg (mul_nonneg hδ hK) (sub_nonneg.mpr hΓ) + have hRmem := finite_envelope_memLp (by positivity : 0≤δ*Real.sqrt δ) hβ hPm hPpos + hRm.aestronglyMeasurable hRbound + have hRb := finite_envelope_L2_bound (by positivity : 0≤δ*Real.sqrt δ) hβ hPm hPpos hPval + hRm.aestronglyMeasurable hRbound + have hQb := predictableCenteredSquare_sum_bound (δ := δ) hK hHm hHp hHb + have heq (z : Fin (N+1) → ℝ) : (U N z-U 0 z-∑ i : Fin N, Real.sqrt δ*A i z*coordinate N i z)= + R z+Q z := by dsimp only [R]; ring + simp_rw [heq] + have hb := integral_square_add_le hRmem hQm + simp only [Fintype.card_fin] at hRb + dsimp only [Q] at hb + nlinarith + +end SKValue + +end + +end OAI diff --git a/lean/OAI/Probability/SKValue/Equations/TestGenerator.lean b/lean/OAI/Probability/SKValue/Equations/TestGenerator.lean new file mode 100644 index 0000000000000000000000000000000000000000..72cfb0db9e8004babd97e8e4a37bff2ac4fcb374 --- /dev/null +++ b/lean/OAI/Probability/SKValue/Equations/TestGenerator.lean @@ -0,0 +1,94 @@ +import Mathlib +import OAI.Probability.SKValue.Gaussian.GaussianSquareVariance +import OAI.Probability.SKValue.Equations.ThirdOrderRemainderBound +import OAI.Probability.SKValue.Processes.Measurable + +namespace OAI + +section + +open MeasureTheory ProbabilityTheory Set Filter +open scoped Topology ContDiff NNReal BigOperators +namespace SKValue +structure BackwardTest (T:ℝ) (γ:ℝ → ℝ) (u V:ℝ → ℝ → ℝ) (K L:ℝ) : Prop where + K_nonneg : 0≤K + L_nonneg : 0≤L + gamma_nonneg : ∀ t∈Icc (0:ℝ) T,0≤γ t + gamma_mono : MonotoneOn γ (Icc (0:ℝ) T) + drift_measurable : ∀ t∈Icc (0:ℝ) T,Measurable (u t) + drift_bound : ∀ t∈Icc (0:ℝ) T,∀ x,|u t x|≤1 + smooth : ∀ t∈Icc (0:ℝ) T,ContDiff ℝ 3 (V t) + bound : ∀ t∈Icc (0:ℝ) T,∀ x,|V t x|≤K + first_bound : ∀ t∈Icc (0:ℝ) T,∀ x,|deriv (V t) x|≤K + second_bound : ∀ t∈Icc (0:ℝ) T,∀ x,|deriv (deriv (V t)) x|≤K + third_bound : ∀ t∈Icc (0:ℝ) T,∀ x,|iteratedDeriv 3 (V t) x|≤K + second_lipschitz : ∀ t∈Icc (0:ℝ) T,∀ s∈Icc (0:ℝ) T,∀ x y, + |deriv (deriv (V s)) y-deriv (deriv (V t)) x|≤L*(|s-t|+|y-x|) + product_lipschitz : ∀ t∈Icc (0:ℝ) T,∀ s∈Icc (0:ℝ) T,∀ x y, + |u s y*deriv (V s) y-u t x*deriv (V t) x|≤L*(|s-t|+|y-x|) + second_integrable : ∀ y,IntervalIntegrable (fun s ↦ deriv (deriv (V s)) y) volume 0 T + product_integrable : ∀ y,IntervalIntegrable (fun s ↦ γ s*(u s y*deriv (V s) y)) volume 0 T + pde : ∀ a∈Icc (0:ℝ) T,∀ b∈Icc (0:ℝ) T,∀ x, + V b x-V a x=-(∫ s in a..b,(1/2:ℝ)*deriv (deriv (V s)) x+γ s*(u s x*deriv (V s) x)) + +lemma BackwardTest.product_bound {T K L:ℝ} {γ:ℝ → ℝ} {u V:ℝ → ℝ → ℝ} + (h:BackwardTest T γ u V K L) {t:ℝ} (ht:t∈Icc (0:ℝ) T) (x:ℝ) : + |u t x*deriv (V t) x|≤K := by + rw [abs_mul] + simpa only [one_mul] using mul_le_mul (h.drift_bound t ht x) (h.first_bound t ht x) + (abs_nonneg _) (by norm_num : (0:ℝ)≤1) + +lemma BackwardTest.euler_one_step {T K L t δ x z:ℝ} {γ:ℝ → ℝ} {u V:ℝ → ℝ → ℝ} + (h:BackwardTest T γ u V K L) (ht:0≤t) (hδ:0≤δ) (hδ1:δ≤1) (htδ:t+δ≤T) : + let d := Real.sqrt δ*z+δ*γ t*u t x + |V (t+δ) (x+d)-V t x-deriv (V t) x*Real.sqrt δ*z- + (1/2:ℝ)*δ*deriv (deriv (V t)) x*(z^2-1)|≤ + δ*Real.sqrt δ*cubicEnvelope (γ T) K ((1/2+γ T)*L) z+ + δ*K*(γ (t+δ)-γ t) := by + dsimp only + let d := Real.sqrt δ*z+δ*γ t*u t x + have htT:t≤T := (le_add_of_nonneg_right hδ).trans htδ + have hT:0≤T := ht.trans htT + have hsub:Icc t (t+δ)⊆Icc (0:ℝ) T := Icc_subset_Icc ht htδ + have htm:t∈Icc (0:ℝ) T := ⟨ht,htT⟩ + have hem:t+δ∈Icc (0:ℝ) T := ⟨by linarith,htδ⟩ + have hTm:T∈Icc (0:ℝ) T := ⟨hT,le_rfl⟩ + have hbint (y:ℝ) : IntervalIntegrable (fun s ↦ deriv (deriv (V s)) y) volume t (t+δ) := + (h.second_integrable y).mono_set (by rw [uIcc_of_le (by linarith:t≤t+δ),uIcc_of_le hT];exact hsub) + have hpint (y:ℝ) : IntervalIntegrable (fun s ↦ γ s*(u s y*deriv (V s) y)) volume t (t+δ) := + (h.product_integrable y).mono_set (by rw [uIcc_of_le (by linarith:t≤t+δ),uIcc_of_le hT];exact hsub) + have hgen := gradient_generator_quadrature + (b:=fun s y ↦ deriv (deriv (V s)) y) (p:=fun s y ↦ u s y*deriv (V s) y) (y:=x+d) + hδ (h.gamma_nonneg T hTm) h.K_nonneg h.L_nonneg (h.gamma_mono.mono hsub) + (h.gamma_nonneg t htm) (h.gamma_mono htm hTm htT) + (fun s hs ↦ h.product_bound (hsub hs) _) (fun s hs ↦ h.second_lipschitz t htm s (hsub hs) x _) + (fun s hs ↦ h.product_lipschitz t htm s (hsub hs) x _) (hbint _) (hpint _) + have htime : |(V (t+δ) (x+d)-V t x+u t x)-(V t (x+d)-V t x+u t x)+ + δ*((1/2:ℝ)*deriv (deriv (V t)) x+γ t*u t x*deriv (V t) x)|≤ + δ*(((1/2:ℝ)+γ T)*L*(δ+|d|)+K*(γ (t+δ)-γ t)) := by + have heq : (V (t+δ) (x+d)-V t x+u t x)-(V t (x+d)-V t x+u t x)+ + δ*((1/2:ℝ)*deriv (deriv (V t)) x+γ t*u t x*deriv (V t) x)= + (V (t+δ) (x+d)-V t (x+d))+ + δ*((1/2:ℝ)*deriv (deriv (V t)) x+γ t*(u t x*deriv (V t) x)) := by ring + rw [heq,h.pde t htm (t+δ) hem] + rw [show -(∫ s in t..t+δ,(1/2:ℝ)*deriv (deriv (V s)) (x+d)+γ s*(u s (x+d)*deriv (V s) (x+d)))+ + δ*((1/2:ℝ)*deriv (deriv (V t)) x+γ t*(u t x*deriv (V t) x))= + -((∫ s in t..t+δ,(1/2:ℝ)*deriv (deriv (V s)) (x+d)+γ s*(u s (x+d)*deriv (V s) (x+d)))- + δ*((1/2:ℝ)*deriv (deriv (V t)) x+γ t*(u t x*deriv (V t) x))) by ring,abs_neg] + simpa only [add_sub_cancel_left] using hgen + have hspace : |(V t (x+d)-V t x+u t x)-u t x-deriv (V t) x*d- + (1/2:ℝ)*deriv (deriv (V t)) x*d^2|≤K*|d|^3 := by + simpa only [add_sub_cancel_right] using third_order_remainder_bound (h.smooth t htm) h.K_nonneg (h.third_bound t htm) x d + have hh := euler_cubic_remainder hδ hδ1 (h.gamma_nonneg T hTm) h.K_nonneg + (mul_nonneg (by linarith [h.gamma_nonneg T hTm] : 0≤1/2+γ T) h.L_nonneg) + (by rw [abs_of_nonneg (h.gamma_nonneg t htm)];exact h.gamma_mono htm hTm htT) + (h.drift_bound t htm x) (h.second_bound t htm x) hspace htime + convert! hh using 1 + congr 1 + dsimp only [d,cubicEnvelope] + ring +end SKValue + +end + +end OAI diff --git a/lean/OAI/Probability/SKValue/Equations/TestPatch.lean b/lean/OAI/Probability/SKValue/Equations/TestPatch.lean new file mode 100644 index 0000000000000000000000000000000000000000..6f74a2e302020d001752429192014dd60d0eada2 --- /dev/null +++ b/lean/OAI/Probability/SKValue/Equations/TestPatch.lean @@ -0,0 +1,134 @@ +import Mathlib +import OAI.Probability.SKValue.Evolution.EvolutionPatch +import OAI.Probability.SKValue.Evolution.TestEvolution + +namespace OAI + +section + +open MeasureTheory ProbabilityTheory Set Filter +open scoped Topology ContDiff NNReal +namespace SKValue +lemma patchTime_testjet {a t x:ℝ} (V W:ℝ → ℝ → ℝ) (n:ℕ) : + iteratedDeriv n (patchTime a V W t) x= + patchTime a (fun t ↦ iteratedDeriv n (V t) x) (fun t ↦ iteratedDeriv n (W t) x) t := by + by_cases ht:t≤a <;> simp [patchTime,ht] + +lemma LinearEvolution.rhs_integrable {T:ℝ} (hT:0≤T) {γ:ℝ → ℝ} {A V:ℝ → ℝ → ℝ} + (h:LinearEvolution T γ A V) (hA:SmoothEvolution T γ A) + (hg:IntervalIntegrable γ volume 0 T) (x:ℝ) : + IntervalIntegrable (fun r ↦ -((1/2:ℝ)*deriv (deriv (V r)) x+γ r*(deriv (A r) x*deriv (V r) x))) volume 0 T := by + have h1:ContinuousOn (fun r ↦ deriv (V r) x) (uIcc (0:ℝ) T) := by + simpa only [uIcc_of_le hT,iteratedDeriv_one] using h.continuous_jet 1 x + have h2:ContinuousOn (fun r ↦ deriv (deriv (V r)) x) (uIcc (0:ℝ) T) := by + simpa only [uIcc_of_le hT,show (2:ℕ)=1+1 from rfl,iteratedDeriv_succ,iteratedDeriv_one,iteratedDeriv_zero] using h.continuous_jet 2 x + have ha:ContinuousOn (fun r ↦ deriv (A r) x) (uIcc (0:ℝ) T) := by + simpa only [uIcc_of_le hT,iteratedDeriv_zero] using hA.continuous_jet 0 x + exact ((h2.intervalIntegrable.const_mul _).add (hg.mul_continuousOn (ha.mul h1))).neg + +lemma LinearEvolution.patch_pde {a b:ℝ} (ha:0≤a) (hb:0≤b) + {γ η:ℝ → ℝ} {A B V W:ℝ → ℝ → ℝ} + (hV:LinearEvolution a γ A V) (hW:LinearEvolution b η B W) + (hA:SmoothEvolution a γ A) (hB:SmoothEvolution b η B) + (hγ:IntervalIntegrable γ volume 0 a) (hη:IntervalIntegrable η volume 0 b) + (hjoin:V a=W 0) {s t:ℝ} (hs:s∈Icc (0:ℝ) (a+b)) (ht:t∈Icc (0:ℝ) (a+b)) (x:ℝ) : + patchTime a V W s x-patchTime a V W t x= + -(∫ r in t..s,(1/2:ℝ)*deriv (deriv (patchTime a V W r)) x+ + patchTime a γ η r*(deriv (patchTime a A B r) x*deriv (patchTime a V W r) x)) := by + let p := fun r ↦ -((1/2:ℝ)*deriv (deriv (V r)) x+γ r*(deriv (A r) x*deriv (V r) x)) + let q := fun r ↦ -((1/2:ℝ)*deriv (deriv (W r)) x+η r*(deriv (B r) x*deriv (W r) x)) + have hp := hV.rhs_integrable ha hA hγ x + have hq := hW.rhs_integrable hb hB hη x + have hv:∀ t∈Icc (0:ℝ) a,V t x-V 0 x=∫ r in (0:ℝ)..t,p r := by + intro t ht + simpa only [p,intervalIntegral.integral_neg] using hV.pde 0 ⟨le_rfl,ha⟩ t ht x + have hw:∀ t∈Icc (0:ℝ) b,W t x-W 0 x=∫ r in (0:ℝ)..t,q r := by + intro t ht + simpa only [q,intervalIntegral.integral_neg] using hW.pde 0 ⟨le_rfl,hb⟩ t ht x + have he := primitive_to_integral (add_nonneg ha hb) (patchTime_intervalIntegrable ha hb hp hq) + (patchTime_primitive ha hb hp hq hv hw (congrFun hjoin x)) hs ht + rw [←patchTime_apply V W,←patchTime_apply V W] at he + rw [he,←intervalIntegral.integral_neg] + apply intervalIntegral.integral_congr + intro r _ + by_cases hr:r≤a <;> simp [patchTime,hr] + +lemma LinearEvolution.patch {a b:ℝ} (ha:0≤a) (hb:0≤b) + {γ η:ℝ → ℝ} {A B V W:ℝ → ℝ → ℝ} + (hV:LinearEvolution a γ A V) (hW:LinearEvolution b η B W) + (hA:SmoothEvolution a γ A) (hB:SmoothEvolution b η B) + (hγ:IntervalIntegrable γ volume 0 a) (hη:IntervalIntegrable η volume 0 b) + (hjoin:V a=W 0) : + LinearEvolution (a+b) (patchTime a γ η) (patchTime a A B) (patchTime a V W) := by + refine ⟨?_,?_,?_,?_,?_⟩ + · intro t ht + by_cases hta:t≤a + · rw [patchTime_left V W hta];exact hV.slices t ⟨ht.1,hta⟩ + · rw [patchTime_right V W (lt_of_not_ge hta)];exact hW.slices (t-a) ⟨by linarith,by linarith [ht.2]⟩ + · intro n x + simp_rw [patchTime_testjet] + apply patchTime_continuous (hV.continuous_jet n x) (hW.continuous_jet n x) + rw [hjoin] + · intro n + obtain ⟨C,hC,hv⟩ := hV.bound n + obtain ⟨D,hD,hw⟩ := hW.bound n + refine ⟨C+D,add_nonneg hC hD,?_⟩ + intro t ht x + rw [patchTime_testjet] + exact patchTime_bound hC hD (fun t ht ↦ hv t ht x) (fun t ht ↦ hw t ht x) t ht + · intro n + obtain ⟨C,hC,hv⟩ := hV.temporal n + obtain ⟨D,hD,hw⟩ := hW.temporal n + refine ⟨C+D,add_nonneg hC hD,?_⟩ + intro s hs t ht x + rw [patchTime_testjet,patchTime_testjet] + apply patchTime_lipschitz ha hb hC hD (fun s hs t ht ↦ hv s hs t ht x) + (fun s hs t ht ↦ hw s hs t ht x) _ s hs t ht + rw [hjoin] + · intro t ht s hs x + exact hV.patch_pde ha hb hW hA hB hγ hη hjoin hs ht x + +noncomputable def profileResponse (ψ f:ℝ → ℝ) : HeatProfile → ℝ → ℝ → ℝ + | [] => fun _ ↦ f + | p::l => patchTime (p.1:ℝ) + (fun t ↦ responseJet (p.2:ℝ) (profileValue ψ l 0) (profileResponse ψ f l 0) 0 ((p.1:ℝ)-t)) + (profileResponse ψ f l) + +lemma SmoothTerminal.linear_profile {ψ f:ℝ → ℝ} (hψ:SmoothTerminal ψ) (hf:BoundedSmooth f) (l:HeatProfile) : + LinearEvolution (profileTime l) (profileCoeff l) (profileValue ψ l) (profileResponse ψ f l) := by + induction l with + | nil => + change LinearEvolution 0 (fun _ ↦ 0) (fun _ ↦ ψ) (fun _ ↦ f) + refine ⟨fun t _ ↦ hf,fun _ _ ↦ continuousOn_const,?_,?_,?_⟩ + · intro n + obtain ⟨C,hC,hb⟩ := hf.bound n + exact ⟨C,hC,fun _ _ ↦ hb⟩ + · intro n + exact ⟨0,le_rfl,by intros;simp⟩ + · intro t ht s hs x + have ht0:t=0 := le_antisymm ht.2 ht.1 + have hs0:s=0 := le_antisymm hs.2 hs.1 + subst t;subst s;simp + | cons p l ih => + have hA := hψ.profile_evolution l + have hψ' := hA.slices 0 ⟨le_rfl,profileTime_nonneg l⟩ + have hf' := ih.slices 0 ⟨le_rfl,profileTime_nonneg l⟩ + apply (hψ'.linear_constant hf' p.2.coe_nonneg (p.1:ℝ)).patch p.1.coe_nonneg (profileTime_nonneg l) + ih (hψ'.constant_evolution p.2.coe_nonneg (p.1:ℝ)) hA intervalIntegrable_const (profileCoeff_integrable l) + funext x + simp only [sub_self,responseJet_zero] + +lemma profileResponse_terminal (ψ f:ℝ → ℝ) (l:HeatProfile) : + profileResponse ψ f l (profileTime l)=f := by + induction l with + | nil => rfl + | cons p l ih => + change patchTime _ _ _ ((p.1:ℝ)+profileTime l)=f + rw [patchTime_end (profileTime_nonneg l)] + · exact ih + · funext x;simp only [sub_self,responseJet_zero] +end SKValue + +end + +end OAI diff --git a/lean/OAI/Probability/SKValue/Equations/ThirdOrderRemainderBound.lean b/lean/OAI/Probability/SKValue/Equations/ThirdOrderRemainderBound.lean new file mode 100644 index 0000000000000000000000000000000000000000..e6f468a32827fdca47f5850254e2ba217c308262 --- /dev/null +++ b/lean/OAI/Probability/SKValue/Equations/ThirdOrderRemainderBound.lean @@ -0,0 +1,213 @@ +import Mathlib + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set +open scoped ENNReal NNReal BigOperators +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators Topology +open MeasureTheory ProbabilityTheory Set Filter +open scoped Topology BigOperators +namespace SKValue + +lemma third_order_remainder_bound {f : ℝ → ℝ} {K : ℝ} + (hf : ContDiff ℝ 3 f) (hK : 0≤K) + (hbound : ∀ x, |iteratedDeriv 3 f x|≤K) (x d : ℝ) : + |f (x+d)-f x-deriv f x*d-(1/2 : ℝ)*deriv (deriv f) x*d^2| ≤ K*|d|^3 := by + by_cases hd : d=0 + · simp [hd] + have hne : x ≠ x+d := by + intro hx + apply hd + linarith + have hu := uniqueDiffOn_uIcc hne + have hmem : x ∈ uIcc x (x+d) := left_mem_uIcc + have h1 : iteratedDerivWithin 1 f (uIcc x (x+d)) x = deriv f x := by + rw [iteratedDerivWithin_eq_iteratedDeriv hu (hf.of_le (by norm_num)).contDiffAt hmem, + iteratedDeriv_one] + have h2 : iteratedDerivWithin 2 f (uIcc x (x+d)) x = deriv (deriv f) x := by + rw [iteratedDerivWithin_eq_iteratedDeriv hu (hf.of_le (by norm_num)).contDiffAt hmem, + iteratedDeriv_succ, iteratedDeriv_one] + have ht : taylorWithinEval f 2 (uIcc x (x+d)) x (x+d) = + f x+deriv f x*d+(1/2 : ℝ)*deriv (deriv f) x*d^2 := by + rw [taylorWithinEval_succ, taylorWithinEval_succ, taylor_within_zero_eval] + rw [h1, h2] + norm_num + ring + obtain ⟨y,_,hy⟩ := taylor_mean_remainder_lagrange_iteratedDeriv (n := 2) hne hf.contDiffOn + rw [ht] at hy + have heq : f (x+d)-f x-deriv f x*d-(1/2 : ℝ)*deriv (deriv f) x*d^2 = + iteratedDeriv 3 f y*d^3/6 := by + norm_num at hy + linarith + rw [heq, abs_div, abs_mul, abs_pow] + norm_num + have hh : |iteratedDeriv 3 f y| *|d|^3 ≤ K*|d|^3 := + mul_le_mul_of_nonneg_right (hbound y) (by positivity) + have hp : 0≤K*|d|^3 := by positivity + linarith + +lemma gradient_generator_quadrature {γ : ℝ → ℝ} {b p : ℝ → ℝ → ℝ} + {t δ x y G K L : ℝ} (hδ : 0 ≤ δ) (hG : 0 ≤ G) (hK : 0 ≤ K) (hL : 0 ≤ L) + (hγ : MonotoneOn γ (Icc t (t+δ))) (hγ0 : 0 ≤ γ t) (hγG : γ t ≤ G) + (hp : ∀ s ∈ Icc t (t+δ), |p s y| ≤ K) + (hbLip : ∀ s ∈ Icc t (t+δ), |b s y-b t x| ≤ L*(|s-t|+|y-x|)) + (hpLip : ∀ s ∈ Icc t (t+δ), |p s y-p t x| ≤ L*(|s-t|+|y-x|)) + (hbint : IntervalIntegrable (fun s ↦ b s y) volume t (t+δ)) + (hpint : IntervalIntegrable (fun s ↦ γ s*p s y) volume t (t+δ)) : + |(∫ s in t..(t+δ), (1/2 : ℝ)*b s y+γ s*p s y) - + δ*((1/2 : ℝ)*b t x+γ t*p t x)| ≤ + δ*((1/2+G)*L*(δ+|y-x|)+K*(γ (t+δ)-γ t)) := by + have het : t ∈ Icc t (t+δ) := ⟨le_rfl, by linarith⟩ + have heT : t+δ ∈ Icc t (t+δ) := ⟨by linarith, le_rfl⟩ + have hgap : 0 ≤ γ (t+δ)-γ t := sub_nonneg.mpr (hγ het heT (by linarith)) + have hpw : ∀ s ∈ Icc t (t+δ), + |((1/2 : ℝ)*b s y+γ s*p s y)-((1/2 : ℝ)*b t x+γ t*p t x)| ≤ + (1/2+G)*L*(δ+|y-x|)+K*(γ (t+δ)-γ t) := by + intro s hs + have hst := hγ het hs hs.1 + have hsT := hγ hs heT hs.2 + have hr : |s-t| ≤ δ := by rw [abs_of_nonneg (sub_nonneg.mpr hs.1)]; linarith [hs.2] + have hb' : |b s y-b t x| ≤ L*(δ+|y-x|) := (hbLip s hs).trans (by gcongr) + have hp' : |p s y-p t x| ≤ L*(δ+|y-x|) := (hpLip s hs).trans (by gcongr) + calc + _ = |((1/2 : ℝ)*(b s y-b t x)+γ t*(p s y-p t x))+(γ s-γ t)*p s y| := by + congr 1; ring + _ ≤ |(1/2 : ℝ)*(b s y-b t x)|+|γ t*(p s y-p t x)|+|(γ s-γ t)*p s y| := + (abs_add_le _ _).trans (add_le_add (abs_add_le _ _) le_rfl) + _ = (1/2 : ℝ)*|b s y-b t x|+γ t*|p s y-p t x|+(γ s-γ t)*|p s y| := by + rw [abs_mul, abs_mul, abs_mul, abs_of_nonneg hγ0, + abs_of_nonneg (sub_nonneg.mpr hst)] + norm_num + _ ≤ (1/2+G)*L*(δ+|y-x|)+K*(γ (t+δ)-γ t) := by + calc + _ ≤ (1/2 : ℝ)*(L*(δ+|y-x|))+G*(L*(δ+|y-x|))+(γ (t+δ)-γ t)*K := by + apply add_le_add + · gcongr + · calc + _ ≤ (γ s-γ t)*K := + mul_le_mul_of_nonneg_left (hp s hs) (sub_nonneg.mpr hst) + _ ≤ _ := mul_le_mul_of_nonneg_right (sub_le_sub_right hsT _) hK + _ = _ := by ring + have hi := intervalIntegral.norm_integral_le_of_norm_le_const + (a := t) (b := t+δ) + (f := fun s ↦ ((1/2 : ℝ)*b s y+γ s*p s y)-((1/2 : ℝ)*b t x+γ t*p t x)) + (C := (1/2+G)*L*(δ+|y-x|)+K*(γ (t+δ)-γ t)) (fun s hs ↦ by + rw [Real.norm_eq_abs] + rw [uIoc_of_le (by linarith : t≤t+δ)] at hs + exact hpw s ⟨hs.1.le, hs.2⟩) + rw [intervalIntegral.integral_sub ((hbint.const_mul _).add hpint) intervalIntegrable_const, + intervalIntegral.integral_const, smul_eq_mul, Real.norm_eq_abs, + show t+δ-t=δ by ring, abs_of_nonneg hδ] at hi + simpa only [mul_comm δ] using hi + +lemma euler_cubic_remainder {δ G K C D c v a b vsp vend z : ℝ} + (hδ : 0≤δ) (hδ1 : δ≤1) (hG : 0≤G) (hK : 0≤K) (hC : 0≤C) + (hc : |c|≤G) (hv : |v|≤1) (hb : |b|≤K) + (hsp : |vsp-v-a*(Real.sqrt δ*z+δ*c*v)- + (1/2 : ℝ)*b*(Real.sqrt δ*z+δ*c*v)^2| ≤ K*|Real.sqrt δ*z+δ*c*v|^3) + (htm : |vend-vsp+δ*((1/2 : ℝ)*b+c*v*a)| ≤ + δ*(C*(δ+|Real.sqrt δ*z+δ*c*v|)+K*D)) : + |vend-v-a*Real.sqrt δ*z-(1/2 : ℝ)*δ*b*(z^2-1)| ≤ + δ*Real.sqrt δ*(K*(|z|+G)^3+C*(1+|z|+G)+K*G*(|z|+G/2))+δ*K*D := by + let η := Real.sqrt δ + let d := η*z+δ*c*v + have hη : 0≤η := Real.sqrt_nonneg _ + have hηsq : η^2=δ := Real.sq_sqrt hδ + have hη1 : η≤1 := (Real.sqrt_le_one).2 hδ1 + have hδη : δ≤η := by nlinarith + have hcv : |c*v|≤G := by + rw [abs_mul] + calc |c| *|v| ≤ G*1 := mul_le_mul hc hv (abs_nonneg _) hG + _ = G := mul_one _ + have hdcv : |δ*c*v|≤δ*G := by + rw [mul_assoc δ, abs_mul, abs_of_nonneg hδ] + exact mul_le_mul_of_nonneg_left hcv hδ + have hd : |d|≤η*(|z|+G) := by + calc + |d| ≤ |η*z|+|δ*c*v| := abs_add_le _ _ + _ ≤ η*|z|+δ*G := by rw [abs_mul, abs_of_nonneg hη]; gcongr + _ ≤ η*(|z|+G) := by nlinarith + have hcube : K*|d|^3 ≤ δ*η*(K*(|z|+G)^3) := by + calc + _ ≤ K*(η*(|z|+G))^3 := by gcongr + _ = _ := by rw [← hηsq]; ring + have htbound : δ*(C*(δ+|d|)+K*D) ≤ δ*η*(C*(1+|z|+G))+δ*K*D := by + have hh : δ+|d| ≤ η*(1+|z|+G) := by nlinarith + have hh' := mul_le_mul_of_nonneg_left hh (mul_nonneg hδ hC) + nlinarith + have hcross : |(1/2 : ℝ)*b*(d^2-δ*z^2)| ≤ δ*η*(K*G*(|z|+G/2)) := by + have heq : d^2-δ*z^2 = (δ*c*v)*(2*η*z+δ*c*v) := by + dsimp only [d] + rw [← hηsq] + ring + have hsum : |2*η*z+δ*c*v| ≤ η*(2*|z|+G) := by + calc + _ ≤ |2*η*z|+|δ*c*v| := abs_add_le _ _ + _ ≤ 2*η*|z|+δ*G := by + rw [abs_mul (2*η), abs_of_nonneg (by positivity : 0≤2*η)] + gcongr + _ ≤ η*(2*|z|+G) := by nlinarith + rw [heq, abs_mul, abs_mul, abs_mul, abs_of_nonneg (by norm_num : (0 : ℝ)≤1/2)] + calc + _ ≤ (1/2 : ℝ)*K*((δ*G)*(η*(2*|z|+G))) := by gcongr + _ = _ := by ring + have heq : vend-v-a*η*z-(1/2 : ℝ)*δ*b*(z^2-1) = + (vsp-v-a*d-(1/2 : ℝ)*b*d^2)+(vend-vsp+δ*((1/2 : ℝ)*b+c*v*a))+ + (1/2 : ℝ)*b*(d^2-δ*z^2) := by dsimp only [d]; ring + change |vend-v-a*η*z-(1/2 : ℝ)*δ*b*(z^2-1)| ≤ _ + rw [heq] + calc + _ ≤ |vsp-v-a*d-(1/2 : ℝ)*b*d^2|+|vend-vsp+δ*((1/2 : ℝ)*b+c*v*a)|+ + |(1/2 : ℝ)*b*(d^2-δ*z^2)| := + (abs_add_le _ _).trans (add_le_add (abs_add_le _ _) le_rfl) + _ ≤ K*|d|^3+δ*(C*(δ+|d|)+K*D)+δ*η*(K*G*(|z|+G/2)) := by gcongr + _ ≤ δ*η*(K*(|z|+G)^3+C*(1+|z|+G)+K*G*(|z|+G/2))+δ*K*D := by linarith + +lemma gradient_euler_one_step {u : ℝ → ℝ → ℝ} {γ : ℝ → ℝ} + {t δ x z G K L : ℝ} (hδ : 0≤δ) (hδ1 : δ≤1) + (hG : 0≤G) (hK : 0≤K) (hL : 0≤L) + (hγ : MonotoneOn γ (Icc t (t+δ))) (hγ0 : 0≤γ t) (hγG : γ t≤G) + (hu : |u t x|≤1) (hsmooth : ContDiff ℝ 3 (u t)) + (hb : |deriv (deriv (u t)) x|≤K) (hthird : ∀ y, |iteratedDeriv 3 (u t) y|≤K) + (hp : ∀ s ∈ Icc t (t+δ), ∀ y, |u s y*deriv (u s) y|≤K) + (hbLip : ∀ s ∈ Icc t (t+δ), ∀ y, + |deriv (deriv (u s)) y-deriv (deriv (u t)) x|≤L*(|s-t|+|y-x|)) + (hpLip : ∀ s ∈ Icc t (t+δ), ∀ y, + |u s y*deriv (u s) y-u t x*deriv (u t) x|≤L*(|s-t|+|y-x|)) + (hbint : ∀ y, IntervalIntegrable (fun s ↦ deriv (deriv (u s)) y) volume t (t+δ)) + (hpint : ∀ y, IntervalIntegrable (fun s ↦ γ s*(u s y*deriv (u s) y)) volume t (t+δ)) + (hPDE : ∀ y, u (t+δ) y-u t y = + -(∫ s in t..(t+δ), (1/2 : ℝ)*deriv (deriv (u s)) y+γ s*(u s y*deriv (u s) y))) : + let d := Real.sqrt δ*z+δ*γ t*u t x + |u (t+δ) (x+d)-u t x-deriv (u t) x*Real.sqrt δ*z- + (1/2 : ℝ)*δ*deriv (deriv (u t)) x*(z^2-1)| ≤ + δ*Real.sqrt δ*(K*(|z|+G)^3+(1/2+G)*L*(1+|z|+G)+K*G*(|z|+G/2))+ + δ*K*(γ (t+δ)-γ t) := by + dsimp only + let d := Real.sqrt δ*z+δ*γ t*u t x + have htm := gradient_generator_quadrature (b := fun s y ↦ deriv (deriv (u s)) y) + (p := fun s y ↦ u s y*deriv (u s) y) (y := x+d) hδ hG hK hL hγ hγ0 hγG + (fun s hs ↦ hp s hs _) (fun s hs ↦ hbLip s hs _) (fun s hs ↦ hpLip s hs _) + (hbint _) (hpint _) + have ht : |u (t+δ) (x+d)-u t (x+d)+ + δ*((1/2 : ℝ)*deriv (deriv (u t)) x+γ t*u t x*deriv (u t) x)| ≤ + δ*(((1/2 : ℝ)+G)*L*(δ+|d|)+K*(γ (t+δ)-γ t)) := by + rw [hPDE] + have heq : -(∫ s in t..(t+δ), (1/2 : ℝ)*deriv (deriv (u s)) (x+d)+ + γ s*(u s (x+d)*deriv (u s) (x+d)))+ + δ*((1/2 : ℝ)*deriv (deriv (u t)) x+γ t*u t x*deriv (u t) x) = + -((∫ s in t..(t+δ), (1/2 : ℝ)*deriv (deriv (u s)) (x+d)+ + γ s*(u s (x+d)*deriv (u s) (x+d)))- + δ*((1/2 : ℝ)*deriv (deriv (u t)) x+γ t*(u t x*deriv (u t) x))) := by ring + rw [heq, abs_neg] + simpa only [add_sub_cancel_left] using htm + exact euler_cubic_remainder hδ hδ1 hG hK (by positivity) + (by rwa [abs_of_nonneg hγ0]) hu hb (third_order_remainder_bound hsmooth hK hthird x d) ht + +end SKValue + +end + +end OAI diff --git a/lean/OAI/Probability/SKValue/Equations/TruncatedStieltjes.lean b/lean/OAI/Probability/SKValue/Equations/TruncatedStieltjes.lean new file mode 100644 index 0000000000000000000000000000000000000000..90b12fcf8f5ae6a485f0dcc898d8698c1ab89de1 --- /dev/null +++ b/lean/OAI/Probability/SKValue/Equations/TruncatedStieltjes.lean @@ -0,0 +1,98 @@ +import Mathlib +import OAI.Probability.SKValue.Model + +namespace OAI + +section + +open MeasureTheory ProbabilityTheory Set Filter +open scoped Topology NNReal ENNReal BigOperators +namespace SKValue + +lemma clamp_mem {T : ℝ} (hT : T∈Ico (0 : ℝ) 1) (t : ℝ) : + min T (max 0 t)∈Ico (0 : ℝ) 1 := + ⟨le_min hT.1 (le_max_left _ _),(min_le_left _ _).trans_lt hT.2⟩ + +noncomputable def OrderParameter.truncatedStieltjes (γ : OrderParameter) (T : ℝ) + (hT : T∈Ico (0 : ℝ) 1) : StieltjesFunction ℝ where + toFun t := γ.coeff (min T (max 0 t)) + mono' a b hab := γ.monotone (clamp_mem hT a) (clamp_mem hT b) + (min_le_min_left T (max_le_max_left 0 hab)) + right_continuous' t := by + apply (γ.rightContinuous _ (clamp_mem hT t)).comp (f := fun s : ℝ ↦ min T (max 0 s)) + ((continuous_const.min (continuous_const.max continuous_id)).continuousWithinAt) + intro u hu + exact min_le_min_left T (max_le_max_left 0 hu) + +lemma OrderParameter.truncatedStieltjes_zero (γ : OrderParameter) {T : ℝ} + (hT : T∈Ico (0 : ℝ) 1) : γ.truncatedStieltjes T hT 0=γ.coeff 0 := by + simp [OrderParameter.truncatedStieltjes,min_eq_right hT.1] + +lemma OrderParameter.truncatedStieltjes_top (γ : OrderParameter) {T : ℝ} + (hT : T∈Ico (0 : ℝ) 1) : γ.truncatedStieltjes T hT T=γ.coeff T := by + simp [OrderParameter.truncatedStieltjes,max_eq_right hT.1] + +noncomputable def OrderParameter.truncatedMass (γ : OrderParameter) (T : ℝ) + (hT : T∈Ico (0 : ℝ) 1) : Measure ℝ := + (γ.truncatedStieltjes T hT).measure.restrict (Ioc 0 T)+ + ENNReal.ofReal (γ.coeff 0) • Measure.dirac 0 + +lemma OrderParameter.truncatedMass_univ (γ : OrderParameter) {T : ℝ} + (hT : T∈Ico (0 : ℝ) 1) : + γ.truncatedMass T hT univ=ENNReal.ofReal (γ.coeff T) := by + have h0 := γ.nonneg 0 (by norm_num) + have hm := γ.monotone (by norm_num : (0 : ℝ)∈Ico (0 : ℝ) 1) hT hT.1 + simp only [OrderParameter.truncatedMass,Measure.add_apply,Measure.restrict_apply_univ, + Measure.smul_apply,Measure.dirac_apply_of_mem (mem_univ (0 : ℝ)),smul_eq_mul,mul_one, + StieltjesFunction.measure_Ioc,γ.truncatedStieltjes_zero hT,γ.truncatedStieltjes_top hT] + rw [←ENNReal.ofReal_add (sub_nonneg.mpr hm) h0] + congr 1 + ring + +instance OrderParameter.truncatedMass_finite (γ : OrderParameter) (T : ℝ) + (hT : T∈Ico (0 : ℝ) 1) : IsFiniteMeasure (γ.truncatedMass T hT) := + ⟨by rw [γ.truncatedMass_univ hT]; exact ENNReal.ofReal_lt_top⟩ + +lemma OrderParameter.truncatedMass_cdf (γ : OrderParameter) {T t : ℝ} + (hT : T∈Ico (0 : ℝ) 1) (ht : t∈Ico (0 : ℝ) 1) : + γ.truncatedMass T hT (Iic t)=ENNReal.ofReal (min (γ.coeff t) (γ.coeff T)) := by + have he : Iic t∩Ioc (0 : ℝ) T=Ioc 0 (min t T) := by + ext s + simp only [mem_inter_iff,mem_Iic,mem_Ioc,le_min_iff] + tauto + have hmin : min t T∈Ico (0 : ℝ) 1 := ⟨le_min ht.1 hT.1,(min_le_left _ _).trans_lt ht.2⟩ + have hm := γ.monotone (by norm_num : (0 : ℝ)∈Ico (0 : ℝ) 1) hmin hmin.1 + have h0 := γ.nonneg 0 (by norm_num) + have hc : γ.truncatedStieltjes T hT (min t T)=min (γ.coeff t) (γ.coeff T) := by + dsimp only [OrderParameter.truncatedStieltjes] + rw [max_eq_right hmin.1,min_eq_right (min_le_right _ _)] + rcases le_total t T with h | h + · rw [min_eq_left h,min_eq_left (γ.monotone ht hT h)] + · rw [min_eq_right h,min_eq_right (γ.monotone hT ht h)] + have hm' : γ.coeff 0 ≤ min (γ.coeff t) (γ.coeff T) := by + exact le_min (γ.monotone (by norm_num) ht ht.1) (γ.monotone (by norm_num) hT hT.1) + simp only [OrderParameter.truncatedMass,Measure.add_apply,Measure.restrict_apply measurableSet_Iic, + he,Measure.smul_apply,Measure.dirac_apply_of_mem (show (0 : ℝ)∈Iic t from ht.1),smul_eq_mul,mul_one, + StieltjesFunction.measure_Ioc,γ.truncatedStieltjes_zero hT,hc] + rw [←ENNReal.ofReal_add (sub_nonneg.mpr hm') h0] + congr 1 + ring + +lemma OrderParameter.truncatedMass_ae_mem (γ : OrderParameter) {T : ℝ} + (hT : T∈Ico (0 : ℝ) 1) : ∀ᵐ s ∂γ.truncatedMass T hT,s∈Icc (0 : ℝ) T := by + rw [ae_iff] + change γ.truncatedMass T hT (Icc (0 : ℝ) T)ᶜ=0 + simp only [OrderParameter.truncatedMass,Measure.add_apply, + Measure.restrict_apply measurableSet_Icc.compl,Measure.smul_apply] + have he : (Icc (0 : ℝ) T)ᶜ∩Ioc 0 T=∅ := by + exact disjoint_iff_inter_eq_empty.mp (disjoint_compl_left.mono_right Ioc_subset_Icc_self) + rw [he,measure_empty,zero_add,Measure.dirac_apply] + have hnot : (0 : ℝ)∉(Icc (0 : ℝ) T)ᶜ := notMem_compl_iff.mpr ⟨le_rfl,hT.1⟩ + rw [indicator_of_notMem hnot] + simp + +end SKValue + +end + +end OAI diff --git a/lean/OAI/Probability/SKValue/Equations/UniformPolynomial.lean b/lean/OAI/Probability/SKValue/Equations/UniformPolynomial.lean new file mode 100644 index 0000000000000000000000000000000000000000..92e55255d523260a4712fcb3f982dc667b86197d --- /dev/null +++ b/lean/OAI/Probability/SKValue/Equations/UniformPolynomial.lean @@ -0,0 +1,76 @@ +import Mathlib + +namespace OAI + +section +open Filter Set +open scoped Topology +namespace SKValue +structure BoundedUniformLimit {A:Type*} (F:ℕ → A → ℝ) (f:A → ℝ) : Prop where + tendsto : TendstoUniformly F f atTop + bound : ∃ C:ℝ,0 ≤ C ∧ (∀ n x,|F n x| ≤ C) ∧ ∀ x,|f x| ≤ C +lemma BoundedUniformLimit.const {A:Type*} (c:ℝ) : + BoundedUniformLimit (fun (_:ℕ) (_:A) ↦ c) (fun _ ↦ c) := + ⟨by + rw [Metric.tendstoUniformly_iff] + exact fun ε hε ↦ Eventually.of_forall (fun _ _ ↦ by simpa using hε),|c|,abs_nonneg c,fun _ _ ↦ le_rfl,fun _ ↦ le_rfl⟩ +lemma BoundedUniformLimit.seq {A:Type*} {c:ℕ → ℝ} {d:ℝ} + (hl:Tendsto c atTop (𝓝 d)) (hb:∃ C:ℝ,0 ≤ C ∧ ∀ n,|c n| ≤ C) : + BoundedUniformLimit (fun n (_:A) ↦ c n) (fun _ ↦ d) := by + obtain ⟨C,hC,hb⟩:=hb + refine ⟨?_,C,hC,fun n _ ↦ hb n,fun _ ↦ le_of_tendsto hl.abs (Eventually.of_forall hb)⟩ + rw [Metric.tendstoUniformly_iff] + intro ε hε + exact (Metric.tendsto_nhds.mp hl ε hε).mono (fun n hn _ ↦ by simpa only [dist_comm] using hn) +lemma BoundedUniformLimit.add {A:Type*} {F G:ℕ → A → ℝ} {f g:A → ℝ} + (hF:BoundedUniformLimit F f) (hG:BoundedUniformLimit G g) : + BoundedUniformLimit (fun n x ↦ F n x+G n x) (fun x ↦ f x+g x) := by + obtain ⟨C,hC,hb,hf⟩:=hF.bound + obtain ⟨D,hD,hd,hg⟩:=hG.bound + exact ⟨hF.tendsto.add hG.tendsto,C+D,add_nonneg hC hD, + fun n x ↦ (abs_add_le _ _).trans (add_le_add (hb n x) (hd n x)), + fun x ↦ (abs_add_le _ _).trans (add_le_add (hf x) (hg x))⟩ +lemma BoundedUniformLimit.mul {A:Type*} {F G:ℕ → A → ℝ} {f g:A → ℝ} + (hF:BoundedUniformLimit F f) (hG:BoundedUniformLimit G g) : + BoundedUniformLimit (fun n x ↦ F n x*G n x) (fun x ↦ f x*g x) := by + obtain ⟨C,hC,hb,hf⟩:=hF.bound + obtain ⟨D,hD,hd,hg⟩:=hG.bound + refine ⟨?_,C*D,mul_nonneg hC hD,?_,?_⟩ + · rw [Metric.tendstoUniformly_iff] + intro ε hε + let δ:=ε/(C+D+1) + have hden:0 exact BoundedUniformLimit.const 1 + | succ k ih => simpa only [pow_succ] using ih.mul hF +end SKValue + +end + +end OAI diff --git a/lean/OAI/Probability/SKValue/Equations/ValueStrip.lean b/lean/OAI/Probability/SKValue/Equations/ValueStrip.lean new file mode 100644 index 0000000000000000000000000000000000000000..1f5e92af11a1323eba2e3f79299a83e12dfd6121 --- /dev/null +++ b/lean/OAI/Probability/SKValue/Equations/ValueStrip.lean @@ -0,0 +1,186 @@ +import Mathlib +import OAI.Probability.SKValue.Equations.GradientErrorConstant +import OAI.Probability.SKValue.Processes.ValueEulerOneStep + +namespace OAI + +section +open MeasureTheory ProbabilityTheory Set +open scoped ENNReal NNReal BigOperators +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators Topology +open MeasureTheory ProbabilityTheory Set Filter +open scoped Topology BigOperators +open MeasureTheory ProbabilityTheory Set Filter +open scoped Topology ENNReal NNReal +open Filter Set +open scoped Topology BigOperators +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology +open MeasureTheory Set Filter +open scoped Topology BigOperators +open MeasureTheory Set Filter Finset +open scoped Topology BigOperators +namespace SKValue +open MeasureTheory ProbabilityTheory Set Filter +open scoped Topology BigOperators + +structure ValueStrip (T : ℝ) (γ : ℝ → ℝ) (V : ℝ → ℝ → ℝ) (K L : ℝ) : Prop where + K_nonneg : 0≤K + L_nonneg : 0≤L + gamma_nonneg : ∀ t ∈ Icc (0 : ℝ) T, 0≤γ t + gamma_mono : MonotoneOn γ (Icc (0 : ℝ) T) + smooth : ∀ t ∈ Icc (0 : ℝ) T, ContDiff ℝ 3 (V t) + bounded : ∀ t ∈ Icc (0 : ℝ) T, ∀ x, |deriv (V t) x|≤1 + second_bound : ∀ t ∈ Icc (0 : ℝ) T, ∀ x, |deriv (deriv (V t)) x|≤K + third_bound : ∀ t ∈ Icc (0 : ℝ) T, ∀ x, |iteratedDeriv 3 (V t) x|≤K + product_bound : ∀ t ∈ Icc (0 : ℝ) T, ∀ x, |(1/2 : ℝ)*(deriv (V t) x)^2|≤K + second_lipschitz : ∀ t ∈ Icc (0 : ℝ) T, ∀ s ∈ Icc (0 : ℝ) T, ∀ x y, + |deriv (deriv (V s)) y-deriv (deriv (V t)) x|≤L*(|s-t|+|y-x|) + product_lipschitz : ∀ t ∈ Icc (0 : ℝ) T, ∀ s ∈ Icc (0 : ℝ) T, ∀ x y, + |(1/2 : ℝ)*(deriv (V s) y)^2-(1/2 : ℝ)*(deriv (V t) x)^2|≤L*(|s-t|+|y-x|) + second_integrable : ∀ x, IntervalIntegrable (fun s ↦ deriv (deriv (V s)) x) volume 0 T + product_integrable : ∀ x, IntervalIntegrable (fun s ↦ γ s*((1/2 : ℝ)*(deriv (V s) x)^2)) volume 0 T + pde : ∀ t ∈ Icc (0 : ℝ) T, ∀ s ∈ Icc (0 : ℝ) T, ∀ x, + V s x-V t x = -(∫ r in t..s, (1/2 : ℝ)*deriv (deriv (V r)) x+γ r*((1/2 : ℝ)*(deriv (V r) x)^2)) + +noncomputable def valueMeshEnergy (T : ℝ) (N : ℕ) (γ : ℝ → ℝ) (V : ℝ → ℝ → ℝ) + (j : ℕ) (z : Fin (N+1) → ℝ) : ℝ := + ∑ i ∈ Finset.range j, (stepSize T N/2)*γ (meshTime T N i)* + (deriv (V (meshTime T N i)) (euler T N γ (fun t ↦ deriv (V t)) z i))^2 + +noncomputable def valueMeshCompensated (T : ℝ) (N : ℕ) (γ : ℝ → ℝ) (V : ℝ → ℝ → ℝ) + (j : ℕ) (z : Fin (N+1) → ℝ) : ℝ := + V (meshTime T N j) (euler T N γ (fun t ↦ deriv (V t)) z j)-valueMeshEnergy T N γ V j z + +lemma valueMeshCompensated_step (T : ℝ) (N : ℕ) (γ : ℝ → ℝ) (V : ℝ → ℝ → ℝ) + (j : ℕ) (z : Fin (N+1) → ℝ) : + valueMeshCompensated T N γ V (j+1) z-valueMeshCompensated T N γ V j z = + V (meshTime T N (j+1)) (euler T N γ (fun t ↦ deriv (V t)) z (j+1))- + V (meshTime T N j) (euler T N γ (fun t ↦ deriv (V t)) z j)- + (stepSize T N/2)*γ (meshTime T N j)* + (deriv (V (meshTime T N j)) (euler T N γ (fun t ↦ deriv (V t)) z j))^2 := by + simp only [valueMeshCompensated, valueMeshEnergy, Finset.sum_range_succ] + ring + +lemma valueMeshCompensated_zero (T : ℝ) (N : ℕ) (γ : ℝ → ℝ) (V : ℝ → ℝ → ℝ) + (z : Fin (N+1) → ℝ) : valueMeshCompensated T N γ V 0 z=V 0 0 := by + simp [valueMeshCompensated, valueMeshEnergy, meshTime, euler] + +noncomputable def valueMeshError (T : ℝ) (N : ℕ) (γ : ℝ → ℝ) (V : ℝ → ℝ → ℝ) : ℝ := + ∫ z, (valueMeshCompensated T N γ V N z-V 0 0-∑ i : Fin N, + Real.sqrt (stepSize T N)*deriv (V (meshTime T N i)) + (euler T N γ (fun t ↦ deriv (V t)) z i)*coordinate N i z)^2 + ∂gaussianProduct (Fin (N+1)) + +lemma valueMeshError_bound {T K L : ℝ} {γ : ℝ → ℝ} {V : ℝ → ℝ → ℝ} + (hT : 0 simp only [hsucc, euler, cubicEnvelope, t, δ, u] + all_goals congr 1 + all_goals ring_nf + have hb := discrete_gradient_residual_L2 (δ := δ) hδ hG h.K_nonneg + (mul_nonneg (by positivity) h.L_nonneg : 0≤(1/2+γ T)*L) + (Γ := fun j ↦ γ (meshTime T N j)) + (U := valueMeshCompensated T N γ V) + (A := fun i z ↦ u (meshTime T N i) (euler T N γ u z i)) + (H := fun i z ↦ deriv (u (meshTime T N i)) (euler T N γ u z i)) + (by simpa only [hlast, hzero] using h.gamma_mono ht0 htT hT.le) + hUm (fun i ↦ hAm i i.isLt.le) hHm + (fun i ↦ eulerCoefficient_dependsBefore T i.isLt.le γ u (fun t ↦ deriv (u t))) + (fun i z ↦ h.second_bound _ (htime i i.isLt.le) _) hloc + simpa only [valueMeshError, valueMeshCompensated_zero, hlast, hzero, u, δ] using hb + +lemma valueMeshError_bound_linear {T K L : ℝ} {γ : ℝ → ℝ} {V : ℝ → ℝ → ℝ} + (hT : 0 fun _ ↦ 1 + | n+1 => fun x ↦ deriv (expJet c ψ n) x+expJet c ψ n x*(c*deriv ψ x) + +lemma expJet_boundedSmooth {ψ : ℝ → ℝ} (hψ : BoundedSmooth (deriv ψ)) (c : ℝ) (n : ℕ) : + BoundedSmooth (expJet c ψ n) := by + induction n with + | zero => exact BoundedSmooth.const 1 + | succ n ih => exact ih.deriv.add (ih.mul (hψ.const_mul c)) + +lemma exp_iteratedDeriv {ψ : ℝ → ℝ} (hψs : ContDiff ℝ ∞ ψ) + (hψ : BoundedSmooth (deriv ψ)) (c : ℝ) (n : ℕ) : + iteratedDeriv n (fun x ↦ Real.exp (c*ψ x)) = + fun x ↦ Real.exp (c*ψ x)*expJet c ψ n x := by + induction n with + | zero => simp only [iteratedDeriv_zero,expJet,mul_one] + | succ n ih => + rw [iteratedDeriv_succ,ih] + funext x + have hψd := hψs.differentiable (ne_of_gt (ENat.natCast_lt_of_coe_top_le_withTop le_rfl 0)) + have hJd := (expJet_boundedSmooth hψ c n).smooth.differentiable + (ne_of_gt (ENat.natCast_lt_of_coe_top_le_withTop le_rfl 0)) + have hd := (((hψd x).hasDerivAt.const_mul c).exp).mul (hJd x).hasDerivAt + convert! hd.deriv using 1 + dsimp only [expJet] + ring + +lemma exp_iteratedDeriv_growth {ψ : ℝ → ℝ} (hψl : LipschitzWith 1 ψ) + (hψs : ContDiff ℝ ∞ ψ) (hψ : BoundedSmooth (deriv ψ)) {c : ℝ} (hc : 0≤c) (n : ℕ) : + ExpGrowth (iteratedDeriv n (fun x ↦ Real.exp (c*ψ x))) := by + rw [exp_iteratedDeriv hψs hψ c n] + obtain ⟨C,hC,hJ⟩ := (expJet_boundedSmooth hψ c n).bound_zero + exact (ExpGrowth.exp_lipschitz hψl hc).mul_bounded hC hJ + +lemma coleHopf_contDiff_of_pos {ψ : ℝ → ℝ} (hψl : LipschitzWith 1 ψ) + (hψs : ContDiff ℝ ∞ ψ) (hψ : BoundedSmooth (deriv ψ)) {c : ℝ} (hc : 0 try rfl + · funext y + simp only [gaussianPDFReal,NNReal.coe_one,mul_one,sub_zero] + · simp only [gaussianPDFReal,NNReal.coe_one,mul_one,sub_zero] + ring + +lemma density_mul_integrable {f : ℝ → ℝ} (hf : Integrable f standardGaussian) : + Integrable (fun x ↦ gaussianPDFReal 0 1 x*f x) := by + rw [standardGaussian,gaussianReal_of_var_ne_zero _ (by norm_num)] at hf + have hh := (integrable_withDensity_iff_integrable_smul' + (measurable_gaussianPDF 0 1) (Eventually.of_forall (fun x ↦ gaussianPDF_lt_top (μ := 0) (v := 1) (x := x)))).mp hf + simpa only [toReal_gaussianPDF,smul_eq_mul] using hh + +lemma gaussian_exp_abs_integrable (a : ℝ) : + Integrable (fun z ↦ Real.exp (a* |z|)) standardGaussian := by + have hi := (integrable_exp_mul_gaussianReal (μ := 0) (v := 1) a).add + (integrable_exp_mul_gaussianReal (μ := 0) (v := 1) (-a)) + apply hi.mono' (by fun_prop) + filter_upwards [] with z + rw [Real.norm_eq_abs,abs_of_pos (Real.exp_pos _)] + simp only [Pi.add_apply] + rcases le_total 0 z with hz | hz + · rw [abs_of_nonneg hz] + linarith [Real.exp_pos (-a*z)] + · rw [abs_of_nonpos hz] + have hid : a*(-z)=(-a)*z := by ring + rw [hid] + linarith [Real.exp_pos (a*z)] + +lemma lipschitz_exp_bound {ψ : ℝ → ℝ} (hψ : LipschitzWith 1 ψ) + {c : ℝ} (hc : 0≤c) (x y z s : ℝ) : + Real.exp (c*ψ (y+s*z)) ≤ + Real.exp (c*(ψ x+|y-x|+|s| * |z|)) := by + apply Real.exp_le_exp.mpr + apply mul_le_mul_of_nonneg_left _ hc + have hh := hψ.dist_le_mul (y+s*z) x + simp only [Real.dist_eq,NNReal.coe_one,one_mul] at hh + have ha : |y+s*z-x|≤|y-x|+|s| * |z| := by + rw [show y+s*z-x = (y-x)+s*z by ring] + simpa only [abs_mul] using abs_add_le (y-x) (s*z) + have hb := le_abs_self (ψ (y+s*z)-ψ x) + linarith + +lemma lipschitz_exp_integrable {ψ : ℝ → ℝ} (hψ : LipschitzWith 1 ψ) + {c : ℝ} (hc : 0≤c) (x s : ℝ) : + Integrable (fun z ↦ Real.exp (c*ψ (x+s*z))) standardGaussian := by + have hi := (gaussian_exp_abs_integrable (c* |s|)).const_mul (Real.exp (c*ψ x)) + have hψc := hψ.continuous + apply hi.mono' (by fun_prop) + filter_upwards [] with z + rw [Real.norm_eq_abs,abs_of_pos (Real.exp_pos _)] + have hh := lipschitz_exp_bound hψ hc x x z s + simpa only [sub_self,abs_zero,add_zero,mul_add,Real.exp_add,mul_assoc] using hh + +lemma lipschitz_exp_integral_pos {ψ : ℝ → ℝ} (hψ : LipschitzWith 1 ψ) + {c : ℝ} (hc : 0≤c) (x s : ℝ) : + 0 < ∫ z, Real.exp (c*ψ (x+s*z)) ∂standardGaussian := + integral_exp_pos (lipschitz_exp_integrable hψ hc x s) + +lemma gaussian_stein_of_integrable {f f' : ℝ → ℝ} + (hf : ∀ x, HasDerivAt f (f' x) x) (hfi : Integrable f standardGaussian) + (hf'i : Integrable f' standardGaussian) + (hxfi : Integrable (fun x ↦ x*f x) standardGaussian) : + (∫ x, x*f x ∂standardGaussian) = ∫ x, f' x ∂standardGaussian := by + have hi1 : Integrable (fun x ↦ f x*(-x*gaussianPDFReal 0 1 x)) := by + convert (density_mul_integrable hxfi).neg using 1 + ext x + simp only [Pi.neg_apply] + ring + have hi2 : Integrable (fun x ↦ f' x*gaussianPDFReal 0 1 x) := by + simpa only [mul_comm] using density_mul_integrable hf'i + have hi3 : Integrable (fun x ↦ f x*gaussianPDFReal 0 1 x) := by + simpa only [mul_comm] using density_mul_integrable hfi + have hibp := integral_mul_deriv_eq_deriv_mul_of_integrable + (u := f) (v := gaussianPDFReal 0 1) (u' := f') (v' := fun x ↦ -x*gaussianPDFReal 0 1 x) + (fun x _ ↦ hf x) (fun x _ ↦ density_hasDerivAt x) hi1 hi2 hi3 + have hb : (∫ x, f x*(-x*gaussianPDFReal 0 1 x)) = + -(∫ x, gaussianPDFReal 0 1 x*(x*f x)) := by + rw [← integral_neg] + apply integral_congr_ae + exact Eventually.of_forall (fun x ↦ by ring) + rw [hb] at hibp + have he : (∫ x, gaussianPDFReal 0 1 x*(x*f x)) = + ∫ x, gaussianPDFReal 0 1 x*f' x := by + exact neg_injective hibp |>.trans (by congr 1; funext x; ring) + simpa only [standardGaussian,integral_gaussianReal_eq_integral_smul (by norm_num : (1 : ℝ≥0) ≠ 0), + smul_eq_mul] using he + +lemma exponential_heat_hasDerivAt {ψ : ℝ → ℝ} (hψ : LipschitzWith 1 ψ) + (hψs : ContDiff ℝ 1 ψ) {c : ℝ} (hc : 0≤c) (x s : ℝ) : + HasDerivAt (fun y ↦ ∫ z, Real.exp (c*ψ (y+s*z)) ∂standardGaussian) + (∫ z, Real.exp (c*ψ (x+s*z))*(c*deriv ψ (x+s*z)) ∂standardGaussian) x := by + have hψc := hψ.continuous + have hψ'c := hψs.continuous_deriv (by norm_num) + have hψd := hψs.differentiable (by norm_num) + let bd := fun z ↦ c*Real.exp (c*(ψ x+1))*Real.exp ((c* |s|)* |z|) + have hbi : Integrable bd standardGaussian := + (gaussian_exp_abs_integrable (c* |s|)).const_mul _ + apply (hasDerivAt_integral_of_dominated_loc_of_deriv_le + (F := fun y z ↦ Real.exp (c*ψ (y+s*z))) + (F' := fun y z ↦ Real.exp (c*ψ (y+s*z))*(c*deriv ψ (y+s*z))) + (s := Metric.ball x 1) (bound := bd) (by exact Metric.ball_mem_nhds x (by norm_num)) + (Eventually.of_forall (fun y ↦ by fun_prop)) + (lipschitz_exp_integrable hψ hc x s) (by fun_prop) _ hbi _).2 + · filter_upwards [] with z + intro y hy + have hyd : |y-x|≤1 := by simpa only [Metric.mem_ball,Real.dist_eq] using hy.le + have hd : |deriv ψ (y+s*z)|≤1 := by + simpa only [Real.norm_eq_abs,NNReal.coe_one] using norm_deriv_le_of_lipschitz hψ (x₀ := y+s*z) + have hex := lipschitz_exp_bound hψ hc x y z s + have hex' : Real.exp (c*ψ (y+s*z)) ≤ + Real.exp (c*(ψ x+1+|s| * |z|)) := + hex.trans (Real.exp_le_exp.mpr (mul_le_mul_of_nonneg_left (by linarith) hc)) + rw [Real.norm_eq_abs,abs_mul,abs_of_pos (Real.exp_pos _),abs_mul,abs_of_nonneg hc] + calc + _ ≤ Real.exp (c*ψ (y+s*z))*(c*1) := + mul_le_mul_of_nonneg_left (mul_le_mul_of_nonneg_left hd hc) (Real.exp_pos _).le + _ ≤ c*Real.exp (c*(ψ x+1+|s| * |z|)) := by + simpa only [mul_one,one_mul,mul_comm c] using mul_le_mul_of_nonneg_left hex' hc + _ = bd z := by simp only [bd,mul_add,Real.exp_add,mul_assoc] + · filter_upwards [] with z + intro y _ + have hh := (((hψd (y+s*z)).hasDerivAt.comp y ((hasDerivAt_id y).add_const (s*z))).const_mul c).exp + simpa only [mul_one,Function.comp_def,id_eq] using hh + +lemma lipschitz_heat_integrable {ψ : ℝ → ℝ} (hψ : LipschitzWith 1 ψ) (x s : ℝ) : + Integrable (fun z ↦ ψ (x+s*z)) standardGaussian := by + have hz : Integrable (fun z : ℝ ↦ z) standardGaussian := + (memLp_id_gaussianReal' (μ := (0 : ℝ)) (v := (1 : ℝ≥0)) 1 (by norm_num)).integrable le_rfl + have hψc := hψ.continuous + apply ((integrable_const (|ψ 0|+|x|)).add (hz.abs.const_mul |s|)).mono' (by fun_prop) + filter_upwards [] with z + simp only [Real.norm_eq_abs,Pi.add_apply] + have hh := hψ.dist_le_mul (x+s*z) 0 + simp only [NNReal.coe_one,one_mul,Real.dist_eq,sub_zero] at hh + have ha := abs_add_le (ψ (x+s*z)-ψ 0) (ψ 0) + have hb := abs_add_le x (s*z) + simp only [sub_add_cancel,abs_mul] at ha hb + linarith + +lemma heat_hasDerivAt {ψ : ℝ → ℝ} (hψ : LipschitzWith 1 ψ) + (hψs : ContDiff ℝ 1 ψ) (x s : ℝ) : + HasDerivAt (fun y ↦ ∫ z, ψ (y+s*z) ∂standardGaussian) + (∫ z, deriv ψ (x+s*z) ∂standardGaussian) x := by + have hψc := hψ.continuous + have hψ'c := hψs.continuous_deriv (by norm_num) + apply (hasDerivAt_integral_of_dominated_loc_of_deriv_le + (F := fun y z ↦ ψ (y+s*z)) (F' := fun y z ↦ deriv ψ (y+s*z)) + (s := Set.univ) (bound := fun _ ↦ (1 : ℝ)) (by simp) + (Eventually.of_forall (fun _ ↦ by fun_prop)) + (lipschitz_heat_integrable hψ x s) (by fun_prop) _ (integrable_const 1) _).2 + · exact Eventually.of_forall (fun _ _ _ ↦ norm_deriv_le_of_lipschitz hψ) + · filter_upwards [] with z + intro y _ + simpa only [Function.comp_def,id_eq,mul_one] using + (((hψs.differentiable (by norm_num)) (y+s*z)).hasDerivAt.comp y + ((hasDerivAt_id y).add_const (s*z))) + +lemma coleHopf_hasDerivAt_of_pos {ψ : ℝ → ℝ} (hψ : LipschitzWith 1 ψ) + (hψs : ContDiff ℝ 1 ψ) {c : ℝ} (hc : 0.mpr (hψ'b y) + rw [sq_abs] at h + nlinarith [mul_nonneg (sq_nonneg c) (sub_nonneg.mpr h)] + linarith [mul_le_mul_of_nonneg_left (hψ'' y) hc.le]) + have hp (y : ℝ) : heat h f y≠0 := (lipschitz_exp_integral_pos hψ hc.le y (Real.sqrt h)).ne' + have hd := heat_log_pde hfd hf'd (by dsimp [f'']; fun_prop) hfg hf'g hf''g hc.ne' hh hp x + have heq (r : ℝ) : coleHopf c r ψ = fun y ↦ Real.log (heat r f y)/c := by + funext y + simp only [coleHopf,ite_eq_right hc.ne',f] + simp_rw [heq] + exact hd + +lemma ExpGrowth.of_bound {f : ℝ → ℝ} {C : ℝ} (hC : 0≤C) (hf : ∀ x, |f x|≤C) : + ExpGrowth f := by + refine ⟨0,C,le_rfl,hC,?_⟩ + intro x + simpa only [zero_mul,Real.exp_zero,mul_one] using hf x + +lemma ExpGrowth.lipschitz {ψ : ℝ → ℝ} (hψ : LipschitzWith 1 ψ) : ExpGrowth ψ := by + refine ⟨1,|ψ 0|+1,by norm_num,by positivity,?_⟩ + intro x + have hh := hψ.dist_le_mul x 0 + simp only [NNReal.coe_one,one_mul,Real.dist_eq,sub_zero] at hh + have hu : |ψ x|≤|ψ 0|+|x| := by + have hh2 := abs_add_le (ψ x-ψ 0) (ψ 0) + rw [sub_add_cancel] at hh2 + linarith + rw [one_mul] + have he1 : 1≤Real.exp |x| := Real.one_le_exp (abs_nonneg x) + have he2 : |x|≤Real.exp |x| := by linarith [Real.add_one_le_exp |x|] + nlinarith [mul_le_mul_of_nonneg_left he1 (abs_nonneg (ψ 0))] + +lemma coleHopf_pde {ψ : ℝ → ℝ} (hψ : LipschitzWith 1 ψ) + (hψs : ContDiff ℝ 2 ψ) {K : ℝ} (hK : 0≤K) + (hψ'' : ∀ x, |deriv (deriv ψ) x|≤K) {c h : ℝ} (hc : 0≤c) (hh : 0.exp |>.mul hf.smooth.continuous.measurable) t + rw [hh] + apply integral_congr_ae + filter_upwards [] with x + rw [D.evolve_weight] + ring + +lemma ForwardDensityData.jump_density (D:ForwardDensityData) {A:ℝ → ℝ} + (hA:SmoothTerminal A) (heven:∀ x,A (-x)=A x) {c d:ℝ} (hcd:c≤d) (x:ℝ) : + Real.exp (d*A x)*(D.jump hA heven (d-c) (sub_nonneg.mpr hcd)).weight x= + Real.exp (c*A x)*D.weight x := by + rw [D.jump_weight] + have he:d*A x+(-(d-c)*A x)=c*A x := by ring + calc + _ = (Real.exp (d*A x)*Real.exp (-(d-c)*A x))*D.weight x := by ring + _ = _ := by rw [←Real.exp_add,he] + +lemma gaussian_heat_zero {f:ℝ → ℝ} (hf:Measurable f) {t:ℝ} (ht:0 ring + rw [he,abs_div,abs_mul,abs_of_nonneg (sq_nonneg d)] + norm_num + nlinarith [mul_le_mul_of_nonneg_right (hb y) (sq_nonneg d)] + +lemma derivative_difference_of_values {f g : ℝ → ℝ} {C ε d : ℝ} + (hf : ContDiff ℝ 2 f) (hg : ContDiff ℝ 2 g) (hC : 0 ≤ C) (hd : 0 simpa only [iteratedDeriv_zero] using hf + | succ k hk => + rw [iteratedDeriv_succ] + exact (contDiff_infty_iff_deriv.mp hk).2 + +lemma uniform_all_derivative_limits {A : Type*} {F : ℕ → A → ℝ → ℝ} {f : A → ℝ → ℝ} + (hF : TendstoUniformly (fun n (p : A×ℝ) ↦ F n p.1 p.2) (fun p ↦ f p.1 p.2) atTop) + (hs : ∀ n a, ContDiff ℝ ∞ (F n a)) + (hb : ∀ k, ∃ C : ℝ, 0 ≤ C ∧ ∀ n a x, |iteratedDeriv (k+1) (F n a) x| ≤ C) : + (∀ k, TendstoUniformly (fun n (p : A×ℝ) ↦ iteratedDeriv k (F n p.1) p.2) + (fun p ↦ iteratedDeriv k (f p.1) p.2) atTop) ∧ ∀ a, ContDiff ℝ ∞ (f a) := by + have step (k : ℕ) + (hk : TendstoUniformly (fun n (p : A×ℝ) ↦ iteratedDeriv k (F n p.1) p.2) + (fun p ↦ iteratedDeriv k (f p.1) p.2) atTop) : + TendstoUniformly (fun n (p : A×ℝ) ↦ iteratedDeriv (k+1) (F n p.1) p.2) + (fun p ↦ iteratedDeriv (k+1) (f p.1) p.2) atTop ∧ + ∀ a, Differentiable ℝ (iteratedDeriv k (f a)) := by + obtain ⟨C,hC,hbc⟩ := hb (k+1) + have hh := uniform_derivative_limit (F := fun n a ↦ iteratedDeriv k (F n a)) + (f := fun a ↦ iteratedDeriv k (f a)) hk + (fun n a ↦ (contDiff_infty_iteratedDeriv (hs n a) k).of_le + (ENat.natCast_le_of_coe_top_le_withTop le_rfl 2)) hC (fun n a x ↦ by + simpa only [iteratedDeriv_succ] using hbc n a x) + simpa only [iteratedDeriv_succ] using hh + have hc : ∀ k, TendstoUniformly (fun n (p : A×ℝ) ↦ iteratedDeriv k (F n p.1) p.2) + (fun p ↦ iteratedDeriv k (f p.1) p.2) atTop := by + intro k + induction k with + | zero => simpa only [iteratedDeriv_zero] using hF + | succ k hk => exact (step k hk).1 + refine ⟨hc,?_⟩ + intro a + apply contDiff_iff_iteratedDeriv.mpr + constructor + · intro m hm + exact ((step m (hc m)).2 a).continuous + · intro m hm + exact (step m (hc m)).2 a + +end SKValue + +end + +end OAI diff --git a/lean/OAI/Probability/SKValue/Evolution/EvolutionDifferentiation.lean b/lean/OAI/Probability/SKValue/Evolution/EvolutionDifferentiation.lean new file mode 100644 index 0000000000000000000000000000000000000000..fd194141cb07c088e9a7c5b3ab00b1df4ff030e8 --- /dev/null +++ b/lean/OAI/Probability/SKValue/Evolution/EvolutionDifferentiation.lean @@ -0,0 +1,172 @@ +import Mathlib +import OAI.Probability.SKValue.Evolution.SmoothEvolution +import OAI.Probability.SKValue.Evolution.EvolveStrips +import OAI.Probability.SKValue.Equations.ParametricChain + +namespace OAI + +section + +open MeasureTheory ProbabilityTheory Set Filter Asymptotics +open scoped Topology NNReal ENNReal BigOperators +namespace SKValue + +lemma SmoothEvolution.jet_joint_continuousOn {T : ℝ} {γ : ℝ → ℝ} {V : ℝ → ℝ → ℝ} + (h : SmoothEvolution T γ V) (n : ℕ) : + ContinuousOn (fun p : ℝ×ℝ ↦ iteratedDeriv n (deriv (V p.1)) p.2) (Icc (0 : ℝ) T ×ˢ univ) := by + obtain ⟨L,hL,hl⟩ := h.jet_joint n + have hh : LipschitzOnWith ⟨2*L,by positivity⟩ + (fun p : ℝ×ℝ ↦ iteratedDeriv n (deriv (V p.1)) p.2) (Icc (0 : ℝ) T ×ˢ univ) := by + apply LipschitzOnWith.of_dist_le_mul + intro p hp q hq + simp only [Real.dist_eq,Prod.dist_eq] + have hb := hl p.1 hp.1 q.1 hq.1 q.2 p.2 + change |iteratedDeriv n (deriv (V p.1)) p.2-iteratedDeriv n (deriv (V q.1)) q.2|≤ + (2*L)*max |p.1-q.1| |p.2-q.2| + have hm1 := le_max_left |p.1-q.1| |p.2-q.2| + have hm2 := le_max_right |p.1-q.1| |p.2-q.2| + nlinarith + exact hh.continuousOn + +lemma SmoothEvolution.jet_joint_continuousAt {T : ℝ} {γ : ℝ → ℝ} {V : ℝ → ℝ → ℝ} + (h : SmoothEvolution T γ V) (n : ℕ) {t : ℝ} (ht : t∈Ioo (0 : ℝ) T) (x : ℝ) : + ContinuousAt (fun p : ℝ×ℝ ↦ iteratedDeriv n (deriv (V p.1)) p.2) (t,x) := by + exact (h.jet_joint_continuousOn n (t,x) ⟨⟨ht.1.le,ht.2.le⟩,mem_univ x⟩).continuousAt + (prod_mem_nhds (Icc_mem_nhds ht.1 ht.2) univ_mem) + +lemma SmoothEvolution.gradient_time_hasDerivAt {T : ℝ} {γ : ℝ → ℝ} {V : ℝ → ℝ → ℝ} + (h : SmoothEvolution T γ V) (hm : Measurable γ) {t : ℝ} (ht : t∈Ioo (0 : ℝ) T) + (hγ : ContinuousAt γ t) (x : ℝ) : + HasDerivAt (fun s ↦ deriv (V s) x) + (-((1/2 : ℝ)*deriv (deriv (deriv (V t))) x+γ t*(deriv (V t) x*deriv (deriv (V t)) x))) t := by + let g := fun r ↦ (1/2 : ℝ)*deriv (deriv (deriv (V r))) x+γ r*(deriv (V r) x*deriv (deriv (V r)) x) + have hc0 : ContinuousOn (fun r ↦ deriv (V r) x) (Icc (0 : ℝ) T) := by + simpa only [iteratedDeriv_zero] using h.continuous_jet 0 x + have hc1 : ContinuousOn (fun r ↦ deriv (deriv (V r)) x) (Icc (0 : ℝ) T) := by + simpa only [iteratedDeriv_one] using h.continuous_jet 1 x + have hc2 : ContinuousOn (fun r ↦ deriv (deriv (deriv (V r))) x) (Icc (0 : ℝ) T) := by + simpa only [show (2 : ℕ)=1+1 from rfl,iteratedDeriv_succ,iteratedDeriv_one,iteratedDeriv_zero] + using h.continuous_jet 2 x + have hti : t∈Icc (0 : ℝ) T := ⟨ht.1.le,ht.2.le⟩ + have hn := Icc_mem_nhds ht.1 ht.2 + have hgc : ContinuousAt g t := + (continuousAt_const.mul ((hc2 t hti).continuousAt hn)).add + (hγ.mul (((hc0 t hti).continuousAt hn).mul ((hc1 t hti).continuousAt hn))) + have hgm : StronglyMeasurableAtFilter g (𝓝 t) volume := by + refine ⟨Icc (0 : ℝ) T,hn,?_⟩ + exact (aestronglyMeasurable_const.mul (hc2.aestronglyMeasurable measurableSet_Icc)).add + (hm.aestronglyMeasurable.mul ((hc0.aestronglyMeasurable measurableSet_Icc).mul + (hc1.aestronglyMeasurable measurableSet_Icc))) + have hd := (hasDerivAt_const t (deriv (V t) x)).sub + (intervalIntegral.integral_hasDerivAt_right (a := t) (b := t) (by simp) hgm hgc) + simp only [zero_sub] at hd + apply hd.congr_of_eventuallyEq + filter_upwards [hn] with s hs + have hh := h.gradient_pde t hti s hs x + dsimp only [g,Pi.sub_apply] at * + linarith + +lemma SmoothEvolution.gradient_curve_hasDerivAt {T : ℝ} {γ : ℝ → ℝ} {V : ℝ → ℝ → ℝ} + (h : SmoothEvolution T γ V) (hm : Measurable γ) {t : ℝ} (ht : t∈Ioo (0 : ℝ) T) + (hγ : ContinuousAt γ t) {φ : ℝ → ℝ} {b : ℝ} (hφ : HasDerivAt φ b t) : + HasDerivAt (fun s ↦ deriv (V s) (φ s)) + (-((1/2 : ℝ)*deriv (deriv (deriv (V t))) (φ t)+ + γ t*(deriv (V t) (φ t)*deriv (deriv (V t)) (φ t)))+deriv (deriv (V t)) (φ t)*b) t := by + apply hasDerivAt_parametric_comp (h.gradient_time_hasDerivAt hm ht hγ (φ t)) hφ + · have he : ∀ᶠ p : ℝ×ℝ in 𝓝 (t,φ t), p.1∈Icc (0 : ℝ) T := + continuousAt_fst.preimage_mem_nhds (Icc_mem_nhds ht.1 ht.2) + filter_upwards [he] with p hp + exact ((h.slices p.1 hp).jets.smooth.differentiable + (ne_of_gt (ENat.natCast_lt_of_coe_top_le_withTop le_rfl 0)) p.2).hasDerivAt + · simpa only [iteratedDeriv_one] using h.jet_joint_continuousAt 1 ht (φ t) + +end SKValue + +end + +section + +open MeasureTheory ProbabilityTheory Set Filter +open scoped Topology NNReal ENNReal BigOperators +namespace SKValue + +lemma sqrt_difference_bound {δ u v : ℝ} (hδ : 0<δ) (hu : δ≤u) (hv : δ≤v) : + |Real.sqrt u-Real.sqrt v|≤(Real.sqrt δ)⁻¹*|u-v| := by + have hd := Real.sqrt_pos.mpr hδ + have hu0 := hδ.le.trans hu + have hv0 := hδ.le.trans hv + have he : |u-v|=|Real.sqrt u-Real.sqrt v| * (Real.sqrt u+Real.sqrt v) := by + rw [←abs_of_nonneg (add_nonneg (Real.sqrt_nonneg _) (Real.sqrt_nonneg _)),←abs_mul] + congr 1 + nlinarith [Real.sq_sqrt hu0,Real.sq_sqrt hv0] + have hh : Real.sqrt δ≤Real.sqrt u+Real.sqrt v := by + linarith [Real.sqrt_le_sqrt hu,Real.sqrt_nonneg v] + rw [inv_mul_eq_div] + apply (le_div_iff₀ hd).mpr + rw [he] + exact mul_le_mul_of_nonneg_left hh (abs_nonneg _) + +lemma SmoothEvolution.heat_gradient_derivative_integral {T a t : ℝ} {γ : ℝ → ℝ} + {V : ℝ → ℝ → ℝ} (h : SmoothEvolution T γ V) (hm : Measurable γ) + (ha : 0≤a) (hat : a simp [patchTime,ht] + +lemma patchTime_gradient {a t : ℝ} (V W : ℝ → ℝ → ℝ) : + deriv (patchTime a V W t)=patchTime a (fun t ↦ deriv (V t)) (fun t ↦ deriv (W t)) t := by + by_cases ht : t≤a <;> simp [patchTime,ht] + +lemma patchTime_jet {a t x : ℝ} (V W : ℝ → ℝ → ℝ) (n : ℕ) : + iteratedDeriv n (deriv (patchTime a V W t)) x= + patchTime a (fun t ↦ iteratedDeriv n (deriv (V t)) x) (fun t ↦ iteratedDeriv n (deriv (W t)) x) t := by + by_cases ht : t≤a <;> simp [patchTime,ht] + +lemma SmoothEvolution.value_rhs_integrable {T : ℝ} (hT : 0≤T) + {γ : ℝ → ℝ} {V : ℝ → ℝ → ℝ} (h : SmoothEvolution T γ V) + (hg : IntervalIntegrable γ volume 0 T) (x : ℝ) : + IntervalIntegrable (fun r ↦ -((1/2 : ℝ)*deriv (deriv (V r)) x+ + γ r*((1/2 : ℝ)*(deriv (V r) x)^2))) volume 0 T := by + have hc1 : ContinuousOn (fun t ↦ deriv (deriv (V t)) x) (uIcc (0 : ℝ) T) := by + simpa only [uIcc_of_le hT,iteratedDeriv_one] using h.continuous_jet 1 x + have hc0 : ContinuousOn (fun t ↦ deriv (V t) x) (uIcc (0 : ℝ) T) := by + simpa only [uIcc_of_le hT,iteratedDeriv_zero] using h.continuous_jet 0 x + apply IntervalIntegrable.neg + apply IntervalIntegrable.add (hc1.intervalIntegrable.const_mul _) + apply hg.mul_continuousOn + convert! continuousOn_const.mul (hc0.pow 2) using 1 + +lemma SmoothEvolution.gradient_rhs_integrable {T : ℝ} (hT : 0≤T) + {γ : ℝ → ℝ} {V : ℝ → ℝ → ℝ} (h : SmoothEvolution T γ V) + (hg : IntervalIntegrable γ volume 0 T) (x : ℝ) : + IntervalIntegrable (fun r ↦ -((1/2 : ℝ)*deriv (deriv (deriv (V r))) x+ + γ r*(deriv (V r) x*deriv (deriv (V r)) x))) volume 0 T := by + have hc2 : ContinuousOn (fun t ↦ deriv (deriv (deriv (V t))) x) (uIcc (0 : ℝ) T) := by + simpa only [uIcc_of_le hT,show (2:ℕ)=1+1 from rfl,iteratedDeriv_succ,iteratedDeriv_zero] + using h.continuous_jet 2 x + have hc1 : ContinuousOn (fun t ↦ deriv (deriv (V t)) x) (uIcc (0 : ℝ) T) := by + simpa only [uIcc_of_le hT,iteratedDeriv_one] using h.continuous_jet 1 x + have hc0 : ContinuousOn (fun t ↦ deriv (V t) x) (uIcc (0 : ℝ) T) := by + simpa only [uIcc_of_le hT,iteratedDeriv_zero] using h.continuous_jet 0 x + apply IntervalIntegrable.neg + apply IntervalIntegrable.add (hc2.intervalIntegrable.const_mul _) + apply hg.mul_continuousOn + convert! hc0.mul hc1 using 1 + +lemma primitive_to_integral {T : ℝ} (hT : 0≤T) {f p : ℝ → ℝ} + (hp : IntervalIntegrable p volume 0 T) + (hf : ∀ t∈Icc (0 : ℝ) T, f t-f 0=∫ r in (0 : ℝ)..t, p r) + {s t : ℝ} (hs : s∈Icc (0 : ℝ) T) (ht : t∈Icc (0 : ℝ) T) : + f s-f t=∫ r in t..s, p r := by + have hi {a b : ℝ} (ha : a∈Icc (0 : ℝ) T) (hb : b∈Icc (0 : ℝ) T) : + IntervalIntegrable p volume a b := hp.mono_set (by + rw [uIcc_of_le hT] + exact uIcc_subset_Icc ha hb) + have hh := intervalIntegral.integral_add_adjacent_intervals (hi ⟨le_rfl,hT⟩ ht) (hi ht hs) + rw [←hf s hs,←hf t ht] at hh + linarith + +lemma SmoothEvolution.patch_value_pde {a b : ℝ} (ha : 0≤a) (hb : 0≤b) + {γ η : ℝ → ℝ} {V W : ℝ → ℝ → ℝ} + (hV : SmoothEvolution a γ V) (hW : SmoothEvolution b η W) + (hγ : IntervalIntegrable γ volume 0 a) (hη : IntervalIntegrable η volume 0 b) + (hjoin : V a=W 0) {s t : ℝ} (hs : s∈Icc (0 : ℝ) (a+b)) (ht : t∈Icc (0 : ℝ) (a+b)) (x : ℝ) : + patchTime a V W s x-patchTime a V W t x = + -(∫ r in t..s, (1/2 : ℝ)*deriv (deriv (patchTime a V W r)) x+ + patchTime a γ η r*((1/2 : ℝ)*(deriv (patchTime a V W r) x)^2)) := by + let p := fun r ↦ -((1/2 : ℝ)*deriv (deriv (V r)) x+γ r*((1/2 : ℝ)*(deriv (V r) x)^2)) + let q := fun r ↦ -((1/2 : ℝ)*deriv (deriv (W r)) x+η r*((1/2 : ℝ)*(deriv (W r) x)^2)) + have hp := hV.value_rhs_integrable ha hγ x + have hq := hW.value_rhs_integrable hb hη x + have hv : ∀ t∈Icc (0 : ℝ) a, V t x-V 0 x=∫ r in (0 : ℝ)..t, p r := by + intro t ht + simpa only [p,intervalIntegral.integral_neg] using hV.value_pde 0 ⟨le_rfl,ha⟩ t ht x + have hw : ∀ t∈Icc (0 : ℝ) b, W t x-W 0 x=∫ r in (0 : ℝ)..t, q r := by + intro t ht + simpa only [q,intervalIntegral.integral_neg] using hW.value_pde 0 ⟨le_rfl,hb⟩ t ht x + have he := primitive_to_integral (add_nonneg ha hb) (patchTime_intervalIntegrable ha hb hp hq) + (patchTime_primitive ha hb hp hq hv hw (congrFun hjoin x)) hs ht + rw [←patchTime_apply V W,←patchTime_apply V W] at he + rw [he,←intervalIntegral.integral_neg] + apply intervalIntegral.integral_congr + intro r _ + by_cases hr : r≤a <;> simp [patchTime,hr] + +lemma SmoothEvolution.patch_gradient_pde {a b : ℝ} (ha : 0≤a) (hb : 0≤b) + {γ η : ℝ → ℝ} {V W : ℝ → ℝ → ℝ} + (hV : SmoothEvolution a γ V) (hW : SmoothEvolution b η W) + (hγ : IntervalIntegrable γ volume 0 a) (hη : IntervalIntegrable η volume 0 b) + (hjoin : V a=W 0) {s t : ℝ} (hs : s∈Icc (0 : ℝ) (a+b)) (ht : t∈Icc (0 : ℝ) (a+b)) (x : ℝ) : + deriv (patchTime a V W s) x-deriv (patchTime a V W t) x = + -(∫ r in t..s, (1/2 : ℝ)*deriv (deriv (deriv (patchTime a V W r))) x+ + patchTime a γ η r*(deriv (patchTime a V W r) x*deriv (deriv (patchTime a V W r)) x)) := by + let p := fun r ↦ -((1/2 : ℝ)*deriv (deriv (deriv (V r))) x+γ r*(deriv (V r) x*deriv (deriv (V r)) x)) + let q := fun r ↦ -((1/2 : ℝ)*deriv (deriv (deriv (W r))) x+η r*(deriv (W r) x*deriv (deriv (W r)) x)) + have hp := hV.gradient_rhs_integrable ha hγ x + have hq := hW.gradient_rhs_integrable hb hη x + have hv : ∀ t∈Icc (0 : ℝ) a, deriv (V t) x-deriv (V 0) x=∫ r in (0 : ℝ)..t, p r := by + intro t ht + simpa only [p,intervalIntegral.integral_neg] using hV.gradient_pde 0 ⟨le_rfl,ha⟩ t ht x + have hw : ∀ t∈Icc (0 : ℝ) b, deriv (W t) x-deriv (W 0) x=∫ r in (0 : ℝ)..t, q r := by + intro t ht + simpa only [q,intervalIntegral.integral_neg] using hW.gradient_pde 0 ⟨le_rfl,hb⟩ t ht x + have hj : deriv (V a) x=deriv (W 0) x := by rw [hjoin] + have he := primitive_to_integral (add_nonneg ha hb) (patchTime_intervalIntegrable ha hb hp hq) + (patchTime_primitive ha hb hp hq hv hw hj) hs ht + simp_rw [patchTime_gradient,patchTime_apply] + rw [he,←intervalIntegral.integral_neg] + apply intervalIntegral.integral_congr + intro r _ + by_cases hr : r≤a <;> simp [patchTime,hr] + +lemma SmoothEvolution.patch {a b : ℝ} (ha : 0≤a) (hb : 0≤b) + {γ η : ℝ → ℝ} {V W : ℝ → ℝ → ℝ} + (hV : SmoothEvolution a γ V) (hW : SmoothEvolution b η W) + (hγ : IntervalIntegrable γ volume 0 a) (hη : IntervalIntegrable η volume 0 b) + (hjoin : V a=W 0) : + SmoothEvolution (a+b) (patchTime a γ η) (patchTime a V W) := by + refine ⟨?_,?_,?_,?_,?_,?_,?_⟩ + · intro t ht + by_cases hta : t≤a + · rw [patchTime_left V W hta] + exact hV.slices t ⟨ht.1,hta⟩ + · rw [patchTime_right V W (lt_of_not_ge hta)] + exact hW.slices (t-a) ⟨by linarith,by linarith [ht.2]⟩ + · intro x + simp_rw [patchTime_apply] + exact patchTime_continuous (hV.continuous_value x) (hW.continuous_value x) (congrFun hjoin x) + · intro n x + simp_rw [patchTime_jet] + apply patchTime_continuous (hV.continuous_jet n x) (hW.continuous_jet n x) + rw [hjoin] + · intro n + obtain ⟨C,hC,hv⟩ := hV.bound n + obtain ⟨D,hD,hw⟩ := hW.bound n + refine ⟨C+D,add_nonneg hC hD,?_⟩ + intro t ht x + rw [patchTime_jet] + exact patchTime_bound hC hD (fun t ht ↦ hv t ht x) (fun t ht ↦ hw t ht x) t ht + · intro n + obtain ⟨C,hC,hv⟩ := hV.temporal n + obtain ⟨D,hD,hw⟩ := hW.temporal n + refine ⟨C+D,add_nonneg hC hD,?_⟩ + intro s hs t ht x + rw [patchTime_jet,patchTime_jet] + apply patchTime_lipschitz ha hb hC hD (fun s hs t ht ↦ hv s hs t ht x) + (fun s hs t ht ↦ hw s hs t ht x) _ s hs t ht + rw [hjoin] + · intro t ht s hs x + exact hV.patch_value_pde ha hb hW hγ hη hjoin hs ht x + · intro t ht s hs x + exact hV.patch_gradient_pde ha hb hW hγ hη hjoin hs ht x + +end SKValue + +end + +end OAI diff --git a/lean/OAI/Probability/SKValue/Evolution/EvolutionShift.lean b/lean/OAI/Probability/SKValue/Evolution/EvolutionShift.lean new file mode 100644 index 0000000000000000000000000000000000000000..71702d6988b9dcd97ed56362ca60791081351287 --- /dev/null +++ b/lean/OAI/Probability/SKValue/Evolution/EvolutionShift.lean @@ -0,0 +1,83 @@ +import Mathlib +import OAI.Probability.SKValue.Evolution.SmoothEvolution + +namespace OAI + +section + +open MeasureTheory ProbabilityTheory Set Filter +open scoped Topology NNReal ENNReal BigOperators ContDiff +namespace SKValue + +lemma deriv_const_add_eq (f : ℝ → ℝ) (x : ℝ) : + deriv (fun y ↦ f (x+y))=fun y ↦ deriv f (x+y) := + funext (deriv_comp_const_add f x) + +lemma BoundedSmooth.translate {f : ℝ → ℝ} (hf : BoundedSmooth f) (x : ℝ) : + BoundedSmooth (fun y ↦ f (x+y)) := by + refine ⟨hf.smooth.comp (contDiff_const.add contDiff_id),?_⟩ + intro n + obtain ⟨C,hC,hb⟩ := hf.bound n + refine ⟨C,hC,?_⟩ + simpa only [iteratedDeriv_comp_const_add] using fun y ↦ hb (x+y) + +lemma SmoothTerminal.translate {f : ℝ → ℝ} (hf : SmoothTerminal f) (x : ℝ) : + SmoothTerminal (fun y ↦ f (x+y)) := by + refine ⟨?_,hf.smooth.comp (contDiff_const.add contDiff_id),?_⟩ + · apply LipschitzWith.of_dist_le_mul + intro y z + simpa only [Real.dist_eq,add_sub_add_left_eq_sub,NNReal.coe_one,one_mul] using hf.lipschitz.dist_le_mul (x+y) (x+z) + · rw [deriv_const_add_eq] + exact hf.jets.translate x + +lemma SmoothEvolution.space_translate {T : ℝ} {γ : ℝ → ℝ} {V : ℝ → ℝ → ℝ} + (h : SmoothEvolution T γ V) (x : ℝ) : + SmoothEvolution T γ (fun t y ↦ V t (x+y)) := by + refine ⟨fun t ht ↦ (h.slices t ht).translate x,fun y ↦ h.continuous_value (x+y),?_,?_,?_,?_,?_⟩ + · intro n y + simpa only [deriv_const_add_eq,iteratedDeriv_comp_const_add] using h.continuous_jet n (x+y) + · intro n + obtain ⟨C,hC,hb⟩ := h.bound n + exact ⟨C,hC,by simpa only [deriv_const_add_eq,iteratedDeriv_comp_const_add] using fun t ht y ↦ hb t ht (x+y)⟩ + · intro n + obtain ⟨C,hC,hb⟩ := h.temporal n + exact ⟨C,hC,by simpa only [deriv_const_add_eq,iteratedDeriv_comp_const_add] using fun s hs t ht y ↦ hb s hs t ht (x+y)⟩ + · intro t ht s hs y + simpa only [deriv_const_add_eq] using h.value_pde t ht s hs (x+y) + · intro t ht s hs y + simpa only [deriv_const_add_eq] using h.gradient_pde t ht s hs (x+y) + +lemma SmoothEvolution.time_shift {T a b : ℝ} {γ : ℝ → ℝ} {V : ℝ → ℝ → ℝ} + (h : SmoothEvolution T γ V) (ha : 0≤a) (hab : a≤b) (hb : b≤T) : + SmoothEvolution (b-a) (fun t ↦ γ (a+t)) (fun t ↦ V (a+t)) := by + have hmem (t : ℝ) (ht : t∈Icc (0 : ℝ) (b-a)) : a+t∈Icc (0 : ℝ) T := by + apply (ordConnected_Icc : OrdConnected (Icc (0 : ℝ) T)).out + ⟨ha,hab.trans hb⟩ ⟨ha.trans hab,hb⟩ + constructor <;> linarith [ht.1,ht.2] + refine ⟨fun t ht ↦ h.slices _ (hmem t ht),?_,?_,?_,?_,?_,?_⟩ + · intro x + exact (h.continuous_value x).comp (continuous_const.add continuous_id).continuousOn hmem + · intro n x + exact (h.continuous_jet n x).comp (continuous_const.add continuous_id).continuousOn hmem + · intro n + obtain ⟨C,hC,hb⟩ := h.bound n + exact ⟨C,hC,fun t ht ↦ hb _ (hmem t ht)⟩ + · intro n + obtain ⟨C,hC,hb⟩ := h.temporal n + refine ⟨C,hC,?_⟩ + intro s hs t ht x + simpa only [add_sub_add_left_eq_sub] using hb _ (hmem s hs) _ (hmem t ht) x + · intro t ht s hs x + rw [intervalIntegral.integral_comp_add_left + (fun r ↦ (1/2 : ℝ)*deriv (deriv (V r)) x+γ r*((1/2 : ℝ)*(deriv (V r) x)^2)) a] + exact h.value_pde _ (hmem t ht) _ (hmem s hs) x + · intro t ht s hs x + rw [intervalIntegral.integral_comp_add_left + (fun r ↦ (1/2 : ℝ)*deriv (deriv (deriv (V r))) x+γ r*(deriv (V r) x*deriv (deriv (V r)) x)) a] + exact h.gradient_pde _ (hmem t ht) _ (hmem s hs) x + +end SKValue + +end + +end OAI diff --git a/lean/OAI/Probability/SKValue/Evolution/EvolveStrips.lean b/lean/OAI/Probability/SKValue/Evolution/EvolveStrips.lean new file mode 100644 index 0000000000000000000000000000000000000000..fb7a37d8fe05ede04c6cd24054249b506682d999 --- /dev/null +++ b/lean/OAI/Probability/SKValue/Evolution/EvolveStrips.lean @@ -0,0 +1,182 @@ +import Mathlib +import OAI.Probability.SKValue.Equations.ValueStrip +import OAI.Probability.SKValue.Evolution.SmoothEvolution + +namespace OAI + +section + +open MeasureTheory ProbabilityTheory Set Filter +open scoped Topology NNReal ENNReal BigOperators ContDiff +namespace SKValue + +lemma SmoothEvolution.jet_joint {T : ℝ} {γ : ℝ → ℝ} {V : ℝ → ℝ → ℝ} + (h : SmoothEvolution T γ V) (n : ℕ) : + ∃ L : ℝ, 0≤L ∧ ∀ s∈Icc (0 : ℝ) T, ∀ t∈Icc (0 : ℝ) T, ∀ x y, + |iteratedDeriv n (deriv (V s)) y-iteratedDeriv n (deriv (V t)) x|≤L*(|s-t|+|y-x|) := by + obtain ⟨A,hA,ha⟩ := h.temporal n + obtain ⟨B,hB,hb⟩ := h.bound (n+1) + refine ⟨A+B,add_nonneg hA hB,?_⟩ + intro s hs t ht x y + have hd := (h.slices t ht).jets.smooth.differentiable_iteratedDeriv n + (ENat.natCast_lt_of_coe_top_le_withTop le_rfl n) + have hl : LipschitzWith ⟨B,hB⟩ (iteratedDeriv n (deriv (V t))) := by + apply lipschitzWith_of_nnnorm_deriv_le hd + intro z + have hz := hb t ht z + rw [iteratedDeriv_succ] at hz + exact_mod_cast hz + have hx := hl.dist_le_mul y x + simp only [Real.dist_eq] at hx + change |iteratedDeriv n (deriv (V t)) y-iteratedDeriv n (deriv (V t)) x|≤B*|y-x| at hx + have hh := abs_sub_le (iteratedDeriv n (deriv (V s)) y) + (iteratedDeriv n (deriv (V t)) y) (iteratedDeriv n (deriv (V t)) x) + have ht := ha s hs t ht y + nlinarith [mul_nonneg hA (abs_nonneg (y-x)),mul_nonneg hB (abs_nonneg (s-t))] + +lemma bounded_product_difference {a b c d A B Lf Lg ρ : ℝ} + (ha : |a|≤A) (hd : |d|≤B) (hf : |a-c|≤Lf*ρ) (hg : |b-d|≤Lg*ρ) + (hA : 0≤A) (hB : 0≤B) : |a*b-c*d|≤(A*Lg+B*Lf)*ρ := by + have hid : a*b-c*d=a*(b-d)+d*(a-c) := by ring + rw [hid] + apply (abs_add_le _ _).trans + rw [abs_mul,abs_mul] + have h1 := mul_le_mul ha hg (abs_nonneg _) hA + have h2 := mul_le_mul hd hf (abs_nonneg _) hB + nlinarith + +lemma SmoothEvolution.deriv_bound {T : ℝ} {γ : ℝ → ℝ} {V : ℝ → ℝ → ℝ} + (h : SmoothEvolution T γ V) {t : ℝ} (ht : t∈Icc (0 : ℝ) T) (x : ℝ) : + |deriv (V t) x|≤1 := by + simpa only [Real.norm_eq_abs,NNReal.coe_one] using norm_deriv_le_of_lipschitz (h.slices t ht).lipschitz (x₀ := x) + +lemma SmoothEvolution.toValueStrip {T : ℝ} (hT : 0≤T) {γ : ℝ → ℝ} {V : ℝ → ℝ → ℝ} + (h : SmoothEvolution T γ V) (hγ : ∀ t∈Icc (0 : ℝ) T, 0≤γ t) + (hγmono : MonotoneOn γ (Icc (0 : ℝ) T)) : + ∃ K L, ValueStrip T γ V K L := by + obtain ⟨B1,hB1,hb1⟩ := h.bound 1 + obtain ⟨B2,hB2,hb2⟩ := h.bound 2 + obtain ⟨L0,hL0,hl0⟩ := h.jet_joint 0 + obtain ⟨L1,hL1,hl1⟩ := h.jet_joint 1 + let K := B1+B2+1 + let L := L0+L1 + have hK : 0≤K := by dsimp [K]; positivity + have hL : 0≤L := by dsimp [L]; positivity + have hgint : IntervalIntegrable γ volume 0 T := by + apply MonotoneOn.intervalIntegrable + simpa only [uIcc_of_le hT] using hγmono + have hc1 (x : ℝ) : ContinuousOn (fun t ↦ deriv (deriv (V t)) x) (Icc (0 : ℝ) T) := by + simpa only [iteratedDeriv_one] using h.continuous_jet 1 x + have hc0 (x : ℝ) : ContinuousOn (fun t ↦ deriv (V t) x) (Icc (0 : ℝ) T) := by + simpa only [iteratedDeriv_zero] using h.continuous_jet 0 x + refine ⟨K,L,hK,hL,hγ,hγmono,?_,fun t ht x ↦ h.deriv_bound ht x,?_,?_,?_,?_,?_,?_,?_,h.value_pde⟩ + · intro t ht + exact (h.slices t ht).smooth.of_le (ENat.natCast_le_of_coe_top_le_withTop le_rfl 3) + · intro t ht x + have hb := hb1 t ht x + simp only [iteratedDeriv_one] at hb + dsimp [K] + linarith + · intro t ht x + have hb := hb2 t ht x + rw [←iteratedDeriv_succ'] at hb + dsimp [K] + linarith + · intro t ht x + have hb := h.deriv_bound ht x + have hs : (deriv (V t) x)^2≤1 := (sq_le_one_iff_abs_le_one _).mpr hb + rw [abs_mul,abs_of_nonneg (by positivity : (0:ℝ)≤1/2),abs_of_nonneg (sq_nonneg _)] + dsimp [K] + nlinarith + · intro t ht s hs x y + have hb := hl1 s hs t ht x y + simp only [iteratedDeriv_one] at hb + dsimp [L] + nlinarith [mul_nonneg hL0 (add_nonneg (abs_nonneg (s-t)) (abs_nonneg (y-x)))] + · intro t ht s hs x y + have hf := hl0 s hs t ht x y + simp only [iteratedDeriv_zero] at hf + have hb := bounded_product_difference (h.deriv_bound hs y) (h.deriv_bound ht x) hf hf (by norm_num) (by norm_num) + have hid : (1/2 : ℝ)*(deriv (V s) y)^2-(1/2 : ℝ)*(deriv (V t) x)^2 = + (1/2 : ℝ)*(deriv (V s) y*deriv (V s) y-deriv (V t) x*deriv (V t) x) := by ring + rw [hid,abs_mul,abs_of_nonneg (by positivity : (0:ℝ)≤1/2)] + dsimp [L] + nlinarith [mul_nonneg hL1 (add_nonneg (abs_nonneg (s-t)) (abs_nonneg (y-x)))] + · intro x + apply ContinuousOn.intervalIntegrable + simpa only [uIcc_of_le hT] using hc1 x + · intro x + apply hgint.mul_continuousOn + rw [uIcc_of_le hT] + convert! continuousOn_const.mul ((hc0 x).pow 2) using 1 + +lemma SmoothEvolution.toGradientStrip {T : ℝ} (hT : 0≤T) {γ : ℝ → ℝ} {V : ℝ → ℝ → ℝ} + (h : SmoothEvolution T γ V) (hγ : ∀ t∈Icc (0 : ℝ) T, 0≤γ t) + (hγmono : MonotoneOn γ (Icc (0 : ℝ) T)) (h0 : deriv (V 0) 0=0) : + ∃ K L, GradientStrip T γ (fun t ↦ deriv (V t)) K L := by + obtain ⟨B1,hB1,hb1⟩ := h.bound 1 + obtain ⟨B2,hB2,hb2⟩ := h.bound 2 + obtain ⟨B3,hB3,hb3⟩ := h.bound 3 + obtain ⟨L0,hL0,hl0⟩ := h.jet_joint 0 + obtain ⟨L1,hL1,hl1⟩ := h.jet_joint 1 + obtain ⟨L2,hL2,hl2⟩ := h.jet_joint 2 + let K := B1+B2+B3 + let L := L2+L1+B1*L0 + have hK : 0≤K := by dsimp [K]; positivity + have hL : 0≤L := by dsimp [L]; positivity + have hgint : IntervalIntegrable γ volume 0 T := by + apply MonotoneOn.intervalIntegrable + simpa only [uIcc_of_le hT] using hγmono + have hc0 (x : ℝ) : ContinuousOn (fun t ↦ deriv (V t) x) (Icc (0 : ℝ) T) := by + simpa only [iteratedDeriv_zero] using h.continuous_jet 0 x + have hc1 (x : ℝ) : ContinuousOn (fun t ↦ deriv (deriv (V t)) x) (Icc (0 : ℝ) T) := by + simpa only [iteratedDeriv_one] using h.continuous_jet 1 x + have hc2 (x : ℝ) : ContinuousOn (fun t ↦ deriv (deriv (deriv (V t))) x) (Icc (0 : ℝ) T) := by + simpa only [show (2:ℕ)=1+1 from rfl,iteratedDeriv_succ,iteratedDeriv_one,iteratedDeriv_zero] + using h.continuous_jet 2 x + have hb1' : ∀ t∈Icc (0 : ℝ) T, ∀ x, |deriv (deriv (V t)) x|≤B1 := by + simpa only [iteratedDeriv_one] using hb1 + refine ⟨K,L,hK,hL,hγ,hγmono,?_,fun t ht x ↦ h.deriv_bound ht x,?_,?_,?_,?_,?_,?_,?_,h.gradient_pde,h0⟩ + · intro t ht + exact (h.slices t ht).jets.smooth.of_le (ENat.natCast_le_of_coe_top_le_withTop le_rfl 3) + · intro t ht x + have hb := hb2 t ht x + simp only [show (2:ℕ)=1+1 from rfl,iteratedDeriv_succ,iteratedDeriv_zero] at hb + dsimp [K] + linarith + · intro t ht x + have hb := hb3 t ht x + dsimp [K] + linarith + · intro t ht x + rw [abs_mul] + have hb := mul_le_mul (h.deriv_bound ht x) (hb1' t ht x) (abs_nonneg _) (by norm_num) + dsimp [K] + linarith + · intro t ht s hs x y + have hb := hl2 s hs t ht x y + simp only [show (2:ℕ)=1+1 from rfl,iteratedDeriv_succ,iteratedDeriv_zero] at hb + dsimp [L] + nlinarith [mul_nonneg (add_nonneg hL1 (mul_nonneg hB1 hL0)) + (add_nonneg (abs_nonneg (s-t)) (abs_nonneg (y-x)))] + · intro t ht s hs x y + have hf := hl0 s hs t ht x y + have hg := hl1 s hs t ht x y + simp only [iteratedDeriv_zero] at hf + simp only [iteratedDeriv_one] at hg + have hb := bounded_product_difference (h.deriv_bound hs y) (hb1' t ht x) hf hg (by norm_num) hB1 + dsimp [L] + nlinarith [mul_nonneg hL2 (add_nonneg (abs_nonneg (s-t)) (abs_nonneg (y-x)))] + · intro x + apply ContinuousOn.intervalIntegrable + simpa only [uIcc_of_le hT] using hc2 x + · intro x + apply hgint.mul_continuousOn + rw [uIcc_of_le hT] + convert! (hc0 x).mul (hc1 x) using 1 + +end SKValue + +end + +end OAI diff --git a/lean/OAI/Probability/SKValue/Evolution/FiniteStepEvolution.lean b/lean/OAI/Probability/SKValue/Evolution/FiniteStepEvolution.lean new file mode 100644 index 0000000000000000000000000000000000000000..7bcc391a1f69441c3a1093eac697a8e34fca03e5 --- /dev/null +++ b/lean/OAI/Probability/SKValue/Evolution/FiniteStepEvolution.lean @@ -0,0 +1,161 @@ +import Mathlib +import OAI.Probability.SKValue.Control.ControlValue +import OAI.Probability.SKValue.Evolution.EvolutionPatch +import OAI.Probability.SKValue.Evolution.EvolveStrips +import OAI.Probability.SKValue.Evolution.SmoothEvolution +import OAI.Probability.SKValue.Evolution.TimePatch + +namespace OAI + +section + +open MeasureTheory ProbabilityTheory Set Filter +open scoped Topology NNReal ENNReal BigOperators +namespace SKValue + +abbrev HeatProfile := List (ℝ≥0 × ℝ≥0) + +noncomputable def profileTime : HeatProfile → ℝ + | [] => 0 + | p::l => (p.1 : ℝ)+profileTime l + +noncomputable def profileCoeff : HeatProfile → ℝ → ℝ + | [] => fun _ ↦ 0 + | p::l => patchTime (p.1 : ℝ) (fun _ ↦ (p.2 : ℝ)) (profileCoeff l) + +noncomputable def profileValue (ψ : ℝ → ℝ) : HeatProfile → ℝ → ℝ → ℝ + | [] => fun _ ↦ ψ + | p::l => patchTime (p.1 : ℝ) + (fun t ↦ coleHopf (p.2 : ℝ) ((p.1 : ℝ)-t) (profileValue ψ l 0)) (profileValue ψ l) + +lemma profileTime_nonneg (l : HeatProfile) : 0≤profileTime l := by + induction l with + | nil => exact le_rfl + | cons p l ih => exact add_nonneg p.1.coe_nonneg ih + +lemma profileCoeff_nonneg (l : HeatProfile) (t : ℝ) : 0≤profileCoeff l t := by + induction l generalizing t with + | nil => exact le_rfl + | cons p l ih => + change 0≤patchTime _ _ _ t + by_cases ht : t≤(p.1 : ℝ) + · rw [patchTime_left _ _ ht] + exact p.2.coe_nonneg + · rw [patchTime_right _ _ (lt_of_not_ge ht)] + exact ih _ + +lemma profileCoeff_integrable (l : HeatProfile) : + IntervalIntegrable (profileCoeff l) volume 0 (profileTime l) := by + induction l with + | nil => exact intervalIntegrable_const + | cons p l ih => + exact patchTime_intervalIntegrable p.1.coe_nonneg (profileTime_nonneg l) intervalIntegrable_const ih + +lemma profileCoeff_measurable (l : HeatProfile) : Measurable (profileCoeff l) := by + induction l with + | nil => exact measurable_const + | cons p l ih => + unfold profileCoeff patchTime + exact Measurable.ite measurableSet_Iic measurable_const (ih.comp (measurable_id.sub measurable_const)) + +lemma SmoothTerminal.zero_evolution {ψ : ℝ → ℝ} (hψ : SmoothTerminal ψ) : + SmoothEvolution 0 (fun _ ↦ 0) (fun _ ↦ ψ) := by + refine ⟨fun _ _ ↦ hψ,fun _ ↦ continuousOn_const,fun _ _ ↦ continuousOn_const,?_,?_,?_,?_⟩ + · intro n + obtain ⟨C,hC,hb⟩ := hψ.jets.bound n + exact ⟨C,hC,fun _ _ ↦ hb⟩ + · intro n + exact ⟨0,le_rfl,by intros; simp⟩ + · intro t ht s hs x + have ht0 : t=0 := le_antisymm ht.2 ht.1 + have hs0 : s=0 := le_antisymm hs.2 hs.1 + subst t; subst s; simp + · intro t ht s hs x + have ht0 : t=0 := le_antisymm ht.2 ht.1 + have hs0 : s=0 := le_antisymm hs.2 hs.1 + subst t; subst s; simp + +lemma SmoothTerminal.profile_evolution {ψ : ℝ → ℝ} (hψ : SmoothTerminal ψ) (l : HeatProfile) : + SmoothEvolution (profileTime l) (profileCoeff l) (profileValue ψ l) := by + induction l with + | nil => exact hψ.zero_evolution + | cons p l ih => + have hv : SmoothTerminal (profileValue ψ l 0) := ih.slices 0 ⟨le_rfl,profileTime_nonneg l⟩ + have hc := hv.constant_evolution p.2.coe_nonneg (p.1 : ℝ) + apply hc.patch p.1.coe_nonneg (profileTime_nonneg l) ih intervalIntegrable_const (profileCoeff_integrable l) + funext x + simp only [sub_self,coleHopf_zero] + +lemma patchTime_end {E : Type*} {a b : ℝ} (hb : 0≤b) {f g : ℝ → E} (hfg : f a=g 0) : + patchTime a f g (a+b)=g b := by + rcases hb.eq_or_lt with rfl | hb + · simpa only [add_zero,patchTime_left f g le_rfl] using hfg + · rw [patchTime_right f g (lt_add_of_pos_right a hb)] + congr 1 + ring + +lemma profileValue_terminal (ψ : ℝ → ℝ) (l : HeatProfile) : + profileValue ψ l (profileTime l)=ψ := by + induction l with + | nil => rfl + | cons p l ih => + change patchTime _ _ _ ((p.1 : ℝ)+profileTime l)=ψ + rw [patchTime_end (profileTime_nonneg l)] + · exact ih + · funext x + simp only [sub_self,coleHopf_zero] + +lemma profileCoeff_lower {l : HeatProfile} {c : ℝ} + (hc : ∀ p∈l, c≤(p.2 : ℝ)) {t : ℝ} (ht : t∈Ioc (0 : ℝ) (profileTime l)) : + c≤profileCoeff l t := by + induction l generalizing t with + | nil => exact (not_lt_of_ge ht.2 ht.1).elim + | cons p l ih => + change c≤patchTime (p.1 : ℝ) _ _ t + by_cases hta : t≤(p.1 : ℝ) + · rw [patchTime_left _ _ hta] + exact hc p (by simp) + · rw [patchTime_right _ _ (lt_of_not_ge hta)] + apply ih (fun q hq ↦ hc q (by simp [hq])) + exact ⟨sub_pos.mpr (lt_of_not_ge hta),by have htu : t≤(p.1 : ℝ)+profileTime l := ht.2; linarith⟩ + +lemma profileCoeff_mono {l : HeatProfile} (hl : l.Pairwise (fun p q ↦ p.2≤q.2)) : + MonotoneOn (profileCoeff l) (Icc (0 : ℝ) (profileTime l)) := by + induction l with + | nil => intro s hs t ht hst; exact le_rfl + | cons p l ih => + obtain ⟨hp,hl⟩ := List.pairwise_cons.mp hl + intro s hs t ht hst + change patchTime (p.1 : ℝ) _ _ s≤patchTime (p.1 : ℝ) _ _ t + by_cases hsa : s≤(p.1 : ℝ) <;> by_cases hta : t≤(p.1 : ℝ) + · rw [patchTime_left _ _ hsa,patchTime_left _ _ hta] + · rw [patchTime_left _ _ hsa,patchTime_right _ _ (lt_of_not_ge hta)] + apply profileCoeff_lower (fun q hq ↦ by exact_mod_cast hp q hq) + exact ⟨sub_pos.mpr (lt_of_not_ge hta),by have htu : t≤(p.1 : ℝ)+profileTime l := ht.2; linarith⟩ + · exact (hsa (hst.trans hta)).elim + · rw [patchTime_right _ _ (lt_of_not_ge hsa),patchTime_right _ _ (lt_of_not_ge hta)] + apply ih hl + · exact ⟨by linarith,by have hsu : s≤(p.1 : ℝ)+profileTime l := hs.2; linarith⟩ + · exact ⟨by linarith,by have htu : t≤(p.1 : ℝ)+profileTime l := ht.2; linarith⟩ + · linarith + +theorem SmoothTerminal.profile_control_value + {Ω : Type*} [m : MeasurableSpace Ω] {μ : Measure Ω} [IsProbabilityMeasure μ] + {B : ℝ≥0 → Ω → ℝ} (hB : IsPreBrownianReal B μ) (hBm : ∀ t, StronglyMeasurable (B t)) + {ψ : ℝ → ℝ} (hψ : SmoothTerminal ψ) {l : HeatProfile} + (hl : l.Pairwise (fun p q ↦ p.2≤q.2)) (hT : 0 [] + | j,n+1 => (d,f j)::gridProfile d f (j+1) n + +lemma gridProfile_time (d : ℝ≥0) (f : ℕ → ℝ≥0) (j n : ℕ) : + profileTime (gridProfile d f j n)=(n : ℝ)*d := by + induction n generalizing j with + | zero => simp only [gridProfile,profileTime,Nat.cast_zero,zero_mul] + | succ n ih => simp only [gridProfile,profileTime,ih,Nat.cast_add,Nat.cast_one]; ring + +lemma gridProfile_mem {d : ℝ≥0} {f : ℕ → ℝ≥0} {j n : ℕ} {p : ℝ≥0 × ℝ≥0} + (hp : p∈gridProfile d f j n) : ∃ i, j ≤ i ∧ i simp only [gridProfile,List.not_mem_nil] at hp + | succ n ih => + simp only [gridProfile,List.mem_cons] at hp + rcases hp with rfl | hp + · exact ⟨j,le_rfl,by omega,rfl⟩ + · obtain ⟨i,hi,hij,rfl⟩ := ih hp + exact ⟨i,by omega,by omega,rfl⟩ + +lemma gridProfile_pairwise {d : ℝ≥0} {f : ℕ → ℝ≥0} {j n : ℕ} + (hm : ∀ i k, j ≤ i → i exact List.Pairwise.nil + | succ n ih => + rw [gridProfile,List.pairwise_cons] + constructor + · intro q hq + obtain ⟨i,hi,hij,rfl⟩ := gridProfile_mem hq + exact hm j i le_rfl (by omega) (by omega) + · exact ih (fun i k hi hik hk ↦ hm i k (by omega) hik (by omega)) + +lemma gridProfile_sample {d : ℝ≥0} {f : ℕ → ℝ≥0} {j n : ℕ} + (hn : 0 omega + | succ n ih => + by_cases htd : t ≤ (d : ℝ) + · refine ⟨j,le_rfl,by omega,?_,?_,?_⟩ + · exact patchTime_left _ _ htd + · linarith [ht.1] + · linarith + · have hd : (d : ℝ) simpa only [iteratedDeriv_zero] using hf + | succ n ih => rw [iteratedDeriv_succ]; exact (contDiff_infty_iff_deriv.mp ih).2 + +lemma derivative_tower_bounded {ι : Type*} (R : ℕ → ι → ℝ → ℝ) + (hs : ∀ j a, ContDiff ℝ ∞ (R j a)) + (hd : ∀ j a, deriv (R j a) = fun x ↦ R (j+1) a x-R j a x*R 1 a x) + (hb : ∀ j, ∃ C : ℝ, 0≤C ∧ ∀ a x, |R j a x|≤C) : + ∀ n j : ℕ, ∃ C : ℝ, 0≤C ∧ ∀ a x, |iteratedDeriv n (R j a) x|≤C := by + classical + intro n + induction n using Nat.strong_induction_on with + | h m ih => + cases m with + | zero => intro j; simpa only [iteratedDeriv_zero] using hb j + | succ n => + have hlo : ∀ k j : ℕ, ∃ C : ℝ, 0≤C ∧ + (k≤n → ∀ a x, |iteratedDeriv k (R j a) x|≤C) := by + intro k j + by_cases hk : k≤n + · obtain ⟨C,hC,hbC⟩ := ih k (Nat.lt_succ_of_le hk) j + exact ⟨C,hC,fun _ ↦ hbC⟩ + · exact ⟨0,le_rfl,fun h ↦ (hk h).elim⟩ + choose C hC hbound using hlo + intro j + refine ⟨C n (j+1)+∑ k∈Finset.range (n+1), (n.choose k : ℝ)*C k j*C (n-k) 1,?_,?_⟩ + · exact add_nonneg (hC _ _) (Finset.sum_nonneg (fun k _ ↦ + mul_nonneg (mul_nonneg (Nat.cast_nonneg _) (hC _ _)) (hC _ _))) + · intro a x + rw [iteratedDeriv_succ',hd, + iteratedDeriv_fun_sub + ((hs (j+1) a).of_le (ENat.natCast_le_of_coe_top_le_withTop le_rfl n)).contDiffAt + (((hs j a).mul (hs 1 a)).of_le (ENat.natCast_le_of_coe_top_le_withTop le_rfl n)).contDiffAt, + iteratedDeriv_fun_mul + ((hs j a).of_le (ENat.natCast_le_of_coe_top_le_withTop le_rfl n)).contDiffAt + ((hs 1 a).of_le (ENat.natCast_le_of_coe_top_le_withTop le_rfl n)).contDiffAt] + apply (abs_sub _ _).trans + apply add_le_add (hbound n (j+1) le_rfl a x) + apply (Finset.abs_sum_le_sum_abs _ _).trans + apply Finset.sum_le_sum + intro k hk + have hk' : k≤n := Nat.le_of_lt_succ (Finset.mem_range.mp hk) + rw [abs_mul,abs_mul,abs_of_nonneg (Nat.cast_nonneg (n.choose k))] + exact mul_le_mul + (mul_le_mul_of_nonneg_left (hbound k j hk' a x) (Nat.cast_nonneg _)) + (hbound (n-k) 1 (Nat.sub_le ..) a x) (abs_nonneg _) + (mul_nonneg (Nat.cast_nonneg _) (hC _ _)) + +noncomputable def normalizedJet {ι : Type*} (F : ι → ℝ → ℝ) (j : ℕ) (a : ι) (x : ℝ) : ℝ := + iteratedDeriv j (F a) x/F a x + +lemma normalizedJet_smooth {ι : Type*} {F : ι → ℝ → ℝ} + (hs : ∀ a, ContDiff ℝ ∞ (F a)) (hp : ∀ a x, F a x≠0) (j : ℕ) (a : ι) : + ContDiff ℝ ∞ (normalizedJet F j a) := + (smooth_iteratedDeriv (hs a) j).div (hs a) (hp a) + +lemma normalizedJet_deriv {ι : Type*} {F : ι → ℝ → ℝ} + (hs : ∀ a, ContDiff ℝ ∞ (F a)) (hp : ∀ a x, F a x≠0) (j : ℕ) (a : ι) : + deriv (normalizedJet F j a) = + fun x ↦ normalizedJet F (j+1) a x-normalizedJet F j a x*normalizedJet F 1 a x := by + funext x + have hd := (((hs a).differentiable_iteratedDeriv j + (ENat.natCast_lt_of_coe_top_le_withTop le_rfl j)) x).hasDerivAt + have hF := (((hs a).differentiable (ne_of_gt (ENat.natCast_lt_of_coe_top_le_withTop le_rfl 0))) x).hasDerivAt + change deriv (fun y ↦ iteratedDeriv j (F a) y/F a y) x = _ + convert! (hd.div hF (hp a x)).deriv using 1 + dsimp only [normalizedJet] + rw [iteratedDeriv_succ,iteratedDeriv_one] + field_simp [hp a x] + +lemma normalizedJet_uniform_bounded {ι : Type*} {F : ι → ℝ → ℝ} + (hs : ∀ a, ContDiff ℝ ∞ (F a)) (hp : ∀ a x, F a x≠0) + (hb : ∀ j, ∃ C : ℝ, 0≤C ∧ ∀ a x, |normalizedJet F j a x|≤C) : + ∀ n j : ℕ, ∃ C : ℝ, 0≤C ∧ ∀ a x, |iteratedDeriv n (normalizedJet F j a) x|≤C := + derivative_tower_bounded (normalizedJet F) (normalizedJet_smooth hs hp) + (normalizedJet_deriv hs hp) hb + +lemma normalizedJet_boundedSmooth {ι : Type*} {F : ι → ℝ → ℝ} + (hs : ∀ a, ContDiff ℝ ∞ (F a)) (hp : ∀ a x, F a x≠0) + (hb : ∀ j, ∃ C : ℝ, 0≤C ∧ ∀ a x, |normalizedJet F j a x|≤C) (j : ℕ) (a : ι) : + BoundedSmooth (normalizedJet F j a) := by + refine ⟨normalizedJet_smooth hs hp j a,?_⟩ + intro n + obtain ⟨C,hC,hbC⟩ := normalizedJet_uniform_bounded hs hp hb n j + exact ⟨C,hC,hbC a⟩ + +lemma heat_relative_bound {f g : ℝ → ℝ} (hf : Measurable f) (hg : Measurable g) + (hfg : ExpGrowth f) (hgg : ExpGrowth g) {C : ℝ} + (hb : ∀ x, |g x|≤C*f x) (h x : ℝ) : + |heat h g x|≤C*heat h f x := by + apply abs_integral_le_integral_abs.trans + rw [heat,←integral_const_mul] + apply integral_mono (hgg.shift_integrable hg x (Real.sqrt h)).abs + ((hfg.shift_integrable hf x (Real.sqrt h)).const_mul C) + exact fun z ↦ hb _ + +lemma exp_heat_normalizedJet_bound {ψ : ℝ → ℝ} (hψl : LipschitzWith 1 ψ) + (hψs : ContDiff ℝ ∞ ψ) (hψ : BoundedSmooth (deriv ψ)) {c : ℝ} (hc : 0≤c) : + ∀ j, ∃ C : ℝ, 0≤C ∧ ∀ h x, + |normalizedJet (fun t ↦ heat t (fun y ↦ Real.exp (c*ψ y))) j h x|≤C := by + have hes : ContDiff ℝ ∞ (fun x ↦ Real.exp (c*ψ x)) := (contDiff_const.mul hψs).exp + have heg := exp_iteratedDeriv_growth hψl hψs hψ hc + intro j + obtain ⟨C,hC,hJ⟩ := (expJet_boundedSmooth hψ c j).bound_zero + refine ⟨C,hC,?_⟩ + intro h x + dsimp only [normalizedJet] + rw [heat_iteratedDeriv hes heg,abs_div] + have hp : 0 < heat h (fun y ↦ Real.exp (c*ψ y)) x := + lipschitz_exp_integral_pos hψl hc x (Real.sqrt h) + rw [abs_of_pos hp] + apply (div_le_iff₀ (lipschitz_exp_integral_pos hψl hc x (Real.sqrt h))).mpr + exact heat_relative_bound hes.continuous.measurable + (smooth_iteratedDeriv hes j).continuous.measurable + (ExpGrowth.exp_lipschitz hψl hc) (heg j) + (fun y ↦ by + rw [exp_iteratedDeriv hψs hψ c j,abs_mul,abs_of_pos (Real.exp_pos _)] + simpa only [mul_comm] using mul_le_mul_of_nonneg_left (hJ y) (Real.exp_pos (c*ψ y)).le) h x + +lemma coleHopf_deriv_eq_normalizedJet {ψ : ℝ → ℝ} (hψl : LipschitzWith 1 ψ) + (hψs : ContDiff ℝ ∞ ψ) (hψ : BoundedSmooth (deriv ψ)) {c : ℝ} (hc : 0 simpa only [iteratedDeriv_zero] using ExpGrowth.lipschitz hψ.lipschitz + | succ n => + obtain ⟨C,hC,hb⟩ := hψ.jets.bound n + rw [iteratedDeriv_succ'] + exact ExpGrowth.of_bound hC hb + +lemma SmoothTerminal.heat_smooth {ψ : ℝ → ℝ} (hψ : SmoothTerminal ψ) (h : ℝ) : + ContDiff ℝ ∞ (heat h ψ) := heat_contDiff hψ.smooth hψ.growth h + +lemma SmoothTerminal.heat_deriv {ψ : ℝ → ℝ} (hψ : SmoothTerminal ψ) (h : ℝ) : + deriv (heat h ψ)=heat h (deriv ψ) := by + simpa only [iteratedDeriv_one] using heat_iteratedDeriv hψ.smooth hψ.growth h 1 + +lemma SmoothTerminal.heat_deriv_jets {ψ : ℝ → ℝ} (hψ : SmoothTerminal ψ) (n : ℕ) (h : ℝ) : + iteratedDeriv n (deriv (heat h ψ))=heat h (iteratedDeriv n (deriv ψ)) := by + simpa only [iteratedDeriv_succ'] using heat_iteratedDeriv hψ.smooth hψ.growth h (n+1) + +lemma SmoothTerminal.coleHopf_smooth {ψ : ℝ → ℝ} (hψ : SmoothTerminal ψ) {c : ℝ} (hc : 0≤c) (h : ℝ) : + ContDiff ℝ ∞ (coleHopf c h ψ) := by + rcases hc.eq_or_lt with rfl | hc + · rw [coleHopf_zero_coeff] + exact hψ.heat_smooth h + · exact coleHopf_contDiff_of_pos hψ.lipschitz hψ.smooth hψ.jets hc h + +lemma SmoothTerminal.coleHopf_deriv_bound {ψ : ℝ → ℝ} (hψ : SmoothTerminal ψ) {c : ℝ} (hc : 0≤c) (h x : ℝ) : + |deriv (coleHopf c h ψ) x|≤1 := by + rcases hc.eq_or_lt with rfl | hc + · rw [coleHopf_zero_coeff] + rw [hψ.heat_deriv] + apply heat_bound zero_le_one + intro y + simpa only [Real.norm_eq_abs,NNReal.coe_one] using norm_deriv_le_of_lipschitz hψ.lipschitz (x₀ := y) + · exact coleHopf_deriv_bound_of_pos hψ.lipschitz + (hψ.smooth.of_le (ENat.natCast_le_of_coe_top_le_withTop le_rfl 1)) hc h x + +lemma SmoothTerminal.evolve {ψ : ℝ → ℝ} (hψ : SmoothTerminal ψ) {c : ℝ} (hc : 0≤c) (h : ℝ) : + SmoothTerminal (coleHopf c h ψ) := by + have hs := hψ.coleHopf_smooth hc h + refine ⟨?_,hs,?_⟩ + · apply lipschitzWith_of_nnnorm_deriv_le (hs.differentiable (ne_of_gt (ENat.natCast_lt_of_coe_top_le_withTop le_rfl 0))) + intro x + exact_mod_cast hψ.coleHopf_deriv_bound hc h x + · rcases hc.eq_or_lt with rfl | hc + · refine ⟨(contDiff_infty_iff_deriv.mp hs).2,?_⟩ + intro n + obtain ⟨C,hC,hb⟩ := hψ.jets.bound n + refine ⟨C,hC,?_⟩ + intro x + rw [coleHopf_zero_coeff] + rw [hψ.heat_deriv_jets] + exact heat_bound hC hb h x + · exact coleHopf_deriv_boundedSmooth_of_pos hψ.lipschitz hψ.smooth hψ.jets hc h + +lemma SmoothTerminal.coleHopf_uniform_jets {ψ : ℝ → ℝ} (hψ : SmoothTerminal ψ) {c : ℝ} (hc : 0≤c) : + ∀ n, ∃ C : ℝ, 0≤C ∧ ∀ h x, |iteratedDeriv n (deriv (coleHopf c h ψ)) x|≤C := by + rcases hc.eq_or_lt with rfl | hc + · intro n + obtain ⟨C,hC,hb⟩ := hψ.jets.bound n + refine ⟨C,hC,?_⟩ + intro h x + rw [coleHopf_zero_coeff] + rw [hψ.heat_deriv_jets] + exact heat_bound hC hb h x + · exact coleHopf_deriv_uniform_bounds_of_pos hψ.lipschitz hψ.smooth hψ.jets hc + +end SKValue + +end + +end OAI diff --git a/lean/OAI/Probability/SKValue/Evolution/HeatConvexity.lean b/lean/OAI/Probability/SKValue/Evolution/HeatConvexity.lean new file mode 100644 index 0000000000000000000000000000000000000000..66ada68f436df2786c5bbb0e4306e3975f0245e2 --- /dev/null +++ b/lean/OAI/Probability/SKValue/Evolution/HeatConvexity.lean @@ -0,0 +1,115 @@ +import Mathlib +import OAI.Probability.SKValue.Evolution.HeatContinuity + +namespace OAI + +section + +open MeasureTheory ProbabilityTheory Set Filter +open scoped Topology NNReal ENNReal BigOperators ContDiff +namespace SKValue + +lemma weighted_variance_nonneg {Ω : Type*} [MeasurableSpace Ω] {μ : Measure Ω} + {w f : Ω → ℝ} (hw : ∀ x,0≤w x) (hZ : 0<∫ x,w x ∂μ) + (hi : Integrable w μ) (hif : Integrable (fun x ↦ w x*f x) μ) + (his : Integrable (fun x ↦ w x*(f x)^2) μ) : + 0≤(∫ x,w x ∂μ)*(∫ x,w x*(f x)^2 ∂μ)-(∫ x,w x*f x ∂μ)^2 := by + let Z := ∫ x,w x ∂μ + let A := ∫ x,w x*f x ∂μ + let J := ∫ x,w x*(f x)^2 ∂μ + let m := A/Z + have hm : m*Z=A := div_mul_cancel₀ A hZ.ne' + have hs : 0≤∫ x,w x*(f x-m)^2 ∂μ := integral_nonneg (fun x ↦ mul_nonneg (hw x) (sq_nonneg _)) + have he : (∫ x,w x*(f x-m)^2 ∂μ)=J-2*m*A+m^2*Z := by + have hp : (fun x ↦ w x*(f x-m)^2)= + fun x ↦ w x*(f x)^2-(2*m)*(w x*f x)+m^2*w x := by funext x; ring + rw [hp] + have hi1 : Integrable (fun x ↦ w x * f x ^ 2 - (2*m)*(w x*f x)) μ := + his.sub (hif.const_mul (2*m)) + rw [integral_add hi1 (hi.const_mul (m^2))] + rw [integral_sub his (hif.const_mul (2*m))] + simp only [integral_const_mul] + rfl + rw [he] at hs + have hz := mul_nonneg hZ.le hs + change 0≤Z*J-A^2 + have heq : Z*(J-2*m*A+m^2*Z)=Z*J-A^2 := by rw [←hm]; ring + rwa [heq] at hz + +lemma SmoothTerminal.coleHopf_curvature_pos {ψ : ℝ → ℝ} (hψ : SmoothTerminal ψ) + (hpos : ∀ x,0 f + | n+1 => fun x ↦ deriv (weightedJet c ψ f n) x+weightedJet c ψ f n x*(c*deriv ψ x) +lemma weightedJet_bounded {ψ f : ℝ → ℝ} (hψ : BoundedSmooth (deriv ψ)) + (hf : BoundedSmooth f) (c : ℝ) (n : ℕ) : BoundedSmooth (weightedJet c ψ f n) := by + induction n with + | zero => exact hf + | succ n ih => exact ih.deriv.add (ih.mul (hψ.const_mul c)) +lemma weighted_iteratedDeriv {ψ f : ℝ → ℝ} (hψ : SmoothTerminal ψ) + (hf : BoundedSmooth f) (c : ℝ) (n : ℕ) : + iteratedDeriv n (fun x ↦ Real.exp (c*ψ x)*f x)= + fun x ↦ Real.exp (c*ψ x)*weightedJet c ψ f n x := by + induction n with + | zero => rfl + | succ n ih => + rw [iteratedDeriv_succ,ih] + funext x + have hd := hψ.smooth.differentiable (ENat.natCast_lt_of_coe_top_le_withTop le_rfl 0).ne' + have hj := (weightedJet_bounded hψ.jets hf c n).smooth.differentiable + (ENat.natCast_lt_of_coe_top_le_withTop le_rfl 0).ne' + convert! ((((hd x).hasDerivAt.const_mul c).exp).mul (hj x).hasDerivAt).deriv using 1 + dsimp [weightedJet] + ring +lemma weighted_growth {ψ f : ℝ → ℝ} (hψ : SmoothTerminal ψ) + (hf : BoundedSmooth f) {c : ℝ} (hc : 0≤c) (n : ℕ) : + ExpGrowth (iteratedDeriv n (fun x ↦ Real.exp (c*ψ x)*f x)) := by + rw [weighted_iteratedDeriv hψ hf c n] + obtain ⟨C,hC,hb⟩ := (weightedJet_bounded hψ.jets hf c n).bound_zero + exact (ExpGrowth.exp_lipschitz hψ.lipschitz hc).mul_bounded hC hb + +noncomputable def responseJet (c : ℝ) (ψ f : ℝ → ℝ) (n : ℕ) (t x : ℝ) : ℝ := + iteratedDeriv n (heat t (fun y ↦ Real.exp (c*ψ y)*f y)) x / + heat t (fun y ↦ Real.exp (c*ψ y)) x +noncomputable def baseJet (c : ℝ) (ψ : ℝ → ℝ) (n : ℕ) (t x : ℝ) : ℝ := + normalizedJet (fun t ↦ heat t (fun y ↦ Real.exp (c*ψ y))) n t x +lemma responseJet_continuous {ψ f : ℝ → ℝ} (hψ : SmoothTerminal ψ) + (hf : BoundedSmooth f) {c : ℝ} (hc : 0≤c) (n : ℕ) : + Continuous (fun p : ℝ×ℝ ↦ responseJet c ψ f n p.1 p.2) := by + exact (heat_jet_continuous ((contDiff_const.mul hψ.smooth).exp.mul hf.smooth) + (weighted_growth hψ hf hc) n).div + (heat_continuous (Real.continuous_exp.comp (continuous_const.mul hψ.smooth.continuous)) + (ExpGrowth.exp_lipschitz hψ.lipschitz hc)) + (fun p ↦ (lipschitz_exp_integral_pos hψ.lipschitz hc p.2 (Real.sqrt p.1)).ne') +lemma responseJet_smooth {ψ f : ℝ → ℝ} (hψ : SmoothTerminal ψ) + (hf : BoundedSmooth f) {c : ℝ} (hc : 0≤c) (n : ℕ) (t : ℝ) : + ContDiff ℝ ∞ (responseJet c ψ f n t) := by + exact (smooth_iteratedDeriv + (heat_contDiff ((contDiff_const.mul hψ.smooth).exp.mul hf.smooth) (weighted_growth hψ hf hc) t) n).div + (heat_contDiff ((contDiff_const.mul hψ.smooth).exp) + (exp_iteratedDeriv_growth hψ.lipschitz hψ.smooth hψ.jets hc) t) + (fun x ↦ (lipschitz_exp_integral_pos hψ.lipschitz hc x (Real.sqrt t)).ne') +lemma responseJet_space {ψ f : ℝ → ℝ} (hψ : SmoothTerminal ψ) + (hf : BoundedSmooth f) {c : ℝ} (hc : 0≤c) (n : ℕ) (t x : ℝ) : + HasDerivAt (responseJet c ψ f n t) + (responseJet c ψ f (n+1) t x-responseJet c ψ f n t x*baseJet c ψ 1 t x) x := by + have hnum := heat_contDiff ((contDiff_const.mul hψ.smooth).exp.mul hf.smooth) (weighted_growth hψ hf hc) t + have hden := heat_contDiff ((contDiff_const.mul hψ.smooth).exp) + (exp_iteratedDeriv_growth hψ.lipschitz hψ.smooth hψ.jets hc) t + have hp := (lipschitz_exp_integral_pos hψ.lipschitz hc x (Real.sqrt t)).ne' + have hd := (((hnum.differentiable_iteratedDeriv n + (ENat.natCast_lt_of_coe_top_le_withTop le_rfl n)) x).hasDerivAt).div + ((hden.differentiable (ENat.natCast_lt_of_coe_top_le_withTop le_rfl 0).ne') x).hasDerivAt hp + convert! hd using 1 + dsimp only [responseJet,baseJet,normalizedJet] + simp only [iteratedDeriv_succ,iteratedDeriv_zero] + field_simp +lemma responseJet_time {ψ f : ℝ → ℝ} (hψ : SmoothTerminal ψ) + (hf : BoundedSmooth f) {c t : ℝ} (hc : 0≤c) (ht : 0 exact hf + | succ n ih => simpa only [iteratedDeriv_succ] using ih.deriv + +lemma BoundedSmooth.heat_deriv {f : ℝ → ℝ} (hf : BoundedSmooth f) (h : ℝ) : + _root_.deriv (heat h f)=heat h (_root_.deriv f) := by + simpa only [iteratedDeriv_one] using heat_iteratedDeriv hf.smooth + (fun n ↦ (hf.iteratedDeriv n).expGrowth) h 1 + +lemma standardGaussian_abs_integral_le_one : (∫ z : ℝ, |z| ∂standardGaussian)≤1 := by + have hl : HasLaw (id : ℝ → ℝ) (gaussianReal 0 1) standardGaussian := HasLaw.id + have hh := integral_abs_le_sqrt_integral_sq (gaussian_memLp hl 2 (by norm_num)) + rw [gaussian_second_moment hl,Real.sqrt_one] at hh + exact hh + +lemma BoundedSmooth.heat_kernel_deriv_bound {f : ℝ → ℝ} (hf : BoundedSmooth f) + {A h : ℝ} (hA : 0≤A) (hb : ∀ x, |f x|≤A) (hh : 0 simp only [iteratedDeriv_zero] + | succ n ih => + rw [iteratedDeriv_succ,ih] + funext x + exact (heat_spatial_hasDerivAt + (fun y ↦ by simpa only [iteratedDeriv_succ] using + ((hf.differentiable_iteratedDeriv n (ENat.natCast_lt_of_coe_top_le_withTop le_rfl n)) y).hasDerivAt) + (hf.continuous_iteratedDeriv (n+1) (ENat.natCast_le_of_coe_top_le_withTop le_rfl (n+1))) (hg n) (hg (n+1)) x h).deriv + +lemma heat_contDiff {f : ℝ → ℝ} (hf : ContDiff ℝ (↑(⊤ : ℕ∞) : ℕ∞ω) f) + (hg : ∀ n : ℕ, ExpGrowth (iteratedDeriv n f)) (h : ℝ) : + ContDiff ℝ (↑(⊤ : ℕ∞) : ℕ∞ω) (heat h f) := by + apply contDiff_of_differentiable_iteratedDeriv (n := ⊤) + intro n _ + rw [heat_iteratedDeriv hf hg] + intro x + exact (heat_spatial_hasDerivAt + (fun y ↦ by simpa only [iteratedDeriv_succ] using + ((hf.differentiable_iteratedDeriv n (ENat.natCast_lt_of_coe_top_le_withTop le_rfl n)) y).hasDerivAt) + (hf.continuous_iteratedDeriv (n+1) (ENat.natCast_le_of_coe_top_le_withTop le_rfl (n+1))) (hg n) (hg (n+1)) x h).differentiableAt + +end SKValue + +end + +end OAI diff --git a/lean/OAI/Probability/SKValue/Evolution/HeatTimeBound.lean b/lean/OAI/Probability/SKValue/Evolution/HeatTimeBound.lean new file mode 100644 index 0000000000000000000000000000000000000000..e20d2782789eb113407e192c3d17980378947883 --- /dev/null +++ b/lean/OAI/Probability/SKValue/Evolution/HeatTimeBound.lean @@ -0,0 +1,160 @@ +import Mathlib +import OAI.Probability.SKValue.Equations.ShortStripClose + +namespace OAI + +section + +open MeasureTheory ProbabilityTheory Set Filter +open scoped Topology NNReal ENNReal BigOperators ContDiff +namespace SKValue + +lemma BoundedSmooth.heat_time_bound {f : ℝ → ℝ} (hf : BoundedSmooth f) {C : ℝ} + (hC : 0 ≤ C) (hb : ∀ x, |_root_.deriv (_root_.deriv f) x| ≤ C) {h : ℝ} (hh : 0 ≤ h) (x : ℝ) : + |heat h f x-f x| ≤ (C/2)*h := by + have hd (r : ℝ) (hr : r∈Ioi (0 : ℝ)) : + HasDerivAt (fun r ↦ heat r f x) ((1/2 : ℝ)*heat r (_root_.deriv (_root_.deriv f)) x) r := + heat_time_hasDerivAt + (fun y ↦ (hf.smooth.differentiable (ENat.natCast_lt_of_coe_top_le_withTop le_rfl 0).ne' y).hasDerivAt) + (fun y ↦ (hf.deriv.smooth.differentiable (ENat.natCast_lt_of_coe_top_le_withTop le_rfl 0).ne' y).hasDerivAt) + hf.deriv.deriv.smooth.continuous hf.expGrowth hf.deriv.expGrowth hf.deriv.deriv.expGrowth x hr + have hl : LipschitzOnWith ⟨C/2,by positivity⟩ (fun r ↦ heat r f x) (Ioi (0 : ℝ)) := by + apply (convex_Ioi (0 : ℝ)).lipschitzOnWith_of_nnnorm_hasDerivWithin_le + (fun r hr ↦ (hd r hr).hasDerivWithinAt) + intro r hr + have hh := heat_bound hC hb r x + have habs : |(1/2 : ℝ)*heat r (_root_.deriv (_root_.deriv f)) x| ≤ C/2 := by + rw [abs_mul,abs_of_nonneg (by norm_num : (0 : ℝ) ≤ 1/2)] + linarith + exact_mod_cast habs + have hc : Continuous (fun r ↦ heat r f x) := + (heat_continuous hf.smooth.continuous hf.expGrowth).comp (continuous_id.prodMk continuous_const) + have hl' := LipschitzOnWith.closure hc.continuousOn hl + rw [closure_Ioi] at hl' + have hb' := hl'.dist_le_mul h (show h∈Ici (0 : ℝ) from hh) 0 (show (0 : ℝ)∈Ici 0 from (by simp)) + change dist (heat h f x) (heat 0 f x) ≤ (C/2)*dist h 0 at hb' + simpa only [Real.dist_eq,heat_zero,sub_zero,abs_of_nonneg hh] using hb' + +end SKValue + +end + +section + +open MeasureTheory ProbabilityTheory Set Filter +open scoped Topology NNReal ENNReal BigOperators ContDiff +namespace SKValue + +lemma SmoothEvolution.burgers_all_jets {T a b : ℝ} {γ : ℝ → ℝ} {V : ℝ → ℝ → ℝ} + (h : SmoothEvolution T γ V) (hm : Measurable γ) (hγ : MonotoneOn γ (Icc (0 : ℝ) T)) + (hi : IntervalIntegrable γ volume 0 T) (ha : 0 ≤ a) (hab : a ≤ b) (hb : b ≤ T) (n : ℕ) (x : ℝ) : + iteratedDeriv n (deriv (V a)) x=heat (b-a) (iteratedDeriv n (deriv (V b))) x+ + ∫ s in a..b, γ s*heat (s-a) (iteratedDeriv n + (fun y ↦ deriv (V s) y*deriv (deriv (V s)) y)) x := by + cases n with + | zero => simpa only [iteratedDeriv_zero] using h.burgers_mild hm hγ hi ha hab hb x + | succ m => + rw [congrFun (h.burgers_jet_mild hm hγ hi ha hab hb m) x] + have hbT : b∈Icc (0 : ℝ) T := ⟨ha.trans hab,hb⟩ + rw [((h.slices b hbT).jets.iteratedDeriv m).heat_deriv,iteratedDeriv_succ] + congr 1 + apply intervalIntegral.integral_congr + intro s hs + rw [uIcc_of_le hab] at hs + have hsT : s∈Icc (0 : ℝ) T := ⟨ha.trans hs.1,hs.2.trans hb⟩ + have hg := ((h.slices s hsT).jets.mul (h.slices s hsT).jets.deriv).iteratedDeriv m + dsimp only + rw [hg.heat_deriv,iteratedDeriv_succ] + +lemma SmoothEvolution.temporal_jet_bound {T S Γ A : ℝ} {γ : ℝ → ℝ} {V : ℝ → ℝ → ℝ} + (h : SmoothEvolution T γ V) (hm : Measurable γ) (hγ : MonotoneOn γ (Icc (0 : ℝ) T)) + (hi : IntervalIntegrable γ volume 0 T) (hST : S ≤ T) (n : ℕ) (hΓ : 0 ≤ Γ) (hA : 0 ≤ A) + (hγbd : ∀ t∈Icc (0 : ℝ) S, |γ t| ≤ Γ) + (hjets : ∀ t∈Icc (0 : ℝ) S, ∀ k ≤ n+2, ∀ x, |iteratedDeriv k (deriv (V t)) x| ≤ A) + {a b : ℝ} (ha : a∈Icc (0 : ℝ) S) (hb : b∈Icc (0 : ℝ) S) (hab : a ≤ b) (x : ℝ) : + |iteratedDeriv n (deriv (V a)) x-iteratedDeriv n (deriv (V b)) x| ≤ + (A/2+Γ*(A+lowerJetConstant n A))*(b-a) := by + let G := fun s y ↦ deriv (V s) y*deriv (deriv (V s)) y + let K := A+lowerJetConstant n A + have hK : 0 ≤ K := add_nonneg hA (lowerJetConstant_nonneg n hA) + have hG (s : ℝ) (hs : s∈Icc a b) (y : ℝ) : |iteratedDeriv n (G s) y| ≤ K := by + have hsS : s∈Icc (0 : ℝ) S := ⟨ha.1.trans hs.1,hs.2.trans hb.2⟩ + apply ((h.slices s ⟨hsS.1,hsS.2.trans hST⟩).product_jet_bound n hA + (fun k hk z ↦ hjets s hsS k (by omega) z) y).trans + exact add_le_add (hjets s hsS (n+1) (by omega) y) le_rfl + have hint : |∫ s in a..b, γ s*heat (s-a) (iteratedDeriv n (G s)) x| ≤ Γ*K*(b-a) := by + have hbnd := intervalIntegral.norm_integral_le_of_norm_le_const (a := a) (b := b) + (C := Γ*K) (f := fun s ↦ γ s*heat (s-a) (iteratedDeriv n (G s)) x) (by + intro s hs + rw [uIoc_of_le hab] at hs + have hsS : s∈Icc (0 : ℝ) S := ⟨ha.1.trans hs.1.le,hs.2.trans hb.2⟩ + rw [Real.norm_eq_abs,abs_mul] + exact mul_le_mul (hγbd s hsS) (heat_bound hK (hG s ⟨hs.1.le,hs.2⟩) (s-a) x) + (abs_nonneg _) hΓ) + simpa only [Real.norm_eq_abs,abs_of_nonneg (sub_nonneg.mpr hab),Real.dist_eq] using hbnd + have hterm := ((h.slices b ⟨hb.1,hb.2.trans hST⟩).jets.iteratedDeriv n).heat_time_bound hA + (fun y ↦ by simpa only [iteratedDeriv_succ,iteratedDeriv_succ'] using hjets b hb (n+2) le_rfl y) + (sub_nonneg.mpr hab) x + have hid := h.burgers_all_jets hm hγ hi ha.1 hab (hb.2.trans hST) n x + rw [hid] + rw [add_sub_right_comm] + exact (abs_add_le _ _).trans ((add_le_add hterm hint).trans_eq (by ring)) + +end SKValue + +end + +section + +open MeasureTheory ProbabilityTheory Set Filter +open scoped Topology NNReal ENNReal BigOperators ContDiff +namespace SKValue + +lemma SmoothEvolution.restrict {T S : ℝ} {γ : ℝ → ℝ} {V : ℝ → ℝ → ℝ} + (h : SmoothEvolution T γ V) (hST : S ≤ T) : SmoothEvolution S γ V := by + have hs : Icc (0 : ℝ) S⊆Icc (0 : ℝ) T := Icc_subset_Icc le_rfl hST + refine ⟨fun t ht ↦ h.slices t (hs ht),fun x ↦ (h.continuous_value x).mono hs, + fun n x ↦ (h.continuous_jet n x).mono hs,?_,?_,?_,?_⟩ + · intro n + obtain ⟨C,hC,hb⟩ := h.bound n + exact ⟨C,hC,fun t ht ↦ hb t (hs ht)⟩ + · intro n + obtain ⟨L,hL,hb⟩ := h.temporal n + exact ⟨L,hL,fun s hs' t ht ↦ hb s (hs hs') t (hs ht)⟩ + · exact fun t ht s hs' ↦ h.value_pde t (hs ht) s (hs hs') + · exact fun t ht s hs' ↦ h.gradient_pde t (hs ht) s (hs hs') + +lemma SmoothEvolution.uniform_temporal_jet {T S Γ A : ℝ} {γ : ℝ → ℝ} {V : ℝ → ℝ → ℝ} + (h : SmoothEvolution T γ V) (hm : Measurable γ) (hγ : MonotoneOn γ (Icc (0 : ℝ) T)) + (hi : IntervalIntegrable γ volume 0 T) (hST : S ≤ T) (n : ℕ) (hΓ : 0 ≤ Γ) (hA : 0 ≤ A) + (hγbd : ∀ t∈Icc (0 : ℝ) S, |γ t| ≤ Γ) + (hjets : ∀ t∈Icc (0 : ℝ) S, ∀ k ≤ n+2, ∀ x, |iteratedDeriv k (deriv (V t)) x| ≤ A) + {a b : ℝ} (ha : a∈Icc (0 : ℝ) S) (hb : b∈Icc (0 : ℝ) S) (x : ℝ) : + |iteratedDeriv n (deriv (V a)) x-iteratedDeriv n (deriv (V b)) x| ≤ + (A/2+Γ*(A+lowerJetConstant n A))*|a-b| := by + rcases le_total a b with hab | hba + · rw [abs_sub_comm a b,abs_of_nonneg (sub_nonneg.mpr hab)] + exact h.temporal_jet_bound hm hγ hi hST n hΓ hA hγbd hjets ha hb hab x + · rw [abs_sub_comm (iteratedDeriv n _ x),abs_of_nonneg (sub_nonneg.mpr hba)] + exact h.temporal_jet_bound hm hγ hi hST n hΓ hA hγbd hjets hb ha hba x + +lemma uniform_bulk_temporal (Γ : ℝ) (hΓ : 0 ≤ Γ) (T : ℝ) (m : ℕ) + {S : ℝ} (hS : 0 ≤ S) (hST : S fun_prop (disch := intro p; exact (heatDen_pos ha p.1).ne') +lemma forwardJet_space {ψ : ℝ → ℝ} (hψ : SmoothTerminal ψ) {a c : ℝ} + (hc : 0≤c) (n : ℕ) (t x : ℝ) : + HasDerivAt (forwardJet a c ψ n t) (forwardJet a c ψ (n+1) t x) x := by + have hd := ((scaledHeatJet_space hψ hc n (heatTime a t) (heatScale a t*x)).comp x + ((hasDerivAt_id x).const_mul (heatScale a t))).const_mul ((heatScale a t)^(n+1)) + obtain rfl | n := n + · convert! ((hasDerivAt_id x).div_const (heatDen a t)).sub hd using 1 + simp [forwardJet] + ring + obtain rfl | n := n + · convert! (hasDerivAt_const x (1/heatDen a t)).sub hd using 1 + simp [forwardJet] + ring + · convert! hd.neg using 1 + · funext y; simp [forwardJet,pow_succ] + · simp [forwardJet,pow_succ]; ring +end SKValue + +end + +section + +open Set Filter +open scoped Topology +namespace SKValue +lemma abs_sub_upper (x y : ℝ) : |x-y|≤|x|+|y| := by + simpa only [sub_zero,zero_sub,abs_neg] using abs_sub_le x 0 y +lemma heatDen_inv_hasDerivAt {a t : ℝ} (ha : 0 simp only [abs_of_nonneg hi.1,abs_zero] <;> linarith [one_div_nonneg.mpr ha.le] + +lemma forwardJet_growth {ψ : ℝ → ℝ} (hψ : SmoothTerminal ψ) {a c : ℝ} + (ha : 0 + have hh:=h.gradient_pde a haT b hbT x + have hci:IntervalIntegrable (fun t ↦ deriv (deriv (deriv (V t))) x) volume a b := by + apply ContinuousOn.intervalIntegrable + rw [uIcc_of_le hab] + exact (hfg.deriv.deriv.at_continuous x).mono (Icc_subset_Icc ha hb) + have hpi:IntervalIntegrable (fun t ↦ γ t*(deriv (V t) x*deriv (deriv (V t)) x)) volume a b := + hiab.mul_continuousOn (by rw [uIcc_of_le hab];exact (hG.at_continuous x).mono (Icc_subset_Icc ha hb)) + rw [intervalIntegral.integral_add (hci.const_mul _) hpi,intervalIntegral.integral_const_mul] at hh + simpa only [Nat.zero_add,weightedFamilyIntegral,iteratedDeriv_zero, + show (2:ℕ)=1+1 from rfl,iteratedDeriv_succ,iteratedDeriv_one,one_mul,neg_add_rev, + neg_mul,sub_eq_add_neg,add_comm] using hh + | succ n ih => + have hleft:=(((hfg.slices b hbT).iteratedDeriv n).smooth.differentiable (by norm_num) x).hasDerivAt.sub + (((hfg.slices a haT).iteratedDeriv n).smooth.differentiable (by norm_num) x).hasDerivAt + have hright:=((hfg.iteratedDeriv (n+2)).weightedFamilyIntegral_hasDerivAt + (intervalIntegrable_const (c:=(1:ℝ))) ha hab hb x).const_mul (-(1/2:ℝ)) + have hright:=hright.sub ((hG.iteratedDeriv n).weightedFamilyIntegral_hasDerivAt hiab ha hab hb x) + have hEq:(fun y ↦ iteratedDeriv n (deriv (V b)) y-iteratedDeriv n (deriv (V a)) y)= + (fun y ↦ -(1/2:ℝ)*weightedFamilyIntegral a b (fun _ ↦ 1) + (fun t ↦ iteratedDeriv (n+2) (deriv (V t))) y- + weightedFamilyIntegral a b γ (fun t ↦ iteratedDeriv n + (fun q ↦ deriv (V t) q*deriv (deriv (V t)) q)) y) := funext ih + have he:=hleft.unique (hright.congr_of_eventuallyEq (Eventually.of_forall ih)) + simpa only [iteratedDeriv_succ,Nat.add_assoc] using he +end SKValue + +end + +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped Topology NNReal BigOperators +namespace SKValue +lemma SmoothEvolution.jet_time_hasDerivAt {T:ℝ} {γ:ℝ → ℝ} {V:ℝ → ℝ → ℝ} + (h:SmoothEvolution T γ V) (hi:IntervalIntegrable γ volume 0 T) + {t:ℝ} (ht:t∈Ioo (0:ℝ) T) (hγ:ContinuousAt γ t) (n:ℕ) (x:ℝ): + HasDerivAt (fun s ↦ iteratedDeriv n (deriv (V s)) x) + (-(1/2:ℝ)*iteratedDeriv (n+2) (deriv (V t)) x- + γ t*iteratedDeriv n (fun y ↦ deriv (V t) y*deriv (deriv (V t)) y) x) t := by + let A:=fun s ↦ iteratedDeriv (n+2) (deriv (V s)) x + let B:=fun s ↦ iteratedDeriv n (fun y ↦ deriv (V s) y*deriv (deriv (V s)) y) x + have hA:ContinuousOn A (Icc (0:ℝ) T) := h.continuous_jet (n+2) x + have hB:ContinuousOn B (Icc (0:ℝ) T) := + ((h.gradient_family.mul h.gradient_family.deriv).iteratedDeriv n).at_continuous x + have hT:0≤T:=ht.1.le.trans ht.2.le + have hiA:IntervalIntegrable A volume 0 T := by + apply ContinuousOn.intervalIntegrable;simpa only [uIcc_of_le hT] using hA + have hiB:IntervalIntegrable (fun s ↦ γ s*B s) volume 0 T := + hi.mul_continuousOn (by simpa only [uIcc_of_le hT] using hB) + have htT:t∈Icc (0:ℝ) T:=⟨ht.1.le,ht.2.le⟩ + have hn:=Icc_mem_nhds ht.1 ht.2 + have hsub:uIcc (0:ℝ) t⊆uIcc (0:ℝ) T:=by + rw [uIcc_of_le ht.1.le,uIcc_of_le hT];exact Icc_subset_Icc le_rfl ht.2.le + have hAi:IntegrableOn A (Icc (0:ℝ) T) volume := by + simpa only [uIcc_of_le hT] using (intervalIntegrable_iff').mp hiA + have hBi:IntegrableOn (fun s ↦ γ s*B s) (Icc (0:ℝ) T) volume := by + simpa only [uIcc_of_le hT] using (intervalIntegrable_iff').mp hiB + have hdA:=intervalIntegral.integral_hasDerivAt_right (hiA.mono_set hsub) + ⟨Icc (0:ℝ) T,hn,hAi.aestronglyMeasurable⟩ ((hA t htT).continuousAt hn) + have hdB:=intervalIntegral.integral_hasDerivAt_right (hiB.mono_set hsub) + ⟨Icc (0:ℝ) T,hn,hBi.aestronglyMeasurable⟩ (hγ.mul ((hB t htT).continuousAt hn)) + have hd:=((hasDerivAt_const t (iteratedDeriv n (deriv (V 0)) x)).add + (hdA.const_mul (-(1/2:ℝ)))).sub hdB + simp only [zero_add] at hd + apply hd.congr_of_eventuallyEq + filter_upwards [hn] with s hs + have he:=h.jet_pde_ordered hi (a:=0) (by norm_num) hs.1 hs.2 n x + dsimp only [weightedFamilyIntegral] at he + simp only [one_mul] at he + change iteratedDeriv n (deriv (V s)) x= + iteratedDeriv n (deriv (V 0)) x+(-(1/2:ℝ))*(∫ r in (0:ℝ)..s,A r)-∫ r in (0:ℝ)..s,γ r*B r + dsimp only [A,B] + linarith +end SKValue + +end + +section +open MeasureTheory ProbabilityTheory Set Filter +open scoped Topology NNReal BigOperators +namespace SKValue +namespace JetExpr +noncomputable def timeB (e:JetExpr):JetExpr := D (fun n ↦ mul (const (-1)) (coord (n+2))) e +noncomputable def timeP (e:JetExpr):JetExpr := D (fun n ↦ mul (const (-1)) ((mul (coord 0) (coord 1)).spatialIter n)) e +end JetExpr +lemma SmoothEvolution.polyJet_time_hasDerivAt {T:ℝ} {γ:ℝ → ℝ} {V:ℝ → ℝ → ℝ} + (h:SmoothEvolution T γ V) (hi:IntervalIntegrable γ volume 0 T) + {t:ℝ} (ht:t∈Ioo (0:ℝ) T) (hγ:ContinuousAt γ t) (e:JetExpr) (x:ℝ): + HasDerivAt (fun s ↦ polyJet V e s x) + ((1/2:ℝ)*polyJet V e.timeB t x+γ t*polyJet V e.timeP t x) t := by + induction e with + | const c => simpa only [polyJet,JetExpr.timeB,JetExpr.timeP,JetExpr.D,JetExpr.eval,mul_zero,add_zero] using hasDerivAt_const t c + | coord n => + have hd:=h.jet_time_hasDerivAt hi ht hγ n x + have he:=congrFun (h.polyJet_iterated (JetExpr.mul (.coord 0) (.coord 1)) ⟨ht.1.le,ht.2.le⟩ n) x + have hf:polyJet V (JetExpr.mul (.coord 0) (.coord 1)) t= + fun y ↦ deriv (V t) y*deriv (deriv (V t)) y := by + funext y;simp only [polyJet,JetExpr.eval,iteratedDeriv_zero,iteratedDeriv_one] + rw [hf] at he + change _=JetExpr.eval (fun i ↦ iteratedDeriv i (deriv (V t)) x) _ at he + simp only [polyJet,JetExpr.timeB,JetExpr.timeP,JetExpr.D,JetExpr.eval] + rw [←he] + convert hd using 1 + ring + | add e f he hf => + convert he.add hf using 1 <;> (try (ext s; rfl)) + simp only [polyJet,JetExpr.timeB,JetExpr.timeP,JetExpr.D,JetExpr.eval] + ring + | mul e f he hf => + convert he.mul hf using 1 <;> (try (ext s; rfl)) + simp only [polyJet,JetExpr.timeB,JetExpr.timeP,JetExpr.D,JetExpr.eval] + ring +lemma SmoothEvolution.polyJet_pde_ordered {T:ℝ} {γ:ℝ → ℝ} {V:ℝ → ℝ → ℝ} + (h:SmoothEvolution T γ V) (hi:IntervalIntegrable γ volume 0 T) + (hm:MonotoneOn γ (Icc (0:ℝ) T)) {a b:ℝ} (ha:0≤a) (hab:a≤b) (hb:b≤T) + (e:JetExpr) (x:ℝ): + polyJet V e b x-polyJet V e a x=∫ s in a..b, + ((1/2:ℝ)*polyJet V e.timeB s x+γ s*polyJet V e.timeP s x) := by + obtain ⟨L,hL,hl⟩:=(h.polyJet_joint e).joint + have hLip:LipschitzOnWith (Real.toNNReal L) (fun s ↦ polyJet V e s x) (uIcc a b) := by + apply LipschitzOnWith.of_dist_le_mul + intro s hs t ht + rw [uIcc_of_le hab] at hs ht + simpa only [Real.coe_toNNReal _ hL,Real.dist_eq,sub_self,abs_zero,add_zero] using + hl t ⟨ha.trans ht.1,ht.2.trans hb⟩ s ⟨ha.trans hs.1,hs.2.trans hb⟩ x x + rw [←hLip.absolutelyContinuousOnInterval.integral_deriv_eq_sub] + apply intervalIntegral.integral_congr_ae + filter_upwards [monotoneOn_ae_continuousAt_interior hm,(Set.countable_singleton b).ae_notMem volume] with s hs hsb hsi + rw [uIoc_of_le hab] at hsi + have hst:s