Goal
Provide a complete Lean formalization (no sorry) of the standard cofactor lemmas used to bound large proper divisors:
- if , and then ;
- if , and then ;
- if , and then ;
- if , and then .
These lemmas are the exact “divisor ordering” ingredients needed to eliminate the remaining sorry in [pjkfl3] (and thus help fully formalize [2jbmwt]).
Lean file
import Mathlib.Data.Nat.Basic
import Mathlib.Tactic
namespace DivisorOrderNk
/-- Cofactor bound: if `n = d*q` and `(d*q)/k < d` with `k>0`, then `q < k`. -/
lemma cofactor_lt_of_div_lt {d q k : ℕ} (hk : 0 < k) (h : (d*q) / k < d) :
q < k := by
have hmul : d * q < d * k := by
have := (Nat.div_lt_iff_lt_mul hk).1 h
simpa [Nat.mul_assoc] using this
exact Nat.lt_of_mul_lt_mul_left hmul
/-- If `d ∣ n`, `d < n`, and `n/3 < d`, then `d = n/2`. -/
theorem eq_div_two_of_dvd_lt_of_div_three_lt {n d : ℕ}
(hd : d ∣ n) (hdlt : d < n) (h : n / 3 < d) :
d = n / 2 := by
rcases hd with ⟨q, rfl⟩
have hd0 : d ≠ 0 := by
intro hd0
subst hd0
simp at hdlt
have hq_gt1 : 1 < q := by
have : d * 1 < d * q := by
simpa [Nat.mul_one] using hdlt
exact Nat.lt_of_mul_lt_mul_left this
have hq_ge2 : 2 ≤ q := (Nat.succ_le_iff).2 hq_gt1
have hq_lt3 : q < 3 := by
have h' : (d * q) / 3 < d := by
simpa [Nat.mul_assoc] using h
exact cofactor_lt_of_div_lt (k := 3) (d := d) (q := q) (by decide) h'
have hq : q = 2 := by
have hq_le2 : q ≤ 2 := Nat.lt_succ_iff.mp (by simpa using hq_lt3)
exact le_antisymm hq_le2 hq_ge2
subst hq
simp
/-- If `d ∣ n`, `d < n`, and `n/4 < d`, then `d = n/2` or `d = n/3`. -/
theorem eq_div_two_or_three_of_dvd_lt_of_div_four_lt {n d : ℕ}
(hd : d ∣ n) (hdlt : d < n) (h : n / 4 < d) :
d = n / 2 ∨ d = n / 3 := by
rcases hd with ⟨q, rfl⟩
have hd0 : d ≠ 0 := by
intro hd0
subst hd0
simp at hdlt
have hq_gt1 : 1 < q := by
have : d * 1 < d * q := by
simpa [Nat.mul_one] using hdlt
exact Nat.lt_of_mul_lt_mul_left this
have hq_ge2 : 2 ≤ q := (Nat.succ_le_iff).2 hq_gt1
have hq_lt4 : q < 4 := by
have h' : (d * q) / 4 < d := by
simpa [Nat.mul_assoc] using h
exact cofactor_lt_of_div_lt (k := 4) (d := d) (q := q) (by decide) h'
have hq_le3 : q ≤ 3 := Nat.lt_succ_iff.mp (by simpa using hq_lt4)
have hq_cases : q = 2 ∨ q = 3 := by omega
rcases hq_cases with rfl | rfl
· left; simp
· right; simp
/-- If `d ∣ n`, `d < n`, and `n/5 < d`, then `d = n/2` or `d = n/3` or `d = n/4`. -/
theorem eq_div_two_or_three_or_four_of_dvd_lt_of_div_five_lt {n d : ℕ}
(hd : d ∣ n) (hdlt : d < n) (h : n / 5 < d) :
d = n / 2 ∨ d = n / 3 ∨ d = n / 4 := by
rcases hd with ⟨q, rfl⟩
have hd0 : d ≠ 0 := by
intro hd0
subst hd0
simp at hdlt
have hq_gt1 : 1 < q := by
have : d * 1 < d * q := by
simpa [Nat.mul_one] using hdlt
exact Nat.lt_of_mul_lt_mul_left this
have hq_ge2 : 2 ≤ q := (Nat.succ_le_iff).2 hq_gt1
have hq_lt5 : q < 5 := by
have h' : (d * q) / 5 < d := by
simpa [Nat.mul_assoc] using h
exact cofactor_lt_of_div_lt (k := 5) (d := d) (q := q) (by decide) h'
have hq_le4 : q ≤ 4 := Nat.lt_succ_iff.mp (by simpa using hq_lt5)
have hq_cases : q = 2 ∨ q = 3 ∨ q = 4 := by omega
rcases hq_cases with rfl | rfl | rfl
· left; simp
· right; left; simp
· right; right; simp
/-- If `d ∣ n`, `d < n`, and `n/6 < d`, then `d = n/2` or `d = n/3` or `d = n/4` or `d = n/5`. -/
theorem eq_div_two_or_three_or_four_or_five_of_dvd_lt_of_div_six_lt {n d : ℕ}
(hd : d ∣ n) (hdlt : d < n) (h : n / 6 < d) :
d = n / 2 ∨ d = n / 3 ∨ d = n / 4 ∨ d = n / 5 := by
rcases hd with ⟨q, rfl⟩
have hd0 : d ≠ 0 := by
intro hd0
subst hd0
simp at hdlt
have hq_gt1 : 1 < q := by
have : d * 1 < d * q := by
simpa [Nat.mul_one] using hdlt
exact Nat.lt_of_mul_lt_mul_left this
have hq_ge2 : 2 ≤ q := (Nat.succ_le_iff).2 hq_gt1
have hq_lt6 : q < 6 := by
have h' : (d * q) / 6 < d := by
simpa [Nat.mul_assoc] using h
exact cofactor_lt_of_div_lt (k := 6) (d := d) (q := q) (by decide) h'
have hq_le5 : q ≤ 5 := Nat.lt_succ_iff.mp (by simpa using hq_lt6)
have hq_cases : q = 2 ∨ q = 3 ∨ q = 4 ∨ q = 5 := by omega
rcases hq_cases with rfl | rfl | rfl | rfl
· left; simp
· right; left; simp
· right; right; left; simp
· right; right; right; simp
end DivisorOrderNk
Compilation output
$ cd /opt/lean/Math
$ lake env lean DivisorOrderNk.lean
# success (only minor linter warnings possible)
Commentary
- The proofs are uniform and short.
- The key helper is
Nat.div_lt_iff_lt_mulplus cancellation viaNat.lt_of_mul_lt_mul_left. omegais used only to turn bounds like2 ≤ qandq ≤ 4into the finite disjunctionq=2 ∨ q=3 ∨ ....