# F-algebra

In mathematics, specifically in category theory, F-algebras generalize the notion of algebraic structure. Rewriting the algebraic laws in terms of morphisms eliminates all references to quantified elements from the axioms, and these algebraic laws may then be glued together in terms of a single functor F, the signature.

F-algebras can also be used to represent data structures used in programming, such as lists and trees.

The main related concepts are initial F-algebras which may serve to encapsulate the induction principle, and the dual construction F-coalgebras.

## Definition

If ${\displaystyle C}$ is a category, and ${\displaystyle F:C\rightarrow C}$ is an endofunctor of ${\displaystyle C}$, then an ${\displaystyle F}$-algebra is a tuple ${\displaystyle (A,\alpha )}$, where ${\displaystyle A}$ is an object of ${\displaystyle C}$ and ${\displaystyle \alpha }$ is a ${\displaystyle C}$-morphism ${\displaystyle F(A)\rightarrow A}$. The object ${\displaystyle A}$ is called the carrier of the algebra. When it is permissible from context, algebras are often referred to by their carrier only instead of the tuple.

A homomorphism from an ${\displaystyle F}$-algebra ${\displaystyle (A,\alpha )}$ to an ${\displaystyle F}$-algebra ${\displaystyle (B,\beta )}$ is a ${\displaystyle C}$-morphism ${\displaystyle f:A\rightarrow B}$ such that ${\displaystyle f\circ \alpha =\beta \circ F(f)}$, according to the following commutative diagram:

Equipped with these morphisms, ${\displaystyle F}$-algebras constitute a category.

The dual construction are ${\displaystyle F}$-coalgebras, which are objects ${\displaystyle A^{*}}$ together with a morphism ${\displaystyle \alpha ^{*}:A^{*}\rightarrow F(A^{*})}$.

## Examples

### Groups

Classically, a group is a set ${\displaystyle G}$ with a group law ${\displaystyle m:G\times G\rightarrow G}$, with ${\displaystyle m(x,y)=x\cdot y}$, satisfying three axioms: the existence of an identity element, the existence of an inverse for each element of the group, and associativity.

To put this in a categorical framework, first define the identity and inverse as functions (morphisms of the set ${\displaystyle G}$) by ${\displaystyle e:1\rightarrow G}$ with ${\displaystyle e(*)=1}$, and ${\displaystyle i:G\rightarrow G}$ with ${\displaystyle i(x)=x^{-1}}$. Here ${\displaystyle 1}$ denotes the set with one element ${\displaystyle 1=\left\{*\right\}}$, which allows one to identify elements ${\displaystyle x\in G}$ with morphisms ${\displaystyle 1\rightarrow G}$.

It is then possible to write the axioms of a group in terms of functions (note how the existential quantifier is absent):

• ${\displaystyle \forall x\in G,\forall y\in G,\forall z\in G,m(m(x,y),z)=m(x,m(y,z))}$,
• ${\displaystyle \forall x\in G,m(e(*),x)=m(x,e(*))=x}$,
• ${\displaystyle \forall x\in G,m(i(x),x)=m(x,i(x))=e(*)}$.

Then this can be expressed with commutative diagrams:[1][2]

Now use the coproduct (the disjoint union of sets) to glue the three morphisms in one: ${\displaystyle \alpha =e+i+m}$ according to

${\displaystyle {\begin{matrix}\alpha :{1}+G+G\times G&\to &G,\\*&\mapsto &1,\\x&\mapsto &x^{-1},\\(x,y)&\mapsto &x\cdot y.\end{matrix}}}$

Thus a group is an ${\displaystyle F}$-algebra where ${\displaystyle F}$ is the functor ${\displaystyle F(G)=1+G+G\times G}$. However the reverse is not necessarily true. Some ${\displaystyle F}$-algebra where ${\displaystyle F}$ is the functor ${\displaystyle F(G)=1+G+G\times G}$ are not groups.

The above construction is used to define group objects over an arbitrary category with finite products and a terminal object ${\displaystyle 1}$. When the category admits finite coproducts, the group objects are ${\displaystyle F}$-algebras. For example, finite groups are ${\displaystyle F}$-algebras in the category of finite sets and Lie groups are ${\displaystyle F}$-algebras in the category of smooth manifolds with smooth maps.

### Algebraic structures

Going one step ahead of universal algebra, most algebraic structures are F-algebras. For example, abelian groups are F-algebras for the same functor F(G) = 1 + G + G×G as for groups, with an additional axiom for commutativity: mt = m, where t(x,y) = (y,x) is the transpose on GxG.

Monoids are F-algebras of signature F(M) = 1 + M×M. In the same vein, semigroups are F-algebras of signature F(S) = S×S

Rings, domains and fields are also F-algebras with a signature involving two laws +,•: R×R → R, an additive identity 0: 1 → R, a multiplicative identity 1: 1 → R, and an additive inverse for each element -: RR. As all these functions share the same codomain R they can be glued into a single signature function 1 + 1 + R + R×R + R×RR, with axioms to express associativity, distributivity, and so on. This makes rings F-algebras on the category of sets with signature 1 + 1 + R + R×R + R×R.

Alternatively, we can look at the functor F(R) = 1 + R×R in the category of abelian groups. In that context, the multiplication is a homomorphism, meaning m(x + y, z) = m(x,z) + m(y,z) and m(x,y + z) = m(x,y) + m(x,z), which are precisely the distributivity conditions. Therefore, a ring is an F-algebra of signature 1 + R×R over the category of abelian groups which satisfies two axioms (associativity and identity for the multiplication).

When we come to vector spaces and modules, the signature functor includes a scalar multiplication k×EE, and the signature F(E) = 1 + E + k×E is parametrized by k over the category of fields, or rings.

Algebras over a field can be viewed as F-algebras of signature 1 + 1 + A + A×A + A×A + k×A over the category of sets, of signature 1 + A×A over the category of modules (a module with an internal multiplication), and of signature k×A over the category of rings (a ring with a scalar multiplication), when they are associative and unitary.

### Lattice

Not all mathematical structures are F-algebras. For example, a poset P may be defined in categorical terms with a morphism s:P × P → Ω, on a subobject classifier (Ω = {0,1} in the category of sets and s(x,y)=1 precisely when xy). The axioms restricting the morphism s to define a poset can be rewritten in terms of morphisms. However, as the codomain of s is Ω and not P, it is not an F-algebra.

However, lattices, which are partial orders in which every two elements have a supremum and an infimum, and in particular total orders, are F-algebras. This is because they can equivalently be defined in terms of the algebraic operations: xy = inf(x,y) and xy = sup(x,y), subject to certain axioms (commutativity, associativity, absorption and idempotency). Thus they are F-algebras of signature P x P + P x P. It is often said that lattice theory draws on both order theory and universal algebra.

### Recurrence

Consider the functor ${\displaystyle F:\mathrm {\bf {Set}} \to \mathrm {\bf {Set}} }$ that sends a set ${\displaystyle X}$ to ${\displaystyle 1+X}$. Here, ${\displaystyle \mathrm {\bf {Set}} }$ denotes the category of sets, ${\displaystyle +}$ denotes the usual coproduct given by the disjoint union, and ${\displaystyle 1}$ is a terminal object (i.e. any singleton set). Then, the set ${\displaystyle \mathbb {N} }$ of natural numbers together with the function ${\displaystyle [\mathrm {zero} ,\mathrm {succ} ]:1+\mathbb {N} \to \mathbb {N} }$—which is the coproduct of the functions ${\displaystyle \mathrm {zero} :1\mapsto 0}$ and ${\displaystyle \mathrm {succ} :n\mapsto n+1}$—is an F-algebra.

## Initial F-algebra

If the category of F-algebras for a given endofunctor F has an initial object, it is called an initial algebra. The algebra ${\displaystyle (\mathbb {N} ,[\mathrm {zero} ,\mathrm {succ} ])}$ in the above example is an initial algebra. Various finite data structures used in programming, such as lists and trees, can be obtained as initial algebras of specific endofunctors.

Types defined by using least fixed point construct with functor F can be regarded as an initial F-algebra, provided that parametricity holds for the type.[3]

## Terminal F-coalgebra

In a dual way, a similar relationship exists between notions of greatest fixed point and terminal F-coalgebra. These can be used for allowing potentially infinite objects while maintaining strong normalization property.[3] In the strongly normalizing Charity programming language (i.e. each program terminates in it), coinductive data types can be used to achieve surprising results, enabling the definition of lookup constructs to implement such “strong” functions like the Ackermann function.[4]

## Notes

1. ^ The vertical arrows without labels in the second diagram must be unique since * is terminal.
2. ^ Strictly speaking, (i,id) and (id,i) are labelled inconsistently with the other diagrams as these morphisms "diagonalise" first.
3. ^ a b Philip Wadler: Recursive types for free! Archived 2007-10-16 at the Wayback Machine University of Glasgow, June 1990. Draft.
4. ^ Robin Cockett: Charitable Thoughts (psArchived 2020-12-29 at the Wayback Machine and ps.gzArchived 2020-12-29 at the Wayback Machine)

## References

• Pierce, Benjamin C. (1991). "F-Algebras". Basic Category Theory for Computer Scientists. ISBN 0-262-66071-7.
• Barr, Michael; Wells, Charles (1990). Category theory for computing science. New York: Prentice Hall. p. 355. ISBN 0131204866. OCLC 19126000.