Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 4 additions & 17 deletions Mathlib/NumberTheory/LucasLehmer.lean
Original file line number Diff line number Diff line change
Expand Up @@ -632,24 +632,11 @@ def sModNat (q : β„•) : β„• β†’ β„•
| i + 1 => (sModNat q i ^ 2 + (q - 2)) % q

theorem sModNat_eq_sMod (p k : β„•) (hp : 2 ≀ p) : (sModNat (2 ^ p - 1) k : β„€) = sMod p k := by
have h1 := calc
4 = 2 ^ 2 := by simp
_ ≀ 2 ^ p := Nat.pow_le_pow_right (by simp) hp
have h2 : 1 ≀ 2 ^ p := by lia
induction k with
| zero =>
rw [sModNat, sMod, Int.natCast_emod]
simp [h2]
| succ k ih =>
rw [sModNat, sMod, ← ih]
have h3 : 2 ≀ 2 ^ p - 1 := by
zify [h2]
calc (2 : β„€)
_ ≀ 4 - 1 := by simp
_ ≀ 2 ^ p - 1 := by zify at h1; exact Int.sub_le_sub_right h1 _
zify [h2, h3]
rw [← add_sub_assoc, sub_eq_add_neg, add_assoc, add_comm _ (-2), ← add_assoc,
Int.add_emod_right, ← sub_eq_add_neg]
| zero => grind [sModNat, sMod]
| succ =>
have : 2 ^ 2 ≀ 2 ^ p := Nat.pow_le_pow_right (by lia) hp
grind [sModNat, sMod, Int.emod_eq_add_self_emod]

/-- Tail-recursive version of `sModNat`. -/
meta def sModNatTR (q k : β„•) : β„• :=
Expand Down
Loading