Download data/lean/OAI/Geometry/ProjectionBody/SimplexVolume.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 8.6 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Geometry/ProjectionBody/SimplexVolume.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Geometry/ProjectionBody/SimplexVolume.lean
-
curl -L -o SimplexVolume.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Geometry/ProjectionBody/SimplexVolume.lean
8.6 kB
| import Mathlib.Logic.Equiv.Fin.Basic | |
| import Mathlib.Analysis.SpecialFunctions.Integrals.Basic | |
| import Mathlib.MeasureTheory.Measure.Haar.InnerProductSpace | |
| import Mathlib.MeasureTheory.Constructions.Pi | |
| import Mathlib.Tactic.Linarith | |
| import Mathlib.Tactic.Ring | |
| import Mathlib.Tactic.Positivity | |
| import Mathlib.Tactic.FunProp | |
| import Mathlib.Tactic.Measurability | |
| import Mathlib.Tactic.SplitIfs | |
| namespace OAI | |
| /-! | |
| # Volumes of standard simplices and their products | |
| The simplex-volume calculation below uses Tonelli's theorem and induction on the | |
| dimension. At first coordinate `t`, the remaining section is a simplex of radius | |
| `r - t`; its volume is integrated over `0 β€ t β€ r`. The Euclidean versions use | |
| the measure-preserving equivalence between coordinate space and `EuclideanSpace`. | |
| The product formula is proved using the product Lebesgue measure under the | |
| canonical splitting of `Fin (p + q)`. | |
| -/ | |
| open MeasureTheory Set | |
| open scoped BigOperators ENNReal | |
| namespace ProjectionCounterexample | |
| /-- The coordinate standard simplex with nonnegative coordinates and sum at most `r`. -/ | |
| def coordinateSimplex (n : β) (r : β) : Set (Fin n β β) := | |
| {x | (β i, 0 β€ x i) β§ β i, x i β€ r} | |
| theorem coordinateSimplex_measurableSet (n : β) (r : β) : | |
| MeasurableSet (coordinateSimplex n r) := by | |
| unfold coordinateSimplex | |
| measurability | |
| theorem coordinateSimplex_eq_empty_of_neg (n : β) {r : β} (hr : r < 0) : | |
| coordinateSimplex n r = β := by | |
| apply Set.eq_empty_iff_forall_notMem.mpr | |
| intro x hx | |
| have hsum : 0 β€ β i, x i := Finset.sum_nonneg fun i _ => hx.1 i | |
| exact (not_lt_of_ge (hsum.trans hx.2)) hr | |
| theorem integral_simplex_slice (n : β) {r : β} (hr : 0 β€ r) : | |
| (β«β» t in Icc 0 r, ENNReal.ofReal ((r - t) ^ n / (n.factorial : β))) = | |
| ENNReal.ofReal (r ^ (n + 1) / ((n + 1).factorial : β)) := by | |
| have hi : IntegrableOn (fun t : β => (r - t) ^ n / (n.factorial : β)) (Icc 0 r) := | |
| ContinuousOn.integrableOn_Icc (by fun_prop) | |
| have hn : 0 β€α΅[volume.restrict (Icc 0 r)] | |
| (fun t : β => (r - t) ^ n / (n.factorial : β)) := by | |
| filter_upwards [ae_restrict_mem measurableSet_Icc] with t ht | |
| exact div_nonneg (pow_nonneg (sub_nonneg.mpr ht.2) n) (by positivity) | |
| rw [β ofReal_integral_eq_lintegral_ofReal hi hn, | |
| integral_Icc_eq_integral_Ioc, β intervalIntegral.integral_of_le hr, | |
| intervalIntegral.integral_div, intervalIntegral.integral_comp_sub_left (fun t : β => t ^ n) r] | |
| simp only [sub_self, sub_zero, integral_pow, | |
| zero_pow (Nat.succ_ne_zero n), sub_zero] | |
| congr 1 | |
| rw [Nat.factorial_succ, Nat.cast_mul, Nat.cast_add, Nat.cast_one, div_div] | |
| theorem volume_coordinateSimplex (n : β) (r : β) (hr : 0 β€ r) : | |
| volume (coordinateSimplex n r) = | |
| ENNReal.ofReal (r ^ n / (n.factorial : β)) := by | |
| induction n generalizing r with | |
| | zero => | |
| have h : coordinateSimplex 0 r = univ := by | |
| ext x | |
| simp [coordinateSimplex, hr] | |
| simp [h, Measure.volume_pi_eq_dirac (0 : Fin 0 β β)] | |
| | succ n ih => | |
| let e := MeasurableEquiv.piFinSuccAbove (fun _ : Fin (n + 1) => β) 0 | |
| have he (p : β Γ (Fin n β β)) : e.symm p = Fin.cons p.1 p.2 := by | |
| ext i | |
| refine Fin.cases ?_ (fun j => ?_) i <;> simp [e, MeasurableEquiv.piFinSuccAbove] | |
| have hslice (t : β) : | |
| Prod.mk t β»ΒΉ' (e.symm β»ΒΉ' coordinateSimplex (n + 1) r) = | |
| if t β Icc 0 r then coordinateSimplex n (r - t) else β := by | |
| ext x | |
| simp only [mem_preimage, he, coordinateSimplex, mem_ofPred_eq, | |
| Fin.forall_fin_succ, Fin.cons_zero, Fin.cons_succ, Fin.sum_univ_succ] | |
| split_ifs with ht | |
| Β· simp only [mem_ofPred_eq] | |
| constructor | |
| Β· rintro β¨β¨_, hxβ©, hsβ© | |
| exact β¨hx, by linarithβ© | |
| Β· rintro β¨hx, hsβ© | |
| exact β¨β¨ht.1, hxβ©, by linarithβ© | |
| Β· simp only [mem_empty_iff_false, iff_false] | |
| rintro β¨β¨ht0, hxβ©, hsβ© | |
| apply ht | |
| have hsum : 0 β€ β i, x i := Finset.sum_nonneg fun i _ => hx i | |
| exact β¨ht0, by linarithβ© | |
| rw [β (volume_preserving_piFinSuccAbove | |
| (fun _ : Fin (n + 1) => β) 0).symm.measure_preimage_equiv] | |
| change volume (e.symm β»ΒΉ' coordinateSimplex (n + 1) r) = _ | |
| rw [Measure.volume_eq_prod, Measure.prod_apply | |
| ((coordinateSimplex_measurableSet (n + 1) r).preimage e.symm.measurable)] | |
| simp_rw [hslice] | |
| have hfun : (fun t : β => volume | |
| (if t β Icc 0 r then coordinateSimplex n (r - t) else β )) = | |
| (Icc 0 r).indicator | |
| (fun t : β => ENNReal.ofReal ((r - t) ^ n / (n.factorial : β))) := by | |
| funext t | |
| by_cases ht : t β Icc 0 r | |
| Β· simp [ht, ih (r - t) (sub_nonneg.mpr ht.2)] | |
| Β· simp [ht] | |
| rw [hfun, lintegral_indicator measurableSet_Icc] | |
| exact integral_simplex_slice n hr | |
| /-- The standard simplex has ordinary Lebesgue volume `1 / n!`. -/ | |
| theorem volume_unit_coordinateSimplex (n : β) : | |
| volume (coordinateSimplex n 1) = ENNReal.ofReal (1 / (n.factorial : β)) := by | |
| simpa using volume_coordinateSimplex n 1 zero_le_one | |
| /-- Exact volume of a possibly degenerate linear image of the coordinate simplex. -/ | |
| theorem volume_linearImage_unit_coordinateSimplex (n : β) | |
| (f : (Fin n β β) ββ[β] (Fin n β β)) : | |
| volume (f '' coordinateSimplex n 1) = | |
| ENNReal.ofReal (|LinearMap.det f| / (n.factorial : β)) := by | |
| rw [Measure.addHaar_image_linearMap, volume_unit_coordinateSimplex, | |
| β ENNReal.ofReal_mul (abs_nonneg _)] | |
| congr 1 | |
| ring | |
| /-- The same volume statement in Euclidean space with its canonical Euclidean measure. -/ | |
| theorem volume_unit_euclideanSimplex (n : β) : | |
| volume {x : EuclideanSpace β (Fin n) | (β i, 0 β€ x i) β§ β i, x i β€ 1} = | |
| ENNReal.ofReal (1 / (n.factorial : β)) := by | |
| have hs : MeasurableSet | |
| {x : EuclideanSpace β (Fin n) | (β i, 0 β€ x i) β§ β i, x i β€ 1} := by | |
| measurability | |
| rw [β (PiLp.volume_preserving_toLp (Fin n)).measure_preimage hs.nullMeasurableSet] | |
| exact volume_unit_coordinateSimplex n | |
| /-- Real-valued version of the Euclidean simplex volume. -/ | |
| theorem realVolume_unit_euclideanSimplex (n : β) : | |
| (volume {x : EuclideanSpace β (Fin n) | | |
| (β i, 0 β€ x i) β§ β i, x i β€ 1}).toReal = 1 / (n.factorial : β) := by | |
| rw [volume_unit_euclideanSimplex, ENNReal.toReal_ofReal] | |
| positivity | |
| /-- The coordinate product, with the first `p` and last `q` coordinates separated. -/ | |
| def coordinateSimplexProduct (p q : β) : Set (Fin (p + q) β β) := | |
| {x | (fun i : Fin p => x (Fin.castAdd q i)) β coordinateSimplex p 1 β§ | |
| (fun i : Fin q => x (Fin.natAdd p i)) β coordinateSimplex q 1} | |
| /-- The product-volume identity uses the actual product Lebesgue measure. -/ | |
| theorem volume_coordinateSimplexProduct (p q : β) : | |
| volume (coordinateSimplexProduct p q) = | |
| ENNReal.ofReal (1 / ((p.factorial : β) * (q.factorial : β))) := by | |
| let e : (Fin (p + q) β β) βα΅ ((Fin p β β) Γ (Fin q β β)) := | |
| (MeasurableEquiv.piCongrLeft (fun _ : Fin (p + q) => β) | |
| finSumFinEquiv).symm.trans (MeasurableEquiv.sumPiEquivProdPi (fun _ => β)) | |
| have he (x : Fin (p + q) β β) : | |
| e x = ((fun i : Fin p => x (Fin.castAdd q i)), | |
| (fun i : Fin q => x (Fin.natAdd p i))) := by | |
| rfl | |
| have hm : MeasurePreserving e := | |
| (volume_measurePreserving_piCongrLeft (fun _ : Fin (p + q) => β) | |
| finSumFinEquiv).symm.trans (volume_measurePreserving_sumPiEquivProdPi (fun _ => β)) | |
| have hs : coordinateSimplexProduct p q = | |
| e β»ΒΉ' (coordinateSimplex p 1 ΓΛ’ coordinateSimplex q 1) := by | |
| ext x | |
| simp [coordinateSimplexProduct, he] | |
| rw [hs, hm.measure_preimage_equiv, Measure.volume_eq_prod, Measure.prod_prod, | |
| volume_unit_coordinateSimplex, volume_unit_coordinateSimplex, | |
| β ENNReal.ofReal_mul (by positivity : 0 β€ 1 / (p.factorial : β))] | |
| congr 1 | |
| ring | |
| /-- Product-simplex volume in the canonical Euclidean coordinates. -/ | |
| theorem volume_euclideanSimplexProduct (p q : β) : | |
| volume {x : EuclideanSpace β (Fin (p + q)) | | |
| ((β i : Fin p, 0 β€ x (Fin.castAdd q i)) β§ | |
| β i : Fin p, x (Fin.castAdd q i) β€ 1) β§ | |
| ((β i : Fin q, 0 β€ x (Fin.natAdd p i)) β§ | |
| β i : Fin q, x (Fin.natAdd p i) β€ 1)} = | |
| ENNReal.ofReal (1 / ((p.factorial : β) * (q.factorial : β))) := by | |
| rw [β (EuclideanSpace.volume_preserving_symm_measurableEquiv_toLp | |
| (Fin (p + q))).symm.measure_preimage_equiv] | |
| exact volume_coordinateSimplexProduct p q | |
| end ProjectionCounterexample | |
| end OAI | |