state
stringlengths 0
159k
| srcUpToTactic
stringlengths 387
167k
| nextTactic
stringlengths 3
9k
| declUpToTactic
stringlengths 22
11.5k
| declId
stringlengths 38
95
| decl
stringlengths 16
1.89k
| file_tag
stringlengths 17
73
|
---|---|---|---|---|---|---|
case hg.hf
x : β
n_large : 512 β€ x
f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
hf' : β (x : β), 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)
hf : β (x : β), 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3))
h5 : 0 < x
β’ ConvexOn β (Set.Ioi 0.5) fun x => x | /-
Copyright (c) 2020 Patrick Stevens. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Stevens, Bolton Bailey
-/
import Mathlib.Data.Nat.Choose.Factorization
import Mathlib.Data.Nat.PrimeNormNum
import Mathlib.NumberTheory.Primorial
import Mathlib.Analysis.Convex.SpecificFunctions.Basic
import Mathlib.Analysis.Convex.SpecificFunctions.Deriv
#align_import number_theory.bertrand from "leanprover-community/mathlib"@"a16665637b378379689c566204817ae792ac8b39"
/-!
# Bertrand's Postulate
This file contains a proof of Bertrand's postulate: That between any positive number and its
double there is a prime.
The proof follows the outline of the ErdΕs proof presented in "Proofs from THE BOOK": One considers
the prime factorization of `(2 * n).choose n`, and splits the constituent primes up into various
groups, then upper bounds the contribution of each group. This upper bounds the central binomial
coefficient, and if the postulate does not hold, this upper bound conflicts with a simple lower
bound for large enough `n`. This proves the result holds for large enough `n`, and for smaller `n`
an explicit list of primes is provided which covers the remaining cases.
As in the [Metamath implementation](carneiro2015arithmetic), we rely on some optimizations from
[Shigenori Tochiori](tochiori_bertrand). In particular we use the cleaner bound on the central
binomial coefficient given in `Nat.four_pow_lt_mul_centralBinom`.
## References
* [M. Aigner and G. M. Ziegler _Proofs from THE BOOK_][aigner1999proofs]
* [S. Tochiori, _Considering the Proof of βThere is a Prime between n and 2nβ_][tochiori_bertrand]
* [M. Carneiro, _Arithmetic in Metamath, Case Study: Bertrand's Postulate_][carneiro2015arithmetic]
## Tags
Bertrand, prime, binomial coefficients
-/
open scoped BigOperators
section Real
open Real
namespace Bertrand
/-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
| exact convexOn_id (convex_Ioi (0.5 : β)) | /-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
| Mathlib.NumberTheory.Bertrand.51_0.gJXoOT9Ce2wC0xc | /-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x | Mathlib_NumberTheory_Bertrand |
x : β
n_large : 512 β€ x
f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
hf' : β (x : β), 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)
hf : β (x : β), 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3))
h5 : 0 < x
h : ConcaveOn β (Set.Ioi 0.5) f
β’ f x β€ 0 | /-
Copyright (c) 2020 Patrick Stevens. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Stevens, Bolton Bailey
-/
import Mathlib.Data.Nat.Choose.Factorization
import Mathlib.Data.Nat.PrimeNormNum
import Mathlib.NumberTheory.Primorial
import Mathlib.Analysis.Convex.SpecificFunctions.Basic
import Mathlib.Analysis.Convex.SpecificFunctions.Deriv
#align_import number_theory.bertrand from "leanprover-community/mathlib"@"a16665637b378379689c566204817ae792ac8b39"
/-!
# Bertrand's Postulate
This file contains a proof of Bertrand's postulate: That between any positive number and its
double there is a prime.
The proof follows the outline of the ErdΕs proof presented in "Proofs from THE BOOK": One considers
the prime factorization of `(2 * n).choose n`, and splits the constituent primes up into various
groups, then upper bounds the contribution of each group. This upper bounds the central binomial
coefficient, and if the postulate does not hold, this upper bound conflicts with a simple lower
bound for large enough `n`. This proves the result holds for large enough `n`, and for smaller `n`
an explicit list of primes is provided which covers the remaining cases.
As in the [Metamath implementation](carneiro2015arithmetic), we rely on some optimizations from
[Shigenori Tochiori](tochiori_bertrand). In particular we use the cleaner bound on the central
binomial coefficient given in `Nat.four_pow_lt_mul_centralBinom`.
## References
* [M. Aigner and G. M. Ziegler _Proofs from THE BOOK_][aigner1999proofs]
* [S. Tochiori, _Considering the Proof of βThere is a Prime between n and 2nβ_][tochiori_bertrand]
* [M. Carneiro, _Arithmetic in Metamath, Case Study: Bertrand's Postulate_][carneiro2015arithmetic]
## Tags
Bertrand, prime, binomial coefficients
-/
open scoped BigOperators
section Real
open Real
namespace Bertrand
/-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
| suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4 | /-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
| Mathlib.NumberTheory.Bertrand.51_0.gJXoOT9Ce2wC0xc | /-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x | Mathlib_NumberTheory_Bertrand |
x : β
n_large : 512 β€ x
f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
hf' : β (x : β), 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)
hf : β (x : β), 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3))
h5 : 0 < x
h : ConcaveOn β (Set.Ioi 0.5) f
this : β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0
β’ f x β€ 0 | /-
Copyright (c) 2020 Patrick Stevens. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Stevens, Bolton Bailey
-/
import Mathlib.Data.Nat.Choose.Factorization
import Mathlib.Data.Nat.PrimeNormNum
import Mathlib.NumberTheory.Primorial
import Mathlib.Analysis.Convex.SpecificFunctions.Basic
import Mathlib.Analysis.Convex.SpecificFunctions.Deriv
#align_import number_theory.bertrand from "leanprover-community/mathlib"@"a16665637b378379689c566204817ae792ac8b39"
/-!
# Bertrand's Postulate
This file contains a proof of Bertrand's postulate: That between any positive number and its
double there is a prime.
The proof follows the outline of the ErdΕs proof presented in "Proofs from THE BOOK": One considers
the prime factorization of `(2 * n).choose n`, and splits the constituent primes up into various
groups, then upper bounds the contribution of each group. This upper bounds the central binomial
coefficient, and if the postulate does not hold, this upper bound conflicts with a simple lower
bound for large enough `n`. This proves the result holds for large enough `n`, and for smaller `n`
an explicit list of primes is provided which covers the remaining cases.
As in the [Metamath implementation](carneiro2015arithmetic), we rely on some optimizations from
[Shigenori Tochiori](tochiori_bertrand). In particular we use the cleaner bound on the central
binomial coefficient given in `Nat.four_pow_lt_mul_centralBinom`.
## References
* [M. Aigner and G. M. Ziegler _Proofs from THE BOOK_][aigner1999proofs]
* [S. Tochiori, _Considering the Proof of βThere is a Prime between n and 2nβ_][tochiori_bertrand]
* [M. Carneiro, _Arithmetic in Metamath, Case Study: Bertrand's Postulate_][carneiro2015arithmetic]
## Tags
Bertrand, prime, binomial coefficients
-/
open scoped BigOperators
section Real
open Real
namespace Bertrand
/-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
| obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this | /-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
| Mathlib.NumberTheory.Bertrand.51_0.gJXoOT9Ce2wC0xc | /-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x | Mathlib_NumberTheory_Bertrand |
case intro.intro.intro.intro.intro.intro
x : β
n_large : 512 β€ x
f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
hf' : β (x : β), 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)
hf : β (x : β), 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3))
h5 : 0 < x
h : ConcaveOn β (Set.Ioi 0.5) f
x1 x2 : β
h1 : 0.5 < x1
h2 : x1 < x2
h0 : x2 β€ x
h3 : 0 β€ f x1
h4 : f x2 β€ 0
β’ f x β€ 0 | /-
Copyright (c) 2020 Patrick Stevens. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Stevens, Bolton Bailey
-/
import Mathlib.Data.Nat.Choose.Factorization
import Mathlib.Data.Nat.PrimeNormNum
import Mathlib.NumberTheory.Primorial
import Mathlib.Analysis.Convex.SpecificFunctions.Basic
import Mathlib.Analysis.Convex.SpecificFunctions.Deriv
#align_import number_theory.bertrand from "leanprover-community/mathlib"@"a16665637b378379689c566204817ae792ac8b39"
/-!
# Bertrand's Postulate
This file contains a proof of Bertrand's postulate: That between any positive number and its
double there is a prime.
The proof follows the outline of the ErdΕs proof presented in "Proofs from THE BOOK": One considers
the prime factorization of `(2 * n).choose n`, and splits the constituent primes up into various
groups, then upper bounds the contribution of each group. This upper bounds the central binomial
coefficient, and if the postulate does not hold, this upper bound conflicts with a simple lower
bound for large enough `n`. This proves the result holds for large enough `n`, and for smaller `n`
an explicit list of primes is provided which covers the remaining cases.
As in the [Metamath implementation](carneiro2015arithmetic), we rely on some optimizations from
[Shigenori Tochiori](tochiori_bertrand). In particular we use the cleaner bound on the central
binomial coefficient given in `Nat.four_pow_lt_mul_centralBinom`.
## References
* [M. Aigner and G. M. Ziegler _Proofs from THE BOOK_][aigner1999proofs]
* [S. Tochiori, _Considering the Proof of βThere is a Prime between n and 2nβ_][tochiori_bertrand]
* [M. Carneiro, _Arithmetic in Metamath, Case Study: Bertrand's Postulate_][carneiro2015arithmetic]
## Tags
Bertrand, prime, binomial coefficients
-/
open scoped BigOperators
section Real
open Real
namespace Bertrand
/-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
| exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4 | /-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
| Mathlib.NumberTheory.Bertrand.51_0.gJXoOT9Ce2wC0xc | /-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x | Mathlib_NumberTheory_Bertrand |
x : β
n_large : 512 β€ x
f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
hf' : β (x : β), 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)
hf : β (x : β), 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3))
h5 : 0 < x
h : ConcaveOn β (Set.Ioi 0.5) f
β’ β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 | /-
Copyright (c) 2020 Patrick Stevens. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Stevens, Bolton Bailey
-/
import Mathlib.Data.Nat.Choose.Factorization
import Mathlib.Data.Nat.PrimeNormNum
import Mathlib.NumberTheory.Primorial
import Mathlib.Analysis.Convex.SpecificFunctions.Basic
import Mathlib.Analysis.Convex.SpecificFunctions.Deriv
#align_import number_theory.bertrand from "leanprover-community/mathlib"@"a16665637b378379689c566204817ae792ac8b39"
/-!
# Bertrand's Postulate
This file contains a proof of Bertrand's postulate: That between any positive number and its
double there is a prime.
The proof follows the outline of the ErdΕs proof presented in "Proofs from THE BOOK": One considers
the prime factorization of `(2 * n).choose n`, and splits the constituent primes up into various
groups, then upper bounds the contribution of each group. This upper bounds the central binomial
coefficient, and if the postulate does not hold, this upper bound conflicts with a simple lower
bound for large enough `n`. This proves the result holds for large enough `n`, and for smaller `n`
an explicit list of primes is provided which covers the remaining cases.
As in the [Metamath implementation](carneiro2015arithmetic), we rely on some optimizations from
[Shigenori Tochiori](tochiori_bertrand). In particular we use the cleaner bound on the central
binomial coefficient given in `Nat.four_pow_lt_mul_centralBinom`.
## References
* [M. Aigner and G. M. Ziegler _Proofs from THE BOOK_][aigner1999proofs]
* [S. Tochiori, _Considering the Proof of βThere is a Prime between n and 2nβ_][tochiori_bertrand]
* [M. Carneiro, _Arithmetic in Metamath, Case Study: Bertrand's Postulate_][carneiro2015arithmetic]
## Tags
Bertrand, prime, binomial coefficients
-/
open scoped BigOperators
section Real
open Real
namespace Bertrand
/-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
| refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β© | /-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
| Mathlib.NumberTheory.Bertrand.51_0.gJXoOT9Ce2wC0xc | /-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x | Mathlib_NumberTheory_Bertrand |
x : β
n_large : 512 β€ x
f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
hf' : β (x : β), 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)
hf : β (x : β), 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3))
h5 : 0 < x
h : ConcaveOn β (Set.Ioi 0.5) f
β’ 0.5 < 18 | /-
Copyright (c) 2020 Patrick Stevens. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Stevens, Bolton Bailey
-/
import Mathlib.Data.Nat.Choose.Factorization
import Mathlib.Data.Nat.PrimeNormNum
import Mathlib.NumberTheory.Primorial
import Mathlib.Analysis.Convex.SpecificFunctions.Basic
import Mathlib.Analysis.Convex.SpecificFunctions.Deriv
#align_import number_theory.bertrand from "leanprover-community/mathlib"@"a16665637b378379689c566204817ae792ac8b39"
/-!
# Bertrand's Postulate
This file contains a proof of Bertrand's postulate: That between any positive number and its
double there is a prime.
The proof follows the outline of the ErdΕs proof presented in "Proofs from THE BOOK": One considers
the prime factorization of `(2 * n).choose n`, and splits the constituent primes up into various
groups, then upper bounds the contribution of each group. This upper bounds the central binomial
coefficient, and if the postulate does not hold, this upper bound conflicts with a simple lower
bound for large enough `n`. This proves the result holds for large enough `n`, and for smaller `n`
an explicit list of primes is provided which covers the remaining cases.
As in the [Metamath implementation](carneiro2015arithmetic), we rely on some optimizations from
[Shigenori Tochiori](tochiori_bertrand). In particular we use the cleaner bound on the central
binomial coefficient given in `Nat.four_pow_lt_mul_centralBinom`.
## References
* [M. Aigner and G. M. Ziegler _Proofs from THE BOOK_][aigner1999proofs]
* [S. Tochiori, _Considering the Proof of βThere is a Prime between n and 2nβ_][tochiori_bertrand]
* [M. Carneiro, _Arithmetic in Metamath, Case Study: Bertrand's Postulate_][carneiro2015arithmetic]
## Tags
Bertrand, prime, binomial coefficients
-/
open scoped BigOperators
section Real
open Real
namespace Bertrand
/-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by | norm_num1 | /-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by | Mathlib.NumberTheory.Bertrand.51_0.gJXoOT9Ce2wC0xc | /-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x | Mathlib_NumberTheory_Bertrand |
x : β
n_large : 512 β€ x
f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
hf' : β (x : β), 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)
hf : β (x : β), 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3))
h5 : 0 < x
h : ConcaveOn β (Set.Ioi 0.5) f
β’ 18 < 512 | /-
Copyright (c) 2020 Patrick Stevens. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Stevens, Bolton Bailey
-/
import Mathlib.Data.Nat.Choose.Factorization
import Mathlib.Data.Nat.PrimeNormNum
import Mathlib.NumberTheory.Primorial
import Mathlib.Analysis.Convex.SpecificFunctions.Basic
import Mathlib.Analysis.Convex.SpecificFunctions.Deriv
#align_import number_theory.bertrand from "leanprover-community/mathlib"@"a16665637b378379689c566204817ae792ac8b39"
/-!
# Bertrand's Postulate
This file contains a proof of Bertrand's postulate: That between any positive number and its
double there is a prime.
The proof follows the outline of the ErdΕs proof presented in "Proofs from THE BOOK": One considers
the prime factorization of `(2 * n).choose n`, and splits the constituent primes up into various
groups, then upper bounds the contribution of each group. This upper bounds the central binomial
coefficient, and if the postulate does not hold, this upper bound conflicts with a simple lower
bound for large enough `n`. This proves the result holds for large enough `n`, and for smaller `n`
an explicit list of primes is provided which covers the remaining cases.
As in the [Metamath implementation](carneiro2015arithmetic), we rely on some optimizations from
[Shigenori Tochiori](tochiori_bertrand). In particular we use the cleaner bound on the central
binomial coefficient given in `Nat.four_pow_lt_mul_centralBinom`.
## References
* [M. Aigner and G. M. Ziegler _Proofs from THE BOOK_][aigner1999proofs]
* [S. Tochiori, _Considering the Proof of βThere is a Prime between n and 2nβ_][tochiori_bertrand]
* [M. Carneiro, _Arithmetic in Metamath, Case Study: Bertrand's Postulate_][carneiro2015arithmetic]
## Tags
Bertrand, prime, binomial coefficients
-/
open scoped BigOperators
section Real
open Real
namespace Bertrand
/-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by | norm_num1 | /-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by | Mathlib.NumberTheory.Bertrand.51_0.gJXoOT9Ce2wC0xc | /-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x | Mathlib_NumberTheory_Bertrand |
case refine'_1
x : β
n_large : 512 β€ x
f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
hf' : β (x : β), 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)
hf : β (x : β), 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3))
h5 : 0 < x
h : ConcaveOn β (Set.Ioi 0.5) f
β’ 0 β€ f 18 | /-
Copyright (c) 2020 Patrick Stevens. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Stevens, Bolton Bailey
-/
import Mathlib.Data.Nat.Choose.Factorization
import Mathlib.Data.Nat.PrimeNormNum
import Mathlib.NumberTheory.Primorial
import Mathlib.Analysis.Convex.SpecificFunctions.Basic
import Mathlib.Analysis.Convex.SpecificFunctions.Deriv
#align_import number_theory.bertrand from "leanprover-community/mathlib"@"a16665637b378379689c566204817ae792ac8b39"
/-!
# Bertrand's Postulate
This file contains a proof of Bertrand's postulate: That between any positive number and its
double there is a prime.
The proof follows the outline of the ErdΕs proof presented in "Proofs from THE BOOK": One considers
the prime factorization of `(2 * n).choose n`, and splits the constituent primes up into various
groups, then upper bounds the contribution of each group. This upper bounds the central binomial
coefficient, and if the postulate does not hold, this upper bound conflicts with a simple lower
bound for large enough `n`. This proves the result holds for large enough `n`, and for smaller `n`
an explicit list of primes is provided which covers the remaining cases.
As in the [Metamath implementation](carneiro2015arithmetic), we rely on some optimizations from
[Shigenori Tochiori](tochiori_bertrand). In particular we use the cleaner bound on the central
binomial coefficient given in `Nat.four_pow_lt_mul_centralBinom`.
## References
* [M. Aigner and G. M. Ziegler _Proofs from THE BOOK_][aigner1999proofs]
* [S. Tochiori, _Considering the Proof of βThere is a Prime between n and 2nβ_][tochiori_bertrand]
* [M. Carneiro, _Arithmetic in Metamath, Case Study: Bertrand's Postulate_][carneiro2015arithmetic]
## Tags
Bertrand, prime, binomial coefficients
-/
open scoped BigOperators
section Real
open Real
namespace Bertrand
/-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· | have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1) | /-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· | Mathlib.NumberTheory.Bertrand.51_0.gJXoOT9Ce2wC0xc | /-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x | Mathlib_NumberTheory_Bertrand |
x : β
n_large : 512 β€ x
f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
hf' : β (x : β), 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)
hf : β (x : β), 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3))
h5 : 0 < x
h : ConcaveOn β (Set.Ioi 0.5) f
β’ 0 < 6 | /-
Copyright (c) 2020 Patrick Stevens. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Stevens, Bolton Bailey
-/
import Mathlib.Data.Nat.Choose.Factorization
import Mathlib.Data.Nat.PrimeNormNum
import Mathlib.NumberTheory.Primorial
import Mathlib.Analysis.Convex.SpecificFunctions.Basic
import Mathlib.Analysis.Convex.SpecificFunctions.Deriv
#align_import number_theory.bertrand from "leanprover-community/mathlib"@"a16665637b378379689c566204817ae792ac8b39"
/-!
# Bertrand's Postulate
This file contains a proof of Bertrand's postulate: That between any positive number and its
double there is a prime.
The proof follows the outline of the ErdΕs proof presented in "Proofs from THE BOOK": One considers
the prime factorization of `(2 * n).choose n`, and splits the constituent primes up into various
groups, then upper bounds the contribution of each group. This upper bounds the central binomial
coefficient, and if the postulate does not hold, this upper bound conflicts with a simple lower
bound for large enough `n`. This proves the result holds for large enough `n`, and for smaller `n`
an explicit list of primes is provided which covers the remaining cases.
As in the [Metamath implementation](carneiro2015arithmetic), we rely on some optimizations from
[Shigenori Tochiori](tochiori_bertrand). In particular we use the cleaner bound on the central
binomial coefficient given in `Nat.four_pow_lt_mul_centralBinom`.
## References
* [M. Aigner and G. M. Ziegler _Proofs from THE BOOK_][aigner1999proofs]
* [S. Tochiori, _Considering the Proof of βThere is a Prime between n and 2nβ_][tochiori_bertrand]
* [M. Carneiro, _Arithmetic in Metamath, Case Study: Bertrand's Postulate_][carneiro2015arithmetic]
## Tags
Bertrand, prime, binomial coefficients
-/
open scoped BigOperators
section Real
open Real
namespace Bertrand
/-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by | norm_num1 | /-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by | Mathlib.NumberTheory.Bertrand.51_0.gJXoOT9Ce2wC0xc | /-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x | Mathlib_NumberTheory_Bertrand |
x : β
n_large : 512 β€ x
f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
hf' : β (x : β), 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)
hf : β (x : β), 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3))
h5 : 0 < x
h : ConcaveOn β (Set.Ioi 0.5) f
β’ 6 * 6 = 2 * 18 | /-
Copyright (c) 2020 Patrick Stevens. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Stevens, Bolton Bailey
-/
import Mathlib.Data.Nat.Choose.Factorization
import Mathlib.Data.Nat.PrimeNormNum
import Mathlib.NumberTheory.Primorial
import Mathlib.Analysis.Convex.SpecificFunctions.Basic
import Mathlib.Analysis.Convex.SpecificFunctions.Deriv
#align_import number_theory.bertrand from "leanprover-community/mathlib"@"a16665637b378379689c566204817ae792ac8b39"
/-!
# Bertrand's Postulate
This file contains a proof of Bertrand's postulate: That between any positive number and its
double there is a prime.
The proof follows the outline of the ErdΕs proof presented in "Proofs from THE BOOK": One considers
the prime factorization of `(2 * n).choose n`, and splits the constituent primes up into various
groups, then upper bounds the contribution of each group. This upper bounds the central binomial
coefficient, and if the postulate does not hold, this upper bound conflicts with a simple lower
bound for large enough `n`. This proves the result holds for large enough `n`, and for smaller `n`
an explicit list of primes is provided which covers the remaining cases.
As in the [Metamath implementation](carneiro2015arithmetic), we rely on some optimizations from
[Shigenori Tochiori](tochiori_bertrand). In particular we use the cleaner bound on the central
binomial coefficient given in `Nat.four_pow_lt_mul_centralBinom`.
## References
* [M. Aigner and G. M. Ziegler _Proofs from THE BOOK_][aigner1999proofs]
* [S. Tochiori, _Considering the Proof of βThere is a Prime between n and 2nβ_][tochiori_bertrand]
* [M. Carneiro, _Arithmetic in Metamath, Case Study: Bertrand's Postulate_][carneiro2015arithmetic]
## Tags
Bertrand, prime, binomial coefficients
-/
open scoped BigOperators
section Real
open Real
namespace Bertrand
/-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by | norm_num1 | /-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by | Mathlib.NumberTheory.Bertrand.51_0.gJXoOT9Ce2wC0xc | /-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x | Mathlib_NumberTheory_Bertrand |
case refine'_1
x : β
n_large : 512 β€ x
f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
hf' : β (x : β), 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)
hf : β (x : β), 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3))
h5 : 0 < x
h : ConcaveOn β (Set.Ioi 0.5) f
this : sqrt (2 * 18) = 6
β’ 0 β€ f 18 | /-
Copyright (c) 2020 Patrick Stevens. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Stevens, Bolton Bailey
-/
import Mathlib.Data.Nat.Choose.Factorization
import Mathlib.Data.Nat.PrimeNormNum
import Mathlib.NumberTheory.Primorial
import Mathlib.Analysis.Convex.SpecificFunctions.Basic
import Mathlib.Analysis.Convex.SpecificFunctions.Deriv
#align_import number_theory.bertrand from "leanprover-community/mathlib"@"a16665637b378379689c566204817ae792ac8b39"
/-!
# Bertrand's Postulate
This file contains a proof of Bertrand's postulate: That between any positive number and its
double there is a prime.
The proof follows the outline of the ErdΕs proof presented in "Proofs from THE BOOK": One considers
the prime factorization of `(2 * n).choose n`, and splits the constituent primes up into various
groups, then upper bounds the contribution of each group. This upper bounds the central binomial
coefficient, and if the postulate does not hold, this upper bound conflicts with a simple lower
bound for large enough `n`. This proves the result holds for large enough `n`, and for smaller `n`
an explicit list of primes is provided which covers the remaining cases.
As in the [Metamath implementation](carneiro2015arithmetic), we rely on some optimizations from
[Shigenori Tochiori](tochiori_bertrand). In particular we use the cleaner bound on the central
binomial coefficient given in `Nat.four_pow_lt_mul_centralBinom`.
## References
* [M. Aigner and G. M. Ziegler _Proofs from THE BOOK_][aigner1999proofs]
* [S. Tochiori, _Considering the Proof of βThere is a Prime between n and 2nβ_][tochiori_bertrand]
* [M. Carneiro, _Arithmetic in Metamath, Case Study: Bertrand's Postulate_][carneiro2015arithmetic]
## Tags
Bertrand, prime, binomial coefficients
-/
open scoped BigOperators
section Real
open Real
namespace Bertrand
/-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
| rw [hf, log_nonneg_iff, this] | /-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
| Mathlib.NumberTheory.Bertrand.51_0.gJXoOT9Ce2wC0xc | /-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x | Mathlib_NumberTheory_Bertrand |
case refine'_1
x : β
n_large : 512 β€ x
f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
hf' : β (x : β), 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)
hf : β (x : β), 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3))
h5 : 0 < x
h : ConcaveOn β (Set.Ioi 0.5) f
this : sqrt (2 * 18) = 6
β’ 1 β€ 18 * (2 * 18) ^ 6 / 4 ^ (18 / 3) | /-
Copyright (c) 2020 Patrick Stevens. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Stevens, Bolton Bailey
-/
import Mathlib.Data.Nat.Choose.Factorization
import Mathlib.Data.Nat.PrimeNormNum
import Mathlib.NumberTheory.Primorial
import Mathlib.Analysis.Convex.SpecificFunctions.Basic
import Mathlib.Analysis.Convex.SpecificFunctions.Deriv
#align_import number_theory.bertrand from "leanprover-community/mathlib"@"a16665637b378379689c566204817ae792ac8b39"
/-!
# Bertrand's Postulate
This file contains a proof of Bertrand's postulate: That between any positive number and its
double there is a prime.
The proof follows the outline of the ErdΕs proof presented in "Proofs from THE BOOK": One considers
the prime factorization of `(2 * n).choose n`, and splits the constituent primes up into various
groups, then upper bounds the contribution of each group. This upper bounds the central binomial
coefficient, and if the postulate does not hold, this upper bound conflicts with a simple lower
bound for large enough `n`. This proves the result holds for large enough `n`, and for smaller `n`
an explicit list of primes is provided which covers the remaining cases.
As in the [Metamath implementation](carneiro2015arithmetic), we rely on some optimizations from
[Shigenori Tochiori](tochiori_bertrand). In particular we use the cleaner bound on the central
binomial coefficient given in `Nat.four_pow_lt_mul_centralBinom`.
## References
* [M. Aigner and G. M. Ziegler _Proofs from THE BOOK_][aigner1999proofs]
* [S. Tochiori, _Considering the Proof of βThere is a Prime between n and 2nβ_][tochiori_bertrand]
* [M. Carneiro, _Arithmetic in Metamath, Case Study: Bertrand's Postulate_][carneiro2015arithmetic]
## Tags
Bertrand, prime, binomial coefficients
-/
open scoped BigOperators
section Real
open Real
namespace Bertrand
/-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
| rw [one_le_div] | /-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
| Mathlib.NumberTheory.Bertrand.51_0.gJXoOT9Ce2wC0xc | /-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x | Mathlib_NumberTheory_Bertrand |
case refine'_1
x : β
n_large : 512 β€ x
f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
hf' : β (x : β), 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)
hf : β (x : β), 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3))
h5 : 0 < x
h : ConcaveOn β (Set.Ioi 0.5) f
this : sqrt (2 * 18) = 6
β’ 4 ^ (18 / 3) β€ 18 * (2 * 18) ^ 6 | /-
Copyright (c) 2020 Patrick Stevens. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Stevens, Bolton Bailey
-/
import Mathlib.Data.Nat.Choose.Factorization
import Mathlib.Data.Nat.PrimeNormNum
import Mathlib.NumberTheory.Primorial
import Mathlib.Analysis.Convex.SpecificFunctions.Basic
import Mathlib.Analysis.Convex.SpecificFunctions.Deriv
#align_import number_theory.bertrand from "leanprover-community/mathlib"@"a16665637b378379689c566204817ae792ac8b39"
/-!
# Bertrand's Postulate
This file contains a proof of Bertrand's postulate: That between any positive number and its
double there is a prime.
The proof follows the outline of the ErdΕs proof presented in "Proofs from THE BOOK": One considers
the prime factorization of `(2 * n).choose n`, and splits the constituent primes up into various
groups, then upper bounds the contribution of each group. This upper bounds the central binomial
coefficient, and if the postulate does not hold, this upper bound conflicts with a simple lower
bound for large enough `n`. This proves the result holds for large enough `n`, and for smaller `n`
an explicit list of primes is provided which covers the remaining cases.
As in the [Metamath implementation](carneiro2015arithmetic), we rely on some optimizations from
[Shigenori Tochiori](tochiori_bertrand). In particular we use the cleaner bound on the central
binomial coefficient given in `Nat.four_pow_lt_mul_centralBinom`.
## References
* [M. Aigner and G. M. Ziegler _Proofs from THE BOOK_][aigner1999proofs]
* [S. Tochiori, _Considering the Proof of βThere is a Prime between n and 2nβ_][tochiori_bertrand]
* [M. Carneiro, _Arithmetic in Metamath, Case Study: Bertrand's Postulate_][carneiro2015arithmetic]
## Tags
Bertrand, prime, binomial coefficients
-/
open scoped BigOperators
section Real
open Real
namespace Bertrand
/-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> | norm_num1 | /-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> | Mathlib.NumberTheory.Bertrand.51_0.gJXoOT9Ce2wC0xc | /-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x | Mathlib_NumberTheory_Bertrand |
case refine'_1
x : β
n_large : 512 β€ x
f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
hf' : β (x : β), 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)
hf : β (x : β), 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3))
h5 : 0 < x
h : ConcaveOn β (Set.Ioi 0.5) f
this : sqrt (2 * 18) = 6
β’ 0 < 4 ^ (18 / 3) | /-
Copyright (c) 2020 Patrick Stevens. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Stevens, Bolton Bailey
-/
import Mathlib.Data.Nat.Choose.Factorization
import Mathlib.Data.Nat.PrimeNormNum
import Mathlib.NumberTheory.Primorial
import Mathlib.Analysis.Convex.SpecificFunctions.Basic
import Mathlib.Analysis.Convex.SpecificFunctions.Deriv
#align_import number_theory.bertrand from "leanprover-community/mathlib"@"a16665637b378379689c566204817ae792ac8b39"
/-!
# Bertrand's Postulate
This file contains a proof of Bertrand's postulate: That between any positive number and its
double there is a prime.
The proof follows the outline of the ErdΕs proof presented in "Proofs from THE BOOK": One considers
the prime factorization of `(2 * n).choose n`, and splits the constituent primes up into various
groups, then upper bounds the contribution of each group. This upper bounds the central binomial
coefficient, and if the postulate does not hold, this upper bound conflicts with a simple lower
bound for large enough `n`. This proves the result holds for large enough `n`, and for smaller `n`
an explicit list of primes is provided which covers the remaining cases.
As in the [Metamath implementation](carneiro2015arithmetic), we rely on some optimizations from
[Shigenori Tochiori](tochiori_bertrand). In particular we use the cleaner bound on the central
binomial coefficient given in `Nat.four_pow_lt_mul_centralBinom`.
## References
* [M. Aigner and G. M. Ziegler _Proofs from THE BOOK_][aigner1999proofs]
* [S. Tochiori, _Considering the Proof of βThere is a Prime between n and 2nβ_][tochiori_bertrand]
* [M. Carneiro, _Arithmetic in Metamath, Case Study: Bertrand's Postulate_][carneiro2015arithmetic]
## Tags
Bertrand, prime, binomial coefficients
-/
open scoped BigOperators
section Real
open Real
namespace Bertrand
/-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> | norm_num1 | /-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> | Mathlib.NumberTheory.Bertrand.51_0.gJXoOT9Ce2wC0xc | /-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x | Mathlib_NumberTheory_Bertrand |
case refine'_1
x : β
n_large : 512 β€ x
f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
hf' : β (x : β), 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)
hf : β (x : β), 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3))
h5 : 0 < x
h : ConcaveOn β (Set.Ioi 0.5) f
this : sqrt (2 * 18) = 6
β’ 4 ^ 6 β€ 18 * 36 ^ 6 | /-
Copyright (c) 2020 Patrick Stevens. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Stevens, Bolton Bailey
-/
import Mathlib.Data.Nat.Choose.Factorization
import Mathlib.Data.Nat.PrimeNormNum
import Mathlib.NumberTheory.Primorial
import Mathlib.Analysis.Convex.SpecificFunctions.Basic
import Mathlib.Analysis.Convex.SpecificFunctions.Deriv
#align_import number_theory.bertrand from "leanprover-community/mathlib"@"a16665637b378379689c566204817ae792ac8b39"
/-!
# Bertrand's Postulate
This file contains a proof of Bertrand's postulate: That between any positive number and its
double there is a prime.
The proof follows the outline of the ErdΕs proof presented in "Proofs from THE BOOK": One considers
the prime factorization of `(2 * n).choose n`, and splits the constituent primes up into various
groups, then upper bounds the contribution of each group. This upper bounds the central binomial
coefficient, and if the postulate does not hold, this upper bound conflicts with a simple lower
bound for large enough `n`. This proves the result holds for large enough `n`, and for smaller `n`
an explicit list of primes is provided which covers the remaining cases.
As in the [Metamath implementation](carneiro2015arithmetic), we rely on some optimizations from
[Shigenori Tochiori](tochiori_bertrand). In particular we use the cleaner bound on the central
binomial coefficient given in `Nat.four_pow_lt_mul_centralBinom`.
## References
* [M. Aigner and G. M. Ziegler _Proofs from THE BOOK_][aigner1999proofs]
* [S. Tochiori, _Considering the Proof of βThere is a Prime between n and 2nβ_][tochiori_bertrand]
* [M. Carneiro, _Arithmetic in Metamath, Case Study: Bertrand's Postulate_][carneiro2015arithmetic]
## Tags
Bertrand, prime, binomial coefficients
-/
open scoped BigOperators
section Real
open Real
namespace Bertrand
/-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> norm_num1
| apply le_trans _ (le_mul_of_one_le_left _ _) | /-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> norm_num1
| Mathlib.NumberTheory.Bertrand.51_0.gJXoOT9Ce2wC0xc | /-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x | Mathlib_NumberTheory_Bertrand |
x : β
n_large : 512 β€ x
f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
hf' : β (x : β), 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)
hf : β (x : β), 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3))
h5 : 0 < x
h : ConcaveOn β (Set.Ioi 0.5) f
this : sqrt (2 * 18) = 6
β’ 4 ^ 6 β€ 36 ^ 6 | /-
Copyright (c) 2020 Patrick Stevens. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Stevens, Bolton Bailey
-/
import Mathlib.Data.Nat.Choose.Factorization
import Mathlib.Data.Nat.PrimeNormNum
import Mathlib.NumberTheory.Primorial
import Mathlib.Analysis.Convex.SpecificFunctions.Basic
import Mathlib.Analysis.Convex.SpecificFunctions.Deriv
#align_import number_theory.bertrand from "leanprover-community/mathlib"@"a16665637b378379689c566204817ae792ac8b39"
/-!
# Bertrand's Postulate
This file contains a proof of Bertrand's postulate: That between any positive number and its
double there is a prime.
The proof follows the outline of the ErdΕs proof presented in "Proofs from THE BOOK": One considers
the prime factorization of `(2 * n).choose n`, and splits the constituent primes up into various
groups, then upper bounds the contribution of each group. This upper bounds the central binomial
coefficient, and if the postulate does not hold, this upper bound conflicts with a simple lower
bound for large enough `n`. This proves the result holds for large enough `n`, and for smaller `n`
an explicit list of primes is provided which covers the remaining cases.
As in the [Metamath implementation](carneiro2015arithmetic), we rely on some optimizations from
[Shigenori Tochiori](tochiori_bertrand). In particular we use the cleaner bound on the central
binomial coefficient given in `Nat.four_pow_lt_mul_centralBinom`.
## References
* [M. Aigner and G. M. Ziegler _Proofs from THE BOOK_][aigner1999proofs]
* [S. Tochiori, _Considering the Proof of βThere is a Prime between n and 2nβ_][tochiori_bertrand]
* [M. Carneiro, _Arithmetic in Metamath, Case Study: Bertrand's Postulate_][carneiro2015arithmetic]
## Tags
Bertrand, prime, binomial coefficients
-/
open scoped BigOperators
section Real
open Real
namespace Bertrand
/-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> norm_num1
apply le_trans _ (le_mul_of_one_le_left _ _) <;> | norm_num1 | /-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> norm_num1
apply le_trans _ (le_mul_of_one_le_left _ _) <;> | Mathlib.NumberTheory.Bertrand.51_0.gJXoOT9Ce2wC0xc | /-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x | Mathlib_NumberTheory_Bertrand |
x : β
n_large : 512 β€ x
f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
hf' : β (x : β), 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)
hf : β (x : β), 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3))
h5 : 0 < x
h : ConcaveOn β (Set.Ioi 0.5) f
this : sqrt (2 * 18) = 6
β’ 0 β€ 36 ^ 6 | /-
Copyright (c) 2020 Patrick Stevens. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Stevens, Bolton Bailey
-/
import Mathlib.Data.Nat.Choose.Factorization
import Mathlib.Data.Nat.PrimeNormNum
import Mathlib.NumberTheory.Primorial
import Mathlib.Analysis.Convex.SpecificFunctions.Basic
import Mathlib.Analysis.Convex.SpecificFunctions.Deriv
#align_import number_theory.bertrand from "leanprover-community/mathlib"@"a16665637b378379689c566204817ae792ac8b39"
/-!
# Bertrand's Postulate
This file contains a proof of Bertrand's postulate: That between any positive number and its
double there is a prime.
The proof follows the outline of the ErdΕs proof presented in "Proofs from THE BOOK": One considers
the prime factorization of `(2 * n).choose n`, and splits the constituent primes up into various
groups, then upper bounds the contribution of each group. This upper bounds the central binomial
coefficient, and if the postulate does not hold, this upper bound conflicts with a simple lower
bound for large enough `n`. This proves the result holds for large enough `n`, and for smaller `n`
an explicit list of primes is provided which covers the remaining cases.
As in the [Metamath implementation](carneiro2015arithmetic), we rely on some optimizations from
[Shigenori Tochiori](tochiori_bertrand). In particular we use the cleaner bound on the central
binomial coefficient given in `Nat.four_pow_lt_mul_centralBinom`.
## References
* [M. Aigner and G. M. Ziegler _Proofs from THE BOOK_][aigner1999proofs]
* [S. Tochiori, _Considering the Proof of βThere is a Prime between n and 2nβ_][tochiori_bertrand]
* [M. Carneiro, _Arithmetic in Metamath, Case Study: Bertrand's Postulate_][carneiro2015arithmetic]
## Tags
Bertrand, prime, binomial coefficients
-/
open scoped BigOperators
section Real
open Real
namespace Bertrand
/-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> norm_num1
apply le_trans _ (le_mul_of_one_le_left _ _) <;> | norm_num1 | /-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> norm_num1
apply le_trans _ (le_mul_of_one_le_left _ _) <;> | Mathlib.NumberTheory.Bertrand.51_0.gJXoOT9Ce2wC0xc | /-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x | Mathlib_NumberTheory_Bertrand |
x : β
n_large : 512 β€ x
f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
hf' : β (x : β), 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)
hf : β (x : β), 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3))
h5 : 0 < x
h : ConcaveOn β (Set.Ioi 0.5) f
this : sqrt (2 * 18) = 6
β’ 1 β€ 18 | /-
Copyright (c) 2020 Patrick Stevens. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Stevens, Bolton Bailey
-/
import Mathlib.Data.Nat.Choose.Factorization
import Mathlib.Data.Nat.PrimeNormNum
import Mathlib.NumberTheory.Primorial
import Mathlib.Analysis.Convex.SpecificFunctions.Basic
import Mathlib.Analysis.Convex.SpecificFunctions.Deriv
#align_import number_theory.bertrand from "leanprover-community/mathlib"@"a16665637b378379689c566204817ae792ac8b39"
/-!
# Bertrand's Postulate
This file contains a proof of Bertrand's postulate: That between any positive number and its
double there is a prime.
The proof follows the outline of the ErdΕs proof presented in "Proofs from THE BOOK": One considers
the prime factorization of `(2 * n).choose n`, and splits the constituent primes up into various
groups, then upper bounds the contribution of each group. This upper bounds the central binomial
coefficient, and if the postulate does not hold, this upper bound conflicts with a simple lower
bound for large enough `n`. This proves the result holds for large enough `n`, and for smaller `n`
an explicit list of primes is provided which covers the remaining cases.
As in the [Metamath implementation](carneiro2015arithmetic), we rely on some optimizations from
[Shigenori Tochiori](tochiori_bertrand). In particular we use the cleaner bound on the central
binomial coefficient given in `Nat.four_pow_lt_mul_centralBinom`.
## References
* [M. Aigner and G. M. Ziegler _Proofs from THE BOOK_][aigner1999proofs]
* [S. Tochiori, _Considering the Proof of βThere is a Prime between n and 2nβ_][tochiori_bertrand]
* [M. Carneiro, _Arithmetic in Metamath, Case Study: Bertrand's Postulate_][carneiro2015arithmetic]
## Tags
Bertrand, prime, binomial coefficients
-/
open scoped BigOperators
section Real
open Real
namespace Bertrand
/-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> norm_num1
apply le_trans _ (le_mul_of_one_le_left _ _) <;> | norm_num1 | /-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> norm_num1
apply le_trans _ (le_mul_of_one_le_left _ _) <;> | Mathlib.NumberTheory.Bertrand.51_0.gJXoOT9Ce2wC0xc | /-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x | Mathlib_NumberTheory_Bertrand |
x : β
n_large : 512 β€ x
f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
hf' : β (x : β), 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)
hf : β (x : β), 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3))
h5 : 0 < x
h : ConcaveOn β (Set.Ioi 0.5) f
this : sqrt (2 * 18) = 6
β’ 4 ^ 6 β€ 36 ^ 6 | /-
Copyright (c) 2020 Patrick Stevens. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Stevens, Bolton Bailey
-/
import Mathlib.Data.Nat.Choose.Factorization
import Mathlib.Data.Nat.PrimeNormNum
import Mathlib.NumberTheory.Primorial
import Mathlib.Analysis.Convex.SpecificFunctions.Basic
import Mathlib.Analysis.Convex.SpecificFunctions.Deriv
#align_import number_theory.bertrand from "leanprover-community/mathlib"@"a16665637b378379689c566204817ae792ac8b39"
/-!
# Bertrand's Postulate
This file contains a proof of Bertrand's postulate: That between any positive number and its
double there is a prime.
The proof follows the outline of the ErdΕs proof presented in "Proofs from THE BOOK": One considers
the prime factorization of `(2 * n).choose n`, and splits the constituent primes up into various
groups, then upper bounds the contribution of each group. This upper bounds the central binomial
coefficient, and if the postulate does not hold, this upper bound conflicts with a simple lower
bound for large enough `n`. This proves the result holds for large enough `n`, and for smaller `n`
an explicit list of primes is provided which covers the remaining cases.
As in the [Metamath implementation](carneiro2015arithmetic), we rely on some optimizations from
[Shigenori Tochiori](tochiori_bertrand). In particular we use the cleaner bound on the central
binomial coefficient given in `Nat.four_pow_lt_mul_centralBinom`.
## References
* [M. Aigner and G. M. Ziegler _Proofs from THE BOOK_][aigner1999proofs]
* [S. Tochiori, _Considering the Proof of βThere is a Prime between n and 2nβ_][tochiori_bertrand]
* [M. Carneiro, _Arithmetic in Metamath, Case Study: Bertrand's Postulate_][carneiro2015arithmetic]
## Tags
Bertrand, prime, binomial coefficients
-/
open scoped BigOperators
section Real
open Real
namespace Bertrand
/-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> norm_num1
apply le_trans _ (le_mul_of_one_le_left _ _) <;> norm_num1
| apply Real.rpow_le_rpow | /-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> norm_num1
apply le_trans _ (le_mul_of_one_le_left _ _) <;> norm_num1
| Mathlib.NumberTheory.Bertrand.51_0.gJXoOT9Ce2wC0xc | /-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x | Mathlib_NumberTheory_Bertrand |
case h
x : β
n_large : 512 β€ x
f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
hf' : β (x : β), 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)
hf : β (x : β), 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3))
h5 : 0 < x
h : ConcaveOn β (Set.Ioi 0.5) f
this : sqrt (2 * 18) = 6
β’ 0 β€ 4 | /-
Copyright (c) 2020 Patrick Stevens. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Stevens, Bolton Bailey
-/
import Mathlib.Data.Nat.Choose.Factorization
import Mathlib.Data.Nat.PrimeNormNum
import Mathlib.NumberTheory.Primorial
import Mathlib.Analysis.Convex.SpecificFunctions.Basic
import Mathlib.Analysis.Convex.SpecificFunctions.Deriv
#align_import number_theory.bertrand from "leanprover-community/mathlib"@"a16665637b378379689c566204817ae792ac8b39"
/-!
# Bertrand's Postulate
This file contains a proof of Bertrand's postulate: That between any positive number and its
double there is a prime.
The proof follows the outline of the ErdΕs proof presented in "Proofs from THE BOOK": One considers
the prime factorization of `(2 * n).choose n`, and splits the constituent primes up into various
groups, then upper bounds the contribution of each group. This upper bounds the central binomial
coefficient, and if the postulate does not hold, this upper bound conflicts with a simple lower
bound for large enough `n`. This proves the result holds for large enough `n`, and for smaller `n`
an explicit list of primes is provided which covers the remaining cases.
As in the [Metamath implementation](carneiro2015arithmetic), we rely on some optimizations from
[Shigenori Tochiori](tochiori_bertrand). In particular we use the cleaner bound on the central
binomial coefficient given in `Nat.four_pow_lt_mul_centralBinom`.
## References
* [M. Aigner and G. M. Ziegler _Proofs from THE BOOK_][aigner1999proofs]
* [S. Tochiori, _Considering the Proof of βThere is a Prime between n and 2nβ_][tochiori_bertrand]
* [M. Carneiro, _Arithmetic in Metamath, Case Study: Bertrand's Postulate_][carneiro2015arithmetic]
## Tags
Bertrand, prime, binomial coefficients
-/
open scoped BigOperators
section Real
open Real
namespace Bertrand
/-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> norm_num1
apply le_trans _ (le_mul_of_one_le_left _ _) <;> norm_num1
apply Real.rpow_le_rpow <;> | norm_num1 | /-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> norm_num1
apply le_trans _ (le_mul_of_one_le_left _ _) <;> norm_num1
apply Real.rpow_le_rpow <;> | Mathlib.NumberTheory.Bertrand.51_0.gJXoOT9Ce2wC0xc | /-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x | Mathlib_NumberTheory_Bertrand |
case hβ
x : β
n_large : 512 β€ x
f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
hf' : β (x : β), 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)
hf : β (x : β), 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3))
h5 : 0 < x
h : ConcaveOn β (Set.Ioi 0.5) f
this : sqrt (2 * 18) = 6
β’ 4 β€ 36 | /-
Copyright (c) 2020 Patrick Stevens. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Stevens, Bolton Bailey
-/
import Mathlib.Data.Nat.Choose.Factorization
import Mathlib.Data.Nat.PrimeNormNum
import Mathlib.NumberTheory.Primorial
import Mathlib.Analysis.Convex.SpecificFunctions.Basic
import Mathlib.Analysis.Convex.SpecificFunctions.Deriv
#align_import number_theory.bertrand from "leanprover-community/mathlib"@"a16665637b378379689c566204817ae792ac8b39"
/-!
# Bertrand's Postulate
This file contains a proof of Bertrand's postulate: That between any positive number and its
double there is a prime.
The proof follows the outline of the ErdΕs proof presented in "Proofs from THE BOOK": One considers
the prime factorization of `(2 * n).choose n`, and splits the constituent primes up into various
groups, then upper bounds the contribution of each group. This upper bounds the central binomial
coefficient, and if the postulate does not hold, this upper bound conflicts with a simple lower
bound for large enough `n`. This proves the result holds for large enough `n`, and for smaller `n`
an explicit list of primes is provided which covers the remaining cases.
As in the [Metamath implementation](carneiro2015arithmetic), we rely on some optimizations from
[Shigenori Tochiori](tochiori_bertrand). In particular we use the cleaner bound on the central
binomial coefficient given in `Nat.four_pow_lt_mul_centralBinom`.
## References
* [M. Aigner and G. M. Ziegler _Proofs from THE BOOK_][aigner1999proofs]
* [S. Tochiori, _Considering the Proof of βThere is a Prime between n and 2nβ_][tochiori_bertrand]
* [M. Carneiro, _Arithmetic in Metamath, Case Study: Bertrand's Postulate_][carneiro2015arithmetic]
## Tags
Bertrand, prime, binomial coefficients
-/
open scoped BigOperators
section Real
open Real
namespace Bertrand
/-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> norm_num1
apply le_trans _ (le_mul_of_one_le_left _ _) <;> norm_num1
apply Real.rpow_le_rpow <;> | norm_num1 | /-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> norm_num1
apply le_trans _ (le_mul_of_one_le_left _ _) <;> norm_num1
apply Real.rpow_le_rpow <;> | Mathlib.NumberTheory.Bertrand.51_0.gJXoOT9Ce2wC0xc | /-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x | Mathlib_NumberTheory_Bertrand |
case hβ
x : β
n_large : 512 β€ x
f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
hf' : β (x : β), 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)
hf : β (x : β), 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3))
h5 : 0 < x
h : ConcaveOn β (Set.Ioi 0.5) f
this : sqrt (2 * 18) = 6
β’ 0 β€ 6 | /-
Copyright (c) 2020 Patrick Stevens. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Stevens, Bolton Bailey
-/
import Mathlib.Data.Nat.Choose.Factorization
import Mathlib.Data.Nat.PrimeNormNum
import Mathlib.NumberTheory.Primorial
import Mathlib.Analysis.Convex.SpecificFunctions.Basic
import Mathlib.Analysis.Convex.SpecificFunctions.Deriv
#align_import number_theory.bertrand from "leanprover-community/mathlib"@"a16665637b378379689c566204817ae792ac8b39"
/-!
# Bertrand's Postulate
This file contains a proof of Bertrand's postulate: That between any positive number and its
double there is a prime.
The proof follows the outline of the ErdΕs proof presented in "Proofs from THE BOOK": One considers
the prime factorization of `(2 * n).choose n`, and splits the constituent primes up into various
groups, then upper bounds the contribution of each group. This upper bounds the central binomial
coefficient, and if the postulate does not hold, this upper bound conflicts with a simple lower
bound for large enough `n`. This proves the result holds for large enough `n`, and for smaller `n`
an explicit list of primes is provided which covers the remaining cases.
As in the [Metamath implementation](carneiro2015arithmetic), we rely on some optimizations from
[Shigenori Tochiori](tochiori_bertrand). In particular we use the cleaner bound on the central
binomial coefficient given in `Nat.four_pow_lt_mul_centralBinom`.
## References
* [M. Aigner and G. M. Ziegler _Proofs from THE BOOK_][aigner1999proofs]
* [S. Tochiori, _Considering the Proof of βThere is a Prime between n and 2nβ_][tochiori_bertrand]
* [M. Carneiro, _Arithmetic in Metamath, Case Study: Bertrand's Postulate_][carneiro2015arithmetic]
## Tags
Bertrand, prime, binomial coefficients
-/
open scoped BigOperators
section Real
open Real
namespace Bertrand
/-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> norm_num1
apply le_trans _ (le_mul_of_one_le_left _ _) <;> norm_num1
apply Real.rpow_le_rpow <;> | norm_num1 | /-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> norm_num1
apply le_trans _ (le_mul_of_one_le_left _ _) <;> norm_num1
apply Real.rpow_le_rpow <;> | Mathlib.NumberTheory.Bertrand.51_0.gJXoOT9Ce2wC0xc | /-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x | Mathlib_NumberTheory_Bertrand |
x : β
n_large : 512 β€ x
f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
hf' : β (x : β), 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)
hf : β (x : β), 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3))
h5 : 0 < x
h : ConcaveOn β (Set.Ioi 0.5) f
this : sqrt (2 * 18) = 6
β’ 0 β€ 36 ^ 6
case refine'_1
x : β
n_large : 512 β€ x
f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
hf' : β (x : β), 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)
hf : β (x : β), 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3))
h5 : 0 < x
h : ConcaveOn β (Set.Ioi 0.5) f
this : sqrt (2 * 18) = 6
β’ 0 < 4 ^ 6
case refine'_1
x : β
n_large : 512 β€ x
f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
hf' : β (x : β), 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)
hf : β (x : β), 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3))
h5 : 0 < x
h : ConcaveOn β (Set.Ioi 0.5) f
this : sqrt (2 * 18) = 6
β’ 0 < 18 * (2 * 18) ^ sqrt (2 * 18) / 4 ^ (18 / 3)
case refine'_1.a
x : β
n_large : 512 β€ x
f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
hf' : β (x : β), 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)
hf : β (x : β), 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3))
h5 : 0 < x
h : ConcaveOn β (Set.Ioi 0.5) f
this : sqrt (2 * 18) = 6
β’ 0 < 18 | /-
Copyright (c) 2020 Patrick Stevens. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Stevens, Bolton Bailey
-/
import Mathlib.Data.Nat.Choose.Factorization
import Mathlib.Data.Nat.PrimeNormNum
import Mathlib.NumberTheory.Primorial
import Mathlib.Analysis.Convex.SpecificFunctions.Basic
import Mathlib.Analysis.Convex.SpecificFunctions.Deriv
#align_import number_theory.bertrand from "leanprover-community/mathlib"@"a16665637b378379689c566204817ae792ac8b39"
/-!
# Bertrand's Postulate
This file contains a proof of Bertrand's postulate: That between any positive number and its
double there is a prime.
The proof follows the outline of the ErdΕs proof presented in "Proofs from THE BOOK": One considers
the prime factorization of `(2 * n).choose n`, and splits the constituent primes up into various
groups, then upper bounds the contribution of each group. This upper bounds the central binomial
coefficient, and if the postulate does not hold, this upper bound conflicts with a simple lower
bound for large enough `n`. This proves the result holds for large enough `n`, and for smaller `n`
an explicit list of primes is provided which covers the remaining cases.
As in the [Metamath implementation](carneiro2015arithmetic), we rely on some optimizations from
[Shigenori Tochiori](tochiori_bertrand). In particular we use the cleaner bound on the central
binomial coefficient given in `Nat.four_pow_lt_mul_centralBinom`.
## References
* [M. Aigner and G. M. Ziegler _Proofs from THE BOOK_][aigner1999proofs]
* [S. Tochiori, _Considering the Proof of βThere is a Prime between n and 2nβ_][tochiori_bertrand]
* [M. Carneiro, _Arithmetic in Metamath, Case Study: Bertrand's Postulate_][carneiro2015arithmetic]
## Tags
Bertrand, prime, binomial coefficients
-/
open scoped BigOperators
section Real
open Real
namespace Bertrand
/-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> norm_num1
apply le_trans _ (le_mul_of_one_le_left _ _) <;> norm_num1
apply Real.rpow_le_rpow <;> norm_num1
| apply rpow_nonneg_of_nonneg | /-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> norm_num1
apply le_trans _ (le_mul_of_one_le_left _ _) <;> norm_num1
apply Real.rpow_le_rpow <;> norm_num1
| Mathlib.NumberTheory.Bertrand.51_0.gJXoOT9Ce2wC0xc | /-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x | Mathlib_NumberTheory_Bertrand |
case hx
x : β
n_large : 512 β€ x
f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
hf' : β (x : β), 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)
hf : β (x : β), 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3))
h5 : 0 < x
h : ConcaveOn β (Set.Ioi 0.5) f
this : sqrt (2 * 18) = 6
β’ 0 β€ 36
case refine'_1
x : β
n_large : 512 β€ x
f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
hf' : β (x : β), 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)
hf : β (x : β), 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3))
h5 : 0 < x
h : ConcaveOn β (Set.Ioi 0.5) f
this : sqrt (2 * 18) = 6
β’ 0 < 4 ^ 6
case refine'_1
x : β
n_large : 512 β€ x
f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
hf' : β (x : β), 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)
hf : β (x : β), 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3))
h5 : 0 < x
h : ConcaveOn β (Set.Ioi 0.5) f
this : sqrt (2 * 18) = 6
β’ 0 < 18 * (2 * 18) ^ sqrt (2 * 18) / 4 ^ (18 / 3)
case refine'_1.a
x : β
n_large : 512 β€ x
f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
hf' : β (x : β), 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)
hf : β (x : β), 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3))
h5 : 0 < x
h : ConcaveOn β (Set.Ioi 0.5) f
this : sqrt (2 * 18) = 6
β’ 0 < 18 | /-
Copyright (c) 2020 Patrick Stevens. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Stevens, Bolton Bailey
-/
import Mathlib.Data.Nat.Choose.Factorization
import Mathlib.Data.Nat.PrimeNormNum
import Mathlib.NumberTheory.Primorial
import Mathlib.Analysis.Convex.SpecificFunctions.Basic
import Mathlib.Analysis.Convex.SpecificFunctions.Deriv
#align_import number_theory.bertrand from "leanprover-community/mathlib"@"a16665637b378379689c566204817ae792ac8b39"
/-!
# Bertrand's Postulate
This file contains a proof of Bertrand's postulate: That between any positive number and its
double there is a prime.
The proof follows the outline of the ErdΕs proof presented in "Proofs from THE BOOK": One considers
the prime factorization of `(2 * n).choose n`, and splits the constituent primes up into various
groups, then upper bounds the contribution of each group. This upper bounds the central binomial
coefficient, and if the postulate does not hold, this upper bound conflicts with a simple lower
bound for large enough `n`. This proves the result holds for large enough `n`, and for smaller `n`
an explicit list of primes is provided which covers the remaining cases.
As in the [Metamath implementation](carneiro2015arithmetic), we rely on some optimizations from
[Shigenori Tochiori](tochiori_bertrand). In particular we use the cleaner bound on the central
binomial coefficient given in `Nat.four_pow_lt_mul_centralBinom`.
## References
* [M. Aigner and G. M. Ziegler _Proofs from THE BOOK_][aigner1999proofs]
* [S. Tochiori, _Considering the Proof of βThere is a Prime between n and 2nβ_][tochiori_bertrand]
* [M. Carneiro, _Arithmetic in Metamath, Case Study: Bertrand's Postulate_][carneiro2015arithmetic]
## Tags
Bertrand, prime, binomial coefficients
-/
open scoped BigOperators
section Real
open Real
namespace Bertrand
/-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> norm_num1
apply le_trans _ (le_mul_of_one_le_left _ _) <;> norm_num1
apply Real.rpow_le_rpow <;> norm_num1
apply rpow_nonneg_of_nonneg; | norm_num1 | /-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> norm_num1
apply le_trans _ (le_mul_of_one_le_left _ _) <;> norm_num1
apply Real.rpow_le_rpow <;> norm_num1
apply rpow_nonneg_of_nonneg; | Mathlib.NumberTheory.Bertrand.51_0.gJXoOT9Ce2wC0xc | /-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x | Mathlib_NumberTheory_Bertrand |
case refine'_1
x : β
n_large : 512 β€ x
f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
hf' : β (x : β), 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)
hf : β (x : β), 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3))
h5 : 0 < x
h : ConcaveOn β (Set.Ioi 0.5) f
this : sqrt (2 * 18) = 6
β’ 0 < 4 ^ 6
case refine'_1
x : β
n_large : 512 β€ x
f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
hf' : β (x : β), 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)
hf : β (x : β), 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3))
h5 : 0 < x
h : ConcaveOn β (Set.Ioi 0.5) f
this : sqrt (2 * 18) = 6
β’ 0 < 18 * (2 * 18) ^ sqrt (2 * 18) / 4 ^ (18 / 3)
case refine'_1.a
x : β
n_large : 512 β€ x
f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
hf' : β (x : β), 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)
hf : β (x : β), 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3))
h5 : 0 < x
h : ConcaveOn β (Set.Ioi 0.5) f
this : sqrt (2 * 18) = 6
β’ 0 < 18 | /-
Copyright (c) 2020 Patrick Stevens. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Stevens, Bolton Bailey
-/
import Mathlib.Data.Nat.Choose.Factorization
import Mathlib.Data.Nat.PrimeNormNum
import Mathlib.NumberTheory.Primorial
import Mathlib.Analysis.Convex.SpecificFunctions.Basic
import Mathlib.Analysis.Convex.SpecificFunctions.Deriv
#align_import number_theory.bertrand from "leanprover-community/mathlib"@"a16665637b378379689c566204817ae792ac8b39"
/-!
# Bertrand's Postulate
This file contains a proof of Bertrand's postulate: That between any positive number and its
double there is a prime.
The proof follows the outline of the ErdΕs proof presented in "Proofs from THE BOOK": One considers
the prime factorization of `(2 * n).choose n`, and splits the constituent primes up into various
groups, then upper bounds the contribution of each group. This upper bounds the central binomial
coefficient, and if the postulate does not hold, this upper bound conflicts with a simple lower
bound for large enough `n`. This proves the result holds for large enough `n`, and for smaller `n`
an explicit list of primes is provided which covers the remaining cases.
As in the [Metamath implementation](carneiro2015arithmetic), we rely on some optimizations from
[Shigenori Tochiori](tochiori_bertrand). In particular we use the cleaner bound on the central
binomial coefficient given in `Nat.four_pow_lt_mul_centralBinom`.
## References
* [M. Aigner and G. M. Ziegler _Proofs from THE BOOK_][aigner1999proofs]
* [S. Tochiori, _Considering the Proof of βThere is a Prime between n and 2nβ_][tochiori_bertrand]
* [M. Carneiro, _Arithmetic in Metamath, Case Study: Bertrand's Postulate_][carneiro2015arithmetic]
## Tags
Bertrand, prime, binomial coefficients
-/
open scoped BigOperators
section Real
open Real
namespace Bertrand
/-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> norm_num1
apply le_trans _ (le_mul_of_one_le_left _ _) <;> norm_num1
apply Real.rpow_le_rpow <;> norm_num1
apply rpow_nonneg_of_nonneg; norm_num1
| apply rpow_pos_of_pos | /-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> norm_num1
apply le_trans _ (le_mul_of_one_le_left _ _) <;> norm_num1
apply Real.rpow_le_rpow <;> norm_num1
apply rpow_nonneg_of_nonneg; norm_num1
| Mathlib.NumberTheory.Bertrand.51_0.gJXoOT9Ce2wC0xc | /-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x | Mathlib_NumberTheory_Bertrand |
case refine'_1.hx
x : β
n_large : 512 β€ x
f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
hf' : β (x : β), 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)
hf : β (x : β), 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3))
h5 : 0 < x
h : ConcaveOn β (Set.Ioi 0.5) f
this : sqrt (2 * 18) = 6
β’ 0 < 4
case refine'_1
x : β
n_large : 512 β€ x
f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
hf' : β (x : β), 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)
hf : β (x : β), 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3))
h5 : 0 < x
h : ConcaveOn β (Set.Ioi 0.5) f
this : sqrt (2 * 18) = 6
β’ 0 < 18 * (2 * 18) ^ sqrt (2 * 18) / 4 ^ (18 / 3)
case refine'_1.a
x : β
n_large : 512 β€ x
f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
hf' : β (x : β), 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)
hf : β (x : β), 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3))
h5 : 0 < x
h : ConcaveOn β (Set.Ioi 0.5) f
this : sqrt (2 * 18) = 6
β’ 0 < 18 | /-
Copyright (c) 2020 Patrick Stevens. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Stevens, Bolton Bailey
-/
import Mathlib.Data.Nat.Choose.Factorization
import Mathlib.Data.Nat.PrimeNormNum
import Mathlib.NumberTheory.Primorial
import Mathlib.Analysis.Convex.SpecificFunctions.Basic
import Mathlib.Analysis.Convex.SpecificFunctions.Deriv
#align_import number_theory.bertrand from "leanprover-community/mathlib"@"a16665637b378379689c566204817ae792ac8b39"
/-!
# Bertrand's Postulate
This file contains a proof of Bertrand's postulate: That between any positive number and its
double there is a prime.
The proof follows the outline of the ErdΕs proof presented in "Proofs from THE BOOK": One considers
the prime factorization of `(2 * n).choose n`, and splits the constituent primes up into various
groups, then upper bounds the contribution of each group. This upper bounds the central binomial
coefficient, and if the postulate does not hold, this upper bound conflicts with a simple lower
bound for large enough `n`. This proves the result holds for large enough `n`, and for smaller `n`
an explicit list of primes is provided which covers the remaining cases.
As in the [Metamath implementation](carneiro2015arithmetic), we rely on some optimizations from
[Shigenori Tochiori](tochiori_bertrand). In particular we use the cleaner bound on the central
binomial coefficient given in `Nat.four_pow_lt_mul_centralBinom`.
## References
* [M. Aigner and G. M. Ziegler _Proofs from THE BOOK_][aigner1999proofs]
* [S. Tochiori, _Considering the Proof of βThere is a Prime between n and 2nβ_][tochiori_bertrand]
* [M. Carneiro, _Arithmetic in Metamath, Case Study: Bertrand's Postulate_][carneiro2015arithmetic]
## Tags
Bertrand, prime, binomial coefficients
-/
open scoped BigOperators
section Real
open Real
namespace Bertrand
/-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> norm_num1
apply le_trans _ (le_mul_of_one_le_left _ _) <;> norm_num1
apply Real.rpow_le_rpow <;> norm_num1
apply rpow_nonneg_of_nonneg; norm_num1
apply rpow_pos_of_pos; | norm_num1 | /-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> norm_num1
apply le_trans _ (le_mul_of_one_le_left _ _) <;> norm_num1
apply Real.rpow_le_rpow <;> norm_num1
apply rpow_nonneg_of_nonneg; norm_num1
apply rpow_pos_of_pos; | Mathlib.NumberTheory.Bertrand.51_0.gJXoOT9Ce2wC0xc | /-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x | Mathlib_NumberTheory_Bertrand |
case refine'_1
x : β
n_large : 512 β€ x
f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
hf' : β (x : β), 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)
hf : β (x : β), 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3))
h5 : 0 < x
h : ConcaveOn β (Set.Ioi 0.5) f
this : sqrt (2 * 18) = 6
β’ 0 < 18 * (2 * 18) ^ sqrt (2 * 18) / 4 ^ (18 / 3)
case refine'_1.a
x : β
n_large : 512 β€ x
f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
hf' : β (x : β), 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)
hf : β (x : β), 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3))
h5 : 0 < x
h : ConcaveOn β (Set.Ioi 0.5) f
this : sqrt (2 * 18) = 6
β’ 0 < 18 | /-
Copyright (c) 2020 Patrick Stevens. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Stevens, Bolton Bailey
-/
import Mathlib.Data.Nat.Choose.Factorization
import Mathlib.Data.Nat.PrimeNormNum
import Mathlib.NumberTheory.Primorial
import Mathlib.Analysis.Convex.SpecificFunctions.Basic
import Mathlib.Analysis.Convex.SpecificFunctions.Deriv
#align_import number_theory.bertrand from "leanprover-community/mathlib"@"a16665637b378379689c566204817ae792ac8b39"
/-!
# Bertrand's Postulate
This file contains a proof of Bertrand's postulate: That between any positive number and its
double there is a prime.
The proof follows the outline of the ErdΕs proof presented in "Proofs from THE BOOK": One considers
the prime factorization of `(2 * n).choose n`, and splits the constituent primes up into various
groups, then upper bounds the contribution of each group. This upper bounds the central binomial
coefficient, and if the postulate does not hold, this upper bound conflicts with a simple lower
bound for large enough `n`. This proves the result holds for large enough `n`, and for smaller `n`
an explicit list of primes is provided which covers the remaining cases.
As in the [Metamath implementation](carneiro2015arithmetic), we rely on some optimizations from
[Shigenori Tochiori](tochiori_bertrand). In particular we use the cleaner bound on the central
binomial coefficient given in `Nat.four_pow_lt_mul_centralBinom`.
## References
* [M. Aigner and G. M. Ziegler _Proofs from THE BOOK_][aigner1999proofs]
* [S. Tochiori, _Considering the Proof of βThere is a Prime between n and 2nβ_][tochiori_bertrand]
* [M. Carneiro, _Arithmetic in Metamath, Case Study: Bertrand's Postulate_][carneiro2015arithmetic]
## Tags
Bertrand, prime, binomial coefficients
-/
open scoped BigOperators
section Real
open Real
namespace Bertrand
/-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> norm_num1
apply le_trans _ (le_mul_of_one_le_left _ _) <;> norm_num1
apply Real.rpow_le_rpow <;> norm_num1
apply rpow_nonneg_of_nonneg; norm_num1
apply rpow_pos_of_pos; norm_num1
| apply hf' 18 | /-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> norm_num1
apply le_trans _ (le_mul_of_one_le_left _ _) <;> norm_num1
apply Real.rpow_le_rpow <;> norm_num1
apply rpow_nonneg_of_nonneg; norm_num1
apply rpow_pos_of_pos; norm_num1
| Mathlib.NumberTheory.Bertrand.51_0.gJXoOT9Ce2wC0xc | /-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x | Mathlib_NumberTheory_Bertrand |
case refine'_1
x : β
n_large : 512 β€ x
f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
hf' : β (x : β), 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)
hf : β (x : β), 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3))
h5 : 0 < x
h : ConcaveOn β (Set.Ioi 0.5) f
this : sqrt (2 * 18) = 6
β’ 0 < 18
case refine'_1.a
x : β
n_large : 512 β€ x
f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
hf' : β (x : β), 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)
hf : β (x : β), 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3))
h5 : 0 < x
h : ConcaveOn β (Set.Ioi 0.5) f
this : sqrt (2 * 18) = 6
β’ 0 < 18 | /-
Copyright (c) 2020 Patrick Stevens. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Stevens, Bolton Bailey
-/
import Mathlib.Data.Nat.Choose.Factorization
import Mathlib.Data.Nat.PrimeNormNum
import Mathlib.NumberTheory.Primorial
import Mathlib.Analysis.Convex.SpecificFunctions.Basic
import Mathlib.Analysis.Convex.SpecificFunctions.Deriv
#align_import number_theory.bertrand from "leanprover-community/mathlib"@"a16665637b378379689c566204817ae792ac8b39"
/-!
# Bertrand's Postulate
This file contains a proof of Bertrand's postulate: That between any positive number and its
double there is a prime.
The proof follows the outline of the ErdΕs proof presented in "Proofs from THE BOOK": One considers
the prime factorization of `(2 * n).choose n`, and splits the constituent primes up into various
groups, then upper bounds the contribution of each group. This upper bounds the central binomial
coefficient, and if the postulate does not hold, this upper bound conflicts with a simple lower
bound for large enough `n`. This proves the result holds for large enough `n`, and for smaller `n`
an explicit list of primes is provided which covers the remaining cases.
As in the [Metamath implementation](carneiro2015arithmetic), we rely on some optimizations from
[Shigenori Tochiori](tochiori_bertrand). In particular we use the cleaner bound on the central
binomial coefficient given in `Nat.four_pow_lt_mul_centralBinom`.
## References
* [M. Aigner and G. M. Ziegler _Proofs from THE BOOK_][aigner1999proofs]
* [S. Tochiori, _Considering the Proof of βThere is a Prime between n and 2nβ_][tochiori_bertrand]
* [M. Carneiro, _Arithmetic in Metamath, Case Study: Bertrand's Postulate_][carneiro2015arithmetic]
## Tags
Bertrand, prime, binomial coefficients
-/
open scoped BigOperators
section Real
open Real
namespace Bertrand
/-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> norm_num1
apply le_trans _ (le_mul_of_one_le_left _ _) <;> norm_num1
apply Real.rpow_le_rpow <;> norm_num1
apply rpow_nonneg_of_nonneg; norm_num1
apply rpow_pos_of_pos; norm_num1
apply hf' 18; | norm_num1 | /-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> norm_num1
apply le_trans _ (le_mul_of_one_le_left _ _) <;> norm_num1
apply Real.rpow_le_rpow <;> norm_num1
apply rpow_nonneg_of_nonneg; norm_num1
apply rpow_pos_of_pos; norm_num1
apply hf' 18; | Mathlib.NumberTheory.Bertrand.51_0.gJXoOT9Ce2wC0xc | /-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x | Mathlib_NumberTheory_Bertrand |
case refine'_1.a
x : β
n_large : 512 β€ x
f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
hf' : β (x : β), 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)
hf : β (x : β), 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3))
h5 : 0 < x
h : ConcaveOn β (Set.Ioi 0.5) f
this : sqrt (2 * 18) = 6
β’ 0 < 18 | /-
Copyright (c) 2020 Patrick Stevens. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Stevens, Bolton Bailey
-/
import Mathlib.Data.Nat.Choose.Factorization
import Mathlib.Data.Nat.PrimeNormNum
import Mathlib.NumberTheory.Primorial
import Mathlib.Analysis.Convex.SpecificFunctions.Basic
import Mathlib.Analysis.Convex.SpecificFunctions.Deriv
#align_import number_theory.bertrand from "leanprover-community/mathlib"@"a16665637b378379689c566204817ae792ac8b39"
/-!
# Bertrand's Postulate
This file contains a proof of Bertrand's postulate: That between any positive number and its
double there is a prime.
The proof follows the outline of the ErdΕs proof presented in "Proofs from THE BOOK": One considers
the prime factorization of `(2 * n).choose n`, and splits the constituent primes up into various
groups, then upper bounds the contribution of each group. This upper bounds the central binomial
coefficient, and if the postulate does not hold, this upper bound conflicts with a simple lower
bound for large enough `n`. This proves the result holds for large enough `n`, and for smaller `n`
an explicit list of primes is provided which covers the remaining cases.
As in the [Metamath implementation](carneiro2015arithmetic), we rely on some optimizations from
[Shigenori Tochiori](tochiori_bertrand). In particular we use the cleaner bound on the central
binomial coefficient given in `Nat.four_pow_lt_mul_centralBinom`.
## References
* [M. Aigner and G. M. Ziegler _Proofs from THE BOOK_][aigner1999proofs]
* [S. Tochiori, _Considering the Proof of βThere is a Prime between n and 2nβ_][tochiori_bertrand]
* [M. Carneiro, _Arithmetic in Metamath, Case Study: Bertrand's Postulate_][carneiro2015arithmetic]
## Tags
Bertrand, prime, binomial coefficients
-/
open scoped BigOperators
section Real
open Real
namespace Bertrand
/-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> norm_num1
apply le_trans _ (le_mul_of_one_le_left _ _) <;> norm_num1
apply Real.rpow_le_rpow <;> norm_num1
apply rpow_nonneg_of_nonneg; norm_num1
apply rpow_pos_of_pos; norm_num1
apply hf' 18; norm_num1
| norm_num1 | /-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> norm_num1
apply le_trans _ (le_mul_of_one_le_left _ _) <;> norm_num1
apply Real.rpow_le_rpow <;> norm_num1
apply rpow_nonneg_of_nonneg; norm_num1
apply rpow_pos_of_pos; norm_num1
apply hf' 18; norm_num1
| Mathlib.NumberTheory.Bertrand.51_0.gJXoOT9Ce2wC0xc | /-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x | Mathlib_NumberTheory_Bertrand |
case refine'_2
x : β
n_large : 512 β€ x
f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
hf' : β (x : β), 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)
hf : β (x : β), 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3))
h5 : 0 < x
h : ConcaveOn β (Set.Ioi 0.5) f
β’ f 512 β€ 0 | /-
Copyright (c) 2020 Patrick Stevens. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Stevens, Bolton Bailey
-/
import Mathlib.Data.Nat.Choose.Factorization
import Mathlib.Data.Nat.PrimeNormNum
import Mathlib.NumberTheory.Primorial
import Mathlib.Analysis.Convex.SpecificFunctions.Basic
import Mathlib.Analysis.Convex.SpecificFunctions.Deriv
#align_import number_theory.bertrand from "leanprover-community/mathlib"@"a16665637b378379689c566204817ae792ac8b39"
/-!
# Bertrand's Postulate
This file contains a proof of Bertrand's postulate: That between any positive number and its
double there is a prime.
The proof follows the outline of the ErdΕs proof presented in "Proofs from THE BOOK": One considers
the prime factorization of `(2 * n).choose n`, and splits the constituent primes up into various
groups, then upper bounds the contribution of each group. This upper bounds the central binomial
coefficient, and if the postulate does not hold, this upper bound conflicts with a simple lower
bound for large enough `n`. This proves the result holds for large enough `n`, and for smaller `n`
an explicit list of primes is provided which covers the remaining cases.
As in the [Metamath implementation](carneiro2015arithmetic), we rely on some optimizations from
[Shigenori Tochiori](tochiori_bertrand). In particular we use the cleaner bound on the central
binomial coefficient given in `Nat.four_pow_lt_mul_centralBinom`.
## References
* [M. Aigner and G. M. Ziegler _Proofs from THE BOOK_][aigner1999proofs]
* [S. Tochiori, _Considering the Proof of βThere is a Prime between n and 2nβ_][tochiori_bertrand]
* [M. Carneiro, _Arithmetic in Metamath, Case Study: Bertrand's Postulate_][carneiro2015arithmetic]
## Tags
Bertrand, prime, binomial coefficients
-/
open scoped BigOperators
section Real
open Real
namespace Bertrand
/-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> norm_num1
apply le_trans _ (le_mul_of_one_le_left _ _) <;> norm_num1
apply Real.rpow_le_rpow <;> norm_num1
apply rpow_nonneg_of_nonneg; norm_num1
apply rpow_pos_of_pos; norm_num1
apply hf' 18; norm_num1
norm_num1
Β· | have : sqrt (2 * 512) = 32 :=
(sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1) | /-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> norm_num1
apply le_trans _ (le_mul_of_one_le_left _ _) <;> norm_num1
apply Real.rpow_le_rpow <;> norm_num1
apply rpow_nonneg_of_nonneg; norm_num1
apply rpow_pos_of_pos; norm_num1
apply hf' 18; norm_num1
norm_num1
Β· | Mathlib.NumberTheory.Bertrand.51_0.gJXoOT9Ce2wC0xc | /-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x | Mathlib_NumberTheory_Bertrand |
x : β
n_large : 512 β€ x
f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
hf' : β (x : β), 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)
hf : β (x : β), 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3))
h5 : 0 < x
h : ConcaveOn β (Set.Ioi 0.5) f
β’ 0 < 32 | /-
Copyright (c) 2020 Patrick Stevens. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Stevens, Bolton Bailey
-/
import Mathlib.Data.Nat.Choose.Factorization
import Mathlib.Data.Nat.PrimeNormNum
import Mathlib.NumberTheory.Primorial
import Mathlib.Analysis.Convex.SpecificFunctions.Basic
import Mathlib.Analysis.Convex.SpecificFunctions.Deriv
#align_import number_theory.bertrand from "leanprover-community/mathlib"@"a16665637b378379689c566204817ae792ac8b39"
/-!
# Bertrand's Postulate
This file contains a proof of Bertrand's postulate: That between any positive number and its
double there is a prime.
The proof follows the outline of the ErdΕs proof presented in "Proofs from THE BOOK": One considers
the prime factorization of `(2 * n).choose n`, and splits the constituent primes up into various
groups, then upper bounds the contribution of each group. This upper bounds the central binomial
coefficient, and if the postulate does not hold, this upper bound conflicts with a simple lower
bound for large enough `n`. This proves the result holds for large enough `n`, and for smaller `n`
an explicit list of primes is provided which covers the remaining cases.
As in the [Metamath implementation](carneiro2015arithmetic), we rely on some optimizations from
[Shigenori Tochiori](tochiori_bertrand). In particular we use the cleaner bound on the central
binomial coefficient given in `Nat.four_pow_lt_mul_centralBinom`.
## References
* [M. Aigner and G. M. Ziegler _Proofs from THE BOOK_][aigner1999proofs]
* [S. Tochiori, _Considering the Proof of βThere is a Prime between n and 2nβ_][tochiori_bertrand]
* [M. Carneiro, _Arithmetic in Metamath, Case Study: Bertrand's Postulate_][carneiro2015arithmetic]
## Tags
Bertrand, prime, binomial coefficients
-/
open scoped BigOperators
section Real
open Real
namespace Bertrand
/-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> norm_num1
apply le_trans _ (le_mul_of_one_le_left _ _) <;> norm_num1
apply Real.rpow_le_rpow <;> norm_num1
apply rpow_nonneg_of_nonneg; norm_num1
apply rpow_pos_of_pos; norm_num1
apply hf' 18; norm_num1
norm_num1
Β· have : sqrt (2 * 512) = 32 :=
(sqrt_eq_iff_mul_self_eq_of_pos (by | norm_num1 | /-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> norm_num1
apply le_trans _ (le_mul_of_one_le_left _ _) <;> norm_num1
apply Real.rpow_le_rpow <;> norm_num1
apply rpow_nonneg_of_nonneg; norm_num1
apply rpow_pos_of_pos; norm_num1
apply hf' 18; norm_num1
norm_num1
Β· have : sqrt (2 * 512) = 32 :=
(sqrt_eq_iff_mul_self_eq_of_pos (by | Mathlib.NumberTheory.Bertrand.51_0.gJXoOT9Ce2wC0xc | /-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x | Mathlib_NumberTheory_Bertrand |
x : β
n_large : 512 β€ x
f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
hf' : β (x : β), 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)
hf : β (x : β), 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3))
h5 : 0 < x
h : ConcaveOn β (Set.Ioi 0.5) f
β’ 32 * 32 = 2 * 512 | /-
Copyright (c) 2020 Patrick Stevens. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Stevens, Bolton Bailey
-/
import Mathlib.Data.Nat.Choose.Factorization
import Mathlib.Data.Nat.PrimeNormNum
import Mathlib.NumberTheory.Primorial
import Mathlib.Analysis.Convex.SpecificFunctions.Basic
import Mathlib.Analysis.Convex.SpecificFunctions.Deriv
#align_import number_theory.bertrand from "leanprover-community/mathlib"@"a16665637b378379689c566204817ae792ac8b39"
/-!
# Bertrand's Postulate
This file contains a proof of Bertrand's postulate: That between any positive number and its
double there is a prime.
The proof follows the outline of the ErdΕs proof presented in "Proofs from THE BOOK": One considers
the prime factorization of `(2 * n).choose n`, and splits the constituent primes up into various
groups, then upper bounds the contribution of each group. This upper bounds the central binomial
coefficient, and if the postulate does not hold, this upper bound conflicts with a simple lower
bound for large enough `n`. This proves the result holds for large enough `n`, and for smaller `n`
an explicit list of primes is provided which covers the remaining cases.
As in the [Metamath implementation](carneiro2015arithmetic), we rely on some optimizations from
[Shigenori Tochiori](tochiori_bertrand). In particular we use the cleaner bound on the central
binomial coefficient given in `Nat.four_pow_lt_mul_centralBinom`.
## References
* [M. Aigner and G. M. Ziegler _Proofs from THE BOOK_][aigner1999proofs]
* [S. Tochiori, _Considering the Proof of βThere is a Prime between n and 2nβ_][tochiori_bertrand]
* [M. Carneiro, _Arithmetic in Metamath, Case Study: Bertrand's Postulate_][carneiro2015arithmetic]
## Tags
Bertrand, prime, binomial coefficients
-/
open scoped BigOperators
section Real
open Real
namespace Bertrand
/-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> norm_num1
apply le_trans _ (le_mul_of_one_le_left _ _) <;> norm_num1
apply Real.rpow_le_rpow <;> norm_num1
apply rpow_nonneg_of_nonneg; norm_num1
apply rpow_pos_of_pos; norm_num1
apply hf' 18; norm_num1
norm_num1
Β· have : sqrt (2 * 512) = 32 :=
(sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by | norm_num1 | /-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> norm_num1
apply le_trans _ (le_mul_of_one_le_left _ _) <;> norm_num1
apply Real.rpow_le_rpow <;> norm_num1
apply rpow_nonneg_of_nonneg; norm_num1
apply rpow_pos_of_pos; norm_num1
apply hf' 18; norm_num1
norm_num1
Β· have : sqrt (2 * 512) = 32 :=
(sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by | Mathlib.NumberTheory.Bertrand.51_0.gJXoOT9Ce2wC0xc | /-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x | Mathlib_NumberTheory_Bertrand |
case refine'_2
x : β
n_large : 512 β€ x
f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
hf' : β (x : β), 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)
hf : β (x : β), 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3))
h5 : 0 < x
h : ConcaveOn β (Set.Ioi 0.5) f
this : sqrt (2 * 512) = 32
β’ f 512 β€ 0 | /-
Copyright (c) 2020 Patrick Stevens. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Stevens, Bolton Bailey
-/
import Mathlib.Data.Nat.Choose.Factorization
import Mathlib.Data.Nat.PrimeNormNum
import Mathlib.NumberTheory.Primorial
import Mathlib.Analysis.Convex.SpecificFunctions.Basic
import Mathlib.Analysis.Convex.SpecificFunctions.Deriv
#align_import number_theory.bertrand from "leanprover-community/mathlib"@"a16665637b378379689c566204817ae792ac8b39"
/-!
# Bertrand's Postulate
This file contains a proof of Bertrand's postulate: That between any positive number and its
double there is a prime.
The proof follows the outline of the ErdΕs proof presented in "Proofs from THE BOOK": One considers
the prime factorization of `(2 * n).choose n`, and splits the constituent primes up into various
groups, then upper bounds the contribution of each group. This upper bounds the central binomial
coefficient, and if the postulate does not hold, this upper bound conflicts with a simple lower
bound for large enough `n`. This proves the result holds for large enough `n`, and for smaller `n`
an explicit list of primes is provided which covers the remaining cases.
As in the [Metamath implementation](carneiro2015arithmetic), we rely on some optimizations from
[Shigenori Tochiori](tochiori_bertrand). In particular we use the cleaner bound on the central
binomial coefficient given in `Nat.four_pow_lt_mul_centralBinom`.
## References
* [M. Aigner and G. M. Ziegler _Proofs from THE BOOK_][aigner1999proofs]
* [S. Tochiori, _Considering the Proof of βThere is a Prime between n and 2nβ_][tochiori_bertrand]
* [M. Carneiro, _Arithmetic in Metamath, Case Study: Bertrand's Postulate_][carneiro2015arithmetic]
## Tags
Bertrand, prime, binomial coefficients
-/
open scoped BigOperators
section Real
open Real
namespace Bertrand
/-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> norm_num1
apply le_trans _ (le_mul_of_one_le_left _ _) <;> norm_num1
apply Real.rpow_le_rpow <;> norm_num1
apply rpow_nonneg_of_nonneg; norm_num1
apply rpow_pos_of_pos; norm_num1
apply hf' 18; norm_num1
norm_num1
Β· have : sqrt (2 * 512) = 32 :=
(sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
| rw [hf, log_nonpos_iff (hf' _ _), this, div_le_one] | /-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> norm_num1
apply le_trans _ (le_mul_of_one_le_left _ _) <;> norm_num1
apply Real.rpow_le_rpow <;> norm_num1
apply rpow_nonneg_of_nonneg; norm_num1
apply rpow_pos_of_pos; norm_num1
apply hf' 18; norm_num1
norm_num1
Β· have : sqrt (2 * 512) = 32 :=
(sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
| Mathlib.NumberTheory.Bertrand.51_0.gJXoOT9Ce2wC0xc | /-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x | Mathlib_NumberTheory_Bertrand |
case refine'_2
x : β
n_large : 512 β€ x
f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
hf' : β (x : β), 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)
hf : β (x : β), 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3))
h5 : 0 < x
h : ConcaveOn β (Set.Ioi 0.5) f
this : sqrt (2 * 512) = 32
β’ 512 * (2 * 512) ^ 32 β€ 4 ^ (512 / 3) | /-
Copyright (c) 2020 Patrick Stevens. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Stevens, Bolton Bailey
-/
import Mathlib.Data.Nat.Choose.Factorization
import Mathlib.Data.Nat.PrimeNormNum
import Mathlib.NumberTheory.Primorial
import Mathlib.Analysis.Convex.SpecificFunctions.Basic
import Mathlib.Analysis.Convex.SpecificFunctions.Deriv
#align_import number_theory.bertrand from "leanprover-community/mathlib"@"a16665637b378379689c566204817ae792ac8b39"
/-!
# Bertrand's Postulate
This file contains a proof of Bertrand's postulate: That between any positive number and its
double there is a prime.
The proof follows the outline of the ErdΕs proof presented in "Proofs from THE BOOK": One considers
the prime factorization of `(2 * n).choose n`, and splits the constituent primes up into various
groups, then upper bounds the contribution of each group. This upper bounds the central binomial
coefficient, and if the postulate does not hold, this upper bound conflicts with a simple lower
bound for large enough `n`. This proves the result holds for large enough `n`, and for smaller `n`
an explicit list of primes is provided which covers the remaining cases.
As in the [Metamath implementation](carneiro2015arithmetic), we rely on some optimizations from
[Shigenori Tochiori](tochiori_bertrand). In particular we use the cleaner bound on the central
binomial coefficient given in `Nat.four_pow_lt_mul_centralBinom`.
## References
* [M. Aigner and G. M. Ziegler _Proofs from THE BOOK_][aigner1999proofs]
* [S. Tochiori, _Considering the Proof of βThere is a Prime between n and 2nβ_][tochiori_bertrand]
* [M. Carneiro, _Arithmetic in Metamath, Case Study: Bertrand's Postulate_][carneiro2015arithmetic]
## Tags
Bertrand, prime, binomial coefficients
-/
open scoped BigOperators
section Real
open Real
namespace Bertrand
/-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> norm_num1
apply le_trans _ (le_mul_of_one_le_left _ _) <;> norm_num1
apply Real.rpow_le_rpow <;> norm_num1
apply rpow_nonneg_of_nonneg; norm_num1
apply rpow_pos_of_pos; norm_num1
apply hf' 18; norm_num1
norm_num1
Β· have : sqrt (2 * 512) = 32 :=
(sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonpos_iff (hf' _ _), this, div_le_one] <;> | norm_num1 | /-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> norm_num1
apply le_trans _ (le_mul_of_one_le_left _ _) <;> norm_num1
apply Real.rpow_le_rpow <;> norm_num1
apply rpow_nonneg_of_nonneg; norm_num1
apply rpow_pos_of_pos; norm_num1
apply hf' 18; norm_num1
norm_num1
Β· have : sqrt (2 * 512) = 32 :=
(sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonpos_iff (hf' _ _), this, div_le_one] <;> | Mathlib.NumberTheory.Bertrand.51_0.gJXoOT9Ce2wC0xc | /-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x | Mathlib_NumberTheory_Bertrand |
case refine'_2
x : β
n_large : 512 β€ x
f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
hf' : β (x : β), 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)
hf : β (x : β), 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3))
h5 : 0 < x
h : ConcaveOn β (Set.Ioi 0.5) f
this : sqrt (2 * 512) = 32
β’ 0 < 4 ^ (512 / 3) | /-
Copyright (c) 2020 Patrick Stevens. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Stevens, Bolton Bailey
-/
import Mathlib.Data.Nat.Choose.Factorization
import Mathlib.Data.Nat.PrimeNormNum
import Mathlib.NumberTheory.Primorial
import Mathlib.Analysis.Convex.SpecificFunctions.Basic
import Mathlib.Analysis.Convex.SpecificFunctions.Deriv
#align_import number_theory.bertrand from "leanprover-community/mathlib"@"a16665637b378379689c566204817ae792ac8b39"
/-!
# Bertrand's Postulate
This file contains a proof of Bertrand's postulate: That between any positive number and its
double there is a prime.
The proof follows the outline of the ErdΕs proof presented in "Proofs from THE BOOK": One considers
the prime factorization of `(2 * n).choose n`, and splits the constituent primes up into various
groups, then upper bounds the contribution of each group. This upper bounds the central binomial
coefficient, and if the postulate does not hold, this upper bound conflicts with a simple lower
bound for large enough `n`. This proves the result holds for large enough `n`, and for smaller `n`
an explicit list of primes is provided which covers the remaining cases.
As in the [Metamath implementation](carneiro2015arithmetic), we rely on some optimizations from
[Shigenori Tochiori](tochiori_bertrand). In particular we use the cleaner bound on the central
binomial coefficient given in `Nat.four_pow_lt_mul_centralBinom`.
## References
* [M. Aigner and G. M. Ziegler _Proofs from THE BOOK_][aigner1999proofs]
* [S. Tochiori, _Considering the Proof of βThere is a Prime between n and 2nβ_][tochiori_bertrand]
* [M. Carneiro, _Arithmetic in Metamath, Case Study: Bertrand's Postulate_][carneiro2015arithmetic]
## Tags
Bertrand, prime, binomial coefficients
-/
open scoped BigOperators
section Real
open Real
namespace Bertrand
/-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> norm_num1
apply le_trans _ (le_mul_of_one_le_left _ _) <;> norm_num1
apply Real.rpow_le_rpow <;> norm_num1
apply rpow_nonneg_of_nonneg; norm_num1
apply rpow_pos_of_pos; norm_num1
apply hf' 18; norm_num1
norm_num1
Β· have : sqrt (2 * 512) = 32 :=
(sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonpos_iff (hf' _ _), this, div_le_one] <;> | norm_num1 | /-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> norm_num1
apply le_trans _ (le_mul_of_one_le_left _ _) <;> norm_num1
apply Real.rpow_le_rpow <;> norm_num1
apply rpow_nonneg_of_nonneg; norm_num1
apply rpow_pos_of_pos; norm_num1
apply hf' 18; norm_num1
norm_num1
Β· have : sqrt (2 * 512) = 32 :=
(sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonpos_iff (hf' _ _), this, div_le_one] <;> | Mathlib.NumberTheory.Bertrand.51_0.gJXoOT9Ce2wC0xc | /-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x | Mathlib_NumberTheory_Bertrand |
x : β
n_large : 512 β€ x
f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
hf' : β (x : β), 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)
hf : β (x : β), 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3))
h5 : 0 < x
h : ConcaveOn β (Set.Ioi 0.5) f
this : sqrt (2 * 512) = 32
β’ 0 < 512 | /-
Copyright (c) 2020 Patrick Stevens. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Stevens, Bolton Bailey
-/
import Mathlib.Data.Nat.Choose.Factorization
import Mathlib.Data.Nat.PrimeNormNum
import Mathlib.NumberTheory.Primorial
import Mathlib.Analysis.Convex.SpecificFunctions.Basic
import Mathlib.Analysis.Convex.SpecificFunctions.Deriv
#align_import number_theory.bertrand from "leanprover-community/mathlib"@"a16665637b378379689c566204817ae792ac8b39"
/-!
# Bertrand's Postulate
This file contains a proof of Bertrand's postulate: That between any positive number and its
double there is a prime.
The proof follows the outline of the ErdΕs proof presented in "Proofs from THE BOOK": One considers
the prime factorization of `(2 * n).choose n`, and splits the constituent primes up into various
groups, then upper bounds the contribution of each group. This upper bounds the central binomial
coefficient, and if the postulate does not hold, this upper bound conflicts with a simple lower
bound for large enough `n`. This proves the result holds for large enough `n`, and for smaller `n`
an explicit list of primes is provided which covers the remaining cases.
As in the [Metamath implementation](carneiro2015arithmetic), we rely on some optimizations from
[Shigenori Tochiori](tochiori_bertrand). In particular we use the cleaner bound on the central
binomial coefficient given in `Nat.four_pow_lt_mul_centralBinom`.
## References
* [M. Aigner and G. M. Ziegler _Proofs from THE BOOK_][aigner1999proofs]
* [S. Tochiori, _Considering the Proof of βThere is a Prime between n and 2nβ_][tochiori_bertrand]
* [M. Carneiro, _Arithmetic in Metamath, Case Study: Bertrand's Postulate_][carneiro2015arithmetic]
## Tags
Bertrand, prime, binomial coefficients
-/
open scoped BigOperators
section Real
open Real
namespace Bertrand
/-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> norm_num1
apply le_trans _ (le_mul_of_one_le_left _ _) <;> norm_num1
apply Real.rpow_le_rpow <;> norm_num1
apply rpow_nonneg_of_nonneg; norm_num1
apply rpow_pos_of_pos; norm_num1
apply hf' 18; norm_num1
norm_num1
Β· have : sqrt (2 * 512) = 32 :=
(sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonpos_iff (hf' _ _), this, div_le_one] <;> | norm_num1 | /-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> norm_num1
apply le_trans _ (le_mul_of_one_le_left _ _) <;> norm_num1
apply Real.rpow_le_rpow <;> norm_num1
apply rpow_nonneg_of_nonneg; norm_num1
apply rpow_pos_of_pos; norm_num1
apply hf' 18; norm_num1
norm_num1
Β· have : sqrt (2 * 512) = 32 :=
(sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonpos_iff (hf' _ _), this, div_le_one] <;> | Mathlib.NumberTheory.Bertrand.51_0.gJXoOT9Ce2wC0xc | /-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x | Mathlib_NumberTheory_Bertrand |
case refine'_2.a
x : β
n_large : 512 β€ x
f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
hf' : β (x : β), 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)
hf : β (x : β), 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3))
h5 : 0 < x
h : ConcaveOn β (Set.Ioi 0.5) f
this : sqrt (2 * 512) = 32
β’ 0 < 512 | /-
Copyright (c) 2020 Patrick Stevens. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Stevens, Bolton Bailey
-/
import Mathlib.Data.Nat.Choose.Factorization
import Mathlib.Data.Nat.PrimeNormNum
import Mathlib.NumberTheory.Primorial
import Mathlib.Analysis.Convex.SpecificFunctions.Basic
import Mathlib.Analysis.Convex.SpecificFunctions.Deriv
#align_import number_theory.bertrand from "leanprover-community/mathlib"@"a16665637b378379689c566204817ae792ac8b39"
/-!
# Bertrand's Postulate
This file contains a proof of Bertrand's postulate: That between any positive number and its
double there is a prime.
The proof follows the outline of the ErdΕs proof presented in "Proofs from THE BOOK": One considers
the prime factorization of `(2 * n).choose n`, and splits the constituent primes up into various
groups, then upper bounds the contribution of each group. This upper bounds the central binomial
coefficient, and if the postulate does not hold, this upper bound conflicts with a simple lower
bound for large enough `n`. This proves the result holds for large enough `n`, and for smaller `n`
an explicit list of primes is provided which covers the remaining cases.
As in the [Metamath implementation](carneiro2015arithmetic), we rely on some optimizations from
[Shigenori Tochiori](tochiori_bertrand). In particular we use the cleaner bound on the central
binomial coefficient given in `Nat.four_pow_lt_mul_centralBinom`.
## References
* [M. Aigner and G. M. Ziegler _Proofs from THE BOOK_][aigner1999proofs]
* [S. Tochiori, _Considering the Proof of βThere is a Prime between n and 2nβ_][tochiori_bertrand]
* [M. Carneiro, _Arithmetic in Metamath, Case Study: Bertrand's Postulate_][carneiro2015arithmetic]
## Tags
Bertrand, prime, binomial coefficients
-/
open scoped BigOperators
section Real
open Real
namespace Bertrand
/-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> norm_num1
apply le_trans _ (le_mul_of_one_le_left _ _) <;> norm_num1
apply Real.rpow_le_rpow <;> norm_num1
apply rpow_nonneg_of_nonneg; norm_num1
apply rpow_pos_of_pos; norm_num1
apply hf' 18; norm_num1
norm_num1
Β· have : sqrt (2 * 512) = 32 :=
(sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonpos_iff (hf' _ _), this, div_le_one] <;> | norm_num1 | /-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> norm_num1
apply le_trans _ (le_mul_of_one_le_left _ _) <;> norm_num1
apply Real.rpow_le_rpow <;> norm_num1
apply rpow_nonneg_of_nonneg; norm_num1
apply rpow_pos_of_pos; norm_num1
apply hf' 18; norm_num1
norm_num1
Β· have : sqrt (2 * 512) = 32 :=
(sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonpos_iff (hf' _ _), this, div_le_one] <;> | Mathlib.NumberTheory.Bertrand.51_0.gJXoOT9Ce2wC0xc | /-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x | Mathlib_NumberTheory_Bertrand |
case refine'_2
x : β
n_large : 512 β€ x
f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
hf' : β (x : β), 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)
hf : β (x : β), 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3))
h5 : 0 < x
h : ConcaveOn β (Set.Ioi 0.5) f
this : sqrt (2 * 512) = 32
β’ 512 * 1024 ^ 32 β€ 4 ^ (512 / 3) | /-
Copyright (c) 2020 Patrick Stevens. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Stevens, Bolton Bailey
-/
import Mathlib.Data.Nat.Choose.Factorization
import Mathlib.Data.Nat.PrimeNormNum
import Mathlib.NumberTheory.Primorial
import Mathlib.Analysis.Convex.SpecificFunctions.Basic
import Mathlib.Analysis.Convex.SpecificFunctions.Deriv
#align_import number_theory.bertrand from "leanprover-community/mathlib"@"a16665637b378379689c566204817ae792ac8b39"
/-!
# Bertrand's Postulate
This file contains a proof of Bertrand's postulate: That between any positive number and its
double there is a prime.
The proof follows the outline of the ErdΕs proof presented in "Proofs from THE BOOK": One considers
the prime factorization of `(2 * n).choose n`, and splits the constituent primes up into various
groups, then upper bounds the contribution of each group. This upper bounds the central binomial
coefficient, and if the postulate does not hold, this upper bound conflicts with a simple lower
bound for large enough `n`. This proves the result holds for large enough `n`, and for smaller `n`
an explicit list of primes is provided which covers the remaining cases.
As in the [Metamath implementation](carneiro2015arithmetic), we rely on some optimizations from
[Shigenori Tochiori](tochiori_bertrand). In particular we use the cleaner bound on the central
binomial coefficient given in `Nat.four_pow_lt_mul_centralBinom`.
## References
* [M. Aigner and G. M. Ziegler _Proofs from THE BOOK_][aigner1999proofs]
* [S. Tochiori, _Considering the Proof of βThere is a Prime between n and 2nβ_][tochiori_bertrand]
* [M. Carneiro, _Arithmetic in Metamath, Case Study: Bertrand's Postulate_][carneiro2015arithmetic]
## Tags
Bertrand, prime, binomial coefficients
-/
open scoped BigOperators
section Real
open Real
namespace Bertrand
/-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> norm_num1
apply le_trans _ (le_mul_of_one_le_left _ _) <;> norm_num1
apply Real.rpow_le_rpow <;> norm_num1
apply rpow_nonneg_of_nonneg; norm_num1
apply rpow_pos_of_pos; norm_num1
apply hf' 18; norm_num1
norm_num1
Β· have : sqrt (2 * 512) = 32 :=
(sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonpos_iff (hf' _ _), this, div_le_one] <;> norm_num1
Β· | conv in 512 => equals 2 ^ 9 => norm_num1 | /-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> norm_num1
apply le_trans _ (le_mul_of_one_le_left _ _) <;> norm_num1
apply Real.rpow_le_rpow <;> norm_num1
apply rpow_nonneg_of_nonneg; norm_num1
apply rpow_pos_of_pos; norm_num1
apply hf' 18; norm_num1
norm_num1
Β· have : sqrt (2 * 512) = 32 :=
(sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonpos_iff (hf' _ _), this, div_le_one] <;> norm_num1
Β· | Mathlib.NumberTheory.Bertrand.51_0.gJXoOT9Ce2wC0xc | /-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x | Mathlib_NumberTheory_Bertrand |
x : β
n_large : 512 β€ x
f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
hf' : β (x : β), 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)
hf : β (x : β), 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3))
h5 : 0 < x
h : ConcaveOn β (Set.Ioi 0.5) f
this : sqrt (2 * 512) = 32
| 512 | /-
Copyright (c) 2020 Patrick Stevens. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Stevens, Bolton Bailey
-/
import Mathlib.Data.Nat.Choose.Factorization
import Mathlib.Data.Nat.PrimeNormNum
import Mathlib.NumberTheory.Primorial
import Mathlib.Analysis.Convex.SpecificFunctions.Basic
import Mathlib.Analysis.Convex.SpecificFunctions.Deriv
#align_import number_theory.bertrand from "leanprover-community/mathlib"@"a16665637b378379689c566204817ae792ac8b39"
/-!
# Bertrand's Postulate
This file contains a proof of Bertrand's postulate: That between any positive number and its
double there is a prime.
The proof follows the outline of the ErdΕs proof presented in "Proofs from THE BOOK": One considers
the prime factorization of `(2 * n).choose n`, and splits the constituent primes up into various
groups, then upper bounds the contribution of each group. This upper bounds the central binomial
coefficient, and if the postulate does not hold, this upper bound conflicts with a simple lower
bound for large enough `n`. This proves the result holds for large enough `n`, and for smaller `n`
an explicit list of primes is provided which covers the remaining cases.
As in the [Metamath implementation](carneiro2015arithmetic), we rely on some optimizations from
[Shigenori Tochiori](tochiori_bertrand). In particular we use the cleaner bound on the central
binomial coefficient given in `Nat.four_pow_lt_mul_centralBinom`.
## References
* [M. Aigner and G. M. Ziegler _Proofs from THE BOOK_][aigner1999proofs]
* [S. Tochiori, _Considering the Proof of βThere is a Prime between n and 2nβ_][tochiori_bertrand]
* [M. Carneiro, _Arithmetic in Metamath, Case Study: Bertrand's Postulate_][carneiro2015arithmetic]
## Tags
Bertrand, prime, binomial coefficients
-/
open scoped BigOperators
section Real
open Real
namespace Bertrand
/-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> norm_num1
apply le_trans _ (le_mul_of_one_le_left _ _) <;> norm_num1
apply Real.rpow_le_rpow <;> norm_num1
apply rpow_nonneg_of_nonneg; norm_num1
apply rpow_pos_of_pos; norm_num1
apply hf' 18; norm_num1
norm_num1
Β· have : sqrt (2 * 512) = 32 :=
(sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonpos_iff (hf' _ _), this, div_le_one] <;> norm_num1
Β· conv in 512 => | equals 2 ^ 9 => norm_num1 | /-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> norm_num1
apply le_trans _ (le_mul_of_one_le_left _ _) <;> norm_num1
apply Real.rpow_le_rpow <;> norm_num1
apply rpow_nonneg_of_nonneg; norm_num1
apply rpow_pos_of_pos; norm_num1
apply hf' 18; norm_num1
norm_num1
Β· have : sqrt (2 * 512) = 32 :=
(sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonpos_iff (hf' _ _), this, div_le_one] <;> norm_num1
Β· conv in 512 => | Mathlib.NumberTheory.Bertrand.51_0.gJXoOT9Ce2wC0xc | /-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x | Mathlib_NumberTheory_Bertrand |
x : β
n_large : 512 β€ x
f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
hf' : β (x : β), 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)
hf : β (x : β), 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3))
h5 : 0 < x
h : ConcaveOn β (Set.Ioi 0.5) f
this : sqrt (2 * 512) = 32
| 512 | /-
Copyright (c) 2020 Patrick Stevens. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Stevens, Bolton Bailey
-/
import Mathlib.Data.Nat.Choose.Factorization
import Mathlib.Data.Nat.PrimeNormNum
import Mathlib.NumberTheory.Primorial
import Mathlib.Analysis.Convex.SpecificFunctions.Basic
import Mathlib.Analysis.Convex.SpecificFunctions.Deriv
#align_import number_theory.bertrand from "leanprover-community/mathlib"@"a16665637b378379689c566204817ae792ac8b39"
/-!
# Bertrand's Postulate
This file contains a proof of Bertrand's postulate: That between any positive number and its
double there is a prime.
The proof follows the outline of the ErdΕs proof presented in "Proofs from THE BOOK": One considers
the prime factorization of `(2 * n).choose n`, and splits the constituent primes up into various
groups, then upper bounds the contribution of each group. This upper bounds the central binomial
coefficient, and if the postulate does not hold, this upper bound conflicts with a simple lower
bound for large enough `n`. This proves the result holds for large enough `n`, and for smaller `n`
an explicit list of primes is provided which covers the remaining cases.
As in the [Metamath implementation](carneiro2015arithmetic), we rely on some optimizations from
[Shigenori Tochiori](tochiori_bertrand). In particular we use the cleaner bound on the central
binomial coefficient given in `Nat.four_pow_lt_mul_centralBinom`.
## References
* [M. Aigner and G. M. Ziegler _Proofs from THE BOOK_][aigner1999proofs]
* [S. Tochiori, _Considering the Proof of βThere is a Prime between n and 2nβ_][tochiori_bertrand]
* [M. Carneiro, _Arithmetic in Metamath, Case Study: Bertrand's Postulate_][carneiro2015arithmetic]
## Tags
Bertrand, prime, binomial coefficients
-/
open scoped BigOperators
section Real
open Real
namespace Bertrand
/-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> norm_num1
apply le_trans _ (le_mul_of_one_le_left _ _) <;> norm_num1
apply Real.rpow_le_rpow <;> norm_num1
apply rpow_nonneg_of_nonneg; norm_num1
apply rpow_pos_of_pos; norm_num1
apply hf' 18; norm_num1
norm_num1
Β· have : sqrt (2 * 512) = 32 :=
(sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonpos_iff (hf' _ _), this, div_le_one] <;> norm_num1
Β· conv in 512 => | equals 2 ^ 9 => norm_num1 | /-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> norm_num1
apply le_trans _ (le_mul_of_one_le_left _ _) <;> norm_num1
apply Real.rpow_le_rpow <;> norm_num1
apply rpow_nonneg_of_nonneg; norm_num1
apply rpow_pos_of_pos; norm_num1
apply hf' 18; norm_num1
norm_num1
Β· have : sqrt (2 * 512) = 32 :=
(sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonpos_iff (hf' _ _), this, div_le_one] <;> norm_num1
Β· conv in 512 => | Mathlib.NumberTheory.Bertrand.51_0.gJXoOT9Ce2wC0xc | /-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x | Mathlib_NumberTheory_Bertrand |
x : β
n_large : 512 β€ x
f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
hf' : β (x : β), 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)
hf : β (x : β), 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3))
h5 : 0 < x
h : ConcaveOn β (Set.Ioi 0.5) f
this : sqrt (2 * 512) = 32
| 512 | /-
Copyright (c) 2020 Patrick Stevens. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Stevens, Bolton Bailey
-/
import Mathlib.Data.Nat.Choose.Factorization
import Mathlib.Data.Nat.PrimeNormNum
import Mathlib.NumberTheory.Primorial
import Mathlib.Analysis.Convex.SpecificFunctions.Basic
import Mathlib.Analysis.Convex.SpecificFunctions.Deriv
#align_import number_theory.bertrand from "leanprover-community/mathlib"@"a16665637b378379689c566204817ae792ac8b39"
/-!
# Bertrand's Postulate
This file contains a proof of Bertrand's postulate: That between any positive number and its
double there is a prime.
The proof follows the outline of the ErdΕs proof presented in "Proofs from THE BOOK": One considers
the prime factorization of `(2 * n).choose n`, and splits the constituent primes up into various
groups, then upper bounds the contribution of each group. This upper bounds the central binomial
coefficient, and if the postulate does not hold, this upper bound conflicts with a simple lower
bound for large enough `n`. This proves the result holds for large enough `n`, and for smaller `n`
an explicit list of primes is provided which covers the remaining cases.
As in the [Metamath implementation](carneiro2015arithmetic), we rely on some optimizations from
[Shigenori Tochiori](tochiori_bertrand). In particular we use the cleaner bound on the central
binomial coefficient given in `Nat.four_pow_lt_mul_centralBinom`.
## References
* [M. Aigner and G. M. Ziegler _Proofs from THE BOOK_][aigner1999proofs]
* [S. Tochiori, _Considering the Proof of βThere is a Prime between n and 2nβ_][tochiori_bertrand]
* [M. Carneiro, _Arithmetic in Metamath, Case Study: Bertrand's Postulate_][carneiro2015arithmetic]
## Tags
Bertrand, prime, binomial coefficients
-/
open scoped BigOperators
section Real
open Real
namespace Bertrand
/-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> norm_num1
apply le_trans _ (le_mul_of_one_le_left _ _) <;> norm_num1
apply Real.rpow_le_rpow <;> norm_num1
apply rpow_nonneg_of_nonneg; norm_num1
apply rpow_pos_of_pos; norm_num1
apply hf' 18; norm_num1
norm_num1
Β· have : sqrt (2 * 512) = 32 :=
(sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonpos_iff (hf' _ _), this, div_le_one] <;> norm_num1
Β· conv in 512 => | equals 2 ^ 9 => norm_num1 | /-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> norm_num1
apply le_trans _ (le_mul_of_one_le_left _ _) <;> norm_num1
apply Real.rpow_le_rpow <;> norm_num1
apply rpow_nonneg_of_nonneg; norm_num1
apply rpow_pos_of_pos; norm_num1
apply hf' 18; norm_num1
norm_num1
Β· have : sqrt (2 * 512) = 32 :=
(sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonpos_iff (hf' _ _), this, div_le_one] <;> norm_num1
Β· conv in 512 => | Mathlib.NumberTheory.Bertrand.51_0.gJXoOT9Ce2wC0xc | /-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x | Mathlib_NumberTheory_Bertrand |
x : β
n_large : 512 β€ x
f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
hf' : β (x : β), 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)
hf : β (x : β), 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3))
h5 : 0 < x
h : ConcaveOn β (Set.Ioi 0.5) f
this : sqrt (2 * 512) = 32
β’ 512 = 2 ^ 9 | /-
Copyright (c) 2020 Patrick Stevens. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Stevens, Bolton Bailey
-/
import Mathlib.Data.Nat.Choose.Factorization
import Mathlib.Data.Nat.PrimeNormNum
import Mathlib.NumberTheory.Primorial
import Mathlib.Analysis.Convex.SpecificFunctions.Basic
import Mathlib.Analysis.Convex.SpecificFunctions.Deriv
#align_import number_theory.bertrand from "leanprover-community/mathlib"@"a16665637b378379689c566204817ae792ac8b39"
/-!
# Bertrand's Postulate
This file contains a proof of Bertrand's postulate: That between any positive number and its
double there is a prime.
The proof follows the outline of the ErdΕs proof presented in "Proofs from THE BOOK": One considers
the prime factorization of `(2 * n).choose n`, and splits the constituent primes up into various
groups, then upper bounds the contribution of each group. This upper bounds the central binomial
coefficient, and if the postulate does not hold, this upper bound conflicts with a simple lower
bound for large enough `n`. This proves the result holds for large enough `n`, and for smaller `n`
an explicit list of primes is provided which covers the remaining cases.
As in the [Metamath implementation](carneiro2015arithmetic), we rely on some optimizations from
[Shigenori Tochiori](tochiori_bertrand). In particular we use the cleaner bound on the central
binomial coefficient given in `Nat.four_pow_lt_mul_centralBinom`.
## References
* [M. Aigner and G. M. Ziegler _Proofs from THE BOOK_][aigner1999proofs]
* [S. Tochiori, _Considering the Proof of βThere is a Prime between n and 2nβ_][tochiori_bertrand]
* [M. Carneiro, _Arithmetic in Metamath, Case Study: Bertrand's Postulate_][carneiro2015arithmetic]
## Tags
Bertrand, prime, binomial coefficients
-/
open scoped BigOperators
section Real
open Real
namespace Bertrand
/-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> norm_num1
apply le_trans _ (le_mul_of_one_le_left _ _) <;> norm_num1
apply Real.rpow_le_rpow <;> norm_num1
apply rpow_nonneg_of_nonneg; norm_num1
apply rpow_pos_of_pos; norm_num1
apply hf' 18; norm_num1
norm_num1
Β· have : sqrt (2 * 512) = 32 :=
(sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonpos_iff (hf' _ _), this, div_le_one] <;> norm_num1
Β· conv in 512 => equals 2 ^ 9 => | norm_num1 | /-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> norm_num1
apply le_trans _ (le_mul_of_one_le_left _ _) <;> norm_num1
apply Real.rpow_le_rpow <;> norm_num1
apply rpow_nonneg_of_nonneg; norm_num1
apply rpow_pos_of_pos; norm_num1
apply hf' 18; norm_num1
norm_num1
Β· have : sqrt (2 * 512) = 32 :=
(sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonpos_iff (hf' _ _), this, div_le_one] <;> norm_num1
Β· conv in 512 => equals 2 ^ 9 => | Mathlib.NumberTheory.Bertrand.51_0.gJXoOT9Ce2wC0xc | /-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x | Mathlib_NumberTheory_Bertrand |
case refine'_2
x : β
n_large : 512 β€ x
f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
hf' : β (x : β), 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)
hf : β (x : β), 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3))
h5 : 0 < x
h : ConcaveOn β (Set.Ioi 0.5) f
this : sqrt (2 * 512) = 32
β’ 2 ^ 9 * 1024 ^ 32 β€ 4 ^ (512 / 3) | /-
Copyright (c) 2020 Patrick Stevens. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Stevens, Bolton Bailey
-/
import Mathlib.Data.Nat.Choose.Factorization
import Mathlib.Data.Nat.PrimeNormNum
import Mathlib.NumberTheory.Primorial
import Mathlib.Analysis.Convex.SpecificFunctions.Basic
import Mathlib.Analysis.Convex.SpecificFunctions.Deriv
#align_import number_theory.bertrand from "leanprover-community/mathlib"@"a16665637b378379689c566204817ae792ac8b39"
/-!
# Bertrand's Postulate
This file contains a proof of Bertrand's postulate: That between any positive number and its
double there is a prime.
The proof follows the outline of the ErdΕs proof presented in "Proofs from THE BOOK": One considers
the prime factorization of `(2 * n).choose n`, and splits the constituent primes up into various
groups, then upper bounds the contribution of each group. This upper bounds the central binomial
coefficient, and if the postulate does not hold, this upper bound conflicts with a simple lower
bound for large enough `n`. This proves the result holds for large enough `n`, and for smaller `n`
an explicit list of primes is provided which covers the remaining cases.
As in the [Metamath implementation](carneiro2015arithmetic), we rely on some optimizations from
[Shigenori Tochiori](tochiori_bertrand). In particular we use the cleaner bound on the central
binomial coefficient given in `Nat.four_pow_lt_mul_centralBinom`.
## References
* [M. Aigner and G. M. Ziegler _Proofs from THE BOOK_][aigner1999proofs]
* [S. Tochiori, _Considering the Proof of βThere is a Prime between n and 2nβ_][tochiori_bertrand]
* [M. Carneiro, _Arithmetic in Metamath, Case Study: Bertrand's Postulate_][carneiro2015arithmetic]
## Tags
Bertrand, prime, binomial coefficients
-/
open scoped BigOperators
section Real
open Real
namespace Bertrand
/-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> norm_num1
apply le_trans _ (le_mul_of_one_le_left _ _) <;> norm_num1
apply Real.rpow_le_rpow <;> norm_num1
apply rpow_nonneg_of_nonneg; norm_num1
apply rpow_pos_of_pos; norm_num1
apply hf' 18; norm_num1
norm_num1
Β· have : sqrt (2 * 512) = 32 :=
(sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonpos_iff (hf' _ _), this, div_le_one] <;> norm_num1
Β· conv in 512 => equals 2 ^ 9 => norm_num1
| conv in 1024 => equals 2 ^ 10 => norm_num1 | /-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> norm_num1
apply le_trans _ (le_mul_of_one_le_left _ _) <;> norm_num1
apply Real.rpow_le_rpow <;> norm_num1
apply rpow_nonneg_of_nonneg; norm_num1
apply rpow_pos_of_pos; norm_num1
apply hf' 18; norm_num1
norm_num1
Β· have : sqrt (2 * 512) = 32 :=
(sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonpos_iff (hf' _ _), this, div_le_one] <;> norm_num1
Β· conv in 512 => equals 2 ^ 9 => norm_num1
| Mathlib.NumberTheory.Bertrand.51_0.gJXoOT9Ce2wC0xc | /-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x | Mathlib_NumberTheory_Bertrand |
x : β
n_large : 512 β€ x
f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
hf' : β (x : β), 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)
hf : β (x : β), 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3))
h5 : 0 < x
h : ConcaveOn β (Set.Ioi 0.5) f
this : sqrt (2 * 512) = 32
| 1024 | /-
Copyright (c) 2020 Patrick Stevens. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Stevens, Bolton Bailey
-/
import Mathlib.Data.Nat.Choose.Factorization
import Mathlib.Data.Nat.PrimeNormNum
import Mathlib.NumberTheory.Primorial
import Mathlib.Analysis.Convex.SpecificFunctions.Basic
import Mathlib.Analysis.Convex.SpecificFunctions.Deriv
#align_import number_theory.bertrand from "leanprover-community/mathlib"@"a16665637b378379689c566204817ae792ac8b39"
/-!
# Bertrand's Postulate
This file contains a proof of Bertrand's postulate: That between any positive number and its
double there is a prime.
The proof follows the outline of the ErdΕs proof presented in "Proofs from THE BOOK": One considers
the prime factorization of `(2 * n).choose n`, and splits the constituent primes up into various
groups, then upper bounds the contribution of each group. This upper bounds the central binomial
coefficient, and if the postulate does not hold, this upper bound conflicts with a simple lower
bound for large enough `n`. This proves the result holds for large enough `n`, and for smaller `n`
an explicit list of primes is provided which covers the remaining cases.
As in the [Metamath implementation](carneiro2015arithmetic), we rely on some optimizations from
[Shigenori Tochiori](tochiori_bertrand). In particular we use the cleaner bound on the central
binomial coefficient given in `Nat.four_pow_lt_mul_centralBinom`.
## References
* [M. Aigner and G. M. Ziegler _Proofs from THE BOOK_][aigner1999proofs]
* [S. Tochiori, _Considering the Proof of βThere is a Prime between n and 2nβ_][tochiori_bertrand]
* [M. Carneiro, _Arithmetic in Metamath, Case Study: Bertrand's Postulate_][carneiro2015arithmetic]
## Tags
Bertrand, prime, binomial coefficients
-/
open scoped BigOperators
section Real
open Real
namespace Bertrand
/-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> norm_num1
apply le_trans _ (le_mul_of_one_le_left _ _) <;> norm_num1
apply Real.rpow_le_rpow <;> norm_num1
apply rpow_nonneg_of_nonneg; norm_num1
apply rpow_pos_of_pos; norm_num1
apply hf' 18; norm_num1
norm_num1
Β· have : sqrt (2 * 512) = 32 :=
(sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonpos_iff (hf' _ _), this, div_le_one] <;> norm_num1
Β· conv in 512 => equals 2 ^ 9 => norm_num1
conv in 1024 => | equals 2 ^ 10 => norm_num1 | /-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> norm_num1
apply le_trans _ (le_mul_of_one_le_left _ _) <;> norm_num1
apply Real.rpow_le_rpow <;> norm_num1
apply rpow_nonneg_of_nonneg; norm_num1
apply rpow_pos_of_pos; norm_num1
apply hf' 18; norm_num1
norm_num1
Β· have : sqrt (2 * 512) = 32 :=
(sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonpos_iff (hf' _ _), this, div_le_one] <;> norm_num1
Β· conv in 512 => equals 2 ^ 9 => norm_num1
conv in 1024 => | Mathlib.NumberTheory.Bertrand.51_0.gJXoOT9Ce2wC0xc | /-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x | Mathlib_NumberTheory_Bertrand |
x : β
n_large : 512 β€ x
f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
hf' : β (x : β), 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)
hf : β (x : β), 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3))
h5 : 0 < x
h : ConcaveOn β (Set.Ioi 0.5) f
this : sqrt (2 * 512) = 32
| 1024 | /-
Copyright (c) 2020 Patrick Stevens. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Stevens, Bolton Bailey
-/
import Mathlib.Data.Nat.Choose.Factorization
import Mathlib.Data.Nat.PrimeNormNum
import Mathlib.NumberTheory.Primorial
import Mathlib.Analysis.Convex.SpecificFunctions.Basic
import Mathlib.Analysis.Convex.SpecificFunctions.Deriv
#align_import number_theory.bertrand from "leanprover-community/mathlib"@"a16665637b378379689c566204817ae792ac8b39"
/-!
# Bertrand's Postulate
This file contains a proof of Bertrand's postulate: That between any positive number and its
double there is a prime.
The proof follows the outline of the ErdΕs proof presented in "Proofs from THE BOOK": One considers
the prime factorization of `(2 * n).choose n`, and splits the constituent primes up into various
groups, then upper bounds the contribution of each group. This upper bounds the central binomial
coefficient, and if the postulate does not hold, this upper bound conflicts with a simple lower
bound for large enough `n`. This proves the result holds for large enough `n`, and for smaller `n`
an explicit list of primes is provided which covers the remaining cases.
As in the [Metamath implementation](carneiro2015arithmetic), we rely on some optimizations from
[Shigenori Tochiori](tochiori_bertrand). In particular we use the cleaner bound on the central
binomial coefficient given in `Nat.four_pow_lt_mul_centralBinom`.
## References
* [M. Aigner and G. M. Ziegler _Proofs from THE BOOK_][aigner1999proofs]
* [S. Tochiori, _Considering the Proof of βThere is a Prime between n and 2nβ_][tochiori_bertrand]
* [M. Carneiro, _Arithmetic in Metamath, Case Study: Bertrand's Postulate_][carneiro2015arithmetic]
## Tags
Bertrand, prime, binomial coefficients
-/
open scoped BigOperators
section Real
open Real
namespace Bertrand
/-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> norm_num1
apply le_trans _ (le_mul_of_one_le_left _ _) <;> norm_num1
apply Real.rpow_le_rpow <;> norm_num1
apply rpow_nonneg_of_nonneg; norm_num1
apply rpow_pos_of_pos; norm_num1
apply hf' 18; norm_num1
norm_num1
Β· have : sqrt (2 * 512) = 32 :=
(sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonpos_iff (hf' _ _), this, div_le_one] <;> norm_num1
Β· conv in 512 => equals 2 ^ 9 => norm_num1
conv in 1024 => | equals 2 ^ 10 => norm_num1 | /-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> norm_num1
apply le_trans _ (le_mul_of_one_le_left _ _) <;> norm_num1
apply Real.rpow_le_rpow <;> norm_num1
apply rpow_nonneg_of_nonneg; norm_num1
apply rpow_pos_of_pos; norm_num1
apply hf' 18; norm_num1
norm_num1
Β· have : sqrt (2 * 512) = 32 :=
(sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonpos_iff (hf' _ _), this, div_le_one] <;> norm_num1
Β· conv in 512 => equals 2 ^ 9 => norm_num1
conv in 1024 => | Mathlib.NumberTheory.Bertrand.51_0.gJXoOT9Ce2wC0xc | /-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x | Mathlib_NumberTheory_Bertrand |
x : β
n_large : 512 β€ x
f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
hf' : β (x : β), 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)
hf : β (x : β), 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3))
h5 : 0 < x
h : ConcaveOn β (Set.Ioi 0.5) f
this : sqrt (2 * 512) = 32
| 1024 | /-
Copyright (c) 2020 Patrick Stevens. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Stevens, Bolton Bailey
-/
import Mathlib.Data.Nat.Choose.Factorization
import Mathlib.Data.Nat.PrimeNormNum
import Mathlib.NumberTheory.Primorial
import Mathlib.Analysis.Convex.SpecificFunctions.Basic
import Mathlib.Analysis.Convex.SpecificFunctions.Deriv
#align_import number_theory.bertrand from "leanprover-community/mathlib"@"a16665637b378379689c566204817ae792ac8b39"
/-!
# Bertrand's Postulate
This file contains a proof of Bertrand's postulate: That between any positive number and its
double there is a prime.
The proof follows the outline of the ErdΕs proof presented in "Proofs from THE BOOK": One considers
the prime factorization of `(2 * n).choose n`, and splits the constituent primes up into various
groups, then upper bounds the contribution of each group. This upper bounds the central binomial
coefficient, and if the postulate does not hold, this upper bound conflicts with a simple lower
bound for large enough `n`. This proves the result holds for large enough `n`, and for smaller `n`
an explicit list of primes is provided which covers the remaining cases.
As in the [Metamath implementation](carneiro2015arithmetic), we rely on some optimizations from
[Shigenori Tochiori](tochiori_bertrand). In particular we use the cleaner bound on the central
binomial coefficient given in `Nat.four_pow_lt_mul_centralBinom`.
## References
* [M. Aigner and G. M. Ziegler _Proofs from THE BOOK_][aigner1999proofs]
* [S. Tochiori, _Considering the Proof of βThere is a Prime between n and 2nβ_][tochiori_bertrand]
* [M. Carneiro, _Arithmetic in Metamath, Case Study: Bertrand's Postulate_][carneiro2015arithmetic]
## Tags
Bertrand, prime, binomial coefficients
-/
open scoped BigOperators
section Real
open Real
namespace Bertrand
/-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> norm_num1
apply le_trans _ (le_mul_of_one_le_left _ _) <;> norm_num1
apply Real.rpow_le_rpow <;> norm_num1
apply rpow_nonneg_of_nonneg; norm_num1
apply rpow_pos_of_pos; norm_num1
apply hf' 18; norm_num1
norm_num1
Β· have : sqrt (2 * 512) = 32 :=
(sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonpos_iff (hf' _ _), this, div_le_one] <;> norm_num1
Β· conv in 512 => equals 2 ^ 9 => norm_num1
conv in 1024 => | equals 2 ^ 10 => norm_num1 | /-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> norm_num1
apply le_trans _ (le_mul_of_one_le_left _ _) <;> norm_num1
apply Real.rpow_le_rpow <;> norm_num1
apply rpow_nonneg_of_nonneg; norm_num1
apply rpow_pos_of_pos; norm_num1
apply hf' 18; norm_num1
norm_num1
Β· have : sqrt (2 * 512) = 32 :=
(sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonpos_iff (hf' _ _), this, div_le_one] <;> norm_num1
Β· conv in 512 => equals 2 ^ 9 => norm_num1
conv in 1024 => | Mathlib.NumberTheory.Bertrand.51_0.gJXoOT9Ce2wC0xc | /-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x | Mathlib_NumberTheory_Bertrand |
x : β
n_large : 512 β€ x
f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
hf' : β (x : β), 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)
hf : β (x : β), 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3))
h5 : 0 < x
h : ConcaveOn β (Set.Ioi 0.5) f
this : sqrt (2 * 512) = 32
β’ 1024 = 2 ^ 10 | /-
Copyright (c) 2020 Patrick Stevens. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Stevens, Bolton Bailey
-/
import Mathlib.Data.Nat.Choose.Factorization
import Mathlib.Data.Nat.PrimeNormNum
import Mathlib.NumberTheory.Primorial
import Mathlib.Analysis.Convex.SpecificFunctions.Basic
import Mathlib.Analysis.Convex.SpecificFunctions.Deriv
#align_import number_theory.bertrand from "leanprover-community/mathlib"@"a16665637b378379689c566204817ae792ac8b39"
/-!
# Bertrand's Postulate
This file contains a proof of Bertrand's postulate: That between any positive number and its
double there is a prime.
The proof follows the outline of the ErdΕs proof presented in "Proofs from THE BOOK": One considers
the prime factorization of `(2 * n).choose n`, and splits the constituent primes up into various
groups, then upper bounds the contribution of each group. This upper bounds the central binomial
coefficient, and if the postulate does not hold, this upper bound conflicts with a simple lower
bound for large enough `n`. This proves the result holds for large enough `n`, and for smaller `n`
an explicit list of primes is provided which covers the remaining cases.
As in the [Metamath implementation](carneiro2015arithmetic), we rely on some optimizations from
[Shigenori Tochiori](tochiori_bertrand). In particular we use the cleaner bound on the central
binomial coefficient given in `Nat.four_pow_lt_mul_centralBinom`.
## References
* [M. Aigner and G. M. Ziegler _Proofs from THE BOOK_][aigner1999proofs]
* [S. Tochiori, _Considering the Proof of βThere is a Prime between n and 2nβ_][tochiori_bertrand]
* [M. Carneiro, _Arithmetic in Metamath, Case Study: Bertrand's Postulate_][carneiro2015arithmetic]
## Tags
Bertrand, prime, binomial coefficients
-/
open scoped BigOperators
section Real
open Real
namespace Bertrand
/-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> norm_num1
apply le_trans _ (le_mul_of_one_le_left _ _) <;> norm_num1
apply Real.rpow_le_rpow <;> norm_num1
apply rpow_nonneg_of_nonneg; norm_num1
apply rpow_pos_of_pos; norm_num1
apply hf' 18; norm_num1
norm_num1
Β· have : sqrt (2 * 512) = 32 :=
(sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonpos_iff (hf' _ _), this, div_le_one] <;> norm_num1
Β· conv in 512 => equals 2 ^ 9 => norm_num1
conv in 1024 => equals 2 ^ 10 => | norm_num1 | /-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> norm_num1
apply le_trans _ (le_mul_of_one_le_left _ _) <;> norm_num1
apply Real.rpow_le_rpow <;> norm_num1
apply rpow_nonneg_of_nonneg; norm_num1
apply rpow_pos_of_pos; norm_num1
apply hf' 18; norm_num1
norm_num1
Β· have : sqrt (2 * 512) = 32 :=
(sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonpos_iff (hf' _ _), this, div_le_one] <;> norm_num1
Β· conv in 512 => equals 2 ^ 9 => norm_num1
conv in 1024 => equals 2 ^ 10 => | Mathlib.NumberTheory.Bertrand.51_0.gJXoOT9Ce2wC0xc | /-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x | Mathlib_NumberTheory_Bertrand |
case refine'_2
x : β
n_large : 512 β€ x
f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
hf' : β (x : β), 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)
hf : β (x : β), 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3))
h5 : 0 < x
h : ConcaveOn β (Set.Ioi 0.5) f
this : sqrt (2 * 512) = 32
β’ 2 ^ 9 * (2 ^ 10) ^ 32 β€ 4 ^ (512 / 3) | /-
Copyright (c) 2020 Patrick Stevens. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Stevens, Bolton Bailey
-/
import Mathlib.Data.Nat.Choose.Factorization
import Mathlib.Data.Nat.PrimeNormNum
import Mathlib.NumberTheory.Primorial
import Mathlib.Analysis.Convex.SpecificFunctions.Basic
import Mathlib.Analysis.Convex.SpecificFunctions.Deriv
#align_import number_theory.bertrand from "leanprover-community/mathlib"@"a16665637b378379689c566204817ae792ac8b39"
/-!
# Bertrand's Postulate
This file contains a proof of Bertrand's postulate: That between any positive number and its
double there is a prime.
The proof follows the outline of the ErdΕs proof presented in "Proofs from THE BOOK": One considers
the prime factorization of `(2 * n).choose n`, and splits the constituent primes up into various
groups, then upper bounds the contribution of each group. This upper bounds the central binomial
coefficient, and if the postulate does not hold, this upper bound conflicts with a simple lower
bound for large enough `n`. This proves the result holds for large enough `n`, and for smaller `n`
an explicit list of primes is provided which covers the remaining cases.
As in the [Metamath implementation](carneiro2015arithmetic), we rely on some optimizations from
[Shigenori Tochiori](tochiori_bertrand). In particular we use the cleaner bound on the central
binomial coefficient given in `Nat.four_pow_lt_mul_centralBinom`.
## References
* [M. Aigner and G. M. Ziegler _Proofs from THE BOOK_][aigner1999proofs]
* [S. Tochiori, _Considering the Proof of βThere is a Prime between n and 2nβ_][tochiori_bertrand]
* [M. Carneiro, _Arithmetic in Metamath, Case Study: Bertrand's Postulate_][carneiro2015arithmetic]
## Tags
Bertrand, prime, binomial coefficients
-/
open scoped BigOperators
section Real
open Real
namespace Bertrand
/-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> norm_num1
apply le_trans _ (le_mul_of_one_le_left _ _) <;> norm_num1
apply Real.rpow_le_rpow <;> norm_num1
apply rpow_nonneg_of_nonneg; norm_num1
apply rpow_pos_of_pos; norm_num1
apply hf' 18; norm_num1
norm_num1
Β· have : sqrt (2 * 512) = 32 :=
(sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonpos_iff (hf' _ _), this, div_le_one] <;> norm_num1
Β· conv in 512 => equals 2 ^ 9 => norm_num1
conv in 1024 => equals 2 ^ 10 => norm_num1
| conv in 32 => rw [β Nat.cast_ofNat] | /-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> norm_num1
apply le_trans _ (le_mul_of_one_le_left _ _) <;> norm_num1
apply Real.rpow_le_rpow <;> norm_num1
apply rpow_nonneg_of_nonneg; norm_num1
apply rpow_pos_of_pos; norm_num1
apply hf' 18; norm_num1
norm_num1
Β· have : sqrt (2 * 512) = 32 :=
(sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonpos_iff (hf' _ _), this, div_le_one] <;> norm_num1
Β· conv in 512 => equals 2 ^ 9 => norm_num1
conv in 1024 => equals 2 ^ 10 => norm_num1
| Mathlib.NumberTheory.Bertrand.51_0.gJXoOT9Ce2wC0xc | /-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x | Mathlib_NumberTheory_Bertrand |
x : β
n_large : 512 β€ x
f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
hf' : β (x : β), 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)
hf : β (x : β), 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3))
h5 : 0 < x
h : ConcaveOn β (Set.Ioi 0.5) f
this : sqrt (2 * 512) = 32
| 32 | /-
Copyright (c) 2020 Patrick Stevens. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Stevens, Bolton Bailey
-/
import Mathlib.Data.Nat.Choose.Factorization
import Mathlib.Data.Nat.PrimeNormNum
import Mathlib.NumberTheory.Primorial
import Mathlib.Analysis.Convex.SpecificFunctions.Basic
import Mathlib.Analysis.Convex.SpecificFunctions.Deriv
#align_import number_theory.bertrand from "leanprover-community/mathlib"@"a16665637b378379689c566204817ae792ac8b39"
/-!
# Bertrand's Postulate
This file contains a proof of Bertrand's postulate: That between any positive number and its
double there is a prime.
The proof follows the outline of the ErdΕs proof presented in "Proofs from THE BOOK": One considers
the prime factorization of `(2 * n).choose n`, and splits the constituent primes up into various
groups, then upper bounds the contribution of each group. This upper bounds the central binomial
coefficient, and if the postulate does not hold, this upper bound conflicts with a simple lower
bound for large enough `n`. This proves the result holds for large enough `n`, and for smaller `n`
an explicit list of primes is provided which covers the remaining cases.
As in the [Metamath implementation](carneiro2015arithmetic), we rely on some optimizations from
[Shigenori Tochiori](tochiori_bertrand). In particular we use the cleaner bound on the central
binomial coefficient given in `Nat.four_pow_lt_mul_centralBinom`.
## References
* [M. Aigner and G. M. Ziegler _Proofs from THE BOOK_][aigner1999proofs]
* [S. Tochiori, _Considering the Proof of βThere is a Prime between n and 2nβ_][tochiori_bertrand]
* [M. Carneiro, _Arithmetic in Metamath, Case Study: Bertrand's Postulate_][carneiro2015arithmetic]
## Tags
Bertrand, prime, binomial coefficients
-/
open scoped BigOperators
section Real
open Real
namespace Bertrand
/-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> norm_num1
apply le_trans _ (le_mul_of_one_le_left _ _) <;> norm_num1
apply Real.rpow_le_rpow <;> norm_num1
apply rpow_nonneg_of_nonneg; norm_num1
apply rpow_pos_of_pos; norm_num1
apply hf' 18; norm_num1
norm_num1
Β· have : sqrt (2 * 512) = 32 :=
(sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonpos_iff (hf' _ _), this, div_le_one] <;> norm_num1
Β· conv in 512 => equals 2 ^ 9 => norm_num1
conv in 1024 => equals 2 ^ 10 => norm_num1
conv in 32 => | rw [β Nat.cast_ofNat] | /-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> norm_num1
apply le_trans _ (le_mul_of_one_le_left _ _) <;> norm_num1
apply Real.rpow_le_rpow <;> norm_num1
apply rpow_nonneg_of_nonneg; norm_num1
apply rpow_pos_of_pos; norm_num1
apply hf' 18; norm_num1
norm_num1
Β· have : sqrt (2 * 512) = 32 :=
(sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonpos_iff (hf' _ _), this, div_le_one] <;> norm_num1
Β· conv in 512 => equals 2 ^ 9 => norm_num1
conv in 1024 => equals 2 ^ 10 => norm_num1
conv in 32 => | Mathlib.NumberTheory.Bertrand.51_0.gJXoOT9Ce2wC0xc | /-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x | Mathlib_NumberTheory_Bertrand |
x : β
n_large : 512 β€ x
f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
hf' : β (x : β), 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)
hf : β (x : β), 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3))
h5 : 0 < x
h : ConcaveOn β (Set.Ioi 0.5) f
this : sqrt (2 * 512) = 32
| 32 | /-
Copyright (c) 2020 Patrick Stevens. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Stevens, Bolton Bailey
-/
import Mathlib.Data.Nat.Choose.Factorization
import Mathlib.Data.Nat.PrimeNormNum
import Mathlib.NumberTheory.Primorial
import Mathlib.Analysis.Convex.SpecificFunctions.Basic
import Mathlib.Analysis.Convex.SpecificFunctions.Deriv
#align_import number_theory.bertrand from "leanprover-community/mathlib"@"a16665637b378379689c566204817ae792ac8b39"
/-!
# Bertrand's Postulate
This file contains a proof of Bertrand's postulate: That between any positive number and its
double there is a prime.
The proof follows the outline of the ErdΕs proof presented in "Proofs from THE BOOK": One considers
the prime factorization of `(2 * n).choose n`, and splits the constituent primes up into various
groups, then upper bounds the contribution of each group. This upper bounds the central binomial
coefficient, and if the postulate does not hold, this upper bound conflicts with a simple lower
bound for large enough `n`. This proves the result holds for large enough `n`, and for smaller `n`
an explicit list of primes is provided which covers the remaining cases.
As in the [Metamath implementation](carneiro2015arithmetic), we rely on some optimizations from
[Shigenori Tochiori](tochiori_bertrand). In particular we use the cleaner bound on the central
binomial coefficient given in `Nat.four_pow_lt_mul_centralBinom`.
## References
* [M. Aigner and G. M. Ziegler _Proofs from THE BOOK_][aigner1999proofs]
* [S. Tochiori, _Considering the Proof of βThere is a Prime between n and 2nβ_][tochiori_bertrand]
* [M. Carneiro, _Arithmetic in Metamath, Case Study: Bertrand's Postulate_][carneiro2015arithmetic]
## Tags
Bertrand, prime, binomial coefficients
-/
open scoped BigOperators
section Real
open Real
namespace Bertrand
/-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> norm_num1
apply le_trans _ (le_mul_of_one_le_left _ _) <;> norm_num1
apply Real.rpow_le_rpow <;> norm_num1
apply rpow_nonneg_of_nonneg; norm_num1
apply rpow_pos_of_pos; norm_num1
apply hf' 18; norm_num1
norm_num1
Β· have : sqrt (2 * 512) = 32 :=
(sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonpos_iff (hf' _ _), this, div_le_one] <;> norm_num1
Β· conv in 512 => equals 2 ^ 9 => norm_num1
conv in 1024 => equals 2 ^ 10 => norm_num1
conv in 32 => | rw [β Nat.cast_ofNat] | /-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> norm_num1
apply le_trans _ (le_mul_of_one_le_left _ _) <;> norm_num1
apply Real.rpow_le_rpow <;> norm_num1
apply rpow_nonneg_of_nonneg; norm_num1
apply rpow_pos_of_pos; norm_num1
apply hf' 18; norm_num1
norm_num1
Β· have : sqrt (2 * 512) = 32 :=
(sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonpos_iff (hf' _ _), this, div_le_one] <;> norm_num1
Β· conv in 512 => equals 2 ^ 9 => norm_num1
conv in 1024 => equals 2 ^ 10 => norm_num1
conv in 32 => | Mathlib.NumberTheory.Bertrand.51_0.gJXoOT9Ce2wC0xc | /-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x | Mathlib_NumberTheory_Bertrand |
x : β
n_large : 512 β€ x
f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
hf' : β (x : β), 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)
hf : β (x : β), 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3))
h5 : 0 < x
h : ConcaveOn β (Set.Ioi 0.5) f
this : sqrt (2 * 512) = 32
| 32 | /-
Copyright (c) 2020 Patrick Stevens. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Stevens, Bolton Bailey
-/
import Mathlib.Data.Nat.Choose.Factorization
import Mathlib.Data.Nat.PrimeNormNum
import Mathlib.NumberTheory.Primorial
import Mathlib.Analysis.Convex.SpecificFunctions.Basic
import Mathlib.Analysis.Convex.SpecificFunctions.Deriv
#align_import number_theory.bertrand from "leanprover-community/mathlib"@"a16665637b378379689c566204817ae792ac8b39"
/-!
# Bertrand's Postulate
This file contains a proof of Bertrand's postulate: That between any positive number and its
double there is a prime.
The proof follows the outline of the ErdΕs proof presented in "Proofs from THE BOOK": One considers
the prime factorization of `(2 * n).choose n`, and splits the constituent primes up into various
groups, then upper bounds the contribution of each group. This upper bounds the central binomial
coefficient, and if the postulate does not hold, this upper bound conflicts with a simple lower
bound for large enough `n`. This proves the result holds for large enough `n`, and for smaller `n`
an explicit list of primes is provided which covers the remaining cases.
As in the [Metamath implementation](carneiro2015arithmetic), we rely on some optimizations from
[Shigenori Tochiori](tochiori_bertrand). In particular we use the cleaner bound on the central
binomial coefficient given in `Nat.four_pow_lt_mul_centralBinom`.
## References
* [M. Aigner and G. M. Ziegler _Proofs from THE BOOK_][aigner1999proofs]
* [S. Tochiori, _Considering the Proof of βThere is a Prime between n and 2nβ_][tochiori_bertrand]
* [M. Carneiro, _Arithmetic in Metamath, Case Study: Bertrand's Postulate_][carneiro2015arithmetic]
## Tags
Bertrand, prime, binomial coefficients
-/
open scoped BigOperators
section Real
open Real
namespace Bertrand
/-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> norm_num1
apply le_trans _ (le_mul_of_one_le_left _ _) <;> norm_num1
apply Real.rpow_le_rpow <;> norm_num1
apply rpow_nonneg_of_nonneg; norm_num1
apply rpow_pos_of_pos; norm_num1
apply hf' 18; norm_num1
norm_num1
Β· have : sqrt (2 * 512) = 32 :=
(sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonpos_iff (hf' _ _), this, div_le_one] <;> norm_num1
Β· conv in 512 => equals 2 ^ 9 => norm_num1
conv in 1024 => equals 2 ^ 10 => norm_num1
conv in 32 => | rw [β Nat.cast_ofNat] | /-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> norm_num1
apply le_trans _ (le_mul_of_one_le_left _ _) <;> norm_num1
apply Real.rpow_le_rpow <;> norm_num1
apply rpow_nonneg_of_nonneg; norm_num1
apply rpow_pos_of_pos; norm_num1
apply hf' 18; norm_num1
norm_num1
Β· have : sqrt (2 * 512) = 32 :=
(sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonpos_iff (hf' _ _), this, div_le_one] <;> norm_num1
Β· conv in 512 => equals 2 ^ 9 => norm_num1
conv in 1024 => equals 2 ^ 10 => norm_num1
conv in 32 => | Mathlib.NumberTheory.Bertrand.51_0.gJXoOT9Ce2wC0xc | /-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x | Mathlib_NumberTheory_Bertrand |
case refine'_2
x : β
n_large : 512 β€ x
f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
hf' : β (x : β), 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)
hf : β (x : β), 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3))
h5 : 0 < x
h : ConcaveOn β (Set.Ioi 0.5) f
this : sqrt (2 * 512) = 32
β’ 2 ^ 9 * (2 ^ 10) ^ β32 β€ 4 ^ (512 / 3) | /-
Copyright (c) 2020 Patrick Stevens. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Stevens, Bolton Bailey
-/
import Mathlib.Data.Nat.Choose.Factorization
import Mathlib.Data.Nat.PrimeNormNum
import Mathlib.NumberTheory.Primorial
import Mathlib.Analysis.Convex.SpecificFunctions.Basic
import Mathlib.Analysis.Convex.SpecificFunctions.Deriv
#align_import number_theory.bertrand from "leanprover-community/mathlib"@"a16665637b378379689c566204817ae792ac8b39"
/-!
# Bertrand's Postulate
This file contains a proof of Bertrand's postulate: That between any positive number and its
double there is a prime.
The proof follows the outline of the ErdΕs proof presented in "Proofs from THE BOOK": One considers
the prime factorization of `(2 * n).choose n`, and splits the constituent primes up into various
groups, then upper bounds the contribution of each group. This upper bounds the central binomial
coefficient, and if the postulate does not hold, this upper bound conflicts with a simple lower
bound for large enough `n`. This proves the result holds for large enough `n`, and for smaller `n`
an explicit list of primes is provided which covers the remaining cases.
As in the [Metamath implementation](carneiro2015arithmetic), we rely on some optimizations from
[Shigenori Tochiori](tochiori_bertrand). In particular we use the cleaner bound on the central
binomial coefficient given in `Nat.four_pow_lt_mul_centralBinom`.
## References
* [M. Aigner and G. M. Ziegler _Proofs from THE BOOK_][aigner1999proofs]
* [S. Tochiori, _Considering the Proof of βThere is a Prime between n and 2nβ_][tochiori_bertrand]
* [M. Carneiro, _Arithmetic in Metamath, Case Study: Bertrand's Postulate_][carneiro2015arithmetic]
## Tags
Bertrand, prime, binomial coefficients
-/
open scoped BigOperators
section Real
open Real
namespace Bertrand
/-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> norm_num1
apply le_trans _ (le_mul_of_one_le_left _ _) <;> norm_num1
apply Real.rpow_le_rpow <;> norm_num1
apply rpow_nonneg_of_nonneg; norm_num1
apply rpow_pos_of_pos; norm_num1
apply hf' 18; norm_num1
norm_num1
Β· have : sqrt (2 * 512) = 32 :=
(sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonpos_iff (hf' _ _), this, div_le_one] <;> norm_num1
Β· conv in 512 => equals 2 ^ 9 => norm_num1
conv in 1024 => equals 2 ^ 10 => norm_num1
conv in 32 => rw [β Nat.cast_ofNat]
| rw [rpow_nat_cast, β pow_mul, β pow_add] | /-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> norm_num1
apply le_trans _ (le_mul_of_one_le_left _ _) <;> norm_num1
apply Real.rpow_le_rpow <;> norm_num1
apply rpow_nonneg_of_nonneg; norm_num1
apply rpow_pos_of_pos; norm_num1
apply hf' 18; norm_num1
norm_num1
Β· have : sqrt (2 * 512) = 32 :=
(sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonpos_iff (hf' _ _), this, div_le_one] <;> norm_num1
Β· conv in 512 => equals 2 ^ 9 => norm_num1
conv in 1024 => equals 2 ^ 10 => norm_num1
conv in 32 => rw [β Nat.cast_ofNat]
| Mathlib.NumberTheory.Bertrand.51_0.gJXoOT9Ce2wC0xc | /-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x | Mathlib_NumberTheory_Bertrand |
case refine'_2
x : β
n_large : 512 β€ x
f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
hf' : β (x : β), 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)
hf : β (x : β), 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3))
h5 : 0 < x
h : ConcaveOn β (Set.Ioi 0.5) f
this : sqrt (2 * 512) = 32
β’ 2 ^ (9 + 10 * 32) β€ 4 ^ (512 / 3) | /-
Copyright (c) 2020 Patrick Stevens. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Stevens, Bolton Bailey
-/
import Mathlib.Data.Nat.Choose.Factorization
import Mathlib.Data.Nat.PrimeNormNum
import Mathlib.NumberTheory.Primorial
import Mathlib.Analysis.Convex.SpecificFunctions.Basic
import Mathlib.Analysis.Convex.SpecificFunctions.Deriv
#align_import number_theory.bertrand from "leanprover-community/mathlib"@"a16665637b378379689c566204817ae792ac8b39"
/-!
# Bertrand's Postulate
This file contains a proof of Bertrand's postulate: That between any positive number and its
double there is a prime.
The proof follows the outline of the ErdΕs proof presented in "Proofs from THE BOOK": One considers
the prime factorization of `(2 * n).choose n`, and splits the constituent primes up into various
groups, then upper bounds the contribution of each group. This upper bounds the central binomial
coefficient, and if the postulate does not hold, this upper bound conflicts with a simple lower
bound for large enough `n`. This proves the result holds for large enough `n`, and for smaller `n`
an explicit list of primes is provided which covers the remaining cases.
As in the [Metamath implementation](carneiro2015arithmetic), we rely on some optimizations from
[Shigenori Tochiori](tochiori_bertrand). In particular we use the cleaner bound on the central
binomial coefficient given in `Nat.four_pow_lt_mul_centralBinom`.
## References
* [M. Aigner and G. M. Ziegler _Proofs from THE BOOK_][aigner1999proofs]
* [S. Tochiori, _Considering the Proof of βThere is a Prime between n and 2nβ_][tochiori_bertrand]
* [M. Carneiro, _Arithmetic in Metamath, Case Study: Bertrand's Postulate_][carneiro2015arithmetic]
## Tags
Bertrand, prime, binomial coefficients
-/
open scoped BigOperators
section Real
open Real
namespace Bertrand
/-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> norm_num1
apply le_trans _ (le_mul_of_one_le_left _ _) <;> norm_num1
apply Real.rpow_le_rpow <;> norm_num1
apply rpow_nonneg_of_nonneg; norm_num1
apply rpow_pos_of_pos; norm_num1
apply hf' 18; norm_num1
norm_num1
Β· have : sqrt (2 * 512) = 32 :=
(sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonpos_iff (hf' _ _), this, div_le_one] <;> norm_num1
Β· conv in 512 => equals 2 ^ 9 => norm_num1
conv in 1024 => equals 2 ^ 10 => norm_num1
conv in 32 => rw [β Nat.cast_ofNat]
rw [rpow_nat_cast, β pow_mul, β pow_add]
| conv in 4 => equals 2 ^ (2 : β) => rw [rpow_two]; norm_num1 | /-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> norm_num1
apply le_trans _ (le_mul_of_one_le_left _ _) <;> norm_num1
apply Real.rpow_le_rpow <;> norm_num1
apply rpow_nonneg_of_nonneg; norm_num1
apply rpow_pos_of_pos; norm_num1
apply hf' 18; norm_num1
norm_num1
Β· have : sqrt (2 * 512) = 32 :=
(sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonpos_iff (hf' _ _), this, div_le_one] <;> norm_num1
Β· conv in 512 => equals 2 ^ 9 => norm_num1
conv in 1024 => equals 2 ^ 10 => norm_num1
conv in 32 => rw [β Nat.cast_ofNat]
rw [rpow_nat_cast, β pow_mul, β pow_add]
| Mathlib.NumberTheory.Bertrand.51_0.gJXoOT9Ce2wC0xc | /-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x | Mathlib_NumberTheory_Bertrand |
x : β
n_large : 512 β€ x
f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
hf' : β (x : β), 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)
hf : β (x : β), 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3))
h5 : 0 < x
h : ConcaveOn β (Set.Ioi 0.5) f
this : sqrt (2 * 512) = 32
| 4 | /-
Copyright (c) 2020 Patrick Stevens. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Stevens, Bolton Bailey
-/
import Mathlib.Data.Nat.Choose.Factorization
import Mathlib.Data.Nat.PrimeNormNum
import Mathlib.NumberTheory.Primorial
import Mathlib.Analysis.Convex.SpecificFunctions.Basic
import Mathlib.Analysis.Convex.SpecificFunctions.Deriv
#align_import number_theory.bertrand from "leanprover-community/mathlib"@"a16665637b378379689c566204817ae792ac8b39"
/-!
# Bertrand's Postulate
This file contains a proof of Bertrand's postulate: That between any positive number and its
double there is a prime.
The proof follows the outline of the ErdΕs proof presented in "Proofs from THE BOOK": One considers
the prime factorization of `(2 * n).choose n`, and splits the constituent primes up into various
groups, then upper bounds the contribution of each group. This upper bounds the central binomial
coefficient, and if the postulate does not hold, this upper bound conflicts with a simple lower
bound for large enough `n`. This proves the result holds for large enough `n`, and for smaller `n`
an explicit list of primes is provided which covers the remaining cases.
As in the [Metamath implementation](carneiro2015arithmetic), we rely on some optimizations from
[Shigenori Tochiori](tochiori_bertrand). In particular we use the cleaner bound on the central
binomial coefficient given in `Nat.four_pow_lt_mul_centralBinom`.
## References
* [M. Aigner and G. M. Ziegler _Proofs from THE BOOK_][aigner1999proofs]
* [S. Tochiori, _Considering the Proof of βThere is a Prime between n and 2nβ_][tochiori_bertrand]
* [M. Carneiro, _Arithmetic in Metamath, Case Study: Bertrand's Postulate_][carneiro2015arithmetic]
## Tags
Bertrand, prime, binomial coefficients
-/
open scoped BigOperators
section Real
open Real
namespace Bertrand
/-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> norm_num1
apply le_trans _ (le_mul_of_one_le_left _ _) <;> norm_num1
apply Real.rpow_le_rpow <;> norm_num1
apply rpow_nonneg_of_nonneg; norm_num1
apply rpow_pos_of_pos; norm_num1
apply hf' 18; norm_num1
norm_num1
Β· have : sqrt (2 * 512) = 32 :=
(sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonpos_iff (hf' _ _), this, div_le_one] <;> norm_num1
Β· conv in 512 => equals 2 ^ 9 => norm_num1
conv in 1024 => equals 2 ^ 10 => norm_num1
conv in 32 => rw [β Nat.cast_ofNat]
rw [rpow_nat_cast, β pow_mul, β pow_add]
conv in 4 => | equals 2 ^ (2 : β) => rw [rpow_two]; norm_num1 | /-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> norm_num1
apply le_trans _ (le_mul_of_one_le_left _ _) <;> norm_num1
apply Real.rpow_le_rpow <;> norm_num1
apply rpow_nonneg_of_nonneg; norm_num1
apply rpow_pos_of_pos; norm_num1
apply hf' 18; norm_num1
norm_num1
Β· have : sqrt (2 * 512) = 32 :=
(sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonpos_iff (hf' _ _), this, div_le_one] <;> norm_num1
Β· conv in 512 => equals 2 ^ 9 => norm_num1
conv in 1024 => equals 2 ^ 10 => norm_num1
conv in 32 => rw [β Nat.cast_ofNat]
rw [rpow_nat_cast, β pow_mul, β pow_add]
conv in 4 => | Mathlib.NumberTheory.Bertrand.51_0.gJXoOT9Ce2wC0xc | /-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x | Mathlib_NumberTheory_Bertrand |
x : β
n_large : 512 β€ x
f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
hf' : β (x : β), 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)
hf : β (x : β), 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3))
h5 : 0 < x
h : ConcaveOn β (Set.Ioi 0.5) f
this : sqrt (2 * 512) = 32
| 4 | /-
Copyright (c) 2020 Patrick Stevens. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Stevens, Bolton Bailey
-/
import Mathlib.Data.Nat.Choose.Factorization
import Mathlib.Data.Nat.PrimeNormNum
import Mathlib.NumberTheory.Primorial
import Mathlib.Analysis.Convex.SpecificFunctions.Basic
import Mathlib.Analysis.Convex.SpecificFunctions.Deriv
#align_import number_theory.bertrand from "leanprover-community/mathlib"@"a16665637b378379689c566204817ae792ac8b39"
/-!
# Bertrand's Postulate
This file contains a proof of Bertrand's postulate: That between any positive number and its
double there is a prime.
The proof follows the outline of the ErdΕs proof presented in "Proofs from THE BOOK": One considers
the prime factorization of `(2 * n).choose n`, and splits the constituent primes up into various
groups, then upper bounds the contribution of each group. This upper bounds the central binomial
coefficient, and if the postulate does not hold, this upper bound conflicts with a simple lower
bound for large enough `n`. This proves the result holds for large enough `n`, and for smaller `n`
an explicit list of primes is provided which covers the remaining cases.
As in the [Metamath implementation](carneiro2015arithmetic), we rely on some optimizations from
[Shigenori Tochiori](tochiori_bertrand). In particular we use the cleaner bound on the central
binomial coefficient given in `Nat.four_pow_lt_mul_centralBinom`.
## References
* [M. Aigner and G. M. Ziegler _Proofs from THE BOOK_][aigner1999proofs]
* [S. Tochiori, _Considering the Proof of βThere is a Prime between n and 2nβ_][tochiori_bertrand]
* [M. Carneiro, _Arithmetic in Metamath, Case Study: Bertrand's Postulate_][carneiro2015arithmetic]
## Tags
Bertrand, prime, binomial coefficients
-/
open scoped BigOperators
section Real
open Real
namespace Bertrand
/-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> norm_num1
apply le_trans _ (le_mul_of_one_le_left _ _) <;> norm_num1
apply Real.rpow_le_rpow <;> norm_num1
apply rpow_nonneg_of_nonneg; norm_num1
apply rpow_pos_of_pos; norm_num1
apply hf' 18; norm_num1
norm_num1
Β· have : sqrt (2 * 512) = 32 :=
(sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonpos_iff (hf' _ _), this, div_le_one] <;> norm_num1
Β· conv in 512 => equals 2 ^ 9 => norm_num1
conv in 1024 => equals 2 ^ 10 => norm_num1
conv in 32 => rw [β Nat.cast_ofNat]
rw [rpow_nat_cast, β pow_mul, β pow_add]
conv in 4 => | equals 2 ^ (2 : β) => rw [rpow_two]; norm_num1 | /-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> norm_num1
apply le_trans _ (le_mul_of_one_le_left _ _) <;> norm_num1
apply Real.rpow_le_rpow <;> norm_num1
apply rpow_nonneg_of_nonneg; norm_num1
apply rpow_pos_of_pos; norm_num1
apply hf' 18; norm_num1
norm_num1
Β· have : sqrt (2 * 512) = 32 :=
(sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonpos_iff (hf' _ _), this, div_le_one] <;> norm_num1
Β· conv in 512 => equals 2 ^ 9 => norm_num1
conv in 1024 => equals 2 ^ 10 => norm_num1
conv in 32 => rw [β Nat.cast_ofNat]
rw [rpow_nat_cast, β pow_mul, β pow_add]
conv in 4 => | Mathlib.NumberTheory.Bertrand.51_0.gJXoOT9Ce2wC0xc | /-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x | Mathlib_NumberTheory_Bertrand |
x : β
n_large : 512 β€ x
f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
hf' : β (x : β), 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)
hf : β (x : β), 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3))
h5 : 0 < x
h : ConcaveOn β (Set.Ioi 0.5) f
this : sqrt (2 * 512) = 32
| 4 | /-
Copyright (c) 2020 Patrick Stevens. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Stevens, Bolton Bailey
-/
import Mathlib.Data.Nat.Choose.Factorization
import Mathlib.Data.Nat.PrimeNormNum
import Mathlib.NumberTheory.Primorial
import Mathlib.Analysis.Convex.SpecificFunctions.Basic
import Mathlib.Analysis.Convex.SpecificFunctions.Deriv
#align_import number_theory.bertrand from "leanprover-community/mathlib"@"a16665637b378379689c566204817ae792ac8b39"
/-!
# Bertrand's Postulate
This file contains a proof of Bertrand's postulate: That between any positive number and its
double there is a prime.
The proof follows the outline of the ErdΕs proof presented in "Proofs from THE BOOK": One considers
the prime factorization of `(2 * n).choose n`, and splits the constituent primes up into various
groups, then upper bounds the contribution of each group. This upper bounds the central binomial
coefficient, and if the postulate does not hold, this upper bound conflicts with a simple lower
bound for large enough `n`. This proves the result holds for large enough `n`, and for smaller `n`
an explicit list of primes is provided which covers the remaining cases.
As in the [Metamath implementation](carneiro2015arithmetic), we rely on some optimizations from
[Shigenori Tochiori](tochiori_bertrand). In particular we use the cleaner bound on the central
binomial coefficient given in `Nat.four_pow_lt_mul_centralBinom`.
## References
* [M. Aigner and G. M. Ziegler _Proofs from THE BOOK_][aigner1999proofs]
* [S. Tochiori, _Considering the Proof of βThere is a Prime between n and 2nβ_][tochiori_bertrand]
* [M. Carneiro, _Arithmetic in Metamath, Case Study: Bertrand's Postulate_][carneiro2015arithmetic]
## Tags
Bertrand, prime, binomial coefficients
-/
open scoped BigOperators
section Real
open Real
namespace Bertrand
/-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> norm_num1
apply le_trans _ (le_mul_of_one_le_left _ _) <;> norm_num1
apply Real.rpow_le_rpow <;> norm_num1
apply rpow_nonneg_of_nonneg; norm_num1
apply rpow_pos_of_pos; norm_num1
apply hf' 18; norm_num1
norm_num1
Β· have : sqrt (2 * 512) = 32 :=
(sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonpos_iff (hf' _ _), this, div_le_one] <;> norm_num1
Β· conv in 512 => equals 2 ^ 9 => norm_num1
conv in 1024 => equals 2 ^ 10 => norm_num1
conv in 32 => rw [β Nat.cast_ofNat]
rw [rpow_nat_cast, β pow_mul, β pow_add]
conv in 4 => | equals 2 ^ (2 : β) => rw [rpow_two]; norm_num1 | /-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> norm_num1
apply le_trans _ (le_mul_of_one_le_left _ _) <;> norm_num1
apply Real.rpow_le_rpow <;> norm_num1
apply rpow_nonneg_of_nonneg; norm_num1
apply rpow_pos_of_pos; norm_num1
apply hf' 18; norm_num1
norm_num1
Β· have : sqrt (2 * 512) = 32 :=
(sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonpos_iff (hf' _ _), this, div_le_one] <;> norm_num1
Β· conv in 512 => equals 2 ^ 9 => norm_num1
conv in 1024 => equals 2 ^ 10 => norm_num1
conv in 32 => rw [β Nat.cast_ofNat]
rw [rpow_nat_cast, β pow_mul, β pow_add]
conv in 4 => | Mathlib.NumberTheory.Bertrand.51_0.gJXoOT9Ce2wC0xc | /-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x | Mathlib_NumberTheory_Bertrand |
x : β
n_large : 512 β€ x
f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
hf' : β (x : β), 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)
hf : β (x : β), 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3))
h5 : 0 < x
h : ConcaveOn β (Set.Ioi 0.5) f
this : sqrt (2 * 512) = 32
β’ 4 = 2 ^ 2 | /-
Copyright (c) 2020 Patrick Stevens. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Stevens, Bolton Bailey
-/
import Mathlib.Data.Nat.Choose.Factorization
import Mathlib.Data.Nat.PrimeNormNum
import Mathlib.NumberTheory.Primorial
import Mathlib.Analysis.Convex.SpecificFunctions.Basic
import Mathlib.Analysis.Convex.SpecificFunctions.Deriv
#align_import number_theory.bertrand from "leanprover-community/mathlib"@"a16665637b378379689c566204817ae792ac8b39"
/-!
# Bertrand's Postulate
This file contains a proof of Bertrand's postulate: That between any positive number and its
double there is a prime.
The proof follows the outline of the ErdΕs proof presented in "Proofs from THE BOOK": One considers
the prime factorization of `(2 * n).choose n`, and splits the constituent primes up into various
groups, then upper bounds the contribution of each group. This upper bounds the central binomial
coefficient, and if the postulate does not hold, this upper bound conflicts with a simple lower
bound for large enough `n`. This proves the result holds for large enough `n`, and for smaller `n`
an explicit list of primes is provided which covers the remaining cases.
As in the [Metamath implementation](carneiro2015arithmetic), we rely on some optimizations from
[Shigenori Tochiori](tochiori_bertrand). In particular we use the cleaner bound on the central
binomial coefficient given in `Nat.four_pow_lt_mul_centralBinom`.
## References
* [M. Aigner and G. M. Ziegler _Proofs from THE BOOK_][aigner1999proofs]
* [S. Tochiori, _Considering the Proof of βThere is a Prime between n and 2nβ_][tochiori_bertrand]
* [M. Carneiro, _Arithmetic in Metamath, Case Study: Bertrand's Postulate_][carneiro2015arithmetic]
## Tags
Bertrand, prime, binomial coefficients
-/
open scoped BigOperators
section Real
open Real
namespace Bertrand
/-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> norm_num1
apply le_trans _ (le_mul_of_one_le_left _ _) <;> norm_num1
apply Real.rpow_le_rpow <;> norm_num1
apply rpow_nonneg_of_nonneg; norm_num1
apply rpow_pos_of_pos; norm_num1
apply hf' 18; norm_num1
norm_num1
Β· have : sqrt (2 * 512) = 32 :=
(sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonpos_iff (hf' _ _), this, div_le_one] <;> norm_num1
Β· conv in 512 => equals 2 ^ 9 => norm_num1
conv in 1024 => equals 2 ^ 10 => norm_num1
conv in 32 => rw [β Nat.cast_ofNat]
rw [rpow_nat_cast, β pow_mul, β pow_add]
conv in 4 => equals 2 ^ (2 : β) => | rw [rpow_two] | /-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> norm_num1
apply le_trans _ (le_mul_of_one_le_left _ _) <;> norm_num1
apply Real.rpow_le_rpow <;> norm_num1
apply rpow_nonneg_of_nonneg; norm_num1
apply rpow_pos_of_pos; norm_num1
apply hf' 18; norm_num1
norm_num1
Β· have : sqrt (2 * 512) = 32 :=
(sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonpos_iff (hf' _ _), this, div_le_one] <;> norm_num1
Β· conv in 512 => equals 2 ^ 9 => norm_num1
conv in 1024 => equals 2 ^ 10 => norm_num1
conv in 32 => rw [β Nat.cast_ofNat]
rw [rpow_nat_cast, β pow_mul, β pow_add]
conv in 4 => equals 2 ^ (2 : β) => | Mathlib.NumberTheory.Bertrand.51_0.gJXoOT9Ce2wC0xc | /-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x | Mathlib_NumberTheory_Bertrand |
x : β
n_large : 512 β€ x
f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
hf' : β (x : β), 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)
hf : β (x : β), 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3))
h5 : 0 < x
h : ConcaveOn β (Set.Ioi 0.5) f
this : sqrt (2 * 512) = 32
β’ 4 = 2 ^ 2 | /-
Copyright (c) 2020 Patrick Stevens. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Stevens, Bolton Bailey
-/
import Mathlib.Data.Nat.Choose.Factorization
import Mathlib.Data.Nat.PrimeNormNum
import Mathlib.NumberTheory.Primorial
import Mathlib.Analysis.Convex.SpecificFunctions.Basic
import Mathlib.Analysis.Convex.SpecificFunctions.Deriv
#align_import number_theory.bertrand from "leanprover-community/mathlib"@"a16665637b378379689c566204817ae792ac8b39"
/-!
# Bertrand's Postulate
This file contains a proof of Bertrand's postulate: That between any positive number and its
double there is a prime.
The proof follows the outline of the ErdΕs proof presented in "Proofs from THE BOOK": One considers
the prime factorization of `(2 * n).choose n`, and splits the constituent primes up into various
groups, then upper bounds the contribution of each group. This upper bounds the central binomial
coefficient, and if the postulate does not hold, this upper bound conflicts with a simple lower
bound for large enough `n`. This proves the result holds for large enough `n`, and for smaller `n`
an explicit list of primes is provided which covers the remaining cases.
As in the [Metamath implementation](carneiro2015arithmetic), we rely on some optimizations from
[Shigenori Tochiori](tochiori_bertrand). In particular we use the cleaner bound on the central
binomial coefficient given in `Nat.four_pow_lt_mul_centralBinom`.
## References
* [M. Aigner and G. M. Ziegler _Proofs from THE BOOK_][aigner1999proofs]
* [S. Tochiori, _Considering the Proof of βThere is a Prime between n and 2nβ_][tochiori_bertrand]
* [M. Carneiro, _Arithmetic in Metamath, Case Study: Bertrand's Postulate_][carneiro2015arithmetic]
## Tags
Bertrand, prime, binomial coefficients
-/
open scoped BigOperators
section Real
open Real
namespace Bertrand
/-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> norm_num1
apply le_trans _ (le_mul_of_one_le_left _ _) <;> norm_num1
apply Real.rpow_le_rpow <;> norm_num1
apply rpow_nonneg_of_nonneg; norm_num1
apply rpow_pos_of_pos; norm_num1
apply hf' 18; norm_num1
norm_num1
Β· have : sqrt (2 * 512) = 32 :=
(sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonpos_iff (hf' _ _), this, div_le_one] <;> norm_num1
Β· conv in 512 => equals 2 ^ 9 => norm_num1
conv in 1024 => equals 2 ^ 10 => norm_num1
conv in 32 => rw [β Nat.cast_ofNat]
rw [rpow_nat_cast, β pow_mul, β pow_add]
conv in 4 => equals 2 ^ (2 : β) => rw [rpow_two]; | norm_num1 | /-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> norm_num1
apply le_trans _ (le_mul_of_one_le_left _ _) <;> norm_num1
apply Real.rpow_le_rpow <;> norm_num1
apply rpow_nonneg_of_nonneg; norm_num1
apply rpow_pos_of_pos; norm_num1
apply hf' 18; norm_num1
norm_num1
Β· have : sqrt (2 * 512) = 32 :=
(sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonpos_iff (hf' _ _), this, div_le_one] <;> norm_num1
Β· conv in 512 => equals 2 ^ 9 => norm_num1
conv in 1024 => equals 2 ^ 10 => norm_num1
conv in 32 => rw [β Nat.cast_ofNat]
rw [rpow_nat_cast, β pow_mul, β pow_add]
conv in 4 => equals 2 ^ (2 : β) => rw [rpow_two]; | Mathlib.NumberTheory.Bertrand.51_0.gJXoOT9Ce2wC0xc | /-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x | Mathlib_NumberTheory_Bertrand |
case refine'_2
x : β
n_large : 512 β€ x
f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
hf' : β (x : β), 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)
hf : β (x : β), 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3))
h5 : 0 < x
h : ConcaveOn β (Set.Ioi 0.5) f
this : sqrt (2 * 512) = 32
β’ 2 ^ (9 + 10 * 32) β€ (2 ^ 2) ^ (512 / 3) | /-
Copyright (c) 2020 Patrick Stevens. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Stevens, Bolton Bailey
-/
import Mathlib.Data.Nat.Choose.Factorization
import Mathlib.Data.Nat.PrimeNormNum
import Mathlib.NumberTheory.Primorial
import Mathlib.Analysis.Convex.SpecificFunctions.Basic
import Mathlib.Analysis.Convex.SpecificFunctions.Deriv
#align_import number_theory.bertrand from "leanprover-community/mathlib"@"a16665637b378379689c566204817ae792ac8b39"
/-!
# Bertrand's Postulate
This file contains a proof of Bertrand's postulate: That between any positive number and its
double there is a prime.
The proof follows the outline of the ErdΕs proof presented in "Proofs from THE BOOK": One considers
the prime factorization of `(2 * n).choose n`, and splits the constituent primes up into various
groups, then upper bounds the contribution of each group. This upper bounds the central binomial
coefficient, and if the postulate does not hold, this upper bound conflicts with a simple lower
bound for large enough `n`. This proves the result holds for large enough `n`, and for smaller `n`
an explicit list of primes is provided which covers the remaining cases.
As in the [Metamath implementation](carneiro2015arithmetic), we rely on some optimizations from
[Shigenori Tochiori](tochiori_bertrand). In particular we use the cleaner bound on the central
binomial coefficient given in `Nat.four_pow_lt_mul_centralBinom`.
## References
* [M. Aigner and G. M. Ziegler _Proofs from THE BOOK_][aigner1999proofs]
* [S. Tochiori, _Considering the Proof of βThere is a Prime between n and 2nβ_][tochiori_bertrand]
* [M. Carneiro, _Arithmetic in Metamath, Case Study: Bertrand's Postulate_][carneiro2015arithmetic]
## Tags
Bertrand, prime, binomial coefficients
-/
open scoped BigOperators
section Real
open Real
namespace Bertrand
/-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> norm_num1
apply le_trans _ (le_mul_of_one_le_left _ _) <;> norm_num1
apply Real.rpow_le_rpow <;> norm_num1
apply rpow_nonneg_of_nonneg; norm_num1
apply rpow_pos_of_pos; norm_num1
apply hf' 18; norm_num1
norm_num1
Β· have : sqrt (2 * 512) = 32 :=
(sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonpos_iff (hf' _ _), this, div_le_one] <;> norm_num1
Β· conv in 512 => equals 2 ^ 9 => norm_num1
conv in 1024 => equals 2 ^ 10 => norm_num1
conv in 32 => rw [β Nat.cast_ofNat]
rw [rpow_nat_cast, β pow_mul, β pow_add]
conv in 4 => equals 2 ^ (2 : β) => rw [rpow_two]; norm_num1
| rw [β rpow_mul, β rpow_nat_cast] | /-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> norm_num1
apply le_trans _ (le_mul_of_one_le_left _ _) <;> norm_num1
apply Real.rpow_le_rpow <;> norm_num1
apply rpow_nonneg_of_nonneg; norm_num1
apply rpow_pos_of_pos; norm_num1
apply hf' 18; norm_num1
norm_num1
Β· have : sqrt (2 * 512) = 32 :=
(sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonpos_iff (hf' _ _), this, div_le_one] <;> norm_num1
Β· conv in 512 => equals 2 ^ 9 => norm_num1
conv in 1024 => equals 2 ^ 10 => norm_num1
conv in 32 => rw [β Nat.cast_ofNat]
rw [rpow_nat_cast, β pow_mul, β pow_add]
conv in 4 => equals 2 ^ (2 : β) => rw [rpow_two]; norm_num1
| Mathlib.NumberTheory.Bertrand.51_0.gJXoOT9Ce2wC0xc | /-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x | Mathlib_NumberTheory_Bertrand |
case refine'_2
x : β
n_large : 512 β€ x
f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
hf' : β (x : β), 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)
hf : β (x : β), 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3))
h5 : 0 < x
h : ConcaveOn β (Set.Ioi 0.5) f
this : sqrt (2 * 512) = 32
β’ 2 ^ β(9 + 10 * 32) β€ 2 ^ (2 * (512 / 3))
case refine'_2.hx
x : β
n_large : 512 β€ x
f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
hf' : β (x : β), 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)
hf : β (x : β), 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3))
h5 : 0 < x
h : ConcaveOn β (Set.Ioi 0.5) f
this : sqrt (2 * 512) = 32
β’ 0 β€ 2 | /-
Copyright (c) 2020 Patrick Stevens. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Stevens, Bolton Bailey
-/
import Mathlib.Data.Nat.Choose.Factorization
import Mathlib.Data.Nat.PrimeNormNum
import Mathlib.NumberTheory.Primorial
import Mathlib.Analysis.Convex.SpecificFunctions.Basic
import Mathlib.Analysis.Convex.SpecificFunctions.Deriv
#align_import number_theory.bertrand from "leanprover-community/mathlib"@"a16665637b378379689c566204817ae792ac8b39"
/-!
# Bertrand's Postulate
This file contains a proof of Bertrand's postulate: That between any positive number and its
double there is a prime.
The proof follows the outline of the ErdΕs proof presented in "Proofs from THE BOOK": One considers
the prime factorization of `(2 * n).choose n`, and splits the constituent primes up into various
groups, then upper bounds the contribution of each group. This upper bounds the central binomial
coefficient, and if the postulate does not hold, this upper bound conflicts with a simple lower
bound for large enough `n`. This proves the result holds for large enough `n`, and for smaller `n`
an explicit list of primes is provided which covers the remaining cases.
As in the [Metamath implementation](carneiro2015arithmetic), we rely on some optimizations from
[Shigenori Tochiori](tochiori_bertrand). In particular we use the cleaner bound on the central
binomial coefficient given in `Nat.four_pow_lt_mul_centralBinom`.
## References
* [M. Aigner and G. M. Ziegler _Proofs from THE BOOK_][aigner1999proofs]
* [S. Tochiori, _Considering the Proof of βThere is a Prime between n and 2nβ_][tochiori_bertrand]
* [M. Carneiro, _Arithmetic in Metamath, Case Study: Bertrand's Postulate_][carneiro2015arithmetic]
## Tags
Bertrand, prime, binomial coefficients
-/
open scoped BigOperators
section Real
open Real
namespace Bertrand
/-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> norm_num1
apply le_trans _ (le_mul_of_one_le_left _ _) <;> norm_num1
apply Real.rpow_le_rpow <;> norm_num1
apply rpow_nonneg_of_nonneg; norm_num1
apply rpow_pos_of_pos; norm_num1
apply hf' 18; norm_num1
norm_num1
Β· have : sqrt (2 * 512) = 32 :=
(sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonpos_iff (hf' _ _), this, div_le_one] <;> norm_num1
Β· conv in 512 => equals 2 ^ 9 => norm_num1
conv in 1024 => equals 2 ^ 10 => norm_num1
conv in 32 => rw [β Nat.cast_ofNat]
rw [rpow_nat_cast, β pow_mul, β pow_add]
conv in 4 => equals 2 ^ (2 : β) => rw [rpow_two]; norm_num1
rw [β rpow_mul, β rpow_nat_cast]
| apply rpow_le_rpow_of_exponent_le | /-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> norm_num1
apply le_trans _ (le_mul_of_one_le_left _ _) <;> norm_num1
apply Real.rpow_le_rpow <;> norm_num1
apply rpow_nonneg_of_nonneg; norm_num1
apply rpow_pos_of_pos; norm_num1
apply hf' 18; norm_num1
norm_num1
Β· have : sqrt (2 * 512) = 32 :=
(sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonpos_iff (hf' _ _), this, div_le_one] <;> norm_num1
Β· conv in 512 => equals 2 ^ 9 => norm_num1
conv in 1024 => equals 2 ^ 10 => norm_num1
conv in 32 => rw [β Nat.cast_ofNat]
rw [rpow_nat_cast, β pow_mul, β pow_add]
conv in 4 => equals 2 ^ (2 : β) => rw [rpow_two]; norm_num1
rw [β rpow_mul, β rpow_nat_cast]
| Mathlib.NumberTheory.Bertrand.51_0.gJXoOT9Ce2wC0xc | /-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x | Mathlib_NumberTheory_Bertrand |
case refine'_2.hx
x : β
n_large : 512 β€ x
f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
hf' : β (x : β), 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)
hf : β (x : β), 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3))
h5 : 0 < x
h : ConcaveOn β (Set.Ioi 0.5) f
this : sqrt (2 * 512) = 32
β’ 1 β€ 2
case refine'_2.hyz
x : β
n_large : 512 β€ x
f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
hf' : β (x : β), 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)
hf : β (x : β), 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3))
h5 : 0 < x
h : ConcaveOn β (Set.Ioi 0.5) f
this : sqrt (2 * 512) = 32
β’ β(9 + 10 * 32) β€ 2 * (512 / 3)
case refine'_2.hx
x : β
n_large : 512 β€ x
f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
hf' : β (x : β), 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)
hf : β (x : β), 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3))
h5 : 0 < x
h : ConcaveOn β (Set.Ioi 0.5) f
this : sqrt (2 * 512) = 32
β’ 0 β€ 2 | /-
Copyright (c) 2020 Patrick Stevens. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Stevens, Bolton Bailey
-/
import Mathlib.Data.Nat.Choose.Factorization
import Mathlib.Data.Nat.PrimeNormNum
import Mathlib.NumberTheory.Primorial
import Mathlib.Analysis.Convex.SpecificFunctions.Basic
import Mathlib.Analysis.Convex.SpecificFunctions.Deriv
#align_import number_theory.bertrand from "leanprover-community/mathlib"@"a16665637b378379689c566204817ae792ac8b39"
/-!
# Bertrand's Postulate
This file contains a proof of Bertrand's postulate: That between any positive number and its
double there is a prime.
The proof follows the outline of the ErdΕs proof presented in "Proofs from THE BOOK": One considers
the prime factorization of `(2 * n).choose n`, and splits the constituent primes up into various
groups, then upper bounds the contribution of each group. This upper bounds the central binomial
coefficient, and if the postulate does not hold, this upper bound conflicts with a simple lower
bound for large enough `n`. This proves the result holds for large enough `n`, and for smaller `n`
an explicit list of primes is provided which covers the remaining cases.
As in the [Metamath implementation](carneiro2015arithmetic), we rely on some optimizations from
[Shigenori Tochiori](tochiori_bertrand). In particular we use the cleaner bound on the central
binomial coefficient given in `Nat.four_pow_lt_mul_centralBinom`.
## References
* [M. Aigner and G. M. Ziegler _Proofs from THE BOOK_][aigner1999proofs]
* [S. Tochiori, _Considering the Proof of βThere is a Prime between n and 2nβ_][tochiori_bertrand]
* [M. Carneiro, _Arithmetic in Metamath, Case Study: Bertrand's Postulate_][carneiro2015arithmetic]
## Tags
Bertrand, prime, binomial coefficients
-/
open scoped BigOperators
section Real
open Real
namespace Bertrand
/-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> norm_num1
apply le_trans _ (le_mul_of_one_le_left _ _) <;> norm_num1
apply Real.rpow_le_rpow <;> norm_num1
apply rpow_nonneg_of_nonneg; norm_num1
apply rpow_pos_of_pos; norm_num1
apply hf' 18; norm_num1
norm_num1
Β· have : sqrt (2 * 512) = 32 :=
(sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonpos_iff (hf' _ _), this, div_le_one] <;> norm_num1
Β· conv in 512 => equals 2 ^ 9 => norm_num1
conv in 1024 => equals 2 ^ 10 => norm_num1
conv in 32 => rw [β Nat.cast_ofNat]
rw [rpow_nat_cast, β pow_mul, β pow_add]
conv in 4 => equals 2 ^ (2 : β) => rw [rpow_two]; norm_num1
rw [β rpow_mul, β rpow_nat_cast]
apply rpow_le_rpow_of_exponent_le
| all_goals norm_num1 | /-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> norm_num1
apply le_trans _ (le_mul_of_one_le_left _ _) <;> norm_num1
apply Real.rpow_le_rpow <;> norm_num1
apply rpow_nonneg_of_nonneg; norm_num1
apply rpow_pos_of_pos; norm_num1
apply hf' 18; norm_num1
norm_num1
Β· have : sqrt (2 * 512) = 32 :=
(sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonpos_iff (hf' _ _), this, div_le_one] <;> norm_num1
Β· conv in 512 => equals 2 ^ 9 => norm_num1
conv in 1024 => equals 2 ^ 10 => norm_num1
conv in 32 => rw [β Nat.cast_ofNat]
rw [rpow_nat_cast, β pow_mul, β pow_add]
conv in 4 => equals 2 ^ (2 : β) => rw [rpow_two]; norm_num1
rw [β rpow_mul, β rpow_nat_cast]
apply rpow_le_rpow_of_exponent_le
| Mathlib.NumberTheory.Bertrand.51_0.gJXoOT9Ce2wC0xc | /-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x | Mathlib_NumberTheory_Bertrand |
case refine'_2.hx
x : β
n_large : 512 β€ x
f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
hf' : β (x : β), 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)
hf : β (x : β), 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3))
h5 : 0 < x
h : ConcaveOn β (Set.Ioi 0.5) f
this : sqrt (2 * 512) = 32
β’ 1 β€ 2 | /-
Copyright (c) 2020 Patrick Stevens. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Stevens, Bolton Bailey
-/
import Mathlib.Data.Nat.Choose.Factorization
import Mathlib.Data.Nat.PrimeNormNum
import Mathlib.NumberTheory.Primorial
import Mathlib.Analysis.Convex.SpecificFunctions.Basic
import Mathlib.Analysis.Convex.SpecificFunctions.Deriv
#align_import number_theory.bertrand from "leanprover-community/mathlib"@"a16665637b378379689c566204817ae792ac8b39"
/-!
# Bertrand's Postulate
This file contains a proof of Bertrand's postulate: That between any positive number and its
double there is a prime.
The proof follows the outline of the ErdΕs proof presented in "Proofs from THE BOOK": One considers
the prime factorization of `(2 * n).choose n`, and splits the constituent primes up into various
groups, then upper bounds the contribution of each group. This upper bounds the central binomial
coefficient, and if the postulate does not hold, this upper bound conflicts with a simple lower
bound for large enough `n`. This proves the result holds for large enough `n`, and for smaller `n`
an explicit list of primes is provided which covers the remaining cases.
As in the [Metamath implementation](carneiro2015arithmetic), we rely on some optimizations from
[Shigenori Tochiori](tochiori_bertrand). In particular we use the cleaner bound on the central
binomial coefficient given in `Nat.four_pow_lt_mul_centralBinom`.
## References
* [M. Aigner and G. M. Ziegler _Proofs from THE BOOK_][aigner1999proofs]
* [S. Tochiori, _Considering the Proof of βThere is a Prime between n and 2nβ_][tochiori_bertrand]
* [M. Carneiro, _Arithmetic in Metamath, Case Study: Bertrand's Postulate_][carneiro2015arithmetic]
## Tags
Bertrand, prime, binomial coefficients
-/
open scoped BigOperators
section Real
open Real
namespace Bertrand
/-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> norm_num1
apply le_trans _ (le_mul_of_one_le_left _ _) <;> norm_num1
apply Real.rpow_le_rpow <;> norm_num1
apply rpow_nonneg_of_nonneg; norm_num1
apply rpow_pos_of_pos; norm_num1
apply hf' 18; norm_num1
norm_num1
Β· have : sqrt (2 * 512) = 32 :=
(sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonpos_iff (hf' _ _), this, div_le_one] <;> norm_num1
Β· conv in 512 => equals 2 ^ 9 => norm_num1
conv in 1024 => equals 2 ^ 10 => norm_num1
conv in 32 => rw [β Nat.cast_ofNat]
rw [rpow_nat_cast, β pow_mul, β pow_add]
conv in 4 => equals 2 ^ (2 : β) => rw [rpow_two]; norm_num1
rw [β rpow_mul, β rpow_nat_cast]
apply rpow_le_rpow_of_exponent_le
all_goals | norm_num1 | /-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> norm_num1
apply le_trans _ (le_mul_of_one_le_left _ _) <;> norm_num1
apply Real.rpow_le_rpow <;> norm_num1
apply rpow_nonneg_of_nonneg; norm_num1
apply rpow_pos_of_pos; norm_num1
apply hf' 18; norm_num1
norm_num1
Β· have : sqrt (2 * 512) = 32 :=
(sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonpos_iff (hf' _ _), this, div_le_one] <;> norm_num1
Β· conv in 512 => equals 2 ^ 9 => norm_num1
conv in 1024 => equals 2 ^ 10 => norm_num1
conv in 32 => rw [β Nat.cast_ofNat]
rw [rpow_nat_cast, β pow_mul, β pow_add]
conv in 4 => equals 2 ^ (2 : β) => rw [rpow_two]; norm_num1
rw [β rpow_mul, β rpow_nat_cast]
apply rpow_le_rpow_of_exponent_le
all_goals | Mathlib.NumberTheory.Bertrand.51_0.gJXoOT9Ce2wC0xc | /-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x | Mathlib_NumberTheory_Bertrand |
case refine'_2.hyz
x : β
n_large : 512 β€ x
f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
hf' : β (x : β), 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)
hf : β (x : β), 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3))
h5 : 0 < x
h : ConcaveOn β (Set.Ioi 0.5) f
this : sqrt (2 * 512) = 32
β’ β(9 + 10 * 32) β€ 2 * (512 / 3) | /-
Copyright (c) 2020 Patrick Stevens. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Stevens, Bolton Bailey
-/
import Mathlib.Data.Nat.Choose.Factorization
import Mathlib.Data.Nat.PrimeNormNum
import Mathlib.NumberTheory.Primorial
import Mathlib.Analysis.Convex.SpecificFunctions.Basic
import Mathlib.Analysis.Convex.SpecificFunctions.Deriv
#align_import number_theory.bertrand from "leanprover-community/mathlib"@"a16665637b378379689c566204817ae792ac8b39"
/-!
# Bertrand's Postulate
This file contains a proof of Bertrand's postulate: That between any positive number and its
double there is a prime.
The proof follows the outline of the ErdΕs proof presented in "Proofs from THE BOOK": One considers
the prime factorization of `(2 * n).choose n`, and splits the constituent primes up into various
groups, then upper bounds the contribution of each group. This upper bounds the central binomial
coefficient, and if the postulate does not hold, this upper bound conflicts with a simple lower
bound for large enough `n`. This proves the result holds for large enough `n`, and for smaller `n`
an explicit list of primes is provided which covers the remaining cases.
As in the [Metamath implementation](carneiro2015arithmetic), we rely on some optimizations from
[Shigenori Tochiori](tochiori_bertrand). In particular we use the cleaner bound on the central
binomial coefficient given in `Nat.four_pow_lt_mul_centralBinom`.
## References
* [M. Aigner and G. M. Ziegler _Proofs from THE BOOK_][aigner1999proofs]
* [S. Tochiori, _Considering the Proof of βThere is a Prime between n and 2nβ_][tochiori_bertrand]
* [M. Carneiro, _Arithmetic in Metamath, Case Study: Bertrand's Postulate_][carneiro2015arithmetic]
## Tags
Bertrand, prime, binomial coefficients
-/
open scoped BigOperators
section Real
open Real
namespace Bertrand
/-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> norm_num1
apply le_trans _ (le_mul_of_one_le_left _ _) <;> norm_num1
apply Real.rpow_le_rpow <;> norm_num1
apply rpow_nonneg_of_nonneg; norm_num1
apply rpow_pos_of_pos; norm_num1
apply hf' 18; norm_num1
norm_num1
Β· have : sqrt (2 * 512) = 32 :=
(sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonpos_iff (hf' _ _), this, div_le_one] <;> norm_num1
Β· conv in 512 => equals 2 ^ 9 => norm_num1
conv in 1024 => equals 2 ^ 10 => norm_num1
conv in 32 => rw [β Nat.cast_ofNat]
rw [rpow_nat_cast, β pow_mul, β pow_add]
conv in 4 => equals 2 ^ (2 : β) => rw [rpow_two]; norm_num1
rw [β rpow_mul, β rpow_nat_cast]
apply rpow_le_rpow_of_exponent_le
all_goals | norm_num1 | /-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> norm_num1
apply le_trans _ (le_mul_of_one_le_left _ _) <;> norm_num1
apply Real.rpow_le_rpow <;> norm_num1
apply rpow_nonneg_of_nonneg; norm_num1
apply rpow_pos_of_pos; norm_num1
apply hf' 18; norm_num1
norm_num1
Β· have : sqrt (2 * 512) = 32 :=
(sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonpos_iff (hf' _ _), this, div_le_one] <;> norm_num1
Β· conv in 512 => equals 2 ^ 9 => norm_num1
conv in 1024 => equals 2 ^ 10 => norm_num1
conv in 32 => rw [β Nat.cast_ofNat]
rw [rpow_nat_cast, β pow_mul, β pow_add]
conv in 4 => equals 2 ^ (2 : β) => rw [rpow_two]; norm_num1
rw [β rpow_mul, β rpow_nat_cast]
apply rpow_le_rpow_of_exponent_le
all_goals | Mathlib.NumberTheory.Bertrand.51_0.gJXoOT9Ce2wC0xc | /-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x | Mathlib_NumberTheory_Bertrand |
case refine'_2.hx
x : β
n_large : 512 β€ x
f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
hf' : β (x : β), 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)
hf : β (x : β), 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3))
h5 : 0 < x
h : ConcaveOn β (Set.Ioi 0.5) f
this : sqrt (2 * 512) = 32
β’ 0 β€ 2 | /-
Copyright (c) 2020 Patrick Stevens. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Stevens, Bolton Bailey
-/
import Mathlib.Data.Nat.Choose.Factorization
import Mathlib.Data.Nat.PrimeNormNum
import Mathlib.NumberTheory.Primorial
import Mathlib.Analysis.Convex.SpecificFunctions.Basic
import Mathlib.Analysis.Convex.SpecificFunctions.Deriv
#align_import number_theory.bertrand from "leanprover-community/mathlib"@"a16665637b378379689c566204817ae792ac8b39"
/-!
# Bertrand's Postulate
This file contains a proof of Bertrand's postulate: That between any positive number and its
double there is a prime.
The proof follows the outline of the ErdΕs proof presented in "Proofs from THE BOOK": One considers
the prime factorization of `(2 * n).choose n`, and splits the constituent primes up into various
groups, then upper bounds the contribution of each group. This upper bounds the central binomial
coefficient, and if the postulate does not hold, this upper bound conflicts with a simple lower
bound for large enough `n`. This proves the result holds for large enough `n`, and for smaller `n`
an explicit list of primes is provided which covers the remaining cases.
As in the [Metamath implementation](carneiro2015arithmetic), we rely on some optimizations from
[Shigenori Tochiori](tochiori_bertrand). In particular we use the cleaner bound on the central
binomial coefficient given in `Nat.four_pow_lt_mul_centralBinom`.
## References
* [M. Aigner and G. M. Ziegler _Proofs from THE BOOK_][aigner1999proofs]
* [S. Tochiori, _Considering the Proof of βThere is a Prime between n and 2nβ_][tochiori_bertrand]
* [M. Carneiro, _Arithmetic in Metamath, Case Study: Bertrand's Postulate_][carneiro2015arithmetic]
## Tags
Bertrand, prime, binomial coefficients
-/
open scoped BigOperators
section Real
open Real
namespace Bertrand
/-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> norm_num1
apply le_trans _ (le_mul_of_one_le_left _ _) <;> norm_num1
apply Real.rpow_le_rpow <;> norm_num1
apply rpow_nonneg_of_nonneg; norm_num1
apply rpow_pos_of_pos; norm_num1
apply hf' 18; norm_num1
norm_num1
Β· have : sqrt (2 * 512) = 32 :=
(sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonpos_iff (hf' _ _), this, div_le_one] <;> norm_num1
Β· conv in 512 => equals 2 ^ 9 => norm_num1
conv in 1024 => equals 2 ^ 10 => norm_num1
conv in 32 => rw [β Nat.cast_ofNat]
rw [rpow_nat_cast, β pow_mul, β pow_add]
conv in 4 => equals 2 ^ (2 : β) => rw [rpow_two]; norm_num1
rw [β rpow_mul, β rpow_nat_cast]
apply rpow_le_rpow_of_exponent_le
all_goals | norm_num1 | /-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> norm_num1
apply le_trans _ (le_mul_of_one_le_left _ _) <;> norm_num1
apply Real.rpow_le_rpow <;> norm_num1
apply rpow_nonneg_of_nonneg; norm_num1
apply rpow_pos_of_pos; norm_num1
apply hf' 18; norm_num1
norm_num1
Β· have : sqrt (2 * 512) = 32 :=
(sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonpos_iff (hf' _ _), this, div_le_one] <;> norm_num1
Β· conv in 512 => equals 2 ^ 9 => norm_num1
conv in 1024 => equals 2 ^ 10 => norm_num1
conv in 32 => rw [β Nat.cast_ofNat]
rw [rpow_nat_cast, β pow_mul, β pow_add]
conv in 4 => equals 2 ^ (2 : β) => rw [rpow_two]; norm_num1
rw [β rpow_mul, β rpow_nat_cast]
apply rpow_le_rpow_of_exponent_le
all_goals | Mathlib.NumberTheory.Bertrand.51_0.gJXoOT9Ce2wC0xc | /-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x | Mathlib_NumberTheory_Bertrand |
case refine'_2
x : β
n_large : 512 β€ x
f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
hf' : β (x : β), 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)
hf : β (x : β), 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3))
h5 : 0 < x
h : ConcaveOn β (Set.Ioi 0.5) f
this : sqrt (2 * 512) = 32
β’ 0 < 4 ^ (512 / 3) | /-
Copyright (c) 2020 Patrick Stevens. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Stevens, Bolton Bailey
-/
import Mathlib.Data.Nat.Choose.Factorization
import Mathlib.Data.Nat.PrimeNormNum
import Mathlib.NumberTheory.Primorial
import Mathlib.Analysis.Convex.SpecificFunctions.Basic
import Mathlib.Analysis.Convex.SpecificFunctions.Deriv
#align_import number_theory.bertrand from "leanprover-community/mathlib"@"a16665637b378379689c566204817ae792ac8b39"
/-!
# Bertrand's Postulate
This file contains a proof of Bertrand's postulate: That between any positive number and its
double there is a prime.
The proof follows the outline of the ErdΕs proof presented in "Proofs from THE BOOK": One considers
the prime factorization of `(2 * n).choose n`, and splits the constituent primes up into various
groups, then upper bounds the contribution of each group. This upper bounds the central binomial
coefficient, and if the postulate does not hold, this upper bound conflicts with a simple lower
bound for large enough `n`. This proves the result holds for large enough `n`, and for smaller `n`
an explicit list of primes is provided which covers the remaining cases.
As in the [Metamath implementation](carneiro2015arithmetic), we rely on some optimizations from
[Shigenori Tochiori](tochiori_bertrand). In particular we use the cleaner bound on the central
binomial coefficient given in `Nat.four_pow_lt_mul_centralBinom`.
## References
* [M. Aigner and G. M. Ziegler _Proofs from THE BOOK_][aigner1999proofs]
* [S. Tochiori, _Considering the Proof of βThere is a Prime between n and 2nβ_][tochiori_bertrand]
* [M. Carneiro, _Arithmetic in Metamath, Case Study: Bertrand's Postulate_][carneiro2015arithmetic]
## Tags
Bertrand, prime, binomial coefficients
-/
open scoped BigOperators
section Real
open Real
namespace Bertrand
/-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> norm_num1
apply le_trans _ (le_mul_of_one_le_left _ _) <;> norm_num1
apply Real.rpow_le_rpow <;> norm_num1
apply rpow_nonneg_of_nonneg; norm_num1
apply rpow_pos_of_pos; norm_num1
apply hf' 18; norm_num1
norm_num1
Β· have : sqrt (2 * 512) = 32 :=
(sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonpos_iff (hf' _ _), this, div_le_one] <;> norm_num1
Β· conv in 512 => equals 2 ^ 9 => norm_num1
conv in 1024 => equals 2 ^ 10 => norm_num1
conv in 32 => rw [β Nat.cast_ofNat]
rw [rpow_nat_cast, β pow_mul, β pow_add]
conv in 4 => equals 2 ^ (2 : β) => rw [rpow_two]; norm_num1
rw [β rpow_mul, β rpow_nat_cast]
apply rpow_le_rpow_of_exponent_le
all_goals norm_num1
Β· | apply rpow_pos_of_pos four_pos | /-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> norm_num1
apply le_trans _ (le_mul_of_one_le_left _ _) <;> norm_num1
apply Real.rpow_le_rpow <;> norm_num1
apply rpow_nonneg_of_nonneg; norm_num1
apply rpow_pos_of_pos; norm_num1
apply hf' 18; norm_num1
norm_num1
Β· have : sqrt (2 * 512) = 32 :=
(sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonpos_iff (hf' _ _), this, div_le_one] <;> norm_num1
Β· conv in 512 => equals 2 ^ 9 => norm_num1
conv in 1024 => equals 2 ^ 10 => norm_num1
conv in 32 => rw [β Nat.cast_ofNat]
rw [rpow_nat_cast, β pow_mul, β pow_add]
conv in 4 => equals 2 ^ (2 : β) => rw [rpow_two]; norm_num1
rw [β rpow_mul, β rpow_nat_cast]
apply rpow_le_rpow_of_exponent_le
all_goals norm_num1
Β· | Mathlib.NumberTheory.Bertrand.51_0.gJXoOT9Ce2wC0xc | /-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x | Mathlib_NumberTheory_Bertrand |
n : β
n_large : 512 β€ n
β’ n * (2 * n) ^ sqrt (2 * n) * 4 ^ (2 * n / 3) β€ 4 ^ n | /-
Copyright (c) 2020 Patrick Stevens. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Stevens, Bolton Bailey
-/
import Mathlib.Data.Nat.Choose.Factorization
import Mathlib.Data.Nat.PrimeNormNum
import Mathlib.NumberTheory.Primorial
import Mathlib.Analysis.Convex.SpecificFunctions.Basic
import Mathlib.Analysis.Convex.SpecificFunctions.Deriv
#align_import number_theory.bertrand from "leanprover-community/mathlib"@"a16665637b378379689c566204817ae792ac8b39"
/-!
# Bertrand's Postulate
This file contains a proof of Bertrand's postulate: That between any positive number and its
double there is a prime.
The proof follows the outline of the ErdΕs proof presented in "Proofs from THE BOOK": One considers
the prime factorization of `(2 * n).choose n`, and splits the constituent primes up into various
groups, then upper bounds the contribution of each group. This upper bounds the central binomial
coefficient, and if the postulate does not hold, this upper bound conflicts with a simple lower
bound for large enough `n`. This proves the result holds for large enough `n`, and for smaller `n`
an explicit list of primes is provided which covers the remaining cases.
As in the [Metamath implementation](carneiro2015arithmetic), we rely on some optimizations from
[Shigenori Tochiori](tochiori_bertrand). In particular we use the cleaner bound on the central
binomial coefficient given in `Nat.four_pow_lt_mul_centralBinom`.
## References
* [M. Aigner and G. M. Ziegler _Proofs from THE BOOK_][aigner1999proofs]
* [S. Tochiori, _Considering the Proof of βThere is a Prime between n and 2nβ_][tochiori_bertrand]
* [M. Carneiro, _Arithmetic in Metamath, Case Study: Bertrand's Postulate_][carneiro2015arithmetic]
## Tags
Bertrand, prime, binomial coefficients
-/
open scoped BigOperators
section Real
open Real
namespace Bertrand
/-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> norm_num1
apply le_trans _ (le_mul_of_one_le_left _ _) <;> norm_num1
apply Real.rpow_le_rpow <;> norm_num1
apply rpow_nonneg_of_nonneg; norm_num1
apply rpow_pos_of_pos; norm_num1
apply hf' 18; norm_num1
norm_num1
Β· have : sqrt (2 * 512) = 32 :=
(sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonpos_iff (hf' _ _), this, div_le_one] <;> norm_num1
Β· conv in 512 => equals 2 ^ 9 => norm_num1
conv in 1024 => equals 2 ^ 10 => norm_num1
conv in 32 => rw [β Nat.cast_ofNat]
rw [rpow_nat_cast, β pow_mul, β pow_add]
conv in 4 => equals 2 ^ (2 : β) => rw [rpow_two]; norm_num1
rw [β rpow_mul, β rpow_nat_cast]
apply rpow_le_rpow_of_exponent_le
all_goals norm_num1
Β· apply rpow_pos_of_pos four_pos
#align bertrand.real_main_inequality Bertrand.real_main_inequality
end Bertrand
end Real
section Nat
open Nat
/-- The inequality which contradicts Bertrand's postulate, for large enough `n`.
-/
theorem bertrand_main_inequality {n : β} (n_large : 512 β€ n) :
n * (2 * n) ^ sqrt (2 * n) * 4 ^ (2 * n / 3) β€ 4 ^ n := by
| rw [β @cast_le β] | /-- The inequality which contradicts Bertrand's postulate, for large enough `n`.
-/
theorem bertrand_main_inequality {n : β} (n_large : 512 β€ n) :
n * (2 * n) ^ sqrt (2 * n) * 4 ^ (2 * n / 3) β€ 4 ^ n := by
| Mathlib.NumberTheory.Bertrand.121_0.gJXoOT9Ce2wC0xc | /-- The inequality which contradicts Bertrand's postulate, for large enough `n`.
-/
theorem bertrand_main_inequality {n : β} (n_large : 512 β€ n) :
n * (2 * n) ^ sqrt (2 * n) * 4 ^ (2 * n / 3) β€ 4 ^ n | Mathlib_NumberTheory_Bertrand |
n : β
n_large : 512 β€ n
β’ β(n * (2 * n) ^ sqrt (2 * n) * 4 ^ (2 * n / 3)) β€ β(4 ^ n) | /-
Copyright (c) 2020 Patrick Stevens. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Stevens, Bolton Bailey
-/
import Mathlib.Data.Nat.Choose.Factorization
import Mathlib.Data.Nat.PrimeNormNum
import Mathlib.NumberTheory.Primorial
import Mathlib.Analysis.Convex.SpecificFunctions.Basic
import Mathlib.Analysis.Convex.SpecificFunctions.Deriv
#align_import number_theory.bertrand from "leanprover-community/mathlib"@"a16665637b378379689c566204817ae792ac8b39"
/-!
# Bertrand's Postulate
This file contains a proof of Bertrand's postulate: That between any positive number and its
double there is a prime.
The proof follows the outline of the ErdΕs proof presented in "Proofs from THE BOOK": One considers
the prime factorization of `(2 * n).choose n`, and splits the constituent primes up into various
groups, then upper bounds the contribution of each group. This upper bounds the central binomial
coefficient, and if the postulate does not hold, this upper bound conflicts with a simple lower
bound for large enough `n`. This proves the result holds for large enough `n`, and for smaller `n`
an explicit list of primes is provided which covers the remaining cases.
As in the [Metamath implementation](carneiro2015arithmetic), we rely on some optimizations from
[Shigenori Tochiori](tochiori_bertrand). In particular we use the cleaner bound on the central
binomial coefficient given in `Nat.four_pow_lt_mul_centralBinom`.
## References
* [M. Aigner and G. M. Ziegler _Proofs from THE BOOK_][aigner1999proofs]
* [S. Tochiori, _Considering the Proof of βThere is a Prime between n and 2nβ_][tochiori_bertrand]
* [M. Carneiro, _Arithmetic in Metamath, Case Study: Bertrand's Postulate_][carneiro2015arithmetic]
## Tags
Bertrand, prime, binomial coefficients
-/
open scoped BigOperators
section Real
open Real
namespace Bertrand
/-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> norm_num1
apply le_trans _ (le_mul_of_one_le_left _ _) <;> norm_num1
apply Real.rpow_le_rpow <;> norm_num1
apply rpow_nonneg_of_nonneg; norm_num1
apply rpow_pos_of_pos; norm_num1
apply hf' 18; norm_num1
norm_num1
Β· have : sqrt (2 * 512) = 32 :=
(sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonpos_iff (hf' _ _), this, div_le_one] <;> norm_num1
Β· conv in 512 => equals 2 ^ 9 => norm_num1
conv in 1024 => equals 2 ^ 10 => norm_num1
conv in 32 => rw [β Nat.cast_ofNat]
rw [rpow_nat_cast, β pow_mul, β pow_add]
conv in 4 => equals 2 ^ (2 : β) => rw [rpow_two]; norm_num1
rw [β rpow_mul, β rpow_nat_cast]
apply rpow_le_rpow_of_exponent_le
all_goals norm_num1
Β· apply rpow_pos_of_pos four_pos
#align bertrand.real_main_inequality Bertrand.real_main_inequality
end Bertrand
end Real
section Nat
open Nat
/-- The inequality which contradicts Bertrand's postulate, for large enough `n`.
-/
theorem bertrand_main_inequality {n : β} (n_large : 512 β€ n) :
n * (2 * n) ^ sqrt (2 * n) * 4 ^ (2 * n / 3) β€ 4 ^ n := by
rw [β @cast_le β]
| simp only [cast_add, cast_one, cast_mul, cast_pow, β Real.rpow_nat_cast] | /-- The inequality which contradicts Bertrand's postulate, for large enough `n`.
-/
theorem bertrand_main_inequality {n : β} (n_large : 512 β€ n) :
n * (2 * n) ^ sqrt (2 * n) * 4 ^ (2 * n / 3) β€ 4 ^ n := by
rw [β @cast_le β]
| Mathlib.NumberTheory.Bertrand.121_0.gJXoOT9Ce2wC0xc | /-- The inequality which contradicts Bertrand's postulate, for large enough `n`.
-/
theorem bertrand_main_inequality {n : β} (n_large : 512 β€ n) :
n * (2 * n) ^ sqrt (2 * n) * 4 ^ (2 * n / 3) β€ 4 ^ n | Mathlib_NumberTheory_Bertrand |
n : β
n_large : 512 β€ n
β’ βn * (β2 * βn) ^ β(sqrt (2 * n)) * β4 ^ β(2 * n / 3) β€ β4 ^ βn | /-
Copyright (c) 2020 Patrick Stevens. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Stevens, Bolton Bailey
-/
import Mathlib.Data.Nat.Choose.Factorization
import Mathlib.Data.Nat.PrimeNormNum
import Mathlib.NumberTheory.Primorial
import Mathlib.Analysis.Convex.SpecificFunctions.Basic
import Mathlib.Analysis.Convex.SpecificFunctions.Deriv
#align_import number_theory.bertrand from "leanprover-community/mathlib"@"a16665637b378379689c566204817ae792ac8b39"
/-!
# Bertrand's Postulate
This file contains a proof of Bertrand's postulate: That between any positive number and its
double there is a prime.
The proof follows the outline of the ErdΕs proof presented in "Proofs from THE BOOK": One considers
the prime factorization of `(2 * n).choose n`, and splits the constituent primes up into various
groups, then upper bounds the contribution of each group. This upper bounds the central binomial
coefficient, and if the postulate does not hold, this upper bound conflicts with a simple lower
bound for large enough `n`. This proves the result holds for large enough `n`, and for smaller `n`
an explicit list of primes is provided which covers the remaining cases.
As in the [Metamath implementation](carneiro2015arithmetic), we rely on some optimizations from
[Shigenori Tochiori](tochiori_bertrand). In particular we use the cleaner bound on the central
binomial coefficient given in `Nat.four_pow_lt_mul_centralBinom`.
## References
* [M. Aigner and G. M. Ziegler _Proofs from THE BOOK_][aigner1999proofs]
* [S. Tochiori, _Considering the Proof of βThere is a Prime between n and 2nβ_][tochiori_bertrand]
* [M. Carneiro, _Arithmetic in Metamath, Case Study: Bertrand's Postulate_][carneiro2015arithmetic]
## Tags
Bertrand, prime, binomial coefficients
-/
open scoped BigOperators
section Real
open Real
namespace Bertrand
/-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> norm_num1
apply le_trans _ (le_mul_of_one_le_left _ _) <;> norm_num1
apply Real.rpow_le_rpow <;> norm_num1
apply rpow_nonneg_of_nonneg; norm_num1
apply rpow_pos_of_pos; norm_num1
apply hf' 18; norm_num1
norm_num1
Β· have : sqrt (2 * 512) = 32 :=
(sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonpos_iff (hf' _ _), this, div_le_one] <;> norm_num1
Β· conv in 512 => equals 2 ^ 9 => norm_num1
conv in 1024 => equals 2 ^ 10 => norm_num1
conv in 32 => rw [β Nat.cast_ofNat]
rw [rpow_nat_cast, β pow_mul, β pow_add]
conv in 4 => equals 2 ^ (2 : β) => rw [rpow_two]; norm_num1
rw [β rpow_mul, β rpow_nat_cast]
apply rpow_le_rpow_of_exponent_le
all_goals norm_num1
Β· apply rpow_pos_of_pos four_pos
#align bertrand.real_main_inequality Bertrand.real_main_inequality
end Bertrand
end Real
section Nat
open Nat
/-- The inequality which contradicts Bertrand's postulate, for large enough `n`.
-/
theorem bertrand_main_inequality {n : β} (n_large : 512 β€ n) :
n * (2 * n) ^ sqrt (2 * n) * 4 ^ (2 * n / 3) β€ 4 ^ n := by
rw [β @cast_le β]
simp only [cast_add, cast_one, cast_mul, cast_pow, β Real.rpow_nat_cast]
| refine' _root_.trans ?_ (Bertrand.real_main_inequality (by exact_mod_cast n_large)) | /-- The inequality which contradicts Bertrand's postulate, for large enough `n`.
-/
theorem bertrand_main_inequality {n : β} (n_large : 512 β€ n) :
n * (2 * n) ^ sqrt (2 * n) * 4 ^ (2 * n / 3) β€ 4 ^ n := by
rw [β @cast_le β]
simp only [cast_add, cast_one, cast_mul, cast_pow, β Real.rpow_nat_cast]
| Mathlib.NumberTheory.Bertrand.121_0.gJXoOT9Ce2wC0xc | /-- The inequality which contradicts Bertrand's postulate, for large enough `n`.
-/
theorem bertrand_main_inequality {n : β} (n_large : 512 β€ n) :
n * (2 * n) ^ sqrt (2 * n) * 4 ^ (2 * n / 3) β€ 4 ^ n | Mathlib_NumberTheory_Bertrand |
n : β
n_large : 512 β€ n
β’ 512 β€ βn | /-
Copyright (c) 2020 Patrick Stevens. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Stevens, Bolton Bailey
-/
import Mathlib.Data.Nat.Choose.Factorization
import Mathlib.Data.Nat.PrimeNormNum
import Mathlib.NumberTheory.Primorial
import Mathlib.Analysis.Convex.SpecificFunctions.Basic
import Mathlib.Analysis.Convex.SpecificFunctions.Deriv
#align_import number_theory.bertrand from "leanprover-community/mathlib"@"a16665637b378379689c566204817ae792ac8b39"
/-!
# Bertrand's Postulate
This file contains a proof of Bertrand's postulate: That between any positive number and its
double there is a prime.
The proof follows the outline of the ErdΕs proof presented in "Proofs from THE BOOK": One considers
the prime factorization of `(2 * n).choose n`, and splits the constituent primes up into various
groups, then upper bounds the contribution of each group. This upper bounds the central binomial
coefficient, and if the postulate does not hold, this upper bound conflicts with a simple lower
bound for large enough `n`. This proves the result holds for large enough `n`, and for smaller `n`
an explicit list of primes is provided which covers the remaining cases.
As in the [Metamath implementation](carneiro2015arithmetic), we rely on some optimizations from
[Shigenori Tochiori](tochiori_bertrand). In particular we use the cleaner bound on the central
binomial coefficient given in `Nat.four_pow_lt_mul_centralBinom`.
## References
* [M. Aigner and G. M. Ziegler _Proofs from THE BOOK_][aigner1999proofs]
* [S. Tochiori, _Considering the Proof of βThere is a Prime between n and 2nβ_][tochiori_bertrand]
* [M. Carneiro, _Arithmetic in Metamath, Case Study: Bertrand's Postulate_][carneiro2015arithmetic]
## Tags
Bertrand, prime, binomial coefficients
-/
open scoped BigOperators
section Real
open Real
namespace Bertrand
/-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> norm_num1
apply le_trans _ (le_mul_of_one_le_left _ _) <;> norm_num1
apply Real.rpow_le_rpow <;> norm_num1
apply rpow_nonneg_of_nonneg; norm_num1
apply rpow_pos_of_pos; norm_num1
apply hf' 18; norm_num1
norm_num1
Β· have : sqrt (2 * 512) = 32 :=
(sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonpos_iff (hf' _ _), this, div_le_one] <;> norm_num1
Β· conv in 512 => equals 2 ^ 9 => norm_num1
conv in 1024 => equals 2 ^ 10 => norm_num1
conv in 32 => rw [β Nat.cast_ofNat]
rw [rpow_nat_cast, β pow_mul, β pow_add]
conv in 4 => equals 2 ^ (2 : β) => rw [rpow_two]; norm_num1
rw [β rpow_mul, β rpow_nat_cast]
apply rpow_le_rpow_of_exponent_le
all_goals norm_num1
Β· apply rpow_pos_of_pos four_pos
#align bertrand.real_main_inequality Bertrand.real_main_inequality
end Bertrand
end Real
section Nat
open Nat
/-- The inequality which contradicts Bertrand's postulate, for large enough `n`.
-/
theorem bertrand_main_inequality {n : β} (n_large : 512 β€ n) :
n * (2 * n) ^ sqrt (2 * n) * 4 ^ (2 * n / 3) β€ 4 ^ n := by
rw [β @cast_le β]
simp only [cast_add, cast_one, cast_mul, cast_pow, β Real.rpow_nat_cast]
refine' _root_.trans ?_ (Bertrand.real_main_inequality (by | exact_mod_cast n_large | /-- The inequality which contradicts Bertrand's postulate, for large enough `n`.
-/
theorem bertrand_main_inequality {n : β} (n_large : 512 β€ n) :
n * (2 * n) ^ sqrt (2 * n) * 4 ^ (2 * n / 3) β€ 4 ^ n := by
rw [β @cast_le β]
simp only [cast_add, cast_one, cast_mul, cast_pow, β Real.rpow_nat_cast]
refine' _root_.trans ?_ (Bertrand.real_main_inequality (by | Mathlib.NumberTheory.Bertrand.121_0.gJXoOT9Ce2wC0xc | /-- The inequality which contradicts Bertrand's postulate, for large enough `n`.
-/
theorem bertrand_main_inequality {n : β} (n_large : 512 β€ n) :
n * (2 * n) ^ sqrt (2 * n) * 4 ^ (2 * n / 3) β€ 4 ^ n | Mathlib_NumberTheory_Bertrand |
n : β
n_large : 512 β€ n
β’ βn * (β2 * βn) ^ β(sqrt (2 * n)) * β4 ^ β(2 * n / 3) β€ βn * (2 * βn) ^ Real.sqrt (2 * βn) * 4 ^ (2 * βn / 3) | /-
Copyright (c) 2020 Patrick Stevens. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Stevens, Bolton Bailey
-/
import Mathlib.Data.Nat.Choose.Factorization
import Mathlib.Data.Nat.PrimeNormNum
import Mathlib.NumberTheory.Primorial
import Mathlib.Analysis.Convex.SpecificFunctions.Basic
import Mathlib.Analysis.Convex.SpecificFunctions.Deriv
#align_import number_theory.bertrand from "leanprover-community/mathlib"@"a16665637b378379689c566204817ae792ac8b39"
/-!
# Bertrand's Postulate
This file contains a proof of Bertrand's postulate: That between any positive number and its
double there is a prime.
The proof follows the outline of the ErdΕs proof presented in "Proofs from THE BOOK": One considers
the prime factorization of `(2 * n).choose n`, and splits the constituent primes up into various
groups, then upper bounds the contribution of each group. This upper bounds the central binomial
coefficient, and if the postulate does not hold, this upper bound conflicts with a simple lower
bound for large enough `n`. This proves the result holds for large enough `n`, and for smaller `n`
an explicit list of primes is provided which covers the remaining cases.
As in the [Metamath implementation](carneiro2015arithmetic), we rely on some optimizations from
[Shigenori Tochiori](tochiori_bertrand). In particular we use the cleaner bound on the central
binomial coefficient given in `Nat.four_pow_lt_mul_centralBinom`.
## References
* [M. Aigner and G. M. Ziegler _Proofs from THE BOOK_][aigner1999proofs]
* [S. Tochiori, _Considering the Proof of βThere is a Prime between n and 2nβ_][tochiori_bertrand]
* [M. Carneiro, _Arithmetic in Metamath, Case Study: Bertrand's Postulate_][carneiro2015arithmetic]
## Tags
Bertrand, prime, binomial coefficients
-/
open scoped BigOperators
section Real
open Real
namespace Bertrand
/-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> norm_num1
apply le_trans _ (le_mul_of_one_le_left _ _) <;> norm_num1
apply Real.rpow_le_rpow <;> norm_num1
apply rpow_nonneg_of_nonneg; norm_num1
apply rpow_pos_of_pos; norm_num1
apply hf' 18; norm_num1
norm_num1
Β· have : sqrt (2 * 512) = 32 :=
(sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonpos_iff (hf' _ _), this, div_le_one] <;> norm_num1
Β· conv in 512 => equals 2 ^ 9 => norm_num1
conv in 1024 => equals 2 ^ 10 => norm_num1
conv in 32 => rw [β Nat.cast_ofNat]
rw [rpow_nat_cast, β pow_mul, β pow_add]
conv in 4 => equals 2 ^ (2 : β) => rw [rpow_two]; norm_num1
rw [β rpow_mul, β rpow_nat_cast]
apply rpow_le_rpow_of_exponent_le
all_goals norm_num1
Β· apply rpow_pos_of_pos four_pos
#align bertrand.real_main_inequality Bertrand.real_main_inequality
end Bertrand
end Real
section Nat
open Nat
/-- The inequality which contradicts Bertrand's postulate, for large enough `n`.
-/
theorem bertrand_main_inequality {n : β} (n_large : 512 β€ n) :
n * (2 * n) ^ sqrt (2 * n) * 4 ^ (2 * n / 3) β€ 4 ^ n := by
rw [β @cast_le β]
simp only [cast_add, cast_one, cast_mul, cast_pow, β Real.rpow_nat_cast]
refine' _root_.trans ?_ (Bertrand.real_main_inequality (by exact_mod_cast n_large))
| gcongr | /-- The inequality which contradicts Bertrand's postulate, for large enough `n`.
-/
theorem bertrand_main_inequality {n : β} (n_large : 512 β€ n) :
n * (2 * n) ^ sqrt (2 * n) * 4 ^ (2 * n / 3) β€ 4 ^ n := by
rw [β @cast_le β]
simp only [cast_add, cast_one, cast_mul, cast_pow, β Real.rpow_nat_cast]
refine' _root_.trans ?_ (Bertrand.real_main_inequality (by exact_mod_cast n_large))
| Mathlib.NumberTheory.Bertrand.121_0.gJXoOT9Ce2wC0xc | /-- The inequality which contradicts Bertrand's postulate, for large enough `n`.
-/
theorem bertrand_main_inequality {n : β} (n_large : 512 β€ n) :
n * (2 * n) ^ sqrt (2 * n) * 4 ^ (2 * n / 3) β€ 4 ^ n | Mathlib_NumberTheory_Bertrand |
case hβ.h.hx
n : β
n_large : 512 β€ n
β’ 1 β€ β2 * βn | /-
Copyright (c) 2020 Patrick Stevens. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Stevens, Bolton Bailey
-/
import Mathlib.Data.Nat.Choose.Factorization
import Mathlib.Data.Nat.PrimeNormNum
import Mathlib.NumberTheory.Primorial
import Mathlib.Analysis.Convex.SpecificFunctions.Basic
import Mathlib.Analysis.Convex.SpecificFunctions.Deriv
#align_import number_theory.bertrand from "leanprover-community/mathlib"@"a16665637b378379689c566204817ae792ac8b39"
/-!
# Bertrand's Postulate
This file contains a proof of Bertrand's postulate: That between any positive number and its
double there is a prime.
The proof follows the outline of the ErdΕs proof presented in "Proofs from THE BOOK": One considers
the prime factorization of `(2 * n).choose n`, and splits the constituent primes up into various
groups, then upper bounds the contribution of each group. This upper bounds the central binomial
coefficient, and if the postulate does not hold, this upper bound conflicts with a simple lower
bound for large enough `n`. This proves the result holds for large enough `n`, and for smaller `n`
an explicit list of primes is provided which covers the remaining cases.
As in the [Metamath implementation](carneiro2015arithmetic), we rely on some optimizations from
[Shigenori Tochiori](tochiori_bertrand). In particular we use the cleaner bound on the central
binomial coefficient given in `Nat.four_pow_lt_mul_centralBinom`.
## References
* [M. Aigner and G. M. Ziegler _Proofs from THE BOOK_][aigner1999proofs]
* [S. Tochiori, _Considering the Proof of βThere is a Prime between n and 2nβ_][tochiori_bertrand]
* [M. Carneiro, _Arithmetic in Metamath, Case Study: Bertrand's Postulate_][carneiro2015arithmetic]
## Tags
Bertrand, prime, binomial coefficients
-/
open scoped BigOperators
section Real
open Real
namespace Bertrand
/-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> norm_num1
apply le_trans _ (le_mul_of_one_le_left _ _) <;> norm_num1
apply Real.rpow_le_rpow <;> norm_num1
apply rpow_nonneg_of_nonneg; norm_num1
apply rpow_pos_of_pos; norm_num1
apply hf' 18; norm_num1
norm_num1
Β· have : sqrt (2 * 512) = 32 :=
(sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonpos_iff (hf' _ _), this, div_le_one] <;> norm_num1
Β· conv in 512 => equals 2 ^ 9 => norm_num1
conv in 1024 => equals 2 ^ 10 => norm_num1
conv in 32 => rw [β Nat.cast_ofNat]
rw [rpow_nat_cast, β pow_mul, β pow_add]
conv in 4 => equals 2 ^ (2 : β) => rw [rpow_two]; norm_num1
rw [β rpow_mul, β rpow_nat_cast]
apply rpow_le_rpow_of_exponent_le
all_goals norm_num1
Β· apply rpow_pos_of_pos four_pos
#align bertrand.real_main_inequality Bertrand.real_main_inequality
end Bertrand
end Real
section Nat
open Nat
/-- The inequality which contradicts Bertrand's postulate, for large enough `n`.
-/
theorem bertrand_main_inequality {n : β} (n_large : 512 β€ n) :
n * (2 * n) ^ sqrt (2 * n) * 4 ^ (2 * n / 3) β€ 4 ^ n := by
rw [β @cast_le β]
simp only [cast_add, cast_one, cast_mul, cast_pow, β Real.rpow_nat_cast]
refine' _root_.trans ?_ (Bertrand.real_main_inequality (by exact_mod_cast n_large))
gcongr
Β· | have n2_pos : 0 < 2 * n := by positivity | /-- The inequality which contradicts Bertrand's postulate, for large enough `n`.
-/
theorem bertrand_main_inequality {n : β} (n_large : 512 β€ n) :
n * (2 * n) ^ sqrt (2 * n) * 4 ^ (2 * n / 3) β€ 4 ^ n := by
rw [β @cast_le β]
simp only [cast_add, cast_one, cast_mul, cast_pow, β Real.rpow_nat_cast]
refine' _root_.trans ?_ (Bertrand.real_main_inequality (by exact_mod_cast n_large))
gcongr
Β· | Mathlib.NumberTheory.Bertrand.121_0.gJXoOT9Ce2wC0xc | /-- The inequality which contradicts Bertrand's postulate, for large enough `n`.
-/
theorem bertrand_main_inequality {n : β} (n_large : 512 β€ n) :
n * (2 * n) ^ sqrt (2 * n) * 4 ^ (2 * n / 3) β€ 4 ^ n | Mathlib_NumberTheory_Bertrand |
n : β
n_large : 512 β€ n
β’ 0 < 2 * n | /-
Copyright (c) 2020 Patrick Stevens. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Stevens, Bolton Bailey
-/
import Mathlib.Data.Nat.Choose.Factorization
import Mathlib.Data.Nat.PrimeNormNum
import Mathlib.NumberTheory.Primorial
import Mathlib.Analysis.Convex.SpecificFunctions.Basic
import Mathlib.Analysis.Convex.SpecificFunctions.Deriv
#align_import number_theory.bertrand from "leanprover-community/mathlib"@"a16665637b378379689c566204817ae792ac8b39"
/-!
# Bertrand's Postulate
This file contains a proof of Bertrand's postulate: That between any positive number and its
double there is a prime.
The proof follows the outline of the ErdΕs proof presented in "Proofs from THE BOOK": One considers
the prime factorization of `(2 * n).choose n`, and splits the constituent primes up into various
groups, then upper bounds the contribution of each group. This upper bounds the central binomial
coefficient, and if the postulate does not hold, this upper bound conflicts with a simple lower
bound for large enough `n`. This proves the result holds for large enough `n`, and for smaller `n`
an explicit list of primes is provided which covers the remaining cases.
As in the [Metamath implementation](carneiro2015arithmetic), we rely on some optimizations from
[Shigenori Tochiori](tochiori_bertrand). In particular we use the cleaner bound on the central
binomial coefficient given in `Nat.four_pow_lt_mul_centralBinom`.
## References
* [M. Aigner and G. M. Ziegler _Proofs from THE BOOK_][aigner1999proofs]
* [S. Tochiori, _Considering the Proof of βThere is a Prime between n and 2nβ_][tochiori_bertrand]
* [M. Carneiro, _Arithmetic in Metamath, Case Study: Bertrand's Postulate_][carneiro2015arithmetic]
## Tags
Bertrand, prime, binomial coefficients
-/
open scoped BigOperators
section Real
open Real
namespace Bertrand
/-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> norm_num1
apply le_trans _ (le_mul_of_one_le_left _ _) <;> norm_num1
apply Real.rpow_le_rpow <;> norm_num1
apply rpow_nonneg_of_nonneg; norm_num1
apply rpow_pos_of_pos; norm_num1
apply hf' 18; norm_num1
norm_num1
Β· have : sqrt (2 * 512) = 32 :=
(sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonpos_iff (hf' _ _), this, div_le_one] <;> norm_num1
Β· conv in 512 => equals 2 ^ 9 => norm_num1
conv in 1024 => equals 2 ^ 10 => norm_num1
conv in 32 => rw [β Nat.cast_ofNat]
rw [rpow_nat_cast, β pow_mul, β pow_add]
conv in 4 => equals 2 ^ (2 : β) => rw [rpow_two]; norm_num1
rw [β rpow_mul, β rpow_nat_cast]
apply rpow_le_rpow_of_exponent_le
all_goals norm_num1
Β· apply rpow_pos_of_pos four_pos
#align bertrand.real_main_inequality Bertrand.real_main_inequality
end Bertrand
end Real
section Nat
open Nat
/-- The inequality which contradicts Bertrand's postulate, for large enough `n`.
-/
theorem bertrand_main_inequality {n : β} (n_large : 512 β€ n) :
n * (2 * n) ^ sqrt (2 * n) * 4 ^ (2 * n / 3) β€ 4 ^ n := by
rw [β @cast_le β]
simp only [cast_add, cast_one, cast_mul, cast_pow, β Real.rpow_nat_cast]
refine' _root_.trans ?_ (Bertrand.real_main_inequality (by exact_mod_cast n_large))
gcongr
Β· have n2_pos : 0 < 2 * n := by | positivity | /-- The inequality which contradicts Bertrand's postulate, for large enough `n`.
-/
theorem bertrand_main_inequality {n : β} (n_large : 512 β€ n) :
n * (2 * n) ^ sqrt (2 * n) * 4 ^ (2 * n / 3) β€ 4 ^ n := by
rw [β @cast_le β]
simp only [cast_add, cast_one, cast_mul, cast_pow, β Real.rpow_nat_cast]
refine' _root_.trans ?_ (Bertrand.real_main_inequality (by exact_mod_cast n_large))
gcongr
Β· have n2_pos : 0 < 2 * n := by | Mathlib.NumberTheory.Bertrand.121_0.gJXoOT9Ce2wC0xc | /-- The inequality which contradicts Bertrand's postulate, for large enough `n`.
-/
theorem bertrand_main_inequality {n : β} (n_large : 512 β€ n) :
n * (2 * n) ^ sqrt (2 * n) * 4 ^ (2 * n / 3) β€ 4 ^ n | Mathlib_NumberTheory_Bertrand |
case hβ.h.hx
n : β
n_large : 512 β€ n
n2_pos : 0 < 2 * n
β’ 1 β€ β2 * βn | /-
Copyright (c) 2020 Patrick Stevens. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Stevens, Bolton Bailey
-/
import Mathlib.Data.Nat.Choose.Factorization
import Mathlib.Data.Nat.PrimeNormNum
import Mathlib.NumberTheory.Primorial
import Mathlib.Analysis.Convex.SpecificFunctions.Basic
import Mathlib.Analysis.Convex.SpecificFunctions.Deriv
#align_import number_theory.bertrand from "leanprover-community/mathlib"@"a16665637b378379689c566204817ae792ac8b39"
/-!
# Bertrand's Postulate
This file contains a proof of Bertrand's postulate: That between any positive number and its
double there is a prime.
The proof follows the outline of the ErdΕs proof presented in "Proofs from THE BOOK": One considers
the prime factorization of `(2 * n).choose n`, and splits the constituent primes up into various
groups, then upper bounds the contribution of each group. This upper bounds the central binomial
coefficient, and if the postulate does not hold, this upper bound conflicts with a simple lower
bound for large enough `n`. This proves the result holds for large enough `n`, and for smaller `n`
an explicit list of primes is provided which covers the remaining cases.
As in the [Metamath implementation](carneiro2015arithmetic), we rely on some optimizations from
[Shigenori Tochiori](tochiori_bertrand). In particular we use the cleaner bound on the central
binomial coefficient given in `Nat.four_pow_lt_mul_centralBinom`.
## References
* [M. Aigner and G. M. Ziegler _Proofs from THE BOOK_][aigner1999proofs]
* [S. Tochiori, _Considering the Proof of βThere is a Prime between n and 2nβ_][tochiori_bertrand]
* [M. Carneiro, _Arithmetic in Metamath, Case Study: Bertrand's Postulate_][carneiro2015arithmetic]
## Tags
Bertrand, prime, binomial coefficients
-/
open scoped BigOperators
section Real
open Real
namespace Bertrand
/-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> norm_num1
apply le_trans _ (le_mul_of_one_le_left _ _) <;> norm_num1
apply Real.rpow_le_rpow <;> norm_num1
apply rpow_nonneg_of_nonneg; norm_num1
apply rpow_pos_of_pos; norm_num1
apply hf' 18; norm_num1
norm_num1
Β· have : sqrt (2 * 512) = 32 :=
(sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonpos_iff (hf' _ _), this, div_le_one] <;> norm_num1
Β· conv in 512 => equals 2 ^ 9 => norm_num1
conv in 1024 => equals 2 ^ 10 => norm_num1
conv in 32 => rw [β Nat.cast_ofNat]
rw [rpow_nat_cast, β pow_mul, β pow_add]
conv in 4 => equals 2 ^ (2 : β) => rw [rpow_two]; norm_num1
rw [β rpow_mul, β rpow_nat_cast]
apply rpow_le_rpow_of_exponent_le
all_goals norm_num1
Β· apply rpow_pos_of_pos four_pos
#align bertrand.real_main_inequality Bertrand.real_main_inequality
end Bertrand
end Real
section Nat
open Nat
/-- The inequality which contradicts Bertrand's postulate, for large enough `n`.
-/
theorem bertrand_main_inequality {n : β} (n_large : 512 β€ n) :
n * (2 * n) ^ sqrt (2 * n) * 4 ^ (2 * n / 3) β€ 4 ^ n := by
rw [β @cast_le β]
simp only [cast_add, cast_one, cast_mul, cast_pow, β Real.rpow_nat_cast]
refine' _root_.trans ?_ (Bertrand.real_main_inequality (by exact_mod_cast n_large))
gcongr
Β· have n2_pos : 0 < 2 * n := by positivity
| exact mod_cast n2_pos | /-- The inequality which contradicts Bertrand's postulate, for large enough `n`.
-/
theorem bertrand_main_inequality {n : β} (n_large : 512 β€ n) :
n * (2 * n) ^ sqrt (2 * n) * 4 ^ (2 * n / 3) β€ 4 ^ n := by
rw [β @cast_le β]
simp only [cast_add, cast_one, cast_mul, cast_pow, β Real.rpow_nat_cast]
refine' _root_.trans ?_ (Bertrand.real_main_inequality (by exact_mod_cast n_large))
gcongr
Β· have n2_pos : 0 < 2 * n := by positivity
| Mathlib.NumberTheory.Bertrand.121_0.gJXoOT9Ce2wC0xc | /-- The inequality which contradicts Bertrand's postulate, for large enough `n`.
-/
theorem bertrand_main_inequality {n : β} (n_large : 512 β€ n) :
n * (2 * n) ^ sqrt (2 * n) * 4 ^ (2 * n / 3) β€ 4 ^ n | Mathlib_NumberTheory_Bertrand |
case hβ.h.hyz
n : β
n_large : 512 β€ n
β’ β(sqrt (2 * n)) β€ Real.sqrt (2 * βn) | /-
Copyright (c) 2020 Patrick Stevens. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Stevens, Bolton Bailey
-/
import Mathlib.Data.Nat.Choose.Factorization
import Mathlib.Data.Nat.PrimeNormNum
import Mathlib.NumberTheory.Primorial
import Mathlib.Analysis.Convex.SpecificFunctions.Basic
import Mathlib.Analysis.Convex.SpecificFunctions.Deriv
#align_import number_theory.bertrand from "leanprover-community/mathlib"@"a16665637b378379689c566204817ae792ac8b39"
/-!
# Bertrand's Postulate
This file contains a proof of Bertrand's postulate: That between any positive number and its
double there is a prime.
The proof follows the outline of the ErdΕs proof presented in "Proofs from THE BOOK": One considers
the prime factorization of `(2 * n).choose n`, and splits the constituent primes up into various
groups, then upper bounds the contribution of each group. This upper bounds the central binomial
coefficient, and if the postulate does not hold, this upper bound conflicts with a simple lower
bound for large enough `n`. This proves the result holds for large enough `n`, and for smaller `n`
an explicit list of primes is provided which covers the remaining cases.
As in the [Metamath implementation](carneiro2015arithmetic), we rely on some optimizations from
[Shigenori Tochiori](tochiori_bertrand). In particular we use the cleaner bound on the central
binomial coefficient given in `Nat.four_pow_lt_mul_centralBinom`.
## References
* [M. Aigner and G. M. Ziegler _Proofs from THE BOOK_][aigner1999proofs]
* [S. Tochiori, _Considering the Proof of βThere is a Prime between n and 2nβ_][tochiori_bertrand]
* [M. Carneiro, _Arithmetic in Metamath, Case Study: Bertrand's Postulate_][carneiro2015arithmetic]
## Tags
Bertrand, prime, binomial coefficients
-/
open scoped BigOperators
section Real
open Real
namespace Bertrand
/-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> norm_num1
apply le_trans _ (le_mul_of_one_le_left _ _) <;> norm_num1
apply Real.rpow_le_rpow <;> norm_num1
apply rpow_nonneg_of_nonneg; norm_num1
apply rpow_pos_of_pos; norm_num1
apply hf' 18; norm_num1
norm_num1
Β· have : sqrt (2 * 512) = 32 :=
(sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonpos_iff (hf' _ _), this, div_le_one] <;> norm_num1
Β· conv in 512 => equals 2 ^ 9 => norm_num1
conv in 1024 => equals 2 ^ 10 => norm_num1
conv in 32 => rw [β Nat.cast_ofNat]
rw [rpow_nat_cast, β pow_mul, β pow_add]
conv in 4 => equals 2 ^ (2 : β) => rw [rpow_two]; norm_num1
rw [β rpow_mul, β rpow_nat_cast]
apply rpow_le_rpow_of_exponent_le
all_goals norm_num1
Β· apply rpow_pos_of_pos four_pos
#align bertrand.real_main_inequality Bertrand.real_main_inequality
end Bertrand
end Real
section Nat
open Nat
/-- The inequality which contradicts Bertrand's postulate, for large enough `n`.
-/
theorem bertrand_main_inequality {n : β} (n_large : 512 β€ n) :
n * (2 * n) ^ sqrt (2 * n) * 4 ^ (2 * n / 3) β€ 4 ^ n := by
rw [β @cast_le β]
simp only [cast_add, cast_one, cast_mul, cast_pow, β Real.rpow_nat_cast]
refine' _root_.trans ?_ (Bertrand.real_main_inequality (by exact_mod_cast n_large))
gcongr
Β· have n2_pos : 0 < 2 * n := by positivity
exact mod_cast n2_pos
Β· | exact_mod_cast Real.nat_sqrt_le_real_sqrt | /-- The inequality which contradicts Bertrand's postulate, for large enough `n`.
-/
theorem bertrand_main_inequality {n : β} (n_large : 512 β€ n) :
n * (2 * n) ^ sqrt (2 * n) * 4 ^ (2 * n / 3) β€ 4 ^ n := by
rw [β @cast_le β]
simp only [cast_add, cast_one, cast_mul, cast_pow, β Real.rpow_nat_cast]
refine' _root_.trans ?_ (Bertrand.real_main_inequality (by exact_mod_cast n_large))
gcongr
Β· have n2_pos : 0 < 2 * n := by positivity
exact mod_cast n2_pos
Β· | Mathlib.NumberTheory.Bertrand.121_0.gJXoOT9Ce2wC0xc | /-- The inequality which contradicts Bertrand's postulate, for large enough `n`.
-/
theorem bertrand_main_inequality {n : β} (n_large : 512 β€ n) :
n * (2 * n) ^ sqrt (2 * n) * 4 ^ (2 * n / 3) β€ 4 ^ n | Mathlib_NumberTheory_Bertrand |
case hβ.hx
n : β
n_large : 512 β€ n
β’ 1 β€ β4 | /-
Copyright (c) 2020 Patrick Stevens. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Stevens, Bolton Bailey
-/
import Mathlib.Data.Nat.Choose.Factorization
import Mathlib.Data.Nat.PrimeNormNum
import Mathlib.NumberTheory.Primorial
import Mathlib.Analysis.Convex.SpecificFunctions.Basic
import Mathlib.Analysis.Convex.SpecificFunctions.Deriv
#align_import number_theory.bertrand from "leanprover-community/mathlib"@"a16665637b378379689c566204817ae792ac8b39"
/-!
# Bertrand's Postulate
This file contains a proof of Bertrand's postulate: That between any positive number and its
double there is a prime.
The proof follows the outline of the ErdΕs proof presented in "Proofs from THE BOOK": One considers
the prime factorization of `(2 * n).choose n`, and splits the constituent primes up into various
groups, then upper bounds the contribution of each group. This upper bounds the central binomial
coefficient, and if the postulate does not hold, this upper bound conflicts with a simple lower
bound for large enough `n`. This proves the result holds for large enough `n`, and for smaller `n`
an explicit list of primes is provided which covers the remaining cases.
As in the [Metamath implementation](carneiro2015arithmetic), we rely on some optimizations from
[Shigenori Tochiori](tochiori_bertrand). In particular we use the cleaner bound on the central
binomial coefficient given in `Nat.four_pow_lt_mul_centralBinom`.
## References
* [M. Aigner and G. M. Ziegler _Proofs from THE BOOK_][aigner1999proofs]
* [S. Tochiori, _Considering the Proof of βThere is a Prime between n and 2nβ_][tochiori_bertrand]
* [M. Carneiro, _Arithmetic in Metamath, Case Study: Bertrand's Postulate_][carneiro2015arithmetic]
## Tags
Bertrand, prime, binomial coefficients
-/
open scoped BigOperators
section Real
open Real
namespace Bertrand
/-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> norm_num1
apply le_trans _ (le_mul_of_one_le_left _ _) <;> norm_num1
apply Real.rpow_le_rpow <;> norm_num1
apply rpow_nonneg_of_nonneg; norm_num1
apply rpow_pos_of_pos; norm_num1
apply hf' 18; norm_num1
norm_num1
Β· have : sqrt (2 * 512) = 32 :=
(sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonpos_iff (hf' _ _), this, div_le_one] <;> norm_num1
Β· conv in 512 => equals 2 ^ 9 => norm_num1
conv in 1024 => equals 2 ^ 10 => norm_num1
conv in 32 => rw [β Nat.cast_ofNat]
rw [rpow_nat_cast, β pow_mul, β pow_add]
conv in 4 => equals 2 ^ (2 : β) => rw [rpow_two]; norm_num1
rw [β rpow_mul, β rpow_nat_cast]
apply rpow_le_rpow_of_exponent_le
all_goals norm_num1
Β· apply rpow_pos_of_pos four_pos
#align bertrand.real_main_inequality Bertrand.real_main_inequality
end Bertrand
end Real
section Nat
open Nat
/-- The inequality which contradicts Bertrand's postulate, for large enough `n`.
-/
theorem bertrand_main_inequality {n : β} (n_large : 512 β€ n) :
n * (2 * n) ^ sqrt (2 * n) * 4 ^ (2 * n / 3) β€ 4 ^ n := by
rw [β @cast_le β]
simp only [cast_add, cast_one, cast_mul, cast_pow, β Real.rpow_nat_cast]
refine' _root_.trans ?_ (Bertrand.real_main_inequality (by exact_mod_cast n_large))
gcongr
Β· have n2_pos : 0 < 2 * n := by positivity
exact mod_cast n2_pos
Β· exact_mod_cast Real.nat_sqrt_le_real_sqrt
Β· | norm_num1 | /-- The inequality which contradicts Bertrand's postulate, for large enough `n`.
-/
theorem bertrand_main_inequality {n : β} (n_large : 512 β€ n) :
n * (2 * n) ^ sqrt (2 * n) * 4 ^ (2 * n / 3) β€ 4 ^ n := by
rw [β @cast_le β]
simp only [cast_add, cast_one, cast_mul, cast_pow, β Real.rpow_nat_cast]
refine' _root_.trans ?_ (Bertrand.real_main_inequality (by exact_mod_cast n_large))
gcongr
Β· have n2_pos : 0 < 2 * n := by positivity
exact mod_cast n2_pos
Β· exact_mod_cast Real.nat_sqrt_le_real_sqrt
Β· | Mathlib.NumberTheory.Bertrand.121_0.gJXoOT9Ce2wC0xc | /-- The inequality which contradicts Bertrand's postulate, for large enough `n`.
-/
theorem bertrand_main_inequality {n : β} (n_large : 512 β€ n) :
n * (2 * n) ^ sqrt (2 * n) * 4 ^ (2 * n / 3) β€ 4 ^ n | Mathlib_NumberTheory_Bertrand |
case hβ.hyz
n : β
n_large : 512 β€ n
β’ β(2 * n / 3) β€ 2 * βn / 3 | /-
Copyright (c) 2020 Patrick Stevens. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Stevens, Bolton Bailey
-/
import Mathlib.Data.Nat.Choose.Factorization
import Mathlib.Data.Nat.PrimeNormNum
import Mathlib.NumberTheory.Primorial
import Mathlib.Analysis.Convex.SpecificFunctions.Basic
import Mathlib.Analysis.Convex.SpecificFunctions.Deriv
#align_import number_theory.bertrand from "leanprover-community/mathlib"@"a16665637b378379689c566204817ae792ac8b39"
/-!
# Bertrand's Postulate
This file contains a proof of Bertrand's postulate: That between any positive number and its
double there is a prime.
The proof follows the outline of the ErdΕs proof presented in "Proofs from THE BOOK": One considers
the prime factorization of `(2 * n).choose n`, and splits the constituent primes up into various
groups, then upper bounds the contribution of each group. This upper bounds the central binomial
coefficient, and if the postulate does not hold, this upper bound conflicts with a simple lower
bound for large enough `n`. This proves the result holds for large enough `n`, and for smaller `n`
an explicit list of primes is provided which covers the remaining cases.
As in the [Metamath implementation](carneiro2015arithmetic), we rely on some optimizations from
[Shigenori Tochiori](tochiori_bertrand). In particular we use the cleaner bound on the central
binomial coefficient given in `Nat.four_pow_lt_mul_centralBinom`.
## References
* [M. Aigner and G. M. Ziegler _Proofs from THE BOOK_][aigner1999proofs]
* [S. Tochiori, _Considering the Proof of βThere is a Prime between n and 2nβ_][tochiori_bertrand]
* [M. Carneiro, _Arithmetic in Metamath, Case Study: Bertrand's Postulate_][carneiro2015arithmetic]
## Tags
Bertrand, prime, binomial coefficients
-/
open scoped BigOperators
section Real
open Real
namespace Bertrand
/-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> norm_num1
apply le_trans _ (le_mul_of_one_le_left _ _) <;> norm_num1
apply Real.rpow_le_rpow <;> norm_num1
apply rpow_nonneg_of_nonneg; norm_num1
apply rpow_pos_of_pos; norm_num1
apply hf' 18; norm_num1
norm_num1
Β· have : sqrt (2 * 512) = 32 :=
(sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonpos_iff (hf' _ _), this, div_le_one] <;> norm_num1
Β· conv in 512 => equals 2 ^ 9 => norm_num1
conv in 1024 => equals 2 ^ 10 => norm_num1
conv in 32 => rw [β Nat.cast_ofNat]
rw [rpow_nat_cast, β pow_mul, β pow_add]
conv in 4 => equals 2 ^ (2 : β) => rw [rpow_two]; norm_num1
rw [β rpow_mul, β rpow_nat_cast]
apply rpow_le_rpow_of_exponent_le
all_goals norm_num1
Β· apply rpow_pos_of_pos four_pos
#align bertrand.real_main_inequality Bertrand.real_main_inequality
end Bertrand
end Real
section Nat
open Nat
/-- The inequality which contradicts Bertrand's postulate, for large enough `n`.
-/
theorem bertrand_main_inequality {n : β} (n_large : 512 β€ n) :
n * (2 * n) ^ sqrt (2 * n) * 4 ^ (2 * n / 3) β€ 4 ^ n := by
rw [β @cast_le β]
simp only [cast_add, cast_one, cast_mul, cast_pow, β Real.rpow_nat_cast]
refine' _root_.trans ?_ (Bertrand.real_main_inequality (by exact_mod_cast n_large))
gcongr
Β· have n2_pos : 0 < 2 * n := by positivity
exact mod_cast n2_pos
Β· exact_mod_cast Real.nat_sqrt_le_real_sqrt
Β· norm_num1
Β· | exact cast_div_le.trans (by norm_cast) | /-- The inequality which contradicts Bertrand's postulate, for large enough `n`.
-/
theorem bertrand_main_inequality {n : β} (n_large : 512 β€ n) :
n * (2 * n) ^ sqrt (2 * n) * 4 ^ (2 * n / 3) β€ 4 ^ n := by
rw [β @cast_le β]
simp only [cast_add, cast_one, cast_mul, cast_pow, β Real.rpow_nat_cast]
refine' _root_.trans ?_ (Bertrand.real_main_inequality (by exact_mod_cast n_large))
gcongr
Β· have n2_pos : 0 < 2 * n := by positivity
exact mod_cast n2_pos
Β· exact_mod_cast Real.nat_sqrt_le_real_sqrt
Β· norm_num1
Β· | Mathlib.NumberTheory.Bertrand.121_0.gJXoOT9Ce2wC0xc | /-- The inequality which contradicts Bertrand's postulate, for large enough `n`.
-/
theorem bertrand_main_inequality {n : β} (n_large : 512 β€ n) :
n * (2 * n) ^ sqrt (2 * n) * 4 ^ (2 * n / 3) β€ 4 ^ n | Mathlib_NumberTheory_Bertrand |
n : β
n_large : 512 β€ n
β’ β(2 * n) / β3 β€ 2 * βn / 3 | /-
Copyright (c) 2020 Patrick Stevens. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Stevens, Bolton Bailey
-/
import Mathlib.Data.Nat.Choose.Factorization
import Mathlib.Data.Nat.PrimeNormNum
import Mathlib.NumberTheory.Primorial
import Mathlib.Analysis.Convex.SpecificFunctions.Basic
import Mathlib.Analysis.Convex.SpecificFunctions.Deriv
#align_import number_theory.bertrand from "leanprover-community/mathlib"@"a16665637b378379689c566204817ae792ac8b39"
/-!
# Bertrand's Postulate
This file contains a proof of Bertrand's postulate: That between any positive number and its
double there is a prime.
The proof follows the outline of the ErdΕs proof presented in "Proofs from THE BOOK": One considers
the prime factorization of `(2 * n).choose n`, and splits the constituent primes up into various
groups, then upper bounds the contribution of each group. This upper bounds the central binomial
coefficient, and if the postulate does not hold, this upper bound conflicts with a simple lower
bound for large enough `n`. This proves the result holds for large enough `n`, and for smaller `n`
an explicit list of primes is provided which covers the remaining cases.
As in the [Metamath implementation](carneiro2015arithmetic), we rely on some optimizations from
[Shigenori Tochiori](tochiori_bertrand). In particular we use the cleaner bound on the central
binomial coefficient given in `Nat.four_pow_lt_mul_centralBinom`.
## References
* [M. Aigner and G. M. Ziegler _Proofs from THE BOOK_][aigner1999proofs]
* [S. Tochiori, _Considering the Proof of βThere is a Prime between n and 2nβ_][tochiori_bertrand]
* [M. Carneiro, _Arithmetic in Metamath, Case Study: Bertrand's Postulate_][carneiro2015arithmetic]
## Tags
Bertrand, prime, binomial coefficients
-/
open scoped BigOperators
section Real
open Real
namespace Bertrand
/-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> norm_num1
apply le_trans _ (le_mul_of_one_le_left _ _) <;> norm_num1
apply Real.rpow_le_rpow <;> norm_num1
apply rpow_nonneg_of_nonneg; norm_num1
apply rpow_pos_of_pos; norm_num1
apply hf' 18; norm_num1
norm_num1
Β· have : sqrt (2 * 512) = 32 :=
(sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonpos_iff (hf' _ _), this, div_le_one] <;> norm_num1
Β· conv in 512 => equals 2 ^ 9 => norm_num1
conv in 1024 => equals 2 ^ 10 => norm_num1
conv in 32 => rw [β Nat.cast_ofNat]
rw [rpow_nat_cast, β pow_mul, β pow_add]
conv in 4 => equals 2 ^ (2 : β) => rw [rpow_two]; norm_num1
rw [β rpow_mul, β rpow_nat_cast]
apply rpow_le_rpow_of_exponent_le
all_goals norm_num1
Β· apply rpow_pos_of_pos four_pos
#align bertrand.real_main_inequality Bertrand.real_main_inequality
end Bertrand
end Real
section Nat
open Nat
/-- The inequality which contradicts Bertrand's postulate, for large enough `n`.
-/
theorem bertrand_main_inequality {n : β} (n_large : 512 β€ n) :
n * (2 * n) ^ sqrt (2 * n) * 4 ^ (2 * n / 3) β€ 4 ^ n := by
rw [β @cast_le β]
simp only [cast_add, cast_one, cast_mul, cast_pow, β Real.rpow_nat_cast]
refine' _root_.trans ?_ (Bertrand.real_main_inequality (by exact_mod_cast n_large))
gcongr
Β· have n2_pos : 0 < 2 * n := by positivity
exact mod_cast n2_pos
Β· exact_mod_cast Real.nat_sqrt_le_real_sqrt
Β· norm_num1
Β· exact cast_div_le.trans (by | norm_cast | /-- The inequality which contradicts Bertrand's postulate, for large enough `n`.
-/
theorem bertrand_main_inequality {n : β} (n_large : 512 β€ n) :
n * (2 * n) ^ sqrt (2 * n) * 4 ^ (2 * n / 3) β€ 4 ^ n := by
rw [β @cast_le β]
simp only [cast_add, cast_one, cast_mul, cast_pow, β Real.rpow_nat_cast]
refine' _root_.trans ?_ (Bertrand.real_main_inequality (by exact_mod_cast n_large))
gcongr
Β· have n2_pos : 0 < 2 * n := by positivity
exact mod_cast n2_pos
Β· exact_mod_cast Real.nat_sqrt_le_real_sqrt
Β· norm_num1
Β· exact cast_div_le.trans (by | Mathlib.NumberTheory.Bertrand.121_0.gJXoOT9Ce2wC0xc | /-- The inequality which contradicts Bertrand's postulate, for large enough `n`.
-/
theorem bertrand_main_inequality {n : β} (n_large : 512 β€ n) :
n * (2 * n) ^ sqrt (2 * n) * 4 ^ (2 * n / 3) β€ 4 ^ n | Mathlib_NumberTheory_Bertrand |
n : β
n_large : 2 < n
no_prime : Β¬β p, Nat.Prime p β§ n < p β§ p β€ 2 * n
β’ centralBinom n = β p in Finset.range (2 * n / 3 + 1), p ^ (Nat.factorization (centralBinom n)) p | /-
Copyright (c) 2020 Patrick Stevens. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Stevens, Bolton Bailey
-/
import Mathlib.Data.Nat.Choose.Factorization
import Mathlib.Data.Nat.PrimeNormNum
import Mathlib.NumberTheory.Primorial
import Mathlib.Analysis.Convex.SpecificFunctions.Basic
import Mathlib.Analysis.Convex.SpecificFunctions.Deriv
#align_import number_theory.bertrand from "leanprover-community/mathlib"@"a16665637b378379689c566204817ae792ac8b39"
/-!
# Bertrand's Postulate
This file contains a proof of Bertrand's postulate: That between any positive number and its
double there is a prime.
The proof follows the outline of the ErdΕs proof presented in "Proofs from THE BOOK": One considers
the prime factorization of `(2 * n).choose n`, and splits the constituent primes up into various
groups, then upper bounds the contribution of each group. This upper bounds the central binomial
coefficient, and if the postulate does not hold, this upper bound conflicts with a simple lower
bound for large enough `n`. This proves the result holds for large enough `n`, and for smaller `n`
an explicit list of primes is provided which covers the remaining cases.
As in the [Metamath implementation](carneiro2015arithmetic), we rely on some optimizations from
[Shigenori Tochiori](tochiori_bertrand). In particular we use the cleaner bound on the central
binomial coefficient given in `Nat.four_pow_lt_mul_centralBinom`.
## References
* [M. Aigner and G. M. Ziegler _Proofs from THE BOOK_][aigner1999proofs]
* [S. Tochiori, _Considering the Proof of βThere is a Prime between n and 2nβ_][tochiori_bertrand]
* [M. Carneiro, _Arithmetic in Metamath, Case Study: Bertrand's Postulate_][carneiro2015arithmetic]
## Tags
Bertrand, prime, binomial coefficients
-/
open scoped BigOperators
section Real
open Real
namespace Bertrand
/-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> norm_num1
apply le_trans _ (le_mul_of_one_le_left _ _) <;> norm_num1
apply Real.rpow_le_rpow <;> norm_num1
apply rpow_nonneg_of_nonneg; norm_num1
apply rpow_pos_of_pos; norm_num1
apply hf' 18; norm_num1
norm_num1
Β· have : sqrt (2 * 512) = 32 :=
(sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonpos_iff (hf' _ _), this, div_le_one] <;> norm_num1
Β· conv in 512 => equals 2 ^ 9 => norm_num1
conv in 1024 => equals 2 ^ 10 => norm_num1
conv in 32 => rw [β Nat.cast_ofNat]
rw [rpow_nat_cast, β pow_mul, β pow_add]
conv in 4 => equals 2 ^ (2 : β) => rw [rpow_two]; norm_num1
rw [β rpow_mul, β rpow_nat_cast]
apply rpow_le_rpow_of_exponent_le
all_goals norm_num1
Β· apply rpow_pos_of_pos four_pos
#align bertrand.real_main_inequality Bertrand.real_main_inequality
end Bertrand
end Real
section Nat
open Nat
/-- The inequality which contradicts Bertrand's postulate, for large enough `n`.
-/
theorem bertrand_main_inequality {n : β} (n_large : 512 β€ n) :
n * (2 * n) ^ sqrt (2 * n) * 4 ^ (2 * n / 3) β€ 4 ^ n := by
rw [β @cast_le β]
simp only [cast_add, cast_one, cast_mul, cast_pow, β Real.rpow_nat_cast]
refine' _root_.trans ?_ (Bertrand.real_main_inequality (by exact_mod_cast n_large))
gcongr
Β· have n2_pos : 0 < 2 * n := by positivity
exact mod_cast n2_pos
Β· exact_mod_cast Real.nat_sqrt_le_real_sqrt
Β· norm_num1
Β· exact cast_div_le.trans (by norm_cast)
#align bertrand_main_inequality bertrand_main_inequality
/-- A lemma that tells us that, in the case where Bertrand's postulate does not hold, the prime
factorization of the central binomial coefficent only has factors at most `2 * n / 3 + 1`.
-/
theorem centralBinom_factorization_small (n : β) (n_large : 2 < n)
(no_prime : Β¬β p : β, p.Prime β§ n < p β§ p β€ 2 * n) :
centralBinom n = β p in Finset.range (2 * n / 3 + 1), p ^ (centralBinom n).factorization p := by
| refine' (Eq.trans _ n.prod_pow_factorization_centralBinom).symm | /-- A lemma that tells us that, in the case where Bertrand's postulate does not hold, the prime
factorization of the central binomial coefficent only has factors at most `2 * n / 3 + 1`.
-/
theorem centralBinom_factorization_small (n : β) (n_large : 2 < n)
(no_prime : Β¬β p : β, p.Prime β§ n < p β§ p β€ 2 * n) :
centralBinom n = β p in Finset.range (2 * n / 3 + 1), p ^ (centralBinom n).factorization p := by
| Mathlib.NumberTheory.Bertrand.136_0.gJXoOT9Ce2wC0xc | /-- A lemma that tells us that, in the case where Bertrand's postulate does not hold, the prime
factorization of the central binomial coefficent only has factors at most `2 * n / 3 + 1`.
-/
theorem centralBinom_factorization_small (n : β) (n_large : 2 < n)
(no_prime : Β¬β p : β, p.Prime β§ n < p β§ p β€ 2 * n) :
centralBinom n = β p in Finset.range (2 * n / 3 + 1), p ^ (centralBinom n).factorization p | Mathlib_NumberTheory_Bertrand |
n : β
n_large : 2 < n
no_prime : Β¬β p, Nat.Prime p β§ n < p β§ p β€ 2 * n
β’ β p in Finset.range (2 * n / 3 + 1), p ^ (Nat.factorization (centralBinom n)) p =
β p in Finset.range (2 * n + 1), p ^ (Nat.factorization (centralBinom n)) p | /-
Copyright (c) 2020 Patrick Stevens. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Stevens, Bolton Bailey
-/
import Mathlib.Data.Nat.Choose.Factorization
import Mathlib.Data.Nat.PrimeNormNum
import Mathlib.NumberTheory.Primorial
import Mathlib.Analysis.Convex.SpecificFunctions.Basic
import Mathlib.Analysis.Convex.SpecificFunctions.Deriv
#align_import number_theory.bertrand from "leanprover-community/mathlib"@"a16665637b378379689c566204817ae792ac8b39"
/-!
# Bertrand's Postulate
This file contains a proof of Bertrand's postulate: That between any positive number and its
double there is a prime.
The proof follows the outline of the ErdΕs proof presented in "Proofs from THE BOOK": One considers
the prime factorization of `(2 * n).choose n`, and splits the constituent primes up into various
groups, then upper bounds the contribution of each group. This upper bounds the central binomial
coefficient, and if the postulate does not hold, this upper bound conflicts with a simple lower
bound for large enough `n`. This proves the result holds for large enough `n`, and for smaller `n`
an explicit list of primes is provided which covers the remaining cases.
As in the [Metamath implementation](carneiro2015arithmetic), we rely on some optimizations from
[Shigenori Tochiori](tochiori_bertrand). In particular we use the cleaner bound on the central
binomial coefficient given in `Nat.four_pow_lt_mul_centralBinom`.
## References
* [M. Aigner and G. M. Ziegler _Proofs from THE BOOK_][aigner1999proofs]
* [S. Tochiori, _Considering the Proof of βThere is a Prime between n and 2nβ_][tochiori_bertrand]
* [M. Carneiro, _Arithmetic in Metamath, Case Study: Bertrand's Postulate_][carneiro2015arithmetic]
## Tags
Bertrand, prime, binomial coefficients
-/
open scoped BigOperators
section Real
open Real
namespace Bertrand
/-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> norm_num1
apply le_trans _ (le_mul_of_one_le_left _ _) <;> norm_num1
apply Real.rpow_le_rpow <;> norm_num1
apply rpow_nonneg_of_nonneg; norm_num1
apply rpow_pos_of_pos; norm_num1
apply hf' 18; norm_num1
norm_num1
Β· have : sqrt (2 * 512) = 32 :=
(sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonpos_iff (hf' _ _), this, div_le_one] <;> norm_num1
Β· conv in 512 => equals 2 ^ 9 => norm_num1
conv in 1024 => equals 2 ^ 10 => norm_num1
conv in 32 => rw [β Nat.cast_ofNat]
rw [rpow_nat_cast, β pow_mul, β pow_add]
conv in 4 => equals 2 ^ (2 : β) => rw [rpow_two]; norm_num1
rw [β rpow_mul, β rpow_nat_cast]
apply rpow_le_rpow_of_exponent_le
all_goals norm_num1
Β· apply rpow_pos_of_pos four_pos
#align bertrand.real_main_inequality Bertrand.real_main_inequality
end Bertrand
end Real
section Nat
open Nat
/-- The inequality which contradicts Bertrand's postulate, for large enough `n`.
-/
theorem bertrand_main_inequality {n : β} (n_large : 512 β€ n) :
n * (2 * n) ^ sqrt (2 * n) * 4 ^ (2 * n / 3) β€ 4 ^ n := by
rw [β @cast_le β]
simp only [cast_add, cast_one, cast_mul, cast_pow, β Real.rpow_nat_cast]
refine' _root_.trans ?_ (Bertrand.real_main_inequality (by exact_mod_cast n_large))
gcongr
Β· have n2_pos : 0 < 2 * n := by positivity
exact mod_cast n2_pos
Β· exact_mod_cast Real.nat_sqrt_le_real_sqrt
Β· norm_num1
Β· exact cast_div_le.trans (by norm_cast)
#align bertrand_main_inequality bertrand_main_inequality
/-- A lemma that tells us that, in the case where Bertrand's postulate does not hold, the prime
factorization of the central binomial coefficent only has factors at most `2 * n / 3 + 1`.
-/
theorem centralBinom_factorization_small (n : β) (n_large : 2 < n)
(no_prime : Β¬β p : β, p.Prime β§ n < p β§ p β€ 2 * n) :
centralBinom n = β p in Finset.range (2 * n / 3 + 1), p ^ (centralBinom n).factorization p := by
refine' (Eq.trans _ n.prod_pow_factorization_centralBinom).symm
| apply Finset.prod_subset | /-- A lemma that tells us that, in the case where Bertrand's postulate does not hold, the prime
factorization of the central binomial coefficent only has factors at most `2 * n / 3 + 1`.
-/
theorem centralBinom_factorization_small (n : β) (n_large : 2 < n)
(no_prime : Β¬β p : β, p.Prime β§ n < p β§ p β€ 2 * n) :
centralBinom n = β p in Finset.range (2 * n / 3 + 1), p ^ (centralBinom n).factorization p := by
refine' (Eq.trans _ n.prod_pow_factorization_centralBinom).symm
| Mathlib.NumberTheory.Bertrand.136_0.gJXoOT9Ce2wC0xc | /-- A lemma that tells us that, in the case where Bertrand's postulate does not hold, the prime
factorization of the central binomial coefficent only has factors at most `2 * n / 3 + 1`.
-/
theorem centralBinom_factorization_small (n : β) (n_large : 2 < n)
(no_prime : Β¬β p : β, p.Prime β§ n < p β§ p β€ 2 * n) :
centralBinom n = β p in Finset.range (2 * n / 3 + 1), p ^ (centralBinom n).factorization p | Mathlib_NumberTheory_Bertrand |
case h
n : β
n_large : 2 < n
no_prime : Β¬β p, Nat.Prime p β§ n < p β§ p β€ 2 * n
β’ Finset.range (2 * n / 3 + 1) β Finset.range (2 * n + 1) | /-
Copyright (c) 2020 Patrick Stevens. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Stevens, Bolton Bailey
-/
import Mathlib.Data.Nat.Choose.Factorization
import Mathlib.Data.Nat.PrimeNormNum
import Mathlib.NumberTheory.Primorial
import Mathlib.Analysis.Convex.SpecificFunctions.Basic
import Mathlib.Analysis.Convex.SpecificFunctions.Deriv
#align_import number_theory.bertrand from "leanprover-community/mathlib"@"a16665637b378379689c566204817ae792ac8b39"
/-!
# Bertrand's Postulate
This file contains a proof of Bertrand's postulate: That between any positive number and its
double there is a prime.
The proof follows the outline of the ErdΕs proof presented in "Proofs from THE BOOK": One considers
the prime factorization of `(2 * n).choose n`, and splits the constituent primes up into various
groups, then upper bounds the contribution of each group. This upper bounds the central binomial
coefficient, and if the postulate does not hold, this upper bound conflicts with a simple lower
bound for large enough `n`. This proves the result holds for large enough `n`, and for smaller `n`
an explicit list of primes is provided which covers the remaining cases.
As in the [Metamath implementation](carneiro2015arithmetic), we rely on some optimizations from
[Shigenori Tochiori](tochiori_bertrand). In particular we use the cleaner bound on the central
binomial coefficient given in `Nat.four_pow_lt_mul_centralBinom`.
## References
* [M. Aigner and G. M. Ziegler _Proofs from THE BOOK_][aigner1999proofs]
* [S. Tochiori, _Considering the Proof of βThere is a Prime between n and 2nβ_][tochiori_bertrand]
* [M. Carneiro, _Arithmetic in Metamath, Case Study: Bertrand's Postulate_][carneiro2015arithmetic]
## Tags
Bertrand, prime, binomial coefficients
-/
open scoped BigOperators
section Real
open Real
namespace Bertrand
/-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> norm_num1
apply le_trans _ (le_mul_of_one_le_left _ _) <;> norm_num1
apply Real.rpow_le_rpow <;> norm_num1
apply rpow_nonneg_of_nonneg; norm_num1
apply rpow_pos_of_pos; norm_num1
apply hf' 18; norm_num1
norm_num1
Β· have : sqrt (2 * 512) = 32 :=
(sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonpos_iff (hf' _ _), this, div_le_one] <;> norm_num1
Β· conv in 512 => equals 2 ^ 9 => norm_num1
conv in 1024 => equals 2 ^ 10 => norm_num1
conv in 32 => rw [β Nat.cast_ofNat]
rw [rpow_nat_cast, β pow_mul, β pow_add]
conv in 4 => equals 2 ^ (2 : β) => rw [rpow_two]; norm_num1
rw [β rpow_mul, β rpow_nat_cast]
apply rpow_le_rpow_of_exponent_le
all_goals norm_num1
Β· apply rpow_pos_of_pos four_pos
#align bertrand.real_main_inequality Bertrand.real_main_inequality
end Bertrand
end Real
section Nat
open Nat
/-- The inequality which contradicts Bertrand's postulate, for large enough `n`.
-/
theorem bertrand_main_inequality {n : β} (n_large : 512 β€ n) :
n * (2 * n) ^ sqrt (2 * n) * 4 ^ (2 * n / 3) β€ 4 ^ n := by
rw [β @cast_le β]
simp only [cast_add, cast_one, cast_mul, cast_pow, β Real.rpow_nat_cast]
refine' _root_.trans ?_ (Bertrand.real_main_inequality (by exact_mod_cast n_large))
gcongr
Β· have n2_pos : 0 < 2 * n := by positivity
exact mod_cast n2_pos
Β· exact_mod_cast Real.nat_sqrt_le_real_sqrt
Β· norm_num1
Β· exact cast_div_le.trans (by norm_cast)
#align bertrand_main_inequality bertrand_main_inequality
/-- A lemma that tells us that, in the case where Bertrand's postulate does not hold, the prime
factorization of the central binomial coefficent only has factors at most `2 * n / 3 + 1`.
-/
theorem centralBinom_factorization_small (n : β) (n_large : 2 < n)
(no_prime : Β¬β p : β, p.Prime β§ n < p β§ p β€ 2 * n) :
centralBinom n = β p in Finset.range (2 * n / 3 + 1), p ^ (centralBinom n).factorization p := by
refine' (Eq.trans _ n.prod_pow_factorization_centralBinom).symm
apply Finset.prod_subset
Β· | exact Finset.range_subset.2 (add_le_add_right (Nat.div_le_self _ _) _) | /-- A lemma that tells us that, in the case where Bertrand's postulate does not hold, the prime
factorization of the central binomial coefficent only has factors at most `2 * n / 3 + 1`.
-/
theorem centralBinom_factorization_small (n : β) (n_large : 2 < n)
(no_prime : Β¬β p : β, p.Prime β§ n < p β§ p β€ 2 * n) :
centralBinom n = β p in Finset.range (2 * n / 3 + 1), p ^ (centralBinom n).factorization p := by
refine' (Eq.trans _ n.prod_pow_factorization_centralBinom).symm
apply Finset.prod_subset
Β· | Mathlib.NumberTheory.Bertrand.136_0.gJXoOT9Ce2wC0xc | /-- A lemma that tells us that, in the case where Bertrand's postulate does not hold, the prime
factorization of the central binomial coefficent only has factors at most `2 * n / 3 + 1`.
-/
theorem centralBinom_factorization_small (n : β) (n_large : 2 < n)
(no_prime : Β¬β p : β, p.Prime β§ n < p β§ p β€ 2 * n) :
centralBinom n = β p in Finset.range (2 * n / 3 + 1), p ^ (centralBinom n).factorization p | Mathlib_NumberTheory_Bertrand |
case hf
n : β
n_large : 2 < n
no_prime : Β¬β p, Nat.Prime p β§ n < p β§ p β€ 2 * n
β’ β x β Finset.range (2 * n + 1), x β Finset.range (2 * n / 3 + 1) β x ^ (Nat.factorization (centralBinom n)) x = 1 | /-
Copyright (c) 2020 Patrick Stevens. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Stevens, Bolton Bailey
-/
import Mathlib.Data.Nat.Choose.Factorization
import Mathlib.Data.Nat.PrimeNormNum
import Mathlib.NumberTheory.Primorial
import Mathlib.Analysis.Convex.SpecificFunctions.Basic
import Mathlib.Analysis.Convex.SpecificFunctions.Deriv
#align_import number_theory.bertrand from "leanprover-community/mathlib"@"a16665637b378379689c566204817ae792ac8b39"
/-!
# Bertrand's Postulate
This file contains a proof of Bertrand's postulate: That between any positive number and its
double there is a prime.
The proof follows the outline of the ErdΕs proof presented in "Proofs from THE BOOK": One considers
the prime factorization of `(2 * n).choose n`, and splits the constituent primes up into various
groups, then upper bounds the contribution of each group. This upper bounds the central binomial
coefficient, and if the postulate does not hold, this upper bound conflicts with a simple lower
bound for large enough `n`. This proves the result holds for large enough `n`, and for smaller `n`
an explicit list of primes is provided which covers the remaining cases.
As in the [Metamath implementation](carneiro2015arithmetic), we rely on some optimizations from
[Shigenori Tochiori](tochiori_bertrand). In particular we use the cleaner bound on the central
binomial coefficient given in `Nat.four_pow_lt_mul_centralBinom`.
## References
* [M. Aigner and G. M. Ziegler _Proofs from THE BOOK_][aigner1999proofs]
* [S. Tochiori, _Considering the Proof of βThere is a Prime between n and 2nβ_][tochiori_bertrand]
* [M. Carneiro, _Arithmetic in Metamath, Case Study: Bertrand's Postulate_][carneiro2015arithmetic]
## Tags
Bertrand, prime, binomial coefficients
-/
open scoped BigOperators
section Real
open Real
namespace Bertrand
/-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> norm_num1
apply le_trans _ (le_mul_of_one_le_left _ _) <;> norm_num1
apply Real.rpow_le_rpow <;> norm_num1
apply rpow_nonneg_of_nonneg; norm_num1
apply rpow_pos_of_pos; norm_num1
apply hf' 18; norm_num1
norm_num1
Β· have : sqrt (2 * 512) = 32 :=
(sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonpos_iff (hf' _ _), this, div_le_one] <;> norm_num1
Β· conv in 512 => equals 2 ^ 9 => norm_num1
conv in 1024 => equals 2 ^ 10 => norm_num1
conv in 32 => rw [β Nat.cast_ofNat]
rw [rpow_nat_cast, β pow_mul, β pow_add]
conv in 4 => equals 2 ^ (2 : β) => rw [rpow_two]; norm_num1
rw [β rpow_mul, β rpow_nat_cast]
apply rpow_le_rpow_of_exponent_le
all_goals norm_num1
Β· apply rpow_pos_of_pos four_pos
#align bertrand.real_main_inequality Bertrand.real_main_inequality
end Bertrand
end Real
section Nat
open Nat
/-- The inequality which contradicts Bertrand's postulate, for large enough `n`.
-/
theorem bertrand_main_inequality {n : β} (n_large : 512 β€ n) :
n * (2 * n) ^ sqrt (2 * n) * 4 ^ (2 * n / 3) β€ 4 ^ n := by
rw [β @cast_le β]
simp only [cast_add, cast_one, cast_mul, cast_pow, β Real.rpow_nat_cast]
refine' _root_.trans ?_ (Bertrand.real_main_inequality (by exact_mod_cast n_large))
gcongr
Β· have n2_pos : 0 < 2 * n := by positivity
exact mod_cast n2_pos
Β· exact_mod_cast Real.nat_sqrt_le_real_sqrt
Β· norm_num1
Β· exact cast_div_le.trans (by norm_cast)
#align bertrand_main_inequality bertrand_main_inequality
/-- A lemma that tells us that, in the case where Bertrand's postulate does not hold, the prime
factorization of the central binomial coefficent only has factors at most `2 * n / 3 + 1`.
-/
theorem centralBinom_factorization_small (n : β) (n_large : 2 < n)
(no_prime : Β¬β p : β, p.Prime β§ n < p β§ p β€ 2 * n) :
centralBinom n = β p in Finset.range (2 * n / 3 + 1), p ^ (centralBinom n).factorization p := by
refine' (Eq.trans _ n.prod_pow_factorization_centralBinom).symm
apply Finset.prod_subset
Β· exact Finset.range_subset.2 (add_le_add_right (Nat.div_le_self _ _) _)
| intro x hx h2x | /-- A lemma that tells us that, in the case where Bertrand's postulate does not hold, the prime
factorization of the central binomial coefficent only has factors at most `2 * n / 3 + 1`.
-/
theorem centralBinom_factorization_small (n : β) (n_large : 2 < n)
(no_prime : Β¬β p : β, p.Prime β§ n < p β§ p β€ 2 * n) :
centralBinom n = β p in Finset.range (2 * n / 3 + 1), p ^ (centralBinom n).factorization p := by
refine' (Eq.trans _ n.prod_pow_factorization_centralBinom).symm
apply Finset.prod_subset
Β· exact Finset.range_subset.2 (add_le_add_right (Nat.div_le_self _ _) _)
| Mathlib.NumberTheory.Bertrand.136_0.gJXoOT9Ce2wC0xc | /-- A lemma that tells us that, in the case where Bertrand's postulate does not hold, the prime
factorization of the central binomial coefficent only has factors at most `2 * n / 3 + 1`.
-/
theorem centralBinom_factorization_small (n : β) (n_large : 2 < n)
(no_prime : Β¬β p : β, p.Prime β§ n < p β§ p β€ 2 * n) :
centralBinom n = β p in Finset.range (2 * n / 3 + 1), p ^ (centralBinom n).factorization p | Mathlib_NumberTheory_Bertrand |
case hf
n : β
n_large : 2 < n
no_prime : Β¬β p, Nat.Prime p β§ n < p β§ p β€ 2 * n
x : β
hx : x β Finset.range (2 * n + 1)
h2x : x β Finset.range (2 * n / 3 + 1)
β’ x ^ (Nat.factorization (centralBinom n)) x = 1 | /-
Copyright (c) 2020 Patrick Stevens. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Stevens, Bolton Bailey
-/
import Mathlib.Data.Nat.Choose.Factorization
import Mathlib.Data.Nat.PrimeNormNum
import Mathlib.NumberTheory.Primorial
import Mathlib.Analysis.Convex.SpecificFunctions.Basic
import Mathlib.Analysis.Convex.SpecificFunctions.Deriv
#align_import number_theory.bertrand from "leanprover-community/mathlib"@"a16665637b378379689c566204817ae792ac8b39"
/-!
# Bertrand's Postulate
This file contains a proof of Bertrand's postulate: That between any positive number and its
double there is a prime.
The proof follows the outline of the ErdΕs proof presented in "Proofs from THE BOOK": One considers
the prime factorization of `(2 * n).choose n`, and splits the constituent primes up into various
groups, then upper bounds the contribution of each group. This upper bounds the central binomial
coefficient, and if the postulate does not hold, this upper bound conflicts with a simple lower
bound for large enough `n`. This proves the result holds for large enough `n`, and for smaller `n`
an explicit list of primes is provided which covers the remaining cases.
As in the [Metamath implementation](carneiro2015arithmetic), we rely on some optimizations from
[Shigenori Tochiori](tochiori_bertrand). In particular we use the cleaner bound on the central
binomial coefficient given in `Nat.four_pow_lt_mul_centralBinom`.
## References
* [M. Aigner and G. M. Ziegler _Proofs from THE BOOK_][aigner1999proofs]
* [S. Tochiori, _Considering the Proof of βThere is a Prime between n and 2nβ_][tochiori_bertrand]
* [M. Carneiro, _Arithmetic in Metamath, Case Study: Bertrand's Postulate_][carneiro2015arithmetic]
## Tags
Bertrand, prime, binomial coefficients
-/
open scoped BigOperators
section Real
open Real
namespace Bertrand
/-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> norm_num1
apply le_trans _ (le_mul_of_one_le_left _ _) <;> norm_num1
apply Real.rpow_le_rpow <;> norm_num1
apply rpow_nonneg_of_nonneg; norm_num1
apply rpow_pos_of_pos; norm_num1
apply hf' 18; norm_num1
norm_num1
Β· have : sqrt (2 * 512) = 32 :=
(sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonpos_iff (hf' _ _), this, div_le_one] <;> norm_num1
Β· conv in 512 => equals 2 ^ 9 => norm_num1
conv in 1024 => equals 2 ^ 10 => norm_num1
conv in 32 => rw [β Nat.cast_ofNat]
rw [rpow_nat_cast, β pow_mul, β pow_add]
conv in 4 => equals 2 ^ (2 : β) => rw [rpow_two]; norm_num1
rw [β rpow_mul, β rpow_nat_cast]
apply rpow_le_rpow_of_exponent_le
all_goals norm_num1
Β· apply rpow_pos_of_pos four_pos
#align bertrand.real_main_inequality Bertrand.real_main_inequality
end Bertrand
end Real
section Nat
open Nat
/-- The inequality which contradicts Bertrand's postulate, for large enough `n`.
-/
theorem bertrand_main_inequality {n : β} (n_large : 512 β€ n) :
n * (2 * n) ^ sqrt (2 * n) * 4 ^ (2 * n / 3) β€ 4 ^ n := by
rw [β @cast_le β]
simp only [cast_add, cast_one, cast_mul, cast_pow, β Real.rpow_nat_cast]
refine' _root_.trans ?_ (Bertrand.real_main_inequality (by exact_mod_cast n_large))
gcongr
Β· have n2_pos : 0 < 2 * n := by positivity
exact mod_cast n2_pos
Β· exact_mod_cast Real.nat_sqrt_le_real_sqrt
Β· norm_num1
Β· exact cast_div_le.trans (by norm_cast)
#align bertrand_main_inequality bertrand_main_inequality
/-- A lemma that tells us that, in the case where Bertrand's postulate does not hold, the prime
factorization of the central binomial coefficent only has factors at most `2 * n / 3 + 1`.
-/
theorem centralBinom_factorization_small (n : β) (n_large : 2 < n)
(no_prime : Β¬β p : β, p.Prime β§ n < p β§ p β€ 2 * n) :
centralBinom n = β p in Finset.range (2 * n / 3 + 1), p ^ (centralBinom n).factorization p := by
refine' (Eq.trans _ n.prod_pow_factorization_centralBinom).symm
apply Finset.prod_subset
Β· exact Finset.range_subset.2 (add_le_add_right (Nat.div_le_self _ _) _)
intro x hx h2x
| rw [Finset.mem_range, lt_succ_iff] at hx h2x | /-- A lemma that tells us that, in the case where Bertrand's postulate does not hold, the prime
factorization of the central binomial coefficent only has factors at most `2 * n / 3 + 1`.
-/
theorem centralBinom_factorization_small (n : β) (n_large : 2 < n)
(no_prime : Β¬β p : β, p.Prime β§ n < p β§ p β€ 2 * n) :
centralBinom n = β p in Finset.range (2 * n / 3 + 1), p ^ (centralBinom n).factorization p := by
refine' (Eq.trans _ n.prod_pow_factorization_centralBinom).symm
apply Finset.prod_subset
Β· exact Finset.range_subset.2 (add_le_add_right (Nat.div_le_self _ _) _)
intro x hx h2x
| Mathlib.NumberTheory.Bertrand.136_0.gJXoOT9Ce2wC0xc | /-- A lemma that tells us that, in the case where Bertrand's postulate does not hold, the prime
factorization of the central binomial coefficent only has factors at most `2 * n / 3 + 1`.
-/
theorem centralBinom_factorization_small (n : β) (n_large : 2 < n)
(no_prime : Β¬β p : β, p.Prime β§ n < p β§ p β€ 2 * n) :
centralBinom n = β p in Finset.range (2 * n / 3 + 1), p ^ (centralBinom n).factorization p | Mathlib_NumberTheory_Bertrand |
case hf
n : β
n_large : 2 < n
no_prime : Β¬β p, Nat.Prime p β§ n < p β§ p β€ 2 * n
x : β
hx : x β€ 2 * n
h2x : Β¬x β€ 2 * n / 3
β’ x ^ (Nat.factorization (centralBinom n)) x = 1 | /-
Copyright (c) 2020 Patrick Stevens. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Stevens, Bolton Bailey
-/
import Mathlib.Data.Nat.Choose.Factorization
import Mathlib.Data.Nat.PrimeNormNum
import Mathlib.NumberTheory.Primorial
import Mathlib.Analysis.Convex.SpecificFunctions.Basic
import Mathlib.Analysis.Convex.SpecificFunctions.Deriv
#align_import number_theory.bertrand from "leanprover-community/mathlib"@"a16665637b378379689c566204817ae792ac8b39"
/-!
# Bertrand's Postulate
This file contains a proof of Bertrand's postulate: That between any positive number and its
double there is a prime.
The proof follows the outline of the ErdΕs proof presented in "Proofs from THE BOOK": One considers
the prime factorization of `(2 * n).choose n`, and splits the constituent primes up into various
groups, then upper bounds the contribution of each group. This upper bounds the central binomial
coefficient, and if the postulate does not hold, this upper bound conflicts with a simple lower
bound for large enough `n`. This proves the result holds for large enough `n`, and for smaller `n`
an explicit list of primes is provided which covers the remaining cases.
As in the [Metamath implementation](carneiro2015arithmetic), we rely on some optimizations from
[Shigenori Tochiori](tochiori_bertrand). In particular we use the cleaner bound on the central
binomial coefficient given in `Nat.four_pow_lt_mul_centralBinom`.
## References
* [M. Aigner and G. M. Ziegler _Proofs from THE BOOK_][aigner1999proofs]
* [S. Tochiori, _Considering the Proof of βThere is a Prime between n and 2nβ_][tochiori_bertrand]
* [M. Carneiro, _Arithmetic in Metamath, Case Study: Bertrand's Postulate_][carneiro2015arithmetic]
## Tags
Bertrand, prime, binomial coefficients
-/
open scoped BigOperators
section Real
open Real
namespace Bertrand
/-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> norm_num1
apply le_trans _ (le_mul_of_one_le_left _ _) <;> norm_num1
apply Real.rpow_le_rpow <;> norm_num1
apply rpow_nonneg_of_nonneg; norm_num1
apply rpow_pos_of_pos; norm_num1
apply hf' 18; norm_num1
norm_num1
Β· have : sqrt (2 * 512) = 32 :=
(sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonpos_iff (hf' _ _), this, div_le_one] <;> norm_num1
Β· conv in 512 => equals 2 ^ 9 => norm_num1
conv in 1024 => equals 2 ^ 10 => norm_num1
conv in 32 => rw [β Nat.cast_ofNat]
rw [rpow_nat_cast, β pow_mul, β pow_add]
conv in 4 => equals 2 ^ (2 : β) => rw [rpow_two]; norm_num1
rw [β rpow_mul, β rpow_nat_cast]
apply rpow_le_rpow_of_exponent_le
all_goals norm_num1
Β· apply rpow_pos_of_pos four_pos
#align bertrand.real_main_inequality Bertrand.real_main_inequality
end Bertrand
end Real
section Nat
open Nat
/-- The inequality which contradicts Bertrand's postulate, for large enough `n`.
-/
theorem bertrand_main_inequality {n : β} (n_large : 512 β€ n) :
n * (2 * n) ^ sqrt (2 * n) * 4 ^ (2 * n / 3) β€ 4 ^ n := by
rw [β @cast_le β]
simp only [cast_add, cast_one, cast_mul, cast_pow, β Real.rpow_nat_cast]
refine' _root_.trans ?_ (Bertrand.real_main_inequality (by exact_mod_cast n_large))
gcongr
Β· have n2_pos : 0 < 2 * n := by positivity
exact mod_cast n2_pos
Β· exact_mod_cast Real.nat_sqrt_le_real_sqrt
Β· norm_num1
Β· exact cast_div_le.trans (by norm_cast)
#align bertrand_main_inequality bertrand_main_inequality
/-- A lemma that tells us that, in the case where Bertrand's postulate does not hold, the prime
factorization of the central binomial coefficent only has factors at most `2 * n / 3 + 1`.
-/
theorem centralBinom_factorization_small (n : β) (n_large : 2 < n)
(no_prime : Β¬β p : β, p.Prime β§ n < p β§ p β€ 2 * n) :
centralBinom n = β p in Finset.range (2 * n / 3 + 1), p ^ (centralBinom n).factorization p := by
refine' (Eq.trans _ n.prod_pow_factorization_centralBinom).symm
apply Finset.prod_subset
Β· exact Finset.range_subset.2 (add_le_add_right (Nat.div_le_self _ _) _)
intro x hx h2x
rw [Finset.mem_range, lt_succ_iff] at hx h2x
| rw [not_le, div_lt_iff_lt_mul' three_pos, mul_comm x] at h2x | /-- A lemma that tells us that, in the case where Bertrand's postulate does not hold, the prime
factorization of the central binomial coefficent only has factors at most `2 * n / 3 + 1`.
-/
theorem centralBinom_factorization_small (n : β) (n_large : 2 < n)
(no_prime : Β¬β p : β, p.Prime β§ n < p β§ p β€ 2 * n) :
centralBinom n = β p in Finset.range (2 * n / 3 + 1), p ^ (centralBinom n).factorization p := by
refine' (Eq.trans _ n.prod_pow_factorization_centralBinom).symm
apply Finset.prod_subset
Β· exact Finset.range_subset.2 (add_le_add_right (Nat.div_le_self _ _) _)
intro x hx h2x
rw [Finset.mem_range, lt_succ_iff] at hx h2x
| Mathlib.NumberTheory.Bertrand.136_0.gJXoOT9Ce2wC0xc | /-- A lemma that tells us that, in the case where Bertrand's postulate does not hold, the prime
factorization of the central binomial coefficent only has factors at most `2 * n / 3 + 1`.
-/
theorem centralBinom_factorization_small (n : β) (n_large : 2 < n)
(no_prime : Β¬β p : β, p.Prime β§ n < p β§ p β€ 2 * n) :
centralBinom n = β p in Finset.range (2 * n / 3 + 1), p ^ (centralBinom n).factorization p | Mathlib_NumberTheory_Bertrand |
case hf
n : β
n_large : 2 < n
no_prime : Β¬β p, Nat.Prime p β§ n < p β§ p β€ 2 * n
x : β
hx : x β€ 2 * n
h2x : 2 * n < 3 * x
β’ x ^ (Nat.factorization (centralBinom n)) x = 1 | /-
Copyright (c) 2020 Patrick Stevens. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Stevens, Bolton Bailey
-/
import Mathlib.Data.Nat.Choose.Factorization
import Mathlib.Data.Nat.PrimeNormNum
import Mathlib.NumberTheory.Primorial
import Mathlib.Analysis.Convex.SpecificFunctions.Basic
import Mathlib.Analysis.Convex.SpecificFunctions.Deriv
#align_import number_theory.bertrand from "leanprover-community/mathlib"@"a16665637b378379689c566204817ae792ac8b39"
/-!
# Bertrand's Postulate
This file contains a proof of Bertrand's postulate: That between any positive number and its
double there is a prime.
The proof follows the outline of the ErdΕs proof presented in "Proofs from THE BOOK": One considers
the prime factorization of `(2 * n).choose n`, and splits the constituent primes up into various
groups, then upper bounds the contribution of each group. This upper bounds the central binomial
coefficient, and if the postulate does not hold, this upper bound conflicts with a simple lower
bound for large enough `n`. This proves the result holds for large enough `n`, and for smaller `n`
an explicit list of primes is provided which covers the remaining cases.
As in the [Metamath implementation](carneiro2015arithmetic), we rely on some optimizations from
[Shigenori Tochiori](tochiori_bertrand). In particular we use the cleaner bound on the central
binomial coefficient given in `Nat.four_pow_lt_mul_centralBinom`.
## References
* [M. Aigner and G. M. Ziegler _Proofs from THE BOOK_][aigner1999proofs]
* [S. Tochiori, _Considering the Proof of βThere is a Prime between n and 2nβ_][tochiori_bertrand]
* [M. Carneiro, _Arithmetic in Metamath, Case Study: Bertrand's Postulate_][carneiro2015arithmetic]
## Tags
Bertrand, prime, binomial coefficients
-/
open scoped BigOperators
section Real
open Real
namespace Bertrand
/-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> norm_num1
apply le_trans _ (le_mul_of_one_le_left _ _) <;> norm_num1
apply Real.rpow_le_rpow <;> norm_num1
apply rpow_nonneg_of_nonneg; norm_num1
apply rpow_pos_of_pos; norm_num1
apply hf' 18; norm_num1
norm_num1
Β· have : sqrt (2 * 512) = 32 :=
(sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonpos_iff (hf' _ _), this, div_le_one] <;> norm_num1
Β· conv in 512 => equals 2 ^ 9 => norm_num1
conv in 1024 => equals 2 ^ 10 => norm_num1
conv in 32 => rw [β Nat.cast_ofNat]
rw [rpow_nat_cast, β pow_mul, β pow_add]
conv in 4 => equals 2 ^ (2 : β) => rw [rpow_two]; norm_num1
rw [β rpow_mul, β rpow_nat_cast]
apply rpow_le_rpow_of_exponent_le
all_goals norm_num1
Β· apply rpow_pos_of_pos four_pos
#align bertrand.real_main_inequality Bertrand.real_main_inequality
end Bertrand
end Real
section Nat
open Nat
/-- The inequality which contradicts Bertrand's postulate, for large enough `n`.
-/
theorem bertrand_main_inequality {n : β} (n_large : 512 β€ n) :
n * (2 * n) ^ sqrt (2 * n) * 4 ^ (2 * n / 3) β€ 4 ^ n := by
rw [β @cast_le β]
simp only [cast_add, cast_one, cast_mul, cast_pow, β Real.rpow_nat_cast]
refine' _root_.trans ?_ (Bertrand.real_main_inequality (by exact_mod_cast n_large))
gcongr
Β· have n2_pos : 0 < 2 * n := by positivity
exact mod_cast n2_pos
Β· exact_mod_cast Real.nat_sqrt_le_real_sqrt
Β· norm_num1
Β· exact cast_div_le.trans (by norm_cast)
#align bertrand_main_inequality bertrand_main_inequality
/-- A lemma that tells us that, in the case where Bertrand's postulate does not hold, the prime
factorization of the central binomial coefficent only has factors at most `2 * n / 3 + 1`.
-/
theorem centralBinom_factorization_small (n : β) (n_large : 2 < n)
(no_prime : Β¬β p : β, p.Prime β§ n < p β§ p β€ 2 * n) :
centralBinom n = β p in Finset.range (2 * n / 3 + 1), p ^ (centralBinom n).factorization p := by
refine' (Eq.trans _ n.prod_pow_factorization_centralBinom).symm
apply Finset.prod_subset
Β· exact Finset.range_subset.2 (add_le_add_right (Nat.div_le_self _ _) _)
intro x hx h2x
rw [Finset.mem_range, lt_succ_iff] at hx h2x
rw [not_le, div_lt_iff_lt_mul' three_pos, mul_comm x] at h2x
| replace no_prime := not_exists.mp no_prime x | /-- A lemma that tells us that, in the case where Bertrand's postulate does not hold, the prime
factorization of the central binomial coefficent only has factors at most `2 * n / 3 + 1`.
-/
theorem centralBinom_factorization_small (n : β) (n_large : 2 < n)
(no_prime : Β¬β p : β, p.Prime β§ n < p β§ p β€ 2 * n) :
centralBinom n = β p in Finset.range (2 * n / 3 + 1), p ^ (centralBinom n).factorization p := by
refine' (Eq.trans _ n.prod_pow_factorization_centralBinom).symm
apply Finset.prod_subset
Β· exact Finset.range_subset.2 (add_le_add_right (Nat.div_le_self _ _) _)
intro x hx h2x
rw [Finset.mem_range, lt_succ_iff] at hx h2x
rw [not_le, div_lt_iff_lt_mul' three_pos, mul_comm x] at h2x
| Mathlib.NumberTheory.Bertrand.136_0.gJXoOT9Ce2wC0xc | /-- A lemma that tells us that, in the case where Bertrand's postulate does not hold, the prime
factorization of the central binomial coefficent only has factors at most `2 * n / 3 + 1`.
-/
theorem centralBinom_factorization_small (n : β) (n_large : 2 < n)
(no_prime : Β¬β p : β, p.Prime β§ n < p β§ p β€ 2 * n) :
centralBinom n = β p in Finset.range (2 * n / 3 + 1), p ^ (centralBinom n).factorization p | Mathlib_NumberTheory_Bertrand |
case hf
n : β
n_large : 2 < n
x : β
hx : x β€ 2 * n
h2x : 2 * n < 3 * x
no_prime : Β¬(Nat.Prime x β§ n < x β§ x β€ 2 * n)
β’ x ^ (Nat.factorization (centralBinom n)) x = 1 | /-
Copyright (c) 2020 Patrick Stevens. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Stevens, Bolton Bailey
-/
import Mathlib.Data.Nat.Choose.Factorization
import Mathlib.Data.Nat.PrimeNormNum
import Mathlib.NumberTheory.Primorial
import Mathlib.Analysis.Convex.SpecificFunctions.Basic
import Mathlib.Analysis.Convex.SpecificFunctions.Deriv
#align_import number_theory.bertrand from "leanprover-community/mathlib"@"a16665637b378379689c566204817ae792ac8b39"
/-!
# Bertrand's Postulate
This file contains a proof of Bertrand's postulate: That between any positive number and its
double there is a prime.
The proof follows the outline of the ErdΕs proof presented in "Proofs from THE BOOK": One considers
the prime factorization of `(2 * n).choose n`, and splits the constituent primes up into various
groups, then upper bounds the contribution of each group. This upper bounds the central binomial
coefficient, and if the postulate does not hold, this upper bound conflicts with a simple lower
bound for large enough `n`. This proves the result holds for large enough `n`, and for smaller `n`
an explicit list of primes is provided which covers the remaining cases.
As in the [Metamath implementation](carneiro2015arithmetic), we rely on some optimizations from
[Shigenori Tochiori](tochiori_bertrand). In particular we use the cleaner bound on the central
binomial coefficient given in `Nat.four_pow_lt_mul_centralBinom`.
## References
* [M. Aigner and G. M. Ziegler _Proofs from THE BOOK_][aigner1999proofs]
* [S. Tochiori, _Considering the Proof of βThere is a Prime between n and 2nβ_][tochiori_bertrand]
* [M. Carneiro, _Arithmetic in Metamath, Case Study: Bertrand's Postulate_][carneiro2015arithmetic]
## Tags
Bertrand, prime, binomial coefficients
-/
open scoped BigOperators
section Real
open Real
namespace Bertrand
/-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> norm_num1
apply le_trans _ (le_mul_of_one_le_left _ _) <;> norm_num1
apply Real.rpow_le_rpow <;> norm_num1
apply rpow_nonneg_of_nonneg; norm_num1
apply rpow_pos_of_pos; norm_num1
apply hf' 18; norm_num1
norm_num1
Β· have : sqrt (2 * 512) = 32 :=
(sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonpos_iff (hf' _ _), this, div_le_one] <;> norm_num1
Β· conv in 512 => equals 2 ^ 9 => norm_num1
conv in 1024 => equals 2 ^ 10 => norm_num1
conv in 32 => rw [β Nat.cast_ofNat]
rw [rpow_nat_cast, β pow_mul, β pow_add]
conv in 4 => equals 2 ^ (2 : β) => rw [rpow_two]; norm_num1
rw [β rpow_mul, β rpow_nat_cast]
apply rpow_le_rpow_of_exponent_le
all_goals norm_num1
Β· apply rpow_pos_of_pos four_pos
#align bertrand.real_main_inequality Bertrand.real_main_inequality
end Bertrand
end Real
section Nat
open Nat
/-- The inequality which contradicts Bertrand's postulate, for large enough `n`.
-/
theorem bertrand_main_inequality {n : β} (n_large : 512 β€ n) :
n * (2 * n) ^ sqrt (2 * n) * 4 ^ (2 * n / 3) β€ 4 ^ n := by
rw [β @cast_le β]
simp only [cast_add, cast_one, cast_mul, cast_pow, β Real.rpow_nat_cast]
refine' _root_.trans ?_ (Bertrand.real_main_inequality (by exact_mod_cast n_large))
gcongr
Β· have n2_pos : 0 < 2 * n := by positivity
exact mod_cast n2_pos
Β· exact_mod_cast Real.nat_sqrt_le_real_sqrt
Β· norm_num1
Β· exact cast_div_le.trans (by norm_cast)
#align bertrand_main_inequality bertrand_main_inequality
/-- A lemma that tells us that, in the case where Bertrand's postulate does not hold, the prime
factorization of the central binomial coefficent only has factors at most `2 * n / 3 + 1`.
-/
theorem centralBinom_factorization_small (n : β) (n_large : 2 < n)
(no_prime : Β¬β p : β, p.Prime β§ n < p β§ p β€ 2 * n) :
centralBinom n = β p in Finset.range (2 * n / 3 + 1), p ^ (centralBinom n).factorization p := by
refine' (Eq.trans _ n.prod_pow_factorization_centralBinom).symm
apply Finset.prod_subset
Β· exact Finset.range_subset.2 (add_le_add_right (Nat.div_le_self _ _) _)
intro x hx h2x
rw [Finset.mem_range, lt_succ_iff] at hx h2x
rw [not_le, div_lt_iff_lt_mul' three_pos, mul_comm x] at h2x
replace no_prime := not_exists.mp no_prime x
| rw [β and_assoc, not_and', not_and_or, not_lt] at no_prime | /-- A lemma that tells us that, in the case where Bertrand's postulate does not hold, the prime
factorization of the central binomial coefficent only has factors at most `2 * n / 3 + 1`.
-/
theorem centralBinom_factorization_small (n : β) (n_large : 2 < n)
(no_prime : Β¬β p : β, p.Prime β§ n < p β§ p β€ 2 * n) :
centralBinom n = β p in Finset.range (2 * n / 3 + 1), p ^ (centralBinom n).factorization p := by
refine' (Eq.trans _ n.prod_pow_factorization_centralBinom).symm
apply Finset.prod_subset
Β· exact Finset.range_subset.2 (add_le_add_right (Nat.div_le_self _ _) _)
intro x hx h2x
rw [Finset.mem_range, lt_succ_iff] at hx h2x
rw [not_le, div_lt_iff_lt_mul' three_pos, mul_comm x] at h2x
replace no_prime := not_exists.mp no_prime x
| Mathlib.NumberTheory.Bertrand.136_0.gJXoOT9Ce2wC0xc | /-- A lemma that tells us that, in the case where Bertrand's postulate does not hold, the prime
factorization of the central binomial coefficent only has factors at most `2 * n / 3 + 1`.
-/
theorem centralBinom_factorization_small (n : β) (n_large : 2 < n)
(no_prime : Β¬β p : β, p.Prime β§ n < p β§ p β€ 2 * n) :
centralBinom n = β p in Finset.range (2 * n / 3 + 1), p ^ (centralBinom n).factorization p | Mathlib_NumberTheory_Bertrand |
case hf
n : β
n_large : 2 < n
x : β
hx : x β€ 2 * n
h2x : 2 * n < 3 * x
no_prime : x β€ 2 * n β Β¬Nat.Prime x β¨ x β€ n
β’ x ^ (Nat.factorization (centralBinom n)) x = 1 | /-
Copyright (c) 2020 Patrick Stevens. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Stevens, Bolton Bailey
-/
import Mathlib.Data.Nat.Choose.Factorization
import Mathlib.Data.Nat.PrimeNormNum
import Mathlib.NumberTheory.Primorial
import Mathlib.Analysis.Convex.SpecificFunctions.Basic
import Mathlib.Analysis.Convex.SpecificFunctions.Deriv
#align_import number_theory.bertrand from "leanprover-community/mathlib"@"a16665637b378379689c566204817ae792ac8b39"
/-!
# Bertrand's Postulate
This file contains a proof of Bertrand's postulate: That between any positive number and its
double there is a prime.
The proof follows the outline of the ErdΕs proof presented in "Proofs from THE BOOK": One considers
the prime factorization of `(2 * n).choose n`, and splits the constituent primes up into various
groups, then upper bounds the contribution of each group. This upper bounds the central binomial
coefficient, and if the postulate does not hold, this upper bound conflicts with a simple lower
bound for large enough `n`. This proves the result holds for large enough `n`, and for smaller `n`
an explicit list of primes is provided which covers the remaining cases.
As in the [Metamath implementation](carneiro2015arithmetic), we rely on some optimizations from
[Shigenori Tochiori](tochiori_bertrand). In particular we use the cleaner bound on the central
binomial coefficient given in `Nat.four_pow_lt_mul_centralBinom`.
## References
* [M. Aigner and G. M. Ziegler _Proofs from THE BOOK_][aigner1999proofs]
* [S. Tochiori, _Considering the Proof of βThere is a Prime between n and 2nβ_][tochiori_bertrand]
* [M. Carneiro, _Arithmetic in Metamath, Case Study: Bertrand's Postulate_][carneiro2015arithmetic]
## Tags
Bertrand, prime, binomial coefficients
-/
open scoped BigOperators
section Real
open Real
namespace Bertrand
/-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> norm_num1
apply le_trans _ (le_mul_of_one_le_left _ _) <;> norm_num1
apply Real.rpow_le_rpow <;> norm_num1
apply rpow_nonneg_of_nonneg; norm_num1
apply rpow_pos_of_pos; norm_num1
apply hf' 18; norm_num1
norm_num1
Β· have : sqrt (2 * 512) = 32 :=
(sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonpos_iff (hf' _ _), this, div_le_one] <;> norm_num1
Β· conv in 512 => equals 2 ^ 9 => norm_num1
conv in 1024 => equals 2 ^ 10 => norm_num1
conv in 32 => rw [β Nat.cast_ofNat]
rw [rpow_nat_cast, β pow_mul, β pow_add]
conv in 4 => equals 2 ^ (2 : β) => rw [rpow_two]; norm_num1
rw [β rpow_mul, β rpow_nat_cast]
apply rpow_le_rpow_of_exponent_le
all_goals norm_num1
Β· apply rpow_pos_of_pos four_pos
#align bertrand.real_main_inequality Bertrand.real_main_inequality
end Bertrand
end Real
section Nat
open Nat
/-- The inequality which contradicts Bertrand's postulate, for large enough `n`.
-/
theorem bertrand_main_inequality {n : β} (n_large : 512 β€ n) :
n * (2 * n) ^ sqrt (2 * n) * 4 ^ (2 * n / 3) β€ 4 ^ n := by
rw [β @cast_le β]
simp only [cast_add, cast_one, cast_mul, cast_pow, β Real.rpow_nat_cast]
refine' _root_.trans ?_ (Bertrand.real_main_inequality (by exact_mod_cast n_large))
gcongr
Β· have n2_pos : 0 < 2 * n := by positivity
exact mod_cast n2_pos
Β· exact_mod_cast Real.nat_sqrt_le_real_sqrt
Β· norm_num1
Β· exact cast_div_le.trans (by norm_cast)
#align bertrand_main_inequality bertrand_main_inequality
/-- A lemma that tells us that, in the case where Bertrand's postulate does not hold, the prime
factorization of the central binomial coefficent only has factors at most `2 * n / 3 + 1`.
-/
theorem centralBinom_factorization_small (n : β) (n_large : 2 < n)
(no_prime : Β¬β p : β, p.Prime β§ n < p β§ p β€ 2 * n) :
centralBinom n = β p in Finset.range (2 * n / 3 + 1), p ^ (centralBinom n).factorization p := by
refine' (Eq.trans _ n.prod_pow_factorization_centralBinom).symm
apply Finset.prod_subset
Β· exact Finset.range_subset.2 (add_le_add_right (Nat.div_le_self _ _) _)
intro x hx h2x
rw [Finset.mem_range, lt_succ_iff] at hx h2x
rw [not_le, div_lt_iff_lt_mul' three_pos, mul_comm x] at h2x
replace no_prime := not_exists.mp no_prime x
rw [β and_assoc, not_and', not_and_or, not_lt] at no_prime
| cases' no_prime hx with h h | /-- A lemma that tells us that, in the case where Bertrand's postulate does not hold, the prime
factorization of the central binomial coefficent only has factors at most `2 * n / 3 + 1`.
-/
theorem centralBinom_factorization_small (n : β) (n_large : 2 < n)
(no_prime : Β¬β p : β, p.Prime β§ n < p β§ p β€ 2 * n) :
centralBinom n = β p in Finset.range (2 * n / 3 + 1), p ^ (centralBinom n).factorization p := by
refine' (Eq.trans _ n.prod_pow_factorization_centralBinom).symm
apply Finset.prod_subset
Β· exact Finset.range_subset.2 (add_le_add_right (Nat.div_le_self _ _) _)
intro x hx h2x
rw [Finset.mem_range, lt_succ_iff] at hx h2x
rw [not_le, div_lt_iff_lt_mul' three_pos, mul_comm x] at h2x
replace no_prime := not_exists.mp no_prime x
rw [β and_assoc, not_and', not_and_or, not_lt] at no_prime
| Mathlib.NumberTheory.Bertrand.136_0.gJXoOT9Ce2wC0xc | /-- A lemma that tells us that, in the case where Bertrand's postulate does not hold, the prime
factorization of the central binomial coefficent only has factors at most `2 * n / 3 + 1`.
-/
theorem centralBinom_factorization_small (n : β) (n_large : 2 < n)
(no_prime : Β¬β p : β, p.Prime β§ n < p β§ p β€ 2 * n) :
centralBinom n = β p in Finset.range (2 * n / 3 + 1), p ^ (centralBinom n).factorization p | Mathlib_NumberTheory_Bertrand |
case hf.inl
n : β
n_large : 2 < n
x : β
hx : x β€ 2 * n
h2x : 2 * n < 3 * x
no_prime : x β€ 2 * n β Β¬Nat.Prime x β¨ x β€ n
h : Β¬Nat.Prime x
β’ x ^ (Nat.factorization (centralBinom n)) x = 1 | /-
Copyright (c) 2020 Patrick Stevens. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Stevens, Bolton Bailey
-/
import Mathlib.Data.Nat.Choose.Factorization
import Mathlib.Data.Nat.PrimeNormNum
import Mathlib.NumberTheory.Primorial
import Mathlib.Analysis.Convex.SpecificFunctions.Basic
import Mathlib.Analysis.Convex.SpecificFunctions.Deriv
#align_import number_theory.bertrand from "leanprover-community/mathlib"@"a16665637b378379689c566204817ae792ac8b39"
/-!
# Bertrand's Postulate
This file contains a proof of Bertrand's postulate: That between any positive number and its
double there is a prime.
The proof follows the outline of the ErdΕs proof presented in "Proofs from THE BOOK": One considers
the prime factorization of `(2 * n).choose n`, and splits the constituent primes up into various
groups, then upper bounds the contribution of each group. This upper bounds the central binomial
coefficient, and if the postulate does not hold, this upper bound conflicts with a simple lower
bound for large enough `n`. This proves the result holds for large enough `n`, and for smaller `n`
an explicit list of primes is provided which covers the remaining cases.
As in the [Metamath implementation](carneiro2015arithmetic), we rely on some optimizations from
[Shigenori Tochiori](tochiori_bertrand). In particular we use the cleaner bound on the central
binomial coefficient given in `Nat.four_pow_lt_mul_centralBinom`.
## References
* [M. Aigner and G. M. Ziegler _Proofs from THE BOOK_][aigner1999proofs]
* [S. Tochiori, _Considering the Proof of βThere is a Prime between n and 2nβ_][tochiori_bertrand]
* [M. Carneiro, _Arithmetic in Metamath, Case Study: Bertrand's Postulate_][carneiro2015arithmetic]
## Tags
Bertrand, prime, binomial coefficients
-/
open scoped BigOperators
section Real
open Real
namespace Bertrand
/-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> norm_num1
apply le_trans _ (le_mul_of_one_le_left _ _) <;> norm_num1
apply Real.rpow_le_rpow <;> norm_num1
apply rpow_nonneg_of_nonneg; norm_num1
apply rpow_pos_of_pos; norm_num1
apply hf' 18; norm_num1
norm_num1
Β· have : sqrt (2 * 512) = 32 :=
(sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonpos_iff (hf' _ _), this, div_le_one] <;> norm_num1
Β· conv in 512 => equals 2 ^ 9 => norm_num1
conv in 1024 => equals 2 ^ 10 => norm_num1
conv in 32 => rw [β Nat.cast_ofNat]
rw [rpow_nat_cast, β pow_mul, β pow_add]
conv in 4 => equals 2 ^ (2 : β) => rw [rpow_two]; norm_num1
rw [β rpow_mul, β rpow_nat_cast]
apply rpow_le_rpow_of_exponent_le
all_goals norm_num1
Β· apply rpow_pos_of_pos four_pos
#align bertrand.real_main_inequality Bertrand.real_main_inequality
end Bertrand
end Real
section Nat
open Nat
/-- The inequality which contradicts Bertrand's postulate, for large enough `n`.
-/
theorem bertrand_main_inequality {n : β} (n_large : 512 β€ n) :
n * (2 * n) ^ sqrt (2 * n) * 4 ^ (2 * n / 3) β€ 4 ^ n := by
rw [β @cast_le β]
simp only [cast_add, cast_one, cast_mul, cast_pow, β Real.rpow_nat_cast]
refine' _root_.trans ?_ (Bertrand.real_main_inequality (by exact_mod_cast n_large))
gcongr
Β· have n2_pos : 0 < 2 * n := by positivity
exact mod_cast n2_pos
Β· exact_mod_cast Real.nat_sqrt_le_real_sqrt
Β· norm_num1
Β· exact cast_div_le.trans (by norm_cast)
#align bertrand_main_inequality bertrand_main_inequality
/-- A lemma that tells us that, in the case where Bertrand's postulate does not hold, the prime
factorization of the central binomial coefficent only has factors at most `2 * n / 3 + 1`.
-/
theorem centralBinom_factorization_small (n : β) (n_large : 2 < n)
(no_prime : Β¬β p : β, p.Prime β§ n < p β§ p β€ 2 * n) :
centralBinom n = β p in Finset.range (2 * n / 3 + 1), p ^ (centralBinom n).factorization p := by
refine' (Eq.trans _ n.prod_pow_factorization_centralBinom).symm
apply Finset.prod_subset
Β· exact Finset.range_subset.2 (add_le_add_right (Nat.div_le_self _ _) _)
intro x hx h2x
rw [Finset.mem_range, lt_succ_iff] at hx h2x
rw [not_le, div_lt_iff_lt_mul' three_pos, mul_comm x] at h2x
replace no_prime := not_exists.mp no_prime x
rw [β and_assoc, not_and', not_and_or, not_lt] at no_prime
cases' no_prime hx with h h
Β· | rw [factorization_eq_zero_of_non_prime n.centralBinom h, Nat.pow_zero] | /-- A lemma that tells us that, in the case where Bertrand's postulate does not hold, the prime
factorization of the central binomial coefficent only has factors at most `2 * n / 3 + 1`.
-/
theorem centralBinom_factorization_small (n : β) (n_large : 2 < n)
(no_prime : Β¬β p : β, p.Prime β§ n < p β§ p β€ 2 * n) :
centralBinom n = β p in Finset.range (2 * n / 3 + 1), p ^ (centralBinom n).factorization p := by
refine' (Eq.trans _ n.prod_pow_factorization_centralBinom).symm
apply Finset.prod_subset
Β· exact Finset.range_subset.2 (add_le_add_right (Nat.div_le_self _ _) _)
intro x hx h2x
rw [Finset.mem_range, lt_succ_iff] at hx h2x
rw [not_le, div_lt_iff_lt_mul' three_pos, mul_comm x] at h2x
replace no_prime := not_exists.mp no_prime x
rw [β and_assoc, not_and', not_and_or, not_lt] at no_prime
cases' no_prime hx with h h
Β· | Mathlib.NumberTheory.Bertrand.136_0.gJXoOT9Ce2wC0xc | /-- A lemma that tells us that, in the case where Bertrand's postulate does not hold, the prime
factorization of the central binomial coefficent only has factors at most `2 * n / 3 + 1`.
-/
theorem centralBinom_factorization_small (n : β) (n_large : 2 < n)
(no_prime : Β¬β p : β, p.Prime β§ n < p β§ p β€ 2 * n) :
centralBinom n = β p in Finset.range (2 * n / 3 + 1), p ^ (centralBinom n).factorization p | Mathlib_NumberTheory_Bertrand |
case hf.inr
n : β
n_large : 2 < n
x : β
hx : x β€ 2 * n
h2x : 2 * n < 3 * x
no_prime : x β€ 2 * n β Β¬Nat.Prime x β¨ x β€ n
h : x β€ n
β’ x ^ (Nat.factorization (centralBinom n)) x = 1 | /-
Copyright (c) 2020 Patrick Stevens. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Stevens, Bolton Bailey
-/
import Mathlib.Data.Nat.Choose.Factorization
import Mathlib.Data.Nat.PrimeNormNum
import Mathlib.NumberTheory.Primorial
import Mathlib.Analysis.Convex.SpecificFunctions.Basic
import Mathlib.Analysis.Convex.SpecificFunctions.Deriv
#align_import number_theory.bertrand from "leanprover-community/mathlib"@"a16665637b378379689c566204817ae792ac8b39"
/-!
# Bertrand's Postulate
This file contains a proof of Bertrand's postulate: That between any positive number and its
double there is a prime.
The proof follows the outline of the ErdΕs proof presented in "Proofs from THE BOOK": One considers
the prime factorization of `(2 * n).choose n`, and splits the constituent primes up into various
groups, then upper bounds the contribution of each group. This upper bounds the central binomial
coefficient, and if the postulate does not hold, this upper bound conflicts with a simple lower
bound for large enough `n`. This proves the result holds for large enough `n`, and for smaller `n`
an explicit list of primes is provided which covers the remaining cases.
As in the [Metamath implementation](carneiro2015arithmetic), we rely on some optimizations from
[Shigenori Tochiori](tochiori_bertrand). In particular we use the cleaner bound on the central
binomial coefficient given in `Nat.four_pow_lt_mul_centralBinom`.
## References
* [M. Aigner and G. M. Ziegler _Proofs from THE BOOK_][aigner1999proofs]
* [S. Tochiori, _Considering the Proof of βThere is a Prime between n and 2nβ_][tochiori_bertrand]
* [M. Carneiro, _Arithmetic in Metamath, Case Study: Bertrand's Postulate_][carneiro2015arithmetic]
## Tags
Bertrand, prime, binomial coefficients
-/
open scoped BigOperators
section Real
open Real
namespace Bertrand
/-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> norm_num1
apply le_trans _ (le_mul_of_one_le_left _ _) <;> norm_num1
apply Real.rpow_le_rpow <;> norm_num1
apply rpow_nonneg_of_nonneg; norm_num1
apply rpow_pos_of_pos; norm_num1
apply hf' 18; norm_num1
norm_num1
Β· have : sqrt (2 * 512) = 32 :=
(sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonpos_iff (hf' _ _), this, div_le_one] <;> norm_num1
Β· conv in 512 => equals 2 ^ 9 => norm_num1
conv in 1024 => equals 2 ^ 10 => norm_num1
conv in 32 => rw [β Nat.cast_ofNat]
rw [rpow_nat_cast, β pow_mul, β pow_add]
conv in 4 => equals 2 ^ (2 : β) => rw [rpow_two]; norm_num1
rw [β rpow_mul, β rpow_nat_cast]
apply rpow_le_rpow_of_exponent_le
all_goals norm_num1
Β· apply rpow_pos_of_pos four_pos
#align bertrand.real_main_inequality Bertrand.real_main_inequality
end Bertrand
end Real
section Nat
open Nat
/-- The inequality which contradicts Bertrand's postulate, for large enough `n`.
-/
theorem bertrand_main_inequality {n : β} (n_large : 512 β€ n) :
n * (2 * n) ^ sqrt (2 * n) * 4 ^ (2 * n / 3) β€ 4 ^ n := by
rw [β @cast_le β]
simp only [cast_add, cast_one, cast_mul, cast_pow, β Real.rpow_nat_cast]
refine' _root_.trans ?_ (Bertrand.real_main_inequality (by exact_mod_cast n_large))
gcongr
Β· have n2_pos : 0 < 2 * n := by positivity
exact mod_cast n2_pos
Β· exact_mod_cast Real.nat_sqrt_le_real_sqrt
Β· norm_num1
Β· exact cast_div_le.trans (by norm_cast)
#align bertrand_main_inequality bertrand_main_inequality
/-- A lemma that tells us that, in the case where Bertrand's postulate does not hold, the prime
factorization of the central binomial coefficent only has factors at most `2 * n / 3 + 1`.
-/
theorem centralBinom_factorization_small (n : β) (n_large : 2 < n)
(no_prime : Β¬β p : β, p.Prime β§ n < p β§ p β€ 2 * n) :
centralBinom n = β p in Finset.range (2 * n / 3 + 1), p ^ (centralBinom n).factorization p := by
refine' (Eq.trans _ n.prod_pow_factorization_centralBinom).symm
apply Finset.prod_subset
Β· exact Finset.range_subset.2 (add_le_add_right (Nat.div_le_self _ _) _)
intro x hx h2x
rw [Finset.mem_range, lt_succ_iff] at hx h2x
rw [not_le, div_lt_iff_lt_mul' three_pos, mul_comm x] at h2x
replace no_prime := not_exists.mp no_prime x
rw [β and_assoc, not_and', not_and_or, not_lt] at no_prime
cases' no_prime hx with h h
Β· rw [factorization_eq_zero_of_non_prime n.centralBinom h, Nat.pow_zero]
Β· | rw [factorization_centralBinom_of_two_mul_self_lt_three_mul n_large h h2x, Nat.pow_zero] | /-- A lemma that tells us that, in the case where Bertrand's postulate does not hold, the prime
factorization of the central binomial coefficent only has factors at most `2 * n / 3 + 1`.
-/
theorem centralBinom_factorization_small (n : β) (n_large : 2 < n)
(no_prime : Β¬β p : β, p.Prime β§ n < p β§ p β€ 2 * n) :
centralBinom n = β p in Finset.range (2 * n / 3 + 1), p ^ (centralBinom n).factorization p := by
refine' (Eq.trans _ n.prod_pow_factorization_centralBinom).symm
apply Finset.prod_subset
Β· exact Finset.range_subset.2 (add_le_add_right (Nat.div_le_self _ _) _)
intro x hx h2x
rw [Finset.mem_range, lt_succ_iff] at hx h2x
rw [not_le, div_lt_iff_lt_mul' three_pos, mul_comm x] at h2x
replace no_prime := not_exists.mp no_prime x
rw [β and_assoc, not_and', not_and_or, not_lt] at no_prime
cases' no_prime hx with h h
Β· rw [factorization_eq_zero_of_non_prime n.centralBinom h, Nat.pow_zero]
Β· | Mathlib.NumberTheory.Bertrand.136_0.gJXoOT9Ce2wC0xc | /-- A lemma that tells us that, in the case where Bertrand's postulate does not hold, the prime
factorization of the central binomial coefficent only has factors at most `2 * n / 3 + 1`.
-/
theorem centralBinom_factorization_small (n : β) (n_large : 2 < n)
(no_prime : Β¬β p : β, p.Prime β§ n < p β§ p β€ 2 * n) :
centralBinom n = β p in Finset.range (2 * n / 3 + 1), p ^ (centralBinom n).factorization p | Mathlib_NumberTheory_Bertrand |
n : β
n_big : 2 < n
no_prime : Β¬β p, Nat.Prime p β§ n < p β§ p β€ 2 * n
β’ centralBinom n β€ (2 * n) ^ sqrt (2 * n) * 4 ^ (2 * n / 3) | /-
Copyright (c) 2020 Patrick Stevens. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Stevens, Bolton Bailey
-/
import Mathlib.Data.Nat.Choose.Factorization
import Mathlib.Data.Nat.PrimeNormNum
import Mathlib.NumberTheory.Primorial
import Mathlib.Analysis.Convex.SpecificFunctions.Basic
import Mathlib.Analysis.Convex.SpecificFunctions.Deriv
#align_import number_theory.bertrand from "leanprover-community/mathlib"@"a16665637b378379689c566204817ae792ac8b39"
/-!
# Bertrand's Postulate
This file contains a proof of Bertrand's postulate: That between any positive number and its
double there is a prime.
The proof follows the outline of the ErdΕs proof presented in "Proofs from THE BOOK": One considers
the prime factorization of `(2 * n).choose n`, and splits the constituent primes up into various
groups, then upper bounds the contribution of each group. This upper bounds the central binomial
coefficient, and if the postulate does not hold, this upper bound conflicts with a simple lower
bound for large enough `n`. This proves the result holds for large enough `n`, and for smaller `n`
an explicit list of primes is provided which covers the remaining cases.
As in the [Metamath implementation](carneiro2015arithmetic), we rely on some optimizations from
[Shigenori Tochiori](tochiori_bertrand). In particular we use the cleaner bound on the central
binomial coefficient given in `Nat.four_pow_lt_mul_centralBinom`.
## References
* [M. Aigner and G. M. Ziegler _Proofs from THE BOOK_][aigner1999proofs]
* [S. Tochiori, _Considering the Proof of βThere is a Prime between n and 2nβ_][tochiori_bertrand]
* [M. Carneiro, _Arithmetic in Metamath, Case Study: Bertrand's Postulate_][carneiro2015arithmetic]
## Tags
Bertrand, prime, binomial coefficients
-/
open scoped BigOperators
section Real
open Real
namespace Bertrand
/-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> norm_num1
apply le_trans _ (le_mul_of_one_le_left _ _) <;> norm_num1
apply Real.rpow_le_rpow <;> norm_num1
apply rpow_nonneg_of_nonneg; norm_num1
apply rpow_pos_of_pos; norm_num1
apply hf' 18; norm_num1
norm_num1
Β· have : sqrt (2 * 512) = 32 :=
(sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonpos_iff (hf' _ _), this, div_le_one] <;> norm_num1
Β· conv in 512 => equals 2 ^ 9 => norm_num1
conv in 1024 => equals 2 ^ 10 => norm_num1
conv in 32 => rw [β Nat.cast_ofNat]
rw [rpow_nat_cast, β pow_mul, β pow_add]
conv in 4 => equals 2 ^ (2 : β) => rw [rpow_two]; norm_num1
rw [β rpow_mul, β rpow_nat_cast]
apply rpow_le_rpow_of_exponent_le
all_goals norm_num1
Β· apply rpow_pos_of_pos four_pos
#align bertrand.real_main_inequality Bertrand.real_main_inequality
end Bertrand
end Real
section Nat
open Nat
/-- The inequality which contradicts Bertrand's postulate, for large enough `n`.
-/
theorem bertrand_main_inequality {n : β} (n_large : 512 β€ n) :
n * (2 * n) ^ sqrt (2 * n) * 4 ^ (2 * n / 3) β€ 4 ^ n := by
rw [β @cast_le β]
simp only [cast_add, cast_one, cast_mul, cast_pow, β Real.rpow_nat_cast]
refine' _root_.trans ?_ (Bertrand.real_main_inequality (by exact_mod_cast n_large))
gcongr
Β· have n2_pos : 0 < 2 * n := by positivity
exact mod_cast n2_pos
Β· exact_mod_cast Real.nat_sqrt_le_real_sqrt
Β· norm_num1
Β· exact cast_div_le.trans (by norm_cast)
#align bertrand_main_inequality bertrand_main_inequality
/-- A lemma that tells us that, in the case where Bertrand's postulate does not hold, the prime
factorization of the central binomial coefficent only has factors at most `2 * n / 3 + 1`.
-/
theorem centralBinom_factorization_small (n : β) (n_large : 2 < n)
(no_prime : Β¬β p : β, p.Prime β§ n < p β§ p β€ 2 * n) :
centralBinom n = β p in Finset.range (2 * n / 3 + 1), p ^ (centralBinom n).factorization p := by
refine' (Eq.trans _ n.prod_pow_factorization_centralBinom).symm
apply Finset.prod_subset
Β· exact Finset.range_subset.2 (add_le_add_right (Nat.div_le_self _ _) _)
intro x hx h2x
rw [Finset.mem_range, lt_succ_iff] at hx h2x
rw [not_le, div_lt_iff_lt_mul' three_pos, mul_comm x] at h2x
replace no_prime := not_exists.mp no_prime x
rw [β and_assoc, not_and', not_and_or, not_lt] at no_prime
cases' no_prime hx with h h
Β· rw [factorization_eq_zero_of_non_prime n.centralBinom h, Nat.pow_zero]
Β· rw [factorization_centralBinom_of_two_mul_self_lt_three_mul n_large h h2x, Nat.pow_zero]
#align central_binom_factorization_small centralBinom_factorization_small
/-- An upper bound on the central binomial coefficient used in the proof of Bertrand's postulate.
The bound splits the prime factors of `centralBinom n` into those
1. At most `sqrt (2 * n)`, which contribute at most `2 * n` for each such prime.
2. Between `sqrt (2 * n)` and `2 * n / 3`, which contribute at most `4^(2 * n / 3)` in total.
3. Between `2 * n / 3` and `n`, which do not exist.
4. Between `n` and `2 * n`, which would not exist in the case where Bertrand's postulate is false.
5. Above `2 * n`, which do not exist.
-/
theorem centralBinom_le_of_no_bertrand_prime (n : β) (n_big : 2 < n)
(no_prime : Β¬β p : β, Nat.Prime p β§ n < p β§ p β€ 2 * n) :
centralBinom n β€ (2 * n) ^ sqrt (2 * n) * 4 ^ (2 * n / 3) := by
| have n_pos : 0 < n := (Nat.zero_le _).trans_lt n_big | /-- An upper bound on the central binomial coefficient used in the proof of Bertrand's postulate.
The bound splits the prime factors of `centralBinom n` into those
1. At most `sqrt (2 * n)`, which contribute at most `2 * n` for each such prime.
2. Between `sqrt (2 * n)` and `2 * n / 3`, which contribute at most `4^(2 * n / 3)` in total.
3. Between `2 * n / 3` and `n`, which do not exist.
4. Between `n` and `2 * n`, which would not exist in the case where Bertrand's postulate is false.
5. Above `2 * n`, which do not exist.
-/
theorem centralBinom_le_of_no_bertrand_prime (n : β) (n_big : 2 < n)
(no_prime : Β¬β p : β, Nat.Prime p β§ n < p β§ p β€ 2 * n) :
centralBinom n β€ (2 * n) ^ sqrt (2 * n) * 4 ^ (2 * n / 3) := by
| Mathlib.NumberTheory.Bertrand.155_0.gJXoOT9Ce2wC0xc | /-- An upper bound on the central binomial coefficient used in the proof of Bertrand's postulate.
The bound splits the prime factors of `centralBinom n` into those
1. At most `sqrt (2 * n)`, which contribute at most `2 * n` for each such prime.
2. Between `sqrt (2 * n)` and `2 * n / 3`, which contribute at most `4^(2 * n / 3)` in total.
3. Between `2 * n / 3` and `n`, which do not exist.
4. Between `n` and `2 * n`, which would not exist in the case where Bertrand's postulate is false.
5. Above `2 * n`, which do not exist.
-/
theorem centralBinom_le_of_no_bertrand_prime (n : β) (n_big : 2 < n)
(no_prime : Β¬β p : β, Nat.Prime p β§ n < p β§ p β€ 2 * n) :
centralBinom n β€ (2 * n) ^ sqrt (2 * n) * 4 ^ (2 * n / 3) | Mathlib_NumberTheory_Bertrand |
n : β
n_big : 2 < n
no_prime : Β¬β p, Nat.Prime p β§ n < p β§ p β€ 2 * n
n_pos : 0 < n
β’ centralBinom n β€ (2 * n) ^ sqrt (2 * n) * 4 ^ (2 * n / 3) | /-
Copyright (c) 2020 Patrick Stevens. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Stevens, Bolton Bailey
-/
import Mathlib.Data.Nat.Choose.Factorization
import Mathlib.Data.Nat.PrimeNormNum
import Mathlib.NumberTheory.Primorial
import Mathlib.Analysis.Convex.SpecificFunctions.Basic
import Mathlib.Analysis.Convex.SpecificFunctions.Deriv
#align_import number_theory.bertrand from "leanprover-community/mathlib"@"a16665637b378379689c566204817ae792ac8b39"
/-!
# Bertrand's Postulate
This file contains a proof of Bertrand's postulate: That between any positive number and its
double there is a prime.
The proof follows the outline of the ErdΕs proof presented in "Proofs from THE BOOK": One considers
the prime factorization of `(2 * n).choose n`, and splits the constituent primes up into various
groups, then upper bounds the contribution of each group. This upper bounds the central binomial
coefficient, and if the postulate does not hold, this upper bound conflicts with a simple lower
bound for large enough `n`. This proves the result holds for large enough `n`, and for smaller `n`
an explicit list of primes is provided which covers the remaining cases.
As in the [Metamath implementation](carneiro2015arithmetic), we rely on some optimizations from
[Shigenori Tochiori](tochiori_bertrand). In particular we use the cleaner bound on the central
binomial coefficient given in `Nat.four_pow_lt_mul_centralBinom`.
## References
* [M. Aigner and G. M. Ziegler _Proofs from THE BOOK_][aigner1999proofs]
* [S. Tochiori, _Considering the Proof of βThere is a Prime between n and 2nβ_][tochiori_bertrand]
* [M. Carneiro, _Arithmetic in Metamath, Case Study: Bertrand's Postulate_][carneiro2015arithmetic]
## Tags
Bertrand, prime, binomial coefficients
-/
open scoped BigOperators
section Real
open Real
namespace Bertrand
/-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> norm_num1
apply le_trans _ (le_mul_of_one_le_left _ _) <;> norm_num1
apply Real.rpow_le_rpow <;> norm_num1
apply rpow_nonneg_of_nonneg; norm_num1
apply rpow_pos_of_pos; norm_num1
apply hf' 18; norm_num1
norm_num1
Β· have : sqrt (2 * 512) = 32 :=
(sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonpos_iff (hf' _ _), this, div_le_one] <;> norm_num1
Β· conv in 512 => equals 2 ^ 9 => norm_num1
conv in 1024 => equals 2 ^ 10 => norm_num1
conv in 32 => rw [β Nat.cast_ofNat]
rw [rpow_nat_cast, β pow_mul, β pow_add]
conv in 4 => equals 2 ^ (2 : β) => rw [rpow_two]; norm_num1
rw [β rpow_mul, β rpow_nat_cast]
apply rpow_le_rpow_of_exponent_le
all_goals norm_num1
Β· apply rpow_pos_of_pos four_pos
#align bertrand.real_main_inequality Bertrand.real_main_inequality
end Bertrand
end Real
section Nat
open Nat
/-- The inequality which contradicts Bertrand's postulate, for large enough `n`.
-/
theorem bertrand_main_inequality {n : β} (n_large : 512 β€ n) :
n * (2 * n) ^ sqrt (2 * n) * 4 ^ (2 * n / 3) β€ 4 ^ n := by
rw [β @cast_le β]
simp only [cast_add, cast_one, cast_mul, cast_pow, β Real.rpow_nat_cast]
refine' _root_.trans ?_ (Bertrand.real_main_inequality (by exact_mod_cast n_large))
gcongr
Β· have n2_pos : 0 < 2 * n := by positivity
exact mod_cast n2_pos
Β· exact_mod_cast Real.nat_sqrt_le_real_sqrt
Β· norm_num1
Β· exact cast_div_le.trans (by norm_cast)
#align bertrand_main_inequality bertrand_main_inequality
/-- A lemma that tells us that, in the case where Bertrand's postulate does not hold, the prime
factorization of the central binomial coefficent only has factors at most `2 * n / 3 + 1`.
-/
theorem centralBinom_factorization_small (n : β) (n_large : 2 < n)
(no_prime : Β¬β p : β, p.Prime β§ n < p β§ p β€ 2 * n) :
centralBinom n = β p in Finset.range (2 * n / 3 + 1), p ^ (centralBinom n).factorization p := by
refine' (Eq.trans _ n.prod_pow_factorization_centralBinom).symm
apply Finset.prod_subset
Β· exact Finset.range_subset.2 (add_le_add_right (Nat.div_le_self _ _) _)
intro x hx h2x
rw [Finset.mem_range, lt_succ_iff] at hx h2x
rw [not_le, div_lt_iff_lt_mul' three_pos, mul_comm x] at h2x
replace no_prime := not_exists.mp no_prime x
rw [β and_assoc, not_and', not_and_or, not_lt] at no_prime
cases' no_prime hx with h h
Β· rw [factorization_eq_zero_of_non_prime n.centralBinom h, Nat.pow_zero]
Β· rw [factorization_centralBinom_of_two_mul_self_lt_three_mul n_large h h2x, Nat.pow_zero]
#align central_binom_factorization_small centralBinom_factorization_small
/-- An upper bound on the central binomial coefficient used in the proof of Bertrand's postulate.
The bound splits the prime factors of `centralBinom n` into those
1. At most `sqrt (2 * n)`, which contribute at most `2 * n` for each such prime.
2. Between `sqrt (2 * n)` and `2 * n / 3`, which contribute at most `4^(2 * n / 3)` in total.
3. Between `2 * n / 3` and `n`, which do not exist.
4. Between `n` and `2 * n`, which would not exist in the case where Bertrand's postulate is false.
5. Above `2 * n`, which do not exist.
-/
theorem centralBinom_le_of_no_bertrand_prime (n : β) (n_big : 2 < n)
(no_prime : Β¬β p : β, Nat.Prime p β§ n < p β§ p β€ 2 * n) :
centralBinom n β€ (2 * n) ^ sqrt (2 * n) * 4 ^ (2 * n / 3) := by
have n_pos : 0 < n := (Nat.zero_le _).trans_lt n_big
| have n2_pos : 1 β€ 2 * n := mul_pos (zero_lt_two' β) n_pos | /-- An upper bound on the central binomial coefficient used in the proof of Bertrand's postulate.
The bound splits the prime factors of `centralBinom n` into those
1. At most `sqrt (2 * n)`, which contribute at most `2 * n` for each such prime.
2. Between `sqrt (2 * n)` and `2 * n / 3`, which contribute at most `4^(2 * n / 3)` in total.
3. Between `2 * n / 3` and `n`, which do not exist.
4. Between `n` and `2 * n`, which would not exist in the case where Bertrand's postulate is false.
5. Above `2 * n`, which do not exist.
-/
theorem centralBinom_le_of_no_bertrand_prime (n : β) (n_big : 2 < n)
(no_prime : Β¬β p : β, Nat.Prime p β§ n < p β§ p β€ 2 * n) :
centralBinom n β€ (2 * n) ^ sqrt (2 * n) * 4 ^ (2 * n / 3) := by
have n_pos : 0 < n := (Nat.zero_le _).trans_lt n_big
| Mathlib.NumberTheory.Bertrand.155_0.gJXoOT9Ce2wC0xc | /-- An upper bound on the central binomial coefficient used in the proof of Bertrand's postulate.
The bound splits the prime factors of `centralBinom n` into those
1. At most `sqrt (2 * n)`, which contribute at most `2 * n` for each such prime.
2. Between `sqrt (2 * n)` and `2 * n / 3`, which contribute at most `4^(2 * n / 3)` in total.
3. Between `2 * n / 3` and `n`, which do not exist.
4. Between `n` and `2 * n`, which would not exist in the case where Bertrand's postulate is false.
5. Above `2 * n`, which do not exist.
-/
theorem centralBinom_le_of_no_bertrand_prime (n : β) (n_big : 2 < n)
(no_prime : Β¬β p : β, Nat.Prime p β§ n < p β§ p β€ 2 * n) :
centralBinom n β€ (2 * n) ^ sqrt (2 * n) * 4 ^ (2 * n / 3) | Mathlib_NumberTheory_Bertrand |
n : β
n_big : 2 < n
no_prime : Β¬β p, Nat.Prime p β§ n < p β§ p β€ 2 * n
n_pos : 0 < n
n2_pos : 1 β€ 2 * n
β’ centralBinom n β€ (2 * n) ^ sqrt (2 * n) * 4 ^ (2 * n / 3) | /-
Copyright (c) 2020 Patrick Stevens. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Stevens, Bolton Bailey
-/
import Mathlib.Data.Nat.Choose.Factorization
import Mathlib.Data.Nat.PrimeNormNum
import Mathlib.NumberTheory.Primorial
import Mathlib.Analysis.Convex.SpecificFunctions.Basic
import Mathlib.Analysis.Convex.SpecificFunctions.Deriv
#align_import number_theory.bertrand from "leanprover-community/mathlib"@"a16665637b378379689c566204817ae792ac8b39"
/-!
# Bertrand's Postulate
This file contains a proof of Bertrand's postulate: That between any positive number and its
double there is a prime.
The proof follows the outline of the ErdΕs proof presented in "Proofs from THE BOOK": One considers
the prime factorization of `(2 * n).choose n`, and splits the constituent primes up into various
groups, then upper bounds the contribution of each group. This upper bounds the central binomial
coefficient, and if the postulate does not hold, this upper bound conflicts with a simple lower
bound for large enough `n`. This proves the result holds for large enough `n`, and for smaller `n`
an explicit list of primes is provided which covers the remaining cases.
As in the [Metamath implementation](carneiro2015arithmetic), we rely on some optimizations from
[Shigenori Tochiori](tochiori_bertrand). In particular we use the cleaner bound on the central
binomial coefficient given in `Nat.four_pow_lt_mul_centralBinom`.
## References
* [M. Aigner and G. M. Ziegler _Proofs from THE BOOK_][aigner1999proofs]
* [S. Tochiori, _Considering the Proof of βThere is a Prime between n and 2nβ_][tochiori_bertrand]
* [M. Carneiro, _Arithmetic in Metamath, Case Study: Bertrand's Postulate_][carneiro2015arithmetic]
## Tags
Bertrand, prime, binomial coefficients
-/
open scoped BigOperators
section Real
open Real
namespace Bertrand
/-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> norm_num1
apply le_trans _ (le_mul_of_one_le_left _ _) <;> norm_num1
apply Real.rpow_le_rpow <;> norm_num1
apply rpow_nonneg_of_nonneg; norm_num1
apply rpow_pos_of_pos; norm_num1
apply hf' 18; norm_num1
norm_num1
Β· have : sqrt (2 * 512) = 32 :=
(sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonpos_iff (hf' _ _), this, div_le_one] <;> norm_num1
Β· conv in 512 => equals 2 ^ 9 => norm_num1
conv in 1024 => equals 2 ^ 10 => norm_num1
conv in 32 => rw [β Nat.cast_ofNat]
rw [rpow_nat_cast, β pow_mul, β pow_add]
conv in 4 => equals 2 ^ (2 : β) => rw [rpow_two]; norm_num1
rw [β rpow_mul, β rpow_nat_cast]
apply rpow_le_rpow_of_exponent_le
all_goals norm_num1
Β· apply rpow_pos_of_pos four_pos
#align bertrand.real_main_inequality Bertrand.real_main_inequality
end Bertrand
end Real
section Nat
open Nat
/-- The inequality which contradicts Bertrand's postulate, for large enough `n`.
-/
theorem bertrand_main_inequality {n : β} (n_large : 512 β€ n) :
n * (2 * n) ^ sqrt (2 * n) * 4 ^ (2 * n / 3) β€ 4 ^ n := by
rw [β @cast_le β]
simp only [cast_add, cast_one, cast_mul, cast_pow, β Real.rpow_nat_cast]
refine' _root_.trans ?_ (Bertrand.real_main_inequality (by exact_mod_cast n_large))
gcongr
Β· have n2_pos : 0 < 2 * n := by positivity
exact mod_cast n2_pos
Β· exact_mod_cast Real.nat_sqrt_le_real_sqrt
Β· norm_num1
Β· exact cast_div_le.trans (by norm_cast)
#align bertrand_main_inequality bertrand_main_inequality
/-- A lemma that tells us that, in the case where Bertrand's postulate does not hold, the prime
factorization of the central binomial coefficent only has factors at most `2 * n / 3 + 1`.
-/
theorem centralBinom_factorization_small (n : β) (n_large : 2 < n)
(no_prime : Β¬β p : β, p.Prime β§ n < p β§ p β€ 2 * n) :
centralBinom n = β p in Finset.range (2 * n / 3 + 1), p ^ (centralBinom n).factorization p := by
refine' (Eq.trans _ n.prod_pow_factorization_centralBinom).symm
apply Finset.prod_subset
Β· exact Finset.range_subset.2 (add_le_add_right (Nat.div_le_self _ _) _)
intro x hx h2x
rw [Finset.mem_range, lt_succ_iff] at hx h2x
rw [not_le, div_lt_iff_lt_mul' three_pos, mul_comm x] at h2x
replace no_prime := not_exists.mp no_prime x
rw [β and_assoc, not_and', not_and_or, not_lt] at no_prime
cases' no_prime hx with h h
Β· rw [factorization_eq_zero_of_non_prime n.centralBinom h, Nat.pow_zero]
Β· rw [factorization_centralBinom_of_two_mul_self_lt_three_mul n_large h h2x, Nat.pow_zero]
#align central_binom_factorization_small centralBinom_factorization_small
/-- An upper bound on the central binomial coefficient used in the proof of Bertrand's postulate.
The bound splits the prime factors of `centralBinom n` into those
1. At most `sqrt (2 * n)`, which contribute at most `2 * n` for each such prime.
2. Between `sqrt (2 * n)` and `2 * n / 3`, which contribute at most `4^(2 * n / 3)` in total.
3. Between `2 * n / 3` and `n`, which do not exist.
4. Between `n` and `2 * n`, which would not exist in the case where Bertrand's postulate is false.
5. Above `2 * n`, which do not exist.
-/
theorem centralBinom_le_of_no_bertrand_prime (n : β) (n_big : 2 < n)
(no_prime : Β¬β p : β, Nat.Prime p β§ n < p β§ p β€ 2 * n) :
centralBinom n β€ (2 * n) ^ sqrt (2 * n) * 4 ^ (2 * n / 3) := by
have n_pos : 0 < n := (Nat.zero_le _).trans_lt n_big
have n2_pos : 1 β€ 2 * n := mul_pos (zero_lt_two' β) n_pos
| let S := (Finset.range (2 * n / 3 + 1)).filter Nat.Prime | /-- An upper bound on the central binomial coefficient used in the proof of Bertrand's postulate.
The bound splits the prime factors of `centralBinom n` into those
1. At most `sqrt (2 * n)`, which contribute at most `2 * n` for each such prime.
2. Between `sqrt (2 * n)` and `2 * n / 3`, which contribute at most `4^(2 * n / 3)` in total.
3. Between `2 * n / 3` and `n`, which do not exist.
4. Between `n` and `2 * n`, which would not exist in the case where Bertrand's postulate is false.
5. Above `2 * n`, which do not exist.
-/
theorem centralBinom_le_of_no_bertrand_prime (n : β) (n_big : 2 < n)
(no_prime : Β¬β p : β, Nat.Prime p β§ n < p β§ p β€ 2 * n) :
centralBinom n β€ (2 * n) ^ sqrt (2 * n) * 4 ^ (2 * n / 3) := by
have n_pos : 0 < n := (Nat.zero_le _).trans_lt n_big
have n2_pos : 1 β€ 2 * n := mul_pos (zero_lt_two' β) n_pos
| Mathlib.NumberTheory.Bertrand.155_0.gJXoOT9Ce2wC0xc | /-- An upper bound on the central binomial coefficient used in the proof of Bertrand's postulate.
The bound splits the prime factors of `centralBinom n` into those
1. At most `sqrt (2 * n)`, which contribute at most `2 * n` for each such prime.
2. Between `sqrt (2 * n)` and `2 * n / 3`, which contribute at most `4^(2 * n / 3)` in total.
3. Between `2 * n / 3` and `n`, which do not exist.
4. Between `n` and `2 * n`, which would not exist in the case where Bertrand's postulate is false.
5. Above `2 * n`, which do not exist.
-/
theorem centralBinom_le_of_no_bertrand_prime (n : β) (n_big : 2 < n)
(no_prime : Β¬β p : β, Nat.Prime p β§ n < p β§ p β€ 2 * n) :
centralBinom n β€ (2 * n) ^ sqrt (2 * n) * 4 ^ (2 * n / 3) | Mathlib_NumberTheory_Bertrand |
n : β
n_big : 2 < n
no_prime : Β¬β p, Nat.Prime p β§ n < p β§ p β€ 2 * n
n_pos : 0 < n
n2_pos : 1 β€ 2 * n
S : Finset β := Finset.filter Nat.Prime (Finset.range (2 * n / 3 + 1))
β’ centralBinom n β€ (2 * n) ^ sqrt (2 * n) * 4 ^ (2 * n / 3) | /-
Copyright (c) 2020 Patrick Stevens. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Stevens, Bolton Bailey
-/
import Mathlib.Data.Nat.Choose.Factorization
import Mathlib.Data.Nat.PrimeNormNum
import Mathlib.NumberTheory.Primorial
import Mathlib.Analysis.Convex.SpecificFunctions.Basic
import Mathlib.Analysis.Convex.SpecificFunctions.Deriv
#align_import number_theory.bertrand from "leanprover-community/mathlib"@"a16665637b378379689c566204817ae792ac8b39"
/-!
# Bertrand's Postulate
This file contains a proof of Bertrand's postulate: That between any positive number and its
double there is a prime.
The proof follows the outline of the ErdΕs proof presented in "Proofs from THE BOOK": One considers
the prime factorization of `(2 * n).choose n`, and splits the constituent primes up into various
groups, then upper bounds the contribution of each group. This upper bounds the central binomial
coefficient, and if the postulate does not hold, this upper bound conflicts with a simple lower
bound for large enough `n`. This proves the result holds for large enough `n`, and for smaller `n`
an explicit list of primes is provided which covers the remaining cases.
As in the [Metamath implementation](carneiro2015arithmetic), we rely on some optimizations from
[Shigenori Tochiori](tochiori_bertrand). In particular we use the cleaner bound on the central
binomial coefficient given in `Nat.four_pow_lt_mul_centralBinom`.
## References
* [M. Aigner and G. M. Ziegler _Proofs from THE BOOK_][aigner1999proofs]
* [S. Tochiori, _Considering the Proof of βThere is a Prime between n and 2nβ_][tochiori_bertrand]
* [M. Carneiro, _Arithmetic in Metamath, Case Study: Bertrand's Postulate_][carneiro2015arithmetic]
## Tags
Bertrand, prime, binomial coefficients
-/
open scoped BigOperators
section Real
open Real
namespace Bertrand
/-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> norm_num1
apply le_trans _ (le_mul_of_one_le_left _ _) <;> norm_num1
apply Real.rpow_le_rpow <;> norm_num1
apply rpow_nonneg_of_nonneg; norm_num1
apply rpow_pos_of_pos; norm_num1
apply hf' 18; norm_num1
norm_num1
Β· have : sqrt (2 * 512) = 32 :=
(sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonpos_iff (hf' _ _), this, div_le_one] <;> norm_num1
Β· conv in 512 => equals 2 ^ 9 => norm_num1
conv in 1024 => equals 2 ^ 10 => norm_num1
conv in 32 => rw [β Nat.cast_ofNat]
rw [rpow_nat_cast, β pow_mul, β pow_add]
conv in 4 => equals 2 ^ (2 : β) => rw [rpow_two]; norm_num1
rw [β rpow_mul, β rpow_nat_cast]
apply rpow_le_rpow_of_exponent_le
all_goals norm_num1
Β· apply rpow_pos_of_pos four_pos
#align bertrand.real_main_inequality Bertrand.real_main_inequality
end Bertrand
end Real
section Nat
open Nat
/-- The inequality which contradicts Bertrand's postulate, for large enough `n`.
-/
theorem bertrand_main_inequality {n : β} (n_large : 512 β€ n) :
n * (2 * n) ^ sqrt (2 * n) * 4 ^ (2 * n / 3) β€ 4 ^ n := by
rw [β @cast_le β]
simp only [cast_add, cast_one, cast_mul, cast_pow, β Real.rpow_nat_cast]
refine' _root_.trans ?_ (Bertrand.real_main_inequality (by exact_mod_cast n_large))
gcongr
Β· have n2_pos : 0 < 2 * n := by positivity
exact mod_cast n2_pos
Β· exact_mod_cast Real.nat_sqrt_le_real_sqrt
Β· norm_num1
Β· exact cast_div_le.trans (by norm_cast)
#align bertrand_main_inequality bertrand_main_inequality
/-- A lemma that tells us that, in the case where Bertrand's postulate does not hold, the prime
factorization of the central binomial coefficent only has factors at most `2 * n / 3 + 1`.
-/
theorem centralBinom_factorization_small (n : β) (n_large : 2 < n)
(no_prime : Β¬β p : β, p.Prime β§ n < p β§ p β€ 2 * n) :
centralBinom n = β p in Finset.range (2 * n / 3 + 1), p ^ (centralBinom n).factorization p := by
refine' (Eq.trans _ n.prod_pow_factorization_centralBinom).symm
apply Finset.prod_subset
Β· exact Finset.range_subset.2 (add_le_add_right (Nat.div_le_self _ _) _)
intro x hx h2x
rw [Finset.mem_range, lt_succ_iff] at hx h2x
rw [not_le, div_lt_iff_lt_mul' three_pos, mul_comm x] at h2x
replace no_prime := not_exists.mp no_prime x
rw [β and_assoc, not_and', not_and_or, not_lt] at no_prime
cases' no_prime hx with h h
Β· rw [factorization_eq_zero_of_non_prime n.centralBinom h, Nat.pow_zero]
Β· rw [factorization_centralBinom_of_two_mul_self_lt_three_mul n_large h h2x, Nat.pow_zero]
#align central_binom_factorization_small centralBinom_factorization_small
/-- An upper bound on the central binomial coefficient used in the proof of Bertrand's postulate.
The bound splits the prime factors of `centralBinom n` into those
1. At most `sqrt (2 * n)`, which contribute at most `2 * n` for each such prime.
2. Between `sqrt (2 * n)` and `2 * n / 3`, which contribute at most `4^(2 * n / 3)` in total.
3. Between `2 * n / 3` and `n`, which do not exist.
4. Between `n` and `2 * n`, which would not exist in the case where Bertrand's postulate is false.
5. Above `2 * n`, which do not exist.
-/
theorem centralBinom_le_of_no_bertrand_prime (n : β) (n_big : 2 < n)
(no_prime : Β¬β p : β, Nat.Prime p β§ n < p β§ p β€ 2 * n) :
centralBinom n β€ (2 * n) ^ sqrt (2 * n) * 4 ^ (2 * n / 3) := by
have n_pos : 0 < n := (Nat.zero_le _).trans_lt n_big
have n2_pos : 1 β€ 2 * n := mul_pos (zero_lt_two' β) n_pos
let S := (Finset.range (2 * n / 3 + 1)).filter Nat.Prime
| let f x := x ^ n.centralBinom.factorization x | /-- An upper bound on the central binomial coefficient used in the proof of Bertrand's postulate.
The bound splits the prime factors of `centralBinom n` into those
1. At most `sqrt (2 * n)`, which contribute at most `2 * n` for each such prime.
2. Between `sqrt (2 * n)` and `2 * n / 3`, which contribute at most `4^(2 * n / 3)` in total.
3. Between `2 * n / 3` and `n`, which do not exist.
4. Between `n` and `2 * n`, which would not exist in the case where Bertrand's postulate is false.
5. Above `2 * n`, which do not exist.
-/
theorem centralBinom_le_of_no_bertrand_prime (n : β) (n_big : 2 < n)
(no_prime : Β¬β p : β, Nat.Prime p β§ n < p β§ p β€ 2 * n) :
centralBinom n β€ (2 * n) ^ sqrt (2 * n) * 4 ^ (2 * n / 3) := by
have n_pos : 0 < n := (Nat.zero_le _).trans_lt n_big
have n2_pos : 1 β€ 2 * n := mul_pos (zero_lt_two' β) n_pos
let S := (Finset.range (2 * n / 3 + 1)).filter Nat.Prime
| Mathlib.NumberTheory.Bertrand.155_0.gJXoOT9Ce2wC0xc | /-- An upper bound on the central binomial coefficient used in the proof of Bertrand's postulate.
The bound splits the prime factors of `centralBinom n` into those
1. At most `sqrt (2 * n)`, which contribute at most `2 * n` for each such prime.
2. Between `sqrt (2 * n)` and `2 * n / 3`, which contribute at most `4^(2 * n / 3)` in total.
3. Between `2 * n / 3` and `n`, which do not exist.
4. Between `n` and `2 * n`, which would not exist in the case where Bertrand's postulate is false.
5. Above `2 * n`, which do not exist.
-/
theorem centralBinom_le_of_no_bertrand_prime (n : β) (n_big : 2 < n)
(no_prime : Β¬β p : β, Nat.Prime p β§ n < p β§ p β€ 2 * n) :
centralBinom n β€ (2 * n) ^ sqrt (2 * n) * 4 ^ (2 * n / 3) | Mathlib_NumberTheory_Bertrand |
n : β
n_big : 2 < n
no_prime : Β¬β p, Nat.Prime p β§ n < p β§ p β€ 2 * n
n_pos : 0 < n
n2_pos : 1 β€ 2 * n
S : Finset β := Finset.filter Nat.Prime (Finset.range (2 * n / 3 + 1))
f : β β β := fun x => x ^ (Nat.factorization (centralBinom n)) x
β’ centralBinom n β€ (2 * n) ^ sqrt (2 * n) * 4 ^ (2 * n / 3) | /-
Copyright (c) 2020 Patrick Stevens. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Stevens, Bolton Bailey
-/
import Mathlib.Data.Nat.Choose.Factorization
import Mathlib.Data.Nat.PrimeNormNum
import Mathlib.NumberTheory.Primorial
import Mathlib.Analysis.Convex.SpecificFunctions.Basic
import Mathlib.Analysis.Convex.SpecificFunctions.Deriv
#align_import number_theory.bertrand from "leanprover-community/mathlib"@"a16665637b378379689c566204817ae792ac8b39"
/-!
# Bertrand's Postulate
This file contains a proof of Bertrand's postulate: That between any positive number and its
double there is a prime.
The proof follows the outline of the ErdΕs proof presented in "Proofs from THE BOOK": One considers
the prime factorization of `(2 * n).choose n`, and splits the constituent primes up into various
groups, then upper bounds the contribution of each group. This upper bounds the central binomial
coefficient, and if the postulate does not hold, this upper bound conflicts with a simple lower
bound for large enough `n`. This proves the result holds for large enough `n`, and for smaller `n`
an explicit list of primes is provided which covers the remaining cases.
As in the [Metamath implementation](carneiro2015arithmetic), we rely on some optimizations from
[Shigenori Tochiori](tochiori_bertrand). In particular we use the cleaner bound on the central
binomial coefficient given in `Nat.four_pow_lt_mul_centralBinom`.
## References
* [M. Aigner and G. M. Ziegler _Proofs from THE BOOK_][aigner1999proofs]
* [S. Tochiori, _Considering the Proof of βThere is a Prime between n and 2nβ_][tochiori_bertrand]
* [M. Carneiro, _Arithmetic in Metamath, Case Study: Bertrand's Postulate_][carneiro2015arithmetic]
## Tags
Bertrand, prime, binomial coefficients
-/
open scoped BigOperators
section Real
open Real
namespace Bertrand
/-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> norm_num1
apply le_trans _ (le_mul_of_one_le_left _ _) <;> norm_num1
apply Real.rpow_le_rpow <;> norm_num1
apply rpow_nonneg_of_nonneg; norm_num1
apply rpow_pos_of_pos; norm_num1
apply hf' 18; norm_num1
norm_num1
Β· have : sqrt (2 * 512) = 32 :=
(sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonpos_iff (hf' _ _), this, div_le_one] <;> norm_num1
Β· conv in 512 => equals 2 ^ 9 => norm_num1
conv in 1024 => equals 2 ^ 10 => norm_num1
conv in 32 => rw [β Nat.cast_ofNat]
rw [rpow_nat_cast, β pow_mul, β pow_add]
conv in 4 => equals 2 ^ (2 : β) => rw [rpow_two]; norm_num1
rw [β rpow_mul, β rpow_nat_cast]
apply rpow_le_rpow_of_exponent_le
all_goals norm_num1
Β· apply rpow_pos_of_pos four_pos
#align bertrand.real_main_inequality Bertrand.real_main_inequality
end Bertrand
end Real
section Nat
open Nat
/-- The inequality which contradicts Bertrand's postulate, for large enough `n`.
-/
theorem bertrand_main_inequality {n : β} (n_large : 512 β€ n) :
n * (2 * n) ^ sqrt (2 * n) * 4 ^ (2 * n / 3) β€ 4 ^ n := by
rw [β @cast_le β]
simp only [cast_add, cast_one, cast_mul, cast_pow, β Real.rpow_nat_cast]
refine' _root_.trans ?_ (Bertrand.real_main_inequality (by exact_mod_cast n_large))
gcongr
Β· have n2_pos : 0 < 2 * n := by positivity
exact mod_cast n2_pos
Β· exact_mod_cast Real.nat_sqrt_le_real_sqrt
Β· norm_num1
Β· exact cast_div_le.trans (by norm_cast)
#align bertrand_main_inequality bertrand_main_inequality
/-- A lemma that tells us that, in the case where Bertrand's postulate does not hold, the prime
factorization of the central binomial coefficent only has factors at most `2 * n / 3 + 1`.
-/
theorem centralBinom_factorization_small (n : β) (n_large : 2 < n)
(no_prime : Β¬β p : β, p.Prime β§ n < p β§ p β€ 2 * n) :
centralBinom n = β p in Finset.range (2 * n / 3 + 1), p ^ (centralBinom n).factorization p := by
refine' (Eq.trans _ n.prod_pow_factorization_centralBinom).symm
apply Finset.prod_subset
Β· exact Finset.range_subset.2 (add_le_add_right (Nat.div_le_self _ _) _)
intro x hx h2x
rw [Finset.mem_range, lt_succ_iff] at hx h2x
rw [not_le, div_lt_iff_lt_mul' three_pos, mul_comm x] at h2x
replace no_prime := not_exists.mp no_prime x
rw [β and_assoc, not_and', not_and_or, not_lt] at no_prime
cases' no_prime hx with h h
Β· rw [factorization_eq_zero_of_non_prime n.centralBinom h, Nat.pow_zero]
Β· rw [factorization_centralBinom_of_two_mul_self_lt_three_mul n_large h h2x, Nat.pow_zero]
#align central_binom_factorization_small centralBinom_factorization_small
/-- An upper bound on the central binomial coefficient used in the proof of Bertrand's postulate.
The bound splits the prime factors of `centralBinom n` into those
1. At most `sqrt (2 * n)`, which contribute at most `2 * n` for each such prime.
2. Between `sqrt (2 * n)` and `2 * n / 3`, which contribute at most `4^(2 * n / 3)` in total.
3. Between `2 * n / 3` and `n`, which do not exist.
4. Between `n` and `2 * n`, which would not exist in the case where Bertrand's postulate is false.
5. Above `2 * n`, which do not exist.
-/
theorem centralBinom_le_of_no_bertrand_prime (n : β) (n_big : 2 < n)
(no_prime : Β¬β p : β, Nat.Prime p β§ n < p β§ p β€ 2 * n) :
centralBinom n β€ (2 * n) ^ sqrt (2 * n) * 4 ^ (2 * n / 3) := by
have n_pos : 0 < n := (Nat.zero_le _).trans_lt n_big
have n2_pos : 1 β€ 2 * n := mul_pos (zero_lt_two' β) n_pos
let S := (Finset.range (2 * n / 3 + 1)).filter Nat.Prime
let f x := x ^ n.centralBinom.factorization x
| have : β x : β in S, f x = β x : β in Finset.range (2 * n / 3 + 1), f x := by
refine' Finset.prod_filter_of_ne fun p _ h => _
contrapose! h; dsimp only
rw [factorization_eq_zero_of_non_prime n.centralBinom h, _root_.pow_zero] | /-- An upper bound on the central binomial coefficient used in the proof of Bertrand's postulate.
The bound splits the prime factors of `centralBinom n` into those
1. At most `sqrt (2 * n)`, which contribute at most `2 * n` for each such prime.
2. Between `sqrt (2 * n)` and `2 * n / 3`, which contribute at most `4^(2 * n / 3)` in total.
3. Between `2 * n / 3` and `n`, which do not exist.
4. Between `n` and `2 * n`, which would not exist in the case where Bertrand's postulate is false.
5. Above `2 * n`, which do not exist.
-/
theorem centralBinom_le_of_no_bertrand_prime (n : β) (n_big : 2 < n)
(no_prime : Β¬β p : β, Nat.Prime p β§ n < p β§ p β€ 2 * n) :
centralBinom n β€ (2 * n) ^ sqrt (2 * n) * 4 ^ (2 * n / 3) := by
have n_pos : 0 < n := (Nat.zero_le _).trans_lt n_big
have n2_pos : 1 β€ 2 * n := mul_pos (zero_lt_two' β) n_pos
let S := (Finset.range (2 * n / 3 + 1)).filter Nat.Prime
let f x := x ^ n.centralBinom.factorization x
| Mathlib.NumberTheory.Bertrand.155_0.gJXoOT9Ce2wC0xc | /-- An upper bound on the central binomial coefficient used in the proof of Bertrand's postulate.
The bound splits the prime factors of `centralBinom n` into those
1. At most `sqrt (2 * n)`, which contribute at most `2 * n` for each such prime.
2. Between `sqrt (2 * n)` and `2 * n / 3`, which contribute at most `4^(2 * n / 3)` in total.
3. Between `2 * n / 3` and `n`, which do not exist.
4. Between `n` and `2 * n`, which would not exist in the case where Bertrand's postulate is false.
5. Above `2 * n`, which do not exist.
-/
theorem centralBinom_le_of_no_bertrand_prime (n : β) (n_big : 2 < n)
(no_prime : Β¬β p : β, Nat.Prime p β§ n < p β§ p β€ 2 * n) :
centralBinom n β€ (2 * n) ^ sqrt (2 * n) * 4 ^ (2 * n / 3) | Mathlib_NumberTheory_Bertrand |
n : β
n_big : 2 < n
no_prime : Β¬β p, Nat.Prime p β§ n < p β§ p β€ 2 * n
n_pos : 0 < n
n2_pos : 1 β€ 2 * n
S : Finset β := Finset.filter Nat.Prime (Finset.range (2 * n / 3 + 1))
f : β β β := fun x => x ^ (Nat.factorization (centralBinom n)) x
β’ β x in S, f x = β x in Finset.range (2 * n / 3 + 1), f x | /-
Copyright (c) 2020 Patrick Stevens. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Stevens, Bolton Bailey
-/
import Mathlib.Data.Nat.Choose.Factorization
import Mathlib.Data.Nat.PrimeNormNum
import Mathlib.NumberTheory.Primorial
import Mathlib.Analysis.Convex.SpecificFunctions.Basic
import Mathlib.Analysis.Convex.SpecificFunctions.Deriv
#align_import number_theory.bertrand from "leanprover-community/mathlib"@"a16665637b378379689c566204817ae792ac8b39"
/-!
# Bertrand's Postulate
This file contains a proof of Bertrand's postulate: That between any positive number and its
double there is a prime.
The proof follows the outline of the ErdΕs proof presented in "Proofs from THE BOOK": One considers
the prime factorization of `(2 * n).choose n`, and splits the constituent primes up into various
groups, then upper bounds the contribution of each group. This upper bounds the central binomial
coefficient, and if the postulate does not hold, this upper bound conflicts with a simple lower
bound for large enough `n`. This proves the result holds for large enough `n`, and for smaller `n`
an explicit list of primes is provided which covers the remaining cases.
As in the [Metamath implementation](carneiro2015arithmetic), we rely on some optimizations from
[Shigenori Tochiori](tochiori_bertrand). In particular we use the cleaner bound on the central
binomial coefficient given in `Nat.four_pow_lt_mul_centralBinom`.
## References
* [M. Aigner and G. M. Ziegler _Proofs from THE BOOK_][aigner1999proofs]
* [S. Tochiori, _Considering the Proof of βThere is a Prime between n and 2nβ_][tochiori_bertrand]
* [M. Carneiro, _Arithmetic in Metamath, Case Study: Bertrand's Postulate_][carneiro2015arithmetic]
## Tags
Bertrand, prime, binomial coefficients
-/
open scoped BigOperators
section Real
open Real
namespace Bertrand
/-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> norm_num1
apply le_trans _ (le_mul_of_one_le_left _ _) <;> norm_num1
apply Real.rpow_le_rpow <;> norm_num1
apply rpow_nonneg_of_nonneg; norm_num1
apply rpow_pos_of_pos; norm_num1
apply hf' 18; norm_num1
norm_num1
Β· have : sqrt (2 * 512) = 32 :=
(sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonpos_iff (hf' _ _), this, div_le_one] <;> norm_num1
Β· conv in 512 => equals 2 ^ 9 => norm_num1
conv in 1024 => equals 2 ^ 10 => norm_num1
conv in 32 => rw [β Nat.cast_ofNat]
rw [rpow_nat_cast, β pow_mul, β pow_add]
conv in 4 => equals 2 ^ (2 : β) => rw [rpow_two]; norm_num1
rw [β rpow_mul, β rpow_nat_cast]
apply rpow_le_rpow_of_exponent_le
all_goals norm_num1
Β· apply rpow_pos_of_pos four_pos
#align bertrand.real_main_inequality Bertrand.real_main_inequality
end Bertrand
end Real
section Nat
open Nat
/-- The inequality which contradicts Bertrand's postulate, for large enough `n`.
-/
theorem bertrand_main_inequality {n : β} (n_large : 512 β€ n) :
n * (2 * n) ^ sqrt (2 * n) * 4 ^ (2 * n / 3) β€ 4 ^ n := by
rw [β @cast_le β]
simp only [cast_add, cast_one, cast_mul, cast_pow, β Real.rpow_nat_cast]
refine' _root_.trans ?_ (Bertrand.real_main_inequality (by exact_mod_cast n_large))
gcongr
Β· have n2_pos : 0 < 2 * n := by positivity
exact mod_cast n2_pos
Β· exact_mod_cast Real.nat_sqrt_le_real_sqrt
Β· norm_num1
Β· exact cast_div_le.trans (by norm_cast)
#align bertrand_main_inequality bertrand_main_inequality
/-- A lemma that tells us that, in the case where Bertrand's postulate does not hold, the prime
factorization of the central binomial coefficent only has factors at most `2 * n / 3 + 1`.
-/
theorem centralBinom_factorization_small (n : β) (n_large : 2 < n)
(no_prime : Β¬β p : β, p.Prime β§ n < p β§ p β€ 2 * n) :
centralBinom n = β p in Finset.range (2 * n / 3 + 1), p ^ (centralBinom n).factorization p := by
refine' (Eq.trans _ n.prod_pow_factorization_centralBinom).symm
apply Finset.prod_subset
Β· exact Finset.range_subset.2 (add_le_add_right (Nat.div_le_self _ _) _)
intro x hx h2x
rw [Finset.mem_range, lt_succ_iff] at hx h2x
rw [not_le, div_lt_iff_lt_mul' three_pos, mul_comm x] at h2x
replace no_prime := not_exists.mp no_prime x
rw [β and_assoc, not_and', not_and_or, not_lt] at no_prime
cases' no_prime hx with h h
Β· rw [factorization_eq_zero_of_non_prime n.centralBinom h, Nat.pow_zero]
Β· rw [factorization_centralBinom_of_two_mul_self_lt_three_mul n_large h h2x, Nat.pow_zero]
#align central_binom_factorization_small centralBinom_factorization_small
/-- An upper bound on the central binomial coefficient used in the proof of Bertrand's postulate.
The bound splits the prime factors of `centralBinom n` into those
1. At most `sqrt (2 * n)`, which contribute at most `2 * n` for each such prime.
2. Between `sqrt (2 * n)` and `2 * n / 3`, which contribute at most `4^(2 * n / 3)` in total.
3. Between `2 * n / 3` and `n`, which do not exist.
4. Between `n` and `2 * n`, which would not exist in the case where Bertrand's postulate is false.
5. Above `2 * n`, which do not exist.
-/
theorem centralBinom_le_of_no_bertrand_prime (n : β) (n_big : 2 < n)
(no_prime : Β¬β p : β, Nat.Prime p β§ n < p β§ p β€ 2 * n) :
centralBinom n β€ (2 * n) ^ sqrt (2 * n) * 4 ^ (2 * n / 3) := by
have n_pos : 0 < n := (Nat.zero_le _).trans_lt n_big
have n2_pos : 1 β€ 2 * n := mul_pos (zero_lt_two' β) n_pos
let S := (Finset.range (2 * n / 3 + 1)).filter Nat.Prime
let f x := x ^ n.centralBinom.factorization x
have : β x : β in S, f x = β x : β in Finset.range (2 * n / 3 + 1), f x := by
| refine' Finset.prod_filter_of_ne fun p _ h => _ | /-- An upper bound on the central binomial coefficient used in the proof of Bertrand's postulate.
The bound splits the prime factors of `centralBinom n` into those
1. At most `sqrt (2 * n)`, which contribute at most `2 * n` for each such prime.
2. Between `sqrt (2 * n)` and `2 * n / 3`, which contribute at most `4^(2 * n / 3)` in total.
3. Between `2 * n / 3` and `n`, which do not exist.
4. Between `n` and `2 * n`, which would not exist in the case where Bertrand's postulate is false.
5. Above `2 * n`, which do not exist.
-/
theorem centralBinom_le_of_no_bertrand_prime (n : β) (n_big : 2 < n)
(no_prime : Β¬β p : β, Nat.Prime p β§ n < p β§ p β€ 2 * n) :
centralBinom n β€ (2 * n) ^ sqrt (2 * n) * 4 ^ (2 * n / 3) := by
have n_pos : 0 < n := (Nat.zero_le _).trans_lt n_big
have n2_pos : 1 β€ 2 * n := mul_pos (zero_lt_two' β) n_pos
let S := (Finset.range (2 * n / 3 + 1)).filter Nat.Prime
let f x := x ^ n.centralBinom.factorization x
have : β x : β in S, f x = β x : β in Finset.range (2 * n / 3 + 1), f x := by
| Mathlib.NumberTheory.Bertrand.155_0.gJXoOT9Ce2wC0xc | /-- An upper bound on the central binomial coefficient used in the proof of Bertrand's postulate.
The bound splits the prime factors of `centralBinom n` into those
1. At most `sqrt (2 * n)`, which contribute at most `2 * n` for each such prime.
2. Between `sqrt (2 * n)` and `2 * n / 3`, which contribute at most `4^(2 * n / 3)` in total.
3. Between `2 * n / 3` and `n`, which do not exist.
4. Between `n` and `2 * n`, which would not exist in the case where Bertrand's postulate is false.
5. Above `2 * n`, which do not exist.
-/
theorem centralBinom_le_of_no_bertrand_prime (n : β) (n_big : 2 < n)
(no_prime : Β¬β p : β, Nat.Prime p β§ n < p β§ p β€ 2 * n) :
centralBinom n β€ (2 * n) ^ sqrt (2 * n) * 4 ^ (2 * n / 3) | Mathlib_NumberTheory_Bertrand |
n : β
n_big : 2 < n
no_prime : Β¬β p, Nat.Prime p β§ n < p β§ p β€ 2 * n
n_pos : 0 < n
n2_pos : 1 β€ 2 * n
S : Finset β := Finset.filter Nat.Prime (Finset.range (2 * n / 3 + 1))
f : β β β := fun x => x ^ (Nat.factorization (centralBinom n)) x
p : β
xβ : p β Finset.range (2 * n / 3 + 1)
h : f p β 1
β’ Nat.Prime p | /-
Copyright (c) 2020 Patrick Stevens. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Stevens, Bolton Bailey
-/
import Mathlib.Data.Nat.Choose.Factorization
import Mathlib.Data.Nat.PrimeNormNum
import Mathlib.NumberTheory.Primorial
import Mathlib.Analysis.Convex.SpecificFunctions.Basic
import Mathlib.Analysis.Convex.SpecificFunctions.Deriv
#align_import number_theory.bertrand from "leanprover-community/mathlib"@"a16665637b378379689c566204817ae792ac8b39"
/-!
# Bertrand's Postulate
This file contains a proof of Bertrand's postulate: That between any positive number and its
double there is a prime.
The proof follows the outline of the ErdΕs proof presented in "Proofs from THE BOOK": One considers
the prime factorization of `(2 * n).choose n`, and splits the constituent primes up into various
groups, then upper bounds the contribution of each group. This upper bounds the central binomial
coefficient, and if the postulate does not hold, this upper bound conflicts with a simple lower
bound for large enough `n`. This proves the result holds for large enough `n`, and for smaller `n`
an explicit list of primes is provided which covers the remaining cases.
As in the [Metamath implementation](carneiro2015arithmetic), we rely on some optimizations from
[Shigenori Tochiori](tochiori_bertrand). In particular we use the cleaner bound on the central
binomial coefficient given in `Nat.four_pow_lt_mul_centralBinom`.
## References
* [M. Aigner and G. M. Ziegler _Proofs from THE BOOK_][aigner1999proofs]
* [S. Tochiori, _Considering the Proof of βThere is a Prime between n and 2nβ_][tochiori_bertrand]
* [M. Carneiro, _Arithmetic in Metamath, Case Study: Bertrand's Postulate_][carneiro2015arithmetic]
## Tags
Bertrand, prime, binomial coefficients
-/
open scoped BigOperators
section Real
open Real
namespace Bertrand
/-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> norm_num1
apply le_trans _ (le_mul_of_one_le_left _ _) <;> norm_num1
apply Real.rpow_le_rpow <;> norm_num1
apply rpow_nonneg_of_nonneg; norm_num1
apply rpow_pos_of_pos; norm_num1
apply hf' 18; norm_num1
norm_num1
Β· have : sqrt (2 * 512) = 32 :=
(sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonpos_iff (hf' _ _), this, div_le_one] <;> norm_num1
Β· conv in 512 => equals 2 ^ 9 => norm_num1
conv in 1024 => equals 2 ^ 10 => norm_num1
conv in 32 => rw [β Nat.cast_ofNat]
rw [rpow_nat_cast, β pow_mul, β pow_add]
conv in 4 => equals 2 ^ (2 : β) => rw [rpow_two]; norm_num1
rw [β rpow_mul, β rpow_nat_cast]
apply rpow_le_rpow_of_exponent_le
all_goals norm_num1
Β· apply rpow_pos_of_pos four_pos
#align bertrand.real_main_inequality Bertrand.real_main_inequality
end Bertrand
end Real
section Nat
open Nat
/-- The inequality which contradicts Bertrand's postulate, for large enough `n`.
-/
theorem bertrand_main_inequality {n : β} (n_large : 512 β€ n) :
n * (2 * n) ^ sqrt (2 * n) * 4 ^ (2 * n / 3) β€ 4 ^ n := by
rw [β @cast_le β]
simp only [cast_add, cast_one, cast_mul, cast_pow, β Real.rpow_nat_cast]
refine' _root_.trans ?_ (Bertrand.real_main_inequality (by exact_mod_cast n_large))
gcongr
Β· have n2_pos : 0 < 2 * n := by positivity
exact mod_cast n2_pos
Β· exact_mod_cast Real.nat_sqrt_le_real_sqrt
Β· norm_num1
Β· exact cast_div_le.trans (by norm_cast)
#align bertrand_main_inequality bertrand_main_inequality
/-- A lemma that tells us that, in the case where Bertrand's postulate does not hold, the prime
factorization of the central binomial coefficent only has factors at most `2 * n / 3 + 1`.
-/
theorem centralBinom_factorization_small (n : β) (n_large : 2 < n)
(no_prime : Β¬β p : β, p.Prime β§ n < p β§ p β€ 2 * n) :
centralBinom n = β p in Finset.range (2 * n / 3 + 1), p ^ (centralBinom n).factorization p := by
refine' (Eq.trans _ n.prod_pow_factorization_centralBinom).symm
apply Finset.prod_subset
Β· exact Finset.range_subset.2 (add_le_add_right (Nat.div_le_self _ _) _)
intro x hx h2x
rw [Finset.mem_range, lt_succ_iff] at hx h2x
rw [not_le, div_lt_iff_lt_mul' three_pos, mul_comm x] at h2x
replace no_prime := not_exists.mp no_prime x
rw [β and_assoc, not_and', not_and_or, not_lt] at no_prime
cases' no_prime hx with h h
Β· rw [factorization_eq_zero_of_non_prime n.centralBinom h, Nat.pow_zero]
Β· rw [factorization_centralBinom_of_two_mul_self_lt_three_mul n_large h h2x, Nat.pow_zero]
#align central_binom_factorization_small centralBinom_factorization_small
/-- An upper bound on the central binomial coefficient used in the proof of Bertrand's postulate.
The bound splits the prime factors of `centralBinom n` into those
1. At most `sqrt (2 * n)`, which contribute at most `2 * n` for each such prime.
2. Between `sqrt (2 * n)` and `2 * n / 3`, which contribute at most `4^(2 * n / 3)` in total.
3. Between `2 * n / 3` and `n`, which do not exist.
4. Between `n` and `2 * n`, which would not exist in the case where Bertrand's postulate is false.
5. Above `2 * n`, which do not exist.
-/
theorem centralBinom_le_of_no_bertrand_prime (n : β) (n_big : 2 < n)
(no_prime : Β¬β p : β, Nat.Prime p β§ n < p β§ p β€ 2 * n) :
centralBinom n β€ (2 * n) ^ sqrt (2 * n) * 4 ^ (2 * n / 3) := by
have n_pos : 0 < n := (Nat.zero_le _).trans_lt n_big
have n2_pos : 1 β€ 2 * n := mul_pos (zero_lt_two' β) n_pos
let S := (Finset.range (2 * n / 3 + 1)).filter Nat.Prime
let f x := x ^ n.centralBinom.factorization x
have : β x : β in S, f x = β x : β in Finset.range (2 * n / 3 + 1), f x := by
refine' Finset.prod_filter_of_ne fun p _ h => _
| contrapose! h | /-- An upper bound on the central binomial coefficient used in the proof of Bertrand's postulate.
The bound splits the prime factors of `centralBinom n` into those
1. At most `sqrt (2 * n)`, which contribute at most `2 * n` for each such prime.
2. Between `sqrt (2 * n)` and `2 * n / 3`, which contribute at most `4^(2 * n / 3)` in total.
3. Between `2 * n / 3` and `n`, which do not exist.
4. Between `n` and `2 * n`, which would not exist in the case where Bertrand's postulate is false.
5. Above `2 * n`, which do not exist.
-/
theorem centralBinom_le_of_no_bertrand_prime (n : β) (n_big : 2 < n)
(no_prime : Β¬β p : β, Nat.Prime p β§ n < p β§ p β€ 2 * n) :
centralBinom n β€ (2 * n) ^ sqrt (2 * n) * 4 ^ (2 * n / 3) := by
have n_pos : 0 < n := (Nat.zero_le _).trans_lt n_big
have n2_pos : 1 β€ 2 * n := mul_pos (zero_lt_two' β) n_pos
let S := (Finset.range (2 * n / 3 + 1)).filter Nat.Prime
let f x := x ^ n.centralBinom.factorization x
have : β x : β in S, f x = β x : β in Finset.range (2 * n / 3 + 1), f x := by
refine' Finset.prod_filter_of_ne fun p _ h => _
| Mathlib.NumberTheory.Bertrand.155_0.gJXoOT9Ce2wC0xc | /-- An upper bound on the central binomial coefficient used in the proof of Bertrand's postulate.
The bound splits the prime factors of `centralBinom n` into those
1. At most `sqrt (2 * n)`, which contribute at most `2 * n` for each such prime.
2. Between `sqrt (2 * n)` and `2 * n / 3`, which contribute at most `4^(2 * n / 3)` in total.
3. Between `2 * n / 3` and `n`, which do not exist.
4. Between `n` and `2 * n`, which would not exist in the case where Bertrand's postulate is false.
5. Above `2 * n`, which do not exist.
-/
theorem centralBinom_le_of_no_bertrand_prime (n : β) (n_big : 2 < n)
(no_prime : Β¬β p : β, Nat.Prime p β§ n < p β§ p β€ 2 * n) :
centralBinom n β€ (2 * n) ^ sqrt (2 * n) * 4 ^ (2 * n / 3) | Mathlib_NumberTheory_Bertrand |
n : β
n_big : 2 < n
no_prime : Β¬β p, Nat.Prime p β§ n < p β§ p β€ 2 * n
n_pos : 0 < n
n2_pos : 1 β€ 2 * n
S : Finset β := Finset.filter Nat.Prime (Finset.range (2 * n / 3 + 1))
f : β β β := fun x => x ^ (Nat.factorization (centralBinom n)) x
p : β
xβ : p β Finset.range (2 * n / 3 + 1)
h : Β¬Nat.Prime p
β’ f p = 1 | /-
Copyright (c) 2020 Patrick Stevens. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Stevens, Bolton Bailey
-/
import Mathlib.Data.Nat.Choose.Factorization
import Mathlib.Data.Nat.PrimeNormNum
import Mathlib.NumberTheory.Primorial
import Mathlib.Analysis.Convex.SpecificFunctions.Basic
import Mathlib.Analysis.Convex.SpecificFunctions.Deriv
#align_import number_theory.bertrand from "leanprover-community/mathlib"@"a16665637b378379689c566204817ae792ac8b39"
/-!
# Bertrand's Postulate
This file contains a proof of Bertrand's postulate: That between any positive number and its
double there is a prime.
The proof follows the outline of the ErdΕs proof presented in "Proofs from THE BOOK": One considers
the prime factorization of `(2 * n).choose n`, and splits the constituent primes up into various
groups, then upper bounds the contribution of each group. This upper bounds the central binomial
coefficient, and if the postulate does not hold, this upper bound conflicts with a simple lower
bound for large enough `n`. This proves the result holds for large enough `n`, and for smaller `n`
an explicit list of primes is provided which covers the remaining cases.
As in the [Metamath implementation](carneiro2015arithmetic), we rely on some optimizations from
[Shigenori Tochiori](tochiori_bertrand). In particular we use the cleaner bound on the central
binomial coefficient given in `Nat.four_pow_lt_mul_centralBinom`.
## References
* [M. Aigner and G. M. Ziegler _Proofs from THE BOOK_][aigner1999proofs]
* [S. Tochiori, _Considering the Proof of βThere is a Prime between n and 2nβ_][tochiori_bertrand]
* [M. Carneiro, _Arithmetic in Metamath, Case Study: Bertrand's Postulate_][carneiro2015arithmetic]
## Tags
Bertrand, prime, binomial coefficients
-/
open scoped BigOperators
section Real
open Real
namespace Bertrand
/-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> norm_num1
apply le_trans _ (le_mul_of_one_le_left _ _) <;> norm_num1
apply Real.rpow_le_rpow <;> norm_num1
apply rpow_nonneg_of_nonneg; norm_num1
apply rpow_pos_of_pos; norm_num1
apply hf' 18; norm_num1
norm_num1
Β· have : sqrt (2 * 512) = 32 :=
(sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonpos_iff (hf' _ _), this, div_le_one] <;> norm_num1
Β· conv in 512 => equals 2 ^ 9 => norm_num1
conv in 1024 => equals 2 ^ 10 => norm_num1
conv in 32 => rw [β Nat.cast_ofNat]
rw [rpow_nat_cast, β pow_mul, β pow_add]
conv in 4 => equals 2 ^ (2 : β) => rw [rpow_two]; norm_num1
rw [β rpow_mul, β rpow_nat_cast]
apply rpow_le_rpow_of_exponent_le
all_goals norm_num1
Β· apply rpow_pos_of_pos four_pos
#align bertrand.real_main_inequality Bertrand.real_main_inequality
end Bertrand
end Real
section Nat
open Nat
/-- The inequality which contradicts Bertrand's postulate, for large enough `n`.
-/
theorem bertrand_main_inequality {n : β} (n_large : 512 β€ n) :
n * (2 * n) ^ sqrt (2 * n) * 4 ^ (2 * n / 3) β€ 4 ^ n := by
rw [β @cast_le β]
simp only [cast_add, cast_one, cast_mul, cast_pow, β Real.rpow_nat_cast]
refine' _root_.trans ?_ (Bertrand.real_main_inequality (by exact_mod_cast n_large))
gcongr
Β· have n2_pos : 0 < 2 * n := by positivity
exact mod_cast n2_pos
Β· exact_mod_cast Real.nat_sqrt_le_real_sqrt
Β· norm_num1
Β· exact cast_div_le.trans (by norm_cast)
#align bertrand_main_inequality bertrand_main_inequality
/-- A lemma that tells us that, in the case where Bertrand's postulate does not hold, the prime
factorization of the central binomial coefficent only has factors at most `2 * n / 3 + 1`.
-/
theorem centralBinom_factorization_small (n : β) (n_large : 2 < n)
(no_prime : Β¬β p : β, p.Prime β§ n < p β§ p β€ 2 * n) :
centralBinom n = β p in Finset.range (2 * n / 3 + 1), p ^ (centralBinom n).factorization p := by
refine' (Eq.trans _ n.prod_pow_factorization_centralBinom).symm
apply Finset.prod_subset
Β· exact Finset.range_subset.2 (add_le_add_right (Nat.div_le_self _ _) _)
intro x hx h2x
rw [Finset.mem_range, lt_succ_iff] at hx h2x
rw [not_le, div_lt_iff_lt_mul' three_pos, mul_comm x] at h2x
replace no_prime := not_exists.mp no_prime x
rw [β and_assoc, not_and', not_and_or, not_lt] at no_prime
cases' no_prime hx with h h
Β· rw [factorization_eq_zero_of_non_prime n.centralBinom h, Nat.pow_zero]
Β· rw [factorization_centralBinom_of_two_mul_self_lt_three_mul n_large h h2x, Nat.pow_zero]
#align central_binom_factorization_small centralBinom_factorization_small
/-- An upper bound on the central binomial coefficient used in the proof of Bertrand's postulate.
The bound splits the prime factors of `centralBinom n` into those
1. At most `sqrt (2 * n)`, which contribute at most `2 * n` for each such prime.
2. Between `sqrt (2 * n)` and `2 * n / 3`, which contribute at most `4^(2 * n / 3)` in total.
3. Between `2 * n / 3` and `n`, which do not exist.
4. Between `n` and `2 * n`, which would not exist in the case where Bertrand's postulate is false.
5. Above `2 * n`, which do not exist.
-/
theorem centralBinom_le_of_no_bertrand_prime (n : β) (n_big : 2 < n)
(no_prime : Β¬β p : β, Nat.Prime p β§ n < p β§ p β€ 2 * n) :
centralBinom n β€ (2 * n) ^ sqrt (2 * n) * 4 ^ (2 * n / 3) := by
have n_pos : 0 < n := (Nat.zero_le _).trans_lt n_big
have n2_pos : 1 β€ 2 * n := mul_pos (zero_lt_two' β) n_pos
let S := (Finset.range (2 * n / 3 + 1)).filter Nat.Prime
let f x := x ^ n.centralBinom.factorization x
have : β x : β in S, f x = β x : β in Finset.range (2 * n / 3 + 1), f x := by
refine' Finset.prod_filter_of_ne fun p _ h => _
contrapose! h; | dsimp only | /-- An upper bound on the central binomial coefficient used in the proof of Bertrand's postulate.
The bound splits the prime factors of `centralBinom n` into those
1. At most `sqrt (2 * n)`, which contribute at most `2 * n` for each such prime.
2. Between `sqrt (2 * n)` and `2 * n / 3`, which contribute at most `4^(2 * n / 3)` in total.
3. Between `2 * n / 3` and `n`, which do not exist.
4. Between `n` and `2 * n`, which would not exist in the case where Bertrand's postulate is false.
5. Above `2 * n`, which do not exist.
-/
theorem centralBinom_le_of_no_bertrand_prime (n : β) (n_big : 2 < n)
(no_prime : Β¬β p : β, Nat.Prime p β§ n < p β§ p β€ 2 * n) :
centralBinom n β€ (2 * n) ^ sqrt (2 * n) * 4 ^ (2 * n / 3) := by
have n_pos : 0 < n := (Nat.zero_le _).trans_lt n_big
have n2_pos : 1 β€ 2 * n := mul_pos (zero_lt_two' β) n_pos
let S := (Finset.range (2 * n / 3 + 1)).filter Nat.Prime
let f x := x ^ n.centralBinom.factorization x
have : β x : β in S, f x = β x : β in Finset.range (2 * n / 3 + 1), f x := by
refine' Finset.prod_filter_of_ne fun p _ h => _
contrapose! h; | Mathlib.NumberTheory.Bertrand.155_0.gJXoOT9Ce2wC0xc | /-- An upper bound on the central binomial coefficient used in the proof of Bertrand's postulate.
The bound splits the prime factors of `centralBinom n` into those
1. At most `sqrt (2 * n)`, which contribute at most `2 * n` for each such prime.
2. Between `sqrt (2 * n)` and `2 * n / 3`, which contribute at most `4^(2 * n / 3)` in total.
3. Between `2 * n / 3` and `n`, which do not exist.
4. Between `n` and `2 * n`, which would not exist in the case where Bertrand's postulate is false.
5. Above `2 * n`, which do not exist.
-/
theorem centralBinom_le_of_no_bertrand_prime (n : β) (n_big : 2 < n)
(no_prime : Β¬β p : β, Nat.Prime p β§ n < p β§ p β€ 2 * n) :
centralBinom n β€ (2 * n) ^ sqrt (2 * n) * 4 ^ (2 * n / 3) | Mathlib_NumberTheory_Bertrand |
n : β
n_big : 2 < n
no_prime : Β¬β p, Nat.Prime p β§ n < p β§ p β€ 2 * n
n_pos : 0 < n
n2_pos : 1 β€ 2 * n
S : Finset β := Finset.filter Nat.Prime (Finset.range (2 * n / 3 + 1))
f : β β β := fun x => x ^ (Nat.factorization (centralBinom n)) x
p : β
xβ : p β Finset.range (2 * n / 3 + 1)
h : Β¬Nat.Prime p
β’ p ^ (Nat.factorization (centralBinom n)) p = 1 | /-
Copyright (c) 2020 Patrick Stevens. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Stevens, Bolton Bailey
-/
import Mathlib.Data.Nat.Choose.Factorization
import Mathlib.Data.Nat.PrimeNormNum
import Mathlib.NumberTheory.Primorial
import Mathlib.Analysis.Convex.SpecificFunctions.Basic
import Mathlib.Analysis.Convex.SpecificFunctions.Deriv
#align_import number_theory.bertrand from "leanprover-community/mathlib"@"a16665637b378379689c566204817ae792ac8b39"
/-!
# Bertrand's Postulate
This file contains a proof of Bertrand's postulate: That between any positive number and its
double there is a prime.
The proof follows the outline of the ErdΕs proof presented in "Proofs from THE BOOK": One considers
the prime factorization of `(2 * n).choose n`, and splits the constituent primes up into various
groups, then upper bounds the contribution of each group. This upper bounds the central binomial
coefficient, and if the postulate does not hold, this upper bound conflicts with a simple lower
bound for large enough `n`. This proves the result holds for large enough `n`, and for smaller `n`
an explicit list of primes is provided which covers the remaining cases.
As in the [Metamath implementation](carneiro2015arithmetic), we rely on some optimizations from
[Shigenori Tochiori](tochiori_bertrand). In particular we use the cleaner bound on the central
binomial coefficient given in `Nat.four_pow_lt_mul_centralBinom`.
## References
* [M. Aigner and G. M. Ziegler _Proofs from THE BOOK_][aigner1999proofs]
* [S. Tochiori, _Considering the Proof of βThere is a Prime between n and 2nβ_][tochiori_bertrand]
* [M. Carneiro, _Arithmetic in Metamath, Case Study: Bertrand's Postulate_][carneiro2015arithmetic]
## Tags
Bertrand, prime, binomial coefficients
-/
open scoped BigOperators
section Real
open Real
namespace Bertrand
/-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> norm_num1
apply le_trans _ (le_mul_of_one_le_left _ _) <;> norm_num1
apply Real.rpow_le_rpow <;> norm_num1
apply rpow_nonneg_of_nonneg; norm_num1
apply rpow_pos_of_pos; norm_num1
apply hf' 18; norm_num1
norm_num1
Β· have : sqrt (2 * 512) = 32 :=
(sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonpos_iff (hf' _ _), this, div_le_one] <;> norm_num1
Β· conv in 512 => equals 2 ^ 9 => norm_num1
conv in 1024 => equals 2 ^ 10 => norm_num1
conv in 32 => rw [β Nat.cast_ofNat]
rw [rpow_nat_cast, β pow_mul, β pow_add]
conv in 4 => equals 2 ^ (2 : β) => rw [rpow_two]; norm_num1
rw [β rpow_mul, β rpow_nat_cast]
apply rpow_le_rpow_of_exponent_le
all_goals norm_num1
Β· apply rpow_pos_of_pos four_pos
#align bertrand.real_main_inequality Bertrand.real_main_inequality
end Bertrand
end Real
section Nat
open Nat
/-- The inequality which contradicts Bertrand's postulate, for large enough `n`.
-/
theorem bertrand_main_inequality {n : β} (n_large : 512 β€ n) :
n * (2 * n) ^ sqrt (2 * n) * 4 ^ (2 * n / 3) β€ 4 ^ n := by
rw [β @cast_le β]
simp only [cast_add, cast_one, cast_mul, cast_pow, β Real.rpow_nat_cast]
refine' _root_.trans ?_ (Bertrand.real_main_inequality (by exact_mod_cast n_large))
gcongr
Β· have n2_pos : 0 < 2 * n := by positivity
exact mod_cast n2_pos
Β· exact_mod_cast Real.nat_sqrt_le_real_sqrt
Β· norm_num1
Β· exact cast_div_le.trans (by norm_cast)
#align bertrand_main_inequality bertrand_main_inequality
/-- A lemma that tells us that, in the case where Bertrand's postulate does not hold, the prime
factorization of the central binomial coefficent only has factors at most `2 * n / 3 + 1`.
-/
theorem centralBinom_factorization_small (n : β) (n_large : 2 < n)
(no_prime : Β¬β p : β, p.Prime β§ n < p β§ p β€ 2 * n) :
centralBinom n = β p in Finset.range (2 * n / 3 + 1), p ^ (centralBinom n).factorization p := by
refine' (Eq.trans _ n.prod_pow_factorization_centralBinom).symm
apply Finset.prod_subset
Β· exact Finset.range_subset.2 (add_le_add_right (Nat.div_le_self _ _) _)
intro x hx h2x
rw [Finset.mem_range, lt_succ_iff] at hx h2x
rw [not_le, div_lt_iff_lt_mul' three_pos, mul_comm x] at h2x
replace no_prime := not_exists.mp no_prime x
rw [β and_assoc, not_and', not_and_or, not_lt] at no_prime
cases' no_prime hx with h h
Β· rw [factorization_eq_zero_of_non_prime n.centralBinom h, Nat.pow_zero]
Β· rw [factorization_centralBinom_of_two_mul_self_lt_three_mul n_large h h2x, Nat.pow_zero]
#align central_binom_factorization_small centralBinom_factorization_small
/-- An upper bound on the central binomial coefficient used in the proof of Bertrand's postulate.
The bound splits the prime factors of `centralBinom n` into those
1. At most `sqrt (2 * n)`, which contribute at most `2 * n` for each such prime.
2. Between `sqrt (2 * n)` and `2 * n / 3`, which contribute at most `4^(2 * n / 3)` in total.
3. Between `2 * n / 3` and `n`, which do not exist.
4. Between `n` and `2 * n`, which would not exist in the case where Bertrand's postulate is false.
5. Above `2 * n`, which do not exist.
-/
theorem centralBinom_le_of_no_bertrand_prime (n : β) (n_big : 2 < n)
(no_prime : Β¬β p : β, Nat.Prime p β§ n < p β§ p β€ 2 * n) :
centralBinom n β€ (2 * n) ^ sqrt (2 * n) * 4 ^ (2 * n / 3) := by
have n_pos : 0 < n := (Nat.zero_le _).trans_lt n_big
have n2_pos : 1 β€ 2 * n := mul_pos (zero_lt_two' β) n_pos
let S := (Finset.range (2 * n / 3 + 1)).filter Nat.Prime
let f x := x ^ n.centralBinom.factorization x
have : β x : β in S, f x = β x : β in Finset.range (2 * n / 3 + 1), f x := by
refine' Finset.prod_filter_of_ne fun p _ h => _
contrapose! h; dsimp only
| rw [factorization_eq_zero_of_non_prime n.centralBinom h, _root_.pow_zero] | /-- An upper bound on the central binomial coefficient used in the proof of Bertrand's postulate.
The bound splits the prime factors of `centralBinom n` into those
1. At most `sqrt (2 * n)`, which contribute at most `2 * n` for each such prime.
2. Between `sqrt (2 * n)` and `2 * n / 3`, which contribute at most `4^(2 * n / 3)` in total.
3. Between `2 * n / 3` and `n`, which do not exist.
4. Between `n` and `2 * n`, which would not exist in the case where Bertrand's postulate is false.
5. Above `2 * n`, which do not exist.
-/
theorem centralBinom_le_of_no_bertrand_prime (n : β) (n_big : 2 < n)
(no_prime : Β¬β p : β, Nat.Prime p β§ n < p β§ p β€ 2 * n) :
centralBinom n β€ (2 * n) ^ sqrt (2 * n) * 4 ^ (2 * n / 3) := by
have n_pos : 0 < n := (Nat.zero_le _).trans_lt n_big
have n2_pos : 1 β€ 2 * n := mul_pos (zero_lt_two' β) n_pos
let S := (Finset.range (2 * n / 3 + 1)).filter Nat.Prime
let f x := x ^ n.centralBinom.factorization x
have : β x : β in S, f x = β x : β in Finset.range (2 * n / 3 + 1), f x := by
refine' Finset.prod_filter_of_ne fun p _ h => _
contrapose! h; dsimp only
| Mathlib.NumberTheory.Bertrand.155_0.gJXoOT9Ce2wC0xc | /-- An upper bound on the central binomial coefficient used in the proof of Bertrand's postulate.
The bound splits the prime factors of `centralBinom n` into those
1. At most `sqrt (2 * n)`, which contribute at most `2 * n` for each such prime.
2. Between `sqrt (2 * n)` and `2 * n / 3`, which contribute at most `4^(2 * n / 3)` in total.
3. Between `2 * n / 3` and `n`, which do not exist.
4. Between `n` and `2 * n`, which would not exist in the case where Bertrand's postulate is false.
5. Above `2 * n`, which do not exist.
-/
theorem centralBinom_le_of_no_bertrand_prime (n : β) (n_big : 2 < n)
(no_prime : Β¬β p : β, Nat.Prime p β§ n < p β§ p β€ 2 * n) :
centralBinom n β€ (2 * n) ^ sqrt (2 * n) * 4 ^ (2 * n / 3) | Mathlib_NumberTheory_Bertrand |
n : β
n_big : 2 < n
no_prime : Β¬β p, Nat.Prime p β§ n < p β§ p β€ 2 * n
n_pos : 0 < n
n2_pos : 1 β€ 2 * n
S : Finset β := Finset.filter Nat.Prime (Finset.range (2 * n / 3 + 1))
f : β β β := fun x => x ^ (Nat.factorization (centralBinom n)) x
this : β x in S, f x = β x in Finset.range (2 * n / 3 + 1), f x
β’ centralBinom n β€ (2 * n) ^ sqrt (2 * n) * 4 ^ (2 * n / 3) | /-
Copyright (c) 2020 Patrick Stevens. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Stevens, Bolton Bailey
-/
import Mathlib.Data.Nat.Choose.Factorization
import Mathlib.Data.Nat.PrimeNormNum
import Mathlib.NumberTheory.Primorial
import Mathlib.Analysis.Convex.SpecificFunctions.Basic
import Mathlib.Analysis.Convex.SpecificFunctions.Deriv
#align_import number_theory.bertrand from "leanprover-community/mathlib"@"a16665637b378379689c566204817ae792ac8b39"
/-!
# Bertrand's Postulate
This file contains a proof of Bertrand's postulate: That between any positive number and its
double there is a prime.
The proof follows the outline of the ErdΕs proof presented in "Proofs from THE BOOK": One considers
the prime factorization of `(2 * n).choose n`, and splits the constituent primes up into various
groups, then upper bounds the contribution of each group. This upper bounds the central binomial
coefficient, and if the postulate does not hold, this upper bound conflicts with a simple lower
bound for large enough `n`. This proves the result holds for large enough `n`, and for smaller `n`
an explicit list of primes is provided which covers the remaining cases.
As in the [Metamath implementation](carneiro2015arithmetic), we rely on some optimizations from
[Shigenori Tochiori](tochiori_bertrand). In particular we use the cleaner bound on the central
binomial coefficient given in `Nat.four_pow_lt_mul_centralBinom`.
## References
* [M. Aigner and G. M. Ziegler _Proofs from THE BOOK_][aigner1999proofs]
* [S. Tochiori, _Considering the Proof of βThere is a Prime between n and 2nβ_][tochiori_bertrand]
* [M. Carneiro, _Arithmetic in Metamath, Case Study: Bertrand's Postulate_][carneiro2015arithmetic]
## Tags
Bertrand, prime, binomial coefficients
-/
open scoped BigOperators
section Real
open Real
namespace Bertrand
/-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> norm_num1
apply le_trans _ (le_mul_of_one_le_left _ _) <;> norm_num1
apply Real.rpow_le_rpow <;> norm_num1
apply rpow_nonneg_of_nonneg; norm_num1
apply rpow_pos_of_pos; norm_num1
apply hf' 18; norm_num1
norm_num1
Β· have : sqrt (2 * 512) = 32 :=
(sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonpos_iff (hf' _ _), this, div_le_one] <;> norm_num1
Β· conv in 512 => equals 2 ^ 9 => norm_num1
conv in 1024 => equals 2 ^ 10 => norm_num1
conv in 32 => rw [β Nat.cast_ofNat]
rw [rpow_nat_cast, β pow_mul, β pow_add]
conv in 4 => equals 2 ^ (2 : β) => rw [rpow_two]; norm_num1
rw [β rpow_mul, β rpow_nat_cast]
apply rpow_le_rpow_of_exponent_le
all_goals norm_num1
Β· apply rpow_pos_of_pos four_pos
#align bertrand.real_main_inequality Bertrand.real_main_inequality
end Bertrand
end Real
section Nat
open Nat
/-- The inequality which contradicts Bertrand's postulate, for large enough `n`.
-/
theorem bertrand_main_inequality {n : β} (n_large : 512 β€ n) :
n * (2 * n) ^ sqrt (2 * n) * 4 ^ (2 * n / 3) β€ 4 ^ n := by
rw [β @cast_le β]
simp only [cast_add, cast_one, cast_mul, cast_pow, β Real.rpow_nat_cast]
refine' _root_.trans ?_ (Bertrand.real_main_inequality (by exact_mod_cast n_large))
gcongr
Β· have n2_pos : 0 < 2 * n := by positivity
exact mod_cast n2_pos
Β· exact_mod_cast Real.nat_sqrt_le_real_sqrt
Β· norm_num1
Β· exact cast_div_le.trans (by norm_cast)
#align bertrand_main_inequality bertrand_main_inequality
/-- A lemma that tells us that, in the case where Bertrand's postulate does not hold, the prime
factorization of the central binomial coefficent only has factors at most `2 * n / 3 + 1`.
-/
theorem centralBinom_factorization_small (n : β) (n_large : 2 < n)
(no_prime : Β¬β p : β, p.Prime β§ n < p β§ p β€ 2 * n) :
centralBinom n = β p in Finset.range (2 * n / 3 + 1), p ^ (centralBinom n).factorization p := by
refine' (Eq.trans _ n.prod_pow_factorization_centralBinom).symm
apply Finset.prod_subset
Β· exact Finset.range_subset.2 (add_le_add_right (Nat.div_le_self _ _) _)
intro x hx h2x
rw [Finset.mem_range, lt_succ_iff] at hx h2x
rw [not_le, div_lt_iff_lt_mul' three_pos, mul_comm x] at h2x
replace no_prime := not_exists.mp no_prime x
rw [β and_assoc, not_and', not_and_or, not_lt] at no_prime
cases' no_prime hx with h h
Β· rw [factorization_eq_zero_of_non_prime n.centralBinom h, Nat.pow_zero]
Β· rw [factorization_centralBinom_of_two_mul_self_lt_three_mul n_large h h2x, Nat.pow_zero]
#align central_binom_factorization_small centralBinom_factorization_small
/-- An upper bound on the central binomial coefficient used in the proof of Bertrand's postulate.
The bound splits the prime factors of `centralBinom n` into those
1. At most `sqrt (2 * n)`, which contribute at most `2 * n` for each such prime.
2. Between `sqrt (2 * n)` and `2 * n / 3`, which contribute at most `4^(2 * n / 3)` in total.
3. Between `2 * n / 3` and `n`, which do not exist.
4. Between `n` and `2 * n`, which would not exist in the case where Bertrand's postulate is false.
5. Above `2 * n`, which do not exist.
-/
theorem centralBinom_le_of_no_bertrand_prime (n : β) (n_big : 2 < n)
(no_prime : Β¬β p : β, Nat.Prime p β§ n < p β§ p β€ 2 * n) :
centralBinom n β€ (2 * n) ^ sqrt (2 * n) * 4 ^ (2 * n / 3) := by
have n_pos : 0 < n := (Nat.zero_le _).trans_lt n_big
have n2_pos : 1 β€ 2 * n := mul_pos (zero_lt_two' β) n_pos
let S := (Finset.range (2 * n / 3 + 1)).filter Nat.Prime
let f x := x ^ n.centralBinom.factorization x
have : β x : β in S, f x = β x : β in Finset.range (2 * n / 3 + 1), f x := by
refine' Finset.prod_filter_of_ne fun p _ h => _
contrapose! h; dsimp only
rw [factorization_eq_zero_of_non_prime n.centralBinom h, _root_.pow_zero]
| rw [centralBinom_factorization_small n n_big no_prime, β this, β
Finset.prod_filter_mul_prod_filter_not S (Β· β€ sqrt (2 * n))] | /-- An upper bound on the central binomial coefficient used in the proof of Bertrand's postulate.
The bound splits the prime factors of `centralBinom n` into those
1. At most `sqrt (2 * n)`, which contribute at most `2 * n` for each such prime.
2. Between `sqrt (2 * n)` and `2 * n / 3`, which contribute at most `4^(2 * n / 3)` in total.
3. Between `2 * n / 3` and `n`, which do not exist.
4. Between `n` and `2 * n`, which would not exist in the case where Bertrand's postulate is false.
5. Above `2 * n`, which do not exist.
-/
theorem centralBinom_le_of_no_bertrand_prime (n : β) (n_big : 2 < n)
(no_prime : Β¬β p : β, Nat.Prime p β§ n < p β§ p β€ 2 * n) :
centralBinom n β€ (2 * n) ^ sqrt (2 * n) * 4 ^ (2 * n / 3) := by
have n_pos : 0 < n := (Nat.zero_le _).trans_lt n_big
have n2_pos : 1 β€ 2 * n := mul_pos (zero_lt_two' β) n_pos
let S := (Finset.range (2 * n / 3 + 1)).filter Nat.Prime
let f x := x ^ n.centralBinom.factorization x
have : β x : β in S, f x = β x : β in Finset.range (2 * n / 3 + 1), f x := by
refine' Finset.prod_filter_of_ne fun p _ h => _
contrapose! h; dsimp only
rw [factorization_eq_zero_of_non_prime n.centralBinom h, _root_.pow_zero]
| Mathlib.NumberTheory.Bertrand.155_0.gJXoOT9Ce2wC0xc | /-- An upper bound on the central binomial coefficient used in the proof of Bertrand's postulate.
The bound splits the prime factors of `centralBinom n` into those
1. At most `sqrt (2 * n)`, which contribute at most `2 * n` for each such prime.
2. Between `sqrt (2 * n)` and `2 * n / 3`, which contribute at most `4^(2 * n / 3)` in total.
3. Between `2 * n / 3` and `n`, which do not exist.
4. Between `n` and `2 * n`, which would not exist in the case where Bertrand's postulate is false.
5. Above `2 * n`, which do not exist.
-/
theorem centralBinom_le_of_no_bertrand_prime (n : β) (n_big : 2 < n)
(no_prime : Β¬β p : β, Nat.Prime p β§ n < p β§ p β€ 2 * n) :
centralBinom n β€ (2 * n) ^ sqrt (2 * n) * 4 ^ (2 * n / 3) | Mathlib_NumberTheory_Bertrand |
n : β
n_big : 2 < n
no_prime : Β¬β p, Nat.Prime p β§ n < p β§ p β€ 2 * n
n_pos : 0 < n
n2_pos : 1 β€ 2 * n
S : Finset β := Finset.filter Nat.Prime (Finset.range (2 * n / 3 + 1))
f : β β β := fun x => x ^ (Nat.factorization (centralBinom n)) x
this : β x in S, f x = β x in Finset.range (2 * n / 3 + 1), f x
β’ (β x in Finset.filter (fun x => x β€ sqrt (2 * n)) S, f x) * β x in Finset.filter (fun x => Β¬x β€ sqrt (2 * n)) S, f x β€
(2 * n) ^ sqrt (2 * n) * 4 ^ (2 * n / 3) | /-
Copyright (c) 2020 Patrick Stevens. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Stevens, Bolton Bailey
-/
import Mathlib.Data.Nat.Choose.Factorization
import Mathlib.Data.Nat.PrimeNormNum
import Mathlib.NumberTheory.Primorial
import Mathlib.Analysis.Convex.SpecificFunctions.Basic
import Mathlib.Analysis.Convex.SpecificFunctions.Deriv
#align_import number_theory.bertrand from "leanprover-community/mathlib"@"a16665637b378379689c566204817ae792ac8b39"
/-!
# Bertrand's Postulate
This file contains a proof of Bertrand's postulate: That between any positive number and its
double there is a prime.
The proof follows the outline of the ErdΕs proof presented in "Proofs from THE BOOK": One considers
the prime factorization of `(2 * n).choose n`, and splits the constituent primes up into various
groups, then upper bounds the contribution of each group. This upper bounds the central binomial
coefficient, and if the postulate does not hold, this upper bound conflicts with a simple lower
bound for large enough `n`. This proves the result holds for large enough `n`, and for smaller `n`
an explicit list of primes is provided which covers the remaining cases.
As in the [Metamath implementation](carneiro2015arithmetic), we rely on some optimizations from
[Shigenori Tochiori](tochiori_bertrand). In particular we use the cleaner bound on the central
binomial coefficient given in `Nat.four_pow_lt_mul_centralBinom`.
## References
* [M. Aigner and G. M. Ziegler _Proofs from THE BOOK_][aigner1999proofs]
* [S. Tochiori, _Considering the Proof of βThere is a Prime between n and 2nβ_][tochiori_bertrand]
* [M. Carneiro, _Arithmetic in Metamath, Case Study: Bertrand's Postulate_][carneiro2015arithmetic]
## Tags
Bertrand, prime, binomial coefficients
-/
open scoped BigOperators
section Real
open Real
namespace Bertrand
/-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> norm_num1
apply le_trans _ (le_mul_of_one_le_left _ _) <;> norm_num1
apply Real.rpow_le_rpow <;> norm_num1
apply rpow_nonneg_of_nonneg; norm_num1
apply rpow_pos_of_pos; norm_num1
apply hf' 18; norm_num1
norm_num1
Β· have : sqrt (2 * 512) = 32 :=
(sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonpos_iff (hf' _ _), this, div_le_one] <;> norm_num1
Β· conv in 512 => equals 2 ^ 9 => norm_num1
conv in 1024 => equals 2 ^ 10 => norm_num1
conv in 32 => rw [β Nat.cast_ofNat]
rw [rpow_nat_cast, β pow_mul, β pow_add]
conv in 4 => equals 2 ^ (2 : β) => rw [rpow_two]; norm_num1
rw [β rpow_mul, β rpow_nat_cast]
apply rpow_le_rpow_of_exponent_le
all_goals norm_num1
Β· apply rpow_pos_of_pos four_pos
#align bertrand.real_main_inequality Bertrand.real_main_inequality
end Bertrand
end Real
section Nat
open Nat
/-- The inequality which contradicts Bertrand's postulate, for large enough `n`.
-/
theorem bertrand_main_inequality {n : β} (n_large : 512 β€ n) :
n * (2 * n) ^ sqrt (2 * n) * 4 ^ (2 * n / 3) β€ 4 ^ n := by
rw [β @cast_le β]
simp only [cast_add, cast_one, cast_mul, cast_pow, β Real.rpow_nat_cast]
refine' _root_.trans ?_ (Bertrand.real_main_inequality (by exact_mod_cast n_large))
gcongr
Β· have n2_pos : 0 < 2 * n := by positivity
exact mod_cast n2_pos
Β· exact_mod_cast Real.nat_sqrt_le_real_sqrt
Β· norm_num1
Β· exact cast_div_le.trans (by norm_cast)
#align bertrand_main_inequality bertrand_main_inequality
/-- A lemma that tells us that, in the case where Bertrand's postulate does not hold, the prime
factorization of the central binomial coefficent only has factors at most `2 * n / 3 + 1`.
-/
theorem centralBinom_factorization_small (n : β) (n_large : 2 < n)
(no_prime : Β¬β p : β, p.Prime β§ n < p β§ p β€ 2 * n) :
centralBinom n = β p in Finset.range (2 * n / 3 + 1), p ^ (centralBinom n).factorization p := by
refine' (Eq.trans _ n.prod_pow_factorization_centralBinom).symm
apply Finset.prod_subset
Β· exact Finset.range_subset.2 (add_le_add_right (Nat.div_le_self _ _) _)
intro x hx h2x
rw [Finset.mem_range, lt_succ_iff] at hx h2x
rw [not_le, div_lt_iff_lt_mul' three_pos, mul_comm x] at h2x
replace no_prime := not_exists.mp no_prime x
rw [β and_assoc, not_and', not_and_or, not_lt] at no_prime
cases' no_prime hx with h h
Β· rw [factorization_eq_zero_of_non_prime n.centralBinom h, Nat.pow_zero]
Β· rw [factorization_centralBinom_of_two_mul_self_lt_three_mul n_large h h2x, Nat.pow_zero]
#align central_binom_factorization_small centralBinom_factorization_small
/-- An upper bound on the central binomial coefficient used in the proof of Bertrand's postulate.
The bound splits the prime factors of `centralBinom n` into those
1. At most `sqrt (2 * n)`, which contribute at most `2 * n` for each such prime.
2. Between `sqrt (2 * n)` and `2 * n / 3`, which contribute at most `4^(2 * n / 3)` in total.
3. Between `2 * n / 3` and `n`, which do not exist.
4. Between `n` and `2 * n`, which would not exist in the case where Bertrand's postulate is false.
5. Above `2 * n`, which do not exist.
-/
theorem centralBinom_le_of_no_bertrand_prime (n : β) (n_big : 2 < n)
(no_prime : Β¬β p : β, Nat.Prime p β§ n < p β§ p β€ 2 * n) :
centralBinom n β€ (2 * n) ^ sqrt (2 * n) * 4 ^ (2 * n / 3) := by
have n_pos : 0 < n := (Nat.zero_le _).trans_lt n_big
have n2_pos : 1 β€ 2 * n := mul_pos (zero_lt_two' β) n_pos
let S := (Finset.range (2 * n / 3 + 1)).filter Nat.Prime
let f x := x ^ n.centralBinom.factorization x
have : β x : β in S, f x = β x : β in Finset.range (2 * n / 3 + 1), f x := by
refine' Finset.prod_filter_of_ne fun p _ h => _
contrapose! h; dsimp only
rw [factorization_eq_zero_of_non_prime n.centralBinom h, _root_.pow_zero]
rw [centralBinom_factorization_small n n_big no_prime, β this, β
Finset.prod_filter_mul_prod_filter_not S (Β· β€ sqrt (2 * n))]
| apply mul_le_mul' | /-- An upper bound on the central binomial coefficient used in the proof of Bertrand's postulate.
The bound splits the prime factors of `centralBinom n` into those
1. At most `sqrt (2 * n)`, which contribute at most `2 * n` for each such prime.
2. Between `sqrt (2 * n)` and `2 * n / 3`, which contribute at most `4^(2 * n / 3)` in total.
3. Between `2 * n / 3` and `n`, which do not exist.
4. Between `n` and `2 * n`, which would not exist in the case where Bertrand's postulate is false.
5. Above `2 * n`, which do not exist.
-/
theorem centralBinom_le_of_no_bertrand_prime (n : β) (n_big : 2 < n)
(no_prime : Β¬β p : β, Nat.Prime p β§ n < p β§ p β€ 2 * n) :
centralBinom n β€ (2 * n) ^ sqrt (2 * n) * 4 ^ (2 * n / 3) := by
have n_pos : 0 < n := (Nat.zero_le _).trans_lt n_big
have n2_pos : 1 β€ 2 * n := mul_pos (zero_lt_two' β) n_pos
let S := (Finset.range (2 * n / 3 + 1)).filter Nat.Prime
let f x := x ^ n.centralBinom.factorization x
have : β x : β in S, f x = β x : β in Finset.range (2 * n / 3 + 1), f x := by
refine' Finset.prod_filter_of_ne fun p _ h => _
contrapose! h; dsimp only
rw [factorization_eq_zero_of_non_prime n.centralBinom h, _root_.pow_zero]
rw [centralBinom_factorization_small n n_big no_prime, β this, β
Finset.prod_filter_mul_prod_filter_not S (Β· β€ sqrt (2 * n))]
| Mathlib.NumberTheory.Bertrand.155_0.gJXoOT9Ce2wC0xc | /-- An upper bound on the central binomial coefficient used in the proof of Bertrand's postulate.
The bound splits the prime factors of `centralBinom n` into those
1. At most `sqrt (2 * n)`, which contribute at most `2 * n` for each such prime.
2. Between `sqrt (2 * n)` and `2 * n / 3`, which contribute at most `4^(2 * n / 3)` in total.
3. Between `2 * n / 3` and `n`, which do not exist.
4. Between `n` and `2 * n`, which would not exist in the case where Bertrand's postulate is false.
5. Above `2 * n`, which do not exist.
-/
theorem centralBinom_le_of_no_bertrand_prime (n : β) (n_big : 2 < n)
(no_prime : Β¬β p : β, Nat.Prime p β§ n < p β§ p β€ 2 * n) :
centralBinom n β€ (2 * n) ^ sqrt (2 * n) * 4 ^ (2 * n / 3) | Mathlib_NumberTheory_Bertrand |
case hβ
n : β
n_big : 2 < n
no_prime : Β¬β p, Nat.Prime p β§ n < p β§ p β€ 2 * n
n_pos : 0 < n
n2_pos : 1 β€ 2 * n
S : Finset β := Finset.filter Nat.Prime (Finset.range (2 * n / 3 + 1))
f : β β β := fun x => x ^ (Nat.factorization (centralBinom n)) x
this : β x in S, f x = β x in Finset.range (2 * n / 3 + 1), f x
β’ β x in Finset.filter (fun x => x β€ sqrt (2 * n)) S, f x β€ (2 * n) ^ sqrt (2 * n) | /-
Copyright (c) 2020 Patrick Stevens. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Stevens, Bolton Bailey
-/
import Mathlib.Data.Nat.Choose.Factorization
import Mathlib.Data.Nat.PrimeNormNum
import Mathlib.NumberTheory.Primorial
import Mathlib.Analysis.Convex.SpecificFunctions.Basic
import Mathlib.Analysis.Convex.SpecificFunctions.Deriv
#align_import number_theory.bertrand from "leanprover-community/mathlib"@"a16665637b378379689c566204817ae792ac8b39"
/-!
# Bertrand's Postulate
This file contains a proof of Bertrand's postulate: That between any positive number and its
double there is a prime.
The proof follows the outline of the ErdΕs proof presented in "Proofs from THE BOOK": One considers
the prime factorization of `(2 * n).choose n`, and splits the constituent primes up into various
groups, then upper bounds the contribution of each group. This upper bounds the central binomial
coefficient, and if the postulate does not hold, this upper bound conflicts with a simple lower
bound for large enough `n`. This proves the result holds for large enough `n`, and for smaller `n`
an explicit list of primes is provided which covers the remaining cases.
As in the [Metamath implementation](carneiro2015arithmetic), we rely on some optimizations from
[Shigenori Tochiori](tochiori_bertrand). In particular we use the cleaner bound on the central
binomial coefficient given in `Nat.four_pow_lt_mul_centralBinom`.
## References
* [M. Aigner and G. M. Ziegler _Proofs from THE BOOK_][aigner1999proofs]
* [S. Tochiori, _Considering the Proof of βThere is a Prime between n and 2nβ_][tochiori_bertrand]
* [M. Carneiro, _Arithmetic in Metamath, Case Study: Bertrand's Postulate_][carneiro2015arithmetic]
## Tags
Bertrand, prime, binomial coefficients
-/
open scoped BigOperators
section Real
open Real
namespace Bertrand
/-- A reified version of the `Bertrand.main_inequality` below.
This is not best possible: it actually holds for 464 β€ x.
-/
theorem real_main_inequality {x : β} (n_large : (512 : β) β€ x) :
x * (2 * x) ^ sqrt (2 * x) * 4 ^ (2 * x / 3) β€ 4 ^ x := by
let f : β β β := fun x => log x + sqrt (2 * x) * log (2 * x) - log 4 / 3 * x
have hf' : β x, 0 < x β 0 < x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3) := fun x h =>
div_pos (mul_pos h (rpow_pos_of_pos (mul_pos two_pos h) _)) (rpow_pos_of_pos four_pos _)
have hf : β x, 0 < x β f x = log (x * (2 * x) ^ sqrt (2 * x) / 4 ^ (x / 3)) := by
intro x h5
have h6 := mul_pos (zero_lt_two' β) h5
have h7 := rpow_pos_of_pos h6 (sqrt (2 * x))
rw [log_div (mul_pos h5 h7).ne' (rpow_pos_of_pos four_pos _).ne', log_mul h5.ne' h7.ne',
log_rpow h6, log_rpow zero_lt_four, β mul_div_right_comm, β mul_div, mul_comm x]
have h5 : 0 < x := lt_of_lt_of_le (by norm_num1) n_large
rw [β div_le_one (rpow_pos_of_pos four_pos x), β div_div_eq_mul_div, β rpow_sub four_pos, β
mul_div 2 x, mul_div_left_comm, β mul_one_sub, (by norm_num1 : (1 : β) - 2 / 3 = 1 / 3),
mul_one_div, β log_nonpos_iff (hf' x h5), β hf x h5]
-- porting note: the proof was rewritten, because it was too slow
have h : ConcaveOn β (Set.Ioi 0.5) f := by
apply ConcaveOn.sub
apply ConcaveOn.add
exact strictConcaveOn_log_Ioi.concaveOn.subset
(Set.Ioi_subset_Ioi (by norm_num)) (convex_Ioi 0.5)
convert ((strictConcaveOn_sqrt_mul_log_Ioi.concaveOn.comp_linearMap
((2 : β) β’ LinearMap.id))) using 1
Β· ext x
simp only [Set.mem_Ioi, Set.mem_preimage, LinearMap.smul_apply,
LinearMap.id_coe, id_eq, smul_eq_mul]
rw [β mul_lt_mul_left (two_pos)]
norm_num1
rfl
apply ConvexOn.smul
refine div_nonneg (log_nonneg (by norm_num1)) (by norm_num1)
exact convexOn_id (convex_Ioi (0.5 : β))
suffices β x1 x2, 0.5 < x1 β§ x1 < x2 β§ x2 β€ x β§ 0 β€ f x1 β§ f x2 β€ 0 by
obtain β¨x1, x2, h1, h2, h0, h3, h4β© := this
exact (h.right_le_of_le_left'' h1 ((h1.trans h2).trans_le h0) h2 h0 (h4.trans h3)).trans h4
refine' β¨18, 512, by norm_num1, by norm_num1, n_large, _, _β©
Β· have : sqrt (2 * 18) = 6 := (sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonneg_iff, this]
rw [one_le_div] <;> norm_num1
apply le_trans _ (le_mul_of_one_le_left _ _) <;> norm_num1
apply Real.rpow_le_rpow <;> norm_num1
apply rpow_nonneg_of_nonneg; norm_num1
apply rpow_pos_of_pos; norm_num1
apply hf' 18; norm_num1
norm_num1
Β· have : sqrt (2 * 512) = 32 :=
(sqrt_eq_iff_mul_self_eq_of_pos (by norm_num1)).mpr (by norm_num1)
rw [hf, log_nonpos_iff (hf' _ _), this, div_le_one] <;> norm_num1
Β· conv in 512 => equals 2 ^ 9 => norm_num1
conv in 1024 => equals 2 ^ 10 => norm_num1
conv in 32 => rw [β Nat.cast_ofNat]
rw [rpow_nat_cast, β pow_mul, β pow_add]
conv in 4 => equals 2 ^ (2 : β) => rw [rpow_two]; norm_num1
rw [β rpow_mul, β rpow_nat_cast]
apply rpow_le_rpow_of_exponent_le
all_goals norm_num1
Β· apply rpow_pos_of_pos four_pos
#align bertrand.real_main_inequality Bertrand.real_main_inequality
end Bertrand
end Real
section Nat
open Nat
/-- The inequality which contradicts Bertrand's postulate, for large enough `n`.
-/
theorem bertrand_main_inequality {n : β} (n_large : 512 β€ n) :
n * (2 * n) ^ sqrt (2 * n) * 4 ^ (2 * n / 3) β€ 4 ^ n := by
rw [β @cast_le β]
simp only [cast_add, cast_one, cast_mul, cast_pow, β Real.rpow_nat_cast]
refine' _root_.trans ?_ (Bertrand.real_main_inequality (by exact_mod_cast n_large))
gcongr
Β· have n2_pos : 0 < 2 * n := by positivity
exact mod_cast n2_pos
Β· exact_mod_cast Real.nat_sqrt_le_real_sqrt
Β· norm_num1
Β· exact cast_div_le.trans (by norm_cast)
#align bertrand_main_inequality bertrand_main_inequality
/-- A lemma that tells us that, in the case where Bertrand's postulate does not hold, the prime
factorization of the central binomial coefficent only has factors at most `2 * n / 3 + 1`.
-/
theorem centralBinom_factorization_small (n : β) (n_large : 2 < n)
(no_prime : Β¬β p : β, p.Prime β§ n < p β§ p β€ 2 * n) :
centralBinom n = β p in Finset.range (2 * n / 3 + 1), p ^ (centralBinom n).factorization p := by
refine' (Eq.trans _ n.prod_pow_factorization_centralBinom).symm
apply Finset.prod_subset
Β· exact Finset.range_subset.2 (add_le_add_right (Nat.div_le_self _ _) _)
intro x hx h2x
rw [Finset.mem_range, lt_succ_iff] at hx h2x
rw [not_le, div_lt_iff_lt_mul' three_pos, mul_comm x] at h2x
replace no_prime := not_exists.mp no_prime x
rw [β and_assoc, not_and', not_and_or, not_lt] at no_prime
cases' no_prime hx with h h
Β· rw [factorization_eq_zero_of_non_prime n.centralBinom h, Nat.pow_zero]
Β· rw [factorization_centralBinom_of_two_mul_self_lt_three_mul n_large h h2x, Nat.pow_zero]
#align central_binom_factorization_small centralBinom_factorization_small
/-- An upper bound on the central binomial coefficient used in the proof of Bertrand's postulate.
The bound splits the prime factors of `centralBinom n` into those
1. At most `sqrt (2 * n)`, which contribute at most `2 * n` for each such prime.
2. Between `sqrt (2 * n)` and `2 * n / 3`, which contribute at most `4^(2 * n / 3)` in total.
3. Between `2 * n / 3` and `n`, which do not exist.
4. Between `n` and `2 * n`, which would not exist in the case where Bertrand's postulate is false.
5. Above `2 * n`, which do not exist.
-/
theorem centralBinom_le_of_no_bertrand_prime (n : β) (n_big : 2 < n)
(no_prime : Β¬β p : β, Nat.Prime p β§ n < p β§ p β€ 2 * n) :
centralBinom n β€ (2 * n) ^ sqrt (2 * n) * 4 ^ (2 * n / 3) := by
have n_pos : 0 < n := (Nat.zero_le _).trans_lt n_big
have n2_pos : 1 β€ 2 * n := mul_pos (zero_lt_two' β) n_pos
let S := (Finset.range (2 * n / 3 + 1)).filter Nat.Prime
let f x := x ^ n.centralBinom.factorization x
have : β x : β in S, f x = β x : β in Finset.range (2 * n / 3 + 1), f x := by
refine' Finset.prod_filter_of_ne fun p _ h => _
contrapose! h; dsimp only
rw [factorization_eq_zero_of_non_prime n.centralBinom h, _root_.pow_zero]
rw [centralBinom_factorization_small n n_big no_prime, β this, β
Finset.prod_filter_mul_prod_filter_not S (Β· β€ sqrt (2 * n))]
apply mul_le_mul'
Β· | refine' (Finset.prod_le_prod' fun p _ => (_ : f p β€ 2 * n)).trans _ | /-- An upper bound on the central binomial coefficient used in the proof of Bertrand's postulate.
The bound splits the prime factors of `centralBinom n` into those
1. At most `sqrt (2 * n)`, which contribute at most `2 * n` for each such prime.
2. Between `sqrt (2 * n)` and `2 * n / 3`, which contribute at most `4^(2 * n / 3)` in total.
3. Between `2 * n / 3` and `n`, which do not exist.
4. Between `n` and `2 * n`, which would not exist in the case where Bertrand's postulate is false.
5. Above `2 * n`, which do not exist.
-/
theorem centralBinom_le_of_no_bertrand_prime (n : β) (n_big : 2 < n)
(no_prime : Β¬β p : β, Nat.Prime p β§ n < p β§ p β€ 2 * n) :
centralBinom n β€ (2 * n) ^ sqrt (2 * n) * 4 ^ (2 * n / 3) := by
have n_pos : 0 < n := (Nat.zero_le _).trans_lt n_big
have n2_pos : 1 β€ 2 * n := mul_pos (zero_lt_two' β) n_pos
let S := (Finset.range (2 * n / 3 + 1)).filter Nat.Prime
let f x := x ^ n.centralBinom.factorization x
have : β x : β in S, f x = β x : β in Finset.range (2 * n / 3 + 1), f x := by
refine' Finset.prod_filter_of_ne fun p _ h => _
contrapose! h; dsimp only
rw [factorization_eq_zero_of_non_prime n.centralBinom h, _root_.pow_zero]
rw [centralBinom_factorization_small n n_big no_prime, β this, β
Finset.prod_filter_mul_prod_filter_not S (Β· β€ sqrt (2 * n))]
apply mul_le_mul'
Β· | Mathlib.NumberTheory.Bertrand.155_0.gJXoOT9Ce2wC0xc | /-- An upper bound on the central binomial coefficient used in the proof of Bertrand's postulate.
The bound splits the prime factors of `centralBinom n` into those
1. At most `sqrt (2 * n)`, which contribute at most `2 * n` for each such prime.
2. Between `sqrt (2 * n)` and `2 * n / 3`, which contribute at most `4^(2 * n / 3)` in total.
3. Between `2 * n / 3` and `n`, which do not exist.
4. Between `n` and `2 * n`, which would not exist in the case where Bertrand's postulate is false.
5. Above `2 * n`, which do not exist.
-/
theorem centralBinom_le_of_no_bertrand_prime (n : β) (n_big : 2 < n)
(no_prime : Β¬β p : β, Nat.Prime p β§ n < p β§ p β€ 2 * n) :
centralBinom n β€ (2 * n) ^ sqrt (2 * n) * 4 ^ (2 * n / 3) | Mathlib_NumberTheory_Bertrand |