h_chain_pos_lt
For any index $i$ in an array of length $n$ and any positive step $h$, the quotient $i / h$ is strictly less than the length of the $h$-chain of residue $i \pmod h$.
Statement
theorem h_chain_pos_lt (n h : ℕ) (hpos : 0 < h) (i : Fin n) : i.val / h < h_chain_len n h (i.val % h)- 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$ and $h$, given a proof that $0 < h$, and for every element $i$ of Fin n (i.e., a natural number $i < n$), the integer quotient $i / h$ is strictly less than h_chain_len n h (i % h).
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
To show that the chain position i / h is strictly less than the chain length for residue r = i % h, we first observe that h > 0 and r ≤ i < n, so the definition of h_chain_len evaluates to (n - 1 - r) / h + 1. The division algorithm expresses i as h * (i / h) + r; since i ≤ n - 1, subtracting r gives (i / h) * h ≤ n - 1 - r. Dividing by h yields i / h ≤ (n - 1 - r) / h, from which i / h < (n - 1 - r) / h + 1 follows immediately.
Setting r = i % h, we have r ≤ i and therefore r < n.
We set r = i % h. By Nat.mod_le, the remainder satisfies r ≤ i. Since i < n by the index property i.isLt, combining these inequalities via lt_of_le_of_lt establishes r < n.
uses
Nat.mod_le,lt_of_le_of_ltset r := i.val % h have hr_le : r ≤ i.val := Nat.mod_le _ _ have hr_lt_n : r < n := lt_of_le_of_lt hr_le i.isLt
Neither h = 0 nor n ≤ r holds.
We refute the disjunction h = 0 ∨ n ≤ r: the case h = 0 contradicts hpos (0 < h) by Nat.ne_of_gt, and the case n ≤ r contradicts r < n by Nat.not_le_of_gt.
uses
Nat.ne_of_gt,Nat.not_le_of_gthave hif : ¬ (h = 0 ∨ n ≤ r) := by rintro (h0 | hn) · exact (Nat.ne_of_gt hpos) h0 · exact absurd hn (Nat.not_le_of_gt hr_lt_n)
The goal reduces to i / h < (n - 1 - r) / h + 1.
Unfolding the definition h_chain_len yields a conditional on h = 0 ∨ n ≤ r. Because this condition was just proved false, rewriting with if_neg selects the alternative branch, (n - 1 - r) / h + 1.
uses
h_chain_len,if_negrw [h_chain_len, if_neg hif](i / h) * h ≤ n - 1 - r.
From Nat.div_add_mod and Nat.mul_comm, we have h * (i / h) + r = i. Since i < n, Nat.le_sub_one_of_lt gives i ≤ n - 1, and so h * (i / h) + r ≤ n - 1. Subtracting r from both sides via Nat.le_sub_of_add_le and commuting multiplication with Nat.mul_comm yields (i / h) * h ≤ n - 1 - r.
uses
Nat.div_add_mod,Nat.mul_comm,Nat.le_sub_one_of_lt,Nat.le_sub_of_add_lehave hkey : i.val / h * h ≤ n - 1 - r := by have h1 : h * (i.val / h) + r = i.val := by simpa [r, Nat.mul_comm] using Nat.div_add_mod i.val h have h2 : h * (i.val / h) + r ≤ n - 1 := by rw [h1]; exact Nat.le_sub_one_of_lt i.isLt have h3 : h * (i.val / h) ≤ n - 1 - r := Nat.le_sub_of_add_le h2 rwa [Nat.mul_comm] at h3
i / h < (n - 1 - r) / h + 1.
Applying Nat.le_div_iff_mul_le to the previous inequality yields i / h ≤ (n - 1 - r) / h. From this, the linear arithmetic tactic omega concludes i / h < (n - 1 - r) / h + 1.
uses
Nat.le_div_iff_mul_lehave := (Nat.le_div_iff_mul_le hpos).mpr hkey omega
Nat.mod_le- The remainder of division of x by y is at most x.
lt_of_le_of_lt- If a ≤ b and b < c, then a < c.
Nat.ne_of_gt- If a > b, then a ≠ b.
Nat.not_le_of_gt- If n > m, then n ≤ m is false.
if_neg- If c is false, then (if c then t else e) = e.
h_chain_len- The definition of the chain length: (n - 1 - r) / h + 1 when h > 0 and r < n, and 0 otherwise.
Nat.mul_comm- Multiplication on natural numbers is commutative: n * m = m * n.
Nat.div_add_mod- The division theorem for natural numbers: n * (m / n) + m % n = m.
Nat.le_sub_one_of_lt- If a < b for natural numbers, then a ≤ b - 1.
Nat.le_sub_of_add_le- If a + b ≤ c, then a ≤ c - b.
Nat.le_div_iff_mul_le- For k > 0, x ≤ y / k is equivalent to x * k ≤ y.
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.
/-- The chain position i / h is strictly less than the chain length. -/theorem h_chain_pos_lt (n h : ℕ) (hpos : 0 < h) (i : Fin n) : i.val / h < h_chain_len n h (i.val % h) := by set r := i.val % h have hr_le : r ≤ i.val := Nat.mod_le _ _ have hr_lt_n : r < n := lt_of_le_of_lt hr_le i.isLt have hif : ¬ (h = 0 ∨ n ≤ r) := by rintro (h0 | hn) · exact (Nat.ne_of_gt hpos) h0 · exact absurd hn (Nat.not_le_of_gt hr_lt_n) rw [h_chain_len, if_neg hif] have hkey : i.val / h * h ≤ n - 1 - r := by have h1 : h * (i.val / h) + r = i.val := by simpa [r, Nat.mul_comm] using Nat.div_add_mod i.val h have h2 : h * (i.val / h) + r ≤ n - 1 := by rw [h1]; exact Nat.le_sub_one_of_lt i.isLt have h3 : h * (i.val / h) ≤ n - 1 - r := Nat.le_sub_of_add_le h2 rwa [Nat.mul_comm] at h3 have := (Nat.le_div_iff_mul_le hpos).mpr hkey omega