Lean / Reader
Lean readerErdos311Lower.lean
Lean 4 Web has Mathlib, so it can check files that import only Mathlib. This one also imports Erdos311Residues, which it does not have: you can read it there, but it will not check. Build the project itself to check it.
import Erdos311Residuesopen Finsetnamespace Erdos311Lowerdef scale : ℕ := 337293588832926264639465766794841407432394382785157234228847021917234018060677390066992000def pivots : List ℕ := [199,197,193,191,181,179,173,167,163,157,151,149,139,137,131,127]def modulus : ℕ := 246754462477588902008901238171675219def gap : ℕ := 1507565388862991484001615748834/-- The projections of all subset sums of a list, without constructing its powerset. -/def residues (L q : ℕ) : List ℕ → List ℕ| [] => [0]| n :: ns => let old := residues L q nsold ++ old.map (fun a => (a + L/n) % q)theorem residue_mem (L q : ℕ) (ns : List ℕ) (A : Finset ℕ) (h : A ⊆ ns.toFinset) :(∑ j ∈ A, L/j)%q ∈ residues L q ns := byinduction ns generalizing A with| nil => have ha : A=∅ := Finset.subset_empty.mp (by simpa using h)simp [ha,residues]| cons n ns ih =>by_cases hn : n ∈ A· have hrest : A.erase n ⊆ ns.toFinset := byintro j hjobtain ⟨hne,hjA⟩ := Finset.mem_erase.mp hjsimpa [hne] using h hjAhave hm := ih (A.erase n) hrestapply List.mem_append.mpr (Or.inr (List.mem_map.mpr ⟨_,hm,?_⟩))rw [Nat.mod_add_mod, Finset.sum_erase_add _ _ hn]· have hrest : A ⊆ ns.toFinset := byintro j hjhave hne : j ≠ n := fun he => hn (he ▸ hj)simpa [hne] using h hjexact List.mem_append.mpr (Or.inl (ih A hrest))set_option maxHeartbeats 0set_option maxRecDepth 200000theorem scale_eq : Erdos311Residues.commonDen 200 = scale := by decide +kerneltheorem invisible : ∀ j ∈ Finset.Icc 1 200, j ∉ pivots.toFinset → modulus ∣ scale/j := by decide +kerneltheorem computed : (residues scale modulus pivots).all (fun r => decide (r=0 ∨ gap ≤ r ∧ r+gap ≤ modulus)) = true := by decide +kerneltheorem residue_bound (A : Finset ℕ) (hA : A ⊆ Finset.Icc 1 200) :let r := (∑ j ∈ A, scale/j) % modulusr=0 ∨ gap ≤ r ∧ r+gap ≤ modulus := bylet B := pivots.toFinsethave he : (∑ j ∈ A, scale/j) % modulus = (∑ j ∈ A ∩ B,scale/j) % modulus := byapply (ZMod.natCast_eq_natCast_iff' ..).mprw [Nat.cast_sum,Nat.cast_sum]exact Erdos311Residues.filter_sum A B _ (fun j hj hB => (ZMod.natCast_eq_zero_iff ..).mpr (invisible j (hA hj) hB))dsimp onlyrw [he]exact of_decide_eq_true (List.all_eq_true.mp computed _ (residue_mem scale modulus pivots _ Finset.inter_subset_right))/-- A gap on both sides of zero in the residue circle yields a gap about a multiple of q. -/theorem dist_bound {q b u L : ℕ} (hL : q ∣ L) (hb : b ≤ q)(hne : u ≠ L) (h : u%q=0 ∨ b ≤ u%q ∧ u%q+b ≤ q) :b ≤ u-L ∨ b ≤ L-u := byhave hzero := Nat.mod_eq_zero_of_dvd hLby_cases hu : L ≤ u· lefthave he : (u-L)%q = u%q := bycalc (u-L)%q = (L+(u-L))%q := by rw [Nat.add_mod,hzero,Nat.zero_add,Nat.mod_mod]_ = u%q := by rw [Nat.add_sub_of_le hu]rcases h with hr | hr· have hd : q ∣ u-L := Nat.dvd_of_mod_eq_zero (he.trans hr)exact hb.trans (Nat.le_of_dvd (by omega) hd)· exact hr.1.trans (he ▸ Nat.mod_le _ _)· righthave he : (u%q+(L-u))%q=0 := by rw [Nat.mod_add_mod,Nat.add_sub_of_le (by omega : u≤L),hzero]have hp : q ≤ u%q+(L-u) := Nat.le_of_dvd (by omega) (Nat.dvd_of_mod_eq_zero he)omegatheorem rational_dist {a L u : ℕ} {z : ℚ} (ha : 0 < a) (hL : (0 : ℚ) < L)(he : (u : ℚ) = (L : ℚ)*z) (h : a ≤ u-L ∨ a ≤ L-u) :(a : ℚ)/L ≤ |z-1| := byapply (div_le_iff₀ hL).mprrw [← abs_of_pos hL, ← abs_mul, sub_mul, mul_comm z, ← he, one_mul]rcases h with h | h· have hs : L ≤ u := by omegahave hh : (a : ℚ) ≤ (u : ℚ)-L := byexact_mod_cast (show (a : ℤ) ≤ (u : ℤ)-L by omega)exact hh.trans (le_abs_self _)· have hs : u ≤ L := by omegahave hh : (a : ℚ) ≤ (L : ℚ)-u := byexact_mod_cast (show (a : ℤ) ≤ (L : ℤ)-u by omega)rw [abs_sub_comm]exact hh.trans (le_abs_self _)theorem lower_200 (A : Finset ℕ) (hA : A ⊆ Icc 1 200) (hne : (∑ j ∈ A, (j : ℚ)⁻¹) ≠ 1) :(gap : ℚ)/scale ≤ |(∑ j ∈ A, (j : ℚ)⁻¹)-1| := bylet u := ∑ j ∈ A, scale/jlet z := ∑ j ∈ A, (j : ℚ)⁻¹have he : (u : ℚ) = (scale : ℚ)*z := by simpa [u,z,scale_eq] using Erdos311Residues.weight_sum_eq 200 A hAhave hpos : (0 : ℚ) < scale := by norm_num [scale]have huv : u ≠ scale := byintro hurw [hu] at heapply hnechange z=1nlinarithexact rational_dist (by decide +kernel : 0 < gap) hpos he(dist_bound (q:=modulus) (by decide +kernel : modulus ∣ scale)(by decide +kernel : gap ≤ modulus) huv (residue_bound A hA))#print axioms computed#print axioms lower_200end Erdos311Lower