cfahlgren1/math / lean /OAI /NumberTheory /Jacobsthal /Primes /PrimeDensityBlocks.lean
cfahlgren1's picture
download
raw
14.5 kB
import Mathlib.Data.Nat.Log
import Mathlib.Tactic
import OAI.NumberTheory.Jacobsthal.Estimates.DisjointBlockExpansion
import OAI.NumberTheory.Jacobsthal.Estimates.SquarefreeHarmonic
namespace OAI
namespace Erdos970
section
namespace NumberTheoryLean.PrimeDensityBlocks
open scoped BigOperators
def dyadicPrimes (n : ℕ) : Finset ℕ := (Finset.Ico n (2 * n)).filter Nat.Prime
@[simp] theorem mem_dyadicPrimes {n p : ℕ} :
p ∈ dyadicPrimes n ↔ n ≤ p ∧ p < 2 * n ∧ p.Prime := by
simp only [dyadicPrimes, Finset.mem_filter, Finset.mem_Ico]
tauto
theorem dyadicPrimes_subset_survivors (n : ℕ) :
dyadicPrimes n ⊆ {n} ∪
(LargePrimeDeletion.cutoffSurvivors n n (LargePrimeDeletion.divisibilityResidue (n : ℤ))).image
(fun i => n + i) := by
intro p hp
obtain ⟨hnp, hp2n, hprime⟩ := mem_dyadicPrimes.mp hp
by_cases heq : p = n
· exact Finset.mem_union_left _ (by simp [heq])
· have hnp' : n < p := lt_of_le_of_ne hnp (Ne.symm heq)
apply Finset.mem_union_right
apply Finset.mem_image.mpr
refine ⟨p - n, ?_, Nat.add_sub_of_le hnp⟩
apply LargePrimeDeletion.mem_cutoffSurvivors.mpr
refine ⟨by omega, ?_⟩
intro q hq hqn hbad
have hdiv := (LargePrimeDeletion.divisibility_iff_modEq (n : ℤ) hq.pos (p - n)).mpr hbad
have hdivN : q ∣ p := by
have hnEq : (n : ℤ) + (p - n : ℕ) = p := by exact_mod_cast Nat.add_sub_of_le hnp
rw [hnEq] at hdiv
exact Int.natCast_dvd_natCast.mp hdiv
have hqp : q = p := (Nat.prime_dvd_prime_iff_eq hq hprime).mp hdivN
omega
theorem dyadicPrimes_card_le (n : ℕ) :
((dyadicPrimes n).card : ℝ) ≤ 1 + 255 * (1 + (n : ℝ) / Real.log n) := by
let C := LargePrimeDeletion.cutoffSurvivors n n (LargePrimeDeletion.divisibilityResidue (n : ℤ))
have hcard : (dyadicPrimes n).card ≤ 1 + C.card := by
calc
_ ≤ ({n} ∪ C.image (fun i => n + i)).card := Finset.card_le_card (dyadicPrimes_subset_survivors n)
_ ≤ ({n} : Finset ℕ).card + (C.image (fun i => n + i)).card := Finset.card_union_le _ _
_ ≤ 1 + C.card := by simpa using Nat.add_le_add_left (Finset.card_image_le) 1
have hcardR : ((dyadicPrimes n).card : ℝ) ≤ 1 + (C.card : ℝ) := by exact_mod_cast hcard
exact hcardR.trans (add_le_add le_rfl
(SquarefreeHarmonic.cutoffSurvivors_le_uniform_log n n _ le_rfl))
theorem self_le_two_pow (k : ℕ) : k ≤ 2 ^ k := by
induction k with
| zero => simp
| succ k ih =>
have hpos : 1 ≤ 2 ^ k := Nat.one_le_pow _ _ (by norm_num)
rw [pow_succ]
omega
theorem dyadic_density_sum_le (k : ℕ) (hk : 1 ≤ k) (g : ℕ → ℝ)
(hg : ∀ p ∈ dyadicPrimes (2 ^ k), g p ≤ 2 / p) :
(∑ p ∈ dyadicPrimes (2 ^ k), g p) ≤ 1532 / (k : ℝ) := by
let n : ℕ := 2 ^ k
have hnpos : (0 : ℝ) < n := by dsimp [n]; positivity
have hkpos : (0 : ℝ) < k := by exact_mod_cast hk
have hkn : (k : ℝ) ≤ n := by exact_mod_cast self_le_two_pow k
have hlog2 : (1 / 2 : ℝ) ≤ Real.log 2 := by
have h := Real.one_sub_inv_le_log_of_pos (by norm_num : (0 : ℝ) < 2)
norm_num at h
exact h
have hlogeq : Real.log (n : ℝ) = (k : ℝ) * Real.log 2 := by
simp only [n, Nat.cast_pow, Nat.cast_ofNat, Real.log_pow]
have hloglower : (k : ℝ) / 2 ≤ Real.log (n : ℝ) := by
rw [hlogeq]
nlinarith [mul_nonneg hkpos.le (sub_nonneg.mpr hlog2)]
have hlogpos : 0 < Real.log (n : ℝ) := by linarith
have hsum : (∑ p ∈ dyadicPrimes n, g p) ≤ ((dyadicPrimes n).card : ℝ) * (2 / n) := by
calc
_ ≤ ∑ _p ∈ dyadicPrimes n, (2 / n : ℝ) := by
apply Finset.sum_le_sum
intro p hp
apply (hg p hp).trans
exact div_le_div_of_nonneg_left (by norm_num) hnpos
(by exact_mod_cast (mem_dyadicPrimes.mp hp).1)
_ = _ := by simp
have hcount := dyadicPrimes_card_le n
have hfirst : (512 : ℝ) / n ≤ 512 / (k : ℝ) :=
div_le_div_of_nonneg_left (by norm_num) hkpos hkn
have hsecond : (510 : ℝ) / Real.log (n : ℝ) ≤ 1020 / (k : ℝ) := by
apply (div_le_div_iff₀ hlogpos hkpos).mpr
nlinarith
calc
(∑ p ∈ dyadicPrimes (2 ^ k), g p) ≤ ((dyadicPrimes n).card : ℝ) * (2 / n) := hsum
_ ≤ (1 + 255 * (1 + (n : ℝ) / Real.log n)) * (2 / n) :=
mul_le_mul_of_nonneg_right hcount (by positivity)
_ = (512 : ℝ) / n + 510 / Real.log (n : ℝ) := by field_simp; ring
_ ≤ 512 / (k : ℝ) + 1020 / (k : ℝ) := add_le_add hfirst hsecond
_ = _ := by ring
def geometricPrimes (j : ℕ) : Finset ℕ :=
(Finset.Ico (2 ^ (2 ^ j)) (2 ^ (2 ^ (j + 1)))).filter Nat.Prime
@[simp] theorem mem_geometricPrimes {j p : ℕ} :
p ∈ geometricPrimes j ↔ 2 ^ (2 ^ j) ≤ p ∧ p < 2 ^ (2 ^ (j + 1)) ∧ p.Prime := by
simp only [geometricPrimes, Finset.mem_filter, Finset.mem_Ico]
tauto
theorem dyadicPrimes_disjoint {k l : ℕ} (hkl : k ≠ l) :
Disjoint (dyadicPrimes (2 ^ k)) (dyadicPrimes (2 ^ l)) := by
apply Finset.disjoint_left.mpr
intro p hp hk
obtain ⟨hkp, hpk, _⟩ := mem_dyadicPrimes.mp hp
obtain ⟨hlp, hpl, _⟩ := mem_dyadicPrimes.mp hk
rcases lt_or_gt_of_ne hkl with hlt | hlt
· have hpow : 2 ^ (k + 1) ≤ 2 ^ l := Nat.pow_le_pow_right (by norm_num) (Nat.succ_le_of_lt hlt)
rw [pow_succ, Nat.mul_comm] at hpow
omega
· have hpow : 2 ^ (l + 1) ≤ 2 ^ k := Nat.pow_le_pow_right (by norm_num) (Nat.succ_le_of_lt hlt)
rw [pow_succ, Nat.mul_comm] at hpow
omega
theorem geometricPrimes_eq_dyadic_union (j : ℕ) :
geometricPrimes j = (Finset.Ico (2 ^ j : ℕ) (2 ^ (j + 1))).biUnion
(fun k => dyadicPrimes (2 ^ k)) := by
ext p
constructor
· intro hp
obtain ⟨hlo, hhi, hprime⟩ := mem_geometricPrimes.mp hp
let k := Nat.log 2 p
have hklo : 2 ^ j ≤ k := Nat.le_log_of_pow_le (by norm_num) hlo
have hkhi : k < 2 ^ (j + 1) := Nat.log_lt_of_lt_pow hprime.ne_zero hhi
apply Finset.mem_biUnion.mpr
refine ⟨k, Finset.mem_Ico.mpr ⟨hklo, hkhi⟩, ?_⟩
apply mem_dyadicPrimes.mpr
refine ⟨Nat.pow_log_le_self 2 hprime.ne_zero, ?_, hprime⟩
have h := Nat.lt_pow_succ_log_self (by norm_num : 1 < 2) p
simpa only [pow_succ, Nat.mul_comm] using h
· intro hp
obtain ⟨k, hk, hpk⟩ := Finset.mem_biUnion.mp hp
obtain ⟨hklo, hkhi⟩ := Finset.mem_Ico.mp hk
obtain ⟨hkp, hpk, hprime⟩ := mem_dyadicPrimes.mp hpk
apply mem_geometricPrimes.mpr
refine ⟨(Nat.pow_le_pow_right (by norm_num) hklo).trans hkp, ?_, hprime⟩
have hpow : 2 ^ (k + 1) ≤ 2 ^ (2 ^ (j + 1)) :=
Nat.pow_le_pow_right (by norm_num) (Nat.succ_le_of_lt hkhi)
rw [pow_succ, Nat.mul_comm] at hpow
exact hpk.trans_le hpow
theorem geometric_reciprocal_sum_le (j : ℕ) :
(∑ p ∈ geometricPrimes j, (2 : ℝ) / p) ≤ 1532 := by
rw [geometricPrimes_eq_dyadic_union]
rw [Finset.sum_biUnion (fun k _ l _ hkl => dyadicPrimes_disjoint hkl)]
have hKpos : (0 : ℝ) < (2 ^ j : ℕ) := by positivity
calc
_ ≤ ∑ k ∈ Finset.Ico (2 ^ j : ℕ) (2 ^ (j + 1)), (1532 : ℝ) / (k : ℝ) := by
apply Finset.sum_le_sum
intro k hk
have hk1 : 1 ≤ k := (Nat.one_le_pow _ _ (by norm_num)).trans (Finset.mem_Ico.mp hk).1
exact dyadic_density_sum_le k hk1 (fun p => (2 : ℝ) / p) (fun _ _ => le_rfl)
_ ≤ ∑ _k ∈ Finset.Ico (2 ^ j : ℕ) (2 ^ (j + 1)), (1532 : ℝ) / (2 ^ j : ℕ) := by
apply Finset.sum_le_sum
intro k hk
exact div_le_div_of_nonneg_left (by norm_num) hKpos
(by exact_mod_cast (Finset.mem_Ico.mp hk).1)
_ = 1532 := by
have hcard : (Finset.Ico (2 ^ j : ℕ) (2 ^ (j + 1))).card = 2 ^ j := by
rw [Nat.card_Ico, pow_succ]
omega
simp only [Finset.sum_const, hcard, nsmul_eq_mul]
field_simp
theorem subset_geometric_density_sum_le (j : ℕ) (Q : Finset ℕ) (hQ : Q ⊆ geometricPrimes j)
(g : ℕ → ℝ) (hg : ∀ p ∈ Q, g p ≤ 2 / p) : (∑ p ∈ Q, g p) ≤ 1532 := by
calc
_ ≤ ∑ p ∈ Q, (2 : ℝ) / p := Finset.sum_le_sum hg
_ ≤ ∑ p ∈ geometricPrimes j, (2 : ℝ) / p :=
Finset.sum_le_sum_of_subset_of_nonneg hQ (fun _ _ _ => by positivity)
_ ≤ _ := geometric_reciprocal_sum_le j
def lastBlock (V : ℕ) : ℕ := Nat.log 2 (Nat.log 2 V)
def blockIndices (V : ℕ) : Finset ℕ := Finset.range (lastBlock V + 1)
def primeBlock (P : Finset ℕ) (j : ℕ) : Finset ℕ := P ∩ geometricPrimes j
theorem geometricPrimes_disjoint {i j : ℕ} (hij : i ≠ j) :
Disjoint (geometricPrimes i) (geometricPrimes j) := by
apply Finset.disjoint_left.mpr
intro p hp hq
obtain ⟨hil, hiu, _⟩ := mem_geometricPrimes.mp hp
obtain ⟨hjl, hju, _⟩ := mem_geometricPrimes.mp hq
rcases lt_or_gt_of_ne hij with hlt | hlt
· have hexp : 2 ^ (i + 1) ≤ 2 ^ j := Nat.pow_le_pow_right (by norm_num) (Nat.succ_le_of_lt hlt)
have hpowers := Nat.pow_le_pow_right (by norm_num : 1 ≤ 2) hexp
omega
· have hexp : 2 ^ (j + 1) ≤ 2 ^ i := Nat.pow_le_pow_right (by norm_num) (Nat.succ_le_of_lt hlt)
have hpowers := Nat.pow_le_pow_right (by norm_num : 1 ≤ 2) hexp
omega
theorem primeBlock_pairwise (V : ℕ) (P : Finset ℕ) :
(blockIndices V : Set ℕ).Pairwise fun i j => Disjoint (primeBlock P i) (primeBlock P j) := by
intro i _ j _ hij
exact (geometricPrimes_disjoint hij).mono Finset.inter_subset_right Finset.inter_subset_right
theorem primeBlock_union (V : ℕ) (P : Finset ℕ)
(hprime : ∀ p ∈ P, p.Prime) (hV : ∀ p ∈ P, p ≤ V) :
(blockIndices V).biUnion (primeBlock P) = P := by
ext p
constructor
· intro hp
obtain ⟨j, _, hpj⟩ := Finset.mem_biUnion.mp hp
exact (Finset.mem_inter.mp hpj).1
· intro hp
have hpp := hprime p hp
let k := Nat.log 2 p
let j := Nat.log 2 k
have hk1 : 1 ≤ k := Nat.le_log_of_pow_le (by norm_num) (by simpa using hpp.two_le)
have hk0 : k ≠ 0 := by omega
have hjlast : j ≤ lastBlock V := Nat.log_mono_right (Nat.log_mono_right (hV p hp))
have hlo : 2 ^ (2 ^ j) ≤ p :=
(Nat.pow_le_pow_right (by norm_num) (Nat.pow_log_le_self 2 hk0)).trans
(Nat.pow_log_le_self 2 hpp.ne_zero)
have hhi : p < 2 ^ (2 ^ (j + 1)) := by
have hkj : k < 2 ^ (j + 1) := Nat.lt_pow_succ_log_self (by norm_num) k
have hpk : p < 2 ^ (k + 1) := Nat.lt_pow_succ_log_self (by norm_num) p
exact hpk.trans_le (Nat.pow_le_pow_right (by norm_num) (Nat.succ_le_of_lt hkj))
exact Finset.mem_biUnion.mpr ⟨j, Finset.mem_range.mpr (Nat.lt_succ_of_le hjlast),
Finset.mem_inter.mpr ⟨hp, mem_geometricPrimes.mpr ⟨hlo, hhi, hpp⟩⟩⟩
theorem primeBlock_density_sum_le (P : Finset ℕ) (j : ℕ) (g : ℕ → ℝ)
(hdim : ∀ p ∈ P, g p ≤ 2 / p) : (∑ p ∈ primeBlock P j, g p) ≤ 1532 :=
subset_geometric_density_sum_le j _ Finset.inter_subset_right g
(fun p hp => hdim p (Finset.mem_inter.mp hp).1)
def reverseOrder (m J j : ℕ) : ℕ := m + (J - j)
def supportCost (m J : ℕ) : ℕ :=
∑ j ∈ Finset.range (J + 1), 2 ^ (j + 1) * (2 * reverseOrder m J j + 1)
theorem supportCost_succ (m J : ℕ) :
supportCost m (J + 1) = supportCost (m + 1) J + 2 ^ (J + 2) * (2 * m + 1) := by
unfold supportCost
rw [Finset.sum_range_succ]
have hsum : (∑ j ∈ Finset.range (J + 1), 2 ^ (j + 1) * (2 * reverseOrder m (J + 1) j + 1)) =
∑ j ∈ Finset.range (J + 1), 2 ^ (j + 1) * (2 * reverseOrder (m + 1) J j + 1) := by
apply Finset.sum_congr rfl
intro j hj
have hjJ : j ≤ J := Nat.le_of_lt_succ (Finset.mem_range.mp hj)
have horder : reverseOrder m (J + 1) j = reverseOrder (m + 1) J j := by
unfold reverseOrder
omega
rw [horder]
rw [hsum]
simp only [reverseOrder, Nat.sub_self, Nat.add_zero]
theorem supportCost_le (m J : ℕ) : supportCost m J ≤ (8 * m + 12) * 2 ^ J := by
induction J generalizing m with
| zero => simp [supportCost, reverseOrder]; omega
| succ J ih =>
rw [supportCost_succ]
calc
_ ≤ (8 * (m + 1) + 12) * 2 ^ J + 2 ^ (J + 2) * (2 * m + 1) :=
Nat.add_le_add_right (ih (m + 1)) _
_ = (8 * m + 12) * 2 ^ (J + 1) := by simp only [pow_add]; norm_num; ring
theorem supportCost_le_twelve (m J : ℕ) : supportCost m J ≤ 12 * (m + 1) * 2 ^ J := by
apply (supportCost_le m J).trans
exact Nat.mul_le_mul_right (2 ^ J) (by omega)
theorem lastBlock_lower_le (V : ℕ) (hV : 2 ≤ V) : 2 ^ (2 ^ lastBlock V) ≤ V := by
have hlog1 : 1 ≤ Nat.log 2 V := Nat.le_log_of_pow_le (by norm_num) (by simpa using hV)
have hlog0 : Nat.log 2 V ≠ 0 := by omega
have hinner : 2 ^ lastBlock V ≤ Nat.log 2 V := Nat.pow_log_le_self 2 hlog0
exact (Nat.pow_le_pow_right (by norm_num) hinner).trans (Nat.pow_log_le_self 2 (by omega))
theorem supportHeight_product_le (V m : ℕ) (hV : 2 ≤ V) :
(∏ j ∈ blockIndices V, (2 ^ (2 ^ (j + 1))) ^ (2 * reverseOrder m (lastBlock V) j + 1)) ≤
V ^ (12 * (m + 1)) := by
simp only [← pow_mul]
rw [Finset.prod_pow_eq_pow_sum]
change 2 ^ supportCost m (lastBlock V) ≤ _
calc
_ ≤ 2 ^ (12 * (m + 1) * 2 ^ lastBlock V) :=
Nat.pow_le_pow_right (by norm_num) (supportCost_le_twelve m (lastBlock V))
_ = (2 ^ (2 ^ lastBlock V)) ^ (12 * (m + 1)) := by rw [← pow_mul, Nat.mul_comm]
_ ≤ _ := Nat.pow_le_pow_left (lastBlock_lower_le V hV) _
noncomputable def actualLowerCoefficient (V m : ℕ) (P : Finset ℕ) (T : Finset ℕ) : ℝ :=
DisjointBlockExpansion.lowerCoefficient (blockIndices V) (primeBlock P)
(reverseOrder m (lastBlock V)) T
theorem actualLowerCoefficient_support (V m : ℕ) (P : Finset ℕ) (hV : 2 ≤ V)
(hprime : ∀ p ∈ P, p.Prime) (hsize : ∀ p ∈ P, p ≤ V)
{T : Finset ℕ} (hT : T ⊆ P) (hc : actualLowerCoefficient V m P T ≠ 0) :
Squarefree (∏ p ∈ T, p) ∧ (∏ p ∈ T, p) ≤ V ^ (12 * (m + 1)) := by
have hTu : T ⊆ (blockIndices V).biUnion (primeBlock P) := by
simpa only [primeBlock_union V P hprime hsize] using hT
have hbound := DisjointBlockExpansion.lowerCoefficient_prime_support (blockIndices V) (primeBlock P)
(primeBlock_pairwise V P) (reverseOrder m (lastBlock V)) (fun j => 2 ^ (2 ^ (j + 1)))
(fun j _ => Nat.one_le_pow _ _ (by norm_num))
(fun j _ p hp => hprime p (Finset.mem_inter.mp hp).1)
(fun j _ p hp => (mem_geometricPrimes.mp (Finset.mem_inter.mp hp).2).2.1.le) hTu hc
exact ⟨hbound.1, hbound.2.trans (supportHeight_product_le V m hV)⟩
end NumberTheoryLean.PrimeDensityBlocks
end
end Erdos970
end OAI

Xet Storage Details

Size:
14.5 kB
·
Xet hash:
7c97cecc6d5298cbfc3cc32320e4b6a250b428c70e29ac710976ba08ab943654

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.