Lean / Reader
Lean readerErdos824Semiprime.lean
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.
import Erdos824Primitiveimport Mathlib.Algebra.Order.Chebyshevnamespace Erdos824Primitiveopen ArithmeticFunctionprivate lemma sigma_prime {p : ℕ} (hp : p.Prime) : sigma 1 p = p+1 := byhave hh := sigma_one_apply_prime_pow (i := 1) hpsimpa [Finset.sum_range_succ, add_comm] using hhprivate lemma proper_divisor_semiprime {u p q : ℕ} (hp : p.Prime) (hq : q.Prime)(hu : 1 < u) (hlt : u < p*q) (hdiv : u ∣ p*q) : u = p ∨ u = q := byobtain ⟨x,y,hx,hy,rfl⟩ := exists_dvd_and_dvd_of_dvd_mul hdivrcases (Nat.dvd_prime hp).mp hx with rfl | rfl <;>rcases (Nat.dvd_prime hq).mp hy with rfl | rfl <;> simp_all/-- Two hits in one row of the shifted-prime construction give an unorderedprimitive pair of squarefree semiprimes. Here p+1=(q+1)n and t+1=(r+1)n. -/theorem semiprime_construction {q r p t n : ℕ} (hq : q.Prime) (hr : r.Prime)(hp : p.Prime) (ht : t.Prime) (hqr : q < r) (hrp : r < p) (hpt : p < t)(hn : 1 < n) (hpv : p+1=(q+1)*n) (htv : t+1=(r+1)*n) :q*t < r*p ∧ Primitive (q*t,r*p) ∧ Squarefree (q*t) ∧ Squarefree (r*p) := byhave hqt := (Nat.coprime_primes hq ht).mpr (show q ≠ t by omega)have hrp' := (Nat.coprime_primes hr hp).mpr hrp.nehave hcop : (q*t).Coprime (r*p) := byexact ((Nat.coprime_primes hq hr).mpr hqr.ne).mul_right((Nat.coprime_primes hq hp).mpr (show q ≠ p by omega)) |>.mul_left(((Nat.coprime_primes ht hr).mpr (show t ≠ r by omega)).mul_right((Nat.coprime_primes ht hp).mpr hpt.ne'))have hsig : sigma 1 (q*t) = sigma 1 (r*p) := byrw [isMultiplicative_sigma.map_mul_of_coprime hqt, isMultiplicative_sigma.map_mul_of_coprime hrp',sigma_prime hq, sigma_prime ht, sigma_prime hr, sigma_prime hp, htv, hpv]ringhave hlt : q*t < r*p := byzify at hpv htv hqr hn ⊢nlinarith [mul_pos (sub_pos.mpr hqr) (sub_pos.mpr hn),congrArg (fun z : ℤ ↦ (q : ℤ)*z) htv, congrArg (fun z : ℤ ↦ (r : ℤ)*z) hpv]refine ⟨hlt, ⟨⟨by have := hq.one_lt; have := ht.one_lt; nlinarith,by have := hr.one_lt; have := hp.one_lt; nlinarith,hcop,hsig⟩,?_⟩,(Nat.squarefree_mul hqt).mpr ⟨hq.squarefree,ht.squarefree⟩,(Nat.squarefree_mul hrp').mpr ⟨hr.squarefree,hp.squarefree⟩⟩intro hsplitobtain ⟨u,v,hu,hua,hud,hv,hvb,hvd,_,_,he⟩ := (splits_iff_unitary_divisors _ _).mp hsplithave huv := proper_divisor_semiprime hq ht hu hua hudhave hvv := proper_divisor_semiprime hr hp hv hvb hvdrcases huv with rfl | rfl <;> rcases hvv with rfl | rfl <;>simp only [sigma_prime hq, sigma_prime hr, sigma_prime hp, sigma_prime ht] at he <;> omega/-- The gap has one fewer large prime factor than either constructed number. -/theorem semiprime_gap {q r p t n : ℕ} (hqr : q ≤ r) (hn : 1 ≤ n)(hpv : p+1=(q+1)*n) (htv : t+1=(r+1)*n) :r*p-q*t = (r-q)*(n-1) := byhave he : r*p = q*t + (r-q)*(n-1) := byzify [hqr,hn] at hpv htv ⊢nlinarith [congrArg (fun z : ℤ ↦ (q : ℤ)*z) htv, congrArg (fun z : ℤ ↦ (r : ℤ)*z) hpv]omega/-- Cauchy--Schwarz supplies many unordered collisions as soon as the meanincidence degree is at least two. Degrees are viewed in the reals. -/theorem row_collision_bound {ι : Type*} (S : Finset ι) (d : ι → ℕ)(hmean : 2*(S.card : ℝ) ≤ ∑ i ∈ S, (d i : ℝ)) :(∑ i ∈ S, (d i : ℝ))^2 ≤4*(S.card : ℝ) * (∑ i ∈ S, (d i : ℝ)*((d i : ℝ)-1)/2) := byhave hcs := sq_sum_le_card_mul_sum_sq (s := S) (f := fun i ↦ (d i : ℝ))have hid : (∑ i ∈ S, (d i : ℝ)^2) =2*(∑ i ∈ S, (d i : ℝ)*((d i : ℝ)-1)/2) + ∑ i ∈ S, (d i : ℝ) := byrw [Finset.mul_sum, ← Finset.sum_add_distrib]apply Finset.sum_congr rflintro i _; ringrw [hid] at hcshave hnon : 0 ≤ ∑ i ∈ S, (d i : ℝ) := by positivitynlinarith [mul_le_mul_of_nonneg_right hmean hnon]private lemma ordered_factors_unique {a b c d : ℕ} (ha : a.Prime) (hb : b.Prime)(hc : c.Prime) (hd : d.Prime) (hab : a < b) (hcd : c < d) (he : a*b = c*d) :a = c ∧ b = d := byhave ha' : a ∣ c*d := he ▸ dvd_mul_right a bhave hc' : c ∣ a*b := he.symm ▸ dvd_mul_right c dhave hac : a = c := byrcases ha.dvd_mul.mp ha' with hh | hh· exact (Nat.prime_dvd_prime_iff_eq ha hc).mp hh· have had := (Nat.prime_dvd_prime_iff_eq ha hd).mp hhrcases hc.dvd_mul.mp hc' with hh | hh· exact ((Nat.prime_dvd_prime_iff_eq hc ha).mp hh).symm· have := (Nat.prime_dvd_prime_iff_eq hc hb).mp hhomegasubst cexact ⟨rfl, Nat.eq_of_mul_eq_mul_left ha.pos he⟩/-- Sorted output products recover the small primes and the original row. -/theorem semiprime_parameters_unique {q r p t n q' r' p' t' n' : ℕ}(hq : q.Prime) (hr : r.Prime) (hp : p.Prime) (ht : t.Prime)(hq' : q'.Prime) (hr' : r'.Prime) (hp' : p'.Prime) (ht' : t'.Prime)(hqt : q < t) (hrp : r < p) (hqt' : q' < t') (hrp' : r' < p')(htv : t+1=(r+1)*n) (htv' : t'+1=(r'+1)*n')(ha : q*t=q'*t') (hb : r*p=r'*p') : q=q' ∧ r=r' ∧ n=n' := byobtain ⟨rfl,rfl⟩ := ordered_factors_unique hq ht hq' ht' hqt hqt' haobtain ⟨rfl,rfl⟩ := ordered_factors_unique hr hp hr' hp' hrp hrp' hbexact ⟨rfl,rfl,Nat.eq_of_mul_eq_mul_left (by omega) (htv.symm.trans htv')⟩#print axioms semiprime_construction#print axioms semiprime_gap#print axioms semiprime_parameters_unique#print axioms row_collision_boundend Erdos824Primitive