The difference counting function
DefinitionLL_Decomp1537b_I1For natural numbers and an integer , let be the number of natural numbers with and , that is, the number of pairs with .
import Mathlib namespace LL_Decomp1537b open Finset Real def I1 (N N1 : ℕ) (h : ℤ) : ℕ := ((Ioo N1 N).filter (fun m : ℕ => (N1 : ℤ) < (m : ℤ) - h ∧ (m : ℤ) - h < N)).card end LL_Decomp1537b
Read-back
What the Lean code literally says, in plain math · claude-haiku
counts the natural numbers with and, in the integers, . Here are natural numbers, is an integer, and is cast to before subtracting . The result is a natural number, so it is never negative.
Both conditions hold, so ranges over integers strictly between and . Since , is automatically natural. Therefore
The max with covers the empty case, which occurs when , including every . No division or truncated subtraction occurs in the definition, so there are no junk values.
Surprising: the sign of is irrelevant, since shrinks the window by in either direction.
Confirmed by the mission captain (proposal self-audit).