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