op2046_majorization_threshold_equiv
For finite real vectors with positive sums, normalized majorization is equivalent to dominance of the sums of positive parts above every real threshold.
Statement
theorem op2046_majorization_threshold_equiv (n : ℕ) (x y : Fin n → ℝ) (hx : 0 < ∑ i, x i) (hy : 0 < ∑ i, y i) : op2046_majorizes n x y ↔ ∀ s : ℝ, (∑ i, max (y i / (∑ j, y j) - s) 0) ≤ ∑ i, max (x i / (∑ j, x j) - s) 0- Source
- Deterministic reduction for OP-2046 via positive-part transforms of finite spectra.
- Verified
- 20 Nov 2026
- Axioms
Classical.choiceQuot.soundpropext- Built on 3
- op2046_majorizesFor two real vectors with positive sums, every subset sum of the second normalized vector is bounded by some same-cardinality subset sum…
- TotalPreorderA total preorder: a preorder where
≤is total (complete). This is weaker thanLinearOrder— it does NOT require antisymmetry or… - LinearOrder.toTotalPreorderEvery
LinearOrderis aTotalPreorder.
The proof, explained
The equivalence between normalized majorization and dominance under hockey-stick functions $\max(t - s, 0)$ is established by relating subset sums to level sets. In the forward direction, given a threshold $s$, the sum $\sum_i \max(v_i - s, 0)$ equals the sum of $v_i - s$ over the level set $T = \{i \mid v_i > s\}$, which majorization bounds by the sum of $u_i - s$ over an equicardinal set $S$, and in turn by $\sum_i \max(u_i - s, 0)$. Conversely, given a subset $T$ of size $k > 0$, setting the threshold $s$ to be the $k$-th largest component of $u$ makes $\sum_i \max(u_i - s, 0)$ match the sum of the $k$ largest components of $u$ minus $ks$, and evaluating the threshold hypothesis at $s$ forces these top $k$ components to dominate the sum of $v$ on $T$.
The equivalence splits into two directions; in the forward direction, we assume normalized majorization and introduce an arbitrary real threshold $s$.
The proof begins with `constructor` to split the `↔` statement into the forward implication (majorization implies threshold dominance) and the reverse implication. In the forward direction, we introduce the hypothesis `h` asserting that $x$ majorizes $y$ and the arbitrary threshold $s \in \mathbb{R}$.
constructor · intro h s
The sum $\sum_{i} \max(v_i - s, 0)$ equals the restricted sum $\sum_{i \in T} (v_i - s)$, where $T = \{i \mid v_i > s\}$.
Let $v_i = y_i / \sum y$ and $u_i = x_i / \sum x$ denote the normalized vectors. We partition the index set into $T = \{i \mid v_i > s\}$ and its complement. For $i \in T$, we have $v_i - s > 0$, so $\max(v_i - s, 0) = v_i - s$. For $i \notin T$, we have $v_i - s \le 0$, so $\max(v_i - s, 0) = 0$. Summing over the whole universe therefore reduces to the sum over $T$.
uses
Finset.sum_filter_add_sum_filter_not,Finset.mem_filter,Finset.mem_univ,true_and,max_eq_left,sub_nonneg.mpr,le_of_lt,max_eq_right,sub_nonpos.mpr,not_lt.mp,Finset.sum_congr,Finset.sum_const_zero,add_zerolet v := fun i => y i / (∑ j, y j) let u := fun i => x i / (∑ j, x j) let T := Finset.filter (fun i => s < v i) Finset.univ have hT_sum : (∑ i, max (v i - s) 0) = (∑ i ∈ T, (v i - s)) := by rw [← Finset.sum_filter_add_sum_filter_not Finset.univ (fun i => s < v i)] have h1 : ∀ i ∈ T, max (v i - s) 0 = v i - s := by intro i hi simp only [T, Finset.mem_filter, Finset.mem_univ, true_and] at hi exact max_eq_left (sub_nonneg.mpr (le_of_lt hi)) have h2 : ∀ i ∈ Finset.filter (fun i => ¬(s < v i)) Finset.univ, max (v i - s) 0 = 0 := by intro i hi simp only [Finset.mem_filter, Finset.mem_univ, true_and] at hi exact max_eq_right (sub_nonpos.mpr (not_lt.mp hi)) rw [Finset.sum_congr rfl h1, Finset.sum_congr rfl h2, Finset.sum_const_zero, add_zero]
Majorization yields a subset $S$ with $|S| = |T|$ such that $\sum_{i \in T} v_i - |T|s \le \sum_{i \in S} u_i - |S|s$.
Applying the definition of majorization to the set $T$ provides a subset $S$ with $|S| = |T|$ such that the normalized sum of $y$ on $T$ is at most the normalized sum of $x$ on $S$, i.e., $\sum_{i \in T} v_i \le \sum_{i \in S} u_i$. Subtracting $|T|s = |S|s$ from both sides maintains the inequality.
uses
Finset.sum_sub_distrib,Finset.sum_divobtain ⟨S, hScard, hSineq⟩ := h.2.2 T have hT_expand : (∑ i ∈ T, (v i - s)) = (∑ i ∈ T, v i) - (T.card : ℝ) * s := by simp [Finset.sum_sub_distrib] have hS_expand : (∑ i ∈ S, (u i - s)) = (∑ i ∈ S, u i) - (S.card : ℝ) * s := by simp [Finset.sum_sub_distrib] have h_sum_T_eq : (∑ i ∈ T, v i) = (∑ i ∈ T, y i) / (∑ j, y j) := (Finset.sum_div T y (∑ j, y j)).symm have h_sum_S_eq : (∑ i ∈ S, u i) = (∑ i ∈ S, x i) / (∑ j, x j) := (Finset.sum_div S x (∑ j, x j)).symm have h_le : (∑ i ∈ T, v i) - (T.card : ℝ) * s ≤ (∑ i ∈ S, u i) - (S.card : ℝ) * s := by rw [h_sum_T_eq, h_sum_S_eq, hScard] linarith
The sum $\sum_{i \in S} (u_i - s)$ is bounded above by $\sum_i \max(u_i - s, 0)$, completing the forward direction.
Each term $u_i - s$ is bounded by $\max(u_i - s, 0)$. Since each $\max(u_i - s, 0)$ is nonnegative, summing over the subset $S$ is bounded by summing over all indices. Combining this with the previous steps by transitivity shows that $\sum_i \max(v_i - s, 0) \le \sum_i \max(u_i - s, 0)$.
uses
Finset.sum_le_sum,le_max_left,Finset.sum_le_univ_sum_of_nonneg,le_max_right,le_transhave hS_le : (∑ i ∈ S, (u i - s)) ≤ ∑ i, max (u i - s) 0 := by have h1 : (∑ i ∈ S, (u i - s)) ≤ ∑ i ∈ S, max (u i - s) 0 := Finset.sum_le_sum (fun i _ => le_max_left (u i - s) 0) have h2 : (∑ i ∈ S, max (u i - s) 0) ≤ ∑ i, max (u i - s) 0 := Finset.sum_le_univ_sum_of_nonneg (fun i => le_max_right (u i - s) 0) exact le_trans h1 h2 rw [hT_sum, hT_expand] rw [← hS_expand] at h_le exact le_trans h_le hS_le
In the reverse direction, the required majorization inequality holds trivially when $T$ is empty.
Assuming threshold dominance for all $s \in \mathbb{R}$, we are given a subset $T$ and must find an equicardinal subset $S$ dominating $T$. If $|T| = 0$, then $T = \emptyset$; taking $S = \emptyset$ satisfies $|S| = |T| = 0$, and both sums are $0 \le 0$.
uses
Finset.card_eq_zero.mp· intro h_thresh refine ⟨hx, hy, fun T => ?_⟩ by_cases hT0 : T.card = 0 · use ∅ rw [Finset.card_eq_zero.mp hT0] simp
When $|T| > 0$, we sort $u$ in non-increasing order and set $s$ to be its $|T|$-th largest component.
Since $|T| \neq 0$, we have $0 < |T| \le n$. Sorting $-u$ non-decreasingly via the permutation $\sigma = \text{Tuple.sort}(-u)$ makes $g = u \circ \sigma$ antitone (non-increasing). We take $m = |T| - 1$ as an index in $\text{Fin } n$ and set the threshold $s = g(m)$, which is the $|T|$-th largest component of $u$.
uses
Nat.pos_of_ne_zero,Finset.card_le_univ,Tuple.sort,Tuple.monotone_sort· have hk0 : 0 < T.card := Nat.pos_of_ne_zero hT0 have hkn : T.card ≤ n := by have := Finset.card_le_univ T simpa using this let u := fun i => x i / (∑ j, x j) let v := fun i => y i / (∑ j, y j) let σ := Tuple.sort (-u) let g := u ∘ σ have hg : Antitone g := by intro i j hij have h := Tuple.monotone_sort (-u) hij have h' : - u (σ i) ≤ - u (σ j) := h dsimp [g] linarith let m : Fin n := ⟨T.card - 1, by omega⟩ let s := g m
The set $S = \sigma(I)$ consisting of the indices of the $|T|$ largest elements of $u$ satisfies $|S| = |T|$.
We let $I = \{i \in \text{Fin } n \mid i < |T|\}$ be the initial segment of $|T|$ indices, which has cardinality $|T|$ by bijecting with $\text{Fin } |T|$. Its image $S = \sigma(I)$ under the permutation $\sigma$ has the same cardinality $|S| = |T|$ because $\sigma$ is injective.
uses
Nat.lt_of_lt_of_le,Finset.mem_filter,Finset.mem_univ,true_and,Finset.mem_image,Finset.card_image_of_injective,Fin.mk.injlet I := Finset.filter (fun i : Fin n => (i : ℕ) < T.card) Finset.univ have hIcard : I.card = T.card := by have : I = Finset.image (fun (i : Fin T.card) => (⟨i.val, Nat.lt_of_lt_of_le i.isLt hkn⟩ : Fin n)) Finset.univ := by ext ⟨x, hx_lt⟩ simp only [I, Finset.mem_filter, Finset.mem_univ, true_and, Finset.mem_image] constructor · intro h exact ⟨⟨x, h⟩, rfl⟩ · rintro ⟨⟨y, hy⟩, hy2⟩ cases hy2 exact hy rw [this, Finset.card_image_of_injective] · simp · intro ⟨a, ha⟩ ⟨b, hb⟩ h ext exact Fin.mk.inj h let S := Finset.image σ I have hScard : S.card = T.card := by rw [Finset.card_image_of_injective _ (fun _ _ h => σ.injective h), hIcard] use S refine ⟨hScard, ?_⟩
At this threshold $s$, the positive part sum $\sum_i \max(u_i - s, 0)$ is exactly $\sum_{i \in S} u_i - |T|s$.
Because $g$ is antitone and $s = g(m)$ with $m = |T| - 1$, for $i \in I$ ($i \le m$) we have $g(i) \ge s$, giving $\max(g(i) - s, 0) = g(i) - s$. For $i \notin I$ ($i > m$), $g(i) \le s$, so the positive part vanishes. Reindexing the sum by the permutation $\sigma$ yields $\sum_i \max(u_i - s, 0) = \sum_{i \in I} (g(i) - s) = \sum_{i \in S} u_i - |T|s$.
uses
Finset.sum_filter_add_sum_filter_not,Finset.mem_filter,Finset.mem_univ,true_and,Fin.le_def,max_eq_left,sub_nonneg.mpr,max_eq_right,sub_nonpos.mpr,Finset.sum_congr,Finset.sum_const_zero,add_zero,Equiv.sum_comp,Finset.sum_image,Finset.sum_sub_distribhave hsplit := (Finset.sum_filter_add_sum_filter_not Finset.univ (fun i : Fin n => (i : ℕ) < T.card) (fun i => max (g i - s) 0)).symm have h1 : ∀ i ∈ I, max (g i - s) 0 = g i - s := by intro i hi simp only [I, Finset.mem_filter, Finset.mem_univ, true_and] at hi have him : i ≤ m := by rw [Fin.le_def] dsimp [m] omega have hgi : s ≤ g i := hg him exact max_eq_left (sub_nonneg.mpr hgi) have h2 : ∀ i ∈ Finset.filter (fun i : Fin n => ¬((i : ℕ) < T.card)) Finset.univ, max (g i - s) 0 = 0 := by intro i hi simp only [Finset.mem_filter, Finset.mem_univ, true_and] at hi have hmi : m ≤ i := by rw [Fin.le_def] dsimp [m] omega have hgi : g i ≤ s := hg hmi exact max_eq_right (sub_nonpos.mpr hgi) have hg_sum : (∑ i, max (g i - s) 0) = ∑ i ∈ I, (g i - s) := by rw [hsplit, Finset.sum_congr rfl h1] have h2' : (∑ i ∈ Finset.filter (fun i : Fin n => ¬((i : ℕ) < T.card)) Finset.univ, max (g i - s) 0) = 0 := by rw [Finset.sum_congr rfl h2, Finset.sum_const_zero] rw [h2', add_zero] have h_u_sum : (∑ i, max (u i - s) 0) = ∑ i, max (g i - s) 0 := by have := (Equiv.sum_comp σ (fun j => max (u j - s) 0)).symm exact this have hS_sum : (∑ i ∈ S, u i) = ∑ i ∈ I, g i := by exact Finset.sum_image (fun _ _ _ _ h => σ.injective h) have hI_expand : (∑ i ∈ I, (g i - s)) = (∑ i ∈ I, g i) - (T.card : ℝ) * s := by simp [Finset.sum_sub_distrib, hIcard] have h_u_final : (∑ i, max (u i - s) 0) = (∑ i ∈ S, u i) - (T.card : ℝ) * s := by rw [h_u_sum, hg_sum, hI_expand, ← hS_sum]
Bounding the $T$-sum and applying the threshold dominance hypothesis at $s$ completes the proof.
For the given subset $T$, we have $\sum_{i \in T} v_i - |T|s = \sum_{i \in T} (v_i - s) \le \sum_{i \in T} \max(v_i - s, 0) \le \sum_i \max(v_i - s, 0)$. Applying the threshold dominance hypothesis at $s = g(m)$ and substituting the exact value for the $u$-sum gives $\sum_{i \in T} v_i - |T|s \le \sum_{i \in S} u_i - |T|s$. Adding $|T|s$ to both sides yields $\sum_{i \in T} v_i \le \sum_{i \in S} u_i$, establishing majorization.
uses
Finset.sum_sub_distrib,Finset.sum_le_sum,le_max_left,Finset.sum_le_univ_sum_of_nonneg,le_max_right,le_trans,le_of_eq,Finset.sum_divhave hT_le : (∑ i ∈ T, v i) - (T.card : ℝ) * s ≤ ∑ i, max (v i - s) 0 := by have hT_sub : (∑ i ∈ T, (v i - s)) = (∑ i ∈ T, v i) - (T.card : ℝ) * s := by simp [Finset.sum_sub_distrib] rw [← hT_sub] have h1 : (∑ i ∈ T, (v i - s)) ≤ ∑ i ∈ T, max (v i - s) 0 := Finset.sum_le_sum (fun i _ => le_max_left (v i - s) 0) have h2 : (∑ i ∈ T, max (v i - s) 0) ≤ ∑ i, max (v i - s) 0 := Finset.sum_le_univ_sum_of_nonneg (fun i => le_max_right (v i - s) 0) exact le_trans h1 h2 have h_main : (∑ i ∈ T, v i) - (T.card : ℝ) * s ≤ (∑ i ∈ S, u i) - (T.card : ℝ) * s := by have h_th := h_thresh s exact le_trans (le_trans hT_le h_th) (le_of_eq h_u_final) have h_le : (∑ i ∈ T, v i) ≤ (∑ i ∈ S, u i) := by linarith have h_sum_T_eq : (∑ i ∈ T, v i) = (∑ i ∈ T, y i) / (∑ j, y j) := (Finset.sum_div T y (∑ j, y j)).symm have h_sum_S_eq : (∑ i ∈ S, u i) = (∑ i ∈ S, x i) / (∑ j, x j) := (Finset.sum_div S x (∑ j, x j)).symm rw [← h_sum_T_eq, ← h_sum_S_eq] exact h_le
add_zero- Adding zero to an element leaves it unchanged ($a + 0 = a$)
Equiv.sum_comp- Reindexing a sum over a finite type by an equivalence (permutation) leaves the sum unchanged
Fin.le_def- The order relation on `Fin n` coincides with the standard order on the underlying natural numbers
Fin.mk.inj- Equality of elements in `Fin n` implies equality of their underlying values
Finset.card_eq_zero.mp- A finite set has cardinality zero if and only if it is the empty set
Finset.card_image_of_injective- The image of a finite set under an injective map has the same cardinality as the original set
Finset.card_le_univ- The cardinality of any subset is at most the cardinality of the ambient finite type
Finset.mem_image- An element belongs to the image of a set under $f$ if and only if it is the value of $f$ at some element of the set
Finset.mem_filter- An element belongs to a filtered set if and only if it belongs to the base set and satisfies the predicate
Finset.mem_univ- Every element of a finite type belongs to the universal finset `Finset.univ`
Finset.sum_const_zero- A sum of constant zero over any finite set is zero
Finset.sum_congr- Two finite sums are equal if their index sets are equal and their summands agree on that set
Finset.sum_div- Factoring out a division from a finite sum: $(\sum f(i)) / a = \sum (f(i) / a)$
Finset.sum_filter_add_sum_filter_not- A sum over a finite set splits into the sum over elements satisfying $p$ plus the sum over elements satisfying $\neg p$
Finset.sum_image- Summing a function over the image of an injective map equals the sum over the domain
Finset.sum_le_sum- A sum of pointwise smaller terms is less than or equal to the sum of larger terms
Finset.sum_le_univ_sum_of_nonneg- A sum of nonnegative terms over a subset is bounded by the sum over the entire finite type
Finset.sum_sub_distrib- Summation distributes over subtraction: $\sum (f(i) - g(i)) = \sum f(i) - \sum g(i)$
le_max_left- Any term is less than or equal to its maximum with another term: $a \le \max(a, b)$
le_max_right- Any term is less than or equal to the maximum with it: $b \le \max(a, b)$
le_of_eq- Equality implies non-strict inequality ($a = b \implies a \le b$)
le_of_lt- Strict inequality implies non-strict inequality ($a < b \implies a \le b$)
le_trans- Transitivity of order: $a \le b$ and $b \le c$ imply $a \le c$
max_eq_left- If $b \le a$, then $\max(a, b) = a$
max_eq_right- If $a \le b$, then $\max(a, b) = b$
Nat.lt_of_lt_of_le- Strict inequality $n < m$ and non-strict inequality $m \le k$ imply $n < k$
Nat.pos_of_ne_zero- A natural number is strictly positive if and only if it is not zero
not_lt.mp- In a linear order, $\neg(a < b)$ implies $b \le a$
sub_nonneg.mpr- If $b \le a$, then $a - b \ge 0$
sub_nonpos.mpr- If $a \le b$, then $a - b \le 0$
true_and- The logical equivalence $\text{True} \land p \leftrightarrow p$
Tuple.monotone_sort- Composing a vector with its sorting permutation yields a non-decreasing (monotone) sequence
Tuple.sort- The permutation of indices that sorts a finite sequence in non-decreasing order
- Sorting a vector in non-increasing order is formalized in Mathlib by sorting its negation $-u$ non-decreasingly using `Tuple.sort (-u)`.
- The relation `op2046_majorizes` tests dominance of arbitrary subsets $T$ against some subset $S$ of equal cardinality; in the proof, the optimal choice of $S$ is explicitly constructed as the set of indices of the $|T|$ largest coordinates of the dominating vector.
Written by a model (gemini-3.8-flash) from the Lean proof and the goal states Lean reported at each step. Lean verified the proof; this explanation is a reading aid and is not itself machine-checked.
Lean source view module on GitHub
Choose a tactic — a marked line — to see the goals Lean had before and after it, as in Lean’s infoview. Step with ← → or j k.
open scoped BigOperators Matrix Topologyopen MeasureTheory ProbabilityTheory Filternoncomputable sectiontheorem op2046_majorization_threshold_equiv (n : ℕ) (x y : Fin n → ℝ) (hx : 0 < ∑ i, x i) (hy : 0 < ∑ i, y i) : op2046_majorizes n x y ↔ ∀ s : ℝ, (∑ i, max (y i / (∑ j, y j) - s) 0) ≤ ∑ i, max (x i / (∑ j, x j) - s) 0 := by constructor · intro h s let v := fun i => y i / (∑ j, y j) let u := fun i => x i / (∑ j, x j) let T := Finset.filter (fun i => s < v i) Finset.univ have hT_sum : (∑ i, max (v i - s) 0) = (∑ i ∈ T, (v i - s)) := by rw [← Finset.sum_filter_add_sum_filter_not Finset.univ (fun i => s < v i)] have h1 : ∀ i ∈ T, max (v i - s) 0 = v i - s := by intro i hi simp only [T, Finset.mem_filter, Finset.mem_univ, true_and] at hi exact max_eq_left (sub_nonneg.mpr (le_of_lt hi)) have h2 : ∀ i ∈ Finset.filter (fun i => ¬(s < v i)) Finset.univ, max (v i - s) 0 = 0 := by intro i hi simp only [Finset.mem_filter, Finset.mem_univ, true_and] at hi exact max_eq_right (sub_nonpos.mpr (not_lt.mp hi)) rw [Finset.sum_congr rfl h1, Finset.sum_congr rfl h2, Finset.sum_const_zero, add_zero] obtain ⟨S, hScard, hSineq⟩ := h.2.2 T have hT_expand : (∑ i ∈ T, (v i - s)) = (∑ i ∈ T, v i) - (T.card : ℝ) * s := by simp [Finset.sum_sub_distrib] have hS_expand : (∑ i ∈ S, (u i - s)) = (∑ i ∈ S, u i) - (S.card : ℝ) * s := by simp [Finset.sum_sub_distrib] have h_sum_T_eq : (∑ i ∈ T, v i) = (∑ i ∈ T, y i) / (∑ j, y j) := (Finset.sum_div T y (∑ j, y j)).symm have h_sum_S_eq : (∑ i ∈ S, u i) = (∑ i ∈ S, x i) / (∑ j, x j) := (Finset.sum_div S x (∑ j, x j)).symm have h_le : (∑ i ∈ T, v i) - (T.card : ℝ) * s ≤ (∑ i ∈ S, u i) - (S.card : ℝ) * s := by rw [h_sum_T_eq, h_sum_S_eq, hScard] linarith have hS_le : (∑ i ∈ S, (u i - s)) ≤ ∑ i, max (u i - s) 0 := by have h1 : (∑ i ∈ S, (u i - s)) ≤ ∑ i ∈ S, max (u i - s) 0 := Finset.sum_le_sum (fun i _ => le_max_left (u i - s) 0) have h2 : (∑ i ∈ S, max (u i - s) 0) ≤ ∑ i, max (u i - s) 0 := Finset.sum_le_univ_sum_of_nonneg (fun i => le_max_right (u i - s) 0) exact le_trans h1 h2 rw [hT_sum, hT_expand] rw [← hS_expand] at h_le exact le_trans h_le hS_le · intro h_thresh refine ⟨hx, hy, fun T => ?_⟩ by_cases hT0 : T.card = 0 · use ∅ rw [Finset.card_eq_zero.mp hT0] simp · have hk0 : 0 < T.card := Nat.pos_of_ne_zero hT0 have hkn : T.card ≤ n := by have := Finset.card_le_univ T simpa using this let u := fun i => x i / (∑ j, x j) let v := fun i => y i / (∑ j, y j) let σ := Tuple.sort (-u) let g := u ∘ σ have hg : Antitone g := by intro i j hij have h := Tuple.monotone_sort (-u) hij have h' : - u (σ i) ≤ - u (σ j) := h dsimp [g] linarith let m : Fin n := ⟨T.card - 1, by omega⟩ let s := g m let I := Finset.filter (fun i : Fin n => (i : ℕ) < T.card) Finset.univ have hIcard : I.card = T.card := by have : I = Finset.image (fun (i : Fin T.card) => (⟨i.val, Nat.lt_of_lt_of_le i.isLt hkn⟩ : Fin n)) Finset.univ := by ext ⟨x, hx_lt⟩ simp only [I, Finset.mem_filter, Finset.mem_univ, true_and, Finset.mem_image] constructor · intro h exact ⟨⟨x, h⟩, rfl⟩ · rintro ⟨⟨y, hy⟩, hy2⟩ cases hy2 exact hy rw [this, Finset.card_image_of_injective] · simp · intro ⟨a, ha⟩ ⟨b, hb⟩ h ext exact Fin.mk.inj h let S := Finset.image σ I have hScard : S.card = T.card := by rw [Finset.card_image_of_injective _ (fun _ _ h => σ.injective h), hIcard] use S refine ⟨hScard, ?_⟩ have hsplit := (Finset.sum_filter_add_sum_filter_not Finset.univ (fun i : Fin n => (i : ℕ) < T.card) (fun i => max (g i - s) 0)).symm have h1 : ∀ i ∈ I, max (g i - s) 0 = g i - s := by intro i hi simp only [I, Finset.mem_filter, Finset.mem_univ, true_and] at hi have him : i ≤ m := by rw [Fin.le_def] dsimp [m] omega have hgi : s ≤ g i := hg him exact max_eq_left (sub_nonneg.mpr hgi) have h2 : ∀ i ∈ Finset.filter (fun i : Fin n => ¬((i : ℕ) < T.card)) Finset.univ, max (g i - s) 0 = 0 := by intro i hi simp only [Finset.mem_filter, Finset.mem_univ, true_and] at hi have hmi : m ≤ i := by rw [Fin.le_def] dsimp [m] omega have hgi : g i ≤ s := hg hmi exact max_eq_right (sub_nonpos.mpr hgi) have hg_sum : (∑ i, max (g i - s) 0) = ∑ i ∈ I, (g i - s) := by rw [hsplit, Finset.sum_congr rfl h1] have h2' : (∑ i ∈ Finset.filter (fun i : Fin n => ¬((i : ℕ) < T.card)) Finset.univ, max (g i - s) 0) = 0 := by rw [Finset.sum_congr rfl h2, Finset.sum_const_zero] rw [h2', add_zero] have h_u_sum : (∑ i, max (u i - s) 0) = ∑ i, max (g i - s) 0 := by have := (Equiv.sum_comp σ (fun j => max (u j - s) 0)).symm exact this have hS_sum : (∑ i ∈ S, u i) = ∑ i ∈ I, g i := by exact Finset.sum_image (fun _ _ _ _ h => σ.injective h) have hI_expand : (∑ i ∈ I, (g i - s)) = (∑ i ∈ I, g i) - (T.card : ℝ) * s := by simp [Finset.sum_sub_distrib, hIcard] have h_u_final : (∑ i, max (u i - s) 0) = (∑ i ∈ S, u i) - (T.card : ℝ) * s := by rw [h_u_sum, hg_sum, hI_expand, ← hS_sum] have hT_le : (∑ i ∈ T, v i) - (T.card : ℝ) * s ≤ ∑ i, max (v i - s) 0 := by have hT_sub : (∑ i ∈ T, (v i - s)) = (∑ i ∈ T, v i) - (T.card : ℝ) * s := by simp [Finset.sum_sub_distrib] rw [← hT_sub] have h1 : (∑ i ∈ T, (v i - s)) ≤ ∑ i ∈ T, max (v i - s) 0 := Finset.sum_le_sum (fun i _ => le_max_left (v i - s) 0) have h2 : (∑ i ∈ T, max (v i - s) 0) ≤ ∑ i, max (v i - s) 0 := Finset.sum_le_univ_sum_of_nonneg (fun i => le_max_right (v i - s) 0) exact le_trans h1 h2 have h_main : (∑ i ∈ T, v i) - (T.card : ℝ) * s ≤ (∑ i ∈ S, u i) - (T.card : ℝ) * s := by have h_th := h_thresh s exact le_trans (le_trans hT_le h_th) (le_of_eq h_u_final) have h_le : (∑ i ∈ T, v i) ≤ (∑ i ∈ S, u i) := by linarith have h_sum_T_eq : (∑ i ∈ T, v i) = (∑ i ∈ T, y i) / (∑ j, y j) := (Finset.sum_div T y (∑ j, y j)).symm have h_sum_S_eq : (∑ i ∈ S, u i) = (∑ i ∈ S, x i) / (∑ j, x j) := (Finset.sum_div S x (∑ j, x j)).symm rw [← h_sum_T_eq, ← h_sum_S_eq] exact h_le