ExponentialSignMoments.lean
1module23public import SubentropyCertificates.ExponentialEntropy4import Mathlib.MeasureTheory.Integral.Pi5import Mathlib.MeasureTheory.Constructions.Pi6import Mathlib.Analysis.SpecialFunctions.ImproperIntegrals7import Mathlib.Analysis.SpecialFunctions.Log.NegMulLog8import Mathlib.Probability.Independence.Basic910/-! Radial integrals for independent unit exponential coordinates. -/11@[expose] public section12noncomputable section13open MeasureTheory ProbabilityTheory Real Set Filter14open scoped BigOperators Topology ENNReal15namespace SubentropyCertificates.ConditionalContinuity16open SubentropyCertificates.Representations1718local instance : IsProbabilityMeasure (expMeasure 1) := isProbabilityMeasure_expMeasure one_pos1920private theorem ae_nonneg_exp : ∀ᵐ x ∂expMeasure 1, 0 ≤ x := by21 rw [expMeasure, gammaMeasure]22 apply (ae_withDensity_iff (f := gammaPDF 1 1) (by23 exact ENNReal.measurable_ofReal.comp (measurable_gammaPDFReal 1 1))).mpr24 exact .of_forall fun x hx ↦ le_of_not_gt (fun h ↦ hx (gammaPDF_of_neg h))2526private theorem pi_positive {D : Type*} [Fintype D] :27 ∀ᵐ z ∂Measure.pi (fun _ : D ↦ expMeasure 1), ∀ j, 0 ≤ z j := by28 rw [ae_all_iff]29 intro j30 exact (measurePreserving_eval (fun _ : D ↦ expMeasure 1) j).quasiMeasurePreserving.ae31 ae_nonneg_exp3233private theorem exp_radial_factor (a : ℝ) (ha : 0 ≤ a) :34 (∫ z, exp (-(a*z)) ∂expMeasure 1) = (1+a)⁻¹ := by35 rw [unit_exponential_integral]36 simp_rw [← exp_add, show ∀ z : ℝ, -z + -(a*z) = (-(1+a))*z by intro z; ring]37 rw [integral_exp_mul_Ioi (by linarith : -(1+a) < 0)]38 simp only [mul_zero, exp_zero, neg_div_neg_eq, one_div]3940private theorem exp_radial_first_moment (a : ℝ) (ha : 0 ≤ a) :41 (∫ z, z * exp (-(a*z)) ∂expMeasure 1) = (1+a)⁻¹ * (1+a)⁻¹ := by42 rw [unit_exponential_integral]43 have hh := integral_rpow_mul_exp_neg_mul_Ioi (by norm_num : (0:ℝ)<2)44 (by linarith : 0 < 1+a)45 norm_num [one_div] at hh46 calc47 _ = ∫ z in Ioi (0:ℝ), z * exp (-((1+a)*z)) := by48 apply setIntegral_congr_fun measurableSet_Ioi49 intro z _50 dsimp only51 rw [mul_left_comm, ← exp_add]52 ring_nf53 _ = _ := by simpa [sq] using hh5455private theorem tilted_exp_moment {D : Type*} [Fintype D] [DecidableEq D]56 (w : D → ℝ) (hw : ∀ j, 0 ≤ w j) (i : D) (t : ℝ) (ht : 0 ≤ t) :57 (∫ z : D → ℝ, w i*z i*exp (-(t*(∑ j, w j*z j))) ∂Measure.pi (fun _ ↦ expMeasure 1)) =58 (w i / (1+t*w i)) * ∏ j, (1+t*w j)⁻¹ := by59 let f (j : D) (x : ℝ) := (if j = i then x else 1) * exp (-((t*w j)*x))60 have eq (z : D → ℝ) : w i*z i*exp (-(t*(∑ j, w j*z j))) = w i*∏ j, f j (z j) := by61 simp only [f, Finset.prod_mul_distrib, ← exp_sum, ← Finset.sum_neg_distrib, Finset.mul_sum,62 mul_assoc]63 simp64 simp_rw [eq, integral_const_mul, integral_fintype_prod_eq_prod]65 have term (j : D) : (∫ x, f j x ∂expMeasure 1) =66 (if j = i then (1+t*w i)⁻¹ else 1) * (1+t*w j)⁻¹ := by67 by_cases h : j = i68 · subst j69 simpa [f] using exp_radial_first_moment (t*w i) (mul_nonneg ht (hw i))70 · simpa [f,h] using exp_radial_factor (t*w j) (mul_nonneg ht (hw j))71 simp only [term, Finset.prod_mul_distrib]72 simp [div_eq_mul_inv, mul_assoc]7374/-- The expected fraction of the total energy contributed by coordinate i equals its75determinant integral. Zero individual weights and zero total energy are allowed. -/76theorem exponential_sign_integral {D : Type*} [Fintype D] [DecidableEq D]77 (w : D → ℝ) (hw : ∀ j, 0 ≤ w j) (i : D) :78 (∫ z : D → ℝ, w i*z i/(∑ j, w j*z j) ∂Measure.pi (fun _ ↦ expMeasure 1)) =79 ∫ t in Ioi (0:ℝ), (w i/(1+t*w i)) * ∏ j, (1+t*w j)⁻¹ := by80 let μ := Measure.pi (fun _ : D ↦ expMeasure 1)81 let ν : Measure ℝ := volume.restrict (Ioi 0)82 let T (z : D → ℝ) := ∑ j, w j*z j83 let n (z : D → ℝ) := w i*z i84 let F (z : D → ℝ) (t : ℝ) := n z * exp (-(t*T z))85 have bounds {z : D → ℝ} (hz : ∀ j, 0 ≤ z j) : 0 ≤ n z ∧ n z ≤ T z :=86 ⟨mul_nonneg (hw i) (hz i), Finset.single_le_sum (fun j _ ↦ mul_nonneg (hw j) (hz j))87 (Finset.mem_univ i)⟩88 have slice {z : D → ℝ} (hz : ∀ j, 0 ≤ z j) :89 Integrable (F z) ν ∧ (∫ t, F z t ∂ν) = n z/T z := by90 obtain ⟨hn,hle⟩ := bounds hz91 by_cases h : T z = 092 · have h0 : n z = 0 := le_antisymm (hle.trans_eq h) hn93 simp [F,h0]94 · have hp := lt_of_le_of_ne (hn.trans hle) (Ne.symm h)95 refine ⟨?_, ?_⟩96 · simpa [F, mul_comm] using (exp_neg_integrableOn_Ioi 0 hp).const_mul (n z)97 · change (∫ t in Ioi (0:ℝ), n z * exp (-(t*T z))) = _98 simp_rw [show ∀ t, -(t*T z) = (-T z)*t by intro t; ring]99 rw [integral_const_mul, integral_exp_mul_Ioi (neg_lt_zero.mpr hp)]100 simp [div_eq_mul_inv]101 have hs : Integrable (Function.uncurry F) (μ.prod ν) := by102 apply (integrable_prod_iff (by dsimp [F,n,T,Function.uncurry]; fun_prop)).mpr103 refine ⟨pi_positive.mono fun z hz ↦ (slice hz).1, ?_⟩104 apply (integrable_const (μ := μ) (1 : ℝ)).mono'105 · exact (show AEStronglyMeasurable (fun p : (D → ℝ) × ℝ ↦ ‖F p.1 p.2‖) (μ.prod ν) by106 dsimp [F,n,T]; fun_prop).integral_prod_right'107 · filter_upwards [pi_positive (D := D)] with z hz108 obtain ⟨hn,hle⟩ := bounds hz109 have hab (t : ℝ) : ‖F z t‖ = F z t := Real.norm_of_nonneg (mul_nonneg hn (exp_pos _).le)110 change ‖∫ t, ‖F z t‖ ∂ν‖ ≤ 1111 simp only [hab,(slice hz).2,Real.norm_of_nonneg (div_nonneg hn (hn.trans hle))]112 exact div_le_one_of_le₀ hle (hn.trans hle)113 calc114 _ = ∫ z, ∫ t, F z t ∂ν ∂μ := integral_congr_ae (pi_positive.mono fun z hz ↦ (slice hz).2.symm)115 _ = ∫ t, ∫ z, F z t ∂μ ∂ν := integral_integral_swap hs116 _ = _ := setIntegral_congr_fun measurableSet_Ioi fun t ht ↦ tilted_exp_moment w hw i t ht.le117118private theorem exp_coord_pos {D : Type*} [Fintype D] :119 ∀ᵐ z ∂Measure.pi (fun _ : D ↦ expMeasure 1), ∀ j, 0 < z j := by120 let _ : NullSingletonClass (expMeasure 1) := ⟨fun x ↦121 withDensity_absolutelyContinuous (volume : Measure ℝ) (gammaPDF 1 1) (measure_singleton x)⟩122 have hp : ∀ᵐ x ∂expMeasure 1, 0 < x := by123 filter_upwards [ae_nonneg_exp, (expMeasure 1).ae_ne (0:ℝ)] with x hx hn124 exact lt_of_le_of_ne hx hn.symm125 rw [ae_all_iff]126 exact fun j ↦ (measurePreserving_eval (fun _ : D ↦ expMeasure 1) j).quasiMeasurePreserving.ae hp127128private theorem exp_moments :129 (∫ x, x ∂expMeasure 1) = 1 ∧ Integrable (fun x : ℝ ↦ x^2) (expMeasure 1) ∧130 Integrable Real.log (expMeasure 1) ∧ Integrable (fun x ↦ x*log x) (expMeasure 1) := by131 refine ⟨by simpa using exp_radial_first_moment 0 le_rfl, ?_, ?_, ?_⟩132 · apply Integrable.of_integral_ne_zero133 rw [unit_exponential_integral]134 have h := integral_rpow_mul_exp_neg_mul_Ioi (by norm_num : (0:ℝ)<3) one_pos135 norm_num at h136 simp [mul_comm, h]137 · apply Integrable.of_integral_ne_zero138 rw [unit_exponential_integral]139 have h := (hasDerivAt_Gamma_of_pos one_pos).unique hasDerivAt_Gamma_one140 simp only [sub_self, rpow_zero, one_mul] at h141 simp_rw [mul_comm (exp _) (log _), h]142 linarith [one_half_lt_eulerMascheroniConstant]143 · apply Integrable.of_integral_ne_zero144 rw [unit_exponential_log_moment]145 linarith [eulerMascheroniConstant_lt_two_thirds]146147/-- The logarithm of a strictly positive weighted sum of independent exponential coordinates148is integrable, also after multiplication by any one of the coordinates. -/149theorem exponential_log_integrable {D : Type*} [Fintype D] (w : D → ℝ) (hw : ∀ j, 0 < w j) (i : D) :150 let μ := Measure.pi (fun _ : D ↦ expMeasure 1)151 let T (z : D → ℝ) := ∑ j, w j*z j152 Integrable (fun z ↦ log (T z)) μ ∧ Integrable (fun z ↦ z i*log (T z)) μ := by153 intro μ T154 have he (j : D) : Integrable (fun z : D → ℝ ↦ z j) μ :=155 integrable_comp_eval (μ := fun _ : D ↦ expMeasure 1) (f := fun x : ℝ ↦ x)156 (Integrable.of_integral_ne_zero (exp_moments.1.trans_ne one_ne_zero))157 have hs (j : D) : Integrable (fun z : D → ℝ ↦ z j^2) μ := integrable_comp_eval158 (μ := fun _ : D ↦ expMeasure 1) (f := fun x : ℝ ↦ x^2) exp_moments.2.1159 have hl : Integrable (fun z : D → ℝ ↦ log (z i)) μ := integrable_comp_eval160 (μ := fun _ : D ↦ expMeasure 1) (f := Real.log) exp_moments.2.2.1161 have hzl : Integrable (fun z : D → ℝ ↦ z i*log (z i)) μ := integrable_comp_eval162 (μ := fun _ : D ↦ expMeasure 1) (f := fun x : ℝ ↦ x*log x) exp_moments.2.2.2163 have hT : Integrable T μ := integrable_finsetSum _ (fun j _ ↦ (he j).const_mul (w j))164 have hprod (j : D) : Integrable (fun z : D → ℝ ↦ z i*z j) μ := by165 apply ((hs i).add (hs j)).mono' (by fun_prop)166 filter_upwards [pi_positive (D := D)] with z hz167 rw [Real.norm_of_nonneg (mul_nonneg (hz _) (hz _))]168 dsimp169 nlinarith [sq_nonneg (z i-z j),sq_nonneg (z i),sq_nonneg (z j)]170 have hiT : Integrable (fun z ↦ z i*T z) μ := by171 have hh : Integrable (fun z : D → ℝ ↦ ∑ j, w j*(z i*z j)) μ :=172 integrable_finsetSum _ (fun j _ ↦ (hprod j).const_mul (w j))173 apply hh.congr <| .of_forall fun z ↦ ?_174 simp only [T,Finset.mul_sum]175 exact Finset.sum_congr rfl (fun j _ ↦ mul_left_comm _ _ _)176 have bd {z : D → ℝ} (hz : ∀ j, 0 < z j) :177 |log (T z)| ≤ |log (w i)| + |log (z i)| + T z := by178 have hlow : w i*z i ≤ T z :=179 Finset.single_le_sum (fun j _ ↦ mul_nonneg (hw j).le (hz j).le) (Finset.mem_univ i)180 have hpos := (mul_pos (hw i) (hz i)).trans_le hlow181 have hb := Real.log_le_log (mul_pos (hw i) (hz i)) hlow182 rw [log_mul (hw i).ne' (hz i).ne'] at hb183 exact abs_le.mpr ⟨by linarith [neg_abs_le (log (w i)),neg_abs_le (log (z i))],184 by linarith [log_le_sub_one_of_pos hpos,abs_nonneg (log (w i)),abs_nonneg (log (z i))]⟩185 constructor186 · apply (((integrable_const (μ := μ) |log (w i)|).add hl.abs).add hT).mono'187 (by apply Measurable.aestronglyMeasurable; dsimp [T]; fun_prop)188 filter_upwards [exp_coord_pos (D := D)] with z hz189 exact bd hz190 · apply ((((he i).mul_const |log (w i)|).add hzl.abs).add hiT).mono'191 (by apply Measurable.aestronglyMeasurable; dsimp [T]; fun_prop)192 filter_upwards [exp_coord_pos (D := D)] with z hz193 have h := mul_le_mul_of_nonneg_left (bd hz) (hz i).le194 simpa only [Real.norm_eq_abs, abs_mul, Pi.add_apply, abs_of_pos (hz i), mul_add] using h195196private def centeredLog (a s x : ℝ) :=197 (x-1)*log (s+a*x) - a*x/(s+a*x)198199private theorem exponential_stein_slice {a s : ℝ} (ha : 0 < a) (hs : 0 ≤ s)200 (hi : Integrable (centeredLog a s) (expMeasure 1)) :201 (∫ x, centeredLog a s x ∂expMeasure 1) = 0 := by202 let f (x : ℝ) := -(x*exp (-x)*log (s+a*x))203 have hd (x : ℝ) (hx : x ∈ Ioi (0:ℝ)) :204 HasDerivAt f (exp (-x)*centeredLog a s x) x := by205 have hpos := add_pos_of_nonneg_of_pos hs (mul_pos ha hx)206 have ht := (hasDerivAt_const x s).add ((hasDerivAt_id x).const_mul a)207 convert (((hasDerivAt_id x).mul (hasDerivAt_id x).neg.exp).mul (ht.log hpos.ne')).neg using 1208 · rfl209 · change exp (-x)*((x-1)*log (s+a*x)-a*x/(s+a*x)) =210 -((1*exp (-x)+x*(exp (-x)*(-1)))*log (s+a*x)+x*exp (-x)*((0+a*1)/(s+a*x)))211 field_simp [hpos.ne']212 ring213 have hzero : ContinuousWithinAt f (Ici 0) 0 := by214 rcases hs.eq_or_lt with rfl | h215 · have heq : f = fun x ↦ -exp (-x)*(x * log a + x * log x) := by216 funext x217 by_cases hx : x = 0218 · simp [f,hx]219 · rw [show f x = -(x*exp (-x)*log (a*x)) by simp [f], log_mul ha.ne' hx]220 ring221 rw [heq]222 exact ((continuous_exp.comp continuous_neg).neg.mul223 ((continuous_id.mul_const _).add continuous_mul_log)).continuousWithinAt224 · apply ContinuousAt.continuousWithinAt225 dsimp [f]226 fun_prop (disch := simp [h.ne'])227 have top : Tendsto f atTop (𝓝 0) := by228 suffices h : Tendsto (fun x ↦ x*exp (-x)*log (s+a*x)) atTop (𝓝 0) by229 simpa [f] using h.neg230 have hp : Tendsto (fun x : ℝ ↦ s*(x^1*exp (-x)) + a*(x^2*exp (-x))) atTop (𝓝 0) := by231 simpa using ((tendsto_pow_mul_exp_neg_atTop_nhds_zero 1).const_mul s).add232 ((tendsto_pow_mul_exp_neg_atTop_nhds_zero 2).const_mul a)233 refine squeeze_zero' ?_ ?_ hp234 · filter_upwards [eventually_ge_atTop (max 0 a⁻¹)] with x hx235 have hx0 := (le_max_left 0 a⁻¹).trans hx236 have hx1 := (le_max_right 0 a⁻¹).trans hx237 have hx2 := mul_le_mul_of_nonneg_left hx1 ha.le238 rw [mul_inv_cancel₀ ha.ne'] at hx2239 exact mul_nonneg (mul_nonneg hx0 (exp_pos _).le) (log_nonneg (by linarith))240 · filter_upwards [eventually_gt_atTop (0:ℝ)] with x hx241 have hpos := add_pos_of_nonneg_of_pos hs (mul_pos ha hx)242 have h := mul_le_mul_of_nonneg_left (log_le_sub_one_of_pos hpos)243 (mul_nonneg hx.le (exp_pos (-x)).le)244 nlinarith only [h,mul_nonneg hx.le (exp_pos (-x)).le]245 have hint : IntegrableOn (fun x ↦ exp (-x)*centeredLog a s x) (Ioi 0) := by246 unfold expMeasure gammaMeasure at hi247 have h := (integrable_withDensity_iff248 (f := gammaPDF 1 1) (by exact ENNReal.measurable_ofReal.comp (measurable_gammaPDFReal 1 1))249 (.of_forall (fun _ ↦ ENNReal.ofReal_lt_top)) ).mp hi250 apply h.integrableOn.congr_fun _ measurableSet_Ioi251 intro x hx252 simp [gammaPDF_of_nonneg hx.le, mul_comm, (exp_pos _).le]253 rw [unit_exponential_integral, integral_Ioi_of_hasDerivAt_of_tendsto hzero hd hint top]254 simp [f]255256/-- The exponential integration-by-parts identity for the logarithmic gradient moment. -/257theorem exponential_log_moment {D : Type*} [Fintype D] [DecidableEq D]258 (w : D → ℝ) (hw : ∀ j, 0 < w j) (i : D) :259 let μ := Measure.pi (fun _ : D ↦ expMeasure 1)260 let T (z : D → ℝ) := ∑ j, w j*z j261 (∫ z, (1+log (T z))*z i ∂μ) =262 1 + (∫ z, log (T z) ∂μ) + ∫ z, w i*z i/T z ∂μ := by263 intro μ T264 let J := Finset.univ.erase i265 let S (z : D → ℝ) := ∑ j ∈ J, w j*z j266 let pair (z : D → ℝ) := (S z,z i)267 let g (p : ℝ × ℝ) := centeredLog (w i) p.1 p.2268 have hsplit (z) : S z + w i*z i = T z := Finset.sum_erase_add _ _ (Finset.mem_univ i)269 have hS : Measurable S := by dsimp [S]; fun_prop270 have hpair : Measurable pair := hS.prodMk (measurable_pi_apply i)271 have hg : Measurable g := by dsimp [g,centeredLog]; fun_prop272 have hind : IndepFun S (fun z : D → ℝ ↦ z i) μ := by273 let b (j : D) (x : ℝ) := if j = i then x else w j*x274 have hh := iIndepFun_pi (μ := fun _ : D ↦ expMeasure 1) (X := b)275 (fun j ↦ by by_cases h : j = i <;> simp [b,h] <;> fun_prop)276 have h := hh.indepFun_finsetSum_of_notMem277 (fun j ↦ by by_cases hj : j = i <;> simp [b,hj] <;> fun_prop)278 (Finset.notMem_erase i Finset.univ)279 have he : (∑ j ∈ J, fun z : D → ℝ ↦ b j (z j)) = S := by280 funext z281 simp only [Finset.sum_apply, S]282 exact Finset.sum_congr rfl (fun j hj ↦ ite_eq_right (Finset.mem_erase.mp hj).1)283 change IndepFun (∑ j ∈ J, fun z : D → ℝ ↦ b j (z j)) (fun z ↦ b i (z i)) μ at h284 rw [he] at h285 simpa [b] using h286 have hmap : μ.map pair = (μ.map S).prod (expMeasure 1) :=287 (hind.map_prod_eq_prod_map_map hS.aemeasurable (measurable_pi_apply i).aemeasurable).trans288 (congrArg (Measure.prod (μ.map S)) (measurePreserving_eval (fun _ : D ↦ expMeasure 1) i).map_eq)289 obtain ⟨hl,hxl⟩ : Integrable (fun z ↦ log (T z)) μ ∧290 Integrable (fun z ↦ z i * log (T z)) μ := exponential_log_integrable w hw i291 have hratio : Integrable (fun z ↦ w i*z i/T z) μ := by292 apply (integrable_const (μ := μ) (1:ℝ)).mono' (by293 apply Measurable.aestronglyMeasurable294 dsimp [T]295 fun_prop)296 filter_upwards [pi_positive (D := D)] with z hz297 have hn := mul_nonneg (hw i).le (hz i)298 have hle : w i*z i ≤ T z := Finset.single_le_sum (fun j _ ↦ mul_nonneg (hw j).le (hz j))299 (Finset.mem_univ i)300 rw [Real.norm_of_nonneg (div_nonneg hn (hn.trans hle))]301 exact div_le_one_of_le₀ hle (hn.trans hle)302 have he (z) : g (pair z) = (z i*log (T z) - log (T z)) - w i*z i/T z := by303 dsimp [g,pair,centeredLog]304 rw [hsplit]305 ring306 have hi : Integrable g ((μ.map S).prod (expMeasure 1)) := by307 rw [← hmap,integrable_map_measure hg.aestronglyMeasurable hpair.aemeasurable]308 simp only [Function.comp_def, he]309 exact (hxl.sub hl).sub hratio310 have hnon : ∀ᵐ s ∂μ.map S, 0 ≤ s := by311 rw [ae_map_iff hS.aemeasurable (measurableSet_Ici (a := (0:ℝ)))]312 exact pi_positive.mono fun z hz ↦ Finset.sum_nonneg fun j _ ↦ mul_nonneg (hw j).le (hz j)313 have hzero : (∫ z, g (pair z) ∂μ) = 0 := by314 rw [← integral_map hpair.aemeasurable hg.aestronglyMeasurable, hmap, integral_prod _ hi]315 apply integral_eq_zero_of_ae316 filter_upwards [hnon,hi.prod_right_ae] with s hs hint317 exact exponential_stein_slice (hw i) hs hint318 simp_rw [he] at hzero319 have hsub : Integrable (fun z ↦ z i*log (T z) - log (T z)) μ := hxl.sub hl320 rw [integral_sub hsub hratio,integral_sub hxl hl] at hzero321 have hx : Integrable (fun z : D → ℝ ↦ z i) μ :=322 integrable_comp_eval (μ := fun _ : D ↦ expMeasure 1) (f := fun x : ℝ ↦ x)323 (Integrable.of_integral_ne_zero (exp_moments.1.trans_ne one_ne_zero))324 have hmean : (∫ z, z i ∂μ) = 1 := by325 have h := integral_map (μ := μ) (measurable_pi_apply (X := fun _ : D ↦ ℝ) i).aemeasurable326 (by fun_prop : AEStronglyMeasurable id (μ.map (fun z ↦ z i)))327 rw [(measurePreserving_eval (fun _ : D ↦ expMeasure 1) i).map_eq] at h328 exact h.symm.trans exp_moments.1329 have heq (z : D → ℝ) : (1+log (T z))*z i = z i + z i*log (T z) := by ring330 simp_rw [heq]331 rw [integral_add hx hxl,hmean]332 linarith333334end SubentropyCertificates.ConditionalContinuity
Axioms used
Choose a statement to see which axioms its proof uses.