shellsort_h_pass
The h-pass of Shellsort on an array A : Fin n → α over a linear order: for each index i, form the h-chain of i, i.e. the list of the values A j at the indices j with j % h = i % h, in increasing order of j (List.finRange n filtered, mapped by A); sort it in non-decreasing order (List.insertionSort (· ≤ ·)); the new value at i is the entry at position i / h of the sorted list, which is the position of i in its chain (List.getD with the unreachable default A i). So every chain {r, r+h, r+2h, ...} is sorted in place. For h = 0 every chain is a single index and the pass is the identity.
Statement
def shellsort_h_pass {n : ℕ} {α : Type*} [LinearOrder α] (h : ℕ) (A : Fin n → α) : Fin n → α
- Defined in
- arXiv:2611.27671, Section 2 (the h-pass P_h sorts each h-chain).
- Verified
- 27 Nov 2026
- Axioms
- none listed
- Built on 2
- TotalPreorderA total preorder: a preorder where
≤is total (complete). This is weaker thanLinearOrder— it does NOT require antisymmetry or… - LinearOrder.toTotalPreorderEvery
LinearOrderis aTotalPreorder.
- TotalPreorderA total preorder: a preorder where
- Used by 1
- shellsort_h_pass_exampleSanity check of the h-pass: the 2-pass of the array 5, 4, 3, 2, 1, 0 sorts the even positions (values 5, 3, 1) and the odd positions (4,…
Read back from the Lean
shellsort_h_pass defines a function which, given a natural number n, a linearly ordered type α, a natural number h, and an array A : Fin n → α, produces a new array of type Fin n → α. For each index i : Fin n, its value is obtained by:
1. Filtering List.finRange n to those indices j : Fin n such that j.val % h = i.val % h;
2. Mapping A over these indices;
3. Sorting the resulting list of values in non-decreasing order using List.insertionSort (· ≤ ·);
4. Taking the element at index i.val / h from this sorted list, with default fallback A i if out of bounds.
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
def shellsort_h_pass {n : ℕ} {α : Type*} [LinearOrder α] (h : ℕ) (A : Fin n → α) : Fin n → α := fun i => ((((List.finRange n).filter (fun j => j.val % h = i.val % h)).map A).insertionSort (· ≤ ·)).getD (i.val / h) (A i)