Lean / Reader
Lean readerErdos824Rectangle.lean
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.
import Erdos824Semiprimenamespace Erdos824Primitive/-- Every positive integral rank-one rectangle has a primitive first row.Strict increase from its top left gives strictly increasing parameters. -/theorem rectangle_parameters {A B C D : ℕ} (hA : 0 < A) (hAB : A < B) (hAC : A < C)(he : A*D = B*C) : ∃ s t u v : ℕ, 0 < s ∧ 0 < u ∧ s<t ∧ u<v ∧u.Coprime v ∧ A=s*u ∧ B=s*v ∧ C=t*u ∧ D=t*v := bylet s := A.gcd Blet u := A / slet v := B / shave hs : 0 < s := Nat.gcd_pos_of_pos_left B hAhave ha : s*u=A := by simpa [s,u,Nat.mul_comm] using Nat.div_mul_cancel (Nat.gcd_dvd_left A B)have hb : s*v=B := by simpa [s,v,Nat.mul_comm] using Nat.div_mul_cancel (Nat.gcd_dvd_right A B)have hu : 0 < u := byapply Nat.pos_of_ne_zerointro hzrw [hz,Nat.mul_zero] at haexact (Nat.ne_of_gt hA) ha.symmhave huv : u.Coprime v := Nat.coprime_div_gcd_div_gcd hshave hcancel : u*D=v*C := Nat.eq_of_mul_eq_mul_left hs (by simpa only [← Nat.mul_assoc, ha, hb] using he)have hdiv : u ∣ C := huv.dvd_of_dvd_mul_left (hcancel ▸ dvd_mul_right u D)obtain ⟨t,ht⟩ := hdivhave hD : D=t*v := Nat.eq_of_mul_eq_mul_left hu (by rw [hcancel,ht]; ring)refine ⟨s,t,u,v,hs,hu,?_,?_,huv,ha.symm,hb.symm,by simpa [Nat.mul_comm] using ht,hD⟩· apply Nat.lt_of_mul_lt_mul_left (a := u)simpa only [Nat.mul_comm u s,ha,←ht] using hAC· exact Nat.lt_of_mul_lt_mul_left (ha ▸ hb ▸ hAB)/-- The gap in the ordered products of four shifted primes is the productof adjacent row and column differences. -/theorem rectangle_gap {s t u v P Q R T : ℕ} (hst : s ≤ t) (huv : u ≤ v)(hP : P+1=s*u) (hQ : Q+1=s*v) (hR : R+1=t*u) (hT : T+1=t*v) :Q*R=P*T+(t-s)*(v-u) := byzify [hst,huv] at *linear_combination ((t:ℤ)*u-1)*hQ + (Q:ℤ)*hR - ((t:ℤ)*v-1)*hP - (P:ℤ)*hT/-- The factor 2 at the smallest corner forces an upper bound purely interms of the gap. This applies to every odd gap between squarefree semiprimes. -/theorem rectangle_two_bound {s t u v Q R : ℕ} (hs : 0<s) (hu : 0<u)(hst : s<t) (huv : u<v) (hcorner : s*u=3) (hQ : Q+1=s*v) (hR : R+1=t*u) :Q*R ≤ 9*((t-s)*(v-u))+6 := byhave hds := (Nat.dvd_prime Nat.prime_three).mp (hcorner ▸ dvd_mul_right s u)have hdu := (Nat.dvd_prime Nat.prime_three).mp (hcorner ▸ dvd_mul_left u s)rcases hds with rfl | rfl <;> rcases hdu with rfl | rfl <;> norm_num at hcorner· zify [hst.le,huv.le] at *have hx : (Q:ℤ)*R = (v-1)*(3*t-1) := bylinear_combination ((R:ℤ))*hQ + ((v:ℤ)-1)*hRrw [hx]nlinarith [mul_nonneg (show (0:ℤ) ≤ 6*t-8 by omega) (show (0:ℤ) ≤ v-4 by omega)]· zify [hst.le,huv.le] at *have hx : (Q:ℤ)*R = (3*v-1)*(t-1) := bylinear_combination ((R:ℤ))*hQ + (3*(v:ℤ)-1)*hRrw [hx]nlinarith [mul_nonneg (show (0:ℤ) ≤ t-4 by omega) (show (0:ℤ) ≤ 6*v-8 by omega)]private lemma sigma_prime_local {p : ℕ} (hp : p.Prime) :ArithmeticFunction.sigma 1 p = p+1 := byhave hh := ArithmeticFunction.sigma_one_apply_prime_pow (i := 1) hpsimpa [Finset.sum_range_succ, add_comm] using hhprivate lemma shifted_products_eq {P Q R T : ℕ} (hP : P.Prime) (hQ : Q.Prime)(hR : R.Prime) (hT : T.Prime) (hPT : P<T) (hQR : Q<R)(he : ArithmeticFunction.sigma 1 (P*T) = ArithmeticFunction.sigma 1 (Q*R)) :(P+1)*(T+1)=(Q+1)*(R+1) := bysimpa only [ArithmeticFunction.isMultiplicative_sigma.map_mul_of_coprime((Nat.coprime_primes hP hT).mpr hPT.ne),ArithmeticFunction.isMultiplicative_sigma.map_mul_of_coprime ((Nat.coprime_primes hQ hR).mpr hQR.ne),sigma_prime_local hP, sigma_prime_local hQ, sigma_prime_local hR, sigma_prime_local hT] using he/-- For four sorted primes giving equal divisor sums, an odd gap constrains thelarger member by a linear function of that gap alone. -/theorem semiprime_odd_gap_bound {P Q R T : ℕ} (hP : P.Prime) (hQ : Q.Prime)(hR : R.Prime) (hT : T.Prime) (hPQ : P<Q) (hQR : Q<R) (hRT : R<T)(he : ArithmeticFunction.sigma 1 (P*T) = ArithmeticFunction.sigma 1 (Q*R))(hodd : (Q*R-P*T)%2=1) : Q*R ≤ 9*(Q*R-P*T)+6 := byhave h2 := hP.two_lehave hp2 : P=2 := byby_contra hnhave hoP := hP.eq_two_or_odd.resolve_left hnhave hoQ := hQ.eq_two_or_odd.resolve_left (by omega)have hoR := hR.eq_two_or_odd.resolve_left (by omega)have hoT := hT.eq_two_or_odd.resolve_left (by omega)have ma : (P*T)%2=1 := by rw [Nat.mul_mod,hoP,hoT]have mb : (Q*R)%2=1 := by rw [Nat.mul_mod,hoQ,hoR]omegahave hmul := shifted_products_eq hP hQ hR hT (by omega) hQR heobtain ⟨s,t,u,v,hs,hu,hst,huv,_,hA,hB,hC,hD⟩ :=rectangle_parameters (by omega : 0<P+1) (by omega : P+1<Q+1) (by omega : P+1<R+1) hmulhave hgap := rectangle_gap hst.le huv.le hA hB hC hDhave hgap' : Q*R-P*T=(t-s)*(v-u) := by omegarw [hgap']exact rectangle_two_bound hs hu hst huv (by omega) hB hC/-- The only consecutive equal-sigma pair of distinct squarefree semiprimesin the sorted four-prime parametrization is (14,15). -/theorem semiprime_gap_one {P Q R T : ℕ} (hP : P.Prime) (hQ : Q.Prime)(hR : R.Prime) (hT : T.Prime) (hPQ : P<Q) (hQR : Q<R) (hRT : R<T)(he : ArithmeticFunction.sigma 1 (P*T) = ArithmeticFunction.sigma 1 (Q*R))(hgap : Q*R-P*T=1) : P*T=14 ∧ Q*R=15 := byhave hb := semiprime_odd_gap_bound hP hQ hR hT hPQ hQR hRT he (by simp [hgap])rw [hgap] at hbhave hp2 := hP.two_lehave hr5 : 5 ≤ R := byby_contra! hobtain hr : R=4 := by omegasubst Rexact (by decide : ¬ Nat.Prime 4) hRhave hlow := Nat.mul_le_mul (by omega : 3≤Q) hr5omega/-- The order of the four factors is forced by the order of the two products. -/theorem semiprime_factor_order {p q r t : ℕ} (hp : p.Prime) (hq : q.Prime)(hr : r.Prime) (ht : t.Prime) (hpq : p<q) (hrt : r<t) (hab : p*q<r*t)(he : ArithmeticFunction.sigma 1 (p*q) = ArithmeticFunction.sigma 1 (r*t)) :p<r ∧ t<q := byhave hm := shifted_products_eq hp hr ht hq hpq hrt hezify at hpq hrt hab hm ⊢have hid : (r*t-p*q)*(r+1 : ℤ) = (r-p)*(q-r) := bylinear_combination -(r:ℤ)*hmhave hpr : (p:ℤ)<r := byby_contra! hhave := mul_nonpos_of_nonpos_of_nonneg (sub_nonpos.mpr h) (show (0:ℤ) ≤ q-r by omega)have hpos := mul_pos (sub_pos.mpr hab) (show (0:ℤ) < r+1 by positivity)linarithrefine ⟨hpr,?_⟩by_contra! hnlinarith [mul_pos (sub_pos.mpr hpr) (show (0:ℤ)<q+1 by positivity),mul_nonneg (show (0:ℤ)≤r+1 by positivity) (sub_nonneg.mpr h)]/-- A squarefree semiprime has precisely two distinct prime factors. -/def ProductOfTwoDistinctPrimes (a : ℕ) : Prop :=∃ p q : ℕ, p.Prime ∧ q.Prime ∧ p < q ∧ a=p*qtheorem odd_gap_bound_of_semiprimes {a b : ℕ} (ha : ProductOfTwoDistinctPrimes a)(hb : ProductOfTwoDistinctPrimes b) (hab : a<b)(he : ArithmeticFunction.sigma 1 a = ArithmeticFunction.sigma 1 b)(ho : (b-a)%2=1) : b≤9*(b-a)+6 := byobtain ⟨p,q,hp,hq,hpq,rfl⟩ := haobtain ⟨r,t,hr,ht,hrt,rfl⟩ := hbobtain ⟨hpr,htq⟩ := semiprime_factor_order hp hq hr ht hpq hrt hab heexact semiprime_odd_gap_bound hp hr ht hq hpr hrt htq he hotheorem unique_consecutive_semiprimes {a b : ℕ} (ha : ProductOfTwoDistinctPrimes a)(hb : ProductOfTwoDistinctPrimes b) (he : ArithmeticFunction.sigma 1 a = ArithmeticFunction.sigma 1 b)(hg : b=a+1) : a=14 ∧ b=15 := byobtain ⟨p,q,hp,hq,hpq,rfl⟩ := haobtain ⟨r,t,hr,ht,hrt,rfl⟩ := hbobtain ⟨hpr,htq⟩ := semiprime_factor_order hp hq hr ht hpq hrt (by omega) heexact semiprime_gap_one hp hr ht hq hpr hrt htq he (by omega)/-- The gap and the smaller corner control the number of possible pairs. -/theorem semiprime_counting_parameters {a b : ℕ} (ha : ProductOfTwoDistinctPrimes a)(hb : ProductOfTwoDistinctPrimes b) (hab : a<b)(he : ArithmeticFunction.sigma 1 a = ArithmeticFunction.sigma 1 b) :∃ s u d e : ℕ, 0<s ∧ 0<u ∧ 0<d ∧ 0<e ∧ d*e=b-a ∧ (s*u-1)^2≤a ∧a=(s*u-1)*((s+d)*(u+e)-1) ∧ b=(s*(u+e)-1)*((s+d)*u-1) := byobtain ⟨P,T,hP,hT,hPT,rfl⟩ := haobtain ⟨Q,R,hQ,hR,hQR,rfl⟩ := hbobtain ⟨hPQ,hRT⟩ := semiprime_factor_order hP hT hQ hR hPT hQR hab hehave hm := shifted_products_eq hP hQ hR hT hPT hQR heobtain ⟨s,t,u,v,hs,hu,hst,huv,_,hA,hB,hC,hD⟩ :=rectangle_parameters (by omega : 0<P+1) (by omega : P+1<Q+1) (by omega : P+1<R+1) hmhave hg := rectangle_gap hst.le huv.le hA hB hC hDhave ht : s+(t-s)=t := by omegahave hv : u+(v-u)=v := by omegarefine ⟨s,u,t-s,v-u,hs,hu,by omega,by omega,by omega,?_,?_,?_⟩· rw [← hA]simpa [pow_two] using Nat.mul_le_mul_left P hPT.le· simp [ht,hv,←hA,←hD]· simp [ht,hv,←hB,←hC]/-- Iterating the finite collision bound counts four-cycles from row degreesand the matching column-pair codegrees. -/theorem two_stage_collision_bound {ι κ : Type*} (S : Finset ι) (V : Finset κ)(d : ι → ℕ) (c : κ → ℕ)(hd : 2*(S.card:ℝ) ≤ ∑ i ∈ S, (d i:ℝ)) (hc : 2*(V.card:ℝ) ≤ ∑ j ∈ V, (c j:ℝ))(hdouble : (∑ i ∈ S, (d i:ℝ)*((d i:ℝ)-1)/2) = ∑ j ∈ V, (c j:ℝ)) :(∑ i ∈ S, (d i:ℝ))^4 ≤ 64*(S.card:ℝ)^2*V.card*(∑ j ∈ V, (c j:ℝ)*((c j:ℝ)-1)/2) := byhave h1 := row_collision_bound S d hdrw [hdouble] at h1have h2 := row_collision_bound V c hccalc(∑ i ∈ S, (d i:ℝ))^4 = ((∑ i ∈ S, (d i:ℝ))^2)^2 := by ring_ ≤ (4*(S.card:ℝ)*(∑ j ∈ V, (c j:ℝ)))^2 := byexact pow_le_pow_left₀ (by positivity) h1 2_ = (16*(S.card:ℝ)^2)*(∑ j ∈ V, (c j:ℝ))^2 := by ring_ ≤ _ := byconvert mul_le_mul_of_nonneg_left h2 (by positivity : 0≤16*(S.card:ℝ)^2) using 1 <;> ring#print axioms rectangle_parameters#print axioms rectangle_gap#print axioms rectangle_two_bound#print axioms semiprime_odd_gap_bound#print axioms semiprime_gap_one#print axioms semiprime_factor_order#print axioms odd_gap_bound_of_semiprimes#print axioms unique_consecutive_semiprimes#print axioms semiprime_counting_parameters#print axioms two_stage_collision_boundend Erdos824Primitive