-- Mathlib/GroupTheory/CoprodI.lean
theorem equivPair_head {i : ι} {w : Word M} :
    (equivPair i w).head =
      if h : ∃ (h : w.toList ≠ []), (w.toList.head h).1 = i
      then h.snd ▸ (w.toList.head h.1).2
      else 1

Proof state:
case h_cons
ι : Type u_1
M : ι → Type u_2
inst✝² : (i : ι) → Monoid (M i)
inst✝¹ : DecidableEq ι
inst✝ : (i : ι) → DecidableEq (M i)
i head : ι
m✝ : M head
w✝ : Word M
h1✝ : w✝.fstIdx ≠ some head
h2✝ : m✝ ≠ 1
a✝ :
  ({
          toFun := fun w =>
            ↑(consRecOn w ⟨{ head := 1, tail := empty, fstIdx_ne := ⋯ }, ⋯⟩ fun j m w h1 h2 x =>
                if ij : i = j then ⟨{ head := ⋯ ▸ m, tail := w, fstIdx_ne := ⋯ }, ⋯⟩
                else ⟨{ head := 1, tail := cons m w h1 h2, fstIdx_ne := ⋯ }, ⋯⟩),
          invFun := rcons, left_inv := ⋯, right_inv := ⋯ }
        w✝).head =
    if h : ∃ (h : w✝.toList ≠ []), (w✝.toList.head h).fst = i then ⋯ ▸ (w✝.toList.head ⋯).snd else 1
⊢ ({
          toFun := fun w =>
            ↑(consRecOn w ⟨{ head := 1, tail := empty, fstIdx_ne := ⋯ }, ⋯⟩ fun j m w h1 h2 x =>
                if ij : i = j then ⟨{ head := ⋯ ▸ m, tail := w, fstIdx_ne := ⋯ }, ⋯⟩
                else ⟨{ head := 1, tail := cons m w h1 h2, fstIdx_ne := ⋯ }, ⋯⟩),
          invFun := rcons, left_inv := ⋯, right_inv := ⋯ }
        (cons m✝ w✝ h1✝ h2✝)).head =
    if h : ∃ (h : (cons m✝ w✝ h1✝ h2✝).toList ≠ []), ((cons m✝ w✝ h1✝ h2✝).toList.head h).fst = i then
      ⋯ ▸ ((cons m✝ w✝ h1✝ h2✝).toList.head ⋯).snd
    else 1

Tactic:
by_cases hi : i = head

Result:
case pos
ι : Type u_1
M : ι → Type u_2
inst✝² : (i : ι) → Monoid (M i)
inst✝¹ : DecidableEq ι
inst✝ : (i : ι) → DecidableEq (M i)
i head : ι
m✝ : M head
w✝ : Word M
h1✝ : w✝.fstIdx ≠ some head
h2✝ : m✝ ≠ 1
a✝ :
  ({
          toFun := fun w =>
            ↑(consRecOn w ⟨{ head := 1, tail := empty, fstIdx_ne := ⋯ }, ⋯⟩ fun j m w h1 h2 x =>
                if ij : i = j then ⟨{ head := ⋯ ▸ m, tail := w, fstIdx_ne := ⋯ }, ⋯⟩
                else ⟨{ head := 1, tail := cons m w h1 h2, fstIdx_ne := ⋯ }, ⋯⟩),
          invFun := rcons, left_inv := ⋯, right_inv := ⋯ }
        w✝).head =
    if h : ∃ (h : w✝.toList ≠ []), (w✝.toList.head h).fst = i then ⋯ ▸ (w✝.toList.head ⋯).snd else 1
hi : i = head
⊢ ({
          toFun := fun w =>
            ↑(consRecOn w ⟨{ head := 1, tail := empty, fstIdx_ne := ⋯ }, ⋯⟩ fun j m w h1 h2 x =>
                if ij : i = j then ⟨{ head := ⋯ ▸ m, tail := w, fstIdx_ne := ⋯ }, ⋯⟩
                else ⟨{ head := 1, tail := cons m w h1 h2, fstIdx_ne := ⋯ }, ⋯⟩),
          invFun := rcons, left_inv := ⋯, right_inv := ⋯ }
        (cons m✝ w✝ h1✝ h2✝)).head =
    if h : ∃ (h : (cons m✝ w✝ h1✝ h2✝).toList ≠ []), ((cons m✝ w✝ h1✝ h2✝).toList.head h).fst = i then
      ⋯ ▸ ((cons m✝ w✝ h1✝ h2✝).toList.head ⋯).snd
    else 1

case neg
ι : Type u_1
M : ι → Type u_2
inst✝² : (i : ι) → Monoid (M i)
inst✝¹ : DecidableEq ι
inst✝ : (i : ι) → DecidableEq (M i)
i head : ι
m✝ : M head
w✝ : Word M
h1✝ : w✝.fstIdx ≠ some head
h2✝ : m✝ ≠ 1
a✝ :
  ({
          toFun := fun w =>
            ↑(consRecOn w ⟨{ head := 1, tail := empty, fstIdx_ne := ⋯ }, ⋯⟩ fun j m w h1 h2 x =>
                if ij : i = j then ⟨{ head := ⋯ ▸ m, tail := w, fstIdx_ne := ⋯ }, ⋯⟩
                else ⟨{ head := 1, tail := cons m w h1 h2, fstIdx_ne := ⋯ }, ⋯⟩),
          invFun := rcons, left_inv := ⋯, right_inv := ⋯ }
        w✝).head =
    if h : ∃ (h : w✝.toList ≠ []), (w✝.toList.head h).fst = i then ⋯ ▸ (w✝.toList.head ⋯).snd else 1
hi : ¬i = head
⊢ ({
          toFun := fun w =>
            ↑(consRecOn w ⟨{ head := 1, tail := empty, fstIdx_ne := ⋯ }, ⋯⟩ fun j m w h1 h2 x =>
                if ij : i = j then ⟨{ head := ⋯ ▸ m, tail := w, fstIdx_ne := ⋯ }, ⋯⟩
                else ⟨{ head := 1, tail := cons m w h1 h2, fstIdx_ne := ⋯ }, ⋯⟩),
          invFun := rcons, left_inv := ⋯, right_inv := ⋯ }
        (cons m✝ w✝ h1✝ h2✝)).head =
    if h : ∃ (h : (cons m✝ w✝ h1✝ h2✝).toList ≠ []), ((cons m✝ w✝ h1✝ h2✝).toList.head h).fst = i then
      ⋯ ▸ ((cons m✝ w✝ h1✝ h2✝).toList.head ⋯).snd
    else 1

Proof state:
case pos
ι : Type u_1
M : ι → Type u_2
inst✝² : (i : ι) → Monoid (M i)
inst✝¹ : DecidableEq ι
inst✝ : (i : ι) → DecidableEq (M i)
i : ι
w✝ : Word M
a✝ :
  ({
          toFun := fun w =>
            ↑(consRecOn w ⟨{ head := 1, tail := empty, fstIdx_ne := ⋯ }, ⋯⟩ fun j m w h1 h2 x =>
                if ij : i = j then ⟨{ head := ⋯ ▸ m, tail := w, fstIdx_ne := ⋯ }, ⋯⟩
                else ⟨{ head := 1, tail := cons m w h1 h2, fstIdx_ne := ⋯ }, ⋯⟩),
          invFun := rcons, left_inv := ⋯, right_inv := ⋯ }
        w✝).head =
    if h : ∃ (h : w✝.toList ≠ []), (w✝.toList.head h).fst = i then ⋯ ▸ (w✝.toList.head ⋯).snd else 1
m✝ : M i
h1✝ : w✝.fstIdx ≠ some i
h2✝ : m✝ ≠ 1
⊢ ({
          toFun := fun w =>
            ↑(consRecOn w ⟨{ head := 1, tail := empty, fstIdx_ne := ⋯ }, ⋯⟩ fun j m w h1 h2 x =>
                if ij : i = j then ⟨{ head := ⋯ ▸ m, tail := w, fstIdx_ne := ⋯ }, ⋯⟩
                else ⟨{ head := 1, tail := cons m w h1 h2, fstIdx_ne := ⋯ }, ⋯⟩),
          invFun := rcons, left_inv := ⋯, right_inv := ⋯ }
        (cons m✝ w✝ h1✝ h2✝)).head =
    if h : ∃ (h : (cons m✝ w✝ h1✝ h2✝).toList ≠ []), ((cons m✝ w✝ h1✝ h2✝).toList.head h).fst = i then
      ⋯ ▸ ((cons m✝ w✝ h1✝ h2✝).toList.head ⋯).snd
    else 1

Tactic:
simp

Result:
no goals

Proof state:
case pos
ι : Type u_1
M : ι → Type u_2
inst✝² : (i : ι) → Monoid (M i)
inst✝¹ : DecidableEq ι
inst✝ : (i : ι) → DecidableEq (M i)
i head : ι
m✝ : M head
w✝ : Word M
h1✝ : w✝.fstIdx ≠ some head
h2✝ : m✝ ≠ 1
a✝ :
  ({
          toFun := fun w =>
            ↑(consRecOn w ⟨{ head := 1, tail := empty, fstIdx_ne := ⋯ }, ⋯⟩ fun j m w h1 h2 x =>
                if ij : i = j then ⟨{ head := ⋯ ▸ m, tail := w, fstIdx_ne := ⋯ }, ⋯⟩
                else ⟨{ head := 1, tail := cons m w h1 h2, fstIdx_ne := ⋯ }, ⋯⟩),
          invFun := rcons, left_inv := ⋯, right_inv := ⋯ }
        w✝).head =
    if h : ∃ (h : w✝.toList ≠ []), (w✝.toList.head h).fst = i then ⋯ ▸ (w✝.toList.head ⋯).snd else 1
hi : i = head
⊢ ({
          toFun := fun w =>
            ↑(consRecOn w ⟨{ head := 1, tail := empty, fstIdx_ne := ⋯ }, ⋯⟩ fun j m w h1 h2 x =>
                if ij : i = j then ⟨{ head := ⋯ ▸ m, tail := w, fstIdx_ne := ⋯ }, ⋯⟩
                else ⟨{ head := 1, tail := cons m w h1 h2, fstIdx_ne := ⋯ }, ⋯⟩),
          invFun := rcons, left_inv := ⋯, right_inv := ⋯ }
        (cons m✝ w✝ h1✝ h2✝)).head =
    if h : ∃ (h : (cons m✝ w✝ h1✝ h2✝).toList ≠ []), ((cons m✝ w✝ h1✝ h2✝).toList.head h).fst = i then
      ⋯ ▸ ((cons m✝ w✝ h1✝ h2✝).toList.head ⋯).snd
    else 1

Tactic:
subst hi

Result:
case pos
ι : Type u_1
M : ι → Type u_2
inst✝² : (i : ι) → Monoid (M i)
inst✝¹ : DecidableEq ι
inst✝ : (i : ι) → DecidableEq (M i)
i : ι
w✝ : Word M
a✝ :
  ({
          toFun := fun w =>
            ↑(consRecOn w ⟨{ head := 1, tail := empty, fstIdx_ne := ⋯ }, ⋯⟩ fun j m w h1 h2 x =>
                if ij : i = j then ⟨{ head := ⋯ ▸ m, tail := w, fstIdx_ne := ⋯ }, ⋯⟩
                else ⟨{ head := 1, tail := cons m w h1 h2, fstIdx_ne := ⋯ }, ⋯⟩),
          invFun := rcons, left_inv := ⋯, right_inv := ⋯ }
        w✝).head =
    if h : ∃ (h : w✝.toList ≠ []), (w✝.toList.head h).fst = i then ⋯ ▸ (w✝.toList.head ⋯).snd else 1
m✝ : M i
h1✝ : w✝.fstIdx ≠ some i
h2✝ : m✝ ≠ 1
⊢ ({
          toFun := fun w =>
            ↑(consRecOn w ⟨{ head := 1, tail := empty, fstIdx_ne := ⋯ }, ⋯⟩ fun j m w h1 h2 x =>
                if ij : i = j then ⟨{ head := ⋯ ▸ m, tail := w, fstIdx_ne := ⋯ }, ⋯⟩
                else ⟨{ head := 1, tail := cons m w h1 h2, fstIdx_ne := ⋯ }, ⋯⟩),
          invFun := rcons, left_inv := ⋯, right_inv := ⋯ }
        (cons m✝ w✝ h1✝ h2✝)).head =
    if h : ∃ (h : (cons m✝ w✝ h1✝ h2✝).toList ≠ []), ((cons m✝ w✝ h1✝ h2✝).toList.head h).fst = i then
      ⋯ ▸ ((cons m✝ w✝ h1✝ h2✝).toList.head ⋯).snd
    else 1