Documentation

CslibFrontier.Foundations.Data.Fintype.OrderStatistic

Order statistics and medians of finite families #

Defines rank-k order statistics (Fintype.IsOrderStatistic, Fintype.orderStatistic), lower median x_((n - 1) / 2) (Fintype.lowerMedian), and upper median x_(n / 2) (Fintype.upperMedian) for finite families x : ι → α, bridging to List.IsOrderStatistic and proving that any median minimizes ∑ i, |x i - y| over ℝ.

Main definitions #

Main results #

def Fintype.IsOrderStatistic {ι : Type u_1} {α : Type u_2} [Fintype ι] [LinearOrder α] (x : ι → α) (k : ℕ) (y : α) :

y is the k-th order statistic (0-indexed) of the profile x : ι → α: y lies in the image of x, at most k indices satisfy x i < y, and strictly more than k satisfy x i ≤ y.

noncomputable def Fintype.orderStatistic {ι : Type u_1} {α : Type u_2} [Fintype ι] [Nonempty ι] [LinearOrder α] (x : ι → α) (k : ℕ) :
α

The k-th order statistic (0-indexed) of x : ι → α, clamped to Fintype.card ι - 1 when k ≥ Fintype.card ι.

noncomputable def Fintype.lowerMedian {ι : Type u_1} {α : Type u_2} [Fintype ι] [Nonempty ι] [LinearOrder α] (x : ι → α) :
α

The lower median x_((n - 1) / 2) of a nonempty finite family x.

noncomputable def Fintype.upperMedian {ι : Type u_1} {α : Type u_2} [Fintype ι] [Nonempty ι] [LinearOrder α] (x : ι → α) :
α

The upper median x_(n / 2) of a nonempty finite family x.

theorem Fintype.lowerMedian_def {ι : Type u_1} {α : Type u_2} [Fintype ι] [Nonempty ι] [LinearOrder α] (x : ι → α) :
theorem Fintype.upperMedian_def {ι : Type u_1} {α : Type u_2} [Fintype ι] [Nonempty ι] [LinearOrder α] (x : ι → α) :
theorem Fintype.orderStatistic_eq_min {ι : Type u_1} {α : Type u_2} [Fintype ι] [Nonempty ι] [LinearOrder α] (x : ι → α) (k : ℕ) :
theorem Fintype.IsOrderStatistic.unique {ι : Type u_1} {α : Type u_2} [Fintype ι] [LinearOrder α] {x : ι → α} {k : ℕ} {y y' : α} (h : IsOrderStatistic x k y) (h' : IsOrderStatistic x k y') :
y = y'
theorem Fintype.orderStatistic_isOrderStatistic {ι : Type u_1} {α : Type u_2} [Fintype ι] [LinearOrder α] [Nonempty ι] (x : ι → α) {k : ℕ} (hk : k < card ι) :
theorem Fintype.orderStatistic_eq_of_isOrderStatistic {ι : Type u_1} {α : Type u_2} [Fintype ι] [LinearOrder α] [Nonempty ι] {x : ι → α} {k : ℕ} (hk : k < card ι) {y : α} (h : IsOrderStatistic x k y) :
theorem Fintype.orderStatistic_fin_eq_mergeSort {α : Type u_2} [LinearOrder α] {n : ℕ} (x : Fin (n + 1) → α) {k : ℕ} (hk : k < n + 1) :
((List.ofFn x).mergeSort fun (a b : α) => decide (a ≤ b))[k]? = some (orderStatistic x k)
theorem Fintype.lt_orderStatistic_iff {ι : Type u_1} {α : Type u_2} [Fintype ι] [LinearOrder α] [Nonempty ι] (x : ι → α) {k : ℕ} (hk : k < card ι) (t : α) :
t < orderStatistic x k ↔ {i : ι | x i ≤ t}.card ≤ k

Threshold characterization of the k-th order statistic: t < orderStatistic x k if and only if at most k indices satisfy x i ≤ t.

theorem Fintype.orderStatistic_comp_equiv {ι : Type u_1} {α : Type u_2} [Fintype ι] [LinearOrder α] {ι' : Type u_3} [Fintype ι'] [Nonempty ι] [Nonempty ι'] (e : ι' ≃ ι) (x : ι → α) (k : ℕ) :

Reindexing a family along an equivalence preserves every order statistic.

theorem Fintype.sum_abs_sub_le_of_median_counts {ι : Type u_1} [Fintype ι] {x : ι → ℝ} {y : ℝ} (hlt : 2 * {i : ι | x i < y}.card ≤ card ι) (hgt : 2 * {i : ι | y < x i}.card ≤ card ι) (z : ℝ) :
∑ i : ι, |x i - y| ≤ ∑ i : ι, |x i - z|

Any point y : ℝ having at most |ι| / 2 points strictly to its left and at most |ι| / 2 points strictly to its right minimizes ∑ i, |x i - y|.

theorem Fintype.sum_abs_sub_lowerMedian_le {ι : Type u_1} [Fintype ι] [Nonempty ι] (x : ι → ℝ) (z : ℝ) :
∑ i : ι, |x i - lowerMedian x| ≤ ∑ i : ι, |x i - z|

The lower median minimizes ∑ i, |x i - y| over ℝ.

theorem Fintype.sum_abs_sub_upperMedian_le {ι : Type u_1} [Fintype ι] [Nonempty ι] (x : ι → ℝ) (z : ℝ) :
∑ i : ι, |x i - upperMedian x| ≤ ∑ i : ι, |x i - z|

The upper median minimizes ∑ i, |x i - y| over ℝ.