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/NaturalDensity/L41Aux.lean

All files · 197 lines · source at the verified commit

1module
2
3public import E424.RoughElements.L12
4public import E424.Tools.T3
5
6@[expose] public section
7
8/-!
9# Section 10: helpers for Lemma 41 (Turán-Kubilius in natural density)
10
11Counting multiples in `(X, 2X]`, expanding the second moment of `rc T - ms T` over pairs of divisors,
12and the gcd structure of blocks (distinct blocks are coprime, since each block is rough at a scale below the
13next block).
14-/
15
16set_option linter.style.header false
17open Finset
18
19namespace E424
20
21/-- The integers of `(X, 2X]` divisible by `d` are within 1 of `X/d`. -/
22lemma card_dvd_Ioc_bounds {X : ℝ} (hX : 0 ≤ X) {d : ℕ} (hd : 0 < d) :
23 X * (1 / (d : ℝ)) - 1 ≤ ((Ioc ⌊X⌋₊ ⌊2 * X⌋₊).filter (fun n => d ∣ n)).card ∧
24 ((Ioc ⌊X⌋₊ ⌊2 * X⌋₊).filter (fun n => d ∣ n)).card ≤ X * (1 / (d : ℝ)) + 1 := by
25 have h0 := abs_card_multiples_le hX hX hd
26 rw [← two_mul] at h0
27 have h := abs_le.1 h0
28 have e : X * (1 / (d : ℝ)) = X / d := by ring
29 rw [e]
30 constructor <;> linarith [h.1, h.2]
31
32/-- Expanding the second moment over `I`: a pair `s, t` contributes the multiples of `lcm s t`. -/
33lemma sum_sq_expand (I T : Finset ℕ) :
34 ∑ n ∈ I, (rc T n - ms T) ^ 2 =
35 ∑ s ∈ T, ∑ t ∈ T, ((I.filter fun n => Nat.lcm s t ∣ n).card : ℝ)
36 - 2 * ms T * ∑ s ∈ T, ((I.filter fun n => s ∣ n).card : ℝ)
37 + ((I.filter fun n => 1 ∣ n).card : ℝ) * ms T ^ 2 := by
38 have hpt : ∀ n : ℕ, (rc T n - ms T) ^ 2 =
39 ∑ s ∈ T, ∑ t ∈ T, (if s ∣ n then (1 : ℝ) else 0) * (if t ∣ n then (1 : ℝ) else 0)
40 - 2 * ms T * ∑ s ∈ T, (if s ∣ n then (1 : ℝ) else 0) + ms T ^ 2 := by
41 intro n
42 have hA : (∑ s ∈ T, (if s ∣ n then (1 : ℝ) else 0)) ^ 2 =
43 ∑ s ∈ T, ∑ t ∈ T, (if s ∣ n then (1 : ℝ) else 0) * (if t ∣ n then (1 : ℝ) else 0) := by
44 rw [sq, sum_mul_sum]
45 rw [rc_eq_sum]
46 calc _ = (∑ s ∈ T, (if s ∣ n then (1 : ℝ) else 0)) ^ 2
47 - 2 * ms T * ∑ s ∈ T, (if s ∣ n then (1 : ℝ) else 0) + ms T ^ 2 := by ring
48 _ = _ := by rw [hA]
49 have hlcm : ∀ s t : ℕ, ∑ n ∈ I, (if s ∣ n then (1 : ℝ) else 0) * (if t ∣ n then (1 : ℝ) else 0)
50 = ((I.filter fun n => Nat.lcm s t ∣ n).card : ℝ) := by
51 intro s t
52 rw [← sum_boole (fun n => Nat.lcm s t ∣ n) I]
53 refine sum_congr rfl fun n _ => ?_
54 by_cases h1 : s ∣ n <;> by_cases h2 : t ∣ n <;> simp [h1, h2, Nat.lcm_dvd_iff]
55 have hdiv : ∀ s : ℕ, ∑ n ∈ I, (if s ∣ n then (1 : ℝ) else 0)
56 = ((I.filter fun n => s ∣ n).card : ℝ) := fun s => by
57 rw [← sum_boole (fun n => s ∣ n) I]
58 have h1 : ∑ n ∈ I, ∑ s ∈ T, ∑ t ∈ T, (if s ∣ n then (1 : ℝ) else 0) * (if t ∣ n then (1 : ℝ) else 0)
59 = ∑ s ∈ T, ∑ t ∈ T, ((I.filter fun n => Nat.lcm s t ∣ n).card : ℝ) := by
60 rw [sum_comm]
61 refine sum_congr rfl fun s _ => ?_
62 rw [sum_comm]
63 exact sum_congr rfl fun t _ => hlcm s t
64 have h2 : ∑ n ∈ I, 2 * ms T * ∑ s ∈ T, (if s ∣ n then (1 : ℝ) else 0)
65 = 2 * ms T * ∑ s ∈ T, ((I.filter fun n => s ∣ n).card : ℝ) := by
66 rw [← mul_sum, sum_comm]
67 congr 1
68 exact sum_congr rfl fun s _ => hdiv s
69 have h3 : ∑ n ∈ I, ms T ^ 2 = ((I.filter fun n => 1 ∣ n).card : ℝ) * ms T ^ 2 := by
70 rw [filter_true_of_mem fun n _ => one_dvd n, sum_const, nsmul_eq_mul]
71 rw [sum_congr rfl fun n _ => hpt n, sum_add_distrib, sum_sub_distrib, h1, h2, h3]
72
73/-- `1/lcm s t` splits as `1/(s t) + gcd/(s t)` when `gcd > 1`, and equals `1/(s t)` otherwise. -/
74lemma one_div_lcm_le (s t : ℕ) (hs : 0 < s) (ht : 0 < t) :
75 1 / (Nat.lcm s t : ℝ) ≤
76 1 / ((s : ℝ) * t) + (if 1 < Nat.gcd s t then (Nat.gcd s t : ℝ) / ((s : ℝ) * t) else 0) := by
77 have hgl : (Nat.gcd s t : ℝ) * (Nat.lcm s t : ℝ) = (s : ℝ) * t := by
78 exact_mod_cast Nat.gcd_mul_lcm s t
79 have hg : 0 < Nat.gcd s t := Nat.gcd_pos_of_pos_left t hs
80 have hst : (0 : ℝ) < (s : ℝ) * t := by positivity
81 have hl : (0 : ℝ) < Nat.lcm s t := by exact_mod_cast Nat.lcm_pos hs ht
82 have h1st : (0 : ℝ) ≤ 1 / ((s : ℝ) * t) := by positivity
83 split_ifs with h1
84 · have e : 1 / (Nat.lcm s t : ℝ) = (Nat.gcd s t : ℝ) / ((s : ℝ) * t) := by
85 rw [div_eq_div_iff hl.ne' hst.ne']
86 linarith [hgl]
87 rw [e]
88 have : (0 : ℝ) ≤ 1 / ((s : ℝ) * t) := by positivity
89 linarith
90 · have hg1 : Nat.gcd s t = 1 := by omega
91 have hl' : (Nat.lcm s t : ℝ) = (s : ℝ) * t := by
92 rw [hg1] at hgl
93 push_cast at hgl
94 linarith [hgl]
95 rw [hl', add_zero]
96
97/-- Block scales increase: `z j ^ 200 ≤ z k` for `j < k < J`. -/
98lemma blocks_scale {J : ℕ} {z : ℕ → ℝ} (hz : ∀ j < J, 3 ≤ z j)
99 (hmono : ∀ j, j + 1 < J → z j ^ 200 ≤ z (j + 1)) :
100 ∀ j k, j < k → k < J → z j ^ 200 ≤ z k := by
101 intro j k hjk
102 have hjk' : j + 1 ≤ k := hjk
103 clear hjk
104 induction k, hjk' using Nat.le_induction with
105 | base => intro hkJ; exact hmono j hkJ
106 | succ k hjk ih =>
107 intro hkJ
108 have hk : k < J := by omega
109 have h1 : z k ≤ z k ^ 200 := le_self_pow₀ (by linarith [hz k hk]) (by norm_num)
110 exact (ih hk).trans (h1.trans (hmono k hkJ))
111
112/-- Two different blocks are coprime: a number of block `j` is at most `z j ^ 200 ≤ z k`,
113below every prime factor of a number of block `k`, which is `z k`-rough. -/
114lemma gcd_eq_one_of_blocks {J : ℕ} {z : ℕ → ℝ} {S : ℕ → Finset ℕ}
115 (hz : ∀ j < J, 3 ≤ z j) (hfam : ∀ j < J, IsFam (z j) (S j))
116 (hscale : ∀ j k, j < k → k < J → z j ^ 200 ≤ z k)
117 {j k : ℕ} (hjk : j < k) (hk : k < J) {s t : ℕ} (hs : s ∈ S j) (ht : t ∈ S k) :
118 Nat.gcd s t = 1 := by
119 by_contra hne
120 obtain ⟨p, hp, hpg⟩ := Nat.exists_prime_and_dvd hne
121 have hps : p ∣ s := hpg.trans (Nat.gcd_dvd_left s t)
122 have hpt : p ∣ t := hpg.trans (Nat.gcd_dvd_right s t)
123 obtain ⟨hzs, hsz, -⟩ := hfam j (by omega) s hs
124 obtain ⟨-, -, hrt⟩ := hfam k hk t ht
125 have hs0 : 0 < s := by
126 have : (0 : ℝ) < s := by linarith [hz j (by omega)]
127 exact_mod_cast this
128 have h2 : (p : ℝ) ≤ s := by exact_mod_cast Nat.le_of_dvd hs0 hps
129 have h1 : z k < p := hrt p hp hpt
130 linarith [hscale j k hjk hk]
131
132/-- Every element of a union of blocks lies in one block. -/
133lemma exists_block_of_mem {J : ℕ} {S : ℕ → Finset ℕ} {T : Finset ℕ} (hT : T = (range J).biUnion S)
134 {s : ℕ} (hs : s ∈ T) : ∃ j < J, s ∈ S j := by
135 rw [hT, mem_biUnion] at hs
136 obtain ⟨j, hj, hsj⟩ := hs
137 exact ⟨j, mem_range.1 hj, hsj⟩
138
139/-- Sum over pairs of `T` restricted to `B × B`, for `B ⊆ T`, is at most the sum over `B × B`. -/
140lemma sum_ite_block_le (T B : Finset ℕ) (g : ℕ → ℕ → ℝ) (hg : ∀ s t, 0 ≤ g s t) :
141 ∑ s ∈ T, ∑ t ∈ T, (if s ∈ B ∧ t ∈ B then g s t else 0) ≤ ∑ s ∈ B, ∑ t ∈ B, g s t := by
142 rw [← sum_product' (f := fun s t => if s ∈ B ∧ t ∈ B then g s t else 0),
143 ← sum_product' (f := g), ← sum_filter]
144 refine sum_le_sum_of_subset_of_nonneg ?_ fun p _ _ => hg p.1 p.2
145 intro p hp
146 simp only [mem_filter, mem_product] at hp
147 exact mem_product.2 hp.2
148
149/-- Swap the order of a triple sum over `T × T × range J`. -/
150lemma sum_swap_block (T : Finset ℕ) (J : ℕ) (f : ℕ → ℕ → ℕ → ℝ) :
151 ∑ s ∈ T, ∑ t ∈ T, ∑ j ∈ range J, f s t j = ∑ j ∈ range J, ∑ s ∈ T, ∑ t ∈ T, f s t j := by
152 calc ∑ s ∈ T, ∑ t ∈ T, ∑ j ∈ range J, f s t j = ∑ s ∈ T, ∑ j ∈ range J, ∑ t ∈ T, f s t j :=
153 sum_congr rfl fun s _ => sum_comm
154 _ = ∑ j ∈ range J, ∑ s ∈ T, ∑ t ∈ T, f s t j := sum_comm
155
156/-- The gcd part of the second moment: pairs with `gcd > 1` lie in a single block, so their
157total weight is at most the sum of the `J` block sums. -/
158lemma sum_gcd_gt_le {J : ℕ} {S : ℕ → Finset ℕ} {C : ℝ} {T : Finset ℕ} (hT : T = (range J).biUnion S)
159 (hblk : ∀ j < J, ∑ s ∈ S j, ∑ t ∈ S j, (Nat.gcd s t : ℝ) / ((s : ℝ) * t) ≤ C)
160 (hcop : ∀ j k, j < J → k < J → j ≠ k → ∀ s ∈ S j, ∀ t ∈ S k, Nat.gcd s t = 1) :
161 ∑ s ∈ T, ∑ t ∈ T, (if 1 < Nat.gcd s t then (Nat.gcd s t : ℝ) / ((s : ℝ) * t) else 0)
162 ≤ J * C := by
163 have hpair : ∀ s ∈ T, ∀ t ∈ T,
164 (if 1 < Nat.gcd s t then (Nat.gcd s t : ℝ) / ((s : ℝ) * t) else 0) ≤
165 ∑ j ∈ range J, (if s ∈ S j ∧ t ∈ S j then (Nat.gcd s t : ℝ) / ((s : ℝ) * t) else 0) := by
166 intro s hs t ht
167 split_ifs with hg
168 · obtain ⟨j1, hj1, hs1⟩ := exists_block_of_mem hT hs
169 obtain ⟨j2, hj2, ht2⟩ := exists_block_of_mem hT ht
170 have hj : j1 = j2 := by
171 by_contra hne
172 have h1 := hcop j1 j2 hj1 hj2 hne s hs1 t ht2
173 rw [h1] at hg
174 omega
175 subst hj
176 calc _ = (if s ∈ S j1 ∧ t ∈ S j1 then (Nat.gcd s t : ℝ) / ((s : ℝ) * t) else 0) :=
177 (if_pos ⟨hs1, ht2⟩).symm
178 _ ≤ _ := single_le_sum (f := fun j => if s ∈ S j ∧ t ∈ S j then
179 (Nat.gcd s t : ℝ) / ((s : ℝ) * t) else 0)
180 (fun j _ => by split_ifs <;> positivity) (mem_range.2 hj1)
181 · exact sum_nonneg fun j _ => by split_ifs <;> positivity
182 have hg : ∀ s t : ℕ, 0 ≤ (Nat.gcd s t : ℝ) / ((s : ℝ) * t) := fun s t => by positivity
183 calc ∑ s ∈ T, ∑ t ∈ T, (if 1 < Nat.gcd s t then (Nat.gcd s t : ℝ) / ((s : ℝ) * t) else 0)
184 ≤ ∑ s ∈ T, ∑ t ∈ T, ∑ j ∈ range J,
185 (if s ∈ S j ∧ t ∈ S j then (Nat.gcd s t : ℝ) / ((s : ℝ) * t) else 0) :=
186 sum_le_sum fun s hs => sum_le_sum fun t ht => hpair s hs t ht
187 _ = ∑ j ∈ range J, ∑ s ∈ T, ∑ t ∈ T,
188 (if s ∈ S j ∧ t ∈ S j then (Nat.gcd s t : ℝ) / ((s : ℝ) * t) else 0) :=
189 sum_swap_block T J (fun s t j =>
190 if s ∈ S j ∧ t ∈ S j then (Nat.gcd s t : ℝ) / ((s : ℝ) * t) else 0)
191 _ ≤ ∑ j ∈ range J, C := sum_le_sum fun j hj =>
192 (sum_ite_block_le T (S j) (fun s t => (Nat.gcd s t : ℝ) / ((s : ℝ) * t)) hg).trans
193 (hblk j (mem_range.1 hj))
194 _ = J * C := by rw [sum_const, card_range, nsmul_eq_mul, mul_comm]
195
196end E424
197