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

tactic: cases' n with n
state_before: n✝ : ℕ
R : Type u_1
inst✝ : Ring R
n : ℕ
a b : ZMod n
⊢ (a + b).cast = if ↑n ≤ a.cast + b.cast then a.cast + b.cast - ↑n else a.cast + b.cast
state_after: case zero
n : ℕ
R : Type u_1
inst✝ : Ring R
a b : ZMod 0
⊢ (a + b).cast = if ↑0 ≤ a.cast + b.cast then a.cast + b.cast - ↑0 else a.cast + b.cast

case succ
n✝ : ℕ
R : Type u_1
inst✝ : Ring R
n : ℕ
a b : ZMod (n + 1)
⊢ (a + b).cast = if ↑(n + 1) ≤ a.cast + b.cast then a.cast + b.cast - ↑(n + 1) else a.cast + b.cast

tactic: change Fin (n + 1) at a b
state_before: case succ
n✝ : ℕ
R : Type u_1
inst✝ : Ring R
n : ℕ
a b : ZMod (n + 1)
⊢ (a + b).cast = if ↑(n + 1) ≤ a.cast + b.cast then a.cast + b.cast - ↑(n + 1) else a.cast + b.cast
state_after: case succ
n✝ : ℕ
R : Type u_1
inst✝ : Ring R
n : ℕ
a b : Fin (n + 1)
⊢ (a + b).cast = if ↑(n + 1) ≤ cast a + cast b then cast a + cast b - ↑(n + 1) else cast a + cast b

tactic: change ((((a + b) : Fin (n + 1)) : ℕ) : ℤ) = if ((n + 1 : ℕ) : ℤ) ≤ (a : ℕ) + b then _ else _
state_before: case succ
n✝ : ℕ
R : Type u_1
inst✝ : Ring R
n : ℕ
a b : Fin (n + 1)
⊢ (a + b).cast = if ↑(n + 1) ≤ cast a + cast b then cast a + cast b - ↑(n + 1) else cast a + cast b
state_after: case succ
n✝ : ℕ
R : Type u_1
inst✝ : Ring R
n : ℕ
a b : Fin (n + 1)
⊢ ↑↑(a + b) = if ↑(n + 1) ≤ ↑↑a + ↑↑b then cast a + cast b - ↑(n + 1) else cast a + cast b

tactic: simp only [Fin.val_add_eq_ite, Int.ofNat_succ, Int.ofNat_le]
state_before: case succ
n✝ : ℕ
R : Type u_1
inst✝ : Ring R
n : ℕ
a b : Fin (n + 1)
⊢ ↑↑(a + b) = if ↑(n + 1) ≤ ↑↑a + ↑↑b then cast a + cast b - ↑(n + 1) else cast a + cast b
state_after: case succ
n✝ : ℕ
R : Type u_1
inst✝ : Ring R
n : ℕ
a b : Fin (n + 1)
⊢ ↑(if n + 1 ≤ ↑a + ↑b then ↑a + ↑b - (n + 1) else ↑a + ↑b) =
    if ↑n + 1 ≤ ↑↑a + ↑↑b then cast a + cast b - (↑n + 1) else cast a + cast b

tactic: norm_cast
state_before: case succ
n✝ : ℕ
R : Type u_1
inst✝ : Ring R
n : ℕ
a b : Fin (n + 1)
⊢ ↑(if n + 1 ≤ ↑a + ↑b then ↑a + ↑b - (n + 1) else ↑a + ↑b) =
    if ↑n + 1 ≤ ↑↑a + ↑↑b then cast a + cast b - (↑n + 1) else cast a + cast b
state_after: case succ
n✝ : ℕ
R : Type u_1
inst✝ : Ring R
n : ℕ
a b : Fin (n + 1)
⊢ ↑(if n + 1 ≤ ↑a + ↑b then ↑a + ↑b - (n + 1) else ↑a + ↑b) =
    if n + 1 ≤ ↑a + ↑b then cast a + cast b - ↑(n + 1) else cast a + cast b

tactic: split_ifs with h
state_before: case succ
n✝ : ℕ
R : Type u_1
inst✝ : Ring R
n : ℕ
a b : Fin (n + 1)
⊢ ↑(if n + 1 ≤ ↑a + ↑b then ↑a + ↑b - (n + 1) else ↑a + ↑b) =
    if n + 1 ≤ ↑a + ↑b then cast a + cast b - ↑(n + 1) else cast a + cast b
state_after: case pos
n✝ : ℕ
R : Type u_1
inst✝ : Ring R
n : ℕ
a b : Fin (n + 1)
h : n + 1 ≤ ↑a + ↑b
⊢ ↑(↑a + ↑b - (n + 1)) = cast a + cast b - ↑(n + 1)

case neg
n✝ : ℕ
R : Type u_1
inst✝ : Ring R
n : ℕ
a b : Fin (n + 1)
h : ¬n + 1 ≤ ↑a + ↑b
⊢ ↑(↑a + ↑b) = cast a + cast b

tactic: simp
state_before: case zero
n : ℕ
R : Type u_1
inst✝ : Ring R
a b : ZMod 0
⊢ (a + b).cast = if ↑0 ≤ a.cast + b.cast then a.cast + b.cast - ↑0 else a.cast + b.cast
state_after: case zero
n : ℕ
R : Type u_1
inst✝ : Ring R
a b : ZMod 0
⊢ (a + b).cast = a.cast + b.cast

tactic: rfl
state_before: case zero
n : ℕ
R : Type u_1
inst✝ : Ring R
a b : ZMod 0
⊢ (a + b).cast = a.cast + b.cast
state_after: no goals

tactic: rw [Nat.cast_sub h]
state_before: case pos
n✝ : ℕ
R : Type u_1
inst✝ : Ring R
n : ℕ
a b : Fin (n + 1)
h : n + 1 ≤ ↑a + ↑b
⊢ ↑(↑a + ↑b - (n + 1)) = cast a + cast b - ↑(n + 1)
state_after: case pos
n✝ : ℕ
R : Type u_1
inst✝ : Ring R
n : ℕ
a b : Fin (n + 1)
h : n + 1 ≤ ↑a + ↑b
⊢ ↑(↑a + ↑b) - ↑(n + 1) = cast a + cast b - ↑(n + 1)

tactic: congr
state_before: case pos
n✝ : ℕ
R : Type u_1
inst✝ : Ring R
n : ℕ
a b : Fin (n + 1)
h : n + 1 ≤ ↑a + ↑b
⊢ ↑(↑a + ↑b) - ↑(n + 1) = cast a + cast b - ↑(n + 1)
state_after: no goals

tactic: rfl
state_before: case neg
n✝ : ℕ
R : Type u_1
inst✝ : Ring R
n : ℕ
a b : Fin (n + 1)
h : ¬n + 1 ≤ ↑a + ↑b
⊢ ↑(↑a + ↑b) = cast a + cast b
state_after: no goals