For instance, consider the endofunctor 1+(−){\displaystyle 1+(-)} on the category of sets, where 1{\displaystyle 1} is the one-point (singleton) set, the terminal object in the category. An algebra for this endofunctor is a set X{\displaystyle X} (called the carrier of the algebra) together with a point x∈X{\displaystyle x\in X} and a function X→X{\displaystyle X\to X}. 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 1+N×(−){\displaystyle 1+\mathbf {N} \times (-)} on the category of sets, where N{\displaystyle \mathbf {N} } is the set of natural numbers. An algebra for this endofunctor is a set X{\displaystyle X} together with a point x∈X{\displaystyle x\in X} and a function N×X→X{\displaystyle \mathbf {N} \times X\to X}. 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.

In categories with binary coproducts, the definitions just given are equivalent to the usual definitions of a natural number object and a list object, respectively.

Contents

For example, using the same functor 1+(−){\displaystyle 1+(-)} as before, a coalgebra is a set X{\displaystyle X} together with a truth-valued test function p:X→2{\displaystyle p\colon X\to 2} and a partial functionf:X→X{\displaystyle f\colon X\to X} whose domain is formed by those x∈X{\displaystyle x\in X} for which p(x)=0{\displaystyle p(x)=0}. The set N∪{ω}{\displaystyle \mathbf {N} \cup \{\omega \}} consisting of the natural numbers extended with a new element ω{\displaystyle \omega } is the carrier of the final coalgebra in the category, where p{\displaystyle p} is the test for zero: p(0)=1{\displaystyle p(0)=1} and p(n+1)=p(ω)=0{\displaystyle p(n+1)=p(\omega )=0}, and f{\displaystyle f} is the predecessor function (the inverse of the successor function) on the positive naturals, but acts like the identity on the new element ω{\displaystyle \omega }: f(n+1)=n{\displaystyle f(n+1)=n}, f(ω)=ω{\displaystyle f(\omega )=\omega }.

For a second example, consider the same functor 1+N×(−){\displaystyle 1+\mathbf {N} \times ({\mathord {-}})} 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.

Then the set N{\displaystyle \mathbf {N} } of natural numbers together with the function [zero,succ]:1+N→N{\displaystyle [\operatorname {zero} ,\operatorname {succ} ]\colon 1+\mathbf {N} \to \mathbf {N} } is an initial F{\displaystyle F}-algebra. The initiality (the universal property for this case) is not hard to establish; the unique homomorphism to an arbitrary F{\displaystyle F}-algebra (A,[e,f]){\displaystyle (A,[e,f])}, for e:1→A{\displaystyle e\colon 1\to A} an element of A{\displaystyle A} and f:A→A{\displaystyle f\colon A\to A} a function on A{\displaystyle A}, is the function sending the natural number n{\displaystyle n} to fn(e){\displaystyle f^{n}(e)}, that is, f(f(…(f(e))…)){\displaystyle f(f(\dots (f(e))\dots ))}, the n{\displaystyle n}-fold application of f{\displaystyle f} to e{\displaystyle e}.

Various finite data structures used in programming, such as lists and trees, can be obtained as initial algebras of specific endofunctors. While there may be several initial algebras for a given end functor, they are uniqueup toisomorphism, 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 typeList(A){\displaystyle \mathrm {List} (A)} of lists whose elements are members of set A{\displaystyle A}, consider that the list-forming operations are:

which makes this an F{\displaystyle F}-algebra for the end functor FunctorEndo{\displaystyle FunctorEndo} sending X{\displaystyle X} to 1+(A×X){\displaystyle 1+(A\times X)}. It is, in fact, the initial F{\displaystyle F}-algebra. Initiality is established by the function known as foldr in functionalprogramming languages such as Haskell and ML.

Likewise, binary trees with elements at the leaves can be obtained as the initial algebra