Theorem: LucasLehmer.norm_num_ext.sMod'_eq_sMod
File: Mathlib/NumberTheory/LucasLehmer.lean

tactic: have h1 := calc
  4 = 2 ^ 2 := by norm_num
  _ ≤ 2 ^ p := Nat.pow_le_pow_of_le_right (by norm_num) hp
state_before: p k : ℕ
hp : 2 ≤ p
⊢ ↑(sMod' (2 ^ p - 1) k) = sMod p k
state_after: p k : ℕ
hp : 2 ≤ p
h1 : 4 ≤ 2 ^ p
⊢ ↑(sMod' (2 ^ p - 1) k) = sMod p k

tactic: have h2 : 1 ≤ 2 ^ p := by omega
state_before: p k : ℕ
hp : 2 ≤ p
h1 : 4 ≤ 2 ^ p
⊢ ↑(sMod' (2 ^ p - 1) k) = sMod p k
state_after: p k : ℕ
hp : 2 ≤ p
h1 : 4 ≤ 2 ^ p
h2 : 1 ≤ 2 ^ p
⊢ ↑(sMod' (2 ^ p - 1) k) = sMod p k

tactic: induction k with
| zero =>
  rw [sMod', sMod, Int.ofNat_emod]
  simp [h2]
| succ k ih =>
  rw [sMod', sMod, ← ih]
  have h3 : 2 ≤ 2 ^ p - 1 := by
    zify [h2]
    calc
      (2 : Int) ≤ 4 - 1 := by norm_num
      _         ≤ 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_self, ← sub_eq_add_neg]
state_before: p k : ℕ
hp : 2 ≤ p
h1 : 4 ≤ 2 ^ p
h2 : 1 ≤ 2 ^ p
⊢ ↑(sMod' (2 ^ p - 1) k) = sMod p k
state_after: no goals

tactic: norm_num
state_before: p k : ℕ
hp : 2 ≤ p
⊢ 4 = 2 ^ 2
state_after: no goals

tactic: norm_num
state_before: p k : ℕ
hp : 2 ≤ p
⊢ 2 > 0
state_after: no goals

tactic: omega
state_before: p k : ℕ
hp : 2 ≤ p
h1 : 4 ≤ 2 ^ p
⊢ 1 ≤ 2 ^ p
state_after: no goals

tactic: rw [sMod', sMod, Int.ofNat_emod]
state_before: case zero
p : ℕ
hp : 2 ≤ p
h1 : 4 ≤ 2 ^ p
h2 : 1 ≤ 2 ^ p
⊢ ↑(sMod' (2 ^ p - 1) 0) = sMod p 0
state_after: case zero
p : ℕ
hp : 2 ≤ p
h1 : 4 ≤ 2 ^ p
h2 : 1 ≤ 2 ^ p
⊢ ↑4 % ↑(2 ^ p - 1) = 4 % (2 ^ p - 1)

tactic: simp [h2]
state_before: case zero
p : ℕ
hp : 2 ≤ p
h1 : 4 ≤ 2 ^ p
h2 : 1 ≤ 2 ^ p
⊢ ↑4 % ↑(2 ^ p - 1) = 4 % (2 ^ p - 1)
state_after: no goals

tactic: rw [sMod', sMod, ← ih]
state_before: case succ
p : ℕ
hp : 2 ≤ p
h1 : 4 ≤ 2 ^ p
h2 : 1 ≤ 2 ^ p
k : ℕ
ih : ↑(sMod' (2 ^ p - 1) k) = sMod p k
⊢ ↑(sMod' (2 ^ p - 1) (k + 1)) = sMod p (k + 1)
state_after: case succ
p : ℕ
hp : 2 ≤ p
h1 : 4 ≤ 2 ^ p
h2 : 1 ≤ 2 ^ p
k : ℕ
ih : ↑(sMod' (2 ^ p - 1) k) = sMod p k
⊢ ↑((sMod' (2 ^ p - 1) k ^ 2 + (2 ^ p - 1 - 2)) % (2 ^ p - 1)) = (↑(sMod' (2 ^ p - 1) k) ^ 2 - 2) % (2 ^ p - 1)

tactic: have h3 : 2 ≤ 2 ^ p - 1 := by
  zify [h2]
  calc
    (2 : Int) ≤ 4 - 1 := by norm_num
    _         ≤ 2 ^ p - 1 := by zify at h1; exact Int.sub_le_sub_right h1 _
state_before: case succ
p : ℕ
hp : 2 ≤ p
h1 : 4 ≤ 2 ^ p
h2 : 1 ≤ 2 ^ p
k : ℕ
ih : ↑(sMod' (2 ^ p - 1) k) = sMod p k
⊢ ↑((sMod' (2 ^ p - 1) k ^ 2 + (2 ^ p - 1 - 2)) % (2 ^ p - 1)) = (↑(sMod' (2 ^ p - 1) k) ^ 2 - 2) % (2 ^ p - 1)
state_after: case succ
p : ℕ
hp : 2 ≤ p
h1 : 4 ≤ 2 ^ p
h2 : 1 ≤ 2 ^ p
k : ℕ
ih : ↑(sMod' (2 ^ p - 1) k) = sMod p k
h3 : 2 ≤ 2 ^ p - 1
⊢ ↑((sMod' (2 ^ p - 1) k ^ 2 + (2 ^ p - 1 - 2)) % (2 ^ p - 1)) = (↑(sMod' (2 ^ p - 1) k) ^ 2 - 2) % (2 ^ p - 1)

tactic: zify [h2, h3]
state_before: case succ
p : ℕ
hp : 2 ≤ p
h1 : 4 ≤ 2 ^ p
h2 : 1 ≤ 2 ^ p
k : ℕ
ih : ↑(sMod' (2 ^ p - 1) k) = sMod p k
h3 : 2 ≤ 2 ^ p - 1
⊢ ↑((sMod' (2 ^ p - 1) k ^ 2 + (2 ^ p - 1 - 2)) % (2 ^ p - 1)) = (↑(sMod' (2 ^ p - 1) k) ^ 2 - 2) % (2 ^ p - 1)
state_after: case succ
p : ℕ
hp : 2 ≤ p
h1 : 4 ≤ 2 ^ p
h2 : 1 ≤ 2 ^ p
k : ℕ
ih : ↑(sMod' (2 ^ p - 1) k) = sMod p k
h3 : 2 ≤ 2 ^ p - 1
⊢ (↑(sMod' (2 ^ p - 1) k) ^ 2 + (2 ^ p - 1 - 2)) % (2 ^ p - 1) = (↑(sMod' (2 ^ p - 1) k) ^ 2 - 2) % (2 ^ p - 1)

tactic: rw [← add_sub_assoc, sub_eq_add_neg, add_assoc, add_comm _ (-2), ← add_assoc,
  Int.add_emod_self, ← sub_eq_add_neg]
state_before: case succ
p : ℕ
hp : 2 ≤ p
h1 : 4 ≤ 2 ^ p
h2 : 1 ≤ 2 ^ p
k : ℕ
ih : ↑(sMod' (2 ^ p - 1) k) = sMod p k
h3 : 2 ≤ 2 ^ p - 1
⊢ (↑(sMod' (2 ^ p - 1) k) ^ 2 + (2 ^ p - 1 - 2)) % (2 ^ p - 1) = (↑(sMod' (2 ^ p - 1) k) ^ 2 - 2) % (2 ^ p - 1)
state_after: no goals

tactic: calc
  (2 : Int) ≤ 4 - 1 := by norm_num
  _         ≤ 2 ^ p - 1 := by zify at h1; exact Int.sub_le_sub_right h1 _
state_before: p : ℕ
hp : 2 ≤ p
h1 : 4 ≤ 2 ^ p
h2 : 1 ≤ 2 ^ p
k : ℕ
ih : ↑(sMod' (2 ^ p - 1) k) = sMod p k
⊢ 2 ≤ 2 ^ p - 1
state_after: no goals

tactic: norm_num
state_before: p : ℕ
hp : 2 ≤ p
h1 : 4 ≤ 2 ^ p
h2 : 1 ≤ 2 ^ p
k : ℕ
ih : ↑(sMod' (2 ^ p - 1) k) = sMod p k
⊢ 2 ≤ 4 - 1
state_after: no goals

tactic: zify at h1
state_before: p : ℕ
hp : 2 ≤ p
h1 : 4 ≤ 2 ^ p
h2 : 1 ≤ 2 ^ p
k : ℕ
ih : ↑(sMod' (2 ^ p - 1) k) = sMod p k
⊢ 4 - 1 ≤ 2 ^ p - 1
state_after: p : ℕ
hp : 2 ≤ p
h2 : 1 ≤ 2 ^ p
k : ℕ
ih : ↑(sMod' (2 ^ p - 1) k) = sMod p k
h1 : 4 ≤ 2 ^ p
⊢ 4 - 1 ≤ 2 ^ p - 1

tactic: exact Int.sub_le_sub_right h1 _
state_before: p : ℕ
hp : 2 ≤ p
h2 : 1 ≤ 2 ^ p
k : ℕ
ih : ↑(sMod' (2 ^ p - 1) k) = sMod p k
h1 : 4 ≤ 2 ^ p
⊢ 4 - 1 ≤ 2 ^ p - 1
state_after: no goals