Stat.OrderStatistic
Exact distribution theory for the order statistics of n i.i.d.
Basic 7 core · 2 supporting This module fixes a concrete uniform measure on [0,1], iid finite samples, Mathlib tuple sorting, and the ordered-simplex measure identity. ★ sorted_uniform_law
Uniform samples and their sorted order region
This module fixes a concrete uniform measure on [0,1], iid finite samples,
Mathlib tuple sorting, and the ordered-simplex measure identity. The latter is
the measure-theoretic input to exact spacing calculations.
The unit-uniform probability measure is Lebesgue measure restricted to the closed unit interval.
Given a real sampling law and a finite sample size, the iid sample law is the corresponding finite product measure.
Given a finite sample size and a real tuple, the sorted sample is that tuple rearranged in nondecreasing order.
Given a finite dimension, the ordered unit region is the nondecreasing part of the closed unit cube.
Given a finite dimension, the unit cube is the set of real tuples with every coordinate in the closed unit interval.
Given a sample size, a zero-based gap index, and a real tuple, the sorted gap is the difference between the indicated adjacent order statistics, or zero when that index is out of range.
Definition (Lean source)
Given a finite sample size, the sorted iid unit-uniform sample has factorial density on the ordered unit region.
Formal statement
Proof (Lean source)
2 supporting declarations (lemmas, instances)
-
iid_uniform_cube_lawtheorem — Given a finite sample size, the iid unit-uniform product law is Lebesgue measure restricted to the unit cube.Proof (Lean source)
theorem iid_uniform_cube_law (n : ℕ) : iidSample uniform01 n = volume.restrict (unitCube n) := by change (Measure.pi fun _ : Fin n => volume.restrict (Icc (0 : ℝ) 1)) = _ rw [← Measure.restrict_pi_pi, ← volume_pi] congr 1 ext x simp [unitCube, Pi.le_def, Set.mem_Icc, forall_and] -
sorted_cube_lawtheorem — Given a finite dimension, sorting Lebesgue measure on the unit cube yields factorial density on the ordered chamber.hypothesesn :ℕconclusion(volume.restrict (unitCube n)).map (sortedSample n)= (n.factorial : ENNReal) • (volume.restrict (orderedUnitRegion n))Proof (Lean source)
theorem sorted_cube_law (n : ℕ) : (volume.restrict (unitCube n)).map (sortedSample n) = (n.factorial : ENNReal) • (volume.restrict (orderedUnitRegion n)) := by let s (σ : Perm (Fin n)) : Set (Fin n → ℝ) := {x | x ∈ unitCube n ∧ Monotone (x ∘ σ)} have hs (σ : Perm (Fin n)) : MeasurableSet (s σ) := by have hc : MeasurableSet (unitCube n) := by have heq : unitCube n = ⋂ i, (fun x : Fin n → ℝ => x i) ⁻¹' Icc (0 : ℝ) 1 := by ext x simp [unitCube] rw [heq] exact MeasurableSet.iInter (fun i => measurable_pi_apply i measurableSet_Icc) have hmono : MeasurableSet {x : Fin n → ℝ | Monotone (x ∘ σ)} := by have hcont : Continuous (fun x : Fin n → ℝ => x ∘ σ) := by fun_prop exact (isClosed_monotone.preimage hcont).measurableSet exact hc.inter hmono have hm (σ : Perm (Fin n)) : AEMeasurable (sortedSample n) (volume.restrict (s σ)) := by have hperm : Measurable (fun x : Fin n → ℝ => x ∘ σ) := by fun_prop exact hperm.aemeasurable.congr (ae_restrict_of_forall_mem (hs σ) (fun x hx => (sortedSample_eq_comp_of_monotone n σ x hx.2).symm)) have hsum : AEMeasurable (sortedSample n) (∑ σ : Perm (Fin n), volume.restrict (s σ)) := by rw [← Measure.sum_fintype] exact AEMeasurable.sum_measure hm calc (volume.restrict (unitCube n)).map (sortedSample n) = (∑ σ : Perm (Fin n), volume.restrict (s σ)).map (sortedSample n) := by rw [cube_chamber_decomposition] _ = ∑ σ : Perm (Fin n), (volume.restrict (s σ)).map (sortedSample n) := Measure.map_finset_sum' hsum _ = ∑ _σ : Perm (Fin n), volume.restrict (orderedUnitRegion n) := by simp only [s, permutation_chamber_map] _ = (n.factorial : ENNReal) • (volume.restrict (orderedUnitRegion n)) := by simp [Finset.sum_const, Fintype.card_perm, Nat.cast_smul_eq_nsmul]
Dirichlet 6 core · 8 supporting The first n spacings, including the gap from zero to the first order statistic, give ordinary coordinates for the n+1-component spacing simplex. ★ uniform_firstN_spacings_law
Dirichlet coordinate law for uniform spacings
The first n spacings, including the gap from zero to the first order
statistic, give ordinary coordinates for the n+1-component spacing simplex.
The last spacing is one minus their sum. Their density in these coordinates
is the constant n! on the standard simplex.
Given a finite dimension, an ordered real tuple, and a coordinate index, the ordered spacing is the successive difference at that coordinate, beginning from zero.
Given a finite dimension, a spacing vector, and a coordinate index, the prefix coordinate is the sum of spacings through that coordinate.
Given a sample size, a real sample, and a coordinate index, the first spacing vector is the successive differences of the sorted sample, beginning from zero, so its first entry is the smallest observation itself.
Definition (Lean source)
Given a finite dimension, the spacing simplex is the nonnegative coordinate simplex with total at most one.
Given a finite dimension, the linear spacing transformation is the linear map of successive coordinate differences.
Given a finite sample size, the first spacing vector of an iid unit-uniform sample has factorial density on the spacing simplex.
Formal statement
Proof (Lean source)
8 supporting declarations (lemmas, instances)
-
orderedSpacings_prefixCoordinatestheorem — Given a finite dimension and a spacing vector, successive differences of its prefix coordinates recover that vector.Proof (Lean source)
theorem orderedSpacings_prefixCoordinates (n : ℕ) (z : Fin n → ℝ) : orderedSpacings n (prefixCoordinates n z) = z := by funext i by_cases hi : i.val = 0 · have hset : Iic i = {i} := by ext j simp only [Finset.mem_Iic, Finset.mem_singleton] constructor · intro hj exact Fin.ext (by omega) · intro h subst j exact le_refl _ simp [orderedSpacings, prefixCoordinates, hi, hset] · have hset : Iic (⟨i.val - 1, by omega⟩ : Fin n) = Finset.Iio i := by ext j simp only [Finset.mem_Iic, Finset.mem_Iio, Fin.le_def, Fin.lt_def] omega have hsum := Finset.sum_Iio_add_eq_sum_Iic (f := z) i rw [← hset] at hsum simp only [orderedSpacings, prefixCoordinates, hi, ↓reduceIte] linarith -
prefixCoordinates_orderedSpacingstheorem — Given a finite dimension and a real tuple, prefix sums of its successive differences recover that tuple.Proof (Lean source)
theorem prefixCoordinates_orderedSpacings (n : ℕ) (y : Fin n → ℝ) : prefixCoordinates n (orderedSpacings n y) = y := by cases n with | zero => funext i exact elim0 i | succ n => funext i induction i using Fin.induction with | zero => have hset : Iic (0 : Fin (n + 1)) = {0} := by ext j simp only [Finset.mem_Iic, Finset.mem_singleton] exact ⟨fun h => le_antisymm h (bot_le), fun h => h ▸ le_refl _⟩ simp [prefixCoordinates, orderedSpacings, hset] | succ j ih => have hset : Finset.Iio j.succ = Iic j.castSucc := by ext k simp only [Finset.mem_Iio, Finset.mem_Iic, Fin.lt_def, Fin.le_def] simp only [Fin.val_succ, Fin.val_castSucc] omega have hpred : (⟨j.val, by omega⟩ : Fin (n + 1)) = j.castSucc := by ext rfl have hsum := Finset.sum_Iio_add_eq_sum_Iic (f := orderedSpacings (n + 1) y) j.succ rw [hset] at hsum change (∑ k ∈ Iic j.succ, orderedSpacings (n + 1) y k) = y j.succ rw [← hsum, ← prefixCoordinates, ih] simp [orderedSpacings, hpred] -
orderedSpacings_preimage_simplextheorem — Given a finite dimension, the preimage of the spacing simplex under successive differences is exactly the ordered unit region.Proof (Lean source)
theorem orderedSpacings_preimage_simplex (n : ℕ) : (orderedSpacings n) ⁻¹' spacingSimplex n = orderedUnitRegion n := by ext y simp only [Set.mem_preimage, spacingSimplex, orderedUnitRegion, Set.mem_ofPred_eq] constructor · rintro ⟨hpos, hsum⟩ have hy : prefixCoordinates n (orderedSpacings n y) = y := prefixCoordinates_orderedSpacings n y have hmono : Monotone (prefixCoordinates n (orderedSpacings n y)) := by intro i j hij exact Finset.sum_le_sum_of_subset_of_nonneg (Finset.Iic_subset_Iic.mpr hij) (by intros; exact hpos _) refine ⟨?_, hy ▸ hmono⟩ intro i rw [← hy] constructor · exact Finset.sum_nonneg (fun j _ => hpos j) · exact le_trans (Finset.sum_le_univ_sum_of_nonneg hpos) hsum · rintro ⟨hunit, hmono⟩ constructor · intro i by_cases hi : i.val = 0 · simpa [orderedSpacings, hi] using (hunit i).1 · have hp : (⟨i.val - 1, by omega⟩ : Fin n) ≤ i := by apply Fin.le_def.mpr change i.val - 1 ≤ i.val omega simpa [orderedSpacings, hi] using sub_nonneg.mpr (hmono hp) · cases n with | zero => simp | succ m => have hlast : (Iic (last m)) = univ := by ext i simp only [Finset.mem_Iic, Finset.mem_univ, iff_true] exact Fin.le_last i have h := congrFun (prefixCoordinates_orderedSpacings (m + 1) y) (last m) simp only [prefixCoordinates, hlast] at h rw [h] exact (hunit (last m)).2 -
orderedSpacingsLinear_applytheorem — Given a finite dimension and a real tuple, the linear spacing transformation agrees with the spacing definition.Proof (Lean source)
theorem orderedSpacingsLinear_apply (n : ℕ) (y : Fin n → ℝ) : orderedSpacingsLinear n y = orderedSpacings n y := by funext i by_cases hi : i.val = 0 · simp [orderedSpacingsLinear, orderedSpacings, hi] · simp [orderedSpacingsLinear, orderedSpacings, hi] -
orderedSpacingsLinear_dettheorem — Given a finite dimension, the linear spacing transformation has determinant one.Proof (Lean source)
theorem orderedSpacingsLinear_det (n : ℕ) : det (orderedSpacingsLinear n) = 1 := by classical let M := LinearMap.toMatrix' (orderedSpacingsLinear n) have htri : M.IsLowerTriangular := by intro i j hij have hij' : i < j := hij have hj0 : i.val ≠ 0 ∨ i.val = 0 := ne_or_eq _ _ rcases hj0 with hi | hi · simp [M, LinearMap.toMatrix'_apply, orderedSpacingsLinear_apply, orderedSpacings, hi, ne_of_lt hij', show (⟨i.val - 1, by omega⟩ : Fin n) ≠ j from by intro h have := congrArg val h simp at this omega] · simp [M, LinearMap.toMatrix'_apply, orderedSpacingsLinear_apply, orderedSpacings, hi, ne_of_lt hij'] have hdiag (i : Fin n) : M i i = 1 := by by_cases hi : i.val = 0 · simp [M, LinearMap.toMatrix'_apply, orderedSpacingsLinear_apply, orderedSpacings, hi] · have hp : (⟨i.val - 1, by omega⟩ : Fin n) ≠ i := by intro h have := congrArg val h simp at this omega simp [M, LinearMap.toMatrix'_apply, orderedSpacingsLinear_apply, orderedSpacings, hi, hp] rw [← LinearMap.det_toMatrix'] change M.det = 1 rw [Matrix.det_of_isLowerTriangular M htri] simp [hdiag] -
orderedSpacings_measurePreservingtheorem — Given a finite dimension, the linear spacing transformation preserves Lebesgue measure.Proof (Lean source)
theorem orderedSpacings_measurePreserving (n : ℕ) : MeasurePreserving (orderedSpacings n) volume volume := by have hfun : orderedSpacings n = orderedSpacingsLinear n := by funext y exact (orderedSpacingsLinear_apply n y).symm have hmeas : Measurable (orderedSpacings n) := by rw [hfun] exact (orderedSpacingsLinear n).continuous_of_finiteDimensional.measurable refine ⟨hmeas, ?_⟩ rw [hfun] simpa [orderedSpacingsLinear_det n] using (Real.map_linearMap_volume_pi_eq_smul_volume_pi (f := orderedSpacingsLinear n) (by simp [orderedSpacingsLinear_det n])) -
orderedSpacings_restrict_lawtheorem — Given a finite dimension, successive differences transport restricted Lebesgue measure from the ordered unit region to the spacing simplex.Proof (Lean source)
theorem orderedSpacings_restrict_law (n : ℕ) : (volume.restrict (orderedUnitRegion n)).map (orderedSpacings n) = volume.restrict (spacingSimplex n) := by have hsimplex : MeasurableSet (spacingSimplex n) := by have hclosed : IsClosed (spacingSimplex n) := by change IsClosed {z : Fin n → ℝ | (∀ i, 0 ≤ z i) ∧ (∑ i, z i) ≤ 1} apply IsClosed.inter · have hp : IsClosed (⋂ i : Fin n, (fun z : Fin n → ℝ => z i) ⁻¹' Ici (0 : ℝ)) := isClosed_iInter (fun i => isClosed_Ici.preimage (continuous_apply i)) have heq : {z : Fin n → ℝ | ∀ i, 0 ≤ z i} = ⋂ i : Fin n, (fun z : Fin n → ℝ => z i) ⁻¹' Ici (0 : ℝ) := by ext z simp change IsClosed (ofPred (fun z : Fin n → ℝ => ∀ i, 0 ≤ z i)) rw [heq] exact hp · exact isClosed_Iic.preimage (continuous_finsetSum _ (fun i _ => (show Continuous (fun z : Fin n → ℝ => z i) from continuous_apply i))) exact hclosed.measurableSet have hmp := orderedSpacings_measurePreserving n rw [← orderedSpacings_preimage_simplex n, ← Measure.restrict_map hmp.measurable hsimplex, hmp.map_eq] -
firstNSpacings_eq_orderedSpacingstheorem — Given a finite sample size and a real sample, the first spacing vector equals the successive differences of the sorted sample.Proof (Lean source)
theorem firstNSpacings_eq_orderedSpacings (n : ℕ) (x : Fin n → ℝ) : firstNSpacings n x = orderedSpacings n (sortedSample n x) := by rfl
SimplexIntegrals 2 core · 5 supporting This module isolates the volume, slicing, and one-variable integral needed to compute a coordinate's second moment under the uniform spacing law. ★ simplex_coordinate_square_eq_first
Elementary integrals on spacing simplices
This module isolates the volume, slicing, and one-variable integral needed to compute a coordinate's second moment under the uniform spacing law.
Given a finite dimension and a real radius, the scaled spacing simplex is the nonnegative coordinate simplex with total at most that radius.
Given a finite dimension and a coordinate index, the integral over the spacing simplex of the square of that coordinate equals the integral of the square of the first coordinate.
Formal statement
Proof (Lean source)
5 supporting declarations (lemmas, instances)
-
scaledSpacingSimplex_volumetheorem — Given a finite dimension, a real radius, and its nonnegativity, the scaled spacing simplex has the stated factorial-normalized Lebesgue volume.hypothesesn :ℕr :ℝhr :0 ≤ rconclusionProof (Lean source)
theorem scaledSpacingSimplex_volume (n : ℕ) (r : ℝ) (hr : 0 ≤ r) : volume (scaledSpacingSimplex n r) = ofReal (r ^ n / (n.factorial : ℝ)) := by classical have hsort : AEMeasurable (sortedSample n) (volume : Measure (Fin n → ℝ)) := by let s (σ : Perm (Fin n)) : Set (Fin n → ℝ) := {x | Monotone (x ∘ σ)} have hs (σ : Perm (Fin n)) : MeasurableSet (s σ) := by have hc : Continuous (fun x : Fin n → ℝ => x ∘ σ) := by fun_prop exact (isClosed_monotone.preimage hc).measurableSet have hcover : (⋃ σ, s σ) = univ := by ext x simp only [Set.mem_iUnion, Set.mem_univ, iff_true] exact ⟨Tuple.sort x, Tuple.monotone_sort x⟩ have hpiece (σ : Perm (Fin n)) : AEMeasurable (sortedSample n) (volume.restrict (s σ)) := by have hp : Measurable (fun x : Fin n → ℝ => x ∘ σ) := by fun_prop apply hp.aemeasurable.congr exact ae_restrict_of_forall_mem (hs σ) (fun x hx => (show (fun x => x ∘ σ) x = sortedSample n x from (Tuple.comp_sort_eq_comp_iff_monotone (f := x) (σ := σ)).2 hx)) simpa only [hcover, Measure.restrict_univ] using (AEMeasurable.iUnion hpiece) have hsort' : AEMeasurable (sortedSample n) (iidSample uniform01 n) := by rw [iid_uniform_cube_law] exact hsort.restrict have hspacing : Measurable (orderedSpacings n) := (orderedSpacings_measurePreserving n).measurable have hfirst : AEMeasurable (firstNSpacings n) (iidSample uniform01 n) := by convert hspacing.comp_aemeasurable hsort' using 1 funext x exact firstNSpacings_eq_orderedSpacings n x have hprob : (iidSample uniform01 n) univ = 1 := by haveI : IsProbabilityMeasure uniform01 := ⟨by simp [uniform01]⟩ simp [iidSample] have hunit : volume (spacingSimplex n) = (n.factorial : ENNReal)⁻¹ := by have h := congrArg (fun μ : Measure (Fin n → ℝ) => μ univ) (uniform_firstN_spacings_law n) rw [Measure.map_apply_of_aemeasurable hfirst MeasurableSet.univ] at h simp only [Set.preimage_univ, Measure.smul_apply, Measure.restrict_apply, Set.univ_inter, hprob] at h exact ENNReal.eq_inv_of_mul_eq_one_left (by simpa [mul_comm] using h.symm) have hscale : r • spacingSimplex n = scaledSpacingSimplex n r := by ext z simp only [Set.mem_smul_set, spacingSimplex, scaledSpacingSimplex, Set.mem_ofPred_eq] by_cases hr0 : r = 0 · subst r constructor · rintro ⟨y, _, rfl⟩ simp · rintro ⟨hp, hs⟩ have hz : z = 0 := by funext i have hi : z i ≤ ∑ j, z j := Finset.single_le_sum (fun j _ => hp j) (Finset.mem_univ i) exact le_antisymm (le_trans hi hs) (hp i) subst z refine ⟨0, ?_, by simp⟩ simp [spacingSimplex] · have hrpos : 0 < r := lt_of_le_of_ne hr (Ne.symm hr0) constructor · rintro ⟨y, ⟨hp, hs⟩, rfl⟩ constructor · intro i simpa [Pi.smul_apply, smul_eq_mul] using mul_nonneg hr (hp i) · simpa [Pi.smul_apply, smul_eq_mul, ← Finset.mul_sum] using (mul_le_mul_of_nonneg_left hs hr) · rintro ⟨hp, hs⟩ refine ⟨r⁻¹ • z, ?_, ?_⟩ · constructor · intro i exact smul_nonneg (inv_nonneg.mpr hr) (hp i) · have hs' : (∑ i, (r⁻¹ • z) i) = r⁻¹ * ∑ i, z i := by simp [Pi.smul_apply, smul_eq_mul, Finset.mul_sum] rw [hs'] calc r⁻¹ * ∑ i, z i ≤ r⁻¹ * r := mul_le_mul_of_nonneg_left hs (inv_nonneg.mpr hr) _ = 1 := inv_mul_cancel₀ hr0 · simp [smul_smul, hr0] rw [← hscale, Measure.addHaar_smul, hunit] simp only [Module.finrank_pi, Module.finrank_self, Finset.sum_const_zero, Fintype.card_fin, nsmul_eq_mul, mul_one] rw [abs_of_nonneg (pow_nonneg hr n), ENNReal.ofReal_div_of_pos (by positivity)] simp [ENNReal.ofReal_natCast, div_eq_mul_inv] -
simplex_tail_sectiontheorem — Given a finite dimension, a first coordinate, and its membership in the unit interval, the remaining simplex section has radius one minus that coordinate.hypothesesconclusionProof (Lean source)
theorem simplex_tail_section (n : ℕ) (t : ℝ) (ht : t ∈ Icc (0 : ℝ) 1) : {w : Fin n → ℝ | cons t w ∈ spacingSimplex (n + 1)} = scaledSpacingSimplex n (1 - t) := by ext w simp only [Set.mem_ofPred_eq, spacingSimplex, scaledSpacingSimplex] constructor · rintro ⟨hpos, hsum⟩ constructor · intro i simpa using hpos i.succ · rw [Fin.sum_cons] at hsum linarith · rintro ⟨hpos, hsum⟩ constructor · intro i refine Fin.cases ?_ ?_ i · exact ht.1 · intro j simpa using hpos j · rw [Fin.sum_cons] linarith -
simplex_first_coordinate_square_fubinitheorem — Given a finite dimension, integrating the squared first spacing coordinate equals integrating it against its tail-section volume.Proof (Lean source)
theorem simplex_first_coordinate_square_fubini (n : ℕ) : (∫ z in spacingSimplex (n + 1), (z (0 : Fin (n + 1))) ^ 2 ∂volume) = ∫ t in Icc (0 : ℝ) 1, t ^ 2 * (volume (scaledSpacingSimplex n (1 - t))).toReal := by let e : (ℝ × (Fin n → ℝ)) ≃ᵐ (Fin (n + 1) → ℝ) := (piFinSuccAbove (fun _ => ℝ) 0).symm let S : Set (ℝ × (Fin n → ℝ)) := e ⁻¹' spacingSimplex (n + 1) have hem : MeasurePreserving e := (volume_preserving_piFinSuccAbove (fun _ : Fin (n + 1) => ℝ) 0).symm _ have hsimplex : MeasurableSet (spacingSimplex (n + 1)) := by have hclosed : IsClosed (spacingSimplex (n + 1)) := by change IsClosed {z : Fin (n + 1) → ℝ | (∀ i, 0 ≤ z i) ∧ (∑ i, z i) ≤ 1} apply IsClosed.inter · have hp : IsClosed (⋂ i : Fin (n + 1), (fun z : Fin (n + 1) → ℝ => z i) ⁻¹' Ici (0 : ℝ)) := isClosed_iInter (fun i => isClosed_Ici.preimage (continuous_apply i)) have heq : {z : Fin (n + 1) → ℝ | ∀ i, 0 ≤ z i} = ⋂ i : Fin (n + 1), (fun z : Fin (n + 1) → ℝ => z i) ⁻¹' Ici 0 := by ext z simp change IsClosed {z : Fin (n + 1) → ℝ | ∀ i, 0 ≤ z i} rw [heq] exact hp · exact isClosed_Iic.preimage (continuous_finsetSum _ (fun i _ => continuous_apply i)) exact hclosed.measurableSet have hS : MeasurableSet S := hsimplex.preimage e.measurable have hfinite : volume (spacingSimplex (n + 1)) ≠ ⊤ := by change volume (scaledSpacingSimplex (n + 1) 1) ≠ ⊤ rw [scaledSpacingSimplex_volume (n + 1) 1 (by norm_num)] simp have hInt : IntegrableOn (fun z : Fin (n + 1) → ℝ => z 0 ^ 2) (spacingSimplex (n + 1)) volume := by apply Measure.integrableOn_of_bounded hfinite (((measurable_pi_apply 0).pow_const 2).aestronglyMeasurable) (M := 1) apply ae_restrict_of_forall_mem hsimplex intro z hz have h0 : 0 ≤ z 0 := hz.1 0 have hle : z 0 ≤ 1 := by calc z 0 ≤ ∑ i, z i := Finset.single_le_sum (fun i _ => hz.1 i) (Finset.mem_univ 0) _ ≤ 1 := hz.2 rw [Real.norm_eq_abs, abs_of_nonneg (sq_nonneg _)] nlinarith have hpreInt : IntegrableOn (fun p : ℝ × (Fin n → ℝ) => p.1 ^ 2) S ((volume : Measure ℝ).prod volume) := by rw [← Measure.volume_eq_prod] rw [← hem.integrableOn_comp_preimage e.measurableEmbedding] at hInt convert hInt using 1 funext p simp [e, MeasurableEquiv.piFinSuccAbove_symm_apply, Fin.consEquiv] have hprodInt : Integrable (S.indicator (fun p : ℝ × (Fin n → ℝ) => p.1 ^ 2)) ((volume : Measure ℝ).prod volume) := by exact hpreInt.integrable_indicator hS have hsection (t : ℝ) (ht : t ∈ Icc (0 : ℝ) 1) : {w : Fin n → ℝ | (t, w) ∈ S} = scaledSpacingSimplex n (1 - t) := by simpa [S, e, MeasurableEquiv.piFinSuccAbove_symm_apply, Fin.insertNth_zero, Fin.consEquiv] using simplex_tail_section n t ht have hsubset (p : ℝ × (Fin n → ℝ)) (hp : p ∈ S) : p.1 ∈ Icc (0 : ℝ) 1 := by have hp' : cons p.1 p.2 ∈ spacingSimplex (n + 1) := by simpa [S, e, MeasurableEquiv.piFinSuccAbove_symm_apply, Fin.insertNth_zero, Fin.consEquiv] using hp have h0 : 0 ≤ p.1 := hp'.1 0 have hle : p.1 ≤ 1 := by calc p.1 ≤ ∑ i, (cons p.1 p.2) i := by simpa using (Finset.single_le_sum (fun i _ => hp'.1 i) (Finset.mem_univ (0 : Fin (n + 1)))) _ ≤ 1 := hp'.2 exact ⟨h0, hle⟩ have hfiber (t : ℝ) : (∫ w : Fin n → ℝ, S.indicator (fun p : ℝ × (Fin n → ℝ) => p.1 ^ 2) (t, w) ∂volume) = if ht : t ∈ Icc (0 : ℝ) 1 then t ^ 2 * (volume (scaledSpacingSimplex n (1 - t))).toReal else 0 := by split_ifs with ht · have hs : MeasurableSet {w : Fin n → ℝ | (t, w) ∈ S} := hS.preimage measurable_prodMk_left calc _ = ∫ w in {w : Fin n → ℝ | (t, w) ∈ S}, t ^ 2 ∂volume := by rw [← integral_indicator hs] congr 1 _ = t ^ 2 * (volume (scaledSpacingSimplex n (1 - t))).toReal := by rw [setIntegral_const, hsection t ht] simp [measureReal_def, smul_eq_mul, mul_comm] · have hzero : ∀ w : Fin n → ℝ, (t, w) ∉ S := by intro w hw exact ht (hsubset (t, w) hw) simp [indicator, hzero] calc (∫ z in spacingSimplex (n + 1), z 0 ^ 2 ∂volume) = ∫ p in S, p.1 ^ 2 ∂volume := by rw [← hem.map_eq, setIntegral_map_equiv] rfl _ = ∫ p : ℝ × (Fin n → ℝ), S.indicator (fun p : ℝ × (Fin n → ℝ) => p.1 ^ 2) p ∂volume := by rw [integral_indicator hS] _ = ∫ t : ℝ, ∫ w : Fin n → ℝ, S.indicator (fun p : ℝ × (Fin n → ℝ) => p.1 ^ 2) (t, w) ∂volume := by rw [Measure.volume_eq_prod] exact integral_prod _ hprodInt _ = ∫ t in Icc (0 : ℝ) 1, t ^ 2 * (volume (scaledSpacingSimplex n (1 - t))).toReal := by simp_rw [hfiber] rw [← integral_indicator measurableSet_Icc] congr 1 funext t simp [indicator, dite_eq_ite] -
simplex_first_coordinate_square_slicetheorem — Given a finite dimension, the squared first-coordinate simplex integral equals its one-dimensional sliced integral.hypothesesn :ℕconclusion(∫ z in spacingSimplex (n + 1), (z (0 : Fin (n + 1))) ^ 2 ∂volume)= ∫ t in (0 : ℝ)..1, t ^ 2 * ((1 - t) ^ n / (n.factorial : ℝ))Proof (Lean source)
theorem simplex_first_coordinate_square_slice (n : ℕ) : (∫ z in spacingSimplex (n + 1), (z (0 : Fin (n + 1))) ^ 2 ∂volume) = ∫ t in (0 : ℝ)..1, t ^ 2 * ((1 - t) ^ n / (n.factorial : ℝ)) := by rw [simplex_first_coordinate_square_fubini, intervalIntegral.integral_of_le (by norm_num : (0 : ℝ) ≤ 1), ← integral_Icc_eq_integral_Ioc] apply setIntegral_congr_fun measurableSet_Icc intro t ht have hr : 0 ≤ 1 - t := sub_nonneg.mpr ht.2 change t ^ 2 * (volume (scaledSpacingSimplex n (1 - t))).toReal = t ^ 2 * ((1 - t) ^ n / (n.factorial : ℝ)) rw [scaledSpacingSimplex_volume n (1 - t) hr] rw [ENNReal.toReal_ofReal (div_nonneg (pow_nonneg hr n) (by positivity))] -
unit_beta_square_integraltheorem — Given a nonnegative integer exponent, the unit-interval beta-type polynomial integral has the stated factorial value.hypothesesn :ℕconclusion(∫ t in (0 : ℝ)..1, t ^ 2 * (1 - t) ^ n) = 2 * (n.factorial : ℝ) / ((n + 3).factorial : ℝ)Proof (Lean source)
theorem unit_beta_square_integral (n : ℕ) : (∫ t in (0 : ℝ)..1, t ^ 2 * (1 - t) ^ n) = 2 * (n.factorial : ℝ) / ((n + 3).factorial : ℝ) := by have hbeta : (∫ t in (0 : ℝ)..1, ((t ^ 2 * (1 - t) ^ n : ℝ) : ℂ)) = Complex.betaIntegral 3 (n + 1) := by rw [Complex.betaIntegral] apply intervalIntegral.integral_congr intro t ht have ht0 : 0 ≤ t := by simpa using ht.1 have ht1 : t ≤ 1 := by simpa using ht.2 dsimp simp only [Complex.ofReal_mul, Complex.ofReal_cpow ht0, Complex.ofReal_pow, Complex.ofReal_sub, Complex.ofReal_one, Complex.cpow_natCast] norm_num have heval := Complex.betaIntegral_eq_Gamma_mul_div 3 (n + 1) (by norm_num) (by simp; positivity) rw [← hbeta] at heval have hg3 : Complex.Gamma 3 = 2 := by convert Complex.Gamma_nat_eq_factorial 2 using 1 <;> norm_num have hgn : Complex.Gamma (n + 1) = (n.factorial : ℂ) := by simpa using Complex.Gamma_nat_eq_factorial n have hgn3 : Complex.Gamma (3 + (n + 1)) = ((n + 3).factorial : ℂ) := by convert Complex.Gamma_nat_eq_factorial (n + 3) using 1 <;> push_cast <;> ring rw [hg3, hgn, hgn3] at heval rw [intervalIntegral.integral_ofReal] at heval exact Complex.ofReal_inj.mp (by simpa using heval)
CDFTransport 1 core · 3 supporting These lemmas separate continuity, the probability-integral transform, and the interval-mass identity used for density-envelope comparisons. ★ cdf_pushforward_of_continuous
Continuous CDF transport and interval mass
These lemmas separate continuity, the probability-integral transform, and the interval-mass identity used for density-envelope comparisons.
Given a real probability law and continuity of its cumulative distribution function, that CDF pushes the law forward to the unit-uniform law.
Formal statement
Proof (Lean source)
3 supporting declarations (lemmas, instances)
-
cdf_continuous_of_withDensitytheorem — Given a real probability law, a real density, and an equality representing the law by that density, its cumulative distribution function is continuous.hypothesesconclusionContinuous (fun x => cdf μ x)Proof (Lean source)
theorem cdf_continuous_of_withDensity (μ : Measure ℝ) [IsProbabilityMeasure μ] (p : ℝ → ℝ) (hμ : μ = volume.withDensity (fun x => ofReal (p x))) : Continuous (fun x => cdf μ x) := by haveI : NullSingletonClass μ := hμ ▸ inferInstance exact cdf_continuous_of_noAtoms μ -
cdf_increment_eq_interval_masstheorem — Given a real probability law and ordered endpoints, its CDF increment equals the interval's real-valued probability mass.hypothesesProof (Lean source)
theorem cdf_increment_eq_interval_mass (μ : Measure ℝ) [IsProbabilityMeasure μ] {x y : ℝ} (hxy : x ≤ y) : cdf μ y - cdf μ x = μ.real (Ioc x y) := by rw [ProbabilityTheory.cdf_eq_real, ProbabilityTheory.cdf_eq_real] have hdisj : Disjoint (Iic x) (Ioc x y) := by rw [Set.disjoint_left] intro z hz hz' exact (not_lt_of_ge hz) hz'.1 have hunion : Iic x ∪ Ioc x y = Iic y := by ext z simp only [Set.mem_union, Set.mem_Iic, Set.mem_Ioc] constructor · rintro (hz | ⟨_, hz⟩) · exact hz.trans hxy · exact hz · intro hz exact le_or_gt z x |>.elim (fun h => inl h) (fun h => inr ⟨h, hz⟩) have hadd := measureReal_union hdisj measurableSet_Ioc (μ := μ) (s₁ := Iic x) (s₂ := Ioc x y) rw [hunion] at hadd linarith -
sortedSample_map_monotonetheorem — Given a sample size, a monotone real transformation, and a real tuple, sorting after transformation equals transforming the sorted tuple.hypothesesconclusionsortedSample n (fun i => f (x i)) = fun i => f (sortedSample n x i)Proof (Lean source)
theorem sortedSample_map_monotone (n : ℕ) (f : ℝ → ℝ) (hf : Monotone f) (x : Fin n → ℝ) : sortedSample n (fun i => f (x i)) = fun i => f (sortedSample n x i) := by unfold sortedSample have hmono : Monotone ((fun j : Fin n => f (x j)) ∘ sort x) := hf.comp (Tuple.monotone_sort x) exact ((Tuple.comp_sort_eq_comp_iff_monotone (f := fun j : Fin n => f (x j)) (σ := sort x)).2 hmono).symm
Comparison 1 core · 9 supporting A real distribution with density bounded above and below on its support has a CDF that transports it to the unit uniform law and compares its sorted gaps with uniform sorted gaps. ★ real_alternating_gap_second_moment_bounds
Density-envelope comparison for iid real spacings
A real distribution with density bounded above and below on its support has a CDF that transports it to the unit uniform law and compares its sorted gaps with uniform sorted gaps. The resulting bounds apply to individual gaps and to the alternating sum.
Given a real probability law, interval endpoints, density constants and their order, a density, its density representation, support in that interval, an almost-everywhere density envelope, a sample size, and proof that it is even, the expected sum of squares of every other sorted gap (the gaps between the order statistics of ranks 2j+1 and 2j+2, over all n/2 such pairs) lies between n/((n+1)(n+2)) divided by the squared upper density constant and n/((n+1)(n+2)) divided by the squared lower density constant.
Formal statement
Proof (Lean source)
9 supporting declarations (lemmas, instances)
-
cdf_pushforward_uniform01theorem — Given a real probability law, a density, and its density representation, its CDF pushes the law forward to the unit-uniform law.hypothesesProof (Lean source)
theorem cdf_pushforward_uniform01 (μ : Measure ℝ) [IsProbabilityMeasure μ] (p : ℝ → ℝ) (hμ : μ = volume.withDensity (fun x => ofReal (p x))) : μ.map (fun x => cdf μ x) = uniform01 := by exact cdf_pushforward_of_continuous μ (cdf_continuous_of_withDensity μ p hμ) -
cdf_increment_boundstheorem — Given a real probability law, interval endpoints, density constants and their order, a density, its density representation, an almost-everywhere density envelope, and two ordered points inside it, the CDF increment lies between the density constants times their distance.hypothesesProof (Lean source)
theorem cdf_increment_bounds (μ : Measure ℝ) [IsProbabilityMeasure μ] (a b cg Cg : ℝ) (p : ℝ → ℝ) (hcg : 0 < cg) (hCg : cg ≤ Cg) (hμ : μ = volume.withDensity (fun x => ofReal (p x))) (hbound : ∀ᵐ x ∂(volume.restrict (Icc a b)), cg ≤ p x ∧ p x ≤ Cg) {x y : ℝ} (hax : a ≤ x) (hxy : x ≤ y) (hyb : y ≤ b) : cg * (y - x) ≤ cdf μ y - cdf μ x ∧ cdf μ y - cdf μ x ≤ Cg * (y - x) := by rw [cdf_increment_eq_interval_mass μ hxy] exact withDensity_interval_mass_bounds μ a b cg Cg p hcg hCg hμ hbound hax hxy hyb -
iid_cdf_pushforward_uniform01theorem — Given a real probability law, a density, its density representation, and a sample size, coordinatewise CDF transformation sends the iid sample law to the iid unit-uniform law.hypothesesProof (Lean source)
theorem iid_cdf_pushforward_uniform01 (μ : Measure ℝ) [IsProbabilityMeasure μ] (p : ℝ → ℝ) (hμ : μ = volume.withDensity (fun x => ofReal (p x))) (n : ℕ) : (iidSample μ n).map (fun x i => cdf μ (x i)) = iidSample uniform01 n := by have hc := cdf_continuous_of_withDensity μ p hμ have hmap := cdf_pushforward_uniform01 μ p hμ haveI : IsProbabilityMeasure (μ.map (fun x => cdf μ x)) := Measure.isProbabilityMeasure_map hc.measurable.aemeasurable change (Measure.pi (fun _ : Fin n => μ)).map (fun x i => cdf μ (x i)) = Measure.pi (fun _ : Fin n => uniform01) rw [Measure.pi_map_pi (fun _ : Fin n => hc.measurable.aemeasurable)] simp only [hmap] -
iid_support_interval_aetheorem — Given a real probability law, interval endpoints, support in that interval, and a sample size, every iid sample coordinate lies in that interval almost surely.hypothesesconclusion∀ᵐ x ∂iidSample μ n, ∀ i, x i ∈ Icc a bProof (Lean source)
theorem iid_support_interval_ae (μ : Measure ℝ) [IsProbabilityMeasure μ] (a b : ℝ) (hsupp : μ (Icc a b)ᶜ = 0) (n : ℕ) : ∀ᵐ x ∂iidSample μ n, ∀ i, x i ∈ Icc a b := by have hcoord : ∀ᵐ y ∂μ, y ∈ Icc a b := mem_ae_iff.mpr hsupp change ∀ᵐ x ∂Measure.pi (fun _ : Fin n => μ), ∀ i, x i ∈ Icc a b exact Filter.eventually_all.mpr (fun i => Measure.tendsto_eval_ae_ae.eventually hcoord) -
sortedGap_square_integrable_of_interval_supporttheorem — Given a real probability law, interval endpoints, support in that interval, a sample size and adjacent-gap index, and proof that the gap is interior, the squared sorted gap is integrable.hypothesesconclusionProof (Lean source)
theorem sortedGap_square_integrable_of_interval_support (μ : Measure ℝ) [IsProbabilityMeasure μ] (a b : ℝ) (hsupp : μ (Icc a b)ᶜ = 0) (n k : ℕ) (hk : k + 1 < n) : Integrable (fun x => (sortedGap n k x) ^ 2) (iidSample μ n) := by classical let lo : Fin n := ⟨k, by omega⟩ let hi : Fin n := ⟨k + 1, hk⟩ have hsort : AEMeasurable (sortedSample n) (iidSample μ n) := by let s (σ : Perm (Fin n)) : Set (Fin n → ℝ) := {x | Monotone (x ∘ σ)} have hs (σ : Perm (Fin n)) : MeasurableSet (s σ) := by have hc : Continuous (fun x : Fin n → ℝ => x ∘ σ) := by fun_prop exact (isClosed_monotone.preimage hc).measurableSet have hcover : (⋃ σ, s σ) = univ := by ext x simp only [Set.mem_iUnion, Set.mem_univ, iff_true] exact ⟨Tuple.sort x, Tuple.monotone_sort x⟩ have hpiece (σ : Perm (Fin n)) : AEMeasurable (sortedSample n) ((iidSample μ n).restrict (s σ)) := by have hp : Measurable (fun x : Fin n → ℝ => x ∘ σ) := by fun_prop apply hp.aemeasurable.congr exact ae_restrict_of_forall_mem (hs σ) (fun x hx => (show (fun x => x ∘ σ) x = sortedSample n x from (Tuple.comp_sort_eq_comp_iff_monotone (f := x) (σ := σ)).2 hx)) simpa only [hcover, Measure.restrict_univ] using (AEMeasurable.iUnion hpiece) have hmeas : AEStronglyMeasurable (fun x => (sortedGap n k x) ^ 2) (iidSample μ n) := by have hp : Measurable (fun y : Fin n → ℝ => (y hi - y lo) ^ 2) := by fun_prop have h := hp.aestronglyMeasurable.comp_aemeasurable hsort convert h using 1 funext x simp [sortedGap, hk, sortedSample, lo, hi] have hfinite : (iidSample μ n) univ ≠ ⊤ := by simp [iidSample] have hbound : ∀ᵐ x ∂iidSample μ n, ‖(sortedGap n k x) ^ 2‖ ≤ (b - a) ^ 2 := by filter_upwards [iid_support_interval_ae μ a b hsupp n] with x hx have hmono : sortedSample n x lo ≤ sortedSample n x hi := (Tuple.monotone_sort x) (by simp [lo, hi, Fin.le_def]) have hlo : a ≤ sortedSample n x lo := (hx (sort x lo)).1 have hhi : sortedSample n x hi ≤ b := (hx (sort x hi)).2 have hgap : sortedGap n k x = sortedSample n x hi - sortedSample n x lo := by simp [sortedGap, hk, lo, hi] have hg0 : 0 ≤ sortedGap n k x := by rw [hgap]; linarith have hgle : sortedGap n k x ≤ b - a := by rw [hgap]; linarith rw [Real.norm_eq_abs, abs_of_nonneg (sq_nonneg _)] exact (sq_le_sq₀ hg0 (by linarith)).2 hgle exact integrableOn_univ.mp (Measure.integrableOn_of_bounded hfinite hmeas (by simpa only [Measure.restrict_univ] using hbound) : IntegrableOn (fun x => (sortedGap n k x) ^ 2) univ (iidSample μ n)) -
sortedGap_cdf_linear_boundstheorem — Given a real probability law, interval endpoints, density constants and their order, a density, its density representation, an almost-everywhere density envelope, a sample size and adjacent-gap index, proof that the gap is interior, a real sample, and coordinatewise interval membership, the sorted CDF gap lies between the density constants times the original gap.hypothesesProof (Lean source)
theorem sortedGap_cdf_linear_bounds (μ : Measure ℝ) [IsProbabilityMeasure μ] (a b cg Cg : ℝ) (p : ℝ → ℝ) (hcg : 0 < cg) (hCg : cg ≤ Cg) (hμ : μ = volume.withDensity (fun x => ofReal (p x))) (hbound : ∀ᵐ x ∂(volume.restrict (Icc a b)), cg ≤ p x ∧ p x ≤ Cg) (n k : ℕ) (hk : k + 1 < n) (x : Fin n → ℝ) (hx : ∀ i, x i ∈ Icc a b) : cg * sortedGap n k x ≤ sortedGap n k (fun i => cdf μ (x i)) ∧ sortedGap n k (fun i => cdf μ (x i)) ≤ Cg * sortedGap n k x := by let lo : Fin n := ⟨k, by omega⟩ let hi : Fin n := ⟨k + 1, hk⟩ have hxy : sortedSample n x lo ≤ sortedSample n x hi := (Tuple.monotone_sort x) (by simp [lo, hi, Fin.le_def]) have hax : a ≤ sortedSample n x lo := (hx (sort x lo)).1 have hyb : sortedSample n x hi ≤ b := (hx (sort x hi)).2 have hinc := cdf_increment_bounds μ a b cg Cg p hcg hCg hμ hbound hax hxy hyb have hsort := sortedSample_map_monotone n (fun z => cdf μ z) (ProbabilityTheory.monotone_cdf μ) x simpa only [sortedGap, dif_pos hk, lo, hi, hsort] using hinc -
sortedGap_cdf_square_boundstheorem — Given a real probability law, interval endpoints, density constants and their order, a density, its density representation, an almost-everywhere density envelope, a sample size and adjacent-gap index, proof that the gap is interior, a real sample, and coordinatewise interval membership, the squared sorted CDF gap lies between squared density multiples of the original gap.hypothesesProof (Lean source)
theorem sortedGap_cdf_square_bounds (μ : Measure ℝ) [IsProbabilityMeasure μ] (a b cg Cg : ℝ) (p : ℝ → ℝ) (hcg : 0 < cg) (hCg : cg ≤ Cg) (hμ : μ = volume.withDensity (fun x => ofReal (p x))) (hbound : ∀ᵐ x ∂(volume.restrict (Icc a b)), cg ≤ p x ∧ p x ≤ Cg) (n k : ℕ) (hk : k + 1 < n) (x : Fin n → ℝ) (hx : ∀ i, x i ∈ Icc a b) : cg ^ 2 * (sortedGap n k x) ^ 2 ≤ (sortedGap n k (fun i => cdf μ (x i))) ^ 2 ∧ (sortedGap n k (fun i => cdf μ (x i))) ^ 2 ≤ Cg ^ 2 * (sortedGap n k x) ^ 2 := by have hmono := Tuple.monotone_sort x have hg0 : 0 ≤ sortedGap n k x := by simp only [sortedGap, dif_pos hk] exact sub_nonneg.mpr (hmono (by simp [Fin.le_def])) have hlin := sortedGap_cdf_linear_bounds μ a b cg Cg p hcg hCg hμ hbound n k hk x hx have hcg0 : 0 ≤ cg * sortedGap n k x := mul_nonneg hcg.le hg0 have hCg0 : 0 ≤ Cg * sortedGap n k x := mul_nonneg (le_trans hcg.le hCg) hg0 have hfg0 : 0 ≤ sortedGap n k (fun i => cdf μ (x i)) := le_trans hcg0 hlin.1 have hlow := (sq_le_sq₀ hcg0 hfg0).2 hlin.1 have hupp := (sq_le_sq₀ hfg0 hCg0).2 hlin.2 constructor <;> nlinarith [hlow, hupp] -
cdf_transformed_gap_second_momenttheorem — Given a real probability law, a sample size and adjacent-gap index, proof that the gap is interior, a continuous CDF, and its coordinatewise iid pushforward identity, the transformed squared sorted gap has the exact unit-uniform second moment.hypothesesProof (Lean source)
theorem cdf_transformed_gap_second_moment (μ : Measure ℝ) [IsProbabilityMeasure μ] (n k : ℕ) (hk : k + 1 < n) (hcont : Continuous (cdf μ)) (hmap : (iidSample μ n).map (fun x i => cdf μ (x i)) = iidSample uniform01 n) : ∫ x, (sortedGap n k (fun i => cdf μ (x i))) ^ 2 ∂iidSample μ n = (2 : ℝ) / ((n + 1 : ℕ) * (n + 2 : ℕ)) := by -- Use integral_map for the coordinatewise CDF. The gap function is -- a.e. strongly measurable under the uniform product law because it is -- integrable there; the uniform law lives on the unit cube. have hmeas : Measurable (fun x : Fin n → ℝ => fun i => cdf μ (x i)) := measurable_pi_lambda _ fun i => hcont.measurable.comp (measurable_pi_apply i) have hstrong : AEStronglyMeasurable (fun x => (sortedGap n k x) ^ 2) (iidSample uniform01 n) := (uniform_gap_square_integrable n k hk).aestronglyMeasurable rw [← hmap] at hstrong rw [← integral_map hmeas.aemeasurable hstrong, hmap] exact uniform_gap_second_moment n k hk -
real_gap_second_moment_boundstheorem — Given a real probability law, interval endpoints, density constants and their order, a density, its density representation, support in that interval, an almost-everywhere density envelope, a sample size and adjacent-gap index, and proof that the gap is interior, the squared sorted-gap moment lies between the inverse squared density bounds times the uniform moment.hypothesesProof (Lean source)
theorem real_gap_second_moment_bounds (μ : Measure ℝ) [IsProbabilityMeasure μ] (a b cg Cg : ℝ) (p : ℝ → ℝ) (hcg : 0 < cg) (hCg : cg ≤ Cg) (hμ : μ = volume.withDensity (fun x => ofReal (p x))) (hsupp : μ (Icc a b)ᶜ = 0) (hbound : ∀ᵐ x ∂(volume.restrict (Icc a b)), cg ≤ p x ∧ p x ≤ Cg) (n k : ℕ) (hk : k + 1 < n) : (1 / Cg ^ 2) * ((2 : ℝ) / ((n + 1 : ℕ) * (n + 2 : ℕ))) ≤ ∫ x, (sortedGap n k x) ^ 2 ∂iidSample μ n ∧ (∫ x, (sortedGap n k x) ^ 2 ∂iidSample μ n) ≤ (1 / cg ^ 2) * ((2 : ℝ) / ((n + 1 : ℕ) * (n + 2 : ℕ))) := by let F : (Fin n → ℝ) → (Fin n → ℝ) := fun x i => cdf μ (x i) have hcont := cdf_continuous_of_withDensity μ p hμ have hmap := iid_cdf_pushforward_uniform01 μ p hμ n have hmeas : Measurable F := measurable_pi_lambda _ fun i => hcont.measurable.comp (measurable_pi_apply i) have horig : Integrable (fun x => (sortedGap n k x) ^ 2) (iidSample μ n) := sortedGap_square_integrable_of_interval_support μ a b hsupp n k hk have htrans : Integrable (fun x => (sortedGap n k (F x)) ^ 2) (iidSample μ n) := by have hu := uniform_gap_square_integrable n k hk rw [← hmap] at hu simpa only [Function.comp_def] using hu.comp_measurable hmeas have hpoint : ∀ᵐ x ∂iidSample μ n, cg ^ 2 * (sortedGap n k x) ^ 2 ≤ (sortedGap n k (F x)) ^ 2 ∧ (sortedGap n k (F x)) ^ 2 ≤ Cg ^ 2 * (sortedGap n k x) ^ 2 := by filter_upwards [iid_support_interval_ae μ a b hsupp n] with x hx exact sortedGap_cdf_square_bounds μ a b cg Cg p hcg hCg hμ hbound n k hk x hx have hlow : cg ^ 2 * (∫ x, (sortedGap n k x) ^ 2 ∂iidSample μ n) ≤ ∫ x, (sortedGap n k (F x)) ^ 2 ∂iidSample μ n := by rw [← integral_const_mul] exact integral_mono_ae (horig.const_mul _) htrans (hpoint.mono fun x hx => hx.1) have hupp : (∫ x, (sortedGap n k (F x)) ^ 2 ∂iidSample μ n) ≤ Cg ^ 2 * (∫ x, (sortedGap n k x) ^ 2 ∂iidSample μ n) := by rw [← integral_const_mul] exact integral_mono_ae htrans (horig.const_mul _) (hpoint.mono fun x hx => hx.2) have hmoment := cdf_transformed_gap_second_moment μ n k hk hcont hmap change (∫ x, (sortedGap n k (F x)) ^ 2 ∂iidSample μ n) = _ at hmoment rw [hmoment] at hlow hupp have hcg2 : 0 < cg ^ 2 := sq_pos_of_pos hcg have hCg2 : 0 < Cg ^ 2 := sq_pos_of_pos (lt_of_lt_of_le hcg hCg) constructor · have h : ((2 : ℝ) / ((n + 1 : ℕ) * (n + 2 : ℕ))) / Cg ^ 2 ≤ ∫ x, (sortedGap n k x) ^ 2 ∂iidSample μ n := (div_le_iff₀ hCg2).2 (by simpa only [mul_comm] using hupp) simpa only [one_div, div_eq_mul_inv, mul_comm, one_mul, mul_one] using h · have h : (∫ x, (sortedGap n k x) ^ 2 ∂iidSample μ n) ≤ ((2 : ℝ) / ((n + 1 : ℕ) * (n + 2 : ℕ))) / cg ^ 2 := (le_div_iff₀ hcg2).2 (by simpa only [mul_comm] using hlow) simpa only [one_div, div_eq_mul_inv, mul_comm, one_mul, mul_one] using h
DensityEnvelope 1 core · 0 supporting An almost-everywhere density envelope on a closed interval bounds the mass of each subinterval by its length. ★ withDensity_interval_mass_bounds
Interval masses under a bounded density
An almost-everywhere density envelope on a closed interval bounds the mass of each subinterval by its length. This is the measure-theoretic input to CDF and order-spacing comparisons.
Given a real probability law, interval endpoints, positive lower and upper density constants, a density, its density representation, an almost-everywhere density envelope on the interval, and a subinterval specified by its endpoint bounds, that subinterval's mass lies between the two density constants times its length.
Formal statement
Proof (Lean source)
Moments 1 core · 3 supporting The adjacent interior gaps of an iid unit-uniform sample have a common exact second moment. ★ uniform_alternating_gap_second_moment
Exact moments of uniform order-statistic spacings
The adjacent interior gaps of an iid unit-uniform sample have a common exact second moment. Summing every other gap gives the finite even-sample identity.
Given a finite sample size and proof that it is even, the expected sum of squares of every other sorted gap of an iid unit-uniform sample (the gaps between the order statistics of ranks 2j+1 and 2j+2, over all n/2 such pairs) equals n/((n+1)(n+2)).
Formal statement
Proof (Lean source)
3 supporting declarations (lemmas, instances)
-
simplex_coordinate_second_momenttheorem — Given a finite dimension and a coordinate index, the factorial-scaled second moment of that simplex coordinate has the stated exact value.hypothesesn :ℕi :Fin nconclusion(n.factorial : ℝ) * (∫ z in spacingSimplex n, (z i) ^ 2 ∂volume)= (2 : ℝ) / ((n + 1 : ℕ) * (n + 2 : ℕ))Proof (Lean source)
theorem simplex_coordinate_second_moment (n : ℕ) (i : Fin n) : (n.factorial : ℝ) * (∫ z in spacingSimplex n, (z i) ^ 2 ∂volume) = (2 : ℝ) / ((n + 1 : ℕ) * (n + 2 : ℕ)) := by cases n with | zero => exact elim0 i | succ m => rw [simplex_coordinate_square_eq_first] change (m + 1).factorial * (∫ z in spacingSimplex (m + 1), (z (0 : Fin (m + 1))) ^ 2 ∂volume) = _ rw [simplex_first_coordinate_square_slice] have hfactorial : (m + 1).factorial = (m + 1) * m.factorial := Nat.factorial_succ m simp_rw [← mul_div_assoc] rw [intervalIntegral.integral_div] rw [unit_beta_square_integral] norm_num [hfactorial, Nat.factorial_succ] have hm : (m.factorial : ℝ) ≠ 0 := by positivity field_simp ring -
uniform_gap_second_momenttheorem — Given a finite sample size, an adjacent-gap index, and proof that the gap is interior, the squared sorted unit-uniform gap has the stated exact second moment.hypothesesn k :ℕhk :k + 1 < nProof (Lean source)
theorem uniform_gap_second_moment (n k : ℕ) (hk : k + 1 < n) : ∫ x, (sortedGap n k x) ^ 2 ∂iidSample uniform01 n = (2 : ℝ) / ((n + 1 : ℕ) * (n + 2 : ℕ)) := by have hfirst := firstNSpacings_aemeasurable n let i : Fin n := ⟨k + 1, hk⟩ have hgap (x : Fin n → ℝ) : sortedGap n k x = firstNSpacings n x i := by simp [sortedGap, firstNSpacings, i, hk] calc (∫ x, (sortedGap n k x) ^ 2 ∂iidSample uniform01 n) = ∫ z, (z i) ^ 2 ∂(iidSample uniform01 n).map (firstNSpacings n) := by rw [integral_map hfirst ((measurable_pi_apply i).pow_const 2).aestronglyMeasurable] simp only [hgap] _ = (n.factorial : ℝ) * (∫ z in spacingSimplex n, (z i) ^ 2 ∂volume) := by rw [uniform_firstN_spacings_law, integral_smul_measure] simp _ = _ := simplex_coordinate_second_moment n i -
uniform_gap_square_integrabletheorem — Given a finite sample size, an adjacent-gap index, and proof that the gap is interior, the squared sorted unit-uniform gap is integrable.hypothesesn k :ℕhk :k + 1 < nconclusionProof (Lean source)
theorem uniform_gap_square_integrable (n k : ℕ) (hk : k + 1 < n) : Integrable (fun x => (sortedGap n k x) ^ 2) (iidSample uniform01 n) := by let i : Fin n := ⟨k + 1, hk⟩ have hgap (x : Fin n → ℝ) : sortedGap n k x = firstNSpacings n x i := by simp [sortedGap, firstNSpacings, i, hk] have hmeas : AEStronglyMeasurable (fun x => (sortedGap n k x) ^ 2) (iidSample uniform01 n) := by have h := ((measurable_pi_apply i).pow_const 2).aestronglyMeasurable.comp_aemeasurable (firstNSpacings_aemeasurable n) convert h using 1 funext x simp [hgap] have hfinite : (iidSample uniform01 n) univ ≠ ⊤ := by have : IsProbabilityMeasure uniform01 := ⟨by simp [uniform01]⟩ simp [iidSample] have hcube : MeasurableSet (unitCube n) := by change MeasurableSet {x : Fin n → ℝ | ∀ i, x i ∈ Icc (0 : ℝ) 1} have heq : {x : Fin n → ℝ | ∀ i, x i ∈ Icc (0 : ℝ) 1} = ⋂ i : Fin n, (fun x : Fin n → ℝ => x i) ⁻¹' Icc 0 1 := by ext x simp rw [heq] exact MeasurableSet.iInter (fun i => measurableSet_Icc.preimage (measurable_pi_apply i)) have hbound : ∀ᵐ x ∂iidSample uniform01 n, ‖(sortedGap n k x) ^ 2‖ ≤ (1 : ℝ) := by rw [iid_uniform_cube_law] apply ae_restrict_of_forall_mem hcube intro x hx have hmono : Monotone (sortedSample n x) := Tuple.monotone_sort x have h0 : 0 ≤ sortedSample n x ⟨k, by omega⟩ := (hx (sort x ⟨k, by omega⟩)).1 have h1 : sortedSample n x i ≤ 1 := (hx (sort x i)).2 have hle : sortedSample n x ⟨k, by omega⟩ ≤ sortedSample n x i := hmono (by simp [i, Fin.le_def]) have hgap' : sortedGap n k x = sortedSample n x i - sortedSample n x ⟨k, by omega⟩ := by simp [sortedGap, hk, i] have hb : 0 ≤ sortedGap n k x ∧ sortedGap n k x ≤ 1 := by rw [hgap'] constructor <;> linarith rw [Real.norm_eq_abs, abs_of_nonneg (sq_nonneg _)] nlinarith exact integrableOn_univ.mp (Measure.integrableOn_of_bounded hfinite hmeas (by simpa only [Measure.restrict_univ] using hbound) : IntegrableOn (fun x => (sortedGap n k x) ^ 2) univ (iidSample uniform01 n))