Lean / Reader
Lean readerPrimeSignatures.lean
Lean 4 Web has Mathlib, so it can check files that import only Mathlib. This one also imports PrimeCollisions, which it does not have: you can read it there, but it will not check. Build the project itself to check it.
import PrimeCollisionsimport Mathlib.Algebra.BigOperators.ModEqnamespace ReciprocalRecordsdef w (L d : ℕ) : ℤ := (L / d : ℕ)def scaledTotal (L : ℕ) (A : Finset ℕ) : ℤ := ∑ d ∈ A, w L d/-- Only denominators divisible by p contribute to a scaled reciprocal sum modulo p. -/theorem zero_off_multiples {L d p : ℕ} (hp : p.Prime) (hpL : p ∣ L)(hd : d ∣ L) (hpd : ¬p ∣ d) : w L d ≡ 0 [ZMOD (p : ℤ)] := byhave hh : p ∣ L / d * d := by rwa [Nat.div_mul_cancel hd]have h := (hp.dvd_mul.mp hh).resolve_right hpdapply Int.modEq_zero_iff_dvd.mprunfold wexact_mod_cast h/-- Below 3p no positive multiples other than p and 2p occur. -/theorem other_denominator {p d : ℕ} (hd : 0 < d)(hu : d < 3*p) (h1 : d ≠ p) (h2 : d ≠ 2*p) : ¬p ∣ d := byrintro ⟨k, rfl⟩have hk : k < 3 := by nlinarithinterval_cases k <;> simp_all [mul_comm]def localTotal (L p : ℕ) (A : Finset ℕ) : ℤ :=(if p ∈ A then w L p else 0) + (if 2*p ∈ A then w L (2*p) else 0)theorem local_signature {L p : ℕ} (hp : p.Prime) (hpL : p ∣ L)(A : Finset ℕ) (hA : ∀ d ∈ A, 0 < d ∧ d < 3*p ∧ d ∣ L) :scaledTotal L A ≡ localTotal L p A [ZMOD (p : ℤ)] := bylet f (d : ℕ) : ℤ := (if p = d then w L p else 0) + (if 2*p = d then w L (2*p) else 0)have he (d) (hd : d ∈ A) : w L d ≡ f d [ZMOD (p : ℤ)] := byobtain ⟨hpos, hu, hdiv⟩ := hA d hdhave hne : 2*p ≠ p := by have := hp.pos; omegaby_cases h : p = d· subst d; simp [f, hne]by_cases h' : 2*p = d· subst d; simp [f, hne.symm]simpa [f, h, h'] using zero_off_multiples hp hpL hdiv(other_denominator hpos hu (Ne.symm h) (Ne.symm h'))simpa [scaledTotal, f, localTotal, Finset.sum_add_distrib] using Int.ModEq.sum he/-- The order on labels is used when the older witnesses cannot use 2p. -/def label (p : ℕ) (A : Finset ℕ) : Fin 4 :=if 2*p ∈ A then (if p ∈ A then 3 else 2) else (if p ∈ A then 1 else 0)theorem local_of_label {p L : ℕ} {A B : Finset ℕ} (he : label p A = label p B) :localTotal L p A = localTotal L p B := byunfold label at heunfold localTotalsplit_ifs at * <;> simp_alltheorem label_binary {p : ℕ} {A : Finset ℕ} (h : 2*p ∉ A) : (label p A).val < 2 := bysimp only [label, h, if_false]split <;> decidetheorem label_zero {p : ℕ} {A : Finset ℕ} (h : p ∉ A) (h' : 2*p ∉ A) :label p A = 0 := by simp [label, h, h']theorem labelled_totals {n p L : ℕ} (hp : p.Prime) (hpL : p ∣ L)(A : Fin n → Finset ℕ) (hA : ∀ i d, d ∈ A i → 0 < d ∧ d < 3*p ∧ d ∣ L) :equalEdges (fun i => label p (A i)) ≤(taggedEdges p (fun i => scaledTotal L (A i))).card := byapply labelled_collisionsintro i j hhave hi := local_signature hp hpL (A i) (hA i)have hj := local_signature hp hpL (A j) (hA j)rw [local_of_label (L := L) h] at hiexact hi.trans hj.symmend ReciprocalRecords