Theorem: FermatPsp.psp_from_prime_gt_p
File: Mathlib/NumberTheory/FermatPsp.lean

tactic: unfold psp_from_prime
state_before: b : ℕ
b_ge_two : 2 ≤ b
p : ℕ
p_prime : Nat.Prime p
p_gt_two : 2 < p
⊢ p < FermatPsp.psp_from_prime b p

tactic: set A := (b ^ p - 1) / (b - 1)
state_before: b : ℕ
b_ge_two : 2 ≤ b
p : ℕ
p_prime : Nat.Prime p
p_gt_two : 2 < p
⊢ p < (b ^ p - 1) / (b - 1) * ((b ^ p + 1) / (b + 1))

tactic: set B := (b ^ p + 1) / (b + 1)
state_before: b : ℕ
b_ge_two : 2 ≤ b
p : ℕ
p_prime : Nat.Prime p
p_gt_two : 2 < p
A : ℕ := (b ^ p - 1) / (b - 1)
⊢ p < A * ((b ^ p + 1) / (b + 1))

tactic: rw [show A * B = (b ^ (2 * p) - 1) / (b ^ 2 - 1) from
    AB_id_helper _ _ b_ge_two (p_prime.odd_of_ne_two p_gt_two.ne.symm)]
state_before: b : ℕ
b_ge_two : 2 ≤ b
p : ℕ
p_prime : Nat.Prime p
p_gt_two : 2 < p
A : ℕ := (b ^ p - 1) / (b - 1)
B : ℕ := (b ^ p + 1) / (b + 1)
⊢ p < A * B

tactic: have AB_dvd : b ^ 2 - 1 ∣ b ^ (2 * p) - 1 := by
  simpa only [one_pow, pow_mul] using nat_sub_dvd_pow_sub_pow _ 1 p
state_before: b : ℕ
b_ge_two : 2 ≤ b
p : ℕ
p_prime : Nat.Prime p
p_gt_two : 2 < p
A : ℕ := (b ^ p - 1) / (b - 1)
B : ℕ := (b ^ p + 1) / (b + 1)
⊢ p < (b ^ (2 * p) - 1) / (b ^ 2 - 1)

tactic: suffices h : p * (b ^ 2 - 1) < b ^ (2 * p) - 1
state_before: b : ℕ
b_ge_two : 2 ≤ b
p : ℕ
p_prime : Nat.Prime p
p_gt_two : 2 < p
A : ℕ := (b ^ p - 1) / (b - 1)
B : ℕ := (b ^ p + 1) / (b + 1)
AB_dvd : b ^ 2 - 1 ∣ b ^ (2 * p) - 1
⊢ p < (b ^ (2 * p) - 1) / (b ^ 2 - 1)

tactic: rw [Nat.mul_sub_left_distrib, mul_one, pow_mul]
state_before: case h
b : ℕ
b_ge_two : 2 ≤ b
p : ℕ
p_prime : Nat.Prime p
p_gt_two : 2 < p
A : ℕ := (b ^ p - 1) / (b - 1)
B : ℕ := (b ^ p + 1) / (b + 1)
AB_dvd : b ^ 2 - 1 ∣ b ^ (2 * p) - 1
⊢ p * (b ^ 2 - 1) < b ^ (2 * p) - 1

tactic: conv_rhs => rw [← Nat.sub_add_cancel (show 1 ≤ p by linarith)]
state_before: case h
b : ℕ
b_ge_two : 2 ≤ b
p : ℕ
p_prime : Nat.Prime p
p_gt_two : 2 < p
A : ℕ := (b ^ p - 1) / (b - 1)
B : ℕ := (b ^ p + 1) / (b + 1)
AB_dvd : b ^ 2 - 1 ∣ b ^ (2 * p) - 1
⊢ p * b ^ 2 - p < (b ^ 2) ^ p - 1

tactic: rw [pow_succ (b ^ 2)]
state_before: case h
b : ℕ
b_ge_two : 2 ≤ b
p : ℕ
p_prime : Nat.Prime p
p_gt_two : 2 < p
A : ℕ := (b ^ p - 1) / (b - 1)
B : ℕ := (b ^ p + 1) / (b + 1)
AB_dvd : b ^ 2 - 1 ∣ b ^ (2 * p) - 1
⊢ p * b ^ 2 - p < (b ^ 2) ^ (p - 1 + 1) - 1

tactic: suffices h : p * b ^ 2 < b ^ 2 * (b ^ 2) ^ (p - 1)
state_before: case h
b : ℕ
b_ge_two : 2 ≤ b
p : ℕ
p_prime : Nat.Prime p
p_gt_two : 2 < p
A : ℕ := (b ^ p - 1) / (b - 1)
B : ℕ := (b ^ p + 1) / (b + 1)
AB_dvd : b ^ 2 - 1 ∣ b ^ (2 * p) - 1
⊢ p * b ^ 2 - p < b ^ 2 * (b ^ 2) ^ (p - 1) - 1

tactic: suffices h : p < (b ^ 2) ^ (p - 1)
state_before: case h
b : ℕ
b_ge_two : 2 ≤ b
p : ℕ
p_prime : Nat.Prime p
p_gt_two : 2 < p
A : ℕ := (b ^ p - 1) / (b - 1)
B : ℕ := (b ^ p + 1) / (b + 1)
AB_dvd : b ^ 2 - 1 ∣ b ^ (2 * p) - 1
⊢ p * b ^ 2 < b ^ 2 * (b ^ 2) ^ (p - 1)

tactic: rw [← pow_mul, Nat.mul_sub_left_distrib, mul_one]
state_before: case h
b : ℕ
b_ge_two : 2 ≤ b
p : ℕ
p_prime : Nat.Prime p
p_gt_two : 2 < p
A : ℕ := (b ^ p - 1) / (b - 1)
B : ℕ := (b ^ p + 1) / (b + 1)
AB_dvd : b ^ 2 - 1 ∣ b ^ (2 * p) - 1
⊢ p < (b ^ 2) ^ (p - 1)

tactic: have : 2 ≤ 2 * p - 2 := le_tsub_of_add_le_left (show 4 ≤ 2 * p by linarith)
state_before: case h
b : ℕ
b_ge_two : 2 ≤ b
p : ℕ
p_prime : Nat.Prime p
p_gt_two : 2 < p
A : ℕ := (b ^ p - 1) / (b - 1)
B : ℕ := (b ^ p + 1) / (b + 1)
AB_dvd : b ^ 2 - 1 ∣ b ^ (2 * p) - 1
⊢ p < b ^ (2 * p - 2)

tactic: have : 2 + p ≤ 2 * p := by linarith
state_before: case h
b : ℕ
b_ge_two : 2 ≤ b
p : ℕ
p_prime : Nat.Prime p
p_gt_two : 2 < p
A : ℕ := (b ^ p - 1) / (b - 1)
B : ℕ := (b ^ p + 1) / (b + 1)
AB_dvd : b ^ 2 - 1 ∣ b ^ (2 * p) - 1
this : 2 ≤ 2 * p - 2
⊢ p < b ^ (2 * p - 2)

tactic: have : p ≤ 2 * p - 2 := le_tsub_of_add_le_left this
state_before: case h
b : ℕ
b_ge_two : 2 ≤ b
p : ℕ
p_prime : Nat.Prime p
p_gt_two : 2 < p
A : ℕ := (b ^ p - 1) / (b - 1)
B : ℕ := (b ^ p + 1) / (b + 1)
AB_dvd : b ^ 2 - 1 ∣ b ^ (2 * p) - 1
this✝ : 2 ≤ 2 * p - 2
this : 2 + p ≤ 2 * p
⊢ p < b ^ (2 * p - 2)

tactic: exact Nat.lt_of_le_of_lt this (pow_gt_exponent _ b_ge_two)
state_before: case h
b : ℕ
b_ge_two : 2 ≤ b
p : ℕ
p_prime : Nat.Prime p
p_gt_two : 2 < p
A : ℕ := (b ^ p - 1) / (b - 1)
B : ℕ := (b ^ p + 1) / (b + 1)
AB_dvd : b ^ 2 - 1 ∣ b ^ (2 * p) - 1
this✝¹ : 2 ≤ 2 * p - 2
this✝ : 2 + p ≤ 2 * p
this : p ≤ 2 * p - 2
⊢ p < b ^ (2 * p - 2)

tactic: simpa only [one_pow, pow_mul] using nat_sub_dvd_pow_sub_pow _ 1 p
state_before: b : ℕ
b_ge_two : 2 ≤ b
p : ℕ
p_prime : Nat.Prime p
p_gt_two : 2 < p
A : ℕ := (b ^ p - 1) / (b - 1)
B : ℕ := (b ^ p + 1) / (b + 1)
⊢ b ^ 2 - 1 ∣ b ^ (2 * p) - 1

tactic: have h₁ : p * (b ^ 2 - 1) / (b ^ 2 - 1) < (b ^ (2 * p) - 1) / (b ^ 2 - 1) :=
  Nat.div_lt_div_of_lt_of_dvd AB_dvd h
state_before: b : ℕ
b_ge_two : 2 ≤ b
p : ℕ
p_prime : Nat.Prime p
p_gt_two : 2 < p
A : ℕ := (b ^ p - 1) / (b - 1)
B : ℕ := (b ^ p + 1) / (b + 1)
AB_dvd : b ^ 2 - 1 ∣ b ^ (2 * p) - 1
h : p * (b ^ 2 - 1) < b ^ (2 * p) - 1
⊢ p < (b ^ (2 * p) - 1) / (b ^ 2 - 1)

tactic: have h₂ : 0 < b ^ 2 - 1 := by
  linarith [show 3 ≤ b ^ 2 - 1 from le_tsub_of_add_le_left (show 4 ≤ b ^ 2 by nlinarith)]
state_before: b : ℕ
b_ge_two : 2 ≤ b
p : ℕ
p_prime : Nat.Prime p
p_gt_two : 2 < p
A : ℕ := (b ^ p - 1) / (b - 1)
B : ℕ := (b ^ p + 1) / (b + 1)
AB_dvd : b ^ 2 - 1 ∣ b ^ (2 * p) - 1
h : p * (b ^ 2 - 1) < b ^ (2 * p) - 1
h₁ : p * (b ^ 2 - 1) / (b ^ 2 - 1) < (b ^ (2 * p) - 1) / (b ^ 2 - 1)
⊢ p < (b ^ (2 * p) - 1) / (b ^ 2 - 1)

tactic: rwa [Nat.mul_div_cancel _ h₂] at h₁
state_before: b : ℕ
b_ge_two : 2 ≤ b
p : ℕ
p_prime : Nat.Prime p
p_gt_two : 2 < p
A : ℕ := (b ^ p - 1) / (b - 1)
B : ℕ := (b ^ p + 1) / (b + 1)
AB_dvd : b ^ 2 - 1 ∣ b ^ (2 * p) - 1
h : p * (b ^ 2 - 1) < b ^ (2 * p) - 1
h₁ : p * (b ^ 2 - 1) / (b ^ 2 - 1) < (b ^ (2 * p) - 1) / (b ^ 2 - 1)
h₂ : 0 < b ^ 2 - 1
⊢ p < (b ^ (2 * p) - 1) / (b ^ 2 - 1)

tactic: linarith [show 3 ≤ b ^ 2 - 1 from le_tsub_of_add_le_left (show 4 ≤ b ^ 2 by nlinarith)]
state_before: b : ℕ
b_ge_two : 2 ≤ b
p : ℕ
p_prime : Nat.Prime p
p_gt_two : 2 < p
A : ℕ := (b ^ p - 1) / (b - 1)
B : ℕ := (b ^ p + 1) / (b + 1)
AB_dvd : b ^ 2 - 1 ∣ b ^ (2 * p) - 1
h : p * (b ^ 2 - 1) < b ^ (2 * p) - 1
h₁ : p * (b ^ 2 - 1) / (b ^ 2 - 1) < (b ^ (2 * p) - 1) / (b ^ 2 - 1)
⊢ 0 < b ^ 2 - 1

tactic: nlinarith
state_before: b : ℕ
b_ge_two : 2 ≤ b
p : ℕ
p_prime : Nat.Prime p
p_gt_two : 2 < p
A : ℕ := (b ^ p - 1) / (b - 1)
B : ℕ := (b ^ p + 1) / (b + 1)
AB_dvd : b ^ 2 - 1 ∣ b ^ (2 * p) - 1
h : p * (b ^ 2 - 1) < b ^ (2 * p) - 1
h₁ : p * (b ^ 2 - 1) / (b ^ 2 - 1) < (b ^ (2 * p) - 1) / (b ^ 2 - 1)
⊢ 4 ≤ b ^ 2

tactic: linarith
state_before: b : ℕ
b_ge_two : 2 ≤ b
p : ℕ
p_prime : Nat.Prime p
p_gt_two : 2 < p
A : ℕ := (b ^ p - 1) / (b - 1)
B : ℕ := (b ^ p + 1) / (b + 1)
AB_dvd : b ^ 2 - 1 ∣ b ^ (2 * p) - 1
⊢ 1 ≤ p

tactic: apply gt_of_ge_of_gt
state_before: case h
b : ℕ
b_ge_two : 2 ≤ b
p : ℕ
p_prime : Nat.Prime p
p_gt_two : 2 < p
A : ℕ := (b ^ p - 1) / (b - 1)
B : ℕ := (b ^ p + 1) / (b + 1)
AB_dvd : b ^ 2 - 1 ∣ b ^ (2 * p) - 1
h : p * b ^ 2 < b ^ 2 * (b ^ 2) ^ (p - 1)
⊢ p * b ^ 2 - p < b ^ 2 * (b ^ 2) ^ (p - 1) - 1

tactic: exact tsub_le_tsub_left (show 1 ≤ p by linarith) (b ^ 2 * (b ^ 2) ^ (p - 1))
state_before: case h.h₁
b : ℕ
b_ge_two : 2 ≤ b
p : ℕ
p_prime : Nat.Prime p
p_gt_two : 2 < p
A : ℕ := (b ^ p - 1) / (b - 1)
B : ℕ := (b ^ p + 1) / (b + 1)
AB_dvd : b ^ 2 - 1 ∣ b ^ (2 * p) - 1
h : p * b ^ 2 < b ^ 2 * (b ^ 2) ^ (p - 1)
⊢ b ^ 2 * (b ^ 2) ^ (p - 1) - 1 ≥ ?h.b

tactic: linarith
state_before: b : ℕ
b_ge_two : 2 ≤ b
p : ℕ
p_prime : Nat.Prime p
p_gt_two : 2 < p
A : ℕ := (b ^ p - 1) / (b - 1)
B : ℕ := (b ^ p + 1) / (b + 1)
AB_dvd : b ^ 2 - 1 ∣ b ^ (2 * p) - 1
h : p * b ^ 2 < b ^ 2 * (b ^ 2) ^ (p - 1)
⊢ 1 ≤ p

tactic: have : p ≤ p * b ^ 2 := Nat.le_mul_of_pos_right (show 0 < b ^ 2 by nlinarith)
state_before: case h.h₂
b : ℕ
b_ge_two : 2 ≤ b
p : ℕ
p_prime : Nat.Prime p
p_gt_two : 2 < p
A : ℕ := (b ^ p - 1) / (b - 1)
B : ℕ := (b ^ p + 1) / (b + 1)
AB_dvd : b ^ 2 - 1 ∣ b ^ (2 * p) - 1
h : p * b ^ 2 < b ^ 2 * (b ^ 2) ^ (p - 1)
⊢ b ^ 2 * (b ^ 2) ^ (p - 1) - p > p * b ^ 2 - p

tactic: exact tsub_lt_tsub_right_of_le this h
state_before: case h.h₂
b : ℕ
b_ge_two : 2 ≤ b
p : ℕ
p_prime : Nat.Prime p
p_gt_two : 2 < p
A : ℕ := (b ^ p - 1) / (b - 1)
B : ℕ := (b ^ p + 1) / (b + 1)
AB_dvd : b ^ 2 - 1 ∣ b ^ (2 * p) - 1
h : p * b ^ 2 < b ^ 2 * (b ^ 2) ^ (p - 1)
this : p ≤ p * b ^ 2
⊢ b ^ 2 * (b ^ 2) ^ (p - 1) - p > p * b ^ 2 - p

tactic: nlinarith
state_before: b : ℕ
b_ge_two : 2 ≤ b
p : ℕ
p_prime : Nat.Prime p
p_gt_two : 2 < p
A : ℕ := (b ^ p - 1) / (b - 1)
B : ℕ := (b ^ p + 1) / (b + 1)
AB_dvd : b ^ 2 - 1 ∣ b ^ (2 * p) - 1
h : p * b ^ 2 < b ^ 2 * (b ^ 2) ^ (p - 1)
⊢ 0 < b ^ 2

tactic: rw [mul_comm (b ^ 2)]
state_before: case h
b : ℕ
b_ge_two : 2 ≤ b
p : ℕ
p_prime : Nat.Prime p
p_gt_two : 2 < p
A : ℕ := (b ^ p - 1) / (b - 1)
B : ℕ := (b ^ p + 1) / (b + 1)
AB_dvd : b ^ 2 - 1 ∣ b ^ (2 * p) - 1
h : p < (b ^ 2) ^ (p - 1)
⊢ p * b ^ 2 < b ^ 2 * (b ^ 2) ^ (p - 1)

tactic: have : 4 ≤ b ^ 2 := by nlinarith
state_before: case h
b : ℕ
b_ge_two : 2 ≤ b
p : ℕ
p_prime : Nat.Prime p
p_gt_two : 2 < p
A : ℕ := (b ^ p - 1) / (b - 1)
B : ℕ := (b ^ p + 1) / (b + 1)
AB_dvd : b ^ 2 - 1 ∣ b ^ (2 * p) - 1
h : p < (b ^ 2) ^ (p - 1)
⊢ p * b ^ 2 < (b ^ 2) ^ (p - 1) * b ^ 2

tactic: have : 0 < b ^ 2 := by linarith
state_before: case h
b : ℕ
b_ge_two : 2 ≤ b
p : ℕ
p_prime : Nat.Prime p
p_gt_two : 2 < p
A : ℕ := (b ^ p - 1) / (b - 1)
B : ℕ := (b ^ p + 1) / (b + 1)
AB_dvd : b ^ 2 - 1 ∣ b ^ (2 * p) - 1
h : p < (b ^ 2) ^ (p - 1)
this : 4 ≤ b ^ 2
⊢ p * b ^ 2 < (b ^ 2) ^ (p - 1) * b ^ 2

tactic: exact mul_lt_mul_of_pos_right h this
state_before: case h
b : ℕ
b_ge_two : 2 ≤ b
p : ℕ
p_prime : Nat.Prime p
p_gt_two : 2 < p
A : ℕ := (b ^ p - 1) / (b - 1)
B : ℕ := (b ^ p + 1) / (b + 1)
AB_dvd : b ^ 2 - 1 ∣ b ^ (2 * p) - 1
h : p < (b ^ 2) ^ (p - 1)
this✝ : 4 ≤ b ^ 2
this : 0 < b ^ 2
⊢ p * b ^ 2 < (b ^ 2) ^ (p - 1) * b ^ 2

tactic: nlinarith
state_before: b : ℕ
b_ge_two : 2 ≤ b
p : ℕ
p_prime : Nat.Prime p
p_gt_two : 2 < p
A : ℕ := (b ^ p - 1) / (b - 1)
B : ℕ := (b ^ p + 1) / (b + 1)
AB_dvd : b ^ 2 - 1 ∣ b ^ (2 * p) - 1
h : p < (b ^ 2) ^ (p - 1)
⊢ 4 ≤ b ^ 2

tactic: linarith
state_before: b : ℕ
b_ge_two : 2 ≤ b
p : ℕ
p_prime : Nat.Prime p
p_gt_two : 2 < p
A : ℕ := (b ^ p - 1) / (b - 1)
B : ℕ := (b ^ p + 1) / (b + 1)
AB_dvd : b ^ 2 - 1 ∣ b ^ (2 * p) - 1
h : p < (b ^ 2) ^ (p - 1)
this : 4 ≤ b ^ 2
⊢ 0 < b ^ 2

tactic: linarith
state_before: b : ℕ
b_ge_two : 2 ≤ b
p : ℕ
p_prime : Nat.Prime p
p_gt_two : 2 < p
A : ℕ := (b ^ p - 1) / (b - 1)
B : ℕ := (b ^ p + 1) / (b + 1)
AB_dvd : b ^ 2 - 1 ∣ b ^ (2 * p) - 1
⊢ 4 ≤ 2 * p

tactic: linarith
state_before: b : ℕ
b_ge_two : 2 ≤ b
p : ℕ
p_prime : Nat.Prime p
p_gt_two : 2 < p
A : ℕ := (b ^ p - 1) / (b - 1)
B : ℕ := (b ^ p + 1) / (b + 1)
AB_dvd : b ^ 2 - 1 ∣ b ^ (2 * p) - 1
this : 2 ≤ 2 * p - 2
⊢ 2 + p ≤ 2 * p