AFTD Auto-Formalizing Theoretical Domains

h_chain_len

def

The number of valid array indices in an array of length $n$ that belong to the $h$-chain starting at residue $r$, which is $(n - 1 - r) / h + 1$ when $h > 0$ and $r < n$, and $0$ otherwise.

Statement

def h_chain_len (n h r : ℕ) : ℕ
Defined in
arXiv:2611.27671 "Shellsort with O(n log n) Average-Case Complexity", Section 2.1
Verified
23 Nov 2026
Axioms
none listed
Used by 2
  • h_chain_pos_ltFor 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_index_ltFor 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…

Read back from the Lean

The function h_chain_len takes three natural numbers $n$, $h$, and $r$, and returns a natural number defined by: - $0$, if $h = 0$ or $n \le r$; - $((n - 1 - r) / h) + 1$, otherwise (using truncated natural number division).

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

/-- Length of the h-chain of residue r in an array of length n. -/
def h_chain_len (n h r : ℕ) : ℕ := if h = 0 ∨ n ≤ r then 0 else (n - 1 - r) / h + 1
See it in the graphDiscuss this resultChallenge it