Theorem: Nat.properDivisors_eq_singleton_one_iff_prime
File: Mathlib/NumberTheory/Divisors.lean

tactic: refine ⟨?_, ?_⟩
state_before: n : ℕ
⊢ n.properDivisors = {1} ↔ Prime n
state_after: case refine_1
n : ℕ
⊢ n.properDivisors = {1} → Prime n

case refine_2
n : ℕ
⊢ Prime n → n.properDivisors = {1}

tactic: intro h
state_before: case refine_1
n : ℕ
⊢ n.properDivisors = {1} → Prime n
state_after: case refine_1
n : ℕ
h : n.properDivisors = {1}
⊢ Prime n

tactic: refine Nat.prime_def_lt''.mpr ⟨?_, fun m hdvd => ?_⟩
state_before: case refine_1
n : ℕ
h : n.properDivisors = {1}
⊢ Prime n
state_after: case refine_1.refine_1
n : ℕ
h : n.properDivisors = {1}
⊢ 2 ≤ n

case refine_1.refine_2
n : ℕ
h : n.properDivisors = {1}
m : ℕ
hdvd : m ∣ n
⊢ m = 1 ∨ m = n

tactic: match n with
| 0 => contradiction
| 1 => contradiction
| Nat.succ (Nat.succ n) => simp [succ_le_succ]
state_before: case refine_1.refine_1
n : ℕ
h : n.properDivisors = {1}
⊢ 2 ≤ n
state_after: no goals

tactic: contradiction
state_before: n : ℕ
h : properDivisors 0 = {1}
⊢ 2 ≤ 0
state_after: no goals

tactic: contradiction
state_before: n : ℕ
h : properDivisors 1 = {1}
⊢ 2 ≤ 1
state_after: no goals

tactic: simp [succ_le_succ]
state_before: n✝ n : ℕ
h : n.succ.succ.properDivisors = {1}
⊢ 2 ≤ n.succ.succ
state_after: no goals

tactic: rw [← mem_singleton, ← h, mem_properDivisors]
state_before: case refine_1.refine_2
n : ℕ
h : n.properDivisors = {1}
m : ℕ
hdvd : m ∣ n
⊢ m = 1 ∨ m = n
state_after: case refine_1.refine_2
n : ℕ
h : n.properDivisors = {1}
m : ℕ
hdvd : m ∣ n
⊢ m ∣ n ∧ m < n ∨ m = n

tactic: have := Nat.le_of_dvd ?_ hdvd
state_before: case refine_1.refine_2
n : ℕ
h : n.properDivisors = {1}
m : ℕ
hdvd : m ∣ n
⊢ m ∣ n ∧ m < n ∨ m = n
state_after: case refine_1.refine_2.refine_2
n : ℕ
h : n.properDivisors = {1}
m : ℕ
hdvd : m ∣ n
this : m ≤ n
⊢ m ∣ n ∧ m < n ∨ m = n

case refine_1.refine_2.refine_1
n : ℕ
h : n.properDivisors = {1}
m : ℕ
hdvd : m ∣ n
⊢ 0 < n

tactic: simp [hdvd, this]
state_before: case refine_1.refine_2.refine_2
n : ℕ
h : n.properDivisors = {1}
m : ℕ
hdvd : m ∣ n
this : m ≤ n
⊢ m ∣ n ∧ m < n ∨ m = n
state_after: case refine_1.refine_2.refine_2
n : ℕ
h : n.properDivisors = {1}
m : ℕ
hdvd : m ∣ n
this : m ≤ n
⊢ m < n ∨ m = n

tactic: exact (le_iff_eq_or_lt.mp this).symm
state_before: case refine_1.refine_2.refine_2
n : ℕ
h : n.properDivisors = {1}
m : ℕ
hdvd : m ∣ n
this : m ≤ n
⊢ m < n ∨ m = n
state_after: no goals

tactic: by_contra!
state_before: case refine_1.refine_2.refine_1
n : ℕ
h : n.properDivisors = {1}
m : ℕ
hdvd : m ∣ n
⊢ 0 < n
state_after: case refine_1.refine_2.refine_1
n : ℕ
h : n.properDivisors = {1}
m : ℕ
hdvd : m ∣ n
this : n ≤ 0
⊢ False

tactic: simp only [nonpos_iff_eq_zero.mp this, this] at h
state_before: case refine_1.refine_2.refine_1
n : ℕ
h : n.properDivisors = {1}
m : ℕ
hdvd : m ∣ n
this : n ≤ 0
⊢ False
state_after: case refine_1.refine_2.refine_1
n m : ℕ
hdvd : m ∣ n
this : n ≤ 0
h : properDivisors 0 = {1}
⊢ False

tactic: contradiction
state_before: case refine_1.refine_2.refine_1
n m : ℕ
hdvd : m ∣ n
this : n ≤ 0
h : properDivisors 0 = {1}
⊢ False
state_after: no goals

tactic: exact fun h => Prime.properDivisors h
state_before: case refine_2
n : ℕ
⊢ Prime n → n.properDivisors = {1}
state_after: no goals