Stat.Order­Statistic

Exact distribution theory for the order statistics of n i.i.d.

Weighted­Concomitant 25 core · 71 supporting · 17 submodules Finite-sample theory of the statistic ∑ⱼ aⱼ Y₍ⱼ₎, where the marks Y are sorted by a continuously distributed coordinate and aⱼ are fixed cell weights.
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.

def uniform01 reviewed
Causalean.Stat.OrderStatistic

The unit-uniform probability measure is Lebesgue measure restricted to the closed unit interval.

Definition (Lean source)
uniform01 :
volume.restrict (Icc 0 1)
Causalean.Stat.OrderStatistic.uniform01 · Causalean/Stat/OrderStatistic/Basic.lean:20
def iidSample reviewed
Causalean.Stat.OrderStatistic

Given a real sampling law and a finite sample size, the iid sample law is the corresponding finite product measure.

Definition (Lean source)
μ :
n :
ℕ
iidSample μ n :
Measure (Fin n → ℝ)
Measure.pi fun _ : Fin n => μ
Causalean.Stat.OrderStatistic.iidSample · Causalean/Stat/OrderStatistic/Basic.lean:23
def sortedSample reviewed
Causalean.Stat.OrderStatistic

Given a finite sample size and a real tuple, the sorted sample is that tuple rearranged in nondecreasing order.

Definition (Lean source)
n :
ℕ
x :
Fin n → ℝ
sortedSample n x :
Fin n → ℝ
x ∘ sort x
Causalean.Stat.OrderStatistic.sortedSample · Causalean/Stat/OrderStatistic/Basic.lean:27
def orderedUnitRegion reviewed
Causalean.Stat.OrderStatistic

Given a finite dimension, the ordered unit region is the nondecreasing part of the closed unit cube.

Definition (Lean source)
n :
ℕ
orderedUnitRegion n :
Set (Fin n → ℝ)
{x | (∀ i, x i ∈ Icc (0 : ℝ) 1) ∧ Monotone x}
Causalean.Stat.OrderStatistic.orderedUnitRegion · Causalean/Stat/OrderStatistic/Basic.lean:31
def unitCube reviewed
Causalean.Stat.OrderStatistic

Given a finite dimension, the unit cube is the set of real tuples with every coordinate in the closed unit interval.

Definition (Lean source)
n :
ℕ
unitCube n :
Set (Fin n → ℝ)
{x | ∀ i, x i ∈ Icc (0 : ℝ) 1}
Causalean.Stat.OrderStatistic.unitCube · Causalean/Stat/OrderStatistic/Basic.lean:35
def sortedGap reviewed
Causalean.Stat.OrderStatistic

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)
n k :
ℕ
x :
Fin n → ℝ
sortedGap n k x :
ℝ
if h : k + 1 < n then sortedSample n x ⟨k + 1, h⟩ - sortedSample n x ⟨k, by omega⟩ else 0
Causalean.Stat.OrderStatistic.sortedGap · Causalean/Stat/OrderStatistic/Basic.lean:39
theorem sorted_uniform_law reviewed
Causalean.Stat.OrderStatistic

Given a finite sample size, the sorted iid unit-uniform sample has factorial density on the ordered unit region.

Formal statement
n :
ℕ
= (n.factorial : ENNReal) • (volume.restrict (orderedUnitRegion n))
Proof (Lean source)
theorem sorted_uniform_law (n : ℕ) : (iidSample uniform01 n).map (sortedSample n) = (n.factorial : ENNReal) • (volume.restrict (orderedUnitRegion n)) := by rw [iid_uniform_cube_law] exact sorted_cube_law n
2 supporting declarations (lemmas, instances)
  • iid_uniform_cube_law theorem — Given a finite sample size, the iid unit-uniform product law is Lebesgue measure restricted to the unit cube.
    n :
    ℕ
    iidSample uniform01 n = volume.restrict (unitCube n)
    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]
    Causalean.Stat.OrderStatistic.iid_uniform_cube_law · Causalean/Stat/OrderStatistic/Basic.lean:45
  • sorted_cube_law theorem — Given a finite dimension, sorting Lebesgue measure on the unit cube yields factorial density on the ordered chamber.
    n :
    ℕ
    (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]
    Causalean.Stat.OrderStatistic.sorted_cube_law · Causalean/Stat/OrderStatistic/Basic.lean:185
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.

def orderedSpacings reviewed
Causalean.Stat.OrderStatistic

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.

Definition (Lean source)
n :
ℕ
y :
Fin n → ℝ
i :
Fin n
orderedSpacings n y i :
ℝ
if i.val = 0 then y i else y i - y ⟨i.val - 1, by omega⟩
Causalean.Stat.OrderStatistic.orderedSpacings · Causalean/Stat/OrderStatistic/Dirichlet.lean:21
def prefixCoordinates reviewed
Causalean.Stat.OrderStatistic

Given a finite dimension, a spacing vector, and a coordinate index, the prefix coordinate is the sum of spacings through that coordinate.

Definition (Lean source)
n :
ℕ
z :
Fin n → ℝ
i :
Fin n
prefixCoordinates n z i :
ℝ
∑ j ∈ Iic i, z j
Causalean.Stat.OrderStatistic.prefixCoordinates · Causalean/Stat/OrderStatistic/Dirichlet.lean:25
def firstNSpacings reviewed
Causalean.Stat.OrderStatistic

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)
n :
ℕ
x :
Fin n → ℝ
i :
Fin n
firstNSpacings n x i :
ℝ
if i.val
= 0 then sortedSample n x i else sortedSample n x i
- sortedSample n x ⟨i.val
- 1, by omega⟩
Causalean.Stat.OrderStatistic.firstNSpacings · Causalean/Stat/OrderStatistic/Dirichlet.lean:29
def spacingSimplex reviewed
Causalean.Stat.OrderStatistic

Given a finite dimension, the spacing simplex is the nonnegative coordinate simplex with total at most one.

Definition (Lean source)
n :
ℕ
spacingSimplex n :
Set (Fin n → ℝ)
{z | (∀ i, 0 ≤ z i) ∧ (∑ i, z i) ≤ 1}
Causalean.Stat.OrderStatistic.spacingSimplex · Causalean/Stat/OrderStatistic/Dirichlet.lean:34
def orderedSpacingsLinear reviewed
Causalean.Stat.OrderStatistic

Given a finite dimension, the linear spacing transformation is the linear map of successive coordinate differences.

Definition (Lean source)
n :
ℕ
orderedSpacingsLinear n :
(Fin n → ℝ) →ₗ[ℝ] (Fin n → ℝ)
LinearMap.pi fun i : Fin n
=> if h : i.val = 0 then (LinearMap.proj i : (Fin n → ℝ) →ₗ[ℝ] ℝ) else (LinearMap.proj i : (Fin n → ℝ) →ₗ[ℝ] ℝ)
- LinearMap.proj (⟨i.val - 1, by omega⟩ : Fin n)
Causalean.Stat.OrderStatistic.orderedSpacingsLinear · Causalean/Stat/OrderStatistic/Dirichlet.lean:135
theorem uniform_firstN_spacings_law reviewed
Causalean.Stat.OrderStatistic

Given a finite sample size, the first spacing vector of an iid unit-uniform sample has factorial density on the spacing simplex.

Formal statement
n :
ℕ
= (n.factorial : ENNReal) • (volume.restrict (spacingSimplex n))
Proof (Lean source)
theorem uniform_firstN_spacings_law (n : ℕ) : (iidSample uniform01 n).map (firstNSpacings n) = (n.factorial : ENNReal) • (volume.restrict (spacingSimplex n)) := by 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 hfun : firstNSpacings n = orderedSpacings n ∘ sortedSample n := by funext x exact firstNSpacings_eq_orderedSpacings n x rw [hfun] rw [← AEMeasurable.map_map_of_aemeasurable (hspacing.aemeasurable : AEMeasurable (orderedSpacings n) ((iidSample uniform01 n).map (sortedSample n))) hsort'] rw [sorted_uniform_law n, Measure.map_smul, orderedSpacings_restrict_law]
Causalean.Stat.OrderStatistic.uniform_firstN_spacings_law · Causalean/Stat/OrderStatistic/Dirichlet.lean:231 · uses firstNSpacings , iidSample , spacingSimplex , uniform01
8 supporting declarations (lemmas, instances)
Simplex­Integrals 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.

def scaledSpacingSimplex reviewed
Causalean.Stat.OrderStatistic

Given a finite dimension and a real radius, the scaled spacing simplex is the nonnegative coordinate simplex with total at most that radius.

Definition (Lean source)
n :
ℕ
r :
ℝ
scaledSpacingSimplex n r :
Set (Fin n → ℝ)
{z | (∀ i, 0 ≤ z i) ∧ (∑ i, z i) ≤ r}
Causalean.Stat.OrderStatistic.scaledSpacingSimplex · Causalean/Stat/OrderStatistic/SimplexIntegrals.lean:20
theorem simplex_coordinate_square_eq_first reviewed
Causalean.Stat.OrderStatistic

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
n :
ℕ
i :
Fin n
(∫ z in spacingSimplex n, (z i) ^ 2 ∂volume)
= ∫ z in spacingSimplex n, (z (⟨0, by have := i.isLt; omega⟩ : Fin n)) ^ 2 ∂volume
Proof (Lean source)
theorem simplex_coordinate_square_eq_first (n : ℕ) (i : Fin n) : (∫ z in spacingSimplex n, (z i) ^ 2 ∂volume) = ∫ z in spacingSimplex n, (z (⟨0, by have := i.isLt; omega⟩ : Fin n)) ^ 2 ∂volume := by classical let j : Fin n := ⟨0, by have := i.isLt; omega⟩ let σ : Perm (Fin n) := Equiv.swap i j let e : (Fin n → ℝ) ≃ᵐ (Fin n → ℝ) := MeasurableEquiv.piCongrLeft (fun _ : Fin n => ℝ) σ.symm have he : MeasurePreserving e volume volume := volume_measurePreserving_piCongrLeft (fun _ : Fin n => ℝ) σ.symm have hfun (z : Fin n → ℝ) : e z = z ∘ σ := by funext k simp [e, MeasurableEquiv.coe_piCongrLeft, Equiv.piCongrLeft_apply] have hpre : e ⁻¹' spacingSimplex n = spacingSimplex n := by ext z simp only [Set.mem_preimage, spacingSimplex, Set.mem_ofPred_eq] rw [hfun] have hsum : (∑ k, z (σ k)) = ∑ k, z k := Equiv.sum_comp σ z constructor · rintro ⟨hp, hs⟩ exact ⟨fun k => by simpa using hp (σ.symm k), by simpa [hsum] using hs⟩ · rintro ⟨hp, hs⟩ exact ⟨fun k => hp (σ k), by simpa [hsum] using hs⟩ have hmp : MeasurePreserving e (volume.restrict (spacingSimplex n)) (volume.restrict (spacingSimplex n)) := by refine ⟨e.measurable, ?_⟩ calc (volume.restrict (spacingSimplex n)).map e = (volume.restrict (e ⁻¹' spacingSimplex n)).map e := by rw [hpre] _ = (volume.map e).restrict (spacingSimplex n) := (e.restrict_map volume (spacingSimplex n)).symm _ = volume.restrict (spacingSimplex n) := by rw [he.map_eq] have hint := hmp.integral_comp' (fun z : Fin n → ℝ => (z j) ^ 2) simp only [hfun] at hint have hswap : σ j = i := Equiv.swap_apply_right i j simpa [j, hswap] using hint
Causalean.Stat.OrderStatistic.simplex_coordinate_square_eq_first · Causalean/Stat/OrderStatistic/SimplexIntegrals.lean:294 · uses spacingSimplex
5 supporting declarations (lemmas, instances)
  • scaledSpacingSimplex_volume theorem — Given a finite dimension, a real radius, and its nonnegativity, the scaled spacing simplex has the stated factorial-normalized Lebesgue volume.
    n :
    ℕ
    r :
    ℝ
    hr :
    0 ≤ r
    volume (scaledSpacingSimplex n r) = ofReal (r ^ n / (n.factorial : ℝ))
    Proof (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]
    Causalean.Stat.OrderStatistic.scaledSpacingSimplex_volume · Causalean/Stat/OrderStatistic/SimplexIntegrals.lean:24
  • simplex_tail_section theorem — Given a finite dimension, a first coordinate, and its membership in the unit interval, the remaining simplex section has radius one minus that coordinate.
    n :
    ℕ
    t :
    ℝ
    ht :
    t ∈ Icc (0 : ℝ) 1
    {w : Fin n → ℝ | cons t w ∈ spacingSimplex (n + 1)} = scaledSpacingSimplex n (1 - t)
    Proof (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
    Causalean.Stat.OrderStatistic.simplex_tail_section · Causalean/Stat/OrderStatistic/SimplexIntegrals.lean:111
  • simplex_first_coordinate_square_fubini theorem — Given a finite dimension, integrating the squared first spacing coordinate equals integrating it against its tail-section volume.
    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
    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]
    Causalean.Stat.OrderStatistic.simplex_first_coordinate_square_fubini · Causalean/Stat/OrderStatistic/SimplexIntegrals.lean:134
  • simplex_first_coordinate_square_slice theorem — Given a finite dimension, the squared first-coordinate simplex integral equals its one-dimensional sliced integral.
    n :
    ℕ
    (∫ 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))]
    Causalean.Stat.OrderStatistic.simplex_first_coordinate_square_slice · Causalean/Stat/OrderStatistic/SimplexIntegrals.lean:249
  • unit_beta_square_integral theorem — Given a nonnegative integer exponent, the unit-interval beta-type polynomial integral has the stated factorial value.
    n :
    ℕ
    (∫ 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)
    Causalean.Stat.OrderStatistic.unit_beta_square_integral · Causalean/Stat/OrderStatistic/SimplexIntegrals.lean:264
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.

theorem cdf_pushforward_of_continuous reviewed
Causalean.Stat.OrderStatistic

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
hcont :
Continuous (fun x => cdf μ x)
μ.map (fun x => cdf μ x) = uniform01
Proof (Lean source)
theorem cdf_pushforward_of_continuous (μ : Measure ℝ) [IsProbabilityMeasure μ] (hcont : Continuous (fun x => cdf μ x)) : μ.map (fun x => cdf μ x) = uniform01 := by let ν : Measure ℝ := Causalean.Stat.unifOI have hquant : ν.map (quantile μ) = μ := Causalean.Stat.quantile_map_uniform μ have hcomp : (fun x => cdf μ x) ∘ quantile μ =ᵐ[ν] id := by filter_upwards [MeasureTheory.ae_restrict_mem measurableSet_Ioo] with u hu exact cdf_quantile_eq μ hu.1 hu.2 (hcont.continuousAt) calc μ.map (fun x => cdf μ x) = (ν.map (quantile μ)).map (fun x => cdf μ x) := by rw [hquant] _ = ν.map ((fun x => cdf μ x) ∘ quantile μ) := by exact (AEMeasurable.map_map_of_aemeasurable hcont.measurable.aemeasurable (aemeasurable_quantile_unifOI μ)) _ = ν := by simpa using (Measure.map_congr hcomp) _ = uniform01 := by change volume.restrict (Ioo (0 : ℝ) 1) = volume.restrict (Icc (0 : ℝ) 1) exact restrict_Ioo_eq_restrict_Icc
Causalean.Stat.OrderStatistic.cdf_pushforward_of_continuous · Causalean/Stat/OrderStatistic/CDFTransport.lean:30 · uses uniform01
3 supporting declarations (lemmas, instances)
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.

theorem real_alternating_gap_second_moment_bounds reviewed
Causalean.Stat.OrderStatistic

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
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 :
ℕ
hn :
Even n
conclusion 1
(1 / Cg ^ 2) * ((n : ℝ) / ((n + 1 : ℕ) * (n + 2 : ℕ)))
≤ ∫ x, (∑ j ∈ range (n / 2), (sortedGap n (2 * j) x) ^ 2) ∂iidSample μ n
conclusion 2
(∫ x, (∑ j ∈ range (n / 2), (sortedGap n (2 * j) x) ^ 2) ∂iidSample μ n)
≤ (1 / cg ^ 2) * ((n : ℝ) / ((n + 1 : ℕ) * (n + 2 : ℕ)))
Proof (Lean source)
theorem real_alternating_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 : ℕ) (hn : Even n) : (1 / Cg ^ 2) * ((n : ℝ) / ((n + 1 : ℕ) * (n + 2 : ℕ))) ≤ ∫ x, (∑ j ∈ range (n / 2), (sortedGap n (2 * j) x) ^ 2) ∂iidSample μ n ∧ (∫ x, (∑ j ∈ range (n / 2), (sortedGap n (2 * j) x) ^ 2) ∂iidSample μ n) ≤ (1 / cg ^ 2) * ((n : ℝ) / ((n + 1 : ℕ) * (n + 2 : ℕ))) := by have heven : 2 * (n / 2) = n := by rcases hn with ⟨m, hm⟩ omega have hindex (j : ℕ) (hj : j ∈ range (n / 2)) : 2 * j + 1 < n := by simp only [Finset.mem_range] at hj omega have hsumconst : (∑ _j ∈ range (n / 2), (2 : ℝ) / ((n + 1 : ℕ) * (n + 2 : ℕ))) = (n : ℝ) / ((n + 1 : ℕ) * (n + 2 : ℕ)) := by simp only [Finset.sum_const, Finset.card_range, nsmul_eq_mul] have hreal : (2 : ℝ) * (n / 2 : ℕ) = n := by exact_mod_cast heven have hden : ((n + 1 : ℕ) : ℝ) * ((n + 2 : ℕ) : ℝ) ≠ 0 := by positivity field_simp nlinarith have hfactor (c : ℝ) : (∑ _j ∈ range (n / 2), c * ((2 : ℝ) / ((n + 1 : ℕ) * (n + 2 : ℕ)))) = c * ((n : ℝ) / ((n + 1 : ℕ) * (n + 2 : ℕ))) := by rw [← Finset.mul_sum, hsumconst] rw [integral_finsetSum (range (n / 2)) (fun j hj => sortedGap_square_integrable_of_interval_support μ a b hsupp n (2 * j) (hindex j hj))] have hlow : (∑ j ∈ range (n / 2), (1 / Cg ^ 2) * ((2 : ℝ) / ((n + 1 : ℕ) * (n + 2 : ℕ)))) ≤ ∑ j ∈ range (n / 2), ∫ x, (sortedGap n (2 * j) x) ^ 2 ∂iidSample μ n := by apply Finset.sum_le_sum intro j hj exact (real_gap_second_moment_bounds μ a b cg Cg p hcg hCg hμ hsupp hbound n (2 * j) (hindex j hj)).1 have hupp : (∑ j ∈ range (n / 2), ∫ x, (sortedGap n (2 * j) x) ^ 2 ∂iidSample μ n) ≤ ∑ j ∈ range (n / 2), (1 / cg ^ 2) * ((2 : ℝ) / ((n + 1 : ℕ) * (n + 2 : ℕ))) := by apply Finset.sum_le_sum intro j hj exact (real_gap_second_moment_bounds μ a b cg Cg p hcg hCg hμ hsupp hbound n (2 * j) (hindex j hj)).2 constructor · calc _ = ∑ _j ∈ range (n / 2), (1 / Cg ^ 2) * ((2 : ℝ) / ((n + 1 : ℕ) * (n + 2 : ℕ))) := (hfactor _).symm _ ≤ _ := hlow · calc _ ≤ ∑ _j ∈ range (n / 2), (1 / cg ^ 2) * ((2 : ℝ) / ((n + 1 : ℕ) * (n + 2 : ℕ))) := hupp _ = _ := hfactor _
Causalean.Stat.OrderStatistic.real_alternating_gap_second_moment_bounds · Causalean/Stat/OrderStatistic/Comparison.lean:248 · uses iidSample , sortedGap
9 supporting declarations (lemmas, instances)
  • cdf_pushforward_uniform01 theorem — Given a real probability law, a density, and its density representation, its CDF pushes the law forward to the unit-uniform law.
    p :
    ℝ → ℝ
    hμ :
    μ = volume.withDensity (fun x => ofReal (p x))
    μ.map (fun x => cdf μ x) = uniform01
    Proof (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μ)
    Causalean.Stat.OrderStatistic.cdf_pushforward_uniform01 · Causalean/Stat/OrderStatistic/Comparison.lean:23
  • cdf_increment_bounds theorem — 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.
    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
    conclusion 1
    cg * (y - x) ≤ cdf μ y - cdf μ x
    conclusion 2
    cdf μ y - cdf μ x ≤ Cg * (y - x)
    Proof (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
    Causalean.Stat.OrderStatistic.cdf_increment_bounds · Causalean/Stat/OrderStatistic/Comparison.lean:30
  • iid_cdf_pushforward_uniform01 theorem — 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.
    p :
    ℝ → ℝ
    hμ :
    μ = volume.withDensity (fun x => ofReal (p x))
    n :
    ℕ
    (iidSample μ n).map (fun x i => cdf μ (x i)) = iidSample uniform01 n
    Proof (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]
    Causalean.Stat.OrderStatistic.iid_cdf_pushforward_uniform01 · Causalean/Stat/OrderStatistic/Comparison.lean:42
  • iid_support_interval_ae theorem — 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.
    a b :
    ℝ
    hsupp :
    μ (Icc a b)ᶜ = 0
    n :
    ℕ
    ∀ᵐ x ∂iidSample μ n, ∀ i, x i ∈ Icc a b
    Proof (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)
    Causalean.Stat.OrderStatistic.iid_support_interval_ae · Causalean/Stat/OrderStatistic/Comparison.lean:58
  • sortedGap_square_integrable_of_interval_support theorem — 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.
    a b :
    ℝ
    hsupp :
    μ (Icc a b)ᶜ = 0
    n k :
    ℕ
    hk :
    k + 1 < n
    Integrable (fun x => (sortedGap n k x) ^ 2) (iidSample μ n)
    Proof (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))
    Causalean.Stat.OrderStatistic.sortedGap_square_integrable_of_interval_support · Causalean/Stat/OrderStatistic/Comparison.lean:66
  • sortedGap_cdf_linear_bounds theorem — 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.
    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
    conclusion 1
    cg * sortedGap n k x ≤ sortedGap n k (fun i => cdf μ (x i))
    conclusion 2
    sortedGap n k (fun i => cdf μ (x i)) ≤ Cg * sortedGap n k x
    Proof (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
    Causalean.Stat.OrderStatistic.sortedGap_cdf_linear_bounds · Causalean/Stat/OrderStatistic/Comparison.lean:120
  • sortedGap_cdf_square_bounds theorem — 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.
    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
    conclusion 1
    cg ^ 2 * (sortedGap n k x) ^ 2
    ≤ (sortedGap n k (fun i => cdf μ (x i))) ^ 2
    conclusion 2
    (sortedGap n k (fun i => cdf μ (x i))) ^ 2
    ≤ Cg ^ 2 * (sortedGap n k x) ^ 2
    Proof (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]
    Causalean.Stat.OrderStatistic.sortedGap_cdf_square_bounds · Causalean/Stat/OrderStatistic/Comparison.lean:146
  • cdf_transformed_gap_second_moment theorem — 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.
    n k :
    ℕ
    hk :
    k + 1 < n
    hcont :
    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 : ℕ))
    Proof (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
    Causalean.Stat.OrderStatistic.cdf_transformed_gap_second_moment · Causalean/Stat/OrderStatistic/Comparison.lean:173
  • real_gap_second_moment_bounds theorem — 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.
    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
    conclusion 1
    (1 / Cg ^ 2) * ((2 : ℝ) / ((n + 1 : ℕ) * (n + 2 : ℕ)))
    ≤ ∫ x, (sortedGap n k x) ^ 2 ∂iidSample μ n
    conclusion 2
    (∫ x, (sortedGap n k x) ^ 2 ∂iidSample μ n)
    ≤ (1 / cg ^ 2) * ((2 : ℝ) / ((n + 1 : ℕ) * (n + 2 : ℕ)))
    Proof (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
    Causalean.Stat.OrderStatistic.real_gap_second_moment_bounds · Causalean/Stat/OrderStatistic/Comparison.lean:195
Density­Envelope 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.

theorem withDensity_interval_mass_bounds reviewed
Causalean.Stat.OrderStatistic

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
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
conclusion 1
cg * (y - x) ≤ μ.real (Ioc x y)
conclusion 2
μ.real (Ioc x y) ≤ Cg * (y - x)
Proof (Lean source)
theorem withDensity_interval_mass_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) ≤ μ.real (Ioc x y) ∧ μ.real (Ioc x y) ≤ Cg * (y - x) := by have hsub : Ioc x y ⊆ Icc a b := by intro z hz exact ⟨le_trans hax hz.1.le, le_trans hz.2 hyb⟩ have hlocal := ae_restrict_of_ae_restrict_of_subset hsub hbound have hlen : 0 ≤ y - x := sub_nonneg.mpr hxy have hmass : ofReal cg * volume (Ioc x y) ≤ μ (Ioc x y) ∧ μ (Ioc x y) ≤ ofReal Cg * volume (Ioc x y) := by rw [hμ, withDensity_apply _ measurableSet_Ioc] constructor · rw [← setLIntegral_const] apply setLIntegral_mono_ae' measurableSet_Ioc exact (ae_restrict_iff' measurableSet_Ioc).1 (hlocal.mono fun z hz => ENNReal.ofReal_le_ofReal hz.1) · rw [← setLIntegral_const] apply setLIntegral_mono_ae' measurableSet_Ioc exact (ae_restrict_iff' measurableSet_Ioc).1 (hlocal.mono fun z hz => ENNReal.ofReal_le_ofReal hz.2) have hfin : μ (Ioc x y) ≠ ⊤ := measure_ne_top μ _ have hvol : volume (Ioc x y) = ofReal (y - x) := by simp [Real.volume_Ioc] constructor · have h := ENNReal.toReal_mono hfin hmass.1 simpa [measureReal_def, hvol, ENNReal.toReal_mul, ENNReal.toReal_ofReal (le_of_lt hcg), ENNReal.toReal_ofReal hlen] using h · have hupper : ofReal Cg * volume (Ioc x y) ≠ ⊤ := by rw [hvol, ← ENNReal.ofReal_mul (le_trans (le_of_lt hcg) hCg)] exact ENNReal.ofReal_ne_top have h := ENNReal.toReal_mono hupper hmass.2 simpa [measureReal_def, hvol, ENNReal.toReal_mul, ENNReal.toReal_ofReal (le_trans (le_of_lt hcg) hCg), ENNReal.toReal_ofReal hlen] using h
Causalean.Stat.OrderStatistic.withDensity_interval_mass_bounds · Causalean/Stat/OrderStatistic/DensityEnvelope.lean:20
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.

theorem uniform_alternating_gap_second_moment reviewed
Causalean.Stat.OrderStatistic

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
n :
ℕ
hn :
Even n
∫ x, (∑ j ∈ range (n / 2), (sortedGap n (2 * j) x) ^ 2) ∂iidSample uniform01 n
= (n : ℝ) / ((n + 1 : ℕ) * (n + 2 : ℕ))
Proof (Lean source)
theorem uniform_alternating_gap_second_moment (n : ℕ) (hn : Even n) : ∫ x, (∑ j ∈ range (n / 2), (sortedGap n (2 * j) x) ^ 2) ∂iidSample uniform01 n = (n : ℝ) / ((n + 1 : ℕ) * (n + 2 : ℕ)) := by have heven : 2 * (n / 2) = n := by rcases hn with ⟨m, hm⟩ omega have hindex (j : ℕ) (hj : j ∈ range (n / 2)) : 2 * j + 1 < n := by simp only [Finset.mem_range] at hj omega rw [integral_finsetSum (range (n / 2)) (fun j hj => uniform_gap_square_integrable n (2 * j) (hindex j hj))] have hsum : (∑ j ∈ range (n / 2), ∫ x, (sortedGap n (2 * j) x) ^ 2 ∂iidSample uniform01 n) = ∑ _j ∈ range (n / 2), (2 : ℝ) / ((n + 1 : ℕ) * (n + 2 : ℕ)) := by apply Finset.sum_congr rfl intro j hj exact uniform_gap_second_moment n (2 * j) (hindex j hj) rw [hsum] simp only [Finset.sum_const, Finset.card_range, nsmul_eq_mul] have hreal : (2 : ℝ) * (n / 2 : ℕ) = n := by exact_mod_cast heven have hden : ((n + 1 : ℕ) : ℝ) * ((n + 2 : ℕ) : ℝ) ≠ 0 := by positivity field_simp nlinarith
Causalean.Stat.OrderStatistic.uniform_alternating_gap_second_moment · Causalean/Stat/OrderStatistic/Moments.lean:137 · uses iidSample , sortedGap , uniform01
3 supporting declarations (lemmas, instances)