k_sorted_of_monotone
If an array $A : \text{Fin } n \to \alpha$ is monotone non-decreasing, then it is $k$-sorted for every $k$.
Statement
theorem k_sorted_of_monotone {n : ℕ} (k : ℕ) {α : Type*} [Preorder α] (A : Fin n → α) (hA : Monotone A) : k_sorted k A
- Source
- folklore
- Verified
- 24 Nov 2026
- Axioms
Classical.choiceQuot.soundpropext- Built on 3
- k_sortedAn array $A : \text{Fin } n \to \alpha$ is $k$-sorted if $A_i \le A_{i+k}$ whenever $i+k < n$.
- LinearOrder.toTotalPreorderEvery
LinearOrderis aTotalPreorder. - TotalPreorderA total preorder: a preorder where
≤is total (complete). This is weaker thanLinearOrder— it does NOT require antisymmetry or…
Read back from the Lean
For any natural number $n$, natural number $k$, type $\alpha$ with a preorder, and sequence $A : \mathrm{Fin}\; n \to \alpha$, if $A$ is monotone, then $A$ is $k$-sorted.
Written by a model that saw only the Lean, never the English above. If the two disagree, that is worth a challenge.
The proof, explained
An array $A$ is $k$-sorted if $A(i) \le A(i+k)$ whenever $i+k < n$. By the monotonicity of $A$, this inequality reduces immediately to $i \le i + k$ on the index set $\text{Fin } n$, which holds because the order on $\text{Fin } n$ is inherited from the usual ordering on $\mathbb{N}$.
To show that $A$ is $k$-sorted, it suffices to show that $i \le i + k$ as indices in $\text{Fin } n$.
Unfolding the definition of a $k$-sorted array, we introduce an arbitrary index $i \in \text{Fin } n$ and the condition $hi : i + k < n$, leaving the goal $A(i) \le A(\langle i + k, hi \rangle)$. Because $A$ is assumed to be monotone ($hA$), this requirement reduces to checking that the index $i$ is at most the shifted index $\langle i + k, hi \rangle$.
intro i hi apply hA
The index inequality $i \le \langle i + k, hi \rangle$ holds in $\text{Fin } n$.
Rewriting with `Fin.le_def` converts the inequality in $\text{Fin } n$ into the standard inequality $i \le i + k$ on the underlying natural numbers. The simplifier then removes the coercion from the constructor $\langle i + k, hi \rangle$ and discharges the arithmetic statement $i \le i + k$.
uses
Fin.le_defrw [Fin.le_def] simp
Fin.le_def- An inequality $a \le b$ between elements of $\text{Fin } n$ is equivalent to the inequality between their underlying natural numbers.
- In Lean, an element of $\text{Fin } n$ bundles a natural number together with a proof that it is strictly less than $n$. Consequently, the shifted index $i + k$ is written as $\langle i + k, hi \rangle$, pairing the value with the bound $hi : i + k < n$.
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.
/-- A monotone array is k-sorted for any k. -/theorem k_sorted_of_monotone {n : ℕ} (k : ℕ) {α : Type*} [Preorder α] (A : Fin n → α) (hA : Monotone A) : k_sorted k A := by intro i hi apply hA rw [Fin.le_def] simp