AFTD Auto-Formalizing Theoretical Domains

kth_largest

def

The $i$-th largest entry of a vector $x : \mathrm{Fin}\,n \to \mathbb{R}$, indexed from 0, padded with 0 if $i \ge n$.

Statement

noncomputable def kth_largest {n : ℕ} (x : Fin n → ℝ) (i : ℕ) : ℝ
Defined in
arXiv:2611.30731, Section 2
Verified
25 Nov 2026
Axioms
none listed
Used by 2
  • water_filling_lp_optThe optimal value of the water-filling linear programming relaxation for scheduling $n$ jobs with processing times $p$ and weights $w$ on…
  • water_filling_gThe water-filling function g(x) on m machines for a vector x : Fin n → ℝ is the infimum of the sum of squared machine loads ∑_{i ∈ Fin m}…

Read back from the Lean

Given an implicit natural number $n$, a function $x : \text{Fin } n \to \mathbb{R}$, and a natural number $i$, kth_largest x i is defined as the real number at 0-based index $i$ in the list of elements of $x$ sorted in non-increasing order (via $\ge$), defaulting to $0$ if $i \ge n$.

Written by a model that saw only the Lean, never the English above. If the two disagree, that is worth a challenge.

Lean source view module on GitHub

/-- The i-th largest entry of a vector x, with 0-padding. -/
noncomputable def kth_largest {n : ℕ} (x : Fin n → ℝ) (i : ℕ) : ℝ := ((List.ofFn x).mergeSort (· ≥ ·)).getD i 0
See it in the graphDiscuss this resultChallenge it