-- Lean 4 proof step from Mathlib.GroupTheory.CoprodI (goal)
Goal:
ι : Type u_1
M : ι → Type u_2
inst : (i : ι) → Monoid (M i)
inst_1 : DecidableEq ι
inst_2 : (i : ι) → DecidableEq (M i)
i j : ι
m : M i
tail : Word M
ih :
  Membership.mem (γ := List ((i : ι) × M i))
      (toList (M := M)
        (Pair.tail (M := M) (i := j)
          (↑(consRecOn (M := M) (motive := fun (x : Word M) ↦ { p : Pair M j // rcons (M := M) p = x }) tail
                (Subtype.mk (p := fun (p : Pair M j) ↦ rcons (M := M) p = empty (M := M))
                  (Pair.mk (M := M) 1 (empty (M := M)) ⋯) ⋯)
                fun (j_1 : ι) (m : M j_1) (w : Word M) (h1 : ¬w.fstIdx (M := M) = some j_1) (h2 : ¬m = 1)
                  (x : { p : Pair M j // rcons (M := M) p = w }) ↦
                if ij : j = j_1 then
                  Subtype.mk (p := fun (p : Pair M j) ↦ rcons (M := M) p = cons (M := M) m w h1 h2)
                    (Pair.mk (M := M) (Eq.rec (motive := fun (x : ι) (h : j_1 = x) ↦ M x) m ⋯) w ⋯) ⋯
                else
                  Subtype.mk (p := fun (p : Pair M j) ↦ rcons (M := M) p = cons (M := M) m w h1 h2)
                    (Pair.mk (M := M) 1 (cons (M := M) m w h1 h2) ⋯) ⋯) :
            Pair M j)))
      (Sigma.mk (β := fun (i : ι) ↦ M i) i m) ↔
    Sigma.mk (β := fun (i : ι) ↦ M i) i m ∈ tail.toList (M := M).tail ∨
      ¬i = j ∧ ∃ (h : ¬tail.toList (M := M) = []), tail.toList (M := M).head h = Sigma.mk (β := fun (i : ι) ↦ M i) i m
g : M j
h1 : tail.fstIdx (M := M) ≠ some j
h2 : g ≠ 1
pos :
  ∀ (hij : j = i),
    Sigma.mk (β := fun (i : ι) ↦ M i) i m ∈
        (↑(Subtype.mk (p := fun (p : Pair M j) ↦ rcons (M := M) p = cons (M := M) g tail h1 h2)
                      (Pair.mk (M := M) (Eq.rec (motive := fun (x : ι) (h : j = x) ↦ M x) g ⋯) tail ⋯) ⋯) :
                  Pair M j).tail
              (M := M).toList
          (M := M) ↔
      Sigma.mk (β := fun (i : ι) ↦ M i) i m ∈ (cons (M := M) g tail h1 h2).toList (M := M).tail ∨
        ¬i = j ∧
          ∃ (h : ¬(cons (M := M) g tail h1 h2).toList (M := M) = []),
            (cons (M := M) g tail h1 h2).toList (M := M).head h = Sigma.mk (β := fun (i : ι) ↦ M i) i m
⊢ Sigma.mk (β := fun (i : ι) ↦ M i) i m ∈
      (↑(Subtype.mk (p := fun (p : Pair M j) ↦ rcons (M := M) p = cons (M := M) g tail h1 h2)
                    (Pair.mk (M := M) (Eq.rec (motive := fun (x : ι) (h : j = x) ↦ M x) g ⋯) tail ⋯) ⋯) :
                Pair M j).tail
            (M := M).toList
        (M := M) ↔
    Sigma.mk (β := fun (i : ι) ↦ M i) i m ∈ (cons (M := M) g tail h1 h2).toList (M := M).tail ∨
      ¬i = j ∧
        ∃ (h : ¬(cons (M := M) g tail h1 h2).toList (M := M) = []),
          (cons (M := M) g tail h1 h2).toList (M := M).head h = Sigma.mk (β := fun (i : ι) ↦ M i) i m
have neg : ∀ (hij : ¬j = i),
  Sigma.mk (β := fun (i : ι) ↦ M i) i m ∈
      (↑(Subtype.mk (p := fun (p : Pair M j) ↦ rcons (M := M) p = cons (M := M) g tail h1 h2)
                    (Pair.mk (M := M) (Eq.rec (motive := fun (x : ι) (h : j = x) ↦ M x) g sorry) tail sorry) sorry) :
                Pair M j).tail
            (M := M).toList
        (M := M) ↔
    Sigma.mk (β := fun (i : ι) ↦ M i) i m ∈ (cons (M := M) g tail h1 h2).toList (M := M).tail ∨
      ¬i = j ∧
        ∃ (h : ¬(cons (M := M) g tail h1 h2).toList (M := M) = []),
          (cons (M := M) g tail h1 h2).toList (M := M).head h = Sigma.mk (β := fun (i : ι) ↦ M i) i m
Tactic: by_cases hij : j = i