-
Notifications
You must be signed in to change notification settings - Fork 2
/
basic_estimates.lean
2220 lines (2016 loc) · 94.6 KB
/
basic_estimates.lean
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/-
Copyright (c) 2021 Thomas Bloom, Alex Kontorovich, Bhavik Mehta. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Thomas Bloom, Alex Kontorovich, Bhavik Mehta
-/
import analysis.special_functions.integrals
import analysis.special_functions.pow
import number_theory.arithmetic_function
import number_theory.von_mangoldt
import measure_theory.function.floor
import measure_theory.integral.integral_eq_improper
import data.complex.exponential_bounds
import analysis.p_series
import topology.algebra.floor_ring
import number_theory.prime_counting
import analysis.special_functions.logb
import for_mathlib.misc
import tactic.equiv_rw
noncomputable theory
open_locale big_operators nnreal filter topological_space arithmetic_function
open filter asymptotics real set
section to_mathlib
-- TODO (BM): Put this in mathlib
lemma Ici_diff_Icc {a b : ℝ} (hab : a ≤ b) : Ici a \ Icc a b = Ioi b :=
begin
rw [←Icc_union_Ioi_eq_Ici hab, union_diff_left, diff_eq_self],
rintro x ⟨⟨_, hx⟩, hx'⟩,
exact not_le_of_lt hx' hx,
end
-- TODO: Move to mathlib
lemma Ioi_diff_Icc {a b : ℝ} (hab : a ≤ b) : Ioi a \ Ioc a b = Ioi b :=
begin
rw [←Ioc_union_Ioi_eq_Ioi hab, union_diff_left, diff_eq_self, subset_def],
simp,
end
lemma is_o_log_id_at_top : is_o log id at_top :=
is_o_pow_log_id_at_top.congr_left (λ x, pow_one _)
lemma is_o_log_rpow_at_top {r : ℝ} (hr : 0 < r) : is_o log (λ x, x ^ r) at_top :=
begin
rw ←is_o_const_mul_left_iff hr.ne',
refine (is_o_log_id_at_top.comp_tendsto (tendsto_rpow_at_top hr)).congr' _ eventually_eq.rfl,
filter_upwards [eventually_gt_at_top (0 : ℝ)] with x hx using log_rpow hx _,
end
end to_mathlib
/--
Given a function `a : ℕ → M` from the naturals into an additive commutative monoid, this expresses
∑ 1 ≤ n ≤ x, a(n).
-/
-- BM: Formally I wrote this as the sum over the naturals in the closed interval `[1, ⌊x⌋]`.
-- The version in the notes uses sums from 1, mathlib typically uses sums from zero - hopefully
-- this difference shouldn't cause serious issues
variables {M : Type*} [add_comm_monoid M] (a : ℕ → M)
def summatory (a : ℕ → M) (k : ℕ) (x : ℝ) : M :=
∑ n in finset.Icc k ⌊x⌋₊, a n
lemma summatory_nat (k n : ℕ) :
summatory a k n = ∑ i in finset.Icc k n, a i :=
by simp only [summatory, nat.floor_coe]
lemma summatory_eq_floor {k : ℕ} (x : ℝ) :
summatory a k x = summatory a k ⌊x⌋₊ :=
by rw [summatory, summatory, nat.floor_coe]
lemma summatory_eq_of_Ico {n k : ℕ} {x : ℝ}
(hx : x ∈ Ico (n : ℝ) (n + 1)) :
summatory a k x = summatory a k n :=
by rw [summatory_eq_floor, nat.floor_eq_on_Ico' _ _ hx]
lemma summatory_eq_of_lt_one {k : ℕ} {x : ℝ} (hk : k ≠ 0) (hx : x < k) :
summatory a k x = 0 :=
begin
rw [summatory, finset.Icc_eq_empty_of_lt, finset.sum_empty],
rwa [nat.floor_lt' hk],
end
lemma summatory_zero_eq_of_lt {x : ℝ} (hx : x < 1) :
summatory a 0 x = a 0 :=
by rw [summatory_eq_floor, nat.floor_eq_zero.2 hx, summatory_nat, finset.Icc_self,
finset.sum_singleton]
@[simp] lemma summatory_zero {k : ℕ} (hk : k ≠ 0) : summatory a k 0 = 0 :=
summatory_eq_of_lt_one _ hk (by rwa [nat.cast_pos, pos_iff_ne_zero])
@[simp] lemma summatory_self {k : ℕ} : summatory a k k = a k :=
by simp [summatory]
@[simp] lemma summatory_one : summatory a 1 1 = a 1 :=
by simp [summatory]
lemma summatory_succ (k n : ℕ) (hk : k ≤ n + 1) :
summatory a k (n+1) = a (n + 1) + summatory a k n :=
by rw [summatory_nat, ←nat.cast_add_one, summatory_nat, ←nat.Ico_succ_right, @add_comm M,
finset.sum_Ico_succ_top hk, nat.Ico_succ_right]
lemma summatory_succ_sub {M : Type*} [add_comm_group M] (a : ℕ → M) (k : ℕ) (n : ℕ)
(hk : k ≤ n + 1) :
a (n + 1) = summatory a k (n + 1) - summatory a k n :=
begin
rwa [←nat.cast_add_one, summatory_nat, summatory_nat, ←nat.Ico_succ_right,
finset.sum_Ico_succ_top, nat.Ico_succ_right, add_sub_cancel'],
end
lemma summatory_eq_sub {M : Type*} [add_comm_group M] (a : ℕ → M) :
∀ n, n ≠ 0 → a n = summatory a 1 n - summatory a 1 (n - 1)
| 0 h := (h rfl).elim
| (n+1) _ := by simpa using summatory_succ_sub a 1 n
lemma abs_summatory_le_sum {M : Type*} [semi_normed_group M] (a : ℕ → M) {k : ℕ} {x : ℝ} :
∥summatory a k x∥ ≤ ∑ i in finset.Icc k ⌊x⌋₊, ∥a i∥ :=
norm_sum_le _ _
lemma summatory_const_one {x : ℝ} :
summatory (λ _, (1 : ℝ)) 1 x = (⌊x⌋₊ : ℝ) :=
by { rw [summatory, finset.sum_const, nat.card_Icc, nat.smul_one_eq_coe], refl }
lemma summatory_nonneg' {M : Type*} [ordered_add_comm_group M] {a : ℕ → M} (k : ℕ) (x : ℝ)
(ha : ∀ (i : ℕ), k ≤ i → (i : ℝ) ≤ x → 0 ≤ a i) (hk : k ≠ 0) :
0 ≤ summatory a k x :=
begin
apply finset.sum_nonneg,
simp only [and_imp, finset.mem_Icc],
intros i hi₁ hi₂,
apply ha i hi₁ ((nat.le_floor_iff' (ne_of_gt (lt_of_lt_of_le hk.bot_lt hi₁))).1 hi₂),
end
lemma summatory_nonneg {M : Type*} [ordered_add_comm_group M] (a : ℕ → M) (x : ℝ) (k : ℕ)
(ha : ∀ (i : ℕ), 0 ≤ a i) :
0 ≤ summatory a k x :=
finset.sum_nonneg (λ i _, ha _)
lemma summatory_monotone_of_nonneg {M : Type*} [ordered_add_comm_group M] (a : ℕ → M) (k : ℕ)
(ha : ∀ (i : ℕ), 0 ≤ a i) :
monotone (summatory a k) :=
begin
intros i j h,
refine finset.sum_le_sum_of_subset_of_nonneg _ (λ k _ _, ha _),
apply finset.Icc_subset_Icc le_rfl (nat.floor_mono h),
end
lemma abs_summatory_bound {M : Type*} [semi_normed_group M] (a : ℕ → M) (k z : ℕ)
{x : ℝ} (hx : x ≤ z) :
∥summatory a k x∥ ≤ ∑ i in finset.Icc k z, ∥a i∥ :=
(abs_summatory_le_sum a).trans
(finset.sum_le_sum_of_subset_of_nonneg
(finset.Icc_subset_Icc le_rfl (nat.floor_le_of_le hx)) (by simp))
open measure_theory
@[measurability] lemma measurable_summatory {M : Type*} [add_comm_monoid M] [measurable_space M]
{k : ℕ} {a : ℕ → M} :
measurable (summatory a k) :=
begin
change measurable ((λ y, ∑ i in finset.Icc k y, a i) ∘ _),
exact measurable_from_nat.comp nat.measurable_floor,
end
lemma partial_summation_integrable {𝕜 : Type*} [is_R_or_C 𝕜] (a : ℕ → 𝕜) {f : ℝ → 𝕜} {x y : ℝ}
{k : ℕ} (hf' : integrable_on f (Icc x y)) :
integrable_on (summatory a k * f) (Icc x y) :=
begin
let b := ∑ i in finset.Icc k ⌈y⌉₊, ∥a i∥,
have : integrable_on (b • f) (Icc x y) := integrable.smul b hf',
refine this.integrable.mono (measurable_summatory.ae_measurable.mul' hf'.1) _,
rw ae_restrict_iff' (measurable_set_Icc : measurable_set (Icc x _)),
refine eventually_of_forall (λ z hz, _),
rw [pi.mul_apply, norm_mul, pi.smul_apply, norm_smul],
refine mul_le_mul_of_nonneg_right ((abs_summatory_bound _ _ ⌈y⌉₊ _).trans _) (norm_nonneg _),
{ exact hz.2.trans (nat.le_ceil y) },
rw real.norm_eq_abs,
exact le_abs_self b,
end
/-- A version of partial summation where the upper bound is a natural number, useful to prove the
general case. -/
theorem partial_summation_nat {𝕜 : Type*} [is_R_or_C 𝕜] (a : ℕ → 𝕜) (f f' : ℝ → 𝕜)
{k : ℕ} {N : ℕ} (hN : k ≤ N)
(hf : ∀ i ∈ Icc (k : ℝ) N, has_deriv_at f (f' i) i) (hf' : integrable_on f' (Icc k N)) :
∑ n in finset.Icc k N, a n * f n =
summatory a k N * f N - ∫ t in Icc (k : ℝ) N, summatory a k t * f' t :=
begin
rw ←nat.Ico_succ_right,
revert hf hf',
refine nat.le_induction _ _ _ hN,
{ simp },
intros N hN' ih hf hf',
have hN'' : (N:ℝ) ≤ N + 1 := by simp only [zero_le_one, le_add_iff_nonneg_right],
have : Icc (k:ℝ) (N+1) = Icc k N ∪ Icc N (N+1),
{ refine (Icc_union_Icc_eq_Icc _ hN'').symm,
rwa nat.cast_le },
simp only [nat.cast_succ, this, mem_union_eq, or_imp_distrib, forall_and_distrib,
integrable_on_union] at ih hf hf' ⊢,
replace ih := ih hf.1 hf'.1,
have hN''' := hN'.trans le_self_add,
rw [finset.sum_Ico_succ_top hN''', ih, summatory_succ _ _ _ hN''', add_mul, add_sub_assoc,
add_comm, nat.cast_add_one, add_right_inj, eq_comm, sub_eq_sub_iff_sub_eq_sub, ←mul_sub,
integral_union_ae, add_sub_cancel',
←set_integral_congr_set_ae (Ico_ae_eq_Icc' volume_singleton)],
rotate, -- the first goal is the only hard one
{ rw [ae_disjoint, Icc_inter_Icc_eq_singleton _ hN'', volume_singleton],
rwa nat.cast_le },
{ exact measurable_set_Icc.null_measurable_set },
{ exact partial_summation_integrable a hf'.1 },
{ exact partial_summation_integrable a hf'.2 },
have : eq_on (λ x, summatory a k x * f' x) (λ x, summatory a k N • f' x) (Ico N (N+1)) :=
λ x hx, congr_arg2 (*) (summatory_eq_of_Ico _ hx) rfl,
rw [set_integral_congr measurable_set_Ico this, integral_smul, algebra.id.smul_eq_mul,
set_integral_congr_set_ae (Ico_ae_eq_Ioc' volume_singleton volume_singleton),
←interval_integral.integral_of_le hN'', interval_integral.integral_eq_sub_of_has_deriv_at],
{ rw interval_of_le hN'',
exact hf.2 },
{ exact (interval_integral.interval_integrable_iff_integrable_Icc_of_le hN'').2 hf'.2 },
end
/--
Right now this works for functions taking values in R or C, I think it should work for more target
spaces.
Also valid if k = 0 and a 0 = 0, not sure which is more interesting
-/
theorem partial_summation {𝕜 : Type*} [is_R_or_C 𝕜] (a : ℕ → 𝕜) (f f' : ℝ → 𝕜) {k : ℕ} {x : ℝ}
(hk : k ≠ 0) (hf : ∀ i ∈ Icc (k:ℝ) x, has_deriv_at f (f' i) i)
(hf' : integrable_on f' (Icc k x)) :
summatory (λ n, a n * f n) k x =
summatory a k x * f x - ∫ t in Icc (k : ℝ) x, summatory a k t * f' t :=
begin
cases lt_or_le x k,
{ rw [Icc_eq_empty_of_lt h, measure.restrict_empty, integral_zero_measure, sub_zero,
summatory_eq_of_lt_one _ hk h, summatory_eq_of_lt_one _ hk h, zero_mul] },
have hx : k ≤ ⌊x⌋₊ := by rwa [nat.le_floor_iff' hk],
have hx' : (⌊x⌋₊ : ℝ) ≤ x := nat.floor_le (le_trans (nat.cast_nonneg _) h),
have hx'' : (k : ℝ) ≤ ⌊x⌋₊ := by rwa nat.cast_le,
have : Icc (k : ℝ) x = Icc k ⌊x⌋₊ ∪ Icc ⌊x⌋₊ x := (Icc_union_Icc_eq_Icc hx'' hx').symm,
simp only [this, integrable_on_union, mem_union, or_imp_distrib, forall_and_distrib] at hf hf' ⊢,
rw [summatory, partial_summation_nat a f f' hx hf.1 hf'.1, eq_comm,
sub_eq_sub_iff_sub_eq_sub, summatory_eq_floor, ←mul_sub,
integral_union_ae _ (measurable_set_Icc.null_measurable_set : null_measurable_set (Icc (_:ℝ) _)),
add_sub_cancel'],
{ have : eq_on (λ y, summatory a k y * f' y) (λ y, summatory a k ⌊x⌋₊ • f' y) (Icc ⌊x⌋₊ x),
{ intros y hy,
dsimp,
rw summatory_eq_floor,
congr' 3,
exact nat.floor_eq_on_Ico _ _ ⟨hy.1, hy.2.trans_lt (nat.lt_floor_add_one _)⟩ },
rw [set_integral_congr measurable_set_Icc this, integral_smul, algebra.id.smul_eq_mul,
←set_integral_congr_set_ae (Ioc_ae_eq_Icc' volume_singleton),
←interval_integral.integral_of_le hx',
interval_integral.integral_eq_sub_of_has_deriv_at],
{ rw interval_of_le hx',
exact hf.2 },
{ exact (interval_integral.interval_integrable_iff_integrable_Icc_of_le hx').2 hf'.2 } },
{ apply partial_summation_integrable _ hf'.1 },
{ apply partial_summation_integrable _ hf'.2 },
{ rw [ae_disjoint, Icc_inter_Icc_eq_singleton hx'' hx',
volume_singleton] },
end
theorem partial_summation_cont {𝕜 : Type*} [is_R_or_C 𝕜] (a : ℕ → 𝕜) (f f' : ℝ → 𝕜) {k : ℕ} {x : ℝ}
(hk : k ≠ 0) (hf : ∀ i ∈ Icc (k:ℝ) x, has_deriv_at f (f' i) i) (hf' : continuous_on f' (Icc k x)) :
summatory (λ n, a n * f n) k x =
summatory a k x * f x - ∫ t in Icc (k : ℝ) x, summatory a k t * f' t :=
partial_summation _ _ _ hk hf hf'.integrable_on_Icc
/--
A variant of partial summation where we assume differentiability of `f` and integrability of `f'` on
`[1, ∞)` and derive the partial summation equation for all `x`.
-/
theorem partial_summation' {𝕜 : Type*} [is_R_or_C 𝕜] (a : ℕ → 𝕜) (f f' : ℝ → 𝕜) {k : ℕ} (hk : k ≠ 0)
(hf : ∀ i ∈ Ici (k:ℝ), has_deriv_at f (f' i) i) (hf' : integrable_on f' (Ici k)) {x : ℝ} :
summatory (λ n, a n * f n) k x =
summatory a k x * f x - ∫ t in Icc (k : ℝ) x, summatory a k t * f' t :=
partial_summation _ _ _ hk (λ i hi, hf _ hi.1) (hf'.mono_set Icc_subset_Ici_self)
/--
A variant of partial summation where we assume differentiability of `f` and continuity of `f'` on
`[1, ∞)` and derive the partial summation equation for all `x`.
-/
theorem partial_summation_cont' {𝕜 : Type*} [is_R_or_C 𝕜] (a : ℕ → 𝕜) (f f' : ℝ → 𝕜) {k : ℕ}
(hk : k ≠ 0) (hf : ∀ i ∈ Ici (k:ℝ), has_deriv_at f (f' i) i) (hf' : continuous_on f' (Ici k))
(x : ℝ) :
summatory (λ n, a n * f n) k x =
summatory a k x * f x - ∫ t in Icc (k : ℝ) x, summatory a k t * f' t :=
partial_summation_cont _ _ _ hk (λ i hi, hf _ hi.1) (hf'.mono Icc_subset_Ici_self)
-- BM: A definition of the Euler-Mascheroni constant
-- Maybe a different form is a better definition, and in any case it would be nice to show the
-- different definitions are equivalent.
-- This version uses an integral over an infinite interval, which in mathlib is *not* defined
-- as the limit of integrals over finite intervals, but there is a result saying they are equal:
-- see measure_theory.integral.integral_eq_improper: `interval_integral_tendsto_integral_Ioi`
def euler_mascheroni : ℝ := 1 - ∫ t in Ioi 1, int.fract t * (t^2)⁻¹
lemma integral_Ioi_rpow_tendsto_aux {a r : ℝ} (hr : r < -1) (ha : 0 < a)
{ι : Type*} {b : ι → ℝ} {l : filter ι} (hb : tendsto b l at_top) :
tendsto (λ i, ∫ x in a..b i, x ^ r) l (nhds (-a ^ (r + 1) / (r + 1))) :=
begin
suffices :
tendsto (λ i, ∫ x in a..b i, x ^ r) l (nhds (0 / (r + 1) - a ^ (r + 1) / (r + 1))),
{ simpa [neg_div] using this },
have : ∀ᶠ i in l, ∫ x in a..b i, x ^ r = (b i) ^ (r + 1) / (r + 1) - a ^ (r + 1) / (r + 1),
{ filter_upwards [hb.eventually (eventually_ge_at_top a)],
intros i hi,
rw [←sub_div, ←integral_rpow (or.inr ⟨hr.ne, not_mem_interval_of_lt ha (ha.trans_le hi)⟩)], },
rw tendsto_congr' this,
refine tendsto.sub_const _ (tendsto.div_const _),
rw ←neg_neg (r+1),
apply (tendsto_rpow_neg_at_top _).comp hb,
simpa using hr
end
-- TODO: Move to mathlib
lemma integrable_on_rpow_Ioi {a r : ℝ} (hr : r < -1) (ha : 0 < a) :
integrable_on (λ x, x ^ r) (Ioi a) :=
begin
have hb : tendsto (λ (x : ℝ≥0), a + x) at_top at_top :=
tendsto_at_top_add_const_left _ _ (nnreal.tendsto_coe_at_top.2 tendsto_id),
have : tendsto (λ (i : ℝ≥0), ∫ x in a..(a + i), ∥x ^ r∥) at_top (nhds (-a ^ (r + 1) / (r + 1))),
{ refine (integral_Ioi_rpow_tendsto_aux hr ha hb).congr (λ x, _),
refine interval_integral.integral_congr (λ i hi, _),
apply (real.norm_of_nonneg (real.rpow_nonneg_of_nonneg _ _)).symm,
exact ha.le.trans ((by simp : _ ≤ _).trans hi.1) },
refine integrable_on_Ioi_of_interval_integral_norm_tendsto _ _ (λ i, _) hb this,
refine (continuous_on.integrable_on_Icc _).mono_set Ioc_subset_Icc_self,
exact continuous_on_id.rpow_const (λ x hx, or.inl (ha.trans_le hx.1).ne'),
end
-- TODO: Move to mathlib
lemma integral_rpow_Ioi {a r : ℝ} (hr : r < -1) (ha : 0 < a) :
∫ x in Ioi a, x ^ r = - a ^ (r + 1) / (r + 1) :=
tendsto_nhds_unique
(interval_integral_tendsto_integral_Ioi _ (integrable_on_rpow_Ioi hr ha) tendsto_id)
(integral_Ioi_rpow_tendsto_aux hr ha tendsto_id)
-- TODO: Move to mathlib
lemma integrable_on_rpow_inv_Ioi {a r : ℝ} (hr : 1 < r) (ha : 0 < a) :
integrable_on (λ x, (x ^ r)⁻¹) (Ioi a) :=
(integrable_on_rpow_Ioi (neg_lt_neg hr) ha).congr_fun (λ x hx, rpow_neg (ha.trans hx).le _)
measurable_set_Ioi
-- TODO: Move to mathlib
lemma integral_rpow_inv {a r : ℝ} (hr : 1 < r) (ha : 0 < a) :
∫ x in Ioi a, (x ^ r)⁻¹ = a ^ (1 - r) / (r - 1) :=
begin
rw [←set_integral_congr, integral_rpow_Ioi (neg_lt_neg hr) ha, neg_div, ←div_neg, neg_add',
neg_neg, neg_add_eq_sub],
{ apply measurable_set_Ioi },
exact λ x hx, (rpow_neg (ha.trans hx).le _)
end
-- TODO: Move to mathlib
lemma integrable_on_zpow_Ioi {a : ℝ} {n : ℤ} (hn : n < -1) (ha : 0 < a) :
integrable_on (λ x, x ^ n) (Ioi a) :=
by exact_mod_cast integrable_on_rpow_Ioi (show (n : ℝ) < -1, by exact_mod_cast hn) ha
-- TODO: Move to mathlib
lemma integral_zpow_Ioi {a : ℝ} {n : ℤ} (hn : n < -1) (ha : 0 < a) :
∫ x in Ioi a, x ^ n = - a ^ (n + 1) / (n + 1) :=
by exact_mod_cast integral_rpow_Ioi (show (n : ℝ) < -1, by exact_mod_cast hn) ha
-- TODO: Move to mathlib
lemma integrable_on_zpow_inv_Ioi {a : ℝ} {n : ℤ} (hn : 1 < n) (ha : 0 < a) :
integrable_on (λ x, (x ^ n)⁻¹) (Ioi a) :=
(integrable_on_zpow_Ioi (neg_lt_neg hn) ha).congr_fun (by simp) measurable_set_Ioi
-- TODO: Move to mathlib
lemma integral_zpow_inv_Ioi {a : ℝ} {n : ℤ} (hn : 1 < n) (ha : 0 < a) :
∫ x in Ioi a, (x ^ n)⁻¹ = a ^ (1 - n) / (n - 1) :=
begin
simp_rw [←zpow_neg₀, integral_zpow_Ioi (neg_lt_neg hn) ha, neg_div, ←div_neg, neg_add',
int.cast_neg, neg_neg, neg_add_eq_sub],
end
-- TODO: Move to mathlib
lemma integrable_on_pow_inv_Ioi {a : ℝ} {n : ℕ} (hn : 1 < n) (ha : 0 < a) :
integrable_on (λ x, (x ^ n)⁻¹) (Ioi a) :=
by exact_mod_cast integrable_on_zpow_inv_Ioi (show 1 < (n : ℤ), by exact_mod_cast hn) ha
-- TODO: Move to mathlib
lemma integral_pow_inv_Ioi {a : ℝ} {n : ℕ} (hn : 1 < n) (ha : 0 < a) :
∫ x in Ioi a, (x ^ n)⁻¹ = (a ^ (n - 1))⁻¹ / (n - 1) :=
by simp_rw [←zpow_coe_nat, integral_zpow_inv_Ioi (show 1 < (n : ℤ), by exact_mod_cast hn) ha,
int.cast_coe_nat, ←zpow_neg₀, int.coe_nat_sub hn.le, neg_sub, int.coe_nat_one]
lemma fract_mul_integrable {f : ℝ → ℝ} (s : set ℝ)
(hf' : integrable_on f s) :
integrable_on (int.fract * f) s :=
begin
refine integrable.mono hf' _ (eventually_of_forall _),
{ exact measurable_fract.ae_measurable.mul' hf'.1 },
intro x,
simp only [norm_mul, pi.mul_apply, norm_of_nonneg (int.fract_nonneg _)],
exact mul_le_of_le_one_left (norm_nonneg _) (int.fract_lt_one _).le,
end
lemma euler_mascheroni_convergence_rate :
is_O_with 1 (λ x : ℝ, 1 - (∫ t in Ioc 1 x, int.fract t * (t^2)⁻¹) - euler_mascheroni)
(λ x, x⁻¹) at_top :=
begin
apply is_O_with.of_bound,
rw eventually_at_top,
refine ⟨1, λ x (hx : _ ≤ _), _⟩,
have h : integrable_on (λ (x : ℝ), int.fract x * (x ^ 2)⁻¹) (Ioi 1),
{ apply fract_mul_integrable,
apply integrable_on_pow_inv_Ioi one_lt_two zero_lt_one },
rw [one_mul, euler_mascheroni, norm_of_nonneg (inv_nonneg.2 (zero_le_one.trans hx)),
sub_sub_sub_cancel_left, ←integral_diff measurable_set_Ioc h (h.mono_set Ioc_subset_Ioi_self)
Ioc_subset_Ioi_self, Ioi_diff_Icc hx, norm_of_nonneg],
{ apply (set_integral_mono_on (h.mono_set (Ioi_subset_Ioi hx))
(integrable_on_pow_inv_Ioi one_lt_two (zero_lt_one.trans_le hx)) measurable_set_Ioi _).trans,
{ rw integral_pow_inv_Ioi one_lt_two (zero_lt_one.trans_le hx),
norm_num },
{ intros t ht,
exact mul_le_of_le_one_left (inv_nonneg.2 (sq_nonneg _)) (int.fract_lt_one _).le } },
exact set_integral_nonneg measurable_set_Ioi
(λ t ht, div_nonneg (int.fract_nonneg _) (sq_nonneg _)),
end
lemma euler_mascheroni_integral_Ioc_convergence :
tendsto (λ x : ℝ, 1 - ∫ t in Ioc 1 x, int.fract t * (t^2)⁻¹) at_top (𝓝 euler_mascheroni) :=
by simpa using
(euler_mascheroni_convergence_rate.is_O.trans_tendsto tendsto_inv_at_top_zero).add_const
euler_mascheroni
lemma euler_mascheroni_interval_integral_convergence :
tendsto (λ x : ℝ, (1 : ℝ) - ∫ t in 1..x, int.fract t * (t^2)⁻¹) at_top (𝓝 euler_mascheroni) :=
begin
apply euler_mascheroni_integral_Ioc_convergence.congr' _,
rw [eventually_eq, eventually_at_top],
exact ⟨1, λ x hx, by rw interval_integral.integral_of_le hx⟩,
end
lemma nat_floor_eq_int_floor {α : Type*} [linear_ordered_ring α] [floor_ring α]
{y : α} (hy : 0 ≤ y) : (⌊y⌋₊ : ℤ) = ⌊y⌋ :=
begin
rw [eq_comm, int.floor_eq_iff, int.cast_coe_nat],
exact ⟨nat.floor_le hy, nat.lt_floor_add_one y⟩,
end
lemma nat_floor_eq_int_floor' {α : Type*} [linear_ordered_ring α] [floor_ring α]
{y : α} (hy : 0 ≤ y) : (⌊y⌋₊ : α) = ⌊y⌋ :=
begin
rw ←nat_floor_eq_int_floor hy,
simp
end
lemma harmonic_series_is_O_aux {x : ℝ} (hx : 1 ≤ x) :
summatory (λ i, (i : ℝ)⁻¹) 1 x - log x - euler_mascheroni =
(1 - (∫ t in Ioc 1 x, int.fract t * (t^2)⁻¹) - euler_mascheroni) - int.fract x * x⁻¹ :=
begin
have diff : (∀ (i ∈ Ici (1:ℝ)), has_deriv_at (λ x, x⁻¹) (-(i ^ 2)⁻¹) i),
{ rintro i (hi : (1:ℝ) ≤ _),
apply has_deriv_at_inv (zero_lt_one.trans_le hi).ne' },
have cont : continuous_on (λ (i : ℝ), (i ^ 2)⁻¹) (Ici 1),
{ refine ((continuous_pow 2).continuous_on.inv₀ _),
rintro i (hi : _ ≤ _),
exact (pow_ne_zero_iff nat.succ_pos').2 (zero_lt_one.trans_le hi).ne' },
have ps := partial_summation_cont' (λ _, (1 : ℝ)) _ _ one_ne_zero
(by exact_mod_cast diff) (by exact_mod_cast cont.neg) x,
simp only [one_mul] at ps,
simp only [ps, integral_Icc_eq_integral_Ioc],
rw [summatory_const_one, nat_floor_eq_int_floor' (zero_le_one.trans hx), ←int.self_sub_floor,
sub_mul, mul_inv_cancel (zero_lt_one.trans_le hx).ne', sub_sub (1 : ℝ), sub_sub_sub_cancel_left,
sub_sub, sub_sub, sub_right_inj, ←add_assoc, add_left_inj, ←eq_sub_iff_add_eq', nat.cast_one,
←integral_sub],
rotate,
{ apply fract_mul_integrable,
exact (cont.mono Icc_subset_Ici_self).integrable_on_Icc.mono_set Ioc_subset_Icc_self },
{ refine integrable_on.congr_set_ae _ Ioc_ae_eq_Icc,
exact partial_summation_integrable _ (cont.neg.mono Icc_subset_Ici_self).integrable_on_Icc },
have : eq_on (λ a : ℝ, int.fract a * (a ^ 2)⁻¹ - summatory (λ _, (1 : ℝ)) 1 a * -(a ^ 2)⁻¹)
(λ y : ℝ, y⁻¹) (Ioc 1 x),
{ intros y hy,
dsimp,
have : 0 < y := zero_lt_one.trans hy.1,
rw [summatory_const_one, nat_floor_eq_int_floor' this.le, mul_neg, sub_neg_eq_add, ←add_mul,
int.fract_add_floor, sq, mul_inv₀, mul_inv_cancel_left₀ this.ne'] },
rw [set_integral_congr measurable_set_Ioc this, ←interval_integral.integral_of_le hx,
integral_inv_of_pos zero_lt_one (zero_lt_one.trans_le hx), div_one],
end
lemma is_O_with_one_fract_mul (f : ℝ → ℝ) :
is_O_with 1 (λ (x : ℝ), int.fract x * f x) f at_top :=
begin
apply is_O_with.of_bound (eventually_of_forall _),
intro x,
simp only [one_mul, norm_mul],
refine mul_le_of_le_one_left (norm_nonneg _) _,
rw norm_of_nonneg (int.fract_nonneg _),
exact (int.fract_lt_one x).le,
end
lemma harmonic_series_is_O_with :
is_O_with 2 (λ x, summatory (λ i, (i : ℝ)⁻¹) 1 x - log x - euler_mascheroni) (λ x, x⁻¹) at_top :=
begin
have : is_O_with 1 (λ (x : ℝ), int.fract x * x⁻¹) (λ x, x⁻¹) at_top := is_O_with_one_fract_mul _,
refine (euler_mascheroni_convergence_rate.sub this).congr' _ _ eventually_eq.rfl,
{ norm_num1 }, -- I seriously need to prove 1 + 1 = 2
filter_upwards [eventually_ge_at_top (1 : ℝ)],
intros x hx,
exact (harmonic_series_is_O_aux hx).symm,
end
lemma harmonic_series_real_limit :
tendsto (λ x, (∑ i in finset.Icc 1 ⌊x⌋₊, (i : ℝ)⁻¹) - log x) at_top (𝓝 euler_mascheroni) :=
by simpa using
(harmonic_series_is_O_with.is_O.trans_tendsto tendsto_inv_at_top_zero).add_const euler_mascheroni
lemma harmonic_series_limit :
tendsto (λ (n : ℕ), (∑ i in finset.Icc 1 n, (i : ℝ)⁻¹) - log n) at_top (𝓝 euler_mascheroni) :=
(harmonic_series_real_limit.comp tendsto_coe_nat_at_top_at_top).congr (λ x, by simp)
lemma summatory_log_aux {x : ℝ} (hx : 1 ≤ x) :
summatory (λ i, log i) 1 x - (x * log x - x) =
1 + ((∫ t in 1..x, int.fract t * t⁻¹) - int.fract x * log x) :=
begin
rw interval_integral.integral_of_le hx,
have diff : (∀ (i ∈ Ici (1:ℝ)), has_deriv_at log (i⁻¹) i),
{ rintro i (hi : (1:ℝ) ≤ _),
exact has_deriv_at_log (zero_lt_one.trans_le hi).ne' },
have cont : continuous_on (λ x : ℝ, x⁻¹) (Ici 1),
{ exact continuous_on_inv₀.mono (λ x (hx : _ ≤ _), (zero_lt_one.trans_le hx).ne') },
have ps := partial_summation_cont' (λ _, (1 : ℝ)) _ _ one_ne_zero
(by exact_mod_cast diff) (by exact_mod_cast cont) x,
simp only [one_mul] at ps,
simp only [ps, integral_Icc_eq_integral_Ioc],
clear ps,
rw [summatory_const_one, nat_floor_eq_int_floor' (zero_le_one.trans hx), ←int.self_sub_fract,
sub_mul, sub_sub (x * log x), sub_sub_sub_cancel_left, sub_eq_iff_eq_add, add_assoc,
←sub_eq_iff_eq_add', ←add_assoc, sub_add_cancel, nat.cast_one, ←integral_add],
{ rw [←integral_one, interval_integral.integral_of_le hx, set_integral_congr],
{ apply measurable_set_Ioc },
intros y hy,
have hy' : 0 < y := zero_lt_one.trans hy.1,
rw [←add_mul, summatory_const_one, nat_floor_eq_int_floor' hy'.le, int.fract_add_floor,
mul_inv_cancel hy'.ne'] },
{ apply fract_mul_integrable,
exact (cont.mono Icc_subset_Ici_self).integrable_on_Icc.mono_set Ioc_subset_Icc_self },
{ apply (partial_summation_integrable _ _).mono_set Ioc_subset_Icc_self,
exact (cont.mono Icc_subset_Ici_self).integrable_on_Icc },
end
lemma is_o_const_of_tendsto_at_top (f : ℝ → ℝ) (l : filter ℝ) (h : tendsto f l at_top) (c : ℝ) :
is_o (λ (x : ℝ), c) f l :=
begin
rw is_o_iff,
intros ε hε,
have : ∀ᶠ (x : ℝ) in at_top, ∥c∥ ≤ ε * ∥x∥,
{ filter_upwards [eventually_ge_at_top (∥c∥ * ε⁻¹), eventually_ge_at_top (0:ℝ)],
intros x hx₁ hx₂,
rwa [←mul_inv_le_iff hε, norm_of_nonneg hx₂] },
exact h.eventually this,
end
lemma is_o_one_log (c : ℝ) : is_o (λ (x : ℝ), c) log at_top :=
is_o_const_of_tendsto_at_top _ _ tendsto_log_at_top _
lemma summatory_log {c : ℝ} (hc : 2 < c) :
is_O_with c (λ x, summatory (λ i, log i) 1 x - (x * log x - x)) (λ x, log x) at_top :=
begin
have f₁ : is_O_with 1 (λ (x : ℝ), int.fract x * log x) (λ x, log x) at_top :=
is_O_with_one_fract_mul _,
have f₂ : is_o (λ (x : ℝ), (1 : ℝ)) log at_top := is_o_one_log _,
have f₃ : is_O_with 1 (λ (x : ℝ), ∫ t in 1..x, int.fract t * t⁻¹) log at_top,
{ simp only [is_O_with_iff, eventually_at_top, ge_iff_le, one_mul],
refine ⟨1, λ x hx, _⟩,
rw [norm_of_nonneg (log_nonneg hx), norm_of_nonneg, ←div_one x,
←integral_inv_of_pos zero_lt_one (zero_lt_one.trans_le hx), div_one],
swap,
{ apply interval_integral.integral_nonneg hx,
intros y hy,
exact mul_nonneg (int.fract_nonneg _) (inv_nonneg.2 (zero_le_one.trans hy.1)) },
{ have h₁ : interval_integrable (λ (u : ℝ), u⁻¹) volume 1 x,
{ refine interval_integral.interval_integrable_inv _ continuous_on_id,
intros y hy,
rw interval_of_le hx at hy,
exact (zero_lt_one.trans_le hy.1).ne' },
have h₂ : ∀ y ∈ Icc 1 x, int.fract y * y⁻¹ ≤ y⁻¹,
{ intros y hy,
refine mul_le_of_le_one_left (inv_nonneg.2 _) (int.fract_lt_one _).le,
exact zero_le_one.trans hy.1 },
apply interval_integral.integral_mono_on hx _ h₁ h₂,
{ refine h₁.mono_fun' (by measurability) _,
rw [eventually_le, ae_restrict_iff'],
{ apply eventually_of_forall,
intros y hy,
rw interval_oc_of_le hx at hy,
rw [norm_mul, norm_inv, norm_of_nonneg (int.fract_nonneg _),
norm_of_nonneg (zero_le_one.trans hy.1.le)],
apply h₂,
exact Ioc_subset_Icc_self hy },
exact measurable_set_interval_oc } } },
apply (f₂.add_is_O_with (f₃.sub f₁) _).congr' rfl _ eventually_eq.rfl,
{ rw [eventually_eq, eventually_at_top],
exact ⟨1, λ x hx, (summatory_log_aux hx).symm⟩ },
norm_num [hc]
end
lemma summatory_mul_floor_eq_summatory_sum_divisors {x y : ℝ}
(hy : 0 ≤ x) (xy : x ≤ y) (f : ℕ → ℝ) :
summatory (λ n, f n * ⌊x / n⌋) 1 y = summatory (λ n, ∑ i in n.divisors, f i) 1 x :=
begin
simp_rw [summatory, ←nat_floor_eq_int_floor' (div_nonneg hy (nat.cast_nonneg _)),
←summatory_const_one, summatory, finset.mul_sum, mul_one, finset.sum_sigma'],
refine finset.sum_bij _ _ _ _ _,
-- Construct the forward function
{ intros i hi,
exact ⟨i.1 * i.2, i.1⟩ },
-- Show it lands in the correct set
{ rintro ⟨i, j⟩ hi,
simp_rw [finset.mem_sigma, finset.mem_Icc, nat.mem_divisors, dvd_mul_right, true_and, ne.def,
nat.mul_eq_zero, not_or_distrib, ←ne.def, nat.le_floor_iff hy, nat.cast_mul,
←pos_iff_ne_zero, nat.succ_le_iff],
simp only [finset.mem_Icc, finset.mem_sigma, nat.succ_le_iff,
nat.le_floor_iff (div_nonneg hy (nat.cast_nonneg _))] at hi,
refine ⟨⟨mul_pos hi.1.1 hi.2.1, _⟩, hi.1.1, hi.2.1⟩,
apply (le_div_iff' _).1 hi.2.2,
exact nat.cast_pos.2 hi.1.1 },
-- Show it respects the function
{ rintro ⟨i, j⟩,
simp },
-- Show it's injective
{ rintro ⟨i₁, j₁⟩ ⟨i₂, j₂⟩ h₁ h₂ h,
dsimp at h,
simp only [finset.mem_Icc, finset.mem_sigma, nat.succ_le_iff] at h₁ h₂,
simp only [heq_iff_eq] at h ⊢,
cases h.2,
rw mul_right_inj' h₁.1.1.ne' at h,
exact ⟨h.2, h.1⟩ },
-- Show it's surjective
{ rintro ⟨i, j⟩ h,
refine ⟨⟨j, i / j⟩, _⟩,
simp_rw [finset.mem_sigma, finset.mem_Icc, nat.mem_divisors, nat.le_floor_iff hy,
nat.succ_le_iff] at h,
obtain ⟨⟨hij, hx'⟩, ⟨i, rfl⟩, -⟩ := h,
simp_rw [exists_prop],
simp only [canonically_ordered_comm_semiring.mul_pos] at hij,
simp only [finset.mem_Icc, and_true, true_and, eq_self_iff_true, finset.mem_sigma, heq_iff_eq,
nat.succ_le_iff, hij.1, hij.2, nat.mul_div_right, le_div_iff, nat.le_floor_iff (hy.trans xy),
nat.le_floor_iff (div_nonneg hy (nat.cast_nonneg _)), nat.cast_pos, ←nat.cast_mul],
rw [mul_comm] at hx',
refine ⟨le_trans _ (hx'.trans xy), hx'⟩,
rw nat.cast_le,
apply nat.le_mul_of_pos_left hij.2 }
end
namespace nat.arithmetic_function
lemma pow_zero_eq_zeta :
pow 0 = ζ :=
begin
ext i,
simp,
end
lemma sigma_zero_eq_zeta_mul_zeta :
σ 0 = ζ * ζ :=
by rw [←zeta_mul_pow_eq_sigma, pow_zero_eq_zeta]
lemma sigma_zero_apply_eq_sum_divisors {i : ℕ} :
σ 0 i = ∑ d in i.divisors, 1 :=
begin
rw [sigma_apply, finset.sum_congr rfl],
intros x hx,
apply pow_zero,
end
lemma sigma_zero_apply_eq_card_divisors {i : ℕ} :
σ 0 i = i.divisors.card :=
by rw [sigma_zero_apply_eq_sum_divisors, finset.card_eq_sum_ones]
end nat.arithmetic_function
localized "notation `τ` := σ 0" in arithmetic_function
open nat.arithmetic_function
-- BM: Bounds like these make me tempted to define a relation
-- `equal_up_to p f g` to express that `f - g ≪ p` (probably stated `f - g = O(p)`) and show that
-- (for fixed p) this is an equivalence relation, and that it is increasing in `p`
-- Perhaps this would make it easier to express the sorts of calculations that are common in ANT,
-- especially ones like
-- f₁ = f₂ + O(p)
-- = f₃ + O(p)
-- = f₄ + O(p)
-- since this is essentially using transitivity of `equal_up_to p` three times
lemma hyperbola :
is_O (λ x : ℝ, summatory (λ i, (τ i : ℝ)) 1 x - x * log x - (2 * euler_mascheroni - 1) * x)
sqrt at_top :=
sorry
-- This lemma and proof is from Bhavik
lemma exp_sub_mul {x c : ℝ} {hc : 0 ≤ c} : c - c * log c ≤ exp x - c * x :=
begin
rcases eq_or_lt_of_le hc with rfl | hc,
{ simp [(exp_pos _).le] },
suffices : exp (log c) - c * log c ≤ exp x - c * x,
{ rwa exp_log hc at this },
have h₁ : differentiable ℝ (λ x, exp x - c * x) :=
differentiable_exp.sub (differentiable_id.const_mul _),
have h₂ : ∀ t, deriv (λ y, exp y - c * y) t = exp t - c := by simp,
cases le_total (log c) x with hx hx,
{ refine (convex_Icc (log c) x).monotone_on_of_deriv_nonneg h₁.continuous.continuous_on
h₁.differentiable_on _ (left_mem_Icc.2 hx) (right_mem_Icc.2 hx) hx,
intros y hy,
rw interior_Icc at hy,
rw [h₂, sub_nonneg, ←log_le_iff_le_exp hc],
apply hy.1.le },
{ refine (convex_Icc x (log c)).antitone_on_of_deriv_nonpos h₁.continuous.continuous_on
h₁.differentiable_on _ (left_mem_Icc.2 hx) (right_mem_Icc.2 hx) hx,
intros y hy,
rw interior_Icc at hy,
rw [h₂, sub_nonpos, ←le_log_iff_exp_le hc],
apply hy.2.le },
end
lemma div_bound_aux1 (n : ℝ) (r : ℕ) (K : ℝ) (h1 : 2^K < n) (h2 : 0 < K) (hr : 1 ≤ r) :
(r:ℝ) + 1 ≤ n ^ ((r:ℝ)/K) :=
begin
transitivity (2 : ℝ) ^ (r : ℝ),
{ rw add_comm, simpa using one_add_mul_le_pow (show (-2 : ℝ) ≤ 1, by norm_num) r },
{ refine le_trans _ (rpow_le_rpow _ h1.le _),
{ rw [←rpow_mul (zero_le_two : (0 : ℝ) ≤ 2), mul_div_cancel' _ h2.ne'] },
{ refine rpow_nonneg_of_nonneg zero_le_two _ },
{ exact div_nonneg (nat.cast_nonneg _) h2.le } }
end
lemma rpow_two (x : ℝ) : x^(2 : ℝ) = x^2 :=
by rw [←rpow_nat_cast, nat.cast_two]
lemma bernoulli_aux (x : ℝ) (hx : 0 ≤ x) : x + 1/2 ≤ 2^x :=
begin
have h : (0 : ℝ) < log (2 : ℝ) := log_pos one_lt_two,
have h₁ :
1 / real.log 2 - 1 / real.log 2 * log (1 / real.log 2) ≤
exp (real.log 2 * x) - 1 / real.log 2 * (real.log 2 * x),
{ apply exp_sub_mul,
simp only [one_div, inv_nonneg],
apply h.le },
rw [rpow_def_of_pos zero_lt_two, ←le_sub_iff_add_le'],
rw [←mul_assoc, div_mul_cancel _ h.ne', one_mul] at h₁,
apply le_trans _ h₁,
rw [one_div (real.log 2), log_inv],
simp only [one_div, mul_neg, sub_neg_eq_add],
suffices : real.log 2 / 2 - 1 ≤ log (real.log 2),
{ field_simp [h],
rw le_div_iff h,
linarith },
transitivity' (-1/2),
{ linarith [log_two_lt_d9] },
rw [div_le_iff' (@zero_lt_two ℝ _ _), ←log_rpow h, le_log_iff_exp_le (rpow_pos_of_pos h _)],
apply exp_neg_one_lt_d9.le.trans _,
apply le_trans _ (rpow_le_rpow _ log_two_gt_d9.le zero_le_two),
{ rw [rpow_two],
norm_num },
{ norm_num }
end
lemma div_bound_aux2 (n : ℝ) (r : ℕ) (K : ℝ) (h1 : 2 ≤ n) (h2 : 2 ≤ K) (h3 : 1 ≤ r) :
(r:ℝ) + 1 ≤ n ^ ((r:ℝ)/K) * K :=
begin
have h4 : ((r:ℝ)+1)/K ≤ 2^((r:ℝ)/K),
{ transitivity (r:ℝ)/K + (1/2),
rw add_div,
simp only [one_div, add_le_add_iff_left],
apply inv_le_inv_of_le, norm_num, exact h2,
apply bernoulli_aux,
apply div_nonneg,
norm_cast,
linarith, linarith,
},
transitivity (2:ℝ)^((r:ℝ)/K)*K,
{rwa ← div_le_iff, linarith,},
apply mul_le_mul_of_nonneg_right,
rwa rpow_le_rpow_iff,
norm_num, linarith, apply div_pos,
norm_cast, linarith, linarith, linarith,
end
lemma divisor_function_exact_prime_power (r : ℕ) {p : ℕ} (h : p.prime) : σ 0 (p^r) = r + 1 :=
begin
rw [nat.arithmetic_function.sigma_zero_apply_eq_card_divisors, nat.divisors_prime_pow h],
rw [finset.card_map, finset.card_range],
end
variables {R : Type*}
lemma divisor_function_exact {n : ℕ} :
n ≠ 0 → σ 0 n = n.factorization.prod (λ _ k, k + 1) :=
begin
intro hn,
rw [nat.arithmetic_function.is_multiplicative_sigma.multiplicative_factorization _ hn],
apply finsupp.prod_congr,
intros p hp,
rw divisor_function_exact_prime_power _ (nat.prime_of_mem_factorization hp),
end
-- INCOMPLETE PROOF
lemma anyk_divisor_bound (n : ℕ) (K : ℝ) (hK : 2 < K) :
(σ 0 n : ℝ) ≤ ((n : ℝ) ^ (1/K)) * K ^ ((2 : ℝ) ^ K) :=
begin
rcases eq_or_ne n 0 with rfl | hn,
{ simp only [one_div, finset.card_empty, algebra.id.smul_eq_mul, nat.divisors_zero,
nat.cast_zero, zero_mul, finset.sum_const, pow_zero, nat.arithmetic_function.sigma_apply],
rw zero_rpow, { simp },
simp only [inv_eq_zero, ne.def],
linarith },
rw divisor_function_exact hn,
sorry
-- by_cases n = 0,
-- rw h, simp,
-- have h1 : (0 : ℝ) ^ K⁻¹ = 0,
-- { apply zero_rpow, simp, linarith,},
-- rw h1, linarith,
-- have : (σ 0 n) = ∏ p in n.factors.to_finset, (n.factors.count p + 1),
-- { apply divisor_function_exact, exact h,},
-- rw this, clear this,
-- sorry
end
lemma divisor_bound (ε : ℝ) (hε1 : 0 < ε) (hε2 : ε ≤ 1) :
∀ᶠ (n : ℕ) in filter.at_top, (σ 0 n : ℝ) ≤ n ^ (real.log 2 * (1 / log (log (n : ℝ))) * (1 + ε)) :=
begin
sorry
end
lemma weak_divisor_bound (ε : ℝ) (hε : 0 < ε) :
∀ᶠ (n : ℕ) in filter.at_top, (σ 0 n : ℝ) ≤ (n : ℝ)^ε :=
sorry
lemma big_O_divisor_bound (ε : ℝ) (hε : 0 < ε) :
is_O (λ n, (σ 0 n : ℝ)) (λ n, (n : ℝ)^ε) filter.at_top :=
sorry
lemma von_mangoldt_upper {n : ℕ} : Λ n ≤ log (n : ℝ) :=
begin
rcases n.eq_zero_or_pos with rfl | hn,
{ simp },
rw ←von_mangoldt_sum, exact finset.single_le_sum (λ i hi, von_mangoldt_nonneg)
(nat.mem_divisors_self _ hn.ne'),
end
lemma von_mangoldt_summatory {x y : ℝ} (hx : 0 ≤ x) (xy : x ≤ y) :
summatory (λ n, Λ n * ⌊x / n⌋) 1 y = summatory (λ n, real.log n) 1 x :=
by simp only [summatory_mul_floor_eq_summatory_sum_divisors hx xy,
von_mangoldt_sum]
lemma helpful_floor_identity {x : ℝ} :
⌊x⌋ - 2 * ⌊x/2⌋ ≤ 1 :=
begin
rw [←int.lt_add_one_iff, ←@int.cast_lt ℝ],
push_cast,
linarith [int.sub_one_lt_floor (x/2), int.floor_le x],
end
lemma helpful_floor_identity2 {x : ℝ} (hx₁ : 1 ≤ x) (hx₂ : x < 2) :
⌊x⌋ - 2 * ⌊x/2⌋ = 1 :=
begin
have h₁ : ⌊x⌋ = 1,
{ rw [int.floor_eq_iff, int.cast_one],
exact ⟨hx₁, hx₂⟩ },
have h₂ : ⌊x/2⌋ = 0,
{ rw [int.floor_eq_iff],
norm_cast,
split;
linarith },
rw [h₁, h₂],
simp,
end
lemma helpful_floor_identity3 {x : ℝ} :
2 * ⌊x/2⌋ ≤ ⌊x⌋ :=
begin
have h₄ : (2 : ℝ) * ⌊x / 2⌋ - 1 < ⌊x⌋ :=
lt_of_le_of_lt (sub_le_sub_right ((le_div_iff' (by norm_num1)).1 (int.floor_le _)) _)
(int.sub_one_lt_floor x),
norm_cast at h₄,
rwa ←int.sub_one_lt_iff,
end
def chebyshev_error (x : ℝ) : ℝ :=
(summatory (λ i, real.log i) 1 x - (x * log x - x))
- 2 * (summatory (λ i, real.log i) 1 (x/2) - (x/2 * log (x/2) - x/2))
lemma von_mangoldt_floor_sum {x : ℝ} (hx₀ : 0 < x) :
summatory (λ n, Λ n * (⌊x / n⌋ - 2 * ⌊x / n / 2⌋)) 1 x = real.log 2 * x + chebyshev_error x :=
begin
rw [chebyshev_error, mul_sub, log_div hx₀.ne' two_ne_zero, mul_sub, ←mul_assoc,
mul_div_cancel' x two_ne_zero, mul_sub, sub_right_comm (x * log x), ←sub_add _ (_ - _),
sub_add_eq_add_sub, sub_sub_sub_cancel_right, ←sub_sub, mul_comm x, add_sub_cancel'_right,
←von_mangoldt_summatory hx₀.le le_rfl, summatory,
←von_mangoldt_summatory (div_nonneg hx₀.le zero_le_two) (half_le_self hx₀.le), summatory,
summatory, finset.mul_sum, ←finset.sum_sub_distrib, finset.sum_congr rfl],
intros i hi,
rw div_right_comm,
ring,
end
def chebyshev_first (x : ℝ) : ℝ := ∑ n in (finset.range (⌊x⌋₊ + 1)).filter nat.prime, real.log n
def chebyshev_second (x : ℝ) : ℝ := ∑ n in finset.range (⌊x⌋₊ + 1), Λ n
def chebyshev_first' (x : ℝ) : ℝ := ∑ n in (finset.range ⌊x⌋₊).filter nat.prime, real.log n
def chebyshev_second' (x : ℝ) : ℝ := ∑ n in finset.range ⌊x⌋₊, Λ n
localized "notation `ϑ` := chebyshev_first" in analytic_number_theory
localized "notation `ψ` := chebyshev_second" in analytic_number_theory
localized "notation `ϑ'` := chebyshev_first'" in analytic_number_theory
localized "notation `ψ'` := chebyshev_second'" in analytic_number_theory
lemma chebyshev_first_eq {x : ℝ} :
ϑ x = ∑ n in (finset.range (⌊x⌋₊ + 1)).filter nat.prime, Λ n :=
finset.sum_congr rfl (by simp [von_mangoldt_apply_prime] {contextual := tt})
lemma chebyshev_first'_eq {x : ℝ} :
ϑ' x = ∑ n in (finset.range ⌊x⌋₊).filter nat.prime, Λ n :=
finset.sum_congr rfl (by simp [von_mangoldt_apply_prime] {contextual := tt})
lemma chebyshev_first_le_chebyshev_second : ϑ ≤ ψ :=
begin
intro x,
rw chebyshev_first_eq,
exact finset.sum_le_sum_of_subset_of_nonneg (finset.filter_subset _ _)
(λ _ _ _, von_mangoldt_nonneg),
end
lemma chebyshev_first'_le_chebyshev_second' : ϑ' ≤ ψ' :=
begin
intro x,
rw chebyshev_first'_eq,
exact finset.sum_le_sum_of_subset_of_nonneg (finset.filter_subset _ _)
(λ _ _ _, von_mangoldt_nonneg),
end
lemma chebyshev_first_nonneg : 0 ≤ ϑ :=
λ x, by { rw chebyshev_first_eq, exact finset.sum_nonneg' (λ _, von_mangoldt_nonneg) }
lemma chebyshev_first'_nonneg : 0 ≤ ϑ' :=
λ x, by { rw chebyshev_first'_eq, exact finset.sum_nonneg' (λ _, von_mangoldt_nonneg) }
lemma chebyshev_second_nonneg : 0 ≤ ψ :=
λ x, finset.sum_nonneg' (λ _, von_mangoldt_nonneg)
lemma chebyshev_second'_nonneg : 0 ≤ ψ' :=
λ x, finset.sum_nonneg' (λ _, von_mangoldt_nonneg)
lemma log_nat_nonneg : ∀ (n : ℕ), 0 ≤ log (n : ℝ)
| 0 := by simp
| (n+1) := log_nonneg (by simp)
lemma chebyshev_first_monotone : monotone ϑ :=
begin
intros x₁ x₂ h,
apply finset.sum_le_sum_of_subset_of_nonneg,
{ apply finset.filter_subset_filter _ (finset.range_mono (add_le_add_right _ _)),
exact nat.floor_mono h },
rintro i - -,
apply log_nat_nonneg,
end
lemma is_O_chebyshev_first_chebyshev_second : is_O ϑ ψ at_top :=
is_O_of_le _
(λ x, by { rw [norm_of_nonneg (chebyshev_first_nonneg _),
norm_of_nonneg (chebyshev_second_nonneg _)],
exact chebyshev_first_le_chebyshev_second _ })
lemma chebyshev_second_eq_summatory : ψ = summatory Λ 1 :=
begin
ext x,
rw [chebyshev_second, summatory, eq_comm, finset.sum_subset_zero_on_sdiff],
{ exact finset.Icc_subset_range_add_one },
{ intros y hy,
rw [finset.mem_sdiff, finset.mem_range, finset.mem_Icc, nat.lt_add_one_iff, not_and', not_le,
nat.lt_one_iff] at hy,
rw hy.2 hy.1,
simp },
{ intros,
refl }
end
@[simp] lemma chebyshev_first_zero : ϑ 0 = 0 :=
by simp [chebyshev_first_eq, finset.filter_singleton, nat.not_prime_zero]
@[simp] lemma chebyshev_second_zero : ψ 0 = 0 := by simp [chebyshev_second]
@[simp] lemma chebyshev_first'_zero : ϑ' 0 = 0 := by simp [chebyshev_first']
@[simp] lemma chebyshev_second'_zero : ψ' 0 = 0 := by simp [chebyshev_second']
lemma chebyshev_lower_aux {x : ℝ} (hx : 0 < x) :
chebyshev_error x ≤ ψ x - real.log 2 * x :=
begin
rw [le_sub_iff_add_le', ←von_mangoldt_floor_sum hx, chebyshev_second_eq_summatory],
apply finset.sum_le_sum,
intros i hi,
apply mul_le_of_le_one_right von_mangoldt_nonneg,
norm_cast,