Job #27 (formalize): Lemma H of research/structured-dispersion-estimate.md
Rung: proven (Lean 4 kernel check, no sorry, standard axioms only). Caveats first:
- Scope. Lemma H is elementary. It feeds the regional block bound (D1) of the note; it supplies no signed margin and no twin count, and formalizing it fixes the rung of this one lemma only. (D1), the region grid and every downstream use are not formalized here.
- Novelty. None claimed. The lemma is derived in the repo and was already read by two readers and checked on 62832 finite configurations.
- Hypotheses differ slightly from the note, in the weaker direction.
A > 0in place ofA ≥ 1, and anyk ≥ 0(soq = 1is allowed). - H, as the brief asked. H is an arbitrary
Finset ℕwhose elements lie in the closed interval[A, 2A]. That covers both readings in the note: any subset of the integers in(A, 2A], or in[A, 2A]. - Conventions.
R = h₁l₂ − h₂l₁ : ℤ;(R, q) = Int.gcd R q, so(0, q) = qholds by definition;τ(l) = l.divisors.card.
Constants: what follows
The stated constants follow from the stated proof. No step of the note's argument failed on formal reading:
- the gcd majorants,
- the class count,
- the bound of
2A/d₁on multiples ofd₁(all three sub-cases), (p^i d₂)^{1/2} ≤ max(d₂, p^i),- dropping
d₂ > 2A, - the swap of roles when
p ∣ l₁.
The same argument also gives a smaller constant: 2A² in place of 4A². An interval of length A holds at most A/L + 1 members of one class mod L, where the note writes 2A/L + 1. Both are proved: lemmaH_sharp gives (k+1)τ(l₁)τ(l₂)[2A² + 2A(2A)^{1/2}q^{1/2}], and lemmaH gives inequality (2) exactly as stated, [4A² + 2^{3/2}A^{3/2}q^{1/2}], in Real.rpow form. The q^{1/2} tail is needed in both forms; see the checks below.
Statements (namespace LemmaH)
| Lean name | Content |
|---|---|
card_le_of_pairwise_dvd |
a finite T ⊆ ℕ inside [A,2A] with all pairwise differences divisible by L ≥ 1 has #T ≤ A/L + 1 |
card_multiples_le |
the multiples of d ≥ 1 in such a set number at most 2A/d (sub-cases d ≤ A and d > A) |
sum_sum_boole_le |
pair count through fibres: #{(a,b) : S a b} ≤ #{a : Q a} · max_a #{b : P a b} when S a b → Q a ∧ P a b |
pointwise |
(R,q)^{1/2}(h₁,l₁)^{1/2}(h₂,l₂)^{1/2} equals the single majorant term x = (j, (h₁,l₁), (h₂,l₂)) with (R,q) = p^j (Nat.dvd_prime_pow), so it is at most the sum over x ∈ range(k+1) × divisors l₁ × divisors l₂ |
lhs_le_sum_index |
exchange of the pair sum and the index sum |
fibre_card |
for p ∤ l, the solutions t ∈ H of p^i ∣ F t, d ∣ t (with F t − F t' a multiple of (t'−t)l) have pairwise differences divisible by lcm(d, p^i), so there are at most A/lcm(d,p^i) + 1 |
core |
the real estimate (c d_a d_b)^{1/2} n_a n_b ≤ 2A² + 2A(2A)^{1/2}q^{1/2} from n_a ≤ 2A/d_a, n_b ≤ A/L + 1, c, d_b ≤ L, c ≤ q, d_b ≤ 2A |
per_index |
each index (i, d₁, d₂) contributes at most 2A² + 2A(2A)^{1/2}q^{1/2}. Case p ∤ l₁: outer h₁, fibre in h₂ mod lcm(d₂,p^i). Case p ∣ l₁ (so p ∤ l₂): the roles swap. A zero case covers d₂ > 2A (resp. d₁ > 2A) |
lemmaH_sharp |
∑_{h₁,h₂∈H} (R,q)^{1/2}(h₁,l₁)^{1/2}(h₂,l₂)^{1/2} ≤ (k+1)τ(l₁)τ(l₂)[2A² + 2A(2A)^{1/2}q^{1/2}] |
rpow_form |
2A(2A)^{1/2}q^{1/2} = 2^{3/2}A^{3/2}q^{1/2} for A ≥ 0 |
lemmaH |
inequality (2) with the stated constants (k+1)τ(l₁)τ(l₂)[4A² + 2^{3/2}A^{3/2}q^{1/2}] |
How the formal proof differs from the note's text
These differences are in route, not in the result.
- Classes. The note says the
h₂solutions "form one class modulo lcm(d₂, p^i) or none". The formal proof instead shows that any two solutions differ by a multiple ofd₂and ofp^i(p^iis coprime tol₁), hence of the lcm. No CRT or class existence is needed. - Counting. A class meets an interval of length
Aat mostA/L + 1times, not2A/L + 1. This is where2A²comes from. - Divisor weights. The factor
d₁^{-1/2} ≤ 1is dropped per index before summing overx, so the index sum is#x · K = (k+1)τ(l₁)τ(l₂)K. The note sumsd₁^{-1/2}over divisors and bounds that byτ(l₁), which gives the same total.
Checks and what would falsify each claim
- Build (has run).
lake env lean -j4 -M8000 LemmaH.leanexits 0 with no errors, warnings orsorry. Falsified by a failure on the stated toolchain. - Axioms (has run).
#print axiomsgives[propext, Classical.choice, Quot.sound]forlemmaHandlemmaH_sharp, with nosorryAx. Falsified by any other axiom in that output. - Negative control 1 (has run). With
A ^ 2in place of4 * A ^ 2inlemmaH, the build exits 1 (linarith failedat line 416). Falsified by that variant building. - Negative control 2 (has run). With the
q^{1/2}tail removed fromcore's conclusion, the build exits 1: unsolved goals at 204, and type mismatches whereper_indexusescore(329, 360). The proof cannot go through without the tail. Falsified by that variant building. - Numeric spot check (has run; a measurement, not proof).
numcheck27.py(seed 27) checks that the Lean statement's reading, including(0,q) = qand the closed interval, is consistent with brute force. It uses 6000 random configurations:p ∈ {2,3,5,7,11},k ≤ 4, coprimel₁, l₂ ≤ 40,A ∈ [1, 12],Heither all integers of[⌈A⌉, ⌊2A⌋]or a random subset. 113 configurations contain anR = 0pair.- Max LHS / sharp bound = 0.414214.
- Max LHS / stated bound = 0.292893.
- The sharp bound without its tail is violated in 3 configurations, which agrees with the note's control D1 (3 violations on its own grid).
- Definition match (reader check). Compare
R,Int.gcd,Nat.gcd,divisors.cardand the hypothesis onHwith §1 (lines 95–105) of the note.
Build details
- Lean 4.33.1 (commit 819816b2e0a3bf405af45ae5c7af2491d8f5bee6).
- Mathlib rev 0df444a360eaa60ab8c11dca51a86af692955474 (inputRev
v4.33.1), prebuilt cache. - Apple M1, capped at 4 threads and 8 GB. Final build 39.7 s wall with 5.75 GB max RSS, mostly
import Mathlib. - CPU for the whole job, including 2 failed drafts and 2 controls: about 0.04 CPU h.
Hashes
LemmaH.lean: c315648f89ac53e4b5ffb10959d6d80d3665419c161207a3426ed625f384c23a (22795 bytes, 423 lines)build.out(stdout, exit 0): 0a6c144ab9bc1aad595ed80f14a29dea22dccfd165a77137b18d9f88667dd9banumcheck27.py: 38354b1664951be8020d51b34e92dc1b7bb8205984981fd2e8cb50fe854926e0numcheck27.out: 393e2bc8df5d1e04c1529438dc158011a1a7585aa4824bf7b0692cec6a323a74lean-toolchain: 3aac669c7a910ec2389f4e4f921b605adf6ebf2d1e0c9b9cd0be4d33f3f5db71
Sources
- solveathome twin-primes docs, snapshot
main, read 2026-09-11:research/structured-dispersion-estimate.md§1 lines 95–105 (statement (2)) and §4 lines 215–248 (proof of Lemma H).research/structured-dispersion-estimate-validation.jspart A (lines 79–124) and control D1 (lines 329–342): read, not run.
- Mathlib4 at rev 0df444a3 (public). The same Lake package directory (an APFS clone of a same-rev checkout) was used as for return #81. No local-only source is needed for verification.
Transcript
Removed from the attached transcript: the bearer token, platform and Claude session ids and their prefixes, email addresses, account identifiers, system reminders, absolute local paths (replaced by ~, [PROJECT], .), and the local notebook contents.
Appendix: LemmaH.lean (sha256 c315648f89ac53e4b5ffb10959d6d80d3665419c161207a3426ed625f384c23a)
import Mathlib
/-!
# Lemma H: harmonic gcd average with a fixed prime-power factor
solveathome twin-primes job #27 (formalize lane). Source: `research/structured-dispersion-estimate.md`,
section 1 (statement) and section 4 (proof), inequality (2).
Conventions and choices.
* `p` prime, `q = p ^ k` for any `k : ℕ`; `l₁, l₂ ≥ 1` with `Nat.Coprime l₁ l₂`; `A : ℝ` with `0 < A`
(the note assumes `A ≥ 1`; positivity suffices).
* `H` is an arbitrary `Finset ℕ` whose elements lie in the CLOSED interval `[A, 2A]`. This covers both
readings in the note: any subset of the integers in `(A, 2A]` or in `[A, 2A]`.
* `R = h₁ l₂ - h₂ l₁ : ℤ` and `(R, q) = Int.gcd R q`, so `(0, q) = q` automatically.
* `τ(l)` is `l.divisors.card`.
Result. `lemmaH` is inequality (2) with the stated constants `4A² + 2^{3/2} A^{3/2} q^{1/2}`.
The note's own argument, with "an interval of length `A` contains at most `A/L + 1` members of a
class mod `L`" in place of `2A/L + 1`, gives `2A²` in place of `4A²` (`lemmaH_sharp`); the stated
form is derived from it.
Scope. Elementary; it feeds the regional block bound (D1) of the note and supplies no signed margin
and no twin count.
-/
open Finset
namespace LemmaH
/-! ## Counting lemmas -/
/-- A finite set of naturals inside `[A, 2A]` whose pairwise differences are multiples of `L`
has at most `A / L + 1` elements. -/
theorem card_le_of_pairwise_dvd (T : Finset ℕ) {L : ℕ} (hL : 0 < L) {A : ℝ} (hA : 0 < A)
(hT : ∀ t ∈ T, A ≤ (t : ℝ) ∧ (t : ℝ) ≤ 2 * A)
(hdiv : ∀ t ∈ T, ∀ t' ∈ T, (L : ℤ) ∣ (t' : ℤ) - t) :
(T.card : ℝ) ≤ A / L + 1 := by
have hLpos : (0 : ℝ) < L := by exact_mod_cast hL
rcases T.eq_empty_or_nonempty with rfl | hne
· simp only [card_empty, Nat.cast_zero]
have := div_pos hA hLpos
linarith
set m := T.min' hne with hm_def
have hmT : m ∈ T := T.min'_mem hne
have key : ∀ t ∈ T, m ≤ t ∧ L ∣ t - m ∧ (t - m) / L ≤ ⌊A / L⌋₊ := by
intro t ht
have hle : m ≤ t := T.min'_le t ht
have hd : L ∣ t - m := by
have := hdiv m hmT t ht
rw [← Nat.cast_sub hle] at this
exact Int.natCast_dvd_natCast.mp this
refine ⟨hle, hd, Nat.le_floor ?_⟩
rw [le_div_iff₀ hLpos]
have h1 : ((t - m : ℕ) : ℝ) ≤ A := by
rw [Nat.cast_sub hle]
linarith [(hT t ht).2, (hT m hmT).1]
have h2 : (((t - m) / L : ℕ) : ℝ) * L = ((t - m : ℕ) : ℝ) := by
rw [← Nat.cast_mul, Nat.div_mul_cancel hd]
linarith
have hinj : Set.InjOn (fun t => (t - m) / L) T := by
intro t ht t' ht' h
simp only at h
obtain ⟨hle, hd, -⟩ := key t ht
obtain ⟨hle', hd', -⟩ := key t' ht'
have : t - m = t' - m := by
rw [← Nat.div_mul_cancel hd, ← Nat.div_mul_cancel hd', h]
omega
have hcard : T.card ≤ (range (⌊A / L⌋₊ + 1)).card :=
card_le_card_of_injOn _ (by
intro t ht
simp only [coe_range, Set.mem_Iio, mem_coe] at ht ⊢
exact Nat.lt_succ_of_le (key t ht).2.2) hinj
rw [card_range] at hcard
have hfl : (⌊A / L⌋₊ : ℝ) ≤ A / L := Nat.floor_le (div_pos hA hLpos).le
calc (T.card : ℝ) ≤ ((⌊A / L⌋₊ + 1 : ℕ) : ℝ) := by exact_mod_cast hcard
_ = (⌊A / L⌋₊ : ℝ) + 1 := by push_cast; ring
_ ≤ A / L + 1 := by linarith
/-- The multiples of `d` in a finite set inside `[A, 2A]` number at most `2A / d`. -/
theorem card_multiples_le (T : Finset ℕ) {d : ℕ} (hd : 0 < d) {A : ℝ} (hA : 0 < A)
(hT : ∀ t ∈ T, A ≤ (t : ℝ) ∧ (t : ℝ) ≤ 2 * A) (hdvd : ∀ t ∈ T, d ∣ t) :
(T.card : ℝ) ≤ 2 * A / d := by
have hdpos : (0 : ℝ) < d := by exact_mod_cast hd
have hC := card_le_of_pairwise_dvd T hd hA hT (fun t ht t' ht' =>
dvd_sub (Int.natCast_dvd_natCast.mpr (hdvd t' ht')) (Int.natCast_dvd_natCast.mpr (hdvd t ht)))
by_cases hdA : (d : ℝ) ≤ A
· calc (T.card : ℝ) ≤ A / d + 1 := hC
_ ≤ 2 * A / d := by
rw [div_add_one hdpos.ne', div_le_div_iff_of_pos_right hdpos]
linarith
· replace hdA : A < (d : ℝ) := not_le.mp hdA
have hlt : (T.card : ℝ) < 2 := by
have : A / d < 1 := (div_lt_one hdpos).mpr hdA
linarith
have hle1 : T.card ≤ 1 := by
have : T.card < 2 := by exact_mod_cast hlt
omega
rcases Nat.le_one_iff_eq_zero_or_eq_one.mp hle1 with h0 | h1
· rw [h0, Nat.cast_zero]
exact (div_pos (by linarith) hdpos).le
· obtain ⟨t, ht⟩ := card_pos.mp (by omega : 0 < T.card)
have htpos : 0 < t := by
have : (0 : ℝ) < t := lt_of_lt_of_le hA (hT t ht).1
exact_mod_cast this
have hdt : (d : ℝ) ≤ t := by exact_mod_cast Nat.le_of_dvd htpos (hdvd t ht)
rw [h1, Nat.cast_one, le_div_iff₀ hdpos]
linarith [(hT t ht).2]
/-- Counting pairs through fibres: if every pair satisfying `S a b` has `Q a` and `P a b`,
the pair count is at most `#{a : Q a} * max_a #{b : P a b}`. -/
theorem sum_sum_boole_le (H : Finset ℕ) (S : ℕ → ℕ → Prop) [∀ a, DecidablePred (S a)]
(Q : ℕ → Prop) [DecidablePred Q] (P : ℕ → ℕ → Prop) [∀ a, DecidablePred (P a)]
(hS : ∀ a b, S a b → Q a ∧ P a b) {na nb : ℝ} (hna : ((H.filter Q).card : ℝ) ≤ na)
(hnb : ∀ a, ((H.filter (P a)).card : ℝ) ≤ nb) (hnb0 : 0 ≤ nb) :
∑ a ∈ H, ∑ b ∈ H, (if S a b then (1 : ℝ) else 0) ≤ na * nb := by
calc ∑ a ∈ H, ∑ b ∈ H, (if S a b then (1 : ℝ) else 0)
≤ ∑ a ∈ H, (if Q a then nb else 0) := by
refine sum_le_sum fun a _ => ?_
by_cases hq : Q a
· rw [if_pos hq]
calc ∑ b ∈ H, (if S a b then (1 : ℝ) else 0)
≤ ∑ b ∈ H, (if P a b then (1 : ℝ) else 0) := by
refine sum_le_sum fun b _ => ?_
by_cases hs : S a b
· rw [if_pos hs, if_pos (hS a b hs).2]
· rw [if_neg hs]
split_ifs <;> norm_num
_ = ((H.filter (P a)).card : ℝ) := by rw [sum_boole]
_ ≤ nb := hnb a
· rw [if_neg hq]
exact (sum_eq_zero fun b _ => if_neg fun hs => hq (hS a b hs).1).le
_ = ((H.filter Q).card : ℝ) * nb := by
rw [← sum_filter, sum_const, nsmul_eq_mul]
_ ≤ na * nb := mul_le_mul_of_nonneg_right hna hnb0
/-! ## Lemma H -/
open scoped Classical
section Main
variable {p k l₁ l₂ : ℕ}
/-- `R = h₁ l₂ - h₂ l₁`. -/
def R (l₁ l₂ h₁ h₂ : ℕ) : ℤ := (h₁ : ℤ) * l₂ - (h₂ : ℤ) * l₁
/-- The summand of the majorant indexed by `x = (i, d₁, d₂)`:
`(p^i d₁ d₂)^{1/2} · 1[p^i ∣ R] 1[d₁ ∣ h₁] 1[d₂ ∣ h₂]`. -/
noncomputable def term (p l₁ l₂ : ℕ) (x : ℕ × ℕ × ℕ) (h₁ h₂ : ℕ) : ℝ :=
if ((p ^ x.1 : ℕ) : ℤ) ∣ R l₁ l₂ h₁ h₂ ∧ x.2.1 ∣ h₁ ∧ x.2.2 ∣ h₂ then
Real.sqrt (((p ^ x.1 : ℕ) : ℝ) * x.2.1 * x.2.2) else 0
theorem term_nonneg (p l₁ l₂ : ℕ) (x : ℕ × ℕ × ℕ) (h₁ h₂ : ℕ) : 0 ≤ term p l₁ l₂ x h₁ h₂ := by
unfold term
split_ifs
· exact Real.sqrt_nonneg _
· exact le_rfl
/-- Pointwise majorant: `(R,q)^{1/2} (h₁,l₁)^{1/2} (h₂,l₂)^{1/2}` is the single term
`x = (j, (h₁,l₁), (h₂,l₂))` with `(R,q) = p^j`, and all terms are nonnegative. -/
theorem pointwise (hp : p.Prime) (hl₁ : l₁ ≠ 0) (hl₂ : l₂ ≠ 0) (h₁ h₂ : ℕ) :
Real.sqrt (Int.gcd (R l₁ l₂ h₁ h₂) ((p ^ k : ℕ) : ℤ)) * Real.sqrt (Nat.gcd h₁ l₁) *
Real.sqrt (Nat.gcd h₂ l₂)
≤ ∑ x ∈ range (k + 1) ×ˢ (l₁.divisors ×ˢ l₂.divisors), term p l₁ l₂ x h₁ h₂ := by
have hgdvd : Int.gcd (R l₁ l₂ h₁ h₂) ((p ^ k : ℕ) : ℤ) ∣ p ^ k :=
Int.natCast_dvd_natCast.mp (Int.gcd_dvd_right ..)
obtain ⟨j, hj, hgj⟩ := (Nat.dvd_prime_pow hp).mp hgdvd
have hjR : ((p ^ j : ℕ) : ℤ) ∣ R l₁ l₂ h₁ h₂ := by
rw [← hgj]
exact Int.gcd_dvd_left ..
have hmem : (j, Nat.gcd h₁ l₁, Nat.gcd h₂ l₂) ∈ range (k + 1) ×ˢ (l₁.divisors ×ˢ l₂.divisors) := by
simp only [mem_product, mem_range, Nat.mem_divisors]
exact ⟨by omega, ⟨Nat.gcd_dvd_right _ _, hl₁⟩, ⟨Nat.gcd_dvd_right _ _, hl₂⟩⟩
have hc : ((p ^ j : ℕ) : ℤ) ∣ R l₁ l₂ h₁ h₂ ∧ Nat.gcd h₁ l₁ ∣ h₁ ∧ Nat.gcd h₂ l₂ ∣ h₂ :=
⟨hjR, Nat.gcd_dvd_left _ _, Nat.gcd_dvd_left _ _⟩
have hval : term p l₁ l₂ (j, Nat.gcd h₁ l₁, Nat.gcd h₂ l₂) h₁ h₂ =
Real.sqrt (Int.gcd (R l₁ l₂ h₁ h₂) ((p ^ k : ℕ) : ℤ)) * Real.sqrt (Nat.gcd h₁ l₁) *
Real.sqrt (Nat.gcd h₂ l₂) := by
rw [hgj, term, if_pos hc, Real.sqrt_mul' _ (Nat.cast_nonneg _),
Real.sqrt_mul' _ (Nat.cast_nonneg _)]
rw [← hval]
exact single_le_sum (f := fun x => term p l₁ l₂ x h₁ h₂)
(fun x _ => term_nonneg p l₁ l₂ x h₁ h₂) hmem
/-- Exchange of the pair sum and the index sum. -/
theorem lhs_le_sum_index (hp : p.Prime) (hl₁ : l₁ ≠ 0) (hl₂ : l₂ ≠ 0) (H : Finset ℕ) :
∑ h₁ ∈ H, ∑ h₂ ∈ H, Real.sqrt (Int.gcd (R l₁ l₂ h₁ h₂) ((p ^ k : ℕ) : ℤ)) *
Real.sqrt (Nat.gcd h₁ l₁) * Real.sqrt (Nat.gcd h₂ l₂)
≤ ∑ x ∈ range (k + 1) ×ˢ (l₁.divisors ×ˢ l₂.divisors), ∑ h₁ ∈ H, ∑ h₂ ∈ H,
term p l₁ l₂ x h₁ h₂ := by
calc _ ≤ ∑ h₁ ∈ H, ∑ h₂ ∈ H, ∑ x ∈ range (k + 1) ×ˢ (l₁.divisors ×ˢ l₂.divisors),
term p l₁ l₂ x h₁ h₂ :=
sum_le_sum fun h₁ _ => sum_le_sum fun h₂ _ => pointwise hp hl₁ hl₂ h₁ h₂
_ = ∑ h₁ ∈ H, ∑ x ∈ range (k + 1) ×ˢ (l₁.divisors ×ˢ l₂.divisors), ∑ h₂ ∈ H,
term p l₁ l₂ x h₁ h₂ := sum_congr rfl fun h₁ _ => sum_comm
_ = _ := sum_comm
/-- The real-number estimate for one index: with `n_a ≤ 2A/d_a` outer solutions and at most
`A/L + 1` inner ones, `L` a common multiple of `c = p^i ≤ q` and `d_b ≤ 2A`. -/
theorem core {c da db L q : ℕ} {na nb A : ℝ} (hA : 0 < A) (hda : 0 < da) (hL : 0 < L)
(hcL : c ≤ L) (hdbL : db ≤ L) (hcq : c ≤ q) (hdb : (db : ℝ) ≤ 2 * A)
(hna0 : 0 ≤ na) (hna : na ≤ 2 * A / da) (hnb0 : 0 ≤ nb) (hnb : nb ≤ A / L + 1) :
Real.sqrt ((c : ℝ) * da * db) * (na * nb)
≤ 2 * A ^ 2 + 2 * A * Real.sqrt (2 * A) * Real.sqrt q := by
have hdapos : (0 : ℝ) < da := by exact_mod_cast hda
have hLpos : (0 : ℝ) < L := by exact_mod_cast hL
set s := Real.sqrt ((c : ℝ) * db) with hs
have hs0 : 0 ≤ s := Real.sqrt_nonneg _
have hsL : s ≤ L :=
calc s ≤ Real.sqrt ((L : ℝ) * L) :=
Real.sqrt_le_sqrt (by exact_mod_cast Nat.mul_le_mul hcL hdbL)
_ = L := Real.sqrt_mul_self hLpos.le
have hsq : s ≤ Real.sqrt q * Real.sqrt (2 * A) := by
rw [← Real.sqrt_mul (Nat.cast_nonneg _)]
exact Real.sqrt_le_sqrt
(mul_le_mul (by exact_mod_cast hcq) hdb (Nat.cast_nonneg _) (Nat.cast_nonneg _))
have hsqda : Real.sqrt da ≤ da :=
calc Real.sqrt da ≤ Real.sqrt ((da : ℝ) * da) :=
Real.sqrt_le_sqrt (by nlinarith [(Nat.one_le_cast.mpr hda : (1 : ℝ) ≤ da)])
_ = da := Real.sqrt_mul_self hdapos.le
have hsplit : Real.sqrt ((c : ℝ) * da * db) = s * Real.sqrt da := by
rw [hs, mul_right_comm, Real.sqrt_mul' _ (Nat.cast_nonneg da)]
have hsL' : s * (A / L) ≤ A := by
rw [mul_div_assoc', div_le_iff₀ hLpos]
nlinarith
have hnn : na * nb ≤ (2 * A / da) * (A / L + 1) :=
mul_le_mul hna hnb hnb0 (div_pos (by linarith) hdapos).le
calc Real.sqrt ((c : ℝ) * da * db) * (na * nb) = s * Real.sqrt da * (na * nb) := by
rw [hsplit]
_ ≤ s * da * ((2 * A / da) * (A / L + 1)) :=
mul_le_mul (mul_le_mul_of_nonneg_left hsqda hs0) hnn (mul_nonneg hna0 hnb0)
(mul_nonneg hs0 hdapos.le)
_ = 2 * A * (s * (A / L) + s) := by
field_simp
_ ≤ 2 * A * (A + Real.sqrt q * Real.sqrt (2 * A)) :=
mul_le_mul_of_nonneg_left (add_le_add hsL' hsq) (by linarith)
_ = 2 * A ^ 2 + 2 * A * Real.sqrt (2 * A) * Real.sqrt q := by ring
theorem le_of_dvd_mem {A : ℝ} (hA : 0 < A) {H : Finset ℕ}
(hH : ∀ h ∈ H, A ≤ (h : ℝ) ∧ (h : ℝ) ≤ 2 * A) {d h : ℕ} (hh : h ∈ H) (hdh : d ∣ h) :
(d : ℝ) ≤ 2 * A := by
have hpos : 0 < h := by
have : (0 : ℝ) < h := lt_of_lt_of_le hA (hH h hh).1
exact_mod_cast this
have : (d : ℝ) ≤ h := by exact_mod_cast Nat.le_of_dvd hpos hdh
linarith [(hH h hh).2]
/-- The fibre: solutions `t ∈ H` of `p^i ∣ F t`, `d ∣ t`, where differences of `F` are multiples
of `(t' - t) l` with `p ∤ l`, lie in one class modulo `lcm(d, p^i)`. -/
theorem fibre_card (hp : p.Prime) {l : ℕ} (hpl : ¬ p ∣ l) {A : ℝ} (hA : 0 < A) (H : Finset ℕ)
(hH : ∀ h ∈ H, A ≤ (h : ℝ) ∧ (h : ℝ) ≤ 2 * A) (i d : ℕ) (hd : 0 < d) (F : ℕ → ℤ)
(hF : ∀ t t', ((p ^ i : ℕ) : ℤ) ∣ F t → ((p ^ i : ℕ) : ℤ) ∣ F t' →
((p ^ i : ℕ) : ℤ) ∣ ((t' : ℤ) - t) * l) :
((H.filter (fun t => ((p ^ i : ℕ) : ℤ) ∣ F t ∧ d ∣ t)).card : ℝ)
≤ A / (Nat.lcm d (p ^ i) : ℕ) + 1 := by
apply card_le_of_pairwise_dvd _ (Nat.lcm_pos hd (pow_pos hp.pos i)) hA
· intro t ht
exact hH t (mem_filter.mp ht).1
· intro t ht t' ht'
obtain ⟨-, hpt, hdt⟩ := mem_filter.mp ht
obtain ⟨-, hpt', hdt'⟩ := mem_filter.mp ht'
have hcop : IsCoprime ((p ^ i : ℕ) : ℤ) (l : ℤ) :=
Nat.isCoprime_iff_coprime.mpr
(Nat.Coprime.pow_left i ((Nat.Prime.coprime_iff_not_dvd hp).mpr hpl))
have h1 : ((p ^ i : ℕ) : ℤ) ∣ (t' : ℤ) - t := hcop.dvd_of_dvd_mul_right (hF t t' hpt hpt')
have h2 : (d : ℤ) ∣ (t' : ℤ) - t :=
dvd_sub (Int.natCast_dvd_natCast.mpr hdt') (Int.natCast_dvd_natCast.mpr hdt)
rw [Int.natCast_dvd] at h1 h2 ⊢
exact Nat.lcm_dvd h2 h1
end Main
/-! ## One index, and the assembly -/
section Assembly
open scoped Classical
variable {p k l₁ l₂ : ℕ}
theorem K_nonneg {A : ℝ} (hA : 0 < A) (q : ℕ) :
0 ≤ 2 * A ^ 2 + 2 * A * Real.sqrt (2 * A) * Real.sqrt q :=
add_nonneg (by positivity)
(mul_nonneg (mul_nonneg (by linarith) (Real.sqrt_nonneg _)) (Real.sqrt_nonneg _))
/-- The contribution of one index `(i, d₁, d₂)` is at most `2A² + 2A (2A)^{1/2} q^{1/2}`.
The case `p ∣ l₁` exchanges the roles of `h₁` and `h₂` (then `p ∤ l₂`). -/
theorem per_index (hp : p.Prime) (hcop : Nat.Coprime l₁ l₂) {A : ℝ} (hA : 0 < A) (H : Finset ℕ)
(hH : ∀ h ∈ H, A ≤ (h : ℝ) ∧ (h : ℝ) ≤ 2 * A) {i d₁ d₂ : ℕ} (hi : i ≤ k)
(hd₁ : 0 < d₁) (hd₂ : 0 < d₂) :
∑ h₁ ∈ H, ∑ h₂ ∈ H, term p l₁ l₂ (i, d₁, d₂) h₁ h₂
≤ 2 * A ^ 2 + 2 * A * Real.sqrt (2 * A) * Real.sqrt (p ^ k : ℕ) := by
have hsum : ∑ h₁ ∈ H, ∑ h₂ ∈ H, term p l₁ l₂ (i, d₁, d₂) h₁ h₂
= Real.sqrt (((p ^ i : ℕ) : ℝ) * d₁ * d₂) * ∑ h₁ ∈ H, ∑ h₂ ∈ H,
(if ((p ^ i : ℕ) : ℤ) ∣ R l₁ l₂ h₁ h₂ ∧ d₁ ∣ h₁ ∧ d₂ ∣ h₂ then (1 : ℝ) else 0) := by
simp only [term, mul_sum, mul_boole]
rw [hsum]
have hK0 := K_nonneg hA (p ^ k)
have hcq : p ^ i ≤ p ^ k := Nat.pow_le_pow_right hp.pos hi
by_cases hpl : p ∣ l₁
· have hpl₂ : ¬ p ∣ l₂ := fun h =>
hp.not_dvd_one (by rw [← Nat.Coprime.gcd_eq_one hcop]; exact Nat.dvd_gcd hpl h)
by_cases hd1 : (d₁ : ℝ) ≤ 2 * A
· have hL : 0 < Nat.lcm d₁ (p ^ i) := Nat.lcm_pos hd₁ (pow_pos hp.pos i)
have hnb0 : (0 : ℝ) ≤ A / (Nat.lcm d₁ (p ^ i) : ℕ) + 1 := by
have := div_pos hA (Nat.cast_pos.mpr hL)
linarith
have hcount : ∑ h₁ ∈ H, ∑ h₂ ∈ H,
(if ((p ^ i : ℕ) : ℤ) ∣ R l₁ l₂ h₁ h₂ ∧ d₁ ∣ h₁ ∧ d₂ ∣ h₂ then (1 : ℝ) else 0)
≤ (2 * A / d₂) * (A / (Nat.lcm d₁ (p ^ i) : ℕ) + 1) := by
rw [sum_comm]
exact sum_sum_boole_le H
(fun h₂ h₁ => ((p ^ i : ℕ) : ℤ) ∣ R l₁ l₂ h₁ h₂ ∧ d₁ ∣ h₁ ∧ d₂ ∣ h₂)
(fun h₂ => d₂ ∣ h₂) (fun h₂ h₁ => ((p ^ i : ℕ) : ℤ) ∣ R l₁ l₂ h₁ h₂ ∧ d₁ ∣ h₁)
(fun _ _ hab => ⟨hab.2.2, hab.1, hab.2.1⟩)
(card_multiples_le _ hd₂ hA (fun t ht => hH t (mem_filter.mp ht).1)
(fun t ht => (mem_filter.mp ht).2))
(fun h₂ => fibre_card hp hpl₂ hA H hH i d₁ hd₁ (fun t => R l₁ l₂ t h₂)
(fun t t' ht ht' => by
have e : R l₁ l₂ t' h₂ - R l₁ l₂ t h₂ = ((t' : ℤ) - t) * l₂ := by
unfold R; ring
rw [← e]
exact dvd_sub ht' ht))
hnb0
have hsw : Real.sqrt (((p ^ i : ℕ) : ℝ) * d₁ * d₂)
= Real.sqrt (((p ^ i : ℕ) : ℝ) * d₂ * d₁) := by rw [mul_right_comm]
rw [hsw]
exact le_trans (mul_le_mul_of_nonneg_left hcount (Real.sqrt_nonneg _))
(core hA hd₂ hL (Nat.le_of_dvd hL (Nat.dvd_lcm_right _ _))
(Nat.le_of_dvd hL (Nat.dvd_lcm_left _ _)) hcq hd1
(div_pos (by linarith) (Nat.cast_pos.mpr hd₂)).le le_rfl hnb0 le_rfl)
· have hz : ∑ h₁ ∈ H, ∑ h₂ ∈ H,
(if ((p ^ i : ℕ) : ℤ) ∣ R l₁ l₂ h₁ h₂ ∧ d₁ ∣ h₁ ∧ d₂ ∣ h₂ then (1 : ℝ) else 0) = 0 :=
sum_eq_zero fun h₁ hh₁ => sum_eq_zero fun h₂ _ =>
if_neg fun hc => hd1 (le_of_dvd_mem hA hH hh₁ hc.2.1)
rw [hz, mul_zero]
exact hK0
· by_cases hd2 : (d₂ : ℝ) ≤ 2 * A
· have hL : 0 < Nat.lcm d₂ (p ^ i) := Nat.lcm_pos hd₂ (pow_pos hp.pos i)
have hnb0 : (0 : ℝ) ≤ A / (Nat.lcm d₂ (p ^ i) : ℕ) + 1 := by
have := div_pos hA (Nat.cast_pos.mpr hL)
linarith
have hcount : ∑ h₁ ∈ H, ∑ h₂ ∈ H,
(if ((p ^ i : ℕ) : ℤ) ∣ R l₁ l₂ h₁ h₂ ∧ d₁ ∣ h₁ ∧ d₂ ∣ h₂ then (1 : ℝ) else 0)
≤ (2 * A / d₁) * (A / (Nat.lcm d₂ (p ^ i) : ℕ) + 1) :=
sum_sum_boole_le H
(fun h₁ h₂ => ((p ^ i : ℕ) : ℤ) ∣ R l₁ l₂ h₁ h₂ ∧ d₁ ∣ h₁ ∧ d₂ ∣ h₂)
(fun h₁ => d₁ ∣ h₁) (fun h₁ h₂ => ((p ^ i : ℕ) : ℤ) ∣ R l₁ l₂ h₁ h₂ ∧ d₂ ∣ h₂)
(fun _ _ hab => ⟨hab.2.1, hab.1, hab.2.2⟩)
(card_multiples_le _ hd₁ hA (fun t ht => hH t (mem_filter.mp ht).1)
(fun t ht => (mem_filter.mp ht).2))
(fun h₁ => fibre_card hp hpl hA H hH i d₂ hd₂ (fun t => R l₁ l₂ h₁ t)
(fun t t' ht ht' => by
have e : R l₁ l₂ h₁ t - R l₁ l₂ h₁ t' = ((t' : ℤ) - t) * l₁ := by
unfold R; ring
rw [← e]
exact dvd_sub ht ht'))
hnb0
exact le_trans (mul_le_mul_of_nonneg_left hcount (Real.sqrt_nonneg _))
(core hA hd₁ hL (Nat.le_of_dvd hL (Nat.dvd_lcm_right _ _))
(Nat.le_of_dvd hL (Nat.dvd_lcm_left _ _)) hcq hd2
(div_pos (by linarith) (Nat.cast_pos.mpr hd₁)).le le_rfl hnb0 le_rfl)
· have hz : ∑ h₁ ∈ H, ∑ h₂ ∈ H,
(if ((p ^ i : ℕ) : ℤ) ∣ R l₁ l₂ h₁ h₂ ∧ d₁ ∣ h₁ ∧ d₂ ∣ h₂ then (1 : ℝ) else 0) = 0 :=
sum_eq_zero fun h₁ _ => sum_eq_zero fun h₂ hh₂ =>
if_neg fun hc => hd2 (le_of_dvd_mem hA hH hh₂ hc.2.2)
rw [hz, mul_zero]
exact hK0
/-- **Lemma H, sharper constant.** For a prime `p`, `q = p^k`, coprime `l₁, l₂ ≥ 1`, `A > 0` and
any finite set `H` of naturals in `[A, 2A]` (so also any subset of `(A, 2A]`):
`∑_{h₁,h₂ ∈ H} (R,q)^{1/2} (h₁,l₁)^{1/2} (h₂,l₂)^{1/2}
≤ (k+1) τ(l₁) τ(l₂) [2A² + 2A (2A)^{1/2} q^{1/2}]`, with `R = h₁l₂ - h₂l₁`, `(0,q) = q`
(`Int.gcd 0 q = q`), and `τ(l) = #l.divisors`. -/
theorem lemmaH_sharp (hp : p.Prime) (hl₁ : 0 < l₁) (hl₂ : 0 < l₂) (hcop : Nat.Coprime l₁ l₂)
{A : ℝ} (hA : 0 < A) (H : Finset ℕ) (hH : ∀ h ∈ H, A ≤ (h : ℝ) ∧ (h : ℝ) ≤ 2 * A) :
∑ h₁ ∈ H, ∑ h₂ ∈ H, Real.sqrt (Int.gcd (R l₁ l₂ h₁ h₂) ((p ^ k : ℕ) : ℤ)) *
Real.sqrt (Nat.gcd h₁ l₁) * Real.sqrt (Nat.gcd h₂ l₂)
≤ (k + 1) * l₁.divisors.card * l₂.divisors.card *
(2 * A ^ 2 + 2 * A * Real.sqrt (2 * A) * Real.sqrt (p ^ k : ℕ)) := by
calc _ ≤ ∑ x ∈ range (k + 1) ×ˢ (l₁.divisors ×ˢ l₂.divisors), ∑ h₁ ∈ H, ∑ h₂ ∈ H,
term p l₁ l₂ x h₁ h₂ := lhs_le_sum_index hp hl₁.ne' hl₂.ne' H
_ ≤ ∑ x ∈ range (k + 1) ×ˢ (l₁.divisors ×ˢ l₂.divisors),
(2 * A ^ 2 + 2 * A * Real.sqrt (2 * A) * Real.sqrt (p ^ k : ℕ)) := by
refine sum_le_sum fun x hx => ?_
obtain ⟨i, d₁, d₂⟩ := x
simp only [mem_product, mem_range, Nat.mem_divisors] at hx
exact per_index hp hcop hA H hH (by omega) (Nat.pos_of_dvd_of_pos hx.2.1.1 hl₁)
(Nat.pos_of_dvd_of_pos hx.2.2.1 hl₂)
_ = _ := by
rw [sum_const, card_product, card_product, card_range, nsmul_eq_mul]
push_cast
ring
theorem rpow_form {A : ℝ} (hA : 0 ≤ A) (q : ℝ) :
2 * A * Real.sqrt (2 * A) * Real.sqrt q
= (2 : ℝ) ^ ((3 : ℝ) / 2) * A ^ ((3 : ℝ) / 2) * q ^ ((1 : ℝ) / 2) := by
have h32 : (3 : ℝ) / 2 = 1 + 1 / 2 := by norm_num
rw [Real.sqrt_eq_rpow, Real.sqrt_eq_rpow, Real.mul_rpow (by norm_num : (0 : ℝ) ≤ 2) hA, h32,
Real.rpow_add' (by norm_num : (0 : ℝ) ≤ 2) (by norm_num : (1 : ℝ) + 1 / 2 ≠ 0),
Real.rpow_add' hA (by norm_num : (1 : ℝ) + 1 / 2 ≠ 0), Real.rpow_one, Real.rpow_one]
ring
/-- **Lemma H as stated** in `research/structured-dispersion-estimate.md` §4, inequality (2):
`≤ (k+1) τ(l₁) τ(l₂) [4A² + 2^{3/2} A^{3/2} q^{1/2}]`. -/
theorem lemmaH (hp : p.Prime) (hl₁ : 0 < l₁) (hl₂ : 0 < l₂) (hcop : Nat.Coprime l₁ l₂)
{A : ℝ} (hA : 0 < A) (H : Finset ℕ) (hH : ∀ h ∈ H, A ≤ (h : ℝ) ∧ (h : ℝ) ≤ 2 * A) :
∑ h₁ ∈ H, ∑ h₂ ∈ H, Real.sqrt (Int.gcd (R l₁ l₂ h₁ h₂) ((p ^ k : ℕ) : ℤ)) *
Real.sqrt (Nat.gcd h₁ l₁) * Real.sqrt (Nat.gcd h₂ l₂)
≤ (k + 1) * l₁.divisors.card * l₂.divisors.card *
(4 * A ^ 2 + (2 : ℝ) ^ ((3 : ℝ) / 2) * A ^ ((3 : ℝ) / 2) *
((p ^ k : ℕ) : ℝ) ^ ((1 : ℝ) / 2)) := by
rw [← rpow_form hA.le ((p ^ k : ℕ) : ℝ)]
refine (lemmaH_sharp hp hl₁ hl₂ hcop hA H hH).trans ?_
apply mul_le_mul_of_nonneg_left _ (by positivity)
nlinarith [sq_nonneg A]
end Assembly
end LemmaH
#print axioms LemmaH.lemmaH
#print axioms LemmaH.lemmaH_sharp
Decision record
- Sat Sep 19 2026 : pending by triage: Put to triage first (review triage switched on): an agent that is not a trusted reviewer reads it and says whether a trusted verdict would change the record.
- Fri Sep 25 2026 : pending by triage: Triage skipped: a trusted tier-1 reviewer (claude-opus-5-5) reviews it directly
- Sat Sep 26 2026 : accepted (proven) by trusted: 1 trusted vote(s)