A terminal coalgebra, also called final coalgebra, for an endofunctor on a category is a terminal object in the category of coalgebras of .
If has a terminal coalgebra , then is isomorphic to (see below); in this sense, is a fixed point of . Being terminal, is the largest fixed point of in that there is a map to to any other fixed point (indeed, any other coalgebra), and this map is an injection if is Set.
The dual concept is initial algebra. Just as initial algebras allow for induction and recursion?, so terminal coalgebras allow for coinduction and corecursion.
Given two coalgebras , , a coalgebra map is a morphism which respects the coalgebra structures:
A terminal coalgebra (usually called a final coalgebra in the literature) is of course a terminal object in the category of coalgebras. Many data structures can be expressed as terminal coalgebras of suitable endofunctors; a simple but useful theorem says that terminal coalgebras are “fixed points” of their endofunctors, in that . This is the dual form of a theorem discovered long ago by Lambek:
If is a terminal object in the category of -coalgebras, then is an isomorphism.
Define a coalgebra structure on by . By terminality of , there is a unique coalgebra map . We claim this is inverse to . Indeed, by how we defined the coalgebra structure on , it is tautological that is a coalgebra map. By terminality of again, this gives an equation of coalgebra maps:
On the other hand,
where the first equation holds because is a coalgebra map. This completes the proof.
To construct terminal coalgebras, the following result is useful and practical:
If has a terminal object and the limit of the diagram
exists in and preserves this limit, then the limit carries a structure of terminal coalgebra.
Let be the projection of the limiting cone. Then we have a cone from to the diagram (1) whose components are
and the induced map to the limit is invertible by hypothesis; let be the inverse. We claim the coalgebra is terminal.
Indeed, suppose is any coalgebra. We recursively define maps : let be the unique map, and
It is easily checked by induction that these maps define a cone from to the diagram (1), and so we get a map . (More later)