Stat.Order­Statistic.Weighted­Concomitant

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.

Bernstein­Kernel 2 core · 3 supporting The density kernel associated with arbitrary nonnegative cell masses, and its normalization by the beta integral. ★ integral_bernsteinCell

Finite Bernstein cell kernels

The density kernel associated with arbitrary nonnegative cell masses, and its normalization by the beta integral.

Proof route: use the integer-parameter beta integral to normalize each basis term. Exchange the finite sum and integral to normalize the mixture.

def bernsteinCell reviewed
Causalean.Stat.OrderStatistic.WeightedConcomitant

For a sample size, cell masses, and evaluation point, the Bernstein cell-average kernel is the degree N-1 Bernstein mixture multiplied by N.

Definition (Lean source)
N :
ℕ
a :
Fin N → ℝ
u :
ℝ
bernsteinCell N a u :
ℝ
N * ∑ j : Fin N, a j * (choose (N - 1) (j : ℕ) : ℝ) * u ^ (j : ℕ) * (1 - u) ^ (N - 1 - (j : ℕ))
Causalean.Stat.OrderStatistic.WeightedConcomitant.bernsteinCell · Causalean/Stat/OrderStatistic/WeightedConcomitant/BernsteinKernel.lean:24
theorem integral_bernsteinCell reviewed
Causalean.Stat.OrderStatistic.WeightedConcomitant

For a positive sample size, cell masses with unit sum, the Bernstein kernel integrates to one on the unit interval.

Formal statement
N :
ℕ
hN :
0 < N
a :
Fin N → ℝ
hsum :
∑ j : Fin N, a j = 1
∫ u in Icc (0 : ℝ) 1, bernsteinCell N a u ∂volume = 1
Proof (Lean source)
theorem integral_bernsteinCell {N : ℕ} (hN : 0 < N) (a : Fin N → ℝ) (hsum : ∑ j : Fin N, a j = 1) : ∫ u in Icc (0 : ℝ) 1, bernsteinCell N a u ∂volume = 1 := by have hint (j : Fin N) : IntegrableOn (fun u : ℝ => a j * ((N : ℝ) * (choose (N - 1) (j : ℕ) : ℝ) * u ^ (j : ℕ) * (1 - u) ^ (N - 1 - (j : ℕ)))) (Icc (0 : ℝ) 1) volume := by apply Continuous.integrableOn_Icc fun_prop calc (∫ u in Icc (0 : ℝ) 1, bernsteinCell N a u ∂volume) = ∫ u in Icc (0 : ℝ) 1, ∑ j : Fin N, a j * ((N : ℝ) * (choose (N - 1) (j : ℕ) : ℝ) * u ^ (j : ℕ) * (1 - u) ^ (N - 1 - (j : ℕ))) ∂volume := by congr 1 funext u simp only [bernsteinCell, Finset.mul_sum] apply Finset.sum_congr rfl intro j hj ring _ = ∑ j : Fin N, a j := by rw [integral_finsetSum (s := univ) (fun j hj => hint j)] apply Finset.sum_congr rfl intro j hj rw [integral_const_mul, integral_bernstein_basis hN j, mul_one] _ = 1 := hsum
Causalean.Stat.OrderStatistic.WeightedConcomitant.integral_bernsteinCell · Causalean/Stat/OrderStatistic/WeightedConcomitant/BernsteinKernel.lean:104 · uses bernsteinCell
3 supporting declarations (lemmas, instances)
  • measurable_bernsteinCell theorem — For any finite cell masses, the Bernstein kernel is measurable.
    N :
    ℕ
    a :
    Fin N → ℝ
    Proof (Lean source)
    theorem measurable_bernsteinCell {N : ℕ} (a : Fin N → ℝ) : Measurable (bernsteinCell N a) := by unfold bernsteinCell fun_prop
    Causalean.Stat.OrderStatistic.WeightedConcomitant.measurable_bernsteinCell · Causalean/Stat/OrderStatistic/WeightedConcomitant/BernsteinKernel.lean:30
  • bernsteinCell_nonneg theorem — For nonnegative cell masses and a point in the unit interval, the Bernstein kernel is nonnegative.
    N :
    ℕ
    Fin N → ℝ
    ha :
    ∀ j, 0 ≤ a j
    u :
    ℝ
    hu :
    u ∈ Icc (0 : ℝ) 1
    0 ≤ bernsteinCell N a u
    Proof (Lean source)
    theorem bernsteinCell_nonneg {N : ℕ} {a : Fin N → ℝ} (ha : ∀ j, 0 ≤ a j) {u : ℝ} (hu : u ∈ Icc (0 : ℝ) 1) : 0 ≤ bernsteinCell N a u := by unfold bernsteinCell apply mul_nonneg (by positivity) apply Finset.sum_nonneg intro j hj exact mul_nonneg (mul_nonneg (mul_nonneg (ha j) (by positivity)) (pow_nonneg hu.1 _)) (pow_nonneg (sub_nonneg.mpr hu.2) _)
    Causalean.Stat.OrderStatistic.WeightedConcomitant.bernsteinCell_nonneg · Causalean/Stat/OrderStatistic/WeightedConcomitant/BernsteinKernel.lean:36
  • integral_bernstein_basis theorem — For a positive sample size and cell index, the Bernstein basis density associated with that cell integrates to one.
    N :
    ℕ
    hN :
    0 < N
    j :
    Fin N
    (∫ u in Icc (0 : ℝ) 1, (N : ℝ) * (choose (N - 1) (j : ℕ) : ℝ) * u ^ (j : ℕ) * (1 - u) ^ (N - 1 - (j : ℕ)) ∂volume)
    = 1
    Proof (Lean source)
    theorem integral_bernstein_basis {N : ℕ} (hN : 0 < N) (j : Fin N) : (∫ u in Icc (0 : ℝ) 1, (N : ℝ) * (choose (N - 1) (j : ℕ) : ℝ) * u ^ (j : ℕ) * (1 - u) ^ (N - 1 - (j : ℕ)) ∂volume) = 1 := by let k := N - 1 - (j : ℕ) have hj : (j : ℕ) ≤ N - 1 := by omega have hsum : (j : ℕ) + k + 1 = N := by dsimp [k]; omega have hbeta : (∫ u in (0 : ℝ)..1, ((u ^ (j : ℕ) * (1 - u) ^ k : ℝ) : ℂ)) = Complex.betaIntegral ((j : ℕ) + 1) (k + 1) := by rw [Complex.betaIntegral] apply intervalIntegral.integral_congr intro u hu have hu0 : 0 ≤ u := by simpa using hu.1 have hu1 : u ≤ 1 := by simpa using hu.2 dsimp simp only [Complex.ofReal_mul, Complex.ofReal_pow, Complex.ofReal_sub, Complex.ofReal_one] simp [Complex.cpow_natCast] have heval := Complex.betaIntegral_eq_Gamma_mul_div ((j : ℕ) + 1) (k + 1) (by simp only [Complex.add_re, Complex.natCast_re, Complex.one_re]; positivity) (by simp only [Complex.add_re, Complex.natCast_re, Complex.one_re]; positivity) rw [← hbeta] at heval have hg1 : Complex.Gamma ((j : ℕ) + 1) = ((j : ℕ).factorial : ℂ) := by simpa using Complex.Gamma_nat_eq_factorial (j : ℕ) have hg2 : Complex.Gamma (k + 1) = (k.factorial : ℂ) := by simpa using Complex.Gamma_nat_eq_factorial k have hg3 : Complex.Gamma (((j : ℕ) + 1) + (k + 1)) = (N.factorial : ℂ) := by have harg : ((j : ℕ) : ℂ) + 1 + ((k : ℕ) : ℂ) + 1 = (N : ℂ) + 1 := by exact_mod_cast (show (j : ℕ) + 1 + k + 1 = N + 1 by omega) rw [← add_assoc, harg] exact Complex.Gamma_nat_eq_factorial N rw [hg1, hg2, hg3, intervalIntegral.integral_ofReal] at heval have hreal : (∫ u in (0 : ℝ)..1, u ^ (j : ℕ) * (1 - u) ^ k) = (j : ℕ).factorial * k.factorial / N.factorial := by exact Complex.ofReal_inj.mp (by simpa using heval) rw [intervalIntegral.integral_of_le (by norm_num : (0 : ℝ) ≤ 1), ← integral_Icc_eq_integral_Ioc] at hreal rw [show N - 1 - (j : ℕ) = k from rfl] simp_rw [mul_assoc] rw [integral_const_mul, integral_const_mul, hreal] have hchoose : (choose (N - 1) (j : ℕ) : ℝ) * (j : ℕ).factorial * k.factorial = (N - 1).factorial := by exact_mod_cast Nat.choose_mul_factorial_mul_factorial hj have hfac : (N.factorial : ℝ) = N * (N - 1).factorial := by have : N - 1 + 1 = N := by omega rw [← this, Nat.factorial_succ] push_cast congr 1 rw [hfac] field_simp nlinarith [hchoose]
    Causalean.Stat.OrderStatistic.WeightedConcomitant.integral_bernstein_basis · Causalean/Stat/OrderStatistic/WeightedConcomitant/BernsteinKernel.lean:48
Concomitant­Core 2 core · 7 supporting Continuous CDF transport of iid sorting coordinates, almost-sure rank equivalence, and the conditional-mean and tagged-rank ingredients of the Bernstein-kernel expectation of bounded marks; the expectation formula itself ★ uniform_tagged_rank_cell_integral

Rank-weighted concomitant expectation

Continuous CDF transport of iid sorting coordinates, almost-sure rank equivalence, and the conditional-mean and tagged-rank ingredients of the Bernstein-kernel expectation of bounded marks; the expectation formula itself is proved in ConcomitantExpectation.

Proof route: apply Measure.pi_map_pi to the one-coordinate CDF transport. Uniform coordinates have no ties; strict ordering is therefore preserved by the monotone CDF almost surely. Conditional expectation against the CDF's comap sigma algebra replaces each mark by m(U). The rank of one tagged uniform observation has the binomial cell kernel. Pull almost-everywhere measurability and bounds of m back along the measure-preserving CDF map.

def rankConcomitant reviewed
Causalean.Stat.OrderStatistic.WeightedConcomitant

For cell weights and a sample of sorting coordinates with marks, the rank-weighted concomitant statistic sums each sorted mark against its cell weight.

Definition (Lean source)
N :
ℕ
a :
Fin N → ℝ
x :
Fin N → ℝ × ℝ
rankConcomitant a x :
ℝ
∑ j : Fin N, a j * (x (sort (fun i => (x i).1) j)).2
Causalean.Stat.OrderStatistic.WeightedConcomitant.rankConcomitant · Causalean/Stat/OrderStatistic/WeightedConcomitant/ConcomitantCore.lean:34
theorem uniform_tagged_rank_cell_integral reviewed
Causalean.Stat.OrderStatistic.WeightedConcomitant

For a positive sample size, a tagged coordinate, a rank, and an almost-everywhere measurable bounded test function, the iid unit-uniform expectation of the test function at the tagged coordinate, on the event that this coordinate has that (zero-based) rank j in the sample, equals the integral over the unit interval of the test function against the binomial weight C(N−1, j) v^j (1−v)^(N−1−j).

Formal statement
N :
ℕ
hN :
0 < N
i j :
Fin N
f :
ℝ → ℝ
hbound :
∀ᵐ u ∂uniform01, |f u| ≤ 1
(∫ u, (if (sort u).symm i = j then f (u i) else 0) ∂iidSample uniform01 N)
= ∫ v in Icc (0 : ℝ) 1, f v * ((choose (N - 1) j.val : ℝ) * v ^ j.val * (1 - v) ^ (N - 1 - j.val)) ∂volume
Proof (Lean source)
theorem uniform_tagged_rank_cell_integral {N : ℕ} (hN : 0 < N) (i j : Fin N) (f : ℝ → ℝ) (hf : AEMeasurable f uniform01) (hbound : ∀ᵐ u ∂uniform01, |f u| ≤ 1) : (∫ u, (if (sort u).symm i = j then f (u i) else 0) ∂iidSample uniform01 N) = ∫ v in Icc (0 : ℝ) 1, f v * ((Nat.choose (N - 1) j.val : ℝ) * v ^ j.val * (1 - v) ^ (N - 1 - j.val)) ∂volume := by classical haveI : IsProbabilityMeasure uniform01 := ⟨by simp [uniform01]⟩ let g := hf.mk f have hg : Measurable g := hf.measurable_mk have hfg : f =ᵐ[uniform01] g := hf.ae_eq_mk have hgbound : ∀ᵐ v ∂uniform01, |g v| ≤ 1 := by filter_upwards [hbound, hfg] with v hv heq simpa only [← heq] using hv have hmain (g : ℝ → ℝ) (hg : Measurable g) (hgbound : ∀ᵐ v ∂uniform01, |g v| ≤ 1) : (∫ u, (if (sort u).symm i = j then g (u i) else 0) ∂iidSample uniform01 N) = ∫ v in Icc (0 : ℝ) 1, g v * ((Nat.choose (N - 1) j.val : ℝ) * v ^ j.val * (1 - v) ^ (N - 1 - j.val)) ∂volume := by cases N with | zero => omega | succ n => let ν : Measure (Fin (n + 1) → ℝ) := Measure.pi (fun _ => uniform01) let ρ : Measure (Fin n → ℝ) := Measure.pi (fun _ => uniform01) let e := piFinSuccAbove (fun _ : Fin (n + 1) => ℝ) i let A (v : ℝ) : Set (Fin n → ℝ) := {w | ((Finset.univ : Finset (Fin n)).filter (fun k => w k < v)).card = j.val} let C : Set (Fin (n + 1) → ℝ) := {u | (((Finset.univ : Finset (Fin (n + 1))).erase i).filter (fun k => u k < u i)).card = j.val} have hcount (v : ℝ) (u : Fin (n + 1) → ℝ) : (((Finset.univ : Finset (Fin (n + 1))).erase i).filter (fun k => u k < v)).card = ((Finset.univ : Finset (Fin n)).filter (fun k => i.removeNth u k < v)).card := by have hindex : ((Finset.univ : Finset (Fin (n + 1))).erase i) = (Finset.univ : Finset (Fin n)).image i.succAbove := by ext k simp only [Finset.mem_erase, Finset.mem_univ, and_true, mem_image, Finset.mem_univ, true_and] rw [← Set.mem_range] simp [Fin.range_succAbove] rw [hindex, Finset.filter_image, Finset.card_image_of_injective] · rfl · exact Fin.succAbove_right_injective have hA (v : ℝ) : MeasurableSet (A v) := by dsimp [A] apply measurableSet_eq_fun · simp_rw [Finset.card_filter] apply Finset.measurable_sum intro k _ apply Measurable.ite · exact measurableSet_lt (measurable_pi_apply k) measurable_const · exact measurable_const · exact measurable_const · exact measurable_const have hC : MeasurableSet C := by dsimp [C] apply measurableSet_eq_fun · simp_rw [Finset.card_filter] apply Finset.measurable_sum intro k _ apply Measurable.ite · exact measurableSet_lt (measurable_pi_apply k) (measurable_pi_apply i) · exact measurable_const · exact measurable_const · exact measurable_const have hmass (v : ℝ) (hv : v ∈ Icc (0 : ℝ) 1) : ρ (A v) = ofReal ((Nat.choose n j.val : ℝ) * v ^ j.val * (1 - v) ^ (n - j.val)) := by let B : Set (Fin (n + 1) → ℝ) := {u | (((Finset.univ : Finset (Fin (n + 1))).erase i).filter (fun k => u k < v)).card = j.val} have hB : B = e ⁻¹' (univ ×ˢ A v) := by ext u simp only [Set.mem_preimage, Set.mem_prod, Set.mem_univ, true_and] change (((Finset.univ : Finset (Fin (n + 1))).erase i).filter (fun k => u k < v)).card = j.val ↔ ((Finset.univ : Finset (Fin n)).filter (fun k => i.removeNth u k < v)).card = j.val rw [hcount] have he := measurePreserving_piFinSuccAbove (fun _ : Fin (n + 1) => uniform01) i have hBmass : ρ (A v) = ν B := by rw [hB, he.measure_preimage ((MeasurableSet.univ.prod (hA v)).nullMeasurableSet)] rw [Measure.prod_prod] simp [ρ] simpa [ν, ρ, B] using hBmass.trans (uniform_other_lt_count_mass i j hv) let F : (Fin (n + 1) → ℝ) → ℝ := fun u => if u ∈ C then g (u i) else 0 have hFmeas : Measurable F := by apply Measurable.ite hC · exact hg.comp (measurable_pi_apply i) · exact measurable_const have hpi_bound : ∀ᵐ u ∂ν, |g (u i)| ≤ 1 := by have hmap : ν.map (fun u => u i) = uniform01 := by exact (measurePreserving_eval (fun _ : Fin (n + 1) => uniform01) i).map_eq exact ae_of_ae_map (μ := ν) (f := fun u : Fin (n + 1) → ℝ => u i) (p := fun v => |g v| ≤ 1) (measurable_pi_apply i).aemeasurable (by simpa [hmap] using hgbound) have hFint : Integrable F ν := by apply Integrable.of_bound hFmeas.aestronglyMeasurable 1 filter_upwards [hpi_bound] with u hu by_cases hc : u ∈ C · simpa [F, hc, Real.norm_eq_abs] using hu · simp [F, hc] have hrank : (fun u : Fin (n + 1) → ℝ => if (sort u).symm i = j then g (u i) else 0) =ᵐ[ν] F := by filter_upwards [iid_uniform_coordinates_injective_ae (N := n + 1)] with u hu have hiff : (sort u).symm i = j ↔ u ∈ C := by change (sort u).symm i = j ↔ (((Finset.univ : Finset (Fin (n + 1))).erase i).filter (fun k => u k < u i)).card = j.val rw [← uniform_tagged_rank_eq_count u i hu] exact Fin.ext_iff simp only [F, hiff] have he := measurePreserving_piFinSuccAbove (fun _ : Fin (n + 1) => uniform01) i have hcomp : (fun z => F (e.symm z)) ∘ e = F := by funext u simp have hsplit : (∫ u, F u ∂ν) = ∫ v, ∫ w : Fin n → ℝ, F (e.symm (v, w)) ∂ρ ∂uniform01 := by calc _ = ∫ z : ℝ × (Fin n → ℝ), F (e.symm z) ∂uniform01.prod ρ := by have hh := he.integral_comp' (fun z => F (e.symm z)) change (∫ u, ((fun z => F (e.symm z)) ∘ e) u ∂ν) = _ at hh rw [hcomp] at hh exact hh _ = _ := by apply integral_prod apply (he.integrable_comp_emb e.measurableEmbedding).mp change Integrable (((fun z => F (e.symm z)) ∘ e)) ν rw [hcomp] exact hFint have hinner (v : ℝ) : (∫ w : Fin n → ℝ, (if w ∈ A v then g v else 0) ∂ρ) = (ρ (A v)).toReal * g v := by simpa [indicator, Measure.real, smul_eq_mul] using (integral_indicator_const (g v) (hA v) (μ := ρ)) have hfiber (v : ℝ) (w : Fin n → ℝ) : F (e.symm (v, w)) = if w ∈ A v then g v else 0 := by have heval : (e.symm (v, w)) i = v := by simp [e] have hrem : i.removeNth (e.symm (v, w)) = w := by have hh := congrArg snd (e.apply_symm_apply (v, w)) exact hh simp only [F] change (if (((Finset.univ : Finset (Fin (n + 1))).erase i).filter (fun k => (e.symm (v, w)) k < (e.symm (v, w)) i)).card = j.val then g ((e.symm (v, w)) i) else 0) = if ((Finset.univ : Finset (Fin n)).filter (fun k => w k < v)).card = j.val then g v else 0 rw [heval, hcount v (e.symm (v, w)), hrem] have hkernel_nonneg (v : ℝ) (hv : v ∈ Icc (0 : ℝ) 1) : 0 ≤ (Nat.choose n j.val : ℝ) * v ^ j.val * (1 - v) ^ (n - j.val) := by have hv0 : 0 ≤ v := hv.1 have hv1 : 0 ≤ 1 - v := sub_nonneg.mpr hv.2 positivity calc (∫ u, (if (sort u).symm i = j then g (u i) else 0) ∂iidSample uniform01 (n + 1)) = ∫ u, F u ∂ν := by exact integral_congr_ae hrank _ = ∫ v, ∫ w : Fin n → ℝ, F (e.symm (v, w)) ∂ρ ∂uniform01 := hsplit _ = ∫ v, (ρ (A v)).toReal * g v ∂uniform01 := by congr 1 funext v simp_rw [hfiber] exact hinner v _ = ∫ v, g v * ((Nat.choose n j.val : ℝ) * v ^ j.val * (1 - v) ^ (n - j.val)) ∂uniform01 := by apply integral_congr_ae filter_upwards [ae_restrict_mem measurableSet_Icc] with v hv rw [hmass v hv, ENNReal.toReal_ofReal (hkernel_nonneg v hv)] ring _ = _ := by simp only [uniform01, Nat.succ_sub_one] calc (∫ u, (if (sort u).symm i = j then f (u i) else 0) ∂iidSample uniform01 N) = ∫ u, (if (sort u).symm i = j then g (u i) else 0) ∂iidSample uniform01 N := by apply integral_congr_ae have hmap : (iidSample uniform01 N).map (fun u => u i) = uniform01 := (measurePreserving_eval (fun _ : Fin N => uniform01) i).map_eq have hcomp : ∀ᵐ u ∂iidSample uniform01 N, f (u i) = g (u i) := by exact ae_of_ae_map (μ := iidSample uniform01 N) (f := fun u : Fin N → ℝ => u i) (p := fun v => f v = g v) (measurable_pi_apply i).aemeasurable (by rw [hmap]; exact hfg) filter_upwards [hcomp] with u hu split_ifs <;> simp [hu] _ = ∫ v in Icc (0 : ℝ) 1, g v * ((Nat.choose (N - 1) j.val : ℝ) * v ^ j.val * (1 - v) ^ (N - 1 - j.val)) ∂volume := hmain g hg hgbound _ = _ := by apply integral_congr_ae have hfg' : f =ᵐ[volume.restrict (Icc (0 : ℝ) 1)] g := by simpa only [uniform01] using hfg filter_upwards [hfg'] with v hv simp [hv]
Causalean.Stat.OrderStatistic.WeightedConcomitant.uniform_tagged_rank_cell_integral · Causalean/Stat/OrderStatistic/WeightedConcomitant/ConcomitantCore.lean:274 · uses iidSample , uniform01
7 supporting declarations (lemmas, instances)
  • cdf_transport_iid theorem — For a probability law of marked observations whose sorting-coordinate CDF is continuous, the coordinatewise CDF pushforward of the iid sample is iid unit-uniform.
    N :
    ℕ
    μ :
    hcont :
    Continuous (fun t => cdf (μ.map fst) t)
    (Measure.pi (fun _ : Fin N => μ)).map (fun x i => cdf (μ.map fst) (x i).1)
    Proof (Lean source)
    theorem cdf_transport_iid {N : ℕ} (μ : Measure (ℝ × ℝ)) [IsProbabilityMeasure μ] (hcont : Continuous (fun t => cdf (μ.map Prod.fst) t)) : (Measure.pi (fun _ : Fin N => μ)).map (fun x i => cdf (μ.map Prod.fst) (x i).1) = iidSample uniform01 N := by have hfst : Measurable (Prod.fst : ℝ × ℝ → ℝ) := measurable_fst have : IsProbabilityMeasure (μ.map Prod.fst) := Measure.isProbabilityMeasure_map hfst.aemeasurable have hmap : μ.map (fun p : ℝ × ℝ => cdf (μ.map Prod.fst) p.1) = uniform01 := by simpa only [Function.comp_def] using (Measure.map_map hcont.measurable hfst).symm.trans (cdf_pushforward_of_continuous (μ.map Prod.fst) hcont) change (Measure.pi (fun _ : Fin N => μ)).map (fun x i => cdf (μ.map Prod.fst) (x i).1) = Measure.pi (fun _ : Fin N => uniform01) haveI : IsProbabilityMeasure (μ.map (fun p : ℝ × ℝ => cdf (μ.map Prod.fst) p.1)) := Measure.isProbabilityMeasure_map (hcont.measurable.comp hfst).aemeasurable haveI : ∀ _ : Fin N, SigmaFinite (μ.map (fun p : ℝ × ℝ => cdf (μ.map Prod.fst) p.1)) := fun _ => inferInstance simpa only [Function.comp_def, hmap] using (Measure.pi_map_pi (μ := fun _ : Fin N => μ) (f := fun _ p => cdf (μ.map Prod.fst) p.1) (fun _ : Fin N => (hcont.measurable.comp hfst).aemeasurable))
    Causalean.Stat.OrderStatistic.WeightedConcomitant.cdf_transport_iid · Causalean/Stat/OrderStatistic/WeightedConcomitant/ConcomitantCore.lean:39
  • sort_cdf_eq_ae theorem — For a marked observation law with continuous sorting-coordinate CDF, original and CDF coordinates sort in the same order almost surely.
    N :
    ℕ
    μ :
    hcont :
    Continuous (fun t => cdf (μ.map fst) t)
    ∀ᵐ x ∂Measure.pi (fun _ : Fin N => μ), sort (fun i => (x i).1)
    = sort (fun i => cdf (μ.map fst) (x i).1)
    Proof (Lean source)
    theorem sort_cdf_eq_ae {N : ℕ} (μ : Measure (ℝ × ℝ)) [IsProbabilityMeasure μ] (hcont : Continuous (fun t => cdf (μ.map fst) t)) : ∀ᵐ x ∂Measure.pi (fun _ : Fin N => μ), sort (fun i => (x i).1) = sort (fun i => cdf (μ.map fst) (x i).1) := by classical have hface (i j : Fin N) (hij : i ≠ j) : volume {u : Fin N → ℝ | u i = u j} = 0 := by let L : (Fin N → ℝ) →ₗ[ℝ] ℝ := (LinearMap.proj i : (Fin N → ℝ) →ₗ[ℝ] ℝ) - LinearMap.proj j have hL : L ≠ 0 := by intro h have h' := LinearMap.congr_fun h (fun k => if k = i then 1 else 0) simp [L, hij.symm] at h' have hker : LinearMap.ker L ≠ ⊤ := by intro h exact hL (LinearMap.ker_eq_top.mp h) have hs : {u : Fin N → ℝ | u i = u j} = (LinearMap.ker L : Set (Fin N → ℝ)) := by ext u simp [L, LinearMap.mem_ker, sub_eq_zero] rw [hs] exact Measure.addHaar_submodule volume (LinearMap.ker L) hker have huniform : ∀ᵐ u ∂iidSample uniform01 N, ∀ i j : Fin N, i ≠ j → u i ≠ u j := by apply Filter.eventually_all.mpr intro i apply Filter.eventually_all.mpr intro j by_cases hij : i = j · exact Filter.Eventually.of_forall (fun _ h => (h hij).elim) · have hne : ∀ᵐ u ∂(volume : Measure (Fin N → ℝ)), u i ≠ u j := by exact ae_iff.mpr (by simpa only [not_not] using hface i j hij) rw [iid_uniform_cube_law] exact (ae_restrict_of_ae hne).mono (fun u hu _ => hu) have htransport := cdf_transport_iid (N := N) μ hcont have hcoord : ∀ᵐ x ∂Measure.pi (fun _ : Fin N => μ), ∀ i j : Fin N, i ≠ j → cdf (μ.map fst) (x i).1 ≠ cdf (μ.map fst) (x j).1 := by rw [← htransport] at huniform exact ae_of_ae_map (by apply aemeasurable apply measurable_pi_iff.mpr intro i exact hcont.measurable.comp (measurable_fst.comp (measurable_pi_apply i)) : AEMeasurable (fun x : Fin N → ℝ × ℝ => fun i => cdf (μ.map fst) (x i).1) (Measure.pi (fun _ : Fin N => μ))) huniform filter_upwards [hcoord] with x hx let f : Fin N → ℝ := fun i => (x i).1 let g : Fin N → ℝ := fun i => cdf (μ.map fst) (x i).1 have hg : Injective g := by intro i j h by_contra hij exact hx i j hij h have hmono : Monotone (g ∘ sort f) := (ProbabilityTheory.monotone_cdf (μ.map fst)).comp (Tuple.monotone_sort f) change sort f = sort g apply (Tuple.eq_sort_iff).2 constructor · exact hmono · intro i j hij heq exact (hij.ne ((sort f).injective (hg heq))).elim
    Causalean.Stat.OrderStatistic.WeightedConcomitant.sort_cdf_eq_ae · Causalean/Stat/OrderStatistic/WeightedConcomitant/ConcomitantCore.lean:70
  • conditionalMean_exists_measurable_version theorem — For a marked observation law and an almost-everywhere conditional mean version, that version has a measurable representative on the CDF coordinate.
    μ :
    m :
    ℝ → ℝ
    hm :
    (fun p : ℝ × ℝ => m (cdf (μ.map fst) p.1))
    =ᵐ[μ] μ[(fun p : ℝ × ℝ => p.2) | comap (fun p : ℝ × ℝ => cdf (μ.map fst) p.1) inferInstance]
    ∃ g : ℝ → ℝ,
    conclusion 1
    conclusion 2
    (fun p : ℝ × ℝ => m (cdf (μ.map fst) p.1))
    =ᵐ[μ] (fun p => g (cdf (μ.map fst) p.1))
    Proof (Lean source)
    theorem conditionalMean_exists_measurable_version (μ : Measure (ℝ × ℝ)) [IsProbabilityMeasure μ] (m : ℝ → ℝ) (hm : (fun p : ℝ × ℝ => m (cdf (μ.map fst) p.1)) =ᵐ[μ] μ[(fun p : ℝ × ℝ => p.2) | comap (fun p : ℝ × ℝ => cdf (μ.map fst) p.1) inferInstance]) : ∃ g : ℝ → ℝ, Measurable g ∧ (fun p : ℝ × ℝ => m (cdf (μ.map fst) p.1)) =ᵐ[μ] (fun p => g (cdf (μ.map fst) p.1)) := by let F : ℝ × ℝ → ℝ := fun p => cdf (μ.map fst) p.1 let c : ℝ × ℝ → ℝ := μ[(fun p : ℝ × ℝ => p.2) | comap F inferInstance] have hc : @StronglyMeasurable (ℝ × ℝ) ℝ _ (comap F inferInstance) c := stronglyMeasurable_condExp obtain ⟨g, hg, hgc⟩ := hc.exists_eq_measurable_comp refine ⟨g, hg.measurable, ?_⟩ exact hm.trans (Filter.Eventually.of_forall fun p => by simpa only [Function.comp_apply] using congrFun hgc p)
    Causalean.Stat.OrderStatistic.WeightedConcomitant.conditionalMean_exists_measurable_version · Causalean/Stat/OrderStatistic/WeightedConcomitant/ConcomitantCore.lean:140
  • conditionalMean_ae_eq_uniform_version theorem — A conditional-mean version that factors measurably through a continuous CDF equals that measurable factor almost everywhere under the uniform law.
    μ :
    hcont :
    Continuous (fun t => cdf (μ.map fst) t)
    m :
    ℝ → ℝ
    hm :
    (fun p : ℝ × ℝ => m (cdf (μ.map fst) p.1))
    =ᵐ[μ] μ[(fun p : ℝ × ℝ => p.2) | comap (fun p : ℝ × ℝ => cdf (μ.map fst) p.1) inferInstance]
    ∃ g : ℝ → ℝ,
    conclusion 1
    conclusion 2
    m =ᵐ[uniform01] g
    Proof (Lean source)
    theorem conditionalMean_ae_eq_uniform_version (μ : Measure (ℝ × ℝ)) [IsProbabilityMeasure μ] (hcont : Continuous (fun t => cdf (μ.map Prod.fst) t)) (m : ℝ → ℝ) (hm : (fun p : ℝ × ℝ => m (cdf (μ.map Prod.fst) p.1)) =ᵐ[μ] μ[(fun p : ℝ × ℝ => p.2) | comap (fun p : ℝ × ℝ => cdf (μ.map Prod.fst) p.1) inferInstance]) : ∃ g : ℝ → ℝ, Measurable g ∧ m =ᵐ[uniform01] g := by obtain ⟨g, hg, hcomp⟩ := conditionalMean_exists_measurable_version μ m hm refine ⟨g, hg, ?_⟩ let ν : Measure ℝ := μ.map Prod.fst haveI : IsProbabilityMeasure ν := Measure.isProbabilityMeasure_map measurable_fst.aemeasurable have hfst : (fun t => m (cdf ν t)) =ᵐ[ν] (fun t => g (cdf ν t)) := by exact ae_eq_of_comp_fst μ (fun t => m (cdf ν t)) (fun t => g (cdf ν t)) hcomp exact ae_eq_of_comp_continuous_cdf ν hcont m g hfst
    Causalean.Stat.OrderStatistic.WeightedConcomitant.conditionalMean_ae_eq_uniform_version · Causalean/Stat/OrderStatistic/WeightedConcomitant/ConcomitantCore.lean:163
  • conditionalMean_comp_mem_Icc_ae theorem — A conditional mean of a mark in [0,1] stays in [0,1] almost surely under the original marked observation law.
    μ :
    hmark :
    ∀ᵐ p ∂μ, p.2 ∈ Icc (0 : ℝ) 1
    m :
    ℝ → ℝ
    hm :
    (fun p : ℝ × ℝ => m (cdf (μ.map fst) p.1))
    =ᵐ[μ] μ[(fun p : ℝ × ℝ => p.2) | comap (fun p : ℝ × ℝ => cdf (μ.map fst) p.1) inferInstance]
    ∀ᵐ p ∂μ, m (cdf (μ.map fst) p.1) ∈ Icc (0 : ℝ) 1
    Proof (Lean source)
    theorem conditionalMean_comp_mem_Icc_ae (μ : Measure (ℝ × ℝ)) [IsProbabilityMeasure μ] (hmark : ∀ᵐ p ∂μ, p.2 ∈ Icc (0 : ℝ) 1) (m : ℝ → ℝ) (hm : (fun p : ℝ × ℝ => m (cdf (μ.map fst) p.1)) =ᵐ[μ] μ[(fun p : ℝ × ℝ => p.2) | comap (fun p : ℝ × ℝ => cdf (μ.map fst) p.1) inferInstance]) : ∀ᵐ p ∂μ, m (cdf (μ.map fst) p.1) ∈ Icc (0 : ℝ) 1 := by have hlo : ∀ᵐ p ∂μ, (0 : ℝ) ≤ p.2 := hmark.mono fun _ hp => hp.1 have hhi : ∀ᵐ p ∂μ, p.2 ≤ (1 : ℝ) := hmark.mono fun _ hp => hp.2 have hcondlo : ∀ᵐ p ∂μ, (0 : ℝ) ≤ μ[(fun p : ℝ × ℝ => p.2) | comap (fun p : ℝ × ℝ => cdf (μ.map fst) p.1) inferInstance] p := condExp_nonneg hlo have hcondhi : ∀ᵐ p ∂μ, μ[(fun p : ℝ × ℝ => p.2) | comap (fun p : ℝ × ℝ => cdf (μ.map fst) p.1) inferInstance] p ≤ (1 : ℝ) := condExp_le_nonneg_const (by norm_num) hhi filter_upwards [hm, hcondlo, hcondhi] with p hp hp0 hp1 constructor · simpa only [hp] using hp0 · simpa only [hp] using hp1
    Causalean.Stat.OrderStatistic.WeightedConcomitant.conditionalMean_comp_mem_Icc_ae · Causalean/Stat/OrderStatistic/WeightedConcomitant/ConcomitantCore.lean:188
  • aemeasurable_conditionalMean_uniform theorem — For a marked observation law, continuous sorting-coordinate CDF, and conditional mean version, the version is almost-everywhere measurable under the unit-uniform law.
    μ :
    hcont :
    Continuous (fun t => cdf (μ.map fst) t)
    m :
    ℝ → ℝ
    hm :
    (fun p : ℝ × ℝ => m (cdf (μ.map fst) p.1))
    =ᵐ[μ] μ[(fun p : ℝ × ℝ => p.2) | comap (fun p : ℝ × ℝ => cdf (μ.map fst) p.1) inferInstance]
    Proof (Lean source)
    theorem aemeasurable_conditionalMean_uniform (μ : Measure (ℝ × ℝ)) [IsProbabilityMeasure μ] (hcont : Continuous (fun t => cdf (μ.map fst) t)) (m : ℝ → ℝ) (hm : (fun p : ℝ × ℝ => m (cdf (μ.map fst) p.1)) =ᵐ[μ] μ[(fun p : ℝ × ℝ => p.2) | comap (fun p : ℝ × ℝ => cdf (μ.map fst) p.1) inferInstance]) : AEMeasurable m uniform01 := by obtain ⟨g, hg, hmg⟩ := conditionalMean_ae_eq_uniform_version μ hcont m hm exact hg.aemeasurable.congr hmg.symm
    Causalean.Stat.OrderStatistic.WeightedConcomitant.aemeasurable_conditionalMean_uniform · Causalean/Stat/OrderStatistic/WeightedConcomitant/ConcomitantCore.lean:218
  • conditionalMean_mem_Icc_ae theorem — For a marked observation law, continuous sorting-coordinate CDF, marks in the unit interval almost surely, and a conditional mean version, that version lies in the unit interval almost everywhere under the uniform law.
    μ :
    hcont :
    Continuous (fun t => cdf (μ.map fst) t)
    hmark :
    ∀ᵐ p ∂μ, p.2 ∈ Icc (0 : ℝ) 1
    m :
    ℝ → ℝ
    hm :
    (fun p : ℝ × ℝ => m (cdf (μ.map fst) p.1))
    =ᵐ[μ] μ[(fun p : ℝ × ℝ => p.2) | comap (fun p : ℝ × ℝ => cdf (μ.map fst) p.1) inferInstance]
    ∀ᵐ u ∂uniform01, m u ∈ Icc (0 : ℝ) 1
    Proof (Lean source)
    theorem conditionalMean_mem_Icc_ae (μ : Measure (ℝ × ℝ)) [IsProbabilityMeasure μ] (hcont : Continuous (fun t => cdf (μ.map Prod.fst) t)) (hmark : ∀ᵐ p ∂μ, p.2 ∈ Icc (0 : ℝ) 1) (m : ℝ → ℝ) (hm : (fun p : ℝ × ℝ => m (cdf (μ.map Prod.fst) p.1)) =ᵐ[μ] μ[(fun p : ℝ × ℝ => p.2) | comap (fun p : ℝ × ℝ => cdf (μ.map Prod.fst) p.1) inferInstance]) : ∀ᵐ u ∂uniform01, m u ∈ Icc (0 : ℝ) 1 := by let ν : Measure ℝ := μ.map Prod.fst haveI : IsProbabilityMeasure ν := Measure.isProbabilityMeasure_map measurable_fst.aemeasurable let bad : ℝ → ℝ := fun u => if m u ∈ Icc (0 : ℝ) 1 then 0 else 1 have hcomp : (fun p : ℝ × ℝ => bad (cdf ν p.1)) =ᵐ[μ] (fun _ => (0 : ℝ)) := by filter_upwards [conditionalMean_comp_mem_Icc_ae μ hmark m hm] with p hp change (if m (cdf ν p.1) ∈ Icc (0 : ℝ) 1 then (0 : ℝ) else 1) = 0 exact if_pos hp have hfst : (fun t => bad (cdf ν t)) =ᵐ[ν] (fun _ => (0 : ℝ)) := ae_eq_of_comp_fst μ (fun t => bad (cdf ν t)) (fun _ => 0) hcomp have huni : bad =ᵐ[uniform01] (fun _ => (0 : ℝ)) := ae_eq_of_comp_continuous_cdf ν hcont bad (fun _ => 0) hfst filter_upwards [huni] with u hu by_contra hnot have hbad : bad u = 1 := if_neg hnot rw [hbad] at hu norm_num at hu
    Causalean.Stat.OrderStatistic.WeightedConcomitant.conditionalMean_mem_Icc_ae · Causalean/Stat/OrderStatistic/WeightedConcomitant/ConcomitantCore.lean:235
Power­Approximation 3 core · 6 supporting Order-statistic moments, the randomized adjacent-statistic coupling, and its threshold-indicator L1 estimate. ★ adjacentOrderMix_indicator_L1

Adjacent order-statistic coupling for power approximation

Order-statistic moments, the randomized adjacent-statistic coupling, and its threshold-indicator L1 estimate. The power-density approximation is assembled in PowerL1.

The mixture includes deterministic endpoints. Its moments follow from the single-statistic formulas, and its threshold error is controlled by the centered second moment.

def powerDensity reviewed
Causalean.Stat.OrderStatistic.WeightedConcomitant

For a power, the power density at a real argument is s(1-u)^(s-1).

Definition (Lean source)
s u :
ℝ
powerDensity s u :
ℝ
s * (1 - u) ^ (s - 1)
Causalean.Stat.OrderStatistic.WeightedConcomitant.powerDensity · Causalean/Stat/OrderStatistic/WeightedConcomitant/PowerApproximation.lean:28
def adjacentOrderMix reviewed
Causalean.Stat.OrderStatistic.WeightedConcomitant

A sample size, adjacent order index, and interpolation fraction determine the randomized adjacent order-statistic law: with weight 1-δ it is the law of the k-th smallest and with weight δ the law of the (k+1)-th smallest of N-1 independent unit-uniform draws, where the zeroth order statistic is read as the constant 0 and the N-th as the constant 1 (weights are truncated at zero when δ lies outside the unit interval).

Definition (Lean source)
N k :
ℕ
δ :
ℝ
adjacentOrderMix N k δ :
(ofReal (1 - δ)) • (iidSample uniform01 (N - 1)).map (fun x => if h : k = 0 then (0 : ℝ) else if h' : k ≤ N - 1 then sortedSample (N - 1) x ⟨k - 1, by omega⟩ else 1)
+ (ofReal δ) • (iidSample uniform01 (N - 1)).map (fun x => if h : k + 1 = N then (1 : ℝ) else if h' : k < N - 1 then sortedSample (N - 1) x ⟨k, h'⟩ else 1)
Causalean.Stat.OrderStatistic.WeightedConcomitant.adjacentOrderMix · Causalean/Stat/OrderStatistic/WeightedConcomitant/PowerApproximation.lean:31
theorem adjacentOrderMix_indicator_L1 reviewed
Causalean.Stat.OrderStatistic.WeightedConcomitant

A positive sample size, valid adjacent index, and unit-interval interpolation fraction give an integrated indicator error bounded by the mixture's root mean-square displacement: writing m = (k+δ)/N, the integral over the unit interval of the absolute difference between the CDF of the randomized adjacent order-statistic law and the step function jumping from 0 to 1 at m is at most the square root of m(1-m)/(N+1) + δ(1-δ)/(N(N+1)).

Formal statement
N k :
ℕ
hN :
0 < N
hk :
k < N
δ :
ℝ
hδ :
δ ∈ Icc (0 : ℝ) 1
(∫ u in Icc (0 : ℝ) 1, |((adjacentOrderMix N k δ) (Iic u)).toReal - (if (k + δ) / N ≤ u then (1 : ℝ) else 0)| ∂volume)
≤ sqrt (((k + δ) / N) * (1 - (k + δ) / N) / (N + 1) + δ * (1 - δ) / (N * (N + 1)))
Proof (Lean source)
theorem adjacentOrderMix_indicator_L1 {N k : ℕ} (hN : 0 < N) (hk : k < N) {δ : ℝ} (hδ : δ ∈ Icc (0 : ℝ) 1) : (∫ u in Icc (0 : ℝ) 1, |((adjacentOrderMix N k δ) (Iic u)).toReal - (if (k + δ) / N ≤ u then (1 : ℝ) else 0)| ∂volume) ≤ sqrt (((k + δ) / N) * (1 - (k + δ) / N) / (N + 1) + δ * (1 - δ) / (N * (N + 1))) := by haveI : IsProbabilityMeasure uniform01 := ⟨by simp [uniform01]⟩ haveI : IsProbabilityMeasure (iidSample uniform01 (N - 1)) := by dsimp [iidSample] infer_instance let μ := adjacentOrderMix N k δ have hmass : (∫ _u : ℝ, (1 : ℝ) ∂μ) = 1 := by have hmap (r : ℕ) : (∫ _u : ℝ, (1 : ℝ) ∂(iidSample uniform01 (N - 1)).map (orderEndpoint (N - 1) r)) = 1 := by rw [integral_map (orderEndpoint_aemeasurable (N - 1) r) measurable_const.aestronglyMeasurable] simp change (∫ _u : ℝ, (1 : ℝ) ∂adjacentOrderMix N k δ) = 1 rw [adjacentOrderMix_integral hN hk hδ (fun _ : ℝ => (1 : ℝ)) (integrable_const _) (integrable_const _), hmap k, hmap (k + 1)] ring haveI : IsProbabilityMeasure μ := by have hreal : (μ univ).toReal = 1 := by simpa [integral_const, Measure.real] using hmass exact isProbabilityMeasure_iff_real.mpr hreal have hsupp : ∀ᵐ x ∂μ, x ∈ Icc (0 : ℝ) 1 := by change ∀ᵐ x ∂adjacentOrderMix N k δ, x ∈ Icc (0 : ℝ) 1 rw [adjacentOrderMix_eq_endpoints hN hk, ae_add_measure_iff] constructor · exact Measure.ae_smul_measure ((ae_map_iff (orderEndpoint_aemeasurable (N - 1) k) measurableSet_Icc).2 (orderEndpoint_mem_Icc (N - 1) k)) _ · exact Measure.ae_smul_measure ((ae_map_iff (orderEndpoint_aemeasurable (N - 1) (k + 1)) measurableSet_Icc).2 (orderEndpoint_mem_Icc (N - 1) (k + 1))) _ have ht : (k + δ) / N ∈ Icc (0 : ℝ) 1 := by have hNr : (0 : ℝ) < N := by exact_mod_cast hN have hkr : (k : ℝ) + 1 ≤ N := by exact_mod_cast hk constructor · exact div_nonneg (add_nonneg (Nat.cast_nonneg _) hδ.1) (le_of_lt hNr) · apply (div_le_iff₀ hNr).2 linarith [hδ.2] calc (∫ u in Icc (0 : ℝ) 1, |((adjacentOrderMix N k δ) (Iic u)).toReal - (if (k + δ) / N ≤ u then (1 : ℝ) else 0)| ∂volume) = ∫ x, |x - ((k + δ) / N)| ∂μ := by exact integral_abs_cdf_sub_step_eq_mean_abs μ hsupp ht _ ≤ _ := adjacentOrderMix_abs_deviation_le_sqrt hN hk hδ
Causalean.Stat.OrderStatistic.WeightedConcomitant.adjacentOrderMix_indicator_L1 · Causalean/Stat/OrderStatistic/WeightedConcomitant/PowerApproximation.lean:474 · uses adjacentOrderMix
6 supporting declarations (lemmas, instances)
  • adjacentOrderMix_mean theorem — For a positive sample size, interpolation index, and unit interpolation fraction, the adjacent order-statistic mixture has mean (k+δ)/N.
    N k :
    ℕ
    hN :
    0 < N
    hk :
    k < N
    δ :
    ℝ
    hδ :
    δ ∈ Icc (0 : ℝ) 1
    ∫ u, u ∂adjacentOrderMix N k δ = (k + δ) / N
    Proof (Lean source)
    theorem adjacentOrderMix_mean {N k : ℕ} (hN : 0 < N) (hk : k < N) {δ : ℝ} (hδ : δ ∈ Icc (0 : ℝ) 1) : ∫ u, u ∂adjacentOrderMix N k δ = (k + δ) / N := by haveI : IsProbabilityMeasure uniform01 := ⟨by simp [uniform01]⟩ haveI : IsProbabilityMeasure (iidSample uniform01 (N - 1)) := by dsimp [iidSample] infer_instance have hlo := (integrable_endpoint_moments (orderEndpoint_aemeasurable (N - 1) k) (orderEndpoint_mem_Icc (N - 1) k)).1 have hhi := (integrable_endpoint_moments (orderEndpoint_aemeasurable (N - 1) (k + 1)) (orderEndpoint_mem_Icc (N - 1) (k + 1))).1 rw [adjacentOrderMix_integral hN hk hδ (fun u : ℝ => u) hlo hhi, orderEndpoint_mean (N - 1) k (by omega), orderEndpoint_mean (N - 1) (k + 1) (by omega)] have hcast : ((N - 1 : ℕ) : ℝ) + 1 = N := by exact_mod_cast (show N - 1 + 1 = N by omega) rw [hcast] have hne : (N : ℝ) ≠ 0 := by exact_mod_cast (Nat.ne_of_gt hN) field_simp push_cast ring
    Causalean.Stat.OrderStatistic.WeightedConcomitant.adjacentOrderMix_mean · Causalean/Stat/OrderStatistic/WeightedConcomitant/PowerApproximation.lean:228
  • adjacentOrderMix_variance theorem — For a positive sample size, interpolation index, and unit interpolation fraction, the adjacent order-statistic mixture has the stated centered second moment.
    N k :
    ℕ
    hN :
    0 < N
    hk :
    k < N
    δ :
    ℝ
    hδ :
    δ ∈ Icc (0 : ℝ) 1
    (∫ u, (u - ((k + δ) / N)) ^ 2 ∂adjacentOrderMix N k δ)
    = ((k + δ) / N) * (1 - (k + δ) / N) / (N + 1) + δ * (1 - δ) / (N * (N + 1))
    Proof (Lean source)
    theorem adjacentOrderMix_variance {N k : ℕ} (hN : 0 < N) (hk : k < N) {δ : ℝ} (hδ : δ ∈ Icc (0 : ℝ) 1) : (∫ u, (u - ((k + δ) / N)) ^ 2 ∂adjacentOrderMix N k δ) = ((k + δ) / N) * (1 - (k + δ) / N) / (N + 1) + δ * (1 - δ) / (N * (N + 1)) := by haveI : IsProbabilityMeasure uniform01 := ⟨by simp [uniform01]⟩ haveI : IsProbabilityMeasure (iidSample uniform01 (N - 1)) := by dsimp [iidSample] infer_instance let μ := adjacentOrderMix N k δ let m : ℝ := (k + δ) / N have hmass : (∫ _u : ℝ, (1 : ℝ) ∂μ) = 1 := by have hmap (r : ℕ) : (∫ _u : ℝ, (1 : ℝ) ∂(iidSample uniform01 (N - 1)).map (orderEndpoint (N - 1) r)) = 1 := by rw [integral_map (orderEndpoint_aemeasurable (N - 1) r) measurable_const.aestronglyMeasurable] simp change (∫ _u : ℝ, (1 : ℝ) ∂adjacentOrderMix N k δ) = 1 rw [adjacentOrderMix_integral hN hk hδ (fun _ : ℝ => (1 : ℝ)) (integrable_const _) (integrable_const _), hmap k, hmap (k + 1)] ring have hμfinite : IsFiniteMeasure μ := by have hm : (μ univ).toReal = 1 := by simpa [integral_const, Measure.real] using hmass have hne : μ univ ≠ ⊤ := (ENNReal.toReal_ne_zero.mp (by rw [hm]; norm_num)).2 exact ⟨lt_top_iff_ne_top.mpr hne⟩ have hlo1 := (integrable_endpoint_moments (orderEndpoint_aemeasurable (N - 1) k) (orderEndpoint_mem_Icc (N - 1) k)).1 have hhi1 := (integrable_endpoint_moments (orderEndpoint_aemeasurable (N - 1) (k + 1)) (orderEndpoint_mem_Icc (N - 1) (k + 1))).1 have hlo2 := (integrable_endpoint_moments (orderEndpoint_aemeasurable (N - 1) k) (orderEndpoint_mem_Icc (N - 1) k)).2 have hhi2 := (integrable_endpoint_moments (orderEndpoint_aemeasurable (N - 1) (k + 1)) (orderEndpoint_mem_Icc (N - 1) (k + 1))).2 have hI1 : Integrable (fun u : ℝ => u) μ := by change Integrable (fun u : ℝ => u) (adjacentOrderMix N k δ) rw [adjacentOrderMix_eq_endpoints hN hk] exact (hlo1.smul_measure (by simp)).add_measure (hhi1.smul_measure (by simp)) have hI2 : Integrable (fun u : ℝ => u ^ 2) μ := by change Integrable (fun u : ℝ => u ^ 2) (adjacentOrderMix N k δ) rw [adjacentOrderMix_eq_endpoints hN hk] exact (hlo2.smul_measure (by simp)).add_measure (hhi2.smul_measure (by simp)) have hcenter : (∫ u, (u - m) ^ 2 ∂μ) = (∫ u, u ^ 2 ∂μ) - 2 * m * (∫ u, u ∂μ) + m ^ 2 := by calc (∫ u, (u - m) ^ 2 ∂μ) = ∫ u, (u ^ 2 - (2 * m) * u + m ^ 2) ∂μ := by congr 1 funext u ring _ = (∫ u, u ^ 2 ∂μ) - 2 * m * (∫ u, u ∂μ) + m ^ 2 := by have hmul : Integrable (fun u : ℝ => (2 * m) * u) μ := hI1.const_mul _ have hsub : Integrable (fun u : ℝ => u ^ 2 - (2 * m) * u) μ := hI2.sub hmul rw [integral_add hsub (integrable_const (m ^ 2)), integral_sub hI2 hmul, integral_const_mul] have hmreal : μ.real univ = 1 := by simpa [integral_const] using hmass simp [integral_const, hmreal] rw [hcenter, adjacentOrderMix_mean hN hk hδ, adjacentOrderMix_second_moment hN hk hδ] dsimp [m] have hNr : (N : ℝ) ≠ 0 := by exact_mod_cast (Nat.ne_of_gt hN) have hNr1 : (N : ℝ) + 1 ≠ 0 := by positivity field_simp push_cast ring
    Causalean.Stat.OrderStatistic.WeightedConcomitant.adjacentOrderMix_variance · Causalean/Stat/OrderStatistic/WeightedConcomitant/PowerApproximation.lean:279
  • integral_abs_cdf_sub_step_eq_mean_abs theorem — For a probability law supported on the unit interval and a threshold in that interval, the integrated absolute difference between its CDF and the threshold step equals its mean absolute displacement from that threshold.
    hsupp :
    ∀ᵐ x ∂ν, x ∈ Icc (0 : ℝ) 1
    t :
    ℝ
    ht :
    t ∈ Icc (0 : ℝ) 1
    (∫ u in Icc (0 : ℝ) 1, |(ν (Iic u)).toReal - (if t ≤ u then (1 : ℝ) else 0)| ∂volume)
    = ∫ x, |x - t| ∂ν
    Proof (Lean source)
    theorem integral_abs_cdf_sub_step_eq_mean_abs (ν : Measure ℝ) [IsProbabilityMeasure ν] (hsupp : ∀ᵐ x ∂ν, x ∈ Icc (0 : ℝ) 1) {t : ℝ} (ht : t ∈ Icc (0 : ℝ) 1) : (∫ u in Icc (0 : ℝ) 1, |(ν (Iic u)).toReal - (if t ≤ u then (1 : ℝ) else 0)| ∂volume) = ∫ x, |x - t| ∂ν := by have hν : ν (Icc (0 : ℝ) 1)ᶜ = 0 := (ae_iff).mp hsupp have hδ : (Measure.dirac t) (Icc (0 : ℝ) 1)ᶜ = 0 := by simp [ht] have hq : ∀ᵐ u ∂Causalean.Stat.unifOI, quantile (Measure.dirac t) u = t := by filter_upwards [quantile_mem_Icc_ae (Measure.dirac t) (by simp : (Measure.dirac t) (Icc t t)ᶜ = 0)] with u hu exact (Set.mem_Icc.mp hu).2.antisymm (Set.mem_Icc.mp hu).1 have hcost : (∫ u in (0 : ℝ)..1, |quantile ν u - quantile (Measure.dirac t) u|) = ∫ x, |x - t| ∂ν := by have hrest : volume.restrict (Ioc (0 : ℝ) 1) = unifOI := by rw [unifOI, restrict_Ioo_eq_restrict_Ioc] rw [intervalIntegral.integral_of_le (by norm_num : (0 : ℝ) ≤ 1), hrest] have hcongr : (∫ u, |quantile ν u - quantile (Measure.dirac t) u| ∂Causalean.Stat.unifOI) = ∫ u, |quantile ν u - t| ∂Causalean.Stat.unifOI := by apply integral_congr_ae filter_upwards [hq] with u hu rw [hu] calc _ = ∫ u, |quantile ν u - t| ∂Causalean.Stat.unifOI := hcongr _ = ∫ x, |x - t| ∂(Causalean.Stat.unifOI.map (quantile ν)) := by exact (integral_map (aemeasurable_quantile_unifOI ν) (show AEStronglyMeasurable (fun x : ℝ => |x - t|) (Causalean.Stat.unifOI.map (quantile ν)) from by fun_prop)).symm _ = ∫ x, |x - t| ∂ν := by rw [quantile_map_uniform] have htransport := quantile_transport_eq_cdf_distance ν (Measure.dirac t) (by norm_num : (0 : ℝ) ≤ 1) hν hδ rw [hcost] at htransport rw [htransport] rw [MeasureTheory.integral_Icc_eq_integral_Ioc, ← intervalIntegral.integral_of_le (by norm_num : (0 : ℝ) ≤ 1)] congr 1 funext u rw [ProbabilityTheory.cdf_eq_real, ProbabilityTheory.cdf_eq_real] by_cases h : t ≤ u <;> simp [Measure.real, Set.mem_Iic, h]
    Causalean.Stat.OrderStatistic.WeightedConcomitant.integral_abs_cdf_sub_step_eq_mean_abs · Causalean/Stat/OrderStatistic/WeightedConcomitant/PowerApproximation.lean:354
  • adjacentOrderMix_abs_deviation_le_sqrt theorem — The mean absolute displacement of an adjacent order-statistic mixture from its interpolation threshold is bounded by its root mean-square displacement.
    N k :
    ℕ
    hN :
    0 < N
    hk :
    k < N
    δ :
    ℝ
    hδ :
    δ ∈ Icc (0 : ℝ) 1
    (∫ x, |x - ((k + δ) / N)| ∂adjacentOrderMix N k δ)
    ≤ sqrt (((k + δ) / N) * (1 - (k + δ) / N) / (N + 1) + δ * (1 - δ) / (N * (N + 1)))
    Proof (Lean source)
    theorem adjacentOrderMix_abs_deviation_le_sqrt {N k : ℕ} (hN : 0 < N) (hk : k < N) {δ : ℝ} (hδ : δ ∈ Icc (0 : ℝ) 1) : (∫ x, |x - ((k + δ) / N)| ∂adjacentOrderMix N k δ) ≤ sqrt (((k + δ) / N) * (1 - (k + δ) / N) / (N + 1) + δ * (1 - δ) / (N * (N + 1))) := by haveI : IsProbabilityMeasure uniform01 := ⟨by simp [uniform01]⟩ haveI : IsProbabilityMeasure (iidSample uniform01 (N - 1)) := by dsimp [iidSample] infer_instance let μ := adjacentOrderMix N k δ let m : ℝ := (k + δ) / N have hmass : (∫ _u : ℝ, (1 : ℝ) ∂μ) = 1 := by have hmap (r : ℕ) : (∫ _u : ℝ, (1 : ℝ) ∂(iidSample uniform01 (N - 1)).map (orderEndpoint (N - 1) r)) = 1 := by rw [integral_map (orderEndpoint_aemeasurable (N - 1) r) measurable_const.aestronglyMeasurable] simp change (∫ _u : ℝ, (1 : ℝ) ∂adjacentOrderMix N k δ) = 1 rw [adjacentOrderMix_integral hN hk hδ (fun _ : ℝ => (1 : ℝ)) (integrable_const _) (integrable_const _), hmap k, hmap (k + 1)] ring haveI : IsProbabilityMeasure μ := by have hreal : (μ univ).toReal = 1 := by simpa [integral_const, Measure.real] using hmass exact isProbabilityMeasure_iff_real.mpr hreal have hlo1 := (integrable_endpoint_moments (orderEndpoint_aemeasurable (N - 1) k) (orderEndpoint_mem_Icc (N - 1) k)).1 have hhi1 := (integrable_endpoint_moments (orderEndpoint_aemeasurable (N - 1) (k + 1)) (orderEndpoint_mem_Icc (N - 1) (k + 1))).1 have hlo2 := (integrable_endpoint_moments (orderEndpoint_aemeasurable (N - 1) k) (orderEndpoint_mem_Icc (N - 1) k)).2 have hhi2 := (integrable_endpoint_moments (orderEndpoint_aemeasurable (N - 1) (k + 1)) (orderEndpoint_mem_Icc (N - 1) (k + 1))).2 have hI1 : Integrable (fun u : ℝ => u) μ := by change Integrable (fun u : ℝ => u) (adjacentOrderMix N k δ) rw [adjacentOrderMix_eq_endpoints hN hk] exact (hlo1.smul_measure (by simp)).add_measure (hhi1.smul_measure (by simp)) have hI2 : Integrable (fun u : ℝ => u ^ 2) μ := by change Integrable (fun u : ℝ => u ^ 2) (adjacentOrderMix N k δ) rw [adjacentOrderMix_eq_endpoints hN hk] exact (hlo2.smul_measure (by simp)).add_measure (hhi2.smul_measure (by simp)) have hsq : Integrable (fun u : ℝ => (u - m) ^ 2) μ := by have h := (hI2.sub (hI1.const_mul (2 * m))).add (integrable_const (m ^ 2)) have hfun : (fun u : ℝ => (u - m) ^ 2) = (fun u : ℝ => u ^ 2 - (2 * m) * u + m ^ 2) := by funext u ring rw [hfun] exact h have hmeas : AEStronglyMeasurable (fun u : ℝ => u - m) μ := by fun_prop have hL2 : MemLp (fun u : ℝ => u - m) 2 μ := (memLp_two_iff_integrable_sq hmeas).2 hsq have hbound := integral_abs_le_sqrt_integral_sq μ (fun u : ℝ => u - m) hL2 have hsquared : (∫ u, |u - m| ^ 2 ∂μ) = m * (1 - m) / (N + 1) + δ * (1 - δ) / (N * (N + 1)) := by simpa only [sq_abs, m, μ] using adjacentOrderMix_variance hN hk hδ simp only [Real.norm_eq_abs, hsquared, m, μ] at hbound exact hbound
    Causalean.Stat.OrderStatistic.WeightedConcomitant.adjacentOrderMix_abs_deviation_le_sqrt · Causalean/Stat/OrderStatistic/WeightedConcomitant/PowerApproximation.lean:406
  • adjacentOrderMix_indicator_L1_le_sqrt_two_t_over_N theorem — For a positive sample size, adjacent index, and interpolation fraction in the unit interval, the threshold-indicator error is at most the square root of twice the threshold divided by N. This coarse bound isolates the algebra needed to integrate the coupling error against the power curvature, including the deterministic endpoint cases.
    N k :
    ℕ
    hN :
    0 < N
    hk :
    k < N
    δ :
    ℝ
    hδ :
    δ ∈ Icc (0 : ℝ) 1
    (∫ u in Icc (0 : ℝ) 1, |((adjacentOrderMix N k δ) (Iic u)).toReal - (if (k + δ) / N ≤ u then (1 : ℝ) else 0)| ∂volume)
    ≤ sqrt (2 * ((k + δ) / N) / N)
    Proof (Lean source)
    theorem adjacentOrderMix_indicator_L1_le_sqrt_two_t_over_N {N k : ℕ} (hN : 0 < N) (hk : k < N) {δ : ℝ} (hδ : δ ∈ Icc (0 : ℝ) 1) : (∫ u in Icc (0 : ℝ) 1, |((adjacentOrderMix N k δ) (Iic u)).toReal - (if (k + δ) / N ≤ u then (1 : ℝ) else 0)| ∂volume) ≤ sqrt (2 * ((k + δ) / N) / N) := by -- Use `adjacentOrderMix_indicator_L1`, then bound its exact variance by -- `2 * t / N`: the first term is at most `t / N`, and the interpolation -- term is at most `t / N` because `δ ≤ k + δ`. have hNr : (0 : ℝ) < N := by exact_mod_cast hN have hNr1 : (0 : ℝ) < N + 1 := by positivity have ht0 : 0 ≤ (k + δ) / (N : ℝ) := by apply div_nonneg _ (le_of_lt hNr) exact add_nonneg (Nat.cast_nonneg _) hδ.1 have ht1 : (k + δ) / (N : ℝ) ≤ 1 := by apply (div_le_iff₀ hNr).2 have hk' : (k : ℝ) + 1 ≤ N := by exact_mod_cast hk linarith [hδ.2] have hδk : δ ≤ (k : ℝ) + δ := by linarith [Nat.cast_nonneg (α := ℝ) k] have hfirst : ((k + δ) / N) * (1 - (k + δ) / N) / (N + 1) ≤ ((k + δ) / N) / N := by calc _ ≤ ((k + δ) / N) / (N + 1) := by apply div_le_div_of_nonneg_right _ (le_of_lt hNr1) nlinarith [mul_nonneg ht0 (sub_nonneg.mpr ht1)] _ ≤ ((k + δ) / N) / N := by apply div_le_div_of_nonneg_left ht0 hNr linarith have hsecond : δ * (1 - δ) / (N * (N + 1)) ≤ ((k + δ) / N) / N := by calc _ ≤ δ / (N * (N + 1)) := by apply div_le_div_of_nonneg_right _ (by positivity) nlinarith [sq_nonneg δ] _ ≤ (k + δ) / (N * (N + 1)) := by apply div_le_div_of_nonneg_right hδk (by positivity) _ ≤ (k + δ) / (N * N) := by apply div_le_div_of_nonneg_left (add_nonneg (Nat.cast_nonneg _) hδ.1) (by positivity) nlinarith [sq_nonneg (N : ℝ)] _ = ((k + δ) / N) / N := by ring calc _ ≤ sqrt (((k + δ) / N) * (1 - (k + δ) / N) / (N + 1) + δ * (1 - δ) / (N * (N + 1))) := adjacentOrderMix_indicator_L1 hN hk hδ _ ≤ _ := by apply Real.sqrt_le_sqrt have htwo : ((k + δ) / (N : ℝ)) / N + ((k + δ) / N) / N = 2 * ((k + δ) / N) / N := by ring rw [← htwo] exact add_le_add hfirst hsecond
    Causalean.Stat.OrderStatistic.WeightedConcomitant.adjacentOrderMix_indicator_L1_le_sqrt_two_t_over_N · Causalean/Stat/OrderStatistic/WeightedConcomitant/PowerApproximation.lean:532
  • integral_powerDensity theorem — For a real power at least one, the power density integrates to one over the unit interval.
    s :
    ℝ
    hs :
    1 ≤ s
    (∫ u in Icc (0 : ℝ) 1, powerDensity s u ∂volume) = 1
    Proof (Lean source)
    theorem integral_powerDensity {s : ℝ} (hs : 1 ≤ s) : (∫ u in Icc (0 : ℝ) 1, powerDensity s u ∂volume) = 1 := by have h := powerCell_eq_integral (N := 1) (by omega) hs (0 : Fin 1) have hcell : powerCell 1 s (0 : Fin 1) = 1 := by simp [powerCell, Real.zero_rpow (by linarith : s ≠ 0)] rw [hcell] at h simpa [powerDensity, intervalIntegral.integral_of_le, ← integral_Icc_eq_integral_Ioc] using h.symm
    Causalean.Stat.OrderStatistic.WeightedConcomitant.integral_powerDensity · Causalean/Stat/OrderStatistic/WeightedConcomitant/PowerApproximation.lean:591
Power­Cells 2 core · 5 supporting Finite cells of the decreasing power density and their algebraic bounds. ★ sum_powerCell_sq_le

Power cell masses

Finite cells of the decreasing power density and their algebraic bounds.

Proof route: the sum telescopes; the integral identity follows from the real power antiderivative on each cell, including the rightmost endpoint by continuity. Monotonicity follows from the decreasing derivative for s ≥ 1. The first-cell bound is Bernoulli's inequality, then nonnegativity, antitonicity, and unit sum give the square-sum bound.

def powerCell reviewed
Causalean.Stat.OrderStatistic.WeightedConcomitant

For a cell index, sample size, and power, the power cell mass is the drop of the power survival function across that cell.

Definition (Lean source)
N :
ℕ
s :
ℝ
j :
Fin N
powerCell N s j :
ℝ
(1 - (j : ℝ) / N) ^ s - (1 - ((j : ℕ) + 1 : ℝ) / N) ^ s
Causalean.Stat.OrderStatistic.WeightedConcomitant.powerCell · Causalean/Stat/OrderStatistic/WeightedConcomitant/PowerCells.lean:29
theorem sum_powerCell_sq_le reviewed
Causalean.Stat.OrderStatistic.WeightedConcomitant

For a positive sample size and power at least one, the sum of squared power cell masses is at most the power divided by sample size.

Formal statement
N :
ℕ
hN :
0 < N
s :
ℝ
hs :
1 ≤ s
∑ j : Fin N, (powerCell N s j) ^ 2 ≤ s / N
Proof (Lean source)
theorem sum_powerCell_sq_le {N : ℕ} (hN : 0 < N) {s : ℝ} (hs : 1 ≤ s) : ∑ j : Fin N, (powerCell N s j) ^ 2 ≤ s / N := by haveI : NeZero N := ⟨Nat.ne_of_gt hN⟩ have hmax : ∀ j : Fin N, powerCell N s j ≤ s / N := by intro j calc powerCell N s j ≤ powerCell N s ⟨0, hN⟩ := powerCell_antitone hs (Fin.zero_le j) _ ≤ s / N := powerCell_zero_le hN hs calc ∑ j : Fin N, (powerCell N s j) ^ 2 ≤ ∑ j : Fin N, (s / N) * powerCell N s j := by apply Finset.sum_le_sum intro j _ have h₁ := powerCell_nonneg hs j have h₂ := hmax j nlinarith [mul_nonneg h₁ (sub_nonneg.mpr h₂)] _ = s / N := by rw [← Finset.mul_sum, sum_powerCell hN hs, mul_one]
Causalean.Stat.OrderStatistic.WeightedConcomitant.sum_powerCell_sq_le · Causalean/Stat/OrderStatistic/WeightedConcomitant/PowerCells.lean:113 · uses powerCell
5 supporting declarations (lemmas, instances)
  • powerCell_nonneg theorem — For a power at least one, power cells are nonnegative.
    N :
    ℕ
    s :
    ℝ
    hs :
    1 ≤ s
    j :
    Fin N
    0 ≤ powerCell N s j
    Proof (Lean source)
    theorem powerCell_nonneg {N : ℕ} {s : ℝ} (hs : 1 ≤ s) (j : Fin N) : 0 ≤ powerCell N s j := by have hN : (0 : ℝ) < N := by exact_mod_cast Nat.zero_lt_of_lt j.isLt have hj : ((j : ℕ) : ℝ) + 1 ≤ N := by exact_mod_cast j.isLt have hleft : 0 ≤ 1 - ((j : ℝ) + 1) / N := by apply sub_nonneg.mpr exact (div_le_one hN).2 hj have horder : 1 - ((j : ℝ) + 1) / N ≤ 1 - (j : ℝ) / N := by have hdiv : (j : ℝ) / N ≤ ((j : ℝ) + 1) / N := div_le_div_of_nonneg_right (by linarith) hN.le linarith unfold powerCell exact sub_nonneg.mpr (Real.rpow_le_rpow hleft horder (by linarith))
    Causalean.Stat.OrderStatistic.WeightedConcomitant.powerCell_nonneg · Causalean/Stat/OrderStatistic/WeightedConcomitant/PowerCells.lean:34
  • powerCell_antitone theorem — For a power at least one, power cell masses decrease with the cell index.
    N :
    ℕ
    s :
    ℝ
    hs :
    1 ≤ s
    Proof (Lean source)
    theorem powerCell_antitone {N : ℕ} {s : ℝ} (hs : 1 ≤ s) : Antitone (powerCell N s) := by cases N with | zero => intro j; exact elim0 j | succ n => apply Fin.antitone_iff_succ_le.mpr intro i let a : ℝ := 1 - ((i : ℕ) + 2 : ℝ) / (n + 1) let b : ℝ := 1 - ((i : ℕ) + 1 : ℝ) / (n + 1) let c : ℝ := 1 - (i : ℝ) / (n + 1) have hn : (0 : ℝ) < (n + 1 : ℕ) := by positivity have ha : 0 ≤ a := by have hi : (i : ℕ) + 2 ≤ n + 1 := by omega have hi' : (((i : ℕ) + 2 : ℕ) : ℝ) ≤ (n + 1 : ℕ) := by exact_mod_cast hi simpa only [Nat.cast_add, Nat.cast_one, Nat.cast_ofNat] using (sub_nonneg.mpr ((div_le_one hn).2 hi')) have hc : 0 ≤ c := by have hi : (i : ℕ) ≤ n + 1 := by omega have hi' : ((i : ℕ) : ℝ) ≤ (n + 1 : ℕ) := by exact_mod_cast hi simpa only [Nat.cast_add, Nat.cast_one] using (sub_nonneg.mpr ((div_le_one hn).2 hi')) have hm : b = (1 / 2 : ℝ) • a + (1 / 2 : ℝ) • c := by dsimp [a, b, c] ring have hconv := (convexOn_rpow hs).2 ha hc (show (0 : ℝ) ≤ 1 / 2 by norm_num) (show (0 : ℝ) ≤ 1 / 2 by norm_num) (by norm_num : (1 / 2 : ℝ) + 1 / 2 = 1) rw [← hm] at hconv simp only [smul_eq_mul] at hconv have hstep : b ^ s - a ^ s ≤ c ^ s - b ^ s := by linarith convert hstep using 1 all_goals first | rfl | (simp [powerCell, a, b, c, succ, castSucc, Nat.cast_add, add_assoc] <;> ring)
    Causalean.Stat.OrderStatistic.WeightedConcomitant.powerCell_antitone · Causalean/Stat/OrderStatistic/WeightedConcomitant/PowerCells.lean:49
  • sum_powerCell theorem — For a positive sample size and power at least one, the power cell masses sum to one.
    N :
    ℕ
    hN :
    0 < N
    s :
    ℝ
    hs :
    1 ≤ s
    ∑ j : Fin N, powerCell N s j = 1
    Proof (Lean source)
    theorem sum_powerCell {N : ℕ} (hN : 0 < N) {s : ℝ} (hs : 1 ≤ s) : ∑ j : Fin N, powerCell N s j = 1 := by let f : ℕ → ℝ := fun i => (1 - (i : ℝ) / N) ^ s have hsum : (∑ j : Fin N, powerCell N s j) = ∑ i ∈ range N, (f i - f (i + 1)) := by rw [← Fin.sum_univ_eq_sum_range] apply Finset.sum_congr rfl intro j _ simp only [powerCell, f, Nat.cast_add, Nat.cast_one] rw [hsum, Finset.sum_range_sub'] simp [f, ne_of_gt hN, Real.zero_rpow (by linarith : s ≠ 0)]
    Causalean.Stat.OrderStatistic.WeightedConcomitant.sum_powerCell · Causalean/Stat/OrderStatistic/WeightedConcomitant/PowerCells.lean:85
  • powerCell_zero_le theorem — For a positive sample size and power at least one, the first cell mass is at most the power divided by sample size.
    N :
    ℕ
    hN :
    0 < N
    s :
    ℝ
    hs :
    1 ≤ s
    powerCell N s ⟨0, hN⟩ ≤ s / N
    Proof (Lean source)
    theorem powerCell_zero_le {N : ℕ} (hN : 0 < N) {s : ℝ} (hs : 1 ≤ s) : powerCell N s ⟨0, hN⟩ ≤ s / N := by have hNr : (0 : ℝ) < N := by exact_mod_cast hN have hb : -1 ≤ -(1 / (N : ℝ)) := by have : (1 : ℝ) ≤ N := by exact_mod_cast hN have : (1 : ℝ) / N ≤ 1 := (div_le_one hNr).2 this linarith have h := one_add_mul_self_le_rpow_one_add hb hs have h' : 1 - s / (N : ℝ) ≤ (1 - 1 / (N : ℝ)) ^ s := by convert h using 1 <;> ring have h'' : 1 - (1 - 1 / (N : ℝ)) ^ s ≤ s / N := by linarith simpa [powerCell] using h''
    Causalean.Stat.OrderStatistic.WeightedConcomitant.powerCell_zero_le · Causalean/Stat/OrderStatistic/WeightedConcomitant/PowerCells.lean:98
  • powerCell_eq_integral theorem — For a positive sample size, power at least one, and cell, the power cell mass is the integral of the power density over that cell.
    N :
    ℕ
    hN :
    0 < N
    s :
    ℝ
    hs :
    1 ≤ s
    j :
    Fin N
    powerCell N s j = ∫ u in (j : ℝ) / N..(((j : ℕ) + 1 : ℝ) / N), s * (1 - u) ^ (s - 1)
    Proof (Lean source)
    theorem powerCell_eq_integral {N : ℕ} (hN : 0 < N) {s : ℝ} (hs : 1 ≤ s) (j : Fin N) : powerCell N s j = ∫ u in (j : ℝ) / N..(((j : ℕ) + 1 : ℝ) / N), s * (1 - u) ^ (s - 1) := by let a : ℝ := (j : ℝ) / N let b : ℝ := ((j : ℕ) + 1 : ℝ) / N let f : ℝ → ℝ := fun u => -((1 - u) ^ s) let g : ℝ → ℝ := fun u => s * (1 - u) ^ (s - 1) have hN' : (0 : ℝ) < N := by exact_mod_cast hN have hab : a ≤ b := by dsimp [a, b] apply div_le_div_of_nonneg_right _ hN'.le linarith have hf : Continuous f := by exact ((Real.continuous_rpow_const (by linarith : 0 ≤ s)).comp (continuous_const.sub continuous_id)).neg have hg : Continuous g := by exact continuous_const.mul ((Real.continuous_rpow_const (by linarith : 0 ≤ s - 1)).comp (continuous_const.sub continuous_id)) have hderiv : ∀ x ∈ Ioo a b, HasDerivAt f (g x) x := by intro x hx have hb1 : b ≤ 1 := by dsimp [b] apply (div_le_one hN').2 have : (j : ℕ) + 1 ≤ N := j.isLt exact_mod_cast this have hx1 : x < 1 := lt_of_lt_of_le hx.2 hb1 have hlin : HasDerivAt (fun u : ℝ => 1 - u) (-1) x := by convert (hasDerivAt_const x (1 : ℝ)).sub (hasDerivAt_id x) using 1 all_goals first | rfl | ring have hpow := (Real.hasDerivAt_rpow_const (x := 1 - x) (p := s) (inl (by linarith : 1 - x ≠ 0))).comp x hlin convert hpow.neg using 1 all_goals first | rfl | (dsimp [g]; ring) have hInt : IntervalIntegrable g volume a b := hg.continuousOn.intervalIntegrable_of_Icc hab have h := intervalIntegral.integral_eq_sub_of_hasDerivAt_of_le hab hf.continuousOn hderiv hInt dsimp [f, g] at h dsimp [powerCell, a, b] convert h.symm using 1 <;> ring
    Causalean.Stat.OrderStatistic.WeightedConcomitant.powerCell_eq_integral · Causalean/Stat/OrderStatistic/WeightedConcomitant/PowerCells.lean:134
Power­Curvature 3 core · 4 supporting The curvature representation of a real power supplies the integrable threshold weight and the hinge-cell increment used in the finite Bernstein L1 estimate. ★ integral_powerCurvature_mul_sqrt_le

Curvature and hinge cells for real power weights

The curvature representation of a real power supplies the integrable threshold weight and the hinge-cell increment used in the finite Bernstein L1 estimate.

def hingeCell reviewed
Causalean.Stat.OrderStatistic.WeightedConcomitant

For a sample size, threshold, and cell, the cell increment of the positive-part hinge at that threshold is the difference between its values at the cell endpoints.

Definition (Lean source)
N :
ℕ
t :
ℝ
j :
Fin N
hingeCell N t j :
ℝ
max (((((j : ℕ) : ℝ) + 1) / N) - t) 0 - max ((((j : ℕ) : ℝ) / N) - t) 0
Causalean.Stat.OrderStatistic.WeightedConcomitant.hingeCell · Causalean/Stat/OrderStatistic/WeightedConcomitant/PowerCurvature.lean:21
def powerCurvature reviewed
Causalean.Stat.OrderStatistic.WeightedConcomitant

For a real power and threshold, the curvature density of the power CDF is s(s-1)(1-t)^(s-2).

Definition (Lean source)
s t :
ℝ
powerCurvature s t :
ℝ
s * (s - 1) * (1 - t) ^ (s - 2)
Causalean.Stat.OrderStatistic.WeightedConcomitant.powerCurvature · Causalean/Stat/OrderStatistic/WeightedConcomitant/PowerCurvature.lean:28
theorem integral_powerCurvature_mul_sqrt_le reviewed
Causalean.Stat.OrderStatistic.WeightedConcomitant

A real power above one has a curvature-weighted square-root integral bounded by the square root of that power.

Formal statement
s :
ℝ
hs :
1 < s
(∫ t in Icc (0 : ℝ) 1, powerCurvature s t * sqrt t ∂volume) ≤ sqrt s
Proof (Lean source)
theorem integral_powerCurvature_mul_sqrt_le {s : ℝ} (hs : 1 < s) : (∫ t in Icc (0 : ℝ) 1, powerCurvature s t * sqrt t ∂volume) ≤ sqrt s := by have hr : IntervalIntegrable (fun x : ℝ => x ^ (s - 2)) volume 0 1 := intervalIntegral.intervalIntegrable_rpow' (by linarith) have hr' : IntervalIntegrable (fun t : ℝ => (1 - t) ^ (s - 2)) volume 0 1 := by convert (hr.comp_sub_left 1).symm using 1 <;> norm_num have hq : Integrable (powerCurvature s) (volume.restrict (Icc (0 : ℝ) 1)) := by apply (intervalIntegrable_iff_integrableOn_Icc_of_le (by norm_num : (0 : ℝ) ≤ 1)).mp change IntervalIntegrable (fun t : ℝ => s * (s - 1) * (1 - t) ^ (s - 2)) volume 0 1 exact hr'.const_mul (s * (s - 1)) have hpos : ∀ t ∈ Icc (0 : ℝ) 1, 0 ≤ powerCurvature s t := by intro t ht unfold powerCurvature exact mul_nonneg (mul_nonneg (by linarith) (by linarith)) (Real.rpow_nonneg (by linarith [ht.2]) _) have hsm : AEStronglyMeasurable (fun t : ℝ => sqrt t) (volume.restrict (Icc (0 : ℝ) 1)) := by fun_prop have hsqrt : Integrable (fun t : ℝ => powerCurvature s t * sqrt t) (volume.restrict (Icc (0 : ℝ) 1)) := by apply hq.mul_bdd (c := 1) hsm filter_upwards [ae_restrict_mem measurableSet_Icc] with t ht rw [Real.norm_eq_abs, abs_of_nonneg (Real.sqrt_nonneg t)] exact Real.sqrt_le_one.mpr ht.2 have htint : Integrable (fun t : ℝ => t * powerCurvature s t) (volume.restrict (Icc (0 : ℝ) 1)) := by apply hq.bdd_mul (by fun_prop) · filter_upwards [ae_restrict_mem measurableSet_Icc] with t ht rw [Real.norm_eq_abs, abs_of_nonneg ht.1] exact ht.2 have hroot : 0 < sqrt s := Real.sqrt_pos.2 (by linarith) have hbound : ∀ t ∈ Icc (0 : ℝ) 1, powerCurvature s t * sqrt t ≤ (sqrt s / 2) * (t * powerCurvature s t) + (1 / (2 * sqrt s)) * powerCurvature s t := by intro t ht have hsq := sq_nonneg (sqrt s * sqrt t - 1) have htsq : (sqrt t) ^ 2 = t := Real.sq_sqrt ht.1 have hssq : (sqrt s) ^ 2 = s := Real.sq_sqrt (by linarith) have hp := hpos t ht have hroot_ne : sqrt s ≠ 0 := ne_of_gt hroot have hscalar : sqrt t ≤ sqrt s / 2 * t + 1 / (2 * sqrt s) := by calc sqrt t ≤ (s * t + 1) / (2 * sqrt s) := by apply (le_div_iff₀ (by positivity : (0 : ℝ) < 2 * sqrt s)).mpr nlinarith [hsq] _ = sqrt s / 2 * t + 1 / (2 * sqrt s) := by field_simp nlinarith [hssq] calc powerCurvature s t * sqrt t = sqrt t * powerCurvature s t := by ring _ ≤ (sqrt s / 2 * t + 1 / (2 * sqrt s)) * powerCurvature s t := mul_le_mul_of_nonneg_right hscalar hp _ = _ := by ring calc (∫ t in Icc (0 : ℝ) 1, powerCurvature s t * sqrt t ∂volume) ≤ ∫ t in Icc (0 : ℝ) 1, (sqrt s / 2) * (t * powerCurvature s t) + (1 / (2 * sqrt s)) * powerCurvature s t ∂volume := by apply integral_mono_ae hsqrt ((htint.const_mul _).add (hq.const_mul _)) filter_upwards [ae_restrict_mem measurableSet_Icc] with t ht exact hbound t ht _ = sqrt s := by rw [integral_add (htint.const_mul _) (hq.const_mul _), integral_const_mul, integral_const_mul, integral_mul_powerCurvature_unit hs, integral_powerCurvature_unit hs] have hsq : (sqrt s) ^ 2 = s := Real.sq_sqrt (by linarith) field_simp nlinarith
Causalean.Stat.OrderStatistic.WeightedConcomitant.integral_powerCurvature_mul_sqrt_le · Causalean/Stat/OrderStatistic/WeightedConcomitant/PowerCurvature.lean:136 · uses powerCurvature
4 supporting declarations (lemmas, instances)
  • hingeCell_eq_piecewise theorem — For a positive sample size, a hinge-cell increment is its full width below the cell, the remaining width inside it, and zero above it.
    N :
    ℕ
    hN :
    0 < N
    t :
    ℝ
    j :
    Fin N
    hingeCell N t j
    = if t ≤ ((j : ℕ) : ℝ) / (N : ℝ) then (1 : ℝ) / (N : ℝ) else if t ≤ (((j : ℕ) : ℝ) + 1) / N then (((j : ℕ) : ℝ) + 1) / N
    - t else (0 : ℝ)
    Proof (Lean source)
    theorem hingeCell_eq_piecewise {N : ℕ} (hN : 0 < N) (t : ℝ) (j : Fin N) : hingeCell N t j = if t ≤ ((j : ℕ) : ℝ) / (N : ℝ) then (1 : ℝ) / (N : ℝ) else if t ≤ (((j : ℕ) : ℝ) + 1) / N then (((j : ℕ) : ℝ) + 1) / N - t else (0 : ℝ) := by have hNr : (0 : ℝ) < N := by exact_mod_cast hN have hw : (((j : ℕ) : ℝ) / N) ≤ (((j : ℕ) : ℝ) + 1) / N := by apply (div_le_div_iff_of_pos_right hNr).2 linarith unfold hingeCell split_ifs with hleft hmid · rw [max_eq_left (by linarith : 0 ≤ ((((j : ℕ) : ℝ) + 1) / N) - t), max_eq_left (by linarith : 0 ≤ (((j : ℕ) : ℝ) / N) - t)] field_simp ring · rw [max_eq_left (by linarith : 0 ≤ ((((j : ℕ) : ℝ) + 1) / N) - t), max_eq_right (by linarith : (((j : ℕ) : ℝ) / N) - t ≤ 0)] ring · rw [max_eq_right (by linarith : ((((j : ℕ) : ℝ) + 1) / N) - t ≤ 0), max_eq_right (by linarith : (((j : ℕ) : ℝ) / N) - t ≤ 0)] ring
    Causalean.Stat.OrderStatistic.WeightedConcomitant.hingeCell_eq_piecewise · Causalean/Stat/OrderStatistic/WeightedConcomitant/PowerCurvature.lean:33
  • integral_powerCurvature_Icc theorem — For a power above one, integrating its curvature from zero to a point in the unit interval gives the drop of the power density from its initial value.
    s u :
    ℝ
    hs :
    1 < s
    hu :
    u ∈ Icc (0 : ℝ) 1
    (∫ t in Icc (0 : ℝ) u, powerCurvature s t ∂volume) = s - powerDensity s u
    Proof (Lean source)
    theorem integral_powerCurvature_Icc {s u : ℝ} (hs : 1 < s) (hu : u ∈ Icc (0 : ℝ) 1) : (∫ t in Icc (0 : ℝ) u, powerCurvature s t ∂volume) = s - powerDensity s u := by have hpow : -1 < s - 2 := by linarith rw [integral_Icc_eq_integral_Ioc, ← intervalIntegral.integral_of_le hu.1] simp only [powerCurvature, powerDensity] rw [intervalIntegral.integral_const_mul] rw [intervalIntegral.integral_comp_sub_left (fun x : ℝ => x ^ (s - 2)) 1] simp only [sub_zero] rw [integral_rpow (a := 1 - u) (b := 1) (r := s - 2) (inl hpow)] simp only [Real.one_rpow] have hs0 : s - 1 ≠ 0 := by linarith have he : s - 2 + 1 = s - 1 := by ring rw [he] field_simp
    Causalean.Stat.OrderStatistic.WeightedConcomitant.integral_powerCurvature_Icc · Causalean/Stat/OrderStatistic/WeightedConcomitant/PowerCurvature.lean:60
  • integral_powerCurvature_unit theorem — For a real power above one, the curvature density has total mass s on the unit interval.
    s :
    ℝ
    hs :
    1 < s
    (∫ t in Icc (0 : ℝ) 1, powerCurvature s t ∂volume) = s
    Proof (Lean source)
    theorem integral_powerCurvature_unit {s : ℝ} (hs : 1 < s) : (∫ t in Icc (0 : ℝ) 1, powerCurvature s t ∂volume) = s := by rw [integral_powerCurvature_Icc hs (by norm_num)] simp [powerDensity, Real.zero_rpow (by linarith : s - 1 ≠ 0)]
    Causalean.Stat.OrderStatistic.WeightedConcomitant.integral_powerCurvature_unit · Causalean/Stat/OrderStatistic/WeightedConcomitant/PowerCurvature.lean:79
  • integral_mul_powerCurvature_unit theorem — For a real power above one, the first moment of its curvature density on the unit interval is one.
    s :
    ℝ
    hs :
    1 < s
    (∫ t in Icc (0 : ℝ) 1, t * powerCurvature s t ∂volume) = 1
    Proof (Lean source)
    theorem integral_mul_powerCurvature_unit {s : ℝ} (hs : 1 < s) : (∫ t in Icc (0 : ℝ) 1, t * powerCurvature s t ∂volume) = 1 := by have hp : -1 < s - 2 := by linarith have hq : -1 < s - 1 := by linarith have hp0 : s - 1 ≠ 0 := by linarith have hq0 : s ≠ 0 := by linarith calc (∫ t in Icc (0 : ℝ) 1, t * powerCurvature s t ∂volume) = ∫ t in (0 : ℝ)..1, t * (s * (s - 1) * (1 - t) ^ (s - 2)) := by rw [integral_Icc_eq_integral_Ioc, ← intervalIntegral.integral_of_le (by norm_num : (0 : ℝ) ≤ 1)] rfl _ = ∫ x in (0 : ℝ)..1, (1 - x) * (s * (s - 1) * x ^ (s - 2)) := by convert intervalIntegral.integral_comp_sub_left (fun x : ℝ => (1 - x) * (s * (s - 1) * x ^ (s - 2))) 1 (a := 0) (b := 1) using 1 <;> simp _ = ∫ x in (0 : ℝ)..1, (s * (s - 1)) * (x ^ (s - 2) - x ^ (s - 1)) := by apply intervalIntegral.integral_congr intro x hx have hx0 : 0 ≤ x := by have hx' : x ∈ Icc (0 : ℝ) 1 := by simpa only [Set.uIcc_of_le (by norm_num : (0 : ℝ) ≤ 1)] using hx exact hx'.1 have hpow : x ^ (s - 1) = x ^ (s - 2) * x := by rw [show s - 1 = s - 2 + 1 by ring, Real.rpow_add_one' hx0 (by linarith : s - 2 + 1 ≠ 0)] change (1 - x) * (s * (s - 1) * x ^ (s - 2)) = (s * (s - 1)) * (x ^ (s - 2) - x ^ (s - 1)) rw [hpow] ring _ = (s * (s - 1)) * ((∫ x in (0 : ℝ)..1, x ^ (s - 2)) - (∫ x in (0 : ℝ)..1, x ^ (s - 1))) := by rw [intervalIntegral.integral_const_mul, intervalIntegral.integral_sub (intervalIntegral.intervalIntegrable_rpow' hp) (intervalIntegral.intervalIntegrable_rpow' hq)] _ = 1 := by rw [integral_rpow (a := 0) (b := 1) (r := s - 2) (inl hp), integral_rpow (a := 0) (b := 1) (r := s - 1) (inl hq)] have he : s - 2 + 1 = s - 1 := by ring have he' : s - 1 + 1 = s := by ring rw [he, he'] simp [Real.zero_rpow hp0, Real.zero_rpow hq0] field_simp ring
    Causalean.Stat.OrderStatistic.WeightedConcomitant.integral_mul_powerCurvature_unit · Causalean/Stat/OrderStatistic/WeightedConcomitant/PowerCurvature.lean:86
Replacement­Sensitivity 2 core · 3 supporting Exact removal and insertion positions for a replaced observation, followed by tensorized variance under an iid marked sample law. ★ rankConcomitant_replacement_sensitivity

Replacement sensitivity and variance of rank concomitants

Exact removal and insertion positions for a replaced observation, followed by tensorized variance under an iid marked sample law.

Proof route: remove the tagged point, compare the two ordered lists of the remaining points, then insert the old and new marks at their exact ranks. Antitonicity makes all intermediate weight increments one-signed and telescoping. Under continuous CDF transport, all coordinates and independent replacements avoid ties almost surely. Apply the existing tensor variance theorem and use rank exchangeability to sum the squared weights.

def rankPosition reviewed
Causalean.Stat.OrderStatistic.WeightedConcomitant

For a marked sample and observation index, the zero-based rank position is the inverse sorting permutation evaluated at that index.

Definition (Lean source)
N :
ℕ
x :
Fin N → ℝ × ℝ
i :
Fin N
rankPosition x i :
Fin N
(sort (fun j => (x j).1)).symm i
Causalean.Stat.OrderStatistic.WeightedConcomitant.rankPosition · Causalean/Stat/OrderStatistic/WeightedConcomitant/ReplacementSensitivity.lean:31
theorem rankConcomitant_replacement_sensitivity reviewed
Causalean.Stat.OrderStatistic.WeightedConcomitant

For rank weights that are nonnegative and decrease with rank, an original sample, selected coordinate, and replacement with unit-bounded marks, distinct original coordinates, and distinct coordinates after replacement, the statistic changes by at most the removal and insertion weights.

Formal statement
N :
ℕ
a :
Fin N → ℝ
ha :
∀ j, 0 ≤ a j
hmono :
x :
Fin N → ℝ × ℝ
i :
Fin N
y :
ℝ × ℝ
hx :
∀ j, (x j).2 ∈ Icc (0 : ℝ) 1
hy :
y.2 ∈ Icc (0 : ℝ) 1
hinj :
Injective (fun j => (x j).1)
hinj' :
Injective (fun j => ((coordinateReplace i x y) j).1)
Proof (Lean source)
theorem rankConcomitant_replacement_sensitivity {N : ℕ} (a : Fin N → ℝ) (ha : ∀ j, 0 ≤ a j) (hmono : Antitone a) (x : Fin N → ℝ × ℝ) (i : Fin N) (y : ℝ × ℝ) (hx : ∀ j, (x j).2 ∈ Icc (0 : ℝ) 1) (hy : y.2 ∈ Icc (0 : ℝ) 1) (hinj : Injective (fun j => (x j).1)) (hinj' : Injective (fun j => ((coordinateReplace i x y) j).1)) : |rankConcomitant a x - rankConcomitant a (coordinateReplace i x y)| ≤ a (rankPosition x i) + a (rankPosition (coordinateReplace i x y) i) := by classical let x' := coordinateReplace i x y have hback : coordinateReplace i x' (x i) = x := by funext j by_cases hji : j = i · subst j simp [x', coordinateReplace] · simp [x', coordinateReplace, hji] have hsum : (∑ j : Fin N, a (rankPosition x j)) = ∑ j : Fin N, a (rankPosition x' j) := by rw [sum_rankPosition_weights, sum_rankPosition_weights] have hnew : rankConcomitant a x' = (∑ j ∈ (Finset.univ : Finset (Fin N)).erase i, a (rankPosition x' j) * (x j).2) + a (rankPosition x' i) * y.2 := by rw [rankConcomitant_eq_sum_rankPosition, ← Finset.sum_erase_add Finset.univ _ (Finset.mem_univ i)] congr 1 · apply Finset.sum_congr rfl intro j hj have hji : j ≠ i := (Finset.mem_erase.mp hj).1 simp [x', coordinateReplace, hji] · simp [x', coordinateReplace] rcases le_total (x i).1 y.1 with hxy | hyx · have hcd : ∀ j, j ≠ i → a (rankPosition x j) ≤ a (rankPosition x' j) := by intro j hji exact hmono (rankPosition_replace_le x i j y hji hxy hinj hinj') have hb := weighted_replacement_bound (fun j => a (rankPosition x j)) (fun j => a (rankPosition x' j)) (fun j => (x j).2) i y.2 (fun j => ha _) (fun j => ha _) hx hy hcd hsum rw [rankConcomitant_eq_sum_rankPosition, hnew] exact hb · have hcd : ∀ j, j ≠ i → a (rankPosition x' j) ≤ a (rankPosition x j) := by intro j hji apply hmono simpa only [hback] using (rankPosition_replace_le x' i j (x i) hji (by simpa [x', coordinateReplace] using hyx) hinj' (by simpa [hback] using hinj)) have hmark : ∀ j, (x' j).2 ∈ Icc (0 : ℝ) 1 := by intro j by_cases hji : j = i · subst j simpa [x', coordinateReplace] using hy · simpa [x', coordinateReplace, hji] using hx j have hold : rankConcomitant a x = (∑ j ∈ (Finset.univ : Finset (Fin N)).erase i, a (rankPosition x j) * (x' j).2) + a (rankPosition x i) * (x i).2 := by rw [rankConcomitant_eq_sum_rankPosition, ← Finset.sum_erase_add Finset.univ _ (Finset.mem_univ i)] congr 1 apply Finset.sum_congr rfl intro j hj have hji : j ≠ i := (Finset.mem_erase.mp hj).1 simp [x', coordinateReplace, hji] have hb := weighted_replacement_bound (fun j => a (rankPosition x' j)) (fun j => a (rankPosition x j)) (fun j => (x' j).2) i (x i).2 (fun j => ha _) (fun j => ha _) hmark (hx i) hcd hsum.symm change |rankConcomitant a x - rankConcomitant a x'| ≤ a (rankPosition x i) + a (rankPosition x' i) calc |rankConcomitant a x - rankConcomitant a x'| = |rankConcomitant a x' - rankConcomitant a x| := abs_sub_comm _ _ _ = |(∑ j : Fin N, a (rankPosition x' j) * (x' j).2) - ((∑ j ∈ (Finset.univ : Finset (Fin N)).erase i, a (rankPosition x j) * (x' j).2) + a (rankPosition x i) * (x i).2)| := by rw [rankConcomitant_eq_sum_rankPosition, hold] _ ≤ _ := by simpa only [add_comm] using hb
Causalean.Stat.OrderStatistic.WeightedConcomitant.rankConcomitant_replacement_sensitivity · Causalean/Stat/OrderStatistic/WeightedConcomitant/ReplacementSensitivity.lean:137 · uses coordinateReplace , rankConcomitant , rankPosition
3 supporting declarations (lemmas, instances)
  • rankPosition_val_eq_card_lt theorem — For distinct sorting coordinates, the zero-based rank of a tagged observation is the number of observations with a smaller coordinate.
    N :
    ℕ
    x :
    Fin N → ℝ × ℝ
    i :
    Fin N
    hinj :
    Injective (fun j => (x j).1)
    (rankPosition x i).val
    = ((Finset.univ : Finset (Fin N)).filter (fun j => (x j).1 < (x i).1)).card
    Proof (Lean source)
    theorem rankPosition_val_eq_card_lt {N : ℕ} (x : Fin N → ℝ × ℝ) (i : Fin N) (hinj : Injective (fun j => (x j).1)) : (rankPosition x i).val = ((Finset.univ : Finset (Fin N)).filter (fun j => (x j).1 < (x i).1)).card := by classical let f : Fin N → ℝ := fun j => (x j).1 let σ := Tuple.sort f have hs : StrictMono (f ∘ σ) := (Tuple.monotone_sort f).strictMono_of_injective (hinj.comp σ.injective) have hcard : ((Finset.univ : Finset (Fin N)).filter (fun j => f j < f i)).card = ((Finset.univ : Finset (Fin N)).filter (fun j => j < σ.symm i)).card := by apply Finset.card_equiv σ.symm intro j simp only [mem_filter, Finset.mem_univ, true_and] simpa only [Function.comp_apply, Equiv.apply_symm_apply] using (hs.lt_iff_lt (a := σ.symm j) (b := σ.symm i)) rw [hcard] change (σ.symm i).val = ((Finset.univ : Finset (Fin N)).filter (fun j : Fin N => j.val < (σ.symm i).val)).card rw [Fin.card_filter_val_lt] exact (Nat.min_eq_right (le_of_lt (σ.symm i).isLt)).symm
    Causalean.Stat.OrderStatistic.WeightedConcomitant.rankPosition_val_eq_card_lt · Causalean/Stat/OrderStatistic/WeightedConcomitant/ReplacementSensitivity.lean:36
  • rankConcomitant_memLp_two theorem — For an iid marked observation law with unit-bounded marks, a rank-weighted concomitant has a square-integrable law.
    N :
    ℕ
    μ :
    hmark :
    ∀ᵐ p ∂μ, p.2 ∈ Icc (0 : ℝ) 1
    a :
    Fin N → ℝ
    MemLp (rankConcomitant a) 2 (Measure.pi (fun _ : Fin N => μ))
    Proof (Lean source)
    theorem rankConcomitant_memLp_two {N : ℕ} (μ : Measure (ℝ × ℝ)) [IsProbabilityMeasure μ] (hmark : ∀ᵐ p ∂μ, p.2 ∈ Icc (0 : ℝ) 1) (a : Fin N → ℝ) : MemLp (rankConcomitant a) 2 (Measure.pi (fun _ : Fin N => μ)) := by classical let P : Measure (Fin N → ℝ × ℝ) := Measure.pi (fun _ : Fin N => μ) letI : MeasurableSpace (Perm (Fin N)) := ⊤ have hsort : Measurable (fun x : Fin N → ℝ × ℝ => sort (fun i => (x i).1)) := by apply measurable_to_countable' intro σ have hEq : {x : Fin N → ℝ × ℝ | sort (fun i => (x i).1) = σ} = {x | Monotone ((fun i => (x i).1) ∘ σ) ∧ ∀ i j : Fin N, i < j → (x (σ i)).1 = (x (σ j)).1 → σ i < σ j} := by ext x simpa only [Set.mem_setOf_eq, eq_comm] using (Tuple.eq_sort_iff (f := fun i => (x i).1) (σ := σ)) rw [show (fun x : Fin N → ℝ × ℝ => sort (fun i => (x i).1)) ⁻¹' {σ} = {x | sort (fun i => (x i).1) = σ} by rfl, hEq] apply MeasurableSet.inter · change MeasurableSet {x : Fin N → ℝ × ℝ | ∀ i j : Fin N, i ≤ j → (x (σ i)).1 ≤ (x (σ j)).1} have hh : MeasurableSet (⋂ i : Fin N, ⋂ j : Fin N, {x : Fin N → ℝ × ℝ | i ≤ j → (x (σ i)).1 ≤ (x (σ j)).1}) := by apply MeasurableSet.iInter intro i apply MeasurableSet.iInter intro j by_cases hij : i ≤ j · simpa only [hij, true_implies, Function.comp_apply] using measurableSet_le (measurable_fst.comp (measurable_pi_apply (σ i))) (measurable_fst.comp (measurable_pi_apply (σ j))) · simp [hij] simpa only [Set.iInter_setOf] using hh · change MeasurableSet {x : Fin N → ℝ × ℝ | ∀ i j : Fin N, i < j → (x (σ i)).1 = (x (σ j)).1 → σ i < σ j} have hh : MeasurableSet (⋂ i : Fin N, ⋂ j : Fin N, {x : Fin N → ℝ × ℝ | i < j → (x (σ i)).1 = (x (σ j)).1 → σ i < σ j}) := by apply MeasurableSet.iInter intro i apply MeasurableSet.iInter intro j by_cases hij : i < j · by_cases hσ : σ i < σ j · simp [hσ] · have heq : MeasurableSet {x : Fin N → ℝ × ℝ | (x (σ i)).1 = (x (σ j)).1} := by simpa only [Function.comp_apply] using (measurableSet_eq_fun (measurable_fst.comp (measurable_pi_apply (σ i))) (measurable_fst.comp (measurable_pi_apply (σ j)))) convert heq.compl using 1 <;> ext x <;> simp [hij, hσ] · simp [hij] simpa only [Set.iInter_setOf] using hh have hstat : Measurable (rankConcomitant a : (Fin N → ℝ × ℝ) → ℝ) := by unfold rankConcomitant apply Finset.measurable_sum intro j _ apply measurable_const.mul have hsel : Measurable (fun x : Fin N → ℝ × ℝ => ∑ i : Fin N, if sort (fun k => (x k).1) j = i then (x i).2 else 0) := by apply Finset.measurable_sum intro i _ apply Measurable.ite · exact measurableSet_eq_fun ((measurable_of_finite (fun σ : Perm (Fin N) => σ j)).comp hsort) measurable_const · exact measurable_snd.comp (measurable_pi_apply i) · exact measurable_const convert hsel using 1 funext x simp have hcoord (i : Fin N) : ∀ᵐ x ∂P, (x i).2 ∈ Icc (0 : ℝ) 1 := by exact (Measure.tendsto_eval_ae_ae (μ := fun _ : Fin N => μ) (i := i)).eventually hmark have hbound : ∀ᵐ x ∂P, ‖rankConcomitant a x‖ ≤ ∑ j : Fin N, |a j| := by have hall : ∀ᵐ x ∂P, ∀ i : Fin N, (x i).2 ∈ Icc (0 : ℝ) 1 := by exact Filter.eventually_all.mpr hcoord filter_upwards [hall] with x hx rw [Real.norm_eq_abs] calc |rankConcomitant a x| ≤ ∑ j : Fin N, |a j * (x (sort (fun i => (x i).1) j)).2| := by exact Finset.abs_sum_le_sum_abs _ _ _ ≤ ∑ j : Fin N, |a j| := by apply Finset.sum_le_sum intro j _ rw [abs_mul] have hm := hx (sort (fun i => (x i).1) j) have habs : |(x (sort (fun i => (x i).1) j)).2| ≤ 1 := by rw [abs_le] constructor <;> linarith [hm.1, hm.2] nlinarith [abs_nonneg (a j)] exact MemLp.of_bound hstat.aestronglyMeasurable _ hbound
    Causalean.Stat.OrderStatistic.WeightedConcomitant.rankConcomitant_memLp_two · Causalean/Stat/OrderStatistic/WeightedConcomitant/ReplacementSensitivity.lean:222
  • integral_rankPosition_weight_sq theorem — For a positive iid sample size and continuous sorting-coordinate CDF, each tagged observation has uniform rank, so its squared rank weight averages to the mean squared cell weight.
    N :
    ℕ
    hN :
    0 < N
    μ :
    hcont :
    Continuous (fun t => cdf (μ.map fst) t)
    a :
    Fin N → ℝ
    i :
    Fin N
    (∫ x, (a (rankPosition x i)) ^ 2 ∂Measure.pi (fun _ : Fin N => μ))
    = (∑ j : Fin N, (a j) ^ 2) / N
    Proof (Lean source)
    theorem integral_rankPosition_weight_sq {N : ℕ} (hN : 0 < N) (μ : Measure (ℝ × ℝ)) [IsProbabilityMeasure μ] (hcont : Continuous (fun t => cdf (μ.map fst) t)) (a : Fin N → ℝ) (i : Fin N) : (∫ x, (a (rankPosition x i)) ^ 2 ∂Measure.pi (fun _ : Fin N => μ)) = (∑ j : Fin N, (a j) ^ 2) / N := by -- Transport to iid uniforms and integrate over the finite rank partition. classical let P : Measure (Fin N → ℝ × ℝ) := Measure.pi (fun _ : Fin N => μ) let Q : Measure (Fin N → ℝ) := Causalean.Stat.OrderStatistic.iidSample Causalean.Stat.OrderStatistic.uniform01 N let F : (Fin N → ℝ × ℝ) → (Fin N → ℝ) := fun x k => cdf (μ.map fst) (x k).1 let r : (Fin N → ℝ) → Fin N := fun u => (sort u).symm i have hF : Measurable F := by apply measurable_pi_iff.mpr intro k exact hcont.measurable.comp (measurable_fst.comp (measurable_pi_apply k)) have hrank (j : Fin N) : NullMeasurableSet {u | r u = j} Q := by let E : Set (Fin N → ℝ) := {u | (((Finset.univ : Finset (Fin N)).erase i).filter (fun k => u k < u i)).card = j.val} have hE : MeasurableSet E := by dsimp [E] apply measurableSet_eq_fun · simp_rw [Finset.card_filter] apply Finset.measurable_sum intro k _ apply Measurable.ite · exact measurableSet_lt (measurable_pi_apply k) (measurable_pi_apply i) · exact measurable_const · exact measurable_const · exact measurable_const apply hE.nullMeasurableSet.congr filter_upwards [iid_uniform_coordinates_injective_ae (N := N)] with u hu apply propext change (((Finset.univ : Finset (Fin N)).erase i).filter (fun k => u k < u i)).card = j.val ↔ r u = j rw [← uniform_tagged_rank_eq_count u i hu] exact Fin.ext_iff.symm have hr : AEMeasurable r Q := by apply NullMeasurable.aemeasurable change @Measurable (NullMeasurableSpace (Fin N → ℝ) Q) (Fin N) _ _ r apply measurable_to_countable' intro j exact hrank j have htransport : P.map F = Q := cdf_transport_iid μ hcont have hmass (j : Fin N) : (Q.map r) {j} = ofReal (1 / (N : ℝ)) := by rw [Measure.map_apply₀ hr (measurableSet_singleton j).nullMeasurableSet] exact uniform_tagged_rank_mass hN i j haveI : IsProbabilityMeasure Q := by haveI : IsProbabilityMeasure Causalean.Stat.OrderStatistic.uniform01 := ⟨by simp [Causalean.Stat.OrderStatistic.uniform01]⟩ dsimp [Q, Causalean.Stat.OrderStatistic.iidSample] infer_instance haveI : IsProbabilityMeasure (Q.map r) := Measure.isProbabilityMeasure_map hr have hfin : Integrable (fun j : Fin N => (a j) ^ 2) (Q.map r) := Integrable.of_finite calc (∫ x, (a (rankPosition x i)) ^ 2 ∂P) = ∫ x, (a (r (F x))) ^ 2 ∂P := by apply integral_congr_ae filter_upwards [sort_cdf_eq_ae μ hcont] with x hx simp only [rankPosition, r, F, hx] _ = ∫ u, (a (r u)) ^ 2 ∂Q := by have hstrong : AEStronglyMeasurable (fun u => (a (r u)) ^ 2) Q := ((measurable_of_countable (fun j : Fin N => (a j) ^ 2)).comp_aemeasurable hr).aestronglyMeasurable rw [← htransport] rw [← htransport] at hstrong exact (integral_map hF.aemeasurable hstrong).symm _ = ∫ j, (a j) ^ 2 ∂Q.map r := by exact (integral_map hr ((measurable_of_countable (fun j : Fin N => (a j) ^ 2)).aestronglyMeasurable)).symm _ = (∑ j : Fin N, (a j) ^ 2) / N := by rw [integral_fintype hfin] have hnonneg : 0 ≤ (1 / (N : ℝ)) := by positivity simp only [Measure.real, hmass, ENNReal.toReal_ofReal hnonneg, smul_eq_mul] rw [← Finset.mul_sum] ring
    Causalean.Stat.OrderStatistic.WeightedConcomitant.integral_rankPosition_weight_sq · Causalean/Stat/OrderStatistic/WeightedConcomitant/ReplacementSensitivity.lean:323
Ae­Descent 1 core · 2 supporting These two measure-transport facts isolate the descent of an equality of possibly nonmeasurable versions. ★ ae_eq_of_comp_continuous_cdf

Almost-everywhere descent through a marginal and a continuous CDF

These two measure-transport facts isolate the descent of an equality of possibly nonmeasurable versions. The target equality itself must be proved almost everywhere; no global measurability of either version is assumed.

theorem ae_eq_of_comp_continuous_cdf reviewed
Causalean.Stat.OrderStatistic.WeightedConcomitant

A real probability law with a continuous CDF carries two real functions that agree after CDF composition to agreement under the unit-uniform law.

Formal statement
hcont :
Continuous (fun t => cdf ν t)
f g :
ℝ → ℝ
h :
(fun t => f (cdf ν t)) =ᵐ[ν] (fun t => g (cdf ν t))
f =ᵐ[uniform01] g
Proof (Lean source)
theorem ae_eq_of_comp_continuous_cdf (ν : Measure ℝ) [IsProbabilityMeasure ν] (hcont : Continuous (fun t => cdf ν t)) (f g : ℝ → ℝ) (h : (fun t => f (cdf ν t)) =ᵐ[ν] (fun t => g (cdf ν t))) : f =ᵐ[uniform01] g := by let ρ : Measure ℝ := unifOI change (∀ᵐ t ∂ν, f (cdf ν t) = g (cdf ν t)) at h have hq : (fun u => f (cdf ν (quantile ν u))) =ᵐ[ρ] (fun u => g (cdf ν (quantile ν u))) := by have h' := ae_of_ae_map (aemeasurable_quantile_unifOI ν) (p := fun t => f (cdf ν t) = g (cdf ν t)) (by simpa only [quantile_map_uniform] using h) change (∀ᵐ u ∂ρ, f (cdf ν (quantile ν u)) = g (cdf ν (quantile ν u))) exact h' have hc : (fun u => cdf ν (quantile ν u)) =ᵐ[ρ] id := by filter_upwards [ae_restrict_mem measurableSet_Ioo] with u hu exact Causalean.Stat.cdf_quantile_eq ν hu.1 hu.2 hcont.continuousAt have hfg : f =ᵐ[ρ] g := by filter_upwards [hq, hc] with u heq hid simpa only [id_eq, hid] using heq change f =ᵐ[volume.restrict (Icc (0 : ℝ) 1)] g rw [← restrict_Ioo_eq_restrict_Icc] exact hfg
Causalean.Stat.OrderStatistic.WeightedConcomitant.ae_eq_of_comp_continuous_cdf · Causalean/Stat/OrderStatistic/WeightedConcomitant/AeDescent.lean:64 · uses uniform01
2 supporting declarations (lemmas, instances)
  • fst_null_of_preimage_null theorem — For a probability law on real pairs, a set of first-coordinate values whose full inverse image is null is itself null under the first marginal.
    μ :
    s :
    Set ℝ
    hs :
    μ (fst ⁻¹' s) = 0
    (μ.map fst) s = 0
    Proof (Lean source)
    theorem fst_null_of_preimage_null (μ : Measure (ℝ × ℝ)) [IsProbabilityMeasure μ] (s : Set ℝ) (hs : μ (fst ⁻¹' s) = 0) : (μ.map fst) s = 0 := by obtain ⟨t, hst, htm, ht0⟩ := exists_measurable_superset_of_null hs let u : Set ℝ := {x | μ.condKernel x {y | (x, y) ∈ t} ≠ 0} have hF : Measurable (fun x => μ.condKernel x {y | (x, y) ∈ t}) := ProbabilityTheory.Kernel.measurable_kernel_prodMk_left (κ := μ.condKernel) htm have hu : MeasurableSet u := (measurableSet_singleton (0 : ENNReal)).compl.preimage hF have hsu : s ⊆ u := by intro x hx have hf : {y : ℝ | (x, y) ∈ t} = univ := by ext y simp only [Set.mem_ofPred_eq, Set.mem_univ, iff_true] exact hst hx simp only [u, Set.mem_ofPred_eq, hf] simp have hu0 : μ.fst u = 0 := by have hi : (∫⁻ x, μ.condKernel x {y | (x, y) ∈ t} ∂μ.fst) = 0 := by rw [μ.lintegral_condKernel_mem htm, ht0] have hae := (lintegral_eq_zero_iff hF).mp hi exact (ae_iff).mp (hae.mono fun x hx => by change μ.condKernel x {y | (x, y) ∈ t} = 0 at hx exact hx) apply le_antisymm _ zero_le calc (μ.map fst) s ≤ (μ.map fst) u := measure_mono hsu _ = μ.fst u := rfl _ = 0 := hu0
    Causalean.Stat.OrderStatistic.WeightedConcomitant.fst_null_of_preimage_null · Causalean/Stat/OrderStatistic/WeightedConcomitant/AeDescent.lean:22
  • ae_eq_of_comp_fst theorem — If two real functions of the first coordinate agree almost surely under a probability law on real pairs, then they agree almost surely under its first marginal.
    μ :
    f g :
    ℝ → ℝ
    h :
    (fun p : ℝ × ℝ => f p.1) =ᵐ[μ] (fun p => g p.1)
    f =ᵐ[μ.map fst] g
    Proof (Lean source)
    theorem ae_eq_of_comp_fst (μ : Measure (ℝ × ℝ)) [IsProbabilityMeasure μ] (f g : ℝ → ℝ) (h : (fun p : ℝ × ℝ => f p.1) =ᵐ[μ] (fun p => g p.1)) : f =ᵐ[μ.map fst] g := by apply (ae_iff).2 exact fst_null_of_preimage_null μ {t | f t ≠ g t} (by simpa only [Set.preimage_setOf_eq, ne_eq] using (ae_iff).mp h)
    Causalean.Stat.OrderStatistic.WeightedConcomitant.ae_eq_of_comp_fst · Causalean/Stat/OrderStatistic/WeightedConcomitant/AeDescent.lean:54
Concomitant­Expectation 1 core · 1 supporting This module turns the tagged conditional-mean identity into the Bernstein-kernel expectation formula for a complete finite marked sample. ★ integral_rankConcomitant_eq_bernstein

Bernstein expectation of rank-weighted concomitants

This module turns the tagged conditional-mean identity into the Bernstein-kernel expectation formula for a complete finite marked sample.

theorem integral_rankConcomitant_eq_bernstein reviewed
Causalean.Stat.OrderStatistic.WeightedConcomitant

For positive sample size, marked observation law, continuous sorting-coordinate CDF, bounded marks, cell weights, and a conditional mean version, the expected concomitant equals the Bernstein integral.

Formal statement
N :
ℕ
hN :
0 < N
μ :
hcont :
Continuous (fun t => cdf (μ.map fst) t)
hmark :
∀ᵐ p ∂μ, p.2 ∈ Icc (0 : ℝ) 1
a :
Fin N → ℝ
m :
ℝ → ℝ
hm :
(fun p : ℝ × ℝ => m (cdf (μ.map fst) p.1))
=ᵐ[μ] μ[(fun p : ℝ × ℝ => p.2) | comap (fun p : ℝ × ℝ => cdf (μ.map fst) p.1) inferInstance]
(∫ x, rankConcomitant a x ∂Measure.pi (fun _ : Fin N => μ))
= ∫ u in Icc (0 : ℝ) 1, m u * bernsteinCell N a u ∂volume
Proof (Lean source)
theorem integral_rankConcomitant_eq_bernstein {N : ℕ} (hN : 0 < N) (μ : Measure (ℝ × ℝ)) [IsProbabilityMeasure μ] (hcont : Continuous (fun t => cdf (μ.map fst) t)) (hmark : ∀ᵐ p ∂μ, p.2 ∈ Icc (0 : ℝ) 1) (a : Fin N → ℝ) (m : ℝ → ℝ) (hm : (fun p : ℝ × ℝ => m (cdf (μ.map fst) p.1)) =ᵐ[μ] μ[(fun p : ℝ × ℝ => p.2) | comap (fun p : ℝ × ℝ => cdf (μ.map fst) p.1) inferInstance]) : (∫ x, rankConcomitant a x ∂Measure.pi (fun _ : Fin N => μ)) = ∫ u in Icc (0 : ℝ) 1, m u * bernsteinCell N a u ∂volume := by classical let ν : Measure (Fin N → ℝ × ℝ) := Measure.pi (fun _ => μ) haveI : IsProbabilityMeasure uniform01 := ⟨by simp [uniform01]⟩ let ρ : Measure (Fin N → ℝ) := iidSample uniform01 N haveI : IsProbabilityMeasure ρ := by dsimp [ρ, iidSample] infer_instance let F : ℝ × ℝ → ℝ := fun p => cdf (μ.map fst) p.1 let T : (Fin N → ℝ × ℝ) → (Fin N → ℝ) := fun x i => F (x i) have hT : Measurable T := measurable_pi_iff.mpr fun i => hcont.measurable.comp (measurable_fst.comp (measurable_pi_apply i)) have hmap : ν.map T = ρ := cdf_transport_iid μ hcont have hm_meas : AEMeasurable m uniform01 := aemeasurable_conditionalMean_uniform μ hcont m hm have hm_bound : ∀ᵐ u ∂uniform01, |m u| ≤ 1 := (conditionalMean_mem_Icc_ae μ hcont hmark m hm).mono fun u hu => abs_le.mpr ⟨by linarith [hu.1], hu.2⟩ let g := hm_meas.mk m have hg : Measurable g := hm_meas.measurable_mk have hmg : m =ᵐ[uniform01] g := hm_meas.ae_eq_mk let B (j : Fin N) (u : ℝ) : ℝ := (choose (N - 1) j.val : ℝ) * u ^ j.val * (1 - u) ^ (N - 1 - j.val) let Q (i j : Fin N) (u : Fin N → ℝ) : ℝ := if (sort u).symm i = j then m (u i) else 0 have htag_meas (i j : Fin N) : AEStronglyMeasurable (Q i j) ρ := by let C : Set (Fin N → ℝ) := {u | (((Finset.univ : Finset (Fin N)).erase i).filter (fun k => u k < u i)).card = j.val} have hC : MeasurableSet C := by apply measurableSet_eq_fun · simp_rw [Finset.card_filter] apply Finset.measurable_sum intro k _ apply Measurable.ite · exact measurableSet_lt (measurable_pi_apply k) (measurable_pi_apply i) · exact measurable_const · exact measurable_const · exact measurable_const have hcoord : ∀ᵐ u ∂ρ, m (u i) = g (u i) := by apply ae_of_ae_map (μ := ρ) (f := fun u : Fin N → ℝ => u i) (p := fun v => m v = g v) (measurable_pi_apply i).aemeasurable have heval : ρ.map (fun u : Fin N → ℝ => u i) = uniform01 := (measurePreserving_eval (fun _ : Fin N => uniform01) i).map_eq rw [heval] exact hmg have haux : AEStronglyMeasurable (fun u : Fin N → ℝ => if u ∈ C then m (u i) else 0) ρ := by have haux' : AEStronglyMeasurable (fun u : Fin N → ℝ => if u ∈ C then g (u i) else 0) ρ := ((hg.comp (measurable_pi_apply i)).ite hC measurable_const).aestronglyMeasurable apply haux'.congr filter_upwards [hcoord] with u hu by_cases hc : u ∈ C <;> simp [hc, hu] apply haux.congr filter_upwards [iid_uniform_coordinates_injective_ae (N := N)] with u hu have hiff : (sort u).symm i = j ↔ u ∈ C := by change (sort u).symm i = j ↔ (((Finset.univ : Finset (Fin N)).erase i).filter (fun k => u k < u i)).card = j.val rw [← uniform_tagged_rank_eq_count u i hu] exact Fin.ext_iff simp [Q, hiff] have htag_int (i j : Fin N) : Integrable (Q i j) ρ := by apply Integrable.of_bound (htag_meas i j) 1 have hcoord : ∀ᵐ u ∂ρ, |m (u i)| ≤ 1 := by apply ae_of_ae_map (μ := ρ) (f := fun u : Fin N → ℝ => u i) (p := fun v => |m v| ≤ 1) (measurable_pi_apply i).aemeasurable have heval : ρ.map (fun u : Fin N → ℝ => u i) = uniform01 := (measurePreserving_eval (fun _ : Fin N => uniform01) i).map_eq rw [heval] exact hm_bound filter_upwards [hcoord] with u hu by_cases h : (sort u).symm i = j · simpa [Q, h, Real.norm_eq_abs] using hu · simp [Q, h] have hterm (i j : Fin N) : (∫ x, (if (sort (fun k => (x k).1)).symm i = j then m (F (x i)) else 0) ∂ν) = ∫ u in Icc (0 : ℝ) 1, m u * B j u ∂volume := by calc _ = ∫ x, Q i j (T x) ∂ν := by apply integral_congr_ae filter_upwards [sort_cdf_eq_ae μ hcont] with x hx simp only [Q, T, F, ← hx] _ = ∫ u, Q i j u ∂ρ := by have hh : (∫ u, Q i j u ∂ν.map T) = ∫ x, Q i j (T x) ∂ν := integral_map hT.aemeasurable (by rw [hmap]; exact htag_meas i j) rw [hmap] at hh exact hh.symm _ = _ := uniform_tagged_rank_cell_integral hN i j m hm_meas hm_bound have hpoint (x : Fin N → ℝ × ℝ) (z : Fin N → ℝ) : (∑ j : Fin N, a j * z ((sort (fun k => (x k).1)) j)) = ∑ i : Fin N, ∑ j : Fin N, if (sort (fun k => (x k).1)).symm i = j then a j * z i else 0 := by let σ := sort (fun k => (x k).1) have h := Equiv.sum_comp σ (fun i : Fin N => ∑ j : Fin N, if σ.symm i = j then a j * z i else 0) simpa only [σ, Equiv.symm_apply_apply, Finset.sum_ite_eq, Finset.mem_univ, if_true] using h have hmean_int (i j : Fin N) : Integrable (fun x : Fin N → ℝ × ℝ => if (sort (fun k => (x k).1)).symm i = j then a j * m (F (x i)) else 0) ν := by have hcomp : Integrable (fun x => a j * Q i j (T x)) ν := by have hi := (htag_int i j).const_mul (a j) have hi' : Integrable (fun u => a j * Q i j u) (ν.map T) := by rw [hmap] exact hi simpa only [Function.comp_def] using hi'.comp_aemeasurable hT.aemeasurable apply hcomp.congr filter_upwards [sort_cdf_eq_ae μ hcont] with x hx simp only [Q, T, F, ← hx] split_ifs <;> simp have hm_int : Integrable m uniform01 := by apply Integrable.of_bound hm_meas.aestronglyMeasurable 1 simpa only [Real.norm_eq_abs] using hm_bound have hrhs_int (j : Fin N) : IntegrableOn (fun u => m u * (a j * B j u)) (Icc (0 : ℝ) 1) volume := by have hB : Continuous (B j) := by dsimp [B] fun_prop have hmI : IntegrableOn m (Icc (0 : ℝ) 1) volume := by change Integrable m (volume.restrict (Icc (0 : ℝ) 1)) simpa only [uniform01] using hm_int exact hmI.mul_continuousOn (continuous_const.mul hB).continuousOn isCompact_Icc calc (∫ x, rankConcomitant a x ∂ν) = ∫ x, ∑ j : Fin N, a j * m (F (x (sort (fun i => (x i).1) j))) ∂ν := integral_rankConcomitant_eq_conditionalMean μ hcont hmark a m hm _ = ∫ x, ∑ i : Fin N, ∑ j : Fin N, (if (sort (fun k => (x k).1)).symm i = j then a j * m (F (x i)) else 0) ∂ν := by apply integral_congr_ae exact Filter.Eventually.of_forall fun x => by simpa only using hpoint x (fun i => m (F (x i))) _ = ∑ i : Fin N, ∑ j : Fin N, ∫ x, (if (sort (fun k => (x k).1)).symm i = j then a j * m (F (x i)) else 0) ∂ν := by rw [integral_finsetSum (s := Finset.univ) (fun i _ => integrable_finsetSum _ (fun j _ => hmean_int i j))] congr 1 funext i rw [integral_finsetSum (s := Finset.univ) (fun j _ => hmean_int i j)] _ = ∑ i : Fin N, ∑ j : Fin N, a j * ∫ u in Icc (0 : ℝ) 1, m u * B j u ∂volume := by apply Finset.sum_congr rfl intro i _ apply Finset.sum_congr rfl intro j _ calc _ = a j * ∫ x, (if (sort (fun k => (x k).1)).symm i = j then m (F (x i)) else 0) ∂ν := by rw [← integral_const_mul] congr 1 funext x split_ifs <;> simp [*] _ = _ := congrArg (a j * ·) (hterm i j) _ = ∫ u in Icc (0 : ℝ) 1, m u * bernsteinCell N a u ∂volume := by calc _ = (N : ℝ) * ∑ j : Fin N, a j * ∫ u in Icc (0 : ℝ) 1, m u * B j u ∂volume := by simp only [Finset.sum_const, Finset.card_fin, nsmul_eq_mul] _ = (N : ℝ) * ∫ u in Icc (0 : ℝ) 1, ∑ j : Fin N, m u * (a j * B j u) ∂volume := by rw [integral_finsetSum (s := Finset.univ) (fun j _ => hrhs_int j)] congr 1 apply Finset.sum_congr rfl intro j _ rw [← integral_const_mul] apply integral_congr_ae exact Filter.Eventually.of_forall fun u => by ring _ = _ := by rw [← integral_const_mul] apply integral_congr_ae exact Filter.Eventually.of_forall fun u => by simp only [bernsteinCell, B, Finset.mul_sum] apply Finset.sum_congr rfl intro j _ ring
Causalean.Stat.OrderStatistic.WeightedConcomitant.integral_rankConcomitant_eq_bernstein · Causalean/Stat/OrderStatistic/WeightedConcomitant/ConcomitantExpectation.lean:205 · uses bernsteinCell , rankConcomitant
1 supporting declaration (lemmas, instances)
  • integral_rankConcomitant_eq_conditionalMean theorem — For a bounded marked iid law, continuous coordinate CDF, cell weights, and a conditional mean function and version, conditioning replaces each sorted mark by that mean in the expected rank concomitant.
    N :
    ℕ
    μ :
    hcont :
    Continuous (fun t => cdf (μ.map fst) t)
    hmark :
    ∀ᵐ p ∂μ, p.2 ∈ Icc (0 : ℝ) 1
    a :
    Fin N → ℝ
    m :
    ℝ → ℝ
    hm :
    (fun p : ℝ × ℝ => m (cdf (μ.map fst) p.1))
    =ᵐ[μ] μ[(fun p : ℝ × ℝ => p.2) | comap (fun p : ℝ × ℝ => cdf (μ.map fst) p.1) inferInstance]
    (∫ x, rankConcomitant a x ∂Measure.pi (fun _ : Fin N => μ))
    = ∫ x, (∑ j : Fin N, a j * m (cdf (μ.map fst) (x (sort (fun i => (x i).1) j)).1)) ∂Measure.pi (fun _ : Fin N => μ)
    Proof (Lean source)
    theorem integral_rankConcomitant_eq_conditionalMean {N : ℕ} (μ : Measure (ℝ × ℝ)) [IsProbabilityMeasure μ] (hcont : Continuous (fun t => cdf (μ.map fst) t)) (hmark : ∀ᵐ p ∂μ, p.2 ∈ Icc (0 : ℝ) 1) (a : Fin N → ℝ) (m : ℝ → ℝ) (hm : (fun p : ℝ × ℝ => m (cdf (μ.map fst) p.1)) =ᵐ[μ] μ[(fun p : ℝ × ℝ => p.2) | comap (fun p : ℝ × ℝ => cdf (μ.map fst) p.1) inferInstance]) : (∫ x, rankConcomitant a x ∂Measure.pi (fun _ : Fin N => μ)) = ∫ x, (∑ j : Fin N, a j * m (cdf (μ.map fst) (x (sort (fun i => (x i).1) j)).1)) ∂Measure.pi (fun _ : Fin N => μ) := by -- Expand the finite sum, condition each tagged mark on its CDF coordinate, -- and use `sort_cdf_eq_ae` to make the rank event coordinate-measurable. classical let ν : Measure (Fin N → ℝ × ℝ) := Measure.pi (fun _ => μ) let F : ℝ × ℝ → ℝ := fun p => cdf (μ.map fst) p.1 have hF : Measurable F := hcont.measurable.comp measurable_fst have hinj : ∀ᵐ x ∂ν, Injective (fun k => F (x k)) := by have hu := iid_uniform_coordinates_injective_ae (N := N) rw [← cdf_transport_iid μ hcont] at hu exact ae_of_ae_map (by apply aemeasurable apply measurable_pi_iff.mpr intro k exact hF.comp (measurable_pi_apply k) : AEMeasurable (fun x : Fin N → ℝ × ℝ => fun k => F (x k)) ν) hu have hC (i j : Fin N) : MeasurableSet {x : Fin N → ℝ × ℝ | (((Finset.univ : Finset (Fin N)).erase i).filter (fun k => F (x k) < F (x i))).card = j.val} := by apply measurableSet_eq_fun · simp_rw [Finset.card_filter] apply Finset.measurable_sum intro k _ apply Measurable.ite · exact measurableSet_lt (hF.comp (measurable_pi_apply k)) (hF.comp (measurable_pi_apply i)) · exact measurable_const · exact measurable_const · exact measurable_const have hrank (i j : Fin N) : ∀ᵐ x ∂ν, (((sort (fun k => (x k).1)).symm i = j) ↔ (((Finset.univ : Finset (Fin N)).erase i).filter (fun k => F (x k) < F (x i))).card = j.val) := by filter_upwards [sort_cdf_eq_ae μ hcont, hinj] with x hs hx rw [hs, ← uniform_tagged_rank_eq_count (fun k => F (x k)) i hx] exact Fin.ext_iff obtain ⟨g, hg, hmg⟩ := conditionalMean_exists_measurable_version μ m hm have hgbound : ∀ᵐ p ∂μ, |g (F p)| ≤ 1 := by filter_upwards [conditionalMean_comp_mem_Icc_ae μ hmark m hm, hmg] with p hp he rw [he] at hp exact abs_le.mpr ⟨by linarith [hp.1], hp.2⟩ have hmarkBound (i : Fin N) : ∀ᵐ x ∂ν, |(x i).2| ≤ 1 := by have hbμ : ∀ᵐ p ∂μ, |p.2| ≤ 1 := hmark.mono fun p hp => abs_le.mpr ⟨by linarith [hp.1], hp.2⟩ exact ae_of_ae_map (μ := ν) (f := fun x : Fin N → ℝ × ℝ => x i) (p := fun p => |p.2| ≤ 1) (measurable_pi_apply i).aemeasurable (by rw [(measurePreserving_eval (fun _ : Fin N => μ) i).map_eq] exact hbμ) have hgBound (i : Fin N) : ∀ᵐ x ∂ν, |g (F (x i))| ≤ 1 := by exact ae_of_ae_map (μ := ν) (f := fun x : Fin N → ℝ × ℝ => x i) (p := fun p => |g (F p)| ≤ 1) (measurable_pi_apply i).aemeasurable (by rw [(measurePreserving_eval (fun _ : Fin N => μ) i).map_eq] exact hgbound) have hmgCoord (i : Fin N) : ∀ᵐ x ∂ν, m (F (x i)) = g (F (x i)) := by exact ae_of_ae_map (μ := ν) (f := fun x : Fin N → ℝ × ℝ => x i) (p := fun p => m (F p) = g (F p)) (measurable_pi_apply i).aemeasurable (by rw [(measurePreserving_eval (fun _ : Fin N => μ) i).map_eq] exact hmg) have htagInt (i j : Fin N) (b : ℝ) : Integrable (fun x : Fin N → ℝ × ℝ => if (sort (fun k => (x k).1)).symm i = j then b * (x i).2 else 0) ν := by let C : Set (Fin N → ℝ × ℝ) := {x | (((Finset.univ : Finset (Fin N)).erase i).filter (fun k => F (x k) < F (x i))).card = j.val} have hL : Integrable (fun x : Fin N → ℝ × ℝ => if x ∈ C then b * (x i).2 else 0) ν := by apply Integrable.of_bound ((measurable_const.mul (measurable_snd.comp (measurable_pi_apply i))).ite (hC i j) measurable_const).aestronglyMeasurable |b| filter_upwards [hmarkBound i] with x hx change ‖(if x ∈ C then b * (x i).2 else 0 : ℝ)‖ ≤ |b| by_cases hc : x ∈ C · simpa [hc, Real.norm_eq_abs, abs_mul] using (mul_le_mul_of_nonneg_left hx (abs_nonneg b)) · simp [hc] apply hL.congr filter_upwards [hrank i j] with x hx simp only [C, Set.mem_ofPred_eq, if_congr hx rfl rfl] have hmeanInt (i j : Fin N) (b : ℝ) : Integrable (fun x : Fin N → ℝ × ℝ => if (sort (fun k => (x k).1)).symm i = j then b * m (F (x i)) else 0) ν := by let C : Set (Fin N → ℝ × ℝ) := {x | (((Finset.univ : Finset (Fin N)).erase i).filter (fun k => F (x k) < F (x i))).card = j.val} have hL : Integrable (fun x : Fin N → ℝ × ℝ => if x ∈ C then b * g (F (x i)) else 0) ν := by apply Integrable.of_bound ((measurable_const.mul (hg.comp (hF.comp (measurable_pi_apply i)))).ite (hC i j) measurable_const).aestronglyMeasurable |b| filter_upwards [hgBound i] with x hx change ‖(if x ∈ C then b * g (F (x i)) else 0 : ℝ)‖ ≤ |b| by_cases hc : x ∈ C · simpa [hc, Real.norm_eq_abs, abs_mul] using (mul_le_mul_of_nonneg_left hx (abs_nonneg b)) · simp [hc] apply hL.congr filter_upwards [hrank i j, hmgCoord i] with x hx hm' simp only [C, Set.mem_ofPred_eq, if_congr hx rfl rfl, hm'] have hpoint (x : Fin N → ℝ × ℝ) (z : Fin N → ℝ) : (∑ j : Fin N, a j * z ((sort (fun k => (x k).1)) j)) = ∑ i : Fin N, ∑ j : Fin N, if (sort (fun k => (x k).1)).symm i = j then a j * z i else 0 := by let σ := sort (fun k => (x k).1) have h := Equiv.sum_comp σ (fun i : Fin N => ∑ j : Fin N, if σ.symm i = j then a j * z i else 0) simpa only [σ, Equiv.symm_apply_apply, Finset.sum_ite_eq, Finset.mem_univ, if_true] using h have hterm (i j : Fin N) : (∫ x, (if (sort (fun k => (x k).1)).symm i = j then a j * (x i).2 else 0) ∂ν) = ∫ x, (if (sort (fun k => (x k).1)).symm i = j then a j * m (F (x i)) else 0) ∂ν := by calc _ = a j * ∫ x, (if (sort (fun k => (x k).1)).symm i = j then (x i).2 else 0) ∂ν := by rw [← integral_const_mul] congr 1 funext x split_ifs <;> simp [*] _ = a j * ∫ x, (if (sort (fun k => (x k).1)).symm i = j then m (F (x i)) else 0) ∂ν := by exact congrArg (a j * ·) (integral_tagged_rank_mark_eq_conditionalMean μ hcont hmark i j m hm) _ = _ := by rw [← integral_const_mul] congr 1 funext x split_ifs <;> simp [*] calc (∫ x, rankConcomitant a x ∂ν) = ∫ x, ∑ i : Fin N, ∑ j : Fin N, (if (sort (fun k => (x k).1)).symm i = j then a j * (x i).2 else 0) ∂ν := by apply integral_congr_ae exact Filter.Eventually.of_forall (fun x => by simpa only [rankConcomitant] using hpoint x (fun i => (x i).2)) _ = ∑ i : Fin N, ∑ j : Fin N, ∫ x, (if (sort (fun k => (x k).1)).symm i = j then a j * (x i).2 else 0) ∂ν := by rw [integral_finsetSum (s := Finset.univ) (fun i _ => integrable_finsetSum _ (fun j _ => htagInt i j (a j)))] congr 1 funext i rw [integral_finsetSum (s := Finset.univ) (fun j _ => htagInt i j (a j))] _ = ∑ i : Fin N, ∑ j : Fin N, ∫ x, (if (sort (fun k => (x k).1)).symm i = j then a j * m (F (x i)) else 0) ∂ν := by apply Finset.sum_congr rfl intro i _ apply Finset.sum_congr rfl intro j _ exact hterm i j _ = ∫ x, ∑ i : Fin N, ∑ j : Fin N, (if (sort (fun k => (x k).1)).symm i = j then a j * m (F (x i)) else 0) ∂ν := by rw [integral_finsetSum (s := Finset.univ) (fun i _ => integrable_finsetSum _ (fun j _ => hmeanInt i j (a j)))] congr 1 funext i rw [integral_finsetSum (s := Finset.univ) (fun j _ => hmeanInt i j (a j))] _ = _ := by apply integral_congr_ae exact Filter.Eventually.of_forall (fun x => by simpa only [F] using (hpoint x (fun i => m (F (x i)))).symm)
    Causalean.Stat.OrderStatistic.WeightedConcomitant.integral_rankConcomitant_eq_conditionalMean · Causalean/Stat/OrderStatistic/WeightedConcomitant/ConcomitantExpectation.lean:21
Concomitant­Tagged 1 core · 0 supporting This module derives the conditional-mean identity for one tagged observation in a continuous rank-weighted marked sample. ★ integral_tagged_rank_mark_eq_conditionalMean

Tagged rank concomitant expectations

This module derives the conditional-mean identity for one tagged observation in a continuous rank-weighted marked sample.

theorem integral_tagged_rank_mark_eq_conditionalMean reviewed
Causalean.Stat.OrderStatistic.WeightedConcomitant

For a bounded marked iid law, a continuous coordinate CDF, a tagged coordinate and rank, and a conditional mean function and version, one tagged mark restricted to one rank has the same expectation after replacing the mark by its conditional mean.

Formal statement
N :
ℕ
μ :
hcont :
Continuous (fun t => cdf (μ.map fst) t)
hmark :
∀ᵐ p ∂μ, p.2 ∈ Icc (0 : ℝ) 1
i j :
Fin N
m :
ℝ → ℝ
hm :
(fun p : ℝ × ℝ => m (cdf (μ.map fst) p.1))
=ᵐ[μ] μ[(fun p : ℝ × ℝ => p.2) | comap (fun p : ℝ × ℝ => cdf (μ.map fst) p.1) inferInstance]
(∫ x, (if (sort (fun k => (x k).1)).symm i = j then (x i).2 else 0) ∂Measure.pi (fun _ : Fin N => μ))
= ∫ x, (if (sort (fun k => (x k).1)).symm i = j then m (cdf (μ.map fst) (x i).1) else 0) ∂Measure.pi (fun _ : Fin N => μ)
Proof (Lean source)
theorem integral_tagged_rank_mark_eq_conditionalMean {N : ℕ} (μ : Measure (ℝ × ℝ)) [IsProbabilityMeasure μ] (hcont : Continuous (fun t => cdf (μ.map fst) t)) (hmark : ∀ᵐ p ∂μ, p.2 ∈ Icc (0 : ℝ) 1) (i j : Fin N) (m : ℝ → ℝ) (hm : (fun p : ℝ × ℝ => m (cdf (μ.map fst) p.1)) =ᵐ[μ] μ[(fun p : ℝ × ℝ => p.2) | comap (fun p : ℝ × ℝ => cdf (μ.map fst) p.1) inferInstance]) : (∫ x, (if (sort (fun k => (x k).1)).symm i = j then (x i).2 else 0) ∂Measure.pi (fun _ : Fin N => μ)) = ∫ x, (if (sort (fun k => (x k).1)).symm i = j then m (cdf (μ.map fst) (x i).1) else 0) ∂Measure.pi (fun _ : Fin N => μ) := by -- Conditional expectation is taken in the tagged factor. The rank event is -- measurable in the sigma algebra generated by the transported coordinates; -- use `sort_cdf_eq_ae` before conditioning to remove dependence on raw marks. classical obtain ⟨g, hg, hmg⟩ := conditionalMean_exists_measurable_version μ m hm let F : ℝ × ℝ → ℝ := fun p => cdf (μ.map fst) p.1 have hF : Measurable F := hcont.measurable.comp measurable_fst have hgm : (fun p => g (F p)) =ᵐ[μ] μ[(fun p : ℝ × ℝ => p.2) | comap F inferInstance] := hmg.symm.trans hm have hgbound : ∀ᵐ p ∂μ, |g (F p)| ≤ 1 := by filter_upwards [conditionalMean_comp_mem_Icc_ae μ hmark m hm, hmg] with p hp he rw [he] at hp exact abs_le.mpr ⟨by linarith [hp.1], hp.2⟩ have hreplace : (∫ x, (if (sort (fun k => (x k).1)).symm i = j then m (F (x i)) else 0) ∂Measure.pi (fun _ : Fin N => μ)) = ∫ x, (if (sort (fun k => (x k).1)).symm i = j then g (F (x i)) else 0) ∂Measure.pi (fun _ : Fin N => μ) := by apply integral_congr_ae have he : ∀ᵐ x ∂Measure.pi (fun _ : Fin N => μ), m (F (x i)) = g (F (x i)) := by exact ae_of_ae_map (μ := Measure.pi (fun _ : Fin N => μ)) (f := fun x : Fin N → ℝ × ℝ => x i) (p := fun p => m (F p) = g (F p)) (measurable_pi_apply i).aemeasurable (by rw [(measurePreserving_eval (fun _ : Fin N => μ) i).map_eq] exact hmg) filter_upwards [he] with x hx split_ifs <;> simp [hx] rw [hreplace] cases N with | zero => exact i.elim0 | succ n => let ν : Measure (Fin (n + 1) → ℝ × ℝ) := Measure.pi (fun _ => μ) let ρ : Measure (Fin n → ℝ × ℝ) := Measure.pi (fun _ => μ) let e := piFinSuccAbove (fun _ : Fin (n + 1) => ℝ × ℝ) i let C : Set (Fin (n + 1) → ℝ × ℝ) := {x | (((Finset.univ : Finset (Fin (n + 1))).erase i).filter (fun k => F (x k) < F (x i))).card = j.val} have hC : MeasurableSet C := by dsimp [C] apply measurableSet_eq_fun · simp_rw [Finset.card_filter] apply Finset.measurable_sum intro k _ apply Measurable.ite · exact measurableSet_lt (hF.comp (measurable_pi_apply k)) (hF.comp (measurable_pi_apply i)) · exact measurable_const · exact measurable_const · exact measurable_const have hrank : ∀ᵐ x ∂ν, ((sort (fun k => (x k).1)).symm i = j) ↔ x ∈ C := by have htransport := cdf_transport_iid (N := n + 1) μ hcont have hinj : ∀ᵐ x ∂ν, Injective (fun k => F (x k)) := by have hu := iid_uniform_coordinates_injective_ae (N := n + 1) rw [← htransport] at hu exact ae_of_ae_map (by apply aemeasurable apply measurable_pi_iff.mpr intro k exact hF.comp (measurable_pi_apply k) : AEMeasurable (fun x : Fin (n + 1) → ℝ × ℝ => fun k => F (x k)) ν) hu filter_upwards [sort_cdf_eq_ae μ hcont, hinj] with x hs hx have hc : ((sort (fun k => F (x k))).symm i = j) ↔ x ∈ C := by change ((sort (fun k => F (x k))).symm i = j) ↔ (((Finset.univ : Finset (Fin (n + 1))).erase i).filter (fun k => F (x k) < F (x i))).card = j.val rw [← uniform_tagged_rank_eq_count (fun k => F (x k)) i hx] exact Fin.ext_iff rw [hs] exact hc let L : (Fin (n + 1) → ℝ × ℝ) → ℝ := fun x => if x ∈ C then (x i).2 else 0 let R : (Fin (n + 1) → ℝ × ℝ) → ℝ := fun x => if x ∈ C then g (F (x i)) else 0 have hLint : Integrable L ν := by have hmeas : Measurable L := (measurable_snd.comp (measurable_pi_apply i)).ite hC measurable_const have hb : ∀ᵐ x ∂ν, |(x i).2| ≤ 1 := by have hbμ : ∀ᵐ p ∂μ, |p.2| ≤ 1 := hmark.mono fun p hp => abs_le.mpr ⟨by linarith [hp.1], hp.2⟩ exact ae_of_ae_map (μ := ν) (f := fun x : Fin (n + 1) → ℝ × ℝ => x i) (p := fun p => |p.2| ≤ 1) (measurable_pi_apply i).aemeasurable (by rw [(measurePreserving_eval (fun _ : Fin (n + 1) => μ) i).map_eq] exact hbμ) apply Integrable.of_bound hmeas.aestronglyMeasurable 1 filter_upwards [hb] with x hx by_cases hc : x ∈ C · simpa [L, hc, Real.norm_eq_abs] using hx · simp [L, hc] have hRint : Integrable R ν := by have hmeas : Measurable R := (hg.comp (hF.comp (measurable_pi_apply i))).ite hC measurable_const have hb : ∀ᵐ x ∂ν, |g (F (x i))| ≤ 1 := by exact ae_of_ae_map (μ := ν) (f := fun x : Fin (n + 1) → ℝ × ℝ => x i) (p := fun p => |g (F p)| ≤ 1) (measurable_pi_apply i).aemeasurable (by rw [(measurePreserving_eval (fun _ : Fin (n + 1) => μ) i).map_eq] exact hgbound) apply Integrable.of_bound hmeas.aestronglyMeasurable 1 filter_upwards [hb] with x hx by_cases hc : x ∈ C · simpa [R, hc, Real.norm_eq_abs] using hx · simp [R, hc] have hsplit (T : (Fin (n + 1) → ℝ × ℝ) → ℝ) (hT : Integrable T ν) : (∫ x, T x ∂ν) = ∫ w, ∫ p, T (e.symm (p, w)) ∂μ ∂ρ := by have he := measurePreserving_piFinSuccAbove (fun _ : Fin (n + 1) => μ) i have hcomp : (fun z => T (e.symm z)) ∘ e = T := by funext x simp calc _ = ∫ z : (ℝ × ℝ) × (Fin n → ℝ × ℝ), T (e.symm z) ∂μ.prod ρ := by have hh := he.integral_comp' (fun z => T (e.symm z)) change (∫ x, ((fun z => T (e.symm z)) ∘ e) x ∂ν) = _ at hh rw [hcomp] at hh exact hh _ = _ := by apply integral_prod_symm apply (he.integrable_comp_emb e.measurableEmbedding).mp change Integrable (((fun z => T (e.symm z)) ∘ e)) ν rw [hcomp] exact hT have hcount (p : ℝ × ℝ) (w : Fin n → ℝ × ℝ) : (((Finset.univ : Finset (Fin (n + 1))).erase i).filter (fun k => F ((e.symm (p, w)) k) < F p)).card = ((Finset.univ : Finset (Fin n)).filter (fun k => F (w k) < F p)).card := by have hindex : ((Finset.univ : Finset (Fin (n + 1))).erase i) = (Finset.univ : Finset (Fin n)).image i.succAbove := by ext k simp only [Finset.mem_erase, Finset.mem_univ, and_true, mem_image, Finset.mem_univ, true_and] rw [← Set.mem_range] simp [Fin.range_succAbove] rw [hindex, Finset.filter_image, Finset.card_image_of_injective] · simp [e] · exact Fin.succAbove_right_injective have hinner (w : Fin n → ℝ × ℝ) : (∫ p, L (e.symm (p, w)) ∂μ) = ∫ p, R (e.symm (p, w)) ∂μ := by let S : Set (ℝ × ℝ) := {p | ((Finset.univ : Finset (Fin n)).filter (fun k => F (w k) < F p)).card = j.val} have hS : MeasurableSet[comap F inferInstance] S := by dsimp [S] apply measurableSet_eq_fun · simp_rw [Finset.card_filter] apply Finset.measurable_sum intro k _ apply Measurable.ite · exact measurableSet_lt measurable_const (comap_measurable F) · exact measurable_const · exact measurable_const · exact measurable_const have hS' : MeasurableSet S := hF.comap_le S hS have hL : (fun p => L (e.symm (p, w))) = S.indicator (fun p => p.2) := by funext p have hi : (e.symm (p,w)) i = p := by simp [e] have hc : e.symm (p,w) ∈ C ↔ p ∈ S := by change (((Finset.univ : Finset (Fin (n + 1))).erase i).filter (fun k => F ((e.symm (p,w)) k) < F ((e.symm (p,w)) i))).card = j.val ↔ ((Finset.univ : Finset (Fin n)).filter (fun k => F (w k) < F p)).card = j.val rw [hi, hcount] simp only [L, indicator, hi, hc] have hR : (fun p => R (e.symm (p, w))) = S.indicator (fun p => g (F p)) := by funext p have hi : (e.symm (p,w)) i = p := by simp [e] have hc : e.symm (p,w) ∈ C ↔ p ∈ S := by change (((Finset.univ : Finset (Fin (n + 1))).erase i).filter (fun k => F ((e.symm (p,w)) k) < F ((e.symm (p,w)) i))).card = j.val ↔ ((Finset.univ : Finset (Fin n)).filter (fun k => F (w k) < F p)).card = j.val rw [hi, hcount] simp only [R, indicator, hi, hc] rw [hL, hR] rw [integral_indicator hS', integral_indicator hS'] calc (∫ p in S, p.2 ∂μ) = ∫ p in S, (μ[(fun p : ℝ × ℝ => p.2) | comap F inferInstance]) p ∂μ := (setIntegral_condExp hF.comap_le (Integrable.of_bound measurable_snd.aestronglyMeasurable 1 (hmark.mono fun p hp => by simpa only [Real.norm_eq_abs] using (abs_le.mpr ⟨by linarith [hp.1], hp.2⟩))) hS).symm _ = ∫ p in S, g (F p) ∂μ := by apply setIntegral_congr_ae hS' exact hgm.symm.mono (fun p hp _ => hp) calc (∫ x, (if (sort (fun k => (x k).1)).symm i = j then (x i).2 else 0) ∂ν) = ∫ x, L x ∂ν := by apply integral_congr_ae filter_upwards [hrank] with x hx simp only [L, if_congr hx rfl rfl] _ = ∫ w, ∫ p, L (e.symm (p, w)) ∂μ ∂ρ := hsplit L hLint _ = ∫ w, ∫ p, R (e.symm (p, w)) ∂μ ∂ρ := by exact integral_congr_ae (Filter.Eventually.of_forall hinner) _ = ∫ x, R x ∂ν := (hsplit R hRint).symm _ = ∫ x, (if (sort (fun k => (x k).1)).symm i = j then g (F (x i)) else 0) ∂ν := by apply integral_congr_ae filter_upwards [hrank] with x hx simp only [R, if_congr hx rfl rfl]
Causalean.Stat.OrderStatistic.WeightedConcomitant.integral_tagged_rank_mark_eq_conditionalMean · Causalean/Stat/OrderStatistic/WeightedConcomitant/ConcomitantTagged.lean:21
Order­Statistic­Moments 1 core · 5 supporting Exact first and second moments of one coordinate of a sorted finite iid unit-uniform tuple. ★ simplex_coordinate_cross_moment

Uniform order-statistic moments

Exact first and second moments of one coordinate of a sorted finite iid unit-uniform tuple. These refine the existing spacing moment API.

Proof route: the first j+1 spacings sum to the jth zero-based order statistic. The existing uniform-spacing law and coordinate-square moment reduce the two order-statistic moments to the first and mixed moments of coordinates in the spacing simplex, recorded separately below.

theorem simplex_coordinate_cross_moment reviewed
Causalean.Stat.OrderStatistic.WeightedConcomitant

For a simplex dimension, two coordinates that are distinct, their factorial-scaled product integral is 1/((n+1)(n+2)).

Formal statement
n :
ℕ
i j :
Fin n
hij :
i ≠ j
(n.factorial : ℝ) * (∫ z in spacingSimplex n, z i * z j ∂volume)
= (1 : ℝ) / ((n + 1) * (n + 2))
Proof (Lean source)
theorem simplex_coordinate_cross_moment (n : ℕ) (i j : Fin n) (hij : i ≠ j) : (n.factorial : ℝ) * (∫ z in spacingSimplex n, z i * z j ∂volume) = (1 : ℝ) / ((n + 1) * (n + 2)) := by cases n with | zero => exact elim0 i | succ n => cases n with | zero => exact False.elim (hij (Fin.ext (by have hi := i.isLt have hj := j.isLt omega))) | succ m => have hcross := simplex_cross_coordinate_eq_first_two m i j hij have hfubini := simplex_first_second_cross_fubini m have hinner (t : ℝ) (ht : t ∈ Icc (0 : ℝ) 1) : (∫ w in scaledSpacingSimplex (m + 1) (1 - t), w (0 : Fin (m + 1)) ∂volume) = (1 - t) ^ (m + 2) / ((m + 2) * ((m + 1).factorial : ℝ)) := by have h := scaled_simplex_coordinate_first_moment (m + 1) (1 - t) (sub_nonneg.mpr ht.2) (0 : Fin (m + 1)) have hfac : ((m + 1).factorial : ℝ) ≠ 0 := by positivity have hdim : ((m + 2 : ℕ) : ℝ) ≠ 0 := by positivity push_cast at h ⊢ field_simp at h ⊢ nlinarith [h] have hint : (∫ z in spacingSimplex (m + 2), z (0 : Fin (m + 2)) * z (1 : Fin (m + 2)) ∂volume) = (m + 2).factorial / (m + 4).factorial / ((m + 2) * ((m + 1).factorial : ℝ)) := by rw [hfubini] have heq : (∫ t in Icc (0 : ℝ) 1, t * (∫ w in scaledSpacingSimplex (m + 1) (1 - t), w (0 : Fin (m + 1)) ∂volume) ∂volume) = ∫ t in Icc (0 : ℝ) 1, t * ((1 - t) ^ (m + 2) / ((m + 2) * ((m + 1).factorial : ℝ))) ∂volume := by apply setIntegral_congr_fun measurableSet_Icc intro t ht change t * _ = t * _ rw [hinner t ht] rw [heq] simp_rw [← mul_div_assoc] rw [integral_div] rw [unit_beta_linear_integral (m + 2)] rw [hcross, hint] have hfac : ((m + 1).factorial : ℝ) ≠ 0 := by positivity simp only [Nat.factorial_succ] push_cast field_simp ring
Causalean.Stat.OrderStatistic.WeightedConcomitant.simplex_coordinate_cross_moment · Causalean/Stat/OrderStatistic/WeightedConcomitant/OrderStatisticMoments.lean:513 · uses spacingSimplex
5 supporting declarations (lemmas, instances)
  • simplex_coordinate_first_moment theorem — For a simplex dimension and coordinate, the factorial-scaled mean of that spacing coordinate is 1/(n+1).
    n :
    ℕ
    i :
    Fin n
    (n.factorial : ℝ) * (∫ z in spacingSimplex n, z i ∂volume) = (1 : ℝ) / (n + 1)
    Proof (Lean source)
    theorem simplex_coordinate_first_moment (n : ℕ) (i : Fin n) : (n.factorial : ℝ) * (∫ z in spacingSimplex n, z i ∂volume) = (1 : ℝ) / (n + 1) := by -- Slice the simplex by one coordinate and use permutation symmetry for `i`. have hfirst_fubini (m : ℕ) : (∫ z in spacingSimplex (m + 1), (z (0 : Fin (m + 1))) ∂volume) = ∫ t in Icc (0 : ℝ) 1, t * (volume (scaledSpacingSimplex m (1 - t))).toReal := by let e : (ℝ × (Fin m → ℝ)) ≃ᵐ (Fin (m + 1) → ℝ) := (piFinSuccAbove (fun _ => ℝ) 0).symm let S : Set (ℝ × (Fin m → ℝ)) := e ⁻¹' spacingSimplex (m + 1) have hem : MeasurePreserving e := (volume_preserving_piFinSuccAbove (fun _ : Fin (m + 1) => ℝ) 0).symm _ have hsimplex : MeasurableSet (spacingSimplex (m + 1)) := by have hclosed : IsClosed (spacingSimplex (m + 1)) := by change IsClosed {z : Fin (m + 1) → ℝ | (∀ i, 0 ≤ z i) ∧ (∑ i, z i) ≤ 1} apply IsClosed.inter · have hp : IsClosed (⋂ i : Fin (m + 1), (fun z : Fin (m + 1) → ℝ => z i) ⁻¹' Ici (0 : ℝ)) := isClosed_iInter (fun i => isClosed_Ici.preimage (continuous_apply i)) have heq : {z : Fin (m + 1) → ℝ | ∀ i, 0 ≤ z i} = ⋂ i : Fin (m + 1), (fun z : Fin (m + 1) → ℝ => z i) ⁻¹' Ici 0 := by ext z simp change IsClosed {z : Fin (m + 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 (m + 1)) ≠ ⊤ := by change volume (scaledSpacingSimplex (m + 1) 1) ≠ ⊤ rw [scaledSpacingSimplex_volume (m + 1) 1 (by norm_num)] simp have hInt : IntegrableOn (fun z : Fin (m + 1) → ℝ => z 0) (spacingSimplex (m + 1)) volume := by apply Measure.integrableOn_of_bounded hfinite ((measurable_pi_apply 0).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 h0] exact hle have hpreInt : IntegrableOn (fun p : ℝ × (Fin m → ℝ) => p.1) 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 m → ℝ) => p.1)) ((volume : Measure ℝ).prod volume) := by exact hpreInt.integrable_indicator hS have hsection (t : ℝ) (ht : t ∈ Icc (0 : ℝ) 1) : {w : Fin m → ℝ | (t, w) ∈ S} = scaledSpacingSimplex m (1 - t) := by simpa [S, e, MeasurableEquiv.piFinSuccAbove_symm_apply, Fin.insertNth_zero, Fin.consEquiv] using simplex_tail_section m t ht have hsubset (p : ℝ × (Fin m → ℝ)) (hp : p ∈ S) : p.1 ∈ Icc (0 : ℝ) 1 := by have hp' : cons p.1 p.2 ∈ spacingSimplex (m + 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 (m + 1)))) _ ≤ 1 := hp'.2 exact ⟨h0, hle⟩ have hfiber (t : ℝ) : (∫ w : Fin m → ℝ, S.indicator (fun p : ℝ × (Fin m → ℝ) => p.1) (t, w) ∂volume) = if ht : t ∈ Icc (0 : ℝ) 1 then t * (volume (scaledSpacingSimplex m (1 - t))).toReal else 0 := by split_ifs with ht · have hs : MeasurableSet {w : Fin m → ℝ | (t, w) ∈ S} := hS.preimage measurable_prodMk_left calc _ = ∫ w in {w : Fin m → ℝ | (t, w) ∈ S}, t ∂volume := by rw [← integral_indicator hs] congr 1 _ = t * (volume (scaledSpacingSimplex m (1 - t))).toReal := by rw [setIntegral_const, hsection t ht] simp [measureReal_def, smul_eq_mul, mul_comm] · have hzero : ∀ w : Fin m → ℝ, (t, w) ∉ S := by intro w hw exact ht (hsubset (t, w) hw) simp [indicator, hzero] calc (∫ z in spacingSimplex (m + 1), z 0 ∂volume) = ∫ p in S, p.1 ∂volume := by rw [← hem.map_eq, setIntegral_map_equiv] rfl _ = ∫ p : ℝ × (Fin m → ℝ), S.indicator (fun p : ℝ × (Fin m → ℝ) => p.1) p ∂volume := by rw [integral_indicator hS] _ = ∫ t : ℝ, ∫ w : Fin m → ℝ, S.indicator (fun p : ℝ × (Fin m → ℝ) => p.1) (t, w) ∂volume := by rw [Measure.volume_eq_prod] exact integral_prod _ hprodInt _ = ∫ t in Icc (0 : ℝ) 1, t * (volume (scaledSpacingSimplex m (1 - t))).toReal := by simp_rw [hfiber] rw [← integral_indicator measurableSet_Icc] congr 1 funext t simp [indicator, dite_eq_ite] have hfirst_slice (m : ℕ) : (∫ z in spacingSimplex (m + 1), (z (0 : Fin (m + 1))) ∂volume) = ∫ t in (0 : ℝ)..1, t * ((1 - t) ^ m / (m.factorial : ℝ)) := by rw [hfirst_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 * (volume (scaledSpacingSimplex m (1 - t))).toReal = t * ((1 - t) ^ m / (m.factorial : ℝ)) rw [scaledSpacingSimplex_volume m (1 - t) hr] rw [ENNReal.toReal_ofReal (div_nonneg (pow_nonneg hr m) (by positivity))] have hbeta_first (m : ℕ) : (∫ t in (0 : ℝ)..1, t * (1 - t) ^ m) = (m.factorial : ℝ) / ((m + 2).factorial : ℝ) := by have hbeta : (∫ t in (0 : ℝ)..1, ((t * (1 - t) ^ m : ℝ) : ℂ)) = Complex.betaIntegral 2 (m + 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_pow, Complex.ofReal_sub, Complex.ofReal_one] norm_num have heval := Complex.betaIntegral_eq_Gamma_mul_div 2 (m + 1) (by norm_num) (by simp; positivity) rw [← hbeta] at heval have hg3 : Complex.Gamma 2 = 1 := by convert Complex.Gamma_nat_eq_factorial 1 using 1 <;> norm_num have hgn : Complex.Gamma (m + 1) = (m.factorial : ℂ) := by simpa using Complex.Gamma_nat_eq_factorial m have hgn3 : Complex.Gamma (2 + (m + 1)) = ((m + 2).factorial : ℂ) := by convert Complex.Gamma_nat_eq_factorial (m + 2) 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) have hcoord_eq_first (m : ℕ) (k : Fin m) : (∫ z in spacingSimplex m, z k ∂volume) = ∫ z in spacingSimplex m, z (⟨0, by have := k.isLt; omega⟩ : Fin m) ∂volume := by classical let j : Fin m := ⟨0, by have := k.isLt; omega⟩ let σ : Perm (Fin m) := Equiv.swap k j let e : (Fin m → ℝ) ≃ᵐ (Fin m → ℝ) := MeasurableEquiv.piCongrLeft (fun _ : Fin m => ℝ) σ.symm have he : MeasurePreserving e volume volume := volume_measurePreserving_piCongrLeft (fun _ : Fin m => ℝ) σ.symm have hfun (z : Fin m → ℝ) : e z = z ∘ σ := by funext k simp [e, MeasurableEquiv.coe_piCongrLeft, Equiv.piCongrLeft_apply] have hpre : e ⁻¹' spacingSimplex m = spacingSimplex m := 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 m)) (volume.restrict (spacingSimplex m)) := by refine ⟨e.measurable, ?_⟩ calc (volume.restrict (spacingSimplex m)).map e = (volume.restrict (e ⁻¹' spacingSimplex m)).map e := by rw [hpre] _ = (volume.map e).restrict (spacingSimplex m) := (e.restrict_map volume (spacingSimplex m)).symm _ = volume.restrict (spacingSimplex m) := by rw [he.map_eq] have hint := hmp.integral_comp' (fun z : Fin m → ℝ => z j) simp only [hfun] at hint have hswap : σ j = k := Equiv.swap_apply_right k j simpa [j, hswap] using hint cases n with | zero => exact elim0 i | succ m => rw [hcoord_eq_first] change (m + 1).factorial * (∫ z in spacingSimplex (m + 1), z (0 : Fin (m + 1)) ∂volume) = _ rw [hfirst_slice] have hfactorial : (m + 1).factorial = (m + 1) * m.factorial := Nat.factorial_succ m simp_rw [← mul_div_assoc] rw [intervalIntegral.integral_div] rw [hbeta_first] norm_num [hfactorial, Nat.factorial_succ] have hm : (m.factorial : ℝ) ≠ 0 := by positivity field_simp
    Causalean.Stat.OrderStatistic.WeightedConcomitant.simplex_coordinate_first_moment · Causalean/Stat/OrderStatistic/WeightedConcomitant/OrderStatisticMoments.lean:26
  • scaled_simplex_coordinate_first_moment theorem — For a simplex dimension, nonnegative scale, and coordinate, the factorial-scaled coordinate integral over the scaled simplex is r^(n+1)/(n+1).
    n :
    ℕ
    r :
    ℝ
    hr :
    0 ≤ r
    i :
    Fin n
    (n.factorial : ℝ) * (∫ z in scaledSpacingSimplex n r, z i ∂volume) = r ^ (n + 1) / (n + 1)
    Proof (Lean source)
    theorem scaled_simplex_coordinate_first_moment (n : ℕ) (r : ℝ) (hr : 0 ≤ r) (i : Fin n) : (n.factorial : ℝ) * (∫ z in scaledSpacingSimplex n r, z i ∂volume) = r ^ (n + 1) / (n + 1) := by classical have hn : n ≠ 0 := by have := i.isLt; omega by_cases hr0 : r = 0 · subst r have hzero : volume (scaledSpacingSimplex n 0) = 0 := by rw [scaledSpacingSimplex_volume n 0 (le_refl 0)] simp [hn] simp [hzero] · have hrpos : 0 < r := lt_of_le_of_ne hr (Ne.symm hr0) have hscale : r • spacingSimplex n = scaledSpacingSimplex n r := by ext z simp only [Set.mem_smul_set, spacingSimplex, scaledSpacingSimplex, Set.mem_ofPred_eq] constructor · rintro ⟨y, ⟨hp, hs⟩, rfl⟩ constructor · intro j simpa [Pi.smul_apply, smul_eq_mul] using mul_nonneg hr (hp j) · 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 j exact smul_nonneg (inv_nonneg.mpr hr) (hp j) · have hs' : (∑ j, (r⁻¹ • z) j) = r⁻¹ * ∑ j, z j := by simp [Pi.smul_apply, smul_eq_mul, Finset.mul_sum] rw [hs'] calc r⁻¹ * ∑ j, z j ≤ r⁻¹ * r := mul_le_mul_of_nonneg_left hs (inv_nonneg.mpr hr) _ = 1 := inv_mul_cancel₀ hr0 · simp [smul_smul, hr0] have hchange := Measure.setIntegral_comp_smul (μ := (volume : Measure (Fin n → ℝ))) (f := fun z : Fin n → ℝ => z i) (s := spacingSimplex n) hr0 rw [hscale] at hchange simp only [Pi.smul_apply, smul_eq_mul, Module.finrank_pi, Fintype.card_fin] at hchange rw [integral_const_mul] at hchange simp only [abs_of_nonneg (inv_nonneg.mpr (pow_nonneg hr n))] at hchange have hmean := simplex_coordinate_first_moment n i calc (n.factorial : ℝ) * (∫ z in scaledSpacingSimplex n r, z i ∂volume) = r ^ (n + 1) * ((n.factorial : ℝ) * (∫ z in spacingSimplex n, z i ∂volume)) := by have hpow : r ^ n ≠ 0 := pow_ne_zero n hr0 field_simp at hchange ⊢ rw [pow_succ] nlinarith [hchange] _ = r ^ (n + 1) / (n + 1) := by rw [hmean]; ring
    Causalean.Stat.OrderStatistic.WeightedConcomitant.scaled_simplex_coordinate_first_moment · Causalean/Stat/OrderStatistic/WeightedConcomitant/OrderStatisticMoments.lean:238
  • simplex_first_second_cross_fubini theorem — For a remaining simplex dimension, the first two coordinate product integral is the first-coordinate slice weighted by the scaled tail's coordinate integral.
    n :
    ℕ
    (∫ z in spacingSimplex (n + 2), z (0 : Fin (n + 2)) * z (1 : Fin (n + 2)) ∂volume)
    = ∫ t in Icc (0 : ℝ) 1, t * (∫ w in scaledSpacingSimplex (n + 1) (1 - t), w (0 : Fin (n + 1)) ∂volume) ∂volume
    Proof (Lean source)
    theorem simplex_first_second_cross_fubini (n : ℕ) : (∫ z in spacingSimplex (n + 2), z (0 : Fin (n + 2)) * z (1 : Fin (n + 2)) ∂volume) = ∫ t in Icc (0 : ℝ) 1, t * (∫ w in scaledSpacingSimplex (n + 1) (1 - t), w (0 : Fin (n + 1)) ∂volume) ∂volume := by let m := n + 1 let e : (ℝ × (Fin m → ℝ)) ≃ᵐ (Fin (m + 1) → ℝ) := (piFinSuccAbove (fun _ => ℝ) 0).symm let S : Set (ℝ × (Fin m → ℝ)) := e ⁻¹' spacingSimplex (m + 1) have hem : MeasurePreserving e := (volume_preserving_piFinSuccAbove (fun _ : Fin (m + 1) => ℝ) 0).symm _ have hsimplex : MeasurableSet (spacingSimplex (m + 1)) := by have hclosed : IsClosed (spacingSimplex (m + 1)) := by change IsClosed {z : Fin (m + 1) → ℝ | (∀ i, 0 ≤ z i) ∧ (∑ i, z i) ≤ 1} apply IsClosed.inter · have hp : IsClosed (⋂ i : Fin (m + 1), (fun z : Fin (m + 1) → ℝ => z i) ⁻¹' Ici (0 : ℝ)) := isClosed_iInter (fun i => isClosed_Ici.preimage (continuous_apply i)) have heq : {z : Fin (m + 1) → ℝ | ∀ i, 0 ≤ z i} = ⋂ i : Fin (m + 1), (fun z : Fin (m + 1) → ℝ => z i) ⁻¹' Ici 0 := by ext z simp change IsClosed {z : Fin (m + 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 (m + 1)) ≠ ⊤ := by change volume (scaledSpacingSimplex (m + 1) 1) ≠ ⊤ rw [scaledSpacingSimplex_volume (m + 1) 1 (by norm_num)] simp have hInt : IntegrableOn (fun z : Fin (m + 1) → ℝ => z 0 * z 1) (spacingSimplex (m + 1)) volume := by apply Measure.integrableOn_of_bounded hfinite (((measurable_pi_apply 0).mul (measurable_pi_apply 1)).aestronglyMeasurable) (M := 1) apply ae_restrict_of_forall_mem hsimplex intro z hz have hcoord (j : Fin (m + 1)) : 0 ≤ z j ∧ z j ≤ 1 := by refine ⟨hz.1 j, ?_⟩ calc z j ≤ ∑ k, z k := Finset.single_le_sum (fun k _ => hz.1 k) (Finset.mem_univ j) _ ≤ 1 := hz.2 change ‖z 0 * z 1‖ ≤ 1 rw [Real.norm_eq_abs, abs_of_nonneg (mul_nonneg (hcoord 0).1 (hcoord 1).1)] calc z 0 * z 1 ≤ 1 * z 1 := mul_le_mul_of_nonneg_right (hcoord 0).2 (hcoord 1).1 _ ≤ 1 := by simpa using (hcoord 1).2 have hpreInt : IntegrableOn (fun p : ℝ × (Fin m → ℝ) => p.1 * p.2 0) 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 m → ℝ) => p.1 * p.2 0)) ((volume : Measure ℝ).prod volume) := hpreInt.integrable_indicator hS have hsection (t : ℝ) (ht : t ∈ Icc (0 : ℝ) 1) : {w : Fin m → ℝ | (t, w) ∈ S} = scaledSpacingSimplex m (1 - t) := by simpa [S, e, MeasurableEquiv.piFinSuccAbove_symm_apply, Fin.insertNth_zero, Fin.consEquiv] using simplex_tail_section m t ht have hsubset (p : ℝ × (Fin m → ℝ)) (hp : p ∈ S) : p.1 ∈ Icc (0 : ℝ) 1 := by have hp' : cons p.1 p.2 ∈ spacingSimplex (m + 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 (m + 1)))) _ ≤ 1 := hp'.2 exact ⟨h0, hle⟩ have hfiber (t : ℝ) : (∫ w : Fin m → ℝ, S.indicator (fun p : ℝ × (Fin m → ℝ) => p.1 * p.2 0) (t, w) ∂volume) = if ht : t ∈ Icc (0 : ℝ) 1 then t * (∫ w in scaledSpacingSimplex m (1 - t), w 0 ∂volume) else 0 := by split_ifs with ht · have hs : MeasurableSet {w : Fin m → ℝ | (t, w) ∈ S} := hS.preimage measurable_prodMk_left calc _ = ∫ w in {w : Fin m → ℝ | (t, w) ∈ S}, t * w 0 ∂volume := by rw [← integral_indicator hs] congr 1 _ = t * (∫ w in scaledSpacingSimplex m (1 - t), w 0 ∂volume) := by rw [hsection t ht, integral_const_mul] · have hzero : ∀ w : Fin m → ℝ, (t, w) ∉ S := by intro w hw exact ht (hsubset (t, w) hw) simp [indicator, hzero] change (∫ z in spacingSimplex (m + 1), z 0 * z 1 ∂volume) = _ calc (∫ z in spacingSimplex (m + 1), z 0 * z 1 ∂volume) = ∫ p in S, p.1 * p.2 0 ∂volume := by rw [← hem.map_eq, setIntegral_map_equiv] rfl _ = ∫ p : ℝ × (Fin m → ℝ), S.indicator (fun p : ℝ × (Fin m → ℝ) => p.1 * p.2 0) p ∂volume := by rw [integral_indicator hS] _ = ∫ t : ℝ, ∫ w : Fin m → ℝ, S.indicator (fun p : ℝ × (Fin m → ℝ) => p.1 * p.2 0) (t, w) ∂volume := by rw [Measure.volume_eq_prod] exact integral_prod _ hprodInt _ = ∫ t in Icc (0 : ℝ) 1, t * (∫ w in scaledSpacingSimplex m (1 - t), w 0 ∂volume) ∂volume := by simp_rw [hfiber] rw [← integral_indicator measurableSet_Icc] congr 1 funext t simp [indicator, dite_eq_ite]
    Causalean.Stat.OrderStatistic.WeightedConcomitant.simplex_first_second_cross_fubini · Causalean/Stat/OrderStatistic/WeightedConcomitant/OrderStatisticMoments.lean:299
  • unit_beta_linear_integral theorem — For a natural exponent, the first-moment beta integral over the unit interval equals the factorial ratio n!/(n+2)!.
    n :
    ℕ
    (∫ t in Icc (0 : ℝ) 1, t * (1 - t) ^ n ∂volume)
    = (n.factorial : ℝ) / ((n + 2).factorial : ℝ)
    Proof (Lean source)
    theorem unit_beta_linear_integral (n : ℕ) : (∫ t in Icc (0 : ℝ) 1, t * (1 - t) ^ n ∂volume) = (n.factorial : ℝ) / ((n + 2).factorial : ℝ) := by have hbeta : (∫ t in (0 : ℝ)..1, t * (1 - t) ^ n) = (n.factorial : ℝ) / ((n + 2).factorial : ℝ) := by have hbeta_complex : (∫ t in (0 : ℝ)..1, ((t * (1 - t) ^ n : ℝ) : ℂ)) = Complex.betaIntegral 2 (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_pow, Complex.ofReal_sub, Complex.ofReal_one] norm_num have heval := Complex.betaIntegral_eq_Gamma_mul_div 2 (n + 1) (by norm_num) (by simp; positivity) rw [← hbeta_complex] at heval have hg3 : Complex.Gamma 2 = 1 := by convert Complex.Gamma_nat_eq_factorial 1 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 (2 + (n + 1)) = ((n + 2).factorial : ℂ) := by convert Complex.Gamma_nat_eq_factorial (n + 2) 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) rw [integral_Icc_eq_integral_Ioc, ← intervalIntegral.integral_of_le (by norm_num : (0 : ℝ) ≤ 1)] exact hbeta
    Causalean.Stat.OrderStatistic.WeightedConcomitant.unit_beta_linear_integral · Causalean/Stat/OrderStatistic/WeightedConcomitant/OrderStatisticMoments.lean:425
  • simplex_cross_coordinate_eq_first_two theorem — For distinct coordinates in a spacing simplex, their product integral equals the product integral of coordinates zero and one.
    n :
    ℕ
    i j :
    Fin (n + 2)
    hij :
    i ≠ j
    (∫ z in spacingSimplex (n + 2), z i * z j ∂volume)
    = ∫ z in spacingSimplex (n + 2), z (0 : Fin (n + 2)) * z (1 : Fin (n + 2)) ∂volume
    Proof (Lean source)
    theorem simplex_cross_coordinate_eq_first_two (n : ℕ) (i j : Fin (n + 2)) (hij : i ≠ j) : (∫ z in spacingSimplex (n + 2), z i * z j ∂volume) = ∫ z in spacingSimplex (n + 2), z (0 : Fin (n + 2)) * z (1 : Fin (n + 2)) ∂volume := by classical let τ : Perm (Fin (n + 2)) := swap 0 i let σ : Perm (Fin (n + 2)) := τ.trans (swap (τ 1) j) have hτ0 : τ 0 = i := Equiv.swap_apply_left 0 i have hτ1i : τ 1 ≠ i := by intro h have h' : (1 : Fin (n + 2)) = 0 := τ.injective (h.trans hτ0.symm) exact (by norm_num : (1 : Fin (n + 2)) ≠ 0) h' have hσ0 : σ 0 = i := by change (swap (τ 1) j) (τ 0) = i rw [hτ0] exact Equiv.swap_apply_of_ne_of_ne (Ne.symm hτ1i) hij have hσ1 : σ 1 = j := Equiv.swap_apply_left (τ 1) j let e : (Fin (n + 2) → ℝ) ≃ᵐ (Fin (n + 2) → ℝ) := MeasurableEquiv.piCongrLeft (fun _ : Fin (n + 2) => ℝ) σ.symm have he : MeasurePreserving e volume volume := volume_measurePreserving_piCongrLeft (fun _ : Fin (n + 2) => ℝ) σ.symm have hfun (z : Fin (n + 2) → ℝ) : e z = z ∘ σ := by funext k simp [e, MeasurableEquiv.coe_piCongrLeft, Equiv.piCongrLeft_apply] have hpre : e ⁻¹' spacingSimplex (n + 2) = spacingSimplex (n + 2) := 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 + 2))) (volume.restrict (spacingSimplex (n + 2))) := by refine ⟨e.measurable, ?_⟩ calc (volume.restrict (spacingSimplex (n + 2))).map e = (volume.restrict (e ⁻¹' spacingSimplex (n + 2))).map e := by rw [hpre] _ = (volume.map e).restrict (spacingSimplex (n + 2)) := (e.restrict_map volume (spacingSimplex (n + 2))).symm _ = volume.restrict (spacingSimplex (n + 2)) := by rw [he.map_eq] have hint := hmp.integral_comp' (fun z : Fin (n + 2) → ℝ => z (0 : Fin (n + 2)) * z (1 : Fin (n + 2))) simp only [hfun] at hint simpa [hσ0, hσ1] using hint
    Causalean.Stat.OrderStatistic.WeightedConcomitant.simplex_cross_coordinate_eq_first_two · Causalean/Stat/OrderStatistic/WeightedConcomitant/OrderStatisticMoments.lean:461
Power­L1­Core 1 core · 7 supporting The hinge-cell kernel is an adjacent order-statistic CDF. ★ bernsteinCell_power_eq_sub_curvature_hinge_integral

L1 approximation of the power density by finite Bernstein cells

The hinge-cell kernel is an adjacent order-statistic CDF. Combined with a curvature representation of a real power, this reduces the small-power L1 bound to the centered adjacent-mixture moment bound. The endpoint and large-power cases use unit-density identities.

theorem bernsteinCell_power_eq_sub_curvature_hinge_integral reviewed
Causalean.Stat.OrderStatistic.WeightedConcomitant

For a positive sample size, power strictly above one, and evaluation point, the Bernstein kernel of the power cell masses equals the power itself minus the integral, over thresholds in the unit interval, of the curvature density times the Bernstein kernel of the hinge-cell increments at that threshold.

Formal statement
N :
ℕ
hN :
0 < N
s :
ℝ
hs :
1 < s
u :
ℝ
= s
- ∫ t in Icc (0 : ℝ) 1, powerCurvature s t * bernsteinCell N (hingeCell N t) u ∂volume
Proof (Lean source)
theorem bernsteinCell_power_eq_sub_curvature_hinge_integral {N : ℕ} (hN : 0 < N) {s : ℝ} (hs : 1 < s) (u : ℝ) : bernsteinCell N (powerCell N s) u = s - ∫ t in Icc (0 : ℝ) 1, powerCurvature s t * bernsteinCell N (hingeCell N t) u ∂volume := by -- Integrate the preceding hinge representation over each cell, then use -- finite-sum linearity and the binomial partition of unity. This is valid -- for every real u because the Bernstein basis sum is identically one. let b (j : Fin N) : ℝ := (choose (N - 1) (j : ℕ) : ℝ) * u ^ (j : ℕ) * (1 - u) ^ (N - 1 - (j : ℕ)) have hNr : (N : ℝ) ≠ 0 := by exact_mod_cast (Nat.ne_of_gt hN) have hsum : (∑ j : Fin N, b j) = 1 := by have hpow := add_pow u (1 - u) (N - 1) rw [show N - 1 + 1 = N by omega, ← Fin.sum_univ_eq_sum_range] at hpow convert hpow.symm using 1 · apply Finset.sum_congr rfl intro j hj dsimp [b] ring · ring have hr : IntervalIntegrable (fun x : ℝ => x ^ (s - 2)) volume 0 1 := intervalIntegral.intervalIntegrable_rpow' (by linarith) have hr' : IntervalIntegrable (fun t : ℝ => (1 - t) ^ (s - 2)) volume 0 1 := by convert (hr.comp_sub_left 1).symm using 1 <;> norm_num have hq : Integrable (powerCurvature s) (volume.restrict (Icc (0 : ℝ) 1)) := by apply (intervalIntegrable_iff_integrableOn_Icc_of_le (by norm_num : (0 : ℝ) ≤ 1)).mp change IntervalIntegrable (fun t : ℝ => s * (s - 1) * (1 - t) ^ (s - 2)) volume 0 1 exact hr'.const_mul (s * (s - 1)) have hbound (j : Fin N) (t : ℝ) : ‖hingeCell N t j‖ ≤ (1 : ℝ) / N := by have hNr' : (0 : ℝ) < N := by exact_mod_cast hN have hw : (((j : ℕ) : ℝ) + 1) / N - ((j : ℕ) : ℝ) / N = (1 : ℝ) / N := by ring rw [hingeCell_eq_piecewise hN] split_ifs with ha hb · rw [Real.norm_eq_abs, abs_of_nonneg (by positivity)] · have hlt : ((j : ℕ) : ℝ) / N < t := lt_of_not_ge ha have hnonneg : 0 ≤ (((j : ℕ) : ℝ) + 1) / N - t := by linarith rw [Real.norm_eq_abs, abs_of_nonneg hnonneg] linarith · simp [hNr'.le] have hint (j : Fin N) : Integrable (fun t : ℝ => powerCurvature s t * hingeCell N t j) (volume.restrict (Icc (0 : ℝ) 1)) := by apply hq.mul_bdd (c := (1 : ℝ) / N) · have hc : Continuous (hingeCell N · j) := by unfold hingeCell fun_prop exact hc.aestronglyMeasurable · filter_upwards [] with t exact hbound j t have hint' (j : Fin N) : Integrable (fun t : ℝ => powerCurvature s t * hingeCell N t j * b j) (volume.restrict (Icc (0 : ℝ) 1)) := (hint j).mul_const _ have hswap : (∑ j : Fin N, (∫ t in Icc (0 : ℝ) 1, powerCurvature s t * hingeCell N t j ∂volume) * b j) = ∫ t in Icc (0 : ℝ) 1, ∑ j : Fin N, powerCurvature s t * hingeCell N t j * b j ∂volume := by rw [integral_finsetSum (s := univ) (fun j hj => hint' j)] apply Finset.sum_congr rfl intro j hj rw [integral_mul_const] calc bernsteinCell N (powerCell N s) u = N * ∑ j : Fin N, powerCell N s j * b j := by unfold bernsteinCell congr 1 apply Finset.sum_congr rfl intro j hj dsimp [b] ring _ = N * ∑ j : Fin N, (s / N - ∫ t in Icc (0 : ℝ) 1, powerCurvature s t * hingeCell N t j ∂volume) * b j := by congr 1 apply Finset.sum_congr rfl intro j hj rw [powerCell_eq_sub_curvature_hinge_integral hN hs j] _ = N * (s / N * (∑ j : Fin N, b j) - ∑ j : Fin N, (∫ t in Icc (0 : ℝ) 1, powerCurvature s t * hingeCell N t j ∂volume) * b j) := by congr 1 rw [Finset.mul_sum, ← Finset.sum_sub_distrib] apply Finset.sum_congr rfl intro j hj ring _ = s - ∫ t in Icc (0 : ℝ) 1, powerCurvature s t * bernsteinCell N (hingeCell N t) u ∂volume := by rw [hsum, mul_one, hswap, mul_sub, mul_div_cancel₀ s hNr] rw [← integral_const_mul] congr 1 apply integral_congr_ae filter_upwards [] with t simp only [bernsteinCell, Finset.mul_sum] apply Finset.sum_congr rfl intro j hj dsimp [b] ring
Causalean.Stat.OrderStatistic.WeightedConcomitant.bernsteinCell_power_eq_sub_curvature_hinge_integral · Causalean/Stat/OrderStatistic/WeightedConcomitant/PowerL1Core.lean:432 · uses bernsteinCell , hingeCell , powerCell , powerCurvature
7 supporting declarations (lemmas, instances)
  • hingeCell_at_adjacent theorem — At an adjacent threshold (k+δ)/N, multiplying a hinge-cell mass by N gives zero before cell k, 1-δ in cell k, and one after it.
    N k :
    ℕ
    hN :
    0 < N
    hk :
    k < N
    δ :
    ℝ
    hδ :
    δ ∈ Icc (0 : ℝ) 1
    j :
    Fin N
    (N : ℝ) * hingeCell N ((k + δ) / N) j
    = if (j : ℕ) < k then 0 else if (j : ℕ) = k then 1 - δ else 1
    Proof (Lean source)
    theorem hingeCell_at_adjacent {N k : ℕ} (hN : 0 < N) (hk : k < N) {δ : ℝ} (hδ : δ ∈ Icc (0 : ℝ) 1) (j : Fin N) : (N : ℝ) * hingeCell N ((k + δ) / N) j = if (j : ℕ) < k then 0 else if (j : ℕ) = k then 1 - δ else 1 := by have hNr : (0 : ℝ) < N := by exact_mod_cast hN have hNne : (N : ℝ) ≠ 0 := ne_of_gt hNr rcases hδ with ⟨hδ0, hδ1⟩ rw [hingeCell_eq_piecewise hN] rcases lt_trichotomy (j : ℕ) k with hjk | hjk | hkj · have hjk' : ((j : ℕ) : ℝ) + 1 ≤ (k : ℝ) := by exact_mod_cast Nat.succ_le_of_lt hjk have hleft : ¬ (k + δ) / (N : ℝ) ≤ ((j : ℕ) : ℝ) / (N : ℝ) := by rw [div_le_div_iff_of_pos_right hNr] linarith simp only [if_pos hjk, if_neg hleft] split_ifs with hmid · have hmid' : (k : ℝ) + δ ≤ ((j : ℕ) : ℝ) + 1 := by exact (div_le_div_iff_of_pos_right hNr).mp hmid have heq : (k : ℝ) + δ = ((j : ℕ) : ℝ) + 1 := by linarith rw [← heq] ring · ring · subst k have hmid : ((j : ℕ) : ℝ) + δ ≤ ((j : ℕ) : ℝ) + 1 := by linarith have hmid' : (((j : ℕ) : ℝ) + δ) / (N : ℝ) ≤ (((j : ℕ) : ℝ) + 1) / (N : ℝ) := (div_le_div_iff_of_pos_right hNr).mpr hmid simp only [lt_self_iff_false, ↓reduceIte, if_pos hmid'] split_ifs with hleft · have hδeq : δ = 0 := by have := (div_le_div_iff_of_pos_right hNr).mp hleft linarith simp [hδeq, hNne] · field_simp ring · have hkj' : (k : ℝ) + 1 ≤ ((j : ℕ) : ℝ) := by exact_mod_cast Nat.succ_le_of_lt hkj have hleft : ((k : ℝ) + δ) / (N : ℝ) ≤ ((j : ℕ) : ℝ) / (N : ℝ) := (div_le_div_iff_of_pos_right hNr).mpr (by linarith) simp [not_lt.mpr (le_of_lt hkj), ne_of_gt hkj, hleft, hNne]
    Causalean.Stat.OrderStatistic.WeightedConcomitant.hingeCell_at_adjacent · Causalean/Stat/OrderStatistic/WeightedConcomitant/PowerL1Core.lean:23
  • bernsteinCell_hinge_eq_binomial_tails theorem — The Bernstein kernel of an adjacent hinge is the convex combination of the two binomial upper tails with cutoffs k and k+1.
    N k :
    ℕ
    hN :
    0 < N
    hk :
    k < N
    δ :
    ℝ
    hδ :
    δ ∈ Icc (0 : ℝ) 1
    u :
    ℝ
    bernsteinCell N (hingeCell N ((k + δ) / N)) u
    = (1 - δ) * (∑ j ∈ Icc k (N - 1), (choose (N - 1) j : ℝ) * u ^ j * (1 - u) ^ (N - 1 - j))
    + δ * (∑ j ∈ Icc (k + 1) (N - 1), (choose (N - 1) j : ℝ) * u ^ j * (1 - u) ^ (N - 1 - j))
    Proof (Lean source)
    theorem bernsteinCell_hinge_eq_binomial_tails {N k : ℕ} (hN : 0 < N) (hk : k < N) {δ : ℝ} (hδ : δ ∈ Icc (0 : ℝ) 1) (u : ℝ) : bernsteinCell N (hingeCell N ((k + δ) / N)) u = (1 - δ) * (∑ j ∈ Icc k (N - 1), (choose (N - 1) j : ℝ) * u ^ j * (1 - u) ^ (N - 1 - j)) + δ * (∑ j ∈ Icc (k + 1) (N - 1), (choose (N - 1) j : ℝ) * u ^ j * (1 - u) ^ (N - 1 - j)) := by let f : ℕ → ℝ := fun j => (choose (N - 1) j : ℝ) * u ^ j * (1 - u) ^ (N - 1 - j) have hsets (a : ℕ) : Icc a (N - 1) = (range N).filter (fun j => a ≤ j) := by ext j simp only [Finset.mem_Icc, mem_filter, Finset.mem_range] omega have htail (a : ℕ) : (∑ j ∈ range N, if a ≤ j then f j else 0) = ∑ j ∈ Icc a (N - 1), f j := by rw [hsets, Finset.sum_filter] have hcoeff (j : ℕ) : (if j < k then (0 : ℝ) else if j = k then 1 - δ else 1) = (if k ≤ j then 1 - δ else 0) + (if k + 1 ≤ j then δ else 0) := by rcases lt_trichotomy j k with h | h | h · simp [h, show ¬ k ≤ j by omega, show ¬ k + 1 ≤ j by omega] · subst j simp · have hkj : k + 1 ≤ j := succ_le_of_lt h simp [show ¬ j < k by omega, show j ≠ k by omega, hkj, le_of_lt h] calc bernsteinCell N (hingeCell N ((k + δ) / N)) u = ∑ j : Fin N, ((if (j : ℕ) < k then (0 : ℝ) else if (j : ℕ) = k then 1 - δ else 1) * f (j : ℕ)) := by unfold bernsteinCell rw [Finset.mul_sum] apply Finset.sum_congr rfl intro j hj rw [← hingeCell_at_adjacent hN hk hδ j] dsimp [f] ring _ = ∑ j ∈ range N, ((if j < k then (0 : ℝ) else if j = k then 1 - δ else 1) * f j) := by simpa only using (Fin.sum_univ_eq_sum_range (fun j : ℕ => (if j < k then (0 : ℝ) else if j = k then 1 - δ else 1) * f j) N) _ = ∑ j ∈ range N, ((if k ≤ j then 1 - δ else 0) * f j + (if k + 1 ≤ j then δ else 0) * f j) := by apply Finset.sum_congr rfl intro j hj rw [hcoeff j] ring _ = (1 - δ) * (∑ j ∈ Icc k (N - 1), f j) + δ * (∑ j ∈ Icc (k + 1) (N - 1), f j) := by calc _ = ∑ j ∈ range N, ((1 - δ) * (if k ≤ j then f j else 0) + δ * (if k + 1 ≤ j then f j else 0)) := by apply Finset.sum_congr rfl intro j hj simp only [ite_mul, mul_ite, zero_mul, mul_zero] _ = _ := by rw [Finset.sum_add_distrib, ← Finset.mul_sum, ← Finset.mul_sum, htail k, htail (k + 1)] _ = _ := rfl
    Causalean.Stat.OrderStatistic.WeightedConcomitant.bernsteinCell_hinge_eq_binomial_tails · Causalean/Stat/OrderStatistic/WeightedConcomitant/PowerL1Core.lean:67
  • bernsteinCell_hinge_eq_adjacent_cdf theorem — For a positive sample size, adjacent cell, and interpolation fraction, at an interior point, the Bernstein density of the corresponding hinge increments is the CDF of the adjacent order-statistic mixture at each interior point of the unit interval.
    N k :
    ℕ
    hN :
    0 < N
    hk :
    k < N
    δ :
    ℝ
    hδ :
    δ ∈ Icc (0 : ℝ) 1
    u :
    ℝ
    hu :
    u ∈ Ioo (0 : ℝ) 1
    bernsteinCell N (hingeCell N ((k + δ) / N)) u
    = ((adjacentOrderMix N k δ) (Iic u)).toReal
    Proof (Lean source)
    theorem bernsteinCell_hinge_eq_adjacent_cdf {N k : ℕ} (hN : 0 < N) (hk : k < N) {δ : ℝ} (hδ : δ ∈ Icc (0 : ℝ) 1) {u : ℝ} (hu : u ∈ Ioo (0 : ℝ) 1) : bernsteinCell N (hingeCell N ((k + δ) / N)) u = ((adjacentOrderMix N k δ) (Iic u)).toReal := by -- A hinge increment is 0 below cell k, (1-δ)/N in cell k, and -- 1/N above it. The Bernstein binomial tail is the CDF of the -- kth order statistic of N-1 uniforms; mix the adjacent tails. -- At δ=1 and u=1 the deterministic upper endpoint creates a CDF jump, -- so this exact pointwise identity is stated on the open interval. let ν := iidSample uniform01 (N - 1) let μ₀ : Measure ℝ := ν.map (fun x => if h : k = 0 then (0 : ℝ) else if h' : k ≤ N - 1 then sortedSample (N - 1) x ⟨k - 1, by omega⟩ else 1) let μ₁ : Measure ℝ := ν.map (fun x => if h : k + 1 = N then (1 : ℝ) else if h' : k < N - 1 then sortedSample (N - 1) x ⟨k, h'⟩ else 1) haveI : IsProbabilityMeasure uniform01 := ⟨by simp [uniform01]⟩ have hν : IsProbabilityMeasure ν := by dsimp [ν, iidSample] infer_instance letI := hν haveI : IsFiniteMeasure μ₀ := by dsimp [μ₀] exact Measure.isFiniteMeasure_map ν _ haveI : IsFiniteMeasure μ₁ := by dsimp [μ₁] exact Measure.isFiniteMeasure_map ν _ haveI : IsFiniteMeasure ((ofReal (1 - δ)) • μ₀) := Measure.smul_finite μ₀ (by simp) haveI : IsFiniteMeasure ((ofReal δ) • μ₁) := Measure.smul_finite μ₁ (by simp) have hδ₀ : 0 ≤ δ := hδ.1 have hδ₁ : 0 ≤ 1 - δ := by linarith [hδ.2] have hmix : ((adjacentOrderMix N k δ) (Iic u)).toReal = (1 - δ) * (μ₀ (Iic u)).toReal + δ * (μ₁ (Iic u)).toReal := by change (((ofReal (1 - δ)) • μ₀ + (ofReal δ) • μ₁) (Iic u)).toReal = _ rw [← Measure.real, measureReal_add_apply, measureReal_ennreal_smul_apply, measureReal_ennreal_smul_apply] simp [Measure.real, ENNReal.toReal_ofReal hδ₀, ENNReal.toReal_ofReal hδ₁] have hL : (μ₀ (Iic u)).toReal = ∑ j ∈ Icc k (N - 1), (choose (N - 1) j : ℝ) * u ^ j * (1 - u) ^ (N - 1 - j) := by by_cases hk₀ : k = 0 · subst k have hs : (∑ j ∈ Icc 0 (N - 1), (choose (N - 1) j : ℝ) * u ^ j * (1 - u) ^ (N - 1 - j)) = 1 := by have hI : Icc 0 (N - 1) = range ((N - 1) + 1) := by ext j simp only [Finset.mem_Icc, zero_le, true_and, Finset.mem_range] omega rw [hI] calc _ = ∑ j ∈ range (N - 1 + 1), u ^ j * (1 - u) ^ (N - 1 - j) * (choose (N - 1) j : ℝ) := by apply Finset.sum_congr rfl intro j hj ring _ = (u + (1 - u)) ^ (N - 1) := by rw [add_pow] _ = 1 := by simp simp [μ₀, Measure.map_const, hs, hu.1.le] · have hkn : k ≤ N - 1 := by omega have hr : k - 1 < N - 1 := by omega have hks : k - 1 + 1 = k := by omega simp only [μ₀, hk₀, hkn, dite_false, dite_true] rw [uniform_sorted_cdf_eq_binomial_tail ⟨k - 1, hr⟩ ⟨hu.1.le, hu.2.le⟩] have h1u : 0 ≤ 1 - u := by linarith [hu.2] rw [hks, ENNReal.toReal_ofReal (Finset.sum_nonneg (by intro j hj exact mul_nonneg (mul_nonneg (by positivity) (pow_nonneg hu.1.le _)) (pow_nonneg h1u _)))] have hU : (μ₁ (Iic u)).toReal = ∑ j ∈ Icc (k + 1) (N - 1), (choose (N - 1) j : ℝ) * u ^ j * (1 - u) ^ (N - 1 - j) := by by_cases htop : k + 1 = N · have hs : (∑ j ∈ Icc (k + 1) (N - 1), (choose (N - 1) j : ℝ) * u ^ j * (1 - u) ^ (N - 1 - j)) = 0 := by have : Icc (k + 1) (N - 1) = ∅ := by apply Finset.Icc_eq_empty_of_lt omega simp [this] have heq : μ₁ = ν.map (fun _ => (1 : ℝ)) := by simp [μ₁, htop] rw [heq, Measure.map_const] simp [hs, Set.mem_Iic, not_le.mpr hu.2] · have hkn : k < N - 1 := by omega have hks : k + 1 ≤ N - 1 := by omega simp only [μ₁, htop, hkn, dite_false, dite_true] rw [uniform_sorted_cdf_eq_binomial_tail ⟨k, hkn⟩ ⟨hu.1.le, hu.2.le⟩] have h1u : 0 ≤ 1 - u := by linarith [hu.2] rw [ENNReal.toReal_ofReal (Finset.sum_nonneg (by intro j hj exact mul_nonneg (mul_nonneg (by positivity) (pow_nonneg hu.1.le _)) (pow_nonneg h1u _)))] rw [bernsteinCell_hinge_eq_binomial_tails hN hk hδ u, hmix, hL, hU]
    Causalean.Stat.OrderStatistic.WeightedConcomitant.bernsteinCell_hinge_eq_adjacent_cdf · Causalean/Stat/OrderStatistic/WeightedConcomitant/PowerL1Core.lean:136
  • unit_threshold_eq_adjacent theorem — Every threshold in the unit interval lies in an adjacent cell of a positive sample size, including the right endpoint by taking the last cell and interpolation fraction one.
    N :
    ℕ
    hN :
    0 < N
    t :
    ℝ
    ht :
    t ∈ Icc (0 : ℝ) 1
    ∃ k : ℕ, ∃ δ : ℝ,
    conclusion 1
    k < N
    conclusion 2
    δ ∈ Icc (0 : ℝ) 1
    conclusion 3
    t = (k + δ) / N
    Proof (Lean source)
    theorem unit_threshold_eq_adjacent {N : ℕ} (hN : 0 < N) {t : ℝ} (ht : t ∈ Icc (0 : ℝ) 1) : ∃ k : ℕ, ∃ δ : ℝ, k < N ∧ δ ∈ Icc (0 : ℝ) 1 ∧ t = (k + δ) / N := by have hNr : (0 : ℝ) < N := by exact_mod_cast hN have hNne : (N : ℝ) ≠ 0 := ne_of_gt hNr by_cases htop : t = 1 · refine ⟨N - 1, 1, by omega, by norm_num, ?_⟩ rw [htop] have hlast : ((N - 1 : ℕ) : ℝ) + 1 = N := by exact_mod_cast (by omega : N - 1 + 1 = N) rw [hlast] exact (div_self hNne).symm · have htlt : t < 1 := lt_of_le_of_ne ht.2 htop let k := Nat.floor ((N : ℝ) * t) let δ := (N : ℝ) * t - k have hNt0 : 0 ≤ (N : ℝ) * t := mul_nonneg hNr.le ht.1 have hklo : (k : ℝ) ≤ (N : ℝ) * t := Nat.floor_le hNt0 have hkhi : (N : ℝ) * t < (k : ℝ) + 1 := Nat.lt_floor_add_one _ have hkN : k < N := by have hkr : (k : ℝ) < N := lt_of_le_of_lt hklo (mul_lt_of_lt_one_right hNr htlt) exact_mod_cast hkr refine ⟨k, δ, hkN, ⟨by dsimp [δ]; linarith, by dsimp [δ]; linarith⟩, ?_⟩ dsimp [δ] field_simp ring
    Causalean.Stat.OrderStatistic.WeightedConcomitant.unit_threshold_eq_adjacent · Causalean/Stat/OrderStatistic/WeightedConcomitant/PowerL1Core.lean:240
  • bernsteinCell_hinge_indicator_L1 theorem — For a unit-interval threshold, the Bernstein kernel of its hinge cells approximates the threshold step function in L1 with error at most sqrt (2*t/N) for a positive sample size.
    N :
    ℕ
    hN :
    0 < N
    t :
    ℝ
    ht :
    t ∈ Icc (0 : ℝ) 1
    (∫ u in Icc (0 : ℝ) 1, |bernsteinCell N (hingeCell N t) u - (if t ≤ u then (1 : ℝ) else 0)| ∂volume)
    ≤ sqrt (2 * t / N)
    Proof (Lean source)
    theorem bernsteinCell_hinge_indicator_L1 {N : ℕ} (hN : 0 < N) {t : ℝ} (ht : t ∈ Icc (0 : ℝ) 1) : (∫ u in Icc (0 : ℝ) 1, |bernsteinCell N (hingeCell N t) u - (if t ≤ u then (1 : ℝ) else 0)| ∂volume) ≤ sqrt (2 * t / N) := by obtain ⟨k, δ, hk, hδ, rfl⟩ := unit_threshold_eq_adjacent hN ht have hEq : (∫ u in Icc (0 : ℝ) 1, |bernsteinCell N (hingeCell N ((k + δ) / N)) u - (if (k + δ) / N ≤ u then (1 : ℝ) else 0)| ∂volume) = (∫ u in Icc (0 : ℝ) 1, |((adjacentOrderMix N k δ) (Iic u)).toReal - (if (k + δ) / N ≤ u then (1 : ℝ) else 0)| ∂volume) := by simp only [integral_Icc_eq_integral_Ioo] apply setIntegral_congr_fun measurableSet_Ioo intro u hu dsimp rw [bernsteinCell_hinge_eq_adjacent_cdf hN hk hδ hu] rw [hEq] exact _root_.Causalean.Stat.OrderStatistic.WeightedConcomitant.adjacentOrderMix_indicator_L1_le_sqrt_two_t_over_N hN hk hδ
    Causalean.Stat.OrderStatistic.WeightedConcomitant.bernsteinCell_hinge_indicator_L1 · Causalean/Stat/OrderStatistic/WeightedConcomitant/PowerL1Core.lean:270
  • powerDensity_eq_sub_curvature_integral theorem — For a power strictly greater than one and unit-interval point, the power density is a constant minus its integrated curvature thresholds.
    s u :
    ℝ
    hs :
    1 < s
    hu :
    u ∈ Icc (0 : ℝ) 1
    = s
    - ∫ t in Icc (0 : ℝ) 1, powerCurvature s t * (if t ≤ u then (1 : ℝ) else 0) ∂volume
    Proof (Lean source)
    theorem powerDensity_eq_sub_curvature_integral {s u : ℝ} (hs : 1 < s) (hu : u ∈ Icc (0 : ℝ) 1) : powerDensity s u = s - ∫ t in Icc (0 : ℝ) 1, powerCurvature s t * (if t ≤ u then (1 : ℝ) else 0) ∂volume := by have hind : (fun t : ℝ => powerCurvature s t * (if t ≤ u then (1 : ℝ) else 0)) = (Iic u).indicator (powerCurvature s) := by funext t by_cases ht : t ≤ u <;> simp [indicator, ht] have hset : Icc (0 : ℝ) 1 ∩ Iic u = Icc 0 u := by ext t simp only [Set.mem_inter_iff, Set.mem_Icc, Set.mem_Iic] constructor · rintro ⟨⟨ht0, _⟩, htu⟩ exact ⟨ht0, htu⟩ · rintro ⟨ht0, htu⟩ exact ⟨⟨ht0, htu.trans hu.2⟩, htu⟩ rw [hind, setIntegral_indicator measurableSet_Iic, hset, integral_powerCurvature_Icc hs hu] ring
    Causalean.Stat.OrderStatistic.WeightedConcomitant.powerDensity_eq_sub_curvature_integral · Causalean/Stat/OrderStatistic/WeightedConcomitant/PowerL1Core.lean:297
  • powerCell_eq_sub_curvature_hinge_integral theorem — For a positive sample size and a real power above one, each power cell mass is its constant-density mass minus the curvature-weighted hinge cell.
    N :
    ℕ
    hN :
    0 < N
    s :
    ℝ
    hs :
    1 < s
    j :
    Fin N
    powerCell N s j
    = s / N - ∫ t in Icc (0 : ℝ) 1, powerCurvature s t * hingeCell N t j ∂volume
    Proof (Lean source)
    theorem powerCell_eq_sub_curvature_hinge_integral {N : ℕ} (hN : 0 < N) {s : ℝ} (hs : 1 < s) (j : Fin N) : powerCell N s j = s / N - ∫ t in Icc (0 : ℝ) 1, powerCurvature s t * hingeCell N t j ∂volume := by let a : ℝ := (j : ℝ) / N let b : ℝ := (((j : ℕ) + 1 : ℝ) / N) have hNr : (0 : ℝ) < N := by exact_mod_cast hN have hab : a ≤ b := by dsimp [a, b] apply div_le_div_of_nonneg_right _ hNr.le linarith have ha0 : 0 ≤ a := by dsimp [a]; positivity have hb1 : b ≤ 1 := by dsimp [b] apply (div_le_one hNr).2 exact_mod_cast j.isLt have hgeom (t : ℝ) : (∫ u in Ioc a b, if t ≤ u then (1 : ℝ) else 0 ∂volume) = hingeCell N t j := by have hstep : (∫ u in Ioc a b, if t ≤ u then (1 : ℝ) else 0 ∂volume) = (∫ u in Ioc a b, (Ioi t).indicator (fun _ => (1 : ℝ)) u ∂volume) := by apply integral_congr_ae filter_upwards [ae_restrict_of_ae (volume.ae_ne t)] with u hu by_cases htu : t < u · simp [indicator, htu, htu.le] · have : ¬ t ≤ u := by intro h rcases h.eq_or_lt with he | hl · exact hu he.symm · exact htu hl simp [indicator, htu, this] rw [hstep, setIntegral_indicator measurableSet_Ioi, Set.Ioc_inter_Ioi] simp only [setIntegral_const, smul_eq_mul, mul_one, Real.volume_real_Ioc] change max (b - max a t) 0 = max (b - t) 0 - max (a - t) 0 rcases le_total t a with h | h · rw [max_eq_left h] simp [max_eq_left (by linarith : 0 ≤ b - a), max_eq_left (by linarith : 0 ≤ b - t), max_eq_left (by linarith : 0 ≤ a - t)] · rcases le_total t b with h' | h' · rw [max_eq_right h] simp [max_eq_left (by linarith : 0 ≤ b - t), max_eq_right (by linarith : a - t ≤ 0)] · rw [max_eq_right h] simp [max_eq_right (by linarith : b - t ≤ 0), max_eq_right (by linarith : a - t ≤ 0)] have hr : IntervalIntegrable (fun x : ℝ => x ^ (s - 2)) volume 0 1 := intervalIntegral.intervalIntegrable_rpow' (by linarith) have hr' : IntervalIntegrable (fun t : ℝ => (1 - t) ^ (s - 2)) volume 0 1 := by convert (hr.comp_sub_left 1).symm using 1 <;> norm_num have hq : Integrable (powerCurvature s) (volume.restrict (Icc (0 : ℝ) 1)) := by apply (intervalIntegrable_iff_integrableOn_Icc_of_le (by norm_num : (0 : ℝ) ≤ 1)).mp change IntervalIntegrable (fun t : ℝ => s * (s - 1) * (1 - t) ^ (s - 2)) volume 0 1 exact hr'.const_mul (s * (s - 1)) let μ := volume.restrict (Ioc a b) let ν := volume.restrict (Icc (0 : ℝ) 1) have hqprod : Integrable (fun z : ℝ × ℝ => powerCurvature s z.2) (μ.prod ν) := by exact hq.comp_snd μ have hF : Integrable (fun z : ℝ × ℝ => powerCurvature s z.2 * if z.2 ≤ z.1 then (1 : ℝ) else 0) (μ.prod ν) := by apply hqprod.mul_bdd (c := 1) · exact ((measurable_const.ite (measurableSet_le measurable_snd measurable_fst) measurable_const).aestronglyMeasurable) · filter_upwards [] with z split_ifs <;> simp have hswap : (∫ u in Ioc a b, ∫ t in Icc (0 : ℝ) 1, powerCurvature s t * if t ≤ u then (1 : ℝ) else 0 ∂volume ∂volume) = (∫ t in Icc (0 : ℝ) 1, ∫ u in Ioc a b, powerCurvature s t * if t ≤ u then (1 : ℝ) else 0 ∂volume ∂volume) := by exact integral_integral_swap (μ := μ) (ν := ν) hF have hinner_int : Integrable (fun u : ℝ => ∫ t in Icc (0 : ℝ) 1, powerCurvature s t * if t ≤ u then (1 : ℝ) else 0 ∂volume) μ := hF.integral_prod_left have hcell : powerCell N s j = ∫ u in Ioc a b, powerDensity s u ∂volume := by rw [powerCell_eq_integral hN hs.le j, intervalIntegral.integral_of_le hab] rfl have hconst : (∫ u in Ioc a b, s ∂volume) = s / N := by rw [setIntegral_const, Real.volume_real_Ioc_of_le hab] simp only [smul_eq_mul] dsimp [a, b] field_simp ring calc powerCell N s j = ∫ u in Ioc a b, powerDensity s u ∂volume := hcell _ = ∫ u in Ioc a b, s - ∫ t in Icc (0 : ℝ) 1, powerCurvature s t * if t ≤ u then (1 : ℝ) else 0 ∂volume ∂volume := by apply integral_congr_ae filter_upwards [ae_restrict_mem measurableSet_Ioc] with u hu exact powerDensity_eq_sub_curvature_integral hs ⟨ha0.trans hu.1.le, hu.2.trans hb1⟩ _ = s / N - ∫ u in Ioc a b, ∫ t in Icc (0 : ℝ) 1, powerCurvature s t * if t ≤ u then (1 : ℝ) else 0 ∂volume ∂volume := by rw [integral_sub (integrable_const _) hinner_int, hconst] _ = s / N - ∫ t in Icc (0 : ℝ) 1, ∫ u in Ioc a b, powerCurvature s t * if t ≤ u then (1 : ℝ) else 0 ∂volume ∂volume := by rw [hswap] _ = s / N - ∫ t in Icc (0 : ℝ) 1, powerCurvature s t * hingeCell N t j ∂volume := by congr 1 apply integral_congr_ae filter_upwards [] with t rw [integral_const_mul, hgeom]
    Causalean.Stat.OrderStatistic.WeightedConcomitant.powerCell_eq_sub_curvature_hinge_integral · Causalean/Stat/OrderStatistic/WeightedConcomitant/PowerL1Core.lean:320
Power­L1­Error 1 core · 6 supporting This module integrates the adjacent-order-statistic hinge error and proves the finite Bernstein L1 approximation for real power weights. ★ power_bernstein_L1

Curvature control of the Bernstein power approximation

This module integrates the adjacent-order-statistic hinge error and proves the finite Bernstein L1 approximation for real power weights.

theorem power_bernstein_L1 reviewed
Causalean.Stat.OrderStatistic.WeightedConcomitant

For a positive sample size and real power at least one, the Bernstein power kernel has L1 error at most 2 sqrt(s/N).

Formal statement
N :
ℕ
hN :
0 < N
s :
ℝ
hs :
1 ≤ s
(∫ u in Icc (0 : ℝ) 1, |bernsteinCell N (powerCell N s) u - powerDensity s u| ∂volume)
≤ 2 * sqrt (s / N)
Proof (Lean source)
theorem power_bernstein_L1 {N : ℕ} (hN : 0 < N) {s : ℝ} (hs : 1 ≤ s) : (∫ u in Icc (0 : ℝ) 1, |bernsteinCell N (powerCell N s) u - powerDensity s u| ∂volume) ≤ 2 * sqrt (s / N) := by by_cases hlarge : (N : ℝ) < s · exact power_bernstein_L1_large hN hlarge · exact power_bernstein_L1_small hN hs (le_of_not_gt hlarge)
Causalean.Stat.OrderStatistic.WeightedConcomitant.power_bernstein_L1 · Causalean/Stat/OrderStatistic/WeightedConcomitant/PowerL1Error.lean:407 · uses bernsteinCell , powerCell , powerDensity
6 supporting declarations (lemmas, instances)
  • power_curvature_hinge_error_integrable theorem — For a power above one, the curvature times the absolute error of the Bernstein hinge approximation is integrable on the unit square. This is the Fubini prerequisite for the power-density bound.
    N :
    ℕ
    s :
    ℝ
    hs :
    1 < s
    Integrable (fun p : ℝ × ℝ => powerCurvature s p.1 * |bernsteinCell N (hingeCell N p.1) p.2 - (if p.1 ≤ p.2 then (1 : ℝ) else 0)|) ((volume.restrict (Icc (0 : ℝ) 1)).prod (volume.restrict (Icc (0 : ℝ) 1)))
    Proof (Lean source)
    theorem power_curvature_hinge_error_integrable {N : ℕ} {s : ℝ} (hs : 1 < s) : Integrable (fun p : ℝ × ℝ => powerCurvature s p.1 * |bernsteinCell N (hingeCell N p.1) p.2 - (if p.1 ≤ p.2 then (1 : ℝ) else 0)|) ((volume.restrict (Icc (0 : ℝ) 1)).prod (volume.restrict (Icc (0 : ℝ) 1))) := by -- Bound the hinge kernel and the step by one; curvature is integrable -- even when 1 < s < 2 and it is singular at the right endpoint. let I : Set ℝ := Icc 0 1 let μ : Measure ℝ := volume.restrict I have hq : Integrable (powerCurvature s) μ := by apply (intervalIntegrable_iff_integrableOn_Icc_of_le (by norm_num : (0 : ℝ) ≤ 1)).mp have hr : IntervalIntegrable (fun x : ℝ => x ^ (s - 2)) volume 0 1 := intervalIntegral.intervalIntegrable_rpow' (by linarith) have hr' : IntervalIntegrable (fun t : ℝ => (1 - t) ^ (s - 2)) volume 0 1 := by convert (hr.comp_sub_left 1).symm using 1 <;> norm_num change IntervalIntegrable (fun t : ℝ => s * (s - 1) * (1 - t) ^ (s - 2)) volume 0 1 exact hr'.const_mul (s * (s - 1)) have hc : Continuous (fun p : ℝ × ℝ => bernsteinCell N (hingeCell N p.1) p.2) := by unfold bernsteinCell hingeCell fun_prop obtain ⟨C, hC⟩ := (isCompact_Icc.prod isCompact_Icc).exists_bound_of_continuousOn (hc.continuousOn : ContinuousOn (fun p : ℝ × ℝ => bernsteinCell N (hingeCell N p.1) p.2) (I ×ˢ I)) have he : AEStronglyMeasurable (fun p : ℝ × ℝ => |bernsteinCell N (hingeCell N p.1) p.2 - (if p.1 ≤ p.2 then (1 : ℝ) else 0)|) (μ.prod μ) := by apply Measurable.aestronglyMeasurable apply Measurable.abs apply Measurable.sub · exact hc.measurable · exact Measurable.ite (measurableSet_le measurable_fst measurable_snd) measurable_const measurable_const have hbound : ∀ᵐ p : ℝ × ℝ ∂μ.prod μ, ‖bernsteinCell N (hingeCell N p.1) p.2 - (if p.1 ≤ p.2 then (1 : ℝ) else 0)‖ ≤ C + 1 := by rw [Measure.prod_restrict] filter_upwards [ae_restrict_mem (measurableSet_Icc.prod measurableSet_Icc)] with p hp calc _ ≤ ‖bernsteinCell N (hingeCell N p.1) p.2‖ + ‖(if p.1 ≤ p.2 then (1 : ℝ) else 0)‖ := norm_sub_le _ _ _ ≤ C + 1 := by apply add_le_add (hC p hp) split_ifs <;> norm_num have hqprod : Integrable (fun p : ℝ × ℝ => powerCurvature s p.1) (μ.prod μ) := hq.comp_fst μ have hbound' : ∀ᵐ p : ℝ × ℝ ∂μ.prod μ, ‖|bernsteinCell N (hingeCell N p.1) p.2 - (if p.1 ≤ p.2 then (1 : ℝ) else 0)|‖ ≤ C + 1 := by simpa only [Real.norm_eq_abs, abs_abs] using hbound have hint := hqprod.mul_bdd he hbound' simpa only [μ, I] using hint
    Causalean.Stat.OrderStatistic.WeightedConcomitant.power_curvature_hinge_error_integrable · Causalean/Stat/OrderStatistic/WeightedConcomitant/PowerL1Error.lean:20
  • power_curvature_hinge_error_integral_le theorem — The L1 norm of the integrated, curvature-weighted hinge error is at most the curvature-weighted integral of its pointwise L1 norms.
    N :
    ℕ
    s :
    ℝ
    hs :
    1 < s
    (∫ u in Icc (0 : ℝ) 1, |∫ t in Icc (0 : ℝ) 1, powerCurvature s t * (bernsteinCell N (hingeCell N t) u - (if t ≤ u then (1 : ℝ) else 0)) ∂volume| ∂volume)
    ≤ ∫ t in Icc (0 : ℝ) 1, powerCurvature s t * (∫ u in Icc (0 : ℝ) 1, |bernsteinCell N (hingeCell N t) u - (if t ≤ u then (1 : ℝ) else 0)| ∂volume) ∂volume
    Proof (Lean source)
    theorem power_curvature_hinge_error_integral_le {N : ℕ} {s : ℝ} (hs : 1 < s) : (∫ u in Icc (0 : ℝ) 1, |∫ t in Icc (0 : ℝ) 1, powerCurvature s t * (bernsteinCell N (hingeCell N t) u - (if t ≤ u then (1 : ℝ) else 0)) ∂volume| ∂volume) ≤ ∫ t in Icc (0 : ℝ) 1, powerCurvature s t * (∫ u in Icc (0 : ℝ) 1, |bernsteinCell N (hingeCell N t) u - (if t ≤ u then (1 : ℝ) else 0)| ∂volume) ∂volume := by -- Apply abs_integral_le_integral_abs for each u and integral_prod_symm -- using power_curvature_hinge_error_integrable. let I : Set ℝ := Icc 0 1 let μ : Measure ℝ := volume.restrict I let F : ℝ × ℝ → ℝ := fun p => powerCurvature s p.1 * (bernsteinCell N (hingeCell N p.1) p.2 - (if p.1 ≤ p.2 then (1 : ℝ) else 0)) let G : ℝ × ℝ → ℝ := fun p => powerCurvature s p.1 * |bernsteinCell N (hingeCell N p.1) p.2 - (if p.1 ≤ p.2 then (1 : ℝ) else 0)| have hG : Integrable G (μ.prod μ) := power_curvature_hinge_error_integrable hs have hFmeas : AEStronglyMeasurable F (μ.prod μ) := by apply Measurable.aestronglyMeasurable dsimp [F, powerCurvature, bernsteinCell, hingeCell] apply mul · fun_prop · apply Measurable.sub · fun_prop · exact Measurable.ite (measurableSet_le measurable_fst measurable_snd) measurable_const measurable_const have hqnonneg : ∀ t ∈ I, 0 ≤ powerCurvature s t := by intro t ht unfold powerCurvature exact mul_nonneg (mul_nonneg (by linarith) (by linarith)) (Real.rpow_nonneg (by have := ht.2; dsimp [I] at ht; linarith) _) have hnorm : ∀ᵐ p : ℝ × ℝ ∂μ.prod μ, ‖F p‖ = G p := by rw [Measure.prod_restrict] filter_upwards [ae_restrict_mem (measurableSet_Icc.prod measurableSet_Icc)] with p hp dsimp [F, G] rw [abs_mul, abs_of_nonneg (hqnonneg p.1 hp.1)] have hF : Integrable F (μ.prod μ) := by apply (integrable_norm_iff hFmeas).1 exact hG.congr (by filter_upwards [hnorm] with p hp; exact hp.symm) have houterF : Integrable (fun u => ∫ t, F (t, u) ∂μ) μ := hF.swap.integral_prod_left have houterG : Integrable (fun u => ∫ t, G (t, u) ∂μ) μ := hG.swap.integral_prod_left have hpoint (u : ℝ) : |∫ t, F (t, u) ∂μ| ≤ ∫ t, G (t, u) ∂μ := by calc _ ≤ ∫ t, |F (t, u)| ∂μ := abs_integral_le_integral_abs _ = ∫ t, G (t, u) ∂μ := by apply integral_congr_ae filter_upwards [ae_restrict_mem measurableSet_Icc] with t ht dsimp [F, G] rw [abs_mul, abs_of_nonneg (hqnonneg t ht)] have hle : (∫ u, |∫ t, F (t, u) ∂μ| ∂μ) ≤ ∫ u, (∫ t, G (t, u) ∂μ) ∂μ := integral_mono houterF.abs houterG hpoint have hswap : (∫ u, (∫ t, G (t, u) ∂μ) ∂μ) = ∫ t, (∫ u, G (t, u) ∂μ) ∂μ := (integral_integral_swap hG).symm calc _ = ∫ u, |∫ t, F (t, u) ∂μ| ∂μ := rfl _ ≤ ∫ u, (∫ t, G (t, u) ∂μ) ∂μ := hle _ = ∫ t, (∫ u, G (t, u) ∂μ) ∂μ := hswap _ = _ := by apply integral_congr_ae filter_upwards [] with t dsimp [G] rw [integral_const_mul]
    Causalean.Stat.OrderStatistic.WeightedConcomitant.power_curvature_hinge_error_integral_le · Causalean/Stat/OrderStatistic/WeightedConcomitant/PowerL1Error.lean:82
  • power_bernstein_L1_le_curvature_error theorem — For a real power above one, the L1 error of its finite Bernstein cell density is bounded by the curvature-weighted adjacent-threshold error.
    N :
    ℕ
    hN :
    0 < N
    s :
    ℝ
    hs :
    1 < s
    (∫ u in Icc (0 : ℝ) 1, |bernsteinCell N (powerCell N s) u - powerDensity s u| ∂volume)
    ≤ ∫ t in Icc (0 : ℝ) 1, powerCurvature s t * sqrt (2 * t / N) ∂volume
    Proof (Lean source)
    theorem power_bernstein_L1_le_curvature_error {N : ℕ} (hN : 0 < N) {s : ℝ} (hs : 1 < s) : (∫ u in Icc (0 : ℝ) 1, |bernsteinCell N (powerCell N s) u - powerDensity s u| ∂volume) ≤ ∫ t in Icc (0 : ℝ) 1, powerCurvature s t * sqrt (2 * t / N) ∂volume := by let I : Set ℝ := Icc 0 1 let μ : Measure ℝ := volume.restrict I have hr : IntervalIntegrable (fun x : ℝ => x ^ (s - 2)) volume 0 1 := intervalIntegral.intervalIntegrable_rpow' (by linarith) have hr' : IntervalIntegrable (fun t : ℝ => (1 - t) ^ (s - 2)) volume 0 1 := by convert (hr.comp_sub_left 1).symm using 1 <;> norm_num have hq : Integrable (powerCurvature s) μ := by apply (intervalIntegrable_iff_integrableOn_Icc_of_le (by norm_num : (0 : ℝ) ≤ 1)).mp change IntervalIntegrable (fun t : ℝ => s * (s - 1) * (1 - t) ^ (s - 2)) volume 0 1 exact hr'.const_mul (s * (s - 1)) have hstep (u : ℝ) : Integrable (fun t => powerCurvature s t * (if t ≤ u then (1 : ℝ) else 0)) μ := by apply hq.mul_bdd (c := 1) · exact (Measurable.ite (measurableSet_le measurable_id measurable_const) measurable_const measurable_const).aestronglyMeasurable · filter_upwards [] with t split_ifs <;> simp have hhinge (u : ℝ) : Integrable (fun t => powerCurvature s t * bernsteinCell N (hingeCell N t) u) μ := by have hc : Continuous (fun t : ℝ => bernsteinCell N (hingeCell N t) u) := by unfold bernsteinCell hingeCell fun_prop obtain ⟨C, hC⟩ := isCompact_Icc.exists_bound_of_continuousOn (hc.continuousOn : ContinuousOn (fun t : ℝ => bernsteinCell N (hingeCell N t) u) I) apply hq.mul_bdd (c := C) · exact hc.aestronglyMeasurable · filter_upwards [ae_restrict_mem measurableSet_Icc] with t ht exact hC t ht have heq (u : ℝ) (hu : u ∈ I) : bernsteinCell N (powerCell N s) u - powerDensity s u = - ∫ t in I, powerCurvature s t * (bernsteinCell N (hingeCell N t) u - (if t ≤ u then (1 : ℝ) else 0)) ∂volume := by rw [bernsteinCell_power_eq_sub_curvature_hinge_integral hN hs u, powerDensity_eq_sub_curvature_integral hs hu] calc _ = -((∫ t in I, powerCurvature s t * bernsteinCell N (hingeCell N t) u ∂volume) - (∫ t in I, powerCurvature s t * (if t ≤ u then (1 : ℝ) else 0) ∂volume)) := by ring _ = _ := by rw [← integral_sub (hhinge u) (hstep u)] congr 1 apply integral_congr_ae filter_upwards [] with t ring calc (∫ u in I, |bernsteinCell N (powerCell N s) u - powerDensity s u| ∂volume) = ∫ u in I, |∫ t in I, powerCurvature s t * (bernsteinCell N (hingeCell N t) u - (if t ≤ u then (1 : ℝ) else 0)) ∂volume| ∂volume := by apply setIntegral_congr_fun measurableSet_Icc intro u hu dsimp rw [heq u hu, abs_neg] _ ≤ ∫ t in I, powerCurvature s t * (∫ u in I, |bernsteinCell N (hingeCell N t) u - (if t ≤ u then (1 : ℝ) else 0)| ∂volume) ∂volume := power_curvature_hinge_error_integral_le hs _ ≤ ∫ t in I, powerCurvature s t * sqrt (2 * t / N) ∂volume := by have hG := power_curvature_hinge_error_integrable (N := N) hs have hleft : Integrable (fun t => powerCurvature s t * (∫ u in I, |bernsteinCell N (hingeCell N t) u - (if t ≤ u then (1 : ℝ) else 0)| ∂volume)) μ := by have hG' := hG.integral_prod_left simp only [integral_const_mul] at hG' exact hG' have hroot : Integrable (fun t => sqrt (2 * t / N)) μ := by apply Continuous.integrableOn_Icc fun_prop have hright : Integrable (fun t => powerCurvature s t * sqrt (2 * t / N)) μ := by apply hq.mul_bdd (c := 2) hroot.aestronglyMeasurable filter_upwards [ae_restrict_mem measurableSet_Icc] with t ht rw [Real.norm_eq_abs, abs_of_nonneg (Real.sqrt_nonneg _)] have hNr : (0 : ℝ) < N := by exact_mod_cast hN have harg : 2 * t / (N : ℝ) ≤ 4 := by apply (div_le_iff₀ hNr).mpr have hN1 : (1 : ℝ) ≤ N := by exact_mod_cast hN nlinarith [ht.2] calc _ ≤ sqrt 4 := Real.sqrt_le_sqrt harg _ = 2 := by norm_num apply integral_mono_ae hleft hright filter_upwards [ae_restrict_mem measurableSet_Icc] with t ht exact mul_le_mul_of_nonneg_left (bernsteinCell_hinge_indicator_L1 hN ht) (by unfold powerCurvature exact mul_nonneg (mul_nonneg (by linarith) (by linarith)) (Real.rpow_nonneg (by linarith [ht.2]) _))
    Causalean.Stat.OrderStatistic.WeightedConcomitant.power_bernstein_L1_le_curvature_error · Causalean/Stat/OrderStatistic/WeightedConcomitant/PowerL1Error.lean:157
  • power_bernstein_L1_one theorem — For a positive sample size, the Bernstein kernel of first-power cells agrees with the constant unit density in L1.
    N :
    ℕ
    hN :
    0 < N
    (∫ u in Icc (0 : ℝ) 1, |bernsteinCell N (powerCell N 1) u - powerDensity 1 u| ∂volume)
    = 0
    Proof (Lean source)
    theorem power_bernstein_L1_one {N : ℕ} (hN : 0 < N) : (∫ u in Icc (0 : ℝ) 1, |bernsteinCell N (powerCell N 1) u - powerDensity 1 u| ∂volume) = 0 := by have hNr : (N : ℝ) ≠ 0 := by exact_mod_cast (Nat.ne_of_gt hN) have hcell (j : Fin N) : powerCell N 1 j = 1 / N := by unfold powerCell simp only [Real.rpow_one] field_simp ring have hbern (u : ℝ) : bernsteinCell N (powerCell N 1) u = 1 := by simp_rw [bernsteinCell, hcell] have hsum : (∑ j : Fin N, (choose (N - 1) (j : ℕ) : ℝ) * u ^ (j : ℕ) * (1 - u) ^ (N - 1 - (j : ℕ))) = 1 := by have hpow := add_pow u (1 - u) (N - 1) rw [show N - 1 + 1 = N by omega, ← Fin.sum_univ_eq_sum_range] at hpow convert hpow.symm using 1 · apply Finset.sum_congr rfl intro j hj ring · ring calc (N : ℝ) * ∑ j : Fin N, (1 / N) * (choose (N - 1) (j : ℕ) : ℝ) * u ^ (j : ℕ) * (1 - u) ^ (N - 1 - (j : ℕ)) = N * ((1 / N) * ∑ j : Fin N, (choose (N - 1) (j : ℕ) : ℝ) * u ^ (j : ℕ) * (1 - u) ^ (N - 1 - (j : ℕ))) := by congr 1 rw [Finset.mul_sum] apply Finset.sum_congr rfl intro j hj ring _ = N * (1 / N) * ∑ j : Fin N, (choose (N - 1) (j : ℕ) : ℝ) * u ^ (j : ℕ) * (1 - u) ^ (N - 1 - (j : ℕ)) := by ring _ = 1 := by rw [hsum]; field_simp have hdens (u : ℝ) (hu : u ∈ Icc (0 : ℝ) 1) : powerDensity 1 u = 1 := by simp [powerDensity, Real.rpow_zero] have hzero : ∀ u ∈ Icc (0 : ℝ) 1, |bernsteinCell N (powerCell N 1) u - powerDensity 1 u| = 0 := by intro u hu rw [hbern u, hdens u hu] norm_num rw [setIntegral_congr_fun measurableSet_Icc hzero] simp
    Causalean.Stat.OrderStatistic.WeightedConcomitant.power_bernstein_L1_one · Causalean/Stat/OrderStatistic/WeightedConcomitant/PowerL1Error.lean:260
  • power_bernstein_L1_large theorem — For a positive sample size and power greater than the sample size, the unit-density bound gives the claimed L1 estimate.
    N :
    ℕ
    hN :
    0 < N
    s :
    ℝ
    hs :
    (N : ℝ) < s
    (∫ u in Icc (0 : ℝ) 1, |bernsteinCell N (powerCell N s) u - powerDensity s u| ∂volume)
    ≤ 2 * sqrt (s / N)
    Proof (Lean source)
    theorem power_bernstein_L1_large {N : ℕ} (hN : 0 < N) {s : ℝ} (hs : (N : ℝ) < s) : (∫ u in Icc (0 : ℝ) 1, |bernsteinCell N (powerCell N s) u - powerDensity s u| ∂volume) ≤ 2 * sqrt (s / N) := by have hNr : (0 : ℝ) < N := by exact_mod_cast hN have hs1 : 1 ≤ s := by have : (1 : ℝ) ≤ N := by exact_mod_cast hN linarith have hb : Continuous (bernsteinCell N (powerCell N s)) := by unfold bernsteinCell fun_prop have hd : Continuous (powerDensity s) := by unfold powerDensity exact continuous_const.mul ((Real.continuous_rpow_const (by linarith : 0 ≤ s - 1)).comp (continuous_const.sub continuous_id)) have hib : IntegrableOn (bernsteinCell N (powerCell N s)) (Icc (0 : ℝ) 1) volume := hb.integrableOn_Icc have hid : IntegrableOn (powerDensity s) (Icc (0 : ℝ) 1) volume := hd.integrableOn_Icc have hiabs : IntegrableOn (fun u => |bernsteinCell N (powerCell N s) u - powerDensity s u|) (Icc (0 : ℝ) 1) volume := by apply Continuous.integrableOn_Icc exact (hb.sub hd).abs have hiadd : IntegrableOn (fun u => bernsteinCell N (powerCell N s) u + powerDensity s u) (Icc (0 : ℝ) 1) volume := hib.add hid have hbound : (∫ u in Icc (0 : ℝ) 1, |bernsteinCell N (powerCell N s) u - powerDensity s u| ∂volume) ≤ 2 := by calc (∫ u in Icc (0 : ℝ) 1, |bernsteinCell N (powerCell N s) u - powerDensity s u| ∂volume) ≤ ∫ u in Icc (0 : ℝ) 1, (bernsteinCell N (powerCell N s) u + powerDensity s u) ∂volume := by apply setIntegral_mono_on hiabs hiadd measurableSet_Icc intro u hu have hbu := bernsteinCell_nonneg (N := N) (a := powerCell N s) (fun j => powerCell_nonneg hs1 j) hu have hdu : 0 ≤ powerDensity s u := by unfold powerDensity exact mul_nonneg (by linarith) (Real.rpow_nonneg (by linarith [hu.2]) _) rw [abs_le] constructor <;> linarith _ = 2 := by rw [integral_add hib hid, integral_bernsteinCell hN (powerCell N s) (sum_powerCell hN hs1), integral_powerDensity hs1] norm_num have hratio : 1 ≤ s / N := (le_div_iff₀ hNr).2 (by nlinarith) have hsqrt : 1 ≤ sqrt (s / N) := by simpa using Real.sqrt_le_sqrt hratio nlinarith
    Causalean.Stat.OrderStatistic.WeightedConcomitant.power_bernstein_L1_large · Causalean/Stat/OrderStatistic/WeightedConcomitant/PowerL1Error.lean:307
  • power_bernstein_L1_small theorem — For a positive sample size and power between one and the sample size, the adjacent-order-statistic coupling gives the claimed L1 estimate.
    N :
    ℕ
    hN :
    0 < N
    s :
    ℝ
    hs :
    1 ≤ s
    hsmall :
    s ≤ N
    (∫ u in Icc (0 : ℝ) 1, |bernsteinCell N (powerCell N s) u - powerDensity s u| ∂volume)
    ≤ 2 * sqrt (s / N)
    Proof (Lean source)
    theorem power_bernstein_L1_small {N : ℕ} (hN : 0 < N) {s : ℝ} (hs : 1 ≤ s) (hsmall : s ≤ N) : (∫ u in Icc (0 : ℝ) 1, |bernsteinCell N (powerCell N s) u - powerDensity s u| ∂volume) ≤ 2 * sqrt (s / N) := by rcases eq_or_lt_of_le hs with rfl | hs' · rw [power_bernstein_L1_one hN] positivity · have hNr : (0 : ℝ) < N := by exact_mod_cast hN calc (∫ u in Icc (0 : ℝ) 1, |bernsteinCell N (powerCell N s) u - powerDensity s u| ∂volume) ≤ ∫ t in Icc (0 : ℝ) 1, powerCurvature s t * sqrt (2 * t / N) ∂volume := power_bernstein_L1_le_curvature_error hN hs' _ = sqrt (2 / N) * (∫ t in Icc (0 : ℝ) 1, powerCurvature s t * sqrt t ∂volume) := by rw [← integral_const_mul] apply integral_congr_ae filter_upwards [] with t rw [show 2 * t / (N : ℝ) = (2 / N) * t by ring, Real.sqrt_mul (by positivity : 0 ≤ (2 : ℝ) / N)] ring _ ≤ sqrt (2 / N) * sqrt s := mul_le_mul_of_nonneg_left (integral_powerCurvature_mul_sqrt_le hs') (Real.sqrt_nonneg _) _ ≤ 2 * sqrt (s / N) := by calc sqrt (2 / N) * sqrt s = sqrt (2 * s / N) := by rw [show 2 * s / (N : ℝ) = (2 / N) * s by ring, Real.sqrt_mul (by positivity : 0 ≤ (2 : ℝ) / N)] _ ≤ sqrt (4 * s / N) := by apply Real.sqrt_le_sqrt apply (div_le_div_iff_of_pos_right hNr).mpr nlinarith _ = 2 * sqrt (s / N) := by rw [show 4 * s / (N : ℝ) = 4 * (s / N) by ring, Real.sqrt_mul (by norm_num : (0 : ℝ) ≤ 4)] norm_num
    Causalean.Stat.OrderStatistic.WeightedConcomitant.power_bernstein_L1_small · Causalean/Stat/OrderStatistic/WeightedConcomitant/PowerL1Error.lean:364
Replacement­Law 1 core · 5 supporting Replacing one coordinate of an iid tuple by an independent observation preserves its product distribution. ★ integral_coordinateVariance_eq_half_replacement_sq

Independent replacement under a finite product law

Replacing one coordinate of an iid tuple by an independent observation preserves its product distribution. This measure statement isolates the exchangeability step used by rank-statistic variance bounds.

theorem integral_coordinateVariance_eq_half_replacement_sq reviewed
Causalean.Stat.OrderStatistic.WeightedConcomitant

An iid sampling law, selected coordinate, and square-integrable statistic give an expected replacement variance equal to half its expected squared independent replacement change.

Formal statement
N :
ℕ
α :
i :
Fin N
F :
(Fin N → α) → ℝ
hF :
MemLp F 2 (Measure.pi (fun _ : Fin N => μ))
(∫ x, variance (fun y => F (coordinateReplace i x y)) μ ∂Measure.pi (fun _ : Fin N => μ))
= (1 / 2 : ℝ) * ∫ x, ∫ y, (F x - F (coordinateReplace i x y)) ^ 2 ∂μ ∂Measure.pi (fun _ : Fin N => μ)
Proof (Lean source)
theorem integral_coordinateVariance_eq_half_replacement_sq {N : ℕ} {α : Type*} [MeasurableSpace α] (μ : Measure α) [IsProbabilityMeasure μ] (i : Fin N) (F : (Fin N → α) → ℝ) (hF : MemLp F 2 (Measure.pi (fun _ : Fin N => μ))) : (∫ x, variance (fun y => F (coordinateReplace i x y)) μ ∂Measure.pi (fun _ : Fin N => μ)) = (1 / 2 : ℝ) * ∫ x, ∫ y, (F x - F (coordinateReplace i x y)) ^ 2 ∂μ ∂Measure.pi (fun _ : Fin N => μ) := by rw [integral_coordinateVariance_eq_half_double_replacement_sq μ i F hF, integral_double_replacement_sq_eq_replacement_sq μ i F hF]
Causalean.Stat.OrderStatistic.WeightedConcomitant.integral_coordinateVariance_eq_half_replacement_sq · Causalean/Stat/OrderStatistic/WeightedConcomitant/ReplacementLaw.lean:199 · uses coordinateReplace
5 supporting declarations (lemmas, instances)
  • measurable_coordinateReplace_pair theorem — For a finite tuple and an independent replacement value, updating one coordinate is a measurable map of the tuple and the value.
    N :
    ℕ
    α :
    i :
    Fin N
    Measurable (fun p : (Fin N → α) × α => coordinateReplace i p.1 p.2)
    Proof (Lean source)
    @[fun_prop] theorem measurable_coordinateReplace_pair {N : ℕ} {α : Type*} [MeasurableSpace α] (i : Fin N) : Measurable (fun p : (Fin N → α) × α => coordinateReplace i p.1 p.2) := by classical apply measurable_pi_iff.mpr intro j by_cases h : j = i · subst j simpa [coordinateReplace] using (measurable_snd : Measurable (fun p : (Fin N → α) × α => p.2)) · have hm : Measurable (fun p : (Fin N → α) × α => p.1 j) := by fun_prop simpa [coordinateReplace, h] using hm
    Causalean.Stat.OrderStatistic.WeightedConcomitant.measurable_coordinateReplace_pair · Causalean/Stat/OrderStatistic/WeightedConcomitant/ReplacementLaw.lean:22
  • coordinateReplace_map_prod theorem — If a finite tuple has iid law μ and y is an independent draw from μ, the tuple obtained by replacing coordinate i with y has the original iid law.
    N :
    ℕ
    α :
    i :
    Fin N
    Measure.map (fun p : (Fin N → α) × α => coordinateReplace i p.1 p.2) ((Measure.pi (fun _ : Fin N => μ)).prod μ)
    = Measure.pi (fun _ : Fin N => μ)
    Proof (Lean source)
    theorem coordinateReplace_map_prod {N : ℕ} {α : Type*} [MeasurableSpace α] (μ : Measure α) [IsProbabilityMeasure μ] (i : Fin N) : Measure.map (fun p : (Fin N → α) × α => coordinateReplace i p.1 p.2) ((Measure.pi (fun _ : Fin N => μ)).prod μ) = Measure.pi (fun _ : Fin N => μ) := by classical apply (Measure.pi_eq (μ := fun _ : Fin N => μ) (fun s hs => ?_)).symm let t : Fin N → Set α := fun j => if j = i then Set.univ else s j have hpre : (fun p : (Fin N → α) × α => coordinateReplace i p.1 p.2) ⁻¹' (Set.univ.pi s) = (Set.univ.pi t) ×ˢ s i := by ext p simp only [Set.mem_preimage, Set.mem_pi, Set.mem_univ, forall_true_left, Set.mem_prod, t, coordinateReplace] constructor · intro hp constructor · intro j by_cases h : j = i · simp [h] · simpa [h] using hp j · simpa using hp i · rintro ⟨hp, hi⟩ j by_cases h : j = i · simpa [h] using hi · simpa [h] using hp j rw [Measure.map_apply (measurable_coordinateReplace_pair i) (MeasurableSet.univ_pi hs), hpre, Measure.prod_prod, Measure.pi_pi] dsimp [t] rw [show (∏ j : Fin N, μ (if j = i then Set.univ else s j)) = ∏ j ∈ Finset.univ.erase i, μ (s j) by rw [← Finset.prod_erase_mul (s := univ) (f := fun j => μ (if j = i then Set.univ else s j)) (a := i) (by simp)] simp only [if_true, measure_univ, mul_one] apply Finset.prod_congr rfl intro j hj have hji : j ≠ i := Finset.ne_of_mem_erase hj simp [hji]] exact Finset.prod_erase_mul univ (fun j : Fin N => μ (s j)) (by simp)
    Causalean.Stat.OrderStatistic.WeightedConcomitant.coordinateReplace_map_prod · Causalean/Stat/OrderStatistic/WeightedConcomitant/ReplacementLaw.lean:38
  • integral_coordinateReplace_prod theorem — Integrating an integrable function of an iid tuple is unchanged when one coordinate is replaced by an independent draw from the same law.
    N :
    ℕ
    α :
    i :
    Fin N
    f :
    (Fin N → α) → ℝ
    hf :
    Integrable f (Measure.pi (fun _ : Fin N => μ))
    (∫ p : (Fin N → α) × α, f (coordinateReplace i p.1 p.2) ∂(Measure.pi (fun _ : Fin N => μ)).prod μ)
    = ∫ x, f x ∂Measure.pi (fun _ : Fin N => μ)
    Proof (Lean source)
    theorem integral_coordinateReplace_prod {N : ℕ} {α : Type*} [MeasurableSpace α] (μ : Measure α) [IsProbabilityMeasure μ] (i : Fin N) (f : (Fin N → α) → ℝ) (hf : Integrable f (Measure.pi (fun _ : Fin N => μ))) : (∫ p : (Fin N → α) × α, f (coordinateReplace i p.1 p.2) ∂(Measure.pi (fun _ : Fin N => μ)).prod μ) = ∫ x, f x ∂Measure.pi (fun _ : Fin N => μ) := by have hfm : AEStronglyMeasurable f (Measure.map (fun p : (Fin N → α) × α => coordinateReplace i p.1 p.2) ((Measure.pi (fun _ : Fin N => μ)).prod μ)) := by rw [coordinateReplace_map_prod μ i] exact hf.aestronglyMeasurable rw [← integral_map (measurable_coordinateReplace_pair i).aemeasurable hfm, coordinateReplace_map_prod μ i]
    Causalean.Stat.OrderStatistic.WeightedConcomitant.integral_coordinateReplace_prod · Causalean/Stat/OrderStatistic/WeightedConcomitant/ReplacementLaw.lean:83
  • integral_coordinateVariance_eq_half_double_replacement_sq theorem — For a square-integrable statistic of an iid finite tuple, the expected conditional variance at one coordinate is half the expected squared difference between two independent replacements of that coordinate.
    N :
    ℕ
    α :
    i :
    Fin N
    F :
    (Fin N → α) → ℝ
    hF :
    MemLp F 2 (Measure.pi (fun _ : Fin N => μ))
    (∫ x, variance (fun y => F (coordinateReplace i x y)) μ ∂Measure.pi (fun _ : Fin N => μ))
    = (1 / 2 : ℝ) * ∫ x, ∫ y, ∫ z, (F (coordinateReplace i x y) - F (coordinateReplace i x z)) ^ 2 ∂μ ∂μ ∂Measure.pi (fun _ : Fin N => μ)
    Proof (Lean source)
    theorem integral_coordinateVariance_eq_half_double_replacement_sq {N : ℕ} {α : Type*} [MeasurableSpace α] (μ : Measure α) [IsProbabilityMeasure μ] (i : Fin N) (F : (Fin N → α) → ℝ) (hF : MemLp F 2 (Measure.pi (fun _ : Fin N => μ))) : (∫ x, variance (fun y => F (coordinateReplace i x y)) μ ∂Measure.pi (fun _ : Fin N => μ)) = (1 / 2 : ℝ) * ∫ x, ∫ y, ∫ z, (F (coordinateReplace i x y) - F (coordinateReplace i x z)) ^ 2 ∂μ ∂μ ∂Measure.pi (fun _ : Fin N => μ) := by -- Derive MemLp of the replacement section for almost every x from the -- product L² hypothesis. Apply variance_eq_half_integral_prod_sq_sub -- on those sections, then use Fubini for the triple square integral. let ν : Measure (Fin N → α) := Measure.pi (fun _ => μ) let H : (Fin N → α) × α → ℝ := fun p => F (coordinateReplace i p.1 p.2) have hmp : MeasurePreserving (fun p : (Fin N → α) × α => coordinateReplace i p.1 p.2) (ν.prod μ) ν := by refine ⟨measurable_coordinateReplace_pair i, ?_⟩ exact coordinateReplace_map_prod μ i have hH : MemLp H 2 (ν.prod μ) := hF.comp_measurePreserving hmp have hslices : ∀ᵐ x ∂ν, MemLp (fun y => H (x, y)) 2 μ := by filter_upwards [hH.aestronglyMeasurable.prodMk_left, hH.integrable_sq.prod_right_ae] with x hxm hxi exact (memLp_two_iff_integrable_sq hxm).2 hxi change (∫ x, variance (fun y => H (x, y)) μ ∂ν) = (1 / 2 : ℝ) * ∫ x, ∫ y, ∫ z, (H (x, y) - H (x, z)) ^ 2 ∂μ ∂μ ∂ν rw [← integral_const_mul] apply integral_congr_ae filter_upwards [hslices] with x hx rw [variance_eq_half_integral_prod_sq_sub μ (fun y => H (x, y)) hx] congr 1 have hpair : Integrable (fun p : α × α => (H (x, p.1) - H (x, p.2)) ^ 2) (μ.prod μ) := ((hx.comp_fst μ).sub (hx.comp_snd μ)).integrable_sq exact integral_prod _ hpair
    Causalean.Stat.OrderStatistic.WeightedConcomitant.integral_coordinateVariance_eq_half_double_replacement_sq · Causalean/Stat/OrderStatistic/WeightedConcomitant/ReplacementLaw.lean:100
  • integral_double_replacement_sq_eq_replacement_sq theorem — For a square-integrable statistic of an iid finite tuple, averaging the squared difference of two independent coordinate replacements equals averaging the squared difference between the original tuple and one replacement.
    N :
    ℕ
    α :
    i :
    Fin N
    F :
    (Fin N → α) → ℝ
    hF :
    MemLp F 2 (Measure.pi (fun _ : Fin N => μ))
    (∫ x, ∫ y, ∫ z, (F (coordinateReplace i x y) - F (coordinateReplace i x z)) ^ 2 ∂μ ∂μ ∂Measure.pi (fun _ : Fin N => μ))
    = ∫ x, ∫ y, (F x - F (coordinateReplace i x y)) ^ 2 ∂μ ∂Measure.pi (fun _ : Fin N => μ)
    Proof (Lean source)
    theorem integral_double_replacement_sq_eq_replacement_sq {N : ℕ} {α : Type*} [MeasurableSpace α] (μ : Measure α) [IsProbabilityMeasure μ] (i : Fin N) (F : (Fin N → α) → ℝ) (hF : MemLp F 2 (Measure.pi (fun _ : Fin N => μ))) : (∫ x, ∫ y, ∫ z, (F (coordinateReplace i x y) - F (coordinateReplace i x z)) ^ 2 ∂μ ∂μ ∂Measure.pi (fun _ : Fin N => μ)) = ∫ x, ∫ y, (F x - F (coordinateReplace i x y)) ^ 2 ∂μ ∂Measure.pi (fun _ : Fin N => μ) := by -- Replacing the original tuple with the independent draw preserves its law. -- Lift that measure-preserving map across the other independent draw, then -- apply Fubini and collapse the two updates at the same coordinate. let ν : Measure (Fin N → α) := Measure.pi (fun _ => μ) let R : (Fin N → α) × α → (Fin N → α) := fun p => coordinateReplace i p.1 p.2 let G : (Fin N → α) × α → ℝ := fun p => (F p.1 - F (coordinateReplace i p.1 p.2)) ^ 2 have hR : MeasurePreserving R (ν.prod μ) ν := by refine ⟨measurable_coordinateReplace_pair i, ?_⟩ exact coordinateReplace_map_prod μ i have hFR : MemLp (fun p : (Fin N → α) × α => F (R p)) 2 (ν.prod μ) := hF.comp_measurePreserving hR have hG : Integrable G (ν.prod μ) := by exact ((hF.comp_fst μ).sub hFR).integrable_sq have hRR : MeasurePreserving (map R id) ((ν.prod μ).prod μ) (ν.prod μ) := hR.prod (MeasurePreserving.id μ) have hGcomp : Integrable (fun p : ((Fin N → α) × α) × α => G (R p.1, p.2)) ((ν.prod μ).prod μ) := by exact hRR.integrable_comp_of_integrable hG have hmap : (∫ p : ((Fin N → α) × α) × α, G (R p.1, p.2) ∂((ν.prod μ).prod μ)) = ∫ q, G q ∂(ν.prod μ) := by have hm : AEStronglyMeasurable G (Measure.map (map R id) ((ν.prod μ).prod μ)) := by rw [hRR.map_eq] exact hG.aestronglyMeasurable change (∫ p : ((Fin N → α) × α) × α, G ((map R id) p) ∂((ν.prod μ).prod μ)) = ∫ q, G q ∂(ν.prod μ) rw [← integral_map hRR.measurable.aemeasurable hm, hRR.map_eq] have hiter : (∫ x, ∫ z, ∫ y, G (R (x, z), y) ∂μ ∂μ ∂ν) = ∫ x, ∫ y, G (x, y) ∂μ ∂ν := by calc _ = ∫ p : (Fin N → α) × α, ∫ y, G (R p, y) ∂μ ∂(ν.prod μ) := by exact (integral_prod _ hGcomp.integral_prod_left).symm _ = ∫ p : ((Fin N → α) × α) × α, G (R p.1, p.2) ∂((ν.prod μ).prod μ) := by exact (integral_prod _ hGcomp).symm _ = ∫ q, G q ∂(ν.prod μ) := hmap _ = ∫ x, ∫ y, G (x, y) ∂μ ∂ν := integral_prod _ hG simpa only [G, R, coordinateReplace, Function.update_idem] using hiter
    Causalean.Stat.OrderStatistic.WeightedConcomitant.integral_double_replacement_sq_eq_replacement_sq · Causalean/Stat/OrderStatistic/WeightedConcomitant/ReplacementLaw.lean:141
Replacement­Variance 1 core · 7 supporting This module applies independent coordinate replacement to bound the variance of a bounded rank-weighted concomitant by its squared cell weights. ★ variance_rankConcomitant_le_twice_sum_sq

Tensorized variance of rank-weighted concomitants

This module applies independent coordinate replacement to bound the variance of a bounded rank-weighted concomitant by its squared cell weights.

theorem variance_rankConcomitant_le_twice_sum_sq reviewed
Causalean.Stat.OrderStatistic.WeightedConcomitant

For an iid marked law with continuous sorting-coordinate CDF and unit-bounded marks, and cell weights that are nonnegative and antitone, the concomitant variance is at most twice the squared-weight sum.

Formal statement
N :
ℕ
μ :
hcont :
Continuous (fun t => cdf (μ.map fst) t)
hmark :
∀ᵐ p ∂μ, p.2 ∈ Icc (0 : ℝ) 1
a :
Fin N → ℝ
ha :
∀ j, 0 ≤ a j
hmono :
variance (rankConcomitant a) (Measure.pi (fun _ : Fin N => μ))
≤ 2 * ∑ j : Fin N, (a j) ^ 2
Proof (Lean source)
theorem variance_rankConcomitant_le_twice_sum_sq {N : ℕ} (μ : Measure (ℝ × ℝ)) [IsProbabilityMeasure μ] (hcont : Continuous (fun t => cdf (μ.map fst) t)) (hmark : ∀ᵐ p ∂μ, p.2 ∈ Icc (0 : ℝ) 1) (a : Fin N → ℝ) (ha : ∀ j, 0 ≤ a j) (hmono : Antitone a) : variance (rankConcomitant a) (Measure.pi (fun _ : Fin N => μ)) ≤ 2 * ∑ j : Fin N, (a j) ^ 2 := by classical have hT := variance_pi_le_sum_integral_coordinateVariance (fun _ : Fin N => μ) (rankConcomitant a) (rankConcomitant_memLp_two μ hmark a) by_cases hN : 0 < N · calc variance (rankConcomitant a) (Measure.pi (fun _ : Fin N => μ)) ≤ ∑ i : Fin N, ∫ x, variance (fun y => rankConcomitant a (coordinateReplace i x y)) μ ∂Measure.pi (fun _ : Fin N => μ) := hT _ ≤ ∑ i : Fin N, 2 * ∫ x, (a (rankPosition x i)) ^ 2 ∂Measure.pi (fun _ : Fin N => μ) := by apply Finset.sum_le_sum intro i _ exact integral_coordinateVariance_rankConcomitant_le μ hcont hmark a ha hmono i _ = 2 * ∑ j : Fin N, (a j) ^ 2 := by simp_rw [integral_rankPosition_weight_sq hN μ hcont a] simp only [Finset.sum_const, Finset.card_fin, nsmul_eq_mul] have hN' : (N : ℝ) ≠ 0 := by exact_mod_cast (Nat.ne_of_gt hN) field_simp · have h0 : N = 0 := Nat.eq_zero_of_not_pos hN subst N simpa using hT
Causalean.Stat.OrderStatistic.WeightedConcomitant.variance_rankConcomitant_le_twice_sum_sq · Causalean/Stat/OrderStatistic/WeightedConcomitant/ReplacementVariance.lean:311 · uses rankConcomitant
7 supporting declarations (lemmas, instances)
Uniform­Order­CDF 1 core · 2 supporting The counting identity and binomial-tail law needed to identify an adjacent order-statistic mixture with a Bernstein hinge kernel. ★ uniform_sorted_cdf_eq_binomial_tail

Finite uniform order-statistic CDF

The counting identity and binomial-tail law needed to identify an adjacent order-statistic mixture with a Bernstein hinge kernel.

theorem uniform_sorted_cdf_eq_binomial_tail reviewed
Causalean.Stat.OrderStatistic.WeightedConcomitant

A sorted position and unit-interval threshold give the upper-binomial-tail formula for its iid uniform CDF.

Formal statement
n :
ℕ
r :
Fin n
u :
ℝ
hu :
u ∈ Icc (0 : ℝ) 1
((iidSample uniform01 n).map (fun x => sortedSample n x r)) (Iic u)
= ofReal (∑ k ∈ Icc (r.val + 1) n, (Nat.choose n k : ℝ) * u ^ k * (1 - u) ^ (n - k))
Proof (Lean source)
theorem uniform_sorted_cdf_eq_binomial_tail {n : ℕ} (r : Fin n) {u : ℝ} (hu : u ∈ Icc (0 : ℝ) 1) : ((iidSample uniform01 n).map (fun x => sortedSample n x r)) (Iic u) = ofReal (∑ k ∈ Icc (r.val + 1) n, (Nat.choose n k : ℝ) * u ^ k * (1 - u) ^ (n - k)) := by -- Use `sortedSample_le_iff_count_le`, partition by the finite count, -- and sum `uniform_count_le_mass` over the upper tail. Mathlib's -- `MeasureTheory.sum_measure_preimage_singleton` gives the finite -- partition directly for the count function and `Icc (r.val+1) n`. -- Its measurability follows by a finite sum of indicators of the -- measurable coordinate events `{x | x i ≤ u}`. let count : (Fin n → ℝ) → ℕ := fun x => ((Finset.univ : Finset (Fin n)).filter (fun i => x i ≤ u)).card have hcount : Measurable count := by have hsum : Measurable (fun x : Fin n → ℝ => ∑ i : Fin n, if x i ≤ u then (1 : ℕ) else 0) := by apply Finset.measurable_sum intro i hi exact Measurable.ite ((measurable_pi_apply i) measurableSet_Iic) measurable_const measurable_const simpa only [count, Finset.card_filter] using hsum have hsorted : Measurable (fun x : Fin n → ℝ => sortedSample n x r) := by apply measurable_of_Iic intro t have ht : (fun x : Fin n → ℝ => sortedSample n x r) ⁻¹' Iic t = {x | r.val + 1 ≤ ((Finset.univ : Finset (Fin n)).filter (fun i => x i ≤ t)).card} := by ext x exact sortedSample_le_iff_count_le x r t rw [ht] have hcount_t : Measurable (fun x : Fin n → ℝ => ((Finset.univ : Finset (Fin n)).filter (fun i => x i ≤ t)).card) := by have hsum : Measurable (fun x : Fin n → ℝ => ∑ i : Fin n, if x i ≤ t then (1 : ℕ) else 0) := by apply Finset.measurable_sum intro i hi exact Measurable.ite ((measurable_pi_apply i) measurableSet_Iic) measurable_const measurable_const simpa only [Finset.card_filter] using hsum exact measurableSet_le measurable_const hcount_t have hpre : (fun x : Fin n → ℝ => sortedSample n x r) ⁻¹' Iic u = count ⁻¹' (Icc (r.val + 1) n : Set ℕ) := by ext x simp only [Set.mem_preimage, Set.mem_Iic, Finset.mem_coe, Finset.mem_Icc] constructor · intro hx exact ⟨(sortedSample_le_iff_count_le x r u).mp hx, by simpa only [count, Finset.card_univ, Fintype.card_fin] using Finset.card_le_card (filter_subset (fun i => x i ≤ u) Finset.univ)⟩ · intro hx exact (sortedSample_le_iff_count_le x r u).mpr hx.1 rw [Measure.map_apply hsorted measurableSet_Iic, hpre] rw [← MeasureTheory.sum_measure_preimage_singleton (μ := iidSample uniform01 n) (Icc (r.val + 1) n) (fun k hk => hcount (measurableSet_singleton k))] calc ∑ k ∈ Icc (r.val + 1) n, iidSample uniform01 n (count ⁻¹' {k}) = ∑ k ∈ Icc (r.val + 1) n, ofReal ((Nat.choose n k : ℝ) * u ^ k * (1 - u) ^ (n - k)) := by apply Finset.sum_congr rfl intro k hk exact uniform_count_le_mass n k hu _ = _ := by rw [ENNReal.ofReal_sum_of_nonneg] intro k hk have hu0 : 0 ≤ u := hu.1 have hu1 : 0 ≤ 1 - u := sub_nonneg.mpr hu.2 positivity
Causalean.Stat.OrderStatistic.WeightedConcomitant.uniform_sorted_cdf_eq_binomial_tail · Causalean/Stat/OrderStatistic/WeightedConcomitant/UniformOrderCDF.lean:79 · uses iidSample , sortedSample , uniform01
2 supporting declarations (lemmas, instances)
  • sortedSample_le_iff_count_le theorem — The rth sorted coordinate is at most a threshold exactly when at least r+1 coordinates of the original finite tuple are at most that threshold.
    n :
    ℕ
    x :
    Fin n → ℝ
    r :
    Fin n
    u :
    ℝ
    ≤ u ↔ r.val + 1 ≤ ((Finset.univ : Finset (Fin n)).filter (fun i => x i ≤ u)).card
    Proof (Lean source)
    theorem sortedSample_le_iff_count_le {n : ℕ} (x : Fin n → ℝ) (r : Fin n) (u : ℝ) : sortedSample n x r ≤ u ↔ r.val + 1 ≤ ((Finset.univ : Finset (Fin n)).filter (fun i => x i ≤ u)).card := by -- Sorting is a permutation. In a monotone tuple, the initial segment below -- `u` contains position `r` iff its cardinality is at least `r+1`. let σ := Tuple.sort x have hcard : ((Finset.univ : Finset (Fin n)).filter (fun i => (x ∘ σ) i ≤ u)).card = ((Finset.univ : Finset (Fin n)).filter (fun i => x i ≤ u)).card := by apply Finset.card_equiv σ intro i simp [Function.comp_apply] have h := Tuple.lt_card_le_iff_apply_le_of_monotone (f := x ∘ σ) (a := u) (j := r) (Tuple.monotone_sort x) simpa only [sortedSample, σ, hcard, Fin.val_fin_lt, Nat.lt_iff_add_one_le] using h.symm
    Causalean.Stat.OrderStatistic.WeightedConcomitant.sortedSample_le_iff_count_le · Causalean/Stat/OrderStatistic/WeightedConcomitant/UniformOrderCDF.lean:20
  • uniform_count_le_mass theorem — In an iid sample of n unit uniforms, the number of coordinates at most u has the binomial mass with parameters n and u.
    n k :
    ℕ
    u :
    ℝ
    hu :
    u ∈ Icc (0 : ℝ) 1
    iidSample uniform01 n {x | ((Finset.univ : Finset (Fin n)).filter (fun i => x i ≤ u)).card = k}
    = ofReal ((Nat.choose n k : ℝ) * u ^ k * (1 - u) ^ (n - k))
    Proof (Lean source)
    theorem uniform_count_le_mass (n k : ℕ) {u : ℝ} (hu : u ∈ Icc (0 : ℝ) 1) : iidSample uniform01 n {x | ((Finset.univ : Finset (Fin n)).filter (fun i => x i ≤ u)).card = k} = ofReal ((Nat.choose n k : ℝ) * u ^ k * (1 - u) ^ (n - k)) := by -- `uniform_subset_lt_count_mass` proves the strict-threshold version. -- Each coordinate equals the fixed threshold only on a null set. haveI : IsProbabilityMeasure uniform01 := ⟨by simp [uniform01]⟩ have hsingle : uniform01 ({u} : Set ℝ) = 0 := by simp [uniform01] have hcoord (i : Fin n) : ∀ᵐ x ∂iidSample uniform01 n, x i ≠ u := by have hp := MeasureTheory.measurePreserving_eval (fun _ : Fin n => uniform01) i have hs : iidSample uniform01 n {x | x i = u} = 0 := by have hpre : (fun x : Fin n → ℝ => x i) ⁻¹' ({u} : Set ℝ) = {x | x i = u} := by ext x; simp calc iidSample uniform01 n {x | x i = u} = uniform01 ({u} : Set ℝ) := by rw [← hpre] exact hp.measure_preimage (measurableSet_singleton u).nullMeasurableSet _ = 0 := hsingle exact (ae_iff).2 (by simpa only [not_not] using hs) have hno : ∀ᵐ x ∂iidSample uniform01 n, ∀ i : Fin n, x i ≠ u := by simpa only [Filter.eventually_all] using hcoord have heq : {x : Fin n → ℝ | ((Finset.univ : Finset (Fin n)).filter (fun i => x i ≤ u)).card = k} =ᵐ[iidSample uniform01 n] {x : Fin n → ℝ | ((Finset.univ : Finset (Fin n)).filter (fun i => x i < u)).card = k} := by filter_upwards [hno] with x hx have hf : (Finset.univ : Finset (Fin n)).filter (fun i => x i ≤ u) = (Finset.univ : Finset (Fin n)).filter (fun i => x i < u) := by ext i simp [lt_iff_le_and_ne, hx i] change (((Finset.univ : Finset (Fin n)).filter (fun i => x i ≤ u)).card = k) = (((Finset.univ : Finset (Fin n)).filter (fun i => x i < u)).card = k) rw [hf] rw [measure_congr heq] simpa using uniform_subset_lt_count_mass (Finset.univ : Finset (Fin n)) k hu
    Causalean.Stat.OrderStatistic.WeightedConcomitant.uniform_count_le_mass · Causalean/Stat/OrderStatistic/WeightedConcomitant/UniformOrderCDF.lean:39
Uniform­Order­Moments 1 core · 1 supporting The sorted-coordinate identities follow from the first-n spacing law and the simplex coordinate and cross moments in OrderStatisticMoments. ★ uniform_order_second_moment

First two moments of a uniform order statistic

The sorted-coordinate identities follow from the first-n spacing law and the simplex coordinate and cross moments in OrderStatisticMoments. The zero-based sorted index j corresponds to beta parameters j+1 and n-j, as in the standard uniform order-statistic density.

theorem uniform_order_second_moment reviewed
Causalean.Stat.OrderStatistic.WeightedConcomitant

For a positive sample size and zero-based sorted index, the corresponding uniform order statistic has second moment (j+1)(j+2)/((n+1)(n+2)).

Formal statement
n :
ℕ
hn :
0 < n
j :
Fin n
(∫ x, (sortedSample n x j) ^ 2 ∂iidSample uniform01 n)
= (((j : ℕ) + 1 : ℝ) * ((j : ℕ) + 2)) / ((n + 1) * (n + 2))
Proof (Lean source)
theorem uniform_order_second_moment {n : ℕ} (hn : 0 < n) (j : Fin n) : (∫ x, (sortedSample n x j) ^ 2 ∂iidSample uniform01 n) = (((j : ℕ) + 1 : ℝ) * ((j : ℕ) + 2)) / ((n + 1) * (n + 2)) := by have _ := hn classical let s := Finset.Iic j let D : ℝ := (n + 1) * (n + 2) have hsorted (x : Fin n → ℝ) : sortedSample n x j = ∑ i ∈ s, firstNSpacings n x i := by simpa [s, prefixCoordinates, firstNSpacings_eq_orderedSpacings] using (congrFun (prefixCoordinates_orderedSpacings n (sortedSample n x)) j).symm have hsquare (z : Fin n → ℝ) : (∑ i ∈ s, z i) ^ 2 = ∑ i ∈ s, ∑ k ∈ s, z i * z k := by rw [pow_two, Finset.sum_mul_sum] have hmeas : Measurable (fun z : Fin n → ℝ => ∑ i ∈ s, ∑ k ∈ s, z i * z k) := by fun_prop have hpair (i k : Fin n) : (n.factorial : ℝ) * (∫ z in spacingSimplex n, z i * z k ∂volume) = (if i = k then (2 : ℝ) else 1) / D := by by_cases hik : i = k · subst k simpa [D, pow_two] using simplex_coordinate_second_moment n i · simpa [hik, D] using simplex_coordinate_cross_moment n i k hik have hinter (i : Fin n) : Integrable (fun z : Fin n → ℝ => ∑ k ∈ s, z i * z k) (volume.restrict (spacingSimplex n)) := by exact integrable_finsetSum s (fun k _ => simplex_coordinate_product_integrable_local n i k) have hcount (i : Fin n) (hi : i ∈ s) : (∑ k ∈ s, (if i = k then (2 : ℝ) else 1) / D) = ((s.card : ℝ) + 1) / D := by have hnum : (∑ k ∈ s, if i = k then (2 : ℝ) else 1) = (s.card : ℝ) + 1 := by calc _ = ∑ k ∈ s, ((1 : ℝ) + if i = k then 1 else 0) := by apply Finset.sum_congr rfl intro k hk split_ifs <;> norm_num _ = _ := by simp [Finset.sum_add_distrib, hi] rw [← Finset.sum_div] exact congrArg (· / D) hnum calc (∫ x, (sortedSample n x j) ^ 2 ∂iidSample uniform01 n) = ∫ z, (∑ i ∈ s, ∑ k ∈ s, z i * z k) ∂(iidSample uniform01 n).map (firstNSpacings n) := by rw [integral_map (firstNSpacings_aemeasurable_local n) hmeas.aestronglyMeasurable] simp only [← hsquare, ← hsorted] _ = (n.factorial : ℝ) * (∫ z, (∑ i ∈ s, ∑ k ∈ s, z i * z k) ∂volume.restrict (spacingSimplex n)) := by rw [uniform_firstN_spacings_law, integral_smul_measure] simp _ = ∑ i ∈ s, ∑ k ∈ s, (if i = k then (2 : ℝ) else 1) / D := by rw [integral_finsetSum _ (fun i _ => hinter i), Finset.mul_sum] apply Finset.sum_congr rfl intro i hi rw [integral_finsetSum _ (fun k _ => simplex_coordinate_product_integrable_local n i k), Finset.mul_sum] exact Finset.sum_congr rfl (fun k _ => hpair i k) _ = ((s.card : ℝ) * ((s.card : ℝ) + 1)) / D := by rw [Finset.sum_congr rfl (fun i hi => hcount i hi)] simp [div_eq_mul_inv] ring _ = (((j : ℕ) + 1 : ℝ) * ((j : ℕ) + 2)) / ((n + 1) * (n + 2)) := by simp [s, D, Fin.card_Iic] ring
Causalean.Stat.OrderStatistic.WeightedConcomitant.uniform_order_second_moment · Causalean/Stat/OrderStatistic/WeightedConcomitant/UniformOrderMoments.lean:126 · uses iidSample , sortedSample , uniform01
1 supporting declaration (lemmas, instances)
Uniform­Tagged­Rank 1 core · 7 supporting These facts isolate the finite-product and tie-free steps used by the tagged concomitant cell law. ★ uniform_tagged_rank_mass

Ranks and binomial counts in an iid uniform tuple

These facts isolate the finite-product and tie-free steps used by the tagged concomitant cell law. A tagged point's rank is the number of other observations below it, and that count at a fixed threshold has a binomial law.

theorem uniform_tagged_rank_mass reviewed
Causalean.Stat.OrderStatistic.WeightedConcomitant

A positive sample size, tagged coordinate, and rank have uniform rank mass under the iid unit-uniform law: the probability that the tagged observation occupies that position in the sorted sample is one over the sample size.

Formal statement
N :
ℕ
hN :
0 < N
i j :
Fin N
iidSample uniform01 N {u | (sort u).symm i = j} = ofReal (1 / (N : ℝ))
Proof (Lean source)
theorem uniform_tagged_rank_mass {N : ℕ} (hN : 0 < N) (i j : Fin N) : iidSample uniform01 N {u | (sort u).symm i = j} = ofReal (1 / (N : ℝ)) := by let m := iidSample uniform01 N {u | (sort u).symm i = j} have hsum : N • m = 1 := by calc N • m = ∑ _ : Fin N, m := (Fin.sum_const N m).symm _ = ∑ k : Fin N, iidSample uniform01 N {u | (sort u).symm k = j} := by apply Finset.sum_congr rfl intro k _ simpa only [m] using uniform_tagged_rank_mass_eq_of_tag i k j _ = 1 := sum_uniform_tagged_rank_mass j have hN0 : (N : ENNReal) ≠ 0 := by exact_mod_cast Nat.ne_of_gt hN have hNtop : (N : ENNReal) ≠ ⊤ := ENNReal.natCast_ne_top N have hm : (N : ENNReal) * m = 1 := by simpa [nsmul_eq_mul] using hsum have ht : (N : ENNReal) * ofReal (1 / (N : ℝ)) = 1 := by rw [ENNReal.ofReal_div_of_pos (by exact_mod_cast hN)] simpa [one_div] using ENNReal.mul_inv_cancel hN0 hNtop exact (ENNReal.mul_left_inj hN0 hNtop).mp (by simpa only [mul_comm] using hm.trans ht.symm)
Causalean.Stat.OrderStatistic.WeightedConcomitant.uniform_tagged_rank_mass · Causalean/Stat/OrderStatistic/WeightedConcomitant/UniformTaggedRank.lean:326 · uses iidSample , uniform01
7 supporting declarations (lemmas, instances)
  • iid_uniform_coordinates_injective_ae theorem — For an iid unit-uniform tuple, its coordinates are pairwise distinct almost surely.
    N :
    ℕ
    ∀ᵐ u ∂iidSample uniform01 N, Injective u
    Proof (Lean source)
    theorem iid_uniform_coordinates_injective_ae {N : ℕ} : ∀ᵐ u ∂iidSample uniform01 N, Injective u := by rw [iid_uniform_cube_law] apply ae_restrict_of_ae have hpair (i j : Fin N) (hij : i ≠ j) : ∀ᵐ u : Fin N → ℝ ∂volume, u i ≠ u j := by let L : (Fin N → ℝ) →ₗ[ℝ] ℝ := (LinearMap.proj i : (Fin N → ℝ) →ₗ[ℝ] ℝ) - LinearMap.proj j have hL : L ≠ 0 := by intro h have h' := LinearMap.congr_fun h (fun k => if k = i then 1 else 0) simp [L, hij.symm] at h' have hker : LinearMap.ker L ≠ ⊤ := by intro h exact hL (LinearMap.ker_eq_top.mp h) have hs : {u : Fin N → ℝ | u i = u j} = (LinearMap.ker L : Set (Fin N → ℝ)) := by ext u simp [L, LinearMap.mem_ker, sub_eq_zero] apply (ae_iff).2 simp only [not_not] change volume {u : Fin N → ℝ | u i = u j} = 0 rw [hs] exact Measure.addHaar_submodule volume (LinearMap.ker L) hker have hall : ∀ᵐ u : Fin N → ℝ ∂volume, ∀ i j : Fin N, i ≠ j → u i ≠ u j := by simp only [Filter.eventually_all] intro i j hij exact hpair i j hij filter_upwards [hall] with u hu i j hij by_contra hne exact hu i j hne hij
    Causalean.Stat.OrderStatistic.WeightedConcomitant.iid_uniform_coordinates_injective_ae · Causalean/Stat/OrderStatistic/WeightedConcomitant/UniformTaggedRank.lean:22
  • uniform_tagged_rank_eq_count theorem — For an iid unit-uniform tuple with no ties, the zero-based rank of a tagged coordinate equals the number of other coordinates below it.
    N :
    ℕ
    u :
    Fin N → ℝ
    i :
    Fin N
    hu :
    ((sort u).symm i).val
    = (((Finset.univ : Finset (Fin N)).erase i).filter (fun k => u k < u i)).card
    Proof (Lean source)
    theorem uniform_tagged_rank_eq_count {N : ℕ} (u : Fin N → ℝ) (i : Fin N) (hu : Injective u) : ((Tuple.sort u).symm i).val = (((Finset.univ : Finset (Fin N)).erase i).filter (fun k => u k < u i)).card := by let σ := Tuple.sort u have hs : StrictMono (u ∘ σ) := (Tuple.monotone_sort u).strictMono_of_injective (hu.comp σ.injective) have hcard : ((Finset.univ : Finset (Fin N)).filter (fun k => k < σ.symm i)).card = (σ.symm i).val := by simpa using (Fin.card_filter_val_lt (n := N) (m := (σ.symm i).val)) rw [← hcard] apply Finset.card_equiv σ intro k simp only [mem_filter, Finset.mem_univ, true_and, Finset.mem_erase, ne_eq, and_true] constructor · intro hk have : u (σ k) < u i := by simpa only [Function.comp_apply, σ.apply_symm_apply] using hs hk exact ⟨by intro h; subst h; exact (lt_irrefl _ this), this⟩ · intro hk apply hs.lt_iff_lt.mp simpa only [Function.comp_apply, σ.apply_symm_apply] using hk.2
    Causalean.Stat.OrderStatistic.WeightedConcomitant.uniform_tagged_rank_eq_count · Causalean/Stat/OrderStatistic/WeightedConcomitant/UniformTaggedRank.lean:56
  • uniform_subset_lt_count_mass theorem — For any finite set of coordinates in an iid unit-uniform tuple, the number strictly below a threshold in the unit interval has the binomial mass with one trial per selected coordinate.
    N :
    ℕ
    S :
    r :
    ℕ
    v :
    ℝ
    hv :
    v ∈ Icc (0 : ℝ) 1
    iidSample uniform01 N {u | (S.filter (fun k => u k < v)).card = r}
    = ofReal ((Nat.choose S.card r : ℝ) * v ^ r * (1 - v) ^ (S.card - r))
    Proof (Lean source)
    theorem uniform_subset_lt_count_mass {N : ℕ} (S : Finset (Fin N)) (r : ℕ) {v : ℝ} (hv : v ∈ Icc (0 : ℝ) 1) : iidSample uniform01 N {u | (S.filter (fun k => u k < v)).card = r} = ofReal ((Nat.choose S.card r : ℝ) * v ^ r * (1 - v) ^ (S.card - r)) := by let p : unitInterval := ⟨v, hv⟩ let f : Fin N → ℝ → Prop := fun k x => k ∈ S ∧ x < v haveI : IsProbabilityMeasure uniform01 := ⟨by simp [uniform01]⟩ have hbase : Measure.map (fun x : ℝ => x < v) uniform01 = unitInterval.toNNReal p • Measure.dirac True + unitInterval.toNNReal (unitInterval.symm p) • Measure.dirac False := by apply Measure.ext_of_singleton intro b by_cases hb : b · have he : b = True := propext (iff_true_intro hb) rw [he] rw [show (Measure.map (fun x : ℝ => x < v) uniform01) {True} = uniform01 (Iio v) by rw [Measure.map_apply (by fun_prop) (by simp)] congr 1 ext x simp] simp only [Measure.add_apply, Measure.smul_apply] simp rw [uniform01, Measure.restrict_apply measurableSet_Iio] have hs : Iio v ∩ Icc 0 1 = Ico 0 v := by ext x simp only [Set.mem_inter_iff, Set.mem_Iio, Set.mem_Icc, Set.mem_Ico] exact ⟨fun h => ⟨h.2.1, h.1⟩, fun h => ⟨h.2, h.1, le_trans h.2.le hv.2⟩⟩ rw [hs, Real.volume_Ico] simp only [sub_zero, ofReal, unitInterval.toNNReal] congr 1 exact Subtype.ext (Real.coe_toNNReal v hv.1) · have he : b = False := propext (iff_false_intro hb) rw [he] rw [show (Measure.map (fun x : ℝ => x < v) uniform01) {False} = uniform01 (Ici v) by rw [Measure.map_apply (by fun_prop) (by simp)] congr 1 ext x simp] simp only [Measure.add_apply, Measure.smul_apply] simp rw [uniform01, Measure.restrict_apply measurableSet_Ici] have hs : Ici v ∩ Icc 0 1 = Icc v 1 := by ext x simp only [Set.mem_inter_iff, Set.mem_Ici, Set.mem_Icc] exact ⟨fun h => ⟨h.1, h.2.2⟩, fun h => ⟨h.1, le_trans hv.1 h.1, h.2⟩⟩ rw [hs, Real.volume_Icc] simp only [ofReal, unitInterval.toNNReal] congr 1 exact Subtype.ext (Real.coe_toNNReal (1 - v) (sub_nonneg.mpr hv.2)) haveI (k : Fin N) : IsProbabilityMeasure (uniform01.map (f k)) := Measure.isProbabilityMeasure_map (by fun_prop) have hcoord (k : Fin N) : uniform01.map (f k) = unitInterval.toNNReal p • Measure.dirac (k ∈ (S : Set (Fin N))) + unitInterval.toNNReal (unitInterval.symm p) • Measure.dirac False := by by_cases hk : k ∈ S · simpa [f, p, hk] using hbase · simp [f, hk, ← add_smul, unitInterval.toNNReal_add_toNNReal_symm] have hLaw : (iidSample uniform01 N).map (fun u => {k | k ∈ S ∧ u k < v}) = ProbabilityTheory.setBernoulli (S : Set (Fin N)) p := by calc (iidSample uniform01 N).map (fun u => {k | k ∈ S ∧ u k < v}) = (Measure.pi fun k => uniform01.map (f k)).map (fun b => {k | b k}) := by rw [← Measure.pi_map_pi (fun k => (show AEMeasurable (f k) uniform01 from by fun_prop))] rw [Measure.map_map (by fun_prop) (by fun_prop)] rfl _ = ProbabilityTheory.setBernoulli (S : Set (Fin N)) p := by simp_rw [hcoord] rw [ProbabilityTheory.setBernoulli_eq_map, Measure.infinitePi_eq_pi] calc iidSample uniform01 N {u | (S.filter (fun k => u k < v)).card = r} = ((iidSample uniform01 N).map (fun u => {k | k ∈ S ∧ u k < v})).map ncard {r} := by rw [Measure.map_apply (by fun_prop) (by simp)] rw [Measure.map_apply (by fun_prop) (by measurability)] congr 1 ext u have he : {k | k ∈ S ∧ u k < v} = (S.filter (fun k => u k < v) : Set (Fin N)) := by ext k simp change (S.filter (fun k => u k < v)).card = r ↔ ({k | k ∈ S ∧ u k < v} : Set (Fin N)).ncard = r rw [he, Set.ncard_coe_finset] _ = (ProbabilityTheory.setBernoulli (S : Set (Fin N)) p).map ncard {r} := by rw [hLaw] _ = _ := by rw [ProbabilityTheory.map_ncard_setBernoulli_singleton (Set.toFinite (S : Set (Fin N)))] simp [p]
    Causalean.Stat.OrderStatistic.WeightedConcomitant.uniform_subset_lt_count_mass · Causalean/Stat/OrderStatistic/WeightedConcomitant/UniformTaggedRank.lean:83
  • iid_uniform_relabel_law theorem — Relabeling the coordinates of an iid unit-uniform tuple by a permutation preserves its finite-product probability law.
    N :
    ℕ
    σ :
    Perm (Fin N)
    (iidSample uniform01 N).map (fun u i => u (σ i)) = iidSample uniform01 N
    Proof (Lean source)
    theorem iid_uniform_relabel_law {N : ℕ} (σ : Perm (Fin N)) : (iidSample uniform01 N).map (fun u i => u (σ i)) = iidSample uniform01 N := by haveI : IsProbabilityMeasure uniform01 := ⟨by simp [uniform01]⟩ have hf : (fun u : Fin N → ℝ => fun i => u (σ i)) = (MeasurableEquiv.piCongrLeft (fun _ : Fin N => ℝ) σ.symm : (Fin N → ℝ) → (Fin N → ℝ)) := by funext u i simp [MeasurableEquiv.coe_piCongrLeft, Equiv.piCongrLeft_apply] rw [hf] simpa [iidSample] using Measure.pi_map_piCongrLeft σ.symm (fun _ : Fin N => uniform01)
    Causalean.Stat.OrderStatistic.WeightedConcomitant.iid_uniform_relabel_law · Causalean/Stat/OrderStatistic/WeightedConcomitant/UniformTaggedRank.lean:185
  • uniform_tagged_rank_mass_eq_of_tag theorem — For an iid uniform tuple, two tagged coordinates have the same probability of occupying any specified rank.
    N :
    ℕ
    i k j :
    Fin N
    iidSample uniform01 N {u | (sort u).symm i = j}
    = iidSample uniform01 N {u | (sort u).symm k = j}
    Proof (Lean source)
    theorem uniform_tagged_rank_mass_eq_of_tag {N : ℕ} (i k j : Fin N) : iidSample uniform01 N {u | (sort u).symm i = j} = iidSample uniform01 N {u | (sort u).symm k = j} := by classical let μ := iidSample uniform01 N let σ : Perm (Fin N) := Equiv.swap i k let R : (Fin N → ℝ) → Fin N → Prop := fun u a => (sort u).symm a = j have hmeas : NullMeasurableSet {u | R u i} μ := by let F : Set (Fin N → ℝ) := {u | (((Finset.univ : Finset (Fin N)).erase i).filter (fun a => u a < u i)).card = j.val} have hF : MeasurableSet F := by dsimp [F] apply measurableSet_eq_fun · simp_rw [Finset.card_filter] apply Finset.measurable_sum intro a _ apply Measurable.ite · exact measurableSet_lt (measurable_pi_apply a) (measurable_pi_apply i) · exact measurable_const · exact measurable_const · exact measurable_const apply hF.nullMeasurableSet.congr filter_upwards [iid_uniform_coordinates_injective_ae (N := N)] with u hu apply propext change (((Finset.univ : Finset (Fin N)).erase i).filter (fun a => u a < u i)).card = j.val ↔ ((sort u).symm i = j) rw [← uniform_tagged_rank_eq_count u i hu] exact Fin.ext_iff.symm have hsort (u : Fin N → ℝ) (hu : Injective u) : (sort (fun a => u (σ a))).symm i = (sort u).symm (σ i) := by have hs (a : Fin N) : σ (sort (fun a => u (σ a)) a) = sort u a := by apply hu exact congrFun (Tuple.comp_perm_comp_sort_eq_comp_sort (f := u) (σ := σ)) a apply (sort u).injective calc (sort u) ((sort (fun a => u (σ a))).symm i) = σ (sort (fun a => u (σ a)) ((sort (fun a => u (σ a))).symm i)) := (hs _).symm _ = σ i := by simp _ = (sort u) ((sort u).symm (σ i)) := by simp have hrelabel : Measurable (fun u : Fin N → ℝ => fun a => u (σ a)) := by fun_prop have hmeas' : NullMeasurableSet {u | R u i} (μ.map (fun u => fun a => u (σ a))) := by rw [iid_uniform_relabel_law σ] exact hmeas calc μ {u | R u i} = (μ.map (fun u => fun a => u (σ a))) {u | R u i} := by rw [iid_uniform_relabel_law σ] _ = μ {u | R (fun a => u (σ a)) i} := by rw [Measure.map_apply₀ hrelabel.aemeasurable hmeas'] rfl _ = μ {u | R u k} := by apply measure_congr filter_upwards [iid_uniform_coordinates_injective_ae (N := N)] with u hu apply propext change (sort (fun a => u (σ a))).symm i = j ↔ (sort u).symm k = j rw [hsort u hu] simp [σ]
    Causalean.Stat.OrderStatistic.WeightedConcomitant.uniform_tagged_rank_mass_eq_of_tag · Causalean/Stat/OrderStatistic/WeightedConcomitant/UniformTaggedRank.lean:200
  • sum_uniform_tagged_rank_mass theorem — For one rank of an iid uniform tuple, the masses of the events that each possible tag occupies that rank sum to one.
    N :
    ℕ
    j :
    Fin N
    (∑ i : Fin N, iidSample uniform01 N {u | (sort u).symm i = j}) = 1
    Proof (Lean source)
    theorem sum_uniform_tagged_rank_mass {N : ℕ} (j : Fin N) : (∑ i : Fin N, iidSample uniform01 N {u | (sort u).symm i = j}) = 1 := by classical let μ := iidSample uniform01 N let E : Fin N → Set (Fin N → ℝ) := fun i => {u | (sort u).symm i = j} have hmeas (i : Fin N) : NullMeasurableSet (E i) μ := by let F : Set (Fin N → ℝ) := {u | (((Finset.univ : Finset (Fin N)).erase i).filter (fun k => u k < u i)).card = j.val} have hF : MeasurableSet F := by dsimp [F] apply measurableSet_eq_fun · simp_rw [Finset.card_filter] apply Finset.measurable_sum intro k _ apply Measurable.ite · exact measurableSet_lt (measurable_pi_apply k) (measurable_pi_apply i) · exact measurable_const · exact measurable_const · exact measurable_const apply hF.nullMeasurableSet.congr filter_upwards [iid_uniform_coordinates_injective_ae (N := N)] with u hu apply propext change ( (((Finset.univ : Finset (Fin N)).erase i).filter (fun k => u k < u i)).card = j.val) ↔ ((sort u).symm i = j) rw [← uniform_tagged_rank_eq_count u i hu] exact Fin.ext_iff.symm have hdisj : Pairwise (onFun (AEDisjoint μ) E) := by intro i k hik apply Disjoint.aedisjoint rw [Set.disjoint_left] intro u hi hk have hi' : (sort u).symm i = j := hi have hk' : (sort u).symm k = j := hk exact hik ((sort u).symm.injective (hi'.trans hk'.symm)) have hcover : (⋃ i, E i) = univ := by ext u simp only [Set.mem_iUnion, Set.mem_univ, iff_true] exact ⟨(sort u) j, by simp [E]⟩ haveI : IsProbabilityMeasure μ := by haveI : IsProbabilityMeasure uniform01 := ⟨by simp [uniform01]⟩ dsimp [μ, iidSample] infer_instance calc (∑ i : Fin N, μ (E i)) = ∑' i : Fin N, μ (E i) := (tsum_fintype _).symm _ = μ (⋃ i, E i) := (measure_iUnion₀ hdisj hmeas).symm _ = 1 := by rw [hcover]; exact measure_univ
    Causalean.Stat.OrderStatistic.WeightedConcomitant.sum_uniform_tagged_rank_mass · Causalean/Stat/OrderStatistic/WeightedConcomitant/UniformTaggedRank.lean:271
  • uniform_other_lt_count_mass theorem — For a tagged coordinate of an iid unit-uniform tuple and a point inside the unit interval, the number of other coordinates below that point has the binomial mass with N-1 trials.
    N :
    ℕ
    i j :
    Fin N
    v :
    ℝ
    hv :
    v ∈ Icc (0 : ℝ) 1
    iidSample uniform01 N {u | (((Finset.univ : Finset (Fin N)).erase i).filter (fun k => u k < v)).card = j.val}
    = ofReal ((choose (N - 1) j.val : ℝ) * v ^ j.val * (1 - v) ^ (N - 1 - j.val))
    Proof (Lean source)
    theorem uniform_other_lt_count_mass {N : ℕ} (i j : Fin N) {v : ℝ} (hv : v ∈ Icc (0 : ℝ) 1) : iidSample uniform01 N {u | (((Finset.univ : Finset (Fin N)).erase i).filter (fun k => u k < v)).card = j.val} = ofReal ((choose (N - 1) j.val : ℝ) * v ^ j.val * (1 - v) ^ (N - 1 - j.val)) := by have hcard : ((Finset.univ : Finset (Fin N)).erase i).card = N - 1 := by simp simpa [hcard] using (uniform_subset_lt_count_mass ((Finset.univ : Finset (Fin N)).erase i) j.val hv)
    Causalean.Stat.OrderStatistic.WeightedConcomitant.uniform_other_lt_count_mass · Causalean/Stat/OrderStatistic/WeightedConcomitant/UniformTaggedRank.lean:352