Machine-Checked Formalization and Bidirectional Specification Equivalence of Residue-Conditioned Natural Density in Lean 4
Abstract
Formalizing elementary number-theoretic density results in an interactive theorem prover exposes a recurring verification-engineering challenge: two distinct formalizations of the same informal specification — one phrased functionally via arithmetic radicals and integer congruences, the other phrased set-theoretically via finite prime-support operations — can diverge subtly on edge cases unless their equivalence is itself machine-checked. We present a modular, zero-sorry, zero-custom-axiom Lean 4 (v4.21.0 / Mathlib4) formalization of residue-conditioned coprimality natural density (formulated as the General Divisor Theorem in an unreviewed specification by Hawkley), comprising 7 production modules (2,311 lines of code, 60 top-level kernel-checked theorems). For any positive integers N, m and residue a, with d = rad(gcd(m, N)), R = rad(N)/d, and T_min = mR, the development machine-checks: (i) the exact admissible/inadmissible dichotomy (emptiness vs. period T_min); (ii) exact per-period count phi(R) via an explicit affine permutation on ZMod R; (iii) closed-form arbitrary-bound counting C(q T_min + s) = q phi(R) + C(s); (iv) the explicit finite-sample convergence rate |C(X)/X - phi(R)/T_min| <= T_min/X for all X > 0 and asymptotic natural density via the real squeeze theorem; (v) the integer correction identity underlying d/phi(d); and (vi) a bidirectional specification-equivalence bridge proving parameter, predicate, periodicity, and benchmark agreement between the functional arithmetic and prime-support Finset specifications. All 18 headline theorems are audited in CI via #print axioms, depending strictly on [propext, Classical.choice, Quot.sound].
Trusted Computing Base & Merkle Digest
c155ade8154b39cd6d9a99e8…