This journal is in preparation. Submissions are open as a pilot and the editorial board is being formed. Articles marked Demonstration show the format only.
Journal of Machine-Verified MathematicsPeer-reviewed mathematics with machine-checked proofs, for the age of AI

E424/RoughElements/L12Aux.lean

All files · 213 lines · source at the verified commit

1module
2
3public import E424.Tools.T10
4
5@[expose] public section
6
7/-!
8# Section 3 helpers for L12
9
10`rough_mass`: the reciprocal sum over z-rough integers `n ≤ z^K` is at most `A K` (Euler product, via T10).
11`card_divisors_rough`: a rough integer `n ≤ z^K` has at most `2^K` divisors.
12`sum_inv_le_of_fiber`: a sum of `1/g i` is at most the fiber size times the sum over the image of `g`.
13`card_fiber_lcm2`, `card_fiber_lcm4`: tuples from a set with a fixed lcm are divisor tuples of that lcm.
14-/
15
16set_option linter.style.header false
17open Finset
18
19namespace E424
20
21/-- Mass bound: the reciprocal sum over z-rough integers `n ≤ z^K` is at most `A K`. -/
22theorem rough_mass : ∃ A > 0, ∀ z : ℝ, 2 ≤ z → ∀ K : ℕ, 1 ≤ K → ∀ D : Finset ℕ,
23 (∀ n ∈ D, 0 < n ∧ (n : ℝ) ≤ z ^ K ∧ Rough z n) → ∑ n ∈ D, 1 / (n : ℝ) ≤ A * K := by
24 obtain ⟨A, hA, hT⟩ := T10_mertens_prod
25 refine ⟨A, hA, fun z hz K hK D hD => ?_⟩
26 have hz0 : 0 < z := by linarith
27 have hzl : 0 < Real.log z := Real.log_pos (by linarith)
28 set P := primesIoc z (z ^ K) with hP
29 set M := ⌊z ^ K⌋₊ + 1 with hM
30 have hprime : ∀ a ∈ P, a.Prime := fun a ha => by
31 rw [hP, primesIoc, mem_filter] at ha
32 exact ha.2
33 have hPge : ∀ a ∈ P, (2 : ℝ) ≤ a := fun a ha => by exact_mod_cast (hprime a ha).two_le
34 -- every prime factor of an element of D lies in P
35 have hPmem : ∀ n ∈ D, ∀ p, p.Prime → p ∣ n → p ∈ P := by
36 intro n hn p hp hpn
37 obtain ⟨hn0, hle, hr⟩ := hD n hn
38 have hzp : z < p := hr p hp hpn
39 have hpk : (p : ℝ) ≤ z ^ K :=
40 le_trans (by exact_mod_cast Nat.le_of_dvd hn0 hpn) hle
41 rw [hP, primesIoc, mem_filter, mem_Ioc]
42 exact ⟨⟨(Nat.floor_lt hz0.le).2 hzp, Nat.le_floor hpk⟩, hp⟩
43 have hzero : ∀ n ∈ D, ∀ p, p ∉ P → n.factorization p = 0 := by
44 intro n hn p hp
45 by_cases hpp : p.Prime
46 · exact Nat.factorization_eq_zero_of_not_dvd fun h => hp (hPmem n hn p hpp h)
47 · exact Nat.factorization_eq_zero_of_not_prime n hpp
48 -- exponent vectors indexed by P, and the weight of such a vector
49 let F : ℕ → (∀ a ∈ P, ℕ) := fun n a _ => n.factorization a
50 let W : (∀ a ∈ P, ℕ) → ℝ := fun x => ∏ a ∈ P.attach, (1 / (a.1 : ℝ)) ^ x a.1 a.2
51 have hW : ∀ n ∈ D, W (F n) = 1 / (n : ℝ) := by
52 intro n hn
53 obtain ⟨hn0, -, -⟩ := hD n hn
54 have hsupp : n.factorization.support ⊆ P := by
55 intro a ha
56 rw [Nat.support_factorization] at ha
57 exact hPmem n hn a (Nat.prime_of_mem_primeFactors ha) (Nat.dvd_of_mem_primeFactors ha)
58 have hnP : n = ∏ a ∈ P, a ^ n.factorization a := by
59 have h := Nat.prod_factorization_pow_eq_self hn0.ne'
60 rw [Finsupp.prod_of_support_subset _ hsupp _ (fun i _ => pow_zero i)] at h
61 exact h.symm
62 have hreal : (n : ℝ) = ∏ a ∈ P, (a : ℝ) ^ n.factorization a := by
63 exact_mod_cast hnP
64 show (∏ a ∈ P.attach, (1 / (a.1 : ℝ)) ^ n.factorization a.1) = 1 / (n : ℝ)
65 rw [Finset.prod_attach P (fun a => (1 / (a : ℝ)) ^ n.factorization a), hreal, one_div,
66 ← Finset.prod_inv_distrib]
67 exact Finset.prod_congr rfl fun a _ => by rw [one_div, inv_pow]
68 have hFmem : ∀ n ∈ D, F n ∈ P.pi (fun _ => range M) := by
69 intro n hn
70 obtain ⟨hn0, hle, -⟩ := hD n hn
71 rw [Finset.mem_pi]
72 intro a ha
73 rw [mem_range]
74 have hdvd : a ^ n.factorization a ∣ n := Nat.ordProj_dvd n a
75 have hpow : n.factorization a < a ^ n.factorization a :=
76 Nat.lt_two_pow_self.trans_le (Nat.pow_le_pow_left (hprime a ha).two_le _)
77 have hnk : n ≤ ⌊z ^ K⌋₊ := Nat.le_floor hle
78 have hle' : a ^ n.factorization a ≤ n := Nat.le_of_dvd hn0 hdvd
79 rw [hM]
80 exact Nat.lt_succ_of_le ((hpow.le.trans hle').trans hnk)
81 have hinj : Set.InjOn F D := by
82 intro n hn m hm hnm
83 obtain ⟨hn0, -, -⟩ := hD n hn
84 obtain ⟨hm0, -, -⟩ := hD m hm
85 refine Nat.eq_of_factorization_eq hn0.ne' hm0.ne' fun p => ?_
86 by_cases hp : p ∈ P
87 · have := congrArg (fun f => f p hp) hnm
88 simpa [F] using this
89 · rw [hzero n hn p hp, hzero m hm p hp]
90 have hWnn : ∀ x, 0 ≤ W x := fun x =>
91 Finset.prod_nonneg fun a _ => pow_nonneg (by have := hPge a a.2; positivity) _
92 -- a finite geometric series is at most its infinite sum
93 have hgeom : ∀ a ∈ P, ∑ k ∈ range M, (1 / (a : ℝ)) ^ k ≤ (1 - 1 / (a : ℝ))⁻¹ := by
94 intro a ha
95 have hr0 : 0 ≤ 1 / (a : ℝ) := by have := hPge a ha; positivity
96 have hr1 : 1 / (a : ℝ) ≤ 1 / 2 := one_div_le_one_div_of_le (by norm_num) (hPge a ha)
97 have hpos : 0 < 1 - 1 / (a : ℝ) := by linarith
98 have h := geom_sum_mul_neg (1 / (a : ℝ)) M
99 rw [inv_eq_one_div, le_div_iff₀ hpos]
100 linarith [pow_nonneg hr0 M]
101 have hprod_geom : ∏ a ∈ P, ∑ k ∈ range M, (1 / (a : ℝ)) ^ k = ∑ x ∈ P.pi (fun _ => range M), W x :=
102 Finset.prod_sum P (fun _ => range M) (fun a k => (1 / (a : ℝ)) ^ k)
103 have hsum_img : ∑ n ∈ D, 1 / (n : ℝ) = ∑ x ∈ D.image F, W x := by
104 rw [Finset.sum_image hinj]
105 exact Finset.sum_congr rfl fun n hn => (hW n hn).symm
106 have hsub : ∑ x ∈ D.image F, W x ≤ ∑ x ∈ P.pi (fun _ => range M), W x :=
107 Finset.sum_le_sum_of_subset_of_nonneg
108 (fun x hx => by
109 obtain ⟨n, hn, rfl⟩ := mem_image.1 hx
110 exact hFmem n hn)
111 (fun x _ _ => hWnn x)
112 have hgeomprod : ∏ a ∈ P, ∑ k ∈ range M, (1 / (a : ℝ)) ^ k ≤ ∏ a ∈ P, (1 - 1 / (a : ℝ))⁻¹ :=
113 Finset.prod_le_prod₀ (fun a ha => Finset.sum_nonneg fun k _ => by
114 have := hPge a ha
115 have : (0 : ℝ) ≤ 1 / (a : ℝ) := by positivity
116 exact pow_nonneg this _) hgeom
117 have hzK : z ≤ z ^ K := le_self_pow₀ (by linarith) (by omega)
118 have hTP := (hT z (z ^ K) hz hzK).1
119 have hlog : A * Real.log (z ^ K) / Real.log z = A * K := by
120 rw [Real.log_pow]
121 field_simp
122 calc ∑ n ∈ D, 1 / (n : ℝ) = ∑ x ∈ D.image F, W x := hsum_img
123 _ ≤ ∑ x ∈ P.pi (fun _ => range M), W x := hsub
124 _ = ∏ a ∈ P, ∑ k ∈ range M, (1 / (a : ℝ)) ^ k := hprod_geom.symm
125 _ ≤ ∏ a ∈ P, (1 - 1 / (a : ℝ))⁻¹ := hgeomprod
126 _ ≤ A * Real.log (z ^ K) / Real.log z := hTP
127 _ = A * K := hlog
128
129/-- A rough integer `n ≤ z^K` (with `z ≥ 2`) has at most `2^K` divisors. -/
130theorem card_divisors_rough {z : ℝ} (hz : 2 ≤ z) {K : ℕ} {n : ℕ} (hn : n ≠ 0)
131 (hr : Rough z n) (hle : (n : ℝ) ≤ z ^ K) : n.divisors.card ≤ 2 ^ K := by
132 have hz0 : 0 < z := by linarith
133 have hprod : n = ∏ p ∈ n.primeFactors, p ^ n.factorization p := by
134 have h := Nat.prod_factorization_pow_eq_self hn
135 rw [Finsupp.prod, Nat.support_factorization] at h
136 exact h.symm
137 have hsum : ∑ p ∈ n.primeFactors, n.factorization p ≤ K := by
138 have h1 : z ^ (∑ p ∈ n.primeFactors, n.factorization p) ≤ (n : ℝ) := by
139 rw [← Finset.prod_pow_eq_pow_sum]
140 conv_rhs => rw [hprod]
141 push_cast
142 refine Finset.prod_le_prod₀ (fun _ _ => pow_nonneg hz0.le _) fun p hp => pow_le_pow_left₀ hz0.le ?_ _
143 exact (hr p (Nat.prime_of_mem_primeFactors hp) (Nat.dvd_of_mem_primeFactors hp)).le
144 exact (pow_le_pow_iff_right₀ (by linarith)).1 (h1.trans hle)
145 calc n.divisors.card = ∏ p ∈ n.primeFactors, (n.factorization p + 1) := Nat.card_divisors hn
146 _ ≤ ∏ p ∈ n.primeFactors, 2 ^ n.factorization p :=
147 Finset.prod_le_prod₀ (fun _ _ => Nat.zero_le _) fun p _ => Nat.lt_two_pow_self
148 _ = 2 ^ ∑ p ∈ n.primeFactors, n.factorization p := (Finset.prod_pow_eq_pow_sum _ _ _)
149 _ ≤ 2 ^ K := Nat.pow_le_pow_right (by norm_num) hsum
150
151/-- Fiber sums: `∑ 1/g i` is at most the largest fiber times the sum of `1/j` over the image. -/
152theorem sum_inv_le_of_fiber {ι : Type*} (s : Finset ι) (g : ι → ℕ) {B : ℝ}
153 (hB : ∀ j ∈ s.image g, ((s.filter fun i => g i = j).card : ℝ) ≤ B) :
154 ∑ i ∈ s, 1 / (g i : ℝ) ≤ B * ∑ j ∈ s.image g, 1 / (j : ℝ) := by
155 calc ∑ i ∈ s, 1 / (g i : ℝ)
156 = ∑ j ∈ s.image g, ∑ i ∈ s.filter (fun i => g i = j), 1 / (g i : ℝ) :=
157 (Finset.sum_fiberwise_of_maps_to (fun i hi => Finset.mem_image_of_mem g hi) (fun i => 1 / (g i : ℝ))).symm
158 _ ≤ ∑ j ∈ s.image g, B * (1 / (j : ℝ)) := by
159 refine Finset.sum_le_sum fun j hj => ?_
160 have hc : ∑ i ∈ s.filter (fun i => g i = j), 1 / (g i : ℝ)
161 = ∑ i ∈ s.filter (fun i => g i = j), 1 / (j : ℝ) :=
162 Finset.sum_congr rfl fun i hi => by rw [(Finset.mem_filter.1 hi).2]
163 rw [hc, Finset.sum_const, nsmul_eq_mul]
164 exact mul_le_mul_of_nonneg_right (hB j hj) (by positivity)
165 _ = B * ∑ j ∈ s.image g, 1 / (j : ℝ) := by rw [Finset.mul_sum]
166
167theorem lcm_le_mul_nat {a b : ℕ} (ha : 0 < a) (hb : 0 < b) : a.lcm b ≤ a * b :=
168 Nat.le_of_dvd (Nat.mul_pos ha hb) (Nat.lcm_dvd (dvd_mul_right a b) (dvd_mul_left b a))
169
170theorem rough_lcm {z : ℝ} {a b : ℕ} (ha : Rough z a) (hb : Rough z b) : Rough z (a.lcm b) := by
171 intro p hp hpd
172 rcases (Nat.Prime.dvd_mul hp).1 (hpd.trans (Nat.lcm_dvd (dvd_mul_right a b) (dvd_mul_left b a))) with h | h
173 · exact ha p hp h
174 · exact hb p hp h
175
176/-- The pairs of `S` with a fixed lcm `j` are pairs of divisors of `j`. -/
177theorem card_fiber_lcm2 (S : Finset ℕ) {j : ℕ} (hj : j ≠ 0) :
178 ((S ×ˢ S).filter fun x : ℕ × ℕ => x.1.lcm x.2 = j).card ≤ j.divisors.card ^ 2 := by
179 calc ((S ×ˢ S).filter fun x : ℕ × ℕ => x.1.lcm x.2 = j).card
180 ≤ (j.divisors ×ˢ j.divisors).card := by
181 apply Finset.card_le_card
182 intro x hx
183 rw [mem_filter] at hx
184 have h1 : x.1 ∣ j := by rw [← hx.2]; exact Nat.dvd_lcm_left _ _
185 have h2 : x.2 ∣ j := by rw [← hx.2]; exact Nat.dvd_lcm_right _ _
186 simp only [mem_product, Nat.mem_divisors]
187 exact ⟨⟨h1, hj⟩, ⟨h2, hj⟩⟩
188 _ = j.divisors.card ^ 2 := by rw [card_product, sq]
189
190/-- The 4-tuples of `S` with a fixed lcm `j` are 4-tuples of divisors of `j`. -/
191theorem card_fiber_lcm4 (S : Finset ℕ) {j : ℕ} (hj : j ≠ 0) :
192 ((S ×ˢ S ×ˢ S ×ˢ S).filter fun x : ℕ × ℕ × ℕ × ℕ =>
193 x.1.lcm (x.2.1.lcm (x.2.2.1.lcm x.2.2.2)) = j).card ≤ j.divisors.card ^ 4 := by
194 calc ((S ×ˢ S ×ˢ S ×ˢ S).filter fun x : ℕ × ℕ × ℕ × ℕ =>
195 x.1.lcm (x.2.1.lcm (x.2.2.1.lcm x.2.2.2)) = j).card
196 ≤ (j.divisors ×ˢ j.divisors ×ˢ j.divisors ×ˢ j.divisors).card := by
197 apply Finset.card_le_card
198 intro x hx
199 rw [mem_filter] at hx
200 obtain ⟨-, hx⟩ := hx
201 have h1 : x.1 ∣ j := by rw [← hx]; exact Nat.dvd_lcm_left _ _
202 have h2 : x.2.1 ∣ j := by
203 rw [← hx]; exact (Nat.dvd_lcm_left _ _).trans (Nat.dvd_lcm_right _ _)
204 have h3 : x.2.2.1 ∣ j := by
205 rw [← hx]; exact ((Nat.dvd_lcm_left _ _).trans (Nat.dvd_lcm_right _ _)).trans (Nat.dvd_lcm_right _ _)
206 have h4 : x.2.2.2 ∣ j := by
207 rw [← hx]; exact ((Nat.dvd_lcm_right _ _).trans (Nat.dvd_lcm_right _ _)).trans (Nat.dvd_lcm_right _ _)
208 simp only [mem_product, Nat.mem_divisors]
209 exact ⟨⟨h1, hj⟩, ⟨h2, hj⟩, ⟨h3, hj⟩, h4, hj⟩
210 _ = j.divisors.card ^ 4 := by rw [card_product, card_product, card_product]; ring
211
212end E424
213