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/Main.lean

All files · 309 lines · source at the verified commit

1module
2
3public import E424.NaturalDensity
4
5@[expose] public section
6
7/-!
8# The theorem: the set has natural density 2/3
9
10Proved from Proposition L, Lemmas 11, 42, 43.
11-/
12
13set_option linter.style.header false
14open Finset Filter
15
16namespace E424
17
18/-- `#(B ∩ (X, 2X]) ≤ ε X` for large `X`. -/
19theorem bcount_small (ε : ℝ) (hε : 0 < ε) : ∃ X0 ≥ (1 : ℝ), ∀ X ≥ X0, bcount X ≤ ε * X := by
20 obtain ⟨cS, hcS, z0, h11⟩ := L11
21 obtain ⟨C42, hC42, h42⟩ := L42
22 obtain ⟨C43, hC43, h43⟩ := L43
23 -- choose `J`
24 obtain ⟨j, hj⟩ := exists_nat_ge (3 * C42 / (cS * ε))
25 set J := (j + 1) ^ 2 with hJ
26 have hsJ : Real.sqrt (J : ℝ) = j + 1 := by
27 rw [hJ]; push_cast; exact Real.sqrt_sq (by positivity)
28 have hJ0 : (0 : ℝ) < J := by rw [hJ]; positivity
29 have hj' : 3 * C42 ≤ cS * ε * (j + 1) := by
30 rw [div_le_iff₀ (by positivity)] at hj; nlinarith [mul_pos hcS hε]
31 have hJC : C42 * Real.sqrt J ≤ cS * J * (ε / 3) := by
32 have : (J : ℝ) = (j + 1) * (j + 1) := by rw [hJ]; push_cast; ring
33 rw [hsJ, this]
34 have : 0 < (j : ℝ) + 1 := by positivity
35 nlinarith
36 -- scales `z_i = X^{e_i}`
37 set e : ℕ → ℝ := fun i => 200 ^ i / (10 * 200 ^ J) with he
38 have he0 : ∀ i, 0 < e i := fun i => by simp only [he]; positivity
39 have hes : ∀ i, e i * 200 = e (i + 1) := fun i => by simp only [he, pow_succ]; ring
40 have he1 : ∀ i, i < J → e i * 200 ≤ 0.1 := fun i hi => by
41 rw [hes]
42 simp only [he]
43 rw [div_le_iff₀ (by positivity)]
44 have : (200 : ℝ) ^ (i + 1) ≤ 200 ^ J := pow_le_pow_right₀ (by norm_num) hi
45 linarith
46 set η := 199 * e 0 with hη
47 have hη0 : 0 < η := by have := he0 0; positivity
48 have hemono : ∀ i, e 0 ≤ e i := fun i => by
49 simp only [he]
50 gcongr
51 · norm_num
52 · exact Nat.zero_le i
53 set ε1 := cS * ε / (3 * (200 * C43)) with hε1
54 have hε10 : 0 < ε1 := by positivity
55 obtain ⟨N, hN⟩ := PropL η hη0 ε1 hε10
56 have ev : ∀ᶠ X : ℝ in atTop, max 4 z0 ≤ X ^ e 0 ∧ max 3 N ≤ X ^ (0.9 : ℝ) ∧ max 2 (3 / ε) ≤ X :=
57 ((tendsto_rpow_atTop (he0 0)).eventually_ge_atTop _).and
58 (((tendsto_rpow_atTop (by norm_num)).eventually_ge_atTop _).and (eventually_ge_atTop _))
59 obtain ⟨X0, hX0⟩ := eventually_atTop.mp ev
60 refine ⟨max 1 X0, le_max_left _ _, fun X hX => ?_⟩
61 obtain ⟨hz, h9, hX2'⟩ := hX0 X ((le_max_right _ _).trans hX)
62 have hX2 : 2 ≤ X := (le_max_left _ _).trans hX2'
63 have hXε : 3 / ε ≤ X := (le_max_right _ _).trans hX2'
64 have hX1 : 1 ≤ X := by linarith
65 have hXp : 0 < X := by linarith
66 have hlX : 0 < Real.log X := Real.log_pos (by linarith)
67 set z : ℕ → ℝ := fun i => X ^ e i with hzdef
68 have hz4 : ∀ i, max 4 z0 ≤ z i := fun i =>
69 hz.trans (Real.rpow_le_rpow_of_exponent_le hX1 (hemono i))
70 have hzpos : ∀ i, 0 < z i := fun i => Real.rpow_pos_of_pos hXp _
71 have hz200 : ∀ i, z i ^ 200 = z (i + 1) := fun i => by
72 simp only [hzdef]
73 rw [← Real.rpow_natCast, ← Real.rpow_mul hXp.le, ← hes]; norm_num
74 have hz200' : ∀ i, i < J → z i ^ 200 ≤ X ^ (0.1 : ℝ) := fun i hi => by
75 rw [hz200]
76 refine Real.rpow_le_rpow_of_exponent_le hX1 ?_
77 rw [← hes]; exact he1 i hi
78 choose S hS using fun i => h11 (z i) ((le_max_right _ _).trans (hz4 i)) 53 (Or.inl rfl)
79 set T := (range J).biUnion S with hT
80 have hblocks : IsBlocks J T :=
81 ⟨z, S, fun i _ => ⟨by linarith [(le_max_left _ _).trans (hz4 i)], (hS i).fam⟩,
82 fun i _ => (hz200 i).le, rfl⟩
83 have hzmono : ∀ i k, i ≤ k → z i ≤ z k := fun i k hik => by
84 refine Real.rpow_le_rpow_of_exponent_le hX1 ?_
85 simp only [he]
86 gcongr
87 norm_num
88 have hdisj : ∀ i ∈ range J, ∀ k ∈ range J, i ≠ k → Disjoint (S i) (S k) := by
89 have key : ∀ i k, i < k → Disjoint (S i) (S k) := fun i k hik => by
90 refine disjoint_left.mpr fun s hs hs' => ?_
91 have h1 := ((hS i).fam s hs).2.1
92 have h2 := ((hS k).fam s hs').1
93 rw [hz200] at h1
94 have := hzmono (i + 1) k hik
95 linarith
96 intro i _ k _ hik
97 rcases lt_or_gt_of_ne hik with h | h
98 · exact key i k h
99 · exact (key k i h).symm
100 have hmsT : cS * J ≤ ms T := by
101 have : ms T = ∑ i ∈ range J, ms (S i) := by unfold ms; rw [hT, sum_biUnion hdisj]
102 rw [this]
103 calc cS * J = ∑ i ∈ range J, cS := by rw [sum_const, card_range, nsmul_eq_mul]; ring
104 _ ≤ _ := sum_le_sum fun i _ => (hS i).mass
105 have hmsT0 : 0 < ms T := lt_of_lt_of_le (by positivity) hmsT
106 have hmem : ∀ s ∈ T, s ∈ A ∧ s % 3 = 2 ∧ (s : ℝ) ≤ X ^ (0.1 : ℝ) := by
107 intro s hs
108 obtain ⟨i, hi, hs⟩ := mem_biUnion.mp hs
109 have h1 := (hS i).mem s hs
110 exact ⟨h1.1, by omega, (((hS i).fam s hs).2.1).trans (hz200' i (mem_range.mp hi))⟩
111 have main := h42 J T hblocks X hX2 hmem
112 -- each block
113 have hblock : ∀ i ∈ range J, ∑ s ∈ S i, bcount (X / s) ≤ 200 * C43 * ε1 * X := by
114 intro i hi
115 have hz4' : 4 ≤ z i := (le_max_left _ _).trans (hz4 i)
116 have hlz : 0 < Real.log (z i) := Real.log_pos (by linarith)
117 refine (h43 (z i) hz4' (S i) (hS i).fam X hX1).trans ?_
118 set W : Win := ⟨X / z i ^ 200, 2 * X / z i⟩ with hW
119 have hlo : X ^ (0.9 : ℝ) ≤ W.lo := by
120 change _ ≤ X / z i ^ 200
121 rw [le_div_iff₀ (by have := hzpos i; positivity)]
122 calc X ^ (0.9 : ℝ) * z i ^ 200 ≤ X ^ (0.9 : ℝ) * X ^ (0.1 : ℝ) := by
123 gcongr; exact hz200' i (mem_range.mp hi)
124 _ = X := by rw [← Real.rpow_add hXp]; norm_num
125 have hlen : W.len = Real.log 2 + 199 * Real.log (z i) := by
126 have hp := hzpos i
127 have : W.hi / W.lo = 2 * z i ^ 199 := by
128 change (2 * X / z i) / (X / z i ^ 200) = _
129 field_simp
130 rw [Win.len, this, Real.log_mul (by norm_num) (by positivity), Real.log_pow]; norm_num
131 have hlz2 : Real.log 2 ≤ Real.log (z i) := Real.log_le_log (by norm_num) (by linarith)
132 have hl2 := Real.log_pos (show (1 : ℝ) < 2 by norm_num)
133 have hlogz : Real.log (z i) = e i * Real.log X := Real.log_rpow hXp _
134 have hWlo3 : 3 ≤ W.lo := ((le_max_left _ _).trans h9).trans hlo
135 have hWloX : W.lo ≤ X := by
136 change X / z i ^ 200 ≤ X
137 exact div_le_self hXp.le (one_le_pow₀ (by linarith))
138 have hlt : W.lo < W.hi := by
139 have hpos : 0 < W.len := by rw [hlen]; positivity
140 by_contra hcon
141 rw [not_lt] at hcon
142 have hhi : 0 < W.hi := by
143 have := hzpos i
144 change 0 < 2 * X / z i
145 positivity
146 have : W.len ≤ 0 :=
147 Real.log_nonpos (by positivity) ((div_le_one (by linarith)).mpr hcon)
148 linarith
149 have hP := hN W hWlo3 hlt (((le_max_right _ _).trans h9).trans hlo) (by
150 rw [hlen, hlogz, hη]
151 have h1 : Real.log W.lo ≤ Real.log X := Real.log_le_log (by linarith) hWloX
152 have h2 := hemono i
153 have h3 := he0 0
154 calc 199 * e 0 * Real.log W.lo ≤ 199 * e 0 * Real.log X := by gcongr
155 _ ≤ 199 * e i * Real.log X := by gcongr
156 _ ≤ _ := by linarith)
157 calc C43 * X / Real.log (z i) * W.sum f
158 ≤ C43 * X / Real.log (z i) * (ε1 * (200 * Real.log (z i))) := by
159 gcongr
160 refine hP.trans ?_
161 gcongr
162 rw [hlen]; linarith
163 _ = 200 * C43 * ε1 * X := by field_simp
164 have hsumT : ∑ s ∈ T, bcount (X / s) ≤ J * (200 * C43 * ε1 * X) := by
165 rw [hT, sum_biUnion hdisj]
166 calc _ ≤ ∑ i ∈ range J, 200 * C43 * ε1 * X := sum_le_sum hblock
167 _ = _ := by rw [sum_const, card_range, nsmul_eq_mul]
168 have hε1' : 200 * C43 * ε1 = cS * (ε / 3) := by rw [hε1]; field_simp
169 rw [hε1'] at hsumT
170 have h1X : 1 ≤ ε / 3 * X := by
171 rw [div_le_iff₀ hε] at hXε; linarith
172 have hfin : bcount X * ms T ≤ ε * X * ms T := by
173 have e1 : J * (cS * (ε / 3) * X) ≤ ε / 3 * X * ms T := by
174 calc J * (cS * (ε / 3) * X) = ε / 3 * X * (cS * J) := by ring
175 _ ≤ _ := by gcongr
176 have e2 : C42 * Real.sqrt J * X ≤ ε / 3 * X * ms T := by
177 calc C42 * Real.sqrt J * X ≤ cS * J * (ε / 3) * X := by gcongr
178 _ = ε / 3 * X * (cS * J) := by ring
179 _ ≤ _ := by gcongr
180 have e3 : ms T ≤ ε / 3 * X * ms T := by nlinarith
181 linarith
182 exact le_of_mul_le_mul_right hfin hmsT0
183
184/-- `#(B ∩ [1, x])`. -/
185noncomputable def bsum (x : ℝ) : ℝ := ∑ n ∈ Ioc 0 ⌊x⌋₊, f n
186
187theorem bsum_le_self (x : ℝ) (hx : 0 ≤ x) : bsum x ≤ x := by
188 unfold bsum
189 calc ∑ n ∈ Ioc 0 ⌊x⌋₊, f n ≤ ∑ n ∈ Ioc 0 ⌊x⌋₊, (1 : ℝ) := sum_le_sum fun n _ => f_le_one n
190 _ = ⌊x⌋₊ := by simp
191 _ ≤ x := Nat.floor_le hx
192
193theorem bsum_double (x : ℝ) (hx : 0 ≤ x) : bsum x = bsum (x / 2) + bcount (x / 2) := by
194 unfold bsum bcount
195 rw [← sum_union (Ioc_disjoint_Ioc_of_le le_rfl), show 2 * (x / 2) = x by ring,
196 Ioc_union_Ioc_eq_Ioc (Nat.zero_le _) (Nat.floor_mono (by linarith))]
197
198theorem bsum_small (ε : ℝ) (hε : 0 < ε) : ∃ K ≥ (0 : ℝ), ∀ x ≥ 0, bsum x ≤ K + ε * x := by
199 obtain ⟨X0, hX0, h⟩ := bcount_small ε hε
200 refine ⟨2 * X0, by positivity, ?_⟩
201 have key : ∀ n : ℕ, ∀ x : ℝ, 0 ≤ x → x ≤ 2 ^ n * X0 → bsum x ≤ 2 * X0 + ε * x := by
202 intro n
203 induction n with
204 | zero =>
205 intro x hx hle
206 have := bsum_le_self x hx
207 have : 0 ≤ ε * x := by positivity
208 rw [pow_zero, one_mul] at hle
209 linarith
210 | succ n ih =>
211 intro x hx hle
212 rcases le_or_gt x (2 * X0) with h1 | h1
213 · have := bsum_le_self x hx
214 have : 0 ≤ ε * x := by positivity
215 linarith
216 · have e1 := ih (x / 2) (by positivity) (by rw [pow_succ] at hle; linarith)
217 have e2 := h (x / 2) (by linarith)
218 rw [bsum_double x hx]
219 linarith
220 intro x hx
221 obtain ⟨n, hn⟩ := exists_nat_ge (x / X0)
222 refine key n x hx ?_
223 rw [div_le_iff₀ (by linarith)] at hn
224 have : (n : ℝ) ≤ 2 ^ n := by exact_mod_cast (Nat.lt_two_pow_self).le
225 nlinarith
226
227open Classical in
228/-- `#(U ∩ [0, n)) = 2n/3 + O(1)`. -/
229theorem card_U (n : ℕ) :
230 |(((range n).filter (· ∈ U)).card : ℝ) - 2 / 3 * n| ≤ 2 := by
231 have key : ∀ n : ℕ, (n = 0 → ((range n).filter (· ∈ U)).card = 0) ∧
232 (0 < n → n % 3 = 0 → 3 * ((range n).filter (· ∈ U)).card + 3 = 2 * n) ∧
233 (n % 3 = 1 → 3 * ((range n).filter (· ∈ U)).card + 2 = 2 * n) ∧
234 (n % 3 = 2 → 3 * ((range n).filter (· ∈ U)).card + 4 = 2 * n) := by
235 intro n
236 induction n with
237 | zero => simp
238 | succ n ih =>
239 rw [range_add_one, filter_insert]
240 have hU : n ∈ U ↔ 1 ≤ n ∧ n % 3 ≠ 1 := Iff.rfl
241 by_cases h : n ∈ U
242 · rw [if_pos h, card_insert_of_notMem (by simp)]
243 rw [hU] at h
244 omega
245 · rw [if_neg h]
246 rw [hU] at h
247 omega
248 have hk := key n
249 have h1 : 3 * ((range n).filter (· ∈ U)).card ≤ 2 * n := by omega
250 have h2 : 2 * n ≤ 3 * ((range n).filter (· ∈ U)).card + 4 := by omega
251 have h1' : 3 * (((range n).filter (· ∈ U)).card : ℝ) ≤ 2 * n := by exact_mod_cast h1
252 have h2' : 2 * (n : ℝ) ≤ 3 * (((range n).filter (· ∈ U)).card : ℝ) + 4 := by exact_mod_cast h2
253 rw [abs_le]; constructor <;> linarith
254
255open Classical in
256theorem card_A (n : ℕ) : |(((range n).filter (· ∈ A)).card : ℝ) - 2 / 3 * n| ≤ 2 + bsum n := by
257 have hsub : (range n).filter (· ∈ A) ⊆ (range n).filter (· ∈ U) := fun m hm => by
258 rw [mem_filter] at *; exact ⟨hm.1, A_subset_U hm.2⟩
259 have hdiff : (((range n).filter (· ∈ U)).card : ℝ) - ((range n).filter (· ∈ A)).card ≤ bsum n := by
260 have h1 := card_sdiff_add_card_eq_card hsub
261 have h2 : ((((range n).filter (· ∈ U)) \ ((range n).filter (· ∈ A))).card : ℝ) ≤ bsum n := by
262 unfold bsum f ind
263 rw [Finset.sum_ite, Finset.sum_const_zero, add_zero, Finset.sum_const, nsmul_eq_mul, mul_one]
264 refine Nat.cast_le.mpr (card_le_card fun m hm => ?_)
265 obtain ⟨hm1, hm2⟩ := Finset.mem_sdiff.mp hm
266 obtain ⟨hmn, hmU⟩ := Finset.mem_filter.mp hm1
267 have hmA : m ∉ A := fun h => hm2 (Finset.mem_filter.mpr ⟨hmn, h⟩)
268 rw [mem_range] at hmn
269 rw [mem_filter, mem_Ioc, Nat.floor_natCast]
270 exact ⟨⟨hmU.1, hmn.le⟩, hmU, hmA⟩
271 have h1' : ((((range n).filter (· ∈ U)) \ ((range n).filter (· ∈ A))).card : ℝ) +
272 ((range n).filter (· ∈ A)).card = ((range n).filter (· ∈ U)).card := by exact_mod_cast h1
273 linarith
274 have hle : (((range n).filter (· ∈ A)).card : ℝ) ≤ ((range n).filter (· ∈ U)).card := by
275 exact_mod_cast card_le_card hsub
276 have hU := abs_le.mp (card_U n)
277 rw [abs_le]; constructor <;> linarith [hU.1, hU.2]
278
279/-- The natural density of the set is `2/3`. -/
280theorem hasDensity_two_thirds :
281 Filter.Tendsto (fun n : ℕ => (Set.ncard {m : ℕ | m < n ∧ Inp.Gen m} : ℝ) / n) Filter.atTop
282 (nhds (2 / 3)) := by
283 classical
284 rw [Metric.tendsto_atTop]
285 intro ε hε
286 obtain ⟨K, hK0, hK⟩ := bsum_small (ε / 3) (by positivity)
287 obtain ⟨N, hN⟩ := exists_nat_ge (3 * (2 + K) / ε)
288 refine ⟨N + 1, fun n hn => ?_⟩
289 have hn0 : (0 : ℝ) < n := by exact_mod_cast (by omega : 0 < n)
290 have hnN : 3 * (2 + K) ≤ ε * n := by
291 rw [div_le_iff₀ hε] at hN
292 have : (N : ℝ) ≤ n := by exact_mod_cast (by omega : N ≤ n)
293 nlinarith
294 have hpd : (Set.ncard {m : ℕ | m < n ∧ Inp.Gen m} : ℝ) / n =
295 (((range n).filter (· ∈ A)).card : ℝ) / n := by
296 have h1 : {m : ℕ | m < n ∧ Inp.Gen m} = (((range n).filter (· ∈ A) : Finset ℕ) : Set ℕ) := by
297 ext m; simp [mem_A_iff]
298 rw [h1, Set.ncard_coe_finset]
299 rw [hpd, Real.dist_eq]
300 have h1 := card_A n
301 have h2 := hK n hn0.le
302 have h3 : (((range n).filter (· ∈ A)).card : ℝ) / n - 2 / 3 =
303 (((range n).filter (· ∈ A)).card - 2 / 3 * n) / n := by field_simp
304 rw [h3, abs_div, abs_of_pos hn0, div_lt_iff₀ hn0]
305 have : 0 < ε * n := by positivity
306 linarith
307
308end E424
309