Lean4
/-- The fork constructed is a limit. This shows that any coalgebra is a (coreflexive) equalizer of
cofree coalgebras.
-/
def beckCoalgebraEqualizer : IsLimit (beckCoalgebraFork X) :=
Fork.IsLimit.mk' _ fun s =>
by
have h₁ : s.ι.f ≫ (T : C ⥤ C).map X.a = s.ι.f ≫ T.δ.app X.A := congr_arg Comonad.Coalgebra.Hom.f s.condition
have h₂ : s.pt.a ≫ (T : C ⥤ C).map s.ι.f = s.ι.f ≫ T.δ.app X.A := s.ι.h
refine ⟨⟨s.ι.f ≫ T.ε.app _, ?_⟩, ?_, ?_⟩
· dsimp
rw [Functor.map_comp, reassoc_of% h₂, Comonad.right_counit]
dsimp
rw [Category.comp_id, Category.assoc, ← T.counit_naturality, reassoc_of% h₁, Comonad.left_counit]
simp
· ext
simpa [← T.ε.naturality_assoc, T.left_counit_assoc] using h₁ =≫ T.ε.app ((T : C ⥤ C).obj X.A)
· intro m hm
ext
dsimp only
rw [← hm]
simp [beckCoalgebraFork, X.counit]