Result
Let $n\in
\mathbb{N}$ be even and . Then the largest proper divisor of equals .
This lemma is a useful building block for problems where one iterates a function depending on the largest proper divisors (e.g. sums of the three largest proper divisors).
Lean4 / mathlib formalization
Statement
/-- For an even natural number `n>1`, the largest proper divisor is `n/2`. -/
theorem max'_properDivisors_eq_div_two {n : ℕ} (hn2 : 2 ∣ n) (hn1 : 1 < n) :
(n.properDivisors).max' (by
simpa [Nat.nonempty_properDivisors] using hn1) = n / 2 := by
...
Proof idea
Using Finset.max'_eq_iff, it suffices to show:
- ;
- for any proper divisor we have .
For (2), if is a proper divisor then for some , hence , so , and by Nat.le_div_iff_mul_le we obtain .
Complete file
import Mathlib.NumberTheory.Divisors
import Mathlib.Data.Finset.Max
namespace DivisorSequence
open Finset
/-- For an even natural number `n>1`, the largest proper divisor is `n/2`. -/
theorem max'_properDivisors_eq_div_two {n : ℕ} (hn2 : 2 ∣ n) (hn1 : 1 < n) :
(n.properDivisors).max' (by
-- nonemptiness
simpa [Nat.nonempty_properDivisors] using hn1) = n / 2 := by
classical
set H : (n.properDivisors).Nonempty := by
simpa [Nat.nonempty_properDivisors] using hn1
refine (Finset.max'_eq_iff (s := n.properDivisors) (H := H) (a := n / 2)).2 ?_
constructor
· -- show `n/2` is a proper divisor
rcases hn2 with ⟨m, rfl⟩
have hmpos : 0 < m := by
refine Nat.pos_of_ne_zero ?_
intro hm0
subst hm0
simpa using hn1
have hdiv : (2 * m) / 2 ∣ 2 * m := by
-- `(2*m)/2 = m` and `m ∣ 2*m`
simpa [Nat.mul_comm] using (dvd_mul_left m 2)
have hlt : (2 * m) / 2 < 2 * m := by
-- reduces to `m < 2*m`
simpa using (Nat.mul_lt_mul_of_pos_right (by decide : (1:ℕ) < 2) hmpos)
exact (Nat.mem_properDivisors).2 ⟨hdiv, hlt⟩
· intro b hb
-- show `b ≤ n/2`
have hn0 : n ≠ 0 := Nat.ne_of_gt (lt_trans Nat.zero_lt_one hn1)
rcases (Nat.mem_properDivisors_iff_exists (m := b) (n := n) hn0).1 hb with ⟨k, hk, hnk⟩
have hk2 : 2 ≤ k := (Nat.succ_le_iff).2 hk
have hb2' : b * 2 ≤ b * k := Nat.mul_le_mul_left b hk2
have hb2 : b * 2 ≤ n := by
simpa [hnk] using hb2'
exact (Nat.le_div_iff_mul_le Nat.zero_lt_two).2 hb2
end DivisorSequence
Compilation output
$ cd /opt/lean/Math
$ lake env lean ProperDivisorsMax.lean
# success (only linter warnings about unnecessary `simpa`)