-- Mathlib/AlgebraicTopology/DoldKan/Decomposition.lean
theorem decomposition_Q (n q : ℕ) :
    ((Q q).f (n + 1) : X _⦋n + 1⦌ ⟶ X _⦋n + 1⦌) =
      ∑ i ∈ Finset.filter (fun i : Fin (n + 1) => (i : ℕ) < q) Finset.univ,
        (P i).f (n + 1) ≫ X.δ i.rev.succ ≫ X.σ (Fin.rev i)

Proof state:
case neg
C : Type u_1
inst✝¹ : Category.{u_2, u_1} C
inst✝ : Preadditive C
X : SimplicialObject C
n q : ℕ
hq : (Q q).f (n + 1) = ∑ i ∈ Finset.filter (fun i => ↑i < q) Finset.univ, (P ↑i).f (n + 1) ≫ X.δ i.rev.succ ≫ X.σ i.rev
hqn : ¬q + 1 ≤ n + 1
⊢ (Q (q + 1)).f (n + 1) =
    ∑ i ∈ Finset.filter (fun i => ↑i < q + 1) Finset.univ, (P ↑i).f (n + 1) ≫ X.δ i.rev.succ ≫ X.σ i.rev

Tactic:
rw [Q_is_eventually_constant (show n + 1 ≤ q by omega), hq]

Result:
case neg
C : Type u_1
inst✝¹ : Category.{u_2, u_1} C
inst✝ : Preadditive C
X : SimplicialObject C
n q : ℕ
hq : (Q q).f (n + 1) = ∑ i ∈ Finset.filter (fun i => ↑i < q) Finset.univ, (P ↑i).f (n + 1) ≫ X.δ i.rev.succ ≫ X.σ i.rev
hqn : ¬q + 1 ≤ n + 1
⊢ ∑ i ∈ Finset.filter (fun i => ↑i < q) Finset.univ, (P ↑i).f (n + 1) ≫ X.δ i.rev.succ ≫ X.σ i.rev =
    ∑ i ∈ Finset.filter (fun i => ↑i < q + 1) Finset.univ, (P ↑i).f (n + 1) ≫ X.δ i.rev.succ ≫ X.σ i.rev

Proof state:
case pos
C : Type u_1
inst✝¹ : Category.{u_2, u_1} C
inst✝ : Preadditive C
X : SimplicialObject C
n q : ℕ
hq : (Q q).f (n + 1) = ∑ i ∈ Finset.filter (fun i => ↑i < q) Finset.univ, (P ↑i).f (n + 1) ≫ X.δ i.rev.succ ≫ X.σ i.rev
hqn : q + 1 ≤ n + 1
⊢ (Q (q + 1)).f (n + 1) =
    ∑ i ∈ Finset.filter (fun i => ↑i < q + 1) Finset.univ, (P ↑i).f (n + 1) ≫ X.δ i.rev.succ ≫ X.σ i.rev

case neg
C : Type u_1
inst✝¹ : Category.{u_2, u_1} C
inst✝ : Preadditive C
X : SimplicialObject C
n q : ℕ
hq : (Q q).f (n + 1) = ∑ i ∈ Finset.filter (fun i => ↑i < q) Finset.univ, (P ↑i).f (n + 1) ≫ X.δ i.rev.succ ≫ X.σ i.rev
hqn : ¬q + 1 ≤ n + 1
⊢ (Q (q + 1)).f (n + 1) =
    ∑ i ∈ Finset.filter (fun i => ↑i < q + 1) Finset.univ, (P ↑i).f (n + 1) ≫ X.δ i.rev.succ ≫ X.σ i.rev

Tactic:
swap

Result:
case neg
C : Type u_1
inst✝¹ : Category.{u_2, u_1} C
inst✝ : Preadditive C
X : SimplicialObject C
n q : ℕ
hq : (Q q).f (n + 1) = ∑ i ∈ Finset.filter (fun i => ↑i < q) Finset.univ, (P ↑i).f (n + 1) ≫ X.δ i.rev.succ ≫ X.σ i.rev
hqn : ¬q + 1 ≤ n + 1
⊢ (Q (q + 1)).f (n + 1) =
    ∑ i ∈ Finset.filter (fun i => ↑i < q + 1) Finset.univ, (P ↑i).f (n + 1) ≫ X.δ i.rev.succ ≫ X.σ i.rev

case pos
C : Type u_1
inst✝¹ : Category.{u_2, u_1} C
inst✝ : Preadditive C
X : SimplicialObject C
n q : ℕ
hq : (Q q).f (n + 1) = ∑ i ∈ Finset.filter (fun i => ↑i < q) Finset.univ, (P ↑i).f (n + 1) ≫ X.δ i.rev.succ ≫ X.σ i.rev
hqn : q + 1 ≤ n + 1
⊢ (Q (q + 1)).f (n + 1) =
    ∑ i ∈ Finset.filter (fun i => ↑i < q + 1) Finset.univ, (P ↑i).f (n + 1) ≫ X.δ i.rev.succ ≫ X.σ i.rev

Proof state:
case pos.intro
C : Type u_1
inst✝¹ : Category.{u_2, u_1} C
inst✝ : Preadditive C
X : SimplicialObject C
n q : ℕ
hq : (Q q).f (n + 1) = ∑ i ∈ Finset.filter (fun i => ↑i < q) Finset.univ, (P ↑i).f (n + 1) ≫ X.δ i.rev.succ ≫ X.σ i.rev
hqn : q + 1 ≤ n + 1
a : ℕ
ha : q + a = n
q' : Fin (n + 1) := ⟨q, ⋯⟩
⊢ ∑ i ∈ Finset.filter (fun i => ↑i < q + 1) Finset.univ, (P ↑i).f (n + 1) ≫ X.δ i.rev.succ ≫ X.σ i.rev =
    -(P q).f (n + 1) ≫ (Hσ q).f (n + 1) +
      ∑ i ∈ Finset.filter (fun i => ↑i < q) Finset.univ, (P ↑i).f (n + 1) ≫ X.δ i.rev.succ ≫ X.σ i.rev

Tactic:
rw [← @Finset.add_sum_erase _ _ _ _ _ _ q' (by simp [q'])]

Result:
case pos.intro
C : Type u_1
inst✝¹ : Category.{u_2, u_1} C
inst✝ : Preadditive C
X : SimplicialObject C
n q : ℕ
hq : (Q q).f (n + 1) = ∑ i ∈ Finset.filter (fun i => ↑i < q) Finset.univ, (P ↑i).f (n + 1) ≫ X.δ i.rev.succ ≫ X.σ i.rev
hqn : q + 1 ≤ n + 1
a : ℕ
ha : q + a = n
q' : Fin (n + 1) := ⟨q, ⋯⟩
⊢ (P ↑q').f (n + 1) ≫ X.δ q'.rev.succ ≫ X.σ q'.rev +
      ∑ x ∈ (Finset.filter (fun i => ↑i < q + 1) Finset.univ).erase q', (P ↑x).f (n + 1) ≫ X.δ x.rev.succ ≫ X.σ x.rev =
    -(P q).f (n + 1) ≫ (Hσ q).f (n + 1) +
      ∑ i ∈ Finset.filter (fun i => ↑i < q) Finset.univ, (P ↑i).f (n + 1) ≫ X.δ i.rev.succ ≫ X.σ i.rev

Proof state:
case neg.e_s.h.mk
C : Type u_1
inst✝¹ : Category.{u_2, u_1} C
inst✝ : Preadditive C
X : SimplicialObject C
n q : ℕ
hq : (Q q).f (n + 1) = ∑ i ∈ Finset.filter (fun i => ↑i < q) Finset.univ, (P ↑i).f (n + 1) ≫ X.δ i.rev.succ ≫ X.σ i.rev
hqn : ¬q + 1 ≤ n + 1
x : ℕ
hx : x < n + 1
⊢ ⟨x, hx⟩ ∈ Finset.filter (fun i => ↑i < q) Finset.univ ↔ ⟨x, hx⟩ ∈ Finset.filter (fun i => ↑i < q + 1) Finset.univ

Tactic:
simp only [Nat.succ_eq_add_one, Finset.mem_filter, Finset.mem_univ, true_and]

Result:
case neg.e_s.h.mk
C : Type u_1
inst✝¹ : Category.{u_2, u_1} C
inst✝ : Preadditive C
X : SimplicialObject C
n q : ℕ
hq : (Q q).f (n + 1) = ∑ i ∈ Finset.filter (fun i => ↑i < q) Finset.univ, (P ↑i).f (n + 1) ≫ X.δ i.rev.succ ≫ X.σ i.rev
hqn : ¬q + 1 ≤ n + 1
x : ℕ
hx : x < n + 1
⊢ x < q ↔ x < q + 1

Proof state:
C : Type u_1
inst✝¹ : Category.{u_2, u_1} C
inst✝ : Preadditive C
X : SimplicialObject C
n q : ℕ
hq : (Q q).f (n + 1) = ∑ i ∈ Finset.filter (fun i => ↑i < q) Finset.univ, (P ↑i).f (n + 1) ≫ X.δ i.rev.succ ≫ X.σ i.rev
hqn : ¬q + 1 ≤ n + 1
⊢ n + 1 ≤ q

Tactic:
omega

Result:
no goals

Proof state:
case pos.intro
C : Type u_1
inst✝¹ : Category.{u_2, u_1} C
inst✝ : Preadditive C
X : SimplicialObject C
n q : ℕ
hq : (Q q).f (n + 1) = ∑ i ∈ Finset.filter (fun i => ↑i < q) Finset.univ, (P ↑i).f (n + 1) ≫ X.δ i.rev.succ ≫ X.σ i.rev
hqn : q + 1 ≤ n + 1
a : ℕ
ha : q + a = n
⊢ ∑ i ∈ Finset.filter (fun i => ↑i < q + 1) Finset.univ, (P ↑i).f (n + 1) ≫ X.δ i.rev.succ ≫ X.σ i.rev =
    ∑ i ∈ Finset.filter (fun i => ↑i < q) Finset.univ, (P ↑i).f (n + 1) ≫ X.δ i.rev.succ ≫ X.σ i.rev -
      (P q).f (n + 1) ≫ (Hσ q).f (n + 1)

Tactic:
conv_rhs => rw [sub_eq_add_neg, add_comm]

Result:
case pos.intro
C : Type u_1
inst✝¹ : Category.{u_2, u_1} C
inst✝ : Preadditive C
X : SimplicialObject C
n q : ℕ
hq : (Q q).f (n + 1) = ∑ i ∈ Finset.filter (fun i => ↑i < q) Finset.univ, (P ↑i).f (n + 1) ≫ X.δ i.rev.succ ≫ X.σ i.rev
hqn : q + 1 ≤ n + 1
a : ℕ
ha : q + a = n
⊢ ∑ i ∈ Finset.filter (fun i => ↑i < q + 1) Finset.univ, (P ↑i).f (n + 1) ≫ X.δ i.rev.succ ≫ X.σ i.rev =
    -(P q).f (n + 1) ≫ (Hσ q).f (n + 1) +
      ∑ i ∈ Finset.filter (fun i => ↑i < q) Finset.univ, (P ↑i).f (n + 1) ≫ X.δ i.rev.succ ≫ X.σ i.rev

Proof state:
case pos.intro
C : Type u_1
inst✝¹ : Category.{u_2, u_1} C
inst✝ : Preadditive C
X : SimplicialObject C
n q : ℕ
hq : (Q q).f (n + 1) = ∑ i ∈ Finset.filter (fun i => ↑i < q) Finset.univ, (P ↑i).f (n + 1) ≫ X.δ i.rev.succ ≫ X.σ i.rev
hqn : q + 1 ≤ n + 1
a : ℕ
ha : q + a = n
⊢ ∑ i ∈ Finset.filter (fun i => ↑i < q + 1) Finset.univ, (P ↑i).f (n + 1) ≫ X.δ i.rev.succ ≫ X.σ i.rev =
    -(P q).f (n + 1) ≫ (Hσ q).f (n + 1) +
      ∑ i ∈ Finset.filter (fun i => ↑i < q) Finset.univ, (P ↑i).f (n + 1) ≫ X.δ i.rev.succ ≫ X.σ i.rev

Tactic:
let q' : Fin (n + 1) := ⟨q, Nat.succ_le_iff.mp hqn⟩

Result:
case pos.intro
C : Type u_1
inst✝¹ : Category.{u_2, u_1} C
inst✝ : Preadditive C
X : SimplicialObject C
n q : ℕ
hq : (Q q).f (n + 1) = ∑ i ∈ Finset.filter (fun i => ↑i < q) Finset.univ, (P ↑i).f (n + 1) ≫ X.δ i.rev.succ ≫ X.σ i.rev
hqn : q + 1 ≤ n + 1
a : ℕ
ha : q + a = n
q' : Fin (n + 1) := ⟨q, ⋯⟩
⊢ ∑ i ∈ Finset.filter (fun i => ↑i < q + 1) Finset.univ, (P ↑i).f (n + 1) ≫ X.δ i.rev.succ ≫ X.σ i.rev =
    -(P q).f (n + 1) ≫ (Hσ q).f (n + 1) +
      ∑ i ∈ Finset.filter (fun i => ↑i < q) Finset.univ, (P ↑i).f (n + 1) ≫ X.δ i.rev.succ ≫ X.σ i.rev