h_chain_index_lt
For any $t$ strictly less than the length of the $h$-chain starting at residue $r$ in an array of length $n$, the index $r + t \cdot h$ is strictly less than $n$.
Statement
theorem h_chain_index_lt (n h r : ℕ) (t : ℕ) (ht : t < h_chain_len n h r) : r + t * h < n- Source
- arXiv:2611.27671 "Shellsort with O(n log n) Average-Case Complexity", Lemma 2.2
- Verified
- 24 Nov 2026
- Axioms
Quot.soundpropext- Built on 1
- h_chain_lenThe number of valid array indices in an array of length $n$ that belong to the $h$-chain starting at residue $r$, which is…
Read back from the Lean
For all natural numbers $n$, $h$, $r$, and $t$, if $t < \operatorname{h\_chain\_len}(n, h, r)$, then $r + t \cdot h < n$.
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
The proof proceeds by case analysis on whether the degenerate condition $h = 0 \lor n \le r$ holds. If it holds, `h_chain_len` is defined to be $0$, which contradicts the assumption $t < \text{h\_chain\_len}(n, h, r)$ since natural numbers cannot be negative. In the non-degenerate case, the hypothesis simplifies to $t < (n - 1 - r) / h + 1$, which implies $t \le (n - 1 - r) / h$. Multiplying by $h$ and applying the division inequality $((n - 1 - r) / h) \cdot h \le n - 1 - r$ yields $t \cdot h \le n - 1 - r$, from which $r + t \cdot h < n$ follows because $r < n$.
The degenerate condition $h = 0 \lor n \le r$ cannot hold, so we may assume $\neg(h = 0 \lor n \le r)$.
Unfolding the definition of `h_chain_len`, we split into cases depending on whether $h = 0 \lor n \le r$. If this condition holds, `h_chain_len n h r` evaluates to $0$ by `if_pos`, turning the hypothesis into $t < 0$. Since no natural number is strictly less than zero (`Nat.not_lt_zero`), this case produces a contradiction via `absurd`.
uses
if_pos,absurd,Nat.not_lt_zerounfold h_chain_len at ht by_cases hcond : h = 0 ∨ n ≤ r · rw [if_pos hcond] at ht exact absurd ht (Nat.not_lt_zero _)
$t \cdot h \le n - 1 - r$.
Under the assumption $\neg(h = 0 \lor n \le r)$, the definition of `h_chain_len` simplifies by `if_neg` to give $t < (n - 1 - r) / h + 1$, which by linear arithmetic (`omega`) implies $t \le (n - 1 - r) / h$. Multiplying both sides by $h$ via `Nat.mul_le_mul_right` gives $t \cdot h \le ((n - 1 - r) / h) \cdot h$. Because integer division satisfies $((n - 1 - r) / h) \cdot h \le n - 1 - r$ (`Nat.div_mul_le_self`), transitivity of inequality (`le_trans`) yields $t \cdot h \le n - 1 - r$.
uses
if_neg,Nat.mul_le_mul_right,Nat.div_mul_le_self,le_trans· rw [if_neg hcond] at ht have htle : t ≤ (n - 1 - r) / h := by omega have hmul : t * h ≤ ((n - 1 - r) / h) * h := Nat.mul_le_mul_right h htle have hdiv : ((n - 1 - r) / h) * h ≤ n - 1 - r := Nat.div_mul_le_self _ _ have hle : t * h ≤ n - 1 - r := le_trans hmul hdiv
$r + t \cdot h < n$.
From the negated disjunction $\neg(h = 0 \lor n \le r)$, we obtain $\neg(n \le r)$, which implies $r < n$ by `Nat.lt_of_not_le`. Combining this strict upper bound with $t \cdot h \le n - 1 - r$, linear integer arithmetic (`omega`) establishes that $r + t \cdot h < n$.
uses
Nat.lt_of_not_lehave hnr : ¬ n ≤ r := fun h' => hcond (Or.inr h') have hr : r < n := Nat.lt_of_not_le hnr omega
if_pos- If a condition $c$ is true, the conditional expression $\text{if } c \text{ then } t \text{ else } e$ evaluates to $t$.
if_neg- If a condition $c$ is false, the conditional expression $\text{if } c \text{ then } t \text{ else } e$ evaluates to $e$.
Nat.not_lt_zero- No natural number is strictly less than zero: $\neg (a < 0)$ for all $a \in \mathbb{N}$.
absurd- From a proposition and its negation, any conclusion follows (principle of explosion).
Nat.mul_le_mul_right- Multiplying both sides of an inequality of natural numbers on the right by a constant preserves the inequality: if $a \le b$, then $a \cdot k \le b \cdot k$.
Nat.div_mul_le_self- For any natural numbers $m$ and $k$, integer division satisfies $(m / k) \cdot k \le m$.
le_trans- Inequality on natural numbers is transitive: if $a \le b$ and $b \le c$, then $a \le c$.
Nat.lt_of_not_le- For natural numbers, if $m$ is not less than or equal to $n$, then $n < m$.
- The proof relies on the `omega` tactic for linear integer arithmetic in two places: to simplify $t < (n - 1 - r) / h + 1$ to $t \le (n - 1 - r) / h$ (line 8), and to deduce $r + t \cdot h < n$ from $t \cdot h \le n - 1 - r$ and $r < n$ (line 14).
Written by a model (gemini-3.8-flash) from the Lean source alone (no goal states were available). Lean verified the proof; this explanation is a reading aid and is not itself machine-checked.
Lean source view module on GitHub
/-- Valid chain steps produce array indices strictly less than n. -/theorem h_chain_index_lt (n h r : ℕ) (t : ℕ) (ht : t < h_chain_len n h r) : r + t * h < n := by unfold h_chain_len at ht by_cases hcond : h = 0 ∨ n ≤ r · rw [if_pos hcond] at ht exact absurd ht (Nat.not_lt_zero _) · rw [if_neg hcond] at ht have htle : t ≤ (n - 1 - r) / h := by omega have hmul : t * h ≤ ((n - 1 - r) / h) * h := Nat.mul_le_mul_right h htle have hdiv : ((n - 1 - r) / h) * h ≤ n - 1 - r := Nat.div_mul_le_self _ _ have hle : t * h ≤ n - 1 - r := le_trans hmul hdiv have hnr : ¬ n ≤ r := fun h' => hcond (Or.inr h') have hr : r < n := Nat.lt_of_not_le hnr omega