Theorem: ZMod.neg_eq_self_iff
File: Mathlib/Data/ZMod/Basic.lean

tactic: rw [neg_eq_iff_add_eq_zero, ← two_mul]
state_before: n : ℕ
a : ZMod n
⊢ -a = a ↔ a = 0 ∨ 2 * a.val = n
state_after: n : ℕ
a : ZMod n
⊢ 2 * a = 0 ↔ a = 0 ∨ 2 * a.val = n

tactic: cases n
state_before: n : ℕ
a : ZMod n
⊢ 2 * a = 0 ↔ a = 0 ∨ 2 * a.val = n
state_after: case zero
a : ZMod 0
⊢ 2 * a = 0 ↔ a = 0 ∨ 2 * a.val = 0

case succ
n✝ : ℕ
a : ZMod (n✝ + 1)
⊢ 2 * a = 0 ↔ a = 0 ∨ 2 * a.val = n✝ + 1

tactic: conv_lhs =>
  rw [← a.natCast_zmod_val, ← Nat.cast_two, ← Nat.cast_mul, natCast_zmod_eq_zero_iff_dvd]
state_before: case succ
n✝ : ℕ
a : ZMod (n✝ + 1)
⊢ 2 * a = 0 ↔ a = 0 ∨ 2 * a.val = n✝ + 1
state_after: case succ
n✝ : ℕ
a : ZMod (n✝ + 1)
⊢ n✝ + 1 ∣ 2 * a.val ↔ a = 0 ∨ 2 * a.val = n✝ + 1

tactic: constructor
state_before: case succ
n✝ : ℕ
a : ZMod (n✝ + 1)
⊢ n✝ + 1 ∣ 2 * a.val ↔ a = 0 ∨ 2 * a.val = n✝ + 1
state_after: case succ.mp
n✝ : ℕ
a : ZMod (n✝ + 1)
⊢ n✝ + 1 ∣ 2 * a.val → a = 0 ∨ 2 * a.val = n✝ + 1

case succ.mpr
n✝ : ℕ
a : ZMod (n✝ + 1)
⊢ a = 0 ∨ 2 * a.val = n✝ + 1 → n✝ + 1 ∣ 2 * a.val

tactic: erw [@mul_eq_zero ℤ, @mul_eq_zero ℕ, val_eq_zero]
state_before: case zero
a : ZMod 0
⊢ 2 * a = 0 ↔ a = 0 ∨ 2 * a.val = 0
state_after: case zero
a : ZMod 0
⊢ 2 = 0 ∨ a = 0 ↔ a = 0 ∨ 2 = 0 ∨ a = 0

tactic: exact
  ⟨fun h => h.elim (by simp) Or.inl, fun h =>
    Or.inr (h.elim id fun h => h.elim (by simp) id)⟩
state_before: case zero
a : ZMod 0
⊢ 2 = 0 ∨ a = 0 ↔ a = 0 ∨ 2 = 0 ∨ a = 0
state_after: no goals

tactic: simp
state_before: a : ZMod 0
h : 2 = 0 ∨ a = 0
⊢ 2 = 0 → a = 0 ∨ 2 = 0 ∨ a = 0
state_after: no goals

tactic: simp
state_before: a : ZMod 0
h✝ : a = 0 ∨ 2 = 0 ∨ a = 0
h : 2 = 0 ∨ a = 0
⊢ 2 = 0 → a = 0
state_after: no goals

tactic: rintro ⟨m, he⟩
state_before: case succ.mp
n✝ : ℕ
a : ZMod (n✝ + 1)
⊢ n✝ + 1 ∣ 2 * a.val → a = 0 ∨ 2 * a.val = n✝ + 1
state_after: case succ.mp.intro
n✝ : ℕ
a : ZMod (n✝ + 1)
m : ℕ
he : 2 * a.val = (n✝ + 1) * m
⊢ a = 0 ∨ 2 * a.val = n✝ + 1

tactic: cases' m with m
state_before: case succ.mp.intro
n✝ : ℕ
a : ZMod (n✝ + 1)
m : ℕ
he : 2 * a.val = (n✝ + 1) * m
⊢ a = 0 ∨ 2 * a.val = n✝ + 1
state_after: case succ.mp.intro.zero
n✝ : ℕ
a : ZMod (n✝ + 1)
he : 2 * a.val = (n✝ + 1) * 0
⊢ a = 0 ∨ 2 * a.val = n✝ + 1

case succ.mp.intro.succ
n✝ : ℕ
a : ZMod (n✝ + 1)
m : ℕ
he : 2 * a.val = (n✝ + 1) * (m + 1)
⊢ a = 0 ∨ 2 * a.val = n✝ + 1

tactic: cases m
state_before: case succ.mp.intro.succ
n✝ : ℕ
a : ZMod (n✝ + 1)
m : ℕ
he : 2 * a.val = (n✝ + 1) * (m + 1)
⊢ a = 0 ∨ 2 * a.val = n✝ + 1
state_after: case succ.mp.intro.succ.zero
n✝ : ℕ
a : ZMod (n✝ + 1)
he : 2 * a.val = (n✝ + 1) * (0 + 1)
⊢ a = 0 ∨ 2 * a.val = n✝ + 1

case succ.mp.intro.succ.succ
n✝¹ : ℕ
a : ZMod (n✝¹ + 1)
n✝ : ℕ
he : 2 * a.val = (n✝¹ + 1) * (n✝ + 1 + 1)
⊢ a = 0 ∨ 2 * a.val = n✝¹ + 1

tactic: refine (a.val_lt.not_le <| Nat.le_of_mul_le_mul_left ?_ zero_lt_two).elim
state_before: case succ.mp.intro.succ.succ
n✝¹ : ℕ
a : ZMod (n✝¹ + 1)
n✝ : ℕ
he : 2 * a.val = (n✝¹ + 1) * (n✝ + 1 + 1)
⊢ a = 0 ∨ 2 * a.val = n✝¹ + 1
state_after: case succ.mp.intro.succ.succ
n✝¹ : ℕ
a : ZMod (n✝¹ + 1)
n✝ : ℕ
he : 2 * a.val = (n✝¹ + 1) * (n✝ + 1 + 1)
⊢ 2 * (n✝¹ + 1) ≤ 2 * a.val

tactic: rw [he, mul_comm]
state_before: case succ.mp.intro.succ.succ
n✝¹ : ℕ
a : ZMod (n✝¹ + 1)
n✝ : ℕ
he : 2 * a.val = (n✝¹ + 1) * (n✝ + 1 + 1)
⊢ 2 * (n✝¹ + 1) ≤ 2 * a.val
state_after: case succ.mp.intro.succ.succ
n✝¹ : ℕ
a : ZMod (n✝¹ + 1)
n✝ : ℕ
he : 2 * a.val = (n✝¹ + 1) * (n✝ + 1 + 1)
⊢ (n✝¹ + 1) * 2 ≤ (n✝¹ + 1) * (n✝ + 1 + 1)

tactic: apply Nat.mul_le_mul_left
state_before: case succ.mp.intro.succ.succ
n✝¹ : ℕ
a : ZMod (n✝¹ + 1)
n✝ : ℕ
he : 2 * a.val = (n✝¹ + 1) * (n✝ + 1 + 1)
⊢ (n✝¹ + 1) * 2 ≤ (n✝¹ + 1) * (n✝ + 1 + 1)
state_after: case succ.mp.intro.succ.succ.h
n✝¹ : ℕ
a : ZMod (n✝¹ + 1)
n✝ : ℕ
he : 2 * a.val = (n✝¹ + 1) * (n✝ + 1 + 1)
⊢ 2 ≤ n✝ + 1 + 1

tactic: erw [Nat.succ_le_succ_iff, Nat.succ_le_succ_iff]
state_before: case succ.mp.intro.succ.succ.h
n✝¹ : ℕ
a : ZMod (n✝¹ + 1)
n✝ : ℕ
he : 2 * a.val = (n✝¹ + 1) * (n✝ + 1 + 1)
⊢ 2 ≤ n✝ + 1 + 1
state_after: case succ.mp.intro.succ.succ.h
n✝¹ : ℕ
a : ZMod (n✝¹ + 1)
n✝ : ℕ
he : 2 * a.val = (n✝¹ + 1) * (n✝ + 1 + 1)
⊢ 0 ≤ n✝

tactic: simp
state_before: case succ.mp.intro.succ.succ.h
n✝¹ : ℕ
a : ZMod (n✝¹ + 1)
n✝ : ℕ
he : 2 * a.val = (n✝¹ + 1) * (n✝ + 1 + 1)
⊢ 0 ≤ n✝
state_after: no goals

tactic: erw [mul_zero, mul_eq_zero] at he
state_before: case succ.mp.intro.zero
n✝ : ℕ
a : ZMod (n✝ + 1)
he : 2 * a.val = (n✝ + 1) * 0
⊢ a = 0 ∨ 2 * a.val = n✝ + 1
state_after: case succ.mp.intro.zero
n✝ : ℕ
a : ZMod (n✝ + 1)
he : 2 = 0 ∨ a.val = 0
⊢ a = 0 ∨ 2 * a.val = n✝ + 1

tactic: rcases he with (⟨⟨⟩⟩ | he)
state_before: case succ.mp.intro.zero
n✝ : ℕ
a : ZMod (n✝ + 1)
he : 2 = 0 ∨ a.val = 0
⊢ a = 0 ∨ 2 * a.val = n✝ + 1
state_after: case succ.mp.intro.zero.inr
n✝ : ℕ
a : ZMod (n✝ + 1)
he : a.val = 0
⊢ a = 0 ∨ 2 * a.val = n✝ + 1

tactic: exact Or.inl (a.val_eq_zero.1 he)
state_before: case succ.mp.intro.zero.inr
n✝ : ℕ
a : ZMod (n✝ + 1)
he : a.val = 0
⊢ a = 0 ∨ 2 * a.val = n✝ + 1
state_after: no goals

tactic: right
state_before: case succ.mp.intro.succ.zero
n✝ : ℕ
a : ZMod (n✝ + 1)
he : 2 * a.val = (n✝ + 1) * (0 + 1)
⊢ a = 0 ∨ 2 * a.val = n✝ + 1
state_after: case succ.mp.intro.succ.zero.h
n✝ : ℕ
a : ZMod (n✝ + 1)
he : 2 * a.val = (n✝ + 1) * (0 + 1)
⊢ 2 * a.val = n✝ + 1

tactic: rwa [show 0 + 1 = 1 from rfl, mul_one] at he
state_before: case succ.mp.intro.succ.zero.h
n✝ : ℕ
a : ZMod (n✝ + 1)
he : 2 * a.val = (n✝ + 1) * (0 + 1)
⊢ 2 * a.val = n✝ + 1
state_after: no goals

tactic: rintro (rfl | h)
state_before: case succ.mpr
n✝ : ℕ
a : ZMod (n✝ + 1)
⊢ a = 0 ∨ 2 * a.val = n✝ + 1 → n✝ + 1 ∣ 2 * a.val
state_after: case succ.mpr.inl
n✝ : ℕ
⊢ n✝ + 1 ∣ 2 * val 0

case succ.mpr.inr
n✝ : ℕ
a : ZMod (n✝ + 1)
h : 2 * a.val = n✝ + 1
⊢ n✝ + 1 ∣ 2 * a.val

tactic: rw [val_zero, mul_zero]
state_before: case succ.mpr.inl
n✝ : ℕ
⊢ n✝ + 1 ∣ 2 * val 0
state_after: case succ.mpr.inl
n✝ : ℕ
⊢ n✝ + 1 ∣ 0

tactic: apply dvd_zero
state_before: case succ.mpr.inl
n✝ : ℕ
⊢ n✝ + 1 ∣ 0
state_after: no goals

tactic: rw [h]
state_before: case succ.mpr.inr
n✝ : ℕ
a : ZMod (n✝ + 1)
h : 2 * a.val = n✝ + 1
⊢ n✝ + 1 ∣ 2 * a.val
state_after: no goals