Lean / Reader
Lean reader

Erdos824Semiprime.lean

106 lines7 declarationsno sorryimports Erdos824Primitive Mathlib.Algebra.Order.Chebyshev

Lean 4 Web has Mathlib, so it can check files that import only Mathlib. This one also imports Erdos824Primitive, which it does not have: you can read it there, but it will not check. Build the project itself to check it.

  1. import Erdos824Primitive
  2. import Mathlib.Algebra.Order.Chebyshev
  3. namespace Erdos824Primitive
  4. open ArithmeticFunction
  5. private lemma sigma_prime {p : ℕ} (hp : p.Prime) : sigma 1 p = p+1 := by
  6. have hh := sigma_one_apply_prime_pow (i := 1) hp
  7. simpa [Finset.sum_range_succ, add_comm] using hh
  8. private lemma proper_divisor_semiprime {u p q : ℕ} (hp : p.Prime) (hq : q.Prime)
  9. (hu : 1 < u) (hlt : u < p*q) (hdiv : u ∣ p*q) : u = p ∨ u = q := by
  10. obtain ⟨x,y,hx,hy,rfl⟩ := exists_dvd_and_dvd_of_dvd_mul hdiv
  11. rcases (Nat.dvd_prime hp).mp hx with rfl | rfl <;>
  12. rcases (Nat.dvd_prime hq).mp hy with rfl | rfl <;> simp_all
  13. /-- Two hits in one row of the shifted-prime construction give an unordered
  14. primitive pair of squarefree semiprimes. Here p+1=(q+1)n and t+1=(r+1)n. -/
  15. theorem semiprime_construction {q r p t n : ℕ} (hq : q.Prime) (hr : r.Prime)
  16. (hp : p.Prime) (ht : t.Prime) (hqr : q < r) (hrp : r < p) (hpt : p < t)
  17. (hn : 1 < n) (hpv : p+1=(q+1)*n) (htv : t+1=(r+1)*n) :
  18. q*t < r*p ∧ Primitive (q*t,r*p) ∧ Squarefree (q*t) ∧ Squarefree (r*p) := by
  19. have hqt := (Nat.coprime_primes hq ht).mpr (show q ≠ t by omega)
  20. have hrp' := (Nat.coprime_primes hr hp).mpr hrp.ne
  21. have hcop : (q*t).Coprime (r*p) := by
  22. exact ((Nat.coprime_primes hq hr).mpr hqr.ne).mul_right
  23. ((Nat.coprime_primes hq hp).mpr (show q ≠ p by omega)) |>.mul_left
  24. (((Nat.coprime_primes ht hr).mpr (show t ≠ r by omega)).mul_right
  25. ((Nat.coprime_primes ht hp).mpr hpt.ne'))
  26. have hsig : sigma 1 (q*t) = sigma 1 (r*p) := by
  27. rw [isMultiplicative_sigma.map_mul_of_coprime hqt, isMultiplicative_sigma.map_mul_of_coprime hrp',
  28. sigma_prime hq, sigma_prime ht, sigma_prime hr, sigma_prime hp, htv, hpv]
  29. ring
  30. have hlt : q*t < r*p := by
  31. zify at hpv htv hqr hn ⊢
  32. nlinarith [mul_pos (sub_pos.mpr hqr) (sub_pos.mpr hn),
  33. congrArg (fun z : ℤ ↦ (q : ℤ)*z) htv, congrArg (fun z : ℤ ↦ (r : ℤ)*z) hpv]
  34. refine ⟨hlt, ⟨⟨by have := hq.one_lt; have := ht.one_lt; nlinarith,
  35. by have := hr.one_lt; have := hp.one_lt; nlinarith,hcop,hsig⟩,?_⟩,
  36. (Nat.squarefree_mul hqt).mpr ⟨hq.squarefree,ht.squarefree⟩,
  37. (Nat.squarefree_mul hrp').mpr ⟨hr.squarefree,hp.squarefree⟩⟩
  38. intro hsplit
  39. obtain ⟨u,v,hu,hua,hud,hv,hvb,hvd,_,_,he⟩ := (splits_iff_unitary_divisors _ _).mp hsplit
  40. have huv := proper_divisor_semiprime hq ht hu hua hud
  41. have hvv := proper_divisor_semiprime hr hp hv hvb hvd
  42. rcases huv with rfl | rfl <;> rcases hvv with rfl | rfl <;>
  43. simp only [sigma_prime hq, sigma_prime hr, sigma_prime hp, sigma_prime ht] at he <;> omega
  44. /-- The gap has one fewer large prime factor than either constructed number. -/
  45. theorem semiprime_gap {q r p t n : ℕ} (hqr : q ≤ r) (hn : 1 ≤ n)
  46. (hpv : p+1=(q+1)*n) (htv : t+1=(r+1)*n) :
  47. r*p-q*t = (r-q)*(n-1) := by
  48. have he : r*p = q*t + (r-q)*(n-1) := by
  49. zify [hqr,hn] at hpv htv ⊢
  50. nlinarith [congrArg (fun z : ℤ ↦ (q : ℤ)*z) htv, congrArg (fun z : ℤ ↦ (r : ℤ)*z) hpv]
  51. omega
  52. /-- Cauchy--Schwarz supplies many unordered collisions as soon as the mean
  53. incidence degree is at least two. Degrees are viewed in the reals. -/
  54. theorem row_collision_bound {ι : Type*} (S : Finset ι) (d : ι → ℕ)
  55. (hmean : 2*(S.card : ℝ) ≤ ∑ i ∈ S, (d i : ℝ)) :
  56. (∑ i ∈ S, (d i : ℝ))^2 ≤
  57. 4*(S.card : ℝ) * (∑ i ∈ S, (d i : ℝ)*((d i : ℝ)-1)/2) := by
  58. have hcs := sq_sum_le_card_mul_sum_sq (s := S) (f := fun i ↦ (d i : ℝ))
  59. have hid : (∑ i ∈ S, (d i : ℝ)^2) =
  60. 2*(∑ i ∈ S, (d i : ℝ)*((d i : ℝ)-1)/2) + ∑ i ∈ S, (d i : ℝ) := by
  61. rw [Finset.mul_sum, ← Finset.sum_add_distrib]
  62. apply Finset.sum_congr rfl
  63. intro i _; ring
  64. rw [hid] at hcs
  65. have hnon : 0 ≤ ∑ i ∈ S, (d i : ℝ) := by positivity
  66. nlinarith [mul_le_mul_of_nonneg_right hmean hnon]
  67. private lemma ordered_factors_unique {a b c d : ℕ} (ha : a.Prime) (hb : b.Prime)
  68. (hc : c.Prime) (hd : d.Prime) (hab : a < b) (hcd : c < d) (he : a*b = c*d) :
  69. a = c ∧ b = d := by
  70. have ha' : a ∣ c*d := he ▸ dvd_mul_right a b
  71. have hc' : c ∣ a*b := he.symm ▸ dvd_mul_right c d
  72. have hac : a = c := by
  73. rcases ha.dvd_mul.mp ha' with hh | hh
  74. · exact (Nat.prime_dvd_prime_iff_eq ha hc).mp hh
  75. · have had := (Nat.prime_dvd_prime_iff_eq ha hd).mp hh
  76. rcases hc.dvd_mul.mp hc' with hh | hh
  77. · exact ((Nat.prime_dvd_prime_iff_eq hc ha).mp hh).symm
  78. · have := (Nat.prime_dvd_prime_iff_eq hc hb).mp hh
  79. omega
  80. subst c
  81. exact ⟨rfl, Nat.eq_of_mul_eq_mul_left ha.pos he⟩
  82. /-- Sorted output products recover the small primes and the original row. -/
  83. theorem semiprime_parameters_unique {q r p t n q' r' p' t' n' : ℕ}
  84. (hq : q.Prime) (hr : r.Prime) (hp : p.Prime) (ht : t.Prime)
  85. (hq' : q'.Prime) (hr' : r'.Prime) (hp' : p'.Prime) (ht' : t'.Prime)
  86. (hqt : q < t) (hrp : r < p) (hqt' : q' < t') (hrp' : r' < p')
  87. (htv : t+1=(r+1)*n) (htv' : t'+1=(r'+1)*n')
  88. (ha : q*t=q'*t') (hb : r*p=r'*p') : q=q' ∧ r=r' ∧ n=n' := by
  89. obtain ⟨rfl,rfl⟩ := ordered_factors_unique hq ht hq' ht' hqt hqt' ha
  90. obtain ⟨rfl,rfl⟩ := ordered_factors_unique hr hp hr' hp' hrp hrp' hb
  91. exact ⟨rfl,rfl,Nat.eq_of_mul_eq_mul_left (by omega) (htv.symm.trans htv')⟩
  92. #print axioms semiprime_construction
  93. #print axioms semiprime_gap
  94. #print axioms semiprime_parameters_unique
  95. #print axioms row_collision_bound
  96. end Erdos824Primitive