Download data/lean/OAI/Probability/PosteriorReplicas/Geometry/SphereSubspace.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 12.9 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Probability/PosteriorReplicas/Geometry/SphereSubspace.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Probability/PosteriorReplicas/Geometry/SphereSubspace.lean
-
curl -L -o SphereSubspace.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Probability/PosteriorReplicas/Geometry/SphereSubspace.lean
12.9 kB
| import OAI.Probability.PosteriorReplicas.Gaussian.RadialIntegrals | |
| import OAI.Probability.PosteriorReplicas.Geometry.BallJacobian | |
| namespace OAI | |
| open MeasureTheory ProbabilityTheory Set Matrix InnerProductSpace Metric | |
| open scoped ENNReal NNReal RealInnerProductSpace Topology | |
| noncomputable section | |
| namespace PosteriorReplicas | |
| variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace โ E] | |
| [FiniteDimensional โ E] [MeasurableSpace E] [BorelSpace E] | |
| lemma gaussian_orthogonalProjectionOnto (U : Submodule โ E) : | |
| (stdGaussian E).map U.orthogonalProjectionOnto = stdGaussian U := by | |
| apply Measure.ext_of_charFun | |
| ext t | |
| rw [charFun_apply, integral_map (by fun_prop) (by fun_prop)] | |
| have he (x : E) : โชU.orthogonalProjectionOnto x, tโซ = โชx, (t : E)โซ := by | |
| change โชU.starProjection x, (t : E)โซ = _ | |
| rw [real_inner_comm, pairing_starProjection U t.2, real_inner_comm] | |
| simp_rw [he] | |
| change charFun (stdGaussian E) (t : E) = _ | |
| rw [charFun_stdGaussian, charFun_stdGaussian] | |
| rfl | |
| lemma gaussian_subspace_map (U : Submodule โ E) : | |
| (stdGaussian U).map (Subtype.val : U โ E) = (stdGaussian E).map U.starProjection := by | |
| rw [โ gaussian_orthogonalProjectionOnto U, Measure.map_map (by fun_prop) (by fun_prop)] | |
| rfl | |
| lemma gaussian_subspace_sum (U : Submodule โ E) : | |
| ((stdGaussian U).prod (stdGaussian Uแฎ)).map (fun z => (z.1 : E) + (z.2 : E)) = | |
| stdGaussian E := by | |
| rw [โ gaussian_orthogonal_sum U, โ gaussian_subspace_map, โ gaussian_subspace_map, | |
| Measure.map_prod_map _ _ (by fun_prop) (by fun_prop), | |
| Measure.map_map (by fun_prop) (by fun_prop)] | |
| rfl | |
| omit [FiniteDimensional โ E] [MeasurableSpace E] [BorelSpace E] in | |
| lemma subspace_sum_norm_sq [FiniteDimensional โ E] [MeasurableSpace E] [BorelSpace E] | |
| (U : Submodule โ E) (x : U) (z : Uแฎ) : | |
| โ(x : E) + (z : E)โ^2 = โxโ^2 + โzโ^2 := by | |
| have ho : โช(x : E), (z : E)โซ = 0 := | |
| (real_inner_comm _ _).trans ((Submodule.mem_orthogonal' U (z : E)).mp z.2 _ x.2) | |
| simp [norm_add_sq_real, ho] | |
| omit [FiniteDimensional โ E] [MeasurableSpace E] [BorelSpace E] in | |
| lemma normalDirection_pos_smul [FiniteDimensional โ E] [MeasurableSpace E] [BorelSpace E] | |
| {r : โ} (hr : 0 < r) (x : E) : | |
| normalDirection (r โข x) = normalDirection x := by | |
| simp [normalDirection, norm_smul, Real.norm_eq_abs, abs_of_pos hr, | |
| _root_.mul_inv_rev, smul_smul, hr.ne'] | |
| lemma sphere_subspace_gaussian_integral (U : Submodule โ E) [Nontrivial E] | |
| {g : E โ โโฅ0โ} (hg : Measurable g) : | |
| โซโป x, g x โuniformDirection E = | |
| โซโป x : U, โซโป z : Uแฎ, g (normalDirection ((x : E) + (z : E))) | |
| โstdGaussian Uแฎ โstdGaussian U := by | |
| rw [โ gaussian_normalDirection, lintegral_map hg (by fun_prop), | |
| โ gaussian_subspace_sum U, lintegral_map (by fun_prop) (by fun_prop), | |
| lintegral_prod _ (by fun_prop)] | |
| lemma sphere_subspace_polar_integral (U : Submodule โ E) [Nontrivial E] [Nontrivial Uแฎ] | |
| {g : E โ โโฅ0โ} (hg : Measurable g) : | |
| โซโป y, g y โuniformDirection E = | |
| โซโป z : sphere (0 : Uแฎ) 1, โซโป r : Ioi (0 : โ), โซโป x : U, | |
| gaussianRadialDensity (Module.finrank โ U) โxโ * | |
| g (normalDirection ((x : E) + r.1 โข ((z : Uแฎ) : E))) | |
| โvolume โgaussianPolarRadius Uแฎ โ(volume : Measure Uแฎ).toSphere := by | |
| rw [sphere_subspace_gaussian_integral U hg] | |
| have hp (x : U) : (โซโป z : Uแฎ, g (normalDirection ((x : E) + (z : E))) โstdGaussian Uแฎ) = | |
| โซโป z : sphere (0 : Uแฎ) 1, โซโป r : Ioi (0 : โ), | |
| g (normalDirection ((x : E) + r.1 โข ((z : Uแฎ) : E))) | |
| โgaussianPolarRadius Uแฎ โ(volume : Measure Uแฎ).toSphere := by | |
| rw [โ gaussian_polar_reconstruction (E := Uแฎ), lintegral_map (by fun_prop) (by fun_prop), | |
| lintegral_prod _ (by fun_prop)] | |
| rfl | |
| simp_rw [hp] | |
| rw [lintegral_lintegral_swap (by fun_prop)] | |
| apply lintegral_congr | |
| intro z | |
| rw [lintegral_lintegral_swap (by fun_prop)] | |
| apply lintegral_congr | |
| intro r | |
| rw [stdGaussian_density, lintegral_withDensity_eq_lintegral_mul _ (by fun_prop) (by fun_prop)] | |
| rfl | |
| lemma radial_subspace_integral (U : Submodule โ E) [Nontrivial E] [Nontrivial Uแฎ] (s : โ) : | |
| โซโป r : Ioi (0 : โ), ENNReal.ofReal (r.1 ^ Module.finrank โ U) * | |
| gaussianRadialDensity (Module.finrank โ U) (r.1 * s) โgaussianPolarRadius Uแฎ = | |
| ENNReal.ofReal ((1 + s^2) ^ (-((Module.finrank โ E : โ) : โ) / 2)) * | |
| ((volume : Measure E).toSphere univ)โปยน := by | |
| rw [lintegral_gaussianPolarRadius (E := Uแฎ) (g := fun r : โ => | |
| ENNReal.ofReal (r ^ Module.finrank โ U) * | |
| gaussianRadialDensity (Module.finrank โ U) (r * s)) (by fun_prop)] | |
| calc | |
| _ = โซโป r in Ioi (0 : โ), ENNReal.ofReal (r ^ (Module.finrank โ E - 1)) * | |
| ENNReal.ofReal ((2 * Real.pi) ^ (-((Module.finrank โ E : โ) : โ) / 2) * | |
| Real.exp (-(1 + s^2) * r^2 / 2)) := by | |
| apply setLIntegral_congr_fun measurableSet_Ioi | |
| intro r hr | |
| exact radial_power_gaussian_product Module.finrank_pos U.finrank_add_finrank_orthogonal hr.le s | |
| _ = _ := radial_gaussian_integral (by positivity) | |
| lemma scaled_subspace_integral (U : Submodule โ E) (z : sphere (0 : Uแฎ) 1) | |
| (r : Ioi (0 : โ)) {g : E โ โโฅ0โ} (hg : Measurable g) : | |
| โซโป x : U, gaussianRadialDensity (Module.finrank โ U) โxโ * | |
| g (normalDirection ((x : E) + r.1 โข ((z : Uแฎ) : E))) = | |
| โซโป x : U, ENNReal.ofReal (r.1 ^ Module.finrank โ U) * | |
| gaussianRadialDensity (Module.finrank โ U) (r.1 * โxโ) * | |
| g (normalDirection ((x : E) + ((z : Uแฎ) : E))) := by | |
| rw [lintegral_pos_smul r.2 (by fun_prop), โ lintegral_const_mul _ (by fun_prop)] | |
| apply lintegral_congr | |
| intro x | |
| rw [norm_smul, Real.norm_eq_abs, abs_of_pos r.2] | |
| have he : ((r.1 โข x : U) : E) + r.1 โข ((z : Uแฎ) : E) = | |
| r.1 โข ((x : E) + ((z : Uแฎ) : E)) := by simp [smul_add] | |
| rw [he, normalDirection_pos_smul r.2, mul_assoc] | |
| lemma sphere_subspace_slope_integral (U : Submodule โ E) [Nontrivial E] [Nontrivial Uแฎ] | |
| {g : E โ โโฅ0โ} (hg : Measurable g) : | |
| โซโป y, g y โuniformDirection E = | |
| ((volume : Measure E).toSphere univ)โปยน * | |
| โซโป z : sphere (0 : Uแฎ) 1, โซโป x : U, | |
| ENNReal.ofReal ((1 + โxโ^2) ^ (-((Module.finrank โ E : โ) : โ) / 2)) * | |
| g (normalDirection ((x : E) + ((z : Uแฎ) : E))) | |
| โvolume โ(volume : Measure Uแฎ).toSphere := by | |
| rw [sphere_subspace_polar_integral U hg, โ lintegral_const_mul _ (by fun_prop)] | |
| apply lintegral_congr | |
| intro z | |
| simp_rw [scaled_subspace_integral U z _ hg] | |
| rw [lintegral_lintegral_swap (by fun_prop), โ lintegral_const_mul _ (by fun_prop)] | |
| apply lintegral_congr | |
| intro x | |
| rw [lintegral_mul_const _ (by fun_prop), radial_subspace_integral] | |
| ac_rfl | |
| lemma normalDirection_ballStretch (U : Submodule โ E) {x : U} | |
| (hx : x โ ball (0 : U) 1) (z : sphere (0 : Uแฎ) 1) : | |
| normalDirection (((ballStretch x : U) : E) + ((z : Uแฎ) : E)) = | |
| (x : E) + Real.sqrt (1 - โxโ^2) โข ((z : Uแฎ) : E) := by | |
| have hb := one_sub_norm_sq_pos hx | |
| have hs := Real.sqrt_pos.mpr hb | |
| have hz : โ(z : Uแฎ)โ = 1 := mem_sphere_zero_iff_norm.mp z.2 | |
| have hn : โ(x : E) + Real.sqrt (1 - โxโ^2) โข ((z : Uแฎ) : E)โ = 1 := by | |
| have h := subspace_sum_norm_sq U x (Real.sqrt (1 - โxโ^2) โข (z : Uแฎ)) | |
| simp only [Submodule.coe_smul_of_tower, norm_smul, Real.norm_eq_abs, | |
| abs_of_pos hs, hz, mul_one, Real.sq_sqrt hb.le] at h | |
| nlinarith [norm_nonneg ((x : E) + Real.sqrt (1 - โxโ^2) โข ((z : Uแฎ) : E))] | |
| have he : ((ballStretch x : U) : E) + ((z : Uแฎ) : E) = | |
| (Real.sqrt (1 - โxโ^2))โปยน โข | |
| ((x : E) + Real.sqrt (1 - โxโ^2) โข ((z : Uแฎ) : E)) := by | |
| rw [ballStretch_eq_inv_sqrt hx] | |
| change (Real.sqrt (1 - โxโ^2))โปยน โข (x : E) + ((z : Uแฎ) : E) = _ | |
| rw [smul_add, smul_smul, inv_mul_cancelโ hs.ne', one_smul] | |
| rw [he, normalDirection_smul_sphere (inv_pos.mpr hs) hn] | |
| lemma sphere_subspace_surface_integral (U : Submodule โ E) [Nontrivial E] [Nontrivial Uแฎ] | |
| {g : E โ โโฅ0โ} (hg : Measurable g) : | |
| โซโป y, g y โuniformDirection E = | |
| ((volume : Measure E).toSphere univ)โปยน * | |
| โซโป x : U in ball 0 1, | |
| ENNReal.ofReal ((1 - โxโ^2) ^ ((((Module.finrank โ Uแฎ : โ) : โ) - 2) / 2)) * | |
| โซโป z : sphere (0 : Uแฎ) 1, | |
| g ((x : E) + Real.sqrt (1 - โxโ^2) โข ((z : Uแฎ) : E)) | |
| โ(volume : Measure Uแฎ).toSphere := by | |
| rw [sphere_subspace_slope_integral U hg] | |
| congr 1 | |
| have ht (z : sphere (0 : Uแฎ) 1) : | |
| (โซโป x : U, ENNReal.ofReal ((1 + โxโ^2) ^ (-((Module.finrank โ E : โ) : โ) / 2)) * | |
| g (normalDirection ((x : E) + ((z : Uแฎ) : E)))) = | |
| โซโป x : U in ball 0 1, | |
| ENNReal.ofReal ((1 - โxโ^2) ^ ((((Module.finrank โ Uแฎ : โ) : โ) - 2) / 2)) * | |
| g ((x : E) + Real.sqrt (1 - โxโ^2) โข ((z : Uแฎ) : E)) := by | |
| rw [lintegral_ballStretch] | |
| apply setLIntegral_congr_fun measurableSet_ball | |
| intro x hx | |
| dsimp only | |
| rw [normalDirection_ballStretch U hx z, โ mul_assoc, | |
| โ U.finrank_add_finrank_orthogonal, ballStretch_weight hx] | |
| simp_rw [ht] | |
| rw [lintegral_lintegral_swap (by fun_prop)] | |
| apply setLIntegral_congr_fun measurableSet_ball | |
| intro x hx | |
| dsimp only | |
| rw [lintegral_const_mul _ (by fun_prop)] | |
| lemma surface_lintegral_eq_gaussian [Nontrivial E] {g : E โ โโฅ0โ} (hg : Measurable g) : | |
| โซโป z : sphere (0 : E) 1, g (z : E) โ(volume : Measure E).toSphere = | |
| (volume : Measure E).toSphere univ * โซโป x, g (normalDirection x) โstdGaussian E := by | |
| have he : (โซโป x, g (normalDirection x) โstdGaussian E) = โซโป x, g x โuniformDirection E := by | |
| rw [โ gaussian_normalDirection, lintegral_map hg (by fun_prop)] | |
| rw [he, uniformDirection, lintegral_map hg (by fun_prop), lintegral_smul_measure] | |
| change _ = (volume : Measure E).toSphere univ * | |
| (((volume : Measure E).toSphere univ)โปยน * | |
| โซโป z : sphere (0 : E) 1, g (z : E) โ(volume : Measure E).toSphere) | |
| rw [โ mul_assoc, ENNReal.mul_inv_cancel | |
| (Measure.measure_univ_ne_zero.mpr (Measure.toSphere_ne_zero volume)) (measure_ne_top _ _), one_mul] | |
| lemma sphere_subspace_gaussian_fiber_integral (U : Submodule โ E) | |
| [Nontrivial E] [Nontrivial Uแฎ] {g : E โ โโฅ0โ} (hg : Measurable g) : | |
| โซโป y, g y โuniformDirection E = | |
| ((volume : Measure E).toSphere univ)โปยน * (volume : Measure Uแฎ).toSphere univ * | |
| โซโป x : U in ball 0 1, | |
| ENNReal.ofReal ((1 - โxโ^2) ^ ((((Module.finrank โ Uแฎ : โ) : โ) - 2) / 2)) * | |
| โซโป z : E, g ((x : E) + Real.sqrt (1 - โxโ^2) โข | |
| normalDirection (Uแฎ.starProjection z)) โstdGaussian E := by | |
| rw [sphere_subspace_surface_integral U hg, mul_assoc] | |
| congr 1 | |
| rw [โ lintegral_const_mul _ (by fun_prop)] | |
| apply setLIntegral_congr_fun measurableSet_ball | |
| intro x hx | |
| dsimp only | |
| rw [surface_lintegral_eq_gaussian (E := Uแฎ) (g := fun z => | |
| g ((x : E) + Real.sqrt (1 - โxโ^2) โข (z : E))) (by fun_prop)] | |
| have he : (โซโป z : Uแฎ, g ((x : E) + Real.sqrt (1 - โxโ^2) โข ((normalDirection z : Uแฎ) : E)) | |
| โstdGaussian Uแฎ) = โซโป z : E, g ((x : E) + Real.sqrt (1 - โxโ^2) โข | |
| normalDirection (Uแฎ.starProjection z)) โstdGaussian E := by | |
| rw [โ gaussian_orthogonalProjectionOnto Uแฎ, lintegral_map (by fun_prop) (by fun_prop)] | |
| rfl | |
| rw [he] | |
| ac_rfl | |
| lemma sphere_area_ratio (U : Submodule โ E) [Nontrivial E] [Nontrivial Uแฎ] : | |
| ((volume : Measure E).toSphere univ)โปยน * (volume : Measure Uแฎ).toSphere univ = | |
| ENNReal.ofReal (Real.Gamma (((Module.finrank โ E : โ) : โ) / 2) / | |
| (Real.pi ^ (((Module.finrank โ U : โ) : โ) / 2) * | |
| Real.Gamma (((Module.finrank โ Uแฎ : โ) : โ) / 2))) := by | |
| have hd : 0 < ((Module.finrank โ E : โ) : โ) := Nat.cast_pos.mpr Module.finrank_pos | |
| have hq : 0 < ((Module.finrank โ Uแฎ : โ) : โ) := Nat.cast_pos.mpr Module.finrank_pos | |
| have he : ((Module.finrank โ E : โ) : โ) = | |
| ((Module.finrank โ U : โ) : โ) + ((Module.finrank โ Uแฎ : โ) : โ) := by | |
| exact_mod_cast U.finrank_add_finrank_orthogonal.symm | |
| have hp : Real.pi ^ (((Module.finrank โ E : โ) : โ) / 2) = | |
| Real.pi ^ (((Module.finrank โ U : โ) : โ) / 2) * | |
| Real.pi ^ (((Module.finrank โ Uแฎ : โ) : โ) / 2) := by | |
| rw [he, add_div, Real.rpow_add Real.pi_pos] | |
| rw [sphere_area, sphere_area, โ ENNReal.ofReal_inv_of_pos (by positivity), | |
| โ ENNReal.ofReal_mul (by positivity)] | |
| congr 1 | |
| rw [hp] | |
| field_simp | |
| end PosteriorReplicas | |
| end | |
| end OAI | |