Lean / Reader
Lean reader

Erdos824Rectangle.lean

204 lines13 declarationsno sorryimports Erdos824Semiprime

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

  1. import Erdos824Semiprime
  2. namespace Erdos824Primitive
  3. /-- Every positive integral rank-one rectangle has a primitive first row.
  4. Strict increase from its top left gives strictly increasing parameters. -/
  5. theorem rectangle_parameters {A B C D : ℕ} (hA : 0 < A) (hAB : A < B) (hAC : A < C)
  6. (he : A*D = B*C) : ∃ s t u v : ℕ, 0 < s ∧ 0 < u ∧ s<t ∧ u<v ∧
  7. u.Coprime v ∧ A=s*u ∧ B=s*v ∧ C=t*u ∧ D=t*v := by
  8. let s := A.gcd B
  9. let u := A / s
  10. let v := B / s
  11. have hs : 0 < s := Nat.gcd_pos_of_pos_left B hA
  12. have ha : s*u=A := by simpa [s,u,Nat.mul_comm] using Nat.div_mul_cancel (Nat.gcd_dvd_left A B)
  13. have hb : s*v=B := by simpa [s,v,Nat.mul_comm] using Nat.div_mul_cancel (Nat.gcd_dvd_right A B)
  14. have hu : 0 < u := by
  15. apply Nat.pos_of_ne_zero
  16. intro hz
  17. rw [hz,Nat.mul_zero] at ha
  18. exact (Nat.ne_of_gt hA) ha.symm
  19. have huv : u.Coprime v := Nat.coprime_div_gcd_div_gcd hs
  20. have hcancel : u*D=v*C := Nat.eq_of_mul_eq_mul_left hs (by simpa only [← Nat.mul_assoc, ha, hb] using he)
  21. have hdiv : u ∣ C := huv.dvd_of_dvd_mul_left (hcancel ▸ dvd_mul_right u D)
  22. obtain ⟨t,ht⟩ := hdiv
  23. have hD : D=t*v := Nat.eq_of_mul_eq_mul_left hu (by rw [hcancel,ht]; ring)
  24. refine ⟨s,t,u,v,hs,hu,?_,?_,huv,ha.symm,hb.symm,by simpa [Nat.mul_comm] using ht,hD⟩
  25. · apply Nat.lt_of_mul_lt_mul_left (a := u)
  26. simpa only [Nat.mul_comm u s,ha,←ht] using hAC
  27. · exact Nat.lt_of_mul_lt_mul_left (ha ▸ hb ▸ hAB)
  28. /-- The gap in the ordered products of four shifted primes is the product
  29. of adjacent row and column differences. -/
  30. theorem rectangle_gap {s t u v P Q R T : ℕ} (hst : s ≤ t) (huv : u ≤ v)
  31. (hP : P+1=s*u) (hQ : Q+1=s*v) (hR : R+1=t*u) (hT : T+1=t*v) :
  32. Q*R=P*T+(t-s)*(v-u) := by
  33. zify [hst,huv] at *
  34. linear_combination ((t:ℤ)*u-1)*hQ + (Q:ℤ)*hR - ((t:ℤ)*v-1)*hP - (P:ℤ)*hT
  35. /-- The factor 2 at the smallest corner forces an upper bound purely in
  36. terms of the gap. This applies to every odd gap between squarefree semiprimes. -/
  37. theorem rectangle_two_bound {s t u v Q R : ℕ} (hs : 0<s) (hu : 0<u)
  38. (hst : s<t) (huv : u<v) (hcorner : s*u=3) (hQ : Q+1=s*v) (hR : R+1=t*u) :
  39. Q*R ≤ 9*((t-s)*(v-u))+6 := by
  40. have hds := (Nat.dvd_prime Nat.prime_three).mp (hcorner ▸ dvd_mul_right s u)
  41. have hdu := (Nat.dvd_prime Nat.prime_three).mp (hcorner ▸ dvd_mul_left u s)
  42. rcases hds with rfl | rfl <;> rcases hdu with rfl | rfl <;> norm_num at hcorner
  43. · zify [hst.le,huv.le] at *
  44. have hx : (Q:ℤ)*R = (v-1)*(3*t-1) := by
  45. linear_combination ((R:ℤ))*hQ + ((v:ℤ)-1)*hR
  46. rw [hx]
  47. nlinarith [mul_nonneg (show (0:ℤ) ≤ 6*t-8 by omega) (show (0:ℤ) ≤ v-4 by omega)]
  48. · zify [hst.le,huv.le] at *
  49. have hx : (Q:ℤ)*R = (3*v-1)*(t-1) := by
  50. linear_combination ((R:ℤ))*hQ + (3*(v:ℤ)-1)*hR
  51. rw [hx]
  52. nlinarith [mul_nonneg (show (0:ℤ) ≤ t-4 by omega) (show (0:ℤ) ≤ 6*v-8 by omega)]
  53. private lemma sigma_prime_local {p : ℕ} (hp : p.Prime) :
  54. ArithmeticFunction.sigma 1 p = p+1 := by
  55. have hh := ArithmeticFunction.sigma_one_apply_prime_pow (i := 1) hp
  56. simpa [Finset.sum_range_succ, add_comm] using hh
  57. private lemma shifted_products_eq {P Q R T : ℕ} (hP : P.Prime) (hQ : Q.Prime)
  58. (hR : R.Prime) (hT : T.Prime) (hPT : P<T) (hQR : Q<R)
  59. (he : ArithmeticFunction.sigma 1 (P*T) = ArithmeticFunction.sigma 1 (Q*R)) :
  60. (P+1)*(T+1)=(Q+1)*(R+1) := by
  61. simpa only [ArithmeticFunction.isMultiplicative_sigma.map_mul_of_coprime
  62. ((Nat.coprime_primes hP hT).mpr hPT.ne),
  63. ArithmeticFunction.isMultiplicative_sigma.map_mul_of_coprime ((Nat.coprime_primes hQ hR).mpr hQR.ne),
  64. sigma_prime_local hP, sigma_prime_local hQ, sigma_prime_local hR, sigma_prime_local hT] using he
  65. /-- For four sorted primes giving equal divisor sums, an odd gap constrains the
  66. larger member by a linear function of that gap alone. -/
  67. theorem semiprime_odd_gap_bound {P Q R T : ℕ} (hP : P.Prime) (hQ : Q.Prime)
  68. (hR : R.Prime) (hT : T.Prime) (hPQ : P<Q) (hQR : Q<R) (hRT : R<T)
  69. (he : ArithmeticFunction.sigma 1 (P*T) = ArithmeticFunction.sigma 1 (Q*R))
  70. (hodd : (Q*R-P*T)%2=1) : Q*R ≤ 9*(Q*R-P*T)+6 := by
  71. have h2 := hP.two_le
  72. have hp2 : P=2 := by
  73. by_contra hn
  74. have hoP := hP.eq_two_or_odd.resolve_left hn
  75. have hoQ := hQ.eq_two_or_odd.resolve_left (by omega)
  76. have hoR := hR.eq_two_or_odd.resolve_left (by omega)
  77. have hoT := hT.eq_two_or_odd.resolve_left (by omega)
  78. have ma : (P*T)%2=1 := by rw [Nat.mul_mod,hoP,hoT]
  79. have mb : (Q*R)%2=1 := by rw [Nat.mul_mod,hoQ,hoR]
  80. omega
  81. have hmul := shifted_products_eq hP hQ hR hT (by omega) hQR he
  82. obtain ⟨s,t,u,v,hs,hu,hst,huv,_,hA,hB,hC,hD⟩ :=
  83. rectangle_parameters (by omega : 0<P+1) (by omega : P+1<Q+1) (by omega : P+1<R+1) hmul
  84. have hgap := rectangle_gap hst.le huv.le hA hB hC hD
  85. have hgap' : Q*R-P*T=(t-s)*(v-u) := by omega
  86. rw [hgap']
  87. exact rectangle_two_bound hs hu hst huv (by omega) hB hC
  88. /-- The only consecutive equal-sigma pair of distinct squarefree semiprimes
  89. in the sorted four-prime parametrization is (14,15). -/
  90. theorem semiprime_gap_one {P Q R T : ℕ} (hP : P.Prime) (hQ : Q.Prime)
  91. (hR : R.Prime) (hT : T.Prime) (hPQ : P<Q) (hQR : Q<R) (hRT : R<T)
  92. (he : ArithmeticFunction.sigma 1 (P*T) = ArithmeticFunction.sigma 1 (Q*R))
  93. (hgap : Q*R-P*T=1) : P*T=14 ∧ Q*R=15 := by
  94. have hb := semiprime_odd_gap_bound hP hQ hR hT hPQ hQR hRT he (by simp [hgap])
  95. rw [hgap] at hb
  96. have hp2 := hP.two_le
  97. have hr5 : 5 ≤ R := by
  98. by_contra! h
  99. obtain hr : R=4 := by omega
  100. subst R
  101. exact (by decide : ¬ Nat.Prime 4) hR
  102. have hlow := Nat.mul_le_mul (by omega : 3≤Q) hr5
  103. omega
  104. /-- The order of the four factors is forced by the order of the two products. -/
  105. theorem semiprime_factor_order {p q r t : ℕ} (hp : p.Prime) (hq : q.Prime)
  106. (hr : r.Prime) (ht : t.Prime) (hpq : p<q) (hrt : r<t) (hab : p*q<r*t)
  107. (he : ArithmeticFunction.sigma 1 (p*q) = ArithmeticFunction.sigma 1 (r*t)) :
  108. p<r ∧ t<q := by
  109. have hm := shifted_products_eq hp hr ht hq hpq hrt he
  110. zify at hpq hrt hab hm ⊢
  111. have hid : (r*t-p*q)*(r+1 : ℤ) = (r-p)*(q-r) := by
  112. linear_combination -(r:ℤ)*hm
  113. have hpr : (p:ℤ)<r := by
  114. by_contra! h
  115. have := mul_nonpos_of_nonpos_of_nonneg (sub_nonpos.mpr h) (show (0:ℤ) ≤ q-r by omega)
  116. have hpos := mul_pos (sub_pos.mpr hab) (show (0:ℤ) < r+1 by positivity)
  117. linarith
  118. refine ⟨hpr,?_⟩
  119. by_contra! h
  120. nlinarith [mul_pos (sub_pos.mpr hpr) (show (0:ℤ)<q+1 by positivity),
  121. mul_nonneg (show (0:ℤ)≤r+1 by positivity) (sub_nonneg.mpr h)]
  122. /-- A squarefree semiprime has precisely two distinct prime factors. -/
  123. def ProductOfTwoDistinctPrimes (a : ℕ) : Prop :=
  124. ∃ p q : ℕ, p.Prime ∧ q.Prime ∧ p < q ∧ a=p*q
  125. theorem odd_gap_bound_of_semiprimes {a b : ℕ} (ha : ProductOfTwoDistinctPrimes a)
  126. (hb : ProductOfTwoDistinctPrimes b) (hab : a<b)
  127. (he : ArithmeticFunction.sigma 1 a = ArithmeticFunction.sigma 1 b)
  128. (ho : (b-a)%2=1) : b≤9*(b-a)+6 := by
  129. obtain ⟨p,q,hp,hq,hpq,rfl⟩ := ha
  130. obtain ⟨r,t,hr,ht,hrt,rfl⟩ := hb
  131. obtain ⟨hpr,htq⟩ := semiprime_factor_order hp hq hr ht hpq hrt hab he
  132. exact semiprime_odd_gap_bound hp hr ht hq hpr hrt htq he ho
  133. theorem unique_consecutive_semiprimes {a b : ℕ} (ha : ProductOfTwoDistinctPrimes a)
  134. (hb : ProductOfTwoDistinctPrimes b) (he : ArithmeticFunction.sigma 1 a = ArithmeticFunction.sigma 1 b)
  135. (hg : b=a+1) : a=14 ∧ b=15 := by
  136. obtain ⟨p,q,hp,hq,hpq,rfl⟩ := ha
  137. obtain ⟨r,t,hr,ht,hrt,rfl⟩ := hb
  138. obtain ⟨hpr,htq⟩ := semiprime_factor_order hp hq hr ht hpq hrt (by omega) he
  139. exact semiprime_gap_one hp hr ht hq hpr hrt htq he (by omega)
  140. /-- The gap and the smaller corner control the number of possible pairs. -/
  141. theorem semiprime_counting_parameters {a b : ℕ} (ha : ProductOfTwoDistinctPrimes a)
  142. (hb : ProductOfTwoDistinctPrimes b) (hab : a<b)
  143. (he : ArithmeticFunction.sigma 1 a = ArithmeticFunction.sigma 1 b) :
  144. ∃ s u d e : ℕ, 0<s ∧ 0<u ∧ 0<d ∧ 0<e ∧ d*e=b-a ∧ (s*u-1)^2≤a ∧
  145. a=(s*u-1)*((s+d)*(u+e)-1) ∧ b=(s*(u+e)-1)*((s+d)*u-1) := by
  146. obtain ⟨P,T,hP,hT,hPT,rfl⟩ := ha
  147. obtain ⟨Q,R,hQ,hR,hQR,rfl⟩ := hb
  148. obtain ⟨hPQ,hRT⟩ := semiprime_factor_order hP hT hQ hR hPT hQR hab he
  149. have hm := shifted_products_eq hP hQ hR hT hPT hQR he
  150. obtain ⟨s,t,u,v,hs,hu,hst,huv,_,hA,hB,hC,hD⟩ :=
  151. rectangle_parameters (by omega : 0<P+1) (by omega : P+1<Q+1) (by omega : P+1<R+1) hm
  152. have hg := rectangle_gap hst.le huv.le hA hB hC hD
  153. have ht : s+(t-s)=t := by omega
  154. have hv : u+(v-u)=v := by omega
  155. refine ⟨s,u,t-s,v-u,hs,hu,by omega,by omega,by omega,?_,?_,?_⟩
  156. · rw [← hA]
  157. simpa [pow_two] using Nat.mul_le_mul_left P hPT.le
  158. · simp [ht,hv,←hA,←hD]
  159. · simp [ht,hv,←hB,←hC]
  160. /-- Iterating the finite collision bound counts four-cycles from row degrees
  161. and the matching column-pair codegrees. -/
  162. theorem two_stage_collision_bound {ι κ : Type*} (S : Finset ι) (V : Finset κ)
  163. (d : ι → ℕ) (c : κ → ℕ)
  164. (hd : 2*(S.card:ℝ) ≤ ∑ i ∈ S, (d i:ℝ)) (hc : 2*(V.card:ℝ) ≤ ∑ j ∈ V, (c j:ℝ))
  165. (hdouble : (∑ i ∈ S, (d i:ℝ)*((d i:ℝ)-1)/2) = ∑ j ∈ V, (c j:ℝ)) :
  166. (∑ i ∈ S, (d i:ℝ))^4 ≤ 64*(S.card:ℝ)^2*V.card*
  167. (∑ j ∈ V, (c j:ℝ)*((c j:ℝ)-1)/2) := by
  168. have h1 := row_collision_bound S d hd
  169. rw [hdouble] at h1
  170. have h2 := row_collision_bound V c hc
  171. calc
  172. (∑ i ∈ S, (d i:ℝ))^4 = ((∑ i ∈ S, (d i:ℝ))^2)^2 := by ring
  173. _ ≤ (4*(S.card:ℝ)*(∑ j ∈ V, (c j:ℝ)))^2 := by
  174. exact pow_le_pow_left₀ (by positivity) h1 2
  175. _ = (16*(S.card:ℝ)^2)*(∑ j ∈ V, (c j:ℝ))^2 := by ring
  176. _ ≤ _ := by
  177. convert mul_le_mul_of_nonneg_left h2 (by positivity : 0≤16*(S.card:ℝ)^2) using 1 <;> ring
  178. #print axioms rectangle_parameters
  179. #print axioms rectangle_gap
  180. #print axioms rectangle_two_bound
  181. #print axioms semiprime_odd_gap_bound
  182. #print axioms semiprime_gap_one
  183. #print axioms semiprime_factor_order
  184. #print axioms odd_gap_bound_of_semiprimes
  185. #print axioms unique_consecutive_semiprimes
  186. #print axioms semiprime_counting_parameters
  187. #print axioms two_stage_collision_bound
  188. end Erdos824Primitive