l3lab/ntp-mathlib huggingface dataset:
/-- The functor that sends each category to the quotient space of its objects up to an isomorphism.
-/
def isomorphismClasses : Cat.{v, u} ⥤ Type u where
  obj C := Quotient (isIsomorphicSetoid C.α)
  map {C D} F := Quot.map F.obj fun X Y ⟨f⟩ => ⟨F.mapIso f⟩
  map_id {C} := by  -- Porting note: this used to be `tidy`
    dsimp; apply funext; intro x
    apply x.recOn  -- Porting note: `induction x` not working yet
    · intro _ _ p
      simp only [types_id_apply]
    · intro _
      rfl
  map_comp {C D E} f g := by -- Porting note(s): idem
    dsimp; apply funext; intro x
    apply x.recOn
    · intro _ _ _
      

Proof state:
case h.h
C D E : Cat
f : C ⟶ D
g : D ⟶ E
x : Quot Setoid.r
a✝ b✝ : ↑C
p✝ : Setoid.r a✝ b✝
⊢ (_ :
      Quot.map (f ≫ g).obj (_ : ∀ (X Y : ↑C), Setoid.r X Y → Setoid.r (g.obj (f.obj X)) (g.obj (f.obj Y)))
          (Quot.mk Setoid.r b✝) =
        (Quot.map f.obj (_ : ∀ (X Y : ↑C), Setoid.r X Y → Setoid.r (f.obj X) (f.obj Y)) ≫
            Quot.map g.obj (_ : ∀ (X Y : ↑D), Setoid.r X Y → Setoid.r (g.obj X) (g.obj Y)))
          (Quot.mk Setoid.r b✝)) =
    (_ : ?m.1373 (Quot.mk Setoid.r b✝))

Next tactic:
simp only [types_id_apply]
/-- The functor that sends each category to the quotient space of its objects up to an isomorphism.
-/
def isomorphismClasses : Cat.{v, u} ⥤ Type u where
  obj C := Quotient (isIsomorphicSetoid C.α)
  map {C D} F := Quot.map F.obj fun X Y ⟨f⟩ => ⟨F.mapIso f⟩
  map_id {C} := by  -- Porting note: this used to be `tidy`
    dsimp; apply funext; intro x
    apply x.recOn  -- Porting note: `induction x` not working yet
    · intro _ _ p
      simp only [types_id_apply]
    · intro _
      rfl
  map_comp {C D E} f g := by -- Porting note(s): idem
    dsimp; apply funext; intro x
    apply x.recOn
    · intro _ _ _
      simp only [types_id_apply]
    · 

Proof state:
case h.f
C D E : Cat
f : C ⟶ D
g : D ⟶ E
x : Quot Setoid.r
⊢ ∀ (a : ↑C),
    Quot.map (f ≫ g).obj (_ : ∀ (X Y : ↑C), Setoid.r X Y → Setoid.r (g.obj (f.obj X)) (g.obj (f.obj Y)))
        (Quot.mk Setoid.r a) =
      (Quot.map f.obj (_ : ∀ (X Y : ↑C), Setoid.r X Y → Setoid.r (f.obj X) (f.obj Y)) ≫
          Quot.map g.obj (_ : ∀ (X Y : ↑D), Setoid.r X Y → Setoid.r (g.obj X) (g.obj Y)))
        (Quot.mk Setoid.r a)

Next tactic:
intro _
/-- The functor that sends each category to the quotient space of its objects up to an isomorphism.
-/
def isomorphismClasses : Cat.{v, u} ⥤ Type u where
  obj C := Quotient (isIsomorphicSetoid C.α)
  map {C D} F := Quot.map F.obj fun X Y ⟨f⟩ => ⟨F.mapIso f⟩
  map_id {C} := by  -- Porting note: this used to be `tidy`
    dsimp; apply funext; intro x
    apply x.recOn  -- Porting note: `induction x` not working yet
    · intro _ _ p
      simp only [types_id_apply]
    · intro _
      rfl
  map_comp {C D E} f g := by -- Porting note(s): idem
    dsimp; apply funext; intro x
    apply x.recOn
    · intro _ _ _
      simp only [types_id_apply]
    · intro _
      

Proof state:
case h.f
C D E : Cat
f : C ⟶ D
g : D ⟶ E
x : Quot Setoid.r
a✝ : ↑C
⊢ Quot.map (f ≫ g).obj (_ : ∀ (X Y : ↑C), Setoid.r X Y → Setoid.r (g.obj (f.obj X)) (g.obj (f.obj Y)))
      (Quot.mk Setoid.r a✝) =
    (Quot.map f.obj (_ : ∀ (X Y : ↑C), Setoid.r X Y → Setoid.r (f.obj X) (f.obj Y)) ≫
        Quot.map g.obj (_ : ∀ (X Y : ↑D), Setoid.r X Y → Setoid.r (g.obj X) (g.obj Y)))
      (Quot.mk Setoid.r a✝)

Next tactic:
rfl
theorem sum_card_bipartiteAbove_eq_sum_card_bipartiteBelow [∀ a b, Decidable (r a b)] :
    (∑ a in s, (t.bipartiteAbove r a).card) = ∑ b in t, (s.bipartiteBelow r b).card := by
  

Proof state:
α : Type u_1
β : Type u_2
r : α → β → Prop
s : Finset α
t : Finset β
a a' : α
b b' : β
inst✝² : DecidablePred (r a)
inst✝¹ : (a : α) → Decidable (r a b)
m n : ℕ
inst✝ : (a : α) → (b : β) → Decidable (r a b)
⊢ ∑ a in s, card (bipartiteAbove r t a) = ∑ b in t, card (bipartiteBelow r s b)

Next tactic:
simp_rw [card_eq_sum_ones, bipartiteAbove, bipartiteBelow, sum_filter]
theorem sum_card_bipartiteAbove_eq_sum_card_bipartiteBelow [∀ a b, Decidable (r a b)] :
    (∑ a in s, (t.bipartiteAbove r a).card) = ∑ b in t, (s.bipartiteBelow r b).card := by
  simp_rw [card_eq_sum_ones, bipartiteAbove, bipartiteBelow, sum_filter]
  

Proof state:
α : Type u_1
β : Type u_2
r : α → β → Prop
s : Finset α
t : Finset β
a a' : α
b b' : β
inst✝² : DecidablePred (r a)
inst✝¹ : (a : α) → Decidable (r a b)
m n : ℕ
inst✝ : (a : α) → (b : β) → Decidable (r a b)
⊢ (∑ x in s, ∑ a in t, if r x a then 1 else 0) = ∑ x in t, ∑ a in s, if r a x then 1 else 0

Next tactic:
exact sum_comm
theorem card_le_card_of_forall_subsingleton (hs : ∀ a ∈ s, ∃ b, b ∈ t ∧ r a b)
    (ht : ∀ b ∈ t, ({ a ∈ s | r a b } : Set α).Subsingleton) : s.card ≤ t.card := by
  

Proof state:
α : Type u_1
β : Type u_2
r : α → β → Prop
s : Finset α
t : Finset β
a a' : α
b b' : β
inst✝¹ : DecidablePred (r a)
inst✝ : (a : α) → Decidable (r a b)
m n : ℕ
hs : ∀ a ∈ s, ∃ b ∈ t, r a b
ht : ∀ b ∈ t, Set.Subsingleton {a | a ∈ s ∧ r a b}
⊢ card s ≤ card t

Next tactic:
classical
    rw [← mul_one s.card, ← mul_one t.card]
    exact card_mul_le_card_mul r
      (fun a h ↦ card_pos.2 (by
        rw [← coe_nonempty, coe_bipartiteAbove]
        exact hs _ h : (t.bipartiteAbove r a).Nonempty))
      (fun b h ↦ card_le_one.2 (by
        simp_rw [mem_bipartiteBelow]
        exact ht _ h))
theorem card_le_card_of_forall_subsingleton (hs : ∀ a ∈ s, ∃ b, b ∈ t ∧ r a b)
    (ht : ∀ b ∈ t, ({ a ∈ s | r a b } : Set α).Subsingleton) : s.card ≤ t.card := by
  classical
    

Proof state:
α : Type u_1
β : Type u_2
r : α → β → Prop
s : Finset α
t : Finset β
a a' : α
b b' : β
inst✝¹ : DecidablePred (r a)
inst✝ : (a : α) → Decidable (r a b)
m n : ℕ
hs : ∀ a ∈ s, ∃ b ∈ t, r a b
ht : ∀ b ∈ t, Set.Subsingleton {a | a ∈ s ∧ r a b}
⊢ card s ≤ card t

Next tactic:
rw [← mul_one s.card, ← mul_one t.card]
theorem card_le_card_of_forall_subsingleton (hs : ∀ a ∈ s, ∃ b, b ∈ t ∧ r a b)
    (ht : ∀ b ∈ t, ({ a ∈ s | r a b } : Set α).Subsingleton) : s.card ≤ t.card := by
  classical
    rw [← mul_one s.card, ← mul_one t.card]
    

Proof state:
α : Type u_1
β : Type u_2
r : α → β → Prop
s : Finset α
t : Finset β
a a' : α
b b' : β
inst✝¹ : DecidablePred (r a)
inst✝ : (a : α) → Decidable (r a b)
m n : ℕ
hs : ∀ a ∈ s, ∃ b ∈ t, r a b
ht : ∀ b ∈ t, Set.Subsingleton {a | a ∈ s ∧ r a b}
⊢ card s * 1 ≤ card t * 1

Next tactic:
exact card_mul_le_card_mul r
      (fun a h ↦ card_pos.2 (by
        rw [← coe_nonempty, coe_bipartiteAbove]
        exact hs _ h : (t.bipartiteAbove r a).Nonempty))
      (fun b h ↦ card_le_one.2 (by
        simp_rw [mem_bipartiteBelow]
        exact ht _ h))
theorem card_le_card_of_forall_subsingleton (hs : ∀ a ∈ s, ∃ b, b ∈ t ∧ r a b)
    (ht : ∀ b ∈ t, ({ a ∈ s | r a b } : Set α).Subsingleton) : s.card ≤ t.card := by
  classical
    rw [← mul_one s.card, ← mul_one t.card]
    exact card_mul_le_card_mul r
      (fun a h ↦ card_pos.2 (by
        

Proof state:
α : Type u_1
β : Type u_2
r : α → β → Prop
s : Finset α
t : Finset β
a✝ a' : α
b b' : β
inst✝¹ : DecidablePred (r a✝)
inst✝ : (a : α) → Decidable (r a b)
m n : ℕ
hs : ∀ a ∈ s, ∃ b ∈ t, r a b
ht : ∀ b ∈ t, Set.Subsingleton {a | a ∈ s ∧ r a b}
a : α
h : a ∈ s
⊢ Finset.Nonempty (bipartiteAbove r t a)

Next tactic:
rw [← coe_nonempty, coe_bipartiteAbove]
theorem card_le_card_of_forall_subsingleton (hs : ∀ a ∈ s, ∃ b, b ∈ t ∧ r a b)
    (ht : ∀ b ∈ t, ({ a ∈ s | r a b } : Set α).Subsingleton) : s.card ≤ t.card := by
  classical
    rw [← mul_one s.card, ← mul_one t.card]
    exact card_mul_le_card_mul r
      (fun a h ↦ card_pos.2 (by
        rw [← coe_nonempty, coe_bipartiteAbove]
        

Proof state:
α : Type u_1
β : Type u_2
r : α → β → Prop
s : Finset α
t : Finset β
a✝ a' : α
b b' : β
inst✝¹ : DecidablePred (r a✝)
inst✝ : (a : α) → Decidable (r a b)
m n : ℕ
hs : ∀ a ∈ s, ∃ b ∈ t, r a b
ht : ∀ b ∈ t, Set.Subsingleton {a | a ∈ s ∧ r a b}
a : α
h : a ∈ s
⊢ Set.Nonempty {b | b ∈ t ∧ r a b}

Next tactic:
exact hs _ h
theorem card_le_card_of_forall_subsingleton (hs : ∀ a ∈ s, ∃ b, b ∈ t ∧ r a b)
    (ht : ∀ b ∈ t, ({ a ∈ s | r a b } : Set α).Subsingleton) : s.card ≤ t.card := by
  classical
    rw [← mul_one s.card, ← mul_one t.card]
    exact card_mul_le_card_mul r
      (fun a h ↦ card_pos.2 (by
        rw [← coe_nonempty, coe_bipartiteAbove]
        exact hs _ h : (t.bipartiteAbove r a).Nonempty))
      (fun b h ↦ card_le_one.2 (by
        

Proof state:
α : Type u_1
β : Type u_2
r : α → β → Prop
s : Finset α
t : Finset β
a a' : α
b✝ b' : β
inst✝¹ : DecidablePred (r a)
inst✝ : (a : α) → Decidable (r a b✝)
m n : ℕ
hs : ∀ a ∈ s, ∃ b ∈ t, r a b
ht : ∀ b ∈ t, Set.Subsingleton {a | a ∈ s ∧ r a b}
b : β
h : b ∈ t
⊢ ∀ a ∈ bipartiteBelow r s b, ∀ b_1 ∈ bipartiteBelow r s b, a = b_1

Next tactic:
simp_rw [mem_bipartiteBelow]
theorem card_le_card_of_forall_subsingleton (hs : ∀ a ∈ s, ∃ b, b ∈ t ∧ r a b)
    (ht : ∀ b ∈ t, ({ a ∈ s | r a b } : Set α).Subsingleton) : s.card ≤ t.card := by
  classical
    rw [← mul_one s.card, ← mul_one t.card]
    exact card_mul_le_card_mul r
      (fun a h ↦ card_pos.2 (by
        rw [← coe_nonempty, coe_bipartiteAbove]
        exact hs _ h : (t.bipartiteAbove r a).Nonempty))
      (fun b h ↦ card_le_one.2 (by
        simp_rw [mem_bipartiteBelow]
        

Proof state:
α : Type u_1
β : Type u_2
r : α → β → Prop
s : Finset α
t : Finset β
a a' : α
b✝ b' : β
inst✝¹ : DecidablePred (r a)
inst✝ : (a : α) → Decidable (r a b✝)
m n : ℕ
hs : ∀ a ∈ s, ∃ b ∈ t, r a b
ht : ∀ b ∈ t, Set.Subsingleton {a | a ∈ s ∧ r a b}
b : β
h : b ∈ t
⊢ ∀ (a : α), a ∈ s ∧ r a b → ∀ (b_1 : α), b_1 ∈ s ∧ r b_1 b → a = b_1

Next tactic:
exact ht _ h
theorem card_le_card_of_leftTotal_unique (h₁ : LeftTotal r) (h₂ : LeftUnique r) :
    Fintype.card α ≤ Fintype.card β :=
  card_le_card_of_forall_subsingleton r (by 

Proof state:
α : Type u_1
β : Type u_2
inst✝¹ : Fintype α
inst✝ : Fintype β
r : α → β → Prop
h₁ : LeftTotal r
h₂ : LeftUnique r
⊢ ∀ a ∈ univ, ∃ b ∈ univ, r a b

Next tactic:
simpa using h₁
theorem card_le_card_of_rightTotal_unique (h₁ : RightTotal r) (h₂ : RightUnique r) :
    Fintype.card β ≤ Fintype.card α :=
  card_le_card_of_forall_subsingleton' r (by 

Proof state:
α : Type u_1
β : Type u_2
inst✝¹ : Fintype α
inst✝ : Fintype β
r : α → β → Prop
h₁ : RightTotal r
h₂ : RightUnique r
⊢ ∀ b ∈ univ, ∃ a ∈ univ, r a b

Next tactic:
simpa using h₁
/-- In each positive degree, this lemma decomposes the idempotent endomorphism
`Q q` as a sum of morphisms which are postcompositions with suitable degeneracies.
As `Q q` is the complement projection to `P q`, this implies that in the case of
simplicial abelian groups, any $(n+1)$-simplex $x$ can be decomposed as
$x = x' + \sum (i=0}^{q-1} σ_{n-i}(y_i)$ where $x'$ is in the image of `P q` and
the $y_i$ are in degree $n$. -/
theorem decomposition_Q (n q : ℕ) :
    ((Q q).f (n + 1) : X _[n + 1] ⟶ X _[n + 1]) =
      ∑ i : Fin (n + 1) in Finset.filter (fun i : Fin (n + 1) => (i : ℕ) < q) Finset.univ,
        (P i).f (n + 1) ≫ X.δ i.rev.succ ≫ X.σ (Fin.rev i) := by
  

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

Next tactic:
induction' q with q hq
/-- In each positive degree, this lemma decomposes the idempotent endomorphism
`Q q` as a sum of morphisms which are postcompositions with suitable degeneracies.
As `Q q` is the complement projection to `P q`, this implies that in the case of
simplicial abelian groups, any $(n+1)$-simplex $x$ can be decomposed as
$x = x' + \sum (i=0}^{q-1} σ_{n-i}(y_i)$ where $x'$ is in the image of `P q` and
the $y_i$ are in degree $n$. -/
theorem decomposition_Q (n q : ℕ) :
    ((Q q).f (n + 1) : X _[n + 1] ⟶ X _[n + 1]) =
      ∑ i : Fin (n + 1) in Finset.filter (fun i : Fin (n + 1) => (i : ℕ) < q) Finset.univ,
        (P i).f (n + 1) ≫ X.δ i.rev.succ ≫ X.σ (Fin.rev i) := by
  induction' q with q hq
  · 

Proof state:
case zero
C : Type u_1
inst✝¹ : Category.{u_2, u_1} C
inst✝ : Preadditive C
X X' : SimplicialObject C
n : ℕ
⊢ HomologicalComplex.Hom.f (Q Nat.zero) (n + 1) =
    ∑ i in Finset.filter (fun i => ↑i < Nat.zero) Finset.univ,
      HomologicalComplex.Hom.f (P ↑i) (n + 1) ≫
        SimplicialObject.δ X (Fin.succ (Fin.rev i)) ≫ SimplicialObject.σ X (Fin.rev i)

Next tactic:
simp only [Nat.zero_eq, Q_zero, HomologicalComplex.zero_f_apply, Nat.not_lt_zero,
      Finset.filter_False, Finset.sum_empty]
/-- In each positive degree, this lemma decomposes the idempotent endomorphism
`Q q` as a sum of morphisms which are postcompositions with suitable degeneracies.
As `Q q` is the complement projection to `P q`, this implies that in the case of
simplicial abelian groups, any $(n+1)$-simplex $x$ can be decomposed as
$x = x' + \sum (i=0}^{q-1} σ_{n-i}(y_i)$ where $x'$ is in the image of `P q` and
the $y_i$ are in degree $n$. -/
theorem decomposition_Q (n q : ℕ) :
    ((Q q).f (n + 1) : X _[n + 1] ⟶ X _[n + 1]) =
      ∑ i : Fin (n + 1) in Finset.filter (fun i : Fin (n + 1) => (i : ℕ) < q) Finset.univ,
        (P i).f (n + 1) ≫ X.δ i.rev.succ ≫ X.σ (Fin.rev i) := by
  induction' q with q hq
  · simp only [Nat.zero_eq, Q_zero, HomologicalComplex.zero_f_apply, Nat.not_lt_zero,
      Finset.filter_False, Finset.sum_empty]
  · 

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

Next tactic:
by_cases hqn : q + 1 ≤ n + 1
/-- In each positive degree, this lemma decomposes the idempotent endomorphism
`Q q` as a sum of morphisms which are postcompositions with suitable degeneracies.
As `Q q` is the complement projection to `P q`, this implies that in the case of
simplicial abelian groups, any $(n+1)$-simplex $x$ can be decomposed as
$x = x' + \sum (i=0}^{q-1} σ_{n-i}(y_i)$ where $x'$ is in the image of `P q` and
the $y_i$ are in degree $n$. -/
theorem decomposition_Q (n q : ℕ) :
    ((Q q).f (n + 1) : X _[n + 1] ⟶ X _[n + 1]) =
      ∑ i : Fin (n + 1) in Finset.filter (fun i : Fin (n + 1) => (i : ℕ) < q) Finset.univ,
        (P i).f (n + 1) ≫ X.δ i.rev.succ ≫ X.σ (Fin.rev i) := by
  induction' q with q hq
  · simp only [Nat.zero_eq, Q_zero, HomologicalComplex.zero_f_apply, Nat.not_lt_zero,
      Finset.filter_False, Finset.sum_empty]
  · by_cases hqn : q + 1 ≤ n + 1
    

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

Next tactic:
swap
/-- In each positive degree, this lemma decomposes the idempotent endomorphism
`Q q` as a sum of morphisms which are postcompositions with suitable degeneracies.
As `Q q` is the complement projection to `P q`, this implies that in the case of
simplicial abelian groups, any $(n+1)$-simplex $x$ can be decomposed as
$x = x' + \sum (i=0}^{q-1} σ_{n-i}(y_i)$ where $x'$ is in the image of `P q` and
the $y_i$ are in degree $n$. -/
theorem decomposition_Q (n q : ℕ) :
    ((Q q).f (n + 1) : X _[n + 1] ⟶ X _[n + 1]) =
      ∑ i : Fin (n + 1) in Finset.filter (fun i : Fin (n + 1) => (i : ℕ) < q) Finset.univ,
        (P i).f (n + 1) ≫ X.δ i.rev.succ ≫ X.σ (Fin.rev i) := by
  induction' q with q hq
  · simp only [Nat.zero_eq, Q_zero, HomologicalComplex.zero_f_apply, Nat.not_lt_zero,
      Finset.filter_False, Finset.sum_empty]
  · by_cases hqn : q + 1 ≤ n + 1
    swap
    · 

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

Next tactic:
rw [Q_is_eventually_constant (show n + 1 ≤ q by linarith), hq]
/-- In each positive degree, this lemma decomposes the idempotent endomorphism
`Q q` as a sum of morphisms which are postcompositions with suitable degeneracies.
As `Q q` is the complement projection to `P q`, this implies that in the case of
simplicial abelian groups, any $(n+1)$-simplex $x$ can be decomposed as
$x = x' + \sum (i=0}^{q-1} σ_{n-i}(y_i)$ where $x'$ is in the image of `P q` and
the $y_i$ are in degree $n$. -/
theorem decomposition_Q (n q : ℕ) :
    ((Q q).f (n + 1) : X _[n + 1] ⟶ X _[n + 1]) =
      ∑ i : Fin (n + 1) in Finset.filter (fun i : Fin (n + 1) => (i : ℕ) < q) Finset.univ,
        (P i).f (n + 1) ≫ X.δ i.rev.succ ≫ X.σ (Fin.rev i) := by
  induction' q with q hq
  · simp only [Nat.zero_eq, Q_zero, HomologicalComplex.zero_f_apply, Nat.not_lt_zero,
      Finset.filter_False, Finset.sum_empty]
  · by_cases hqn : q + 1 ≤ n + 1
    swap
    · rw [Q_is_eventually_constant (show n + 1 ≤ q by 

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

Next tactic:
linarith
/-- In each positive degree, this lemma decomposes the idempotent endomorphism
`Q q` as a sum of morphisms which are postcompositions with suitable degeneracies.
As `Q q` is the complement projection to `P q`, this implies that in the case of
simplicial abelian groups, any $(n+1)$-simplex $x$ can be decomposed as
$x = x' + \sum (i=0}^{q-1} σ_{n-i}(y_i)$ where $x'$ is in the image of `P q` and
the $y_i$ are in degree $n$. -/
theorem decomposition_Q (n q : ℕ) :
    ((Q q).f (n + 1) : X _[n + 1] ⟶ X _[n + 1]) =
      ∑ i : Fin (n + 1) in Finset.filter (fun i : Fin (n + 1) => (i : ℕ) < q) Finset.univ,
        (P i).f (n + 1) ≫ X.δ i.rev.succ ≫ X.σ (Fin.rev i) := by
  induction' q with q hq
  · simp only [Nat.zero_eq, Q_zero, HomologicalComplex.zero_f_apply, Nat.not_lt_zero,
      Finset.filter_False, Finset.sum_empty]
  · by_cases hqn : q + 1 ≤ n + 1
    swap
    · rw [Q_is_eventually_constant (show n + 1 ≤ q by linarith), hq]
      

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

Next tactic:
congr 1
/-- In each positive degree, this lemma decomposes the idempotent endomorphism
`Q q` as a sum of morphisms which are postcompositions with suitable degeneracies.
As `Q q` is the complement projection to `P q`, this implies that in the case of
simplicial abelian groups, any $(n+1)$-simplex $x$ can be decomposed as
$x = x' + \sum (i=0}^{q-1} σ_{n-i}(y_i)$ where $x'$ is in the image of `P q` and
the $y_i$ are in degree $n$. -/
theorem decomposition_Q (n q : ℕ) :
    ((Q q).f (n + 1) : X _[n + 1] ⟶ X _[n + 1]) =
      ∑ i : Fin (n + 1) in Finset.filter (fun i : Fin (n + 1) => (i : ℕ) < q) Finset.univ,
        (P i).f (n + 1) ≫ X.δ i.rev.succ ≫ X.σ (Fin.rev i) := by
  induction' q with q hq
  · simp only [Nat.zero_eq, Q_zero, HomologicalComplex.zero_f_apply, Nat.not_lt_zero,
      Finset.filter_False, Finset.sum_empty]
  · by_cases hqn : q + 1 ≤ n + 1
    swap
    · rw [Q_is_eventually_constant (show n + 1 ≤ q by linarith), hq]
      congr 1
      

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

Next tactic:
ext ⟨x, hx⟩
/-- In each positive degree, this lemma decomposes the idempotent endomorphism
`Q q` as a sum of morphisms which are postcompositions with suitable degeneracies.
As `Q q` is the complement projection to `P q`, this implies that in the case of
simplicial abelian groups, any $(n+1)$-simplex $x$ can be decomposed as
$x = x' + \sum (i=0}^{q-1} σ_{n-i}(y_i)$ where $x'$ is in the image of `P q` and
the $y_i$ are in degree $n$. -/
theorem decomposition_Q (n q : ℕ) :
    ((Q q).f (n + 1) : X _[n + 1] ⟶ X _[n + 1]) =
      ∑ i : Fin (n + 1) in Finset.filter (fun i : Fin (n + 1) => (i : ℕ) < q) Finset.univ,
        (P i).f (n + 1) ≫ X.δ i.rev.succ ≫ X.σ (Fin.rev i) := by
  induction' q with q hq
  · simp only [Nat.zero_eq, Q_zero, HomologicalComplex.zero_f_apply, Nat.not_lt_zero,
      Finset.filter_False, Finset.sum_empty]
  · by_cases hqn : q + 1 ≤ n + 1
    swap
    · rw [Q_is_eventually_constant (show n + 1 ≤ q by linarith), hq]
      congr 1
      ext ⟨x, hx⟩
      

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

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