For instance, consider the endofunctor on the category of sets, where is the one-point (singleton) set, the terminal object in the category. An algebra for this endofunctor is a set (called the carrier of the algebra) together with a point and a function . The set of natural numbers is the carrier of the initial such algebra: the point is zero and the function is the successor map.
For a second example, consider the endofunctor on the category of sets, where is the set of natural numbers. An algebra for this endofunctor is a set together with a point and a function . The set of finite lists of natural numbers is the initial such algebra. The point is the empty list, and the function is cons, taking a number and a finite list, and returning a new finite list with the number at the head.
For example, using the same functor as before, a coalgebra is a set together with a truth-valued test function and a partial function whose domain is formed by those for which . The set consisting of the natural numbers extended with a new element is the carrier of the final coalgebra in the category, where is the test for zero: and , and is the predecessor function (the inverse of the successor function) on the positive naturals, but acts like the identity on the new element : , .
For a second example, consider the same functor as before. In this case the carrier of the final coalgebra consists of all lists of natural numbers, finite as well as infinite. The operations are a test function testing whether a list is empty, and a deconstruction function defined on nonempty lists returning a pair consisting of the head and the tail of the input list.
Consider the endofunctor sending to . Then the set of natural numbers together with the functions , where and are the obvious functions suggested by their names, is an initial -algebra. The initiality (the universal property for this case) is not hard to establish; the unique homomorphism to an arbitrary -algebra , for an element of and a function on , is the function sending the natural number to , that is, , the -fold application of to .
Use in computer scienceEdit
Various finite data structures used in programming, such as lists and trees, can be obtained as initial algebras of specific end functors. While there may be several initial algebras for a given end functor, they are unique up to isomorphism, which informally means that the "observable" properties of a data structure can be adequately captured by defining it as an initial algebra.
To obtain the type of lists whose elements are members of set , consider that the list-forming operations are:
Combined into one function, they give:
which makes this an -algebra for the end functor sending to . It is, in fact, the initial -algebra. Initiality is established by the function known as foldr in functional programming languages such as Haskell and ML.
Likewise, binary trees with elements at the leaves can be obtained as the initial algebra
Types obtained this way are known as algebraic data types.
In a dual way, similar relationship exists between notions of greatest fixed point and terminal F-coalgebra, with applications to coinductive types. These can be used for allowing potentially infinite objects while maintaining strong normalization property. In the strongly normalizing Charity programming language (i.e. each program terminates), coinductive data types can be used achieving surprising results, e.g. defining lookup constructs to implement such “strong” functions like the Ackermann function.
- Categorical programming with inductive and coinductive types by Varmo Vene
- Philip Wadler: Recursive types for free! University of Glasgow, July 1998. Draft.
- Initial Algebra and Final Coalgebra Semantics for Concurrency by J.J.M.M. Rutten and D. Turi
- Initiality and finality from CLiki